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