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