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