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