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 | 3797c22 | 2015-10-27 14:21:58 -0700 | [diff] [blame] | 19 | import static android.app.ActivityManager.StackId.DOCKED_STACK_ID; |
| 20 | import static android.app.ActivityManager.StackId.FREEFORM_WORKSPACE_STACK_ID; |
| 21 | import static android.app.ActivityManager.StackId.FULLSCREEN_WORKSPACE_STACK_ID; |
| 22 | import static android.app.ActivityManager.StackId.HOME_STACK_ID; |
Wale Ogunwale | 56d75cf | 2016-03-09 15:14:47 -0800 | [diff] [blame] | 23 | import static android.app.ActivityManager.StackId.INVALID_STACK_ID; |
Wale Ogunwale | 3797c22 | 2015-10-27 14:21:58 -0700 | [diff] [blame] | 24 | import static android.app.ActivityManager.StackId.PINNED_STACK_ID; |
Filip Gruszczynski | 3c2db1d1 | 2016-01-06 17:39:14 -0800 | [diff] [blame] | 25 | import static android.content.pm.ActivityInfo.CONFIG_ORIENTATION; |
| 26 | import static android.content.pm.ActivityInfo.CONFIG_SCREEN_LAYOUT; |
| 27 | import static android.content.pm.ActivityInfo.CONFIG_SCREEN_SIZE; |
| 28 | import static android.content.pm.ActivityInfo.CONFIG_SMALLEST_SCREEN_SIZE; |
Wale Ogunwale | 5658e4b | 2016-02-12 12:22:19 -0800 | [diff] [blame] | 29 | import static android.content.pm.ActivityInfo.FLAG_RESUME_WHILE_PAUSING; |
Wale Ogunwale | 6dfdfd6 | 2015-04-15 12:01:38 -0700 | [diff] [blame] | 30 | import static android.content.pm.ActivityInfo.FLAG_SHOW_FOR_ALL_USERS; |
Filip Gruszczynski | 3c2db1d1 | 2016-01-06 17:39:14 -0800 | [diff] [blame] | 31 | import static android.content.res.Configuration.SCREENLAYOUT_UNDEFINED; |
Jorim Jaggi | af80db4 | 2016-04-07 19:19:15 -0700 | [diff] [blame] | 32 | import static com.android.server.am.ActivityManagerDebugConfig.DEBUG_ADD_REMOVE; |
| 33 | import static com.android.server.am.ActivityManagerDebugConfig.DEBUG_ALL; |
| 34 | import static com.android.server.am.ActivityManagerDebugConfig.DEBUG_APP; |
| 35 | import static com.android.server.am.ActivityManagerDebugConfig.DEBUG_CLEANUP; |
| 36 | import static com.android.server.am.ActivityManagerDebugConfig.DEBUG_CONFIGURATION; |
| 37 | import static com.android.server.am.ActivityManagerDebugConfig.DEBUG_CONTAINERS; |
| 38 | import static com.android.server.am.ActivityManagerDebugConfig.DEBUG_LOCKSCREEN; |
| 39 | import static com.android.server.am.ActivityManagerDebugConfig.DEBUG_PAUSE; |
| 40 | import static com.android.server.am.ActivityManagerDebugConfig.DEBUG_RELEASE; |
| 41 | import static com.android.server.am.ActivityManagerDebugConfig.DEBUG_RESULTS; |
| 42 | import static com.android.server.am.ActivityManagerDebugConfig.DEBUG_SAVED_STATE; |
| 43 | import static com.android.server.am.ActivityManagerDebugConfig.DEBUG_SCREENSHOTS; |
| 44 | import static com.android.server.am.ActivityManagerDebugConfig.DEBUG_STACK; |
| 45 | import static com.android.server.am.ActivityManagerDebugConfig.DEBUG_STATES; |
| 46 | import static com.android.server.am.ActivityManagerDebugConfig.DEBUG_SWITCH; |
| 47 | import static com.android.server.am.ActivityManagerDebugConfig.DEBUG_TASKS; |
| 48 | import static com.android.server.am.ActivityManagerDebugConfig.DEBUG_TRANSITION; |
| 49 | import static com.android.server.am.ActivityManagerDebugConfig.DEBUG_USER_LEAVING; |
| 50 | import static com.android.server.am.ActivityManagerDebugConfig.DEBUG_VISIBILITY; |
| 51 | import static com.android.server.am.ActivityManagerDebugConfig.POSTFIX_ADD_REMOVE; |
| 52 | import static com.android.server.am.ActivityManagerDebugConfig.POSTFIX_APP; |
| 53 | import static com.android.server.am.ActivityManagerDebugConfig.POSTFIX_CLEANUP; |
| 54 | import static com.android.server.am.ActivityManagerDebugConfig.POSTFIX_CONFIGURATION; |
| 55 | import static com.android.server.am.ActivityManagerDebugConfig.POSTFIX_CONTAINERS; |
| 56 | import static com.android.server.am.ActivityManagerDebugConfig.POSTFIX_PAUSE; |
| 57 | import static com.android.server.am.ActivityManagerDebugConfig.POSTFIX_RELEASE; |
| 58 | import static com.android.server.am.ActivityManagerDebugConfig.POSTFIX_RESULTS; |
| 59 | import static com.android.server.am.ActivityManagerDebugConfig.POSTFIX_SAVED_STATE; |
| 60 | import static com.android.server.am.ActivityManagerDebugConfig.POSTFIX_SCREENSHOTS; |
| 61 | import static com.android.server.am.ActivityManagerDebugConfig.POSTFIX_STACK; |
| 62 | import static com.android.server.am.ActivityManagerDebugConfig.POSTFIX_STATES; |
| 63 | import static com.android.server.am.ActivityManagerDebugConfig.POSTFIX_SWITCH; |
| 64 | import static com.android.server.am.ActivityManagerDebugConfig.POSTFIX_TASKS; |
| 65 | import static com.android.server.am.ActivityManagerDebugConfig.POSTFIX_TRANSITION; |
| 66 | import static com.android.server.am.ActivityManagerDebugConfig.POSTFIX_USER_LEAVING; |
| 67 | import static com.android.server.am.ActivityManagerDebugConfig.POSTFIX_VISIBILITY; |
| 68 | import static com.android.server.am.ActivityManagerDebugConfig.TAG_AM; |
| 69 | import static com.android.server.am.ActivityManagerDebugConfig.TAG_WITH_CLASS_NAME; |
Chong Zhang | 75b3720 | 2015-12-04 14:16:36 -0800 | [diff] [blame] | 70 | import static com.android.server.am.ActivityManagerService.LOCK_SCREEN_SHOWN; |
Craig Mautner | 84984fa | 2014-06-19 11:19:20 -0700 | [diff] [blame] | 71 | import static com.android.server.am.ActivityRecord.APPLICATION_ACTIVITY_TYPE; |
Jorim Jaggi | af80db4 | 2016-04-07 19:19:15 -0700 | [diff] [blame] | 72 | import static com.android.server.am.ActivityRecord.HOME_ACTIVITY_TYPE; |
Wale Ogunwale | f40c11b | 2016-02-26 08:16:02 -0800 | [diff] [blame] | 73 | import static com.android.server.am.ActivityRecord.STARTING_WINDOW_REMOVED; |
| 74 | import static com.android.server.am.ActivityRecord.STARTING_WINDOW_SHOWN; |
Wale Ogunwale | 3938197 | 2015-12-17 17:15:29 -0800 | [diff] [blame] | 75 | import static com.android.server.am.ActivityStackSupervisor.FindTaskResult; |
Wale Ogunwale | 06579d6 | 2016-04-30 15:29:06 -0700 | [diff] [blame] | 76 | import static com.android.server.am.ActivityStackSupervisor.ON_TOP; |
Filip Gruszczynski | bc5a6c5 | 2015-09-22 13:13:24 -0700 | [diff] [blame] | 77 | import static com.android.server.am.ActivityStackSupervisor.PRESERVE_WINDOWS; |
Jorim Jaggi | af80db4 | 2016-04-07 19:19:15 -0700 | [diff] [blame] | 78 | import static com.android.server.wm.AppTransition.TRANSIT_ACTIVITY_CLOSE; |
| 79 | import static com.android.server.wm.AppTransition.TRANSIT_ACTIVITY_OPEN; |
| 80 | import static com.android.server.wm.AppTransition.TRANSIT_NONE; |
| 81 | import static com.android.server.wm.AppTransition.TRANSIT_TASK_CLOSE; |
| 82 | import static com.android.server.wm.AppTransition.TRANSIT_TASK_OPEN; |
| 83 | import static com.android.server.wm.AppTransition.TRANSIT_TASK_OPEN_BEHIND; |
| 84 | import static com.android.server.wm.AppTransition.TRANSIT_TASK_TO_BACK; |
| 85 | import static com.android.server.wm.AppTransition.TRANSIT_TASK_TO_FRONT; |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 86 | |
| 87 | import android.app.Activity; |
Dianne Hackborn | 0c5001d | 2011-04-12 18:16:08 -0700 | [diff] [blame] | 88 | import android.app.ActivityManager; |
Jorim Jaggi | af80db4 | 2016-04-07 19:19:15 -0700 | [diff] [blame] | 89 | import android.app.ActivityManager.RunningTaskInfo; |
Wale Ogunwale | 3797c22 | 2015-10-27 14:21:58 -0700 | [diff] [blame] | 90 | import android.app.ActivityManager.StackId; |
Dianne Hackborn | 7a2195c | 2012-03-19 17:38:00 -0700 | [diff] [blame] | 91 | import android.app.ActivityOptions; |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 92 | import android.app.AppGlobals; |
Craig Mautner | 05d6272ba | 2013-02-11 09:39:27 -0800 | [diff] [blame] | 93 | import android.app.IActivityController; |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 94 | import android.app.ResultInfo; |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 95 | import android.content.ComponentName; |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 96 | import android.content.Intent; |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 97 | import android.content.pm.ActivityInfo; |
Todd Kennedy | 39bfee5 | 2016-02-24 10:28:21 -0800 | [diff] [blame] | 98 | import android.content.pm.ApplicationInfo; |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 99 | import android.content.res.Configuration; |
Dianne Hackborn | 0aae2d4 | 2010-12-07 23:51:29 -0800 | [diff] [blame] | 100 | import android.graphics.Bitmap; |
Jorim Jaggi | af80db4 | 2016-04-07 19:19:15 -0700 | [diff] [blame] | 101 | import android.graphics.Point; |
| 102 | import android.graphics.Rect; |
Santos Cordon | 73ff7d8 | 2013-03-06 17:24:11 -0800 | [diff] [blame] | 103 | import android.net.Uri; |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 104 | import android.os.Binder; |
Dianne Hackborn | ce86ba8 | 2011-07-13 19:33:41 -0700 | [diff] [blame] | 105 | import android.os.Bundle; |
Craig Mautner | 329f412 | 2013-11-07 09:10:42 -0800 | [diff] [blame] | 106 | import android.os.Debug; |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 107 | import android.os.Handler; |
| 108 | import android.os.IBinder; |
Zoran Marceta | f958b32 | 2012-08-09 20:27:12 +0900 | [diff] [blame] | 109 | import android.os.Looper; |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 110 | import android.os.Message; |
Craig Mautner | a002604 | 2014-04-23 11:45:37 -0700 | [diff] [blame] | 111 | import android.os.PersistableBundle; |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 112 | import android.os.RemoteException; |
| 113 | import android.os.SystemClock; |
Craig Mautner | 329f412 | 2013-11-07 09:10:42 -0800 | [diff] [blame] | 114 | import android.os.Trace; |
Dianne Hackborn | f02b60a | 2012-08-16 10:48:27 -0700 | [diff] [blame] | 115 | import android.os.UserHandle; |
Craig Mautner | 4c07d02 | 2014-06-11 17:12:59 -0700 | [diff] [blame] | 116 | import android.service.voice.IVoiceInteractionSession; |
Jorim Jaggi | af80db4 | 2016-04-07 19:19:15 -0700 | [diff] [blame] | 117 | import android.util.ArraySet; |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 118 | import android.util.EventLog; |
Jorim Jaggi | 023da53 | 2016-04-20 22:42:32 -0700 | [diff] [blame] | 119 | import android.util.Log; |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 120 | import android.util.Slog; |
Craig Mautner | 59c0097 | 2012-07-30 12:10:24 -0700 | [diff] [blame] | 121 | import android.view.Display; |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 122 | |
Jorim Jaggi | af80db4 | 2016-04-07 19:19:15 -0700 | [diff] [blame] | 123 | import com.android.internal.app.IVoiceInteractor; |
| 124 | import com.android.internal.content.ReferrerIntent; |
| 125 | import com.android.internal.os.BatteryStatsImpl; |
| 126 | import com.android.server.Watchdog; |
| 127 | import com.android.server.am.ActivityManagerService.ItemMatcher; |
| 128 | import com.android.server.am.ActivityStackSupervisor.ActivityContainer; |
| 129 | import com.android.server.wm.TaskGroup; |
| 130 | import com.android.server.wm.WindowManagerService; |
| 131 | |
Craig Mautner | cae015f | 2013-02-08 14:31:27 -0800 | [diff] [blame] | 132 | import java.io.FileDescriptor; |
Craig Mautner | cae015f | 2013-02-08 14:31:27 -0800 | [diff] [blame] | 133 | import java.io.PrintWriter; |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 134 | import java.lang.ref.WeakReference; |
| 135 | import java.util.ArrayList; |
| 136 | import java.util.Iterator; |
| 137 | import java.util.List; |
Kenny Root | e6585b3 | 2013-12-13 12:00:26 -0800 | [diff] [blame] | 138 | import java.util.Objects; |
Wale Ogunwale | 540e123 | 2015-05-01 15:35:39 -0700 | [diff] [blame] | 139 | import java.util.Set; |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 140 | |
| 141 | /** |
| 142 | * State and management of a single stack of activities. |
| 143 | */ |
Dianne Hackborn | 0c5001d | 2011-04-12 18:16:08 -0700 | [diff] [blame] | 144 | final class ActivityStack { |
Craig Mautner | 5d9c7be | 2013-02-15 14:02:56 -0800 | [diff] [blame] | 145 | |
Wale Ogunwale | e23149f | 2015-03-06 15:39:44 -0800 | [diff] [blame] | 146 | private static final String TAG = TAG_WITH_CLASS_NAME ? "ActivityStack" : TAG_AM; |
Wale Ogunwale | 0fc365c | 2015-05-25 19:35:42 -0700 | [diff] [blame] | 147 | private static final String TAG_ADD_REMOVE = TAG + POSTFIX_ADD_REMOVE; |
| 148 | private static final String TAG_APP = TAG + POSTFIX_APP; |
Wale Ogunwale | e23149f | 2015-03-06 15:39:44 -0800 | [diff] [blame] | 149 | private static final String TAG_CLEANUP = TAG + POSTFIX_CLEANUP; |
Wale Ogunwale | 3ab9a27 | 2015-03-16 09:55:45 -0700 | [diff] [blame] | 150 | private static final String TAG_CONFIGURATION = TAG + POSTFIX_CONFIGURATION; |
Wale Ogunwale | 0fc365c | 2015-05-25 19:35:42 -0700 | [diff] [blame] | 151 | private static final String TAG_CONTAINERS = TAG + POSTFIX_CONTAINERS; |
Wale Ogunwale | ee006da | 2015-03-30 14:49:25 -0700 | [diff] [blame] | 152 | private static final String TAG_PAUSE = TAG + POSTFIX_PAUSE; |
Wale Ogunwale | 0fc365c | 2015-05-25 19:35:42 -0700 | [diff] [blame] | 153 | private static final String TAG_RELEASE = TAG + POSTFIX_RELEASE; |
Wale Ogunwale | ee006da | 2015-03-30 14:49:25 -0700 | [diff] [blame] | 154 | private static final String TAG_RESULTS = TAG + POSTFIX_RESULTS; |
Wale Ogunwale | 0fc365c | 2015-05-25 19:35:42 -0700 | [diff] [blame] | 155 | private static final String TAG_SAVED_STATE = TAG + POSTFIX_SAVED_STATE; |
| 156 | private static final String TAG_SCREENSHOTS = TAG + POSTFIX_SCREENSHOTS; |
Wale Ogunwale | ee006da | 2015-03-30 14:49:25 -0700 | [diff] [blame] | 157 | private static final String TAG_STACK = TAG + POSTFIX_STACK; |
Wale Ogunwale | 0fc365c | 2015-05-25 19:35:42 -0700 | [diff] [blame] | 158 | private static final String TAG_STATES = TAG + POSTFIX_STATES; |
Wale Ogunwale | ee006da | 2015-03-30 14:49:25 -0700 | [diff] [blame] | 159 | private static final String TAG_SWITCH = TAG + POSTFIX_SWITCH; |
| 160 | private static final String TAG_TASKS = TAG + POSTFIX_TASKS; |
| 161 | private static final String TAG_TRANSITION = TAG + POSTFIX_TRANSITION; |
| 162 | private static final String TAG_USER_LEAVING = TAG + POSTFIX_USER_LEAVING; |
| 163 | private static final String TAG_VISIBILITY = TAG + POSTFIX_VISIBILITY; |
Wale Ogunwale | 3ab9a27 | 2015-03-16 09:55:45 -0700 | [diff] [blame] | 164 | |
| 165 | private static final boolean VALIDATE_TOKENS = false; |
Wale Ogunwale | e23149f | 2015-03-06 15:39:44 -0800 | [diff] [blame] | 166 | |
Dianne Hackborn | 2a29b3a | 2012-03-15 15:48:38 -0700 | [diff] [blame] | 167 | // Ticks during which we check progress while waiting for an app to launch. |
| 168 | static final int LAUNCH_TICK = 500; |
| 169 | |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 170 | // How long we wait until giving up on the last activity to pause. This |
| 171 | // is short because it directly impacts the responsiveness of starting the |
| 172 | // next activity. |
| 173 | static final int PAUSE_TIMEOUT = 500; |
| 174 | |
Dianne Hackborn | 162bc0e | 2012-04-09 14:06:16 -0700 | [diff] [blame] | 175 | // How long we wait for the activity to tell us it has stopped before |
| 176 | // giving up. This is a good amount of time because we really need this |
| 177 | // from the application in order to get its saved state. |
Wale Ogunwale | e4a0c57 | 2015-06-30 08:40:31 -0700 | [diff] [blame] | 178 | static final int STOP_TIMEOUT = 10 * 1000; |
Dianne Hackborn | 162bc0e | 2012-04-09 14:06:16 -0700 | [diff] [blame] | 179 | |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 180 | // How long we wait until giving up on an activity telling us it has |
| 181 | // finished destroying itself. |
Wale Ogunwale | e4a0c57 | 2015-06-30 08:40:31 -0700 | [diff] [blame] | 182 | static final int DESTROY_TIMEOUT = 10 * 1000; |
Craig Mautner | d74f7d7 | 2013-02-26 13:41:02 -0800 | [diff] [blame] | 183 | |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 184 | // 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] | 185 | // disabled. |
| 186 | static final long ACTIVITY_INACTIVE_RESET_TIME = 0; |
Craig Mautner | d74f7d7 | 2013-02-26 13:41:02 -0800 | [diff] [blame] | 187 | |
Dianne Hackborn | 0dad364 | 2010-09-09 21:25:35 -0700 | [diff] [blame] | 188 | // How long between activity launches that we consider safe to not warn |
| 189 | // the user about an unexpected activity being launched on top. |
Wale Ogunwale | e4a0c57 | 2015-06-30 08:40:31 -0700 | [diff] [blame] | 190 | static final long START_WARN_TIME = 5 * 1000; |
Craig Mautner | d74f7d7 | 2013-02-26 13:41:02 -0800 | [diff] [blame] | 191 | |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 192 | // Set to false to disable the preview that is shown while a new activity |
| 193 | // is being started. |
| 194 | static final boolean SHOW_APP_STARTING_PREVIEW = true; |
Craig Mautner | 5d9c7be | 2013-02-15 14:02:56 -0800 | [diff] [blame] | 195 | |
Craig Mautner | 5eda9b3 | 2013-07-02 11:58:16 -0700 | [diff] [blame] | 196 | // How long to wait for all background Activities to redraw following a call to |
| 197 | // convertToTranslucent(). |
| 198 | static final long TRANSLUCENT_CONVERSION_TIMEOUT = 2000; |
| 199 | |
Filip Gruszczynski | ef2f72b | 2015-12-04 14:52:25 -0800 | [diff] [blame] | 200 | // How many activities have to be scheduled to stop to force a stop pass. |
| 201 | private static final int MAX_STOPPING_TO_FORCE = 3; |
| 202 | |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 203 | enum ActivityState { |
| 204 | INITIALIZING, |
| 205 | RESUMED, |
| 206 | PAUSING, |
| 207 | PAUSED, |
| 208 | STOPPING, |
| 209 | STOPPED, |
| 210 | FINISHING, |
| 211 | DESTROYING, |
| 212 | DESTROYED |
| 213 | } |
| 214 | |
Filip Gruszczynski | 0e381e2 | 2016-01-14 16:31:33 -0800 | [diff] [blame] | 215 | // Stack is not considered visible. |
| 216 | static final int STACK_INVISIBLE = 0; |
| 217 | // Stack is considered visible |
| 218 | static final int STACK_VISIBLE = 1; |
| 219 | // Stack is considered visible, but only becuase it has activity that is visible behind other |
| 220 | // activities and there is a specific combination of stacks. |
| 221 | static final int STACK_VISIBLE_ACTIVITY_BEHIND = 2; |
| 222 | |
Wale Ogunwale | 06579d6 | 2016-04-30 15:29:06 -0700 | [diff] [blame] | 223 | /* The various modes for the method {@link #removeTask}. */ |
| 224 | // Task is being completely removed from all stacks in the system. |
| 225 | static final int REMOVE_TASK_MODE_DESTROYING = 0; |
| 226 | // Task is being removed from this stack so we can add it to another stack. In the case we are |
| 227 | // moving we don't want to perform some operations on the task like removing it from window |
| 228 | // manager or recents. |
| 229 | static final int REMOVE_TASK_MODE_MOVING = 1; |
| 230 | // Similar to {@link #REMOVE_TASK_MODE_MOVING} and the task will be added to the top of its new |
| 231 | // stack and the new stack will be on top of all stacks. |
| 232 | static final int REMOVE_TASK_MODE_MOVING_TO_TOP = 2; |
| 233 | |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 234 | final ActivityManagerService mService; |
Craig Mautner | ce5f3cb | 2013-04-22 08:58:54 -0700 | [diff] [blame] | 235 | final WindowManagerService mWindowManager; |
Wale Ogunwale | c82f2f5 | 2014-12-09 09:32:50 -0800 | [diff] [blame] | 236 | private final RecentTasks mRecentTasks; |
Craig Mautner | d74f7d7 | 2013-02-26 13:41:02 -0800 | [diff] [blame] | 237 | |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 238 | /** |
| 239 | * The back history of all previous (and possibly still |
Craig Mautner | 5d9c7be | 2013-02-15 14:02:56 -0800 | [diff] [blame] | 240 | * running) activities. It contains #TaskRecord objects. |
| 241 | */ |
Todd Kennedy | 39bfee5 | 2016-02-24 10:28:21 -0800 | [diff] [blame] | 242 | private final ArrayList<TaskRecord> mTaskHistory = new ArrayList<>(); |
Craig Mautner | 5d9c7be | 2013-02-15 14:02:56 -0800 | [diff] [blame] | 243 | |
| 244 | /** |
Dianne Hackborn | be70785 | 2011-11-11 14:32:10 -0800 | [diff] [blame] | 245 | * Used for validating app tokens with window manager. |
| 246 | */ |
Wale Ogunwale | 53a29a9 | 2015-02-23 15:42:52 -0800 | [diff] [blame] | 247 | final ArrayList<TaskGroup> mValidateAppTokens = new ArrayList<>(); |
Dianne Hackborn | be70785 | 2011-11-11 14:32:10 -0800 | [diff] [blame] | 248 | |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 249 | /** |
| 250 | * List of running activities, sorted by recent usage. |
| 251 | * The first entry in the list is the least recently used. |
| 252 | * It contains HistoryRecord objects. |
| 253 | */ |
Wale Ogunwale | 53a29a9 | 2015-02-23 15:42:52 -0800 | [diff] [blame] | 254 | final ArrayList<ActivityRecord> mLRUActivities = new ArrayList<>(); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 255 | |
| 256 | /** |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 257 | * Animations that for the current transition have requested not to |
| 258 | * be considered for the transition animation. |
| 259 | */ |
Wale Ogunwale | 53a29a9 | 2015-02-23 15:42:52 -0800 | [diff] [blame] | 260 | final ArrayList<ActivityRecord> mNoAnimActivities = new ArrayList<>(); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 261 | |
| 262 | /** |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 263 | * When we are in the process of pausing an activity, before starting the |
| 264 | * next one, this variable holds the activity that is currently being paused. |
| 265 | */ |
Dianne Hackborn | 621e2fe | 2012-02-16 17:07:33 -0800 | [diff] [blame] | 266 | ActivityRecord mPausingActivity = null; |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 267 | |
| 268 | /** |
| 269 | * This is the last activity that we put into the paused state. This is |
| 270 | * used to determine if we need to do an activity transition while sleeping, |
| 271 | * when we normally hold the top activity paused. |
| 272 | */ |
| 273 | ActivityRecord mLastPausedActivity = null; |
| 274 | |
| 275 | /** |
Craig Mautner | 0f92274 | 2013-08-06 08:44:42 -0700 | [diff] [blame] | 276 | * Activities that specify No History must be removed once the user navigates away from them. |
| 277 | * If the device goes to sleep with such an activity in the paused state then we save it here |
| 278 | * and finish it later if another activity replaces it on wakeup. |
| 279 | */ |
| 280 | ActivityRecord mLastNoHistoryActivity = null; |
| 281 | |
| 282 | /** |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 283 | * Current activity that is resumed, or null if there is none. |
| 284 | */ |
| 285 | ActivityRecord mResumedActivity = null; |
Craig Mautner | d74f7d7 | 2013-02-26 13:41:02 -0800 | [diff] [blame] | 286 | |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 287 | /** |
Dianne Hackborn | 0dad364 | 2010-09-09 21:25:35 -0700 | [diff] [blame] | 288 | * This is the last activity that has been started. It is only used to |
| 289 | * identify when multiple activities are started at once so that the user |
| 290 | * can be warned they may not be in the activity they think they are. |
| 291 | */ |
| 292 | ActivityRecord mLastStartedActivity = null; |
Craig Mautner | d74f7d7 | 2013-02-26 13:41:02 -0800 | [diff] [blame] | 293 | |
Craig Mautner | 5eda9b3 | 2013-07-02 11:58:16 -0700 | [diff] [blame] | 294 | // The topmost Activity passed to convertToTranslucent(). When non-null it means we are |
| 295 | // waiting for all Activities in mUndrawnActivitiesBelowTopTranslucent to be removed as they |
| 296 | // are drawn. When the last member of mUndrawnActivitiesBelowTopTranslucent is removed the |
| 297 | // Activity in mTranslucentActivityWaiting is notified via |
| 298 | // Activity.onTranslucentConversionComplete(false). If a timeout occurs prior to the last |
| 299 | // background activity being drawn then the same call will be made with a true value. |
| 300 | ActivityRecord mTranslucentActivityWaiting = null; |
Wale Ogunwale | e4a0c57 | 2015-06-30 08:40:31 -0700 | [diff] [blame] | 301 | private ArrayList<ActivityRecord> mUndrawnActivitiesBelowTopTranslucent = new ArrayList<>(); |
Craig Mautner | 5eda9b3 | 2013-07-02 11:58:16 -0700 | [diff] [blame] | 302 | |
Dianne Hackborn | 0dad364 | 2010-09-09 21:25:35 -0700 | [diff] [blame] | 303 | /** |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 304 | * Set when we know we are going to be calling updateConfiguration() |
| 305 | * soon, so want to skip intermediate config checks. |
| 306 | */ |
| 307 | boolean mConfigWillChange; |
| 308 | |
Wale Ogunwale | e4a0c57 | 2015-06-30 08:40:31 -0700 | [diff] [blame] | 309 | // 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] | 310 | boolean mFullscreen = true; |
Wale Ogunwale | b34a7ad | 2015-08-14 11:05:30 -0700 | [diff] [blame] | 311 | // Current bounds of the stack or null if fullscreen. |
| 312 | Rect mBounds = null; |
Todd Kennedy | aab56db | 2015-01-30 09:39:53 -0800 | [diff] [blame] | 313 | |
Jorim Jaggi | 192086e | 2016-03-11 17:17:03 +0100 | [diff] [blame] | 314 | boolean mUpdateBoundsDeferred; |
| 315 | boolean mUpdateBoundsDeferredCalled; |
| 316 | final Rect mDeferredBounds = new Rect(); |
| 317 | final Rect mDeferredTaskBounds = new Rect(); |
| 318 | final Rect mDeferredTaskInsetBounds = new Rect(); |
| 319 | |
Dianne Hackborn | 2286cdc | 2013-07-01 19:10:06 -0700 | [diff] [blame] | 320 | long mLaunchStartTime = 0; |
| 321 | long mFullyDrawnStartTime = 0; |
Craig Mautner | d74f7d7 | 2013-02-26 13:41:02 -0800 | [diff] [blame] | 322 | |
Craig Mautner | 858d8a6 | 2013-04-23 17:08:34 -0700 | [diff] [blame] | 323 | int mCurrentUser; |
Amith Yamasani | 742a671 | 2011-05-04 14:49:28 -0700 | [diff] [blame] | 324 | |
Craig Mautner | c00204b | 2013-03-05 15:02:14 -0800 | [diff] [blame] | 325 | final int mStackId; |
Craig Mautner | 4a1cb22 | 2013-12-04 16:14:06 -0800 | [diff] [blame] | 326 | final ActivityContainer mActivityContainer; |
Craig Mautner | e0a3884 | 2013-12-16 16:14:02 -0800 | [diff] [blame] | 327 | /** The other stacks, in order, on the attached display. Updated at attach/detach time. */ |
| 328 | ArrayList<ActivityStack> mStacks; |
| 329 | /** The attached Display's unique identifier, or -1 if detached */ |
| 330 | int mDisplayId; |
Craig Mautner | 4a1cb22 | 2013-12-04 16:14:06 -0800 | [diff] [blame] | 331 | |
Craig Mautner | 2708430 | 2013-03-25 08:05:25 -0700 | [diff] [blame] | 332 | /** Run all ActivityStacks through this */ |
| 333 | final ActivityStackSupervisor mStackSupervisor; |
| 334 | |
Filip Gruszczynski | e5390e7 | 2015-08-18 16:39:00 -0700 | [diff] [blame] | 335 | private final LaunchingTaskPositioner mTaskPositioner; |
| 336 | |
Craig Mautner | 7ea5bd4 | 2013-07-05 15:27:08 -0700 | [diff] [blame] | 337 | static final int PAUSE_TIMEOUT_MSG = ActivityManagerService.FIRST_ACTIVITY_STACK_MSG + 1; |
Craig Mautner | 0eea92c | 2013-05-16 13:35:39 -0700 | [diff] [blame] | 338 | static final int DESTROY_TIMEOUT_MSG = ActivityManagerService.FIRST_ACTIVITY_STACK_MSG + 2; |
| 339 | static final int LAUNCH_TICK_MSG = ActivityManagerService.FIRST_ACTIVITY_STACK_MSG + 3; |
| 340 | static final int STOP_TIMEOUT_MSG = ActivityManagerService.FIRST_ACTIVITY_STACK_MSG + 4; |
| 341 | static final int DESTROY_ACTIVITIES_MSG = ActivityManagerService.FIRST_ACTIVITY_STACK_MSG + 5; |
Craig Mautner | 5eda9b3 | 2013-07-02 11:58:16 -0700 | [diff] [blame] | 342 | static final int TRANSLUCENT_TIMEOUT_MSG = ActivityManagerService.FIRST_ACTIVITY_STACK_MSG + 6; |
Jose Lima | 4b6c669 | 2014-08-12 17:41:12 -0700 | [diff] [blame] | 343 | static final int RELEASE_BACKGROUND_RESOURCES_TIMEOUT_MSG = |
Craig Mautner | ee2e45a | 2014-06-27 12:10:03 -0700 | [diff] [blame] | 344 | ActivityManagerService.FIRST_ACTIVITY_STACK_MSG + 7; |
Dianne Hackborn | 755c8bf | 2012-05-07 15:06:09 -0700 | [diff] [blame] | 345 | |
| 346 | static class ScheduleDestroyArgs { |
| 347 | final ProcessRecord mOwner; |
Dianne Hackborn | 755c8bf | 2012-05-07 15:06:09 -0700 | [diff] [blame] | 348 | final String mReason; |
Craig Mautner | ee2e45a | 2014-06-27 12:10:03 -0700 | [diff] [blame] | 349 | ScheduleDestroyArgs(ProcessRecord owner, String reason) { |
Dianne Hackborn | 755c8bf | 2012-05-07 15:06:09 -0700 | [diff] [blame] | 350 | mOwner = owner; |
Dianne Hackborn | 755c8bf | 2012-05-07 15:06:09 -0700 | [diff] [blame] | 351 | mReason = reason; |
| 352 | } |
| 353 | } |
| 354 | |
Zoran Marceta | f958b32 | 2012-08-09 20:27:12 +0900 | [diff] [blame] | 355 | final Handler mHandler; |
| 356 | |
| 357 | final class ActivityStackHandler extends Handler { |
Wale Ogunwale | e23149f | 2015-03-06 15:39:44 -0800 | [diff] [blame] | 358 | |
Craig Mautner | c8143c6 | 2013-09-03 12:15:57 -0700 | [diff] [blame] | 359 | ActivityStackHandler(Looper looper) { |
Zoran Marceta | f958b32 | 2012-08-09 20:27:12 +0900 | [diff] [blame] | 360 | super(looper); |
| 361 | } |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 362 | |
Zoran Marceta | f958b32 | 2012-08-09 20:27:12 +0900 | [diff] [blame] | 363 | @Override |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 364 | public void handleMessage(Message msg) { |
| 365 | switch (msg.what) { |
| 366 | case PAUSE_TIMEOUT_MSG: { |
Dianne Hackborn | be70785 | 2011-11-11 14:32:10 -0800 | [diff] [blame] | 367 | ActivityRecord r = (ActivityRecord)msg.obj; |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 368 | // We don't at this point know if the activity is fullscreen, |
| 369 | // so we need to be conservative and assume it isn't. |
Dianne Hackborn | be70785 | 2011-11-11 14:32:10 -0800 | [diff] [blame] | 370 | Slog.w(TAG, "Activity pause timeout for " + r); |
Dianne Hackborn | 2a29b3a | 2012-03-15 15:48:38 -0700 | [diff] [blame] | 371 | synchronized (mService) { |
| 372 | if (r.app != null) { |
Craig Mautner | f7bfefb | 2013-05-16 17:30:44 -0700 | [diff] [blame] | 373 | mService.logAppTooSlow(r.app, r.pauseTime, "pausing " + r); |
Dianne Hackborn | 2a29b3a | 2012-03-15 15:48:38 -0700 | [diff] [blame] | 374 | } |
Dianne Hackborn | a4e102e | 2014-09-04 22:52:27 -0700 | [diff] [blame] | 375 | activityPausedLocked(r.appToken, true); |
Craig Mautner | d232895 | 2013-03-05 12:46:26 -0800 | [diff] [blame] | 376 | } |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 377 | } break; |
Dianne Hackborn | 2a29b3a | 2012-03-15 15:48:38 -0700 | [diff] [blame] | 378 | case LAUNCH_TICK_MSG: { |
| 379 | ActivityRecord r = (ActivityRecord)msg.obj; |
| 380 | synchronized (mService) { |
| 381 | if (r.continueLaunchTickingLocked()) { |
Craig Mautner | f7bfefb | 2013-05-16 17:30:44 -0700 | [diff] [blame] | 382 | mService.logAppTooSlow(r.app, r.launchTickTime, "launching " + r); |
Dianne Hackborn | 2a29b3a | 2012-03-15 15:48:38 -0700 | [diff] [blame] | 383 | } |
| 384 | } |
| 385 | } break; |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 386 | case DESTROY_TIMEOUT_MSG: { |
Dianne Hackborn | be70785 | 2011-11-11 14:32:10 -0800 | [diff] [blame] | 387 | ActivityRecord r = (ActivityRecord)msg.obj; |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 388 | // We don't at this point know if the activity is fullscreen, |
| 389 | // so we need to be conservative and assume it isn't. |
Dianne Hackborn | be70785 | 2011-11-11 14:32:10 -0800 | [diff] [blame] | 390 | Slog.w(TAG, "Activity destroy timeout for " + r); |
Craig Mautner | d232895 | 2013-03-05 12:46:26 -0800 | [diff] [blame] | 391 | synchronized (mService) { |
Craig Mautner | 299f960 | 2015-01-26 09:47:33 -0800 | [diff] [blame] | 392 | activityDestroyedLocked(r != null ? r.appToken : null, "destroyTimeout"); |
Craig Mautner | d232895 | 2013-03-05 12:46:26 -0800 | [diff] [blame] | 393 | } |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 394 | } break; |
Dianne Hackborn | 162bc0e | 2012-04-09 14:06:16 -0700 | [diff] [blame] | 395 | case STOP_TIMEOUT_MSG: { |
| 396 | ActivityRecord r = (ActivityRecord)msg.obj; |
| 397 | // We don't at this point know if the activity is fullscreen, |
| 398 | // so we need to be conservative and assume it isn't. |
| 399 | Slog.w(TAG, "Activity stop timeout for " + r); |
| 400 | synchronized (mService) { |
| 401 | if (r.isInHistory()) { |
| 402 | activityStoppedLocked(r, null, null, null); |
| 403 | } |
| 404 | } |
| 405 | } break; |
Dianne Hackborn | 755c8bf | 2012-05-07 15:06:09 -0700 | [diff] [blame] | 406 | case DESTROY_ACTIVITIES_MSG: { |
| 407 | ScheduleDestroyArgs args = (ScheduleDestroyArgs)msg.obj; |
| 408 | synchronized (mService) { |
Craig Mautner | ee2e45a | 2014-06-27 12:10:03 -0700 | [diff] [blame] | 409 | destroyActivitiesLocked(args.mOwner, args.mReason); |
Dianne Hackborn | 755c8bf | 2012-05-07 15:06:09 -0700 | [diff] [blame] | 410 | } |
Craig Mautner | 5eda9b3 | 2013-07-02 11:58:16 -0700 | [diff] [blame] | 411 | } break; |
| 412 | case TRANSLUCENT_TIMEOUT_MSG: { |
| 413 | synchronized (mService) { |
| 414 | notifyActivityDrawnLocked(null); |
| 415 | } |
| 416 | } break; |
Jose Lima | 4b6c669 | 2014-08-12 17:41:12 -0700 | [diff] [blame] | 417 | case RELEASE_BACKGROUND_RESOURCES_TIMEOUT_MSG: { |
Craig Mautner | ee2e45a | 2014-06-27 12:10:03 -0700 | [diff] [blame] | 418 | synchronized (mService) { |
Jose Lima | 4b6c669 | 2014-08-12 17:41:12 -0700 | [diff] [blame] | 419 | final ActivityRecord r = getVisibleBehindActivity(); |
| 420 | Slog.e(TAG, "Timeout waiting for cancelVisibleBehind player=" + r); |
Craig Mautner | ee2e45a | 2014-06-27 12:10:03 -0700 | [diff] [blame] | 421 | if (r != null) { |
| 422 | mService.killAppAtUsersRequest(r.app, null); |
| 423 | } |
| 424 | } |
| 425 | } break; |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 426 | } |
| 427 | } |
Craig Mautner | 4b71aa1 | 2012-12-27 17:20:01 -0800 | [diff] [blame] | 428 | } |
| 429 | |
Craig Mautner | 34b73df | 2014-01-12 21:11:08 -0800 | [diff] [blame] | 430 | int numActivities() { |
Craig Mautner | 000f002 | 2013-02-26 15:04:29 -0800 | [diff] [blame] | 431 | int count = 0; |
| 432 | for (int taskNdx = mTaskHistory.size() - 1; taskNdx >= 0; --taskNdx) { |
| 433 | count += mTaskHistory.get(taskNdx).mActivities.size(); |
| 434 | } |
| 435 | return count; |
| 436 | } |
| 437 | |
Wale Ogunwale | c82f2f5 | 2014-12-09 09:32:50 -0800 | [diff] [blame] | 438 | ActivityStack(ActivityStackSupervisor.ActivityContainer activityContainer, |
| 439 | RecentTasks recentTasks) { |
Craig Mautner | 4a1cb22 | 2013-12-04 16:14:06 -0800 | [diff] [blame] | 440 | mActivityContainer = activityContainer; |
| 441 | mStackSupervisor = activityContainer.getOuter(); |
| 442 | mService = mStackSupervisor.mService; |
| 443 | mHandler = new ActivityStackHandler(mService.mHandler.getLooper()); |
| 444 | mWindowManager = mService.mWindowManager; |
| 445 | mStackId = activityContainer.mStackId; |
Fyodor Kupolov | f63b89c | 2015-10-27 18:08:56 -0700 | [diff] [blame] | 446 | mCurrentUser = mService.mUserController.getCurrentUserIdLocked(); |
Wale Ogunwale | c82f2f5 | 2014-12-09 09:32:50 -0800 | [diff] [blame] | 447 | mRecentTasks = recentTasks; |
Filip Gruszczynski | e5390e7 | 2015-08-18 16:39:00 -0700 | [diff] [blame] | 448 | mTaskPositioner = mStackId == FREEFORM_WORKSPACE_STACK_ID |
| 449 | ? new LaunchingTaskPositioner() : null; |
| 450 | } |
| 451 | |
| 452 | void attachDisplay(ActivityStackSupervisor.ActivityDisplay activityDisplay, boolean onTop) { |
| 453 | mDisplayId = activityDisplay.mDisplayId; |
| 454 | mStacks = activityDisplay.mStacks; |
| 455 | mBounds = mWindowManager.attachStack(mStackId, activityDisplay.mDisplayId, onTop); |
| 456 | mFullscreen = mBounds == null; |
| 457 | if (mTaskPositioner != null) { |
| 458 | mTaskPositioner.setDisplay(activityDisplay.mDisplay); |
| 459 | mTaskPositioner.configure(mBounds); |
| 460 | } |
Wale Ogunwale | 961f485 | 2016-02-01 20:25:54 -0800 | [diff] [blame] | 461 | |
| 462 | if (mStackId == DOCKED_STACK_ID) { |
| 463 | // If we created a docked stack we want to resize it so it resizes all other stacks |
| 464 | // in the system. |
| 465 | mStackSupervisor.resizeDockedStackLocked( |
| 466 | mBounds, null, null, null, null, PRESERVE_WINDOWS); |
| 467 | } |
Filip Gruszczynski | e5390e7 | 2015-08-18 16:39:00 -0700 | [diff] [blame] | 468 | } |
| 469 | |
| 470 | void detachDisplay() { |
| 471 | mDisplayId = Display.INVALID_DISPLAY; |
| 472 | mStacks = null; |
| 473 | if (mTaskPositioner != null) { |
| 474 | mTaskPositioner.reset(); |
| 475 | } |
| 476 | mWindowManager.detachStack(mStackId); |
Jorim Jaggi | 899327f | 2016-02-25 20:44:18 -0500 | [diff] [blame] | 477 | if (mStackId == DOCKED_STACK_ID) { |
| 478 | // If we removed a docked stack we want to resize it so it resizes all other stacks |
| 479 | // in the system to fullscreen. |
| 480 | mStackSupervisor.resizeDockedStackLocked( |
| 481 | null, null, null, null, null, PRESERVE_WINDOWS); |
| 482 | } |
Filip Gruszczynski | e5390e7 | 2015-08-18 16:39:00 -0700 | [diff] [blame] | 483 | } |
| 484 | |
Winson | c809cbb | 2015-11-02 12:06:15 -0800 | [diff] [blame] | 485 | public void getDisplaySize(Point out) { |
| 486 | mActivityContainer.mActivityDisplay.mDisplay.getSize(out); |
| 487 | } |
| 488 | |
Jorim Jaggi | 192086e | 2016-03-11 17:17:03 +0100 | [diff] [blame] | 489 | /** |
| 490 | * Defers updating the bounds of the stack. If the stack was resized/repositioned while |
| 491 | * deferring, the bounds will update in {@link #continueUpdateBounds()}. |
| 492 | */ |
| 493 | void deferUpdateBounds() { |
| 494 | if (!mUpdateBoundsDeferred) { |
| 495 | mUpdateBoundsDeferred = true; |
| 496 | mUpdateBoundsDeferredCalled = false; |
| 497 | } |
| 498 | } |
| 499 | |
| 500 | /** |
| 501 | * Continues updating bounds after updates have been deferred. If there was a resize attempt |
| 502 | * between {@link #deferUpdateBounds()} and {@link #continueUpdateBounds()}, the stack will |
| 503 | * be resized to that bounds. |
| 504 | */ |
| 505 | void continueUpdateBounds() { |
| 506 | final boolean wasDeferred = mUpdateBoundsDeferred; |
| 507 | mUpdateBoundsDeferred = false; |
| 508 | if (wasDeferred && mUpdateBoundsDeferredCalled) { |
| 509 | mStackSupervisor.resizeStackUncheckedLocked(this, |
| 510 | mDeferredBounds.isEmpty() ? null : mDeferredBounds, |
| 511 | mDeferredTaskBounds.isEmpty() ? null : mDeferredTaskBounds, |
| 512 | mDeferredTaskInsetBounds.isEmpty() ? null : mDeferredTaskInsetBounds); |
| 513 | } |
| 514 | } |
| 515 | |
| 516 | boolean updateBoundsAllowed(Rect bounds, Rect tempTaskBounds, |
| 517 | Rect tempTaskInsetBounds) { |
| 518 | if (!mUpdateBoundsDeferred) { |
| 519 | return true; |
| 520 | } |
| 521 | if (bounds != null) { |
| 522 | mDeferredBounds.set(bounds); |
| 523 | } else { |
| 524 | mDeferredBounds.setEmpty(); |
| 525 | } |
| 526 | if (tempTaskBounds != null) { |
| 527 | mDeferredTaskBounds.set(tempTaskBounds); |
| 528 | } else { |
| 529 | mDeferredTaskBounds.setEmpty(); |
| 530 | } |
| 531 | if (tempTaskInsetBounds != null) { |
| 532 | mDeferredTaskInsetBounds.set(tempTaskInsetBounds); |
| 533 | } else { |
| 534 | mDeferredTaskInsetBounds.setEmpty(); |
| 535 | } |
| 536 | mUpdateBoundsDeferredCalled = true; |
| 537 | return false; |
| 538 | } |
| 539 | |
Filip Gruszczynski | e5390e7 | 2015-08-18 16:39:00 -0700 | [diff] [blame] | 540 | void setBounds(Rect bounds) { |
| 541 | mBounds = mFullscreen ? null : new Rect(bounds); |
Filip Gruszczynski | 9ac01a7 | 2015-09-04 11:12:17 -0700 | [diff] [blame] | 542 | if (mTaskPositioner != null) { |
| 543 | mTaskPositioner.configure(bounds); |
| 544 | } |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 545 | } |
Craig Mautner | 5962b12 | 2012-10-05 14:45:52 -0700 | [diff] [blame] | 546 | |
Filip Gruszczynski | 3e85ba2 | 2015-10-05 22:48:30 -0700 | [diff] [blame] | 547 | final ActivityRecord topRunningActivityLocked() { |
Craig Mautner | d74f7d7 | 2013-02-26 13:41:02 -0800 | [diff] [blame] | 548 | for (int taskNdx = mTaskHistory.size() - 1; taskNdx >= 0; --taskNdx) { |
Filip Gruszczynski | 3e85ba2 | 2015-10-05 22:48:30 -0700 | [diff] [blame] | 549 | ActivityRecord r = mTaskHistory.get(taskNdx).topRunningActivityLocked(); |
Craig Mautner | 6b74cb5 | 2013-09-27 17:02:21 -0700 | [diff] [blame] | 550 | if (r != null) { |
| 551 | return r; |
Craig Mautner | 11bf9a5 | 2013-02-19 14:08:51 -0800 | [diff] [blame] | 552 | } |
| 553 | } |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 554 | return null; |
| 555 | } |
| 556 | |
| 557 | final ActivityRecord topRunningNonDelayedActivityLocked(ActivityRecord notTop) { |
Craig Mautner | d74f7d7 | 2013-02-26 13:41:02 -0800 | [diff] [blame] | 558 | for (int taskNdx = mTaskHistory.size() - 1; taskNdx >= 0; --taskNdx) { |
| 559 | final TaskRecord task = mTaskHistory.get(taskNdx); |
Craig Mautner | 11bf9a5 | 2013-02-19 14:08:51 -0800 | [diff] [blame] | 560 | final ArrayList<ActivityRecord> activities = task.mActivities; |
Craig Mautner | d74f7d7 | 2013-02-26 13:41:02 -0800 | [diff] [blame] | 561 | for (int activityNdx = activities.size() - 1; activityNdx >= 0; --activityNdx) { |
| 562 | ActivityRecord r = activities.get(activityNdx); |
Chong Zhang | 8776197 | 2016-08-22 13:53:24 -0700 | [diff] [blame^] | 563 | if (!r.finishing && !r.delayedResume && r != notTop && r.okToShowLocked()) { |
Craig Mautner | 11bf9a5 | 2013-02-19 14:08:51 -0800 | [diff] [blame] | 564 | return r; |
| 565 | } |
| 566 | } |
| 567 | } |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 568 | return null; |
| 569 | } |
| 570 | |
| 571 | /** |
| 572 | * This is a simplified version of topRunningActivityLocked that provides a number of |
| 573 | * 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] | 574 | * |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 575 | * @param token If non-null, any history records matching this token will be skipped. |
| 576 | * @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] | 577 | * |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 578 | * @return Returns the HistoryRecord of the next activity on the stack. |
| 579 | */ |
| 580 | final ActivityRecord topRunningActivityLocked(IBinder token, int taskId) { |
Craig Mautner | 11bf9a5 | 2013-02-19 14:08:51 -0800 | [diff] [blame] | 581 | for (int taskNdx = mTaskHistory.size() - 1; taskNdx >= 0; --taskNdx) { |
| 582 | TaskRecord task = mTaskHistory.get(taskNdx); |
| 583 | if (task.taskId == taskId) { |
| 584 | continue; |
| 585 | } |
| 586 | ArrayList<ActivityRecord> activities = task.mActivities; |
| 587 | for (int i = activities.size() - 1; i >= 0; --i) { |
| 588 | final ActivityRecord r = activities.get(i); |
| 589 | // Note: the taskId check depends on real taskId fields being non-zero |
Chong Zhang | 8776197 | 2016-08-22 13:53:24 -0700 | [diff] [blame^] | 590 | if (!r.finishing && (token != r.appToken) && r.okToShowLocked()) { |
Craig Mautner | 11bf9a5 | 2013-02-19 14:08:51 -0800 | [diff] [blame] | 591 | return r; |
| 592 | } |
| 593 | } |
| 594 | } |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 595 | return null; |
| 596 | } |
| 597 | |
Craig Mautner | 8849a5e | 2013-04-02 16:41:03 -0700 | [diff] [blame] | 598 | final ActivityRecord topActivity() { |
Craig Mautner | 8849a5e | 2013-04-02 16:41:03 -0700 | [diff] [blame] | 599 | for (int taskNdx = mTaskHistory.size() - 1; taskNdx >= 0; --taskNdx) { |
| 600 | ArrayList<ActivityRecord> activities = mTaskHistory.get(taskNdx).mActivities; |
Craig Mautner | 0175b88 | 2014-09-07 18:05:31 -0700 | [diff] [blame] | 601 | for (int activityNdx = activities.size() - 1; activityNdx >= 0; --activityNdx) { |
| 602 | final ActivityRecord r = activities.get(activityNdx); |
| 603 | if (!r.finishing) { |
| 604 | return r; |
| 605 | } |
Craig Mautner | 8849a5e | 2013-04-02 16:41:03 -0700 | [diff] [blame] | 606 | } |
| 607 | } |
Craig Mautner | de4ef02 | 2013-04-07 19:01:33 -0700 | [diff] [blame] | 608 | return null; |
Craig Mautner | 8849a5e | 2013-04-02 16:41:03 -0700 | [diff] [blame] | 609 | } |
| 610 | |
Craig Mautner | 9e14d0f | 2013-05-01 11:26:09 -0700 | [diff] [blame] | 611 | final TaskRecord topTask() { |
| 612 | final int size = mTaskHistory.size(); |
| 613 | if (size > 0) { |
| 614 | return mTaskHistory.get(size - 1); |
| 615 | } |
| 616 | return null; |
| 617 | } |
| 618 | |
Craig Mautner | d232895 | 2013-03-05 12:46:26 -0800 | [diff] [blame] | 619 | TaskRecord taskForIdLocked(int id) { |
| 620 | for (int taskNdx = mTaskHistory.size() - 1; taskNdx >= 0; --taskNdx) { |
| 621 | final TaskRecord task = mTaskHistory.get(taskNdx); |
| 622 | if (task.taskId == id) { |
| 623 | return task; |
Craig Mautner | 5d9c7be | 2013-02-15 14:02:56 -0800 | [diff] [blame] | 624 | } |
| 625 | } |
Dianne Hackborn | ce86ba8 | 2011-07-13 19:33:41 -0700 | [diff] [blame] | 626 | return null; |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 627 | } |
| 628 | |
Craig Mautner | d232895 | 2013-03-05 12:46:26 -0800 | [diff] [blame] | 629 | ActivityRecord isInStackLocked(IBinder token) { |
Wale Ogunwale | 7d70117 | 2015-03-11 15:36:30 -0700 | [diff] [blame] | 630 | final ActivityRecord r = ActivityRecord.forTokenLocked(token); |
Wale Ogunwale | 60454db | 2015-01-23 16:05:07 -0800 | [diff] [blame] | 631 | return isInStackLocked(r); |
| 632 | } |
| 633 | |
| 634 | ActivityRecord isInStackLocked(ActivityRecord r) { |
| 635 | if (r == null) { |
| 636 | return null; |
| 637 | } |
| 638 | final TaskRecord task = r.task; |
Wale Ogunwale | 7d70117 | 2015-03-11 15:36:30 -0700 | [diff] [blame] | 639 | if (task != null && task.stack != null |
| 640 | && task.mActivities.contains(r) && mTaskHistory.contains(task)) { |
Wale Ogunwale | 60454db | 2015-01-23 16:05:07 -0800 | [diff] [blame] | 641 | if (task.stack != this) Slog.w(TAG, |
Craig Mautner | d232895 | 2013-03-05 12:46:26 -0800 | [diff] [blame] | 642 | "Illegal state! task does not point to stack it is in."); |
Wale Ogunwale | 60454db | 2015-01-23 16:05:07 -0800 | [diff] [blame] | 643 | return r; |
Craig Mautner | 5d9c7be | 2013-02-15 14:02:56 -0800 | [diff] [blame] | 644 | } |
Craig Mautner | d232895 | 2013-03-05 12:46:26 -0800 | [diff] [blame] | 645 | return null; |
Craig Mautner | 5d9c7be | 2013-02-15 14:02:56 -0800 | [diff] [blame] | 646 | } |
| 647 | |
Craig Mautner | 2420ead | 2013-04-01 17:13:20 -0700 | [diff] [blame] | 648 | final boolean updateLRUListLocked(ActivityRecord r) { |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 649 | final boolean hadit = mLRUActivities.remove(r); |
| 650 | mLRUActivities.add(r); |
| 651 | return hadit; |
| 652 | } |
| 653 | |
Craig Mautner | de4ef02 | 2013-04-07 19:01:33 -0700 | [diff] [blame] | 654 | final boolean isHomeStack() { |
| 655 | return mStackId == HOME_STACK_ID; |
| 656 | } |
| 657 | |
Winson Chung | 0583d3d | 2015-12-18 10:03:12 -0500 | [diff] [blame] | 658 | final boolean isDockedStack() { |
| 659 | return mStackId == DOCKED_STACK_ID; |
| 660 | } |
| 661 | |
| 662 | final boolean isPinnedStack() { |
| 663 | return mStackId == PINNED_STACK_ID; |
| 664 | } |
| 665 | |
Craig Mautner | e0a3884 | 2013-12-16 16:14:02 -0800 | [diff] [blame] | 666 | final boolean isOnHomeDisplay() { |
| 667 | return isAttached() && |
| 668 | mActivityContainer.mActivityDisplay.mDisplayId == Display.DEFAULT_DISPLAY; |
| 669 | } |
| 670 | |
Wale Ogunwale | eae451e | 2015-08-04 15:20:50 -0700 | [diff] [blame] | 671 | void moveToFront(String reason) { |
| 672 | moveToFront(reason, null); |
| 673 | } |
| 674 | |
| 675 | /** |
| 676 | * @param reason The reason for moving the stack to the front. |
| 677 | * @param task If non-null, the task will be moved to the top of the stack. |
| 678 | * */ |
| 679 | void moveToFront(String reason, TaskRecord task) { |
Wale Ogunwale | 1e60e0c | 2015-10-28 13:36:10 -0700 | [diff] [blame] | 680 | if (!isAttached()) { |
| 681 | return; |
| 682 | } |
Wale Ogunwale | 925d0d1 | 2015-09-23 15:40:07 -0700 | [diff] [blame] | 683 | |
Wale Ogunwale | 1e60e0c | 2015-10-28 13:36:10 -0700 | [diff] [blame] | 684 | mStacks.remove(this); |
| 685 | int addIndex = mStacks.size(); |
| 686 | |
| 687 | if (addIndex > 0) { |
| 688 | final ActivityStack topStack = mStacks.get(addIndex - 1); |
Filip Gruszczynski | 114d5ca | 2015-12-04 09:05:00 -0800 | [diff] [blame] | 689 | if (StackId.isAlwaysOnTop(topStack.mStackId) && topStack != this) { |
| 690 | // If the top stack is always on top, we move this stack just below it. |
Wale Ogunwale | 1e60e0c | 2015-10-28 13:36:10 -0700 | [diff] [blame] | 691 | addIndex--; |
Wale Ogunwale | cb82f30 | 2015-02-25 07:53:40 -0800 | [diff] [blame] | 692 | } |
Wale Ogunwale | 1e60e0c | 2015-10-28 13:36:10 -0700 | [diff] [blame] | 693 | } |
| 694 | |
| 695 | mStacks.add(addIndex, this); |
| 696 | |
| 697 | // TODO(multi-display): Needs to also work if focus is moving to the non-home display. |
| 698 | if (isOnHomeDisplay()) { |
Wale Ogunwale | 4cea0f5 | 2015-12-25 06:30:31 -0800 | [diff] [blame] | 699 | mStackSupervisor.setFocusStackUnchecked(reason, this); |
Wale Ogunwale | 1e60e0c | 2015-10-28 13:36:10 -0700 | [diff] [blame] | 700 | } |
| 701 | if (task != null) { |
| 702 | insertTaskAtTop(task, null); |
| 703 | } else { |
| 704 | task = topTask(); |
| 705 | } |
| 706 | if (task != null) { |
| 707 | mWindowManager.moveTaskToTop(task.taskId); |
Craig Mautner | 4a1cb22 | 2013-12-04 16:14:06 -0800 | [diff] [blame] | 708 | } |
Craig Mautner | e0a3884 | 2013-12-16 16:14:02 -0800 | [diff] [blame] | 709 | } |
| 710 | |
Jiaquan He | e13e964 | 2016-06-15 15:16:13 -0700 | [diff] [blame] | 711 | /** |
| 712 | * @param task If non-null, the task will be moved to the back of the stack. |
| 713 | * */ |
| 714 | void moveToBack(TaskRecord task) { |
| 715 | if (!isAttached()) { |
| 716 | return; |
| 717 | } |
| 718 | |
| 719 | mStacks.remove(this); |
| 720 | mStacks.add(0, this); |
| 721 | |
| 722 | if (task != null) { |
| 723 | mTaskHistory.remove(task); |
| 724 | mTaskHistory.add(0, task); |
| 725 | updateTaskMovement(task, false); |
| 726 | mWindowManager.moveTaskToBottom(task.taskId); |
| 727 | } |
| 728 | } |
| 729 | |
Wale Ogunwale | d046a01 | 2015-12-24 13:05:59 -0800 | [diff] [blame] | 730 | boolean isFocusable() { |
Wale Ogunwale | 4cea0f5 | 2015-12-25 06:30:31 -0800 | [diff] [blame] | 731 | if (StackId.canReceiveKeys(mStackId)) { |
| 732 | return true; |
| 733 | } |
| 734 | // The stack isn't focusable. See if its top activity is focusable to force focus on the |
| 735 | // stack. |
| 736 | final ActivityRecord r = topRunningActivityLocked(); |
| 737 | return r != null && r.isFocusable(); |
Wale Ogunwale | d046a01 | 2015-12-24 13:05:59 -0800 | [diff] [blame] | 738 | } |
| 739 | |
Craig Mautner | e0a3884 | 2013-12-16 16:14:02 -0800 | [diff] [blame] | 740 | final boolean isAttached() { |
| 741 | return mStacks != null; |
Craig Mautner | 4a1cb22 | 2013-12-04 16:14:06 -0800 | [diff] [blame] | 742 | } |
| 743 | |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 744 | /** |
Wale Ogunwale | 3938197 | 2015-12-17 17:15:29 -0800 | [diff] [blame] | 745 | * Returns the top activity in any existing task matching the given Intent in the input result. |
| 746 | * Returns null if no such task is found. |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 747 | */ |
Wale Ogunwale | 3938197 | 2015-12-17 17:15:29 -0800 | [diff] [blame] | 748 | void findTaskLocked(ActivityRecord target, FindTaskResult result) { |
Craig Mautner | ac6f843 | 2013-07-17 13:24:59 -0700 | [diff] [blame] | 749 | Intent intent = target.intent; |
| 750 | ActivityInfo info = target.info; |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 751 | ComponentName cls = intent.getComponent(); |
| 752 | if (info.targetActivity != null) { |
| 753 | cls = new ComponentName(info.packageName, info.targetActivity); |
| 754 | } |
Dianne Hackborn | f02b60a | 2012-08-16 10:48:27 -0700 | [diff] [blame] | 755 | final int userId = UserHandle.getUserId(info.applicationInfo.uid); |
Craig Mautner | d00f474 | 2014-03-12 14:17:26 -0700 | [diff] [blame] | 756 | boolean isDocument = intent != null & intent.isDocument(); |
| 757 | // If documentData is non-null then it must match the existing task data. |
| 758 | Uri documentData = isDocument ? intent.getData() : null; |
Craig Mautner | 000f002 | 2013-02-26 15:04:29 -0800 | [diff] [blame] | 759 | |
Wale Ogunwale | ee006da | 2015-03-30 14:49:25 -0700 | [diff] [blame] | 760 | 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] | 761 | for (int taskNdx = mTaskHistory.size() - 1; taskNdx >= 0; --taskNdx) { |
| 762 | final TaskRecord task = mTaskHistory.get(taskNdx); |
Dianne Hackborn | 91097de | 2014-04-04 18:02:06 -0700 | [diff] [blame] | 763 | if (task.voiceSession != null) { |
| 764 | // We never match voice sessions; those always run independently. |
Wale Ogunwale | ee006da | 2015-03-30 14:49:25 -0700 | [diff] [blame] | 765 | if (DEBUG_TASKS) Slog.d(TAG_TASKS, "Skipping " + task + ": voice session"); |
Dianne Hackborn | 91097de | 2014-04-04 18:02:06 -0700 | [diff] [blame] | 766 | continue; |
| 767 | } |
Craig Mautner | ac6f843 | 2013-07-17 13:24:59 -0700 | [diff] [blame] | 768 | if (task.userId != userId) { |
| 769 | // Looking for a different task. |
Wale Ogunwale | ee006da | 2015-03-30 14:49:25 -0700 | [diff] [blame] | 770 | if (DEBUG_TASKS) Slog.d(TAG_TASKS, "Skipping " + task + ": different user"); |
Craig Mautner | ac6f843 | 2013-07-17 13:24:59 -0700 | [diff] [blame] | 771 | continue; |
| 772 | } |
Craig Mautner | 000f002 | 2013-02-26 15:04:29 -0800 | [diff] [blame] | 773 | final ActivityRecord r = task.getTopActivity(); |
| 774 | if (r == null || r.finishing || r.userId != userId || |
| 775 | r.launchMode == ActivityInfo.LAUNCH_SINGLE_INSTANCE) { |
Wale Ogunwale | ee006da | 2015-03-30 14:49:25 -0700 | [diff] [blame] | 776 | if (DEBUG_TASKS) Slog.d(TAG_TASKS, "Skipping " + task + ": mismatch root " + r); |
Craig Mautner | 000f002 | 2013-02-26 15:04:29 -0800 | [diff] [blame] | 777 | continue; |
| 778 | } |
Chong Zhang | b546f7e | 2015-08-05 14:21:36 -0700 | [diff] [blame] | 779 | if (r.mActivityType != target.mActivityType) { |
| 780 | if (DEBUG_TASKS) Slog.d(TAG_TASKS, "Skipping " + task + ": mismatch activity type"); |
| 781 | continue; |
| 782 | } |
Craig Mautner | 000f002 | 2013-02-26 15:04:29 -0800 | [diff] [blame] | 783 | |
Craig Mautner | d00f474 | 2014-03-12 14:17:26 -0700 | [diff] [blame] | 784 | final Intent taskIntent = task.intent; |
| 785 | final Intent affinityIntent = task.affinityIntent; |
| 786 | final boolean taskIsDocument; |
| 787 | final Uri taskDocumentData; |
| 788 | if (taskIntent != null && taskIntent.isDocument()) { |
| 789 | taskIsDocument = true; |
| 790 | taskDocumentData = taskIntent.getData(); |
| 791 | } else if (affinityIntent != null && affinityIntent.isDocument()) { |
| 792 | taskIsDocument = true; |
| 793 | taskDocumentData = affinityIntent.getData(); |
| 794 | } else { |
| 795 | taskIsDocument = false; |
| 796 | taskDocumentData = null; |
| 797 | } |
| 798 | |
Wale Ogunwale | ee006da | 2015-03-30 14:49:25 -0700 | [diff] [blame] | 799 | if (DEBUG_TASKS) Slog.d(TAG_TASKS, "Comparing existing cls=" |
Craig Mautner | d00f474 | 2014-03-12 14:17:26 -0700 | [diff] [blame] | 800 | + taskIntent.getComponent().flattenToShortString() |
Dianne Hackborn | 7922882 | 2014-09-16 11:11:23 -0700 | [diff] [blame] | 801 | + "/aff=" + r.task.rootAffinity + " to new cls=" |
Dianne Hackborn | 2a272d4 | 2013-10-16 13:34:33 -0700 | [diff] [blame] | 802 | + intent.getComponent().flattenToShortString() + "/aff=" + info.taskAffinity); |
Andrii Kulian | 206b9fa | 2016-06-02 13:18:01 -0700 | [diff] [blame] | 803 | // TODO Refactor to remove duplications. Check if logic can be simplified. |
| 804 | if (taskIntent != null && taskIntent.getComponent() != null && |
Craig Mautner | ffcfcaa | 2014-06-05 09:54:38 -0700 | [diff] [blame] | 805 | taskIntent.getComponent().compareTo(cls) == 0 && |
Craig Mautner | d00f474 | 2014-03-12 14:17:26 -0700 | [diff] [blame] | 806 | Objects.equals(documentData, taskDocumentData)) { |
Wale Ogunwale | ee006da | 2015-03-30 14:49:25 -0700 | [diff] [blame] | 807 | if (DEBUG_TASKS) Slog.d(TAG_TASKS, "Found matching class!"); |
Craig Mautner | 000f002 | 2013-02-26 15:04:29 -0800 | [diff] [blame] | 808 | //dump(); |
Wale Ogunwale | ee006da | 2015-03-30 14:49:25 -0700 | [diff] [blame] | 809 | if (DEBUG_TASKS) Slog.d(TAG_TASKS, |
| 810 | "For Intent " + intent + " bringing to top: " + r.intent); |
Wale Ogunwale | 3938197 | 2015-12-17 17:15:29 -0800 | [diff] [blame] | 811 | result.r = r; |
| 812 | result.matchedByRootAffinity = false; |
| 813 | break; |
Craig Mautner | ffcfcaa | 2014-06-05 09:54:38 -0700 | [diff] [blame] | 814 | } else if (affinityIntent != null && affinityIntent.getComponent() != null && |
| 815 | affinityIntent.getComponent().compareTo(cls) == 0 && |
Craig Mautner | d00f474 | 2014-03-12 14:17:26 -0700 | [diff] [blame] | 816 | Objects.equals(documentData, taskDocumentData)) { |
Wale Ogunwale | ee006da | 2015-03-30 14:49:25 -0700 | [diff] [blame] | 817 | if (DEBUG_TASKS) Slog.d(TAG_TASKS, "Found matching class!"); |
Craig Mautner | 000f002 | 2013-02-26 15:04:29 -0800 | [diff] [blame] | 818 | //dump(); |
Wale Ogunwale | ee006da | 2015-03-30 14:49:25 -0700 | [diff] [blame] | 819 | if (DEBUG_TASKS) Slog.d(TAG_TASKS, |
| 820 | "For Intent " + intent + " bringing to top: " + r.intent); |
Wale Ogunwale | 3938197 | 2015-12-17 17:15:29 -0800 | [diff] [blame] | 821 | result.r = r; |
| 822 | result.matchedByRootAffinity = false; |
| 823 | break; |
Andrii Kulian | 206b9fa | 2016-06-02 13:18:01 -0700 | [diff] [blame] | 824 | } else if (!isDocument && !taskIsDocument |
| 825 | && result.r == null && task.canMatchRootAffinity()) { |
| 826 | if (task.rootAffinity.equals(target.taskAffinity)) { |
| 827 | if (DEBUG_TASKS) Slog.d(TAG_TASKS, "Found matching affinity candidate!"); |
| 828 | // It is possible for multiple tasks to have the same root affinity especially |
| 829 | // if they are in separate stacks. We save off this candidate, but keep looking |
| 830 | // to see if there is a better candidate. |
| 831 | result.r = r; |
| 832 | result.matchedByRootAffinity = true; |
| 833 | } |
Wale Ogunwale | ee006da | 2015-03-30 14:49:25 -0700 | [diff] [blame] | 834 | } else if (DEBUG_TASKS) Slog.d(TAG_TASKS, "Not a match: " + task); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 835 | } |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 836 | } |
| 837 | |
| 838 | /** |
| 839 | * Returns the first activity (starting from the top of the stack) that |
| 840 | * is the same as the given activity. Returns null if no such activity |
| 841 | * is found. |
| 842 | */ |
Andrii Kulian | d3bbb13 | 2016-06-16 16:00:20 -0700 | [diff] [blame] | 843 | ActivityRecord findActivityLocked(Intent intent, ActivityInfo info, |
| 844 | boolean compareIntentFilters) { |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 845 | ComponentName cls = intent.getComponent(); |
| 846 | if (info.targetActivity != null) { |
| 847 | cls = new ComponentName(info.packageName, info.targetActivity); |
| 848 | } |
Dianne Hackborn | f02b60a | 2012-08-16 10:48:27 -0700 | [diff] [blame] | 849 | final int userId = UserHandle.getUserId(info.applicationInfo.uid); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 850 | |
Craig Mautner | 000f002 | 2013-02-26 15:04:29 -0800 | [diff] [blame] | 851 | for (int taskNdx = mTaskHistory.size() - 1; taskNdx >= 0; --taskNdx) { |
Wale Ogunwale | 3fcb4a8 | 2015-04-06 14:00:13 -0700 | [diff] [blame] | 852 | final TaskRecord task = mTaskHistory.get(taskNdx); |
Craig Mautner | ac6f843 | 2013-07-17 13:24:59 -0700 | [diff] [blame] | 853 | final ArrayList<ActivityRecord> activities = task.mActivities; |
Wale Ogunwale | 3fcb4a8 | 2015-04-06 14:00:13 -0700 | [diff] [blame] | 854 | |
Craig Mautner | 000f002 | 2013-02-26 15:04:29 -0800 | [diff] [blame] | 855 | for (int activityNdx = activities.size() - 1; activityNdx >= 0; --activityNdx) { |
| 856 | ActivityRecord r = activities.get(activityNdx); |
Chong Zhang | 8776197 | 2016-08-22 13:53:24 -0700 | [diff] [blame^] | 857 | if (!r.okToShowLocked()) { |
Wale Ogunwale | 25073dd | 2015-07-21 16:54:54 -0700 | [diff] [blame] | 858 | continue; |
Wale Ogunwale | 3fcb4a8 | 2015-04-06 14:00:13 -0700 | [diff] [blame] | 859 | } |
Andrii Kulian | d3bbb13 | 2016-06-16 16:00:20 -0700 | [diff] [blame] | 860 | if (!r.finishing && r.userId == userId) { |
| 861 | if (compareIntentFilters) { |
| 862 | if (r.intent.filterEquals(intent)) { |
| 863 | return r; |
| 864 | } |
| 865 | } else { |
| 866 | if (r.intent.getComponent().equals(cls)) { |
| 867 | return r; |
| 868 | } |
| 869 | } |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 870 | } |
| 871 | } |
| 872 | } |
| 873 | |
| 874 | return null; |
| 875 | } |
| 876 | |
Amith Yamasani | 742a671 | 2011-05-04 14:49:28 -0700 | [diff] [blame] | 877 | /* |
Craig Mautner | ac6f843 | 2013-07-17 13:24:59 -0700 | [diff] [blame] | 878 | * 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] | 879 | */ |
Craig Mautner | 93529a4 | 2013-10-04 15:03:13 -0700 | [diff] [blame] | 880 | final void switchUserLocked(int userId) { |
Craig Mautner | 5d9c7be | 2013-02-15 14:02:56 -0800 | [diff] [blame] | 881 | if (mCurrentUser == userId) { |
Craig Mautner | 93529a4 | 2013-10-04 15:03:13 -0700 | [diff] [blame] | 882 | return; |
Craig Mautner | 5d9c7be | 2013-02-15 14:02:56 -0800 | [diff] [blame] | 883 | } |
| 884 | mCurrentUser = userId; |
| 885 | |
| 886 | // Move userId's tasks to the top. |
Craig Mautner | 5d9c7be | 2013-02-15 14:02:56 -0800 | [diff] [blame] | 887 | int index = mTaskHistory.size(); |
Craig Mautner | db5c4fb | 2013-11-06 13:55:08 -0800 | [diff] [blame] | 888 | for (int i = 0; i < index; ) { |
Wale Ogunwale | 3fcb4a8 | 2015-04-06 14:00:13 -0700 | [diff] [blame] | 889 | final TaskRecord task = mTaskHistory.get(i); |
| 890 | |
Chong Zhang | 8776197 | 2016-08-22 13:53:24 -0700 | [diff] [blame^] | 891 | if (task.okToShowLocked()) { |
Wale Ogunwale | ee006da | 2015-03-30 14:49:25 -0700 | [diff] [blame] | 892 | if (DEBUG_TASKS) Slog.d(TAG_TASKS, "switchUserLocked: stack=" + getStackId() + |
Craig Mautner | 4f1df4f | 2013-10-15 15:44:14 -0700 | [diff] [blame] | 893 | " moving " + task + " to top"); |
Craig Mautner | 5d9c7be | 2013-02-15 14:02:56 -0800 | [diff] [blame] | 894 | mTaskHistory.remove(i); |
| 895 | mTaskHistory.add(task); |
| 896 | --index; |
Craig Mautner | db5c4fb | 2013-11-06 13:55:08 -0800 | [diff] [blame] | 897 | // Use same value for i. |
| 898 | } else { |
| 899 | ++i; |
Craig Mautner | 5d9c7be | 2013-02-15 14:02:56 -0800 | [diff] [blame] | 900 | } |
| 901 | } |
Craig Mautner | 4f1df4f | 2013-10-15 15:44:14 -0700 | [diff] [blame] | 902 | if (VALIDATE_TOKENS) { |
| 903 | validateAppTokensLocked(); |
| 904 | } |
Amith Yamasani | 742a671 | 2011-05-04 14:49:28 -0700 | [diff] [blame] | 905 | } |
| 906 | |
Craig Mautner | 2420ead | 2013-04-01 17:13:20 -0700 | [diff] [blame] | 907 | void minimalResumeActivityLocked(ActivityRecord r) { |
Wale Ogunwale | 5658e4b | 2016-02-12 12:22:19 -0800 | [diff] [blame] | 908 | if (DEBUG_STATES) Slog.v(TAG_STATES, "Moving to RESUMED: " + r + " (starting new instance)" |
| 909 | + " callers=" + Debug.getCallers(5)); |
Chong Zhang | 6cda19c | 2016-06-14 19:07:56 -0700 | [diff] [blame] | 910 | setResumedActivityLocked(r, "minimalResumeActivityLocked"); |
Craig Mautner | 2420ead | 2013-04-01 17:13:20 -0700 | [diff] [blame] | 911 | completeResumeLocked(r); |
Craig Mautner | 1e8b872 | 2013-10-14 18:24:52 -0700 | [diff] [blame] | 912 | setLaunchTime(r); |
Wale Ogunwale | 0fc365c | 2015-05-25 19:35:42 -0700 | [diff] [blame] | 913 | if (DEBUG_SAVED_STATE) Slog.i(TAG_SAVED_STATE, |
| 914 | "Launch completed; removing icicle of " + r.icicle); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 915 | } |
| 916 | |
Filip Gruszczynski | 3d82ed6 | 2015-12-10 10:41:39 -0800 | [diff] [blame] | 917 | void addRecentActivityLocked(ActivityRecord r) { |
Chong Zhang | 45c25ce | 2015-08-10 22:18:26 -0700 | [diff] [blame] | 918 | if (r != null) { |
| 919 | mRecentTasks.addLocked(r.task); |
| 920 | r.task.touchActiveTime(); |
| 921 | } |
| 922 | } |
| 923 | |
Narayan Kamath | 7829c81 | 2015-06-08 17:39:43 +0100 | [diff] [blame] | 924 | private void startLaunchTraces(String packageName) { |
Dianne Hackborn | cee04b5 | 2013-07-03 17:01:28 -0700 | [diff] [blame] | 925 | if (mFullyDrawnStartTime != 0) { |
| 926 | Trace.asyncTraceEnd(Trace.TRACE_TAG_ACTIVITY_MANAGER, "drawing", 0); |
| 927 | } |
Narayan Kamath | 7829c81 | 2015-06-08 17:39:43 +0100 | [diff] [blame] | 928 | Trace.asyncTraceBegin(Trace.TRACE_TAG_ACTIVITY_MANAGER, "launching: " + packageName, 0); |
Dianne Hackborn | cee04b5 | 2013-07-03 17:01:28 -0700 | [diff] [blame] | 929 | Trace.asyncTraceBegin(Trace.TRACE_TAG_ACTIVITY_MANAGER, "drawing", 0); |
| 930 | } |
| 931 | |
| 932 | private void stopFullyDrawnTraceIfNeeded() { |
| 933 | if (mFullyDrawnStartTime != 0 && mLaunchStartTime == 0) { |
| 934 | Trace.asyncTraceEnd(Trace.TRACE_TAG_ACTIVITY_MANAGER, "drawing", 0); |
| 935 | mFullyDrawnStartTime = 0; |
| 936 | } |
| 937 | } |
| 938 | |
Craig Mautner | e79d4268 | 2013-04-01 19:01:53 -0700 | [diff] [blame] | 939 | void setLaunchTime(ActivityRecord r) { |
Dianne Hackborn | 2286cdc | 2013-07-01 19:10:06 -0700 | [diff] [blame] | 940 | if (r.displayStartTime == 0) { |
| 941 | r.fullyDrawnStartTime = r.displayStartTime = SystemClock.uptimeMillis(); |
| 942 | if (mLaunchStartTime == 0) { |
Narayan Kamath | 7829c81 | 2015-06-08 17:39:43 +0100 | [diff] [blame] | 943 | startLaunchTraces(r.packageName); |
Dianne Hackborn | 2286cdc | 2013-07-01 19:10:06 -0700 | [diff] [blame] | 944 | mLaunchStartTime = mFullyDrawnStartTime = r.displayStartTime; |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 945 | } |
Dianne Hackborn | 2286cdc | 2013-07-01 19:10:06 -0700 | [diff] [blame] | 946 | } else if (mLaunchStartTime == 0) { |
Narayan Kamath | 7829c81 | 2015-06-08 17:39:43 +0100 | [diff] [blame] | 947 | startLaunchTraces(r.packageName); |
Dianne Hackborn | 2286cdc | 2013-07-01 19:10:06 -0700 | [diff] [blame] | 948 | mLaunchStartTime = mFullyDrawnStartTime = SystemClock.uptimeMillis(); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 949 | } |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 950 | } |
Craig Mautner | aab647e | 2013-02-28 16:31:36 -0800 | [diff] [blame] | 951 | |
Dianne Hackborn | 2286cdc | 2013-07-01 19:10:06 -0700 | [diff] [blame] | 952 | void clearLaunchTime(ActivityRecord r) { |
Craig Mautner | 5c49454 | 2013-09-06 11:59:38 -0700 | [diff] [blame] | 953 | // Make sure that there is no activity waiting for this to launch. |
| 954 | if (mStackSupervisor.mWaitingActivityLaunched.isEmpty()) { |
| 955 | r.displayStartTime = r.fullyDrawnStartTime = 0; |
| 956 | } else { |
| 957 | mStackSupervisor.removeTimeoutsForActivityLocked(r); |
| 958 | mStackSupervisor.scheduleIdleTimeoutLocked(r); |
| 959 | } |
Dianne Hackborn | 2286cdc | 2013-07-01 19:10:06 -0700 | [diff] [blame] | 960 | } |
| 961 | |
Dianne Hackborn | 4eba96b | 2011-01-21 13:34:36 -0800 | [diff] [blame] | 962 | void awakeFromSleepingLocked() { |
Dianne Hackborn | 4eba96b | 2011-01-21 13:34:36 -0800 | [diff] [blame] | 963 | // Ensure activities are no longer sleeping. |
Craig Mautner | d44711d | 2013-02-23 11:24:36 -0800 | [diff] [blame] | 964 | for (int taskNdx = mTaskHistory.size() - 1; taskNdx >= 0; --taskNdx) { |
| 965 | final ArrayList<ActivityRecord> activities = mTaskHistory.get(taskNdx).mActivities; |
| 966 | for (int activityNdx = activities.size() - 1; activityNdx >= 0; --activityNdx) { |
| 967 | activities.get(activityNdx).setSleeping(false); |
| 968 | } |
Dianne Hackborn | 4eba96b | 2011-01-21 13:34:36 -0800 | [diff] [blame] | 969 | } |
Craig Mautner | f49b0a4 | 2014-11-20 15:06:40 -0800 | [diff] [blame] | 970 | if (mPausingActivity != null) { |
| 971 | Slog.d(TAG, "awakeFromSleepingLocked: previously pausing activity didn't pause"); |
| 972 | activityPausedLocked(mPausingActivity.appToken, true); |
| 973 | } |
Dianne Hackborn | 4eba96b | 2011-01-21 13:34:36 -0800 | [diff] [blame] | 974 | } |
| 975 | |
Todd Kennedy | 39bfee5 | 2016-02-24 10:28:21 -0800 | [diff] [blame] | 976 | void updateActivityApplicationInfoLocked(ApplicationInfo aInfo) { |
| 977 | final String packageName = aInfo.packageName; |
| 978 | for (int taskNdx = mTaskHistory.size() - 1; taskNdx >= 0; --taskNdx) { |
| 979 | final List<ActivityRecord> activities = mTaskHistory.get(taskNdx).mActivities; |
| 980 | for (int activityNdx = activities.size() - 1; activityNdx >= 0; --activityNdx) { |
| 981 | if (packageName.equals(activities.get(activityNdx).packageName)) { |
| 982 | activities.get(activityNdx).info.applicationInfo = aInfo; |
| 983 | } |
| 984 | } |
| 985 | } |
| 986 | } |
| 987 | |
Craig Mautner | 0eea92c | 2013-05-16 13:35:39 -0700 | [diff] [blame] | 988 | /** |
| 989 | * @return true if something must be done before going to sleep. |
| 990 | */ |
| 991 | boolean checkReadyForSleepLocked() { |
| 992 | if (mResumedActivity != null) { |
| 993 | // Still have something resumed; can't sleep until it is paused. |
Wale Ogunwale | ee006da | 2015-03-30 14:49:25 -0700 | [diff] [blame] | 994 | if (DEBUG_PAUSE) Slog.v(TAG_PAUSE, "Sleep needs to pause " + mResumedActivity); |
| 995 | if (DEBUG_USER_LEAVING) Slog.v(TAG_USER_LEAVING, |
| 996 | "Sleep => pause with userLeaving=false"); |
Wale Ogunwale | 950faff | 2016-08-08 09:51:04 -0700 | [diff] [blame] | 997 | startPausingLocked(false, true, null, false); |
Craig Mautner | 0eea92c | 2013-05-16 13:35:39 -0700 | [diff] [blame] | 998 | return true; |
| 999 | } |
| 1000 | if (mPausingActivity != null) { |
| 1001 | // Still waiting for something to pause; can't sleep yet. |
Wale Ogunwale | ee006da | 2015-03-30 14:49:25 -0700 | [diff] [blame] | 1002 | 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] | 1003 | return true; |
Dianne Hackborn | 4eba96b | 2011-01-21 13:34:36 -0800 | [diff] [blame] | 1004 | } |
| 1005 | |
Wale Ogunwale | 5c42e50 | 2015-04-08 09:18:54 -0700 | [diff] [blame] | 1006 | if (hasVisibleBehindActivity()) { |
| 1007 | // Stop visible behind activity before going to sleep. |
Wale Ogunwale | 1f544be | 2015-12-17 10:27:23 -0800 | [diff] [blame] | 1008 | final ActivityRecord r = getVisibleBehindActivity(); |
Wale Ogunwale | 5c42e50 | 2015-04-08 09:18:54 -0700 | [diff] [blame] | 1009 | mStackSupervisor.mStoppingActivities.add(r); |
Wale Ogunwale | 1f544be | 2015-12-17 10:27:23 -0800 | [diff] [blame] | 1010 | if (DEBUG_STATES) Slog.v(TAG_STATES, "Sleep still waiting to stop visible behind " + r); |
Wale Ogunwale | 5c42e50 | 2015-04-08 09:18:54 -0700 | [diff] [blame] | 1011 | return true; |
| 1012 | } |
| 1013 | |
Craig Mautner | 0eea92c | 2013-05-16 13:35:39 -0700 | [diff] [blame] | 1014 | return false; |
| 1015 | } |
Dianne Hackborn | 4eba96b | 2011-01-21 13:34:36 -0800 | [diff] [blame] | 1016 | |
Craig Mautner | 0eea92c | 2013-05-16 13:35:39 -0700 | [diff] [blame] | 1017 | void goToSleep() { |
Filip Gruszczynski | bc5a6c5 | 2015-09-22 13:13:24 -0700 | [diff] [blame] | 1018 | ensureActivitiesVisibleLocked(null, 0, !PRESERVE_WINDOWS); |
Dianne Hackborn | 4eba96b | 2011-01-21 13:34:36 -0800 | [diff] [blame] | 1019 | |
Andrii Kulian | f9949d5 | 2016-05-06 12:53:25 -0700 | [diff] [blame] | 1020 | // Make sure any paused or stopped but visible activities are now sleeping. |
Craig Mautner | 0eea92c | 2013-05-16 13:35:39 -0700 | [diff] [blame] | 1021 | // This ensures that the activity's onStop() is called. |
| 1022 | for (int taskNdx = mTaskHistory.size() - 1; taskNdx >= 0; --taskNdx) { |
| 1023 | final ArrayList<ActivityRecord> activities = mTaskHistory.get(taskNdx).mActivities; |
| 1024 | for (int activityNdx = activities.size() - 1; activityNdx >= 0; --activityNdx) { |
| 1025 | final ActivityRecord r = activities.get(activityNdx); |
Andrii Kulian | f9949d5 | 2016-05-06 12:53:25 -0700 | [diff] [blame] | 1026 | if (r.state == ActivityState.STOPPING || r.state == ActivityState.STOPPED |
| 1027 | || r.state == ActivityState.PAUSED || r.state == ActivityState.PAUSING) { |
Craig Mautner | 0eea92c | 2013-05-16 13:35:39 -0700 | [diff] [blame] | 1028 | r.setSleeping(true); |
Dianne Hackborn | 4eba96b | 2011-01-21 13:34:36 -0800 | [diff] [blame] | 1029 | } |
| 1030 | } |
Dianne Hackborn | 4eba96b | 2011-01-21 13:34:36 -0800 | [diff] [blame] | 1031 | } |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 1032 | } |
Craig Mautner | 59c0097 | 2012-07-30 12:10:24 -0700 | [diff] [blame] | 1033 | |
Winson | 8b1871d | 2015-11-20 09:56:20 -0800 | [diff] [blame] | 1034 | public final Bitmap screenshotActivitiesLocked(ActivityRecord who) { |
| 1035 | if (DEBUG_SCREENSHOTS) Slog.d(TAG_SCREENSHOTS, "screenshotActivitiesLocked: " + who); |
Dianne Hackborn | ff801ec | 2011-01-22 18:05:38 -0800 | [diff] [blame] | 1036 | if (who.noDisplay) { |
Wale Ogunwale | 0fc365c | 2015-05-25 19:35:42 -0700 | [diff] [blame] | 1037 | if (DEBUG_SCREENSHOTS) Slog.d(TAG_SCREENSHOTS, "\tNo display"); |
Dianne Hackborn | ff801ec | 2011-01-22 18:05:38 -0800 | [diff] [blame] | 1038 | return null; |
| 1039 | } |
Craig Mautner | aab647e | 2013-02-28 16:31:36 -0800 | [diff] [blame] | 1040 | |
Winson Chung | 083baf9 | 2014-07-11 10:32:42 -0700 | [diff] [blame] | 1041 | if (isHomeStack()) { |
Winson Chung | 376543b | 2014-05-21 17:43:28 -0700 | [diff] [blame] | 1042 | // 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] | 1043 | // 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] | 1044 | if (DEBUG_SCREENSHOTS) Slog.d(TAG_SCREENSHOTS, "\tHome stack"); |
Dianne Hackborn | 4d03fe6 | 2013-10-04 17:26:37 -0700 | [diff] [blame] | 1045 | return null; |
| 1046 | } |
| 1047 | |
Winson Chung | 48a10a5 | 2014-08-27 14:36:51 -0700 | [diff] [blame] | 1048 | int w = mService.mThumbnailWidth; |
| 1049 | int h = mService.mThumbnailHeight; |
Winson | 8b1871d | 2015-11-20 09:56:20 -0800 | [diff] [blame] | 1050 | float scale = 1f; |
Dianne Hackborn | 0aae2d4 | 2010-12-07 23:51:29 -0800 | [diff] [blame] | 1051 | if (w > 0) { |
Wale Ogunwale | 0fc365c | 2015-05-25 19:35:42 -0700 | [diff] [blame] | 1052 | if (DEBUG_SCREENSHOTS) Slog.d(TAG_SCREENSHOTS, "\tTaking screenshot"); |
Winson | 8b1871d | 2015-11-20 09:56:20 -0800 | [diff] [blame] | 1053 | |
| 1054 | // When this flag is set, we currently take the fullscreen screenshot of the activity |
Winson | 387aac6 | 2015-11-25 11:18:56 -0800 | [diff] [blame] | 1055 | // but scaled to half the size. This gives us a "good-enough" fullscreen thumbnail to |
| 1056 | // use within SystemUI while keeping memory usage low. |
Winson Chung | ead5c0f | 2015-12-14 11:18:57 -0500 | [diff] [blame] | 1057 | if (ActivityManagerService.TAKE_FULLSCREEN_SCREENSHOTS) { |
Winson | 8b1871d | 2015-11-20 09:56:20 -0800 | [diff] [blame] | 1058 | w = h = -1; |
Winson | 2170093 | 2016-03-24 17:26:23 -0700 | [diff] [blame] | 1059 | scale = mService.mFullscreenThumbnailScale; |
Winson | 8b1871d | 2015-11-20 09:56:20 -0800 | [diff] [blame] | 1060 | } |
Wale Ogunwale | eacdf2c | 2014-12-09 14:02:27 -0800 | [diff] [blame] | 1061 | return mWindowManager.screenshotApplications(who.appToken, Display.DEFAULT_DISPLAY, |
Winson | 8b1871d | 2015-11-20 09:56:20 -0800 | [diff] [blame] | 1062 | w, h, scale); |
Dianne Hackborn | 0aae2d4 | 2010-12-07 23:51:29 -0800 | [diff] [blame] | 1063 | } |
Winson Chung | 376543b | 2014-05-21 17:43:28 -0700 | [diff] [blame] | 1064 | Slog.e(TAG, "Invalid thumbnail dimensions: " + w + "x" + h); |
Dianne Hackborn | 0aae2d4 | 2010-12-07 23:51:29 -0800 | [diff] [blame] | 1065 | return null; |
| 1066 | } |
| 1067 | |
Dianne Hackborn | a4e102e | 2014-09-04 22:52:27 -0700 | [diff] [blame] | 1068 | /** |
| 1069 | * Start pausing the currently resumed activity. It is an error to call this if there |
| 1070 | * is already an activity being paused or there is no resumed activity. |
| 1071 | * |
| 1072 | * @param userLeaving True if this should result in an onUserLeaving to the current activity. |
| 1073 | * @param uiSleeping True if this is happening with the user interface going to sleep (the |
| 1074 | * screen turning off). |
Wale Ogunwale | 950faff | 2016-08-08 09:51:04 -0700 | [diff] [blame] | 1075 | * @param resuming The activity we are currently trying to resume or null if this is not being |
| 1076 | * called as part of resuming the top activity, so we shouldn't try to instigate |
| 1077 | * a resume here if not null. |
Dianne Hackborn | a4e102e | 2014-09-04 22:52:27 -0700 | [diff] [blame] | 1078 | * @param dontWait True if the caller does not want to wait for the pause to complete. If |
| 1079 | * set to true, we will immediately complete the pause here before returning. |
| 1080 | * @return Returns true if an activity now is in the PAUSING state, and we are waiting for |
| 1081 | * it to tell us when it is done. |
| 1082 | */ |
Wale Ogunwale | 950faff | 2016-08-08 09:51:04 -0700 | [diff] [blame] | 1083 | final boolean startPausingLocked(boolean userLeaving, boolean uiSleeping, |
| 1084 | ActivityRecord resuming, boolean dontWait) { |
Dianne Hackborn | 621e2fe | 2012-02-16 17:07:33 -0800 | [diff] [blame] | 1085 | if (mPausingActivity != null) { |
riddle_hsu | 7dfe4d7 | 2015-02-16 18:43:49 +0800 | [diff] [blame] | 1086 | Slog.wtf(TAG, "Going to pause when pause is already pending for " + mPausingActivity |
| 1087 | + " state=" + mPausingActivity.state); |
Fyodor Kupolov | 9b80b94 | 2016-06-16 16:29:05 -0700 | [diff] [blame] | 1088 | if (!mService.isSleepingLocked()) { |
riddle_hsu | 7dfe4d7 | 2015-02-16 18:43:49 +0800 | [diff] [blame] | 1089 | // Avoid recursion among check for sleep and complete pause during sleeping. |
| 1090 | // Because activity will be paused immediately after resume, just let pause |
| 1091 | // be completed by the order of activity paused from clients. |
Wale Ogunwale | 950faff | 2016-08-08 09:51:04 -0700 | [diff] [blame] | 1092 | completePauseLocked(false, resuming); |
riddle_hsu | 7dfe4d7 | 2015-02-16 18:43:49 +0800 | [diff] [blame] | 1093 | } |
Dianne Hackborn | 621e2fe | 2012-02-16 17:07:33 -0800 | [diff] [blame] | 1094 | } |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 1095 | ActivityRecord prev = mResumedActivity; |
| 1096 | if (prev == null) { |
Wale Ogunwale | 950faff | 2016-08-08 09:51:04 -0700 | [diff] [blame] | 1097 | if (resuming == null) { |
Dianne Hackborn | a4e102e | 2014-09-04 22:52:27 -0700 | [diff] [blame] | 1098 | Slog.wtf(TAG, "Trying to pause when nothing is resumed"); |
Wale Ogunwale | d046a01 | 2015-12-24 13:05:59 -0800 | [diff] [blame] | 1099 | mStackSupervisor.resumeFocusedStackTopActivityLocked(); |
Dianne Hackborn | a4e102e | 2014-09-04 22:52:27 -0700 | [diff] [blame] | 1100 | } |
| 1101 | return false; |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 1102 | } |
Craig Mautner | df88d73 | 2014-01-27 09:21:32 -0800 | [diff] [blame] | 1103 | |
| 1104 | if (mActivityContainer.mParentActivity == null) { |
| 1105 | // Top level stack, not a child. Look for child stacks. |
Dianne Hackborn | a4e102e | 2014-09-04 22:52:27 -0700 | [diff] [blame] | 1106 | mStackSupervisor.pauseChildStacks(prev, userLeaving, uiSleeping, resuming, dontWait); |
Craig Mautner | df88d73 | 2014-01-27 09:21:32 -0800 | [diff] [blame] | 1107 | } |
| 1108 | |
Wale Ogunwale | 0fc365c | 2015-05-25 19:35:42 -0700 | [diff] [blame] | 1109 | if (DEBUG_STATES) Slog.v(TAG_STATES, "Moving to PAUSING: " + prev); |
Wale Ogunwale | ee006da | 2015-03-30 14:49:25 -0700 | [diff] [blame] | 1110 | else if (DEBUG_PAUSE) Slog.v(TAG_PAUSE, "Start pausing: " + prev); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 1111 | mResumedActivity = null; |
Dianne Hackborn | 621e2fe | 2012-02-16 17:07:33 -0800 | [diff] [blame] | 1112 | mPausingActivity = prev; |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 1113 | mLastPausedActivity = prev; |
Craig Mautner | 0f92274 | 2013-08-06 08:44:42 -0700 | [diff] [blame] | 1114 | mLastNoHistoryActivity = (prev.intent.getFlags() & Intent.FLAG_ACTIVITY_NO_HISTORY) != 0 |
| 1115 | || (prev.info.flags & ActivityInfo.FLAG_NO_HISTORY) != 0 ? prev : null; |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 1116 | prev.state = ActivityState.PAUSING; |
| 1117 | prev.task.touchActiveTime(); |
Dianne Hackborn | 2286cdc | 2013-07-01 19:10:06 -0700 | [diff] [blame] | 1118 | clearLaunchTime(prev); |
Craig Mautner | 6f6d56f | 2013-10-24 16:02:07 -0700 | [diff] [blame] | 1119 | final ActivityRecord next = mStackSupervisor.topRunningActivityLocked(); |
Wale Ogunwale | 979f5ed | 2015-10-12 11:22:50 -0700 | [diff] [blame] | 1120 | if (mService.mHasRecents |
| 1121 | && (next == null || next.noDisplay || next.task != prev.task || uiSleeping)) { |
Jorim Jaggi | c2f262b | 2015-12-07 16:59:10 -0800 | [diff] [blame] | 1122 | prev.mUpdateTaskThumbnailWhenHidden = true; |
Craig Mautner | 6f6d56f | 2013-10-24 16:02:07 -0700 | [diff] [blame] | 1123 | } |
Dianne Hackborn | cee04b5 | 2013-07-03 17:01:28 -0700 | [diff] [blame] | 1124 | stopFullyDrawnTraceIfNeeded(); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 1125 | |
| 1126 | mService.updateCpuStats(); |
Craig Mautner | aab647e | 2013-02-28 16:31:36 -0800 | [diff] [blame] | 1127 | |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 1128 | if (prev.app != null && prev.app.thread != null) { |
Wale Ogunwale | ee006da | 2015-03-30 14:49:25 -0700 | [diff] [blame] | 1129 | if (DEBUG_PAUSE) Slog.v(TAG_PAUSE, "Enqueueing pending pause: " + prev); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 1130 | try { |
| 1131 | EventLog.writeEvent(EventLogTags.AM_PAUSE_ACTIVITY, |
Dianne Hackborn | b12e135 | 2012-09-26 11:39:20 -0700 | [diff] [blame] | 1132 | prev.userId, System.identityHashCode(prev), |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 1133 | prev.shortComponentName); |
Jeff Sharkey | 5782da7 | 2013-04-25 14:32:30 -0700 | [diff] [blame] | 1134 | mService.updateUsageStats(prev, false); |
Dianne Hackborn | be70785 | 2011-11-11 14:32:10 -0800 | [diff] [blame] | 1135 | prev.app.thread.schedulePauseActivity(prev.appToken, prev.finishing, |
Dianne Hackborn | a4e102e | 2014-09-04 22:52:27 -0700 | [diff] [blame] | 1136 | userLeaving, prev.configChangeFlags, dontWait); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 1137 | } catch (Exception e) { |
| 1138 | // Ignore exception, if process died other code will cleanup. |
| 1139 | Slog.w(TAG, "Exception thrown during pause", e); |
Dianne Hackborn | 621e2fe | 2012-02-16 17:07:33 -0800 | [diff] [blame] | 1140 | mPausingActivity = null; |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 1141 | mLastPausedActivity = null; |
Craig Mautner | 0f92274 | 2013-08-06 08:44:42 -0700 | [diff] [blame] | 1142 | mLastNoHistoryActivity = null; |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 1143 | } |
| 1144 | } else { |
Dianne Hackborn | 621e2fe | 2012-02-16 17:07:33 -0800 | [diff] [blame] | 1145 | mPausingActivity = null; |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 1146 | mLastPausedActivity = null; |
Craig Mautner | 0f92274 | 2013-08-06 08:44:42 -0700 | [diff] [blame] | 1147 | mLastNoHistoryActivity = null; |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 1148 | } |
| 1149 | |
| 1150 | // If we are not going to sleep, we want to ensure the device is |
| 1151 | // awake until the next activity is started. |
Fyodor Kupolov | 9b80b94 | 2016-06-16 16:29:05 -0700 | [diff] [blame] | 1152 | if (!uiSleeping && !mService.isSleepingOrShuttingDownLocked()) { |
Craig Mautner | 7ea5bd4 | 2013-07-05 15:27:08 -0700 | [diff] [blame] | 1153 | mStackSupervisor.acquireLaunchWakelock(); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 1154 | } |
| 1155 | |
Dianne Hackborn | 621e2fe | 2012-02-16 17:07:33 -0800 | [diff] [blame] | 1156 | if (mPausingActivity != null) { |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 1157 | // Have the window manager pause its key dispatching until the new |
| 1158 | // activity has started. If we're pausing the activity just because |
| 1159 | // the screen is being turned off and the UI is sleeping, don't interrupt |
| 1160 | // key dispatch; the same activity will pick it up again on wakeup. |
| 1161 | if (!uiSleeping) { |
Dianne Hackborn | 621e2fe | 2012-02-16 17:07:33 -0800 | [diff] [blame] | 1162 | prev.pauseKeyDispatchingLocked(); |
Wale Ogunwale | ee006da | 2015-03-30 14:49:25 -0700 | [diff] [blame] | 1163 | } else if (DEBUG_PAUSE) { |
| 1164 | Slog.v(TAG_PAUSE, "Key dispatch not paused for screen off"); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 1165 | } |
| 1166 | |
Dianne Hackborn | a4e102e | 2014-09-04 22:52:27 -0700 | [diff] [blame] | 1167 | if (dontWait) { |
| 1168 | // If the caller said they don't want to wait for the pause, then complete |
| 1169 | // the pause now. |
Wale Ogunwale | 950faff | 2016-08-08 09:51:04 -0700 | [diff] [blame] | 1170 | completePauseLocked(false, resuming); |
Dianne Hackborn | a4e102e | 2014-09-04 22:52:27 -0700 | [diff] [blame] | 1171 | return false; |
| 1172 | |
| 1173 | } else { |
| 1174 | // Schedule a pause timeout in case the app doesn't respond. |
| 1175 | // We don't give it much time because this directly impacts the |
| 1176 | // responsiveness seen by the user. |
| 1177 | Message msg = mHandler.obtainMessage(PAUSE_TIMEOUT_MSG); |
| 1178 | msg.obj = prev; |
| 1179 | prev.pauseTime = SystemClock.uptimeMillis(); |
| 1180 | mHandler.sendMessageDelayed(msg, PAUSE_TIMEOUT); |
Wale Ogunwale | ee006da | 2015-03-30 14:49:25 -0700 | [diff] [blame] | 1181 | if (DEBUG_PAUSE) Slog.v(TAG_PAUSE, "Waiting for pause to complete..."); |
Dianne Hackborn | a4e102e | 2014-09-04 22:52:27 -0700 | [diff] [blame] | 1182 | return true; |
| 1183 | } |
| 1184 | |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 1185 | } else { |
| 1186 | // This activity failed to schedule the |
| 1187 | // pause, so just treat it as being paused now. |
Wale Ogunwale | ee006da | 2015-03-30 14:49:25 -0700 | [diff] [blame] | 1188 | if (DEBUG_PAUSE) Slog.v(TAG_PAUSE, "Activity not running, resuming next."); |
Wale Ogunwale | 950faff | 2016-08-08 09:51:04 -0700 | [diff] [blame] | 1189 | if (resuming == null) { |
Wale Ogunwale | d046a01 | 2015-12-24 13:05:59 -0800 | [diff] [blame] | 1190 | mStackSupervisor.resumeFocusedStackTopActivityLocked(); |
Dianne Hackborn | a4e102e | 2014-09-04 22:52:27 -0700 | [diff] [blame] | 1191 | } |
| 1192 | return false; |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 1193 | } |
| 1194 | } |
Dianne Hackborn | ad9b3211 | 2012-09-17 15:35:01 -0700 | [diff] [blame] | 1195 | |
Dianne Hackborn | a4e102e | 2014-09-04 22:52:27 -0700 | [diff] [blame] | 1196 | final void activityPausedLocked(IBinder token, boolean timeout) { |
Wale Ogunwale | ee006da | 2015-03-30 14:49:25 -0700 | [diff] [blame] | 1197 | if (DEBUG_PAUSE) Slog.v(TAG_PAUSE, |
| 1198 | "Activity paused: token=" + token + ", timeout=" + timeout); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 1199 | |
Craig Mautner | d232895 | 2013-03-05 12:46:26 -0800 | [diff] [blame] | 1200 | final ActivityRecord r = isInStackLocked(token); |
| 1201 | if (r != null) { |
| 1202 | mHandler.removeMessages(PAUSE_TIMEOUT_MSG, r); |
| 1203 | if (mPausingActivity == r) { |
Wale Ogunwale | 0fc365c | 2015-05-25 19:35:42 -0700 | [diff] [blame] | 1204 | if (DEBUG_STATES) Slog.v(TAG_STATES, "Moving to PAUSED: " + r |
Craig Mautner | d232895 | 2013-03-05 12:46:26 -0800 | [diff] [blame] | 1205 | + (timeout ? " (due to timeout)" : " (pause complete)")); |
Wale Ogunwale | 950faff | 2016-08-08 09:51:04 -0700 | [diff] [blame] | 1206 | completePauseLocked(true, null); |
Wale Ogunwale | 5658e4b | 2016-02-12 12:22:19 -0800 | [diff] [blame] | 1207 | return; |
Craig Mautner | d232895 | 2013-03-05 12:46:26 -0800 | [diff] [blame] | 1208 | } else { |
| 1209 | EventLog.writeEvent(EventLogTags.AM_FAILED_TO_PAUSE, |
| 1210 | r.userId, System.identityHashCode(r), r.shortComponentName, |
| 1211 | mPausingActivity != null |
| 1212 | ? mPausingActivity.shortComponentName : "(none)"); |
riddle_hsu | 9caeef7 | 2015-10-20 16:34:05 +0800 | [diff] [blame] | 1213 | if (r.state == ActivityState.PAUSING) { |
| 1214 | r.state = ActivityState.PAUSED; |
| 1215 | if (r.finishing) { |
| 1216 | if (DEBUG_PAUSE) Slog.v(TAG, |
| 1217 | "Executing finish of failed to pause activity: " + r); |
| 1218 | finishCurrentActivityLocked(r, FINISH_AFTER_VISIBLE, false); |
| 1219 | } |
louis_chang | 047dfd4 | 2015-04-08 16:35:55 +0800 | [diff] [blame] | 1220 | } |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 1221 | } |
| 1222 | } |
Wale Ogunwale | 5658e4b | 2016-02-12 12:22:19 -0800 | [diff] [blame] | 1223 | mStackSupervisor.ensureActivitiesVisibleLocked(null, 0, !PRESERVE_WINDOWS); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 1224 | } |
| 1225 | |
Chong Zhang | d78ddb4 | 2016-03-02 17:01:14 -0800 | [diff] [blame] | 1226 | final void activityResumedLocked(IBinder token) { |
| 1227 | final ActivityRecord r = ActivityRecord.forTokenLocked(token); |
| 1228 | if (DEBUG_SAVED_STATE) Slog.i(TAG_STATES, "Resumed activity; dropping state of: " + r); |
| 1229 | r.icicle = null; |
| 1230 | r.haveState = false; |
| 1231 | } |
| 1232 | |
Craig Mautner | a002604 | 2014-04-23 11:45:37 -0700 | [diff] [blame] | 1233 | final void activityStoppedLocked(ActivityRecord r, Bundle icicle, |
| 1234 | PersistableBundle persistentState, CharSequence description) { |
Dianne Hackborn | b61a026 | 2012-05-14 17:19:18 -0700 | [diff] [blame] | 1235 | if (r.state != ActivityState.STOPPING) { |
| 1236 | Slog.i(TAG, "Activity reported stop, but no longer stopping: " + r); |
| 1237 | mHandler.removeMessages(STOP_TIMEOUT_MSG, r); |
| 1238 | return; |
| 1239 | } |
Craig Mautner | 21d24a2 | 2014-04-23 11:45:37 -0700 | [diff] [blame] | 1240 | if (persistentState != null) { |
| 1241 | r.persistentState = persistentState; |
| 1242 | mService.notifyTaskPersisterLocked(r.task, false); |
| 1243 | } |
Wale Ogunwale | 0fc365c | 2015-05-25 19:35:42 -0700 | [diff] [blame] | 1244 | 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] | 1245 | if (icicle != null) { |
| 1246 | // If icicle is null, this is happening due to a timeout, so we |
| 1247 | // haven't really saved the state. |
| 1248 | r.icicle = icicle; |
| 1249 | r.haveState = true; |
Dianne Hackborn | 0798149 | 2013-01-28 11:36:23 -0800 | [diff] [blame] | 1250 | r.launchCount = 0; |
Winson Chung | 740c3ac | 2014-11-12 16:14:38 -0800 | [diff] [blame] | 1251 | r.updateThumbnailLocked(null, description); |
Dianne Hackborn | 162bc0e | 2012-04-09 14:06:16 -0700 | [diff] [blame] | 1252 | } |
| 1253 | if (!r.stopped) { |
Wale Ogunwale | 0fc365c | 2015-05-25 19:35:42 -0700 | [diff] [blame] | 1254 | 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] | 1255 | mHandler.removeMessages(STOP_TIMEOUT_MSG, r); |
| 1256 | r.stopped = true; |
| 1257 | r.state = ActivityState.STOPPED; |
Robert Carr | e12aece | 2016-02-02 22:43:27 -0800 | [diff] [blame] | 1258 | |
Chong Zhang | 45e6d2d | 2016-07-20 18:33:56 -0700 | [diff] [blame] | 1259 | mWindowManager.notifyAppStopped(r.appToken); |
Robert Carr | e12aece | 2016-02-02 22:43:27 -0800 | [diff] [blame] | 1260 | |
Wale Ogunwale | 1f544be | 2015-12-17 10:27:23 -0800 | [diff] [blame] | 1261 | if (getVisibleBehindActivity() == r) { |
Jose Lima | 4b6c669 | 2014-08-12 17:41:12 -0700 | [diff] [blame] | 1262 | mStackSupervisor.requestVisibleBehindLocked(r, false); |
Craig Mautner | ee2e45a | 2014-06-27 12:10:03 -0700 | [diff] [blame] | 1263 | } |
Dianne Hackborn | 6e3d6da | 2012-06-15 12:05:27 -0700 | [diff] [blame] | 1264 | if (r.finishing) { |
| 1265 | r.clearOptionsLocked(); |
| 1266 | } else { |
Wale Ogunwale | f81c1d1 | 2016-01-12 12:20:18 -0800 | [diff] [blame] | 1267 | if (r.deferRelaunchUntilPaused) { |
Craig Mautner | ee2e45a | 2014-06-27 12:10:03 -0700 | [diff] [blame] | 1268 | destroyActivityLocked(r, true, "stop-config"); |
Wale Ogunwale | d046a01 | 2015-12-24 13:05:59 -0800 | [diff] [blame] | 1269 | mStackSupervisor.resumeFocusedStackTopActivityLocked(); |
Dianne Hackborn | 162bc0e | 2012-04-09 14:06:16 -0700 | [diff] [blame] | 1270 | } else { |
Dianne Hackborn | a413dc0 | 2013-07-12 12:02:55 -0700 | [diff] [blame] | 1271 | mStackSupervisor.updatePreviousProcessLocked(r); |
Dianne Hackborn | 5068560 | 2011-12-01 12:23:37 -0800 | [diff] [blame] | 1272 | } |
Dianne Hackborn | ce86ba8 | 2011-07-13 19:33:41 -0700 | [diff] [blame] | 1273 | } |
| 1274 | } |
| 1275 | } |
| 1276 | |
Wale Ogunwale | 950faff | 2016-08-08 09:51:04 -0700 | [diff] [blame] | 1277 | private void completePauseLocked(boolean resumeNext, ActivityRecord resuming) { |
Dianne Hackborn | 621e2fe | 2012-02-16 17:07:33 -0800 | [diff] [blame] | 1278 | ActivityRecord prev = mPausingActivity; |
Wale Ogunwale | ee006da | 2015-03-30 14:49:25 -0700 | [diff] [blame] | 1279 | if (DEBUG_PAUSE) Slog.v(TAG_PAUSE, "Complete pause: " + prev); |
Craig Mautner | aab647e | 2013-02-28 16:31:36 -0800 | [diff] [blame] | 1280 | |
Dianne Hackborn | 621e2fe | 2012-02-16 17:07:33 -0800 | [diff] [blame] | 1281 | if (prev != null) { |
Filip Gruszczynski | dba623a | 2015-12-04 15:45:35 -0800 | [diff] [blame] | 1282 | final boolean wasStopping = prev.state == ActivityState.STOPPING; |
Dianne Hackborn | a4e102e | 2014-09-04 22:52:27 -0700 | [diff] [blame] | 1283 | prev.state = ActivityState.PAUSED; |
Dianne Hackborn | 621e2fe | 2012-02-16 17:07:33 -0800 | [diff] [blame] | 1284 | if (prev.finishing) { |
Wale Ogunwale | ee006da | 2015-03-30 14:49:25 -0700 | [diff] [blame] | 1285 | if (DEBUG_PAUSE) Slog.v(TAG_PAUSE, "Executing finish of activity: " + prev); |
Dianne Hackborn | 2d1b378 | 2012-09-09 17:49:39 -0700 | [diff] [blame] | 1286 | prev = finishCurrentActivityLocked(prev, FINISH_AFTER_VISIBLE, false); |
Dianne Hackborn | 621e2fe | 2012-02-16 17:07:33 -0800 | [diff] [blame] | 1287 | } else if (prev.app != null) { |
Wale Ogunwale | d802664 | 2016-02-09 20:40:18 -0800 | [diff] [blame] | 1288 | if (DEBUG_PAUSE) Slog.v(TAG_PAUSE, "Enqueue pending stop if needed: " + prev |
| 1289 | + " wasStopping=" + wasStopping + " visible=" + prev.visible); |
Craig Mautner | 8c14c15 | 2015-01-15 17:32:07 -0800 | [diff] [blame] | 1290 | if (mStackSupervisor.mWaitingVisibleActivities.remove(prev)) { |
Wale Ogunwale | ee006da | 2015-03-30 14:49:25 -0700 | [diff] [blame] | 1291 | if (DEBUG_SWITCH || DEBUG_PAUSE) Slog.v(TAG_PAUSE, |
| 1292 | "Complete pause, no longer waiting: " + prev); |
Dianne Hackborn | cbb722e | 2012-02-07 18:33:49 -0800 | [diff] [blame] | 1293 | } |
Wale Ogunwale | f81c1d1 | 2016-01-12 12:20:18 -0800 | [diff] [blame] | 1294 | if (prev.deferRelaunchUntilPaused) { |
| 1295 | // Complete the deferred relaunch that was waiting for pause to complete. |
| 1296 | if (DEBUG_PAUSE) Slog.v(TAG_PAUSE, "Re-launching after pause: " + prev); |
| 1297 | relaunchActivityLocked(prev, prev.configChangeFlags, false, |
| 1298 | prev.preserveWindowOnDeferredRelaunch); |
Filip Gruszczynski | dba623a | 2015-12-04 15:45:35 -0800 | [diff] [blame] | 1299 | } else if (wasStopping) { |
| 1300 | // We are also stopping, the stop request must have gone soon after the pause. |
| 1301 | // We can't clobber it, because the stop confirmation will not be handled. |
| 1302 | // We don't need to schedule another stop, we only need to let it happen. |
| 1303 | prev.state = ActivityState.STOPPING; |
Wale Ogunwale | d802664 | 2016-02-09 20:40:18 -0800 | [diff] [blame] | 1304 | } else if ((!prev.visible && !hasVisibleBehindActivity()) |
Fyodor Kupolov | 9b80b94 | 2016-06-16 16:29:05 -0700 | [diff] [blame] | 1305 | || mService.isSleepingOrShuttingDownLocked()) { |
Jose Lima | 4b6c669 | 2014-08-12 17:41:12 -0700 | [diff] [blame] | 1306 | // If we were visible then resumeTopActivities will release resources before |
Craig Mautner | ee2e45a | 2014-06-27 12:10:03 -0700 | [diff] [blame] | 1307 | // stopping. |
Chong Zhang | 46b1ac6 | 2016-02-18 17:53:57 -0800 | [diff] [blame] | 1308 | addToStopping(prev, true /* immediate */); |
Dianne Hackborn | 621e2fe | 2012-02-16 17:07:33 -0800 | [diff] [blame] | 1309 | } |
| 1310 | } else { |
Wale Ogunwale | ee006da | 2015-03-30 14:49:25 -0700 | [diff] [blame] | 1311 | 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] | 1312 | prev = null; |
Dianne Hackborn | cbb722e | 2012-02-07 18:33:49 -0800 | [diff] [blame] | 1313 | } |
Wale Ogunwale | 07927bf | 2015-03-28 17:21:05 -0700 | [diff] [blame] | 1314 | // It is possible the activity was freezing the screen before it was paused. |
| 1315 | // In that case go ahead and remove the freeze this activity has on the screen |
| 1316 | // since it is no longer visible. |
| 1317 | prev.stopFreezingScreenLocked(true /*force*/); |
Dianne Hackborn | 621e2fe | 2012-02-16 17:07:33 -0800 | [diff] [blame] | 1318 | mPausingActivity = null; |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 1319 | } |
Dianne Hackborn | cbb722e | 2012-02-07 18:33:49 -0800 | [diff] [blame] | 1320 | |
Dianne Hackborn | a4e102e | 2014-09-04 22:52:27 -0700 | [diff] [blame] | 1321 | if (resumeNext) { |
| 1322 | final ActivityStack topStack = mStackSupervisor.getFocusedStack(); |
Fyodor Kupolov | 9b80b94 | 2016-06-16 16:29:05 -0700 | [diff] [blame] | 1323 | if (!mService.isSleepingOrShuttingDownLocked()) { |
Wale Ogunwale | d046a01 | 2015-12-24 13:05:59 -0800 | [diff] [blame] | 1324 | mStackSupervisor.resumeFocusedStackTopActivityLocked(topStack, prev, null); |
Dianne Hackborn | a4e102e | 2014-09-04 22:52:27 -0700 | [diff] [blame] | 1325 | } else { |
| 1326 | mStackSupervisor.checkReadyForSleepLocked(); |
Filip Gruszczynski | 3e85ba2 | 2015-10-05 22:48:30 -0700 | [diff] [blame] | 1327 | ActivityRecord top = topStack.topRunningActivityLocked(); |
Dianne Hackborn | a4e102e | 2014-09-04 22:52:27 -0700 | [diff] [blame] | 1328 | if (top == null || (prev != null && top != prev)) { |
Wale Ogunwale | d046a01 | 2015-12-24 13:05:59 -0800 | [diff] [blame] | 1329 | // If there are no more activities available to run, do resume anyway to start |
| 1330 | // something. Also if the top activity on the stack is not the just paused |
| 1331 | // activity, we need to go ahead and resume it to ensure we complete an |
| 1332 | // in-flight app switch. |
| 1333 | mStackSupervisor.resumeFocusedStackTopActivityLocked(); |
Dianne Hackborn | a4e102e | 2014-09-04 22:52:27 -0700 | [diff] [blame] | 1334 | } |
Dianne Hackborn | 42e620c | 2012-06-24 13:20:51 -0700 | [diff] [blame] | 1335 | } |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 1336 | } |
Craig Mautner | aab647e | 2013-02-28 16:31:36 -0800 | [diff] [blame] | 1337 | |
Dianne Hackborn | 621e2fe | 2012-02-16 17:07:33 -0800 | [diff] [blame] | 1338 | if (prev != null) { |
| 1339 | prev.resumeKeyDispatchingLocked(); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 1340 | |
Craig Mautner | 525f3d9 | 2013-05-07 14:01:50 -0700 | [diff] [blame] | 1341 | if (prev.app != null && prev.cpuTimeAtResume > 0 |
| 1342 | && mService.mBatteryStatsService.isOnBattery()) { |
Dianne Hackborn | 652973f | 2014-09-10 17:08:48 -0700 | [diff] [blame] | 1343 | long diff = mService.mProcessCpuTracker.getCpuTimeForPid(prev.app.pid) |
| 1344 | - prev.cpuTimeAtResume; |
Craig Mautner | 525f3d9 | 2013-05-07 14:01:50 -0700 | [diff] [blame] | 1345 | if (diff > 0) { |
| 1346 | BatteryStatsImpl bsi = mService.mBatteryStatsService.getActiveStatistics(); |
| 1347 | synchronized (bsi) { |
| 1348 | BatteryStatsImpl.Uid.Proc ps = |
| 1349 | bsi.getProcessStatsLocked(prev.info.applicationInfo.uid, |
Dianne Hackborn | d293224 | 2013-08-05 18:18:42 -0700 | [diff] [blame] | 1350 | prev.info.packageName); |
Craig Mautner | 525f3d9 | 2013-05-07 14:01:50 -0700 | [diff] [blame] | 1351 | if (ps != null) { |
| 1352 | ps.addForegroundTimeLocked(diff); |
| 1353 | } |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 1354 | } |
| 1355 | } |
| 1356 | } |
Craig Mautner | 525f3d9 | 2013-05-07 14:01:50 -0700 | [diff] [blame] | 1357 | prev.cpuTimeAtResume = 0; // reset it |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 1358 | } |
Winson Chung | 740c3ac | 2014-11-12 16:14:38 -0800 | [diff] [blame] | 1359 | |
Andrii Kulian | 8290f8f | 2016-06-30 17:51:32 -0700 | [diff] [blame] | 1360 | // Notify when the task stack has changed, but only if visibilities changed (not just |
| 1361 | // focus). Also if there is an active pinned stack - we always want to notify it about |
| 1362 | // task stack changes, because its positioning may depend on it. |
| 1363 | if (mStackSupervisor.mAppVisibilitiesChangedSinceLastPause |
| 1364 | || mService.mStackSupervisor.getStack(PINNED_STACK_ID) != null) { |
Jorim Jaggi | a0fdeec | 2016-01-07 14:42:28 +0100 | [diff] [blame] | 1365 | mService.notifyTaskStackChangedLocked(); |
| 1366 | mStackSupervisor.mAppVisibilitiesChangedSinceLastPause = false; |
| 1367 | } |
Wale Ogunwale | 5658e4b | 2016-02-12 12:22:19 -0800 | [diff] [blame] | 1368 | |
Wale Ogunwale | 950faff | 2016-08-08 09:51:04 -0700 | [diff] [blame] | 1369 | mStackSupervisor.ensureActivitiesVisibleLocked(resuming, 0, !PRESERVE_WINDOWS); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 1370 | } |
| 1371 | |
Chong Zhang | 46b1ac6 | 2016-02-18 17:53:57 -0800 | [diff] [blame] | 1372 | private void addToStopping(ActivityRecord r, boolean immediate) { |
| 1373 | if (!mStackSupervisor.mStoppingActivities.contains(r)) { |
| 1374 | mStackSupervisor.mStoppingActivities.add(r); |
| 1375 | } |
| 1376 | |
| 1377 | // If we already have a few activities waiting to stop, then give up |
| 1378 | // on things going idle and start clearing them out. Or if r is the |
| 1379 | // last of activity of the last task the stack will be empty and must |
| 1380 | // be cleared immediately. |
| 1381 | boolean forceIdle = mStackSupervisor.mStoppingActivities.size() > MAX_STOPPING_TO_FORCE |
| 1382 | || (r.frontOfTask && mTaskHistory.size() <= 1); |
| 1383 | |
| 1384 | if (immediate || forceIdle) { |
| 1385 | if (DEBUG_PAUSE) Slog.v(TAG_PAUSE, "Scheduling idle now: forceIdle=" |
| 1386 | + forceIdle + "immediate=" + immediate); |
Filip Gruszczynski | ef2f72b | 2015-12-04 14:52:25 -0800 | [diff] [blame] | 1387 | mStackSupervisor.scheduleIdleLocked(); |
| 1388 | } else { |
| 1389 | mStackSupervisor.checkReadyForSleepLocked(); |
| 1390 | } |
| 1391 | } |
| 1392 | |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 1393 | /** |
| 1394 | * Once we know that we have asked an application to put an activity in |
| 1395 | * the resumed state (either by launching it or explicitly telling it), |
| 1396 | * this function updates the rest of our state to match that fact. |
| 1397 | */ |
Craig Mautner | 525f3d9 | 2013-05-07 14:01:50 -0700 | [diff] [blame] | 1398 | private void completeResumeLocked(ActivityRecord next) { |
Chong Zhang | 2b79af1 | 2016-02-10 18:47:06 -0800 | [diff] [blame] | 1399 | next.visible = true; |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 1400 | next.idle = false; |
| 1401 | next.results = null; |
| 1402 | next.newIntents = null; |
Chong Zhang | 2b79af1 | 2016-02-10 18:47:06 -0800 | [diff] [blame] | 1403 | next.stopped = false; |
Craig Mautner | f33f4d7 | 2014-07-16 17:25:48 +0000 | [diff] [blame] | 1404 | |
Chong Zhang | 85ee654 | 2015-10-02 13:36:38 -0700 | [diff] [blame] | 1405 | if (next.isHomeActivity()) { |
Craig Mautner | f33f4d7 | 2014-07-16 17:25:48 +0000 | [diff] [blame] | 1406 | ProcessRecord app = next.task.mActivities.get(0).app; |
| 1407 | if (app != null && app != mService.mHomeProcess) { |
| 1408 | mService.mHomeProcess = app; |
| 1409 | } |
| 1410 | } |
| 1411 | |
Craig Mautner | 0756632 | 2013-09-26 16:42:55 -0700 | [diff] [blame] | 1412 | if (next.nowVisible) { |
| 1413 | // We won't get a call to reportActivityVisibleLocked() so dismiss lockscreen now. |
Chong Zhang | 5022da3 | 2016-06-21 16:31:37 -0700 | [diff] [blame] | 1414 | mStackSupervisor.reportActivityVisibleLocked(next); |
Jorim Jaggi | 8de4311c | 2014-08-11 22:36:20 +0200 | [diff] [blame] | 1415 | mStackSupervisor.notifyActivityDrawnForKeyguard(); |
Craig Mautner | 0756632 | 2013-09-26 16:42:55 -0700 | [diff] [blame] | 1416 | } |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 1417 | |
| 1418 | // 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] | 1419 | mStackSupervisor.scheduleIdleTimeoutLocked(next); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 1420 | |
Craig Mautner | ce5f3cb | 2013-04-22 08:58:54 -0700 | [diff] [blame] | 1421 | mStackSupervisor.reportResumedActivityLocked(next); |
| 1422 | |
| 1423 | next.resumeKeyDispatchingLocked(); |
| 1424 | mNoAnimActivities.clear(); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 1425 | |
| 1426 | // Mark the point when the activity is resuming |
| 1427 | // TODO: To be more accurate, the mark should be before the onCreate, |
| 1428 | // not after the onResume. But for subsequent starts, onResume is fine. |
| 1429 | if (next.app != null) { |
Dianne Hackborn | 652973f | 2014-09-10 17:08:48 -0700 | [diff] [blame] | 1430 | next.cpuTimeAtResume = mService.mProcessCpuTracker.getCpuTimeForPid(next.app.pid); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 1431 | } else { |
| 1432 | next.cpuTimeAtResume = 0; // Couldn't get the cpu time of process |
| 1433 | } |
Winson Chung | 376543b | 2014-05-21 17:43:28 -0700 | [diff] [blame] | 1434 | |
George Mount | 6ba042b | 2014-07-28 11:12:28 -0700 | [diff] [blame] | 1435 | next.returningOptions = null; |
Craig Mautner | 64ccb70 | 2014-10-01 09:38:40 -0700 | [diff] [blame] | 1436 | |
Wale Ogunwale | 1f544be | 2015-12-17 10:27:23 -0800 | [diff] [blame] | 1437 | if (getVisibleBehindActivity() == next) { |
Craig Mautner | 64ccb70 | 2014-10-01 09:38:40 -0700 | [diff] [blame] | 1438 | // When resuming an activity, require it to call requestVisibleBehind() again. |
Wale Ogunwale | 1f544be | 2015-12-17 10:27:23 -0800 | [diff] [blame] | 1439 | setVisibleBehindActivity(null); |
Craig Mautner | 64ccb70 | 2014-10-01 09:38:40 -0700 | [diff] [blame] | 1440 | } |
Chong Zhang | 6cda19c | 2016-06-14 19:07:56 -0700 | [diff] [blame] | 1441 | mStackSupervisor.checkReadyForSleepLocked(); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 1442 | } |
| 1443 | |
Craig Mautner | 2568c3a | 2015-03-26 14:22:34 -0700 | [diff] [blame] | 1444 | private void setVisible(ActivityRecord r, boolean visible) { |
Craig Mautner | e3a00d7 | 2014-04-16 08:31:19 -0700 | [diff] [blame] | 1445 | r.visible = visible; |
Jorim Jaggi | c2f262b | 2015-12-07 16:59:10 -0800 | [diff] [blame] | 1446 | if (!visible && r.mUpdateTaskThumbnailWhenHidden) { |
| 1447 | r.updateThumbnailLocked(r.task.stack.screenshotActivitiesLocked(r), null); |
| 1448 | r.mUpdateTaskThumbnailWhenHidden = false; |
| 1449 | } |
Craig Mautner | e3a00d7 | 2014-04-16 08:31:19 -0700 | [diff] [blame] | 1450 | mWindowManager.setAppVisibility(r.appToken, visible); |
Craig Mautner | f4c909b | 2014-04-17 18:39:38 -0700 | [diff] [blame] | 1451 | final ArrayList<ActivityContainer> containers = r.mChildContainers; |
Craig Mautner | e3a00d7 | 2014-04-16 08:31:19 -0700 | [diff] [blame] | 1452 | for (int containerNdx = containers.size() - 1; containerNdx >= 0; --containerNdx) { |
Craig Mautner | f4c909b | 2014-04-17 18:39:38 -0700 | [diff] [blame] | 1453 | ActivityContainer container = containers.get(containerNdx); |
Craig Mautner | e3a00d7 | 2014-04-16 08:31:19 -0700 | [diff] [blame] | 1454 | container.setVisible(visible); |
| 1455 | } |
Jorim Jaggi | a0fdeec | 2016-01-07 14:42:28 +0100 | [diff] [blame] | 1456 | mStackSupervisor.mAppVisibilitiesChangedSinceLastPause = true; |
Craig Mautner | e3a00d7 | 2014-04-16 08:31:19 -0700 | [diff] [blame] | 1457 | } |
| 1458 | |
Craig Mautner | fa387ad | 2014-08-05 11:16:41 -0700 | [diff] [blame] | 1459 | // Find the first visible activity above the passed activity and if it is translucent return it |
| 1460 | // otherwise return null; |
| 1461 | ActivityRecord findNextTranslucentActivity(ActivityRecord r) { |
| 1462 | TaskRecord task = r.task; |
| 1463 | if (task == null) { |
| 1464 | return null; |
| 1465 | } |
| 1466 | |
| 1467 | ActivityStack stack = task.stack; |
| 1468 | if (stack == null) { |
| 1469 | return null; |
| 1470 | } |
| 1471 | |
| 1472 | int stackNdx = mStacks.indexOf(stack); |
| 1473 | |
| 1474 | ArrayList<TaskRecord> tasks = stack.mTaskHistory; |
| 1475 | int taskNdx = tasks.indexOf(task); |
| 1476 | |
| 1477 | ArrayList<ActivityRecord> activities = task.mActivities; |
| 1478 | int activityNdx = activities.indexOf(r) + 1; |
| 1479 | |
| 1480 | final int numStacks = mStacks.size(); |
| 1481 | while (stackNdx < numStacks) { |
Wale Ogunwale | e4a0c57 | 2015-06-30 08:40:31 -0700 | [diff] [blame] | 1482 | final ActivityStack historyStack = mStacks.get(stackNdx); |
Todd Kennedy | aab56db | 2015-01-30 09:39:53 -0800 | [diff] [blame] | 1483 | tasks = historyStack.mTaskHistory; |
Craig Mautner | fa387ad | 2014-08-05 11:16:41 -0700 | [diff] [blame] | 1484 | final int numTasks = tasks.size(); |
| 1485 | while (taskNdx < numTasks) { |
Wale Ogunwale | e4a0c57 | 2015-06-30 08:40:31 -0700 | [diff] [blame] | 1486 | final TaskRecord currentTask = tasks.get(taskNdx); |
| 1487 | activities = currentTask.mActivities; |
Craig Mautner | fa387ad | 2014-08-05 11:16:41 -0700 | [diff] [blame] | 1488 | final int numActivities = activities.size(); |
| 1489 | while (activityNdx < numActivities) { |
| 1490 | final ActivityRecord activity = activities.get(activityNdx); |
| 1491 | if (!activity.finishing) { |
Wale Ogunwale | e4a0c57 | 2015-06-30 08:40:31 -0700 | [diff] [blame] | 1492 | return historyStack.mFullscreen |
| 1493 | && currentTask.mFullscreen && activity.fullscreen ? null : activity; |
Craig Mautner | fa387ad | 2014-08-05 11:16:41 -0700 | [diff] [blame] | 1494 | } |
| 1495 | ++activityNdx; |
| 1496 | } |
| 1497 | activityNdx = 0; |
| 1498 | ++taskNdx; |
| 1499 | } |
| 1500 | taskNdx = 0; |
| 1501 | ++stackNdx; |
| 1502 | } |
| 1503 | |
| 1504 | return null; |
| 1505 | } |
| 1506 | |
Wale Ogunwale | 4cea0f5 | 2015-12-25 06:30:31 -0800 | [diff] [blame] | 1507 | ActivityStack getNextFocusableStackLocked() { |
Wale Ogunwale | d697cea | 2015-02-20 17:19:49 -0800 | [diff] [blame] | 1508 | ArrayList<ActivityStack> stacks = mStacks; |
| 1509 | final ActivityRecord parent = mActivityContainer.mParentActivity; |
| 1510 | if (parent != null) { |
| 1511 | stacks = parent.task.stack.mStacks; |
| 1512 | } |
| 1513 | if (stacks != null) { |
| 1514 | for (int i = stacks.size() - 1; i >= 0; --i) { |
| 1515 | ActivityStack stack = stacks.get(i); |
Filip Gruszczynski | 0e381e2 | 2016-01-14 16:31:33 -0800 | [diff] [blame] | 1516 | if (stack != this && stack.isFocusable() |
Wale Ogunwale | 8051c5c | 2016-03-04 10:27:32 -0800 | [diff] [blame] | 1517 | && stack.getStackVisibilityLocked(null) != STACK_INVISIBLE) { |
Wale Ogunwale | d697cea | 2015-02-20 17:19:49 -0800 | [diff] [blame] | 1518 | return stack; |
| 1519 | } |
| 1520 | } |
| 1521 | } |
| 1522 | return null; |
| 1523 | } |
| 1524 | |
Wale Ogunwale | b34a7ad | 2015-08-14 11:05:30 -0700 | [diff] [blame] | 1525 | /** Returns true if the stack contains a fullscreen task. */ |
| 1526 | private boolean hasFullscreenTask() { |
| 1527 | for (int i = mTaskHistory.size() - 1; i >= 0; --i) { |
| 1528 | final TaskRecord task = mTaskHistory.get(i); |
| 1529 | if (task.mFullscreen) { |
| 1530 | return true; |
| 1531 | } |
| 1532 | } |
| 1533 | return false; |
| 1534 | } |
| 1535 | |
Wale Ogunwale | 8051c5c | 2016-03-04 10:27:32 -0800 | [diff] [blame] | 1536 | /** |
| 1537 | * Returns true if the stack is translucent and can have other contents visible behind it if |
| 1538 | * needed. A stack is considered translucent if it don't contain a visible or |
| 1539 | * starting (about to be visible) activity that is fullscreen (opaque). |
| 1540 | * @param starting The currently starting activity or null if there is none. |
Wale Ogunwale | 56d75cf | 2016-03-09 15:14:47 -0800 | [diff] [blame] | 1541 | * @param stackBehindId The id of the stack directly behind this one. |
Wale Ogunwale | 8051c5c | 2016-03-04 10:27:32 -0800 | [diff] [blame] | 1542 | */ |
Wale Ogunwale | 56d75cf | 2016-03-09 15:14:47 -0800 | [diff] [blame] | 1543 | private boolean isStackTranslucent(ActivityRecord starting, int stackBehindId) { |
Wale Ogunwale | 8051c5c | 2016-03-04 10:27:32 -0800 | [diff] [blame] | 1544 | for (int taskNdx = mTaskHistory.size() - 1; taskNdx >= 0; --taskNdx) { |
| 1545 | final TaskRecord task = mTaskHistory.get(taskNdx); |
Wale Ogunwale | 1e3523c | 2015-09-16 13:11:10 -0700 | [diff] [blame] | 1546 | final ArrayList<ActivityRecord> activities = task.mActivities; |
| 1547 | for (int activityNdx = activities.size() - 1; activityNdx >= 0; --activityNdx) { |
| 1548 | final ActivityRecord r = activities.get(activityNdx); |
Wale Ogunwale | b34a7ad | 2015-08-14 11:05:30 -0700 | [diff] [blame] | 1549 | |
Wale Ogunwale | 56d75cf | 2016-03-09 15:14:47 -0800 | [diff] [blame] | 1550 | if (r.finishing) { |
| 1551 | // We don't factor in finishing activities when determining translucency since |
| 1552 | // they will be gone soon. |
| 1553 | continue; |
| 1554 | } |
| 1555 | |
| 1556 | if (!r.visible && r != starting) { |
| 1557 | // Also ignore invisible activities that are not the currently starting |
| 1558 | // activity (about to be visible). |
| 1559 | continue; |
| 1560 | } |
| 1561 | |
| 1562 | if (r.fullscreen) { |
| 1563 | // Stack isn't translucent if it has at least one fullscreen activity |
| 1564 | // that is visible. |
| 1565 | return false; |
| 1566 | } |
| 1567 | |
| 1568 | if (!isHomeStack() && r.frontOfTask |
| 1569 | && task.isOverHomeStack() && stackBehindId != HOME_STACK_ID) { |
| 1570 | // Stack isn't translucent if it's top activity should have the home stack |
| 1571 | // behind it and the stack currently behind it isn't the home stack. |
Wale Ogunwale | 1e3523c | 2015-09-16 13:11:10 -0700 | [diff] [blame] | 1572 | return false; |
Wale Ogunwale | b34a7ad | 2015-08-14 11:05:30 -0700 | [diff] [blame] | 1573 | } |
| 1574 | } |
| 1575 | } |
Wale Ogunwale | 1e3523c | 2015-09-16 13:11:10 -0700 | [diff] [blame] | 1576 | return true; |
Wale Ogunwale | b34a7ad | 2015-08-14 11:05:30 -0700 | [diff] [blame] | 1577 | } |
| 1578 | |
Filip Gruszczynski | 0e381e2 | 2016-01-14 16:31:33 -0800 | [diff] [blame] | 1579 | /** |
| 1580 | * Returns stack's visibility: {@link #STACK_INVISIBLE}, {@link #STACK_VISIBLE} or |
| 1581 | * {@link #STACK_VISIBLE_ACTIVITY_BEHIND}. |
Wale Ogunwale | 8051c5c | 2016-03-04 10:27:32 -0800 | [diff] [blame] | 1582 | * @param starting The currently starting activity or null if there is none. |
Filip Gruszczynski | 0e381e2 | 2016-01-14 16:31:33 -0800 | [diff] [blame] | 1583 | */ |
Wale Ogunwale | 8051c5c | 2016-03-04 10:27:32 -0800 | [diff] [blame] | 1584 | int getStackVisibilityLocked(ActivityRecord starting) { |
Jose Lima | 7ba7125 | 2014-04-30 12:59:27 -0700 | [diff] [blame] | 1585 | if (!isAttached()) { |
Filip Gruszczynski | 0e381e2 | 2016-01-14 16:31:33 -0800 | [diff] [blame] | 1586 | return STACK_INVISIBLE; |
Jose Lima | 7ba7125 | 2014-04-30 12:59:27 -0700 | [diff] [blame] | 1587 | } |
| 1588 | |
Wale Ogunwale | 1e60e0c | 2015-10-28 13:36:10 -0700 | [diff] [blame] | 1589 | if (mStackSupervisor.isFrontStack(this) || mStackSupervisor.isFocusedStack(this)) { |
Filip Gruszczynski | 0e381e2 | 2016-01-14 16:31:33 -0800 | [diff] [blame] | 1590 | return STACK_VISIBLE; |
Wale Ogunwale | 99db186 | 2015-10-23 20:08:22 -0700 | [diff] [blame] | 1591 | } |
| 1592 | |
Wale Ogunwale | b34a7ad | 2015-08-14 11:05:30 -0700 | [diff] [blame] | 1593 | final int stackIndex = mStacks.indexOf(this); |
| 1594 | |
| 1595 | if (stackIndex == mStacks.size() - 1) { |
| 1596 | Slog.wtf(TAG, |
| 1597 | "Stack=" + this + " isn't front stack but is at the top of the stack list"); |
Filip Gruszczynski | 0e381e2 | 2016-01-14 16:31:33 -0800 | [diff] [blame] | 1598 | return STACK_INVISIBLE; |
Wale Ogunwale | b34a7ad | 2015-08-14 11:05:30 -0700 | [diff] [blame] | 1599 | } |
| 1600 | |
Chong Zhang | 75b3720 | 2015-12-04 14:16:36 -0800 | [diff] [blame] | 1601 | final boolean isLockscreenShown = mService.mLockScreenShown == LOCK_SCREEN_SHOWN; |
| 1602 | if (isLockscreenShown && !StackId.isAllowedOverLockscreen(mStackId)) { |
Filip Gruszczynski | 0e381e2 | 2016-01-14 16:31:33 -0800 | [diff] [blame] | 1603 | return STACK_INVISIBLE; |
Chong Zhang | 75b3720 | 2015-12-04 14:16:36 -0800 | [diff] [blame] | 1604 | } |
| 1605 | |
Wale Ogunwale | 1e3523c | 2015-09-16 13:11:10 -0700 | [diff] [blame] | 1606 | final ActivityStack focusedStack = mStackSupervisor.getFocusedStack(); |
| 1607 | final int focusedStackId = focusedStack.mStackId; |
| 1608 | |
Jiaquan He | 9bc01a8 | 2016-07-08 10:29:38 -0700 | [diff] [blame] | 1609 | final TaskRecord topFocusedTask = focusedStack.topTask(); |
| 1610 | final boolean isOnTopLauncherFocused = topFocusedTask != null && |
| 1611 | topFocusedTask.isOnTopLauncher(); |
| 1612 | if (isOnTopLauncherFocused) { |
| 1613 | // When an on-top launcher is focused, we should find out whether the freeform stack or |
| 1614 | // the fullscreen stack appears first underneath and has activities to show, and then |
| 1615 | // make it visible. |
| 1616 | boolean behindFullscreenOrFreeForm = false; |
| 1617 | for (int stackBehindFocusedIndex = mStacks.indexOf(focusedStack) - 1; |
| 1618 | stackBehindFocusedIndex >= 0; stackBehindFocusedIndex--) { |
| 1619 | ActivityStack stack = mStacks.get(stackBehindFocusedIndex); |
| 1620 | if ((stack.mStackId == FREEFORM_WORKSPACE_STACK_ID |
| 1621 | || stack.mStackId == FULLSCREEN_WORKSPACE_STACK_ID) |
| 1622 | && stack.topRunningActivityLocked() != null) { |
| 1623 | if (stackIndex == stackBehindFocusedIndex) { |
| 1624 | return !behindFullscreenOrFreeForm ? STACK_VISIBLE : STACK_INVISIBLE; |
| 1625 | } |
| 1626 | behindFullscreenOrFreeForm = true; |
| 1627 | } |
| 1628 | } |
| 1629 | } |
Jiaquan He | c4dcd4b | 2016-07-29 15:31:10 -0700 | [diff] [blame] | 1630 | // If an on-top launcher is on the top of the home stack but the home stack is not focused, |
| 1631 | // then the whole stack should be invisible. |
| 1632 | TaskRecord topTask = topTask(); |
| 1633 | if (mStackId != focusedStackId && topTask != null && topTask.isOnTopLauncher()) { |
| 1634 | // We're here mostly because the on-top launcher didn't have a chance to move itself to |
| 1635 | // back. We should move it to back as soon as possible to avoid other activities |
| 1636 | // returning to it or other visibility issues. |
| 1637 | moveTaskToBackLocked(topTask.taskId); |
| 1638 | return STACK_INVISIBLE; |
| 1639 | } |
Jiaquan He | 9bc01a8 | 2016-07-08 10:29:38 -0700 | [diff] [blame] | 1640 | |
Wale Ogunwale | cff4aa3 | 2015-12-11 10:44:25 -0800 | [diff] [blame] | 1641 | if (mStackId == FULLSCREEN_WORKSPACE_STACK_ID |
Filip Gruszczynski | 4e7fe71 | 2016-01-13 13:22:44 -0800 | [diff] [blame] | 1642 | && hasVisibleBehindActivity() && focusedStackId == HOME_STACK_ID |
| 1643 | && !focusedStack.topActivity().fullscreen) { |
Wale Ogunwale | cff4aa3 | 2015-12-11 10:44:25 -0800 | [diff] [blame] | 1644 | // The fullscreen stack should be visible if it has a visible behind activity behind |
Filip Gruszczynski | 4e7fe71 | 2016-01-13 13:22:44 -0800 | [diff] [blame] | 1645 | // the home stack that is translucent. |
Filip Gruszczynski | 0e381e2 | 2016-01-14 16:31:33 -0800 | [diff] [blame] | 1646 | return STACK_VISIBLE_ACTIVITY_BEHIND; |
Wale Ogunwale | cff4aa3 | 2015-12-11 10:44:25 -0800 | [diff] [blame] | 1647 | } |
| 1648 | |
Wale Ogunwale | 1e3523c | 2015-09-16 13:11:10 -0700 | [diff] [blame] | 1649 | if (mStackId == DOCKED_STACK_ID) { |
Wale Ogunwale | b1faf60 | 2016-01-27 09:12:31 -0800 | [diff] [blame] | 1650 | // Docked stack is always visible, except in the case where the top running activity |
Jorim Jaggi | 42625d1b | 2016-02-11 20:11:07 -0800 | [diff] [blame] | 1651 | // task in the focus stack doesn't support any form of resizing but we show it for the |
| 1652 | // home task even though it's not resizable. |
Wale Ogunwale | d26176f | 2016-01-25 20:04:04 -0800 | [diff] [blame] | 1653 | final ActivityRecord r = focusedStack.topRunningActivityLocked(); |
Wale Ogunwale | b1faf60 | 2016-01-27 09:12:31 -0800 | [diff] [blame] | 1654 | final TaskRecord task = r != null ? r.task : null; |
Jorim Jaggi | 42625d1b | 2016-02-11 20:11:07 -0800 | [diff] [blame] | 1655 | return task == null || task.canGoInDockedStack() || task.isHomeTask() ? STACK_VISIBLE |
| 1656 | : STACK_INVISIBLE; |
Wale Ogunwale | 1e3523c | 2015-09-16 13:11:10 -0700 | [diff] [blame] | 1657 | } |
| 1658 | |
Wale Ogunwale | 56d75cf | 2016-03-09 15:14:47 -0800 | [diff] [blame] | 1659 | // Find the first stack behind focused stack that actually got something visible. |
| 1660 | int stackBehindFocusedIndex = mStacks.indexOf(focusedStack) - 1; |
| 1661 | while (stackBehindFocusedIndex >= 0 && |
| 1662 | mStacks.get(stackBehindFocusedIndex).topRunningActivityLocked() == null) { |
| 1663 | stackBehindFocusedIndex--; |
Chong Zhang | b16cf34 | 2015-11-12 17:22:40 -0800 | [diff] [blame] | 1664 | } |
Wale Ogunwale | 99db186 | 2015-10-23 20:08:22 -0700 | [diff] [blame] | 1665 | if ((focusedStackId == DOCKED_STACK_ID || focusedStackId == PINNED_STACK_ID) |
Wale Ogunwale | 56d75cf | 2016-03-09 15:14:47 -0800 | [diff] [blame] | 1666 | && stackIndex == stackBehindFocusedIndex) { |
Wale Ogunwale | 99db186 | 2015-10-23 20:08:22 -0700 | [diff] [blame] | 1667 | // Stacks directly behind the docked or pinned stack are always visible. |
Filip Gruszczynski | 0e381e2 | 2016-01-14 16:31:33 -0800 | [diff] [blame] | 1668 | return STACK_VISIBLE; |
Wale Ogunwale | 1e3523c | 2015-09-16 13:11:10 -0700 | [diff] [blame] | 1669 | } |
| 1670 | |
Wale Ogunwale | 56d75cf | 2016-03-09 15:14:47 -0800 | [diff] [blame] | 1671 | final int stackBehindFocusedId = (stackBehindFocusedIndex >= 0) |
| 1672 | ? mStacks.get(stackBehindFocusedIndex).mStackId : INVALID_STACK_ID; |
| 1673 | |
Wale Ogunwale | bd26d2a | 2015-09-22 22:08:37 -0700 | [diff] [blame] | 1674 | if (focusedStackId == FULLSCREEN_WORKSPACE_STACK_ID |
Wale Ogunwale | 56d75cf | 2016-03-09 15:14:47 -0800 | [diff] [blame] | 1675 | && focusedStack.isStackTranslucent(starting, stackBehindFocusedId)) { |
Wale Ogunwale | bd26d2a | 2015-09-22 22:08:37 -0700 | [diff] [blame] | 1676 | // Stacks behind the fullscreen stack with a translucent activity are always |
| 1677 | // visible so they can act as a backdrop to the translucent activity. |
| 1678 | // For example, dialog activities |
Wale Ogunwale | 56d75cf | 2016-03-09 15:14:47 -0800 | [diff] [blame] | 1679 | if (stackIndex == stackBehindFocusedIndex) { |
Filip Gruszczynski | 0e381e2 | 2016-01-14 16:31:33 -0800 | [diff] [blame] | 1680 | return STACK_VISIBLE; |
Wale Ogunwale | bd26d2a | 2015-09-22 22:08:37 -0700 | [diff] [blame] | 1681 | } |
Wale Ogunwale | 56d75cf | 2016-03-09 15:14:47 -0800 | [diff] [blame] | 1682 | if (stackBehindFocusedIndex >= 0) { |
| 1683 | if ((stackBehindFocusedId == DOCKED_STACK_ID |
| 1684 | || stackBehindFocusedId == PINNED_STACK_ID) |
| 1685 | && stackIndex == (stackBehindFocusedIndex - 1)) { |
Wale Ogunwale | 99db186 | 2015-10-23 20:08:22 -0700 | [diff] [blame] | 1686 | // The stack behind the docked or pinned stack is also visible so we can have a |
| 1687 | // complete backdrop to the translucent activity when the docked stack is up. |
Filip Gruszczynski | 0e381e2 | 2016-01-14 16:31:33 -0800 | [diff] [blame] | 1688 | return STACK_VISIBLE; |
Wale Ogunwale | bd26d2a | 2015-09-22 22:08:37 -0700 | [diff] [blame] | 1689 | } |
| 1690 | } |
Wale Ogunwale | 1e3523c | 2015-09-16 13:11:10 -0700 | [diff] [blame] | 1691 | } |
| 1692 | |
Wale Ogunwale | 3797c22 | 2015-10-27 14:21:58 -0700 | [diff] [blame] | 1693 | if (StackId.isStaticStack(mStackId)) { |
Wale Ogunwale | 1e3523c | 2015-09-16 13:11:10 -0700 | [diff] [blame] | 1694 | // Visibility of any static stack should have been determined by the conditions above. |
Filip Gruszczynski | 0e381e2 | 2016-01-14 16:31:33 -0800 | [diff] [blame] | 1695 | return STACK_INVISIBLE; |
Wale Ogunwale | ddc1cb2 | 2015-07-25 19:23:04 -0700 | [diff] [blame] | 1696 | } |
| 1697 | |
Wale Ogunwale | b34a7ad | 2015-08-14 11:05:30 -0700 | [diff] [blame] | 1698 | for (int i = stackIndex + 1; i < mStacks.size(); i++) { |
Wale Ogunwale | e4a0c57 | 2015-06-30 08:40:31 -0700 | [diff] [blame] | 1699 | final ActivityStack stack = mStacks.get(i); |
Wale Ogunwale | b34a7ad | 2015-08-14 11:05:30 -0700 | [diff] [blame] | 1700 | |
| 1701 | if (!stack.mFullscreen && !stack.hasFullscreenTask()) { |
| 1702 | continue; |
| 1703 | } |
| 1704 | |
Wale Ogunwale | 3797c22 | 2015-10-27 14:21:58 -0700 | [diff] [blame] | 1705 | if (!StackId.isDynamicStacksVisibleBehindAllowed(stack.mStackId)) { |
Wale Ogunwale | 1e3523c | 2015-09-16 13:11:10 -0700 | [diff] [blame] | 1706 | // These stacks can't have any dynamic stacks visible behind them. |
Filip Gruszczynski | 0e381e2 | 2016-01-14 16:31:33 -0800 | [diff] [blame] | 1707 | return STACK_INVISIBLE; |
Todd Kennedy | aab56db | 2015-01-30 09:39:53 -0800 | [diff] [blame] | 1708 | } |
Wale Ogunwale | ddc1cb2 | 2015-07-25 19:23:04 -0700 | [diff] [blame] | 1709 | |
Wale Ogunwale | 56d75cf | 2016-03-09 15:14:47 -0800 | [diff] [blame] | 1710 | if (!stack.isStackTranslucent(starting, INVALID_STACK_ID)) { |
Filip Gruszczynski | 0e381e2 | 2016-01-14 16:31:33 -0800 | [diff] [blame] | 1711 | return STACK_INVISIBLE; |
Jose Lima | 7ba7125 | 2014-04-30 12:59:27 -0700 | [diff] [blame] | 1712 | } |
| 1713 | } |
| 1714 | |
Filip Gruszczynski | 0e381e2 | 2016-01-14 16:31:33 -0800 | [diff] [blame] | 1715 | return STACK_VISIBLE; |
Jose Lima | 7ba7125 | 2014-04-30 12:59:27 -0700 | [diff] [blame] | 1716 | } |
| 1717 | |
Chong Zhang | fdcc4d4 | 2015-10-14 16:50:12 -0700 | [diff] [blame] | 1718 | final int rankTaskLayers(int baseLayer) { |
| 1719 | int layer = 0; |
| 1720 | for (int taskNdx = mTaskHistory.size() - 1; taskNdx >= 0; --taskNdx) { |
| 1721 | final TaskRecord task = mTaskHistory.get(taskNdx); |
| 1722 | ActivityRecord r = task.topRunningActivityLocked(); |
| 1723 | if (r == null || r.finishing || !r.visible) { |
| 1724 | task.mLayerRank = -1; |
| 1725 | } else { |
| 1726 | task.mLayerRank = baseLayer + layer++; |
| 1727 | } |
| 1728 | } |
| 1729 | return layer; |
| 1730 | } |
| 1731 | |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 1732 | /** |
| 1733 | * Make sure that all activities that need to be visible (that is, they |
| 1734 | * currently can be seen by the user) actually are. |
| 1735 | */ |
Filip Gruszczynski | bc5a6c5 | 2015-09-22 13:13:24 -0700 | [diff] [blame] | 1736 | final void ensureActivitiesVisibleLocked(ActivityRecord starting, int configChanges, |
| 1737 | boolean preserveWindows) { |
Filip Gruszczynski | 3e85ba2 | 2015-10-05 22:48:30 -0700 | [diff] [blame] | 1738 | ActivityRecord top = topRunningActivityLocked(); |
Filip Gruszczynski | 9104aea | 2015-11-13 16:42:05 -0800 | [diff] [blame] | 1739 | if (DEBUG_VISIBILITY) Slog.v(TAG_VISIBILITY, "ensureActivitiesVisible behind " + top |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 1740 | + " configChanges=0x" + Integer.toHexString(configChanges)); |
Filip Gruszczynski | 21199bd | 2015-12-02 12:49:58 -0800 | [diff] [blame] | 1741 | if (top != null) { |
| 1742 | checkTranslucentActivityWaiting(top); |
| 1743 | } |
Craig Mautner | 5eda9b3 | 2013-07-02 11:58:16 -0700 | [diff] [blame] | 1744 | |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 1745 | // If the top activity is not fullscreen, then we need to |
| 1746 | // make sure any activities under it are now visible. |
Filip Gruszczynski | 21199bd | 2015-12-02 12:49:58 -0800 | [diff] [blame] | 1747 | boolean aboveTop = top != null; |
Wale Ogunwale | 8051c5c | 2016-03-04 10:27:32 -0800 | [diff] [blame] | 1748 | final int stackVisibility = getStackVisibilityLocked(starting); |
Filip Gruszczynski | 0e381e2 | 2016-01-14 16:31:33 -0800 | [diff] [blame] | 1749 | final boolean stackInvisible = stackVisibility != STACK_VISIBLE; |
| 1750 | final boolean stackVisibleBehind = stackVisibility == STACK_VISIBLE_ACTIVITY_BEHIND; |
Wale Ogunwale | c219c0b | 2015-09-12 09:18:07 -0700 | [diff] [blame] | 1751 | boolean behindFullscreenActivity = stackInvisible; |
Andrii Kulian | c11ce7b | 2016-06-27 10:53:53 -0700 | [diff] [blame] | 1752 | boolean resumeNextActivity = mStackSupervisor.isFocusedStack(this) |
| 1753 | && (isInStackLocked(starting) == null); |
Filip Gruszczynski | 0e381e2 | 2016-01-14 16:31:33 -0800 | [diff] [blame] | 1754 | boolean behindTranslucentActivity = false; |
| 1755 | final ActivityRecord visibleBehind = getVisibleBehindActivity(); |
Craig Mautner | b59dcfd | 2013-05-06 13:12:58 -0700 | [diff] [blame] | 1756 | for (int taskNdx = mTaskHistory.size() - 1; taskNdx >= 0; --taskNdx) { |
Craig Mautner | ae7ecab | 2013-09-18 11:48:14 -0700 | [diff] [blame] | 1757 | final TaskRecord task = mTaskHistory.get(taskNdx); |
| 1758 | final ArrayList<ActivityRecord> activities = task.mActivities; |
Craig Mautner | d44711d | 2013-02-23 11:24:36 -0800 | [diff] [blame] | 1759 | for (int activityNdx = activities.size() - 1; activityNdx >= 0; --activityNdx) { |
| 1760 | final ActivityRecord r = activities.get(activityNdx); |
| 1761 | if (r.finishing) { |
Chong Zhang | 22bc851 | 2016-04-07 13:47:18 -0700 | [diff] [blame] | 1762 | // Normally the screenshot will be taken in makeInvisible(). When an activity |
| 1763 | // is finishing, we no longer change its visibility, but we still need to take |
| 1764 | // the screenshots if startPausingLocked decided it should be taken. |
| 1765 | if (r.mUpdateTaskThumbnailWhenHidden) { |
| 1766 | r.updateThumbnailLocked(screenshotActivitiesLocked(r), null); |
| 1767 | r.mUpdateTaskThumbnailWhenHidden = false; |
| 1768 | } |
Craig Mautner | d44711d | 2013-02-23 11:24:36 -0800 | [diff] [blame] | 1769 | continue; |
| 1770 | } |
Filip Gruszczynski | 21199bd | 2015-12-02 12:49:58 -0800 | [diff] [blame] | 1771 | final boolean isTop = r == top; |
| 1772 | if (aboveTop && !isTop) { |
Craig Mautner | d44711d | 2013-02-23 11:24:36 -0800 | [diff] [blame] | 1773 | continue; |
| 1774 | } |
| 1775 | aboveTop = false; |
Wale Ogunwale | e76407c | 2016-05-16 17:04:37 -0700 | [diff] [blame] | 1776 | |
| 1777 | if (shouldBeVisible(r, behindTranslucentActivity, stackVisibleBehind, |
| 1778 | visibleBehind, behindFullscreenActivity)) { |
Filip Gruszczynski | 0e381e2 | 2016-01-14 16:31:33 -0800 | [diff] [blame] | 1779 | if (DEBUG_VISIBILITY) Slog.v(TAG_VISIBILITY, "Make visible? " + r |
| 1780 | + " finishing=" + r.finishing + " state=" + r.state); |
Craig Mautner | d44711d | 2013-02-23 11:24:36 -0800 | [diff] [blame] | 1781 | // First: if this is not the current activity being started, make |
| 1782 | // sure it matches the current configuration. |
Craig Mautner | bb74246 | 2014-07-07 15:28:55 -0700 | [diff] [blame] | 1783 | if (r != starting) { |
Filip Gruszczynski | bc5a6c5 | 2015-09-22 13:13:24 -0700 | [diff] [blame] | 1784 | ensureActivityConfigurationLocked(r, 0, preserveWindows); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 1785 | } |
Craig Mautner | d44711d | 2013-02-23 11:24:36 -0800 | [diff] [blame] | 1786 | |
| 1787 | if (r.app == null || r.app.thread == null) { |
Filip Gruszczynski | 21199bd | 2015-12-02 12:49:58 -0800 | [diff] [blame] | 1788 | if (makeVisibleAndRestartIfNeeded(starting, configChanges, isTop, |
Wale Ogunwale | d046a01 | 2015-12-24 13:05:59 -0800 | [diff] [blame] | 1789 | resumeNextActivity, r)) { |
Filip Gruszczynski | 9104aea | 2015-11-13 16:42:05 -0800 | [diff] [blame] | 1790 | if (activityNdx >= activities.size()) { |
| 1791 | // Record may be removed if its process needs to restart. |
| 1792 | activityNdx = activities.size() - 1; |
| 1793 | } else { |
Wale Ogunwale | d046a01 | 2015-12-24 13:05:59 -0800 | [diff] [blame] | 1794 | resumeNextActivity = false; |
riddle_hsu | 36ee73d | 2015-06-05 16:38:38 +0800 | [diff] [blame] | 1795 | } |
Craig Mautner | d44711d | 2013-02-23 11:24:36 -0800 | [diff] [blame] | 1796 | } |
Craig Mautner | d44711d | 2013-02-23 11:24:36 -0800 | [diff] [blame] | 1797 | } else if (r.visible) { |
Filip Gruszczynski | 21199bd | 2015-12-02 12:49:58 -0800 | [diff] [blame] | 1798 | // If this activity is already visible, then there is nothing to do here. |
Chong Zhang | 371c442 | 2016-05-11 10:48:32 -0700 | [diff] [blame] | 1799 | if (DEBUG_VISIBILITY) Slog.v(TAG_VISIBILITY, |
| 1800 | "Skipping: already visible at " + r); |
| 1801 | |
Filip Gruszczynski | 21199bd | 2015-12-02 12:49:58 -0800 | [diff] [blame] | 1802 | if (handleAlreadyVisible(r)) { |
Wale Ogunwale | d046a01 | 2015-12-24 13:05:59 -0800 | [diff] [blame] | 1803 | resumeNextActivity = false; |
Wale Ogunwale | 85b90ab | 2015-04-27 20:54:47 -0700 | [diff] [blame] | 1804 | } |
Craig Mautner | bb74246 | 2014-07-07 15:28:55 -0700 | [diff] [blame] | 1805 | } else { |
Jorim Jaggi | e66edb1 | 2016-02-05 12:41:17 -0800 | [diff] [blame] | 1806 | makeVisibleIfNeeded(starting, r); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 1807 | } |
Craig Mautner | d44711d | 2013-02-23 11:24:36 -0800 | [diff] [blame] | 1808 | // Aggregate current change flags. |
| 1809 | configChanges |= r.configChangeFlags; |
Filip Gruszczynski | 9104aea | 2015-11-13 16:42:05 -0800 | [diff] [blame] | 1810 | behindFullscreenActivity = updateBehindFullscreen(stackInvisible, |
| 1811 | behindFullscreenActivity, task, r); |
Filip Gruszczynski | 0e381e2 | 2016-01-14 16:31:33 -0800 | [diff] [blame] | 1812 | if (behindFullscreenActivity && !r.fullscreen) { |
| 1813 | behindTranslucentActivity = true; |
| 1814 | } |
Craig Mautner | d44711d | 2013-02-23 11:24:36 -0800 | [diff] [blame] | 1815 | } else { |
Wale Ogunwale | 834c236 | 2016-01-23 18:14:58 -0800 | [diff] [blame] | 1816 | if (DEBUG_VISIBILITY) Slog.v(TAG_VISIBILITY, "Make invisible? " + r |
Filip Gruszczynski | 0e381e2 | 2016-01-14 16:31:33 -0800 | [diff] [blame] | 1817 | + " finishing=" + r.finishing + " state=" + r.state + " stackInvisible=" |
| 1818 | + stackInvisible + " behindFullscreenActivity=" |
| 1819 | + behindFullscreenActivity + " mLaunchTaskBehind=" |
| 1820 | + r.mLaunchTaskBehind); |
| 1821 | makeInvisible(r, visibleBehind); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 1822 | } |
| 1823 | } |
Wale Ogunwale | c219c0b | 2015-09-12 09:18:07 -0700 | [diff] [blame] | 1824 | if (mStackId == FREEFORM_WORKSPACE_STACK_ID) { |
| 1825 | // The visibility of tasks and the activities they contain in freeform stack are |
| 1826 | // determined individually unlike other stacks where the visibility or fullscreen |
| 1827 | // status of an activity in a previous task affects other. |
Filip Gruszczynski | 0e381e2 | 2016-01-14 16:31:33 -0800 | [diff] [blame] | 1828 | behindFullscreenActivity = stackVisibility == STACK_INVISIBLE; |
Wale Ogunwale | 74e2659 | 2016-02-05 11:48:37 -0800 | [diff] [blame] | 1829 | } else if (mStackId == HOME_STACK_ID) { |
Jiaquan He | 9bc01a8 | 2016-07-08 10:29:38 -0700 | [diff] [blame] | 1830 | if (task.isOnTopLauncher()) { |
| 1831 | if (DEBUG_VISIBILITY) Slog.v(TAG_VISIBILITY, "On-top launcher: at " + task |
| 1832 | + " stackInvisible=" + stackInvisible |
| 1833 | + " behindFullscreenActivity=" + behindFullscreenActivity); |
| 1834 | // When an on-top launcher is visible, (e.g. it's on the top of the home stack), |
| 1835 | // other tasks in the home stack could be visible if and only if: |
| 1836 | // - some app is running in the docked stack; |
| 1837 | // - no app is running in either the fullscreen stack or the freefrom stack. |
| 1838 | final ActivityStack dockedStack = mStackSupervisor.getStack(DOCKED_STACK_ID); |
| 1839 | final ActivityStack fullscreenStack = mStackSupervisor.getStack( |
| 1840 | FULLSCREEN_WORKSPACE_STACK_ID); |
| 1841 | final ActivityStack freeformStack = mStackSupervisor.getStack( |
| 1842 | FREEFORM_WORKSPACE_STACK_ID); |
| 1843 | final boolean dockedStackEmpty = dockedStack == null || |
| 1844 | dockedStack.topRunningActivityLocked() == null; |
| 1845 | final boolean fullscreenStackEmpty = fullscreenStack == null || |
| 1846 | fullscreenStack.topRunningActivityLocked() == null; |
| 1847 | final boolean freeformStackEmpty = freeformStack == null || |
| 1848 | freeformStack.topRunningActivityLocked() == null; |
| 1849 | behindFullscreenActivity = dockedStackEmpty || !fullscreenStackEmpty || |
| 1850 | !freeformStackEmpty; |
| 1851 | } else if (task.isHomeTask()) { |
Wale Ogunwale | 74e2659 | 2016-02-05 11:48:37 -0800 | [diff] [blame] | 1852 | if (DEBUG_VISIBILITY) Slog.v(TAG_VISIBILITY, "Home task: at " + task |
| 1853 | + " stackInvisible=" + stackInvisible |
| 1854 | + " behindFullscreenActivity=" + behindFullscreenActivity); |
| 1855 | // No other task in the home stack should be visible behind the home activity. |
| 1856 | // Home activities is usually a translucent activity with the wallpaper behind |
| 1857 | // them. However, when they don't have the wallpaper behind them, we want to |
| 1858 | // show activities in the next application stack behind them vs. another |
| 1859 | // task in the home stack like recents. |
| 1860 | behindFullscreenActivity = true; |
| 1861 | } else if (task.isRecentsTask() |
| 1862 | && task.getTaskToReturnTo() == APPLICATION_ACTIVITY_TYPE) { |
| 1863 | if (DEBUG_VISIBILITY) Slog.v(TAG_VISIBILITY, |
| 1864 | "Recents task returning to app: at " + task |
| 1865 | + " stackInvisible=" + stackInvisible |
| 1866 | + " behindFullscreenActivity=" + behindFullscreenActivity); |
| 1867 | // We don't want any other tasks in the home stack visible if the recents |
| 1868 | // activity is going to be returning to an application activity type. |
| 1869 | // We do this to preserve the visible order the user used to get into the |
| 1870 | // recents activity. The recents activity is normally translucent and if it |
| 1871 | // doesn't have the wallpaper behind it the next activity in the home stack |
| 1872 | // shouldn't be visible when the home stack is brought to the front to display |
| 1873 | // the recents activity from an app. |
| 1874 | behindFullscreenActivity = true; |
| 1875 | } |
| 1876 | |
Wale Ogunwale | c219c0b | 2015-09-12 09:18:07 -0700 | [diff] [blame] | 1877 | } |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 1878 | } |
Craig Mautner | eb8abf7 | 2014-07-02 15:04:09 -0700 | [diff] [blame] | 1879 | |
| 1880 | if (mTranslucentActivityWaiting != null && |
| 1881 | mUndrawnActivitiesBelowTopTranslucent.isEmpty()) { |
| 1882 | // Nothing is getting drawn or everything was already visible, don't wait for timeout. |
| 1883 | notifyActivityDrawnLocked(null); |
| 1884 | } |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 1885 | } |
Craig Mautner | 5854780 | 2013-03-05 08:23:53 -0800 | [diff] [blame] | 1886 | |
Wale Ogunwale | e76407c | 2016-05-16 17:04:37 -0700 | [diff] [blame] | 1887 | /** Return true if the input activity should be made visible */ |
| 1888 | private boolean shouldBeVisible(ActivityRecord r, boolean behindTranslucentActivity, |
| 1889 | boolean stackVisibleBehind, ActivityRecord visibleBehind, |
| 1890 | boolean behindFullscreenActivity) { |
Wale Ogunwale | e76407c | 2016-05-16 17:04:37 -0700 | [diff] [blame] | 1891 | |
Chong Zhang | 8776197 | 2016-08-22 13:53:24 -0700 | [diff] [blame^] | 1892 | if (r == null || !r.okToShowLocked()) { |
Wale Ogunwale | e76407c | 2016-05-16 17:04:37 -0700 | [diff] [blame] | 1893 | return false; |
| 1894 | } |
| 1895 | |
Wale Ogunwale | 8c09c7d | 2016-05-23 09:10:24 -0700 | [diff] [blame] | 1896 | // mLaunchingBehind: Activities launching behind are at the back of the task stack |
| 1897 | // but must be drawn initially for the animation as though they were visible. |
| 1898 | final boolean activityVisibleBehind = |
| 1899 | (behindTranslucentActivity || stackVisibleBehind) && visibleBehind == r; |
| 1900 | |
Wale Ogunwale | e76407c | 2016-05-16 17:04:37 -0700 | [diff] [blame] | 1901 | boolean isVisible = |
| 1902 | !behindFullscreenActivity || r.mLaunchTaskBehind || activityVisibleBehind; |
| 1903 | |
Wale Ogunwale | ca2af9e | 2016-05-26 14:43:19 -0700 | [diff] [blame] | 1904 | if (mService.mSupportsLeanbackOnly && isVisible && r.isRecentsActivity()) { |
| 1905 | // On devices that support leanback only (Android TV), Recents activity can only be |
| 1906 | // visible if the home stack is the focused stack or we are in split-screen mode. |
Wale Ogunwale | 8c09c7d | 2016-05-23 09:10:24 -0700 | [diff] [blame] | 1907 | isVisible = mStackSupervisor.getStack(DOCKED_STACK_ID) != null |
| 1908 | || mStackSupervisor.isFocusedStack(this); |
Wale Ogunwale | e76407c | 2016-05-16 17:04:37 -0700 | [diff] [blame] | 1909 | } |
| 1910 | |
| 1911 | return isVisible; |
| 1912 | } |
| 1913 | |
Filip Gruszczynski | 9104aea | 2015-11-13 16:42:05 -0800 | [diff] [blame] | 1914 | private void checkTranslucentActivityWaiting(ActivityRecord top) { |
| 1915 | if (mTranslucentActivityWaiting != top) { |
| 1916 | mUndrawnActivitiesBelowTopTranslucent.clear(); |
| 1917 | if (mTranslucentActivityWaiting != null) { |
| 1918 | // Call the callback with a timeout indication. |
| 1919 | notifyActivityDrawnLocked(null); |
| 1920 | mTranslucentActivityWaiting = null; |
| 1921 | } |
| 1922 | mHandler.removeMessages(TRANSLUCENT_TIMEOUT_MSG); |
| 1923 | } |
| 1924 | } |
| 1925 | |
| 1926 | private boolean makeVisibleAndRestartIfNeeded(ActivityRecord starting, int configChanges, |
Wale Ogunwale | d046a01 | 2015-12-24 13:05:59 -0800 | [diff] [blame] | 1927 | boolean isTop, boolean andResume, ActivityRecord r) { |
Filip Gruszczynski | 9104aea | 2015-11-13 16:42:05 -0800 | [diff] [blame] | 1928 | // We need to make sure the app is running if it's the top, or it is just made visible from |
| 1929 | // invisible. If the app is already visible, it must have died while it was visible. In this |
| 1930 | // case, we'll show the dead window but will not restart the app. Otherwise we could end up |
| 1931 | // thrashing. |
Filip Gruszczynski | 21199bd | 2015-12-02 12:49:58 -0800 | [diff] [blame] | 1932 | if (isTop || !r.visible) { |
Filip Gruszczynski | 9104aea | 2015-11-13 16:42:05 -0800 | [diff] [blame] | 1933 | // This activity needs to be visible, but isn't even running... |
| 1934 | // get it started and resume if no other stack in this stack is resumed. |
| 1935 | if (DEBUG_VISIBILITY) Slog.v(TAG_VISIBILITY, "Start and freeze screen for " + r); |
| 1936 | if (r != starting) { |
| 1937 | r.startFreezingScreenLocked(r.app, configChanges); |
| 1938 | } |
| 1939 | if (!r.visible || r.mLaunchTaskBehind) { |
| 1940 | if (DEBUG_VISIBILITY) Slog.v(TAG_VISIBILITY, "Starting and making visible: " + r); |
| 1941 | setVisible(r, true); |
| 1942 | } |
| 1943 | if (r != starting) { |
Wale Ogunwale | d046a01 | 2015-12-24 13:05:59 -0800 | [diff] [blame] | 1944 | mStackSupervisor.startSpecificActivityLocked(r, andResume, false); |
Filip Gruszczynski | 9104aea | 2015-11-13 16:42:05 -0800 | [diff] [blame] | 1945 | return true; |
| 1946 | } |
| 1947 | } |
| 1948 | return false; |
| 1949 | } |
| 1950 | |
Filip Gruszczynski | 0e381e2 | 2016-01-14 16:31:33 -0800 | [diff] [blame] | 1951 | private void makeInvisible(ActivityRecord r, ActivityRecord visibleBehind) { |
Filip Gruszczynski | 9104aea | 2015-11-13 16:42:05 -0800 | [diff] [blame] | 1952 | if (!r.visible) { |
| 1953 | if (DEBUG_VISIBILITY) Slog.v(TAG_VISIBILITY, "Already invisible: " + r); |
| 1954 | return; |
| 1955 | } |
| 1956 | // Now for any activities that aren't visible to the user, make sure they no longer are |
| 1957 | // keeping the screen frozen. |
Filip Gruszczynski | 4e7fe71 | 2016-01-13 13:22:44 -0800 | [diff] [blame] | 1958 | if (DEBUG_VISIBILITY) Slog.v(TAG_VISIBILITY, "Making invisible: " + r + " " + r.state); |
Filip Gruszczynski | 9104aea | 2015-11-13 16:42:05 -0800 | [diff] [blame] | 1959 | try { |
| 1960 | setVisible(r, false); |
| 1961 | switch (r.state) { |
| 1962 | case STOPPING: |
| 1963 | case STOPPED: |
| 1964 | if (r.app != null && r.app.thread != null) { |
| 1965 | if (DEBUG_VISIBILITY) Slog.v(TAG_VISIBILITY, |
| 1966 | "Scheduling invisibility: " + r); |
| 1967 | r.app.thread.scheduleWindowVisibility(r.appToken, false); |
| 1968 | } |
| 1969 | break; |
| 1970 | |
| 1971 | case INITIALIZING: |
| 1972 | case RESUMED: |
| 1973 | case PAUSING: |
| 1974 | case PAUSED: |
| 1975 | // This case created for transitioning activities from |
| 1976 | // translucent to opaque {@link Activity#convertToOpaque}. |
Filip Gruszczynski | 0e381e2 | 2016-01-14 16:31:33 -0800 | [diff] [blame] | 1977 | if (visibleBehind == r) { |
Filip Gruszczynski | 9104aea | 2015-11-13 16:42:05 -0800 | [diff] [blame] | 1978 | releaseBackgroundResources(r); |
| 1979 | } else { |
Chong Zhang | 46b1ac6 | 2016-02-18 17:53:57 -0800 | [diff] [blame] | 1980 | addToStopping(r, true /* immediate */); |
Filip Gruszczynski | 9104aea | 2015-11-13 16:42:05 -0800 | [diff] [blame] | 1981 | } |
| 1982 | break; |
| 1983 | |
| 1984 | default: |
| 1985 | break; |
| 1986 | } |
| 1987 | } catch (Exception e) { |
| 1988 | // Just skip on any failure; we'll make it visible when it next restarts. |
| 1989 | Slog.w(TAG, "Exception thrown making hidden: " + r.intent.getComponent(), e); |
| 1990 | } |
| 1991 | } |
| 1992 | |
| 1993 | private boolean updateBehindFullscreen(boolean stackInvisible, boolean behindFullscreenActivity, |
| 1994 | TaskRecord task, ActivityRecord r) { |
| 1995 | if (r.fullscreen) { |
Filip Gruszczynski | 9104aea | 2015-11-13 16:42:05 -0800 | [diff] [blame] | 1996 | if (DEBUG_VISIBILITY) Slog.v(TAG_VISIBILITY, "Fullscreen: at " + r |
Wale Ogunwale | 673cbd2 | 2016-01-30 18:30:55 -0800 | [diff] [blame] | 1997 | + " stackInvisible=" + stackInvisible |
| 1998 | + " behindFullscreenActivity=" + behindFullscreenActivity); |
Filip Gruszczynski | 0e381e2 | 2016-01-14 16:31:33 -0800 | [diff] [blame] | 1999 | // At this point, nothing else needs to be shown in this task. |
Filip Gruszczynski | 9104aea | 2015-11-13 16:42:05 -0800 | [diff] [blame] | 2000 | behindFullscreenActivity = true; |
Wale Ogunwale | 74e2659 | 2016-02-05 11:48:37 -0800 | [diff] [blame] | 2001 | } else if (!isHomeStack() && r.frontOfTask && task.isOverHomeStack()) { |
Filip Gruszczynski | 9104aea | 2015-11-13 16:42:05 -0800 | [diff] [blame] | 2002 | if (DEBUG_VISIBILITY) Slog.v(TAG_VISIBILITY, "Showing home: at " + r |
| 2003 | + " stackInvisible=" + stackInvisible |
| 2004 | + " behindFullscreenActivity=" + behindFullscreenActivity); |
Filip Gruszczynski | 0e381e2 | 2016-01-14 16:31:33 -0800 | [diff] [blame] | 2005 | behindFullscreenActivity = true; |
Filip Gruszczynski | 9104aea | 2015-11-13 16:42:05 -0800 | [diff] [blame] | 2006 | } |
| 2007 | return behindFullscreenActivity; |
| 2008 | } |
| 2009 | |
Jorim Jaggi | e66edb1 | 2016-02-05 12:41:17 -0800 | [diff] [blame] | 2010 | private void makeVisibleIfNeeded(ActivityRecord starting, ActivityRecord r) { |
| 2011 | |
Filip Gruszczynski | 9104aea | 2015-11-13 16:42:05 -0800 | [diff] [blame] | 2012 | // This activity is not currently visible, but is running. Tell it to become visible. |
Jorim Jaggi | e66edb1 | 2016-02-05 12:41:17 -0800 | [diff] [blame] | 2013 | if (r.state == ActivityState.RESUMED || r == starting) { |
Chong Zhang | e05db74 | 2016-02-16 16:58:37 -0800 | [diff] [blame] | 2014 | if (DEBUG_VISIBILITY) Slog.d(TAG_VISIBILITY, |
| 2015 | "Not making visible, r=" + r + " state=" + r.state + " starting=" + starting); |
Jorim Jaggi | e66edb1 | 2016-02-05 12:41:17 -0800 | [diff] [blame] | 2016 | return; |
| 2017 | } |
| 2018 | |
| 2019 | // If this activity is paused, tell it to now show its window. |
| 2020 | if (DEBUG_VISIBILITY) Slog.v(TAG_VISIBILITY, |
| 2021 | "Making visible and scheduling visibility: " + r); |
| 2022 | try { |
| 2023 | if (mTranslucentActivityWaiting != null) { |
| 2024 | r.updateOptionsLocked(r.returningOptions); |
| 2025 | mUndrawnActivitiesBelowTopTranslucent.add(r); |
Filip Gruszczynski | 9104aea | 2015-11-13 16:42:05 -0800 | [diff] [blame] | 2026 | } |
Jorim Jaggi | e66edb1 | 2016-02-05 12:41:17 -0800 | [diff] [blame] | 2027 | setVisible(r, true); |
| 2028 | r.sleeping = false; |
| 2029 | r.app.pendingUiClean = true; |
| 2030 | r.app.thread.scheduleWindowVisibility(r.appToken, true); |
Jorim Jaggi | d47e7e1 | 2016-03-01 09:57:38 +0100 | [diff] [blame] | 2031 | // The activity may be waiting for stop, but that is no longer |
| 2032 | // appropriate for it. |
| 2033 | mStackSupervisor.mStoppingActivities.remove(r); |
| 2034 | mStackSupervisor.mGoingToSleepActivities.remove(r); |
Jorim Jaggi | e66edb1 | 2016-02-05 12:41:17 -0800 | [diff] [blame] | 2035 | } catch (Exception e) { |
| 2036 | // Just skip on any failure; we'll make it |
| 2037 | // visible when it next restarts. |
| 2038 | Slog.w(TAG, "Exception thrown making visibile: " + r.intent.getComponent(), e); |
Filip Gruszczynski | 9104aea | 2015-11-13 16:42:05 -0800 | [diff] [blame] | 2039 | } |
Chong Zhang | 371c442 | 2016-05-11 10:48:32 -0700 | [diff] [blame] | 2040 | handleAlreadyVisible(r); |
Filip Gruszczynski | 9104aea | 2015-11-13 16:42:05 -0800 | [diff] [blame] | 2041 | } |
| 2042 | |
Filip Gruszczynski | 21199bd | 2015-12-02 12:49:58 -0800 | [diff] [blame] | 2043 | private boolean handleAlreadyVisible(ActivityRecord r) { |
Filip Gruszczynski | 9104aea | 2015-11-13 16:42:05 -0800 | [diff] [blame] | 2044 | r.stopFreezingScreenLocked(false); |
| 2045 | try { |
| 2046 | if (r.returningOptions != null) { |
| 2047 | r.app.thread.scheduleOnNewActivityOptions(r.appToken, r.returningOptions); |
| 2048 | } |
| 2049 | } catch(RemoteException e) { |
| 2050 | } |
| 2051 | return r.state == ActivityState.RESUMED; |
| 2052 | } |
| 2053 | |
Todd Kennedy | aab56db | 2015-01-30 09:39:53 -0800 | [diff] [blame] | 2054 | void convertActivityToTranslucent(ActivityRecord r) { |
Craig Mautner | 5eda9b3 | 2013-07-02 11:58:16 -0700 | [diff] [blame] | 2055 | mTranslucentActivityWaiting = r; |
| 2056 | mUndrawnActivitiesBelowTopTranslucent.clear(); |
| 2057 | mHandler.sendEmptyMessageDelayed(TRANSLUCENT_TIMEOUT_MSG, TRANSLUCENT_CONVERSION_TIMEOUT); |
| 2058 | } |
| 2059 | |
Dianne Hackborn | b5a380d | 2015-05-20 18:18:46 -0700 | [diff] [blame] | 2060 | void clearOtherAppTimeTrackers(AppTimeTracker except) { |
| 2061 | for (int taskNdx = mTaskHistory.size() - 1; taskNdx >= 0; --taskNdx) { |
| 2062 | final TaskRecord task = mTaskHistory.get(taskNdx); |
| 2063 | final ArrayList<ActivityRecord> activities = task.mActivities; |
| 2064 | for (int activityNdx = activities.size() - 1; activityNdx >= 0; --activityNdx) { |
| 2065 | final ActivityRecord r = activities.get(activityNdx); |
| 2066 | if ( r.appTimeTracker != except) { |
| 2067 | r.appTimeTracker = null; |
| 2068 | } |
| 2069 | } |
| 2070 | } |
| 2071 | } |
| 2072 | |
Craig Mautner | 5eda9b3 | 2013-07-02 11:58:16 -0700 | [diff] [blame] | 2073 | /** |
| 2074 | * Called as activities below the top translucent activity are redrawn. When the last one is |
| 2075 | * redrawn notify the top activity by calling |
| 2076 | * {@link Activity#onTranslucentConversionComplete}. |
| 2077 | * |
| 2078 | * @param r The most recent background activity to be drawn. Or, if r is null then a timeout |
| 2079 | * occurred and the activity will be notified immediately. |
| 2080 | */ |
| 2081 | void notifyActivityDrawnLocked(ActivityRecord r) { |
Craig Mautner | 6985bad | 2014-04-21 15:22:06 -0700 | [diff] [blame] | 2082 | mActivityContainer.setDrawn(); |
Craig Mautner | 5eda9b3 | 2013-07-02 11:58:16 -0700 | [diff] [blame] | 2083 | if ((r == null) |
| 2084 | || (mUndrawnActivitiesBelowTopTranslucent.remove(r) && |
| 2085 | mUndrawnActivitiesBelowTopTranslucent.isEmpty())) { |
| 2086 | // The last undrawn activity below the top has just been drawn. If there is an |
| 2087 | // opaque activity at the top, notify it that it can become translucent safely now. |
| 2088 | final ActivityRecord waitingActivity = mTranslucentActivityWaiting; |
| 2089 | mTranslucentActivityWaiting = null; |
| 2090 | mUndrawnActivitiesBelowTopTranslucent.clear(); |
| 2091 | mHandler.removeMessages(TRANSLUCENT_TIMEOUT_MSG); |
| 2092 | |
Craig Mautner | 71dd1b6 | 2014-02-18 15:48:52 -0800 | [diff] [blame] | 2093 | if (waitingActivity != null) { |
| 2094 | mWindowManager.setWindowOpaque(waitingActivity.appToken, false); |
| 2095 | if (waitingActivity.app != null && waitingActivity.app.thread != null) { |
| 2096 | try { |
| 2097 | waitingActivity.app.thread.scheduleTranslucentConversionComplete( |
| 2098 | waitingActivity.appToken, r != null); |
| 2099 | } catch (RemoteException e) { |
| 2100 | } |
Craig Mautner | 5eda9b3 | 2013-07-02 11:58:16 -0700 | [diff] [blame] | 2101 | } |
| 2102 | } |
| 2103 | } |
| 2104 | } |
| 2105 | |
Craig Mautner | a61bc65 | 2013-10-28 15:43:18 -0700 | [diff] [blame] | 2106 | /** If any activities below the top running one are in the INITIALIZING state and they have a |
| 2107 | * starting window displayed then remove that starting window. It is possible that the activity |
| 2108 | * in this state will never resumed in which case that starting window will be orphaned. */ |
| 2109 | void cancelInitializingActivities() { |
Filip Gruszczynski | 3e85ba2 | 2015-10-05 22:48:30 -0700 | [diff] [blame] | 2110 | final ActivityRecord topActivity = topRunningActivityLocked(); |
Craig Mautner | a61bc65 | 2013-10-28 15:43:18 -0700 | [diff] [blame] | 2111 | boolean aboveTop = true; |
Wale Ogunwale | 6874114 | 2016-05-17 09:40:02 -0700 | [diff] [blame] | 2112 | // We don't want to clear starting window for activities that aren't behind fullscreen |
| 2113 | // activities as we need to display their starting window until they are done initializing. |
| 2114 | boolean behindFullscreenActivity = false; |
Wale Ogunwale | 98742a5 | 2016-07-12 10:29:12 -0700 | [diff] [blame] | 2115 | |
| 2116 | if (getStackVisibilityLocked(null) == STACK_INVISIBLE) { |
| 2117 | // The stack is not visible, so no activity in it should be displaying a starting |
| 2118 | // window. Mark all activities below top and behind fullscreen. |
| 2119 | aboveTop = false; |
| 2120 | behindFullscreenActivity = true; |
| 2121 | } |
| 2122 | |
Craig Mautner | a61bc65 | 2013-10-28 15:43:18 -0700 | [diff] [blame] | 2123 | for (int taskNdx = mTaskHistory.size() - 1; taskNdx >= 0; --taskNdx) { |
| 2124 | final ArrayList<ActivityRecord> activities = mTaskHistory.get(taskNdx).mActivities; |
| 2125 | for (int activityNdx = activities.size() - 1; activityNdx >= 0; --activityNdx) { |
| 2126 | final ActivityRecord r = activities.get(activityNdx); |
| 2127 | if (aboveTop) { |
| 2128 | if (r == topActivity) { |
| 2129 | aboveTop = false; |
| 2130 | } |
Wale Ogunwale | 6874114 | 2016-05-17 09:40:02 -0700 | [diff] [blame] | 2131 | behindFullscreenActivity |= r.fullscreen; |
Craig Mautner | a61bc65 | 2013-10-28 15:43:18 -0700 | [diff] [blame] | 2132 | continue; |
| 2133 | } |
| 2134 | |
Wale Ogunwale | f40c11b | 2016-02-26 08:16:02 -0800 | [diff] [blame] | 2135 | if (r.state == ActivityState.INITIALIZING |
Wale Ogunwale | 6874114 | 2016-05-17 09:40:02 -0700 | [diff] [blame] | 2136 | && r.mStartingWindowState == STARTING_WINDOW_SHOWN |
| 2137 | && behindFullscreenActivity) { |
Wale Ogunwale | ee006da | 2015-03-30 14:49:25 -0700 | [diff] [blame] | 2138 | if (DEBUG_VISIBILITY) Slog.w(TAG_VISIBILITY, |
| 2139 | "Found orphaned starting window " + r); |
Wale Ogunwale | f40c11b | 2016-02-26 08:16:02 -0800 | [diff] [blame] | 2140 | r.mStartingWindowState = STARTING_WINDOW_REMOVED; |
Craig Mautner | a61bc65 | 2013-10-28 15:43:18 -0700 | [diff] [blame] | 2141 | mWindowManager.removeAppStartingWindow(r.appToken); |
| 2142 | } |
Wale Ogunwale | 6874114 | 2016-05-17 09:40:02 -0700 | [diff] [blame] | 2143 | |
| 2144 | behindFullscreenActivity |= r.fullscreen; |
Craig Mautner | a61bc65 | 2013-10-28 15:43:18 -0700 | [diff] [blame] | 2145 | } |
| 2146 | } |
| 2147 | } |
| 2148 | |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 2149 | /** |
| 2150 | * Ensure that the top activity in the stack is resumed. |
| 2151 | * |
| 2152 | * @param prev The previously resumed activity, for when in the process |
| 2153 | * of pausing; can be null to call from elsewhere. |
Wale Ogunwale | d046a01 | 2015-12-24 13:05:59 -0800 | [diff] [blame] | 2154 | * @param options Activity options. |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 2155 | * |
| 2156 | * @return Returns true if something is being resumed, or false if |
| 2157 | * nothing happened. |
Wale Ogunwale | d046a01 | 2015-12-24 13:05:59 -0800 | [diff] [blame] | 2158 | * |
| 2159 | * NOTE: It is not safe to call this method directly as it can cause an activity in a |
| 2160 | * non-focused stack to be resumed. |
| 2161 | * Use {@link ActivityStackSupervisor#resumeFocusedStackTopActivityLocked} to resume the |
| 2162 | * right activity for the current system state. |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 2163 | */ |
Wale Ogunwale | d046a01 | 2015-12-24 13:05:59 -0800 | [diff] [blame] | 2164 | boolean resumeTopActivityUncheckedLocked(ActivityRecord prev, ActivityOptions options) { |
Craig Mautner | 42d04db | 2014-11-06 12:13:23 -0800 | [diff] [blame] | 2165 | if (mStackSupervisor.inResumeTopActivity) { |
Craig Mautner | 544efa7 | 2014-09-04 16:41:20 -0700 | [diff] [blame] | 2166 | // Don't even start recursing. |
| 2167 | return false; |
| 2168 | } |
| 2169 | |
| 2170 | boolean result = false; |
| 2171 | try { |
| 2172 | // Protect against recursion. |
Craig Mautner | 42d04db | 2014-11-06 12:13:23 -0800 | [diff] [blame] | 2173 | mStackSupervisor.inResumeTopActivity = true; |
| 2174 | if (mService.mLockScreenShown == ActivityManagerService.LOCK_SCREEN_LEAVING) { |
| 2175 | mService.mLockScreenShown = ActivityManagerService.LOCK_SCREEN_HIDDEN; |
Jeff Brown | 9ef9401 | 2014-11-21 13:04:42 -0800 | [diff] [blame] | 2176 | mService.updateSleepIfNeededLocked(); |
Craig Mautner | 42d04db | 2014-11-06 12:13:23 -0800 | [diff] [blame] | 2177 | } |
Craig Mautner | 544efa7 | 2014-09-04 16:41:20 -0700 | [diff] [blame] | 2178 | result = resumeTopActivityInnerLocked(prev, options); |
| 2179 | } finally { |
Craig Mautner | 42d04db | 2014-11-06 12:13:23 -0800 | [diff] [blame] | 2180 | mStackSupervisor.inResumeTopActivity = false; |
Craig Mautner | 544efa7 | 2014-09-04 16:41:20 -0700 | [diff] [blame] | 2181 | } |
| 2182 | return result; |
| 2183 | } |
| 2184 | |
Chong Zhang | 6cda19c | 2016-06-14 19:07:56 -0700 | [diff] [blame] | 2185 | void setResumedActivityLocked(ActivityRecord r, String reason) { |
| 2186 | // TODO: move mResumedActivity to stack supervisor, |
| 2187 | // there should only be 1 global copy of resumed activity. |
| 2188 | mResumedActivity = r; |
Chong Zhang | d2cb311 | 2016-07-20 11:13:22 -0700 | [diff] [blame] | 2189 | r.state = ActivityState.RESUMED; |
Chong Zhang | 6cda19c | 2016-06-14 19:07:56 -0700 | [diff] [blame] | 2190 | mService.setResumedActivityUncheckLocked(r, reason); |
| 2191 | r.task.touchActiveTime(); |
| 2192 | mRecentTasks.addLocked(r.task); |
| 2193 | } |
| 2194 | |
Chong Zhang | 280d332 | 2015-11-03 17:27:26 -0800 | [diff] [blame] | 2195 | private boolean resumeTopActivityInnerLocked(ActivityRecord prev, ActivityOptions options) { |
Wale Ogunwale | ee006da | 2015-03-30 14:49:25 -0700 | [diff] [blame] | 2196 | if (DEBUG_LOCKSCREEN) mService.logLockScreen(""); |
Craig Mautner | 5314a40 | 2013-09-26 12:40:16 -0700 | [diff] [blame] | 2197 | |
Dianne Hackborn | 7622a0f | 2014-09-30 14:31:42 -0700 | [diff] [blame] | 2198 | if (!mService.mBooting && !mService.mBooted) { |
| 2199 | // Not ready yet! |
| 2200 | return false; |
| 2201 | } |
| 2202 | |
Craig Mautner | df88d73 | 2014-01-27 09:21:32 -0800 | [diff] [blame] | 2203 | ActivityRecord parent = mActivityContainer.mParentActivity; |
Craig Mautner | f4c909b | 2014-04-17 18:39:38 -0700 | [diff] [blame] | 2204 | if ((parent != null && parent.state != ActivityState.RESUMED) || |
Craig Mautner | d163e75 | 2014-06-13 17:18:47 -0700 | [diff] [blame] | 2205 | !mActivityContainer.isAttachedLocked()) { |
Craig Mautner | df88d73 | 2014-01-27 09:21:32 -0800 | [diff] [blame] | 2206 | // Do not resume this stack if its parent is not resumed. |
| 2207 | // TODO: If in a loop, make sure that parent stack resumeTopActivity is called 1st. |
| 2208 | return false; |
| 2209 | } |
| 2210 | |
Wale Ogunwale | 2be760d | 2016-02-17 11:16:10 -0800 | [diff] [blame] | 2211 | mStackSupervisor.cancelInitializingActivities(); |
Craig Mautner | a61bc65 | 2013-10-28 15:43:18 -0700 | [diff] [blame] | 2212 | |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 2213 | // Find the first activity that is not finishing. |
Filip Gruszczynski | 3e85ba2 | 2015-10-05 22:48:30 -0700 | [diff] [blame] | 2214 | final ActivityRecord next = topRunningActivityLocked(); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 2215 | |
| 2216 | // Remember how we'll process this pause/resume situation, and ensure |
| 2217 | // that the state is reset however we wind up proceeding. |
Craig Mautner | de4ef02 | 2013-04-07 19:01:33 -0700 | [diff] [blame] | 2218 | final boolean userLeaving = mStackSupervisor.mUserLeaving; |
| 2219 | mStackSupervisor.mUserLeaving = false; |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 2220 | |
Craig Mautner | 84984fa | 2014-06-19 11:19:20 -0700 | [diff] [blame] | 2221 | final TaskRecord prevTask = prev != null ? prev.task : null; |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 2222 | if (next == null) { |
Wale Ogunwale | d697cea | 2015-02-20 17:19:49 -0800 | [diff] [blame] | 2223 | // There are no more activities! |
| 2224 | final String reason = "noMoreActivities"; |
Wale Ogunwale | d34e80c | 2016-03-23 17:08:44 -0700 | [diff] [blame] | 2225 | final int returnTaskType = prevTask == null || !prevTask.isOverHomeStack() |
| 2226 | ? HOME_ACTIVITY_TYPE : prevTask.getTaskToReturnTo(); |
| 2227 | if (!mFullscreen && adjustFocusToNextFocusableStackLocked(returnTaskType, reason)) { |
Wale Ogunwale | d697cea | 2015-02-20 17:19:49 -0800 | [diff] [blame] | 2228 | // Try to move focus to the next visible stack with a running activity if this |
| 2229 | // stack is not covering the entire screen. |
Wale Ogunwale | 4cea0f5 | 2015-12-25 06:30:31 -0800 | [diff] [blame] | 2230 | return mStackSupervisor.resumeFocusedStackTopActivityLocked( |
| 2231 | mStackSupervisor.getFocusedStack(), prev, null); |
Wale Ogunwale | d697cea | 2015-02-20 17:19:49 -0800 | [diff] [blame] | 2232 | } |
Wale Ogunwale | 4cea0f5 | 2015-12-25 06:30:31 -0800 | [diff] [blame] | 2233 | |
Wale Ogunwale | d697cea | 2015-02-20 17:19:49 -0800 | [diff] [blame] | 2234 | // Let's just start up the Launcher... |
Craig Mautner | de4ef02 | 2013-04-07 19:01:33 -0700 | [diff] [blame] | 2235 | ActivityOptions.abort(options); |
Wale Ogunwale | 0fc365c | 2015-05-25 19:35:42 -0700 | [diff] [blame] | 2236 | if (DEBUG_STATES) Slog.d(TAG_STATES, |
| 2237 | "resumeTopActivityLocked: No more activities go home"); |
Craig Mautner | cf910b0 | 2013-04-23 11:23:27 -0700 | [diff] [blame] | 2238 | if (DEBUG_STACK) mStackSupervisor.validateTopActivitiesLocked(); |
Craig Mautner | e0a3884 | 2013-12-16 16:14:02 -0800 | [diff] [blame] | 2239 | // Only resume home if on home display |
Craig Mautner | 84984fa | 2014-06-19 11:19:20 -0700 | [diff] [blame] | 2240 | return isOnHomeDisplay() && |
Wale Ogunwale | d697cea | 2015-02-20 17:19:49 -0800 | [diff] [blame] | 2241 | mStackSupervisor.resumeHomeStackTask(returnTaskType, prev, reason); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 2242 | } |
| 2243 | |
| 2244 | next.delayedResume = false; |
Craig Mautner | 5854780 | 2013-03-05 08:23:53 -0800 | [diff] [blame] | 2245 | |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 2246 | // If the top activity is the resumed one, nothing to do. |
Craig Mautner | de4ef02 | 2013-04-07 19:01:33 -0700 | [diff] [blame] | 2247 | if (mResumedActivity == next && next.state == ActivityState.RESUMED && |
| 2248 | mStackSupervisor.allResumedActivitiesComplete()) { |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 2249 | // Make sure we have executed any pending transitions, since there |
| 2250 | // should be nothing left to do at this point. |
Craig Mautner | ce5f3cb | 2013-04-22 08:58:54 -0700 | [diff] [blame] | 2251 | mWindowManager.executeAppTransition(); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 2252 | mNoAnimActivities.clear(); |
Dianne Hackborn | 8437587 | 2012-06-01 19:03:50 -0700 | [diff] [blame] | 2253 | ActivityOptions.abort(options); |
Wale Ogunwale | 0fc365c | 2015-05-25 19:35:42 -0700 | [diff] [blame] | 2254 | if (DEBUG_STATES) Slog.d(TAG_STATES, |
| 2255 | "resumeTopActivityLocked: Top activity resumed " + next); |
Craig Mautner | cf910b0 | 2013-04-23 11:23:27 -0700 | [diff] [blame] | 2256 | if (DEBUG_STACK) mStackSupervisor.validateTopActivitiesLocked(); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 2257 | return false; |
| 2258 | } |
| 2259 | |
Craig Mautner | 525f3d9 | 2013-05-07 14:01:50 -0700 | [diff] [blame] | 2260 | final TaskRecord nextTask = next.task; |
bulic | ccd23071 | 2014-05-12 14:34:50 -0700 | [diff] [blame] | 2261 | if (prevTask != null && prevTask.stack == this && |
Craig Mautner | 84984fa | 2014-06-19 11:19:20 -0700 | [diff] [blame] | 2262 | prevTask.isOverHomeStack() && prev.finishing && prev.frontOfTask) { |
Craig Mautner | cf910b0 | 2013-04-23 11:23:27 -0700 | [diff] [blame] | 2263 | if (DEBUG_STACK) mStackSupervisor.validateTopActivitiesLocked(); |
Craig Mautner | 525f3d9 | 2013-05-07 14:01:50 -0700 | [diff] [blame] | 2264 | if (prevTask == nextTask) { |
Craig Mautner | 1aa9d0d3f | 2013-12-16 15:58:31 -0800 | [diff] [blame] | 2265 | prevTask.setFrontOfTask(); |
Craig Mautner | 525f3d9 | 2013-05-07 14:01:50 -0700 | [diff] [blame] | 2266 | } else if (prevTask != topTask()) { |
Craig Mautner | 84984fa | 2014-06-19 11:19:20 -0700 | [diff] [blame] | 2267 | // 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] | 2268 | // 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] | 2269 | final int taskNdx = mTaskHistory.indexOf(prevTask) + 1; |
Craig Mautner | 84984fa | 2014-06-19 11:19:20 -0700 | [diff] [blame] | 2270 | mTaskHistory.get(taskNdx).setTaskToReturnTo(HOME_ACTIVITY_TYPE); |
louis_chang | 2d094e9 | 2015-01-21 19:01:52 +0800 | [diff] [blame] | 2271 | } else if (!isOnHomeDisplay()) { |
| 2272 | return false; |
| 2273 | } else if (!isHomeStack()){ |
Wale Ogunwale | 0fc365c | 2015-05-25 19:35:42 -0700 | [diff] [blame] | 2274 | if (DEBUG_STATES) Slog.d(TAG_STATES, |
Craig Mautner | e0a3884 | 2013-12-16 16:14:02 -0800 | [diff] [blame] | 2275 | "resumeTopActivityLocked: Launching home next"); |
Craig Mautner | 84984fa | 2014-06-19 11:19:20 -0700 | [diff] [blame] | 2276 | final int returnTaskType = prevTask == null || !prevTask.isOverHomeStack() ? |
| 2277 | HOME_ACTIVITY_TYPE : prevTask.getTaskToReturnTo(); |
| 2278 | return isOnHomeDisplay() && |
Craig Mautner | 3c878f2 | 2015-01-26 13:57:19 -0800 | [diff] [blame] | 2279 | mStackSupervisor.resumeHomeStackTask(returnTaskType, prev, "prevFinished"); |
Craig Mautner | e418ecd | 2013-05-01 17:02:29 -0700 | [diff] [blame] | 2280 | } |
Craig Mautner | de4ef02 | 2013-04-07 19:01:33 -0700 | [diff] [blame] | 2281 | } |
| 2282 | |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 2283 | // If we are sleeping, and there is no resumed activity, and the top |
| 2284 | // activity is paused, well that is the state we want. |
Fyodor Kupolov | 9b80b94 | 2016-06-16 16:29:05 -0700 | [diff] [blame] | 2285 | if (mService.isSleepingOrShuttingDownLocked() |
p13451 | dbad287 | 2012-04-18 11:39:23 +0900 | [diff] [blame] | 2286 | && mLastPausedActivity == next |
Craig Mautner | 5314a40 | 2013-09-26 12:40:16 -0700 | [diff] [blame] | 2287 | && mStackSupervisor.allPausedActivitiesComplete()) { |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 2288 | // Make sure we have executed any pending transitions, since there |
| 2289 | // should be nothing left to do at this point. |
Craig Mautner | ce5f3cb | 2013-04-22 08:58:54 -0700 | [diff] [blame] | 2290 | mWindowManager.executeAppTransition(); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 2291 | mNoAnimActivities.clear(); |
Dianne Hackborn | 8437587 | 2012-06-01 19:03:50 -0700 | [diff] [blame] | 2292 | ActivityOptions.abort(options); |
Wale Ogunwale | 0fc365c | 2015-05-25 19:35:42 -0700 | [diff] [blame] | 2293 | if (DEBUG_STATES) Slog.d(TAG_STATES, |
| 2294 | "resumeTopActivityLocked: Going to sleep and all paused"); |
Craig Mautner | cf910b0 | 2013-04-23 11:23:27 -0700 | [diff] [blame] | 2295 | if (DEBUG_STACK) mStackSupervisor.validateTopActivitiesLocked(); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 2296 | return false; |
| 2297 | } |
Dianne Hackborn | 80a4af2 | 2012-08-27 19:18:31 -0700 | [diff] [blame] | 2298 | |
| 2299 | // Make sure that the user who owns this activity is started. If not, |
| 2300 | // we will just leave it as is because someone should be bringing |
| 2301 | // another user's activities to the top of the stack. |
Fyodor Kupolov | 610acda | 2015-10-19 18:44:07 -0700 | [diff] [blame] | 2302 | if (!mService.mUserController.hasStartedUserState(next.userId)) { |
Dianne Hackborn | 80a4af2 | 2012-08-27 19:18:31 -0700 | [diff] [blame] | 2303 | Slog.w(TAG, "Skipping resume of top activity " + next |
| 2304 | + ": user " + next.userId + " is stopped"); |
Craig Mautner | cf910b0 | 2013-04-23 11:23:27 -0700 | [diff] [blame] | 2305 | if (DEBUG_STACK) mStackSupervisor.validateTopActivitiesLocked(); |
Dianne Hackborn | 80a4af2 | 2012-08-27 19:18:31 -0700 | [diff] [blame] | 2306 | return false; |
| 2307 | } |
| 2308 | |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 2309 | // The activity may be waiting for stop, but that is no longer |
| 2310 | // appropriate for it. |
Craig Mautner | de4ef02 | 2013-04-07 19:01:33 -0700 | [diff] [blame] | 2311 | mStackSupervisor.mStoppingActivities.remove(next); |
Craig Mautner | 0eea92c | 2013-05-16 13:35:39 -0700 | [diff] [blame] | 2312 | mStackSupervisor.mGoingToSleepActivities.remove(next); |
Dianne Hackborn | 4eba96b | 2011-01-21 13:34:36 -0800 | [diff] [blame] | 2313 | next.sleeping = false; |
Craig Mautner | de4ef02 | 2013-04-07 19:01:33 -0700 | [diff] [blame] | 2314 | mStackSupervisor.mWaitingVisibleActivities.remove(next); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 2315 | |
Wale Ogunwale | ee006da | 2015-03-30 14:49:25 -0700 | [diff] [blame] | 2316 | if (DEBUG_SWITCH) Slog.v(TAG_SWITCH, "Resuming " + next); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 2317 | |
Wale Ogunwale | 5658e4b | 2016-02-12 12:22:19 -0800 | [diff] [blame] | 2318 | // If we are currently pausing an activity, then don't do anything until that is done. |
Craig Mautner | 69ada55 | 2013-04-18 13:51:51 -0700 | [diff] [blame] | 2319 | if (!mStackSupervisor.allPausedActivitiesComplete()) { |
Wale Ogunwale | ee006da | 2015-03-30 14:49:25 -0700 | [diff] [blame] | 2320 | if (DEBUG_SWITCH || DEBUG_PAUSE || DEBUG_STATES) Slog.v(TAG_PAUSE, |
Craig Mautner | ac6f843 | 2013-07-17 13:24:59 -0700 | [diff] [blame] | 2321 | "resumeTopActivityLocked: Skip resume: some activity pausing."); |
Craig Mautner | cf910b0 | 2013-04-23 11:23:27 -0700 | [diff] [blame] | 2322 | if (DEBUG_STACK) mStackSupervisor.validateTopActivitiesLocked(); |
Dianne Hackborn | 621e2fe | 2012-02-16 17:07:33 -0800 | [diff] [blame] | 2323 | return false; |
| 2324 | } |
| 2325 | |
Dianne Hackborn | 3d07c94 | 2015-03-13 18:02:54 -0700 | [diff] [blame] | 2326 | mStackSupervisor.setLaunchSource(next.info.applicationInfo.uid); |
| 2327 | |
Wale Ogunwale | 5658e4b | 2016-02-12 12:22:19 -0800 | [diff] [blame] | 2328 | // We need to start pausing the current activity so the top one can be resumed... |
| 2329 | final boolean dontWaitForPause = (next.info.flags & FLAG_RESUME_WHILE_PAUSING) != 0; |
Wale Ogunwale | 950faff | 2016-08-08 09:51:04 -0700 | [diff] [blame] | 2330 | boolean pausing = mStackSupervisor.pauseBackStacks(userLeaving, next, dontWaitForPause); |
Craig Mautner | eb95786 | 2013-04-24 15:34:32 -0700 | [diff] [blame] | 2331 | if (mResumedActivity != null) { |
Wale Ogunwale | 0fc365c | 2015-05-25 19:35:42 -0700 | [diff] [blame] | 2332 | if (DEBUG_STATES) Slog.d(TAG_STATES, |
| 2333 | "resumeTopActivityLocked: Pausing " + mResumedActivity); |
Wale Ogunwale | 950faff | 2016-08-08 09:51:04 -0700 | [diff] [blame] | 2334 | pausing |= startPausingLocked(userLeaving, false, next, dontWaitForPause); |
Craig Mautner | eb95786 | 2013-04-24 15:34:32 -0700 | [diff] [blame] | 2335 | } |
| 2336 | if (pausing) { |
Wale Ogunwale | 0fc365c | 2015-05-25 19:35:42 -0700 | [diff] [blame] | 2337 | if (DEBUG_SWITCH || DEBUG_STATES) Slog.v(TAG_STATES, |
Craig Mautner | ac6f843 | 2013-07-17 13:24:59 -0700 | [diff] [blame] | 2338 | "resumeTopActivityLocked: Skip resume: need to start pausing"); |
Dianne Hackborn | ad9b3211 | 2012-09-17 15:35:01 -0700 | [diff] [blame] | 2339 | // At this point we want to put the upcoming activity's process |
| 2340 | // at the top of the LRU list, since we know we will be needing it |
| 2341 | // very soon and it would be a waste to let it get killed if it |
| 2342 | // happens to be sitting towards the end. |
| 2343 | if (next.app != null && next.app.thread != null) { |
Dianne Hackborn | db92608 | 2013-10-31 16:32:44 -0700 | [diff] [blame] | 2344 | mService.updateLruProcessLocked(next.app, true, null); |
Dianne Hackborn | ad9b3211 | 2012-09-17 15:35:01 -0700 | [diff] [blame] | 2345 | } |
Craig Mautner | cf910b0 | 2013-04-23 11:23:27 -0700 | [diff] [blame] | 2346 | if (DEBUG_STACK) mStackSupervisor.validateTopActivitiesLocked(); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 2347 | return true; |
Wale Ogunwale | cac5c32 | 2016-05-23 10:56:33 -0700 | [diff] [blame] | 2348 | } else if (mResumedActivity == next && next.state == ActivityState.RESUMED && |
| 2349 | mStackSupervisor.allResumedActivitiesComplete()) { |
| 2350 | // It is possible for the activity to be resumed when we paused back stacks above if the |
| 2351 | // next activity doesn't have to wait for pause to complete. |
| 2352 | // So, nothing else to-do except: |
| 2353 | // Make sure we have executed any pending transitions, since there |
| 2354 | // should be nothing left to do at this point. |
| 2355 | mWindowManager.executeAppTransition(); |
| 2356 | mNoAnimActivities.clear(); |
| 2357 | ActivityOptions.abort(options); |
| 2358 | if (DEBUG_STATES) Slog.d(TAG_STATES, |
| 2359 | "resumeTopActivityLocked: Top activity resumed (dontWaitForPause) " + next); |
| 2360 | if (DEBUG_STACK) mStackSupervisor.validateTopActivitiesLocked(); |
| 2361 | return true; |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 2362 | } |
| 2363 | |
Christopher Tate | d3f175c | 2012-06-14 14:16:54 -0700 | [diff] [blame] | 2364 | // If the most recent activity was noHistory but was only stopped rather |
| 2365 | // than stopped+finished because the device went to sleep, we need to make |
| 2366 | // sure to finish it as we're making a new activity topmost. |
Fyodor Kupolov | 9b80b94 | 2016-06-16 16:29:05 -0700 | [diff] [blame] | 2367 | if (mService.isSleepingLocked() && mLastNoHistoryActivity != null && |
Craig Mautner | 0f92274 | 2013-08-06 08:44:42 -0700 | [diff] [blame] | 2368 | !mLastNoHistoryActivity.finishing) { |
Wale Ogunwale | 0fc365c | 2015-05-25 19:35:42 -0700 | [diff] [blame] | 2369 | if (DEBUG_STATES) Slog.d(TAG_STATES, |
| 2370 | "no-history finish of " + mLastNoHistoryActivity + " on new resume"); |
Craig Mautner | 0f92274 | 2013-08-06 08:44:42 -0700 | [diff] [blame] | 2371 | requestFinishActivityLocked(mLastNoHistoryActivity.appToken, Activity.RESULT_CANCELED, |
Todd Kennedy | 539db51 | 2014-12-15 09:57:55 -0800 | [diff] [blame] | 2372 | null, "resume-no-history", false); |
Craig Mautner | 0f92274 | 2013-08-06 08:44:42 -0700 | [diff] [blame] | 2373 | mLastNoHistoryActivity = null; |
Christopher Tate | d3f175c | 2012-06-14 14:16:54 -0700 | [diff] [blame] | 2374 | } |
| 2375 | |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 2376 | if (prev != null && prev != next) { |
Craig Mautner | 8c14c15 | 2015-01-15 17:32:07 -0800 | [diff] [blame] | 2377 | if (!mStackSupervisor.mWaitingVisibleActivities.contains(prev) |
| 2378 | && next != null && !next.nowVisible) { |
Craig Mautner | de4ef02 | 2013-04-07 19:01:33 -0700 | [diff] [blame] | 2379 | mStackSupervisor.mWaitingVisibleActivities.add(prev); |
Wale Ogunwale | ee006da | 2015-03-30 14:49:25 -0700 | [diff] [blame] | 2380 | if (DEBUG_SWITCH) Slog.v(TAG_SWITCH, |
| 2381 | "Resuming top, waiting visible to hide: " + prev); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 2382 | } else { |
| 2383 | // The next activity is already visible, so hide the previous |
| 2384 | // activity's windows right now so we can show the new one ASAP. |
| 2385 | // We only do this if the previous is finishing, which should mean |
| 2386 | // it is on top of the one being resumed so hiding it quickly |
| 2387 | // is good. Otherwise, we want to do the normal route of allowing |
| 2388 | // the resumed activity to be shown so we can decide if the |
| 2389 | // previous should actually be hidden depending on whether the |
| 2390 | // new one is found to be full-screen or not. |
| 2391 | if (prev.finishing) { |
Craig Mautner | ce5f3cb | 2013-04-22 08:58:54 -0700 | [diff] [blame] | 2392 | mWindowManager.setAppVisibility(prev.appToken, false); |
Wale Ogunwale | ee006da | 2015-03-30 14:49:25 -0700 | [diff] [blame] | 2393 | if (DEBUG_SWITCH) Slog.v(TAG_SWITCH, |
| 2394 | "Not waiting for visible to hide: " + prev + ", waitingVisible=" |
Craig Mautner | 8c14c15 | 2015-01-15 17:32:07 -0800 | [diff] [blame] | 2395 | + mStackSupervisor.mWaitingVisibleActivities.contains(prev) |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 2396 | + ", nowVisible=" + next.nowVisible); |
| 2397 | } else { |
Wale Ogunwale | ee006da | 2015-03-30 14:49:25 -0700 | [diff] [blame] | 2398 | if (DEBUG_SWITCH) Slog.v(TAG_SWITCH, |
Craig Mautner | 8c14c15 | 2015-01-15 17:32:07 -0800 | [diff] [blame] | 2399 | "Previous already visible but still waiting to hide: " + prev |
Wale Ogunwale | ee006da | 2015-03-30 14:49:25 -0700 | [diff] [blame] | 2400 | + ", waitingVisible=" |
| 2401 | + mStackSupervisor.mWaitingVisibleActivities.contains(prev) |
| 2402 | + ", nowVisible=" + next.nowVisible); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 2403 | } |
| 2404 | } |
| 2405 | } |
| 2406 | |
Dianne Hackborn | e7f9721 | 2011-02-24 14:40:20 -0800 | [diff] [blame] | 2407 | // Launching this app's activity, make sure the app is no longer |
| 2408 | // considered stopped. |
| 2409 | try { |
| 2410 | AppGlobals.getPackageManager().setPackageStoppedState( |
Amith Yamasani | 483f3b0 | 2012-03-13 16:08:00 -0700 | [diff] [blame] | 2411 | next.packageName, false, next.userId); /* TODO: Verify if correct userid */ |
Dianne Hackborn | e7f9721 | 2011-02-24 14:40:20 -0800 | [diff] [blame] | 2412 | } catch (RemoteException e1) { |
Dianne Hackborn | a925cd4 | 2011-03-10 13:18:20 -0800 | [diff] [blame] | 2413 | } catch (IllegalArgumentException e) { |
| 2414 | Slog.w(TAG, "Failed trying to unstop package " |
| 2415 | + next.packageName + ": " + e); |
Dianne Hackborn | e7f9721 | 2011-02-24 14:40:20 -0800 | [diff] [blame] | 2416 | } |
| 2417 | |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 2418 | // We are starting up the next activity, so tell the window manager |
| 2419 | // that the previous one will be hidden soon. This way it can know |
| 2420 | // to ignore it when computing the desired screen orientation. |
Craig Mautner | 525f3d9 | 2013-05-07 14:01:50 -0700 | [diff] [blame] | 2421 | boolean anim = true; |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 2422 | if (prev != null) { |
| 2423 | if (prev.finishing) { |
Wale Ogunwale | ee006da | 2015-03-30 14:49:25 -0700 | [diff] [blame] | 2424 | if (DEBUG_TRANSITION) Slog.v(TAG_TRANSITION, |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 2425 | "Prepare close transition: prev=" + prev); |
| 2426 | if (mNoAnimActivities.contains(prev)) { |
Craig Mautner | 525f3d9 | 2013-05-07 14:01:50 -0700 | [diff] [blame] | 2427 | anim = false; |
Jorim Jaggi | af80db4 | 2016-04-07 19:19:15 -0700 | [diff] [blame] | 2428 | mWindowManager.prepareAppTransition(TRANSIT_NONE, false); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 2429 | } else { |
Craig Mautner | ce5f3cb | 2013-04-22 08:58:54 -0700 | [diff] [blame] | 2430 | mWindowManager.prepareAppTransition(prev.task == next.task |
Jorim Jaggi | af80db4 | 2016-04-07 19:19:15 -0700 | [diff] [blame] | 2431 | ? TRANSIT_ACTIVITY_CLOSE |
| 2432 | : TRANSIT_TASK_CLOSE, false); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 2433 | } |
Craig Mautner | ce5f3cb | 2013-04-22 08:58:54 -0700 | [diff] [blame] | 2434 | mWindowManager.setAppVisibility(prev.appToken, false); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 2435 | } else { |
Wale Ogunwale | ee006da | 2015-03-30 14:49:25 -0700 | [diff] [blame] | 2436 | if (DEBUG_TRANSITION) Slog.v(TAG_TRANSITION, |
| 2437 | "Prepare open transition: prev=" + prev); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 2438 | if (mNoAnimActivities.contains(next)) { |
Craig Mautner | 525f3d9 | 2013-05-07 14:01:50 -0700 | [diff] [blame] | 2439 | anim = false; |
Jorim Jaggi | af80db4 | 2016-04-07 19:19:15 -0700 | [diff] [blame] | 2440 | mWindowManager.prepareAppTransition(TRANSIT_NONE, false); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 2441 | } else { |
Craig Mautner | ce5f3cb | 2013-04-22 08:58:54 -0700 | [diff] [blame] | 2442 | mWindowManager.prepareAppTransition(prev.task == next.task |
Jorim Jaggi | af80db4 | 2016-04-07 19:19:15 -0700 | [diff] [blame] | 2443 | ? TRANSIT_ACTIVITY_OPEN |
Craig Mautner | bb74246 | 2014-07-07 15:28:55 -0700 | [diff] [blame] | 2444 | : next.mLaunchTaskBehind |
Jorim Jaggi | af80db4 | 2016-04-07 19:19:15 -0700 | [diff] [blame] | 2445 | ? TRANSIT_TASK_OPEN_BEHIND |
| 2446 | : TRANSIT_TASK_OPEN, false); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 2447 | } |
| 2448 | } |
Craig Mautner | 967212c | 2013-04-13 21:10:58 -0700 | [diff] [blame] | 2449 | } else { |
Wale Ogunwale | ee006da | 2015-03-30 14:49:25 -0700 | [diff] [blame] | 2450 | if (DEBUG_TRANSITION) Slog.v(TAG_TRANSITION, "Prepare open transition: no previous"); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 2451 | if (mNoAnimActivities.contains(next)) { |
Craig Mautner | 525f3d9 | 2013-05-07 14:01:50 -0700 | [diff] [blame] | 2452 | anim = false; |
Jorim Jaggi | af80db4 | 2016-04-07 19:19:15 -0700 | [diff] [blame] | 2453 | mWindowManager.prepareAppTransition(TRANSIT_NONE, false); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 2454 | } else { |
Jorim Jaggi | af80db4 | 2016-04-07 19:19:15 -0700 | [diff] [blame] | 2455 | mWindowManager.prepareAppTransition(TRANSIT_ACTIVITY_OPEN, false); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 2456 | } |
| 2457 | } |
Adam Powell | cfbe9be | 2013-11-06 14:58:58 -0800 | [diff] [blame] | 2458 | |
| 2459 | Bundle resumeAnimOptions = null; |
Craig Mautner | 525f3d9 | 2013-05-07 14:01:50 -0700 | [diff] [blame] | 2460 | if (anim) { |
Adam Powell | cfbe9be | 2013-11-06 14:58:58 -0800 | [diff] [blame] | 2461 | ActivityOptions opts = next.getOptionsForTargetActivityLocked(); |
| 2462 | if (opts != null) { |
| 2463 | resumeAnimOptions = opts.toBundle(); |
| 2464 | } |
Dianne Hackborn | 7a2195c | 2012-03-19 17:38:00 -0700 | [diff] [blame] | 2465 | next.applyOptionsLocked(); |
| 2466 | } else { |
| 2467 | next.clearOptionsLocked(); |
| 2468 | } |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 2469 | |
Craig Mautner | cf910b0 | 2013-04-23 11:23:27 -0700 | [diff] [blame] | 2470 | ActivityStack lastStack = mStackSupervisor.getLastStack(); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 2471 | if (next.app != null && next.app.thread != null) { |
Chong Zhang | dea4bd9 | 2016-03-15 12:50:03 -0700 | [diff] [blame] | 2472 | if (DEBUG_SWITCH) Slog.v(TAG_SWITCH, "Resume running: " + next |
| 2473 | + " stopped=" + next.stopped + " visible=" + next.visible); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 2474 | |
Chong Zhang | d127c6d | 2016-05-02 16:36:41 -0700 | [diff] [blame] | 2475 | // If the previous activity is translucent, force a visibility update of |
| 2476 | // the next activity, so that it's added to WM's opening app list, and |
| 2477 | // transition animation can be set up properly. |
| 2478 | // For example, pressing Home button with a translucent activity in focus. |
| 2479 | // Launcher is already visible in this case. If we don't add it to opening |
| 2480 | // apps, maybeUpdateTransitToWallpaper() will fail to identify this as a |
| 2481 | // TRANSIT_WALLPAPER_OPEN animation, and run some funny animation. |
| 2482 | final boolean lastActivityTranslucent = lastStack != null |
| 2483 | && (!lastStack.mFullscreen |
| 2484 | || (lastStack.mLastPausedActivity != null |
| 2485 | && !lastStack.mLastPausedActivity.fullscreen)); |
| 2486 | |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 2487 | // This activity is now becoming visible. |
Chong Zhang | d127c6d | 2016-05-02 16:36:41 -0700 | [diff] [blame] | 2488 | if (!next.visible || next.stopped || lastActivityTranslucent) { |
Jorim Jaggi | 1b025a6 | 2016-02-03 19:27:49 -0800 | [diff] [blame] | 2489 | mWindowManager.setAppVisibility(next.appToken, true); |
| 2490 | } |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 2491 | |
Dianne Hackborn | 2a29b3a | 2012-03-15 15:48:38 -0700 | [diff] [blame] | 2492 | // schedule launch ticks to collect information about slow apps. |
| 2493 | next.startLaunchTickingLocked(); |
| 2494 | |
Craig Mautner | f88c50f | 2013-04-18 19:25:12 -0700 | [diff] [blame] | 2495 | ActivityRecord lastResumedActivity = |
| 2496 | lastStack == null ? null :lastStack.mResumedActivity; |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 2497 | ActivityState lastState = next.state; |
| 2498 | |
| 2499 | mService.updateCpuStats(); |
Craig Mautner | 5854780 | 2013-03-05 08:23:53 -0800 | [diff] [blame] | 2500 | |
Wale Ogunwale | 0fc365c | 2015-05-25 19:35:42 -0700 | [diff] [blame] | 2501 | if (DEBUG_STATES) Slog.v(TAG_STATES, "Moving to RESUMED: " + next + " (in existing)"); |
Chong Zhang | 6cda19c | 2016-06-14 19:07:56 -0700 | [diff] [blame] | 2502 | |
| 2503 | setResumedActivityLocked(next, "resumeTopActivityInnerLocked"); |
| 2504 | |
Dianne Hackborn | db92608 | 2013-10-31 16:32:44 -0700 | [diff] [blame] | 2505 | mService.updateLruProcessLocked(next.app, true, null); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 2506 | updateLRUListLocked(next); |
Dianne Hackborn | db92608 | 2013-10-31 16:32:44 -0700 | [diff] [blame] | 2507 | mService.updateOomAdjLocked(); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 2508 | |
| 2509 | // Have the window manager re-evaluate the orientation of |
| 2510 | // the screen based on the new activity order. |
Craig Mautner | 525f3d9 | 2013-05-07 14:01:50 -0700 | [diff] [blame] | 2511 | boolean notUpdated = true; |
Wale Ogunwale | 1e60e0c | 2015-10-28 13:36:10 -0700 | [diff] [blame] | 2512 | if (mStackSupervisor.isFocusedStack(this)) { |
Craig Mautner | ce5f3cb | 2013-04-22 08:58:54 -0700 | [diff] [blame] | 2513 | Configuration config = mWindowManager.updateOrientationFromAppTokens( |
Craig Mautner | 8d341ef | 2013-03-26 09:03:27 -0700 | [diff] [blame] | 2514 | mService.mConfiguration, |
| 2515 | next.mayFreezeScreenLocked(next.app) ? next.appToken : null); |
| 2516 | if (config != null) { |
| 2517 | next.frozenBeforeDestroy = true; |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 2518 | } |
Maxim Bogatov | 0507530 | 2015-05-19 18:33:08 -0700 | [diff] [blame] | 2519 | notUpdated = !mService.updateConfigurationLocked(config, next, false); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 2520 | } |
Craig Mautner | 8d341ef | 2013-03-26 09:03:27 -0700 | [diff] [blame] | 2521 | |
Craig Mautner | 525f3d9 | 2013-05-07 14:01:50 -0700 | [diff] [blame] | 2522 | if (notUpdated) { |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 2523 | // The configuration update wasn't able to keep the existing |
| 2524 | // instance of the activity, and instead started a new one. |
| 2525 | // We should be all done, but let's just make sure our activity |
| 2526 | // is still at the top and schedule another run if something |
| 2527 | // weird happened. |
Filip Gruszczynski | 3e85ba2 | 2015-10-05 22:48:30 -0700 | [diff] [blame] | 2528 | ActivityRecord nextNext = topRunningActivityLocked(); |
Wale Ogunwale | 0fc365c | 2015-05-25 19:35:42 -0700 | [diff] [blame] | 2529 | if (DEBUG_SWITCH || DEBUG_STATES) Slog.i(TAG_STATES, |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 2530 | "Activity config changed during resume: " + next |
| 2531 | + ", new next: " + nextNext); |
| 2532 | if (nextNext != next) { |
| 2533 | // Do over! |
Craig Mautner | 05d2903 | 2013-05-03 13:40:13 -0700 | [diff] [blame] | 2534 | mStackSupervisor.scheduleResumeTopActivities(); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 2535 | } |
Chong Zhang | d2cb311 | 2016-07-20 11:13:22 -0700 | [diff] [blame] | 2536 | if (!next.visible || next.stopped) { |
| 2537 | mWindowManager.setAppVisibility(next.appToken, true); |
Craig Mautner | de4ef02 | 2013-04-07 19:01:33 -0700 | [diff] [blame] | 2538 | } |
Chong Zhang | d2cb311 | 2016-07-20 11:13:22 -0700 | [diff] [blame] | 2539 | completeResumeLocked(next); |
Craig Mautner | cf910b0 | 2013-04-23 11:23:27 -0700 | [diff] [blame] | 2540 | if (DEBUG_STACK) mStackSupervisor.validateTopActivitiesLocked(); |
Chong Zhang | d2cb311 | 2016-07-20 11:13:22 -0700 | [diff] [blame] | 2541 | return true; |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 2542 | } |
Craig Mautner | 5854780 | 2013-03-05 08:23:53 -0800 | [diff] [blame] | 2543 | |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 2544 | try { |
| 2545 | // Deliver all pending results. |
Craig Mautner | 05d6272ba | 2013-02-11 09:39:27 -0800 | [diff] [blame] | 2546 | ArrayList<ResultInfo> a = next.results; |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 2547 | if (a != null) { |
| 2548 | final int N = a.size(); |
| 2549 | if (!next.finishing && N > 0) { |
Wale Ogunwale | ee006da | 2015-03-30 14:49:25 -0700 | [diff] [blame] | 2550 | if (DEBUG_RESULTS) Slog.v(TAG_RESULTS, |
| 2551 | "Delivering results to " + next + ": " + a); |
Dianne Hackborn | be70785 | 2011-11-11 14:32:10 -0800 | [diff] [blame] | 2552 | next.app.thread.scheduleSendResult(next.appToken, a); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 2553 | } |
| 2554 | } |
| 2555 | |
| 2556 | if (next.newIntents != null) { |
Dianne Hackborn | be70785 | 2011-11-11 14:32:10 -0800 | [diff] [blame] | 2557 | next.app.thread.scheduleNewIntent(next.newIntents, next.appToken); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 2558 | } |
| 2559 | |
Wale Ogunwale | 8d5a542 | 2016-03-03 18:28:21 -0800 | [diff] [blame] | 2560 | // Well the app will no longer be stopped. |
| 2561 | // Clear app token stopped state in window manager if needed. |
Chong Zhang | 45e6d2d | 2016-07-20 18:33:56 -0700 | [diff] [blame] | 2562 | mWindowManager.notifyAppResumed(next.appToken, next.stopped); |
Wale Ogunwale | 8d5a542 | 2016-03-03 18:28:21 -0800 | [diff] [blame] | 2563 | |
Craig Mautner | 299f960 | 2015-01-26 09:47:33 -0800 | [diff] [blame] | 2564 | EventLog.writeEvent(EventLogTags.AM_RESUME_ACTIVITY, next.userId, |
| 2565 | System.identityHashCode(next), next.task.taskId, next.shortComponentName); |
Craig Mautner | 5854780 | 2013-03-05 08:23:53 -0800 | [diff] [blame] | 2566 | |
Dianne Hackborn | 4eba96b | 2011-01-21 13:34:36 -0800 | [diff] [blame] | 2567 | next.sleeping = false; |
Alan Viverette | 5f31b98 | 2016-06-21 14:46:14 -0400 | [diff] [blame] | 2568 | mService.showUnsupportedZoomDialogIfNeededLocked(next); |
Craig Mautner | 2420ead | 2013-04-01 17:13:20 -0700 | [diff] [blame] | 2569 | mService.showAskCompatModeDialogLocked(next); |
Dianne Hackborn | 905577f | 2011-09-07 18:31:28 -0700 | [diff] [blame] | 2570 | next.app.pendingUiClean = true; |
Dianne Hackborn | 4870e9d | 2015-04-08 16:55:47 -0700 | [diff] [blame] | 2571 | next.app.forceProcessStateUpTo(mService.mTopProcessState); |
George Mount | 2c92c97 | 2014-03-20 09:38:23 -0700 | [diff] [blame] | 2572 | next.clearOptionsLocked(); |
Dianne Hackborn | a413dc0 | 2013-07-12 12:02:55 -0700 | [diff] [blame] | 2573 | next.app.thread.scheduleResumeActivity(next.appToken, next.app.repProcState, |
Adam Powell | cfbe9be | 2013-11-06 14:58:58 -0800 | [diff] [blame] | 2574 | mService.isNextTransitionForward(), resumeAnimOptions); |
Craig Mautner | 5854780 | 2013-03-05 08:23:53 -0800 | [diff] [blame] | 2575 | |
Wale Ogunwale | 0fc365c | 2015-05-25 19:35:42 -0700 | [diff] [blame] | 2576 | if (DEBUG_STATES) Slog.d(TAG_STATES, "resumeTopActivityLocked: Resumed " + next); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 2577 | } catch (Exception e) { |
| 2578 | // Whoops, need to restart this activity! |
Wale Ogunwale | 0fc365c | 2015-05-25 19:35:42 -0700 | [diff] [blame] | 2579 | if (DEBUG_STATES) Slog.v(TAG_STATES, "Resume failed; resetting state to " |
Dianne Hackborn | ce86ba8 | 2011-07-13 19:33:41 -0700 | [diff] [blame] | 2580 | + lastState + ": " + next); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 2581 | next.state = lastState; |
Craig Mautner | f88c50f | 2013-04-18 19:25:12 -0700 | [diff] [blame] | 2582 | if (lastStack != null) { |
| 2583 | lastStack.mResumedActivity = lastResumedActivity; |
| 2584 | } |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 2585 | Slog.i(TAG, "Restarting because process died: " + next); |
| 2586 | if (!next.hasBeenLaunched) { |
| 2587 | next.hasBeenLaunched = true; |
Craig Mautner | f88c50f | 2013-04-18 19:25:12 -0700 | [diff] [blame] | 2588 | } else if (SHOW_APP_STARTING_PREVIEW && lastStack != null && |
| 2589 | mStackSupervisor.isFrontStack(lastStack)) { |
Wale Ogunwale | 3b23239 | 2016-05-13 15:37:13 -0700 | [diff] [blame] | 2590 | next.showStartingWindow(null, true); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 2591 | } |
George Mount | 2c92c97 | 2014-03-20 09:38:23 -0700 | [diff] [blame] | 2592 | mStackSupervisor.startSpecificActivityLocked(next, true, false); |
Craig Mautner | cf910b0 | 2013-04-23 11:23:27 -0700 | [diff] [blame] | 2593 | if (DEBUG_STACK) mStackSupervisor.validateTopActivitiesLocked(); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 2594 | return true; |
| 2595 | } |
| 2596 | |
| 2597 | // From this point on, if something goes wrong there is no way |
| 2598 | // to recover the activity. |
| 2599 | try { |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 2600 | completeResumeLocked(next); |
| 2601 | } catch (Exception e) { |
| 2602 | // If any exception gets thrown, toss away this |
| 2603 | // activity and try the next one. |
| 2604 | Slog.w(TAG, "Exception thrown during resume of " + next, e); |
Dianne Hackborn | be70785 | 2011-11-11 14:32:10 -0800 | [diff] [blame] | 2605 | requestFinishActivityLocked(next.appToken, Activity.RESULT_CANCELED, null, |
Dianne Hackborn | 2d1b378 | 2012-09-09 17:49:39 -0700 | [diff] [blame] | 2606 | "resume-exception", true); |
Craig Mautner | cf910b0 | 2013-04-23 11:23:27 -0700 | [diff] [blame] | 2607 | if (DEBUG_STACK) mStackSupervisor.validateTopActivitiesLocked(); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 2608 | return true; |
| 2609 | } |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 2610 | } else { |
| 2611 | // Whoops, need to restart this activity! |
| 2612 | if (!next.hasBeenLaunched) { |
| 2613 | next.hasBeenLaunched = true; |
| 2614 | } else { |
| 2615 | if (SHOW_APP_STARTING_PREVIEW) { |
Wale Ogunwale | 3b23239 | 2016-05-13 15:37:13 -0700 | [diff] [blame] | 2616 | next.showStartingWindow(null, true); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 2617 | } |
Wale Ogunwale | ee006da | 2015-03-30 14:49:25 -0700 | [diff] [blame] | 2618 | if (DEBUG_SWITCH) Slog.v(TAG_SWITCH, "Restarting: " + next); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 2619 | } |
Wale Ogunwale | 0fc365c | 2015-05-25 19:35:42 -0700 | [diff] [blame] | 2620 | if (DEBUG_STATES) Slog.d(TAG_STATES, "resumeTopActivityLocked: Restarting " + next); |
George Mount | 2c92c97 | 2014-03-20 09:38:23 -0700 | [diff] [blame] | 2621 | mStackSupervisor.startSpecificActivityLocked(next, true, true); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 2622 | } |
| 2623 | |
Craig Mautner | cf910b0 | 2013-04-23 11:23:27 -0700 | [diff] [blame] | 2624 | if (DEBUG_STACK) mStackSupervisor.validateTopActivitiesLocked(); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 2625 | return true; |
| 2626 | } |
| 2627 | |
riddle_hsu | c215a4f | 2014-12-27 12:10:45 +0800 | [diff] [blame] | 2628 | private TaskRecord getNextTask(TaskRecord targetTask) { |
| 2629 | final int index = mTaskHistory.indexOf(targetTask); |
| 2630 | if (index >= 0) { |
| 2631 | final int numTasks = mTaskHistory.size(); |
| 2632 | for (int i = index + 1; i < numTasks; ++i) { |
| 2633 | TaskRecord task = mTaskHistory.get(i); |
| 2634 | if (task.userId == targetTask.userId) { |
| 2635 | return task; |
| 2636 | } |
| 2637 | } |
| 2638 | } |
| 2639 | return null; |
| 2640 | } |
| 2641 | |
Wale Ogunwale | ddc1cb2 | 2015-07-25 19:23:04 -0700 | [diff] [blame] | 2642 | private void insertTaskAtPosition(TaskRecord task, int position) { |
| 2643 | if (position >= mTaskHistory.size()) { |
| 2644 | insertTaskAtTop(task, null); |
| 2645 | return; |
| 2646 | } |
| 2647 | // Calculate maximum possible position for this task. |
| 2648 | int maxPosition = mTaskHistory.size(); |
Chong Zhang | 8776197 | 2016-08-22 13:53:24 -0700 | [diff] [blame^] | 2649 | if (!task.okToShowLocked()) { |
Wale Ogunwale | ddc1cb2 | 2015-07-25 19:23:04 -0700 | [diff] [blame] | 2650 | // Put non-current user tasks below current user tasks. |
| 2651 | while (maxPosition > 0) { |
| 2652 | final TaskRecord tmpTask = mTaskHistory.get(maxPosition - 1); |
| 2653 | if (!mStackSupervisor.isCurrentProfileLocked(tmpTask.userId) |
Filip Gruszczynski | 3e85ba2 | 2015-10-05 22:48:30 -0700 | [diff] [blame] | 2654 | || tmpTask.topRunningActivityLocked() == null) { |
Wale Ogunwale | ddc1cb2 | 2015-07-25 19:23:04 -0700 | [diff] [blame] | 2655 | break; |
| 2656 | } |
| 2657 | maxPosition--; |
| 2658 | } |
| 2659 | } |
| 2660 | position = Math.min(position, maxPosition); |
| 2661 | mTaskHistory.remove(task); |
| 2662 | mTaskHistory.add(position, task); |
| 2663 | updateTaskMovement(task, true); |
| 2664 | } |
| 2665 | |
Wale Ogunwale | 3fcb4a8 | 2015-04-06 14:00:13 -0700 | [diff] [blame] | 2666 | private void insertTaskAtTop(TaskRecord task, ActivityRecord newActivity) { |
Andrii Kulian | dc0f893 | 2016-06-28 16:34:02 -0700 | [diff] [blame] | 2667 | boolean isLastTaskOverHome = false; |
riddle_hsu | c215a4f | 2014-12-27 12:10:45 +0800 | [diff] [blame] | 2668 | // If the moving task is over home stack, transfer its return type to next task |
| 2669 | if (task.isOverHomeStack()) { |
| 2670 | final TaskRecord nextTask = getNextTask(task); |
| 2671 | if (nextTask != null) { |
| 2672 | nextTask.setTaskToReturnTo(task.getTaskToReturnTo()); |
Andrii Kulian | dc0f893 | 2016-06-28 16:34:02 -0700 | [diff] [blame] | 2673 | } else { |
| 2674 | isLastTaskOverHome = true; |
riddle_hsu | c215a4f | 2014-12-27 12:10:45 +0800 | [diff] [blame] | 2675 | } |
| 2676 | } |
| 2677 | |
Craig Mautner | 9c85c20 | 2013-10-04 20:11:26 -0700 | [diff] [blame] | 2678 | // 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] | 2679 | // activity, set mTaskToReturnTo accordingly. |
Craig Mautner | e0a3884 | 2013-12-16 16:14:02 -0800 | [diff] [blame] | 2680 | if (isOnHomeDisplay()) { |
| 2681 | ActivityStack lastStack = mStackSupervisor.getLastStack(); |
| 2682 | final boolean fromHome = lastStack.isHomeStack(); |
Jiaquan He | e13e964 | 2016-06-15 15:16:13 -0700 | [diff] [blame] | 2683 | final boolean fromOnTopLauncher = lastStack.topTask() != null && |
| 2684 | lastStack.topTask().isOnTopLauncher(); |
| 2685 | if (fromOnTopLauncher) { |
| 2686 | // Since an on-top launcher will is moved to back when tasks are launched from it, |
| 2687 | // those tasks should first try to return to a non-home activity. |
| 2688 | // This also makes sure that non-home activities are visible under a transparent |
| 2689 | // non-home activity. |
| 2690 | task.setTaskToReturnTo(APPLICATION_ACTIVITY_TYPE); |
| 2691 | } else if (!isHomeStack() && (fromHome || topTask() != task)) { |
Andrii Kulian | dc0f893 | 2016-06-28 16:34:02 -0700 | [diff] [blame] | 2692 | // If it's a last task over home - we default to keep its return to type not to |
| 2693 | // make underlying task focused when this one will be finished. |
| 2694 | int returnToType = isLastTaskOverHome |
| 2695 | ? task.getTaskToReturnTo() : APPLICATION_ACTIVITY_TYPE; |
Wale Ogunwale | f81c1d1 | 2016-01-12 12:20:18 -0800 | [diff] [blame] | 2696 | if (fromHome && StackId.allowTopTaskToReturnHome(mStackId)) { |
| 2697 | returnToType = lastStack.topTask() == null |
| 2698 | ? HOME_ACTIVITY_TYPE : lastStack.topTask().taskType; |
| 2699 | } |
| 2700 | task.setTaskToReturnTo(returnToType); |
Craig Mautner | e0a3884 | 2013-12-16 16:14:02 -0800 | [diff] [blame] | 2701 | } |
| 2702 | } else { |
Craig Mautner | 84984fa | 2014-06-19 11:19:20 -0700 | [diff] [blame] | 2703 | task.setTaskToReturnTo(APPLICATION_ACTIVITY_TYPE); |
Craig Mautner | 9c85c20 | 2013-10-04 20:11:26 -0700 | [diff] [blame] | 2704 | } |
Craig Mautner | d99384d | 2013-10-14 07:09:18 -0700 | [diff] [blame] | 2705 | |
Craig Mautner | ac6f843 | 2013-07-17 13:24:59 -0700 | [diff] [blame] | 2706 | mTaskHistory.remove(task); |
| 2707 | // Now put task at top. |
Craig Mautner | bb74246 | 2014-07-07 15:28:55 -0700 | [diff] [blame] | 2708 | int taskNdx = mTaskHistory.size(); |
Wale Ogunwale | 3fcb4a8 | 2015-04-06 14:00:13 -0700 | [diff] [blame] | 2709 | final boolean notShownWhenLocked = |
Chong Zhang | 8776197 | 2016-08-22 13:53:24 -0700 | [diff] [blame^] | 2710 | (newActivity != null && !newActivity.okToShowLocked()) |
| 2711 | || (newActivity == null && !task.okToShowLocked()); |
| 2712 | if (notShownWhenLocked) { |
Craig Mautner | ac6f843 | 2013-07-17 13:24:59 -0700 | [diff] [blame] | 2713 | // Put non-current user tasks below current user tasks. |
Craig Mautner | bb74246 | 2014-07-07 15:28:55 -0700 | [diff] [blame] | 2714 | while (--taskNdx >= 0) { |
Wale Ogunwale | 3fcb4a8 | 2015-04-06 14:00:13 -0700 | [diff] [blame] | 2715 | final TaskRecord tmpTask = mTaskHistory.get(taskNdx); |
Wale Ogunwale | 0bd2aa7 | 2015-04-16 13:50:44 -0700 | [diff] [blame] | 2716 | if (!mStackSupervisor.isCurrentProfileLocked(tmpTask.userId) |
Filip Gruszczynski | 3e85ba2 | 2015-10-05 22:48:30 -0700 | [diff] [blame] | 2717 | || tmpTask.topRunningActivityLocked() == null) { |
Craig Mautner | ac6f843 | 2013-07-17 13:24:59 -0700 | [diff] [blame] | 2718 | break; |
| 2719 | } |
| 2720 | } |
Craig Mautner | bb74246 | 2014-07-07 15:28:55 -0700 | [diff] [blame] | 2721 | ++taskNdx; |
Craig Mautner | ac6f843 | 2013-07-17 13:24:59 -0700 | [diff] [blame] | 2722 | } |
Craig Mautner | bb74246 | 2014-07-07 15:28:55 -0700 | [diff] [blame] | 2723 | mTaskHistory.add(taskNdx, task); |
Craig Mautner | 21d24a2 | 2014-04-23 11:45:37 -0700 | [diff] [blame] | 2724 | updateTaskMovement(task, true); |
Craig Mautner | ac6f843 | 2013-07-17 13:24:59 -0700 | [diff] [blame] | 2725 | } |
Craig Mautner | 11bf9a5 | 2013-02-19 14:08:51 -0800 | [diff] [blame] | 2726 | |
Filip Gruszczynski | 3d82ed6 | 2015-12-10 10:41:39 -0800 | [diff] [blame] | 2727 | final void startActivityLocked(ActivityRecord r, boolean newTask, boolean keepCurTransition, |
| 2728 | ActivityOptions options) { |
Craig Mautner | d232895 | 2013-03-05 12:46:26 -0800 | [diff] [blame] | 2729 | TaskRecord rTask = r.task; |
| 2730 | final int taskId = rTask.taskId; |
Craig Mautner | bb74246 | 2014-07-07 15:28:55 -0700 | [diff] [blame] | 2731 | // mLaunchTaskBehind tasks get placed at the back of the task stack. |
| 2732 | if (!r.mLaunchTaskBehind && (taskForIdLocked(taskId) == null || newTask)) { |
Craig Mautner | 7787877 | 2013-03-04 19:46:24 -0800 | [diff] [blame] | 2733 | // Last activity in task had been removed or ActivityManagerService is reusing task. |
| 2734 | // Insert or replace. |
Craig Mautner | 7787877 | 2013-03-04 19:46:24 -0800 | [diff] [blame] | 2735 | // Might not even be in. |
Wale Ogunwale | 3fcb4a8 | 2015-04-06 14:00:13 -0700 | [diff] [blame] | 2736 | insertTaskAtTop(rTask, r); |
Craig Mautner | ce5f3cb | 2013-04-22 08:58:54 -0700 | [diff] [blame] | 2737 | mWindowManager.moveTaskToTop(taskId); |
Craig Mautner | 7787877 | 2013-03-04 19:46:24 -0800 | [diff] [blame] | 2738 | } |
Craig Mautner | 525f3d9 | 2013-05-07 14:01:50 -0700 | [diff] [blame] | 2739 | TaskRecord task = null; |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 2740 | if (!newTask) { |
| 2741 | // If starting in an existing task, find where that is... |
Craig Mautner | 70a8693 | 2013-02-28 22:37:44 -0800 | [diff] [blame] | 2742 | boolean startIt = true; |
| 2743 | for (int taskNdx = mTaskHistory.size() - 1; taskNdx >= 0; --taskNdx) { |
| 2744 | task = mTaskHistory.get(taskNdx); |
riddle_hsu | 9bcc6e8 | 2014-07-31 00:26:51 +0800 | [diff] [blame] | 2745 | if (task.getTopActivity() == null) { |
| 2746 | // All activities in task are finishing. |
| 2747 | continue; |
| 2748 | } |
Craig Mautner | 70a8693 | 2013-02-28 22:37:44 -0800 | [diff] [blame] | 2749 | if (task == r.task) { |
| 2750 | // Here it is! Now, if this is not yet visible to the |
| 2751 | // user, then just add it without starting; it will |
| 2752 | // get started when the user navigates back to it. |
Craig Mautner | 70a8693 | 2013-02-28 22:37:44 -0800 | [diff] [blame] | 2753 | if (!startIt) { |
| 2754 | if (DEBUG_ADD_REMOVE) Slog.i(TAG, "Adding activity " + r + " to task " |
| 2755 | + task, new RuntimeException("here").fillInStackTrace()); |
| 2756 | task.addActivityToTop(r); |
Dianne Hackborn | f26fd99 | 2011-04-08 18:14:09 -0700 | [diff] [blame] | 2757 | r.putInHistory(); |
Filip Gruszczynski | e5390e7 | 2015-08-18 16:39:00 -0700 | [diff] [blame] | 2758 | addConfigOverride(r, task); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 2759 | if (VALIDATE_TOKENS) { |
Dianne Hackborn | be70785 | 2011-11-11 14:32:10 -0800 | [diff] [blame] | 2760 | validateAppTokensLocked(); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 2761 | } |
Dianne Hackborn | 8078d8c | 2012-03-20 11:11:26 -0700 | [diff] [blame] | 2762 | ActivityOptions.abort(options); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 2763 | return; |
| 2764 | } |
| 2765 | break; |
Craig Mautner | 70a8693 | 2013-02-28 22:37:44 -0800 | [diff] [blame] | 2766 | } else if (task.numFullscreen > 0) { |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 2767 | startIt = false; |
| 2768 | } |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 2769 | } |
| 2770 | } |
| 2771 | |
| 2772 | // Place a new activity at top of stack, so it is next to interact |
| 2773 | // with the user. |
Craig Mautner | 70a8693 | 2013-02-28 22:37:44 -0800 | [diff] [blame] | 2774 | |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 2775 | // If we are not placing the new activity frontmost, we do not want |
| 2776 | // to deliver the onUserLeaving callback to the actual frontmost |
| 2777 | // activity |
Craig Mautner | 70a8693 | 2013-02-28 22:37:44 -0800 | [diff] [blame] | 2778 | if (task == r.task && mTaskHistory.indexOf(task) != (mTaskHistory.size() - 1)) { |
Craig Mautner | de4ef02 | 2013-04-07 19:01:33 -0700 | [diff] [blame] | 2779 | mStackSupervisor.mUserLeaving = false; |
Wale Ogunwale | ee006da | 2015-03-30 14:49:25 -0700 | [diff] [blame] | 2780 | if (DEBUG_USER_LEAVING) Slog.v(TAG_USER_LEAVING, |
Craig Mautner | 70a8693 | 2013-02-28 22:37:44 -0800 | [diff] [blame] | 2781 | "startActivity() behind front, mUserLeaving=false"); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 2782 | } |
Craig Mautner | 70a8693 | 2013-02-28 22:37:44 -0800 | [diff] [blame] | 2783 | |
| 2784 | task = r.task; |
| 2785 | |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 2786 | // Slot the activity into the history stack and proceed |
Craig Mautner | 70a8693 | 2013-02-28 22:37:44 -0800 | [diff] [blame] | 2787 | 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] | 2788 | new RuntimeException("here").fillInStackTrace()); |
Craig Mautner | 70a8693 | 2013-02-28 22:37:44 -0800 | [diff] [blame] | 2789 | task.addActivityToTop(r); |
Craig Mautner | 1aa9d0d3f | 2013-12-16 15:58:31 -0800 | [diff] [blame] | 2790 | task.setFrontOfTask(); |
Craig Mautner | 70a8693 | 2013-02-28 22:37:44 -0800 | [diff] [blame] | 2791 | |
Dianne Hackborn | f26fd99 | 2011-04-08 18:14:09 -0700 | [diff] [blame] | 2792 | r.putInHistory(); |
Craig Mautner | de4ef02 | 2013-04-07 19:01:33 -0700 | [diff] [blame] | 2793 | if (!isHomeStack() || numActivities() > 0) { |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 2794 | // We want to show the starting preview window if we are |
| 2795 | // switching to a new task, or the next activity's process is |
| 2796 | // not currently running. |
| 2797 | boolean showStartingIcon = newTask; |
| 2798 | ProcessRecord proc = r.app; |
| 2799 | if (proc == null) { |
| 2800 | proc = mService.mProcessNames.get(r.processName, r.info.applicationInfo.uid); |
| 2801 | } |
| 2802 | if (proc == null || proc.thread == null) { |
| 2803 | showStartingIcon = true; |
| 2804 | } |
Wale Ogunwale | ee006da | 2015-03-30 14:49:25 -0700 | [diff] [blame] | 2805 | if (DEBUG_TRANSITION) Slog.v(TAG_TRANSITION, |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 2806 | "Prepare open transition: starting " + r); |
Wale Ogunwale | ee006da | 2015-03-30 14:49:25 -0700 | [diff] [blame] | 2807 | if ((r.intent.getFlags() & Intent.FLAG_ACTIVITY_NO_ANIMATION) != 0) { |
Jorim Jaggi | af80db4 | 2016-04-07 19:19:15 -0700 | [diff] [blame] | 2808 | mWindowManager.prepareAppTransition(TRANSIT_NONE, keepCurTransition); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 2809 | mNoAnimActivities.add(r); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 2810 | } else { |
Craig Mautner | ce5f3cb | 2013-04-22 08:58:54 -0700 | [diff] [blame] | 2811 | mWindowManager.prepareAppTransition(newTask |
Craig Mautner | bb74246 | 2014-07-07 15:28:55 -0700 | [diff] [blame] | 2812 | ? r.mLaunchTaskBehind |
Jorim Jaggi | af80db4 | 2016-04-07 19:19:15 -0700 | [diff] [blame] | 2813 | ? TRANSIT_TASK_OPEN_BEHIND |
| 2814 | : TRANSIT_TASK_OPEN |
| 2815 | : TRANSIT_ACTIVITY_OPEN, keepCurTransition); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 2816 | mNoAnimActivities.remove(r); |
| 2817 | } |
Filip Gruszczynski | e5390e7 | 2015-08-18 16:39:00 -0700 | [diff] [blame] | 2818 | addConfigOverride(r, task); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 2819 | boolean doShow = true; |
| 2820 | if (newTask) { |
| 2821 | // Even though this activity is starting fresh, we still need |
| 2822 | // to reset it to make sure we apply affinities to move any |
| 2823 | // existing activities from other tasks in to it. |
| 2824 | // If the caller has requested that the target task be |
| 2825 | // reset, then do so. |
Craig Mautner | 9d4e9bc | 2014-06-18 18:34:56 -0700 | [diff] [blame] | 2826 | if ((r.intent.getFlags() & Intent.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED) != 0) { |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 2827 | resetTaskIfNeededLocked(r, r); |
| 2828 | doShow = topRunningNonDelayedActivityLocked(null) == r; |
| 2829 | } |
Chong Zhang | 280d332 | 2015-11-03 17:27:26 -0800 | [diff] [blame] | 2830 | } else if (options != null && options.getAnimationType() |
George Mount | 70778d7 | 2014-07-01 16:33:45 -0700 | [diff] [blame] | 2831 | == ActivityOptions.ANIM_SCENE_TRANSITION) { |
| 2832 | doShow = false; |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 2833 | } |
Craig Mautner | bb74246 | 2014-07-07 15:28:55 -0700 | [diff] [blame] | 2834 | if (r.mLaunchTaskBehind) { |
| 2835 | // Don't do a starting window for mLaunchTaskBehind. More importantly make sure we |
| 2836 | // tell WindowManager that r is visible even though it is at the back of the stack. |
| 2837 | mWindowManager.setAppVisibility(r.appToken, true); |
Filip Gruszczynski | bc5a6c5 | 2015-09-22 13:13:24 -0700 | [diff] [blame] | 2838 | ensureActivitiesVisibleLocked(null, 0, !PRESERVE_WINDOWS); |
Craig Mautner | bb74246 | 2014-07-07 15:28:55 -0700 | [diff] [blame] | 2839 | } else if (SHOW_APP_STARTING_PREVIEW && doShow) { |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 2840 | // Figure out if we are transitioning from another activity that is |
| 2841 | // "has the same starting icon" as the next one. This allows the |
| 2842 | // window manager to keep the previous window it had previously |
| 2843 | // created, if it still had one. |
Wale Ogunwale | 3b23239 | 2016-05-13 15:37:13 -0700 | [diff] [blame] | 2844 | ActivityRecord prev = r.task.topRunningActivityWithStartingWindowLocked(); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 2845 | if (prev != null) { |
| 2846 | // We don't want to reuse the previous starting preview if: |
| 2847 | // (1) The current activity is in a different task. |
Craig Mautner | 29219d9 | 2013-04-16 20:19:12 -0700 | [diff] [blame] | 2848 | if (prev.task != r.task) { |
| 2849 | prev = null; |
| 2850 | } |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 2851 | // (2) The current activity is already displayed. |
Craig Mautner | 29219d9 | 2013-04-16 20:19:12 -0700 | [diff] [blame] | 2852 | else if (prev.nowVisible) { |
| 2853 | prev = null; |
| 2854 | } |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 2855 | } |
Wale Ogunwale | 3b23239 | 2016-05-13 15:37:13 -0700 | [diff] [blame] | 2856 | r.showStartingWindow(prev, showStartingIcon); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 2857 | } |
| 2858 | } else { |
| 2859 | // If this is the first activity, don't do any fancy animations, |
| 2860 | // because there is nothing for it to animate on top of. |
Filip Gruszczynski | e5390e7 | 2015-08-18 16:39:00 -0700 | [diff] [blame] | 2861 | addConfigOverride(r, task); |
Dianne Hackborn | 8078d8c | 2012-03-20 11:11:26 -0700 | [diff] [blame] | 2862 | ActivityOptions.abort(options); |
Craig Mautner | 233ceee | 2014-05-09 17:05:11 -0700 | [diff] [blame] | 2863 | options = null; |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 2864 | } |
| 2865 | if (VALIDATE_TOKENS) { |
Dianne Hackborn | be70785 | 2011-11-11 14:32:10 -0800 | [diff] [blame] | 2866 | validateAppTokensLocked(); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 2867 | } |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 2868 | } |
| 2869 | |
Dianne Hackborn | be70785 | 2011-11-11 14:32:10 -0800 | [diff] [blame] | 2870 | final void validateAppTokensLocked() { |
| 2871 | mValidateAppTokens.clear(); |
Craig Mautner | 000f002 | 2013-02-26 15:04:29 -0800 | [diff] [blame] | 2872 | mValidateAppTokens.ensureCapacity(numActivities()); |
| 2873 | final int numTasks = mTaskHistory.size(); |
| 2874 | for (int taskNdx = 0; taskNdx < numTasks; ++taskNdx) { |
| 2875 | TaskRecord task = mTaskHistory.get(taskNdx); |
| 2876 | final ArrayList<ActivityRecord> activities = task.mActivities; |
Craig Mautner | c8143c6 | 2013-09-03 12:15:57 -0700 | [diff] [blame] | 2877 | if (activities.isEmpty()) { |
Craig Mautner | 000f002 | 2013-02-26 15:04:29 -0800 | [diff] [blame] | 2878 | continue; |
Craig Mautner | b1fd65c0 | 2013-02-05 13:34:57 -0800 | [diff] [blame] | 2879 | } |
Craig Mautner | 000f002 | 2013-02-26 15:04:29 -0800 | [diff] [blame] | 2880 | TaskGroup group = new TaskGroup(); |
| 2881 | group.taskId = task.taskId; |
| 2882 | mValidateAppTokens.add(group); |
| 2883 | final int numActivities = activities.size(); |
| 2884 | for (int activityNdx = 0; activityNdx < numActivities; ++activityNdx) { |
| 2885 | final ActivityRecord r = activities.get(activityNdx); |
| 2886 | group.tokens.add(r.appToken); |
| 2887 | } |
Dianne Hackborn | be70785 | 2011-11-11 14:32:10 -0800 | [diff] [blame] | 2888 | } |
Craig Mautner | ce5f3cb | 2013-04-22 08:58:54 -0700 | [diff] [blame] | 2889 | mWindowManager.validateAppTokens(mStackId, mValidateAppTokens); |
Dianne Hackborn | be70785 | 2011-11-11 14:32:10 -0800 | [diff] [blame] | 2890 | } |
| 2891 | |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 2892 | /** |
| 2893 | * Perform a reset of the given task, if needed as part of launching it. |
| 2894 | * Returns the new HistoryRecord at the top of the task. |
| 2895 | */ |
Craig Mautner | e3a74d5 | 2013-02-22 14:14:58 -0800 | [diff] [blame] | 2896 | /** |
| 2897 | * Helper method for #resetTaskIfNeededLocked. |
| 2898 | * We are inside of the task being reset... we'll either finish this activity, push it out |
| 2899 | * for another task, or leave it as-is. |
| 2900 | * @param task The task containing the Activity (taskTop) that might be reset. |
| 2901 | * @param forceReset |
| 2902 | * @return An ActivityOptions that needs to be processed. |
| 2903 | */ |
Craig Mautner | ce5f3cb | 2013-04-22 08:58:54 -0700 | [diff] [blame] | 2904 | final ActivityOptions resetTargetTaskIfNeededLocked(TaskRecord task, boolean forceReset) { |
Craig Mautner | e3a74d5 | 2013-02-22 14:14:58 -0800 | [diff] [blame] | 2905 | ActivityOptions topOptions = null; |
| 2906 | |
| 2907 | int replyChainEnd = -1; |
| 2908 | boolean canMoveOptions = true; |
| 2909 | |
| 2910 | // We only do this for activities that are not the root of the task (since if we finish |
| 2911 | // the root, we may no longer have the task!). |
| 2912 | final ArrayList<ActivityRecord> activities = task.mActivities; |
| 2913 | final int numActivities = activities.size(); |
Craig Mautner | 9d4e9bc | 2014-06-18 18:34:56 -0700 | [diff] [blame] | 2914 | final int rootActivityNdx = task.findEffectiveRootIndex(); |
| 2915 | for (int i = numActivities - 1; i > rootActivityNdx; --i ) { |
Craig Mautner | e3a74d5 | 2013-02-22 14:14:58 -0800 | [diff] [blame] | 2916 | ActivityRecord target = activities.get(i); |
Craig Mautner | 76ae2f0 | 2014-07-16 16:16:19 +0000 | [diff] [blame] | 2917 | if (target.frontOfTask) |
| 2918 | break; |
Craig Mautner | e3a74d5 | 2013-02-22 14:14:58 -0800 | [diff] [blame] | 2919 | |
| 2920 | final int flags = target.info.flags; |
| 2921 | final boolean finishOnTaskLaunch = |
| 2922 | (flags & ActivityInfo.FLAG_FINISH_ON_TASK_LAUNCH) != 0; |
| 2923 | final boolean allowTaskReparenting = |
| 2924 | (flags & ActivityInfo.FLAG_ALLOW_TASK_REPARENTING) != 0; |
| 2925 | final boolean clearWhenTaskReset = |
| 2926 | (target.intent.getFlags() & Intent.FLAG_ACTIVITY_CLEAR_WHEN_TASK_RESET) != 0; |
| 2927 | |
| 2928 | if (!finishOnTaskLaunch |
| 2929 | && !clearWhenTaskReset |
| 2930 | && target.resultTo != null) { |
| 2931 | // If this activity is sending a reply to a previous |
| 2932 | // activity, we can't do anything with it now until |
| 2933 | // we reach the start of the reply chain. |
| 2934 | // XXX note that we are assuming the result is always |
| 2935 | // to the previous activity, which is almost always |
| 2936 | // the case but we really shouldn't count on. |
| 2937 | if (replyChainEnd < 0) { |
| 2938 | replyChainEnd = i; |
| 2939 | } |
| 2940 | } else if (!finishOnTaskLaunch |
| 2941 | && !clearWhenTaskReset |
| 2942 | && allowTaskReparenting |
| 2943 | && target.taskAffinity != null |
| 2944 | && !target.taskAffinity.equals(task.affinity)) { |
| 2945 | // If this activity has an affinity for another |
| 2946 | // task, then we need to move it out of here. We will |
| 2947 | // move it as far out of the way as possible, to the |
| 2948 | // bottom of the activity stack. This also keeps it |
| 2949 | // correctly ordered with any activities we previously |
| 2950 | // moved. |
Craig Mautner | 329f412 | 2013-11-07 09:10:42 -0800 | [diff] [blame] | 2951 | final TaskRecord targetTask; |
Craig Mautner | dccb770 | 2013-09-17 15:53:34 -0700 | [diff] [blame] | 2952 | final ActivityRecord bottom = |
| 2953 | !mTaskHistory.isEmpty() && !mTaskHistory.get(0).mActivities.isEmpty() ? |
Craig Mautner | 329f412 | 2013-11-07 09:10:42 -0800 | [diff] [blame] | 2954 | mTaskHistory.get(0).mActivities.get(0) : null; |
Craig Mautner | dccb770 | 2013-09-17 15:53:34 -0700 | [diff] [blame] | 2955 | if (bottom != null && target.taskAffinity != null |
| 2956 | && target.taskAffinity.equals(bottom.task.affinity)) { |
Craig Mautner | e3a74d5 | 2013-02-22 14:14:58 -0800 | [diff] [blame] | 2957 | // If the activity currently at the bottom has the |
| 2958 | // same task affinity as the one we are moving, |
| 2959 | // then merge it into the same task. |
Craig Mautner | 329f412 | 2013-11-07 09:10:42 -0800 | [diff] [blame] | 2960 | targetTask = bottom.task; |
Wale Ogunwale | ee006da | 2015-03-30 14:49:25 -0700 | [diff] [blame] | 2961 | if (DEBUG_TASKS) Slog.v(TAG_TASKS, "Start pushing activity " + target |
Craig Mautner | dccb770 | 2013-09-17 15:53:34 -0700 | [diff] [blame] | 2962 | + " out to bottom task " + bottom.task); |
Craig Mautner | e3a74d5 | 2013-02-22 14:14:58 -0800 | [diff] [blame] | 2963 | } else { |
Suprabh Shukla | 09a88f5 | 2015-12-02 14:36:31 -0800 | [diff] [blame] | 2964 | targetTask = createTaskRecord( |
| 2965 | mStackSupervisor.getNextTaskIdForUserLocked(target.userId), |
| 2966 | target.info, null, null, null, false); |
Craig Mautner | 329f412 | 2013-11-07 09:10:42 -0800 | [diff] [blame] | 2967 | targetTask.affinityIntent = target.intent; |
Wale Ogunwale | ee006da | 2015-03-30 14:49:25 -0700 | [diff] [blame] | 2968 | if (DEBUG_TASKS) Slog.v(TAG_TASKS, "Start pushing activity " + target |
Craig Mautner | e3a74d5 | 2013-02-22 14:14:58 -0800 | [diff] [blame] | 2969 | + " out to new task " + target.task); |
| 2970 | } |
| 2971 | |
Wale Ogunwale | 706ed79 | 2015-08-02 10:29:44 -0700 | [diff] [blame] | 2972 | setAppTask(target, targetTask); |
Craig Mautner | e3a74d5 | 2013-02-22 14:14:58 -0800 | [diff] [blame] | 2973 | |
Craig Mautner | 525f3d9 | 2013-05-07 14:01:50 -0700 | [diff] [blame] | 2974 | boolean noOptions = canMoveOptions; |
Craig Mautner | e3a74d5 | 2013-02-22 14:14:58 -0800 | [diff] [blame] | 2975 | final int start = replyChainEnd < 0 ? i : replyChainEnd; |
| 2976 | for (int srcPos = start; srcPos >= i; --srcPos) { |
Craig Mautner | dccb770 | 2013-09-17 15:53:34 -0700 | [diff] [blame] | 2977 | final ActivityRecord p = activities.get(srcPos); |
Craig Mautner | e3a74d5 | 2013-02-22 14:14:58 -0800 | [diff] [blame] | 2978 | if (p.finishing) { |
| 2979 | continue; |
| 2980 | } |
| 2981 | |
Craig Mautner | e3a74d5 | 2013-02-22 14:14:58 -0800 | [diff] [blame] | 2982 | canMoveOptions = false; |
Craig Mautner | 525f3d9 | 2013-05-07 14:01:50 -0700 | [diff] [blame] | 2983 | if (noOptions && topOptions == null) { |
Craig Mautner | e3a74d5 | 2013-02-22 14:14:58 -0800 | [diff] [blame] | 2984 | topOptions = p.takeOptionsLocked(); |
| 2985 | if (topOptions != null) { |
Craig Mautner | 525f3d9 | 2013-05-07 14:01:50 -0700 | [diff] [blame] | 2986 | noOptions = false; |
Craig Mautner | e3a74d5 | 2013-02-22 14:14:58 -0800 | [diff] [blame] | 2987 | } |
| 2988 | } |
Wale Ogunwale | 0fc365c | 2015-05-25 19:35:42 -0700 | [diff] [blame] | 2989 | if (DEBUG_ADD_REMOVE) Slog.i(TAG_ADD_REMOVE, |
| 2990 | "Removing activity " + p + " from task=" + task + " adding to task=" |
| 2991 | + targetTask + " Callers=" + Debug.getCallers(4)); |
Wale Ogunwale | ee006da | 2015-03-30 14:49:25 -0700 | [diff] [blame] | 2992 | if (DEBUG_TASKS) Slog.v(TAG_TASKS, |
| 2993 | "Pushing next activity " + p + " out to target's task " + target.task); |
Craig Mautner | a228ae9 | 2014-07-09 05:44:55 -0700 | [diff] [blame] | 2994 | p.setTask(targetTask, null); |
Craig Mautner | e3a74d5 | 2013-02-22 14:14:58 -0800 | [diff] [blame] | 2995 | targetTask.addActivityAtBottom(p); |
Craig Mautner | 0247fc8 | 2013-02-28 14:32:06 -0800 | [diff] [blame] | 2996 | |
Wale Ogunwale | 706ed79 | 2015-08-02 10:29:44 -0700 | [diff] [blame] | 2997 | setAppTask(p, targetTask); |
Craig Mautner | e3a74d5 | 2013-02-22 14:14:58 -0800 | [diff] [blame] | 2998 | } |
| 2999 | |
Wale Ogunwale | 706ed79 | 2015-08-02 10:29:44 -0700 | [diff] [blame] | 3000 | mWindowManager.moveTaskToBottom(targetTask.taskId); |
Craig Mautner | e3a74d5 | 2013-02-22 14:14:58 -0800 | [diff] [blame] | 3001 | if (VALIDATE_TOKENS) { |
| 3002 | validateAppTokensLocked(); |
| 3003 | } |
| 3004 | |
| 3005 | replyChainEnd = -1; |
| 3006 | } else if (forceReset || finishOnTaskLaunch || clearWhenTaskReset) { |
| 3007 | // If the activity should just be removed -- either |
| 3008 | // because it asks for it, or the task should be |
| 3009 | // cleared -- then finish it and anything that is |
| 3010 | // part of its reply chain. |
| 3011 | int end; |
| 3012 | if (clearWhenTaskReset) { |
| 3013 | // In this case, we want to finish this activity |
| 3014 | // and everything above it, so be sneaky and pretend |
| 3015 | // like these are all in the reply chain. |
Mark Lu | 4b5a9a0 | 2014-12-09 14:47:13 +0800 | [diff] [blame] | 3016 | end = activities.size() - 1; |
Craig Mautner | e3a74d5 | 2013-02-22 14:14:58 -0800 | [diff] [blame] | 3017 | } else if (replyChainEnd < 0) { |
| 3018 | end = i; |
| 3019 | } else { |
| 3020 | end = replyChainEnd; |
| 3021 | } |
Craig Mautner | 525f3d9 | 2013-05-07 14:01:50 -0700 | [diff] [blame] | 3022 | boolean noOptions = canMoveOptions; |
Craig Mautner | e3a74d5 | 2013-02-22 14:14:58 -0800 | [diff] [blame] | 3023 | for (int srcPos = i; srcPos <= end; srcPos++) { |
Craig Mautner | 525f3d9 | 2013-05-07 14:01:50 -0700 | [diff] [blame] | 3024 | ActivityRecord p = activities.get(srcPos); |
Craig Mautner | e3a74d5 | 2013-02-22 14:14:58 -0800 | [diff] [blame] | 3025 | if (p.finishing) { |
| 3026 | continue; |
| 3027 | } |
| 3028 | canMoveOptions = false; |
Craig Mautner | 525f3d9 | 2013-05-07 14:01:50 -0700 | [diff] [blame] | 3029 | if (noOptions && topOptions == null) { |
Craig Mautner | e3a74d5 | 2013-02-22 14:14:58 -0800 | [diff] [blame] | 3030 | topOptions = p.takeOptionsLocked(); |
| 3031 | if (topOptions != null) { |
Craig Mautner | 525f3d9 | 2013-05-07 14:01:50 -0700 | [diff] [blame] | 3032 | noOptions = false; |
Craig Mautner | e3a74d5 | 2013-02-22 14:14:58 -0800 | [diff] [blame] | 3033 | } |
| 3034 | } |
Wale Ogunwale | ee006da | 2015-03-30 14:49:25 -0700 | [diff] [blame] | 3035 | if (DEBUG_TASKS) Slog.w(TAG_TASKS, |
Craig Mautner | 5854780 | 2013-03-05 08:23:53 -0800 | [diff] [blame] | 3036 | "resetTaskIntendedTask: calling finishActivity on " + p); |
Todd Kennedy | 539db51 | 2014-12-15 09:57:55 -0800 | [diff] [blame] | 3037 | if (finishActivityLocked( |
| 3038 | p, Activity.RESULT_CANCELED, null, "reset-task", false)) { |
Craig Mautner | e3a74d5 | 2013-02-22 14:14:58 -0800 | [diff] [blame] | 3039 | end--; |
| 3040 | srcPos--; |
| 3041 | } |
| 3042 | } |
| 3043 | replyChainEnd = -1; |
| 3044 | } else { |
| 3045 | // If we were in the middle of a chain, well the |
| 3046 | // activity that started it all doesn't want anything |
| 3047 | // special, so leave it all as-is. |
| 3048 | replyChainEnd = -1; |
| 3049 | } |
| 3050 | } |
| 3051 | |
| 3052 | return topOptions; |
| 3053 | } |
| 3054 | |
| 3055 | /** |
| 3056 | * Helper method for #resetTaskIfNeededLocked. Processes all of the activities in a given |
| 3057 | * TaskRecord looking for an affinity with the task of resetTaskIfNeededLocked.taskTop. |
| 3058 | * @param affinityTask The task we are looking for an affinity to. |
| 3059 | * @param task Task that resetTaskIfNeededLocked.taskTop belongs to. |
| 3060 | * @param topTaskIsHigher True if #task has already been processed by resetTaskIfNeededLocked. |
| 3061 | * @param forceReset Flag passed in to resetTaskIfNeededLocked. |
| 3062 | */ |
Craig Mautner | 525f3d9 | 2013-05-07 14:01:50 -0700 | [diff] [blame] | 3063 | private int resetAffinityTaskIfNeededLocked(TaskRecord affinityTask, TaskRecord task, |
Craig Mautner | 7787877 | 2013-03-04 19:46:24 -0800 | [diff] [blame] | 3064 | boolean topTaskIsHigher, boolean forceReset, int taskInsertionPoint) { |
Craig Mautner | e3a74d5 | 2013-02-22 14:14:58 -0800 | [diff] [blame] | 3065 | int replyChainEnd = -1; |
| 3066 | final int taskId = task.taskId; |
| 3067 | final String taskAffinity = task.affinity; |
| 3068 | |
| 3069 | final ArrayList<ActivityRecord> activities = affinityTask.mActivities; |
| 3070 | final int numActivities = activities.size(); |
Craig Mautner | 9d4e9bc | 2014-06-18 18:34:56 -0700 | [diff] [blame] | 3071 | final int rootActivityNdx = affinityTask.findEffectiveRootIndex(); |
| 3072 | |
| 3073 | // Do not operate on or below the effective root Activity. |
| 3074 | for (int i = numActivities - 1; i > rootActivityNdx; --i) { |
Craig Mautner | e3a74d5 | 2013-02-22 14:14:58 -0800 | [diff] [blame] | 3075 | ActivityRecord target = activities.get(i); |
Craig Mautner | 76ae2f0 | 2014-07-16 16:16:19 +0000 | [diff] [blame] | 3076 | if (target.frontOfTask) |
| 3077 | break; |
Craig Mautner | e3a74d5 | 2013-02-22 14:14:58 -0800 | [diff] [blame] | 3078 | |
| 3079 | final int flags = target.info.flags; |
| 3080 | boolean finishOnTaskLaunch = (flags & ActivityInfo.FLAG_FINISH_ON_TASK_LAUNCH) != 0; |
| 3081 | boolean allowTaskReparenting = (flags & ActivityInfo.FLAG_ALLOW_TASK_REPARENTING) != 0; |
| 3082 | |
| 3083 | if (target.resultTo != null) { |
| 3084 | // If this activity is sending a reply to a previous |
| 3085 | // activity, we can't do anything with it now until |
| 3086 | // we reach the start of the reply chain. |
| 3087 | // XXX note that we are assuming the result is always |
| 3088 | // to the previous activity, which is almost always |
| 3089 | // the case but we really shouldn't count on. |
| 3090 | if (replyChainEnd < 0) { |
| 3091 | replyChainEnd = i; |
| 3092 | } |
| 3093 | } else if (topTaskIsHigher |
| 3094 | && allowTaskReparenting |
| 3095 | && taskAffinity != null |
| 3096 | && taskAffinity.equals(target.taskAffinity)) { |
| 3097 | // This activity has an affinity for our task. Either remove it if we are |
| 3098 | // clearing or move it over to our task. Note that |
| 3099 | // we currently punt on the case where we are resetting a |
| 3100 | // task that is not at the top but who has activities above |
| 3101 | // with an affinity to it... this is really not a normal |
| 3102 | // case, and we will need to later pull that task to the front |
| 3103 | // and usually at that point we will do the reset and pick |
| 3104 | // up those remaining activities. (This only happens if |
| 3105 | // someone starts an activity in a new task from an activity |
| 3106 | // in a task that is not currently on top.) |
| 3107 | if (forceReset || finishOnTaskLaunch) { |
| 3108 | final int start = replyChainEnd >= 0 ? replyChainEnd : i; |
Wale Ogunwale | ee006da | 2015-03-30 14:49:25 -0700 | [diff] [blame] | 3109 | if (DEBUG_TASKS) Slog.v(TAG_TASKS, |
| 3110 | "Finishing task at index " + start + " to " + i); |
Craig Mautner | e3a74d5 | 2013-02-22 14:14:58 -0800 | [diff] [blame] | 3111 | for (int srcPos = start; srcPos >= i; --srcPos) { |
| 3112 | final ActivityRecord p = activities.get(srcPos); |
| 3113 | if (p.finishing) { |
| 3114 | continue; |
| 3115 | } |
Todd Kennedy | 539db51 | 2014-12-15 09:57:55 -0800 | [diff] [blame] | 3116 | finishActivityLocked( |
| 3117 | p, Activity.RESULT_CANCELED, null, "move-affinity", false); |
Craig Mautner | e3a74d5 | 2013-02-22 14:14:58 -0800 | [diff] [blame] | 3118 | } |
| 3119 | } else { |
Craig Mautner | 7787877 | 2013-03-04 19:46:24 -0800 | [diff] [blame] | 3120 | if (taskInsertionPoint < 0) { |
| 3121 | taskInsertionPoint = task.mActivities.size(); |
Craig Mautner | d232895 | 2013-03-05 12:46:26 -0800 | [diff] [blame] | 3122 | |
Craig Mautner | 7787877 | 2013-03-04 19:46:24 -0800 | [diff] [blame] | 3123 | } |
Craig Mautner | 7787877 | 2013-03-04 19:46:24 -0800 | [diff] [blame] | 3124 | |
| 3125 | final int start = replyChainEnd >= 0 ? replyChainEnd : i; |
Wale Ogunwale | ee006da | 2015-03-30 14:49:25 -0700 | [diff] [blame] | 3126 | if (DEBUG_TASKS) Slog.v(TAG_TASKS, |
| 3127 | "Reparenting from task=" + affinityTask + ":" + start + "-" + i |
| 3128 | + " to task=" + task + ":" + taskInsertionPoint); |
Craig Mautner | 7787877 | 2013-03-04 19:46:24 -0800 | [diff] [blame] | 3129 | for (int srcPos = start; srcPos >= i; --srcPos) { |
Craig Mautner | e3a74d5 | 2013-02-22 14:14:58 -0800 | [diff] [blame] | 3130 | final ActivityRecord p = activities.get(srcPos); |
Craig Mautner | a228ae9 | 2014-07-09 05:44:55 -0700 | [diff] [blame] | 3131 | p.setTask(task, null); |
Craig Mautner | 7787877 | 2013-03-04 19:46:24 -0800 | [diff] [blame] | 3132 | task.addActivityAtIndex(taskInsertionPoint, p); |
Craig Mautner | e3a74d5 | 2013-02-22 14:14:58 -0800 | [diff] [blame] | 3133 | |
Wale Ogunwale | 0fc365c | 2015-05-25 19:35:42 -0700 | [diff] [blame] | 3134 | if (DEBUG_ADD_REMOVE) Slog.i(TAG_ADD_REMOVE, |
| 3135 | "Removing and adding activity " + p + " to stack at " + task |
| 3136 | + " callers=" + Debug.getCallers(3)); |
Wale Ogunwale | ee006da | 2015-03-30 14:49:25 -0700 | [diff] [blame] | 3137 | if (DEBUG_TASKS) Slog.v(TAG_TASKS, "Pulling activity " + p |
| 3138 | + " from " + srcPos + " in to resetting task " + task); |
Wale Ogunwale | 706ed79 | 2015-08-02 10:29:44 -0700 | [diff] [blame] | 3139 | setAppTask(p, task); |
Craig Mautner | e3a74d5 | 2013-02-22 14:14:58 -0800 | [diff] [blame] | 3140 | } |
Craig Mautner | ce5f3cb | 2013-04-22 08:58:54 -0700 | [diff] [blame] | 3141 | mWindowManager.moveTaskToTop(taskId); |
Craig Mautner | 9658b31 | 2013-02-28 10:55:59 -0800 | [diff] [blame] | 3142 | if (VALIDATE_TOKENS) { |
| 3143 | validateAppTokensLocked(); |
| 3144 | } |
Craig Mautner | e3a74d5 | 2013-02-22 14:14:58 -0800 | [diff] [blame] | 3145 | |
| 3146 | // Now we've moved it in to place... but what if this is |
| 3147 | // a singleTop activity and we have put it on top of another |
| 3148 | // instance of the same activity? Then we drop the instance |
| 3149 | // below so it remains singleTop. |
| 3150 | if (target.info.launchMode == ActivityInfo.LAUNCH_SINGLE_TOP) { |
| 3151 | ArrayList<ActivityRecord> taskActivities = task.mActivities; |
Craig Mautner | e3a74d5 | 2013-02-22 14:14:58 -0800 | [diff] [blame] | 3152 | int targetNdx = taskActivities.indexOf(target); |
| 3153 | if (targetNdx > 0) { |
| 3154 | ActivityRecord p = taskActivities.get(targetNdx - 1); |
| 3155 | if (p.intent.getComponent().equals(target.intent.getComponent())) { |
Craig Mautner | 5854780 | 2013-03-05 08:23:53 -0800 | [diff] [blame] | 3156 | finishActivityLocked(p, Activity.RESULT_CANCELED, null, "replace", |
| 3157 | false); |
Craig Mautner | e3a74d5 | 2013-02-22 14:14:58 -0800 | [diff] [blame] | 3158 | } |
| 3159 | } |
| 3160 | } |
| 3161 | } |
| 3162 | |
| 3163 | replyChainEnd = -1; |
| 3164 | } |
| 3165 | } |
Craig Mautner | 7787877 | 2013-03-04 19:46:24 -0800 | [diff] [blame] | 3166 | return taskInsertionPoint; |
Craig Mautner | e3a74d5 | 2013-02-22 14:14:58 -0800 | [diff] [blame] | 3167 | } |
| 3168 | |
Craig Mautner | 8849a5e | 2013-04-02 16:41:03 -0700 | [diff] [blame] | 3169 | final ActivityRecord resetTaskIfNeededLocked(ActivityRecord taskTop, |
Craig Mautner | e3a74d5 | 2013-02-22 14:14:58 -0800 | [diff] [blame] | 3170 | ActivityRecord newActivity) { |
| 3171 | boolean forceReset = |
| 3172 | (newActivity.info.flags & ActivityInfo.FLAG_CLEAR_TASK_ON_LAUNCH) != 0; |
| 3173 | if (ACTIVITY_INACTIVE_RESET_TIME > 0 |
| 3174 | && taskTop.task.getInactiveDuration() > ACTIVITY_INACTIVE_RESET_TIME) { |
| 3175 | if ((newActivity.info.flags & ActivityInfo.FLAG_ALWAYS_RETAIN_TASK_STATE) == 0) { |
| 3176 | forceReset = true; |
| 3177 | } |
| 3178 | } |
| 3179 | |
| 3180 | final TaskRecord task = taskTop.task; |
| 3181 | |
| 3182 | /** False until we evaluate the TaskRecord associated with taskTop. Switches to true |
| 3183 | * for remaining tasks. Used for later tasks to reparent to task. */ |
| 3184 | boolean taskFound = false; |
| 3185 | |
| 3186 | /** If ActivityOptions are moved out and need to be aborted or moved to taskTop. */ |
| 3187 | ActivityOptions topOptions = null; |
| 3188 | |
Craig Mautner | 7787877 | 2013-03-04 19:46:24 -0800 | [diff] [blame] | 3189 | // Preserve the location for reparenting in the new task. |
| 3190 | int reparentInsertionPoint = -1; |
| 3191 | |
Craig Mautner | e3a74d5 | 2013-02-22 14:14:58 -0800 | [diff] [blame] | 3192 | for (int i = mTaskHistory.size() - 1; i >= 0; --i) { |
| 3193 | final TaskRecord targetTask = mTaskHistory.get(i); |
| 3194 | |
| 3195 | if (targetTask == task) { |
| 3196 | topOptions = resetTargetTaskIfNeededLocked(task, forceReset); |
| 3197 | taskFound = true; |
| 3198 | } else { |
Craig Mautner | 7787877 | 2013-03-04 19:46:24 -0800 | [diff] [blame] | 3199 | reparentInsertionPoint = resetAffinityTaskIfNeededLocked(targetTask, task, |
| 3200 | taskFound, forceReset, reparentInsertionPoint); |
Craig Mautner | e3a74d5 | 2013-02-22 14:14:58 -0800 | [diff] [blame] | 3201 | } |
| 3202 | } |
| 3203 | |
Craig Mautner | 70a8693 | 2013-02-28 22:37:44 -0800 | [diff] [blame] | 3204 | int taskNdx = mTaskHistory.indexOf(task); |
riddle_hsu | 1d7919a | 2015-03-11 17:09:50 +0800 | [diff] [blame] | 3205 | if (taskNdx >= 0) { |
| 3206 | do { |
| 3207 | taskTop = mTaskHistory.get(taskNdx--).getTopActivity(); |
| 3208 | } while (taskTop == null && taskNdx >= 0); |
| 3209 | } |
Craig Mautner | 70a8693 | 2013-02-28 22:37:44 -0800 | [diff] [blame] | 3210 | |
Craig Mautner | e3a74d5 | 2013-02-22 14:14:58 -0800 | [diff] [blame] | 3211 | if (topOptions != null) { |
| 3212 | // If we got some ActivityOptions from an activity on top that |
| 3213 | // was removed from the task, propagate them to the new real top. |
| 3214 | if (taskTop != null) { |
Craig Mautner | e3a74d5 | 2013-02-22 14:14:58 -0800 | [diff] [blame] | 3215 | taskTop.updateOptionsLocked(topOptions); |
| 3216 | } else { |
Craig Mautner | e3a74d5 | 2013-02-22 14:14:58 -0800 | [diff] [blame] | 3217 | topOptions.abort(); |
| 3218 | } |
| 3219 | } |
| 3220 | |
| 3221 | return taskTop; |
| 3222 | } |
| 3223 | |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 3224 | void sendActivityResultLocked(int callingUid, ActivityRecord r, |
| 3225 | String resultWho, int requestCode, int resultCode, Intent data) { |
| 3226 | |
| 3227 | if (callingUid > 0) { |
| 3228 | mService.grantUriPermissionFromIntentLocked(callingUid, r.packageName, |
Nicolas Prevot | c6cf95c | 2014-05-29 11:30:36 +0100 | [diff] [blame] | 3229 | data, r.getUriPermissionsLocked(), r.userId); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 3230 | } |
| 3231 | |
| 3232 | if (DEBUG_RESULTS) Slog.v(TAG, "Send activity result to " + r |
| 3233 | + " : who=" + resultWho + " req=" + requestCode |
| 3234 | + " res=" + resultCode + " data=" + data); |
| 3235 | if (mResumedActivity == r && r.app != null && r.app.thread != null) { |
| 3236 | try { |
| 3237 | ArrayList<ResultInfo> list = new ArrayList<ResultInfo>(); |
| 3238 | list.add(new ResultInfo(resultWho, requestCode, |
| 3239 | resultCode, data)); |
Dianne Hackborn | be70785 | 2011-11-11 14:32:10 -0800 | [diff] [blame] | 3240 | r.app.thread.scheduleSendResult(r.appToken, list); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 3241 | return; |
| 3242 | } catch (Exception e) { |
| 3243 | Slog.w(TAG, "Exception thrown sending result to " + r, e); |
| 3244 | } |
| 3245 | } |
| 3246 | |
| 3247 | r.addResultLocked(null, resultWho, requestCode, resultCode, data); |
| 3248 | } |
| 3249 | |
Chong Zhang | 6cda19c | 2016-06-14 19:07:56 -0700 | [diff] [blame] | 3250 | private void adjustFocusedActivityStackLocked(ActivityRecord r, String reason) { |
| 3251 | if (!mStackSupervisor.isFocusedStack(this) || mResumedActivity != r) { |
Wale Ogunwale | d045c82 | 2015-12-02 09:14:28 -0800 | [diff] [blame] | 3252 | return; |
| 3253 | } |
| 3254 | |
| 3255 | final ActivityRecord next = topRunningActivityLocked(); |
| 3256 | final String myReason = reason + " adjustFocus"; |
| 3257 | if (next != r) { |
Wale Ogunwale | 4cea0f5 | 2015-12-25 06:30:31 -0800 | [diff] [blame] | 3258 | if (next != null && StackId.keepFocusInStackIfPossible(mStackId) && isFocusable()) { |
Wale Ogunwale | d045c82 | 2015-12-02 09:14:28 -0800 | [diff] [blame] | 3259 | // For freeform, docked, and pinned stacks we always keep the focus within the |
Chong Zhang | 6cda19c | 2016-06-14 19:07:56 -0700 | [diff] [blame] | 3260 | // stack as long as there is a running activity. |
Wale Ogunwale | d045c82 | 2015-12-02 09:14:28 -0800 | [diff] [blame] | 3261 | return; |
| 3262 | } else { |
| 3263 | final TaskRecord task = r.task; |
| 3264 | if (r.frontOfTask && task == topTask() && task.isOverHomeStack()) { |
Wale Ogunwale | d34e80c | 2016-03-23 17:08:44 -0700 | [diff] [blame] | 3265 | final int taskToReturnTo = task.getTaskToReturnTo(); |
| 3266 | |
Wale Ogunwale | d045c82 | 2015-12-02 09:14:28 -0800 | [diff] [blame] | 3267 | // For non-fullscreen stack, we want to move the focus to the next visible |
| 3268 | // stack to prevent the home screen from moving to the top and obscuring |
| 3269 | // other visible stacks. |
Wale Ogunwale | d34e80c | 2016-03-23 17:08:44 -0700 | [diff] [blame] | 3270 | if (!mFullscreen |
| 3271 | && adjustFocusToNextFocusableStackLocked(taskToReturnTo, myReason)) { |
Wale Ogunwale | d045c82 | 2015-12-02 09:14:28 -0800 | [diff] [blame] | 3272 | return; |
| 3273 | } |
| 3274 | // Move the home stack to the top if this stack is fullscreen or there is no |
| 3275 | // other visible stack. |
Wale Ogunwale | d34e80c | 2016-03-23 17:08:44 -0700 | [diff] [blame] | 3276 | if (mStackSupervisor.moveHomeStackTaskToTop(taskToReturnTo, myReason)) { |
Wale Ogunwale | d045c82 | 2015-12-02 09:14:28 -0800 | [diff] [blame] | 3277 | // Activity focus was already adjusted. Nothing else to do... |
| 3278 | return; |
Wale Ogunwale | d80c263 | 2015-03-13 10:26:26 -0700 | [diff] [blame] | 3279 | } |
Craig Mautner | 04f0b70 | 2013-10-22 12:31:01 -0700 | [diff] [blame] | 3280 | } |
| 3281 | } |
Wale Ogunwale | d045c82 | 2015-12-02 09:14:28 -0800 | [diff] [blame] | 3282 | } |
Wale Ogunwale | d697cea | 2015-02-20 17:19:49 -0800 | [diff] [blame] | 3283 | |
Chong Zhang | 6cda19c | 2016-06-14 19:07:56 -0700 | [diff] [blame] | 3284 | mStackSupervisor.moveFocusableActivityStackToFrontLocked( |
| 3285 | mStackSupervisor.topRunningActivityLocked(), myReason); |
Craig Mautner | 04f0b70 | 2013-10-22 12:31:01 -0700 | [diff] [blame] | 3286 | } |
| 3287 | |
Wale Ogunwale | d34e80c | 2016-03-23 17:08:44 -0700 | [diff] [blame] | 3288 | private boolean adjustFocusToNextFocusableStackLocked(int taskToReturnTo, String reason) { |
Wale Ogunwale | 4cea0f5 | 2015-12-25 06:30:31 -0800 | [diff] [blame] | 3289 | final ActivityStack stack = getNextFocusableStackLocked(); |
| 3290 | final String myReason = reason + " adjustFocusToNextFocusableStack"; |
Wale Ogunwale | d697cea | 2015-02-20 17:19:49 -0800 | [diff] [blame] | 3291 | if (stack == null) { |
| 3292 | return false; |
| 3293 | } |
Wale Ogunwale | d34e80c | 2016-03-23 17:08:44 -0700 | [diff] [blame] | 3294 | |
Wale Ogunwale | c750f5f | 2016-03-28 07:43:51 -0700 | [diff] [blame] | 3295 | final ActivityRecord top = stack.topRunningActivityLocked(); |
| 3296 | |
| 3297 | if (stack.isHomeStack() && (top == null || !top.visible)) { |
| 3298 | // If we will be focusing on the home stack next and its current top activity isn't |
| 3299 | // visible, then use the task return to value to determine the home task to display next. |
Wale Ogunwale | d34e80c | 2016-03-23 17:08:44 -0700 | [diff] [blame] | 3300 | return mStackSupervisor.moveHomeStackTaskToTop(taskToReturnTo, reason); |
| 3301 | } |
Chong Zhang | 6cda19c | 2016-06-14 19:07:56 -0700 | [diff] [blame] | 3302 | |
| 3303 | stack.moveToFront(myReason); |
| 3304 | return true; |
Wale Ogunwale | d697cea | 2015-02-20 17:19:49 -0800 | [diff] [blame] | 3305 | } |
| 3306 | |
Craig Mautner | f333327 | 2013-04-22 10:55:53 -0700 | [diff] [blame] | 3307 | final void stopActivityLocked(ActivityRecord r) { |
Wale Ogunwale | ee006da | 2015-03-30 14:49:25 -0700 | [diff] [blame] | 3308 | if (DEBUG_SWITCH) Slog.d(TAG_SWITCH, "Stopping: " + r); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 3309 | if ((r.intent.getFlags()&Intent.FLAG_ACTIVITY_NO_HISTORY) != 0 |
| 3310 | || (r.info.flags&ActivityInfo.FLAG_NO_HISTORY) != 0) { |
| 3311 | if (!r.finishing) { |
Fyodor Kupolov | 9b80b94 | 2016-06-16 16:29:05 -0700 | [diff] [blame] | 3312 | if (!mService.isSleepingLocked()) { |
Wale Ogunwale | 0fc365c | 2015-05-25 19:35:42 -0700 | [diff] [blame] | 3313 | if (DEBUG_STATES) Slog.d(TAG_STATES, "no-history finish of " + r); |
Wale Ogunwale | 3f529ee | 2015-07-12 15:14:01 -0700 | [diff] [blame] | 3314 | if (requestFinishActivityLocked(r.appToken, Activity.RESULT_CANCELED, null, |
| 3315 | "stop-no-history", false)) { |
| 3316 | // Activity was finished, no need to continue trying to schedule stop. |
Chong Zhang | 6cda19c | 2016-06-14 19:07:56 -0700 | [diff] [blame] | 3317 | adjustFocusedActivityStackLocked(r, "stopActivityFinished"); |
Wale Ogunwale | 3f529ee | 2015-07-12 15:14:01 -0700 | [diff] [blame] | 3318 | r.resumeKeyDispatchingLocked(); |
| 3319 | return; |
| 3320 | } |
Christopher Tate | d3f175c | 2012-06-14 14:16:54 -0700 | [diff] [blame] | 3321 | } else { |
Wale Ogunwale | 0fc365c | 2015-05-25 19:35:42 -0700 | [diff] [blame] | 3322 | if (DEBUG_STATES) Slog.d(TAG_STATES, "Not finishing noHistory " + r |
Christopher Tate | d3f175c | 2012-06-14 14:16:54 -0700 | [diff] [blame] | 3323 | + " on stop because we're just sleeping"); |
| 3324 | } |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 3325 | } |
Christopher Tate | 5007ddd | 2012-06-12 13:08:18 -0700 | [diff] [blame] | 3326 | } |
| 3327 | |
| 3328 | if (r.app != null && r.app.thread != null) { |
Chong Zhang | 6cda19c | 2016-06-14 19:07:56 -0700 | [diff] [blame] | 3329 | adjustFocusedActivityStackLocked(r, "stopActivity"); |
Dianne Hackborn | 621e2fe | 2012-02-16 17:07:33 -0800 | [diff] [blame] | 3330 | r.resumeKeyDispatchingLocked(); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 3331 | try { |
| 3332 | r.stopped = false; |
Wale Ogunwale | 0fc365c | 2015-05-25 19:35:42 -0700 | [diff] [blame] | 3333 | if (DEBUG_STATES) Slog.v(TAG_STATES, |
| 3334 | "Moving to STOPPING: " + r + " (stop requested)"); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 3335 | r.state = ActivityState.STOPPING; |
Wale Ogunwale | ee006da | 2015-03-30 14:49:25 -0700 | [diff] [blame] | 3336 | if (DEBUG_VISIBILITY) Slog.v(TAG_VISIBILITY, |
| 3337 | "Stopping visible=" + r.visible + " for " + r); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 3338 | if (!r.visible) { |
Craig Mautner | ce5f3cb | 2013-04-22 08:58:54 -0700 | [diff] [blame] | 3339 | mWindowManager.setAppVisibility(r.appToken, false); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 3340 | } |
Wale Ogunwale | cd7043e | 2016-02-27 17:37:46 -0800 | [diff] [blame] | 3341 | EventLogTags.writeAmStopActivity( |
| 3342 | r.userId, System.identityHashCode(r), r.shortComponentName); |
Dianne Hackborn | be70785 | 2011-11-11 14:32:10 -0800 | [diff] [blame] | 3343 | r.app.thread.scheduleStopActivity(r.appToken, r.visible, r.configChangeFlags); |
Fyodor Kupolov | 9b80b94 | 2016-06-16 16:29:05 -0700 | [diff] [blame] | 3344 | if (mService.isSleepingOrShuttingDownLocked()) { |
Dianne Hackborn | 4eba96b | 2011-01-21 13:34:36 -0800 | [diff] [blame] | 3345 | r.setSleeping(true); |
| 3346 | } |
Craig Mautner | f7bfefb | 2013-05-16 17:30:44 -0700 | [diff] [blame] | 3347 | Message msg = mHandler.obtainMessage(STOP_TIMEOUT_MSG, r); |
Dianne Hackborn | 162bc0e | 2012-04-09 14:06:16 -0700 | [diff] [blame] | 3348 | mHandler.sendMessageDelayed(msg, STOP_TIMEOUT); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 3349 | } catch (Exception e) { |
| 3350 | // Maybe just ignore exceptions here... if the process |
| 3351 | // has crashed, our death notification will clean things |
| 3352 | // up. |
| 3353 | Slog.w(TAG, "Exception thrown during pause", e); |
| 3354 | // Just in case, assume it to be stopped. |
| 3355 | r.stopped = true; |
Wale Ogunwale | 0fc365c | 2015-05-25 19:35:42 -0700 | [diff] [blame] | 3356 | 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] | 3357 | r.state = ActivityState.STOPPED; |
Wale Ogunwale | f81c1d1 | 2016-01-12 12:20:18 -0800 | [diff] [blame] | 3358 | if (r.deferRelaunchUntilPaused) { |
Craig Mautner | ee2e45a | 2014-06-27 12:10:03 -0700 | [diff] [blame] | 3359 | destroyActivityLocked(r, true, "stop-except"); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 3360 | } |
| 3361 | } |
| 3362 | } |
| 3363 | } |
Craig Mautner | 23ac33b | 2013-04-01 16:26:35 -0700 | [diff] [blame] | 3364 | |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 3365 | /** |
| 3366 | * @return Returns true if the activity is being finished, false if for |
| 3367 | * some reason it is being left as-is. |
| 3368 | */ |
| 3369 | final boolean requestFinishActivityLocked(IBinder token, int resultCode, |
Dianne Hackborn | 2d1b378 | 2012-09-09 17:49:39 -0700 | [diff] [blame] | 3370 | Intent resultData, String reason, boolean oomAdj) { |
Craig Mautner | d74f7d7 | 2013-02-26 13:41:02 -0800 | [diff] [blame] | 3371 | ActivityRecord r = isInStackLocked(token); |
Wale Ogunwale | 0fc365c | 2015-05-25 19:35:42 -0700 | [diff] [blame] | 3372 | if (DEBUG_RESULTS || DEBUG_STATES) Slog.v(TAG_STATES, |
| 3373 | "Finishing activity token=" + token + " r=" |
Christopher Tate | d3f175c | 2012-06-14 14:16:54 -0700 | [diff] [blame] | 3374 | + ", result=" + resultCode + ", data=" + resultData |
| 3375 | + ", reason=" + reason); |
Craig Mautner | d74f7d7 | 2013-02-26 13:41:02 -0800 | [diff] [blame] | 3376 | if (r == null) { |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 3377 | return false; |
| 3378 | } |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 3379 | |
Craig Mautner | d44711d | 2013-02-23 11:24:36 -0800 | [diff] [blame] | 3380 | finishActivityLocked(r, resultCode, resultData, reason, oomAdj); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 3381 | return true; |
| 3382 | } |
| 3383 | |
Craig Mautner | d232895 | 2013-03-05 12:46:26 -0800 | [diff] [blame] | 3384 | final void finishSubActivityLocked(ActivityRecord self, String resultWho, int requestCode) { |
Craig Mautner | 9658b31 | 2013-02-28 10:55:59 -0800 | [diff] [blame] | 3385 | for (int taskNdx = mTaskHistory.size() - 1; taskNdx >= 0; --taskNdx) { |
| 3386 | ArrayList<ActivityRecord> activities = mTaskHistory.get(taskNdx).mActivities; |
| 3387 | for (int activityNdx = activities.size() - 1; activityNdx >= 0; --activityNdx) { |
| 3388 | ActivityRecord r = activities.get(activityNdx); |
| 3389 | if (r.resultTo == self && r.requestCode == requestCode) { |
| 3390 | if ((r.resultWho == null && resultWho == null) || |
| 3391 | (r.resultWho != null && r.resultWho.equals(resultWho))) { |
| 3392 | finishActivityLocked(r, Activity.RESULT_CANCELED, null, "request-sub", |
| 3393 | false); |
| 3394 | } |
Dianne Hackborn | ecc5a9c | 2012-04-26 18:56:09 -0700 | [diff] [blame] | 3395 | } |
| 3396 | } |
| 3397 | } |
Dianne Hackborn | 2d1b378 | 2012-09-09 17:49:39 -0700 | [diff] [blame] | 3398 | mService.updateOomAdjLocked(); |
Dianne Hackborn | ecc5a9c | 2012-04-26 18:56:09 -0700 | [diff] [blame] | 3399 | } |
| 3400 | |
Adrian Roos | 20d7df3 | 2016-01-12 18:59:43 +0100 | [diff] [blame] | 3401 | final TaskRecord finishTopRunningActivityLocked(ProcessRecord app, String reason) { |
Filip Gruszczynski | 3e85ba2 | 2015-10-05 22:48:30 -0700 | [diff] [blame] | 3402 | ActivityRecord r = topRunningActivityLocked(); |
Adrian Roos | 20d7df3 | 2016-01-12 18:59:43 +0100 | [diff] [blame] | 3403 | TaskRecord finishedTask = null; |
| 3404 | if (r == null || r.app != app) { |
| 3405 | return null; |
| 3406 | } |
| 3407 | Slog.w(TAG, " Force finishing activity " |
| 3408 | + r.intent.getComponent().flattenToShortString()); |
| 3409 | int taskNdx = mTaskHistory.indexOf(r.task); |
| 3410 | int activityNdx = r.task.mActivities.indexOf(r); |
| 3411 | finishActivityLocked(r, Activity.RESULT_CANCELED, null, reason, false); |
| 3412 | finishedTask = r.task; |
| 3413 | // Also terminate any activities below it that aren't yet |
| 3414 | // stopped, to avoid a situation where one will get |
| 3415 | // re-start our crashing activity once it gets resumed again. |
| 3416 | --activityNdx; |
| 3417 | if (activityNdx < 0) { |
| 3418 | do { |
| 3419 | --taskNdx; |
| 3420 | if (taskNdx < 0) { |
| 3421 | break; |
| 3422 | } |
| 3423 | activityNdx = mTaskHistory.get(taskNdx).mActivities.size() - 1; |
| 3424 | } while (activityNdx < 0); |
| 3425 | } |
| 3426 | if (activityNdx >= 0) { |
| 3427 | r = mTaskHistory.get(taskNdx).mActivities.get(activityNdx); |
| 3428 | if (r.state == ActivityState.RESUMED |
| 3429 | || r.state == ActivityState.PAUSING |
| 3430 | || r.state == ActivityState.PAUSED) { |
| 3431 | if (!r.isHomeActivity() || mService.mHomeProcess != r.app) { |
| 3432 | Slog.w(TAG, " Force finishing activity " |
| 3433 | + r.intent.getComponent().flattenToShortString()); |
| 3434 | finishActivityLocked(r, Activity.RESULT_CANCELED, null, reason, false); |
Craig Mautner | 05d6272ba | 2013-02-11 09:39:27 -0800 | [diff] [blame] | 3435 | } |
| 3436 | } |
| 3437 | } |
Adrian Roos | 20d7df3 | 2016-01-12 18:59:43 +0100 | [diff] [blame] | 3438 | return finishedTask; |
Craig Mautner | 05d6272ba | 2013-02-11 09:39:27 -0800 | [diff] [blame] | 3439 | } |
| 3440 | |
Dianne Hackborn | 6ea0d0a | 2014-07-02 16:23:21 -0700 | [diff] [blame] | 3441 | final void finishVoiceTask(IVoiceInteractionSession session) { |
| 3442 | IBinder sessionBinder = session.asBinder(); |
| 3443 | boolean didOne = false; |
| 3444 | for (int taskNdx = mTaskHistory.size() - 1; taskNdx >= 0; --taskNdx) { |
| 3445 | TaskRecord tr = mTaskHistory.get(taskNdx); |
| 3446 | if (tr.voiceSession != null && tr.voiceSession.asBinder() == sessionBinder) { |
| 3447 | for (int activityNdx = tr.mActivities.size() - 1; activityNdx >= 0; --activityNdx) { |
| 3448 | ActivityRecord r = tr.mActivities.get(activityNdx); |
| 3449 | if (!r.finishing) { |
| 3450 | finishActivityLocked(r, Activity.RESULT_CANCELED, null, "finish-voice", |
| 3451 | false); |
| 3452 | didOne = true; |
| 3453 | } |
| 3454 | } |
Amith Yamasani | 0af6fa7 | 2016-01-17 15:36:19 -0800 | [diff] [blame] | 3455 | } else { |
| 3456 | // Check if any of the activities are using voice |
| 3457 | for (int activityNdx = tr.mActivities.size() - 1; activityNdx >= 0; --activityNdx) { |
| 3458 | ActivityRecord r = tr.mActivities.get(activityNdx); |
| 3459 | if (r.voiceSession != null |
| 3460 | && r.voiceSession.asBinder() == sessionBinder) { |
| 3461 | // Inform of cancellation |
| 3462 | r.clearVoiceSessionLocked(); |
| 3463 | try { |
| 3464 | r.app.thread.scheduleLocalVoiceInteractionStarted((IBinder) r.appToken, |
| 3465 | null); |
| 3466 | } catch (RemoteException re) { |
| 3467 | // Ok |
| 3468 | } |
Amith Yamasani | 0af6fa7 | 2016-01-17 15:36:19 -0800 | [diff] [blame] | 3469 | mService.finishRunningVoiceLocked(); |
| 3470 | break; |
| 3471 | } |
| 3472 | } |
Dianne Hackborn | 6ea0d0a | 2014-07-02 16:23:21 -0700 | [diff] [blame] | 3473 | } |
| 3474 | } |
Amith Yamasani | 0af6fa7 | 2016-01-17 15:36:19 -0800 | [diff] [blame] | 3475 | |
Dianne Hackborn | 6ea0d0a | 2014-07-02 16:23:21 -0700 | [diff] [blame] | 3476 | if (didOne) { |
| 3477 | mService.updateOomAdjLocked(); |
| 3478 | } |
| 3479 | } |
| 3480 | |
Craig Mautner | d232895 | 2013-03-05 12:46:26 -0800 | [diff] [blame] | 3481 | final boolean finishActivityAffinityLocked(ActivityRecord r) { |
Craig Mautner | d74f7d7 | 2013-02-26 13:41:02 -0800 | [diff] [blame] | 3482 | ArrayList<ActivityRecord> activities = r.task.mActivities; |
| 3483 | for (int index = activities.indexOf(r); index >= 0; --index) { |
| 3484 | ActivityRecord cur = activities.get(index); |
Kenny Root | e6585b3 | 2013-12-13 12:00:26 -0800 | [diff] [blame] | 3485 | if (!Objects.equals(cur.taskAffinity, r.taskAffinity)) { |
Dianne Hackborn | ecc5a9c | 2012-04-26 18:56:09 -0700 | [diff] [blame] | 3486 | break; |
| 3487 | } |
Craig Mautner | de4ef02 | 2013-04-07 19:01:33 -0700 | [diff] [blame] | 3488 | finishActivityLocked(cur, Activity.RESULT_CANCELED, null, "request-affinity", true); |
Dianne Hackborn | ecc5a9c | 2012-04-26 18:56:09 -0700 | [diff] [blame] | 3489 | } |
| 3490 | return true; |
| 3491 | } |
| 3492 | |
Dianne Hackborn | 5c60743 | 2012-02-28 14:44:19 -0800 | [diff] [blame] | 3493 | final void finishActivityResultsLocked(ActivityRecord r, int resultCode, Intent resultData) { |
| 3494 | // send the result |
| 3495 | ActivityRecord resultTo = r.resultTo; |
| 3496 | if (resultTo != null) { |
Wale Ogunwale | ee006da | 2015-03-30 14:49:25 -0700 | [diff] [blame] | 3497 | if (DEBUG_RESULTS) Slog.v(TAG_RESULTS, "Adding result to " + resultTo |
Dianne Hackborn | 5c60743 | 2012-02-28 14:44:19 -0800 | [diff] [blame] | 3498 | + " who=" + r.resultWho + " req=" + r.requestCode |
| 3499 | + " res=" + resultCode + " data=" + resultData); |
Nicolas Prevot | c6cf95c | 2014-05-29 11:30:36 +0100 | [diff] [blame] | 3500 | if (resultTo.userId != r.userId) { |
Nicolas Prevot | 6b942b8 | 2014-06-02 15:20:42 +0100 | [diff] [blame] | 3501 | if (resultData != null) { |
Nicolas Prevot | 107f7b7 | 2015-07-01 16:31:48 +0100 | [diff] [blame] | 3502 | resultData.prepareToLeaveUser(r.userId); |
Nicolas Prevot | 6b942b8 | 2014-06-02 15:20:42 +0100 | [diff] [blame] | 3503 | } |
Nicolas Prevot | c6cf95c | 2014-05-29 11:30:36 +0100 | [diff] [blame] | 3504 | } |
Dianne Hackborn | 5c60743 | 2012-02-28 14:44:19 -0800 | [diff] [blame] | 3505 | if (r.info.applicationInfo.uid > 0) { |
| 3506 | mService.grantUriPermissionFromIntentLocked(r.info.applicationInfo.uid, |
| 3507 | resultTo.packageName, resultData, |
Nicolas Prevot | c6cf95c | 2014-05-29 11:30:36 +0100 | [diff] [blame] | 3508 | resultTo.getUriPermissionsLocked(), resultTo.userId); |
Dianne Hackborn | 5c60743 | 2012-02-28 14:44:19 -0800 | [diff] [blame] | 3509 | } |
| 3510 | resultTo.addResultLocked(r, r.resultWho, r.requestCode, resultCode, |
| 3511 | resultData); |
| 3512 | r.resultTo = null; |
| 3513 | } |
Wale Ogunwale | ee006da | 2015-03-30 14:49:25 -0700 | [diff] [blame] | 3514 | 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] | 3515 | |
| 3516 | // Make sure this HistoryRecord is not holding on to other resources, |
| 3517 | // because clients have remote IPC references to this object so we |
| 3518 | // can't assume that will go away and want to avoid circular IPC refs. |
| 3519 | r.results = null; |
| 3520 | r.pendingResults = null; |
| 3521 | r.newIntents = null; |
| 3522 | r.icicle = null; |
| 3523 | } |
| 3524 | |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 3525 | /** |
| 3526 | * @return Returns true if this activity has been removed from the history |
| 3527 | * list, or false if it is still in the list and will be removed later. |
| 3528 | */ |
Craig Mautner | f333327 | 2013-04-22 10:55:53 -0700 | [diff] [blame] | 3529 | final boolean finishActivityLocked(ActivityRecord r, int resultCode, Intent resultData, |
| 3530 | String reason, boolean oomAdj) { |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 3531 | if (r.finishing) { |
| 3532 | Slog.w(TAG, "Duplicate finish request for " + r); |
| 3533 | return false; |
| 3534 | } |
| 3535 | |
Wale Ogunwale | 7d70117 | 2015-03-11 15:36:30 -0700 | [diff] [blame] | 3536 | r.makeFinishingLocked(); |
Craig Mautner | aea74a5 | 2014-03-08 14:23:10 -0800 | [diff] [blame] | 3537 | final TaskRecord task = r.task; |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 3538 | EventLog.writeEvent(EventLogTags.AM_FINISH_ACTIVITY, |
Dianne Hackborn | b12e135 | 2012-09-26 11:39:20 -0700 | [diff] [blame] | 3539 | r.userId, System.identityHashCode(r), |
Craig Mautner | aea74a5 | 2014-03-08 14:23:10 -0800 | [diff] [blame] | 3540 | task.taskId, r.shortComponentName, reason); |
| 3541 | final ArrayList<ActivityRecord> activities = task.mActivities; |
Craig Mautner | d44711d | 2013-02-23 11:24:36 -0800 | [diff] [blame] | 3542 | final int index = activities.indexOf(r); |
| 3543 | if (index < (activities.size() - 1)) { |
Craig Mautner | aea74a5 | 2014-03-08 14:23:10 -0800 | [diff] [blame] | 3544 | task.setFrontOfTask(); |
Craig Mautner | d00f474 | 2014-03-12 14:17:26 -0700 | [diff] [blame] | 3545 | if ((r.intent.getFlags() & Intent.FLAG_ACTIVITY_CLEAR_WHEN_TASK_RESET) != 0) { |
Craig Mautner | d44711d | 2013-02-23 11:24:36 -0800 | [diff] [blame] | 3546 | // If the caller asked that this activity (and all above it) |
| 3547 | // be cleared when the task is reset, don't lose that information, |
| 3548 | // but propagate it up to the next activity. |
Craig Mautner | 1aa9d0d3f | 2013-12-16 15:58:31 -0800 | [diff] [blame] | 3549 | ActivityRecord next = activities.get(index+1); |
Craig Mautner | d44711d | 2013-02-23 11:24:36 -0800 | [diff] [blame] | 3550 | next.intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_WHEN_TASK_RESET); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 3551 | } |
| 3552 | } |
| 3553 | |
| 3554 | r.pauseKeyDispatchingLocked(); |
Craig Mautner | 04f0b70 | 2013-10-22 12:31:01 -0700 | [diff] [blame] | 3555 | |
Chong Zhang | 6cda19c | 2016-06-14 19:07:56 -0700 | [diff] [blame] | 3556 | adjustFocusedActivityStackLocked(r, "finishActivity"); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 3557 | |
Dianne Hackborn | 5c60743 | 2012-02-28 14:44:19 -0800 | [diff] [blame] | 3558 | finishActivityResultsLocked(r, resultCode, resultData); |
Craig Mautner | 2420ead | 2013-04-01 17:13:20 -0700 | [diff] [blame] | 3559 | |
Jorim Jaggi | af80db4 | 2016-04-07 19:19:15 -0700 | [diff] [blame] | 3560 | final boolean endTask = index <= 0; |
| 3561 | final int transit = endTask ? TRANSIT_TASK_CLOSE : TRANSIT_ACTIVITY_CLOSE; |
Craig Mautner | de4ef02 | 2013-04-07 19:01:33 -0700 | [diff] [blame] | 3562 | if (mResumedActivity == r) { |
Jorim Jaggi | af80db4 | 2016-04-07 19:19:15 -0700 | [diff] [blame] | 3563 | |
Wale Ogunwale | ee006da | 2015-03-30 14:49:25 -0700 | [diff] [blame] | 3564 | if (DEBUG_VISIBILITY || DEBUG_TRANSITION) Slog.v(TAG_TRANSITION, |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 3565 | "Prepare close transition: finishing " + r); |
Jorim Jaggi | af80db4 | 2016-04-07 19:19:15 -0700 | [diff] [blame] | 3566 | mWindowManager.prepareAppTransition(transit, false); |
Craig Mautner | 0247fc8 | 2013-02-28 14:32:06 -0800 | [diff] [blame] | 3567 | |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 3568 | // Tell window manager to prepare for this one to be removed. |
Craig Mautner | ce5f3cb | 2013-04-22 08:58:54 -0700 | [diff] [blame] | 3569 | mWindowManager.setAppVisibility(r.appToken, false); |
Craig Mautner | dbcb31f | 2013-04-02 12:32:53 -0700 | [diff] [blame] | 3570 | |
Dianne Hackborn | 621e2fe | 2012-02-16 17:07:33 -0800 | [diff] [blame] | 3571 | if (mPausingActivity == null) { |
Wale Ogunwale | ee006da | 2015-03-30 14:49:25 -0700 | [diff] [blame] | 3572 | if (DEBUG_PAUSE) Slog.v(TAG_PAUSE, "Finish needs to pause: " + r); |
| 3573 | if (DEBUG_USER_LEAVING) Slog.v(TAG_USER_LEAVING, |
| 3574 | "finish() => pause with userLeaving=false"); |
Wale Ogunwale | 950faff | 2016-08-08 09:51:04 -0700 | [diff] [blame] | 3575 | startPausingLocked(false, false, null, false); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 3576 | } |
| 3577 | |
Craig Mautner | aea74a5 | 2014-03-08 14:23:10 -0800 | [diff] [blame] | 3578 | if (endTask) { |
Craig Mautner | 15df08a | 2015-04-01 12:17:18 -0700 | [diff] [blame] | 3579 | mStackSupervisor.removeLockedTaskLocked(task); |
Craig Mautner | aea74a5 | 2014-03-08 14:23:10 -0800 | [diff] [blame] | 3580 | } |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 3581 | } else if (r.state != ActivityState.PAUSING) { |
| 3582 | // If the activity is PAUSING, we will complete the finish once |
| 3583 | // it is done pausing; else we can just directly finish it here. |
Wale Ogunwale | ee006da | 2015-03-30 14:49:25 -0700 | [diff] [blame] | 3584 | if (DEBUG_PAUSE) Slog.v(TAG_PAUSE, "Finish not pausing: " + r); |
Chong Zhang | 66ed4c6 | 2015-11-12 14:56:28 -0800 | [diff] [blame] | 3585 | if (r.visible) { |
Jorim Jaggi | af80db4 | 2016-04-07 19:19:15 -0700 | [diff] [blame] | 3586 | mWindowManager.prepareAppTransition(transit, false); |
Chong Zhang | 66ed4c6 | 2015-11-12 14:56:28 -0800 | [diff] [blame] | 3587 | mWindowManager.setAppVisibility(r.appToken, false); |
Jorim Jaggi | af80db4 | 2016-04-07 19:19:15 -0700 | [diff] [blame] | 3588 | mWindowManager.executeAppTransition(); |
Chong Zhang | b8bd069 | 2016-04-27 17:29:28 -0700 | [diff] [blame] | 3589 | if (!mStackSupervisor.mWaitingVisibleActivities.contains(r)) { |
| 3590 | mStackSupervisor.mWaitingVisibleActivities.add(r); |
| 3591 | } |
Chong Zhang | 66ed4c6 | 2015-11-12 14:56:28 -0800 | [diff] [blame] | 3592 | } |
Chong Zhang | 4c5f7ff | 2016-04-22 11:31:51 -0700 | [diff] [blame] | 3593 | return finishCurrentActivityLocked(r, (r.visible || r.nowVisible) ? |
| 3594 | FINISH_AFTER_VISIBLE : FINISH_AFTER_PAUSE, oomAdj) == null; |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 3595 | } else { |
Wale Ogunwale | ee006da | 2015-03-30 14:49:25 -0700 | [diff] [blame] | 3596 | 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] | 3597 | } |
| 3598 | |
| 3599 | return false; |
| 3600 | } |
| 3601 | |
Craig Mautner | f333327 | 2013-04-22 10:55:53 -0700 | [diff] [blame] | 3602 | static final int FINISH_IMMEDIATELY = 0; |
| 3603 | static final int FINISH_AFTER_PAUSE = 1; |
| 3604 | static final int FINISH_AFTER_VISIBLE = 2; |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 3605 | |
Craig Mautner | f333327 | 2013-04-22 10:55:53 -0700 | [diff] [blame] | 3606 | final ActivityRecord finishCurrentActivityLocked(ActivityRecord r, int mode, boolean oomAdj) { |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 3607 | // First things first: if this activity is currently visible, |
| 3608 | // and the resumed activity is not yet visible, then hold off on |
| 3609 | // finishing until the resumed one becomes visible. |
Chong Zhang | 824b6dc | 2016-04-27 14:11:12 -0700 | [diff] [blame] | 3610 | |
| 3611 | final ActivityRecord next = mStackSupervisor.topRunningActivityLocked(); |
| 3612 | |
Chong Zhang | efd9a5b | 2016-04-26 16:21:07 -0700 | [diff] [blame] | 3613 | if (mode == FINISH_AFTER_VISIBLE && (r.visible || r.nowVisible) |
Chong Zhang | 824b6dc | 2016-04-27 14:11:12 -0700 | [diff] [blame] | 3614 | && next != null && !next.nowVisible) { |
Craig Mautner | de4ef02 | 2013-04-07 19:01:33 -0700 | [diff] [blame] | 3615 | if (!mStackSupervisor.mStoppingActivities.contains(r)) { |
Chong Zhang | 46b1ac6 | 2016-02-18 17:53:57 -0800 | [diff] [blame] | 3616 | addToStopping(r, false /* immediate */); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 3617 | } |
Wale Ogunwale | 0fc365c | 2015-05-25 19:35:42 -0700 | [diff] [blame] | 3618 | if (DEBUG_STATES) Slog.v(TAG_STATES, |
| 3619 | "Moving to STOPPING: "+ r + " (finish requested)"); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 3620 | r.state = ActivityState.STOPPING; |
Dianne Hackborn | 2d1b378 | 2012-09-09 17:49:39 -0700 | [diff] [blame] | 3621 | if (oomAdj) { |
| 3622 | mService.updateOomAdjLocked(); |
| 3623 | } |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 3624 | return r; |
| 3625 | } |
| 3626 | |
| 3627 | // make sure the record is cleaned out of other places. |
Craig Mautner | de4ef02 | 2013-04-07 19:01:33 -0700 | [diff] [blame] | 3628 | mStackSupervisor.mStoppingActivities.remove(r); |
Craig Mautner | 0eea92c | 2013-05-16 13:35:39 -0700 | [diff] [blame] | 3629 | mStackSupervisor.mGoingToSleepActivities.remove(r); |
Craig Mautner | de4ef02 | 2013-04-07 19:01:33 -0700 | [diff] [blame] | 3630 | mStackSupervisor.mWaitingVisibleActivities.remove(r); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 3631 | if (mResumedActivity == r) { |
| 3632 | mResumedActivity = null; |
| 3633 | } |
| 3634 | final ActivityState prevState = r.state; |
Wale Ogunwale | 0fc365c | 2015-05-25 19:35:42 -0700 | [diff] [blame] | 3635 | if (DEBUG_STATES) Slog.v(TAG_STATES, "Moving to FINISHING: " + r); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 3636 | r.state = ActivityState.FINISHING; |
Andrii Kulian | 995fa2b | 2016-07-29 12:55:41 -0700 | [diff] [blame] | 3637 | final boolean finishingActivityInNonFocusedStack |
| 3638 | = r.task.stack != mStackSupervisor.getFocusedStack() |
| 3639 | && prevState == ActivityState.PAUSED && mode == FINISH_AFTER_VISIBLE; |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 3640 | |
| 3641 | if (mode == FINISH_IMMEDIATELY |
Wale Ogunwale | ae30f30 | 2016-05-02 10:35:45 -0700 | [diff] [blame] | 3642 | || (prevState == ActivityState.PAUSED |
Andrii Kulian | 995fa2b | 2016-07-29 12:55:41 -0700 | [diff] [blame] | 3643 | && (mode == FINISH_AFTER_PAUSE || mStackId == PINNED_STACK_ID)) |
| 3644 | || finishingActivityInNonFocusedStack |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 3645 | || prevState == ActivityState.STOPPED |
| 3646 | || prevState == ActivityState.INITIALIZING) { |
Wale Ogunwale | 7d70117 | 2015-03-11 15:36:30 -0700 | [diff] [blame] | 3647 | r.makeFinishingLocked(); |
Craig Mautner | ee2e45a | 2014-06-27 12:10:03 -0700 | [diff] [blame] | 3648 | boolean activityRemoved = destroyActivityLocked(r, true, "finish-imm"); |
Andrii Kulian | 7318d63 | 2016-07-20 18:59:28 -0700 | [diff] [blame] | 3649 | |
Andrii Kulian | 995fa2b | 2016-07-29 12:55:41 -0700 | [diff] [blame] | 3650 | if (finishingActivityInNonFocusedStack) { |
| 3651 | // Finishing activity that was in paused state and it was in not currently focused |
| 3652 | // stack, need to make something visible in its place. |
Andrii Kulian | 7318d63 | 2016-07-20 18:59:28 -0700 | [diff] [blame] | 3653 | mStackSupervisor.ensureActivitiesVisibleLocked(null, 0, !PRESERVE_WINDOWS); |
| 3654 | } |
Dianne Hackborn | 42e620c | 2012-06-24 13:20:51 -0700 | [diff] [blame] | 3655 | if (activityRemoved) { |
Wale Ogunwale | d046a01 | 2015-12-24 13:05:59 -0800 | [diff] [blame] | 3656 | mStackSupervisor.resumeFocusedStackTopActivityLocked(); |
Dianne Hackborn | 42e620c | 2012-06-24 13:20:51 -0700 | [diff] [blame] | 3657 | } |
Wale Ogunwale | 0fc365c | 2015-05-25 19:35:42 -0700 | [diff] [blame] | 3658 | if (DEBUG_CONTAINERS) Slog.d(TAG_CONTAINERS, |
Craig Mautner | d163e75 | 2014-06-13 17:18:47 -0700 | [diff] [blame] | 3659 | "destroyActivityLocked: finishCurrentActivityLocked r=" + r + |
| 3660 | " destroy returned removed=" + activityRemoved); |
Dianne Hackborn | 42e620c | 2012-06-24 13:20:51 -0700 | [diff] [blame] | 3661 | return activityRemoved ? null : r; |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 3662 | } |
Craig Mautner | 05d6272ba | 2013-02-11 09:39:27 -0800 | [diff] [blame] | 3663 | |
| 3664 | // Need to go through the full pause cycle to get this |
| 3665 | // activity into the stopped state and then finish it. |
Wale Ogunwale | e23149f | 2015-03-06 15:39:44 -0800 | [diff] [blame] | 3666 | if (DEBUG_ALL) Slog.v(TAG, "Enqueueing pending finish: " + r); |
Craig Mautner | f333327 | 2013-04-22 10:55:53 -0700 | [diff] [blame] | 3667 | mStackSupervisor.mFinishingActivities.add(r); |
Martin Wallgren | c8733b8 | 2011-08-31 12:39:31 +0200 | [diff] [blame] | 3668 | r.resumeKeyDispatchingLocked(); |
Wale Ogunwale | d046a01 | 2015-12-24 13:05:59 -0800 | [diff] [blame] | 3669 | mStackSupervisor.resumeFocusedStackTopActivityLocked(); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 3670 | return r; |
| 3671 | } |
| 3672 | |
Craig Mautner | ee36c77 | 2014-07-16 14:56:05 -0700 | [diff] [blame] | 3673 | void finishAllActivitiesLocked(boolean immediately) { |
| 3674 | boolean noActivitiesInStack = true; |
Craig Mautner | f4c909b | 2014-04-17 18:39:38 -0700 | [diff] [blame] | 3675 | for (int taskNdx = mTaskHistory.size() - 1; taskNdx >= 0; --taskNdx) { |
| 3676 | final ArrayList<ActivityRecord> activities = mTaskHistory.get(taskNdx).mActivities; |
| 3677 | for (int activityNdx = activities.size() - 1; activityNdx >= 0; --activityNdx) { |
| 3678 | final ActivityRecord r = activities.get(activityNdx); |
Craig Mautner | ee36c77 | 2014-07-16 14:56:05 -0700 | [diff] [blame] | 3679 | noActivitiesInStack = false; |
| 3680 | if (r.finishing && !immediately) { |
Craig Mautner | f4c909b | 2014-04-17 18:39:38 -0700 | [diff] [blame] | 3681 | continue; |
| 3682 | } |
Craig Mautner | ee36c77 | 2014-07-16 14:56:05 -0700 | [diff] [blame] | 3683 | Slog.d(TAG, "finishAllActivitiesLocked: finishing " + r + " immediately"); |
Craig Mautner | f4c909b | 2014-04-17 18:39:38 -0700 | [diff] [blame] | 3684 | finishCurrentActivityLocked(r, FINISH_IMMEDIATELY, false); |
| 3685 | } |
| 3686 | } |
Craig Mautner | ee36c77 | 2014-07-16 14:56:05 -0700 | [diff] [blame] | 3687 | if (noActivitiesInStack) { |
| 3688 | mActivityContainer.onTaskListEmptyLocked(); |
| 3689 | } |
Craig Mautner | f4c909b | 2014-04-17 18:39:38 -0700 | [diff] [blame] | 3690 | } |
| 3691 | |
Dianne Hackborn | 6f4d61f | 2014-08-21 17:50:42 -0700 | [diff] [blame] | 3692 | final boolean shouldUpRecreateTaskLocked(ActivityRecord srec, String destAffinity) { |
| 3693 | // Basic case: for simple app-centric recents, we need to recreate |
| 3694 | // the task if the affinity has changed. |
| 3695 | if (srec == null || srec.task.affinity == null || |
| 3696 | !srec.task.affinity.equals(destAffinity)) { |
| 3697 | return true; |
| 3698 | } |
| 3699 | // Document-centric case: an app may be split in to multiple documents; |
| 3700 | // they need to re-create their task if this current activity is the root |
| 3701 | // of a document, unless simply finishing it will return them to the the |
| 3702 | // correct app behind. |
Dianne Hackborn | f3eb843 | 2014-09-19 17:21:46 -0700 | [diff] [blame] | 3703 | if (srec.frontOfTask && srec.task != null && srec.task.getBaseIntent() != null |
| 3704 | && srec.task.getBaseIntent().isDocument()) { |
Dianne Hackborn | 6f4d61f | 2014-08-21 17:50:42 -0700 | [diff] [blame] | 3705 | // Okay, this activity is at the root of its task. What to do, what to do... |
| 3706 | if (srec.task.getTaskToReturnTo() != ActivityRecord.APPLICATION_ACTIVITY_TYPE) { |
| 3707 | // Finishing won't return to an application, so we need to recreate. |
| 3708 | return true; |
| 3709 | } |
| 3710 | // We now need to get the task below it to determine what to do. |
| 3711 | int taskIdx = mTaskHistory.indexOf(srec.task); |
| 3712 | if (taskIdx <= 0) { |
| 3713 | Slog.w(TAG, "shouldUpRecreateTask: task not in history for " + srec); |
| 3714 | return false; |
| 3715 | } |
| 3716 | if (taskIdx == 0) { |
| 3717 | // At the bottom of the stack, nothing to go back to. |
| 3718 | return true; |
| 3719 | } |
| 3720 | TaskRecord prevTask = mTaskHistory.get(taskIdx); |
| 3721 | if (!srec.task.affinity.equals(prevTask.affinity)) { |
| 3722 | // These are different apps, so need to recreate. |
| 3723 | return true; |
| 3724 | } |
| 3725 | } |
| 3726 | return false; |
| 3727 | } |
| 3728 | |
Wale Ogunwale | 7d70117 | 2015-03-11 15:36:30 -0700 | [diff] [blame] | 3729 | final boolean navigateUpToLocked(ActivityRecord srec, Intent destIntent, int resultCode, |
Craig Mautner | 05d6272ba | 2013-02-11 09:39:27 -0800 | [diff] [blame] | 3730 | Intent resultData) { |
Craig Mautner | 0247fc8 | 2013-02-28 14:32:06 -0800 | [diff] [blame] | 3731 | final TaskRecord task = srec.task; |
| 3732 | final ArrayList<ActivityRecord> activities = task.mActivities; |
| 3733 | final int start = activities.indexOf(srec); |
| 3734 | if (!mTaskHistory.contains(task) || (start < 0)) { |
Craig Mautner | 05d6272ba | 2013-02-11 09:39:27 -0800 | [diff] [blame] | 3735 | return false; |
| 3736 | } |
| 3737 | int finishTo = start - 1; |
Craig Mautner | 0247fc8 | 2013-02-28 14:32:06 -0800 | [diff] [blame] | 3738 | ActivityRecord parent = finishTo < 0 ? null : activities.get(finishTo); |
Craig Mautner | 05d6272ba | 2013-02-11 09:39:27 -0800 | [diff] [blame] | 3739 | boolean foundParentInTask = false; |
Craig Mautner | 0247fc8 | 2013-02-28 14:32:06 -0800 | [diff] [blame] | 3740 | final ComponentName dest = destIntent.getComponent(); |
| 3741 | if (start > 0 && dest != null) { |
| 3742 | for (int i = finishTo; i >= 0; i--) { |
| 3743 | ActivityRecord r = activities.get(i); |
| 3744 | if (r.info.packageName.equals(dest.getPackageName()) && |
Craig Mautner | 05d6272ba | 2013-02-11 09:39:27 -0800 | [diff] [blame] | 3745 | r.info.name.equals(dest.getClassName())) { |
| 3746 | finishTo = i; |
| 3747 | parent = r; |
| 3748 | foundParentInTask = true; |
| 3749 | break; |
| 3750 | } |
| 3751 | } |
| 3752 | } |
| 3753 | |
| 3754 | IActivityController controller = mService.mController; |
| 3755 | if (controller != null) { |
| 3756 | ActivityRecord next = topRunningActivityLocked(srec.appToken, 0); |
| 3757 | if (next != null) { |
| 3758 | // ask watcher if this is allowed |
| 3759 | boolean resumeOK = true; |
| 3760 | try { |
| 3761 | resumeOK = controller.activityResuming(next.packageName); |
| 3762 | } catch (RemoteException e) { |
| 3763 | mService.mController = null; |
Kenny Root | add5821 | 2013-05-07 09:47:34 -0700 | [diff] [blame] | 3764 | Watchdog.getInstance().setActivityController(null); |
Craig Mautner | 05d6272ba | 2013-02-11 09:39:27 -0800 | [diff] [blame] | 3765 | } |
| 3766 | |
| 3767 | if (!resumeOK) { |
| 3768 | return false; |
| 3769 | } |
| 3770 | } |
| 3771 | } |
| 3772 | final long origId = Binder.clearCallingIdentity(); |
| 3773 | for (int i = start; i > finishTo; i--) { |
Craig Mautner | 0247fc8 | 2013-02-28 14:32:06 -0800 | [diff] [blame] | 3774 | ActivityRecord r = activities.get(i); |
| 3775 | requestFinishActivityLocked(r.appToken, resultCode, resultData, "navigate-up", true); |
Craig Mautner | 05d6272ba | 2013-02-11 09:39:27 -0800 | [diff] [blame] | 3776 | // Only return the supplied result for the first activity finished |
| 3777 | resultCode = Activity.RESULT_CANCELED; |
| 3778 | resultData = null; |
| 3779 | } |
| 3780 | |
| 3781 | if (parent != null && foundParentInTask) { |
| 3782 | final int parentLaunchMode = parent.info.launchMode; |
| 3783 | final int destIntentFlags = destIntent.getFlags(); |
| 3784 | if (parentLaunchMode == ActivityInfo.LAUNCH_SINGLE_INSTANCE || |
| 3785 | parentLaunchMode == ActivityInfo.LAUNCH_SINGLE_TASK || |
| 3786 | parentLaunchMode == ActivityInfo.LAUNCH_SINGLE_TOP || |
| 3787 | (destIntentFlags & Intent.FLAG_ACTIVITY_CLEAR_TOP) != 0) { |
Dianne Hackborn | 85d558c | 2014-11-04 10:31:54 -0800 | [diff] [blame] | 3788 | parent.deliverNewIntentLocked(srec.info.applicationInfo.uid, destIntent, |
| 3789 | srec.packageName); |
Craig Mautner | 05d6272ba | 2013-02-11 09:39:27 -0800 | [diff] [blame] | 3790 | } else { |
| 3791 | try { |
| 3792 | ActivityInfo aInfo = AppGlobals.getPackageManager().getActivityInfo( |
| 3793 | destIntent.getComponent(), 0, srec.userId); |
Filip Gruszczynski | 303210b | 2016-01-08 16:28:08 -0800 | [diff] [blame] | 3794 | int res = mService.mActivityStarter.startActivityLocked(srec.app.thread, |
| 3795 | destIntent, null /*ephemeralIntent*/, null, aInfo, null /*rInfo*/, null, |
| 3796 | null, parent.appToken, null, 0, -1, parent.launchedFromUid, |
Todd Kennedy | 7440f17 | 2015-12-09 14:31:22 -0800 | [diff] [blame] | 3797 | parent.launchedFromPackage, -1, parent.launchedFromUid, 0, null, |
| 3798 | false, true, null, null, null); |
Craig Mautner | 05d6272ba | 2013-02-11 09:39:27 -0800 | [diff] [blame] | 3799 | foundParentInTask = res == ActivityManager.START_SUCCESS; |
| 3800 | } catch (RemoteException e) { |
| 3801 | foundParentInTask = false; |
| 3802 | } |
| 3803 | requestFinishActivityLocked(parent.appToken, resultCode, |
Todd Kennedy | 539db51 | 2014-12-15 09:57:55 -0800 | [diff] [blame] | 3804 | resultData, "navigate-top", true); |
Craig Mautner | 05d6272ba | 2013-02-11 09:39:27 -0800 | [diff] [blame] | 3805 | } |
| 3806 | } |
| 3807 | Binder.restoreCallingIdentity(origId); |
| 3808 | return foundParentInTask; |
| 3809 | } |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 3810 | /** |
| 3811 | * Perform the common clean-up of an activity record. This is called both |
| 3812 | * as part of destroyActivityLocked() (when destroying the client-side |
| 3813 | * representation) and cleaning things up as a result of its hosting |
| 3814 | * processing going away, in which case there is no remaining client-side |
| 3815 | * state to destroy so only the cleanup here is needed. |
Craig Mautner | acebdc8 | 2015-02-24 10:53:03 -0800 | [diff] [blame] | 3816 | * |
| 3817 | * Note: Call before #removeActivityFromHistoryLocked. |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 3818 | */ |
Dianne Hackborn | ce86ba8 | 2011-07-13 19:33:41 -0700 | [diff] [blame] | 3819 | final void cleanUpActivityLocked(ActivityRecord r, boolean cleanServices, |
| 3820 | boolean setState) { |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 3821 | if (mResumedActivity == r) { |
| 3822 | mResumedActivity = null; |
| 3823 | } |
Craig Mautner | 1872ce3 | 2014-03-28 23:05:42 +0000 | [diff] [blame] | 3824 | if (mPausingActivity == r) { |
| 3825 | mPausingActivity = null; |
| 3826 | } |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 3827 | |
Wale Ogunwale | f81c1d1 | 2016-01-12 12:20:18 -0800 | [diff] [blame] | 3828 | r.deferRelaunchUntilPaused = false; |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 3829 | r.frozenBeforeDestroy = false; |
| 3830 | |
Dianne Hackborn | ce86ba8 | 2011-07-13 19:33:41 -0700 | [diff] [blame] | 3831 | if (setState) { |
Wale Ogunwale | 0fc365c | 2015-05-25 19:35:42 -0700 | [diff] [blame] | 3832 | 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] | 3833 | r.state = ActivityState.DESTROYED; |
Wale Ogunwale | 0fc365c | 2015-05-25 19:35:42 -0700 | [diff] [blame] | 3834 | 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] | 3835 | r.app = null; |
Dianne Hackborn | ce86ba8 | 2011-07-13 19:33:41 -0700 | [diff] [blame] | 3836 | } |
| 3837 | |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 3838 | // Make sure this record is no longer in the pending finishes list. |
| 3839 | // This could happen, for example, if we are trimming activities |
| 3840 | // down to the max limit while they are still waiting to finish. |
Craig Mautner | f333327 | 2013-04-22 10:55:53 -0700 | [diff] [blame] | 3841 | mStackSupervisor.mFinishingActivities.remove(r); |
Craig Mautner | de4ef02 | 2013-04-07 19:01:33 -0700 | [diff] [blame] | 3842 | mStackSupervisor.mWaitingVisibleActivities.remove(r); |
Craig Mautner | 2420ead | 2013-04-01 17:13:20 -0700 | [diff] [blame] | 3843 | |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 3844 | // Remove any pending results. |
| 3845 | if (r.finishing && r.pendingResults != null) { |
| 3846 | for (WeakReference<PendingIntentRecord> apr : r.pendingResults) { |
| 3847 | PendingIntentRecord rec = apr.get(); |
| 3848 | if (rec != null) { |
| 3849 | mService.cancelIntentSenderLocked(rec, false); |
| 3850 | } |
| 3851 | } |
| 3852 | r.pendingResults = null; |
| 3853 | } |
| 3854 | |
| 3855 | if (cleanServices) { |
Craig Mautner | 2420ead | 2013-04-01 17:13:20 -0700 | [diff] [blame] | 3856 | cleanUpActivityServicesLocked(r); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 3857 | } |
| 3858 | |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 3859 | // Get rid of any pending idle timeouts. |
Dianne Hackborn | 42e620c | 2012-06-24 13:20:51 -0700 | [diff] [blame] | 3860 | removeTimeoutsForActivityLocked(r); |
Jose Lima | 4b6c669 | 2014-08-12 17:41:12 -0700 | [diff] [blame] | 3861 | if (getVisibleBehindActivity() == r) { |
| 3862 | mStackSupervisor.requestVisibleBehindLocked(r, false); |
Craig Mautner | ee2e45a | 2014-06-27 12:10:03 -0700 | [diff] [blame] | 3863 | } |
Wale Ogunwale | 8fd7542 | 2016-06-24 14:20:37 -0700 | [diff] [blame] | 3864 | |
| 3865 | // Clean-up activities are no longer relaunching (e.g. app process died). Notify window |
| 3866 | // manager so it can update its bookkeeping. |
| 3867 | mWindowManager.notifyAppRelaunchesCleared(r.appToken); |
Dianne Hackborn | 42e620c | 2012-06-24 13:20:51 -0700 | [diff] [blame] | 3868 | } |
| 3869 | |
| 3870 | private void removeTimeoutsForActivityLocked(ActivityRecord r) { |
Craig Mautner | f333327 | 2013-04-22 10:55:53 -0700 | [diff] [blame] | 3871 | mStackSupervisor.removeTimeoutsForActivityLocked(r); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 3872 | mHandler.removeMessages(PAUSE_TIMEOUT_MSG, r); |
Dianne Hackborn | 162bc0e | 2012-04-09 14:06:16 -0700 | [diff] [blame] | 3873 | mHandler.removeMessages(STOP_TIMEOUT_MSG, r); |
Dianne Hackborn | 0c5001d | 2011-04-12 18:16:08 -0700 | [diff] [blame] | 3874 | mHandler.removeMessages(DESTROY_TIMEOUT_MSG, r); |
Dianne Hackborn | 2a29b3a | 2012-03-15 15:48:38 -0700 | [diff] [blame] | 3875 | r.finishLaunchTickingLocked(); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 3876 | } |
| 3877 | |
Chong Zhang | bffd889 | 2016-08-08 11:16:06 -0700 | [diff] [blame] | 3878 | private void removeActivityFromHistoryLocked(ActivityRecord r, String reason) { |
Craig Mautner | 34b73df | 2014-01-12 21:11:08 -0800 | [diff] [blame] | 3879 | mStackSupervisor.removeChildActivityContainers(r); |
Dianne Hackborn | cc5a055 | 2012-10-01 16:32:39 -0700 | [diff] [blame] | 3880 | finishActivityResultsLocked(r, Activity.RESULT_CANCELED, null); |
Wale Ogunwale | 7d70117 | 2015-03-11 15:36:30 -0700 | [diff] [blame] | 3881 | r.makeFinishingLocked(); |
Wale Ogunwale | 0fc365c | 2015-05-25 19:35:42 -0700 | [diff] [blame] | 3882 | if (DEBUG_ADD_REMOVE) Slog.i(TAG_ADD_REMOVE, |
| 3883 | "Removing activity " + r + " from stack callers=" + Debug.getCallers(5)); |
| 3884 | |
Dianne Hackborn | cc5a055 | 2012-10-01 16:32:39 -0700 | [diff] [blame] | 3885 | r.takeFromHistory(); |
| 3886 | removeTimeoutsForActivityLocked(r); |
Wale Ogunwale | 0fc365c | 2015-05-25 19:35:42 -0700 | [diff] [blame] | 3887 | if (DEBUG_STATES) Slog.v(TAG_STATES, |
| 3888 | "Moving to DESTROYED: " + r + " (removed from history)"); |
Dianne Hackborn | cc5a055 | 2012-10-01 16:32:39 -0700 | [diff] [blame] | 3889 | r.state = ActivityState.DESTROYED; |
Wale Ogunwale | 0fc365c | 2015-05-25 19:35:42 -0700 | [diff] [blame] | 3890 | 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] | 3891 | r.app = null; |
Craig Mautner | ce5f3cb | 2013-04-22 08:58:54 -0700 | [diff] [blame] | 3892 | mWindowManager.removeAppToken(r.appToken); |
Dianne Hackborn | cc5a055 | 2012-10-01 16:32:39 -0700 | [diff] [blame] | 3893 | if (VALIDATE_TOKENS) { |
| 3894 | validateAppTokensLocked(); |
| 3895 | } |
Craig Mautner | 312ba86 | 2014-02-10 17:55:01 -0800 | [diff] [blame] | 3896 | final TaskRecord task = r.task; |
| 3897 | if (task != null && task.removeActivity(r)) { |
Wale Ogunwale | ee006da | 2015-03-30 14:49:25 -0700 | [diff] [blame] | 3898 | if (DEBUG_STACK) Slog.i(TAG_STACK, |
Craig Mautner | 312ba86 | 2014-02-10 17:55:01 -0800 | [diff] [blame] | 3899 | "removeActivityFromHistoryLocked: last activity removed from " + this); |
Chong Zhang | bffd889 | 2016-08-08 11:16:06 -0700 | [diff] [blame] | 3900 | if (mStackSupervisor.isFocusedStack(this) && task == topTask() && |
Craig Mautner | 84984fa | 2014-06-19 11:19:20 -0700 | [diff] [blame] | 3901 | task.isOverHomeStack()) { |
Craig Mautner | 299f960 | 2015-01-26 09:47:33 -0800 | [diff] [blame] | 3902 | mStackSupervisor.moveHomeStackTaskToTop(task.getTaskToReturnTo(), reason); |
Craig Mautner | 312ba86 | 2014-02-10 17:55:01 -0800 | [diff] [blame] | 3903 | } |
Craig Mautner | 299f960 | 2015-01-26 09:47:33 -0800 | [diff] [blame] | 3904 | removeTask(task, reason); |
Craig Mautner | 312ba86 | 2014-02-10 17:55:01 -0800 | [diff] [blame] | 3905 | } |
Dianne Hackborn | cc5a055 | 2012-10-01 16:32:39 -0700 | [diff] [blame] | 3906 | cleanUpActivityServicesLocked(r); |
| 3907 | r.removeUriPermissionsLocked(); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 3908 | } |
Craig Mautner | dbcb31f | 2013-04-02 12:32:53 -0700 | [diff] [blame] | 3909 | |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 3910 | /** |
| 3911 | * Perform clean-up of service connections in an activity record. |
| 3912 | */ |
| 3913 | final void cleanUpActivityServicesLocked(ActivityRecord r) { |
| 3914 | // Throw away any services that have been bound by this activity. |
| 3915 | if (r.connections != null) { |
| 3916 | Iterator<ConnectionRecord> it = r.connections.iterator(); |
| 3917 | while (it.hasNext()) { |
| 3918 | ConnectionRecord c = it.next(); |
Dianne Hackborn | 599db5c | 2012-08-03 19:28:48 -0700 | [diff] [blame] | 3919 | mService.mServices.removeConnectionLocked(c, null, r); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 3920 | } |
| 3921 | r.connections = null; |
| 3922 | } |
| 3923 | } |
Dianne Hackborn | 755c8bf | 2012-05-07 15:06:09 -0700 | [diff] [blame] | 3924 | |
Craig Mautner | ee2e45a | 2014-06-27 12:10:03 -0700 | [diff] [blame] | 3925 | final void scheduleDestroyActivities(ProcessRecord owner, String reason) { |
Dianne Hackborn | 755c8bf | 2012-05-07 15:06:09 -0700 | [diff] [blame] | 3926 | Message msg = mHandler.obtainMessage(DESTROY_ACTIVITIES_MSG); |
Craig Mautner | ee2e45a | 2014-06-27 12:10:03 -0700 | [diff] [blame] | 3927 | msg.obj = new ScheduleDestroyArgs(owner, reason); |
Dianne Hackborn | 755c8bf | 2012-05-07 15:06:09 -0700 | [diff] [blame] | 3928 | mHandler.sendMessage(msg); |
| 3929 | } |
| 3930 | |
Craig Mautner | ee2e45a | 2014-06-27 12:10:03 -0700 | [diff] [blame] | 3931 | final void destroyActivitiesLocked(ProcessRecord owner, String reason) { |
Dianne Hackborn | 755c8bf | 2012-05-07 15:06:09 -0700 | [diff] [blame] | 3932 | boolean lastIsOpaque = false; |
Dianne Hackborn | 42e620c | 2012-06-24 13:20:51 -0700 | [diff] [blame] | 3933 | boolean activityRemoved = false; |
Craig Mautner | d44711d | 2013-02-23 11:24:36 -0800 | [diff] [blame] | 3934 | for (int taskNdx = mTaskHistory.size() - 1; taskNdx >= 0; --taskNdx) { |
| 3935 | final ArrayList<ActivityRecord> activities = mTaskHistory.get(taskNdx).mActivities; |
| 3936 | for (int activityNdx = activities.size() - 1; activityNdx >= 0; --activityNdx) { |
| 3937 | final ActivityRecord r = activities.get(activityNdx); |
| 3938 | if (r.finishing) { |
| 3939 | continue; |
| 3940 | } |
| 3941 | if (r.fullscreen) { |
| 3942 | lastIsOpaque = true; |
| 3943 | } |
| 3944 | if (owner != null && r.app != owner) { |
| 3945 | continue; |
| 3946 | } |
| 3947 | if (!lastIsOpaque) { |
| 3948 | continue; |
| 3949 | } |
Dianne Hackborn | 89ad456 | 2014-08-24 16:45:38 -0700 | [diff] [blame] | 3950 | if (r.isDestroyable()) { |
Wale Ogunwale | ee006da | 2015-03-30 14:49:25 -0700 | [diff] [blame] | 3951 | 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] | 3952 | + " resumed=" + mResumedActivity |
Dianne Hackborn | 89ad456 | 2014-08-24 16:45:38 -0700 | [diff] [blame] | 3953 | + " pausing=" + mPausingActivity + " for reason " + reason); |
Craig Mautner | ee2e45a | 2014-06-27 12:10:03 -0700 | [diff] [blame] | 3954 | if (destroyActivityLocked(r, true, reason)) { |
Craig Mautner | d44711d | 2013-02-23 11:24:36 -0800 | [diff] [blame] | 3955 | activityRemoved = true; |
| 3956 | } |
Dianne Hackborn | 42e620c | 2012-06-24 13:20:51 -0700 | [diff] [blame] | 3957 | } |
Dianne Hackborn | ce86ba8 | 2011-07-13 19:33:41 -0700 | [diff] [blame] | 3958 | } |
| 3959 | } |
Dianne Hackborn | 42e620c | 2012-06-24 13:20:51 -0700 | [diff] [blame] | 3960 | if (activityRemoved) { |
Wale Ogunwale | d046a01 | 2015-12-24 13:05:59 -0800 | [diff] [blame] | 3961 | mStackSupervisor.resumeFocusedStackTopActivityLocked(); |
Dianne Hackborn | 42e620c | 2012-06-24 13:20:51 -0700 | [diff] [blame] | 3962 | } |
Dianne Hackborn | ce86ba8 | 2011-07-13 19:33:41 -0700 | [diff] [blame] | 3963 | } |
| 3964 | |
Dianne Hackborn | 89ad456 | 2014-08-24 16:45:38 -0700 | [diff] [blame] | 3965 | final boolean safelyDestroyActivityLocked(ActivityRecord r, String reason) { |
| 3966 | if (r.isDestroyable()) { |
Wale Ogunwale | ee006da | 2015-03-30 14:49:25 -0700 | [diff] [blame] | 3967 | if (DEBUG_SWITCH) Slog.v(TAG_SWITCH, |
| 3968 | "Destroying " + r + " in state " + r.state + " resumed=" + mResumedActivity |
Dianne Hackborn | 89ad456 | 2014-08-24 16:45:38 -0700 | [diff] [blame] | 3969 | + " pausing=" + mPausingActivity + " for reason " + reason); |
| 3970 | return destroyActivityLocked(r, true, reason); |
| 3971 | } |
| 3972 | return false; |
| 3973 | } |
| 3974 | |
| 3975 | final int releaseSomeActivitiesLocked(ProcessRecord app, ArraySet<TaskRecord> tasks, |
| 3976 | String reason) { |
| 3977 | // Iterate over tasks starting at the back (oldest) first. |
Wale Ogunwale | 0fc365c | 2015-05-25 19:35:42 -0700 | [diff] [blame] | 3978 | 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] | 3979 | int maxTasks = tasks.size() / 4; |
| 3980 | if (maxTasks < 1) { |
| 3981 | maxTasks = 1; |
| 3982 | } |
| 3983 | int numReleased = 0; |
| 3984 | for (int taskNdx = 0; taskNdx < mTaskHistory.size() && maxTasks > 0; taskNdx++) { |
| 3985 | final TaskRecord task = mTaskHistory.get(taskNdx); |
| 3986 | if (!tasks.contains(task)) { |
| 3987 | continue; |
| 3988 | } |
Wale Ogunwale | 0fc365c | 2015-05-25 19:35:42 -0700 | [diff] [blame] | 3989 | 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] | 3990 | int curNum = 0; |
| 3991 | final ArrayList<ActivityRecord> activities = task.mActivities; |
| 3992 | for (int actNdx = 0; actNdx < activities.size(); actNdx++) { |
| 3993 | final ActivityRecord activity = activities.get(actNdx); |
| 3994 | if (activity.app == app && activity.isDestroyable()) { |
Wale Ogunwale | 0fc365c | 2015-05-25 19:35:42 -0700 | [diff] [blame] | 3995 | if (DEBUG_RELEASE) Slog.v(TAG_RELEASE, "Destroying " + activity |
Dianne Hackborn | 89ad456 | 2014-08-24 16:45:38 -0700 | [diff] [blame] | 3996 | + " in state " + activity.state + " resumed=" + mResumedActivity |
| 3997 | + " pausing=" + mPausingActivity + " for reason " + reason); |
| 3998 | destroyActivityLocked(activity, true, reason); |
| 3999 | if (activities.get(actNdx) != activity) { |
| 4000 | // Was removed from list, back up so we don't miss the next one. |
| 4001 | actNdx--; |
| 4002 | } |
| 4003 | curNum++; |
| 4004 | } |
| 4005 | } |
| 4006 | if (curNum > 0) { |
| 4007 | numReleased += curNum; |
| 4008 | maxTasks--; |
| 4009 | if (mTaskHistory.get(taskNdx) != task) { |
| 4010 | // The entire task got removed, back up so we don't miss the next one. |
| 4011 | taskNdx--; |
| 4012 | } |
| 4013 | } |
| 4014 | } |
Wale Ogunwale | 0fc365c | 2015-05-25 19:35:42 -0700 | [diff] [blame] | 4015 | if (DEBUG_RELEASE) Slog.d(TAG_RELEASE, |
| 4016 | "Done releasing: did " + numReleased + " activities"); |
Dianne Hackborn | 89ad456 | 2014-08-24 16:45:38 -0700 | [diff] [blame] | 4017 | return numReleased; |
| 4018 | } |
| 4019 | |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 4020 | /** |
| 4021 | * Destroy the current CLIENT SIDE instance of an activity. This may be |
| 4022 | * called both when actually finishing an activity, or when performing |
| 4023 | * a configuration switch where we destroy the current client-side object |
| 4024 | * but then create a new client-side object for this same HistoryRecord. |
| 4025 | */ |
Craig Mautner | ee2e45a | 2014-06-27 12:10:03 -0700 | [diff] [blame] | 4026 | final boolean destroyActivityLocked(ActivityRecord r, boolean removeFromApp, String reason) { |
Wale Ogunwale | ee006da | 2015-03-30 14:49:25 -0700 | [diff] [blame] | 4027 | if (DEBUG_SWITCH || DEBUG_CLEANUP) Slog.v(TAG_SWITCH, |
| 4028 | "Removing activity from " + reason + ": token=" + r |
Filip Gruszczynski | a59ac9c | 2015-09-10 18:28:48 -0700 | [diff] [blame] | 4029 | + ", app=" + (r.app != null ? r.app.processName : "(null)")); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 4030 | EventLog.writeEvent(EventLogTags.AM_DESTROY_ACTIVITY, |
Dianne Hackborn | b12e135 | 2012-09-26 11:39:20 -0700 | [diff] [blame] | 4031 | r.userId, System.identityHashCode(r), |
Dianne Hackborn | 28695e0 | 2011-11-02 21:59:51 -0700 | [diff] [blame] | 4032 | r.task.taskId, r.shortComponentName, reason); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 4033 | |
| 4034 | boolean removedFromHistory = false; |
Dianne Hackborn | cc5a055 | 2012-10-01 16:32:39 -0700 | [diff] [blame] | 4035 | |
Dianne Hackborn | ce86ba8 | 2011-07-13 19:33:41 -0700 | [diff] [blame] | 4036 | cleanUpActivityLocked(r, false, false); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 4037 | |
| 4038 | final boolean hadApp = r.app != null; |
Dianne Hackborn | cc5a055 | 2012-10-01 16:32:39 -0700 | [diff] [blame] | 4039 | |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 4040 | if (hadApp) { |
| 4041 | if (removeFromApp) { |
Craig Mautner | d232895 | 2013-03-05 12:46:26 -0800 | [diff] [blame] | 4042 | r.app.activities.remove(r); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 4043 | if (mService.mHeavyWeightProcess == r.app && r.app.activities.size() <= 0) { |
| 4044 | mService.mHeavyWeightProcess = null; |
| 4045 | mService.mHandler.sendEmptyMessage( |
| 4046 | ActivityManagerService.CANCEL_HEAVY_NOTIFICATION_MSG); |
| 4047 | } |
Craig Mautner | c8143c6 | 2013-09-03 12:15:57 -0700 | [diff] [blame] | 4048 | if (r.app.activities.isEmpty()) { |
Dianne Hackborn | 465fa39 | 2014-09-14 14:21:18 -0700 | [diff] [blame] | 4049 | // Update any services we are bound to that might care about whether |
| 4050 | // their client may have activities. |
| 4051 | mService.mServices.updateServiceConnectionActivitiesLocked(r.app); |
Dianne Hackborn | 3bc8f78d | 2013-09-19 13:34:35 -0700 | [diff] [blame] | 4052 | // No longer have activities, so update LRU list and oom adj. |
Dianne Hackborn | db92608 | 2013-10-31 16:32:44 -0700 | [diff] [blame] | 4053 | mService.updateLruProcessLocked(r.app, false, null); |
Dianne Hackborn | 2d1b378 | 2012-09-09 17:49:39 -0700 | [diff] [blame] | 4054 | mService.updateOomAdjLocked(); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 4055 | } |
| 4056 | } |
| 4057 | |
| 4058 | boolean skipDestroy = false; |
Craig Mautner | dbcb31f | 2013-04-02 12:32:53 -0700 | [diff] [blame] | 4059 | |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 4060 | try { |
Wale Ogunwale | ee006da | 2015-03-30 14:49:25 -0700 | [diff] [blame] | 4061 | if (DEBUG_SWITCH) Slog.i(TAG_SWITCH, "Destroying: " + r); |
Dianne Hackborn | be70785 | 2011-11-11 14:32:10 -0800 | [diff] [blame] | 4062 | r.app.thread.scheduleDestroyActivity(r.appToken, r.finishing, |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 4063 | r.configChangeFlags); |
| 4064 | } catch (Exception e) { |
| 4065 | // We can just ignore exceptions here... if the process |
| 4066 | // has crashed, our death notification will clean things |
| 4067 | // up. |
| 4068 | //Slog.w(TAG, "Exception thrown during finish", e); |
| 4069 | if (r.finishing) { |
Chong Zhang | bffd889 | 2016-08-08 11:16:06 -0700 | [diff] [blame] | 4070 | removeActivityFromHistoryLocked(r, reason + " exceptionInScheduleDestroy"); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 4071 | removedFromHistory = true; |
| 4072 | skipDestroy = true; |
| 4073 | } |
| 4074 | } |
| 4075 | |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 4076 | r.nowVisible = false; |
Craig Mautner | dbcb31f | 2013-04-02 12:32:53 -0700 | [diff] [blame] | 4077 | |
Dianne Hackborn | ce86ba8 | 2011-07-13 19:33:41 -0700 | [diff] [blame] | 4078 | // If the activity is finishing, we need to wait on removing it |
| 4079 | // from the list to give it a chance to do its cleanup. During |
| 4080 | // that time it may make calls back with its token so we need to |
| 4081 | // be able to find it on the list and so we don't want to remove |
| 4082 | // it from the list yet. Otherwise, we can just immediately put |
| 4083 | // it in the destroyed state since we are not removing it from the |
| 4084 | // list. |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 4085 | if (r.finishing && !skipDestroy) { |
Wale Ogunwale | 0fc365c | 2015-05-25 19:35:42 -0700 | [diff] [blame] | 4086 | if (DEBUG_STATES) Slog.v(TAG_STATES, "Moving to DESTROYING: " + r |
Dianne Hackborn | ce86ba8 | 2011-07-13 19:33:41 -0700 | [diff] [blame] | 4087 | + " (destroy requested)"); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 4088 | r.state = ActivityState.DESTROYING; |
Craig Mautner | f7bfefb | 2013-05-16 17:30:44 -0700 | [diff] [blame] | 4089 | Message msg = mHandler.obtainMessage(DESTROY_TIMEOUT_MSG, r); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 4090 | mHandler.sendMessageDelayed(msg, DESTROY_TIMEOUT); |
| 4091 | } else { |
Wale Ogunwale | 0fc365c | 2015-05-25 19:35:42 -0700 | [diff] [blame] | 4092 | if (DEBUG_STATES) Slog.v(TAG_STATES, |
| 4093 | "Moving to DESTROYED: " + r + " (destroy skipped)"); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 4094 | r.state = ActivityState.DESTROYED; |
Wale Ogunwale | 0fc365c | 2015-05-25 19:35:42 -0700 | [diff] [blame] | 4095 | 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] | 4096 | r.app = null; |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 4097 | } |
| 4098 | } else { |
| 4099 | // remove this record from the history. |
| 4100 | if (r.finishing) { |
Chong Zhang | bffd889 | 2016-08-08 11:16:06 -0700 | [diff] [blame] | 4101 | removeActivityFromHistoryLocked(r, reason + " hadNoApp"); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 4102 | removedFromHistory = true; |
| 4103 | } else { |
Wale Ogunwale | 0fc365c | 2015-05-25 19:35:42 -0700 | [diff] [blame] | 4104 | 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] | 4105 | r.state = ActivityState.DESTROYED; |
Wale Ogunwale | 0fc365c | 2015-05-25 19:35:42 -0700 | [diff] [blame] | 4106 | 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] | 4107 | r.app = null; |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 4108 | } |
| 4109 | } |
| 4110 | |
| 4111 | r.configChangeFlags = 0; |
Craig Mautner | dbcb31f | 2013-04-02 12:32:53 -0700 | [diff] [blame] | 4112 | |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 4113 | if (!mLRUActivities.remove(r) && hadApp) { |
| 4114 | Slog.w(TAG, "Activity " + r + " being finished, but not in LRU list"); |
| 4115 | } |
Craig Mautner | dbcb31f | 2013-04-02 12:32:53 -0700 | [diff] [blame] | 4116 | |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 4117 | return removedFromHistory; |
| 4118 | } |
| 4119 | |
Craig Mautner | 299f960 | 2015-01-26 09:47:33 -0800 | [diff] [blame] | 4120 | final void activityDestroyedLocked(IBinder token, String reason) { |
Craig Mautner | d232895 | 2013-03-05 12:46:26 -0800 | [diff] [blame] | 4121 | final long origId = Binder.clearCallingIdentity(); |
| 4122 | try { |
Wale Ogunwale | 7d70117 | 2015-03-11 15:36:30 -0700 | [diff] [blame] | 4123 | ActivityRecord r = ActivityRecord.forTokenLocked(token); |
Craig Mautner | d232895 | 2013-03-05 12:46:26 -0800 | [diff] [blame] | 4124 | if (r != null) { |
| 4125 | mHandler.removeMessages(DESTROY_TIMEOUT_MSG, r); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 4126 | } |
Wale Ogunwale | 0fc365c | 2015-05-25 19:35:42 -0700 | [diff] [blame] | 4127 | if (DEBUG_CONTAINERS) Slog.d(TAG_CONTAINERS, "activityDestroyedLocked: r=" + r); |
Craig Mautner | d232895 | 2013-03-05 12:46:26 -0800 | [diff] [blame] | 4128 | |
Wale Ogunwale | 60454db | 2015-01-23 16:05:07 -0800 | [diff] [blame] | 4129 | if (isInStackLocked(r) != null) { |
Craig Mautner | d232895 | 2013-03-05 12:46:26 -0800 | [diff] [blame] | 4130 | if (r.state == ActivityState.DESTROYING) { |
| 4131 | cleanUpActivityLocked(r, true, false); |
Chong Zhang | bffd889 | 2016-08-08 11:16:06 -0700 | [diff] [blame] | 4132 | removeActivityFromHistoryLocked(r, reason); |
Craig Mautner | d232895 | 2013-03-05 12:46:26 -0800 | [diff] [blame] | 4133 | } |
| 4134 | } |
Wale Ogunwale | d046a01 | 2015-12-24 13:05:59 -0800 | [diff] [blame] | 4135 | mStackSupervisor.resumeFocusedStackTopActivityLocked(); |
Craig Mautner | d232895 | 2013-03-05 12:46:26 -0800 | [diff] [blame] | 4136 | } finally { |
| 4137 | Binder.restoreCallingIdentity(origId); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 4138 | } |
| 4139 | } |
Craig Mautner | de4ef02 | 2013-04-07 19:01:33 -0700 | [diff] [blame] | 4140 | |
Todd Kennedy | aab56db | 2015-01-30 09:39:53 -0800 | [diff] [blame] | 4141 | void releaseBackgroundResources(ActivityRecord r) { |
Jose Lima | 4b6c669 | 2014-08-12 17:41:12 -0700 | [diff] [blame] | 4142 | if (hasVisibleBehindActivity() && |
| 4143 | !mHandler.hasMessages(RELEASE_BACKGROUND_RESOURCES_TIMEOUT_MSG)) { |
Wale Ogunwale | 8051c5c | 2016-03-04 10:27:32 -0800 | [diff] [blame] | 4144 | if (r == topRunningActivityLocked() |
| 4145 | && getStackVisibilityLocked(null) == STACK_VISIBLE) { |
Craig Mautner | 64ccb70 | 2014-10-01 09:38:40 -0700 | [diff] [blame] | 4146 | // Don't release the top activity if it has requested to run behind the next |
Filip Gruszczynski | 4e7fe71 | 2016-01-13 13:22:44 -0800 | [diff] [blame] | 4147 | // activity and the stack is currently visible. |
Craig Mautner | 64ccb70 | 2014-10-01 09:38:40 -0700 | [diff] [blame] | 4148 | return; |
| 4149 | } |
Wale Ogunwale | 0fc365c | 2015-05-25 19:35:42 -0700 | [diff] [blame] | 4150 | if (DEBUG_STATES) Slog.d(TAG_STATES, "releaseBackgroundResources activtyDisplay=" + |
Jose Lima | 4b6c669 | 2014-08-12 17:41:12 -0700 | [diff] [blame] | 4151 | mActivityContainer.mActivityDisplay + " visibleBehind=" + r + " app=" + r.app + |
Craig Mautner | ee2e45a | 2014-06-27 12:10:03 -0700 | [diff] [blame] | 4152 | " thread=" + r.app.thread); |
| 4153 | if (r != null && r.app != null && r.app.thread != null) { |
| 4154 | try { |
Jose Lima | 4b6c669 | 2014-08-12 17:41:12 -0700 | [diff] [blame] | 4155 | r.app.thread.scheduleCancelVisibleBehind(r.appToken); |
Craig Mautner | ee2e45a | 2014-06-27 12:10:03 -0700 | [diff] [blame] | 4156 | } catch (RemoteException e) { |
| 4157 | } |
Jose Lima | 4b6c669 | 2014-08-12 17:41:12 -0700 | [diff] [blame] | 4158 | mHandler.sendEmptyMessageDelayed(RELEASE_BACKGROUND_RESOURCES_TIMEOUT_MSG, 500); |
Craig Mautner | ee2e45a | 2014-06-27 12:10:03 -0700 | [diff] [blame] | 4159 | } else { |
Jose Lima | 4b6c669 | 2014-08-12 17:41:12 -0700 | [diff] [blame] | 4160 | Slog.e(TAG, "releaseBackgroundResources: activity " + r + " no longer running"); |
Wale Ogunwale | 1f4c02b | 2014-11-13 14:22:32 -0800 | [diff] [blame] | 4161 | backgroundResourcesReleased(); |
Craig Mautner | ee2e45a | 2014-06-27 12:10:03 -0700 | [diff] [blame] | 4162 | } |
| 4163 | } |
| 4164 | } |
| 4165 | |
Wale Ogunwale | 1f4c02b | 2014-11-13 14:22:32 -0800 | [diff] [blame] | 4166 | final void backgroundResourcesReleased() { |
Jose Lima | 4b6c669 | 2014-08-12 17:41:12 -0700 | [diff] [blame] | 4167 | mHandler.removeMessages(RELEASE_BACKGROUND_RESOURCES_TIMEOUT_MSG); |
| 4168 | final ActivityRecord r = getVisibleBehindActivity(); |
Craig Mautner | ee2e45a | 2014-06-27 12:10:03 -0700 | [diff] [blame] | 4169 | if (r != null) { |
| 4170 | mStackSupervisor.mStoppingActivities.add(r); |
Jose Lima | 4b6c669 | 2014-08-12 17:41:12 -0700 | [diff] [blame] | 4171 | setVisibleBehindActivity(null); |
Wale Ogunwale | 1f4c02b | 2014-11-13 14:22:32 -0800 | [diff] [blame] | 4172 | mStackSupervisor.scheduleIdleTimeoutLocked(null); |
Craig Mautner | ee2e45a | 2014-06-27 12:10:03 -0700 | [diff] [blame] | 4173 | } |
Wale Ogunwale | d046a01 | 2015-12-24 13:05:59 -0800 | [diff] [blame] | 4174 | mStackSupervisor.resumeFocusedStackTopActivityLocked(); |
Craig Mautner | ee2e45a | 2014-06-27 12:10:03 -0700 | [diff] [blame] | 4175 | } |
| 4176 | |
Jose Lima | 4b6c669 | 2014-08-12 17:41:12 -0700 | [diff] [blame] | 4177 | boolean hasVisibleBehindActivity() { |
| 4178 | return isAttached() && mActivityContainer.mActivityDisplay.hasVisibleBehindActivity(); |
Craig Mautner | ee2e45a | 2014-06-27 12:10:03 -0700 | [diff] [blame] | 4179 | } |
| 4180 | |
Jose Lima | 4b6c669 | 2014-08-12 17:41:12 -0700 | [diff] [blame] | 4181 | void setVisibleBehindActivity(ActivityRecord r) { |
Craig Mautner | ee2e45a | 2014-06-27 12:10:03 -0700 | [diff] [blame] | 4182 | if (isAttached()) { |
Jose Lima | 4b6c669 | 2014-08-12 17:41:12 -0700 | [diff] [blame] | 4183 | mActivityContainer.mActivityDisplay.setVisibleBehindActivity(r); |
Craig Mautner | ee2e45a | 2014-06-27 12:10:03 -0700 | [diff] [blame] | 4184 | } |
| 4185 | } |
| 4186 | |
Jose Lima | 4b6c669 | 2014-08-12 17:41:12 -0700 | [diff] [blame] | 4187 | ActivityRecord getVisibleBehindActivity() { |
| 4188 | return isAttached() ? mActivityContainer.mActivityDisplay.mVisibleBehindActivity : null; |
Craig Mautner | ee2e45a | 2014-06-27 12:10:03 -0700 | [diff] [blame] | 4189 | } |
| 4190 | |
Craig Mautner | 05d6272ba | 2013-02-11 09:39:27 -0800 | [diff] [blame] | 4191 | private void removeHistoryRecordsForAppLocked(ArrayList<ActivityRecord> list, |
| 4192 | ProcessRecord app, String listName) { |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 4193 | int i = list.size(); |
Wale Ogunwale | e23149f | 2015-03-06 15:39:44 -0800 | [diff] [blame] | 4194 | if (DEBUG_CLEANUP) Slog.v(TAG_CLEANUP, |
| 4195 | "Removing app " + app + " from list " + listName + " with " + i + " entries"); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 4196 | while (i > 0) { |
| 4197 | i--; |
Craig Mautner | 05d6272ba | 2013-02-11 09:39:27 -0800 | [diff] [blame] | 4198 | ActivityRecord r = list.get(i); |
Wale Ogunwale | e23149f | 2015-03-06 15:39:44 -0800 | [diff] [blame] | 4199 | if (DEBUG_CLEANUP) Slog.v(TAG_CLEANUP, "Record #" + i + " " + r); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 4200 | if (r.app == app) { |
Wale Ogunwale | e23149f | 2015-03-06 15:39:44 -0800 | [diff] [blame] | 4201 | if (DEBUG_CLEANUP) Slog.v(TAG_CLEANUP, "---> REMOVING this entry!"); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 4202 | list.remove(i); |
Dianne Hackborn | 42e620c | 2012-06-24 13:20:51 -0700 | [diff] [blame] | 4203 | removeTimeoutsForActivityLocked(r); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 4204 | } |
| 4205 | } |
| 4206 | } |
| 4207 | |
Dianne Hackborn | cc5a055 | 2012-10-01 16:32:39 -0700 | [diff] [blame] | 4208 | boolean removeHistoryRecordsForAppLocked(ProcessRecord app) { |
| 4209 | removeHistoryRecordsForAppLocked(mLRUActivities, app, "mLRUActivities"); |
Craig Mautner | de4ef02 | 2013-04-07 19:01:33 -0700 | [diff] [blame] | 4210 | removeHistoryRecordsForAppLocked(mStackSupervisor.mStoppingActivities, app, |
| 4211 | "mStoppingActivities"); |
Craig Mautner | 0eea92c | 2013-05-16 13:35:39 -0700 | [diff] [blame] | 4212 | removeHistoryRecordsForAppLocked(mStackSupervisor.mGoingToSleepActivities, app, |
| 4213 | "mGoingToSleepActivities"); |
Craig Mautner | de4ef02 | 2013-04-07 19:01:33 -0700 | [diff] [blame] | 4214 | removeHistoryRecordsForAppLocked(mStackSupervisor.mWaitingVisibleActivities, app, |
Dianne Hackborn | cc5a055 | 2012-10-01 16:32:39 -0700 | [diff] [blame] | 4215 | "mWaitingVisibleActivities"); |
Craig Mautner | f333327 | 2013-04-22 10:55:53 -0700 | [diff] [blame] | 4216 | removeHistoryRecordsForAppLocked(mStackSupervisor.mFinishingActivities, app, |
| 4217 | "mFinishingActivities"); |
Dianne Hackborn | cc5a055 | 2012-10-01 16:32:39 -0700 | [diff] [blame] | 4218 | |
| 4219 | boolean hasVisibleActivities = false; |
| 4220 | |
| 4221 | // Clean out the history list. |
Craig Mautner | 0247fc8 | 2013-02-28 14:32:06 -0800 | [diff] [blame] | 4222 | int i = numActivities(); |
Wale Ogunwale | e23149f | 2015-03-06 15:39:44 -0800 | [diff] [blame] | 4223 | if (DEBUG_CLEANUP) Slog.v(TAG_CLEANUP, |
| 4224 | "Removing app " + app + " from history with " + i + " entries"); |
Craig Mautner | 0247fc8 | 2013-02-28 14:32:06 -0800 | [diff] [blame] | 4225 | for (int taskNdx = mTaskHistory.size() - 1; taskNdx >= 0; --taskNdx) { |
| 4226 | final ArrayList<ActivityRecord> activities = mTaskHistory.get(taskNdx).mActivities; |
| 4227 | for (int activityNdx = activities.size() - 1; activityNdx >= 0; --activityNdx) { |
| 4228 | final ActivityRecord r = activities.get(activityNdx); |
| 4229 | --i; |
Wale Ogunwale | e23149f | 2015-03-06 15:39:44 -0800 | [diff] [blame] | 4230 | if (DEBUG_CLEANUP) Slog.v(TAG_CLEANUP, |
| 4231 | "Record #" + i + " " + r + ": app=" + r.app); |
Craig Mautner | 0247fc8 | 2013-02-28 14:32:06 -0800 | [diff] [blame] | 4232 | if (r.app == app) { |
riddle_hsu | 558e849 | 2015-04-02 16:43:13 +0800 | [diff] [blame] | 4233 | if (r.visible) { |
| 4234 | hasVisibleActivities = true; |
| 4235 | } |
Craig Mautner | acebdc8 | 2015-02-24 10:53:03 -0800 | [diff] [blame] | 4236 | final boolean remove; |
Craig Mautner | 0247fc8 | 2013-02-28 14:32:06 -0800 | [diff] [blame] | 4237 | if ((!r.haveState && !r.stateNotNeeded) || r.finishing) { |
| 4238 | // Don't currently have state for the activity, or |
| 4239 | // it is finishing -- always remove it. |
| 4240 | remove = true; |
Chong Zhang | 112eb8c | 2015-11-02 11:17:00 -0800 | [diff] [blame] | 4241 | } else if (!r.visible && r.launchCount > 2 && |
| 4242 | r.lastLaunchTime > (SystemClock.uptimeMillis() - 60000)) { |
Craig Mautner | 0247fc8 | 2013-02-28 14:32:06 -0800 | [diff] [blame] | 4243 | // We have launched this activity too many times since it was |
| 4244 | // able to run, so give up and remove it. |
Chong Zhang | 112eb8c | 2015-11-02 11:17:00 -0800 | [diff] [blame] | 4245 | // (Note if the activity is visible, we don't remove the record. |
| 4246 | // We leave the dead window on the screen but the process will |
| 4247 | // not be restarted unless user explicitly tap on it.) |
Craig Mautner | 0247fc8 | 2013-02-28 14:32:06 -0800 | [diff] [blame] | 4248 | remove = true; |
| 4249 | } else { |
| 4250 | // The process may be gone, but the activity lives on! |
| 4251 | remove = false; |
Dianne Hackborn | cc5a055 | 2012-10-01 16:32:39 -0700 | [diff] [blame] | 4252 | } |
Craig Mautner | 0247fc8 | 2013-02-28 14:32:06 -0800 | [diff] [blame] | 4253 | if (remove) { |
Wale Ogunwale | 0fc365c | 2015-05-25 19:35:42 -0700 | [diff] [blame] | 4254 | if (DEBUG_ADD_REMOVE || DEBUG_CLEANUP) Slog.i(TAG_ADD_REMOVE, |
| 4255 | "Removing activity " + r + " from stack at " + i |
| 4256 | + ": haveState=" + r.haveState |
| 4257 | + " stateNotNeeded=" + r.stateNotNeeded |
| 4258 | + " finishing=" + r.finishing |
| 4259 | + " state=" + r.state + " callers=" + Debug.getCallers(5)); |
Craig Mautner | 0247fc8 | 2013-02-28 14:32:06 -0800 | [diff] [blame] | 4260 | if (!r.finishing) { |
| 4261 | Slog.w(TAG, "Force removing " + r + ": app died, no saved state"); |
| 4262 | EventLog.writeEvent(EventLogTags.AM_FINISH_ACTIVITY, |
| 4263 | r.userId, System.identityHashCode(r), |
| 4264 | r.task.taskId, r.shortComponentName, |
| 4265 | "proc died without state saved"); |
Jeff Sharkey | 5782da7 | 2013-04-25 14:32:30 -0700 | [diff] [blame] | 4266 | if (r.state == ActivityState.RESUMED) { |
| 4267 | mService.updateUsageStats(r, false); |
| 4268 | } |
Craig Mautner | 0247fc8 | 2013-02-28 14:32:06 -0800 | [diff] [blame] | 4269 | } |
Craig Mautner | 0247fc8 | 2013-02-28 14:32:06 -0800 | [diff] [blame] | 4270 | } else { |
| 4271 | // We have the current state for this activity, so |
| 4272 | // it can be restarted later when needed. |
Wale Ogunwale | 0fc365c | 2015-05-25 19:35:42 -0700 | [diff] [blame] | 4273 | if (DEBUG_ALL) Slog.v(TAG, "Keeping entry, setting app to null"); |
| 4274 | if (DEBUG_APP) Slog.v(TAG_APP, |
| 4275 | "Clearing app during removeHistory for activity " + r); |
Craig Mautner | 0247fc8 | 2013-02-28 14:32:06 -0800 | [diff] [blame] | 4276 | r.app = null; |
Chong Zhang | 112eb8c | 2015-11-02 11:17:00 -0800 | [diff] [blame] | 4277 | // Set nowVisible to previous visible state. If the app was visible while |
| 4278 | // it died, we leave the dead window on screen so it's basically visible. |
| 4279 | // This is needed when user later tap on the dead window, we need to stop |
| 4280 | // other apps when user transfers focus to the restarted activity. |
| 4281 | r.nowVisible = r.visible; |
Craig Mautner | 0247fc8 | 2013-02-28 14:32:06 -0800 | [diff] [blame] | 4282 | if (!r.haveState) { |
Wale Ogunwale | 0fc365c | 2015-05-25 19:35:42 -0700 | [diff] [blame] | 4283 | if (DEBUG_SAVED_STATE) Slog.i(TAG_SAVED_STATE, |
Craig Mautner | 0247fc8 | 2013-02-28 14:32:06 -0800 | [diff] [blame] | 4284 | "App died, clearing saved state of " + r); |
| 4285 | r.icicle = null; |
| 4286 | } |
Dianne Hackborn | cc5a055 | 2012-10-01 16:32:39 -0700 | [diff] [blame] | 4287 | } |
Craig Mautner | d232895 | 2013-03-05 12:46:26 -0800 | [diff] [blame] | 4288 | cleanUpActivityLocked(r, true, true); |
Craig Mautner | acebdc8 | 2015-02-24 10:53:03 -0800 | [diff] [blame] | 4289 | if (remove) { |
Chong Zhang | bffd889 | 2016-08-08 11:16:06 -0700 | [diff] [blame] | 4290 | removeActivityFromHistoryLocked(r, "appDied"); |
Craig Mautner | acebdc8 | 2015-02-24 10:53:03 -0800 | [diff] [blame] | 4291 | } |
Craig Mautner | 0247fc8 | 2013-02-28 14:32:06 -0800 | [diff] [blame] | 4292 | } |
Dianne Hackborn | cc5a055 | 2012-10-01 16:32:39 -0700 | [diff] [blame] | 4293 | } |
| 4294 | } |
| 4295 | |
| 4296 | return hasVisibleActivities; |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 4297 | } |
Craig Mautner | 0247fc8 | 2013-02-28 14:32:06 -0800 | [diff] [blame] | 4298 | |
Chong Zhang | 280d332 | 2015-11-03 17:27:26 -0800 | [diff] [blame] | 4299 | final void updateTransitLocked(int transit, ActivityOptions options) { |
Dianne Hackborn | 7f58b95 | 2012-04-18 12:59:29 -0700 | [diff] [blame] | 4300 | if (options != null) { |
Filip Gruszczynski | 3e85ba2 | 2015-10-05 22:48:30 -0700 | [diff] [blame] | 4301 | ActivityRecord r = topRunningActivityLocked(); |
Dianne Hackborn | 7f58b95 | 2012-04-18 12:59:29 -0700 | [diff] [blame] | 4302 | if (r != null && r.state != ActivityState.RESUMED) { |
| 4303 | r.updateOptionsLocked(options); |
| 4304 | } else { |
| 4305 | ActivityOptions.abort(options); |
| 4306 | } |
| 4307 | } |
Craig Mautner | ce5f3cb | 2013-04-22 08:58:54 -0700 | [diff] [blame] | 4308 | mWindowManager.prepareAppTransition(transit, false); |
Dianne Hackborn | 7f58b95 | 2012-04-18 12:59:29 -0700 | [diff] [blame] | 4309 | } |
Dianne Hackborn | 621e17d | 2010-11-22 15:59:56 -0800 | [diff] [blame] | 4310 | |
Craig Mautner | 21d24a2 | 2014-04-23 11:45:37 -0700 | [diff] [blame] | 4311 | void updateTaskMovement(TaskRecord task, boolean toFront) { |
| 4312 | if (task.isPersistable) { |
| 4313 | task.mLastTimeMoved = System.currentTimeMillis(); |
| 4314 | // Sign is used to keep tasks sorted when persisted. Tasks sent to the bottom most |
| 4315 | // recently will be most negative, tasks sent to the bottom before that will be less |
| 4316 | // negative. Similarly for recent tasks moved to the top which will be most positive. |
| 4317 | if (!toFront) { |
| 4318 | task.mLastTimeMoved *= -1; |
| 4319 | } |
| 4320 | } |
Chong Zhang | fdcc4d4 | 2015-10-14 16:50:12 -0700 | [diff] [blame] | 4321 | mStackSupervisor.invalidateTaskLayers(); |
Craig Mautner | 21d24a2 | 2014-04-23 11:45:37 -0700 | [diff] [blame] | 4322 | } |
| 4323 | |
Craig Mautner | 84984fa | 2014-06-19 11:19:20 -0700 | [diff] [blame] | 4324 | void moveHomeStackTaskToTop(int homeStackTaskType) { |
Craig Mautner | a82aa09 | 2013-09-13 15:34:08 -0700 | [diff] [blame] | 4325 | final int top = mTaskHistory.size() - 1; |
| 4326 | for (int taskNdx = top; taskNdx >= 0; --taskNdx) { |
| 4327 | final TaskRecord task = mTaskHistory.get(taskNdx); |
Craig Mautner | 84984fa | 2014-06-19 11:19:20 -0700 | [diff] [blame] | 4328 | if (task.taskType == homeStackTaskType) { |
Wale Ogunwale | ee006da | 2015-03-30 14:49:25 -0700 | [diff] [blame] | 4329 | if (DEBUG_TASKS || DEBUG_STACK) Slog.d(TAG_STACK, |
| 4330 | "moveHomeStackTaskToTop: moving " + task); |
Craig Mautner | a82aa09 | 2013-09-13 15:34:08 -0700 | [diff] [blame] | 4331 | mTaskHistory.remove(taskNdx); |
| 4332 | mTaskHistory.add(top, task); |
Craig Mautner | 21d24a2 | 2014-04-23 11:45:37 -0700 | [diff] [blame] | 4333 | updateTaskMovement(task, true); |
Craig Mautner | a82aa09 | 2013-09-13 15:34:08 -0700 | [diff] [blame] | 4334 | return; |
| 4335 | } |
| 4336 | } |
| 4337 | } |
| 4338 | |
Chong Zhang | 280d332 | 2015-11-03 17:27:26 -0800 | [diff] [blame] | 4339 | final void moveTaskToFrontLocked(TaskRecord tr, boolean noAnimation, ActivityOptions options, |
Dianne Hackborn | b5a380d | 2015-05-20 18:18:46 -0700 | [diff] [blame] | 4340 | AppTimeTracker timeTracker, String reason) { |
Wale Ogunwale | ee006da | 2015-03-30 14:49:25 -0700 | [diff] [blame] | 4341 | if (DEBUG_SWITCH) Slog.v(TAG_SWITCH, "moveTaskToFront: " + tr); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 4342 | |
Craig Mautner | 11bf9a5 | 2013-02-19 14:08:51 -0800 | [diff] [blame] | 4343 | final int numTasks = mTaskHistory.size(); |
| 4344 | final int index = mTaskHistory.indexOf(tr); |
Craig Mautner | 86d67a4 | 2013-05-14 10:34:38 -0700 | [diff] [blame] | 4345 | if (numTasks == 0 || index < 0) { |
Craig Mautner | 11bf9a5 | 2013-02-19 14:08:51 -0800 | [diff] [blame] | 4346 | // nothing to do! |
Craig Mautner | 8f5f7e9 | 2015-01-26 18:03:13 -0800 | [diff] [blame] | 4347 | if (noAnimation) { |
Craig Mautner | 11bf9a5 | 2013-02-19 14:08:51 -0800 | [diff] [blame] | 4348 | ActivityOptions.abort(options); |
| 4349 | } else { |
Jorim Jaggi | af80db4 | 2016-04-07 19:19:15 -0700 | [diff] [blame] | 4350 | updateTransitLocked(TRANSIT_TASK_TO_FRONT, options); |
Craig Mautner | 11bf9a5 | 2013-02-19 14:08:51 -0800 | [diff] [blame] | 4351 | } |
| 4352 | return; |
| 4353 | } |
| 4354 | |
Dianne Hackborn | b5a380d | 2015-05-20 18:18:46 -0700 | [diff] [blame] | 4355 | if (timeTracker != null) { |
| 4356 | // The caller wants a time tracker associated with this task. |
| 4357 | for (int i = tr.mActivities.size() - 1; i >= 0; i--) { |
| 4358 | tr.mActivities.get(i).appTimeTracker = timeTracker; |
| 4359 | } |
| 4360 | } |
| 4361 | |
Craig Mautner | 11bf9a5 | 2013-02-19 14:08:51 -0800 | [diff] [blame] | 4362 | // Shift all activities with this task up to the top |
| 4363 | // of the stack, keeping them in the same internal order. |
Wale Ogunwale | 3fcb4a8 | 2015-04-06 14:00:13 -0700 | [diff] [blame] | 4364 | insertTaskAtTop(tr, null); |
Wale Ogunwale | d80c263 | 2015-03-13 10:26:26 -0700 | [diff] [blame] | 4365 | |
Chong Zhang | 45c25ce | 2015-08-10 22:18:26 -0700 | [diff] [blame] | 4366 | // Don't refocus if invisible to current user |
| 4367 | ActivityRecord top = tr.getTopActivity(); |
Chong Zhang | 8776197 | 2016-08-22 13:53:24 -0700 | [diff] [blame^] | 4368 | if (top == null || !top.okToShowLocked()) { |
Chong Zhang | 45c25ce | 2015-08-10 22:18:26 -0700 | [diff] [blame] | 4369 | addRecentActivityLocked(top); |
| 4370 | ActivityOptions.abort(options); |
| 4371 | return; |
| 4372 | } |
| 4373 | |
Wale Ogunwale | d80c263 | 2015-03-13 10:26:26 -0700 | [diff] [blame] | 4374 | // Set focus to the top running activity of this stack. |
Filip Gruszczynski | 3e85ba2 | 2015-10-05 22:48:30 -0700 | [diff] [blame] | 4375 | ActivityRecord r = topRunningActivityLocked(); |
Chong Zhang | 6cda19c | 2016-06-14 19:07:56 -0700 | [diff] [blame] | 4376 | mStackSupervisor.moveFocusableActivityStackToFrontLocked(r, reason); |
Craig Mautner | 11bf9a5 | 2013-02-19 14:08:51 -0800 | [diff] [blame] | 4377 | |
Wale Ogunwale | ee006da | 2015-03-30 14:49:25 -0700 | [diff] [blame] | 4378 | 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] | 4379 | if (noAnimation) { |
Jorim Jaggi | af80db4 | 2016-04-07 19:19:15 -0700 | [diff] [blame] | 4380 | mWindowManager.prepareAppTransition(TRANSIT_NONE, false); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 4381 | if (r != null) { |
| 4382 | mNoAnimActivities.add(r); |
| 4383 | } |
Dianne Hackborn | 8078d8c | 2012-03-20 11:11:26 -0700 | [diff] [blame] | 4384 | ActivityOptions.abort(options); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 4385 | } else { |
Jorim Jaggi | af80db4 | 2016-04-07 19:19:15 -0700 | [diff] [blame] | 4386 | updateTransitLocked(TRANSIT_TASK_TO_FRONT, options); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 4387 | } |
Craig Mautner | 30e2d72 | 2013-02-12 11:30:16 -0800 | [diff] [blame] | 4388 | |
Wale Ogunwale | d046a01 | 2015-12-24 13:05:59 -0800 | [diff] [blame] | 4389 | mStackSupervisor.resumeFocusedStackTopActivityLocked(); |
Craig Mautner | 5854780 | 2013-03-05 08:23:53 -0800 | [diff] [blame] | 4390 | EventLog.writeEvent(EventLogTags.AM_TASK_TO_FRONT, tr.userId, tr.taskId); |
Craig Mautner | 11bf9a5 | 2013-02-19 14:08:51 -0800 | [diff] [blame] | 4391 | |
| 4392 | if (VALIDATE_TOKENS) { |
| 4393 | validateAppTokensLocked(); |
| 4394 | } |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 4395 | } |
| 4396 | |
| 4397 | /** |
Craig Mautner | ce5f3cb | 2013-04-22 08:58:54 -0700 | [diff] [blame] | 4398 | * Worker method for rearranging history stack. Implements the function of moving all |
| 4399 | * 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] | 4400 | * bottom of the stack. |
Craig Mautner | ce5f3cb | 2013-04-22 08:58:54 -0700 | [diff] [blame] | 4401 | * |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 4402 | * If a watcher is installed, the action is preflighted and the watcher has an opportunity |
| 4403 | * to premeptively cancel the move. |
Craig Mautner | ce5f3cb | 2013-04-22 08:58:54 -0700 | [diff] [blame] | 4404 | * |
Craig Mautner | ae7ecab | 2013-09-18 11:48:14 -0700 | [diff] [blame] | 4405 | * @param taskId The taskId to collect and move to the bottom. |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 4406 | * @return Returns true if the move completed, false if not. |
| 4407 | */ |
Craig Mautner | 299f960 | 2015-01-26 09:47:33 -0800 | [diff] [blame] | 4408 | final boolean moveTaskToBackLocked(int taskId) { |
Craig Mautner | aea74a5 | 2014-03-08 14:23:10 -0800 | [diff] [blame] | 4409 | final TaskRecord tr = taskForIdLocked(taskId); |
| 4410 | if (tr == null) { |
| 4411 | Slog.i(TAG, "moveTaskToBack: bad taskId=" + taskId); |
| 4412 | return false; |
| 4413 | } |
| 4414 | |
| 4415 | Slog.i(TAG, "moveTaskToBack: " + tr); |
Craig Mautner | 15df08a | 2015-04-01 12:17:18 -0700 | [diff] [blame] | 4416 | mStackSupervisor.removeLockedTaskLocked(tr); |
Craig Mautner | b44de0d | 2013-02-21 20:00:58 -0800 | [diff] [blame] | 4417 | |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 4418 | // If we have a watcher, preflight the move before committing to it. First check |
| 4419 | // for *other* available tasks, but if none are available, then try again allowing the |
| 4420 | // current task to be selected. |
Craig Mautner | de4ef02 | 2013-04-07 19:01:33 -0700 | [diff] [blame] | 4421 | if (mStackSupervisor.isFrontStack(this) && mService.mController != null) { |
Craig Mautner | ae7ecab | 2013-09-18 11:48:14 -0700 | [diff] [blame] | 4422 | ActivityRecord next = topRunningActivityLocked(null, taskId); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 4423 | if (next == null) { |
| 4424 | next = topRunningActivityLocked(null, 0); |
| 4425 | } |
| 4426 | if (next != null) { |
| 4427 | // ask watcher if this is allowed |
| 4428 | boolean moveOK = true; |
| 4429 | try { |
| 4430 | moveOK = mService.mController.activityResuming(next.packageName); |
| 4431 | } catch (RemoteException e) { |
| 4432 | mService.mController = null; |
Kenny Root | add5821 | 2013-05-07 09:47:34 -0700 | [diff] [blame] | 4433 | Watchdog.getInstance().setActivityController(null); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 4434 | } |
| 4435 | if (!moveOK) { |
| 4436 | return false; |
| 4437 | } |
| 4438 | } |
| 4439 | } |
| 4440 | |
Wale Ogunwale | ee006da | 2015-03-30 14:49:25 -0700 | [diff] [blame] | 4441 | 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] | 4442 | |
Wale Ogunwale | 285ccef | 2015-12-11 14:56:37 -0800 | [diff] [blame] | 4443 | if (mStackId == HOME_STACK_ID && topTask().isHomeTask()) { |
Jiaquan He | e13e964 | 2016-06-15 15:16:13 -0700 | [diff] [blame] | 4444 | if (topTask().isOnTopLauncher()) { |
| 4445 | // An on-top launcher doesn't affect the visibility of activities on other stacks |
| 4446 | // behind it. So if we're moving an on-top launcher to the back, we want to move the |
| 4447 | // focus to the next focusable stack and resume an activity there. |
| 4448 | // Besides, when the docked stack is visible, we should also move the home stack to |
| 4449 | // the back to avoid the recents pops up on top of a fullscreen or freeform |
| 4450 | // activity. |
| 4451 | |
| 4452 | // Move the home stack to back. |
| 4453 | moveToBack(topTask()); |
| 4454 | |
| 4455 | // Resume an activity in the next focusable stack. |
| 4456 | adjustFocusToNextFocusableStackLocked(APPLICATION_ACTIVITY_TYPE, "moveTaskToBack"); |
| 4457 | mStackSupervisor.resumeFocusedStackTopActivityLocked(); |
| 4458 | return true; |
| 4459 | } |
| 4460 | |
Wale Ogunwale | 285ccef | 2015-12-11 14:56:37 -0800 | [diff] [blame] | 4461 | // For the case where we are moving the home task back and there is an activity visible |
| 4462 | // behind it on the fullscreen stack, we want to move the focus to the visible behind |
| 4463 | // activity to maintain order with what the user is seeing. |
| 4464 | final ActivityStack fullscreenStack = |
| 4465 | mStackSupervisor.getStack(FULLSCREEN_WORKSPACE_STACK_ID); |
| 4466 | if (fullscreenStack != null && fullscreenStack.hasVisibleBehindActivity()) { |
| 4467 | final ActivityRecord visibleBehind = fullscreenStack.getVisibleBehindActivity(); |
Chong Zhang | 6cda19c | 2016-06-14 19:07:56 -0700 | [diff] [blame] | 4468 | mStackSupervisor.moveFocusableActivityStackToFrontLocked(visibleBehind, "moveTaskToBack"); |
Wale Ogunwale | d046a01 | 2015-12-24 13:05:59 -0800 | [diff] [blame] | 4469 | mStackSupervisor.resumeFocusedStackTopActivityLocked(); |
Wale Ogunwale | 285ccef | 2015-12-11 14:56:37 -0800 | [diff] [blame] | 4470 | return true; |
| 4471 | } |
| 4472 | } |
| 4473 | |
riddle_hsu | c215a4f | 2014-12-27 12:10:45 +0800 | [diff] [blame] | 4474 | boolean prevIsHome = false; |
Wale Ogunwale | 4270924 | 2015-08-11 13:54:42 -0700 | [diff] [blame] | 4475 | |
| 4476 | // If true, we should resume the home activity next if the task we are moving to the |
| 4477 | // back is over the home stack. We force to false if the task we are moving to back |
| 4478 | // is the home task and we don't want it resumed after moving to the back. |
| 4479 | final boolean canGoHome = !tr.isHomeTask() && tr.isOverHomeStack(); |
| 4480 | if (canGoHome) { |
riddle_hsu | c215a4f | 2014-12-27 12:10:45 +0800 | [diff] [blame] | 4481 | final TaskRecord nextTask = getNextTask(tr); |
| 4482 | if (nextTask != null) { |
| 4483 | nextTask.setTaskToReturnTo(tr.getTaskToReturnTo()); |
| 4484 | } else { |
| 4485 | prevIsHome = true; |
| 4486 | } |
| 4487 | } |
Craig Mautner | 11bf9a5 | 2013-02-19 14:08:51 -0800 | [diff] [blame] | 4488 | mTaskHistory.remove(tr); |
| 4489 | mTaskHistory.add(0, tr); |
Craig Mautner | 21d24a2 | 2014-04-23 11:45:37 -0700 | [diff] [blame] | 4490 | updateTaskMovement(tr, false); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 4491 | |
Craig Mautner | c8143c6 | 2013-09-03 12:15:57 -0700 | [diff] [blame] | 4492 | // There is an assumption that moving a task to the back moves it behind the home activity. |
| 4493 | // 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] | 4494 | int numTasks = mTaskHistory.size(); |
Craig Mautner | ae7ecab | 2013-09-18 11:48:14 -0700 | [diff] [blame] | 4495 | for (int taskNdx = numTasks - 1; taskNdx >= 1; --taskNdx) { |
| 4496 | final TaskRecord task = mTaskHistory.get(taskNdx); |
Craig Mautner | 84984fa | 2014-06-19 11:19:20 -0700 | [diff] [blame] | 4497 | if (task.isOverHomeStack()) { |
Craig Mautner | c8143c6 | 2013-09-03 12:15:57 -0700 | [diff] [blame] | 4498 | break; |
| 4499 | } |
Craig Mautner | ae7ecab | 2013-09-18 11:48:14 -0700 | [diff] [blame] | 4500 | if (taskNdx == 1) { |
| 4501 | // Set the last task before tr to go to home. |
Craig Mautner | 84984fa | 2014-06-19 11:19:20 -0700 | [diff] [blame] | 4502 | task.setTaskToReturnTo(HOME_ACTIVITY_TYPE); |
Craig Mautner | ae7ecab | 2013-09-18 11:48:14 -0700 | [diff] [blame] | 4503 | } |
Craig Mautner | c8143c6 | 2013-09-03 12:15:57 -0700 | [diff] [blame] | 4504 | } |
| 4505 | |
Jorim Jaggi | af80db4 | 2016-04-07 19:19:15 -0700 | [diff] [blame] | 4506 | mWindowManager.prepareAppTransition(TRANSIT_TASK_TO_BACK, false); |
Craig Mautner | ae7ecab | 2013-09-18 11:48:14 -0700 | [diff] [blame] | 4507 | mWindowManager.moveTaskToBottom(taskId); |
Craig Mautner | b44de0d | 2013-02-21 20:00:58 -0800 | [diff] [blame] | 4508 | |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 4509 | if (VALIDATE_TOKENS) { |
Dianne Hackborn | be70785 | 2011-11-11 14:32:10 -0800 | [diff] [blame] | 4510 | validateAppTokensLocked(); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 4511 | } |
| 4512 | |
Craig Mautner | ae7ecab | 2013-09-18 11:48:14 -0700 | [diff] [blame] | 4513 | final TaskRecord task = mResumedActivity != null ? mResumedActivity.task : null; |
Wale Ogunwale | 4270924 | 2015-08-11 13:54:42 -0700 | [diff] [blame] | 4514 | if (prevIsHome || (task == tr && canGoHome) || (numTasks <= 1 && isOnHomeDisplay())) { |
Dianne Hackborn | 7622a0f | 2014-09-30 14:31:42 -0700 | [diff] [blame] | 4515 | if (!mService.mBooting && !mService.mBooted) { |
| 4516 | // Not ready yet! |
| 4517 | return false; |
| 4518 | } |
Craig Mautner | 84984fa | 2014-06-19 11:19:20 -0700 | [diff] [blame] | 4519 | final int taskToReturnTo = tr.getTaskToReturnTo(); |
| 4520 | tr.setTaskToReturnTo(APPLICATION_ACTIVITY_TYPE); |
Craig Mautner | 299f960 | 2015-01-26 09:47:33 -0800 | [diff] [blame] | 4521 | return mStackSupervisor.resumeHomeStackTask(taskToReturnTo, null, "moveTaskToBack"); |
Craig Mautner | de4ef02 | 2013-04-07 19:01:33 -0700 | [diff] [blame] | 4522 | } |
| 4523 | |
Wale Ogunwale | d046a01 | 2015-12-24 13:05:59 -0800 | [diff] [blame] | 4524 | mStackSupervisor.resumeFocusedStackTopActivityLocked(); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 4525 | return true; |
| 4526 | } |
Dianne Hackborn | 15491c6 | 2012-09-19 10:59:14 -0700 | [diff] [blame] | 4527 | |
Craig Mautner | 8849a5e | 2013-04-02 16:41:03 -0700 | [diff] [blame] | 4528 | static final void logStartActivity(int tag, ActivityRecord r, |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 4529 | TaskRecord task) { |
Santos Cordon | 73ff7d8 | 2013-03-06 17:24:11 -0800 | [diff] [blame] | 4530 | final Uri data = r.intent.getData(); |
| 4531 | final String strData = data != null ? data.toSafeString() : null; |
| 4532 | |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 4533 | EventLog.writeEvent(tag, |
Dianne Hackborn | b12e135 | 2012-09-26 11:39:20 -0700 | [diff] [blame] | 4534 | r.userId, System.identityHashCode(r), task.taskId, |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 4535 | r.shortComponentName, r.intent.getAction(), |
Santos Cordon | 73ff7d8 | 2013-03-06 17:24:11 -0800 | [diff] [blame] | 4536 | r.intent.getType(), strData, r.intent.getFlags()); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 4537 | } |
| 4538 | |
| 4539 | /** |
Wale Ogunwale | db0fa12 | 2016-05-16 15:12:03 -0700 | [diff] [blame] | 4540 | * Ensures all visible activities at or below the input activity have the right configuration. |
| 4541 | */ |
| 4542 | void ensureVisibleActivitiesConfigurationLocked(ActivityRecord start, boolean preserveWindow) { |
| 4543 | if (start == null || !start.visible) { |
| 4544 | return; |
| 4545 | } |
| 4546 | |
| 4547 | final TaskRecord startTask = start.task; |
| 4548 | boolean behindFullscreen = false; |
| 4549 | boolean updatedConfig = false; |
| 4550 | |
| 4551 | for (int taskIndex = mTaskHistory.indexOf(startTask); taskIndex >= 0; --taskIndex) { |
| 4552 | final TaskRecord task = mTaskHistory.get(taskIndex); |
| 4553 | final ArrayList<ActivityRecord> activities = task.mActivities; |
| 4554 | int activityIndex = |
| 4555 | (start.task == task) ? activities.indexOf(start) : activities.size() - 1; |
| 4556 | for (; activityIndex >= 0; --activityIndex) { |
| 4557 | final ActivityRecord r = activities.get(activityIndex); |
| 4558 | updatedConfig |= ensureActivityConfigurationLocked(r, 0, preserveWindow); |
| 4559 | if (r.fullscreen) { |
| 4560 | behindFullscreen = true; |
| 4561 | break; |
| 4562 | } |
| 4563 | } |
| 4564 | if (behindFullscreen) { |
| 4565 | break; |
| 4566 | } |
| 4567 | } |
| 4568 | if (updatedConfig) { |
Wale Ogunwale | 089586f | 2016-06-20 14:16:22 -0700 | [diff] [blame] | 4569 | // Ensure the resumed state of the focus activity if we updated the configuration of |
Wale Ogunwale | db0fa12 | 2016-05-16 15:12:03 -0700 | [diff] [blame] | 4570 | // any activity. |
| 4571 | mStackSupervisor.resumeFocusedStackTopActivityLocked(); |
| 4572 | } |
| 4573 | } |
| 4574 | |
| 4575 | /** |
| 4576 | * Make sure the given activity matches the current configuration. Returns false if the activity |
| 4577 | * had to be destroyed. Returns true if the configuration is the same, or the activity will |
| 4578 | * remain running as-is for whatever reason. Ensures the HistoryRecord is updated with the |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 4579 | * correct configuration and all other bookkeeping is handled. |
| 4580 | */ |
Wale Ogunwale | db0fa12 | 2016-05-16 15:12:03 -0700 | [diff] [blame] | 4581 | boolean ensureActivityConfigurationLocked( |
| 4582 | ActivityRecord r, int globalChanges, boolean preserveWindow) { |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 4583 | if (mConfigWillChange) { |
Wale Ogunwale | 3ab9a27 | 2015-03-16 09:55:45 -0700 | [diff] [blame] | 4584 | if (DEBUG_SWITCH || DEBUG_CONFIGURATION) Slog.v(TAG_CONFIGURATION, |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 4585 | "Skipping config check (will change): " + r); |
| 4586 | return true; |
| 4587 | } |
Craig Mautner | ce5f3cb | 2013-04-22 08:58:54 -0700 | [diff] [blame] | 4588 | |
Wale Ogunwale | 089586f | 2016-06-20 14:16:22 -0700 | [diff] [blame] | 4589 | // TODO: We could probably make the condition below just check that the activity state is |
| 4590 | // stopped, but also checking the sleep state for now to reduce change impact late in |
| 4591 | // development cycle. |
| 4592 | if (mService.isSleepingOrShuttingDownLocked() && r.state == ActivityState.STOPPED) { |
| 4593 | if (DEBUG_SWITCH || DEBUG_CONFIGURATION) Slog.v(TAG_CONFIGURATION, |
| 4594 | "Skipping config check (stopped while sleeping): " + r); |
| 4595 | return true; |
| 4596 | } |
| 4597 | |
Wale Ogunwale | 3ab9a27 | 2015-03-16 09:55:45 -0700 | [diff] [blame] | 4598 | if (DEBUG_SWITCH || DEBUG_CONFIGURATION) Slog.v(TAG_CONFIGURATION, |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 4599 | "Ensuring correct configuration: " + r); |
Craig Mautner | 9db9a0b | 2013-04-29 17:05:56 -0700 | [diff] [blame] | 4600 | |
Wale Ogunwale | f7dab1e | 2016-04-16 11:38:50 -0700 | [diff] [blame] | 4601 | // Short circuit: if the two configurations are equal (the common case), then there is |
| 4602 | // nothing to do. |
Wale Ogunwale | e4a0c57 | 2015-06-30 08:40:31 -0700 | [diff] [blame] | 4603 | final Configuration newConfig = mService.mConfiguration; |
Andrii Kulian | f12fce1 | 2016-05-27 17:30:16 -0700 | [diff] [blame] | 4604 | r.task.sanitizeOverrideConfiguration(newConfig); |
Wale Ogunwale | e4a0c57 | 2015-06-30 08:40:31 -0700 | [diff] [blame] | 4605 | final Configuration taskConfig = r.task.mOverrideConfig; |
Wale Ogunwale | f7dab1e | 2016-04-16 11:38:50 -0700 | [diff] [blame] | 4606 | if (r.configuration.equals(newConfig) |
| 4607 | && r.taskConfigOverride.equals(taskConfig) |
Wale Ogunwale | 60454db | 2015-01-23 16:05:07 -0800 | [diff] [blame] | 4608 | && !r.forceNewConfig) { |
Wale Ogunwale | 3ab9a27 | 2015-03-16 09:55:45 -0700 | [diff] [blame] | 4609 | if (DEBUG_SWITCH || DEBUG_CONFIGURATION) Slog.v(TAG_CONFIGURATION, |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 4610 | "Configuration unchanged in " + r); |
| 4611 | return true; |
| 4612 | } |
Craig Mautner | ce5f3cb | 2013-04-22 08:58:54 -0700 | [diff] [blame] | 4613 | |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 4614 | // We don't worry about activities that are finishing. |
| 4615 | if (r.finishing) { |
Wale Ogunwale | 3ab9a27 | 2015-03-16 09:55:45 -0700 | [diff] [blame] | 4616 | if (DEBUG_SWITCH || DEBUG_CONFIGURATION) Slog.v(TAG_CONFIGURATION, |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 4617 | "Configuration doesn't matter in finishing " + r); |
| 4618 | r.stopFreezingScreenLocked(false); |
| 4619 | return true; |
| 4620 | } |
Craig Mautner | ce5f3cb | 2013-04-22 08:58:54 -0700 | [diff] [blame] | 4621 | |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 4622 | // Okay we now are going to make this activity have the new config. |
| 4623 | // 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] | 4624 | final Configuration oldConfig = r.configuration; |
Wale Ogunwale | e4a0c57 | 2015-06-30 08:40:31 -0700 | [diff] [blame] | 4625 | final Configuration oldTaskOverride = r.taskConfigOverride; |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 4626 | r.configuration = newConfig; |
Wale Ogunwale | e4a0c57 | 2015-06-30 08:40:31 -0700 | [diff] [blame] | 4627 | r.taskConfigOverride = taskConfig; |
Dianne Hackborn | 58f42a5 | 2011-10-10 13:46:34 -0700 | [diff] [blame] | 4628 | |
Filip Gruszczynski | 2349332 | 2015-07-29 17:02:59 -0700 | [diff] [blame] | 4629 | int taskChanges = getTaskConfigurationChanges(r, taskConfig, oldTaskOverride); |
Wale Ogunwale | e4a0c57 | 2015-06-30 08:40:31 -0700 | [diff] [blame] | 4630 | final int changes = oldConfig.diff(newConfig) | taskChanges; |
Dianne Hackborn | 58f42a5 | 2011-10-10 13:46:34 -0700 | [diff] [blame] | 4631 | if (changes == 0 && !r.forceNewConfig) { |
Wale Ogunwale | 3ab9a27 | 2015-03-16 09:55:45 -0700 | [diff] [blame] | 4632 | if (DEBUG_SWITCH || DEBUG_CONFIGURATION) Slog.v(TAG_CONFIGURATION, |
Dianne Hackborn | 58f42a5 | 2011-10-10 13:46:34 -0700 | [diff] [blame] | 4633 | "Configuration no differences in " + r); |
Filip Gruszczynski | ca66481 | 2015-12-04 12:43:36 -0800 | [diff] [blame] | 4634 | // There are no significant differences, so we won't relaunch but should still deliver |
| 4635 | // the new configuration to the client process. |
Wale Ogunwale | f7dab1e | 2016-04-16 11:38:50 -0700 | [diff] [blame] | 4636 | r.scheduleConfigurationChanged(taskConfig, true); |
Dianne Hackborn | 58f42a5 | 2011-10-10 13:46:34 -0700 | [diff] [blame] | 4637 | return true; |
| 4638 | } |
| 4639 | |
Filip Gruszczynski | bc5a6c5 | 2015-09-22 13:13:24 -0700 | [diff] [blame] | 4640 | if (DEBUG_SWITCH || DEBUG_CONFIGURATION) Slog.v(TAG_CONFIGURATION, |
| 4641 | "Configuration changes for " + r + " ; taskChanges=" |
| 4642 | + Configuration.configurationDiffToString(taskChanges) + ", allChanges=" |
| 4643 | + Configuration.configurationDiffToString(changes)); |
| 4644 | |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 4645 | // If the activity isn't currently running, just leave the new |
| 4646 | // configuration and it will pick that up next time it starts. |
| 4647 | if (r.app == null || r.app.thread == null) { |
Wale Ogunwale | 3ab9a27 | 2015-03-16 09:55:45 -0700 | [diff] [blame] | 4648 | if (DEBUG_SWITCH || DEBUG_CONFIGURATION) Slog.v(TAG_CONFIGURATION, |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 4649 | "Configuration doesn't matter not running " + r); |
| 4650 | r.stopFreezingScreenLocked(false); |
Dianne Hackborn | e2515ee | 2011-04-27 18:52:56 -0400 | [diff] [blame] | 4651 | r.forceNewConfig = false; |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 4652 | return true; |
| 4653 | } |
Craig Mautner | ce5f3cb | 2013-04-22 08:58:54 -0700 | [diff] [blame] | 4654 | |
Dianne Hackborn | 58f42a5 | 2011-10-10 13:46:34 -0700 | [diff] [blame] | 4655 | // Figure out how to handle the changes between the configurations. |
Wale Ogunwale | 3ab9a27 | 2015-03-16 09:55:45 -0700 | [diff] [blame] | 4656 | if (DEBUG_SWITCH || DEBUG_CONFIGURATION) Slog.v(TAG_CONFIGURATION, |
| 4657 | "Checking to restart " + r.info.name + ": changed=0x" |
| 4658 | + Integer.toHexString(changes) + ", handles=0x" |
Filip Gruszczynski | ca66481 | 2015-12-04 12:43:36 -0800 | [diff] [blame] | 4659 | + Integer.toHexString(r.info.getRealConfigChanged()) + ", newConfig=" + newConfig |
| 4660 | + ", taskConfig=" + taskConfig); |
Wale Ogunwale | 3ab9a27 | 2015-03-16 09:55:45 -0700 | [diff] [blame] | 4661 | |
Dianne Hackborn | e667635 | 2011-06-01 16:51:20 -0700 | [diff] [blame] | 4662 | if ((changes&(~r.info.getRealConfigChanged())) != 0 || r.forceNewConfig) { |
Dianne Hackborn | 3c4c2b7 | 2010-10-05 18:07:54 -0700 | [diff] [blame] | 4663 | // Aha, the activity isn't handling the change, so DIE DIE DIE. |
| 4664 | r.configChangeFlags |= changes; |
| 4665 | r.startFreezingScreenLocked(r.app, globalChanges); |
Dianne Hackborn | e2515ee | 2011-04-27 18:52:56 -0400 | [diff] [blame] | 4666 | r.forceNewConfig = false; |
Wale Ogunwale | f81c1d1 | 2016-01-12 12:20:18 -0800 | [diff] [blame] | 4667 | preserveWindow &= isResizeOnlyChange(changes); |
Dianne Hackborn | 3c4c2b7 | 2010-10-05 18:07:54 -0700 | [diff] [blame] | 4668 | if (r.app == null || r.app.thread == null) { |
Wale Ogunwale | 3ab9a27 | 2015-03-16 09:55:45 -0700 | [diff] [blame] | 4669 | if (DEBUG_SWITCH || DEBUG_CONFIGURATION) Slog.v(TAG_CONFIGURATION, |
Dianne Hackborn | b61a026 | 2012-05-14 17:19:18 -0700 | [diff] [blame] | 4670 | "Config is destroying non-running " + r); |
Craig Mautner | ee2e45a | 2014-06-27 12:10:03 -0700 | [diff] [blame] | 4671 | destroyActivityLocked(r, true, "config"); |
Dianne Hackborn | 3c4c2b7 | 2010-10-05 18:07:54 -0700 | [diff] [blame] | 4672 | } else if (r.state == ActivityState.PAUSING) { |
Wale Ogunwale | f81c1d1 | 2016-01-12 12:20:18 -0800 | [diff] [blame] | 4673 | // A little annoying: we are waiting for this activity to finish pausing. Let's not |
| 4674 | // do anything now, but just flag that it needs to be restarted when done pausing. |
Wale Ogunwale | 3ab9a27 | 2015-03-16 09:55:45 -0700 | [diff] [blame] | 4675 | if (DEBUG_SWITCH || DEBUG_CONFIGURATION) Slog.v(TAG_CONFIGURATION, |
Dianne Hackborn | b61a026 | 2012-05-14 17:19:18 -0700 | [diff] [blame] | 4676 | "Config is skipping already pausing " + r); |
Wale Ogunwale | f81c1d1 | 2016-01-12 12:20:18 -0800 | [diff] [blame] | 4677 | r.deferRelaunchUntilPaused = true; |
| 4678 | r.preserveWindowOnDeferredRelaunch = preserveWindow; |
Dianne Hackborn | 3c4c2b7 | 2010-10-05 18:07:54 -0700 | [diff] [blame] | 4679 | return true; |
| 4680 | } else if (r.state == ActivityState.RESUMED) { |
Wale Ogunwale | f81c1d1 | 2016-01-12 12:20:18 -0800 | [diff] [blame] | 4681 | // Try to optimize this case: the configuration is changing and we need to restart |
| 4682 | // the top, resumed activity. Instead of doing the normal handshaking, just say |
Dianne Hackborn | 3c4c2b7 | 2010-10-05 18:07:54 -0700 | [diff] [blame] | 4683 | // "restart!". |
Wale Ogunwale | 3ab9a27 | 2015-03-16 09:55:45 -0700 | [diff] [blame] | 4684 | if (DEBUG_SWITCH || DEBUG_CONFIGURATION) Slog.v(TAG_CONFIGURATION, |
Dianne Hackborn | b61a026 | 2012-05-14 17:19:18 -0700 | [diff] [blame] | 4685 | "Config is relaunching resumed " + r); |
Chong Zhang | 2b79af1 | 2016-02-10 18:47:06 -0800 | [diff] [blame] | 4686 | |
| 4687 | if (DEBUG_STATES && !r.visible) { |
| 4688 | Slog.v(TAG_STATES, "Config is relaunching resumed invisible activity " + r |
| 4689 | + " called by " + Debug.getCallers(4)); |
| 4690 | } |
| 4691 | |
Wale Ogunwale | f81c1d1 | 2016-01-12 12:20:18 -0800 | [diff] [blame] | 4692 | relaunchActivityLocked(r, r.configChangeFlags, true, preserveWindow); |
Dianne Hackborn | 3c4c2b7 | 2010-10-05 18:07:54 -0700 | [diff] [blame] | 4693 | } else { |
Wale Ogunwale | 3ab9a27 | 2015-03-16 09:55:45 -0700 | [diff] [blame] | 4694 | if (DEBUG_SWITCH || DEBUG_CONFIGURATION) Slog.v(TAG_CONFIGURATION, |
Dianne Hackborn | b61a026 | 2012-05-14 17:19:18 -0700 | [diff] [blame] | 4695 | "Config is relaunching non-resumed " + r); |
Wale Ogunwale | f81c1d1 | 2016-01-12 12:20:18 -0800 | [diff] [blame] | 4696 | relaunchActivityLocked(r, r.configChangeFlags, false, preserveWindow); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 4697 | } |
Craig Mautner | ce5f3cb | 2013-04-22 08:58:54 -0700 | [diff] [blame] | 4698 | |
Wale Ogunwale | f81c1d1 | 2016-01-12 12:20:18 -0800 | [diff] [blame] | 4699 | // All done... tell the caller we weren't able to keep this activity around. |
Dianne Hackborn | 3c4c2b7 | 2010-10-05 18:07:54 -0700 | [diff] [blame] | 4700 | return false; |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 4701 | } |
Craig Mautner | ce5f3cb | 2013-04-22 08:58:54 -0700 | [diff] [blame] | 4702 | |
Wale Ogunwale | c2607b4 | 2015-02-07 16:16:59 -0800 | [diff] [blame] | 4703 | // 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] | 4704 | // 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] | 4705 | // changes is always sent to all processes when they happen so it can just use whatever |
| 4706 | // system level configuration it last got. |
Filip Gruszczynski | ca66481 | 2015-12-04 12:43:36 -0800 | [diff] [blame] | 4707 | r.scheduleConfigurationChanged(taskConfig, true); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 4708 | r.stopFreezingScreenLocked(false); |
Craig Mautner | ce5f3cb | 2013-04-22 08:58:54 -0700 | [diff] [blame] | 4709 | |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 4710 | return true; |
| 4711 | } |
| 4712 | |
Filip Gruszczynski | 2349332 | 2015-07-29 17:02:59 -0700 | [diff] [blame] | 4713 | private int getTaskConfigurationChanges(ActivityRecord record, Configuration taskConfig, |
| 4714 | Configuration oldTaskOverride) { |
Jorim Jaggi | a95ca8d | 2016-01-15 22:54:46 -0800 | [diff] [blame] | 4715 | |
| 4716 | // If we went from full-screen to non-full-screen, make sure to use the correct |
| 4717 | // configuration task diff, so the diff stays as small as possible. |
| 4718 | if (Configuration.EMPTY.equals(oldTaskOverride) |
| 4719 | && !Configuration.EMPTY.equals(taskConfig)) { |
| 4720 | oldTaskOverride = record.task.extractOverrideConfig(record.configuration); |
| 4721 | } |
| 4722 | |
Jorim Jaggi | 1b025a6 | 2016-02-03 19:27:49 -0800 | [diff] [blame] | 4723 | // Conversely, do the same when going the other direction. |
| 4724 | if (Configuration.EMPTY.equals(taskConfig) |
| 4725 | && !Configuration.EMPTY.equals(oldTaskOverride)) { |
| 4726 | taskConfig = record.task.extractOverrideConfig(record.configuration); |
| 4727 | } |
| 4728 | |
Filip Gruszczynski | 2349332 | 2015-07-29 17:02:59 -0700 | [diff] [blame] | 4729 | // Determine what has changed. May be nothing, if this is a config |
| 4730 | // that has come back from the app after going idle. In that case |
| 4731 | // we just want to leave the official config object now in the |
| 4732 | // activity and do nothing else. |
| 4733 | int taskChanges = oldTaskOverride.diff(taskConfig); |
| 4734 | // We don't want to use size changes if they don't cross boundaries that are important to |
| 4735 | // the app. |
Filip Gruszczynski | 3c2db1d1 | 2016-01-06 17:39:14 -0800 | [diff] [blame] | 4736 | if ((taskChanges & CONFIG_SCREEN_SIZE) != 0) { |
Filip Gruszczynski | 2349332 | 2015-07-29 17:02:59 -0700 | [diff] [blame] | 4737 | final boolean crosses = record.crossesHorizontalSizeThreshold( |
| 4738 | oldTaskOverride.screenWidthDp, taskConfig.screenWidthDp) |
| 4739 | || record.crossesVerticalSizeThreshold( |
| 4740 | oldTaskOverride.screenHeightDp, taskConfig.screenHeightDp); |
| 4741 | if (!crosses) { |
Filip Gruszczynski | 3c2db1d1 | 2016-01-06 17:39:14 -0800 | [diff] [blame] | 4742 | taskChanges &= ~CONFIG_SCREEN_SIZE; |
Filip Gruszczynski | 2349332 | 2015-07-29 17:02:59 -0700 | [diff] [blame] | 4743 | } |
| 4744 | } |
Filip Gruszczynski | 3c2db1d1 | 2016-01-06 17:39:14 -0800 | [diff] [blame] | 4745 | if ((taskChanges & CONFIG_SMALLEST_SCREEN_SIZE) != 0) { |
Filip Gruszczynski | 2349332 | 2015-07-29 17:02:59 -0700 | [diff] [blame] | 4746 | final int oldSmallest = oldTaskOverride.smallestScreenWidthDp; |
| 4747 | final int newSmallest = taskConfig.smallestScreenWidthDp; |
Filip Gruszczynski | 20aa0ae | 2015-10-30 10:08:27 -0700 | [diff] [blame] | 4748 | if (!record.crossesSmallestSizeThreshold(oldSmallest, newSmallest)) { |
Filip Gruszczynski | 3c2db1d1 | 2016-01-06 17:39:14 -0800 | [diff] [blame] | 4749 | taskChanges &= ~CONFIG_SMALLEST_SCREEN_SIZE; |
Filip Gruszczynski | 2349332 | 2015-07-29 17:02:59 -0700 | [diff] [blame] | 4750 | } |
| 4751 | } |
| 4752 | return catchConfigChangesFromUnset(taskConfig, oldTaskOverride, taskChanges); |
| 4753 | } |
| 4754 | |
| 4755 | private static int catchConfigChangesFromUnset(Configuration taskConfig, |
| 4756 | Configuration oldTaskOverride, int taskChanges) { |
| 4757 | if (taskChanges == 0) { |
| 4758 | // {@link Configuration#diff} doesn't catch changes from unset values. |
| 4759 | // Check for changes we care about. |
| 4760 | if (oldTaskOverride.orientation != taskConfig.orientation) { |
Filip Gruszczynski | 3c2db1d1 | 2016-01-06 17:39:14 -0800 | [diff] [blame] | 4761 | taskChanges |= CONFIG_ORIENTATION; |
Filip Gruszczynski | 2349332 | 2015-07-29 17:02:59 -0700 | [diff] [blame] | 4762 | } |
| 4763 | // We want to explicitly track situations where the size configuration goes from |
| 4764 | // undefined to defined. We don't care about crossing the threshold in that case, |
| 4765 | // because there is no threshold. |
| 4766 | final int oldHeight = oldTaskOverride.screenHeightDp; |
| 4767 | final int newHeight = taskConfig.screenHeightDp; |
| 4768 | final int undefinedHeight = Configuration.SCREEN_HEIGHT_DP_UNDEFINED; |
| 4769 | if ((oldHeight == undefinedHeight && newHeight != undefinedHeight) |
| 4770 | || (oldHeight != undefinedHeight && newHeight == undefinedHeight)) { |
Filip Gruszczynski | 3c2db1d1 | 2016-01-06 17:39:14 -0800 | [diff] [blame] | 4771 | taskChanges |= CONFIG_SCREEN_SIZE; |
Filip Gruszczynski | 2349332 | 2015-07-29 17:02:59 -0700 | [diff] [blame] | 4772 | } |
| 4773 | final int oldWidth = oldTaskOverride.screenWidthDp; |
| 4774 | final int newWidth = taskConfig.screenWidthDp; |
| 4775 | final int undefinedWidth = Configuration.SCREEN_WIDTH_DP_UNDEFINED; |
| 4776 | if ((oldWidth == undefinedWidth && newWidth != undefinedWidth) |
| 4777 | || (oldWidth != undefinedWidth && newWidth == undefinedWidth)) { |
Filip Gruszczynski | 3c2db1d1 | 2016-01-06 17:39:14 -0800 | [diff] [blame] | 4778 | taskChanges |= CONFIG_SCREEN_SIZE; |
Filip Gruszczynski | 2349332 | 2015-07-29 17:02:59 -0700 | [diff] [blame] | 4779 | } |
| 4780 | final int oldSmallest = oldTaskOverride.smallestScreenWidthDp; |
| 4781 | final int newSmallest = taskConfig.smallestScreenWidthDp; |
| 4782 | final int undefinedSmallest = Configuration.SMALLEST_SCREEN_WIDTH_DP_UNDEFINED; |
| 4783 | if ((oldSmallest == undefinedSmallest && newSmallest != undefinedSmallest) |
| 4784 | || (oldSmallest != undefinedSmallest && newSmallest == undefinedSmallest)) { |
Filip Gruszczynski | 3c2db1d1 | 2016-01-06 17:39:14 -0800 | [diff] [blame] | 4785 | taskChanges |= CONFIG_SMALLEST_SCREEN_SIZE; |
| 4786 | } |
| 4787 | final int oldLayout = oldTaskOverride.screenLayout; |
| 4788 | final int newLayout = taskConfig.screenLayout; |
| 4789 | if ((oldLayout == SCREENLAYOUT_UNDEFINED && newLayout != SCREENLAYOUT_UNDEFINED) |
| 4790 | || (oldLayout != SCREENLAYOUT_UNDEFINED && newLayout == SCREENLAYOUT_UNDEFINED)) { |
| 4791 | taskChanges |= CONFIG_SCREEN_LAYOUT; |
Filip Gruszczynski | 2349332 | 2015-07-29 17:02:59 -0700 | [diff] [blame] | 4792 | } |
| 4793 | } |
| 4794 | return taskChanges; |
| 4795 | } |
| 4796 | |
Filip Gruszczynski | a59ac9c | 2015-09-10 18:28:48 -0700 | [diff] [blame] | 4797 | private static boolean isResizeOnlyChange(int change) { |
Filip Gruszczynski | 3c2db1d1 | 2016-01-06 17:39:14 -0800 | [diff] [blame] | 4798 | return (change & ~(CONFIG_SCREEN_SIZE | CONFIG_SMALLEST_SCREEN_SIZE | CONFIG_ORIENTATION |
| 4799 | | CONFIG_SCREEN_LAYOUT)) == 0; |
Filip Gruszczynski | a59ac9c | 2015-09-10 18:28:48 -0700 | [diff] [blame] | 4800 | } |
| 4801 | |
Wale Ogunwale | 83301a9 | 2015-09-24 15:54:08 -0700 | [diff] [blame] | 4802 | private void relaunchActivityLocked( |
| 4803 | ActivityRecord r, int changes, boolean andResume, boolean preserveWindow) { |
| 4804 | if (mService.mSuppressResizeConfigChanges && preserveWindow) { |
Wale Ogunwale | f81c1d1 | 2016-01-12 12:20:18 -0800 | [diff] [blame] | 4805 | r.configChangeFlags = 0; |
Wale Ogunwale | 83301a9 | 2015-09-24 15:54:08 -0700 | [diff] [blame] | 4806 | return; |
| 4807 | } |
| 4808 | |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 4809 | List<ResultInfo> results = null; |
Dianne Hackborn | 85d558c | 2014-11-04 10:31:54 -0800 | [diff] [blame] | 4810 | List<ReferrerIntent> newIntents = null; |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 4811 | if (andResume) { |
| 4812 | results = r.results; |
| 4813 | newIntents = r.newIntents; |
| 4814 | } |
Wale Ogunwale | ee006da | 2015-03-30 14:49:25 -0700 | [diff] [blame] | 4815 | if (DEBUG_SWITCH) Slog.v(TAG_SWITCH, |
| 4816 | "Relaunching: " + r + " with results=" + results + " newIntents=" + newIntents |
Filip Gruszczynski | a59ac9c | 2015-09-10 18:28:48 -0700 | [diff] [blame] | 4817 | + " andResume=" + andResume + " preserveWindow=" + preserveWindow); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 4818 | EventLog.writeEvent(andResume ? EventLogTags.AM_RELAUNCH_RESUME_ACTIVITY |
Dianne Hackborn | b12e135 | 2012-09-26 11:39:20 -0700 | [diff] [blame] | 4819 | : EventLogTags.AM_RELAUNCH_ACTIVITY, r.userId, System.identityHashCode(r), |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 4820 | r.task.taskId, r.shortComponentName); |
Craig Mautner | 9db9a0b | 2013-04-29 17:05:56 -0700 | [diff] [blame] | 4821 | |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 4822 | r.startFreezingScreenLocked(r.app, 0); |
Craig Mautner | 9db9a0b | 2013-04-29 17:05:56 -0700 | [diff] [blame] | 4823 | |
Craig Mautner | 34b73df | 2014-01-12 21:11:08 -0800 | [diff] [blame] | 4824 | mStackSupervisor.removeChildActivityContainers(r); |
| 4825 | |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 4826 | try { |
Wale Ogunwale | ee006da | 2015-03-30 14:49:25 -0700 | [diff] [blame] | 4827 | if (DEBUG_SWITCH || DEBUG_STATES) Slog.i(TAG_SWITCH, |
Wale Ogunwale | 5658e4b | 2016-02-12 12:22:19 -0800 | [diff] [blame] | 4828 | "Moving to " + (andResume ? "RESUMED" : "PAUSED") + " Relaunching " + r |
| 4829 | + " callers=" + Debug.getCallers(6)); |
Dianne Hackborn | e2515ee | 2011-04-27 18:52:56 -0400 | [diff] [blame] | 4830 | r.forceNewConfig = false; |
Chong Zhang | d78ddb4 | 2016-03-02 17:01:14 -0800 | [diff] [blame] | 4831 | mStackSupervisor.activityRelaunchingLocked(r); |
Wale Ogunwale | 60454db | 2015-01-23 16:05:07 -0800 | [diff] [blame] | 4832 | r.app.thread.scheduleRelaunchActivity(r.appToken, results, newIntents, changes, |
| 4833 | !andResume, new Configuration(mService.mConfiguration), |
Filip Gruszczynski | a59ac9c | 2015-09-10 18:28:48 -0700 | [diff] [blame] | 4834 | new Configuration(r.task.mOverrideConfig), preserveWindow); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 4835 | // Note: don't need to call pauseIfSleepingLocked() here, because |
| 4836 | // the caller will only pass in 'andResume' if this activity is |
| 4837 | // currently resumed, which implies we aren't sleeping. |
| 4838 | } catch (RemoteException e) { |
Wale Ogunwale | ee006da | 2015-03-30 14:49:25 -0700 | [diff] [blame] | 4839 | if (DEBUG_SWITCH || DEBUG_STATES) Slog.i(TAG_SWITCH, "Relaunch failed", e); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 4840 | } |
| 4841 | |
| 4842 | if (andResume) { |
Chong Zhang | 2b79af1 | 2016-02-10 18:47:06 -0800 | [diff] [blame] | 4843 | if (DEBUG_STATES) { |
| 4844 | Slog.d(TAG_STATES, "Resumed after relaunch " + r); |
| 4845 | } |
Chong Zhang | d2cb311 | 2016-07-20 11:13:22 -0700 | [diff] [blame] | 4846 | r.results = null; |
| 4847 | r.newIntents = null; |
Andrii Kulian | f42cbe8 | 2016-06-22 14:49:58 -0700 | [diff] [blame] | 4848 | mService.showUnsupportedZoomDialogIfNeededLocked(r); |
| 4849 | mService.showAskCompatModeDialogLocked(r); |
Dianne Hackborn | b61a026 | 2012-05-14 17:19:18 -0700 | [diff] [blame] | 4850 | } else { |
| 4851 | mHandler.removeMessages(PAUSE_TIMEOUT_MSG, r); |
| 4852 | r.state = ActivityState.PAUSED; |
Chong Zhang | fec694e | 2016-08-09 12:57:38 -0700 | [diff] [blame] | 4853 | // if the app is relaunched when it's stopped, and we're not resuming, |
| 4854 | // put it back into stopped state. |
| 4855 | if (r.stopped) { |
| 4856 | addToStopping(r, true /* immediate */); |
| 4857 | } |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 4858 | } |
Wale Ogunwale | f81c1d1 | 2016-01-12 12:20:18 -0800 | [diff] [blame] | 4859 | |
| 4860 | r.configChangeFlags = 0; |
Chong Zhang | 225d1b6 | 2016-03-31 14:09:33 -0700 | [diff] [blame] | 4861 | r.deferRelaunchUntilPaused = false; |
| 4862 | r.preserveWindowOnDeferredRelaunch = false; |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 4863 | } |
Craig Mautner | cae015f | 2013-02-08 14:31:27 -0800 | [diff] [blame] | 4864 | |
| 4865 | boolean willActivityBeVisibleLocked(IBinder token) { |
Craig Mautner | d44711d | 2013-02-23 11:24:36 -0800 | [diff] [blame] | 4866 | for (int taskNdx = mTaskHistory.size() - 1; taskNdx >= 0; --taskNdx) { |
| 4867 | final ArrayList<ActivityRecord> activities = mTaskHistory.get(taskNdx).mActivities; |
| 4868 | for (int activityNdx = activities.size() - 1; activityNdx >= 0; --activityNdx) { |
| 4869 | final ActivityRecord r = activities.get(activityNdx); |
| 4870 | if (r.appToken == token) { |
Craig Mautner | 34b73df | 2014-01-12 21:11:08 -0800 | [diff] [blame] | 4871 | return true; |
Craig Mautner | d44711d | 2013-02-23 11:24:36 -0800 | [diff] [blame] | 4872 | } |
| 4873 | if (r.fullscreen && !r.finishing) { |
| 4874 | return false; |
| 4875 | } |
Craig Mautner | cae015f | 2013-02-08 14:31:27 -0800 | [diff] [blame] | 4876 | } |
| 4877 | } |
Wale Ogunwale | 7d70117 | 2015-03-11 15:36:30 -0700 | [diff] [blame] | 4878 | final ActivityRecord r = ActivityRecord.forTokenLocked(token); |
Craig Mautner | 34b73df | 2014-01-12 21:11:08 -0800 | [diff] [blame] | 4879 | if (r == null) { |
| 4880 | return false; |
| 4881 | } |
| 4882 | if (r.finishing) Slog.e(TAG, "willActivityBeVisibleLocked: Returning false," |
| 4883 | + " would have returned true for r=" + r); |
| 4884 | return !r.finishing; |
Craig Mautner | cae015f | 2013-02-08 14:31:27 -0800 | [diff] [blame] | 4885 | } |
| 4886 | |
| 4887 | void closeSystemDialogsLocked() { |
Craig Mautner | d44711d | 2013-02-23 11:24:36 -0800 | [diff] [blame] | 4888 | for (int taskNdx = mTaskHistory.size() - 1; taskNdx >= 0; --taskNdx) { |
| 4889 | final ArrayList<ActivityRecord> activities = mTaskHistory.get(taskNdx).mActivities; |
| 4890 | for (int activityNdx = activities.size() - 1; activityNdx >= 0; --activityNdx) { |
| 4891 | final ActivityRecord r = activities.get(activityNdx); |
| 4892 | if ((r.info.flags&ActivityInfo.FLAG_FINISH_ON_CLOSE_SYSTEM_DIALOGS) != 0) { |
Craig Mautner | d232895 | 2013-03-05 12:46:26 -0800 | [diff] [blame] | 4893 | finishActivityLocked(r, Activity.RESULT_CANCELED, null, "close-sys", true); |
Craig Mautner | d44711d | 2013-02-23 11:24:36 -0800 | [diff] [blame] | 4894 | } |
Craig Mautner | cae015f | 2013-02-08 14:31:27 -0800 | [diff] [blame] | 4895 | } |
| 4896 | } |
| 4897 | } |
| 4898 | |
Wale Ogunwale | 540e123 | 2015-05-01 15:35:39 -0700 | [diff] [blame] | 4899 | boolean finishDisabledPackageActivitiesLocked(String packageName, Set<String> filterByClasses, |
| 4900 | boolean doit, boolean evenPersistent, int userId) { |
Craig Mautner | cae015f | 2013-02-08 14:31:27 -0800 | [diff] [blame] | 4901 | boolean didSomething = false; |
| 4902 | TaskRecord lastTask = null; |
Craig Mautner | 9d8a30d | 2014-07-07 17:26:20 +0000 | [diff] [blame] | 4903 | ComponentName homeActivity = null; |
Craig Mautner | 56f52db | 2013-02-25 10:03:01 -0800 | [diff] [blame] | 4904 | for (int taskNdx = mTaskHistory.size() - 1; taskNdx >= 0; --taskNdx) { |
| 4905 | final ArrayList<ActivityRecord> activities = mTaskHistory.get(taskNdx).mActivities; |
| 4906 | int numActivities = activities.size(); |
| 4907 | for (int activityNdx = 0; activityNdx < numActivities; ++activityNdx) { |
| 4908 | ActivityRecord r = activities.get(activityNdx); |
Wale Ogunwale | 540e123 | 2015-05-01 15:35:39 -0700 | [diff] [blame] | 4909 | final boolean sameComponent = |
| 4910 | (r.packageName.equals(packageName) && (filterByClasses == null |
| 4911 | || filterByClasses.contains(r.realActivity.getClassName()))) |
| 4912 | || (packageName == null && r.userId == userId); |
Craig Mautner | 56f52db | 2013-02-25 10:03:01 -0800 | [diff] [blame] | 4913 | if ((userId == UserHandle.USER_ALL || r.userId == userId) |
Wale Ogunwale | 540e123 | 2015-05-01 15:35:39 -0700 | [diff] [blame] | 4914 | && (sameComponent || r.task == lastTask) |
Craig Mautner | 56f52db | 2013-02-25 10:03:01 -0800 | [diff] [blame] | 4915 | && (r.app == null || evenPersistent || !r.app.persistent)) { |
| 4916 | if (!doit) { |
| 4917 | if (r.finishing) { |
| 4918 | // If this activity is just finishing, then it is not |
| 4919 | // interesting as far as something to stop. |
| 4920 | continue; |
| 4921 | } |
| 4922 | return true; |
Craig Mautner | cae015f | 2013-02-08 14:31:27 -0800 | [diff] [blame] | 4923 | } |
Craig Mautner | 9d8a30d | 2014-07-07 17:26:20 +0000 | [diff] [blame] | 4924 | if (r.isHomeActivity()) { |
| 4925 | if (homeActivity != null && homeActivity.equals(r.realActivity)) { |
| 4926 | Slog.i(TAG, "Skip force-stop again " + r); |
| 4927 | continue; |
| 4928 | } else { |
| 4929 | homeActivity = r.realActivity; |
| 4930 | } |
| 4931 | } |
Craig Mautner | 56f52db | 2013-02-25 10:03:01 -0800 | [diff] [blame] | 4932 | didSomething = true; |
| 4933 | Slog.i(TAG, " Force finishing activity " + r); |
Wale Ogunwale | 540e123 | 2015-05-01 15:35:39 -0700 | [diff] [blame] | 4934 | if (sameComponent) { |
Craig Mautner | 56f52db | 2013-02-25 10:03:01 -0800 | [diff] [blame] | 4935 | if (r.app != null) { |
| 4936 | r.app.removed = true; |
| 4937 | } |
| 4938 | r.app = null; |
Craig Mautner | cae015f | 2013-02-08 14:31:27 -0800 | [diff] [blame] | 4939 | } |
Craig Mautner | 56f52db | 2013-02-25 10:03:01 -0800 | [diff] [blame] | 4940 | lastTask = r.task; |
Craig Mautner | d94b1b4 | 2013-05-01 11:58:03 -0700 | [diff] [blame] | 4941 | if (finishActivityLocked(r, Activity.RESULT_CANCELED, null, "force-stop", |
| 4942 | true)) { |
| 4943 | // r has been deleted from mActivities, accommodate. |
| 4944 | --numActivities; |
| 4945 | --activityNdx; |
| 4946 | } |
Craig Mautner | cae015f | 2013-02-08 14:31:27 -0800 | [diff] [blame] | 4947 | } |
| 4948 | } |
| 4949 | } |
| 4950 | return didSomething; |
| 4951 | } |
| 4952 | |
Dianne Hackborn | 0923328 | 2014-04-30 11:33:59 -0700 | [diff] [blame] | 4953 | void getTasksLocked(List<RunningTaskInfo> list, int callingUid, boolean allowed) { |
riddle_hsu | ddc7415 | 2015-04-07 11:30:09 +0800 | [diff] [blame] | 4954 | boolean focusedStack = mStackSupervisor.getFocusedStack() == this; |
| 4955 | boolean topTask = true; |
Craig Mautner | c0fd805 | 2013-09-19 11:20:17 -0700 | [diff] [blame] | 4956 | for (int taskNdx = mTaskHistory.size() - 1; taskNdx >= 0; --taskNdx) { |
Craig Mautner | aab647e | 2013-02-28 16:31:36 -0800 | [diff] [blame] | 4957 | final TaskRecord task = mTaskHistory.get(taskNdx); |
riddle_hsu | ddc7415 | 2015-04-07 11:30:09 +0800 | [diff] [blame] | 4958 | if (task.getTopActivity() == null) { |
| 4959 | continue; |
| 4960 | } |
Craig Mautner | aab647e | 2013-02-28 16:31:36 -0800 | [diff] [blame] | 4961 | ActivityRecord r = null; |
| 4962 | ActivityRecord top = null; |
Wale Ogunwale | 6035e01 | 2015-04-14 15:54:10 -0700 | [diff] [blame] | 4963 | ActivityRecord tmp; |
Craig Mautner | aab647e | 2013-02-28 16:31:36 -0800 | [diff] [blame] | 4964 | int numActivities = 0; |
| 4965 | int numRunning = 0; |
| 4966 | final ArrayList<ActivityRecord> activities = task.mActivities; |
Dianne Hackborn | 885fbe5 | 2014-08-23 15:23:58 -0700 | [diff] [blame] | 4967 | if (!allowed && !task.isHomeTask() && task.effectiveUid != callingUid) { |
Dianne Hackborn | 0923328 | 2014-04-30 11:33:59 -0700 | [diff] [blame] | 4968 | continue; |
| 4969 | } |
Craig Mautner | aab647e | 2013-02-28 16:31:36 -0800 | [diff] [blame] | 4970 | for (int activityNdx = activities.size() - 1; activityNdx >= 0; --activityNdx) { |
Wale Ogunwale | 6035e01 | 2015-04-14 15:54:10 -0700 | [diff] [blame] | 4971 | tmp = activities.get(activityNdx); |
| 4972 | if (tmp.finishing) { |
| 4973 | continue; |
| 4974 | } |
| 4975 | r = tmp; |
Craig Mautner | cae015f | 2013-02-08 14:31:27 -0800 | [diff] [blame] | 4976 | |
Craig Mautner | aab647e | 2013-02-28 16:31:36 -0800 | [diff] [blame] | 4977 | // Initialize state for next task if needed. |
| 4978 | if (top == null || (top.state == ActivityState.INITIALIZING)) { |
| 4979 | top = r; |
| 4980 | numActivities = numRunning = 0; |
Craig Mautner | cae015f | 2013-02-08 14:31:27 -0800 | [diff] [blame] | 4981 | } |
Craig Mautner | aab647e | 2013-02-28 16:31:36 -0800 | [diff] [blame] | 4982 | |
| 4983 | // Add 'r' into the current task. |
| 4984 | numActivities++; |
| 4985 | if (r.app != null && r.app.thread != null) { |
| 4986 | numRunning++; |
| 4987 | } |
| 4988 | |
Wale Ogunwale | e23149f | 2015-03-06 15:39:44 -0800 | [diff] [blame] | 4989 | if (DEBUG_ALL) Slog.v( |
Craig Mautner | aab647e | 2013-02-28 16:31:36 -0800 | [diff] [blame] | 4990 | TAG, r.intent.getComponent().flattenToShortString() |
| 4991 | + ": task=" + r.task); |
| 4992 | } |
| 4993 | |
| 4994 | RunningTaskInfo ci = new RunningTaskInfo(); |
| 4995 | ci.id = task.taskId; |
Filip Gruszczynski | d64ef3e | 2015-10-27 17:58:02 -0700 | [diff] [blame] | 4996 | ci.stackId = mStackId; |
Craig Mautner | aab647e | 2013-02-28 16:31:36 -0800 | [diff] [blame] | 4997 | ci.baseActivity = r.intent.getComponent(); |
| 4998 | ci.topActivity = top.intent.getComponent(); |
Craig Mautner | c0fd805 | 2013-09-19 11:20:17 -0700 | [diff] [blame] | 4999 | ci.lastActiveTime = task.lastActiveTime; |
riddle_hsu | ddc7415 | 2015-04-07 11:30:09 +0800 | [diff] [blame] | 5000 | if (focusedStack && topTask) { |
| 5001 | // Give the latest time to ensure foreground task can be sorted |
| 5002 | // at the first, because lastActiveTime of creating task is 0. |
| 5003 | ci.lastActiveTime = System.currentTimeMillis(); |
| 5004 | topTask = false; |
| 5005 | } |
Craig Mautner | c0fd805 | 2013-09-19 11:20:17 -0700 | [diff] [blame] | 5006 | |
Craig Mautner | c0ffce5 | 2014-07-01 12:38:52 -0700 | [diff] [blame] | 5007 | if (top.task != null) { |
| 5008 | ci.description = top.task.lastDescription; |
Craig Mautner | aab647e | 2013-02-28 16:31:36 -0800 | [diff] [blame] | 5009 | } |
| 5010 | ci.numActivities = numActivities; |
| 5011 | ci.numRunning = numRunning; |
Wale Ogunwale | 21b6058 | 2016-01-27 12:34:16 -0800 | [diff] [blame] | 5012 | ci.isDockable = task.canGoInDockedStack(); |
Jorim Jaggi | 29379ec | 2016-04-11 23:43:42 -0700 | [diff] [blame] | 5013 | ci.resizeMode = task.mResizeMode; |
Craig Mautner | aab647e | 2013-02-28 16:31:36 -0800 | [diff] [blame] | 5014 | list.add(ci); |
Craig Mautner | cae015f | 2013-02-08 14:31:27 -0800 | [diff] [blame] | 5015 | } |
Craig Mautner | cae015f | 2013-02-08 14:31:27 -0800 | [diff] [blame] | 5016 | } |
| 5017 | |
| 5018 | public void unhandledBackLocked() { |
Craig Mautner | aab647e | 2013-02-28 16:31:36 -0800 | [diff] [blame] | 5019 | final int top = mTaskHistory.size() - 1; |
Wale Ogunwale | ee006da | 2015-03-30 14:49:25 -0700 | [diff] [blame] | 5020 | 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] | 5021 | if (top >= 0) { |
| 5022 | final ArrayList<ActivityRecord> activities = mTaskHistory.get(top).mActivities; |
| 5023 | int activityTop = activities.size() - 1; |
| 5024 | if (activityTop > 0) { |
| 5025 | finishActivityLocked(activities.get(activityTop), Activity.RESULT_CANCELED, null, |
| 5026 | "unhandled-back", true); |
| 5027 | } |
Craig Mautner | cae015f | 2013-02-08 14:31:27 -0800 | [diff] [blame] | 5028 | } |
| 5029 | } |
| 5030 | |
Craig Mautner | 6b74cb5 | 2013-09-27 17:02:21 -0700 | [diff] [blame] | 5031 | /** |
| 5032 | * Reset local parameters because an app's activity died. |
| 5033 | * @param app The app of the activity that died. |
Craig Mautner | 1909125 | 2013-10-05 00:03:53 -0700 | [diff] [blame] | 5034 | * @return result from removeHistoryRecordsForAppLocked. |
Craig Mautner | 6b74cb5 | 2013-09-27 17:02:21 -0700 | [diff] [blame] | 5035 | */ |
| 5036 | boolean handleAppDiedLocked(ProcessRecord app) { |
Craig Mautner | e79d4268 | 2013-04-01 19:01:53 -0700 | [diff] [blame] | 5037 | if (mPausingActivity != null && mPausingActivity.app == app) { |
Wale Ogunwale | ee006da | 2015-03-30 14:49:25 -0700 | [diff] [blame] | 5038 | if (DEBUG_PAUSE || DEBUG_CLEANUP) Slog.v(TAG_PAUSE, |
Craig Mautner | e79d4268 | 2013-04-01 19:01:53 -0700 | [diff] [blame] | 5039 | "App died while pausing: " + mPausingActivity); |
| 5040 | mPausingActivity = null; |
| 5041 | } |
| 5042 | if (mLastPausedActivity != null && mLastPausedActivity.app == app) { |
| 5043 | mLastPausedActivity = null; |
Craig Mautner | 0f92274 | 2013-08-06 08:44:42 -0700 | [diff] [blame] | 5044 | mLastNoHistoryActivity = null; |
Craig Mautner | e79d4268 | 2013-04-01 19:01:53 -0700 | [diff] [blame] | 5045 | } |
| 5046 | |
Craig Mautner | 1909125 | 2013-10-05 00:03:53 -0700 | [diff] [blame] | 5047 | return removeHistoryRecordsForAppLocked(app); |
Craig Mautner | e79d4268 | 2013-04-01 19:01:53 -0700 | [diff] [blame] | 5048 | } |
| 5049 | |
Craig Mautner | cae015f | 2013-02-08 14:31:27 -0800 | [diff] [blame] | 5050 | void handleAppCrashLocked(ProcessRecord app) { |
Craig Mautner | d44711d | 2013-02-23 11:24:36 -0800 | [diff] [blame] | 5051 | for (int taskNdx = mTaskHistory.size() - 1; taskNdx >= 0; --taskNdx) { |
| 5052 | final ArrayList<ActivityRecord> activities = mTaskHistory.get(taskNdx).mActivities; |
| 5053 | for (int activityNdx = activities.size() - 1; activityNdx >= 0; --activityNdx) { |
| 5054 | final ActivityRecord r = activities.get(activityNdx); |
| 5055 | if (r.app == app) { |
| 5056 | Slog.w(TAG, " Force finishing activity " |
| 5057 | + r.intent.getComponent().flattenToShortString()); |
Craig Mautner | 8e5b133 | 2014-07-24 13:32:37 -0700 | [diff] [blame] | 5058 | // Force the destroy to skip right to removal. |
| 5059 | r.app = null; |
| 5060 | finishCurrentActivityLocked(r, FINISH_IMMEDIATELY, false); |
Craig Mautner | d44711d | 2013-02-23 11:24:36 -0800 | [diff] [blame] | 5061 | } |
Craig Mautner | cae015f | 2013-02-08 14:31:27 -0800 | [diff] [blame] | 5062 | } |
| 5063 | } |
| 5064 | } |
| 5065 | |
Dianne Hackborn | 390517b | 2013-05-30 15:03:32 -0700 | [diff] [blame] | 5066 | boolean dumpActivitiesLocked(FileDescriptor fd, PrintWriter pw, boolean dumpAll, |
Dianne Hackborn | 7ad34e5 | 2013-06-05 18:41:45 -0700 | [diff] [blame] | 5067 | boolean dumpClient, String dumpPackage, boolean needSep, String header) { |
Dianne Hackborn | 390517b | 2013-05-30 15:03:32 -0700 | [diff] [blame] | 5068 | boolean printed = false; |
Craig Mautner | aab647e | 2013-02-28 16:31:36 -0800 | [diff] [blame] | 5069 | for (int taskNdx = mTaskHistory.size() - 1; taskNdx >= 0; --taskNdx) { |
| 5070 | final TaskRecord task = mTaskHistory.get(taskNdx); |
Dianne Hackborn | 390517b | 2013-05-30 15:03:32 -0700 | [diff] [blame] | 5071 | printed |= ActivityStackSupervisor.dumpHistoryList(fd, pw, |
| 5072 | mTaskHistory.get(taskNdx).mActivities, " ", "Hist", true, !dumpAll, |
Dianne Hackborn | 7ad34e5 | 2013-06-05 18:41:45 -0700 | [diff] [blame] | 5073 | dumpClient, dumpPackage, needSep, header, |
Wale Ogunwale | b34a7ad | 2015-08-14 11:05:30 -0700 | [diff] [blame] | 5074 | " Task id #" + task.taskId + "\n" + |
| 5075 | " mFullscreen=" + task.mFullscreen + "\n" + |
| 5076 | " mBounds=" + task.mBounds + "\n" + |
Andrii Kulian | f66a83d | 2016-05-17 12:17:44 -0700 | [diff] [blame] | 5077 | " mMinWidth=" + task.mMinWidth + "\n" + |
| 5078 | " mMinHeight=" + task.mMinHeight + "\n" + |
Wale Ogunwale | b34a7ad | 2015-08-14 11:05:30 -0700 | [diff] [blame] | 5079 | " mLastNonFullscreenBounds=" + task.mLastNonFullscreenBounds); |
Dianne Hackborn | 7ad34e5 | 2013-06-05 18:41:45 -0700 | [diff] [blame] | 5080 | if (printed) { |
| 5081 | header = null; |
| 5082 | } |
Craig Mautner | aab647e | 2013-02-28 16:31:36 -0800 | [diff] [blame] | 5083 | } |
Dianne Hackborn | 390517b | 2013-05-30 15:03:32 -0700 | [diff] [blame] | 5084 | return printed; |
Craig Mautner | cae015f | 2013-02-08 14:31:27 -0800 | [diff] [blame] | 5085 | } |
| 5086 | |
| 5087 | ArrayList<ActivityRecord> getDumpActivitiesLocked(String name) { |
| 5088 | ArrayList<ActivityRecord> activities = new ArrayList<ActivityRecord>(); |
| 5089 | |
| 5090 | if ("all".equals(name)) { |
Craig Mautner | aab647e | 2013-02-28 16:31:36 -0800 | [diff] [blame] | 5091 | for (int taskNdx = mTaskHistory.size() - 1; taskNdx >= 0; --taskNdx) { |
| 5092 | activities.addAll(mTaskHistory.get(taskNdx).mActivities); |
Craig Mautner | cae015f | 2013-02-08 14:31:27 -0800 | [diff] [blame] | 5093 | } |
| 5094 | } else if ("top".equals(name)) { |
Craig Mautner | aab647e | 2013-02-28 16:31:36 -0800 | [diff] [blame] | 5095 | final int top = mTaskHistory.size() - 1; |
| 5096 | if (top >= 0) { |
| 5097 | final ArrayList<ActivityRecord> list = mTaskHistory.get(top).mActivities; |
| 5098 | int listTop = list.size() - 1; |
| 5099 | if (listTop >= 0) { |
| 5100 | activities.add(list.get(listTop)); |
| 5101 | } |
Craig Mautner | cae015f | 2013-02-08 14:31:27 -0800 | [diff] [blame] | 5102 | } |
| 5103 | } else { |
| 5104 | ItemMatcher matcher = new ItemMatcher(); |
| 5105 | matcher.build(name); |
| 5106 | |
Craig Mautner | aab647e | 2013-02-28 16:31:36 -0800 | [diff] [blame] | 5107 | for (int taskNdx = mTaskHistory.size() - 1; taskNdx >= 0; --taskNdx) { |
| 5108 | for (ActivityRecord r1 : mTaskHistory.get(taskNdx).mActivities) { |
| 5109 | if (matcher.match(r1, r1.intent.getComponent())) { |
| 5110 | activities.add(r1); |
| 5111 | } |
Craig Mautner | cae015f | 2013-02-08 14:31:27 -0800 | [diff] [blame] | 5112 | } |
| 5113 | } |
| 5114 | } |
| 5115 | |
| 5116 | return activities; |
| 5117 | } |
| 5118 | |
| 5119 | ActivityRecord restartPackage(String packageName) { |
Filip Gruszczynski | 3e85ba2 | 2015-10-05 22:48:30 -0700 | [diff] [blame] | 5120 | ActivityRecord starting = topRunningActivityLocked(); |
Craig Mautner | cae015f | 2013-02-08 14:31:27 -0800 | [diff] [blame] | 5121 | |
| 5122 | // All activities that came from the package must be |
| 5123 | // restarted as if there was a config change. |
Craig Mautner | aab647e | 2013-02-28 16:31:36 -0800 | [diff] [blame] | 5124 | for (int taskNdx = mTaskHistory.size() - 1; taskNdx >= 0; --taskNdx) { |
| 5125 | final ArrayList<ActivityRecord> activities = mTaskHistory.get(taskNdx).mActivities; |
| 5126 | for (int activityNdx = activities.size() - 1; activityNdx >= 0; --activityNdx) { |
| 5127 | final ActivityRecord a = activities.get(activityNdx); |
| 5128 | if (a.info.packageName.equals(packageName)) { |
| 5129 | a.forceNewConfig = true; |
| 5130 | if (starting != null && a == starting && a.visible) { |
| 5131 | a.startFreezingScreenLocked(starting.app, |
Filip Gruszczynski | 3c2db1d1 | 2016-01-06 17:39:14 -0800 | [diff] [blame] | 5132 | CONFIG_SCREEN_LAYOUT); |
Craig Mautner | aab647e | 2013-02-28 16:31:36 -0800 | [diff] [blame] | 5133 | } |
Craig Mautner | cae015f | 2013-02-08 14:31:27 -0800 | [diff] [blame] | 5134 | } |
| 5135 | } |
| 5136 | } |
| 5137 | |
| 5138 | return starting; |
| 5139 | } |
Craig Mautner | 5d9c7be | 2013-02-15 14:02:56 -0800 | [diff] [blame] | 5140 | |
Craig Mautner | 299f960 | 2015-01-26 09:47:33 -0800 | [diff] [blame] | 5141 | void removeTask(TaskRecord task, String reason) { |
Wale Ogunwale | 06579d6 | 2016-04-30 15:29:06 -0700 | [diff] [blame] | 5142 | removeTask(task, reason, REMOVE_TASK_MODE_DESTROYING); |
Wale Ogunwale | 53a29a9 | 2015-02-23 15:42:52 -0800 | [diff] [blame] | 5143 | } |
| 5144 | |
Wale Ogunwale | 000957c | 2015-04-03 08:19:12 -0700 | [diff] [blame] | 5145 | /** |
| 5146 | * Removes the input task from this stack. |
| 5147 | * @param task to remove. |
| 5148 | * @param reason for removal. |
Wale Ogunwale | 06579d6 | 2016-04-30 15:29:06 -0700 | [diff] [blame] | 5149 | * @param mode task removal mode. Either {@link #REMOVE_TASK_MODE_DESTROYING}, |
| 5150 | * {@link #REMOVE_TASK_MODE_MOVING}, {@link #REMOVE_TASK_MODE_MOVING_TO_TOP}. |
Wale Ogunwale | 000957c | 2015-04-03 08:19:12 -0700 | [diff] [blame] | 5151 | */ |
Wale Ogunwale | 06579d6 | 2016-04-30 15:29:06 -0700 | [diff] [blame] | 5152 | void removeTask(TaskRecord task, String reason, int mode) { |
| 5153 | if (mode == REMOVE_TASK_MODE_DESTROYING) { |
Craig Mautner | 15df08a | 2015-04-01 12:17:18 -0700 | [diff] [blame] | 5154 | mStackSupervisor.removeLockedTaskLocked(task); |
Wale Ogunwale | 53a29a9 | 2015-02-23 15:42:52 -0800 | [diff] [blame] | 5155 | mWindowManager.removeTask(task.taskId); |
Wale Ogunwale | b317b22 | 2015-11-09 11:14:10 -0800 | [diff] [blame] | 5156 | if (!StackId.persistTaskBounds(mStackId)) { |
| 5157 | // Reset current bounds for task whose bounds shouldn't be persisted so it uses |
| 5158 | // default configuration the next time it launches. |
| 5159 | task.updateOverrideConfiguration(null); |
| 5160 | } |
Wale Ogunwale | 53a29a9 | 2015-02-23 15:42:52 -0800 | [diff] [blame] | 5161 | } |
Wale Ogunwale | 000957c | 2015-04-03 08:19:12 -0700 | [diff] [blame] | 5162 | |
Craig Mautner | 04a0ea6 | 2014-01-13 12:51:26 -0800 | [diff] [blame] | 5163 | final ActivityRecord r = mResumedActivity; |
| 5164 | if (r != null && r.task == task) { |
| 5165 | mResumedActivity = null; |
| 5166 | } |
| 5167 | |
Craig Mautner | ae7ecab | 2013-09-18 11:48:14 -0700 | [diff] [blame] | 5168 | final int taskNdx = mTaskHistory.indexOf(task); |
| 5169 | final int topTaskNdx = mTaskHistory.size() - 1; |
Craig Mautner | 84984fa | 2014-06-19 11:19:20 -0700 | [diff] [blame] | 5170 | if (task.isOverHomeStack() && taskNdx < topTaskNdx) { |
| 5171 | final TaskRecord nextTask = mTaskHistory.get(taskNdx + 1); |
| 5172 | if (!nextTask.isOverHomeStack()) { |
| 5173 | nextTask.setTaskToReturnTo(HOME_ACTIVITY_TYPE); |
| 5174 | } |
Craig Mautner | ae7ecab | 2013-09-18 11:48:14 -0700 | [diff] [blame] | 5175 | } |
Craig Mautner | de4ef02 | 2013-04-07 19:01:33 -0700 | [diff] [blame] | 5176 | mTaskHistory.remove(task); |
Craig Mautner | 21d24a2 | 2014-04-23 11:45:37 -0700 | [diff] [blame] | 5177 | updateTaskMovement(task, true); |
Craig Mautner | 41db4a7 | 2014-05-07 17:20:56 -0700 | [diff] [blame] | 5178 | |
Wale Ogunwale | 06579d6 | 2016-04-30 15:29:06 -0700 | [diff] [blame] | 5179 | if (mode == REMOVE_TASK_MODE_DESTROYING && task.mActivities.isEmpty()) { |
Amith Yamasani | 0af6fa7 | 2016-01-17 15:36:19 -0800 | [diff] [blame] | 5180 | // TODO: VI what about activity? |
Craig Mautner | 41db4a7 | 2014-05-07 17:20:56 -0700 | [diff] [blame] | 5181 | final boolean isVoiceSession = task.voiceSession != null; |
| 5182 | if (isVoiceSession) { |
| 5183 | try { |
| 5184 | task.voiceSession.taskFinished(task.intent, task.taskId); |
| 5185 | } catch (RemoteException e) { |
| 5186 | } |
Dianne Hackborn | c03c916 | 2014-05-02 10:45:59 -0700 | [diff] [blame] | 5187 | } |
Craig Mautner | 41db4a7 | 2014-05-07 17:20:56 -0700 | [diff] [blame] | 5188 | if (task.autoRemoveFromRecents() || isVoiceSession) { |
| 5189 | // Task creator asked to remove this when done, or this task was a voice |
| 5190 | // interaction, so it should not remain on the recent tasks list. |
Wale Ogunwale | c82f2f5 | 2014-12-09 09:32:50 -0800 | [diff] [blame] | 5191 | mRecentTasks.remove(task); |
Winson Chung | 740c3ac | 2014-11-12 16:14:38 -0800 | [diff] [blame] | 5192 | task.removedFromRecents(); |
Craig Mautner | 41db4a7 | 2014-05-07 17:20:56 -0700 | [diff] [blame] | 5193 | } |
Dianne Hackborn | 91097de | 2014-04-04 18:02:06 -0700 | [diff] [blame] | 5194 | } |
Craig Mautner | 04a0ea6 | 2014-01-13 12:51:26 -0800 | [diff] [blame] | 5195 | |
| 5196 | if (mTaskHistory.isEmpty()) { |
Wale Ogunwale | ee006da | 2015-03-30 14:49:25 -0700 | [diff] [blame] | 5197 | if (DEBUG_STACK) Slog.i(TAG_STACK, "removeTask: removing stack=" + this); |
Wale Ogunwale | 06579d6 | 2016-04-30 15:29:06 -0700 | [diff] [blame] | 5198 | // We only need to adjust focused stack if this stack is in focus and we are not in the |
| 5199 | // process of moving the task to the top of the stack that will be focused. |
| 5200 | if (isOnHomeDisplay() && mode != REMOVE_TASK_MODE_MOVING_TO_TOP |
| 5201 | && mStackSupervisor.isFocusedStack(this)) { |
Wale Ogunwale | d697cea | 2015-02-20 17:19:49 -0800 | [diff] [blame] | 5202 | String myReason = reason + " leftTaskHistoryEmpty"; |
Wale Ogunwale | d34e80c | 2016-03-23 17:08:44 -0700 | [diff] [blame] | 5203 | if (mFullscreen |
| 5204 | || !adjustFocusToNextFocusableStackLocked( |
| 5205 | task.getTaskToReturnTo(), myReason)) { |
Wale Ogunwale | 925d0d1 | 2015-09-23 15:40:07 -0700 | [diff] [blame] | 5206 | mStackSupervisor.moveHomeStackToFront(myReason); |
Wale Ogunwale | d697cea | 2015-02-20 17:19:49 -0800 | [diff] [blame] | 5207 | } |
Craig Mautner | 04a0ea6 | 2014-01-13 12:51:26 -0800 | [diff] [blame] | 5208 | } |
Craig Mautner | 593a4e6 | 2014-01-15 17:55:51 -0800 | [diff] [blame] | 5209 | if (mStacks != null) { |
| 5210 | mStacks.remove(this); |
| 5211 | mStacks.add(0, this); |
| 5212 | } |
Wale Ogunwale | 925d0d1 | 2015-09-23 15:40:07 -0700 | [diff] [blame] | 5213 | if (!isHomeStack()) { |
Wale Ogunwale | 49853bf | 2015-02-23 09:24:42 -0800 | [diff] [blame] | 5214 | mActivityContainer.onTaskListEmptyLocked(); |
| 5215 | } |
Craig Mautner | 04a0ea6 | 2014-01-13 12:51:26 -0800 | [diff] [blame] | 5216 | } |
Wale Ogunwale | 04f4d6b | 2015-03-11 09:23:25 -0700 | [diff] [blame] | 5217 | |
| 5218 | task.stack = null; |
Craig Mautner | 0247fc8 | 2013-02-28 14:32:06 -0800 | [diff] [blame] | 5219 | } |
| 5220 | |
Dianne Hackborn | 91097de | 2014-04-04 18:02:06 -0700 | [diff] [blame] | 5221 | TaskRecord createTaskRecord(int taskId, ActivityInfo info, Intent intent, |
| 5222 | IVoiceInteractionSession voiceSession, IVoiceInteractor voiceInteractor, |
| 5223 | boolean toTop) { |
Craig Mautner | 21d24a2 | 2014-04-23 11:45:37 -0700 | [diff] [blame] | 5224 | TaskRecord task = new TaskRecord(mService, taskId, info, intent, voiceSession, |
| 5225 | voiceInteractor); |
Chong Zhang | 0fa656b | 2015-08-31 15:17:21 -0700 | [diff] [blame] | 5226 | // add the task to stack first, mTaskPositioner might need the stack association |
Wale Ogunwale | 5f98609 | 2015-12-04 15:35:38 -0800 | [diff] [blame] | 5227 | addTask(task, toTop, "createTaskRecord"); |
Chong Zhang | 75b3720 | 2015-12-04 14:16:36 -0800 | [diff] [blame] | 5228 | final boolean isLockscreenShown = mService.mLockScreenShown == LOCK_SCREEN_SHOWN; |
Andrii Kulian | 2e751b8 | 2016-03-16 16:59:32 -0700 | [diff] [blame] | 5229 | if (!layoutTaskInStack(task, info.windowLayout) && mBounds != null && task.isResizeable() |
Chong Zhang | 75b3720 | 2015-12-04 14:16:36 -0800 | [diff] [blame] | 5230 | && !isLockscreenShown) { |
Wale Ogunwale | a6e902e | 2015-09-21 18:37:15 -0700 | [diff] [blame] | 5231 | task.updateOverrideConfiguration(mBounds); |
Filip Gruszczynski | e5390e7 | 2015-08-18 16:39:00 -0700 | [diff] [blame] | 5232 | } |
Craig Mautner | 5d9c7be | 2013-02-15 14:02:56 -0800 | [diff] [blame] | 5233 | return task; |
| 5234 | } |
Craig Mautner | c00204b | 2013-03-05 15:02:14 -0800 | [diff] [blame] | 5235 | |
Andrii Kulian | 2e751b8 | 2016-03-16 16:59:32 -0700 | [diff] [blame] | 5236 | boolean layoutTaskInStack(TaskRecord task, ActivityInfo.WindowLayout windowLayout) { |
Wale Ogunwale | 935e502 | 2015-11-10 12:36:10 -0800 | [diff] [blame] | 5237 | if (mTaskPositioner == null) { |
| 5238 | return false; |
| 5239 | } |
Andrii Kulian | 2e751b8 | 2016-03-16 16:59:32 -0700 | [diff] [blame] | 5240 | mTaskPositioner.updateDefaultBounds(task, mTaskHistory, windowLayout); |
Wale Ogunwale | 935e502 | 2015-11-10 12:36:10 -0800 | [diff] [blame] | 5241 | return true; |
| 5242 | } |
| 5243 | |
Craig Mautner | c00204b | 2013-03-05 15:02:14 -0800 | [diff] [blame] | 5244 | ArrayList<TaskRecord> getAllTasks() { |
Wale Ogunwale | 9d3de4c | 2015-02-01 16:49:44 -0800 | [diff] [blame] | 5245 | return new ArrayList<>(mTaskHistory); |
Craig Mautner | c00204b | 2013-03-05 15:02:14 -0800 | [diff] [blame] | 5246 | } |
| 5247 | |
Wale Ogunwale | 5f98609 | 2015-12-04 15:35:38 -0800 | [diff] [blame] | 5248 | void addTask(final TaskRecord task, final boolean toTop, String reason) { |
Wale Ogunwale | 06579d6 | 2016-04-30 15:29:06 -0700 | [diff] [blame] | 5249 | final ActivityStack prevStack = preAddTask(task, reason, toTop); |
Wale Ogunwale | 5f98609 | 2015-12-04 15:35:38 -0800 | [diff] [blame] | 5250 | |
Craig Mautner | c00204b | 2013-03-05 15:02:14 -0800 | [diff] [blame] | 5251 | task.stack = this; |
| 5252 | if (toTop) { |
Wale Ogunwale | 3fcb4a8 | 2015-04-06 14:00:13 -0700 | [diff] [blame] | 5253 | insertTaskAtTop(task, null); |
Craig Mautner | c00204b | 2013-03-05 15:02:14 -0800 | [diff] [blame] | 5254 | } else { |
| 5255 | mTaskHistory.add(0, task); |
Craig Mautner | 21d24a2 | 2014-04-23 11:45:37 -0700 | [diff] [blame] | 5256 | updateTaskMovement(task, false); |
Craig Mautner | c00204b | 2013-03-05 15:02:14 -0800 | [diff] [blame] | 5257 | } |
Wale Ogunwale | 5f98609 | 2015-12-04 15:35:38 -0800 | [diff] [blame] | 5258 | postAddTask(task, prevStack); |
Craig Mautner | c00204b | 2013-03-05 15:02:14 -0800 | [diff] [blame] | 5259 | } |
| 5260 | |
Wale Ogunwale | 5f98609 | 2015-12-04 15:35:38 -0800 | [diff] [blame] | 5261 | void positionTask(final TaskRecord task, int position) { |
Jorim Jaggi | 023da53 | 2016-04-20 22:42:32 -0700 | [diff] [blame] | 5262 | final ActivityRecord topRunningActivity = task.topRunningActivityLocked(); |
| 5263 | final boolean wasResumed = topRunningActivity == task.stack.mResumedActivity; |
Wale Ogunwale | ed811d7 | 2016-05-06 08:41:19 -0700 | [diff] [blame] | 5264 | final ActivityStack prevStack = preAddTask(task, "positionTask", !ON_TOP); |
Wale Ogunwale | ddc1cb2 | 2015-07-25 19:23:04 -0700 | [diff] [blame] | 5265 | task.stack = this; |
| 5266 | insertTaskAtPosition(task, position); |
Wale Ogunwale | 5f98609 | 2015-12-04 15:35:38 -0800 | [diff] [blame] | 5267 | postAddTask(task, prevStack); |
Jorim Jaggi | 023da53 | 2016-04-20 22:42:32 -0700 | [diff] [blame] | 5268 | if (wasResumed) { |
| 5269 | if (mResumedActivity != null) { |
| 5270 | Log.wtf(TAG, "mResumedActivity was already set when moving mResumedActivity from" |
| 5271 | + " other stack to this stack mResumedActivity=" + mResumedActivity |
| 5272 | + " other mResumedActivity=" + topRunningActivity); |
| 5273 | } |
| 5274 | mResumedActivity = topRunningActivity; |
| 5275 | } |
Wale Ogunwale | 5f98609 | 2015-12-04 15:35:38 -0800 | [diff] [blame] | 5276 | } |
| 5277 | |
Wale Ogunwale | 06579d6 | 2016-04-30 15:29:06 -0700 | [diff] [blame] | 5278 | private ActivityStack preAddTask(TaskRecord task, String reason, boolean toTop) { |
Wale Ogunwale | 5f98609 | 2015-12-04 15:35:38 -0800 | [diff] [blame] | 5279 | final ActivityStack prevStack = task.stack; |
| 5280 | if (prevStack != null && prevStack != this) { |
Wale Ogunwale | 06579d6 | 2016-04-30 15:29:06 -0700 | [diff] [blame] | 5281 | prevStack.removeTask(task, reason, |
| 5282 | toTop ? REMOVE_TASK_MODE_MOVING_TO_TOP : REMOVE_TASK_MODE_MOVING); |
Wale Ogunwale | 5f98609 | 2015-12-04 15:35:38 -0800 | [diff] [blame] | 5283 | } |
| 5284 | return prevStack; |
| 5285 | } |
| 5286 | |
| 5287 | private void postAddTask(TaskRecord task, ActivityStack prevStack) { |
| 5288 | if (prevStack != null) { |
Andrii Kulian | 933076d | 2016-03-29 17:04:42 -0700 | [diff] [blame] | 5289 | mStackSupervisor.scheduleReportPictureInPictureModeChangedIfNeeded(task, prevStack); |
Wale Ogunwale | 5f98609 | 2015-12-04 15:35:38 -0800 | [diff] [blame] | 5290 | } else if (task.voiceSession != null) { |
Wale Ogunwale | ddc1cb2 | 2015-07-25 19:23:04 -0700 | [diff] [blame] | 5291 | try { |
| 5292 | task.voiceSession.taskStarted(task.intent, task.taskId); |
| 5293 | } catch (RemoteException e) { |
| 5294 | } |
| 5295 | } |
| 5296 | } |
| 5297 | |
Filip Gruszczynski | e5390e7 | 2015-08-18 16:39:00 -0700 | [diff] [blame] | 5298 | void addConfigOverride(ActivityRecord r, TaskRecord task) { |
Filip Gruszczynski | dce2d16 | 2016-01-12 15:40:13 -0800 | [diff] [blame] | 5299 | final Rect bounds = task.updateOverrideConfigurationFromLaunchBounds(); |
Amith Yamasani | 0af6fa7 | 2016-01-17 15:36:19 -0800 | [diff] [blame] | 5300 | // TODO: VI deal with activity |
Filip Gruszczynski | ebcc875 | 2015-08-25 16:51:05 -0700 | [diff] [blame] | 5301 | mWindowManager.addAppToken(task.mActivities.indexOf(r), r.appToken, |
| 5302 | r.task.taskId, mStackId, r.info.screenOrientation, r.fullscreen, |
Wale Ogunwale | 6cae765 | 2015-12-26 07:36:26 -0800 | [diff] [blame] | 5303 | (r.info.flags & FLAG_SHOW_FOR_ALL_USERS) != 0, r.userId, r.info.configChanges, |
| 5304 | task.voiceSession != null, r.mLaunchTaskBehind, bounds, task.mOverrideConfig, |
Yorke Lee | 0e85247 | 2016-06-15 10:03:18 -0700 | [diff] [blame] | 5305 | task.mResizeMode, r.isAlwaysFocusable(), task.isHomeTask(), |
Jiaquan He | dd1e66f | 2016-06-15 15:15:12 -0700 | [diff] [blame] | 5306 | r.appInfo.targetSdkVersion, r.mRotationAnimationHint, task.isOnTopLauncher()); |
Wale Ogunwale | 706ed79 | 2015-08-02 10:29:44 -0700 | [diff] [blame] | 5307 | r.taskConfigOverride = task.mOverrideConfig; |
| 5308 | } |
| 5309 | |
Wale Ogunwale | d046a01 | 2015-12-24 13:05:59 -0800 | [diff] [blame] | 5310 | void moveToFrontAndResumeStateIfNeeded( |
| 5311 | ActivityRecord r, boolean moveToFront, boolean setResume, String reason) { |
| 5312 | if (!moveToFront) { |
| 5313 | return; |
Wale Ogunwale | 079a004 | 2015-10-24 11:44:07 -0700 | [diff] [blame] | 5314 | } |
Wale Ogunwale | d046a01 | 2015-12-24 13:05:59 -0800 | [diff] [blame] | 5315 | |
| 5316 | // If the activity owns the last resumed activity, transfer that together, |
| 5317 | // so that we don't resume the same activity again in the new stack. |
| 5318 | // Apps may depend on onResume()/onPause() being called in pairs. |
| 5319 | if (setResume) { |
| 5320 | mResumedActivity = r; |
| 5321 | } |
| 5322 | // Move the stack in which we are placing the activity to the front. The call will also |
| 5323 | // make sure the activity focus is set. |
| 5324 | moveToFront(reason); |
Wale Ogunwale | 079a004 | 2015-10-24 11:44:07 -0700 | [diff] [blame] | 5325 | } |
| 5326 | |
| 5327 | /** |
| 5328 | * Moves the input activity from its current stack to this one. |
| 5329 | * NOTE: The current task of the activity isn't moved to this stack. Instead a new task is |
| 5330 | * created on this stack which the activity is added to. |
| 5331 | * */ |
| 5332 | void moveActivityToStack(ActivityRecord r) { |
| 5333 | final ActivityStack prevStack = r.task.stack; |
| 5334 | if (prevStack.mStackId == mStackId) { |
| 5335 | // You are already in the right stack silly... |
| 5336 | return; |
| 5337 | } |
| 5338 | |
Wale Ogunwale | 1e60e0c | 2015-10-28 13:36:10 -0700 | [diff] [blame] | 5339 | final boolean wasFocused = mStackSupervisor.isFocusedStack(prevStack) |
Wale Ogunwale | 079a004 | 2015-10-24 11:44:07 -0700 | [diff] [blame] | 5340 | && (mStackSupervisor.topRunningActivityLocked() == r); |
| 5341 | final boolean wasResumed = wasFocused && (prevStack.mResumedActivity == r); |
| 5342 | |
| 5343 | final TaskRecord task = createTaskRecord( |
Suprabh Shukla | 09a88f5 | 2015-12-02 14:36:31 -0800 | [diff] [blame] | 5344 | mStackSupervisor.getNextTaskIdForUserLocked(r.userId), |
| 5345 | r.info, r.intent, null, null, true); |
Wale Ogunwale | 079a004 | 2015-10-24 11:44:07 -0700 | [diff] [blame] | 5346 | r.setTask(task, null); |
| 5347 | task.addActivityToTop(r); |
| 5348 | setAppTask(r, task); |
Andrii Kulian | 933076d | 2016-03-29 17:04:42 -0700 | [diff] [blame] | 5349 | mStackSupervisor.scheduleReportPictureInPictureModeChangedIfNeeded(task, prevStack); |
Wale Ogunwale | d046a01 | 2015-12-24 13:05:59 -0800 | [diff] [blame] | 5350 | moveToFrontAndResumeStateIfNeeded(r, wasFocused, wasResumed, "moveActivityToStack"); |
| 5351 | if (wasResumed) { |
| 5352 | prevStack.mResumedActivity = null; |
| 5353 | } |
Wale Ogunwale | 079a004 | 2015-10-24 11:44:07 -0700 | [diff] [blame] | 5354 | } |
| 5355 | |
Wale Ogunwale | 706ed79 | 2015-08-02 10:29:44 -0700 | [diff] [blame] | 5356 | private void setAppTask(ActivityRecord r, TaskRecord task) { |
Filip Gruszczynski | dce2d16 | 2016-01-12 15:40:13 -0800 | [diff] [blame] | 5357 | final Rect bounds = task.updateOverrideConfigurationFromLaunchBounds(); |
Wale Ogunwale | b1faf60 | 2016-01-27 09:12:31 -0800 | [diff] [blame] | 5358 | mWindowManager.setAppTask(r.appToken, task.taskId, mStackId, bounds, task.mOverrideConfig, |
Jiaquan He | dd1e66f | 2016-06-15 15:15:12 -0700 | [diff] [blame] | 5359 | task.mResizeMode, task.isHomeTask(), task.isOnTopLauncher()); |
Wale Ogunwale | 706ed79 | 2015-08-02 10:29:44 -0700 | [diff] [blame] | 5360 | r.taskConfigOverride = task.mOverrideConfig; |
| 5361 | } |
| 5362 | |
Craig Mautner | c00204b | 2013-03-05 15:02:14 -0800 | [diff] [blame] | 5363 | public int getStackId() { |
| 5364 | return mStackId; |
| 5365 | } |
Craig Mautner | de4ef02 | 2013-04-07 19:01:33 -0700 | [diff] [blame] | 5366 | |
| 5367 | @Override |
| 5368 | public String toString() { |
Dianne Hackborn | 2a272d4 | 2013-10-16 13:34:33 -0700 | [diff] [blame] | 5369 | return "ActivityStack{" + Integer.toHexString(System.identityHashCode(this)) |
| 5370 | + " stackId=" + mStackId + ", " + mTaskHistory.size() + " tasks}"; |
Craig Mautner | de4ef02 | 2013-04-07 19:01:33 -0700 | [diff] [blame] | 5371 | } |
Wale Ogunwale | 60454db | 2015-01-23 16:05:07 -0800 | [diff] [blame] | 5372 | |
Craig Mautner | 15df08a | 2015-04-01 12:17:18 -0700 | [diff] [blame] | 5373 | void onLockTaskPackagesUpdatedLocked() { |
| 5374 | for (int taskNdx = mTaskHistory.size() - 1; taskNdx >= 0; --taskNdx) { |
| 5375 | mTaskHistory.get(taskNdx).setLockTaskAuth(); |
| 5376 | } |
| 5377 | } |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 5378 | } |