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