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