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