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