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