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