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