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