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 | b34a7ad | 2015-08-14 11:05:30 -0700 | [diff] [blame] | 19 | import static android.app.ActivityManager.DOCKED_STACK_ID; |
Wale Ogunwale | 1e3523c | 2015-09-16 13:11:10 -0700 | [diff] [blame] | 20 | import static android.app.ActivityManager.FIRST_STATIC_STACK_ID; |
Wale Ogunwale | 61803ee | 2015-08-07 19:59:47 -0700 | [diff] [blame] | 21 | import static android.app.ActivityManager.FREEFORM_WORKSPACE_STACK_ID; |
Wale Ogunwale | 1e3523c | 2015-09-16 13:11:10 -0700 | [diff] [blame] | 22 | import static android.app.ActivityManager.FULLSCREEN_WORKSPACE_STACK_ID; |
Wale Ogunwale | ddc1cb2 | 2015-07-25 19:23:04 -0700 | [diff] [blame] | 23 | import static android.app.ActivityManager.HOME_STACK_ID; |
Wale Ogunwale | 1e3523c | 2015-09-16 13:11:10 -0700 | [diff] [blame] | 24 | import static android.app.ActivityManager.LAST_STATIC_STACK_ID; |
Wale Ogunwale | 6dfdfd6 | 2015-04-15 12:01:38 -0700 | [diff] [blame] | 25 | import static android.content.pm.ActivityInfo.FLAG_SHOW_FOR_ALL_USERS; |
Wale Ogunwale | 3fcb4a8 | 2015-04-06 14:00:13 -0700 | [diff] [blame] | 26 | |
Wale Ogunwale | e23149f | 2015-03-06 15:39:44 -0800 | [diff] [blame] | 27 | import static com.android.server.am.ActivityManagerDebugConfig.*; |
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 | |
Wale Ogunwale | 040b470 | 2015-08-06 18:10:50 -0700 | [diff] [blame] | 32 | import static com.android.server.am.ActivityStackSupervisor.MOVING; |
| 33 | |
Wale Ogunwale | 706ed79 | 2015-08-02 10:29:44 -0700 | [diff] [blame] | 34 | import android.graphics.Rect; |
Dianne Hackborn | 89ad456 | 2014-08-24 16:45:38 -0700 | [diff] [blame] | 35 | import android.util.ArraySet; |
Wale Ogunwale | 1e3523c | 2015-09-16 13:11:10 -0700 | [diff] [blame] | 36 | |
Dianne Hackborn | 91097de | 2014-04-04 18:02:06 -0700 | [diff] [blame] | 37 | import com.android.internal.app.IVoiceInteractor; |
Dianne Hackborn | 85d558c | 2014-11-04 10:31:54 -0800 | [diff] [blame] | 38 | import com.android.internal.content.ReferrerIntent; |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 39 | import com.android.internal.os.BatteryStatsImpl; |
Kenny Root | add5821 | 2013-05-07 09:47:34 -0700 | [diff] [blame] | 40 | import com.android.server.Watchdog; |
Craig Mautner | cae015f | 2013-02-08 14:31:27 -0800 | [diff] [blame] | 41 | import com.android.server.am.ActivityManagerService.ItemMatcher; |
Craig Mautner | 4a1cb22 | 2013-12-04 16:14:06 -0800 | [diff] [blame] | 42 | import com.android.server.am.ActivityStackSupervisor.ActivityContainer; |
Craig Mautner | 4b71aa1 | 2012-12-27 17:20:01 -0800 | [diff] [blame] | 43 | import com.android.server.wm.AppTransition; |
Craig Mautner | 05d6272ba | 2013-02-11 09:39:27 -0800 | [diff] [blame] | 44 | import com.android.server.wm.TaskGroup; |
Craig Mautner | ce5f3cb | 2013-04-22 08:58:54 -0700 | [diff] [blame] | 45 | import com.android.server.wm.WindowManagerService; |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 46 | |
| 47 | import android.app.Activity; |
Dianne Hackborn | 0c5001d | 2011-04-12 18:16:08 -0700 | [diff] [blame] | 48 | import android.app.ActivityManager; |
Dianne Hackborn | 7a2195c | 2012-03-19 17:38:00 -0700 | [diff] [blame] | 49 | import android.app.ActivityOptions; |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 50 | import android.app.AppGlobals; |
Craig Mautner | 05d6272ba | 2013-02-11 09:39:27 -0800 | [diff] [blame] | 51 | import android.app.IActivityController; |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 52 | import android.app.ResultInfo; |
Craig Mautner | cae015f | 2013-02-08 14:31:27 -0800 | [diff] [blame] | 53 | import android.app.ActivityManager.RunningTaskInfo; |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 54 | import android.content.ComponentName; |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 55 | import android.content.Intent; |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 56 | import android.content.pm.ActivityInfo; |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 57 | import android.content.pm.PackageManager; |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 58 | import android.content.res.Configuration; |
Dianne Hackborn | 0aae2d4 | 2010-12-07 23:51:29 -0800 | [diff] [blame] | 59 | import android.graphics.Bitmap; |
Santos Cordon | 73ff7d8 | 2013-03-06 17:24:11 -0800 | [diff] [blame] | 60 | import android.net.Uri; |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 61 | import android.os.Binder; |
Dianne Hackborn | ce86ba8 | 2011-07-13 19:33:41 -0700 | [diff] [blame] | 62 | import android.os.Bundle; |
Craig Mautner | 329f412 | 2013-11-07 09:10:42 -0800 | [diff] [blame] | 63 | import android.os.Debug; |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 64 | import android.os.Handler; |
| 65 | import android.os.IBinder; |
Zoran Marceta | f958b32 | 2012-08-09 20:27:12 +0900 | [diff] [blame] | 66 | import android.os.Looper; |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 67 | import android.os.Message; |
Craig Mautner | a002604 | 2014-04-23 11:45:37 -0700 | [diff] [blame] | 68 | import android.os.PersistableBundle; |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 69 | import android.os.RemoteException; |
| 70 | import android.os.SystemClock; |
Craig Mautner | 329f412 | 2013-11-07 09:10:42 -0800 | [diff] [blame] | 71 | import android.os.Trace; |
Dianne Hackborn | f02b60a | 2012-08-16 10:48:27 -0700 | [diff] [blame] | 72 | import android.os.UserHandle; |
Craig Mautner | 4c07d02 | 2014-06-11 17:12:59 -0700 | [diff] [blame] | 73 | import android.service.voice.IVoiceInteractionSession; |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 74 | import android.util.EventLog; |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 75 | import android.util.Slog; |
Craig Mautner | 59c0097 | 2012-07-30 12:10:24 -0700 | [diff] [blame] | 76 | import android.view.Display; |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 77 | |
Craig Mautner | cae015f | 2013-02-08 14:31:27 -0800 | [diff] [blame] | 78 | import java.io.FileDescriptor; |
Craig Mautner | cae015f | 2013-02-08 14:31:27 -0800 | [diff] [blame] | 79 | import java.io.PrintWriter; |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 80 | import java.lang.ref.WeakReference; |
| 81 | import java.util.ArrayList; |
| 82 | import java.util.Iterator; |
| 83 | import java.util.List; |
Kenny Root | e6585b3 | 2013-12-13 12:00:26 -0800 | [diff] [blame] | 84 | import java.util.Objects; |
Wale Ogunwale | 540e123 | 2015-05-01 15:35:39 -0700 | [diff] [blame] | 85 | import java.util.Set; |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 86 | |
| 87 | /** |
| 88 | * State and management of a single stack of activities. |
| 89 | */ |
Dianne Hackborn | 0c5001d | 2011-04-12 18:16:08 -0700 | [diff] [blame] | 90 | final class ActivityStack { |
Craig Mautner | 5d9c7be | 2013-02-15 14:02:56 -0800 | [diff] [blame] | 91 | |
Wale Ogunwale | e23149f | 2015-03-06 15:39:44 -0800 | [diff] [blame] | 92 | private static final String TAG = TAG_WITH_CLASS_NAME ? "ActivityStack" : TAG_AM; |
Wale Ogunwale | 0fc365c | 2015-05-25 19:35:42 -0700 | [diff] [blame] | 93 | private static final String TAG_ADD_REMOVE = TAG + POSTFIX_ADD_REMOVE; |
| 94 | private static final String TAG_APP = TAG + POSTFIX_APP; |
Wale Ogunwale | e23149f | 2015-03-06 15:39:44 -0800 | [diff] [blame] | 95 | private static final String TAG_CLEANUP = TAG + POSTFIX_CLEANUP; |
Wale Ogunwale | 3ab9a27 | 2015-03-16 09:55:45 -0700 | [diff] [blame] | 96 | private static final String TAG_CONFIGURATION = TAG + POSTFIX_CONFIGURATION; |
Wale Ogunwale | 0fc365c | 2015-05-25 19:35:42 -0700 | [diff] [blame] | 97 | private static final String TAG_CONTAINERS = TAG + POSTFIX_CONTAINERS; |
Wale Ogunwale | ee006da | 2015-03-30 14:49:25 -0700 | [diff] [blame] | 98 | private static final String TAG_PAUSE = TAG + POSTFIX_PAUSE; |
Wale Ogunwale | 0fc365c | 2015-05-25 19:35:42 -0700 | [diff] [blame] | 99 | private static final String TAG_RELEASE = TAG + POSTFIX_RELEASE; |
Wale Ogunwale | ee006da | 2015-03-30 14:49:25 -0700 | [diff] [blame] | 100 | private static final String TAG_RESULTS = TAG + POSTFIX_RESULTS; |
Wale Ogunwale | 0fc365c | 2015-05-25 19:35:42 -0700 | [diff] [blame] | 101 | private static final String TAG_SAVED_STATE = TAG + POSTFIX_SAVED_STATE; |
| 102 | private static final String TAG_SCREENSHOTS = TAG + POSTFIX_SCREENSHOTS; |
Wale Ogunwale | ee006da | 2015-03-30 14:49:25 -0700 | [diff] [blame] | 103 | private static final String TAG_STACK = TAG + POSTFIX_STACK; |
Wale Ogunwale | 0fc365c | 2015-05-25 19:35:42 -0700 | [diff] [blame] | 104 | private static final String TAG_STATES = TAG + POSTFIX_STATES; |
Wale Ogunwale | ee006da | 2015-03-30 14:49:25 -0700 | [diff] [blame] | 105 | private static final String TAG_SWITCH = TAG + POSTFIX_SWITCH; |
| 106 | private static final String TAG_TASKS = TAG + POSTFIX_TASKS; |
| 107 | private static final String TAG_TRANSITION = TAG + POSTFIX_TRANSITION; |
| 108 | private static final String TAG_USER_LEAVING = TAG + POSTFIX_USER_LEAVING; |
| 109 | private static final String TAG_VISIBILITY = TAG + POSTFIX_VISIBILITY; |
Wale Ogunwale | 3ab9a27 | 2015-03-16 09:55:45 -0700 | [diff] [blame] | 110 | |
| 111 | private static final boolean VALIDATE_TOKENS = false; |
Wale Ogunwale | e23149f | 2015-03-06 15:39:44 -0800 | [diff] [blame] | 112 | |
Dianne Hackborn | 2a29b3a | 2012-03-15 15:48:38 -0700 | [diff] [blame] | 113 | // Ticks during which we check progress while waiting for an app to launch. |
| 114 | static final int LAUNCH_TICK = 500; |
| 115 | |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 116 | // How long we wait until giving up on the last activity to pause. This |
| 117 | // is short because it directly impacts the responsiveness of starting the |
| 118 | // next activity. |
| 119 | static final int PAUSE_TIMEOUT = 500; |
| 120 | |
Dianne Hackborn | 162bc0e | 2012-04-09 14:06:16 -0700 | [diff] [blame] | 121 | // How long we wait for the activity to tell us it has stopped before |
| 122 | // giving up. This is a good amount of time because we really need this |
| 123 | // from the application in order to get its saved state. |
Wale Ogunwale | e4a0c57 | 2015-06-30 08:40:31 -0700 | [diff] [blame] | 124 | static final int STOP_TIMEOUT = 10 * 1000; |
Dianne Hackborn | 162bc0e | 2012-04-09 14:06:16 -0700 | [diff] [blame] | 125 | |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 126 | // How long we wait until giving up on an activity telling us it has |
| 127 | // finished destroying itself. |
Wale Ogunwale | e4a0c57 | 2015-06-30 08:40:31 -0700 | [diff] [blame] | 128 | static final int DESTROY_TIMEOUT = 10 * 1000; |
Craig Mautner | d74f7d7 | 2013-02-26 13:41:02 -0800 | [diff] [blame] | 129 | |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 130 | // 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] | 131 | // disabled. |
| 132 | static final long ACTIVITY_INACTIVE_RESET_TIME = 0; |
Craig Mautner | d74f7d7 | 2013-02-26 13:41:02 -0800 | [diff] [blame] | 133 | |
Dianne Hackborn | 0dad364 | 2010-09-09 21:25:35 -0700 | [diff] [blame] | 134 | // How long between activity launches that we consider safe to not warn |
| 135 | // the user about an unexpected activity being launched on top. |
Wale Ogunwale | e4a0c57 | 2015-06-30 08:40:31 -0700 | [diff] [blame] | 136 | static final long START_WARN_TIME = 5 * 1000; |
Craig Mautner | d74f7d7 | 2013-02-26 13:41:02 -0800 | [diff] [blame] | 137 | |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 138 | // Set to false to disable the preview that is shown while a new activity |
| 139 | // is being started. |
| 140 | static final boolean SHOW_APP_STARTING_PREVIEW = true; |
Craig Mautner | 5d9c7be | 2013-02-15 14:02:56 -0800 | [diff] [blame] | 141 | |
Craig Mautner | 5eda9b3 | 2013-07-02 11:58:16 -0700 | [diff] [blame] | 142 | // How long to wait for all background Activities to redraw following a call to |
| 143 | // convertToTranslucent(). |
| 144 | static final long TRANSLUCENT_CONVERSION_TIMEOUT = 2000; |
| 145 | |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 146 | enum ActivityState { |
| 147 | INITIALIZING, |
| 148 | RESUMED, |
| 149 | PAUSING, |
| 150 | PAUSED, |
| 151 | STOPPING, |
| 152 | STOPPED, |
| 153 | FINISHING, |
| 154 | DESTROYING, |
| 155 | DESTROYED |
| 156 | } |
| 157 | |
| 158 | final ActivityManagerService mService; |
Craig Mautner | ce5f3cb | 2013-04-22 08:58:54 -0700 | [diff] [blame] | 159 | final WindowManagerService mWindowManager; |
Wale Ogunwale | c82f2f5 | 2014-12-09 09:32:50 -0800 | [diff] [blame] | 160 | private final RecentTasks mRecentTasks; |
Craig Mautner | d74f7d7 | 2013-02-26 13:41:02 -0800 | [diff] [blame] | 161 | |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 162 | /** |
| 163 | * The back history of all previous (and possibly still |
Craig Mautner | 5d9c7be | 2013-02-15 14:02:56 -0800 | [diff] [blame] | 164 | * running) activities. It contains #TaskRecord objects. |
| 165 | */ |
Wale Ogunwale | 53a29a9 | 2015-02-23 15:42:52 -0800 | [diff] [blame] | 166 | private ArrayList<TaskRecord> mTaskHistory = new ArrayList<>(); |
Craig Mautner | 5d9c7be | 2013-02-15 14:02:56 -0800 | [diff] [blame] | 167 | |
| 168 | /** |
Dianne Hackborn | be70785 | 2011-11-11 14:32:10 -0800 | [diff] [blame] | 169 | * Used for validating app tokens with window manager. |
| 170 | */ |
Wale Ogunwale | 53a29a9 | 2015-02-23 15:42:52 -0800 | [diff] [blame] | 171 | final ArrayList<TaskGroup> mValidateAppTokens = new ArrayList<>(); |
Dianne Hackborn | be70785 | 2011-11-11 14:32:10 -0800 | [diff] [blame] | 172 | |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 173 | /** |
| 174 | * List of running activities, sorted by recent usage. |
| 175 | * The first entry in the list is the least recently used. |
| 176 | * It contains HistoryRecord objects. |
| 177 | */ |
Wale Ogunwale | 53a29a9 | 2015-02-23 15:42:52 -0800 | [diff] [blame] | 178 | final ArrayList<ActivityRecord> mLRUActivities = new ArrayList<>(); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 179 | |
| 180 | /** |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 181 | * Animations that for the current transition have requested not to |
| 182 | * be considered for the transition animation. |
| 183 | */ |
Wale Ogunwale | 53a29a9 | 2015-02-23 15:42:52 -0800 | [diff] [blame] | 184 | final ArrayList<ActivityRecord> mNoAnimActivities = new ArrayList<>(); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 185 | |
| 186 | /** |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 187 | * When we are in the process of pausing an activity, before starting the |
| 188 | * next one, this variable holds the activity that is currently being paused. |
| 189 | */ |
Dianne Hackborn | 621e2fe | 2012-02-16 17:07:33 -0800 | [diff] [blame] | 190 | ActivityRecord mPausingActivity = null; |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 191 | |
| 192 | /** |
| 193 | * This is the last activity that we put into the paused state. This is |
| 194 | * used to determine if we need to do an activity transition while sleeping, |
| 195 | * when we normally hold the top activity paused. |
| 196 | */ |
| 197 | ActivityRecord mLastPausedActivity = null; |
| 198 | |
| 199 | /** |
Craig Mautner | 0f92274 | 2013-08-06 08:44:42 -0700 | [diff] [blame] | 200 | * Activities that specify No History must be removed once the user navigates away from them. |
| 201 | * If the device goes to sleep with such an activity in the paused state then we save it here |
| 202 | * and finish it later if another activity replaces it on wakeup. |
| 203 | */ |
| 204 | ActivityRecord mLastNoHistoryActivity = null; |
| 205 | |
| 206 | /** |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 207 | * Current activity that is resumed, or null if there is none. |
| 208 | */ |
| 209 | ActivityRecord mResumedActivity = null; |
Craig Mautner | d74f7d7 | 2013-02-26 13:41:02 -0800 | [diff] [blame] | 210 | |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 211 | /** |
Dianne Hackborn | 0dad364 | 2010-09-09 21:25:35 -0700 | [diff] [blame] | 212 | * This is the last activity that has been started. It is only used to |
| 213 | * identify when multiple activities are started at once so that the user |
| 214 | * can be warned they may not be in the activity they think they are. |
| 215 | */ |
| 216 | ActivityRecord mLastStartedActivity = null; |
Craig Mautner | d74f7d7 | 2013-02-26 13:41:02 -0800 | [diff] [blame] | 217 | |
Craig Mautner | 5eda9b3 | 2013-07-02 11:58:16 -0700 | [diff] [blame] | 218 | // The topmost Activity passed to convertToTranslucent(). When non-null it means we are |
| 219 | // waiting for all Activities in mUndrawnActivitiesBelowTopTranslucent to be removed as they |
| 220 | // are drawn. When the last member of mUndrawnActivitiesBelowTopTranslucent is removed the |
| 221 | // Activity in mTranslucentActivityWaiting is notified via |
| 222 | // Activity.onTranslucentConversionComplete(false). If a timeout occurs prior to the last |
| 223 | // background activity being drawn then the same call will be made with a true value. |
| 224 | ActivityRecord mTranslucentActivityWaiting = null; |
Wale Ogunwale | e4a0c57 | 2015-06-30 08:40:31 -0700 | [diff] [blame] | 225 | private ArrayList<ActivityRecord> mUndrawnActivitiesBelowTopTranslucent = new ArrayList<>(); |
Craig Mautner | 5eda9b3 | 2013-07-02 11:58:16 -0700 | [diff] [blame] | 226 | |
Dianne Hackborn | 0dad364 | 2010-09-09 21:25:35 -0700 | [diff] [blame] | 227 | /** |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 228 | * Set when we know we are going to be calling updateConfiguration() |
| 229 | * soon, so want to skip intermediate config checks. |
| 230 | */ |
| 231 | boolean mConfigWillChange; |
| 232 | |
Wale Ogunwale | e4a0c57 | 2015-06-30 08:40:31 -0700 | [diff] [blame] | 233 | // Whether or not this stack covers the entire screen; by default stacks are fullscreen |
Todd Kennedy | aab56db | 2015-01-30 09:39:53 -0800 | [diff] [blame] | 234 | boolean mFullscreen = true; |
Wale Ogunwale | b34a7ad | 2015-08-14 11:05:30 -0700 | [diff] [blame] | 235 | // Current bounds of the stack or null if fullscreen. |
| 236 | Rect mBounds = null; |
Todd Kennedy | aab56db | 2015-01-30 09:39:53 -0800 | [diff] [blame] | 237 | |
Dianne Hackborn | 2286cdc | 2013-07-01 19:10:06 -0700 | [diff] [blame] | 238 | long mLaunchStartTime = 0; |
| 239 | long mFullyDrawnStartTime = 0; |
Craig Mautner | d74f7d7 | 2013-02-26 13:41:02 -0800 | [diff] [blame] | 240 | |
Craig Mautner | 858d8a6 | 2013-04-23 17:08:34 -0700 | [diff] [blame] | 241 | int mCurrentUser; |
Amith Yamasani | 742a671 | 2011-05-04 14:49:28 -0700 | [diff] [blame] | 242 | |
Craig Mautner | c00204b | 2013-03-05 15:02:14 -0800 | [diff] [blame] | 243 | final int mStackId; |
Craig Mautner | 4a1cb22 | 2013-12-04 16:14:06 -0800 | [diff] [blame] | 244 | final ActivityContainer mActivityContainer; |
Craig Mautner | e0a3884 | 2013-12-16 16:14:02 -0800 | [diff] [blame] | 245 | /** The other stacks, in order, on the attached display. Updated at attach/detach time. */ |
| 246 | ArrayList<ActivityStack> mStacks; |
| 247 | /** The attached Display's unique identifier, or -1 if detached */ |
| 248 | int mDisplayId; |
Craig Mautner | 4a1cb22 | 2013-12-04 16:14:06 -0800 | [diff] [blame] | 249 | |
Craig Mautner | 2708430 | 2013-03-25 08:05:25 -0700 | [diff] [blame] | 250 | /** Run all ActivityStacks through this */ |
| 251 | final ActivityStackSupervisor mStackSupervisor; |
| 252 | |
Filip Gruszczynski | e5390e7 | 2015-08-18 16:39:00 -0700 | [diff] [blame] | 253 | private final LaunchingTaskPositioner mTaskPositioner; |
| 254 | |
Craig Mautner | 7ea5bd4 | 2013-07-05 15:27:08 -0700 | [diff] [blame] | 255 | static final int PAUSE_TIMEOUT_MSG = ActivityManagerService.FIRST_ACTIVITY_STACK_MSG + 1; |
Craig Mautner | 0eea92c | 2013-05-16 13:35:39 -0700 | [diff] [blame] | 256 | static final int DESTROY_TIMEOUT_MSG = ActivityManagerService.FIRST_ACTIVITY_STACK_MSG + 2; |
| 257 | static final int LAUNCH_TICK_MSG = ActivityManagerService.FIRST_ACTIVITY_STACK_MSG + 3; |
| 258 | static final int STOP_TIMEOUT_MSG = ActivityManagerService.FIRST_ACTIVITY_STACK_MSG + 4; |
| 259 | static final int DESTROY_ACTIVITIES_MSG = ActivityManagerService.FIRST_ACTIVITY_STACK_MSG + 5; |
Craig Mautner | 5eda9b3 | 2013-07-02 11:58:16 -0700 | [diff] [blame] | 260 | static final int TRANSLUCENT_TIMEOUT_MSG = ActivityManagerService.FIRST_ACTIVITY_STACK_MSG + 6; |
Jose Lima | 4b6c669 | 2014-08-12 17:41:12 -0700 | [diff] [blame] | 261 | static final int RELEASE_BACKGROUND_RESOURCES_TIMEOUT_MSG = |
Craig Mautner | ee2e45a | 2014-06-27 12:10:03 -0700 | [diff] [blame] | 262 | ActivityManagerService.FIRST_ACTIVITY_STACK_MSG + 7; |
Dianne Hackborn | 755c8bf | 2012-05-07 15:06:09 -0700 | [diff] [blame] | 263 | |
| 264 | static class ScheduleDestroyArgs { |
| 265 | final ProcessRecord mOwner; |
Dianne Hackborn | 755c8bf | 2012-05-07 15:06:09 -0700 | [diff] [blame] | 266 | final String mReason; |
Craig Mautner | ee2e45a | 2014-06-27 12:10:03 -0700 | [diff] [blame] | 267 | ScheduleDestroyArgs(ProcessRecord owner, String reason) { |
Dianne Hackborn | 755c8bf | 2012-05-07 15:06:09 -0700 | [diff] [blame] | 268 | mOwner = owner; |
Dianne Hackborn | 755c8bf | 2012-05-07 15:06:09 -0700 | [diff] [blame] | 269 | mReason = reason; |
| 270 | } |
| 271 | } |
| 272 | |
Zoran Marceta | f958b32 | 2012-08-09 20:27:12 +0900 | [diff] [blame] | 273 | final Handler mHandler; |
| 274 | |
| 275 | final class ActivityStackHandler extends Handler { |
Wale Ogunwale | e23149f | 2015-03-06 15:39:44 -0800 | [diff] [blame] | 276 | |
Craig Mautner | c8143c6 | 2013-09-03 12:15:57 -0700 | [diff] [blame] | 277 | ActivityStackHandler(Looper looper) { |
Zoran Marceta | f958b32 | 2012-08-09 20:27:12 +0900 | [diff] [blame] | 278 | super(looper); |
| 279 | } |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 280 | |
Zoran Marceta | f958b32 | 2012-08-09 20:27:12 +0900 | [diff] [blame] | 281 | @Override |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 282 | public void handleMessage(Message msg) { |
| 283 | switch (msg.what) { |
| 284 | case PAUSE_TIMEOUT_MSG: { |
Dianne Hackborn | be70785 | 2011-11-11 14:32:10 -0800 | [diff] [blame] | 285 | ActivityRecord r = (ActivityRecord)msg.obj; |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 286 | // We don't at this point know if the activity is fullscreen, |
| 287 | // so we need to be conservative and assume it isn't. |
Dianne Hackborn | be70785 | 2011-11-11 14:32:10 -0800 | [diff] [blame] | 288 | Slog.w(TAG, "Activity pause timeout for " + r); |
Dianne Hackborn | 2a29b3a | 2012-03-15 15:48:38 -0700 | [diff] [blame] | 289 | synchronized (mService) { |
| 290 | if (r.app != null) { |
Craig Mautner | f7bfefb | 2013-05-16 17:30:44 -0700 | [diff] [blame] | 291 | mService.logAppTooSlow(r.app, r.pauseTime, "pausing " + r); |
Dianne Hackborn | 2a29b3a | 2012-03-15 15:48:38 -0700 | [diff] [blame] | 292 | } |
Dianne Hackborn | a4e102e | 2014-09-04 22:52:27 -0700 | [diff] [blame] | 293 | activityPausedLocked(r.appToken, true); |
Craig Mautner | d232895 | 2013-03-05 12:46:26 -0800 | [diff] [blame] | 294 | } |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 295 | } break; |
Dianne Hackborn | 2a29b3a | 2012-03-15 15:48:38 -0700 | [diff] [blame] | 296 | case LAUNCH_TICK_MSG: { |
| 297 | ActivityRecord r = (ActivityRecord)msg.obj; |
| 298 | synchronized (mService) { |
| 299 | if (r.continueLaunchTickingLocked()) { |
Craig Mautner | f7bfefb | 2013-05-16 17:30:44 -0700 | [diff] [blame] | 300 | mService.logAppTooSlow(r.app, r.launchTickTime, "launching " + r); |
Dianne Hackborn | 2a29b3a | 2012-03-15 15:48:38 -0700 | [diff] [blame] | 301 | } |
| 302 | } |
| 303 | } break; |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 304 | case DESTROY_TIMEOUT_MSG: { |
Dianne Hackborn | be70785 | 2011-11-11 14:32:10 -0800 | [diff] [blame] | 305 | ActivityRecord r = (ActivityRecord)msg.obj; |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 306 | // We don't at this point know if the activity is fullscreen, |
| 307 | // so we need to be conservative and assume it isn't. |
Dianne Hackborn | be70785 | 2011-11-11 14:32:10 -0800 | [diff] [blame] | 308 | Slog.w(TAG, "Activity destroy timeout for " + r); |
Craig Mautner | d232895 | 2013-03-05 12:46:26 -0800 | [diff] [blame] | 309 | synchronized (mService) { |
Craig Mautner | 299f960 | 2015-01-26 09:47:33 -0800 | [diff] [blame] | 310 | activityDestroyedLocked(r != null ? r.appToken : null, "destroyTimeout"); |
Craig Mautner | d232895 | 2013-03-05 12:46:26 -0800 | [diff] [blame] | 311 | } |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 312 | } break; |
Dianne Hackborn | 162bc0e | 2012-04-09 14:06:16 -0700 | [diff] [blame] | 313 | case STOP_TIMEOUT_MSG: { |
| 314 | ActivityRecord r = (ActivityRecord)msg.obj; |
| 315 | // We don't at this point know if the activity is fullscreen, |
| 316 | // so we need to be conservative and assume it isn't. |
| 317 | Slog.w(TAG, "Activity stop timeout for " + r); |
| 318 | synchronized (mService) { |
| 319 | if (r.isInHistory()) { |
| 320 | activityStoppedLocked(r, null, null, null); |
| 321 | } |
| 322 | } |
| 323 | } break; |
Dianne Hackborn | 755c8bf | 2012-05-07 15:06:09 -0700 | [diff] [blame] | 324 | case DESTROY_ACTIVITIES_MSG: { |
| 325 | ScheduleDestroyArgs args = (ScheduleDestroyArgs)msg.obj; |
| 326 | synchronized (mService) { |
Craig Mautner | ee2e45a | 2014-06-27 12:10:03 -0700 | [diff] [blame] | 327 | destroyActivitiesLocked(args.mOwner, args.mReason); |
Dianne Hackborn | 755c8bf | 2012-05-07 15:06:09 -0700 | [diff] [blame] | 328 | } |
Craig Mautner | 5eda9b3 | 2013-07-02 11:58:16 -0700 | [diff] [blame] | 329 | } break; |
| 330 | case TRANSLUCENT_TIMEOUT_MSG: { |
| 331 | synchronized (mService) { |
| 332 | notifyActivityDrawnLocked(null); |
| 333 | } |
| 334 | } break; |
Jose Lima | 4b6c669 | 2014-08-12 17:41:12 -0700 | [diff] [blame] | 335 | case RELEASE_BACKGROUND_RESOURCES_TIMEOUT_MSG: { |
Craig Mautner | ee2e45a | 2014-06-27 12:10:03 -0700 | [diff] [blame] | 336 | synchronized (mService) { |
Jose Lima | 4b6c669 | 2014-08-12 17:41:12 -0700 | [diff] [blame] | 337 | final ActivityRecord r = getVisibleBehindActivity(); |
| 338 | Slog.e(TAG, "Timeout waiting for cancelVisibleBehind player=" + r); |
Craig Mautner | ee2e45a | 2014-06-27 12:10:03 -0700 | [diff] [blame] | 339 | if (r != null) { |
| 340 | mService.killAppAtUsersRequest(r.app, null); |
| 341 | } |
| 342 | } |
| 343 | } break; |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 344 | } |
| 345 | } |
Craig Mautner | 4b71aa1 | 2012-12-27 17:20:01 -0800 | [diff] [blame] | 346 | } |
| 347 | |
Craig Mautner | 34b73df | 2014-01-12 21:11:08 -0800 | [diff] [blame] | 348 | int numActivities() { |
Craig Mautner | 000f002 | 2013-02-26 15:04:29 -0800 | [diff] [blame] | 349 | int count = 0; |
| 350 | for (int taskNdx = mTaskHistory.size() - 1; taskNdx >= 0; --taskNdx) { |
| 351 | count += mTaskHistory.get(taskNdx).mActivities.size(); |
| 352 | } |
| 353 | return count; |
| 354 | } |
| 355 | |
Wale Ogunwale | 53a29a9 | 2015-02-23 15:42:52 -0800 | [diff] [blame] | 356 | int numTasks() { |
| 357 | return mTaskHistory.size(); |
| 358 | } |
| 359 | |
Wale Ogunwale | c82f2f5 | 2014-12-09 09:32:50 -0800 | [diff] [blame] | 360 | ActivityStack(ActivityStackSupervisor.ActivityContainer activityContainer, |
| 361 | RecentTasks recentTasks) { |
Craig Mautner | 4a1cb22 | 2013-12-04 16:14:06 -0800 | [diff] [blame] | 362 | mActivityContainer = activityContainer; |
| 363 | mStackSupervisor = activityContainer.getOuter(); |
| 364 | mService = mStackSupervisor.mService; |
| 365 | mHandler = new ActivityStackHandler(mService.mHandler.getLooper()); |
| 366 | mWindowManager = mService.mWindowManager; |
| 367 | mStackId = activityContainer.mStackId; |
| 368 | mCurrentUser = mService.mCurrentUserId; |
Wale Ogunwale | c82f2f5 | 2014-12-09 09:32:50 -0800 | [diff] [blame] | 369 | mRecentTasks = recentTasks; |
Filip Gruszczynski | e5390e7 | 2015-08-18 16:39:00 -0700 | [diff] [blame] | 370 | mTaskPositioner = mStackId == FREEFORM_WORKSPACE_STACK_ID |
| 371 | ? new LaunchingTaskPositioner() : null; |
| 372 | } |
| 373 | |
| 374 | void attachDisplay(ActivityStackSupervisor.ActivityDisplay activityDisplay, boolean onTop) { |
| 375 | mDisplayId = activityDisplay.mDisplayId; |
| 376 | mStacks = activityDisplay.mStacks; |
| 377 | mBounds = mWindowManager.attachStack(mStackId, activityDisplay.mDisplayId, onTop); |
| 378 | mFullscreen = mBounds == null; |
| 379 | if (mTaskPositioner != null) { |
| 380 | mTaskPositioner.setDisplay(activityDisplay.mDisplay); |
| 381 | mTaskPositioner.configure(mBounds); |
| 382 | } |
| 383 | } |
| 384 | |
| 385 | void detachDisplay() { |
| 386 | mDisplayId = Display.INVALID_DISPLAY; |
| 387 | mStacks = null; |
| 388 | if (mTaskPositioner != null) { |
| 389 | mTaskPositioner.reset(); |
| 390 | } |
| 391 | mWindowManager.detachStack(mStackId); |
| 392 | } |
| 393 | |
| 394 | void setBounds(Rect bounds) { |
| 395 | mBounds = mFullscreen ? null : new Rect(bounds); |
Filip Gruszczynski | 9ac01a7 | 2015-09-04 11:12:17 -0700 | [diff] [blame] | 396 | if (mTaskPositioner != null) { |
| 397 | mTaskPositioner.configure(bounds); |
| 398 | } |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 399 | } |
Craig Mautner | 5962b12 | 2012-10-05 14:45:52 -0700 | [diff] [blame] | 400 | |
Amith Yamasani | 734983f | 2014-03-04 16:48:05 -0800 | [diff] [blame] | 401 | boolean okToShowLocked(ActivityRecord r) { |
Chong Zhang | 45c25ce | 2015-08-10 22:18:26 -0700 | [diff] [blame] | 402 | return mStackSupervisor.okToShowLocked(r); |
Craig Mautner | 5962b12 | 2012-10-05 14:45:52 -0700 | [diff] [blame] | 403 | } |
| 404 | |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 405 | final ActivityRecord topRunningActivityLocked(ActivityRecord notTop) { |
Craig Mautner | d74f7d7 | 2013-02-26 13:41:02 -0800 | [diff] [blame] | 406 | for (int taskNdx = mTaskHistory.size() - 1; taskNdx >= 0; --taskNdx) { |
Craig Mautner | 6b74cb5 | 2013-09-27 17:02:21 -0700 | [diff] [blame] | 407 | ActivityRecord r = mTaskHistory.get(taskNdx).topRunningActivityLocked(notTop); |
| 408 | if (r != null) { |
| 409 | return r; |
Craig Mautner | 11bf9a5 | 2013-02-19 14:08:51 -0800 | [diff] [blame] | 410 | } |
| 411 | } |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 412 | return null; |
| 413 | } |
| 414 | |
| 415 | final ActivityRecord topRunningNonDelayedActivityLocked(ActivityRecord notTop) { |
Craig Mautner | d74f7d7 | 2013-02-26 13:41:02 -0800 | [diff] [blame] | 416 | for (int taskNdx = mTaskHistory.size() - 1; taskNdx >= 0; --taskNdx) { |
| 417 | final TaskRecord task = mTaskHistory.get(taskNdx); |
Craig Mautner | 11bf9a5 | 2013-02-19 14:08:51 -0800 | [diff] [blame] | 418 | final ArrayList<ActivityRecord> activities = task.mActivities; |
Craig Mautner | d74f7d7 | 2013-02-26 13:41:02 -0800 | [diff] [blame] | 419 | for (int activityNdx = activities.size() - 1; activityNdx >= 0; --activityNdx) { |
| 420 | ActivityRecord r = activities.get(activityNdx); |
Amith Yamasani | 734983f | 2014-03-04 16:48:05 -0800 | [diff] [blame] | 421 | if (!r.finishing && !r.delayedResume && r != notTop && okToShowLocked(r)) { |
Craig Mautner | 11bf9a5 | 2013-02-19 14:08:51 -0800 | [diff] [blame] | 422 | return r; |
| 423 | } |
| 424 | } |
| 425 | } |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 426 | return null; |
| 427 | } |
| 428 | |
| 429 | /** |
| 430 | * This is a simplified version of topRunningActivityLocked that provides a number of |
| 431 | * 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] | 432 | * |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 433 | * @param token If non-null, any history records matching this token will be skipped. |
| 434 | * @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] | 435 | * |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 436 | * @return Returns the HistoryRecord of the next activity on the stack. |
| 437 | */ |
| 438 | final ActivityRecord topRunningActivityLocked(IBinder token, int taskId) { |
Craig Mautner | 11bf9a5 | 2013-02-19 14:08:51 -0800 | [diff] [blame] | 439 | for (int taskNdx = mTaskHistory.size() - 1; taskNdx >= 0; --taskNdx) { |
| 440 | TaskRecord task = mTaskHistory.get(taskNdx); |
| 441 | if (task.taskId == taskId) { |
| 442 | continue; |
| 443 | } |
| 444 | ArrayList<ActivityRecord> activities = task.mActivities; |
| 445 | for (int i = activities.size() - 1; i >= 0; --i) { |
| 446 | final ActivityRecord r = activities.get(i); |
| 447 | // Note: the taskId check depends on real taskId fields being non-zero |
Amith Yamasani | 734983f | 2014-03-04 16:48:05 -0800 | [diff] [blame] | 448 | if (!r.finishing && (token != r.appToken) && okToShowLocked(r)) { |
Craig Mautner | 11bf9a5 | 2013-02-19 14:08:51 -0800 | [diff] [blame] | 449 | return r; |
| 450 | } |
| 451 | } |
| 452 | } |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 453 | return null; |
| 454 | } |
| 455 | |
Craig Mautner | 8849a5e | 2013-04-02 16:41:03 -0700 | [diff] [blame] | 456 | final ActivityRecord topActivity() { |
Craig Mautner | 8849a5e | 2013-04-02 16:41:03 -0700 | [diff] [blame] | 457 | for (int taskNdx = mTaskHistory.size() - 1; taskNdx >= 0; --taskNdx) { |
| 458 | ArrayList<ActivityRecord> activities = mTaskHistory.get(taskNdx).mActivities; |
Craig Mautner | 0175b88 | 2014-09-07 18:05:31 -0700 | [diff] [blame] | 459 | for (int activityNdx = activities.size() - 1; activityNdx >= 0; --activityNdx) { |
| 460 | final ActivityRecord r = activities.get(activityNdx); |
| 461 | if (!r.finishing) { |
| 462 | return r; |
| 463 | } |
Craig Mautner | 8849a5e | 2013-04-02 16:41:03 -0700 | [diff] [blame] | 464 | } |
| 465 | } |
Craig Mautner | de4ef02 | 2013-04-07 19:01:33 -0700 | [diff] [blame] | 466 | return null; |
Craig Mautner | 8849a5e | 2013-04-02 16:41:03 -0700 | [diff] [blame] | 467 | } |
| 468 | |
Craig Mautner | 9e14d0f | 2013-05-01 11:26:09 -0700 | [diff] [blame] | 469 | final TaskRecord topTask() { |
| 470 | final int size = mTaskHistory.size(); |
| 471 | if (size > 0) { |
| 472 | return mTaskHistory.get(size - 1); |
| 473 | } |
| 474 | return null; |
| 475 | } |
| 476 | |
Craig Mautner | d232895 | 2013-03-05 12:46:26 -0800 | [diff] [blame] | 477 | TaskRecord taskForIdLocked(int id) { |
| 478 | for (int taskNdx = mTaskHistory.size() - 1; taskNdx >= 0; --taskNdx) { |
| 479 | final TaskRecord task = mTaskHistory.get(taskNdx); |
| 480 | if (task.taskId == id) { |
| 481 | return task; |
Craig Mautner | 5d9c7be | 2013-02-15 14:02:56 -0800 | [diff] [blame] | 482 | } |
| 483 | } |
Dianne Hackborn | ce86ba8 | 2011-07-13 19:33:41 -0700 | [diff] [blame] | 484 | return null; |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 485 | } |
| 486 | |
Craig Mautner | d232895 | 2013-03-05 12:46:26 -0800 | [diff] [blame] | 487 | ActivityRecord isInStackLocked(IBinder token) { |
Wale Ogunwale | 7d70117 | 2015-03-11 15:36:30 -0700 | [diff] [blame] | 488 | final ActivityRecord r = ActivityRecord.forTokenLocked(token); |
Wale Ogunwale | 60454db | 2015-01-23 16:05:07 -0800 | [diff] [blame] | 489 | return isInStackLocked(r); |
| 490 | } |
| 491 | |
| 492 | ActivityRecord isInStackLocked(ActivityRecord r) { |
| 493 | if (r == null) { |
| 494 | return null; |
| 495 | } |
| 496 | final TaskRecord task = r.task; |
Wale Ogunwale | 7d70117 | 2015-03-11 15:36:30 -0700 | [diff] [blame] | 497 | if (task != null && task.stack != null |
| 498 | && task.mActivities.contains(r) && mTaskHistory.contains(task)) { |
Wale Ogunwale | 60454db | 2015-01-23 16:05:07 -0800 | [diff] [blame] | 499 | if (task.stack != this) Slog.w(TAG, |
Craig Mautner | d232895 | 2013-03-05 12:46:26 -0800 | [diff] [blame] | 500 | "Illegal state! task does not point to stack it is in."); |
Wale Ogunwale | 60454db | 2015-01-23 16:05:07 -0800 | [diff] [blame] | 501 | return r; |
Craig Mautner | 5d9c7be | 2013-02-15 14:02:56 -0800 | [diff] [blame] | 502 | } |
Craig Mautner | d232895 | 2013-03-05 12:46:26 -0800 | [diff] [blame] | 503 | return null; |
Craig Mautner | 5d9c7be | 2013-02-15 14:02:56 -0800 | [diff] [blame] | 504 | } |
| 505 | |
Craig Mautner | 2420ead | 2013-04-01 17:13:20 -0700 | [diff] [blame] | 506 | final boolean updateLRUListLocked(ActivityRecord r) { |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 507 | final boolean hadit = mLRUActivities.remove(r); |
| 508 | mLRUActivities.add(r); |
| 509 | return hadit; |
| 510 | } |
| 511 | |
Craig Mautner | de4ef02 | 2013-04-07 19:01:33 -0700 | [diff] [blame] | 512 | final boolean isHomeStack() { |
| 513 | return mStackId == HOME_STACK_ID; |
| 514 | } |
| 515 | |
Craig Mautner | e0a3884 | 2013-12-16 16:14:02 -0800 | [diff] [blame] | 516 | final boolean isOnHomeDisplay() { |
| 517 | return isAttached() && |
| 518 | mActivityContainer.mActivityDisplay.mDisplayId == Display.DEFAULT_DISPLAY; |
| 519 | } |
| 520 | |
Wale Ogunwale | eae451e | 2015-08-04 15:20:50 -0700 | [diff] [blame] | 521 | void moveToFront(String reason) { |
| 522 | moveToFront(reason, null); |
| 523 | } |
| 524 | |
| 525 | /** |
| 526 | * @param reason The reason for moving the stack to the front. |
| 527 | * @param task If non-null, the task will be moved to the top of the stack. |
| 528 | * */ |
| 529 | void moveToFront(String reason, TaskRecord task) { |
Craig Mautner | e0a3884 | 2013-12-16 16:14:02 -0800 | [diff] [blame] | 530 | if (isAttached()) { |
Wale Ogunwale | 925d0d1 | 2015-09-23 15:40:07 -0700 | [diff] [blame^] | 531 | final ActivityStack lastFocusStack = mStacks.get(mStacks.size() - 1); |
| 532 | // Need to move this stack to the front before calling |
| 533 | // {@link ActivityStackSupervisor#setFocusStack} below. |
| 534 | mStacks.remove(this); |
| 535 | mStacks.add(this); |
| 536 | |
| 537 | // TODO(multi-display): 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] | 538 | if (isOnHomeDisplay()) { |
Wale Ogunwale | 925d0d1 | 2015-09-23 15:40:07 -0700 | [diff] [blame^] | 539 | mStackSupervisor.setFocusStack(reason, lastFocusStack); |
Wale Ogunwale | cb82f30 | 2015-02-25 07:53:40 -0800 | [diff] [blame] | 540 | } |
Wale Ogunwale | eae451e | 2015-08-04 15:20:50 -0700 | [diff] [blame] | 541 | if (task != null) { |
| 542 | insertTaskAtTop(task, null); |
| 543 | } else { |
| 544 | task = topTask(); |
| 545 | } |
Craig Mautner | 6b904ef | 2014-12-17 15:45:03 -0800 | [diff] [blame] | 546 | if (task != null) { |
| 547 | mWindowManager.moveTaskToTop(task.taskId); |
| 548 | } |
Craig Mautner | 4a1cb22 | 2013-12-04 16:14:06 -0800 | [diff] [blame] | 549 | } |
Craig Mautner | e0a3884 | 2013-12-16 16:14:02 -0800 | [diff] [blame] | 550 | } |
| 551 | |
| 552 | final boolean isAttached() { |
| 553 | return mStacks != null; |
Craig Mautner | 4a1cb22 | 2013-12-04 16:14:06 -0800 | [diff] [blame] | 554 | } |
| 555 | |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 556 | /** |
| 557 | * Returns the top activity in any existing task matching the given |
| 558 | * Intent. Returns null if no such task is found. |
| 559 | */ |
Craig Mautner | ac6f843 | 2013-07-17 13:24:59 -0700 | [diff] [blame] | 560 | ActivityRecord findTaskLocked(ActivityRecord target) { |
| 561 | Intent intent = target.intent; |
| 562 | ActivityInfo info = target.info; |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 563 | ComponentName cls = intent.getComponent(); |
| 564 | if (info.targetActivity != null) { |
| 565 | cls = new ComponentName(info.packageName, info.targetActivity); |
| 566 | } |
Dianne Hackborn | f02b60a | 2012-08-16 10:48:27 -0700 | [diff] [blame] | 567 | final int userId = UserHandle.getUserId(info.applicationInfo.uid); |
Craig Mautner | d00f474 | 2014-03-12 14:17:26 -0700 | [diff] [blame] | 568 | boolean isDocument = intent != null & intent.isDocument(); |
| 569 | // If documentData is non-null then it must match the existing task data. |
| 570 | Uri documentData = isDocument ? intent.getData() : null; |
Craig Mautner | 000f002 | 2013-02-26 15:04:29 -0800 | [diff] [blame] | 571 | |
Wale Ogunwale | ee006da | 2015-03-30 14:49:25 -0700 | [diff] [blame] | 572 | if (DEBUG_TASKS) Slog.d(TAG_TASKS, "Looking for task of " + target + " in " + this); |
Craig Mautner | 000f002 | 2013-02-26 15:04:29 -0800 | [diff] [blame] | 573 | for (int taskNdx = mTaskHistory.size() - 1; taskNdx >= 0; --taskNdx) { |
| 574 | final TaskRecord task = mTaskHistory.get(taskNdx); |
Dianne Hackborn | 91097de | 2014-04-04 18:02:06 -0700 | [diff] [blame] | 575 | if (task.voiceSession != null) { |
| 576 | // We never match voice sessions; those always run independently. |
Wale Ogunwale | ee006da | 2015-03-30 14:49:25 -0700 | [diff] [blame] | 577 | if (DEBUG_TASKS) Slog.d(TAG_TASKS, "Skipping " + task + ": voice session"); |
Dianne Hackborn | 91097de | 2014-04-04 18:02:06 -0700 | [diff] [blame] | 578 | continue; |
| 579 | } |
Craig Mautner | ac6f843 | 2013-07-17 13:24:59 -0700 | [diff] [blame] | 580 | if (task.userId != userId) { |
| 581 | // Looking for a different task. |
Wale Ogunwale | ee006da | 2015-03-30 14:49:25 -0700 | [diff] [blame] | 582 | if (DEBUG_TASKS) Slog.d(TAG_TASKS, "Skipping " + task + ": different user"); |
Craig Mautner | ac6f843 | 2013-07-17 13:24:59 -0700 | [diff] [blame] | 583 | continue; |
| 584 | } |
Craig Mautner | 000f002 | 2013-02-26 15:04:29 -0800 | [diff] [blame] | 585 | final ActivityRecord r = task.getTopActivity(); |
| 586 | if (r == null || r.finishing || r.userId != userId || |
| 587 | r.launchMode == ActivityInfo.LAUNCH_SINGLE_INSTANCE) { |
Wale Ogunwale | ee006da | 2015-03-30 14:49:25 -0700 | [diff] [blame] | 588 | if (DEBUG_TASKS) Slog.d(TAG_TASKS, "Skipping " + task + ": mismatch root " + r); |
Craig Mautner | 000f002 | 2013-02-26 15:04:29 -0800 | [diff] [blame] | 589 | continue; |
| 590 | } |
Chong Zhang | b546f7e | 2015-08-05 14:21:36 -0700 | [diff] [blame] | 591 | if (r.mActivityType != target.mActivityType) { |
| 592 | if (DEBUG_TASKS) Slog.d(TAG_TASKS, "Skipping " + task + ": mismatch activity type"); |
| 593 | continue; |
| 594 | } |
Craig Mautner | 000f002 | 2013-02-26 15:04:29 -0800 | [diff] [blame] | 595 | |
Craig Mautner | d00f474 | 2014-03-12 14:17:26 -0700 | [diff] [blame] | 596 | final Intent taskIntent = task.intent; |
| 597 | final Intent affinityIntent = task.affinityIntent; |
| 598 | final boolean taskIsDocument; |
| 599 | final Uri taskDocumentData; |
| 600 | if (taskIntent != null && taskIntent.isDocument()) { |
| 601 | taskIsDocument = true; |
| 602 | taskDocumentData = taskIntent.getData(); |
| 603 | } else if (affinityIntent != null && affinityIntent.isDocument()) { |
| 604 | taskIsDocument = true; |
| 605 | taskDocumentData = affinityIntent.getData(); |
| 606 | } else { |
| 607 | taskIsDocument = false; |
| 608 | taskDocumentData = null; |
| 609 | } |
| 610 | |
Wale Ogunwale | ee006da | 2015-03-30 14:49:25 -0700 | [diff] [blame] | 611 | if (DEBUG_TASKS) Slog.d(TAG_TASKS, "Comparing existing cls=" |
Craig Mautner | d00f474 | 2014-03-12 14:17:26 -0700 | [diff] [blame] | 612 | + taskIntent.getComponent().flattenToShortString() |
Dianne Hackborn | 7922882 | 2014-09-16 11:11:23 -0700 | [diff] [blame] | 613 | + "/aff=" + r.task.rootAffinity + " to new cls=" |
Dianne Hackborn | 2a272d4 | 2013-10-16 13:34:33 -0700 | [diff] [blame] | 614 | + intent.getComponent().flattenToShortString() + "/aff=" + info.taskAffinity); |
Dianne Hackborn | 7922882 | 2014-09-16 11:11:23 -0700 | [diff] [blame] | 615 | if (!isDocument && !taskIsDocument && task.rootAffinity != null) { |
| 616 | if (task.rootAffinity.equals(target.taskAffinity)) { |
Wale Ogunwale | ee006da | 2015-03-30 14:49:25 -0700 | [diff] [blame] | 617 | if (DEBUG_TASKS) Slog.d(TAG_TASKS, "Found matching affinity!"); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 618 | return r; |
| 619 | } |
Craig Mautner | ffcfcaa | 2014-06-05 09:54:38 -0700 | [diff] [blame] | 620 | } else if (taskIntent != null && taskIntent.getComponent() != null && |
| 621 | taskIntent.getComponent().compareTo(cls) == 0 && |
Craig Mautner | d00f474 | 2014-03-12 14:17:26 -0700 | [diff] [blame] | 622 | Objects.equals(documentData, taskDocumentData)) { |
Wale Ogunwale | ee006da | 2015-03-30 14:49:25 -0700 | [diff] [blame] | 623 | if (DEBUG_TASKS) Slog.d(TAG_TASKS, "Found matching class!"); |
Craig Mautner | 000f002 | 2013-02-26 15:04:29 -0800 | [diff] [blame] | 624 | //dump(); |
Wale Ogunwale | ee006da | 2015-03-30 14:49:25 -0700 | [diff] [blame] | 625 | if (DEBUG_TASKS) Slog.d(TAG_TASKS, |
| 626 | "For Intent " + intent + " bringing to top: " + r.intent); |
Craig Mautner | 000f002 | 2013-02-26 15:04:29 -0800 | [diff] [blame] | 627 | return r; |
Craig Mautner | ffcfcaa | 2014-06-05 09:54:38 -0700 | [diff] [blame] | 628 | } else if (affinityIntent != null && affinityIntent.getComponent() != null && |
| 629 | affinityIntent.getComponent().compareTo(cls) == 0 && |
Craig Mautner | d00f474 | 2014-03-12 14:17:26 -0700 | [diff] [blame] | 630 | Objects.equals(documentData, taskDocumentData)) { |
Wale Ogunwale | ee006da | 2015-03-30 14:49:25 -0700 | [diff] [blame] | 631 | if (DEBUG_TASKS) Slog.d(TAG_TASKS, "Found matching class!"); |
Craig Mautner | 000f002 | 2013-02-26 15:04:29 -0800 | [diff] [blame] | 632 | //dump(); |
Wale Ogunwale | ee006da | 2015-03-30 14:49:25 -0700 | [diff] [blame] | 633 | if (DEBUG_TASKS) Slog.d(TAG_TASKS, |
| 634 | "For Intent " + intent + " bringing to top: " + r.intent); |
Craig Mautner | 000f002 | 2013-02-26 15:04:29 -0800 | [diff] [blame] | 635 | return r; |
Wale Ogunwale | ee006da | 2015-03-30 14:49:25 -0700 | [diff] [blame] | 636 | } else if (DEBUG_TASKS) Slog.d(TAG_TASKS, "Not a match: " + task); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 637 | } |
| 638 | |
| 639 | return null; |
| 640 | } |
| 641 | |
| 642 | /** |
| 643 | * Returns the first activity (starting from the top of the stack) that |
| 644 | * is the same as the given activity. Returns null if no such activity |
| 645 | * is found. |
| 646 | */ |
Craig Mautner | 8849a5e | 2013-04-02 16:41:03 -0700 | [diff] [blame] | 647 | ActivityRecord findActivityLocked(Intent intent, ActivityInfo info) { |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 648 | ComponentName cls = intent.getComponent(); |
| 649 | if (info.targetActivity != null) { |
| 650 | cls = new ComponentName(info.packageName, info.targetActivity); |
| 651 | } |
Dianne Hackborn | f02b60a | 2012-08-16 10:48:27 -0700 | [diff] [blame] | 652 | final int userId = UserHandle.getUserId(info.applicationInfo.uid); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 653 | |
Craig Mautner | 000f002 | 2013-02-26 15:04:29 -0800 | [diff] [blame] | 654 | for (int taskNdx = mTaskHistory.size() - 1; taskNdx >= 0; --taskNdx) { |
Wale Ogunwale | 3fcb4a8 | 2015-04-06 14:00:13 -0700 | [diff] [blame] | 655 | final TaskRecord task = mTaskHistory.get(taskNdx); |
Wale Ogunwale | 0bd2aa7 | 2015-04-16 13:50:44 -0700 | [diff] [blame] | 656 | final boolean notCurrentUserTask = |
| 657 | !mStackSupervisor.isCurrentProfileLocked(task.userId); |
Craig Mautner | ac6f843 | 2013-07-17 13:24:59 -0700 | [diff] [blame] | 658 | final ArrayList<ActivityRecord> activities = task.mActivities; |
Wale Ogunwale | 3fcb4a8 | 2015-04-06 14:00:13 -0700 | [diff] [blame] | 659 | |
Craig Mautner | 000f002 | 2013-02-26 15:04:29 -0800 | [diff] [blame] | 660 | for (int activityNdx = activities.size() - 1; activityNdx >= 0; --activityNdx) { |
| 661 | ActivityRecord r = activities.get(activityNdx); |
Wale Ogunwale | 6dfdfd6 | 2015-04-15 12:01:38 -0700 | [diff] [blame] | 662 | if (notCurrentUserTask && (r.info.flags & FLAG_SHOW_FOR_ALL_USERS) == 0) { |
Wale Ogunwale | 25073dd | 2015-07-21 16:54:54 -0700 | [diff] [blame] | 663 | continue; |
Wale Ogunwale | 3fcb4a8 | 2015-04-06 14:00:13 -0700 | [diff] [blame] | 664 | } |
Craig Mautner | 000f002 | 2013-02-26 15:04:29 -0800 | [diff] [blame] | 665 | if (!r.finishing && r.intent.getComponent().equals(cls) && r.userId == userId) { |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 666 | return r; |
| 667 | } |
| 668 | } |
| 669 | } |
| 670 | |
| 671 | return null; |
| 672 | } |
| 673 | |
Amith Yamasani | 742a671 | 2011-05-04 14:49:28 -0700 | [diff] [blame] | 674 | /* |
Craig Mautner | ac6f843 | 2013-07-17 13:24:59 -0700 | [diff] [blame] | 675 | * 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] | 676 | */ |
Craig Mautner | 93529a4 | 2013-10-04 15:03:13 -0700 | [diff] [blame] | 677 | final void switchUserLocked(int userId) { |
Craig Mautner | 5d9c7be | 2013-02-15 14:02:56 -0800 | [diff] [blame] | 678 | if (mCurrentUser == userId) { |
Craig Mautner | 93529a4 | 2013-10-04 15:03:13 -0700 | [diff] [blame] | 679 | return; |
Craig Mautner | 5d9c7be | 2013-02-15 14:02:56 -0800 | [diff] [blame] | 680 | } |
| 681 | mCurrentUser = userId; |
| 682 | |
| 683 | // Move userId's tasks to the top. |
Craig Mautner | 5d9c7be | 2013-02-15 14:02:56 -0800 | [diff] [blame] | 684 | int index = mTaskHistory.size(); |
Craig Mautner | db5c4fb | 2013-11-06 13:55:08 -0800 | [diff] [blame] | 685 | for (int i = 0; i < index; ) { |
Wale Ogunwale | 3fcb4a8 | 2015-04-06 14:00:13 -0700 | [diff] [blame] | 686 | final TaskRecord task = mTaskHistory.get(i); |
| 687 | |
| 688 | // NOTE: If {@link TaskRecord#topRunningActivityLocked} return is not null then it is |
| 689 | // okay to show the activity when locked. |
Wale Ogunwale | 0bd2aa7 | 2015-04-16 13:50:44 -0700 | [diff] [blame] | 690 | if (mStackSupervisor.isCurrentProfileLocked(task.userId) |
Wale Ogunwale | 3fcb4a8 | 2015-04-06 14:00:13 -0700 | [diff] [blame] | 691 | || task.topRunningActivityLocked(null) != null) { |
Wale Ogunwale | ee006da | 2015-03-30 14:49:25 -0700 | [diff] [blame] | 692 | if (DEBUG_TASKS) Slog.d(TAG_TASKS, "switchUserLocked: stack=" + getStackId() + |
Craig Mautner | 4f1df4f | 2013-10-15 15:44:14 -0700 | [diff] [blame] | 693 | " moving " + task + " to top"); |
Craig Mautner | 5d9c7be | 2013-02-15 14:02:56 -0800 | [diff] [blame] | 694 | mTaskHistory.remove(i); |
| 695 | mTaskHistory.add(task); |
| 696 | --index; |
Craig Mautner | db5c4fb | 2013-11-06 13:55:08 -0800 | [diff] [blame] | 697 | // Use same value for i. |
| 698 | } else { |
| 699 | ++i; |
Craig Mautner | 5d9c7be | 2013-02-15 14:02:56 -0800 | [diff] [blame] | 700 | } |
| 701 | } |
Craig Mautner | 4f1df4f | 2013-10-15 15:44:14 -0700 | [diff] [blame] | 702 | if (VALIDATE_TOKENS) { |
| 703 | validateAppTokensLocked(); |
| 704 | } |
Amith Yamasani | 742a671 | 2011-05-04 14:49:28 -0700 | [diff] [blame] | 705 | } |
| 706 | |
Craig Mautner | 2420ead | 2013-04-01 17:13:20 -0700 | [diff] [blame] | 707 | void minimalResumeActivityLocked(ActivityRecord r) { |
| 708 | r.state = ActivityState.RESUMED; |
Wale Ogunwale | 0fc365c | 2015-05-25 19:35:42 -0700 | [diff] [blame] | 709 | if (DEBUG_STATES) Slog.v(TAG_STATES, |
| 710 | "Moving to RESUMED: " + r + " (starting new instance)"); |
Craig Mautner | 2420ead | 2013-04-01 17:13:20 -0700 | [diff] [blame] | 711 | r.stopped = false; |
| 712 | mResumedActivity = r; |
| 713 | r.task.touchActiveTime(); |
Wale Ogunwale | c82f2f5 | 2014-12-09 09:32:50 -0800 | [diff] [blame] | 714 | mRecentTasks.addLocked(r.task); |
Craig Mautner | 2420ead | 2013-04-01 17:13:20 -0700 | [diff] [blame] | 715 | completeResumeLocked(r); |
Craig Mautner | 0eea92c | 2013-05-16 13:35:39 -0700 | [diff] [blame] | 716 | mStackSupervisor.checkReadyForSleepLocked(); |
Craig Mautner | 1e8b872 | 2013-10-14 18:24:52 -0700 | [diff] [blame] | 717 | setLaunchTime(r); |
Wale Ogunwale | 0fc365c | 2015-05-25 19:35:42 -0700 | [diff] [blame] | 718 | if (DEBUG_SAVED_STATE) Slog.i(TAG_SAVED_STATE, |
| 719 | "Launch completed; removing icicle of " + r.icicle); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 720 | } |
| 721 | |
Chong Zhang | 45c25ce | 2015-08-10 22:18:26 -0700 | [diff] [blame] | 722 | private void addRecentActivityLocked(ActivityRecord r) { |
| 723 | if (r != null) { |
| 724 | mRecentTasks.addLocked(r.task); |
| 725 | r.task.touchActiveTime(); |
| 726 | } |
| 727 | } |
| 728 | |
Narayan Kamath | 7829c81 | 2015-06-08 17:39:43 +0100 | [diff] [blame] | 729 | private void startLaunchTraces(String packageName) { |
Dianne Hackborn | cee04b5 | 2013-07-03 17:01:28 -0700 | [diff] [blame] | 730 | if (mFullyDrawnStartTime != 0) { |
| 731 | Trace.asyncTraceEnd(Trace.TRACE_TAG_ACTIVITY_MANAGER, "drawing", 0); |
| 732 | } |
Narayan Kamath | 7829c81 | 2015-06-08 17:39:43 +0100 | [diff] [blame] | 733 | Trace.asyncTraceBegin(Trace.TRACE_TAG_ACTIVITY_MANAGER, "launching: " + packageName, 0); |
Dianne Hackborn | cee04b5 | 2013-07-03 17:01:28 -0700 | [diff] [blame] | 734 | Trace.asyncTraceBegin(Trace.TRACE_TAG_ACTIVITY_MANAGER, "drawing", 0); |
| 735 | } |
| 736 | |
| 737 | private void stopFullyDrawnTraceIfNeeded() { |
| 738 | if (mFullyDrawnStartTime != 0 && mLaunchStartTime == 0) { |
| 739 | Trace.asyncTraceEnd(Trace.TRACE_TAG_ACTIVITY_MANAGER, "drawing", 0); |
| 740 | mFullyDrawnStartTime = 0; |
| 741 | } |
| 742 | } |
| 743 | |
Craig Mautner | e79d4268 | 2013-04-01 19:01:53 -0700 | [diff] [blame] | 744 | void setLaunchTime(ActivityRecord r) { |
Dianne Hackborn | 2286cdc | 2013-07-01 19:10:06 -0700 | [diff] [blame] | 745 | if (r.displayStartTime == 0) { |
| 746 | r.fullyDrawnStartTime = r.displayStartTime = SystemClock.uptimeMillis(); |
| 747 | if (mLaunchStartTime == 0) { |
Narayan Kamath | 7829c81 | 2015-06-08 17:39:43 +0100 | [diff] [blame] | 748 | startLaunchTraces(r.packageName); |
Dianne Hackborn | 2286cdc | 2013-07-01 19:10:06 -0700 | [diff] [blame] | 749 | mLaunchStartTime = mFullyDrawnStartTime = r.displayStartTime; |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 750 | } |
Dianne Hackborn | 2286cdc | 2013-07-01 19:10:06 -0700 | [diff] [blame] | 751 | } else if (mLaunchStartTime == 0) { |
Narayan Kamath | 7829c81 | 2015-06-08 17:39:43 +0100 | [diff] [blame] | 752 | startLaunchTraces(r.packageName); |
Dianne Hackborn | 2286cdc | 2013-07-01 19:10:06 -0700 | [diff] [blame] | 753 | mLaunchStartTime = mFullyDrawnStartTime = SystemClock.uptimeMillis(); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 754 | } |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 755 | } |
Craig Mautner | aab647e | 2013-02-28 16:31:36 -0800 | [diff] [blame] | 756 | |
Dianne Hackborn | 2286cdc | 2013-07-01 19:10:06 -0700 | [diff] [blame] | 757 | void clearLaunchTime(ActivityRecord r) { |
Craig Mautner | 5c49454 | 2013-09-06 11:59:38 -0700 | [diff] [blame] | 758 | // Make sure that there is no activity waiting for this to launch. |
| 759 | if (mStackSupervisor.mWaitingActivityLaunched.isEmpty()) { |
| 760 | r.displayStartTime = r.fullyDrawnStartTime = 0; |
| 761 | } else { |
| 762 | mStackSupervisor.removeTimeoutsForActivityLocked(r); |
| 763 | mStackSupervisor.scheduleIdleTimeoutLocked(r); |
| 764 | } |
Dianne Hackborn | 2286cdc | 2013-07-01 19:10:06 -0700 | [diff] [blame] | 765 | } |
| 766 | |
Dianne Hackborn | 4eba96b | 2011-01-21 13:34:36 -0800 | [diff] [blame] | 767 | void awakeFromSleepingLocked() { |
Dianne Hackborn | 4eba96b | 2011-01-21 13:34:36 -0800 | [diff] [blame] | 768 | // Ensure activities are no longer sleeping. |
Craig Mautner | d44711d | 2013-02-23 11:24:36 -0800 | [diff] [blame] | 769 | for (int taskNdx = mTaskHistory.size() - 1; taskNdx >= 0; --taskNdx) { |
| 770 | final ArrayList<ActivityRecord> activities = mTaskHistory.get(taskNdx).mActivities; |
| 771 | for (int activityNdx = activities.size() - 1; activityNdx >= 0; --activityNdx) { |
| 772 | activities.get(activityNdx).setSleeping(false); |
| 773 | } |
Dianne Hackborn | 4eba96b | 2011-01-21 13:34:36 -0800 | [diff] [blame] | 774 | } |
Craig Mautner | f49b0a4 | 2014-11-20 15:06:40 -0800 | [diff] [blame] | 775 | if (mPausingActivity != null) { |
| 776 | Slog.d(TAG, "awakeFromSleepingLocked: previously pausing activity didn't pause"); |
| 777 | activityPausedLocked(mPausingActivity.appToken, true); |
| 778 | } |
Dianne Hackborn | 4eba96b | 2011-01-21 13:34:36 -0800 | [diff] [blame] | 779 | } |
| 780 | |
Craig Mautner | 0eea92c | 2013-05-16 13:35:39 -0700 | [diff] [blame] | 781 | /** |
| 782 | * @return true if something must be done before going to sleep. |
| 783 | */ |
| 784 | boolean checkReadyForSleepLocked() { |
| 785 | if (mResumedActivity != null) { |
| 786 | // Still have something resumed; can't sleep until it is paused. |
Wale Ogunwale | ee006da | 2015-03-30 14:49:25 -0700 | [diff] [blame] | 787 | if (DEBUG_PAUSE) Slog.v(TAG_PAUSE, "Sleep needs to pause " + mResumedActivity); |
| 788 | if (DEBUG_USER_LEAVING) Slog.v(TAG_USER_LEAVING, |
| 789 | "Sleep => pause with userLeaving=false"); |
Dianne Hackborn | a4e102e | 2014-09-04 22:52:27 -0700 | [diff] [blame] | 790 | startPausingLocked(false, true, false, false); |
Craig Mautner | 0eea92c | 2013-05-16 13:35:39 -0700 | [diff] [blame] | 791 | return true; |
| 792 | } |
| 793 | if (mPausingActivity != null) { |
| 794 | // Still waiting for something to pause; can't sleep yet. |
Wale Ogunwale | ee006da | 2015-03-30 14:49:25 -0700 | [diff] [blame] | 795 | if (DEBUG_PAUSE) Slog.v(TAG_PAUSE, "Sleep still waiting to pause " + mPausingActivity); |
Craig Mautner | 0eea92c | 2013-05-16 13:35:39 -0700 | [diff] [blame] | 796 | return true; |
Dianne Hackborn | 4eba96b | 2011-01-21 13:34:36 -0800 | [diff] [blame] | 797 | } |
| 798 | |
Wale Ogunwale | 5c42e50 | 2015-04-08 09:18:54 -0700 | [diff] [blame] | 799 | if (hasVisibleBehindActivity()) { |
| 800 | // Stop visible behind activity before going to sleep. |
| 801 | final ActivityRecord r = mActivityContainer.mActivityDisplay.mVisibleBehindActivity; |
| 802 | mStackSupervisor.mStoppingActivities.add(r); |
Wale Ogunwale | 0fc365c | 2015-05-25 19:35:42 -0700 | [diff] [blame] | 803 | if (DEBUG_STATES) Slog.v(TAG_STATES, |
| 804 | "Sleep still waiting to stop visible behind " + r); |
Wale Ogunwale | 5c42e50 | 2015-04-08 09:18:54 -0700 | [diff] [blame] | 805 | return true; |
| 806 | } |
| 807 | |
Craig Mautner | 0eea92c | 2013-05-16 13:35:39 -0700 | [diff] [blame] | 808 | return false; |
| 809 | } |
Dianne Hackborn | 4eba96b | 2011-01-21 13:34:36 -0800 | [diff] [blame] | 810 | |
Craig Mautner | 0eea92c | 2013-05-16 13:35:39 -0700 | [diff] [blame] | 811 | void goToSleep() { |
| 812 | ensureActivitiesVisibleLocked(null, 0); |
Dianne Hackborn | 4eba96b | 2011-01-21 13:34:36 -0800 | [diff] [blame] | 813 | |
Craig Mautner | 0eea92c | 2013-05-16 13:35:39 -0700 | [diff] [blame] | 814 | // Make sure any stopped but visible activities are now sleeping. |
| 815 | // This ensures that the activity's onStop() is called. |
| 816 | for (int taskNdx = mTaskHistory.size() - 1; taskNdx >= 0; --taskNdx) { |
| 817 | final ArrayList<ActivityRecord> activities = mTaskHistory.get(taskNdx).mActivities; |
| 818 | for (int activityNdx = activities.size() - 1; activityNdx >= 0; --activityNdx) { |
| 819 | final ActivityRecord r = activities.get(activityNdx); |
| 820 | if (r.state == ActivityState.STOPPING || r.state == ActivityState.STOPPED) { |
| 821 | r.setSleeping(true); |
Dianne Hackborn | 4eba96b | 2011-01-21 13:34:36 -0800 | [diff] [blame] | 822 | } |
| 823 | } |
Dianne Hackborn | 4eba96b | 2011-01-21 13:34:36 -0800 | [diff] [blame] | 824 | } |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 825 | } |
Craig Mautner | 59c0097 | 2012-07-30 12:10:24 -0700 | [diff] [blame] | 826 | |
Dianne Hackborn | d283593 | 2010-12-13 16:28:46 -0800 | [diff] [blame] | 827 | public final Bitmap screenshotActivities(ActivityRecord who) { |
Wale Ogunwale | 0fc365c | 2015-05-25 19:35:42 -0700 | [diff] [blame] | 828 | if (DEBUG_SCREENSHOTS) Slog.d(TAG_SCREENSHOTS, "screenshotActivities: " + who); |
Dianne Hackborn | ff801ec | 2011-01-22 18:05:38 -0800 | [diff] [blame] | 829 | if (who.noDisplay) { |
Wale Ogunwale | 0fc365c | 2015-05-25 19:35:42 -0700 | [diff] [blame] | 830 | if (DEBUG_SCREENSHOTS) Slog.d(TAG_SCREENSHOTS, "\tNo display"); |
Dianne Hackborn | ff801ec | 2011-01-22 18:05:38 -0800 | [diff] [blame] | 831 | return null; |
| 832 | } |
Craig Mautner | aab647e | 2013-02-28 16:31:36 -0800 | [diff] [blame] | 833 | |
Winson Chung | 083baf9 | 2014-07-11 10:32:42 -0700 | [diff] [blame] | 834 | if (isHomeStack()) { |
Winson Chung | 376543b | 2014-05-21 17:43:28 -0700 | [diff] [blame] | 835 | // 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] | 836 | // we can just go ahead and skip taking the screenshot if this is the home stack. |
Wale Ogunwale | 0fc365c | 2015-05-25 19:35:42 -0700 | [diff] [blame] | 837 | if (DEBUG_SCREENSHOTS) Slog.d(TAG_SCREENSHOTS, "\tHome stack"); |
Dianne Hackborn | 4d03fe6 | 2013-10-04 17:26:37 -0700 | [diff] [blame] | 838 | return null; |
| 839 | } |
| 840 | |
Winson Chung | 48a10a5 | 2014-08-27 14:36:51 -0700 | [diff] [blame] | 841 | int w = mService.mThumbnailWidth; |
| 842 | int h = mService.mThumbnailHeight; |
Dianne Hackborn | 0aae2d4 | 2010-12-07 23:51:29 -0800 | [diff] [blame] | 843 | if (w > 0) { |
Wale Ogunwale | 0fc365c | 2015-05-25 19:35:42 -0700 | [diff] [blame] | 844 | if (DEBUG_SCREENSHOTS) Slog.d(TAG_SCREENSHOTS, "\tTaking screenshot"); |
Wale Ogunwale | eacdf2c | 2014-12-09 14:02:27 -0800 | [diff] [blame] | 845 | return mWindowManager.screenshotApplications(who.appToken, Display.DEFAULT_DISPLAY, |
Dianne Hackborn | 27eac1d | 2015-03-16 17:15:53 -0700 | [diff] [blame] | 846 | w, h); |
Dianne Hackborn | 0aae2d4 | 2010-12-07 23:51:29 -0800 | [diff] [blame] | 847 | } |
Winson Chung | 376543b | 2014-05-21 17:43:28 -0700 | [diff] [blame] | 848 | Slog.e(TAG, "Invalid thumbnail dimensions: " + w + "x" + h); |
Dianne Hackborn | 0aae2d4 | 2010-12-07 23:51:29 -0800 | [diff] [blame] | 849 | return null; |
| 850 | } |
| 851 | |
Dianne Hackborn | a4e102e | 2014-09-04 22:52:27 -0700 | [diff] [blame] | 852 | /** |
| 853 | * Start pausing the currently resumed activity. It is an error to call this if there |
| 854 | * is already an activity being paused or there is no resumed activity. |
| 855 | * |
| 856 | * @param userLeaving True if this should result in an onUserLeaving to the current activity. |
| 857 | * @param uiSleeping True if this is happening with the user interface going to sleep (the |
| 858 | * screen turning off). |
| 859 | * @param resuming True if this is being called as part of resuming the top activity, so |
| 860 | * we shouldn't try to instigate a resume here. |
| 861 | * @param dontWait True if the caller does not want to wait for the pause to complete. If |
| 862 | * set to true, we will immediately complete the pause here before returning. |
| 863 | * @return Returns true if an activity now is in the PAUSING state, and we are waiting for |
| 864 | * it to tell us when it is done. |
| 865 | */ |
| 866 | final boolean startPausingLocked(boolean userLeaving, boolean uiSleeping, boolean resuming, |
| 867 | boolean dontWait) { |
Dianne Hackborn | 621e2fe | 2012-02-16 17:07:33 -0800 | [diff] [blame] | 868 | if (mPausingActivity != null) { |
riddle_hsu | 7dfe4d7 | 2015-02-16 18:43:49 +0800 | [diff] [blame] | 869 | Slog.wtf(TAG, "Going to pause when pause is already pending for " + mPausingActivity |
| 870 | + " state=" + mPausingActivity.state); |
| 871 | if (!mService.isSleeping()) { |
| 872 | // Avoid recursion among check for sleep and complete pause during sleeping. |
| 873 | // Because activity will be paused immediately after resume, just let pause |
| 874 | // be completed by the order of activity paused from clients. |
| 875 | completePauseLocked(false); |
| 876 | } |
Dianne Hackborn | 621e2fe | 2012-02-16 17:07:33 -0800 | [diff] [blame] | 877 | } |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 878 | ActivityRecord prev = mResumedActivity; |
| 879 | if (prev == null) { |
Dianne Hackborn | a4e102e | 2014-09-04 22:52:27 -0700 | [diff] [blame] | 880 | if (!resuming) { |
| 881 | Slog.wtf(TAG, "Trying to pause when nothing is resumed"); |
| 882 | mStackSupervisor.resumeTopActivitiesLocked(); |
| 883 | } |
| 884 | return false; |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 885 | } |
Craig Mautner | df88d73 | 2014-01-27 09:21:32 -0800 | [diff] [blame] | 886 | |
| 887 | if (mActivityContainer.mParentActivity == null) { |
| 888 | // Top level stack, not a child. Look for child stacks. |
Dianne Hackborn | a4e102e | 2014-09-04 22:52:27 -0700 | [diff] [blame] | 889 | mStackSupervisor.pauseChildStacks(prev, userLeaving, uiSleeping, resuming, dontWait); |
Craig Mautner | df88d73 | 2014-01-27 09:21:32 -0800 | [diff] [blame] | 890 | } |
| 891 | |
Wale Ogunwale | 0fc365c | 2015-05-25 19:35:42 -0700 | [diff] [blame] | 892 | if (DEBUG_STATES) Slog.v(TAG_STATES, "Moving to PAUSING: " + prev); |
Wale Ogunwale | ee006da | 2015-03-30 14:49:25 -0700 | [diff] [blame] | 893 | else if (DEBUG_PAUSE) Slog.v(TAG_PAUSE, "Start pausing: " + prev); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 894 | mResumedActivity = null; |
Dianne Hackborn | 621e2fe | 2012-02-16 17:07:33 -0800 | [diff] [blame] | 895 | mPausingActivity = prev; |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 896 | mLastPausedActivity = prev; |
Craig Mautner | 0f92274 | 2013-08-06 08:44:42 -0700 | [diff] [blame] | 897 | mLastNoHistoryActivity = (prev.intent.getFlags() & Intent.FLAG_ACTIVITY_NO_HISTORY) != 0 |
| 898 | || (prev.info.flags & ActivityInfo.FLAG_NO_HISTORY) != 0 ? prev : null; |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 899 | prev.state = ActivityState.PAUSING; |
| 900 | prev.task.touchActiveTime(); |
Dianne Hackborn | 2286cdc | 2013-07-01 19:10:06 -0700 | [diff] [blame] | 901 | clearLaunchTime(prev); |
Craig Mautner | 6f6d56f | 2013-10-24 16:02:07 -0700 | [diff] [blame] | 902 | final ActivityRecord next = mStackSupervisor.topRunningActivityLocked(); |
Skuhne | 17690ff | 2015-08-27 09:47:20 -0700 | [diff] [blame] | 903 | // In freeform mode we only update the thumbnail when there is no thumbnail yet since every |
| 904 | // focus change will request a thumbnail to be taken. |
| 905 | // Note furthermore that since windows can change their content in freeform mode all the |
| 906 | // time a thumbnail is possibly constantly outdated. |
| 907 | if (mService.mHasRecents && |
| 908 | (next == null || next.noDisplay || next.task != prev.task || uiSleeping) && |
| 909 | (!prev.task.hasThumbnail() || |
| 910 | prev.task.stack.mStackId != FREEFORM_WORKSPACE_STACK_ID)) { |
Winson Chung | 740c3ac | 2014-11-12 16:14:38 -0800 | [diff] [blame] | 911 | prev.updateThumbnailLocked(screenshotActivities(prev), null); |
Craig Mautner | 6f6d56f | 2013-10-24 16:02:07 -0700 | [diff] [blame] | 912 | } |
Dianne Hackborn | cee04b5 | 2013-07-03 17:01:28 -0700 | [diff] [blame] | 913 | stopFullyDrawnTraceIfNeeded(); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 914 | |
| 915 | mService.updateCpuStats(); |
Craig Mautner | aab647e | 2013-02-28 16:31:36 -0800 | [diff] [blame] | 916 | |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 917 | if (prev.app != null && prev.app.thread != null) { |
Wale Ogunwale | ee006da | 2015-03-30 14:49:25 -0700 | [diff] [blame] | 918 | if (DEBUG_PAUSE) Slog.v(TAG_PAUSE, "Enqueueing pending pause: " + prev); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 919 | try { |
| 920 | EventLog.writeEvent(EventLogTags.AM_PAUSE_ACTIVITY, |
Dianne Hackborn | b12e135 | 2012-09-26 11:39:20 -0700 | [diff] [blame] | 921 | prev.userId, System.identityHashCode(prev), |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 922 | prev.shortComponentName); |
Jeff Sharkey | 5782da7 | 2013-04-25 14:32:30 -0700 | [diff] [blame] | 923 | mService.updateUsageStats(prev, false); |
Dianne Hackborn | be70785 | 2011-11-11 14:32:10 -0800 | [diff] [blame] | 924 | prev.app.thread.schedulePauseActivity(prev.appToken, prev.finishing, |
Dianne Hackborn | a4e102e | 2014-09-04 22:52:27 -0700 | [diff] [blame] | 925 | userLeaving, prev.configChangeFlags, dontWait); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 926 | } catch (Exception e) { |
| 927 | // Ignore exception, if process died other code will cleanup. |
| 928 | Slog.w(TAG, "Exception thrown during pause", e); |
Dianne Hackborn | 621e2fe | 2012-02-16 17:07:33 -0800 | [diff] [blame] | 929 | mPausingActivity = null; |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 930 | mLastPausedActivity = null; |
Craig Mautner | 0f92274 | 2013-08-06 08:44:42 -0700 | [diff] [blame] | 931 | mLastNoHistoryActivity = null; |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 932 | } |
| 933 | } else { |
Dianne Hackborn | 621e2fe | 2012-02-16 17:07:33 -0800 | [diff] [blame] | 934 | mPausingActivity = null; |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 935 | mLastPausedActivity = null; |
Craig Mautner | 0f92274 | 2013-08-06 08:44:42 -0700 | [diff] [blame] | 936 | mLastNoHistoryActivity = null; |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 937 | } |
| 938 | |
| 939 | // If we are not going to sleep, we want to ensure the device is |
| 940 | // awake until the next activity is started. |
Dianne Hackborn | 3d07c94 | 2015-03-13 18:02:54 -0700 | [diff] [blame] | 941 | if (!uiSleeping && !mService.isSleepingOrShuttingDown()) { |
Craig Mautner | 7ea5bd4 | 2013-07-05 15:27:08 -0700 | [diff] [blame] | 942 | mStackSupervisor.acquireLaunchWakelock(); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 943 | } |
| 944 | |
Dianne Hackborn | 621e2fe | 2012-02-16 17:07:33 -0800 | [diff] [blame] | 945 | if (mPausingActivity != null) { |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 946 | // Have the window manager pause its key dispatching until the new |
| 947 | // activity has started. If we're pausing the activity just because |
| 948 | // the screen is being turned off and the UI is sleeping, don't interrupt |
| 949 | // key dispatch; the same activity will pick it up again on wakeup. |
| 950 | if (!uiSleeping) { |
Dianne Hackborn | 621e2fe | 2012-02-16 17:07:33 -0800 | [diff] [blame] | 951 | prev.pauseKeyDispatchingLocked(); |
Wale Ogunwale | ee006da | 2015-03-30 14:49:25 -0700 | [diff] [blame] | 952 | } else if (DEBUG_PAUSE) { |
| 953 | Slog.v(TAG_PAUSE, "Key dispatch not paused for screen off"); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 954 | } |
| 955 | |
Dianne Hackborn | a4e102e | 2014-09-04 22:52:27 -0700 | [diff] [blame] | 956 | if (dontWait) { |
| 957 | // If the caller said they don't want to wait for the pause, then complete |
| 958 | // the pause now. |
| 959 | completePauseLocked(false); |
| 960 | return false; |
| 961 | |
| 962 | } else { |
| 963 | // Schedule a pause timeout in case the app doesn't respond. |
| 964 | // We don't give it much time because this directly impacts the |
| 965 | // responsiveness seen by the user. |
| 966 | Message msg = mHandler.obtainMessage(PAUSE_TIMEOUT_MSG); |
| 967 | msg.obj = prev; |
| 968 | prev.pauseTime = SystemClock.uptimeMillis(); |
| 969 | mHandler.sendMessageDelayed(msg, PAUSE_TIMEOUT); |
Wale Ogunwale | ee006da | 2015-03-30 14:49:25 -0700 | [diff] [blame] | 970 | if (DEBUG_PAUSE) Slog.v(TAG_PAUSE, "Waiting for pause to complete..."); |
Dianne Hackborn | a4e102e | 2014-09-04 22:52:27 -0700 | [diff] [blame] | 971 | return true; |
| 972 | } |
| 973 | |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 974 | } else { |
| 975 | // This activity failed to schedule the |
| 976 | // pause, so just treat it as being paused now. |
Wale Ogunwale | ee006da | 2015-03-30 14:49:25 -0700 | [diff] [blame] | 977 | if (DEBUG_PAUSE) Slog.v(TAG_PAUSE, "Activity not running, resuming next."); |
Dianne Hackborn | a4e102e | 2014-09-04 22:52:27 -0700 | [diff] [blame] | 978 | if (!resuming) { |
| 979 | mStackSupervisor.getFocusedStack().resumeTopActivityLocked(null); |
| 980 | } |
| 981 | return false; |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 982 | } |
| 983 | } |
Dianne Hackborn | ad9b3211 | 2012-09-17 15:35:01 -0700 | [diff] [blame] | 984 | |
Dianne Hackborn | a4e102e | 2014-09-04 22:52:27 -0700 | [diff] [blame] | 985 | final void activityPausedLocked(IBinder token, boolean timeout) { |
Wale Ogunwale | ee006da | 2015-03-30 14:49:25 -0700 | [diff] [blame] | 986 | if (DEBUG_PAUSE) Slog.v(TAG_PAUSE, |
| 987 | "Activity paused: token=" + token + ", timeout=" + timeout); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 988 | |
Craig Mautner | d232895 | 2013-03-05 12:46:26 -0800 | [diff] [blame] | 989 | final ActivityRecord r = isInStackLocked(token); |
| 990 | if (r != null) { |
| 991 | mHandler.removeMessages(PAUSE_TIMEOUT_MSG, r); |
| 992 | if (mPausingActivity == r) { |
Wale Ogunwale | 0fc365c | 2015-05-25 19:35:42 -0700 | [diff] [blame] | 993 | if (DEBUG_STATES) Slog.v(TAG_STATES, "Moving to PAUSED: " + r |
Craig Mautner | d232895 | 2013-03-05 12:46:26 -0800 | [diff] [blame] | 994 | + (timeout ? " (due to timeout)" : " (pause complete)")); |
Dianne Hackborn | a4e102e | 2014-09-04 22:52:27 -0700 | [diff] [blame] | 995 | completePauseLocked(true); |
Craig Mautner | d232895 | 2013-03-05 12:46:26 -0800 | [diff] [blame] | 996 | } else { |
| 997 | EventLog.writeEvent(EventLogTags.AM_FAILED_TO_PAUSE, |
| 998 | r.userId, System.identityHashCode(r), r.shortComponentName, |
| 999 | mPausingActivity != null |
| 1000 | ? mPausingActivity.shortComponentName : "(none)"); |
louis_chang | 047dfd4 | 2015-04-08 16:35:55 +0800 | [diff] [blame] | 1001 | if (r.finishing && r.state == ActivityState.PAUSING) { |
| 1002 | if (DEBUG_PAUSE) Slog.v(TAG, |
| 1003 | "Executing finish of failed to pause activity: " + r); |
| 1004 | finishCurrentActivityLocked(r, FINISH_AFTER_VISIBLE, false); |
| 1005 | } |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 1006 | } |
| 1007 | } |
| 1008 | } |
| 1009 | |
Craig Mautner | a002604 | 2014-04-23 11:45:37 -0700 | [diff] [blame] | 1010 | final void activityStoppedLocked(ActivityRecord r, Bundle icicle, |
| 1011 | PersistableBundle persistentState, CharSequence description) { |
Dianne Hackborn | b61a026 | 2012-05-14 17:19:18 -0700 | [diff] [blame] | 1012 | if (r.state != ActivityState.STOPPING) { |
| 1013 | Slog.i(TAG, "Activity reported stop, but no longer stopping: " + r); |
| 1014 | mHandler.removeMessages(STOP_TIMEOUT_MSG, r); |
| 1015 | return; |
| 1016 | } |
Craig Mautner | 21d24a2 | 2014-04-23 11:45:37 -0700 | [diff] [blame] | 1017 | if (persistentState != null) { |
| 1018 | r.persistentState = persistentState; |
| 1019 | mService.notifyTaskPersisterLocked(r.task, false); |
| 1020 | } |
Wale Ogunwale | 0fc365c | 2015-05-25 19:35:42 -0700 | [diff] [blame] | 1021 | if (DEBUG_SAVED_STATE) Slog.i(TAG_SAVED_STATE, "Saving icicle of " + r + ": " + icicle); |
Dianne Hackborn | 162bc0e | 2012-04-09 14:06:16 -0700 | [diff] [blame] | 1022 | if (icicle != null) { |
| 1023 | // If icicle is null, this is happening due to a timeout, so we |
| 1024 | // haven't really saved the state. |
| 1025 | r.icicle = icicle; |
| 1026 | r.haveState = true; |
Dianne Hackborn | 0798149 | 2013-01-28 11:36:23 -0800 | [diff] [blame] | 1027 | r.launchCount = 0; |
Winson Chung | 740c3ac | 2014-11-12 16:14:38 -0800 | [diff] [blame] | 1028 | r.updateThumbnailLocked(null, description); |
Dianne Hackborn | 162bc0e | 2012-04-09 14:06:16 -0700 | [diff] [blame] | 1029 | } |
| 1030 | if (!r.stopped) { |
Wale Ogunwale | 0fc365c | 2015-05-25 19:35:42 -0700 | [diff] [blame] | 1031 | if (DEBUG_STATES) Slog.v(TAG_STATES, "Moving to STOPPED: " + r + " (stop complete)"); |
Dianne Hackborn | 162bc0e | 2012-04-09 14:06:16 -0700 | [diff] [blame] | 1032 | mHandler.removeMessages(STOP_TIMEOUT_MSG, r); |
| 1033 | r.stopped = true; |
| 1034 | r.state = ActivityState.STOPPED; |
Jose Lima | 4b6c669 | 2014-08-12 17:41:12 -0700 | [diff] [blame] | 1035 | if (mActivityContainer.mActivityDisplay.mVisibleBehindActivity == r) { |
| 1036 | mStackSupervisor.requestVisibleBehindLocked(r, false); |
Craig Mautner | ee2e45a | 2014-06-27 12:10:03 -0700 | [diff] [blame] | 1037 | } |
Dianne Hackborn | 6e3d6da | 2012-06-15 12:05:27 -0700 | [diff] [blame] | 1038 | if (r.finishing) { |
| 1039 | r.clearOptionsLocked(); |
| 1040 | } else { |
Dianne Hackborn | 162bc0e | 2012-04-09 14:06:16 -0700 | [diff] [blame] | 1041 | if (r.configDestroy) { |
Craig Mautner | ee2e45a | 2014-06-27 12:10:03 -0700 | [diff] [blame] | 1042 | destroyActivityLocked(r, true, "stop-config"); |
Craig Mautner | 05d2903 | 2013-05-03 13:40:13 -0700 | [diff] [blame] | 1043 | mStackSupervisor.resumeTopActivitiesLocked(); |
Dianne Hackborn | 162bc0e | 2012-04-09 14:06:16 -0700 | [diff] [blame] | 1044 | } else { |
Dianne Hackborn | a413dc0 | 2013-07-12 12:02:55 -0700 | [diff] [blame] | 1045 | mStackSupervisor.updatePreviousProcessLocked(r); |
Dianne Hackborn | 5068560 | 2011-12-01 12:23:37 -0800 | [diff] [blame] | 1046 | } |
Dianne Hackborn | ce86ba8 | 2011-07-13 19:33:41 -0700 | [diff] [blame] | 1047 | } |
| 1048 | } |
| 1049 | } |
| 1050 | |
Dianne Hackborn | a4e102e | 2014-09-04 22:52:27 -0700 | [diff] [blame] | 1051 | private void completePauseLocked(boolean resumeNext) { |
Dianne Hackborn | 621e2fe | 2012-02-16 17:07:33 -0800 | [diff] [blame] | 1052 | ActivityRecord prev = mPausingActivity; |
Wale Ogunwale | ee006da | 2015-03-30 14:49:25 -0700 | [diff] [blame] | 1053 | if (DEBUG_PAUSE) Slog.v(TAG_PAUSE, "Complete pause: " + prev); |
Craig Mautner | aab647e | 2013-02-28 16:31:36 -0800 | [diff] [blame] | 1054 | |
Dianne Hackborn | 621e2fe | 2012-02-16 17:07:33 -0800 | [diff] [blame] | 1055 | if (prev != null) { |
Dianne Hackborn | a4e102e | 2014-09-04 22:52:27 -0700 | [diff] [blame] | 1056 | prev.state = ActivityState.PAUSED; |
Dianne Hackborn | 621e2fe | 2012-02-16 17:07:33 -0800 | [diff] [blame] | 1057 | if (prev.finishing) { |
Wale Ogunwale | ee006da | 2015-03-30 14:49:25 -0700 | [diff] [blame] | 1058 | if (DEBUG_PAUSE) Slog.v(TAG_PAUSE, "Executing finish of activity: " + prev); |
Dianne Hackborn | 2d1b378 | 2012-09-09 17:49:39 -0700 | [diff] [blame] | 1059 | prev = finishCurrentActivityLocked(prev, FINISH_AFTER_VISIBLE, false); |
Dianne Hackborn | 621e2fe | 2012-02-16 17:07:33 -0800 | [diff] [blame] | 1060 | } else if (prev.app != null) { |
Wale Ogunwale | ee006da | 2015-03-30 14:49:25 -0700 | [diff] [blame] | 1061 | if (DEBUG_PAUSE) Slog.v(TAG_PAUSE, "Enqueueing pending stop: " + prev); |
Craig Mautner | 8c14c15 | 2015-01-15 17:32:07 -0800 | [diff] [blame] | 1062 | if (mStackSupervisor.mWaitingVisibleActivities.remove(prev)) { |
Wale Ogunwale | ee006da | 2015-03-30 14:49:25 -0700 | [diff] [blame] | 1063 | if (DEBUG_SWITCH || DEBUG_PAUSE) Slog.v(TAG_PAUSE, |
| 1064 | "Complete pause, no longer waiting: " + prev); |
Dianne Hackborn | cbb722e | 2012-02-07 18:33:49 -0800 | [diff] [blame] | 1065 | } |
Dianne Hackborn | 621e2fe | 2012-02-16 17:07:33 -0800 | [diff] [blame] | 1066 | if (prev.configDestroy) { |
| 1067 | // The previous is being paused because the configuration |
| 1068 | // is changing, which means it is actually stopping... |
| 1069 | // To juggle the fact that we are also starting a new |
| 1070 | // instance right now, we need to first completely stop |
| 1071 | // the current instance before starting the new one. |
Wale Ogunwale | ee006da | 2015-03-30 14:49:25 -0700 | [diff] [blame] | 1072 | if (DEBUG_PAUSE) Slog.v(TAG_PAUSE, "Destroying after pause: " + prev); |
Craig Mautner | ee2e45a | 2014-06-27 12:10:03 -0700 | [diff] [blame] | 1073 | destroyActivityLocked(prev, true, "pause-config"); |
Wale Ogunwale | 5c42e50 | 2015-04-08 09:18:54 -0700 | [diff] [blame] | 1074 | } else if (!hasVisibleBehindActivity() || mService.isSleepingOrShuttingDown()) { |
Jose Lima | 4b6c669 | 2014-08-12 17:41:12 -0700 | [diff] [blame] | 1075 | // If we were visible then resumeTopActivities will release resources before |
Craig Mautner | ee2e45a | 2014-06-27 12:10:03 -0700 | [diff] [blame] | 1076 | // stopping. |
Craig Mautner | de4ef02 | 2013-04-07 19:01:33 -0700 | [diff] [blame] | 1077 | mStackSupervisor.mStoppingActivities.add(prev); |
Craig Mautner | 29219d9 | 2013-04-16 20:19:12 -0700 | [diff] [blame] | 1078 | if (mStackSupervisor.mStoppingActivities.size() > 3 || |
| 1079 | prev.frontOfTask && mTaskHistory.size() <= 1) { |
Dianne Hackborn | 621e2fe | 2012-02-16 17:07:33 -0800 | [diff] [blame] | 1080 | // If we already have a few activities waiting to stop, |
| 1081 | // then give up on things going idle and start clearing |
Craig Mautner | 29219d9 | 2013-04-16 20:19:12 -0700 | [diff] [blame] | 1082 | // them out. Or if r is the last of activity of the last task the stack |
| 1083 | // will be empty and must be cleared immediately. |
Wale Ogunwale | ee006da | 2015-03-30 14:49:25 -0700 | [diff] [blame] | 1084 | if (DEBUG_PAUSE) Slog.v(TAG_PAUSE, "To many pending stops, forcing idle"); |
Craig Mautner | f333327 | 2013-04-22 10:55:53 -0700 | [diff] [blame] | 1085 | mStackSupervisor.scheduleIdleLocked(); |
Dianne Hackborn | 621e2fe | 2012-02-16 17:07:33 -0800 | [diff] [blame] | 1086 | } else { |
Craig Mautner | 0eea92c | 2013-05-16 13:35:39 -0700 | [diff] [blame] | 1087 | mStackSupervisor.checkReadyForSleepLocked(); |
Dianne Hackborn | 621e2fe | 2012-02-16 17:07:33 -0800 | [diff] [blame] | 1088 | } |
| 1089 | } |
| 1090 | } else { |
Wale Ogunwale | ee006da | 2015-03-30 14:49:25 -0700 | [diff] [blame] | 1091 | if (DEBUG_PAUSE) Slog.v(TAG_PAUSE, "App died during pause, not stopping: " + prev); |
Dianne Hackborn | 621e2fe | 2012-02-16 17:07:33 -0800 | [diff] [blame] | 1092 | prev = null; |
Dianne Hackborn | cbb722e | 2012-02-07 18:33:49 -0800 | [diff] [blame] | 1093 | } |
Wale Ogunwale | 07927bf | 2015-03-28 17:21:05 -0700 | [diff] [blame] | 1094 | // It is possible the activity was freezing the screen before it was paused. |
| 1095 | // In that case go ahead and remove the freeze this activity has on the screen |
| 1096 | // since it is no longer visible. |
| 1097 | prev.stopFreezingScreenLocked(true /*force*/); |
Dianne Hackborn | 621e2fe | 2012-02-16 17:07:33 -0800 | [diff] [blame] | 1098 | mPausingActivity = null; |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 1099 | } |
Dianne Hackborn | cbb722e | 2012-02-07 18:33:49 -0800 | [diff] [blame] | 1100 | |
Dianne Hackborn | a4e102e | 2014-09-04 22:52:27 -0700 | [diff] [blame] | 1101 | if (resumeNext) { |
| 1102 | final ActivityStack topStack = mStackSupervisor.getFocusedStack(); |
| 1103 | if (!mService.isSleepingOrShuttingDown()) { |
| 1104 | mStackSupervisor.resumeTopActivitiesLocked(topStack, prev, null); |
| 1105 | } else { |
| 1106 | mStackSupervisor.checkReadyForSleepLocked(); |
| 1107 | ActivityRecord top = topStack.topRunningActivityLocked(null); |
| 1108 | if (top == null || (prev != null && top != prev)) { |
| 1109 | // If there are no more activities available to run, |
| 1110 | // do resume anyway to start something. Also if the top |
| 1111 | // activity on the stack is not the just paused activity, |
| 1112 | // we need to go ahead and resume it to ensure we complete |
| 1113 | // an in-flight app switch. |
| 1114 | mStackSupervisor.resumeTopActivitiesLocked(topStack, null, null); |
| 1115 | } |
Dianne Hackborn | 42e620c | 2012-06-24 13:20:51 -0700 | [diff] [blame] | 1116 | } |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 1117 | } |
Craig Mautner | aab647e | 2013-02-28 16:31:36 -0800 | [diff] [blame] | 1118 | |
Dianne Hackborn | 621e2fe | 2012-02-16 17:07:33 -0800 | [diff] [blame] | 1119 | if (prev != null) { |
| 1120 | prev.resumeKeyDispatchingLocked(); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 1121 | |
Craig Mautner | 525f3d9 | 2013-05-07 14:01:50 -0700 | [diff] [blame] | 1122 | if (prev.app != null && prev.cpuTimeAtResume > 0 |
| 1123 | && mService.mBatteryStatsService.isOnBattery()) { |
Dianne Hackborn | 652973f | 2014-09-10 17:08:48 -0700 | [diff] [blame] | 1124 | long diff = mService.mProcessCpuTracker.getCpuTimeForPid(prev.app.pid) |
| 1125 | - prev.cpuTimeAtResume; |
Craig Mautner | 525f3d9 | 2013-05-07 14:01:50 -0700 | [diff] [blame] | 1126 | if (diff > 0) { |
| 1127 | BatteryStatsImpl bsi = mService.mBatteryStatsService.getActiveStatistics(); |
| 1128 | synchronized (bsi) { |
| 1129 | BatteryStatsImpl.Uid.Proc ps = |
| 1130 | bsi.getProcessStatsLocked(prev.info.applicationInfo.uid, |
Dianne Hackborn | d293224 | 2013-08-05 18:18:42 -0700 | [diff] [blame] | 1131 | prev.info.packageName); |
Craig Mautner | 525f3d9 | 2013-05-07 14:01:50 -0700 | [diff] [blame] | 1132 | if (ps != null) { |
| 1133 | ps.addForegroundTimeLocked(diff); |
| 1134 | } |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 1135 | } |
| 1136 | } |
| 1137 | } |
Craig Mautner | 525f3d9 | 2013-05-07 14:01:50 -0700 | [diff] [blame] | 1138 | prev.cpuTimeAtResume = 0; // reset it |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 1139 | } |
Winson Chung | 740c3ac | 2014-11-12 16:14:38 -0800 | [diff] [blame] | 1140 | |
| 1141 | // Notfiy when the task stack has changed |
| 1142 | mService.notifyTaskStackChangedLocked(); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 1143 | } |
| 1144 | |
| 1145 | /** |
| 1146 | * Once we know that we have asked an application to put an activity in |
| 1147 | * the resumed state (either by launching it or explicitly telling it), |
| 1148 | * this function updates the rest of our state to match that fact. |
| 1149 | */ |
Craig Mautner | 525f3d9 | 2013-05-07 14:01:50 -0700 | [diff] [blame] | 1150 | private void completeResumeLocked(ActivityRecord next) { |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 1151 | next.idle = false; |
| 1152 | next.results = null; |
| 1153 | next.newIntents = null; |
Craig Mautner | f33f4d7 | 2014-07-16 17:25:48 +0000 | [diff] [blame] | 1154 | |
| 1155 | if (next.isHomeActivity() && next.isNotResolverActivity()) { |
| 1156 | ProcessRecord app = next.task.mActivities.get(0).app; |
| 1157 | if (app != null && app != mService.mHomeProcess) { |
| 1158 | mService.mHomeProcess = app; |
| 1159 | } |
| 1160 | } |
| 1161 | |
Craig Mautner | 0756632 | 2013-09-26 16:42:55 -0700 | [diff] [blame] | 1162 | if (next.nowVisible) { |
| 1163 | // We won't get a call to reportActivityVisibleLocked() so dismiss lockscreen now. |
Jorim Jaggi | 8de4311c | 2014-08-11 22:36:20 +0200 | [diff] [blame] | 1164 | mStackSupervisor.notifyActivityDrawnForKeyguard(); |
Craig Mautner | 0756632 | 2013-09-26 16:42:55 -0700 | [diff] [blame] | 1165 | } |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 1166 | |
| 1167 | // 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] | 1168 | mStackSupervisor.scheduleIdleTimeoutLocked(next); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 1169 | |
Craig Mautner | ce5f3cb | 2013-04-22 08:58:54 -0700 | [diff] [blame] | 1170 | mStackSupervisor.reportResumedActivityLocked(next); |
| 1171 | |
| 1172 | next.resumeKeyDispatchingLocked(); |
| 1173 | mNoAnimActivities.clear(); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 1174 | |
| 1175 | // Mark the point when the activity is resuming |
| 1176 | // TODO: To be more accurate, the mark should be before the onCreate, |
| 1177 | // not after the onResume. But for subsequent starts, onResume is fine. |
| 1178 | if (next.app != null) { |
Dianne Hackborn | 652973f | 2014-09-10 17:08:48 -0700 | [diff] [blame] | 1179 | next.cpuTimeAtResume = mService.mProcessCpuTracker.getCpuTimeForPid(next.app.pid); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 1180 | } else { |
| 1181 | next.cpuTimeAtResume = 0; // Couldn't get the cpu time of process |
| 1182 | } |
Winson Chung | 376543b | 2014-05-21 17:43:28 -0700 | [diff] [blame] | 1183 | |
George Mount | 6ba042b | 2014-07-28 11:12:28 -0700 | [diff] [blame] | 1184 | next.returningOptions = null; |
Craig Mautner | 64ccb70 | 2014-10-01 09:38:40 -0700 | [diff] [blame] | 1185 | |
| 1186 | if (mActivityContainer.mActivityDisplay.mVisibleBehindActivity == next) { |
| 1187 | // When resuming an activity, require it to call requestVisibleBehind() again. |
| 1188 | mActivityContainer.mActivityDisplay.setVisibleBehindActivity(null); |
| 1189 | } |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 1190 | } |
| 1191 | |
Craig Mautner | 2568c3a | 2015-03-26 14:22:34 -0700 | [diff] [blame] | 1192 | private void setVisible(ActivityRecord r, boolean visible) { |
Craig Mautner | e3a00d7 | 2014-04-16 08:31:19 -0700 | [diff] [blame] | 1193 | r.visible = visible; |
| 1194 | mWindowManager.setAppVisibility(r.appToken, visible); |
Craig Mautner | f4c909b | 2014-04-17 18:39:38 -0700 | [diff] [blame] | 1195 | final ArrayList<ActivityContainer> containers = r.mChildContainers; |
Craig Mautner | e3a00d7 | 2014-04-16 08:31:19 -0700 | [diff] [blame] | 1196 | for (int containerNdx = containers.size() - 1; containerNdx >= 0; --containerNdx) { |
Craig Mautner | f4c909b | 2014-04-17 18:39:38 -0700 | [diff] [blame] | 1197 | ActivityContainer container = containers.get(containerNdx); |
Craig Mautner | e3a00d7 | 2014-04-16 08:31:19 -0700 | [diff] [blame] | 1198 | container.setVisible(visible); |
| 1199 | } |
| 1200 | } |
| 1201 | |
Craig Mautner | fa387ad | 2014-08-05 11:16:41 -0700 | [diff] [blame] | 1202 | // Find the first visible activity above the passed activity and if it is translucent return it |
| 1203 | // otherwise return null; |
| 1204 | ActivityRecord findNextTranslucentActivity(ActivityRecord r) { |
| 1205 | TaskRecord task = r.task; |
| 1206 | if (task == null) { |
| 1207 | return null; |
| 1208 | } |
| 1209 | |
| 1210 | ActivityStack stack = task.stack; |
| 1211 | if (stack == null) { |
| 1212 | return null; |
| 1213 | } |
| 1214 | |
| 1215 | int stackNdx = mStacks.indexOf(stack); |
| 1216 | |
| 1217 | ArrayList<TaskRecord> tasks = stack.mTaskHistory; |
| 1218 | int taskNdx = tasks.indexOf(task); |
| 1219 | |
| 1220 | ArrayList<ActivityRecord> activities = task.mActivities; |
| 1221 | int activityNdx = activities.indexOf(r) + 1; |
| 1222 | |
| 1223 | final int numStacks = mStacks.size(); |
| 1224 | while (stackNdx < numStacks) { |
Wale Ogunwale | e4a0c57 | 2015-06-30 08:40:31 -0700 | [diff] [blame] | 1225 | final ActivityStack historyStack = mStacks.get(stackNdx); |
Todd Kennedy | aab56db | 2015-01-30 09:39:53 -0800 | [diff] [blame] | 1226 | tasks = historyStack.mTaskHistory; |
Craig Mautner | fa387ad | 2014-08-05 11:16:41 -0700 | [diff] [blame] | 1227 | final int numTasks = tasks.size(); |
| 1228 | while (taskNdx < numTasks) { |
Wale Ogunwale | e4a0c57 | 2015-06-30 08:40:31 -0700 | [diff] [blame] | 1229 | final TaskRecord currentTask = tasks.get(taskNdx); |
| 1230 | activities = currentTask.mActivities; |
Craig Mautner | fa387ad | 2014-08-05 11:16:41 -0700 | [diff] [blame] | 1231 | final int numActivities = activities.size(); |
| 1232 | while (activityNdx < numActivities) { |
| 1233 | final ActivityRecord activity = activities.get(activityNdx); |
| 1234 | if (!activity.finishing) { |
Wale Ogunwale | e4a0c57 | 2015-06-30 08:40:31 -0700 | [diff] [blame] | 1235 | return historyStack.mFullscreen |
| 1236 | && currentTask.mFullscreen && activity.fullscreen ? null : activity; |
Craig Mautner | fa387ad | 2014-08-05 11:16:41 -0700 | [diff] [blame] | 1237 | } |
| 1238 | ++activityNdx; |
| 1239 | } |
| 1240 | activityNdx = 0; |
| 1241 | ++taskNdx; |
| 1242 | } |
| 1243 | taskNdx = 0; |
| 1244 | ++stackNdx; |
| 1245 | } |
| 1246 | |
| 1247 | return null; |
| 1248 | } |
| 1249 | |
Wale Ogunwale | d697cea | 2015-02-20 17:19:49 -0800 | [diff] [blame] | 1250 | private ActivityStack getNextVisibleStackLocked() { |
| 1251 | ArrayList<ActivityStack> stacks = mStacks; |
| 1252 | final ActivityRecord parent = mActivityContainer.mParentActivity; |
| 1253 | if (parent != null) { |
| 1254 | stacks = parent.task.stack.mStacks; |
| 1255 | } |
| 1256 | if (stacks != null) { |
| 1257 | for (int i = stacks.size() - 1; i >= 0; --i) { |
| 1258 | ActivityStack stack = stacks.get(i); |
| 1259 | if (stack != this && stack.isStackVisibleLocked()) { |
| 1260 | return stack; |
| 1261 | } |
| 1262 | } |
| 1263 | } |
| 1264 | return null; |
| 1265 | } |
| 1266 | |
Wale Ogunwale | b34a7ad | 2015-08-14 11:05:30 -0700 | [diff] [blame] | 1267 | /** Returns true if the stack contains a fullscreen task. */ |
| 1268 | private boolean hasFullscreenTask() { |
| 1269 | for (int i = mTaskHistory.size() - 1; i >= 0; --i) { |
| 1270 | final TaskRecord task = mTaskHistory.get(i); |
| 1271 | if (task.mFullscreen) { |
| 1272 | return true; |
| 1273 | } |
| 1274 | } |
| 1275 | return false; |
| 1276 | } |
| 1277 | |
Wale Ogunwale | 1e3523c | 2015-09-16 13:11:10 -0700 | [diff] [blame] | 1278 | private boolean hasTranslucentActivity(ActivityStack stack) { |
| 1279 | final ArrayList<TaskRecord> tasks = stack.getAllTasks(); |
| 1280 | for (int taskNdx = tasks.size() - 1; taskNdx >= 0; --taskNdx) { |
| 1281 | final TaskRecord task = tasks.get(taskNdx); |
| 1282 | final ArrayList<ActivityRecord> activities = task.mActivities; |
| 1283 | for (int activityNdx = activities.size() - 1; activityNdx >= 0; --activityNdx) { |
| 1284 | final ActivityRecord r = activities.get(activityNdx); |
Wale Ogunwale | b34a7ad | 2015-08-14 11:05:30 -0700 | [diff] [blame] | 1285 | |
Wale Ogunwale | 1e3523c | 2015-09-16 13:11:10 -0700 | [diff] [blame] | 1286 | // Conditions for an activity to obscure the stack we're |
| 1287 | // examining: |
| 1288 | // 1. Not Finishing AND Visible AND: |
| 1289 | // 2. Either: |
| 1290 | // - Full Screen Activity OR |
| 1291 | // - On top of Home and our stack is NOT home |
| 1292 | if (!r.finishing && r.visible && (r.fullscreen || |
| 1293 | (!isHomeStack() && r.frontOfTask && task.isOverHomeStack()))) { |
| 1294 | return false; |
Wale Ogunwale | b34a7ad | 2015-08-14 11:05:30 -0700 | [diff] [blame] | 1295 | } |
| 1296 | } |
| 1297 | } |
Wale Ogunwale | 1e3523c | 2015-09-16 13:11:10 -0700 | [diff] [blame] | 1298 | return true; |
Wale Ogunwale | b34a7ad | 2015-08-14 11:05:30 -0700 | [diff] [blame] | 1299 | } |
| 1300 | |
| 1301 | /** Returns true if the stack is considered visible. */ |
Todd Kennedy | aab56db | 2015-01-30 09:39:53 -0800 | [diff] [blame] | 1302 | private boolean isStackVisibleLocked() { |
Jose Lima | 7ba7125 | 2014-04-30 12:59:27 -0700 | [diff] [blame] | 1303 | if (!isAttached()) { |
| 1304 | return false; |
| 1305 | } |
| 1306 | |
| 1307 | if (mStackSupervisor.isFrontStack(this)) { |
| 1308 | return true; |
| 1309 | } |
| 1310 | |
Wale Ogunwale | b34a7ad | 2015-08-14 11:05:30 -0700 | [diff] [blame] | 1311 | final int stackIndex = mStacks.indexOf(this); |
| 1312 | |
| 1313 | if (stackIndex == mStacks.size() - 1) { |
| 1314 | Slog.wtf(TAG, |
| 1315 | "Stack=" + this + " isn't front stack but is at the top of the stack list"); |
| 1316 | return false; |
| 1317 | } |
| 1318 | |
Wale Ogunwale | 1e3523c | 2015-09-16 13:11:10 -0700 | [diff] [blame] | 1319 | final ActivityStack focusedStack = mStackSupervisor.getFocusedStack(); |
| 1320 | final int focusedStackId = focusedStack.mStackId; |
| 1321 | |
| 1322 | if (mStackId == DOCKED_STACK_ID) { |
| 1323 | // Docked stack is always visible, except in the case where the home activity |
| 1324 | // is the top running activity in the focused home stack. |
| 1325 | if (focusedStackId != HOME_STACK_ID) { |
| 1326 | return true; |
| 1327 | } |
| 1328 | ActivityRecord topHomeActivity = focusedStack.topRunningActivityLocked(null); |
| 1329 | return topHomeActivity == null || !topHomeActivity.isHomeActivity(); |
| 1330 | } |
| 1331 | |
| 1332 | if (focusedStackId == DOCKED_STACK_ID |
| 1333 | && stackIndex == (mStacks.indexOf(focusedStack) - 1)) { |
| 1334 | // Stacks directly behind the docked stack are always visible. |
| 1335 | return true; |
| 1336 | } |
| 1337 | |
| 1338 | if (mStackId == HOME_STACK_ID && focusedStackId == FULLSCREEN_WORKSPACE_STACK_ID) { |
| 1339 | // Home stack is always visible behind the fullscreen stack with a translucent activity. |
| 1340 | // This is done so that the home stack can act as a background to the translucent |
| 1341 | // activity. |
| 1342 | return hasTranslucentActivity(focusedStack); |
| 1343 | } |
| 1344 | |
| 1345 | if (mStackId >= FIRST_STATIC_STACK_ID && mStackId <= LAST_STATIC_STACK_ID) { |
| 1346 | // Visibility of any static stack should have been determined by the conditions above. |
Wale Ogunwale | ddc1cb2 | 2015-07-25 19:23:04 -0700 | [diff] [blame] | 1347 | return false; |
| 1348 | } |
| 1349 | |
Wale Ogunwale | b34a7ad | 2015-08-14 11:05:30 -0700 | [diff] [blame] | 1350 | for (int i = stackIndex + 1; i < mStacks.size(); i++) { |
Wale Ogunwale | e4a0c57 | 2015-06-30 08:40:31 -0700 | [diff] [blame] | 1351 | final ActivityStack stack = mStacks.get(i); |
Wale Ogunwale | b34a7ad | 2015-08-14 11:05:30 -0700 | [diff] [blame] | 1352 | |
| 1353 | if (!stack.mFullscreen && !stack.hasFullscreenTask()) { |
| 1354 | continue; |
| 1355 | } |
| 1356 | |
| 1357 | if (stack.mStackId == FREEFORM_WORKSPACE_STACK_ID |
Wale Ogunwale | 1e3523c | 2015-09-16 13:11:10 -0700 | [diff] [blame] | 1358 | || stack.mStackId == HOME_STACK_ID |
| 1359 | || stack.mStackId == FULLSCREEN_WORKSPACE_STACK_ID) { |
| 1360 | // These stacks can't have any dynamic stacks visible behind them. |
Wale Ogunwale | ddc1cb2 | 2015-07-25 19:23:04 -0700 | [diff] [blame] | 1361 | return false; |
Todd Kennedy | aab56db | 2015-01-30 09:39:53 -0800 | [diff] [blame] | 1362 | } |
Wale Ogunwale | ddc1cb2 | 2015-07-25 19:23:04 -0700 | [diff] [blame] | 1363 | |
Wale Ogunwale | 1e3523c | 2015-09-16 13:11:10 -0700 | [diff] [blame] | 1364 | if (!hasTranslucentActivity(stack)) { |
| 1365 | return false; |
Jose Lima | 7ba7125 | 2014-04-30 12:59:27 -0700 | [diff] [blame] | 1366 | } |
| 1367 | } |
| 1368 | |
| 1369 | return true; |
| 1370 | } |
| 1371 | |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 1372 | /** |
| 1373 | * Make sure that all activities that need to be visible (that is, they |
| 1374 | * currently can be seen by the user) actually are. |
| 1375 | */ |
Craig Mautner | bb74246 | 2014-07-07 15:28:55 -0700 | [diff] [blame] | 1376 | final void ensureActivitiesVisibleLocked(ActivityRecord starting, int configChanges) { |
| 1377 | ActivityRecord top = topRunningActivityLocked(null); |
| 1378 | if (top == null) { |
| 1379 | return; |
| 1380 | } |
Wale Ogunwale | ee006da | 2015-03-30 14:49:25 -0700 | [diff] [blame] | 1381 | if (DEBUG_VISIBILITY) Slog.v(TAG_VISIBILITY, |
| 1382 | "ensureActivitiesVisible behind " + top |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 1383 | + " configChanges=0x" + Integer.toHexString(configChanges)); |
| 1384 | |
Craig Mautner | 5eda9b3 | 2013-07-02 11:58:16 -0700 | [diff] [blame] | 1385 | if (mTranslucentActivityWaiting != top) { |
| 1386 | mUndrawnActivitiesBelowTopTranslucent.clear(); |
| 1387 | if (mTranslucentActivityWaiting != null) { |
| 1388 | // Call the callback with a timeout indication. |
| 1389 | notifyActivityDrawnLocked(null); |
| 1390 | mTranslucentActivityWaiting = null; |
| 1391 | } |
| 1392 | mHandler.removeMessages(TRANSLUCENT_TIMEOUT_MSG); |
| 1393 | } |
| 1394 | |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 1395 | // If the top activity is not fullscreen, then we need to |
| 1396 | // make sure any activities under it are now visible. |
Craig Mautner | d44711d | 2013-02-23 11:24:36 -0800 | [diff] [blame] | 1397 | boolean aboveTop = true; |
Wale Ogunwale | c219c0b | 2015-09-12 09:18:07 -0700 | [diff] [blame] | 1398 | final boolean stackInvisible = !isStackVisibleLocked(); |
| 1399 | boolean behindFullscreenActivity = stackInvisible; |
Wale Ogunwale | addd00e | 2015-04-04 17:10:50 -0700 | [diff] [blame] | 1400 | boolean noStackActivityResumed = (isInStackLocked(starting) == null); |
Jose Lima | 7ba7125 | 2014-04-30 12:59:27 -0700 | [diff] [blame] | 1401 | |
Craig Mautner | b59dcfd | 2013-05-06 13:12:58 -0700 | [diff] [blame] | 1402 | for (int taskNdx = mTaskHistory.size() - 1; taskNdx >= 0; --taskNdx) { |
Craig Mautner | ae7ecab | 2013-09-18 11:48:14 -0700 | [diff] [blame] | 1403 | final TaskRecord task = mTaskHistory.get(taskNdx); |
| 1404 | final ArrayList<ActivityRecord> activities = task.mActivities; |
Wale Ogunwale | c219c0b | 2015-09-12 09:18:07 -0700 | [diff] [blame] | 1405 | |
Craig Mautner | d44711d | 2013-02-23 11:24:36 -0800 | [diff] [blame] | 1406 | for (int activityNdx = activities.size() - 1; activityNdx >= 0; --activityNdx) { |
| 1407 | final ActivityRecord r = activities.get(activityNdx); |
| 1408 | if (r.finishing) { |
| 1409 | continue; |
| 1410 | } |
| 1411 | if (aboveTop && r != top) { |
| 1412 | continue; |
| 1413 | } |
| 1414 | aboveTop = false; |
Craig Mautner | bb74246 | 2014-07-07 15:28:55 -0700 | [diff] [blame] | 1415 | // mLaunchingBehind: Activities launching behind are at the back of the task stack |
| 1416 | // but must be drawn initially for the animation as though they were visible. |
Wale Ogunwale | e4a0c57 | 2015-06-30 08:40:31 -0700 | [diff] [blame] | 1417 | if (!behindFullscreenActivity || r.mLaunchTaskBehind) { |
Wale Ogunwale | ee006da | 2015-03-30 14:49:25 -0700 | [diff] [blame] | 1418 | if (DEBUG_VISIBILITY) Slog.v(TAG_VISIBILITY, |
| 1419 | "Make visible? " + r + " finishing=" + r.finishing |
Craig Mautner | d44711d | 2013-02-23 11:24:36 -0800 | [diff] [blame] | 1420 | + " state=" + r.state); |
Craig Mautner | 5854780 | 2013-03-05 08:23:53 -0800 | [diff] [blame] | 1421 | |
Craig Mautner | d44711d | 2013-02-23 11:24:36 -0800 | [diff] [blame] | 1422 | // First: if this is not the current activity being started, make |
| 1423 | // sure it matches the current configuration. |
Craig Mautner | bb74246 | 2014-07-07 15:28:55 -0700 | [diff] [blame] | 1424 | if (r != starting) { |
Filip Gruszczynski | a59ac9c | 2015-09-10 18:28:48 -0700 | [diff] [blame] | 1425 | ensureActivityConfigurationLocked(r, 0, false); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 1426 | } |
Craig Mautner | d44711d | 2013-02-23 11:24:36 -0800 | [diff] [blame] | 1427 | |
| 1428 | if (r.app == null || r.app.thread == null) { |
Wale Ogunwale | addd00e | 2015-04-04 17:10:50 -0700 | [diff] [blame] | 1429 | // This activity needs to be visible, but isn't even running... |
| 1430 | // get it started and resume if no other stack in this stack is resumed. |
Wale Ogunwale | ee006da | 2015-03-30 14:49:25 -0700 | [diff] [blame] | 1431 | if (DEBUG_VISIBILITY) Slog.v(TAG_VISIBILITY, |
| 1432 | "Start and freeze screen for " + r); |
Craig Mautner | bb74246 | 2014-07-07 15:28:55 -0700 | [diff] [blame] | 1433 | if (r != starting) { |
| 1434 | r.startFreezingScreenLocked(r.app, configChanges); |
| 1435 | } |
| 1436 | if (!r.visible || r.mLaunchTaskBehind) { |
Wale Ogunwale | ee006da | 2015-03-30 14:49:25 -0700 | [diff] [blame] | 1437 | if (DEBUG_VISIBILITY) Slog.v(TAG_VISIBILITY, |
| 1438 | "Starting and making visible: " + r); |
Craig Mautner | 2568c3a | 2015-03-26 14:22:34 -0700 | [diff] [blame] | 1439 | setVisible(r, true); |
Craig Mautner | bb74246 | 2014-07-07 15:28:55 -0700 | [diff] [blame] | 1440 | } |
| 1441 | if (r != starting) { |
Wale Ogunwale | addd00e | 2015-04-04 17:10:50 -0700 | [diff] [blame] | 1442 | mStackSupervisor.startSpecificActivityLocked( |
| 1443 | r, noStackActivityResumed, false); |
riddle_hsu | 36ee73d | 2015-06-05 16:38:38 +0800 | [diff] [blame] | 1444 | if (activityNdx >= activities.size()) { |
| 1445 | // Record may be removed if its process needs to restart. |
| 1446 | activityNdx = activities.size() - 1; |
| 1447 | } else { |
| 1448 | noStackActivityResumed = false; |
| 1449 | } |
Craig Mautner | d44711d | 2013-02-23 11:24:36 -0800 | [diff] [blame] | 1450 | } |
| 1451 | |
| 1452 | } else if (r.visible) { |
| 1453 | // If this activity is already visible, then there is nothing |
| 1454 | // else to do here. |
Wale Ogunwale | ee006da | 2015-03-30 14:49:25 -0700 | [diff] [blame] | 1455 | if (DEBUG_VISIBILITY) Slog.v(TAG_VISIBILITY, |
| 1456 | "Skipping: already visible at " + r); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 1457 | r.stopFreezingScreenLocked(false); |
Craig Mautner | eb8abf7 | 2014-07-02 15:04:09 -0700 | [diff] [blame] | 1458 | try { |
George Mount | 6ba042b | 2014-07-28 11:12:28 -0700 | [diff] [blame] | 1459 | if (r.returningOptions != null) { |
| 1460 | r.app.thread.scheduleOnNewActivityOptions(r.appToken, |
| 1461 | r.returningOptions); |
Craig Mautner | eb8abf7 | 2014-07-02 15:04:09 -0700 | [diff] [blame] | 1462 | } |
| 1463 | } catch(RemoteException e) { |
| 1464 | } |
Wale Ogunwale | 85b90ab | 2015-04-27 20:54:47 -0700 | [diff] [blame] | 1465 | if (r.state == ActivityState.RESUMED) { |
| 1466 | noStackActivityResumed = false; |
| 1467 | } |
Craig Mautner | bb74246 | 2014-07-07 15:28:55 -0700 | [diff] [blame] | 1468 | } else { |
Craig Mautner | d44711d | 2013-02-23 11:24:36 -0800 | [diff] [blame] | 1469 | // This activity is not currently visible, but is running. |
| 1470 | // Tell it to become visible. |
| 1471 | r.visible = true; |
| 1472 | if (r.state != ActivityState.RESUMED && r != starting) { |
| 1473 | // If this activity is paused, tell it |
| 1474 | // to now show its window. |
Wale Ogunwale | ee006da | 2015-03-30 14:49:25 -0700 | [diff] [blame] | 1475 | if (DEBUG_VISIBILITY) Slog.v(TAG_VISIBILITY, |
| 1476 | "Making visible and scheduling visibility: " + r); |
Craig Mautner | d44711d | 2013-02-23 11:24:36 -0800 | [diff] [blame] | 1477 | try { |
Craig Mautner | 5eda9b3 | 2013-07-02 11:58:16 -0700 | [diff] [blame] | 1478 | if (mTranslucentActivityWaiting != null) { |
George Mount | 6ba042b | 2014-07-28 11:12:28 -0700 | [diff] [blame] | 1479 | r.updateOptionsLocked(r.returningOptions); |
Craig Mautner | 5eda9b3 | 2013-07-02 11:58:16 -0700 | [diff] [blame] | 1480 | mUndrawnActivitiesBelowTopTranslucent.add(r); |
| 1481 | } |
Craig Mautner | 2568c3a | 2015-03-26 14:22:34 -0700 | [diff] [blame] | 1482 | setVisible(r, true); |
Craig Mautner | d44711d | 2013-02-23 11:24:36 -0800 | [diff] [blame] | 1483 | r.sleeping = false; |
| 1484 | r.app.pendingUiClean = true; |
| 1485 | r.app.thread.scheduleWindowVisibility(r.appToken, true); |
| 1486 | r.stopFreezingScreenLocked(false); |
| 1487 | } catch (Exception e) { |
| 1488 | // Just skip on any failure; we'll make it |
| 1489 | // visible when it next restarts. |
| 1490 | Slog.w(TAG, "Exception thrown making visibile: " |
| 1491 | + r.intent.getComponent(), e); |
| 1492 | } |
| 1493 | } |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 1494 | } |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 1495 | |
Craig Mautner | d44711d | 2013-02-23 11:24:36 -0800 | [diff] [blame] | 1496 | // Aggregate current change flags. |
| 1497 | configChanges |= r.configChangeFlags; |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 1498 | |
Craig Mautner | d44711d | 2013-02-23 11:24:36 -0800 | [diff] [blame] | 1499 | if (r.fullscreen) { |
Wale Ogunwale | e4a0c57 | 2015-06-30 08:40:31 -0700 | [diff] [blame] | 1500 | // At this point, nothing else needs to be shown in this task. |
| 1501 | behindFullscreenActivity = true; |
| 1502 | if (DEBUG_VISIBILITY) Slog.v(TAG_VISIBILITY, "Fullscreen: at " + r |
Wale Ogunwale | c219c0b | 2015-09-12 09:18:07 -0700 | [diff] [blame] | 1503 | + " stackInvisible=" + stackInvisible |
Wale Ogunwale | e4a0c57 | 2015-06-30 08:40:31 -0700 | [diff] [blame] | 1504 | + " behindFullscreenActivity=" + behindFullscreenActivity); |
Craig Mautner | 84984fa | 2014-06-19 11:19:20 -0700 | [diff] [blame] | 1505 | } else if (!isHomeStack() && r.frontOfTask && task.isOverHomeStack()) { |
Wale Ogunwale | e4a0c57 | 2015-06-30 08:40:31 -0700 | [diff] [blame] | 1506 | behindFullscreenActivity = true; |
| 1507 | if (DEBUG_VISIBILITY) Slog.v(TAG_VISIBILITY, "Showing home: at " + r |
Wale Ogunwale | c219c0b | 2015-09-12 09:18:07 -0700 | [diff] [blame] | 1508 | + " stackInvisible=" + stackInvisible |
Wale Ogunwale | e4a0c57 | 2015-06-30 08:40:31 -0700 | [diff] [blame] | 1509 | + " behindFullscreenActivity=" + behindFullscreenActivity); |
Craig Mautner | d44711d | 2013-02-23 11:24:36 -0800 | [diff] [blame] | 1510 | } |
| 1511 | } else { |
Wale Ogunwale | ee006da | 2015-03-30 14:49:25 -0700 | [diff] [blame] | 1512 | if (DEBUG_VISIBILITY) Slog.v(TAG_VISIBILITY, |
Wale Ogunwale | e4a0c57 | 2015-06-30 08:40:31 -0700 | [diff] [blame] | 1513 | "Make invisible? " + r + " finishing=" + r.finishing |
Wale Ogunwale | c219c0b | 2015-09-12 09:18:07 -0700 | [diff] [blame] | 1514 | + " state=" + r.state + " stackInvisible=" + stackInvisible |
Wale Ogunwale | e4a0c57 | 2015-06-30 08:40:31 -0700 | [diff] [blame] | 1515 | + " behindFullscreenActivity=" + behindFullscreenActivity); |
Craig Mautner | de4ef02 | 2013-04-07 19:01:33 -0700 | [diff] [blame] | 1516 | // Now for any activities that aren't visible to the user, make |
| 1517 | // sure they no longer are keeping the screen frozen. |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 1518 | if (r.visible) { |
Wale Ogunwale | ee006da | 2015-03-30 14:49:25 -0700 | [diff] [blame] | 1519 | if (DEBUG_VISIBILITY) Slog.v(TAG_VISIBILITY, "Making invisible: " + r); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 1520 | try { |
Craig Mautner | 2568c3a | 2015-03-26 14:22:34 -0700 | [diff] [blame] | 1521 | setVisible(r, false); |
Craig Mautner | 4addfc5 | 2013-06-25 08:05:45 -0700 | [diff] [blame] | 1522 | switch (r.state) { |
| 1523 | case STOPPING: |
| 1524 | case STOPPED: |
| 1525 | if (r.app != null && r.app.thread != null) { |
Wale Ogunwale | ee006da | 2015-03-30 14:49:25 -0700 | [diff] [blame] | 1526 | if (DEBUG_VISIBILITY) Slog.v(TAG_VISIBILITY, |
| 1527 | "Scheduling invisibility: " + r); |
Craig Mautner | 4addfc5 | 2013-06-25 08:05:45 -0700 | [diff] [blame] | 1528 | r.app.thread.scheduleWindowVisibility(r.appToken, false); |
| 1529 | } |
| 1530 | break; |
| 1531 | |
| 1532 | case INITIALIZING: |
| 1533 | case RESUMED: |
| 1534 | case PAUSING: |
| 1535 | case PAUSED: |
Craig Mautner | 8817610 | 2013-07-22 12:57:51 -0700 | [diff] [blame] | 1536 | // This case created for transitioning activities from |
| 1537 | // translucent to opaque {@link Activity#convertToOpaque}. |
Jose Lima | 4b6c669 | 2014-08-12 17:41:12 -0700 | [diff] [blame] | 1538 | if (getVisibleBehindActivity() == r) { |
Todd Kennedy | aab56db | 2015-01-30 09:39:53 -0800 | [diff] [blame] | 1539 | releaseBackgroundResources(r); |
Craig Mautner | ee2e45a | 2014-06-27 12:10:03 -0700 | [diff] [blame] | 1540 | } else { |
| 1541 | if (!mStackSupervisor.mStoppingActivities.contains(r)) { |
| 1542 | mStackSupervisor.mStoppingActivities.add(r); |
| 1543 | } |
| 1544 | mStackSupervisor.scheduleIdleLocked(); |
Craig Mautner | e5273b4 | 2013-09-09 12:57:47 -0700 | [diff] [blame] | 1545 | } |
Craig Mautner | 4addfc5 | 2013-06-25 08:05:45 -0700 | [diff] [blame] | 1546 | break; |
| 1547 | |
| 1548 | default: |
| 1549 | break; |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 1550 | } |
| 1551 | } catch (Exception e) { |
| 1552 | // Just skip on any failure; we'll make it |
| 1553 | // visible when it next restarts. |
| 1554 | Slog.w(TAG, "Exception thrown making hidden: " |
| 1555 | + r.intent.getComponent(), e); |
| 1556 | } |
| 1557 | } else { |
Wale Ogunwale | ee006da | 2015-03-30 14:49:25 -0700 | [diff] [blame] | 1558 | if (DEBUG_VISIBILITY) Slog.v(TAG_VISIBILITY, "Already invisible: " + r); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 1559 | } |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 1560 | } |
| 1561 | } |
Wale Ogunwale | c219c0b | 2015-09-12 09:18:07 -0700 | [diff] [blame] | 1562 | if (mStackId == FREEFORM_WORKSPACE_STACK_ID) { |
| 1563 | // The visibility of tasks and the activities they contain in freeform stack are |
| 1564 | // determined individually unlike other stacks where the visibility or fullscreen |
| 1565 | // status of an activity in a previous task affects other. |
| 1566 | behindFullscreenActivity = stackInvisible; |
| 1567 | } |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 1568 | } |
Craig Mautner | eb8abf7 | 2014-07-02 15:04:09 -0700 | [diff] [blame] | 1569 | |
| 1570 | if (mTranslucentActivityWaiting != null && |
| 1571 | mUndrawnActivitiesBelowTopTranslucent.isEmpty()) { |
| 1572 | // Nothing is getting drawn or everything was already visible, don't wait for timeout. |
| 1573 | notifyActivityDrawnLocked(null); |
| 1574 | } |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 1575 | } |
Craig Mautner | 5854780 | 2013-03-05 08:23:53 -0800 | [diff] [blame] | 1576 | |
Todd Kennedy | aab56db | 2015-01-30 09:39:53 -0800 | [diff] [blame] | 1577 | void convertActivityToTranslucent(ActivityRecord r) { |
Craig Mautner | 5eda9b3 | 2013-07-02 11:58:16 -0700 | [diff] [blame] | 1578 | mTranslucentActivityWaiting = r; |
| 1579 | mUndrawnActivitiesBelowTopTranslucent.clear(); |
| 1580 | mHandler.sendEmptyMessageDelayed(TRANSLUCENT_TIMEOUT_MSG, TRANSLUCENT_CONVERSION_TIMEOUT); |
| 1581 | } |
| 1582 | |
Dianne Hackborn | b5a380d | 2015-05-20 18:18:46 -0700 | [diff] [blame] | 1583 | void clearOtherAppTimeTrackers(AppTimeTracker except) { |
| 1584 | for (int taskNdx = mTaskHistory.size() - 1; taskNdx >= 0; --taskNdx) { |
| 1585 | final TaskRecord task = mTaskHistory.get(taskNdx); |
| 1586 | final ArrayList<ActivityRecord> activities = task.mActivities; |
| 1587 | for (int activityNdx = activities.size() - 1; activityNdx >= 0; --activityNdx) { |
| 1588 | final ActivityRecord r = activities.get(activityNdx); |
| 1589 | if ( r.appTimeTracker != except) { |
| 1590 | r.appTimeTracker = null; |
| 1591 | } |
| 1592 | } |
| 1593 | } |
| 1594 | } |
| 1595 | |
Craig Mautner | 5eda9b3 | 2013-07-02 11:58:16 -0700 | [diff] [blame] | 1596 | /** |
| 1597 | * Called as activities below the top translucent activity are redrawn. When the last one is |
| 1598 | * redrawn notify the top activity by calling |
| 1599 | * {@link Activity#onTranslucentConversionComplete}. |
| 1600 | * |
| 1601 | * @param r The most recent background activity to be drawn. Or, if r is null then a timeout |
| 1602 | * occurred and the activity will be notified immediately. |
| 1603 | */ |
| 1604 | void notifyActivityDrawnLocked(ActivityRecord r) { |
Craig Mautner | 6985bad | 2014-04-21 15:22:06 -0700 | [diff] [blame] | 1605 | mActivityContainer.setDrawn(); |
Craig Mautner | 5eda9b3 | 2013-07-02 11:58:16 -0700 | [diff] [blame] | 1606 | if ((r == null) |
| 1607 | || (mUndrawnActivitiesBelowTopTranslucent.remove(r) && |
| 1608 | mUndrawnActivitiesBelowTopTranslucent.isEmpty())) { |
| 1609 | // The last undrawn activity below the top has just been drawn. If there is an |
| 1610 | // opaque activity at the top, notify it that it can become translucent safely now. |
| 1611 | final ActivityRecord waitingActivity = mTranslucentActivityWaiting; |
| 1612 | mTranslucentActivityWaiting = null; |
| 1613 | mUndrawnActivitiesBelowTopTranslucent.clear(); |
| 1614 | mHandler.removeMessages(TRANSLUCENT_TIMEOUT_MSG); |
| 1615 | |
Craig Mautner | 71dd1b6 | 2014-02-18 15:48:52 -0800 | [diff] [blame] | 1616 | if (waitingActivity != null) { |
| 1617 | mWindowManager.setWindowOpaque(waitingActivity.appToken, false); |
| 1618 | if (waitingActivity.app != null && waitingActivity.app.thread != null) { |
| 1619 | try { |
| 1620 | waitingActivity.app.thread.scheduleTranslucentConversionComplete( |
| 1621 | waitingActivity.appToken, r != null); |
| 1622 | } catch (RemoteException e) { |
| 1623 | } |
Craig Mautner | 5eda9b3 | 2013-07-02 11:58:16 -0700 | [diff] [blame] | 1624 | } |
| 1625 | } |
| 1626 | } |
| 1627 | } |
| 1628 | |
Craig Mautner | a61bc65 | 2013-10-28 15:43:18 -0700 | [diff] [blame] | 1629 | /** If any activities below the top running one are in the INITIALIZING state and they have a |
| 1630 | * starting window displayed then remove that starting window. It is possible that the activity |
| 1631 | * in this state will never resumed in which case that starting window will be orphaned. */ |
| 1632 | void cancelInitializingActivities() { |
| 1633 | final ActivityRecord topActivity = topRunningActivityLocked(null); |
| 1634 | boolean aboveTop = true; |
| 1635 | for (int taskNdx = mTaskHistory.size() - 1; taskNdx >= 0; --taskNdx) { |
| 1636 | final ArrayList<ActivityRecord> activities = mTaskHistory.get(taskNdx).mActivities; |
| 1637 | for (int activityNdx = activities.size() - 1; activityNdx >= 0; --activityNdx) { |
| 1638 | final ActivityRecord r = activities.get(activityNdx); |
| 1639 | if (aboveTop) { |
| 1640 | if (r == topActivity) { |
| 1641 | aboveTop = false; |
| 1642 | } |
| 1643 | continue; |
| 1644 | } |
| 1645 | |
| 1646 | if (r.state == ActivityState.INITIALIZING && r.mStartingWindowShown) { |
Wale Ogunwale | ee006da | 2015-03-30 14:49:25 -0700 | [diff] [blame] | 1647 | if (DEBUG_VISIBILITY) Slog.w(TAG_VISIBILITY, |
| 1648 | "Found orphaned starting window " + r); |
Craig Mautner | a61bc65 | 2013-10-28 15:43:18 -0700 | [diff] [blame] | 1649 | r.mStartingWindowShown = false; |
| 1650 | mWindowManager.removeAppStartingWindow(r.appToken); |
| 1651 | } |
| 1652 | } |
| 1653 | } |
| 1654 | } |
| 1655 | |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 1656 | /** |
| 1657 | * Ensure that the top activity in the stack is resumed. |
| 1658 | * |
| 1659 | * @param prev The previously resumed activity, for when in the process |
| 1660 | * of pausing; can be null to call from elsewhere. |
| 1661 | * |
| 1662 | * @return Returns true if something is being resumed, or false if |
| 1663 | * nothing happened. |
| 1664 | */ |
| 1665 | final boolean resumeTopActivityLocked(ActivityRecord prev) { |
Dianne Hackborn | 8437587 | 2012-06-01 19:03:50 -0700 | [diff] [blame] | 1666 | return resumeTopActivityLocked(prev, null); |
| 1667 | } |
| 1668 | |
| 1669 | final boolean resumeTopActivityLocked(ActivityRecord prev, Bundle options) { |
Craig Mautner | 42d04db | 2014-11-06 12:13:23 -0800 | [diff] [blame] | 1670 | if (mStackSupervisor.inResumeTopActivity) { |
Craig Mautner | 544efa7 | 2014-09-04 16:41:20 -0700 | [diff] [blame] | 1671 | // Don't even start recursing. |
| 1672 | return false; |
| 1673 | } |
| 1674 | |
| 1675 | boolean result = false; |
| 1676 | try { |
| 1677 | // Protect against recursion. |
Craig Mautner | 42d04db | 2014-11-06 12:13:23 -0800 | [diff] [blame] | 1678 | mStackSupervisor.inResumeTopActivity = true; |
| 1679 | if (mService.mLockScreenShown == ActivityManagerService.LOCK_SCREEN_LEAVING) { |
| 1680 | mService.mLockScreenShown = ActivityManagerService.LOCK_SCREEN_HIDDEN; |
Jeff Brown | 9ef9401 | 2014-11-21 13:04:42 -0800 | [diff] [blame] | 1681 | mService.updateSleepIfNeededLocked(); |
Craig Mautner | 42d04db | 2014-11-06 12:13:23 -0800 | [diff] [blame] | 1682 | } |
Craig Mautner | 544efa7 | 2014-09-04 16:41:20 -0700 | [diff] [blame] | 1683 | result = resumeTopActivityInnerLocked(prev, options); |
| 1684 | } finally { |
Craig Mautner | 42d04db | 2014-11-06 12:13:23 -0800 | [diff] [blame] | 1685 | mStackSupervisor.inResumeTopActivity = false; |
Craig Mautner | 544efa7 | 2014-09-04 16:41:20 -0700 | [diff] [blame] | 1686 | } |
| 1687 | return result; |
| 1688 | } |
| 1689 | |
Wale Ogunwale | d697cea | 2015-02-20 17:19:49 -0800 | [diff] [blame] | 1690 | private boolean resumeTopActivityInnerLocked(ActivityRecord prev, Bundle options) { |
Wale Ogunwale | ee006da | 2015-03-30 14:49:25 -0700 | [diff] [blame] | 1691 | if (DEBUG_LOCKSCREEN) mService.logLockScreen(""); |
Craig Mautner | 5314a40 | 2013-09-26 12:40:16 -0700 | [diff] [blame] | 1692 | |
Dianne Hackborn | 7622a0f | 2014-09-30 14:31:42 -0700 | [diff] [blame] | 1693 | if (!mService.mBooting && !mService.mBooted) { |
| 1694 | // Not ready yet! |
| 1695 | return false; |
| 1696 | } |
| 1697 | |
Craig Mautner | df88d73 | 2014-01-27 09:21:32 -0800 | [diff] [blame] | 1698 | ActivityRecord parent = mActivityContainer.mParentActivity; |
Craig Mautner | f4c909b | 2014-04-17 18:39:38 -0700 | [diff] [blame] | 1699 | if ((parent != null && parent.state != ActivityState.RESUMED) || |
Craig Mautner | d163e75 | 2014-06-13 17:18:47 -0700 | [diff] [blame] | 1700 | !mActivityContainer.isAttachedLocked()) { |
Craig Mautner | df88d73 | 2014-01-27 09:21:32 -0800 | [diff] [blame] | 1701 | // Do not resume this stack if its parent is not resumed. |
| 1702 | // TODO: If in a loop, make sure that parent stack resumeTopActivity is called 1st. |
| 1703 | return false; |
| 1704 | } |
| 1705 | |
Craig Mautner | a61bc65 | 2013-10-28 15:43:18 -0700 | [diff] [blame] | 1706 | cancelInitializingActivities(); |
| 1707 | |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 1708 | // Find the first activity that is not finishing. |
Craig Mautner | 94ab466 | 2015-01-20 10:49:22 -0800 | [diff] [blame] | 1709 | final ActivityRecord next = topRunningActivityLocked(null); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 1710 | |
| 1711 | // Remember how we'll process this pause/resume situation, and ensure |
| 1712 | // that the state is reset however we wind up proceeding. |
Craig Mautner | de4ef02 | 2013-04-07 19:01:33 -0700 | [diff] [blame] | 1713 | final boolean userLeaving = mStackSupervisor.mUserLeaving; |
| 1714 | mStackSupervisor.mUserLeaving = false; |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 1715 | |
Craig Mautner | 84984fa | 2014-06-19 11:19:20 -0700 | [diff] [blame] | 1716 | final TaskRecord prevTask = prev != null ? prev.task : null; |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 1717 | if (next == null) { |
Wale Ogunwale | d697cea | 2015-02-20 17:19:49 -0800 | [diff] [blame] | 1718 | // There are no more activities! |
| 1719 | final String reason = "noMoreActivities"; |
| 1720 | if (!mFullscreen) { |
| 1721 | // Try to move focus to the next visible stack with a running activity if this |
| 1722 | // stack is not covering the entire screen. |
| 1723 | final ActivityStack stack = getNextVisibleStackLocked(); |
| 1724 | if (adjustFocusToNextVisibleStackLocked(stack, reason)) { |
| 1725 | return mStackSupervisor.resumeTopActivitiesLocked(stack, prev, null); |
| 1726 | } |
| 1727 | } |
| 1728 | // Let's just start up the Launcher... |
Craig Mautner | de4ef02 | 2013-04-07 19:01:33 -0700 | [diff] [blame] | 1729 | ActivityOptions.abort(options); |
Wale Ogunwale | 0fc365c | 2015-05-25 19:35:42 -0700 | [diff] [blame] | 1730 | if (DEBUG_STATES) Slog.d(TAG_STATES, |
| 1731 | "resumeTopActivityLocked: No more activities go home"); |
Craig Mautner | cf910b0 | 2013-04-23 11:23:27 -0700 | [diff] [blame] | 1732 | if (DEBUG_STACK) mStackSupervisor.validateTopActivitiesLocked(); |
Craig Mautner | e0a3884 | 2013-12-16 16:14:02 -0800 | [diff] [blame] | 1733 | // Only resume home if on home display |
Craig Mautner | 84984fa | 2014-06-19 11:19:20 -0700 | [diff] [blame] | 1734 | final int returnTaskType = prevTask == null || !prevTask.isOverHomeStack() ? |
| 1735 | HOME_ACTIVITY_TYPE : prevTask.getTaskToReturnTo(); |
| 1736 | return isOnHomeDisplay() && |
Wale Ogunwale | d697cea | 2015-02-20 17:19:49 -0800 | [diff] [blame] | 1737 | mStackSupervisor.resumeHomeStackTask(returnTaskType, prev, reason); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 1738 | } |
| 1739 | |
| 1740 | next.delayedResume = false; |
Craig Mautner | 5854780 | 2013-03-05 08:23:53 -0800 | [diff] [blame] | 1741 | |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 1742 | // If the top activity is the resumed one, nothing to do. |
Craig Mautner | de4ef02 | 2013-04-07 19:01:33 -0700 | [diff] [blame] | 1743 | if (mResumedActivity == next && next.state == ActivityState.RESUMED && |
| 1744 | mStackSupervisor.allResumedActivitiesComplete()) { |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 1745 | // Make sure we have executed any pending transitions, since there |
| 1746 | // should be nothing left to do at this point. |
Craig Mautner | ce5f3cb | 2013-04-22 08:58:54 -0700 | [diff] [blame] | 1747 | mWindowManager.executeAppTransition(); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 1748 | mNoAnimActivities.clear(); |
Dianne Hackborn | 8437587 | 2012-06-01 19:03:50 -0700 | [diff] [blame] | 1749 | ActivityOptions.abort(options); |
Wale Ogunwale | 0fc365c | 2015-05-25 19:35:42 -0700 | [diff] [blame] | 1750 | if (DEBUG_STATES) Slog.d(TAG_STATES, |
| 1751 | "resumeTopActivityLocked: Top activity resumed " + next); |
Craig Mautner | cf910b0 | 2013-04-23 11:23:27 -0700 | [diff] [blame] | 1752 | if (DEBUG_STACK) mStackSupervisor.validateTopActivitiesLocked(); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 1753 | return false; |
| 1754 | } |
| 1755 | |
Craig Mautner | 525f3d9 | 2013-05-07 14:01:50 -0700 | [diff] [blame] | 1756 | final TaskRecord nextTask = next.task; |
bulic | ccd23071 | 2014-05-12 14:34:50 -0700 | [diff] [blame] | 1757 | if (prevTask != null && prevTask.stack == this && |
Craig Mautner | 84984fa | 2014-06-19 11:19:20 -0700 | [diff] [blame] | 1758 | prevTask.isOverHomeStack() && prev.finishing && prev.frontOfTask) { |
Craig Mautner | cf910b0 | 2013-04-23 11:23:27 -0700 | [diff] [blame] | 1759 | if (DEBUG_STACK) mStackSupervisor.validateTopActivitiesLocked(); |
Craig Mautner | 525f3d9 | 2013-05-07 14:01:50 -0700 | [diff] [blame] | 1760 | if (prevTask == nextTask) { |
Craig Mautner | 1aa9d0d3f | 2013-12-16 15:58:31 -0800 | [diff] [blame] | 1761 | prevTask.setFrontOfTask(); |
Craig Mautner | 525f3d9 | 2013-05-07 14:01:50 -0700 | [diff] [blame] | 1762 | } else if (prevTask != topTask()) { |
Craig Mautner | 84984fa | 2014-06-19 11:19:20 -0700 | [diff] [blame] | 1763 | // 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] | 1764 | // 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] | 1765 | final int taskNdx = mTaskHistory.indexOf(prevTask) + 1; |
Craig Mautner | 84984fa | 2014-06-19 11:19:20 -0700 | [diff] [blame] | 1766 | mTaskHistory.get(taskNdx).setTaskToReturnTo(HOME_ACTIVITY_TYPE); |
louis_chang | 2d094e9 | 2015-01-21 19:01:52 +0800 | [diff] [blame] | 1767 | } else if (!isOnHomeDisplay()) { |
| 1768 | return false; |
| 1769 | } else if (!isHomeStack()){ |
Wale Ogunwale | 0fc365c | 2015-05-25 19:35:42 -0700 | [diff] [blame] | 1770 | if (DEBUG_STATES) Slog.d(TAG_STATES, |
Craig Mautner | e0a3884 | 2013-12-16 16:14:02 -0800 | [diff] [blame] | 1771 | "resumeTopActivityLocked: Launching home next"); |
Craig Mautner | 84984fa | 2014-06-19 11:19:20 -0700 | [diff] [blame] | 1772 | final int returnTaskType = prevTask == null || !prevTask.isOverHomeStack() ? |
| 1773 | HOME_ACTIVITY_TYPE : prevTask.getTaskToReturnTo(); |
| 1774 | return isOnHomeDisplay() && |
Craig Mautner | 3c878f2 | 2015-01-26 13:57:19 -0800 | [diff] [blame] | 1775 | mStackSupervisor.resumeHomeStackTask(returnTaskType, prev, "prevFinished"); |
Craig Mautner | e418ecd | 2013-05-01 17:02:29 -0700 | [diff] [blame] | 1776 | } |
Craig Mautner | de4ef02 | 2013-04-07 19:01:33 -0700 | [diff] [blame] | 1777 | } |
| 1778 | |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 1779 | // If we are sleeping, and there is no resumed activity, and the top |
| 1780 | // activity is paused, well that is the state we want. |
Craig Mautner | 5314a40 | 2013-09-26 12:40:16 -0700 | [diff] [blame] | 1781 | if (mService.isSleepingOrShuttingDown() |
p13451 | dbad287 | 2012-04-18 11:39:23 +0900 | [diff] [blame] | 1782 | && mLastPausedActivity == next |
Craig Mautner | 5314a40 | 2013-09-26 12:40:16 -0700 | [diff] [blame] | 1783 | && mStackSupervisor.allPausedActivitiesComplete()) { |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 1784 | // Make sure we have executed any pending transitions, since there |
| 1785 | // should be nothing left to do at this point. |
Craig Mautner | ce5f3cb | 2013-04-22 08:58:54 -0700 | [diff] [blame] | 1786 | mWindowManager.executeAppTransition(); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 1787 | mNoAnimActivities.clear(); |
Dianne Hackborn | 8437587 | 2012-06-01 19:03:50 -0700 | [diff] [blame] | 1788 | ActivityOptions.abort(options); |
Wale Ogunwale | 0fc365c | 2015-05-25 19:35:42 -0700 | [diff] [blame] | 1789 | if (DEBUG_STATES) Slog.d(TAG_STATES, |
| 1790 | "resumeTopActivityLocked: Going to sleep and all paused"); |
Craig Mautner | cf910b0 | 2013-04-23 11:23:27 -0700 | [diff] [blame] | 1791 | if (DEBUG_STACK) mStackSupervisor.validateTopActivitiesLocked(); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 1792 | return false; |
| 1793 | } |
Dianne Hackborn | 80a4af2 | 2012-08-27 19:18:31 -0700 | [diff] [blame] | 1794 | |
| 1795 | // Make sure that the user who owns this activity is started. If not, |
| 1796 | // we will just leave it as is because someone should be bringing |
| 1797 | // another user's activities to the top of the stack. |
| 1798 | if (mService.mStartedUsers.get(next.userId) == null) { |
| 1799 | Slog.w(TAG, "Skipping resume of top activity " + next |
| 1800 | + ": user " + next.userId + " is stopped"); |
Craig Mautner | cf910b0 | 2013-04-23 11:23:27 -0700 | [diff] [blame] | 1801 | if (DEBUG_STACK) mStackSupervisor.validateTopActivitiesLocked(); |
Dianne Hackborn | 80a4af2 | 2012-08-27 19:18:31 -0700 | [diff] [blame] | 1802 | return false; |
| 1803 | } |
| 1804 | |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 1805 | // The activity may be waiting for stop, but that is no longer |
| 1806 | // appropriate for it. |
Craig Mautner | de4ef02 | 2013-04-07 19:01:33 -0700 | [diff] [blame] | 1807 | mStackSupervisor.mStoppingActivities.remove(next); |
Craig Mautner | 0eea92c | 2013-05-16 13:35:39 -0700 | [diff] [blame] | 1808 | mStackSupervisor.mGoingToSleepActivities.remove(next); |
Dianne Hackborn | 4eba96b | 2011-01-21 13:34:36 -0800 | [diff] [blame] | 1809 | next.sleeping = false; |
Craig Mautner | de4ef02 | 2013-04-07 19:01:33 -0700 | [diff] [blame] | 1810 | mStackSupervisor.mWaitingVisibleActivities.remove(next); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 1811 | |
Wale Ogunwale | ee006da | 2015-03-30 14:49:25 -0700 | [diff] [blame] | 1812 | if (DEBUG_SWITCH) Slog.v(TAG_SWITCH, "Resuming " + next); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 1813 | |
Dianne Hackborn | 621e2fe | 2012-02-16 17:07:33 -0800 | [diff] [blame] | 1814 | // If we are currently pausing an activity, then don't do anything |
| 1815 | // until that is done. |
Craig Mautner | 69ada55 | 2013-04-18 13:51:51 -0700 | [diff] [blame] | 1816 | if (!mStackSupervisor.allPausedActivitiesComplete()) { |
Wale Ogunwale | ee006da | 2015-03-30 14:49:25 -0700 | [diff] [blame] | 1817 | if (DEBUG_SWITCH || DEBUG_PAUSE || DEBUG_STATES) Slog.v(TAG_PAUSE, |
Craig Mautner | ac6f843 | 2013-07-17 13:24:59 -0700 | [diff] [blame] | 1818 | "resumeTopActivityLocked: Skip resume: some activity pausing."); |
Craig Mautner | cf910b0 | 2013-04-23 11:23:27 -0700 | [diff] [blame] | 1819 | if (DEBUG_STACK) mStackSupervisor.validateTopActivitiesLocked(); |
Dianne Hackborn | 621e2fe | 2012-02-16 17:07:33 -0800 | [diff] [blame] | 1820 | return false; |
| 1821 | } |
| 1822 | |
Dianne Hackborn | 0dad364 | 2010-09-09 21:25:35 -0700 | [diff] [blame] | 1823 | // Okay we are now going to start a switch, to 'next'. We may first |
| 1824 | // have to pause the current activity, but this is an important point |
| 1825 | // 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] | 1826 | // XXX "App Redirected" dialog is getting too many false positives |
| 1827 | // at this point, so turn off for now. |
| 1828 | if (false) { |
| 1829 | if (mLastStartedActivity != null && !mLastStartedActivity.finishing) { |
| 1830 | long now = SystemClock.uptimeMillis(); |
| 1831 | final boolean inTime = mLastStartedActivity.startTime != 0 |
| 1832 | && (mLastStartedActivity.startTime + START_WARN_TIME) >= now; |
| 1833 | final int lastUid = mLastStartedActivity.info.applicationInfo.uid; |
| 1834 | final int nextUid = next.info.applicationInfo.uid; |
| 1835 | if (inTime && lastUid != nextUid |
| 1836 | && lastUid != next.launchedFromUid |
| 1837 | && mService.checkPermission( |
| 1838 | android.Manifest.permission.STOP_APP_SWITCHES, |
| 1839 | -1, next.launchedFromUid) |
| 1840 | != PackageManager.PERMISSION_GRANTED) { |
| 1841 | mService.showLaunchWarningLocked(mLastStartedActivity, next); |
| 1842 | } else { |
| 1843 | next.startTime = now; |
| 1844 | mLastStartedActivity = next; |
| 1845 | } |
Dianne Hackborn | 0dad364 | 2010-09-09 21:25:35 -0700 | [diff] [blame] | 1846 | } else { |
Dianne Hackborn | 034093a4 | 2010-09-20 22:24:38 -0700 | [diff] [blame] | 1847 | next.startTime = SystemClock.uptimeMillis(); |
Dianne Hackborn | 0dad364 | 2010-09-09 21:25:35 -0700 | [diff] [blame] | 1848 | mLastStartedActivity = next; |
| 1849 | } |
Dianne Hackborn | 0dad364 | 2010-09-09 21:25:35 -0700 | [diff] [blame] | 1850 | } |
Craig Mautner | 5854780 | 2013-03-05 08:23:53 -0800 | [diff] [blame] | 1851 | |
Dianne Hackborn | 3d07c94 | 2015-03-13 18:02:54 -0700 | [diff] [blame] | 1852 | mStackSupervisor.setLaunchSource(next.info.applicationInfo.uid); |
| 1853 | |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 1854 | // We need to start pausing the current activity so the top one |
| 1855 | // can be resumed... |
Dianne Hackborn | a4e102e | 2014-09-04 22:52:27 -0700 | [diff] [blame] | 1856 | boolean dontWaitForPause = (next.info.flags&ActivityInfo.FLAG_RESUME_WHILE_PAUSING) != 0; |
| 1857 | boolean pausing = mStackSupervisor.pauseBackStacks(userLeaving, true, dontWaitForPause); |
Craig Mautner | eb95786 | 2013-04-24 15:34:32 -0700 | [diff] [blame] | 1858 | if (mResumedActivity != null) { |
Wale Ogunwale | 0fc365c | 2015-05-25 19:35:42 -0700 | [diff] [blame] | 1859 | if (DEBUG_STATES) Slog.d(TAG_STATES, |
| 1860 | "resumeTopActivityLocked: Pausing " + mResumedActivity); |
Craig Mautner | e042bf2 | 2014-11-11 11:28:43 -0800 | [diff] [blame] | 1861 | pausing |= startPausingLocked(userLeaving, false, true, dontWaitForPause); |
Craig Mautner | eb95786 | 2013-04-24 15:34:32 -0700 | [diff] [blame] | 1862 | } |
| 1863 | if (pausing) { |
Wale Ogunwale | 0fc365c | 2015-05-25 19:35:42 -0700 | [diff] [blame] | 1864 | if (DEBUG_SWITCH || DEBUG_STATES) Slog.v(TAG_STATES, |
Craig Mautner | ac6f843 | 2013-07-17 13:24:59 -0700 | [diff] [blame] | 1865 | "resumeTopActivityLocked: Skip resume: need to start pausing"); |
Dianne Hackborn | ad9b3211 | 2012-09-17 15:35:01 -0700 | [diff] [blame] | 1866 | // At this point we want to put the upcoming activity's process |
| 1867 | // at the top of the LRU list, since we know we will be needing it |
| 1868 | // very soon and it would be a waste to let it get killed if it |
| 1869 | // happens to be sitting towards the end. |
| 1870 | if (next.app != null && next.app.thread != null) { |
Dianne Hackborn | db92608 | 2013-10-31 16:32:44 -0700 | [diff] [blame] | 1871 | mService.updateLruProcessLocked(next.app, true, null); |
Dianne Hackborn | ad9b3211 | 2012-09-17 15:35:01 -0700 | [diff] [blame] | 1872 | } |
Craig Mautner | cf910b0 | 2013-04-23 11:23:27 -0700 | [diff] [blame] | 1873 | if (DEBUG_STACK) mStackSupervisor.validateTopActivitiesLocked(); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 1874 | return true; |
| 1875 | } |
| 1876 | |
Christopher Tate | d3f175c | 2012-06-14 14:16:54 -0700 | [diff] [blame] | 1877 | // If the most recent activity was noHistory but was only stopped rather |
| 1878 | // than stopped+finished because the device went to sleep, we need to make |
| 1879 | // sure to finish it as we're making a new activity topmost. |
Dianne Hackborn | 91097de | 2014-04-04 18:02:06 -0700 | [diff] [blame] | 1880 | if (mService.isSleeping() && mLastNoHistoryActivity != null && |
Craig Mautner | 0f92274 | 2013-08-06 08:44:42 -0700 | [diff] [blame] | 1881 | !mLastNoHistoryActivity.finishing) { |
Wale Ogunwale | 0fc365c | 2015-05-25 19:35:42 -0700 | [diff] [blame] | 1882 | if (DEBUG_STATES) Slog.d(TAG_STATES, |
| 1883 | "no-history finish of " + mLastNoHistoryActivity + " on new resume"); |
Craig Mautner | 0f92274 | 2013-08-06 08:44:42 -0700 | [diff] [blame] | 1884 | requestFinishActivityLocked(mLastNoHistoryActivity.appToken, Activity.RESULT_CANCELED, |
Todd Kennedy | 539db51 | 2014-12-15 09:57:55 -0800 | [diff] [blame] | 1885 | null, "resume-no-history", false); |
Craig Mautner | 0f92274 | 2013-08-06 08:44:42 -0700 | [diff] [blame] | 1886 | mLastNoHistoryActivity = null; |
Christopher Tate | d3f175c | 2012-06-14 14:16:54 -0700 | [diff] [blame] | 1887 | } |
| 1888 | |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 1889 | if (prev != null && prev != next) { |
Craig Mautner | 8c14c15 | 2015-01-15 17:32:07 -0800 | [diff] [blame] | 1890 | if (!mStackSupervisor.mWaitingVisibleActivities.contains(prev) |
| 1891 | && next != null && !next.nowVisible) { |
Craig Mautner | de4ef02 | 2013-04-07 19:01:33 -0700 | [diff] [blame] | 1892 | mStackSupervisor.mWaitingVisibleActivities.add(prev); |
Wale Ogunwale | ee006da | 2015-03-30 14:49:25 -0700 | [diff] [blame] | 1893 | if (DEBUG_SWITCH) Slog.v(TAG_SWITCH, |
| 1894 | "Resuming top, waiting visible to hide: " + prev); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 1895 | } else { |
| 1896 | // The next activity is already visible, so hide the previous |
| 1897 | // activity's windows right now so we can show the new one ASAP. |
| 1898 | // We only do this if the previous is finishing, which should mean |
| 1899 | // it is on top of the one being resumed so hiding it quickly |
| 1900 | // is good. Otherwise, we want to do the normal route of allowing |
| 1901 | // the resumed activity to be shown so we can decide if the |
| 1902 | // previous should actually be hidden depending on whether the |
| 1903 | // new one is found to be full-screen or not. |
| 1904 | if (prev.finishing) { |
Craig Mautner | ce5f3cb | 2013-04-22 08:58:54 -0700 | [diff] [blame] | 1905 | mWindowManager.setAppVisibility(prev.appToken, false); |
Wale Ogunwale | ee006da | 2015-03-30 14:49:25 -0700 | [diff] [blame] | 1906 | if (DEBUG_SWITCH) Slog.v(TAG_SWITCH, |
| 1907 | "Not waiting for visible to hide: " + prev + ", waitingVisible=" |
Craig Mautner | 8c14c15 | 2015-01-15 17:32:07 -0800 | [diff] [blame] | 1908 | + mStackSupervisor.mWaitingVisibleActivities.contains(prev) |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 1909 | + ", nowVisible=" + next.nowVisible); |
| 1910 | } else { |
Wale Ogunwale | ee006da | 2015-03-30 14:49:25 -0700 | [diff] [blame] | 1911 | if (DEBUG_SWITCH) Slog.v(TAG_SWITCH, |
Craig Mautner | 8c14c15 | 2015-01-15 17:32:07 -0800 | [diff] [blame] | 1912 | "Previous already visible but still waiting to hide: " + prev |
Wale Ogunwale | ee006da | 2015-03-30 14:49:25 -0700 | [diff] [blame] | 1913 | + ", waitingVisible=" |
| 1914 | + mStackSupervisor.mWaitingVisibleActivities.contains(prev) |
| 1915 | + ", nowVisible=" + next.nowVisible); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 1916 | } |
| 1917 | } |
| 1918 | } |
| 1919 | |
Dianne Hackborn | e7f9721 | 2011-02-24 14:40:20 -0800 | [diff] [blame] | 1920 | // Launching this app's activity, make sure the app is no longer |
| 1921 | // considered stopped. |
| 1922 | try { |
| 1923 | AppGlobals.getPackageManager().setPackageStoppedState( |
Amith Yamasani | 483f3b0 | 2012-03-13 16:08:00 -0700 | [diff] [blame] | 1924 | next.packageName, false, next.userId); /* TODO: Verify if correct userid */ |
Dianne Hackborn | e7f9721 | 2011-02-24 14:40:20 -0800 | [diff] [blame] | 1925 | } catch (RemoteException e1) { |
Dianne Hackborn | a925cd4 | 2011-03-10 13:18:20 -0800 | [diff] [blame] | 1926 | } catch (IllegalArgumentException e) { |
| 1927 | Slog.w(TAG, "Failed trying to unstop package " |
| 1928 | + next.packageName + ": " + e); |
Dianne Hackborn | e7f9721 | 2011-02-24 14:40:20 -0800 | [diff] [blame] | 1929 | } |
| 1930 | |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 1931 | // We are starting up the next activity, so tell the window manager |
| 1932 | // that the previous one will be hidden soon. This way it can know |
| 1933 | // to ignore it when computing the desired screen orientation. |
Craig Mautner | 525f3d9 | 2013-05-07 14:01:50 -0700 | [diff] [blame] | 1934 | boolean anim = true; |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 1935 | if (prev != null) { |
| 1936 | if (prev.finishing) { |
Wale Ogunwale | ee006da | 2015-03-30 14:49:25 -0700 | [diff] [blame] | 1937 | if (DEBUG_TRANSITION) Slog.v(TAG_TRANSITION, |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 1938 | "Prepare close transition: prev=" + prev); |
| 1939 | if (mNoAnimActivities.contains(prev)) { |
Craig Mautner | 525f3d9 | 2013-05-07 14:01:50 -0700 | [diff] [blame] | 1940 | anim = false; |
Craig Mautner | ce5f3cb | 2013-04-22 08:58:54 -0700 | [diff] [blame] | 1941 | mWindowManager.prepareAppTransition(AppTransition.TRANSIT_NONE, false); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 1942 | } else { |
Craig Mautner | ce5f3cb | 2013-04-22 08:58:54 -0700 | [diff] [blame] | 1943 | mWindowManager.prepareAppTransition(prev.task == next.task |
Craig Mautner | 4b71aa1 | 2012-12-27 17:20:01 -0800 | [diff] [blame] | 1944 | ? AppTransition.TRANSIT_ACTIVITY_CLOSE |
| 1945 | : AppTransition.TRANSIT_TASK_CLOSE, false); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 1946 | } |
Craig Mautner | ce5f3cb | 2013-04-22 08:58:54 -0700 | [diff] [blame] | 1947 | mWindowManager.setAppWillBeHidden(prev.appToken); |
| 1948 | mWindowManager.setAppVisibility(prev.appToken, false); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 1949 | } else { |
Wale Ogunwale | ee006da | 2015-03-30 14:49:25 -0700 | [diff] [blame] | 1950 | if (DEBUG_TRANSITION) Slog.v(TAG_TRANSITION, |
| 1951 | "Prepare open transition: prev=" + prev); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 1952 | if (mNoAnimActivities.contains(next)) { |
Craig Mautner | 525f3d9 | 2013-05-07 14:01:50 -0700 | [diff] [blame] | 1953 | anim = false; |
Craig Mautner | ce5f3cb | 2013-04-22 08:58:54 -0700 | [diff] [blame] | 1954 | mWindowManager.prepareAppTransition(AppTransition.TRANSIT_NONE, false); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 1955 | } else { |
Craig Mautner | ce5f3cb | 2013-04-22 08:58:54 -0700 | [diff] [blame] | 1956 | mWindowManager.prepareAppTransition(prev.task == next.task |
Craig Mautner | 4b71aa1 | 2012-12-27 17:20:01 -0800 | [diff] [blame] | 1957 | ? AppTransition.TRANSIT_ACTIVITY_OPEN |
Craig Mautner | bb74246 | 2014-07-07 15:28:55 -0700 | [diff] [blame] | 1958 | : next.mLaunchTaskBehind |
| 1959 | ? AppTransition.TRANSIT_TASK_OPEN_BEHIND |
| 1960 | : AppTransition.TRANSIT_TASK_OPEN, false); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 1961 | } |
| 1962 | } |
| 1963 | if (false) { |
Craig Mautner | ce5f3cb | 2013-04-22 08:58:54 -0700 | [diff] [blame] | 1964 | mWindowManager.setAppWillBeHidden(prev.appToken); |
| 1965 | mWindowManager.setAppVisibility(prev.appToken, false); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 1966 | } |
Craig Mautner | 967212c | 2013-04-13 21:10:58 -0700 | [diff] [blame] | 1967 | } else { |
Wale Ogunwale | ee006da | 2015-03-30 14:49:25 -0700 | [diff] [blame] | 1968 | if (DEBUG_TRANSITION) Slog.v(TAG_TRANSITION, "Prepare open transition: no previous"); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 1969 | if (mNoAnimActivities.contains(next)) { |
Craig Mautner | 525f3d9 | 2013-05-07 14:01:50 -0700 | [diff] [blame] | 1970 | anim = false; |
Craig Mautner | ce5f3cb | 2013-04-22 08:58:54 -0700 | [diff] [blame] | 1971 | mWindowManager.prepareAppTransition(AppTransition.TRANSIT_NONE, false); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 1972 | } else { |
Craig Mautner | ce5f3cb | 2013-04-22 08:58:54 -0700 | [diff] [blame] | 1973 | mWindowManager.prepareAppTransition(AppTransition.TRANSIT_ACTIVITY_OPEN, false); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 1974 | } |
| 1975 | } |
Adam Powell | cfbe9be | 2013-11-06 14:58:58 -0800 | [diff] [blame] | 1976 | |
| 1977 | Bundle resumeAnimOptions = null; |
Craig Mautner | 525f3d9 | 2013-05-07 14:01:50 -0700 | [diff] [blame] | 1978 | if (anim) { |
Adam Powell | cfbe9be | 2013-11-06 14:58:58 -0800 | [diff] [blame] | 1979 | ActivityOptions opts = next.getOptionsForTargetActivityLocked(); |
| 1980 | if (opts != null) { |
| 1981 | resumeAnimOptions = opts.toBundle(); |
| 1982 | } |
Dianne Hackborn | 7a2195c | 2012-03-19 17:38:00 -0700 | [diff] [blame] | 1983 | next.applyOptionsLocked(); |
| 1984 | } else { |
| 1985 | next.clearOptionsLocked(); |
| 1986 | } |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 1987 | |
Craig Mautner | cf910b0 | 2013-04-23 11:23:27 -0700 | [diff] [blame] | 1988 | ActivityStack lastStack = mStackSupervisor.getLastStack(); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 1989 | if (next.app != null && next.app.thread != null) { |
Wale Ogunwale | ee006da | 2015-03-30 14:49:25 -0700 | [diff] [blame] | 1990 | if (DEBUG_SWITCH) Slog.v(TAG_SWITCH, "Resume running: " + next); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 1991 | |
| 1992 | // This activity is now becoming visible. |
Craig Mautner | ce5f3cb | 2013-04-22 08:58:54 -0700 | [diff] [blame] | 1993 | mWindowManager.setAppVisibility(next.appToken, true); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 1994 | |
Dianne Hackborn | 2a29b3a | 2012-03-15 15:48:38 -0700 | [diff] [blame] | 1995 | // schedule launch ticks to collect information about slow apps. |
| 1996 | next.startLaunchTickingLocked(); |
| 1997 | |
Craig Mautner | f88c50f | 2013-04-18 19:25:12 -0700 | [diff] [blame] | 1998 | ActivityRecord lastResumedActivity = |
| 1999 | lastStack == null ? null :lastStack.mResumedActivity; |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 2000 | ActivityState lastState = next.state; |
| 2001 | |
| 2002 | mService.updateCpuStats(); |
Craig Mautner | 5854780 | 2013-03-05 08:23:53 -0800 | [diff] [blame] | 2003 | |
Wale Ogunwale | 0fc365c | 2015-05-25 19:35:42 -0700 | [diff] [blame] | 2004 | if (DEBUG_STATES) Slog.v(TAG_STATES, "Moving to RESUMED: " + next + " (in existing)"); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 2005 | next.state = ActivityState.RESUMED; |
| 2006 | mResumedActivity = next; |
| 2007 | next.task.touchActiveTime(); |
Wale Ogunwale | c82f2f5 | 2014-12-09 09:32:50 -0800 | [diff] [blame] | 2008 | mRecentTasks.addLocked(next.task); |
Dianne Hackborn | db92608 | 2013-10-31 16:32:44 -0700 | [diff] [blame] | 2009 | mService.updateLruProcessLocked(next.app, true, null); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 2010 | updateLRUListLocked(next); |
Dianne Hackborn | db92608 | 2013-10-31 16:32:44 -0700 | [diff] [blame] | 2011 | mService.updateOomAdjLocked(); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 2012 | |
| 2013 | // Have the window manager re-evaluate the orientation of |
| 2014 | // the screen based on the new activity order. |
Craig Mautner | 525f3d9 | 2013-05-07 14:01:50 -0700 | [diff] [blame] | 2015 | boolean notUpdated = true; |
Craig Mautner | de4ef02 | 2013-04-07 19:01:33 -0700 | [diff] [blame] | 2016 | if (mStackSupervisor.isFrontStack(this)) { |
Craig Mautner | ce5f3cb | 2013-04-22 08:58:54 -0700 | [diff] [blame] | 2017 | Configuration config = mWindowManager.updateOrientationFromAppTokens( |
Craig Mautner | 8d341ef | 2013-03-26 09:03:27 -0700 | [diff] [blame] | 2018 | mService.mConfiguration, |
| 2019 | next.mayFreezeScreenLocked(next.app) ? next.appToken : null); |
| 2020 | if (config != null) { |
| 2021 | next.frozenBeforeDestroy = true; |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 2022 | } |
Maxim Bogatov | 0507530 | 2015-05-19 18:33:08 -0700 | [diff] [blame] | 2023 | notUpdated = !mService.updateConfigurationLocked(config, next, false); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 2024 | } |
Craig Mautner | 8d341ef | 2013-03-26 09:03:27 -0700 | [diff] [blame] | 2025 | |
Craig Mautner | 525f3d9 | 2013-05-07 14:01:50 -0700 | [diff] [blame] | 2026 | if (notUpdated) { |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 2027 | // The configuration update wasn't able to keep the existing |
| 2028 | // instance of the activity, and instead started a new one. |
| 2029 | // We should be all done, but let's just make sure our activity |
| 2030 | // is still at the top and schedule another run if something |
| 2031 | // weird happened. |
| 2032 | ActivityRecord nextNext = topRunningActivityLocked(null); |
Wale Ogunwale | 0fc365c | 2015-05-25 19:35:42 -0700 | [diff] [blame] | 2033 | if (DEBUG_SWITCH || DEBUG_STATES) Slog.i(TAG_STATES, |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 2034 | "Activity config changed during resume: " + next |
| 2035 | + ", new next: " + nextNext); |
| 2036 | if (nextNext != next) { |
| 2037 | // Do over! |
Craig Mautner | 05d2903 | 2013-05-03 13:40:13 -0700 | [diff] [blame] | 2038 | mStackSupervisor.scheduleResumeTopActivities(); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 2039 | } |
Craig Mautner | ce5f3cb | 2013-04-22 08:58:54 -0700 | [diff] [blame] | 2040 | if (mStackSupervisor.reportResumedActivityLocked(next)) { |
Craig Mautner | de4ef02 | 2013-04-07 19:01:33 -0700 | [diff] [blame] | 2041 | mNoAnimActivities.clear(); |
Craig Mautner | cf910b0 | 2013-04-23 11:23:27 -0700 | [diff] [blame] | 2042 | if (DEBUG_STACK) mStackSupervisor.validateTopActivitiesLocked(); |
Craig Mautner | de4ef02 | 2013-04-07 19:01:33 -0700 | [diff] [blame] | 2043 | return true; |
| 2044 | } |
Craig Mautner | cf910b0 | 2013-04-23 11:23:27 -0700 | [diff] [blame] | 2045 | if (DEBUG_STACK) mStackSupervisor.validateTopActivitiesLocked(); |
Craig Mautner | de4ef02 | 2013-04-07 19:01:33 -0700 | [diff] [blame] | 2046 | return false; |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 2047 | } |
Craig Mautner | 5854780 | 2013-03-05 08:23:53 -0800 | [diff] [blame] | 2048 | |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 2049 | try { |
| 2050 | // Deliver all pending results. |
Craig Mautner | 05d6272ba | 2013-02-11 09:39:27 -0800 | [diff] [blame] | 2051 | ArrayList<ResultInfo> a = next.results; |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 2052 | if (a != null) { |
| 2053 | final int N = a.size(); |
| 2054 | if (!next.finishing && N > 0) { |
Wale Ogunwale | ee006da | 2015-03-30 14:49:25 -0700 | [diff] [blame] | 2055 | if (DEBUG_RESULTS) Slog.v(TAG_RESULTS, |
| 2056 | "Delivering results to " + next + ": " + a); |
Dianne Hackborn | be70785 | 2011-11-11 14:32:10 -0800 | [diff] [blame] | 2057 | next.app.thread.scheduleSendResult(next.appToken, a); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 2058 | } |
| 2059 | } |
| 2060 | |
| 2061 | if (next.newIntents != null) { |
Dianne Hackborn | be70785 | 2011-11-11 14:32:10 -0800 | [diff] [blame] | 2062 | next.app.thread.scheduleNewIntent(next.newIntents, next.appToken); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 2063 | } |
| 2064 | |
Craig Mautner | 299f960 | 2015-01-26 09:47:33 -0800 | [diff] [blame] | 2065 | EventLog.writeEvent(EventLogTags.AM_RESUME_ACTIVITY, next.userId, |
| 2066 | System.identityHashCode(next), next.task.taskId, next.shortComponentName); |
Craig Mautner | 5854780 | 2013-03-05 08:23:53 -0800 | [diff] [blame] | 2067 | |
Dianne Hackborn | 4eba96b | 2011-01-21 13:34:36 -0800 | [diff] [blame] | 2068 | next.sleeping = false; |
Craig Mautner | 2420ead | 2013-04-01 17:13:20 -0700 | [diff] [blame] | 2069 | mService.showAskCompatModeDialogLocked(next); |
Dianne Hackborn | 905577f | 2011-09-07 18:31:28 -0700 | [diff] [blame] | 2070 | next.app.pendingUiClean = true; |
Dianne Hackborn | 4870e9d | 2015-04-08 16:55:47 -0700 | [diff] [blame] | 2071 | next.app.forceProcessStateUpTo(mService.mTopProcessState); |
George Mount | 2c92c97 | 2014-03-20 09:38:23 -0700 | [diff] [blame] | 2072 | next.clearOptionsLocked(); |
Dianne Hackborn | a413dc0 | 2013-07-12 12:02:55 -0700 | [diff] [blame] | 2073 | next.app.thread.scheduleResumeActivity(next.appToken, next.app.repProcState, |
Adam Powell | cfbe9be | 2013-11-06 14:58:58 -0800 | [diff] [blame] | 2074 | mService.isNextTransitionForward(), resumeAnimOptions); |
Craig Mautner | 5854780 | 2013-03-05 08:23:53 -0800 | [diff] [blame] | 2075 | |
Craig Mautner | 0eea92c | 2013-05-16 13:35:39 -0700 | [diff] [blame] | 2076 | mStackSupervisor.checkReadyForSleepLocked(); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 2077 | |
Wale Ogunwale | 0fc365c | 2015-05-25 19:35:42 -0700 | [diff] [blame] | 2078 | if (DEBUG_STATES) Slog.d(TAG_STATES, "resumeTopActivityLocked: Resumed " + next); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 2079 | } catch (Exception e) { |
| 2080 | // Whoops, need to restart this activity! |
Wale Ogunwale | 0fc365c | 2015-05-25 19:35:42 -0700 | [diff] [blame] | 2081 | if (DEBUG_STATES) Slog.v(TAG_STATES, "Resume failed; resetting state to " |
Dianne Hackborn | ce86ba8 | 2011-07-13 19:33:41 -0700 | [diff] [blame] | 2082 | + lastState + ": " + next); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 2083 | next.state = lastState; |
Craig Mautner | f88c50f | 2013-04-18 19:25:12 -0700 | [diff] [blame] | 2084 | if (lastStack != null) { |
| 2085 | lastStack.mResumedActivity = lastResumedActivity; |
| 2086 | } |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 2087 | Slog.i(TAG, "Restarting because process died: " + next); |
| 2088 | if (!next.hasBeenLaunched) { |
| 2089 | next.hasBeenLaunched = true; |
Craig Mautner | f88c50f | 2013-04-18 19:25:12 -0700 | [diff] [blame] | 2090 | } else if (SHOW_APP_STARTING_PREVIEW && lastStack != null && |
| 2091 | mStackSupervisor.isFrontStack(lastStack)) { |
Craig Mautner | ce5f3cb | 2013-04-22 08:58:54 -0700 | [diff] [blame] | 2092 | mWindowManager.setAppStartingWindow( |
Craig Mautner | f88c50f | 2013-04-18 19:25:12 -0700 | [diff] [blame] | 2093 | next.appToken, next.packageName, next.theme, |
| 2094 | mService.compatibilityInfoForPackageLocked(next.info.applicationInfo), |
Adam Powell | 04fe6eb | 2013-05-31 14:39:48 -0700 | [diff] [blame] | 2095 | next.nonLocalizedLabel, next.labelRes, next.icon, next.logo, |
| 2096 | next.windowFlags, null, true); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 2097 | } |
George Mount | 2c92c97 | 2014-03-20 09:38:23 -0700 | [diff] [blame] | 2098 | mStackSupervisor.startSpecificActivityLocked(next, true, false); |
Craig Mautner | cf910b0 | 2013-04-23 11:23:27 -0700 | [diff] [blame] | 2099 | if (DEBUG_STACK) mStackSupervisor.validateTopActivitiesLocked(); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 2100 | return true; |
| 2101 | } |
| 2102 | |
| 2103 | // From this point on, if something goes wrong there is no way |
| 2104 | // to recover the activity. |
| 2105 | try { |
| 2106 | next.visible = true; |
| 2107 | completeResumeLocked(next); |
| 2108 | } catch (Exception e) { |
| 2109 | // If any exception gets thrown, toss away this |
| 2110 | // activity and try the next one. |
| 2111 | Slog.w(TAG, "Exception thrown during resume of " + next, e); |
Dianne Hackborn | be70785 | 2011-11-11 14:32:10 -0800 | [diff] [blame] | 2112 | requestFinishActivityLocked(next.appToken, Activity.RESULT_CANCELED, null, |
Dianne Hackborn | 2d1b378 | 2012-09-09 17:49:39 -0700 | [diff] [blame] | 2113 | "resume-exception", true); |
Craig Mautner | cf910b0 | 2013-04-23 11:23:27 -0700 | [diff] [blame] | 2114 | if (DEBUG_STACK) mStackSupervisor.validateTopActivitiesLocked(); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 2115 | return true; |
| 2116 | } |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 2117 | next.stopped = false; |
| 2118 | |
| 2119 | } else { |
| 2120 | // Whoops, need to restart this activity! |
| 2121 | if (!next.hasBeenLaunched) { |
| 2122 | next.hasBeenLaunched = true; |
| 2123 | } else { |
| 2124 | if (SHOW_APP_STARTING_PREVIEW) { |
Craig Mautner | ce5f3cb | 2013-04-22 08:58:54 -0700 | [diff] [blame] | 2125 | mWindowManager.setAppStartingWindow( |
Dianne Hackborn | be70785 | 2011-11-11 14:32:10 -0800 | [diff] [blame] | 2126 | next.appToken, next.packageName, next.theme, |
Dianne Hackborn | 2f0b175 | 2011-05-31 17:59:49 -0700 | [diff] [blame] | 2127 | mService.compatibilityInfoForPackageLocked( |
| 2128 | next.info.applicationInfo), |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 2129 | next.nonLocalizedLabel, |
Adam Powell | 04fe6eb | 2013-05-31 14:39:48 -0700 | [diff] [blame] | 2130 | next.labelRes, next.icon, next.logo, next.windowFlags, |
Dianne Hackborn | 7eec10e | 2010-11-12 18:03:47 -0800 | [diff] [blame] | 2131 | null, true); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 2132 | } |
Wale Ogunwale | ee006da | 2015-03-30 14:49:25 -0700 | [diff] [blame] | 2133 | if (DEBUG_SWITCH) Slog.v(TAG_SWITCH, "Restarting: " + next); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 2134 | } |
Wale Ogunwale | 0fc365c | 2015-05-25 19:35:42 -0700 | [diff] [blame] | 2135 | if (DEBUG_STATES) Slog.d(TAG_STATES, "resumeTopActivityLocked: Restarting " + next); |
George Mount | 2c92c97 | 2014-03-20 09:38:23 -0700 | [diff] [blame] | 2136 | mStackSupervisor.startSpecificActivityLocked(next, true, true); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 2137 | } |
| 2138 | |
Craig Mautner | cf910b0 | 2013-04-23 11:23:27 -0700 | [diff] [blame] | 2139 | if (DEBUG_STACK) mStackSupervisor.validateTopActivitiesLocked(); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 2140 | return true; |
| 2141 | } |
| 2142 | |
riddle_hsu | c215a4f | 2014-12-27 12:10:45 +0800 | [diff] [blame] | 2143 | private TaskRecord getNextTask(TaskRecord targetTask) { |
| 2144 | final int index = mTaskHistory.indexOf(targetTask); |
| 2145 | if (index >= 0) { |
| 2146 | final int numTasks = mTaskHistory.size(); |
| 2147 | for (int i = index + 1; i < numTasks; ++i) { |
| 2148 | TaskRecord task = mTaskHistory.get(i); |
| 2149 | if (task.userId == targetTask.userId) { |
| 2150 | return task; |
| 2151 | } |
| 2152 | } |
| 2153 | } |
| 2154 | return null; |
| 2155 | } |
| 2156 | |
Wale Ogunwale | ddc1cb2 | 2015-07-25 19:23:04 -0700 | [diff] [blame] | 2157 | private void insertTaskAtPosition(TaskRecord task, int position) { |
| 2158 | if (position >= mTaskHistory.size()) { |
| 2159 | insertTaskAtTop(task, null); |
| 2160 | return; |
| 2161 | } |
| 2162 | // Calculate maximum possible position for this task. |
| 2163 | int maxPosition = mTaskHistory.size(); |
| 2164 | if (!mStackSupervisor.isCurrentProfileLocked(task.userId) |
| 2165 | && task.topRunningActivityLocked(null) == null) { |
| 2166 | // Put non-current user tasks below current user tasks. |
| 2167 | while (maxPosition > 0) { |
| 2168 | final TaskRecord tmpTask = mTaskHistory.get(maxPosition - 1); |
| 2169 | if (!mStackSupervisor.isCurrentProfileLocked(tmpTask.userId) |
| 2170 | || tmpTask.topRunningActivityLocked(null) == null) { |
| 2171 | break; |
| 2172 | } |
| 2173 | maxPosition--; |
| 2174 | } |
| 2175 | } |
| 2176 | position = Math.min(position, maxPosition); |
| 2177 | mTaskHistory.remove(task); |
| 2178 | mTaskHistory.add(position, task); |
| 2179 | updateTaskMovement(task, true); |
| 2180 | } |
| 2181 | |
Wale Ogunwale | 3fcb4a8 | 2015-04-06 14:00:13 -0700 | [diff] [blame] | 2182 | private void insertTaskAtTop(TaskRecord task, ActivityRecord newActivity) { |
riddle_hsu | c215a4f | 2014-12-27 12:10:45 +0800 | [diff] [blame] | 2183 | // If the moving task is over home stack, transfer its return type to next task |
| 2184 | if (task.isOverHomeStack()) { |
| 2185 | final TaskRecord nextTask = getNextTask(task); |
| 2186 | if (nextTask != null) { |
| 2187 | nextTask.setTaskToReturnTo(task.getTaskToReturnTo()); |
| 2188 | } |
| 2189 | } |
| 2190 | |
Craig Mautner | 9c85c20 | 2013-10-04 20:11:26 -0700 | [diff] [blame] | 2191 | // 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] | 2192 | // activity, set mTaskToReturnTo accordingly. |
Craig Mautner | e0a3884 | 2013-12-16 16:14:02 -0800 | [diff] [blame] | 2193 | if (isOnHomeDisplay()) { |
| 2194 | ActivityStack lastStack = mStackSupervisor.getLastStack(); |
| 2195 | final boolean fromHome = lastStack.isHomeStack(); |
| 2196 | if (!isHomeStack() && (fromHome || topTask() != task)) { |
Craig Mautner | 3b1dac8 | 2014-07-15 09:51:33 -0700 | [diff] [blame] | 2197 | task.setTaskToReturnTo(fromHome |
| 2198 | ? lastStack.topTask() == null |
| 2199 | ? HOME_ACTIVITY_TYPE |
| 2200 | : lastStack.topTask().taskType |
| 2201 | : APPLICATION_ACTIVITY_TYPE); |
Craig Mautner | e0a3884 | 2013-12-16 16:14:02 -0800 | [diff] [blame] | 2202 | } |
| 2203 | } else { |
Craig Mautner | 84984fa | 2014-06-19 11:19:20 -0700 | [diff] [blame] | 2204 | task.setTaskToReturnTo(APPLICATION_ACTIVITY_TYPE); |
Craig Mautner | 9c85c20 | 2013-10-04 20:11:26 -0700 | [diff] [blame] | 2205 | } |
Craig Mautner | d99384d | 2013-10-14 07:09:18 -0700 | [diff] [blame] | 2206 | |
Craig Mautner | ac6f843 | 2013-07-17 13:24:59 -0700 | [diff] [blame] | 2207 | mTaskHistory.remove(task); |
| 2208 | // Now put task at top. |
Craig Mautner | bb74246 | 2014-07-07 15:28:55 -0700 | [diff] [blame] | 2209 | int taskNdx = mTaskHistory.size(); |
Wale Ogunwale | 3fcb4a8 | 2015-04-06 14:00:13 -0700 | [diff] [blame] | 2210 | final boolean notShownWhenLocked = |
Wale Ogunwale | 6dfdfd6 | 2015-04-15 12:01:38 -0700 | [diff] [blame] | 2211 | (newActivity != null && (newActivity.info.flags & FLAG_SHOW_FOR_ALL_USERS) == 0) |
Wale Ogunwale | 3fcb4a8 | 2015-04-06 14:00:13 -0700 | [diff] [blame] | 2212 | || (newActivity == null && task.topRunningActivityLocked(null) == null); |
Wale Ogunwale | 0bd2aa7 | 2015-04-16 13:50:44 -0700 | [diff] [blame] | 2213 | if (!mStackSupervisor.isCurrentProfileLocked(task.userId) && notShownWhenLocked) { |
Craig Mautner | ac6f843 | 2013-07-17 13:24:59 -0700 | [diff] [blame] | 2214 | // Put non-current user tasks below current user tasks. |
Craig Mautner | bb74246 | 2014-07-07 15:28:55 -0700 | [diff] [blame] | 2215 | while (--taskNdx >= 0) { |
Wale Ogunwale | 3fcb4a8 | 2015-04-06 14:00:13 -0700 | [diff] [blame] | 2216 | final TaskRecord tmpTask = mTaskHistory.get(taskNdx); |
Wale Ogunwale | 0bd2aa7 | 2015-04-16 13:50:44 -0700 | [diff] [blame] | 2217 | if (!mStackSupervisor.isCurrentProfileLocked(tmpTask.userId) |
Wale Ogunwale | 3fcb4a8 | 2015-04-06 14:00:13 -0700 | [diff] [blame] | 2218 | || tmpTask.topRunningActivityLocked(null) == null) { |
Craig Mautner | ac6f843 | 2013-07-17 13:24:59 -0700 | [diff] [blame] | 2219 | break; |
| 2220 | } |
| 2221 | } |
Craig Mautner | bb74246 | 2014-07-07 15:28:55 -0700 | [diff] [blame] | 2222 | ++taskNdx; |
Craig Mautner | ac6f843 | 2013-07-17 13:24:59 -0700 | [diff] [blame] | 2223 | } |
Craig Mautner | bb74246 | 2014-07-07 15:28:55 -0700 | [diff] [blame] | 2224 | mTaskHistory.add(taskNdx, task); |
Craig Mautner | 21d24a2 | 2014-04-23 11:45:37 -0700 | [diff] [blame] | 2225 | updateTaskMovement(task, true); |
Craig Mautner | ac6f843 | 2013-07-17 13:24:59 -0700 | [diff] [blame] | 2226 | } |
Craig Mautner | 11bf9a5 | 2013-02-19 14:08:51 -0800 | [diff] [blame] | 2227 | |
Craig Mautner | 8849a5e | 2013-04-02 16:41:03 -0700 | [diff] [blame] | 2228 | final void startActivityLocked(ActivityRecord r, boolean newTask, |
Dianne Hackborn | 7a2195c | 2012-03-19 17:38:00 -0700 | [diff] [blame] | 2229 | boolean doResume, boolean keepCurTransition, Bundle options) { |
Craig Mautner | d232895 | 2013-03-05 12:46:26 -0800 | [diff] [blame] | 2230 | TaskRecord rTask = r.task; |
| 2231 | final int taskId = rTask.taskId; |
Craig Mautner | bb74246 | 2014-07-07 15:28:55 -0700 | [diff] [blame] | 2232 | // mLaunchTaskBehind tasks get placed at the back of the task stack. |
| 2233 | if (!r.mLaunchTaskBehind && (taskForIdLocked(taskId) == null || newTask)) { |
Craig Mautner | 7787877 | 2013-03-04 19:46:24 -0800 | [diff] [blame] | 2234 | // Last activity in task had been removed or ActivityManagerService is reusing task. |
| 2235 | // Insert or replace. |
Craig Mautner | 7787877 | 2013-03-04 19:46:24 -0800 | [diff] [blame] | 2236 | // Might not even be in. |
Wale Ogunwale | 3fcb4a8 | 2015-04-06 14:00:13 -0700 | [diff] [blame] | 2237 | insertTaskAtTop(rTask, r); |
Craig Mautner | ce5f3cb | 2013-04-22 08:58:54 -0700 | [diff] [blame] | 2238 | mWindowManager.moveTaskToTop(taskId); |
Craig Mautner | 7787877 | 2013-03-04 19:46:24 -0800 | [diff] [blame] | 2239 | } |
Craig Mautner | 525f3d9 | 2013-05-07 14:01:50 -0700 | [diff] [blame] | 2240 | TaskRecord task = null; |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 2241 | if (!newTask) { |
| 2242 | // If starting in an existing task, find where that is... |
Craig Mautner | 70a8693 | 2013-02-28 22:37:44 -0800 | [diff] [blame] | 2243 | boolean startIt = true; |
| 2244 | for (int taskNdx = mTaskHistory.size() - 1; taskNdx >= 0; --taskNdx) { |
| 2245 | task = mTaskHistory.get(taskNdx); |
riddle_hsu | 9bcc6e8 | 2014-07-31 00:26:51 +0800 | [diff] [blame] | 2246 | if (task.getTopActivity() == null) { |
| 2247 | // All activities in task are finishing. |
| 2248 | continue; |
| 2249 | } |
Craig Mautner | 70a8693 | 2013-02-28 22:37:44 -0800 | [diff] [blame] | 2250 | if (task == r.task) { |
| 2251 | // Here it is! Now, if this is not yet visible to the |
| 2252 | // user, then just add it without starting; it will |
| 2253 | // get started when the user navigates back to it. |
Craig Mautner | 70a8693 | 2013-02-28 22:37:44 -0800 | [diff] [blame] | 2254 | if (!startIt) { |
| 2255 | if (DEBUG_ADD_REMOVE) Slog.i(TAG, "Adding activity " + r + " to task " |
| 2256 | + task, new RuntimeException("here").fillInStackTrace()); |
| 2257 | task.addActivityToTop(r); |
Dianne Hackborn | f26fd99 | 2011-04-08 18:14:09 -0700 | [diff] [blame] | 2258 | r.putInHistory(); |
Filip Gruszczynski | e5390e7 | 2015-08-18 16:39:00 -0700 | [diff] [blame] | 2259 | addConfigOverride(r, task); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 2260 | if (VALIDATE_TOKENS) { |
Dianne Hackborn | be70785 | 2011-11-11 14:32:10 -0800 | [diff] [blame] | 2261 | validateAppTokensLocked(); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 2262 | } |
Dianne Hackborn | 8078d8c | 2012-03-20 11:11:26 -0700 | [diff] [blame] | 2263 | ActivityOptions.abort(options); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 2264 | return; |
| 2265 | } |
| 2266 | break; |
Craig Mautner | 70a8693 | 2013-02-28 22:37:44 -0800 | [diff] [blame] | 2267 | } else if (task.numFullscreen > 0) { |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 2268 | startIt = false; |
| 2269 | } |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 2270 | } |
| 2271 | } |
| 2272 | |
| 2273 | // Place a new activity at top of stack, so it is next to interact |
| 2274 | // with the user. |
Craig Mautner | 70a8693 | 2013-02-28 22:37:44 -0800 | [diff] [blame] | 2275 | |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 2276 | // If we are not placing the new activity frontmost, we do not want |
| 2277 | // to deliver the onUserLeaving callback to the actual frontmost |
| 2278 | // activity |
Craig Mautner | 70a8693 | 2013-02-28 22:37:44 -0800 | [diff] [blame] | 2279 | if (task == r.task && mTaskHistory.indexOf(task) != (mTaskHistory.size() - 1)) { |
Craig Mautner | de4ef02 | 2013-04-07 19:01:33 -0700 | [diff] [blame] | 2280 | mStackSupervisor.mUserLeaving = false; |
Wale Ogunwale | ee006da | 2015-03-30 14:49:25 -0700 | [diff] [blame] | 2281 | if (DEBUG_USER_LEAVING) Slog.v(TAG_USER_LEAVING, |
Craig Mautner | 70a8693 | 2013-02-28 22:37:44 -0800 | [diff] [blame] | 2282 | "startActivity() behind front, mUserLeaving=false"); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 2283 | } |
Craig Mautner | 70a8693 | 2013-02-28 22:37:44 -0800 | [diff] [blame] | 2284 | |
| 2285 | task = r.task; |
| 2286 | |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 2287 | // Slot the activity into the history stack and proceed |
Craig Mautner | 70a8693 | 2013-02-28 22:37:44 -0800 | [diff] [blame] | 2288 | 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] | 2289 | new RuntimeException("here").fillInStackTrace()); |
Craig Mautner | 70a8693 | 2013-02-28 22:37:44 -0800 | [diff] [blame] | 2290 | task.addActivityToTop(r); |
Craig Mautner | 1aa9d0d3f | 2013-12-16 15:58:31 -0800 | [diff] [blame] | 2291 | task.setFrontOfTask(); |
Craig Mautner | 70a8693 | 2013-02-28 22:37:44 -0800 | [diff] [blame] | 2292 | |
Dianne Hackborn | f26fd99 | 2011-04-08 18:14:09 -0700 | [diff] [blame] | 2293 | r.putInHistory(); |
Craig Mautner | de4ef02 | 2013-04-07 19:01:33 -0700 | [diff] [blame] | 2294 | if (!isHomeStack() || numActivities() > 0) { |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 2295 | // We want to show the starting preview window if we are |
| 2296 | // switching to a new task, or the next activity's process is |
| 2297 | // not currently running. |
| 2298 | boolean showStartingIcon = newTask; |
| 2299 | ProcessRecord proc = r.app; |
| 2300 | if (proc == null) { |
| 2301 | proc = mService.mProcessNames.get(r.processName, r.info.applicationInfo.uid); |
| 2302 | } |
| 2303 | if (proc == null || proc.thread == null) { |
| 2304 | showStartingIcon = true; |
| 2305 | } |
Wale Ogunwale | ee006da | 2015-03-30 14:49:25 -0700 | [diff] [blame] | 2306 | if (DEBUG_TRANSITION) Slog.v(TAG_TRANSITION, |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 2307 | "Prepare open transition: starting " + r); |
Wale Ogunwale | ee006da | 2015-03-30 14:49:25 -0700 | [diff] [blame] | 2308 | if ((r.intent.getFlags() & Intent.FLAG_ACTIVITY_NO_ANIMATION) != 0) { |
Craig Mautner | ce5f3cb | 2013-04-22 08:58:54 -0700 | [diff] [blame] | 2309 | mWindowManager.prepareAppTransition(AppTransition.TRANSIT_NONE, keepCurTransition); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 2310 | mNoAnimActivities.add(r); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 2311 | } else { |
Craig Mautner | ce5f3cb | 2013-04-22 08:58:54 -0700 | [diff] [blame] | 2312 | mWindowManager.prepareAppTransition(newTask |
Craig Mautner | bb74246 | 2014-07-07 15:28:55 -0700 | [diff] [blame] | 2313 | ? r.mLaunchTaskBehind |
| 2314 | ? AppTransition.TRANSIT_TASK_OPEN_BEHIND |
| 2315 | : AppTransition.TRANSIT_TASK_OPEN |
Craig Mautner | 4b71aa1 | 2012-12-27 17:20:01 -0800 | [diff] [blame] | 2316 | : AppTransition.TRANSIT_ACTIVITY_OPEN, keepCurTransition); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 2317 | mNoAnimActivities.remove(r); |
| 2318 | } |
Filip Gruszczynski | e5390e7 | 2015-08-18 16:39:00 -0700 | [diff] [blame] | 2319 | addConfigOverride(r, task); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 2320 | boolean doShow = true; |
| 2321 | if (newTask) { |
| 2322 | // Even though this activity is starting fresh, we still need |
| 2323 | // to reset it to make sure we apply affinities to move any |
| 2324 | // existing activities from other tasks in to it. |
| 2325 | // If the caller has requested that the target task be |
| 2326 | // reset, then do so. |
Craig Mautner | 9d4e9bc | 2014-06-18 18:34:56 -0700 | [diff] [blame] | 2327 | if ((r.intent.getFlags() & Intent.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED) != 0) { |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 2328 | resetTaskIfNeededLocked(r, r); |
| 2329 | doShow = topRunningNonDelayedActivityLocked(null) == r; |
| 2330 | } |
George Mount | 70778d7 | 2014-07-01 16:33:45 -0700 | [diff] [blame] | 2331 | } else if (options != null && new ActivityOptions(options).getAnimationType() |
| 2332 | == ActivityOptions.ANIM_SCENE_TRANSITION) { |
| 2333 | doShow = false; |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 2334 | } |
Craig Mautner | bb74246 | 2014-07-07 15:28:55 -0700 | [diff] [blame] | 2335 | if (r.mLaunchTaskBehind) { |
| 2336 | // Don't do a starting window for mLaunchTaskBehind. More importantly make sure we |
| 2337 | // tell WindowManager that r is visible even though it is at the back of the stack. |
| 2338 | mWindowManager.setAppVisibility(r.appToken, true); |
| 2339 | ensureActivitiesVisibleLocked(null, 0); |
| 2340 | } else if (SHOW_APP_STARTING_PREVIEW && doShow) { |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 2341 | // Figure out if we are transitioning from another activity that is |
| 2342 | // "has the same starting icon" as the next one. This allows the |
| 2343 | // window manager to keep the previous window it had previously |
| 2344 | // created, if it still had one. |
| 2345 | ActivityRecord prev = mResumedActivity; |
| 2346 | if (prev != null) { |
| 2347 | // We don't want to reuse the previous starting preview if: |
| 2348 | // (1) The current activity is in a different task. |
Craig Mautner | 29219d9 | 2013-04-16 20:19:12 -0700 | [diff] [blame] | 2349 | if (prev.task != r.task) { |
| 2350 | prev = null; |
| 2351 | } |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 2352 | // (2) The current activity is already displayed. |
Craig Mautner | 29219d9 | 2013-04-16 20:19:12 -0700 | [diff] [blame] | 2353 | else if (prev.nowVisible) { |
| 2354 | prev = null; |
| 2355 | } |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 2356 | } |
Craig Mautner | ce5f3cb | 2013-04-22 08:58:54 -0700 | [diff] [blame] | 2357 | mWindowManager.setAppStartingWindow( |
Dianne Hackborn | be70785 | 2011-11-11 14:32:10 -0800 | [diff] [blame] | 2358 | r.appToken, r.packageName, r.theme, |
Dianne Hackborn | 2f0b175 | 2011-05-31 17:59:49 -0700 | [diff] [blame] | 2359 | mService.compatibilityInfoForPackageLocked( |
| 2360 | r.info.applicationInfo), r.nonLocalizedLabel, |
Adam Powell | 04fe6eb | 2013-05-31 14:39:48 -0700 | [diff] [blame] | 2361 | r.labelRes, r.icon, r.logo, r.windowFlags, |
Dianne Hackborn | be70785 | 2011-11-11 14:32:10 -0800 | [diff] [blame] | 2362 | prev != null ? prev.appToken : null, showStartingIcon); |
Craig Mautner | a61bc65 | 2013-10-28 15:43:18 -0700 | [diff] [blame] | 2363 | r.mStartingWindowShown = true; |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 2364 | } |
| 2365 | } else { |
| 2366 | // If this is the first activity, don't do any fancy animations, |
| 2367 | // because there is nothing for it to animate on top of. |
Filip Gruszczynski | e5390e7 | 2015-08-18 16:39:00 -0700 | [diff] [blame] | 2368 | addConfigOverride(r, task); |
Dianne Hackborn | 8078d8c | 2012-03-20 11:11:26 -0700 | [diff] [blame] | 2369 | ActivityOptions.abort(options); |
Craig Mautner | 233ceee | 2014-05-09 17:05:11 -0700 | [diff] [blame] | 2370 | options = null; |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 2371 | } |
| 2372 | if (VALIDATE_TOKENS) { |
Dianne Hackborn | be70785 | 2011-11-11 14:32:10 -0800 | [diff] [blame] | 2373 | validateAppTokensLocked(); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 2374 | } |
| 2375 | |
| 2376 | if (doResume) { |
Craig Mautner | 233ceee | 2014-05-09 17:05:11 -0700 | [diff] [blame] | 2377 | mStackSupervisor.resumeTopActivitiesLocked(this, r, options); |
Chong Zhang | 45c25ce | 2015-08-10 22:18:26 -0700 | [diff] [blame] | 2378 | } else { |
| 2379 | addRecentActivityLocked(r); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 2380 | } |
| 2381 | } |
| 2382 | |
Dianne Hackborn | be70785 | 2011-11-11 14:32:10 -0800 | [diff] [blame] | 2383 | final void validateAppTokensLocked() { |
| 2384 | mValidateAppTokens.clear(); |
Craig Mautner | 000f002 | 2013-02-26 15:04:29 -0800 | [diff] [blame] | 2385 | mValidateAppTokens.ensureCapacity(numActivities()); |
| 2386 | final int numTasks = mTaskHistory.size(); |
| 2387 | for (int taskNdx = 0; taskNdx < numTasks; ++taskNdx) { |
| 2388 | TaskRecord task = mTaskHistory.get(taskNdx); |
| 2389 | final ArrayList<ActivityRecord> activities = task.mActivities; |
Craig Mautner | c8143c6 | 2013-09-03 12:15:57 -0700 | [diff] [blame] | 2390 | if (activities.isEmpty()) { |
Craig Mautner | 000f002 | 2013-02-26 15:04:29 -0800 | [diff] [blame] | 2391 | continue; |
Craig Mautner | b1fd65c0 | 2013-02-05 13:34:57 -0800 | [diff] [blame] | 2392 | } |
Craig Mautner | 000f002 | 2013-02-26 15:04:29 -0800 | [diff] [blame] | 2393 | TaskGroup group = new TaskGroup(); |
| 2394 | group.taskId = task.taskId; |
| 2395 | mValidateAppTokens.add(group); |
| 2396 | final int numActivities = activities.size(); |
| 2397 | for (int activityNdx = 0; activityNdx < numActivities; ++activityNdx) { |
| 2398 | final ActivityRecord r = activities.get(activityNdx); |
| 2399 | group.tokens.add(r.appToken); |
| 2400 | } |
Dianne Hackborn | be70785 | 2011-11-11 14:32:10 -0800 | [diff] [blame] | 2401 | } |
Craig Mautner | ce5f3cb | 2013-04-22 08:58:54 -0700 | [diff] [blame] | 2402 | mWindowManager.validateAppTokens(mStackId, mValidateAppTokens); |
Dianne Hackborn | be70785 | 2011-11-11 14:32:10 -0800 | [diff] [blame] | 2403 | } |
| 2404 | |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 2405 | /** |
| 2406 | * Perform a reset of the given task, if needed as part of launching it. |
| 2407 | * Returns the new HistoryRecord at the top of the task. |
| 2408 | */ |
Craig Mautner | e3a74d5 | 2013-02-22 14:14:58 -0800 | [diff] [blame] | 2409 | /** |
| 2410 | * Helper method for #resetTaskIfNeededLocked. |
| 2411 | * We are inside of the task being reset... we'll either finish this activity, push it out |
| 2412 | * for another task, or leave it as-is. |
| 2413 | * @param task The task containing the Activity (taskTop) that might be reset. |
| 2414 | * @param forceReset |
| 2415 | * @return An ActivityOptions that needs to be processed. |
| 2416 | */ |
Craig Mautner | ce5f3cb | 2013-04-22 08:58:54 -0700 | [diff] [blame] | 2417 | final ActivityOptions resetTargetTaskIfNeededLocked(TaskRecord task, boolean forceReset) { |
Craig Mautner | e3a74d5 | 2013-02-22 14:14:58 -0800 | [diff] [blame] | 2418 | ActivityOptions topOptions = null; |
| 2419 | |
| 2420 | int replyChainEnd = -1; |
| 2421 | boolean canMoveOptions = true; |
| 2422 | |
| 2423 | // We only do this for activities that are not the root of the task (since if we finish |
| 2424 | // the root, we may no longer have the task!). |
| 2425 | final ArrayList<ActivityRecord> activities = task.mActivities; |
| 2426 | final int numActivities = activities.size(); |
Craig Mautner | 9d4e9bc | 2014-06-18 18:34:56 -0700 | [diff] [blame] | 2427 | final int rootActivityNdx = task.findEffectiveRootIndex(); |
| 2428 | for (int i = numActivities - 1; i > rootActivityNdx; --i ) { |
Craig Mautner | e3a74d5 | 2013-02-22 14:14:58 -0800 | [diff] [blame] | 2429 | ActivityRecord target = activities.get(i); |
Craig Mautner | 76ae2f0 | 2014-07-16 16:16:19 +0000 | [diff] [blame] | 2430 | if (target.frontOfTask) |
| 2431 | break; |
Craig Mautner | e3a74d5 | 2013-02-22 14:14:58 -0800 | [diff] [blame] | 2432 | |
| 2433 | final int flags = target.info.flags; |
| 2434 | final boolean finishOnTaskLaunch = |
| 2435 | (flags & ActivityInfo.FLAG_FINISH_ON_TASK_LAUNCH) != 0; |
| 2436 | final boolean allowTaskReparenting = |
| 2437 | (flags & ActivityInfo.FLAG_ALLOW_TASK_REPARENTING) != 0; |
| 2438 | final boolean clearWhenTaskReset = |
| 2439 | (target.intent.getFlags() & Intent.FLAG_ACTIVITY_CLEAR_WHEN_TASK_RESET) != 0; |
| 2440 | |
| 2441 | if (!finishOnTaskLaunch |
| 2442 | && !clearWhenTaskReset |
| 2443 | && target.resultTo != null) { |
| 2444 | // If this activity is sending a reply to a previous |
| 2445 | // activity, we can't do anything with it now until |
| 2446 | // we reach the start of the reply chain. |
| 2447 | // XXX note that we are assuming the result is always |
| 2448 | // to the previous activity, which is almost always |
| 2449 | // the case but we really shouldn't count on. |
| 2450 | if (replyChainEnd < 0) { |
| 2451 | replyChainEnd = i; |
| 2452 | } |
| 2453 | } else if (!finishOnTaskLaunch |
| 2454 | && !clearWhenTaskReset |
| 2455 | && allowTaskReparenting |
| 2456 | && target.taskAffinity != null |
| 2457 | && !target.taskAffinity.equals(task.affinity)) { |
| 2458 | // If this activity has an affinity for another |
| 2459 | // task, then we need to move it out of here. We will |
| 2460 | // move it as far out of the way as possible, to the |
| 2461 | // bottom of the activity stack. This also keeps it |
| 2462 | // correctly ordered with any activities we previously |
| 2463 | // moved. |
Craig Mautner | 329f412 | 2013-11-07 09:10:42 -0800 | [diff] [blame] | 2464 | final TaskRecord targetTask; |
Craig Mautner | dccb770 | 2013-09-17 15:53:34 -0700 | [diff] [blame] | 2465 | final ActivityRecord bottom = |
| 2466 | !mTaskHistory.isEmpty() && !mTaskHistory.get(0).mActivities.isEmpty() ? |
Craig Mautner | 329f412 | 2013-11-07 09:10:42 -0800 | [diff] [blame] | 2467 | mTaskHistory.get(0).mActivities.get(0) : null; |
Craig Mautner | dccb770 | 2013-09-17 15:53:34 -0700 | [diff] [blame] | 2468 | if (bottom != null && target.taskAffinity != null |
| 2469 | && target.taskAffinity.equals(bottom.task.affinity)) { |
Craig Mautner | e3a74d5 | 2013-02-22 14:14:58 -0800 | [diff] [blame] | 2470 | // If the activity currently at the bottom has the |
| 2471 | // same task affinity as the one we are moving, |
| 2472 | // then merge it into the same task. |
Craig Mautner | 329f412 | 2013-11-07 09:10:42 -0800 | [diff] [blame] | 2473 | targetTask = bottom.task; |
Wale Ogunwale | ee006da | 2015-03-30 14:49:25 -0700 | [diff] [blame] | 2474 | if (DEBUG_TASKS) Slog.v(TAG_TASKS, "Start pushing activity " + target |
Craig Mautner | dccb770 | 2013-09-17 15:53:34 -0700 | [diff] [blame] | 2475 | + " out to bottom task " + bottom.task); |
Craig Mautner | e3a74d5 | 2013-02-22 14:14:58 -0800 | [diff] [blame] | 2476 | } else { |
Craig Mautner | 329f412 | 2013-11-07 09:10:42 -0800 | [diff] [blame] | 2477 | targetTask = createTaskRecord(mStackSupervisor.getNextTaskId(), target.info, |
Dianne Hackborn | 91097de | 2014-04-04 18:02:06 -0700 | [diff] [blame] | 2478 | null, null, null, false); |
Craig Mautner | 329f412 | 2013-11-07 09:10:42 -0800 | [diff] [blame] | 2479 | targetTask.affinityIntent = target.intent; |
Wale Ogunwale | ee006da | 2015-03-30 14:49:25 -0700 | [diff] [blame] | 2480 | if (DEBUG_TASKS) Slog.v(TAG_TASKS, "Start pushing activity " + target |
Craig Mautner | e3a74d5 | 2013-02-22 14:14:58 -0800 | [diff] [blame] | 2481 | + " out to new task " + target.task); |
| 2482 | } |
| 2483 | |
Wale Ogunwale | 706ed79 | 2015-08-02 10:29:44 -0700 | [diff] [blame] | 2484 | setAppTask(target, targetTask); |
Craig Mautner | e3a74d5 | 2013-02-22 14:14:58 -0800 | [diff] [blame] | 2485 | |
Craig Mautner | 525f3d9 | 2013-05-07 14:01:50 -0700 | [diff] [blame] | 2486 | boolean noOptions = canMoveOptions; |
Craig Mautner | e3a74d5 | 2013-02-22 14:14:58 -0800 | [diff] [blame] | 2487 | final int start = replyChainEnd < 0 ? i : replyChainEnd; |
| 2488 | for (int srcPos = start; srcPos >= i; --srcPos) { |
Craig Mautner | dccb770 | 2013-09-17 15:53:34 -0700 | [diff] [blame] | 2489 | final ActivityRecord p = activities.get(srcPos); |
Craig Mautner | e3a74d5 | 2013-02-22 14:14:58 -0800 | [diff] [blame] | 2490 | if (p.finishing) { |
| 2491 | continue; |
| 2492 | } |
| 2493 | |
Craig Mautner | e3a74d5 | 2013-02-22 14:14:58 -0800 | [diff] [blame] | 2494 | canMoveOptions = false; |
Craig Mautner | 525f3d9 | 2013-05-07 14:01:50 -0700 | [diff] [blame] | 2495 | if (noOptions && topOptions == null) { |
Craig Mautner | e3a74d5 | 2013-02-22 14:14:58 -0800 | [diff] [blame] | 2496 | topOptions = p.takeOptionsLocked(); |
| 2497 | if (topOptions != null) { |
Craig Mautner | 525f3d9 | 2013-05-07 14:01:50 -0700 | [diff] [blame] | 2498 | noOptions = false; |
Craig Mautner | e3a74d5 | 2013-02-22 14:14:58 -0800 | [diff] [blame] | 2499 | } |
| 2500 | } |
Wale Ogunwale | 0fc365c | 2015-05-25 19:35:42 -0700 | [diff] [blame] | 2501 | if (DEBUG_ADD_REMOVE) Slog.i(TAG_ADD_REMOVE, |
| 2502 | "Removing activity " + p + " from task=" + task + " adding to task=" |
| 2503 | + targetTask + " Callers=" + Debug.getCallers(4)); |
Wale Ogunwale | ee006da | 2015-03-30 14:49:25 -0700 | [diff] [blame] | 2504 | if (DEBUG_TASKS) Slog.v(TAG_TASKS, |
| 2505 | "Pushing next activity " + p + " out to target's task " + target.task); |
Craig Mautner | a228ae9 | 2014-07-09 05:44:55 -0700 | [diff] [blame] | 2506 | p.setTask(targetTask, null); |
Craig Mautner | e3a74d5 | 2013-02-22 14:14:58 -0800 | [diff] [blame] | 2507 | targetTask.addActivityAtBottom(p); |
Craig Mautner | 0247fc8 | 2013-02-28 14:32:06 -0800 | [diff] [blame] | 2508 | |
Wale Ogunwale | 706ed79 | 2015-08-02 10:29:44 -0700 | [diff] [blame] | 2509 | setAppTask(p, targetTask); |
Craig Mautner | e3a74d5 | 2013-02-22 14:14:58 -0800 | [diff] [blame] | 2510 | } |
| 2511 | |
Wale Ogunwale | 706ed79 | 2015-08-02 10:29:44 -0700 | [diff] [blame] | 2512 | mWindowManager.moveTaskToBottom(targetTask.taskId); |
Craig Mautner | e3a74d5 | 2013-02-22 14:14:58 -0800 | [diff] [blame] | 2513 | if (VALIDATE_TOKENS) { |
| 2514 | validateAppTokensLocked(); |
| 2515 | } |
| 2516 | |
| 2517 | replyChainEnd = -1; |
| 2518 | } else if (forceReset || finishOnTaskLaunch || clearWhenTaskReset) { |
| 2519 | // If the activity should just be removed -- either |
| 2520 | // because it asks for it, or the task should be |
| 2521 | // cleared -- then finish it and anything that is |
| 2522 | // part of its reply chain. |
| 2523 | int end; |
| 2524 | if (clearWhenTaskReset) { |
| 2525 | // In this case, we want to finish this activity |
| 2526 | // and everything above it, so be sneaky and pretend |
| 2527 | // like these are all in the reply chain. |
Mark Lu | 4b5a9a0 | 2014-12-09 14:47:13 +0800 | [diff] [blame] | 2528 | end = activities.size() - 1; |
Craig Mautner | e3a74d5 | 2013-02-22 14:14:58 -0800 | [diff] [blame] | 2529 | } else if (replyChainEnd < 0) { |
| 2530 | end = i; |
| 2531 | } else { |
| 2532 | end = replyChainEnd; |
| 2533 | } |
Craig Mautner | 525f3d9 | 2013-05-07 14:01:50 -0700 | [diff] [blame] | 2534 | boolean noOptions = canMoveOptions; |
Craig Mautner | e3a74d5 | 2013-02-22 14:14:58 -0800 | [diff] [blame] | 2535 | for (int srcPos = i; srcPos <= end; srcPos++) { |
Craig Mautner | 525f3d9 | 2013-05-07 14:01:50 -0700 | [diff] [blame] | 2536 | ActivityRecord p = activities.get(srcPos); |
Craig Mautner | e3a74d5 | 2013-02-22 14:14:58 -0800 | [diff] [blame] | 2537 | if (p.finishing) { |
| 2538 | continue; |
| 2539 | } |
| 2540 | canMoveOptions = false; |
Craig Mautner | 525f3d9 | 2013-05-07 14:01:50 -0700 | [diff] [blame] | 2541 | if (noOptions && topOptions == null) { |
Craig Mautner | e3a74d5 | 2013-02-22 14:14:58 -0800 | [diff] [blame] | 2542 | topOptions = p.takeOptionsLocked(); |
| 2543 | if (topOptions != null) { |
Craig Mautner | 525f3d9 | 2013-05-07 14:01:50 -0700 | [diff] [blame] | 2544 | noOptions = false; |
Craig Mautner | e3a74d5 | 2013-02-22 14:14:58 -0800 | [diff] [blame] | 2545 | } |
| 2546 | } |
Wale Ogunwale | ee006da | 2015-03-30 14:49:25 -0700 | [diff] [blame] | 2547 | if (DEBUG_TASKS) Slog.w(TAG_TASKS, |
Craig Mautner | 5854780 | 2013-03-05 08:23:53 -0800 | [diff] [blame] | 2548 | "resetTaskIntendedTask: calling finishActivity on " + p); |
Todd Kennedy | 539db51 | 2014-12-15 09:57:55 -0800 | [diff] [blame] | 2549 | if (finishActivityLocked( |
| 2550 | p, Activity.RESULT_CANCELED, null, "reset-task", false)) { |
Craig Mautner | e3a74d5 | 2013-02-22 14:14:58 -0800 | [diff] [blame] | 2551 | end--; |
| 2552 | srcPos--; |
| 2553 | } |
| 2554 | } |
| 2555 | replyChainEnd = -1; |
| 2556 | } else { |
| 2557 | // If we were in the middle of a chain, well the |
| 2558 | // activity that started it all doesn't want anything |
| 2559 | // special, so leave it all as-is. |
| 2560 | replyChainEnd = -1; |
| 2561 | } |
| 2562 | } |
| 2563 | |
| 2564 | return topOptions; |
| 2565 | } |
| 2566 | |
| 2567 | /** |
| 2568 | * Helper method for #resetTaskIfNeededLocked. Processes all of the activities in a given |
| 2569 | * TaskRecord looking for an affinity with the task of resetTaskIfNeededLocked.taskTop. |
| 2570 | * @param affinityTask The task we are looking for an affinity to. |
| 2571 | * @param task Task that resetTaskIfNeededLocked.taskTop belongs to. |
| 2572 | * @param topTaskIsHigher True if #task has already been processed by resetTaskIfNeededLocked. |
| 2573 | * @param forceReset Flag passed in to resetTaskIfNeededLocked. |
| 2574 | */ |
Craig Mautner | 525f3d9 | 2013-05-07 14:01:50 -0700 | [diff] [blame] | 2575 | private int resetAffinityTaskIfNeededLocked(TaskRecord affinityTask, TaskRecord task, |
Craig Mautner | 7787877 | 2013-03-04 19:46:24 -0800 | [diff] [blame] | 2576 | boolean topTaskIsHigher, boolean forceReset, int taskInsertionPoint) { |
Craig Mautner | e3a74d5 | 2013-02-22 14:14:58 -0800 | [diff] [blame] | 2577 | int replyChainEnd = -1; |
| 2578 | final int taskId = task.taskId; |
| 2579 | final String taskAffinity = task.affinity; |
| 2580 | |
| 2581 | final ArrayList<ActivityRecord> activities = affinityTask.mActivities; |
| 2582 | final int numActivities = activities.size(); |
Craig Mautner | 9d4e9bc | 2014-06-18 18:34:56 -0700 | [diff] [blame] | 2583 | final int rootActivityNdx = affinityTask.findEffectiveRootIndex(); |
| 2584 | |
| 2585 | // Do not operate on or below the effective root Activity. |
| 2586 | for (int i = numActivities - 1; i > rootActivityNdx; --i) { |
Craig Mautner | e3a74d5 | 2013-02-22 14:14:58 -0800 | [diff] [blame] | 2587 | ActivityRecord target = activities.get(i); |
Craig Mautner | 76ae2f0 | 2014-07-16 16:16:19 +0000 | [diff] [blame] | 2588 | if (target.frontOfTask) |
| 2589 | break; |
Craig Mautner | e3a74d5 | 2013-02-22 14:14:58 -0800 | [diff] [blame] | 2590 | |
| 2591 | final int flags = target.info.flags; |
| 2592 | boolean finishOnTaskLaunch = (flags & ActivityInfo.FLAG_FINISH_ON_TASK_LAUNCH) != 0; |
| 2593 | boolean allowTaskReparenting = (flags & ActivityInfo.FLAG_ALLOW_TASK_REPARENTING) != 0; |
| 2594 | |
| 2595 | if (target.resultTo != null) { |
| 2596 | // If this activity is sending a reply to a previous |
| 2597 | // activity, we can't do anything with it now until |
| 2598 | // we reach the start of the reply chain. |
| 2599 | // XXX note that we are assuming the result is always |
| 2600 | // to the previous activity, which is almost always |
| 2601 | // the case but we really shouldn't count on. |
| 2602 | if (replyChainEnd < 0) { |
| 2603 | replyChainEnd = i; |
| 2604 | } |
| 2605 | } else if (topTaskIsHigher |
| 2606 | && allowTaskReparenting |
| 2607 | && taskAffinity != null |
| 2608 | && taskAffinity.equals(target.taskAffinity)) { |
| 2609 | // This activity has an affinity for our task. Either remove it if we are |
| 2610 | // clearing or move it over to our task. Note that |
| 2611 | // we currently punt on the case where we are resetting a |
| 2612 | // task that is not at the top but who has activities above |
| 2613 | // with an affinity to it... this is really not a normal |
| 2614 | // case, and we will need to later pull that task to the front |
| 2615 | // and usually at that point we will do the reset and pick |
| 2616 | // up those remaining activities. (This only happens if |
| 2617 | // someone starts an activity in a new task from an activity |
| 2618 | // in a task that is not currently on top.) |
| 2619 | if (forceReset || finishOnTaskLaunch) { |
| 2620 | final int start = replyChainEnd >= 0 ? replyChainEnd : i; |
Wale Ogunwale | ee006da | 2015-03-30 14:49:25 -0700 | [diff] [blame] | 2621 | if (DEBUG_TASKS) Slog.v(TAG_TASKS, |
| 2622 | "Finishing task at index " + start + " to " + i); |
Craig Mautner | e3a74d5 | 2013-02-22 14:14:58 -0800 | [diff] [blame] | 2623 | for (int srcPos = start; srcPos >= i; --srcPos) { |
| 2624 | final ActivityRecord p = activities.get(srcPos); |
| 2625 | if (p.finishing) { |
| 2626 | continue; |
| 2627 | } |
Todd Kennedy | 539db51 | 2014-12-15 09:57:55 -0800 | [diff] [blame] | 2628 | finishActivityLocked( |
| 2629 | p, Activity.RESULT_CANCELED, null, "move-affinity", false); |
Craig Mautner | e3a74d5 | 2013-02-22 14:14:58 -0800 | [diff] [blame] | 2630 | } |
| 2631 | } else { |
Craig Mautner | 7787877 | 2013-03-04 19:46:24 -0800 | [diff] [blame] | 2632 | if (taskInsertionPoint < 0) { |
| 2633 | taskInsertionPoint = task.mActivities.size(); |
Craig Mautner | d232895 | 2013-03-05 12:46:26 -0800 | [diff] [blame] | 2634 | |
Craig Mautner | 7787877 | 2013-03-04 19:46:24 -0800 | [diff] [blame] | 2635 | } |
Craig Mautner | 7787877 | 2013-03-04 19:46:24 -0800 | [diff] [blame] | 2636 | |
| 2637 | final int start = replyChainEnd >= 0 ? replyChainEnd : i; |
Wale Ogunwale | ee006da | 2015-03-30 14:49:25 -0700 | [diff] [blame] | 2638 | if (DEBUG_TASKS) Slog.v(TAG_TASKS, |
| 2639 | "Reparenting from task=" + affinityTask + ":" + start + "-" + i |
| 2640 | + " to task=" + task + ":" + taskInsertionPoint); |
Craig Mautner | 7787877 | 2013-03-04 19:46:24 -0800 | [diff] [blame] | 2641 | for (int srcPos = start; srcPos >= i; --srcPos) { |
Craig Mautner | e3a74d5 | 2013-02-22 14:14:58 -0800 | [diff] [blame] | 2642 | final ActivityRecord p = activities.get(srcPos); |
Craig Mautner | a228ae9 | 2014-07-09 05:44:55 -0700 | [diff] [blame] | 2643 | p.setTask(task, null); |
Craig Mautner | 7787877 | 2013-03-04 19:46:24 -0800 | [diff] [blame] | 2644 | task.addActivityAtIndex(taskInsertionPoint, p); |
Craig Mautner | e3a74d5 | 2013-02-22 14:14:58 -0800 | [diff] [blame] | 2645 | |
Wale Ogunwale | 0fc365c | 2015-05-25 19:35:42 -0700 | [diff] [blame] | 2646 | if (DEBUG_ADD_REMOVE) Slog.i(TAG_ADD_REMOVE, |
| 2647 | "Removing and adding activity " + p + " to stack at " + task |
| 2648 | + " callers=" + Debug.getCallers(3)); |
Wale Ogunwale | ee006da | 2015-03-30 14:49:25 -0700 | [diff] [blame] | 2649 | if (DEBUG_TASKS) Slog.v(TAG_TASKS, "Pulling activity " + p |
| 2650 | + " from " + srcPos + " in to resetting task " + task); |
Wale Ogunwale | 706ed79 | 2015-08-02 10:29:44 -0700 | [diff] [blame] | 2651 | setAppTask(p, task); |
Craig Mautner | e3a74d5 | 2013-02-22 14:14:58 -0800 | [diff] [blame] | 2652 | } |
Craig Mautner | ce5f3cb | 2013-04-22 08:58:54 -0700 | [diff] [blame] | 2653 | mWindowManager.moveTaskToTop(taskId); |
Craig Mautner | 9658b31 | 2013-02-28 10:55:59 -0800 | [diff] [blame] | 2654 | if (VALIDATE_TOKENS) { |
| 2655 | validateAppTokensLocked(); |
| 2656 | } |
Craig Mautner | e3a74d5 | 2013-02-22 14:14:58 -0800 | [diff] [blame] | 2657 | |
| 2658 | // Now we've moved it in to place... but what if this is |
| 2659 | // a singleTop activity and we have put it on top of another |
| 2660 | // instance of the same activity? Then we drop the instance |
| 2661 | // below so it remains singleTop. |
| 2662 | if (target.info.launchMode == ActivityInfo.LAUNCH_SINGLE_TOP) { |
| 2663 | ArrayList<ActivityRecord> taskActivities = task.mActivities; |
Craig Mautner | e3a74d5 | 2013-02-22 14:14:58 -0800 | [diff] [blame] | 2664 | int targetNdx = taskActivities.indexOf(target); |
| 2665 | if (targetNdx > 0) { |
| 2666 | ActivityRecord p = taskActivities.get(targetNdx - 1); |
| 2667 | if (p.intent.getComponent().equals(target.intent.getComponent())) { |
Craig Mautner | 5854780 | 2013-03-05 08:23:53 -0800 | [diff] [blame] | 2668 | finishActivityLocked(p, Activity.RESULT_CANCELED, null, "replace", |
| 2669 | false); |
Craig Mautner | e3a74d5 | 2013-02-22 14:14:58 -0800 | [diff] [blame] | 2670 | } |
| 2671 | } |
| 2672 | } |
| 2673 | } |
| 2674 | |
| 2675 | replyChainEnd = -1; |
| 2676 | } |
| 2677 | } |
Craig Mautner | 7787877 | 2013-03-04 19:46:24 -0800 | [diff] [blame] | 2678 | return taskInsertionPoint; |
Craig Mautner | e3a74d5 | 2013-02-22 14:14:58 -0800 | [diff] [blame] | 2679 | } |
| 2680 | |
Craig Mautner | 8849a5e | 2013-04-02 16:41:03 -0700 | [diff] [blame] | 2681 | final ActivityRecord resetTaskIfNeededLocked(ActivityRecord taskTop, |
Craig Mautner | e3a74d5 | 2013-02-22 14:14:58 -0800 | [diff] [blame] | 2682 | ActivityRecord newActivity) { |
| 2683 | boolean forceReset = |
| 2684 | (newActivity.info.flags & ActivityInfo.FLAG_CLEAR_TASK_ON_LAUNCH) != 0; |
| 2685 | if (ACTIVITY_INACTIVE_RESET_TIME > 0 |
| 2686 | && taskTop.task.getInactiveDuration() > ACTIVITY_INACTIVE_RESET_TIME) { |
| 2687 | if ((newActivity.info.flags & ActivityInfo.FLAG_ALWAYS_RETAIN_TASK_STATE) == 0) { |
| 2688 | forceReset = true; |
| 2689 | } |
| 2690 | } |
| 2691 | |
| 2692 | final TaskRecord task = taskTop.task; |
| 2693 | |
| 2694 | /** False until we evaluate the TaskRecord associated with taskTop. Switches to true |
| 2695 | * for remaining tasks. Used for later tasks to reparent to task. */ |
| 2696 | boolean taskFound = false; |
| 2697 | |
| 2698 | /** If ActivityOptions are moved out and need to be aborted or moved to taskTop. */ |
| 2699 | ActivityOptions topOptions = null; |
| 2700 | |
Craig Mautner | 7787877 | 2013-03-04 19:46:24 -0800 | [diff] [blame] | 2701 | // Preserve the location for reparenting in the new task. |
| 2702 | int reparentInsertionPoint = -1; |
| 2703 | |
Craig Mautner | e3a74d5 | 2013-02-22 14:14:58 -0800 | [diff] [blame] | 2704 | for (int i = mTaskHistory.size() - 1; i >= 0; --i) { |
| 2705 | final TaskRecord targetTask = mTaskHistory.get(i); |
| 2706 | |
| 2707 | if (targetTask == task) { |
| 2708 | topOptions = resetTargetTaskIfNeededLocked(task, forceReset); |
| 2709 | taskFound = true; |
| 2710 | } else { |
Craig Mautner | 7787877 | 2013-03-04 19:46:24 -0800 | [diff] [blame] | 2711 | reparentInsertionPoint = resetAffinityTaskIfNeededLocked(targetTask, task, |
| 2712 | taskFound, forceReset, reparentInsertionPoint); |
Craig Mautner | e3a74d5 | 2013-02-22 14:14:58 -0800 | [diff] [blame] | 2713 | } |
| 2714 | } |
| 2715 | |
Craig Mautner | 70a8693 | 2013-02-28 22:37:44 -0800 | [diff] [blame] | 2716 | int taskNdx = mTaskHistory.indexOf(task); |
riddle_hsu | 1d7919a | 2015-03-11 17:09:50 +0800 | [diff] [blame] | 2717 | if (taskNdx >= 0) { |
| 2718 | do { |
| 2719 | taskTop = mTaskHistory.get(taskNdx--).getTopActivity(); |
| 2720 | } while (taskTop == null && taskNdx >= 0); |
| 2721 | } |
Craig Mautner | 70a8693 | 2013-02-28 22:37:44 -0800 | [diff] [blame] | 2722 | |
Craig Mautner | e3a74d5 | 2013-02-22 14:14:58 -0800 | [diff] [blame] | 2723 | if (topOptions != null) { |
| 2724 | // If we got some ActivityOptions from an activity on top that |
| 2725 | // was removed from the task, propagate them to the new real top. |
| 2726 | if (taskTop != null) { |
Craig Mautner | e3a74d5 | 2013-02-22 14:14:58 -0800 | [diff] [blame] | 2727 | taskTop.updateOptionsLocked(topOptions); |
| 2728 | } else { |
Craig Mautner | e3a74d5 | 2013-02-22 14:14:58 -0800 | [diff] [blame] | 2729 | topOptions.abort(); |
| 2730 | } |
| 2731 | } |
| 2732 | |
| 2733 | return taskTop; |
| 2734 | } |
| 2735 | |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 2736 | void sendActivityResultLocked(int callingUid, ActivityRecord r, |
| 2737 | String resultWho, int requestCode, int resultCode, Intent data) { |
| 2738 | |
| 2739 | if (callingUid > 0) { |
| 2740 | mService.grantUriPermissionFromIntentLocked(callingUid, r.packageName, |
Nicolas Prevot | c6cf95c | 2014-05-29 11:30:36 +0100 | [diff] [blame] | 2741 | data, r.getUriPermissionsLocked(), r.userId); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 2742 | } |
| 2743 | |
| 2744 | if (DEBUG_RESULTS) Slog.v(TAG, "Send activity result to " + r |
| 2745 | + " : who=" + resultWho + " req=" + requestCode |
| 2746 | + " res=" + resultCode + " data=" + data); |
| 2747 | if (mResumedActivity == r && r.app != null && r.app.thread != null) { |
| 2748 | try { |
| 2749 | ArrayList<ResultInfo> list = new ArrayList<ResultInfo>(); |
| 2750 | list.add(new ResultInfo(resultWho, requestCode, |
| 2751 | resultCode, data)); |
Dianne Hackborn | be70785 | 2011-11-11 14:32:10 -0800 | [diff] [blame] | 2752 | r.app.thread.scheduleSendResult(r.appToken, list); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 2753 | return; |
| 2754 | } catch (Exception e) { |
| 2755 | Slog.w(TAG, "Exception thrown sending result to " + r, e); |
| 2756 | } |
| 2757 | } |
| 2758 | |
| 2759 | r.addResultLocked(null, resultWho, requestCode, resultCode, data); |
| 2760 | } |
| 2761 | |
Craig Mautner | 299f960 | 2015-01-26 09:47:33 -0800 | [diff] [blame] | 2762 | private void adjustFocusedActivityLocked(ActivityRecord r, String reason) { |
Craig Mautner | 04f0b70 | 2013-10-22 12:31:01 -0700 | [diff] [blame] | 2763 | if (mStackSupervisor.isFrontStack(this) && mService.mFocusedActivity == r) { |
| 2764 | ActivityRecord next = topRunningActivityLocked(null); |
Wale Ogunwale | d697cea | 2015-02-20 17:19:49 -0800 | [diff] [blame] | 2765 | final String myReason = reason + " adjustFocus"; |
Craig Mautner | 04f0b70 | 2013-10-22 12:31:01 -0700 | [diff] [blame] | 2766 | if (next != r) { |
Wale Ogunwale | b34a7ad | 2015-08-14 11:05:30 -0700 | [diff] [blame] | 2767 | if (next != null && (mStackId == FREEFORM_WORKSPACE_STACK_ID |
| 2768 | || mStackId == DOCKED_STACK_ID)) { |
| 2769 | // For freeform and docked stacks we always keep the focus within the stack as |
| 2770 | // long as there is a running activity in the stack that we can adjust focus to. |
Wale Ogunwale | 61803ee | 2015-08-07 19:59:47 -0700 | [diff] [blame] | 2771 | mService.setFocusedActivityLocked(next, myReason); |
| 2772 | return; |
| 2773 | } else { |
| 2774 | final TaskRecord task = r.task; |
| 2775 | if (r.frontOfTask && task == topTask() && task.isOverHomeStack()) { |
| 2776 | // For non-fullscreen stack, we want to move the focus to the next visible |
| 2777 | // stack to prevent the home screen from moving to the top and obscuring |
| 2778 | // other visible stacks. |
| 2779 | if (!mFullscreen |
| 2780 | && adjustFocusToNextVisibleStackLocked(null, myReason)) { |
| 2781 | return; |
| 2782 | } |
| 2783 | // Move the home stack to the top if this stack is fullscreen or there is no |
| 2784 | // other visible stack. |
| 2785 | if (mStackSupervisor.moveHomeStackTaskToTop( |
| 2786 | task.getTaskToReturnTo(), myReason)) { |
| 2787 | // Activity focus was already adjusted. Nothing else to do... |
| 2788 | return; |
| 2789 | } |
Wale Ogunwale | d80c263 | 2015-03-13 10:26:26 -0700 | [diff] [blame] | 2790 | } |
Craig Mautner | 04f0b70 | 2013-10-22 12:31:01 -0700 | [diff] [blame] | 2791 | } |
| 2792 | } |
Wale Ogunwale | d697cea | 2015-02-20 17:19:49 -0800 | [diff] [blame] | 2793 | |
| 2794 | final ActivityRecord top = mStackSupervisor.topRunningActivityLocked(); |
Winson Chung | 648c83b | 2014-04-28 15:11:56 -0700 | [diff] [blame] | 2795 | if (top != null) { |
Wale Ogunwale | d697cea | 2015-02-20 17:19:49 -0800 | [diff] [blame] | 2796 | mService.setFocusedActivityLocked(top, myReason); |
Winson Chung | 648c83b | 2014-04-28 15:11:56 -0700 | [diff] [blame] | 2797 | } |
Craig Mautner | 04f0b70 | 2013-10-22 12:31:01 -0700 | [diff] [blame] | 2798 | } |
| 2799 | } |
| 2800 | |
Wale Ogunwale | d697cea | 2015-02-20 17:19:49 -0800 | [diff] [blame] | 2801 | private boolean adjustFocusToNextVisibleStackLocked(ActivityStack inStack, String reason) { |
| 2802 | final ActivityStack stack = (inStack != null) ? inStack : getNextVisibleStackLocked(); |
| 2803 | final String myReason = reason + " adjustFocusToNextVisibleStack"; |
| 2804 | if (stack == null) { |
| 2805 | return false; |
| 2806 | } |
| 2807 | final ActivityRecord top = stack.topRunningActivityLocked(null); |
| 2808 | if (top == null) { |
| 2809 | return false; |
| 2810 | } |
Wale Ogunwale | d697cea | 2015-02-20 17:19:49 -0800 | [diff] [blame] | 2811 | mService.setFocusedActivityLocked(top, myReason); |
| 2812 | return true; |
| 2813 | } |
| 2814 | |
Craig Mautner | f333327 | 2013-04-22 10:55:53 -0700 | [diff] [blame] | 2815 | final void stopActivityLocked(ActivityRecord r) { |
Wale Ogunwale | ee006da | 2015-03-30 14:49:25 -0700 | [diff] [blame] | 2816 | if (DEBUG_SWITCH) Slog.d(TAG_SWITCH, "Stopping: " + r); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 2817 | if ((r.intent.getFlags()&Intent.FLAG_ACTIVITY_NO_HISTORY) != 0 |
| 2818 | || (r.info.flags&ActivityInfo.FLAG_NO_HISTORY) != 0) { |
| 2819 | if (!r.finishing) { |
Dianne Hackborn | 91097de | 2014-04-04 18:02:06 -0700 | [diff] [blame] | 2820 | if (!mService.isSleeping()) { |
Wale Ogunwale | 0fc365c | 2015-05-25 19:35:42 -0700 | [diff] [blame] | 2821 | if (DEBUG_STATES) Slog.d(TAG_STATES, "no-history finish of " + r); |
Wale Ogunwale | 3f529ee | 2015-07-12 15:14:01 -0700 | [diff] [blame] | 2822 | if (requestFinishActivityLocked(r.appToken, Activity.RESULT_CANCELED, null, |
| 2823 | "stop-no-history", false)) { |
| 2824 | // Activity was finished, no need to continue trying to schedule stop. |
| 2825 | adjustFocusedActivityLocked(r, "stopActivityFinished"); |
| 2826 | r.resumeKeyDispatchingLocked(); |
| 2827 | return; |
| 2828 | } |
Christopher Tate | d3f175c | 2012-06-14 14:16:54 -0700 | [diff] [blame] | 2829 | } else { |
Wale Ogunwale | 0fc365c | 2015-05-25 19:35:42 -0700 | [diff] [blame] | 2830 | if (DEBUG_STATES) Slog.d(TAG_STATES, "Not finishing noHistory " + r |
Christopher Tate | d3f175c | 2012-06-14 14:16:54 -0700 | [diff] [blame] | 2831 | + " on stop because we're just sleeping"); |
| 2832 | } |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 2833 | } |
Christopher Tate | 5007ddd | 2012-06-12 13:08:18 -0700 | [diff] [blame] | 2834 | } |
| 2835 | |
| 2836 | if (r.app != null && r.app.thread != null) { |
Craig Mautner | 299f960 | 2015-01-26 09:47:33 -0800 | [diff] [blame] | 2837 | adjustFocusedActivityLocked(r, "stopActivity"); |
Dianne Hackborn | 621e2fe | 2012-02-16 17:07:33 -0800 | [diff] [blame] | 2838 | r.resumeKeyDispatchingLocked(); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 2839 | try { |
| 2840 | r.stopped = false; |
Wale Ogunwale | 0fc365c | 2015-05-25 19:35:42 -0700 | [diff] [blame] | 2841 | if (DEBUG_STATES) Slog.v(TAG_STATES, |
| 2842 | "Moving to STOPPING: " + r + " (stop requested)"); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 2843 | r.state = ActivityState.STOPPING; |
Wale Ogunwale | ee006da | 2015-03-30 14:49:25 -0700 | [diff] [blame] | 2844 | if (DEBUG_VISIBILITY) Slog.v(TAG_VISIBILITY, |
| 2845 | "Stopping visible=" + r.visible + " for " + r); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 2846 | if (!r.visible) { |
Craig Mautner | ce5f3cb | 2013-04-22 08:58:54 -0700 | [diff] [blame] | 2847 | mWindowManager.setAppVisibility(r.appToken, false); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 2848 | } |
Dianne Hackborn | be70785 | 2011-11-11 14:32:10 -0800 | [diff] [blame] | 2849 | r.app.thread.scheduleStopActivity(r.appToken, r.visible, r.configChangeFlags); |
Craig Mautner | e11f2b7 | 2013-04-01 12:37:17 -0700 | [diff] [blame] | 2850 | if (mService.isSleepingOrShuttingDown()) { |
Dianne Hackborn | 4eba96b | 2011-01-21 13:34:36 -0800 | [diff] [blame] | 2851 | r.setSleeping(true); |
| 2852 | } |
Craig Mautner | f7bfefb | 2013-05-16 17:30:44 -0700 | [diff] [blame] | 2853 | Message msg = mHandler.obtainMessage(STOP_TIMEOUT_MSG, r); |
Dianne Hackborn | 162bc0e | 2012-04-09 14:06:16 -0700 | [diff] [blame] | 2854 | mHandler.sendMessageDelayed(msg, STOP_TIMEOUT); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 2855 | } catch (Exception e) { |
| 2856 | // Maybe just ignore exceptions here... if the process |
| 2857 | // has crashed, our death notification will clean things |
| 2858 | // up. |
| 2859 | Slog.w(TAG, "Exception thrown during pause", e); |
| 2860 | // Just in case, assume it to be stopped. |
| 2861 | r.stopped = true; |
Wale Ogunwale | 0fc365c | 2015-05-25 19:35:42 -0700 | [diff] [blame] | 2862 | if (DEBUG_STATES) Slog.v(TAG_STATES, "Stop failed; moving to STOPPED: " + r); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 2863 | r.state = ActivityState.STOPPED; |
| 2864 | if (r.configDestroy) { |
Craig Mautner | ee2e45a | 2014-06-27 12:10:03 -0700 | [diff] [blame] | 2865 | destroyActivityLocked(r, true, "stop-except"); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 2866 | } |
| 2867 | } |
| 2868 | } |
| 2869 | } |
Craig Mautner | 23ac33b | 2013-04-01 16:26:35 -0700 | [diff] [blame] | 2870 | |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 2871 | /** |
| 2872 | * @return Returns true if the activity is being finished, false if for |
| 2873 | * some reason it is being left as-is. |
| 2874 | */ |
| 2875 | final boolean requestFinishActivityLocked(IBinder token, int resultCode, |
Dianne Hackborn | 2d1b378 | 2012-09-09 17:49:39 -0700 | [diff] [blame] | 2876 | Intent resultData, String reason, boolean oomAdj) { |
Craig Mautner | d74f7d7 | 2013-02-26 13:41:02 -0800 | [diff] [blame] | 2877 | ActivityRecord r = isInStackLocked(token); |
Wale Ogunwale | 0fc365c | 2015-05-25 19:35:42 -0700 | [diff] [blame] | 2878 | if (DEBUG_RESULTS || DEBUG_STATES) Slog.v(TAG_STATES, |
| 2879 | "Finishing activity token=" + token + " r=" |
Christopher Tate | d3f175c | 2012-06-14 14:16:54 -0700 | [diff] [blame] | 2880 | + ", result=" + resultCode + ", data=" + resultData |
| 2881 | + ", reason=" + reason); |
Craig Mautner | d74f7d7 | 2013-02-26 13:41:02 -0800 | [diff] [blame] | 2882 | if (r == null) { |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 2883 | return false; |
| 2884 | } |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 2885 | |
Craig Mautner | d44711d | 2013-02-23 11:24:36 -0800 | [diff] [blame] | 2886 | finishActivityLocked(r, resultCode, resultData, reason, oomAdj); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 2887 | return true; |
| 2888 | } |
| 2889 | |
Craig Mautner | d232895 | 2013-03-05 12:46:26 -0800 | [diff] [blame] | 2890 | final void finishSubActivityLocked(ActivityRecord self, String resultWho, int requestCode) { |
Craig Mautner | 9658b31 | 2013-02-28 10:55:59 -0800 | [diff] [blame] | 2891 | for (int taskNdx = mTaskHistory.size() - 1; taskNdx >= 0; --taskNdx) { |
| 2892 | ArrayList<ActivityRecord> activities = mTaskHistory.get(taskNdx).mActivities; |
| 2893 | for (int activityNdx = activities.size() - 1; activityNdx >= 0; --activityNdx) { |
| 2894 | ActivityRecord r = activities.get(activityNdx); |
| 2895 | if (r.resultTo == self && r.requestCode == requestCode) { |
| 2896 | if ((r.resultWho == null && resultWho == null) || |
| 2897 | (r.resultWho != null && r.resultWho.equals(resultWho))) { |
| 2898 | finishActivityLocked(r, Activity.RESULT_CANCELED, null, "request-sub", |
| 2899 | false); |
| 2900 | } |
Dianne Hackborn | ecc5a9c | 2012-04-26 18:56:09 -0700 | [diff] [blame] | 2901 | } |
| 2902 | } |
| 2903 | } |
Dianne Hackborn | 2d1b378 | 2012-09-09 17:49:39 -0700 | [diff] [blame] | 2904 | mService.updateOomAdjLocked(); |
Dianne Hackborn | ecc5a9c | 2012-04-26 18:56:09 -0700 | [diff] [blame] | 2905 | } |
| 2906 | |
Todd Kennedy | 539db51 | 2014-12-15 09:57:55 -0800 | [diff] [blame] | 2907 | final void finishTopRunningActivityLocked(ProcessRecord app, String reason) { |
Craig Mautner | 05d6272ba | 2013-02-11 09:39:27 -0800 | [diff] [blame] | 2908 | ActivityRecord r = topRunningActivityLocked(null); |
| 2909 | if (r != null && r.app == app) { |
| 2910 | // If the top running activity is from this crashing |
| 2911 | // process, then terminate it to avoid getting in a loop. |
| 2912 | Slog.w(TAG, " Force finishing activity " |
| 2913 | + r.intent.getComponent().flattenToShortString()); |
Craig Mautner | 9658b31 | 2013-02-28 10:55:59 -0800 | [diff] [blame] | 2914 | int taskNdx = mTaskHistory.indexOf(r.task); |
| 2915 | int activityNdx = r.task.mActivities.indexOf(r); |
Todd Kennedy | 539db51 | 2014-12-15 09:57:55 -0800 | [diff] [blame] | 2916 | finishActivityLocked(r, Activity.RESULT_CANCELED, null, reason, false); |
Craig Mautner | 05d6272ba | 2013-02-11 09:39:27 -0800 | [diff] [blame] | 2917 | // Also terminate any activities below it that aren't yet |
| 2918 | // stopped, to avoid a situation where one will get |
| 2919 | // re-start our crashing activity once it gets resumed again. |
Craig Mautner | 9658b31 | 2013-02-28 10:55:59 -0800 | [diff] [blame] | 2920 | --activityNdx; |
| 2921 | if (activityNdx < 0) { |
| 2922 | do { |
| 2923 | --taskNdx; |
| 2924 | if (taskNdx < 0) { |
| 2925 | break; |
| 2926 | } |
| 2927 | activityNdx = mTaskHistory.get(taskNdx).mActivities.size() - 1; |
| 2928 | } while (activityNdx < 0); |
| 2929 | } |
| 2930 | if (activityNdx >= 0) { |
| 2931 | r = mTaskHistory.get(taskNdx).mActivities.get(activityNdx); |
Craig Mautner | 05d6272ba | 2013-02-11 09:39:27 -0800 | [diff] [blame] | 2932 | if (r.state == ActivityState.RESUMED |
| 2933 | || r.state == ActivityState.PAUSING |
| 2934 | || r.state == ActivityState.PAUSED) { |
Craig Mautner | 4ef2693 | 2013-09-18 15:15:52 -0700 | [diff] [blame] | 2935 | if (!r.isHomeActivity() || mService.mHomeProcess != r.app) { |
Craig Mautner | 05d6272ba | 2013-02-11 09:39:27 -0800 | [diff] [blame] | 2936 | Slog.w(TAG, " Force finishing activity " |
| 2937 | + r.intent.getComponent().flattenToShortString()); |
Todd Kennedy | 539db51 | 2014-12-15 09:57:55 -0800 | [diff] [blame] | 2938 | finishActivityLocked(r, Activity.RESULT_CANCELED, null, reason, false); |
Craig Mautner | 05d6272ba | 2013-02-11 09:39:27 -0800 | [diff] [blame] | 2939 | } |
| 2940 | } |
| 2941 | } |
| 2942 | } |
| 2943 | } |
| 2944 | |
Dianne Hackborn | 6ea0d0a | 2014-07-02 16:23:21 -0700 | [diff] [blame] | 2945 | final void finishVoiceTask(IVoiceInteractionSession session) { |
| 2946 | IBinder sessionBinder = session.asBinder(); |
| 2947 | boolean didOne = false; |
| 2948 | for (int taskNdx = mTaskHistory.size() - 1; taskNdx >= 0; --taskNdx) { |
| 2949 | TaskRecord tr = mTaskHistory.get(taskNdx); |
| 2950 | if (tr.voiceSession != null && tr.voiceSession.asBinder() == sessionBinder) { |
| 2951 | for (int activityNdx = tr.mActivities.size() - 1; activityNdx >= 0; --activityNdx) { |
| 2952 | ActivityRecord r = tr.mActivities.get(activityNdx); |
| 2953 | if (!r.finishing) { |
| 2954 | finishActivityLocked(r, Activity.RESULT_CANCELED, null, "finish-voice", |
| 2955 | false); |
| 2956 | didOne = true; |
| 2957 | } |
| 2958 | } |
| 2959 | } |
| 2960 | } |
| 2961 | if (didOne) { |
| 2962 | mService.updateOomAdjLocked(); |
| 2963 | } |
| 2964 | } |
| 2965 | |
Craig Mautner | d232895 | 2013-03-05 12:46:26 -0800 | [diff] [blame] | 2966 | final boolean finishActivityAffinityLocked(ActivityRecord r) { |
Craig Mautner | d74f7d7 | 2013-02-26 13:41:02 -0800 | [diff] [blame] | 2967 | ArrayList<ActivityRecord> activities = r.task.mActivities; |
| 2968 | for (int index = activities.indexOf(r); index >= 0; --index) { |
| 2969 | ActivityRecord cur = activities.get(index); |
Kenny Root | e6585b3 | 2013-12-13 12:00:26 -0800 | [diff] [blame] | 2970 | if (!Objects.equals(cur.taskAffinity, r.taskAffinity)) { |
Dianne Hackborn | ecc5a9c | 2012-04-26 18:56:09 -0700 | [diff] [blame] | 2971 | break; |
| 2972 | } |
Craig Mautner | de4ef02 | 2013-04-07 19:01:33 -0700 | [diff] [blame] | 2973 | finishActivityLocked(cur, Activity.RESULT_CANCELED, null, "request-affinity", true); |
Dianne Hackborn | ecc5a9c | 2012-04-26 18:56:09 -0700 | [diff] [blame] | 2974 | } |
| 2975 | return true; |
| 2976 | } |
| 2977 | |
Dianne Hackborn | 5c60743 | 2012-02-28 14:44:19 -0800 | [diff] [blame] | 2978 | final void finishActivityResultsLocked(ActivityRecord r, int resultCode, Intent resultData) { |
| 2979 | // send the result |
| 2980 | ActivityRecord resultTo = r.resultTo; |
| 2981 | if (resultTo != null) { |
Wale Ogunwale | ee006da | 2015-03-30 14:49:25 -0700 | [diff] [blame] | 2982 | if (DEBUG_RESULTS) Slog.v(TAG_RESULTS, "Adding result to " + resultTo |
Dianne Hackborn | 5c60743 | 2012-02-28 14:44:19 -0800 | [diff] [blame] | 2983 | + " who=" + r.resultWho + " req=" + r.requestCode |
| 2984 | + " res=" + resultCode + " data=" + resultData); |
Nicolas Prevot | c6cf95c | 2014-05-29 11:30:36 +0100 | [diff] [blame] | 2985 | if (resultTo.userId != r.userId) { |
Nicolas Prevot | 6b942b8 | 2014-06-02 15:20:42 +0100 | [diff] [blame] | 2986 | if (resultData != null) { |
Nicolas Prevot | 107f7b7 | 2015-07-01 16:31:48 +0100 | [diff] [blame] | 2987 | resultData.prepareToLeaveUser(r.userId); |
Nicolas Prevot | 6b942b8 | 2014-06-02 15:20:42 +0100 | [diff] [blame] | 2988 | } |
Nicolas Prevot | c6cf95c | 2014-05-29 11:30:36 +0100 | [diff] [blame] | 2989 | } |
Dianne Hackborn | 5c60743 | 2012-02-28 14:44:19 -0800 | [diff] [blame] | 2990 | if (r.info.applicationInfo.uid > 0) { |
| 2991 | mService.grantUriPermissionFromIntentLocked(r.info.applicationInfo.uid, |
| 2992 | resultTo.packageName, resultData, |
Nicolas Prevot | c6cf95c | 2014-05-29 11:30:36 +0100 | [diff] [blame] | 2993 | resultTo.getUriPermissionsLocked(), resultTo.userId); |
Dianne Hackborn | 5c60743 | 2012-02-28 14:44:19 -0800 | [diff] [blame] | 2994 | } |
| 2995 | resultTo.addResultLocked(r, r.resultWho, r.requestCode, resultCode, |
| 2996 | resultData); |
| 2997 | r.resultTo = null; |
| 2998 | } |
Wale Ogunwale | ee006da | 2015-03-30 14:49:25 -0700 | [diff] [blame] | 2999 | else if (DEBUG_RESULTS) Slog.v(TAG_RESULTS, "No result destination from " + r); |
Dianne Hackborn | 5c60743 | 2012-02-28 14:44:19 -0800 | [diff] [blame] | 3000 | |
| 3001 | // Make sure this HistoryRecord is not holding on to other resources, |
| 3002 | // because clients have remote IPC references to this object so we |
| 3003 | // can't assume that will go away and want to avoid circular IPC refs. |
| 3004 | r.results = null; |
| 3005 | r.pendingResults = null; |
| 3006 | r.newIntents = null; |
| 3007 | r.icicle = null; |
| 3008 | } |
| 3009 | |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 3010 | /** |
| 3011 | * @return Returns true if this activity has been removed from the history |
| 3012 | * list, or false if it is still in the list and will be removed later. |
| 3013 | */ |
Craig Mautner | f333327 | 2013-04-22 10:55:53 -0700 | [diff] [blame] | 3014 | final boolean finishActivityLocked(ActivityRecord r, int resultCode, Intent resultData, |
| 3015 | String reason, boolean oomAdj) { |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 3016 | if (r.finishing) { |
| 3017 | Slog.w(TAG, "Duplicate finish request for " + r); |
| 3018 | return false; |
| 3019 | } |
| 3020 | |
Wale Ogunwale | 7d70117 | 2015-03-11 15:36:30 -0700 | [diff] [blame] | 3021 | r.makeFinishingLocked(); |
Craig Mautner | aea74a5 | 2014-03-08 14:23:10 -0800 | [diff] [blame] | 3022 | final TaskRecord task = r.task; |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 3023 | EventLog.writeEvent(EventLogTags.AM_FINISH_ACTIVITY, |
Dianne Hackborn | b12e135 | 2012-09-26 11:39:20 -0700 | [diff] [blame] | 3024 | r.userId, System.identityHashCode(r), |
Craig Mautner | aea74a5 | 2014-03-08 14:23:10 -0800 | [diff] [blame] | 3025 | task.taskId, r.shortComponentName, reason); |
| 3026 | final ArrayList<ActivityRecord> activities = task.mActivities; |
Craig Mautner | d44711d | 2013-02-23 11:24:36 -0800 | [diff] [blame] | 3027 | final int index = activities.indexOf(r); |
| 3028 | if (index < (activities.size() - 1)) { |
Craig Mautner | aea74a5 | 2014-03-08 14:23:10 -0800 | [diff] [blame] | 3029 | task.setFrontOfTask(); |
Craig Mautner | d00f474 | 2014-03-12 14:17:26 -0700 | [diff] [blame] | 3030 | if ((r.intent.getFlags() & Intent.FLAG_ACTIVITY_CLEAR_WHEN_TASK_RESET) != 0) { |
Craig Mautner | d44711d | 2013-02-23 11:24:36 -0800 | [diff] [blame] | 3031 | // If the caller asked that this activity (and all above it) |
| 3032 | // be cleared when the task is reset, don't lose that information, |
| 3033 | // but propagate it up to the next activity. |
Craig Mautner | 1aa9d0d3f | 2013-12-16 15:58:31 -0800 | [diff] [blame] | 3034 | ActivityRecord next = activities.get(index+1); |
Craig Mautner | d44711d | 2013-02-23 11:24:36 -0800 | [diff] [blame] | 3035 | next.intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_WHEN_TASK_RESET); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 3036 | } |
| 3037 | } |
| 3038 | |
| 3039 | r.pauseKeyDispatchingLocked(); |
Craig Mautner | 04f0b70 | 2013-10-22 12:31:01 -0700 | [diff] [blame] | 3040 | |
Craig Mautner | 299f960 | 2015-01-26 09:47:33 -0800 | [diff] [blame] | 3041 | adjustFocusedActivityLocked(r, "finishActivity"); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 3042 | |
Dianne Hackborn | 5c60743 | 2012-02-28 14:44:19 -0800 | [diff] [blame] | 3043 | finishActivityResultsLocked(r, resultCode, resultData); |
Craig Mautner | 2420ead | 2013-04-01 17:13:20 -0700 | [diff] [blame] | 3044 | |
Craig Mautner | de4ef02 | 2013-04-07 19:01:33 -0700 | [diff] [blame] | 3045 | if (mResumedActivity == r) { |
Craig Mautner | 0247fc8 | 2013-02-28 14:32:06 -0800 | [diff] [blame] | 3046 | boolean endTask = index <= 0; |
Wale Ogunwale | ee006da | 2015-03-30 14:49:25 -0700 | [diff] [blame] | 3047 | if (DEBUG_VISIBILITY || DEBUG_TRANSITION) Slog.v(TAG_TRANSITION, |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 3048 | "Prepare close transition: finishing " + r); |
Craig Mautner | ce5f3cb | 2013-04-22 08:58:54 -0700 | [diff] [blame] | 3049 | mWindowManager.prepareAppTransition(endTask |
Craig Mautner | 4b71aa1 | 2012-12-27 17:20:01 -0800 | [diff] [blame] | 3050 | ? AppTransition.TRANSIT_TASK_CLOSE |
| 3051 | : AppTransition.TRANSIT_ACTIVITY_CLOSE, false); |
Craig Mautner | 0247fc8 | 2013-02-28 14:32:06 -0800 | [diff] [blame] | 3052 | |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 3053 | // Tell window manager to prepare for this one to be removed. |
Craig Mautner | ce5f3cb | 2013-04-22 08:58:54 -0700 | [diff] [blame] | 3054 | mWindowManager.setAppVisibility(r.appToken, false); |
Craig Mautner | dbcb31f | 2013-04-02 12:32:53 -0700 | [diff] [blame] | 3055 | |
Dianne Hackborn | 621e2fe | 2012-02-16 17:07:33 -0800 | [diff] [blame] | 3056 | if (mPausingActivity == null) { |
Wale Ogunwale | ee006da | 2015-03-30 14:49:25 -0700 | [diff] [blame] | 3057 | if (DEBUG_PAUSE) Slog.v(TAG_PAUSE, "Finish needs to pause: " + r); |
| 3058 | if (DEBUG_USER_LEAVING) Slog.v(TAG_USER_LEAVING, |
| 3059 | "finish() => pause with userLeaving=false"); |
Dianne Hackborn | a4e102e | 2014-09-04 22:52:27 -0700 | [diff] [blame] | 3060 | startPausingLocked(false, false, false, false); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 3061 | } |
| 3062 | |
Craig Mautner | aea74a5 | 2014-03-08 14:23:10 -0800 | [diff] [blame] | 3063 | if (endTask) { |
Craig Mautner | 15df08a | 2015-04-01 12:17:18 -0700 | [diff] [blame] | 3064 | mStackSupervisor.removeLockedTaskLocked(task); |
Craig Mautner | aea74a5 | 2014-03-08 14:23:10 -0800 | [diff] [blame] | 3065 | } |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 3066 | } else if (r.state != ActivityState.PAUSING) { |
| 3067 | // If the activity is PAUSING, we will complete the finish once |
| 3068 | // it is done pausing; else we can just directly finish it here. |
Wale Ogunwale | ee006da | 2015-03-30 14:49:25 -0700 | [diff] [blame] | 3069 | if (DEBUG_PAUSE) Slog.v(TAG_PAUSE, "Finish not pausing: " + r); |
Craig Mautner | d44711d | 2013-02-23 11:24:36 -0800 | [diff] [blame] | 3070 | return finishCurrentActivityLocked(r, FINISH_AFTER_PAUSE, oomAdj) == null; |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 3071 | } else { |
Wale Ogunwale | ee006da | 2015-03-30 14:49:25 -0700 | [diff] [blame] | 3072 | if (DEBUG_PAUSE) Slog.v(TAG_PAUSE, "Finish waiting for pause of: " + r); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 3073 | } |
| 3074 | |
| 3075 | return false; |
| 3076 | } |
| 3077 | |
Craig Mautner | f333327 | 2013-04-22 10:55:53 -0700 | [diff] [blame] | 3078 | static final int FINISH_IMMEDIATELY = 0; |
| 3079 | static final int FINISH_AFTER_PAUSE = 1; |
| 3080 | static final int FINISH_AFTER_VISIBLE = 2; |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 3081 | |
Craig Mautner | f333327 | 2013-04-22 10:55:53 -0700 | [diff] [blame] | 3082 | final ActivityRecord finishCurrentActivityLocked(ActivityRecord r, int mode, boolean oomAdj) { |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 3083 | // First things first: if this activity is currently visible, |
| 3084 | // and the resumed activity is not yet visible, then hold off on |
| 3085 | // finishing until the resumed one becomes visible. |
| 3086 | if (mode == FINISH_AFTER_VISIBLE && r.nowVisible) { |
Craig Mautner | de4ef02 | 2013-04-07 19:01:33 -0700 | [diff] [blame] | 3087 | if (!mStackSupervisor.mStoppingActivities.contains(r)) { |
| 3088 | mStackSupervisor.mStoppingActivities.add(r); |
Craig Mautner | 29219d9 | 2013-04-16 20:19:12 -0700 | [diff] [blame] | 3089 | if (mStackSupervisor.mStoppingActivities.size() > 3 |
| 3090 | || r.frontOfTask && mTaskHistory.size() <= 1) { |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 3091 | // If we already have a few activities waiting to stop, |
| 3092 | // then give up on things going idle and start clearing |
Craig Mautner | 29219d9 | 2013-04-16 20:19:12 -0700 | [diff] [blame] | 3093 | // them out. Or if r is the last of activity of the last task the stack |
| 3094 | // will be empty and must be cleared immediately. |
Craig Mautner | f333327 | 2013-04-22 10:55:53 -0700 | [diff] [blame] | 3095 | mStackSupervisor.scheduleIdleLocked(); |
Dianne Hackborn | 4eba96b | 2011-01-21 13:34:36 -0800 | [diff] [blame] | 3096 | } else { |
Craig Mautner | 0eea92c | 2013-05-16 13:35:39 -0700 | [diff] [blame] | 3097 | mStackSupervisor.checkReadyForSleepLocked(); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 3098 | } |
| 3099 | } |
Wale Ogunwale | 0fc365c | 2015-05-25 19:35:42 -0700 | [diff] [blame] | 3100 | if (DEBUG_STATES) Slog.v(TAG_STATES, |
| 3101 | "Moving to STOPPING: "+ r + " (finish requested)"); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 3102 | r.state = ActivityState.STOPPING; |
Dianne Hackborn | 2d1b378 | 2012-09-09 17:49:39 -0700 | [diff] [blame] | 3103 | if (oomAdj) { |
| 3104 | mService.updateOomAdjLocked(); |
| 3105 | } |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 3106 | return r; |
| 3107 | } |
| 3108 | |
| 3109 | // make sure the record is cleaned out of other places. |
Craig Mautner | de4ef02 | 2013-04-07 19:01:33 -0700 | [diff] [blame] | 3110 | mStackSupervisor.mStoppingActivities.remove(r); |
Craig Mautner | 0eea92c | 2013-05-16 13:35:39 -0700 | [diff] [blame] | 3111 | mStackSupervisor.mGoingToSleepActivities.remove(r); |
Craig Mautner | de4ef02 | 2013-04-07 19:01:33 -0700 | [diff] [blame] | 3112 | mStackSupervisor.mWaitingVisibleActivities.remove(r); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 3113 | if (mResumedActivity == r) { |
| 3114 | mResumedActivity = null; |
| 3115 | } |
| 3116 | final ActivityState prevState = r.state; |
Wale Ogunwale | 0fc365c | 2015-05-25 19:35:42 -0700 | [diff] [blame] | 3117 | if (DEBUG_STATES) Slog.v(TAG_STATES, "Moving to FINISHING: " + r); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 3118 | r.state = ActivityState.FINISHING; |
| 3119 | |
| 3120 | if (mode == FINISH_IMMEDIATELY |
Wale Ogunwale | 3f529ee | 2015-07-12 15:14:01 -0700 | [diff] [blame] | 3121 | || (mode == FINISH_AFTER_PAUSE && prevState == ActivityState.PAUSED) |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 3122 | || prevState == ActivityState.STOPPED |
| 3123 | || prevState == ActivityState.INITIALIZING) { |
| 3124 | // If this activity is already stopped, we can just finish |
| 3125 | // it right now. |
Wale Ogunwale | 7d70117 | 2015-03-11 15:36:30 -0700 | [diff] [blame] | 3126 | r.makeFinishingLocked(); |
Craig Mautner | ee2e45a | 2014-06-27 12:10:03 -0700 | [diff] [blame] | 3127 | boolean activityRemoved = destroyActivityLocked(r, true, "finish-imm"); |
Dianne Hackborn | 42e620c | 2012-06-24 13:20:51 -0700 | [diff] [blame] | 3128 | if (activityRemoved) { |
Craig Mautner | 05d2903 | 2013-05-03 13:40:13 -0700 | [diff] [blame] | 3129 | mStackSupervisor.resumeTopActivitiesLocked(); |
Dianne Hackborn | 42e620c | 2012-06-24 13:20:51 -0700 | [diff] [blame] | 3130 | } |
Wale Ogunwale | 0fc365c | 2015-05-25 19:35:42 -0700 | [diff] [blame] | 3131 | if (DEBUG_CONTAINERS) Slog.d(TAG_CONTAINERS, |
Craig Mautner | d163e75 | 2014-06-13 17:18:47 -0700 | [diff] [blame] | 3132 | "destroyActivityLocked: finishCurrentActivityLocked r=" + r + |
| 3133 | " destroy returned removed=" + activityRemoved); |
Dianne Hackborn | 42e620c | 2012-06-24 13:20:51 -0700 | [diff] [blame] | 3134 | return activityRemoved ? null : r; |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 3135 | } |
Craig Mautner | 05d6272ba | 2013-02-11 09:39:27 -0800 | [diff] [blame] | 3136 | |
| 3137 | // Need to go through the full pause cycle to get this |
| 3138 | // activity into the stopped state and then finish it. |
Wale Ogunwale | e23149f | 2015-03-06 15:39:44 -0800 | [diff] [blame] | 3139 | if (DEBUG_ALL) Slog.v(TAG, "Enqueueing pending finish: " + r); |
Craig Mautner | f333327 | 2013-04-22 10:55:53 -0700 | [diff] [blame] | 3140 | mStackSupervisor.mFinishingActivities.add(r); |
Martin Wallgren | c8733b8 | 2011-08-31 12:39:31 +0200 | [diff] [blame] | 3141 | r.resumeKeyDispatchingLocked(); |
Craig Mautner | ce5f3cb | 2013-04-22 08:58:54 -0700 | [diff] [blame] | 3142 | mStackSupervisor.getFocusedStack().resumeTopActivityLocked(null); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 3143 | return r; |
| 3144 | } |
| 3145 | |
Craig Mautner | ee36c77 | 2014-07-16 14:56:05 -0700 | [diff] [blame] | 3146 | void finishAllActivitiesLocked(boolean immediately) { |
| 3147 | boolean noActivitiesInStack = true; |
Craig Mautner | f4c909b | 2014-04-17 18:39:38 -0700 | [diff] [blame] | 3148 | for (int taskNdx = mTaskHistory.size() - 1; taskNdx >= 0; --taskNdx) { |
| 3149 | final ArrayList<ActivityRecord> activities = mTaskHistory.get(taskNdx).mActivities; |
| 3150 | for (int activityNdx = activities.size() - 1; activityNdx >= 0; --activityNdx) { |
| 3151 | final ActivityRecord r = activities.get(activityNdx); |
Craig Mautner | ee36c77 | 2014-07-16 14:56:05 -0700 | [diff] [blame] | 3152 | noActivitiesInStack = false; |
| 3153 | if (r.finishing && !immediately) { |
Craig Mautner | f4c909b | 2014-04-17 18:39:38 -0700 | [diff] [blame] | 3154 | continue; |
| 3155 | } |
Craig Mautner | ee36c77 | 2014-07-16 14:56:05 -0700 | [diff] [blame] | 3156 | Slog.d(TAG, "finishAllActivitiesLocked: finishing " + r + " immediately"); |
Craig Mautner | f4c909b | 2014-04-17 18:39:38 -0700 | [diff] [blame] | 3157 | finishCurrentActivityLocked(r, FINISH_IMMEDIATELY, false); |
| 3158 | } |
| 3159 | } |
Craig Mautner | ee36c77 | 2014-07-16 14:56:05 -0700 | [diff] [blame] | 3160 | if (noActivitiesInStack) { |
| 3161 | mActivityContainer.onTaskListEmptyLocked(); |
| 3162 | } |
Craig Mautner | f4c909b | 2014-04-17 18:39:38 -0700 | [diff] [blame] | 3163 | } |
| 3164 | |
Dianne Hackborn | 6f4d61f | 2014-08-21 17:50:42 -0700 | [diff] [blame] | 3165 | final boolean shouldUpRecreateTaskLocked(ActivityRecord srec, String destAffinity) { |
| 3166 | // Basic case: for simple app-centric recents, we need to recreate |
| 3167 | // the task if the affinity has changed. |
| 3168 | if (srec == null || srec.task.affinity == null || |
| 3169 | !srec.task.affinity.equals(destAffinity)) { |
| 3170 | return true; |
| 3171 | } |
| 3172 | // Document-centric case: an app may be split in to multiple documents; |
| 3173 | // they need to re-create their task if this current activity is the root |
| 3174 | // of a document, unless simply finishing it will return them to the the |
| 3175 | // correct app behind. |
Dianne Hackborn | f3eb843 | 2014-09-19 17:21:46 -0700 | [diff] [blame] | 3176 | if (srec.frontOfTask && srec.task != null && srec.task.getBaseIntent() != null |
| 3177 | && srec.task.getBaseIntent().isDocument()) { |
Dianne Hackborn | 6f4d61f | 2014-08-21 17:50:42 -0700 | [diff] [blame] | 3178 | // Okay, this activity is at the root of its task. What to do, what to do... |
| 3179 | if (srec.task.getTaskToReturnTo() != ActivityRecord.APPLICATION_ACTIVITY_TYPE) { |
| 3180 | // Finishing won't return to an application, so we need to recreate. |
| 3181 | return true; |
| 3182 | } |
| 3183 | // We now need to get the task below it to determine what to do. |
| 3184 | int taskIdx = mTaskHistory.indexOf(srec.task); |
| 3185 | if (taskIdx <= 0) { |
| 3186 | Slog.w(TAG, "shouldUpRecreateTask: task not in history for " + srec); |
| 3187 | return false; |
| 3188 | } |
| 3189 | if (taskIdx == 0) { |
| 3190 | // At the bottom of the stack, nothing to go back to. |
| 3191 | return true; |
| 3192 | } |
| 3193 | TaskRecord prevTask = mTaskHistory.get(taskIdx); |
| 3194 | if (!srec.task.affinity.equals(prevTask.affinity)) { |
| 3195 | // These are different apps, so need to recreate. |
| 3196 | return true; |
| 3197 | } |
| 3198 | } |
| 3199 | return false; |
| 3200 | } |
| 3201 | |
Wale Ogunwale | 7d70117 | 2015-03-11 15:36:30 -0700 | [diff] [blame] | 3202 | final boolean navigateUpToLocked(ActivityRecord srec, Intent destIntent, int resultCode, |
Craig Mautner | 05d6272ba | 2013-02-11 09:39:27 -0800 | [diff] [blame] | 3203 | Intent resultData) { |
Craig Mautner | 0247fc8 | 2013-02-28 14:32:06 -0800 | [diff] [blame] | 3204 | final TaskRecord task = srec.task; |
| 3205 | final ArrayList<ActivityRecord> activities = task.mActivities; |
| 3206 | final int start = activities.indexOf(srec); |
| 3207 | if (!mTaskHistory.contains(task) || (start < 0)) { |
Craig Mautner | 05d6272ba | 2013-02-11 09:39:27 -0800 | [diff] [blame] | 3208 | return false; |
| 3209 | } |
| 3210 | int finishTo = start - 1; |
Craig Mautner | 0247fc8 | 2013-02-28 14:32:06 -0800 | [diff] [blame] | 3211 | ActivityRecord parent = finishTo < 0 ? null : activities.get(finishTo); |
Craig Mautner | 05d6272ba | 2013-02-11 09:39:27 -0800 | [diff] [blame] | 3212 | boolean foundParentInTask = false; |
Craig Mautner | 0247fc8 | 2013-02-28 14:32:06 -0800 | [diff] [blame] | 3213 | final ComponentName dest = destIntent.getComponent(); |
| 3214 | if (start > 0 && dest != null) { |
| 3215 | for (int i = finishTo; i >= 0; i--) { |
| 3216 | ActivityRecord r = activities.get(i); |
| 3217 | if (r.info.packageName.equals(dest.getPackageName()) && |
Craig Mautner | 05d6272ba | 2013-02-11 09:39:27 -0800 | [diff] [blame] | 3218 | r.info.name.equals(dest.getClassName())) { |
| 3219 | finishTo = i; |
| 3220 | parent = r; |
| 3221 | foundParentInTask = true; |
| 3222 | break; |
| 3223 | } |
| 3224 | } |
| 3225 | } |
| 3226 | |
| 3227 | IActivityController controller = mService.mController; |
| 3228 | if (controller != null) { |
| 3229 | ActivityRecord next = topRunningActivityLocked(srec.appToken, 0); |
| 3230 | if (next != null) { |
| 3231 | // ask watcher if this is allowed |
| 3232 | boolean resumeOK = true; |
| 3233 | try { |
| 3234 | resumeOK = controller.activityResuming(next.packageName); |
| 3235 | } catch (RemoteException e) { |
| 3236 | mService.mController = null; |
Kenny Root | add5821 | 2013-05-07 09:47:34 -0700 | [diff] [blame] | 3237 | Watchdog.getInstance().setActivityController(null); |
Craig Mautner | 05d6272ba | 2013-02-11 09:39:27 -0800 | [diff] [blame] | 3238 | } |
| 3239 | |
| 3240 | if (!resumeOK) { |
| 3241 | return false; |
| 3242 | } |
| 3243 | } |
| 3244 | } |
| 3245 | final long origId = Binder.clearCallingIdentity(); |
| 3246 | for (int i = start; i > finishTo; i--) { |
Craig Mautner | 0247fc8 | 2013-02-28 14:32:06 -0800 | [diff] [blame] | 3247 | ActivityRecord r = activities.get(i); |
| 3248 | requestFinishActivityLocked(r.appToken, resultCode, resultData, "navigate-up", true); |
Craig Mautner | 05d6272ba | 2013-02-11 09:39:27 -0800 | [diff] [blame] | 3249 | // Only return the supplied result for the first activity finished |
| 3250 | resultCode = Activity.RESULT_CANCELED; |
| 3251 | resultData = null; |
| 3252 | } |
| 3253 | |
| 3254 | if (parent != null && foundParentInTask) { |
| 3255 | final int parentLaunchMode = parent.info.launchMode; |
| 3256 | final int destIntentFlags = destIntent.getFlags(); |
| 3257 | if (parentLaunchMode == ActivityInfo.LAUNCH_SINGLE_INSTANCE || |
| 3258 | parentLaunchMode == ActivityInfo.LAUNCH_SINGLE_TASK || |
| 3259 | parentLaunchMode == ActivityInfo.LAUNCH_SINGLE_TOP || |
| 3260 | (destIntentFlags & Intent.FLAG_ACTIVITY_CLEAR_TOP) != 0) { |
Dianne Hackborn | 85d558c | 2014-11-04 10:31:54 -0800 | [diff] [blame] | 3261 | parent.deliverNewIntentLocked(srec.info.applicationInfo.uid, destIntent, |
| 3262 | srec.packageName); |
Craig Mautner | 05d6272ba | 2013-02-11 09:39:27 -0800 | [diff] [blame] | 3263 | } else { |
| 3264 | try { |
| 3265 | ActivityInfo aInfo = AppGlobals.getPackageManager().getActivityInfo( |
| 3266 | destIntent.getComponent(), 0, srec.userId); |
Craig Mautner | 6170f73 | 2013-04-02 13:05:23 -0700 | [diff] [blame] | 3267 | int res = mStackSupervisor.startActivityLocked(srec.app.thread, destIntent, |
Dianne Hackborn | 91097de | 2014-04-04 18:02:06 -0700 | [diff] [blame] | 3268 | null, aInfo, null, null, parent.appToken, null, |
Craig Mautner | 05d6272ba | 2013-02-11 09:39:27 -0800 | [diff] [blame] | 3269 | 0, -1, parent.launchedFromUid, parent.launchedFromPackage, |
Dianne Hackborn | a7cfbe0 | 2015-07-16 10:52:52 -0700 | [diff] [blame] | 3270 | -1, parent.launchedFromUid, 0, null, false, true, null, null, null); |
Craig Mautner | 05d6272ba | 2013-02-11 09:39:27 -0800 | [diff] [blame] | 3271 | foundParentInTask = res == ActivityManager.START_SUCCESS; |
| 3272 | } catch (RemoteException e) { |
| 3273 | foundParentInTask = false; |
| 3274 | } |
| 3275 | requestFinishActivityLocked(parent.appToken, resultCode, |
Todd Kennedy | 539db51 | 2014-12-15 09:57:55 -0800 | [diff] [blame] | 3276 | resultData, "navigate-top", true); |
Craig Mautner | 05d6272ba | 2013-02-11 09:39:27 -0800 | [diff] [blame] | 3277 | } |
| 3278 | } |
| 3279 | Binder.restoreCallingIdentity(origId); |
| 3280 | return foundParentInTask; |
| 3281 | } |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 3282 | /** |
| 3283 | * Perform the common clean-up of an activity record. This is called both |
| 3284 | * as part of destroyActivityLocked() (when destroying the client-side |
| 3285 | * representation) and cleaning things up as a result of its hosting |
| 3286 | * processing going away, in which case there is no remaining client-side |
| 3287 | * state to destroy so only the cleanup here is needed. |
Craig Mautner | acebdc8 | 2015-02-24 10:53:03 -0800 | [diff] [blame] | 3288 | * |
| 3289 | * Note: Call before #removeActivityFromHistoryLocked. |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 3290 | */ |
Dianne Hackborn | ce86ba8 | 2011-07-13 19:33:41 -0700 | [diff] [blame] | 3291 | final void cleanUpActivityLocked(ActivityRecord r, boolean cleanServices, |
| 3292 | boolean setState) { |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 3293 | if (mResumedActivity == r) { |
| 3294 | mResumedActivity = null; |
| 3295 | } |
Craig Mautner | 1872ce3 | 2014-03-28 23:05:42 +0000 | [diff] [blame] | 3296 | if (mPausingActivity == r) { |
| 3297 | mPausingActivity = null; |
| 3298 | } |
Dianne Hackborn | 91097de | 2014-04-04 18:02:06 -0700 | [diff] [blame] | 3299 | mService.clearFocusedActivity(r); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 3300 | |
| 3301 | r.configDestroy = false; |
| 3302 | r.frozenBeforeDestroy = false; |
| 3303 | |
Dianne Hackborn | ce86ba8 | 2011-07-13 19:33:41 -0700 | [diff] [blame] | 3304 | if (setState) { |
Wale Ogunwale | 0fc365c | 2015-05-25 19:35:42 -0700 | [diff] [blame] | 3305 | if (DEBUG_STATES) Slog.v(TAG_STATES, "Moving to DESTROYED: " + r + " (cleaning up)"); |
Dianne Hackborn | ce86ba8 | 2011-07-13 19:33:41 -0700 | [diff] [blame] | 3306 | r.state = ActivityState.DESTROYED; |
Wale Ogunwale | 0fc365c | 2015-05-25 19:35:42 -0700 | [diff] [blame] | 3307 | if (DEBUG_APP) Slog.v(TAG_APP, "Clearing app during cleanUp for activity " + r); |
Dianne Hackborn | cc5a055 | 2012-10-01 16:32:39 -0700 | [diff] [blame] | 3308 | r.app = null; |
Dianne Hackborn | ce86ba8 | 2011-07-13 19:33:41 -0700 | [diff] [blame] | 3309 | } |
| 3310 | |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 3311 | // Make sure this record is no longer in the pending finishes list. |
| 3312 | // This could happen, for example, if we are trimming activities |
| 3313 | // down to the max limit while they are still waiting to finish. |
Craig Mautner | f333327 | 2013-04-22 10:55:53 -0700 | [diff] [blame] | 3314 | mStackSupervisor.mFinishingActivities.remove(r); |
Craig Mautner | de4ef02 | 2013-04-07 19:01:33 -0700 | [diff] [blame] | 3315 | mStackSupervisor.mWaitingVisibleActivities.remove(r); |
Craig Mautner | 2420ead | 2013-04-01 17:13:20 -0700 | [diff] [blame] | 3316 | |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 3317 | // Remove any pending results. |
| 3318 | if (r.finishing && r.pendingResults != null) { |
| 3319 | for (WeakReference<PendingIntentRecord> apr : r.pendingResults) { |
| 3320 | PendingIntentRecord rec = apr.get(); |
| 3321 | if (rec != null) { |
| 3322 | mService.cancelIntentSenderLocked(rec, false); |
| 3323 | } |
| 3324 | } |
| 3325 | r.pendingResults = null; |
| 3326 | } |
| 3327 | |
| 3328 | if (cleanServices) { |
Craig Mautner | 2420ead | 2013-04-01 17:13:20 -0700 | [diff] [blame] | 3329 | cleanUpActivityServicesLocked(r); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 3330 | } |
| 3331 | |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 3332 | // Get rid of any pending idle timeouts. |
Dianne Hackborn | 42e620c | 2012-06-24 13:20:51 -0700 | [diff] [blame] | 3333 | removeTimeoutsForActivityLocked(r); |
Jose Lima | 4b6c669 | 2014-08-12 17:41:12 -0700 | [diff] [blame] | 3334 | if (getVisibleBehindActivity() == r) { |
| 3335 | mStackSupervisor.requestVisibleBehindLocked(r, false); |
Craig Mautner | ee2e45a | 2014-06-27 12:10:03 -0700 | [diff] [blame] | 3336 | } |
Dianne Hackborn | 42e620c | 2012-06-24 13:20:51 -0700 | [diff] [blame] | 3337 | } |
| 3338 | |
| 3339 | private void removeTimeoutsForActivityLocked(ActivityRecord r) { |
Craig Mautner | f333327 | 2013-04-22 10:55:53 -0700 | [diff] [blame] | 3340 | mStackSupervisor.removeTimeoutsForActivityLocked(r); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 3341 | mHandler.removeMessages(PAUSE_TIMEOUT_MSG, r); |
Dianne Hackborn | 162bc0e | 2012-04-09 14:06:16 -0700 | [diff] [blame] | 3342 | mHandler.removeMessages(STOP_TIMEOUT_MSG, r); |
Dianne Hackborn | 0c5001d | 2011-04-12 18:16:08 -0700 | [diff] [blame] | 3343 | mHandler.removeMessages(DESTROY_TIMEOUT_MSG, r); |
Dianne Hackborn | 2a29b3a | 2012-03-15 15:48:38 -0700 | [diff] [blame] | 3344 | r.finishLaunchTickingLocked(); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 3345 | } |
| 3346 | |
Craig Mautner | 299f960 | 2015-01-26 09:47:33 -0800 | [diff] [blame] | 3347 | private void removeActivityFromHistoryLocked(ActivityRecord r, String reason) { |
Craig Mautner | 34b73df | 2014-01-12 21:11:08 -0800 | [diff] [blame] | 3348 | mStackSupervisor.removeChildActivityContainers(r); |
Dianne Hackborn | cc5a055 | 2012-10-01 16:32:39 -0700 | [diff] [blame] | 3349 | finishActivityResultsLocked(r, Activity.RESULT_CANCELED, null); |
Wale Ogunwale | 7d70117 | 2015-03-11 15:36:30 -0700 | [diff] [blame] | 3350 | r.makeFinishingLocked(); |
Wale Ogunwale | 0fc365c | 2015-05-25 19:35:42 -0700 | [diff] [blame] | 3351 | if (DEBUG_ADD_REMOVE) Slog.i(TAG_ADD_REMOVE, |
| 3352 | "Removing activity " + r + " from stack callers=" + Debug.getCallers(5)); |
| 3353 | |
Dianne Hackborn | cc5a055 | 2012-10-01 16:32:39 -0700 | [diff] [blame] | 3354 | r.takeFromHistory(); |
| 3355 | removeTimeoutsForActivityLocked(r); |
Wale Ogunwale | 0fc365c | 2015-05-25 19:35:42 -0700 | [diff] [blame] | 3356 | if (DEBUG_STATES) Slog.v(TAG_STATES, |
| 3357 | "Moving to DESTROYED: " + r + " (removed from history)"); |
Dianne Hackborn | cc5a055 | 2012-10-01 16:32:39 -0700 | [diff] [blame] | 3358 | r.state = ActivityState.DESTROYED; |
Wale Ogunwale | 0fc365c | 2015-05-25 19:35:42 -0700 | [diff] [blame] | 3359 | if (DEBUG_APP) Slog.v(TAG_APP, "Clearing app during remove for activity " + r); |
Dianne Hackborn | cc5a055 | 2012-10-01 16:32:39 -0700 | [diff] [blame] | 3360 | r.app = null; |
Craig Mautner | ce5f3cb | 2013-04-22 08:58:54 -0700 | [diff] [blame] | 3361 | mWindowManager.removeAppToken(r.appToken); |
Dianne Hackborn | cc5a055 | 2012-10-01 16:32:39 -0700 | [diff] [blame] | 3362 | if (VALIDATE_TOKENS) { |
| 3363 | validateAppTokensLocked(); |
| 3364 | } |
Craig Mautner | 312ba86 | 2014-02-10 17:55:01 -0800 | [diff] [blame] | 3365 | final TaskRecord task = r.task; |
| 3366 | if (task != null && task.removeActivity(r)) { |
Wale Ogunwale | ee006da | 2015-03-30 14:49:25 -0700 | [diff] [blame] | 3367 | if (DEBUG_STACK) Slog.i(TAG_STACK, |
Craig Mautner | 312ba86 | 2014-02-10 17:55:01 -0800 | [diff] [blame] | 3368 | "removeActivityFromHistoryLocked: last activity removed from " + this); |
Craig Mautner | 84984fa | 2014-06-19 11:19:20 -0700 | [diff] [blame] | 3369 | if (mStackSupervisor.isFrontStack(this) && task == topTask() && |
| 3370 | task.isOverHomeStack()) { |
Craig Mautner | 299f960 | 2015-01-26 09:47:33 -0800 | [diff] [blame] | 3371 | mStackSupervisor.moveHomeStackTaskToTop(task.getTaskToReturnTo(), reason); |
Craig Mautner | 312ba86 | 2014-02-10 17:55:01 -0800 | [diff] [blame] | 3372 | } |
Craig Mautner | 299f960 | 2015-01-26 09:47:33 -0800 | [diff] [blame] | 3373 | removeTask(task, reason); |
Craig Mautner | 312ba86 | 2014-02-10 17:55:01 -0800 | [diff] [blame] | 3374 | } |
Dianne Hackborn | cc5a055 | 2012-10-01 16:32:39 -0700 | [diff] [blame] | 3375 | cleanUpActivityServicesLocked(r); |
| 3376 | r.removeUriPermissionsLocked(); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 3377 | } |
Craig Mautner | dbcb31f | 2013-04-02 12:32:53 -0700 | [diff] [blame] | 3378 | |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 3379 | /** |
| 3380 | * Perform clean-up of service connections in an activity record. |
| 3381 | */ |
| 3382 | final void cleanUpActivityServicesLocked(ActivityRecord r) { |
| 3383 | // Throw away any services that have been bound by this activity. |
| 3384 | if (r.connections != null) { |
| 3385 | Iterator<ConnectionRecord> it = r.connections.iterator(); |
| 3386 | while (it.hasNext()) { |
| 3387 | ConnectionRecord c = it.next(); |
Dianne Hackborn | 599db5c | 2012-08-03 19:28:48 -0700 | [diff] [blame] | 3388 | mService.mServices.removeConnectionLocked(c, null, r); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 3389 | } |
| 3390 | r.connections = null; |
| 3391 | } |
| 3392 | } |
Dianne Hackborn | 755c8bf | 2012-05-07 15:06:09 -0700 | [diff] [blame] | 3393 | |
Craig Mautner | ee2e45a | 2014-06-27 12:10:03 -0700 | [diff] [blame] | 3394 | final void scheduleDestroyActivities(ProcessRecord owner, String reason) { |
Dianne Hackborn | 755c8bf | 2012-05-07 15:06:09 -0700 | [diff] [blame] | 3395 | Message msg = mHandler.obtainMessage(DESTROY_ACTIVITIES_MSG); |
Craig Mautner | ee2e45a | 2014-06-27 12:10:03 -0700 | [diff] [blame] | 3396 | msg.obj = new ScheduleDestroyArgs(owner, reason); |
Dianne Hackborn | 755c8bf | 2012-05-07 15:06:09 -0700 | [diff] [blame] | 3397 | mHandler.sendMessage(msg); |
| 3398 | } |
| 3399 | |
Craig Mautner | ee2e45a | 2014-06-27 12:10:03 -0700 | [diff] [blame] | 3400 | final void destroyActivitiesLocked(ProcessRecord owner, String reason) { |
Dianne Hackborn | 755c8bf | 2012-05-07 15:06:09 -0700 | [diff] [blame] | 3401 | boolean lastIsOpaque = false; |
Dianne Hackborn | 42e620c | 2012-06-24 13:20:51 -0700 | [diff] [blame] | 3402 | boolean activityRemoved = false; |
Craig Mautner | d44711d | 2013-02-23 11:24:36 -0800 | [diff] [blame] | 3403 | for (int taskNdx = mTaskHistory.size() - 1; taskNdx >= 0; --taskNdx) { |
| 3404 | final ArrayList<ActivityRecord> activities = mTaskHistory.get(taskNdx).mActivities; |
| 3405 | for (int activityNdx = activities.size() - 1; activityNdx >= 0; --activityNdx) { |
| 3406 | final ActivityRecord r = activities.get(activityNdx); |
| 3407 | if (r.finishing) { |
| 3408 | continue; |
| 3409 | } |
| 3410 | if (r.fullscreen) { |
| 3411 | lastIsOpaque = true; |
| 3412 | } |
| 3413 | if (owner != null && r.app != owner) { |
| 3414 | continue; |
| 3415 | } |
| 3416 | if (!lastIsOpaque) { |
| 3417 | continue; |
| 3418 | } |
Dianne Hackborn | 89ad456 | 2014-08-24 16:45:38 -0700 | [diff] [blame] | 3419 | if (r.isDestroyable()) { |
Wale Ogunwale | ee006da | 2015-03-30 14:49:25 -0700 | [diff] [blame] | 3420 | if (DEBUG_SWITCH) Slog.v(TAG_SWITCH, "Destroying " + r + " in state " + r.state |
Craig Mautner | d44711d | 2013-02-23 11:24:36 -0800 | [diff] [blame] | 3421 | + " resumed=" + mResumedActivity |
Dianne Hackborn | 89ad456 | 2014-08-24 16:45:38 -0700 | [diff] [blame] | 3422 | + " pausing=" + mPausingActivity + " for reason " + reason); |
Craig Mautner | ee2e45a | 2014-06-27 12:10:03 -0700 | [diff] [blame] | 3423 | if (destroyActivityLocked(r, true, reason)) { |
Craig Mautner | d44711d | 2013-02-23 11:24:36 -0800 | [diff] [blame] | 3424 | activityRemoved = true; |
| 3425 | } |
Dianne Hackborn | 42e620c | 2012-06-24 13:20:51 -0700 | [diff] [blame] | 3426 | } |
Dianne Hackborn | ce86ba8 | 2011-07-13 19:33:41 -0700 | [diff] [blame] | 3427 | } |
| 3428 | } |
Dianne Hackborn | 42e620c | 2012-06-24 13:20:51 -0700 | [diff] [blame] | 3429 | if (activityRemoved) { |
Craig Mautner | 05d2903 | 2013-05-03 13:40:13 -0700 | [diff] [blame] | 3430 | mStackSupervisor.resumeTopActivitiesLocked(); |
Dianne Hackborn | 42e620c | 2012-06-24 13:20:51 -0700 | [diff] [blame] | 3431 | } |
Dianne Hackborn | ce86ba8 | 2011-07-13 19:33:41 -0700 | [diff] [blame] | 3432 | } |
| 3433 | |
Dianne Hackborn | 89ad456 | 2014-08-24 16:45:38 -0700 | [diff] [blame] | 3434 | final boolean safelyDestroyActivityLocked(ActivityRecord r, String reason) { |
| 3435 | if (r.isDestroyable()) { |
Wale Ogunwale | ee006da | 2015-03-30 14:49:25 -0700 | [diff] [blame] | 3436 | if (DEBUG_SWITCH) Slog.v(TAG_SWITCH, |
| 3437 | "Destroying " + r + " in state " + r.state + " resumed=" + mResumedActivity |
Dianne Hackborn | 89ad456 | 2014-08-24 16:45:38 -0700 | [diff] [blame] | 3438 | + " pausing=" + mPausingActivity + " for reason " + reason); |
| 3439 | return destroyActivityLocked(r, true, reason); |
| 3440 | } |
| 3441 | return false; |
| 3442 | } |
| 3443 | |
| 3444 | final int releaseSomeActivitiesLocked(ProcessRecord app, ArraySet<TaskRecord> tasks, |
| 3445 | String reason) { |
| 3446 | // Iterate over tasks starting at the back (oldest) first. |
Wale Ogunwale | 0fc365c | 2015-05-25 19:35:42 -0700 | [diff] [blame] | 3447 | if (DEBUG_RELEASE) Slog.d(TAG_RELEASE, "Trying to release some activities in " + app); |
Dianne Hackborn | 89ad456 | 2014-08-24 16:45:38 -0700 | [diff] [blame] | 3448 | int maxTasks = tasks.size() / 4; |
| 3449 | if (maxTasks < 1) { |
| 3450 | maxTasks = 1; |
| 3451 | } |
| 3452 | int numReleased = 0; |
| 3453 | for (int taskNdx = 0; taskNdx < mTaskHistory.size() && maxTasks > 0; taskNdx++) { |
| 3454 | final TaskRecord task = mTaskHistory.get(taskNdx); |
| 3455 | if (!tasks.contains(task)) { |
| 3456 | continue; |
| 3457 | } |
Wale Ogunwale | 0fc365c | 2015-05-25 19:35:42 -0700 | [diff] [blame] | 3458 | if (DEBUG_RELEASE) Slog.d(TAG_RELEASE, "Looking for activities to release in " + task); |
Dianne Hackborn | 89ad456 | 2014-08-24 16:45:38 -0700 | [diff] [blame] | 3459 | int curNum = 0; |
| 3460 | final ArrayList<ActivityRecord> activities = task.mActivities; |
| 3461 | for (int actNdx = 0; actNdx < activities.size(); actNdx++) { |
| 3462 | final ActivityRecord activity = activities.get(actNdx); |
| 3463 | if (activity.app == app && activity.isDestroyable()) { |
Wale Ogunwale | 0fc365c | 2015-05-25 19:35:42 -0700 | [diff] [blame] | 3464 | if (DEBUG_RELEASE) Slog.v(TAG_RELEASE, "Destroying " + activity |
Dianne Hackborn | 89ad456 | 2014-08-24 16:45:38 -0700 | [diff] [blame] | 3465 | + " in state " + activity.state + " resumed=" + mResumedActivity |
| 3466 | + " pausing=" + mPausingActivity + " for reason " + reason); |
| 3467 | destroyActivityLocked(activity, true, reason); |
| 3468 | if (activities.get(actNdx) != activity) { |
| 3469 | // Was removed from list, back up so we don't miss the next one. |
| 3470 | actNdx--; |
| 3471 | } |
| 3472 | curNum++; |
| 3473 | } |
| 3474 | } |
| 3475 | if (curNum > 0) { |
| 3476 | numReleased += curNum; |
| 3477 | maxTasks--; |
| 3478 | if (mTaskHistory.get(taskNdx) != task) { |
| 3479 | // The entire task got removed, back up so we don't miss the next one. |
| 3480 | taskNdx--; |
| 3481 | } |
| 3482 | } |
| 3483 | } |
Wale Ogunwale | 0fc365c | 2015-05-25 19:35:42 -0700 | [diff] [blame] | 3484 | if (DEBUG_RELEASE) Slog.d(TAG_RELEASE, |
| 3485 | "Done releasing: did " + numReleased + " activities"); |
Dianne Hackborn | 89ad456 | 2014-08-24 16:45:38 -0700 | [diff] [blame] | 3486 | return numReleased; |
| 3487 | } |
| 3488 | |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 3489 | /** |
| 3490 | * Destroy the current CLIENT SIDE instance of an activity. This may be |
| 3491 | * called both when actually finishing an activity, or when performing |
| 3492 | * a configuration switch where we destroy the current client-side object |
| 3493 | * but then create a new client-side object for this same HistoryRecord. |
| 3494 | */ |
Craig Mautner | ee2e45a | 2014-06-27 12:10:03 -0700 | [diff] [blame] | 3495 | final boolean destroyActivityLocked(ActivityRecord r, boolean removeFromApp, String reason) { |
Wale Ogunwale | ee006da | 2015-03-30 14:49:25 -0700 | [diff] [blame] | 3496 | if (DEBUG_SWITCH || DEBUG_CLEANUP) Slog.v(TAG_SWITCH, |
| 3497 | "Removing activity from " + reason + ": token=" + r |
Filip Gruszczynski | a59ac9c | 2015-09-10 18:28:48 -0700 | [diff] [blame] | 3498 | + ", app=" + (r.app != null ? r.app.processName : "(null)")); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 3499 | EventLog.writeEvent(EventLogTags.AM_DESTROY_ACTIVITY, |
Dianne Hackborn | b12e135 | 2012-09-26 11:39:20 -0700 | [diff] [blame] | 3500 | r.userId, System.identityHashCode(r), |
Dianne Hackborn | 28695e0 | 2011-11-02 21:59:51 -0700 | [diff] [blame] | 3501 | r.task.taskId, r.shortComponentName, reason); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 3502 | |
| 3503 | boolean removedFromHistory = false; |
Dianne Hackborn | cc5a055 | 2012-10-01 16:32:39 -0700 | [diff] [blame] | 3504 | |
Dianne Hackborn | ce86ba8 | 2011-07-13 19:33:41 -0700 | [diff] [blame] | 3505 | cleanUpActivityLocked(r, false, false); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 3506 | |
| 3507 | final boolean hadApp = r.app != null; |
Dianne Hackborn | cc5a055 | 2012-10-01 16:32:39 -0700 | [diff] [blame] | 3508 | |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 3509 | if (hadApp) { |
| 3510 | if (removeFromApp) { |
Craig Mautner | d232895 | 2013-03-05 12:46:26 -0800 | [diff] [blame] | 3511 | r.app.activities.remove(r); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 3512 | if (mService.mHeavyWeightProcess == r.app && r.app.activities.size() <= 0) { |
| 3513 | mService.mHeavyWeightProcess = null; |
| 3514 | mService.mHandler.sendEmptyMessage( |
| 3515 | ActivityManagerService.CANCEL_HEAVY_NOTIFICATION_MSG); |
| 3516 | } |
Craig Mautner | c8143c6 | 2013-09-03 12:15:57 -0700 | [diff] [blame] | 3517 | if (r.app.activities.isEmpty()) { |
Dianne Hackborn | 465fa39 | 2014-09-14 14:21:18 -0700 | [diff] [blame] | 3518 | // Update any services we are bound to that might care about whether |
| 3519 | // their client may have activities. |
| 3520 | mService.mServices.updateServiceConnectionActivitiesLocked(r.app); |
Dianne Hackborn | 3bc8f78d | 2013-09-19 13:34:35 -0700 | [diff] [blame] | 3521 | // No longer have activities, so update LRU list and oom adj. |
Dianne Hackborn | db92608 | 2013-10-31 16:32:44 -0700 | [diff] [blame] | 3522 | mService.updateLruProcessLocked(r.app, false, null); |
Dianne Hackborn | 2d1b378 | 2012-09-09 17:49:39 -0700 | [diff] [blame] | 3523 | mService.updateOomAdjLocked(); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 3524 | } |
| 3525 | } |
| 3526 | |
| 3527 | boolean skipDestroy = false; |
Craig Mautner | dbcb31f | 2013-04-02 12:32:53 -0700 | [diff] [blame] | 3528 | |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 3529 | try { |
Wale Ogunwale | ee006da | 2015-03-30 14:49:25 -0700 | [diff] [blame] | 3530 | if (DEBUG_SWITCH) Slog.i(TAG_SWITCH, "Destroying: " + r); |
Dianne Hackborn | be70785 | 2011-11-11 14:32:10 -0800 | [diff] [blame] | 3531 | r.app.thread.scheduleDestroyActivity(r.appToken, r.finishing, |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 3532 | r.configChangeFlags); |
| 3533 | } catch (Exception e) { |
| 3534 | // We can just ignore exceptions here... if the process |
| 3535 | // has crashed, our death notification will clean things |
| 3536 | // up. |
| 3537 | //Slog.w(TAG, "Exception thrown during finish", e); |
| 3538 | if (r.finishing) { |
Craig Mautner | 299f960 | 2015-01-26 09:47:33 -0800 | [diff] [blame] | 3539 | removeActivityFromHistoryLocked(r, reason + " exceptionInScheduleDestroy"); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 3540 | removedFromHistory = true; |
| 3541 | skipDestroy = true; |
| 3542 | } |
| 3543 | } |
| 3544 | |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 3545 | r.nowVisible = false; |
Craig Mautner | dbcb31f | 2013-04-02 12:32:53 -0700 | [diff] [blame] | 3546 | |
Dianne Hackborn | ce86ba8 | 2011-07-13 19:33:41 -0700 | [diff] [blame] | 3547 | // If the activity is finishing, we need to wait on removing it |
| 3548 | // from the list to give it a chance to do its cleanup. During |
| 3549 | // that time it may make calls back with its token so we need to |
| 3550 | // be able to find it on the list and so we don't want to remove |
| 3551 | // it from the list yet. Otherwise, we can just immediately put |
| 3552 | // it in the destroyed state since we are not removing it from the |
| 3553 | // list. |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 3554 | if (r.finishing && !skipDestroy) { |
Wale Ogunwale | 0fc365c | 2015-05-25 19:35:42 -0700 | [diff] [blame] | 3555 | if (DEBUG_STATES) Slog.v(TAG_STATES, "Moving to DESTROYING: " + r |
Dianne Hackborn | ce86ba8 | 2011-07-13 19:33:41 -0700 | [diff] [blame] | 3556 | + " (destroy requested)"); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 3557 | r.state = ActivityState.DESTROYING; |
Craig Mautner | f7bfefb | 2013-05-16 17:30:44 -0700 | [diff] [blame] | 3558 | Message msg = mHandler.obtainMessage(DESTROY_TIMEOUT_MSG, r); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 3559 | mHandler.sendMessageDelayed(msg, DESTROY_TIMEOUT); |
| 3560 | } else { |
Wale Ogunwale | 0fc365c | 2015-05-25 19:35:42 -0700 | [diff] [blame] | 3561 | if (DEBUG_STATES) Slog.v(TAG_STATES, |
| 3562 | "Moving to DESTROYED: " + r + " (destroy skipped)"); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 3563 | r.state = ActivityState.DESTROYED; |
Wale Ogunwale | 0fc365c | 2015-05-25 19:35:42 -0700 | [diff] [blame] | 3564 | if (DEBUG_APP) Slog.v(TAG_APP, "Clearing app during destroy for activity " + r); |
Dianne Hackborn | cc5a055 | 2012-10-01 16:32:39 -0700 | [diff] [blame] | 3565 | r.app = null; |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 3566 | } |
| 3567 | } else { |
| 3568 | // remove this record from the history. |
| 3569 | if (r.finishing) { |
Craig Mautner | 299f960 | 2015-01-26 09:47:33 -0800 | [diff] [blame] | 3570 | removeActivityFromHistoryLocked(r, reason + " hadNoApp"); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 3571 | removedFromHistory = true; |
| 3572 | } else { |
Wale Ogunwale | 0fc365c | 2015-05-25 19:35:42 -0700 | [diff] [blame] | 3573 | if (DEBUG_STATES) Slog.v(TAG_STATES, "Moving to DESTROYED: " + r + " (no app)"); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 3574 | r.state = ActivityState.DESTROYED; |
Wale Ogunwale | 0fc365c | 2015-05-25 19:35:42 -0700 | [diff] [blame] | 3575 | if (DEBUG_APP) Slog.v(TAG_APP, "Clearing app during destroy for activity " + r); |
Dianne Hackborn | cc5a055 | 2012-10-01 16:32:39 -0700 | [diff] [blame] | 3576 | r.app = null; |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 3577 | } |
| 3578 | } |
| 3579 | |
| 3580 | r.configChangeFlags = 0; |
Craig Mautner | dbcb31f | 2013-04-02 12:32:53 -0700 | [diff] [blame] | 3581 | |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 3582 | if (!mLRUActivities.remove(r) && hadApp) { |
| 3583 | Slog.w(TAG, "Activity " + r + " being finished, but not in LRU list"); |
| 3584 | } |
Craig Mautner | dbcb31f | 2013-04-02 12:32:53 -0700 | [diff] [blame] | 3585 | |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 3586 | return removedFromHistory; |
| 3587 | } |
| 3588 | |
Craig Mautner | 299f960 | 2015-01-26 09:47:33 -0800 | [diff] [blame] | 3589 | final void activityDestroyedLocked(IBinder token, String reason) { |
Craig Mautner | d232895 | 2013-03-05 12:46:26 -0800 | [diff] [blame] | 3590 | final long origId = Binder.clearCallingIdentity(); |
| 3591 | try { |
Wale Ogunwale | 7d70117 | 2015-03-11 15:36:30 -0700 | [diff] [blame] | 3592 | ActivityRecord r = ActivityRecord.forTokenLocked(token); |
Craig Mautner | d232895 | 2013-03-05 12:46:26 -0800 | [diff] [blame] | 3593 | if (r != null) { |
| 3594 | mHandler.removeMessages(DESTROY_TIMEOUT_MSG, r); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 3595 | } |
Wale Ogunwale | 0fc365c | 2015-05-25 19:35:42 -0700 | [diff] [blame] | 3596 | if (DEBUG_CONTAINERS) Slog.d(TAG_CONTAINERS, "activityDestroyedLocked: r=" + r); |
Craig Mautner | d232895 | 2013-03-05 12:46:26 -0800 | [diff] [blame] | 3597 | |
Wale Ogunwale | 60454db | 2015-01-23 16:05:07 -0800 | [diff] [blame] | 3598 | if (isInStackLocked(r) != null) { |
Craig Mautner | d232895 | 2013-03-05 12:46:26 -0800 | [diff] [blame] | 3599 | if (r.state == ActivityState.DESTROYING) { |
| 3600 | cleanUpActivityLocked(r, true, false); |
Craig Mautner | 299f960 | 2015-01-26 09:47:33 -0800 | [diff] [blame] | 3601 | removeActivityFromHistoryLocked(r, reason); |
Craig Mautner | d232895 | 2013-03-05 12:46:26 -0800 | [diff] [blame] | 3602 | } |
| 3603 | } |
Craig Mautner | 05d2903 | 2013-05-03 13:40:13 -0700 | [diff] [blame] | 3604 | mStackSupervisor.resumeTopActivitiesLocked(); |
Craig Mautner | d232895 | 2013-03-05 12:46:26 -0800 | [diff] [blame] | 3605 | } finally { |
| 3606 | Binder.restoreCallingIdentity(origId); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 3607 | } |
| 3608 | } |
Craig Mautner | de4ef02 | 2013-04-07 19:01:33 -0700 | [diff] [blame] | 3609 | |
Todd Kennedy | aab56db | 2015-01-30 09:39:53 -0800 | [diff] [blame] | 3610 | void releaseBackgroundResources(ActivityRecord r) { |
Jose Lima | 4b6c669 | 2014-08-12 17:41:12 -0700 | [diff] [blame] | 3611 | if (hasVisibleBehindActivity() && |
| 3612 | !mHandler.hasMessages(RELEASE_BACKGROUND_RESOURCES_TIMEOUT_MSG)) { |
Craig Mautner | 64ccb70 | 2014-10-01 09:38:40 -0700 | [diff] [blame] | 3613 | if (r == topRunningActivityLocked(null)) { |
| 3614 | // Don't release the top activity if it has requested to run behind the next |
| 3615 | // activity. |
| 3616 | return; |
| 3617 | } |
Wale Ogunwale | 0fc365c | 2015-05-25 19:35:42 -0700 | [diff] [blame] | 3618 | if (DEBUG_STATES) Slog.d(TAG_STATES, "releaseBackgroundResources activtyDisplay=" + |
Jose Lima | 4b6c669 | 2014-08-12 17:41:12 -0700 | [diff] [blame] | 3619 | mActivityContainer.mActivityDisplay + " visibleBehind=" + r + " app=" + r.app + |
Craig Mautner | ee2e45a | 2014-06-27 12:10:03 -0700 | [diff] [blame] | 3620 | " thread=" + r.app.thread); |
| 3621 | if (r != null && r.app != null && r.app.thread != null) { |
| 3622 | try { |
Jose Lima | 4b6c669 | 2014-08-12 17:41:12 -0700 | [diff] [blame] | 3623 | r.app.thread.scheduleCancelVisibleBehind(r.appToken); |
Craig Mautner | ee2e45a | 2014-06-27 12:10:03 -0700 | [diff] [blame] | 3624 | } catch (RemoteException e) { |
| 3625 | } |
Jose Lima | 4b6c669 | 2014-08-12 17:41:12 -0700 | [diff] [blame] | 3626 | mHandler.sendEmptyMessageDelayed(RELEASE_BACKGROUND_RESOURCES_TIMEOUT_MSG, 500); |
Craig Mautner | ee2e45a | 2014-06-27 12:10:03 -0700 | [diff] [blame] | 3627 | } else { |
Jose Lima | 4b6c669 | 2014-08-12 17:41:12 -0700 | [diff] [blame] | 3628 | Slog.e(TAG, "releaseBackgroundResources: activity " + r + " no longer running"); |
Wale Ogunwale | 1f4c02b | 2014-11-13 14:22:32 -0800 | [diff] [blame] | 3629 | backgroundResourcesReleased(); |
Craig Mautner | ee2e45a | 2014-06-27 12:10:03 -0700 | [diff] [blame] | 3630 | } |
| 3631 | } |
| 3632 | } |
| 3633 | |
Wale Ogunwale | 1f4c02b | 2014-11-13 14:22:32 -0800 | [diff] [blame] | 3634 | final void backgroundResourcesReleased() { |
Jose Lima | 4b6c669 | 2014-08-12 17:41:12 -0700 | [diff] [blame] | 3635 | mHandler.removeMessages(RELEASE_BACKGROUND_RESOURCES_TIMEOUT_MSG); |
| 3636 | final ActivityRecord r = getVisibleBehindActivity(); |
Craig Mautner | ee2e45a | 2014-06-27 12:10:03 -0700 | [diff] [blame] | 3637 | if (r != null) { |
| 3638 | mStackSupervisor.mStoppingActivities.add(r); |
Jose Lima | 4b6c669 | 2014-08-12 17:41:12 -0700 | [diff] [blame] | 3639 | setVisibleBehindActivity(null); |
Wale Ogunwale | 1f4c02b | 2014-11-13 14:22:32 -0800 | [diff] [blame] | 3640 | mStackSupervisor.scheduleIdleTimeoutLocked(null); |
Craig Mautner | ee2e45a | 2014-06-27 12:10:03 -0700 | [diff] [blame] | 3641 | } |
| 3642 | mStackSupervisor.resumeTopActivitiesLocked(); |
| 3643 | } |
| 3644 | |
Jose Lima | 4b6c669 | 2014-08-12 17:41:12 -0700 | [diff] [blame] | 3645 | boolean hasVisibleBehindActivity() { |
| 3646 | return isAttached() && mActivityContainer.mActivityDisplay.hasVisibleBehindActivity(); |
Craig Mautner | ee2e45a | 2014-06-27 12:10:03 -0700 | [diff] [blame] | 3647 | } |
| 3648 | |
Jose Lima | 4b6c669 | 2014-08-12 17:41:12 -0700 | [diff] [blame] | 3649 | void setVisibleBehindActivity(ActivityRecord r) { |
Craig Mautner | ee2e45a | 2014-06-27 12:10:03 -0700 | [diff] [blame] | 3650 | if (isAttached()) { |
Jose Lima | 4b6c669 | 2014-08-12 17:41:12 -0700 | [diff] [blame] | 3651 | mActivityContainer.mActivityDisplay.setVisibleBehindActivity(r); |
Craig Mautner | ee2e45a | 2014-06-27 12:10:03 -0700 | [diff] [blame] | 3652 | } |
| 3653 | } |
| 3654 | |
Jose Lima | 4b6c669 | 2014-08-12 17:41:12 -0700 | [diff] [blame] | 3655 | ActivityRecord getVisibleBehindActivity() { |
| 3656 | return isAttached() ? mActivityContainer.mActivityDisplay.mVisibleBehindActivity : null; |
Craig Mautner | ee2e45a | 2014-06-27 12:10:03 -0700 | [diff] [blame] | 3657 | } |
| 3658 | |
Craig Mautner | 05d6272ba | 2013-02-11 09:39:27 -0800 | [diff] [blame] | 3659 | private void removeHistoryRecordsForAppLocked(ArrayList<ActivityRecord> list, |
| 3660 | ProcessRecord app, String listName) { |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 3661 | int i = list.size(); |
Wale Ogunwale | e23149f | 2015-03-06 15:39:44 -0800 | [diff] [blame] | 3662 | if (DEBUG_CLEANUP) Slog.v(TAG_CLEANUP, |
| 3663 | "Removing app " + app + " from list " + listName + " with " + i + " entries"); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 3664 | while (i > 0) { |
| 3665 | i--; |
Craig Mautner | 05d6272ba | 2013-02-11 09:39:27 -0800 | [diff] [blame] | 3666 | ActivityRecord r = list.get(i); |
Wale Ogunwale | e23149f | 2015-03-06 15:39:44 -0800 | [diff] [blame] | 3667 | if (DEBUG_CLEANUP) Slog.v(TAG_CLEANUP, "Record #" + i + " " + r); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 3668 | if (r.app == app) { |
Wale Ogunwale | e23149f | 2015-03-06 15:39:44 -0800 | [diff] [blame] | 3669 | if (DEBUG_CLEANUP) Slog.v(TAG_CLEANUP, "---> REMOVING this entry!"); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 3670 | list.remove(i); |
Dianne Hackborn | 42e620c | 2012-06-24 13:20:51 -0700 | [diff] [blame] | 3671 | removeTimeoutsForActivityLocked(r); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 3672 | } |
| 3673 | } |
| 3674 | } |
| 3675 | |
Dianne Hackborn | cc5a055 | 2012-10-01 16:32:39 -0700 | [diff] [blame] | 3676 | boolean removeHistoryRecordsForAppLocked(ProcessRecord app) { |
| 3677 | removeHistoryRecordsForAppLocked(mLRUActivities, app, "mLRUActivities"); |
Craig Mautner | de4ef02 | 2013-04-07 19:01:33 -0700 | [diff] [blame] | 3678 | removeHistoryRecordsForAppLocked(mStackSupervisor.mStoppingActivities, app, |
| 3679 | "mStoppingActivities"); |
Craig Mautner | 0eea92c | 2013-05-16 13:35:39 -0700 | [diff] [blame] | 3680 | removeHistoryRecordsForAppLocked(mStackSupervisor.mGoingToSleepActivities, app, |
| 3681 | "mGoingToSleepActivities"); |
Craig Mautner | de4ef02 | 2013-04-07 19:01:33 -0700 | [diff] [blame] | 3682 | removeHistoryRecordsForAppLocked(mStackSupervisor.mWaitingVisibleActivities, app, |
Dianne Hackborn | cc5a055 | 2012-10-01 16:32:39 -0700 | [diff] [blame] | 3683 | "mWaitingVisibleActivities"); |
Craig Mautner | f333327 | 2013-04-22 10:55:53 -0700 | [diff] [blame] | 3684 | removeHistoryRecordsForAppLocked(mStackSupervisor.mFinishingActivities, app, |
| 3685 | "mFinishingActivities"); |
Dianne Hackborn | cc5a055 | 2012-10-01 16:32:39 -0700 | [diff] [blame] | 3686 | |
| 3687 | boolean hasVisibleActivities = false; |
| 3688 | |
| 3689 | // Clean out the history list. |
Craig Mautner | 0247fc8 | 2013-02-28 14:32:06 -0800 | [diff] [blame] | 3690 | int i = numActivities(); |
Wale Ogunwale | e23149f | 2015-03-06 15:39:44 -0800 | [diff] [blame] | 3691 | if (DEBUG_CLEANUP) Slog.v(TAG_CLEANUP, |
| 3692 | "Removing app " + app + " from history with " + i + " entries"); |
Craig Mautner | 0247fc8 | 2013-02-28 14:32:06 -0800 | [diff] [blame] | 3693 | for (int taskNdx = mTaskHistory.size() - 1; taskNdx >= 0; --taskNdx) { |
| 3694 | final ArrayList<ActivityRecord> activities = mTaskHistory.get(taskNdx).mActivities; |
| 3695 | for (int activityNdx = activities.size() - 1; activityNdx >= 0; --activityNdx) { |
| 3696 | final ActivityRecord r = activities.get(activityNdx); |
| 3697 | --i; |
Wale Ogunwale | e23149f | 2015-03-06 15:39:44 -0800 | [diff] [blame] | 3698 | if (DEBUG_CLEANUP) Slog.v(TAG_CLEANUP, |
| 3699 | "Record #" + i + " " + r + ": app=" + r.app); |
Craig Mautner | 0247fc8 | 2013-02-28 14:32:06 -0800 | [diff] [blame] | 3700 | if (r.app == app) { |
riddle_hsu | 558e849 | 2015-04-02 16:43:13 +0800 | [diff] [blame] | 3701 | if (r.visible) { |
| 3702 | hasVisibleActivities = true; |
| 3703 | } |
Craig Mautner | acebdc8 | 2015-02-24 10:53:03 -0800 | [diff] [blame] | 3704 | final boolean remove; |
Craig Mautner | 0247fc8 | 2013-02-28 14:32:06 -0800 | [diff] [blame] | 3705 | if ((!r.haveState && !r.stateNotNeeded) || r.finishing) { |
| 3706 | // Don't currently have state for the activity, or |
| 3707 | // it is finishing -- always remove it. |
| 3708 | remove = true; |
| 3709 | } else if (r.launchCount > 2 && |
| 3710 | r.lastLaunchTime > (SystemClock.uptimeMillis()-60000)) { |
| 3711 | // We have launched this activity too many times since it was |
| 3712 | // able to run, so give up and remove it. |
| 3713 | remove = true; |
| 3714 | } else { |
| 3715 | // The process may be gone, but the activity lives on! |
| 3716 | remove = false; |
Dianne Hackborn | cc5a055 | 2012-10-01 16:32:39 -0700 | [diff] [blame] | 3717 | } |
Craig Mautner | 0247fc8 | 2013-02-28 14:32:06 -0800 | [diff] [blame] | 3718 | if (remove) { |
Wale Ogunwale | 0fc365c | 2015-05-25 19:35:42 -0700 | [diff] [blame] | 3719 | if (DEBUG_ADD_REMOVE || DEBUG_CLEANUP) Slog.i(TAG_ADD_REMOVE, |
| 3720 | "Removing activity " + r + " from stack at " + i |
| 3721 | + ": haveState=" + r.haveState |
| 3722 | + " stateNotNeeded=" + r.stateNotNeeded |
| 3723 | + " finishing=" + r.finishing |
| 3724 | + " state=" + r.state + " callers=" + Debug.getCallers(5)); |
Craig Mautner | 0247fc8 | 2013-02-28 14:32:06 -0800 | [diff] [blame] | 3725 | if (!r.finishing) { |
| 3726 | Slog.w(TAG, "Force removing " + r + ": app died, no saved state"); |
| 3727 | EventLog.writeEvent(EventLogTags.AM_FINISH_ACTIVITY, |
| 3728 | r.userId, System.identityHashCode(r), |
| 3729 | r.task.taskId, r.shortComponentName, |
| 3730 | "proc died without state saved"); |
Jeff Sharkey | 5782da7 | 2013-04-25 14:32:30 -0700 | [diff] [blame] | 3731 | if (r.state == ActivityState.RESUMED) { |
| 3732 | mService.updateUsageStats(r, false); |
| 3733 | } |
Craig Mautner | 0247fc8 | 2013-02-28 14:32:06 -0800 | [diff] [blame] | 3734 | } |
Craig Mautner | 0247fc8 | 2013-02-28 14:32:06 -0800 | [diff] [blame] | 3735 | } else { |
| 3736 | // We have the current state for this activity, so |
| 3737 | // it can be restarted later when needed. |
Wale Ogunwale | 0fc365c | 2015-05-25 19:35:42 -0700 | [diff] [blame] | 3738 | if (DEBUG_ALL) Slog.v(TAG, "Keeping entry, setting app to null"); |
| 3739 | if (DEBUG_APP) Slog.v(TAG_APP, |
| 3740 | "Clearing app during removeHistory for activity " + r); |
Craig Mautner | 0247fc8 | 2013-02-28 14:32:06 -0800 | [diff] [blame] | 3741 | r.app = null; |
| 3742 | r.nowVisible = false; |
| 3743 | if (!r.haveState) { |
Wale Ogunwale | 0fc365c | 2015-05-25 19:35:42 -0700 | [diff] [blame] | 3744 | if (DEBUG_SAVED_STATE) Slog.i(TAG_SAVED_STATE, |
Craig Mautner | 0247fc8 | 2013-02-28 14:32:06 -0800 | [diff] [blame] | 3745 | "App died, clearing saved state of " + r); |
| 3746 | r.icicle = null; |
| 3747 | } |
Dianne Hackborn | cc5a055 | 2012-10-01 16:32:39 -0700 | [diff] [blame] | 3748 | } |
Craig Mautner | d232895 | 2013-03-05 12:46:26 -0800 | [diff] [blame] | 3749 | cleanUpActivityLocked(r, true, true); |
Craig Mautner | acebdc8 | 2015-02-24 10:53:03 -0800 | [diff] [blame] | 3750 | if (remove) { |
| 3751 | removeActivityFromHistoryLocked(r, "appDied"); |
| 3752 | } |
Craig Mautner | 0247fc8 | 2013-02-28 14:32:06 -0800 | [diff] [blame] | 3753 | } |
Dianne Hackborn | cc5a055 | 2012-10-01 16:32:39 -0700 | [diff] [blame] | 3754 | } |
| 3755 | } |
| 3756 | |
| 3757 | return hasVisibleActivities; |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 3758 | } |
Craig Mautner | 0247fc8 | 2013-02-28 14:32:06 -0800 | [diff] [blame] | 3759 | |
Dianne Hackborn | 7f58b95 | 2012-04-18 12:59:29 -0700 | [diff] [blame] | 3760 | final void updateTransitLocked(int transit, Bundle options) { |
| 3761 | if (options != null) { |
| 3762 | ActivityRecord r = topRunningActivityLocked(null); |
| 3763 | if (r != null && r.state != ActivityState.RESUMED) { |
| 3764 | r.updateOptionsLocked(options); |
| 3765 | } else { |
| 3766 | ActivityOptions.abort(options); |
| 3767 | } |
| 3768 | } |
Craig Mautner | ce5f3cb | 2013-04-22 08:58:54 -0700 | [diff] [blame] | 3769 | mWindowManager.prepareAppTransition(transit, false); |
Dianne Hackborn | 7f58b95 | 2012-04-18 12:59:29 -0700 | [diff] [blame] | 3770 | } |
Dianne Hackborn | 621e17d | 2010-11-22 15:59:56 -0800 | [diff] [blame] | 3771 | |
Craig Mautner | 21d24a2 | 2014-04-23 11:45:37 -0700 | [diff] [blame] | 3772 | void updateTaskMovement(TaskRecord task, boolean toFront) { |
| 3773 | if (task.isPersistable) { |
| 3774 | task.mLastTimeMoved = System.currentTimeMillis(); |
| 3775 | // Sign is used to keep tasks sorted when persisted. Tasks sent to the bottom most |
| 3776 | // recently will be most negative, tasks sent to the bottom before that will be less |
| 3777 | // negative. Similarly for recent tasks moved to the top which will be most positive. |
| 3778 | if (!toFront) { |
| 3779 | task.mLastTimeMoved *= -1; |
| 3780 | } |
| 3781 | } |
| 3782 | } |
| 3783 | |
Craig Mautner | 84984fa | 2014-06-19 11:19:20 -0700 | [diff] [blame] | 3784 | void moveHomeStackTaskToTop(int homeStackTaskType) { |
Craig Mautner | a82aa09 | 2013-09-13 15:34:08 -0700 | [diff] [blame] | 3785 | final int top = mTaskHistory.size() - 1; |
| 3786 | for (int taskNdx = top; taskNdx >= 0; --taskNdx) { |
| 3787 | final TaskRecord task = mTaskHistory.get(taskNdx); |
Craig Mautner | 84984fa | 2014-06-19 11:19:20 -0700 | [diff] [blame] | 3788 | if (task.taskType == homeStackTaskType) { |
Wale Ogunwale | ee006da | 2015-03-30 14:49:25 -0700 | [diff] [blame] | 3789 | if (DEBUG_TASKS || DEBUG_STACK) Slog.d(TAG_STACK, |
| 3790 | "moveHomeStackTaskToTop: moving " + task); |
Craig Mautner | a82aa09 | 2013-09-13 15:34:08 -0700 | [diff] [blame] | 3791 | mTaskHistory.remove(taskNdx); |
| 3792 | mTaskHistory.add(top, task); |
Craig Mautner | 21d24a2 | 2014-04-23 11:45:37 -0700 | [diff] [blame] | 3793 | updateTaskMovement(task, true); |
Craig Mautner | a82aa09 | 2013-09-13 15:34:08 -0700 | [diff] [blame] | 3794 | return; |
| 3795 | } |
| 3796 | } |
| 3797 | } |
| 3798 | |
Craig Mautner | 8f5f7e9 | 2015-01-26 18:03:13 -0800 | [diff] [blame] | 3799 | final void moveTaskToFrontLocked(TaskRecord tr, boolean noAnimation, Bundle options, |
Dianne Hackborn | b5a380d | 2015-05-20 18:18:46 -0700 | [diff] [blame] | 3800 | AppTimeTracker timeTracker, String reason) { |
Wale Ogunwale | ee006da | 2015-03-30 14:49:25 -0700 | [diff] [blame] | 3801 | if (DEBUG_SWITCH) Slog.v(TAG_SWITCH, "moveTaskToFront: " + tr); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 3802 | |
Craig Mautner | 11bf9a5 | 2013-02-19 14:08:51 -0800 | [diff] [blame] | 3803 | final int numTasks = mTaskHistory.size(); |
| 3804 | final int index = mTaskHistory.indexOf(tr); |
Craig Mautner | 86d67a4 | 2013-05-14 10:34:38 -0700 | [diff] [blame] | 3805 | if (numTasks == 0 || index < 0) { |
Craig Mautner | 11bf9a5 | 2013-02-19 14:08:51 -0800 | [diff] [blame] | 3806 | // nothing to do! |
Craig Mautner | 8f5f7e9 | 2015-01-26 18:03:13 -0800 | [diff] [blame] | 3807 | if (noAnimation) { |
Craig Mautner | 11bf9a5 | 2013-02-19 14:08:51 -0800 | [diff] [blame] | 3808 | ActivityOptions.abort(options); |
| 3809 | } else { |
| 3810 | updateTransitLocked(AppTransition.TRANSIT_TASK_TO_FRONT, options); |
| 3811 | } |
| 3812 | return; |
| 3813 | } |
| 3814 | |
Dianne Hackborn | b5a380d | 2015-05-20 18:18:46 -0700 | [diff] [blame] | 3815 | if (timeTracker != null) { |
| 3816 | // The caller wants a time tracker associated with this task. |
| 3817 | for (int i = tr.mActivities.size() - 1; i >= 0; i--) { |
| 3818 | tr.mActivities.get(i).appTimeTracker = timeTracker; |
| 3819 | } |
| 3820 | } |
| 3821 | |
Craig Mautner | 11bf9a5 | 2013-02-19 14:08:51 -0800 | [diff] [blame] | 3822 | // Shift all activities with this task up to the top |
| 3823 | // of the stack, keeping them in the same internal order. |
Wale Ogunwale | 3fcb4a8 | 2015-04-06 14:00:13 -0700 | [diff] [blame] | 3824 | insertTaskAtTop(tr, null); |
Wale Ogunwale | d80c263 | 2015-03-13 10:26:26 -0700 | [diff] [blame] | 3825 | |
Chong Zhang | 45c25ce | 2015-08-10 22:18:26 -0700 | [diff] [blame] | 3826 | // Don't refocus if invisible to current user |
| 3827 | ActivityRecord top = tr.getTopActivity(); |
| 3828 | if (!okToShowLocked(top)) { |
| 3829 | addRecentActivityLocked(top); |
| 3830 | ActivityOptions.abort(options); |
| 3831 | return; |
| 3832 | } |
| 3833 | |
Wale Ogunwale | d80c263 | 2015-03-13 10:26:26 -0700 | [diff] [blame] | 3834 | // Set focus to the top running activity of this stack. |
| 3835 | ActivityRecord r = topRunningActivityLocked(null); |
| 3836 | mService.setFocusedActivityLocked(r, reason); |
Craig Mautner | 11bf9a5 | 2013-02-19 14:08:51 -0800 | [diff] [blame] | 3837 | |
Wale Ogunwale | ee006da | 2015-03-30 14:49:25 -0700 | [diff] [blame] | 3838 | if (DEBUG_TRANSITION) Slog.v(TAG_TRANSITION, "Prepare to front transition: task=" + tr); |
Craig Mautner | 8f5f7e9 | 2015-01-26 18:03:13 -0800 | [diff] [blame] | 3839 | if (noAnimation) { |
Craig Mautner | ce5f3cb | 2013-04-22 08:58:54 -0700 | [diff] [blame] | 3840 | mWindowManager.prepareAppTransition(AppTransition.TRANSIT_NONE, false); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 3841 | if (r != null) { |
| 3842 | mNoAnimActivities.add(r); |
| 3843 | } |
Dianne Hackborn | 8078d8c | 2012-03-20 11:11:26 -0700 | [diff] [blame] | 3844 | ActivityOptions.abort(options); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 3845 | } else { |
Craig Mautner | 4b71aa1 | 2012-12-27 17:20:01 -0800 | [diff] [blame] | 3846 | updateTransitLocked(AppTransition.TRANSIT_TASK_TO_FRONT, options); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 3847 | } |
Craig Mautner | 30e2d72 | 2013-02-12 11:30:16 -0800 | [diff] [blame] | 3848 | |
Craig Mautner | 05d2903 | 2013-05-03 13:40:13 -0700 | [diff] [blame] | 3849 | mStackSupervisor.resumeTopActivitiesLocked(); |
Craig Mautner | 5854780 | 2013-03-05 08:23:53 -0800 | [diff] [blame] | 3850 | EventLog.writeEvent(EventLogTags.AM_TASK_TO_FRONT, tr.userId, tr.taskId); |
Craig Mautner | 11bf9a5 | 2013-02-19 14:08:51 -0800 | [diff] [blame] | 3851 | |
| 3852 | if (VALIDATE_TOKENS) { |
| 3853 | validateAppTokensLocked(); |
| 3854 | } |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 3855 | } |
| 3856 | |
| 3857 | /** |
Craig Mautner | ce5f3cb | 2013-04-22 08:58:54 -0700 | [diff] [blame] | 3858 | * Worker method for rearranging history stack. Implements the function of moving all |
| 3859 | * 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] | 3860 | * bottom of the stack. |
Craig Mautner | ce5f3cb | 2013-04-22 08:58:54 -0700 | [diff] [blame] | 3861 | * |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 3862 | * If a watcher is installed, the action is preflighted and the watcher has an opportunity |
| 3863 | * to premeptively cancel the move. |
Craig Mautner | ce5f3cb | 2013-04-22 08:58:54 -0700 | [diff] [blame] | 3864 | * |
Craig Mautner | ae7ecab | 2013-09-18 11:48:14 -0700 | [diff] [blame] | 3865 | * @param taskId The taskId to collect and move to the bottom. |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 3866 | * @return Returns true if the move completed, false if not. |
| 3867 | */ |
Craig Mautner | 299f960 | 2015-01-26 09:47:33 -0800 | [diff] [blame] | 3868 | final boolean moveTaskToBackLocked(int taskId) { |
Craig Mautner | aea74a5 | 2014-03-08 14:23:10 -0800 | [diff] [blame] | 3869 | final TaskRecord tr = taskForIdLocked(taskId); |
| 3870 | if (tr == null) { |
| 3871 | Slog.i(TAG, "moveTaskToBack: bad taskId=" + taskId); |
| 3872 | return false; |
| 3873 | } |
| 3874 | |
| 3875 | Slog.i(TAG, "moveTaskToBack: " + tr); |
Craig Mautner | 15df08a | 2015-04-01 12:17:18 -0700 | [diff] [blame] | 3876 | mStackSupervisor.removeLockedTaskLocked(tr); |
Craig Mautner | b44de0d | 2013-02-21 20:00:58 -0800 | [diff] [blame] | 3877 | |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 3878 | // If we have a watcher, preflight the move before committing to it. First check |
| 3879 | // for *other* available tasks, but if none are available, then try again allowing the |
| 3880 | // current task to be selected. |
Craig Mautner | de4ef02 | 2013-04-07 19:01:33 -0700 | [diff] [blame] | 3881 | if (mStackSupervisor.isFrontStack(this) && mService.mController != null) { |
Craig Mautner | ae7ecab | 2013-09-18 11:48:14 -0700 | [diff] [blame] | 3882 | ActivityRecord next = topRunningActivityLocked(null, taskId); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 3883 | if (next == null) { |
| 3884 | next = topRunningActivityLocked(null, 0); |
| 3885 | } |
| 3886 | if (next != null) { |
| 3887 | // ask watcher if this is allowed |
| 3888 | boolean moveOK = true; |
| 3889 | try { |
| 3890 | moveOK = mService.mController.activityResuming(next.packageName); |
| 3891 | } catch (RemoteException e) { |
| 3892 | mService.mController = null; |
Kenny Root | add5821 | 2013-05-07 09:47:34 -0700 | [diff] [blame] | 3893 | Watchdog.getInstance().setActivityController(null); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 3894 | } |
| 3895 | if (!moveOK) { |
| 3896 | return false; |
| 3897 | } |
| 3898 | } |
| 3899 | } |
| 3900 | |
Wale Ogunwale | ee006da | 2015-03-30 14:49:25 -0700 | [diff] [blame] | 3901 | if (DEBUG_TRANSITION) Slog.v(TAG_TRANSITION, "Prepare to back transition: task=" + taskId); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 3902 | |
riddle_hsu | c215a4f | 2014-12-27 12:10:45 +0800 | [diff] [blame] | 3903 | boolean prevIsHome = false; |
Wale Ogunwale | 4270924 | 2015-08-11 13:54:42 -0700 | [diff] [blame] | 3904 | |
| 3905 | // If true, we should resume the home activity next if the task we are moving to the |
| 3906 | // back is over the home stack. We force to false if the task we are moving to back |
| 3907 | // is the home task and we don't want it resumed after moving to the back. |
| 3908 | final boolean canGoHome = !tr.isHomeTask() && tr.isOverHomeStack(); |
| 3909 | if (canGoHome) { |
riddle_hsu | c215a4f | 2014-12-27 12:10:45 +0800 | [diff] [blame] | 3910 | final TaskRecord nextTask = getNextTask(tr); |
| 3911 | if (nextTask != null) { |
| 3912 | nextTask.setTaskToReturnTo(tr.getTaskToReturnTo()); |
| 3913 | } else { |
| 3914 | prevIsHome = true; |
| 3915 | } |
| 3916 | } |
Craig Mautner | 11bf9a5 | 2013-02-19 14:08:51 -0800 | [diff] [blame] | 3917 | mTaskHistory.remove(tr); |
| 3918 | mTaskHistory.add(0, tr); |
Craig Mautner | 21d24a2 | 2014-04-23 11:45:37 -0700 | [diff] [blame] | 3919 | updateTaskMovement(tr, false); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 3920 | |
Craig Mautner | c8143c6 | 2013-09-03 12:15:57 -0700 | [diff] [blame] | 3921 | // There is an assumption that moving a task to the back moves it behind the home activity. |
| 3922 | // 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] | 3923 | int numTasks = mTaskHistory.size(); |
Craig Mautner | ae7ecab | 2013-09-18 11:48:14 -0700 | [diff] [blame] | 3924 | for (int taskNdx = numTasks - 1; taskNdx >= 1; --taskNdx) { |
| 3925 | final TaskRecord task = mTaskHistory.get(taskNdx); |
Craig Mautner | 84984fa | 2014-06-19 11:19:20 -0700 | [diff] [blame] | 3926 | if (task.isOverHomeStack()) { |
Craig Mautner | c8143c6 | 2013-09-03 12:15:57 -0700 | [diff] [blame] | 3927 | break; |
| 3928 | } |
Craig Mautner | ae7ecab | 2013-09-18 11:48:14 -0700 | [diff] [blame] | 3929 | if (taskNdx == 1) { |
| 3930 | // Set the last task before tr to go to home. |
Craig Mautner | 84984fa | 2014-06-19 11:19:20 -0700 | [diff] [blame] | 3931 | task.setTaskToReturnTo(HOME_ACTIVITY_TYPE); |
Craig Mautner | ae7ecab | 2013-09-18 11:48:14 -0700 | [diff] [blame] | 3932 | } |
Craig Mautner | c8143c6 | 2013-09-03 12:15:57 -0700 | [diff] [blame] | 3933 | } |
| 3934 | |
Craig Mautner | 299f960 | 2015-01-26 09:47:33 -0800 | [diff] [blame] | 3935 | mWindowManager.prepareAppTransition(AppTransition.TRANSIT_TASK_TO_BACK, false); |
Craig Mautner | ae7ecab | 2013-09-18 11:48:14 -0700 | [diff] [blame] | 3936 | mWindowManager.moveTaskToBottom(taskId); |
Craig Mautner | b44de0d | 2013-02-21 20:00:58 -0800 | [diff] [blame] | 3937 | |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 3938 | if (VALIDATE_TOKENS) { |
Dianne Hackborn | be70785 | 2011-11-11 14:32:10 -0800 | [diff] [blame] | 3939 | validateAppTokensLocked(); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 3940 | } |
| 3941 | |
Craig Mautner | ae7ecab | 2013-09-18 11:48:14 -0700 | [diff] [blame] | 3942 | final TaskRecord task = mResumedActivity != null ? mResumedActivity.task : null; |
Wale Ogunwale | 4270924 | 2015-08-11 13:54:42 -0700 | [diff] [blame] | 3943 | if (prevIsHome || (task == tr && canGoHome) || (numTasks <= 1 && isOnHomeDisplay())) { |
Dianne Hackborn | 7622a0f | 2014-09-30 14:31:42 -0700 | [diff] [blame] | 3944 | if (!mService.mBooting && !mService.mBooted) { |
| 3945 | // Not ready yet! |
| 3946 | return false; |
| 3947 | } |
Craig Mautner | 84984fa | 2014-06-19 11:19:20 -0700 | [diff] [blame] | 3948 | final int taskToReturnTo = tr.getTaskToReturnTo(); |
| 3949 | tr.setTaskToReturnTo(APPLICATION_ACTIVITY_TYPE); |
Craig Mautner | 299f960 | 2015-01-26 09:47:33 -0800 | [diff] [blame] | 3950 | return mStackSupervisor.resumeHomeStackTask(taskToReturnTo, null, "moveTaskToBack"); |
Craig Mautner | de4ef02 | 2013-04-07 19:01:33 -0700 | [diff] [blame] | 3951 | } |
| 3952 | |
Craig Mautner | 05d2903 | 2013-05-03 13:40:13 -0700 | [diff] [blame] | 3953 | mStackSupervisor.resumeTopActivitiesLocked(); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 3954 | return true; |
| 3955 | } |
Dianne Hackborn | 15491c6 | 2012-09-19 10:59:14 -0700 | [diff] [blame] | 3956 | |
Craig Mautner | 8849a5e | 2013-04-02 16:41:03 -0700 | [diff] [blame] | 3957 | static final void logStartActivity(int tag, ActivityRecord r, |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 3958 | TaskRecord task) { |
Santos Cordon | 73ff7d8 | 2013-03-06 17:24:11 -0800 | [diff] [blame] | 3959 | final Uri data = r.intent.getData(); |
| 3960 | final String strData = data != null ? data.toSafeString() : null; |
| 3961 | |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 3962 | EventLog.writeEvent(tag, |
Dianne Hackborn | b12e135 | 2012-09-26 11:39:20 -0700 | [diff] [blame] | 3963 | r.userId, System.identityHashCode(r), task.taskId, |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 3964 | r.shortComponentName, r.intent.getAction(), |
Santos Cordon | 73ff7d8 | 2013-03-06 17:24:11 -0800 | [diff] [blame] | 3965 | r.intent.getType(), strData, r.intent.getFlags()); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 3966 | } |
| 3967 | |
| 3968 | /** |
| 3969 | * Make sure the given activity matches the current configuration. Returns |
| 3970 | * false if the activity had to be destroyed. Returns true if the |
| 3971 | * configuration is the same, or the activity will remain running as-is |
| 3972 | * for whatever reason. Ensures the HistoryRecord is updated with the |
| 3973 | * correct configuration and all other bookkeeping is handled. |
| 3974 | */ |
Filip Gruszczynski | a59ac9c | 2015-09-10 18:28:48 -0700 | [diff] [blame] | 3975 | final boolean ensureActivityConfigurationLocked(ActivityRecord r, int globalChanges, |
| 3976 | boolean preserveWindow) { |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 3977 | if (mConfigWillChange) { |
Wale Ogunwale | 3ab9a27 | 2015-03-16 09:55:45 -0700 | [diff] [blame] | 3978 | if (DEBUG_SWITCH || DEBUG_CONFIGURATION) Slog.v(TAG_CONFIGURATION, |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 3979 | "Skipping config check (will change): " + r); |
| 3980 | return true; |
| 3981 | } |
Craig Mautner | ce5f3cb | 2013-04-22 08:58:54 -0700 | [diff] [blame] | 3982 | |
Wale Ogunwale | 3ab9a27 | 2015-03-16 09:55:45 -0700 | [diff] [blame] | 3983 | if (DEBUG_SWITCH || DEBUG_CONFIGURATION) Slog.v(TAG_CONFIGURATION, |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 3984 | "Ensuring correct configuration: " + r); |
Craig Mautner | 9db9a0b | 2013-04-29 17:05:56 -0700 | [diff] [blame] | 3985 | |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 3986 | // Short circuit: if the two configurations are the exact same |
| 3987 | // object (the common case), then there is nothing to do. |
Wale Ogunwale | e4a0c57 | 2015-06-30 08:40:31 -0700 | [diff] [blame] | 3988 | final Configuration newConfig = mService.mConfiguration; |
| 3989 | final Configuration taskConfig = r.task.mOverrideConfig; |
Wale Ogunwale | 60454db | 2015-01-23 16:05:07 -0800 | [diff] [blame] | 3990 | if (r.configuration == newConfig |
Wale Ogunwale | e4a0c57 | 2015-06-30 08:40:31 -0700 | [diff] [blame] | 3991 | && r.taskConfigOverride == taskConfig |
Wale Ogunwale | 60454db | 2015-01-23 16:05:07 -0800 | [diff] [blame] | 3992 | && !r.forceNewConfig) { |
Wale Ogunwale | 3ab9a27 | 2015-03-16 09:55:45 -0700 | [diff] [blame] | 3993 | if (DEBUG_SWITCH || DEBUG_CONFIGURATION) Slog.v(TAG_CONFIGURATION, |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 3994 | "Configuration unchanged in " + r); |
| 3995 | return true; |
| 3996 | } |
Craig Mautner | ce5f3cb | 2013-04-22 08:58:54 -0700 | [diff] [blame] | 3997 | |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 3998 | // We don't worry about activities that are finishing. |
| 3999 | if (r.finishing) { |
Wale Ogunwale | 3ab9a27 | 2015-03-16 09:55:45 -0700 | [diff] [blame] | 4000 | if (DEBUG_SWITCH || DEBUG_CONFIGURATION) Slog.v(TAG_CONFIGURATION, |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 4001 | "Configuration doesn't matter in finishing " + r); |
| 4002 | r.stopFreezingScreenLocked(false); |
| 4003 | return true; |
| 4004 | } |
Craig Mautner | ce5f3cb | 2013-04-22 08:58:54 -0700 | [diff] [blame] | 4005 | |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 4006 | // Okay we now are going to make this activity have the new config. |
| 4007 | // 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] | 4008 | final Configuration oldConfig = r.configuration; |
Wale Ogunwale | e4a0c57 | 2015-06-30 08:40:31 -0700 | [diff] [blame] | 4009 | final Configuration oldTaskOverride = r.taskConfigOverride; |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 4010 | r.configuration = newConfig; |
Wale Ogunwale | e4a0c57 | 2015-06-30 08:40:31 -0700 | [diff] [blame] | 4011 | r.taskConfigOverride = taskConfig; |
Dianne Hackborn | 58f42a5 | 2011-10-10 13:46:34 -0700 | [diff] [blame] | 4012 | |
Filip Gruszczynski | 2349332 | 2015-07-29 17:02:59 -0700 | [diff] [blame] | 4013 | int taskChanges = getTaskConfigurationChanges(r, taskConfig, oldTaskOverride); |
Wale Ogunwale | e4a0c57 | 2015-06-30 08:40:31 -0700 | [diff] [blame] | 4014 | final int changes = oldConfig.diff(newConfig) | taskChanges; |
Dianne Hackborn | 58f42a5 | 2011-10-10 13:46:34 -0700 | [diff] [blame] | 4015 | if (changes == 0 && !r.forceNewConfig) { |
Wale Ogunwale | 3ab9a27 | 2015-03-16 09:55:45 -0700 | [diff] [blame] | 4016 | if (DEBUG_SWITCH || DEBUG_CONFIGURATION) Slog.v(TAG_CONFIGURATION, |
Dianne Hackborn | 58f42a5 | 2011-10-10 13:46:34 -0700 | [diff] [blame] | 4017 | "Configuration no differences in " + r); |
| 4018 | return true; |
| 4019 | } |
| 4020 | |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 4021 | // If the activity isn't currently running, just leave the new |
| 4022 | // configuration and it will pick that up next time it starts. |
| 4023 | if (r.app == null || r.app.thread == null) { |
Wale Ogunwale | 3ab9a27 | 2015-03-16 09:55:45 -0700 | [diff] [blame] | 4024 | if (DEBUG_SWITCH || DEBUG_CONFIGURATION) Slog.v(TAG_CONFIGURATION, |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 4025 | "Configuration doesn't matter not running " + r); |
| 4026 | r.stopFreezingScreenLocked(false); |
Dianne Hackborn | e2515ee | 2011-04-27 18:52:56 -0400 | [diff] [blame] | 4027 | r.forceNewConfig = false; |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 4028 | return true; |
| 4029 | } |
Craig Mautner | ce5f3cb | 2013-04-22 08:58:54 -0700 | [diff] [blame] | 4030 | |
Dianne Hackborn | 58f42a5 | 2011-10-10 13:46:34 -0700 | [diff] [blame] | 4031 | // Figure out how to handle the changes between the configurations. |
Wale Ogunwale | 3ab9a27 | 2015-03-16 09:55:45 -0700 | [diff] [blame] | 4032 | if (DEBUG_SWITCH || DEBUG_CONFIGURATION) Slog.v(TAG_CONFIGURATION, |
| 4033 | "Checking to restart " + r.info.name + ": changed=0x" |
| 4034 | + Integer.toHexString(changes) + ", handles=0x" |
| 4035 | + Integer.toHexString(r.info.getRealConfigChanged()) + ", newConfig=" + newConfig); |
| 4036 | |
Dianne Hackborn | e667635 | 2011-06-01 16:51:20 -0700 | [diff] [blame] | 4037 | if ((changes&(~r.info.getRealConfigChanged())) != 0 || r.forceNewConfig) { |
Dianne Hackborn | 3c4c2b7 | 2010-10-05 18:07:54 -0700 | [diff] [blame] | 4038 | // Aha, the activity isn't handling the change, so DIE DIE DIE. |
| 4039 | r.configChangeFlags |= changes; |
| 4040 | r.startFreezingScreenLocked(r.app, globalChanges); |
Dianne Hackborn | e2515ee | 2011-04-27 18:52:56 -0400 | [diff] [blame] | 4041 | r.forceNewConfig = false; |
Dianne Hackborn | 3c4c2b7 | 2010-10-05 18:07:54 -0700 | [diff] [blame] | 4042 | if (r.app == null || r.app.thread == null) { |
Wale Ogunwale | 3ab9a27 | 2015-03-16 09:55:45 -0700 | [diff] [blame] | 4043 | if (DEBUG_SWITCH || DEBUG_CONFIGURATION) Slog.v(TAG_CONFIGURATION, |
Dianne Hackborn | b61a026 | 2012-05-14 17:19:18 -0700 | [diff] [blame] | 4044 | "Config is destroying non-running " + r); |
Craig Mautner | ee2e45a | 2014-06-27 12:10:03 -0700 | [diff] [blame] | 4045 | destroyActivityLocked(r, true, "config"); |
Dianne Hackborn | 3c4c2b7 | 2010-10-05 18:07:54 -0700 | [diff] [blame] | 4046 | } else if (r.state == ActivityState.PAUSING) { |
| 4047 | // A little annoying: we are waiting for this activity to |
| 4048 | // finish pausing. Let's not do anything now, but just |
| 4049 | // flag that it needs to be restarted when done pausing. |
Wale Ogunwale | 3ab9a27 | 2015-03-16 09:55:45 -0700 | [diff] [blame] | 4050 | if (DEBUG_SWITCH || DEBUG_CONFIGURATION) Slog.v(TAG_CONFIGURATION, |
Dianne Hackborn | b61a026 | 2012-05-14 17:19:18 -0700 | [diff] [blame] | 4051 | "Config is skipping already pausing " + r); |
Dianne Hackborn | 3c4c2b7 | 2010-10-05 18:07:54 -0700 | [diff] [blame] | 4052 | r.configDestroy = true; |
| 4053 | return true; |
| 4054 | } else if (r.state == ActivityState.RESUMED) { |
| 4055 | // Try to optimize this case: the configuration is changing |
| 4056 | // and we need to restart the top, resumed activity. |
| 4057 | // Instead of doing the normal handshaking, just say |
| 4058 | // "restart!". |
Wale Ogunwale | 3ab9a27 | 2015-03-16 09:55:45 -0700 | [diff] [blame] | 4059 | if (DEBUG_SWITCH || DEBUG_CONFIGURATION) Slog.v(TAG_CONFIGURATION, |
Dianne Hackborn | b61a026 | 2012-05-14 17:19:18 -0700 | [diff] [blame] | 4060 | "Config is relaunching resumed " + r); |
Filip Gruszczynski | a59ac9c | 2015-09-10 18:28:48 -0700 | [diff] [blame] | 4061 | relaunchActivityLocked(r, r.configChangeFlags, true, |
| 4062 | preserveWindow && isResizeOnlyChange(changes)); |
Dianne Hackborn | 3c4c2b7 | 2010-10-05 18:07:54 -0700 | [diff] [blame] | 4063 | r.configChangeFlags = 0; |
| 4064 | } else { |
Wale Ogunwale | 3ab9a27 | 2015-03-16 09:55:45 -0700 | [diff] [blame] | 4065 | if (DEBUG_SWITCH || DEBUG_CONFIGURATION) Slog.v(TAG_CONFIGURATION, |
Dianne Hackborn | b61a026 | 2012-05-14 17:19:18 -0700 | [diff] [blame] | 4066 | "Config is relaunching non-resumed " + r); |
Filip Gruszczynski | a59ac9c | 2015-09-10 18:28:48 -0700 | [diff] [blame] | 4067 | relaunchActivityLocked(r, r.configChangeFlags, false, |
| 4068 | preserveWindow && isResizeOnlyChange(changes)); |
Dianne Hackborn | 3c4c2b7 | 2010-10-05 18:07:54 -0700 | [diff] [blame] | 4069 | r.configChangeFlags = 0; |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 4070 | } |
Craig Mautner | ce5f3cb | 2013-04-22 08:58:54 -0700 | [diff] [blame] | 4071 | |
Dianne Hackborn | 3c4c2b7 | 2010-10-05 18:07:54 -0700 | [diff] [blame] | 4072 | // All done... tell the caller we weren't able to keep this |
| 4073 | // activity around. |
| 4074 | return false; |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 4075 | } |
Craig Mautner | ce5f3cb | 2013-04-22 08:58:54 -0700 | [diff] [blame] | 4076 | |
Wale Ogunwale | c2607b4 | 2015-02-07 16:16:59 -0800 | [diff] [blame] | 4077 | // Default case: the activity can handle this new configuration, so hand it over. |
Wale Ogunwale | e4a0c57 | 2015-06-30 08:40:31 -0700 | [diff] [blame] | 4078 | // NOTE: We only forward the task override configuration as the system level configuration |
Wale Ogunwale | c2607b4 | 2015-02-07 16:16:59 -0800 | [diff] [blame] | 4079 | // changes is always sent to all processes when they happen so it can just use whatever |
| 4080 | // system level configuration it last got. |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 4081 | if (r.app != null && r.app.thread != null) { |
| 4082 | try { |
Wale Ogunwale | 3ab9a27 | 2015-03-16 09:55:45 -0700 | [diff] [blame] | 4083 | if (DEBUG_CONFIGURATION) Slog.v(TAG_CONFIGURATION, "Sending new config to " + r); |
Wale Ogunwale | c2607b4 | 2015-02-07 16:16:59 -0800 | [diff] [blame] | 4084 | r.app.thread.scheduleActivityConfigurationChanged( |
Wale Ogunwale | e4a0c57 | 2015-06-30 08:40:31 -0700 | [diff] [blame] | 4085 | r.appToken, new Configuration(taskConfig)); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 4086 | } catch (RemoteException e) { |
| 4087 | // If process died, whatever. |
| 4088 | } |
| 4089 | } |
| 4090 | r.stopFreezingScreenLocked(false); |
Craig Mautner | ce5f3cb | 2013-04-22 08:58:54 -0700 | [diff] [blame] | 4091 | |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 4092 | return true; |
| 4093 | } |
| 4094 | |
Filip Gruszczynski | 2349332 | 2015-07-29 17:02:59 -0700 | [diff] [blame] | 4095 | private int getTaskConfigurationChanges(ActivityRecord record, Configuration taskConfig, |
| 4096 | Configuration oldTaskOverride) { |
| 4097 | // Determine what has changed. May be nothing, if this is a config |
| 4098 | // that has come back from the app after going idle. In that case |
| 4099 | // we just want to leave the official config object now in the |
| 4100 | // activity and do nothing else. |
| 4101 | int taskChanges = oldTaskOverride.diff(taskConfig); |
| 4102 | // We don't want to use size changes if they don't cross boundaries that are important to |
| 4103 | // the app. |
| 4104 | if ((taskChanges & ActivityInfo.CONFIG_SCREEN_SIZE) != 0) { |
| 4105 | final boolean crosses = record.crossesHorizontalSizeThreshold( |
| 4106 | oldTaskOverride.screenWidthDp, taskConfig.screenWidthDp) |
| 4107 | || record.crossesVerticalSizeThreshold( |
| 4108 | oldTaskOverride.screenHeightDp, taskConfig.screenHeightDp); |
| 4109 | if (!crosses) { |
| 4110 | taskChanges &= ~ActivityInfo.CONFIG_SCREEN_SIZE; |
| 4111 | } |
| 4112 | } |
| 4113 | if ((taskChanges & ActivityInfo.CONFIG_SMALLEST_SCREEN_SIZE) != 0) { |
| 4114 | final int oldSmallest = oldTaskOverride.smallestScreenWidthDp; |
| 4115 | final int newSmallest = taskConfig.smallestScreenWidthDp; |
| 4116 | final boolean crosses = record.crossesHorizontalSizeThreshold(oldSmallest, newSmallest) |
| 4117 | || record.crossesVerticalSizeThreshold(oldSmallest, newSmallest); |
| 4118 | if (!crosses) { |
| 4119 | taskChanges &= ~ActivityInfo.CONFIG_SMALLEST_SCREEN_SIZE; |
| 4120 | } |
| 4121 | } |
| 4122 | return catchConfigChangesFromUnset(taskConfig, oldTaskOverride, taskChanges); |
| 4123 | } |
| 4124 | |
| 4125 | private static int catchConfigChangesFromUnset(Configuration taskConfig, |
| 4126 | Configuration oldTaskOverride, int taskChanges) { |
| 4127 | if (taskChanges == 0) { |
| 4128 | // {@link Configuration#diff} doesn't catch changes from unset values. |
| 4129 | // Check for changes we care about. |
| 4130 | if (oldTaskOverride.orientation != taskConfig.orientation) { |
| 4131 | taskChanges |= ActivityInfo.CONFIG_ORIENTATION; |
| 4132 | } |
| 4133 | // We want to explicitly track situations where the size configuration goes from |
| 4134 | // undefined to defined. We don't care about crossing the threshold in that case, |
| 4135 | // because there is no threshold. |
| 4136 | final int oldHeight = oldTaskOverride.screenHeightDp; |
| 4137 | final int newHeight = taskConfig.screenHeightDp; |
| 4138 | final int undefinedHeight = Configuration.SCREEN_HEIGHT_DP_UNDEFINED; |
| 4139 | if ((oldHeight == undefinedHeight && newHeight != undefinedHeight) |
| 4140 | || (oldHeight != undefinedHeight && newHeight == undefinedHeight)) { |
| 4141 | taskChanges |= ActivityInfo.CONFIG_SCREEN_SIZE; |
| 4142 | } |
| 4143 | final int oldWidth = oldTaskOverride.screenWidthDp; |
| 4144 | final int newWidth = taskConfig.screenWidthDp; |
| 4145 | final int undefinedWidth = Configuration.SCREEN_WIDTH_DP_UNDEFINED; |
| 4146 | if ((oldWidth == undefinedWidth && newWidth != undefinedWidth) |
| 4147 | || (oldWidth != undefinedWidth && newWidth == undefinedWidth)) { |
| 4148 | taskChanges |= ActivityInfo.CONFIG_SCREEN_SIZE; |
| 4149 | } |
| 4150 | final int oldSmallest = oldTaskOverride.smallestScreenWidthDp; |
| 4151 | final int newSmallest = taskConfig.smallestScreenWidthDp; |
| 4152 | final int undefinedSmallest = Configuration.SMALLEST_SCREEN_WIDTH_DP_UNDEFINED; |
| 4153 | if ((oldSmallest == undefinedSmallest && newSmallest != undefinedSmallest) |
| 4154 | || (oldSmallest != undefinedSmallest && newSmallest == undefinedSmallest)) { |
| 4155 | taskChanges |= ActivityInfo.CONFIG_SMALLEST_SCREEN_SIZE; |
| 4156 | } |
| 4157 | } |
| 4158 | return taskChanges; |
| 4159 | } |
| 4160 | |
Filip Gruszczynski | a59ac9c | 2015-09-10 18:28:48 -0700 | [diff] [blame] | 4161 | private static boolean isResizeOnlyChange(int change) { |
| 4162 | return (change & ~(ActivityInfo.CONFIG_SCREEN_SIZE |
| 4163 | | ActivityInfo.CONFIG_SMALLEST_SCREEN_SIZE | ActivityInfo.CONFIG_ORIENTATION)) == 0; |
| 4164 | } |
| 4165 | |
| 4166 | private boolean relaunchActivityLocked(ActivityRecord r, int changes, boolean andResume, |
| 4167 | boolean preserveWindow) { |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 4168 | List<ResultInfo> results = null; |
Dianne Hackborn | 85d558c | 2014-11-04 10:31:54 -0800 | [diff] [blame] | 4169 | List<ReferrerIntent> newIntents = null; |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 4170 | if (andResume) { |
| 4171 | results = r.results; |
| 4172 | newIntents = r.newIntents; |
| 4173 | } |
Wale Ogunwale | ee006da | 2015-03-30 14:49:25 -0700 | [diff] [blame] | 4174 | if (DEBUG_SWITCH) Slog.v(TAG_SWITCH, |
| 4175 | "Relaunching: " + r + " with results=" + results + " newIntents=" + newIntents |
Filip Gruszczynski | a59ac9c | 2015-09-10 18:28:48 -0700 | [diff] [blame] | 4176 | + " andResume=" + andResume + " preserveWindow=" + preserveWindow); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 4177 | EventLog.writeEvent(andResume ? EventLogTags.AM_RELAUNCH_RESUME_ACTIVITY |
Dianne Hackborn | b12e135 | 2012-09-26 11:39:20 -0700 | [diff] [blame] | 4178 | : EventLogTags.AM_RELAUNCH_ACTIVITY, r.userId, System.identityHashCode(r), |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 4179 | r.task.taskId, r.shortComponentName); |
Craig Mautner | 9db9a0b | 2013-04-29 17:05:56 -0700 | [diff] [blame] | 4180 | |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 4181 | r.startFreezingScreenLocked(r.app, 0); |
Craig Mautner | 9db9a0b | 2013-04-29 17:05:56 -0700 | [diff] [blame] | 4182 | |
Craig Mautner | 34b73df | 2014-01-12 21:11:08 -0800 | [diff] [blame] | 4183 | mStackSupervisor.removeChildActivityContainers(r); |
| 4184 | |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 4185 | try { |
Wale Ogunwale | ee006da | 2015-03-30 14:49:25 -0700 | [diff] [blame] | 4186 | if (DEBUG_SWITCH || DEBUG_STATES) Slog.i(TAG_SWITCH, |
| 4187 | "Moving to " + (andResume ? "RESUMED" : "PAUSED") + " Relaunching " + r); |
Dianne Hackborn | e2515ee | 2011-04-27 18:52:56 -0400 | [diff] [blame] | 4188 | r.forceNewConfig = false; |
Wale Ogunwale | 60454db | 2015-01-23 16:05:07 -0800 | [diff] [blame] | 4189 | r.app.thread.scheduleRelaunchActivity(r.appToken, results, newIntents, changes, |
| 4190 | !andResume, new Configuration(mService.mConfiguration), |
Filip Gruszczynski | a59ac9c | 2015-09-10 18:28:48 -0700 | [diff] [blame] | 4191 | new Configuration(r.task.mOverrideConfig), preserveWindow); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 4192 | // Note: don't need to call pauseIfSleepingLocked() here, because |
| 4193 | // the caller will only pass in 'andResume' if this activity is |
| 4194 | // currently resumed, which implies we aren't sleeping. |
| 4195 | } catch (RemoteException e) { |
Wale Ogunwale | ee006da | 2015-03-30 14:49:25 -0700 | [diff] [blame] | 4196 | if (DEBUG_SWITCH || DEBUG_STATES) Slog.i(TAG_SWITCH, "Relaunch failed", e); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 4197 | } |
| 4198 | |
| 4199 | if (andResume) { |
| 4200 | r.results = null; |
| 4201 | r.newIntents = null; |
Dianne Hackborn | b61a026 | 2012-05-14 17:19:18 -0700 | [diff] [blame] | 4202 | r.state = ActivityState.RESUMED; |
| 4203 | } else { |
| 4204 | mHandler.removeMessages(PAUSE_TIMEOUT_MSG, r); |
| 4205 | r.state = ActivityState.PAUSED; |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 4206 | } |
| 4207 | |
| 4208 | return true; |
| 4209 | } |
Craig Mautner | cae015f | 2013-02-08 14:31:27 -0800 | [diff] [blame] | 4210 | |
| 4211 | boolean willActivityBeVisibleLocked(IBinder token) { |
Craig Mautner | d44711d | 2013-02-23 11:24:36 -0800 | [diff] [blame] | 4212 | for (int taskNdx = mTaskHistory.size() - 1; taskNdx >= 0; --taskNdx) { |
| 4213 | final ArrayList<ActivityRecord> activities = mTaskHistory.get(taskNdx).mActivities; |
| 4214 | for (int activityNdx = activities.size() - 1; activityNdx >= 0; --activityNdx) { |
| 4215 | final ActivityRecord r = activities.get(activityNdx); |
| 4216 | if (r.appToken == token) { |
Craig Mautner | 34b73df | 2014-01-12 21:11:08 -0800 | [diff] [blame] | 4217 | return true; |
Craig Mautner | d44711d | 2013-02-23 11:24:36 -0800 | [diff] [blame] | 4218 | } |
| 4219 | if (r.fullscreen && !r.finishing) { |
| 4220 | return false; |
| 4221 | } |
Craig Mautner | cae015f | 2013-02-08 14:31:27 -0800 | [diff] [blame] | 4222 | } |
| 4223 | } |
Wale Ogunwale | 7d70117 | 2015-03-11 15:36:30 -0700 | [diff] [blame] | 4224 | final ActivityRecord r = ActivityRecord.forTokenLocked(token); |
Craig Mautner | 34b73df | 2014-01-12 21:11:08 -0800 | [diff] [blame] | 4225 | if (r == null) { |
| 4226 | return false; |
| 4227 | } |
| 4228 | if (r.finishing) Slog.e(TAG, "willActivityBeVisibleLocked: Returning false," |
| 4229 | + " would have returned true for r=" + r); |
| 4230 | return !r.finishing; |
Craig Mautner | cae015f | 2013-02-08 14:31:27 -0800 | [diff] [blame] | 4231 | } |
| 4232 | |
| 4233 | void closeSystemDialogsLocked() { |
Craig Mautner | d44711d | 2013-02-23 11:24:36 -0800 | [diff] [blame] | 4234 | for (int taskNdx = mTaskHistory.size() - 1; taskNdx >= 0; --taskNdx) { |
| 4235 | final ArrayList<ActivityRecord> activities = mTaskHistory.get(taskNdx).mActivities; |
| 4236 | for (int activityNdx = activities.size() - 1; activityNdx >= 0; --activityNdx) { |
| 4237 | final ActivityRecord r = activities.get(activityNdx); |
| 4238 | if ((r.info.flags&ActivityInfo.FLAG_FINISH_ON_CLOSE_SYSTEM_DIALOGS) != 0) { |
Craig Mautner | d232895 | 2013-03-05 12:46:26 -0800 | [diff] [blame] | 4239 | finishActivityLocked(r, Activity.RESULT_CANCELED, null, "close-sys", true); |
Craig Mautner | d44711d | 2013-02-23 11:24:36 -0800 | [diff] [blame] | 4240 | } |
Craig Mautner | cae015f | 2013-02-08 14:31:27 -0800 | [diff] [blame] | 4241 | } |
| 4242 | } |
| 4243 | } |
| 4244 | |
Wale Ogunwale | 540e123 | 2015-05-01 15:35:39 -0700 | [diff] [blame] | 4245 | boolean finishDisabledPackageActivitiesLocked(String packageName, Set<String> filterByClasses, |
| 4246 | boolean doit, boolean evenPersistent, int userId) { |
Craig Mautner | cae015f | 2013-02-08 14:31:27 -0800 | [diff] [blame] | 4247 | boolean didSomething = false; |
| 4248 | TaskRecord lastTask = null; |
Craig Mautner | 9d8a30d | 2014-07-07 17:26:20 +0000 | [diff] [blame] | 4249 | ComponentName homeActivity = null; |
Craig Mautner | 56f52db | 2013-02-25 10:03:01 -0800 | [diff] [blame] | 4250 | for (int taskNdx = mTaskHistory.size() - 1; taskNdx >= 0; --taskNdx) { |
| 4251 | final ArrayList<ActivityRecord> activities = mTaskHistory.get(taskNdx).mActivities; |
| 4252 | int numActivities = activities.size(); |
| 4253 | for (int activityNdx = 0; activityNdx < numActivities; ++activityNdx) { |
| 4254 | ActivityRecord r = activities.get(activityNdx); |
Wale Ogunwale | 540e123 | 2015-05-01 15:35:39 -0700 | [diff] [blame] | 4255 | final boolean sameComponent = |
| 4256 | (r.packageName.equals(packageName) && (filterByClasses == null |
| 4257 | || filterByClasses.contains(r.realActivity.getClassName()))) |
| 4258 | || (packageName == null && r.userId == userId); |
Craig Mautner | 56f52db | 2013-02-25 10:03:01 -0800 | [diff] [blame] | 4259 | if ((userId == UserHandle.USER_ALL || r.userId == userId) |
Wale Ogunwale | 540e123 | 2015-05-01 15:35:39 -0700 | [diff] [blame] | 4260 | && (sameComponent || r.task == lastTask) |
Craig Mautner | 56f52db | 2013-02-25 10:03:01 -0800 | [diff] [blame] | 4261 | && (r.app == null || evenPersistent || !r.app.persistent)) { |
| 4262 | if (!doit) { |
| 4263 | if (r.finishing) { |
| 4264 | // If this activity is just finishing, then it is not |
| 4265 | // interesting as far as something to stop. |
| 4266 | continue; |
| 4267 | } |
| 4268 | return true; |
Craig Mautner | cae015f | 2013-02-08 14:31:27 -0800 | [diff] [blame] | 4269 | } |
Craig Mautner | 9d8a30d | 2014-07-07 17:26:20 +0000 | [diff] [blame] | 4270 | if (r.isHomeActivity()) { |
| 4271 | if (homeActivity != null && homeActivity.equals(r.realActivity)) { |
| 4272 | Slog.i(TAG, "Skip force-stop again " + r); |
| 4273 | continue; |
| 4274 | } else { |
| 4275 | homeActivity = r.realActivity; |
| 4276 | } |
| 4277 | } |
Craig Mautner | 56f52db | 2013-02-25 10:03:01 -0800 | [diff] [blame] | 4278 | didSomething = true; |
| 4279 | Slog.i(TAG, " Force finishing activity " + r); |
Wale Ogunwale | 540e123 | 2015-05-01 15:35:39 -0700 | [diff] [blame] | 4280 | if (sameComponent) { |
Craig Mautner | 56f52db | 2013-02-25 10:03:01 -0800 | [diff] [blame] | 4281 | if (r.app != null) { |
| 4282 | r.app.removed = true; |
| 4283 | } |
| 4284 | r.app = null; |
Craig Mautner | cae015f | 2013-02-08 14:31:27 -0800 | [diff] [blame] | 4285 | } |
Craig Mautner | 56f52db | 2013-02-25 10:03:01 -0800 | [diff] [blame] | 4286 | lastTask = r.task; |
Craig Mautner | d94b1b4 | 2013-05-01 11:58:03 -0700 | [diff] [blame] | 4287 | if (finishActivityLocked(r, Activity.RESULT_CANCELED, null, "force-stop", |
| 4288 | true)) { |
| 4289 | // r has been deleted from mActivities, accommodate. |
| 4290 | --numActivities; |
| 4291 | --activityNdx; |
| 4292 | } |
Craig Mautner | cae015f | 2013-02-08 14:31:27 -0800 | [diff] [blame] | 4293 | } |
| 4294 | } |
| 4295 | } |
| 4296 | return didSomething; |
| 4297 | } |
| 4298 | |
Dianne Hackborn | 0923328 | 2014-04-30 11:33:59 -0700 | [diff] [blame] | 4299 | void getTasksLocked(List<RunningTaskInfo> list, int callingUid, boolean allowed) { |
riddle_hsu | ddc7415 | 2015-04-07 11:30:09 +0800 | [diff] [blame] | 4300 | boolean focusedStack = mStackSupervisor.getFocusedStack() == this; |
| 4301 | boolean topTask = true; |
Craig Mautner | c0fd805 | 2013-09-19 11:20:17 -0700 | [diff] [blame] | 4302 | for (int taskNdx = mTaskHistory.size() - 1; taskNdx >= 0; --taskNdx) { |
Craig Mautner | aab647e | 2013-02-28 16:31:36 -0800 | [diff] [blame] | 4303 | final TaskRecord task = mTaskHistory.get(taskNdx); |
riddle_hsu | ddc7415 | 2015-04-07 11:30:09 +0800 | [diff] [blame] | 4304 | if (task.getTopActivity() == null) { |
| 4305 | continue; |
| 4306 | } |
Craig Mautner | aab647e | 2013-02-28 16:31:36 -0800 | [diff] [blame] | 4307 | ActivityRecord r = null; |
| 4308 | ActivityRecord top = null; |
Wale Ogunwale | 6035e01 | 2015-04-14 15:54:10 -0700 | [diff] [blame] | 4309 | ActivityRecord tmp; |
Craig Mautner | aab647e | 2013-02-28 16:31:36 -0800 | [diff] [blame] | 4310 | int numActivities = 0; |
| 4311 | int numRunning = 0; |
| 4312 | final ArrayList<ActivityRecord> activities = task.mActivities; |
Dianne Hackborn | 885fbe5 | 2014-08-23 15:23:58 -0700 | [diff] [blame] | 4313 | if (!allowed && !task.isHomeTask() && task.effectiveUid != callingUid) { |
Dianne Hackborn | 0923328 | 2014-04-30 11:33:59 -0700 | [diff] [blame] | 4314 | continue; |
| 4315 | } |
Craig Mautner | aab647e | 2013-02-28 16:31:36 -0800 | [diff] [blame] | 4316 | for (int activityNdx = activities.size() - 1; activityNdx >= 0; --activityNdx) { |
Wale Ogunwale | 6035e01 | 2015-04-14 15:54:10 -0700 | [diff] [blame] | 4317 | tmp = activities.get(activityNdx); |
| 4318 | if (tmp.finishing) { |
| 4319 | continue; |
| 4320 | } |
| 4321 | r = tmp; |
Craig Mautner | cae015f | 2013-02-08 14:31:27 -0800 | [diff] [blame] | 4322 | |
Craig Mautner | aab647e | 2013-02-28 16:31:36 -0800 | [diff] [blame] | 4323 | // Initialize state for next task if needed. |
| 4324 | if (top == null || (top.state == ActivityState.INITIALIZING)) { |
| 4325 | top = r; |
| 4326 | numActivities = numRunning = 0; |
Craig Mautner | cae015f | 2013-02-08 14:31:27 -0800 | [diff] [blame] | 4327 | } |
Craig Mautner | aab647e | 2013-02-28 16:31:36 -0800 | [diff] [blame] | 4328 | |
| 4329 | // Add 'r' into the current task. |
| 4330 | numActivities++; |
| 4331 | if (r.app != null && r.app.thread != null) { |
| 4332 | numRunning++; |
| 4333 | } |
| 4334 | |
Wale Ogunwale | e23149f | 2015-03-06 15:39:44 -0800 | [diff] [blame] | 4335 | if (DEBUG_ALL) Slog.v( |
Craig Mautner | aab647e | 2013-02-28 16:31:36 -0800 | [diff] [blame] | 4336 | TAG, r.intent.getComponent().flattenToShortString() |
| 4337 | + ": task=" + r.task); |
| 4338 | } |
| 4339 | |
| 4340 | RunningTaskInfo ci = new RunningTaskInfo(); |
| 4341 | ci.id = task.taskId; |
| 4342 | ci.baseActivity = r.intent.getComponent(); |
| 4343 | ci.topActivity = top.intent.getComponent(); |
Craig Mautner | c0fd805 | 2013-09-19 11:20:17 -0700 | [diff] [blame] | 4344 | ci.lastActiveTime = task.lastActiveTime; |
riddle_hsu | ddc7415 | 2015-04-07 11:30:09 +0800 | [diff] [blame] | 4345 | if (focusedStack && topTask) { |
| 4346 | // Give the latest time to ensure foreground task can be sorted |
| 4347 | // at the first, because lastActiveTime of creating task is 0. |
| 4348 | ci.lastActiveTime = System.currentTimeMillis(); |
| 4349 | topTask = false; |
| 4350 | } |
Craig Mautner | c0fd805 | 2013-09-19 11:20:17 -0700 | [diff] [blame] | 4351 | |
Craig Mautner | c0ffce5 | 2014-07-01 12:38:52 -0700 | [diff] [blame] | 4352 | if (top.task != null) { |
| 4353 | ci.description = top.task.lastDescription; |
Craig Mautner | aab647e | 2013-02-28 16:31:36 -0800 | [diff] [blame] | 4354 | } |
| 4355 | ci.numActivities = numActivities; |
| 4356 | ci.numRunning = numRunning; |
Craig Mautner | aab647e | 2013-02-28 16:31:36 -0800 | [diff] [blame] | 4357 | list.add(ci); |
Craig Mautner | cae015f | 2013-02-08 14:31:27 -0800 | [diff] [blame] | 4358 | } |
Craig Mautner | cae015f | 2013-02-08 14:31:27 -0800 | [diff] [blame] | 4359 | } |
| 4360 | |
| 4361 | public void unhandledBackLocked() { |
Craig Mautner | aab647e | 2013-02-28 16:31:36 -0800 | [diff] [blame] | 4362 | final int top = mTaskHistory.size() - 1; |
Wale Ogunwale | ee006da | 2015-03-30 14:49:25 -0700 | [diff] [blame] | 4363 | if (DEBUG_SWITCH) Slog.d(TAG_SWITCH, "Performing unhandledBack(): top activity at " + top); |
Craig Mautner | aab647e | 2013-02-28 16:31:36 -0800 | [diff] [blame] | 4364 | if (top >= 0) { |
| 4365 | final ArrayList<ActivityRecord> activities = mTaskHistory.get(top).mActivities; |
| 4366 | int activityTop = activities.size() - 1; |
| 4367 | if (activityTop > 0) { |
| 4368 | finishActivityLocked(activities.get(activityTop), Activity.RESULT_CANCELED, null, |
| 4369 | "unhandled-back", true); |
| 4370 | } |
Craig Mautner | cae015f | 2013-02-08 14:31:27 -0800 | [diff] [blame] | 4371 | } |
| 4372 | } |
| 4373 | |
Craig Mautner | 6b74cb5 | 2013-09-27 17:02:21 -0700 | [diff] [blame] | 4374 | /** |
| 4375 | * Reset local parameters because an app's activity died. |
| 4376 | * @param app The app of the activity that died. |
Craig Mautner | 1909125 | 2013-10-05 00:03:53 -0700 | [diff] [blame] | 4377 | * @return result from removeHistoryRecordsForAppLocked. |
Craig Mautner | 6b74cb5 | 2013-09-27 17:02:21 -0700 | [diff] [blame] | 4378 | */ |
| 4379 | boolean handleAppDiedLocked(ProcessRecord app) { |
Craig Mautner | e79d4268 | 2013-04-01 19:01:53 -0700 | [diff] [blame] | 4380 | if (mPausingActivity != null && mPausingActivity.app == app) { |
Wale Ogunwale | ee006da | 2015-03-30 14:49:25 -0700 | [diff] [blame] | 4381 | if (DEBUG_PAUSE || DEBUG_CLEANUP) Slog.v(TAG_PAUSE, |
Craig Mautner | e79d4268 | 2013-04-01 19:01:53 -0700 | [diff] [blame] | 4382 | "App died while pausing: " + mPausingActivity); |
| 4383 | mPausingActivity = null; |
| 4384 | } |
| 4385 | if (mLastPausedActivity != null && mLastPausedActivity.app == app) { |
| 4386 | mLastPausedActivity = null; |
Craig Mautner | 0f92274 | 2013-08-06 08:44:42 -0700 | [diff] [blame] | 4387 | mLastNoHistoryActivity = null; |
Craig Mautner | e79d4268 | 2013-04-01 19:01:53 -0700 | [diff] [blame] | 4388 | } |
| 4389 | |
Craig Mautner | 1909125 | 2013-10-05 00:03:53 -0700 | [diff] [blame] | 4390 | return removeHistoryRecordsForAppLocked(app); |
Craig Mautner | e79d4268 | 2013-04-01 19:01:53 -0700 | [diff] [blame] | 4391 | } |
| 4392 | |
Craig Mautner | cae015f | 2013-02-08 14:31:27 -0800 | [diff] [blame] | 4393 | void handleAppCrashLocked(ProcessRecord app) { |
Craig Mautner | d44711d | 2013-02-23 11:24:36 -0800 | [diff] [blame] | 4394 | for (int taskNdx = mTaskHistory.size() - 1; taskNdx >= 0; --taskNdx) { |
| 4395 | final ArrayList<ActivityRecord> activities = mTaskHistory.get(taskNdx).mActivities; |
| 4396 | for (int activityNdx = activities.size() - 1; activityNdx >= 0; --activityNdx) { |
| 4397 | final ActivityRecord r = activities.get(activityNdx); |
| 4398 | if (r.app == app) { |
| 4399 | Slog.w(TAG, " Force finishing activity " |
| 4400 | + r.intent.getComponent().flattenToShortString()); |
Craig Mautner | 8e5b133 | 2014-07-24 13:32:37 -0700 | [diff] [blame] | 4401 | // Force the destroy to skip right to removal. |
| 4402 | r.app = null; |
| 4403 | finishCurrentActivityLocked(r, FINISH_IMMEDIATELY, false); |
Craig Mautner | d44711d | 2013-02-23 11:24:36 -0800 | [diff] [blame] | 4404 | } |
Craig Mautner | cae015f | 2013-02-08 14:31:27 -0800 | [diff] [blame] | 4405 | } |
| 4406 | } |
| 4407 | } |
| 4408 | |
Dianne Hackborn | 390517b | 2013-05-30 15:03:32 -0700 | [diff] [blame] | 4409 | boolean dumpActivitiesLocked(FileDescriptor fd, PrintWriter pw, boolean dumpAll, |
Dianne Hackborn | 7ad34e5 | 2013-06-05 18:41:45 -0700 | [diff] [blame] | 4410 | boolean dumpClient, String dumpPackage, boolean needSep, String header) { |
Dianne Hackborn | 390517b | 2013-05-30 15:03:32 -0700 | [diff] [blame] | 4411 | boolean printed = false; |
Craig Mautner | aab647e | 2013-02-28 16:31:36 -0800 | [diff] [blame] | 4412 | for (int taskNdx = mTaskHistory.size() - 1; taskNdx >= 0; --taskNdx) { |
| 4413 | final TaskRecord task = mTaskHistory.get(taskNdx); |
Dianne Hackborn | 390517b | 2013-05-30 15:03:32 -0700 | [diff] [blame] | 4414 | printed |= ActivityStackSupervisor.dumpHistoryList(fd, pw, |
| 4415 | mTaskHistory.get(taskNdx).mActivities, " ", "Hist", true, !dumpAll, |
Dianne Hackborn | 7ad34e5 | 2013-06-05 18:41:45 -0700 | [diff] [blame] | 4416 | dumpClient, dumpPackage, needSep, header, |
Wale Ogunwale | b34a7ad | 2015-08-14 11:05:30 -0700 | [diff] [blame] | 4417 | " Task id #" + task.taskId + "\n" + |
| 4418 | " mFullscreen=" + task.mFullscreen + "\n" + |
| 4419 | " mBounds=" + task.mBounds + "\n" + |
| 4420 | " mLastNonFullscreenBounds=" + task.mLastNonFullscreenBounds); |
Dianne Hackborn | 7ad34e5 | 2013-06-05 18:41:45 -0700 | [diff] [blame] | 4421 | if (printed) { |
| 4422 | header = null; |
| 4423 | } |
Craig Mautner | aab647e | 2013-02-28 16:31:36 -0800 | [diff] [blame] | 4424 | } |
Dianne Hackborn | 390517b | 2013-05-30 15:03:32 -0700 | [diff] [blame] | 4425 | return printed; |
Craig Mautner | cae015f | 2013-02-08 14:31:27 -0800 | [diff] [blame] | 4426 | } |
| 4427 | |
| 4428 | ArrayList<ActivityRecord> getDumpActivitiesLocked(String name) { |
| 4429 | ArrayList<ActivityRecord> activities = new ArrayList<ActivityRecord>(); |
| 4430 | |
| 4431 | if ("all".equals(name)) { |
Craig Mautner | aab647e | 2013-02-28 16:31:36 -0800 | [diff] [blame] | 4432 | for (int taskNdx = mTaskHistory.size() - 1; taskNdx >= 0; --taskNdx) { |
| 4433 | activities.addAll(mTaskHistory.get(taskNdx).mActivities); |
Craig Mautner | cae015f | 2013-02-08 14:31:27 -0800 | [diff] [blame] | 4434 | } |
| 4435 | } else if ("top".equals(name)) { |
Craig Mautner | aab647e | 2013-02-28 16:31:36 -0800 | [diff] [blame] | 4436 | final int top = mTaskHistory.size() - 1; |
| 4437 | if (top >= 0) { |
| 4438 | final ArrayList<ActivityRecord> list = mTaskHistory.get(top).mActivities; |
| 4439 | int listTop = list.size() - 1; |
| 4440 | if (listTop >= 0) { |
| 4441 | activities.add(list.get(listTop)); |
| 4442 | } |
Craig Mautner | cae015f | 2013-02-08 14:31:27 -0800 | [diff] [blame] | 4443 | } |
| 4444 | } else { |
| 4445 | ItemMatcher matcher = new ItemMatcher(); |
| 4446 | matcher.build(name); |
| 4447 | |
Craig Mautner | aab647e | 2013-02-28 16:31:36 -0800 | [diff] [blame] | 4448 | for (int taskNdx = mTaskHistory.size() - 1; taskNdx >= 0; --taskNdx) { |
| 4449 | for (ActivityRecord r1 : mTaskHistory.get(taskNdx).mActivities) { |
| 4450 | if (matcher.match(r1, r1.intent.getComponent())) { |
| 4451 | activities.add(r1); |
| 4452 | } |
Craig Mautner | cae015f | 2013-02-08 14:31:27 -0800 | [diff] [blame] | 4453 | } |
| 4454 | } |
| 4455 | } |
| 4456 | |
| 4457 | return activities; |
| 4458 | } |
| 4459 | |
| 4460 | ActivityRecord restartPackage(String packageName) { |
| 4461 | ActivityRecord starting = topRunningActivityLocked(null); |
| 4462 | |
| 4463 | // All activities that came from the package must be |
| 4464 | // restarted as if there was a config change. |
Craig Mautner | aab647e | 2013-02-28 16:31:36 -0800 | [diff] [blame] | 4465 | for (int taskNdx = mTaskHistory.size() - 1; taskNdx >= 0; --taskNdx) { |
| 4466 | final ArrayList<ActivityRecord> activities = mTaskHistory.get(taskNdx).mActivities; |
| 4467 | for (int activityNdx = activities.size() - 1; activityNdx >= 0; --activityNdx) { |
| 4468 | final ActivityRecord a = activities.get(activityNdx); |
| 4469 | if (a.info.packageName.equals(packageName)) { |
| 4470 | a.forceNewConfig = true; |
| 4471 | if (starting != null && a == starting && a.visible) { |
| 4472 | a.startFreezingScreenLocked(starting.app, |
| 4473 | ActivityInfo.CONFIG_SCREEN_LAYOUT); |
| 4474 | } |
Craig Mautner | cae015f | 2013-02-08 14:31:27 -0800 | [diff] [blame] | 4475 | } |
| 4476 | } |
| 4477 | } |
| 4478 | |
| 4479 | return starting; |
| 4480 | } |
Craig Mautner | 5d9c7be | 2013-02-15 14:02:56 -0800 | [diff] [blame] | 4481 | |
Craig Mautner | 299f960 | 2015-01-26 09:47:33 -0800 | [diff] [blame] | 4482 | void removeTask(TaskRecord task, String reason) { |
Wale Ogunwale | 040b470 | 2015-08-06 18:10:50 -0700 | [diff] [blame] | 4483 | removeTask(task, reason, !MOVING); |
Wale Ogunwale | 53a29a9 | 2015-02-23 15:42:52 -0800 | [diff] [blame] | 4484 | } |
| 4485 | |
Wale Ogunwale | 000957c | 2015-04-03 08:19:12 -0700 | [diff] [blame] | 4486 | /** |
| 4487 | * Removes the input task from this stack. |
| 4488 | * @param task to remove. |
| 4489 | * @param reason for removal. |
Wale Ogunwale | 040b470 | 2015-08-06 18:10:50 -0700 | [diff] [blame] | 4490 | * @param moving task to another stack. In the case we are moving we don't want to perform |
| 4491 | * some operations on the task like removing it from window manager or recents. |
Wale Ogunwale | 000957c | 2015-04-03 08:19:12 -0700 | [diff] [blame] | 4492 | */ |
Wale Ogunwale | 040b470 | 2015-08-06 18:10:50 -0700 | [diff] [blame] | 4493 | void removeTask(TaskRecord task, String reason, boolean moving) { |
| 4494 | if (!moving) { |
Craig Mautner | 15df08a | 2015-04-01 12:17:18 -0700 | [diff] [blame] | 4495 | mStackSupervisor.removeLockedTaskLocked(task); |
Wale Ogunwale | 53a29a9 | 2015-02-23 15:42:52 -0800 | [diff] [blame] | 4496 | mWindowManager.removeTask(task.taskId); |
| 4497 | } |
Wale Ogunwale | 000957c | 2015-04-03 08:19:12 -0700 | [diff] [blame] | 4498 | |
Craig Mautner | 04a0ea6 | 2014-01-13 12:51:26 -0800 | [diff] [blame] | 4499 | final ActivityRecord r = mResumedActivity; |
| 4500 | if (r != null && r.task == task) { |
| 4501 | mResumedActivity = null; |
| 4502 | } |
| 4503 | |
Craig Mautner | ae7ecab | 2013-09-18 11:48:14 -0700 | [diff] [blame] | 4504 | final int taskNdx = mTaskHistory.indexOf(task); |
| 4505 | final int topTaskNdx = mTaskHistory.size() - 1; |
Craig Mautner | 84984fa | 2014-06-19 11:19:20 -0700 | [diff] [blame] | 4506 | if (task.isOverHomeStack() && taskNdx < topTaskNdx) { |
| 4507 | final TaskRecord nextTask = mTaskHistory.get(taskNdx + 1); |
| 4508 | if (!nextTask.isOverHomeStack()) { |
| 4509 | nextTask.setTaskToReturnTo(HOME_ACTIVITY_TYPE); |
| 4510 | } |
Craig Mautner | ae7ecab | 2013-09-18 11:48:14 -0700 | [diff] [blame] | 4511 | } |
Craig Mautner | de4ef02 | 2013-04-07 19:01:33 -0700 | [diff] [blame] | 4512 | mTaskHistory.remove(task); |
Craig Mautner | 21d24a2 | 2014-04-23 11:45:37 -0700 | [diff] [blame] | 4513 | updateTaskMovement(task, true); |
Craig Mautner | 41db4a7 | 2014-05-07 17:20:56 -0700 | [diff] [blame] | 4514 | |
Wale Ogunwale | 040b470 | 2015-08-06 18:10:50 -0700 | [diff] [blame] | 4515 | if (!moving && task.mActivities.isEmpty()) { |
Craig Mautner | 41db4a7 | 2014-05-07 17:20:56 -0700 | [diff] [blame] | 4516 | final boolean isVoiceSession = task.voiceSession != null; |
| 4517 | if (isVoiceSession) { |
| 4518 | try { |
| 4519 | task.voiceSession.taskFinished(task.intent, task.taskId); |
| 4520 | } catch (RemoteException e) { |
| 4521 | } |
Dianne Hackborn | c03c916 | 2014-05-02 10:45:59 -0700 | [diff] [blame] | 4522 | } |
Craig Mautner | 41db4a7 | 2014-05-07 17:20:56 -0700 | [diff] [blame] | 4523 | if (task.autoRemoveFromRecents() || isVoiceSession) { |
| 4524 | // Task creator asked to remove this when done, or this task was a voice |
| 4525 | // interaction, so it should not remain on the recent tasks list. |
Wale Ogunwale | c82f2f5 | 2014-12-09 09:32:50 -0800 | [diff] [blame] | 4526 | mRecentTasks.remove(task); |
Winson Chung | 740c3ac | 2014-11-12 16:14:38 -0800 | [diff] [blame] | 4527 | task.removedFromRecents(); |
Craig Mautner | 41db4a7 | 2014-05-07 17:20:56 -0700 | [diff] [blame] | 4528 | } |
Dianne Hackborn | 91097de | 2014-04-04 18:02:06 -0700 | [diff] [blame] | 4529 | } |
Craig Mautner | 04a0ea6 | 2014-01-13 12:51:26 -0800 | [diff] [blame] | 4530 | |
| 4531 | if (mTaskHistory.isEmpty()) { |
Wale Ogunwale | ee006da | 2015-03-30 14:49:25 -0700 | [diff] [blame] | 4532 | if (DEBUG_STACK) Slog.i(TAG_STACK, "removeTask: removing stack=" + this); |
Craig Mautner | 04a0ea6 | 2014-01-13 12:51:26 -0800 | [diff] [blame] | 4533 | if (isOnHomeDisplay()) { |
Wale Ogunwale | d697cea | 2015-02-20 17:19:49 -0800 | [diff] [blame] | 4534 | String myReason = reason + " leftTaskHistoryEmpty"; |
| 4535 | if (mFullscreen || !adjustFocusToNextVisibleStackLocked(null, myReason)) { |
Wale Ogunwale | 925d0d1 | 2015-09-23 15:40:07 -0700 | [diff] [blame^] | 4536 | mStackSupervisor.moveHomeStackToFront(myReason); |
Wale Ogunwale | d697cea | 2015-02-20 17:19:49 -0800 | [diff] [blame] | 4537 | } |
Craig Mautner | 04a0ea6 | 2014-01-13 12:51:26 -0800 | [diff] [blame] | 4538 | } |
Craig Mautner | 593a4e6 | 2014-01-15 17:55:51 -0800 | [diff] [blame] | 4539 | if (mStacks != null) { |
| 4540 | mStacks.remove(this); |
| 4541 | mStacks.add(0, this); |
| 4542 | } |
Wale Ogunwale | 925d0d1 | 2015-09-23 15:40:07 -0700 | [diff] [blame^] | 4543 | if (!isHomeStack()) { |
Wale Ogunwale | 49853bf | 2015-02-23 09:24:42 -0800 | [diff] [blame] | 4544 | mActivityContainer.onTaskListEmptyLocked(); |
| 4545 | } |
Craig Mautner | 04a0ea6 | 2014-01-13 12:51:26 -0800 | [diff] [blame] | 4546 | } |
Wale Ogunwale | 04f4d6b | 2015-03-11 09:23:25 -0700 | [diff] [blame] | 4547 | |
| 4548 | task.stack = null; |
Craig Mautner | 0247fc8 | 2013-02-28 14:32:06 -0800 | [diff] [blame] | 4549 | } |
| 4550 | |
Dianne Hackborn | 91097de | 2014-04-04 18:02:06 -0700 | [diff] [blame] | 4551 | TaskRecord createTaskRecord(int taskId, ActivityInfo info, Intent intent, |
| 4552 | IVoiceInteractionSession voiceSession, IVoiceInteractor voiceInteractor, |
| 4553 | boolean toTop) { |
Craig Mautner | 21d24a2 | 2014-04-23 11:45:37 -0700 | [diff] [blame] | 4554 | TaskRecord task = new TaskRecord(mService, taskId, info, intent, voiceSession, |
| 4555 | voiceInteractor); |
Chong Zhang | 0fa656b | 2015-08-31 15:17:21 -0700 | [diff] [blame] | 4556 | // add the task to stack first, mTaskPositioner might need the stack association |
| 4557 | addTask(task, toTop, false); |
Filip Gruszczynski | e5390e7 | 2015-08-18 16:39:00 -0700 | [diff] [blame] | 4558 | if (mTaskPositioner != null) { |
Filip Gruszczynski | 9b1ce52 | 2015-08-20 18:37:19 -0700 | [diff] [blame] | 4559 | mTaskPositioner.updateDefaultBounds(task, mTaskHistory, info.initialLayout); |
Wale Ogunwale | a6e902e | 2015-09-21 18:37:15 -0700 | [diff] [blame] | 4560 | } else if (mBounds != null && task.mResizeable) { |
| 4561 | task.updateOverrideConfiguration(mBounds); |
Filip Gruszczynski | e5390e7 | 2015-08-18 16:39:00 -0700 | [diff] [blame] | 4562 | } |
Craig Mautner | 5d9c7be | 2013-02-15 14:02:56 -0800 | [diff] [blame] | 4563 | return task; |
| 4564 | } |
Craig Mautner | c00204b | 2013-03-05 15:02:14 -0800 | [diff] [blame] | 4565 | |
| 4566 | ArrayList<TaskRecord> getAllTasks() { |
Wale Ogunwale | 9d3de4c | 2015-02-01 16:49:44 -0800 | [diff] [blame] | 4567 | return new ArrayList<>(mTaskHistory); |
Craig Mautner | c00204b | 2013-03-05 15:02:14 -0800 | [diff] [blame] | 4568 | } |
| 4569 | |
Dianne Hackborn | c03c916 | 2014-05-02 10:45:59 -0700 | [diff] [blame] | 4570 | void addTask(final TaskRecord task, final boolean toTop, boolean moving) { |
Craig Mautner | c00204b | 2013-03-05 15:02:14 -0800 | [diff] [blame] | 4571 | task.stack = this; |
| 4572 | if (toTop) { |
Wale Ogunwale | 3fcb4a8 | 2015-04-06 14:00:13 -0700 | [diff] [blame] | 4573 | insertTaskAtTop(task, null); |
Craig Mautner | c00204b | 2013-03-05 15:02:14 -0800 | [diff] [blame] | 4574 | } else { |
| 4575 | mTaskHistory.add(0, task); |
Craig Mautner | 21d24a2 | 2014-04-23 11:45:37 -0700 | [diff] [blame] | 4576 | updateTaskMovement(task, false); |
Craig Mautner | c00204b | 2013-03-05 15:02:14 -0800 | [diff] [blame] | 4577 | } |
Dianne Hackborn | c03c916 | 2014-05-02 10:45:59 -0700 | [diff] [blame] | 4578 | if (!moving && task.voiceSession != null) { |
| 4579 | try { |
| 4580 | task.voiceSession.taskStarted(task.intent, task.taskId); |
| 4581 | } catch (RemoteException e) { |
| 4582 | } |
| 4583 | } |
Craig Mautner | c00204b | 2013-03-05 15:02:14 -0800 | [diff] [blame] | 4584 | } |
| 4585 | |
Wale Ogunwale | ddc1cb2 | 2015-07-25 19:23:04 -0700 | [diff] [blame] | 4586 | void positionTask(final TaskRecord task, int position, boolean moving) { |
| 4587 | task.stack = this; |
| 4588 | insertTaskAtPosition(task, position); |
| 4589 | if (!moving && task.voiceSession != null) { |
| 4590 | try { |
| 4591 | task.voiceSession.taskStarted(task.intent, task.taskId); |
| 4592 | } catch (RemoteException e) { |
| 4593 | } |
| 4594 | } |
| 4595 | } |
| 4596 | |
Filip Gruszczynski | e5390e7 | 2015-08-18 16:39:00 -0700 | [diff] [blame] | 4597 | void addConfigOverride(ActivityRecord r, TaskRecord task) { |
Wale Ogunwale | 706ed79 | 2015-08-02 10:29:44 -0700 | [diff] [blame] | 4598 | final Rect bounds = task.getLaunchBounds(); |
Chong Zhang | 0fa656b | 2015-08-31 15:17:21 -0700 | [diff] [blame] | 4599 | task.updateOverrideConfiguration(bounds); |
Filip Gruszczynski | ebcc875 | 2015-08-25 16:51:05 -0700 | [diff] [blame] | 4600 | mWindowManager.addAppToken(task.mActivities.indexOf(r), r.appToken, |
| 4601 | r.task.taskId, mStackId, r.info.screenOrientation, r.fullscreen, |
| 4602 | (r.info.flags & ActivityInfo.FLAG_SHOW_FOR_ALL_USERS) != 0, r.userId, |
| 4603 | r.info.configChanges, task.voiceSession != null, r.mLaunchTaskBehind, |
Wale Ogunwale | 61b009e | 2015-09-16 15:43:05 -0700 | [diff] [blame] | 4604 | bounds, task.mOverrideConfig, !r.isHomeActivity()); |
Wale Ogunwale | 706ed79 | 2015-08-02 10:29:44 -0700 | [diff] [blame] | 4605 | r.taskConfigOverride = task.mOverrideConfig; |
| 4606 | } |
| 4607 | |
| 4608 | private void setAppTask(ActivityRecord r, TaskRecord task) { |
| 4609 | final Rect bounds = task.getLaunchBounds(); |
Chong Zhang | 0fa656b | 2015-08-31 15:17:21 -0700 | [diff] [blame] | 4610 | task.updateOverrideConfiguration(bounds); |
| 4611 | mWindowManager.setAppTask( |
| 4612 | r.appToken, task.taskId, task.getLaunchBounds(), task.mOverrideConfig); |
Wale Ogunwale | 706ed79 | 2015-08-02 10:29:44 -0700 | [diff] [blame] | 4613 | r.taskConfigOverride = task.mOverrideConfig; |
| 4614 | } |
| 4615 | |
Craig Mautner | c00204b | 2013-03-05 15:02:14 -0800 | [diff] [blame] | 4616 | public int getStackId() { |
| 4617 | return mStackId; |
| 4618 | } |
Craig Mautner | de4ef02 | 2013-04-07 19:01:33 -0700 | [diff] [blame] | 4619 | |
| 4620 | @Override |
| 4621 | public String toString() { |
Dianne Hackborn | 2a272d4 | 2013-10-16 13:34:33 -0700 | [diff] [blame] | 4622 | return "ActivityStack{" + Integer.toHexString(System.identityHashCode(this)) |
| 4623 | + " stackId=" + mStackId + ", " + mTaskHistory.size() + " tasks}"; |
Craig Mautner | de4ef02 | 2013-04-07 19:01:33 -0700 | [diff] [blame] | 4624 | } |
Wale Ogunwale | 60454db | 2015-01-23 16:05:07 -0800 | [diff] [blame] | 4625 | |
Craig Mautner | 15df08a | 2015-04-01 12:17:18 -0700 | [diff] [blame] | 4626 | void onLockTaskPackagesUpdatedLocked() { |
| 4627 | for (int taskNdx = mTaskHistory.size() - 1; taskNdx >= 0; --taskNdx) { |
| 4628 | mTaskHistory.get(taskNdx).setLockTaskAuth(); |
| 4629 | } |
| 4630 | } |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 4631 | } |