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