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