Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2010 The Android Open Source Project |
| 3 | * |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | * you may not use this file except in compliance with the License. |
| 6 | * You may obtain a copy of the License at |
| 7 | * |
| 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | * |
| 10 | * Unless required by applicable law or agreed to in writing, software |
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | * See the License for the specific language governing permissions and |
| 14 | * limitations under the License. |
| 15 | */ |
| 16 | |
| 17 | package com.android.server.am; |
| 18 | |
Craig Mautner | 0eea92c | 2013-05-16 13:35:39 -0700 | [diff] [blame] | 19 | import static com.android.server.am.ActivityManagerService.TAG; |
| 20 | import static com.android.server.am.ActivityManagerService.localLOGV; |
| 21 | import static com.android.server.am.ActivityManagerService.DEBUG_CLEANUP; |
| 22 | import static com.android.server.am.ActivityManagerService.DEBUG_CONFIGURATION; |
| 23 | import static com.android.server.am.ActivityManagerService.DEBUG_PAUSE; |
| 24 | import static com.android.server.am.ActivityManagerService.DEBUG_RESULTS; |
| 25 | import static com.android.server.am.ActivityManagerService.DEBUG_STACK; |
| 26 | import static com.android.server.am.ActivityManagerService.DEBUG_SWITCH; |
| 27 | import static com.android.server.am.ActivityManagerService.DEBUG_TASKS; |
| 28 | import static com.android.server.am.ActivityManagerService.DEBUG_TRANSITION; |
| 29 | import static com.android.server.am.ActivityManagerService.DEBUG_USER_LEAVING; |
| 30 | import static com.android.server.am.ActivityManagerService.DEBUG_VISBILITY; |
| 31 | import static com.android.server.am.ActivityManagerService.VALIDATE_TOKENS; |
| 32 | |
| 33 | import static com.android.server.am.ActivityStackSupervisor.DEBUG_ADD_REMOVE; |
| 34 | import static com.android.server.am.ActivityStackSupervisor.DEBUG_APP; |
| 35 | import static com.android.server.am.ActivityStackSupervisor.DEBUG_SAVED_STATE; |
Winson Chung | 376543b | 2014-05-21 17:43:28 -0700 | [diff] [blame] | 36 | import static com.android.server.am.ActivityStackSupervisor.DEBUG_SCREENSHOTS; |
Craig Mautner | 0eea92c | 2013-05-16 13:35:39 -0700 | [diff] [blame] | 37 | import static com.android.server.am.ActivityStackSupervisor.DEBUG_STATES; |
Craig Mautner | de4ef02 | 2013-04-07 19:01:33 -0700 | [diff] [blame] | 38 | import static com.android.server.am.ActivityStackSupervisor.HOME_STACK_ID; |
| 39 | |
Dianne Hackborn | 91097de | 2014-04-04 18:02:06 -0700 | [diff] [blame] | 40 | import android.service.voice.IVoiceInteractionSession; |
| 41 | import com.android.internal.app.IVoiceInteractor; |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 42 | import com.android.internal.os.BatteryStatsImpl; |
Kenny Root | add5821 | 2013-05-07 09:47:34 -0700 | [diff] [blame] | 43 | import com.android.server.Watchdog; |
Craig Mautner | cae015f | 2013-02-08 14:31:27 -0800 | [diff] [blame] | 44 | import com.android.server.am.ActivityManagerService.ItemMatcher; |
Craig Mautner | 4a1cb22 | 2013-12-04 16:14:06 -0800 | [diff] [blame] | 45 | import com.android.server.am.ActivityStackSupervisor.ActivityContainer; |
Craig Mautner | 4b71aa1 | 2012-12-27 17:20:01 -0800 | [diff] [blame] | 46 | import com.android.server.wm.AppTransition; |
Craig Mautner | 05d6272ba | 2013-02-11 09:39:27 -0800 | [diff] [blame] | 47 | import com.android.server.wm.TaskGroup; |
Craig Mautner | ce5f3cb | 2013-04-22 08:58:54 -0700 | [diff] [blame] | 48 | import com.android.server.wm.WindowManagerService; |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 49 | |
| 50 | import android.app.Activity; |
Dianne Hackborn | 0c5001d | 2011-04-12 18:16:08 -0700 | [diff] [blame] | 51 | import android.app.ActivityManager; |
Dianne Hackborn | 7a2195c | 2012-03-19 17:38:00 -0700 | [diff] [blame] | 52 | import android.app.ActivityOptions; |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 53 | import android.app.AppGlobals; |
Craig Mautner | 05d6272ba | 2013-02-11 09:39:27 -0800 | [diff] [blame] | 54 | import android.app.IActivityController; |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 55 | import android.app.ResultInfo; |
Craig Mautner | cae015f | 2013-02-08 14:31:27 -0800 | [diff] [blame] | 56 | import android.app.ActivityManager.RunningTaskInfo; |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 57 | import android.content.ComponentName; |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 58 | import android.content.Intent; |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 59 | import android.content.pm.ActivityInfo; |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 60 | import android.content.pm.PackageManager; |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 61 | import android.content.res.Configuration; |
Dianne Hackborn | 0aae2d4 | 2010-12-07 23:51:29 -0800 | [diff] [blame] | 62 | import android.content.res.Resources; |
| 63 | import android.graphics.Bitmap; |
Santos Cordon | 73ff7d8 | 2013-03-06 17:24:11 -0800 | [diff] [blame] | 64 | import android.net.Uri; |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 65 | import android.os.Binder; |
Dianne Hackborn | ce86ba8 | 2011-07-13 19:33:41 -0700 | [diff] [blame] | 66 | import android.os.Bundle; |
Craig Mautner | 329f412 | 2013-11-07 09:10:42 -0800 | [diff] [blame] | 67 | import android.os.Debug; |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 68 | import android.os.Handler; |
| 69 | import android.os.IBinder; |
Zoran Marceta | f958b32 | 2012-08-09 20:27:12 +0900 | [diff] [blame] | 70 | import android.os.Looper; |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 71 | import android.os.Message; |
Craig Mautner | a002604 | 2014-04-23 11:45:37 -0700 | [diff] [blame] | 72 | import android.os.PersistableBundle; |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 73 | import android.os.RemoteException; |
| 74 | import android.os.SystemClock; |
Craig Mautner | 329f412 | 2013-11-07 09:10:42 -0800 | [diff] [blame] | 75 | import android.os.Trace; |
Dianne Hackborn | f02b60a | 2012-08-16 10:48:27 -0700 | [diff] [blame] | 76 | import android.os.UserHandle; |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 77 | import android.util.EventLog; |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 78 | import android.util.Slog; |
Craig Mautner | 59c0097 | 2012-07-30 12:10:24 -0700 | [diff] [blame] | 79 | import android.view.Display; |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 80 | |
Craig Mautner | cae015f | 2013-02-08 14:31:27 -0800 | [diff] [blame] | 81 | import java.io.FileDescriptor; |
Craig Mautner | cae015f | 2013-02-08 14:31:27 -0800 | [diff] [blame] | 82 | import java.io.PrintWriter; |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 83 | import java.lang.ref.WeakReference; |
| 84 | import java.util.ArrayList; |
| 85 | import java.util.Iterator; |
| 86 | import java.util.List; |
Kenny Root | e6585b3 | 2013-12-13 12:00:26 -0800 | [diff] [blame] | 87 | import java.util.Objects; |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 88 | |
| 89 | /** |
| 90 | * State and management of a single stack of activities. |
| 91 | */ |
Dianne Hackborn | 0c5001d | 2011-04-12 18:16:08 -0700 | [diff] [blame] | 92 | final class ActivityStack { |
Craig Mautner | 5d9c7be | 2013-02-15 14:02:56 -0800 | [diff] [blame] | 93 | |
Dianne Hackborn | 2a29b3a | 2012-03-15 15:48:38 -0700 | [diff] [blame] | 94 | // Ticks during which we check progress while waiting for an app to launch. |
| 95 | static final int LAUNCH_TICK = 500; |
| 96 | |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 97 | // How long we wait until giving up on the last activity to pause. This |
| 98 | // is short because it directly impacts the responsiveness of starting the |
| 99 | // next activity. |
| 100 | static final int PAUSE_TIMEOUT = 500; |
| 101 | |
Dianne Hackborn | 162bc0e | 2012-04-09 14:06:16 -0700 | [diff] [blame] | 102 | // How long we wait for the activity to tell us it has stopped before |
| 103 | // giving up. This is a good amount of time because we really need this |
| 104 | // from the application in order to get its saved state. |
| 105 | static final int STOP_TIMEOUT = 10*1000; |
| 106 | |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 107 | // How long we wait until giving up on an activity telling us it has |
| 108 | // finished destroying itself. |
| 109 | static final int DESTROY_TIMEOUT = 10*1000; |
Craig Mautner | d74f7d7 | 2013-02-26 13:41:02 -0800 | [diff] [blame] | 110 | |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 111 | // How long until we reset a task when the user returns to it. Currently |
Dianne Hackborn | 621e17d | 2010-11-22 15:59:56 -0800 | [diff] [blame] | 112 | // disabled. |
| 113 | static final long ACTIVITY_INACTIVE_RESET_TIME = 0; |
Craig Mautner | d74f7d7 | 2013-02-26 13:41:02 -0800 | [diff] [blame] | 114 | |
Dianne Hackborn | 0dad364 | 2010-09-09 21:25:35 -0700 | [diff] [blame] | 115 | // How long between activity launches that we consider safe to not warn |
| 116 | // the user about an unexpected activity being launched on top. |
| 117 | static final long START_WARN_TIME = 5*1000; |
Craig Mautner | d74f7d7 | 2013-02-26 13:41:02 -0800 | [diff] [blame] | 118 | |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 119 | // Set to false to disable the preview that is shown while a new activity |
| 120 | // is being started. |
| 121 | static final boolean SHOW_APP_STARTING_PREVIEW = true; |
Craig Mautner | 5d9c7be | 2013-02-15 14:02:56 -0800 | [diff] [blame] | 122 | |
Craig Mautner | 5eda9b3 | 2013-07-02 11:58:16 -0700 | [diff] [blame] | 123 | // How long to wait for all background Activities to redraw following a call to |
| 124 | // convertToTranslucent(). |
| 125 | static final long TRANSLUCENT_CONVERSION_TIMEOUT = 2000; |
| 126 | |
Craig Mautner | a61bc65 | 2013-10-28 15:43:18 -0700 | [diff] [blame] | 127 | static final boolean SCREENSHOT_FORCE_565 = ActivityManager.isLowRamDeviceStatic(); |
John Reck | 172e87c | 2013-10-02 16:55:16 -0700 | [diff] [blame] | 128 | |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 129 | enum ActivityState { |
| 130 | INITIALIZING, |
| 131 | RESUMED, |
| 132 | PAUSING, |
| 133 | PAUSED, |
| 134 | STOPPING, |
| 135 | STOPPED, |
| 136 | FINISHING, |
| 137 | DESTROYING, |
| 138 | DESTROYED |
| 139 | } |
| 140 | |
| 141 | final ActivityManagerService mService; |
Craig Mautner | ce5f3cb | 2013-04-22 08:58:54 -0700 | [diff] [blame] | 142 | final WindowManagerService mWindowManager; |
Craig Mautner | d74f7d7 | 2013-02-26 13:41:02 -0800 | [diff] [blame] | 143 | |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 144 | /** |
| 145 | * The back history of all previous (and possibly still |
Craig Mautner | 5d9c7be | 2013-02-15 14:02:56 -0800 | [diff] [blame] | 146 | * running) activities. It contains #TaskRecord objects. |
| 147 | */ |
| 148 | private ArrayList<TaskRecord> mTaskHistory = new ArrayList<TaskRecord>(); |
| 149 | |
| 150 | /** |
Dianne Hackborn | be70785 | 2011-11-11 14:32:10 -0800 | [diff] [blame] | 151 | * Used for validating app tokens with window manager. |
| 152 | */ |
Craig Mautner | b1fd65c0 | 2013-02-05 13:34:57 -0800 | [diff] [blame] | 153 | final ArrayList<TaskGroup> mValidateAppTokens = new ArrayList<TaskGroup>(); |
Dianne Hackborn | be70785 | 2011-11-11 14:32:10 -0800 | [diff] [blame] | 154 | |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 155 | /** |
| 156 | * List of running activities, sorted by recent usage. |
| 157 | * The first entry in the list is the least recently used. |
| 158 | * It contains HistoryRecord objects. |
| 159 | */ |
Dianne Hackborn | 0c5001d | 2011-04-12 18:16:08 -0700 | [diff] [blame] | 160 | final ArrayList<ActivityRecord> mLRUActivities = new ArrayList<ActivityRecord>(); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 161 | |
| 162 | /** |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 163 | * Animations that for the current transition have requested not to |
| 164 | * be considered for the transition animation. |
| 165 | */ |
Craig Mautner | ce5f3cb | 2013-04-22 08:58:54 -0700 | [diff] [blame] | 166 | final ArrayList<ActivityRecord> mNoAnimActivities = new ArrayList<ActivityRecord>(); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 167 | |
| 168 | /** |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 169 | * When we are in the process of pausing an activity, before starting the |
| 170 | * next one, this variable holds the activity that is currently being paused. |
| 171 | */ |
Dianne Hackborn | 621e2fe | 2012-02-16 17:07:33 -0800 | [diff] [blame] | 172 | ActivityRecord mPausingActivity = null; |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 173 | |
| 174 | /** |
| 175 | * This is the last activity that we put into the paused state. This is |
| 176 | * used to determine if we need to do an activity transition while sleeping, |
| 177 | * when we normally hold the top activity paused. |
| 178 | */ |
| 179 | ActivityRecord mLastPausedActivity = null; |
| 180 | |
| 181 | /** |
Craig Mautner | 0f92274 | 2013-08-06 08:44:42 -0700 | [diff] [blame] | 182 | * Activities that specify No History must be removed once the user navigates away from them. |
| 183 | * If the device goes to sleep with such an activity in the paused state then we save it here |
| 184 | * and finish it later if another activity replaces it on wakeup. |
| 185 | */ |
| 186 | ActivityRecord mLastNoHistoryActivity = null; |
| 187 | |
| 188 | /** |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 189 | * Current activity that is resumed, or null if there is none. |
| 190 | */ |
| 191 | ActivityRecord mResumedActivity = null; |
Craig Mautner | d74f7d7 | 2013-02-26 13:41:02 -0800 | [diff] [blame] | 192 | |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 193 | /** |
Dianne Hackborn | 0dad364 | 2010-09-09 21:25:35 -0700 | [diff] [blame] | 194 | * This is the last activity that has been started. It is only used to |
| 195 | * identify when multiple activities are started at once so that the user |
| 196 | * can be warned they may not be in the activity they think they are. |
| 197 | */ |
| 198 | ActivityRecord mLastStartedActivity = null; |
Craig Mautner | d74f7d7 | 2013-02-26 13:41:02 -0800 | [diff] [blame] | 199 | |
Craig Mautner | 5eda9b3 | 2013-07-02 11:58:16 -0700 | [diff] [blame] | 200 | // The topmost Activity passed to convertToTranslucent(). When non-null it means we are |
| 201 | // waiting for all Activities in mUndrawnActivitiesBelowTopTranslucent to be removed as they |
| 202 | // are drawn. When the last member of mUndrawnActivitiesBelowTopTranslucent is removed the |
| 203 | // Activity in mTranslucentActivityWaiting is notified via |
| 204 | // Activity.onTranslucentConversionComplete(false). If a timeout occurs prior to the last |
| 205 | // background activity being drawn then the same call will be made with a true value. |
| 206 | ActivityRecord mTranslucentActivityWaiting = null; |
| 207 | ArrayList<ActivityRecord> mUndrawnActivitiesBelowTopTranslucent = |
| 208 | new ArrayList<ActivityRecord>(); |
Craig Mautner | 233ceee | 2014-05-09 17:05:11 -0700 | [diff] [blame] | 209 | // Options passed from the caller of the convertToTranslucent to the activity that will |
| 210 | // appear below it. |
| 211 | ActivityOptions mReturningActivityOptions = null; |
Craig Mautner | 5eda9b3 | 2013-07-02 11:58:16 -0700 | [diff] [blame] | 212 | |
Dianne Hackborn | 0dad364 | 2010-09-09 21:25:35 -0700 | [diff] [blame] | 213 | /** |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 214 | * Set when we know we are going to be calling updateConfiguration() |
| 215 | * soon, so want to skip intermediate config checks. |
| 216 | */ |
| 217 | boolean mConfigWillChange; |
| 218 | |
Dianne Hackborn | 2286cdc | 2013-07-01 19:10:06 -0700 | [diff] [blame] | 219 | long mLaunchStartTime = 0; |
| 220 | long mFullyDrawnStartTime = 0; |
Craig Mautner | d74f7d7 | 2013-02-26 13:41:02 -0800 | [diff] [blame] | 221 | |
Dianne Hackborn | 4eba96b | 2011-01-21 13:34:36 -0800 | [diff] [blame] | 222 | /** |
Craig Mautner | b12428a | 2012-12-20 16:07:06 -0800 | [diff] [blame] | 223 | * Save the most recent screenshot for reuse. This keeps Recents from taking two identical |
| 224 | * screenshots, one for the Recents thumbnail and one for the pauseActivity thumbnail. |
| 225 | */ |
| 226 | private ActivityRecord mLastScreenshotActivity = null; |
| 227 | private Bitmap mLastScreenshotBitmap = null; |
| 228 | |
Dianne Hackborn | 0aae2d4 | 2010-12-07 23:51:29 -0800 | [diff] [blame] | 229 | int mThumbnailWidth = -1; |
| 230 | int mThumbnailHeight = -1; |
| 231 | |
Craig Mautner | 858d8a6 | 2013-04-23 17:08:34 -0700 | [diff] [blame] | 232 | int mCurrentUser; |
Amith Yamasani | 742a671 | 2011-05-04 14:49:28 -0700 | [diff] [blame] | 233 | |
Craig Mautner | c00204b | 2013-03-05 15:02:14 -0800 | [diff] [blame] | 234 | final int mStackId; |
Craig Mautner | 4a1cb22 | 2013-12-04 16:14:06 -0800 | [diff] [blame] | 235 | final ActivityContainer mActivityContainer; |
Craig Mautner | e0a3884 | 2013-12-16 16:14:02 -0800 | [diff] [blame] | 236 | /** The other stacks, in order, on the attached display. Updated at attach/detach time. */ |
| 237 | ArrayList<ActivityStack> mStacks; |
| 238 | /** The attached Display's unique identifier, or -1 if detached */ |
| 239 | int mDisplayId; |
Craig Mautner | 4a1cb22 | 2013-12-04 16:14:06 -0800 | [diff] [blame] | 240 | |
Craig Mautner | 2708430 | 2013-03-25 08:05:25 -0700 | [diff] [blame] | 241 | /** Run all ActivityStacks through this */ |
| 242 | final ActivityStackSupervisor mStackSupervisor; |
| 243 | |
Craig Mautner | 7ea5bd4 | 2013-07-05 15:27:08 -0700 | [diff] [blame] | 244 | static final int PAUSE_TIMEOUT_MSG = ActivityManagerService.FIRST_ACTIVITY_STACK_MSG + 1; |
Craig Mautner | 0eea92c | 2013-05-16 13:35:39 -0700 | [diff] [blame] | 245 | static final int DESTROY_TIMEOUT_MSG = ActivityManagerService.FIRST_ACTIVITY_STACK_MSG + 2; |
| 246 | static final int LAUNCH_TICK_MSG = ActivityManagerService.FIRST_ACTIVITY_STACK_MSG + 3; |
| 247 | static final int STOP_TIMEOUT_MSG = ActivityManagerService.FIRST_ACTIVITY_STACK_MSG + 4; |
| 248 | static final int DESTROY_ACTIVITIES_MSG = ActivityManagerService.FIRST_ACTIVITY_STACK_MSG + 5; |
Craig Mautner | 5eda9b3 | 2013-07-02 11:58:16 -0700 | [diff] [blame] | 249 | static final int TRANSLUCENT_TIMEOUT_MSG = ActivityManagerService.FIRST_ACTIVITY_STACK_MSG + 6; |
Dianne Hackborn | 755c8bf | 2012-05-07 15:06:09 -0700 | [diff] [blame] | 250 | |
| 251 | static class ScheduleDestroyArgs { |
| 252 | final ProcessRecord mOwner; |
| 253 | final boolean mOomAdj; |
| 254 | final String mReason; |
| 255 | ScheduleDestroyArgs(ProcessRecord owner, boolean oomAdj, String reason) { |
| 256 | mOwner = owner; |
| 257 | mOomAdj = oomAdj; |
| 258 | mReason = reason; |
| 259 | } |
| 260 | } |
| 261 | |
Zoran Marceta | f958b32 | 2012-08-09 20:27:12 +0900 | [diff] [blame] | 262 | final Handler mHandler; |
| 263 | |
| 264 | final class ActivityStackHandler extends Handler { |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 265 | //public Handler() { |
| 266 | // if (localLOGV) Slog.v(TAG, "Handler started!"); |
| 267 | //} |
Craig Mautner | c8143c6 | 2013-09-03 12:15:57 -0700 | [diff] [blame] | 268 | ActivityStackHandler(Looper looper) { |
Zoran Marceta | f958b32 | 2012-08-09 20:27:12 +0900 | [diff] [blame] | 269 | super(looper); |
| 270 | } |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 271 | |
Zoran Marceta | f958b32 | 2012-08-09 20:27:12 +0900 | [diff] [blame] | 272 | @Override |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 273 | public void handleMessage(Message msg) { |
| 274 | switch (msg.what) { |
| 275 | case PAUSE_TIMEOUT_MSG: { |
Dianne Hackborn | be70785 | 2011-11-11 14:32:10 -0800 | [diff] [blame] | 276 | ActivityRecord r = (ActivityRecord)msg.obj; |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 277 | // We don't at this point know if the activity is fullscreen, |
| 278 | // so we need to be conservative and assume it isn't. |
Dianne Hackborn | be70785 | 2011-11-11 14:32:10 -0800 | [diff] [blame] | 279 | Slog.w(TAG, "Activity pause timeout for " + r); |
Dianne Hackborn | 2a29b3a | 2012-03-15 15:48:38 -0700 | [diff] [blame] | 280 | synchronized (mService) { |
| 281 | if (r.app != null) { |
Craig Mautner | f7bfefb | 2013-05-16 17:30:44 -0700 | [diff] [blame] | 282 | mService.logAppTooSlow(r.app, r.pauseTime, "pausing " + r); |
Dianne Hackborn | 2a29b3a | 2012-03-15 15:48:38 -0700 | [diff] [blame] | 283 | } |
Craig Mautner | a002604 | 2014-04-23 11:45:37 -0700 | [diff] [blame] | 284 | activityPausedLocked(r.appToken, true, r.persistentState); |
Craig Mautner | d232895 | 2013-03-05 12:46:26 -0800 | [diff] [blame] | 285 | } |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 286 | } break; |
Dianne Hackborn | 2a29b3a | 2012-03-15 15:48:38 -0700 | [diff] [blame] | 287 | case LAUNCH_TICK_MSG: { |
| 288 | ActivityRecord r = (ActivityRecord)msg.obj; |
| 289 | synchronized (mService) { |
| 290 | if (r.continueLaunchTickingLocked()) { |
Craig Mautner | f7bfefb | 2013-05-16 17:30:44 -0700 | [diff] [blame] | 291 | mService.logAppTooSlow(r.app, r.launchTickTime, "launching " + r); |
Dianne Hackborn | 2a29b3a | 2012-03-15 15:48:38 -0700 | [diff] [blame] | 292 | } |
| 293 | } |
| 294 | } break; |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 295 | case DESTROY_TIMEOUT_MSG: { |
Dianne Hackborn | be70785 | 2011-11-11 14:32:10 -0800 | [diff] [blame] | 296 | ActivityRecord r = (ActivityRecord)msg.obj; |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 297 | // We don't at this point know if the activity is fullscreen, |
| 298 | // so we need to be conservative and assume it isn't. |
Dianne Hackborn | be70785 | 2011-11-11 14:32:10 -0800 | [diff] [blame] | 299 | Slog.w(TAG, "Activity destroy timeout for " + r); |
Craig Mautner | d232895 | 2013-03-05 12:46:26 -0800 | [diff] [blame] | 300 | synchronized (mService) { |
| 301 | activityDestroyedLocked(r != null ? r.appToken : null); |
| 302 | } |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 303 | } break; |
Dianne Hackborn | 162bc0e | 2012-04-09 14:06:16 -0700 | [diff] [blame] | 304 | case STOP_TIMEOUT_MSG: { |
| 305 | ActivityRecord r = (ActivityRecord)msg.obj; |
| 306 | // We don't at this point know if the activity is fullscreen, |
| 307 | // so we need to be conservative and assume it isn't. |
| 308 | Slog.w(TAG, "Activity stop timeout for " + r); |
| 309 | synchronized (mService) { |
| 310 | if (r.isInHistory()) { |
| 311 | activityStoppedLocked(r, null, null, null); |
| 312 | } |
| 313 | } |
| 314 | } break; |
Dianne Hackborn | 755c8bf | 2012-05-07 15:06:09 -0700 | [diff] [blame] | 315 | case DESTROY_ACTIVITIES_MSG: { |
| 316 | ScheduleDestroyArgs args = (ScheduleDestroyArgs)msg.obj; |
| 317 | synchronized (mService) { |
| 318 | destroyActivitiesLocked(args.mOwner, args.mOomAdj, args.mReason); |
| 319 | } |
Craig Mautner | 5eda9b3 | 2013-07-02 11:58:16 -0700 | [diff] [blame] | 320 | } break; |
| 321 | case TRANSLUCENT_TIMEOUT_MSG: { |
| 322 | synchronized (mService) { |
| 323 | notifyActivityDrawnLocked(null); |
| 324 | } |
| 325 | } break; |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 326 | } |
| 327 | } |
Craig Mautner | 4b71aa1 | 2012-12-27 17:20:01 -0800 | [diff] [blame] | 328 | } |
| 329 | |
Craig Mautner | 34b73df | 2014-01-12 21:11:08 -0800 | [diff] [blame] | 330 | int numActivities() { |
Craig Mautner | 000f002 | 2013-02-26 15:04:29 -0800 | [diff] [blame] | 331 | int count = 0; |
| 332 | for (int taskNdx = mTaskHistory.size() - 1; taskNdx >= 0; --taskNdx) { |
| 333 | count += mTaskHistory.get(taskNdx).mActivities.size(); |
| 334 | } |
| 335 | return count; |
| 336 | } |
| 337 | |
Craig Mautner | 4a1cb22 | 2013-12-04 16:14:06 -0800 | [diff] [blame] | 338 | ActivityStack(ActivityStackSupervisor.ActivityContainer activityContainer) { |
| 339 | mActivityContainer = activityContainer; |
| 340 | mStackSupervisor = activityContainer.getOuter(); |
| 341 | mService = mStackSupervisor.mService; |
| 342 | mHandler = new ActivityStackHandler(mService.mHandler.getLooper()); |
| 343 | mWindowManager = mService.mWindowManager; |
| 344 | mStackId = activityContainer.mStackId; |
| 345 | mCurrentUser = mService.mCurrentUserId; |
Winson Chung | 376543b | 2014-05-21 17:43:28 -0700 | [diff] [blame] | 346 | // Get the activity screenshot thumbnail dimensions |
| 347 | Resources res = mService.mContext.getResources(); |
Winson Chung | 2eb4f9c | 2014-05-22 11:22:41 -0700 | [diff] [blame] | 348 | mThumbnailWidth = res.getDimensionPixelSize(com.android.internal.R.dimen.thumbnail_width); |
| 349 | mThumbnailHeight = res.getDimensionPixelSize(com.android.internal.R.dimen.thumbnail_height); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 350 | } |
Craig Mautner | 5962b12 | 2012-10-05 14:45:52 -0700 | [diff] [blame] | 351 | |
Amith Yamasani | 734983f | 2014-03-04 16:48:05 -0800 | [diff] [blame] | 352 | /** |
Kenny Guy | 2a76494 | 2014-04-02 13:29:20 +0100 | [diff] [blame] | 353 | * Checks whether the userid is a profile of the current user. |
Amith Yamasani | 734983f | 2014-03-04 16:48:05 -0800 | [diff] [blame] | 354 | */ |
Kenny Guy | 2a76494 | 2014-04-02 13:29:20 +0100 | [diff] [blame] | 355 | private boolean isCurrentProfileLocked(int userId) { |
Kenny Guy | f4824a0 | 2014-04-02 19:17:41 +0100 | [diff] [blame] | 356 | if (userId == mCurrentUser) return true; |
Kenny Guy | 2a76494 | 2014-04-02 13:29:20 +0100 | [diff] [blame] | 357 | for (int i = 0; i < mService.mCurrentProfileIds.length; i++) { |
| 358 | if (mService.mCurrentProfileIds[i] == userId) return true; |
Amith Yamasani | 734983f | 2014-03-04 16:48:05 -0800 | [diff] [blame] | 359 | } |
| 360 | return false; |
| 361 | } |
| 362 | |
| 363 | boolean okToShowLocked(ActivityRecord r) { |
Kenny Guy | 2a76494 | 2014-04-02 13:29:20 +0100 | [diff] [blame] | 364 | return isCurrentProfileLocked(r.userId) |
Craig Mautner | 5962b12 | 2012-10-05 14:45:52 -0700 | [diff] [blame] | 365 | || (r.info.flags & ActivityInfo.FLAG_SHOW_ON_LOCK_SCREEN) != 0; |
| 366 | } |
| 367 | |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 368 | final ActivityRecord topRunningActivityLocked(ActivityRecord notTop) { |
Craig Mautner | d74f7d7 | 2013-02-26 13:41:02 -0800 | [diff] [blame] | 369 | for (int taskNdx = mTaskHistory.size() - 1; taskNdx >= 0; --taskNdx) { |
Craig Mautner | 6b74cb5 | 2013-09-27 17:02:21 -0700 | [diff] [blame] | 370 | ActivityRecord r = mTaskHistory.get(taskNdx).topRunningActivityLocked(notTop); |
| 371 | if (r != null) { |
| 372 | return r; |
Craig Mautner | 11bf9a5 | 2013-02-19 14:08:51 -0800 | [diff] [blame] | 373 | } |
| 374 | } |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 375 | return null; |
| 376 | } |
| 377 | |
| 378 | final ActivityRecord topRunningNonDelayedActivityLocked(ActivityRecord notTop) { |
Craig Mautner | d74f7d7 | 2013-02-26 13:41:02 -0800 | [diff] [blame] | 379 | for (int taskNdx = mTaskHistory.size() - 1; taskNdx >= 0; --taskNdx) { |
| 380 | final TaskRecord task = mTaskHistory.get(taskNdx); |
Craig Mautner | 11bf9a5 | 2013-02-19 14:08:51 -0800 | [diff] [blame] | 381 | final ArrayList<ActivityRecord> activities = task.mActivities; |
Craig Mautner | d74f7d7 | 2013-02-26 13:41:02 -0800 | [diff] [blame] | 382 | for (int activityNdx = activities.size() - 1; activityNdx >= 0; --activityNdx) { |
| 383 | ActivityRecord r = activities.get(activityNdx); |
Amith Yamasani | 734983f | 2014-03-04 16:48:05 -0800 | [diff] [blame] | 384 | if (!r.finishing && !r.delayedResume && r != notTop && okToShowLocked(r)) { |
Craig Mautner | 11bf9a5 | 2013-02-19 14:08:51 -0800 | [diff] [blame] | 385 | return r; |
| 386 | } |
| 387 | } |
| 388 | } |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 389 | return null; |
| 390 | } |
| 391 | |
| 392 | /** |
| 393 | * This is a simplified version of topRunningActivityLocked that provides a number of |
| 394 | * optional skip-over modes. It is intended for use with the ActivityController hook only. |
Craig Mautner | 9658b31 | 2013-02-28 10:55:59 -0800 | [diff] [blame] | 395 | * |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 396 | * @param token If non-null, any history records matching this token will be skipped. |
| 397 | * @param taskId If non-zero, we'll attempt to skip over records with the same task ID. |
Craig Mautner | 9658b31 | 2013-02-28 10:55:59 -0800 | [diff] [blame] | 398 | * |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 399 | * @return Returns the HistoryRecord of the next activity on the stack. |
| 400 | */ |
| 401 | final ActivityRecord topRunningActivityLocked(IBinder token, int taskId) { |
Craig Mautner | 11bf9a5 | 2013-02-19 14:08:51 -0800 | [diff] [blame] | 402 | for (int taskNdx = mTaskHistory.size() - 1; taskNdx >= 0; --taskNdx) { |
| 403 | TaskRecord task = mTaskHistory.get(taskNdx); |
| 404 | if (task.taskId == taskId) { |
| 405 | continue; |
| 406 | } |
| 407 | ArrayList<ActivityRecord> activities = task.mActivities; |
| 408 | for (int i = activities.size() - 1; i >= 0; --i) { |
| 409 | final ActivityRecord r = activities.get(i); |
| 410 | // Note: the taskId check depends on real taskId fields being non-zero |
Amith Yamasani | 734983f | 2014-03-04 16:48:05 -0800 | [diff] [blame] | 411 | if (!r.finishing && (token != r.appToken) && okToShowLocked(r)) { |
Craig Mautner | 11bf9a5 | 2013-02-19 14:08:51 -0800 | [diff] [blame] | 412 | return r; |
| 413 | } |
| 414 | } |
| 415 | } |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 416 | return null; |
| 417 | } |
| 418 | |
Craig Mautner | 8849a5e | 2013-04-02 16:41:03 -0700 | [diff] [blame] | 419 | final ActivityRecord topActivity() { |
| 420 | // Iterate to find the first non-empty task stack. Note that this code can |
Craig Mautner | de4ef02 | 2013-04-07 19:01:33 -0700 | [diff] [blame] | 421 | // be simplified once we stop storing tasks with empty mActivities lists. |
Craig Mautner | 8849a5e | 2013-04-02 16:41:03 -0700 | [diff] [blame] | 422 | for (int taskNdx = mTaskHistory.size() - 1; taskNdx >= 0; --taskNdx) { |
| 423 | ArrayList<ActivityRecord> activities = mTaskHistory.get(taskNdx).mActivities; |
Craig Mautner | a61bc65 | 2013-10-28 15:43:18 -0700 | [diff] [blame] | 424 | final int topActivityNdx = activities.size() - 1; |
| 425 | if (topActivityNdx >= 0) { |
| 426 | return activities.get(topActivityNdx); |
Craig Mautner | 8849a5e | 2013-04-02 16:41:03 -0700 | [diff] [blame] | 427 | } |
| 428 | } |
Craig Mautner | de4ef02 | 2013-04-07 19:01:33 -0700 | [diff] [blame] | 429 | return null; |
Craig Mautner | 8849a5e | 2013-04-02 16:41:03 -0700 | [diff] [blame] | 430 | } |
| 431 | |
Craig Mautner | 9e14d0f | 2013-05-01 11:26:09 -0700 | [diff] [blame] | 432 | final TaskRecord topTask() { |
| 433 | final int size = mTaskHistory.size(); |
| 434 | if (size > 0) { |
| 435 | return mTaskHistory.get(size - 1); |
| 436 | } |
| 437 | return null; |
| 438 | } |
| 439 | |
Craig Mautner | d232895 | 2013-03-05 12:46:26 -0800 | [diff] [blame] | 440 | TaskRecord taskForIdLocked(int id) { |
| 441 | for (int taskNdx = mTaskHistory.size() - 1; taskNdx >= 0; --taskNdx) { |
| 442 | final TaskRecord task = mTaskHistory.get(taskNdx); |
| 443 | if (task.taskId == id) { |
| 444 | return task; |
Craig Mautner | 5d9c7be | 2013-02-15 14:02:56 -0800 | [diff] [blame] | 445 | } |
| 446 | } |
Dianne Hackborn | ce86ba8 | 2011-07-13 19:33:41 -0700 | [diff] [blame] | 447 | return null; |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 448 | } |
| 449 | |
Craig Mautner | d232895 | 2013-03-05 12:46:26 -0800 | [diff] [blame] | 450 | ActivityRecord isInStackLocked(IBinder token) { |
Craig Mautner | 5d9c7be | 2013-02-15 14:02:56 -0800 | [diff] [blame] | 451 | final ActivityRecord r = ActivityRecord.forToken(token); |
Craig Mautner | d232895 | 2013-03-05 12:46:26 -0800 | [diff] [blame] | 452 | if (r != null) { |
| 453 | final TaskRecord task = r.task; |
| 454 | if (task.mActivities.contains(r) && mTaskHistory.contains(task)) { |
| 455 | if (task.stack != this) Slog.w(TAG, |
| 456 | "Illegal state! task does not point to stack it is in."); |
| 457 | return r; |
| 458 | } |
Craig Mautner | 5d9c7be | 2013-02-15 14:02:56 -0800 | [diff] [blame] | 459 | } |
Craig Mautner | d232895 | 2013-03-05 12:46:26 -0800 | [diff] [blame] | 460 | return null; |
Craig Mautner | 5d9c7be | 2013-02-15 14:02:56 -0800 | [diff] [blame] | 461 | } |
| 462 | |
Craig Mautner | 2420ead | 2013-04-01 17:13:20 -0700 | [diff] [blame] | 463 | final boolean updateLRUListLocked(ActivityRecord r) { |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 464 | final boolean hadit = mLRUActivities.remove(r); |
| 465 | mLRUActivities.add(r); |
| 466 | return hadit; |
| 467 | } |
| 468 | |
Craig Mautner | de4ef02 | 2013-04-07 19:01:33 -0700 | [diff] [blame] | 469 | final boolean isHomeStack() { |
| 470 | return mStackId == HOME_STACK_ID; |
| 471 | } |
| 472 | |
Craig Mautner | e0a3884 | 2013-12-16 16:14:02 -0800 | [diff] [blame] | 473 | final boolean isOnHomeDisplay() { |
| 474 | return isAttached() && |
| 475 | mActivityContainer.mActivityDisplay.mDisplayId == Display.DEFAULT_DISPLAY; |
| 476 | } |
| 477 | |
| 478 | final void moveToFront() { |
| 479 | if (isAttached()) { |
Craig Mautner | e0a3884 | 2013-12-16 16:14:02 -0800 | [diff] [blame] | 480 | if (isOnHomeDisplay()) { |
| 481 | mStackSupervisor.moveHomeStack(isHomeStack()); |
| 482 | } |
Craig Mautner | fefeef8 | 2014-01-10 08:40:23 -0800 | [diff] [blame] | 483 | mStacks.remove(this); |
| 484 | mStacks.add(this); |
Craig Mautner | 4a1cb22 | 2013-12-04 16:14:06 -0800 | [diff] [blame] | 485 | } |
Craig Mautner | e0a3884 | 2013-12-16 16:14:02 -0800 | [diff] [blame] | 486 | } |
| 487 | |
| 488 | final boolean isAttached() { |
| 489 | return mStacks != null; |
Craig Mautner | 4a1cb22 | 2013-12-04 16:14:06 -0800 | [diff] [blame] | 490 | } |
| 491 | |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 492 | /** |
| 493 | * Returns the top activity in any existing task matching the given |
| 494 | * Intent. Returns null if no such task is found. |
| 495 | */ |
Craig Mautner | ac6f843 | 2013-07-17 13:24:59 -0700 | [diff] [blame] | 496 | ActivityRecord findTaskLocked(ActivityRecord target) { |
| 497 | Intent intent = target.intent; |
| 498 | ActivityInfo info = target.info; |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 499 | ComponentName cls = intent.getComponent(); |
| 500 | if (info.targetActivity != null) { |
| 501 | cls = new ComponentName(info.packageName, info.targetActivity); |
| 502 | } |
Dianne Hackborn | f02b60a | 2012-08-16 10:48:27 -0700 | [diff] [blame] | 503 | final int userId = UserHandle.getUserId(info.applicationInfo.uid); |
Craig Mautner | d00f474 | 2014-03-12 14:17:26 -0700 | [diff] [blame] | 504 | boolean isDocument = intent != null & intent.isDocument(); |
| 505 | // If documentData is non-null then it must match the existing task data. |
| 506 | Uri documentData = isDocument ? intent.getData() : null; |
Craig Mautner | 000f002 | 2013-02-26 15:04:29 -0800 | [diff] [blame] | 507 | |
Dianne Hackborn | 2a272d4 | 2013-10-16 13:34:33 -0700 | [diff] [blame] | 508 | if (DEBUG_TASKS) Slog.d(TAG, "Looking for task of " + target + " in " + this); |
Craig Mautner | 000f002 | 2013-02-26 15:04:29 -0800 | [diff] [blame] | 509 | for (int taskNdx = mTaskHistory.size() - 1; taskNdx >= 0; --taskNdx) { |
| 510 | final TaskRecord task = mTaskHistory.get(taskNdx); |
Dianne Hackborn | 91097de | 2014-04-04 18:02:06 -0700 | [diff] [blame] | 511 | if (task.voiceSession != null) { |
| 512 | // We never match voice sessions; those always run independently. |
| 513 | if (DEBUG_TASKS) Slog.d(TAG, "Skipping " + task + ": voice session"); |
| 514 | continue; |
| 515 | } |
Craig Mautner | ac6f843 | 2013-07-17 13:24:59 -0700 | [diff] [blame] | 516 | if (task.userId != userId) { |
| 517 | // Looking for a different task. |
Dianne Hackborn | 2a272d4 | 2013-10-16 13:34:33 -0700 | [diff] [blame] | 518 | if (DEBUG_TASKS) Slog.d(TAG, "Skipping " + task + ": different user"); |
Craig Mautner | ac6f843 | 2013-07-17 13:24:59 -0700 | [diff] [blame] | 519 | continue; |
| 520 | } |
Craig Mautner | 000f002 | 2013-02-26 15:04:29 -0800 | [diff] [blame] | 521 | final ActivityRecord r = task.getTopActivity(); |
| 522 | if (r == null || r.finishing || r.userId != userId || |
| 523 | r.launchMode == ActivityInfo.LAUNCH_SINGLE_INSTANCE) { |
Dianne Hackborn | 2a272d4 | 2013-10-16 13:34:33 -0700 | [diff] [blame] | 524 | if (DEBUG_TASKS) Slog.d(TAG, "Skipping " + task + ": mismatch root " + r); |
Craig Mautner | 000f002 | 2013-02-26 15:04:29 -0800 | [diff] [blame] | 525 | continue; |
| 526 | } |
| 527 | |
Craig Mautner | d00f474 | 2014-03-12 14:17:26 -0700 | [diff] [blame] | 528 | final Intent taskIntent = task.intent; |
| 529 | final Intent affinityIntent = task.affinityIntent; |
| 530 | final boolean taskIsDocument; |
| 531 | final Uri taskDocumentData; |
| 532 | if (taskIntent != null && taskIntent.isDocument()) { |
| 533 | taskIsDocument = true; |
| 534 | taskDocumentData = taskIntent.getData(); |
| 535 | } else if (affinityIntent != null && affinityIntent.isDocument()) { |
| 536 | taskIsDocument = true; |
| 537 | taskDocumentData = affinityIntent.getData(); |
| 538 | } else { |
| 539 | taskIsDocument = false; |
| 540 | taskDocumentData = null; |
| 541 | } |
| 542 | |
Dianne Hackborn | 2a272d4 | 2013-10-16 13:34:33 -0700 | [diff] [blame] | 543 | if (DEBUG_TASKS) Slog.d(TAG, "Comparing existing cls=" |
Craig Mautner | d00f474 | 2014-03-12 14:17:26 -0700 | [diff] [blame] | 544 | + taskIntent.getComponent().flattenToShortString() |
Dianne Hackborn | 2a272d4 | 2013-10-16 13:34:33 -0700 | [diff] [blame] | 545 | + "/aff=" + r.task.affinity + " to new cls=" |
| 546 | + intent.getComponent().flattenToShortString() + "/aff=" + info.taskAffinity); |
Craig Mautner | d00f474 | 2014-03-12 14:17:26 -0700 | [diff] [blame] | 547 | if (!isDocument && !taskIsDocument && task.affinity != null) { |
| 548 | if (task.affinity.equals(target.taskAffinity)) { |
Dianne Hackborn | 2a272d4 | 2013-10-16 13:34:33 -0700 | [diff] [blame] | 549 | if (DEBUG_TASKS) Slog.d(TAG, "Found matching affinity!"); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 550 | return r; |
| 551 | } |
Craig Mautner | ffcfcaa | 2014-06-05 09:54:38 -0700 | [diff] [blame^] | 552 | } else if (taskIntent != null && taskIntent.getComponent() != null && |
| 553 | taskIntent.getComponent().compareTo(cls) == 0 && |
Craig Mautner | d00f474 | 2014-03-12 14:17:26 -0700 | [diff] [blame] | 554 | Objects.equals(documentData, taskDocumentData)) { |
Dianne Hackborn | 2a272d4 | 2013-10-16 13:34:33 -0700 | [diff] [blame] | 555 | if (DEBUG_TASKS) Slog.d(TAG, "Found matching class!"); |
Craig Mautner | 000f002 | 2013-02-26 15:04:29 -0800 | [diff] [blame] | 556 | //dump(); |
Dianne Hackborn | 2a272d4 | 2013-10-16 13:34:33 -0700 | [diff] [blame] | 557 | if (DEBUG_TASKS) Slog.d(TAG, "For Intent " + intent + " bringing to top: " |
| 558 | + r.intent); |
Craig Mautner | 000f002 | 2013-02-26 15:04:29 -0800 | [diff] [blame] | 559 | return r; |
Craig Mautner | ffcfcaa | 2014-06-05 09:54:38 -0700 | [diff] [blame^] | 560 | } else if (affinityIntent != null && affinityIntent.getComponent() != null && |
| 561 | affinityIntent.getComponent().compareTo(cls) == 0 && |
Craig Mautner | d00f474 | 2014-03-12 14:17:26 -0700 | [diff] [blame] | 562 | Objects.equals(documentData, taskDocumentData)) { |
Dianne Hackborn | 2a272d4 | 2013-10-16 13:34:33 -0700 | [diff] [blame] | 563 | if (DEBUG_TASKS) Slog.d(TAG, "Found matching class!"); |
Craig Mautner | 000f002 | 2013-02-26 15:04:29 -0800 | [diff] [blame] | 564 | //dump(); |
Dianne Hackborn | 2a272d4 | 2013-10-16 13:34:33 -0700 | [diff] [blame] | 565 | if (DEBUG_TASKS) Slog.d(TAG, "For Intent " + intent + " bringing to top: " |
| 566 | + r.intent); |
Craig Mautner | 000f002 | 2013-02-26 15:04:29 -0800 | [diff] [blame] | 567 | return r; |
Dianne Hackborn | 2a272d4 | 2013-10-16 13:34:33 -0700 | [diff] [blame] | 568 | } else if (DEBUG_TASKS) { |
| 569 | Slog.d(TAG, "Not a match: " + task); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 570 | } |
| 571 | } |
| 572 | |
| 573 | return null; |
| 574 | } |
| 575 | |
| 576 | /** |
| 577 | * Returns the first activity (starting from the top of the stack) that |
| 578 | * is the same as the given activity. Returns null if no such activity |
| 579 | * is found. |
| 580 | */ |
Craig Mautner | 8849a5e | 2013-04-02 16:41:03 -0700 | [diff] [blame] | 581 | ActivityRecord findActivityLocked(Intent intent, ActivityInfo info) { |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 582 | ComponentName cls = intent.getComponent(); |
| 583 | if (info.targetActivity != null) { |
| 584 | cls = new ComponentName(info.packageName, info.targetActivity); |
| 585 | } |
Dianne Hackborn | f02b60a | 2012-08-16 10:48:27 -0700 | [diff] [blame] | 586 | final int userId = UserHandle.getUserId(info.applicationInfo.uid); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 587 | |
Craig Mautner | 000f002 | 2013-02-26 15:04:29 -0800 | [diff] [blame] | 588 | for (int taskNdx = mTaskHistory.size() - 1; taskNdx >= 0; --taskNdx) { |
Craig Mautner | ac6f843 | 2013-07-17 13:24:59 -0700 | [diff] [blame] | 589 | TaskRecord task = mTaskHistory.get(taskNdx); |
Kenny Guy | 2a76494 | 2014-04-02 13:29:20 +0100 | [diff] [blame] | 590 | if (!isCurrentProfileLocked(task.userId)) { |
Craig Mautner | ac6f843 | 2013-07-17 13:24:59 -0700 | [diff] [blame] | 591 | return null; |
| 592 | } |
| 593 | final ArrayList<ActivityRecord> activities = task.mActivities; |
Craig Mautner | 000f002 | 2013-02-26 15:04:29 -0800 | [diff] [blame] | 594 | for (int activityNdx = activities.size() - 1; activityNdx >= 0; --activityNdx) { |
| 595 | ActivityRecord r = activities.get(activityNdx); |
| 596 | if (!r.finishing && r.intent.getComponent().equals(cls) && r.userId == userId) { |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 597 | //Slog.i(TAG, "Found matching class!"); |
| 598 | //dump(); |
| 599 | //Slog.i(TAG, "For Intent " + intent + " bringing to top: " + r.intent); |
| 600 | return r; |
| 601 | } |
| 602 | } |
| 603 | } |
| 604 | |
| 605 | return null; |
| 606 | } |
| 607 | |
Amith Yamasani | 742a671 | 2011-05-04 14:49:28 -0700 | [diff] [blame] | 608 | /* |
Craig Mautner | ac6f843 | 2013-07-17 13:24:59 -0700 | [diff] [blame] | 609 | * Move the activities around in the stack to bring a user to the foreground. |
Amith Yamasani | 742a671 | 2011-05-04 14:49:28 -0700 | [diff] [blame] | 610 | */ |
Craig Mautner | 93529a4 | 2013-10-04 15:03:13 -0700 | [diff] [blame] | 611 | final void switchUserLocked(int userId) { |
Craig Mautner | 5d9c7be | 2013-02-15 14:02:56 -0800 | [diff] [blame] | 612 | if (mCurrentUser == userId) { |
Craig Mautner | 93529a4 | 2013-10-04 15:03:13 -0700 | [diff] [blame] | 613 | return; |
Craig Mautner | 5d9c7be | 2013-02-15 14:02:56 -0800 | [diff] [blame] | 614 | } |
| 615 | mCurrentUser = userId; |
| 616 | |
| 617 | // Move userId's tasks to the top. |
Craig Mautner | 5d9c7be | 2013-02-15 14:02:56 -0800 | [diff] [blame] | 618 | int index = mTaskHistory.size(); |
Craig Mautner | db5c4fb | 2013-11-06 13:55:08 -0800 | [diff] [blame] | 619 | for (int i = 0; i < index; ) { |
Craig Mautner | b59dcfd | 2013-05-06 13:12:58 -0700 | [diff] [blame] | 620 | TaskRecord task = mTaskHistory.get(i); |
Kenny Guy | 2a76494 | 2014-04-02 13:29:20 +0100 | [diff] [blame] | 621 | if (isCurrentProfileLocked(task.userId)) { |
Craig Mautner | 4f1df4f | 2013-10-15 15:44:14 -0700 | [diff] [blame] | 622 | if (DEBUG_TASKS) Slog.d(TAG, "switchUserLocked: stack=" + getStackId() + |
| 623 | " moving " + task + " to top"); |
Craig Mautner | 5d9c7be | 2013-02-15 14:02:56 -0800 | [diff] [blame] | 624 | mTaskHistory.remove(i); |
| 625 | mTaskHistory.add(task); |
| 626 | --index; |
Craig Mautner | db5c4fb | 2013-11-06 13:55:08 -0800 | [diff] [blame] | 627 | // Use same value for i. |
| 628 | } else { |
| 629 | ++i; |
Craig Mautner | 5d9c7be | 2013-02-15 14:02:56 -0800 | [diff] [blame] | 630 | } |
| 631 | } |
Craig Mautner | 4f1df4f | 2013-10-15 15:44:14 -0700 | [diff] [blame] | 632 | if (VALIDATE_TOKENS) { |
| 633 | validateAppTokensLocked(); |
| 634 | } |
Amith Yamasani | 742a671 | 2011-05-04 14:49:28 -0700 | [diff] [blame] | 635 | } |
| 636 | |
Craig Mautner | 2420ead | 2013-04-01 17:13:20 -0700 | [diff] [blame] | 637 | void minimalResumeActivityLocked(ActivityRecord r) { |
| 638 | r.state = ActivityState.RESUMED; |
| 639 | if (DEBUG_STATES) Slog.v(TAG, "Moving to RESUMED: " + r |
| 640 | + " (starting new instance)"); |
| 641 | r.stopped = false; |
| 642 | mResumedActivity = r; |
| 643 | r.task.touchActiveTime(); |
| 644 | mService.addRecentTaskLocked(r.task); |
| 645 | completeResumeLocked(r); |
Craig Mautner | 0eea92c | 2013-05-16 13:35:39 -0700 | [diff] [blame] | 646 | mStackSupervisor.checkReadyForSleepLocked(); |
Craig Mautner | 1e8b872 | 2013-10-14 18:24:52 -0700 | [diff] [blame] | 647 | setLaunchTime(r); |
Craig Mautner | 2420ead | 2013-04-01 17:13:20 -0700 | [diff] [blame] | 648 | if (DEBUG_SAVED_STATE) Slog.i(TAG, "Launch completed; removing icicle of " + r.icicle); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 649 | } |
| 650 | |
Dianne Hackborn | cee04b5 | 2013-07-03 17:01:28 -0700 | [diff] [blame] | 651 | private void startLaunchTraces() { |
| 652 | if (mFullyDrawnStartTime != 0) { |
| 653 | Trace.asyncTraceEnd(Trace.TRACE_TAG_ACTIVITY_MANAGER, "drawing", 0); |
| 654 | } |
| 655 | Trace.asyncTraceBegin(Trace.TRACE_TAG_ACTIVITY_MANAGER, "launching", 0); |
| 656 | Trace.asyncTraceBegin(Trace.TRACE_TAG_ACTIVITY_MANAGER, "drawing", 0); |
| 657 | } |
| 658 | |
| 659 | private void stopFullyDrawnTraceIfNeeded() { |
| 660 | if (mFullyDrawnStartTime != 0 && mLaunchStartTime == 0) { |
| 661 | Trace.asyncTraceEnd(Trace.TRACE_TAG_ACTIVITY_MANAGER, "drawing", 0); |
| 662 | mFullyDrawnStartTime = 0; |
| 663 | } |
| 664 | } |
| 665 | |
Craig Mautner | e79d4268 | 2013-04-01 19:01:53 -0700 | [diff] [blame] | 666 | void setLaunchTime(ActivityRecord r) { |
Dianne Hackborn | 2286cdc | 2013-07-01 19:10:06 -0700 | [diff] [blame] | 667 | if (r.displayStartTime == 0) { |
| 668 | r.fullyDrawnStartTime = r.displayStartTime = SystemClock.uptimeMillis(); |
| 669 | if (mLaunchStartTime == 0) { |
Dianne Hackborn | cee04b5 | 2013-07-03 17:01:28 -0700 | [diff] [blame] | 670 | startLaunchTraces(); |
Dianne Hackborn | 2286cdc | 2013-07-01 19:10:06 -0700 | [diff] [blame] | 671 | mLaunchStartTime = mFullyDrawnStartTime = r.displayStartTime; |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 672 | } |
Dianne Hackborn | 2286cdc | 2013-07-01 19:10:06 -0700 | [diff] [blame] | 673 | } else if (mLaunchStartTime == 0) { |
Dianne Hackborn | cee04b5 | 2013-07-03 17:01:28 -0700 | [diff] [blame] | 674 | startLaunchTraces(); |
Dianne Hackborn | 2286cdc | 2013-07-01 19:10:06 -0700 | [diff] [blame] | 675 | mLaunchStartTime = mFullyDrawnStartTime = SystemClock.uptimeMillis(); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 676 | } |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 677 | } |
Craig Mautner | aab647e | 2013-02-28 16:31:36 -0800 | [diff] [blame] | 678 | |
Dianne Hackborn | 2286cdc | 2013-07-01 19:10:06 -0700 | [diff] [blame] | 679 | void clearLaunchTime(ActivityRecord r) { |
Craig Mautner | 5c49454 | 2013-09-06 11:59:38 -0700 | [diff] [blame] | 680 | // Make sure that there is no activity waiting for this to launch. |
| 681 | if (mStackSupervisor.mWaitingActivityLaunched.isEmpty()) { |
| 682 | r.displayStartTime = r.fullyDrawnStartTime = 0; |
| 683 | } else { |
| 684 | mStackSupervisor.removeTimeoutsForActivityLocked(r); |
| 685 | mStackSupervisor.scheduleIdleTimeoutLocked(r); |
| 686 | } |
Dianne Hackborn | 2286cdc | 2013-07-01 19:10:06 -0700 | [diff] [blame] | 687 | } |
| 688 | |
Dianne Hackborn | 4eba96b | 2011-01-21 13:34:36 -0800 | [diff] [blame] | 689 | void awakeFromSleepingLocked() { |
Dianne Hackborn | 4eba96b | 2011-01-21 13:34:36 -0800 | [diff] [blame] | 690 | // Ensure activities are no longer sleeping. |
Craig Mautner | d44711d | 2013-02-23 11:24:36 -0800 | [diff] [blame] | 691 | for (int taskNdx = mTaskHistory.size() - 1; taskNdx >= 0; --taskNdx) { |
| 692 | final ArrayList<ActivityRecord> activities = mTaskHistory.get(taskNdx).mActivities; |
| 693 | for (int activityNdx = activities.size() - 1; activityNdx >= 0; --activityNdx) { |
| 694 | activities.get(activityNdx).setSleeping(false); |
| 695 | } |
Dianne Hackborn | 4eba96b | 2011-01-21 13:34:36 -0800 | [diff] [blame] | 696 | } |
Dianne Hackborn | 4eba96b | 2011-01-21 13:34:36 -0800 | [diff] [blame] | 697 | } |
| 698 | |
Craig Mautner | 0eea92c | 2013-05-16 13:35:39 -0700 | [diff] [blame] | 699 | /** |
| 700 | * @return true if something must be done before going to sleep. |
| 701 | */ |
| 702 | boolean checkReadyForSleepLocked() { |
| 703 | if (mResumedActivity != null) { |
| 704 | // Still have something resumed; can't sleep until it is paused. |
| 705 | if (DEBUG_PAUSE) Slog.v(TAG, "Sleep needs to pause " + mResumedActivity); |
| 706 | if (DEBUG_USER_LEAVING) Slog.v(TAG, "Sleep => pause with userLeaving=false"); |
| 707 | startPausingLocked(false, true); |
| 708 | return true; |
| 709 | } |
| 710 | if (mPausingActivity != null) { |
| 711 | // Still waiting for something to pause; can't sleep yet. |
| 712 | if (DEBUG_PAUSE) Slog.v(TAG, "Sleep still waiting to pause " + mPausingActivity); |
| 713 | return true; |
Dianne Hackborn | 4eba96b | 2011-01-21 13:34:36 -0800 | [diff] [blame] | 714 | } |
| 715 | |
Craig Mautner | 0eea92c | 2013-05-16 13:35:39 -0700 | [diff] [blame] | 716 | return false; |
| 717 | } |
Dianne Hackborn | 4eba96b | 2011-01-21 13:34:36 -0800 | [diff] [blame] | 718 | |
Craig Mautner | 0eea92c | 2013-05-16 13:35:39 -0700 | [diff] [blame] | 719 | void goToSleep() { |
| 720 | ensureActivitiesVisibleLocked(null, 0); |
Dianne Hackborn | 4eba96b | 2011-01-21 13:34:36 -0800 | [diff] [blame] | 721 | |
Craig Mautner | 0eea92c | 2013-05-16 13:35:39 -0700 | [diff] [blame] | 722 | // Make sure any stopped but visible activities are now sleeping. |
| 723 | // This ensures that the activity's onStop() is called. |
| 724 | for (int taskNdx = mTaskHistory.size() - 1; taskNdx >= 0; --taskNdx) { |
| 725 | final ArrayList<ActivityRecord> activities = mTaskHistory.get(taskNdx).mActivities; |
| 726 | for (int activityNdx = activities.size() - 1; activityNdx >= 0; --activityNdx) { |
| 727 | final ActivityRecord r = activities.get(activityNdx); |
| 728 | if (r.state == ActivityState.STOPPING || r.state == ActivityState.STOPPED) { |
| 729 | r.setSleeping(true); |
Dianne Hackborn | 4eba96b | 2011-01-21 13:34:36 -0800 | [diff] [blame] | 730 | } |
| 731 | } |
Dianne Hackborn | 4eba96b | 2011-01-21 13:34:36 -0800 | [diff] [blame] | 732 | } |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 733 | } |
Craig Mautner | 59c0097 | 2012-07-30 12:10:24 -0700 | [diff] [blame] | 734 | |
Winson Chung | 376543b | 2014-05-21 17:43:28 -0700 | [diff] [blame] | 735 | /** |
| 736 | * This resets the saved state from the last screenshot, forcing a new screenshot to be taken |
| 737 | * again when requested. |
| 738 | */ |
| 739 | private void invalidateLastScreenshot() { |
| 740 | mLastScreenshotActivity = null; |
| 741 | if (mLastScreenshotBitmap != null) { |
| 742 | mLastScreenshotBitmap.recycle(); |
| 743 | } |
| 744 | mLastScreenshotBitmap = null; |
| 745 | } |
| 746 | |
Dianne Hackborn | d283593 | 2010-12-13 16:28:46 -0800 | [diff] [blame] | 747 | public final Bitmap screenshotActivities(ActivityRecord who) { |
Winson Chung | 376543b | 2014-05-21 17:43:28 -0700 | [diff] [blame] | 748 | if (DEBUG_SCREENSHOTS) Slog.d(TAG, "screenshotActivities: " + who); |
Dianne Hackborn | ff801ec | 2011-01-22 18:05:38 -0800 | [diff] [blame] | 749 | if (who.noDisplay) { |
Winson Chung | 376543b | 2014-05-21 17:43:28 -0700 | [diff] [blame] | 750 | if (DEBUG_SCREENSHOTS) Slog.d(TAG, "\tNo display"); |
Dianne Hackborn | ff801ec | 2011-01-22 18:05:38 -0800 | [diff] [blame] | 751 | return null; |
| 752 | } |
Craig Mautner | aab647e | 2013-02-28 16:31:36 -0800 | [diff] [blame] | 753 | |
Dianne Hackborn | 4d03fe6 | 2013-10-04 17:26:37 -0700 | [diff] [blame] | 754 | TaskRecord tr = who.task; |
Winson Chung | 376543b | 2014-05-21 17:43:28 -0700 | [diff] [blame] | 755 | if (mService.getMostRecentTask() != tr || isHomeStack()) { |
| 756 | // This is an optimization -- since we never show Home or Recents within Recents itself, |
| 757 | // we can just go ahead and skip taking the screenshot if this is the home stack. In |
| 758 | // the case where the most recent task is not the task that was supplied, then the stack |
| 759 | // has changed, so invalidate the last screenshot(). |
| 760 | invalidateLastScreenshot(); |
| 761 | if (DEBUG_SCREENSHOTS) Slog.d(TAG, "\tIs Home stack? " + isHomeStack()); |
Dianne Hackborn | 4d03fe6 | 2013-10-04 17:26:37 -0700 | [diff] [blame] | 762 | return null; |
| 763 | } |
| 764 | |
Dianne Hackborn | 0aae2d4 | 2010-12-07 23:51:29 -0800 | [diff] [blame] | 765 | int w = mThumbnailWidth; |
| 766 | int h = mThumbnailHeight; |
Dianne Hackborn | 0aae2d4 | 2010-12-07 23:51:29 -0800 | [diff] [blame] | 767 | if (w > 0) { |
Craig Mautner | b12428a | 2012-12-20 16:07:06 -0800 | [diff] [blame] | 768 | if (who != mLastScreenshotActivity || mLastScreenshotBitmap == null |
Dianne Hackborn | 4d03fe6 | 2013-10-04 17:26:37 -0700 | [diff] [blame] | 769 | || mLastScreenshotActivity.state == ActivityState.RESUMED |
Craig Mautner | b12428a | 2012-12-20 16:07:06 -0800 | [diff] [blame] | 770 | || mLastScreenshotBitmap.getWidth() != w |
| 771 | || mLastScreenshotBitmap.getHeight() != h) { |
Winson Chung | 376543b | 2014-05-21 17:43:28 -0700 | [diff] [blame] | 772 | if (DEBUG_SCREENSHOTS) Slog.d(TAG, "\tUpdating screenshot"); |
Craig Mautner | b12428a | 2012-12-20 16:07:06 -0800 | [diff] [blame] | 773 | mLastScreenshotActivity = who; |
Craig Mautner | ce5f3cb | 2013-04-22 08:58:54 -0700 | [diff] [blame] | 774 | mLastScreenshotBitmap = mWindowManager.screenshotApplications( |
John Reck | 172e87c | 2013-10-02 16:55:16 -0700 | [diff] [blame] | 775 | who.appToken, Display.DEFAULT_DISPLAY, w, h, SCREENSHOT_FORCE_565); |
Craig Mautner | b12428a | 2012-12-20 16:07:06 -0800 | [diff] [blame] | 776 | } |
| 777 | if (mLastScreenshotBitmap != null) { |
Winson Chung | 376543b | 2014-05-21 17:43:28 -0700 | [diff] [blame] | 778 | if (DEBUG_SCREENSHOTS) Slog.d(TAG, "\tReusing last screenshot"); |
John Reck | 172e87c | 2013-10-02 16:55:16 -0700 | [diff] [blame] | 779 | return mLastScreenshotBitmap.copy(mLastScreenshotBitmap.getConfig(), true); |
Craig Mautner | b12428a | 2012-12-20 16:07:06 -0800 | [diff] [blame] | 780 | } |
Dianne Hackborn | 0aae2d4 | 2010-12-07 23:51:29 -0800 | [diff] [blame] | 781 | } |
Winson Chung | 376543b | 2014-05-21 17:43:28 -0700 | [diff] [blame] | 782 | Slog.e(TAG, "Invalid thumbnail dimensions: " + w + "x" + h); |
Dianne Hackborn | 0aae2d4 | 2010-12-07 23:51:29 -0800 | [diff] [blame] | 783 | return null; |
| 784 | } |
| 785 | |
Craig Mautner | cf910b0 | 2013-04-23 11:23:27 -0700 | [diff] [blame] | 786 | final void startPausingLocked(boolean userLeaving, boolean uiSleeping) { |
Dianne Hackborn | 621e2fe | 2012-02-16 17:07:33 -0800 | [diff] [blame] | 787 | if (mPausingActivity != null) { |
Dianne Hackborn | 621e2fe | 2012-02-16 17:07:33 -0800 | [diff] [blame] | 788 | Slog.e(TAG, "Trying to pause when pause is already pending for " |
Craig Mautner | e11f2b7 | 2013-04-01 12:37:17 -0700 | [diff] [blame] | 789 | + mPausingActivity, new RuntimeException("here").fillInStackTrace()); |
Dianne Hackborn | 621e2fe | 2012-02-16 17:07:33 -0800 | [diff] [blame] | 790 | } |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 791 | ActivityRecord prev = mResumedActivity; |
| 792 | if (prev == null) { |
Craig Mautner | e11f2b7 | 2013-04-01 12:37:17 -0700 | [diff] [blame] | 793 | Slog.e(TAG, "Trying to pause when nothing is resumed", |
| 794 | new RuntimeException("here").fillInStackTrace()); |
Craig Mautner | 05d2903 | 2013-05-03 13:40:13 -0700 | [diff] [blame] | 795 | mStackSupervisor.resumeTopActivitiesLocked(); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 796 | return; |
| 797 | } |
Craig Mautner | df88d73 | 2014-01-27 09:21:32 -0800 | [diff] [blame] | 798 | |
| 799 | if (mActivityContainer.mParentActivity == null) { |
| 800 | // Top level stack, not a child. Look for child stacks. |
| 801 | mStackSupervisor.pauseChildStacks(prev, userLeaving, uiSleeping); |
| 802 | } |
| 803 | |
Dianne Hackborn | ce86ba8 | 2011-07-13 19:33:41 -0700 | [diff] [blame] | 804 | if (DEBUG_STATES) Slog.v(TAG, "Moving to PAUSING: " + prev); |
| 805 | else if (DEBUG_PAUSE) Slog.v(TAG, "Start pausing: " + prev); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 806 | mResumedActivity = null; |
Dianne Hackborn | 621e2fe | 2012-02-16 17:07:33 -0800 | [diff] [blame] | 807 | mPausingActivity = prev; |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 808 | mLastPausedActivity = prev; |
Craig Mautner | 0f92274 | 2013-08-06 08:44:42 -0700 | [diff] [blame] | 809 | mLastNoHistoryActivity = (prev.intent.getFlags() & Intent.FLAG_ACTIVITY_NO_HISTORY) != 0 |
| 810 | || (prev.info.flags & ActivityInfo.FLAG_NO_HISTORY) != 0 ? prev : null; |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 811 | prev.state = ActivityState.PAUSING; |
| 812 | prev.task.touchActiveTime(); |
Dianne Hackborn | 2286cdc | 2013-07-01 19:10:06 -0700 | [diff] [blame] | 813 | clearLaunchTime(prev); |
Craig Mautner | 6f6d56f | 2013-10-24 16:02:07 -0700 | [diff] [blame] | 814 | final ActivityRecord next = mStackSupervisor.topRunningActivityLocked(); |
Craig Mautner | f6ead5d6 | 2014-04-24 10:19:20 -0700 | [diff] [blame] | 815 | if (next == null || next.noDisplay || next.task != prev.task) { |
Craig Mautner | 6f6d56f | 2013-10-24 16:02:07 -0700 | [diff] [blame] | 816 | prev.updateThumbnail(screenshotActivities(prev), null); |
| 817 | } |
Dianne Hackborn | cee04b5 | 2013-07-03 17:01:28 -0700 | [diff] [blame] | 818 | stopFullyDrawnTraceIfNeeded(); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 819 | |
| 820 | mService.updateCpuStats(); |
Craig Mautner | aab647e | 2013-02-28 16:31:36 -0800 | [diff] [blame] | 821 | |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 822 | if (prev.app != null && prev.app.thread != null) { |
| 823 | if (DEBUG_PAUSE) Slog.v(TAG, "Enqueueing pending pause: " + prev); |
| 824 | try { |
| 825 | EventLog.writeEvent(EventLogTags.AM_PAUSE_ACTIVITY, |
Dianne Hackborn | b12e135 | 2012-09-26 11:39:20 -0700 | [diff] [blame] | 826 | prev.userId, System.identityHashCode(prev), |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 827 | prev.shortComponentName); |
Jeff Sharkey | 5782da7 | 2013-04-25 14:32:30 -0700 | [diff] [blame] | 828 | mService.updateUsageStats(prev, false); |
Dianne Hackborn | be70785 | 2011-11-11 14:32:10 -0800 | [diff] [blame] | 829 | prev.app.thread.schedulePauseActivity(prev.appToken, prev.finishing, |
| 830 | userLeaving, prev.configChangeFlags); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 831 | } catch (Exception e) { |
| 832 | // Ignore exception, if process died other code will cleanup. |
| 833 | Slog.w(TAG, "Exception thrown during pause", e); |
Dianne Hackborn | 621e2fe | 2012-02-16 17:07:33 -0800 | [diff] [blame] | 834 | mPausingActivity = null; |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 835 | mLastPausedActivity = null; |
Craig Mautner | 0f92274 | 2013-08-06 08:44:42 -0700 | [diff] [blame] | 836 | mLastNoHistoryActivity = null; |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 837 | } |
| 838 | } else { |
Dianne Hackborn | 621e2fe | 2012-02-16 17:07:33 -0800 | [diff] [blame] | 839 | mPausingActivity = null; |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 840 | mLastPausedActivity = null; |
Craig Mautner | 0f92274 | 2013-08-06 08:44:42 -0700 | [diff] [blame] | 841 | mLastNoHistoryActivity = null; |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 842 | } |
| 843 | |
| 844 | // If we are not going to sleep, we want to ensure the device is |
| 845 | // awake until the next activity is started. |
Craig Mautner | e11f2b7 | 2013-04-01 12:37:17 -0700 | [diff] [blame] | 846 | if (!mService.isSleepingOrShuttingDown()) { |
Craig Mautner | 7ea5bd4 | 2013-07-05 15:27:08 -0700 | [diff] [blame] | 847 | mStackSupervisor.acquireLaunchWakelock(); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 848 | } |
| 849 | |
Dianne Hackborn | 621e2fe | 2012-02-16 17:07:33 -0800 | [diff] [blame] | 850 | if (mPausingActivity != null) { |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 851 | // Have the window manager pause its key dispatching until the new |
| 852 | // activity has started. If we're pausing the activity just because |
| 853 | // the screen is being turned off and the UI is sleeping, don't interrupt |
| 854 | // key dispatch; the same activity will pick it up again on wakeup. |
| 855 | if (!uiSleeping) { |
Dianne Hackborn | 621e2fe | 2012-02-16 17:07:33 -0800 | [diff] [blame] | 856 | prev.pauseKeyDispatchingLocked(); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 857 | } else { |
| 858 | if (DEBUG_PAUSE) Slog.v(TAG, "Key dispatch not paused for screen off"); |
| 859 | } |
| 860 | |
| 861 | // Schedule a pause timeout in case the app doesn't respond. |
| 862 | // We don't give it much time because this directly impacts the |
| 863 | // responsiveness seen by the user. |
| 864 | Message msg = mHandler.obtainMessage(PAUSE_TIMEOUT_MSG); |
| 865 | msg.obj = prev; |
Dianne Hackborn | 2a29b3a | 2012-03-15 15:48:38 -0700 | [diff] [blame] | 866 | prev.pauseTime = SystemClock.uptimeMillis(); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 867 | mHandler.sendMessageDelayed(msg, PAUSE_TIMEOUT); |
| 868 | if (DEBUG_PAUSE) Slog.v(TAG, "Waiting for pause to complete..."); |
| 869 | } else { |
| 870 | // This activity failed to schedule the |
| 871 | // pause, so just treat it as being paused now. |
| 872 | if (DEBUG_PAUSE) Slog.v(TAG, "Activity not running, resuming next."); |
Craig Mautner | ce5f3cb | 2013-04-22 08:58:54 -0700 | [diff] [blame] | 873 | mStackSupervisor.getFocusedStack().resumeTopActivityLocked(null); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 874 | } |
| 875 | } |
Dianne Hackborn | ad9b3211 | 2012-09-17 15:35:01 -0700 | [diff] [blame] | 876 | |
Craig Mautner | a002604 | 2014-04-23 11:45:37 -0700 | [diff] [blame] | 877 | final void activityPausedLocked(IBinder token, boolean timeout, |
| 878 | PersistableBundle persistentState) { |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 879 | if (DEBUG_PAUSE) Slog.v( |
Dianne Hackborn | 0aae2d4 | 2010-12-07 23:51:29 -0800 | [diff] [blame] | 880 | TAG, "Activity paused: token=" + token + ", timeout=" + timeout); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 881 | |
Craig Mautner | d232895 | 2013-03-05 12:46:26 -0800 | [diff] [blame] | 882 | final ActivityRecord r = isInStackLocked(token); |
| 883 | if (r != null) { |
| 884 | mHandler.removeMessages(PAUSE_TIMEOUT_MSG, r); |
Craig Mautner | 21d24a2 | 2014-04-23 11:45:37 -0700 | [diff] [blame] | 885 | if (persistentState != null) { |
| 886 | r.persistentState = persistentState; |
| 887 | mService.notifyTaskPersisterLocked(r.task, false); |
| 888 | } |
Craig Mautner | d232895 | 2013-03-05 12:46:26 -0800 | [diff] [blame] | 889 | if (mPausingActivity == r) { |
| 890 | if (DEBUG_STATES) Slog.v(TAG, "Moving to PAUSED: " + r |
| 891 | + (timeout ? " (due to timeout)" : " (pause complete)")); |
| 892 | r.state = ActivityState.PAUSED; |
| 893 | completePauseLocked(); |
| 894 | } else { |
| 895 | EventLog.writeEvent(EventLogTags.AM_FAILED_TO_PAUSE, |
| 896 | r.userId, System.identityHashCode(r), r.shortComponentName, |
| 897 | mPausingActivity != null |
| 898 | ? mPausingActivity.shortComponentName : "(none)"); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 899 | } |
| 900 | } |
| 901 | } |
| 902 | |
Craig Mautner | a002604 | 2014-04-23 11:45:37 -0700 | [diff] [blame] | 903 | final void activityStoppedLocked(ActivityRecord r, Bundle icicle, |
| 904 | PersistableBundle persistentState, CharSequence description) { |
Dianne Hackborn | b61a026 | 2012-05-14 17:19:18 -0700 | [diff] [blame] | 905 | if (r.state != ActivityState.STOPPING) { |
| 906 | Slog.i(TAG, "Activity reported stop, but no longer stopping: " + r); |
| 907 | mHandler.removeMessages(STOP_TIMEOUT_MSG, r); |
| 908 | return; |
| 909 | } |
Craig Mautner | 21d24a2 | 2014-04-23 11:45:37 -0700 | [diff] [blame] | 910 | if (persistentState != null) { |
| 911 | r.persistentState = persistentState; |
| 912 | mService.notifyTaskPersisterLocked(r.task, false); |
| 913 | } |
Dianne Hackborn | 98cfebc | 2011-10-18 13:17:33 -0700 | [diff] [blame] | 914 | if (DEBUG_SAVED_STATE) Slog.i(TAG, "Saving icicle of " + r + ": " + icicle); |
Dianne Hackborn | 162bc0e | 2012-04-09 14:06:16 -0700 | [diff] [blame] | 915 | if (icicle != null) { |
| 916 | // If icicle is null, this is happening due to a timeout, so we |
| 917 | // haven't really saved the state. |
| 918 | r.icicle = icicle; |
| 919 | r.haveState = true; |
Dianne Hackborn | 0798149 | 2013-01-28 11:36:23 -0800 | [diff] [blame] | 920 | r.launchCount = 0; |
Craig Mautner | a002604 | 2014-04-23 11:45:37 -0700 | [diff] [blame] | 921 | r.updateThumbnail(null, description); |
Dianne Hackborn | 162bc0e | 2012-04-09 14:06:16 -0700 | [diff] [blame] | 922 | } |
| 923 | if (!r.stopped) { |
| 924 | if (DEBUG_STATES) Slog.v(TAG, "Moving to STOPPED: " + r + " (stop complete)"); |
| 925 | mHandler.removeMessages(STOP_TIMEOUT_MSG, r); |
| 926 | r.stopped = true; |
| 927 | r.state = ActivityState.STOPPED; |
Dianne Hackborn | 6e3d6da | 2012-06-15 12:05:27 -0700 | [diff] [blame] | 928 | if (r.finishing) { |
| 929 | r.clearOptionsLocked(); |
| 930 | } else { |
Dianne Hackborn | 162bc0e | 2012-04-09 14:06:16 -0700 | [diff] [blame] | 931 | if (r.configDestroy) { |
| 932 | destroyActivityLocked(r, true, false, "stop-config"); |
Craig Mautner | 05d2903 | 2013-05-03 13:40:13 -0700 | [diff] [blame] | 933 | mStackSupervisor.resumeTopActivitiesLocked(); |
Dianne Hackborn | 162bc0e | 2012-04-09 14:06:16 -0700 | [diff] [blame] | 934 | } else { |
Dianne Hackborn | a413dc0 | 2013-07-12 12:02:55 -0700 | [diff] [blame] | 935 | mStackSupervisor.updatePreviousProcessLocked(r); |
Dianne Hackborn | 5068560 | 2011-12-01 12:23:37 -0800 | [diff] [blame] | 936 | } |
Dianne Hackborn | ce86ba8 | 2011-07-13 19:33:41 -0700 | [diff] [blame] | 937 | } |
| 938 | } |
| 939 | } |
| 940 | |
Craig Mautner | c8143c6 | 2013-09-03 12:15:57 -0700 | [diff] [blame] | 941 | private void completePauseLocked() { |
Dianne Hackborn | 621e2fe | 2012-02-16 17:07:33 -0800 | [diff] [blame] | 942 | ActivityRecord prev = mPausingActivity; |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 943 | if (DEBUG_PAUSE) Slog.v(TAG, "Complete pause: " + prev); |
Craig Mautner | aab647e | 2013-02-28 16:31:36 -0800 | [diff] [blame] | 944 | |
Dianne Hackborn | 621e2fe | 2012-02-16 17:07:33 -0800 | [diff] [blame] | 945 | if (prev != null) { |
| 946 | if (prev.finishing) { |
| 947 | if (DEBUG_PAUSE) Slog.v(TAG, "Executing finish of activity: " + prev); |
Dianne Hackborn | 2d1b378 | 2012-09-09 17:49:39 -0700 | [diff] [blame] | 948 | prev = finishCurrentActivityLocked(prev, FINISH_AFTER_VISIBLE, false); |
Dianne Hackborn | 621e2fe | 2012-02-16 17:07:33 -0800 | [diff] [blame] | 949 | } else if (prev.app != null) { |
| 950 | if (DEBUG_PAUSE) Slog.v(TAG, "Enqueueing pending stop: " + prev); |
| 951 | if (prev.waitingVisible) { |
| 952 | prev.waitingVisible = false; |
Craig Mautner | de4ef02 | 2013-04-07 19:01:33 -0700 | [diff] [blame] | 953 | mStackSupervisor.mWaitingVisibleActivities.remove(prev); |
Dianne Hackborn | 621e2fe | 2012-02-16 17:07:33 -0800 | [diff] [blame] | 954 | if (DEBUG_SWITCH || DEBUG_PAUSE) Slog.v( |
| 955 | TAG, "Complete pause, no longer waiting: " + prev); |
Dianne Hackborn | cbb722e | 2012-02-07 18:33:49 -0800 | [diff] [blame] | 956 | } |
Dianne Hackborn | 621e2fe | 2012-02-16 17:07:33 -0800 | [diff] [blame] | 957 | if (prev.configDestroy) { |
| 958 | // The previous is being paused because the configuration |
| 959 | // is changing, which means it is actually stopping... |
| 960 | // To juggle the fact that we are also starting a new |
| 961 | // instance right now, we need to first completely stop |
| 962 | // the current instance before starting the new one. |
| 963 | if (DEBUG_PAUSE) Slog.v(TAG, "Destroying after pause: " + prev); |
| 964 | destroyActivityLocked(prev, true, false, "pause-config"); |
| 965 | } else { |
Craig Mautner | de4ef02 | 2013-04-07 19:01:33 -0700 | [diff] [blame] | 966 | mStackSupervisor.mStoppingActivities.add(prev); |
Craig Mautner | 29219d9 | 2013-04-16 20:19:12 -0700 | [diff] [blame] | 967 | if (mStackSupervisor.mStoppingActivities.size() > 3 || |
| 968 | prev.frontOfTask && mTaskHistory.size() <= 1) { |
Dianne Hackborn | 621e2fe | 2012-02-16 17:07:33 -0800 | [diff] [blame] | 969 | // If we already have a few activities waiting to stop, |
| 970 | // then give up on things going idle and start clearing |
Craig Mautner | 29219d9 | 2013-04-16 20:19:12 -0700 | [diff] [blame] | 971 | // them out. Or if r is the last of activity of the last task the stack |
| 972 | // will be empty and must be cleared immediately. |
Dianne Hackborn | 621e2fe | 2012-02-16 17:07:33 -0800 | [diff] [blame] | 973 | if (DEBUG_PAUSE) Slog.v(TAG, "To many pending stops, forcing idle"); |
Craig Mautner | f333327 | 2013-04-22 10:55:53 -0700 | [diff] [blame] | 974 | mStackSupervisor.scheduleIdleLocked(); |
Dianne Hackborn | 621e2fe | 2012-02-16 17:07:33 -0800 | [diff] [blame] | 975 | } else { |
Craig Mautner | 0eea92c | 2013-05-16 13:35:39 -0700 | [diff] [blame] | 976 | mStackSupervisor.checkReadyForSleepLocked(); |
Dianne Hackborn | 621e2fe | 2012-02-16 17:07:33 -0800 | [diff] [blame] | 977 | } |
| 978 | } |
| 979 | } else { |
| 980 | if (DEBUG_PAUSE) Slog.v(TAG, "App died during pause, not stopping: " + prev); |
| 981 | prev = null; |
Dianne Hackborn | cbb722e | 2012-02-07 18:33:49 -0800 | [diff] [blame] | 982 | } |
Dianne Hackborn | 621e2fe | 2012-02-16 17:07:33 -0800 | [diff] [blame] | 983 | mPausingActivity = null; |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 984 | } |
Dianne Hackborn | cbb722e | 2012-02-07 18:33:49 -0800 | [diff] [blame] | 985 | |
Craig Mautner | ce5f3cb | 2013-04-22 08:58:54 -0700 | [diff] [blame] | 986 | final ActivityStack topStack = mStackSupervisor.getFocusedStack(); |
Craig Mautner | e11f2b7 | 2013-04-01 12:37:17 -0700 | [diff] [blame] | 987 | if (!mService.isSleepingOrShuttingDown()) { |
Craig Mautner | 05d2903 | 2013-05-03 13:40:13 -0700 | [diff] [blame] | 988 | mStackSupervisor.resumeTopActivitiesLocked(topStack, prev, null); |
Dianne Hackborn | 621e2fe | 2012-02-16 17:07:33 -0800 | [diff] [blame] | 989 | } else { |
Craig Mautner | 0eea92c | 2013-05-16 13:35:39 -0700 | [diff] [blame] | 990 | mStackSupervisor.checkReadyForSleepLocked(); |
Craig Mautner | de4ef02 | 2013-04-07 19:01:33 -0700 | [diff] [blame] | 991 | ActivityRecord top = topStack.topRunningActivityLocked(null); |
Dianne Hackborn | cc5a055 | 2012-10-01 16:32:39 -0700 | [diff] [blame] | 992 | if (top == null || (prev != null && top != prev)) { |
| 993 | // If there are no more activities available to run, |
| 994 | // do resume anyway to start something. Also if the top |
| 995 | // activity on the stack is not the just paused activity, |
| 996 | // we need to go ahead and resume it to ensure we complete |
| 997 | // an in-flight app switch. |
Craig Mautner | 05d2903 | 2013-05-03 13:40:13 -0700 | [diff] [blame] | 998 | mStackSupervisor.resumeTopActivitiesLocked(topStack, null, null); |
Dianne Hackborn | 42e620c | 2012-06-24 13:20:51 -0700 | [diff] [blame] | 999 | } |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 1000 | } |
Craig Mautner | aab647e | 2013-02-28 16:31:36 -0800 | [diff] [blame] | 1001 | |
Dianne Hackborn | 621e2fe | 2012-02-16 17:07:33 -0800 | [diff] [blame] | 1002 | if (prev != null) { |
| 1003 | prev.resumeKeyDispatchingLocked(); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 1004 | |
Craig Mautner | 525f3d9 | 2013-05-07 14:01:50 -0700 | [diff] [blame] | 1005 | if (prev.app != null && prev.cpuTimeAtResume > 0 |
| 1006 | && mService.mBatteryStatsService.isOnBattery()) { |
| 1007 | long diff; |
Dianne Hackborn | d293224 | 2013-08-05 18:18:42 -0700 | [diff] [blame] | 1008 | synchronized (mService.mProcessCpuThread) { |
| 1009 | diff = mService.mProcessCpuTracker.getCpuTimeForPid(prev.app.pid) |
Craig Mautner | 525f3d9 | 2013-05-07 14:01:50 -0700 | [diff] [blame] | 1010 | - prev.cpuTimeAtResume; |
| 1011 | } |
| 1012 | if (diff > 0) { |
| 1013 | BatteryStatsImpl bsi = mService.mBatteryStatsService.getActiveStatistics(); |
| 1014 | synchronized (bsi) { |
| 1015 | BatteryStatsImpl.Uid.Proc ps = |
| 1016 | bsi.getProcessStatsLocked(prev.info.applicationInfo.uid, |
Dianne Hackborn | d293224 | 2013-08-05 18:18:42 -0700 | [diff] [blame] | 1017 | prev.info.packageName); |
Craig Mautner | 525f3d9 | 2013-05-07 14:01:50 -0700 | [diff] [blame] | 1018 | if (ps != null) { |
| 1019 | ps.addForegroundTimeLocked(diff); |
| 1020 | } |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 1021 | } |
| 1022 | } |
| 1023 | } |
Craig Mautner | 525f3d9 | 2013-05-07 14:01:50 -0700 | [diff] [blame] | 1024 | prev.cpuTimeAtResume = 0; // reset it |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 1025 | } |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 1026 | } |
| 1027 | |
| 1028 | /** |
| 1029 | * Once we know that we have asked an application to put an activity in |
| 1030 | * the resumed state (either by launching it or explicitly telling it), |
| 1031 | * this function updates the rest of our state to match that fact. |
| 1032 | */ |
Craig Mautner | 525f3d9 | 2013-05-07 14:01:50 -0700 | [diff] [blame] | 1033 | private void completeResumeLocked(ActivityRecord next) { |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 1034 | next.idle = false; |
| 1035 | next.results = null; |
| 1036 | next.newIntents = null; |
Craig Mautner | 0756632 | 2013-09-26 16:42:55 -0700 | [diff] [blame] | 1037 | if (next.nowVisible) { |
| 1038 | // We won't get a call to reportActivityVisibleLocked() so dismiss lockscreen now. |
| 1039 | mStackSupervisor.dismissKeyguard(); |
| 1040 | } |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 1041 | |
| 1042 | // schedule an idle timeout in case the app doesn't do it for us. |
Craig Mautner | f333327 | 2013-04-22 10:55:53 -0700 | [diff] [blame] | 1043 | mStackSupervisor.scheduleIdleTimeoutLocked(next); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 1044 | |
Craig Mautner | ce5f3cb | 2013-04-22 08:58:54 -0700 | [diff] [blame] | 1045 | mStackSupervisor.reportResumedActivityLocked(next); |
| 1046 | |
| 1047 | next.resumeKeyDispatchingLocked(); |
| 1048 | mNoAnimActivities.clear(); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 1049 | |
| 1050 | // Mark the point when the activity is resuming |
| 1051 | // TODO: To be more accurate, the mark should be before the onCreate, |
| 1052 | // not after the onResume. But for subsequent starts, onResume is fine. |
| 1053 | if (next.app != null) { |
Dianne Hackborn | d293224 | 2013-08-05 18:18:42 -0700 | [diff] [blame] | 1054 | synchronized (mService.mProcessCpuThread) { |
| 1055 | next.cpuTimeAtResume = mService.mProcessCpuTracker.getCpuTimeForPid(next.app.pid); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 1056 | } |
| 1057 | } else { |
| 1058 | next.cpuTimeAtResume = 0; // Couldn't get the cpu time of process |
| 1059 | } |
Winson Chung | 376543b | 2014-05-21 17:43:28 -0700 | [diff] [blame] | 1060 | |
| 1061 | // If we are resuming the activity that we had last screenshotted, then we know it will be |
| 1062 | // updated, so invalidate the last screenshot to ensure we take a fresh one when requested |
| 1063 | if (next == mLastScreenshotActivity) { |
| 1064 | invalidateLastScreenshot(); |
| 1065 | } |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 1066 | } |
| 1067 | |
Craig Mautner | b9a6c8a | 2014-05-29 16:50:59 +0000 | [diff] [blame] | 1068 | /** |
| 1069 | * Determine if home should be visible below the passed record. |
| 1070 | * @param record activity we are querying for. |
| 1071 | * @return true if home is visible below the passed activity, false otherwise. |
| 1072 | */ |
| 1073 | boolean isActivityOverHome(ActivityRecord record) { |
| 1074 | // Start at record and go down, look for either home or a visible fullscreen activity. |
| 1075 | final TaskRecord recordTask = record.task; |
| 1076 | for (int taskNdx = mTaskHistory.indexOf(recordTask); taskNdx >= 0; --taskNdx) { |
| 1077 | TaskRecord task = mTaskHistory.get(taskNdx); |
| 1078 | final ArrayList<ActivityRecord> activities = task.mActivities; |
| 1079 | final int startNdx = |
| 1080 | task == recordTask ? activities.indexOf(record) : activities.size() - 1; |
| 1081 | for (int activityNdx = startNdx; activityNdx >= 0; --activityNdx) { |
| 1082 | final ActivityRecord r = activities.get(activityNdx); |
| 1083 | if (r.isHomeActivity()) { |
| 1084 | return true; |
| 1085 | } |
| 1086 | if (!r.finishing && r.fullscreen) { |
| 1087 | // Passed activity is over a fullscreen activity. |
| 1088 | return false; |
| 1089 | } |
| 1090 | } |
| 1091 | if (task.mOnTopOfHome) { |
| 1092 | // Got to the bottom of a task on top of home without finding a visible fullscreen |
| 1093 | // activity. Home is visible. |
| 1094 | return true; |
| 1095 | } |
| 1096 | } |
| 1097 | // Got to the bottom of this stack and still don't know. If this is over the home stack |
| 1098 | // then record is over home. May not work if we ever get more than two layers. |
| 1099 | return mStackSupervisor.isFrontStack(this); |
| 1100 | } |
| 1101 | |
Craig Mautner | e3a00d7 | 2014-04-16 08:31:19 -0700 | [diff] [blame] | 1102 | private void setVisibile(ActivityRecord r, boolean visible) { |
| 1103 | r.visible = visible; |
| 1104 | mWindowManager.setAppVisibility(r.appToken, visible); |
Craig Mautner | f4c909b | 2014-04-17 18:39:38 -0700 | [diff] [blame] | 1105 | final ArrayList<ActivityContainer> containers = r.mChildContainers; |
Craig Mautner | e3a00d7 | 2014-04-16 08:31:19 -0700 | [diff] [blame] | 1106 | for (int containerNdx = containers.size() - 1; containerNdx >= 0; --containerNdx) { |
Craig Mautner | f4c909b | 2014-04-17 18:39:38 -0700 | [diff] [blame] | 1107 | ActivityContainer container = containers.get(containerNdx); |
Craig Mautner | e3a00d7 | 2014-04-16 08:31:19 -0700 | [diff] [blame] | 1108 | container.setVisible(visible); |
| 1109 | } |
| 1110 | } |
| 1111 | |
Jose Lima | 7ba7125 | 2014-04-30 12:59:27 -0700 | [diff] [blame] | 1112 | // Checks if any of the stacks above this one has a fullscreen activity behind it. |
| 1113 | // If so, this stack is hidden, otherwise it is visible. |
| 1114 | private boolean isStackVisible() { |
| 1115 | if (!isAttached()) { |
| 1116 | return false; |
| 1117 | } |
| 1118 | |
| 1119 | if (mStackSupervisor.isFrontStack(this)) { |
| 1120 | return true; |
| 1121 | } |
| 1122 | |
Jose Lima | 729cb23 | 2014-05-05 15:59:40 -0700 | [diff] [blame] | 1123 | /** |
| 1124 | * Start at the task above this one and go up, looking for a visible |
| 1125 | * fullscreen activity, or a translucent activity that requested the |
| 1126 | * wallpaper to be shown behind it. |
| 1127 | */ |
Jose Lima | 7ba7125 | 2014-04-30 12:59:27 -0700 | [diff] [blame] | 1128 | for (int i = mStacks.indexOf(this) + 1; i < mStacks.size(); i++) { |
| 1129 | final ArrayList<TaskRecord> tasks = mStacks.get(i).getAllTasks(); |
| 1130 | for (int taskNdx = 0; taskNdx < tasks.size(); taskNdx++) { |
Craig Mautner | b9a6c8a | 2014-05-29 16:50:59 +0000 | [diff] [blame] | 1131 | final ArrayList<ActivityRecord> activities = tasks.get(taskNdx).mActivities; |
Jose Lima | 7ba7125 | 2014-04-30 12:59:27 -0700 | [diff] [blame] | 1132 | for (int activityNdx = 0; activityNdx < activities.size(); activityNdx++) { |
| 1133 | final ActivityRecord r = activities.get(activityNdx); |
Jose Lima | 729cb23 | 2014-05-05 15:59:40 -0700 | [diff] [blame] | 1134 | |
| 1135 | // Conditions for an activity to obscure the stack we're |
| 1136 | // examining: |
| 1137 | // 1. Not Finishing AND Visible AND: |
| 1138 | // 2. Either: |
| 1139 | // - Full Screen Activity OR |
| 1140 | // - On top of Home and our stack is NOT home |
| 1141 | if (!r.finishing && r.visible && (r.fullscreen || |
Craig Mautner | b9a6c8a | 2014-05-29 16:50:59 +0000 | [diff] [blame] | 1142 | (!isHomeStack() && r.frontOfTask && tasks.get(taskNdx).mOnTopOfHome))) { |
Jose Lima | 7ba7125 | 2014-04-30 12:59:27 -0700 | [diff] [blame] | 1143 | return false; |
| 1144 | } |
| 1145 | } |
| 1146 | } |
| 1147 | } |
| 1148 | |
| 1149 | return true; |
| 1150 | } |
| 1151 | |
Jose Lima | 729cb23 | 2014-05-05 15:59:40 -0700 | [diff] [blame] | 1152 | final void ensureActivitiesVisibleLocked(ActivityRecord starting, int configChanges) { |
| 1153 | ActivityRecord r = topRunningActivityLocked(null); |
| 1154 | if (r != null) { |
| 1155 | ensureActivitiesVisibleLocked(r, starting, null, configChanges); |
| 1156 | } |
| 1157 | } |
| 1158 | |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 1159 | /** |
| 1160 | * Make sure that all activities that need to be visible (that is, they |
| 1161 | * currently can be seen by the user) actually are. |
| 1162 | */ |
Jose Lima | 729cb23 | 2014-05-05 15:59:40 -0700 | [diff] [blame] | 1163 | final void ensureActivitiesVisibleLocked(ActivityRecord top, ActivityRecord starting, |
| 1164 | String onlyThisProcess, int configChanges) { |
Craig Mautner | a7f2bd4 | 2013-10-15 16:13:50 -0700 | [diff] [blame] | 1165 | if (DEBUG_VISBILITY) Slog.v( |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 1166 | TAG, "ensureActivitiesVisible behind " + top |
| 1167 | + " configChanges=0x" + Integer.toHexString(configChanges)); |
| 1168 | |
Craig Mautner | 5eda9b3 | 2013-07-02 11:58:16 -0700 | [diff] [blame] | 1169 | if (mTranslucentActivityWaiting != top) { |
| 1170 | mUndrawnActivitiesBelowTopTranslucent.clear(); |
| 1171 | if (mTranslucentActivityWaiting != null) { |
| 1172 | // Call the callback with a timeout indication. |
| 1173 | notifyActivityDrawnLocked(null); |
| 1174 | mTranslucentActivityWaiting = null; |
| 1175 | } |
| 1176 | mHandler.removeMessages(TRANSLUCENT_TIMEOUT_MSG); |
| 1177 | } |
| 1178 | |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 1179 | // If the top activity is not fullscreen, then we need to |
| 1180 | // make sure any activities under it are now visible. |
Craig Mautner | d44711d | 2013-02-23 11:24:36 -0800 | [diff] [blame] | 1181 | boolean aboveTop = true; |
Jose Lima | 7ba7125 | 2014-04-30 12:59:27 -0700 | [diff] [blame] | 1182 | boolean behindFullscreen = !isStackVisible(); |
| 1183 | |
Craig Mautner | b59dcfd | 2013-05-06 13:12:58 -0700 | [diff] [blame] | 1184 | for (int taskNdx = mTaskHistory.size() - 1; taskNdx >= 0; --taskNdx) { |
Craig Mautner | ae7ecab | 2013-09-18 11:48:14 -0700 | [diff] [blame] | 1185 | final TaskRecord task = mTaskHistory.get(taskNdx); |
| 1186 | final ArrayList<ActivityRecord> activities = task.mActivities; |
Craig Mautner | d44711d | 2013-02-23 11:24:36 -0800 | [diff] [blame] | 1187 | for (int activityNdx = activities.size() - 1; activityNdx >= 0; --activityNdx) { |
| 1188 | final ActivityRecord r = activities.get(activityNdx); |
| 1189 | if (r.finishing) { |
| 1190 | continue; |
| 1191 | } |
| 1192 | if (aboveTop && r != top) { |
| 1193 | continue; |
| 1194 | } |
| 1195 | aboveTop = false; |
| 1196 | if (!behindFullscreen) { |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 1197 | if (DEBUG_VISBILITY) Slog.v( |
Craig Mautner | d44711d | 2013-02-23 11:24:36 -0800 | [diff] [blame] | 1198 | TAG, "Make visible? " + r + " finishing=" + r.finishing |
| 1199 | + " state=" + r.state); |
Craig Mautner | 5854780 | 2013-03-05 08:23:53 -0800 | [diff] [blame] | 1200 | |
Craig Mautner | d44711d | 2013-02-23 11:24:36 -0800 | [diff] [blame] | 1201 | final boolean doThisProcess = onlyThisProcess == null |
| 1202 | || onlyThisProcess.equals(r.processName); |
| 1203 | |
| 1204 | // First: if this is not the current activity being started, make |
| 1205 | // sure it matches the current configuration. |
| 1206 | if (r != starting && doThisProcess) { |
| 1207 | ensureActivityConfigurationLocked(r, 0); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 1208 | } |
Craig Mautner | d44711d | 2013-02-23 11:24:36 -0800 | [diff] [blame] | 1209 | |
| 1210 | if (r.app == null || r.app.thread == null) { |
Craig Mautner | de4ef02 | 2013-04-07 19:01:33 -0700 | [diff] [blame] | 1211 | if (onlyThisProcess == null || onlyThisProcess.equals(r.processName)) { |
Craig Mautner | d44711d | 2013-02-23 11:24:36 -0800 | [diff] [blame] | 1212 | // This activity needs to be visible, but isn't even |
| 1213 | // running... get it started, but don't resume it |
| 1214 | // at this point. |
Craig Mautner | de4ef02 | 2013-04-07 19:01:33 -0700 | [diff] [blame] | 1215 | if (DEBUG_VISBILITY) Slog.v(TAG, "Start and freeze screen for " + r); |
Craig Mautner | d44711d | 2013-02-23 11:24:36 -0800 | [diff] [blame] | 1216 | if (r != starting) { |
| 1217 | r.startFreezingScreenLocked(r.app, configChanges); |
| 1218 | } |
| 1219 | if (!r.visible) { |
Craig Mautner | a7f2bd4 | 2013-10-15 16:13:50 -0700 | [diff] [blame] | 1220 | if (DEBUG_VISBILITY) Slog.v( |
Craig Mautner | d44711d | 2013-02-23 11:24:36 -0800 | [diff] [blame] | 1221 | TAG, "Starting and making visible: " + r); |
Craig Mautner | e3a00d7 | 2014-04-16 08:31:19 -0700 | [diff] [blame] | 1222 | setVisibile(r, true); |
Craig Mautner | d44711d | 2013-02-23 11:24:36 -0800 | [diff] [blame] | 1223 | } |
| 1224 | if (r != starting) { |
George Mount | 2c92c97 | 2014-03-20 09:38:23 -0700 | [diff] [blame] | 1225 | mStackSupervisor.startSpecificActivityLocked(r, false, false); |
Craig Mautner | d44711d | 2013-02-23 11:24:36 -0800 | [diff] [blame] | 1226 | } |
| 1227 | } |
| 1228 | |
| 1229 | } else if (r.visible) { |
| 1230 | // If this activity is already visible, then there is nothing |
| 1231 | // else to do here. |
Craig Mautner | de4ef02 | 2013-04-07 19:01:33 -0700 | [diff] [blame] | 1232 | if (DEBUG_VISBILITY) Slog.v(TAG, "Skipping: already visible at " + r); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 1233 | r.stopFreezingScreenLocked(false); |
Craig Mautner | d44711d | 2013-02-23 11:24:36 -0800 | [diff] [blame] | 1234 | |
| 1235 | } else if (onlyThisProcess == null) { |
| 1236 | // This activity is not currently visible, but is running. |
| 1237 | // Tell it to become visible. |
| 1238 | r.visible = true; |
| 1239 | if (r.state != ActivityState.RESUMED && r != starting) { |
| 1240 | // If this activity is paused, tell it |
| 1241 | // to now show its window. |
Craig Mautner | a7f2bd4 | 2013-10-15 16:13:50 -0700 | [diff] [blame] | 1242 | if (DEBUG_VISBILITY) Slog.v( |
Craig Mautner | d44711d | 2013-02-23 11:24:36 -0800 | [diff] [blame] | 1243 | TAG, "Making visible and scheduling visibility: " + r); |
| 1244 | try { |
Craig Mautner | 5eda9b3 | 2013-07-02 11:58:16 -0700 | [diff] [blame] | 1245 | if (mTranslucentActivityWaiting != null) { |
Craig Mautner | 233ceee | 2014-05-09 17:05:11 -0700 | [diff] [blame] | 1246 | r.updateOptionsLocked(mReturningActivityOptions); |
Craig Mautner | 5eda9b3 | 2013-07-02 11:58:16 -0700 | [diff] [blame] | 1247 | mUndrawnActivitiesBelowTopTranslucent.add(r); |
| 1248 | } |
Craig Mautner | e3a00d7 | 2014-04-16 08:31:19 -0700 | [diff] [blame] | 1249 | setVisibile(r, true); |
Craig Mautner | d44711d | 2013-02-23 11:24:36 -0800 | [diff] [blame] | 1250 | r.sleeping = false; |
| 1251 | r.app.pendingUiClean = true; |
| 1252 | r.app.thread.scheduleWindowVisibility(r.appToken, true); |
| 1253 | r.stopFreezingScreenLocked(false); |
| 1254 | } catch (Exception e) { |
| 1255 | // Just skip on any failure; we'll make it |
| 1256 | // visible when it next restarts. |
| 1257 | Slog.w(TAG, "Exception thrown making visibile: " |
| 1258 | + r.intent.getComponent(), e); |
| 1259 | } |
| 1260 | } |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 1261 | } |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 1262 | |
Craig Mautner | d44711d | 2013-02-23 11:24:36 -0800 | [diff] [blame] | 1263 | // Aggregate current change flags. |
| 1264 | configChanges |= r.configChangeFlags; |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 1265 | |
Craig Mautner | d44711d | 2013-02-23 11:24:36 -0800 | [diff] [blame] | 1266 | if (r.fullscreen) { |
| 1267 | // At this point, nothing else needs to be shown |
Craig Mautner | 580ea81 | 2013-04-25 12:58:38 -0700 | [diff] [blame] | 1268 | if (DEBUG_VISBILITY) Slog.v(TAG, "Fullscreen: at " + r); |
| 1269 | behindFullscreen = true; |
Craig Mautner | b9a6c8a | 2014-05-29 16:50:59 +0000 | [diff] [blame] | 1270 | } else if (!isHomeStack() && r.frontOfTask && task.mOnTopOfHome) { |
Craig Mautner | 39e1c5a | 2013-10-23 15:14:22 -0700 | [diff] [blame] | 1271 | if (DEBUG_VISBILITY) Slog.v(TAG, "Showing home: at " + r); |
Jose Lima | 729cb23 | 2014-05-05 15:59:40 -0700 | [diff] [blame] | 1272 | behindFullscreen = true; |
Craig Mautner | d44711d | 2013-02-23 11:24:36 -0800 | [diff] [blame] | 1273 | } |
| 1274 | } else { |
Craig Mautner | de4ef02 | 2013-04-07 19:01:33 -0700 | [diff] [blame] | 1275 | if (DEBUG_VISBILITY) Slog.v( |
| 1276 | TAG, "Make invisible? " + r + " finishing=" + r.finishing |
| 1277 | + " state=" + r.state |
| 1278 | + " behindFullscreen=" + behindFullscreen); |
| 1279 | // Now for any activities that aren't visible to the user, make |
| 1280 | // sure they no longer are keeping the screen frozen. |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 1281 | if (r.visible) { |
Craig Mautner | a7f2bd4 | 2013-10-15 16:13:50 -0700 | [diff] [blame] | 1282 | if (DEBUG_VISBILITY) Slog.v(TAG, "Making invisible: " + r); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 1283 | try { |
Craig Mautner | e3a00d7 | 2014-04-16 08:31:19 -0700 | [diff] [blame] | 1284 | setVisibile(r, false); |
Craig Mautner | 4addfc5 | 2013-06-25 08:05:45 -0700 | [diff] [blame] | 1285 | switch (r.state) { |
| 1286 | case STOPPING: |
| 1287 | case STOPPED: |
| 1288 | if (r.app != null && r.app.thread != null) { |
| 1289 | if (DEBUG_VISBILITY) Slog.v( |
| 1290 | TAG, "Scheduling invisibility: " + r); |
| 1291 | r.app.thread.scheduleWindowVisibility(r.appToken, false); |
| 1292 | } |
| 1293 | break; |
| 1294 | |
| 1295 | case INITIALIZING: |
| 1296 | case RESUMED: |
| 1297 | case PAUSING: |
| 1298 | case PAUSED: |
Craig Mautner | 8817610 | 2013-07-22 12:57:51 -0700 | [diff] [blame] | 1299 | // This case created for transitioning activities from |
| 1300 | // translucent to opaque {@link Activity#convertToOpaque}. |
Craig Mautner | e5273b4 | 2013-09-09 12:57:47 -0700 | [diff] [blame] | 1301 | if (!mStackSupervisor.mStoppingActivities.contains(r)) { |
| 1302 | mStackSupervisor.mStoppingActivities.add(r); |
| 1303 | } |
| 1304 | mStackSupervisor.scheduleIdleLocked(); |
Craig Mautner | 4addfc5 | 2013-06-25 08:05:45 -0700 | [diff] [blame] | 1305 | break; |
| 1306 | |
| 1307 | default: |
| 1308 | break; |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 1309 | } |
| 1310 | } catch (Exception e) { |
| 1311 | // Just skip on any failure; we'll make it |
| 1312 | // visible when it next restarts. |
| 1313 | Slog.w(TAG, "Exception thrown making hidden: " |
| 1314 | + r.intent.getComponent(), e); |
| 1315 | } |
| 1316 | } else { |
Craig Mautner | de4ef02 | 2013-04-07 19:01:33 -0700 | [diff] [blame] | 1317 | if (DEBUG_VISBILITY) Slog.v(TAG, "Already invisible: " + r); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 1318 | } |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 1319 | } |
| 1320 | } |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 1321 | } |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 1322 | } |
Craig Mautner | 5854780 | 2013-03-05 08:23:53 -0800 | [diff] [blame] | 1323 | |
Craig Mautner | 233ceee | 2014-05-09 17:05:11 -0700 | [diff] [blame] | 1324 | void convertToTranslucent(ActivityRecord r, ActivityOptions options) { |
Craig Mautner | 5eda9b3 | 2013-07-02 11:58:16 -0700 | [diff] [blame] | 1325 | mTranslucentActivityWaiting = r; |
| 1326 | mUndrawnActivitiesBelowTopTranslucent.clear(); |
Craig Mautner | 233ceee | 2014-05-09 17:05:11 -0700 | [diff] [blame] | 1327 | mReturningActivityOptions = options; |
Craig Mautner | 5eda9b3 | 2013-07-02 11:58:16 -0700 | [diff] [blame] | 1328 | mHandler.sendEmptyMessageDelayed(TRANSLUCENT_TIMEOUT_MSG, TRANSLUCENT_CONVERSION_TIMEOUT); |
| 1329 | } |
| 1330 | |
| 1331 | /** |
| 1332 | * Called as activities below the top translucent activity are redrawn. When the last one is |
| 1333 | * redrawn notify the top activity by calling |
| 1334 | * {@link Activity#onTranslucentConversionComplete}. |
| 1335 | * |
| 1336 | * @param r The most recent background activity to be drawn. Or, if r is null then a timeout |
| 1337 | * occurred and the activity will be notified immediately. |
| 1338 | */ |
| 1339 | void notifyActivityDrawnLocked(ActivityRecord r) { |
Craig Mautner | 6985bad | 2014-04-21 15:22:06 -0700 | [diff] [blame] | 1340 | mActivityContainer.setDrawn(); |
Craig Mautner | 5eda9b3 | 2013-07-02 11:58:16 -0700 | [diff] [blame] | 1341 | if ((r == null) |
| 1342 | || (mUndrawnActivitiesBelowTopTranslucent.remove(r) && |
| 1343 | mUndrawnActivitiesBelowTopTranslucent.isEmpty())) { |
| 1344 | // The last undrawn activity below the top has just been drawn. If there is an |
| 1345 | // opaque activity at the top, notify it that it can become translucent safely now. |
| 1346 | final ActivityRecord waitingActivity = mTranslucentActivityWaiting; |
| 1347 | mTranslucentActivityWaiting = null; |
| 1348 | mUndrawnActivitiesBelowTopTranslucent.clear(); |
| 1349 | mHandler.removeMessages(TRANSLUCENT_TIMEOUT_MSG); |
| 1350 | |
Craig Mautner | 71dd1b6 | 2014-02-18 15:48:52 -0800 | [diff] [blame] | 1351 | if (waitingActivity != null) { |
| 1352 | mWindowManager.setWindowOpaque(waitingActivity.appToken, false); |
| 1353 | if (waitingActivity.app != null && waitingActivity.app.thread != null) { |
| 1354 | try { |
| 1355 | waitingActivity.app.thread.scheduleTranslucentConversionComplete( |
| 1356 | waitingActivity.appToken, r != null); |
| 1357 | } catch (RemoteException e) { |
| 1358 | } |
Craig Mautner | 5eda9b3 | 2013-07-02 11:58:16 -0700 | [diff] [blame] | 1359 | } |
| 1360 | } |
| 1361 | } |
| 1362 | } |
| 1363 | |
Craig Mautner | a61bc65 | 2013-10-28 15:43:18 -0700 | [diff] [blame] | 1364 | /** If any activities below the top running one are in the INITIALIZING state and they have a |
| 1365 | * starting window displayed then remove that starting window. It is possible that the activity |
| 1366 | * in this state will never resumed in which case that starting window will be orphaned. */ |
| 1367 | void cancelInitializingActivities() { |
| 1368 | final ActivityRecord topActivity = topRunningActivityLocked(null); |
| 1369 | boolean aboveTop = true; |
| 1370 | for (int taskNdx = mTaskHistory.size() - 1; taskNdx >= 0; --taskNdx) { |
| 1371 | final ArrayList<ActivityRecord> activities = mTaskHistory.get(taskNdx).mActivities; |
| 1372 | for (int activityNdx = activities.size() - 1; activityNdx >= 0; --activityNdx) { |
| 1373 | final ActivityRecord r = activities.get(activityNdx); |
| 1374 | if (aboveTop) { |
| 1375 | if (r == topActivity) { |
| 1376 | aboveTop = false; |
| 1377 | } |
| 1378 | continue; |
| 1379 | } |
| 1380 | |
| 1381 | if (r.state == ActivityState.INITIALIZING && r.mStartingWindowShown) { |
| 1382 | if (DEBUG_VISBILITY) Slog.w(TAG, "Found orphaned starting window " + r); |
| 1383 | r.mStartingWindowShown = false; |
| 1384 | mWindowManager.removeAppStartingWindow(r.appToken); |
| 1385 | } |
| 1386 | } |
| 1387 | } |
| 1388 | } |
| 1389 | |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 1390 | /** |
| 1391 | * Ensure that the top activity in the stack is resumed. |
| 1392 | * |
| 1393 | * @param prev The previously resumed activity, for when in the process |
| 1394 | * of pausing; can be null to call from elsewhere. |
| 1395 | * |
| 1396 | * @return Returns true if something is being resumed, or false if |
| 1397 | * nothing happened. |
| 1398 | */ |
| 1399 | final boolean resumeTopActivityLocked(ActivityRecord prev) { |
Dianne Hackborn | 8437587 | 2012-06-01 19:03:50 -0700 | [diff] [blame] | 1400 | return resumeTopActivityLocked(prev, null); |
| 1401 | } |
| 1402 | |
| 1403 | final boolean resumeTopActivityLocked(ActivityRecord prev, Bundle options) { |
Craig Mautner | 5314a40 | 2013-09-26 12:40:16 -0700 | [diff] [blame] | 1404 | if (ActivityManagerService.DEBUG_LOCKSCREEN) mService.logLockScreen(""); |
| 1405 | |
Craig Mautner | df88d73 | 2014-01-27 09:21:32 -0800 | [diff] [blame] | 1406 | ActivityRecord parent = mActivityContainer.mParentActivity; |
Craig Mautner | f4c909b | 2014-04-17 18:39:38 -0700 | [diff] [blame] | 1407 | if ((parent != null && parent.state != ActivityState.RESUMED) || |
Craig Mautner | 6985bad | 2014-04-21 15:22:06 -0700 | [diff] [blame] | 1408 | !mActivityContainer.isAttached()) { |
Craig Mautner | df88d73 | 2014-01-27 09:21:32 -0800 | [diff] [blame] | 1409 | // Do not resume this stack if its parent is not resumed. |
| 1410 | // TODO: If in a loop, make sure that parent stack resumeTopActivity is called 1st. |
| 1411 | return false; |
| 1412 | } |
| 1413 | |
Craig Mautner | a61bc65 | 2013-10-28 15:43:18 -0700 | [diff] [blame] | 1414 | cancelInitializingActivities(); |
| 1415 | |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 1416 | // Find the first activity that is not finishing. |
| 1417 | ActivityRecord next = topRunningActivityLocked(null); |
| 1418 | |
| 1419 | // Remember how we'll process this pause/resume situation, and ensure |
| 1420 | // that the state is reset however we wind up proceeding. |
Craig Mautner | de4ef02 | 2013-04-07 19:01:33 -0700 | [diff] [blame] | 1421 | final boolean userLeaving = mStackSupervisor.mUserLeaving; |
| 1422 | mStackSupervisor.mUserLeaving = false; |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 1423 | |
| 1424 | if (next == null) { |
| 1425 | // There are no more activities! Let's just start up the |
| 1426 | // Launcher... |
Craig Mautner | de4ef02 | 2013-04-07 19:01:33 -0700 | [diff] [blame] | 1427 | ActivityOptions.abort(options); |
Craig Mautner | ac6f843 | 2013-07-17 13:24:59 -0700 | [diff] [blame] | 1428 | if (DEBUG_STATES) Slog.d(TAG, "resumeTopActivityLocked: No more activities go home"); |
Craig Mautner | cf910b0 | 2013-04-23 11:23:27 -0700 | [diff] [blame] | 1429 | if (DEBUG_STACK) mStackSupervisor.validateTopActivitiesLocked(); |
Craig Mautner | e0a3884 | 2013-12-16 16:14:02 -0800 | [diff] [blame] | 1430 | // Only resume home if on home display |
Craig Mautner | b9a6c8a | 2014-05-29 16:50:59 +0000 | [diff] [blame] | 1431 | return isOnHomeDisplay() && mStackSupervisor.resumeHomeActivity(prev); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 1432 | } |
| 1433 | |
| 1434 | next.delayedResume = false; |
Craig Mautner | 5854780 | 2013-03-05 08:23:53 -0800 | [diff] [blame] | 1435 | |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 1436 | // If the top activity is the resumed one, nothing to do. |
Craig Mautner | de4ef02 | 2013-04-07 19:01:33 -0700 | [diff] [blame] | 1437 | if (mResumedActivity == next && next.state == ActivityState.RESUMED && |
| 1438 | mStackSupervisor.allResumedActivitiesComplete()) { |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 1439 | // Make sure we have executed any pending transitions, since there |
| 1440 | // should be nothing left to do at this point. |
Craig Mautner | ce5f3cb | 2013-04-22 08:58:54 -0700 | [diff] [blame] | 1441 | mWindowManager.executeAppTransition(); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 1442 | mNoAnimActivities.clear(); |
Dianne Hackborn | 8437587 | 2012-06-01 19:03:50 -0700 | [diff] [blame] | 1443 | ActivityOptions.abort(options); |
Craig Mautner | ac6f843 | 2013-07-17 13:24:59 -0700 | [diff] [blame] | 1444 | if (DEBUG_STATES) Slog.d(TAG, "resumeTopActivityLocked: Top activity resumed " + next); |
Craig Mautner | cf910b0 | 2013-04-23 11:23:27 -0700 | [diff] [blame] | 1445 | if (DEBUG_STACK) mStackSupervisor.validateTopActivitiesLocked(); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 1446 | return false; |
| 1447 | } |
| 1448 | |
Craig Mautner | 525f3d9 | 2013-05-07 14:01:50 -0700 | [diff] [blame] | 1449 | final TaskRecord nextTask = next.task; |
Craig Mautner | b9a6c8a | 2014-05-29 16:50:59 +0000 | [diff] [blame] | 1450 | final TaskRecord prevTask = prev != null ? prev.task : null; |
bulic | ccd23071 | 2014-05-12 14:34:50 -0700 | [diff] [blame] | 1451 | if (prevTask != null && prevTask.stack == this && |
Craig Mautner | b9a6c8a | 2014-05-29 16:50:59 +0000 | [diff] [blame] | 1452 | prevTask.mOnTopOfHome && prev.finishing && prev.frontOfTask) { |
Craig Mautner | cf910b0 | 2013-04-23 11:23:27 -0700 | [diff] [blame] | 1453 | if (DEBUG_STACK) mStackSupervisor.validateTopActivitiesLocked(); |
Craig Mautner | 525f3d9 | 2013-05-07 14:01:50 -0700 | [diff] [blame] | 1454 | if (prevTask == nextTask) { |
Craig Mautner | 1aa9d0d3f | 2013-12-16 15:58:31 -0800 | [diff] [blame] | 1455 | prevTask.setFrontOfTask(); |
Craig Mautner | 525f3d9 | 2013-05-07 14:01:50 -0700 | [diff] [blame] | 1456 | } else if (prevTask != topTask()) { |
Craig Mautner | b9a6c8a | 2014-05-29 16:50:59 +0000 | [diff] [blame] | 1457 | // This task is going away but it was supposed to return to the home task. |
Craig Mautner | e418ecd | 2013-05-01 17:02:29 -0700 | [diff] [blame] | 1458 | // Now the task above it has to return to the home task instead. |
Craig Mautner | 525f3d9 | 2013-05-07 14:01:50 -0700 | [diff] [blame] | 1459 | final int taskNdx = mTaskHistory.indexOf(prevTask) + 1; |
Craig Mautner | b9a6c8a | 2014-05-29 16:50:59 +0000 | [diff] [blame] | 1460 | mTaskHistory.get(taskNdx).mOnTopOfHome = true; |
Craig Mautner | e418ecd | 2013-05-01 17:02:29 -0700 | [diff] [blame] | 1461 | } else { |
Craig Mautner | e0a3884 | 2013-12-16 16:14:02 -0800 | [diff] [blame] | 1462 | if (DEBUG_STATES && isOnHomeDisplay()) Slog.d(TAG, |
| 1463 | "resumeTopActivityLocked: Launching home next"); |
| 1464 | // Only resume home if on home display |
Craig Mautner | b9a6c8a | 2014-05-29 16:50:59 +0000 | [diff] [blame] | 1465 | return isOnHomeDisplay() && mStackSupervisor.resumeHomeActivity(prev); |
Craig Mautner | e418ecd | 2013-05-01 17:02:29 -0700 | [diff] [blame] | 1466 | } |
Craig Mautner | de4ef02 | 2013-04-07 19:01:33 -0700 | [diff] [blame] | 1467 | } |
| 1468 | |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 1469 | // If we are sleeping, and there is no resumed activity, and the top |
| 1470 | // activity is paused, well that is the state we want. |
Craig Mautner | 5314a40 | 2013-09-26 12:40:16 -0700 | [diff] [blame] | 1471 | if (mService.isSleepingOrShuttingDown() |
p13451 | dbad287 | 2012-04-18 11:39:23 +0900 | [diff] [blame] | 1472 | && mLastPausedActivity == next |
Craig Mautner | 5314a40 | 2013-09-26 12:40:16 -0700 | [diff] [blame] | 1473 | && mStackSupervisor.allPausedActivitiesComplete()) { |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 1474 | // Make sure we have executed any pending transitions, since there |
| 1475 | // should be nothing left to do at this point. |
Craig Mautner | ce5f3cb | 2013-04-22 08:58:54 -0700 | [diff] [blame] | 1476 | mWindowManager.executeAppTransition(); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 1477 | mNoAnimActivities.clear(); |
Dianne Hackborn | 8437587 | 2012-06-01 19:03:50 -0700 | [diff] [blame] | 1478 | ActivityOptions.abort(options); |
Craig Mautner | ac6f843 | 2013-07-17 13:24:59 -0700 | [diff] [blame] | 1479 | if (DEBUG_STATES) Slog.d(TAG, "resumeTopActivityLocked: Going to sleep and all paused"); |
Craig Mautner | cf910b0 | 2013-04-23 11:23:27 -0700 | [diff] [blame] | 1480 | if (DEBUG_STACK) mStackSupervisor.validateTopActivitiesLocked(); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 1481 | return false; |
| 1482 | } |
Dianne Hackborn | 80a4af2 | 2012-08-27 19:18:31 -0700 | [diff] [blame] | 1483 | |
| 1484 | // Make sure that the user who owns this activity is started. If not, |
| 1485 | // we will just leave it as is because someone should be bringing |
| 1486 | // another user's activities to the top of the stack. |
| 1487 | if (mService.mStartedUsers.get(next.userId) == null) { |
| 1488 | Slog.w(TAG, "Skipping resume of top activity " + next |
| 1489 | + ": user " + next.userId + " is stopped"); |
Craig Mautner | cf910b0 | 2013-04-23 11:23:27 -0700 | [diff] [blame] | 1490 | if (DEBUG_STACK) mStackSupervisor.validateTopActivitiesLocked(); |
Dianne Hackborn | 80a4af2 | 2012-08-27 19:18:31 -0700 | [diff] [blame] | 1491 | return false; |
| 1492 | } |
| 1493 | |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 1494 | // The activity may be waiting for stop, but that is no longer |
| 1495 | // appropriate for it. |
Craig Mautner | de4ef02 | 2013-04-07 19:01:33 -0700 | [diff] [blame] | 1496 | mStackSupervisor.mStoppingActivities.remove(next); |
Craig Mautner | 0eea92c | 2013-05-16 13:35:39 -0700 | [diff] [blame] | 1497 | mStackSupervisor.mGoingToSleepActivities.remove(next); |
Dianne Hackborn | 4eba96b | 2011-01-21 13:34:36 -0800 | [diff] [blame] | 1498 | next.sleeping = false; |
Craig Mautner | de4ef02 | 2013-04-07 19:01:33 -0700 | [diff] [blame] | 1499 | mStackSupervisor.mWaitingVisibleActivities.remove(next); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 1500 | |
| 1501 | if (DEBUG_SWITCH) Slog.v(TAG, "Resuming " + next); |
| 1502 | |
Dianne Hackborn | 621e2fe | 2012-02-16 17:07:33 -0800 | [diff] [blame] | 1503 | // If we are currently pausing an activity, then don't do anything |
| 1504 | // until that is done. |
Craig Mautner | 69ada55 | 2013-04-18 13:51:51 -0700 | [diff] [blame] | 1505 | if (!mStackSupervisor.allPausedActivitiesComplete()) { |
Craig Mautner | ac6f843 | 2013-07-17 13:24:59 -0700 | [diff] [blame] | 1506 | if (DEBUG_SWITCH || DEBUG_PAUSE || DEBUG_STATES) Slog.v(TAG, |
| 1507 | "resumeTopActivityLocked: Skip resume: some activity pausing."); |
Craig Mautner | cf910b0 | 2013-04-23 11:23:27 -0700 | [diff] [blame] | 1508 | if (DEBUG_STACK) mStackSupervisor.validateTopActivitiesLocked(); |
Dianne Hackborn | 621e2fe | 2012-02-16 17:07:33 -0800 | [diff] [blame] | 1509 | return false; |
| 1510 | } |
| 1511 | |
Dianne Hackborn | 0dad364 | 2010-09-09 21:25:35 -0700 | [diff] [blame] | 1512 | // Okay we are now going to start a switch, to 'next'. We may first |
| 1513 | // have to pause the current activity, but this is an important point |
| 1514 | // where we have decided to go to 'next' so keep track of that. |
Dianne Hackborn | 034093a4 | 2010-09-20 22:24:38 -0700 | [diff] [blame] | 1515 | // XXX "App Redirected" dialog is getting too many false positives |
| 1516 | // at this point, so turn off for now. |
| 1517 | if (false) { |
| 1518 | if (mLastStartedActivity != null && !mLastStartedActivity.finishing) { |
| 1519 | long now = SystemClock.uptimeMillis(); |
| 1520 | final boolean inTime = mLastStartedActivity.startTime != 0 |
| 1521 | && (mLastStartedActivity.startTime + START_WARN_TIME) >= now; |
| 1522 | final int lastUid = mLastStartedActivity.info.applicationInfo.uid; |
| 1523 | final int nextUid = next.info.applicationInfo.uid; |
| 1524 | if (inTime && lastUid != nextUid |
| 1525 | && lastUid != next.launchedFromUid |
| 1526 | && mService.checkPermission( |
| 1527 | android.Manifest.permission.STOP_APP_SWITCHES, |
| 1528 | -1, next.launchedFromUid) |
| 1529 | != PackageManager.PERMISSION_GRANTED) { |
| 1530 | mService.showLaunchWarningLocked(mLastStartedActivity, next); |
| 1531 | } else { |
| 1532 | next.startTime = now; |
| 1533 | mLastStartedActivity = next; |
| 1534 | } |
Dianne Hackborn | 0dad364 | 2010-09-09 21:25:35 -0700 | [diff] [blame] | 1535 | } else { |
Dianne Hackborn | 034093a4 | 2010-09-20 22:24:38 -0700 | [diff] [blame] | 1536 | next.startTime = SystemClock.uptimeMillis(); |
Dianne Hackborn | 0dad364 | 2010-09-09 21:25:35 -0700 | [diff] [blame] | 1537 | mLastStartedActivity = next; |
| 1538 | } |
Dianne Hackborn | 0dad364 | 2010-09-09 21:25:35 -0700 | [diff] [blame] | 1539 | } |
Craig Mautner | 5854780 | 2013-03-05 08:23:53 -0800 | [diff] [blame] | 1540 | |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 1541 | // We need to start pausing the current activity so the top one |
| 1542 | // can be resumed... |
Craig Mautner | 5314a40 | 2013-09-26 12:40:16 -0700 | [diff] [blame] | 1543 | boolean pausing = mStackSupervisor.pauseBackStacks(userLeaving); |
Craig Mautner | eb95786 | 2013-04-24 15:34:32 -0700 | [diff] [blame] | 1544 | if (mResumedActivity != null) { |
| 1545 | pausing = true; |
| 1546 | startPausingLocked(userLeaving, false); |
Craig Mautner | ac6f843 | 2013-07-17 13:24:59 -0700 | [diff] [blame] | 1547 | if (DEBUG_STATES) Slog.d(TAG, "resumeTopActivityLocked: Pausing " + mResumedActivity); |
Craig Mautner | eb95786 | 2013-04-24 15:34:32 -0700 | [diff] [blame] | 1548 | } |
| 1549 | if (pausing) { |
Craig Mautner | ac6f843 | 2013-07-17 13:24:59 -0700 | [diff] [blame] | 1550 | if (DEBUG_SWITCH || DEBUG_STATES) Slog.v(TAG, |
| 1551 | "resumeTopActivityLocked: Skip resume: need to start pausing"); |
Dianne Hackborn | ad9b3211 | 2012-09-17 15:35:01 -0700 | [diff] [blame] | 1552 | // At this point we want to put the upcoming activity's process |
| 1553 | // at the top of the LRU list, since we know we will be needing it |
| 1554 | // very soon and it would be a waste to let it get killed if it |
| 1555 | // happens to be sitting towards the end. |
| 1556 | if (next.app != null && next.app.thread != null) { |
| 1557 | // No reason to do full oom adj update here; we'll let that |
| 1558 | // happen whenever it needs to later. |
Dianne Hackborn | db92608 | 2013-10-31 16:32:44 -0700 | [diff] [blame] | 1559 | mService.updateLruProcessLocked(next.app, true, null); |
Dianne Hackborn | ad9b3211 | 2012-09-17 15:35:01 -0700 | [diff] [blame] | 1560 | } |
Craig Mautner | cf910b0 | 2013-04-23 11:23:27 -0700 | [diff] [blame] | 1561 | if (DEBUG_STACK) mStackSupervisor.validateTopActivitiesLocked(); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 1562 | return true; |
| 1563 | } |
| 1564 | |
Christopher Tate | d3f175c | 2012-06-14 14:16:54 -0700 | [diff] [blame] | 1565 | // If the most recent activity was noHistory but was only stopped rather |
| 1566 | // than stopped+finished because the device went to sleep, we need to make |
| 1567 | // sure to finish it as we're making a new activity topmost. |
Dianne Hackborn | 91097de | 2014-04-04 18:02:06 -0700 | [diff] [blame] | 1568 | if (mService.isSleeping() && mLastNoHistoryActivity != null && |
Craig Mautner | 0f92274 | 2013-08-06 08:44:42 -0700 | [diff] [blame] | 1569 | !mLastNoHistoryActivity.finishing) { |
| 1570 | if (DEBUG_STATES) Slog.d(TAG, "no-history finish of " + mLastNoHistoryActivity + |
| 1571 | " on new resume"); |
| 1572 | requestFinishActivityLocked(mLastNoHistoryActivity.appToken, Activity.RESULT_CANCELED, |
| 1573 | null, "no-history", false); |
| 1574 | mLastNoHistoryActivity = null; |
Christopher Tate | d3f175c | 2012-06-14 14:16:54 -0700 | [diff] [blame] | 1575 | } |
| 1576 | |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 1577 | if (prev != null && prev != next) { |
| 1578 | if (!prev.waitingVisible && next != null && !next.nowVisible) { |
| 1579 | prev.waitingVisible = true; |
Craig Mautner | de4ef02 | 2013-04-07 19:01:33 -0700 | [diff] [blame] | 1580 | mStackSupervisor.mWaitingVisibleActivities.add(prev); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 1581 | if (DEBUG_SWITCH) Slog.v( |
| 1582 | TAG, "Resuming top, waiting visible to hide: " + prev); |
| 1583 | } else { |
| 1584 | // The next activity is already visible, so hide the previous |
| 1585 | // activity's windows right now so we can show the new one ASAP. |
| 1586 | // We only do this if the previous is finishing, which should mean |
| 1587 | // it is on top of the one being resumed so hiding it quickly |
| 1588 | // is good. Otherwise, we want to do the normal route of allowing |
| 1589 | // the resumed activity to be shown so we can decide if the |
| 1590 | // previous should actually be hidden depending on whether the |
| 1591 | // new one is found to be full-screen or not. |
| 1592 | if (prev.finishing) { |
Craig Mautner | ce5f3cb | 2013-04-22 08:58:54 -0700 | [diff] [blame] | 1593 | mWindowManager.setAppVisibility(prev.appToken, false); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 1594 | if (DEBUG_SWITCH) Slog.v(TAG, "Not waiting for visible to hide: " |
| 1595 | + prev + ", waitingVisible=" |
| 1596 | + (prev != null ? prev.waitingVisible : null) |
| 1597 | + ", nowVisible=" + next.nowVisible); |
| 1598 | } else { |
| 1599 | if (DEBUG_SWITCH) Slog.v(TAG, "Previous already visible but still waiting to hide: " |
| 1600 | + prev + ", waitingVisible=" |
| 1601 | + (prev != null ? prev.waitingVisible : null) |
| 1602 | + ", nowVisible=" + next.nowVisible); |
| 1603 | } |
| 1604 | } |
| 1605 | } |
| 1606 | |
Dianne Hackborn | e7f9721 | 2011-02-24 14:40:20 -0800 | [diff] [blame] | 1607 | // Launching this app's activity, make sure the app is no longer |
| 1608 | // considered stopped. |
| 1609 | try { |
| 1610 | AppGlobals.getPackageManager().setPackageStoppedState( |
Amith Yamasani | 483f3b0 | 2012-03-13 16:08:00 -0700 | [diff] [blame] | 1611 | next.packageName, false, next.userId); /* TODO: Verify if correct userid */ |
Dianne Hackborn | e7f9721 | 2011-02-24 14:40:20 -0800 | [diff] [blame] | 1612 | } catch (RemoteException e1) { |
Dianne Hackborn | a925cd4 | 2011-03-10 13:18:20 -0800 | [diff] [blame] | 1613 | } catch (IllegalArgumentException e) { |
| 1614 | Slog.w(TAG, "Failed trying to unstop package " |
| 1615 | + next.packageName + ": " + e); |
Dianne Hackborn | e7f9721 | 2011-02-24 14:40:20 -0800 | [diff] [blame] | 1616 | } |
| 1617 | |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 1618 | // We are starting up the next activity, so tell the window manager |
| 1619 | // that the previous one will be hidden soon. This way it can know |
| 1620 | // to ignore it when computing the desired screen orientation. |
Craig Mautner | 525f3d9 | 2013-05-07 14:01:50 -0700 | [diff] [blame] | 1621 | boolean anim = true; |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 1622 | if (prev != null) { |
| 1623 | if (prev.finishing) { |
| 1624 | if (DEBUG_TRANSITION) Slog.v(TAG, |
| 1625 | "Prepare close transition: prev=" + prev); |
| 1626 | if (mNoAnimActivities.contains(prev)) { |
Craig Mautner | 525f3d9 | 2013-05-07 14:01:50 -0700 | [diff] [blame] | 1627 | anim = false; |
Craig Mautner | ce5f3cb | 2013-04-22 08:58:54 -0700 | [diff] [blame] | 1628 | mWindowManager.prepareAppTransition(AppTransition.TRANSIT_NONE, false); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 1629 | } else { |
Craig Mautner | ce5f3cb | 2013-04-22 08:58:54 -0700 | [diff] [blame] | 1630 | mWindowManager.prepareAppTransition(prev.task == next.task |
Craig Mautner | 4b71aa1 | 2012-12-27 17:20:01 -0800 | [diff] [blame] | 1631 | ? AppTransition.TRANSIT_ACTIVITY_CLOSE |
| 1632 | : AppTransition.TRANSIT_TASK_CLOSE, false); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 1633 | } |
Craig Mautner | ce5f3cb | 2013-04-22 08:58:54 -0700 | [diff] [blame] | 1634 | mWindowManager.setAppWillBeHidden(prev.appToken); |
| 1635 | mWindowManager.setAppVisibility(prev.appToken, false); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 1636 | } else { |
Craig Mautner | ce5f3cb | 2013-04-22 08:58:54 -0700 | [diff] [blame] | 1637 | if (DEBUG_TRANSITION) Slog.v(TAG, "Prepare open transition: prev=" + prev); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 1638 | if (mNoAnimActivities.contains(next)) { |
Craig Mautner | 525f3d9 | 2013-05-07 14:01:50 -0700 | [diff] [blame] | 1639 | anim = false; |
Craig Mautner | ce5f3cb | 2013-04-22 08:58:54 -0700 | [diff] [blame] | 1640 | mWindowManager.prepareAppTransition(AppTransition.TRANSIT_NONE, false); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 1641 | } else { |
Craig Mautner | ce5f3cb | 2013-04-22 08:58:54 -0700 | [diff] [blame] | 1642 | mWindowManager.prepareAppTransition(prev.task == next.task |
Craig Mautner | 4b71aa1 | 2012-12-27 17:20:01 -0800 | [diff] [blame] | 1643 | ? AppTransition.TRANSIT_ACTIVITY_OPEN |
| 1644 | : AppTransition.TRANSIT_TASK_OPEN, false); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 1645 | } |
| 1646 | } |
| 1647 | if (false) { |
Craig Mautner | ce5f3cb | 2013-04-22 08:58:54 -0700 | [diff] [blame] | 1648 | mWindowManager.setAppWillBeHidden(prev.appToken); |
| 1649 | mWindowManager.setAppVisibility(prev.appToken, false); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 1650 | } |
Craig Mautner | 967212c | 2013-04-13 21:10:58 -0700 | [diff] [blame] | 1651 | } else { |
Craig Mautner | ce5f3cb | 2013-04-22 08:58:54 -0700 | [diff] [blame] | 1652 | if (DEBUG_TRANSITION) Slog.v(TAG, "Prepare open transition: no previous"); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 1653 | if (mNoAnimActivities.contains(next)) { |
Craig Mautner | 525f3d9 | 2013-05-07 14:01:50 -0700 | [diff] [blame] | 1654 | anim = false; |
Craig Mautner | ce5f3cb | 2013-04-22 08:58:54 -0700 | [diff] [blame] | 1655 | mWindowManager.prepareAppTransition(AppTransition.TRANSIT_NONE, false); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 1656 | } else { |
Craig Mautner | ce5f3cb | 2013-04-22 08:58:54 -0700 | [diff] [blame] | 1657 | mWindowManager.prepareAppTransition(AppTransition.TRANSIT_ACTIVITY_OPEN, false); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 1658 | } |
| 1659 | } |
Adam Powell | cfbe9be | 2013-11-06 14:58:58 -0800 | [diff] [blame] | 1660 | |
| 1661 | Bundle resumeAnimOptions = null; |
Craig Mautner | 525f3d9 | 2013-05-07 14:01:50 -0700 | [diff] [blame] | 1662 | if (anim) { |
Adam Powell | cfbe9be | 2013-11-06 14:58:58 -0800 | [diff] [blame] | 1663 | ActivityOptions opts = next.getOptionsForTargetActivityLocked(); |
| 1664 | if (opts != null) { |
| 1665 | resumeAnimOptions = opts.toBundle(); |
| 1666 | } |
Dianne Hackborn | 7a2195c | 2012-03-19 17:38:00 -0700 | [diff] [blame] | 1667 | next.applyOptionsLocked(); |
| 1668 | } else { |
| 1669 | next.clearOptionsLocked(); |
| 1670 | } |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 1671 | |
Craig Mautner | cf910b0 | 2013-04-23 11:23:27 -0700 | [diff] [blame] | 1672 | ActivityStack lastStack = mStackSupervisor.getLastStack(); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 1673 | if (next.app != null && next.app.thread != null) { |
| 1674 | if (DEBUG_SWITCH) Slog.v(TAG, "Resume running: " + next); |
| 1675 | |
| 1676 | // This activity is now becoming visible. |
Craig Mautner | ce5f3cb | 2013-04-22 08:58:54 -0700 | [diff] [blame] | 1677 | mWindowManager.setAppVisibility(next.appToken, true); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 1678 | |
Dianne Hackborn | 2a29b3a | 2012-03-15 15:48:38 -0700 | [diff] [blame] | 1679 | // schedule launch ticks to collect information about slow apps. |
| 1680 | next.startLaunchTickingLocked(); |
| 1681 | |
Craig Mautner | f88c50f | 2013-04-18 19:25:12 -0700 | [diff] [blame] | 1682 | ActivityRecord lastResumedActivity = |
| 1683 | lastStack == null ? null :lastStack.mResumedActivity; |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 1684 | ActivityState lastState = next.state; |
| 1685 | |
| 1686 | mService.updateCpuStats(); |
Craig Mautner | 5854780 | 2013-03-05 08:23:53 -0800 | [diff] [blame] | 1687 | |
Dianne Hackborn | ce86ba8 | 2011-07-13 19:33:41 -0700 | [diff] [blame] | 1688 | if (DEBUG_STATES) Slog.v(TAG, "Moving to RESUMED: " + next + " (in existing)"); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 1689 | next.state = ActivityState.RESUMED; |
| 1690 | mResumedActivity = next; |
| 1691 | next.task.touchActiveTime(); |
Craig Mautner | d232895 | 2013-03-05 12:46:26 -0800 | [diff] [blame] | 1692 | mService.addRecentTaskLocked(next.task); |
Dianne Hackborn | db92608 | 2013-10-31 16:32:44 -0700 | [diff] [blame] | 1693 | mService.updateLruProcessLocked(next.app, true, null); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 1694 | updateLRUListLocked(next); |
Dianne Hackborn | db92608 | 2013-10-31 16:32:44 -0700 | [diff] [blame] | 1695 | mService.updateOomAdjLocked(); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 1696 | |
| 1697 | // Have the window manager re-evaluate the orientation of |
| 1698 | // the screen based on the new activity order. |
Craig Mautner | 525f3d9 | 2013-05-07 14:01:50 -0700 | [diff] [blame] | 1699 | boolean notUpdated = true; |
Craig Mautner | de4ef02 | 2013-04-07 19:01:33 -0700 | [diff] [blame] | 1700 | if (mStackSupervisor.isFrontStack(this)) { |
Craig Mautner | ce5f3cb | 2013-04-22 08:58:54 -0700 | [diff] [blame] | 1701 | Configuration config = mWindowManager.updateOrientationFromAppTokens( |
Craig Mautner | 8d341ef | 2013-03-26 09:03:27 -0700 | [diff] [blame] | 1702 | mService.mConfiguration, |
| 1703 | next.mayFreezeScreenLocked(next.app) ? next.appToken : null); |
| 1704 | if (config != null) { |
| 1705 | next.frozenBeforeDestroy = true; |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 1706 | } |
Craig Mautner | 525f3d9 | 2013-05-07 14:01:50 -0700 | [diff] [blame] | 1707 | notUpdated = !mService.updateConfigurationLocked(config, next, false, false); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 1708 | } |
Craig Mautner | 8d341ef | 2013-03-26 09:03:27 -0700 | [diff] [blame] | 1709 | |
Craig Mautner | 525f3d9 | 2013-05-07 14:01:50 -0700 | [diff] [blame] | 1710 | if (notUpdated) { |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 1711 | // The configuration update wasn't able to keep the existing |
| 1712 | // instance of the activity, and instead started a new one. |
| 1713 | // We should be all done, but let's just make sure our activity |
| 1714 | // is still at the top and schedule another run if something |
| 1715 | // weird happened. |
| 1716 | ActivityRecord nextNext = topRunningActivityLocked(null); |
Craig Mautner | ac6f843 | 2013-07-17 13:24:59 -0700 | [diff] [blame] | 1717 | if (DEBUG_SWITCH || DEBUG_STATES) Slog.i(TAG, |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 1718 | "Activity config changed during resume: " + next |
| 1719 | + ", new next: " + nextNext); |
| 1720 | if (nextNext != next) { |
| 1721 | // Do over! |
Craig Mautner | 05d2903 | 2013-05-03 13:40:13 -0700 | [diff] [blame] | 1722 | mStackSupervisor.scheduleResumeTopActivities(); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 1723 | } |
Craig Mautner | ce5f3cb | 2013-04-22 08:58:54 -0700 | [diff] [blame] | 1724 | if (mStackSupervisor.reportResumedActivityLocked(next)) { |
Craig Mautner | de4ef02 | 2013-04-07 19:01:33 -0700 | [diff] [blame] | 1725 | mNoAnimActivities.clear(); |
Craig Mautner | cf910b0 | 2013-04-23 11:23:27 -0700 | [diff] [blame] | 1726 | if (DEBUG_STACK) mStackSupervisor.validateTopActivitiesLocked(); |
Craig Mautner | de4ef02 | 2013-04-07 19:01:33 -0700 | [diff] [blame] | 1727 | return true; |
| 1728 | } |
Craig Mautner | cf910b0 | 2013-04-23 11:23:27 -0700 | [diff] [blame] | 1729 | if (DEBUG_STACK) mStackSupervisor.validateTopActivitiesLocked(); |
Craig Mautner | de4ef02 | 2013-04-07 19:01:33 -0700 | [diff] [blame] | 1730 | return false; |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 1731 | } |
Craig Mautner | 5854780 | 2013-03-05 08:23:53 -0800 | [diff] [blame] | 1732 | |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 1733 | try { |
| 1734 | // Deliver all pending results. |
Craig Mautner | 05d6272ba | 2013-02-11 09:39:27 -0800 | [diff] [blame] | 1735 | ArrayList<ResultInfo> a = next.results; |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 1736 | if (a != null) { |
| 1737 | final int N = a.size(); |
| 1738 | if (!next.finishing && N > 0) { |
| 1739 | if (DEBUG_RESULTS) Slog.v( |
| 1740 | TAG, "Delivering results to " + next |
| 1741 | + ": " + a); |
Dianne Hackborn | be70785 | 2011-11-11 14:32:10 -0800 | [diff] [blame] | 1742 | next.app.thread.scheduleSendResult(next.appToken, a); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 1743 | } |
| 1744 | } |
| 1745 | |
| 1746 | if (next.newIntents != null) { |
Dianne Hackborn | be70785 | 2011-11-11 14:32:10 -0800 | [diff] [blame] | 1747 | next.app.thread.scheduleNewIntent(next.newIntents, next.appToken); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 1748 | } |
| 1749 | |
| 1750 | EventLog.writeEvent(EventLogTags.AM_RESUME_ACTIVITY, |
Dianne Hackborn | b12e135 | 2012-09-26 11:39:20 -0700 | [diff] [blame] | 1751 | next.userId, System.identityHashCode(next), |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 1752 | next.task.taskId, next.shortComponentName); |
Craig Mautner | 5854780 | 2013-03-05 08:23:53 -0800 | [diff] [blame] | 1753 | |
Dianne Hackborn | 4eba96b | 2011-01-21 13:34:36 -0800 | [diff] [blame] | 1754 | next.sleeping = false; |
Craig Mautner | 2420ead | 2013-04-01 17:13:20 -0700 | [diff] [blame] | 1755 | mService.showAskCompatModeDialogLocked(next); |
Dianne Hackborn | 905577f | 2011-09-07 18:31:28 -0700 | [diff] [blame] | 1756 | next.app.pendingUiClean = true; |
Dianne Hackborn | a413dc0 | 2013-07-12 12:02:55 -0700 | [diff] [blame] | 1757 | next.app.forceProcessStateUpTo(ActivityManager.PROCESS_STATE_TOP); |
George Mount | 2c92c97 | 2014-03-20 09:38:23 -0700 | [diff] [blame] | 1758 | next.clearOptionsLocked(); |
Dianne Hackborn | a413dc0 | 2013-07-12 12:02:55 -0700 | [diff] [blame] | 1759 | next.app.thread.scheduleResumeActivity(next.appToken, next.app.repProcState, |
Adam Powell | cfbe9be | 2013-11-06 14:58:58 -0800 | [diff] [blame] | 1760 | mService.isNextTransitionForward(), resumeAnimOptions); |
Craig Mautner | 5854780 | 2013-03-05 08:23:53 -0800 | [diff] [blame] | 1761 | |
Craig Mautner | 0eea92c | 2013-05-16 13:35:39 -0700 | [diff] [blame] | 1762 | mStackSupervisor.checkReadyForSleepLocked(); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 1763 | |
Craig Mautner | ac6f843 | 2013-07-17 13:24:59 -0700 | [diff] [blame] | 1764 | if (DEBUG_STATES) Slog.d(TAG, "resumeTopActivityLocked: Resumed " + next); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 1765 | } catch (Exception e) { |
| 1766 | // Whoops, need to restart this activity! |
Dianne Hackborn | ce86ba8 | 2011-07-13 19:33:41 -0700 | [diff] [blame] | 1767 | if (DEBUG_STATES) Slog.v(TAG, "Resume failed; resetting state to " |
| 1768 | + lastState + ": " + next); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 1769 | next.state = lastState; |
Craig Mautner | f88c50f | 2013-04-18 19:25:12 -0700 | [diff] [blame] | 1770 | if (lastStack != null) { |
| 1771 | lastStack.mResumedActivity = lastResumedActivity; |
| 1772 | } |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 1773 | Slog.i(TAG, "Restarting because process died: " + next); |
| 1774 | if (!next.hasBeenLaunched) { |
| 1775 | next.hasBeenLaunched = true; |
Craig Mautner | f88c50f | 2013-04-18 19:25:12 -0700 | [diff] [blame] | 1776 | } else if (SHOW_APP_STARTING_PREVIEW && lastStack != null && |
| 1777 | mStackSupervisor.isFrontStack(lastStack)) { |
Craig Mautner | ce5f3cb | 2013-04-22 08:58:54 -0700 | [diff] [blame] | 1778 | mWindowManager.setAppStartingWindow( |
Craig Mautner | f88c50f | 2013-04-18 19:25:12 -0700 | [diff] [blame] | 1779 | next.appToken, next.packageName, next.theme, |
| 1780 | mService.compatibilityInfoForPackageLocked(next.info.applicationInfo), |
Adam Powell | 04fe6eb | 2013-05-31 14:39:48 -0700 | [diff] [blame] | 1781 | next.nonLocalizedLabel, next.labelRes, next.icon, next.logo, |
| 1782 | next.windowFlags, null, true); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 1783 | } |
George Mount | 2c92c97 | 2014-03-20 09:38:23 -0700 | [diff] [blame] | 1784 | mStackSupervisor.startSpecificActivityLocked(next, true, false); |
Craig Mautner | cf910b0 | 2013-04-23 11:23:27 -0700 | [diff] [blame] | 1785 | if (DEBUG_STACK) mStackSupervisor.validateTopActivitiesLocked(); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 1786 | return true; |
| 1787 | } |
| 1788 | |
| 1789 | // From this point on, if something goes wrong there is no way |
| 1790 | // to recover the activity. |
| 1791 | try { |
| 1792 | next.visible = true; |
| 1793 | completeResumeLocked(next); |
| 1794 | } catch (Exception e) { |
| 1795 | // If any exception gets thrown, toss away this |
| 1796 | // activity and try the next one. |
| 1797 | Slog.w(TAG, "Exception thrown during resume of " + next, e); |
Dianne Hackborn | be70785 | 2011-11-11 14:32:10 -0800 | [diff] [blame] | 1798 | requestFinishActivityLocked(next.appToken, Activity.RESULT_CANCELED, null, |
Dianne Hackborn | 2d1b378 | 2012-09-09 17:49:39 -0700 | [diff] [blame] | 1799 | "resume-exception", true); |
Craig Mautner | cf910b0 | 2013-04-23 11:23:27 -0700 | [diff] [blame] | 1800 | if (DEBUG_STACK) mStackSupervisor.validateTopActivitiesLocked(); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 1801 | return true; |
| 1802 | } |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 1803 | next.stopped = false; |
| 1804 | |
| 1805 | } else { |
| 1806 | // Whoops, need to restart this activity! |
| 1807 | if (!next.hasBeenLaunched) { |
| 1808 | next.hasBeenLaunched = true; |
| 1809 | } else { |
| 1810 | if (SHOW_APP_STARTING_PREVIEW) { |
Craig Mautner | ce5f3cb | 2013-04-22 08:58:54 -0700 | [diff] [blame] | 1811 | mWindowManager.setAppStartingWindow( |
Dianne Hackborn | be70785 | 2011-11-11 14:32:10 -0800 | [diff] [blame] | 1812 | next.appToken, next.packageName, next.theme, |
Dianne Hackborn | 2f0b175 | 2011-05-31 17:59:49 -0700 | [diff] [blame] | 1813 | mService.compatibilityInfoForPackageLocked( |
| 1814 | next.info.applicationInfo), |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 1815 | next.nonLocalizedLabel, |
Adam Powell | 04fe6eb | 2013-05-31 14:39:48 -0700 | [diff] [blame] | 1816 | next.labelRes, next.icon, next.logo, next.windowFlags, |
Dianne Hackborn | 7eec10e | 2010-11-12 18:03:47 -0800 | [diff] [blame] | 1817 | null, true); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 1818 | } |
| 1819 | if (DEBUG_SWITCH) Slog.v(TAG, "Restarting: " + next); |
| 1820 | } |
Craig Mautner | ac6f843 | 2013-07-17 13:24:59 -0700 | [diff] [blame] | 1821 | if (DEBUG_STATES) Slog.d(TAG, "resumeTopActivityLocked: Restarting " + next); |
George Mount | 2c92c97 | 2014-03-20 09:38:23 -0700 | [diff] [blame] | 1822 | mStackSupervisor.startSpecificActivityLocked(next, true, true); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 1823 | } |
| 1824 | |
Craig Mautner | cf910b0 | 2013-04-23 11:23:27 -0700 | [diff] [blame] | 1825 | if (DEBUG_STACK) mStackSupervisor.validateTopActivitiesLocked(); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 1826 | return true; |
| 1827 | } |
| 1828 | |
Craig Mautner | ac6f843 | 2013-07-17 13:24:59 -0700 | [diff] [blame] | 1829 | private void insertTaskAtTop(TaskRecord task) { |
Craig Mautner | 9c85c20 | 2013-10-04 20:11:26 -0700 | [diff] [blame] | 1830 | // If this is being moved to the top by another activity or being launched from the home |
| 1831 | // activity, set mOnTopOfHome accordingly. |
Craig Mautner | e0a3884 | 2013-12-16 16:14:02 -0800 | [diff] [blame] | 1832 | if (isOnHomeDisplay()) { |
| 1833 | ActivityStack lastStack = mStackSupervisor.getLastStack(); |
| 1834 | final boolean fromHome = lastStack.isHomeStack(); |
| 1835 | if (!isHomeStack() && (fromHome || topTask() != task)) { |
Craig Mautner | b9a6c8a | 2014-05-29 16:50:59 +0000 | [diff] [blame] | 1836 | task.mOnTopOfHome = fromHome; |
Craig Mautner | e0a3884 | 2013-12-16 16:14:02 -0800 | [diff] [blame] | 1837 | } |
| 1838 | } else { |
Craig Mautner | b9a6c8a | 2014-05-29 16:50:59 +0000 | [diff] [blame] | 1839 | task.mOnTopOfHome = false; |
Craig Mautner | 9c85c20 | 2013-10-04 20:11:26 -0700 | [diff] [blame] | 1840 | } |
Craig Mautner | d99384d | 2013-10-14 07:09:18 -0700 | [diff] [blame] | 1841 | |
Craig Mautner | ac6f843 | 2013-07-17 13:24:59 -0700 | [diff] [blame] | 1842 | mTaskHistory.remove(task); |
| 1843 | // Now put task at top. |
| 1844 | int stackNdx = mTaskHistory.size(); |
Kenny Guy | 2a76494 | 2014-04-02 13:29:20 +0100 | [diff] [blame] | 1845 | if (!isCurrentProfileLocked(task.userId)) { |
Craig Mautner | ac6f843 | 2013-07-17 13:24:59 -0700 | [diff] [blame] | 1846 | // Put non-current user tasks below current user tasks. |
| 1847 | while (--stackNdx >= 0) { |
Kenny Guy | 2a76494 | 2014-04-02 13:29:20 +0100 | [diff] [blame] | 1848 | if (!isCurrentProfileLocked(mTaskHistory.get(stackNdx).userId)) { |
Craig Mautner | ac6f843 | 2013-07-17 13:24:59 -0700 | [diff] [blame] | 1849 | break; |
| 1850 | } |
| 1851 | } |
| 1852 | ++stackNdx; |
| 1853 | } |
| 1854 | mTaskHistory.add(stackNdx, task); |
Craig Mautner | 21d24a2 | 2014-04-23 11:45:37 -0700 | [diff] [blame] | 1855 | updateTaskMovement(task, true); |
Craig Mautner | ac6f843 | 2013-07-17 13:24:59 -0700 | [diff] [blame] | 1856 | } |
Craig Mautner | 11bf9a5 | 2013-02-19 14:08:51 -0800 | [diff] [blame] | 1857 | |
Craig Mautner | 8849a5e | 2013-04-02 16:41:03 -0700 | [diff] [blame] | 1858 | final void startActivityLocked(ActivityRecord r, boolean newTask, |
Dianne Hackborn | 7a2195c | 2012-03-19 17:38:00 -0700 | [diff] [blame] | 1859 | boolean doResume, boolean keepCurTransition, Bundle options) { |
Craig Mautner | d232895 | 2013-03-05 12:46:26 -0800 | [diff] [blame] | 1860 | TaskRecord rTask = r.task; |
| 1861 | final int taskId = rTask.taskId; |
| 1862 | if (taskForIdLocked(taskId) == null || newTask) { |
Craig Mautner | 7787877 | 2013-03-04 19:46:24 -0800 | [diff] [blame] | 1863 | // Last activity in task had been removed or ActivityManagerService is reusing task. |
| 1864 | // Insert or replace. |
Craig Mautner | 7787877 | 2013-03-04 19:46:24 -0800 | [diff] [blame] | 1865 | // Might not even be in. |
Craig Mautner | ac6f843 | 2013-07-17 13:24:59 -0700 | [diff] [blame] | 1866 | insertTaskAtTop(rTask); |
Craig Mautner | ce5f3cb | 2013-04-22 08:58:54 -0700 | [diff] [blame] | 1867 | mWindowManager.moveTaskToTop(taskId); |
Craig Mautner | 7787877 | 2013-03-04 19:46:24 -0800 | [diff] [blame] | 1868 | } |
Craig Mautner | 525f3d9 | 2013-05-07 14:01:50 -0700 | [diff] [blame] | 1869 | TaskRecord task = null; |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 1870 | if (!newTask) { |
| 1871 | // If starting in an existing task, find where that is... |
Craig Mautner | 70a8693 | 2013-02-28 22:37:44 -0800 | [diff] [blame] | 1872 | boolean startIt = true; |
| 1873 | for (int taskNdx = mTaskHistory.size() - 1; taskNdx >= 0; --taskNdx) { |
| 1874 | task = mTaskHistory.get(taskNdx); |
| 1875 | if (task == r.task) { |
| 1876 | // Here it is! Now, if this is not yet visible to the |
| 1877 | // user, then just add it without starting; it will |
| 1878 | // get started when the user navigates back to it. |
Craig Mautner | 70a8693 | 2013-02-28 22:37:44 -0800 | [diff] [blame] | 1879 | if (!startIt) { |
| 1880 | if (DEBUG_ADD_REMOVE) Slog.i(TAG, "Adding activity " + r + " to task " |
| 1881 | + task, new RuntimeException("here").fillInStackTrace()); |
| 1882 | task.addActivityToTop(r); |
Dianne Hackborn | f26fd99 | 2011-04-08 18:14:09 -0700 | [diff] [blame] | 1883 | r.putInHistory(); |
Craig Mautner | ce5f3cb | 2013-04-22 08:58:54 -0700 | [diff] [blame] | 1884 | mWindowManager.addAppToken(task.mActivities.indexOf(r), r.appToken, |
| 1885 | r.task.taskId, mStackId, r.info.screenOrientation, r.fullscreen, |
Craig Mautner | ac6f843 | 2013-07-17 13:24:59 -0700 | [diff] [blame] | 1886 | (r.info.flags & ActivityInfo.FLAG_SHOW_ON_LOCK_SCREEN) != 0, |
Dianne Hackborn | e30e02f | 2014-05-27 18:24:45 -0700 | [diff] [blame] | 1887 | r.userId, r.info.configChanges, task.voiceSession != null); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 1888 | if (VALIDATE_TOKENS) { |
Dianne Hackborn | be70785 | 2011-11-11 14:32:10 -0800 | [diff] [blame] | 1889 | validateAppTokensLocked(); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 1890 | } |
Dianne Hackborn | 8078d8c | 2012-03-20 11:11:26 -0700 | [diff] [blame] | 1891 | ActivityOptions.abort(options); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 1892 | return; |
| 1893 | } |
| 1894 | break; |
Craig Mautner | 70a8693 | 2013-02-28 22:37:44 -0800 | [diff] [blame] | 1895 | } else if (task.numFullscreen > 0) { |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 1896 | startIt = false; |
| 1897 | } |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 1898 | } |
| 1899 | } |
| 1900 | |
| 1901 | // Place a new activity at top of stack, so it is next to interact |
| 1902 | // with the user. |
Craig Mautner | 70a8693 | 2013-02-28 22:37:44 -0800 | [diff] [blame] | 1903 | |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 1904 | // If we are not placing the new activity frontmost, we do not want |
| 1905 | // to deliver the onUserLeaving callback to the actual frontmost |
| 1906 | // activity |
Craig Mautner | 70a8693 | 2013-02-28 22:37:44 -0800 | [diff] [blame] | 1907 | if (task == r.task && mTaskHistory.indexOf(task) != (mTaskHistory.size() - 1)) { |
Craig Mautner | de4ef02 | 2013-04-07 19:01:33 -0700 | [diff] [blame] | 1908 | mStackSupervisor.mUserLeaving = false; |
Craig Mautner | 70a8693 | 2013-02-28 22:37:44 -0800 | [diff] [blame] | 1909 | if (DEBUG_USER_LEAVING) Slog.v(TAG, |
| 1910 | "startActivity() behind front, mUserLeaving=false"); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 1911 | } |
Craig Mautner | 70a8693 | 2013-02-28 22:37:44 -0800 | [diff] [blame] | 1912 | |
| 1913 | task = r.task; |
| 1914 | |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 1915 | // Slot the activity into the history stack and proceed |
Craig Mautner | 70a8693 | 2013-02-28 22:37:44 -0800 | [diff] [blame] | 1916 | if (DEBUG_ADD_REMOVE) Slog.i(TAG, "Adding activity " + r + " to stack to task " + task, |
Craig Mautner | 56f52db | 2013-02-25 10:03:01 -0800 | [diff] [blame] | 1917 | new RuntimeException("here").fillInStackTrace()); |
Craig Mautner | 70a8693 | 2013-02-28 22:37:44 -0800 | [diff] [blame] | 1918 | task.addActivityToTop(r); |
Craig Mautner | 1aa9d0d3f | 2013-12-16 15:58:31 -0800 | [diff] [blame] | 1919 | task.setFrontOfTask(); |
Craig Mautner | 70a8693 | 2013-02-28 22:37:44 -0800 | [diff] [blame] | 1920 | |
Dianne Hackborn | f26fd99 | 2011-04-08 18:14:09 -0700 | [diff] [blame] | 1921 | r.putInHistory(); |
Craig Mautner | de4ef02 | 2013-04-07 19:01:33 -0700 | [diff] [blame] | 1922 | if (!isHomeStack() || numActivities() > 0) { |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 1923 | // We want to show the starting preview window if we are |
| 1924 | // switching to a new task, or the next activity's process is |
| 1925 | // not currently running. |
| 1926 | boolean showStartingIcon = newTask; |
| 1927 | ProcessRecord proc = r.app; |
| 1928 | if (proc == null) { |
| 1929 | proc = mService.mProcessNames.get(r.processName, r.info.applicationInfo.uid); |
| 1930 | } |
| 1931 | if (proc == null || proc.thread == null) { |
| 1932 | showStartingIcon = true; |
| 1933 | } |
| 1934 | if (DEBUG_TRANSITION) Slog.v(TAG, |
| 1935 | "Prepare open transition: starting " + r); |
| 1936 | if ((r.intent.getFlags()&Intent.FLAG_ACTIVITY_NO_ANIMATION) != 0) { |
Craig Mautner | ce5f3cb | 2013-04-22 08:58:54 -0700 | [diff] [blame] | 1937 | mWindowManager.prepareAppTransition(AppTransition.TRANSIT_NONE, keepCurTransition); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 1938 | mNoAnimActivities.add(r); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 1939 | } else { |
Craig Mautner | ce5f3cb | 2013-04-22 08:58:54 -0700 | [diff] [blame] | 1940 | mWindowManager.prepareAppTransition(newTask |
Craig Mautner | 4b71aa1 | 2012-12-27 17:20:01 -0800 | [diff] [blame] | 1941 | ? AppTransition.TRANSIT_TASK_OPEN |
| 1942 | : AppTransition.TRANSIT_ACTIVITY_OPEN, keepCurTransition); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 1943 | mNoAnimActivities.remove(r); |
| 1944 | } |
Craig Mautner | ce5f3cb | 2013-04-22 08:58:54 -0700 | [diff] [blame] | 1945 | mWindowManager.addAppToken(task.mActivities.indexOf(r), |
Craig Mautner | c00204b | 2013-03-05 15:02:14 -0800 | [diff] [blame] | 1946 | r.appToken, r.task.taskId, mStackId, r.info.screenOrientation, r.fullscreen, |
Craig Mautner | 5d9f547 | 2013-11-12 14:02:52 -0800 | [diff] [blame] | 1947 | (r.info.flags & ActivityInfo.FLAG_SHOW_ON_LOCK_SCREEN) != 0, r.userId, |
Dianne Hackborn | e30e02f | 2014-05-27 18:24:45 -0700 | [diff] [blame] | 1948 | r.info.configChanges, task.voiceSession != null); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 1949 | boolean doShow = true; |
| 1950 | if (newTask) { |
| 1951 | // Even though this activity is starting fresh, we still need |
| 1952 | // to reset it to make sure we apply affinities to move any |
| 1953 | // existing activities from other tasks in to it. |
| 1954 | // If the caller has requested that the target task be |
| 1955 | // reset, then do so. |
| 1956 | if ((r.intent.getFlags() |
Craig Mautner | d00f474 | 2014-03-12 14:17:26 -0700 | [diff] [blame] | 1957 | & Intent.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED) != 0) { |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 1958 | resetTaskIfNeededLocked(r, r); |
| 1959 | doShow = topRunningNonDelayedActivityLocked(null) == r; |
| 1960 | } |
| 1961 | } |
| 1962 | if (SHOW_APP_STARTING_PREVIEW && doShow) { |
| 1963 | // Figure out if we are transitioning from another activity that is |
| 1964 | // "has the same starting icon" as the next one. This allows the |
| 1965 | // window manager to keep the previous window it had previously |
| 1966 | // created, if it still had one. |
| 1967 | ActivityRecord prev = mResumedActivity; |
| 1968 | if (prev != null) { |
| 1969 | // We don't want to reuse the previous starting preview if: |
| 1970 | // (1) The current activity is in a different task. |
Craig Mautner | 29219d9 | 2013-04-16 20:19:12 -0700 | [diff] [blame] | 1971 | if (prev.task != r.task) { |
| 1972 | prev = null; |
| 1973 | } |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 1974 | // (2) The current activity is already displayed. |
Craig Mautner | 29219d9 | 2013-04-16 20:19:12 -0700 | [diff] [blame] | 1975 | else if (prev.nowVisible) { |
| 1976 | prev = null; |
| 1977 | } |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 1978 | } |
Craig Mautner | ce5f3cb | 2013-04-22 08:58:54 -0700 | [diff] [blame] | 1979 | mWindowManager.setAppStartingWindow( |
Dianne Hackborn | be70785 | 2011-11-11 14:32:10 -0800 | [diff] [blame] | 1980 | r.appToken, r.packageName, r.theme, |
Dianne Hackborn | 2f0b175 | 2011-05-31 17:59:49 -0700 | [diff] [blame] | 1981 | mService.compatibilityInfoForPackageLocked( |
| 1982 | r.info.applicationInfo), r.nonLocalizedLabel, |
Adam Powell | 04fe6eb | 2013-05-31 14:39:48 -0700 | [diff] [blame] | 1983 | r.labelRes, r.icon, r.logo, r.windowFlags, |
Dianne Hackborn | be70785 | 2011-11-11 14:32:10 -0800 | [diff] [blame] | 1984 | prev != null ? prev.appToken : null, showStartingIcon); |
Craig Mautner | a61bc65 | 2013-10-28 15:43:18 -0700 | [diff] [blame] | 1985 | r.mStartingWindowShown = true; |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 1986 | } |
| 1987 | } else { |
| 1988 | // If this is the first activity, don't do any fancy animations, |
| 1989 | // because there is nothing for it to animate on top of. |
Craig Mautner | ce5f3cb | 2013-04-22 08:58:54 -0700 | [diff] [blame] | 1990 | mWindowManager.addAppToken(task.mActivities.indexOf(r), r.appToken, |
Craig Mautner | c00204b | 2013-03-05 15:02:14 -0800 | [diff] [blame] | 1991 | r.task.taskId, mStackId, r.info.screenOrientation, r.fullscreen, |
Craig Mautner | 5d9f547 | 2013-11-12 14:02:52 -0800 | [diff] [blame] | 1992 | (r.info.flags & ActivityInfo.FLAG_SHOW_ON_LOCK_SCREEN) != 0, r.userId, |
Dianne Hackborn | e30e02f | 2014-05-27 18:24:45 -0700 | [diff] [blame] | 1993 | r.info.configChanges, task.voiceSession != null); |
Dianne Hackborn | 8078d8c | 2012-03-20 11:11:26 -0700 | [diff] [blame] | 1994 | ActivityOptions.abort(options); |
Craig Mautner | 233ceee | 2014-05-09 17:05:11 -0700 | [diff] [blame] | 1995 | options = null; |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 1996 | } |
| 1997 | if (VALIDATE_TOKENS) { |
Dianne Hackborn | be70785 | 2011-11-11 14:32:10 -0800 | [diff] [blame] | 1998 | validateAppTokensLocked(); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 1999 | } |
| 2000 | |
| 2001 | if (doResume) { |
Craig Mautner | 233ceee | 2014-05-09 17:05:11 -0700 | [diff] [blame] | 2002 | mStackSupervisor.resumeTopActivitiesLocked(this, r, options); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 2003 | } |
| 2004 | } |
| 2005 | |
Dianne Hackborn | be70785 | 2011-11-11 14:32:10 -0800 | [diff] [blame] | 2006 | final void validateAppTokensLocked() { |
| 2007 | mValidateAppTokens.clear(); |
Craig Mautner | 000f002 | 2013-02-26 15:04:29 -0800 | [diff] [blame] | 2008 | mValidateAppTokens.ensureCapacity(numActivities()); |
| 2009 | final int numTasks = mTaskHistory.size(); |
| 2010 | for (int taskNdx = 0; taskNdx < numTasks; ++taskNdx) { |
| 2011 | TaskRecord task = mTaskHistory.get(taskNdx); |
| 2012 | final ArrayList<ActivityRecord> activities = task.mActivities; |
Craig Mautner | c8143c6 | 2013-09-03 12:15:57 -0700 | [diff] [blame] | 2013 | if (activities.isEmpty()) { |
Craig Mautner | 000f002 | 2013-02-26 15:04:29 -0800 | [diff] [blame] | 2014 | continue; |
Craig Mautner | b1fd65c0 | 2013-02-05 13:34:57 -0800 | [diff] [blame] | 2015 | } |
Craig Mautner | 000f002 | 2013-02-26 15:04:29 -0800 | [diff] [blame] | 2016 | TaskGroup group = new TaskGroup(); |
| 2017 | group.taskId = task.taskId; |
| 2018 | mValidateAppTokens.add(group); |
| 2019 | final int numActivities = activities.size(); |
| 2020 | for (int activityNdx = 0; activityNdx < numActivities; ++activityNdx) { |
| 2021 | final ActivityRecord r = activities.get(activityNdx); |
| 2022 | group.tokens.add(r.appToken); |
| 2023 | } |
Dianne Hackborn | be70785 | 2011-11-11 14:32:10 -0800 | [diff] [blame] | 2024 | } |
Craig Mautner | ce5f3cb | 2013-04-22 08:58:54 -0700 | [diff] [blame] | 2025 | mWindowManager.validateAppTokens(mStackId, mValidateAppTokens); |
Dianne Hackborn | be70785 | 2011-11-11 14:32:10 -0800 | [diff] [blame] | 2026 | } |
| 2027 | |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 2028 | /** |
| 2029 | * Perform a reset of the given task, if needed as part of launching it. |
| 2030 | * Returns the new HistoryRecord at the top of the task. |
| 2031 | */ |
Craig Mautner | e3a74d5 | 2013-02-22 14:14:58 -0800 | [diff] [blame] | 2032 | /** |
| 2033 | * Helper method for #resetTaskIfNeededLocked. |
| 2034 | * We are inside of the task being reset... we'll either finish this activity, push it out |
| 2035 | * for another task, or leave it as-is. |
| 2036 | * @param task The task containing the Activity (taskTop) that might be reset. |
| 2037 | * @param forceReset |
| 2038 | * @return An ActivityOptions that needs to be processed. |
| 2039 | */ |
Craig Mautner | ce5f3cb | 2013-04-22 08:58:54 -0700 | [diff] [blame] | 2040 | final ActivityOptions resetTargetTaskIfNeededLocked(TaskRecord task, boolean forceReset) { |
Craig Mautner | e3a74d5 | 2013-02-22 14:14:58 -0800 | [diff] [blame] | 2041 | ActivityOptions topOptions = null; |
| 2042 | |
| 2043 | int replyChainEnd = -1; |
| 2044 | boolean canMoveOptions = true; |
| 2045 | |
| 2046 | // We only do this for activities that are not the root of the task (since if we finish |
| 2047 | // the root, we may no longer have the task!). |
| 2048 | final ArrayList<ActivityRecord> activities = task.mActivities; |
| 2049 | final int numActivities = activities.size(); |
| 2050 | for (int i = numActivities - 1; i > 0; --i ) { |
| 2051 | ActivityRecord target = activities.get(i); |
| 2052 | |
| 2053 | final int flags = target.info.flags; |
| 2054 | final boolean finishOnTaskLaunch = |
| 2055 | (flags & ActivityInfo.FLAG_FINISH_ON_TASK_LAUNCH) != 0; |
| 2056 | final boolean allowTaskReparenting = |
| 2057 | (flags & ActivityInfo.FLAG_ALLOW_TASK_REPARENTING) != 0; |
| 2058 | final boolean clearWhenTaskReset = |
| 2059 | (target.intent.getFlags() & Intent.FLAG_ACTIVITY_CLEAR_WHEN_TASK_RESET) != 0; |
| 2060 | |
| 2061 | if (!finishOnTaskLaunch |
| 2062 | && !clearWhenTaskReset |
| 2063 | && target.resultTo != null) { |
| 2064 | // If this activity is sending a reply to a previous |
| 2065 | // activity, we can't do anything with it now until |
| 2066 | // we reach the start of the reply chain. |
| 2067 | // XXX note that we are assuming the result is always |
| 2068 | // to the previous activity, which is almost always |
| 2069 | // the case but we really shouldn't count on. |
| 2070 | if (replyChainEnd < 0) { |
| 2071 | replyChainEnd = i; |
| 2072 | } |
| 2073 | } else if (!finishOnTaskLaunch |
| 2074 | && !clearWhenTaskReset |
| 2075 | && allowTaskReparenting |
| 2076 | && target.taskAffinity != null |
| 2077 | && !target.taskAffinity.equals(task.affinity)) { |
| 2078 | // If this activity has an affinity for another |
| 2079 | // task, then we need to move it out of here. We will |
| 2080 | // move it as far out of the way as possible, to the |
| 2081 | // bottom of the activity stack. This also keeps it |
| 2082 | // correctly ordered with any activities we previously |
| 2083 | // moved. |
Craig Mautner | 329f412 | 2013-11-07 09:10:42 -0800 | [diff] [blame] | 2084 | final ThumbnailHolder newThumbHolder; |
| 2085 | final TaskRecord targetTask; |
Craig Mautner | dccb770 | 2013-09-17 15:53:34 -0700 | [diff] [blame] | 2086 | final ActivityRecord bottom = |
| 2087 | !mTaskHistory.isEmpty() && !mTaskHistory.get(0).mActivities.isEmpty() ? |
Craig Mautner | 329f412 | 2013-11-07 09:10:42 -0800 | [diff] [blame] | 2088 | mTaskHistory.get(0).mActivities.get(0) : null; |
Craig Mautner | dccb770 | 2013-09-17 15:53:34 -0700 | [diff] [blame] | 2089 | if (bottom != null && target.taskAffinity != null |
| 2090 | && target.taskAffinity.equals(bottom.task.affinity)) { |
Craig Mautner | e3a74d5 | 2013-02-22 14:14:58 -0800 | [diff] [blame] | 2091 | // If the activity currently at the bottom has the |
| 2092 | // same task affinity as the one we are moving, |
| 2093 | // then merge it into the same task. |
Craig Mautner | 329f412 | 2013-11-07 09:10:42 -0800 | [diff] [blame] | 2094 | targetTask = bottom.task; |
| 2095 | newThumbHolder = bottom.thumbHolder == null ? targetTask : bottom.thumbHolder; |
Craig Mautner | e3a74d5 | 2013-02-22 14:14:58 -0800 | [diff] [blame] | 2096 | if (DEBUG_TASKS) Slog.v(TAG, "Start pushing activity " + target |
Craig Mautner | dccb770 | 2013-09-17 15:53:34 -0700 | [diff] [blame] | 2097 | + " out to bottom task " + bottom.task); |
Craig Mautner | e3a74d5 | 2013-02-22 14:14:58 -0800 | [diff] [blame] | 2098 | } else { |
Craig Mautner | 329f412 | 2013-11-07 09:10:42 -0800 | [diff] [blame] | 2099 | targetTask = createTaskRecord(mStackSupervisor.getNextTaskId(), target.info, |
Dianne Hackborn | 91097de | 2014-04-04 18:02:06 -0700 | [diff] [blame] | 2100 | null, null, null, false); |
Craig Mautner | 329f412 | 2013-11-07 09:10:42 -0800 | [diff] [blame] | 2101 | newThumbHolder = targetTask; |
| 2102 | targetTask.affinityIntent = target.intent; |
Craig Mautner | e3a74d5 | 2013-02-22 14:14:58 -0800 | [diff] [blame] | 2103 | if (DEBUG_TASKS) Slog.v(TAG, "Start pushing activity " + target |
| 2104 | + " out to new task " + target.task); |
| 2105 | } |
| 2106 | |
Craig Mautner | d00f474 | 2014-03-12 14:17:26 -0700 | [diff] [blame] | 2107 | target.thumbHolder = newThumbHolder; |
Craig Mautner | 329f412 | 2013-11-07 09:10:42 -0800 | [diff] [blame] | 2108 | |
Craig Mautner | e3a74d5 | 2013-02-22 14:14:58 -0800 | [diff] [blame] | 2109 | final int targetTaskId = targetTask.taskId; |
Craig Mautner | ce5f3cb | 2013-04-22 08:58:54 -0700 | [diff] [blame] | 2110 | mWindowManager.setAppGroupId(target.appToken, targetTaskId); |
Craig Mautner | e3a74d5 | 2013-02-22 14:14:58 -0800 | [diff] [blame] | 2111 | |
Craig Mautner | 525f3d9 | 2013-05-07 14:01:50 -0700 | [diff] [blame] | 2112 | boolean noOptions = canMoveOptions; |
Craig Mautner | e3a74d5 | 2013-02-22 14:14:58 -0800 | [diff] [blame] | 2113 | final int start = replyChainEnd < 0 ? i : replyChainEnd; |
| 2114 | for (int srcPos = start; srcPos >= i; --srcPos) { |
Craig Mautner | dccb770 | 2013-09-17 15:53:34 -0700 | [diff] [blame] | 2115 | final ActivityRecord p = activities.get(srcPos); |
Craig Mautner | e3a74d5 | 2013-02-22 14:14:58 -0800 | [diff] [blame] | 2116 | if (p.finishing) { |
| 2117 | continue; |
| 2118 | } |
| 2119 | |
Craig Mautner | 525f3d9 | 2013-05-07 14:01:50 -0700 | [diff] [blame] | 2120 | ThumbnailHolder curThumbHolder = p.thumbHolder; |
Craig Mautner | e3a74d5 | 2013-02-22 14:14:58 -0800 | [diff] [blame] | 2121 | canMoveOptions = false; |
Craig Mautner | 525f3d9 | 2013-05-07 14:01:50 -0700 | [diff] [blame] | 2122 | if (noOptions && topOptions == null) { |
Craig Mautner | e3a74d5 | 2013-02-22 14:14:58 -0800 | [diff] [blame] | 2123 | topOptions = p.takeOptionsLocked(); |
| 2124 | if (topOptions != null) { |
Craig Mautner | 525f3d9 | 2013-05-07 14:01:50 -0700 | [diff] [blame] | 2125 | noOptions = false; |
Craig Mautner | e3a74d5 | 2013-02-22 14:14:58 -0800 | [diff] [blame] | 2126 | } |
| 2127 | } |
| 2128 | if (DEBUG_ADD_REMOVE) Slog.i(TAG, "Removing activity " + p + " from task=" |
Craig Mautner | 329f412 | 2013-11-07 09:10:42 -0800 | [diff] [blame] | 2129 | + task + " adding to task=" + targetTask |
| 2130 | + " Callers=" + Debug.getCallers(4)); |
Craig Mautner | e3a74d5 | 2013-02-22 14:14:58 -0800 | [diff] [blame] | 2131 | if (DEBUG_TASKS) Slog.v(TAG, "Pushing next activity " + p |
| 2132 | + " out to target's task " + target.task); |
Craig Mautner | de4ef02 | 2013-04-07 19:01:33 -0700 | [diff] [blame] | 2133 | p.setTask(targetTask, curThumbHolder, false); |
Craig Mautner | e3a74d5 | 2013-02-22 14:14:58 -0800 | [diff] [blame] | 2134 | targetTask.addActivityAtBottom(p); |
Craig Mautner | 0247fc8 | 2013-02-28 14:32:06 -0800 | [diff] [blame] | 2135 | |
Craig Mautner | ce5f3cb | 2013-04-22 08:58:54 -0700 | [diff] [blame] | 2136 | mWindowManager.setAppGroupId(p.appToken, targetTaskId); |
Craig Mautner | e3a74d5 | 2013-02-22 14:14:58 -0800 | [diff] [blame] | 2137 | } |
| 2138 | |
Craig Mautner | ce5f3cb | 2013-04-22 08:58:54 -0700 | [diff] [blame] | 2139 | mWindowManager.moveTaskToBottom(targetTaskId); |
Craig Mautner | e3a74d5 | 2013-02-22 14:14:58 -0800 | [diff] [blame] | 2140 | if (VALIDATE_TOKENS) { |
| 2141 | validateAppTokensLocked(); |
| 2142 | } |
| 2143 | |
| 2144 | replyChainEnd = -1; |
| 2145 | } else if (forceReset || finishOnTaskLaunch || clearWhenTaskReset) { |
| 2146 | // If the activity should just be removed -- either |
| 2147 | // because it asks for it, or the task should be |
| 2148 | // cleared -- then finish it and anything that is |
| 2149 | // part of its reply chain. |
| 2150 | int end; |
| 2151 | if (clearWhenTaskReset) { |
| 2152 | // In this case, we want to finish this activity |
| 2153 | // and everything above it, so be sneaky and pretend |
| 2154 | // like these are all in the reply chain. |
| 2155 | end = numActivities - 1; |
| 2156 | } else if (replyChainEnd < 0) { |
| 2157 | end = i; |
| 2158 | } else { |
| 2159 | end = replyChainEnd; |
| 2160 | } |
Craig Mautner | 525f3d9 | 2013-05-07 14:01:50 -0700 | [diff] [blame] | 2161 | boolean noOptions = canMoveOptions; |
Craig Mautner | e3a74d5 | 2013-02-22 14:14:58 -0800 | [diff] [blame] | 2162 | for (int srcPos = i; srcPos <= end; srcPos++) { |
Craig Mautner | 525f3d9 | 2013-05-07 14:01:50 -0700 | [diff] [blame] | 2163 | ActivityRecord p = activities.get(srcPos); |
Craig Mautner | e3a74d5 | 2013-02-22 14:14:58 -0800 | [diff] [blame] | 2164 | if (p.finishing) { |
| 2165 | continue; |
| 2166 | } |
| 2167 | canMoveOptions = false; |
Craig Mautner | 525f3d9 | 2013-05-07 14:01:50 -0700 | [diff] [blame] | 2168 | if (noOptions && topOptions == null) { |
Craig Mautner | e3a74d5 | 2013-02-22 14:14:58 -0800 | [diff] [blame] | 2169 | topOptions = p.takeOptionsLocked(); |
| 2170 | if (topOptions != null) { |
Craig Mautner | 525f3d9 | 2013-05-07 14:01:50 -0700 | [diff] [blame] | 2171 | noOptions = false; |
Craig Mautner | e3a74d5 | 2013-02-22 14:14:58 -0800 | [diff] [blame] | 2172 | } |
| 2173 | } |
Craig Mautner | 5854780 | 2013-03-05 08:23:53 -0800 | [diff] [blame] | 2174 | if (DEBUG_TASKS) Slog.w(TAG, |
| 2175 | "resetTaskIntendedTask: calling finishActivity on " + p); |
Craig Mautner | d44711d | 2013-02-23 11:24:36 -0800 | [diff] [blame] | 2176 | if (finishActivityLocked(p, Activity.RESULT_CANCELED, null, "reset", false)) { |
Craig Mautner | e3a74d5 | 2013-02-22 14:14:58 -0800 | [diff] [blame] | 2177 | end--; |
| 2178 | srcPos--; |
| 2179 | } |
| 2180 | } |
| 2181 | replyChainEnd = -1; |
| 2182 | } else { |
| 2183 | // If we were in the middle of a chain, well the |
| 2184 | // activity that started it all doesn't want anything |
| 2185 | // special, so leave it all as-is. |
| 2186 | replyChainEnd = -1; |
| 2187 | } |
| 2188 | } |
| 2189 | |
| 2190 | return topOptions; |
| 2191 | } |
| 2192 | |
| 2193 | /** |
| 2194 | * Helper method for #resetTaskIfNeededLocked. Processes all of the activities in a given |
| 2195 | * TaskRecord looking for an affinity with the task of resetTaskIfNeededLocked.taskTop. |
| 2196 | * @param affinityTask The task we are looking for an affinity to. |
| 2197 | * @param task Task that resetTaskIfNeededLocked.taskTop belongs to. |
| 2198 | * @param topTaskIsHigher True if #task has already been processed by resetTaskIfNeededLocked. |
| 2199 | * @param forceReset Flag passed in to resetTaskIfNeededLocked. |
| 2200 | */ |
Craig Mautner | 525f3d9 | 2013-05-07 14:01:50 -0700 | [diff] [blame] | 2201 | private int resetAffinityTaskIfNeededLocked(TaskRecord affinityTask, TaskRecord task, |
Craig Mautner | 7787877 | 2013-03-04 19:46:24 -0800 | [diff] [blame] | 2202 | boolean topTaskIsHigher, boolean forceReset, int taskInsertionPoint) { |
Craig Mautner | e3a74d5 | 2013-02-22 14:14:58 -0800 | [diff] [blame] | 2203 | int replyChainEnd = -1; |
| 2204 | final int taskId = task.taskId; |
| 2205 | final String taskAffinity = task.affinity; |
| 2206 | |
| 2207 | final ArrayList<ActivityRecord> activities = affinityTask.mActivities; |
| 2208 | final int numActivities = activities.size(); |
| 2209 | // Do not operate on the root Activity. |
| 2210 | for (int i = numActivities - 1; i > 0; --i) { |
| 2211 | ActivityRecord target = activities.get(i); |
| 2212 | |
| 2213 | final int flags = target.info.flags; |
| 2214 | boolean finishOnTaskLaunch = (flags & ActivityInfo.FLAG_FINISH_ON_TASK_LAUNCH) != 0; |
| 2215 | boolean allowTaskReparenting = (flags & ActivityInfo.FLAG_ALLOW_TASK_REPARENTING) != 0; |
| 2216 | |
| 2217 | if (target.resultTo != null) { |
| 2218 | // If this activity is sending a reply to a previous |
| 2219 | // activity, we can't do anything with it now until |
| 2220 | // we reach the start of the reply chain. |
| 2221 | // XXX note that we are assuming the result is always |
| 2222 | // to the previous activity, which is almost always |
| 2223 | // the case but we really shouldn't count on. |
| 2224 | if (replyChainEnd < 0) { |
| 2225 | replyChainEnd = i; |
| 2226 | } |
| 2227 | } else if (topTaskIsHigher |
| 2228 | && allowTaskReparenting |
| 2229 | && taskAffinity != null |
| 2230 | && taskAffinity.equals(target.taskAffinity)) { |
| 2231 | // This activity has an affinity for our task. Either remove it if we are |
| 2232 | // clearing or move it over to our task. Note that |
| 2233 | // we currently punt on the case where we are resetting a |
| 2234 | // task that is not at the top but who has activities above |
| 2235 | // with an affinity to it... this is really not a normal |
| 2236 | // case, and we will need to later pull that task to the front |
| 2237 | // and usually at that point we will do the reset and pick |
| 2238 | // up those remaining activities. (This only happens if |
| 2239 | // someone starts an activity in a new task from an activity |
| 2240 | // in a task that is not currently on top.) |
| 2241 | if (forceReset || finishOnTaskLaunch) { |
| 2242 | final int start = replyChainEnd >= 0 ? replyChainEnd : i; |
| 2243 | if (DEBUG_TASKS) Slog.v(TAG, "Finishing task at index " + start + " to " + i); |
| 2244 | for (int srcPos = start; srcPos >= i; --srcPos) { |
| 2245 | final ActivityRecord p = activities.get(srcPos); |
| 2246 | if (p.finishing) { |
| 2247 | continue; |
| 2248 | } |
Craig Mautner | d44711d | 2013-02-23 11:24:36 -0800 | [diff] [blame] | 2249 | finishActivityLocked(p, Activity.RESULT_CANCELED, null, "reset", false); |
Craig Mautner | e3a74d5 | 2013-02-22 14:14:58 -0800 | [diff] [blame] | 2250 | } |
| 2251 | } else { |
Craig Mautner | 7787877 | 2013-03-04 19:46:24 -0800 | [diff] [blame] | 2252 | if (taskInsertionPoint < 0) { |
| 2253 | taskInsertionPoint = task.mActivities.size(); |
Craig Mautner | d232895 | 2013-03-05 12:46:26 -0800 | [diff] [blame] | 2254 | |
Craig Mautner | 7787877 | 2013-03-04 19:46:24 -0800 | [diff] [blame] | 2255 | } |
Craig Mautner | 7787877 | 2013-03-04 19:46:24 -0800 | [diff] [blame] | 2256 | |
| 2257 | final int start = replyChainEnd >= 0 ? replyChainEnd : i; |
| 2258 | if (DEBUG_TASKS) Slog.v(TAG, "Reparenting from task=" + affinityTask + ":" |
| 2259 | + start + "-" + i + " to task=" + task + ":" + taskInsertionPoint); |
| 2260 | for (int srcPos = start; srcPos >= i; --srcPos) { |
Craig Mautner | e3a74d5 | 2013-02-22 14:14:58 -0800 | [diff] [blame] | 2261 | final ActivityRecord p = activities.get(srcPos); |
Craig Mautner | de4ef02 | 2013-04-07 19:01:33 -0700 | [diff] [blame] | 2262 | p.setTask(task, null, false); |
Craig Mautner | 7787877 | 2013-03-04 19:46:24 -0800 | [diff] [blame] | 2263 | task.addActivityAtIndex(taskInsertionPoint, p); |
Craig Mautner | e3a74d5 | 2013-02-22 14:14:58 -0800 | [diff] [blame] | 2264 | |
Craig Mautner | e3a74d5 | 2013-02-22 14:14:58 -0800 | [diff] [blame] | 2265 | if (DEBUG_ADD_REMOVE) Slog.i(TAG, "Removing and adding activity " + p |
| 2266 | + " to stack at " + task, |
| 2267 | new RuntimeException("here").fillInStackTrace()); |
| 2268 | if (DEBUG_TASKS) Slog.v(TAG, "Pulling activity " + p + " from " + srcPos |
| 2269 | + " in to resetting task " + task); |
Craig Mautner | ce5f3cb | 2013-04-22 08:58:54 -0700 | [diff] [blame] | 2270 | mWindowManager.setAppGroupId(p.appToken, taskId); |
Craig Mautner | e3a74d5 | 2013-02-22 14:14:58 -0800 | [diff] [blame] | 2271 | } |
Craig Mautner | ce5f3cb | 2013-04-22 08:58:54 -0700 | [diff] [blame] | 2272 | mWindowManager.moveTaskToTop(taskId); |
Craig Mautner | 9658b31 | 2013-02-28 10:55:59 -0800 | [diff] [blame] | 2273 | if (VALIDATE_TOKENS) { |
| 2274 | validateAppTokensLocked(); |
| 2275 | } |
Craig Mautner | e3a74d5 | 2013-02-22 14:14:58 -0800 | [diff] [blame] | 2276 | |
| 2277 | // Now we've moved it in to place... but what if this is |
| 2278 | // a singleTop activity and we have put it on top of another |
| 2279 | // instance of the same activity? Then we drop the instance |
| 2280 | // below so it remains singleTop. |
| 2281 | if (target.info.launchMode == ActivityInfo.LAUNCH_SINGLE_TOP) { |
| 2282 | ArrayList<ActivityRecord> taskActivities = task.mActivities; |
Craig Mautner | e3a74d5 | 2013-02-22 14:14:58 -0800 | [diff] [blame] | 2283 | int targetNdx = taskActivities.indexOf(target); |
| 2284 | if (targetNdx > 0) { |
| 2285 | ActivityRecord p = taskActivities.get(targetNdx - 1); |
| 2286 | if (p.intent.getComponent().equals(target.intent.getComponent())) { |
Craig Mautner | 5854780 | 2013-03-05 08:23:53 -0800 | [diff] [blame] | 2287 | finishActivityLocked(p, Activity.RESULT_CANCELED, null, "replace", |
| 2288 | false); |
Craig Mautner | e3a74d5 | 2013-02-22 14:14:58 -0800 | [diff] [blame] | 2289 | } |
| 2290 | } |
| 2291 | } |
| 2292 | } |
| 2293 | |
| 2294 | replyChainEnd = -1; |
| 2295 | } |
| 2296 | } |
Craig Mautner | 7787877 | 2013-03-04 19:46:24 -0800 | [diff] [blame] | 2297 | return taskInsertionPoint; |
Craig Mautner | e3a74d5 | 2013-02-22 14:14:58 -0800 | [diff] [blame] | 2298 | } |
| 2299 | |
Craig Mautner | 8849a5e | 2013-04-02 16:41:03 -0700 | [diff] [blame] | 2300 | final ActivityRecord resetTaskIfNeededLocked(ActivityRecord taskTop, |
Craig Mautner | e3a74d5 | 2013-02-22 14:14:58 -0800 | [diff] [blame] | 2301 | ActivityRecord newActivity) { |
| 2302 | boolean forceReset = |
| 2303 | (newActivity.info.flags & ActivityInfo.FLAG_CLEAR_TASK_ON_LAUNCH) != 0; |
| 2304 | if (ACTIVITY_INACTIVE_RESET_TIME > 0 |
| 2305 | && taskTop.task.getInactiveDuration() > ACTIVITY_INACTIVE_RESET_TIME) { |
| 2306 | if ((newActivity.info.flags & ActivityInfo.FLAG_ALWAYS_RETAIN_TASK_STATE) == 0) { |
| 2307 | forceReset = true; |
| 2308 | } |
| 2309 | } |
| 2310 | |
| 2311 | final TaskRecord task = taskTop.task; |
| 2312 | |
| 2313 | /** False until we evaluate the TaskRecord associated with taskTop. Switches to true |
| 2314 | * for remaining tasks. Used for later tasks to reparent to task. */ |
| 2315 | boolean taskFound = false; |
| 2316 | |
| 2317 | /** If ActivityOptions are moved out and need to be aborted or moved to taskTop. */ |
| 2318 | ActivityOptions topOptions = null; |
| 2319 | |
Craig Mautner | 7787877 | 2013-03-04 19:46:24 -0800 | [diff] [blame] | 2320 | // Preserve the location for reparenting in the new task. |
| 2321 | int reparentInsertionPoint = -1; |
| 2322 | |
Craig Mautner | e3a74d5 | 2013-02-22 14:14:58 -0800 | [diff] [blame] | 2323 | for (int i = mTaskHistory.size() - 1; i >= 0; --i) { |
| 2324 | final TaskRecord targetTask = mTaskHistory.get(i); |
| 2325 | |
| 2326 | if (targetTask == task) { |
| 2327 | topOptions = resetTargetTaskIfNeededLocked(task, forceReset); |
| 2328 | taskFound = true; |
| 2329 | } else { |
Craig Mautner | 7787877 | 2013-03-04 19:46:24 -0800 | [diff] [blame] | 2330 | reparentInsertionPoint = resetAffinityTaskIfNeededLocked(targetTask, task, |
| 2331 | taskFound, forceReset, reparentInsertionPoint); |
Craig Mautner | e3a74d5 | 2013-02-22 14:14:58 -0800 | [diff] [blame] | 2332 | } |
| 2333 | } |
| 2334 | |
Craig Mautner | 70a8693 | 2013-02-28 22:37:44 -0800 | [diff] [blame] | 2335 | int taskNdx = mTaskHistory.indexOf(task); |
| 2336 | do { |
| 2337 | taskTop = mTaskHistory.get(taskNdx--).getTopActivity(); |
| 2338 | } while (taskTop == null && taskNdx >= 0); |
| 2339 | |
Craig Mautner | e3a74d5 | 2013-02-22 14:14:58 -0800 | [diff] [blame] | 2340 | if (topOptions != null) { |
| 2341 | // If we got some ActivityOptions from an activity on top that |
| 2342 | // was removed from the task, propagate them to the new real top. |
| 2343 | if (taskTop != null) { |
Craig Mautner | e3a74d5 | 2013-02-22 14:14:58 -0800 | [diff] [blame] | 2344 | taskTop.updateOptionsLocked(topOptions); |
| 2345 | } else { |
Craig Mautner | e3a74d5 | 2013-02-22 14:14:58 -0800 | [diff] [blame] | 2346 | topOptions.abort(); |
| 2347 | } |
| 2348 | } |
| 2349 | |
| 2350 | return taskTop; |
| 2351 | } |
| 2352 | |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 2353 | void sendActivityResultLocked(int callingUid, ActivityRecord r, |
| 2354 | String resultWho, int requestCode, int resultCode, Intent data) { |
| 2355 | |
| 2356 | if (callingUid > 0) { |
| 2357 | mService.grantUriPermissionFromIntentLocked(callingUid, r.packageName, |
Dianne Hackborn | 7e26964 | 2010-08-25 19:50:20 -0700 | [diff] [blame] | 2358 | data, r.getUriPermissionsLocked()); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 2359 | } |
| 2360 | |
| 2361 | if (DEBUG_RESULTS) Slog.v(TAG, "Send activity result to " + r |
| 2362 | + " : who=" + resultWho + " req=" + requestCode |
| 2363 | + " res=" + resultCode + " data=" + data); |
| 2364 | if (mResumedActivity == r && r.app != null && r.app.thread != null) { |
| 2365 | try { |
| 2366 | ArrayList<ResultInfo> list = new ArrayList<ResultInfo>(); |
| 2367 | list.add(new ResultInfo(resultWho, requestCode, |
| 2368 | resultCode, data)); |
Dianne Hackborn | be70785 | 2011-11-11 14:32:10 -0800 | [diff] [blame] | 2369 | r.app.thread.scheduleSendResult(r.appToken, list); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 2370 | return; |
| 2371 | } catch (Exception e) { |
| 2372 | Slog.w(TAG, "Exception thrown sending result to " + r, e); |
| 2373 | } |
| 2374 | } |
| 2375 | |
| 2376 | r.addResultLocked(null, resultWho, requestCode, resultCode, data); |
| 2377 | } |
| 2378 | |
Craig Mautner | 04f0b70 | 2013-10-22 12:31:01 -0700 | [diff] [blame] | 2379 | private void adjustFocusedActivityLocked(ActivityRecord r) { |
| 2380 | if (mStackSupervisor.isFrontStack(this) && mService.mFocusedActivity == r) { |
| 2381 | ActivityRecord next = topRunningActivityLocked(null); |
| 2382 | if (next != r) { |
| 2383 | final TaskRecord task = r.task; |
Craig Mautner | b9a6c8a | 2014-05-29 16:50:59 +0000 | [diff] [blame] | 2384 | if (r.frontOfTask && task == topTask() && task.mOnTopOfHome) { |
| 2385 | mStackSupervisor.moveHomeToTop(); |
Craig Mautner | 04f0b70 | 2013-10-22 12:31:01 -0700 | [diff] [blame] | 2386 | } |
| 2387 | } |
Winson Chung | 648c83b | 2014-04-28 15:11:56 -0700 | [diff] [blame] | 2388 | ActivityRecord top = mStackSupervisor.topRunningActivityLocked(); |
| 2389 | if (top != null) { |
| 2390 | mService.setFocusedActivityLocked(top); |
| 2391 | } |
Craig Mautner | 04f0b70 | 2013-10-22 12:31:01 -0700 | [diff] [blame] | 2392 | } |
| 2393 | } |
| 2394 | |
Craig Mautner | f333327 | 2013-04-22 10:55:53 -0700 | [diff] [blame] | 2395 | final void stopActivityLocked(ActivityRecord r) { |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 2396 | if (DEBUG_SWITCH) Slog.d(TAG, "Stopping: " + r); |
| 2397 | if ((r.intent.getFlags()&Intent.FLAG_ACTIVITY_NO_HISTORY) != 0 |
| 2398 | || (r.info.flags&ActivityInfo.FLAG_NO_HISTORY) != 0) { |
| 2399 | if (!r.finishing) { |
Dianne Hackborn | 91097de | 2014-04-04 18:02:06 -0700 | [diff] [blame] | 2400 | if (!mService.isSleeping()) { |
Christopher Tate | d3f175c | 2012-06-14 14:16:54 -0700 | [diff] [blame] | 2401 | if (DEBUG_STATES) { |
| 2402 | Slog.d(TAG, "no-history finish of " + r); |
| 2403 | } |
| 2404 | requestFinishActivityLocked(r.appToken, Activity.RESULT_CANCELED, null, |
Dianne Hackborn | 2d1b378 | 2012-09-09 17:49:39 -0700 | [diff] [blame] | 2405 | "no-history", false); |
Christopher Tate | d3f175c | 2012-06-14 14:16:54 -0700 | [diff] [blame] | 2406 | } else { |
| 2407 | if (DEBUG_STATES) Slog.d(TAG, "Not finishing noHistory " + r |
| 2408 | + " on stop because we're just sleeping"); |
| 2409 | } |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 2410 | } |
Christopher Tate | 5007ddd | 2012-06-12 13:08:18 -0700 | [diff] [blame] | 2411 | } |
| 2412 | |
| 2413 | if (r.app != null && r.app.thread != null) { |
Craig Mautner | 04f0b70 | 2013-10-22 12:31:01 -0700 | [diff] [blame] | 2414 | adjustFocusedActivityLocked(r); |
Dianne Hackborn | 621e2fe | 2012-02-16 17:07:33 -0800 | [diff] [blame] | 2415 | r.resumeKeyDispatchingLocked(); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 2416 | try { |
| 2417 | r.stopped = false; |
Dianne Hackborn | ce86ba8 | 2011-07-13 19:33:41 -0700 | [diff] [blame] | 2418 | if (DEBUG_STATES) Slog.v(TAG, "Moving to STOPPING: " + r |
| 2419 | + " (stop requested)"); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 2420 | r.state = ActivityState.STOPPING; |
| 2421 | if (DEBUG_VISBILITY) Slog.v( |
| 2422 | TAG, "Stopping visible=" + r.visible + " for " + r); |
| 2423 | if (!r.visible) { |
Craig Mautner | ce5f3cb | 2013-04-22 08:58:54 -0700 | [diff] [blame] | 2424 | mWindowManager.setAppVisibility(r.appToken, false); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 2425 | } |
Dianne Hackborn | be70785 | 2011-11-11 14:32:10 -0800 | [diff] [blame] | 2426 | r.app.thread.scheduleStopActivity(r.appToken, r.visible, r.configChangeFlags); |
Craig Mautner | e11f2b7 | 2013-04-01 12:37:17 -0700 | [diff] [blame] | 2427 | if (mService.isSleepingOrShuttingDown()) { |
Dianne Hackborn | 4eba96b | 2011-01-21 13:34:36 -0800 | [diff] [blame] | 2428 | r.setSleeping(true); |
| 2429 | } |
Craig Mautner | f7bfefb | 2013-05-16 17:30:44 -0700 | [diff] [blame] | 2430 | Message msg = mHandler.obtainMessage(STOP_TIMEOUT_MSG, r); |
Dianne Hackborn | 162bc0e | 2012-04-09 14:06:16 -0700 | [diff] [blame] | 2431 | mHandler.sendMessageDelayed(msg, STOP_TIMEOUT); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 2432 | } catch (Exception e) { |
| 2433 | // Maybe just ignore exceptions here... if the process |
| 2434 | // has crashed, our death notification will clean things |
| 2435 | // up. |
| 2436 | Slog.w(TAG, "Exception thrown during pause", e); |
| 2437 | // Just in case, assume it to be stopped. |
| 2438 | r.stopped = true; |
Dianne Hackborn | ce86ba8 | 2011-07-13 19:33:41 -0700 | [diff] [blame] | 2439 | if (DEBUG_STATES) Slog.v(TAG, "Stop failed; moving to STOPPED: " + r); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 2440 | r.state = ActivityState.STOPPED; |
| 2441 | if (r.configDestroy) { |
Dianne Hackborn | 28695e0 | 2011-11-02 21:59:51 -0700 | [diff] [blame] | 2442 | destroyActivityLocked(r, true, false, "stop-except"); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 2443 | } |
| 2444 | } |
| 2445 | } |
| 2446 | } |
Craig Mautner | 23ac33b | 2013-04-01 16:26:35 -0700 | [diff] [blame] | 2447 | |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 2448 | /** |
| 2449 | * @return Returns true if the activity is being finished, false if for |
| 2450 | * some reason it is being left as-is. |
| 2451 | */ |
| 2452 | final boolean requestFinishActivityLocked(IBinder token, int resultCode, |
Dianne Hackborn | 2d1b378 | 2012-09-09 17:49:39 -0700 | [diff] [blame] | 2453 | Intent resultData, String reason, boolean oomAdj) { |
Craig Mautner | d74f7d7 | 2013-02-26 13:41:02 -0800 | [diff] [blame] | 2454 | ActivityRecord r = isInStackLocked(token); |
Christopher Tate | d3f175c | 2012-06-14 14:16:54 -0700 | [diff] [blame] | 2455 | if (DEBUG_RESULTS || DEBUG_STATES) Slog.v( |
Craig Mautner | d74f7d7 | 2013-02-26 13:41:02 -0800 | [diff] [blame] | 2456 | TAG, "Finishing activity token=" + token + " r=" |
Christopher Tate | d3f175c | 2012-06-14 14:16:54 -0700 | [diff] [blame] | 2457 | + ", result=" + resultCode + ", data=" + resultData |
| 2458 | + ", reason=" + reason); |
Craig Mautner | d74f7d7 | 2013-02-26 13:41:02 -0800 | [diff] [blame] | 2459 | if (r == null) { |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 2460 | return false; |
| 2461 | } |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 2462 | |
Craig Mautner | d44711d | 2013-02-23 11:24:36 -0800 | [diff] [blame] | 2463 | finishActivityLocked(r, resultCode, resultData, reason, oomAdj); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 2464 | return true; |
| 2465 | } |
| 2466 | |
Craig Mautner | d232895 | 2013-03-05 12:46:26 -0800 | [diff] [blame] | 2467 | final void finishSubActivityLocked(ActivityRecord self, String resultWho, int requestCode) { |
Craig Mautner | 9658b31 | 2013-02-28 10:55:59 -0800 | [diff] [blame] | 2468 | for (int taskNdx = mTaskHistory.size() - 1; taskNdx >= 0; --taskNdx) { |
| 2469 | ArrayList<ActivityRecord> activities = mTaskHistory.get(taskNdx).mActivities; |
| 2470 | for (int activityNdx = activities.size() - 1; activityNdx >= 0; --activityNdx) { |
| 2471 | ActivityRecord r = activities.get(activityNdx); |
| 2472 | if (r.resultTo == self && r.requestCode == requestCode) { |
| 2473 | if ((r.resultWho == null && resultWho == null) || |
| 2474 | (r.resultWho != null && r.resultWho.equals(resultWho))) { |
| 2475 | finishActivityLocked(r, Activity.RESULT_CANCELED, null, "request-sub", |
| 2476 | false); |
| 2477 | } |
Dianne Hackborn | ecc5a9c | 2012-04-26 18:56:09 -0700 | [diff] [blame] | 2478 | } |
| 2479 | } |
| 2480 | } |
Dianne Hackborn | 2d1b378 | 2012-09-09 17:49:39 -0700 | [diff] [blame] | 2481 | mService.updateOomAdjLocked(); |
Dianne Hackborn | ecc5a9c | 2012-04-26 18:56:09 -0700 | [diff] [blame] | 2482 | } |
| 2483 | |
Craig Mautner | 05d6272ba | 2013-02-11 09:39:27 -0800 | [diff] [blame] | 2484 | final void finishTopRunningActivityLocked(ProcessRecord app) { |
| 2485 | ActivityRecord r = topRunningActivityLocked(null); |
| 2486 | if (r != null && r.app == app) { |
| 2487 | // If the top running activity is from this crashing |
| 2488 | // process, then terminate it to avoid getting in a loop. |
| 2489 | Slog.w(TAG, " Force finishing activity " |
| 2490 | + r.intent.getComponent().flattenToShortString()); |
Craig Mautner | 9658b31 | 2013-02-28 10:55:59 -0800 | [diff] [blame] | 2491 | int taskNdx = mTaskHistory.indexOf(r.task); |
| 2492 | int activityNdx = r.task.mActivities.indexOf(r); |
Craig Mautner | d232895 | 2013-03-05 12:46:26 -0800 | [diff] [blame] | 2493 | finishActivityLocked(r, Activity.RESULT_CANCELED, null, "crashed", false); |
Craig Mautner | 05d6272ba | 2013-02-11 09:39:27 -0800 | [diff] [blame] | 2494 | // Also terminate any activities below it that aren't yet |
| 2495 | // stopped, to avoid a situation where one will get |
| 2496 | // re-start our crashing activity once it gets resumed again. |
Craig Mautner | 9658b31 | 2013-02-28 10:55:59 -0800 | [diff] [blame] | 2497 | --activityNdx; |
| 2498 | if (activityNdx < 0) { |
| 2499 | do { |
| 2500 | --taskNdx; |
| 2501 | if (taskNdx < 0) { |
| 2502 | break; |
| 2503 | } |
| 2504 | activityNdx = mTaskHistory.get(taskNdx).mActivities.size() - 1; |
| 2505 | } while (activityNdx < 0); |
| 2506 | } |
| 2507 | if (activityNdx >= 0) { |
| 2508 | r = mTaskHistory.get(taskNdx).mActivities.get(activityNdx); |
Craig Mautner | 05d6272ba | 2013-02-11 09:39:27 -0800 | [diff] [blame] | 2509 | if (r.state == ActivityState.RESUMED |
| 2510 | || r.state == ActivityState.PAUSING |
| 2511 | || r.state == ActivityState.PAUSED) { |
Craig Mautner | 4ef2693 | 2013-09-18 15:15:52 -0700 | [diff] [blame] | 2512 | if (!r.isHomeActivity() || mService.mHomeProcess != r.app) { |
Craig Mautner | 05d6272ba | 2013-02-11 09:39:27 -0800 | [diff] [blame] | 2513 | Slog.w(TAG, " Force finishing activity " |
| 2514 | + r.intent.getComponent().flattenToShortString()); |
Craig Mautner | d232895 | 2013-03-05 12:46:26 -0800 | [diff] [blame] | 2515 | finishActivityLocked(r, Activity.RESULT_CANCELED, null, "crashed", false); |
Craig Mautner | 05d6272ba | 2013-02-11 09:39:27 -0800 | [diff] [blame] | 2516 | } |
| 2517 | } |
| 2518 | } |
| 2519 | } |
| 2520 | } |
| 2521 | |
Craig Mautner | d232895 | 2013-03-05 12:46:26 -0800 | [diff] [blame] | 2522 | final boolean finishActivityAffinityLocked(ActivityRecord r) { |
Craig Mautner | d74f7d7 | 2013-02-26 13:41:02 -0800 | [diff] [blame] | 2523 | ArrayList<ActivityRecord> activities = r.task.mActivities; |
| 2524 | for (int index = activities.indexOf(r); index >= 0; --index) { |
| 2525 | ActivityRecord cur = activities.get(index); |
Kenny Root | e6585b3 | 2013-12-13 12:00:26 -0800 | [diff] [blame] | 2526 | if (!Objects.equals(cur.taskAffinity, r.taskAffinity)) { |
Dianne Hackborn | ecc5a9c | 2012-04-26 18:56:09 -0700 | [diff] [blame] | 2527 | break; |
| 2528 | } |
Craig Mautner | de4ef02 | 2013-04-07 19:01:33 -0700 | [diff] [blame] | 2529 | finishActivityLocked(cur, Activity.RESULT_CANCELED, null, "request-affinity", true); |
Dianne Hackborn | ecc5a9c | 2012-04-26 18:56:09 -0700 | [diff] [blame] | 2530 | } |
| 2531 | return true; |
| 2532 | } |
| 2533 | |
Dianne Hackborn | 5c60743 | 2012-02-28 14:44:19 -0800 | [diff] [blame] | 2534 | final void finishActivityResultsLocked(ActivityRecord r, int resultCode, Intent resultData) { |
| 2535 | // send the result |
| 2536 | ActivityRecord resultTo = r.resultTo; |
| 2537 | if (resultTo != null) { |
| 2538 | if (DEBUG_RESULTS) Slog.v(TAG, "Adding result to " + resultTo |
| 2539 | + " who=" + r.resultWho + " req=" + r.requestCode |
| 2540 | + " res=" + resultCode + " data=" + resultData); |
| 2541 | if (r.info.applicationInfo.uid > 0) { |
| 2542 | mService.grantUriPermissionFromIntentLocked(r.info.applicationInfo.uid, |
| 2543 | resultTo.packageName, resultData, |
| 2544 | resultTo.getUriPermissionsLocked()); |
| 2545 | } |
| 2546 | resultTo.addResultLocked(r, r.resultWho, r.requestCode, resultCode, |
| 2547 | resultData); |
| 2548 | r.resultTo = null; |
| 2549 | } |
| 2550 | else if (DEBUG_RESULTS) Slog.v(TAG, "No result destination from " + r); |
| 2551 | |
| 2552 | // Make sure this HistoryRecord is not holding on to other resources, |
| 2553 | // because clients have remote IPC references to this object so we |
| 2554 | // can't assume that will go away and want to avoid circular IPC refs. |
| 2555 | r.results = null; |
| 2556 | r.pendingResults = null; |
| 2557 | r.newIntents = null; |
| 2558 | r.icicle = null; |
| 2559 | } |
| 2560 | |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 2561 | /** |
| 2562 | * @return Returns true if this activity has been removed from the history |
| 2563 | * list, or false if it is still in the list and will be removed later. |
| 2564 | */ |
Craig Mautner | f333327 | 2013-04-22 10:55:53 -0700 | [diff] [blame] | 2565 | final boolean finishActivityLocked(ActivityRecord r, int resultCode, Intent resultData, |
| 2566 | String reason, boolean oomAdj) { |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 2567 | if (r.finishing) { |
| 2568 | Slog.w(TAG, "Duplicate finish request for " + r); |
| 2569 | return false; |
| 2570 | } |
| 2571 | |
Dianne Hackborn | 94cb2eb | 2011-01-13 21:09:44 -0800 | [diff] [blame] | 2572 | r.makeFinishing(); |
Craig Mautner | aea74a5 | 2014-03-08 14:23:10 -0800 | [diff] [blame] | 2573 | final TaskRecord task = r.task; |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 2574 | EventLog.writeEvent(EventLogTags.AM_FINISH_ACTIVITY, |
Dianne Hackborn | b12e135 | 2012-09-26 11:39:20 -0700 | [diff] [blame] | 2575 | r.userId, System.identityHashCode(r), |
Craig Mautner | aea74a5 | 2014-03-08 14:23:10 -0800 | [diff] [blame] | 2576 | task.taskId, r.shortComponentName, reason); |
| 2577 | final ArrayList<ActivityRecord> activities = task.mActivities; |
Craig Mautner | d44711d | 2013-02-23 11:24:36 -0800 | [diff] [blame] | 2578 | final int index = activities.indexOf(r); |
| 2579 | if (index < (activities.size() - 1)) { |
Craig Mautner | aea74a5 | 2014-03-08 14:23:10 -0800 | [diff] [blame] | 2580 | task.setFrontOfTask(); |
Craig Mautner | d00f474 | 2014-03-12 14:17:26 -0700 | [diff] [blame] | 2581 | if ((r.intent.getFlags() & Intent.FLAG_ACTIVITY_CLEAR_WHEN_TASK_RESET) != 0) { |
Craig Mautner | d44711d | 2013-02-23 11:24:36 -0800 | [diff] [blame] | 2582 | // If the caller asked that this activity (and all above it) |
| 2583 | // be cleared when the task is reset, don't lose that information, |
| 2584 | // but propagate it up to the next activity. |
Craig Mautner | 1aa9d0d3f | 2013-12-16 15:58:31 -0800 | [diff] [blame] | 2585 | ActivityRecord next = activities.get(index+1); |
Craig Mautner | d44711d | 2013-02-23 11:24:36 -0800 | [diff] [blame] | 2586 | next.intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_WHEN_TASK_RESET); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 2587 | } |
| 2588 | } |
| 2589 | |
| 2590 | r.pauseKeyDispatchingLocked(); |
Craig Mautner | 04f0b70 | 2013-10-22 12:31:01 -0700 | [diff] [blame] | 2591 | |
| 2592 | adjustFocusedActivityLocked(r); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 2593 | |
Dianne Hackborn | 5c60743 | 2012-02-28 14:44:19 -0800 | [diff] [blame] | 2594 | finishActivityResultsLocked(r, resultCode, resultData); |
Craig Mautner | 2420ead | 2013-04-01 17:13:20 -0700 | [diff] [blame] | 2595 | |
Craig Mautner | de4ef02 | 2013-04-07 19:01:33 -0700 | [diff] [blame] | 2596 | if (mResumedActivity == r) { |
Craig Mautner | 0247fc8 | 2013-02-28 14:32:06 -0800 | [diff] [blame] | 2597 | boolean endTask = index <= 0; |
Craig Mautner | 323f780 | 2013-10-01 21:16:22 -0700 | [diff] [blame] | 2598 | if (DEBUG_VISBILITY || DEBUG_TRANSITION) Slog.v(TAG, |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 2599 | "Prepare close transition: finishing " + r); |
Craig Mautner | ce5f3cb | 2013-04-22 08:58:54 -0700 | [diff] [blame] | 2600 | mWindowManager.prepareAppTransition(endTask |
Craig Mautner | 4b71aa1 | 2012-12-27 17:20:01 -0800 | [diff] [blame] | 2601 | ? AppTransition.TRANSIT_TASK_CLOSE |
| 2602 | : AppTransition.TRANSIT_ACTIVITY_CLOSE, false); |
Craig Mautner | 0247fc8 | 2013-02-28 14:32:06 -0800 | [diff] [blame] | 2603 | |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 2604 | // Tell window manager to prepare for this one to be removed. |
Craig Mautner | ce5f3cb | 2013-04-22 08:58:54 -0700 | [diff] [blame] | 2605 | mWindowManager.setAppVisibility(r.appToken, false); |
Craig Mautner | dbcb31f | 2013-04-02 12:32:53 -0700 | [diff] [blame] | 2606 | |
Dianne Hackborn | 621e2fe | 2012-02-16 17:07:33 -0800 | [diff] [blame] | 2607 | if (mPausingActivity == null) { |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 2608 | if (DEBUG_PAUSE) Slog.v(TAG, "Finish needs to pause: " + r); |
| 2609 | if (DEBUG_USER_LEAVING) Slog.v(TAG, "finish() => pause with userLeaving=false"); |
| 2610 | startPausingLocked(false, false); |
| 2611 | } |
| 2612 | |
Craig Mautner | aea74a5 | 2014-03-08 14:23:10 -0800 | [diff] [blame] | 2613 | if (endTask) { |
| 2614 | mStackSupervisor.endLockTaskModeIfTaskEnding(task); |
| 2615 | } |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 2616 | } else if (r.state != ActivityState.PAUSING) { |
| 2617 | // If the activity is PAUSING, we will complete the finish once |
| 2618 | // it is done pausing; else we can just directly finish it here. |
| 2619 | if (DEBUG_PAUSE) Slog.v(TAG, "Finish not pausing: " + r); |
Craig Mautner | d44711d | 2013-02-23 11:24:36 -0800 | [diff] [blame] | 2620 | return finishCurrentActivityLocked(r, FINISH_AFTER_PAUSE, oomAdj) == null; |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 2621 | } else { |
| 2622 | if (DEBUG_PAUSE) Slog.v(TAG, "Finish waiting for pause of: " + r); |
| 2623 | } |
| 2624 | |
| 2625 | return false; |
| 2626 | } |
| 2627 | |
Craig Mautner | f333327 | 2013-04-22 10:55:53 -0700 | [diff] [blame] | 2628 | static final int FINISH_IMMEDIATELY = 0; |
| 2629 | static final int FINISH_AFTER_PAUSE = 1; |
| 2630 | static final int FINISH_AFTER_VISIBLE = 2; |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 2631 | |
Craig Mautner | f333327 | 2013-04-22 10:55:53 -0700 | [diff] [blame] | 2632 | final ActivityRecord finishCurrentActivityLocked(ActivityRecord r, int mode, boolean oomAdj) { |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 2633 | // First things first: if this activity is currently visible, |
| 2634 | // and the resumed activity is not yet visible, then hold off on |
| 2635 | // finishing until the resumed one becomes visible. |
| 2636 | if (mode == FINISH_AFTER_VISIBLE && r.nowVisible) { |
Craig Mautner | de4ef02 | 2013-04-07 19:01:33 -0700 | [diff] [blame] | 2637 | if (!mStackSupervisor.mStoppingActivities.contains(r)) { |
| 2638 | mStackSupervisor.mStoppingActivities.add(r); |
Craig Mautner | 29219d9 | 2013-04-16 20:19:12 -0700 | [diff] [blame] | 2639 | if (mStackSupervisor.mStoppingActivities.size() > 3 |
| 2640 | || r.frontOfTask && mTaskHistory.size() <= 1) { |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 2641 | // If we already have a few activities waiting to stop, |
| 2642 | // then give up on things going idle and start clearing |
Craig Mautner | 29219d9 | 2013-04-16 20:19:12 -0700 | [diff] [blame] | 2643 | // them out. Or if r is the last of activity of the last task the stack |
| 2644 | // will be empty and must be cleared immediately. |
Craig Mautner | f333327 | 2013-04-22 10:55:53 -0700 | [diff] [blame] | 2645 | mStackSupervisor.scheduleIdleLocked(); |
Dianne Hackborn | 4eba96b | 2011-01-21 13:34:36 -0800 | [diff] [blame] | 2646 | } else { |
Craig Mautner | 0eea92c | 2013-05-16 13:35:39 -0700 | [diff] [blame] | 2647 | mStackSupervisor.checkReadyForSleepLocked(); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 2648 | } |
| 2649 | } |
Dianne Hackborn | ce86ba8 | 2011-07-13 19:33:41 -0700 | [diff] [blame] | 2650 | if (DEBUG_STATES) Slog.v(TAG, "Moving to STOPPING: " + r |
| 2651 | + " (finish requested)"); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 2652 | r.state = ActivityState.STOPPING; |
Dianne Hackborn | 2d1b378 | 2012-09-09 17:49:39 -0700 | [diff] [blame] | 2653 | if (oomAdj) { |
| 2654 | mService.updateOomAdjLocked(); |
| 2655 | } |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 2656 | return r; |
| 2657 | } |
| 2658 | |
| 2659 | // make sure the record is cleaned out of other places. |
Craig Mautner | de4ef02 | 2013-04-07 19:01:33 -0700 | [diff] [blame] | 2660 | mStackSupervisor.mStoppingActivities.remove(r); |
Craig Mautner | 0eea92c | 2013-05-16 13:35:39 -0700 | [diff] [blame] | 2661 | mStackSupervisor.mGoingToSleepActivities.remove(r); |
Craig Mautner | de4ef02 | 2013-04-07 19:01:33 -0700 | [diff] [blame] | 2662 | mStackSupervisor.mWaitingVisibleActivities.remove(r); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 2663 | if (mResumedActivity == r) { |
| 2664 | mResumedActivity = null; |
| 2665 | } |
| 2666 | final ActivityState prevState = r.state; |
Dianne Hackborn | ce86ba8 | 2011-07-13 19:33:41 -0700 | [diff] [blame] | 2667 | if (DEBUG_STATES) Slog.v(TAG, "Moving to FINISHING: " + r); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 2668 | r.state = ActivityState.FINISHING; |
| 2669 | |
| 2670 | if (mode == FINISH_IMMEDIATELY |
| 2671 | || prevState == ActivityState.STOPPED |
| 2672 | || prevState == ActivityState.INITIALIZING) { |
| 2673 | // If this activity is already stopped, we can just finish |
| 2674 | // it right now. |
Dianne Hackborn | 2d1b378 | 2012-09-09 17:49:39 -0700 | [diff] [blame] | 2675 | boolean activityRemoved = destroyActivityLocked(r, true, |
| 2676 | oomAdj, "finish-imm"); |
Dianne Hackborn | 42e620c | 2012-06-24 13:20:51 -0700 | [diff] [blame] | 2677 | if (activityRemoved) { |
Craig Mautner | 05d2903 | 2013-05-03 13:40:13 -0700 | [diff] [blame] | 2678 | mStackSupervisor.resumeTopActivitiesLocked(); |
Dianne Hackborn | 42e620c | 2012-06-24 13:20:51 -0700 | [diff] [blame] | 2679 | } |
| 2680 | return activityRemoved ? null : r; |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 2681 | } |
Craig Mautner | 05d6272ba | 2013-02-11 09:39:27 -0800 | [diff] [blame] | 2682 | |
| 2683 | // Need to go through the full pause cycle to get this |
| 2684 | // activity into the stopped state and then finish it. |
| 2685 | if (localLOGV) Slog.v(TAG, "Enqueueing pending finish: " + r); |
Craig Mautner | f333327 | 2013-04-22 10:55:53 -0700 | [diff] [blame] | 2686 | mStackSupervisor.mFinishingActivities.add(r); |
Martin Wallgren | c8733b8 | 2011-08-31 12:39:31 +0200 | [diff] [blame] | 2687 | r.resumeKeyDispatchingLocked(); |
Craig Mautner | ce5f3cb | 2013-04-22 08:58:54 -0700 | [diff] [blame] | 2688 | mStackSupervisor.getFocusedStack().resumeTopActivityLocked(null); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 2689 | return r; |
| 2690 | } |
| 2691 | |
Craig Mautner | f4c909b | 2014-04-17 18:39:38 -0700 | [diff] [blame] | 2692 | void finishAllActivitiesLocked() { |
| 2693 | for (int taskNdx = mTaskHistory.size() - 1; taskNdx >= 0; --taskNdx) { |
| 2694 | final ArrayList<ActivityRecord> activities = mTaskHistory.get(taskNdx).mActivities; |
| 2695 | for (int activityNdx = activities.size() - 1; activityNdx >= 0; --activityNdx) { |
| 2696 | final ActivityRecord r = activities.get(activityNdx); |
| 2697 | if (r.finishing) { |
| 2698 | continue; |
| 2699 | } |
| 2700 | Slog.d(TAG, "finishAllActivitiesLocked: finishing " + r); |
| 2701 | finishCurrentActivityLocked(r, FINISH_IMMEDIATELY, false); |
| 2702 | } |
| 2703 | } |
| 2704 | } |
| 2705 | |
Craig Mautner | d232895 | 2013-03-05 12:46:26 -0800 | [diff] [blame] | 2706 | final boolean navigateUpToLocked(IBinder token, Intent destIntent, int resultCode, |
Craig Mautner | 05d6272ba | 2013-02-11 09:39:27 -0800 | [diff] [blame] | 2707 | Intent resultData) { |
Craig Mautner | d232895 | 2013-03-05 12:46:26 -0800 | [diff] [blame] | 2708 | final ActivityRecord srec = ActivityRecord.forToken(token); |
Craig Mautner | 0247fc8 | 2013-02-28 14:32:06 -0800 | [diff] [blame] | 2709 | final TaskRecord task = srec.task; |
| 2710 | final ArrayList<ActivityRecord> activities = task.mActivities; |
| 2711 | final int start = activities.indexOf(srec); |
| 2712 | if (!mTaskHistory.contains(task) || (start < 0)) { |
Craig Mautner | 05d6272ba | 2013-02-11 09:39:27 -0800 | [diff] [blame] | 2713 | return false; |
| 2714 | } |
| 2715 | int finishTo = start - 1; |
Craig Mautner | 0247fc8 | 2013-02-28 14:32:06 -0800 | [diff] [blame] | 2716 | ActivityRecord parent = finishTo < 0 ? null : activities.get(finishTo); |
Craig Mautner | 05d6272ba | 2013-02-11 09:39:27 -0800 | [diff] [blame] | 2717 | boolean foundParentInTask = false; |
Craig Mautner | 0247fc8 | 2013-02-28 14:32:06 -0800 | [diff] [blame] | 2718 | final ComponentName dest = destIntent.getComponent(); |
| 2719 | if (start > 0 && dest != null) { |
| 2720 | for (int i = finishTo; i >= 0; i--) { |
| 2721 | ActivityRecord r = activities.get(i); |
| 2722 | if (r.info.packageName.equals(dest.getPackageName()) && |
Craig Mautner | 05d6272ba | 2013-02-11 09:39:27 -0800 | [diff] [blame] | 2723 | r.info.name.equals(dest.getClassName())) { |
| 2724 | finishTo = i; |
| 2725 | parent = r; |
| 2726 | foundParentInTask = true; |
| 2727 | break; |
| 2728 | } |
| 2729 | } |
| 2730 | } |
| 2731 | |
| 2732 | IActivityController controller = mService.mController; |
| 2733 | if (controller != null) { |
| 2734 | ActivityRecord next = topRunningActivityLocked(srec.appToken, 0); |
| 2735 | if (next != null) { |
| 2736 | // ask watcher if this is allowed |
| 2737 | boolean resumeOK = true; |
| 2738 | try { |
| 2739 | resumeOK = controller.activityResuming(next.packageName); |
| 2740 | } catch (RemoteException e) { |
| 2741 | mService.mController = null; |
Kenny Root | add5821 | 2013-05-07 09:47:34 -0700 | [diff] [blame] | 2742 | Watchdog.getInstance().setActivityController(null); |
Craig Mautner | 05d6272ba | 2013-02-11 09:39:27 -0800 | [diff] [blame] | 2743 | } |
| 2744 | |
| 2745 | if (!resumeOK) { |
| 2746 | return false; |
| 2747 | } |
| 2748 | } |
| 2749 | } |
| 2750 | final long origId = Binder.clearCallingIdentity(); |
| 2751 | for (int i = start; i > finishTo; i--) { |
Craig Mautner | 0247fc8 | 2013-02-28 14:32:06 -0800 | [diff] [blame] | 2752 | ActivityRecord r = activities.get(i); |
| 2753 | requestFinishActivityLocked(r.appToken, resultCode, resultData, "navigate-up", true); |
Craig Mautner | 05d6272ba | 2013-02-11 09:39:27 -0800 | [diff] [blame] | 2754 | // Only return the supplied result for the first activity finished |
| 2755 | resultCode = Activity.RESULT_CANCELED; |
| 2756 | resultData = null; |
| 2757 | } |
| 2758 | |
| 2759 | if (parent != null && foundParentInTask) { |
| 2760 | final int parentLaunchMode = parent.info.launchMode; |
| 2761 | final int destIntentFlags = destIntent.getFlags(); |
| 2762 | if (parentLaunchMode == ActivityInfo.LAUNCH_SINGLE_INSTANCE || |
| 2763 | parentLaunchMode == ActivityInfo.LAUNCH_SINGLE_TASK || |
| 2764 | parentLaunchMode == ActivityInfo.LAUNCH_SINGLE_TOP || |
| 2765 | (destIntentFlags & Intent.FLAG_ACTIVITY_CLEAR_TOP) != 0) { |
| 2766 | parent.deliverNewIntentLocked(srec.info.applicationInfo.uid, destIntent); |
| 2767 | } else { |
| 2768 | try { |
| 2769 | ActivityInfo aInfo = AppGlobals.getPackageManager().getActivityInfo( |
| 2770 | destIntent.getComponent(), 0, srec.userId); |
Craig Mautner | 6170f73 | 2013-04-02 13:05:23 -0700 | [diff] [blame] | 2771 | int res = mStackSupervisor.startActivityLocked(srec.app.thread, destIntent, |
Dianne Hackborn | 91097de | 2014-04-04 18:02:06 -0700 | [diff] [blame] | 2772 | null, aInfo, null, null, parent.appToken, null, |
Craig Mautner | 05d6272ba | 2013-02-11 09:39:27 -0800 | [diff] [blame] | 2773 | 0, -1, parent.launchedFromUid, parent.launchedFromPackage, |
Craig Mautner | e0a3884 | 2013-12-16 16:14:02 -0800 | [diff] [blame] | 2774 | 0, null, true, null, null); |
Craig Mautner | 05d6272ba | 2013-02-11 09:39:27 -0800 | [diff] [blame] | 2775 | foundParentInTask = res == ActivityManager.START_SUCCESS; |
| 2776 | } catch (RemoteException e) { |
| 2777 | foundParentInTask = false; |
| 2778 | } |
| 2779 | requestFinishActivityLocked(parent.appToken, resultCode, |
| 2780 | resultData, "navigate-up", true); |
| 2781 | } |
| 2782 | } |
| 2783 | Binder.restoreCallingIdentity(origId); |
| 2784 | return foundParentInTask; |
| 2785 | } |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 2786 | /** |
| 2787 | * Perform the common clean-up of an activity record. This is called both |
| 2788 | * as part of destroyActivityLocked() (when destroying the client-side |
| 2789 | * representation) and cleaning things up as a result of its hosting |
| 2790 | * processing going away, in which case there is no remaining client-side |
| 2791 | * state to destroy so only the cleanup here is needed. |
| 2792 | */ |
Dianne Hackborn | ce86ba8 | 2011-07-13 19:33:41 -0700 | [diff] [blame] | 2793 | final void cleanUpActivityLocked(ActivityRecord r, boolean cleanServices, |
| 2794 | boolean setState) { |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 2795 | if (mResumedActivity == r) { |
| 2796 | mResumedActivity = null; |
| 2797 | } |
Craig Mautner | 1872ce3 | 2014-03-28 23:05:42 +0000 | [diff] [blame] | 2798 | if (mPausingActivity == r) { |
| 2799 | mPausingActivity = null; |
| 2800 | } |
Dianne Hackborn | 91097de | 2014-04-04 18:02:06 -0700 | [diff] [blame] | 2801 | mService.clearFocusedActivity(r); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 2802 | |
| 2803 | r.configDestroy = false; |
| 2804 | r.frozenBeforeDestroy = false; |
| 2805 | |
Dianne Hackborn | ce86ba8 | 2011-07-13 19:33:41 -0700 | [diff] [blame] | 2806 | if (setState) { |
| 2807 | if (DEBUG_STATES) Slog.v(TAG, "Moving to DESTROYED: " + r + " (cleaning up)"); |
| 2808 | r.state = ActivityState.DESTROYED; |
Dianne Hackborn | 0798149 | 2013-01-28 11:36:23 -0800 | [diff] [blame] | 2809 | if (DEBUG_APP) Slog.v(TAG, "Clearing app during cleanUp for activity " + r); |
Dianne Hackborn | cc5a055 | 2012-10-01 16:32:39 -0700 | [diff] [blame] | 2810 | r.app = null; |
Dianne Hackborn | ce86ba8 | 2011-07-13 19:33:41 -0700 | [diff] [blame] | 2811 | } |
| 2812 | |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 2813 | // Make sure this record is no longer in the pending finishes list. |
| 2814 | // This could happen, for example, if we are trimming activities |
| 2815 | // down to the max limit while they are still waiting to finish. |
Craig Mautner | f333327 | 2013-04-22 10:55:53 -0700 | [diff] [blame] | 2816 | mStackSupervisor.mFinishingActivities.remove(r); |
Craig Mautner | de4ef02 | 2013-04-07 19:01:33 -0700 | [diff] [blame] | 2817 | mStackSupervisor.mWaitingVisibleActivities.remove(r); |
Craig Mautner | 2420ead | 2013-04-01 17:13:20 -0700 | [diff] [blame] | 2818 | |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 2819 | // Remove any pending results. |
| 2820 | if (r.finishing && r.pendingResults != null) { |
| 2821 | for (WeakReference<PendingIntentRecord> apr : r.pendingResults) { |
| 2822 | PendingIntentRecord rec = apr.get(); |
| 2823 | if (rec != null) { |
| 2824 | mService.cancelIntentSenderLocked(rec, false); |
| 2825 | } |
| 2826 | } |
| 2827 | r.pendingResults = null; |
| 2828 | } |
| 2829 | |
| 2830 | if (cleanServices) { |
Craig Mautner | 2420ead | 2013-04-01 17:13:20 -0700 | [diff] [blame] | 2831 | cleanUpActivityServicesLocked(r); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 2832 | } |
| 2833 | |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 2834 | // Get rid of any pending idle timeouts. |
Dianne Hackborn | 42e620c | 2012-06-24 13:20:51 -0700 | [diff] [blame] | 2835 | removeTimeoutsForActivityLocked(r); |
| 2836 | } |
| 2837 | |
| 2838 | private void removeTimeoutsForActivityLocked(ActivityRecord r) { |
Craig Mautner | f333327 | 2013-04-22 10:55:53 -0700 | [diff] [blame] | 2839 | mStackSupervisor.removeTimeoutsForActivityLocked(r); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 2840 | mHandler.removeMessages(PAUSE_TIMEOUT_MSG, r); |
Dianne Hackborn | 162bc0e | 2012-04-09 14:06:16 -0700 | [diff] [blame] | 2841 | mHandler.removeMessages(STOP_TIMEOUT_MSG, r); |
Dianne Hackborn | 0c5001d | 2011-04-12 18:16:08 -0700 | [diff] [blame] | 2842 | mHandler.removeMessages(DESTROY_TIMEOUT_MSG, r); |
Dianne Hackborn | 2a29b3a | 2012-03-15 15:48:38 -0700 | [diff] [blame] | 2843 | r.finishLaunchTickingLocked(); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 2844 | } |
| 2845 | |
Craig Mautner | 04a0ea6 | 2014-01-13 12:51:26 -0800 | [diff] [blame] | 2846 | private void removeActivityFromHistoryLocked(ActivityRecord r) { |
Craig Mautner | 34b73df | 2014-01-12 21:11:08 -0800 | [diff] [blame] | 2847 | mStackSupervisor.removeChildActivityContainers(r); |
Dianne Hackborn | cc5a055 | 2012-10-01 16:32:39 -0700 | [diff] [blame] | 2848 | finishActivityResultsLocked(r, Activity.RESULT_CANCELED, null); |
| 2849 | r.makeFinishing(); |
| 2850 | if (DEBUG_ADD_REMOVE) { |
| 2851 | RuntimeException here = new RuntimeException("here"); |
| 2852 | here.fillInStackTrace(); |
| 2853 | Slog.i(TAG, "Removing activity " + r + " from stack"); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 2854 | } |
Dianne Hackborn | cc5a055 | 2012-10-01 16:32:39 -0700 | [diff] [blame] | 2855 | r.takeFromHistory(); |
| 2856 | removeTimeoutsForActivityLocked(r); |
Craig Mautner | 0247fc8 | 2013-02-28 14:32:06 -0800 | [diff] [blame] | 2857 | if (DEBUG_STATES) Slog.v(TAG, "Moving to DESTROYED: " + r + " (removed from history)"); |
Dianne Hackborn | cc5a055 | 2012-10-01 16:32:39 -0700 | [diff] [blame] | 2858 | r.state = ActivityState.DESTROYED; |
Dianne Hackborn | 0798149 | 2013-01-28 11:36:23 -0800 | [diff] [blame] | 2859 | if (DEBUG_APP) Slog.v(TAG, "Clearing app during remove for activity " + r); |
Dianne Hackborn | cc5a055 | 2012-10-01 16:32:39 -0700 | [diff] [blame] | 2860 | r.app = null; |
Craig Mautner | ce5f3cb | 2013-04-22 08:58:54 -0700 | [diff] [blame] | 2861 | mWindowManager.removeAppToken(r.appToken); |
Dianne Hackborn | cc5a055 | 2012-10-01 16:32:39 -0700 | [diff] [blame] | 2862 | if (VALIDATE_TOKENS) { |
| 2863 | validateAppTokensLocked(); |
| 2864 | } |
Craig Mautner | 312ba86 | 2014-02-10 17:55:01 -0800 | [diff] [blame] | 2865 | final TaskRecord task = r.task; |
| 2866 | if (task != null && task.removeActivity(r)) { |
| 2867 | if (DEBUG_STACK) Slog.i(TAG, |
| 2868 | "removeActivityFromHistoryLocked: last activity removed from " + this); |
Craig Mautner | b9a6c8a | 2014-05-29 16:50:59 +0000 | [diff] [blame] | 2869 | if (mStackSupervisor.isFrontStack(this) && task == topTask() && task.mOnTopOfHome) { |
| 2870 | mStackSupervisor.moveHomeToTop(); |
Craig Mautner | 312ba86 | 2014-02-10 17:55:01 -0800 | [diff] [blame] | 2871 | } |
Craig Mautner | 41db4a7 | 2014-05-07 17:20:56 -0700 | [diff] [blame] | 2872 | removeTask(task); |
Craig Mautner | 312ba86 | 2014-02-10 17:55:01 -0800 | [diff] [blame] | 2873 | } |
Dianne Hackborn | cc5a055 | 2012-10-01 16:32:39 -0700 | [diff] [blame] | 2874 | cleanUpActivityServicesLocked(r); |
| 2875 | r.removeUriPermissionsLocked(); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 2876 | } |
Craig Mautner | dbcb31f | 2013-04-02 12:32:53 -0700 | [diff] [blame] | 2877 | |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 2878 | /** |
| 2879 | * Perform clean-up of service connections in an activity record. |
| 2880 | */ |
| 2881 | final void cleanUpActivityServicesLocked(ActivityRecord r) { |
| 2882 | // Throw away any services that have been bound by this activity. |
| 2883 | if (r.connections != null) { |
| 2884 | Iterator<ConnectionRecord> it = r.connections.iterator(); |
| 2885 | while (it.hasNext()) { |
| 2886 | ConnectionRecord c = it.next(); |
Dianne Hackborn | 599db5c | 2012-08-03 19:28:48 -0700 | [diff] [blame] | 2887 | mService.mServices.removeConnectionLocked(c, null, r); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 2888 | } |
| 2889 | r.connections = null; |
| 2890 | } |
| 2891 | } |
Dianne Hackborn | 755c8bf | 2012-05-07 15:06:09 -0700 | [diff] [blame] | 2892 | |
| 2893 | final void scheduleDestroyActivities(ProcessRecord owner, boolean oomAdj, String reason) { |
| 2894 | Message msg = mHandler.obtainMessage(DESTROY_ACTIVITIES_MSG); |
| 2895 | msg.obj = new ScheduleDestroyArgs(owner, oomAdj, reason); |
| 2896 | mHandler.sendMessage(msg); |
| 2897 | } |
| 2898 | |
Dianne Hackborn | 28695e0 | 2011-11-02 21:59:51 -0700 | [diff] [blame] | 2899 | final void destroyActivitiesLocked(ProcessRecord owner, boolean oomAdj, String reason) { |
Dianne Hackborn | 755c8bf | 2012-05-07 15:06:09 -0700 | [diff] [blame] | 2900 | boolean lastIsOpaque = false; |
Dianne Hackborn | 42e620c | 2012-06-24 13:20:51 -0700 | [diff] [blame] | 2901 | boolean activityRemoved = false; |
Craig Mautner | d44711d | 2013-02-23 11:24:36 -0800 | [diff] [blame] | 2902 | for (int taskNdx = mTaskHistory.size() - 1; taskNdx >= 0; --taskNdx) { |
| 2903 | final ArrayList<ActivityRecord> activities = mTaskHistory.get(taskNdx).mActivities; |
| 2904 | for (int activityNdx = activities.size() - 1; activityNdx >= 0; --activityNdx) { |
| 2905 | final ActivityRecord r = activities.get(activityNdx); |
| 2906 | if (r.finishing) { |
| 2907 | continue; |
| 2908 | } |
| 2909 | if (r.fullscreen) { |
| 2910 | lastIsOpaque = true; |
| 2911 | } |
| 2912 | if (owner != null && r.app != owner) { |
| 2913 | continue; |
| 2914 | } |
| 2915 | if (!lastIsOpaque) { |
| 2916 | continue; |
| 2917 | } |
| 2918 | // We can destroy this one if we have its icicle saved and |
| 2919 | // it is not in the process of pausing/stopping/finishing. |
| 2920 | if (r.app != null && r != mResumedActivity && r != mPausingActivity |
| 2921 | && r.haveState && !r.visible && r.stopped |
| 2922 | && r.state != ActivityState.DESTROYING |
| 2923 | && r.state != ActivityState.DESTROYED) { |
| 2924 | if (DEBUG_SWITCH) Slog.v(TAG, "Destroying " + r + " in state " + r.state |
| 2925 | + " resumed=" + mResumedActivity |
| 2926 | + " pausing=" + mPausingActivity); |
| 2927 | if (destroyActivityLocked(r, true, oomAdj, reason)) { |
| 2928 | activityRemoved = true; |
| 2929 | } |
Dianne Hackborn | 42e620c | 2012-06-24 13:20:51 -0700 | [diff] [blame] | 2930 | } |
Dianne Hackborn | ce86ba8 | 2011-07-13 19:33:41 -0700 | [diff] [blame] | 2931 | } |
| 2932 | } |
Dianne Hackborn | 42e620c | 2012-06-24 13:20:51 -0700 | [diff] [blame] | 2933 | if (activityRemoved) { |
Craig Mautner | 05d2903 | 2013-05-03 13:40:13 -0700 | [diff] [blame] | 2934 | mStackSupervisor.resumeTopActivitiesLocked(); |
Dianne Hackborn | 42e620c | 2012-06-24 13:20:51 -0700 | [diff] [blame] | 2935 | } |
Dianne Hackborn | ce86ba8 | 2011-07-13 19:33:41 -0700 | [diff] [blame] | 2936 | } |
| 2937 | |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 2938 | /** |
| 2939 | * Destroy the current CLIENT SIDE instance of an activity. This may be |
| 2940 | * called both when actually finishing an activity, or when performing |
| 2941 | * a configuration switch where we destroy the current client-side object |
| 2942 | * but then create a new client-side object for this same HistoryRecord. |
| 2943 | */ |
| 2944 | final boolean destroyActivityLocked(ActivityRecord r, |
Dianne Hackborn | 28695e0 | 2011-11-02 21:59:51 -0700 | [diff] [blame] | 2945 | boolean removeFromApp, boolean oomAdj, String reason) { |
Dianne Hackborn | cc5a055 | 2012-10-01 16:32:39 -0700 | [diff] [blame] | 2946 | if (DEBUG_SWITCH || DEBUG_CLEANUP) Slog.v( |
Dianne Hackborn | 755c8bf | 2012-05-07 15:06:09 -0700 | [diff] [blame] | 2947 | TAG, "Removing activity from " + reason + ": token=" + r |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 2948 | + ", app=" + (r.app != null ? r.app.processName : "(null)")); |
| 2949 | EventLog.writeEvent(EventLogTags.AM_DESTROY_ACTIVITY, |
Dianne Hackborn | b12e135 | 2012-09-26 11:39:20 -0700 | [diff] [blame] | 2950 | r.userId, System.identityHashCode(r), |
Dianne Hackborn | 28695e0 | 2011-11-02 21:59:51 -0700 | [diff] [blame] | 2951 | r.task.taskId, r.shortComponentName, reason); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 2952 | |
| 2953 | boolean removedFromHistory = false; |
Dianne Hackborn | cc5a055 | 2012-10-01 16:32:39 -0700 | [diff] [blame] | 2954 | |
Dianne Hackborn | ce86ba8 | 2011-07-13 19:33:41 -0700 | [diff] [blame] | 2955 | cleanUpActivityLocked(r, false, false); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 2956 | |
| 2957 | final boolean hadApp = r.app != null; |
Dianne Hackborn | cc5a055 | 2012-10-01 16:32:39 -0700 | [diff] [blame] | 2958 | |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 2959 | if (hadApp) { |
| 2960 | if (removeFromApp) { |
Craig Mautner | d232895 | 2013-03-05 12:46:26 -0800 | [diff] [blame] | 2961 | r.app.activities.remove(r); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 2962 | if (mService.mHeavyWeightProcess == r.app && r.app.activities.size() <= 0) { |
| 2963 | mService.mHeavyWeightProcess = null; |
| 2964 | mService.mHandler.sendEmptyMessage( |
| 2965 | ActivityManagerService.CANCEL_HEAVY_NOTIFICATION_MSG); |
| 2966 | } |
Craig Mautner | c8143c6 | 2013-09-03 12:15:57 -0700 | [diff] [blame] | 2967 | if (r.app.activities.isEmpty()) { |
Dianne Hackborn | 3bc8f78d | 2013-09-19 13:34:35 -0700 | [diff] [blame] | 2968 | // No longer have activities, so update LRU list and oom adj. |
Dianne Hackborn | db92608 | 2013-10-31 16:32:44 -0700 | [diff] [blame] | 2969 | mService.updateLruProcessLocked(r.app, false, null); |
Dianne Hackborn | 2d1b378 | 2012-09-09 17:49:39 -0700 | [diff] [blame] | 2970 | mService.updateOomAdjLocked(); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 2971 | } |
| 2972 | } |
| 2973 | |
| 2974 | boolean skipDestroy = false; |
Craig Mautner | dbcb31f | 2013-04-02 12:32:53 -0700 | [diff] [blame] | 2975 | |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 2976 | try { |
| 2977 | if (DEBUG_SWITCH) Slog.i(TAG, "Destroying: " + r); |
Dianne Hackborn | be70785 | 2011-11-11 14:32:10 -0800 | [diff] [blame] | 2978 | r.app.thread.scheduleDestroyActivity(r.appToken, r.finishing, |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 2979 | r.configChangeFlags); |
| 2980 | } catch (Exception e) { |
| 2981 | // We can just ignore exceptions here... if the process |
| 2982 | // has crashed, our death notification will clean things |
| 2983 | // up. |
| 2984 | //Slog.w(TAG, "Exception thrown during finish", e); |
| 2985 | if (r.finishing) { |
| 2986 | removeActivityFromHistoryLocked(r); |
| 2987 | removedFromHistory = true; |
| 2988 | skipDestroy = true; |
| 2989 | } |
| 2990 | } |
| 2991 | |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 2992 | r.nowVisible = false; |
Craig Mautner | dbcb31f | 2013-04-02 12:32:53 -0700 | [diff] [blame] | 2993 | |
Dianne Hackborn | ce86ba8 | 2011-07-13 19:33:41 -0700 | [diff] [blame] | 2994 | // If the activity is finishing, we need to wait on removing it |
| 2995 | // from the list to give it a chance to do its cleanup. During |
| 2996 | // that time it may make calls back with its token so we need to |
| 2997 | // be able to find it on the list and so we don't want to remove |
| 2998 | // it from the list yet. Otherwise, we can just immediately put |
| 2999 | // it in the destroyed state since we are not removing it from the |
| 3000 | // list. |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 3001 | if (r.finishing && !skipDestroy) { |
Dianne Hackborn | ce86ba8 | 2011-07-13 19:33:41 -0700 | [diff] [blame] | 3002 | if (DEBUG_STATES) Slog.v(TAG, "Moving to DESTROYING: " + r |
| 3003 | + " (destroy requested)"); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 3004 | r.state = ActivityState.DESTROYING; |
Craig Mautner | f7bfefb | 2013-05-16 17:30:44 -0700 | [diff] [blame] | 3005 | Message msg = mHandler.obtainMessage(DESTROY_TIMEOUT_MSG, r); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 3006 | mHandler.sendMessageDelayed(msg, DESTROY_TIMEOUT); |
| 3007 | } else { |
Craig Mautner | f7bfefb | 2013-05-16 17:30:44 -0700 | [diff] [blame] | 3008 | if (DEBUG_STATES) Slog.v(TAG, "Moving to DESTROYED: " + r + " (destroy skipped)"); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 3009 | r.state = ActivityState.DESTROYED; |
Dianne Hackborn | 0798149 | 2013-01-28 11:36:23 -0800 | [diff] [blame] | 3010 | if (DEBUG_APP) Slog.v(TAG, "Clearing app during destroy for activity " + r); |
Dianne Hackborn | cc5a055 | 2012-10-01 16:32:39 -0700 | [diff] [blame] | 3011 | r.app = null; |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 3012 | } |
| 3013 | } else { |
| 3014 | // remove this record from the history. |
| 3015 | if (r.finishing) { |
| 3016 | removeActivityFromHistoryLocked(r); |
| 3017 | removedFromHistory = true; |
| 3018 | } else { |
Craig Mautner | f7bfefb | 2013-05-16 17:30:44 -0700 | [diff] [blame] | 3019 | if (DEBUG_STATES) Slog.v(TAG, "Moving to DESTROYED: " + r + " (no app)"); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 3020 | r.state = ActivityState.DESTROYED; |
Dianne Hackborn | 0798149 | 2013-01-28 11:36:23 -0800 | [diff] [blame] | 3021 | if (DEBUG_APP) Slog.v(TAG, "Clearing app during destroy for activity " + r); |
Dianne Hackborn | cc5a055 | 2012-10-01 16:32:39 -0700 | [diff] [blame] | 3022 | r.app = null; |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 3023 | } |
| 3024 | } |
| 3025 | |
| 3026 | r.configChangeFlags = 0; |
Craig Mautner | dbcb31f | 2013-04-02 12:32:53 -0700 | [diff] [blame] | 3027 | |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 3028 | if (!mLRUActivities.remove(r) && hadApp) { |
| 3029 | Slog.w(TAG, "Activity " + r + " being finished, but not in LRU list"); |
| 3030 | } |
Craig Mautner | dbcb31f | 2013-04-02 12:32:53 -0700 | [diff] [blame] | 3031 | |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 3032 | return removedFromHistory; |
| 3033 | } |
| 3034 | |
Craig Mautner | d232895 | 2013-03-05 12:46:26 -0800 | [diff] [blame] | 3035 | final void activityDestroyedLocked(IBinder token) { |
| 3036 | final long origId = Binder.clearCallingIdentity(); |
| 3037 | try { |
| 3038 | ActivityRecord r = ActivityRecord.forToken(token); |
| 3039 | if (r != null) { |
| 3040 | mHandler.removeMessages(DESTROY_TIMEOUT_MSG, r); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 3041 | } |
Craig Mautner | d232895 | 2013-03-05 12:46:26 -0800 | [diff] [blame] | 3042 | |
| 3043 | if (isInStackLocked(token) != null) { |
| 3044 | if (r.state == ActivityState.DESTROYING) { |
| 3045 | cleanUpActivityLocked(r, true, false); |
| 3046 | removeActivityFromHistoryLocked(r); |
| 3047 | } |
| 3048 | } |
Craig Mautner | 05d2903 | 2013-05-03 13:40:13 -0700 | [diff] [blame] | 3049 | mStackSupervisor.resumeTopActivitiesLocked(); |
Craig Mautner | d232895 | 2013-03-05 12:46:26 -0800 | [diff] [blame] | 3050 | } finally { |
| 3051 | Binder.restoreCallingIdentity(origId); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 3052 | } |
| 3053 | } |
Craig Mautner | de4ef02 | 2013-04-07 19:01:33 -0700 | [diff] [blame] | 3054 | |
Craig Mautner | 05d6272ba | 2013-02-11 09:39:27 -0800 | [diff] [blame] | 3055 | private void removeHistoryRecordsForAppLocked(ArrayList<ActivityRecord> list, |
| 3056 | ProcessRecord app, String listName) { |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 3057 | int i = list.size(); |
Dianne Hackborn | cc5a055 | 2012-10-01 16:32:39 -0700 | [diff] [blame] | 3058 | if (DEBUG_CLEANUP) Slog.v( |
| 3059 | TAG, "Removing app " + app + " from list " + listName |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 3060 | + " with " + i + " entries"); |
| 3061 | while (i > 0) { |
| 3062 | i--; |
Craig Mautner | 05d6272ba | 2013-02-11 09:39:27 -0800 | [diff] [blame] | 3063 | ActivityRecord r = list.get(i); |
Dianne Hackborn | cc5a055 | 2012-10-01 16:32:39 -0700 | [diff] [blame] | 3064 | if (DEBUG_CLEANUP) Slog.v(TAG, "Record #" + i + " " + r); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 3065 | if (r.app == app) { |
Dianne Hackborn | cc5a055 | 2012-10-01 16:32:39 -0700 | [diff] [blame] | 3066 | if (DEBUG_CLEANUP) Slog.v(TAG, "---> REMOVING this entry!"); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 3067 | list.remove(i); |
Dianne Hackborn | 42e620c | 2012-06-24 13:20:51 -0700 | [diff] [blame] | 3068 | removeTimeoutsForActivityLocked(r); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 3069 | } |
| 3070 | } |
| 3071 | } |
| 3072 | |
Dianne Hackborn | cc5a055 | 2012-10-01 16:32:39 -0700 | [diff] [blame] | 3073 | boolean removeHistoryRecordsForAppLocked(ProcessRecord app) { |
| 3074 | removeHistoryRecordsForAppLocked(mLRUActivities, app, "mLRUActivities"); |
Craig Mautner | de4ef02 | 2013-04-07 19:01:33 -0700 | [diff] [blame] | 3075 | removeHistoryRecordsForAppLocked(mStackSupervisor.mStoppingActivities, app, |
| 3076 | "mStoppingActivities"); |
Craig Mautner | 0eea92c | 2013-05-16 13:35:39 -0700 | [diff] [blame] | 3077 | removeHistoryRecordsForAppLocked(mStackSupervisor.mGoingToSleepActivities, app, |
| 3078 | "mGoingToSleepActivities"); |
Craig Mautner | de4ef02 | 2013-04-07 19:01:33 -0700 | [diff] [blame] | 3079 | removeHistoryRecordsForAppLocked(mStackSupervisor.mWaitingVisibleActivities, app, |
Dianne Hackborn | cc5a055 | 2012-10-01 16:32:39 -0700 | [diff] [blame] | 3080 | "mWaitingVisibleActivities"); |
Craig Mautner | f333327 | 2013-04-22 10:55:53 -0700 | [diff] [blame] | 3081 | removeHistoryRecordsForAppLocked(mStackSupervisor.mFinishingActivities, app, |
| 3082 | "mFinishingActivities"); |
Dianne Hackborn | cc5a055 | 2012-10-01 16:32:39 -0700 | [diff] [blame] | 3083 | |
| 3084 | boolean hasVisibleActivities = false; |
| 3085 | |
| 3086 | // Clean out the history list. |
Craig Mautner | 0247fc8 | 2013-02-28 14:32:06 -0800 | [diff] [blame] | 3087 | int i = numActivities(); |
Dianne Hackborn | cc5a055 | 2012-10-01 16:32:39 -0700 | [diff] [blame] | 3088 | if (DEBUG_CLEANUP) Slog.v( |
| 3089 | TAG, "Removing app " + app + " from history with " + i + " entries"); |
Craig Mautner | 0247fc8 | 2013-02-28 14:32:06 -0800 | [diff] [blame] | 3090 | for (int taskNdx = mTaskHistory.size() - 1; taskNdx >= 0; --taskNdx) { |
| 3091 | final ArrayList<ActivityRecord> activities = mTaskHistory.get(taskNdx).mActivities; |
| 3092 | for (int activityNdx = activities.size() - 1; activityNdx >= 0; --activityNdx) { |
| 3093 | final ActivityRecord r = activities.get(activityNdx); |
| 3094 | --i; |
| 3095 | if (DEBUG_CLEANUP) Slog.v( |
| 3096 | TAG, "Record #" + i + " " + r + ": app=" + r.app); |
| 3097 | if (r.app == app) { |
| 3098 | boolean remove; |
| 3099 | if ((!r.haveState && !r.stateNotNeeded) || r.finishing) { |
| 3100 | // Don't currently have state for the activity, or |
| 3101 | // it is finishing -- always remove it. |
| 3102 | remove = true; |
| 3103 | } else if (r.launchCount > 2 && |
| 3104 | r.lastLaunchTime > (SystemClock.uptimeMillis()-60000)) { |
| 3105 | // We have launched this activity too many times since it was |
| 3106 | // able to run, so give up and remove it. |
| 3107 | remove = true; |
| 3108 | } else { |
| 3109 | // The process may be gone, but the activity lives on! |
| 3110 | remove = false; |
Dianne Hackborn | cc5a055 | 2012-10-01 16:32:39 -0700 | [diff] [blame] | 3111 | } |
Craig Mautner | 0247fc8 | 2013-02-28 14:32:06 -0800 | [diff] [blame] | 3112 | if (remove) { |
Craig Mautner | 0eea92c | 2013-05-16 13:35:39 -0700 | [diff] [blame] | 3113 | if (DEBUG_ADD_REMOVE || DEBUG_CLEANUP) { |
Craig Mautner | 0247fc8 | 2013-02-28 14:32:06 -0800 | [diff] [blame] | 3114 | RuntimeException here = new RuntimeException("here"); |
| 3115 | here.fillInStackTrace(); |
| 3116 | Slog.i(TAG, "Removing activity " + r + " from stack at " + i |
| 3117 | + ": haveState=" + r.haveState |
| 3118 | + " stateNotNeeded=" + r.stateNotNeeded |
| 3119 | + " finishing=" + r.finishing |
| 3120 | + " state=" + r.state, here); |
| 3121 | } |
| 3122 | if (!r.finishing) { |
| 3123 | Slog.w(TAG, "Force removing " + r + ": app died, no saved state"); |
| 3124 | EventLog.writeEvent(EventLogTags.AM_FINISH_ACTIVITY, |
| 3125 | r.userId, System.identityHashCode(r), |
| 3126 | r.task.taskId, r.shortComponentName, |
| 3127 | "proc died without state saved"); |
Jeff Sharkey | 5782da7 | 2013-04-25 14:32:30 -0700 | [diff] [blame] | 3128 | if (r.state == ActivityState.RESUMED) { |
| 3129 | mService.updateUsageStats(r, false); |
| 3130 | } |
Craig Mautner | 0247fc8 | 2013-02-28 14:32:06 -0800 | [diff] [blame] | 3131 | } |
| 3132 | removeActivityFromHistoryLocked(r); |
Dianne Hackborn | cc5a055 | 2012-10-01 16:32:39 -0700 | [diff] [blame] | 3133 | |
Craig Mautner | 0247fc8 | 2013-02-28 14:32:06 -0800 | [diff] [blame] | 3134 | } else { |
| 3135 | // We have the current state for this activity, so |
| 3136 | // it can be restarted later when needed. |
| 3137 | if (localLOGV) Slog.v( |
| 3138 | TAG, "Keeping entry, setting app to null"); |
| 3139 | if (r.visible) { |
| 3140 | hasVisibleActivities = true; |
| 3141 | } |
| 3142 | if (DEBUG_APP) Slog.v(TAG, "Clearing app during removeHistory for activity " |
| 3143 | + r); |
| 3144 | r.app = null; |
| 3145 | r.nowVisible = false; |
| 3146 | if (!r.haveState) { |
Craig Mautner | 0eea92c | 2013-05-16 13:35:39 -0700 | [diff] [blame] | 3147 | if (DEBUG_SAVED_STATE) Slog.i(TAG, |
Craig Mautner | 0247fc8 | 2013-02-28 14:32:06 -0800 | [diff] [blame] | 3148 | "App died, clearing saved state of " + r); |
| 3149 | r.icicle = null; |
| 3150 | } |
Dianne Hackborn | cc5a055 | 2012-10-01 16:32:39 -0700 | [diff] [blame] | 3151 | } |
Dianne Hackborn | cc5a055 | 2012-10-01 16:32:39 -0700 | [diff] [blame] | 3152 | |
Craig Mautner | d232895 | 2013-03-05 12:46:26 -0800 | [diff] [blame] | 3153 | cleanUpActivityLocked(r, true, true); |
Craig Mautner | 0247fc8 | 2013-02-28 14:32:06 -0800 | [diff] [blame] | 3154 | } |
Dianne Hackborn | cc5a055 | 2012-10-01 16:32:39 -0700 | [diff] [blame] | 3155 | } |
| 3156 | } |
| 3157 | |
| 3158 | return hasVisibleActivities; |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 3159 | } |
Craig Mautner | 0247fc8 | 2013-02-28 14:32:06 -0800 | [diff] [blame] | 3160 | |
Dianne Hackborn | 7f58b95 | 2012-04-18 12:59:29 -0700 | [diff] [blame] | 3161 | final void updateTransitLocked(int transit, Bundle options) { |
| 3162 | if (options != null) { |
| 3163 | ActivityRecord r = topRunningActivityLocked(null); |
| 3164 | if (r != null && r.state != ActivityState.RESUMED) { |
| 3165 | r.updateOptionsLocked(options); |
| 3166 | } else { |
| 3167 | ActivityOptions.abort(options); |
| 3168 | } |
| 3169 | } |
Craig Mautner | ce5f3cb | 2013-04-22 08:58:54 -0700 | [diff] [blame] | 3170 | mWindowManager.prepareAppTransition(transit, false); |
Dianne Hackborn | 7f58b95 | 2012-04-18 12:59:29 -0700 | [diff] [blame] | 3171 | } |
Dianne Hackborn | 621e17d | 2010-11-22 15:59:56 -0800 | [diff] [blame] | 3172 | |
Craig Mautner | 21d24a2 | 2014-04-23 11:45:37 -0700 | [diff] [blame] | 3173 | void updateTaskMovement(TaskRecord task, boolean toFront) { |
| 3174 | if (task.isPersistable) { |
| 3175 | task.mLastTimeMoved = System.currentTimeMillis(); |
| 3176 | // Sign is used to keep tasks sorted when persisted. Tasks sent to the bottom most |
| 3177 | // recently will be most negative, tasks sent to the bottom before that will be less |
| 3178 | // negative. Similarly for recent tasks moved to the top which will be most positive. |
| 3179 | if (!toFront) { |
| 3180 | task.mLastTimeMoved *= -1; |
| 3181 | } |
| 3182 | } |
| 3183 | } |
| 3184 | |
Craig Mautner | b9a6c8a | 2014-05-29 16:50:59 +0000 | [diff] [blame] | 3185 | void moveHomeTaskToTop() { |
Craig Mautner | a82aa09 | 2013-09-13 15:34:08 -0700 | [diff] [blame] | 3186 | final int top = mTaskHistory.size() - 1; |
| 3187 | for (int taskNdx = top; taskNdx >= 0; --taskNdx) { |
| 3188 | final TaskRecord task = mTaskHistory.get(taskNdx); |
Craig Mautner | b9a6c8a | 2014-05-29 16:50:59 +0000 | [diff] [blame] | 3189 | if (task.isHomeTask()) { |
| 3190 | if (DEBUG_TASKS || DEBUG_STACK) Slog.d(TAG, "moveHomeTaskToTop: moving " + task); |
Craig Mautner | a82aa09 | 2013-09-13 15:34:08 -0700 | [diff] [blame] | 3191 | mTaskHistory.remove(taskNdx); |
| 3192 | mTaskHistory.add(top, task); |
Craig Mautner | 21d24a2 | 2014-04-23 11:45:37 -0700 | [diff] [blame] | 3193 | updateTaskMovement(task, true); |
Craig Mautner | a82aa09 | 2013-09-13 15:34:08 -0700 | [diff] [blame] | 3194 | mWindowManager.moveTaskToTop(task.taskId); |
| 3195 | return; |
| 3196 | } |
| 3197 | } |
| 3198 | } |
| 3199 | |
Dianne Hackborn | 8078d8c | 2012-03-20 11:11:26 -0700 | [diff] [blame] | 3200 | final void moveTaskToFrontLocked(TaskRecord tr, ActivityRecord reason, Bundle options) { |
Craig Mautner | 11bf9a5 | 2013-02-19 14:08:51 -0800 | [diff] [blame] | 3201 | if (DEBUG_SWITCH) Slog.v(TAG, "moveTaskToFront: " + tr); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 3202 | |
Craig Mautner | 11bf9a5 | 2013-02-19 14:08:51 -0800 | [diff] [blame] | 3203 | final int numTasks = mTaskHistory.size(); |
| 3204 | final int index = mTaskHistory.indexOf(tr); |
Craig Mautner | 86d67a4 | 2013-05-14 10:34:38 -0700 | [diff] [blame] | 3205 | if (numTasks == 0 || index < 0) { |
Craig Mautner | 11bf9a5 | 2013-02-19 14:08:51 -0800 | [diff] [blame] | 3206 | // nothing to do! |
| 3207 | if (reason != null && |
| 3208 | (reason.intent.getFlags()&Intent.FLAG_ACTIVITY_NO_ANIMATION) != 0) { |
| 3209 | ActivityOptions.abort(options); |
| 3210 | } else { |
| 3211 | updateTransitLocked(AppTransition.TRANSIT_TASK_TO_FRONT, options); |
| 3212 | } |
| 3213 | return; |
| 3214 | } |
| 3215 | |
Craig Mautner | e0a3884 | 2013-12-16 16:14:02 -0800 | [diff] [blame] | 3216 | moveToFront(); |
Craig Mautner | fb1e20d | 2013-06-23 21:24:13 -0700 | [diff] [blame] | 3217 | |
Craig Mautner | 11bf9a5 | 2013-02-19 14:08:51 -0800 | [diff] [blame] | 3218 | // Shift all activities with this task up to the top |
| 3219 | // of the stack, keeping them in the same internal order. |
Craig Mautner | ac6f843 | 2013-07-17 13:24:59 -0700 | [diff] [blame] | 3220 | insertTaskAtTop(tr); |
Craig Mautner | 11bf9a5 | 2013-02-19 14:08:51 -0800 | [diff] [blame] | 3221 | |
| 3222 | if (DEBUG_TRANSITION) Slog.v(TAG, "Prepare to front transition: task=" + tr); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 3223 | if (reason != null && |
| 3224 | (reason.intent.getFlags()&Intent.FLAG_ACTIVITY_NO_ANIMATION) != 0) { |
Craig Mautner | ce5f3cb | 2013-04-22 08:58:54 -0700 | [diff] [blame] | 3225 | mWindowManager.prepareAppTransition(AppTransition.TRANSIT_NONE, false); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 3226 | ActivityRecord r = topRunningActivityLocked(null); |
| 3227 | if (r != null) { |
| 3228 | mNoAnimActivities.add(r); |
| 3229 | } |
Dianne Hackborn | 8078d8c | 2012-03-20 11:11:26 -0700 | [diff] [blame] | 3230 | ActivityOptions.abort(options); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 3231 | } else { |
Craig Mautner | 4b71aa1 | 2012-12-27 17:20:01 -0800 | [diff] [blame] | 3232 | updateTransitLocked(AppTransition.TRANSIT_TASK_TO_FRONT, options); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 3233 | } |
Craig Mautner | 30e2d72 | 2013-02-12 11:30:16 -0800 | [diff] [blame] | 3234 | |
Craig Mautner | ce5f3cb | 2013-04-22 08:58:54 -0700 | [diff] [blame] | 3235 | mWindowManager.moveTaskToTop(tr.taskId); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 3236 | |
Craig Mautner | 05d2903 | 2013-05-03 13:40:13 -0700 | [diff] [blame] | 3237 | mStackSupervisor.resumeTopActivitiesLocked(); |
Craig Mautner | 5854780 | 2013-03-05 08:23:53 -0800 | [diff] [blame] | 3238 | EventLog.writeEvent(EventLogTags.AM_TASK_TO_FRONT, tr.userId, tr.taskId); |
Craig Mautner | 11bf9a5 | 2013-02-19 14:08:51 -0800 | [diff] [blame] | 3239 | |
| 3240 | if (VALIDATE_TOKENS) { |
| 3241 | validateAppTokensLocked(); |
| 3242 | } |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 3243 | } |
| 3244 | |
| 3245 | /** |
Craig Mautner | ce5f3cb | 2013-04-22 08:58:54 -0700 | [diff] [blame] | 3246 | * Worker method for rearranging history stack. Implements the function of moving all |
| 3247 | * activities for a specific task (gathering them if disjoint) into a single group at the |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 3248 | * bottom of the stack. |
Craig Mautner | ce5f3cb | 2013-04-22 08:58:54 -0700 | [diff] [blame] | 3249 | * |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 3250 | * If a watcher is installed, the action is preflighted and the watcher has an opportunity |
| 3251 | * to premeptively cancel the move. |
Craig Mautner | ce5f3cb | 2013-04-22 08:58:54 -0700 | [diff] [blame] | 3252 | * |
Craig Mautner | ae7ecab | 2013-09-18 11:48:14 -0700 | [diff] [blame] | 3253 | * @param taskId The taskId to collect and move to the bottom. |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 3254 | * @return Returns true if the move completed, false if not. |
| 3255 | */ |
Craig Mautner | ae7ecab | 2013-09-18 11:48:14 -0700 | [diff] [blame] | 3256 | final boolean moveTaskToBackLocked(int taskId, ActivityRecord reason) { |
Craig Mautner | aea74a5 | 2014-03-08 14:23:10 -0800 | [diff] [blame] | 3257 | final TaskRecord tr = taskForIdLocked(taskId); |
| 3258 | if (tr == null) { |
| 3259 | Slog.i(TAG, "moveTaskToBack: bad taskId=" + taskId); |
| 3260 | return false; |
| 3261 | } |
| 3262 | |
| 3263 | Slog.i(TAG, "moveTaskToBack: " + tr); |
| 3264 | |
| 3265 | mStackSupervisor.endLockTaskModeIfTaskEnding(tr); |
Craig Mautner | b44de0d | 2013-02-21 20:00:58 -0800 | [diff] [blame] | 3266 | |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 3267 | // If we have a watcher, preflight the move before committing to it. First check |
| 3268 | // for *other* available tasks, but if none are available, then try again allowing the |
| 3269 | // current task to be selected. |
Craig Mautner | de4ef02 | 2013-04-07 19:01:33 -0700 | [diff] [blame] | 3270 | if (mStackSupervisor.isFrontStack(this) && mService.mController != null) { |
Craig Mautner | ae7ecab | 2013-09-18 11:48:14 -0700 | [diff] [blame] | 3271 | ActivityRecord next = topRunningActivityLocked(null, taskId); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 3272 | if (next == null) { |
| 3273 | next = topRunningActivityLocked(null, 0); |
| 3274 | } |
| 3275 | if (next != null) { |
| 3276 | // ask watcher if this is allowed |
| 3277 | boolean moveOK = true; |
| 3278 | try { |
| 3279 | moveOK = mService.mController.activityResuming(next.packageName); |
| 3280 | } catch (RemoteException e) { |
| 3281 | mService.mController = null; |
Kenny Root | add5821 | 2013-05-07 09:47:34 -0700 | [diff] [blame] | 3282 | Watchdog.getInstance().setActivityController(null); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 3283 | } |
| 3284 | if (!moveOK) { |
| 3285 | return false; |
| 3286 | } |
| 3287 | } |
| 3288 | } |
| 3289 | |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 3290 | if (DEBUG_TRANSITION) Slog.v(TAG, |
Craig Mautner | ae7ecab | 2013-09-18 11:48:14 -0700 | [diff] [blame] | 3291 | "Prepare to back transition: task=" + taskId); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 3292 | |
Craig Mautner | 11bf9a5 | 2013-02-19 14:08:51 -0800 | [diff] [blame] | 3293 | mTaskHistory.remove(tr); |
| 3294 | mTaskHistory.add(0, tr); |
Craig Mautner | 21d24a2 | 2014-04-23 11:45:37 -0700 | [diff] [blame] | 3295 | updateTaskMovement(tr, false); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 3296 | |
Craig Mautner | c8143c6 | 2013-09-03 12:15:57 -0700 | [diff] [blame] | 3297 | // There is an assumption that moving a task to the back moves it behind the home activity. |
| 3298 | // We make sure here that some activity in the stack will launch home. |
Craig Mautner | c8143c6 | 2013-09-03 12:15:57 -0700 | [diff] [blame] | 3299 | int numTasks = mTaskHistory.size(); |
Craig Mautner | ae7ecab | 2013-09-18 11:48:14 -0700 | [diff] [blame] | 3300 | for (int taskNdx = numTasks - 1; taskNdx >= 1; --taskNdx) { |
| 3301 | final TaskRecord task = mTaskHistory.get(taskNdx); |
Craig Mautner | b9a6c8a | 2014-05-29 16:50:59 +0000 | [diff] [blame] | 3302 | if (task.mOnTopOfHome) { |
Craig Mautner | c8143c6 | 2013-09-03 12:15:57 -0700 | [diff] [blame] | 3303 | break; |
| 3304 | } |
Craig Mautner | ae7ecab | 2013-09-18 11:48:14 -0700 | [diff] [blame] | 3305 | if (taskNdx == 1) { |
| 3306 | // Set the last task before tr to go to home. |
Craig Mautner | b9a6c8a | 2014-05-29 16:50:59 +0000 | [diff] [blame] | 3307 | task.mOnTopOfHome = true; |
Craig Mautner | ae7ecab | 2013-09-18 11:48:14 -0700 | [diff] [blame] | 3308 | } |
Craig Mautner | c8143c6 | 2013-09-03 12:15:57 -0700 | [diff] [blame] | 3309 | } |
| 3310 | |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 3311 | if (reason != null && |
Craig Mautner | ce5f3cb | 2013-04-22 08:58:54 -0700 | [diff] [blame] | 3312 | (reason.intent.getFlags() & Intent.FLAG_ACTIVITY_NO_ANIMATION) != 0) { |
| 3313 | mWindowManager.prepareAppTransition(AppTransition.TRANSIT_NONE, false); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 3314 | ActivityRecord r = topRunningActivityLocked(null); |
| 3315 | if (r != null) { |
| 3316 | mNoAnimActivities.add(r); |
| 3317 | } |
| 3318 | } else { |
Craig Mautner | c8143c6 | 2013-09-03 12:15:57 -0700 | [diff] [blame] | 3319 | mWindowManager.prepareAppTransition(AppTransition.TRANSIT_TASK_TO_BACK, false); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 3320 | } |
Craig Mautner | ae7ecab | 2013-09-18 11:48:14 -0700 | [diff] [blame] | 3321 | mWindowManager.moveTaskToBottom(taskId); |
Craig Mautner | b44de0d | 2013-02-21 20:00:58 -0800 | [diff] [blame] | 3322 | |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 3323 | if (VALIDATE_TOKENS) { |
Dianne Hackborn | be70785 | 2011-11-11 14:32:10 -0800 | [diff] [blame] | 3324 | validateAppTokensLocked(); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 3325 | } |
| 3326 | |
Craig Mautner | ae7ecab | 2013-09-18 11:48:14 -0700 | [diff] [blame] | 3327 | final TaskRecord task = mResumedActivity != null ? mResumedActivity.task : null; |
Craig Mautner | b9a6c8a | 2014-05-29 16:50:59 +0000 | [diff] [blame] | 3328 | if (task == tr && tr.mOnTopOfHome || numTasks <= 1 && isOnHomeDisplay()) { |
| 3329 | tr.mOnTopOfHome = false; |
| 3330 | return mStackSupervisor.resumeHomeActivity(null); |
Craig Mautner | de4ef02 | 2013-04-07 19:01:33 -0700 | [diff] [blame] | 3331 | } |
| 3332 | |
Craig Mautner | 05d2903 | 2013-05-03 13:40:13 -0700 | [diff] [blame] | 3333 | mStackSupervisor.resumeTopActivitiesLocked(); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 3334 | return true; |
| 3335 | } |
Dianne Hackborn | 15491c6 | 2012-09-19 10:59:14 -0700 | [diff] [blame] | 3336 | |
Craig Mautner | 8849a5e | 2013-04-02 16:41:03 -0700 | [diff] [blame] | 3337 | static final void logStartActivity(int tag, ActivityRecord r, |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 3338 | TaskRecord task) { |
Santos Cordon | 73ff7d8 | 2013-03-06 17:24:11 -0800 | [diff] [blame] | 3339 | final Uri data = r.intent.getData(); |
| 3340 | final String strData = data != null ? data.toSafeString() : null; |
| 3341 | |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 3342 | EventLog.writeEvent(tag, |
Dianne Hackborn | b12e135 | 2012-09-26 11:39:20 -0700 | [diff] [blame] | 3343 | r.userId, System.identityHashCode(r), task.taskId, |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 3344 | r.shortComponentName, r.intent.getAction(), |
Santos Cordon | 73ff7d8 | 2013-03-06 17:24:11 -0800 | [diff] [blame] | 3345 | r.intent.getType(), strData, r.intent.getFlags()); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 3346 | } |
| 3347 | |
| 3348 | /** |
| 3349 | * Make sure the given activity matches the current configuration. Returns |
| 3350 | * false if the activity had to be destroyed. Returns true if the |
| 3351 | * configuration is the same, or the activity will remain running as-is |
| 3352 | * for whatever reason. Ensures the HistoryRecord is updated with the |
| 3353 | * correct configuration and all other bookkeeping is handled. |
| 3354 | */ |
| 3355 | final boolean ensureActivityConfigurationLocked(ActivityRecord r, |
| 3356 | int globalChanges) { |
| 3357 | if (mConfigWillChange) { |
| 3358 | if (DEBUG_SWITCH || DEBUG_CONFIGURATION) Slog.v(TAG, |
| 3359 | "Skipping config check (will change): " + r); |
| 3360 | return true; |
| 3361 | } |
Craig Mautner | ce5f3cb | 2013-04-22 08:58:54 -0700 | [diff] [blame] | 3362 | |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 3363 | if (DEBUG_SWITCH || DEBUG_CONFIGURATION) Slog.v(TAG, |
| 3364 | "Ensuring correct configuration: " + r); |
Craig Mautner | 9db9a0b | 2013-04-29 17:05:56 -0700 | [diff] [blame] | 3365 | |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 3366 | // Short circuit: if the two configurations are the exact same |
| 3367 | // object (the common case), then there is nothing to do. |
| 3368 | Configuration newConfig = mService.mConfiguration; |
Dianne Hackborn | e2515ee | 2011-04-27 18:52:56 -0400 | [diff] [blame] | 3369 | if (r.configuration == newConfig && !r.forceNewConfig) { |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 3370 | if (DEBUG_SWITCH || DEBUG_CONFIGURATION) Slog.v(TAG, |
| 3371 | "Configuration unchanged in " + r); |
| 3372 | return true; |
| 3373 | } |
Craig Mautner | ce5f3cb | 2013-04-22 08:58:54 -0700 | [diff] [blame] | 3374 | |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 3375 | // We don't worry about activities that are finishing. |
| 3376 | if (r.finishing) { |
| 3377 | if (DEBUG_SWITCH || DEBUG_CONFIGURATION) Slog.v(TAG, |
| 3378 | "Configuration doesn't matter in finishing " + r); |
| 3379 | r.stopFreezingScreenLocked(false); |
| 3380 | return true; |
| 3381 | } |
Craig Mautner | ce5f3cb | 2013-04-22 08:58:54 -0700 | [diff] [blame] | 3382 | |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 3383 | // Okay we now are going to make this activity have the new config. |
| 3384 | // But then we need to figure out how it needs to deal with that. |
| 3385 | Configuration oldConfig = r.configuration; |
| 3386 | r.configuration = newConfig; |
Dianne Hackborn | 58f42a5 | 2011-10-10 13:46:34 -0700 | [diff] [blame] | 3387 | |
| 3388 | // Determine what has changed. May be nothing, if this is a config |
| 3389 | // that has come back from the app after going idle. In that case |
| 3390 | // we just want to leave the official config object now in the |
| 3391 | // activity and do nothing else. |
| 3392 | final int changes = oldConfig.diff(newConfig); |
| 3393 | if (changes == 0 && !r.forceNewConfig) { |
| 3394 | if (DEBUG_SWITCH || DEBUG_CONFIGURATION) Slog.v(TAG, |
| 3395 | "Configuration no differences in " + r); |
| 3396 | return true; |
| 3397 | } |
| 3398 | |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 3399 | // If the activity isn't currently running, just leave the new |
| 3400 | // configuration and it will pick that up next time it starts. |
| 3401 | if (r.app == null || r.app.thread == null) { |
| 3402 | if (DEBUG_SWITCH || DEBUG_CONFIGURATION) Slog.v(TAG, |
| 3403 | "Configuration doesn't matter not running " + r); |
| 3404 | r.stopFreezingScreenLocked(false); |
Dianne Hackborn | e2515ee | 2011-04-27 18:52:56 -0400 | [diff] [blame] | 3405 | r.forceNewConfig = false; |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 3406 | return true; |
| 3407 | } |
Craig Mautner | ce5f3cb | 2013-04-22 08:58:54 -0700 | [diff] [blame] | 3408 | |
Dianne Hackborn | 58f42a5 | 2011-10-10 13:46:34 -0700 | [diff] [blame] | 3409 | // Figure out how to handle the changes between the configurations. |
Dianne Hackborn | 3c4c2b7 | 2010-10-05 18:07:54 -0700 | [diff] [blame] | 3410 | if (DEBUG_SWITCH || DEBUG_CONFIGURATION) { |
| 3411 | Slog.v(TAG, "Checking to restart " + r.info.name + ": changed=0x" |
| 3412 | + Integer.toHexString(changes) + ", handles=0x" |
Dianne Hackborn | e667635 | 2011-06-01 16:51:20 -0700 | [diff] [blame] | 3413 | + Integer.toHexString(r.info.getRealConfigChanged()) |
Dianne Hackborn | 3c4c2b7 | 2010-10-05 18:07:54 -0700 | [diff] [blame] | 3414 | + ", newConfig=" + newConfig); |
| 3415 | } |
Dianne Hackborn | e667635 | 2011-06-01 16:51:20 -0700 | [diff] [blame] | 3416 | if ((changes&(~r.info.getRealConfigChanged())) != 0 || r.forceNewConfig) { |
Dianne Hackborn | 3c4c2b7 | 2010-10-05 18:07:54 -0700 | [diff] [blame] | 3417 | // Aha, the activity isn't handling the change, so DIE DIE DIE. |
| 3418 | r.configChangeFlags |= changes; |
| 3419 | r.startFreezingScreenLocked(r.app, globalChanges); |
Dianne Hackborn | e2515ee | 2011-04-27 18:52:56 -0400 | [diff] [blame] | 3420 | r.forceNewConfig = false; |
Dianne Hackborn | 3c4c2b7 | 2010-10-05 18:07:54 -0700 | [diff] [blame] | 3421 | if (r.app == null || r.app.thread == null) { |
| 3422 | if (DEBUG_SWITCH || DEBUG_CONFIGURATION) Slog.v(TAG, |
Dianne Hackborn | b61a026 | 2012-05-14 17:19:18 -0700 | [diff] [blame] | 3423 | "Config is destroying non-running " + r); |
Dianne Hackborn | 28695e0 | 2011-11-02 21:59:51 -0700 | [diff] [blame] | 3424 | destroyActivityLocked(r, true, false, "config"); |
Dianne Hackborn | 3c4c2b7 | 2010-10-05 18:07:54 -0700 | [diff] [blame] | 3425 | } else if (r.state == ActivityState.PAUSING) { |
| 3426 | // A little annoying: we are waiting for this activity to |
| 3427 | // finish pausing. Let's not do anything now, but just |
| 3428 | // flag that it needs to be restarted when done pausing. |
| 3429 | if (DEBUG_SWITCH || DEBUG_CONFIGURATION) Slog.v(TAG, |
Dianne Hackborn | b61a026 | 2012-05-14 17:19:18 -0700 | [diff] [blame] | 3430 | "Config is skipping already pausing " + r); |
Dianne Hackborn | 3c4c2b7 | 2010-10-05 18:07:54 -0700 | [diff] [blame] | 3431 | r.configDestroy = true; |
| 3432 | return true; |
| 3433 | } else if (r.state == ActivityState.RESUMED) { |
| 3434 | // Try to optimize this case: the configuration is changing |
| 3435 | // and we need to restart the top, resumed activity. |
| 3436 | // Instead of doing the normal handshaking, just say |
| 3437 | // "restart!". |
| 3438 | if (DEBUG_SWITCH || DEBUG_CONFIGURATION) Slog.v(TAG, |
Dianne Hackborn | b61a026 | 2012-05-14 17:19:18 -0700 | [diff] [blame] | 3439 | "Config is relaunching resumed " + r); |
Dianne Hackborn | 3c4c2b7 | 2010-10-05 18:07:54 -0700 | [diff] [blame] | 3440 | relaunchActivityLocked(r, r.configChangeFlags, true); |
| 3441 | r.configChangeFlags = 0; |
| 3442 | } else { |
| 3443 | if (DEBUG_SWITCH || DEBUG_CONFIGURATION) Slog.v(TAG, |
Dianne Hackborn | b61a026 | 2012-05-14 17:19:18 -0700 | [diff] [blame] | 3444 | "Config is relaunching non-resumed " + r); |
Dianne Hackborn | 3c4c2b7 | 2010-10-05 18:07:54 -0700 | [diff] [blame] | 3445 | relaunchActivityLocked(r, r.configChangeFlags, false); |
| 3446 | r.configChangeFlags = 0; |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 3447 | } |
Craig Mautner | ce5f3cb | 2013-04-22 08:58:54 -0700 | [diff] [blame] | 3448 | |
Dianne Hackborn | 3c4c2b7 | 2010-10-05 18:07:54 -0700 | [diff] [blame] | 3449 | // All done... tell the caller we weren't able to keep this |
| 3450 | // activity around. |
| 3451 | return false; |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 3452 | } |
Craig Mautner | ce5f3cb | 2013-04-22 08:58:54 -0700 | [diff] [blame] | 3453 | |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 3454 | // Default case: the activity can handle this new configuration, so |
| 3455 | // hand it over. Note that we don't need to give it the new |
| 3456 | // configuration, since we always send configuration changes to all |
| 3457 | // process when they happen so it can just use whatever configuration |
| 3458 | // it last got. |
| 3459 | if (r.app != null && r.app.thread != null) { |
| 3460 | try { |
| 3461 | if (DEBUG_CONFIGURATION) Slog.v(TAG, "Sending new config to " + r); |
Dianne Hackborn | be70785 | 2011-11-11 14:32:10 -0800 | [diff] [blame] | 3462 | r.app.thread.scheduleActivityConfigurationChanged(r.appToken); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 3463 | } catch (RemoteException e) { |
| 3464 | // If process died, whatever. |
| 3465 | } |
| 3466 | } |
| 3467 | r.stopFreezingScreenLocked(false); |
Craig Mautner | ce5f3cb | 2013-04-22 08:58:54 -0700 | [diff] [blame] | 3468 | |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 3469 | return true; |
| 3470 | } |
| 3471 | |
Craig Mautner | c8143c6 | 2013-09-03 12:15:57 -0700 | [diff] [blame] | 3472 | private boolean relaunchActivityLocked(ActivityRecord r, |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 3473 | int changes, boolean andResume) { |
| 3474 | List<ResultInfo> results = null; |
| 3475 | List<Intent> newIntents = null; |
| 3476 | if (andResume) { |
| 3477 | results = r.results; |
| 3478 | newIntents = r.newIntents; |
| 3479 | } |
| 3480 | if (DEBUG_SWITCH) Slog.v(TAG, "Relaunching: " + r |
| 3481 | + " with results=" + results + " newIntents=" + newIntents |
| 3482 | + " andResume=" + andResume); |
| 3483 | EventLog.writeEvent(andResume ? EventLogTags.AM_RELAUNCH_RESUME_ACTIVITY |
Dianne Hackborn | b12e135 | 2012-09-26 11:39:20 -0700 | [diff] [blame] | 3484 | : EventLogTags.AM_RELAUNCH_ACTIVITY, r.userId, System.identityHashCode(r), |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 3485 | r.task.taskId, r.shortComponentName); |
Craig Mautner | 9db9a0b | 2013-04-29 17:05:56 -0700 | [diff] [blame] | 3486 | |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 3487 | r.startFreezingScreenLocked(r.app, 0); |
Craig Mautner | 9db9a0b | 2013-04-29 17:05:56 -0700 | [diff] [blame] | 3488 | |
Craig Mautner | 34b73df | 2014-01-12 21:11:08 -0800 | [diff] [blame] | 3489 | mStackSupervisor.removeChildActivityContainers(r); |
| 3490 | |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 3491 | try { |
Dianne Hackborn | b61a026 | 2012-05-14 17:19:18 -0700 | [diff] [blame] | 3492 | if (DEBUG_SWITCH || DEBUG_STATES) Slog.i(TAG, |
| 3493 | (andResume ? "Relaunching to RESUMED " : "Relaunching to PAUSED ") |
| 3494 | + r); |
Dianne Hackborn | e2515ee | 2011-04-27 18:52:56 -0400 | [diff] [blame] | 3495 | r.forceNewConfig = false; |
Dianne Hackborn | be70785 | 2011-11-11 14:32:10 -0800 | [diff] [blame] | 3496 | r.app.thread.scheduleRelaunchActivity(r.appToken, results, newIntents, |
Dianne Hackborn | 813075a6 | 2011-11-14 17:45:19 -0800 | [diff] [blame] | 3497 | changes, !andResume, new Configuration(mService.mConfiguration)); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 3498 | // Note: don't need to call pauseIfSleepingLocked() here, because |
| 3499 | // the caller will only pass in 'andResume' if this activity is |
| 3500 | // currently resumed, which implies we aren't sleeping. |
| 3501 | } catch (RemoteException e) { |
Dianne Hackborn | b61a026 | 2012-05-14 17:19:18 -0700 | [diff] [blame] | 3502 | if (DEBUG_SWITCH || DEBUG_STATES) Slog.i(TAG, "Relaunch failed", e); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 3503 | } |
| 3504 | |
| 3505 | if (andResume) { |
| 3506 | r.results = null; |
| 3507 | r.newIntents = null; |
Dianne Hackborn | b61a026 | 2012-05-14 17:19:18 -0700 | [diff] [blame] | 3508 | r.state = ActivityState.RESUMED; |
| 3509 | } else { |
| 3510 | mHandler.removeMessages(PAUSE_TIMEOUT_MSG, r); |
| 3511 | r.state = ActivityState.PAUSED; |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 3512 | } |
| 3513 | |
| 3514 | return true; |
| 3515 | } |
Craig Mautner | cae015f | 2013-02-08 14:31:27 -0800 | [diff] [blame] | 3516 | |
| 3517 | boolean willActivityBeVisibleLocked(IBinder token) { |
Craig Mautner | d44711d | 2013-02-23 11:24:36 -0800 | [diff] [blame] | 3518 | for (int taskNdx = mTaskHistory.size() - 1; taskNdx >= 0; --taskNdx) { |
| 3519 | final ArrayList<ActivityRecord> activities = mTaskHistory.get(taskNdx).mActivities; |
| 3520 | for (int activityNdx = activities.size() - 1; activityNdx >= 0; --activityNdx) { |
| 3521 | final ActivityRecord r = activities.get(activityNdx); |
| 3522 | if (r.appToken == token) { |
Craig Mautner | 34b73df | 2014-01-12 21:11:08 -0800 | [diff] [blame] | 3523 | return true; |
Craig Mautner | d44711d | 2013-02-23 11:24:36 -0800 | [diff] [blame] | 3524 | } |
| 3525 | if (r.fullscreen && !r.finishing) { |
| 3526 | return false; |
| 3527 | } |
Craig Mautner | cae015f | 2013-02-08 14:31:27 -0800 | [diff] [blame] | 3528 | } |
| 3529 | } |
Craig Mautner | 34b73df | 2014-01-12 21:11:08 -0800 | [diff] [blame] | 3530 | final ActivityRecord r = ActivityRecord.forToken(token); |
| 3531 | if (r == null) { |
| 3532 | return false; |
| 3533 | } |
| 3534 | if (r.finishing) Slog.e(TAG, "willActivityBeVisibleLocked: Returning false," |
| 3535 | + " would have returned true for r=" + r); |
| 3536 | return !r.finishing; |
Craig Mautner | cae015f | 2013-02-08 14:31:27 -0800 | [diff] [blame] | 3537 | } |
| 3538 | |
| 3539 | void closeSystemDialogsLocked() { |
Craig Mautner | d44711d | 2013-02-23 11:24:36 -0800 | [diff] [blame] | 3540 | for (int taskNdx = mTaskHistory.size() - 1; taskNdx >= 0; --taskNdx) { |
| 3541 | final ArrayList<ActivityRecord> activities = mTaskHistory.get(taskNdx).mActivities; |
| 3542 | for (int activityNdx = activities.size() - 1; activityNdx >= 0; --activityNdx) { |
| 3543 | final ActivityRecord r = activities.get(activityNdx); |
| 3544 | if ((r.info.flags&ActivityInfo.FLAG_FINISH_ON_CLOSE_SYSTEM_DIALOGS) != 0) { |
Craig Mautner | d232895 | 2013-03-05 12:46:26 -0800 | [diff] [blame] | 3545 | finishActivityLocked(r, Activity.RESULT_CANCELED, null, "close-sys", true); |
Craig Mautner | d44711d | 2013-02-23 11:24:36 -0800 | [diff] [blame] | 3546 | } |
Craig Mautner | cae015f | 2013-02-08 14:31:27 -0800 | [diff] [blame] | 3547 | } |
| 3548 | } |
| 3549 | } |
| 3550 | |
| 3551 | boolean forceStopPackageLocked(String name, boolean doit, boolean evenPersistent, int userId) { |
| 3552 | boolean didSomething = false; |
| 3553 | TaskRecord lastTask = null; |
Craig Mautner | 56f52db | 2013-02-25 10:03:01 -0800 | [diff] [blame] | 3554 | for (int taskNdx = mTaskHistory.size() - 1; taskNdx >= 0; --taskNdx) { |
| 3555 | final ArrayList<ActivityRecord> activities = mTaskHistory.get(taskNdx).mActivities; |
| 3556 | int numActivities = activities.size(); |
| 3557 | for (int activityNdx = 0; activityNdx < numActivities; ++activityNdx) { |
| 3558 | ActivityRecord r = activities.get(activityNdx); |
| 3559 | final boolean samePackage = r.packageName.equals(name) |
| 3560 | || (name == null && r.userId == userId); |
| 3561 | if ((userId == UserHandle.USER_ALL || r.userId == userId) |
| 3562 | && (samePackage || r.task == lastTask) |
| 3563 | && (r.app == null || evenPersistent || !r.app.persistent)) { |
| 3564 | if (!doit) { |
| 3565 | if (r.finishing) { |
| 3566 | // If this activity is just finishing, then it is not |
| 3567 | // interesting as far as something to stop. |
| 3568 | continue; |
| 3569 | } |
| 3570 | return true; |
Craig Mautner | cae015f | 2013-02-08 14:31:27 -0800 | [diff] [blame] | 3571 | } |
Craig Mautner | 56f52db | 2013-02-25 10:03:01 -0800 | [diff] [blame] | 3572 | didSomething = true; |
| 3573 | Slog.i(TAG, " Force finishing activity " + r); |
| 3574 | if (samePackage) { |
| 3575 | if (r.app != null) { |
| 3576 | r.app.removed = true; |
| 3577 | } |
| 3578 | r.app = null; |
Craig Mautner | cae015f | 2013-02-08 14:31:27 -0800 | [diff] [blame] | 3579 | } |
Craig Mautner | 56f52db | 2013-02-25 10:03:01 -0800 | [diff] [blame] | 3580 | lastTask = r.task; |
Craig Mautner | d94b1b4 | 2013-05-01 11:58:03 -0700 | [diff] [blame] | 3581 | if (finishActivityLocked(r, Activity.RESULT_CANCELED, null, "force-stop", |
| 3582 | true)) { |
| 3583 | // r has been deleted from mActivities, accommodate. |
| 3584 | --numActivities; |
| 3585 | --activityNdx; |
| 3586 | } |
Craig Mautner | cae015f | 2013-02-08 14:31:27 -0800 | [diff] [blame] | 3587 | } |
| 3588 | } |
| 3589 | } |
| 3590 | return didSomething; |
| 3591 | } |
| 3592 | |
Dianne Hackborn | 0923328 | 2014-04-30 11:33:59 -0700 | [diff] [blame] | 3593 | void getTasksLocked(List<RunningTaskInfo> list, int callingUid, boolean allowed) { |
Craig Mautner | c0fd805 | 2013-09-19 11:20:17 -0700 | [diff] [blame] | 3594 | for (int taskNdx = mTaskHistory.size() - 1; taskNdx >= 0; --taskNdx) { |
Craig Mautner | aab647e | 2013-02-28 16:31:36 -0800 | [diff] [blame] | 3595 | final TaskRecord task = mTaskHistory.get(taskNdx); |
| 3596 | ActivityRecord r = null; |
| 3597 | ActivityRecord top = null; |
| 3598 | int numActivities = 0; |
| 3599 | int numRunning = 0; |
| 3600 | final ArrayList<ActivityRecord> activities = task.mActivities; |
Craig Mautner | 5cbaaa3 | 2013-10-29 13:39:26 -0700 | [diff] [blame] | 3601 | if (activities.isEmpty()) { |
| 3602 | continue; |
| 3603 | } |
Dianne Hackborn | 0923328 | 2014-04-30 11:33:59 -0700 | [diff] [blame] | 3604 | if (!allowed && !task.isHomeTask() && task.creatorUid != callingUid) { |
| 3605 | continue; |
| 3606 | } |
Craig Mautner | aab647e | 2013-02-28 16:31:36 -0800 | [diff] [blame] | 3607 | for (int activityNdx = activities.size() - 1; activityNdx >= 0; --activityNdx) { |
| 3608 | r = activities.get(activityNdx); |
Craig Mautner | cae015f | 2013-02-08 14:31:27 -0800 | [diff] [blame] | 3609 | |
Craig Mautner | aab647e | 2013-02-28 16:31:36 -0800 | [diff] [blame] | 3610 | // Initialize state for next task if needed. |
| 3611 | if (top == null || (top.state == ActivityState.INITIALIZING)) { |
| 3612 | top = r; |
| 3613 | numActivities = numRunning = 0; |
Craig Mautner | cae015f | 2013-02-08 14:31:27 -0800 | [diff] [blame] | 3614 | } |
Craig Mautner | aab647e | 2013-02-28 16:31:36 -0800 | [diff] [blame] | 3615 | |
| 3616 | // Add 'r' into the current task. |
| 3617 | numActivities++; |
| 3618 | if (r.app != null && r.app.thread != null) { |
| 3619 | numRunning++; |
| 3620 | } |
| 3621 | |
| 3622 | if (localLOGV) Slog.v( |
| 3623 | TAG, r.intent.getComponent().flattenToShortString() |
| 3624 | + ": task=" + r.task); |
| 3625 | } |
| 3626 | |
| 3627 | RunningTaskInfo ci = new RunningTaskInfo(); |
| 3628 | ci.id = task.taskId; |
| 3629 | ci.baseActivity = r.intent.getComponent(); |
| 3630 | ci.topActivity = top.intent.getComponent(); |
Craig Mautner | c0fd805 | 2013-09-19 11:20:17 -0700 | [diff] [blame] | 3631 | ci.lastActiveTime = task.lastActiveTime; |
| 3632 | |
Craig Mautner | aab647e | 2013-02-28 16:31:36 -0800 | [diff] [blame] | 3633 | if (top.thumbHolder != null) { |
| 3634 | ci.description = top.thumbHolder.lastDescription; |
| 3635 | } |
| 3636 | ci.numActivities = numActivities; |
| 3637 | ci.numRunning = numRunning; |
| 3638 | //System.out.println( |
| 3639 | // "#" + maxNum + ": " + " descr=" + ci.description); |
Craig Mautner | aab647e | 2013-02-28 16:31:36 -0800 | [diff] [blame] | 3640 | list.add(ci); |
Craig Mautner | cae015f | 2013-02-08 14:31:27 -0800 | [diff] [blame] | 3641 | } |
Craig Mautner | cae015f | 2013-02-08 14:31:27 -0800 | [diff] [blame] | 3642 | } |
| 3643 | |
| 3644 | public void unhandledBackLocked() { |
Craig Mautner | aab647e | 2013-02-28 16:31:36 -0800 | [diff] [blame] | 3645 | final int top = mTaskHistory.size() - 1; |
Craig Mautner | cae015f | 2013-02-08 14:31:27 -0800 | [diff] [blame] | 3646 | if (DEBUG_SWITCH) Slog.d( |
| 3647 | TAG, "Performing unhandledBack(): top activity at " + top); |
Craig Mautner | aab647e | 2013-02-28 16:31:36 -0800 | [diff] [blame] | 3648 | if (top >= 0) { |
| 3649 | final ArrayList<ActivityRecord> activities = mTaskHistory.get(top).mActivities; |
| 3650 | int activityTop = activities.size() - 1; |
| 3651 | if (activityTop > 0) { |
| 3652 | finishActivityLocked(activities.get(activityTop), Activity.RESULT_CANCELED, null, |
| 3653 | "unhandled-back", true); |
| 3654 | } |
Craig Mautner | cae015f | 2013-02-08 14:31:27 -0800 | [diff] [blame] | 3655 | } |
| 3656 | } |
| 3657 | |
Craig Mautner | 6b74cb5 | 2013-09-27 17:02:21 -0700 | [diff] [blame] | 3658 | /** |
| 3659 | * Reset local parameters because an app's activity died. |
| 3660 | * @param app The app of the activity that died. |
Craig Mautner | 1909125 | 2013-10-05 00:03:53 -0700 | [diff] [blame] | 3661 | * @return result from removeHistoryRecordsForAppLocked. |
Craig Mautner | 6b74cb5 | 2013-09-27 17:02:21 -0700 | [diff] [blame] | 3662 | */ |
| 3663 | boolean handleAppDiedLocked(ProcessRecord app) { |
Craig Mautner | e79d4268 | 2013-04-01 19:01:53 -0700 | [diff] [blame] | 3664 | if (mPausingActivity != null && mPausingActivity.app == app) { |
| 3665 | if (DEBUG_PAUSE || DEBUG_CLEANUP) Slog.v(TAG, |
| 3666 | "App died while pausing: " + mPausingActivity); |
| 3667 | mPausingActivity = null; |
| 3668 | } |
| 3669 | if (mLastPausedActivity != null && mLastPausedActivity.app == app) { |
| 3670 | mLastPausedActivity = null; |
Craig Mautner | 0f92274 | 2013-08-06 08:44:42 -0700 | [diff] [blame] | 3671 | mLastNoHistoryActivity = null; |
Craig Mautner | e79d4268 | 2013-04-01 19:01:53 -0700 | [diff] [blame] | 3672 | } |
| 3673 | |
Craig Mautner | 1909125 | 2013-10-05 00:03:53 -0700 | [diff] [blame] | 3674 | return removeHistoryRecordsForAppLocked(app); |
Craig Mautner | e79d4268 | 2013-04-01 19:01:53 -0700 | [diff] [blame] | 3675 | } |
| 3676 | |
Craig Mautner | cae015f | 2013-02-08 14:31:27 -0800 | [diff] [blame] | 3677 | void handleAppCrashLocked(ProcessRecord app) { |
Craig Mautner | d44711d | 2013-02-23 11:24:36 -0800 | [diff] [blame] | 3678 | for (int taskNdx = mTaskHistory.size() - 1; taskNdx >= 0; --taskNdx) { |
| 3679 | final ArrayList<ActivityRecord> activities = mTaskHistory.get(taskNdx).mActivities; |
| 3680 | for (int activityNdx = activities.size() - 1; activityNdx >= 0; --activityNdx) { |
| 3681 | final ActivityRecord r = activities.get(activityNdx); |
| 3682 | if (r.app == app) { |
| 3683 | Slog.w(TAG, " Force finishing activity " |
| 3684 | + r.intent.getComponent().flattenToShortString()); |
Craig Mautner | d232895 | 2013-03-05 12:46:26 -0800 | [diff] [blame] | 3685 | finishActivityLocked(r, Activity.RESULT_CANCELED, null, "crashed", false); |
Craig Mautner | d44711d | 2013-02-23 11:24:36 -0800 | [diff] [blame] | 3686 | } |
Craig Mautner | cae015f | 2013-02-08 14:31:27 -0800 | [diff] [blame] | 3687 | } |
| 3688 | } |
| 3689 | } |
| 3690 | |
Dianne Hackborn | 390517b | 2013-05-30 15:03:32 -0700 | [diff] [blame] | 3691 | boolean dumpActivitiesLocked(FileDescriptor fd, PrintWriter pw, boolean dumpAll, |
Dianne Hackborn | 7ad34e5 | 2013-06-05 18:41:45 -0700 | [diff] [blame] | 3692 | boolean dumpClient, String dumpPackage, boolean needSep, String header) { |
Dianne Hackborn | 390517b | 2013-05-30 15:03:32 -0700 | [diff] [blame] | 3693 | boolean printed = false; |
Craig Mautner | aab647e | 2013-02-28 16:31:36 -0800 | [diff] [blame] | 3694 | for (int taskNdx = mTaskHistory.size() - 1; taskNdx >= 0; --taskNdx) { |
| 3695 | final TaskRecord task = mTaskHistory.get(taskNdx); |
Dianne Hackborn | 390517b | 2013-05-30 15:03:32 -0700 | [diff] [blame] | 3696 | printed |= ActivityStackSupervisor.dumpHistoryList(fd, pw, |
| 3697 | mTaskHistory.get(taskNdx).mActivities, " ", "Hist", true, !dumpAll, |
Dianne Hackborn | 7ad34e5 | 2013-06-05 18:41:45 -0700 | [diff] [blame] | 3698 | dumpClient, dumpPackage, needSep, header, |
Craig Mautner | ac6f843 | 2013-07-17 13:24:59 -0700 | [diff] [blame] | 3699 | " Task id #" + task.taskId); |
Dianne Hackborn | 7ad34e5 | 2013-06-05 18:41:45 -0700 | [diff] [blame] | 3700 | if (printed) { |
| 3701 | header = null; |
| 3702 | } |
Craig Mautner | aab647e | 2013-02-28 16:31:36 -0800 | [diff] [blame] | 3703 | } |
Dianne Hackborn | 390517b | 2013-05-30 15:03:32 -0700 | [diff] [blame] | 3704 | return printed; |
Craig Mautner | cae015f | 2013-02-08 14:31:27 -0800 | [diff] [blame] | 3705 | } |
| 3706 | |
| 3707 | ArrayList<ActivityRecord> getDumpActivitiesLocked(String name) { |
| 3708 | ArrayList<ActivityRecord> activities = new ArrayList<ActivityRecord>(); |
| 3709 | |
| 3710 | if ("all".equals(name)) { |
Craig Mautner | aab647e | 2013-02-28 16:31:36 -0800 | [diff] [blame] | 3711 | for (int taskNdx = mTaskHistory.size() - 1; taskNdx >= 0; --taskNdx) { |
| 3712 | activities.addAll(mTaskHistory.get(taskNdx).mActivities); |
Craig Mautner | cae015f | 2013-02-08 14:31:27 -0800 | [diff] [blame] | 3713 | } |
| 3714 | } else if ("top".equals(name)) { |
Craig Mautner | aab647e | 2013-02-28 16:31:36 -0800 | [diff] [blame] | 3715 | final int top = mTaskHistory.size() - 1; |
| 3716 | if (top >= 0) { |
| 3717 | final ArrayList<ActivityRecord> list = mTaskHistory.get(top).mActivities; |
| 3718 | int listTop = list.size() - 1; |
| 3719 | if (listTop >= 0) { |
| 3720 | activities.add(list.get(listTop)); |
| 3721 | } |
Craig Mautner | cae015f | 2013-02-08 14:31:27 -0800 | [diff] [blame] | 3722 | } |
| 3723 | } else { |
| 3724 | ItemMatcher matcher = new ItemMatcher(); |
| 3725 | matcher.build(name); |
| 3726 | |
Craig Mautner | aab647e | 2013-02-28 16:31:36 -0800 | [diff] [blame] | 3727 | for (int taskNdx = mTaskHistory.size() - 1; taskNdx >= 0; --taskNdx) { |
| 3728 | for (ActivityRecord r1 : mTaskHistory.get(taskNdx).mActivities) { |
| 3729 | if (matcher.match(r1, r1.intent.getComponent())) { |
| 3730 | activities.add(r1); |
| 3731 | } |
Craig Mautner | cae015f | 2013-02-08 14:31:27 -0800 | [diff] [blame] | 3732 | } |
| 3733 | } |
| 3734 | } |
| 3735 | |
| 3736 | return activities; |
| 3737 | } |
| 3738 | |
| 3739 | ActivityRecord restartPackage(String packageName) { |
| 3740 | ActivityRecord starting = topRunningActivityLocked(null); |
| 3741 | |
| 3742 | // All activities that came from the package must be |
| 3743 | // restarted as if there was a config change. |
Craig Mautner | aab647e | 2013-02-28 16:31:36 -0800 | [diff] [blame] | 3744 | for (int taskNdx = mTaskHistory.size() - 1; taskNdx >= 0; --taskNdx) { |
| 3745 | final ArrayList<ActivityRecord> activities = mTaskHistory.get(taskNdx).mActivities; |
| 3746 | for (int activityNdx = activities.size() - 1; activityNdx >= 0; --activityNdx) { |
| 3747 | final ActivityRecord a = activities.get(activityNdx); |
| 3748 | if (a.info.packageName.equals(packageName)) { |
| 3749 | a.forceNewConfig = true; |
| 3750 | if (starting != null && a == starting && a.visible) { |
| 3751 | a.startFreezingScreenLocked(starting.app, |
| 3752 | ActivityInfo.CONFIG_SCREEN_LAYOUT); |
| 3753 | } |
Craig Mautner | cae015f | 2013-02-08 14:31:27 -0800 | [diff] [blame] | 3754 | } |
| 3755 | } |
| 3756 | } |
| 3757 | |
| 3758 | return starting; |
| 3759 | } |
Craig Mautner | 5d9c7be | 2013-02-15 14:02:56 -0800 | [diff] [blame] | 3760 | |
Craig Mautner | 41db4a7 | 2014-05-07 17:20:56 -0700 | [diff] [blame] | 3761 | void removeTask(TaskRecord task) { |
Craig Mautner | aea74a5 | 2014-03-08 14:23:10 -0800 | [diff] [blame] | 3762 | mStackSupervisor.endLockTaskModeIfTaskEnding(task); |
Craig Mautner | 04a0ea6 | 2014-01-13 12:51:26 -0800 | [diff] [blame] | 3763 | mWindowManager.removeTask(task.taskId); |
| 3764 | final ActivityRecord r = mResumedActivity; |
| 3765 | if (r != null && r.task == task) { |
| 3766 | mResumedActivity = null; |
| 3767 | } |
| 3768 | |
Craig Mautner | ae7ecab | 2013-09-18 11:48:14 -0700 | [diff] [blame] | 3769 | final int taskNdx = mTaskHistory.indexOf(task); |
| 3770 | final int topTaskNdx = mTaskHistory.size() - 1; |
Craig Mautner | b9a6c8a | 2014-05-29 16:50:59 +0000 | [diff] [blame] | 3771 | if (task.mOnTopOfHome && taskNdx < topTaskNdx) { |
| 3772 | mTaskHistory.get(taskNdx + 1).mOnTopOfHome = true; |
Craig Mautner | ae7ecab | 2013-09-18 11:48:14 -0700 | [diff] [blame] | 3773 | } |
Craig Mautner | de4ef02 | 2013-04-07 19:01:33 -0700 | [diff] [blame] | 3774 | mTaskHistory.remove(task); |
Craig Mautner | 21d24a2 | 2014-04-23 11:45:37 -0700 | [diff] [blame] | 3775 | updateTaskMovement(task, true); |
Craig Mautner | 41db4a7 | 2014-05-07 17:20:56 -0700 | [diff] [blame] | 3776 | |
| 3777 | if (task.mActivities.isEmpty()) { |
| 3778 | final boolean isVoiceSession = task.voiceSession != null; |
| 3779 | if (isVoiceSession) { |
| 3780 | try { |
| 3781 | task.voiceSession.taskFinished(task.intent, task.taskId); |
| 3782 | } catch (RemoteException e) { |
| 3783 | } |
Dianne Hackborn | c03c916 | 2014-05-02 10:45:59 -0700 | [diff] [blame] | 3784 | } |
Craig Mautner | 41db4a7 | 2014-05-07 17:20:56 -0700 | [diff] [blame] | 3785 | if (task.autoRemoveFromRecents() || isVoiceSession) { |
| 3786 | // Task creator asked to remove this when done, or this task was a voice |
| 3787 | // interaction, so it should not remain on the recent tasks list. |
| 3788 | mService.mRecentTasks.remove(task); |
| 3789 | } |
Dianne Hackborn | 91097de | 2014-04-04 18:02:06 -0700 | [diff] [blame] | 3790 | } |
Craig Mautner | 04a0ea6 | 2014-01-13 12:51:26 -0800 | [diff] [blame] | 3791 | |
| 3792 | if (mTaskHistory.isEmpty()) { |
| 3793 | if (DEBUG_STACK) Slog.i(TAG, "removeTask: moving to back stack=" + this); |
| 3794 | if (isOnHomeDisplay()) { |
| 3795 | mStackSupervisor.moveHomeStack(!isHomeStack()); |
| 3796 | } |
Craig Mautner | 593a4e6 | 2014-01-15 17:55:51 -0800 | [diff] [blame] | 3797 | if (mStacks != null) { |
| 3798 | mStacks.remove(this); |
| 3799 | mStacks.add(0, this); |
| 3800 | } |
Craig Mautner | 04a0ea6 | 2014-01-13 12:51:26 -0800 | [diff] [blame] | 3801 | } |
Craig Mautner | 0247fc8 | 2013-02-28 14:32:06 -0800 | [diff] [blame] | 3802 | } |
| 3803 | |
Dianne Hackborn | 91097de | 2014-04-04 18:02:06 -0700 | [diff] [blame] | 3804 | TaskRecord createTaskRecord(int taskId, ActivityInfo info, Intent intent, |
| 3805 | IVoiceInteractionSession voiceSession, IVoiceInteractor voiceInteractor, |
| 3806 | boolean toTop) { |
Craig Mautner | 21d24a2 | 2014-04-23 11:45:37 -0700 | [diff] [blame] | 3807 | TaskRecord task = new TaskRecord(mService, taskId, info, intent, voiceSession, |
| 3808 | voiceInteractor); |
Dianne Hackborn | c03c916 | 2014-05-02 10:45:59 -0700 | [diff] [blame] | 3809 | addTask(task, toTop, false); |
Craig Mautner | 5d9c7be | 2013-02-15 14:02:56 -0800 | [diff] [blame] | 3810 | return task; |
| 3811 | } |
Craig Mautner | c00204b | 2013-03-05 15:02:14 -0800 | [diff] [blame] | 3812 | |
| 3813 | ArrayList<TaskRecord> getAllTasks() { |
| 3814 | return new ArrayList<TaskRecord>(mTaskHistory); |
| 3815 | } |
| 3816 | |
Dianne Hackborn | c03c916 | 2014-05-02 10:45:59 -0700 | [diff] [blame] | 3817 | void addTask(final TaskRecord task, final boolean toTop, boolean moving) { |
Craig Mautner | c00204b | 2013-03-05 15:02:14 -0800 | [diff] [blame] | 3818 | task.stack = this; |
| 3819 | if (toTop) { |
Craig Mautner | ac6f843 | 2013-07-17 13:24:59 -0700 | [diff] [blame] | 3820 | insertTaskAtTop(task); |
Craig Mautner | c00204b | 2013-03-05 15:02:14 -0800 | [diff] [blame] | 3821 | } else { |
| 3822 | mTaskHistory.add(0, task); |
Craig Mautner | 21d24a2 | 2014-04-23 11:45:37 -0700 | [diff] [blame] | 3823 | updateTaskMovement(task, false); |
Craig Mautner | c00204b | 2013-03-05 15:02:14 -0800 | [diff] [blame] | 3824 | } |
Dianne Hackborn | c03c916 | 2014-05-02 10:45:59 -0700 | [diff] [blame] | 3825 | if (!moving && task.voiceSession != null) { |
| 3826 | try { |
| 3827 | task.voiceSession.taskStarted(task.intent, task.taskId); |
| 3828 | } catch (RemoteException e) { |
| 3829 | } |
| 3830 | } |
Craig Mautner | c00204b | 2013-03-05 15:02:14 -0800 | [diff] [blame] | 3831 | } |
| 3832 | |
| 3833 | public int getStackId() { |
| 3834 | return mStackId; |
| 3835 | } |
Craig Mautner | de4ef02 | 2013-04-07 19:01:33 -0700 | [diff] [blame] | 3836 | |
| 3837 | @Override |
| 3838 | public String toString() { |
Dianne Hackborn | 2a272d4 | 2013-10-16 13:34:33 -0700 | [diff] [blame] | 3839 | return "ActivityStack{" + Integer.toHexString(System.identityHashCode(this)) |
| 3840 | + " stackId=" + mStackId + ", " + mTaskHistory.size() + " tasks}"; |
Craig Mautner | de4ef02 | 2013-04-07 19:01:33 -0700 | [diff] [blame] | 3841 | } |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 3842 | } |