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