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