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