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