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 | |
Amith Yamasani | 734983f | 2014-03-04 16:48:05 -0800 | [diff] [blame] | 547 | boolean okToShowLocked(ActivityRecord r) { |
Chong Zhang | 45c25ce | 2015-08-10 22:18:26 -0700 | [diff] [blame] | 548 | return mStackSupervisor.okToShowLocked(r); |
Craig Mautner | 5962b12 | 2012-10-05 14:45:52 -0700 | [diff] [blame] | 549 | } |
| 550 | |
Filip Gruszczynski | 3e85ba2 | 2015-10-05 22:48:30 -0700 | [diff] [blame] | 551 | final ActivityRecord topRunningActivityLocked() { |
Craig Mautner | d74f7d7 | 2013-02-26 13:41:02 -0800 | [diff] [blame] | 552 | for (int taskNdx = mTaskHistory.size() - 1; taskNdx >= 0; --taskNdx) { |
Filip Gruszczynski | 3e85ba2 | 2015-10-05 22:48:30 -0700 | [diff] [blame] | 553 | ActivityRecord r = mTaskHistory.get(taskNdx).topRunningActivityLocked(); |
Craig Mautner | 6b74cb5 | 2013-09-27 17:02:21 -0700 | [diff] [blame] | 554 | if (r != null) { |
| 555 | return r; |
Craig Mautner | 11bf9a5 | 2013-02-19 14:08:51 -0800 | [diff] [blame] | 556 | } |
| 557 | } |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 558 | return null; |
| 559 | } |
| 560 | |
| 561 | final ActivityRecord topRunningNonDelayedActivityLocked(ActivityRecord notTop) { |
Craig Mautner | d74f7d7 | 2013-02-26 13:41:02 -0800 | [diff] [blame] | 562 | for (int taskNdx = mTaskHistory.size() - 1; taskNdx >= 0; --taskNdx) { |
| 563 | final TaskRecord task = mTaskHistory.get(taskNdx); |
Craig Mautner | 11bf9a5 | 2013-02-19 14:08:51 -0800 | [diff] [blame] | 564 | final ArrayList<ActivityRecord> activities = task.mActivities; |
Craig Mautner | d74f7d7 | 2013-02-26 13:41:02 -0800 | [diff] [blame] | 565 | for (int activityNdx = activities.size() - 1; activityNdx >= 0; --activityNdx) { |
| 566 | ActivityRecord r = activities.get(activityNdx); |
Amith Yamasani | 734983f | 2014-03-04 16:48:05 -0800 | [diff] [blame] | 567 | if (!r.finishing && !r.delayedResume && r != notTop && okToShowLocked(r)) { |
Craig Mautner | 11bf9a5 | 2013-02-19 14:08:51 -0800 | [diff] [blame] | 568 | return r; |
| 569 | } |
| 570 | } |
| 571 | } |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 572 | return null; |
| 573 | } |
| 574 | |
| 575 | /** |
| 576 | * This is a simplified version of topRunningActivityLocked that provides a number of |
| 577 | * 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] | 578 | * |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 579 | * @param token If non-null, any history records matching this token will be skipped. |
| 580 | * @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] | 581 | * |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 582 | * @return Returns the HistoryRecord of the next activity on the stack. |
| 583 | */ |
| 584 | final ActivityRecord topRunningActivityLocked(IBinder token, int taskId) { |
Craig Mautner | 11bf9a5 | 2013-02-19 14:08:51 -0800 | [diff] [blame] | 585 | for (int taskNdx = mTaskHistory.size() - 1; taskNdx >= 0; --taskNdx) { |
| 586 | TaskRecord task = mTaskHistory.get(taskNdx); |
| 587 | if (task.taskId == taskId) { |
| 588 | continue; |
| 589 | } |
| 590 | ArrayList<ActivityRecord> activities = task.mActivities; |
| 591 | for (int i = activities.size() - 1; i >= 0; --i) { |
| 592 | final ActivityRecord r = activities.get(i); |
| 593 | // Note: the taskId check depends on real taskId fields being non-zero |
Amith Yamasani | 734983f | 2014-03-04 16:48:05 -0800 | [diff] [blame] | 594 | if (!r.finishing && (token != r.appToken) && okToShowLocked(r)) { |
Craig Mautner | 11bf9a5 | 2013-02-19 14:08:51 -0800 | [diff] [blame] | 595 | return r; |
| 596 | } |
| 597 | } |
| 598 | } |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 599 | return null; |
| 600 | } |
| 601 | |
Craig Mautner | 8849a5e | 2013-04-02 16:41:03 -0700 | [diff] [blame] | 602 | final ActivityRecord topActivity() { |
Craig Mautner | 8849a5e | 2013-04-02 16:41:03 -0700 | [diff] [blame] | 603 | for (int taskNdx = mTaskHistory.size() - 1; taskNdx >= 0; --taskNdx) { |
| 604 | ArrayList<ActivityRecord> activities = mTaskHistory.get(taskNdx).mActivities; |
Craig Mautner | 0175b88 | 2014-09-07 18:05:31 -0700 | [diff] [blame] | 605 | for (int activityNdx = activities.size() - 1; activityNdx >= 0; --activityNdx) { |
| 606 | final ActivityRecord r = activities.get(activityNdx); |
| 607 | if (!r.finishing) { |
| 608 | return r; |
| 609 | } |
Craig Mautner | 8849a5e | 2013-04-02 16:41:03 -0700 | [diff] [blame] | 610 | } |
| 611 | } |
Craig Mautner | de4ef02 | 2013-04-07 19:01:33 -0700 | [diff] [blame] | 612 | return null; |
Craig Mautner | 8849a5e | 2013-04-02 16:41:03 -0700 | [diff] [blame] | 613 | } |
| 614 | |
Craig Mautner | 9e14d0f | 2013-05-01 11:26:09 -0700 | [diff] [blame] | 615 | final TaskRecord topTask() { |
| 616 | final int size = mTaskHistory.size(); |
| 617 | if (size > 0) { |
| 618 | return mTaskHistory.get(size - 1); |
| 619 | } |
| 620 | return null; |
| 621 | } |
| 622 | |
Craig Mautner | d232895 | 2013-03-05 12:46:26 -0800 | [diff] [blame] | 623 | TaskRecord taskForIdLocked(int id) { |
| 624 | for (int taskNdx = mTaskHistory.size() - 1; taskNdx >= 0; --taskNdx) { |
| 625 | final TaskRecord task = mTaskHistory.get(taskNdx); |
| 626 | if (task.taskId == id) { |
| 627 | return task; |
Craig Mautner | 5d9c7be | 2013-02-15 14:02:56 -0800 | [diff] [blame] | 628 | } |
| 629 | } |
Dianne Hackborn | ce86ba8 | 2011-07-13 19:33:41 -0700 | [diff] [blame] | 630 | return null; |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 631 | } |
| 632 | |
Craig Mautner | d232895 | 2013-03-05 12:46:26 -0800 | [diff] [blame] | 633 | ActivityRecord isInStackLocked(IBinder token) { |
Wale Ogunwale | 7d70117 | 2015-03-11 15:36:30 -0700 | [diff] [blame] | 634 | final ActivityRecord r = ActivityRecord.forTokenLocked(token); |
Wale Ogunwale | 60454db | 2015-01-23 16:05:07 -0800 | [diff] [blame] | 635 | return isInStackLocked(r); |
| 636 | } |
| 637 | |
| 638 | ActivityRecord isInStackLocked(ActivityRecord r) { |
| 639 | if (r == null) { |
| 640 | return null; |
| 641 | } |
| 642 | final TaskRecord task = r.task; |
Wale Ogunwale | 7d70117 | 2015-03-11 15:36:30 -0700 | [diff] [blame] | 643 | if (task != null && task.stack != null |
| 644 | && task.mActivities.contains(r) && mTaskHistory.contains(task)) { |
Wale Ogunwale | 60454db | 2015-01-23 16:05:07 -0800 | [diff] [blame] | 645 | if (task.stack != this) Slog.w(TAG, |
Craig Mautner | d232895 | 2013-03-05 12:46:26 -0800 | [diff] [blame] | 646 | "Illegal state! task does not point to stack it is in."); |
Wale Ogunwale | 60454db | 2015-01-23 16:05:07 -0800 | [diff] [blame] | 647 | return r; |
Craig Mautner | 5d9c7be | 2013-02-15 14:02:56 -0800 | [diff] [blame] | 648 | } |
Craig Mautner | d232895 | 2013-03-05 12:46:26 -0800 | [diff] [blame] | 649 | return null; |
Craig Mautner | 5d9c7be | 2013-02-15 14:02:56 -0800 | [diff] [blame] | 650 | } |
| 651 | |
Craig Mautner | 2420ead | 2013-04-01 17:13:20 -0700 | [diff] [blame] | 652 | final boolean updateLRUListLocked(ActivityRecord r) { |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 653 | final boolean hadit = mLRUActivities.remove(r); |
| 654 | mLRUActivities.add(r); |
| 655 | return hadit; |
| 656 | } |
| 657 | |
Craig Mautner | de4ef02 | 2013-04-07 19:01:33 -0700 | [diff] [blame] | 658 | final boolean isHomeStack() { |
| 659 | return mStackId == HOME_STACK_ID; |
| 660 | } |
| 661 | |
Winson Chung | 0583d3d | 2015-12-18 10:03:12 -0500 | [diff] [blame] | 662 | final boolean isDockedStack() { |
| 663 | return mStackId == DOCKED_STACK_ID; |
| 664 | } |
| 665 | |
| 666 | final boolean isPinnedStack() { |
| 667 | return mStackId == PINNED_STACK_ID; |
| 668 | } |
| 669 | |
Craig Mautner | e0a3884 | 2013-12-16 16:14:02 -0800 | [diff] [blame] | 670 | final boolean isOnHomeDisplay() { |
| 671 | return isAttached() && |
| 672 | mActivityContainer.mActivityDisplay.mDisplayId == Display.DEFAULT_DISPLAY; |
| 673 | } |
| 674 | |
Wale Ogunwale | eae451e | 2015-08-04 15:20:50 -0700 | [diff] [blame] | 675 | void moveToFront(String reason) { |
| 676 | moveToFront(reason, null); |
| 677 | } |
| 678 | |
| 679 | /** |
| 680 | * @param reason The reason for moving the stack to the front. |
| 681 | * @param task If non-null, the task will be moved to the top of the stack. |
| 682 | * */ |
| 683 | void moveToFront(String reason, TaskRecord task) { |
Wale Ogunwale | 1e60e0c | 2015-10-28 13:36:10 -0700 | [diff] [blame] | 684 | if (!isAttached()) { |
| 685 | return; |
| 686 | } |
Wale Ogunwale | 925d0d1 | 2015-09-23 15:40:07 -0700 | [diff] [blame] | 687 | |
Wale Ogunwale | 1e60e0c | 2015-10-28 13:36:10 -0700 | [diff] [blame] | 688 | mStacks.remove(this); |
| 689 | int addIndex = mStacks.size(); |
| 690 | |
| 691 | if (addIndex > 0) { |
| 692 | final ActivityStack topStack = mStacks.get(addIndex - 1); |
Filip Gruszczynski | 114d5ca | 2015-12-04 09:05:00 -0800 | [diff] [blame] | 693 | if (StackId.isAlwaysOnTop(topStack.mStackId) && topStack != this) { |
| 694 | // 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] | 695 | addIndex--; |
Wale Ogunwale | cb82f30 | 2015-02-25 07:53:40 -0800 | [diff] [blame] | 696 | } |
Wale Ogunwale | 1e60e0c | 2015-10-28 13:36:10 -0700 | [diff] [blame] | 697 | } |
| 698 | |
| 699 | mStacks.add(addIndex, this); |
| 700 | |
| 701 | // TODO(multi-display): Needs to also work if focus is moving to the non-home display. |
| 702 | if (isOnHomeDisplay()) { |
Wale Ogunwale | 4cea0f5 | 2015-12-25 06:30:31 -0800 | [diff] [blame] | 703 | mStackSupervisor.setFocusStackUnchecked(reason, this); |
Wale Ogunwale | 1e60e0c | 2015-10-28 13:36:10 -0700 | [diff] [blame] | 704 | } |
| 705 | if (task != null) { |
| 706 | insertTaskAtTop(task, null); |
| 707 | } else { |
| 708 | task = topTask(); |
| 709 | } |
| 710 | if (task != null) { |
| 711 | mWindowManager.moveTaskToTop(task.taskId); |
Craig Mautner | 4a1cb22 | 2013-12-04 16:14:06 -0800 | [diff] [blame] | 712 | } |
Craig Mautner | e0a3884 | 2013-12-16 16:14:02 -0800 | [diff] [blame] | 713 | } |
| 714 | |
Wale Ogunwale | d046a01 | 2015-12-24 13:05:59 -0800 | [diff] [blame] | 715 | boolean isFocusable() { |
Wale Ogunwale | 4cea0f5 | 2015-12-25 06:30:31 -0800 | [diff] [blame] | 716 | if (StackId.canReceiveKeys(mStackId)) { |
| 717 | return true; |
| 718 | } |
| 719 | // The stack isn't focusable. See if its top activity is focusable to force focus on the |
| 720 | // stack. |
| 721 | final ActivityRecord r = topRunningActivityLocked(); |
| 722 | return r != null && r.isFocusable(); |
Wale Ogunwale | d046a01 | 2015-12-24 13:05:59 -0800 | [diff] [blame] | 723 | } |
| 724 | |
Craig Mautner | e0a3884 | 2013-12-16 16:14:02 -0800 | [diff] [blame] | 725 | final boolean isAttached() { |
| 726 | return mStacks != null; |
Craig Mautner | 4a1cb22 | 2013-12-04 16:14:06 -0800 | [diff] [blame] | 727 | } |
| 728 | |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 729 | /** |
Wale Ogunwale | 3938197 | 2015-12-17 17:15:29 -0800 | [diff] [blame] | 730 | * Returns the top activity in any existing task matching the given Intent in the input result. |
| 731 | * Returns null if no such task is found. |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 732 | */ |
Wale Ogunwale | 3938197 | 2015-12-17 17:15:29 -0800 | [diff] [blame] | 733 | void findTaskLocked(ActivityRecord target, FindTaskResult result) { |
Craig Mautner | ac6f843 | 2013-07-17 13:24:59 -0700 | [diff] [blame] | 734 | Intent intent = target.intent; |
| 735 | ActivityInfo info = target.info; |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 736 | ComponentName cls = intent.getComponent(); |
| 737 | if (info.targetActivity != null) { |
| 738 | cls = new ComponentName(info.packageName, info.targetActivity); |
| 739 | } |
Dianne Hackborn | f02b60a | 2012-08-16 10:48:27 -0700 | [diff] [blame] | 740 | final int userId = UserHandle.getUserId(info.applicationInfo.uid); |
Craig Mautner | d00f474 | 2014-03-12 14:17:26 -0700 | [diff] [blame] | 741 | boolean isDocument = intent != null & intent.isDocument(); |
| 742 | // If documentData is non-null then it must match the existing task data. |
| 743 | Uri documentData = isDocument ? intent.getData() : null; |
Craig Mautner | 000f002 | 2013-02-26 15:04:29 -0800 | [diff] [blame] | 744 | |
Wale Ogunwale | ee006da | 2015-03-30 14:49:25 -0700 | [diff] [blame] | 745 | 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] | 746 | for (int taskNdx = mTaskHistory.size() - 1; taskNdx >= 0; --taskNdx) { |
| 747 | final TaskRecord task = mTaskHistory.get(taskNdx); |
Dianne Hackborn | 91097de | 2014-04-04 18:02:06 -0700 | [diff] [blame] | 748 | if (task.voiceSession != null) { |
| 749 | // We never match voice sessions; those always run independently. |
Wale Ogunwale | ee006da | 2015-03-30 14:49:25 -0700 | [diff] [blame] | 750 | if (DEBUG_TASKS) Slog.d(TAG_TASKS, "Skipping " + task + ": voice session"); |
Dianne Hackborn | 91097de | 2014-04-04 18:02:06 -0700 | [diff] [blame] | 751 | continue; |
| 752 | } |
Craig Mautner | ac6f843 | 2013-07-17 13:24:59 -0700 | [diff] [blame] | 753 | if (task.userId != userId) { |
| 754 | // Looking for a different task. |
Wale Ogunwale | ee006da | 2015-03-30 14:49:25 -0700 | [diff] [blame] | 755 | if (DEBUG_TASKS) Slog.d(TAG_TASKS, "Skipping " + task + ": different user"); |
Craig Mautner | ac6f843 | 2013-07-17 13:24:59 -0700 | [diff] [blame] | 756 | continue; |
| 757 | } |
Craig Mautner | 000f002 | 2013-02-26 15:04:29 -0800 | [diff] [blame] | 758 | final ActivityRecord r = task.getTopActivity(); |
| 759 | if (r == null || r.finishing || r.userId != userId || |
| 760 | r.launchMode == ActivityInfo.LAUNCH_SINGLE_INSTANCE) { |
Wale Ogunwale | ee006da | 2015-03-30 14:49:25 -0700 | [diff] [blame] | 761 | if (DEBUG_TASKS) Slog.d(TAG_TASKS, "Skipping " + task + ": mismatch root " + r); |
Craig Mautner | 000f002 | 2013-02-26 15:04:29 -0800 | [diff] [blame] | 762 | continue; |
| 763 | } |
Chong Zhang | b546f7e | 2015-08-05 14:21:36 -0700 | [diff] [blame] | 764 | if (r.mActivityType != target.mActivityType) { |
| 765 | if (DEBUG_TASKS) Slog.d(TAG_TASKS, "Skipping " + task + ": mismatch activity type"); |
| 766 | continue; |
| 767 | } |
Craig Mautner | 000f002 | 2013-02-26 15:04:29 -0800 | [diff] [blame] | 768 | |
Craig Mautner | d00f474 | 2014-03-12 14:17:26 -0700 | [diff] [blame] | 769 | final Intent taskIntent = task.intent; |
| 770 | final Intent affinityIntent = task.affinityIntent; |
| 771 | final boolean taskIsDocument; |
| 772 | final Uri taskDocumentData; |
| 773 | if (taskIntent != null && taskIntent.isDocument()) { |
| 774 | taskIsDocument = true; |
| 775 | taskDocumentData = taskIntent.getData(); |
| 776 | } else if (affinityIntent != null && affinityIntent.isDocument()) { |
| 777 | taskIsDocument = true; |
| 778 | taskDocumentData = affinityIntent.getData(); |
| 779 | } else { |
| 780 | taskIsDocument = false; |
| 781 | taskDocumentData = null; |
| 782 | } |
| 783 | |
Wale Ogunwale | ee006da | 2015-03-30 14:49:25 -0700 | [diff] [blame] | 784 | if (DEBUG_TASKS) Slog.d(TAG_TASKS, "Comparing existing cls=" |
Craig Mautner | d00f474 | 2014-03-12 14:17:26 -0700 | [diff] [blame] | 785 | + taskIntent.getComponent().flattenToShortString() |
Dianne Hackborn | 7922882 | 2014-09-16 11:11:23 -0700 | [diff] [blame] | 786 | + "/aff=" + r.task.rootAffinity + " to new cls=" |
Dianne Hackborn | 2a272d4 | 2013-10-16 13:34:33 -0700 | [diff] [blame] | 787 | + intent.getComponent().flattenToShortString() + "/aff=" + info.taskAffinity); |
Andrii Kulian | 206b9fa | 2016-06-02 13:18:01 -0700 | [diff] [blame] | 788 | // TODO Refactor to remove duplications. Check if logic can be simplified. |
| 789 | if (taskIntent != null && taskIntent.getComponent() != null && |
Craig Mautner | ffcfcaa | 2014-06-05 09:54:38 -0700 | [diff] [blame] | 790 | taskIntent.getComponent().compareTo(cls) == 0 && |
Craig Mautner | d00f474 | 2014-03-12 14:17:26 -0700 | [diff] [blame] | 791 | Objects.equals(documentData, taskDocumentData)) { |
Wale Ogunwale | ee006da | 2015-03-30 14:49:25 -0700 | [diff] [blame] | 792 | if (DEBUG_TASKS) Slog.d(TAG_TASKS, "Found matching class!"); |
Craig Mautner | 000f002 | 2013-02-26 15:04:29 -0800 | [diff] [blame] | 793 | //dump(); |
Wale Ogunwale | ee006da | 2015-03-30 14:49:25 -0700 | [diff] [blame] | 794 | if (DEBUG_TASKS) Slog.d(TAG_TASKS, |
| 795 | "For Intent " + intent + " bringing to top: " + r.intent); |
Wale Ogunwale | 3938197 | 2015-12-17 17:15:29 -0800 | [diff] [blame] | 796 | result.r = r; |
| 797 | result.matchedByRootAffinity = false; |
| 798 | break; |
Craig Mautner | ffcfcaa | 2014-06-05 09:54:38 -0700 | [diff] [blame] | 799 | } else if (affinityIntent != null && affinityIntent.getComponent() != null && |
| 800 | affinityIntent.getComponent().compareTo(cls) == 0 && |
Craig Mautner | d00f474 | 2014-03-12 14:17:26 -0700 | [diff] [blame] | 801 | Objects.equals(documentData, taskDocumentData)) { |
Wale Ogunwale | ee006da | 2015-03-30 14:49:25 -0700 | [diff] [blame] | 802 | if (DEBUG_TASKS) Slog.d(TAG_TASKS, "Found matching class!"); |
Craig Mautner | 000f002 | 2013-02-26 15:04:29 -0800 | [diff] [blame] | 803 | //dump(); |
Wale Ogunwale | ee006da | 2015-03-30 14:49:25 -0700 | [diff] [blame] | 804 | if (DEBUG_TASKS) Slog.d(TAG_TASKS, |
| 805 | "For Intent " + intent + " bringing to top: " + r.intent); |
Wale Ogunwale | 3938197 | 2015-12-17 17:15:29 -0800 | [diff] [blame] | 806 | result.r = r; |
| 807 | result.matchedByRootAffinity = false; |
| 808 | break; |
Andrii Kulian | 206b9fa | 2016-06-02 13:18:01 -0700 | [diff] [blame] | 809 | } else if (!isDocument && !taskIsDocument |
| 810 | && result.r == null && task.canMatchRootAffinity()) { |
| 811 | if (task.rootAffinity.equals(target.taskAffinity)) { |
| 812 | if (DEBUG_TASKS) Slog.d(TAG_TASKS, "Found matching affinity candidate!"); |
| 813 | // It is possible for multiple tasks to have the same root affinity especially |
| 814 | // if they are in separate stacks. We save off this candidate, but keep looking |
| 815 | // to see if there is a better candidate. |
| 816 | result.r = r; |
| 817 | result.matchedByRootAffinity = true; |
| 818 | } |
Wale Ogunwale | ee006da | 2015-03-30 14:49:25 -0700 | [diff] [blame] | 819 | } else if (DEBUG_TASKS) Slog.d(TAG_TASKS, "Not a match: " + task); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 820 | } |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 821 | } |
| 822 | |
| 823 | /** |
| 824 | * Returns the first activity (starting from the top of the stack) that |
| 825 | * is the same as the given activity. Returns null if no such activity |
| 826 | * is found. |
| 827 | */ |
Andrii Kulian | d3bbb13 | 2016-06-16 16:00:20 -0700 | [diff] [blame] | 828 | ActivityRecord findActivityLocked(Intent intent, ActivityInfo info, |
| 829 | boolean compareIntentFilters) { |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 830 | ComponentName cls = intent.getComponent(); |
| 831 | if (info.targetActivity != null) { |
| 832 | cls = new ComponentName(info.packageName, info.targetActivity); |
| 833 | } |
Dianne Hackborn | f02b60a | 2012-08-16 10:48:27 -0700 | [diff] [blame] | 834 | final int userId = UserHandle.getUserId(info.applicationInfo.uid); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 835 | |
Craig Mautner | 000f002 | 2013-02-26 15:04:29 -0800 | [diff] [blame] | 836 | for (int taskNdx = mTaskHistory.size() - 1; taskNdx >= 0; --taskNdx) { |
Wale Ogunwale | 3fcb4a8 | 2015-04-06 14:00:13 -0700 | [diff] [blame] | 837 | final TaskRecord task = mTaskHistory.get(taskNdx); |
Wale Ogunwale | 0bd2aa7 | 2015-04-16 13:50:44 -0700 | [diff] [blame] | 838 | final boolean notCurrentUserTask = |
| 839 | !mStackSupervisor.isCurrentProfileLocked(task.userId); |
Craig Mautner | ac6f843 | 2013-07-17 13:24:59 -0700 | [diff] [blame] | 840 | final ArrayList<ActivityRecord> activities = task.mActivities; |
Wale Ogunwale | 3fcb4a8 | 2015-04-06 14:00:13 -0700 | [diff] [blame] | 841 | |
Craig Mautner | 000f002 | 2013-02-26 15:04:29 -0800 | [diff] [blame] | 842 | for (int activityNdx = activities.size() - 1; activityNdx >= 0; --activityNdx) { |
| 843 | ActivityRecord r = activities.get(activityNdx); |
Wale Ogunwale | 6dfdfd6 | 2015-04-15 12:01:38 -0700 | [diff] [blame] | 844 | if (notCurrentUserTask && (r.info.flags & FLAG_SHOW_FOR_ALL_USERS) == 0) { |
Wale Ogunwale | 25073dd | 2015-07-21 16:54:54 -0700 | [diff] [blame] | 845 | continue; |
Wale Ogunwale | 3fcb4a8 | 2015-04-06 14:00:13 -0700 | [diff] [blame] | 846 | } |
Andrii Kulian | d3bbb13 | 2016-06-16 16:00:20 -0700 | [diff] [blame] | 847 | if (!r.finishing && r.userId == userId) { |
| 848 | if (compareIntentFilters) { |
| 849 | if (r.intent.filterEquals(intent)) { |
| 850 | return r; |
| 851 | } |
| 852 | } else { |
| 853 | if (r.intent.getComponent().equals(cls)) { |
| 854 | return r; |
| 855 | } |
| 856 | } |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 857 | } |
| 858 | } |
| 859 | } |
| 860 | |
| 861 | return null; |
| 862 | } |
| 863 | |
Amith Yamasani | 742a671 | 2011-05-04 14:49:28 -0700 | [diff] [blame] | 864 | /* |
Craig Mautner | ac6f843 | 2013-07-17 13:24:59 -0700 | [diff] [blame] | 865 | * 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] | 866 | */ |
Craig Mautner | 93529a4 | 2013-10-04 15:03:13 -0700 | [diff] [blame] | 867 | final void switchUserLocked(int userId) { |
Craig Mautner | 5d9c7be | 2013-02-15 14:02:56 -0800 | [diff] [blame] | 868 | if (mCurrentUser == userId) { |
Craig Mautner | 93529a4 | 2013-10-04 15:03:13 -0700 | [diff] [blame] | 869 | return; |
Craig Mautner | 5d9c7be | 2013-02-15 14:02:56 -0800 | [diff] [blame] | 870 | } |
| 871 | mCurrentUser = userId; |
| 872 | |
| 873 | // Move userId's tasks to the top. |
Craig Mautner | 5d9c7be | 2013-02-15 14:02:56 -0800 | [diff] [blame] | 874 | int index = mTaskHistory.size(); |
Craig Mautner | db5c4fb | 2013-11-06 13:55:08 -0800 | [diff] [blame] | 875 | for (int i = 0; i < index; ) { |
Wale Ogunwale | 3fcb4a8 | 2015-04-06 14:00:13 -0700 | [diff] [blame] | 876 | final TaskRecord task = mTaskHistory.get(i); |
| 877 | |
| 878 | // NOTE: If {@link TaskRecord#topRunningActivityLocked} return is not null then it is |
| 879 | // okay to show the activity when locked. |
Wale Ogunwale | 0bd2aa7 | 2015-04-16 13:50:44 -0700 | [diff] [blame] | 880 | if (mStackSupervisor.isCurrentProfileLocked(task.userId) |
Filip Gruszczynski | 3e85ba2 | 2015-10-05 22:48:30 -0700 | [diff] [blame] | 881 | || task.topRunningActivityLocked() != null) { |
Wale Ogunwale | ee006da | 2015-03-30 14:49:25 -0700 | [diff] [blame] | 882 | if (DEBUG_TASKS) Slog.d(TAG_TASKS, "switchUserLocked: stack=" + getStackId() + |
Craig Mautner | 4f1df4f | 2013-10-15 15:44:14 -0700 | [diff] [blame] | 883 | " moving " + task + " to top"); |
Craig Mautner | 5d9c7be | 2013-02-15 14:02:56 -0800 | [diff] [blame] | 884 | mTaskHistory.remove(i); |
| 885 | mTaskHistory.add(task); |
| 886 | --index; |
Craig Mautner | db5c4fb | 2013-11-06 13:55:08 -0800 | [diff] [blame] | 887 | // Use same value for i. |
| 888 | } else { |
| 889 | ++i; |
Craig Mautner | 5d9c7be | 2013-02-15 14:02:56 -0800 | [diff] [blame] | 890 | } |
| 891 | } |
Craig Mautner | 4f1df4f | 2013-10-15 15:44:14 -0700 | [diff] [blame] | 892 | if (VALIDATE_TOKENS) { |
| 893 | validateAppTokensLocked(); |
| 894 | } |
Amith Yamasani | 742a671 | 2011-05-04 14:49:28 -0700 | [diff] [blame] | 895 | } |
| 896 | |
Craig Mautner | 2420ead | 2013-04-01 17:13:20 -0700 | [diff] [blame] | 897 | void minimalResumeActivityLocked(ActivityRecord r) { |
Wale Ogunwale | 5658e4b | 2016-02-12 12:22:19 -0800 | [diff] [blame] | 898 | if (DEBUG_STATES) Slog.v(TAG_STATES, "Moving to RESUMED: " + r + " (starting new instance)" |
| 899 | + " callers=" + Debug.getCallers(5)); |
Chong Zhang | 6cda19c | 2016-06-14 19:07:56 -0700 | [diff] [blame] | 900 | setResumedActivityLocked(r, "minimalResumeActivityLocked"); |
Craig Mautner | 2420ead | 2013-04-01 17:13:20 -0700 | [diff] [blame] | 901 | completeResumeLocked(r); |
Craig Mautner | 1e8b872 | 2013-10-14 18:24:52 -0700 | [diff] [blame] | 902 | setLaunchTime(r); |
Wale Ogunwale | 0fc365c | 2015-05-25 19:35:42 -0700 | [diff] [blame] | 903 | if (DEBUG_SAVED_STATE) Slog.i(TAG_SAVED_STATE, |
| 904 | "Launch completed; removing icicle of " + r.icicle); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 905 | } |
| 906 | |
Filip Gruszczynski | 3d82ed6 | 2015-12-10 10:41:39 -0800 | [diff] [blame] | 907 | void addRecentActivityLocked(ActivityRecord r) { |
Chong Zhang | 45c25ce | 2015-08-10 22:18:26 -0700 | [diff] [blame] | 908 | if (r != null) { |
| 909 | mRecentTasks.addLocked(r.task); |
| 910 | r.task.touchActiveTime(); |
| 911 | } |
| 912 | } |
| 913 | |
Narayan Kamath | 7829c81 | 2015-06-08 17:39:43 +0100 | [diff] [blame] | 914 | private void startLaunchTraces(String packageName) { |
Dianne Hackborn | cee04b5 | 2013-07-03 17:01:28 -0700 | [diff] [blame] | 915 | if (mFullyDrawnStartTime != 0) { |
| 916 | Trace.asyncTraceEnd(Trace.TRACE_TAG_ACTIVITY_MANAGER, "drawing", 0); |
| 917 | } |
Narayan Kamath | 7829c81 | 2015-06-08 17:39:43 +0100 | [diff] [blame] | 918 | Trace.asyncTraceBegin(Trace.TRACE_TAG_ACTIVITY_MANAGER, "launching: " + packageName, 0); |
Dianne Hackborn | cee04b5 | 2013-07-03 17:01:28 -0700 | [diff] [blame] | 919 | Trace.asyncTraceBegin(Trace.TRACE_TAG_ACTIVITY_MANAGER, "drawing", 0); |
| 920 | } |
| 921 | |
| 922 | private void stopFullyDrawnTraceIfNeeded() { |
| 923 | if (mFullyDrawnStartTime != 0 && mLaunchStartTime == 0) { |
| 924 | Trace.asyncTraceEnd(Trace.TRACE_TAG_ACTIVITY_MANAGER, "drawing", 0); |
| 925 | mFullyDrawnStartTime = 0; |
| 926 | } |
| 927 | } |
| 928 | |
Craig Mautner | e79d4268 | 2013-04-01 19:01:53 -0700 | [diff] [blame] | 929 | void setLaunchTime(ActivityRecord r) { |
Dianne Hackborn | 2286cdc | 2013-07-01 19:10:06 -0700 | [diff] [blame] | 930 | if (r.displayStartTime == 0) { |
| 931 | r.fullyDrawnStartTime = r.displayStartTime = SystemClock.uptimeMillis(); |
| 932 | if (mLaunchStartTime == 0) { |
Narayan Kamath | 7829c81 | 2015-06-08 17:39:43 +0100 | [diff] [blame] | 933 | startLaunchTraces(r.packageName); |
Dianne Hackborn | 2286cdc | 2013-07-01 19:10:06 -0700 | [diff] [blame] | 934 | mLaunchStartTime = mFullyDrawnStartTime = r.displayStartTime; |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 935 | } |
Dianne Hackborn | 2286cdc | 2013-07-01 19:10:06 -0700 | [diff] [blame] | 936 | } else if (mLaunchStartTime == 0) { |
Narayan Kamath | 7829c81 | 2015-06-08 17:39:43 +0100 | [diff] [blame] | 937 | startLaunchTraces(r.packageName); |
Dianne Hackborn | 2286cdc | 2013-07-01 19:10:06 -0700 | [diff] [blame] | 938 | mLaunchStartTime = mFullyDrawnStartTime = SystemClock.uptimeMillis(); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 939 | } |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 940 | } |
Craig Mautner | aab647e | 2013-02-28 16:31:36 -0800 | [diff] [blame] | 941 | |
Dianne Hackborn | 2286cdc | 2013-07-01 19:10:06 -0700 | [diff] [blame] | 942 | void clearLaunchTime(ActivityRecord r) { |
Craig Mautner | 5c49454 | 2013-09-06 11:59:38 -0700 | [diff] [blame] | 943 | // Make sure that there is no activity waiting for this to launch. |
| 944 | if (mStackSupervisor.mWaitingActivityLaunched.isEmpty()) { |
| 945 | r.displayStartTime = r.fullyDrawnStartTime = 0; |
| 946 | } else { |
| 947 | mStackSupervisor.removeTimeoutsForActivityLocked(r); |
| 948 | mStackSupervisor.scheduleIdleTimeoutLocked(r); |
| 949 | } |
Dianne Hackborn | 2286cdc | 2013-07-01 19:10:06 -0700 | [diff] [blame] | 950 | } |
| 951 | |
Dianne Hackborn | 4eba96b | 2011-01-21 13:34:36 -0800 | [diff] [blame] | 952 | void awakeFromSleepingLocked() { |
Dianne Hackborn | 4eba96b | 2011-01-21 13:34:36 -0800 | [diff] [blame] | 953 | // Ensure activities are no longer sleeping. |
Craig Mautner | d44711d | 2013-02-23 11:24:36 -0800 | [diff] [blame] | 954 | for (int taskNdx = mTaskHistory.size() - 1; taskNdx >= 0; --taskNdx) { |
| 955 | final ArrayList<ActivityRecord> activities = mTaskHistory.get(taskNdx).mActivities; |
| 956 | for (int activityNdx = activities.size() - 1; activityNdx >= 0; --activityNdx) { |
| 957 | activities.get(activityNdx).setSleeping(false); |
| 958 | } |
Dianne Hackborn | 4eba96b | 2011-01-21 13:34:36 -0800 | [diff] [blame] | 959 | } |
Craig Mautner | f49b0a4 | 2014-11-20 15:06:40 -0800 | [diff] [blame] | 960 | if (mPausingActivity != null) { |
| 961 | Slog.d(TAG, "awakeFromSleepingLocked: previously pausing activity didn't pause"); |
| 962 | activityPausedLocked(mPausingActivity.appToken, true); |
| 963 | } |
Dianne Hackborn | 4eba96b | 2011-01-21 13:34:36 -0800 | [diff] [blame] | 964 | } |
| 965 | |
Todd Kennedy | 39bfee5 | 2016-02-24 10:28:21 -0800 | [diff] [blame] | 966 | void updateActivityApplicationInfoLocked(ApplicationInfo aInfo) { |
| 967 | final String packageName = aInfo.packageName; |
| 968 | for (int taskNdx = mTaskHistory.size() - 1; taskNdx >= 0; --taskNdx) { |
| 969 | final List<ActivityRecord> activities = mTaskHistory.get(taskNdx).mActivities; |
| 970 | for (int activityNdx = activities.size() - 1; activityNdx >= 0; --activityNdx) { |
| 971 | if (packageName.equals(activities.get(activityNdx).packageName)) { |
| 972 | activities.get(activityNdx).info.applicationInfo = aInfo; |
| 973 | } |
| 974 | } |
| 975 | } |
| 976 | } |
| 977 | |
Craig Mautner | 0eea92c | 2013-05-16 13:35:39 -0700 | [diff] [blame] | 978 | /** |
| 979 | * @return true if something must be done before going to sleep. |
| 980 | */ |
| 981 | boolean checkReadyForSleepLocked() { |
| 982 | if (mResumedActivity != null) { |
| 983 | // Still have something resumed; can't sleep until it is paused. |
Wale Ogunwale | ee006da | 2015-03-30 14:49:25 -0700 | [diff] [blame] | 984 | if (DEBUG_PAUSE) Slog.v(TAG_PAUSE, "Sleep needs to pause " + mResumedActivity); |
| 985 | if (DEBUG_USER_LEAVING) Slog.v(TAG_USER_LEAVING, |
| 986 | "Sleep => pause with userLeaving=false"); |
Dianne Hackborn | a4e102e | 2014-09-04 22:52:27 -0700 | [diff] [blame] | 987 | startPausingLocked(false, true, false, false); |
Craig Mautner | 0eea92c | 2013-05-16 13:35:39 -0700 | [diff] [blame] | 988 | return true; |
| 989 | } |
| 990 | if (mPausingActivity != null) { |
| 991 | // Still waiting for something to pause; can't sleep yet. |
Wale Ogunwale | ee006da | 2015-03-30 14:49:25 -0700 | [diff] [blame] | 992 | 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] | 993 | return true; |
Dianne Hackborn | 4eba96b | 2011-01-21 13:34:36 -0800 | [diff] [blame] | 994 | } |
| 995 | |
Wale Ogunwale | 5c42e50 | 2015-04-08 09:18:54 -0700 | [diff] [blame] | 996 | if (hasVisibleBehindActivity()) { |
| 997 | // Stop visible behind activity before going to sleep. |
Wale Ogunwale | 1f544be | 2015-12-17 10:27:23 -0800 | [diff] [blame] | 998 | final ActivityRecord r = getVisibleBehindActivity(); |
Wale Ogunwale | 5c42e50 | 2015-04-08 09:18:54 -0700 | [diff] [blame] | 999 | mStackSupervisor.mStoppingActivities.add(r); |
Wale Ogunwale | 1f544be | 2015-12-17 10:27:23 -0800 | [diff] [blame] | 1000 | 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] | 1001 | return true; |
| 1002 | } |
| 1003 | |
Craig Mautner | 0eea92c | 2013-05-16 13:35:39 -0700 | [diff] [blame] | 1004 | return false; |
| 1005 | } |
Dianne Hackborn | 4eba96b | 2011-01-21 13:34:36 -0800 | [diff] [blame] | 1006 | |
Craig Mautner | 0eea92c | 2013-05-16 13:35:39 -0700 | [diff] [blame] | 1007 | void goToSleep() { |
Filip Gruszczynski | bc5a6c5 | 2015-09-22 13:13:24 -0700 | [diff] [blame] | 1008 | ensureActivitiesVisibleLocked(null, 0, !PRESERVE_WINDOWS); |
Dianne Hackborn | 4eba96b | 2011-01-21 13:34:36 -0800 | [diff] [blame] | 1009 | |
Andrii Kulian | f9949d5 | 2016-05-06 12:53:25 -0700 | [diff] [blame] | 1010 | // Make sure any paused or stopped but visible activities are now sleeping. |
Craig Mautner | 0eea92c | 2013-05-16 13:35:39 -0700 | [diff] [blame] | 1011 | // This ensures that the activity's onStop() is called. |
| 1012 | for (int taskNdx = mTaskHistory.size() - 1; taskNdx >= 0; --taskNdx) { |
| 1013 | final ArrayList<ActivityRecord> activities = mTaskHistory.get(taskNdx).mActivities; |
| 1014 | for (int activityNdx = activities.size() - 1; activityNdx >= 0; --activityNdx) { |
| 1015 | final ActivityRecord r = activities.get(activityNdx); |
Andrii Kulian | f9949d5 | 2016-05-06 12:53:25 -0700 | [diff] [blame] | 1016 | if (r.state == ActivityState.STOPPING || r.state == ActivityState.STOPPED |
| 1017 | || r.state == ActivityState.PAUSED || r.state == ActivityState.PAUSING) { |
Craig Mautner | 0eea92c | 2013-05-16 13:35:39 -0700 | [diff] [blame] | 1018 | r.setSleeping(true); |
Dianne Hackborn | 4eba96b | 2011-01-21 13:34:36 -0800 | [diff] [blame] | 1019 | } |
| 1020 | } |
Dianne Hackborn | 4eba96b | 2011-01-21 13:34:36 -0800 | [diff] [blame] | 1021 | } |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 1022 | } |
Craig Mautner | 59c0097 | 2012-07-30 12:10:24 -0700 | [diff] [blame] | 1023 | |
Winson | 8b1871d | 2015-11-20 09:56:20 -0800 | [diff] [blame] | 1024 | public final Bitmap screenshotActivitiesLocked(ActivityRecord who) { |
| 1025 | if (DEBUG_SCREENSHOTS) Slog.d(TAG_SCREENSHOTS, "screenshotActivitiesLocked: " + who); |
Dianne Hackborn | ff801ec | 2011-01-22 18:05:38 -0800 | [diff] [blame] | 1026 | if (who.noDisplay) { |
Wale Ogunwale | 0fc365c | 2015-05-25 19:35:42 -0700 | [diff] [blame] | 1027 | if (DEBUG_SCREENSHOTS) Slog.d(TAG_SCREENSHOTS, "\tNo display"); |
Dianne Hackborn | ff801ec | 2011-01-22 18:05:38 -0800 | [diff] [blame] | 1028 | return null; |
| 1029 | } |
Craig Mautner | aab647e | 2013-02-28 16:31:36 -0800 | [diff] [blame] | 1030 | |
Winson Chung | 083baf9 | 2014-07-11 10:32:42 -0700 | [diff] [blame] | 1031 | if (isHomeStack()) { |
Winson Chung | 376543b | 2014-05-21 17:43:28 -0700 | [diff] [blame] | 1032 | // 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] | 1033 | // 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] | 1034 | if (DEBUG_SCREENSHOTS) Slog.d(TAG_SCREENSHOTS, "\tHome stack"); |
Dianne Hackborn | 4d03fe6 | 2013-10-04 17:26:37 -0700 | [diff] [blame] | 1035 | return null; |
| 1036 | } |
| 1037 | |
Winson Chung | 48a10a5 | 2014-08-27 14:36:51 -0700 | [diff] [blame] | 1038 | int w = mService.mThumbnailWidth; |
| 1039 | int h = mService.mThumbnailHeight; |
Winson | 8b1871d | 2015-11-20 09:56:20 -0800 | [diff] [blame] | 1040 | float scale = 1f; |
Dianne Hackborn | 0aae2d4 | 2010-12-07 23:51:29 -0800 | [diff] [blame] | 1041 | if (w > 0) { |
Wale Ogunwale | 0fc365c | 2015-05-25 19:35:42 -0700 | [diff] [blame] | 1042 | if (DEBUG_SCREENSHOTS) Slog.d(TAG_SCREENSHOTS, "\tTaking screenshot"); |
Winson | 8b1871d | 2015-11-20 09:56:20 -0800 | [diff] [blame] | 1043 | |
| 1044 | // 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] | 1045 | // but scaled to half the size. This gives us a "good-enough" fullscreen thumbnail to |
| 1046 | // use within SystemUI while keeping memory usage low. |
Winson Chung | ead5c0f | 2015-12-14 11:18:57 -0500 | [diff] [blame] | 1047 | if (ActivityManagerService.TAKE_FULLSCREEN_SCREENSHOTS) { |
Winson | 8b1871d | 2015-11-20 09:56:20 -0800 | [diff] [blame] | 1048 | w = h = -1; |
Winson | 2170093 | 2016-03-24 17:26:23 -0700 | [diff] [blame] | 1049 | scale = mService.mFullscreenThumbnailScale; |
Winson | 8b1871d | 2015-11-20 09:56:20 -0800 | [diff] [blame] | 1050 | } |
Wale Ogunwale | eacdf2c | 2014-12-09 14:02:27 -0800 | [diff] [blame] | 1051 | return mWindowManager.screenshotApplications(who.appToken, Display.DEFAULT_DISPLAY, |
Winson | 8b1871d | 2015-11-20 09:56:20 -0800 | [diff] [blame] | 1052 | w, h, scale); |
Dianne Hackborn | 0aae2d4 | 2010-12-07 23:51:29 -0800 | [diff] [blame] | 1053 | } |
Winson Chung | 376543b | 2014-05-21 17:43:28 -0700 | [diff] [blame] | 1054 | Slog.e(TAG, "Invalid thumbnail dimensions: " + w + "x" + h); |
Dianne Hackborn | 0aae2d4 | 2010-12-07 23:51:29 -0800 | [diff] [blame] | 1055 | return null; |
| 1056 | } |
| 1057 | |
Dianne Hackborn | a4e102e | 2014-09-04 22:52:27 -0700 | [diff] [blame] | 1058 | /** |
| 1059 | * Start pausing the currently resumed activity. It is an error to call this if there |
| 1060 | * is already an activity being paused or there is no resumed activity. |
| 1061 | * |
| 1062 | * @param userLeaving True if this should result in an onUserLeaving to the current activity. |
| 1063 | * @param uiSleeping True if this is happening with the user interface going to sleep (the |
| 1064 | * screen turning off). |
| 1065 | * @param resuming True if this is being called as part of resuming the top activity, so |
| 1066 | * we shouldn't try to instigate a resume here. |
| 1067 | * @param dontWait True if the caller does not want to wait for the pause to complete. If |
| 1068 | * set to true, we will immediately complete the pause here before returning. |
| 1069 | * @return Returns true if an activity now is in the PAUSING state, and we are waiting for |
| 1070 | * it to tell us when it is done. |
| 1071 | */ |
| 1072 | final boolean startPausingLocked(boolean userLeaving, boolean uiSleeping, boolean resuming, |
| 1073 | boolean dontWait) { |
Dianne Hackborn | 621e2fe | 2012-02-16 17:07:33 -0800 | [diff] [blame] | 1074 | if (mPausingActivity != null) { |
riddle_hsu | 7dfe4d7 | 2015-02-16 18:43:49 +0800 | [diff] [blame] | 1075 | Slog.wtf(TAG, "Going to pause when pause is already pending for " + mPausingActivity |
| 1076 | + " state=" + mPausingActivity.state); |
Fyodor Kupolov | 9b80b94 | 2016-06-16 16:29:05 -0700 | [diff] [blame] | 1077 | if (!mService.isSleepingLocked()) { |
riddle_hsu | 7dfe4d7 | 2015-02-16 18:43:49 +0800 | [diff] [blame] | 1078 | // Avoid recursion among check for sleep and complete pause during sleeping. |
| 1079 | // Because activity will be paused immediately after resume, just let pause |
| 1080 | // be completed by the order of activity paused from clients. |
| 1081 | completePauseLocked(false); |
| 1082 | } |
Dianne Hackborn | 621e2fe | 2012-02-16 17:07:33 -0800 | [diff] [blame] | 1083 | } |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 1084 | ActivityRecord prev = mResumedActivity; |
| 1085 | if (prev == null) { |
Dianne Hackborn | a4e102e | 2014-09-04 22:52:27 -0700 | [diff] [blame] | 1086 | if (!resuming) { |
| 1087 | Slog.wtf(TAG, "Trying to pause when nothing is resumed"); |
Wale Ogunwale | d046a01 | 2015-12-24 13:05:59 -0800 | [diff] [blame] | 1088 | mStackSupervisor.resumeFocusedStackTopActivityLocked(); |
Dianne Hackborn | a4e102e | 2014-09-04 22:52:27 -0700 | [diff] [blame] | 1089 | } |
| 1090 | return false; |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 1091 | } |
Craig Mautner | df88d73 | 2014-01-27 09:21:32 -0800 | [diff] [blame] | 1092 | |
| 1093 | if (mActivityContainer.mParentActivity == null) { |
| 1094 | // Top level stack, not a child. Look for child stacks. |
Dianne Hackborn | a4e102e | 2014-09-04 22:52:27 -0700 | [diff] [blame] | 1095 | mStackSupervisor.pauseChildStacks(prev, userLeaving, uiSleeping, resuming, dontWait); |
Craig Mautner | df88d73 | 2014-01-27 09:21:32 -0800 | [diff] [blame] | 1096 | } |
| 1097 | |
Wale Ogunwale | 0fc365c | 2015-05-25 19:35:42 -0700 | [diff] [blame] | 1098 | if (DEBUG_STATES) Slog.v(TAG_STATES, "Moving to PAUSING: " + prev); |
Wale Ogunwale | ee006da | 2015-03-30 14:49:25 -0700 | [diff] [blame] | 1099 | else if (DEBUG_PAUSE) Slog.v(TAG_PAUSE, "Start pausing: " + prev); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 1100 | mResumedActivity = null; |
Dianne Hackborn | 621e2fe | 2012-02-16 17:07:33 -0800 | [diff] [blame] | 1101 | mPausingActivity = prev; |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 1102 | mLastPausedActivity = prev; |
Craig Mautner | 0f92274 | 2013-08-06 08:44:42 -0700 | [diff] [blame] | 1103 | mLastNoHistoryActivity = (prev.intent.getFlags() & Intent.FLAG_ACTIVITY_NO_HISTORY) != 0 |
| 1104 | || (prev.info.flags & ActivityInfo.FLAG_NO_HISTORY) != 0 ? prev : null; |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 1105 | prev.state = ActivityState.PAUSING; |
| 1106 | prev.task.touchActiveTime(); |
Dianne Hackborn | 2286cdc | 2013-07-01 19:10:06 -0700 | [diff] [blame] | 1107 | clearLaunchTime(prev); |
Craig Mautner | 6f6d56f | 2013-10-24 16:02:07 -0700 | [diff] [blame] | 1108 | final ActivityRecord next = mStackSupervisor.topRunningActivityLocked(); |
Wale Ogunwale | 979f5ed | 2015-10-12 11:22:50 -0700 | [diff] [blame] | 1109 | if (mService.mHasRecents |
| 1110 | && (next == null || next.noDisplay || next.task != prev.task || uiSleeping)) { |
Jorim Jaggi | c2f262b | 2015-12-07 16:59:10 -0800 | [diff] [blame] | 1111 | prev.mUpdateTaskThumbnailWhenHidden = true; |
Craig Mautner | 6f6d56f | 2013-10-24 16:02:07 -0700 | [diff] [blame] | 1112 | } |
Dianne Hackborn | cee04b5 | 2013-07-03 17:01:28 -0700 | [diff] [blame] | 1113 | stopFullyDrawnTraceIfNeeded(); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 1114 | |
| 1115 | mService.updateCpuStats(); |
Craig Mautner | aab647e | 2013-02-28 16:31:36 -0800 | [diff] [blame] | 1116 | |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 1117 | if (prev.app != null && prev.app.thread != null) { |
Wale Ogunwale | ee006da | 2015-03-30 14:49:25 -0700 | [diff] [blame] | 1118 | if (DEBUG_PAUSE) Slog.v(TAG_PAUSE, "Enqueueing pending pause: " + prev); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 1119 | try { |
| 1120 | EventLog.writeEvent(EventLogTags.AM_PAUSE_ACTIVITY, |
Dianne Hackborn | b12e135 | 2012-09-26 11:39:20 -0700 | [diff] [blame] | 1121 | prev.userId, System.identityHashCode(prev), |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 1122 | prev.shortComponentName); |
Jeff Sharkey | 5782da7 | 2013-04-25 14:32:30 -0700 | [diff] [blame] | 1123 | mService.updateUsageStats(prev, false); |
Dianne Hackborn | be70785 | 2011-11-11 14:32:10 -0800 | [diff] [blame] | 1124 | prev.app.thread.schedulePauseActivity(prev.appToken, prev.finishing, |
Dianne Hackborn | a4e102e | 2014-09-04 22:52:27 -0700 | [diff] [blame] | 1125 | userLeaving, prev.configChangeFlags, dontWait); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 1126 | } catch (Exception e) { |
| 1127 | // Ignore exception, if process died other code will cleanup. |
| 1128 | Slog.w(TAG, "Exception thrown during pause", e); |
Dianne Hackborn | 621e2fe | 2012-02-16 17:07:33 -0800 | [diff] [blame] | 1129 | mPausingActivity = null; |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 1130 | mLastPausedActivity = null; |
Craig Mautner | 0f92274 | 2013-08-06 08:44:42 -0700 | [diff] [blame] | 1131 | mLastNoHistoryActivity = null; |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 1132 | } |
| 1133 | } else { |
Dianne Hackborn | 621e2fe | 2012-02-16 17:07:33 -0800 | [diff] [blame] | 1134 | mPausingActivity = null; |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 1135 | mLastPausedActivity = null; |
Craig Mautner | 0f92274 | 2013-08-06 08:44:42 -0700 | [diff] [blame] | 1136 | mLastNoHistoryActivity = null; |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 1137 | } |
| 1138 | |
| 1139 | // If we are not going to sleep, we want to ensure the device is |
| 1140 | // awake until the next activity is started. |
Fyodor Kupolov | 9b80b94 | 2016-06-16 16:29:05 -0700 | [diff] [blame] | 1141 | if (!uiSleeping && !mService.isSleepingOrShuttingDownLocked()) { |
Craig Mautner | 7ea5bd4 | 2013-07-05 15:27:08 -0700 | [diff] [blame] | 1142 | mStackSupervisor.acquireLaunchWakelock(); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 1143 | } |
| 1144 | |
Dianne Hackborn | 621e2fe | 2012-02-16 17:07:33 -0800 | [diff] [blame] | 1145 | if (mPausingActivity != null) { |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 1146 | // Have the window manager pause its key dispatching until the new |
| 1147 | // activity has started. If we're pausing the activity just because |
| 1148 | // the screen is being turned off and the UI is sleeping, don't interrupt |
| 1149 | // key dispatch; the same activity will pick it up again on wakeup. |
| 1150 | if (!uiSleeping) { |
Dianne Hackborn | 621e2fe | 2012-02-16 17:07:33 -0800 | [diff] [blame] | 1151 | prev.pauseKeyDispatchingLocked(); |
Wale Ogunwale | ee006da | 2015-03-30 14:49:25 -0700 | [diff] [blame] | 1152 | } else if (DEBUG_PAUSE) { |
| 1153 | Slog.v(TAG_PAUSE, "Key dispatch not paused for screen off"); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 1154 | } |
| 1155 | |
Dianne Hackborn | a4e102e | 2014-09-04 22:52:27 -0700 | [diff] [blame] | 1156 | if (dontWait) { |
| 1157 | // If the caller said they don't want to wait for the pause, then complete |
| 1158 | // the pause now. |
| 1159 | completePauseLocked(false); |
| 1160 | return false; |
| 1161 | |
| 1162 | } else { |
| 1163 | // Schedule a pause timeout in case the app doesn't respond. |
| 1164 | // We don't give it much time because this directly impacts the |
| 1165 | // responsiveness seen by the user. |
| 1166 | Message msg = mHandler.obtainMessage(PAUSE_TIMEOUT_MSG); |
| 1167 | msg.obj = prev; |
| 1168 | prev.pauseTime = SystemClock.uptimeMillis(); |
| 1169 | mHandler.sendMessageDelayed(msg, PAUSE_TIMEOUT); |
Wale Ogunwale | ee006da | 2015-03-30 14:49:25 -0700 | [diff] [blame] | 1170 | if (DEBUG_PAUSE) Slog.v(TAG_PAUSE, "Waiting for pause to complete..."); |
Dianne Hackborn | a4e102e | 2014-09-04 22:52:27 -0700 | [diff] [blame] | 1171 | return true; |
| 1172 | } |
| 1173 | |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 1174 | } else { |
| 1175 | // This activity failed to schedule the |
| 1176 | // pause, so just treat it as being paused now. |
Wale Ogunwale | ee006da | 2015-03-30 14:49:25 -0700 | [diff] [blame] | 1177 | if (DEBUG_PAUSE) Slog.v(TAG_PAUSE, "Activity not running, resuming next."); |
Dianne Hackborn | a4e102e | 2014-09-04 22:52:27 -0700 | [diff] [blame] | 1178 | if (!resuming) { |
Wale Ogunwale | d046a01 | 2015-12-24 13:05:59 -0800 | [diff] [blame] | 1179 | mStackSupervisor.resumeFocusedStackTopActivityLocked(); |
Dianne Hackborn | a4e102e | 2014-09-04 22:52:27 -0700 | [diff] [blame] | 1180 | } |
| 1181 | return false; |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 1182 | } |
| 1183 | } |
Dianne Hackborn | ad9b3211 | 2012-09-17 15:35:01 -0700 | [diff] [blame] | 1184 | |
Dianne Hackborn | a4e102e | 2014-09-04 22:52:27 -0700 | [diff] [blame] | 1185 | final void activityPausedLocked(IBinder token, boolean timeout) { |
Wale Ogunwale | ee006da | 2015-03-30 14:49:25 -0700 | [diff] [blame] | 1186 | if (DEBUG_PAUSE) Slog.v(TAG_PAUSE, |
| 1187 | "Activity paused: token=" + token + ", timeout=" + timeout); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 1188 | |
Craig Mautner | d232895 | 2013-03-05 12:46:26 -0800 | [diff] [blame] | 1189 | final ActivityRecord r = isInStackLocked(token); |
| 1190 | if (r != null) { |
| 1191 | mHandler.removeMessages(PAUSE_TIMEOUT_MSG, r); |
| 1192 | if (mPausingActivity == r) { |
Wale Ogunwale | 0fc365c | 2015-05-25 19:35:42 -0700 | [diff] [blame] | 1193 | if (DEBUG_STATES) Slog.v(TAG_STATES, "Moving to PAUSED: " + r |
Craig Mautner | d232895 | 2013-03-05 12:46:26 -0800 | [diff] [blame] | 1194 | + (timeout ? " (due to timeout)" : " (pause complete)")); |
Dianne Hackborn | a4e102e | 2014-09-04 22:52:27 -0700 | [diff] [blame] | 1195 | completePauseLocked(true); |
Wale Ogunwale | 5658e4b | 2016-02-12 12:22:19 -0800 | [diff] [blame] | 1196 | return; |
Craig Mautner | d232895 | 2013-03-05 12:46:26 -0800 | [diff] [blame] | 1197 | } else { |
| 1198 | EventLog.writeEvent(EventLogTags.AM_FAILED_TO_PAUSE, |
| 1199 | r.userId, System.identityHashCode(r), r.shortComponentName, |
| 1200 | mPausingActivity != null |
| 1201 | ? mPausingActivity.shortComponentName : "(none)"); |
riddle_hsu | 9caeef7 | 2015-10-20 16:34:05 +0800 | [diff] [blame] | 1202 | if (r.state == ActivityState.PAUSING) { |
| 1203 | r.state = ActivityState.PAUSED; |
| 1204 | if (r.finishing) { |
| 1205 | if (DEBUG_PAUSE) Slog.v(TAG, |
| 1206 | "Executing finish of failed to pause activity: " + r); |
| 1207 | finishCurrentActivityLocked(r, FINISH_AFTER_VISIBLE, false); |
| 1208 | } |
louis_chang | 047dfd4 | 2015-04-08 16:35:55 +0800 | [diff] [blame] | 1209 | } |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 1210 | } |
| 1211 | } |
Wale Ogunwale | 5658e4b | 2016-02-12 12:22:19 -0800 | [diff] [blame] | 1212 | mStackSupervisor.ensureActivitiesVisibleLocked(null, 0, !PRESERVE_WINDOWS); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 1213 | } |
| 1214 | |
Chong Zhang | d78ddb4 | 2016-03-02 17:01:14 -0800 | [diff] [blame] | 1215 | final void activityResumedLocked(IBinder token) { |
| 1216 | final ActivityRecord r = ActivityRecord.forTokenLocked(token); |
| 1217 | if (DEBUG_SAVED_STATE) Slog.i(TAG_STATES, "Resumed activity; dropping state of: " + r); |
| 1218 | r.icicle = null; |
| 1219 | r.haveState = false; |
| 1220 | } |
| 1221 | |
Craig Mautner | a002604 | 2014-04-23 11:45:37 -0700 | [diff] [blame] | 1222 | final void activityStoppedLocked(ActivityRecord r, Bundle icicle, |
| 1223 | PersistableBundle persistentState, CharSequence description) { |
Dianne Hackborn | b61a026 | 2012-05-14 17:19:18 -0700 | [diff] [blame] | 1224 | if (r.state != ActivityState.STOPPING) { |
| 1225 | Slog.i(TAG, "Activity reported stop, but no longer stopping: " + r); |
| 1226 | mHandler.removeMessages(STOP_TIMEOUT_MSG, r); |
| 1227 | return; |
| 1228 | } |
Craig Mautner | 21d24a2 | 2014-04-23 11:45:37 -0700 | [diff] [blame] | 1229 | if (persistentState != null) { |
| 1230 | r.persistentState = persistentState; |
| 1231 | mService.notifyTaskPersisterLocked(r.task, false); |
| 1232 | } |
Wale Ogunwale | 0fc365c | 2015-05-25 19:35:42 -0700 | [diff] [blame] | 1233 | 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] | 1234 | if (icicle != null) { |
| 1235 | // If icicle is null, this is happening due to a timeout, so we |
| 1236 | // haven't really saved the state. |
| 1237 | r.icicle = icicle; |
| 1238 | r.haveState = true; |
Dianne Hackborn | 0798149 | 2013-01-28 11:36:23 -0800 | [diff] [blame] | 1239 | r.launchCount = 0; |
Winson Chung | 740c3ac | 2014-11-12 16:14:38 -0800 | [diff] [blame] | 1240 | r.updateThumbnailLocked(null, description); |
Dianne Hackborn | 162bc0e | 2012-04-09 14:06:16 -0700 | [diff] [blame] | 1241 | } |
| 1242 | if (!r.stopped) { |
Wale Ogunwale | 0fc365c | 2015-05-25 19:35:42 -0700 | [diff] [blame] | 1243 | 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] | 1244 | mHandler.removeMessages(STOP_TIMEOUT_MSG, r); |
| 1245 | r.stopped = true; |
| 1246 | r.state = ActivityState.STOPPED; |
Robert Carr | e12aece | 2016-02-02 22:43:27 -0800 | [diff] [blame] | 1247 | |
Wale Ogunwale | 8d5a542 | 2016-03-03 18:28:21 -0800 | [diff] [blame] | 1248 | mWindowManager.notifyAppStopped(r.appToken, true); |
Robert Carr | e12aece | 2016-02-02 22:43:27 -0800 | [diff] [blame] | 1249 | |
Wale Ogunwale | 1f544be | 2015-12-17 10:27:23 -0800 | [diff] [blame] | 1250 | if (getVisibleBehindActivity() == r) { |
Jose Lima | 4b6c669 | 2014-08-12 17:41:12 -0700 | [diff] [blame] | 1251 | mStackSupervisor.requestVisibleBehindLocked(r, false); |
Craig Mautner | ee2e45a | 2014-06-27 12:10:03 -0700 | [diff] [blame] | 1252 | } |
Dianne Hackborn | 6e3d6da | 2012-06-15 12:05:27 -0700 | [diff] [blame] | 1253 | if (r.finishing) { |
| 1254 | r.clearOptionsLocked(); |
| 1255 | } else { |
Wale Ogunwale | f81c1d1 | 2016-01-12 12:20:18 -0800 | [diff] [blame] | 1256 | if (r.deferRelaunchUntilPaused) { |
Craig Mautner | ee2e45a | 2014-06-27 12:10:03 -0700 | [diff] [blame] | 1257 | destroyActivityLocked(r, true, "stop-config"); |
Wale Ogunwale | d046a01 | 2015-12-24 13:05:59 -0800 | [diff] [blame] | 1258 | mStackSupervisor.resumeFocusedStackTopActivityLocked(); |
Dianne Hackborn | 162bc0e | 2012-04-09 14:06:16 -0700 | [diff] [blame] | 1259 | } else { |
Dianne Hackborn | a413dc0 | 2013-07-12 12:02:55 -0700 | [diff] [blame] | 1260 | mStackSupervisor.updatePreviousProcessLocked(r); |
Dianne Hackborn | 5068560 | 2011-12-01 12:23:37 -0800 | [diff] [blame] | 1261 | } |
Dianne Hackborn | ce86ba8 | 2011-07-13 19:33:41 -0700 | [diff] [blame] | 1262 | } |
| 1263 | } |
| 1264 | } |
| 1265 | |
Dianne Hackborn | a4e102e | 2014-09-04 22:52:27 -0700 | [diff] [blame] | 1266 | private void completePauseLocked(boolean resumeNext) { |
Dianne Hackborn | 621e2fe | 2012-02-16 17:07:33 -0800 | [diff] [blame] | 1267 | ActivityRecord prev = mPausingActivity; |
Wale Ogunwale | ee006da | 2015-03-30 14:49:25 -0700 | [diff] [blame] | 1268 | if (DEBUG_PAUSE) Slog.v(TAG_PAUSE, "Complete pause: " + prev); |
Craig Mautner | aab647e | 2013-02-28 16:31:36 -0800 | [diff] [blame] | 1269 | |
Dianne Hackborn | 621e2fe | 2012-02-16 17:07:33 -0800 | [diff] [blame] | 1270 | if (prev != null) { |
Filip Gruszczynski | dba623a | 2015-12-04 15:45:35 -0800 | [diff] [blame] | 1271 | final boolean wasStopping = prev.state == ActivityState.STOPPING; |
Dianne Hackborn | a4e102e | 2014-09-04 22:52:27 -0700 | [diff] [blame] | 1272 | prev.state = ActivityState.PAUSED; |
Dianne Hackborn | 621e2fe | 2012-02-16 17:07:33 -0800 | [diff] [blame] | 1273 | if (prev.finishing) { |
Wale Ogunwale | ee006da | 2015-03-30 14:49:25 -0700 | [diff] [blame] | 1274 | if (DEBUG_PAUSE) Slog.v(TAG_PAUSE, "Executing finish of activity: " + prev); |
Dianne Hackborn | 2d1b378 | 2012-09-09 17:49:39 -0700 | [diff] [blame] | 1275 | prev = finishCurrentActivityLocked(prev, FINISH_AFTER_VISIBLE, false); |
Dianne Hackborn | 621e2fe | 2012-02-16 17:07:33 -0800 | [diff] [blame] | 1276 | } else if (prev.app != null) { |
Wale Ogunwale | d802664 | 2016-02-09 20:40:18 -0800 | [diff] [blame] | 1277 | if (DEBUG_PAUSE) Slog.v(TAG_PAUSE, "Enqueue pending stop if needed: " + prev |
| 1278 | + " wasStopping=" + wasStopping + " visible=" + prev.visible); |
Craig Mautner | 8c14c15 | 2015-01-15 17:32:07 -0800 | [diff] [blame] | 1279 | if (mStackSupervisor.mWaitingVisibleActivities.remove(prev)) { |
Wale Ogunwale | ee006da | 2015-03-30 14:49:25 -0700 | [diff] [blame] | 1280 | if (DEBUG_SWITCH || DEBUG_PAUSE) Slog.v(TAG_PAUSE, |
| 1281 | "Complete pause, no longer waiting: " + prev); |
Dianne Hackborn | cbb722e | 2012-02-07 18:33:49 -0800 | [diff] [blame] | 1282 | } |
Wale Ogunwale | f81c1d1 | 2016-01-12 12:20:18 -0800 | [diff] [blame] | 1283 | if (prev.deferRelaunchUntilPaused) { |
| 1284 | // Complete the deferred relaunch that was waiting for pause to complete. |
| 1285 | if (DEBUG_PAUSE) Slog.v(TAG_PAUSE, "Re-launching after pause: " + prev); |
| 1286 | relaunchActivityLocked(prev, prev.configChangeFlags, false, |
| 1287 | prev.preserveWindowOnDeferredRelaunch); |
Filip Gruszczynski | dba623a | 2015-12-04 15:45:35 -0800 | [diff] [blame] | 1288 | } else if (wasStopping) { |
| 1289 | // We are also stopping, the stop request must have gone soon after the pause. |
| 1290 | // We can't clobber it, because the stop confirmation will not be handled. |
| 1291 | // We don't need to schedule another stop, we only need to let it happen. |
| 1292 | prev.state = ActivityState.STOPPING; |
Wale Ogunwale | d802664 | 2016-02-09 20:40:18 -0800 | [diff] [blame] | 1293 | } else if ((!prev.visible && !hasVisibleBehindActivity()) |
Fyodor Kupolov | 9b80b94 | 2016-06-16 16:29:05 -0700 | [diff] [blame] | 1294 | || mService.isSleepingOrShuttingDownLocked()) { |
Jose Lima | 4b6c669 | 2014-08-12 17:41:12 -0700 | [diff] [blame] | 1295 | // If we were visible then resumeTopActivities will release resources before |
Craig Mautner | ee2e45a | 2014-06-27 12:10:03 -0700 | [diff] [blame] | 1296 | // stopping. |
Chong Zhang | 46b1ac6 | 2016-02-18 17:53:57 -0800 | [diff] [blame] | 1297 | addToStopping(prev, true /* immediate */); |
Dianne Hackborn | 621e2fe | 2012-02-16 17:07:33 -0800 | [diff] [blame] | 1298 | } |
| 1299 | } else { |
Wale Ogunwale | ee006da | 2015-03-30 14:49:25 -0700 | [diff] [blame] | 1300 | 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] | 1301 | prev = null; |
Dianne Hackborn | cbb722e | 2012-02-07 18:33:49 -0800 | [diff] [blame] | 1302 | } |
Wale Ogunwale | 07927bf | 2015-03-28 17:21:05 -0700 | [diff] [blame] | 1303 | // It is possible the activity was freezing the screen before it was paused. |
| 1304 | // In that case go ahead and remove the freeze this activity has on the screen |
| 1305 | // since it is no longer visible. |
| 1306 | prev.stopFreezingScreenLocked(true /*force*/); |
Dianne Hackborn | 621e2fe | 2012-02-16 17:07:33 -0800 | [diff] [blame] | 1307 | mPausingActivity = null; |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 1308 | } |
Dianne Hackborn | cbb722e | 2012-02-07 18:33:49 -0800 | [diff] [blame] | 1309 | |
Dianne Hackborn | a4e102e | 2014-09-04 22:52:27 -0700 | [diff] [blame] | 1310 | if (resumeNext) { |
| 1311 | final ActivityStack topStack = mStackSupervisor.getFocusedStack(); |
Fyodor Kupolov | 9b80b94 | 2016-06-16 16:29:05 -0700 | [diff] [blame] | 1312 | if (!mService.isSleepingOrShuttingDownLocked()) { |
Wale Ogunwale | d046a01 | 2015-12-24 13:05:59 -0800 | [diff] [blame] | 1313 | mStackSupervisor.resumeFocusedStackTopActivityLocked(topStack, prev, null); |
Dianne Hackborn | a4e102e | 2014-09-04 22:52:27 -0700 | [diff] [blame] | 1314 | } else { |
| 1315 | mStackSupervisor.checkReadyForSleepLocked(); |
Filip Gruszczynski | 3e85ba2 | 2015-10-05 22:48:30 -0700 | [diff] [blame] | 1316 | ActivityRecord top = topStack.topRunningActivityLocked(); |
Dianne Hackborn | a4e102e | 2014-09-04 22:52:27 -0700 | [diff] [blame] | 1317 | if (top == null || (prev != null && top != prev)) { |
Wale Ogunwale | d046a01 | 2015-12-24 13:05:59 -0800 | [diff] [blame] | 1318 | // If there are no more activities available to run, do resume anyway to start |
| 1319 | // something. Also if the top activity on the stack is not the just paused |
| 1320 | // activity, we need to go ahead and resume it to ensure we complete an |
| 1321 | // in-flight app switch. |
| 1322 | mStackSupervisor.resumeFocusedStackTopActivityLocked(); |
Dianne Hackborn | a4e102e | 2014-09-04 22:52:27 -0700 | [diff] [blame] | 1323 | } |
Dianne Hackborn | 42e620c | 2012-06-24 13:20:51 -0700 | [diff] [blame] | 1324 | } |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 1325 | } |
Craig Mautner | aab647e | 2013-02-28 16:31:36 -0800 | [diff] [blame] | 1326 | |
Dianne Hackborn | 621e2fe | 2012-02-16 17:07:33 -0800 | [diff] [blame] | 1327 | if (prev != null) { |
| 1328 | prev.resumeKeyDispatchingLocked(); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 1329 | |
Craig Mautner | 525f3d9 | 2013-05-07 14:01:50 -0700 | [diff] [blame] | 1330 | if (prev.app != null && prev.cpuTimeAtResume > 0 |
| 1331 | && mService.mBatteryStatsService.isOnBattery()) { |
Dianne Hackborn | 652973f | 2014-09-10 17:08:48 -0700 | [diff] [blame] | 1332 | long diff = mService.mProcessCpuTracker.getCpuTimeForPid(prev.app.pid) |
| 1333 | - prev.cpuTimeAtResume; |
Craig Mautner | 525f3d9 | 2013-05-07 14:01:50 -0700 | [diff] [blame] | 1334 | if (diff > 0) { |
| 1335 | BatteryStatsImpl bsi = mService.mBatteryStatsService.getActiveStatistics(); |
| 1336 | synchronized (bsi) { |
| 1337 | BatteryStatsImpl.Uid.Proc ps = |
| 1338 | bsi.getProcessStatsLocked(prev.info.applicationInfo.uid, |
Dianne Hackborn | d293224 | 2013-08-05 18:18:42 -0700 | [diff] [blame] | 1339 | prev.info.packageName); |
Craig Mautner | 525f3d9 | 2013-05-07 14:01:50 -0700 | [diff] [blame] | 1340 | if (ps != null) { |
| 1341 | ps.addForegroundTimeLocked(diff); |
| 1342 | } |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 1343 | } |
| 1344 | } |
| 1345 | } |
Craig Mautner | 525f3d9 | 2013-05-07 14:01:50 -0700 | [diff] [blame] | 1346 | prev.cpuTimeAtResume = 0; // reset it |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 1347 | } |
Winson Chung | 740c3ac | 2014-11-12 16:14:38 -0800 | [diff] [blame] | 1348 | |
Andrii Kulian | 8290f8f | 2016-06-30 17:51:32 -0700 | [diff] [blame] | 1349 | // Notify when the task stack has changed, but only if visibilities changed (not just |
| 1350 | // focus). Also if there is an active pinned stack - we always want to notify it about |
| 1351 | // task stack changes, because its positioning may depend on it. |
| 1352 | if (mStackSupervisor.mAppVisibilitiesChangedSinceLastPause |
| 1353 | || mService.mStackSupervisor.getStack(PINNED_STACK_ID) != null) { |
Jorim Jaggi | a0fdeec | 2016-01-07 14:42:28 +0100 | [diff] [blame] | 1354 | mService.notifyTaskStackChangedLocked(); |
| 1355 | mStackSupervisor.mAppVisibilitiesChangedSinceLastPause = false; |
| 1356 | } |
Wale Ogunwale | 5658e4b | 2016-02-12 12:22:19 -0800 | [diff] [blame] | 1357 | |
| 1358 | mStackSupervisor.ensureActivitiesVisibleLocked(null, 0, !PRESERVE_WINDOWS); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 1359 | } |
| 1360 | |
Chong Zhang | 46b1ac6 | 2016-02-18 17:53:57 -0800 | [diff] [blame] | 1361 | private void addToStopping(ActivityRecord r, boolean immediate) { |
| 1362 | if (!mStackSupervisor.mStoppingActivities.contains(r)) { |
| 1363 | mStackSupervisor.mStoppingActivities.add(r); |
| 1364 | } |
| 1365 | |
| 1366 | // If we already have a few activities waiting to stop, then give up |
| 1367 | // on things going idle and start clearing them out. Or if r is the |
| 1368 | // last of activity of the last task the stack will be empty and must |
| 1369 | // be cleared immediately. |
| 1370 | boolean forceIdle = mStackSupervisor.mStoppingActivities.size() > MAX_STOPPING_TO_FORCE |
| 1371 | || (r.frontOfTask && mTaskHistory.size() <= 1); |
| 1372 | |
| 1373 | if (immediate || forceIdle) { |
| 1374 | if (DEBUG_PAUSE) Slog.v(TAG_PAUSE, "Scheduling idle now: forceIdle=" |
| 1375 | + forceIdle + "immediate=" + immediate); |
Filip Gruszczynski | ef2f72b | 2015-12-04 14:52:25 -0800 | [diff] [blame] | 1376 | mStackSupervisor.scheduleIdleLocked(); |
| 1377 | } else { |
| 1378 | mStackSupervisor.checkReadyForSleepLocked(); |
| 1379 | } |
| 1380 | } |
| 1381 | |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 1382 | /** |
| 1383 | * Once we know that we have asked an application to put an activity in |
| 1384 | * the resumed state (either by launching it or explicitly telling it), |
| 1385 | * this function updates the rest of our state to match that fact. |
| 1386 | */ |
Craig Mautner | 525f3d9 | 2013-05-07 14:01:50 -0700 | [diff] [blame] | 1387 | private void completeResumeLocked(ActivityRecord next) { |
Chong Zhang | 2b79af1 | 2016-02-10 18:47:06 -0800 | [diff] [blame] | 1388 | next.visible = true; |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 1389 | next.idle = false; |
| 1390 | next.results = null; |
| 1391 | next.newIntents = null; |
Chong Zhang | 2b79af1 | 2016-02-10 18:47:06 -0800 | [diff] [blame] | 1392 | next.stopped = false; |
Craig Mautner | f33f4d7 | 2014-07-16 17:25:48 +0000 | [diff] [blame] | 1393 | |
Chong Zhang | 85ee654 | 2015-10-02 13:36:38 -0700 | [diff] [blame] | 1394 | if (next.isHomeActivity()) { |
Craig Mautner | f33f4d7 | 2014-07-16 17:25:48 +0000 | [diff] [blame] | 1395 | ProcessRecord app = next.task.mActivities.get(0).app; |
| 1396 | if (app != null && app != mService.mHomeProcess) { |
| 1397 | mService.mHomeProcess = app; |
| 1398 | } |
| 1399 | } |
| 1400 | |
Craig Mautner | 0756632 | 2013-09-26 16:42:55 -0700 | [diff] [blame] | 1401 | if (next.nowVisible) { |
| 1402 | // We won't get a call to reportActivityVisibleLocked() so dismiss lockscreen now. |
Chong Zhang | 5022da3 | 2016-06-21 16:31:37 -0700 | [diff] [blame] | 1403 | mStackSupervisor.reportActivityVisibleLocked(next); |
Jorim Jaggi | 8de4311c | 2014-08-11 22:36:20 +0200 | [diff] [blame] | 1404 | mStackSupervisor.notifyActivityDrawnForKeyguard(); |
Craig Mautner | 0756632 | 2013-09-26 16:42:55 -0700 | [diff] [blame] | 1405 | } |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 1406 | |
| 1407 | // 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] | 1408 | mStackSupervisor.scheduleIdleTimeoutLocked(next); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 1409 | |
Craig Mautner | ce5f3cb | 2013-04-22 08:58:54 -0700 | [diff] [blame] | 1410 | mStackSupervisor.reportResumedActivityLocked(next); |
| 1411 | |
| 1412 | next.resumeKeyDispatchingLocked(); |
| 1413 | mNoAnimActivities.clear(); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 1414 | |
| 1415 | // Mark the point when the activity is resuming |
| 1416 | // TODO: To be more accurate, the mark should be before the onCreate, |
| 1417 | // not after the onResume. But for subsequent starts, onResume is fine. |
| 1418 | if (next.app != null) { |
Dianne Hackborn | 652973f | 2014-09-10 17:08:48 -0700 | [diff] [blame] | 1419 | next.cpuTimeAtResume = mService.mProcessCpuTracker.getCpuTimeForPid(next.app.pid); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 1420 | } else { |
| 1421 | next.cpuTimeAtResume = 0; // Couldn't get the cpu time of process |
| 1422 | } |
Winson Chung | 376543b | 2014-05-21 17:43:28 -0700 | [diff] [blame] | 1423 | |
George Mount | 6ba042b | 2014-07-28 11:12:28 -0700 | [diff] [blame] | 1424 | next.returningOptions = null; |
Craig Mautner | 64ccb70 | 2014-10-01 09:38:40 -0700 | [diff] [blame] | 1425 | |
Wale Ogunwale | 1f544be | 2015-12-17 10:27:23 -0800 | [diff] [blame] | 1426 | if (getVisibleBehindActivity() == next) { |
Craig Mautner | 64ccb70 | 2014-10-01 09:38:40 -0700 | [diff] [blame] | 1427 | // When resuming an activity, require it to call requestVisibleBehind() again. |
Wale Ogunwale | 1f544be | 2015-12-17 10:27:23 -0800 | [diff] [blame] | 1428 | setVisibleBehindActivity(null); |
Craig Mautner | 64ccb70 | 2014-10-01 09:38:40 -0700 | [diff] [blame] | 1429 | } |
Chong Zhang | 6cda19c | 2016-06-14 19:07:56 -0700 | [diff] [blame] | 1430 | mStackSupervisor.checkReadyForSleepLocked(); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 1431 | } |
| 1432 | |
Craig Mautner | 2568c3a | 2015-03-26 14:22:34 -0700 | [diff] [blame] | 1433 | private void setVisible(ActivityRecord r, boolean visible) { |
Craig Mautner | e3a00d7 | 2014-04-16 08:31:19 -0700 | [diff] [blame] | 1434 | r.visible = visible; |
Jorim Jaggi | c2f262b | 2015-12-07 16:59:10 -0800 | [diff] [blame] | 1435 | if (!visible && r.mUpdateTaskThumbnailWhenHidden) { |
| 1436 | r.updateThumbnailLocked(r.task.stack.screenshotActivitiesLocked(r), null); |
| 1437 | r.mUpdateTaskThumbnailWhenHidden = false; |
| 1438 | } |
Craig Mautner | e3a00d7 | 2014-04-16 08:31:19 -0700 | [diff] [blame] | 1439 | mWindowManager.setAppVisibility(r.appToken, visible); |
Craig Mautner | f4c909b | 2014-04-17 18:39:38 -0700 | [diff] [blame] | 1440 | final ArrayList<ActivityContainer> containers = r.mChildContainers; |
Craig Mautner | e3a00d7 | 2014-04-16 08:31:19 -0700 | [diff] [blame] | 1441 | for (int containerNdx = containers.size() - 1; containerNdx >= 0; --containerNdx) { |
Craig Mautner | f4c909b | 2014-04-17 18:39:38 -0700 | [diff] [blame] | 1442 | ActivityContainer container = containers.get(containerNdx); |
Craig Mautner | e3a00d7 | 2014-04-16 08:31:19 -0700 | [diff] [blame] | 1443 | container.setVisible(visible); |
| 1444 | } |
Jorim Jaggi | a0fdeec | 2016-01-07 14:42:28 +0100 | [diff] [blame] | 1445 | mStackSupervisor.mAppVisibilitiesChangedSinceLastPause = true; |
Craig Mautner | e3a00d7 | 2014-04-16 08:31:19 -0700 | [diff] [blame] | 1446 | } |
| 1447 | |
Craig Mautner | fa387ad | 2014-08-05 11:16:41 -0700 | [diff] [blame] | 1448 | // Find the first visible activity above the passed activity and if it is translucent return it |
| 1449 | // otherwise return null; |
| 1450 | ActivityRecord findNextTranslucentActivity(ActivityRecord r) { |
| 1451 | TaskRecord task = r.task; |
| 1452 | if (task == null) { |
| 1453 | return null; |
| 1454 | } |
| 1455 | |
| 1456 | ActivityStack stack = task.stack; |
| 1457 | if (stack == null) { |
| 1458 | return null; |
| 1459 | } |
| 1460 | |
| 1461 | int stackNdx = mStacks.indexOf(stack); |
| 1462 | |
| 1463 | ArrayList<TaskRecord> tasks = stack.mTaskHistory; |
| 1464 | int taskNdx = tasks.indexOf(task); |
| 1465 | |
| 1466 | ArrayList<ActivityRecord> activities = task.mActivities; |
| 1467 | int activityNdx = activities.indexOf(r) + 1; |
| 1468 | |
| 1469 | final int numStacks = mStacks.size(); |
| 1470 | while (stackNdx < numStacks) { |
Wale Ogunwale | e4a0c57 | 2015-06-30 08:40:31 -0700 | [diff] [blame] | 1471 | final ActivityStack historyStack = mStacks.get(stackNdx); |
Todd Kennedy | aab56db | 2015-01-30 09:39:53 -0800 | [diff] [blame] | 1472 | tasks = historyStack.mTaskHistory; |
Craig Mautner | fa387ad | 2014-08-05 11:16:41 -0700 | [diff] [blame] | 1473 | final int numTasks = tasks.size(); |
| 1474 | while (taskNdx < numTasks) { |
Wale Ogunwale | e4a0c57 | 2015-06-30 08:40:31 -0700 | [diff] [blame] | 1475 | final TaskRecord currentTask = tasks.get(taskNdx); |
| 1476 | activities = currentTask.mActivities; |
Craig Mautner | fa387ad | 2014-08-05 11:16:41 -0700 | [diff] [blame] | 1477 | final int numActivities = activities.size(); |
| 1478 | while (activityNdx < numActivities) { |
| 1479 | final ActivityRecord activity = activities.get(activityNdx); |
| 1480 | if (!activity.finishing) { |
Wale Ogunwale | e4a0c57 | 2015-06-30 08:40:31 -0700 | [diff] [blame] | 1481 | return historyStack.mFullscreen |
| 1482 | && currentTask.mFullscreen && activity.fullscreen ? null : activity; |
Craig Mautner | fa387ad | 2014-08-05 11:16:41 -0700 | [diff] [blame] | 1483 | } |
| 1484 | ++activityNdx; |
| 1485 | } |
| 1486 | activityNdx = 0; |
| 1487 | ++taskNdx; |
| 1488 | } |
| 1489 | taskNdx = 0; |
| 1490 | ++stackNdx; |
| 1491 | } |
| 1492 | |
| 1493 | return null; |
| 1494 | } |
| 1495 | |
Wale Ogunwale | 4cea0f5 | 2015-12-25 06:30:31 -0800 | [diff] [blame] | 1496 | ActivityStack getNextFocusableStackLocked() { |
Wale Ogunwale | d697cea | 2015-02-20 17:19:49 -0800 | [diff] [blame] | 1497 | ArrayList<ActivityStack> stacks = mStacks; |
| 1498 | final ActivityRecord parent = mActivityContainer.mParentActivity; |
| 1499 | if (parent != null) { |
| 1500 | stacks = parent.task.stack.mStacks; |
| 1501 | } |
| 1502 | if (stacks != null) { |
| 1503 | for (int i = stacks.size() - 1; i >= 0; --i) { |
| 1504 | ActivityStack stack = stacks.get(i); |
Filip Gruszczynski | 0e381e2 | 2016-01-14 16:31:33 -0800 | [diff] [blame] | 1505 | if (stack != this && stack.isFocusable() |
Wale Ogunwale | 8051c5c | 2016-03-04 10:27:32 -0800 | [diff] [blame] | 1506 | && stack.getStackVisibilityLocked(null) != STACK_INVISIBLE) { |
Wale Ogunwale | d697cea | 2015-02-20 17:19:49 -0800 | [diff] [blame] | 1507 | return stack; |
| 1508 | } |
| 1509 | } |
| 1510 | } |
| 1511 | return null; |
| 1512 | } |
| 1513 | |
Wale Ogunwale | b34a7ad | 2015-08-14 11:05:30 -0700 | [diff] [blame] | 1514 | /** Returns true if the stack contains a fullscreen task. */ |
| 1515 | private boolean hasFullscreenTask() { |
| 1516 | for (int i = mTaskHistory.size() - 1; i >= 0; --i) { |
| 1517 | final TaskRecord task = mTaskHistory.get(i); |
| 1518 | if (task.mFullscreen) { |
| 1519 | return true; |
| 1520 | } |
| 1521 | } |
| 1522 | return false; |
| 1523 | } |
| 1524 | |
Wale Ogunwale | 8051c5c | 2016-03-04 10:27:32 -0800 | [diff] [blame] | 1525 | /** |
| 1526 | * Returns true if the stack is translucent and can have other contents visible behind it if |
| 1527 | * needed. A stack is considered translucent if it don't contain a visible or |
| 1528 | * starting (about to be visible) activity that is fullscreen (opaque). |
| 1529 | * @param starting The currently starting activity or null if there is none. |
Wale Ogunwale | 56d75cf | 2016-03-09 15:14:47 -0800 | [diff] [blame] | 1530 | * @param stackBehindId The id of the stack directly behind this one. |
Wale Ogunwale | 8051c5c | 2016-03-04 10:27:32 -0800 | [diff] [blame] | 1531 | */ |
Wale Ogunwale | 56d75cf | 2016-03-09 15:14:47 -0800 | [diff] [blame] | 1532 | private boolean isStackTranslucent(ActivityRecord starting, int stackBehindId) { |
Wale Ogunwale | 8051c5c | 2016-03-04 10:27:32 -0800 | [diff] [blame] | 1533 | for (int taskNdx = mTaskHistory.size() - 1; taskNdx >= 0; --taskNdx) { |
| 1534 | final TaskRecord task = mTaskHistory.get(taskNdx); |
Wale Ogunwale | 1e3523c | 2015-09-16 13:11:10 -0700 | [diff] [blame] | 1535 | final ArrayList<ActivityRecord> activities = task.mActivities; |
| 1536 | for (int activityNdx = activities.size() - 1; activityNdx >= 0; --activityNdx) { |
| 1537 | final ActivityRecord r = activities.get(activityNdx); |
Wale Ogunwale | b34a7ad | 2015-08-14 11:05:30 -0700 | [diff] [blame] | 1538 | |
Wale Ogunwale | 56d75cf | 2016-03-09 15:14:47 -0800 | [diff] [blame] | 1539 | if (r.finishing) { |
| 1540 | // We don't factor in finishing activities when determining translucency since |
| 1541 | // they will be gone soon. |
| 1542 | continue; |
| 1543 | } |
| 1544 | |
| 1545 | if (!r.visible && r != starting) { |
| 1546 | // Also ignore invisible activities that are not the currently starting |
| 1547 | // activity (about to be visible). |
| 1548 | continue; |
| 1549 | } |
| 1550 | |
| 1551 | if (r.fullscreen) { |
| 1552 | // Stack isn't translucent if it has at least one fullscreen activity |
| 1553 | // that is visible. |
| 1554 | return false; |
| 1555 | } |
| 1556 | |
| 1557 | if (!isHomeStack() && r.frontOfTask |
| 1558 | && task.isOverHomeStack() && stackBehindId != HOME_STACK_ID) { |
| 1559 | // Stack isn't translucent if it's top activity should have the home stack |
| 1560 | // 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] | 1561 | return false; |
Wale Ogunwale | b34a7ad | 2015-08-14 11:05:30 -0700 | [diff] [blame] | 1562 | } |
| 1563 | } |
| 1564 | } |
Wale Ogunwale | 1e3523c | 2015-09-16 13:11:10 -0700 | [diff] [blame] | 1565 | return true; |
Wale Ogunwale | b34a7ad | 2015-08-14 11:05:30 -0700 | [diff] [blame] | 1566 | } |
| 1567 | |
Filip Gruszczynski | 0e381e2 | 2016-01-14 16:31:33 -0800 | [diff] [blame] | 1568 | /** |
| 1569 | * Returns stack's visibility: {@link #STACK_INVISIBLE}, {@link #STACK_VISIBLE} or |
| 1570 | * {@link #STACK_VISIBLE_ACTIVITY_BEHIND}. |
Wale Ogunwale | 8051c5c | 2016-03-04 10:27:32 -0800 | [diff] [blame] | 1571 | * @param starting The currently starting activity or null if there is none. |
Filip Gruszczynski | 0e381e2 | 2016-01-14 16:31:33 -0800 | [diff] [blame] | 1572 | */ |
Wale Ogunwale | 8051c5c | 2016-03-04 10:27:32 -0800 | [diff] [blame] | 1573 | int getStackVisibilityLocked(ActivityRecord starting) { |
Jose Lima | 7ba7125 | 2014-04-30 12:59:27 -0700 | [diff] [blame] | 1574 | if (!isAttached()) { |
Filip Gruszczynski | 0e381e2 | 2016-01-14 16:31:33 -0800 | [diff] [blame] | 1575 | return STACK_INVISIBLE; |
Jose Lima | 7ba7125 | 2014-04-30 12:59:27 -0700 | [diff] [blame] | 1576 | } |
| 1577 | |
Wale Ogunwale | 1e60e0c | 2015-10-28 13:36:10 -0700 | [diff] [blame] | 1578 | if (mStackSupervisor.isFrontStack(this) || mStackSupervisor.isFocusedStack(this)) { |
Filip Gruszczynski | 0e381e2 | 2016-01-14 16:31:33 -0800 | [diff] [blame] | 1579 | return STACK_VISIBLE; |
Wale Ogunwale | 99db186 | 2015-10-23 20:08:22 -0700 | [diff] [blame] | 1580 | } |
| 1581 | |
Wale Ogunwale | b34a7ad | 2015-08-14 11:05:30 -0700 | [diff] [blame] | 1582 | final int stackIndex = mStacks.indexOf(this); |
| 1583 | |
| 1584 | if (stackIndex == mStacks.size() - 1) { |
| 1585 | Slog.wtf(TAG, |
| 1586 | "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] | 1587 | return STACK_INVISIBLE; |
Wale Ogunwale | b34a7ad | 2015-08-14 11:05:30 -0700 | [diff] [blame] | 1588 | } |
| 1589 | |
Chong Zhang | 75b3720 | 2015-12-04 14:16:36 -0800 | [diff] [blame] | 1590 | final boolean isLockscreenShown = mService.mLockScreenShown == LOCK_SCREEN_SHOWN; |
| 1591 | if (isLockscreenShown && !StackId.isAllowedOverLockscreen(mStackId)) { |
Filip Gruszczynski | 0e381e2 | 2016-01-14 16:31:33 -0800 | [diff] [blame] | 1592 | return STACK_INVISIBLE; |
Chong Zhang | 75b3720 | 2015-12-04 14:16:36 -0800 | [diff] [blame] | 1593 | } |
| 1594 | |
Wale Ogunwale | 1e3523c | 2015-09-16 13:11:10 -0700 | [diff] [blame] | 1595 | final ActivityStack focusedStack = mStackSupervisor.getFocusedStack(); |
| 1596 | final int focusedStackId = focusedStack.mStackId; |
| 1597 | |
Wale Ogunwale | cff4aa3 | 2015-12-11 10:44:25 -0800 | [diff] [blame] | 1598 | if (mStackId == FULLSCREEN_WORKSPACE_STACK_ID |
Filip Gruszczynski | 4e7fe71 | 2016-01-13 13:22:44 -0800 | [diff] [blame] | 1599 | && hasVisibleBehindActivity() && focusedStackId == HOME_STACK_ID |
| 1600 | && !focusedStack.topActivity().fullscreen) { |
Wale Ogunwale | cff4aa3 | 2015-12-11 10:44:25 -0800 | [diff] [blame] | 1601 | // 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] | 1602 | // the home stack that is translucent. |
Filip Gruszczynski | 0e381e2 | 2016-01-14 16:31:33 -0800 | [diff] [blame] | 1603 | return STACK_VISIBLE_ACTIVITY_BEHIND; |
Wale Ogunwale | cff4aa3 | 2015-12-11 10:44:25 -0800 | [diff] [blame] | 1604 | } |
| 1605 | |
Wale Ogunwale | 1e3523c | 2015-09-16 13:11:10 -0700 | [diff] [blame] | 1606 | if (mStackId == DOCKED_STACK_ID) { |
Wale Ogunwale | b1faf60 | 2016-01-27 09:12:31 -0800 | [diff] [blame] | 1607 | // 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] | 1608 | // task in the focus stack doesn't support any form of resizing but we show it for the |
| 1609 | // home task even though it's not resizable. |
Wale Ogunwale | d26176f | 2016-01-25 20:04:04 -0800 | [diff] [blame] | 1610 | final ActivityRecord r = focusedStack.topRunningActivityLocked(); |
Wale Ogunwale | b1faf60 | 2016-01-27 09:12:31 -0800 | [diff] [blame] | 1611 | final TaskRecord task = r != null ? r.task : null; |
Jorim Jaggi | 42625d1b | 2016-02-11 20:11:07 -0800 | [diff] [blame] | 1612 | return task == null || task.canGoInDockedStack() || task.isHomeTask() ? STACK_VISIBLE |
| 1613 | : STACK_INVISIBLE; |
Wale Ogunwale | 1e3523c | 2015-09-16 13:11:10 -0700 | [diff] [blame] | 1614 | } |
| 1615 | |
Wale Ogunwale | 56d75cf | 2016-03-09 15:14:47 -0800 | [diff] [blame] | 1616 | // Find the first stack behind focused stack that actually got something visible. |
| 1617 | int stackBehindFocusedIndex = mStacks.indexOf(focusedStack) - 1; |
| 1618 | while (stackBehindFocusedIndex >= 0 && |
| 1619 | mStacks.get(stackBehindFocusedIndex).topRunningActivityLocked() == null) { |
| 1620 | stackBehindFocusedIndex--; |
Chong Zhang | b16cf34 | 2015-11-12 17:22:40 -0800 | [diff] [blame] | 1621 | } |
Wale Ogunwale | 99db186 | 2015-10-23 20:08:22 -0700 | [diff] [blame] | 1622 | if ((focusedStackId == DOCKED_STACK_ID || focusedStackId == PINNED_STACK_ID) |
Wale Ogunwale | 56d75cf | 2016-03-09 15:14:47 -0800 | [diff] [blame] | 1623 | && stackIndex == stackBehindFocusedIndex) { |
Wale Ogunwale | 99db186 | 2015-10-23 20:08:22 -0700 | [diff] [blame] | 1624 | // Stacks directly behind the docked or pinned stack are always visible. |
Filip Gruszczynski | 0e381e2 | 2016-01-14 16:31:33 -0800 | [diff] [blame] | 1625 | return STACK_VISIBLE; |
Wale Ogunwale | 1e3523c | 2015-09-16 13:11:10 -0700 | [diff] [blame] | 1626 | } |
| 1627 | |
Wale Ogunwale | 56d75cf | 2016-03-09 15:14:47 -0800 | [diff] [blame] | 1628 | final int stackBehindFocusedId = (stackBehindFocusedIndex >= 0) |
| 1629 | ? mStacks.get(stackBehindFocusedIndex).mStackId : INVALID_STACK_ID; |
| 1630 | |
Wale Ogunwale | bd26d2a | 2015-09-22 22:08:37 -0700 | [diff] [blame] | 1631 | if (focusedStackId == FULLSCREEN_WORKSPACE_STACK_ID |
Wale Ogunwale | 56d75cf | 2016-03-09 15:14:47 -0800 | [diff] [blame] | 1632 | && focusedStack.isStackTranslucent(starting, stackBehindFocusedId)) { |
Wale Ogunwale | bd26d2a | 2015-09-22 22:08:37 -0700 | [diff] [blame] | 1633 | // Stacks behind the fullscreen stack with a translucent activity are always |
| 1634 | // visible so they can act as a backdrop to the translucent activity. |
| 1635 | // For example, dialog activities |
Wale Ogunwale | 56d75cf | 2016-03-09 15:14:47 -0800 | [diff] [blame] | 1636 | if (stackIndex == stackBehindFocusedIndex) { |
Filip Gruszczynski | 0e381e2 | 2016-01-14 16:31:33 -0800 | [diff] [blame] | 1637 | return STACK_VISIBLE; |
Wale Ogunwale | bd26d2a | 2015-09-22 22:08:37 -0700 | [diff] [blame] | 1638 | } |
Wale Ogunwale | 56d75cf | 2016-03-09 15:14:47 -0800 | [diff] [blame] | 1639 | if (stackBehindFocusedIndex >= 0) { |
| 1640 | if ((stackBehindFocusedId == DOCKED_STACK_ID |
| 1641 | || stackBehindFocusedId == PINNED_STACK_ID) |
| 1642 | && stackIndex == (stackBehindFocusedIndex - 1)) { |
Wale Ogunwale | 99db186 | 2015-10-23 20:08:22 -0700 | [diff] [blame] | 1643 | // The stack behind the docked or pinned stack is also visible so we can have a |
| 1644 | // complete backdrop to the translucent activity when the docked stack is up. |
Filip Gruszczynski | 0e381e2 | 2016-01-14 16:31:33 -0800 | [diff] [blame] | 1645 | return STACK_VISIBLE; |
Wale Ogunwale | bd26d2a | 2015-09-22 22:08:37 -0700 | [diff] [blame] | 1646 | } |
| 1647 | } |
Wale Ogunwale | 1e3523c | 2015-09-16 13:11:10 -0700 | [diff] [blame] | 1648 | } |
| 1649 | |
Wale Ogunwale | 3797c22 | 2015-10-27 14:21:58 -0700 | [diff] [blame] | 1650 | if (StackId.isStaticStack(mStackId)) { |
Wale Ogunwale | 1e3523c | 2015-09-16 13:11:10 -0700 | [diff] [blame] | 1651 | // 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] | 1652 | return STACK_INVISIBLE; |
Wale Ogunwale | ddc1cb2 | 2015-07-25 19:23:04 -0700 | [diff] [blame] | 1653 | } |
| 1654 | |
Wale Ogunwale | b34a7ad | 2015-08-14 11:05:30 -0700 | [diff] [blame] | 1655 | for (int i = stackIndex + 1; i < mStacks.size(); i++) { |
Wale Ogunwale | e4a0c57 | 2015-06-30 08:40:31 -0700 | [diff] [blame] | 1656 | final ActivityStack stack = mStacks.get(i); |
Wale Ogunwale | b34a7ad | 2015-08-14 11:05:30 -0700 | [diff] [blame] | 1657 | |
| 1658 | if (!stack.mFullscreen && !stack.hasFullscreenTask()) { |
| 1659 | continue; |
| 1660 | } |
| 1661 | |
Wale Ogunwale | 3797c22 | 2015-10-27 14:21:58 -0700 | [diff] [blame] | 1662 | if (!StackId.isDynamicStacksVisibleBehindAllowed(stack.mStackId)) { |
Wale Ogunwale | 1e3523c | 2015-09-16 13:11:10 -0700 | [diff] [blame] | 1663 | // These stacks can't have any dynamic stacks visible behind them. |
Filip Gruszczynski | 0e381e2 | 2016-01-14 16:31:33 -0800 | [diff] [blame] | 1664 | return STACK_INVISIBLE; |
Todd Kennedy | aab56db | 2015-01-30 09:39:53 -0800 | [diff] [blame] | 1665 | } |
Wale Ogunwale | ddc1cb2 | 2015-07-25 19:23:04 -0700 | [diff] [blame] | 1666 | |
Wale Ogunwale | 56d75cf | 2016-03-09 15:14:47 -0800 | [diff] [blame] | 1667 | if (!stack.isStackTranslucent(starting, INVALID_STACK_ID)) { |
Filip Gruszczynski | 0e381e2 | 2016-01-14 16:31:33 -0800 | [diff] [blame] | 1668 | return STACK_INVISIBLE; |
Jose Lima | 7ba7125 | 2014-04-30 12:59:27 -0700 | [diff] [blame] | 1669 | } |
| 1670 | } |
| 1671 | |
Filip Gruszczynski | 0e381e2 | 2016-01-14 16:31:33 -0800 | [diff] [blame] | 1672 | return STACK_VISIBLE; |
Jose Lima | 7ba7125 | 2014-04-30 12:59:27 -0700 | [diff] [blame] | 1673 | } |
| 1674 | |
Chong Zhang | fdcc4d4 | 2015-10-14 16:50:12 -0700 | [diff] [blame] | 1675 | final int rankTaskLayers(int baseLayer) { |
| 1676 | int layer = 0; |
| 1677 | for (int taskNdx = mTaskHistory.size() - 1; taskNdx >= 0; --taskNdx) { |
| 1678 | final TaskRecord task = mTaskHistory.get(taskNdx); |
| 1679 | ActivityRecord r = task.topRunningActivityLocked(); |
| 1680 | if (r == null || r.finishing || !r.visible) { |
| 1681 | task.mLayerRank = -1; |
| 1682 | } else { |
| 1683 | task.mLayerRank = baseLayer + layer++; |
| 1684 | } |
| 1685 | } |
| 1686 | return layer; |
| 1687 | } |
| 1688 | |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 1689 | /** |
| 1690 | * Make sure that all activities that need to be visible (that is, they |
| 1691 | * currently can be seen by the user) actually are. |
| 1692 | */ |
Filip Gruszczynski | bc5a6c5 | 2015-09-22 13:13:24 -0700 | [diff] [blame] | 1693 | final void ensureActivitiesVisibleLocked(ActivityRecord starting, int configChanges, |
| 1694 | boolean preserveWindows) { |
Filip Gruszczynski | 3e85ba2 | 2015-10-05 22:48:30 -0700 | [diff] [blame] | 1695 | ActivityRecord top = topRunningActivityLocked(); |
Filip Gruszczynski | 9104aea | 2015-11-13 16:42:05 -0800 | [diff] [blame] | 1696 | if (DEBUG_VISIBILITY) Slog.v(TAG_VISIBILITY, "ensureActivitiesVisible behind " + top |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 1697 | + " configChanges=0x" + Integer.toHexString(configChanges)); |
Filip Gruszczynski | 21199bd | 2015-12-02 12:49:58 -0800 | [diff] [blame] | 1698 | if (top != null) { |
| 1699 | checkTranslucentActivityWaiting(top); |
| 1700 | } |
Craig Mautner | 5eda9b3 | 2013-07-02 11:58:16 -0700 | [diff] [blame] | 1701 | |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 1702 | // If the top activity is not fullscreen, then we need to |
| 1703 | // make sure any activities under it are now visible. |
Filip Gruszczynski | 21199bd | 2015-12-02 12:49:58 -0800 | [diff] [blame] | 1704 | boolean aboveTop = top != null; |
Wale Ogunwale | 8051c5c | 2016-03-04 10:27:32 -0800 | [diff] [blame] | 1705 | final int stackVisibility = getStackVisibilityLocked(starting); |
Filip Gruszczynski | 0e381e2 | 2016-01-14 16:31:33 -0800 | [diff] [blame] | 1706 | final boolean stackInvisible = stackVisibility != STACK_VISIBLE; |
| 1707 | final boolean stackVisibleBehind = stackVisibility == STACK_VISIBLE_ACTIVITY_BEHIND; |
Wale Ogunwale | c219c0b | 2015-09-12 09:18:07 -0700 | [diff] [blame] | 1708 | boolean behindFullscreenActivity = stackInvisible; |
Andrii Kulian | c11ce7b | 2016-06-27 10:53:53 -0700 | [diff] [blame] | 1709 | boolean resumeNextActivity = mStackSupervisor.isFocusedStack(this) |
| 1710 | && (isInStackLocked(starting) == null); |
Filip Gruszczynski | 0e381e2 | 2016-01-14 16:31:33 -0800 | [diff] [blame] | 1711 | boolean behindTranslucentActivity = false; |
| 1712 | final ActivityRecord visibleBehind = getVisibleBehindActivity(); |
Craig Mautner | b59dcfd | 2013-05-06 13:12:58 -0700 | [diff] [blame] | 1713 | for (int taskNdx = mTaskHistory.size() - 1; taskNdx >= 0; --taskNdx) { |
Craig Mautner | ae7ecab | 2013-09-18 11:48:14 -0700 | [diff] [blame] | 1714 | final TaskRecord task = mTaskHistory.get(taskNdx); |
| 1715 | final ArrayList<ActivityRecord> activities = task.mActivities; |
Craig Mautner | d44711d | 2013-02-23 11:24:36 -0800 | [diff] [blame] | 1716 | for (int activityNdx = activities.size() - 1; activityNdx >= 0; --activityNdx) { |
| 1717 | final ActivityRecord r = activities.get(activityNdx); |
| 1718 | if (r.finishing) { |
Chong Zhang | 22bc851 | 2016-04-07 13:47:18 -0700 | [diff] [blame] | 1719 | // Normally the screenshot will be taken in makeInvisible(). When an activity |
| 1720 | // is finishing, we no longer change its visibility, but we still need to take |
| 1721 | // the screenshots if startPausingLocked decided it should be taken. |
| 1722 | if (r.mUpdateTaskThumbnailWhenHidden) { |
| 1723 | r.updateThumbnailLocked(screenshotActivitiesLocked(r), null); |
| 1724 | r.mUpdateTaskThumbnailWhenHidden = false; |
| 1725 | } |
Craig Mautner | d44711d | 2013-02-23 11:24:36 -0800 | [diff] [blame] | 1726 | continue; |
| 1727 | } |
Filip Gruszczynski | 21199bd | 2015-12-02 12:49:58 -0800 | [diff] [blame] | 1728 | final boolean isTop = r == top; |
| 1729 | if (aboveTop && !isTop) { |
Craig Mautner | d44711d | 2013-02-23 11:24:36 -0800 | [diff] [blame] | 1730 | continue; |
| 1731 | } |
| 1732 | aboveTop = false; |
Wale Ogunwale | e76407c | 2016-05-16 17:04:37 -0700 | [diff] [blame] | 1733 | |
| 1734 | if (shouldBeVisible(r, behindTranslucentActivity, stackVisibleBehind, |
| 1735 | visibleBehind, behindFullscreenActivity)) { |
Filip Gruszczynski | 0e381e2 | 2016-01-14 16:31:33 -0800 | [diff] [blame] | 1736 | if (DEBUG_VISIBILITY) Slog.v(TAG_VISIBILITY, "Make visible? " + r |
| 1737 | + " finishing=" + r.finishing + " state=" + r.state); |
Craig Mautner | d44711d | 2013-02-23 11:24:36 -0800 | [diff] [blame] | 1738 | // First: if this is not the current activity being started, make |
| 1739 | // sure it matches the current configuration. |
Craig Mautner | bb74246 | 2014-07-07 15:28:55 -0700 | [diff] [blame] | 1740 | if (r != starting) { |
Filip Gruszczynski | bc5a6c5 | 2015-09-22 13:13:24 -0700 | [diff] [blame] | 1741 | ensureActivityConfigurationLocked(r, 0, preserveWindows); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 1742 | } |
Craig Mautner | d44711d | 2013-02-23 11:24:36 -0800 | [diff] [blame] | 1743 | |
| 1744 | if (r.app == null || r.app.thread == null) { |
Filip Gruszczynski | 21199bd | 2015-12-02 12:49:58 -0800 | [diff] [blame] | 1745 | if (makeVisibleAndRestartIfNeeded(starting, configChanges, isTop, |
Wale Ogunwale | d046a01 | 2015-12-24 13:05:59 -0800 | [diff] [blame] | 1746 | resumeNextActivity, r)) { |
Filip Gruszczynski | 9104aea | 2015-11-13 16:42:05 -0800 | [diff] [blame] | 1747 | if (activityNdx >= activities.size()) { |
| 1748 | // Record may be removed if its process needs to restart. |
| 1749 | activityNdx = activities.size() - 1; |
| 1750 | } else { |
Wale Ogunwale | d046a01 | 2015-12-24 13:05:59 -0800 | [diff] [blame] | 1751 | resumeNextActivity = false; |
riddle_hsu | 36ee73d | 2015-06-05 16:38:38 +0800 | [diff] [blame] | 1752 | } |
Craig Mautner | d44711d | 2013-02-23 11:24:36 -0800 | [diff] [blame] | 1753 | } |
Craig Mautner | d44711d | 2013-02-23 11:24:36 -0800 | [diff] [blame] | 1754 | } else if (r.visible) { |
Filip Gruszczynski | 21199bd | 2015-12-02 12:49:58 -0800 | [diff] [blame] | 1755 | // 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] | 1756 | if (DEBUG_VISIBILITY) Slog.v(TAG_VISIBILITY, |
| 1757 | "Skipping: already visible at " + r); |
| 1758 | |
Filip Gruszczynski | 21199bd | 2015-12-02 12:49:58 -0800 | [diff] [blame] | 1759 | if (handleAlreadyVisible(r)) { |
Wale Ogunwale | d046a01 | 2015-12-24 13:05:59 -0800 | [diff] [blame] | 1760 | resumeNextActivity = false; |
Wale Ogunwale | 85b90ab | 2015-04-27 20:54:47 -0700 | [diff] [blame] | 1761 | } |
Craig Mautner | bb74246 | 2014-07-07 15:28:55 -0700 | [diff] [blame] | 1762 | } else { |
Jorim Jaggi | e66edb1 | 2016-02-05 12:41:17 -0800 | [diff] [blame] | 1763 | makeVisibleIfNeeded(starting, r); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 1764 | } |
Craig Mautner | d44711d | 2013-02-23 11:24:36 -0800 | [diff] [blame] | 1765 | // Aggregate current change flags. |
| 1766 | configChanges |= r.configChangeFlags; |
Filip Gruszczynski | 9104aea | 2015-11-13 16:42:05 -0800 | [diff] [blame] | 1767 | behindFullscreenActivity = updateBehindFullscreen(stackInvisible, |
| 1768 | behindFullscreenActivity, task, r); |
Filip Gruszczynski | 0e381e2 | 2016-01-14 16:31:33 -0800 | [diff] [blame] | 1769 | if (behindFullscreenActivity && !r.fullscreen) { |
| 1770 | behindTranslucentActivity = true; |
| 1771 | } |
Craig Mautner | d44711d | 2013-02-23 11:24:36 -0800 | [diff] [blame] | 1772 | } else { |
Wale Ogunwale | 834c236 | 2016-01-23 18:14:58 -0800 | [diff] [blame] | 1773 | if (DEBUG_VISIBILITY) Slog.v(TAG_VISIBILITY, "Make invisible? " + r |
Filip Gruszczynski | 0e381e2 | 2016-01-14 16:31:33 -0800 | [diff] [blame] | 1774 | + " finishing=" + r.finishing + " state=" + r.state + " stackInvisible=" |
| 1775 | + stackInvisible + " behindFullscreenActivity=" |
| 1776 | + behindFullscreenActivity + " mLaunchTaskBehind=" |
| 1777 | + r.mLaunchTaskBehind); |
| 1778 | makeInvisible(r, visibleBehind); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 1779 | } |
| 1780 | } |
Wale Ogunwale | c219c0b | 2015-09-12 09:18:07 -0700 | [diff] [blame] | 1781 | if (mStackId == FREEFORM_WORKSPACE_STACK_ID) { |
| 1782 | // The visibility of tasks and the activities they contain in freeform stack are |
| 1783 | // determined individually unlike other stacks where the visibility or fullscreen |
| 1784 | // status of an activity in a previous task affects other. |
Filip Gruszczynski | 0e381e2 | 2016-01-14 16:31:33 -0800 | [diff] [blame] | 1785 | behindFullscreenActivity = stackVisibility == STACK_INVISIBLE; |
Wale Ogunwale | 74e2659 | 2016-02-05 11:48:37 -0800 | [diff] [blame] | 1786 | } else if (mStackId == HOME_STACK_ID) { |
| 1787 | if (task.isHomeTask()) { |
| 1788 | if (DEBUG_VISIBILITY) Slog.v(TAG_VISIBILITY, "Home task: at " + task |
| 1789 | + " stackInvisible=" + stackInvisible |
| 1790 | + " behindFullscreenActivity=" + behindFullscreenActivity); |
| 1791 | // No other task in the home stack should be visible behind the home activity. |
| 1792 | // Home activities is usually a translucent activity with the wallpaper behind |
| 1793 | // them. However, when they don't have the wallpaper behind them, we want to |
| 1794 | // show activities in the next application stack behind them vs. another |
| 1795 | // task in the home stack like recents. |
| 1796 | behindFullscreenActivity = true; |
| 1797 | } else if (task.isRecentsTask() |
| 1798 | && task.getTaskToReturnTo() == APPLICATION_ACTIVITY_TYPE) { |
| 1799 | if (DEBUG_VISIBILITY) Slog.v(TAG_VISIBILITY, |
| 1800 | "Recents task returning to app: at " + task |
| 1801 | + " stackInvisible=" + stackInvisible |
| 1802 | + " behindFullscreenActivity=" + behindFullscreenActivity); |
| 1803 | // We don't want any other tasks in the home stack visible if the recents |
| 1804 | // activity is going to be returning to an application activity type. |
| 1805 | // We do this to preserve the visible order the user used to get into the |
| 1806 | // recents activity. The recents activity is normally translucent and if it |
| 1807 | // doesn't have the wallpaper behind it the next activity in the home stack |
| 1808 | // shouldn't be visible when the home stack is brought to the front to display |
| 1809 | // the recents activity from an app. |
| 1810 | behindFullscreenActivity = true; |
| 1811 | } |
| 1812 | |
Wale Ogunwale | c219c0b | 2015-09-12 09:18:07 -0700 | [diff] [blame] | 1813 | } |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 1814 | } |
Craig Mautner | eb8abf7 | 2014-07-02 15:04:09 -0700 | [diff] [blame] | 1815 | |
| 1816 | if (mTranslucentActivityWaiting != null && |
| 1817 | mUndrawnActivitiesBelowTopTranslucent.isEmpty()) { |
| 1818 | // Nothing is getting drawn or everything was already visible, don't wait for timeout. |
| 1819 | notifyActivityDrawnLocked(null); |
| 1820 | } |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 1821 | } |
Craig Mautner | 5854780 | 2013-03-05 08:23:53 -0800 | [diff] [blame] | 1822 | |
Wale Ogunwale | e76407c | 2016-05-16 17:04:37 -0700 | [diff] [blame] | 1823 | /** Return true if the input activity should be made visible */ |
| 1824 | private boolean shouldBeVisible(ActivityRecord r, boolean behindTranslucentActivity, |
| 1825 | boolean stackVisibleBehind, ActivityRecord visibleBehind, |
| 1826 | boolean behindFullscreenActivity) { |
Wale Ogunwale | e76407c | 2016-05-16 17:04:37 -0700 | [diff] [blame] | 1827 | |
Wale Ogunwale | 60920d5 | 2016-06-20 10:45:13 -0700 | [diff] [blame] | 1828 | if (!okToShowLocked(r)) { |
Wale Ogunwale | e76407c | 2016-05-16 17:04:37 -0700 | [diff] [blame] | 1829 | return false; |
| 1830 | } |
| 1831 | |
Wale Ogunwale | 8c09c7d | 2016-05-23 09:10:24 -0700 | [diff] [blame] | 1832 | // mLaunchingBehind: Activities launching behind are at the back of the task stack |
| 1833 | // but must be drawn initially for the animation as though they were visible. |
| 1834 | final boolean activityVisibleBehind = |
| 1835 | (behindTranslucentActivity || stackVisibleBehind) && visibleBehind == r; |
| 1836 | |
Wale Ogunwale | e76407c | 2016-05-16 17:04:37 -0700 | [diff] [blame] | 1837 | boolean isVisible = |
| 1838 | !behindFullscreenActivity || r.mLaunchTaskBehind || activityVisibleBehind; |
| 1839 | |
Wale Ogunwale | ca2af9e | 2016-05-26 14:43:19 -0700 | [diff] [blame] | 1840 | if (mService.mSupportsLeanbackOnly && isVisible && r.isRecentsActivity()) { |
| 1841 | // On devices that support leanback only (Android TV), Recents activity can only be |
| 1842 | // 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] | 1843 | isVisible = mStackSupervisor.getStack(DOCKED_STACK_ID) != null |
| 1844 | || mStackSupervisor.isFocusedStack(this); |
Wale Ogunwale | e76407c | 2016-05-16 17:04:37 -0700 | [diff] [blame] | 1845 | } |
| 1846 | |
| 1847 | return isVisible; |
| 1848 | } |
| 1849 | |
Filip Gruszczynski | 9104aea | 2015-11-13 16:42:05 -0800 | [diff] [blame] | 1850 | private void checkTranslucentActivityWaiting(ActivityRecord top) { |
| 1851 | if (mTranslucentActivityWaiting != top) { |
| 1852 | mUndrawnActivitiesBelowTopTranslucent.clear(); |
| 1853 | if (mTranslucentActivityWaiting != null) { |
| 1854 | // Call the callback with a timeout indication. |
| 1855 | notifyActivityDrawnLocked(null); |
| 1856 | mTranslucentActivityWaiting = null; |
| 1857 | } |
| 1858 | mHandler.removeMessages(TRANSLUCENT_TIMEOUT_MSG); |
| 1859 | } |
| 1860 | } |
| 1861 | |
| 1862 | private boolean makeVisibleAndRestartIfNeeded(ActivityRecord starting, int configChanges, |
Wale Ogunwale | d046a01 | 2015-12-24 13:05:59 -0800 | [diff] [blame] | 1863 | boolean isTop, boolean andResume, ActivityRecord r) { |
Filip Gruszczynski | 9104aea | 2015-11-13 16:42:05 -0800 | [diff] [blame] | 1864 | // We need to make sure the app is running if it's the top, or it is just made visible from |
| 1865 | // invisible. If the app is already visible, it must have died while it was visible. In this |
| 1866 | // case, we'll show the dead window but will not restart the app. Otherwise we could end up |
| 1867 | // thrashing. |
Filip Gruszczynski | 21199bd | 2015-12-02 12:49:58 -0800 | [diff] [blame] | 1868 | if (isTop || !r.visible) { |
Filip Gruszczynski | 9104aea | 2015-11-13 16:42:05 -0800 | [diff] [blame] | 1869 | // This activity needs to be visible, but isn't even running... |
| 1870 | // get it started and resume if no other stack in this stack is resumed. |
| 1871 | if (DEBUG_VISIBILITY) Slog.v(TAG_VISIBILITY, "Start and freeze screen for " + r); |
| 1872 | if (r != starting) { |
| 1873 | r.startFreezingScreenLocked(r.app, configChanges); |
| 1874 | } |
| 1875 | if (!r.visible || r.mLaunchTaskBehind) { |
| 1876 | if (DEBUG_VISIBILITY) Slog.v(TAG_VISIBILITY, "Starting and making visible: " + r); |
| 1877 | setVisible(r, true); |
| 1878 | } |
| 1879 | if (r != starting) { |
Wale Ogunwale | d046a01 | 2015-12-24 13:05:59 -0800 | [diff] [blame] | 1880 | mStackSupervisor.startSpecificActivityLocked(r, andResume, false); |
Filip Gruszczynski | 9104aea | 2015-11-13 16:42:05 -0800 | [diff] [blame] | 1881 | return true; |
| 1882 | } |
| 1883 | } |
| 1884 | return false; |
| 1885 | } |
| 1886 | |
Filip Gruszczynski | 0e381e2 | 2016-01-14 16:31:33 -0800 | [diff] [blame] | 1887 | private void makeInvisible(ActivityRecord r, ActivityRecord visibleBehind) { |
Filip Gruszczynski | 9104aea | 2015-11-13 16:42:05 -0800 | [diff] [blame] | 1888 | if (!r.visible) { |
| 1889 | if (DEBUG_VISIBILITY) Slog.v(TAG_VISIBILITY, "Already invisible: " + r); |
| 1890 | return; |
| 1891 | } |
| 1892 | // Now for any activities that aren't visible to the user, make sure they no longer are |
| 1893 | // keeping the screen frozen. |
Filip Gruszczynski | 4e7fe71 | 2016-01-13 13:22:44 -0800 | [diff] [blame] | 1894 | if (DEBUG_VISIBILITY) Slog.v(TAG_VISIBILITY, "Making invisible: " + r + " " + r.state); |
Filip Gruszczynski | 9104aea | 2015-11-13 16:42:05 -0800 | [diff] [blame] | 1895 | try { |
| 1896 | setVisible(r, false); |
| 1897 | switch (r.state) { |
| 1898 | case STOPPING: |
| 1899 | case STOPPED: |
| 1900 | if (r.app != null && r.app.thread != null) { |
| 1901 | if (DEBUG_VISIBILITY) Slog.v(TAG_VISIBILITY, |
| 1902 | "Scheduling invisibility: " + r); |
| 1903 | r.app.thread.scheduleWindowVisibility(r.appToken, false); |
| 1904 | } |
| 1905 | break; |
| 1906 | |
| 1907 | case INITIALIZING: |
| 1908 | case RESUMED: |
| 1909 | case PAUSING: |
| 1910 | case PAUSED: |
| 1911 | // This case created for transitioning activities from |
| 1912 | // translucent to opaque {@link Activity#convertToOpaque}. |
Filip Gruszczynski | 0e381e2 | 2016-01-14 16:31:33 -0800 | [diff] [blame] | 1913 | if (visibleBehind == r) { |
Filip Gruszczynski | 9104aea | 2015-11-13 16:42:05 -0800 | [diff] [blame] | 1914 | releaseBackgroundResources(r); |
| 1915 | } else { |
Chong Zhang | 46b1ac6 | 2016-02-18 17:53:57 -0800 | [diff] [blame] | 1916 | addToStopping(r, true /* immediate */); |
Filip Gruszczynski | 9104aea | 2015-11-13 16:42:05 -0800 | [diff] [blame] | 1917 | } |
| 1918 | break; |
| 1919 | |
| 1920 | default: |
| 1921 | break; |
| 1922 | } |
| 1923 | } catch (Exception e) { |
| 1924 | // Just skip on any failure; we'll make it visible when it next restarts. |
| 1925 | Slog.w(TAG, "Exception thrown making hidden: " + r.intent.getComponent(), e); |
| 1926 | } |
| 1927 | } |
| 1928 | |
| 1929 | private boolean updateBehindFullscreen(boolean stackInvisible, boolean behindFullscreenActivity, |
| 1930 | TaskRecord task, ActivityRecord r) { |
| 1931 | if (r.fullscreen) { |
Filip Gruszczynski | 9104aea | 2015-11-13 16:42:05 -0800 | [diff] [blame] | 1932 | if (DEBUG_VISIBILITY) Slog.v(TAG_VISIBILITY, "Fullscreen: at " + r |
Wale Ogunwale | 673cbd2 | 2016-01-30 18:30:55 -0800 | [diff] [blame] | 1933 | + " stackInvisible=" + stackInvisible |
| 1934 | + " behindFullscreenActivity=" + behindFullscreenActivity); |
Filip Gruszczynski | 0e381e2 | 2016-01-14 16:31:33 -0800 | [diff] [blame] | 1935 | // At this point, nothing else needs to be shown in this task. |
Filip Gruszczynski | 9104aea | 2015-11-13 16:42:05 -0800 | [diff] [blame] | 1936 | behindFullscreenActivity = true; |
Wale Ogunwale | 74e2659 | 2016-02-05 11:48:37 -0800 | [diff] [blame] | 1937 | } else if (!isHomeStack() && r.frontOfTask && task.isOverHomeStack()) { |
Filip Gruszczynski | 9104aea | 2015-11-13 16:42:05 -0800 | [diff] [blame] | 1938 | if (DEBUG_VISIBILITY) Slog.v(TAG_VISIBILITY, "Showing home: at " + r |
| 1939 | + " stackInvisible=" + stackInvisible |
| 1940 | + " behindFullscreenActivity=" + behindFullscreenActivity); |
Filip Gruszczynski | 0e381e2 | 2016-01-14 16:31:33 -0800 | [diff] [blame] | 1941 | behindFullscreenActivity = true; |
Filip Gruszczynski | 9104aea | 2015-11-13 16:42:05 -0800 | [diff] [blame] | 1942 | } |
| 1943 | return behindFullscreenActivity; |
| 1944 | } |
| 1945 | |
Jorim Jaggi | e66edb1 | 2016-02-05 12:41:17 -0800 | [diff] [blame] | 1946 | private void makeVisibleIfNeeded(ActivityRecord starting, ActivityRecord r) { |
| 1947 | |
Filip Gruszczynski | 9104aea | 2015-11-13 16:42:05 -0800 | [diff] [blame] | 1948 | // 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] | 1949 | if (r.state == ActivityState.RESUMED || r == starting) { |
Chong Zhang | e05db74 | 2016-02-16 16:58:37 -0800 | [diff] [blame] | 1950 | if (DEBUG_VISIBILITY) Slog.d(TAG_VISIBILITY, |
| 1951 | "Not making visible, r=" + r + " state=" + r.state + " starting=" + starting); |
Jorim Jaggi | e66edb1 | 2016-02-05 12:41:17 -0800 | [diff] [blame] | 1952 | return; |
| 1953 | } |
| 1954 | |
| 1955 | // If this activity is paused, tell it to now show its window. |
| 1956 | if (DEBUG_VISIBILITY) Slog.v(TAG_VISIBILITY, |
| 1957 | "Making visible and scheduling visibility: " + r); |
| 1958 | try { |
| 1959 | if (mTranslucentActivityWaiting != null) { |
| 1960 | r.updateOptionsLocked(r.returningOptions); |
| 1961 | mUndrawnActivitiesBelowTopTranslucent.add(r); |
Filip Gruszczynski | 9104aea | 2015-11-13 16:42:05 -0800 | [diff] [blame] | 1962 | } |
Jorim Jaggi | e66edb1 | 2016-02-05 12:41:17 -0800 | [diff] [blame] | 1963 | setVisible(r, true); |
| 1964 | r.sleeping = false; |
| 1965 | r.app.pendingUiClean = true; |
| 1966 | r.app.thread.scheduleWindowVisibility(r.appToken, true); |
Jorim Jaggi | d47e7e1 | 2016-03-01 09:57:38 +0100 | [diff] [blame] | 1967 | // The activity may be waiting for stop, but that is no longer |
| 1968 | // appropriate for it. |
| 1969 | mStackSupervisor.mStoppingActivities.remove(r); |
| 1970 | mStackSupervisor.mGoingToSleepActivities.remove(r); |
Jorim Jaggi | e66edb1 | 2016-02-05 12:41:17 -0800 | [diff] [blame] | 1971 | } catch (Exception e) { |
| 1972 | // Just skip on any failure; we'll make it |
| 1973 | // visible when it next restarts. |
| 1974 | Slog.w(TAG, "Exception thrown making visibile: " + r.intent.getComponent(), e); |
Filip Gruszczynski | 9104aea | 2015-11-13 16:42:05 -0800 | [diff] [blame] | 1975 | } |
Chong Zhang | 371c442 | 2016-05-11 10:48:32 -0700 | [diff] [blame] | 1976 | handleAlreadyVisible(r); |
Filip Gruszczynski | 9104aea | 2015-11-13 16:42:05 -0800 | [diff] [blame] | 1977 | } |
| 1978 | |
Filip Gruszczynski | 21199bd | 2015-12-02 12:49:58 -0800 | [diff] [blame] | 1979 | private boolean handleAlreadyVisible(ActivityRecord r) { |
Filip Gruszczynski | 9104aea | 2015-11-13 16:42:05 -0800 | [diff] [blame] | 1980 | r.stopFreezingScreenLocked(false); |
| 1981 | try { |
| 1982 | if (r.returningOptions != null) { |
| 1983 | r.app.thread.scheduleOnNewActivityOptions(r.appToken, r.returningOptions); |
| 1984 | } |
| 1985 | } catch(RemoteException e) { |
| 1986 | } |
| 1987 | return r.state == ActivityState.RESUMED; |
| 1988 | } |
| 1989 | |
Todd Kennedy | aab56db | 2015-01-30 09:39:53 -0800 | [diff] [blame] | 1990 | void convertActivityToTranslucent(ActivityRecord r) { |
Craig Mautner | 5eda9b3 | 2013-07-02 11:58:16 -0700 | [diff] [blame] | 1991 | mTranslucentActivityWaiting = r; |
| 1992 | mUndrawnActivitiesBelowTopTranslucent.clear(); |
| 1993 | mHandler.sendEmptyMessageDelayed(TRANSLUCENT_TIMEOUT_MSG, TRANSLUCENT_CONVERSION_TIMEOUT); |
| 1994 | } |
| 1995 | |
Dianne Hackborn | b5a380d | 2015-05-20 18:18:46 -0700 | [diff] [blame] | 1996 | void clearOtherAppTimeTrackers(AppTimeTracker except) { |
| 1997 | for (int taskNdx = mTaskHistory.size() - 1; taskNdx >= 0; --taskNdx) { |
| 1998 | final TaskRecord task = mTaskHistory.get(taskNdx); |
| 1999 | final ArrayList<ActivityRecord> activities = task.mActivities; |
| 2000 | for (int activityNdx = activities.size() - 1; activityNdx >= 0; --activityNdx) { |
| 2001 | final ActivityRecord r = activities.get(activityNdx); |
| 2002 | if ( r.appTimeTracker != except) { |
| 2003 | r.appTimeTracker = null; |
| 2004 | } |
| 2005 | } |
| 2006 | } |
| 2007 | } |
| 2008 | |
Craig Mautner | 5eda9b3 | 2013-07-02 11:58:16 -0700 | [diff] [blame] | 2009 | /** |
| 2010 | * Called as activities below the top translucent activity are redrawn. When the last one is |
| 2011 | * redrawn notify the top activity by calling |
| 2012 | * {@link Activity#onTranslucentConversionComplete}. |
| 2013 | * |
| 2014 | * @param r The most recent background activity to be drawn. Or, if r is null then a timeout |
| 2015 | * occurred and the activity will be notified immediately. |
| 2016 | */ |
| 2017 | void notifyActivityDrawnLocked(ActivityRecord r) { |
Craig Mautner | 6985bad | 2014-04-21 15:22:06 -0700 | [diff] [blame] | 2018 | mActivityContainer.setDrawn(); |
Craig Mautner | 5eda9b3 | 2013-07-02 11:58:16 -0700 | [diff] [blame] | 2019 | if ((r == null) |
| 2020 | || (mUndrawnActivitiesBelowTopTranslucent.remove(r) && |
| 2021 | mUndrawnActivitiesBelowTopTranslucent.isEmpty())) { |
| 2022 | // The last undrawn activity below the top has just been drawn. If there is an |
| 2023 | // opaque activity at the top, notify it that it can become translucent safely now. |
| 2024 | final ActivityRecord waitingActivity = mTranslucentActivityWaiting; |
| 2025 | mTranslucentActivityWaiting = null; |
| 2026 | mUndrawnActivitiesBelowTopTranslucent.clear(); |
| 2027 | mHandler.removeMessages(TRANSLUCENT_TIMEOUT_MSG); |
| 2028 | |
Craig Mautner | 71dd1b6 | 2014-02-18 15:48:52 -0800 | [diff] [blame] | 2029 | if (waitingActivity != null) { |
| 2030 | mWindowManager.setWindowOpaque(waitingActivity.appToken, false); |
| 2031 | if (waitingActivity.app != null && waitingActivity.app.thread != null) { |
| 2032 | try { |
| 2033 | waitingActivity.app.thread.scheduleTranslucentConversionComplete( |
| 2034 | waitingActivity.appToken, r != null); |
| 2035 | } catch (RemoteException e) { |
| 2036 | } |
Craig Mautner | 5eda9b3 | 2013-07-02 11:58:16 -0700 | [diff] [blame] | 2037 | } |
| 2038 | } |
| 2039 | } |
| 2040 | } |
| 2041 | |
Craig Mautner | a61bc65 | 2013-10-28 15:43:18 -0700 | [diff] [blame] | 2042 | /** If any activities below the top running one are in the INITIALIZING state and they have a |
| 2043 | * starting window displayed then remove that starting window. It is possible that the activity |
| 2044 | * in this state will never resumed in which case that starting window will be orphaned. */ |
| 2045 | void cancelInitializingActivities() { |
Filip Gruszczynski | 3e85ba2 | 2015-10-05 22:48:30 -0700 | [diff] [blame] | 2046 | final ActivityRecord topActivity = topRunningActivityLocked(); |
Craig Mautner | a61bc65 | 2013-10-28 15:43:18 -0700 | [diff] [blame] | 2047 | boolean aboveTop = true; |
Wale Ogunwale | 6874114 | 2016-05-17 09:40:02 -0700 | [diff] [blame] | 2048 | // We don't want to clear starting window for activities that aren't behind fullscreen |
| 2049 | // activities as we need to display their starting window until they are done initializing. |
| 2050 | boolean behindFullscreenActivity = false; |
Wale Ogunwale | 98742a5 | 2016-07-12 10:29:12 -0700 | [diff] [blame] | 2051 | |
| 2052 | if (getStackVisibilityLocked(null) == STACK_INVISIBLE) { |
| 2053 | // The stack is not visible, so no activity in it should be displaying a starting |
| 2054 | // window. Mark all activities below top and behind fullscreen. |
| 2055 | aboveTop = false; |
| 2056 | behindFullscreenActivity = true; |
| 2057 | } |
| 2058 | |
Craig Mautner | a61bc65 | 2013-10-28 15:43:18 -0700 | [diff] [blame] | 2059 | for (int taskNdx = mTaskHistory.size() - 1; taskNdx >= 0; --taskNdx) { |
| 2060 | final ArrayList<ActivityRecord> activities = mTaskHistory.get(taskNdx).mActivities; |
| 2061 | for (int activityNdx = activities.size() - 1; activityNdx >= 0; --activityNdx) { |
| 2062 | final ActivityRecord r = activities.get(activityNdx); |
| 2063 | if (aboveTop) { |
| 2064 | if (r == topActivity) { |
| 2065 | aboveTop = false; |
| 2066 | } |
Wale Ogunwale | 6874114 | 2016-05-17 09:40:02 -0700 | [diff] [blame] | 2067 | behindFullscreenActivity |= r.fullscreen; |
Craig Mautner | a61bc65 | 2013-10-28 15:43:18 -0700 | [diff] [blame] | 2068 | continue; |
| 2069 | } |
| 2070 | |
Wale Ogunwale | f40c11b | 2016-02-26 08:16:02 -0800 | [diff] [blame] | 2071 | if (r.state == ActivityState.INITIALIZING |
Wale Ogunwale | 6874114 | 2016-05-17 09:40:02 -0700 | [diff] [blame] | 2072 | && r.mStartingWindowState == STARTING_WINDOW_SHOWN |
| 2073 | && behindFullscreenActivity) { |
Wale Ogunwale | ee006da | 2015-03-30 14:49:25 -0700 | [diff] [blame] | 2074 | if (DEBUG_VISIBILITY) Slog.w(TAG_VISIBILITY, |
| 2075 | "Found orphaned starting window " + r); |
Wale Ogunwale | f40c11b | 2016-02-26 08:16:02 -0800 | [diff] [blame] | 2076 | r.mStartingWindowState = STARTING_WINDOW_REMOVED; |
Craig Mautner | a61bc65 | 2013-10-28 15:43:18 -0700 | [diff] [blame] | 2077 | mWindowManager.removeAppStartingWindow(r.appToken); |
| 2078 | } |
Wale Ogunwale | 6874114 | 2016-05-17 09:40:02 -0700 | [diff] [blame] | 2079 | |
| 2080 | behindFullscreenActivity |= r.fullscreen; |
Craig Mautner | a61bc65 | 2013-10-28 15:43:18 -0700 | [diff] [blame] | 2081 | } |
| 2082 | } |
| 2083 | } |
| 2084 | |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 2085 | /** |
| 2086 | * Ensure that the top activity in the stack is resumed. |
| 2087 | * |
| 2088 | * @param prev The previously resumed activity, for when in the process |
| 2089 | * of pausing; can be null to call from elsewhere. |
Wale Ogunwale | d046a01 | 2015-12-24 13:05:59 -0800 | [diff] [blame] | 2090 | * @param options Activity options. |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 2091 | * |
| 2092 | * @return Returns true if something is being resumed, or false if |
| 2093 | * nothing happened. |
Wale Ogunwale | d046a01 | 2015-12-24 13:05:59 -0800 | [diff] [blame] | 2094 | * |
| 2095 | * NOTE: It is not safe to call this method directly as it can cause an activity in a |
| 2096 | * non-focused stack to be resumed. |
| 2097 | * Use {@link ActivityStackSupervisor#resumeFocusedStackTopActivityLocked} to resume the |
| 2098 | * right activity for the current system state. |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 2099 | */ |
Wale Ogunwale | d046a01 | 2015-12-24 13:05:59 -0800 | [diff] [blame] | 2100 | boolean resumeTopActivityUncheckedLocked(ActivityRecord prev, ActivityOptions options) { |
Craig Mautner | 42d04db | 2014-11-06 12:13:23 -0800 | [diff] [blame] | 2101 | if (mStackSupervisor.inResumeTopActivity) { |
Craig Mautner | 544efa7 | 2014-09-04 16:41:20 -0700 | [diff] [blame] | 2102 | // Don't even start recursing. |
| 2103 | return false; |
| 2104 | } |
| 2105 | |
| 2106 | boolean result = false; |
| 2107 | try { |
| 2108 | // Protect against recursion. |
Craig Mautner | 42d04db | 2014-11-06 12:13:23 -0800 | [diff] [blame] | 2109 | mStackSupervisor.inResumeTopActivity = true; |
| 2110 | if (mService.mLockScreenShown == ActivityManagerService.LOCK_SCREEN_LEAVING) { |
| 2111 | mService.mLockScreenShown = ActivityManagerService.LOCK_SCREEN_HIDDEN; |
Jeff Brown | 9ef9401 | 2014-11-21 13:04:42 -0800 | [diff] [blame] | 2112 | mService.updateSleepIfNeededLocked(); |
Craig Mautner | 42d04db | 2014-11-06 12:13:23 -0800 | [diff] [blame] | 2113 | } |
Craig Mautner | 544efa7 | 2014-09-04 16:41:20 -0700 | [diff] [blame] | 2114 | result = resumeTopActivityInnerLocked(prev, options); |
| 2115 | } finally { |
Craig Mautner | 42d04db | 2014-11-06 12:13:23 -0800 | [diff] [blame] | 2116 | mStackSupervisor.inResumeTopActivity = false; |
Craig Mautner | 544efa7 | 2014-09-04 16:41:20 -0700 | [diff] [blame] | 2117 | } |
| 2118 | return result; |
| 2119 | } |
| 2120 | |
Chong Zhang | 6cda19c | 2016-06-14 19:07:56 -0700 | [diff] [blame] | 2121 | void setResumedActivityLocked(ActivityRecord r, String reason) { |
| 2122 | // TODO: move mResumedActivity to stack supervisor, |
| 2123 | // there should only be 1 global copy of resumed activity. |
| 2124 | mResumedActivity = r; |
Chong Zhang | d2cb311 | 2016-07-20 11:13:22 -0700 | [diff] [blame^] | 2125 | r.state = ActivityState.RESUMED; |
Chong Zhang | 6cda19c | 2016-06-14 19:07:56 -0700 | [diff] [blame] | 2126 | mService.setResumedActivityUncheckLocked(r, reason); |
| 2127 | r.task.touchActiveTime(); |
| 2128 | mRecentTasks.addLocked(r.task); |
| 2129 | } |
| 2130 | |
Chong Zhang | 280d332 | 2015-11-03 17:27:26 -0800 | [diff] [blame] | 2131 | private boolean resumeTopActivityInnerLocked(ActivityRecord prev, ActivityOptions options) { |
Wale Ogunwale | ee006da | 2015-03-30 14:49:25 -0700 | [diff] [blame] | 2132 | if (DEBUG_LOCKSCREEN) mService.logLockScreen(""); |
Craig Mautner | 5314a40 | 2013-09-26 12:40:16 -0700 | [diff] [blame] | 2133 | |
Dianne Hackborn | 7622a0f | 2014-09-30 14:31:42 -0700 | [diff] [blame] | 2134 | if (!mService.mBooting && !mService.mBooted) { |
| 2135 | // Not ready yet! |
| 2136 | return false; |
| 2137 | } |
| 2138 | |
Craig Mautner | df88d73 | 2014-01-27 09:21:32 -0800 | [diff] [blame] | 2139 | ActivityRecord parent = mActivityContainer.mParentActivity; |
Craig Mautner | f4c909b | 2014-04-17 18:39:38 -0700 | [diff] [blame] | 2140 | if ((parent != null && parent.state != ActivityState.RESUMED) || |
Craig Mautner | d163e75 | 2014-06-13 17:18:47 -0700 | [diff] [blame] | 2141 | !mActivityContainer.isAttachedLocked()) { |
Craig Mautner | df88d73 | 2014-01-27 09:21:32 -0800 | [diff] [blame] | 2142 | // Do not resume this stack if its parent is not resumed. |
| 2143 | // TODO: If in a loop, make sure that parent stack resumeTopActivity is called 1st. |
| 2144 | return false; |
| 2145 | } |
| 2146 | |
Wale Ogunwale | 2be760d | 2016-02-17 11:16:10 -0800 | [diff] [blame] | 2147 | mStackSupervisor.cancelInitializingActivities(); |
Craig Mautner | a61bc65 | 2013-10-28 15:43:18 -0700 | [diff] [blame] | 2148 | |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 2149 | // Find the first activity that is not finishing. |
Filip Gruszczynski | 3e85ba2 | 2015-10-05 22:48:30 -0700 | [diff] [blame] | 2150 | final ActivityRecord next = topRunningActivityLocked(); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 2151 | |
| 2152 | // Remember how we'll process this pause/resume situation, and ensure |
| 2153 | // that the state is reset however we wind up proceeding. |
Craig Mautner | de4ef02 | 2013-04-07 19:01:33 -0700 | [diff] [blame] | 2154 | final boolean userLeaving = mStackSupervisor.mUserLeaving; |
| 2155 | mStackSupervisor.mUserLeaving = false; |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 2156 | |
Craig Mautner | 84984fa | 2014-06-19 11:19:20 -0700 | [diff] [blame] | 2157 | final TaskRecord prevTask = prev != null ? prev.task : null; |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 2158 | if (next == null) { |
Wale Ogunwale | d697cea | 2015-02-20 17:19:49 -0800 | [diff] [blame] | 2159 | // There are no more activities! |
| 2160 | final String reason = "noMoreActivities"; |
Wale Ogunwale | d34e80c | 2016-03-23 17:08:44 -0700 | [diff] [blame] | 2161 | final int returnTaskType = prevTask == null || !prevTask.isOverHomeStack() |
| 2162 | ? HOME_ACTIVITY_TYPE : prevTask.getTaskToReturnTo(); |
| 2163 | if (!mFullscreen && adjustFocusToNextFocusableStackLocked(returnTaskType, reason)) { |
Wale Ogunwale | d697cea | 2015-02-20 17:19:49 -0800 | [diff] [blame] | 2164 | // Try to move focus to the next visible stack with a running activity if this |
| 2165 | // stack is not covering the entire screen. |
Wale Ogunwale | 4cea0f5 | 2015-12-25 06:30:31 -0800 | [diff] [blame] | 2166 | return mStackSupervisor.resumeFocusedStackTopActivityLocked( |
| 2167 | mStackSupervisor.getFocusedStack(), prev, null); |
Wale Ogunwale | d697cea | 2015-02-20 17:19:49 -0800 | [diff] [blame] | 2168 | } |
Wale Ogunwale | 4cea0f5 | 2015-12-25 06:30:31 -0800 | [diff] [blame] | 2169 | |
Wale Ogunwale | d697cea | 2015-02-20 17:19:49 -0800 | [diff] [blame] | 2170 | // Let's just start up the Launcher... |
Craig Mautner | de4ef02 | 2013-04-07 19:01:33 -0700 | [diff] [blame] | 2171 | ActivityOptions.abort(options); |
Wale Ogunwale | 0fc365c | 2015-05-25 19:35:42 -0700 | [diff] [blame] | 2172 | if (DEBUG_STATES) Slog.d(TAG_STATES, |
| 2173 | "resumeTopActivityLocked: No more activities go home"); |
Craig Mautner | cf910b0 | 2013-04-23 11:23:27 -0700 | [diff] [blame] | 2174 | if (DEBUG_STACK) mStackSupervisor.validateTopActivitiesLocked(); |
Craig Mautner | e0a3884 | 2013-12-16 16:14:02 -0800 | [diff] [blame] | 2175 | // Only resume home if on home display |
Craig Mautner | 84984fa | 2014-06-19 11:19:20 -0700 | [diff] [blame] | 2176 | return isOnHomeDisplay() && |
Wale Ogunwale | d697cea | 2015-02-20 17:19:49 -0800 | [diff] [blame] | 2177 | mStackSupervisor.resumeHomeStackTask(returnTaskType, prev, reason); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 2178 | } |
| 2179 | |
| 2180 | next.delayedResume = false; |
Craig Mautner | 5854780 | 2013-03-05 08:23:53 -0800 | [diff] [blame] | 2181 | |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 2182 | // If the top activity is the resumed one, nothing to do. |
Craig Mautner | de4ef02 | 2013-04-07 19:01:33 -0700 | [diff] [blame] | 2183 | if (mResumedActivity == next && next.state == ActivityState.RESUMED && |
| 2184 | mStackSupervisor.allResumedActivitiesComplete()) { |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 2185 | // Make sure we have executed any pending transitions, since there |
| 2186 | // should be nothing left to do at this point. |
Craig Mautner | ce5f3cb | 2013-04-22 08:58:54 -0700 | [diff] [blame] | 2187 | mWindowManager.executeAppTransition(); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 2188 | mNoAnimActivities.clear(); |
Dianne Hackborn | 8437587 | 2012-06-01 19:03:50 -0700 | [diff] [blame] | 2189 | ActivityOptions.abort(options); |
Wale Ogunwale | 0fc365c | 2015-05-25 19:35:42 -0700 | [diff] [blame] | 2190 | if (DEBUG_STATES) Slog.d(TAG_STATES, |
| 2191 | "resumeTopActivityLocked: Top activity resumed " + next); |
Craig Mautner | cf910b0 | 2013-04-23 11:23:27 -0700 | [diff] [blame] | 2192 | if (DEBUG_STACK) mStackSupervisor.validateTopActivitiesLocked(); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 2193 | return false; |
| 2194 | } |
| 2195 | |
Craig Mautner | 525f3d9 | 2013-05-07 14:01:50 -0700 | [diff] [blame] | 2196 | final TaskRecord nextTask = next.task; |
bulic | ccd23071 | 2014-05-12 14:34:50 -0700 | [diff] [blame] | 2197 | if (prevTask != null && prevTask.stack == this && |
Craig Mautner | 84984fa | 2014-06-19 11:19:20 -0700 | [diff] [blame] | 2198 | prevTask.isOverHomeStack() && prev.finishing && prev.frontOfTask) { |
Craig Mautner | cf910b0 | 2013-04-23 11:23:27 -0700 | [diff] [blame] | 2199 | if (DEBUG_STACK) mStackSupervisor.validateTopActivitiesLocked(); |
Craig Mautner | 525f3d9 | 2013-05-07 14:01:50 -0700 | [diff] [blame] | 2200 | if (prevTask == nextTask) { |
Craig Mautner | 1aa9d0d3f | 2013-12-16 15:58:31 -0800 | [diff] [blame] | 2201 | prevTask.setFrontOfTask(); |
Craig Mautner | 525f3d9 | 2013-05-07 14:01:50 -0700 | [diff] [blame] | 2202 | } else if (prevTask != topTask()) { |
Craig Mautner | 84984fa | 2014-06-19 11:19:20 -0700 | [diff] [blame] | 2203 | // 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] | 2204 | // 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] | 2205 | final int taskNdx = mTaskHistory.indexOf(prevTask) + 1; |
Craig Mautner | 84984fa | 2014-06-19 11:19:20 -0700 | [diff] [blame] | 2206 | mTaskHistory.get(taskNdx).setTaskToReturnTo(HOME_ACTIVITY_TYPE); |
louis_chang | 2d094e9 | 2015-01-21 19:01:52 +0800 | [diff] [blame] | 2207 | } else if (!isOnHomeDisplay()) { |
| 2208 | return false; |
| 2209 | } else if (!isHomeStack()){ |
Wale Ogunwale | 0fc365c | 2015-05-25 19:35:42 -0700 | [diff] [blame] | 2210 | if (DEBUG_STATES) Slog.d(TAG_STATES, |
Craig Mautner | e0a3884 | 2013-12-16 16:14:02 -0800 | [diff] [blame] | 2211 | "resumeTopActivityLocked: Launching home next"); |
Craig Mautner | 84984fa | 2014-06-19 11:19:20 -0700 | [diff] [blame] | 2212 | final int returnTaskType = prevTask == null || !prevTask.isOverHomeStack() ? |
| 2213 | HOME_ACTIVITY_TYPE : prevTask.getTaskToReturnTo(); |
| 2214 | return isOnHomeDisplay() && |
Craig Mautner | 3c878f2 | 2015-01-26 13:57:19 -0800 | [diff] [blame] | 2215 | mStackSupervisor.resumeHomeStackTask(returnTaskType, prev, "prevFinished"); |
Craig Mautner | e418ecd | 2013-05-01 17:02:29 -0700 | [diff] [blame] | 2216 | } |
Craig Mautner | de4ef02 | 2013-04-07 19:01:33 -0700 | [diff] [blame] | 2217 | } |
| 2218 | |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 2219 | // If we are sleeping, and there is no resumed activity, and the top |
| 2220 | // activity is paused, well that is the state we want. |
Fyodor Kupolov | 9b80b94 | 2016-06-16 16:29:05 -0700 | [diff] [blame] | 2221 | if (mService.isSleepingOrShuttingDownLocked() |
p13451 | dbad287 | 2012-04-18 11:39:23 +0900 | [diff] [blame] | 2222 | && mLastPausedActivity == next |
Craig Mautner | 5314a40 | 2013-09-26 12:40:16 -0700 | [diff] [blame] | 2223 | && mStackSupervisor.allPausedActivitiesComplete()) { |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 2224 | // Make sure we have executed any pending transitions, since there |
| 2225 | // should be nothing left to do at this point. |
Craig Mautner | ce5f3cb | 2013-04-22 08:58:54 -0700 | [diff] [blame] | 2226 | mWindowManager.executeAppTransition(); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 2227 | mNoAnimActivities.clear(); |
Dianne Hackborn | 8437587 | 2012-06-01 19:03:50 -0700 | [diff] [blame] | 2228 | ActivityOptions.abort(options); |
Wale Ogunwale | 0fc365c | 2015-05-25 19:35:42 -0700 | [diff] [blame] | 2229 | if (DEBUG_STATES) Slog.d(TAG_STATES, |
| 2230 | "resumeTopActivityLocked: Going to sleep and all paused"); |
Craig Mautner | cf910b0 | 2013-04-23 11:23:27 -0700 | [diff] [blame] | 2231 | if (DEBUG_STACK) mStackSupervisor.validateTopActivitiesLocked(); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 2232 | return false; |
| 2233 | } |
Dianne Hackborn | 80a4af2 | 2012-08-27 19:18:31 -0700 | [diff] [blame] | 2234 | |
| 2235 | // Make sure that the user who owns this activity is started. If not, |
| 2236 | // we will just leave it as is because someone should be bringing |
| 2237 | // another user's activities to the top of the stack. |
Fyodor Kupolov | 610acda | 2015-10-19 18:44:07 -0700 | [diff] [blame] | 2238 | if (!mService.mUserController.hasStartedUserState(next.userId)) { |
Dianne Hackborn | 80a4af2 | 2012-08-27 19:18:31 -0700 | [diff] [blame] | 2239 | Slog.w(TAG, "Skipping resume of top activity " + next |
| 2240 | + ": user " + next.userId + " is stopped"); |
Craig Mautner | cf910b0 | 2013-04-23 11:23:27 -0700 | [diff] [blame] | 2241 | if (DEBUG_STACK) mStackSupervisor.validateTopActivitiesLocked(); |
Dianne Hackborn | 80a4af2 | 2012-08-27 19:18:31 -0700 | [diff] [blame] | 2242 | return false; |
| 2243 | } |
| 2244 | |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 2245 | // The activity may be waiting for stop, but that is no longer |
| 2246 | // appropriate for it. |
Craig Mautner | de4ef02 | 2013-04-07 19:01:33 -0700 | [diff] [blame] | 2247 | mStackSupervisor.mStoppingActivities.remove(next); |
Craig Mautner | 0eea92c | 2013-05-16 13:35:39 -0700 | [diff] [blame] | 2248 | mStackSupervisor.mGoingToSleepActivities.remove(next); |
Dianne Hackborn | 4eba96b | 2011-01-21 13:34:36 -0800 | [diff] [blame] | 2249 | next.sleeping = false; |
Craig Mautner | de4ef02 | 2013-04-07 19:01:33 -0700 | [diff] [blame] | 2250 | mStackSupervisor.mWaitingVisibleActivities.remove(next); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 2251 | |
Wale Ogunwale | ee006da | 2015-03-30 14:49:25 -0700 | [diff] [blame] | 2252 | if (DEBUG_SWITCH) Slog.v(TAG_SWITCH, "Resuming " + next); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 2253 | |
Wale Ogunwale | 5658e4b | 2016-02-12 12:22:19 -0800 | [diff] [blame] | 2254 | // 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] | 2255 | if (!mStackSupervisor.allPausedActivitiesComplete()) { |
Wale Ogunwale | ee006da | 2015-03-30 14:49:25 -0700 | [diff] [blame] | 2256 | if (DEBUG_SWITCH || DEBUG_PAUSE || DEBUG_STATES) Slog.v(TAG_PAUSE, |
Craig Mautner | ac6f843 | 2013-07-17 13:24:59 -0700 | [diff] [blame] | 2257 | "resumeTopActivityLocked: Skip resume: some activity pausing."); |
Craig Mautner | cf910b0 | 2013-04-23 11:23:27 -0700 | [diff] [blame] | 2258 | if (DEBUG_STACK) mStackSupervisor.validateTopActivitiesLocked(); |
Dianne Hackborn | 621e2fe | 2012-02-16 17:07:33 -0800 | [diff] [blame] | 2259 | return false; |
| 2260 | } |
| 2261 | |
Dianne Hackborn | 3d07c94 | 2015-03-13 18:02:54 -0700 | [diff] [blame] | 2262 | mStackSupervisor.setLaunchSource(next.info.applicationInfo.uid); |
| 2263 | |
Wale Ogunwale | 5658e4b | 2016-02-12 12:22:19 -0800 | [diff] [blame] | 2264 | // We need to start pausing the current activity so the top one can be resumed... |
| 2265 | final boolean dontWaitForPause = (next.info.flags & FLAG_RESUME_WHILE_PAUSING) != 0; |
Dianne Hackborn | a4e102e | 2014-09-04 22:52:27 -0700 | [diff] [blame] | 2266 | boolean pausing = mStackSupervisor.pauseBackStacks(userLeaving, true, dontWaitForPause); |
Craig Mautner | eb95786 | 2013-04-24 15:34:32 -0700 | [diff] [blame] | 2267 | if (mResumedActivity != null) { |
Wale Ogunwale | 0fc365c | 2015-05-25 19:35:42 -0700 | [diff] [blame] | 2268 | if (DEBUG_STATES) Slog.d(TAG_STATES, |
| 2269 | "resumeTopActivityLocked: Pausing " + mResumedActivity); |
Craig Mautner | e042bf2 | 2014-11-11 11:28:43 -0800 | [diff] [blame] | 2270 | pausing |= startPausingLocked(userLeaving, false, true, dontWaitForPause); |
Craig Mautner | eb95786 | 2013-04-24 15:34:32 -0700 | [diff] [blame] | 2271 | } |
| 2272 | if (pausing) { |
Wale Ogunwale | 0fc365c | 2015-05-25 19:35:42 -0700 | [diff] [blame] | 2273 | if (DEBUG_SWITCH || DEBUG_STATES) Slog.v(TAG_STATES, |
Craig Mautner | ac6f843 | 2013-07-17 13:24:59 -0700 | [diff] [blame] | 2274 | "resumeTopActivityLocked: Skip resume: need to start pausing"); |
Dianne Hackborn | ad9b3211 | 2012-09-17 15:35:01 -0700 | [diff] [blame] | 2275 | // At this point we want to put the upcoming activity's process |
| 2276 | // at the top of the LRU list, since we know we will be needing it |
| 2277 | // very soon and it would be a waste to let it get killed if it |
| 2278 | // happens to be sitting towards the end. |
| 2279 | if (next.app != null && next.app.thread != null) { |
Dianne Hackborn | db92608 | 2013-10-31 16:32:44 -0700 | [diff] [blame] | 2280 | mService.updateLruProcessLocked(next.app, true, null); |
Dianne Hackborn | ad9b3211 | 2012-09-17 15:35:01 -0700 | [diff] [blame] | 2281 | } |
Craig Mautner | cf910b0 | 2013-04-23 11:23:27 -0700 | [diff] [blame] | 2282 | if (DEBUG_STACK) mStackSupervisor.validateTopActivitiesLocked(); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 2283 | return true; |
Wale Ogunwale | cac5c32 | 2016-05-23 10:56:33 -0700 | [diff] [blame] | 2284 | } else if (mResumedActivity == next && next.state == ActivityState.RESUMED && |
| 2285 | mStackSupervisor.allResumedActivitiesComplete()) { |
| 2286 | // It is possible for the activity to be resumed when we paused back stacks above if the |
| 2287 | // next activity doesn't have to wait for pause to complete. |
| 2288 | // So, nothing else to-do except: |
| 2289 | // Make sure we have executed any pending transitions, since there |
| 2290 | // should be nothing left to do at this point. |
| 2291 | mWindowManager.executeAppTransition(); |
| 2292 | mNoAnimActivities.clear(); |
| 2293 | ActivityOptions.abort(options); |
| 2294 | if (DEBUG_STATES) Slog.d(TAG_STATES, |
| 2295 | "resumeTopActivityLocked: Top activity resumed (dontWaitForPause) " + next); |
| 2296 | if (DEBUG_STACK) mStackSupervisor.validateTopActivitiesLocked(); |
| 2297 | return true; |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 2298 | } |
| 2299 | |
Christopher Tate | d3f175c | 2012-06-14 14:16:54 -0700 | [diff] [blame] | 2300 | // If the most recent activity was noHistory but was only stopped rather |
| 2301 | // than stopped+finished because the device went to sleep, we need to make |
| 2302 | // sure to finish it as we're making a new activity topmost. |
Fyodor Kupolov | 9b80b94 | 2016-06-16 16:29:05 -0700 | [diff] [blame] | 2303 | if (mService.isSleepingLocked() && mLastNoHistoryActivity != null && |
Craig Mautner | 0f92274 | 2013-08-06 08:44:42 -0700 | [diff] [blame] | 2304 | !mLastNoHistoryActivity.finishing) { |
Wale Ogunwale | 0fc365c | 2015-05-25 19:35:42 -0700 | [diff] [blame] | 2305 | if (DEBUG_STATES) Slog.d(TAG_STATES, |
| 2306 | "no-history finish of " + mLastNoHistoryActivity + " on new resume"); |
Craig Mautner | 0f92274 | 2013-08-06 08:44:42 -0700 | [diff] [blame] | 2307 | requestFinishActivityLocked(mLastNoHistoryActivity.appToken, Activity.RESULT_CANCELED, |
Todd Kennedy | 539db51 | 2014-12-15 09:57:55 -0800 | [diff] [blame] | 2308 | null, "resume-no-history", false); |
Craig Mautner | 0f92274 | 2013-08-06 08:44:42 -0700 | [diff] [blame] | 2309 | mLastNoHistoryActivity = null; |
Christopher Tate | d3f175c | 2012-06-14 14:16:54 -0700 | [diff] [blame] | 2310 | } |
| 2311 | |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 2312 | if (prev != null && prev != next) { |
Craig Mautner | 8c14c15 | 2015-01-15 17:32:07 -0800 | [diff] [blame] | 2313 | if (!mStackSupervisor.mWaitingVisibleActivities.contains(prev) |
| 2314 | && next != null && !next.nowVisible) { |
Craig Mautner | de4ef02 | 2013-04-07 19:01:33 -0700 | [diff] [blame] | 2315 | mStackSupervisor.mWaitingVisibleActivities.add(prev); |
Wale Ogunwale | ee006da | 2015-03-30 14:49:25 -0700 | [diff] [blame] | 2316 | if (DEBUG_SWITCH) Slog.v(TAG_SWITCH, |
| 2317 | "Resuming top, waiting visible to hide: " + prev); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 2318 | } else { |
| 2319 | // The next activity is already visible, so hide the previous |
| 2320 | // activity's windows right now so we can show the new one ASAP. |
| 2321 | // We only do this if the previous is finishing, which should mean |
| 2322 | // it is on top of the one being resumed so hiding it quickly |
| 2323 | // is good. Otherwise, we want to do the normal route of allowing |
| 2324 | // the resumed activity to be shown so we can decide if the |
| 2325 | // previous should actually be hidden depending on whether the |
| 2326 | // new one is found to be full-screen or not. |
| 2327 | if (prev.finishing) { |
Craig Mautner | ce5f3cb | 2013-04-22 08:58:54 -0700 | [diff] [blame] | 2328 | mWindowManager.setAppVisibility(prev.appToken, false); |
Wale Ogunwale | ee006da | 2015-03-30 14:49:25 -0700 | [diff] [blame] | 2329 | if (DEBUG_SWITCH) Slog.v(TAG_SWITCH, |
| 2330 | "Not waiting for visible to hide: " + prev + ", waitingVisible=" |
Craig Mautner | 8c14c15 | 2015-01-15 17:32:07 -0800 | [diff] [blame] | 2331 | + mStackSupervisor.mWaitingVisibleActivities.contains(prev) |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 2332 | + ", nowVisible=" + next.nowVisible); |
| 2333 | } else { |
Wale Ogunwale | ee006da | 2015-03-30 14:49:25 -0700 | [diff] [blame] | 2334 | if (DEBUG_SWITCH) Slog.v(TAG_SWITCH, |
Craig Mautner | 8c14c15 | 2015-01-15 17:32:07 -0800 | [diff] [blame] | 2335 | "Previous already visible but still waiting to hide: " + prev |
Wale Ogunwale | ee006da | 2015-03-30 14:49:25 -0700 | [diff] [blame] | 2336 | + ", waitingVisible=" |
| 2337 | + mStackSupervisor.mWaitingVisibleActivities.contains(prev) |
| 2338 | + ", nowVisible=" + next.nowVisible); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 2339 | } |
| 2340 | } |
| 2341 | } |
| 2342 | |
Dianne Hackborn | e7f9721 | 2011-02-24 14:40:20 -0800 | [diff] [blame] | 2343 | // Launching this app's activity, make sure the app is no longer |
| 2344 | // considered stopped. |
| 2345 | try { |
| 2346 | AppGlobals.getPackageManager().setPackageStoppedState( |
Amith Yamasani | 483f3b0 | 2012-03-13 16:08:00 -0700 | [diff] [blame] | 2347 | next.packageName, false, next.userId); /* TODO: Verify if correct userid */ |
Dianne Hackborn | e7f9721 | 2011-02-24 14:40:20 -0800 | [diff] [blame] | 2348 | } catch (RemoteException e1) { |
Dianne Hackborn | a925cd4 | 2011-03-10 13:18:20 -0800 | [diff] [blame] | 2349 | } catch (IllegalArgumentException e) { |
| 2350 | Slog.w(TAG, "Failed trying to unstop package " |
| 2351 | + next.packageName + ": " + e); |
Dianne Hackborn | e7f9721 | 2011-02-24 14:40:20 -0800 | [diff] [blame] | 2352 | } |
| 2353 | |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 2354 | // We are starting up the next activity, so tell the window manager |
| 2355 | // that the previous one will be hidden soon. This way it can know |
| 2356 | // to ignore it when computing the desired screen orientation. |
Craig Mautner | 525f3d9 | 2013-05-07 14:01:50 -0700 | [diff] [blame] | 2357 | boolean anim = true; |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 2358 | if (prev != null) { |
| 2359 | if (prev.finishing) { |
Wale Ogunwale | ee006da | 2015-03-30 14:49:25 -0700 | [diff] [blame] | 2360 | if (DEBUG_TRANSITION) Slog.v(TAG_TRANSITION, |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 2361 | "Prepare close transition: prev=" + prev); |
| 2362 | if (mNoAnimActivities.contains(prev)) { |
Craig Mautner | 525f3d9 | 2013-05-07 14:01:50 -0700 | [diff] [blame] | 2363 | anim = false; |
Jorim Jaggi | af80db4 | 2016-04-07 19:19:15 -0700 | [diff] [blame] | 2364 | mWindowManager.prepareAppTransition(TRANSIT_NONE, false); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 2365 | } else { |
Craig Mautner | ce5f3cb | 2013-04-22 08:58:54 -0700 | [diff] [blame] | 2366 | mWindowManager.prepareAppTransition(prev.task == next.task |
Jorim Jaggi | af80db4 | 2016-04-07 19:19:15 -0700 | [diff] [blame] | 2367 | ? TRANSIT_ACTIVITY_CLOSE |
| 2368 | : TRANSIT_TASK_CLOSE, false); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 2369 | } |
Craig Mautner | ce5f3cb | 2013-04-22 08:58:54 -0700 | [diff] [blame] | 2370 | mWindowManager.setAppVisibility(prev.appToken, false); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 2371 | } else { |
Wale Ogunwale | ee006da | 2015-03-30 14:49:25 -0700 | [diff] [blame] | 2372 | if (DEBUG_TRANSITION) Slog.v(TAG_TRANSITION, |
| 2373 | "Prepare open transition: prev=" + prev); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 2374 | if (mNoAnimActivities.contains(next)) { |
Craig Mautner | 525f3d9 | 2013-05-07 14:01:50 -0700 | [diff] [blame] | 2375 | anim = false; |
Jorim Jaggi | af80db4 | 2016-04-07 19:19:15 -0700 | [diff] [blame] | 2376 | mWindowManager.prepareAppTransition(TRANSIT_NONE, false); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 2377 | } else { |
Craig Mautner | ce5f3cb | 2013-04-22 08:58:54 -0700 | [diff] [blame] | 2378 | mWindowManager.prepareAppTransition(prev.task == next.task |
Jorim Jaggi | af80db4 | 2016-04-07 19:19:15 -0700 | [diff] [blame] | 2379 | ? TRANSIT_ACTIVITY_OPEN |
Craig Mautner | bb74246 | 2014-07-07 15:28:55 -0700 | [diff] [blame] | 2380 | : next.mLaunchTaskBehind |
Jorim Jaggi | af80db4 | 2016-04-07 19:19:15 -0700 | [diff] [blame] | 2381 | ? TRANSIT_TASK_OPEN_BEHIND |
| 2382 | : TRANSIT_TASK_OPEN, false); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 2383 | } |
| 2384 | } |
Craig Mautner | 967212c | 2013-04-13 21:10:58 -0700 | [diff] [blame] | 2385 | } else { |
Wale Ogunwale | ee006da | 2015-03-30 14:49:25 -0700 | [diff] [blame] | 2386 | if (DEBUG_TRANSITION) Slog.v(TAG_TRANSITION, "Prepare open transition: no previous"); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 2387 | if (mNoAnimActivities.contains(next)) { |
Craig Mautner | 525f3d9 | 2013-05-07 14:01:50 -0700 | [diff] [blame] | 2388 | anim = false; |
Jorim Jaggi | af80db4 | 2016-04-07 19:19:15 -0700 | [diff] [blame] | 2389 | mWindowManager.prepareAppTransition(TRANSIT_NONE, false); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 2390 | } else { |
Jorim Jaggi | af80db4 | 2016-04-07 19:19:15 -0700 | [diff] [blame] | 2391 | mWindowManager.prepareAppTransition(TRANSIT_ACTIVITY_OPEN, false); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 2392 | } |
| 2393 | } |
Adam Powell | cfbe9be | 2013-11-06 14:58:58 -0800 | [diff] [blame] | 2394 | |
| 2395 | Bundle resumeAnimOptions = null; |
Craig Mautner | 525f3d9 | 2013-05-07 14:01:50 -0700 | [diff] [blame] | 2396 | if (anim) { |
Adam Powell | cfbe9be | 2013-11-06 14:58:58 -0800 | [diff] [blame] | 2397 | ActivityOptions opts = next.getOptionsForTargetActivityLocked(); |
| 2398 | if (opts != null) { |
| 2399 | resumeAnimOptions = opts.toBundle(); |
| 2400 | } |
Dianne Hackborn | 7a2195c | 2012-03-19 17:38:00 -0700 | [diff] [blame] | 2401 | next.applyOptionsLocked(); |
| 2402 | } else { |
| 2403 | next.clearOptionsLocked(); |
| 2404 | } |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 2405 | |
Craig Mautner | cf910b0 | 2013-04-23 11:23:27 -0700 | [diff] [blame] | 2406 | ActivityStack lastStack = mStackSupervisor.getLastStack(); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 2407 | if (next.app != null && next.app.thread != null) { |
Chong Zhang | dea4bd9 | 2016-03-15 12:50:03 -0700 | [diff] [blame] | 2408 | if (DEBUG_SWITCH) Slog.v(TAG_SWITCH, "Resume running: " + next |
| 2409 | + " stopped=" + next.stopped + " visible=" + next.visible); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 2410 | |
Chong Zhang | d127c6d | 2016-05-02 16:36:41 -0700 | [diff] [blame] | 2411 | // If the previous activity is translucent, force a visibility update of |
| 2412 | // the next activity, so that it's added to WM's opening app list, and |
| 2413 | // transition animation can be set up properly. |
| 2414 | // For example, pressing Home button with a translucent activity in focus. |
| 2415 | // Launcher is already visible in this case. If we don't add it to opening |
| 2416 | // apps, maybeUpdateTransitToWallpaper() will fail to identify this as a |
| 2417 | // TRANSIT_WALLPAPER_OPEN animation, and run some funny animation. |
| 2418 | final boolean lastActivityTranslucent = lastStack != null |
| 2419 | && (!lastStack.mFullscreen |
| 2420 | || (lastStack.mLastPausedActivity != null |
| 2421 | && !lastStack.mLastPausedActivity.fullscreen)); |
| 2422 | |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 2423 | // This activity is now becoming visible. |
Chong Zhang | d127c6d | 2016-05-02 16:36:41 -0700 | [diff] [blame] | 2424 | if (!next.visible || next.stopped || lastActivityTranslucent) { |
Jorim Jaggi | 1b025a6 | 2016-02-03 19:27:49 -0800 | [diff] [blame] | 2425 | mWindowManager.setAppVisibility(next.appToken, true); |
| 2426 | } |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 2427 | |
Dianne Hackborn | 2a29b3a | 2012-03-15 15:48:38 -0700 | [diff] [blame] | 2428 | // schedule launch ticks to collect information about slow apps. |
| 2429 | next.startLaunchTickingLocked(); |
| 2430 | |
Craig Mautner | f88c50f | 2013-04-18 19:25:12 -0700 | [diff] [blame] | 2431 | ActivityRecord lastResumedActivity = |
| 2432 | lastStack == null ? null :lastStack.mResumedActivity; |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 2433 | ActivityState lastState = next.state; |
| 2434 | |
| 2435 | mService.updateCpuStats(); |
Craig Mautner | 5854780 | 2013-03-05 08:23:53 -0800 | [diff] [blame] | 2436 | |
Wale Ogunwale | 0fc365c | 2015-05-25 19:35:42 -0700 | [diff] [blame] | 2437 | 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] | 2438 | |
| 2439 | setResumedActivityLocked(next, "resumeTopActivityInnerLocked"); |
| 2440 | |
Dianne Hackborn | db92608 | 2013-10-31 16:32:44 -0700 | [diff] [blame] | 2441 | mService.updateLruProcessLocked(next.app, true, null); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 2442 | updateLRUListLocked(next); |
Dianne Hackborn | db92608 | 2013-10-31 16:32:44 -0700 | [diff] [blame] | 2443 | mService.updateOomAdjLocked(); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 2444 | |
| 2445 | // Have the window manager re-evaluate the orientation of |
| 2446 | // the screen based on the new activity order. |
Craig Mautner | 525f3d9 | 2013-05-07 14:01:50 -0700 | [diff] [blame] | 2447 | boolean notUpdated = true; |
Wale Ogunwale | 1e60e0c | 2015-10-28 13:36:10 -0700 | [diff] [blame] | 2448 | if (mStackSupervisor.isFocusedStack(this)) { |
Craig Mautner | ce5f3cb | 2013-04-22 08:58:54 -0700 | [diff] [blame] | 2449 | Configuration config = mWindowManager.updateOrientationFromAppTokens( |
Craig Mautner | 8d341ef | 2013-03-26 09:03:27 -0700 | [diff] [blame] | 2450 | mService.mConfiguration, |
| 2451 | next.mayFreezeScreenLocked(next.app) ? next.appToken : null); |
| 2452 | if (config != null) { |
| 2453 | next.frozenBeforeDestroy = true; |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 2454 | } |
Maxim Bogatov | 0507530 | 2015-05-19 18:33:08 -0700 | [diff] [blame] | 2455 | notUpdated = !mService.updateConfigurationLocked(config, next, false); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 2456 | } |
Craig Mautner | 8d341ef | 2013-03-26 09:03:27 -0700 | [diff] [blame] | 2457 | |
Craig Mautner | 525f3d9 | 2013-05-07 14:01:50 -0700 | [diff] [blame] | 2458 | if (notUpdated) { |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 2459 | // The configuration update wasn't able to keep the existing |
| 2460 | // instance of the activity, and instead started a new one. |
| 2461 | // We should be all done, but let's just make sure our activity |
| 2462 | // is still at the top and schedule another run if something |
| 2463 | // weird happened. |
Filip Gruszczynski | 3e85ba2 | 2015-10-05 22:48:30 -0700 | [diff] [blame] | 2464 | ActivityRecord nextNext = topRunningActivityLocked(); |
Wale Ogunwale | 0fc365c | 2015-05-25 19:35:42 -0700 | [diff] [blame] | 2465 | if (DEBUG_SWITCH || DEBUG_STATES) Slog.i(TAG_STATES, |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 2466 | "Activity config changed during resume: " + next |
| 2467 | + ", new next: " + nextNext); |
| 2468 | if (nextNext != next) { |
| 2469 | // Do over! |
Craig Mautner | 05d2903 | 2013-05-03 13:40:13 -0700 | [diff] [blame] | 2470 | mStackSupervisor.scheduleResumeTopActivities(); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 2471 | } |
Chong Zhang | d2cb311 | 2016-07-20 11:13:22 -0700 | [diff] [blame^] | 2472 | if (!next.visible || next.stopped) { |
| 2473 | mWindowManager.setAppVisibility(next.appToken, true); |
Craig Mautner | de4ef02 | 2013-04-07 19:01:33 -0700 | [diff] [blame] | 2474 | } |
Chong Zhang | d2cb311 | 2016-07-20 11:13:22 -0700 | [diff] [blame^] | 2475 | completeResumeLocked(next); |
Craig Mautner | cf910b0 | 2013-04-23 11:23:27 -0700 | [diff] [blame] | 2476 | if (DEBUG_STACK) mStackSupervisor.validateTopActivitiesLocked(); |
Chong Zhang | d2cb311 | 2016-07-20 11:13:22 -0700 | [diff] [blame^] | 2477 | return true; |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 2478 | } |
Craig Mautner | 5854780 | 2013-03-05 08:23:53 -0800 | [diff] [blame] | 2479 | |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 2480 | try { |
| 2481 | // Deliver all pending results. |
Craig Mautner | 05d6272ba | 2013-02-11 09:39:27 -0800 | [diff] [blame] | 2482 | ArrayList<ResultInfo> a = next.results; |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 2483 | if (a != null) { |
| 2484 | final int N = a.size(); |
| 2485 | if (!next.finishing && N > 0) { |
Wale Ogunwale | ee006da | 2015-03-30 14:49:25 -0700 | [diff] [blame] | 2486 | if (DEBUG_RESULTS) Slog.v(TAG_RESULTS, |
| 2487 | "Delivering results to " + next + ": " + a); |
Dianne Hackborn | be70785 | 2011-11-11 14:32:10 -0800 | [diff] [blame] | 2488 | next.app.thread.scheduleSendResult(next.appToken, a); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 2489 | } |
| 2490 | } |
| 2491 | |
| 2492 | if (next.newIntents != null) { |
Dianne Hackborn | be70785 | 2011-11-11 14:32:10 -0800 | [diff] [blame] | 2493 | next.app.thread.scheduleNewIntent(next.newIntents, next.appToken); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 2494 | } |
| 2495 | |
Wale Ogunwale | 8d5a542 | 2016-03-03 18:28:21 -0800 | [diff] [blame] | 2496 | // Well the app will no longer be stopped. |
| 2497 | // Clear app token stopped state in window manager if needed. |
| 2498 | mWindowManager.notifyAppStopped(next.appToken, false); |
| 2499 | |
Craig Mautner | 299f960 | 2015-01-26 09:47:33 -0800 | [diff] [blame] | 2500 | EventLog.writeEvent(EventLogTags.AM_RESUME_ACTIVITY, next.userId, |
| 2501 | System.identityHashCode(next), next.task.taskId, next.shortComponentName); |
Craig Mautner | 5854780 | 2013-03-05 08:23:53 -0800 | [diff] [blame] | 2502 | |
Dianne Hackborn | 4eba96b | 2011-01-21 13:34:36 -0800 | [diff] [blame] | 2503 | next.sleeping = false; |
Alan Viverette | 5f31b98 | 2016-06-21 14:46:14 -0400 | [diff] [blame] | 2504 | mService.showUnsupportedZoomDialogIfNeededLocked(next); |
Craig Mautner | 2420ead | 2013-04-01 17:13:20 -0700 | [diff] [blame] | 2505 | mService.showAskCompatModeDialogLocked(next); |
Dianne Hackborn | 905577f | 2011-09-07 18:31:28 -0700 | [diff] [blame] | 2506 | next.app.pendingUiClean = true; |
Dianne Hackborn | 4870e9d | 2015-04-08 16:55:47 -0700 | [diff] [blame] | 2507 | next.app.forceProcessStateUpTo(mService.mTopProcessState); |
George Mount | 2c92c97 | 2014-03-20 09:38:23 -0700 | [diff] [blame] | 2508 | next.clearOptionsLocked(); |
Dianne Hackborn | a413dc0 | 2013-07-12 12:02:55 -0700 | [diff] [blame] | 2509 | next.app.thread.scheduleResumeActivity(next.appToken, next.app.repProcState, |
Adam Powell | cfbe9be | 2013-11-06 14:58:58 -0800 | [diff] [blame] | 2510 | mService.isNextTransitionForward(), resumeAnimOptions); |
Craig Mautner | 5854780 | 2013-03-05 08:23:53 -0800 | [diff] [blame] | 2511 | |
Wale Ogunwale | 0fc365c | 2015-05-25 19:35:42 -0700 | [diff] [blame] | 2512 | if (DEBUG_STATES) Slog.d(TAG_STATES, "resumeTopActivityLocked: Resumed " + next); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 2513 | } catch (Exception e) { |
| 2514 | // Whoops, need to restart this activity! |
Wale Ogunwale | 0fc365c | 2015-05-25 19:35:42 -0700 | [diff] [blame] | 2515 | if (DEBUG_STATES) Slog.v(TAG_STATES, "Resume failed; resetting state to " |
Dianne Hackborn | ce86ba8 | 2011-07-13 19:33:41 -0700 | [diff] [blame] | 2516 | + lastState + ": " + next); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 2517 | next.state = lastState; |
Craig Mautner | f88c50f | 2013-04-18 19:25:12 -0700 | [diff] [blame] | 2518 | if (lastStack != null) { |
| 2519 | lastStack.mResumedActivity = lastResumedActivity; |
| 2520 | } |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 2521 | Slog.i(TAG, "Restarting because process died: " + next); |
| 2522 | if (!next.hasBeenLaunched) { |
| 2523 | next.hasBeenLaunched = true; |
Craig Mautner | f88c50f | 2013-04-18 19:25:12 -0700 | [diff] [blame] | 2524 | } else if (SHOW_APP_STARTING_PREVIEW && lastStack != null && |
| 2525 | mStackSupervisor.isFrontStack(lastStack)) { |
Wale Ogunwale | 3b23239 | 2016-05-13 15:37:13 -0700 | [diff] [blame] | 2526 | next.showStartingWindow(null, true); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 2527 | } |
George Mount | 2c92c97 | 2014-03-20 09:38:23 -0700 | [diff] [blame] | 2528 | mStackSupervisor.startSpecificActivityLocked(next, true, false); |
Craig Mautner | cf910b0 | 2013-04-23 11:23:27 -0700 | [diff] [blame] | 2529 | if (DEBUG_STACK) mStackSupervisor.validateTopActivitiesLocked(); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 2530 | return true; |
| 2531 | } |
| 2532 | |
| 2533 | // From this point on, if something goes wrong there is no way |
| 2534 | // to recover the activity. |
| 2535 | try { |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 2536 | completeResumeLocked(next); |
| 2537 | } catch (Exception e) { |
| 2538 | // If any exception gets thrown, toss away this |
| 2539 | // activity and try the next one. |
| 2540 | Slog.w(TAG, "Exception thrown during resume of " + next, e); |
Dianne Hackborn | be70785 | 2011-11-11 14:32:10 -0800 | [diff] [blame] | 2541 | requestFinishActivityLocked(next.appToken, Activity.RESULT_CANCELED, null, |
Dianne Hackborn | 2d1b378 | 2012-09-09 17:49:39 -0700 | [diff] [blame] | 2542 | "resume-exception", true); |
Craig Mautner | cf910b0 | 2013-04-23 11:23:27 -0700 | [diff] [blame] | 2543 | if (DEBUG_STACK) mStackSupervisor.validateTopActivitiesLocked(); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 2544 | return true; |
| 2545 | } |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 2546 | } else { |
| 2547 | // Whoops, need to restart this activity! |
| 2548 | if (!next.hasBeenLaunched) { |
| 2549 | next.hasBeenLaunched = true; |
| 2550 | } else { |
| 2551 | if (SHOW_APP_STARTING_PREVIEW) { |
Wale Ogunwale | 3b23239 | 2016-05-13 15:37:13 -0700 | [diff] [blame] | 2552 | next.showStartingWindow(null, true); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 2553 | } |
Wale Ogunwale | ee006da | 2015-03-30 14:49:25 -0700 | [diff] [blame] | 2554 | if (DEBUG_SWITCH) Slog.v(TAG_SWITCH, "Restarting: " + next); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 2555 | } |
Wale Ogunwale | 0fc365c | 2015-05-25 19:35:42 -0700 | [diff] [blame] | 2556 | if (DEBUG_STATES) Slog.d(TAG_STATES, "resumeTopActivityLocked: Restarting " + next); |
George Mount | 2c92c97 | 2014-03-20 09:38:23 -0700 | [diff] [blame] | 2557 | mStackSupervisor.startSpecificActivityLocked(next, true, true); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 2558 | } |
| 2559 | |
Craig Mautner | cf910b0 | 2013-04-23 11:23:27 -0700 | [diff] [blame] | 2560 | if (DEBUG_STACK) mStackSupervisor.validateTopActivitiesLocked(); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 2561 | return true; |
| 2562 | } |
| 2563 | |
riddle_hsu | c215a4f | 2014-12-27 12:10:45 +0800 | [diff] [blame] | 2564 | private TaskRecord getNextTask(TaskRecord targetTask) { |
| 2565 | final int index = mTaskHistory.indexOf(targetTask); |
| 2566 | if (index >= 0) { |
| 2567 | final int numTasks = mTaskHistory.size(); |
| 2568 | for (int i = index + 1; i < numTasks; ++i) { |
| 2569 | TaskRecord task = mTaskHistory.get(i); |
| 2570 | if (task.userId == targetTask.userId) { |
| 2571 | return task; |
| 2572 | } |
| 2573 | } |
| 2574 | } |
| 2575 | return null; |
| 2576 | } |
| 2577 | |
Wale Ogunwale | ddc1cb2 | 2015-07-25 19:23:04 -0700 | [diff] [blame] | 2578 | private void insertTaskAtPosition(TaskRecord task, int position) { |
| 2579 | if (position >= mTaskHistory.size()) { |
| 2580 | insertTaskAtTop(task, null); |
| 2581 | return; |
| 2582 | } |
| 2583 | // Calculate maximum possible position for this task. |
| 2584 | int maxPosition = mTaskHistory.size(); |
| 2585 | if (!mStackSupervisor.isCurrentProfileLocked(task.userId) |
Filip Gruszczynski | 3e85ba2 | 2015-10-05 22:48:30 -0700 | [diff] [blame] | 2586 | && task.topRunningActivityLocked() == null) { |
Wale Ogunwale | ddc1cb2 | 2015-07-25 19:23:04 -0700 | [diff] [blame] | 2587 | // Put non-current user tasks below current user tasks. |
| 2588 | while (maxPosition > 0) { |
| 2589 | final TaskRecord tmpTask = mTaskHistory.get(maxPosition - 1); |
| 2590 | if (!mStackSupervisor.isCurrentProfileLocked(tmpTask.userId) |
Filip Gruszczynski | 3e85ba2 | 2015-10-05 22:48:30 -0700 | [diff] [blame] | 2591 | || tmpTask.topRunningActivityLocked() == null) { |
Wale Ogunwale | ddc1cb2 | 2015-07-25 19:23:04 -0700 | [diff] [blame] | 2592 | break; |
| 2593 | } |
| 2594 | maxPosition--; |
| 2595 | } |
| 2596 | } |
| 2597 | position = Math.min(position, maxPosition); |
| 2598 | mTaskHistory.remove(task); |
| 2599 | mTaskHistory.add(position, task); |
| 2600 | updateTaskMovement(task, true); |
| 2601 | } |
| 2602 | |
Wale Ogunwale | 3fcb4a8 | 2015-04-06 14:00:13 -0700 | [diff] [blame] | 2603 | private void insertTaskAtTop(TaskRecord task, ActivityRecord newActivity) { |
Andrii Kulian | dc0f893 | 2016-06-28 16:34:02 -0700 | [diff] [blame] | 2604 | boolean isLastTaskOverHome = false; |
riddle_hsu | c215a4f | 2014-12-27 12:10:45 +0800 | [diff] [blame] | 2605 | // If the moving task is over home stack, transfer its return type to next task |
| 2606 | if (task.isOverHomeStack()) { |
| 2607 | final TaskRecord nextTask = getNextTask(task); |
| 2608 | if (nextTask != null) { |
| 2609 | nextTask.setTaskToReturnTo(task.getTaskToReturnTo()); |
Andrii Kulian | dc0f893 | 2016-06-28 16:34:02 -0700 | [diff] [blame] | 2610 | } else { |
| 2611 | isLastTaskOverHome = true; |
riddle_hsu | c215a4f | 2014-12-27 12:10:45 +0800 | [diff] [blame] | 2612 | } |
| 2613 | } |
| 2614 | |
Craig Mautner | 9c85c20 | 2013-10-04 20:11:26 -0700 | [diff] [blame] | 2615 | // 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] | 2616 | // activity, set mTaskToReturnTo accordingly. |
Craig Mautner | e0a3884 | 2013-12-16 16:14:02 -0800 | [diff] [blame] | 2617 | if (isOnHomeDisplay()) { |
| 2618 | ActivityStack lastStack = mStackSupervisor.getLastStack(); |
| 2619 | final boolean fromHome = lastStack.isHomeStack(); |
| 2620 | if (!isHomeStack() && (fromHome || topTask() != task)) { |
Andrii Kulian | dc0f893 | 2016-06-28 16:34:02 -0700 | [diff] [blame] | 2621 | // If it's a last task over home - we default to keep its return to type not to |
| 2622 | // make underlying task focused when this one will be finished. |
| 2623 | int returnToType = isLastTaskOverHome |
| 2624 | ? task.getTaskToReturnTo() : APPLICATION_ACTIVITY_TYPE; |
Wale Ogunwale | f81c1d1 | 2016-01-12 12:20:18 -0800 | [diff] [blame] | 2625 | if (fromHome && StackId.allowTopTaskToReturnHome(mStackId)) { |
| 2626 | returnToType = lastStack.topTask() == null |
| 2627 | ? HOME_ACTIVITY_TYPE : lastStack.topTask().taskType; |
| 2628 | } |
| 2629 | task.setTaskToReturnTo(returnToType); |
Craig Mautner | e0a3884 | 2013-12-16 16:14:02 -0800 | [diff] [blame] | 2630 | } |
| 2631 | } else { |
Craig Mautner | 84984fa | 2014-06-19 11:19:20 -0700 | [diff] [blame] | 2632 | task.setTaskToReturnTo(APPLICATION_ACTIVITY_TYPE); |
Craig Mautner | 9c85c20 | 2013-10-04 20:11:26 -0700 | [diff] [blame] | 2633 | } |
Craig Mautner | d99384d | 2013-10-14 07:09:18 -0700 | [diff] [blame] | 2634 | |
Craig Mautner | ac6f843 | 2013-07-17 13:24:59 -0700 | [diff] [blame] | 2635 | mTaskHistory.remove(task); |
| 2636 | // Now put task at top. |
Craig Mautner | bb74246 | 2014-07-07 15:28:55 -0700 | [diff] [blame] | 2637 | int taskNdx = mTaskHistory.size(); |
Wale Ogunwale | 3fcb4a8 | 2015-04-06 14:00:13 -0700 | [diff] [blame] | 2638 | final boolean notShownWhenLocked = |
Wale Ogunwale | 6dfdfd6 | 2015-04-15 12:01:38 -0700 | [diff] [blame] | 2639 | (newActivity != null && (newActivity.info.flags & FLAG_SHOW_FOR_ALL_USERS) == 0) |
Filip Gruszczynski | 3e85ba2 | 2015-10-05 22:48:30 -0700 | [diff] [blame] | 2640 | || (newActivity == null && task.topRunningActivityLocked() == null); |
Wale Ogunwale | 0bd2aa7 | 2015-04-16 13:50:44 -0700 | [diff] [blame] | 2641 | if (!mStackSupervisor.isCurrentProfileLocked(task.userId) && notShownWhenLocked) { |
Craig Mautner | ac6f843 | 2013-07-17 13:24:59 -0700 | [diff] [blame] | 2642 | // Put non-current user tasks below current user tasks. |
Craig Mautner | bb74246 | 2014-07-07 15:28:55 -0700 | [diff] [blame] | 2643 | while (--taskNdx >= 0) { |
Wale Ogunwale | 3fcb4a8 | 2015-04-06 14:00:13 -0700 | [diff] [blame] | 2644 | final TaskRecord tmpTask = mTaskHistory.get(taskNdx); |
Wale Ogunwale | 0bd2aa7 | 2015-04-16 13:50:44 -0700 | [diff] [blame] | 2645 | if (!mStackSupervisor.isCurrentProfileLocked(tmpTask.userId) |
Filip Gruszczynski | 3e85ba2 | 2015-10-05 22:48:30 -0700 | [diff] [blame] | 2646 | || tmpTask.topRunningActivityLocked() == null) { |
Craig Mautner | ac6f843 | 2013-07-17 13:24:59 -0700 | [diff] [blame] | 2647 | break; |
| 2648 | } |
| 2649 | } |
Craig Mautner | bb74246 | 2014-07-07 15:28:55 -0700 | [diff] [blame] | 2650 | ++taskNdx; |
Craig Mautner | ac6f843 | 2013-07-17 13:24:59 -0700 | [diff] [blame] | 2651 | } |
Craig Mautner | bb74246 | 2014-07-07 15:28:55 -0700 | [diff] [blame] | 2652 | mTaskHistory.add(taskNdx, task); |
Craig Mautner | 21d24a2 | 2014-04-23 11:45:37 -0700 | [diff] [blame] | 2653 | updateTaskMovement(task, true); |
Craig Mautner | ac6f843 | 2013-07-17 13:24:59 -0700 | [diff] [blame] | 2654 | } |
Craig Mautner | 11bf9a5 | 2013-02-19 14:08:51 -0800 | [diff] [blame] | 2655 | |
Filip Gruszczynski | 3d82ed6 | 2015-12-10 10:41:39 -0800 | [diff] [blame] | 2656 | final void startActivityLocked(ActivityRecord r, boolean newTask, boolean keepCurTransition, |
| 2657 | ActivityOptions options) { |
Craig Mautner | d232895 | 2013-03-05 12:46:26 -0800 | [diff] [blame] | 2658 | TaskRecord rTask = r.task; |
| 2659 | final int taskId = rTask.taskId; |
Craig Mautner | bb74246 | 2014-07-07 15:28:55 -0700 | [diff] [blame] | 2660 | // mLaunchTaskBehind tasks get placed at the back of the task stack. |
| 2661 | if (!r.mLaunchTaskBehind && (taskForIdLocked(taskId) == null || newTask)) { |
Craig Mautner | 7787877 | 2013-03-04 19:46:24 -0800 | [diff] [blame] | 2662 | // Last activity in task had been removed or ActivityManagerService is reusing task. |
| 2663 | // Insert or replace. |
Craig Mautner | 7787877 | 2013-03-04 19:46:24 -0800 | [diff] [blame] | 2664 | // Might not even be in. |
Wale Ogunwale | 3fcb4a8 | 2015-04-06 14:00:13 -0700 | [diff] [blame] | 2665 | insertTaskAtTop(rTask, r); |
Craig Mautner | ce5f3cb | 2013-04-22 08:58:54 -0700 | [diff] [blame] | 2666 | mWindowManager.moveTaskToTop(taskId); |
Craig Mautner | 7787877 | 2013-03-04 19:46:24 -0800 | [diff] [blame] | 2667 | } |
Craig Mautner | 525f3d9 | 2013-05-07 14:01:50 -0700 | [diff] [blame] | 2668 | TaskRecord task = null; |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 2669 | if (!newTask) { |
| 2670 | // If starting in an existing task, find where that is... |
Craig Mautner | 70a8693 | 2013-02-28 22:37:44 -0800 | [diff] [blame] | 2671 | boolean startIt = true; |
| 2672 | for (int taskNdx = mTaskHistory.size() - 1; taskNdx >= 0; --taskNdx) { |
| 2673 | task = mTaskHistory.get(taskNdx); |
riddle_hsu | 9bcc6e8 | 2014-07-31 00:26:51 +0800 | [diff] [blame] | 2674 | if (task.getTopActivity() == null) { |
| 2675 | // All activities in task are finishing. |
| 2676 | continue; |
| 2677 | } |
Craig Mautner | 70a8693 | 2013-02-28 22:37:44 -0800 | [diff] [blame] | 2678 | if (task == r.task) { |
| 2679 | // Here it is! Now, if this is not yet visible to the |
| 2680 | // user, then just add it without starting; it will |
| 2681 | // get started when the user navigates back to it. |
Craig Mautner | 70a8693 | 2013-02-28 22:37:44 -0800 | [diff] [blame] | 2682 | if (!startIt) { |
| 2683 | if (DEBUG_ADD_REMOVE) Slog.i(TAG, "Adding activity " + r + " to task " |
| 2684 | + task, new RuntimeException("here").fillInStackTrace()); |
| 2685 | task.addActivityToTop(r); |
Dianne Hackborn | f26fd99 | 2011-04-08 18:14:09 -0700 | [diff] [blame] | 2686 | r.putInHistory(); |
Filip Gruszczynski | e5390e7 | 2015-08-18 16:39:00 -0700 | [diff] [blame] | 2687 | addConfigOverride(r, task); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 2688 | if (VALIDATE_TOKENS) { |
Dianne Hackborn | be70785 | 2011-11-11 14:32:10 -0800 | [diff] [blame] | 2689 | validateAppTokensLocked(); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 2690 | } |
Dianne Hackborn | 8078d8c | 2012-03-20 11:11:26 -0700 | [diff] [blame] | 2691 | ActivityOptions.abort(options); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 2692 | return; |
| 2693 | } |
| 2694 | break; |
Craig Mautner | 70a8693 | 2013-02-28 22:37:44 -0800 | [diff] [blame] | 2695 | } else if (task.numFullscreen > 0) { |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 2696 | startIt = false; |
| 2697 | } |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 2698 | } |
| 2699 | } |
| 2700 | |
| 2701 | // Place a new activity at top of stack, so it is next to interact |
| 2702 | // with the user. |
Craig Mautner | 70a8693 | 2013-02-28 22:37:44 -0800 | [diff] [blame] | 2703 | |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 2704 | // If we are not placing the new activity frontmost, we do not want |
| 2705 | // to deliver the onUserLeaving callback to the actual frontmost |
| 2706 | // activity |
Craig Mautner | 70a8693 | 2013-02-28 22:37:44 -0800 | [diff] [blame] | 2707 | if (task == r.task && mTaskHistory.indexOf(task) != (mTaskHistory.size() - 1)) { |
Craig Mautner | de4ef02 | 2013-04-07 19:01:33 -0700 | [diff] [blame] | 2708 | mStackSupervisor.mUserLeaving = false; |
Wale Ogunwale | ee006da | 2015-03-30 14:49:25 -0700 | [diff] [blame] | 2709 | if (DEBUG_USER_LEAVING) Slog.v(TAG_USER_LEAVING, |
Craig Mautner | 70a8693 | 2013-02-28 22:37:44 -0800 | [diff] [blame] | 2710 | "startActivity() behind front, mUserLeaving=false"); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 2711 | } |
Craig Mautner | 70a8693 | 2013-02-28 22:37:44 -0800 | [diff] [blame] | 2712 | |
| 2713 | task = r.task; |
| 2714 | |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 2715 | // Slot the activity into the history stack and proceed |
Craig Mautner | 70a8693 | 2013-02-28 22:37:44 -0800 | [diff] [blame] | 2716 | 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] | 2717 | new RuntimeException("here").fillInStackTrace()); |
Craig Mautner | 70a8693 | 2013-02-28 22:37:44 -0800 | [diff] [blame] | 2718 | task.addActivityToTop(r); |
Craig Mautner | 1aa9d0d3f | 2013-12-16 15:58:31 -0800 | [diff] [blame] | 2719 | task.setFrontOfTask(); |
Craig Mautner | 70a8693 | 2013-02-28 22:37:44 -0800 | [diff] [blame] | 2720 | |
Dianne Hackborn | f26fd99 | 2011-04-08 18:14:09 -0700 | [diff] [blame] | 2721 | r.putInHistory(); |
Craig Mautner | de4ef02 | 2013-04-07 19:01:33 -0700 | [diff] [blame] | 2722 | if (!isHomeStack() || numActivities() > 0) { |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 2723 | // We want to show the starting preview window if we are |
| 2724 | // switching to a new task, or the next activity's process is |
| 2725 | // not currently running. |
| 2726 | boolean showStartingIcon = newTask; |
| 2727 | ProcessRecord proc = r.app; |
| 2728 | if (proc == null) { |
| 2729 | proc = mService.mProcessNames.get(r.processName, r.info.applicationInfo.uid); |
| 2730 | } |
| 2731 | if (proc == null || proc.thread == null) { |
| 2732 | showStartingIcon = true; |
| 2733 | } |
Wale Ogunwale | ee006da | 2015-03-30 14:49:25 -0700 | [diff] [blame] | 2734 | if (DEBUG_TRANSITION) Slog.v(TAG_TRANSITION, |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 2735 | "Prepare open transition: starting " + r); |
Wale Ogunwale | ee006da | 2015-03-30 14:49:25 -0700 | [diff] [blame] | 2736 | if ((r.intent.getFlags() & Intent.FLAG_ACTIVITY_NO_ANIMATION) != 0) { |
Jorim Jaggi | af80db4 | 2016-04-07 19:19:15 -0700 | [diff] [blame] | 2737 | mWindowManager.prepareAppTransition(TRANSIT_NONE, keepCurTransition); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 2738 | mNoAnimActivities.add(r); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 2739 | } else { |
Craig Mautner | ce5f3cb | 2013-04-22 08:58:54 -0700 | [diff] [blame] | 2740 | mWindowManager.prepareAppTransition(newTask |
Craig Mautner | bb74246 | 2014-07-07 15:28:55 -0700 | [diff] [blame] | 2741 | ? r.mLaunchTaskBehind |
Jorim Jaggi | af80db4 | 2016-04-07 19:19:15 -0700 | [diff] [blame] | 2742 | ? TRANSIT_TASK_OPEN_BEHIND |
| 2743 | : TRANSIT_TASK_OPEN |
| 2744 | : TRANSIT_ACTIVITY_OPEN, keepCurTransition); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 2745 | mNoAnimActivities.remove(r); |
| 2746 | } |
Filip Gruszczynski | e5390e7 | 2015-08-18 16:39:00 -0700 | [diff] [blame] | 2747 | addConfigOverride(r, task); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 2748 | boolean doShow = true; |
| 2749 | if (newTask) { |
| 2750 | // Even though this activity is starting fresh, we still need |
| 2751 | // to reset it to make sure we apply affinities to move any |
| 2752 | // existing activities from other tasks in to it. |
| 2753 | // If the caller has requested that the target task be |
| 2754 | // reset, then do so. |
Craig Mautner | 9d4e9bc | 2014-06-18 18:34:56 -0700 | [diff] [blame] | 2755 | if ((r.intent.getFlags() & Intent.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED) != 0) { |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 2756 | resetTaskIfNeededLocked(r, r); |
| 2757 | doShow = topRunningNonDelayedActivityLocked(null) == r; |
| 2758 | } |
Chong Zhang | 280d332 | 2015-11-03 17:27:26 -0800 | [diff] [blame] | 2759 | } else if (options != null && options.getAnimationType() |
George Mount | 70778d7 | 2014-07-01 16:33:45 -0700 | [diff] [blame] | 2760 | == ActivityOptions.ANIM_SCENE_TRANSITION) { |
| 2761 | doShow = false; |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 2762 | } |
Craig Mautner | bb74246 | 2014-07-07 15:28:55 -0700 | [diff] [blame] | 2763 | if (r.mLaunchTaskBehind) { |
| 2764 | // Don't do a starting window for mLaunchTaskBehind. More importantly make sure we |
| 2765 | // tell WindowManager that r is visible even though it is at the back of the stack. |
| 2766 | mWindowManager.setAppVisibility(r.appToken, true); |
Filip Gruszczynski | bc5a6c5 | 2015-09-22 13:13:24 -0700 | [diff] [blame] | 2767 | ensureActivitiesVisibleLocked(null, 0, !PRESERVE_WINDOWS); |
Craig Mautner | bb74246 | 2014-07-07 15:28:55 -0700 | [diff] [blame] | 2768 | } else if (SHOW_APP_STARTING_PREVIEW && doShow) { |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 2769 | // Figure out if we are transitioning from another activity that is |
| 2770 | // "has the same starting icon" as the next one. This allows the |
| 2771 | // window manager to keep the previous window it had previously |
| 2772 | // created, if it still had one. |
Wale Ogunwale | 3b23239 | 2016-05-13 15:37:13 -0700 | [diff] [blame] | 2773 | ActivityRecord prev = r.task.topRunningActivityWithStartingWindowLocked(); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 2774 | if (prev != null) { |
| 2775 | // We don't want to reuse the previous starting preview if: |
| 2776 | // (1) The current activity is in a different task. |
Craig Mautner | 29219d9 | 2013-04-16 20:19:12 -0700 | [diff] [blame] | 2777 | if (prev.task != r.task) { |
| 2778 | prev = null; |
| 2779 | } |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 2780 | // (2) The current activity is already displayed. |
Craig Mautner | 29219d9 | 2013-04-16 20:19:12 -0700 | [diff] [blame] | 2781 | else if (prev.nowVisible) { |
| 2782 | prev = null; |
| 2783 | } |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 2784 | } |
Wale Ogunwale | 3b23239 | 2016-05-13 15:37:13 -0700 | [diff] [blame] | 2785 | r.showStartingWindow(prev, showStartingIcon); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 2786 | } |
| 2787 | } else { |
| 2788 | // If this is the first activity, don't do any fancy animations, |
| 2789 | // because there is nothing for it to animate on top of. |
Filip Gruszczynski | e5390e7 | 2015-08-18 16:39:00 -0700 | [diff] [blame] | 2790 | addConfigOverride(r, task); |
Dianne Hackborn | 8078d8c | 2012-03-20 11:11:26 -0700 | [diff] [blame] | 2791 | ActivityOptions.abort(options); |
Craig Mautner | 233ceee | 2014-05-09 17:05:11 -0700 | [diff] [blame] | 2792 | options = null; |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 2793 | } |
| 2794 | if (VALIDATE_TOKENS) { |
Dianne Hackborn | be70785 | 2011-11-11 14:32:10 -0800 | [diff] [blame] | 2795 | validateAppTokensLocked(); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 2796 | } |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 2797 | } |
| 2798 | |
Dianne Hackborn | be70785 | 2011-11-11 14:32:10 -0800 | [diff] [blame] | 2799 | final void validateAppTokensLocked() { |
| 2800 | mValidateAppTokens.clear(); |
Craig Mautner | 000f002 | 2013-02-26 15:04:29 -0800 | [diff] [blame] | 2801 | mValidateAppTokens.ensureCapacity(numActivities()); |
| 2802 | final int numTasks = mTaskHistory.size(); |
| 2803 | for (int taskNdx = 0; taskNdx < numTasks; ++taskNdx) { |
| 2804 | TaskRecord task = mTaskHistory.get(taskNdx); |
| 2805 | final ArrayList<ActivityRecord> activities = task.mActivities; |
Craig Mautner | c8143c6 | 2013-09-03 12:15:57 -0700 | [diff] [blame] | 2806 | if (activities.isEmpty()) { |
Craig Mautner | 000f002 | 2013-02-26 15:04:29 -0800 | [diff] [blame] | 2807 | continue; |
Craig Mautner | b1fd65c0 | 2013-02-05 13:34:57 -0800 | [diff] [blame] | 2808 | } |
Craig Mautner | 000f002 | 2013-02-26 15:04:29 -0800 | [diff] [blame] | 2809 | TaskGroup group = new TaskGroup(); |
| 2810 | group.taskId = task.taskId; |
| 2811 | mValidateAppTokens.add(group); |
| 2812 | final int numActivities = activities.size(); |
| 2813 | for (int activityNdx = 0; activityNdx < numActivities; ++activityNdx) { |
| 2814 | final ActivityRecord r = activities.get(activityNdx); |
| 2815 | group.tokens.add(r.appToken); |
| 2816 | } |
Dianne Hackborn | be70785 | 2011-11-11 14:32:10 -0800 | [diff] [blame] | 2817 | } |
Craig Mautner | ce5f3cb | 2013-04-22 08:58:54 -0700 | [diff] [blame] | 2818 | mWindowManager.validateAppTokens(mStackId, mValidateAppTokens); |
Dianne Hackborn | be70785 | 2011-11-11 14:32:10 -0800 | [diff] [blame] | 2819 | } |
| 2820 | |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 2821 | /** |
| 2822 | * Perform a reset of the given task, if needed as part of launching it. |
| 2823 | * Returns the new HistoryRecord at the top of the task. |
| 2824 | */ |
Craig Mautner | e3a74d5 | 2013-02-22 14:14:58 -0800 | [diff] [blame] | 2825 | /** |
| 2826 | * Helper method for #resetTaskIfNeededLocked. |
| 2827 | * We are inside of the task being reset... we'll either finish this activity, push it out |
| 2828 | * for another task, or leave it as-is. |
| 2829 | * @param task The task containing the Activity (taskTop) that might be reset. |
| 2830 | * @param forceReset |
| 2831 | * @return An ActivityOptions that needs to be processed. |
| 2832 | */ |
Craig Mautner | ce5f3cb | 2013-04-22 08:58:54 -0700 | [diff] [blame] | 2833 | final ActivityOptions resetTargetTaskIfNeededLocked(TaskRecord task, boolean forceReset) { |
Craig Mautner | e3a74d5 | 2013-02-22 14:14:58 -0800 | [diff] [blame] | 2834 | ActivityOptions topOptions = null; |
| 2835 | |
| 2836 | int replyChainEnd = -1; |
| 2837 | boolean canMoveOptions = true; |
| 2838 | |
| 2839 | // We only do this for activities that are not the root of the task (since if we finish |
| 2840 | // the root, we may no longer have the task!). |
| 2841 | final ArrayList<ActivityRecord> activities = task.mActivities; |
| 2842 | final int numActivities = activities.size(); |
Craig Mautner | 9d4e9bc | 2014-06-18 18:34:56 -0700 | [diff] [blame] | 2843 | final int rootActivityNdx = task.findEffectiveRootIndex(); |
| 2844 | for (int i = numActivities - 1; i > rootActivityNdx; --i ) { |
Craig Mautner | e3a74d5 | 2013-02-22 14:14:58 -0800 | [diff] [blame] | 2845 | ActivityRecord target = activities.get(i); |
Craig Mautner | 76ae2f0 | 2014-07-16 16:16:19 +0000 | [diff] [blame] | 2846 | if (target.frontOfTask) |
| 2847 | break; |
Craig Mautner | e3a74d5 | 2013-02-22 14:14:58 -0800 | [diff] [blame] | 2848 | |
| 2849 | final int flags = target.info.flags; |
| 2850 | final boolean finishOnTaskLaunch = |
| 2851 | (flags & ActivityInfo.FLAG_FINISH_ON_TASK_LAUNCH) != 0; |
| 2852 | final boolean allowTaskReparenting = |
| 2853 | (flags & ActivityInfo.FLAG_ALLOW_TASK_REPARENTING) != 0; |
| 2854 | final boolean clearWhenTaskReset = |
| 2855 | (target.intent.getFlags() & Intent.FLAG_ACTIVITY_CLEAR_WHEN_TASK_RESET) != 0; |
| 2856 | |
| 2857 | if (!finishOnTaskLaunch |
| 2858 | && !clearWhenTaskReset |
| 2859 | && target.resultTo != null) { |
| 2860 | // If this activity is sending a reply to a previous |
| 2861 | // activity, we can't do anything with it now until |
| 2862 | // we reach the start of the reply chain. |
| 2863 | // XXX note that we are assuming the result is always |
| 2864 | // to the previous activity, which is almost always |
| 2865 | // the case but we really shouldn't count on. |
| 2866 | if (replyChainEnd < 0) { |
| 2867 | replyChainEnd = i; |
| 2868 | } |
| 2869 | } else if (!finishOnTaskLaunch |
| 2870 | && !clearWhenTaskReset |
| 2871 | && allowTaskReparenting |
| 2872 | && target.taskAffinity != null |
| 2873 | && !target.taskAffinity.equals(task.affinity)) { |
| 2874 | // If this activity has an affinity for another |
| 2875 | // task, then we need to move it out of here. We will |
| 2876 | // move it as far out of the way as possible, to the |
| 2877 | // bottom of the activity stack. This also keeps it |
| 2878 | // correctly ordered with any activities we previously |
| 2879 | // moved. |
Craig Mautner | 329f412 | 2013-11-07 09:10:42 -0800 | [diff] [blame] | 2880 | final TaskRecord targetTask; |
Craig Mautner | dccb770 | 2013-09-17 15:53:34 -0700 | [diff] [blame] | 2881 | final ActivityRecord bottom = |
| 2882 | !mTaskHistory.isEmpty() && !mTaskHistory.get(0).mActivities.isEmpty() ? |
Craig Mautner | 329f412 | 2013-11-07 09:10:42 -0800 | [diff] [blame] | 2883 | mTaskHistory.get(0).mActivities.get(0) : null; |
Craig Mautner | dccb770 | 2013-09-17 15:53:34 -0700 | [diff] [blame] | 2884 | if (bottom != null && target.taskAffinity != null |
| 2885 | && target.taskAffinity.equals(bottom.task.affinity)) { |
Craig Mautner | e3a74d5 | 2013-02-22 14:14:58 -0800 | [diff] [blame] | 2886 | // If the activity currently at the bottom has the |
| 2887 | // same task affinity as the one we are moving, |
| 2888 | // then merge it into the same task. |
Craig Mautner | 329f412 | 2013-11-07 09:10:42 -0800 | [diff] [blame] | 2889 | targetTask = bottom.task; |
Wale Ogunwale | ee006da | 2015-03-30 14:49:25 -0700 | [diff] [blame] | 2890 | if (DEBUG_TASKS) Slog.v(TAG_TASKS, "Start pushing activity " + target |
Craig Mautner | dccb770 | 2013-09-17 15:53:34 -0700 | [diff] [blame] | 2891 | + " out to bottom task " + bottom.task); |
Craig Mautner | e3a74d5 | 2013-02-22 14:14:58 -0800 | [diff] [blame] | 2892 | } else { |
Suprabh Shukla | 09a88f5 | 2015-12-02 14:36:31 -0800 | [diff] [blame] | 2893 | targetTask = createTaskRecord( |
| 2894 | mStackSupervisor.getNextTaskIdForUserLocked(target.userId), |
| 2895 | target.info, null, null, null, false); |
Craig Mautner | 329f412 | 2013-11-07 09:10:42 -0800 | [diff] [blame] | 2896 | targetTask.affinityIntent = target.intent; |
Wale Ogunwale | ee006da | 2015-03-30 14:49:25 -0700 | [diff] [blame] | 2897 | if (DEBUG_TASKS) Slog.v(TAG_TASKS, "Start pushing activity " + target |
Craig Mautner | e3a74d5 | 2013-02-22 14:14:58 -0800 | [diff] [blame] | 2898 | + " out to new task " + target.task); |
| 2899 | } |
| 2900 | |
Wale Ogunwale | 706ed79 | 2015-08-02 10:29:44 -0700 | [diff] [blame] | 2901 | setAppTask(target, targetTask); |
Craig Mautner | e3a74d5 | 2013-02-22 14:14:58 -0800 | [diff] [blame] | 2902 | |
Craig Mautner | 525f3d9 | 2013-05-07 14:01:50 -0700 | [diff] [blame] | 2903 | boolean noOptions = canMoveOptions; |
Craig Mautner | e3a74d5 | 2013-02-22 14:14:58 -0800 | [diff] [blame] | 2904 | final int start = replyChainEnd < 0 ? i : replyChainEnd; |
| 2905 | for (int srcPos = start; srcPos >= i; --srcPos) { |
Craig Mautner | dccb770 | 2013-09-17 15:53:34 -0700 | [diff] [blame] | 2906 | final ActivityRecord p = activities.get(srcPos); |
Craig Mautner | e3a74d5 | 2013-02-22 14:14:58 -0800 | [diff] [blame] | 2907 | if (p.finishing) { |
| 2908 | continue; |
| 2909 | } |
| 2910 | |
Craig Mautner | e3a74d5 | 2013-02-22 14:14:58 -0800 | [diff] [blame] | 2911 | canMoveOptions = false; |
Craig Mautner | 525f3d9 | 2013-05-07 14:01:50 -0700 | [diff] [blame] | 2912 | if (noOptions && topOptions == null) { |
Craig Mautner | e3a74d5 | 2013-02-22 14:14:58 -0800 | [diff] [blame] | 2913 | topOptions = p.takeOptionsLocked(); |
| 2914 | if (topOptions != null) { |
Craig Mautner | 525f3d9 | 2013-05-07 14:01:50 -0700 | [diff] [blame] | 2915 | noOptions = false; |
Craig Mautner | e3a74d5 | 2013-02-22 14:14:58 -0800 | [diff] [blame] | 2916 | } |
| 2917 | } |
Wale Ogunwale | 0fc365c | 2015-05-25 19:35:42 -0700 | [diff] [blame] | 2918 | if (DEBUG_ADD_REMOVE) Slog.i(TAG_ADD_REMOVE, |
| 2919 | "Removing activity " + p + " from task=" + task + " adding to task=" |
| 2920 | + targetTask + " Callers=" + Debug.getCallers(4)); |
Wale Ogunwale | ee006da | 2015-03-30 14:49:25 -0700 | [diff] [blame] | 2921 | if (DEBUG_TASKS) Slog.v(TAG_TASKS, |
| 2922 | "Pushing next activity " + p + " out to target's task " + target.task); |
Craig Mautner | a228ae9 | 2014-07-09 05:44:55 -0700 | [diff] [blame] | 2923 | p.setTask(targetTask, null); |
Craig Mautner | e3a74d5 | 2013-02-22 14:14:58 -0800 | [diff] [blame] | 2924 | targetTask.addActivityAtBottom(p); |
Craig Mautner | 0247fc8 | 2013-02-28 14:32:06 -0800 | [diff] [blame] | 2925 | |
Wale Ogunwale | 706ed79 | 2015-08-02 10:29:44 -0700 | [diff] [blame] | 2926 | setAppTask(p, targetTask); |
Craig Mautner | e3a74d5 | 2013-02-22 14:14:58 -0800 | [diff] [blame] | 2927 | } |
| 2928 | |
Wale Ogunwale | 706ed79 | 2015-08-02 10:29:44 -0700 | [diff] [blame] | 2929 | mWindowManager.moveTaskToBottom(targetTask.taskId); |
Craig Mautner | e3a74d5 | 2013-02-22 14:14:58 -0800 | [diff] [blame] | 2930 | if (VALIDATE_TOKENS) { |
| 2931 | validateAppTokensLocked(); |
| 2932 | } |
| 2933 | |
| 2934 | replyChainEnd = -1; |
| 2935 | } else if (forceReset || finishOnTaskLaunch || clearWhenTaskReset) { |
| 2936 | // If the activity should just be removed -- either |
| 2937 | // because it asks for it, or the task should be |
| 2938 | // cleared -- then finish it and anything that is |
| 2939 | // part of its reply chain. |
| 2940 | int end; |
| 2941 | if (clearWhenTaskReset) { |
| 2942 | // In this case, we want to finish this activity |
| 2943 | // and everything above it, so be sneaky and pretend |
| 2944 | // like these are all in the reply chain. |
Mark Lu | 4b5a9a0 | 2014-12-09 14:47:13 +0800 | [diff] [blame] | 2945 | end = activities.size() - 1; |
Craig Mautner | e3a74d5 | 2013-02-22 14:14:58 -0800 | [diff] [blame] | 2946 | } else if (replyChainEnd < 0) { |
| 2947 | end = i; |
| 2948 | } else { |
| 2949 | end = replyChainEnd; |
| 2950 | } |
Craig Mautner | 525f3d9 | 2013-05-07 14:01:50 -0700 | [diff] [blame] | 2951 | boolean noOptions = canMoveOptions; |
Craig Mautner | e3a74d5 | 2013-02-22 14:14:58 -0800 | [diff] [blame] | 2952 | for (int srcPos = i; srcPos <= end; srcPos++) { |
Craig Mautner | 525f3d9 | 2013-05-07 14:01:50 -0700 | [diff] [blame] | 2953 | ActivityRecord p = activities.get(srcPos); |
Craig Mautner | e3a74d5 | 2013-02-22 14:14:58 -0800 | [diff] [blame] | 2954 | if (p.finishing) { |
| 2955 | continue; |
| 2956 | } |
| 2957 | canMoveOptions = false; |
Craig Mautner | 525f3d9 | 2013-05-07 14:01:50 -0700 | [diff] [blame] | 2958 | if (noOptions && topOptions == null) { |
Craig Mautner | e3a74d5 | 2013-02-22 14:14:58 -0800 | [diff] [blame] | 2959 | topOptions = p.takeOptionsLocked(); |
| 2960 | if (topOptions != null) { |
Craig Mautner | 525f3d9 | 2013-05-07 14:01:50 -0700 | [diff] [blame] | 2961 | noOptions = false; |
Craig Mautner | e3a74d5 | 2013-02-22 14:14:58 -0800 | [diff] [blame] | 2962 | } |
| 2963 | } |
Wale Ogunwale | ee006da | 2015-03-30 14:49:25 -0700 | [diff] [blame] | 2964 | if (DEBUG_TASKS) Slog.w(TAG_TASKS, |
Craig Mautner | 5854780 | 2013-03-05 08:23:53 -0800 | [diff] [blame] | 2965 | "resetTaskIntendedTask: calling finishActivity on " + p); |
Todd Kennedy | 539db51 | 2014-12-15 09:57:55 -0800 | [diff] [blame] | 2966 | if (finishActivityLocked( |
| 2967 | p, Activity.RESULT_CANCELED, null, "reset-task", false)) { |
Craig Mautner | e3a74d5 | 2013-02-22 14:14:58 -0800 | [diff] [blame] | 2968 | end--; |
| 2969 | srcPos--; |
| 2970 | } |
| 2971 | } |
| 2972 | replyChainEnd = -1; |
| 2973 | } else { |
| 2974 | // If we were in the middle of a chain, well the |
| 2975 | // activity that started it all doesn't want anything |
| 2976 | // special, so leave it all as-is. |
| 2977 | replyChainEnd = -1; |
| 2978 | } |
| 2979 | } |
| 2980 | |
| 2981 | return topOptions; |
| 2982 | } |
| 2983 | |
| 2984 | /** |
| 2985 | * Helper method for #resetTaskIfNeededLocked. Processes all of the activities in a given |
| 2986 | * TaskRecord looking for an affinity with the task of resetTaskIfNeededLocked.taskTop. |
| 2987 | * @param affinityTask The task we are looking for an affinity to. |
| 2988 | * @param task Task that resetTaskIfNeededLocked.taskTop belongs to. |
| 2989 | * @param topTaskIsHigher True if #task has already been processed by resetTaskIfNeededLocked. |
| 2990 | * @param forceReset Flag passed in to resetTaskIfNeededLocked. |
| 2991 | */ |
Craig Mautner | 525f3d9 | 2013-05-07 14:01:50 -0700 | [diff] [blame] | 2992 | private int resetAffinityTaskIfNeededLocked(TaskRecord affinityTask, TaskRecord task, |
Craig Mautner | 7787877 | 2013-03-04 19:46:24 -0800 | [diff] [blame] | 2993 | boolean topTaskIsHigher, boolean forceReset, int taskInsertionPoint) { |
Craig Mautner | e3a74d5 | 2013-02-22 14:14:58 -0800 | [diff] [blame] | 2994 | int replyChainEnd = -1; |
| 2995 | final int taskId = task.taskId; |
| 2996 | final String taskAffinity = task.affinity; |
| 2997 | |
| 2998 | final ArrayList<ActivityRecord> activities = affinityTask.mActivities; |
| 2999 | final int numActivities = activities.size(); |
Craig Mautner | 9d4e9bc | 2014-06-18 18:34:56 -0700 | [diff] [blame] | 3000 | final int rootActivityNdx = affinityTask.findEffectiveRootIndex(); |
| 3001 | |
| 3002 | // Do not operate on or below the effective root Activity. |
| 3003 | for (int i = numActivities - 1; i > rootActivityNdx; --i) { |
Craig Mautner | e3a74d5 | 2013-02-22 14:14:58 -0800 | [diff] [blame] | 3004 | ActivityRecord target = activities.get(i); |
Craig Mautner | 76ae2f0 | 2014-07-16 16:16:19 +0000 | [diff] [blame] | 3005 | if (target.frontOfTask) |
| 3006 | break; |
Craig Mautner | e3a74d5 | 2013-02-22 14:14:58 -0800 | [diff] [blame] | 3007 | |
| 3008 | final int flags = target.info.flags; |
| 3009 | boolean finishOnTaskLaunch = (flags & ActivityInfo.FLAG_FINISH_ON_TASK_LAUNCH) != 0; |
| 3010 | boolean allowTaskReparenting = (flags & ActivityInfo.FLAG_ALLOW_TASK_REPARENTING) != 0; |
| 3011 | |
| 3012 | if (target.resultTo != null) { |
| 3013 | // If this activity is sending a reply to a previous |
| 3014 | // activity, we can't do anything with it now until |
| 3015 | // we reach the start of the reply chain. |
| 3016 | // XXX note that we are assuming the result is always |
| 3017 | // to the previous activity, which is almost always |
| 3018 | // the case but we really shouldn't count on. |
| 3019 | if (replyChainEnd < 0) { |
| 3020 | replyChainEnd = i; |
| 3021 | } |
| 3022 | } else if (topTaskIsHigher |
| 3023 | && allowTaskReparenting |
| 3024 | && taskAffinity != null |
| 3025 | && taskAffinity.equals(target.taskAffinity)) { |
| 3026 | // This activity has an affinity for our task. Either remove it if we are |
| 3027 | // clearing or move it over to our task. Note that |
| 3028 | // we currently punt on the case where we are resetting a |
| 3029 | // task that is not at the top but who has activities above |
| 3030 | // with an affinity to it... this is really not a normal |
| 3031 | // case, and we will need to later pull that task to the front |
| 3032 | // and usually at that point we will do the reset and pick |
| 3033 | // up those remaining activities. (This only happens if |
| 3034 | // someone starts an activity in a new task from an activity |
| 3035 | // in a task that is not currently on top.) |
| 3036 | if (forceReset || finishOnTaskLaunch) { |
| 3037 | final int start = replyChainEnd >= 0 ? replyChainEnd : i; |
Wale Ogunwale | ee006da | 2015-03-30 14:49:25 -0700 | [diff] [blame] | 3038 | if (DEBUG_TASKS) Slog.v(TAG_TASKS, |
| 3039 | "Finishing task at index " + start + " to " + i); |
Craig Mautner | e3a74d5 | 2013-02-22 14:14:58 -0800 | [diff] [blame] | 3040 | for (int srcPos = start; srcPos >= i; --srcPos) { |
| 3041 | final ActivityRecord p = activities.get(srcPos); |
| 3042 | if (p.finishing) { |
| 3043 | continue; |
| 3044 | } |
Todd Kennedy | 539db51 | 2014-12-15 09:57:55 -0800 | [diff] [blame] | 3045 | finishActivityLocked( |
| 3046 | p, Activity.RESULT_CANCELED, null, "move-affinity", false); |
Craig Mautner | e3a74d5 | 2013-02-22 14:14:58 -0800 | [diff] [blame] | 3047 | } |
| 3048 | } else { |
Craig Mautner | 7787877 | 2013-03-04 19:46:24 -0800 | [diff] [blame] | 3049 | if (taskInsertionPoint < 0) { |
| 3050 | taskInsertionPoint = task.mActivities.size(); |
Craig Mautner | d232895 | 2013-03-05 12:46:26 -0800 | [diff] [blame] | 3051 | |
Craig Mautner | 7787877 | 2013-03-04 19:46:24 -0800 | [diff] [blame] | 3052 | } |
Craig Mautner | 7787877 | 2013-03-04 19:46:24 -0800 | [diff] [blame] | 3053 | |
| 3054 | final int start = replyChainEnd >= 0 ? replyChainEnd : i; |
Wale Ogunwale | ee006da | 2015-03-30 14:49:25 -0700 | [diff] [blame] | 3055 | if (DEBUG_TASKS) Slog.v(TAG_TASKS, |
| 3056 | "Reparenting from task=" + affinityTask + ":" + start + "-" + i |
| 3057 | + " to task=" + task + ":" + taskInsertionPoint); |
Craig Mautner | 7787877 | 2013-03-04 19:46:24 -0800 | [diff] [blame] | 3058 | for (int srcPos = start; srcPos >= i; --srcPos) { |
Craig Mautner | e3a74d5 | 2013-02-22 14:14:58 -0800 | [diff] [blame] | 3059 | final ActivityRecord p = activities.get(srcPos); |
Craig Mautner | a228ae9 | 2014-07-09 05:44:55 -0700 | [diff] [blame] | 3060 | p.setTask(task, null); |
Craig Mautner | 7787877 | 2013-03-04 19:46:24 -0800 | [diff] [blame] | 3061 | task.addActivityAtIndex(taskInsertionPoint, p); |
Craig Mautner | e3a74d5 | 2013-02-22 14:14:58 -0800 | [diff] [blame] | 3062 | |
Wale Ogunwale | 0fc365c | 2015-05-25 19:35:42 -0700 | [diff] [blame] | 3063 | if (DEBUG_ADD_REMOVE) Slog.i(TAG_ADD_REMOVE, |
| 3064 | "Removing and adding activity " + p + " to stack at " + task |
| 3065 | + " callers=" + Debug.getCallers(3)); |
Wale Ogunwale | ee006da | 2015-03-30 14:49:25 -0700 | [diff] [blame] | 3066 | if (DEBUG_TASKS) Slog.v(TAG_TASKS, "Pulling activity " + p |
| 3067 | + " from " + srcPos + " in to resetting task " + task); |
Wale Ogunwale | 706ed79 | 2015-08-02 10:29:44 -0700 | [diff] [blame] | 3068 | setAppTask(p, task); |
Craig Mautner | e3a74d5 | 2013-02-22 14:14:58 -0800 | [diff] [blame] | 3069 | } |
Craig Mautner | ce5f3cb | 2013-04-22 08:58:54 -0700 | [diff] [blame] | 3070 | mWindowManager.moveTaskToTop(taskId); |
Craig Mautner | 9658b31 | 2013-02-28 10:55:59 -0800 | [diff] [blame] | 3071 | if (VALIDATE_TOKENS) { |
| 3072 | validateAppTokensLocked(); |
| 3073 | } |
Craig Mautner | e3a74d5 | 2013-02-22 14:14:58 -0800 | [diff] [blame] | 3074 | |
| 3075 | // Now we've moved it in to place... but what if this is |
| 3076 | // a singleTop activity and we have put it on top of another |
| 3077 | // instance of the same activity? Then we drop the instance |
| 3078 | // below so it remains singleTop. |
| 3079 | if (target.info.launchMode == ActivityInfo.LAUNCH_SINGLE_TOP) { |
| 3080 | ArrayList<ActivityRecord> taskActivities = task.mActivities; |
Craig Mautner | e3a74d5 | 2013-02-22 14:14:58 -0800 | [diff] [blame] | 3081 | int targetNdx = taskActivities.indexOf(target); |
| 3082 | if (targetNdx > 0) { |
| 3083 | ActivityRecord p = taskActivities.get(targetNdx - 1); |
| 3084 | if (p.intent.getComponent().equals(target.intent.getComponent())) { |
Craig Mautner | 5854780 | 2013-03-05 08:23:53 -0800 | [diff] [blame] | 3085 | finishActivityLocked(p, Activity.RESULT_CANCELED, null, "replace", |
| 3086 | false); |
Craig Mautner | e3a74d5 | 2013-02-22 14:14:58 -0800 | [diff] [blame] | 3087 | } |
| 3088 | } |
| 3089 | } |
| 3090 | } |
| 3091 | |
| 3092 | replyChainEnd = -1; |
| 3093 | } |
| 3094 | } |
Craig Mautner | 7787877 | 2013-03-04 19:46:24 -0800 | [diff] [blame] | 3095 | return taskInsertionPoint; |
Craig Mautner | e3a74d5 | 2013-02-22 14:14:58 -0800 | [diff] [blame] | 3096 | } |
| 3097 | |
Craig Mautner | 8849a5e | 2013-04-02 16:41:03 -0700 | [diff] [blame] | 3098 | final ActivityRecord resetTaskIfNeededLocked(ActivityRecord taskTop, |
Craig Mautner | e3a74d5 | 2013-02-22 14:14:58 -0800 | [diff] [blame] | 3099 | ActivityRecord newActivity) { |
| 3100 | boolean forceReset = |
| 3101 | (newActivity.info.flags & ActivityInfo.FLAG_CLEAR_TASK_ON_LAUNCH) != 0; |
| 3102 | if (ACTIVITY_INACTIVE_RESET_TIME > 0 |
| 3103 | && taskTop.task.getInactiveDuration() > ACTIVITY_INACTIVE_RESET_TIME) { |
| 3104 | if ((newActivity.info.flags & ActivityInfo.FLAG_ALWAYS_RETAIN_TASK_STATE) == 0) { |
| 3105 | forceReset = true; |
| 3106 | } |
| 3107 | } |
| 3108 | |
| 3109 | final TaskRecord task = taskTop.task; |
| 3110 | |
| 3111 | /** False until we evaluate the TaskRecord associated with taskTop. Switches to true |
| 3112 | * for remaining tasks. Used for later tasks to reparent to task. */ |
| 3113 | boolean taskFound = false; |
| 3114 | |
| 3115 | /** If ActivityOptions are moved out and need to be aborted or moved to taskTop. */ |
| 3116 | ActivityOptions topOptions = null; |
| 3117 | |
Craig Mautner | 7787877 | 2013-03-04 19:46:24 -0800 | [diff] [blame] | 3118 | // Preserve the location for reparenting in the new task. |
| 3119 | int reparentInsertionPoint = -1; |
| 3120 | |
Craig Mautner | e3a74d5 | 2013-02-22 14:14:58 -0800 | [diff] [blame] | 3121 | for (int i = mTaskHistory.size() - 1; i >= 0; --i) { |
| 3122 | final TaskRecord targetTask = mTaskHistory.get(i); |
| 3123 | |
| 3124 | if (targetTask == task) { |
| 3125 | topOptions = resetTargetTaskIfNeededLocked(task, forceReset); |
| 3126 | taskFound = true; |
| 3127 | } else { |
Craig Mautner | 7787877 | 2013-03-04 19:46:24 -0800 | [diff] [blame] | 3128 | reparentInsertionPoint = resetAffinityTaskIfNeededLocked(targetTask, task, |
| 3129 | taskFound, forceReset, reparentInsertionPoint); |
Craig Mautner | e3a74d5 | 2013-02-22 14:14:58 -0800 | [diff] [blame] | 3130 | } |
| 3131 | } |
| 3132 | |
Craig Mautner | 70a8693 | 2013-02-28 22:37:44 -0800 | [diff] [blame] | 3133 | int taskNdx = mTaskHistory.indexOf(task); |
riddle_hsu | 1d7919a | 2015-03-11 17:09:50 +0800 | [diff] [blame] | 3134 | if (taskNdx >= 0) { |
| 3135 | do { |
| 3136 | taskTop = mTaskHistory.get(taskNdx--).getTopActivity(); |
| 3137 | } while (taskTop == null && taskNdx >= 0); |
| 3138 | } |
Craig Mautner | 70a8693 | 2013-02-28 22:37:44 -0800 | [diff] [blame] | 3139 | |
Craig Mautner | e3a74d5 | 2013-02-22 14:14:58 -0800 | [diff] [blame] | 3140 | if (topOptions != null) { |
| 3141 | // If we got some ActivityOptions from an activity on top that |
| 3142 | // was removed from the task, propagate them to the new real top. |
| 3143 | if (taskTop != null) { |
Craig Mautner | e3a74d5 | 2013-02-22 14:14:58 -0800 | [diff] [blame] | 3144 | taskTop.updateOptionsLocked(topOptions); |
| 3145 | } else { |
Craig Mautner | e3a74d5 | 2013-02-22 14:14:58 -0800 | [diff] [blame] | 3146 | topOptions.abort(); |
| 3147 | } |
| 3148 | } |
| 3149 | |
| 3150 | return taskTop; |
| 3151 | } |
| 3152 | |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 3153 | void sendActivityResultLocked(int callingUid, ActivityRecord r, |
| 3154 | String resultWho, int requestCode, int resultCode, Intent data) { |
| 3155 | |
| 3156 | if (callingUid > 0) { |
| 3157 | mService.grantUriPermissionFromIntentLocked(callingUid, r.packageName, |
Nicolas Prevot | c6cf95c | 2014-05-29 11:30:36 +0100 | [diff] [blame] | 3158 | data, r.getUriPermissionsLocked(), r.userId); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 3159 | } |
| 3160 | |
| 3161 | if (DEBUG_RESULTS) Slog.v(TAG, "Send activity result to " + r |
| 3162 | + " : who=" + resultWho + " req=" + requestCode |
| 3163 | + " res=" + resultCode + " data=" + data); |
| 3164 | if (mResumedActivity == r && r.app != null && r.app.thread != null) { |
| 3165 | try { |
| 3166 | ArrayList<ResultInfo> list = new ArrayList<ResultInfo>(); |
| 3167 | list.add(new ResultInfo(resultWho, requestCode, |
| 3168 | resultCode, data)); |
Dianne Hackborn | be70785 | 2011-11-11 14:32:10 -0800 | [diff] [blame] | 3169 | r.app.thread.scheduleSendResult(r.appToken, list); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 3170 | return; |
| 3171 | } catch (Exception e) { |
| 3172 | Slog.w(TAG, "Exception thrown sending result to " + r, e); |
| 3173 | } |
| 3174 | } |
| 3175 | |
| 3176 | r.addResultLocked(null, resultWho, requestCode, resultCode, data); |
| 3177 | } |
| 3178 | |
Chong Zhang | 6cda19c | 2016-06-14 19:07:56 -0700 | [diff] [blame] | 3179 | private void adjustFocusedActivityStackLocked(ActivityRecord r, String reason) { |
| 3180 | if (!mStackSupervisor.isFocusedStack(this) || mResumedActivity != r) { |
Wale Ogunwale | d045c82 | 2015-12-02 09:14:28 -0800 | [diff] [blame] | 3181 | return; |
| 3182 | } |
| 3183 | |
| 3184 | final ActivityRecord next = topRunningActivityLocked(); |
| 3185 | final String myReason = reason + " adjustFocus"; |
| 3186 | if (next != r) { |
Wale Ogunwale | 4cea0f5 | 2015-12-25 06:30:31 -0800 | [diff] [blame] | 3187 | if (next != null && StackId.keepFocusInStackIfPossible(mStackId) && isFocusable()) { |
Wale Ogunwale | d045c82 | 2015-12-02 09:14:28 -0800 | [diff] [blame] | 3188 | // 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] | 3189 | // stack as long as there is a running activity. |
Wale Ogunwale | d045c82 | 2015-12-02 09:14:28 -0800 | [diff] [blame] | 3190 | return; |
| 3191 | } else { |
| 3192 | final TaskRecord task = r.task; |
| 3193 | if (r.frontOfTask && task == topTask() && task.isOverHomeStack()) { |
Wale Ogunwale | d34e80c | 2016-03-23 17:08:44 -0700 | [diff] [blame] | 3194 | final int taskToReturnTo = task.getTaskToReturnTo(); |
| 3195 | |
Wale Ogunwale | d045c82 | 2015-12-02 09:14:28 -0800 | [diff] [blame] | 3196 | // For non-fullscreen stack, we want to move the focus to the next visible |
| 3197 | // stack to prevent the home screen from moving to the top and obscuring |
| 3198 | // other visible stacks. |
Wale Ogunwale | d34e80c | 2016-03-23 17:08:44 -0700 | [diff] [blame] | 3199 | if (!mFullscreen |
| 3200 | && adjustFocusToNextFocusableStackLocked(taskToReturnTo, myReason)) { |
Wale Ogunwale | d045c82 | 2015-12-02 09:14:28 -0800 | [diff] [blame] | 3201 | return; |
| 3202 | } |
| 3203 | // Move the home stack to the top if this stack is fullscreen or there is no |
| 3204 | // other visible stack. |
Wale Ogunwale | d34e80c | 2016-03-23 17:08:44 -0700 | [diff] [blame] | 3205 | if (mStackSupervisor.moveHomeStackTaskToTop(taskToReturnTo, myReason)) { |
Wale Ogunwale | d045c82 | 2015-12-02 09:14:28 -0800 | [diff] [blame] | 3206 | // Activity focus was already adjusted. Nothing else to do... |
| 3207 | return; |
Wale Ogunwale | d80c263 | 2015-03-13 10:26:26 -0700 | [diff] [blame] | 3208 | } |
Craig Mautner | 04f0b70 | 2013-10-22 12:31:01 -0700 | [diff] [blame] | 3209 | } |
| 3210 | } |
Wale Ogunwale | d045c82 | 2015-12-02 09:14:28 -0800 | [diff] [blame] | 3211 | } |
Wale Ogunwale | d697cea | 2015-02-20 17:19:49 -0800 | [diff] [blame] | 3212 | |
Chong Zhang | 6cda19c | 2016-06-14 19:07:56 -0700 | [diff] [blame] | 3213 | mStackSupervisor.moveFocusableActivityStackToFrontLocked( |
| 3214 | mStackSupervisor.topRunningActivityLocked(), myReason); |
Craig Mautner | 04f0b70 | 2013-10-22 12:31:01 -0700 | [diff] [blame] | 3215 | } |
| 3216 | |
Wale Ogunwale | d34e80c | 2016-03-23 17:08:44 -0700 | [diff] [blame] | 3217 | private boolean adjustFocusToNextFocusableStackLocked(int taskToReturnTo, String reason) { |
Wale Ogunwale | 4cea0f5 | 2015-12-25 06:30:31 -0800 | [diff] [blame] | 3218 | final ActivityStack stack = getNextFocusableStackLocked(); |
| 3219 | final String myReason = reason + " adjustFocusToNextFocusableStack"; |
Wale Ogunwale | d697cea | 2015-02-20 17:19:49 -0800 | [diff] [blame] | 3220 | if (stack == null) { |
| 3221 | return false; |
| 3222 | } |
Wale Ogunwale | d34e80c | 2016-03-23 17:08:44 -0700 | [diff] [blame] | 3223 | |
Wale Ogunwale | c750f5f | 2016-03-28 07:43:51 -0700 | [diff] [blame] | 3224 | final ActivityRecord top = stack.topRunningActivityLocked(); |
| 3225 | |
| 3226 | if (stack.isHomeStack() && (top == null || !top.visible)) { |
| 3227 | // If we will be focusing on the home stack next and its current top activity isn't |
| 3228 | // 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] | 3229 | return mStackSupervisor.moveHomeStackTaskToTop(taskToReturnTo, reason); |
| 3230 | } |
Chong Zhang | 6cda19c | 2016-06-14 19:07:56 -0700 | [diff] [blame] | 3231 | |
| 3232 | stack.moveToFront(myReason); |
| 3233 | return true; |
Wale Ogunwale | d697cea | 2015-02-20 17:19:49 -0800 | [diff] [blame] | 3234 | } |
| 3235 | |
Craig Mautner | f333327 | 2013-04-22 10:55:53 -0700 | [diff] [blame] | 3236 | final void stopActivityLocked(ActivityRecord r) { |
Wale Ogunwale | ee006da | 2015-03-30 14:49:25 -0700 | [diff] [blame] | 3237 | if (DEBUG_SWITCH) Slog.d(TAG_SWITCH, "Stopping: " + r); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 3238 | if ((r.intent.getFlags()&Intent.FLAG_ACTIVITY_NO_HISTORY) != 0 |
| 3239 | || (r.info.flags&ActivityInfo.FLAG_NO_HISTORY) != 0) { |
| 3240 | if (!r.finishing) { |
Fyodor Kupolov | 9b80b94 | 2016-06-16 16:29:05 -0700 | [diff] [blame] | 3241 | if (!mService.isSleepingLocked()) { |
Wale Ogunwale | 0fc365c | 2015-05-25 19:35:42 -0700 | [diff] [blame] | 3242 | if (DEBUG_STATES) Slog.d(TAG_STATES, "no-history finish of " + r); |
Wale Ogunwale | 3f529ee | 2015-07-12 15:14:01 -0700 | [diff] [blame] | 3243 | if (requestFinishActivityLocked(r.appToken, Activity.RESULT_CANCELED, null, |
| 3244 | "stop-no-history", false)) { |
| 3245 | // Activity was finished, no need to continue trying to schedule stop. |
Chong Zhang | 6cda19c | 2016-06-14 19:07:56 -0700 | [diff] [blame] | 3246 | adjustFocusedActivityStackLocked(r, "stopActivityFinished"); |
Wale Ogunwale | 3f529ee | 2015-07-12 15:14:01 -0700 | [diff] [blame] | 3247 | r.resumeKeyDispatchingLocked(); |
| 3248 | return; |
| 3249 | } |
Christopher Tate | d3f175c | 2012-06-14 14:16:54 -0700 | [diff] [blame] | 3250 | } else { |
Wale Ogunwale | 0fc365c | 2015-05-25 19:35:42 -0700 | [diff] [blame] | 3251 | if (DEBUG_STATES) Slog.d(TAG_STATES, "Not finishing noHistory " + r |
Christopher Tate | d3f175c | 2012-06-14 14:16:54 -0700 | [diff] [blame] | 3252 | + " on stop because we're just sleeping"); |
| 3253 | } |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 3254 | } |
Christopher Tate | 5007ddd | 2012-06-12 13:08:18 -0700 | [diff] [blame] | 3255 | } |
| 3256 | |
| 3257 | if (r.app != null && r.app.thread != null) { |
Chong Zhang | 6cda19c | 2016-06-14 19:07:56 -0700 | [diff] [blame] | 3258 | adjustFocusedActivityStackLocked(r, "stopActivity"); |
Dianne Hackborn | 621e2fe | 2012-02-16 17:07:33 -0800 | [diff] [blame] | 3259 | r.resumeKeyDispatchingLocked(); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 3260 | try { |
| 3261 | r.stopped = false; |
Wale Ogunwale | 0fc365c | 2015-05-25 19:35:42 -0700 | [diff] [blame] | 3262 | if (DEBUG_STATES) Slog.v(TAG_STATES, |
| 3263 | "Moving to STOPPING: " + r + " (stop requested)"); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 3264 | r.state = ActivityState.STOPPING; |
Wale Ogunwale | ee006da | 2015-03-30 14:49:25 -0700 | [diff] [blame] | 3265 | if (DEBUG_VISIBILITY) Slog.v(TAG_VISIBILITY, |
| 3266 | "Stopping visible=" + r.visible + " for " + r); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 3267 | if (!r.visible) { |
Craig Mautner | ce5f3cb | 2013-04-22 08:58:54 -0700 | [diff] [blame] | 3268 | mWindowManager.setAppVisibility(r.appToken, false); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 3269 | } |
Wale Ogunwale | cd7043e | 2016-02-27 17:37:46 -0800 | [diff] [blame] | 3270 | EventLogTags.writeAmStopActivity( |
| 3271 | r.userId, System.identityHashCode(r), r.shortComponentName); |
Dianne Hackborn | be70785 | 2011-11-11 14:32:10 -0800 | [diff] [blame] | 3272 | r.app.thread.scheduleStopActivity(r.appToken, r.visible, r.configChangeFlags); |
Fyodor Kupolov | 9b80b94 | 2016-06-16 16:29:05 -0700 | [diff] [blame] | 3273 | if (mService.isSleepingOrShuttingDownLocked()) { |
Dianne Hackborn | 4eba96b | 2011-01-21 13:34:36 -0800 | [diff] [blame] | 3274 | r.setSleeping(true); |
| 3275 | } |
Craig Mautner | f7bfefb | 2013-05-16 17:30:44 -0700 | [diff] [blame] | 3276 | Message msg = mHandler.obtainMessage(STOP_TIMEOUT_MSG, r); |
Dianne Hackborn | 162bc0e | 2012-04-09 14:06:16 -0700 | [diff] [blame] | 3277 | mHandler.sendMessageDelayed(msg, STOP_TIMEOUT); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 3278 | } catch (Exception e) { |
| 3279 | // Maybe just ignore exceptions here... if the process |
| 3280 | // has crashed, our death notification will clean things |
| 3281 | // up. |
| 3282 | Slog.w(TAG, "Exception thrown during pause", e); |
| 3283 | // Just in case, assume it to be stopped. |
| 3284 | r.stopped = true; |
Wale Ogunwale | 0fc365c | 2015-05-25 19:35:42 -0700 | [diff] [blame] | 3285 | 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] | 3286 | r.state = ActivityState.STOPPED; |
Wale Ogunwale | f81c1d1 | 2016-01-12 12:20:18 -0800 | [diff] [blame] | 3287 | if (r.deferRelaunchUntilPaused) { |
Craig Mautner | ee2e45a | 2014-06-27 12:10:03 -0700 | [diff] [blame] | 3288 | destroyActivityLocked(r, true, "stop-except"); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 3289 | } |
| 3290 | } |
| 3291 | } |
| 3292 | } |
Craig Mautner | 23ac33b | 2013-04-01 16:26:35 -0700 | [diff] [blame] | 3293 | |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 3294 | /** |
| 3295 | * @return Returns true if the activity is being finished, false if for |
| 3296 | * some reason it is being left as-is. |
| 3297 | */ |
| 3298 | final boolean requestFinishActivityLocked(IBinder token, int resultCode, |
Dianne Hackborn | 2d1b378 | 2012-09-09 17:49:39 -0700 | [diff] [blame] | 3299 | Intent resultData, String reason, boolean oomAdj) { |
Craig Mautner | d74f7d7 | 2013-02-26 13:41:02 -0800 | [diff] [blame] | 3300 | ActivityRecord r = isInStackLocked(token); |
Wale Ogunwale | 0fc365c | 2015-05-25 19:35:42 -0700 | [diff] [blame] | 3301 | if (DEBUG_RESULTS || DEBUG_STATES) Slog.v(TAG_STATES, |
| 3302 | "Finishing activity token=" + token + " r=" |
Christopher Tate | d3f175c | 2012-06-14 14:16:54 -0700 | [diff] [blame] | 3303 | + ", result=" + resultCode + ", data=" + resultData |
| 3304 | + ", reason=" + reason); |
Craig Mautner | d74f7d7 | 2013-02-26 13:41:02 -0800 | [diff] [blame] | 3305 | if (r == null) { |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 3306 | return false; |
| 3307 | } |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 3308 | |
Craig Mautner | d44711d | 2013-02-23 11:24:36 -0800 | [diff] [blame] | 3309 | finishActivityLocked(r, resultCode, resultData, reason, oomAdj); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 3310 | return true; |
| 3311 | } |
| 3312 | |
Craig Mautner | d232895 | 2013-03-05 12:46:26 -0800 | [diff] [blame] | 3313 | final void finishSubActivityLocked(ActivityRecord self, String resultWho, int requestCode) { |
Craig Mautner | 9658b31 | 2013-02-28 10:55:59 -0800 | [diff] [blame] | 3314 | for (int taskNdx = mTaskHistory.size() - 1; taskNdx >= 0; --taskNdx) { |
| 3315 | ArrayList<ActivityRecord> activities = mTaskHistory.get(taskNdx).mActivities; |
| 3316 | for (int activityNdx = activities.size() - 1; activityNdx >= 0; --activityNdx) { |
| 3317 | ActivityRecord r = activities.get(activityNdx); |
| 3318 | if (r.resultTo == self && r.requestCode == requestCode) { |
| 3319 | if ((r.resultWho == null && resultWho == null) || |
| 3320 | (r.resultWho != null && r.resultWho.equals(resultWho))) { |
| 3321 | finishActivityLocked(r, Activity.RESULT_CANCELED, null, "request-sub", |
| 3322 | false); |
| 3323 | } |
Dianne Hackborn | ecc5a9c | 2012-04-26 18:56:09 -0700 | [diff] [blame] | 3324 | } |
| 3325 | } |
| 3326 | } |
Dianne Hackborn | 2d1b378 | 2012-09-09 17:49:39 -0700 | [diff] [blame] | 3327 | mService.updateOomAdjLocked(); |
Dianne Hackborn | ecc5a9c | 2012-04-26 18:56:09 -0700 | [diff] [blame] | 3328 | } |
| 3329 | |
Adrian Roos | 20d7df3 | 2016-01-12 18:59:43 +0100 | [diff] [blame] | 3330 | final TaskRecord finishTopRunningActivityLocked(ProcessRecord app, String reason) { |
Filip Gruszczynski | 3e85ba2 | 2015-10-05 22:48:30 -0700 | [diff] [blame] | 3331 | ActivityRecord r = topRunningActivityLocked(); |
Adrian Roos | 20d7df3 | 2016-01-12 18:59:43 +0100 | [diff] [blame] | 3332 | TaskRecord finishedTask = null; |
| 3333 | if (r == null || r.app != app) { |
| 3334 | return null; |
| 3335 | } |
| 3336 | Slog.w(TAG, " Force finishing activity " |
| 3337 | + r.intent.getComponent().flattenToShortString()); |
| 3338 | int taskNdx = mTaskHistory.indexOf(r.task); |
| 3339 | int activityNdx = r.task.mActivities.indexOf(r); |
| 3340 | finishActivityLocked(r, Activity.RESULT_CANCELED, null, reason, false); |
| 3341 | finishedTask = r.task; |
| 3342 | // Also terminate any activities below it that aren't yet |
| 3343 | // stopped, to avoid a situation where one will get |
| 3344 | // re-start our crashing activity once it gets resumed again. |
| 3345 | --activityNdx; |
| 3346 | if (activityNdx < 0) { |
| 3347 | do { |
| 3348 | --taskNdx; |
| 3349 | if (taskNdx < 0) { |
| 3350 | break; |
| 3351 | } |
| 3352 | activityNdx = mTaskHistory.get(taskNdx).mActivities.size() - 1; |
| 3353 | } while (activityNdx < 0); |
| 3354 | } |
| 3355 | if (activityNdx >= 0) { |
| 3356 | r = mTaskHistory.get(taskNdx).mActivities.get(activityNdx); |
| 3357 | if (r.state == ActivityState.RESUMED |
| 3358 | || r.state == ActivityState.PAUSING |
| 3359 | || r.state == ActivityState.PAUSED) { |
| 3360 | if (!r.isHomeActivity() || mService.mHomeProcess != r.app) { |
| 3361 | Slog.w(TAG, " Force finishing activity " |
| 3362 | + r.intent.getComponent().flattenToShortString()); |
| 3363 | finishActivityLocked(r, Activity.RESULT_CANCELED, null, reason, false); |
Craig Mautner | 05d6272ba | 2013-02-11 09:39:27 -0800 | [diff] [blame] | 3364 | } |
| 3365 | } |
| 3366 | } |
Adrian Roos | 20d7df3 | 2016-01-12 18:59:43 +0100 | [diff] [blame] | 3367 | return finishedTask; |
Craig Mautner | 05d6272ba | 2013-02-11 09:39:27 -0800 | [diff] [blame] | 3368 | } |
| 3369 | |
Dianne Hackborn | 6ea0d0a | 2014-07-02 16:23:21 -0700 | [diff] [blame] | 3370 | final void finishVoiceTask(IVoiceInteractionSession session) { |
| 3371 | IBinder sessionBinder = session.asBinder(); |
| 3372 | boolean didOne = false; |
| 3373 | for (int taskNdx = mTaskHistory.size() - 1; taskNdx >= 0; --taskNdx) { |
| 3374 | TaskRecord tr = mTaskHistory.get(taskNdx); |
| 3375 | if (tr.voiceSession != null && tr.voiceSession.asBinder() == sessionBinder) { |
| 3376 | for (int activityNdx = tr.mActivities.size() - 1; activityNdx >= 0; --activityNdx) { |
| 3377 | ActivityRecord r = tr.mActivities.get(activityNdx); |
| 3378 | if (!r.finishing) { |
| 3379 | finishActivityLocked(r, Activity.RESULT_CANCELED, null, "finish-voice", |
| 3380 | false); |
| 3381 | didOne = true; |
| 3382 | } |
| 3383 | } |
Amith Yamasani | 0af6fa7 | 2016-01-17 15:36:19 -0800 | [diff] [blame] | 3384 | } else { |
| 3385 | // Check if any of the activities are using voice |
| 3386 | for (int activityNdx = tr.mActivities.size() - 1; activityNdx >= 0; --activityNdx) { |
| 3387 | ActivityRecord r = tr.mActivities.get(activityNdx); |
| 3388 | if (r.voiceSession != null |
| 3389 | && r.voiceSession.asBinder() == sessionBinder) { |
| 3390 | // Inform of cancellation |
| 3391 | r.clearVoiceSessionLocked(); |
| 3392 | try { |
| 3393 | r.app.thread.scheduleLocalVoiceInteractionStarted((IBinder) r.appToken, |
| 3394 | null); |
| 3395 | } catch (RemoteException re) { |
| 3396 | // Ok |
| 3397 | } |
Amith Yamasani | 0af6fa7 | 2016-01-17 15:36:19 -0800 | [diff] [blame] | 3398 | mService.finishRunningVoiceLocked(); |
| 3399 | break; |
| 3400 | } |
| 3401 | } |
Dianne Hackborn | 6ea0d0a | 2014-07-02 16:23:21 -0700 | [diff] [blame] | 3402 | } |
| 3403 | } |
Amith Yamasani | 0af6fa7 | 2016-01-17 15:36:19 -0800 | [diff] [blame] | 3404 | |
Dianne Hackborn | 6ea0d0a | 2014-07-02 16:23:21 -0700 | [diff] [blame] | 3405 | if (didOne) { |
| 3406 | mService.updateOomAdjLocked(); |
| 3407 | } |
| 3408 | } |
| 3409 | |
Craig Mautner | d232895 | 2013-03-05 12:46:26 -0800 | [diff] [blame] | 3410 | final boolean finishActivityAffinityLocked(ActivityRecord r) { |
Craig Mautner | d74f7d7 | 2013-02-26 13:41:02 -0800 | [diff] [blame] | 3411 | ArrayList<ActivityRecord> activities = r.task.mActivities; |
| 3412 | for (int index = activities.indexOf(r); index >= 0; --index) { |
| 3413 | ActivityRecord cur = activities.get(index); |
Kenny Root | e6585b3 | 2013-12-13 12:00:26 -0800 | [diff] [blame] | 3414 | if (!Objects.equals(cur.taskAffinity, r.taskAffinity)) { |
Dianne Hackborn | ecc5a9c | 2012-04-26 18:56:09 -0700 | [diff] [blame] | 3415 | break; |
| 3416 | } |
Craig Mautner | de4ef02 | 2013-04-07 19:01:33 -0700 | [diff] [blame] | 3417 | finishActivityLocked(cur, Activity.RESULT_CANCELED, null, "request-affinity", true); |
Dianne Hackborn | ecc5a9c | 2012-04-26 18:56:09 -0700 | [diff] [blame] | 3418 | } |
| 3419 | return true; |
| 3420 | } |
| 3421 | |
Dianne Hackborn | 5c60743 | 2012-02-28 14:44:19 -0800 | [diff] [blame] | 3422 | final void finishActivityResultsLocked(ActivityRecord r, int resultCode, Intent resultData) { |
| 3423 | // send the result |
| 3424 | ActivityRecord resultTo = r.resultTo; |
| 3425 | if (resultTo != null) { |
Wale Ogunwale | ee006da | 2015-03-30 14:49:25 -0700 | [diff] [blame] | 3426 | if (DEBUG_RESULTS) Slog.v(TAG_RESULTS, "Adding result to " + resultTo |
Dianne Hackborn | 5c60743 | 2012-02-28 14:44:19 -0800 | [diff] [blame] | 3427 | + " who=" + r.resultWho + " req=" + r.requestCode |
| 3428 | + " res=" + resultCode + " data=" + resultData); |
Nicolas Prevot | c6cf95c | 2014-05-29 11:30:36 +0100 | [diff] [blame] | 3429 | if (resultTo.userId != r.userId) { |
Nicolas Prevot | 6b942b8 | 2014-06-02 15:20:42 +0100 | [diff] [blame] | 3430 | if (resultData != null) { |
Nicolas Prevot | 107f7b7 | 2015-07-01 16:31:48 +0100 | [diff] [blame] | 3431 | resultData.prepareToLeaveUser(r.userId); |
Nicolas Prevot | 6b942b8 | 2014-06-02 15:20:42 +0100 | [diff] [blame] | 3432 | } |
Nicolas Prevot | c6cf95c | 2014-05-29 11:30:36 +0100 | [diff] [blame] | 3433 | } |
Dianne Hackborn | 5c60743 | 2012-02-28 14:44:19 -0800 | [diff] [blame] | 3434 | if (r.info.applicationInfo.uid > 0) { |
| 3435 | mService.grantUriPermissionFromIntentLocked(r.info.applicationInfo.uid, |
| 3436 | resultTo.packageName, resultData, |
Nicolas Prevot | c6cf95c | 2014-05-29 11:30:36 +0100 | [diff] [blame] | 3437 | resultTo.getUriPermissionsLocked(), resultTo.userId); |
Dianne Hackborn | 5c60743 | 2012-02-28 14:44:19 -0800 | [diff] [blame] | 3438 | } |
| 3439 | resultTo.addResultLocked(r, r.resultWho, r.requestCode, resultCode, |
| 3440 | resultData); |
| 3441 | r.resultTo = null; |
| 3442 | } |
Wale Ogunwale | ee006da | 2015-03-30 14:49:25 -0700 | [diff] [blame] | 3443 | 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] | 3444 | |
| 3445 | // Make sure this HistoryRecord is not holding on to other resources, |
| 3446 | // because clients have remote IPC references to this object so we |
| 3447 | // can't assume that will go away and want to avoid circular IPC refs. |
| 3448 | r.results = null; |
| 3449 | r.pendingResults = null; |
| 3450 | r.newIntents = null; |
| 3451 | r.icicle = null; |
| 3452 | } |
| 3453 | |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 3454 | /** |
| 3455 | * @return Returns true if this activity has been removed from the history |
| 3456 | * list, or false if it is still in the list and will be removed later. |
| 3457 | */ |
Craig Mautner | f333327 | 2013-04-22 10:55:53 -0700 | [diff] [blame] | 3458 | final boolean finishActivityLocked(ActivityRecord r, int resultCode, Intent resultData, |
| 3459 | String reason, boolean oomAdj) { |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 3460 | if (r.finishing) { |
| 3461 | Slog.w(TAG, "Duplicate finish request for " + r); |
| 3462 | return false; |
| 3463 | } |
| 3464 | |
Wale Ogunwale | 7d70117 | 2015-03-11 15:36:30 -0700 | [diff] [blame] | 3465 | r.makeFinishingLocked(); |
Craig Mautner | aea74a5 | 2014-03-08 14:23:10 -0800 | [diff] [blame] | 3466 | final TaskRecord task = r.task; |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 3467 | EventLog.writeEvent(EventLogTags.AM_FINISH_ACTIVITY, |
Dianne Hackborn | b12e135 | 2012-09-26 11:39:20 -0700 | [diff] [blame] | 3468 | r.userId, System.identityHashCode(r), |
Craig Mautner | aea74a5 | 2014-03-08 14:23:10 -0800 | [diff] [blame] | 3469 | task.taskId, r.shortComponentName, reason); |
| 3470 | final ArrayList<ActivityRecord> activities = task.mActivities; |
Craig Mautner | d44711d | 2013-02-23 11:24:36 -0800 | [diff] [blame] | 3471 | final int index = activities.indexOf(r); |
| 3472 | if (index < (activities.size() - 1)) { |
Craig Mautner | aea74a5 | 2014-03-08 14:23:10 -0800 | [diff] [blame] | 3473 | task.setFrontOfTask(); |
Craig Mautner | d00f474 | 2014-03-12 14:17:26 -0700 | [diff] [blame] | 3474 | if ((r.intent.getFlags() & Intent.FLAG_ACTIVITY_CLEAR_WHEN_TASK_RESET) != 0) { |
Craig Mautner | d44711d | 2013-02-23 11:24:36 -0800 | [diff] [blame] | 3475 | // If the caller asked that this activity (and all above it) |
| 3476 | // be cleared when the task is reset, don't lose that information, |
| 3477 | // but propagate it up to the next activity. |
Craig Mautner | 1aa9d0d3f | 2013-12-16 15:58:31 -0800 | [diff] [blame] | 3478 | ActivityRecord next = activities.get(index+1); |
Craig Mautner | d44711d | 2013-02-23 11:24:36 -0800 | [diff] [blame] | 3479 | next.intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_WHEN_TASK_RESET); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 3480 | } |
| 3481 | } |
| 3482 | |
| 3483 | r.pauseKeyDispatchingLocked(); |
Craig Mautner | 04f0b70 | 2013-10-22 12:31:01 -0700 | [diff] [blame] | 3484 | |
Chong Zhang | 6cda19c | 2016-06-14 19:07:56 -0700 | [diff] [blame] | 3485 | adjustFocusedActivityStackLocked(r, "finishActivity"); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 3486 | |
Dianne Hackborn | 5c60743 | 2012-02-28 14:44:19 -0800 | [diff] [blame] | 3487 | finishActivityResultsLocked(r, resultCode, resultData); |
Craig Mautner | 2420ead | 2013-04-01 17:13:20 -0700 | [diff] [blame] | 3488 | |
Jorim Jaggi | af80db4 | 2016-04-07 19:19:15 -0700 | [diff] [blame] | 3489 | final boolean endTask = index <= 0; |
| 3490 | final int transit = endTask ? TRANSIT_TASK_CLOSE : TRANSIT_ACTIVITY_CLOSE; |
Craig Mautner | de4ef02 | 2013-04-07 19:01:33 -0700 | [diff] [blame] | 3491 | if (mResumedActivity == r) { |
Jorim Jaggi | af80db4 | 2016-04-07 19:19:15 -0700 | [diff] [blame] | 3492 | |
Wale Ogunwale | ee006da | 2015-03-30 14:49:25 -0700 | [diff] [blame] | 3493 | if (DEBUG_VISIBILITY || DEBUG_TRANSITION) Slog.v(TAG_TRANSITION, |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 3494 | "Prepare close transition: finishing " + r); |
Jorim Jaggi | af80db4 | 2016-04-07 19:19:15 -0700 | [diff] [blame] | 3495 | mWindowManager.prepareAppTransition(transit, false); |
Craig Mautner | 0247fc8 | 2013-02-28 14:32:06 -0800 | [diff] [blame] | 3496 | |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 3497 | // Tell window manager to prepare for this one to be removed. |
Craig Mautner | ce5f3cb | 2013-04-22 08:58:54 -0700 | [diff] [blame] | 3498 | mWindowManager.setAppVisibility(r.appToken, false); |
Craig Mautner | dbcb31f | 2013-04-02 12:32:53 -0700 | [diff] [blame] | 3499 | |
Dianne Hackborn | 621e2fe | 2012-02-16 17:07:33 -0800 | [diff] [blame] | 3500 | if (mPausingActivity == null) { |
Wale Ogunwale | ee006da | 2015-03-30 14:49:25 -0700 | [diff] [blame] | 3501 | if (DEBUG_PAUSE) Slog.v(TAG_PAUSE, "Finish needs to pause: " + r); |
| 3502 | if (DEBUG_USER_LEAVING) Slog.v(TAG_USER_LEAVING, |
| 3503 | "finish() => pause with userLeaving=false"); |
Dianne Hackborn | a4e102e | 2014-09-04 22:52:27 -0700 | [diff] [blame] | 3504 | startPausingLocked(false, false, false, false); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 3505 | } |
| 3506 | |
Craig Mautner | aea74a5 | 2014-03-08 14:23:10 -0800 | [diff] [blame] | 3507 | if (endTask) { |
Craig Mautner | 15df08a | 2015-04-01 12:17:18 -0700 | [diff] [blame] | 3508 | mStackSupervisor.removeLockedTaskLocked(task); |
Craig Mautner | aea74a5 | 2014-03-08 14:23:10 -0800 | [diff] [blame] | 3509 | } |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 3510 | } else if (r.state != ActivityState.PAUSING) { |
| 3511 | // If the activity is PAUSING, we will complete the finish once |
| 3512 | // it is done pausing; else we can just directly finish it here. |
Wale Ogunwale | ee006da | 2015-03-30 14:49:25 -0700 | [diff] [blame] | 3513 | if (DEBUG_PAUSE) Slog.v(TAG_PAUSE, "Finish not pausing: " + r); |
Chong Zhang | 66ed4c6 | 2015-11-12 14:56:28 -0800 | [diff] [blame] | 3514 | if (r.visible) { |
Jorim Jaggi | af80db4 | 2016-04-07 19:19:15 -0700 | [diff] [blame] | 3515 | mWindowManager.prepareAppTransition(transit, false); |
Chong Zhang | 66ed4c6 | 2015-11-12 14:56:28 -0800 | [diff] [blame] | 3516 | mWindowManager.setAppVisibility(r.appToken, false); |
Jorim Jaggi | af80db4 | 2016-04-07 19:19:15 -0700 | [diff] [blame] | 3517 | mWindowManager.executeAppTransition(); |
Chong Zhang | b8bd069 | 2016-04-27 17:29:28 -0700 | [diff] [blame] | 3518 | if (!mStackSupervisor.mWaitingVisibleActivities.contains(r)) { |
| 3519 | mStackSupervisor.mWaitingVisibleActivities.add(r); |
| 3520 | } |
Chong Zhang | 66ed4c6 | 2015-11-12 14:56:28 -0800 | [diff] [blame] | 3521 | } |
Chong Zhang | 4c5f7ff | 2016-04-22 11:31:51 -0700 | [diff] [blame] | 3522 | return finishCurrentActivityLocked(r, (r.visible || r.nowVisible) ? |
| 3523 | FINISH_AFTER_VISIBLE : FINISH_AFTER_PAUSE, oomAdj) == null; |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 3524 | } else { |
Wale Ogunwale | ee006da | 2015-03-30 14:49:25 -0700 | [diff] [blame] | 3525 | 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] | 3526 | } |
| 3527 | |
| 3528 | return false; |
| 3529 | } |
| 3530 | |
Craig Mautner | f333327 | 2013-04-22 10:55:53 -0700 | [diff] [blame] | 3531 | static final int FINISH_IMMEDIATELY = 0; |
| 3532 | static final int FINISH_AFTER_PAUSE = 1; |
| 3533 | static final int FINISH_AFTER_VISIBLE = 2; |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 3534 | |
Craig Mautner | f333327 | 2013-04-22 10:55:53 -0700 | [diff] [blame] | 3535 | final ActivityRecord finishCurrentActivityLocked(ActivityRecord r, int mode, boolean oomAdj) { |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 3536 | // First things first: if this activity is currently visible, |
| 3537 | // and the resumed activity is not yet visible, then hold off on |
| 3538 | // finishing until the resumed one becomes visible. |
Chong Zhang | 824b6dc | 2016-04-27 14:11:12 -0700 | [diff] [blame] | 3539 | |
| 3540 | final ActivityRecord next = mStackSupervisor.topRunningActivityLocked(); |
| 3541 | |
Chong Zhang | efd9a5b | 2016-04-26 16:21:07 -0700 | [diff] [blame] | 3542 | if (mode == FINISH_AFTER_VISIBLE && (r.visible || r.nowVisible) |
Chong Zhang | 824b6dc | 2016-04-27 14:11:12 -0700 | [diff] [blame] | 3543 | && next != null && !next.nowVisible) { |
Craig Mautner | de4ef02 | 2013-04-07 19:01:33 -0700 | [diff] [blame] | 3544 | if (!mStackSupervisor.mStoppingActivities.contains(r)) { |
Chong Zhang | 46b1ac6 | 2016-02-18 17:53:57 -0800 | [diff] [blame] | 3545 | addToStopping(r, false /* immediate */); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 3546 | } |
Wale Ogunwale | 0fc365c | 2015-05-25 19:35:42 -0700 | [diff] [blame] | 3547 | if (DEBUG_STATES) Slog.v(TAG_STATES, |
| 3548 | "Moving to STOPPING: "+ r + " (finish requested)"); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 3549 | r.state = ActivityState.STOPPING; |
Dianne Hackborn | 2d1b378 | 2012-09-09 17:49:39 -0700 | [diff] [blame] | 3550 | if (oomAdj) { |
| 3551 | mService.updateOomAdjLocked(); |
| 3552 | } |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 3553 | return r; |
| 3554 | } |
| 3555 | |
| 3556 | // make sure the record is cleaned out of other places. |
Craig Mautner | de4ef02 | 2013-04-07 19:01:33 -0700 | [diff] [blame] | 3557 | mStackSupervisor.mStoppingActivities.remove(r); |
Craig Mautner | 0eea92c | 2013-05-16 13:35:39 -0700 | [diff] [blame] | 3558 | mStackSupervisor.mGoingToSleepActivities.remove(r); |
Craig Mautner | de4ef02 | 2013-04-07 19:01:33 -0700 | [diff] [blame] | 3559 | mStackSupervisor.mWaitingVisibleActivities.remove(r); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 3560 | if (mResumedActivity == r) { |
| 3561 | mResumedActivity = null; |
| 3562 | } |
| 3563 | final ActivityState prevState = r.state; |
Wale Ogunwale | 0fc365c | 2015-05-25 19:35:42 -0700 | [diff] [blame] | 3564 | if (DEBUG_STATES) Slog.v(TAG_STATES, "Moving to FINISHING: " + r); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 3565 | r.state = ActivityState.FINISHING; |
| 3566 | |
| 3567 | if (mode == FINISH_IMMEDIATELY |
Wale Ogunwale | ae30f30 | 2016-05-02 10:35:45 -0700 | [diff] [blame] | 3568 | || (prevState == ActivityState.PAUSED |
| 3569 | && (mode == FINISH_AFTER_PAUSE || mStackId == PINNED_STACK_ID)) |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 3570 | || prevState == ActivityState.STOPPED |
| 3571 | || prevState == ActivityState.INITIALIZING) { |
Wale Ogunwale | 7d70117 | 2015-03-11 15:36:30 -0700 | [diff] [blame] | 3572 | r.makeFinishingLocked(); |
Craig Mautner | ee2e45a | 2014-06-27 12:10:03 -0700 | [diff] [blame] | 3573 | boolean activityRemoved = destroyActivityLocked(r, true, "finish-imm"); |
Dianne Hackborn | 42e620c | 2012-06-24 13:20:51 -0700 | [diff] [blame] | 3574 | if (activityRemoved) { |
Wale Ogunwale | d046a01 | 2015-12-24 13:05:59 -0800 | [diff] [blame] | 3575 | mStackSupervisor.resumeFocusedStackTopActivityLocked(); |
Dianne Hackborn | 42e620c | 2012-06-24 13:20:51 -0700 | [diff] [blame] | 3576 | } |
Wale Ogunwale | 0fc365c | 2015-05-25 19:35:42 -0700 | [diff] [blame] | 3577 | if (DEBUG_CONTAINERS) Slog.d(TAG_CONTAINERS, |
Craig Mautner | d163e75 | 2014-06-13 17:18:47 -0700 | [diff] [blame] | 3578 | "destroyActivityLocked: finishCurrentActivityLocked r=" + r + |
| 3579 | " destroy returned removed=" + activityRemoved); |
Dianne Hackborn | 42e620c | 2012-06-24 13:20:51 -0700 | [diff] [blame] | 3580 | return activityRemoved ? null : r; |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 3581 | } |
Craig Mautner | 05d6272ba | 2013-02-11 09:39:27 -0800 | [diff] [blame] | 3582 | |
| 3583 | // Need to go through the full pause cycle to get this |
| 3584 | // activity into the stopped state and then finish it. |
Wale Ogunwale | e23149f | 2015-03-06 15:39:44 -0800 | [diff] [blame] | 3585 | if (DEBUG_ALL) Slog.v(TAG, "Enqueueing pending finish: " + r); |
Craig Mautner | f333327 | 2013-04-22 10:55:53 -0700 | [diff] [blame] | 3586 | mStackSupervisor.mFinishingActivities.add(r); |
Martin Wallgren | c8733b8 | 2011-08-31 12:39:31 +0200 | [diff] [blame] | 3587 | r.resumeKeyDispatchingLocked(); |
Wale Ogunwale | d046a01 | 2015-12-24 13:05:59 -0800 | [diff] [blame] | 3588 | mStackSupervisor.resumeFocusedStackTopActivityLocked(); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 3589 | return r; |
| 3590 | } |
| 3591 | |
Craig Mautner | ee36c77 | 2014-07-16 14:56:05 -0700 | [diff] [blame] | 3592 | void finishAllActivitiesLocked(boolean immediately) { |
| 3593 | boolean noActivitiesInStack = true; |
Craig Mautner | f4c909b | 2014-04-17 18:39:38 -0700 | [diff] [blame] | 3594 | for (int taskNdx = mTaskHistory.size() - 1; taskNdx >= 0; --taskNdx) { |
| 3595 | final ArrayList<ActivityRecord> activities = mTaskHistory.get(taskNdx).mActivities; |
| 3596 | for (int activityNdx = activities.size() - 1; activityNdx >= 0; --activityNdx) { |
| 3597 | final ActivityRecord r = activities.get(activityNdx); |
Craig Mautner | ee36c77 | 2014-07-16 14:56:05 -0700 | [diff] [blame] | 3598 | noActivitiesInStack = false; |
| 3599 | if (r.finishing && !immediately) { |
Craig Mautner | f4c909b | 2014-04-17 18:39:38 -0700 | [diff] [blame] | 3600 | continue; |
| 3601 | } |
Craig Mautner | ee36c77 | 2014-07-16 14:56:05 -0700 | [diff] [blame] | 3602 | Slog.d(TAG, "finishAllActivitiesLocked: finishing " + r + " immediately"); |
Craig Mautner | f4c909b | 2014-04-17 18:39:38 -0700 | [diff] [blame] | 3603 | finishCurrentActivityLocked(r, FINISH_IMMEDIATELY, false); |
| 3604 | } |
| 3605 | } |
Craig Mautner | ee36c77 | 2014-07-16 14:56:05 -0700 | [diff] [blame] | 3606 | if (noActivitiesInStack) { |
| 3607 | mActivityContainer.onTaskListEmptyLocked(); |
| 3608 | } |
Craig Mautner | f4c909b | 2014-04-17 18:39:38 -0700 | [diff] [blame] | 3609 | } |
| 3610 | |
Dianne Hackborn | 6f4d61f | 2014-08-21 17:50:42 -0700 | [diff] [blame] | 3611 | final boolean shouldUpRecreateTaskLocked(ActivityRecord srec, String destAffinity) { |
| 3612 | // Basic case: for simple app-centric recents, we need to recreate |
| 3613 | // the task if the affinity has changed. |
| 3614 | if (srec == null || srec.task.affinity == null || |
| 3615 | !srec.task.affinity.equals(destAffinity)) { |
| 3616 | return true; |
| 3617 | } |
| 3618 | // Document-centric case: an app may be split in to multiple documents; |
| 3619 | // they need to re-create their task if this current activity is the root |
| 3620 | // of a document, unless simply finishing it will return them to the the |
| 3621 | // correct app behind. |
Dianne Hackborn | f3eb843 | 2014-09-19 17:21:46 -0700 | [diff] [blame] | 3622 | if (srec.frontOfTask && srec.task != null && srec.task.getBaseIntent() != null |
| 3623 | && srec.task.getBaseIntent().isDocument()) { |
Dianne Hackborn | 6f4d61f | 2014-08-21 17:50:42 -0700 | [diff] [blame] | 3624 | // Okay, this activity is at the root of its task. What to do, what to do... |
| 3625 | if (srec.task.getTaskToReturnTo() != ActivityRecord.APPLICATION_ACTIVITY_TYPE) { |
| 3626 | // Finishing won't return to an application, so we need to recreate. |
| 3627 | return true; |
| 3628 | } |
| 3629 | // We now need to get the task below it to determine what to do. |
| 3630 | int taskIdx = mTaskHistory.indexOf(srec.task); |
| 3631 | if (taskIdx <= 0) { |
| 3632 | Slog.w(TAG, "shouldUpRecreateTask: task not in history for " + srec); |
| 3633 | return false; |
| 3634 | } |
| 3635 | if (taskIdx == 0) { |
| 3636 | // At the bottom of the stack, nothing to go back to. |
| 3637 | return true; |
| 3638 | } |
| 3639 | TaskRecord prevTask = mTaskHistory.get(taskIdx); |
| 3640 | if (!srec.task.affinity.equals(prevTask.affinity)) { |
| 3641 | // These are different apps, so need to recreate. |
| 3642 | return true; |
| 3643 | } |
| 3644 | } |
| 3645 | return false; |
| 3646 | } |
| 3647 | |
Wale Ogunwale | 7d70117 | 2015-03-11 15:36:30 -0700 | [diff] [blame] | 3648 | final boolean navigateUpToLocked(ActivityRecord srec, Intent destIntent, int resultCode, |
Craig Mautner | 05d6272ba | 2013-02-11 09:39:27 -0800 | [diff] [blame] | 3649 | Intent resultData) { |
Craig Mautner | 0247fc8 | 2013-02-28 14:32:06 -0800 | [diff] [blame] | 3650 | final TaskRecord task = srec.task; |
| 3651 | final ArrayList<ActivityRecord> activities = task.mActivities; |
| 3652 | final int start = activities.indexOf(srec); |
| 3653 | if (!mTaskHistory.contains(task) || (start < 0)) { |
Craig Mautner | 05d6272ba | 2013-02-11 09:39:27 -0800 | [diff] [blame] | 3654 | return false; |
| 3655 | } |
| 3656 | int finishTo = start - 1; |
Craig Mautner | 0247fc8 | 2013-02-28 14:32:06 -0800 | [diff] [blame] | 3657 | ActivityRecord parent = finishTo < 0 ? null : activities.get(finishTo); |
Craig Mautner | 05d6272ba | 2013-02-11 09:39:27 -0800 | [diff] [blame] | 3658 | boolean foundParentInTask = false; |
Craig Mautner | 0247fc8 | 2013-02-28 14:32:06 -0800 | [diff] [blame] | 3659 | final ComponentName dest = destIntent.getComponent(); |
| 3660 | if (start > 0 && dest != null) { |
| 3661 | for (int i = finishTo; i >= 0; i--) { |
| 3662 | ActivityRecord r = activities.get(i); |
| 3663 | if (r.info.packageName.equals(dest.getPackageName()) && |
Craig Mautner | 05d6272ba | 2013-02-11 09:39:27 -0800 | [diff] [blame] | 3664 | r.info.name.equals(dest.getClassName())) { |
| 3665 | finishTo = i; |
| 3666 | parent = r; |
| 3667 | foundParentInTask = true; |
| 3668 | break; |
| 3669 | } |
| 3670 | } |
| 3671 | } |
| 3672 | |
| 3673 | IActivityController controller = mService.mController; |
| 3674 | if (controller != null) { |
| 3675 | ActivityRecord next = topRunningActivityLocked(srec.appToken, 0); |
| 3676 | if (next != null) { |
| 3677 | // ask watcher if this is allowed |
| 3678 | boolean resumeOK = true; |
| 3679 | try { |
| 3680 | resumeOK = controller.activityResuming(next.packageName); |
| 3681 | } catch (RemoteException e) { |
| 3682 | mService.mController = null; |
Kenny Root | add5821 | 2013-05-07 09:47:34 -0700 | [diff] [blame] | 3683 | Watchdog.getInstance().setActivityController(null); |
Craig Mautner | 05d6272ba | 2013-02-11 09:39:27 -0800 | [diff] [blame] | 3684 | } |
| 3685 | |
| 3686 | if (!resumeOK) { |
| 3687 | return false; |
| 3688 | } |
| 3689 | } |
| 3690 | } |
| 3691 | final long origId = Binder.clearCallingIdentity(); |
| 3692 | for (int i = start; i > finishTo; i--) { |
Craig Mautner | 0247fc8 | 2013-02-28 14:32:06 -0800 | [diff] [blame] | 3693 | ActivityRecord r = activities.get(i); |
| 3694 | requestFinishActivityLocked(r.appToken, resultCode, resultData, "navigate-up", true); |
Craig Mautner | 05d6272ba | 2013-02-11 09:39:27 -0800 | [diff] [blame] | 3695 | // Only return the supplied result for the first activity finished |
| 3696 | resultCode = Activity.RESULT_CANCELED; |
| 3697 | resultData = null; |
| 3698 | } |
| 3699 | |
| 3700 | if (parent != null && foundParentInTask) { |
| 3701 | final int parentLaunchMode = parent.info.launchMode; |
| 3702 | final int destIntentFlags = destIntent.getFlags(); |
| 3703 | if (parentLaunchMode == ActivityInfo.LAUNCH_SINGLE_INSTANCE || |
| 3704 | parentLaunchMode == ActivityInfo.LAUNCH_SINGLE_TASK || |
| 3705 | parentLaunchMode == ActivityInfo.LAUNCH_SINGLE_TOP || |
| 3706 | (destIntentFlags & Intent.FLAG_ACTIVITY_CLEAR_TOP) != 0) { |
Dianne Hackborn | 85d558c | 2014-11-04 10:31:54 -0800 | [diff] [blame] | 3707 | parent.deliverNewIntentLocked(srec.info.applicationInfo.uid, destIntent, |
| 3708 | srec.packageName); |
Craig Mautner | 05d6272ba | 2013-02-11 09:39:27 -0800 | [diff] [blame] | 3709 | } else { |
| 3710 | try { |
| 3711 | ActivityInfo aInfo = AppGlobals.getPackageManager().getActivityInfo( |
| 3712 | destIntent.getComponent(), 0, srec.userId); |
Filip Gruszczynski | 303210b | 2016-01-08 16:28:08 -0800 | [diff] [blame] | 3713 | int res = mService.mActivityStarter.startActivityLocked(srec.app.thread, |
| 3714 | destIntent, null /*ephemeralIntent*/, null, aInfo, null /*rInfo*/, null, |
| 3715 | null, parent.appToken, null, 0, -1, parent.launchedFromUid, |
Todd Kennedy | 7440f17 | 2015-12-09 14:31:22 -0800 | [diff] [blame] | 3716 | parent.launchedFromPackage, -1, parent.launchedFromUid, 0, null, |
| 3717 | false, true, null, null, null); |
Craig Mautner | 05d6272ba | 2013-02-11 09:39:27 -0800 | [diff] [blame] | 3718 | foundParentInTask = res == ActivityManager.START_SUCCESS; |
| 3719 | } catch (RemoteException e) { |
| 3720 | foundParentInTask = false; |
| 3721 | } |
| 3722 | requestFinishActivityLocked(parent.appToken, resultCode, |
Todd Kennedy | 539db51 | 2014-12-15 09:57:55 -0800 | [diff] [blame] | 3723 | resultData, "navigate-top", true); |
Craig Mautner | 05d6272ba | 2013-02-11 09:39:27 -0800 | [diff] [blame] | 3724 | } |
| 3725 | } |
| 3726 | Binder.restoreCallingIdentity(origId); |
| 3727 | return foundParentInTask; |
| 3728 | } |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 3729 | /** |
| 3730 | * Perform the common clean-up of an activity record. This is called both |
| 3731 | * as part of destroyActivityLocked() (when destroying the client-side |
| 3732 | * representation) and cleaning things up as a result of its hosting |
| 3733 | * processing going away, in which case there is no remaining client-side |
| 3734 | * state to destroy so only the cleanup here is needed. |
Craig Mautner | acebdc8 | 2015-02-24 10:53:03 -0800 | [diff] [blame] | 3735 | * |
| 3736 | * Note: Call before #removeActivityFromHistoryLocked. |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 3737 | */ |
Dianne Hackborn | ce86ba8 | 2011-07-13 19:33:41 -0700 | [diff] [blame] | 3738 | final void cleanUpActivityLocked(ActivityRecord r, boolean cleanServices, |
| 3739 | boolean setState) { |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 3740 | if (mResumedActivity == r) { |
| 3741 | mResumedActivity = null; |
| 3742 | } |
Craig Mautner | 1872ce3 | 2014-03-28 23:05:42 +0000 | [diff] [blame] | 3743 | if (mPausingActivity == r) { |
| 3744 | mPausingActivity = null; |
| 3745 | } |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 3746 | |
Wale Ogunwale | f81c1d1 | 2016-01-12 12:20:18 -0800 | [diff] [blame] | 3747 | r.deferRelaunchUntilPaused = false; |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 3748 | r.frozenBeforeDestroy = false; |
| 3749 | |
Dianne Hackborn | ce86ba8 | 2011-07-13 19:33:41 -0700 | [diff] [blame] | 3750 | if (setState) { |
Wale Ogunwale | 0fc365c | 2015-05-25 19:35:42 -0700 | [diff] [blame] | 3751 | 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] | 3752 | r.state = ActivityState.DESTROYED; |
Wale Ogunwale | 0fc365c | 2015-05-25 19:35:42 -0700 | [diff] [blame] | 3753 | 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] | 3754 | r.app = null; |
Dianne Hackborn | ce86ba8 | 2011-07-13 19:33:41 -0700 | [diff] [blame] | 3755 | } |
| 3756 | |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 3757 | // Make sure this record is no longer in the pending finishes list. |
| 3758 | // This could happen, for example, if we are trimming activities |
| 3759 | // down to the max limit while they are still waiting to finish. |
Craig Mautner | f333327 | 2013-04-22 10:55:53 -0700 | [diff] [blame] | 3760 | mStackSupervisor.mFinishingActivities.remove(r); |
Craig Mautner | de4ef02 | 2013-04-07 19:01:33 -0700 | [diff] [blame] | 3761 | mStackSupervisor.mWaitingVisibleActivities.remove(r); |
Craig Mautner | 2420ead | 2013-04-01 17:13:20 -0700 | [diff] [blame] | 3762 | |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 3763 | // Remove any pending results. |
| 3764 | if (r.finishing && r.pendingResults != null) { |
| 3765 | for (WeakReference<PendingIntentRecord> apr : r.pendingResults) { |
| 3766 | PendingIntentRecord rec = apr.get(); |
| 3767 | if (rec != null) { |
| 3768 | mService.cancelIntentSenderLocked(rec, false); |
| 3769 | } |
| 3770 | } |
| 3771 | r.pendingResults = null; |
| 3772 | } |
| 3773 | |
| 3774 | if (cleanServices) { |
Craig Mautner | 2420ead | 2013-04-01 17:13:20 -0700 | [diff] [blame] | 3775 | cleanUpActivityServicesLocked(r); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 3776 | } |
| 3777 | |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 3778 | // Get rid of any pending idle timeouts. |
Dianne Hackborn | 42e620c | 2012-06-24 13:20:51 -0700 | [diff] [blame] | 3779 | removeTimeoutsForActivityLocked(r); |
Jose Lima | 4b6c669 | 2014-08-12 17:41:12 -0700 | [diff] [blame] | 3780 | if (getVisibleBehindActivity() == r) { |
| 3781 | mStackSupervisor.requestVisibleBehindLocked(r, false); |
Craig Mautner | ee2e45a | 2014-06-27 12:10:03 -0700 | [diff] [blame] | 3782 | } |
Wale Ogunwale | 8fd7542 | 2016-06-24 14:20:37 -0700 | [diff] [blame] | 3783 | |
| 3784 | // Clean-up activities are no longer relaunching (e.g. app process died). Notify window |
| 3785 | // manager so it can update its bookkeeping. |
| 3786 | mWindowManager.notifyAppRelaunchesCleared(r.appToken); |
Dianne Hackborn | 42e620c | 2012-06-24 13:20:51 -0700 | [diff] [blame] | 3787 | } |
| 3788 | |
| 3789 | private void removeTimeoutsForActivityLocked(ActivityRecord r) { |
Craig Mautner | f333327 | 2013-04-22 10:55:53 -0700 | [diff] [blame] | 3790 | mStackSupervisor.removeTimeoutsForActivityLocked(r); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 3791 | mHandler.removeMessages(PAUSE_TIMEOUT_MSG, r); |
Dianne Hackborn | 162bc0e | 2012-04-09 14:06:16 -0700 | [diff] [blame] | 3792 | mHandler.removeMessages(STOP_TIMEOUT_MSG, r); |
Dianne Hackborn | 0c5001d | 2011-04-12 18:16:08 -0700 | [diff] [blame] | 3793 | mHandler.removeMessages(DESTROY_TIMEOUT_MSG, r); |
Dianne Hackborn | 2a29b3a | 2012-03-15 15:48:38 -0700 | [diff] [blame] | 3794 | r.finishLaunchTickingLocked(); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 3795 | } |
| 3796 | |
Chong Zhang | e4cf36f | 2016-06-03 14:38:33 -0700 | [diff] [blame] | 3797 | private void removeActivityFromHistoryLocked( |
| 3798 | ActivityRecord r, TaskRecord oldTop, String reason) { |
Craig Mautner | 34b73df | 2014-01-12 21:11:08 -0800 | [diff] [blame] | 3799 | mStackSupervisor.removeChildActivityContainers(r); |
Dianne Hackborn | cc5a055 | 2012-10-01 16:32:39 -0700 | [diff] [blame] | 3800 | finishActivityResultsLocked(r, Activity.RESULT_CANCELED, null); |
Wale Ogunwale | 7d70117 | 2015-03-11 15:36:30 -0700 | [diff] [blame] | 3801 | r.makeFinishingLocked(); |
Wale Ogunwale | 0fc365c | 2015-05-25 19:35:42 -0700 | [diff] [blame] | 3802 | if (DEBUG_ADD_REMOVE) Slog.i(TAG_ADD_REMOVE, |
| 3803 | "Removing activity " + r + " from stack callers=" + Debug.getCallers(5)); |
| 3804 | |
Dianne Hackborn | cc5a055 | 2012-10-01 16:32:39 -0700 | [diff] [blame] | 3805 | r.takeFromHistory(); |
| 3806 | removeTimeoutsForActivityLocked(r); |
Wale Ogunwale | 0fc365c | 2015-05-25 19:35:42 -0700 | [diff] [blame] | 3807 | if (DEBUG_STATES) Slog.v(TAG_STATES, |
| 3808 | "Moving to DESTROYED: " + r + " (removed from history)"); |
Dianne Hackborn | cc5a055 | 2012-10-01 16:32:39 -0700 | [diff] [blame] | 3809 | r.state = ActivityState.DESTROYED; |
Wale Ogunwale | 0fc365c | 2015-05-25 19:35:42 -0700 | [diff] [blame] | 3810 | 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] | 3811 | r.app = null; |
Craig Mautner | ce5f3cb | 2013-04-22 08:58:54 -0700 | [diff] [blame] | 3812 | mWindowManager.removeAppToken(r.appToken); |
Dianne Hackborn | cc5a055 | 2012-10-01 16:32:39 -0700 | [diff] [blame] | 3813 | if (VALIDATE_TOKENS) { |
| 3814 | validateAppTokensLocked(); |
| 3815 | } |
Craig Mautner | 312ba86 | 2014-02-10 17:55:01 -0800 | [diff] [blame] | 3816 | final TaskRecord task = r.task; |
Chong Zhang | e4cf36f | 2016-06-03 14:38:33 -0700 | [diff] [blame] | 3817 | final TaskRecord topTask = oldTop != null ? oldTop : topTask(); |
Craig Mautner | 312ba86 | 2014-02-10 17:55:01 -0800 | [diff] [blame] | 3818 | if (task != null && task.removeActivity(r)) { |
Wale Ogunwale | ee006da | 2015-03-30 14:49:25 -0700 | [diff] [blame] | 3819 | if (DEBUG_STACK) Slog.i(TAG_STACK, |
Craig Mautner | 312ba86 | 2014-02-10 17:55:01 -0800 | [diff] [blame] | 3820 | "removeActivityFromHistoryLocked: last activity removed from " + this); |
Chong Zhang | e4cf36f | 2016-06-03 14:38:33 -0700 | [diff] [blame] | 3821 | if (mStackSupervisor.isFocusedStack(this) && task == topTask && |
Craig Mautner | 84984fa | 2014-06-19 11:19:20 -0700 | [diff] [blame] | 3822 | task.isOverHomeStack()) { |
Craig Mautner | 299f960 | 2015-01-26 09:47:33 -0800 | [diff] [blame] | 3823 | mStackSupervisor.moveHomeStackTaskToTop(task.getTaskToReturnTo(), reason); |
Craig Mautner | 312ba86 | 2014-02-10 17:55:01 -0800 | [diff] [blame] | 3824 | } |
Craig Mautner | 299f960 | 2015-01-26 09:47:33 -0800 | [diff] [blame] | 3825 | removeTask(task, reason); |
Craig Mautner | 312ba86 | 2014-02-10 17:55:01 -0800 | [diff] [blame] | 3826 | } |
Dianne Hackborn | cc5a055 | 2012-10-01 16:32:39 -0700 | [diff] [blame] | 3827 | cleanUpActivityServicesLocked(r); |
| 3828 | r.removeUriPermissionsLocked(); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 3829 | } |
Craig Mautner | dbcb31f | 2013-04-02 12:32:53 -0700 | [diff] [blame] | 3830 | |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 3831 | /** |
| 3832 | * Perform clean-up of service connections in an activity record. |
| 3833 | */ |
| 3834 | final void cleanUpActivityServicesLocked(ActivityRecord r) { |
| 3835 | // Throw away any services that have been bound by this activity. |
| 3836 | if (r.connections != null) { |
| 3837 | Iterator<ConnectionRecord> it = r.connections.iterator(); |
| 3838 | while (it.hasNext()) { |
| 3839 | ConnectionRecord c = it.next(); |
Dianne Hackborn | 599db5c | 2012-08-03 19:28:48 -0700 | [diff] [blame] | 3840 | mService.mServices.removeConnectionLocked(c, null, r); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 3841 | } |
| 3842 | r.connections = null; |
| 3843 | } |
| 3844 | } |
Dianne Hackborn | 755c8bf | 2012-05-07 15:06:09 -0700 | [diff] [blame] | 3845 | |
Craig Mautner | ee2e45a | 2014-06-27 12:10:03 -0700 | [diff] [blame] | 3846 | final void scheduleDestroyActivities(ProcessRecord owner, String reason) { |
Dianne Hackborn | 755c8bf | 2012-05-07 15:06:09 -0700 | [diff] [blame] | 3847 | Message msg = mHandler.obtainMessage(DESTROY_ACTIVITIES_MSG); |
Craig Mautner | ee2e45a | 2014-06-27 12:10:03 -0700 | [diff] [blame] | 3848 | msg.obj = new ScheduleDestroyArgs(owner, reason); |
Dianne Hackborn | 755c8bf | 2012-05-07 15:06:09 -0700 | [diff] [blame] | 3849 | mHandler.sendMessage(msg); |
| 3850 | } |
| 3851 | |
Craig Mautner | ee2e45a | 2014-06-27 12:10:03 -0700 | [diff] [blame] | 3852 | final void destroyActivitiesLocked(ProcessRecord owner, String reason) { |
Dianne Hackborn | 755c8bf | 2012-05-07 15:06:09 -0700 | [diff] [blame] | 3853 | boolean lastIsOpaque = false; |
Dianne Hackborn | 42e620c | 2012-06-24 13:20:51 -0700 | [diff] [blame] | 3854 | boolean activityRemoved = false; |
Craig Mautner | d44711d | 2013-02-23 11:24:36 -0800 | [diff] [blame] | 3855 | for (int taskNdx = mTaskHistory.size() - 1; taskNdx >= 0; --taskNdx) { |
| 3856 | final ArrayList<ActivityRecord> activities = mTaskHistory.get(taskNdx).mActivities; |
| 3857 | for (int activityNdx = activities.size() - 1; activityNdx >= 0; --activityNdx) { |
| 3858 | final ActivityRecord r = activities.get(activityNdx); |
| 3859 | if (r.finishing) { |
| 3860 | continue; |
| 3861 | } |
| 3862 | if (r.fullscreen) { |
| 3863 | lastIsOpaque = true; |
| 3864 | } |
| 3865 | if (owner != null && r.app != owner) { |
| 3866 | continue; |
| 3867 | } |
| 3868 | if (!lastIsOpaque) { |
| 3869 | continue; |
| 3870 | } |
Dianne Hackborn | 89ad456 | 2014-08-24 16:45:38 -0700 | [diff] [blame] | 3871 | if (r.isDestroyable()) { |
Wale Ogunwale | ee006da | 2015-03-30 14:49:25 -0700 | [diff] [blame] | 3872 | 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] | 3873 | + " resumed=" + mResumedActivity |
Dianne Hackborn | 89ad456 | 2014-08-24 16:45:38 -0700 | [diff] [blame] | 3874 | + " pausing=" + mPausingActivity + " for reason " + reason); |
Craig Mautner | ee2e45a | 2014-06-27 12:10:03 -0700 | [diff] [blame] | 3875 | if (destroyActivityLocked(r, true, reason)) { |
Craig Mautner | d44711d | 2013-02-23 11:24:36 -0800 | [diff] [blame] | 3876 | activityRemoved = true; |
| 3877 | } |
Dianne Hackborn | 42e620c | 2012-06-24 13:20:51 -0700 | [diff] [blame] | 3878 | } |
Dianne Hackborn | ce86ba8 | 2011-07-13 19:33:41 -0700 | [diff] [blame] | 3879 | } |
| 3880 | } |
Dianne Hackborn | 42e620c | 2012-06-24 13:20:51 -0700 | [diff] [blame] | 3881 | if (activityRemoved) { |
Wale Ogunwale | d046a01 | 2015-12-24 13:05:59 -0800 | [diff] [blame] | 3882 | mStackSupervisor.resumeFocusedStackTopActivityLocked(); |
Dianne Hackborn | 42e620c | 2012-06-24 13:20:51 -0700 | [diff] [blame] | 3883 | } |
Dianne Hackborn | ce86ba8 | 2011-07-13 19:33:41 -0700 | [diff] [blame] | 3884 | } |
| 3885 | |
Dianne Hackborn | 89ad456 | 2014-08-24 16:45:38 -0700 | [diff] [blame] | 3886 | final boolean safelyDestroyActivityLocked(ActivityRecord r, String reason) { |
| 3887 | if (r.isDestroyable()) { |
Wale Ogunwale | ee006da | 2015-03-30 14:49:25 -0700 | [diff] [blame] | 3888 | if (DEBUG_SWITCH) Slog.v(TAG_SWITCH, |
| 3889 | "Destroying " + r + " in state " + r.state + " resumed=" + mResumedActivity |
Dianne Hackborn | 89ad456 | 2014-08-24 16:45:38 -0700 | [diff] [blame] | 3890 | + " pausing=" + mPausingActivity + " for reason " + reason); |
| 3891 | return destroyActivityLocked(r, true, reason); |
| 3892 | } |
| 3893 | return false; |
| 3894 | } |
| 3895 | |
| 3896 | final int releaseSomeActivitiesLocked(ProcessRecord app, ArraySet<TaskRecord> tasks, |
| 3897 | String reason) { |
| 3898 | // Iterate over tasks starting at the back (oldest) first. |
Wale Ogunwale | 0fc365c | 2015-05-25 19:35:42 -0700 | [diff] [blame] | 3899 | 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] | 3900 | int maxTasks = tasks.size() / 4; |
| 3901 | if (maxTasks < 1) { |
| 3902 | maxTasks = 1; |
| 3903 | } |
| 3904 | int numReleased = 0; |
| 3905 | for (int taskNdx = 0; taskNdx < mTaskHistory.size() && maxTasks > 0; taskNdx++) { |
| 3906 | final TaskRecord task = mTaskHistory.get(taskNdx); |
| 3907 | if (!tasks.contains(task)) { |
| 3908 | continue; |
| 3909 | } |
Wale Ogunwale | 0fc365c | 2015-05-25 19:35:42 -0700 | [diff] [blame] | 3910 | 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] | 3911 | int curNum = 0; |
| 3912 | final ArrayList<ActivityRecord> activities = task.mActivities; |
| 3913 | for (int actNdx = 0; actNdx < activities.size(); actNdx++) { |
| 3914 | final ActivityRecord activity = activities.get(actNdx); |
| 3915 | if (activity.app == app && activity.isDestroyable()) { |
Wale Ogunwale | 0fc365c | 2015-05-25 19:35:42 -0700 | [diff] [blame] | 3916 | if (DEBUG_RELEASE) Slog.v(TAG_RELEASE, "Destroying " + activity |
Dianne Hackborn | 89ad456 | 2014-08-24 16:45:38 -0700 | [diff] [blame] | 3917 | + " in state " + activity.state + " resumed=" + mResumedActivity |
| 3918 | + " pausing=" + mPausingActivity + " for reason " + reason); |
| 3919 | destroyActivityLocked(activity, true, reason); |
| 3920 | if (activities.get(actNdx) != activity) { |
| 3921 | // Was removed from list, back up so we don't miss the next one. |
| 3922 | actNdx--; |
| 3923 | } |
| 3924 | curNum++; |
| 3925 | } |
| 3926 | } |
| 3927 | if (curNum > 0) { |
| 3928 | numReleased += curNum; |
| 3929 | maxTasks--; |
| 3930 | if (mTaskHistory.get(taskNdx) != task) { |
| 3931 | // The entire task got removed, back up so we don't miss the next one. |
| 3932 | taskNdx--; |
| 3933 | } |
| 3934 | } |
| 3935 | } |
Wale Ogunwale | 0fc365c | 2015-05-25 19:35:42 -0700 | [diff] [blame] | 3936 | if (DEBUG_RELEASE) Slog.d(TAG_RELEASE, |
| 3937 | "Done releasing: did " + numReleased + " activities"); |
Dianne Hackborn | 89ad456 | 2014-08-24 16:45:38 -0700 | [diff] [blame] | 3938 | return numReleased; |
| 3939 | } |
| 3940 | |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 3941 | /** |
| 3942 | * Destroy the current CLIENT SIDE instance of an activity. This may be |
| 3943 | * called both when actually finishing an activity, or when performing |
| 3944 | * a configuration switch where we destroy the current client-side object |
| 3945 | * but then create a new client-side object for this same HistoryRecord. |
| 3946 | */ |
Craig Mautner | ee2e45a | 2014-06-27 12:10:03 -0700 | [diff] [blame] | 3947 | final boolean destroyActivityLocked(ActivityRecord r, boolean removeFromApp, String reason) { |
Wale Ogunwale | ee006da | 2015-03-30 14:49:25 -0700 | [diff] [blame] | 3948 | if (DEBUG_SWITCH || DEBUG_CLEANUP) Slog.v(TAG_SWITCH, |
| 3949 | "Removing activity from " + reason + ": token=" + r |
Filip Gruszczynski | a59ac9c | 2015-09-10 18:28:48 -0700 | [diff] [blame] | 3950 | + ", app=" + (r.app != null ? r.app.processName : "(null)")); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 3951 | EventLog.writeEvent(EventLogTags.AM_DESTROY_ACTIVITY, |
Dianne Hackborn | b12e135 | 2012-09-26 11:39:20 -0700 | [diff] [blame] | 3952 | r.userId, System.identityHashCode(r), |
Dianne Hackborn | 28695e0 | 2011-11-02 21:59:51 -0700 | [diff] [blame] | 3953 | r.task.taskId, r.shortComponentName, reason); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 3954 | |
| 3955 | boolean removedFromHistory = false; |
Dianne Hackborn | cc5a055 | 2012-10-01 16:32:39 -0700 | [diff] [blame] | 3956 | |
Chong Zhang | e4cf36f | 2016-06-03 14:38:33 -0700 | [diff] [blame] | 3957 | // If the activity is finishing, it's no longer considered in topRunningActivityLocked, |
| 3958 | // and cleanUpActivityLocked() may change focus to another activity (or task). |
| 3959 | // Get the current top task now, as removeActivityFromHistoryLocked() below need this |
| 3960 | // to decide whether to return to home stack after removal. |
| 3961 | final TaskRecord topTask = topTask(); |
| 3962 | |
Dianne Hackborn | ce86ba8 | 2011-07-13 19:33:41 -0700 | [diff] [blame] | 3963 | cleanUpActivityLocked(r, false, false); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 3964 | |
| 3965 | final boolean hadApp = r.app != null; |
Dianne Hackborn | cc5a055 | 2012-10-01 16:32:39 -0700 | [diff] [blame] | 3966 | |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 3967 | if (hadApp) { |
| 3968 | if (removeFromApp) { |
Craig Mautner | d232895 | 2013-03-05 12:46:26 -0800 | [diff] [blame] | 3969 | r.app.activities.remove(r); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 3970 | if (mService.mHeavyWeightProcess == r.app && r.app.activities.size() <= 0) { |
| 3971 | mService.mHeavyWeightProcess = null; |
| 3972 | mService.mHandler.sendEmptyMessage( |
| 3973 | ActivityManagerService.CANCEL_HEAVY_NOTIFICATION_MSG); |
| 3974 | } |
Craig Mautner | c8143c6 | 2013-09-03 12:15:57 -0700 | [diff] [blame] | 3975 | if (r.app.activities.isEmpty()) { |
Dianne Hackborn | 465fa39 | 2014-09-14 14:21:18 -0700 | [diff] [blame] | 3976 | // Update any services we are bound to that might care about whether |
| 3977 | // their client may have activities. |
| 3978 | mService.mServices.updateServiceConnectionActivitiesLocked(r.app); |
Dianne Hackborn | 3bc8f78d | 2013-09-19 13:34:35 -0700 | [diff] [blame] | 3979 | // No longer have activities, so update LRU list and oom adj. |
Dianne Hackborn | db92608 | 2013-10-31 16:32:44 -0700 | [diff] [blame] | 3980 | mService.updateLruProcessLocked(r.app, false, null); |
Dianne Hackborn | 2d1b378 | 2012-09-09 17:49:39 -0700 | [diff] [blame] | 3981 | mService.updateOomAdjLocked(); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 3982 | } |
| 3983 | } |
| 3984 | |
| 3985 | boolean skipDestroy = false; |
Craig Mautner | dbcb31f | 2013-04-02 12:32:53 -0700 | [diff] [blame] | 3986 | |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 3987 | try { |
Wale Ogunwale | ee006da | 2015-03-30 14:49:25 -0700 | [diff] [blame] | 3988 | if (DEBUG_SWITCH) Slog.i(TAG_SWITCH, "Destroying: " + r); |
Dianne Hackborn | be70785 | 2011-11-11 14:32:10 -0800 | [diff] [blame] | 3989 | r.app.thread.scheduleDestroyActivity(r.appToken, r.finishing, |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 3990 | r.configChangeFlags); |
| 3991 | } catch (Exception e) { |
| 3992 | // We can just ignore exceptions here... if the process |
| 3993 | // has crashed, our death notification will clean things |
| 3994 | // up. |
| 3995 | //Slog.w(TAG, "Exception thrown during finish", e); |
| 3996 | if (r.finishing) { |
Chong Zhang | e4cf36f | 2016-06-03 14:38:33 -0700 | [diff] [blame] | 3997 | removeActivityFromHistoryLocked( |
| 3998 | r, topTask, reason + " exceptionInScheduleDestroy"); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 3999 | removedFromHistory = true; |
| 4000 | skipDestroy = true; |
| 4001 | } |
| 4002 | } |
| 4003 | |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 4004 | r.nowVisible = false; |
Craig Mautner | dbcb31f | 2013-04-02 12:32:53 -0700 | [diff] [blame] | 4005 | |
Dianne Hackborn | ce86ba8 | 2011-07-13 19:33:41 -0700 | [diff] [blame] | 4006 | // If the activity is finishing, we need to wait on removing it |
| 4007 | // from the list to give it a chance to do its cleanup. During |
| 4008 | // that time it may make calls back with its token so we need to |
| 4009 | // be able to find it on the list and so we don't want to remove |
| 4010 | // it from the list yet. Otherwise, we can just immediately put |
| 4011 | // it in the destroyed state since we are not removing it from the |
| 4012 | // list. |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 4013 | if (r.finishing && !skipDestroy) { |
Wale Ogunwale | 0fc365c | 2015-05-25 19:35:42 -0700 | [diff] [blame] | 4014 | if (DEBUG_STATES) Slog.v(TAG_STATES, "Moving to DESTROYING: " + r |
Dianne Hackborn | ce86ba8 | 2011-07-13 19:33:41 -0700 | [diff] [blame] | 4015 | + " (destroy requested)"); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 4016 | r.state = ActivityState.DESTROYING; |
Craig Mautner | f7bfefb | 2013-05-16 17:30:44 -0700 | [diff] [blame] | 4017 | Message msg = mHandler.obtainMessage(DESTROY_TIMEOUT_MSG, r); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 4018 | mHandler.sendMessageDelayed(msg, DESTROY_TIMEOUT); |
| 4019 | } else { |
Wale Ogunwale | 0fc365c | 2015-05-25 19:35:42 -0700 | [diff] [blame] | 4020 | if (DEBUG_STATES) Slog.v(TAG_STATES, |
| 4021 | "Moving to DESTROYED: " + r + " (destroy skipped)"); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 4022 | r.state = ActivityState.DESTROYED; |
Wale Ogunwale | 0fc365c | 2015-05-25 19:35:42 -0700 | [diff] [blame] | 4023 | 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] | 4024 | r.app = null; |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 4025 | } |
| 4026 | } else { |
| 4027 | // remove this record from the history. |
| 4028 | if (r.finishing) { |
Chong Zhang | e4cf36f | 2016-06-03 14:38:33 -0700 | [diff] [blame] | 4029 | removeActivityFromHistoryLocked(r, topTask, reason + " hadNoApp"); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 4030 | removedFromHistory = true; |
| 4031 | } else { |
Wale Ogunwale | 0fc365c | 2015-05-25 19:35:42 -0700 | [diff] [blame] | 4032 | 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] | 4033 | r.state = ActivityState.DESTROYED; |
Wale Ogunwale | 0fc365c | 2015-05-25 19:35:42 -0700 | [diff] [blame] | 4034 | 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] | 4035 | r.app = null; |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 4036 | } |
| 4037 | } |
| 4038 | |
| 4039 | r.configChangeFlags = 0; |
Craig Mautner | dbcb31f | 2013-04-02 12:32:53 -0700 | [diff] [blame] | 4040 | |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 4041 | if (!mLRUActivities.remove(r) && hadApp) { |
| 4042 | Slog.w(TAG, "Activity " + r + " being finished, but not in LRU list"); |
| 4043 | } |
Craig Mautner | dbcb31f | 2013-04-02 12:32:53 -0700 | [diff] [blame] | 4044 | |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 4045 | return removedFromHistory; |
| 4046 | } |
| 4047 | |
Craig Mautner | 299f960 | 2015-01-26 09:47:33 -0800 | [diff] [blame] | 4048 | final void activityDestroyedLocked(IBinder token, String reason) { |
Craig Mautner | d232895 | 2013-03-05 12:46:26 -0800 | [diff] [blame] | 4049 | final long origId = Binder.clearCallingIdentity(); |
| 4050 | try { |
Wale Ogunwale | 7d70117 | 2015-03-11 15:36:30 -0700 | [diff] [blame] | 4051 | ActivityRecord r = ActivityRecord.forTokenLocked(token); |
Craig Mautner | d232895 | 2013-03-05 12:46:26 -0800 | [diff] [blame] | 4052 | if (r != null) { |
| 4053 | mHandler.removeMessages(DESTROY_TIMEOUT_MSG, r); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 4054 | } |
Wale Ogunwale | 0fc365c | 2015-05-25 19:35:42 -0700 | [diff] [blame] | 4055 | if (DEBUG_CONTAINERS) Slog.d(TAG_CONTAINERS, "activityDestroyedLocked: r=" + r); |
Craig Mautner | d232895 | 2013-03-05 12:46:26 -0800 | [diff] [blame] | 4056 | |
Wale Ogunwale | 60454db | 2015-01-23 16:05:07 -0800 | [diff] [blame] | 4057 | if (isInStackLocked(r) != null) { |
Craig Mautner | d232895 | 2013-03-05 12:46:26 -0800 | [diff] [blame] | 4058 | if (r.state == ActivityState.DESTROYING) { |
| 4059 | cleanUpActivityLocked(r, true, false); |
Chong Zhang | e4cf36f | 2016-06-03 14:38:33 -0700 | [diff] [blame] | 4060 | removeActivityFromHistoryLocked(r, null, reason); |
Craig Mautner | d232895 | 2013-03-05 12:46:26 -0800 | [diff] [blame] | 4061 | } |
| 4062 | } |
Wale Ogunwale | d046a01 | 2015-12-24 13:05:59 -0800 | [diff] [blame] | 4063 | mStackSupervisor.resumeFocusedStackTopActivityLocked(); |
Craig Mautner | d232895 | 2013-03-05 12:46:26 -0800 | [diff] [blame] | 4064 | } finally { |
| 4065 | Binder.restoreCallingIdentity(origId); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 4066 | } |
| 4067 | } |
Craig Mautner | de4ef02 | 2013-04-07 19:01:33 -0700 | [diff] [blame] | 4068 | |
Todd Kennedy | aab56db | 2015-01-30 09:39:53 -0800 | [diff] [blame] | 4069 | void releaseBackgroundResources(ActivityRecord r) { |
Jose Lima | 4b6c669 | 2014-08-12 17:41:12 -0700 | [diff] [blame] | 4070 | if (hasVisibleBehindActivity() && |
| 4071 | !mHandler.hasMessages(RELEASE_BACKGROUND_RESOURCES_TIMEOUT_MSG)) { |
Wale Ogunwale | 8051c5c | 2016-03-04 10:27:32 -0800 | [diff] [blame] | 4072 | if (r == topRunningActivityLocked() |
| 4073 | && getStackVisibilityLocked(null) == STACK_VISIBLE) { |
Craig Mautner | 64ccb70 | 2014-10-01 09:38:40 -0700 | [diff] [blame] | 4074 | // 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] | 4075 | // activity and the stack is currently visible. |
Craig Mautner | 64ccb70 | 2014-10-01 09:38:40 -0700 | [diff] [blame] | 4076 | return; |
| 4077 | } |
Wale Ogunwale | 0fc365c | 2015-05-25 19:35:42 -0700 | [diff] [blame] | 4078 | if (DEBUG_STATES) Slog.d(TAG_STATES, "releaseBackgroundResources activtyDisplay=" + |
Jose Lima | 4b6c669 | 2014-08-12 17:41:12 -0700 | [diff] [blame] | 4079 | mActivityContainer.mActivityDisplay + " visibleBehind=" + r + " app=" + r.app + |
Craig Mautner | ee2e45a | 2014-06-27 12:10:03 -0700 | [diff] [blame] | 4080 | " thread=" + r.app.thread); |
| 4081 | if (r != null && r.app != null && r.app.thread != null) { |
| 4082 | try { |
Jose Lima | 4b6c669 | 2014-08-12 17:41:12 -0700 | [diff] [blame] | 4083 | r.app.thread.scheduleCancelVisibleBehind(r.appToken); |
Craig Mautner | ee2e45a | 2014-06-27 12:10:03 -0700 | [diff] [blame] | 4084 | } catch (RemoteException e) { |
| 4085 | } |
Jose Lima | 4b6c669 | 2014-08-12 17:41:12 -0700 | [diff] [blame] | 4086 | mHandler.sendEmptyMessageDelayed(RELEASE_BACKGROUND_RESOURCES_TIMEOUT_MSG, 500); |
Craig Mautner | ee2e45a | 2014-06-27 12:10:03 -0700 | [diff] [blame] | 4087 | } else { |
Jose Lima | 4b6c669 | 2014-08-12 17:41:12 -0700 | [diff] [blame] | 4088 | Slog.e(TAG, "releaseBackgroundResources: activity " + r + " no longer running"); |
Wale Ogunwale | 1f4c02b | 2014-11-13 14:22:32 -0800 | [diff] [blame] | 4089 | backgroundResourcesReleased(); |
Craig Mautner | ee2e45a | 2014-06-27 12:10:03 -0700 | [diff] [blame] | 4090 | } |
| 4091 | } |
| 4092 | } |
| 4093 | |
Wale Ogunwale | 1f4c02b | 2014-11-13 14:22:32 -0800 | [diff] [blame] | 4094 | final void backgroundResourcesReleased() { |
Jose Lima | 4b6c669 | 2014-08-12 17:41:12 -0700 | [diff] [blame] | 4095 | mHandler.removeMessages(RELEASE_BACKGROUND_RESOURCES_TIMEOUT_MSG); |
| 4096 | final ActivityRecord r = getVisibleBehindActivity(); |
Craig Mautner | ee2e45a | 2014-06-27 12:10:03 -0700 | [diff] [blame] | 4097 | if (r != null) { |
| 4098 | mStackSupervisor.mStoppingActivities.add(r); |
Jose Lima | 4b6c669 | 2014-08-12 17:41:12 -0700 | [diff] [blame] | 4099 | setVisibleBehindActivity(null); |
Wale Ogunwale | 1f4c02b | 2014-11-13 14:22:32 -0800 | [diff] [blame] | 4100 | mStackSupervisor.scheduleIdleTimeoutLocked(null); |
Craig Mautner | ee2e45a | 2014-06-27 12:10:03 -0700 | [diff] [blame] | 4101 | } |
Wale Ogunwale | d046a01 | 2015-12-24 13:05:59 -0800 | [diff] [blame] | 4102 | mStackSupervisor.resumeFocusedStackTopActivityLocked(); |
Craig Mautner | ee2e45a | 2014-06-27 12:10:03 -0700 | [diff] [blame] | 4103 | } |
| 4104 | |
Jose Lima | 4b6c669 | 2014-08-12 17:41:12 -0700 | [diff] [blame] | 4105 | boolean hasVisibleBehindActivity() { |
| 4106 | return isAttached() && mActivityContainer.mActivityDisplay.hasVisibleBehindActivity(); |
Craig Mautner | ee2e45a | 2014-06-27 12:10:03 -0700 | [diff] [blame] | 4107 | } |
| 4108 | |
Jose Lima | 4b6c669 | 2014-08-12 17:41:12 -0700 | [diff] [blame] | 4109 | void setVisibleBehindActivity(ActivityRecord r) { |
Craig Mautner | ee2e45a | 2014-06-27 12:10:03 -0700 | [diff] [blame] | 4110 | if (isAttached()) { |
Jose Lima | 4b6c669 | 2014-08-12 17:41:12 -0700 | [diff] [blame] | 4111 | mActivityContainer.mActivityDisplay.setVisibleBehindActivity(r); |
Craig Mautner | ee2e45a | 2014-06-27 12:10:03 -0700 | [diff] [blame] | 4112 | } |
| 4113 | } |
| 4114 | |
Jose Lima | 4b6c669 | 2014-08-12 17:41:12 -0700 | [diff] [blame] | 4115 | ActivityRecord getVisibleBehindActivity() { |
| 4116 | return isAttached() ? mActivityContainer.mActivityDisplay.mVisibleBehindActivity : null; |
Craig Mautner | ee2e45a | 2014-06-27 12:10:03 -0700 | [diff] [blame] | 4117 | } |
| 4118 | |
Craig Mautner | 05d6272ba | 2013-02-11 09:39:27 -0800 | [diff] [blame] | 4119 | private void removeHistoryRecordsForAppLocked(ArrayList<ActivityRecord> list, |
| 4120 | ProcessRecord app, String listName) { |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 4121 | int i = list.size(); |
Wale Ogunwale | e23149f | 2015-03-06 15:39:44 -0800 | [diff] [blame] | 4122 | if (DEBUG_CLEANUP) Slog.v(TAG_CLEANUP, |
| 4123 | "Removing app " + app + " from list " + listName + " with " + i + " entries"); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 4124 | while (i > 0) { |
| 4125 | i--; |
Craig Mautner | 05d6272ba | 2013-02-11 09:39:27 -0800 | [diff] [blame] | 4126 | ActivityRecord r = list.get(i); |
Wale Ogunwale | e23149f | 2015-03-06 15:39:44 -0800 | [diff] [blame] | 4127 | if (DEBUG_CLEANUP) Slog.v(TAG_CLEANUP, "Record #" + i + " " + r); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 4128 | if (r.app == app) { |
Wale Ogunwale | e23149f | 2015-03-06 15:39:44 -0800 | [diff] [blame] | 4129 | if (DEBUG_CLEANUP) Slog.v(TAG_CLEANUP, "---> REMOVING this entry!"); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 4130 | list.remove(i); |
Dianne Hackborn | 42e620c | 2012-06-24 13:20:51 -0700 | [diff] [blame] | 4131 | removeTimeoutsForActivityLocked(r); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 4132 | } |
| 4133 | } |
| 4134 | } |
| 4135 | |
Dianne Hackborn | cc5a055 | 2012-10-01 16:32:39 -0700 | [diff] [blame] | 4136 | boolean removeHistoryRecordsForAppLocked(ProcessRecord app) { |
| 4137 | removeHistoryRecordsForAppLocked(mLRUActivities, app, "mLRUActivities"); |
Craig Mautner | de4ef02 | 2013-04-07 19:01:33 -0700 | [diff] [blame] | 4138 | removeHistoryRecordsForAppLocked(mStackSupervisor.mStoppingActivities, app, |
| 4139 | "mStoppingActivities"); |
Craig Mautner | 0eea92c | 2013-05-16 13:35:39 -0700 | [diff] [blame] | 4140 | removeHistoryRecordsForAppLocked(mStackSupervisor.mGoingToSleepActivities, app, |
| 4141 | "mGoingToSleepActivities"); |
Craig Mautner | de4ef02 | 2013-04-07 19:01:33 -0700 | [diff] [blame] | 4142 | removeHistoryRecordsForAppLocked(mStackSupervisor.mWaitingVisibleActivities, app, |
Dianne Hackborn | cc5a055 | 2012-10-01 16:32:39 -0700 | [diff] [blame] | 4143 | "mWaitingVisibleActivities"); |
Craig Mautner | f333327 | 2013-04-22 10:55:53 -0700 | [diff] [blame] | 4144 | removeHistoryRecordsForAppLocked(mStackSupervisor.mFinishingActivities, app, |
| 4145 | "mFinishingActivities"); |
Dianne Hackborn | cc5a055 | 2012-10-01 16:32:39 -0700 | [diff] [blame] | 4146 | |
| 4147 | boolean hasVisibleActivities = false; |
| 4148 | |
| 4149 | // Clean out the history list. |
Craig Mautner | 0247fc8 | 2013-02-28 14:32:06 -0800 | [diff] [blame] | 4150 | int i = numActivities(); |
Wale Ogunwale | e23149f | 2015-03-06 15:39:44 -0800 | [diff] [blame] | 4151 | if (DEBUG_CLEANUP) Slog.v(TAG_CLEANUP, |
| 4152 | "Removing app " + app + " from history with " + i + " entries"); |
Craig Mautner | 0247fc8 | 2013-02-28 14:32:06 -0800 | [diff] [blame] | 4153 | for (int taskNdx = mTaskHistory.size() - 1; taskNdx >= 0; --taskNdx) { |
| 4154 | final ArrayList<ActivityRecord> activities = mTaskHistory.get(taskNdx).mActivities; |
| 4155 | for (int activityNdx = activities.size() - 1; activityNdx >= 0; --activityNdx) { |
| 4156 | final ActivityRecord r = activities.get(activityNdx); |
| 4157 | --i; |
Wale Ogunwale | e23149f | 2015-03-06 15:39:44 -0800 | [diff] [blame] | 4158 | if (DEBUG_CLEANUP) Slog.v(TAG_CLEANUP, |
| 4159 | "Record #" + i + " " + r + ": app=" + r.app); |
Craig Mautner | 0247fc8 | 2013-02-28 14:32:06 -0800 | [diff] [blame] | 4160 | if (r.app == app) { |
riddle_hsu | 558e849 | 2015-04-02 16:43:13 +0800 | [diff] [blame] | 4161 | if (r.visible) { |
| 4162 | hasVisibleActivities = true; |
| 4163 | } |
Craig Mautner | acebdc8 | 2015-02-24 10:53:03 -0800 | [diff] [blame] | 4164 | final boolean remove; |
Craig Mautner | 0247fc8 | 2013-02-28 14:32:06 -0800 | [diff] [blame] | 4165 | if ((!r.haveState && !r.stateNotNeeded) || r.finishing) { |
| 4166 | // Don't currently have state for the activity, or |
| 4167 | // it is finishing -- always remove it. |
| 4168 | remove = true; |
Chong Zhang | 112eb8c | 2015-11-02 11:17:00 -0800 | [diff] [blame] | 4169 | } else if (!r.visible && r.launchCount > 2 && |
| 4170 | r.lastLaunchTime > (SystemClock.uptimeMillis() - 60000)) { |
Craig Mautner | 0247fc8 | 2013-02-28 14:32:06 -0800 | [diff] [blame] | 4171 | // We have launched this activity too many times since it was |
| 4172 | // able to run, so give up and remove it. |
Chong Zhang | 112eb8c | 2015-11-02 11:17:00 -0800 | [diff] [blame] | 4173 | // (Note if the activity is visible, we don't remove the record. |
| 4174 | // We leave the dead window on the screen but the process will |
| 4175 | // not be restarted unless user explicitly tap on it.) |
Craig Mautner | 0247fc8 | 2013-02-28 14:32:06 -0800 | [diff] [blame] | 4176 | remove = true; |
| 4177 | } else { |
| 4178 | // The process may be gone, but the activity lives on! |
| 4179 | remove = false; |
Dianne Hackborn | cc5a055 | 2012-10-01 16:32:39 -0700 | [diff] [blame] | 4180 | } |
Craig Mautner | 0247fc8 | 2013-02-28 14:32:06 -0800 | [diff] [blame] | 4181 | if (remove) { |
Wale Ogunwale | 0fc365c | 2015-05-25 19:35:42 -0700 | [diff] [blame] | 4182 | if (DEBUG_ADD_REMOVE || DEBUG_CLEANUP) Slog.i(TAG_ADD_REMOVE, |
| 4183 | "Removing activity " + r + " from stack at " + i |
| 4184 | + ": haveState=" + r.haveState |
| 4185 | + " stateNotNeeded=" + r.stateNotNeeded |
| 4186 | + " finishing=" + r.finishing |
| 4187 | + " state=" + r.state + " callers=" + Debug.getCallers(5)); |
Craig Mautner | 0247fc8 | 2013-02-28 14:32:06 -0800 | [diff] [blame] | 4188 | if (!r.finishing) { |
| 4189 | Slog.w(TAG, "Force removing " + r + ": app died, no saved state"); |
| 4190 | EventLog.writeEvent(EventLogTags.AM_FINISH_ACTIVITY, |
| 4191 | r.userId, System.identityHashCode(r), |
| 4192 | r.task.taskId, r.shortComponentName, |
| 4193 | "proc died without state saved"); |
Jeff Sharkey | 5782da7 | 2013-04-25 14:32:30 -0700 | [diff] [blame] | 4194 | if (r.state == ActivityState.RESUMED) { |
| 4195 | mService.updateUsageStats(r, false); |
| 4196 | } |
Craig Mautner | 0247fc8 | 2013-02-28 14:32:06 -0800 | [diff] [blame] | 4197 | } |
Craig Mautner | 0247fc8 | 2013-02-28 14:32:06 -0800 | [diff] [blame] | 4198 | } else { |
| 4199 | // We have the current state for this activity, so |
| 4200 | // it can be restarted later when needed. |
Wale Ogunwale | 0fc365c | 2015-05-25 19:35:42 -0700 | [diff] [blame] | 4201 | if (DEBUG_ALL) Slog.v(TAG, "Keeping entry, setting app to null"); |
| 4202 | if (DEBUG_APP) Slog.v(TAG_APP, |
| 4203 | "Clearing app during removeHistory for activity " + r); |
Craig Mautner | 0247fc8 | 2013-02-28 14:32:06 -0800 | [diff] [blame] | 4204 | r.app = null; |
Chong Zhang | 112eb8c | 2015-11-02 11:17:00 -0800 | [diff] [blame] | 4205 | // Set nowVisible to previous visible state. If the app was visible while |
| 4206 | // it died, we leave the dead window on screen so it's basically visible. |
| 4207 | // This is needed when user later tap on the dead window, we need to stop |
| 4208 | // other apps when user transfers focus to the restarted activity. |
| 4209 | r.nowVisible = r.visible; |
Craig Mautner | 0247fc8 | 2013-02-28 14:32:06 -0800 | [diff] [blame] | 4210 | if (!r.haveState) { |
Wale Ogunwale | 0fc365c | 2015-05-25 19:35:42 -0700 | [diff] [blame] | 4211 | if (DEBUG_SAVED_STATE) Slog.i(TAG_SAVED_STATE, |
Craig Mautner | 0247fc8 | 2013-02-28 14:32:06 -0800 | [diff] [blame] | 4212 | "App died, clearing saved state of " + r); |
| 4213 | r.icicle = null; |
| 4214 | } |
Dianne Hackborn | cc5a055 | 2012-10-01 16:32:39 -0700 | [diff] [blame] | 4215 | } |
Craig Mautner | d232895 | 2013-03-05 12:46:26 -0800 | [diff] [blame] | 4216 | cleanUpActivityLocked(r, true, true); |
Craig Mautner | acebdc8 | 2015-02-24 10:53:03 -0800 | [diff] [blame] | 4217 | if (remove) { |
Chong Zhang | e4cf36f | 2016-06-03 14:38:33 -0700 | [diff] [blame] | 4218 | removeActivityFromHistoryLocked(r, null, "appDied"); |
Craig Mautner | acebdc8 | 2015-02-24 10:53:03 -0800 | [diff] [blame] | 4219 | } |
Craig Mautner | 0247fc8 | 2013-02-28 14:32:06 -0800 | [diff] [blame] | 4220 | } |
Dianne Hackborn | cc5a055 | 2012-10-01 16:32:39 -0700 | [diff] [blame] | 4221 | } |
| 4222 | } |
| 4223 | |
| 4224 | return hasVisibleActivities; |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 4225 | } |
Craig Mautner | 0247fc8 | 2013-02-28 14:32:06 -0800 | [diff] [blame] | 4226 | |
Chong Zhang | 280d332 | 2015-11-03 17:27:26 -0800 | [diff] [blame] | 4227 | final void updateTransitLocked(int transit, ActivityOptions options) { |
Dianne Hackborn | 7f58b95 | 2012-04-18 12:59:29 -0700 | [diff] [blame] | 4228 | if (options != null) { |
Filip Gruszczynski | 3e85ba2 | 2015-10-05 22:48:30 -0700 | [diff] [blame] | 4229 | ActivityRecord r = topRunningActivityLocked(); |
Dianne Hackborn | 7f58b95 | 2012-04-18 12:59:29 -0700 | [diff] [blame] | 4230 | if (r != null && r.state != ActivityState.RESUMED) { |
| 4231 | r.updateOptionsLocked(options); |
| 4232 | } else { |
| 4233 | ActivityOptions.abort(options); |
| 4234 | } |
| 4235 | } |
Craig Mautner | ce5f3cb | 2013-04-22 08:58:54 -0700 | [diff] [blame] | 4236 | mWindowManager.prepareAppTransition(transit, false); |
Dianne Hackborn | 7f58b95 | 2012-04-18 12:59:29 -0700 | [diff] [blame] | 4237 | } |
Dianne Hackborn | 621e17d | 2010-11-22 15:59:56 -0800 | [diff] [blame] | 4238 | |
Craig Mautner | 21d24a2 | 2014-04-23 11:45:37 -0700 | [diff] [blame] | 4239 | void updateTaskMovement(TaskRecord task, boolean toFront) { |
| 4240 | if (task.isPersistable) { |
| 4241 | task.mLastTimeMoved = System.currentTimeMillis(); |
| 4242 | // Sign is used to keep tasks sorted when persisted. Tasks sent to the bottom most |
| 4243 | // recently will be most negative, tasks sent to the bottom before that will be less |
| 4244 | // negative. Similarly for recent tasks moved to the top which will be most positive. |
| 4245 | if (!toFront) { |
| 4246 | task.mLastTimeMoved *= -1; |
| 4247 | } |
| 4248 | } |
Chong Zhang | fdcc4d4 | 2015-10-14 16:50:12 -0700 | [diff] [blame] | 4249 | mStackSupervisor.invalidateTaskLayers(); |
Craig Mautner | 21d24a2 | 2014-04-23 11:45:37 -0700 | [diff] [blame] | 4250 | } |
| 4251 | |
Craig Mautner | 84984fa | 2014-06-19 11:19:20 -0700 | [diff] [blame] | 4252 | void moveHomeStackTaskToTop(int homeStackTaskType) { |
Craig Mautner | a82aa09 | 2013-09-13 15:34:08 -0700 | [diff] [blame] | 4253 | final int top = mTaskHistory.size() - 1; |
| 4254 | for (int taskNdx = top; taskNdx >= 0; --taskNdx) { |
| 4255 | final TaskRecord task = mTaskHistory.get(taskNdx); |
Craig Mautner | 84984fa | 2014-06-19 11:19:20 -0700 | [diff] [blame] | 4256 | if (task.taskType == homeStackTaskType) { |
Wale Ogunwale | ee006da | 2015-03-30 14:49:25 -0700 | [diff] [blame] | 4257 | if (DEBUG_TASKS || DEBUG_STACK) Slog.d(TAG_STACK, |
| 4258 | "moveHomeStackTaskToTop: moving " + task); |
Craig Mautner | a82aa09 | 2013-09-13 15:34:08 -0700 | [diff] [blame] | 4259 | mTaskHistory.remove(taskNdx); |
| 4260 | mTaskHistory.add(top, task); |
Craig Mautner | 21d24a2 | 2014-04-23 11:45:37 -0700 | [diff] [blame] | 4261 | updateTaskMovement(task, true); |
Craig Mautner | a82aa09 | 2013-09-13 15:34:08 -0700 | [diff] [blame] | 4262 | return; |
| 4263 | } |
| 4264 | } |
| 4265 | } |
| 4266 | |
Chong Zhang | 280d332 | 2015-11-03 17:27:26 -0800 | [diff] [blame] | 4267 | final void moveTaskToFrontLocked(TaskRecord tr, boolean noAnimation, ActivityOptions options, |
Dianne Hackborn | b5a380d | 2015-05-20 18:18:46 -0700 | [diff] [blame] | 4268 | AppTimeTracker timeTracker, String reason) { |
Wale Ogunwale | ee006da | 2015-03-30 14:49:25 -0700 | [diff] [blame] | 4269 | if (DEBUG_SWITCH) Slog.v(TAG_SWITCH, "moveTaskToFront: " + tr); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 4270 | |
Craig Mautner | 11bf9a5 | 2013-02-19 14:08:51 -0800 | [diff] [blame] | 4271 | final int numTasks = mTaskHistory.size(); |
| 4272 | final int index = mTaskHistory.indexOf(tr); |
Craig Mautner | 86d67a4 | 2013-05-14 10:34:38 -0700 | [diff] [blame] | 4273 | if (numTasks == 0 || index < 0) { |
Craig Mautner | 11bf9a5 | 2013-02-19 14:08:51 -0800 | [diff] [blame] | 4274 | // nothing to do! |
Craig Mautner | 8f5f7e9 | 2015-01-26 18:03:13 -0800 | [diff] [blame] | 4275 | if (noAnimation) { |
Craig Mautner | 11bf9a5 | 2013-02-19 14:08:51 -0800 | [diff] [blame] | 4276 | ActivityOptions.abort(options); |
| 4277 | } else { |
Jorim Jaggi | af80db4 | 2016-04-07 19:19:15 -0700 | [diff] [blame] | 4278 | updateTransitLocked(TRANSIT_TASK_TO_FRONT, options); |
Craig Mautner | 11bf9a5 | 2013-02-19 14:08:51 -0800 | [diff] [blame] | 4279 | } |
| 4280 | return; |
| 4281 | } |
| 4282 | |
Dianne Hackborn | b5a380d | 2015-05-20 18:18:46 -0700 | [diff] [blame] | 4283 | if (timeTracker != null) { |
| 4284 | // The caller wants a time tracker associated with this task. |
| 4285 | for (int i = tr.mActivities.size() - 1; i >= 0; i--) { |
| 4286 | tr.mActivities.get(i).appTimeTracker = timeTracker; |
| 4287 | } |
| 4288 | } |
| 4289 | |
Craig Mautner | 11bf9a5 | 2013-02-19 14:08:51 -0800 | [diff] [blame] | 4290 | // Shift all activities with this task up to the top |
| 4291 | // of the stack, keeping them in the same internal order. |
Wale Ogunwale | 3fcb4a8 | 2015-04-06 14:00:13 -0700 | [diff] [blame] | 4292 | insertTaskAtTop(tr, null); |
Wale Ogunwale | d80c263 | 2015-03-13 10:26:26 -0700 | [diff] [blame] | 4293 | |
Chong Zhang | 45c25ce | 2015-08-10 22:18:26 -0700 | [diff] [blame] | 4294 | // Don't refocus if invisible to current user |
| 4295 | ActivityRecord top = tr.getTopActivity(); |
| 4296 | if (!okToShowLocked(top)) { |
| 4297 | addRecentActivityLocked(top); |
| 4298 | ActivityOptions.abort(options); |
| 4299 | return; |
| 4300 | } |
| 4301 | |
Wale Ogunwale | d80c263 | 2015-03-13 10:26:26 -0700 | [diff] [blame] | 4302 | // Set focus to the top running activity of this stack. |
Filip Gruszczynski | 3e85ba2 | 2015-10-05 22:48:30 -0700 | [diff] [blame] | 4303 | ActivityRecord r = topRunningActivityLocked(); |
Chong Zhang | 6cda19c | 2016-06-14 19:07:56 -0700 | [diff] [blame] | 4304 | mStackSupervisor.moveFocusableActivityStackToFrontLocked(r, reason); |
Craig Mautner | 11bf9a5 | 2013-02-19 14:08:51 -0800 | [diff] [blame] | 4305 | |
Wale Ogunwale | ee006da | 2015-03-30 14:49:25 -0700 | [diff] [blame] | 4306 | 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] | 4307 | if (noAnimation) { |
Jorim Jaggi | af80db4 | 2016-04-07 19:19:15 -0700 | [diff] [blame] | 4308 | mWindowManager.prepareAppTransition(TRANSIT_NONE, false); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 4309 | if (r != null) { |
| 4310 | mNoAnimActivities.add(r); |
| 4311 | } |
Dianne Hackborn | 8078d8c | 2012-03-20 11:11:26 -0700 | [diff] [blame] | 4312 | ActivityOptions.abort(options); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 4313 | } else { |
Jorim Jaggi | af80db4 | 2016-04-07 19:19:15 -0700 | [diff] [blame] | 4314 | updateTransitLocked(TRANSIT_TASK_TO_FRONT, options); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 4315 | } |
Craig Mautner | 30e2d72 | 2013-02-12 11:30:16 -0800 | [diff] [blame] | 4316 | |
Wale Ogunwale | d046a01 | 2015-12-24 13:05:59 -0800 | [diff] [blame] | 4317 | mStackSupervisor.resumeFocusedStackTopActivityLocked(); |
Craig Mautner | 5854780 | 2013-03-05 08:23:53 -0800 | [diff] [blame] | 4318 | EventLog.writeEvent(EventLogTags.AM_TASK_TO_FRONT, tr.userId, tr.taskId); |
Craig Mautner | 11bf9a5 | 2013-02-19 14:08:51 -0800 | [diff] [blame] | 4319 | |
| 4320 | if (VALIDATE_TOKENS) { |
| 4321 | validateAppTokensLocked(); |
| 4322 | } |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 4323 | } |
| 4324 | |
| 4325 | /** |
Craig Mautner | ce5f3cb | 2013-04-22 08:58:54 -0700 | [diff] [blame] | 4326 | * Worker method for rearranging history stack. Implements the function of moving all |
| 4327 | * 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] | 4328 | * bottom of the stack. |
Craig Mautner | ce5f3cb | 2013-04-22 08:58:54 -0700 | [diff] [blame] | 4329 | * |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 4330 | * If a watcher is installed, the action is preflighted and the watcher has an opportunity |
| 4331 | * to premeptively cancel the move. |
Craig Mautner | ce5f3cb | 2013-04-22 08:58:54 -0700 | [diff] [blame] | 4332 | * |
Craig Mautner | ae7ecab | 2013-09-18 11:48:14 -0700 | [diff] [blame] | 4333 | * @param taskId The taskId to collect and move to the bottom. |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 4334 | * @return Returns true if the move completed, false if not. |
| 4335 | */ |
Craig Mautner | 299f960 | 2015-01-26 09:47:33 -0800 | [diff] [blame] | 4336 | final boolean moveTaskToBackLocked(int taskId) { |
Craig Mautner | aea74a5 | 2014-03-08 14:23:10 -0800 | [diff] [blame] | 4337 | final TaskRecord tr = taskForIdLocked(taskId); |
| 4338 | if (tr == null) { |
| 4339 | Slog.i(TAG, "moveTaskToBack: bad taskId=" + taskId); |
| 4340 | return false; |
| 4341 | } |
| 4342 | |
| 4343 | Slog.i(TAG, "moveTaskToBack: " + tr); |
Craig Mautner | 15df08a | 2015-04-01 12:17:18 -0700 | [diff] [blame] | 4344 | mStackSupervisor.removeLockedTaskLocked(tr); |
Craig Mautner | b44de0d | 2013-02-21 20:00:58 -0800 | [diff] [blame] | 4345 | |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 4346 | // If we have a watcher, preflight the move before committing to it. First check |
| 4347 | // for *other* available tasks, but if none are available, then try again allowing the |
| 4348 | // current task to be selected. |
Craig Mautner | de4ef02 | 2013-04-07 19:01:33 -0700 | [diff] [blame] | 4349 | if (mStackSupervisor.isFrontStack(this) && mService.mController != null) { |
Craig Mautner | ae7ecab | 2013-09-18 11:48:14 -0700 | [diff] [blame] | 4350 | ActivityRecord next = topRunningActivityLocked(null, taskId); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 4351 | if (next == null) { |
| 4352 | next = topRunningActivityLocked(null, 0); |
| 4353 | } |
| 4354 | if (next != null) { |
| 4355 | // ask watcher if this is allowed |
| 4356 | boolean moveOK = true; |
| 4357 | try { |
| 4358 | moveOK = mService.mController.activityResuming(next.packageName); |
| 4359 | } catch (RemoteException e) { |
| 4360 | mService.mController = null; |
Kenny Root | add5821 | 2013-05-07 09:47:34 -0700 | [diff] [blame] | 4361 | Watchdog.getInstance().setActivityController(null); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 4362 | } |
| 4363 | if (!moveOK) { |
| 4364 | return false; |
| 4365 | } |
| 4366 | } |
| 4367 | } |
| 4368 | |
Wale Ogunwale | ee006da | 2015-03-30 14:49:25 -0700 | [diff] [blame] | 4369 | 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] | 4370 | |
Wale Ogunwale | 285ccef | 2015-12-11 14:56:37 -0800 | [diff] [blame] | 4371 | if (mStackId == HOME_STACK_ID && topTask().isHomeTask()) { |
| 4372 | // For the case where we are moving the home task back and there is an activity visible |
| 4373 | // behind it on the fullscreen stack, we want to move the focus to the visible behind |
| 4374 | // activity to maintain order with what the user is seeing. |
| 4375 | final ActivityStack fullscreenStack = |
| 4376 | mStackSupervisor.getStack(FULLSCREEN_WORKSPACE_STACK_ID); |
| 4377 | if (fullscreenStack != null && fullscreenStack.hasVisibleBehindActivity()) { |
| 4378 | final ActivityRecord visibleBehind = fullscreenStack.getVisibleBehindActivity(); |
Chong Zhang | 6cda19c | 2016-06-14 19:07:56 -0700 | [diff] [blame] | 4379 | mStackSupervisor.moveFocusableActivityStackToFrontLocked(visibleBehind, "moveTaskToBack"); |
Wale Ogunwale | d046a01 | 2015-12-24 13:05:59 -0800 | [diff] [blame] | 4380 | mStackSupervisor.resumeFocusedStackTopActivityLocked(); |
Wale Ogunwale | 285ccef | 2015-12-11 14:56:37 -0800 | [diff] [blame] | 4381 | return true; |
| 4382 | } |
| 4383 | } |
| 4384 | |
riddle_hsu | c215a4f | 2014-12-27 12:10:45 +0800 | [diff] [blame] | 4385 | boolean prevIsHome = false; |
Wale Ogunwale | 4270924 | 2015-08-11 13:54:42 -0700 | [diff] [blame] | 4386 | |
| 4387 | // If true, we should resume the home activity next if the task we are moving to the |
| 4388 | // back is over the home stack. We force to false if the task we are moving to back |
| 4389 | // is the home task and we don't want it resumed after moving to the back. |
| 4390 | final boolean canGoHome = !tr.isHomeTask() && tr.isOverHomeStack(); |
| 4391 | if (canGoHome) { |
riddle_hsu | c215a4f | 2014-12-27 12:10:45 +0800 | [diff] [blame] | 4392 | final TaskRecord nextTask = getNextTask(tr); |
| 4393 | if (nextTask != null) { |
| 4394 | nextTask.setTaskToReturnTo(tr.getTaskToReturnTo()); |
| 4395 | } else { |
| 4396 | prevIsHome = true; |
| 4397 | } |
| 4398 | } |
Craig Mautner | 11bf9a5 | 2013-02-19 14:08:51 -0800 | [diff] [blame] | 4399 | mTaskHistory.remove(tr); |
| 4400 | mTaskHistory.add(0, tr); |
Craig Mautner | 21d24a2 | 2014-04-23 11:45:37 -0700 | [diff] [blame] | 4401 | updateTaskMovement(tr, false); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 4402 | |
Craig Mautner | c8143c6 | 2013-09-03 12:15:57 -0700 | [diff] [blame] | 4403 | // There is an assumption that moving a task to the back moves it behind the home activity. |
| 4404 | // 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] | 4405 | int numTasks = mTaskHistory.size(); |
Craig Mautner | ae7ecab | 2013-09-18 11:48:14 -0700 | [diff] [blame] | 4406 | for (int taskNdx = numTasks - 1; taskNdx >= 1; --taskNdx) { |
| 4407 | final TaskRecord task = mTaskHistory.get(taskNdx); |
Craig Mautner | 84984fa | 2014-06-19 11:19:20 -0700 | [diff] [blame] | 4408 | if (task.isOverHomeStack()) { |
Craig Mautner | c8143c6 | 2013-09-03 12:15:57 -0700 | [diff] [blame] | 4409 | break; |
| 4410 | } |
Craig Mautner | ae7ecab | 2013-09-18 11:48:14 -0700 | [diff] [blame] | 4411 | if (taskNdx == 1) { |
| 4412 | // Set the last task before tr to go to home. |
Craig Mautner | 84984fa | 2014-06-19 11:19:20 -0700 | [diff] [blame] | 4413 | task.setTaskToReturnTo(HOME_ACTIVITY_TYPE); |
Craig Mautner | ae7ecab | 2013-09-18 11:48:14 -0700 | [diff] [blame] | 4414 | } |
Craig Mautner | c8143c6 | 2013-09-03 12:15:57 -0700 | [diff] [blame] | 4415 | } |
| 4416 | |
Jorim Jaggi | af80db4 | 2016-04-07 19:19:15 -0700 | [diff] [blame] | 4417 | mWindowManager.prepareAppTransition(TRANSIT_TASK_TO_BACK, false); |
Craig Mautner | ae7ecab | 2013-09-18 11:48:14 -0700 | [diff] [blame] | 4418 | mWindowManager.moveTaskToBottom(taskId); |
Craig Mautner | b44de0d | 2013-02-21 20:00:58 -0800 | [diff] [blame] | 4419 | |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 4420 | if (VALIDATE_TOKENS) { |
Dianne Hackborn | be70785 | 2011-11-11 14:32:10 -0800 | [diff] [blame] | 4421 | validateAppTokensLocked(); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 4422 | } |
| 4423 | |
Craig Mautner | ae7ecab | 2013-09-18 11:48:14 -0700 | [diff] [blame] | 4424 | final TaskRecord task = mResumedActivity != null ? mResumedActivity.task : null; |
Wale Ogunwale | 4270924 | 2015-08-11 13:54:42 -0700 | [diff] [blame] | 4425 | if (prevIsHome || (task == tr && canGoHome) || (numTasks <= 1 && isOnHomeDisplay())) { |
Dianne Hackborn | 7622a0f | 2014-09-30 14:31:42 -0700 | [diff] [blame] | 4426 | if (!mService.mBooting && !mService.mBooted) { |
| 4427 | // Not ready yet! |
| 4428 | return false; |
| 4429 | } |
Craig Mautner | 84984fa | 2014-06-19 11:19:20 -0700 | [diff] [blame] | 4430 | final int taskToReturnTo = tr.getTaskToReturnTo(); |
| 4431 | tr.setTaskToReturnTo(APPLICATION_ACTIVITY_TYPE); |
Craig Mautner | 299f960 | 2015-01-26 09:47:33 -0800 | [diff] [blame] | 4432 | return mStackSupervisor.resumeHomeStackTask(taskToReturnTo, null, "moveTaskToBack"); |
Craig Mautner | de4ef02 | 2013-04-07 19:01:33 -0700 | [diff] [blame] | 4433 | } |
| 4434 | |
Wale Ogunwale | d046a01 | 2015-12-24 13:05:59 -0800 | [diff] [blame] | 4435 | mStackSupervisor.resumeFocusedStackTopActivityLocked(); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 4436 | return true; |
| 4437 | } |
Dianne Hackborn | 15491c6 | 2012-09-19 10:59:14 -0700 | [diff] [blame] | 4438 | |
Craig Mautner | 8849a5e | 2013-04-02 16:41:03 -0700 | [diff] [blame] | 4439 | static final void logStartActivity(int tag, ActivityRecord r, |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 4440 | TaskRecord task) { |
Santos Cordon | 73ff7d8 | 2013-03-06 17:24:11 -0800 | [diff] [blame] | 4441 | final Uri data = r.intent.getData(); |
| 4442 | final String strData = data != null ? data.toSafeString() : null; |
| 4443 | |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 4444 | EventLog.writeEvent(tag, |
Dianne Hackborn | b12e135 | 2012-09-26 11:39:20 -0700 | [diff] [blame] | 4445 | r.userId, System.identityHashCode(r), task.taskId, |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 4446 | r.shortComponentName, r.intent.getAction(), |
Santos Cordon | 73ff7d8 | 2013-03-06 17:24:11 -0800 | [diff] [blame] | 4447 | r.intent.getType(), strData, r.intent.getFlags()); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 4448 | } |
| 4449 | |
| 4450 | /** |
Wale Ogunwale | db0fa12 | 2016-05-16 15:12:03 -0700 | [diff] [blame] | 4451 | * Ensures all visible activities at or below the input activity have the right configuration. |
| 4452 | */ |
| 4453 | void ensureVisibleActivitiesConfigurationLocked(ActivityRecord start, boolean preserveWindow) { |
| 4454 | if (start == null || !start.visible) { |
| 4455 | return; |
| 4456 | } |
| 4457 | |
| 4458 | final TaskRecord startTask = start.task; |
| 4459 | boolean behindFullscreen = false; |
| 4460 | boolean updatedConfig = false; |
| 4461 | |
| 4462 | for (int taskIndex = mTaskHistory.indexOf(startTask); taskIndex >= 0; --taskIndex) { |
| 4463 | final TaskRecord task = mTaskHistory.get(taskIndex); |
| 4464 | final ArrayList<ActivityRecord> activities = task.mActivities; |
| 4465 | int activityIndex = |
| 4466 | (start.task == task) ? activities.indexOf(start) : activities.size() - 1; |
| 4467 | for (; activityIndex >= 0; --activityIndex) { |
| 4468 | final ActivityRecord r = activities.get(activityIndex); |
| 4469 | updatedConfig |= ensureActivityConfigurationLocked(r, 0, preserveWindow); |
| 4470 | if (r.fullscreen) { |
| 4471 | behindFullscreen = true; |
| 4472 | break; |
| 4473 | } |
| 4474 | } |
| 4475 | if (behindFullscreen) { |
| 4476 | break; |
| 4477 | } |
| 4478 | } |
| 4479 | if (updatedConfig) { |
Wale Ogunwale | 089586f | 2016-06-20 14:16:22 -0700 | [diff] [blame] | 4480 | // 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] | 4481 | // any activity. |
| 4482 | mStackSupervisor.resumeFocusedStackTopActivityLocked(); |
| 4483 | } |
| 4484 | } |
| 4485 | |
| 4486 | /** |
| 4487 | * Make sure the given activity matches the current configuration. Returns false if the activity |
| 4488 | * had to be destroyed. Returns true if the configuration is the same, or the activity will |
| 4489 | * 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] | 4490 | * correct configuration and all other bookkeeping is handled. |
| 4491 | */ |
Wale Ogunwale | db0fa12 | 2016-05-16 15:12:03 -0700 | [diff] [blame] | 4492 | boolean ensureActivityConfigurationLocked( |
| 4493 | ActivityRecord r, int globalChanges, boolean preserveWindow) { |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 4494 | if (mConfigWillChange) { |
Wale Ogunwale | 3ab9a27 | 2015-03-16 09:55:45 -0700 | [diff] [blame] | 4495 | if (DEBUG_SWITCH || DEBUG_CONFIGURATION) Slog.v(TAG_CONFIGURATION, |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 4496 | "Skipping config check (will change): " + r); |
| 4497 | return true; |
| 4498 | } |
Craig Mautner | ce5f3cb | 2013-04-22 08:58:54 -0700 | [diff] [blame] | 4499 | |
Wale Ogunwale | 089586f | 2016-06-20 14:16:22 -0700 | [diff] [blame] | 4500 | // TODO: We could probably make the condition below just check that the activity state is |
| 4501 | // stopped, but also checking the sleep state for now to reduce change impact late in |
| 4502 | // development cycle. |
| 4503 | if (mService.isSleepingOrShuttingDownLocked() && r.state == ActivityState.STOPPED) { |
| 4504 | if (DEBUG_SWITCH || DEBUG_CONFIGURATION) Slog.v(TAG_CONFIGURATION, |
| 4505 | "Skipping config check (stopped while sleeping): " + r); |
| 4506 | return true; |
| 4507 | } |
| 4508 | |
Wale Ogunwale | 3ab9a27 | 2015-03-16 09:55:45 -0700 | [diff] [blame] | 4509 | if (DEBUG_SWITCH || DEBUG_CONFIGURATION) Slog.v(TAG_CONFIGURATION, |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 4510 | "Ensuring correct configuration: " + r); |
Craig Mautner | 9db9a0b | 2013-04-29 17:05:56 -0700 | [diff] [blame] | 4511 | |
Wale Ogunwale | f7dab1e | 2016-04-16 11:38:50 -0700 | [diff] [blame] | 4512 | // Short circuit: if the two configurations are equal (the common case), then there is |
| 4513 | // nothing to do. |
Wale Ogunwale | e4a0c57 | 2015-06-30 08:40:31 -0700 | [diff] [blame] | 4514 | final Configuration newConfig = mService.mConfiguration; |
Andrii Kulian | f12fce1 | 2016-05-27 17:30:16 -0700 | [diff] [blame] | 4515 | r.task.sanitizeOverrideConfiguration(newConfig); |
Wale Ogunwale | e4a0c57 | 2015-06-30 08:40:31 -0700 | [diff] [blame] | 4516 | final Configuration taskConfig = r.task.mOverrideConfig; |
Wale Ogunwale | f7dab1e | 2016-04-16 11:38:50 -0700 | [diff] [blame] | 4517 | if (r.configuration.equals(newConfig) |
| 4518 | && r.taskConfigOverride.equals(taskConfig) |
Wale Ogunwale | 60454db | 2015-01-23 16:05:07 -0800 | [diff] [blame] | 4519 | && !r.forceNewConfig) { |
Wale Ogunwale | 3ab9a27 | 2015-03-16 09:55:45 -0700 | [diff] [blame] | 4520 | if (DEBUG_SWITCH || DEBUG_CONFIGURATION) Slog.v(TAG_CONFIGURATION, |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 4521 | "Configuration unchanged in " + r); |
| 4522 | return true; |
| 4523 | } |
Craig Mautner | ce5f3cb | 2013-04-22 08:58:54 -0700 | [diff] [blame] | 4524 | |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 4525 | // We don't worry about activities that are finishing. |
| 4526 | if (r.finishing) { |
Wale Ogunwale | 3ab9a27 | 2015-03-16 09:55:45 -0700 | [diff] [blame] | 4527 | if (DEBUG_SWITCH || DEBUG_CONFIGURATION) Slog.v(TAG_CONFIGURATION, |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 4528 | "Configuration doesn't matter in finishing " + r); |
| 4529 | r.stopFreezingScreenLocked(false); |
| 4530 | return true; |
| 4531 | } |
Craig Mautner | ce5f3cb | 2013-04-22 08:58:54 -0700 | [diff] [blame] | 4532 | |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 4533 | // Okay we now are going to make this activity have the new config. |
| 4534 | // 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] | 4535 | final Configuration oldConfig = r.configuration; |
Wale Ogunwale | e4a0c57 | 2015-06-30 08:40:31 -0700 | [diff] [blame] | 4536 | final Configuration oldTaskOverride = r.taskConfigOverride; |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 4537 | r.configuration = newConfig; |
Wale Ogunwale | e4a0c57 | 2015-06-30 08:40:31 -0700 | [diff] [blame] | 4538 | r.taskConfigOverride = taskConfig; |
Dianne Hackborn | 58f42a5 | 2011-10-10 13:46:34 -0700 | [diff] [blame] | 4539 | |
Filip Gruszczynski | 2349332 | 2015-07-29 17:02:59 -0700 | [diff] [blame] | 4540 | int taskChanges = getTaskConfigurationChanges(r, taskConfig, oldTaskOverride); |
Wale Ogunwale | e4a0c57 | 2015-06-30 08:40:31 -0700 | [diff] [blame] | 4541 | final int changes = oldConfig.diff(newConfig) | taskChanges; |
Dianne Hackborn | 58f42a5 | 2011-10-10 13:46:34 -0700 | [diff] [blame] | 4542 | if (changes == 0 && !r.forceNewConfig) { |
Wale Ogunwale | 3ab9a27 | 2015-03-16 09:55:45 -0700 | [diff] [blame] | 4543 | if (DEBUG_SWITCH || DEBUG_CONFIGURATION) Slog.v(TAG_CONFIGURATION, |
Dianne Hackborn | 58f42a5 | 2011-10-10 13:46:34 -0700 | [diff] [blame] | 4544 | "Configuration no differences in " + r); |
Filip Gruszczynski | ca66481 | 2015-12-04 12:43:36 -0800 | [diff] [blame] | 4545 | // There are no significant differences, so we won't relaunch but should still deliver |
| 4546 | // the new configuration to the client process. |
Wale Ogunwale | f7dab1e | 2016-04-16 11:38:50 -0700 | [diff] [blame] | 4547 | r.scheduleConfigurationChanged(taskConfig, true); |
Dianne Hackborn | 58f42a5 | 2011-10-10 13:46:34 -0700 | [diff] [blame] | 4548 | return true; |
| 4549 | } |
| 4550 | |
Filip Gruszczynski | bc5a6c5 | 2015-09-22 13:13:24 -0700 | [diff] [blame] | 4551 | if (DEBUG_SWITCH || DEBUG_CONFIGURATION) Slog.v(TAG_CONFIGURATION, |
| 4552 | "Configuration changes for " + r + " ; taskChanges=" |
| 4553 | + Configuration.configurationDiffToString(taskChanges) + ", allChanges=" |
| 4554 | + Configuration.configurationDiffToString(changes)); |
| 4555 | |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 4556 | // If the activity isn't currently running, just leave the new |
| 4557 | // configuration and it will pick that up next time it starts. |
| 4558 | if (r.app == null || r.app.thread == null) { |
Wale Ogunwale | 3ab9a27 | 2015-03-16 09:55:45 -0700 | [diff] [blame] | 4559 | if (DEBUG_SWITCH || DEBUG_CONFIGURATION) Slog.v(TAG_CONFIGURATION, |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 4560 | "Configuration doesn't matter not running " + r); |
| 4561 | r.stopFreezingScreenLocked(false); |
Dianne Hackborn | e2515ee | 2011-04-27 18:52:56 -0400 | [diff] [blame] | 4562 | r.forceNewConfig = false; |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 4563 | return true; |
| 4564 | } |
Craig Mautner | ce5f3cb | 2013-04-22 08:58:54 -0700 | [diff] [blame] | 4565 | |
Dianne Hackborn | 58f42a5 | 2011-10-10 13:46:34 -0700 | [diff] [blame] | 4566 | // Figure out how to handle the changes between the configurations. |
Wale Ogunwale | 3ab9a27 | 2015-03-16 09:55:45 -0700 | [diff] [blame] | 4567 | if (DEBUG_SWITCH || DEBUG_CONFIGURATION) Slog.v(TAG_CONFIGURATION, |
| 4568 | "Checking to restart " + r.info.name + ": changed=0x" |
| 4569 | + Integer.toHexString(changes) + ", handles=0x" |
Filip Gruszczynski | ca66481 | 2015-12-04 12:43:36 -0800 | [diff] [blame] | 4570 | + Integer.toHexString(r.info.getRealConfigChanged()) + ", newConfig=" + newConfig |
| 4571 | + ", taskConfig=" + taskConfig); |
Wale Ogunwale | 3ab9a27 | 2015-03-16 09:55:45 -0700 | [diff] [blame] | 4572 | |
Dianne Hackborn | e667635 | 2011-06-01 16:51:20 -0700 | [diff] [blame] | 4573 | if ((changes&(~r.info.getRealConfigChanged())) != 0 || r.forceNewConfig) { |
Dianne Hackborn | 3c4c2b7 | 2010-10-05 18:07:54 -0700 | [diff] [blame] | 4574 | // Aha, the activity isn't handling the change, so DIE DIE DIE. |
| 4575 | r.configChangeFlags |= changes; |
| 4576 | r.startFreezingScreenLocked(r.app, globalChanges); |
Dianne Hackborn | e2515ee | 2011-04-27 18:52:56 -0400 | [diff] [blame] | 4577 | r.forceNewConfig = false; |
Wale Ogunwale | f81c1d1 | 2016-01-12 12:20:18 -0800 | [diff] [blame] | 4578 | preserveWindow &= isResizeOnlyChange(changes); |
Dianne Hackborn | 3c4c2b7 | 2010-10-05 18:07:54 -0700 | [diff] [blame] | 4579 | if (r.app == null || r.app.thread == null) { |
Wale Ogunwale | 3ab9a27 | 2015-03-16 09:55:45 -0700 | [diff] [blame] | 4580 | if (DEBUG_SWITCH || DEBUG_CONFIGURATION) Slog.v(TAG_CONFIGURATION, |
Dianne Hackborn | b61a026 | 2012-05-14 17:19:18 -0700 | [diff] [blame] | 4581 | "Config is destroying non-running " + r); |
Craig Mautner | ee2e45a | 2014-06-27 12:10:03 -0700 | [diff] [blame] | 4582 | destroyActivityLocked(r, true, "config"); |
Dianne Hackborn | 3c4c2b7 | 2010-10-05 18:07:54 -0700 | [diff] [blame] | 4583 | } else if (r.state == ActivityState.PAUSING) { |
Wale Ogunwale | f81c1d1 | 2016-01-12 12:20:18 -0800 | [diff] [blame] | 4584 | // A little annoying: we are waiting for this activity to finish pausing. Let's not |
| 4585 | // 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] | 4586 | if (DEBUG_SWITCH || DEBUG_CONFIGURATION) Slog.v(TAG_CONFIGURATION, |
Dianne Hackborn | b61a026 | 2012-05-14 17:19:18 -0700 | [diff] [blame] | 4587 | "Config is skipping already pausing " + r); |
Wale Ogunwale | f81c1d1 | 2016-01-12 12:20:18 -0800 | [diff] [blame] | 4588 | r.deferRelaunchUntilPaused = true; |
| 4589 | r.preserveWindowOnDeferredRelaunch = preserveWindow; |
Dianne Hackborn | 3c4c2b7 | 2010-10-05 18:07:54 -0700 | [diff] [blame] | 4590 | return true; |
| 4591 | } else if (r.state == ActivityState.RESUMED) { |
Wale Ogunwale | f81c1d1 | 2016-01-12 12:20:18 -0800 | [diff] [blame] | 4592 | // Try to optimize this case: the configuration is changing and we need to restart |
| 4593 | // the top, resumed activity. Instead of doing the normal handshaking, just say |
Dianne Hackborn | 3c4c2b7 | 2010-10-05 18:07:54 -0700 | [diff] [blame] | 4594 | // "restart!". |
Wale Ogunwale | 3ab9a27 | 2015-03-16 09:55:45 -0700 | [diff] [blame] | 4595 | if (DEBUG_SWITCH || DEBUG_CONFIGURATION) Slog.v(TAG_CONFIGURATION, |
Dianne Hackborn | b61a026 | 2012-05-14 17:19:18 -0700 | [diff] [blame] | 4596 | "Config is relaunching resumed " + r); |
Chong Zhang | 2b79af1 | 2016-02-10 18:47:06 -0800 | [diff] [blame] | 4597 | |
| 4598 | if (DEBUG_STATES && !r.visible) { |
| 4599 | Slog.v(TAG_STATES, "Config is relaunching resumed invisible activity " + r |
| 4600 | + " called by " + Debug.getCallers(4)); |
| 4601 | } |
| 4602 | |
Wale Ogunwale | f81c1d1 | 2016-01-12 12:20:18 -0800 | [diff] [blame] | 4603 | relaunchActivityLocked(r, r.configChangeFlags, true, preserveWindow); |
Dianne Hackborn | 3c4c2b7 | 2010-10-05 18:07:54 -0700 | [diff] [blame] | 4604 | } else { |
Wale Ogunwale | 3ab9a27 | 2015-03-16 09:55:45 -0700 | [diff] [blame] | 4605 | if (DEBUG_SWITCH || DEBUG_CONFIGURATION) Slog.v(TAG_CONFIGURATION, |
Dianne Hackborn | b61a026 | 2012-05-14 17:19:18 -0700 | [diff] [blame] | 4606 | "Config is relaunching non-resumed " + r); |
Wale Ogunwale | f81c1d1 | 2016-01-12 12:20:18 -0800 | [diff] [blame] | 4607 | relaunchActivityLocked(r, r.configChangeFlags, false, preserveWindow); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 4608 | } |
Craig Mautner | ce5f3cb | 2013-04-22 08:58:54 -0700 | [diff] [blame] | 4609 | |
Wale Ogunwale | f81c1d1 | 2016-01-12 12:20:18 -0800 | [diff] [blame] | 4610 | // 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] | 4611 | return false; |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 4612 | } |
Craig Mautner | ce5f3cb | 2013-04-22 08:58:54 -0700 | [diff] [blame] | 4613 | |
Wale Ogunwale | c2607b4 | 2015-02-07 16:16:59 -0800 | [diff] [blame] | 4614 | // 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] | 4615 | // 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] | 4616 | // changes is always sent to all processes when they happen so it can just use whatever |
| 4617 | // system level configuration it last got. |
Filip Gruszczynski | ca66481 | 2015-12-04 12:43:36 -0800 | [diff] [blame] | 4618 | r.scheduleConfigurationChanged(taskConfig, true); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 4619 | r.stopFreezingScreenLocked(false); |
Craig Mautner | ce5f3cb | 2013-04-22 08:58:54 -0700 | [diff] [blame] | 4620 | |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 4621 | return true; |
| 4622 | } |
| 4623 | |
Filip Gruszczynski | 2349332 | 2015-07-29 17:02:59 -0700 | [diff] [blame] | 4624 | private int getTaskConfigurationChanges(ActivityRecord record, Configuration taskConfig, |
| 4625 | Configuration oldTaskOverride) { |
Jorim Jaggi | a95ca8d | 2016-01-15 22:54:46 -0800 | [diff] [blame] | 4626 | |
| 4627 | // If we went from full-screen to non-full-screen, make sure to use the correct |
| 4628 | // configuration task diff, so the diff stays as small as possible. |
| 4629 | if (Configuration.EMPTY.equals(oldTaskOverride) |
| 4630 | && !Configuration.EMPTY.equals(taskConfig)) { |
| 4631 | oldTaskOverride = record.task.extractOverrideConfig(record.configuration); |
| 4632 | } |
| 4633 | |
Jorim Jaggi | 1b025a6 | 2016-02-03 19:27:49 -0800 | [diff] [blame] | 4634 | // Conversely, do the same when going the other direction. |
| 4635 | if (Configuration.EMPTY.equals(taskConfig) |
| 4636 | && !Configuration.EMPTY.equals(oldTaskOverride)) { |
| 4637 | taskConfig = record.task.extractOverrideConfig(record.configuration); |
| 4638 | } |
| 4639 | |
Filip Gruszczynski | 2349332 | 2015-07-29 17:02:59 -0700 | [diff] [blame] | 4640 | // Determine what has changed. May be nothing, if this is a config |
| 4641 | // that has come back from the app after going idle. In that case |
| 4642 | // we just want to leave the official config object now in the |
| 4643 | // activity and do nothing else. |
| 4644 | int taskChanges = oldTaskOverride.diff(taskConfig); |
| 4645 | // We don't want to use size changes if they don't cross boundaries that are important to |
| 4646 | // the app. |
Filip Gruszczynski | 3c2db1d1 | 2016-01-06 17:39:14 -0800 | [diff] [blame] | 4647 | if ((taskChanges & CONFIG_SCREEN_SIZE) != 0) { |
Filip Gruszczynski | 2349332 | 2015-07-29 17:02:59 -0700 | [diff] [blame] | 4648 | final boolean crosses = record.crossesHorizontalSizeThreshold( |
| 4649 | oldTaskOverride.screenWidthDp, taskConfig.screenWidthDp) |
| 4650 | || record.crossesVerticalSizeThreshold( |
| 4651 | oldTaskOverride.screenHeightDp, taskConfig.screenHeightDp); |
| 4652 | if (!crosses) { |
Filip Gruszczynski | 3c2db1d1 | 2016-01-06 17:39:14 -0800 | [diff] [blame] | 4653 | taskChanges &= ~CONFIG_SCREEN_SIZE; |
Filip Gruszczynski | 2349332 | 2015-07-29 17:02:59 -0700 | [diff] [blame] | 4654 | } |
| 4655 | } |
Filip Gruszczynski | 3c2db1d1 | 2016-01-06 17:39:14 -0800 | [diff] [blame] | 4656 | if ((taskChanges & CONFIG_SMALLEST_SCREEN_SIZE) != 0) { |
Filip Gruszczynski | 2349332 | 2015-07-29 17:02:59 -0700 | [diff] [blame] | 4657 | final int oldSmallest = oldTaskOverride.smallestScreenWidthDp; |
| 4658 | final int newSmallest = taskConfig.smallestScreenWidthDp; |
Filip Gruszczynski | 20aa0ae | 2015-10-30 10:08:27 -0700 | [diff] [blame] | 4659 | if (!record.crossesSmallestSizeThreshold(oldSmallest, newSmallest)) { |
Filip Gruszczynski | 3c2db1d1 | 2016-01-06 17:39:14 -0800 | [diff] [blame] | 4660 | taskChanges &= ~CONFIG_SMALLEST_SCREEN_SIZE; |
Filip Gruszczynski | 2349332 | 2015-07-29 17:02:59 -0700 | [diff] [blame] | 4661 | } |
| 4662 | } |
| 4663 | return catchConfigChangesFromUnset(taskConfig, oldTaskOverride, taskChanges); |
| 4664 | } |
| 4665 | |
| 4666 | private static int catchConfigChangesFromUnset(Configuration taskConfig, |
| 4667 | Configuration oldTaskOverride, int taskChanges) { |
| 4668 | if (taskChanges == 0) { |
| 4669 | // {@link Configuration#diff} doesn't catch changes from unset values. |
| 4670 | // Check for changes we care about. |
| 4671 | if (oldTaskOverride.orientation != taskConfig.orientation) { |
Filip Gruszczynski | 3c2db1d1 | 2016-01-06 17:39:14 -0800 | [diff] [blame] | 4672 | taskChanges |= CONFIG_ORIENTATION; |
Filip Gruszczynski | 2349332 | 2015-07-29 17:02:59 -0700 | [diff] [blame] | 4673 | } |
| 4674 | // We want to explicitly track situations where the size configuration goes from |
| 4675 | // undefined to defined. We don't care about crossing the threshold in that case, |
| 4676 | // because there is no threshold. |
| 4677 | final int oldHeight = oldTaskOverride.screenHeightDp; |
| 4678 | final int newHeight = taskConfig.screenHeightDp; |
| 4679 | final int undefinedHeight = Configuration.SCREEN_HEIGHT_DP_UNDEFINED; |
| 4680 | if ((oldHeight == undefinedHeight && newHeight != undefinedHeight) |
| 4681 | || (oldHeight != undefinedHeight && newHeight == undefinedHeight)) { |
Filip Gruszczynski | 3c2db1d1 | 2016-01-06 17:39:14 -0800 | [diff] [blame] | 4682 | taskChanges |= CONFIG_SCREEN_SIZE; |
Filip Gruszczynski | 2349332 | 2015-07-29 17:02:59 -0700 | [diff] [blame] | 4683 | } |
| 4684 | final int oldWidth = oldTaskOverride.screenWidthDp; |
| 4685 | final int newWidth = taskConfig.screenWidthDp; |
| 4686 | final int undefinedWidth = Configuration.SCREEN_WIDTH_DP_UNDEFINED; |
| 4687 | if ((oldWidth == undefinedWidth && newWidth != undefinedWidth) |
| 4688 | || (oldWidth != undefinedWidth && newWidth == undefinedWidth)) { |
Filip Gruszczynski | 3c2db1d1 | 2016-01-06 17:39:14 -0800 | [diff] [blame] | 4689 | taskChanges |= CONFIG_SCREEN_SIZE; |
Filip Gruszczynski | 2349332 | 2015-07-29 17:02:59 -0700 | [diff] [blame] | 4690 | } |
| 4691 | final int oldSmallest = oldTaskOverride.smallestScreenWidthDp; |
| 4692 | final int newSmallest = taskConfig.smallestScreenWidthDp; |
| 4693 | final int undefinedSmallest = Configuration.SMALLEST_SCREEN_WIDTH_DP_UNDEFINED; |
| 4694 | if ((oldSmallest == undefinedSmallest && newSmallest != undefinedSmallest) |
| 4695 | || (oldSmallest != undefinedSmallest && newSmallest == undefinedSmallest)) { |
Filip Gruszczynski | 3c2db1d1 | 2016-01-06 17:39:14 -0800 | [diff] [blame] | 4696 | taskChanges |= CONFIG_SMALLEST_SCREEN_SIZE; |
| 4697 | } |
| 4698 | final int oldLayout = oldTaskOverride.screenLayout; |
| 4699 | final int newLayout = taskConfig.screenLayout; |
| 4700 | if ((oldLayout == SCREENLAYOUT_UNDEFINED && newLayout != SCREENLAYOUT_UNDEFINED) |
| 4701 | || (oldLayout != SCREENLAYOUT_UNDEFINED && newLayout == SCREENLAYOUT_UNDEFINED)) { |
| 4702 | taskChanges |= CONFIG_SCREEN_LAYOUT; |
Filip Gruszczynski | 2349332 | 2015-07-29 17:02:59 -0700 | [diff] [blame] | 4703 | } |
| 4704 | } |
| 4705 | return taskChanges; |
| 4706 | } |
| 4707 | |
Filip Gruszczynski | a59ac9c | 2015-09-10 18:28:48 -0700 | [diff] [blame] | 4708 | private static boolean isResizeOnlyChange(int change) { |
Filip Gruszczynski | 3c2db1d1 | 2016-01-06 17:39:14 -0800 | [diff] [blame] | 4709 | return (change & ~(CONFIG_SCREEN_SIZE | CONFIG_SMALLEST_SCREEN_SIZE | CONFIG_ORIENTATION |
| 4710 | | CONFIG_SCREEN_LAYOUT)) == 0; |
Filip Gruszczynski | a59ac9c | 2015-09-10 18:28:48 -0700 | [diff] [blame] | 4711 | } |
| 4712 | |
Wale Ogunwale | 83301a9 | 2015-09-24 15:54:08 -0700 | [diff] [blame] | 4713 | private void relaunchActivityLocked( |
| 4714 | ActivityRecord r, int changes, boolean andResume, boolean preserveWindow) { |
| 4715 | if (mService.mSuppressResizeConfigChanges && preserveWindow) { |
Wale Ogunwale | f81c1d1 | 2016-01-12 12:20:18 -0800 | [diff] [blame] | 4716 | r.configChangeFlags = 0; |
Wale Ogunwale | 83301a9 | 2015-09-24 15:54:08 -0700 | [diff] [blame] | 4717 | return; |
| 4718 | } |
| 4719 | |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 4720 | List<ResultInfo> results = null; |
Dianne Hackborn | 85d558c | 2014-11-04 10:31:54 -0800 | [diff] [blame] | 4721 | List<ReferrerIntent> newIntents = null; |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 4722 | if (andResume) { |
| 4723 | results = r.results; |
| 4724 | newIntents = r.newIntents; |
| 4725 | } |
Wale Ogunwale | ee006da | 2015-03-30 14:49:25 -0700 | [diff] [blame] | 4726 | if (DEBUG_SWITCH) Slog.v(TAG_SWITCH, |
| 4727 | "Relaunching: " + r + " with results=" + results + " newIntents=" + newIntents |
Filip Gruszczynski | a59ac9c | 2015-09-10 18:28:48 -0700 | [diff] [blame] | 4728 | + " andResume=" + andResume + " preserveWindow=" + preserveWindow); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 4729 | EventLog.writeEvent(andResume ? EventLogTags.AM_RELAUNCH_RESUME_ACTIVITY |
Dianne Hackborn | b12e135 | 2012-09-26 11:39:20 -0700 | [diff] [blame] | 4730 | : EventLogTags.AM_RELAUNCH_ACTIVITY, r.userId, System.identityHashCode(r), |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 4731 | r.task.taskId, r.shortComponentName); |
Craig Mautner | 9db9a0b | 2013-04-29 17:05:56 -0700 | [diff] [blame] | 4732 | |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 4733 | r.startFreezingScreenLocked(r.app, 0); |
Craig Mautner | 9db9a0b | 2013-04-29 17:05:56 -0700 | [diff] [blame] | 4734 | |
Craig Mautner | 34b73df | 2014-01-12 21:11:08 -0800 | [diff] [blame] | 4735 | mStackSupervisor.removeChildActivityContainers(r); |
| 4736 | |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 4737 | try { |
Wale Ogunwale | ee006da | 2015-03-30 14:49:25 -0700 | [diff] [blame] | 4738 | if (DEBUG_SWITCH || DEBUG_STATES) Slog.i(TAG_SWITCH, |
Wale Ogunwale | 5658e4b | 2016-02-12 12:22:19 -0800 | [diff] [blame] | 4739 | "Moving to " + (andResume ? "RESUMED" : "PAUSED") + " Relaunching " + r |
| 4740 | + " callers=" + Debug.getCallers(6)); |
Dianne Hackborn | e2515ee | 2011-04-27 18:52:56 -0400 | [diff] [blame] | 4741 | r.forceNewConfig = false; |
Chong Zhang | d78ddb4 | 2016-03-02 17:01:14 -0800 | [diff] [blame] | 4742 | mStackSupervisor.activityRelaunchingLocked(r); |
Wale Ogunwale | 60454db | 2015-01-23 16:05:07 -0800 | [diff] [blame] | 4743 | r.app.thread.scheduleRelaunchActivity(r.appToken, results, newIntents, changes, |
| 4744 | !andResume, new Configuration(mService.mConfiguration), |
Filip Gruszczynski | a59ac9c | 2015-09-10 18:28:48 -0700 | [diff] [blame] | 4745 | new Configuration(r.task.mOverrideConfig), preserveWindow); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 4746 | // Note: don't need to call pauseIfSleepingLocked() here, because |
| 4747 | // the caller will only pass in 'andResume' if this activity is |
| 4748 | // currently resumed, which implies we aren't sleeping. |
| 4749 | } catch (RemoteException e) { |
Wale Ogunwale | ee006da | 2015-03-30 14:49:25 -0700 | [diff] [blame] | 4750 | if (DEBUG_SWITCH || DEBUG_STATES) Slog.i(TAG_SWITCH, "Relaunch failed", e); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 4751 | } |
| 4752 | |
| 4753 | if (andResume) { |
Chong Zhang | 2b79af1 | 2016-02-10 18:47:06 -0800 | [diff] [blame] | 4754 | if (DEBUG_STATES) { |
| 4755 | Slog.d(TAG_STATES, "Resumed after relaunch " + r); |
| 4756 | } |
Chong Zhang | d2cb311 | 2016-07-20 11:13:22 -0700 | [diff] [blame^] | 4757 | r.results = null; |
| 4758 | r.newIntents = null; |
Andrii Kulian | f42cbe8 | 2016-06-22 14:49:58 -0700 | [diff] [blame] | 4759 | mService.showUnsupportedZoomDialogIfNeededLocked(r); |
| 4760 | mService.showAskCompatModeDialogLocked(r); |
Dianne Hackborn | b61a026 | 2012-05-14 17:19:18 -0700 | [diff] [blame] | 4761 | } else { |
| 4762 | mHandler.removeMessages(PAUSE_TIMEOUT_MSG, r); |
| 4763 | r.state = ActivityState.PAUSED; |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 4764 | } |
Wale Ogunwale | f81c1d1 | 2016-01-12 12:20:18 -0800 | [diff] [blame] | 4765 | |
| 4766 | r.configChangeFlags = 0; |
Chong Zhang | 225d1b6 | 2016-03-31 14:09:33 -0700 | [diff] [blame] | 4767 | r.deferRelaunchUntilPaused = false; |
| 4768 | r.preserveWindowOnDeferredRelaunch = false; |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 4769 | } |
Craig Mautner | cae015f | 2013-02-08 14:31:27 -0800 | [diff] [blame] | 4770 | |
| 4771 | boolean willActivityBeVisibleLocked(IBinder token) { |
Craig Mautner | d44711d | 2013-02-23 11:24:36 -0800 | [diff] [blame] | 4772 | for (int taskNdx = mTaskHistory.size() - 1; taskNdx >= 0; --taskNdx) { |
| 4773 | final ArrayList<ActivityRecord> activities = mTaskHistory.get(taskNdx).mActivities; |
| 4774 | for (int activityNdx = activities.size() - 1; activityNdx >= 0; --activityNdx) { |
| 4775 | final ActivityRecord r = activities.get(activityNdx); |
| 4776 | if (r.appToken == token) { |
Craig Mautner | 34b73df | 2014-01-12 21:11:08 -0800 | [diff] [blame] | 4777 | return true; |
Craig Mautner | d44711d | 2013-02-23 11:24:36 -0800 | [diff] [blame] | 4778 | } |
| 4779 | if (r.fullscreen && !r.finishing) { |
| 4780 | return false; |
| 4781 | } |
Craig Mautner | cae015f | 2013-02-08 14:31:27 -0800 | [diff] [blame] | 4782 | } |
| 4783 | } |
Wale Ogunwale | 7d70117 | 2015-03-11 15:36:30 -0700 | [diff] [blame] | 4784 | final ActivityRecord r = ActivityRecord.forTokenLocked(token); |
Craig Mautner | 34b73df | 2014-01-12 21:11:08 -0800 | [diff] [blame] | 4785 | if (r == null) { |
| 4786 | return false; |
| 4787 | } |
| 4788 | if (r.finishing) Slog.e(TAG, "willActivityBeVisibleLocked: Returning false," |
| 4789 | + " would have returned true for r=" + r); |
| 4790 | return !r.finishing; |
Craig Mautner | cae015f | 2013-02-08 14:31:27 -0800 | [diff] [blame] | 4791 | } |
| 4792 | |
| 4793 | void closeSystemDialogsLocked() { |
Craig Mautner | d44711d | 2013-02-23 11:24:36 -0800 | [diff] [blame] | 4794 | for (int taskNdx = mTaskHistory.size() - 1; taskNdx >= 0; --taskNdx) { |
| 4795 | final ArrayList<ActivityRecord> activities = mTaskHistory.get(taskNdx).mActivities; |
| 4796 | for (int activityNdx = activities.size() - 1; activityNdx >= 0; --activityNdx) { |
| 4797 | final ActivityRecord r = activities.get(activityNdx); |
| 4798 | if ((r.info.flags&ActivityInfo.FLAG_FINISH_ON_CLOSE_SYSTEM_DIALOGS) != 0) { |
Craig Mautner | d232895 | 2013-03-05 12:46:26 -0800 | [diff] [blame] | 4799 | finishActivityLocked(r, Activity.RESULT_CANCELED, null, "close-sys", true); |
Craig Mautner | d44711d | 2013-02-23 11:24:36 -0800 | [diff] [blame] | 4800 | } |
Craig Mautner | cae015f | 2013-02-08 14:31:27 -0800 | [diff] [blame] | 4801 | } |
| 4802 | } |
| 4803 | } |
| 4804 | |
Wale Ogunwale | 540e123 | 2015-05-01 15:35:39 -0700 | [diff] [blame] | 4805 | boolean finishDisabledPackageActivitiesLocked(String packageName, Set<String> filterByClasses, |
| 4806 | boolean doit, boolean evenPersistent, int userId) { |
Craig Mautner | cae015f | 2013-02-08 14:31:27 -0800 | [diff] [blame] | 4807 | boolean didSomething = false; |
| 4808 | TaskRecord lastTask = null; |
Craig Mautner | 9d8a30d | 2014-07-07 17:26:20 +0000 | [diff] [blame] | 4809 | ComponentName homeActivity = null; |
Craig Mautner | 56f52db | 2013-02-25 10:03:01 -0800 | [diff] [blame] | 4810 | for (int taskNdx = mTaskHistory.size() - 1; taskNdx >= 0; --taskNdx) { |
| 4811 | final ArrayList<ActivityRecord> activities = mTaskHistory.get(taskNdx).mActivities; |
| 4812 | int numActivities = activities.size(); |
| 4813 | for (int activityNdx = 0; activityNdx < numActivities; ++activityNdx) { |
| 4814 | ActivityRecord r = activities.get(activityNdx); |
Wale Ogunwale | 540e123 | 2015-05-01 15:35:39 -0700 | [diff] [blame] | 4815 | final boolean sameComponent = |
| 4816 | (r.packageName.equals(packageName) && (filterByClasses == null |
| 4817 | || filterByClasses.contains(r.realActivity.getClassName()))) |
| 4818 | || (packageName == null && r.userId == userId); |
Craig Mautner | 56f52db | 2013-02-25 10:03:01 -0800 | [diff] [blame] | 4819 | if ((userId == UserHandle.USER_ALL || r.userId == userId) |
Wale Ogunwale | 540e123 | 2015-05-01 15:35:39 -0700 | [diff] [blame] | 4820 | && (sameComponent || r.task == lastTask) |
Craig Mautner | 56f52db | 2013-02-25 10:03:01 -0800 | [diff] [blame] | 4821 | && (r.app == null || evenPersistent || !r.app.persistent)) { |
| 4822 | if (!doit) { |
| 4823 | if (r.finishing) { |
| 4824 | // If this activity is just finishing, then it is not |
| 4825 | // interesting as far as something to stop. |
| 4826 | continue; |
| 4827 | } |
| 4828 | return true; |
Craig Mautner | cae015f | 2013-02-08 14:31:27 -0800 | [diff] [blame] | 4829 | } |
Craig Mautner | 9d8a30d | 2014-07-07 17:26:20 +0000 | [diff] [blame] | 4830 | if (r.isHomeActivity()) { |
| 4831 | if (homeActivity != null && homeActivity.equals(r.realActivity)) { |
| 4832 | Slog.i(TAG, "Skip force-stop again " + r); |
| 4833 | continue; |
| 4834 | } else { |
| 4835 | homeActivity = r.realActivity; |
| 4836 | } |
| 4837 | } |
Craig Mautner | 56f52db | 2013-02-25 10:03:01 -0800 | [diff] [blame] | 4838 | didSomething = true; |
| 4839 | Slog.i(TAG, " Force finishing activity " + r); |
Wale Ogunwale | 540e123 | 2015-05-01 15:35:39 -0700 | [diff] [blame] | 4840 | if (sameComponent) { |
Craig Mautner | 56f52db | 2013-02-25 10:03:01 -0800 | [diff] [blame] | 4841 | if (r.app != null) { |
| 4842 | r.app.removed = true; |
| 4843 | } |
| 4844 | r.app = null; |
Craig Mautner | cae015f | 2013-02-08 14:31:27 -0800 | [diff] [blame] | 4845 | } |
Craig Mautner | 56f52db | 2013-02-25 10:03:01 -0800 | [diff] [blame] | 4846 | lastTask = r.task; |
Craig Mautner | d94b1b4 | 2013-05-01 11:58:03 -0700 | [diff] [blame] | 4847 | if (finishActivityLocked(r, Activity.RESULT_CANCELED, null, "force-stop", |
| 4848 | true)) { |
| 4849 | // r has been deleted from mActivities, accommodate. |
| 4850 | --numActivities; |
| 4851 | --activityNdx; |
| 4852 | } |
Craig Mautner | cae015f | 2013-02-08 14:31:27 -0800 | [diff] [blame] | 4853 | } |
| 4854 | } |
| 4855 | } |
| 4856 | return didSomething; |
| 4857 | } |
| 4858 | |
Dianne Hackborn | 0923328 | 2014-04-30 11:33:59 -0700 | [diff] [blame] | 4859 | void getTasksLocked(List<RunningTaskInfo> list, int callingUid, boolean allowed) { |
riddle_hsu | ddc7415 | 2015-04-07 11:30:09 +0800 | [diff] [blame] | 4860 | boolean focusedStack = mStackSupervisor.getFocusedStack() == this; |
| 4861 | boolean topTask = true; |
Craig Mautner | c0fd805 | 2013-09-19 11:20:17 -0700 | [diff] [blame] | 4862 | for (int taskNdx = mTaskHistory.size() - 1; taskNdx >= 0; --taskNdx) { |
Craig Mautner | aab647e | 2013-02-28 16:31:36 -0800 | [diff] [blame] | 4863 | final TaskRecord task = mTaskHistory.get(taskNdx); |
riddle_hsu | ddc7415 | 2015-04-07 11:30:09 +0800 | [diff] [blame] | 4864 | if (task.getTopActivity() == null) { |
| 4865 | continue; |
| 4866 | } |
Craig Mautner | aab647e | 2013-02-28 16:31:36 -0800 | [diff] [blame] | 4867 | ActivityRecord r = null; |
| 4868 | ActivityRecord top = null; |
Wale Ogunwale | 6035e01 | 2015-04-14 15:54:10 -0700 | [diff] [blame] | 4869 | ActivityRecord tmp; |
Craig Mautner | aab647e | 2013-02-28 16:31:36 -0800 | [diff] [blame] | 4870 | int numActivities = 0; |
| 4871 | int numRunning = 0; |
| 4872 | final ArrayList<ActivityRecord> activities = task.mActivities; |
Dianne Hackborn | 885fbe5 | 2014-08-23 15:23:58 -0700 | [diff] [blame] | 4873 | if (!allowed && !task.isHomeTask() && task.effectiveUid != callingUid) { |
Dianne Hackborn | 0923328 | 2014-04-30 11:33:59 -0700 | [diff] [blame] | 4874 | continue; |
| 4875 | } |
Craig Mautner | aab647e | 2013-02-28 16:31:36 -0800 | [diff] [blame] | 4876 | for (int activityNdx = activities.size() - 1; activityNdx >= 0; --activityNdx) { |
Wale Ogunwale | 6035e01 | 2015-04-14 15:54:10 -0700 | [diff] [blame] | 4877 | tmp = activities.get(activityNdx); |
| 4878 | if (tmp.finishing) { |
| 4879 | continue; |
| 4880 | } |
| 4881 | r = tmp; |
Craig Mautner | cae015f | 2013-02-08 14:31:27 -0800 | [diff] [blame] | 4882 | |
Craig Mautner | aab647e | 2013-02-28 16:31:36 -0800 | [diff] [blame] | 4883 | // Initialize state for next task if needed. |
| 4884 | if (top == null || (top.state == ActivityState.INITIALIZING)) { |
| 4885 | top = r; |
| 4886 | numActivities = numRunning = 0; |
Craig Mautner | cae015f | 2013-02-08 14:31:27 -0800 | [diff] [blame] | 4887 | } |
Craig Mautner | aab647e | 2013-02-28 16:31:36 -0800 | [diff] [blame] | 4888 | |
| 4889 | // Add 'r' into the current task. |
| 4890 | numActivities++; |
| 4891 | if (r.app != null && r.app.thread != null) { |
| 4892 | numRunning++; |
| 4893 | } |
| 4894 | |
Wale Ogunwale | e23149f | 2015-03-06 15:39:44 -0800 | [diff] [blame] | 4895 | if (DEBUG_ALL) Slog.v( |
Craig Mautner | aab647e | 2013-02-28 16:31:36 -0800 | [diff] [blame] | 4896 | TAG, r.intent.getComponent().flattenToShortString() |
| 4897 | + ": task=" + r.task); |
| 4898 | } |
| 4899 | |
| 4900 | RunningTaskInfo ci = new RunningTaskInfo(); |
| 4901 | ci.id = task.taskId; |
Filip Gruszczynski | d64ef3e | 2015-10-27 17:58:02 -0700 | [diff] [blame] | 4902 | ci.stackId = mStackId; |
Craig Mautner | aab647e | 2013-02-28 16:31:36 -0800 | [diff] [blame] | 4903 | ci.baseActivity = r.intent.getComponent(); |
| 4904 | ci.topActivity = top.intent.getComponent(); |
Craig Mautner | c0fd805 | 2013-09-19 11:20:17 -0700 | [diff] [blame] | 4905 | ci.lastActiveTime = task.lastActiveTime; |
riddle_hsu | ddc7415 | 2015-04-07 11:30:09 +0800 | [diff] [blame] | 4906 | if (focusedStack && topTask) { |
| 4907 | // Give the latest time to ensure foreground task can be sorted |
| 4908 | // at the first, because lastActiveTime of creating task is 0. |
| 4909 | ci.lastActiveTime = System.currentTimeMillis(); |
| 4910 | topTask = false; |
| 4911 | } |
Craig Mautner | c0fd805 | 2013-09-19 11:20:17 -0700 | [diff] [blame] | 4912 | |
Craig Mautner | c0ffce5 | 2014-07-01 12:38:52 -0700 | [diff] [blame] | 4913 | if (top.task != null) { |
| 4914 | ci.description = top.task.lastDescription; |
Craig Mautner | aab647e | 2013-02-28 16:31:36 -0800 | [diff] [blame] | 4915 | } |
| 4916 | ci.numActivities = numActivities; |
| 4917 | ci.numRunning = numRunning; |
Wale Ogunwale | 21b6058 | 2016-01-27 12:34:16 -0800 | [diff] [blame] | 4918 | ci.isDockable = task.canGoInDockedStack(); |
Jorim Jaggi | 29379ec | 2016-04-11 23:43:42 -0700 | [diff] [blame] | 4919 | ci.resizeMode = task.mResizeMode; |
Craig Mautner | aab647e | 2013-02-28 16:31:36 -0800 | [diff] [blame] | 4920 | list.add(ci); |
Craig Mautner | cae015f | 2013-02-08 14:31:27 -0800 | [diff] [blame] | 4921 | } |
Craig Mautner | cae015f | 2013-02-08 14:31:27 -0800 | [diff] [blame] | 4922 | } |
| 4923 | |
| 4924 | public void unhandledBackLocked() { |
Craig Mautner | aab647e | 2013-02-28 16:31:36 -0800 | [diff] [blame] | 4925 | final int top = mTaskHistory.size() - 1; |
Wale Ogunwale | ee006da | 2015-03-30 14:49:25 -0700 | [diff] [blame] | 4926 | 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] | 4927 | if (top >= 0) { |
| 4928 | final ArrayList<ActivityRecord> activities = mTaskHistory.get(top).mActivities; |
| 4929 | int activityTop = activities.size() - 1; |
| 4930 | if (activityTop > 0) { |
| 4931 | finishActivityLocked(activities.get(activityTop), Activity.RESULT_CANCELED, null, |
| 4932 | "unhandled-back", true); |
| 4933 | } |
Craig Mautner | cae015f | 2013-02-08 14:31:27 -0800 | [diff] [blame] | 4934 | } |
| 4935 | } |
| 4936 | |
Craig Mautner | 6b74cb5 | 2013-09-27 17:02:21 -0700 | [diff] [blame] | 4937 | /** |
| 4938 | * Reset local parameters because an app's activity died. |
| 4939 | * @param app The app of the activity that died. |
Craig Mautner | 1909125 | 2013-10-05 00:03:53 -0700 | [diff] [blame] | 4940 | * @return result from removeHistoryRecordsForAppLocked. |
Craig Mautner | 6b74cb5 | 2013-09-27 17:02:21 -0700 | [diff] [blame] | 4941 | */ |
| 4942 | boolean handleAppDiedLocked(ProcessRecord app) { |
Craig Mautner | e79d4268 | 2013-04-01 19:01:53 -0700 | [diff] [blame] | 4943 | if (mPausingActivity != null && mPausingActivity.app == app) { |
Wale Ogunwale | ee006da | 2015-03-30 14:49:25 -0700 | [diff] [blame] | 4944 | if (DEBUG_PAUSE || DEBUG_CLEANUP) Slog.v(TAG_PAUSE, |
Craig Mautner | e79d4268 | 2013-04-01 19:01:53 -0700 | [diff] [blame] | 4945 | "App died while pausing: " + mPausingActivity); |
| 4946 | mPausingActivity = null; |
| 4947 | } |
| 4948 | if (mLastPausedActivity != null && mLastPausedActivity.app == app) { |
| 4949 | mLastPausedActivity = null; |
Craig Mautner | 0f92274 | 2013-08-06 08:44:42 -0700 | [diff] [blame] | 4950 | mLastNoHistoryActivity = null; |
Craig Mautner | e79d4268 | 2013-04-01 19:01:53 -0700 | [diff] [blame] | 4951 | } |
| 4952 | |
Craig Mautner | 1909125 | 2013-10-05 00:03:53 -0700 | [diff] [blame] | 4953 | return removeHistoryRecordsForAppLocked(app); |
Craig Mautner | e79d4268 | 2013-04-01 19:01:53 -0700 | [diff] [blame] | 4954 | } |
| 4955 | |
Craig Mautner | cae015f | 2013-02-08 14:31:27 -0800 | [diff] [blame] | 4956 | void handleAppCrashLocked(ProcessRecord app) { |
Craig Mautner | d44711d | 2013-02-23 11:24:36 -0800 | [diff] [blame] | 4957 | for (int taskNdx = mTaskHistory.size() - 1; taskNdx >= 0; --taskNdx) { |
| 4958 | final ArrayList<ActivityRecord> activities = mTaskHistory.get(taskNdx).mActivities; |
| 4959 | for (int activityNdx = activities.size() - 1; activityNdx >= 0; --activityNdx) { |
| 4960 | final ActivityRecord r = activities.get(activityNdx); |
| 4961 | if (r.app == app) { |
| 4962 | Slog.w(TAG, " Force finishing activity " |
| 4963 | + r.intent.getComponent().flattenToShortString()); |
Craig Mautner | 8e5b133 | 2014-07-24 13:32:37 -0700 | [diff] [blame] | 4964 | // Force the destroy to skip right to removal. |
| 4965 | r.app = null; |
| 4966 | finishCurrentActivityLocked(r, FINISH_IMMEDIATELY, false); |
Craig Mautner | d44711d | 2013-02-23 11:24:36 -0800 | [diff] [blame] | 4967 | } |
Craig Mautner | cae015f | 2013-02-08 14:31:27 -0800 | [diff] [blame] | 4968 | } |
| 4969 | } |
| 4970 | } |
| 4971 | |
Dianne Hackborn | 390517b | 2013-05-30 15:03:32 -0700 | [diff] [blame] | 4972 | boolean dumpActivitiesLocked(FileDescriptor fd, PrintWriter pw, boolean dumpAll, |
Dianne Hackborn | 7ad34e5 | 2013-06-05 18:41:45 -0700 | [diff] [blame] | 4973 | boolean dumpClient, String dumpPackage, boolean needSep, String header) { |
Dianne Hackborn | 390517b | 2013-05-30 15:03:32 -0700 | [diff] [blame] | 4974 | boolean printed = false; |
Craig Mautner | aab647e | 2013-02-28 16:31:36 -0800 | [diff] [blame] | 4975 | for (int taskNdx = mTaskHistory.size() - 1; taskNdx >= 0; --taskNdx) { |
| 4976 | final TaskRecord task = mTaskHistory.get(taskNdx); |
Dianne Hackborn | 390517b | 2013-05-30 15:03:32 -0700 | [diff] [blame] | 4977 | printed |= ActivityStackSupervisor.dumpHistoryList(fd, pw, |
| 4978 | mTaskHistory.get(taskNdx).mActivities, " ", "Hist", true, !dumpAll, |
Dianne Hackborn | 7ad34e5 | 2013-06-05 18:41:45 -0700 | [diff] [blame] | 4979 | dumpClient, dumpPackage, needSep, header, |
Wale Ogunwale | b34a7ad | 2015-08-14 11:05:30 -0700 | [diff] [blame] | 4980 | " Task id #" + task.taskId + "\n" + |
| 4981 | " mFullscreen=" + task.mFullscreen + "\n" + |
| 4982 | " mBounds=" + task.mBounds + "\n" + |
Andrii Kulian | f66a83d | 2016-05-17 12:17:44 -0700 | [diff] [blame] | 4983 | " mMinWidth=" + task.mMinWidth + "\n" + |
| 4984 | " mMinHeight=" + task.mMinHeight + "\n" + |
Wale Ogunwale | b34a7ad | 2015-08-14 11:05:30 -0700 | [diff] [blame] | 4985 | " mLastNonFullscreenBounds=" + task.mLastNonFullscreenBounds); |
Dianne Hackborn | 7ad34e5 | 2013-06-05 18:41:45 -0700 | [diff] [blame] | 4986 | if (printed) { |
| 4987 | header = null; |
| 4988 | } |
Craig Mautner | aab647e | 2013-02-28 16:31:36 -0800 | [diff] [blame] | 4989 | } |
Dianne Hackborn | 390517b | 2013-05-30 15:03:32 -0700 | [diff] [blame] | 4990 | return printed; |
Craig Mautner | cae015f | 2013-02-08 14:31:27 -0800 | [diff] [blame] | 4991 | } |
| 4992 | |
| 4993 | ArrayList<ActivityRecord> getDumpActivitiesLocked(String name) { |
| 4994 | ArrayList<ActivityRecord> activities = new ArrayList<ActivityRecord>(); |
| 4995 | |
| 4996 | if ("all".equals(name)) { |
Craig Mautner | aab647e | 2013-02-28 16:31:36 -0800 | [diff] [blame] | 4997 | for (int taskNdx = mTaskHistory.size() - 1; taskNdx >= 0; --taskNdx) { |
| 4998 | activities.addAll(mTaskHistory.get(taskNdx).mActivities); |
Craig Mautner | cae015f | 2013-02-08 14:31:27 -0800 | [diff] [blame] | 4999 | } |
| 5000 | } else if ("top".equals(name)) { |
Craig Mautner | aab647e | 2013-02-28 16:31:36 -0800 | [diff] [blame] | 5001 | final int top = mTaskHistory.size() - 1; |
| 5002 | if (top >= 0) { |
| 5003 | final ArrayList<ActivityRecord> list = mTaskHistory.get(top).mActivities; |
| 5004 | int listTop = list.size() - 1; |
| 5005 | if (listTop >= 0) { |
| 5006 | activities.add(list.get(listTop)); |
| 5007 | } |
Craig Mautner | cae015f | 2013-02-08 14:31:27 -0800 | [diff] [blame] | 5008 | } |
| 5009 | } else { |
| 5010 | ItemMatcher matcher = new ItemMatcher(); |
| 5011 | matcher.build(name); |
| 5012 | |
Craig Mautner | aab647e | 2013-02-28 16:31:36 -0800 | [diff] [blame] | 5013 | for (int taskNdx = mTaskHistory.size() - 1; taskNdx >= 0; --taskNdx) { |
| 5014 | for (ActivityRecord r1 : mTaskHistory.get(taskNdx).mActivities) { |
| 5015 | if (matcher.match(r1, r1.intent.getComponent())) { |
| 5016 | activities.add(r1); |
| 5017 | } |
Craig Mautner | cae015f | 2013-02-08 14:31:27 -0800 | [diff] [blame] | 5018 | } |
| 5019 | } |
| 5020 | } |
| 5021 | |
| 5022 | return activities; |
| 5023 | } |
| 5024 | |
| 5025 | ActivityRecord restartPackage(String packageName) { |
Filip Gruszczynski | 3e85ba2 | 2015-10-05 22:48:30 -0700 | [diff] [blame] | 5026 | ActivityRecord starting = topRunningActivityLocked(); |
Craig Mautner | cae015f | 2013-02-08 14:31:27 -0800 | [diff] [blame] | 5027 | |
| 5028 | // All activities that came from the package must be |
| 5029 | // restarted as if there was a config change. |
Craig Mautner | aab647e | 2013-02-28 16:31:36 -0800 | [diff] [blame] | 5030 | for (int taskNdx = mTaskHistory.size() - 1; taskNdx >= 0; --taskNdx) { |
| 5031 | final ArrayList<ActivityRecord> activities = mTaskHistory.get(taskNdx).mActivities; |
| 5032 | for (int activityNdx = activities.size() - 1; activityNdx >= 0; --activityNdx) { |
| 5033 | final ActivityRecord a = activities.get(activityNdx); |
| 5034 | if (a.info.packageName.equals(packageName)) { |
| 5035 | a.forceNewConfig = true; |
| 5036 | if (starting != null && a == starting && a.visible) { |
| 5037 | a.startFreezingScreenLocked(starting.app, |
Filip Gruszczynski | 3c2db1d1 | 2016-01-06 17:39:14 -0800 | [diff] [blame] | 5038 | CONFIG_SCREEN_LAYOUT); |
Craig Mautner | aab647e | 2013-02-28 16:31:36 -0800 | [diff] [blame] | 5039 | } |
Craig Mautner | cae015f | 2013-02-08 14:31:27 -0800 | [diff] [blame] | 5040 | } |
| 5041 | } |
| 5042 | } |
| 5043 | |
| 5044 | return starting; |
| 5045 | } |
Craig Mautner | 5d9c7be | 2013-02-15 14:02:56 -0800 | [diff] [blame] | 5046 | |
Craig Mautner | 299f960 | 2015-01-26 09:47:33 -0800 | [diff] [blame] | 5047 | void removeTask(TaskRecord task, String reason) { |
Wale Ogunwale | 06579d6 | 2016-04-30 15:29:06 -0700 | [diff] [blame] | 5048 | removeTask(task, reason, REMOVE_TASK_MODE_DESTROYING); |
Wale Ogunwale | 53a29a9 | 2015-02-23 15:42:52 -0800 | [diff] [blame] | 5049 | } |
| 5050 | |
Wale Ogunwale | 000957c | 2015-04-03 08:19:12 -0700 | [diff] [blame] | 5051 | /** |
| 5052 | * Removes the input task from this stack. |
| 5053 | * @param task to remove. |
| 5054 | * @param reason for removal. |
Wale Ogunwale | 06579d6 | 2016-04-30 15:29:06 -0700 | [diff] [blame] | 5055 | * @param mode task removal mode. Either {@link #REMOVE_TASK_MODE_DESTROYING}, |
| 5056 | * {@link #REMOVE_TASK_MODE_MOVING}, {@link #REMOVE_TASK_MODE_MOVING_TO_TOP}. |
Wale Ogunwale | 000957c | 2015-04-03 08:19:12 -0700 | [diff] [blame] | 5057 | */ |
Wale Ogunwale | 06579d6 | 2016-04-30 15:29:06 -0700 | [diff] [blame] | 5058 | void removeTask(TaskRecord task, String reason, int mode) { |
| 5059 | if (mode == REMOVE_TASK_MODE_DESTROYING) { |
Craig Mautner | 15df08a | 2015-04-01 12:17:18 -0700 | [diff] [blame] | 5060 | mStackSupervisor.removeLockedTaskLocked(task); |
Wale Ogunwale | 53a29a9 | 2015-02-23 15:42:52 -0800 | [diff] [blame] | 5061 | mWindowManager.removeTask(task.taskId); |
Wale Ogunwale | b317b22 | 2015-11-09 11:14:10 -0800 | [diff] [blame] | 5062 | if (!StackId.persistTaskBounds(mStackId)) { |
| 5063 | // Reset current bounds for task whose bounds shouldn't be persisted so it uses |
| 5064 | // default configuration the next time it launches. |
| 5065 | task.updateOverrideConfiguration(null); |
| 5066 | } |
Wale Ogunwale | 53a29a9 | 2015-02-23 15:42:52 -0800 | [diff] [blame] | 5067 | } |
Wale Ogunwale | 000957c | 2015-04-03 08:19:12 -0700 | [diff] [blame] | 5068 | |
Craig Mautner | 04a0ea6 | 2014-01-13 12:51:26 -0800 | [diff] [blame] | 5069 | final ActivityRecord r = mResumedActivity; |
| 5070 | if (r != null && r.task == task) { |
| 5071 | mResumedActivity = null; |
| 5072 | } |
| 5073 | |
Craig Mautner | ae7ecab | 2013-09-18 11:48:14 -0700 | [diff] [blame] | 5074 | final int taskNdx = mTaskHistory.indexOf(task); |
| 5075 | final int topTaskNdx = mTaskHistory.size() - 1; |
Craig Mautner | 84984fa | 2014-06-19 11:19:20 -0700 | [diff] [blame] | 5076 | if (task.isOverHomeStack() && taskNdx < topTaskNdx) { |
| 5077 | final TaskRecord nextTask = mTaskHistory.get(taskNdx + 1); |
| 5078 | if (!nextTask.isOverHomeStack()) { |
| 5079 | nextTask.setTaskToReturnTo(HOME_ACTIVITY_TYPE); |
| 5080 | } |
Craig Mautner | ae7ecab | 2013-09-18 11:48:14 -0700 | [diff] [blame] | 5081 | } |
Craig Mautner | de4ef02 | 2013-04-07 19:01:33 -0700 | [diff] [blame] | 5082 | mTaskHistory.remove(task); |
Craig Mautner | 21d24a2 | 2014-04-23 11:45:37 -0700 | [diff] [blame] | 5083 | updateTaskMovement(task, true); |
Craig Mautner | 41db4a7 | 2014-05-07 17:20:56 -0700 | [diff] [blame] | 5084 | |
Wale Ogunwale | 06579d6 | 2016-04-30 15:29:06 -0700 | [diff] [blame] | 5085 | if (mode == REMOVE_TASK_MODE_DESTROYING && task.mActivities.isEmpty()) { |
Amith Yamasani | 0af6fa7 | 2016-01-17 15:36:19 -0800 | [diff] [blame] | 5086 | // TODO: VI what about activity? |
Craig Mautner | 41db4a7 | 2014-05-07 17:20:56 -0700 | [diff] [blame] | 5087 | final boolean isVoiceSession = task.voiceSession != null; |
| 5088 | if (isVoiceSession) { |
| 5089 | try { |
| 5090 | task.voiceSession.taskFinished(task.intent, task.taskId); |
| 5091 | } catch (RemoteException e) { |
| 5092 | } |
Dianne Hackborn | c03c916 | 2014-05-02 10:45:59 -0700 | [diff] [blame] | 5093 | } |
Craig Mautner | 41db4a7 | 2014-05-07 17:20:56 -0700 | [diff] [blame] | 5094 | if (task.autoRemoveFromRecents() || isVoiceSession) { |
| 5095 | // Task creator asked to remove this when done, or this task was a voice |
| 5096 | // interaction, so it should not remain on the recent tasks list. |
Wale Ogunwale | c82f2f5 | 2014-12-09 09:32:50 -0800 | [diff] [blame] | 5097 | mRecentTasks.remove(task); |
Winson Chung | 740c3ac | 2014-11-12 16:14:38 -0800 | [diff] [blame] | 5098 | task.removedFromRecents(); |
Craig Mautner | 41db4a7 | 2014-05-07 17:20:56 -0700 | [diff] [blame] | 5099 | } |
Dianne Hackborn | 91097de | 2014-04-04 18:02:06 -0700 | [diff] [blame] | 5100 | } |
Craig Mautner | 04a0ea6 | 2014-01-13 12:51:26 -0800 | [diff] [blame] | 5101 | |
| 5102 | if (mTaskHistory.isEmpty()) { |
Wale Ogunwale | ee006da | 2015-03-30 14:49:25 -0700 | [diff] [blame] | 5103 | if (DEBUG_STACK) Slog.i(TAG_STACK, "removeTask: removing stack=" + this); |
Wale Ogunwale | 06579d6 | 2016-04-30 15:29:06 -0700 | [diff] [blame] | 5104 | // We only need to adjust focused stack if this stack is in focus and we are not in the |
| 5105 | // process of moving the task to the top of the stack that will be focused. |
| 5106 | if (isOnHomeDisplay() && mode != REMOVE_TASK_MODE_MOVING_TO_TOP |
| 5107 | && mStackSupervisor.isFocusedStack(this)) { |
Wale Ogunwale | d697cea | 2015-02-20 17:19:49 -0800 | [diff] [blame] | 5108 | String myReason = reason + " leftTaskHistoryEmpty"; |
Wale Ogunwale | d34e80c | 2016-03-23 17:08:44 -0700 | [diff] [blame] | 5109 | if (mFullscreen |
| 5110 | || !adjustFocusToNextFocusableStackLocked( |
| 5111 | task.getTaskToReturnTo(), myReason)) { |
Wale Ogunwale | 925d0d1 | 2015-09-23 15:40:07 -0700 | [diff] [blame] | 5112 | mStackSupervisor.moveHomeStackToFront(myReason); |
Wale Ogunwale | d697cea | 2015-02-20 17:19:49 -0800 | [diff] [blame] | 5113 | } |
Craig Mautner | 04a0ea6 | 2014-01-13 12:51:26 -0800 | [diff] [blame] | 5114 | } |
Craig Mautner | 593a4e6 | 2014-01-15 17:55:51 -0800 | [diff] [blame] | 5115 | if (mStacks != null) { |
| 5116 | mStacks.remove(this); |
| 5117 | mStacks.add(0, this); |
| 5118 | } |
Wale Ogunwale | 925d0d1 | 2015-09-23 15:40:07 -0700 | [diff] [blame] | 5119 | if (!isHomeStack()) { |
Wale Ogunwale | 49853bf | 2015-02-23 09:24:42 -0800 | [diff] [blame] | 5120 | mActivityContainer.onTaskListEmptyLocked(); |
| 5121 | } |
Craig Mautner | 04a0ea6 | 2014-01-13 12:51:26 -0800 | [diff] [blame] | 5122 | } |
Wale Ogunwale | 04f4d6b | 2015-03-11 09:23:25 -0700 | [diff] [blame] | 5123 | |
| 5124 | task.stack = null; |
Craig Mautner | 0247fc8 | 2013-02-28 14:32:06 -0800 | [diff] [blame] | 5125 | } |
| 5126 | |
Dianne Hackborn | 91097de | 2014-04-04 18:02:06 -0700 | [diff] [blame] | 5127 | TaskRecord createTaskRecord(int taskId, ActivityInfo info, Intent intent, |
| 5128 | IVoiceInteractionSession voiceSession, IVoiceInteractor voiceInteractor, |
| 5129 | boolean toTop) { |
Craig Mautner | 21d24a2 | 2014-04-23 11:45:37 -0700 | [diff] [blame] | 5130 | TaskRecord task = new TaskRecord(mService, taskId, info, intent, voiceSession, |
| 5131 | voiceInteractor); |
Chong Zhang | 0fa656b | 2015-08-31 15:17:21 -0700 | [diff] [blame] | 5132 | // add the task to stack first, mTaskPositioner might need the stack association |
Wale Ogunwale | 5f98609 | 2015-12-04 15:35:38 -0800 | [diff] [blame] | 5133 | addTask(task, toTop, "createTaskRecord"); |
Chong Zhang | 75b3720 | 2015-12-04 14:16:36 -0800 | [diff] [blame] | 5134 | final boolean isLockscreenShown = mService.mLockScreenShown == LOCK_SCREEN_SHOWN; |
Andrii Kulian | 2e751b8 | 2016-03-16 16:59:32 -0700 | [diff] [blame] | 5135 | if (!layoutTaskInStack(task, info.windowLayout) && mBounds != null && task.isResizeable() |
Chong Zhang | 75b3720 | 2015-12-04 14:16:36 -0800 | [diff] [blame] | 5136 | && !isLockscreenShown) { |
Wale Ogunwale | a6e902e | 2015-09-21 18:37:15 -0700 | [diff] [blame] | 5137 | task.updateOverrideConfiguration(mBounds); |
Filip Gruszczynski | e5390e7 | 2015-08-18 16:39:00 -0700 | [diff] [blame] | 5138 | } |
Craig Mautner | 5d9c7be | 2013-02-15 14:02:56 -0800 | [diff] [blame] | 5139 | return task; |
| 5140 | } |
Craig Mautner | c00204b | 2013-03-05 15:02:14 -0800 | [diff] [blame] | 5141 | |
Andrii Kulian | 2e751b8 | 2016-03-16 16:59:32 -0700 | [diff] [blame] | 5142 | boolean layoutTaskInStack(TaskRecord task, ActivityInfo.WindowLayout windowLayout) { |
Wale Ogunwale | 935e502 | 2015-11-10 12:36:10 -0800 | [diff] [blame] | 5143 | if (mTaskPositioner == null) { |
| 5144 | return false; |
| 5145 | } |
Andrii Kulian | 2e751b8 | 2016-03-16 16:59:32 -0700 | [diff] [blame] | 5146 | mTaskPositioner.updateDefaultBounds(task, mTaskHistory, windowLayout); |
Wale Ogunwale | 935e502 | 2015-11-10 12:36:10 -0800 | [diff] [blame] | 5147 | return true; |
| 5148 | } |
| 5149 | |
Craig Mautner | c00204b | 2013-03-05 15:02:14 -0800 | [diff] [blame] | 5150 | ArrayList<TaskRecord> getAllTasks() { |
Wale Ogunwale | 9d3de4c | 2015-02-01 16:49:44 -0800 | [diff] [blame] | 5151 | return new ArrayList<>(mTaskHistory); |
Craig Mautner | c00204b | 2013-03-05 15:02:14 -0800 | [diff] [blame] | 5152 | } |
| 5153 | |
Wale Ogunwale | 5f98609 | 2015-12-04 15:35:38 -0800 | [diff] [blame] | 5154 | void addTask(final TaskRecord task, final boolean toTop, String reason) { |
Wale Ogunwale | 06579d6 | 2016-04-30 15:29:06 -0700 | [diff] [blame] | 5155 | final ActivityStack prevStack = preAddTask(task, reason, toTop); |
Wale Ogunwale | 5f98609 | 2015-12-04 15:35:38 -0800 | [diff] [blame] | 5156 | |
Craig Mautner | c00204b | 2013-03-05 15:02:14 -0800 | [diff] [blame] | 5157 | task.stack = this; |
| 5158 | if (toTop) { |
Wale Ogunwale | 3fcb4a8 | 2015-04-06 14:00:13 -0700 | [diff] [blame] | 5159 | insertTaskAtTop(task, null); |
Craig Mautner | c00204b | 2013-03-05 15:02:14 -0800 | [diff] [blame] | 5160 | } else { |
| 5161 | mTaskHistory.add(0, task); |
Craig Mautner | 21d24a2 | 2014-04-23 11:45:37 -0700 | [diff] [blame] | 5162 | updateTaskMovement(task, false); |
Craig Mautner | c00204b | 2013-03-05 15:02:14 -0800 | [diff] [blame] | 5163 | } |
Wale Ogunwale | 5f98609 | 2015-12-04 15:35:38 -0800 | [diff] [blame] | 5164 | postAddTask(task, prevStack); |
Craig Mautner | c00204b | 2013-03-05 15:02:14 -0800 | [diff] [blame] | 5165 | } |
| 5166 | |
Wale Ogunwale | 5f98609 | 2015-12-04 15:35:38 -0800 | [diff] [blame] | 5167 | void positionTask(final TaskRecord task, int position) { |
Jorim Jaggi | 023da53 | 2016-04-20 22:42:32 -0700 | [diff] [blame] | 5168 | final ActivityRecord topRunningActivity = task.topRunningActivityLocked(); |
| 5169 | final boolean wasResumed = topRunningActivity == task.stack.mResumedActivity; |
Wale Ogunwale | ed811d7 | 2016-05-06 08:41:19 -0700 | [diff] [blame] | 5170 | final ActivityStack prevStack = preAddTask(task, "positionTask", !ON_TOP); |
Wale Ogunwale | ddc1cb2 | 2015-07-25 19:23:04 -0700 | [diff] [blame] | 5171 | task.stack = this; |
| 5172 | insertTaskAtPosition(task, position); |
Wale Ogunwale | 5f98609 | 2015-12-04 15:35:38 -0800 | [diff] [blame] | 5173 | postAddTask(task, prevStack); |
Jorim Jaggi | 023da53 | 2016-04-20 22:42:32 -0700 | [diff] [blame] | 5174 | if (wasResumed) { |
| 5175 | if (mResumedActivity != null) { |
| 5176 | Log.wtf(TAG, "mResumedActivity was already set when moving mResumedActivity from" |
| 5177 | + " other stack to this stack mResumedActivity=" + mResumedActivity |
| 5178 | + " other mResumedActivity=" + topRunningActivity); |
| 5179 | } |
| 5180 | mResumedActivity = topRunningActivity; |
| 5181 | } |
Wale Ogunwale | 5f98609 | 2015-12-04 15:35:38 -0800 | [diff] [blame] | 5182 | } |
| 5183 | |
Wale Ogunwale | 06579d6 | 2016-04-30 15:29:06 -0700 | [diff] [blame] | 5184 | private ActivityStack preAddTask(TaskRecord task, String reason, boolean toTop) { |
Wale Ogunwale | 5f98609 | 2015-12-04 15:35:38 -0800 | [diff] [blame] | 5185 | final ActivityStack prevStack = task.stack; |
| 5186 | if (prevStack != null && prevStack != this) { |
Wale Ogunwale | 06579d6 | 2016-04-30 15:29:06 -0700 | [diff] [blame] | 5187 | prevStack.removeTask(task, reason, |
| 5188 | toTop ? REMOVE_TASK_MODE_MOVING_TO_TOP : REMOVE_TASK_MODE_MOVING); |
Wale Ogunwale | 5f98609 | 2015-12-04 15:35:38 -0800 | [diff] [blame] | 5189 | } |
| 5190 | return prevStack; |
| 5191 | } |
| 5192 | |
| 5193 | private void postAddTask(TaskRecord task, ActivityStack prevStack) { |
| 5194 | if (prevStack != null) { |
Andrii Kulian | 933076d | 2016-03-29 17:04:42 -0700 | [diff] [blame] | 5195 | mStackSupervisor.scheduleReportPictureInPictureModeChangedIfNeeded(task, prevStack); |
Wale Ogunwale | 5f98609 | 2015-12-04 15:35:38 -0800 | [diff] [blame] | 5196 | } else if (task.voiceSession != null) { |
Wale Ogunwale | ddc1cb2 | 2015-07-25 19:23:04 -0700 | [diff] [blame] | 5197 | try { |
| 5198 | task.voiceSession.taskStarted(task.intent, task.taskId); |
| 5199 | } catch (RemoteException e) { |
| 5200 | } |
| 5201 | } |
| 5202 | } |
| 5203 | |
Filip Gruszczynski | e5390e7 | 2015-08-18 16:39:00 -0700 | [diff] [blame] | 5204 | void addConfigOverride(ActivityRecord r, TaskRecord task) { |
Filip Gruszczynski | dce2d16 | 2016-01-12 15:40:13 -0800 | [diff] [blame] | 5205 | final Rect bounds = task.updateOverrideConfigurationFromLaunchBounds(); |
Amith Yamasani | 0af6fa7 | 2016-01-17 15:36:19 -0800 | [diff] [blame] | 5206 | // TODO: VI deal with activity |
Filip Gruszczynski | ebcc875 | 2015-08-25 16:51:05 -0700 | [diff] [blame] | 5207 | mWindowManager.addAppToken(task.mActivities.indexOf(r), r.appToken, |
| 5208 | r.task.taskId, mStackId, r.info.screenOrientation, r.fullscreen, |
Wale Ogunwale | 6cae765 | 2015-12-26 07:36:26 -0800 | [diff] [blame] | 5209 | (r.info.flags & FLAG_SHOW_FOR_ALL_USERS) != 0, r.userId, r.info.configChanges, |
| 5210 | task.voiceSession != null, r.mLaunchTaskBehind, bounds, task.mOverrideConfig, |
Yorke Lee | 0e85247 | 2016-06-15 10:03:18 -0700 | [diff] [blame] | 5211 | task.mResizeMode, r.isAlwaysFocusable(), task.isHomeTask(), |
Robert Carr | fd10cd1 | 2016-06-29 16:41:50 -0700 | [diff] [blame] | 5212 | r.appInfo.targetSdkVersion, r.mRotationAnimationHint); |
Wale Ogunwale | 706ed79 | 2015-08-02 10:29:44 -0700 | [diff] [blame] | 5213 | r.taskConfigOverride = task.mOverrideConfig; |
| 5214 | } |
| 5215 | |
Wale Ogunwale | d046a01 | 2015-12-24 13:05:59 -0800 | [diff] [blame] | 5216 | void moveToFrontAndResumeStateIfNeeded( |
| 5217 | ActivityRecord r, boolean moveToFront, boolean setResume, String reason) { |
| 5218 | if (!moveToFront) { |
| 5219 | return; |
Wale Ogunwale | 079a004 | 2015-10-24 11:44:07 -0700 | [diff] [blame] | 5220 | } |
Wale Ogunwale | d046a01 | 2015-12-24 13:05:59 -0800 | [diff] [blame] | 5221 | |
| 5222 | // If the activity owns the last resumed activity, transfer that together, |
| 5223 | // so that we don't resume the same activity again in the new stack. |
| 5224 | // Apps may depend on onResume()/onPause() being called in pairs. |
| 5225 | if (setResume) { |
| 5226 | mResumedActivity = r; |
| 5227 | } |
| 5228 | // Move the stack in which we are placing the activity to the front. The call will also |
| 5229 | // make sure the activity focus is set. |
| 5230 | moveToFront(reason); |
Wale Ogunwale | 079a004 | 2015-10-24 11:44:07 -0700 | [diff] [blame] | 5231 | } |
| 5232 | |
| 5233 | /** |
| 5234 | * Moves the input activity from its current stack to this one. |
| 5235 | * NOTE: The current task of the activity isn't moved to this stack. Instead a new task is |
| 5236 | * created on this stack which the activity is added to. |
| 5237 | * */ |
| 5238 | void moveActivityToStack(ActivityRecord r) { |
| 5239 | final ActivityStack prevStack = r.task.stack; |
| 5240 | if (prevStack.mStackId == mStackId) { |
| 5241 | // You are already in the right stack silly... |
| 5242 | return; |
| 5243 | } |
| 5244 | |
Wale Ogunwale | 1e60e0c | 2015-10-28 13:36:10 -0700 | [diff] [blame] | 5245 | final boolean wasFocused = mStackSupervisor.isFocusedStack(prevStack) |
Wale Ogunwale | 079a004 | 2015-10-24 11:44:07 -0700 | [diff] [blame] | 5246 | && (mStackSupervisor.topRunningActivityLocked() == r); |
| 5247 | final boolean wasResumed = wasFocused && (prevStack.mResumedActivity == r); |
| 5248 | |
| 5249 | final TaskRecord task = createTaskRecord( |
Suprabh Shukla | 09a88f5 | 2015-12-02 14:36:31 -0800 | [diff] [blame] | 5250 | mStackSupervisor.getNextTaskIdForUserLocked(r.userId), |
| 5251 | r.info, r.intent, null, null, true); |
Wale Ogunwale | 079a004 | 2015-10-24 11:44:07 -0700 | [diff] [blame] | 5252 | r.setTask(task, null); |
| 5253 | task.addActivityToTop(r); |
| 5254 | setAppTask(r, task); |
Andrii Kulian | 933076d | 2016-03-29 17:04:42 -0700 | [diff] [blame] | 5255 | mStackSupervisor.scheduleReportPictureInPictureModeChangedIfNeeded(task, prevStack); |
Wale Ogunwale | d046a01 | 2015-12-24 13:05:59 -0800 | [diff] [blame] | 5256 | moveToFrontAndResumeStateIfNeeded(r, wasFocused, wasResumed, "moveActivityToStack"); |
| 5257 | if (wasResumed) { |
| 5258 | prevStack.mResumedActivity = null; |
| 5259 | } |
Wale Ogunwale | 079a004 | 2015-10-24 11:44:07 -0700 | [diff] [blame] | 5260 | } |
| 5261 | |
Wale Ogunwale | 706ed79 | 2015-08-02 10:29:44 -0700 | [diff] [blame] | 5262 | private void setAppTask(ActivityRecord r, TaskRecord task) { |
Filip Gruszczynski | dce2d16 | 2016-01-12 15:40:13 -0800 | [diff] [blame] | 5263 | final Rect bounds = task.updateOverrideConfigurationFromLaunchBounds(); |
Wale Ogunwale | b1faf60 | 2016-01-27 09:12:31 -0800 | [diff] [blame] | 5264 | mWindowManager.setAppTask(r.appToken, task.taskId, mStackId, bounds, task.mOverrideConfig, |
| 5265 | task.mResizeMode, task.isHomeTask()); |
Wale Ogunwale | 706ed79 | 2015-08-02 10:29:44 -0700 | [diff] [blame] | 5266 | r.taskConfigOverride = task.mOverrideConfig; |
| 5267 | } |
| 5268 | |
Craig Mautner | c00204b | 2013-03-05 15:02:14 -0800 | [diff] [blame] | 5269 | public int getStackId() { |
| 5270 | return mStackId; |
| 5271 | } |
Craig Mautner | de4ef02 | 2013-04-07 19:01:33 -0700 | [diff] [blame] | 5272 | |
| 5273 | @Override |
| 5274 | public String toString() { |
Dianne Hackborn | 2a272d4 | 2013-10-16 13:34:33 -0700 | [diff] [blame] | 5275 | return "ActivityStack{" + Integer.toHexString(System.identityHashCode(this)) |
| 5276 | + " stackId=" + mStackId + ", " + mTaskHistory.size() + " tasks}"; |
Craig Mautner | de4ef02 | 2013-04-07 19:01:33 -0700 | [diff] [blame] | 5277 | } |
Wale Ogunwale | 60454db | 2015-01-23 16:05:07 -0800 | [diff] [blame] | 5278 | |
Craig Mautner | 15df08a | 2015-04-01 12:17:18 -0700 | [diff] [blame] | 5279 | void onLockTaskPackagesUpdatedLocked() { |
| 5280 | for (int taskNdx = mTaskHistory.size() - 1; taskNdx >= 0; --taskNdx) { |
| 5281 | mTaskHistory.get(taskNdx).setLockTaskAuth(); |
| 5282 | } |
| 5283 | } |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 5284 | } |