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