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