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