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; |
Jorim Jaggi | af80db4 | 2016-04-07 19:19:15 -0700 | [diff] [blame] | 129 | import com.android.server.wm.WindowManagerService; |
| 130 | |
Craig Mautner | cae015f | 2013-02-08 14:31:27 -0800 | [diff] [blame] | 131 | import java.io.FileDescriptor; |
Craig Mautner | cae015f | 2013-02-08 14:31:27 -0800 | [diff] [blame] | 132 | import java.io.PrintWriter; |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 133 | import java.lang.ref.WeakReference; |
| 134 | import java.util.ArrayList; |
| 135 | import java.util.Iterator; |
| 136 | import java.util.List; |
Kenny Root | e6585b3 | 2013-12-13 12:00:26 -0800 | [diff] [blame] | 137 | import java.util.Objects; |
Wale Ogunwale | 540e123 | 2015-05-01 15:35:39 -0700 | [diff] [blame] | 138 | import java.util.Set; |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 139 | |
| 140 | /** |
| 141 | * State and management of a single stack of activities. |
| 142 | */ |
Dianne Hackborn | 0c5001d | 2011-04-12 18:16:08 -0700 | [diff] [blame] | 143 | final class ActivityStack { |
Craig Mautner | 5d9c7be | 2013-02-15 14:02:56 -0800 | [diff] [blame] | 144 | |
Wale Ogunwale | e23149f | 2015-03-06 15:39:44 -0800 | [diff] [blame] | 145 | private static final String TAG = TAG_WITH_CLASS_NAME ? "ActivityStack" : TAG_AM; |
Wale Ogunwale | 0fc365c | 2015-05-25 19:35:42 -0700 | [diff] [blame] | 146 | private static final String TAG_ADD_REMOVE = TAG + POSTFIX_ADD_REMOVE; |
| 147 | private static final String TAG_APP = TAG + POSTFIX_APP; |
Wale Ogunwale | e23149f | 2015-03-06 15:39:44 -0800 | [diff] [blame] | 148 | private static final String TAG_CLEANUP = TAG + POSTFIX_CLEANUP; |
Wale Ogunwale | 3ab9a27 | 2015-03-16 09:55:45 -0700 | [diff] [blame] | 149 | private static final String TAG_CONFIGURATION = TAG + POSTFIX_CONFIGURATION; |
Wale Ogunwale | 0fc365c | 2015-05-25 19:35:42 -0700 | [diff] [blame] | 150 | private static final String TAG_CONTAINERS = TAG + POSTFIX_CONTAINERS; |
Wale Ogunwale | ee006da | 2015-03-30 14:49:25 -0700 | [diff] [blame] | 151 | private static final String TAG_PAUSE = TAG + POSTFIX_PAUSE; |
Wale Ogunwale | 0fc365c | 2015-05-25 19:35:42 -0700 | [diff] [blame] | 152 | private static final String TAG_RELEASE = TAG + POSTFIX_RELEASE; |
Wale Ogunwale | ee006da | 2015-03-30 14:49:25 -0700 | [diff] [blame] | 153 | private static final String TAG_RESULTS = TAG + POSTFIX_RESULTS; |
Wale Ogunwale | 0fc365c | 2015-05-25 19:35:42 -0700 | [diff] [blame] | 154 | private static final String TAG_SAVED_STATE = TAG + POSTFIX_SAVED_STATE; |
| 155 | private static final String TAG_SCREENSHOTS = TAG + POSTFIX_SCREENSHOTS; |
Wale Ogunwale | ee006da | 2015-03-30 14:49:25 -0700 | [diff] [blame] | 156 | private static final String TAG_STACK = TAG + POSTFIX_STACK; |
Wale Ogunwale | 0fc365c | 2015-05-25 19:35:42 -0700 | [diff] [blame] | 157 | private static final String TAG_STATES = TAG + POSTFIX_STATES; |
Wale Ogunwale | ee006da | 2015-03-30 14:49:25 -0700 | [diff] [blame] | 158 | private static final String TAG_SWITCH = TAG + POSTFIX_SWITCH; |
| 159 | private static final String TAG_TASKS = TAG + POSTFIX_TASKS; |
| 160 | private static final String TAG_TRANSITION = TAG + POSTFIX_TRANSITION; |
| 161 | private static final String TAG_USER_LEAVING = TAG + POSTFIX_USER_LEAVING; |
| 162 | private static final String TAG_VISIBILITY = TAG + POSTFIX_VISIBILITY; |
Wale Ogunwale | 3ab9a27 | 2015-03-16 09:55:45 -0700 | [diff] [blame] | 163 | |
Dianne Hackborn | 2a29b3a | 2012-03-15 15:48:38 -0700 | [diff] [blame] | 164 | // Ticks during which we check progress while waiting for an app to launch. |
| 165 | static final int LAUNCH_TICK = 500; |
| 166 | |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 167 | // How long we wait until giving up on the last activity to pause. This |
| 168 | // is short because it directly impacts the responsiveness of starting the |
| 169 | // next activity. |
| 170 | static final int PAUSE_TIMEOUT = 500; |
| 171 | |
Dianne Hackborn | 162bc0e | 2012-04-09 14:06:16 -0700 | [diff] [blame] | 172 | // How long we wait for the activity to tell us it has stopped before |
| 173 | // giving up. This is a good amount of time because we really need this |
| 174 | // from the application in order to get its saved state. |
Wale Ogunwale | e4a0c57 | 2015-06-30 08:40:31 -0700 | [diff] [blame] | 175 | static final int STOP_TIMEOUT = 10 * 1000; |
Dianne Hackborn | 162bc0e | 2012-04-09 14:06:16 -0700 | [diff] [blame] | 176 | |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 177 | // How long we wait until giving up on an activity telling us it has |
| 178 | // finished destroying itself. |
Wale Ogunwale | e4a0c57 | 2015-06-30 08:40:31 -0700 | [diff] [blame] | 179 | static final int DESTROY_TIMEOUT = 10 * 1000; |
Craig Mautner | d74f7d7 | 2013-02-26 13:41:02 -0800 | [diff] [blame] | 180 | |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 181 | // 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] | 182 | // disabled. |
| 183 | static final long ACTIVITY_INACTIVE_RESET_TIME = 0; |
Craig Mautner | d74f7d7 | 2013-02-26 13:41:02 -0800 | [diff] [blame] | 184 | |
Dianne Hackborn | 0dad364 | 2010-09-09 21:25:35 -0700 | [diff] [blame] | 185 | // How long between activity launches that we consider safe to not warn |
| 186 | // the user about an unexpected activity being launched on top. |
Wale Ogunwale | e4a0c57 | 2015-06-30 08:40:31 -0700 | [diff] [blame] | 187 | static final long START_WARN_TIME = 5 * 1000; |
Craig Mautner | d74f7d7 | 2013-02-26 13:41:02 -0800 | [diff] [blame] | 188 | |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 189 | // Set to false to disable the preview that is shown while a new activity |
| 190 | // is being started. |
| 191 | static final boolean SHOW_APP_STARTING_PREVIEW = true; |
Craig Mautner | 5d9c7be | 2013-02-15 14:02:56 -0800 | [diff] [blame] | 192 | |
Craig Mautner | 5eda9b3 | 2013-07-02 11:58:16 -0700 | [diff] [blame] | 193 | // How long to wait for all background Activities to redraw following a call to |
| 194 | // convertToTranslucent(). |
| 195 | static final long TRANSLUCENT_CONVERSION_TIMEOUT = 2000; |
| 196 | |
Filip Gruszczynski | ef2f72b | 2015-12-04 14:52:25 -0800 | [diff] [blame] | 197 | // How many activities have to be scheduled to stop to force a stop pass. |
| 198 | private static final int MAX_STOPPING_TO_FORCE = 3; |
| 199 | |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 200 | enum ActivityState { |
| 201 | INITIALIZING, |
| 202 | RESUMED, |
| 203 | PAUSING, |
| 204 | PAUSED, |
| 205 | STOPPING, |
| 206 | STOPPED, |
| 207 | FINISHING, |
| 208 | DESTROYING, |
| 209 | DESTROYED |
| 210 | } |
| 211 | |
Filip Gruszczynski | 0e381e2 | 2016-01-14 16:31:33 -0800 | [diff] [blame] | 212 | // Stack is not considered visible. |
| 213 | static final int STACK_INVISIBLE = 0; |
| 214 | // Stack is considered visible |
| 215 | static final int STACK_VISIBLE = 1; |
| 216 | // Stack is considered visible, but only becuase it has activity that is visible behind other |
| 217 | // activities and there is a specific combination of stacks. |
| 218 | static final int STACK_VISIBLE_ACTIVITY_BEHIND = 2; |
| 219 | |
Wale Ogunwale | 06579d6 | 2016-04-30 15:29:06 -0700 | [diff] [blame] | 220 | /* The various modes for the method {@link #removeTask}. */ |
| 221 | // Task is being completely removed from all stacks in the system. |
| 222 | static final int REMOVE_TASK_MODE_DESTROYING = 0; |
| 223 | // Task is being removed from this stack so we can add it to another stack. In the case we are |
| 224 | // moving we don't want to perform some operations on the task like removing it from window |
| 225 | // manager or recents. |
| 226 | static final int REMOVE_TASK_MODE_MOVING = 1; |
| 227 | // Similar to {@link #REMOVE_TASK_MODE_MOVING} and the task will be added to the top of its new |
| 228 | // stack and the new stack will be on top of all stacks. |
| 229 | static final int REMOVE_TASK_MODE_MOVING_TO_TOP = 2; |
| 230 | |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 231 | final ActivityManagerService mService; |
Craig Mautner | ce5f3cb | 2013-04-22 08:58:54 -0700 | [diff] [blame] | 232 | final WindowManagerService mWindowManager; |
Wale Ogunwale | c82f2f5 | 2014-12-09 09:32:50 -0800 | [diff] [blame] | 233 | private final RecentTasks mRecentTasks; |
Craig Mautner | d74f7d7 | 2013-02-26 13:41:02 -0800 | [diff] [blame] | 234 | |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 235 | /** |
| 236 | * The back history of all previous (and possibly still |
Craig Mautner | 5d9c7be | 2013-02-15 14:02:56 -0800 | [diff] [blame] | 237 | * running) activities. It contains #TaskRecord objects. |
| 238 | */ |
Todd Kennedy | 39bfee5 | 2016-02-24 10:28:21 -0800 | [diff] [blame] | 239 | private final ArrayList<TaskRecord> mTaskHistory = new ArrayList<>(); |
Craig Mautner | 5d9c7be | 2013-02-15 14:02:56 -0800 | [diff] [blame] | 240 | |
| 241 | /** |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 242 | * List of running activities, sorted by recent usage. |
| 243 | * The first entry in the list is the least recently used. |
| 244 | * It contains HistoryRecord objects. |
| 245 | */ |
Wale Ogunwale | 53a29a9 | 2015-02-23 15:42:52 -0800 | [diff] [blame] | 246 | final ArrayList<ActivityRecord> mLRUActivities = new ArrayList<>(); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 247 | |
| 248 | /** |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 249 | * Animations that for the current transition have requested not to |
| 250 | * be considered for the transition animation. |
| 251 | */ |
Wale Ogunwale | 53a29a9 | 2015-02-23 15:42:52 -0800 | [diff] [blame] | 252 | final ArrayList<ActivityRecord> mNoAnimActivities = new ArrayList<>(); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 253 | |
| 254 | /** |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 255 | * When we are in the process of pausing an activity, before starting the |
| 256 | * next one, this variable holds the activity that is currently being paused. |
| 257 | */ |
Dianne Hackborn | 621e2fe | 2012-02-16 17:07:33 -0800 | [diff] [blame] | 258 | ActivityRecord mPausingActivity = null; |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 259 | |
| 260 | /** |
| 261 | * This is the last activity that we put into the paused state. This is |
| 262 | * used to determine if we need to do an activity transition while sleeping, |
| 263 | * when we normally hold the top activity paused. |
| 264 | */ |
| 265 | ActivityRecord mLastPausedActivity = null; |
| 266 | |
| 267 | /** |
Craig Mautner | 0f92274 | 2013-08-06 08:44:42 -0700 | [diff] [blame] | 268 | * Activities that specify No History must be removed once the user navigates away from them. |
| 269 | * If the device goes to sleep with such an activity in the paused state then we save it here |
| 270 | * and finish it later if another activity replaces it on wakeup. |
| 271 | */ |
| 272 | ActivityRecord mLastNoHistoryActivity = null; |
| 273 | |
| 274 | /** |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 275 | * Current activity that is resumed, or null if there is none. |
| 276 | */ |
| 277 | ActivityRecord mResumedActivity = null; |
Craig Mautner | d74f7d7 | 2013-02-26 13:41:02 -0800 | [diff] [blame] | 278 | |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 279 | /** |
Dianne Hackborn | 0dad364 | 2010-09-09 21:25:35 -0700 | [diff] [blame] | 280 | * This is the last activity that has been started. It is only used to |
| 281 | * identify when multiple activities are started at once so that the user |
| 282 | * can be warned they may not be in the activity they think they are. |
| 283 | */ |
| 284 | ActivityRecord mLastStartedActivity = null; |
Craig Mautner | d74f7d7 | 2013-02-26 13:41:02 -0800 | [diff] [blame] | 285 | |
Craig Mautner | 5eda9b3 | 2013-07-02 11:58:16 -0700 | [diff] [blame] | 286 | // The topmost Activity passed to convertToTranslucent(). When non-null it means we are |
| 287 | // waiting for all Activities in mUndrawnActivitiesBelowTopTranslucent to be removed as they |
| 288 | // are drawn. When the last member of mUndrawnActivitiesBelowTopTranslucent is removed the |
| 289 | // Activity in mTranslucentActivityWaiting is notified via |
| 290 | // Activity.onTranslucentConversionComplete(false). If a timeout occurs prior to the last |
| 291 | // background activity being drawn then the same call will be made with a true value. |
| 292 | ActivityRecord mTranslucentActivityWaiting = null; |
Wale Ogunwale | e4a0c57 | 2015-06-30 08:40:31 -0700 | [diff] [blame] | 293 | private ArrayList<ActivityRecord> mUndrawnActivitiesBelowTopTranslucent = new ArrayList<>(); |
Craig Mautner | 5eda9b3 | 2013-07-02 11:58:16 -0700 | [diff] [blame] | 294 | |
Dianne Hackborn | 0dad364 | 2010-09-09 21:25:35 -0700 | [diff] [blame] | 295 | /** |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 296 | * Set when we know we are going to be calling updateConfiguration() |
| 297 | * soon, so want to skip intermediate config checks. |
| 298 | */ |
| 299 | boolean mConfigWillChange; |
| 300 | |
Wale Ogunwale | e4a0c57 | 2015-06-30 08:40:31 -0700 | [diff] [blame] | 301 | // 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] | 302 | boolean mFullscreen = true; |
Wale Ogunwale | b34a7ad | 2015-08-14 11:05:30 -0700 | [diff] [blame] | 303 | // Current bounds of the stack or null if fullscreen. |
| 304 | Rect mBounds = null; |
Todd Kennedy | aab56db | 2015-01-30 09:39:53 -0800 | [diff] [blame] | 305 | |
Jorim Jaggi | 192086e | 2016-03-11 17:17:03 +0100 | [diff] [blame] | 306 | boolean mUpdateBoundsDeferred; |
| 307 | boolean mUpdateBoundsDeferredCalled; |
| 308 | final Rect mDeferredBounds = new Rect(); |
| 309 | final Rect mDeferredTaskBounds = new Rect(); |
| 310 | final Rect mDeferredTaskInsetBounds = new Rect(); |
| 311 | |
Dianne Hackborn | 2286cdc | 2013-07-01 19:10:06 -0700 | [diff] [blame] | 312 | long mLaunchStartTime = 0; |
| 313 | long mFullyDrawnStartTime = 0; |
Craig Mautner | d74f7d7 | 2013-02-26 13:41:02 -0800 | [diff] [blame] | 314 | |
Craig Mautner | 858d8a6 | 2013-04-23 17:08:34 -0700 | [diff] [blame] | 315 | int mCurrentUser; |
Amith Yamasani | 742a671 | 2011-05-04 14:49:28 -0700 | [diff] [blame] | 316 | |
Craig Mautner | c00204b | 2013-03-05 15:02:14 -0800 | [diff] [blame] | 317 | final int mStackId; |
Craig Mautner | 4a1cb22 | 2013-12-04 16:14:06 -0800 | [diff] [blame] | 318 | final ActivityContainer mActivityContainer; |
Craig Mautner | e0a3884 | 2013-12-16 16:14:02 -0800 | [diff] [blame] | 319 | /** The other stacks, in order, on the attached display. Updated at attach/detach time. */ |
| 320 | ArrayList<ActivityStack> mStacks; |
| 321 | /** The attached Display's unique identifier, or -1 if detached */ |
| 322 | int mDisplayId; |
Craig Mautner | 4a1cb22 | 2013-12-04 16:14:06 -0800 | [diff] [blame] | 323 | |
Craig Mautner | 2708430 | 2013-03-25 08:05:25 -0700 | [diff] [blame] | 324 | /** Run all ActivityStacks through this */ |
| 325 | final ActivityStackSupervisor mStackSupervisor; |
| 326 | |
Filip Gruszczynski | e5390e7 | 2015-08-18 16:39:00 -0700 | [diff] [blame] | 327 | private final LaunchingTaskPositioner mTaskPositioner; |
| 328 | |
Craig Mautner | 7ea5bd4 | 2013-07-05 15:27:08 -0700 | [diff] [blame] | 329 | static final int PAUSE_TIMEOUT_MSG = ActivityManagerService.FIRST_ACTIVITY_STACK_MSG + 1; |
Craig Mautner | 0eea92c | 2013-05-16 13:35:39 -0700 | [diff] [blame] | 330 | static final int DESTROY_TIMEOUT_MSG = ActivityManagerService.FIRST_ACTIVITY_STACK_MSG + 2; |
| 331 | static final int LAUNCH_TICK_MSG = ActivityManagerService.FIRST_ACTIVITY_STACK_MSG + 3; |
| 332 | static final int STOP_TIMEOUT_MSG = ActivityManagerService.FIRST_ACTIVITY_STACK_MSG + 4; |
| 333 | static final int DESTROY_ACTIVITIES_MSG = ActivityManagerService.FIRST_ACTIVITY_STACK_MSG + 5; |
Craig Mautner | 5eda9b3 | 2013-07-02 11:58:16 -0700 | [diff] [blame] | 334 | static final int TRANSLUCENT_TIMEOUT_MSG = ActivityManagerService.FIRST_ACTIVITY_STACK_MSG + 6; |
Jose Lima | 4b6c669 | 2014-08-12 17:41:12 -0700 | [diff] [blame] | 335 | static final int RELEASE_BACKGROUND_RESOURCES_TIMEOUT_MSG = |
Craig Mautner | ee2e45a | 2014-06-27 12:10:03 -0700 | [diff] [blame] | 336 | ActivityManagerService.FIRST_ACTIVITY_STACK_MSG + 7; |
Dianne Hackborn | 755c8bf | 2012-05-07 15:06:09 -0700 | [diff] [blame] | 337 | |
| 338 | static class ScheduleDestroyArgs { |
| 339 | final ProcessRecord mOwner; |
Dianne Hackborn | 755c8bf | 2012-05-07 15:06:09 -0700 | [diff] [blame] | 340 | final String mReason; |
Craig Mautner | ee2e45a | 2014-06-27 12:10:03 -0700 | [diff] [blame] | 341 | ScheduleDestroyArgs(ProcessRecord owner, String reason) { |
Dianne Hackborn | 755c8bf | 2012-05-07 15:06:09 -0700 | [diff] [blame] | 342 | mOwner = owner; |
Dianne Hackborn | 755c8bf | 2012-05-07 15:06:09 -0700 | [diff] [blame] | 343 | mReason = reason; |
| 344 | } |
| 345 | } |
| 346 | |
Zoran Marceta | f958b32 | 2012-08-09 20:27:12 +0900 | [diff] [blame] | 347 | final Handler mHandler; |
| 348 | |
| 349 | final class ActivityStackHandler extends Handler { |
Wale Ogunwale | e23149f | 2015-03-06 15:39:44 -0800 | [diff] [blame] | 350 | |
Craig Mautner | c8143c6 | 2013-09-03 12:15:57 -0700 | [diff] [blame] | 351 | ActivityStackHandler(Looper looper) { |
Zoran Marceta | f958b32 | 2012-08-09 20:27:12 +0900 | [diff] [blame] | 352 | super(looper); |
| 353 | } |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 354 | |
Zoran Marceta | f958b32 | 2012-08-09 20:27:12 +0900 | [diff] [blame] | 355 | @Override |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 356 | public void handleMessage(Message msg) { |
| 357 | switch (msg.what) { |
| 358 | case PAUSE_TIMEOUT_MSG: { |
Dianne Hackborn | be70785 | 2011-11-11 14:32:10 -0800 | [diff] [blame] | 359 | ActivityRecord r = (ActivityRecord)msg.obj; |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 360 | // We don't at this point know if the activity is fullscreen, |
| 361 | // so we need to be conservative and assume it isn't. |
Dianne Hackborn | be70785 | 2011-11-11 14:32:10 -0800 | [diff] [blame] | 362 | Slog.w(TAG, "Activity pause timeout for " + r); |
Dianne Hackborn | 2a29b3a | 2012-03-15 15:48:38 -0700 | [diff] [blame] | 363 | synchronized (mService) { |
| 364 | if (r.app != null) { |
Craig Mautner | f7bfefb | 2013-05-16 17:30:44 -0700 | [diff] [blame] | 365 | mService.logAppTooSlow(r.app, r.pauseTime, "pausing " + r); |
Dianne Hackborn | 2a29b3a | 2012-03-15 15:48:38 -0700 | [diff] [blame] | 366 | } |
Dianne Hackborn | a4e102e | 2014-09-04 22:52:27 -0700 | [diff] [blame] | 367 | activityPausedLocked(r.appToken, true); |
Craig Mautner | d232895 | 2013-03-05 12:46:26 -0800 | [diff] [blame] | 368 | } |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 369 | } break; |
Dianne Hackborn | 2a29b3a | 2012-03-15 15:48:38 -0700 | [diff] [blame] | 370 | case LAUNCH_TICK_MSG: { |
| 371 | ActivityRecord r = (ActivityRecord)msg.obj; |
| 372 | synchronized (mService) { |
| 373 | if (r.continueLaunchTickingLocked()) { |
Craig Mautner | f7bfefb | 2013-05-16 17:30:44 -0700 | [diff] [blame] | 374 | mService.logAppTooSlow(r.app, r.launchTickTime, "launching " + r); |
Dianne Hackborn | 2a29b3a | 2012-03-15 15:48:38 -0700 | [diff] [blame] | 375 | } |
| 376 | } |
| 377 | } break; |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 378 | case DESTROY_TIMEOUT_MSG: { |
Dianne Hackborn | be70785 | 2011-11-11 14:32:10 -0800 | [diff] [blame] | 379 | ActivityRecord r = (ActivityRecord)msg.obj; |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 380 | // We don't at this point know if the activity is fullscreen, |
| 381 | // so we need to be conservative and assume it isn't. |
Dianne Hackborn | be70785 | 2011-11-11 14:32:10 -0800 | [diff] [blame] | 382 | Slog.w(TAG, "Activity destroy timeout for " + r); |
Craig Mautner | d232895 | 2013-03-05 12:46:26 -0800 | [diff] [blame] | 383 | synchronized (mService) { |
Craig Mautner | 299f960 | 2015-01-26 09:47:33 -0800 | [diff] [blame] | 384 | activityDestroyedLocked(r != null ? r.appToken : null, "destroyTimeout"); |
Craig Mautner | d232895 | 2013-03-05 12:46:26 -0800 | [diff] [blame] | 385 | } |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 386 | } break; |
Dianne Hackborn | 162bc0e | 2012-04-09 14:06:16 -0700 | [diff] [blame] | 387 | case STOP_TIMEOUT_MSG: { |
| 388 | ActivityRecord r = (ActivityRecord)msg.obj; |
| 389 | // We don't at this point know if the activity is fullscreen, |
| 390 | // so we need to be conservative and assume it isn't. |
| 391 | Slog.w(TAG, "Activity stop timeout for " + r); |
| 392 | synchronized (mService) { |
| 393 | if (r.isInHistory()) { |
| 394 | activityStoppedLocked(r, null, null, null); |
| 395 | } |
| 396 | } |
| 397 | } break; |
Dianne Hackborn | 755c8bf | 2012-05-07 15:06:09 -0700 | [diff] [blame] | 398 | case DESTROY_ACTIVITIES_MSG: { |
| 399 | ScheduleDestroyArgs args = (ScheduleDestroyArgs)msg.obj; |
| 400 | synchronized (mService) { |
Craig Mautner | ee2e45a | 2014-06-27 12:10:03 -0700 | [diff] [blame] | 401 | destroyActivitiesLocked(args.mOwner, args.mReason); |
Dianne Hackborn | 755c8bf | 2012-05-07 15:06:09 -0700 | [diff] [blame] | 402 | } |
Craig Mautner | 5eda9b3 | 2013-07-02 11:58:16 -0700 | [diff] [blame] | 403 | } break; |
| 404 | case TRANSLUCENT_TIMEOUT_MSG: { |
| 405 | synchronized (mService) { |
| 406 | notifyActivityDrawnLocked(null); |
| 407 | } |
| 408 | } break; |
Jose Lima | 4b6c669 | 2014-08-12 17:41:12 -0700 | [diff] [blame] | 409 | case RELEASE_BACKGROUND_RESOURCES_TIMEOUT_MSG: { |
Craig Mautner | ee2e45a | 2014-06-27 12:10:03 -0700 | [diff] [blame] | 410 | synchronized (mService) { |
Jose Lima | 4b6c669 | 2014-08-12 17:41:12 -0700 | [diff] [blame] | 411 | final ActivityRecord r = getVisibleBehindActivity(); |
| 412 | Slog.e(TAG, "Timeout waiting for cancelVisibleBehind player=" + r); |
Craig Mautner | ee2e45a | 2014-06-27 12:10:03 -0700 | [diff] [blame] | 413 | if (r != null) { |
| 414 | mService.killAppAtUsersRequest(r.app, null); |
| 415 | } |
| 416 | } |
| 417 | } break; |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 418 | } |
| 419 | } |
Craig Mautner | 4b71aa1 | 2012-12-27 17:20:01 -0800 | [diff] [blame] | 420 | } |
| 421 | |
Craig Mautner | 34b73df | 2014-01-12 21:11:08 -0800 | [diff] [blame] | 422 | int numActivities() { |
Craig Mautner | 000f002 | 2013-02-26 15:04:29 -0800 | [diff] [blame] | 423 | int count = 0; |
| 424 | for (int taskNdx = mTaskHistory.size() - 1; taskNdx >= 0; --taskNdx) { |
| 425 | count += mTaskHistory.get(taskNdx).mActivities.size(); |
| 426 | } |
| 427 | return count; |
| 428 | } |
| 429 | |
Wale Ogunwale | c82f2f5 | 2014-12-09 09:32:50 -0800 | [diff] [blame] | 430 | ActivityStack(ActivityStackSupervisor.ActivityContainer activityContainer, |
| 431 | RecentTasks recentTasks) { |
Craig Mautner | 4a1cb22 | 2013-12-04 16:14:06 -0800 | [diff] [blame] | 432 | mActivityContainer = activityContainer; |
| 433 | mStackSupervisor = activityContainer.getOuter(); |
| 434 | mService = mStackSupervisor.mService; |
| 435 | mHandler = new ActivityStackHandler(mService.mHandler.getLooper()); |
| 436 | mWindowManager = mService.mWindowManager; |
| 437 | mStackId = activityContainer.mStackId; |
Fyodor Kupolov | f63b89c | 2015-10-27 18:08:56 -0700 | [diff] [blame] | 438 | mCurrentUser = mService.mUserController.getCurrentUserIdLocked(); |
Wale Ogunwale | c82f2f5 | 2014-12-09 09:32:50 -0800 | [diff] [blame] | 439 | mRecentTasks = recentTasks; |
Filip Gruszczynski | e5390e7 | 2015-08-18 16:39:00 -0700 | [diff] [blame] | 440 | mTaskPositioner = mStackId == FREEFORM_WORKSPACE_STACK_ID |
| 441 | ? new LaunchingTaskPositioner() : null; |
| 442 | } |
| 443 | |
| 444 | void attachDisplay(ActivityStackSupervisor.ActivityDisplay activityDisplay, boolean onTop) { |
| 445 | mDisplayId = activityDisplay.mDisplayId; |
| 446 | mStacks = activityDisplay.mStacks; |
| 447 | mBounds = mWindowManager.attachStack(mStackId, activityDisplay.mDisplayId, onTop); |
| 448 | mFullscreen = mBounds == null; |
| 449 | if (mTaskPositioner != null) { |
| 450 | mTaskPositioner.setDisplay(activityDisplay.mDisplay); |
| 451 | mTaskPositioner.configure(mBounds); |
| 452 | } |
Wale Ogunwale | 961f485 | 2016-02-01 20:25:54 -0800 | [diff] [blame] | 453 | |
| 454 | if (mStackId == DOCKED_STACK_ID) { |
| 455 | // If we created a docked stack we want to resize it so it resizes all other stacks |
| 456 | // in the system. |
| 457 | mStackSupervisor.resizeDockedStackLocked( |
| 458 | mBounds, null, null, null, null, PRESERVE_WINDOWS); |
| 459 | } |
Filip Gruszczynski | e5390e7 | 2015-08-18 16:39:00 -0700 | [diff] [blame] | 460 | } |
| 461 | |
| 462 | void detachDisplay() { |
| 463 | mDisplayId = Display.INVALID_DISPLAY; |
| 464 | mStacks = null; |
| 465 | if (mTaskPositioner != null) { |
| 466 | mTaskPositioner.reset(); |
| 467 | } |
| 468 | mWindowManager.detachStack(mStackId); |
Jorim Jaggi | 899327f | 2016-02-25 20:44:18 -0500 | [diff] [blame] | 469 | if (mStackId == DOCKED_STACK_ID) { |
| 470 | // If we removed a docked stack we want to resize it so it resizes all other stacks |
| 471 | // in the system to fullscreen. |
| 472 | mStackSupervisor.resizeDockedStackLocked( |
| 473 | null, null, null, null, null, PRESERVE_WINDOWS); |
| 474 | } |
Filip Gruszczynski | e5390e7 | 2015-08-18 16:39:00 -0700 | [diff] [blame] | 475 | } |
| 476 | |
Winson | c809cbb | 2015-11-02 12:06:15 -0800 | [diff] [blame] | 477 | public void getDisplaySize(Point out) { |
| 478 | mActivityContainer.mActivityDisplay.mDisplay.getSize(out); |
| 479 | } |
| 480 | |
Jorim Jaggi | 192086e | 2016-03-11 17:17:03 +0100 | [diff] [blame] | 481 | /** |
| 482 | * Defers updating the bounds of the stack. If the stack was resized/repositioned while |
| 483 | * deferring, the bounds will update in {@link #continueUpdateBounds()}. |
| 484 | */ |
| 485 | void deferUpdateBounds() { |
| 486 | if (!mUpdateBoundsDeferred) { |
| 487 | mUpdateBoundsDeferred = true; |
| 488 | mUpdateBoundsDeferredCalled = false; |
| 489 | } |
| 490 | } |
| 491 | |
| 492 | /** |
| 493 | * Continues updating bounds after updates have been deferred. If there was a resize attempt |
| 494 | * between {@link #deferUpdateBounds()} and {@link #continueUpdateBounds()}, the stack will |
| 495 | * be resized to that bounds. |
| 496 | */ |
| 497 | void continueUpdateBounds() { |
| 498 | final boolean wasDeferred = mUpdateBoundsDeferred; |
| 499 | mUpdateBoundsDeferred = false; |
| 500 | if (wasDeferred && mUpdateBoundsDeferredCalled) { |
| 501 | mStackSupervisor.resizeStackUncheckedLocked(this, |
| 502 | mDeferredBounds.isEmpty() ? null : mDeferredBounds, |
| 503 | mDeferredTaskBounds.isEmpty() ? null : mDeferredTaskBounds, |
| 504 | mDeferredTaskInsetBounds.isEmpty() ? null : mDeferredTaskInsetBounds); |
| 505 | } |
| 506 | } |
| 507 | |
| 508 | boolean updateBoundsAllowed(Rect bounds, Rect tempTaskBounds, |
| 509 | Rect tempTaskInsetBounds) { |
| 510 | if (!mUpdateBoundsDeferred) { |
| 511 | return true; |
| 512 | } |
| 513 | if (bounds != null) { |
| 514 | mDeferredBounds.set(bounds); |
| 515 | } else { |
| 516 | mDeferredBounds.setEmpty(); |
| 517 | } |
| 518 | if (tempTaskBounds != null) { |
| 519 | mDeferredTaskBounds.set(tempTaskBounds); |
| 520 | } else { |
| 521 | mDeferredTaskBounds.setEmpty(); |
| 522 | } |
| 523 | if (tempTaskInsetBounds != null) { |
| 524 | mDeferredTaskInsetBounds.set(tempTaskInsetBounds); |
| 525 | } else { |
| 526 | mDeferredTaskInsetBounds.setEmpty(); |
| 527 | } |
| 528 | mUpdateBoundsDeferredCalled = true; |
| 529 | return false; |
| 530 | } |
| 531 | |
Filip Gruszczynski | e5390e7 | 2015-08-18 16:39:00 -0700 | [diff] [blame] | 532 | void setBounds(Rect bounds) { |
| 533 | mBounds = mFullscreen ? null : new Rect(bounds); |
Filip Gruszczynski | 9ac01a7 | 2015-09-04 11:12:17 -0700 | [diff] [blame] | 534 | if (mTaskPositioner != null) { |
| 535 | mTaskPositioner.configure(bounds); |
| 536 | } |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 537 | } |
Craig Mautner | 5962b12 | 2012-10-05 14:45:52 -0700 | [diff] [blame] | 538 | |
Filip Gruszczynski | 3e85ba2 | 2015-10-05 22:48:30 -0700 | [diff] [blame] | 539 | final ActivityRecord topRunningActivityLocked() { |
Craig Mautner | d74f7d7 | 2013-02-26 13:41:02 -0800 | [diff] [blame] | 540 | for (int taskNdx = mTaskHistory.size() - 1; taskNdx >= 0; --taskNdx) { |
Filip Gruszczynski | 3e85ba2 | 2015-10-05 22:48:30 -0700 | [diff] [blame] | 541 | ActivityRecord r = mTaskHistory.get(taskNdx).topRunningActivityLocked(); |
Craig Mautner | 6b74cb5 | 2013-09-27 17:02:21 -0700 | [diff] [blame] | 542 | if (r != null) { |
| 543 | return r; |
Craig Mautner | 11bf9a5 | 2013-02-19 14:08:51 -0800 | [diff] [blame] | 544 | } |
| 545 | } |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 546 | return null; |
| 547 | } |
| 548 | |
| 549 | final ActivityRecord topRunningNonDelayedActivityLocked(ActivityRecord notTop) { |
Craig Mautner | d74f7d7 | 2013-02-26 13:41:02 -0800 | [diff] [blame] | 550 | for (int taskNdx = mTaskHistory.size() - 1; taskNdx >= 0; --taskNdx) { |
| 551 | final TaskRecord task = mTaskHistory.get(taskNdx); |
Craig Mautner | 11bf9a5 | 2013-02-19 14:08:51 -0800 | [diff] [blame] | 552 | final ArrayList<ActivityRecord> activities = task.mActivities; |
Craig Mautner | d74f7d7 | 2013-02-26 13:41:02 -0800 | [diff] [blame] | 553 | for (int activityNdx = activities.size() - 1; activityNdx >= 0; --activityNdx) { |
| 554 | ActivityRecord r = activities.get(activityNdx); |
Chong Zhang | 8776197 | 2016-08-22 13:53:24 -0700 | [diff] [blame] | 555 | if (!r.finishing && !r.delayedResume && r != notTop && r.okToShowLocked()) { |
Craig Mautner | 11bf9a5 | 2013-02-19 14:08:51 -0800 | [diff] [blame] | 556 | return r; |
| 557 | } |
| 558 | } |
| 559 | } |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 560 | return null; |
| 561 | } |
| 562 | |
| 563 | /** |
| 564 | * This is a simplified version of topRunningActivityLocked that provides a number of |
| 565 | * 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] | 566 | * |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 567 | * @param token If non-null, any history records matching this token will be skipped. |
| 568 | * @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] | 569 | * |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 570 | * @return Returns the HistoryRecord of the next activity on the stack. |
| 571 | */ |
| 572 | final ActivityRecord topRunningActivityLocked(IBinder token, int taskId) { |
Craig Mautner | 11bf9a5 | 2013-02-19 14:08:51 -0800 | [diff] [blame] | 573 | for (int taskNdx = mTaskHistory.size() - 1; taskNdx >= 0; --taskNdx) { |
| 574 | TaskRecord task = mTaskHistory.get(taskNdx); |
| 575 | if (task.taskId == taskId) { |
| 576 | continue; |
| 577 | } |
| 578 | ArrayList<ActivityRecord> activities = task.mActivities; |
| 579 | for (int i = activities.size() - 1; i >= 0; --i) { |
| 580 | final ActivityRecord r = activities.get(i); |
| 581 | // Note: the taskId check depends on real taskId fields being non-zero |
Chong Zhang | 8776197 | 2016-08-22 13:53:24 -0700 | [diff] [blame] | 582 | if (!r.finishing && (token != r.appToken) && r.okToShowLocked()) { |
Craig Mautner | 11bf9a5 | 2013-02-19 14:08:51 -0800 | [diff] [blame] | 583 | return r; |
| 584 | } |
| 585 | } |
| 586 | } |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 587 | return null; |
| 588 | } |
| 589 | |
Craig Mautner | 8849a5e | 2013-04-02 16:41:03 -0700 | [diff] [blame] | 590 | final ActivityRecord topActivity() { |
Craig Mautner | 8849a5e | 2013-04-02 16:41:03 -0700 | [diff] [blame] | 591 | for (int taskNdx = mTaskHistory.size() - 1; taskNdx >= 0; --taskNdx) { |
| 592 | ArrayList<ActivityRecord> activities = mTaskHistory.get(taskNdx).mActivities; |
Craig Mautner | 0175b88 | 2014-09-07 18:05:31 -0700 | [diff] [blame] | 593 | for (int activityNdx = activities.size() - 1; activityNdx >= 0; --activityNdx) { |
| 594 | final ActivityRecord r = activities.get(activityNdx); |
| 595 | if (!r.finishing) { |
| 596 | return r; |
| 597 | } |
Craig Mautner | 8849a5e | 2013-04-02 16:41:03 -0700 | [diff] [blame] | 598 | } |
| 599 | } |
Craig Mautner | de4ef02 | 2013-04-07 19:01:33 -0700 | [diff] [blame] | 600 | return null; |
Craig Mautner | 8849a5e | 2013-04-02 16:41:03 -0700 | [diff] [blame] | 601 | } |
| 602 | |
Craig Mautner | 9e14d0f | 2013-05-01 11:26:09 -0700 | [diff] [blame] | 603 | final TaskRecord topTask() { |
| 604 | final int size = mTaskHistory.size(); |
| 605 | if (size > 0) { |
| 606 | return mTaskHistory.get(size - 1); |
| 607 | } |
| 608 | return null; |
| 609 | } |
| 610 | |
Craig Mautner | d232895 | 2013-03-05 12:46:26 -0800 | [diff] [blame] | 611 | TaskRecord taskForIdLocked(int id) { |
| 612 | for (int taskNdx = mTaskHistory.size() - 1; taskNdx >= 0; --taskNdx) { |
| 613 | final TaskRecord task = mTaskHistory.get(taskNdx); |
| 614 | if (task.taskId == id) { |
| 615 | return task; |
Craig Mautner | 5d9c7be | 2013-02-15 14:02:56 -0800 | [diff] [blame] | 616 | } |
| 617 | } |
Dianne Hackborn | ce86ba8 | 2011-07-13 19:33:41 -0700 | [diff] [blame] | 618 | return null; |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 619 | } |
| 620 | |
Craig Mautner | d232895 | 2013-03-05 12:46:26 -0800 | [diff] [blame] | 621 | ActivityRecord isInStackLocked(IBinder token) { |
Wale Ogunwale | 7d70117 | 2015-03-11 15:36:30 -0700 | [diff] [blame] | 622 | final ActivityRecord r = ActivityRecord.forTokenLocked(token); |
Wale Ogunwale | 60454db | 2015-01-23 16:05:07 -0800 | [diff] [blame] | 623 | return isInStackLocked(r); |
| 624 | } |
| 625 | |
| 626 | ActivityRecord isInStackLocked(ActivityRecord r) { |
| 627 | if (r == null) { |
| 628 | return null; |
| 629 | } |
| 630 | final TaskRecord task = r.task; |
Wale Ogunwale | 7d70117 | 2015-03-11 15:36:30 -0700 | [diff] [blame] | 631 | if (task != null && task.stack != null |
| 632 | && task.mActivities.contains(r) && mTaskHistory.contains(task)) { |
Wale Ogunwale | 60454db | 2015-01-23 16:05:07 -0800 | [diff] [blame] | 633 | if (task.stack != this) Slog.w(TAG, |
Craig Mautner | d232895 | 2013-03-05 12:46:26 -0800 | [diff] [blame] | 634 | "Illegal state! task does not point to stack it is in."); |
Wale Ogunwale | 60454db | 2015-01-23 16:05:07 -0800 | [diff] [blame] | 635 | return r; |
Craig Mautner | 5d9c7be | 2013-02-15 14:02:56 -0800 | [diff] [blame] | 636 | } |
Craig Mautner | d232895 | 2013-03-05 12:46:26 -0800 | [diff] [blame] | 637 | return null; |
Craig Mautner | 5d9c7be | 2013-02-15 14:02:56 -0800 | [diff] [blame] | 638 | } |
| 639 | |
Craig Mautner | 2420ead | 2013-04-01 17:13:20 -0700 | [diff] [blame] | 640 | final boolean updateLRUListLocked(ActivityRecord r) { |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 641 | final boolean hadit = mLRUActivities.remove(r); |
| 642 | mLRUActivities.add(r); |
| 643 | return hadit; |
| 644 | } |
| 645 | |
Craig Mautner | de4ef02 | 2013-04-07 19:01:33 -0700 | [diff] [blame] | 646 | final boolean isHomeStack() { |
| 647 | return mStackId == HOME_STACK_ID; |
| 648 | } |
| 649 | |
Winson Chung | 0583d3d | 2015-12-18 10:03:12 -0500 | [diff] [blame] | 650 | final boolean isDockedStack() { |
| 651 | return mStackId == DOCKED_STACK_ID; |
| 652 | } |
| 653 | |
| 654 | final boolean isPinnedStack() { |
| 655 | return mStackId == PINNED_STACK_ID; |
| 656 | } |
| 657 | |
Craig Mautner | e0a3884 | 2013-12-16 16:14:02 -0800 | [diff] [blame] | 658 | final boolean isOnHomeDisplay() { |
| 659 | return isAttached() && |
| 660 | mActivityContainer.mActivityDisplay.mDisplayId == Display.DEFAULT_DISPLAY; |
| 661 | } |
| 662 | |
Wale Ogunwale | eae451e | 2015-08-04 15:20:50 -0700 | [diff] [blame] | 663 | void moveToFront(String reason) { |
| 664 | moveToFront(reason, null); |
| 665 | } |
| 666 | |
| 667 | /** |
| 668 | * @param reason The reason for moving the stack to the front. |
| 669 | * @param task If non-null, the task will be moved to the top of the stack. |
| 670 | * */ |
| 671 | void moveToFront(String reason, TaskRecord task) { |
Wale Ogunwale | 1e60e0c | 2015-10-28 13:36:10 -0700 | [diff] [blame] | 672 | if (!isAttached()) { |
| 673 | return; |
| 674 | } |
Wale Ogunwale | 925d0d1 | 2015-09-23 15:40:07 -0700 | [diff] [blame] | 675 | |
Wale Ogunwale | 1e60e0c | 2015-10-28 13:36:10 -0700 | [diff] [blame] | 676 | mStacks.remove(this); |
| 677 | int addIndex = mStacks.size(); |
| 678 | |
| 679 | if (addIndex > 0) { |
| 680 | final ActivityStack topStack = mStacks.get(addIndex - 1); |
Filip Gruszczynski | 114d5ca | 2015-12-04 09:05:00 -0800 | [diff] [blame] | 681 | if (StackId.isAlwaysOnTop(topStack.mStackId) && topStack != this) { |
| 682 | // 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] | 683 | addIndex--; |
Wale Ogunwale | cb82f30 | 2015-02-25 07:53:40 -0800 | [diff] [blame] | 684 | } |
Wale Ogunwale | 1e60e0c | 2015-10-28 13:36:10 -0700 | [diff] [blame] | 685 | } |
| 686 | |
| 687 | mStacks.add(addIndex, this); |
| 688 | |
| 689 | // TODO(multi-display): Needs to also work if focus is moving to the non-home display. |
| 690 | if (isOnHomeDisplay()) { |
Wale Ogunwale | 4cea0f5 | 2015-12-25 06:30:31 -0800 | [diff] [blame] | 691 | mStackSupervisor.setFocusStackUnchecked(reason, this); |
Wale Ogunwale | 1e60e0c | 2015-10-28 13:36:10 -0700 | [diff] [blame] | 692 | } |
| 693 | if (task != null) { |
| 694 | insertTaskAtTop(task, null); |
| 695 | } else { |
| 696 | task = topTask(); |
| 697 | } |
| 698 | if (task != null) { |
| 699 | mWindowManager.moveTaskToTop(task.taskId); |
Craig Mautner | 4a1cb22 | 2013-12-04 16:14:06 -0800 | [diff] [blame] | 700 | } |
Craig Mautner | e0a3884 | 2013-12-16 16:14:02 -0800 | [diff] [blame] | 701 | } |
| 702 | |
Jiaquan He | e13e964 | 2016-06-15 15:16:13 -0700 | [diff] [blame] | 703 | /** |
| 704 | * @param task If non-null, the task will be moved to the back of the stack. |
| 705 | * */ |
| 706 | void moveToBack(TaskRecord task) { |
| 707 | if (!isAttached()) { |
| 708 | return; |
| 709 | } |
| 710 | |
| 711 | mStacks.remove(this); |
| 712 | mStacks.add(0, this); |
| 713 | |
| 714 | if (task != null) { |
| 715 | mTaskHistory.remove(task); |
| 716 | mTaskHistory.add(0, task); |
| 717 | updateTaskMovement(task, false); |
| 718 | mWindowManager.moveTaskToBottom(task.taskId); |
| 719 | } |
| 720 | } |
| 721 | |
Wale Ogunwale | d046a01 | 2015-12-24 13:05:59 -0800 | [diff] [blame] | 722 | boolean isFocusable() { |
Wale Ogunwale | 4cea0f5 | 2015-12-25 06:30:31 -0800 | [diff] [blame] | 723 | if (StackId.canReceiveKeys(mStackId)) { |
| 724 | return true; |
| 725 | } |
| 726 | // The stack isn't focusable. See if its top activity is focusable to force focus on the |
| 727 | // stack. |
| 728 | final ActivityRecord r = topRunningActivityLocked(); |
| 729 | return r != null && r.isFocusable(); |
Wale Ogunwale | d046a01 | 2015-12-24 13:05:59 -0800 | [diff] [blame] | 730 | } |
| 731 | |
Craig Mautner | e0a3884 | 2013-12-16 16:14:02 -0800 | [diff] [blame] | 732 | final boolean isAttached() { |
| 733 | return mStacks != null; |
Craig Mautner | 4a1cb22 | 2013-12-04 16:14:06 -0800 | [diff] [blame] | 734 | } |
| 735 | |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 736 | /** |
Wale Ogunwale | 3938197 | 2015-12-17 17:15:29 -0800 | [diff] [blame] | 737 | * Returns the top activity in any existing task matching the given Intent in the input result. |
| 738 | * Returns null if no such task is found. |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 739 | */ |
Wale Ogunwale | 3938197 | 2015-12-17 17:15:29 -0800 | [diff] [blame] | 740 | void findTaskLocked(ActivityRecord target, FindTaskResult result) { |
Craig Mautner | ac6f843 | 2013-07-17 13:24:59 -0700 | [diff] [blame] | 741 | Intent intent = target.intent; |
| 742 | ActivityInfo info = target.info; |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 743 | ComponentName cls = intent.getComponent(); |
| 744 | if (info.targetActivity != null) { |
| 745 | cls = new ComponentName(info.packageName, info.targetActivity); |
| 746 | } |
Dianne Hackborn | f02b60a | 2012-08-16 10:48:27 -0700 | [diff] [blame] | 747 | final int userId = UserHandle.getUserId(info.applicationInfo.uid); |
Craig Mautner | d00f474 | 2014-03-12 14:17:26 -0700 | [diff] [blame] | 748 | boolean isDocument = intent != null & intent.isDocument(); |
| 749 | // If documentData is non-null then it must match the existing task data. |
| 750 | Uri documentData = isDocument ? intent.getData() : null; |
Craig Mautner | 000f002 | 2013-02-26 15:04:29 -0800 | [diff] [blame] | 751 | |
Wale Ogunwale | ee006da | 2015-03-30 14:49:25 -0700 | [diff] [blame] | 752 | 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] | 753 | for (int taskNdx = mTaskHistory.size() - 1; taskNdx >= 0; --taskNdx) { |
| 754 | final TaskRecord task = mTaskHistory.get(taskNdx); |
Dianne Hackborn | 91097de | 2014-04-04 18:02:06 -0700 | [diff] [blame] | 755 | if (task.voiceSession != null) { |
| 756 | // We never match voice sessions; those always run independently. |
Wale Ogunwale | ee006da | 2015-03-30 14:49:25 -0700 | [diff] [blame] | 757 | if (DEBUG_TASKS) Slog.d(TAG_TASKS, "Skipping " + task + ": voice session"); |
Dianne Hackborn | 91097de | 2014-04-04 18:02:06 -0700 | [diff] [blame] | 758 | continue; |
| 759 | } |
Craig Mautner | ac6f843 | 2013-07-17 13:24:59 -0700 | [diff] [blame] | 760 | if (task.userId != userId) { |
| 761 | // Looking for a different task. |
Wale Ogunwale | ee006da | 2015-03-30 14:49:25 -0700 | [diff] [blame] | 762 | if (DEBUG_TASKS) Slog.d(TAG_TASKS, "Skipping " + task + ": different user"); |
Craig Mautner | ac6f843 | 2013-07-17 13:24:59 -0700 | [diff] [blame] | 763 | continue; |
| 764 | } |
Craig Mautner | 000f002 | 2013-02-26 15:04:29 -0800 | [diff] [blame] | 765 | final ActivityRecord r = task.getTopActivity(); |
| 766 | if (r == null || r.finishing || r.userId != userId || |
| 767 | r.launchMode == ActivityInfo.LAUNCH_SINGLE_INSTANCE) { |
Wale Ogunwale | ee006da | 2015-03-30 14:49:25 -0700 | [diff] [blame] | 768 | if (DEBUG_TASKS) Slog.d(TAG_TASKS, "Skipping " + task + ": mismatch root " + r); |
Craig Mautner | 000f002 | 2013-02-26 15:04:29 -0800 | [diff] [blame] | 769 | continue; |
| 770 | } |
Chong Zhang | b546f7e | 2015-08-05 14:21:36 -0700 | [diff] [blame] | 771 | if (r.mActivityType != target.mActivityType) { |
| 772 | if (DEBUG_TASKS) Slog.d(TAG_TASKS, "Skipping " + task + ": mismatch activity type"); |
| 773 | continue; |
| 774 | } |
Craig Mautner | 000f002 | 2013-02-26 15:04:29 -0800 | [diff] [blame] | 775 | |
Craig Mautner | d00f474 | 2014-03-12 14:17:26 -0700 | [diff] [blame] | 776 | final Intent taskIntent = task.intent; |
| 777 | final Intent affinityIntent = task.affinityIntent; |
| 778 | final boolean taskIsDocument; |
| 779 | final Uri taskDocumentData; |
| 780 | if (taskIntent != null && taskIntent.isDocument()) { |
| 781 | taskIsDocument = true; |
| 782 | taskDocumentData = taskIntent.getData(); |
| 783 | } else if (affinityIntent != null && affinityIntent.isDocument()) { |
| 784 | taskIsDocument = true; |
| 785 | taskDocumentData = affinityIntent.getData(); |
| 786 | } else { |
| 787 | taskIsDocument = false; |
| 788 | taskDocumentData = null; |
| 789 | } |
| 790 | |
Wale Ogunwale | ee006da | 2015-03-30 14:49:25 -0700 | [diff] [blame] | 791 | if (DEBUG_TASKS) Slog.d(TAG_TASKS, "Comparing existing cls=" |
Craig Mautner | d00f474 | 2014-03-12 14:17:26 -0700 | [diff] [blame] | 792 | + taskIntent.getComponent().flattenToShortString() |
Dianne Hackborn | 7922882 | 2014-09-16 11:11:23 -0700 | [diff] [blame] | 793 | + "/aff=" + r.task.rootAffinity + " to new cls=" |
Dianne Hackborn | 2a272d4 | 2013-10-16 13:34:33 -0700 | [diff] [blame] | 794 | + intent.getComponent().flattenToShortString() + "/aff=" + info.taskAffinity); |
Andrii Kulian | 206b9fa | 2016-06-02 13:18:01 -0700 | [diff] [blame] | 795 | // TODO Refactor to remove duplications. Check if logic can be simplified. |
| 796 | if (taskIntent != null && taskIntent.getComponent() != null && |
Craig Mautner | ffcfcaa | 2014-06-05 09:54:38 -0700 | [diff] [blame] | 797 | taskIntent.getComponent().compareTo(cls) == 0 && |
Craig Mautner | d00f474 | 2014-03-12 14:17:26 -0700 | [diff] [blame] | 798 | Objects.equals(documentData, taskDocumentData)) { |
Wale Ogunwale | ee006da | 2015-03-30 14:49:25 -0700 | [diff] [blame] | 799 | if (DEBUG_TASKS) Slog.d(TAG_TASKS, "Found matching class!"); |
Craig Mautner | 000f002 | 2013-02-26 15:04:29 -0800 | [diff] [blame] | 800 | //dump(); |
Wale Ogunwale | ee006da | 2015-03-30 14:49:25 -0700 | [diff] [blame] | 801 | if (DEBUG_TASKS) Slog.d(TAG_TASKS, |
| 802 | "For Intent " + intent + " bringing to top: " + r.intent); |
Wale Ogunwale | 3938197 | 2015-12-17 17:15:29 -0800 | [diff] [blame] | 803 | result.r = r; |
| 804 | result.matchedByRootAffinity = false; |
| 805 | break; |
Craig Mautner | ffcfcaa | 2014-06-05 09:54:38 -0700 | [diff] [blame] | 806 | } else if (affinityIntent != null && affinityIntent.getComponent() != null && |
| 807 | affinityIntent.getComponent().compareTo(cls) == 0 && |
Craig Mautner | d00f474 | 2014-03-12 14:17:26 -0700 | [diff] [blame] | 808 | Objects.equals(documentData, taskDocumentData)) { |
Wale Ogunwale | ee006da | 2015-03-30 14:49:25 -0700 | [diff] [blame] | 809 | if (DEBUG_TASKS) Slog.d(TAG_TASKS, "Found matching class!"); |
Craig Mautner | 000f002 | 2013-02-26 15:04:29 -0800 | [diff] [blame] | 810 | //dump(); |
Wale Ogunwale | ee006da | 2015-03-30 14:49:25 -0700 | [diff] [blame] | 811 | if (DEBUG_TASKS) Slog.d(TAG_TASKS, |
| 812 | "For Intent " + intent + " bringing to top: " + r.intent); |
Wale Ogunwale | 3938197 | 2015-12-17 17:15:29 -0800 | [diff] [blame] | 813 | result.r = r; |
| 814 | result.matchedByRootAffinity = false; |
| 815 | break; |
Andrii Kulian | 206b9fa | 2016-06-02 13:18:01 -0700 | [diff] [blame] | 816 | } else if (!isDocument && !taskIsDocument |
| 817 | && result.r == null && task.canMatchRootAffinity()) { |
| 818 | if (task.rootAffinity.equals(target.taskAffinity)) { |
| 819 | if (DEBUG_TASKS) Slog.d(TAG_TASKS, "Found matching affinity candidate!"); |
| 820 | // It is possible for multiple tasks to have the same root affinity especially |
| 821 | // if they are in separate stacks. We save off this candidate, but keep looking |
| 822 | // to see if there is a better candidate. |
| 823 | result.r = r; |
| 824 | result.matchedByRootAffinity = true; |
| 825 | } |
Wale Ogunwale | ee006da | 2015-03-30 14:49:25 -0700 | [diff] [blame] | 826 | } else if (DEBUG_TASKS) Slog.d(TAG_TASKS, "Not a match: " + task); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 827 | } |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 828 | } |
| 829 | |
| 830 | /** |
| 831 | * Returns the first activity (starting from the top of the stack) that |
| 832 | * is the same as the given activity. Returns null if no such activity |
| 833 | * is found. |
| 834 | */ |
Andrii Kulian | d3bbb13 | 2016-06-16 16:00:20 -0700 | [diff] [blame] | 835 | ActivityRecord findActivityLocked(Intent intent, ActivityInfo info, |
| 836 | boolean compareIntentFilters) { |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 837 | ComponentName cls = intent.getComponent(); |
| 838 | if (info.targetActivity != null) { |
| 839 | cls = new ComponentName(info.packageName, info.targetActivity); |
| 840 | } |
Dianne Hackborn | f02b60a | 2012-08-16 10:48:27 -0700 | [diff] [blame] | 841 | final int userId = UserHandle.getUserId(info.applicationInfo.uid); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 842 | |
Craig Mautner | 000f002 | 2013-02-26 15:04:29 -0800 | [diff] [blame] | 843 | for (int taskNdx = mTaskHistory.size() - 1; taskNdx >= 0; --taskNdx) { |
Wale Ogunwale | 3fcb4a8 | 2015-04-06 14:00:13 -0700 | [diff] [blame] | 844 | final TaskRecord task = mTaskHistory.get(taskNdx); |
Craig Mautner | ac6f843 | 2013-07-17 13:24:59 -0700 | [diff] [blame] | 845 | final ArrayList<ActivityRecord> activities = task.mActivities; |
Wale Ogunwale | 3fcb4a8 | 2015-04-06 14:00:13 -0700 | [diff] [blame] | 846 | |
Craig Mautner | 000f002 | 2013-02-26 15:04:29 -0800 | [diff] [blame] | 847 | for (int activityNdx = activities.size() - 1; activityNdx >= 0; --activityNdx) { |
| 848 | ActivityRecord r = activities.get(activityNdx); |
Chong Zhang | 8776197 | 2016-08-22 13:53:24 -0700 | [diff] [blame] | 849 | if (!r.okToShowLocked()) { |
Wale Ogunwale | 25073dd | 2015-07-21 16:54:54 -0700 | [diff] [blame] | 850 | continue; |
Wale Ogunwale | 3fcb4a8 | 2015-04-06 14:00:13 -0700 | [diff] [blame] | 851 | } |
Andrii Kulian | d3bbb13 | 2016-06-16 16:00:20 -0700 | [diff] [blame] | 852 | if (!r.finishing && r.userId == userId) { |
| 853 | if (compareIntentFilters) { |
| 854 | if (r.intent.filterEquals(intent)) { |
| 855 | return r; |
| 856 | } |
| 857 | } else { |
| 858 | if (r.intent.getComponent().equals(cls)) { |
| 859 | return r; |
| 860 | } |
| 861 | } |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 862 | } |
| 863 | } |
| 864 | } |
| 865 | |
| 866 | return null; |
| 867 | } |
| 868 | |
Amith Yamasani | 742a671 | 2011-05-04 14:49:28 -0700 | [diff] [blame] | 869 | /* |
Craig Mautner | ac6f843 | 2013-07-17 13:24:59 -0700 | [diff] [blame] | 870 | * 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] | 871 | */ |
Craig Mautner | 93529a4 | 2013-10-04 15:03:13 -0700 | [diff] [blame] | 872 | final void switchUserLocked(int userId) { |
Craig Mautner | 5d9c7be | 2013-02-15 14:02:56 -0800 | [diff] [blame] | 873 | if (mCurrentUser == userId) { |
Craig Mautner | 93529a4 | 2013-10-04 15:03:13 -0700 | [diff] [blame] | 874 | return; |
Craig Mautner | 5d9c7be | 2013-02-15 14:02:56 -0800 | [diff] [blame] | 875 | } |
| 876 | mCurrentUser = userId; |
| 877 | |
| 878 | // Move userId's tasks to the top. |
Craig Mautner | 5d9c7be | 2013-02-15 14:02:56 -0800 | [diff] [blame] | 879 | int index = mTaskHistory.size(); |
Craig Mautner | db5c4fb | 2013-11-06 13:55:08 -0800 | [diff] [blame] | 880 | for (int i = 0; i < index; ) { |
Wale Ogunwale | 3fcb4a8 | 2015-04-06 14:00:13 -0700 | [diff] [blame] | 881 | final TaskRecord task = mTaskHistory.get(i); |
| 882 | |
Chong Zhang | 8776197 | 2016-08-22 13:53:24 -0700 | [diff] [blame] | 883 | if (task.okToShowLocked()) { |
Wale Ogunwale | ee006da | 2015-03-30 14:49:25 -0700 | [diff] [blame] | 884 | if (DEBUG_TASKS) Slog.d(TAG_TASKS, "switchUserLocked: stack=" + getStackId() + |
Craig Mautner | 4f1df4f | 2013-10-15 15:44:14 -0700 | [diff] [blame] | 885 | " moving " + task + " to top"); |
Craig Mautner | 5d9c7be | 2013-02-15 14:02:56 -0800 | [diff] [blame] | 886 | mTaskHistory.remove(i); |
| 887 | mTaskHistory.add(task); |
| 888 | --index; |
Craig Mautner | db5c4fb | 2013-11-06 13:55:08 -0800 | [diff] [blame] | 889 | // Use same value for i. |
| 890 | } else { |
| 891 | ++i; |
Craig Mautner | 5d9c7be | 2013-02-15 14:02:56 -0800 | [diff] [blame] | 892 | } |
| 893 | } |
Amith Yamasani | 742a671 | 2011-05-04 14:49:28 -0700 | [diff] [blame] | 894 | } |
| 895 | |
Craig Mautner | 2420ead | 2013-04-01 17:13:20 -0700 | [diff] [blame] | 896 | void minimalResumeActivityLocked(ActivityRecord r) { |
Wale Ogunwale | 5658e4b | 2016-02-12 12:22:19 -0800 | [diff] [blame] | 897 | if (DEBUG_STATES) Slog.v(TAG_STATES, "Moving to RESUMED: " + r + " (starting new instance)" |
| 898 | + " callers=" + Debug.getCallers(5)); |
Chong Zhang | 6cda19c | 2016-06-14 19:07:56 -0700 | [diff] [blame] | 899 | setResumedActivityLocked(r, "minimalResumeActivityLocked"); |
Craig Mautner | 2420ead | 2013-04-01 17:13:20 -0700 | [diff] [blame] | 900 | completeResumeLocked(r); |
Craig Mautner | 1e8b872 | 2013-10-14 18:24:52 -0700 | [diff] [blame] | 901 | setLaunchTime(r); |
Wale Ogunwale | 0fc365c | 2015-05-25 19:35:42 -0700 | [diff] [blame] | 902 | if (DEBUG_SAVED_STATE) Slog.i(TAG_SAVED_STATE, |
| 903 | "Launch completed; removing icicle of " + r.icicle); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 904 | } |
| 905 | |
Filip Gruszczynski | 3d82ed6 | 2015-12-10 10:41:39 -0800 | [diff] [blame] | 906 | void addRecentActivityLocked(ActivityRecord r) { |
Chong Zhang | 45c25ce | 2015-08-10 22:18:26 -0700 | [diff] [blame] | 907 | if (r != null) { |
| 908 | mRecentTasks.addLocked(r.task); |
| 909 | r.task.touchActiveTime(); |
| 910 | } |
| 911 | } |
| 912 | |
Narayan Kamath | 7829c81 | 2015-06-08 17:39:43 +0100 | [diff] [blame] | 913 | private void startLaunchTraces(String packageName) { |
Dianne Hackborn | cee04b5 | 2013-07-03 17:01:28 -0700 | [diff] [blame] | 914 | if (mFullyDrawnStartTime != 0) { |
| 915 | Trace.asyncTraceEnd(Trace.TRACE_TAG_ACTIVITY_MANAGER, "drawing", 0); |
| 916 | } |
Narayan Kamath | 7829c81 | 2015-06-08 17:39:43 +0100 | [diff] [blame] | 917 | Trace.asyncTraceBegin(Trace.TRACE_TAG_ACTIVITY_MANAGER, "launching: " + packageName, 0); |
Dianne Hackborn | cee04b5 | 2013-07-03 17:01:28 -0700 | [diff] [blame] | 918 | Trace.asyncTraceBegin(Trace.TRACE_TAG_ACTIVITY_MANAGER, "drawing", 0); |
| 919 | } |
| 920 | |
| 921 | private void stopFullyDrawnTraceIfNeeded() { |
| 922 | if (mFullyDrawnStartTime != 0 && mLaunchStartTime == 0) { |
| 923 | Trace.asyncTraceEnd(Trace.TRACE_TAG_ACTIVITY_MANAGER, "drawing", 0); |
| 924 | mFullyDrawnStartTime = 0; |
| 925 | } |
| 926 | } |
| 927 | |
Craig Mautner | e79d4268 | 2013-04-01 19:01:53 -0700 | [diff] [blame] | 928 | void setLaunchTime(ActivityRecord r) { |
Dianne Hackborn | 2286cdc | 2013-07-01 19:10:06 -0700 | [diff] [blame] | 929 | if (r.displayStartTime == 0) { |
| 930 | r.fullyDrawnStartTime = r.displayStartTime = SystemClock.uptimeMillis(); |
| 931 | if (mLaunchStartTime == 0) { |
Narayan Kamath | 7829c81 | 2015-06-08 17:39:43 +0100 | [diff] [blame] | 932 | startLaunchTraces(r.packageName); |
Dianne Hackborn | 2286cdc | 2013-07-01 19:10:06 -0700 | [diff] [blame] | 933 | mLaunchStartTime = mFullyDrawnStartTime = r.displayStartTime; |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 934 | } |
Dianne Hackborn | 2286cdc | 2013-07-01 19:10:06 -0700 | [diff] [blame] | 935 | } else if (mLaunchStartTime == 0) { |
Narayan Kamath | 7829c81 | 2015-06-08 17:39:43 +0100 | [diff] [blame] | 936 | startLaunchTraces(r.packageName); |
Dianne Hackborn | 2286cdc | 2013-07-01 19:10:06 -0700 | [diff] [blame] | 937 | mLaunchStartTime = mFullyDrawnStartTime = SystemClock.uptimeMillis(); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 938 | } |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 939 | } |
Craig Mautner | aab647e | 2013-02-28 16:31:36 -0800 | [diff] [blame] | 940 | |
Dianne Hackborn | 2286cdc | 2013-07-01 19:10:06 -0700 | [diff] [blame] | 941 | void clearLaunchTime(ActivityRecord r) { |
Craig Mautner | 5c49454 | 2013-09-06 11:59:38 -0700 | [diff] [blame] | 942 | // Make sure that there is no activity waiting for this to launch. |
| 943 | if (mStackSupervisor.mWaitingActivityLaunched.isEmpty()) { |
| 944 | r.displayStartTime = r.fullyDrawnStartTime = 0; |
| 945 | } else { |
| 946 | mStackSupervisor.removeTimeoutsForActivityLocked(r); |
| 947 | mStackSupervisor.scheduleIdleTimeoutLocked(r); |
| 948 | } |
Dianne Hackborn | 2286cdc | 2013-07-01 19:10:06 -0700 | [diff] [blame] | 949 | } |
| 950 | |
Dianne Hackborn | 4eba96b | 2011-01-21 13:34:36 -0800 | [diff] [blame] | 951 | void awakeFromSleepingLocked() { |
Dianne Hackborn | 4eba96b | 2011-01-21 13:34:36 -0800 | [diff] [blame] | 952 | // Ensure activities are no longer sleeping. |
Craig Mautner | d44711d | 2013-02-23 11:24:36 -0800 | [diff] [blame] | 953 | for (int taskNdx = mTaskHistory.size() - 1; taskNdx >= 0; --taskNdx) { |
| 954 | final ArrayList<ActivityRecord> activities = mTaskHistory.get(taskNdx).mActivities; |
| 955 | for (int activityNdx = activities.size() - 1; activityNdx >= 0; --activityNdx) { |
| 956 | activities.get(activityNdx).setSleeping(false); |
| 957 | } |
Dianne Hackborn | 4eba96b | 2011-01-21 13:34:36 -0800 | [diff] [blame] | 958 | } |
Craig Mautner | f49b0a4 | 2014-11-20 15:06:40 -0800 | [diff] [blame] | 959 | if (mPausingActivity != null) { |
| 960 | Slog.d(TAG, "awakeFromSleepingLocked: previously pausing activity didn't pause"); |
| 961 | activityPausedLocked(mPausingActivity.appToken, true); |
| 962 | } |
Dianne Hackborn | 4eba96b | 2011-01-21 13:34:36 -0800 | [diff] [blame] | 963 | } |
| 964 | |
Todd Kennedy | 39bfee5 | 2016-02-24 10:28:21 -0800 | [diff] [blame] | 965 | void updateActivityApplicationInfoLocked(ApplicationInfo aInfo) { |
| 966 | final String packageName = aInfo.packageName; |
| 967 | for (int taskNdx = mTaskHistory.size() - 1; taskNdx >= 0; --taskNdx) { |
| 968 | final List<ActivityRecord> activities = mTaskHistory.get(taskNdx).mActivities; |
| 969 | for (int activityNdx = activities.size() - 1; activityNdx >= 0; --activityNdx) { |
| 970 | if (packageName.equals(activities.get(activityNdx).packageName)) { |
| 971 | activities.get(activityNdx).info.applicationInfo = aInfo; |
| 972 | } |
| 973 | } |
| 974 | } |
| 975 | } |
| 976 | |
Craig Mautner | 0eea92c | 2013-05-16 13:35:39 -0700 | [diff] [blame] | 977 | /** |
| 978 | * @return true if something must be done before going to sleep. |
| 979 | */ |
| 980 | boolean checkReadyForSleepLocked() { |
| 981 | if (mResumedActivity != null) { |
| 982 | // Still have something resumed; can't sleep until it is paused. |
Wale Ogunwale | ee006da | 2015-03-30 14:49:25 -0700 | [diff] [blame] | 983 | if (DEBUG_PAUSE) Slog.v(TAG_PAUSE, "Sleep needs to pause " + mResumedActivity); |
| 984 | if (DEBUG_USER_LEAVING) Slog.v(TAG_USER_LEAVING, |
| 985 | "Sleep => pause with userLeaving=false"); |
Wale Ogunwale | 950faff | 2016-08-08 09:51:04 -0700 | [diff] [blame] | 986 | startPausingLocked(false, true, null, false); |
Craig Mautner | 0eea92c | 2013-05-16 13:35:39 -0700 | [diff] [blame] | 987 | return true; |
| 988 | } |
| 989 | if (mPausingActivity != null) { |
| 990 | // Still waiting for something to pause; can't sleep yet. |
Wale Ogunwale | ee006da | 2015-03-30 14:49:25 -0700 | [diff] [blame] | 991 | 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] | 992 | return true; |
Dianne Hackborn | 4eba96b | 2011-01-21 13:34:36 -0800 | [diff] [blame] | 993 | } |
| 994 | |
Wale Ogunwale | 5c42e50 | 2015-04-08 09:18:54 -0700 | [diff] [blame] | 995 | if (hasVisibleBehindActivity()) { |
| 996 | // Stop visible behind activity before going to sleep. |
Wale Ogunwale | 1f544be | 2015-12-17 10:27:23 -0800 | [diff] [blame] | 997 | final ActivityRecord r = getVisibleBehindActivity(); |
Wale Ogunwale | 5c42e50 | 2015-04-08 09:18:54 -0700 | [diff] [blame] | 998 | mStackSupervisor.mStoppingActivities.add(r); |
Wale Ogunwale | 1f544be | 2015-12-17 10:27:23 -0800 | [diff] [blame] | 999 | 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] | 1000 | return true; |
| 1001 | } |
| 1002 | |
Craig Mautner | 0eea92c | 2013-05-16 13:35:39 -0700 | [diff] [blame] | 1003 | return false; |
| 1004 | } |
Dianne Hackborn | 4eba96b | 2011-01-21 13:34:36 -0800 | [diff] [blame] | 1005 | |
Craig Mautner | 0eea92c | 2013-05-16 13:35:39 -0700 | [diff] [blame] | 1006 | void goToSleep() { |
Filip Gruszczynski | bc5a6c5 | 2015-09-22 13:13:24 -0700 | [diff] [blame] | 1007 | ensureActivitiesVisibleLocked(null, 0, !PRESERVE_WINDOWS); |
Dianne Hackborn | 4eba96b | 2011-01-21 13:34:36 -0800 | [diff] [blame] | 1008 | |
Andrii Kulian | f9949d5 | 2016-05-06 12:53:25 -0700 | [diff] [blame] | 1009 | // Make sure any paused or stopped but visible activities are now sleeping. |
Craig Mautner | 0eea92c | 2013-05-16 13:35:39 -0700 | [diff] [blame] | 1010 | // This ensures that the activity's onStop() is called. |
| 1011 | for (int taskNdx = mTaskHistory.size() - 1; taskNdx >= 0; --taskNdx) { |
| 1012 | final ArrayList<ActivityRecord> activities = mTaskHistory.get(taskNdx).mActivities; |
| 1013 | for (int activityNdx = activities.size() - 1; activityNdx >= 0; --activityNdx) { |
| 1014 | final ActivityRecord r = activities.get(activityNdx); |
Andrii Kulian | f9949d5 | 2016-05-06 12:53:25 -0700 | [diff] [blame] | 1015 | if (r.state == ActivityState.STOPPING || r.state == ActivityState.STOPPED |
| 1016 | || r.state == ActivityState.PAUSED || r.state == ActivityState.PAUSING) { |
Craig Mautner | 0eea92c | 2013-05-16 13:35:39 -0700 | [diff] [blame] | 1017 | r.setSleeping(true); |
Dianne Hackborn | 4eba96b | 2011-01-21 13:34:36 -0800 | [diff] [blame] | 1018 | } |
| 1019 | } |
Dianne Hackborn | 4eba96b | 2011-01-21 13:34:36 -0800 | [diff] [blame] | 1020 | } |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 1021 | } |
Craig Mautner | 59c0097 | 2012-07-30 12:10:24 -0700 | [diff] [blame] | 1022 | |
Winson | 8b1871d | 2015-11-20 09:56:20 -0800 | [diff] [blame] | 1023 | public final Bitmap screenshotActivitiesLocked(ActivityRecord who) { |
| 1024 | if (DEBUG_SCREENSHOTS) Slog.d(TAG_SCREENSHOTS, "screenshotActivitiesLocked: " + who); |
Dianne Hackborn | ff801ec | 2011-01-22 18:05:38 -0800 | [diff] [blame] | 1025 | if (who.noDisplay) { |
Wale Ogunwale | 0fc365c | 2015-05-25 19:35:42 -0700 | [diff] [blame] | 1026 | if (DEBUG_SCREENSHOTS) Slog.d(TAG_SCREENSHOTS, "\tNo display"); |
Dianne Hackborn | ff801ec | 2011-01-22 18:05:38 -0800 | [diff] [blame] | 1027 | return null; |
| 1028 | } |
Craig Mautner | aab647e | 2013-02-28 16:31:36 -0800 | [diff] [blame] | 1029 | |
Winson Chung | 083baf9 | 2014-07-11 10:32:42 -0700 | [diff] [blame] | 1030 | if (isHomeStack()) { |
Winson Chung | 376543b | 2014-05-21 17:43:28 -0700 | [diff] [blame] | 1031 | // 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] | 1032 | // 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] | 1033 | if (DEBUG_SCREENSHOTS) Slog.d(TAG_SCREENSHOTS, "\tHome stack"); |
Dianne Hackborn | 4d03fe6 | 2013-10-04 17:26:37 -0700 | [diff] [blame] | 1034 | return null; |
| 1035 | } |
| 1036 | |
Winson Chung | 48a10a5 | 2014-08-27 14:36:51 -0700 | [diff] [blame] | 1037 | int w = mService.mThumbnailWidth; |
| 1038 | int h = mService.mThumbnailHeight; |
Winson | 8b1871d | 2015-11-20 09:56:20 -0800 | [diff] [blame] | 1039 | float scale = 1f; |
Dianne Hackborn | 0aae2d4 | 2010-12-07 23:51:29 -0800 | [diff] [blame] | 1040 | if (w > 0) { |
Wale Ogunwale | 0fc365c | 2015-05-25 19:35:42 -0700 | [diff] [blame] | 1041 | if (DEBUG_SCREENSHOTS) Slog.d(TAG_SCREENSHOTS, "\tTaking screenshot"); |
Winson | 8b1871d | 2015-11-20 09:56:20 -0800 | [diff] [blame] | 1042 | |
| 1043 | // 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] | 1044 | // but scaled to half the size. This gives us a "good-enough" fullscreen thumbnail to |
| 1045 | // use within SystemUI while keeping memory usage low. |
Winson Chung | ead5c0f | 2015-12-14 11:18:57 -0500 | [diff] [blame] | 1046 | if (ActivityManagerService.TAKE_FULLSCREEN_SCREENSHOTS) { |
Winson | 8b1871d | 2015-11-20 09:56:20 -0800 | [diff] [blame] | 1047 | w = h = -1; |
Winson | 2170093 | 2016-03-24 17:26:23 -0700 | [diff] [blame] | 1048 | scale = mService.mFullscreenThumbnailScale; |
Winson | 8b1871d | 2015-11-20 09:56:20 -0800 | [diff] [blame] | 1049 | } |
Wale Ogunwale | eacdf2c | 2014-12-09 14:02:27 -0800 | [diff] [blame] | 1050 | return mWindowManager.screenshotApplications(who.appToken, Display.DEFAULT_DISPLAY, |
Winson | 8b1871d | 2015-11-20 09:56:20 -0800 | [diff] [blame] | 1051 | w, h, scale); |
Dianne Hackborn | 0aae2d4 | 2010-12-07 23:51:29 -0800 | [diff] [blame] | 1052 | } |
Winson Chung | 376543b | 2014-05-21 17:43:28 -0700 | [diff] [blame] | 1053 | Slog.e(TAG, "Invalid thumbnail dimensions: " + w + "x" + h); |
Dianne Hackborn | 0aae2d4 | 2010-12-07 23:51:29 -0800 | [diff] [blame] | 1054 | return null; |
| 1055 | } |
| 1056 | |
Dianne Hackborn | a4e102e | 2014-09-04 22:52:27 -0700 | [diff] [blame] | 1057 | /** |
| 1058 | * Start pausing the currently resumed activity. It is an error to call this if there |
| 1059 | * is already an activity being paused or there is no resumed activity. |
| 1060 | * |
| 1061 | * @param userLeaving True if this should result in an onUserLeaving to the current activity. |
| 1062 | * @param uiSleeping True if this is happening with the user interface going to sleep (the |
| 1063 | * screen turning off). |
Wale Ogunwale | 950faff | 2016-08-08 09:51:04 -0700 | [diff] [blame] | 1064 | * @param resuming The activity we are currently trying to resume or null if this is not being |
| 1065 | * called as part of resuming the top activity, so we shouldn't try to instigate |
| 1066 | * a resume here if not null. |
Dianne Hackborn | a4e102e | 2014-09-04 22:52:27 -0700 | [diff] [blame] | 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 | */ |
Wale Ogunwale | 950faff | 2016-08-08 09:51:04 -0700 | [diff] [blame] | 1072 | final boolean startPausingLocked(boolean userLeaving, boolean uiSleeping, |
| 1073 | ActivityRecord resuming, 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. |
Wale Ogunwale | 950faff | 2016-08-08 09:51:04 -0700 | [diff] [blame] | 1081 | completePauseLocked(false, resuming); |
riddle_hsu | 7dfe4d7 | 2015-02-16 18:43:49 +0800 | [diff] [blame] | 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) { |
Wale Ogunwale | 950faff | 2016-08-08 09:51:04 -0700 | [diff] [blame] | 1086 | if (resuming == null) { |
Dianne Hackborn | a4e102e | 2014-09-04 22:52:27 -0700 | [diff] [blame] | 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. |
Wale Ogunwale | 950faff | 2016-08-08 09:51:04 -0700 | [diff] [blame] | 1159 | completePauseLocked(false, resuming); |
Dianne Hackborn | a4e102e | 2014-09-04 22:52:27 -0700 | [diff] [blame] | 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."); |
Wale Ogunwale | 950faff | 2016-08-08 09:51:04 -0700 | [diff] [blame] | 1178 | if (resuming == null) { |
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)")); |
Wale Ogunwale | 950faff | 2016-08-08 09:51:04 -0700 | [diff] [blame] | 1195 | completePauseLocked(true, null); |
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 | |
Chong Zhang | 45e6d2d | 2016-07-20 18:33:56 -0700 | [diff] [blame] | 1248 | mWindowManager.notifyAppStopped(r.appToken); |
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 | |
Wale Ogunwale | 950faff | 2016-08-08 09:51:04 -0700 | [diff] [blame] | 1266 | private void completePauseLocked(boolean resumeNext, ActivityRecord resuming) { |
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. |
Wale Ogunwale | e852400 | 2016-09-13 16:34:57 -0700 | [diff] [blame] | 1306 | if (prev != null) { |
| 1307 | prev.stopFreezingScreenLocked(true /*force*/); |
| 1308 | } |
Dianne Hackborn | 621e2fe | 2012-02-16 17:07:33 -0800 | [diff] [blame] | 1309 | mPausingActivity = null; |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 1310 | } |
Dianne Hackborn | cbb722e | 2012-02-07 18:33:49 -0800 | [diff] [blame] | 1311 | |
Dianne Hackborn | a4e102e | 2014-09-04 22:52:27 -0700 | [diff] [blame] | 1312 | if (resumeNext) { |
| 1313 | final ActivityStack topStack = mStackSupervisor.getFocusedStack(); |
Fyodor Kupolov | 9b80b94 | 2016-06-16 16:29:05 -0700 | [diff] [blame] | 1314 | if (!mService.isSleepingOrShuttingDownLocked()) { |
Wale Ogunwale | d046a01 | 2015-12-24 13:05:59 -0800 | [diff] [blame] | 1315 | mStackSupervisor.resumeFocusedStackTopActivityLocked(topStack, prev, null); |
Dianne Hackborn | a4e102e | 2014-09-04 22:52:27 -0700 | [diff] [blame] | 1316 | } else { |
| 1317 | mStackSupervisor.checkReadyForSleepLocked(); |
Filip Gruszczynski | 3e85ba2 | 2015-10-05 22:48:30 -0700 | [diff] [blame] | 1318 | ActivityRecord top = topStack.topRunningActivityLocked(); |
Dianne Hackborn | a4e102e | 2014-09-04 22:52:27 -0700 | [diff] [blame] | 1319 | if (top == null || (prev != null && top != prev)) { |
Wale Ogunwale | d046a01 | 2015-12-24 13:05:59 -0800 | [diff] [blame] | 1320 | // If there are no more activities available to run, do resume anyway to start |
| 1321 | // something. Also if the top activity on the stack is not the just paused |
| 1322 | // activity, we need to go ahead and resume it to ensure we complete an |
| 1323 | // in-flight app switch. |
| 1324 | mStackSupervisor.resumeFocusedStackTopActivityLocked(); |
Dianne Hackborn | a4e102e | 2014-09-04 22:52:27 -0700 | [diff] [blame] | 1325 | } |
Dianne Hackborn | 42e620c | 2012-06-24 13:20:51 -0700 | [diff] [blame] | 1326 | } |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 1327 | } |
Craig Mautner | aab647e | 2013-02-28 16:31:36 -0800 | [diff] [blame] | 1328 | |
Dianne Hackborn | 621e2fe | 2012-02-16 17:07:33 -0800 | [diff] [blame] | 1329 | if (prev != null) { |
| 1330 | prev.resumeKeyDispatchingLocked(); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 1331 | |
Craig Mautner | 525f3d9 | 2013-05-07 14:01:50 -0700 | [diff] [blame] | 1332 | if (prev.app != null && prev.cpuTimeAtResume > 0 |
| 1333 | && mService.mBatteryStatsService.isOnBattery()) { |
Dianne Hackborn | 652973f | 2014-09-10 17:08:48 -0700 | [diff] [blame] | 1334 | long diff = mService.mProcessCpuTracker.getCpuTimeForPid(prev.app.pid) |
| 1335 | - prev.cpuTimeAtResume; |
Craig Mautner | 525f3d9 | 2013-05-07 14:01:50 -0700 | [diff] [blame] | 1336 | if (diff > 0) { |
| 1337 | BatteryStatsImpl bsi = mService.mBatteryStatsService.getActiveStatistics(); |
| 1338 | synchronized (bsi) { |
| 1339 | BatteryStatsImpl.Uid.Proc ps = |
| 1340 | bsi.getProcessStatsLocked(prev.info.applicationInfo.uid, |
Dianne Hackborn | d293224 | 2013-08-05 18:18:42 -0700 | [diff] [blame] | 1341 | prev.info.packageName); |
Craig Mautner | 525f3d9 | 2013-05-07 14:01:50 -0700 | [diff] [blame] | 1342 | if (ps != null) { |
| 1343 | ps.addForegroundTimeLocked(diff); |
| 1344 | } |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 1345 | } |
| 1346 | } |
| 1347 | } |
Craig Mautner | 525f3d9 | 2013-05-07 14:01:50 -0700 | [diff] [blame] | 1348 | prev.cpuTimeAtResume = 0; // reset it |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 1349 | } |
Winson Chung | 740c3ac | 2014-11-12 16:14:38 -0800 | [diff] [blame] | 1350 | |
Andrii Kulian | 8290f8f | 2016-06-30 17:51:32 -0700 | [diff] [blame] | 1351 | // Notify when the task stack has changed, but only if visibilities changed (not just |
| 1352 | // focus). Also if there is an active pinned stack - we always want to notify it about |
| 1353 | // task stack changes, because its positioning may depend on it. |
| 1354 | if (mStackSupervisor.mAppVisibilitiesChangedSinceLastPause |
| 1355 | || mService.mStackSupervisor.getStack(PINNED_STACK_ID) != null) { |
Jorim Jaggi | a0fdeec | 2016-01-07 14:42:28 +0100 | [diff] [blame] | 1356 | mService.notifyTaskStackChangedLocked(); |
| 1357 | mStackSupervisor.mAppVisibilitiesChangedSinceLastPause = false; |
| 1358 | } |
Wale Ogunwale | 5658e4b | 2016-02-12 12:22:19 -0800 | [diff] [blame] | 1359 | |
Wale Ogunwale | 950faff | 2016-08-08 09:51:04 -0700 | [diff] [blame] | 1360 | mStackSupervisor.ensureActivitiesVisibleLocked(resuming, 0, !PRESERVE_WINDOWS); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 1361 | } |
| 1362 | |
Chong Zhang | 46b1ac6 | 2016-02-18 17:53:57 -0800 | [diff] [blame] | 1363 | private void addToStopping(ActivityRecord r, boolean immediate) { |
| 1364 | if (!mStackSupervisor.mStoppingActivities.contains(r)) { |
| 1365 | mStackSupervisor.mStoppingActivities.add(r); |
| 1366 | } |
| 1367 | |
| 1368 | // If we already have a few activities waiting to stop, then give up |
| 1369 | // on things going idle and start clearing them out. Or if r is the |
| 1370 | // last of activity of the last task the stack will be empty and must |
| 1371 | // be cleared immediately. |
| 1372 | boolean forceIdle = mStackSupervisor.mStoppingActivities.size() > MAX_STOPPING_TO_FORCE |
| 1373 | || (r.frontOfTask && mTaskHistory.size() <= 1); |
| 1374 | |
| 1375 | if (immediate || forceIdle) { |
| 1376 | if (DEBUG_PAUSE) Slog.v(TAG_PAUSE, "Scheduling idle now: forceIdle=" |
| 1377 | + forceIdle + "immediate=" + immediate); |
Filip Gruszczynski | ef2f72b | 2015-12-04 14:52:25 -0800 | [diff] [blame] | 1378 | mStackSupervisor.scheduleIdleLocked(); |
| 1379 | } else { |
| 1380 | mStackSupervisor.checkReadyForSleepLocked(); |
| 1381 | } |
| 1382 | } |
| 1383 | |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 1384 | /** |
| 1385 | * Once we know that we have asked an application to put an activity in |
| 1386 | * the resumed state (either by launching it or explicitly telling it), |
| 1387 | * this function updates the rest of our state to match that fact. |
| 1388 | */ |
Craig Mautner | 525f3d9 | 2013-05-07 14:01:50 -0700 | [diff] [blame] | 1389 | private void completeResumeLocked(ActivityRecord next) { |
Chong Zhang | 2b79af1 | 2016-02-10 18:47:06 -0800 | [diff] [blame] | 1390 | next.visible = true; |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 1391 | next.idle = false; |
| 1392 | next.results = null; |
| 1393 | next.newIntents = null; |
Chong Zhang | 2b79af1 | 2016-02-10 18:47:06 -0800 | [diff] [blame] | 1394 | next.stopped = false; |
Craig Mautner | f33f4d7 | 2014-07-16 17:25:48 +0000 | [diff] [blame] | 1395 | |
Chong Zhang | 85ee654 | 2015-10-02 13:36:38 -0700 | [diff] [blame] | 1396 | if (next.isHomeActivity()) { |
Craig Mautner | f33f4d7 | 2014-07-16 17:25:48 +0000 | [diff] [blame] | 1397 | ProcessRecord app = next.task.mActivities.get(0).app; |
| 1398 | if (app != null && app != mService.mHomeProcess) { |
| 1399 | mService.mHomeProcess = app; |
| 1400 | } |
| 1401 | } |
| 1402 | |
Craig Mautner | 0756632 | 2013-09-26 16:42:55 -0700 | [diff] [blame] | 1403 | if (next.nowVisible) { |
| 1404 | // We won't get a call to reportActivityVisibleLocked() so dismiss lockscreen now. |
Chong Zhang | 5022da3 | 2016-06-21 16:31:37 -0700 | [diff] [blame] | 1405 | mStackSupervisor.reportActivityVisibleLocked(next); |
Jorim Jaggi | 8de4311c | 2014-08-11 22:36:20 +0200 | [diff] [blame] | 1406 | mStackSupervisor.notifyActivityDrawnForKeyguard(); |
Craig Mautner | 0756632 | 2013-09-26 16:42:55 -0700 | [diff] [blame] | 1407 | } |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 1408 | |
| 1409 | // 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] | 1410 | mStackSupervisor.scheduleIdleTimeoutLocked(next); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 1411 | |
Craig Mautner | ce5f3cb | 2013-04-22 08:58:54 -0700 | [diff] [blame] | 1412 | mStackSupervisor.reportResumedActivityLocked(next); |
| 1413 | |
| 1414 | next.resumeKeyDispatchingLocked(); |
| 1415 | mNoAnimActivities.clear(); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 1416 | |
| 1417 | // Mark the point when the activity is resuming |
| 1418 | // TODO: To be more accurate, the mark should be before the onCreate, |
| 1419 | // not after the onResume. But for subsequent starts, onResume is fine. |
| 1420 | if (next.app != null) { |
Dianne Hackborn | 652973f | 2014-09-10 17:08:48 -0700 | [diff] [blame] | 1421 | next.cpuTimeAtResume = mService.mProcessCpuTracker.getCpuTimeForPid(next.app.pid); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 1422 | } else { |
| 1423 | next.cpuTimeAtResume = 0; // Couldn't get the cpu time of process |
| 1424 | } |
Winson Chung | 376543b | 2014-05-21 17:43:28 -0700 | [diff] [blame] | 1425 | |
George Mount | 6ba042b | 2014-07-28 11:12:28 -0700 | [diff] [blame] | 1426 | next.returningOptions = null; |
Craig Mautner | 64ccb70 | 2014-10-01 09:38:40 -0700 | [diff] [blame] | 1427 | |
Wale Ogunwale | 1f544be | 2015-12-17 10:27:23 -0800 | [diff] [blame] | 1428 | if (getVisibleBehindActivity() == next) { |
Craig Mautner | 64ccb70 | 2014-10-01 09:38:40 -0700 | [diff] [blame] | 1429 | // When resuming an activity, require it to call requestVisibleBehind() again. |
Wale Ogunwale | 1f544be | 2015-12-17 10:27:23 -0800 | [diff] [blame] | 1430 | setVisibleBehindActivity(null); |
Craig Mautner | 64ccb70 | 2014-10-01 09:38:40 -0700 | [diff] [blame] | 1431 | } |
Chong Zhang | 6cda19c | 2016-06-14 19:07:56 -0700 | [diff] [blame] | 1432 | mStackSupervisor.checkReadyForSleepLocked(); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 1433 | } |
| 1434 | |
Craig Mautner | 2568c3a | 2015-03-26 14:22:34 -0700 | [diff] [blame] | 1435 | private void setVisible(ActivityRecord r, boolean visible) { |
Craig Mautner | e3a00d7 | 2014-04-16 08:31:19 -0700 | [diff] [blame] | 1436 | r.visible = visible; |
Jorim Jaggi | c2f262b | 2015-12-07 16:59:10 -0800 | [diff] [blame] | 1437 | if (!visible && r.mUpdateTaskThumbnailWhenHidden) { |
| 1438 | r.updateThumbnailLocked(r.task.stack.screenshotActivitiesLocked(r), null); |
| 1439 | r.mUpdateTaskThumbnailWhenHidden = false; |
| 1440 | } |
Craig Mautner | e3a00d7 | 2014-04-16 08:31:19 -0700 | [diff] [blame] | 1441 | mWindowManager.setAppVisibility(r.appToken, visible); |
Craig Mautner | f4c909b | 2014-04-17 18:39:38 -0700 | [diff] [blame] | 1442 | final ArrayList<ActivityContainer> containers = r.mChildContainers; |
Craig Mautner | e3a00d7 | 2014-04-16 08:31:19 -0700 | [diff] [blame] | 1443 | for (int containerNdx = containers.size() - 1; containerNdx >= 0; --containerNdx) { |
Craig Mautner | f4c909b | 2014-04-17 18:39:38 -0700 | [diff] [blame] | 1444 | ActivityContainer container = containers.get(containerNdx); |
Craig Mautner | e3a00d7 | 2014-04-16 08:31:19 -0700 | [diff] [blame] | 1445 | container.setVisible(visible); |
| 1446 | } |
Jorim Jaggi | a0fdeec | 2016-01-07 14:42:28 +0100 | [diff] [blame] | 1447 | mStackSupervisor.mAppVisibilitiesChangedSinceLastPause = true; |
Craig Mautner | e3a00d7 | 2014-04-16 08:31:19 -0700 | [diff] [blame] | 1448 | } |
| 1449 | |
Craig Mautner | fa387ad | 2014-08-05 11:16:41 -0700 | [diff] [blame] | 1450 | // Find the first visible activity above the passed activity and if it is translucent return it |
| 1451 | // otherwise return null; |
| 1452 | ActivityRecord findNextTranslucentActivity(ActivityRecord r) { |
| 1453 | TaskRecord task = r.task; |
| 1454 | if (task == null) { |
| 1455 | return null; |
| 1456 | } |
| 1457 | |
| 1458 | ActivityStack stack = task.stack; |
| 1459 | if (stack == null) { |
| 1460 | return null; |
| 1461 | } |
| 1462 | |
| 1463 | int stackNdx = mStacks.indexOf(stack); |
| 1464 | |
| 1465 | ArrayList<TaskRecord> tasks = stack.mTaskHistory; |
| 1466 | int taskNdx = tasks.indexOf(task); |
| 1467 | |
| 1468 | ArrayList<ActivityRecord> activities = task.mActivities; |
| 1469 | int activityNdx = activities.indexOf(r) + 1; |
| 1470 | |
| 1471 | final int numStacks = mStacks.size(); |
| 1472 | while (stackNdx < numStacks) { |
Wale Ogunwale | e4a0c57 | 2015-06-30 08:40:31 -0700 | [diff] [blame] | 1473 | final ActivityStack historyStack = mStacks.get(stackNdx); |
Todd Kennedy | aab56db | 2015-01-30 09:39:53 -0800 | [diff] [blame] | 1474 | tasks = historyStack.mTaskHistory; |
Craig Mautner | fa387ad | 2014-08-05 11:16:41 -0700 | [diff] [blame] | 1475 | final int numTasks = tasks.size(); |
| 1476 | while (taskNdx < numTasks) { |
Wale Ogunwale | e4a0c57 | 2015-06-30 08:40:31 -0700 | [diff] [blame] | 1477 | final TaskRecord currentTask = tasks.get(taskNdx); |
| 1478 | activities = currentTask.mActivities; |
Craig Mautner | fa387ad | 2014-08-05 11:16:41 -0700 | [diff] [blame] | 1479 | final int numActivities = activities.size(); |
| 1480 | while (activityNdx < numActivities) { |
| 1481 | final ActivityRecord activity = activities.get(activityNdx); |
| 1482 | if (!activity.finishing) { |
Wale Ogunwale | e4a0c57 | 2015-06-30 08:40:31 -0700 | [diff] [blame] | 1483 | return historyStack.mFullscreen |
| 1484 | && currentTask.mFullscreen && activity.fullscreen ? null : activity; |
Craig Mautner | fa387ad | 2014-08-05 11:16:41 -0700 | [diff] [blame] | 1485 | } |
| 1486 | ++activityNdx; |
| 1487 | } |
| 1488 | activityNdx = 0; |
| 1489 | ++taskNdx; |
| 1490 | } |
| 1491 | taskNdx = 0; |
| 1492 | ++stackNdx; |
| 1493 | } |
| 1494 | |
| 1495 | return null; |
| 1496 | } |
| 1497 | |
Wale Ogunwale | 4cea0f5 | 2015-12-25 06:30:31 -0800 | [diff] [blame] | 1498 | ActivityStack getNextFocusableStackLocked() { |
Wale Ogunwale | d697cea | 2015-02-20 17:19:49 -0800 | [diff] [blame] | 1499 | ArrayList<ActivityStack> stacks = mStacks; |
| 1500 | final ActivityRecord parent = mActivityContainer.mParentActivity; |
| 1501 | if (parent != null) { |
| 1502 | stacks = parent.task.stack.mStacks; |
| 1503 | } |
| 1504 | if (stacks != null) { |
| 1505 | for (int i = stacks.size() - 1; i >= 0; --i) { |
| 1506 | ActivityStack stack = stacks.get(i); |
Filip Gruszczynski | 0e381e2 | 2016-01-14 16:31:33 -0800 | [diff] [blame] | 1507 | if (stack != this && stack.isFocusable() |
Wale Ogunwale | 8051c5c | 2016-03-04 10:27:32 -0800 | [diff] [blame] | 1508 | && stack.getStackVisibilityLocked(null) != STACK_INVISIBLE) { |
Wale Ogunwale | d697cea | 2015-02-20 17:19:49 -0800 | [diff] [blame] | 1509 | return stack; |
| 1510 | } |
| 1511 | } |
| 1512 | } |
| 1513 | return null; |
| 1514 | } |
| 1515 | |
Wale Ogunwale | b34a7ad | 2015-08-14 11:05:30 -0700 | [diff] [blame] | 1516 | /** Returns true if the stack contains a fullscreen task. */ |
| 1517 | private boolean hasFullscreenTask() { |
| 1518 | for (int i = mTaskHistory.size() - 1; i >= 0; --i) { |
| 1519 | final TaskRecord task = mTaskHistory.get(i); |
| 1520 | if (task.mFullscreen) { |
| 1521 | return true; |
| 1522 | } |
| 1523 | } |
| 1524 | return false; |
| 1525 | } |
| 1526 | |
Wale Ogunwale | 8051c5c | 2016-03-04 10:27:32 -0800 | [diff] [blame] | 1527 | /** |
| 1528 | * Returns true if the stack is translucent and can have other contents visible behind it if |
| 1529 | * needed. A stack is considered translucent if it don't contain a visible or |
| 1530 | * starting (about to be visible) activity that is fullscreen (opaque). |
| 1531 | * @param starting The currently starting activity or null if there is none. |
Wale Ogunwale | 56d75cf | 2016-03-09 15:14:47 -0800 | [diff] [blame] | 1532 | * @param stackBehindId The id of the stack directly behind this one. |
Wale Ogunwale | 8051c5c | 2016-03-04 10:27:32 -0800 | [diff] [blame] | 1533 | */ |
Wale Ogunwale | 56d75cf | 2016-03-09 15:14:47 -0800 | [diff] [blame] | 1534 | private boolean isStackTranslucent(ActivityRecord starting, int stackBehindId) { |
Wale Ogunwale | 8051c5c | 2016-03-04 10:27:32 -0800 | [diff] [blame] | 1535 | for (int taskNdx = mTaskHistory.size() - 1; taskNdx >= 0; --taskNdx) { |
| 1536 | final TaskRecord task = mTaskHistory.get(taskNdx); |
Wale Ogunwale | 1e3523c | 2015-09-16 13:11:10 -0700 | [diff] [blame] | 1537 | final ArrayList<ActivityRecord> activities = task.mActivities; |
| 1538 | for (int activityNdx = activities.size() - 1; activityNdx >= 0; --activityNdx) { |
| 1539 | final ActivityRecord r = activities.get(activityNdx); |
Wale Ogunwale | b34a7ad | 2015-08-14 11:05:30 -0700 | [diff] [blame] | 1540 | |
Wale Ogunwale | 56d75cf | 2016-03-09 15:14:47 -0800 | [diff] [blame] | 1541 | if (r.finishing) { |
| 1542 | // We don't factor in finishing activities when determining translucency since |
| 1543 | // they will be gone soon. |
| 1544 | continue; |
| 1545 | } |
| 1546 | |
| 1547 | if (!r.visible && r != starting) { |
| 1548 | // Also ignore invisible activities that are not the currently starting |
| 1549 | // activity (about to be visible). |
| 1550 | continue; |
| 1551 | } |
| 1552 | |
| 1553 | if (r.fullscreen) { |
| 1554 | // Stack isn't translucent if it has at least one fullscreen activity |
| 1555 | // that is visible. |
| 1556 | return false; |
| 1557 | } |
| 1558 | |
| 1559 | if (!isHomeStack() && r.frontOfTask |
| 1560 | && task.isOverHomeStack() && stackBehindId != HOME_STACK_ID) { |
| 1561 | // Stack isn't translucent if it's top activity should have the home stack |
| 1562 | // 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] | 1563 | return false; |
Wale Ogunwale | b34a7ad | 2015-08-14 11:05:30 -0700 | [diff] [blame] | 1564 | } |
| 1565 | } |
| 1566 | } |
Wale Ogunwale | 1e3523c | 2015-09-16 13:11:10 -0700 | [diff] [blame] | 1567 | return true; |
Wale Ogunwale | b34a7ad | 2015-08-14 11:05:30 -0700 | [diff] [blame] | 1568 | } |
| 1569 | |
Filip Gruszczynski | 0e381e2 | 2016-01-14 16:31:33 -0800 | [diff] [blame] | 1570 | /** |
| 1571 | * Returns stack's visibility: {@link #STACK_INVISIBLE}, {@link #STACK_VISIBLE} or |
| 1572 | * {@link #STACK_VISIBLE_ACTIVITY_BEHIND}. |
Wale Ogunwale | 8051c5c | 2016-03-04 10:27:32 -0800 | [diff] [blame] | 1573 | * @param starting The currently starting activity or null if there is none. |
Filip Gruszczynski | 0e381e2 | 2016-01-14 16:31:33 -0800 | [diff] [blame] | 1574 | */ |
Wale Ogunwale | 8051c5c | 2016-03-04 10:27:32 -0800 | [diff] [blame] | 1575 | int getStackVisibilityLocked(ActivityRecord starting) { |
Jose Lima | 7ba7125 | 2014-04-30 12:59:27 -0700 | [diff] [blame] | 1576 | if (!isAttached()) { |
Filip Gruszczynski | 0e381e2 | 2016-01-14 16:31:33 -0800 | [diff] [blame] | 1577 | return STACK_INVISIBLE; |
Jose Lima | 7ba7125 | 2014-04-30 12:59:27 -0700 | [diff] [blame] | 1578 | } |
| 1579 | |
Wale Ogunwale | 1e60e0c | 2015-10-28 13:36:10 -0700 | [diff] [blame] | 1580 | if (mStackSupervisor.isFrontStack(this) || mStackSupervisor.isFocusedStack(this)) { |
Filip Gruszczynski | 0e381e2 | 2016-01-14 16:31:33 -0800 | [diff] [blame] | 1581 | return STACK_VISIBLE; |
Wale Ogunwale | 99db186 | 2015-10-23 20:08:22 -0700 | [diff] [blame] | 1582 | } |
| 1583 | |
Wale Ogunwale | b34a7ad | 2015-08-14 11:05:30 -0700 | [diff] [blame] | 1584 | final int stackIndex = mStacks.indexOf(this); |
| 1585 | |
| 1586 | if (stackIndex == mStacks.size() - 1) { |
| 1587 | Slog.wtf(TAG, |
| 1588 | "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] | 1589 | return STACK_INVISIBLE; |
Wale Ogunwale | b34a7ad | 2015-08-14 11:05:30 -0700 | [diff] [blame] | 1590 | } |
| 1591 | |
Wale Ogunwale | 1e3523c | 2015-09-16 13:11:10 -0700 | [diff] [blame] | 1592 | final ActivityStack focusedStack = mStackSupervisor.getFocusedStack(); |
| 1593 | final int focusedStackId = focusedStack.mStackId; |
| 1594 | |
Jiaquan He | 9bc01a8 | 2016-07-08 10:29:38 -0700 | [diff] [blame] | 1595 | final TaskRecord topFocusedTask = focusedStack.topTask(); |
| 1596 | final boolean isOnTopLauncherFocused = topFocusedTask != null && |
| 1597 | topFocusedTask.isOnTopLauncher(); |
| 1598 | if (isOnTopLauncherFocused) { |
| 1599 | // When an on-top launcher is focused, we should find out whether the freeform stack or |
| 1600 | // the fullscreen stack appears first underneath and has activities to show, and then |
| 1601 | // make it visible. |
| 1602 | boolean behindFullscreenOrFreeForm = false; |
| 1603 | for (int stackBehindFocusedIndex = mStacks.indexOf(focusedStack) - 1; |
| 1604 | stackBehindFocusedIndex >= 0; stackBehindFocusedIndex--) { |
| 1605 | ActivityStack stack = mStacks.get(stackBehindFocusedIndex); |
| 1606 | if ((stack.mStackId == FREEFORM_WORKSPACE_STACK_ID |
| 1607 | || stack.mStackId == FULLSCREEN_WORKSPACE_STACK_ID) |
| 1608 | && stack.topRunningActivityLocked() != null) { |
| 1609 | if (stackIndex == stackBehindFocusedIndex) { |
| 1610 | return !behindFullscreenOrFreeForm ? STACK_VISIBLE : STACK_INVISIBLE; |
| 1611 | } |
| 1612 | behindFullscreenOrFreeForm = true; |
| 1613 | } |
| 1614 | } |
| 1615 | } |
Jiaquan He | c4dcd4b | 2016-07-29 15:31:10 -0700 | [diff] [blame] | 1616 | // If an on-top launcher is on the top of the home stack but the home stack is not focused, |
| 1617 | // then the whole stack should be invisible. |
| 1618 | TaskRecord topTask = topTask(); |
| 1619 | if (mStackId != focusedStackId && topTask != null && topTask.isOnTopLauncher()) { |
| 1620 | // We're here mostly because the on-top launcher didn't have a chance to move itself to |
| 1621 | // back. We should move it to back as soon as possible to avoid other activities |
| 1622 | // returning to it or other visibility issues. |
| 1623 | moveTaskToBackLocked(topTask.taskId); |
| 1624 | return STACK_INVISIBLE; |
| 1625 | } |
Jiaquan He | 9bc01a8 | 2016-07-08 10:29:38 -0700 | [diff] [blame] | 1626 | |
Wale Ogunwale | cff4aa3 | 2015-12-11 10:44:25 -0800 | [diff] [blame] | 1627 | if (mStackId == FULLSCREEN_WORKSPACE_STACK_ID |
Filip Gruszczynski | 4e7fe71 | 2016-01-13 13:22:44 -0800 | [diff] [blame] | 1628 | && hasVisibleBehindActivity() && focusedStackId == HOME_STACK_ID |
| 1629 | && !focusedStack.topActivity().fullscreen) { |
Wale Ogunwale | cff4aa3 | 2015-12-11 10:44:25 -0800 | [diff] [blame] | 1630 | // 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] | 1631 | // the home stack that is translucent. |
Filip Gruszczynski | 0e381e2 | 2016-01-14 16:31:33 -0800 | [diff] [blame] | 1632 | return STACK_VISIBLE_ACTIVITY_BEHIND; |
Wale Ogunwale | cff4aa3 | 2015-12-11 10:44:25 -0800 | [diff] [blame] | 1633 | } |
| 1634 | |
Wale Ogunwale | 1e3523c | 2015-09-16 13:11:10 -0700 | [diff] [blame] | 1635 | if (mStackId == DOCKED_STACK_ID) { |
Wale Ogunwale | b1faf60 | 2016-01-27 09:12:31 -0800 | [diff] [blame] | 1636 | // 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] | 1637 | // task in the focus stack doesn't support any form of resizing but we show it for the |
| 1638 | // home task even though it's not resizable. |
Wale Ogunwale | d26176f | 2016-01-25 20:04:04 -0800 | [diff] [blame] | 1639 | final ActivityRecord r = focusedStack.topRunningActivityLocked(); |
Wale Ogunwale | b1faf60 | 2016-01-27 09:12:31 -0800 | [diff] [blame] | 1640 | final TaskRecord task = r != null ? r.task : null; |
Jorim Jaggi | 42625d1b | 2016-02-11 20:11:07 -0800 | [diff] [blame] | 1641 | return task == null || task.canGoInDockedStack() || task.isHomeTask() ? STACK_VISIBLE |
| 1642 | : STACK_INVISIBLE; |
Wale Ogunwale | 1e3523c | 2015-09-16 13:11:10 -0700 | [diff] [blame] | 1643 | } |
| 1644 | |
Wale Ogunwale | 56d75cf | 2016-03-09 15:14:47 -0800 | [diff] [blame] | 1645 | // Find the first stack behind focused stack that actually got something visible. |
| 1646 | int stackBehindFocusedIndex = mStacks.indexOf(focusedStack) - 1; |
| 1647 | while (stackBehindFocusedIndex >= 0 && |
| 1648 | mStacks.get(stackBehindFocusedIndex).topRunningActivityLocked() == null) { |
| 1649 | stackBehindFocusedIndex--; |
Chong Zhang | b16cf34 | 2015-11-12 17:22:40 -0800 | [diff] [blame] | 1650 | } |
Wale Ogunwale | 99db186 | 2015-10-23 20:08:22 -0700 | [diff] [blame] | 1651 | if ((focusedStackId == DOCKED_STACK_ID || focusedStackId == PINNED_STACK_ID) |
Wale Ogunwale | 56d75cf | 2016-03-09 15:14:47 -0800 | [diff] [blame] | 1652 | && stackIndex == stackBehindFocusedIndex) { |
Wale Ogunwale | 99db186 | 2015-10-23 20:08:22 -0700 | [diff] [blame] | 1653 | // Stacks directly behind the docked or pinned stack are always visible. |
Filip Gruszczynski | 0e381e2 | 2016-01-14 16:31:33 -0800 | [diff] [blame] | 1654 | return STACK_VISIBLE; |
Wale Ogunwale | 1e3523c | 2015-09-16 13:11:10 -0700 | [diff] [blame] | 1655 | } |
| 1656 | |
Wale Ogunwale | 56d75cf | 2016-03-09 15:14:47 -0800 | [diff] [blame] | 1657 | final int stackBehindFocusedId = (stackBehindFocusedIndex >= 0) |
| 1658 | ? mStacks.get(stackBehindFocusedIndex).mStackId : INVALID_STACK_ID; |
| 1659 | |
Wale Ogunwale | bd26d2a | 2015-09-22 22:08:37 -0700 | [diff] [blame] | 1660 | if (focusedStackId == FULLSCREEN_WORKSPACE_STACK_ID |
Wale Ogunwale | 56d75cf | 2016-03-09 15:14:47 -0800 | [diff] [blame] | 1661 | && focusedStack.isStackTranslucent(starting, stackBehindFocusedId)) { |
Wale Ogunwale | bd26d2a | 2015-09-22 22:08:37 -0700 | [diff] [blame] | 1662 | // Stacks behind the fullscreen stack with a translucent activity are always |
| 1663 | // visible so they can act as a backdrop to the translucent activity. |
| 1664 | // For example, dialog activities |
Wale Ogunwale | 56d75cf | 2016-03-09 15:14:47 -0800 | [diff] [blame] | 1665 | if (stackIndex == stackBehindFocusedIndex) { |
Filip Gruszczynski | 0e381e2 | 2016-01-14 16:31:33 -0800 | [diff] [blame] | 1666 | return STACK_VISIBLE; |
Wale Ogunwale | bd26d2a | 2015-09-22 22:08:37 -0700 | [diff] [blame] | 1667 | } |
Wale Ogunwale | 56d75cf | 2016-03-09 15:14:47 -0800 | [diff] [blame] | 1668 | if (stackBehindFocusedIndex >= 0) { |
| 1669 | if ((stackBehindFocusedId == DOCKED_STACK_ID |
| 1670 | || stackBehindFocusedId == PINNED_STACK_ID) |
| 1671 | && stackIndex == (stackBehindFocusedIndex - 1)) { |
Wale Ogunwale | 99db186 | 2015-10-23 20:08:22 -0700 | [diff] [blame] | 1672 | // The stack behind the docked or pinned stack is also visible so we can have a |
| 1673 | // complete backdrop to the translucent activity when the docked stack is up. |
Filip Gruszczynski | 0e381e2 | 2016-01-14 16:31:33 -0800 | [diff] [blame] | 1674 | return STACK_VISIBLE; |
Wale Ogunwale | bd26d2a | 2015-09-22 22:08:37 -0700 | [diff] [blame] | 1675 | } |
| 1676 | } |
Wale Ogunwale | 1e3523c | 2015-09-16 13:11:10 -0700 | [diff] [blame] | 1677 | } |
| 1678 | |
Wale Ogunwale | 3797c22 | 2015-10-27 14:21:58 -0700 | [diff] [blame] | 1679 | if (StackId.isStaticStack(mStackId)) { |
Wale Ogunwale | 1e3523c | 2015-09-16 13:11:10 -0700 | [diff] [blame] | 1680 | // 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] | 1681 | return STACK_INVISIBLE; |
Wale Ogunwale | ddc1cb2 | 2015-07-25 19:23:04 -0700 | [diff] [blame] | 1682 | } |
| 1683 | |
Wale Ogunwale | b34a7ad | 2015-08-14 11:05:30 -0700 | [diff] [blame] | 1684 | for (int i = stackIndex + 1; i < mStacks.size(); i++) { |
Wale Ogunwale | e4a0c57 | 2015-06-30 08:40:31 -0700 | [diff] [blame] | 1685 | final ActivityStack stack = mStacks.get(i); |
Wale Ogunwale | b34a7ad | 2015-08-14 11:05:30 -0700 | [diff] [blame] | 1686 | |
| 1687 | if (!stack.mFullscreen && !stack.hasFullscreenTask()) { |
| 1688 | continue; |
| 1689 | } |
| 1690 | |
Wale Ogunwale | 3797c22 | 2015-10-27 14:21:58 -0700 | [diff] [blame] | 1691 | if (!StackId.isDynamicStacksVisibleBehindAllowed(stack.mStackId)) { |
Wale Ogunwale | 1e3523c | 2015-09-16 13:11:10 -0700 | [diff] [blame] | 1692 | // These stacks can't have any dynamic stacks visible behind them. |
Filip Gruszczynski | 0e381e2 | 2016-01-14 16:31:33 -0800 | [diff] [blame] | 1693 | return STACK_INVISIBLE; |
Todd Kennedy | aab56db | 2015-01-30 09:39:53 -0800 | [diff] [blame] | 1694 | } |
Wale Ogunwale | ddc1cb2 | 2015-07-25 19:23:04 -0700 | [diff] [blame] | 1695 | |
Wale Ogunwale | 56d75cf | 2016-03-09 15:14:47 -0800 | [diff] [blame] | 1696 | if (!stack.isStackTranslucent(starting, INVALID_STACK_ID)) { |
Filip Gruszczynski | 0e381e2 | 2016-01-14 16:31:33 -0800 | [diff] [blame] | 1697 | return STACK_INVISIBLE; |
Jose Lima | 7ba7125 | 2014-04-30 12:59:27 -0700 | [diff] [blame] | 1698 | } |
| 1699 | } |
| 1700 | |
Filip Gruszczynski | 0e381e2 | 2016-01-14 16:31:33 -0800 | [diff] [blame] | 1701 | return STACK_VISIBLE; |
Jose Lima | 7ba7125 | 2014-04-30 12:59:27 -0700 | [diff] [blame] | 1702 | } |
| 1703 | |
Chong Zhang | fdcc4d4 | 2015-10-14 16:50:12 -0700 | [diff] [blame] | 1704 | final int rankTaskLayers(int baseLayer) { |
| 1705 | int layer = 0; |
| 1706 | for (int taskNdx = mTaskHistory.size() - 1; taskNdx >= 0; --taskNdx) { |
| 1707 | final TaskRecord task = mTaskHistory.get(taskNdx); |
| 1708 | ActivityRecord r = task.topRunningActivityLocked(); |
| 1709 | if (r == null || r.finishing || !r.visible) { |
| 1710 | task.mLayerRank = -1; |
| 1711 | } else { |
| 1712 | task.mLayerRank = baseLayer + layer++; |
| 1713 | } |
| 1714 | } |
| 1715 | return layer; |
| 1716 | } |
| 1717 | |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 1718 | /** |
| 1719 | * Make sure that all activities that need to be visible (that is, they |
| 1720 | * currently can be seen by the user) actually are. |
| 1721 | */ |
Filip Gruszczynski | bc5a6c5 | 2015-09-22 13:13:24 -0700 | [diff] [blame] | 1722 | final void ensureActivitiesVisibleLocked(ActivityRecord starting, int configChanges, |
| 1723 | boolean preserveWindows) { |
Filip Gruszczynski | 3e85ba2 | 2015-10-05 22:48:30 -0700 | [diff] [blame] | 1724 | ActivityRecord top = topRunningActivityLocked(); |
Filip Gruszczynski | 9104aea | 2015-11-13 16:42:05 -0800 | [diff] [blame] | 1725 | if (DEBUG_VISIBILITY) Slog.v(TAG_VISIBILITY, "ensureActivitiesVisible behind " + top |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 1726 | + " configChanges=0x" + Integer.toHexString(configChanges)); |
Filip Gruszczynski | 21199bd | 2015-12-02 12:49:58 -0800 | [diff] [blame] | 1727 | if (top != null) { |
| 1728 | checkTranslucentActivityWaiting(top); |
| 1729 | } |
Craig Mautner | 5eda9b3 | 2013-07-02 11:58:16 -0700 | [diff] [blame] | 1730 | |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 1731 | // If the top activity is not fullscreen, then we need to |
| 1732 | // make sure any activities under it are now visible. |
Filip Gruszczynski | 21199bd | 2015-12-02 12:49:58 -0800 | [diff] [blame] | 1733 | boolean aboveTop = top != null; |
Wale Ogunwale | 8051c5c | 2016-03-04 10:27:32 -0800 | [diff] [blame] | 1734 | final int stackVisibility = getStackVisibilityLocked(starting); |
Filip Gruszczynski | 0e381e2 | 2016-01-14 16:31:33 -0800 | [diff] [blame] | 1735 | final boolean stackInvisible = stackVisibility != STACK_VISIBLE; |
| 1736 | final boolean stackVisibleBehind = stackVisibility == STACK_VISIBLE_ACTIVITY_BEHIND; |
Wale Ogunwale | c219c0b | 2015-09-12 09:18:07 -0700 | [diff] [blame] | 1737 | boolean behindFullscreenActivity = stackInvisible; |
Andrii Kulian | c11ce7b | 2016-06-27 10:53:53 -0700 | [diff] [blame] | 1738 | boolean resumeNextActivity = mStackSupervisor.isFocusedStack(this) |
| 1739 | && (isInStackLocked(starting) == null); |
Filip Gruszczynski | 0e381e2 | 2016-01-14 16:31:33 -0800 | [diff] [blame] | 1740 | boolean behindTranslucentActivity = false; |
| 1741 | final ActivityRecord visibleBehind = getVisibleBehindActivity(); |
Craig Mautner | b59dcfd | 2013-05-06 13:12:58 -0700 | [diff] [blame] | 1742 | for (int taskNdx = mTaskHistory.size() - 1; taskNdx >= 0; --taskNdx) { |
Craig Mautner | ae7ecab | 2013-09-18 11:48:14 -0700 | [diff] [blame] | 1743 | final TaskRecord task = mTaskHistory.get(taskNdx); |
| 1744 | final ArrayList<ActivityRecord> activities = task.mActivities; |
Craig Mautner | d44711d | 2013-02-23 11:24:36 -0800 | [diff] [blame] | 1745 | for (int activityNdx = activities.size() - 1; activityNdx >= 0; --activityNdx) { |
| 1746 | final ActivityRecord r = activities.get(activityNdx); |
| 1747 | if (r.finishing) { |
Chong Zhang | 22bc851 | 2016-04-07 13:47:18 -0700 | [diff] [blame] | 1748 | // Normally the screenshot will be taken in makeInvisible(). When an activity |
| 1749 | // is finishing, we no longer change its visibility, but we still need to take |
| 1750 | // the screenshots if startPausingLocked decided it should be taken. |
| 1751 | if (r.mUpdateTaskThumbnailWhenHidden) { |
| 1752 | r.updateThumbnailLocked(screenshotActivitiesLocked(r), null); |
| 1753 | r.mUpdateTaskThumbnailWhenHidden = false; |
| 1754 | } |
Craig Mautner | d44711d | 2013-02-23 11:24:36 -0800 | [diff] [blame] | 1755 | continue; |
| 1756 | } |
Filip Gruszczynski | 21199bd | 2015-12-02 12:49:58 -0800 | [diff] [blame] | 1757 | final boolean isTop = r == top; |
| 1758 | if (aboveTop && !isTop) { |
Craig Mautner | d44711d | 2013-02-23 11:24:36 -0800 | [diff] [blame] | 1759 | continue; |
| 1760 | } |
| 1761 | aboveTop = false; |
Wale Ogunwale | e76407c | 2016-05-16 17:04:37 -0700 | [diff] [blame] | 1762 | |
| 1763 | if (shouldBeVisible(r, behindTranslucentActivity, stackVisibleBehind, |
| 1764 | visibleBehind, behindFullscreenActivity)) { |
Filip Gruszczynski | 0e381e2 | 2016-01-14 16:31:33 -0800 | [diff] [blame] | 1765 | if (DEBUG_VISIBILITY) Slog.v(TAG_VISIBILITY, "Make visible? " + r |
| 1766 | + " finishing=" + r.finishing + " state=" + r.state); |
Craig Mautner | d44711d | 2013-02-23 11:24:36 -0800 | [diff] [blame] | 1767 | // First: if this is not the current activity being started, make |
| 1768 | // sure it matches the current configuration. |
Craig Mautner | bb74246 | 2014-07-07 15:28:55 -0700 | [diff] [blame] | 1769 | if (r != starting) { |
Filip Gruszczynski | bc5a6c5 | 2015-09-22 13:13:24 -0700 | [diff] [blame] | 1770 | ensureActivityConfigurationLocked(r, 0, preserveWindows); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 1771 | } |
Craig Mautner | d44711d | 2013-02-23 11:24:36 -0800 | [diff] [blame] | 1772 | |
| 1773 | if (r.app == null || r.app.thread == null) { |
Filip Gruszczynski | 21199bd | 2015-12-02 12:49:58 -0800 | [diff] [blame] | 1774 | if (makeVisibleAndRestartIfNeeded(starting, configChanges, isTop, |
Wale Ogunwale | d046a01 | 2015-12-24 13:05:59 -0800 | [diff] [blame] | 1775 | resumeNextActivity, r)) { |
Filip Gruszczynski | 9104aea | 2015-11-13 16:42:05 -0800 | [diff] [blame] | 1776 | if (activityNdx >= activities.size()) { |
| 1777 | // Record may be removed if its process needs to restart. |
| 1778 | activityNdx = activities.size() - 1; |
| 1779 | } else { |
Wale Ogunwale | d046a01 | 2015-12-24 13:05:59 -0800 | [diff] [blame] | 1780 | resumeNextActivity = false; |
riddle_hsu | 36ee73d | 2015-06-05 16:38:38 +0800 | [diff] [blame] | 1781 | } |
Craig Mautner | d44711d | 2013-02-23 11:24:36 -0800 | [diff] [blame] | 1782 | } |
Craig Mautner | d44711d | 2013-02-23 11:24:36 -0800 | [diff] [blame] | 1783 | } else if (r.visible) { |
Filip Gruszczynski | 21199bd | 2015-12-02 12:49:58 -0800 | [diff] [blame] | 1784 | // 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] | 1785 | if (DEBUG_VISIBILITY) Slog.v(TAG_VISIBILITY, |
| 1786 | "Skipping: already visible at " + r); |
| 1787 | |
Filip Gruszczynski | 21199bd | 2015-12-02 12:49:58 -0800 | [diff] [blame] | 1788 | if (handleAlreadyVisible(r)) { |
Wale Ogunwale | d046a01 | 2015-12-24 13:05:59 -0800 | [diff] [blame] | 1789 | resumeNextActivity = false; |
Wale Ogunwale | 85b90ab | 2015-04-27 20:54:47 -0700 | [diff] [blame] | 1790 | } |
Craig Mautner | bb74246 | 2014-07-07 15:28:55 -0700 | [diff] [blame] | 1791 | } else { |
Jorim Jaggi | e66edb1 | 2016-02-05 12:41:17 -0800 | [diff] [blame] | 1792 | makeVisibleIfNeeded(starting, r); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 1793 | } |
Craig Mautner | d44711d | 2013-02-23 11:24:36 -0800 | [diff] [blame] | 1794 | // Aggregate current change flags. |
| 1795 | configChanges |= r.configChangeFlags; |
Filip Gruszczynski | 9104aea | 2015-11-13 16:42:05 -0800 | [diff] [blame] | 1796 | behindFullscreenActivity = updateBehindFullscreen(stackInvisible, |
| 1797 | behindFullscreenActivity, task, r); |
Filip Gruszczynski | 0e381e2 | 2016-01-14 16:31:33 -0800 | [diff] [blame] | 1798 | if (behindFullscreenActivity && !r.fullscreen) { |
| 1799 | behindTranslucentActivity = true; |
| 1800 | } |
Craig Mautner | d44711d | 2013-02-23 11:24:36 -0800 | [diff] [blame] | 1801 | } else { |
Wale Ogunwale | 834c236 | 2016-01-23 18:14:58 -0800 | [diff] [blame] | 1802 | if (DEBUG_VISIBILITY) Slog.v(TAG_VISIBILITY, "Make invisible? " + r |
Filip Gruszczynski | 0e381e2 | 2016-01-14 16:31:33 -0800 | [diff] [blame] | 1803 | + " finishing=" + r.finishing + " state=" + r.state + " stackInvisible=" |
| 1804 | + stackInvisible + " behindFullscreenActivity=" |
| 1805 | + behindFullscreenActivity + " mLaunchTaskBehind=" |
| 1806 | + r.mLaunchTaskBehind); |
| 1807 | makeInvisible(r, visibleBehind); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 1808 | } |
| 1809 | } |
Wale Ogunwale | c219c0b | 2015-09-12 09:18:07 -0700 | [diff] [blame] | 1810 | if (mStackId == FREEFORM_WORKSPACE_STACK_ID) { |
| 1811 | // The visibility of tasks and the activities they contain in freeform stack are |
| 1812 | // determined individually unlike other stacks where the visibility or fullscreen |
| 1813 | // status of an activity in a previous task affects other. |
Filip Gruszczynski | 0e381e2 | 2016-01-14 16:31:33 -0800 | [diff] [blame] | 1814 | behindFullscreenActivity = stackVisibility == STACK_INVISIBLE; |
Wale Ogunwale | 74e2659 | 2016-02-05 11:48:37 -0800 | [diff] [blame] | 1815 | } else if (mStackId == HOME_STACK_ID) { |
Jiaquan He | 9bc01a8 | 2016-07-08 10:29:38 -0700 | [diff] [blame] | 1816 | if (task.isOnTopLauncher()) { |
| 1817 | if (DEBUG_VISIBILITY) Slog.v(TAG_VISIBILITY, "On-top launcher: at " + task |
| 1818 | + " stackInvisible=" + stackInvisible |
| 1819 | + " behindFullscreenActivity=" + behindFullscreenActivity); |
| 1820 | // When an on-top launcher is visible, (e.g. it's on the top of the home stack), |
| 1821 | // other tasks in the home stack could be visible if and only if: |
| 1822 | // - some app is running in the docked stack; |
| 1823 | // - no app is running in either the fullscreen stack or the freefrom stack. |
| 1824 | final ActivityStack dockedStack = mStackSupervisor.getStack(DOCKED_STACK_ID); |
| 1825 | final ActivityStack fullscreenStack = mStackSupervisor.getStack( |
| 1826 | FULLSCREEN_WORKSPACE_STACK_ID); |
| 1827 | final ActivityStack freeformStack = mStackSupervisor.getStack( |
| 1828 | FREEFORM_WORKSPACE_STACK_ID); |
| 1829 | final boolean dockedStackEmpty = dockedStack == null || |
| 1830 | dockedStack.topRunningActivityLocked() == null; |
| 1831 | final boolean fullscreenStackEmpty = fullscreenStack == null || |
| 1832 | fullscreenStack.topRunningActivityLocked() == null; |
| 1833 | final boolean freeformStackEmpty = freeformStack == null || |
| 1834 | freeformStack.topRunningActivityLocked() == null; |
| 1835 | behindFullscreenActivity = dockedStackEmpty || !fullscreenStackEmpty || |
| 1836 | !freeformStackEmpty; |
| 1837 | } else if (task.isHomeTask()) { |
Wale Ogunwale | 74e2659 | 2016-02-05 11:48:37 -0800 | [diff] [blame] | 1838 | if (DEBUG_VISIBILITY) Slog.v(TAG_VISIBILITY, "Home task: at " + task |
| 1839 | + " stackInvisible=" + stackInvisible |
| 1840 | + " behindFullscreenActivity=" + behindFullscreenActivity); |
| 1841 | // No other task in the home stack should be visible behind the home activity. |
| 1842 | // Home activities is usually a translucent activity with the wallpaper behind |
| 1843 | // them. However, when they don't have the wallpaper behind them, we want to |
| 1844 | // show activities in the next application stack behind them vs. another |
| 1845 | // task in the home stack like recents. |
| 1846 | behindFullscreenActivity = true; |
| 1847 | } else if (task.isRecentsTask() |
| 1848 | && task.getTaskToReturnTo() == APPLICATION_ACTIVITY_TYPE) { |
| 1849 | if (DEBUG_VISIBILITY) Slog.v(TAG_VISIBILITY, |
| 1850 | "Recents task returning to app: at " + task |
| 1851 | + " stackInvisible=" + stackInvisible |
| 1852 | + " behindFullscreenActivity=" + behindFullscreenActivity); |
| 1853 | // We don't want any other tasks in the home stack visible if the recents |
| 1854 | // activity is going to be returning to an application activity type. |
| 1855 | // We do this to preserve the visible order the user used to get into the |
| 1856 | // recents activity. The recents activity is normally translucent and if it |
| 1857 | // doesn't have the wallpaper behind it the next activity in the home stack |
| 1858 | // shouldn't be visible when the home stack is brought to the front to display |
| 1859 | // the recents activity from an app. |
| 1860 | behindFullscreenActivity = true; |
| 1861 | } |
| 1862 | |
Wale Ogunwale | c219c0b | 2015-09-12 09:18:07 -0700 | [diff] [blame] | 1863 | } |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 1864 | } |
Craig Mautner | eb8abf7 | 2014-07-02 15:04:09 -0700 | [diff] [blame] | 1865 | |
| 1866 | if (mTranslucentActivityWaiting != null && |
| 1867 | mUndrawnActivitiesBelowTopTranslucent.isEmpty()) { |
| 1868 | // Nothing is getting drawn or everything was already visible, don't wait for timeout. |
| 1869 | notifyActivityDrawnLocked(null); |
| 1870 | } |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 1871 | } |
Craig Mautner | 5854780 | 2013-03-05 08:23:53 -0800 | [diff] [blame] | 1872 | |
Wale Ogunwale | e76407c | 2016-05-16 17:04:37 -0700 | [diff] [blame] | 1873 | /** Return true if the input activity should be made visible */ |
| 1874 | private boolean shouldBeVisible(ActivityRecord r, boolean behindTranslucentActivity, |
| 1875 | boolean stackVisibleBehind, ActivityRecord visibleBehind, |
| 1876 | boolean behindFullscreenActivity) { |
Wale Ogunwale | e76407c | 2016-05-16 17:04:37 -0700 | [diff] [blame] | 1877 | |
Chong Zhang | 8776197 | 2016-08-22 13:53:24 -0700 | [diff] [blame] | 1878 | if (r == null || !r.okToShowLocked()) { |
Wale Ogunwale | e76407c | 2016-05-16 17:04:37 -0700 | [diff] [blame] | 1879 | return false; |
| 1880 | } |
| 1881 | |
Wale Ogunwale | 8c09c7d | 2016-05-23 09:10:24 -0700 | [diff] [blame] | 1882 | // mLaunchingBehind: Activities launching behind are at the back of the task stack |
| 1883 | // but must be drawn initially for the animation as though they were visible. |
| 1884 | final boolean activityVisibleBehind = |
| 1885 | (behindTranslucentActivity || stackVisibleBehind) && visibleBehind == r; |
| 1886 | |
Wale Ogunwale | e76407c | 2016-05-16 17:04:37 -0700 | [diff] [blame] | 1887 | boolean isVisible = |
| 1888 | !behindFullscreenActivity || r.mLaunchTaskBehind || activityVisibleBehind; |
| 1889 | |
Wale Ogunwale | ca2af9e | 2016-05-26 14:43:19 -0700 | [diff] [blame] | 1890 | if (mService.mSupportsLeanbackOnly && isVisible && r.isRecentsActivity()) { |
| 1891 | // On devices that support leanback only (Android TV), Recents activity can only be |
| 1892 | // 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] | 1893 | isVisible = mStackSupervisor.getStack(DOCKED_STACK_ID) != null |
| 1894 | || mStackSupervisor.isFocusedStack(this); |
Wale Ogunwale | e76407c | 2016-05-16 17:04:37 -0700 | [diff] [blame] | 1895 | } |
| 1896 | |
| 1897 | return isVisible; |
| 1898 | } |
| 1899 | |
Filip Gruszczynski | 9104aea | 2015-11-13 16:42:05 -0800 | [diff] [blame] | 1900 | private void checkTranslucentActivityWaiting(ActivityRecord top) { |
| 1901 | if (mTranslucentActivityWaiting != top) { |
| 1902 | mUndrawnActivitiesBelowTopTranslucent.clear(); |
| 1903 | if (mTranslucentActivityWaiting != null) { |
| 1904 | // Call the callback with a timeout indication. |
| 1905 | notifyActivityDrawnLocked(null); |
| 1906 | mTranslucentActivityWaiting = null; |
| 1907 | } |
| 1908 | mHandler.removeMessages(TRANSLUCENT_TIMEOUT_MSG); |
| 1909 | } |
| 1910 | } |
| 1911 | |
| 1912 | private boolean makeVisibleAndRestartIfNeeded(ActivityRecord starting, int configChanges, |
Wale Ogunwale | d046a01 | 2015-12-24 13:05:59 -0800 | [diff] [blame] | 1913 | boolean isTop, boolean andResume, ActivityRecord r) { |
Filip Gruszczynski | 9104aea | 2015-11-13 16:42:05 -0800 | [diff] [blame] | 1914 | // We need to make sure the app is running if it's the top, or it is just made visible from |
| 1915 | // invisible. If the app is already visible, it must have died while it was visible. In this |
| 1916 | // case, we'll show the dead window but will not restart the app. Otherwise we could end up |
| 1917 | // thrashing. |
Filip Gruszczynski | 21199bd | 2015-12-02 12:49:58 -0800 | [diff] [blame] | 1918 | if (isTop || !r.visible) { |
Filip Gruszczynski | 9104aea | 2015-11-13 16:42:05 -0800 | [diff] [blame] | 1919 | // This activity needs to be visible, but isn't even running... |
| 1920 | // get it started and resume if no other stack in this stack is resumed. |
| 1921 | if (DEBUG_VISIBILITY) Slog.v(TAG_VISIBILITY, "Start and freeze screen for " + r); |
| 1922 | if (r != starting) { |
| 1923 | r.startFreezingScreenLocked(r.app, configChanges); |
| 1924 | } |
| 1925 | if (!r.visible || r.mLaunchTaskBehind) { |
| 1926 | if (DEBUG_VISIBILITY) Slog.v(TAG_VISIBILITY, "Starting and making visible: " + r); |
| 1927 | setVisible(r, true); |
| 1928 | } |
| 1929 | if (r != starting) { |
Wale Ogunwale | d046a01 | 2015-12-24 13:05:59 -0800 | [diff] [blame] | 1930 | mStackSupervisor.startSpecificActivityLocked(r, andResume, false); |
Filip Gruszczynski | 9104aea | 2015-11-13 16:42:05 -0800 | [diff] [blame] | 1931 | return true; |
| 1932 | } |
| 1933 | } |
| 1934 | return false; |
| 1935 | } |
| 1936 | |
Filip Gruszczynski | 0e381e2 | 2016-01-14 16:31:33 -0800 | [diff] [blame] | 1937 | private void makeInvisible(ActivityRecord r, ActivityRecord visibleBehind) { |
Filip Gruszczynski | 9104aea | 2015-11-13 16:42:05 -0800 | [diff] [blame] | 1938 | if (!r.visible) { |
| 1939 | if (DEBUG_VISIBILITY) Slog.v(TAG_VISIBILITY, "Already invisible: " + r); |
| 1940 | return; |
| 1941 | } |
| 1942 | // Now for any activities that aren't visible to the user, make sure they no longer are |
| 1943 | // keeping the screen frozen. |
Filip Gruszczynski | 4e7fe71 | 2016-01-13 13:22:44 -0800 | [diff] [blame] | 1944 | if (DEBUG_VISIBILITY) Slog.v(TAG_VISIBILITY, "Making invisible: " + r + " " + r.state); |
Filip Gruszczynski | 9104aea | 2015-11-13 16:42:05 -0800 | [diff] [blame] | 1945 | try { |
| 1946 | setVisible(r, false); |
| 1947 | switch (r.state) { |
| 1948 | case STOPPING: |
| 1949 | case STOPPED: |
| 1950 | if (r.app != null && r.app.thread != null) { |
| 1951 | if (DEBUG_VISIBILITY) Slog.v(TAG_VISIBILITY, |
| 1952 | "Scheduling invisibility: " + r); |
| 1953 | r.app.thread.scheduleWindowVisibility(r.appToken, false); |
| 1954 | } |
| 1955 | break; |
| 1956 | |
| 1957 | case INITIALIZING: |
| 1958 | case RESUMED: |
| 1959 | case PAUSING: |
| 1960 | case PAUSED: |
| 1961 | // This case created for transitioning activities from |
| 1962 | // translucent to opaque {@link Activity#convertToOpaque}. |
Filip Gruszczynski | 0e381e2 | 2016-01-14 16:31:33 -0800 | [diff] [blame] | 1963 | if (visibleBehind == r) { |
Filip Gruszczynski | 9104aea | 2015-11-13 16:42:05 -0800 | [diff] [blame] | 1964 | releaseBackgroundResources(r); |
| 1965 | } else { |
Chong Zhang | 46b1ac6 | 2016-02-18 17:53:57 -0800 | [diff] [blame] | 1966 | addToStopping(r, true /* immediate */); |
Filip Gruszczynski | 9104aea | 2015-11-13 16:42:05 -0800 | [diff] [blame] | 1967 | } |
| 1968 | break; |
| 1969 | |
| 1970 | default: |
| 1971 | break; |
| 1972 | } |
| 1973 | } catch (Exception e) { |
| 1974 | // Just skip on any failure; we'll make it visible when it next restarts. |
| 1975 | Slog.w(TAG, "Exception thrown making hidden: " + r.intent.getComponent(), e); |
| 1976 | } |
| 1977 | } |
| 1978 | |
| 1979 | private boolean updateBehindFullscreen(boolean stackInvisible, boolean behindFullscreenActivity, |
| 1980 | TaskRecord task, ActivityRecord r) { |
| 1981 | if (r.fullscreen) { |
Filip Gruszczynski | 9104aea | 2015-11-13 16:42:05 -0800 | [diff] [blame] | 1982 | if (DEBUG_VISIBILITY) Slog.v(TAG_VISIBILITY, "Fullscreen: at " + r |
Wale Ogunwale | 673cbd2 | 2016-01-30 18:30:55 -0800 | [diff] [blame] | 1983 | + " stackInvisible=" + stackInvisible |
| 1984 | + " behindFullscreenActivity=" + behindFullscreenActivity); |
Filip Gruszczynski | 0e381e2 | 2016-01-14 16:31:33 -0800 | [diff] [blame] | 1985 | // At this point, nothing else needs to be shown in this task. |
Filip Gruszczynski | 9104aea | 2015-11-13 16:42:05 -0800 | [diff] [blame] | 1986 | behindFullscreenActivity = true; |
Wale Ogunwale | 74e2659 | 2016-02-05 11:48:37 -0800 | [diff] [blame] | 1987 | } else if (!isHomeStack() && r.frontOfTask && task.isOverHomeStack()) { |
Filip Gruszczynski | 9104aea | 2015-11-13 16:42:05 -0800 | [diff] [blame] | 1988 | if (DEBUG_VISIBILITY) Slog.v(TAG_VISIBILITY, "Showing home: at " + r |
| 1989 | + " stackInvisible=" + stackInvisible |
| 1990 | + " behindFullscreenActivity=" + behindFullscreenActivity); |
Filip Gruszczynski | 0e381e2 | 2016-01-14 16:31:33 -0800 | [diff] [blame] | 1991 | behindFullscreenActivity = true; |
Filip Gruszczynski | 9104aea | 2015-11-13 16:42:05 -0800 | [diff] [blame] | 1992 | } |
| 1993 | return behindFullscreenActivity; |
| 1994 | } |
| 1995 | |
Jorim Jaggi | e66edb1 | 2016-02-05 12:41:17 -0800 | [diff] [blame] | 1996 | private void makeVisibleIfNeeded(ActivityRecord starting, ActivityRecord r) { |
| 1997 | |
Filip Gruszczynski | 9104aea | 2015-11-13 16:42:05 -0800 | [diff] [blame] | 1998 | // 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] | 1999 | if (r.state == ActivityState.RESUMED || r == starting) { |
Chong Zhang | e05db74 | 2016-02-16 16:58:37 -0800 | [diff] [blame] | 2000 | if (DEBUG_VISIBILITY) Slog.d(TAG_VISIBILITY, |
| 2001 | "Not making visible, r=" + r + " state=" + r.state + " starting=" + starting); |
Jorim Jaggi | e66edb1 | 2016-02-05 12:41:17 -0800 | [diff] [blame] | 2002 | return; |
| 2003 | } |
| 2004 | |
| 2005 | // If this activity is paused, tell it to now show its window. |
| 2006 | if (DEBUG_VISIBILITY) Slog.v(TAG_VISIBILITY, |
| 2007 | "Making visible and scheduling visibility: " + r); |
| 2008 | try { |
| 2009 | if (mTranslucentActivityWaiting != null) { |
| 2010 | r.updateOptionsLocked(r.returningOptions); |
| 2011 | mUndrawnActivitiesBelowTopTranslucent.add(r); |
Filip Gruszczynski | 9104aea | 2015-11-13 16:42:05 -0800 | [diff] [blame] | 2012 | } |
Jorim Jaggi | e66edb1 | 2016-02-05 12:41:17 -0800 | [diff] [blame] | 2013 | setVisible(r, true); |
| 2014 | r.sleeping = false; |
| 2015 | r.app.pendingUiClean = true; |
| 2016 | r.app.thread.scheduleWindowVisibility(r.appToken, true); |
Jorim Jaggi | d47e7e1 | 2016-03-01 09:57:38 +0100 | [diff] [blame] | 2017 | // The activity may be waiting for stop, but that is no longer |
| 2018 | // appropriate for it. |
| 2019 | mStackSupervisor.mStoppingActivities.remove(r); |
| 2020 | mStackSupervisor.mGoingToSleepActivities.remove(r); |
Jorim Jaggi | e66edb1 | 2016-02-05 12:41:17 -0800 | [diff] [blame] | 2021 | } catch (Exception e) { |
| 2022 | // Just skip on any failure; we'll make it |
| 2023 | // visible when it next restarts. |
| 2024 | Slog.w(TAG, "Exception thrown making visibile: " + r.intent.getComponent(), e); |
Filip Gruszczynski | 9104aea | 2015-11-13 16:42:05 -0800 | [diff] [blame] | 2025 | } |
Chong Zhang | 371c442 | 2016-05-11 10:48:32 -0700 | [diff] [blame] | 2026 | handleAlreadyVisible(r); |
Filip Gruszczynski | 9104aea | 2015-11-13 16:42:05 -0800 | [diff] [blame] | 2027 | } |
| 2028 | |
Filip Gruszczynski | 21199bd | 2015-12-02 12:49:58 -0800 | [diff] [blame] | 2029 | private boolean handleAlreadyVisible(ActivityRecord r) { |
Filip Gruszczynski | 9104aea | 2015-11-13 16:42:05 -0800 | [diff] [blame] | 2030 | r.stopFreezingScreenLocked(false); |
| 2031 | try { |
| 2032 | if (r.returningOptions != null) { |
| 2033 | r.app.thread.scheduleOnNewActivityOptions(r.appToken, r.returningOptions); |
| 2034 | } |
| 2035 | } catch(RemoteException e) { |
| 2036 | } |
| 2037 | return r.state == ActivityState.RESUMED; |
| 2038 | } |
| 2039 | |
Todd Kennedy | aab56db | 2015-01-30 09:39:53 -0800 | [diff] [blame] | 2040 | void convertActivityToTranslucent(ActivityRecord r) { |
Craig Mautner | 5eda9b3 | 2013-07-02 11:58:16 -0700 | [diff] [blame] | 2041 | mTranslucentActivityWaiting = r; |
| 2042 | mUndrawnActivitiesBelowTopTranslucent.clear(); |
| 2043 | mHandler.sendEmptyMessageDelayed(TRANSLUCENT_TIMEOUT_MSG, TRANSLUCENT_CONVERSION_TIMEOUT); |
| 2044 | } |
| 2045 | |
Dianne Hackborn | b5a380d | 2015-05-20 18:18:46 -0700 | [diff] [blame] | 2046 | void clearOtherAppTimeTrackers(AppTimeTracker except) { |
| 2047 | for (int taskNdx = mTaskHistory.size() - 1; taskNdx >= 0; --taskNdx) { |
| 2048 | final TaskRecord task = mTaskHistory.get(taskNdx); |
| 2049 | final ArrayList<ActivityRecord> activities = task.mActivities; |
| 2050 | for (int activityNdx = activities.size() - 1; activityNdx >= 0; --activityNdx) { |
| 2051 | final ActivityRecord r = activities.get(activityNdx); |
| 2052 | if ( r.appTimeTracker != except) { |
| 2053 | r.appTimeTracker = null; |
| 2054 | } |
| 2055 | } |
| 2056 | } |
| 2057 | } |
| 2058 | |
Craig Mautner | 5eda9b3 | 2013-07-02 11:58:16 -0700 | [diff] [blame] | 2059 | /** |
| 2060 | * Called as activities below the top translucent activity are redrawn. When the last one is |
| 2061 | * redrawn notify the top activity by calling |
| 2062 | * {@link Activity#onTranslucentConversionComplete}. |
| 2063 | * |
| 2064 | * @param r The most recent background activity to be drawn. Or, if r is null then a timeout |
| 2065 | * occurred and the activity will be notified immediately. |
| 2066 | */ |
| 2067 | void notifyActivityDrawnLocked(ActivityRecord r) { |
Craig Mautner | 6985bad | 2014-04-21 15:22:06 -0700 | [diff] [blame] | 2068 | mActivityContainer.setDrawn(); |
Craig Mautner | 5eda9b3 | 2013-07-02 11:58:16 -0700 | [diff] [blame] | 2069 | if ((r == null) |
| 2070 | || (mUndrawnActivitiesBelowTopTranslucent.remove(r) && |
| 2071 | mUndrawnActivitiesBelowTopTranslucent.isEmpty())) { |
| 2072 | // The last undrawn activity below the top has just been drawn. If there is an |
| 2073 | // opaque activity at the top, notify it that it can become translucent safely now. |
| 2074 | final ActivityRecord waitingActivity = mTranslucentActivityWaiting; |
| 2075 | mTranslucentActivityWaiting = null; |
| 2076 | mUndrawnActivitiesBelowTopTranslucent.clear(); |
| 2077 | mHandler.removeMessages(TRANSLUCENT_TIMEOUT_MSG); |
| 2078 | |
Craig Mautner | 71dd1b6 | 2014-02-18 15:48:52 -0800 | [diff] [blame] | 2079 | if (waitingActivity != null) { |
| 2080 | mWindowManager.setWindowOpaque(waitingActivity.appToken, false); |
| 2081 | if (waitingActivity.app != null && waitingActivity.app.thread != null) { |
| 2082 | try { |
| 2083 | waitingActivity.app.thread.scheduleTranslucentConversionComplete( |
| 2084 | waitingActivity.appToken, r != null); |
| 2085 | } catch (RemoteException e) { |
| 2086 | } |
Craig Mautner | 5eda9b3 | 2013-07-02 11:58:16 -0700 | [diff] [blame] | 2087 | } |
| 2088 | } |
| 2089 | } |
| 2090 | } |
| 2091 | |
Craig Mautner | a61bc65 | 2013-10-28 15:43:18 -0700 | [diff] [blame] | 2092 | /** If any activities below the top running one are in the INITIALIZING state and they have a |
| 2093 | * starting window displayed then remove that starting window. It is possible that the activity |
| 2094 | * in this state will never resumed in which case that starting window will be orphaned. */ |
| 2095 | void cancelInitializingActivities() { |
Filip Gruszczynski | 3e85ba2 | 2015-10-05 22:48:30 -0700 | [diff] [blame] | 2096 | final ActivityRecord topActivity = topRunningActivityLocked(); |
Craig Mautner | a61bc65 | 2013-10-28 15:43:18 -0700 | [diff] [blame] | 2097 | boolean aboveTop = true; |
Wale Ogunwale | 6874114 | 2016-05-17 09:40:02 -0700 | [diff] [blame] | 2098 | // We don't want to clear starting window for activities that aren't behind fullscreen |
| 2099 | // activities as we need to display their starting window until they are done initializing. |
| 2100 | boolean behindFullscreenActivity = false; |
Wale Ogunwale | 98742a5 | 2016-07-12 10:29:12 -0700 | [diff] [blame] | 2101 | |
| 2102 | if (getStackVisibilityLocked(null) == STACK_INVISIBLE) { |
| 2103 | // The stack is not visible, so no activity in it should be displaying a starting |
| 2104 | // window. Mark all activities below top and behind fullscreen. |
| 2105 | aboveTop = false; |
| 2106 | behindFullscreenActivity = true; |
| 2107 | } |
| 2108 | |
Craig Mautner | a61bc65 | 2013-10-28 15:43:18 -0700 | [diff] [blame] | 2109 | for (int taskNdx = mTaskHistory.size() - 1; taskNdx >= 0; --taskNdx) { |
| 2110 | final ArrayList<ActivityRecord> activities = mTaskHistory.get(taskNdx).mActivities; |
| 2111 | for (int activityNdx = activities.size() - 1; activityNdx >= 0; --activityNdx) { |
| 2112 | final ActivityRecord r = activities.get(activityNdx); |
| 2113 | if (aboveTop) { |
| 2114 | if (r == topActivity) { |
| 2115 | aboveTop = false; |
| 2116 | } |
Wale Ogunwale | 6874114 | 2016-05-17 09:40:02 -0700 | [diff] [blame] | 2117 | behindFullscreenActivity |= r.fullscreen; |
Craig Mautner | a61bc65 | 2013-10-28 15:43:18 -0700 | [diff] [blame] | 2118 | continue; |
| 2119 | } |
| 2120 | |
Wale Ogunwale | f40c11b | 2016-02-26 08:16:02 -0800 | [diff] [blame] | 2121 | if (r.state == ActivityState.INITIALIZING |
Wale Ogunwale | 6874114 | 2016-05-17 09:40:02 -0700 | [diff] [blame] | 2122 | && r.mStartingWindowState == STARTING_WINDOW_SHOWN |
| 2123 | && behindFullscreenActivity) { |
Wale Ogunwale | ee006da | 2015-03-30 14:49:25 -0700 | [diff] [blame] | 2124 | if (DEBUG_VISIBILITY) Slog.w(TAG_VISIBILITY, |
| 2125 | "Found orphaned starting window " + r); |
Wale Ogunwale | f40c11b | 2016-02-26 08:16:02 -0800 | [diff] [blame] | 2126 | r.mStartingWindowState = STARTING_WINDOW_REMOVED; |
Craig Mautner | a61bc65 | 2013-10-28 15:43:18 -0700 | [diff] [blame] | 2127 | mWindowManager.removeAppStartingWindow(r.appToken); |
| 2128 | } |
Wale Ogunwale | 6874114 | 2016-05-17 09:40:02 -0700 | [diff] [blame] | 2129 | |
| 2130 | behindFullscreenActivity |= r.fullscreen; |
Craig Mautner | a61bc65 | 2013-10-28 15:43:18 -0700 | [diff] [blame] | 2131 | } |
| 2132 | } |
| 2133 | } |
| 2134 | |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 2135 | /** |
| 2136 | * Ensure that the top activity in the stack is resumed. |
| 2137 | * |
| 2138 | * @param prev The previously resumed activity, for when in the process |
| 2139 | * of pausing; can be null to call from elsewhere. |
Wale Ogunwale | d046a01 | 2015-12-24 13:05:59 -0800 | [diff] [blame] | 2140 | * @param options Activity options. |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 2141 | * |
| 2142 | * @return Returns true if something is being resumed, or false if |
| 2143 | * nothing happened. |
Wale Ogunwale | d046a01 | 2015-12-24 13:05:59 -0800 | [diff] [blame] | 2144 | * |
| 2145 | * NOTE: It is not safe to call this method directly as it can cause an activity in a |
| 2146 | * non-focused stack to be resumed. |
| 2147 | * Use {@link ActivityStackSupervisor#resumeFocusedStackTopActivityLocked} to resume the |
| 2148 | * right activity for the current system state. |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 2149 | */ |
Wale Ogunwale | d046a01 | 2015-12-24 13:05:59 -0800 | [diff] [blame] | 2150 | boolean resumeTopActivityUncheckedLocked(ActivityRecord prev, ActivityOptions options) { |
Craig Mautner | 42d04db | 2014-11-06 12:13:23 -0800 | [diff] [blame] | 2151 | if (mStackSupervisor.inResumeTopActivity) { |
Craig Mautner | 544efa7 | 2014-09-04 16:41:20 -0700 | [diff] [blame] | 2152 | // Don't even start recursing. |
| 2153 | return false; |
| 2154 | } |
| 2155 | |
| 2156 | boolean result = false; |
| 2157 | try { |
| 2158 | // Protect against recursion. |
Craig Mautner | 42d04db | 2014-11-06 12:13:23 -0800 | [diff] [blame] | 2159 | mStackSupervisor.inResumeTopActivity = true; |
| 2160 | if (mService.mLockScreenShown == ActivityManagerService.LOCK_SCREEN_LEAVING) { |
| 2161 | mService.mLockScreenShown = ActivityManagerService.LOCK_SCREEN_HIDDEN; |
Jeff Brown | 9ef9401 | 2014-11-21 13:04:42 -0800 | [diff] [blame] | 2162 | mService.updateSleepIfNeededLocked(); |
Craig Mautner | 42d04db | 2014-11-06 12:13:23 -0800 | [diff] [blame] | 2163 | } |
Craig Mautner | 544efa7 | 2014-09-04 16:41:20 -0700 | [diff] [blame] | 2164 | result = resumeTopActivityInnerLocked(prev, options); |
| 2165 | } finally { |
Craig Mautner | 42d04db | 2014-11-06 12:13:23 -0800 | [diff] [blame] | 2166 | mStackSupervisor.inResumeTopActivity = false; |
Craig Mautner | 544efa7 | 2014-09-04 16:41:20 -0700 | [diff] [blame] | 2167 | } |
| 2168 | return result; |
| 2169 | } |
| 2170 | |
Chong Zhang | 6cda19c | 2016-06-14 19:07:56 -0700 | [diff] [blame] | 2171 | void setResumedActivityLocked(ActivityRecord r, String reason) { |
| 2172 | // TODO: move mResumedActivity to stack supervisor, |
| 2173 | // there should only be 1 global copy of resumed activity. |
| 2174 | mResumedActivity = r; |
Chong Zhang | d2cb311 | 2016-07-20 11:13:22 -0700 | [diff] [blame] | 2175 | r.state = ActivityState.RESUMED; |
Chong Zhang | 6cda19c | 2016-06-14 19:07:56 -0700 | [diff] [blame] | 2176 | mService.setResumedActivityUncheckLocked(r, reason); |
| 2177 | r.task.touchActiveTime(); |
| 2178 | mRecentTasks.addLocked(r.task); |
| 2179 | } |
| 2180 | |
Chong Zhang | 280d332 | 2015-11-03 17:27:26 -0800 | [diff] [blame] | 2181 | private boolean resumeTopActivityInnerLocked(ActivityRecord prev, ActivityOptions options) { |
Wale Ogunwale | ee006da | 2015-03-30 14:49:25 -0700 | [diff] [blame] | 2182 | if (DEBUG_LOCKSCREEN) mService.logLockScreen(""); |
Craig Mautner | 5314a40 | 2013-09-26 12:40:16 -0700 | [diff] [blame] | 2183 | |
Dianne Hackborn | 7622a0f | 2014-09-30 14:31:42 -0700 | [diff] [blame] | 2184 | if (!mService.mBooting && !mService.mBooted) { |
| 2185 | // Not ready yet! |
| 2186 | return false; |
| 2187 | } |
| 2188 | |
Craig Mautner | df88d73 | 2014-01-27 09:21:32 -0800 | [diff] [blame] | 2189 | ActivityRecord parent = mActivityContainer.mParentActivity; |
Craig Mautner | f4c909b | 2014-04-17 18:39:38 -0700 | [diff] [blame] | 2190 | if ((parent != null && parent.state != ActivityState.RESUMED) || |
Craig Mautner | d163e75 | 2014-06-13 17:18:47 -0700 | [diff] [blame] | 2191 | !mActivityContainer.isAttachedLocked()) { |
Craig Mautner | df88d73 | 2014-01-27 09:21:32 -0800 | [diff] [blame] | 2192 | // Do not resume this stack if its parent is not resumed. |
| 2193 | // TODO: If in a loop, make sure that parent stack resumeTopActivity is called 1st. |
| 2194 | return false; |
| 2195 | } |
| 2196 | |
Wale Ogunwale | 2be760d | 2016-02-17 11:16:10 -0800 | [diff] [blame] | 2197 | mStackSupervisor.cancelInitializingActivities(); |
Craig Mautner | a61bc65 | 2013-10-28 15:43:18 -0700 | [diff] [blame] | 2198 | |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 2199 | // Find the first activity that is not finishing. |
Filip Gruszczynski | 3e85ba2 | 2015-10-05 22:48:30 -0700 | [diff] [blame] | 2200 | final ActivityRecord next = topRunningActivityLocked(); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 2201 | |
| 2202 | // Remember how we'll process this pause/resume situation, and ensure |
| 2203 | // that the state is reset however we wind up proceeding. |
Craig Mautner | de4ef02 | 2013-04-07 19:01:33 -0700 | [diff] [blame] | 2204 | final boolean userLeaving = mStackSupervisor.mUserLeaving; |
| 2205 | mStackSupervisor.mUserLeaving = false; |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 2206 | |
Craig Mautner | 84984fa | 2014-06-19 11:19:20 -0700 | [diff] [blame] | 2207 | final TaskRecord prevTask = prev != null ? prev.task : null; |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 2208 | if (next == null) { |
Wale Ogunwale | d697cea | 2015-02-20 17:19:49 -0800 | [diff] [blame] | 2209 | // There are no more activities! |
| 2210 | final String reason = "noMoreActivities"; |
Wale Ogunwale | d34e80c | 2016-03-23 17:08:44 -0700 | [diff] [blame] | 2211 | final int returnTaskType = prevTask == null || !prevTask.isOverHomeStack() |
| 2212 | ? HOME_ACTIVITY_TYPE : prevTask.getTaskToReturnTo(); |
| 2213 | if (!mFullscreen && adjustFocusToNextFocusableStackLocked(returnTaskType, reason)) { |
Wale Ogunwale | d697cea | 2015-02-20 17:19:49 -0800 | [diff] [blame] | 2214 | // Try to move focus to the next visible stack with a running activity if this |
| 2215 | // stack is not covering the entire screen. |
Wale Ogunwale | 4cea0f5 | 2015-12-25 06:30:31 -0800 | [diff] [blame] | 2216 | return mStackSupervisor.resumeFocusedStackTopActivityLocked( |
| 2217 | mStackSupervisor.getFocusedStack(), prev, null); |
Wale Ogunwale | d697cea | 2015-02-20 17:19:49 -0800 | [diff] [blame] | 2218 | } |
Wale Ogunwale | 4cea0f5 | 2015-12-25 06:30:31 -0800 | [diff] [blame] | 2219 | |
Wale Ogunwale | d697cea | 2015-02-20 17:19:49 -0800 | [diff] [blame] | 2220 | // Let's just start up the Launcher... |
Craig Mautner | de4ef02 | 2013-04-07 19:01:33 -0700 | [diff] [blame] | 2221 | ActivityOptions.abort(options); |
Wale Ogunwale | 0fc365c | 2015-05-25 19:35:42 -0700 | [diff] [blame] | 2222 | if (DEBUG_STATES) Slog.d(TAG_STATES, |
| 2223 | "resumeTopActivityLocked: No more activities go home"); |
Craig Mautner | cf910b0 | 2013-04-23 11:23:27 -0700 | [diff] [blame] | 2224 | if (DEBUG_STACK) mStackSupervisor.validateTopActivitiesLocked(); |
Craig Mautner | e0a3884 | 2013-12-16 16:14:02 -0800 | [diff] [blame] | 2225 | // Only resume home if on home display |
Craig Mautner | 84984fa | 2014-06-19 11:19:20 -0700 | [diff] [blame] | 2226 | return isOnHomeDisplay() && |
Wale Ogunwale | d697cea | 2015-02-20 17:19:49 -0800 | [diff] [blame] | 2227 | mStackSupervisor.resumeHomeStackTask(returnTaskType, prev, reason); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 2228 | } |
| 2229 | |
| 2230 | next.delayedResume = false; |
Craig Mautner | 5854780 | 2013-03-05 08:23:53 -0800 | [diff] [blame] | 2231 | |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 2232 | // If the top activity is the resumed one, nothing to do. |
Craig Mautner | de4ef02 | 2013-04-07 19:01:33 -0700 | [diff] [blame] | 2233 | if (mResumedActivity == next && next.state == ActivityState.RESUMED && |
| 2234 | mStackSupervisor.allResumedActivitiesComplete()) { |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 2235 | // Make sure we have executed any pending transitions, since there |
| 2236 | // should be nothing left to do at this point. |
Craig Mautner | ce5f3cb | 2013-04-22 08:58:54 -0700 | [diff] [blame] | 2237 | mWindowManager.executeAppTransition(); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 2238 | mNoAnimActivities.clear(); |
Dianne Hackborn | 8437587 | 2012-06-01 19:03:50 -0700 | [diff] [blame] | 2239 | ActivityOptions.abort(options); |
Wale Ogunwale | 0fc365c | 2015-05-25 19:35:42 -0700 | [diff] [blame] | 2240 | if (DEBUG_STATES) Slog.d(TAG_STATES, |
| 2241 | "resumeTopActivityLocked: Top activity resumed " + next); |
Craig Mautner | cf910b0 | 2013-04-23 11:23:27 -0700 | [diff] [blame] | 2242 | if (DEBUG_STACK) mStackSupervisor.validateTopActivitiesLocked(); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 2243 | return false; |
| 2244 | } |
| 2245 | |
Craig Mautner | 525f3d9 | 2013-05-07 14:01:50 -0700 | [diff] [blame] | 2246 | final TaskRecord nextTask = next.task; |
bulic | ccd23071 | 2014-05-12 14:34:50 -0700 | [diff] [blame] | 2247 | if (prevTask != null && prevTask.stack == this && |
Craig Mautner | 84984fa | 2014-06-19 11:19:20 -0700 | [diff] [blame] | 2248 | prevTask.isOverHomeStack() && prev.finishing && prev.frontOfTask) { |
Craig Mautner | cf910b0 | 2013-04-23 11:23:27 -0700 | [diff] [blame] | 2249 | if (DEBUG_STACK) mStackSupervisor.validateTopActivitiesLocked(); |
Craig Mautner | 525f3d9 | 2013-05-07 14:01:50 -0700 | [diff] [blame] | 2250 | if (prevTask == nextTask) { |
Craig Mautner | 1aa9d0d3f | 2013-12-16 15:58:31 -0800 | [diff] [blame] | 2251 | prevTask.setFrontOfTask(); |
Craig Mautner | 525f3d9 | 2013-05-07 14:01:50 -0700 | [diff] [blame] | 2252 | } else if (prevTask != topTask()) { |
Craig Mautner | 84984fa | 2014-06-19 11:19:20 -0700 | [diff] [blame] | 2253 | // 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] | 2254 | // 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] | 2255 | final int taskNdx = mTaskHistory.indexOf(prevTask) + 1; |
Craig Mautner | 84984fa | 2014-06-19 11:19:20 -0700 | [diff] [blame] | 2256 | mTaskHistory.get(taskNdx).setTaskToReturnTo(HOME_ACTIVITY_TYPE); |
louis_chang | 2d094e9 | 2015-01-21 19:01:52 +0800 | [diff] [blame] | 2257 | } else if (!isOnHomeDisplay()) { |
| 2258 | return false; |
| 2259 | } else if (!isHomeStack()){ |
Wale Ogunwale | 0fc365c | 2015-05-25 19:35:42 -0700 | [diff] [blame] | 2260 | if (DEBUG_STATES) Slog.d(TAG_STATES, |
Craig Mautner | e0a3884 | 2013-12-16 16:14:02 -0800 | [diff] [blame] | 2261 | "resumeTopActivityLocked: Launching home next"); |
Craig Mautner | 84984fa | 2014-06-19 11:19:20 -0700 | [diff] [blame] | 2262 | final int returnTaskType = prevTask == null || !prevTask.isOverHomeStack() ? |
| 2263 | HOME_ACTIVITY_TYPE : prevTask.getTaskToReturnTo(); |
| 2264 | return isOnHomeDisplay() && |
Craig Mautner | 3c878f2 | 2015-01-26 13:57:19 -0800 | [diff] [blame] | 2265 | mStackSupervisor.resumeHomeStackTask(returnTaskType, prev, "prevFinished"); |
Craig Mautner | e418ecd | 2013-05-01 17:02:29 -0700 | [diff] [blame] | 2266 | } |
Craig Mautner | de4ef02 | 2013-04-07 19:01:33 -0700 | [diff] [blame] | 2267 | } |
| 2268 | |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 2269 | // If we are sleeping, and there is no resumed activity, and the top |
| 2270 | // activity is paused, well that is the state we want. |
Fyodor Kupolov | 9b80b94 | 2016-06-16 16:29:05 -0700 | [diff] [blame] | 2271 | if (mService.isSleepingOrShuttingDownLocked() |
p13451 | dbad287 | 2012-04-18 11:39:23 +0900 | [diff] [blame] | 2272 | && mLastPausedActivity == next |
Craig Mautner | 5314a40 | 2013-09-26 12:40:16 -0700 | [diff] [blame] | 2273 | && mStackSupervisor.allPausedActivitiesComplete()) { |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 2274 | // Make sure we have executed any pending transitions, since there |
| 2275 | // should be nothing left to do at this point. |
Craig Mautner | ce5f3cb | 2013-04-22 08:58:54 -0700 | [diff] [blame] | 2276 | mWindowManager.executeAppTransition(); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 2277 | mNoAnimActivities.clear(); |
Dianne Hackborn | 8437587 | 2012-06-01 19:03:50 -0700 | [diff] [blame] | 2278 | ActivityOptions.abort(options); |
Wale Ogunwale | 0fc365c | 2015-05-25 19:35:42 -0700 | [diff] [blame] | 2279 | if (DEBUG_STATES) Slog.d(TAG_STATES, |
| 2280 | "resumeTopActivityLocked: Going to sleep and all paused"); |
Craig Mautner | cf910b0 | 2013-04-23 11:23:27 -0700 | [diff] [blame] | 2281 | if (DEBUG_STACK) mStackSupervisor.validateTopActivitiesLocked(); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 2282 | return false; |
| 2283 | } |
Dianne Hackborn | 80a4af2 | 2012-08-27 19:18:31 -0700 | [diff] [blame] | 2284 | |
| 2285 | // Make sure that the user who owns this activity is started. If not, |
| 2286 | // we will just leave it as is because someone should be bringing |
| 2287 | // another user's activities to the top of the stack. |
Fyodor Kupolov | 610acda | 2015-10-19 18:44:07 -0700 | [diff] [blame] | 2288 | if (!mService.mUserController.hasStartedUserState(next.userId)) { |
Dianne Hackborn | 80a4af2 | 2012-08-27 19:18:31 -0700 | [diff] [blame] | 2289 | Slog.w(TAG, "Skipping resume of top activity " + next |
| 2290 | + ": user " + next.userId + " is stopped"); |
Craig Mautner | cf910b0 | 2013-04-23 11:23:27 -0700 | [diff] [blame] | 2291 | if (DEBUG_STACK) mStackSupervisor.validateTopActivitiesLocked(); |
Dianne Hackborn | 80a4af2 | 2012-08-27 19:18:31 -0700 | [diff] [blame] | 2292 | return false; |
| 2293 | } |
| 2294 | |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 2295 | // The activity may be waiting for stop, but that is no longer |
| 2296 | // appropriate for it. |
Craig Mautner | de4ef02 | 2013-04-07 19:01:33 -0700 | [diff] [blame] | 2297 | mStackSupervisor.mStoppingActivities.remove(next); |
Craig Mautner | 0eea92c | 2013-05-16 13:35:39 -0700 | [diff] [blame] | 2298 | mStackSupervisor.mGoingToSleepActivities.remove(next); |
Dianne Hackborn | 4eba96b | 2011-01-21 13:34:36 -0800 | [diff] [blame] | 2299 | next.sleeping = false; |
Craig Mautner | de4ef02 | 2013-04-07 19:01:33 -0700 | [diff] [blame] | 2300 | mStackSupervisor.mWaitingVisibleActivities.remove(next); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 2301 | |
Wale Ogunwale | ee006da | 2015-03-30 14:49:25 -0700 | [diff] [blame] | 2302 | if (DEBUG_SWITCH) Slog.v(TAG_SWITCH, "Resuming " + next); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 2303 | |
Wale Ogunwale | 5658e4b | 2016-02-12 12:22:19 -0800 | [diff] [blame] | 2304 | // 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] | 2305 | if (!mStackSupervisor.allPausedActivitiesComplete()) { |
Wale Ogunwale | ee006da | 2015-03-30 14:49:25 -0700 | [diff] [blame] | 2306 | if (DEBUG_SWITCH || DEBUG_PAUSE || DEBUG_STATES) Slog.v(TAG_PAUSE, |
Craig Mautner | ac6f843 | 2013-07-17 13:24:59 -0700 | [diff] [blame] | 2307 | "resumeTopActivityLocked: Skip resume: some activity pausing."); |
Craig Mautner | cf910b0 | 2013-04-23 11:23:27 -0700 | [diff] [blame] | 2308 | if (DEBUG_STACK) mStackSupervisor.validateTopActivitiesLocked(); |
Dianne Hackborn | 621e2fe | 2012-02-16 17:07:33 -0800 | [diff] [blame] | 2309 | return false; |
| 2310 | } |
| 2311 | |
Dianne Hackborn | 3d07c94 | 2015-03-13 18:02:54 -0700 | [diff] [blame] | 2312 | mStackSupervisor.setLaunchSource(next.info.applicationInfo.uid); |
| 2313 | |
Wale Ogunwale | 5658e4b | 2016-02-12 12:22:19 -0800 | [diff] [blame] | 2314 | // We need to start pausing the current activity so the top one can be resumed... |
| 2315 | final boolean dontWaitForPause = (next.info.flags & FLAG_RESUME_WHILE_PAUSING) != 0; |
Wale Ogunwale | 950faff | 2016-08-08 09:51:04 -0700 | [diff] [blame] | 2316 | boolean pausing = mStackSupervisor.pauseBackStacks(userLeaving, next, dontWaitForPause); |
Craig Mautner | eb95786 | 2013-04-24 15:34:32 -0700 | [diff] [blame] | 2317 | if (mResumedActivity != null) { |
Wale Ogunwale | 0fc365c | 2015-05-25 19:35:42 -0700 | [diff] [blame] | 2318 | if (DEBUG_STATES) Slog.d(TAG_STATES, |
| 2319 | "resumeTopActivityLocked: Pausing " + mResumedActivity); |
Wale Ogunwale | 950faff | 2016-08-08 09:51:04 -0700 | [diff] [blame] | 2320 | pausing |= startPausingLocked(userLeaving, false, next, dontWaitForPause); |
Craig Mautner | eb95786 | 2013-04-24 15:34:32 -0700 | [diff] [blame] | 2321 | } |
| 2322 | if (pausing) { |
Wale Ogunwale | 0fc365c | 2015-05-25 19:35:42 -0700 | [diff] [blame] | 2323 | if (DEBUG_SWITCH || DEBUG_STATES) Slog.v(TAG_STATES, |
Craig Mautner | ac6f843 | 2013-07-17 13:24:59 -0700 | [diff] [blame] | 2324 | "resumeTopActivityLocked: Skip resume: need to start pausing"); |
Dianne Hackborn | ad9b3211 | 2012-09-17 15:35:01 -0700 | [diff] [blame] | 2325 | // At this point we want to put the upcoming activity's process |
| 2326 | // at the top of the LRU list, since we know we will be needing it |
| 2327 | // very soon and it would be a waste to let it get killed if it |
| 2328 | // happens to be sitting towards the end. |
| 2329 | if (next.app != null && next.app.thread != null) { |
Dianne Hackborn | db92608 | 2013-10-31 16:32:44 -0700 | [diff] [blame] | 2330 | mService.updateLruProcessLocked(next.app, true, null); |
Dianne Hackborn | ad9b3211 | 2012-09-17 15:35:01 -0700 | [diff] [blame] | 2331 | } |
Craig Mautner | cf910b0 | 2013-04-23 11:23:27 -0700 | [diff] [blame] | 2332 | if (DEBUG_STACK) mStackSupervisor.validateTopActivitiesLocked(); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 2333 | return true; |
Wale Ogunwale | cac5c32 | 2016-05-23 10:56:33 -0700 | [diff] [blame] | 2334 | } else if (mResumedActivity == next && next.state == ActivityState.RESUMED && |
| 2335 | mStackSupervisor.allResumedActivitiesComplete()) { |
| 2336 | // It is possible for the activity to be resumed when we paused back stacks above if the |
| 2337 | // next activity doesn't have to wait for pause to complete. |
| 2338 | // So, nothing else to-do except: |
| 2339 | // Make sure we have executed any pending transitions, since there |
| 2340 | // should be nothing left to do at this point. |
| 2341 | mWindowManager.executeAppTransition(); |
| 2342 | mNoAnimActivities.clear(); |
| 2343 | ActivityOptions.abort(options); |
| 2344 | if (DEBUG_STATES) Slog.d(TAG_STATES, |
| 2345 | "resumeTopActivityLocked: Top activity resumed (dontWaitForPause) " + next); |
| 2346 | if (DEBUG_STACK) mStackSupervisor.validateTopActivitiesLocked(); |
| 2347 | return true; |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 2348 | } |
| 2349 | |
Christopher Tate | d3f175c | 2012-06-14 14:16:54 -0700 | [diff] [blame] | 2350 | // If the most recent activity was noHistory but was only stopped rather |
| 2351 | // than stopped+finished because the device went to sleep, we need to make |
| 2352 | // sure to finish it as we're making a new activity topmost. |
Fyodor Kupolov | 9b80b94 | 2016-06-16 16:29:05 -0700 | [diff] [blame] | 2353 | if (mService.isSleepingLocked() && mLastNoHistoryActivity != null && |
Craig Mautner | 0f92274 | 2013-08-06 08:44:42 -0700 | [diff] [blame] | 2354 | !mLastNoHistoryActivity.finishing) { |
Wale Ogunwale | 0fc365c | 2015-05-25 19:35:42 -0700 | [diff] [blame] | 2355 | if (DEBUG_STATES) Slog.d(TAG_STATES, |
| 2356 | "no-history finish of " + mLastNoHistoryActivity + " on new resume"); |
Craig Mautner | 0f92274 | 2013-08-06 08:44:42 -0700 | [diff] [blame] | 2357 | requestFinishActivityLocked(mLastNoHistoryActivity.appToken, Activity.RESULT_CANCELED, |
Todd Kennedy | 539db51 | 2014-12-15 09:57:55 -0800 | [diff] [blame] | 2358 | null, "resume-no-history", false); |
Craig Mautner | 0f92274 | 2013-08-06 08:44:42 -0700 | [diff] [blame] | 2359 | mLastNoHistoryActivity = null; |
Christopher Tate | d3f175c | 2012-06-14 14:16:54 -0700 | [diff] [blame] | 2360 | } |
| 2361 | |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 2362 | if (prev != null && prev != next) { |
Craig Mautner | 8c14c15 | 2015-01-15 17:32:07 -0800 | [diff] [blame] | 2363 | if (!mStackSupervisor.mWaitingVisibleActivities.contains(prev) |
| 2364 | && next != null && !next.nowVisible) { |
Craig Mautner | de4ef02 | 2013-04-07 19:01:33 -0700 | [diff] [blame] | 2365 | mStackSupervisor.mWaitingVisibleActivities.add(prev); |
Wale Ogunwale | ee006da | 2015-03-30 14:49:25 -0700 | [diff] [blame] | 2366 | if (DEBUG_SWITCH) Slog.v(TAG_SWITCH, |
| 2367 | "Resuming top, waiting visible to hide: " + prev); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 2368 | } else { |
| 2369 | // The next activity is already visible, so hide the previous |
| 2370 | // activity's windows right now so we can show the new one ASAP. |
| 2371 | // We only do this if the previous is finishing, which should mean |
| 2372 | // it is on top of the one being resumed so hiding it quickly |
| 2373 | // is good. Otherwise, we want to do the normal route of allowing |
| 2374 | // the resumed activity to be shown so we can decide if the |
| 2375 | // previous should actually be hidden depending on whether the |
| 2376 | // new one is found to be full-screen or not. |
| 2377 | if (prev.finishing) { |
Craig Mautner | ce5f3cb | 2013-04-22 08:58:54 -0700 | [diff] [blame] | 2378 | mWindowManager.setAppVisibility(prev.appToken, false); |
Wale Ogunwale | ee006da | 2015-03-30 14:49:25 -0700 | [diff] [blame] | 2379 | if (DEBUG_SWITCH) Slog.v(TAG_SWITCH, |
| 2380 | "Not waiting for visible to hide: " + prev + ", waitingVisible=" |
Craig Mautner | 8c14c15 | 2015-01-15 17:32:07 -0800 | [diff] [blame] | 2381 | + mStackSupervisor.mWaitingVisibleActivities.contains(prev) |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 2382 | + ", nowVisible=" + next.nowVisible); |
| 2383 | } else { |
Wale Ogunwale | ee006da | 2015-03-30 14:49:25 -0700 | [diff] [blame] | 2384 | if (DEBUG_SWITCH) Slog.v(TAG_SWITCH, |
Craig Mautner | 8c14c15 | 2015-01-15 17:32:07 -0800 | [diff] [blame] | 2385 | "Previous already visible but still waiting to hide: " + prev |
Wale Ogunwale | ee006da | 2015-03-30 14:49:25 -0700 | [diff] [blame] | 2386 | + ", waitingVisible=" |
| 2387 | + mStackSupervisor.mWaitingVisibleActivities.contains(prev) |
| 2388 | + ", nowVisible=" + next.nowVisible); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 2389 | } |
| 2390 | } |
| 2391 | } |
| 2392 | |
Dianne Hackborn | e7f9721 | 2011-02-24 14:40:20 -0800 | [diff] [blame] | 2393 | // Launching this app's activity, make sure the app is no longer |
| 2394 | // considered stopped. |
| 2395 | try { |
| 2396 | AppGlobals.getPackageManager().setPackageStoppedState( |
Amith Yamasani | 483f3b0 | 2012-03-13 16:08:00 -0700 | [diff] [blame] | 2397 | next.packageName, false, next.userId); /* TODO: Verify if correct userid */ |
Dianne Hackborn | e7f9721 | 2011-02-24 14:40:20 -0800 | [diff] [blame] | 2398 | } catch (RemoteException e1) { |
Dianne Hackborn | a925cd4 | 2011-03-10 13:18:20 -0800 | [diff] [blame] | 2399 | } catch (IllegalArgumentException e) { |
| 2400 | Slog.w(TAG, "Failed trying to unstop package " |
| 2401 | + next.packageName + ": " + e); |
Dianne Hackborn | e7f9721 | 2011-02-24 14:40:20 -0800 | [diff] [blame] | 2402 | } |
| 2403 | |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 2404 | // We are starting up the next activity, so tell the window manager |
| 2405 | // that the previous one will be hidden soon. This way it can know |
| 2406 | // to ignore it when computing the desired screen orientation. |
Craig Mautner | 525f3d9 | 2013-05-07 14:01:50 -0700 | [diff] [blame] | 2407 | boolean anim = true; |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 2408 | if (prev != null) { |
| 2409 | if (prev.finishing) { |
Wale Ogunwale | ee006da | 2015-03-30 14:49:25 -0700 | [diff] [blame] | 2410 | if (DEBUG_TRANSITION) Slog.v(TAG_TRANSITION, |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 2411 | "Prepare close transition: prev=" + prev); |
| 2412 | if (mNoAnimActivities.contains(prev)) { |
Craig Mautner | 525f3d9 | 2013-05-07 14:01:50 -0700 | [diff] [blame] | 2413 | anim = false; |
Jorim Jaggi | af80db4 | 2016-04-07 19:19:15 -0700 | [diff] [blame] | 2414 | mWindowManager.prepareAppTransition(TRANSIT_NONE, false); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 2415 | } else { |
Craig Mautner | ce5f3cb | 2013-04-22 08:58:54 -0700 | [diff] [blame] | 2416 | mWindowManager.prepareAppTransition(prev.task == next.task |
Jorim Jaggi | af80db4 | 2016-04-07 19:19:15 -0700 | [diff] [blame] | 2417 | ? TRANSIT_ACTIVITY_CLOSE |
| 2418 | : TRANSIT_TASK_CLOSE, false); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 2419 | } |
Craig Mautner | ce5f3cb | 2013-04-22 08:58:54 -0700 | [diff] [blame] | 2420 | mWindowManager.setAppVisibility(prev.appToken, false); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 2421 | } else { |
Wale Ogunwale | ee006da | 2015-03-30 14:49:25 -0700 | [diff] [blame] | 2422 | if (DEBUG_TRANSITION) Slog.v(TAG_TRANSITION, |
| 2423 | "Prepare open transition: prev=" + prev); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 2424 | if (mNoAnimActivities.contains(next)) { |
Craig Mautner | 525f3d9 | 2013-05-07 14:01:50 -0700 | [diff] [blame] | 2425 | anim = false; |
Jorim Jaggi | af80db4 | 2016-04-07 19:19:15 -0700 | [diff] [blame] | 2426 | mWindowManager.prepareAppTransition(TRANSIT_NONE, false); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 2427 | } else { |
Craig Mautner | ce5f3cb | 2013-04-22 08:58:54 -0700 | [diff] [blame] | 2428 | mWindowManager.prepareAppTransition(prev.task == next.task |
Jorim Jaggi | af80db4 | 2016-04-07 19:19:15 -0700 | [diff] [blame] | 2429 | ? TRANSIT_ACTIVITY_OPEN |
Craig Mautner | bb74246 | 2014-07-07 15:28:55 -0700 | [diff] [blame] | 2430 | : next.mLaunchTaskBehind |
Jorim Jaggi | af80db4 | 2016-04-07 19:19:15 -0700 | [diff] [blame] | 2431 | ? TRANSIT_TASK_OPEN_BEHIND |
| 2432 | : TRANSIT_TASK_OPEN, false); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 2433 | } |
| 2434 | } |
Craig Mautner | 967212c | 2013-04-13 21:10:58 -0700 | [diff] [blame] | 2435 | } else { |
Wale Ogunwale | ee006da | 2015-03-30 14:49:25 -0700 | [diff] [blame] | 2436 | if (DEBUG_TRANSITION) Slog.v(TAG_TRANSITION, "Prepare open transition: no previous"); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 2437 | if (mNoAnimActivities.contains(next)) { |
Craig Mautner | 525f3d9 | 2013-05-07 14:01:50 -0700 | [diff] [blame] | 2438 | anim = false; |
Jorim Jaggi | af80db4 | 2016-04-07 19:19:15 -0700 | [diff] [blame] | 2439 | mWindowManager.prepareAppTransition(TRANSIT_NONE, false); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 2440 | } else { |
Jorim Jaggi | af80db4 | 2016-04-07 19:19:15 -0700 | [diff] [blame] | 2441 | mWindowManager.prepareAppTransition(TRANSIT_ACTIVITY_OPEN, false); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 2442 | } |
| 2443 | } |
Adam Powell | cfbe9be | 2013-11-06 14:58:58 -0800 | [diff] [blame] | 2444 | |
| 2445 | Bundle resumeAnimOptions = null; |
Craig Mautner | 525f3d9 | 2013-05-07 14:01:50 -0700 | [diff] [blame] | 2446 | if (anim) { |
Adam Powell | cfbe9be | 2013-11-06 14:58:58 -0800 | [diff] [blame] | 2447 | ActivityOptions opts = next.getOptionsForTargetActivityLocked(); |
| 2448 | if (opts != null) { |
| 2449 | resumeAnimOptions = opts.toBundle(); |
| 2450 | } |
Dianne Hackborn | 7a2195c | 2012-03-19 17:38:00 -0700 | [diff] [blame] | 2451 | next.applyOptionsLocked(); |
| 2452 | } else { |
| 2453 | next.clearOptionsLocked(); |
| 2454 | } |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 2455 | |
Craig Mautner | cf910b0 | 2013-04-23 11:23:27 -0700 | [diff] [blame] | 2456 | ActivityStack lastStack = mStackSupervisor.getLastStack(); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 2457 | if (next.app != null && next.app.thread != null) { |
Chong Zhang | dea4bd9 | 2016-03-15 12:50:03 -0700 | [diff] [blame] | 2458 | if (DEBUG_SWITCH) Slog.v(TAG_SWITCH, "Resume running: " + next |
| 2459 | + " stopped=" + next.stopped + " visible=" + next.visible); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 2460 | |
Chong Zhang | d127c6d | 2016-05-02 16:36:41 -0700 | [diff] [blame] | 2461 | // If the previous activity is translucent, force a visibility update of |
| 2462 | // the next activity, so that it's added to WM's opening app list, and |
| 2463 | // transition animation can be set up properly. |
| 2464 | // For example, pressing Home button with a translucent activity in focus. |
| 2465 | // Launcher is already visible in this case. If we don't add it to opening |
| 2466 | // apps, maybeUpdateTransitToWallpaper() will fail to identify this as a |
| 2467 | // TRANSIT_WALLPAPER_OPEN animation, and run some funny animation. |
| 2468 | final boolean lastActivityTranslucent = lastStack != null |
| 2469 | && (!lastStack.mFullscreen |
| 2470 | || (lastStack.mLastPausedActivity != null |
| 2471 | && !lastStack.mLastPausedActivity.fullscreen)); |
| 2472 | |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 2473 | // This activity is now becoming visible. |
Chong Zhang | d127c6d | 2016-05-02 16:36:41 -0700 | [diff] [blame] | 2474 | if (!next.visible || next.stopped || lastActivityTranslucent) { |
Jorim Jaggi | 1b025a6 | 2016-02-03 19:27:49 -0800 | [diff] [blame] | 2475 | mWindowManager.setAppVisibility(next.appToken, true); |
| 2476 | } |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 2477 | |
Dianne Hackborn | 2a29b3a | 2012-03-15 15:48:38 -0700 | [diff] [blame] | 2478 | // schedule launch ticks to collect information about slow apps. |
| 2479 | next.startLaunchTickingLocked(); |
| 2480 | |
Craig Mautner | f88c50f | 2013-04-18 19:25:12 -0700 | [diff] [blame] | 2481 | ActivityRecord lastResumedActivity = |
| 2482 | lastStack == null ? null :lastStack.mResumedActivity; |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 2483 | ActivityState lastState = next.state; |
| 2484 | |
| 2485 | mService.updateCpuStats(); |
Craig Mautner | 5854780 | 2013-03-05 08:23:53 -0800 | [diff] [blame] | 2486 | |
Wale Ogunwale | 0fc365c | 2015-05-25 19:35:42 -0700 | [diff] [blame] | 2487 | 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] | 2488 | |
| 2489 | setResumedActivityLocked(next, "resumeTopActivityInnerLocked"); |
| 2490 | |
Dianne Hackborn | db92608 | 2013-10-31 16:32:44 -0700 | [diff] [blame] | 2491 | mService.updateLruProcessLocked(next.app, true, null); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 2492 | updateLRUListLocked(next); |
Dianne Hackborn | db92608 | 2013-10-31 16:32:44 -0700 | [diff] [blame] | 2493 | mService.updateOomAdjLocked(); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 2494 | |
| 2495 | // Have the window manager re-evaluate the orientation of |
| 2496 | // the screen based on the new activity order. |
Craig Mautner | 525f3d9 | 2013-05-07 14:01:50 -0700 | [diff] [blame] | 2497 | boolean notUpdated = true; |
Wale Ogunwale | 1e60e0c | 2015-10-28 13:36:10 -0700 | [diff] [blame] | 2498 | if (mStackSupervisor.isFocusedStack(this)) { |
Craig Mautner | ce5f3cb | 2013-04-22 08:58:54 -0700 | [diff] [blame] | 2499 | Configuration config = mWindowManager.updateOrientationFromAppTokens( |
Craig Mautner | 8d341ef | 2013-03-26 09:03:27 -0700 | [diff] [blame] | 2500 | mService.mConfiguration, |
| 2501 | next.mayFreezeScreenLocked(next.app) ? next.appToken : null); |
| 2502 | if (config != null) { |
| 2503 | next.frozenBeforeDestroy = true; |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 2504 | } |
Maxim Bogatov | 0507530 | 2015-05-19 18:33:08 -0700 | [diff] [blame] | 2505 | notUpdated = !mService.updateConfigurationLocked(config, next, false); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 2506 | } |
Craig Mautner | 8d341ef | 2013-03-26 09:03:27 -0700 | [diff] [blame] | 2507 | |
Craig Mautner | 525f3d9 | 2013-05-07 14:01:50 -0700 | [diff] [blame] | 2508 | if (notUpdated) { |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 2509 | // The configuration update wasn't able to keep the existing |
| 2510 | // instance of the activity, and instead started a new one. |
| 2511 | // We should be all done, but let's just make sure our activity |
| 2512 | // is still at the top and schedule another run if something |
| 2513 | // weird happened. |
Filip Gruszczynski | 3e85ba2 | 2015-10-05 22:48:30 -0700 | [diff] [blame] | 2514 | ActivityRecord nextNext = topRunningActivityLocked(); |
Wale Ogunwale | 0fc365c | 2015-05-25 19:35:42 -0700 | [diff] [blame] | 2515 | if (DEBUG_SWITCH || DEBUG_STATES) Slog.i(TAG_STATES, |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 2516 | "Activity config changed during resume: " + next |
| 2517 | + ", new next: " + nextNext); |
| 2518 | if (nextNext != next) { |
| 2519 | // Do over! |
Craig Mautner | 05d2903 | 2013-05-03 13:40:13 -0700 | [diff] [blame] | 2520 | mStackSupervisor.scheduleResumeTopActivities(); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 2521 | } |
Chong Zhang | d2cb311 | 2016-07-20 11:13:22 -0700 | [diff] [blame] | 2522 | if (!next.visible || next.stopped) { |
| 2523 | mWindowManager.setAppVisibility(next.appToken, true); |
Craig Mautner | de4ef02 | 2013-04-07 19:01:33 -0700 | [diff] [blame] | 2524 | } |
Chong Zhang | d2cb311 | 2016-07-20 11:13:22 -0700 | [diff] [blame] | 2525 | completeResumeLocked(next); |
Craig Mautner | cf910b0 | 2013-04-23 11:23:27 -0700 | [diff] [blame] | 2526 | if (DEBUG_STACK) mStackSupervisor.validateTopActivitiesLocked(); |
Chong Zhang | d2cb311 | 2016-07-20 11:13:22 -0700 | [diff] [blame] | 2527 | return true; |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 2528 | } |
Craig Mautner | 5854780 | 2013-03-05 08:23:53 -0800 | [diff] [blame] | 2529 | |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 2530 | try { |
| 2531 | // Deliver all pending results. |
Craig Mautner | 05d6272ba | 2013-02-11 09:39:27 -0800 | [diff] [blame] | 2532 | ArrayList<ResultInfo> a = next.results; |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 2533 | if (a != null) { |
| 2534 | final int N = a.size(); |
| 2535 | if (!next.finishing && N > 0) { |
Wale Ogunwale | ee006da | 2015-03-30 14:49:25 -0700 | [diff] [blame] | 2536 | if (DEBUG_RESULTS) Slog.v(TAG_RESULTS, |
| 2537 | "Delivering results to " + next + ": " + a); |
Dianne Hackborn | be70785 | 2011-11-11 14:32:10 -0800 | [diff] [blame] | 2538 | next.app.thread.scheduleSendResult(next.appToken, a); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 2539 | } |
| 2540 | } |
| 2541 | |
Chong Zhang | ad24f96 | 2016-08-25 12:12:33 -0700 | [diff] [blame] | 2542 | boolean allowSavedSurface = true; |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 2543 | if (next.newIntents != null) { |
Chong Zhang | ad24f96 | 2016-08-25 12:12:33 -0700 | [diff] [blame] | 2544 | // Restrict saved surface to launcher start, or there is no intent at all |
| 2545 | // (eg. task being brought to front). If the intent is something else, |
| 2546 | // likely the app is going to show some specific page or view, instead of |
| 2547 | // what's left last time. |
| 2548 | for (int i = next.newIntents.size() - 1; i >= 0; i--) { |
| 2549 | final Intent intent = next.newIntents.get(i); |
Chong Zhang | b0a8743 | 2016-08-25 12:12:33 -0700 | [diff] [blame] | 2550 | if (intent != null && !ActivityRecord.isMainIntent(intent)) { |
Chong Zhang | ad24f96 | 2016-08-25 12:12:33 -0700 | [diff] [blame] | 2551 | allowSavedSurface = false; |
| 2552 | break; |
| 2553 | } |
| 2554 | } |
Wale Ogunwale | 826c706 | 2016-09-13 08:25:54 -0700 | [diff] [blame] | 2555 | next.app.thread.scheduleNewIntent( |
| 2556 | next.newIntents, next.appToken, false /* andPause */); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 2557 | } |
| 2558 | |
Wale Ogunwale | 8d5a542 | 2016-03-03 18:28:21 -0800 | [diff] [blame] | 2559 | // Well the app will no longer be stopped. |
| 2560 | // Clear app token stopped state in window manager if needed. |
Chong Zhang | ad24f96 | 2016-08-25 12:12:33 -0700 | [diff] [blame] | 2561 | mWindowManager.notifyAppResumed(next.appToken, next.stopped, allowSavedSurface); |
Wale Ogunwale | 8d5a542 | 2016-03-03 18:28:21 -0800 | [diff] [blame] | 2562 | |
Craig Mautner | 299f960 | 2015-01-26 09:47:33 -0800 | [diff] [blame] | 2563 | EventLog.writeEvent(EventLogTags.AM_RESUME_ACTIVITY, next.userId, |
| 2564 | System.identityHashCode(next), next.task.taskId, next.shortComponentName); |
Craig Mautner | 5854780 | 2013-03-05 08:23:53 -0800 | [diff] [blame] | 2565 | |
Dianne Hackborn | 4eba96b | 2011-01-21 13:34:36 -0800 | [diff] [blame] | 2566 | next.sleeping = false; |
Alan Viverette | 5f31b98 | 2016-06-21 14:46:14 -0400 | [diff] [blame] | 2567 | mService.showUnsupportedZoomDialogIfNeededLocked(next); |
Craig Mautner | 2420ead | 2013-04-01 17:13:20 -0700 | [diff] [blame] | 2568 | mService.showAskCompatModeDialogLocked(next); |
Dianne Hackborn | 905577f | 2011-09-07 18:31:28 -0700 | [diff] [blame] | 2569 | next.app.pendingUiClean = true; |
Dianne Hackborn | 4870e9d | 2015-04-08 16:55:47 -0700 | [diff] [blame] | 2570 | next.app.forceProcessStateUpTo(mService.mTopProcessState); |
George Mount | 2c92c97 | 2014-03-20 09:38:23 -0700 | [diff] [blame] | 2571 | next.clearOptionsLocked(); |
Dianne Hackborn | a413dc0 | 2013-07-12 12:02:55 -0700 | [diff] [blame] | 2572 | next.app.thread.scheduleResumeActivity(next.appToken, next.app.repProcState, |
Adam Powell | cfbe9be | 2013-11-06 14:58:58 -0800 | [diff] [blame] | 2573 | mService.isNextTransitionForward(), resumeAnimOptions); |
Craig Mautner | 5854780 | 2013-03-05 08:23:53 -0800 | [diff] [blame] | 2574 | |
Wale Ogunwale | 0fc365c | 2015-05-25 19:35:42 -0700 | [diff] [blame] | 2575 | if (DEBUG_STATES) Slog.d(TAG_STATES, "resumeTopActivityLocked: Resumed " + next); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 2576 | } catch (Exception e) { |
| 2577 | // Whoops, need to restart this activity! |
Wale Ogunwale | 0fc365c | 2015-05-25 19:35:42 -0700 | [diff] [blame] | 2578 | if (DEBUG_STATES) Slog.v(TAG_STATES, "Resume failed; resetting state to " |
Dianne Hackborn | ce86ba8 | 2011-07-13 19:33:41 -0700 | [diff] [blame] | 2579 | + lastState + ": " + next); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 2580 | next.state = lastState; |
Craig Mautner | f88c50f | 2013-04-18 19:25:12 -0700 | [diff] [blame] | 2581 | if (lastStack != null) { |
| 2582 | lastStack.mResumedActivity = lastResumedActivity; |
| 2583 | } |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 2584 | Slog.i(TAG, "Restarting because process died: " + next); |
| 2585 | if (!next.hasBeenLaunched) { |
| 2586 | next.hasBeenLaunched = true; |
Craig Mautner | f88c50f | 2013-04-18 19:25:12 -0700 | [diff] [blame] | 2587 | } else if (SHOW_APP_STARTING_PREVIEW && lastStack != null && |
| 2588 | mStackSupervisor.isFrontStack(lastStack)) { |
Wale Ogunwale | 3b23239 | 2016-05-13 15:37:13 -0700 | [diff] [blame] | 2589 | next.showStartingWindow(null, true); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 2590 | } |
George Mount | 2c92c97 | 2014-03-20 09:38:23 -0700 | [diff] [blame] | 2591 | mStackSupervisor.startSpecificActivityLocked(next, true, false); |
Craig Mautner | cf910b0 | 2013-04-23 11:23:27 -0700 | [diff] [blame] | 2592 | if (DEBUG_STACK) mStackSupervisor.validateTopActivitiesLocked(); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 2593 | return true; |
| 2594 | } |
| 2595 | |
| 2596 | // From this point on, if something goes wrong there is no way |
| 2597 | // to recover the activity. |
| 2598 | try { |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 2599 | completeResumeLocked(next); |
| 2600 | } catch (Exception e) { |
| 2601 | // If any exception gets thrown, toss away this |
| 2602 | // activity and try the next one. |
| 2603 | Slog.w(TAG, "Exception thrown during resume of " + next, e); |
Dianne Hackborn | be70785 | 2011-11-11 14:32:10 -0800 | [diff] [blame] | 2604 | requestFinishActivityLocked(next.appToken, Activity.RESULT_CANCELED, null, |
Dianne Hackborn | 2d1b378 | 2012-09-09 17:49:39 -0700 | [diff] [blame] | 2605 | "resume-exception", true); |
Craig Mautner | cf910b0 | 2013-04-23 11:23:27 -0700 | [diff] [blame] | 2606 | if (DEBUG_STACK) mStackSupervisor.validateTopActivitiesLocked(); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 2607 | return true; |
| 2608 | } |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 2609 | } else { |
| 2610 | // Whoops, need to restart this activity! |
| 2611 | if (!next.hasBeenLaunched) { |
| 2612 | next.hasBeenLaunched = true; |
| 2613 | } else { |
| 2614 | if (SHOW_APP_STARTING_PREVIEW) { |
Wale Ogunwale | 3b23239 | 2016-05-13 15:37:13 -0700 | [diff] [blame] | 2615 | next.showStartingWindow(null, true); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 2616 | } |
Wale Ogunwale | ee006da | 2015-03-30 14:49:25 -0700 | [diff] [blame] | 2617 | if (DEBUG_SWITCH) Slog.v(TAG_SWITCH, "Restarting: " + next); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 2618 | } |
Wale Ogunwale | 0fc365c | 2015-05-25 19:35:42 -0700 | [diff] [blame] | 2619 | if (DEBUG_STATES) Slog.d(TAG_STATES, "resumeTopActivityLocked: Restarting " + next); |
George Mount | 2c92c97 | 2014-03-20 09:38:23 -0700 | [diff] [blame] | 2620 | mStackSupervisor.startSpecificActivityLocked(next, true, true); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 2621 | } |
| 2622 | |
Craig Mautner | cf910b0 | 2013-04-23 11:23:27 -0700 | [diff] [blame] | 2623 | if (DEBUG_STACK) mStackSupervisor.validateTopActivitiesLocked(); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 2624 | return true; |
| 2625 | } |
| 2626 | |
riddle_hsu | c215a4f | 2014-12-27 12:10:45 +0800 | [diff] [blame] | 2627 | private TaskRecord getNextTask(TaskRecord targetTask) { |
| 2628 | final int index = mTaskHistory.indexOf(targetTask); |
| 2629 | if (index >= 0) { |
| 2630 | final int numTasks = mTaskHistory.size(); |
| 2631 | for (int i = index + 1; i < numTasks; ++i) { |
| 2632 | TaskRecord task = mTaskHistory.get(i); |
| 2633 | if (task.userId == targetTask.userId) { |
| 2634 | return task; |
| 2635 | } |
| 2636 | } |
| 2637 | } |
| 2638 | return null; |
| 2639 | } |
| 2640 | |
Wale Ogunwale | ddc1cb2 | 2015-07-25 19:23:04 -0700 | [diff] [blame] | 2641 | private void insertTaskAtPosition(TaskRecord task, int position) { |
| 2642 | if (position >= mTaskHistory.size()) { |
| 2643 | insertTaskAtTop(task, null); |
| 2644 | return; |
| 2645 | } |
| 2646 | // Calculate maximum possible position for this task. |
| 2647 | int maxPosition = mTaskHistory.size(); |
Chong Zhang | 8776197 | 2016-08-22 13:53:24 -0700 | [diff] [blame] | 2648 | if (!task.okToShowLocked()) { |
Wale Ogunwale | ddc1cb2 | 2015-07-25 19:23:04 -0700 | [diff] [blame] | 2649 | // Put non-current user tasks below current user tasks. |
| 2650 | while (maxPosition > 0) { |
| 2651 | final TaskRecord tmpTask = mTaskHistory.get(maxPosition - 1); |
| 2652 | if (!mStackSupervisor.isCurrentProfileLocked(tmpTask.userId) |
Filip Gruszczynski | 3e85ba2 | 2015-10-05 22:48:30 -0700 | [diff] [blame] | 2653 | || tmpTask.topRunningActivityLocked() == null) { |
Wale Ogunwale | ddc1cb2 | 2015-07-25 19:23:04 -0700 | [diff] [blame] | 2654 | break; |
| 2655 | } |
| 2656 | maxPosition--; |
| 2657 | } |
| 2658 | } |
| 2659 | position = Math.min(position, maxPosition); |
| 2660 | mTaskHistory.remove(task); |
| 2661 | mTaskHistory.add(position, task); |
| 2662 | updateTaskMovement(task, true); |
| 2663 | } |
| 2664 | |
Wale Ogunwale | 3fcb4a8 | 2015-04-06 14:00:13 -0700 | [diff] [blame] | 2665 | private void insertTaskAtTop(TaskRecord task, ActivityRecord newActivity) { |
Andrii Kulian | dc0f893 | 2016-06-28 16:34:02 -0700 | [diff] [blame] | 2666 | boolean isLastTaskOverHome = false; |
riddle_hsu | c215a4f | 2014-12-27 12:10:45 +0800 | [diff] [blame] | 2667 | // If the moving task is over home stack, transfer its return type to next task |
| 2668 | if (task.isOverHomeStack()) { |
| 2669 | final TaskRecord nextTask = getNextTask(task); |
| 2670 | if (nextTask != null) { |
| 2671 | nextTask.setTaskToReturnTo(task.getTaskToReturnTo()); |
Andrii Kulian | dc0f893 | 2016-06-28 16:34:02 -0700 | [diff] [blame] | 2672 | } else { |
| 2673 | isLastTaskOverHome = true; |
riddle_hsu | c215a4f | 2014-12-27 12:10:45 +0800 | [diff] [blame] | 2674 | } |
| 2675 | } |
| 2676 | |
Craig Mautner | 9c85c20 | 2013-10-04 20:11:26 -0700 | [diff] [blame] | 2677 | // 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] | 2678 | // activity, set mTaskToReturnTo accordingly. |
Craig Mautner | e0a3884 | 2013-12-16 16:14:02 -0800 | [diff] [blame] | 2679 | if (isOnHomeDisplay()) { |
| 2680 | ActivityStack lastStack = mStackSupervisor.getLastStack(); |
| 2681 | final boolean fromHome = lastStack.isHomeStack(); |
Jiaquan He | e13e964 | 2016-06-15 15:16:13 -0700 | [diff] [blame] | 2682 | final boolean fromOnTopLauncher = lastStack.topTask() != null && |
| 2683 | lastStack.topTask().isOnTopLauncher(); |
| 2684 | if (fromOnTopLauncher) { |
| 2685 | // Since an on-top launcher will is moved to back when tasks are launched from it, |
| 2686 | // those tasks should first try to return to a non-home activity. |
| 2687 | // This also makes sure that non-home activities are visible under a transparent |
| 2688 | // non-home activity. |
| 2689 | task.setTaskToReturnTo(APPLICATION_ACTIVITY_TYPE); |
| 2690 | } else if (!isHomeStack() && (fromHome || topTask() != task)) { |
Andrii Kulian | dc0f893 | 2016-06-28 16:34:02 -0700 | [diff] [blame] | 2691 | // If it's a last task over home - we default to keep its return to type not to |
| 2692 | // make underlying task focused when this one will be finished. |
| 2693 | int returnToType = isLastTaskOverHome |
| 2694 | ? task.getTaskToReturnTo() : APPLICATION_ACTIVITY_TYPE; |
Wale Ogunwale | f81c1d1 | 2016-01-12 12:20:18 -0800 | [diff] [blame] | 2695 | if (fromHome && StackId.allowTopTaskToReturnHome(mStackId)) { |
| 2696 | returnToType = lastStack.topTask() == null |
| 2697 | ? HOME_ACTIVITY_TYPE : lastStack.topTask().taskType; |
| 2698 | } |
| 2699 | task.setTaskToReturnTo(returnToType); |
Craig Mautner | e0a3884 | 2013-12-16 16:14:02 -0800 | [diff] [blame] | 2700 | } |
| 2701 | } else { |
Craig Mautner | 84984fa | 2014-06-19 11:19:20 -0700 | [diff] [blame] | 2702 | task.setTaskToReturnTo(APPLICATION_ACTIVITY_TYPE); |
Craig Mautner | 9c85c20 | 2013-10-04 20:11:26 -0700 | [diff] [blame] | 2703 | } |
Craig Mautner | d99384d | 2013-10-14 07:09:18 -0700 | [diff] [blame] | 2704 | |
Craig Mautner | ac6f843 | 2013-07-17 13:24:59 -0700 | [diff] [blame] | 2705 | mTaskHistory.remove(task); |
| 2706 | // Now put task at top. |
Craig Mautner | bb74246 | 2014-07-07 15:28:55 -0700 | [diff] [blame] | 2707 | int taskNdx = mTaskHistory.size(); |
Wale Ogunwale | 3fcb4a8 | 2015-04-06 14:00:13 -0700 | [diff] [blame] | 2708 | final boolean notShownWhenLocked = |
Chong Zhang | 8776197 | 2016-08-22 13:53:24 -0700 | [diff] [blame] | 2709 | (newActivity != null && !newActivity.okToShowLocked()) |
| 2710 | || (newActivity == null && !task.okToShowLocked()); |
| 2711 | if (notShownWhenLocked) { |
Craig Mautner | ac6f843 | 2013-07-17 13:24:59 -0700 | [diff] [blame] | 2712 | // Put non-current user tasks below current user tasks. |
Craig Mautner | bb74246 | 2014-07-07 15:28:55 -0700 | [diff] [blame] | 2713 | while (--taskNdx >= 0) { |
Wale Ogunwale | 3fcb4a8 | 2015-04-06 14:00:13 -0700 | [diff] [blame] | 2714 | final TaskRecord tmpTask = mTaskHistory.get(taskNdx); |
Wale Ogunwale | 0bd2aa7 | 2015-04-16 13:50:44 -0700 | [diff] [blame] | 2715 | if (!mStackSupervisor.isCurrentProfileLocked(tmpTask.userId) |
Filip Gruszczynski | 3e85ba2 | 2015-10-05 22:48:30 -0700 | [diff] [blame] | 2716 | || tmpTask.topRunningActivityLocked() == null) { |
Craig Mautner | ac6f843 | 2013-07-17 13:24:59 -0700 | [diff] [blame] | 2717 | break; |
| 2718 | } |
| 2719 | } |
Craig Mautner | bb74246 | 2014-07-07 15:28:55 -0700 | [diff] [blame] | 2720 | ++taskNdx; |
Craig Mautner | ac6f843 | 2013-07-17 13:24:59 -0700 | [diff] [blame] | 2721 | } |
Craig Mautner | bb74246 | 2014-07-07 15:28:55 -0700 | [diff] [blame] | 2722 | mTaskHistory.add(taskNdx, task); |
Craig Mautner | 21d24a2 | 2014-04-23 11:45:37 -0700 | [diff] [blame] | 2723 | updateTaskMovement(task, true); |
Craig Mautner | ac6f843 | 2013-07-17 13:24:59 -0700 | [diff] [blame] | 2724 | } |
Craig Mautner | 11bf9a5 | 2013-02-19 14:08:51 -0800 | [diff] [blame] | 2725 | |
Filip Gruszczynski | 3d82ed6 | 2015-12-10 10:41:39 -0800 | [diff] [blame] | 2726 | final void startActivityLocked(ActivityRecord r, boolean newTask, boolean keepCurTransition, |
| 2727 | ActivityOptions options) { |
Craig Mautner | d232895 | 2013-03-05 12:46:26 -0800 | [diff] [blame] | 2728 | TaskRecord rTask = r.task; |
| 2729 | final int taskId = rTask.taskId; |
Craig Mautner | bb74246 | 2014-07-07 15:28:55 -0700 | [diff] [blame] | 2730 | // mLaunchTaskBehind tasks get placed at the back of the task stack. |
| 2731 | if (!r.mLaunchTaskBehind && (taskForIdLocked(taskId) == null || newTask)) { |
Craig Mautner | 7787877 | 2013-03-04 19:46:24 -0800 | [diff] [blame] | 2732 | // Last activity in task had been removed or ActivityManagerService is reusing task. |
| 2733 | // Insert or replace. |
Craig Mautner | 7787877 | 2013-03-04 19:46:24 -0800 | [diff] [blame] | 2734 | // Might not even be in. |
Wale Ogunwale | 3fcb4a8 | 2015-04-06 14:00:13 -0700 | [diff] [blame] | 2735 | insertTaskAtTop(rTask, r); |
Craig Mautner | ce5f3cb | 2013-04-22 08:58:54 -0700 | [diff] [blame] | 2736 | mWindowManager.moveTaskToTop(taskId); |
Craig Mautner | 7787877 | 2013-03-04 19:46:24 -0800 | [diff] [blame] | 2737 | } |
Craig Mautner | 525f3d9 | 2013-05-07 14:01:50 -0700 | [diff] [blame] | 2738 | TaskRecord task = null; |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 2739 | if (!newTask) { |
| 2740 | // If starting in an existing task, find where that is... |
Craig Mautner | 70a8693 | 2013-02-28 22:37:44 -0800 | [diff] [blame] | 2741 | boolean startIt = true; |
| 2742 | for (int taskNdx = mTaskHistory.size() - 1; taskNdx >= 0; --taskNdx) { |
| 2743 | task = mTaskHistory.get(taskNdx); |
riddle_hsu | 9bcc6e8 | 2014-07-31 00:26:51 +0800 | [diff] [blame] | 2744 | if (task.getTopActivity() == null) { |
| 2745 | // All activities in task are finishing. |
| 2746 | continue; |
| 2747 | } |
Craig Mautner | 70a8693 | 2013-02-28 22:37:44 -0800 | [diff] [blame] | 2748 | if (task == r.task) { |
| 2749 | // Here it is! Now, if this is not yet visible to the |
| 2750 | // user, then just add it without starting; it will |
| 2751 | // get started when the user navigates back to it. |
Craig Mautner | 70a8693 | 2013-02-28 22:37:44 -0800 | [diff] [blame] | 2752 | if (!startIt) { |
| 2753 | if (DEBUG_ADD_REMOVE) Slog.i(TAG, "Adding activity " + r + " to task " |
| 2754 | + task, new RuntimeException("here").fillInStackTrace()); |
| 2755 | task.addActivityToTop(r); |
Dianne Hackborn | f26fd99 | 2011-04-08 18:14:09 -0700 | [diff] [blame] | 2756 | r.putInHistory(); |
Filip Gruszczynski | e5390e7 | 2015-08-18 16:39:00 -0700 | [diff] [blame] | 2757 | addConfigOverride(r, task); |
Dianne Hackborn | 8078d8c | 2012-03-20 11:11:26 -0700 | [diff] [blame] | 2758 | ActivityOptions.abort(options); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 2759 | return; |
| 2760 | } |
| 2761 | break; |
Craig Mautner | 70a8693 | 2013-02-28 22:37:44 -0800 | [diff] [blame] | 2762 | } else if (task.numFullscreen > 0) { |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 2763 | startIt = false; |
| 2764 | } |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 2765 | } |
| 2766 | } |
| 2767 | |
| 2768 | // Place a new activity at top of stack, so it is next to interact |
| 2769 | // with the user. |
Craig Mautner | 70a8693 | 2013-02-28 22:37:44 -0800 | [diff] [blame] | 2770 | |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 2771 | // If we are not placing the new activity frontmost, we do not want |
| 2772 | // to deliver the onUserLeaving callback to the actual frontmost |
| 2773 | // activity |
Craig Mautner | 70a8693 | 2013-02-28 22:37:44 -0800 | [diff] [blame] | 2774 | if (task == r.task && mTaskHistory.indexOf(task) != (mTaskHistory.size() - 1)) { |
Craig Mautner | de4ef02 | 2013-04-07 19:01:33 -0700 | [diff] [blame] | 2775 | mStackSupervisor.mUserLeaving = false; |
Wale Ogunwale | ee006da | 2015-03-30 14:49:25 -0700 | [diff] [blame] | 2776 | if (DEBUG_USER_LEAVING) Slog.v(TAG_USER_LEAVING, |
Craig Mautner | 70a8693 | 2013-02-28 22:37:44 -0800 | [diff] [blame] | 2777 | "startActivity() behind front, mUserLeaving=false"); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 2778 | } |
Craig Mautner | 70a8693 | 2013-02-28 22:37:44 -0800 | [diff] [blame] | 2779 | |
| 2780 | task = r.task; |
| 2781 | |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 2782 | // Slot the activity into the history stack and proceed |
Craig Mautner | 70a8693 | 2013-02-28 22:37:44 -0800 | [diff] [blame] | 2783 | 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] | 2784 | new RuntimeException("here").fillInStackTrace()); |
Craig Mautner | 70a8693 | 2013-02-28 22:37:44 -0800 | [diff] [blame] | 2785 | task.addActivityToTop(r); |
Craig Mautner | 1aa9d0d3f | 2013-12-16 15:58:31 -0800 | [diff] [blame] | 2786 | task.setFrontOfTask(); |
Craig Mautner | 70a8693 | 2013-02-28 22:37:44 -0800 | [diff] [blame] | 2787 | |
Dianne Hackborn | f26fd99 | 2011-04-08 18:14:09 -0700 | [diff] [blame] | 2788 | r.putInHistory(); |
Craig Mautner | de4ef02 | 2013-04-07 19:01:33 -0700 | [diff] [blame] | 2789 | if (!isHomeStack() || numActivities() > 0) { |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 2790 | // We want to show the starting preview window if we are |
| 2791 | // switching to a new task, or the next activity's process is |
| 2792 | // not currently running. |
| 2793 | boolean showStartingIcon = newTask; |
| 2794 | ProcessRecord proc = r.app; |
| 2795 | if (proc == null) { |
| 2796 | proc = mService.mProcessNames.get(r.processName, r.info.applicationInfo.uid); |
| 2797 | } |
| 2798 | if (proc == null || proc.thread == null) { |
| 2799 | showStartingIcon = true; |
| 2800 | } |
Wale Ogunwale | ee006da | 2015-03-30 14:49:25 -0700 | [diff] [blame] | 2801 | if (DEBUG_TRANSITION) Slog.v(TAG_TRANSITION, |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 2802 | "Prepare open transition: starting " + r); |
Wale Ogunwale | ee006da | 2015-03-30 14:49:25 -0700 | [diff] [blame] | 2803 | if ((r.intent.getFlags() & Intent.FLAG_ACTIVITY_NO_ANIMATION) != 0) { |
Jorim Jaggi | af80db4 | 2016-04-07 19:19:15 -0700 | [diff] [blame] | 2804 | mWindowManager.prepareAppTransition(TRANSIT_NONE, keepCurTransition); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 2805 | mNoAnimActivities.add(r); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 2806 | } else { |
Craig Mautner | ce5f3cb | 2013-04-22 08:58:54 -0700 | [diff] [blame] | 2807 | mWindowManager.prepareAppTransition(newTask |
Craig Mautner | bb74246 | 2014-07-07 15:28:55 -0700 | [diff] [blame] | 2808 | ? r.mLaunchTaskBehind |
Jorim Jaggi | af80db4 | 2016-04-07 19:19:15 -0700 | [diff] [blame] | 2809 | ? TRANSIT_TASK_OPEN_BEHIND |
| 2810 | : TRANSIT_TASK_OPEN |
| 2811 | : TRANSIT_ACTIVITY_OPEN, keepCurTransition); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 2812 | mNoAnimActivities.remove(r); |
| 2813 | } |
Filip Gruszczynski | e5390e7 | 2015-08-18 16:39:00 -0700 | [diff] [blame] | 2814 | addConfigOverride(r, task); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 2815 | boolean doShow = true; |
| 2816 | if (newTask) { |
| 2817 | // Even though this activity is starting fresh, we still need |
| 2818 | // to reset it to make sure we apply affinities to move any |
| 2819 | // existing activities from other tasks in to it. |
| 2820 | // If the caller has requested that the target task be |
| 2821 | // reset, then do so. |
Craig Mautner | 9d4e9bc | 2014-06-18 18:34:56 -0700 | [diff] [blame] | 2822 | if ((r.intent.getFlags() & Intent.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED) != 0) { |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 2823 | resetTaskIfNeededLocked(r, r); |
| 2824 | doShow = topRunningNonDelayedActivityLocked(null) == r; |
| 2825 | } |
Chong Zhang | 280d332 | 2015-11-03 17:27:26 -0800 | [diff] [blame] | 2826 | } else if (options != null && options.getAnimationType() |
George Mount | 70778d7 | 2014-07-01 16:33:45 -0700 | [diff] [blame] | 2827 | == ActivityOptions.ANIM_SCENE_TRANSITION) { |
| 2828 | doShow = false; |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 2829 | } |
Craig Mautner | bb74246 | 2014-07-07 15:28:55 -0700 | [diff] [blame] | 2830 | if (r.mLaunchTaskBehind) { |
| 2831 | // Don't do a starting window for mLaunchTaskBehind. More importantly make sure we |
| 2832 | // tell WindowManager that r is visible even though it is at the back of the stack. |
| 2833 | mWindowManager.setAppVisibility(r.appToken, true); |
Filip Gruszczynski | bc5a6c5 | 2015-09-22 13:13:24 -0700 | [diff] [blame] | 2834 | ensureActivitiesVisibleLocked(null, 0, !PRESERVE_WINDOWS); |
Craig Mautner | bb74246 | 2014-07-07 15:28:55 -0700 | [diff] [blame] | 2835 | } else if (SHOW_APP_STARTING_PREVIEW && doShow) { |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 2836 | // Figure out if we are transitioning from another activity that is |
| 2837 | // "has the same starting icon" as the next one. This allows the |
| 2838 | // window manager to keep the previous window it had previously |
| 2839 | // created, if it still had one. |
Wale Ogunwale | 3b23239 | 2016-05-13 15:37:13 -0700 | [diff] [blame] | 2840 | ActivityRecord prev = r.task.topRunningActivityWithStartingWindowLocked(); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 2841 | if (prev != null) { |
| 2842 | // We don't want to reuse the previous starting preview if: |
| 2843 | // (1) The current activity is in a different task. |
Craig Mautner | 29219d9 | 2013-04-16 20:19:12 -0700 | [diff] [blame] | 2844 | if (prev.task != r.task) { |
| 2845 | prev = null; |
| 2846 | } |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 2847 | // (2) The current activity is already displayed. |
Craig Mautner | 29219d9 | 2013-04-16 20:19:12 -0700 | [diff] [blame] | 2848 | else if (prev.nowVisible) { |
| 2849 | prev = null; |
| 2850 | } |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 2851 | } |
Wale Ogunwale | 3b23239 | 2016-05-13 15:37:13 -0700 | [diff] [blame] | 2852 | r.showStartingWindow(prev, showStartingIcon); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 2853 | } |
| 2854 | } else { |
| 2855 | // If this is the first activity, don't do any fancy animations, |
| 2856 | // because there is nothing for it to animate on top of. |
Filip Gruszczynski | e5390e7 | 2015-08-18 16:39:00 -0700 | [diff] [blame] | 2857 | addConfigOverride(r, task); |
Dianne Hackborn | 8078d8c | 2012-03-20 11:11:26 -0700 | [diff] [blame] | 2858 | ActivityOptions.abort(options); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 2859 | } |
Dianne Hackborn | be70785 | 2011-11-11 14:32:10 -0800 | [diff] [blame] | 2860 | } |
| 2861 | |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 2862 | /** |
| 2863 | * Perform a reset of the given task, if needed as part of launching it. |
| 2864 | * Returns the new HistoryRecord at the top of the task. |
| 2865 | */ |
Craig Mautner | e3a74d5 | 2013-02-22 14:14:58 -0800 | [diff] [blame] | 2866 | /** |
| 2867 | * Helper method for #resetTaskIfNeededLocked. |
| 2868 | * We are inside of the task being reset... we'll either finish this activity, push it out |
| 2869 | * for another task, or leave it as-is. |
| 2870 | * @param task The task containing the Activity (taskTop) that might be reset. |
| 2871 | * @param forceReset |
| 2872 | * @return An ActivityOptions that needs to be processed. |
| 2873 | */ |
Craig Mautner | ce5f3cb | 2013-04-22 08:58:54 -0700 | [diff] [blame] | 2874 | final ActivityOptions resetTargetTaskIfNeededLocked(TaskRecord task, boolean forceReset) { |
Craig Mautner | e3a74d5 | 2013-02-22 14:14:58 -0800 | [diff] [blame] | 2875 | ActivityOptions topOptions = null; |
| 2876 | |
| 2877 | int replyChainEnd = -1; |
| 2878 | boolean canMoveOptions = true; |
| 2879 | |
| 2880 | // We only do this for activities that are not the root of the task (since if we finish |
| 2881 | // the root, we may no longer have the task!). |
| 2882 | final ArrayList<ActivityRecord> activities = task.mActivities; |
| 2883 | final int numActivities = activities.size(); |
Craig Mautner | 9d4e9bc | 2014-06-18 18:34:56 -0700 | [diff] [blame] | 2884 | final int rootActivityNdx = task.findEffectiveRootIndex(); |
| 2885 | for (int i = numActivities - 1; i > rootActivityNdx; --i ) { |
Craig Mautner | e3a74d5 | 2013-02-22 14:14:58 -0800 | [diff] [blame] | 2886 | ActivityRecord target = activities.get(i); |
Craig Mautner | 76ae2f0 | 2014-07-16 16:16:19 +0000 | [diff] [blame] | 2887 | if (target.frontOfTask) |
| 2888 | break; |
Craig Mautner | e3a74d5 | 2013-02-22 14:14:58 -0800 | [diff] [blame] | 2889 | |
| 2890 | final int flags = target.info.flags; |
| 2891 | final boolean finishOnTaskLaunch = |
| 2892 | (flags & ActivityInfo.FLAG_FINISH_ON_TASK_LAUNCH) != 0; |
| 2893 | final boolean allowTaskReparenting = |
| 2894 | (flags & ActivityInfo.FLAG_ALLOW_TASK_REPARENTING) != 0; |
| 2895 | final boolean clearWhenTaskReset = |
| 2896 | (target.intent.getFlags() & Intent.FLAG_ACTIVITY_CLEAR_WHEN_TASK_RESET) != 0; |
| 2897 | |
| 2898 | if (!finishOnTaskLaunch |
| 2899 | && !clearWhenTaskReset |
| 2900 | && target.resultTo != null) { |
| 2901 | // If this activity is sending a reply to a previous |
| 2902 | // activity, we can't do anything with it now until |
| 2903 | // we reach the start of the reply chain. |
| 2904 | // XXX note that we are assuming the result is always |
| 2905 | // to the previous activity, which is almost always |
| 2906 | // the case but we really shouldn't count on. |
| 2907 | if (replyChainEnd < 0) { |
| 2908 | replyChainEnd = i; |
| 2909 | } |
| 2910 | } else if (!finishOnTaskLaunch |
| 2911 | && !clearWhenTaskReset |
| 2912 | && allowTaskReparenting |
| 2913 | && target.taskAffinity != null |
| 2914 | && !target.taskAffinity.equals(task.affinity)) { |
| 2915 | // If this activity has an affinity for another |
| 2916 | // task, then we need to move it out of here. We will |
| 2917 | // move it as far out of the way as possible, to the |
| 2918 | // bottom of the activity stack. This also keeps it |
| 2919 | // correctly ordered with any activities we previously |
| 2920 | // moved. |
Craig Mautner | 329f412 | 2013-11-07 09:10:42 -0800 | [diff] [blame] | 2921 | final TaskRecord targetTask; |
Craig Mautner | dccb770 | 2013-09-17 15:53:34 -0700 | [diff] [blame] | 2922 | final ActivityRecord bottom = |
| 2923 | !mTaskHistory.isEmpty() && !mTaskHistory.get(0).mActivities.isEmpty() ? |
Craig Mautner | 329f412 | 2013-11-07 09:10:42 -0800 | [diff] [blame] | 2924 | mTaskHistory.get(0).mActivities.get(0) : null; |
Craig Mautner | dccb770 | 2013-09-17 15:53:34 -0700 | [diff] [blame] | 2925 | if (bottom != null && target.taskAffinity != null |
| 2926 | && target.taskAffinity.equals(bottom.task.affinity)) { |
Craig Mautner | e3a74d5 | 2013-02-22 14:14:58 -0800 | [diff] [blame] | 2927 | // If the activity currently at the bottom has the |
| 2928 | // same task affinity as the one we are moving, |
| 2929 | // then merge it into the same task. |
Craig Mautner | 329f412 | 2013-11-07 09:10:42 -0800 | [diff] [blame] | 2930 | targetTask = bottom.task; |
Wale Ogunwale | ee006da | 2015-03-30 14:49:25 -0700 | [diff] [blame] | 2931 | if (DEBUG_TASKS) Slog.v(TAG_TASKS, "Start pushing activity " + target |
Craig Mautner | dccb770 | 2013-09-17 15:53:34 -0700 | [diff] [blame] | 2932 | + " out to bottom task " + bottom.task); |
Craig Mautner | e3a74d5 | 2013-02-22 14:14:58 -0800 | [diff] [blame] | 2933 | } else { |
Suprabh Shukla | 09a88f5 | 2015-12-02 14:36:31 -0800 | [diff] [blame] | 2934 | targetTask = createTaskRecord( |
| 2935 | mStackSupervisor.getNextTaskIdForUserLocked(target.userId), |
| 2936 | target.info, null, null, null, false); |
Craig Mautner | 329f412 | 2013-11-07 09:10:42 -0800 | [diff] [blame] | 2937 | targetTask.affinityIntent = target.intent; |
Wale Ogunwale | ee006da | 2015-03-30 14:49:25 -0700 | [diff] [blame] | 2938 | if (DEBUG_TASKS) Slog.v(TAG_TASKS, "Start pushing activity " + target |
Craig Mautner | e3a74d5 | 2013-02-22 14:14:58 -0800 | [diff] [blame] | 2939 | + " out to new task " + target.task); |
| 2940 | } |
| 2941 | |
Wale Ogunwale | 706ed79 | 2015-08-02 10:29:44 -0700 | [diff] [blame] | 2942 | setAppTask(target, targetTask); |
Craig Mautner | e3a74d5 | 2013-02-22 14:14:58 -0800 | [diff] [blame] | 2943 | |
Craig Mautner | 525f3d9 | 2013-05-07 14:01:50 -0700 | [diff] [blame] | 2944 | boolean noOptions = canMoveOptions; |
Craig Mautner | e3a74d5 | 2013-02-22 14:14:58 -0800 | [diff] [blame] | 2945 | final int start = replyChainEnd < 0 ? i : replyChainEnd; |
| 2946 | for (int srcPos = start; srcPos >= i; --srcPos) { |
Craig Mautner | dccb770 | 2013-09-17 15:53:34 -0700 | [diff] [blame] | 2947 | final ActivityRecord p = activities.get(srcPos); |
Craig Mautner | e3a74d5 | 2013-02-22 14:14:58 -0800 | [diff] [blame] | 2948 | if (p.finishing) { |
| 2949 | continue; |
| 2950 | } |
| 2951 | |
Craig Mautner | e3a74d5 | 2013-02-22 14:14:58 -0800 | [diff] [blame] | 2952 | canMoveOptions = false; |
Craig Mautner | 525f3d9 | 2013-05-07 14:01:50 -0700 | [diff] [blame] | 2953 | if (noOptions && topOptions == null) { |
Craig Mautner | e3a74d5 | 2013-02-22 14:14:58 -0800 | [diff] [blame] | 2954 | topOptions = p.takeOptionsLocked(); |
| 2955 | if (topOptions != null) { |
Craig Mautner | 525f3d9 | 2013-05-07 14:01:50 -0700 | [diff] [blame] | 2956 | noOptions = false; |
Craig Mautner | e3a74d5 | 2013-02-22 14:14:58 -0800 | [diff] [blame] | 2957 | } |
| 2958 | } |
Wale Ogunwale | 0fc365c | 2015-05-25 19:35:42 -0700 | [diff] [blame] | 2959 | if (DEBUG_ADD_REMOVE) Slog.i(TAG_ADD_REMOVE, |
| 2960 | "Removing activity " + p + " from task=" + task + " adding to task=" |
| 2961 | + targetTask + " Callers=" + Debug.getCallers(4)); |
Wale Ogunwale | ee006da | 2015-03-30 14:49:25 -0700 | [diff] [blame] | 2962 | if (DEBUG_TASKS) Slog.v(TAG_TASKS, |
| 2963 | "Pushing next activity " + p + " out to target's task " + target.task); |
Craig Mautner | a228ae9 | 2014-07-09 05:44:55 -0700 | [diff] [blame] | 2964 | p.setTask(targetTask, null); |
Craig Mautner | e3a74d5 | 2013-02-22 14:14:58 -0800 | [diff] [blame] | 2965 | targetTask.addActivityAtBottom(p); |
Craig Mautner | 0247fc8 | 2013-02-28 14:32:06 -0800 | [diff] [blame] | 2966 | |
Wale Ogunwale | 706ed79 | 2015-08-02 10:29:44 -0700 | [diff] [blame] | 2967 | setAppTask(p, targetTask); |
Craig Mautner | e3a74d5 | 2013-02-22 14:14:58 -0800 | [diff] [blame] | 2968 | } |
| 2969 | |
Wale Ogunwale | 706ed79 | 2015-08-02 10:29:44 -0700 | [diff] [blame] | 2970 | mWindowManager.moveTaskToBottom(targetTask.taskId); |
Craig Mautner | e3a74d5 | 2013-02-22 14:14:58 -0800 | [diff] [blame] | 2971 | replyChainEnd = -1; |
| 2972 | } else if (forceReset || finishOnTaskLaunch || clearWhenTaskReset) { |
| 2973 | // If the activity should just be removed -- either |
| 2974 | // because it asks for it, or the task should be |
| 2975 | // cleared -- then finish it and anything that is |
| 2976 | // part of its reply chain. |
| 2977 | int end; |
| 2978 | if (clearWhenTaskReset) { |
| 2979 | // In this case, we want to finish this activity |
| 2980 | // and everything above it, so be sneaky and pretend |
| 2981 | // like these are all in the reply chain. |
Mark Lu | 4b5a9a0 | 2014-12-09 14:47:13 +0800 | [diff] [blame] | 2982 | end = activities.size() - 1; |
Craig Mautner | e3a74d5 | 2013-02-22 14:14:58 -0800 | [diff] [blame] | 2983 | } else if (replyChainEnd < 0) { |
| 2984 | end = i; |
| 2985 | } else { |
| 2986 | end = replyChainEnd; |
| 2987 | } |
Craig Mautner | 525f3d9 | 2013-05-07 14:01:50 -0700 | [diff] [blame] | 2988 | boolean noOptions = canMoveOptions; |
Craig Mautner | e3a74d5 | 2013-02-22 14:14:58 -0800 | [diff] [blame] | 2989 | for (int srcPos = i; srcPos <= end; srcPos++) { |
Craig Mautner | 525f3d9 | 2013-05-07 14:01:50 -0700 | [diff] [blame] | 2990 | ActivityRecord p = activities.get(srcPos); |
Craig Mautner | e3a74d5 | 2013-02-22 14:14:58 -0800 | [diff] [blame] | 2991 | if (p.finishing) { |
| 2992 | continue; |
| 2993 | } |
| 2994 | canMoveOptions = false; |
Craig Mautner | 525f3d9 | 2013-05-07 14:01:50 -0700 | [diff] [blame] | 2995 | if (noOptions && topOptions == null) { |
Craig Mautner | e3a74d5 | 2013-02-22 14:14:58 -0800 | [diff] [blame] | 2996 | topOptions = p.takeOptionsLocked(); |
| 2997 | if (topOptions != null) { |
Craig Mautner | 525f3d9 | 2013-05-07 14:01:50 -0700 | [diff] [blame] | 2998 | noOptions = false; |
Craig Mautner | e3a74d5 | 2013-02-22 14:14:58 -0800 | [diff] [blame] | 2999 | } |
| 3000 | } |
Wale Ogunwale | ee006da | 2015-03-30 14:49:25 -0700 | [diff] [blame] | 3001 | if (DEBUG_TASKS) Slog.w(TAG_TASKS, |
Craig Mautner | 5854780 | 2013-03-05 08:23:53 -0800 | [diff] [blame] | 3002 | "resetTaskIntendedTask: calling finishActivity on " + p); |
Todd Kennedy | 539db51 | 2014-12-15 09:57:55 -0800 | [diff] [blame] | 3003 | if (finishActivityLocked( |
| 3004 | p, Activity.RESULT_CANCELED, null, "reset-task", false)) { |
Craig Mautner | e3a74d5 | 2013-02-22 14:14:58 -0800 | [diff] [blame] | 3005 | end--; |
| 3006 | srcPos--; |
| 3007 | } |
| 3008 | } |
| 3009 | replyChainEnd = -1; |
| 3010 | } else { |
| 3011 | // If we were in the middle of a chain, well the |
| 3012 | // activity that started it all doesn't want anything |
| 3013 | // special, so leave it all as-is. |
| 3014 | replyChainEnd = -1; |
| 3015 | } |
| 3016 | } |
| 3017 | |
| 3018 | return topOptions; |
| 3019 | } |
| 3020 | |
| 3021 | /** |
| 3022 | * Helper method for #resetTaskIfNeededLocked. Processes all of the activities in a given |
| 3023 | * TaskRecord looking for an affinity with the task of resetTaskIfNeededLocked.taskTop. |
| 3024 | * @param affinityTask The task we are looking for an affinity to. |
| 3025 | * @param task Task that resetTaskIfNeededLocked.taskTop belongs to. |
| 3026 | * @param topTaskIsHigher True if #task has already been processed by resetTaskIfNeededLocked. |
| 3027 | * @param forceReset Flag passed in to resetTaskIfNeededLocked. |
| 3028 | */ |
Craig Mautner | 525f3d9 | 2013-05-07 14:01:50 -0700 | [diff] [blame] | 3029 | private int resetAffinityTaskIfNeededLocked(TaskRecord affinityTask, TaskRecord task, |
Craig Mautner | 7787877 | 2013-03-04 19:46:24 -0800 | [diff] [blame] | 3030 | boolean topTaskIsHigher, boolean forceReset, int taskInsertionPoint) { |
Craig Mautner | e3a74d5 | 2013-02-22 14:14:58 -0800 | [diff] [blame] | 3031 | int replyChainEnd = -1; |
| 3032 | final int taskId = task.taskId; |
| 3033 | final String taskAffinity = task.affinity; |
| 3034 | |
| 3035 | final ArrayList<ActivityRecord> activities = affinityTask.mActivities; |
| 3036 | final int numActivities = activities.size(); |
Craig Mautner | 9d4e9bc | 2014-06-18 18:34:56 -0700 | [diff] [blame] | 3037 | final int rootActivityNdx = affinityTask.findEffectiveRootIndex(); |
| 3038 | |
| 3039 | // Do not operate on or below the effective root Activity. |
| 3040 | for (int i = numActivities - 1; i > rootActivityNdx; --i) { |
Craig Mautner | e3a74d5 | 2013-02-22 14:14:58 -0800 | [diff] [blame] | 3041 | ActivityRecord target = activities.get(i); |
Craig Mautner | 76ae2f0 | 2014-07-16 16:16:19 +0000 | [diff] [blame] | 3042 | if (target.frontOfTask) |
| 3043 | break; |
Craig Mautner | e3a74d5 | 2013-02-22 14:14:58 -0800 | [diff] [blame] | 3044 | |
| 3045 | final int flags = target.info.flags; |
| 3046 | boolean finishOnTaskLaunch = (flags & ActivityInfo.FLAG_FINISH_ON_TASK_LAUNCH) != 0; |
| 3047 | boolean allowTaskReparenting = (flags & ActivityInfo.FLAG_ALLOW_TASK_REPARENTING) != 0; |
| 3048 | |
| 3049 | if (target.resultTo != null) { |
| 3050 | // If this activity is sending a reply to a previous |
| 3051 | // activity, we can't do anything with it now until |
| 3052 | // we reach the start of the reply chain. |
| 3053 | // XXX note that we are assuming the result is always |
| 3054 | // to the previous activity, which is almost always |
| 3055 | // the case but we really shouldn't count on. |
| 3056 | if (replyChainEnd < 0) { |
| 3057 | replyChainEnd = i; |
| 3058 | } |
| 3059 | } else if (topTaskIsHigher |
| 3060 | && allowTaskReparenting |
| 3061 | && taskAffinity != null |
| 3062 | && taskAffinity.equals(target.taskAffinity)) { |
| 3063 | // This activity has an affinity for our task. Either remove it if we are |
| 3064 | // clearing or move it over to our task. Note that |
| 3065 | // we currently punt on the case where we are resetting a |
| 3066 | // task that is not at the top but who has activities above |
| 3067 | // with an affinity to it... this is really not a normal |
| 3068 | // case, and we will need to later pull that task to the front |
| 3069 | // and usually at that point we will do the reset and pick |
| 3070 | // up those remaining activities. (This only happens if |
| 3071 | // someone starts an activity in a new task from an activity |
| 3072 | // in a task that is not currently on top.) |
| 3073 | if (forceReset || finishOnTaskLaunch) { |
| 3074 | final int start = replyChainEnd >= 0 ? replyChainEnd : i; |
Wale Ogunwale | ee006da | 2015-03-30 14:49:25 -0700 | [diff] [blame] | 3075 | if (DEBUG_TASKS) Slog.v(TAG_TASKS, |
| 3076 | "Finishing task at index " + start + " to " + i); |
Craig Mautner | e3a74d5 | 2013-02-22 14:14:58 -0800 | [diff] [blame] | 3077 | for (int srcPos = start; srcPos >= i; --srcPos) { |
| 3078 | final ActivityRecord p = activities.get(srcPos); |
| 3079 | if (p.finishing) { |
| 3080 | continue; |
| 3081 | } |
Todd Kennedy | 539db51 | 2014-12-15 09:57:55 -0800 | [diff] [blame] | 3082 | finishActivityLocked( |
| 3083 | p, Activity.RESULT_CANCELED, null, "move-affinity", false); |
Craig Mautner | e3a74d5 | 2013-02-22 14:14:58 -0800 | [diff] [blame] | 3084 | } |
| 3085 | } else { |
Craig Mautner | 7787877 | 2013-03-04 19:46:24 -0800 | [diff] [blame] | 3086 | if (taskInsertionPoint < 0) { |
| 3087 | taskInsertionPoint = task.mActivities.size(); |
Craig Mautner | d232895 | 2013-03-05 12:46:26 -0800 | [diff] [blame] | 3088 | |
Craig Mautner | 7787877 | 2013-03-04 19:46:24 -0800 | [diff] [blame] | 3089 | } |
Craig Mautner | 7787877 | 2013-03-04 19:46:24 -0800 | [diff] [blame] | 3090 | |
| 3091 | final int start = replyChainEnd >= 0 ? replyChainEnd : i; |
Wale Ogunwale | ee006da | 2015-03-30 14:49:25 -0700 | [diff] [blame] | 3092 | if (DEBUG_TASKS) Slog.v(TAG_TASKS, |
| 3093 | "Reparenting from task=" + affinityTask + ":" + start + "-" + i |
| 3094 | + " to task=" + task + ":" + taskInsertionPoint); |
Craig Mautner | 7787877 | 2013-03-04 19:46:24 -0800 | [diff] [blame] | 3095 | for (int srcPos = start; srcPos >= i; --srcPos) { |
Craig Mautner | e3a74d5 | 2013-02-22 14:14:58 -0800 | [diff] [blame] | 3096 | final ActivityRecord p = activities.get(srcPos); |
Craig Mautner | a228ae9 | 2014-07-09 05:44:55 -0700 | [diff] [blame] | 3097 | p.setTask(task, null); |
Craig Mautner | 7787877 | 2013-03-04 19:46:24 -0800 | [diff] [blame] | 3098 | task.addActivityAtIndex(taskInsertionPoint, p); |
Craig Mautner | e3a74d5 | 2013-02-22 14:14:58 -0800 | [diff] [blame] | 3099 | |
Wale Ogunwale | 0fc365c | 2015-05-25 19:35:42 -0700 | [diff] [blame] | 3100 | if (DEBUG_ADD_REMOVE) Slog.i(TAG_ADD_REMOVE, |
| 3101 | "Removing and adding activity " + p + " to stack at " + task |
| 3102 | + " callers=" + Debug.getCallers(3)); |
Wale Ogunwale | ee006da | 2015-03-30 14:49:25 -0700 | [diff] [blame] | 3103 | if (DEBUG_TASKS) Slog.v(TAG_TASKS, "Pulling activity " + p |
| 3104 | + " from " + srcPos + " in to resetting task " + task); |
Wale Ogunwale | 706ed79 | 2015-08-02 10:29:44 -0700 | [diff] [blame] | 3105 | setAppTask(p, task); |
Craig Mautner | e3a74d5 | 2013-02-22 14:14:58 -0800 | [diff] [blame] | 3106 | } |
Craig Mautner | ce5f3cb | 2013-04-22 08:58:54 -0700 | [diff] [blame] | 3107 | mWindowManager.moveTaskToTop(taskId); |
Craig Mautner | e3a74d5 | 2013-02-22 14:14:58 -0800 | [diff] [blame] | 3108 | |
| 3109 | // Now we've moved it in to place... but what if this is |
| 3110 | // a singleTop activity and we have put it on top of another |
| 3111 | // instance of the same activity? Then we drop the instance |
| 3112 | // below so it remains singleTop. |
| 3113 | if (target.info.launchMode == ActivityInfo.LAUNCH_SINGLE_TOP) { |
| 3114 | ArrayList<ActivityRecord> taskActivities = task.mActivities; |
Craig Mautner | e3a74d5 | 2013-02-22 14:14:58 -0800 | [diff] [blame] | 3115 | int targetNdx = taskActivities.indexOf(target); |
| 3116 | if (targetNdx > 0) { |
| 3117 | ActivityRecord p = taskActivities.get(targetNdx - 1); |
| 3118 | if (p.intent.getComponent().equals(target.intent.getComponent())) { |
Craig Mautner | 5854780 | 2013-03-05 08:23:53 -0800 | [diff] [blame] | 3119 | finishActivityLocked(p, Activity.RESULT_CANCELED, null, "replace", |
| 3120 | false); |
Craig Mautner | e3a74d5 | 2013-02-22 14:14:58 -0800 | [diff] [blame] | 3121 | } |
| 3122 | } |
| 3123 | } |
| 3124 | } |
| 3125 | |
| 3126 | replyChainEnd = -1; |
| 3127 | } |
| 3128 | } |
Craig Mautner | 7787877 | 2013-03-04 19:46:24 -0800 | [diff] [blame] | 3129 | return taskInsertionPoint; |
Craig Mautner | e3a74d5 | 2013-02-22 14:14:58 -0800 | [diff] [blame] | 3130 | } |
| 3131 | |
Craig Mautner | 8849a5e | 2013-04-02 16:41:03 -0700 | [diff] [blame] | 3132 | final ActivityRecord resetTaskIfNeededLocked(ActivityRecord taskTop, |
Craig Mautner | e3a74d5 | 2013-02-22 14:14:58 -0800 | [diff] [blame] | 3133 | ActivityRecord newActivity) { |
| 3134 | boolean forceReset = |
| 3135 | (newActivity.info.flags & ActivityInfo.FLAG_CLEAR_TASK_ON_LAUNCH) != 0; |
| 3136 | if (ACTIVITY_INACTIVE_RESET_TIME > 0 |
| 3137 | && taskTop.task.getInactiveDuration() > ACTIVITY_INACTIVE_RESET_TIME) { |
| 3138 | if ((newActivity.info.flags & ActivityInfo.FLAG_ALWAYS_RETAIN_TASK_STATE) == 0) { |
| 3139 | forceReset = true; |
| 3140 | } |
| 3141 | } |
| 3142 | |
| 3143 | final TaskRecord task = taskTop.task; |
| 3144 | |
| 3145 | /** False until we evaluate the TaskRecord associated with taskTop. Switches to true |
| 3146 | * for remaining tasks. Used for later tasks to reparent to task. */ |
| 3147 | boolean taskFound = false; |
| 3148 | |
| 3149 | /** If ActivityOptions are moved out and need to be aborted or moved to taskTop. */ |
| 3150 | ActivityOptions topOptions = null; |
| 3151 | |
Craig Mautner | 7787877 | 2013-03-04 19:46:24 -0800 | [diff] [blame] | 3152 | // Preserve the location for reparenting in the new task. |
| 3153 | int reparentInsertionPoint = -1; |
| 3154 | |
Craig Mautner | e3a74d5 | 2013-02-22 14:14:58 -0800 | [diff] [blame] | 3155 | for (int i = mTaskHistory.size() - 1; i >= 0; --i) { |
| 3156 | final TaskRecord targetTask = mTaskHistory.get(i); |
| 3157 | |
| 3158 | if (targetTask == task) { |
| 3159 | topOptions = resetTargetTaskIfNeededLocked(task, forceReset); |
| 3160 | taskFound = true; |
| 3161 | } else { |
Craig Mautner | 7787877 | 2013-03-04 19:46:24 -0800 | [diff] [blame] | 3162 | reparentInsertionPoint = resetAffinityTaskIfNeededLocked(targetTask, task, |
| 3163 | taskFound, forceReset, reparentInsertionPoint); |
Craig Mautner | e3a74d5 | 2013-02-22 14:14:58 -0800 | [diff] [blame] | 3164 | } |
| 3165 | } |
| 3166 | |
Craig Mautner | 70a8693 | 2013-02-28 22:37:44 -0800 | [diff] [blame] | 3167 | int taskNdx = mTaskHistory.indexOf(task); |
riddle_hsu | 1d7919a | 2015-03-11 17:09:50 +0800 | [diff] [blame] | 3168 | if (taskNdx >= 0) { |
| 3169 | do { |
| 3170 | taskTop = mTaskHistory.get(taskNdx--).getTopActivity(); |
| 3171 | } while (taskTop == null && taskNdx >= 0); |
| 3172 | } |
Craig Mautner | 70a8693 | 2013-02-28 22:37:44 -0800 | [diff] [blame] | 3173 | |
Craig Mautner | e3a74d5 | 2013-02-22 14:14:58 -0800 | [diff] [blame] | 3174 | if (topOptions != null) { |
| 3175 | // If we got some ActivityOptions from an activity on top that |
| 3176 | // was removed from the task, propagate them to the new real top. |
| 3177 | if (taskTop != null) { |
Craig Mautner | e3a74d5 | 2013-02-22 14:14:58 -0800 | [diff] [blame] | 3178 | taskTop.updateOptionsLocked(topOptions); |
| 3179 | } else { |
Craig Mautner | e3a74d5 | 2013-02-22 14:14:58 -0800 | [diff] [blame] | 3180 | topOptions.abort(); |
| 3181 | } |
| 3182 | } |
| 3183 | |
| 3184 | return taskTop; |
| 3185 | } |
| 3186 | |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 3187 | void sendActivityResultLocked(int callingUid, ActivityRecord r, |
| 3188 | String resultWho, int requestCode, int resultCode, Intent data) { |
| 3189 | |
| 3190 | if (callingUid > 0) { |
| 3191 | mService.grantUriPermissionFromIntentLocked(callingUid, r.packageName, |
Nicolas Prevot | c6cf95c | 2014-05-29 11:30:36 +0100 | [diff] [blame] | 3192 | data, r.getUriPermissionsLocked(), r.userId); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 3193 | } |
| 3194 | |
| 3195 | if (DEBUG_RESULTS) Slog.v(TAG, "Send activity result to " + r |
| 3196 | + " : who=" + resultWho + " req=" + requestCode |
| 3197 | + " res=" + resultCode + " data=" + data); |
| 3198 | if (mResumedActivity == r && r.app != null && r.app.thread != null) { |
| 3199 | try { |
| 3200 | ArrayList<ResultInfo> list = new ArrayList<ResultInfo>(); |
| 3201 | list.add(new ResultInfo(resultWho, requestCode, |
| 3202 | resultCode, data)); |
Dianne Hackborn | be70785 | 2011-11-11 14:32:10 -0800 | [diff] [blame] | 3203 | r.app.thread.scheduleSendResult(r.appToken, list); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 3204 | return; |
| 3205 | } catch (Exception e) { |
| 3206 | Slog.w(TAG, "Exception thrown sending result to " + r, e); |
| 3207 | } |
| 3208 | } |
| 3209 | |
| 3210 | r.addResultLocked(null, resultWho, requestCode, resultCode, data); |
| 3211 | } |
| 3212 | |
Chong Zhang | 6cda19c | 2016-06-14 19:07:56 -0700 | [diff] [blame] | 3213 | private void adjustFocusedActivityStackLocked(ActivityRecord r, String reason) { |
| 3214 | if (!mStackSupervisor.isFocusedStack(this) || mResumedActivity != r) { |
Wale Ogunwale | d045c82 | 2015-12-02 09:14:28 -0800 | [diff] [blame] | 3215 | return; |
| 3216 | } |
| 3217 | |
| 3218 | final ActivityRecord next = topRunningActivityLocked(); |
| 3219 | final String myReason = reason + " adjustFocus"; |
| 3220 | if (next != r) { |
Wale Ogunwale | 4cea0f5 | 2015-12-25 06:30:31 -0800 | [diff] [blame] | 3221 | if (next != null && StackId.keepFocusInStackIfPossible(mStackId) && isFocusable()) { |
Wale Ogunwale | d045c82 | 2015-12-02 09:14:28 -0800 | [diff] [blame] | 3222 | // 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] | 3223 | // stack as long as there is a running activity. |
Wale Ogunwale | d045c82 | 2015-12-02 09:14:28 -0800 | [diff] [blame] | 3224 | return; |
| 3225 | } else { |
| 3226 | final TaskRecord task = r.task; |
| 3227 | if (r.frontOfTask && task == topTask() && task.isOverHomeStack()) { |
Wale Ogunwale | d34e80c | 2016-03-23 17:08:44 -0700 | [diff] [blame] | 3228 | final int taskToReturnTo = task.getTaskToReturnTo(); |
| 3229 | |
Wale Ogunwale | d045c82 | 2015-12-02 09:14:28 -0800 | [diff] [blame] | 3230 | // For non-fullscreen stack, we want to move the focus to the next visible |
| 3231 | // stack to prevent the home screen from moving to the top and obscuring |
| 3232 | // other visible stacks. |
Wale Ogunwale | d34e80c | 2016-03-23 17:08:44 -0700 | [diff] [blame] | 3233 | if (!mFullscreen |
| 3234 | && adjustFocusToNextFocusableStackLocked(taskToReturnTo, myReason)) { |
Wale Ogunwale | d045c82 | 2015-12-02 09:14:28 -0800 | [diff] [blame] | 3235 | return; |
| 3236 | } |
| 3237 | // Move the home stack to the top if this stack is fullscreen or there is no |
| 3238 | // other visible stack. |
Wale Ogunwale | d34e80c | 2016-03-23 17:08:44 -0700 | [diff] [blame] | 3239 | if (mStackSupervisor.moveHomeStackTaskToTop(taskToReturnTo, myReason)) { |
Wale Ogunwale | d045c82 | 2015-12-02 09:14:28 -0800 | [diff] [blame] | 3240 | // Activity focus was already adjusted. Nothing else to do... |
| 3241 | return; |
Wale Ogunwale | d80c263 | 2015-03-13 10:26:26 -0700 | [diff] [blame] | 3242 | } |
Craig Mautner | 04f0b70 | 2013-10-22 12:31:01 -0700 | [diff] [blame] | 3243 | } |
| 3244 | } |
Wale Ogunwale | d045c82 | 2015-12-02 09:14:28 -0800 | [diff] [blame] | 3245 | } |
Wale Ogunwale | d697cea | 2015-02-20 17:19:49 -0800 | [diff] [blame] | 3246 | |
Chong Zhang | 6cda19c | 2016-06-14 19:07:56 -0700 | [diff] [blame] | 3247 | mStackSupervisor.moveFocusableActivityStackToFrontLocked( |
| 3248 | mStackSupervisor.topRunningActivityLocked(), myReason); |
Craig Mautner | 04f0b70 | 2013-10-22 12:31:01 -0700 | [diff] [blame] | 3249 | } |
| 3250 | |
Wale Ogunwale | d34e80c | 2016-03-23 17:08:44 -0700 | [diff] [blame] | 3251 | private boolean adjustFocusToNextFocusableStackLocked(int taskToReturnTo, String reason) { |
Wale Ogunwale | 4cea0f5 | 2015-12-25 06:30:31 -0800 | [diff] [blame] | 3252 | final ActivityStack stack = getNextFocusableStackLocked(); |
| 3253 | final String myReason = reason + " adjustFocusToNextFocusableStack"; |
Wale Ogunwale | d697cea | 2015-02-20 17:19:49 -0800 | [diff] [blame] | 3254 | if (stack == null) { |
| 3255 | return false; |
| 3256 | } |
Wale Ogunwale | d34e80c | 2016-03-23 17:08:44 -0700 | [diff] [blame] | 3257 | |
Wale Ogunwale | c750f5f | 2016-03-28 07:43:51 -0700 | [diff] [blame] | 3258 | final ActivityRecord top = stack.topRunningActivityLocked(); |
| 3259 | |
| 3260 | if (stack.isHomeStack() && (top == null || !top.visible)) { |
| 3261 | // If we will be focusing on the home stack next and its current top activity isn't |
| 3262 | // 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] | 3263 | return mStackSupervisor.moveHomeStackTaskToTop(taskToReturnTo, reason); |
| 3264 | } |
Chong Zhang | 6cda19c | 2016-06-14 19:07:56 -0700 | [diff] [blame] | 3265 | |
| 3266 | stack.moveToFront(myReason); |
| 3267 | return true; |
Wale Ogunwale | d697cea | 2015-02-20 17:19:49 -0800 | [diff] [blame] | 3268 | } |
| 3269 | |
Craig Mautner | f333327 | 2013-04-22 10:55:53 -0700 | [diff] [blame] | 3270 | final void stopActivityLocked(ActivityRecord r) { |
Wale Ogunwale | ee006da | 2015-03-30 14:49:25 -0700 | [diff] [blame] | 3271 | if (DEBUG_SWITCH) Slog.d(TAG_SWITCH, "Stopping: " + r); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 3272 | if ((r.intent.getFlags()&Intent.FLAG_ACTIVITY_NO_HISTORY) != 0 |
| 3273 | || (r.info.flags&ActivityInfo.FLAG_NO_HISTORY) != 0) { |
| 3274 | if (!r.finishing) { |
Fyodor Kupolov | 9b80b94 | 2016-06-16 16:29:05 -0700 | [diff] [blame] | 3275 | if (!mService.isSleepingLocked()) { |
Wale Ogunwale | 0fc365c | 2015-05-25 19:35:42 -0700 | [diff] [blame] | 3276 | if (DEBUG_STATES) Slog.d(TAG_STATES, "no-history finish of " + r); |
Wale Ogunwale | 3f529ee | 2015-07-12 15:14:01 -0700 | [diff] [blame] | 3277 | if (requestFinishActivityLocked(r.appToken, Activity.RESULT_CANCELED, null, |
| 3278 | "stop-no-history", false)) { |
| 3279 | // Activity was finished, no need to continue trying to schedule stop. |
Chong Zhang | 6cda19c | 2016-06-14 19:07:56 -0700 | [diff] [blame] | 3280 | adjustFocusedActivityStackLocked(r, "stopActivityFinished"); |
Wale Ogunwale | 3f529ee | 2015-07-12 15:14:01 -0700 | [diff] [blame] | 3281 | r.resumeKeyDispatchingLocked(); |
| 3282 | return; |
| 3283 | } |
Christopher Tate | d3f175c | 2012-06-14 14:16:54 -0700 | [diff] [blame] | 3284 | } else { |
Wale Ogunwale | 0fc365c | 2015-05-25 19:35:42 -0700 | [diff] [blame] | 3285 | if (DEBUG_STATES) Slog.d(TAG_STATES, "Not finishing noHistory " + r |
Christopher Tate | d3f175c | 2012-06-14 14:16:54 -0700 | [diff] [blame] | 3286 | + " on stop because we're just sleeping"); |
| 3287 | } |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 3288 | } |
Christopher Tate | 5007ddd | 2012-06-12 13:08:18 -0700 | [diff] [blame] | 3289 | } |
| 3290 | |
| 3291 | if (r.app != null && r.app.thread != null) { |
Chong Zhang | 6cda19c | 2016-06-14 19:07:56 -0700 | [diff] [blame] | 3292 | adjustFocusedActivityStackLocked(r, "stopActivity"); |
Dianne Hackborn | 621e2fe | 2012-02-16 17:07:33 -0800 | [diff] [blame] | 3293 | r.resumeKeyDispatchingLocked(); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 3294 | try { |
| 3295 | r.stopped = false; |
Wale Ogunwale | 0fc365c | 2015-05-25 19:35:42 -0700 | [diff] [blame] | 3296 | if (DEBUG_STATES) Slog.v(TAG_STATES, |
| 3297 | "Moving to STOPPING: " + r + " (stop requested)"); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 3298 | r.state = ActivityState.STOPPING; |
Wale Ogunwale | ee006da | 2015-03-30 14:49:25 -0700 | [diff] [blame] | 3299 | if (DEBUG_VISIBILITY) Slog.v(TAG_VISIBILITY, |
| 3300 | "Stopping visible=" + r.visible + " for " + r); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 3301 | if (!r.visible) { |
Craig Mautner | ce5f3cb | 2013-04-22 08:58:54 -0700 | [diff] [blame] | 3302 | mWindowManager.setAppVisibility(r.appToken, false); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 3303 | } |
Wale Ogunwale | cd7043e | 2016-02-27 17:37:46 -0800 | [diff] [blame] | 3304 | EventLogTags.writeAmStopActivity( |
| 3305 | r.userId, System.identityHashCode(r), r.shortComponentName); |
Dianne Hackborn | be70785 | 2011-11-11 14:32:10 -0800 | [diff] [blame] | 3306 | r.app.thread.scheduleStopActivity(r.appToken, r.visible, r.configChangeFlags); |
Fyodor Kupolov | 9b80b94 | 2016-06-16 16:29:05 -0700 | [diff] [blame] | 3307 | if (mService.isSleepingOrShuttingDownLocked()) { |
Dianne Hackborn | 4eba96b | 2011-01-21 13:34:36 -0800 | [diff] [blame] | 3308 | r.setSleeping(true); |
| 3309 | } |
Craig Mautner | f7bfefb | 2013-05-16 17:30:44 -0700 | [diff] [blame] | 3310 | Message msg = mHandler.obtainMessage(STOP_TIMEOUT_MSG, r); |
Dianne Hackborn | 162bc0e | 2012-04-09 14:06:16 -0700 | [diff] [blame] | 3311 | mHandler.sendMessageDelayed(msg, STOP_TIMEOUT); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 3312 | } catch (Exception e) { |
| 3313 | // Maybe just ignore exceptions here... if the process |
| 3314 | // has crashed, our death notification will clean things |
| 3315 | // up. |
| 3316 | Slog.w(TAG, "Exception thrown during pause", e); |
| 3317 | // Just in case, assume it to be stopped. |
| 3318 | r.stopped = true; |
Wale Ogunwale | 0fc365c | 2015-05-25 19:35:42 -0700 | [diff] [blame] | 3319 | 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] | 3320 | r.state = ActivityState.STOPPED; |
Wale Ogunwale | f81c1d1 | 2016-01-12 12:20:18 -0800 | [diff] [blame] | 3321 | if (r.deferRelaunchUntilPaused) { |
Craig Mautner | ee2e45a | 2014-06-27 12:10:03 -0700 | [diff] [blame] | 3322 | destroyActivityLocked(r, true, "stop-except"); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 3323 | } |
| 3324 | } |
| 3325 | } |
| 3326 | } |
Craig Mautner | 23ac33b | 2013-04-01 16:26:35 -0700 | [diff] [blame] | 3327 | |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 3328 | /** |
| 3329 | * @return Returns true if the activity is being finished, false if for |
| 3330 | * some reason it is being left as-is. |
| 3331 | */ |
| 3332 | final boolean requestFinishActivityLocked(IBinder token, int resultCode, |
Dianne Hackborn | 2d1b378 | 2012-09-09 17:49:39 -0700 | [diff] [blame] | 3333 | Intent resultData, String reason, boolean oomAdj) { |
Craig Mautner | d74f7d7 | 2013-02-26 13:41:02 -0800 | [diff] [blame] | 3334 | ActivityRecord r = isInStackLocked(token); |
Wale Ogunwale | 0fc365c | 2015-05-25 19:35:42 -0700 | [diff] [blame] | 3335 | if (DEBUG_RESULTS || DEBUG_STATES) Slog.v(TAG_STATES, |
| 3336 | "Finishing activity token=" + token + " r=" |
Christopher Tate | d3f175c | 2012-06-14 14:16:54 -0700 | [diff] [blame] | 3337 | + ", result=" + resultCode + ", data=" + resultData |
| 3338 | + ", reason=" + reason); |
Craig Mautner | d74f7d7 | 2013-02-26 13:41:02 -0800 | [diff] [blame] | 3339 | if (r == null) { |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 3340 | return false; |
| 3341 | } |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 3342 | |
Craig Mautner | d44711d | 2013-02-23 11:24:36 -0800 | [diff] [blame] | 3343 | finishActivityLocked(r, resultCode, resultData, reason, oomAdj); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 3344 | return true; |
| 3345 | } |
| 3346 | |
Craig Mautner | d232895 | 2013-03-05 12:46:26 -0800 | [diff] [blame] | 3347 | final void finishSubActivityLocked(ActivityRecord self, String resultWho, int requestCode) { |
Craig Mautner | 9658b31 | 2013-02-28 10:55:59 -0800 | [diff] [blame] | 3348 | for (int taskNdx = mTaskHistory.size() - 1; taskNdx >= 0; --taskNdx) { |
| 3349 | ArrayList<ActivityRecord> activities = mTaskHistory.get(taskNdx).mActivities; |
| 3350 | for (int activityNdx = activities.size() - 1; activityNdx >= 0; --activityNdx) { |
| 3351 | ActivityRecord r = activities.get(activityNdx); |
| 3352 | if (r.resultTo == self && r.requestCode == requestCode) { |
| 3353 | if ((r.resultWho == null && resultWho == null) || |
| 3354 | (r.resultWho != null && r.resultWho.equals(resultWho))) { |
| 3355 | finishActivityLocked(r, Activity.RESULT_CANCELED, null, "request-sub", |
| 3356 | false); |
| 3357 | } |
Dianne Hackborn | ecc5a9c | 2012-04-26 18:56:09 -0700 | [diff] [blame] | 3358 | } |
| 3359 | } |
| 3360 | } |
Dianne Hackborn | 2d1b378 | 2012-09-09 17:49:39 -0700 | [diff] [blame] | 3361 | mService.updateOomAdjLocked(); |
Dianne Hackborn | ecc5a9c | 2012-04-26 18:56:09 -0700 | [diff] [blame] | 3362 | } |
| 3363 | |
Adrian Roos | 20d7df3 | 2016-01-12 18:59:43 +0100 | [diff] [blame] | 3364 | final TaskRecord finishTopRunningActivityLocked(ProcessRecord app, String reason) { |
Filip Gruszczynski | 3e85ba2 | 2015-10-05 22:48:30 -0700 | [diff] [blame] | 3365 | ActivityRecord r = topRunningActivityLocked(); |
Adrian Roos | 20d7df3 | 2016-01-12 18:59:43 +0100 | [diff] [blame] | 3366 | TaskRecord finishedTask = null; |
| 3367 | if (r == null || r.app != app) { |
| 3368 | return null; |
| 3369 | } |
| 3370 | Slog.w(TAG, " Force finishing activity " |
| 3371 | + r.intent.getComponent().flattenToShortString()); |
| 3372 | int taskNdx = mTaskHistory.indexOf(r.task); |
| 3373 | int activityNdx = r.task.mActivities.indexOf(r); |
| 3374 | finishActivityLocked(r, Activity.RESULT_CANCELED, null, reason, false); |
| 3375 | finishedTask = r.task; |
| 3376 | // Also terminate any activities below it that aren't yet |
| 3377 | // stopped, to avoid a situation where one will get |
| 3378 | // re-start our crashing activity once it gets resumed again. |
| 3379 | --activityNdx; |
| 3380 | if (activityNdx < 0) { |
| 3381 | do { |
| 3382 | --taskNdx; |
| 3383 | if (taskNdx < 0) { |
| 3384 | break; |
| 3385 | } |
| 3386 | activityNdx = mTaskHistory.get(taskNdx).mActivities.size() - 1; |
| 3387 | } while (activityNdx < 0); |
| 3388 | } |
| 3389 | if (activityNdx >= 0) { |
| 3390 | r = mTaskHistory.get(taskNdx).mActivities.get(activityNdx); |
| 3391 | if (r.state == ActivityState.RESUMED |
| 3392 | || r.state == ActivityState.PAUSING |
| 3393 | || r.state == ActivityState.PAUSED) { |
| 3394 | if (!r.isHomeActivity() || mService.mHomeProcess != r.app) { |
| 3395 | Slog.w(TAG, " Force finishing activity " |
| 3396 | + r.intent.getComponent().flattenToShortString()); |
| 3397 | finishActivityLocked(r, Activity.RESULT_CANCELED, null, reason, false); |
Craig Mautner | 05d6272ba | 2013-02-11 09:39:27 -0800 | [diff] [blame] | 3398 | } |
| 3399 | } |
| 3400 | } |
Adrian Roos | 20d7df3 | 2016-01-12 18:59:43 +0100 | [diff] [blame] | 3401 | return finishedTask; |
Craig Mautner | 05d6272ba | 2013-02-11 09:39:27 -0800 | [diff] [blame] | 3402 | } |
| 3403 | |
Dianne Hackborn | 6ea0d0a | 2014-07-02 16:23:21 -0700 | [diff] [blame] | 3404 | final void finishVoiceTask(IVoiceInteractionSession session) { |
| 3405 | IBinder sessionBinder = session.asBinder(); |
| 3406 | boolean didOne = false; |
| 3407 | for (int taskNdx = mTaskHistory.size() - 1; taskNdx >= 0; --taskNdx) { |
| 3408 | TaskRecord tr = mTaskHistory.get(taskNdx); |
| 3409 | if (tr.voiceSession != null && tr.voiceSession.asBinder() == sessionBinder) { |
| 3410 | for (int activityNdx = tr.mActivities.size() - 1; activityNdx >= 0; --activityNdx) { |
| 3411 | ActivityRecord r = tr.mActivities.get(activityNdx); |
| 3412 | if (!r.finishing) { |
| 3413 | finishActivityLocked(r, Activity.RESULT_CANCELED, null, "finish-voice", |
| 3414 | false); |
| 3415 | didOne = true; |
| 3416 | } |
| 3417 | } |
Amith Yamasani | 0af6fa7 | 2016-01-17 15:36:19 -0800 | [diff] [blame] | 3418 | } else { |
| 3419 | // Check if any of the activities are using voice |
| 3420 | for (int activityNdx = tr.mActivities.size() - 1; activityNdx >= 0; --activityNdx) { |
| 3421 | ActivityRecord r = tr.mActivities.get(activityNdx); |
| 3422 | if (r.voiceSession != null |
| 3423 | && r.voiceSession.asBinder() == sessionBinder) { |
| 3424 | // Inform of cancellation |
| 3425 | r.clearVoiceSessionLocked(); |
| 3426 | try { |
| 3427 | r.app.thread.scheduleLocalVoiceInteractionStarted((IBinder) r.appToken, |
| 3428 | null); |
| 3429 | } catch (RemoteException re) { |
| 3430 | // Ok |
| 3431 | } |
Amith Yamasani | 0af6fa7 | 2016-01-17 15:36:19 -0800 | [diff] [blame] | 3432 | mService.finishRunningVoiceLocked(); |
| 3433 | break; |
| 3434 | } |
| 3435 | } |
Dianne Hackborn | 6ea0d0a | 2014-07-02 16:23:21 -0700 | [diff] [blame] | 3436 | } |
| 3437 | } |
Amith Yamasani | 0af6fa7 | 2016-01-17 15:36:19 -0800 | [diff] [blame] | 3438 | |
Dianne Hackborn | 6ea0d0a | 2014-07-02 16:23:21 -0700 | [diff] [blame] | 3439 | if (didOne) { |
| 3440 | mService.updateOomAdjLocked(); |
| 3441 | } |
| 3442 | } |
| 3443 | |
Craig Mautner | d232895 | 2013-03-05 12:46:26 -0800 | [diff] [blame] | 3444 | final boolean finishActivityAffinityLocked(ActivityRecord r) { |
Craig Mautner | d74f7d7 | 2013-02-26 13:41:02 -0800 | [diff] [blame] | 3445 | ArrayList<ActivityRecord> activities = r.task.mActivities; |
| 3446 | for (int index = activities.indexOf(r); index >= 0; --index) { |
| 3447 | ActivityRecord cur = activities.get(index); |
Kenny Root | e6585b3 | 2013-12-13 12:00:26 -0800 | [diff] [blame] | 3448 | if (!Objects.equals(cur.taskAffinity, r.taskAffinity)) { |
Dianne Hackborn | ecc5a9c | 2012-04-26 18:56:09 -0700 | [diff] [blame] | 3449 | break; |
| 3450 | } |
Craig Mautner | de4ef02 | 2013-04-07 19:01:33 -0700 | [diff] [blame] | 3451 | finishActivityLocked(cur, Activity.RESULT_CANCELED, null, "request-affinity", true); |
Dianne Hackborn | ecc5a9c | 2012-04-26 18:56:09 -0700 | [diff] [blame] | 3452 | } |
| 3453 | return true; |
| 3454 | } |
| 3455 | |
Dianne Hackborn | 5c60743 | 2012-02-28 14:44:19 -0800 | [diff] [blame] | 3456 | final void finishActivityResultsLocked(ActivityRecord r, int resultCode, Intent resultData) { |
| 3457 | // send the result |
| 3458 | ActivityRecord resultTo = r.resultTo; |
| 3459 | if (resultTo != null) { |
Wale Ogunwale | ee006da | 2015-03-30 14:49:25 -0700 | [diff] [blame] | 3460 | if (DEBUG_RESULTS) Slog.v(TAG_RESULTS, "Adding result to " + resultTo |
Dianne Hackborn | 5c60743 | 2012-02-28 14:44:19 -0800 | [diff] [blame] | 3461 | + " who=" + r.resultWho + " req=" + r.requestCode |
| 3462 | + " res=" + resultCode + " data=" + resultData); |
Nicolas Prevot | c6cf95c | 2014-05-29 11:30:36 +0100 | [diff] [blame] | 3463 | if (resultTo.userId != r.userId) { |
Nicolas Prevot | 6b942b8 | 2014-06-02 15:20:42 +0100 | [diff] [blame] | 3464 | if (resultData != null) { |
Nicolas Prevot | 107f7b7 | 2015-07-01 16:31:48 +0100 | [diff] [blame] | 3465 | resultData.prepareToLeaveUser(r.userId); |
Nicolas Prevot | 6b942b8 | 2014-06-02 15:20:42 +0100 | [diff] [blame] | 3466 | } |
Nicolas Prevot | c6cf95c | 2014-05-29 11:30:36 +0100 | [diff] [blame] | 3467 | } |
Dianne Hackborn | 5c60743 | 2012-02-28 14:44:19 -0800 | [diff] [blame] | 3468 | if (r.info.applicationInfo.uid > 0) { |
| 3469 | mService.grantUriPermissionFromIntentLocked(r.info.applicationInfo.uid, |
| 3470 | resultTo.packageName, resultData, |
Nicolas Prevot | c6cf95c | 2014-05-29 11:30:36 +0100 | [diff] [blame] | 3471 | resultTo.getUriPermissionsLocked(), resultTo.userId); |
Dianne Hackborn | 5c60743 | 2012-02-28 14:44:19 -0800 | [diff] [blame] | 3472 | } |
| 3473 | resultTo.addResultLocked(r, r.resultWho, r.requestCode, resultCode, |
| 3474 | resultData); |
| 3475 | r.resultTo = null; |
| 3476 | } |
Wale Ogunwale | ee006da | 2015-03-30 14:49:25 -0700 | [diff] [blame] | 3477 | 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] | 3478 | |
| 3479 | // Make sure this HistoryRecord is not holding on to other resources, |
| 3480 | // because clients have remote IPC references to this object so we |
| 3481 | // can't assume that will go away and want to avoid circular IPC refs. |
| 3482 | r.results = null; |
| 3483 | r.pendingResults = null; |
| 3484 | r.newIntents = null; |
| 3485 | r.icicle = null; |
| 3486 | } |
| 3487 | |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 3488 | /** |
| 3489 | * @return Returns true if this activity has been removed from the history |
| 3490 | * list, or false if it is still in the list and will be removed later. |
| 3491 | */ |
Craig Mautner | f333327 | 2013-04-22 10:55:53 -0700 | [diff] [blame] | 3492 | final boolean finishActivityLocked(ActivityRecord r, int resultCode, Intent resultData, |
| 3493 | String reason, boolean oomAdj) { |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 3494 | if (r.finishing) { |
| 3495 | Slog.w(TAG, "Duplicate finish request for " + r); |
| 3496 | return false; |
| 3497 | } |
| 3498 | |
Wale Ogunwale | 7d70117 | 2015-03-11 15:36:30 -0700 | [diff] [blame] | 3499 | r.makeFinishingLocked(); |
Craig Mautner | aea74a5 | 2014-03-08 14:23:10 -0800 | [diff] [blame] | 3500 | final TaskRecord task = r.task; |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 3501 | EventLog.writeEvent(EventLogTags.AM_FINISH_ACTIVITY, |
Dianne Hackborn | b12e135 | 2012-09-26 11:39:20 -0700 | [diff] [blame] | 3502 | r.userId, System.identityHashCode(r), |
Craig Mautner | aea74a5 | 2014-03-08 14:23:10 -0800 | [diff] [blame] | 3503 | task.taskId, r.shortComponentName, reason); |
| 3504 | final ArrayList<ActivityRecord> activities = task.mActivities; |
Craig Mautner | d44711d | 2013-02-23 11:24:36 -0800 | [diff] [blame] | 3505 | final int index = activities.indexOf(r); |
| 3506 | if (index < (activities.size() - 1)) { |
Craig Mautner | aea74a5 | 2014-03-08 14:23:10 -0800 | [diff] [blame] | 3507 | task.setFrontOfTask(); |
Craig Mautner | d00f474 | 2014-03-12 14:17:26 -0700 | [diff] [blame] | 3508 | if ((r.intent.getFlags() & Intent.FLAG_ACTIVITY_CLEAR_WHEN_TASK_RESET) != 0) { |
Craig Mautner | d44711d | 2013-02-23 11:24:36 -0800 | [diff] [blame] | 3509 | // If the caller asked that this activity (and all above it) |
| 3510 | // be cleared when the task is reset, don't lose that information, |
| 3511 | // but propagate it up to the next activity. |
Craig Mautner | 1aa9d0d3f | 2013-12-16 15:58:31 -0800 | [diff] [blame] | 3512 | ActivityRecord next = activities.get(index+1); |
Craig Mautner | d44711d | 2013-02-23 11:24:36 -0800 | [diff] [blame] | 3513 | next.intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_WHEN_TASK_RESET); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 3514 | } |
| 3515 | } |
| 3516 | |
| 3517 | r.pauseKeyDispatchingLocked(); |
Craig Mautner | 04f0b70 | 2013-10-22 12:31:01 -0700 | [diff] [blame] | 3518 | |
Chong Zhang | 6cda19c | 2016-06-14 19:07:56 -0700 | [diff] [blame] | 3519 | adjustFocusedActivityStackLocked(r, "finishActivity"); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 3520 | |
Dianne Hackborn | 5c60743 | 2012-02-28 14:44:19 -0800 | [diff] [blame] | 3521 | finishActivityResultsLocked(r, resultCode, resultData); |
Craig Mautner | 2420ead | 2013-04-01 17:13:20 -0700 | [diff] [blame] | 3522 | |
Jorim Jaggi | af80db4 | 2016-04-07 19:19:15 -0700 | [diff] [blame] | 3523 | final boolean endTask = index <= 0; |
| 3524 | final int transit = endTask ? TRANSIT_TASK_CLOSE : TRANSIT_ACTIVITY_CLOSE; |
Craig Mautner | de4ef02 | 2013-04-07 19:01:33 -0700 | [diff] [blame] | 3525 | if (mResumedActivity == r) { |
Jorim Jaggi | af80db4 | 2016-04-07 19:19:15 -0700 | [diff] [blame] | 3526 | |
Wale Ogunwale | ee006da | 2015-03-30 14:49:25 -0700 | [diff] [blame] | 3527 | if (DEBUG_VISIBILITY || DEBUG_TRANSITION) Slog.v(TAG_TRANSITION, |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 3528 | "Prepare close transition: finishing " + r); |
Jorim Jaggi | af80db4 | 2016-04-07 19:19:15 -0700 | [diff] [blame] | 3529 | mWindowManager.prepareAppTransition(transit, false); |
Craig Mautner | 0247fc8 | 2013-02-28 14:32:06 -0800 | [diff] [blame] | 3530 | |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 3531 | // Tell window manager to prepare for this one to be removed. |
Craig Mautner | ce5f3cb | 2013-04-22 08:58:54 -0700 | [diff] [blame] | 3532 | mWindowManager.setAppVisibility(r.appToken, false); |
Craig Mautner | dbcb31f | 2013-04-02 12:32:53 -0700 | [diff] [blame] | 3533 | |
Dianne Hackborn | 621e2fe | 2012-02-16 17:07:33 -0800 | [diff] [blame] | 3534 | if (mPausingActivity == null) { |
Wale Ogunwale | ee006da | 2015-03-30 14:49:25 -0700 | [diff] [blame] | 3535 | if (DEBUG_PAUSE) Slog.v(TAG_PAUSE, "Finish needs to pause: " + r); |
| 3536 | if (DEBUG_USER_LEAVING) Slog.v(TAG_USER_LEAVING, |
| 3537 | "finish() => pause with userLeaving=false"); |
Wale Ogunwale | 950faff | 2016-08-08 09:51:04 -0700 | [diff] [blame] | 3538 | startPausingLocked(false, false, null, false); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 3539 | } |
| 3540 | |
Craig Mautner | aea74a5 | 2014-03-08 14:23:10 -0800 | [diff] [blame] | 3541 | if (endTask) { |
Craig Mautner | 15df08a | 2015-04-01 12:17:18 -0700 | [diff] [blame] | 3542 | mStackSupervisor.removeLockedTaskLocked(task); |
Craig Mautner | aea74a5 | 2014-03-08 14:23:10 -0800 | [diff] [blame] | 3543 | } |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 3544 | } else if (r.state != ActivityState.PAUSING) { |
| 3545 | // If the activity is PAUSING, we will complete the finish once |
| 3546 | // it is done pausing; else we can just directly finish it here. |
Wale Ogunwale | ee006da | 2015-03-30 14:49:25 -0700 | [diff] [blame] | 3547 | if (DEBUG_PAUSE) Slog.v(TAG_PAUSE, "Finish not pausing: " + r); |
Chong Zhang | 66ed4c6 | 2015-11-12 14:56:28 -0800 | [diff] [blame] | 3548 | if (r.visible) { |
Jorim Jaggi | af80db4 | 2016-04-07 19:19:15 -0700 | [diff] [blame] | 3549 | mWindowManager.prepareAppTransition(transit, false); |
Chong Zhang | 66ed4c6 | 2015-11-12 14:56:28 -0800 | [diff] [blame] | 3550 | mWindowManager.setAppVisibility(r.appToken, false); |
Jorim Jaggi | af80db4 | 2016-04-07 19:19:15 -0700 | [diff] [blame] | 3551 | mWindowManager.executeAppTransition(); |
Chong Zhang | b8bd069 | 2016-04-27 17:29:28 -0700 | [diff] [blame] | 3552 | if (!mStackSupervisor.mWaitingVisibleActivities.contains(r)) { |
| 3553 | mStackSupervisor.mWaitingVisibleActivities.add(r); |
| 3554 | } |
Chong Zhang | 66ed4c6 | 2015-11-12 14:56:28 -0800 | [diff] [blame] | 3555 | } |
Chong Zhang | 4c5f7ff | 2016-04-22 11:31:51 -0700 | [diff] [blame] | 3556 | return finishCurrentActivityLocked(r, (r.visible || r.nowVisible) ? |
| 3557 | FINISH_AFTER_VISIBLE : FINISH_AFTER_PAUSE, oomAdj) == null; |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 3558 | } else { |
Wale Ogunwale | ee006da | 2015-03-30 14:49:25 -0700 | [diff] [blame] | 3559 | 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] | 3560 | } |
| 3561 | |
| 3562 | return false; |
| 3563 | } |
| 3564 | |
Craig Mautner | f333327 | 2013-04-22 10:55:53 -0700 | [diff] [blame] | 3565 | static final int FINISH_IMMEDIATELY = 0; |
| 3566 | static final int FINISH_AFTER_PAUSE = 1; |
| 3567 | static final int FINISH_AFTER_VISIBLE = 2; |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 3568 | |
Craig Mautner | f333327 | 2013-04-22 10:55:53 -0700 | [diff] [blame] | 3569 | final ActivityRecord finishCurrentActivityLocked(ActivityRecord r, int mode, boolean oomAdj) { |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 3570 | // First things first: if this activity is currently visible, |
| 3571 | // and the resumed activity is not yet visible, then hold off on |
| 3572 | // finishing until the resumed one becomes visible. |
Chong Zhang | 824b6dc | 2016-04-27 14:11:12 -0700 | [diff] [blame] | 3573 | |
| 3574 | final ActivityRecord next = mStackSupervisor.topRunningActivityLocked(); |
| 3575 | |
Chong Zhang | efd9a5b | 2016-04-26 16:21:07 -0700 | [diff] [blame] | 3576 | if (mode == FINISH_AFTER_VISIBLE && (r.visible || r.nowVisible) |
Chong Zhang | 824b6dc | 2016-04-27 14:11:12 -0700 | [diff] [blame] | 3577 | && next != null && !next.nowVisible) { |
Craig Mautner | de4ef02 | 2013-04-07 19:01:33 -0700 | [diff] [blame] | 3578 | if (!mStackSupervisor.mStoppingActivities.contains(r)) { |
Chong Zhang | 46b1ac6 | 2016-02-18 17:53:57 -0800 | [diff] [blame] | 3579 | addToStopping(r, false /* immediate */); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 3580 | } |
Wale Ogunwale | 0fc365c | 2015-05-25 19:35:42 -0700 | [diff] [blame] | 3581 | if (DEBUG_STATES) Slog.v(TAG_STATES, |
| 3582 | "Moving to STOPPING: "+ r + " (finish requested)"); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 3583 | r.state = ActivityState.STOPPING; |
Dianne Hackborn | 2d1b378 | 2012-09-09 17:49:39 -0700 | [diff] [blame] | 3584 | if (oomAdj) { |
| 3585 | mService.updateOomAdjLocked(); |
| 3586 | } |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 3587 | return r; |
| 3588 | } |
| 3589 | |
| 3590 | // make sure the record is cleaned out of other places. |
Craig Mautner | de4ef02 | 2013-04-07 19:01:33 -0700 | [diff] [blame] | 3591 | mStackSupervisor.mStoppingActivities.remove(r); |
Craig Mautner | 0eea92c | 2013-05-16 13:35:39 -0700 | [diff] [blame] | 3592 | mStackSupervisor.mGoingToSleepActivities.remove(r); |
Craig Mautner | de4ef02 | 2013-04-07 19:01:33 -0700 | [diff] [blame] | 3593 | mStackSupervisor.mWaitingVisibleActivities.remove(r); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 3594 | if (mResumedActivity == r) { |
| 3595 | mResumedActivity = null; |
| 3596 | } |
| 3597 | final ActivityState prevState = r.state; |
Wale Ogunwale | 0fc365c | 2015-05-25 19:35:42 -0700 | [diff] [blame] | 3598 | if (DEBUG_STATES) Slog.v(TAG_STATES, "Moving to FINISHING: " + r); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 3599 | r.state = ActivityState.FINISHING; |
Andrii Kulian | 995fa2b | 2016-07-29 12:55:41 -0700 | [diff] [blame] | 3600 | final boolean finishingActivityInNonFocusedStack |
| 3601 | = r.task.stack != mStackSupervisor.getFocusedStack() |
| 3602 | && prevState == ActivityState.PAUSED && mode == FINISH_AFTER_VISIBLE; |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 3603 | |
| 3604 | if (mode == FINISH_IMMEDIATELY |
Wale Ogunwale | ae30f30 | 2016-05-02 10:35:45 -0700 | [diff] [blame] | 3605 | || (prevState == ActivityState.PAUSED |
Andrii Kulian | 995fa2b | 2016-07-29 12:55:41 -0700 | [diff] [blame] | 3606 | && (mode == FINISH_AFTER_PAUSE || mStackId == PINNED_STACK_ID)) |
| 3607 | || finishingActivityInNonFocusedStack |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 3608 | || prevState == ActivityState.STOPPED |
| 3609 | || prevState == ActivityState.INITIALIZING) { |
Wale Ogunwale | 7d70117 | 2015-03-11 15:36:30 -0700 | [diff] [blame] | 3610 | r.makeFinishingLocked(); |
Craig Mautner | ee2e45a | 2014-06-27 12:10:03 -0700 | [diff] [blame] | 3611 | boolean activityRemoved = destroyActivityLocked(r, true, "finish-imm"); |
Andrii Kulian | 7318d63 | 2016-07-20 18:59:28 -0700 | [diff] [blame] | 3612 | |
Andrii Kulian | 995fa2b | 2016-07-29 12:55:41 -0700 | [diff] [blame] | 3613 | if (finishingActivityInNonFocusedStack) { |
| 3614 | // Finishing activity that was in paused state and it was in not currently focused |
| 3615 | // stack, need to make something visible in its place. |
Andrii Kulian | 7318d63 | 2016-07-20 18:59:28 -0700 | [diff] [blame] | 3616 | mStackSupervisor.ensureActivitiesVisibleLocked(null, 0, !PRESERVE_WINDOWS); |
| 3617 | } |
Dianne Hackborn | 42e620c | 2012-06-24 13:20:51 -0700 | [diff] [blame] | 3618 | if (activityRemoved) { |
Wale Ogunwale | d046a01 | 2015-12-24 13:05:59 -0800 | [diff] [blame] | 3619 | mStackSupervisor.resumeFocusedStackTopActivityLocked(); |
Dianne Hackborn | 42e620c | 2012-06-24 13:20:51 -0700 | [diff] [blame] | 3620 | } |
Wale Ogunwale | 0fc365c | 2015-05-25 19:35:42 -0700 | [diff] [blame] | 3621 | if (DEBUG_CONTAINERS) Slog.d(TAG_CONTAINERS, |
Craig Mautner | d163e75 | 2014-06-13 17:18:47 -0700 | [diff] [blame] | 3622 | "destroyActivityLocked: finishCurrentActivityLocked r=" + r + |
| 3623 | " destroy returned removed=" + activityRemoved); |
Dianne Hackborn | 42e620c | 2012-06-24 13:20:51 -0700 | [diff] [blame] | 3624 | return activityRemoved ? null : r; |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 3625 | } |
Craig Mautner | 05d6272ba | 2013-02-11 09:39:27 -0800 | [diff] [blame] | 3626 | |
| 3627 | // Need to go through the full pause cycle to get this |
| 3628 | // activity into the stopped state and then finish it. |
Wale Ogunwale | e23149f | 2015-03-06 15:39:44 -0800 | [diff] [blame] | 3629 | if (DEBUG_ALL) Slog.v(TAG, "Enqueueing pending finish: " + r); |
Craig Mautner | f333327 | 2013-04-22 10:55:53 -0700 | [diff] [blame] | 3630 | mStackSupervisor.mFinishingActivities.add(r); |
Martin Wallgren | c8733b8 | 2011-08-31 12:39:31 +0200 | [diff] [blame] | 3631 | r.resumeKeyDispatchingLocked(); |
Wale Ogunwale | d046a01 | 2015-12-24 13:05:59 -0800 | [diff] [blame] | 3632 | mStackSupervisor.resumeFocusedStackTopActivityLocked(); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 3633 | return r; |
| 3634 | } |
| 3635 | |
Craig Mautner | ee36c77 | 2014-07-16 14:56:05 -0700 | [diff] [blame] | 3636 | void finishAllActivitiesLocked(boolean immediately) { |
| 3637 | boolean noActivitiesInStack = true; |
Craig Mautner | f4c909b | 2014-04-17 18:39:38 -0700 | [diff] [blame] | 3638 | for (int taskNdx = mTaskHistory.size() - 1; taskNdx >= 0; --taskNdx) { |
| 3639 | final ArrayList<ActivityRecord> activities = mTaskHistory.get(taskNdx).mActivities; |
| 3640 | for (int activityNdx = activities.size() - 1; activityNdx >= 0; --activityNdx) { |
| 3641 | final ActivityRecord r = activities.get(activityNdx); |
Craig Mautner | ee36c77 | 2014-07-16 14:56:05 -0700 | [diff] [blame] | 3642 | noActivitiesInStack = false; |
| 3643 | if (r.finishing && !immediately) { |
Craig Mautner | f4c909b | 2014-04-17 18:39:38 -0700 | [diff] [blame] | 3644 | continue; |
| 3645 | } |
Craig Mautner | ee36c77 | 2014-07-16 14:56:05 -0700 | [diff] [blame] | 3646 | Slog.d(TAG, "finishAllActivitiesLocked: finishing " + r + " immediately"); |
Craig Mautner | f4c909b | 2014-04-17 18:39:38 -0700 | [diff] [blame] | 3647 | finishCurrentActivityLocked(r, FINISH_IMMEDIATELY, false); |
| 3648 | } |
| 3649 | } |
Craig Mautner | ee36c77 | 2014-07-16 14:56:05 -0700 | [diff] [blame] | 3650 | if (noActivitiesInStack) { |
| 3651 | mActivityContainer.onTaskListEmptyLocked(); |
| 3652 | } |
Craig Mautner | f4c909b | 2014-04-17 18:39:38 -0700 | [diff] [blame] | 3653 | } |
| 3654 | |
Dianne Hackborn | 6f4d61f | 2014-08-21 17:50:42 -0700 | [diff] [blame] | 3655 | final boolean shouldUpRecreateTaskLocked(ActivityRecord srec, String destAffinity) { |
| 3656 | // Basic case: for simple app-centric recents, we need to recreate |
| 3657 | // the task if the affinity has changed. |
| 3658 | if (srec == null || srec.task.affinity == null || |
| 3659 | !srec.task.affinity.equals(destAffinity)) { |
| 3660 | return true; |
| 3661 | } |
| 3662 | // Document-centric case: an app may be split in to multiple documents; |
| 3663 | // they need to re-create their task if this current activity is the root |
| 3664 | // of a document, unless simply finishing it will return them to the the |
| 3665 | // correct app behind. |
Dianne Hackborn | f3eb843 | 2014-09-19 17:21:46 -0700 | [diff] [blame] | 3666 | if (srec.frontOfTask && srec.task != null && srec.task.getBaseIntent() != null |
| 3667 | && srec.task.getBaseIntent().isDocument()) { |
Dianne Hackborn | 6f4d61f | 2014-08-21 17:50:42 -0700 | [diff] [blame] | 3668 | // Okay, this activity is at the root of its task. What to do, what to do... |
| 3669 | if (srec.task.getTaskToReturnTo() != ActivityRecord.APPLICATION_ACTIVITY_TYPE) { |
| 3670 | // Finishing won't return to an application, so we need to recreate. |
| 3671 | return true; |
| 3672 | } |
| 3673 | // We now need to get the task below it to determine what to do. |
| 3674 | int taskIdx = mTaskHistory.indexOf(srec.task); |
| 3675 | if (taskIdx <= 0) { |
| 3676 | Slog.w(TAG, "shouldUpRecreateTask: task not in history for " + srec); |
| 3677 | return false; |
| 3678 | } |
| 3679 | if (taskIdx == 0) { |
| 3680 | // At the bottom of the stack, nothing to go back to. |
| 3681 | return true; |
| 3682 | } |
| 3683 | TaskRecord prevTask = mTaskHistory.get(taskIdx); |
| 3684 | if (!srec.task.affinity.equals(prevTask.affinity)) { |
| 3685 | // These are different apps, so need to recreate. |
| 3686 | return true; |
| 3687 | } |
| 3688 | } |
| 3689 | return false; |
| 3690 | } |
| 3691 | |
Wale Ogunwale | 7d70117 | 2015-03-11 15:36:30 -0700 | [diff] [blame] | 3692 | final boolean navigateUpToLocked(ActivityRecord srec, Intent destIntent, int resultCode, |
Craig Mautner | 05d6272ba | 2013-02-11 09:39:27 -0800 | [diff] [blame] | 3693 | Intent resultData) { |
Craig Mautner | 0247fc8 | 2013-02-28 14:32:06 -0800 | [diff] [blame] | 3694 | final TaskRecord task = srec.task; |
| 3695 | final ArrayList<ActivityRecord> activities = task.mActivities; |
| 3696 | final int start = activities.indexOf(srec); |
| 3697 | if (!mTaskHistory.contains(task) || (start < 0)) { |
Craig Mautner | 05d6272ba | 2013-02-11 09:39:27 -0800 | [diff] [blame] | 3698 | return false; |
| 3699 | } |
| 3700 | int finishTo = start - 1; |
Craig Mautner | 0247fc8 | 2013-02-28 14:32:06 -0800 | [diff] [blame] | 3701 | ActivityRecord parent = finishTo < 0 ? null : activities.get(finishTo); |
Craig Mautner | 05d6272ba | 2013-02-11 09:39:27 -0800 | [diff] [blame] | 3702 | boolean foundParentInTask = false; |
Craig Mautner | 0247fc8 | 2013-02-28 14:32:06 -0800 | [diff] [blame] | 3703 | final ComponentName dest = destIntent.getComponent(); |
| 3704 | if (start > 0 && dest != null) { |
| 3705 | for (int i = finishTo; i >= 0; i--) { |
| 3706 | ActivityRecord r = activities.get(i); |
| 3707 | if (r.info.packageName.equals(dest.getPackageName()) && |
Craig Mautner | 05d6272ba | 2013-02-11 09:39:27 -0800 | [diff] [blame] | 3708 | r.info.name.equals(dest.getClassName())) { |
| 3709 | finishTo = i; |
| 3710 | parent = r; |
| 3711 | foundParentInTask = true; |
| 3712 | break; |
| 3713 | } |
| 3714 | } |
| 3715 | } |
| 3716 | |
| 3717 | IActivityController controller = mService.mController; |
| 3718 | if (controller != null) { |
| 3719 | ActivityRecord next = topRunningActivityLocked(srec.appToken, 0); |
| 3720 | if (next != null) { |
| 3721 | // ask watcher if this is allowed |
| 3722 | boolean resumeOK = true; |
| 3723 | try { |
| 3724 | resumeOK = controller.activityResuming(next.packageName); |
| 3725 | } catch (RemoteException e) { |
| 3726 | mService.mController = null; |
Kenny Root | add5821 | 2013-05-07 09:47:34 -0700 | [diff] [blame] | 3727 | Watchdog.getInstance().setActivityController(null); |
Craig Mautner | 05d6272ba | 2013-02-11 09:39:27 -0800 | [diff] [blame] | 3728 | } |
| 3729 | |
| 3730 | if (!resumeOK) { |
| 3731 | return false; |
| 3732 | } |
| 3733 | } |
| 3734 | } |
| 3735 | final long origId = Binder.clearCallingIdentity(); |
| 3736 | for (int i = start; i > finishTo; i--) { |
Craig Mautner | 0247fc8 | 2013-02-28 14:32:06 -0800 | [diff] [blame] | 3737 | ActivityRecord r = activities.get(i); |
| 3738 | requestFinishActivityLocked(r.appToken, resultCode, resultData, "navigate-up", true); |
Craig Mautner | 05d6272ba | 2013-02-11 09:39:27 -0800 | [diff] [blame] | 3739 | // Only return the supplied result for the first activity finished |
| 3740 | resultCode = Activity.RESULT_CANCELED; |
| 3741 | resultData = null; |
| 3742 | } |
| 3743 | |
| 3744 | if (parent != null && foundParentInTask) { |
| 3745 | final int parentLaunchMode = parent.info.launchMode; |
| 3746 | final int destIntentFlags = destIntent.getFlags(); |
| 3747 | if (parentLaunchMode == ActivityInfo.LAUNCH_SINGLE_INSTANCE || |
| 3748 | parentLaunchMode == ActivityInfo.LAUNCH_SINGLE_TASK || |
| 3749 | parentLaunchMode == ActivityInfo.LAUNCH_SINGLE_TOP || |
| 3750 | (destIntentFlags & Intent.FLAG_ACTIVITY_CLEAR_TOP) != 0) { |
Dianne Hackborn | 85d558c | 2014-11-04 10:31:54 -0800 | [diff] [blame] | 3751 | parent.deliverNewIntentLocked(srec.info.applicationInfo.uid, destIntent, |
| 3752 | srec.packageName); |
Craig Mautner | 05d6272ba | 2013-02-11 09:39:27 -0800 | [diff] [blame] | 3753 | } else { |
| 3754 | try { |
| 3755 | ActivityInfo aInfo = AppGlobals.getPackageManager().getActivityInfo( |
| 3756 | destIntent.getComponent(), 0, srec.userId); |
Filip Gruszczynski | 303210b | 2016-01-08 16:28:08 -0800 | [diff] [blame] | 3757 | int res = mService.mActivityStarter.startActivityLocked(srec.app.thread, |
| 3758 | destIntent, null /*ephemeralIntent*/, null, aInfo, null /*rInfo*/, null, |
| 3759 | null, parent.appToken, null, 0, -1, parent.launchedFromUid, |
Todd Kennedy | 7440f17 | 2015-12-09 14:31:22 -0800 | [diff] [blame] | 3760 | parent.launchedFromPackage, -1, parent.launchedFromUid, 0, null, |
| 3761 | false, true, null, null, null); |
Craig Mautner | 05d6272ba | 2013-02-11 09:39:27 -0800 | [diff] [blame] | 3762 | foundParentInTask = res == ActivityManager.START_SUCCESS; |
| 3763 | } catch (RemoteException e) { |
| 3764 | foundParentInTask = false; |
| 3765 | } |
| 3766 | requestFinishActivityLocked(parent.appToken, resultCode, |
Todd Kennedy | 539db51 | 2014-12-15 09:57:55 -0800 | [diff] [blame] | 3767 | resultData, "navigate-top", true); |
Craig Mautner | 05d6272ba | 2013-02-11 09:39:27 -0800 | [diff] [blame] | 3768 | } |
| 3769 | } |
| 3770 | Binder.restoreCallingIdentity(origId); |
| 3771 | return foundParentInTask; |
| 3772 | } |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 3773 | /** |
| 3774 | * Perform the common clean-up of an activity record. This is called both |
| 3775 | * as part of destroyActivityLocked() (when destroying the client-side |
| 3776 | * representation) and cleaning things up as a result of its hosting |
| 3777 | * processing going away, in which case there is no remaining client-side |
| 3778 | * state to destroy so only the cleanup here is needed. |
Craig Mautner | acebdc8 | 2015-02-24 10:53:03 -0800 | [diff] [blame] | 3779 | * |
| 3780 | * Note: Call before #removeActivityFromHistoryLocked. |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 3781 | */ |
Dianne Hackborn | ce86ba8 | 2011-07-13 19:33:41 -0700 | [diff] [blame] | 3782 | final void cleanUpActivityLocked(ActivityRecord r, boolean cleanServices, |
| 3783 | boolean setState) { |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 3784 | if (mResumedActivity == r) { |
| 3785 | mResumedActivity = null; |
| 3786 | } |
Craig Mautner | 1872ce3 | 2014-03-28 23:05:42 +0000 | [diff] [blame] | 3787 | if (mPausingActivity == r) { |
| 3788 | mPausingActivity = null; |
| 3789 | } |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 3790 | |
Wale Ogunwale | f81c1d1 | 2016-01-12 12:20:18 -0800 | [diff] [blame] | 3791 | r.deferRelaunchUntilPaused = false; |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 3792 | r.frozenBeforeDestroy = false; |
| 3793 | |
Dianne Hackborn | ce86ba8 | 2011-07-13 19:33:41 -0700 | [diff] [blame] | 3794 | if (setState) { |
Wale Ogunwale | 0fc365c | 2015-05-25 19:35:42 -0700 | [diff] [blame] | 3795 | 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] | 3796 | r.state = ActivityState.DESTROYED; |
Wale Ogunwale | 0fc365c | 2015-05-25 19:35:42 -0700 | [diff] [blame] | 3797 | 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] | 3798 | r.app = null; |
Dianne Hackborn | ce86ba8 | 2011-07-13 19:33:41 -0700 | [diff] [blame] | 3799 | } |
| 3800 | |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 3801 | // Make sure this record is no longer in the pending finishes list. |
| 3802 | // This could happen, for example, if we are trimming activities |
| 3803 | // down to the max limit while they are still waiting to finish. |
Craig Mautner | f333327 | 2013-04-22 10:55:53 -0700 | [diff] [blame] | 3804 | mStackSupervisor.mFinishingActivities.remove(r); |
Craig Mautner | de4ef02 | 2013-04-07 19:01:33 -0700 | [diff] [blame] | 3805 | mStackSupervisor.mWaitingVisibleActivities.remove(r); |
Craig Mautner | 2420ead | 2013-04-01 17:13:20 -0700 | [diff] [blame] | 3806 | |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 3807 | // Remove any pending results. |
| 3808 | if (r.finishing && r.pendingResults != null) { |
| 3809 | for (WeakReference<PendingIntentRecord> apr : r.pendingResults) { |
| 3810 | PendingIntentRecord rec = apr.get(); |
| 3811 | if (rec != null) { |
| 3812 | mService.cancelIntentSenderLocked(rec, false); |
| 3813 | } |
| 3814 | } |
| 3815 | r.pendingResults = null; |
| 3816 | } |
| 3817 | |
| 3818 | if (cleanServices) { |
Craig Mautner | 2420ead | 2013-04-01 17:13:20 -0700 | [diff] [blame] | 3819 | cleanUpActivityServicesLocked(r); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 3820 | } |
| 3821 | |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 3822 | // Get rid of any pending idle timeouts. |
Dianne Hackborn | 42e620c | 2012-06-24 13:20:51 -0700 | [diff] [blame] | 3823 | removeTimeoutsForActivityLocked(r); |
Jose Lima | 4b6c669 | 2014-08-12 17:41:12 -0700 | [diff] [blame] | 3824 | if (getVisibleBehindActivity() == r) { |
| 3825 | mStackSupervisor.requestVisibleBehindLocked(r, false); |
Craig Mautner | ee2e45a | 2014-06-27 12:10:03 -0700 | [diff] [blame] | 3826 | } |
Wale Ogunwale | 8fd7542 | 2016-06-24 14:20:37 -0700 | [diff] [blame] | 3827 | |
| 3828 | // Clean-up activities are no longer relaunching (e.g. app process died). Notify window |
| 3829 | // manager so it can update its bookkeeping. |
| 3830 | mWindowManager.notifyAppRelaunchesCleared(r.appToken); |
Dianne Hackborn | 42e620c | 2012-06-24 13:20:51 -0700 | [diff] [blame] | 3831 | } |
| 3832 | |
| 3833 | private void removeTimeoutsForActivityLocked(ActivityRecord r) { |
Craig Mautner | f333327 | 2013-04-22 10:55:53 -0700 | [diff] [blame] | 3834 | mStackSupervisor.removeTimeoutsForActivityLocked(r); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 3835 | mHandler.removeMessages(PAUSE_TIMEOUT_MSG, r); |
Dianne Hackborn | 162bc0e | 2012-04-09 14:06:16 -0700 | [diff] [blame] | 3836 | mHandler.removeMessages(STOP_TIMEOUT_MSG, r); |
Dianne Hackborn | 0c5001d | 2011-04-12 18:16:08 -0700 | [diff] [blame] | 3837 | mHandler.removeMessages(DESTROY_TIMEOUT_MSG, r); |
Dianne Hackborn | 2a29b3a | 2012-03-15 15:48:38 -0700 | [diff] [blame] | 3838 | r.finishLaunchTickingLocked(); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 3839 | } |
| 3840 | |
Chong Zhang | bffd889 | 2016-08-08 11:16:06 -0700 | [diff] [blame] | 3841 | private void removeActivityFromHistoryLocked(ActivityRecord r, String reason) { |
Craig Mautner | 34b73df | 2014-01-12 21:11:08 -0800 | [diff] [blame] | 3842 | mStackSupervisor.removeChildActivityContainers(r); |
Dianne Hackborn | cc5a055 | 2012-10-01 16:32:39 -0700 | [diff] [blame] | 3843 | finishActivityResultsLocked(r, Activity.RESULT_CANCELED, null); |
Wale Ogunwale | 7d70117 | 2015-03-11 15:36:30 -0700 | [diff] [blame] | 3844 | r.makeFinishingLocked(); |
Wale Ogunwale | 0fc365c | 2015-05-25 19:35:42 -0700 | [diff] [blame] | 3845 | if (DEBUG_ADD_REMOVE) Slog.i(TAG_ADD_REMOVE, |
| 3846 | "Removing activity " + r + " from stack callers=" + Debug.getCallers(5)); |
| 3847 | |
Dianne Hackborn | cc5a055 | 2012-10-01 16:32:39 -0700 | [diff] [blame] | 3848 | r.takeFromHistory(); |
| 3849 | removeTimeoutsForActivityLocked(r); |
Wale Ogunwale | 0fc365c | 2015-05-25 19:35:42 -0700 | [diff] [blame] | 3850 | if (DEBUG_STATES) Slog.v(TAG_STATES, |
| 3851 | "Moving to DESTROYED: " + r + " (removed from history)"); |
Dianne Hackborn | cc5a055 | 2012-10-01 16:32:39 -0700 | [diff] [blame] | 3852 | r.state = ActivityState.DESTROYED; |
Wale Ogunwale | 0fc365c | 2015-05-25 19:35:42 -0700 | [diff] [blame] | 3853 | 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] | 3854 | r.app = null; |
Craig Mautner | ce5f3cb | 2013-04-22 08:58:54 -0700 | [diff] [blame] | 3855 | mWindowManager.removeAppToken(r.appToken); |
Craig Mautner | 312ba86 | 2014-02-10 17:55:01 -0800 | [diff] [blame] | 3856 | final TaskRecord task = r.task; |
| 3857 | if (task != null && task.removeActivity(r)) { |
Wale Ogunwale | ee006da | 2015-03-30 14:49:25 -0700 | [diff] [blame] | 3858 | if (DEBUG_STACK) Slog.i(TAG_STACK, |
Craig Mautner | 312ba86 | 2014-02-10 17:55:01 -0800 | [diff] [blame] | 3859 | "removeActivityFromHistoryLocked: last activity removed from " + this); |
Chong Zhang | bffd889 | 2016-08-08 11:16:06 -0700 | [diff] [blame] | 3860 | if (mStackSupervisor.isFocusedStack(this) && task == topTask() && |
Craig Mautner | 84984fa | 2014-06-19 11:19:20 -0700 | [diff] [blame] | 3861 | task.isOverHomeStack()) { |
Craig Mautner | 299f960 | 2015-01-26 09:47:33 -0800 | [diff] [blame] | 3862 | mStackSupervisor.moveHomeStackTaskToTop(task.getTaskToReturnTo(), reason); |
Craig Mautner | 312ba86 | 2014-02-10 17:55:01 -0800 | [diff] [blame] | 3863 | } |
Craig Mautner | 299f960 | 2015-01-26 09:47:33 -0800 | [diff] [blame] | 3864 | removeTask(task, reason); |
Craig Mautner | 312ba86 | 2014-02-10 17:55:01 -0800 | [diff] [blame] | 3865 | } |
Dianne Hackborn | cc5a055 | 2012-10-01 16:32:39 -0700 | [diff] [blame] | 3866 | cleanUpActivityServicesLocked(r); |
| 3867 | r.removeUriPermissionsLocked(); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 3868 | } |
Craig Mautner | dbcb31f | 2013-04-02 12:32:53 -0700 | [diff] [blame] | 3869 | |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 3870 | /** |
| 3871 | * Perform clean-up of service connections in an activity record. |
| 3872 | */ |
| 3873 | final void cleanUpActivityServicesLocked(ActivityRecord r) { |
| 3874 | // Throw away any services that have been bound by this activity. |
| 3875 | if (r.connections != null) { |
| 3876 | Iterator<ConnectionRecord> it = r.connections.iterator(); |
| 3877 | while (it.hasNext()) { |
| 3878 | ConnectionRecord c = it.next(); |
Dianne Hackborn | 599db5c | 2012-08-03 19:28:48 -0700 | [diff] [blame] | 3879 | mService.mServices.removeConnectionLocked(c, null, r); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 3880 | } |
| 3881 | r.connections = null; |
| 3882 | } |
| 3883 | } |
Dianne Hackborn | 755c8bf | 2012-05-07 15:06:09 -0700 | [diff] [blame] | 3884 | |
Craig Mautner | ee2e45a | 2014-06-27 12:10:03 -0700 | [diff] [blame] | 3885 | final void scheduleDestroyActivities(ProcessRecord owner, String reason) { |
Dianne Hackborn | 755c8bf | 2012-05-07 15:06:09 -0700 | [diff] [blame] | 3886 | Message msg = mHandler.obtainMessage(DESTROY_ACTIVITIES_MSG); |
Craig Mautner | ee2e45a | 2014-06-27 12:10:03 -0700 | [diff] [blame] | 3887 | msg.obj = new ScheduleDestroyArgs(owner, reason); |
Dianne Hackborn | 755c8bf | 2012-05-07 15:06:09 -0700 | [diff] [blame] | 3888 | mHandler.sendMessage(msg); |
| 3889 | } |
| 3890 | |
Craig Mautner | ee2e45a | 2014-06-27 12:10:03 -0700 | [diff] [blame] | 3891 | final void destroyActivitiesLocked(ProcessRecord owner, String reason) { |
Dianne Hackborn | 755c8bf | 2012-05-07 15:06:09 -0700 | [diff] [blame] | 3892 | boolean lastIsOpaque = false; |
Dianne Hackborn | 42e620c | 2012-06-24 13:20:51 -0700 | [diff] [blame] | 3893 | boolean activityRemoved = false; |
Craig Mautner | d44711d | 2013-02-23 11:24:36 -0800 | [diff] [blame] | 3894 | for (int taskNdx = mTaskHistory.size() - 1; taskNdx >= 0; --taskNdx) { |
| 3895 | final ArrayList<ActivityRecord> activities = mTaskHistory.get(taskNdx).mActivities; |
| 3896 | for (int activityNdx = activities.size() - 1; activityNdx >= 0; --activityNdx) { |
| 3897 | final ActivityRecord r = activities.get(activityNdx); |
| 3898 | if (r.finishing) { |
| 3899 | continue; |
| 3900 | } |
| 3901 | if (r.fullscreen) { |
| 3902 | lastIsOpaque = true; |
| 3903 | } |
| 3904 | if (owner != null && r.app != owner) { |
| 3905 | continue; |
| 3906 | } |
| 3907 | if (!lastIsOpaque) { |
| 3908 | continue; |
| 3909 | } |
Dianne Hackborn | 89ad456 | 2014-08-24 16:45:38 -0700 | [diff] [blame] | 3910 | if (r.isDestroyable()) { |
Wale Ogunwale | ee006da | 2015-03-30 14:49:25 -0700 | [diff] [blame] | 3911 | 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] | 3912 | + " resumed=" + mResumedActivity |
Dianne Hackborn | 89ad456 | 2014-08-24 16:45:38 -0700 | [diff] [blame] | 3913 | + " pausing=" + mPausingActivity + " for reason " + reason); |
Craig Mautner | ee2e45a | 2014-06-27 12:10:03 -0700 | [diff] [blame] | 3914 | if (destroyActivityLocked(r, true, reason)) { |
Craig Mautner | d44711d | 2013-02-23 11:24:36 -0800 | [diff] [blame] | 3915 | activityRemoved = true; |
| 3916 | } |
Dianne Hackborn | 42e620c | 2012-06-24 13:20:51 -0700 | [diff] [blame] | 3917 | } |
Dianne Hackborn | ce86ba8 | 2011-07-13 19:33:41 -0700 | [diff] [blame] | 3918 | } |
| 3919 | } |
Dianne Hackborn | 42e620c | 2012-06-24 13:20:51 -0700 | [diff] [blame] | 3920 | if (activityRemoved) { |
Wale Ogunwale | d046a01 | 2015-12-24 13:05:59 -0800 | [diff] [blame] | 3921 | mStackSupervisor.resumeFocusedStackTopActivityLocked(); |
Dianne Hackborn | 42e620c | 2012-06-24 13:20:51 -0700 | [diff] [blame] | 3922 | } |
Dianne Hackborn | ce86ba8 | 2011-07-13 19:33:41 -0700 | [diff] [blame] | 3923 | } |
| 3924 | |
Dianne Hackborn | 89ad456 | 2014-08-24 16:45:38 -0700 | [diff] [blame] | 3925 | final boolean safelyDestroyActivityLocked(ActivityRecord r, String reason) { |
| 3926 | if (r.isDestroyable()) { |
Wale Ogunwale | ee006da | 2015-03-30 14:49:25 -0700 | [diff] [blame] | 3927 | if (DEBUG_SWITCH) Slog.v(TAG_SWITCH, |
| 3928 | "Destroying " + r + " in state " + r.state + " resumed=" + mResumedActivity |
Dianne Hackborn | 89ad456 | 2014-08-24 16:45:38 -0700 | [diff] [blame] | 3929 | + " pausing=" + mPausingActivity + " for reason " + reason); |
| 3930 | return destroyActivityLocked(r, true, reason); |
| 3931 | } |
| 3932 | return false; |
| 3933 | } |
| 3934 | |
| 3935 | final int releaseSomeActivitiesLocked(ProcessRecord app, ArraySet<TaskRecord> tasks, |
| 3936 | String reason) { |
| 3937 | // Iterate over tasks starting at the back (oldest) first. |
Wale Ogunwale | 0fc365c | 2015-05-25 19:35:42 -0700 | [diff] [blame] | 3938 | 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] | 3939 | int maxTasks = tasks.size() / 4; |
| 3940 | if (maxTasks < 1) { |
| 3941 | maxTasks = 1; |
| 3942 | } |
| 3943 | int numReleased = 0; |
| 3944 | for (int taskNdx = 0; taskNdx < mTaskHistory.size() && maxTasks > 0; taskNdx++) { |
| 3945 | final TaskRecord task = mTaskHistory.get(taskNdx); |
| 3946 | if (!tasks.contains(task)) { |
| 3947 | continue; |
| 3948 | } |
Wale Ogunwale | 0fc365c | 2015-05-25 19:35:42 -0700 | [diff] [blame] | 3949 | 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] | 3950 | int curNum = 0; |
| 3951 | final ArrayList<ActivityRecord> activities = task.mActivities; |
| 3952 | for (int actNdx = 0; actNdx < activities.size(); actNdx++) { |
| 3953 | final ActivityRecord activity = activities.get(actNdx); |
| 3954 | if (activity.app == app && activity.isDestroyable()) { |
Wale Ogunwale | 0fc365c | 2015-05-25 19:35:42 -0700 | [diff] [blame] | 3955 | if (DEBUG_RELEASE) Slog.v(TAG_RELEASE, "Destroying " + activity |
Dianne Hackborn | 89ad456 | 2014-08-24 16:45:38 -0700 | [diff] [blame] | 3956 | + " in state " + activity.state + " resumed=" + mResumedActivity |
| 3957 | + " pausing=" + mPausingActivity + " for reason " + reason); |
| 3958 | destroyActivityLocked(activity, true, reason); |
| 3959 | if (activities.get(actNdx) != activity) { |
| 3960 | // Was removed from list, back up so we don't miss the next one. |
| 3961 | actNdx--; |
| 3962 | } |
| 3963 | curNum++; |
| 3964 | } |
| 3965 | } |
| 3966 | if (curNum > 0) { |
| 3967 | numReleased += curNum; |
| 3968 | maxTasks--; |
| 3969 | if (mTaskHistory.get(taskNdx) != task) { |
| 3970 | // The entire task got removed, back up so we don't miss the next one. |
| 3971 | taskNdx--; |
| 3972 | } |
| 3973 | } |
| 3974 | } |
Wale Ogunwale | 0fc365c | 2015-05-25 19:35:42 -0700 | [diff] [blame] | 3975 | if (DEBUG_RELEASE) Slog.d(TAG_RELEASE, |
| 3976 | "Done releasing: did " + numReleased + " activities"); |
Dianne Hackborn | 89ad456 | 2014-08-24 16:45:38 -0700 | [diff] [blame] | 3977 | return numReleased; |
| 3978 | } |
| 3979 | |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 3980 | /** |
| 3981 | * Destroy the current CLIENT SIDE instance of an activity. This may be |
| 3982 | * called both when actually finishing an activity, or when performing |
| 3983 | * a configuration switch where we destroy the current client-side object |
| 3984 | * but then create a new client-side object for this same HistoryRecord. |
| 3985 | */ |
Craig Mautner | ee2e45a | 2014-06-27 12:10:03 -0700 | [diff] [blame] | 3986 | final boolean destroyActivityLocked(ActivityRecord r, boolean removeFromApp, String reason) { |
Wale Ogunwale | ee006da | 2015-03-30 14:49:25 -0700 | [diff] [blame] | 3987 | if (DEBUG_SWITCH || DEBUG_CLEANUP) Slog.v(TAG_SWITCH, |
| 3988 | "Removing activity from " + reason + ": token=" + r |
Filip Gruszczynski | a59ac9c | 2015-09-10 18:28:48 -0700 | [diff] [blame] | 3989 | + ", app=" + (r.app != null ? r.app.processName : "(null)")); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 3990 | EventLog.writeEvent(EventLogTags.AM_DESTROY_ACTIVITY, |
Dianne Hackborn | b12e135 | 2012-09-26 11:39:20 -0700 | [diff] [blame] | 3991 | r.userId, System.identityHashCode(r), |
Dianne Hackborn | 28695e0 | 2011-11-02 21:59:51 -0700 | [diff] [blame] | 3992 | r.task.taskId, r.shortComponentName, reason); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 3993 | |
| 3994 | boolean removedFromHistory = false; |
Dianne Hackborn | cc5a055 | 2012-10-01 16:32:39 -0700 | [diff] [blame] | 3995 | |
Dianne Hackborn | ce86ba8 | 2011-07-13 19:33:41 -0700 | [diff] [blame] | 3996 | cleanUpActivityLocked(r, false, false); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 3997 | |
| 3998 | final boolean hadApp = r.app != null; |
Dianne Hackborn | cc5a055 | 2012-10-01 16:32:39 -0700 | [diff] [blame] | 3999 | |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 4000 | if (hadApp) { |
| 4001 | if (removeFromApp) { |
Craig Mautner | d232895 | 2013-03-05 12:46:26 -0800 | [diff] [blame] | 4002 | r.app.activities.remove(r); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 4003 | if (mService.mHeavyWeightProcess == r.app && r.app.activities.size() <= 0) { |
| 4004 | mService.mHeavyWeightProcess = null; |
| 4005 | mService.mHandler.sendEmptyMessage( |
| 4006 | ActivityManagerService.CANCEL_HEAVY_NOTIFICATION_MSG); |
| 4007 | } |
Craig Mautner | c8143c6 | 2013-09-03 12:15:57 -0700 | [diff] [blame] | 4008 | if (r.app.activities.isEmpty()) { |
Dianne Hackborn | 465fa39 | 2014-09-14 14:21:18 -0700 | [diff] [blame] | 4009 | // Update any services we are bound to that might care about whether |
| 4010 | // their client may have activities. |
| 4011 | mService.mServices.updateServiceConnectionActivitiesLocked(r.app); |
Dianne Hackborn | 3bc8f78d | 2013-09-19 13:34:35 -0700 | [diff] [blame] | 4012 | // No longer have activities, so update LRU list and oom adj. |
Dianne Hackborn | db92608 | 2013-10-31 16:32:44 -0700 | [diff] [blame] | 4013 | mService.updateLruProcessLocked(r.app, false, null); |
Dianne Hackborn | 2d1b378 | 2012-09-09 17:49:39 -0700 | [diff] [blame] | 4014 | mService.updateOomAdjLocked(); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 4015 | } |
| 4016 | } |
| 4017 | |
| 4018 | boolean skipDestroy = false; |
Craig Mautner | dbcb31f | 2013-04-02 12:32:53 -0700 | [diff] [blame] | 4019 | |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 4020 | try { |
Wale Ogunwale | ee006da | 2015-03-30 14:49:25 -0700 | [diff] [blame] | 4021 | if (DEBUG_SWITCH) Slog.i(TAG_SWITCH, "Destroying: " + r); |
Dianne Hackborn | be70785 | 2011-11-11 14:32:10 -0800 | [diff] [blame] | 4022 | r.app.thread.scheduleDestroyActivity(r.appToken, r.finishing, |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 4023 | r.configChangeFlags); |
| 4024 | } catch (Exception e) { |
| 4025 | // We can just ignore exceptions here... if the process |
| 4026 | // has crashed, our death notification will clean things |
| 4027 | // up. |
| 4028 | //Slog.w(TAG, "Exception thrown during finish", e); |
| 4029 | if (r.finishing) { |
Chong Zhang | bffd889 | 2016-08-08 11:16:06 -0700 | [diff] [blame] | 4030 | removeActivityFromHistoryLocked(r, reason + " exceptionInScheduleDestroy"); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 4031 | removedFromHistory = true; |
| 4032 | skipDestroy = true; |
| 4033 | } |
| 4034 | } |
| 4035 | |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 4036 | r.nowVisible = false; |
Craig Mautner | dbcb31f | 2013-04-02 12:32:53 -0700 | [diff] [blame] | 4037 | |
Dianne Hackborn | ce86ba8 | 2011-07-13 19:33:41 -0700 | [diff] [blame] | 4038 | // If the activity is finishing, we need to wait on removing it |
| 4039 | // from the list to give it a chance to do its cleanup. During |
| 4040 | // that time it may make calls back with its token so we need to |
| 4041 | // be able to find it on the list and so we don't want to remove |
| 4042 | // it from the list yet. Otherwise, we can just immediately put |
| 4043 | // it in the destroyed state since we are not removing it from the |
| 4044 | // list. |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 4045 | if (r.finishing && !skipDestroy) { |
Wale Ogunwale | 0fc365c | 2015-05-25 19:35:42 -0700 | [diff] [blame] | 4046 | if (DEBUG_STATES) Slog.v(TAG_STATES, "Moving to DESTROYING: " + r |
Dianne Hackborn | ce86ba8 | 2011-07-13 19:33:41 -0700 | [diff] [blame] | 4047 | + " (destroy requested)"); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 4048 | r.state = ActivityState.DESTROYING; |
Craig Mautner | f7bfefb | 2013-05-16 17:30:44 -0700 | [diff] [blame] | 4049 | Message msg = mHandler.obtainMessage(DESTROY_TIMEOUT_MSG, r); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 4050 | mHandler.sendMessageDelayed(msg, DESTROY_TIMEOUT); |
| 4051 | } else { |
Wale Ogunwale | 0fc365c | 2015-05-25 19:35:42 -0700 | [diff] [blame] | 4052 | if (DEBUG_STATES) Slog.v(TAG_STATES, |
| 4053 | "Moving to DESTROYED: " + r + " (destroy skipped)"); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 4054 | r.state = ActivityState.DESTROYED; |
Wale Ogunwale | 0fc365c | 2015-05-25 19:35:42 -0700 | [diff] [blame] | 4055 | 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] | 4056 | r.app = null; |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 4057 | } |
| 4058 | } else { |
| 4059 | // remove this record from the history. |
| 4060 | if (r.finishing) { |
Chong Zhang | bffd889 | 2016-08-08 11:16:06 -0700 | [diff] [blame] | 4061 | removeActivityFromHistoryLocked(r, reason + " hadNoApp"); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 4062 | removedFromHistory = true; |
| 4063 | } else { |
Wale Ogunwale | 0fc365c | 2015-05-25 19:35:42 -0700 | [diff] [blame] | 4064 | 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] | 4065 | r.state = ActivityState.DESTROYED; |
Wale Ogunwale | 0fc365c | 2015-05-25 19:35:42 -0700 | [diff] [blame] | 4066 | 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] | 4067 | r.app = null; |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 4068 | } |
| 4069 | } |
| 4070 | |
| 4071 | r.configChangeFlags = 0; |
Craig Mautner | dbcb31f | 2013-04-02 12:32:53 -0700 | [diff] [blame] | 4072 | |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 4073 | if (!mLRUActivities.remove(r) && hadApp) { |
| 4074 | Slog.w(TAG, "Activity " + r + " being finished, but not in LRU list"); |
| 4075 | } |
Craig Mautner | dbcb31f | 2013-04-02 12:32:53 -0700 | [diff] [blame] | 4076 | |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 4077 | return removedFromHistory; |
| 4078 | } |
| 4079 | |
Craig Mautner | 299f960 | 2015-01-26 09:47:33 -0800 | [diff] [blame] | 4080 | final void activityDestroyedLocked(IBinder token, String reason) { |
Craig Mautner | d232895 | 2013-03-05 12:46:26 -0800 | [diff] [blame] | 4081 | final long origId = Binder.clearCallingIdentity(); |
| 4082 | try { |
Wale Ogunwale | 7d70117 | 2015-03-11 15:36:30 -0700 | [diff] [blame] | 4083 | ActivityRecord r = ActivityRecord.forTokenLocked(token); |
Craig Mautner | d232895 | 2013-03-05 12:46:26 -0800 | [diff] [blame] | 4084 | if (r != null) { |
| 4085 | mHandler.removeMessages(DESTROY_TIMEOUT_MSG, r); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 4086 | } |
Wale Ogunwale | 0fc365c | 2015-05-25 19:35:42 -0700 | [diff] [blame] | 4087 | if (DEBUG_CONTAINERS) Slog.d(TAG_CONTAINERS, "activityDestroyedLocked: r=" + r); |
Craig Mautner | d232895 | 2013-03-05 12:46:26 -0800 | [diff] [blame] | 4088 | |
Wale Ogunwale | 60454db | 2015-01-23 16:05:07 -0800 | [diff] [blame] | 4089 | if (isInStackLocked(r) != null) { |
Craig Mautner | d232895 | 2013-03-05 12:46:26 -0800 | [diff] [blame] | 4090 | if (r.state == ActivityState.DESTROYING) { |
| 4091 | cleanUpActivityLocked(r, true, false); |
Chong Zhang | bffd889 | 2016-08-08 11:16:06 -0700 | [diff] [blame] | 4092 | removeActivityFromHistoryLocked(r, reason); |
Craig Mautner | d232895 | 2013-03-05 12:46:26 -0800 | [diff] [blame] | 4093 | } |
| 4094 | } |
Wale Ogunwale | d046a01 | 2015-12-24 13:05:59 -0800 | [diff] [blame] | 4095 | mStackSupervisor.resumeFocusedStackTopActivityLocked(); |
Craig Mautner | d232895 | 2013-03-05 12:46:26 -0800 | [diff] [blame] | 4096 | } finally { |
| 4097 | Binder.restoreCallingIdentity(origId); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 4098 | } |
| 4099 | } |
Craig Mautner | de4ef02 | 2013-04-07 19:01:33 -0700 | [diff] [blame] | 4100 | |
Todd Kennedy | aab56db | 2015-01-30 09:39:53 -0800 | [diff] [blame] | 4101 | void releaseBackgroundResources(ActivityRecord r) { |
Jose Lima | 4b6c669 | 2014-08-12 17:41:12 -0700 | [diff] [blame] | 4102 | if (hasVisibleBehindActivity() && |
| 4103 | !mHandler.hasMessages(RELEASE_BACKGROUND_RESOURCES_TIMEOUT_MSG)) { |
Wale Ogunwale | 8051c5c | 2016-03-04 10:27:32 -0800 | [diff] [blame] | 4104 | if (r == topRunningActivityLocked() |
| 4105 | && getStackVisibilityLocked(null) == STACK_VISIBLE) { |
Craig Mautner | 64ccb70 | 2014-10-01 09:38:40 -0700 | [diff] [blame] | 4106 | // 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] | 4107 | // activity and the stack is currently visible. |
Craig Mautner | 64ccb70 | 2014-10-01 09:38:40 -0700 | [diff] [blame] | 4108 | return; |
| 4109 | } |
Wale Ogunwale | 0fc365c | 2015-05-25 19:35:42 -0700 | [diff] [blame] | 4110 | if (DEBUG_STATES) Slog.d(TAG_STATES, "releaseBackgroundResources activtyDisplay=" + |
Jose Lima | 4b6c669 | 2014-08-12 17:41:12 -0700 | [diff] [blame] | 4111 | mActivityContainer.mActivityDisplay + " visibleBehind=" + r + " app=" + r.app + |
Craig Mautner | ee2e45a | 2014-06-27 12:10:03 -0700 | [diff] [blame] | 4112 | " thread=" + r.app.thread); |
| 4113 | if (r != null && r.app != null && r.app.thread != null) { |
| 4114 | try { |
Jose Lima | 4b6c669 | 2014-08-12 17:41:12 -0700 | [diff] [blame] | 4115 | r.app.thread.scheduleCancelVisibleBehind(r.appToken); |
Craig Mautner | ee2e45a | 2014-06-27 12:10:03 -0700 | [diff] [blame] | 4116 | } catch (RemoteException e) { |
| 4117 | } |
Jose Lima | 4b6c669 | 2014-08-12 17:41:12 -0700 | [diff] [blame] | 4118 | mHandler.sendEmptyMessageDelayed(RELEASE_BACKGROUND_RESOURCES_TIMEOUT_MSG, 500); |
Craig Mautner | ee2e45a | 2014-06-27 12:10:03 -0700 | [diff] [blame] | 4119 | } else { |
Jose Lima | 4b6c669 | 2014-08-12 17:41:12 -0700 | [diff] [blame] | 4120 | Slog.e(TAG, "releaseBackgroundResources: activity " + r + " no longer running"); |
Wale Ogunwale | 1f4c02b | 2014-11-13 14:22:32 -0800 | [diff] [blame] | 4121 | backgroundResourcesReleased(); |
Craig Mautner | ee2e45a | 2014-06-27 12:10:03 -0700 | [diff] [blame] | 4122 | } |
| 4123 | } |
| 4124 | } |
| 4125 | |
Wale Ogunwale | 1f4c02b | 2014-11-13 14:22:32 -0800 | [diff] [blame] | 4126 | final void backgroundResourcesReleased() { |
Jose Lima | 4b6c669 | 2014-08-12 17:41:12 -0700 | [diff] [blame] | 4127 | mHandler.removeMessages(RELEASE_BACKGROUND_RESOURCES_TIMEOUT_MSG); |
| 4128 | final ActivityRecord r = getVisibleBehindActivity(); |
Craig Mautner | ee2e45a | 2014-06-27 12:10:03 -0700 | [diff] [blame] | 4129 | if (r != null) { |
| 4130 | mStackSupervisor.mStoppingActivities.add(r); |
Jose Lima | 4b6c669 | 2014-08-12 17:41:12 -0700 | [diff] [blame] | 4131 | setVisibleBehindActivity(null); |
Wale Ogunwale | 1f4c02b | 2014-11-13 14:22:32 -0800 | [diff] [blame] | 4132 | mStackSupervisor.scheduleIdleTimeoutLocked(null); |
Craig Mautner | ee2e45a | 2014-06-27 12:10:03 -0700 | [diff] [blame] | 4133 | } |
Wale Ogunwale | d046a01 | 2015-12-24 13:05:59 -0800 | [diff] [blame] | 4134 | mStackSupervisor.resumeFocusedStackTopActivityLocked(); |
Craig Mautner | ee2e45a | 2014-06-27 12:10:03 -0700 | [diff] [blame] | 4135 | } |
| 4136 | |
Jose Lima | 4b6c669 | 2014-08-12 17:41:12 -0700 | [diff] [blame] | 4137 | boolean hasVisibleBehindActivity() { |
| 4138 | return isAttached() && mActivityContainer.mActivityDisplay.hasVisibleBehindActivity(); |
Craig Mautner | ee2e45a | 2014-06-27 12:10:03 -0700 | [diff] [blame] | 4139 | } |
| 4140 | |
Jose Lima | 4b6c669 | 2014-08-12 17:41:12 -0700 | [diff] [blame] | 4141 | void setVisibleBehindActivity(ActivityRecord r) { |
Craig Mautner | ee2e45a | 2014-06-27 12:10:03 -0700 | [diff] [blame] | 4142 | if (isAttached()) { |
Jose Lima | 4b6c669 | 2014-08-12 17:41:12 -0700 | [diff] [blame] | 4143 | mActivityContainer.mActivityDisplay.setVisibleBehindActivity(r); |
Craig Mautner | ee2e45a | 2014-06-27 12:10:03 -0700 | [diff] [blame] | 4144 | } |
| 4145 | } |
| 4146 | |
Jose Lima | 4b6c669 | 2014-08-12 17:41:12 -0700 | [diff] [blame] | 4147 | ActivityRecord getVisibleBehindActivity() { |
| 4148 | return isAttached() ? mActivityContainer.mActivityDisplay.mVisibleBehindActivity : null; |
Craig Mautner | ee2e45a | 2014-06-27 12:10:03 -0700 | [diff] [blame] | 4149 | } |
| 4150 | |
Craig Mautner | 05d6272ba | 2013-02-11 09:39:27 -0800 | [diff] [blame] | 4151 | private void removeHistoryRecordsForAppLocked(ArrayList<ActivityRecord> list, |
| 4152 | ProcessRecord app, String listName) { |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 4153 | int i = list.size(); |
Wale Ogunwale | e23149f | 2015-03-06 15:39:44 -0800 | [diff] [blame] | 4154 | if (DEBUG_CLEANUP) Slog.v(TAG_CLEANUP, |
| 4155 | "Removing app " + app + " from list " + listName + " with " + i + " entries"); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 4156 | while (i > 0) { |
| 4157 | i--; |
Craig Mautner | 05d6272ba | 2013-02-11 09:39:27 -0800 | [diff] [blame] | 4158 | ActivityRecord r = list.get(i); |
Wale Ogunwale | e23149f | 2015-03-06 15:39:44 -0800 | [diff] [blame] | 4159 | if (DEBUG_CLEANUP) Slog.v(TAG_CLEANUP, "Record #" + i + " " + r); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 4160 | if (r.app == app) { |
Wale Ogunwale | e23149f | 2015-03-06 15:39:44 -0800 | [diff] [blame] | 4161 | if (DEBUG_CLEANUP) Slog.v(TAG_CLEANUP, "---> REMOVING this entry!"); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 4162 | list.remove(i); |
Dianne Hackborn | 42e620c | 2012-06-24 13:20:51 -0700 | [diff] [blame] | 4163 | removeTimeoutsForActivityLocked(r); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 4164 | } |
| 4165 | } |
| 4166 | } |
| 4167 | |
Dianne Hackborn | cc5a055 | 2012-10-01 16:32:39 -0700 | [diff] [blame] | 4168 | boolean removeHistoryRecordsForAppLocked(ProcessRecord app) { |
| 4169 | removeHistoryRecordsForAppLocked(mLRUActivities, app, "mLRUActivities"); |
Craig Mautner | de4ef02 | 2013-04-07 19:01:33 -0700 | [diff] [blame] | 4170 | removeHistoryRecordsForAppLocked(mStackSupervisor.mStoppingActivities, app, |
| 4171 | "mStoppingActivities"); |
Craig Mautner | 0eea92c | 2013-05-16 13:35:39 -0700 | [diff] [blame] | 4172 | removeHistoryRecordsForAppLocked(mStackSupervisor.mGoingToSleepActivities, app, |
| 4173 | "mGoingToSleepActivities"); |
Craig Mautner | de4ef02 | 2013-04-07 19:01:33 -0700 | [diff] [blame] | 4174 | removeHistoryRecordsForAppLocked(mStackSupervisor.mWaitingVisibleActivities, app, |
Dianne Hackborn | cc5a055 | 2012-10-01 16:32:39 -0700 | [diff] [blame] | 4175 | "mWaitingVisibleActivities"); |
Craig Mautner | f333327 | 2013-04-22 10:55:53 -0700 | [diff] [blame] | 4176 | removeHistoryRecordsForAppLocked(mStackSupervisor.mFinishingActivities, app, |
| 4177 | "mFinishingActivities"); |
Dianne Hackborn | cc5a055 | 2012-10-01 16:32:39 -0700 | [diff] [blame] | 4178 | |
| 4179 | boolean hasVisibleActivities = false; |
| 4180 | |
| 4181 | // Clean out the history list. |
Craig Mautner | 0247fc8 | 2013-02-28 14:32:06 -0800 | [diff] [blame] | 4182 | int i = numActivities(); |
Wale Ogunwale | e23149f | 2015-03-06 15:39:44 -0800 | [diff] [blame] | 4183 | if (DEBUG_CLEANUP) Slog.v(TAG_CLEANUP, |
| 4184 | "Removing app " + app + " from history with " + i + " entries"); |
Craig Mautner | 0247fc8 | 2013-02-28 14:32:06 -0800 | [diff] [blame] | 4185 | for (int taskNdx = mTaskHistory.size() - 1; taskNdx >= 0; --taskNdx) { |
| 4186 | final ArrayList<ActivityRecord> activities = mTaskHistory.get(taskNdx).mActivities; |
| 4187 | for (int activityNdx = activities.size() - 1; activityNdx >= 0; --activityNdx) { |
| 4188 | final ActivityRecord r = activities.get(activityNdx); |
| 4189 | --i; |
Wale Ogunwale | e23149f | 2015-03-06 15:39:44 -0800 | [diff] [blame] | 4190 | if (DEBUG_CLEANUP) Slog.v(TAG_CLEANUP, |
| 4191 | "Record #" + i + " " + r + ": app=" + r.app); |
Craig Mautner | 0247fc8 | 2013-02-28 14:32:06 -0800 | [diff] [blame] | 4192 | if (r.app == app) { |
riddle_hsu | 558e849 | 2015-04-02 16:43:13 +0800 | [diff] [blame] | 4193 | if (r.visible) { |
| 4194 | hasVisibleActivities = true; |
| 4195 | } |
Craig Mautner | acebdc8 | 2015-02-24 10:53:03 -0800 | [diff] [blame] | 4196 | final boolean remove; |
Craig Mautner | 0247fc8 | 2013-02-28 14:32:06 -0800 | [diff] [blame] | 4197 | if ((!r.haveState && !r.stateNotNeeded) || r.finishing) { |
| 4198 | // Don't currently have state for the activity, or |
| 4199 | // it is finishing -- always remove it. |
| 4200 | remove = true; |
Chong Zhang | 112eb8c | 2015-11-02 11:17:00 -0800 | [diff] [blame] | 4201 | } else if (!r.visible && r.launchCount > 2 && |
| 4202 | r.lastLaunchTime > (SystemClock.uptimeMillis() - 60000)) { |
Craig Mautner | 0247fc8 | 2013-02-28 14:32:06 -0800 | [diff] [blame] | 4203 | // We have launched this activity too many times since it was |
| 4204 | // able to run, so give up and remove it. |
Chong Zhang | 112eb8c | 2015-11-02 11:17:00 -0800 | [diff] [blame] | 4205 | // (Note if the activity is visible, we don't remove the record. |
| 4206 | // We leave the dead window on the screen but the process will |
| 4207 | // not be restarted unless user explicitly tap on it.) |
Craig Mautner | 0247fc8 | 2013-02-28 14:32:06 -0800 | [diff] [blame] | 4208 | remove = true; |
| 4209 | } else { |
| 4210 | // The process may be gone, but the activity lives on! |
| 4211 | remove = false; |
Dianne Hackborn | cc5a055 | 2012-10-01 16:32:39 -0700 | [diff] [blame] | 4212 | } |
Craig Mautner | 0247fc8 | 2013-02-28 14:32:06 -0800 | [diff] [blame] | 4213 | if (remove) { |
Wale Ogunwale | 0fc365c | 2015-05-25 19:35:42 -0700 | [diff] [blame] | 4214 | if (DEBUG_ADD_REMOVE || DEBUG_CLEANUP) Slog.i(TAG_ADD_REMOVE, |
| 4215 | "Removing activity " + r + " from stack at " + i |
| 4216 | + ": haveState=" + r.haveState |
| 4217 | + " stateNotNeeded=" + r.stateNotNeeded |
| 4218 | + " finishing=" + r.finishing |
| 4219 | + " state=" + r.state + " callers=" + Debug.getCallers(5)); |
Craig Mautner | 0247fc8 | 2013-02-28 14:32:06 -0800 | [diff] [blame] | 4220 | if (!r.finishing) { |
| 4221 | Slog.w(TAG, "Force removing " + r + ": app died, no saved state"); |
| 4222 | EventLog.writeEvent(EventLogTags.AM_FINISH_ACTIVITY, |
| 4223 | r.userId, System.identityHashCode(r), |
| 4224 | r.task.taskId, r.shortComponentName, |
| 4225 | "proc died without state saved"); |
Jeff Sharkey | 5782da7 | 2013-04-25 14:32:30 -0700 | [diff] [blame] | 4226 | if (r.state == ActivityState.RESUMED) { |
| 4227 | mService.updateUsageStats(r, false); |
| 4228 | } |
Craig Mautner | 0247fc8 | 2013-02-28 14:32:06 -0800 | [diff] [blame] | 4229 | } |
Craig Mautner | 0247fc8 | 2013-02-28 14:32:06 -0800 | [diff] [blame] | 4230 | } else { |
| 4231 | // We have the current state for this activity, so |
| 4232 | // it can be restarted later when needed. |
Wale Ogunwale | 0fc365c | 2015-05-25 19:35:42 -0700 | [diff] [blame] | 4233 | if (DEBUG_ALL) Slog.v(TAG, "Keeping entry, setting app to null"); |
| 4234 | if (DEBUG_APP) Slog.v(TAG_APP, |
| 4235 | "Clearing app during removeHistory for activity " + r); |
Craig Mautner | 0247fc8 | 2013-02-28 14:32:06 -0800 | [diff] [blame] | 4236 | r.app = null; |
Chong Zhang | 112eb8c | 2015-11-02 11:17:00 -0800 | [diff] [blame] | 4237 | // Set nowVisible to previous visible state. If the app was visible while |
| 4238 | // it died, we leave the dead window on screen so it's basically visible. |
| 4239 | // This is needed when user later tap on the dead window, we need to stop |
| 4240 | // other apps when user transfers focus to the restarted activity. |
| 4241 | r.nowVisible = r.visible; |
Craig Mautner | 0247fc8 | 2013-02-28 14:32:06 -0800 | [diff] [blame] | 4242 | if (!r.haveState) { |
Wale Ogunwale | 0fc365c | 2015-05-25 19:35:42 -0700 | [diff] [blame] | 4243 | if (DEBUG_SAVED_STATE) Slog.i(TAG_SAVED_STATE, |
Craig Mautner | 0247fc8 | 2013-02-28 14:32:06 -0800 | [diff] [blame] | 4244 | "App died, clearing saved state of " + r); |
| 4245 | r.icicle = null; |
| 4246 | } |
Dianne Hackborn | cc5a055 | 2012-10-01 16:32:39 -0700 | [diff] [blame] | 4247 | } |
Craig Mautner | d232895 | 2013-03-05 12:46:26 -0800 | [diff] [blame] | 4248 | cleanUpActivityLocked(r, true, true); |
Craig Mautner | acebdc8 | 2015-02-24 10:53:03 -0800 | [diff] [blame] | 4249 | if (remove) { |
Chong Zhang | bffd889 | 2016-08-08 11:16:06 -0700 | [diff] [blame] | 4250 | removeActivityFromHistoryLocked(r, "appDied"); |
Craig Mautner | acebdc8 | 2015-02-24 10:53:03 -0800 | [diff] [blame] | 4251 | } |
Craig Mautner | 0247fc8 | 2013-02-28 14:32:06 -0800 | [diff] [blame] | 4252 | } |
Dianne Hackborn | cc5a055 | 2012-10-01 16:32:39 -0700 | [diff] [blame] | 4253 | } |
| 4254 | } |
| 4255 | |
| 4256 | return hasVisibleActivities; |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 4257 | } |
Craig Mautner | 0247fc8 | 2013-02-28 14:32:06 -0800 | [diff] [blame] | 4258 | |
Chong Zhang | 280d332 | 2015-11-03 17:27:26 -0800 | [diff] [blame] | 4259 | final void updateTransitLocked(int transit, ActivityOptions options) { |
Dianne Hackborn | 7f58b95 | 2012-04-18 12:59:29 -0700 | [diff] [blame] | 4260 | if (options != null) { |
Filip Gruszczynski | 3e85ba2 | 2015-10-05 22:48:30 -0700 | [diff] [blame] | 4261 | ActivityRecord r = topRunningActivityLocked(); |
Dianne Hackborn | 7f58b95 | 2012-04-18 12:59:29 -0700 | [diff] [blame] | 4262 | if (r != null && r.state != ActivityState.RESUMED) { |
| 4263 | r.updateOptionsLocked(options); |
| 4264 | } else { |
| 4265 | ActivityOptions.abort(options); |
| 4266 | } |
| 4267 | } |
Craig Mautner | ce5f3cb | 2013-04-22 08:58:54 -0700 | [diff] [blame] | 4268 | mWindowManager.prepareAppTransition(transit, false); |
Dianne Hackborn | 7f58b95 | 2012-04-18 12:59:29 -0700 | [diff] [blame] | 4269 | } |
Dianne Hackborn | 621e17d | 2010-11-22 15:59:56 -0800 | [diff] [blame] | 4270 | |
Craig Mautner | 21d24a2 | 2014-04-23 11:45:37 -0700 | [diff] [blame] | 4271 | void updateTaskMovement(TaskRecord task, boolean toFront) { |
| 4272 | if (task.isPersistable) { |
| 4273 | task.mLastTimeMoved = System.currentTimeMillis(); |
| 4274 | // Sign is used to keep tasks sorted when persisted. Tasks sent to the bottom most |
| 4275 | // recently will be most negative, tasks sent to the bottom before that will be less |
| 4276 | // negative. Similarly for recent tasks moved to the top which will be most positive. |
| 4277 | if (!toFront) { |
| 4278 | task.mLastTimeMoved *= -1; |
| 4279 | } |
| 4280 | } |
Chong Zhang | fdcc4d4 | 2015-10-14 16:50:12 -0700 | [diff] [blame] | 4281 | mStackSupervisor.invalidateTaskLayers(); |
Craig Mautner | 21d24a2 | 2014-04-23 11:45:37 -0700 | [diff] [blame] | 4282 | } |
| 4283 | |
Craig Mautner | 84984fa | 2014-06-19 11:19:20 -0700 | [diff] [blame] | 4284 | void moveHomeStackTaskToTop(int homeStackTaskType) { |
Craig Mautner | a82aa09 | 2013-09-13 15:34:08 -0700 | [diff] [blame] | 4285 | final int top = mTaskHistory.size() - 1; |
| 4286 | for (int taskNdx = top; taskNdx >= 0; --taskNdx) { |
| 4287 | final TaskRecord task = mTaskHistory.get(taskNdx); |
Craig Mautner | 84984fa | 2014-06-19 11:19:20 -0700 | [diff] [blame] | 4288 | if (task.taskType == homeStackTaskType) { |
Wale Ogunwale | ee006da | 2015-03-30 14:49:25 -0700 | [diff] [blame] | 4289 | if (DEBUG_TASKS || DEBUG_STACK) Slog.d(TAG_STACK, |
| 4290 | "moveHomeStackTaskToTop: moving " + task); |
Craig Mautner | a82aa09 | 2013-09-13 15:34:08 -0700 | [diff] [blame] | 4291 | mTaskHistory.remove(taskNdx); |
| 4292 | mTaskHistory.add(top, task); |
Craig Mautner | 21d24a2 | 2014-04-23 11:45:37 -0700 | [diff] [blame] | 4293 | updateTaskMovement(task, true); |
Craig Mautner | a82aa09 | 2013-09-13 15:34:08 -0700 | [diff] [blame] | 4294 | return; |
| 4295 | } |
| 4296 | } |
| 4297 | } |
| 4298 | |
Chong Zhang | 280d332 | 2015-11-03 17:27:26 -0800 | [diff] [blame] | 4299 | final void moveTaskToFrontLocked(TaskRecord tr, boolean noAnimation, ActivityOptions options, |
Dianne Hackborn | b5a380d | 2015-05-20 18:18:46 -0700 | [diff] [blame] | 4300 | AppTimeTracker timeTracker, String reason) { |
Wale Ogunwale | ee006da | 2015-03-30 14:49:25 -0700 | [diff] [blame] | 4301 | if (DEBUG_SWITCH) Slog.v(TAG_SWITCH, "moveTaskToFront: " + tr); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 4302 | |
Craig Mautner | 11bf9a5 | 2013-02-19 14:08:51 -0800 | [diff] [blame] | 4303 | final int numTasks = mTaskHistory.size(); |
| 4304 | final int index = mTaskHistory.indexOf(tr); |
Craig Mautner | 86d67a4 | 2013-05-14 10:34:38 -0700 | [diff] [blame] | 4305 | if (numTasks == 0 || index < 0) { |
Craig Mautner | 11bf9a5 | 2013-02-19 14:08:51 -0800 | [diff] [blame] | 4306 | // nothing to do! |
Craig Mautner | 8f5f7e9 | 2015-01-26 18:03:13 -0800 | [diff] [blame] | 4307 | if (noAnimation) { |
Craig Mautner | 11bf9a5 | 2013-02-19 14:08:51 -0800 | [diff] [blame] | 4308 | ActivityOptions.abort(options); |
| 4309 | } else { |
Jorim Jaggi | af80db4 | 2016-04-07 19:19:15 -0700 | [diff] [blame] | 4310 | updateTransitLocked(TRANSIT_TASK_TO_FRONT, options); |
Craig Mautner | 11bf9a5 | 2013-02-19 14:08:51 -0800 | [diff] [blame] | 4311 | } |
| 4312 | return; |
| 4313 | } |
| 4314 | |
Dianne Hackborn | b5a380d | 2015-05-20 18:18:46 -0700 | [diff] [blame] | 4315 | if (timeTracker != null) { |
| 4316 | // The caller wants a time tracker associated with this task. |
| 4317 | for (int i = tr.mActivities.size() - 1; i >= 0; i--) { |
| 4318 | tr.mActivities.get(i).appTimeTracker = timeTracker; |
| 4319 | } |
| 4320 | } |
| 4321 | |
Craig Mautner | 11bf9a5 | 2013-02-19 14:08:51 -0800 | [diff] [blame] | 4322 | // Shift all activities with this task up to the top |
| 4323 | // of the stack, keeping them in the same internal order. |
Wale Ogunwale | 3fcb4a8 | 2015-04-06 14:00:13 -0700 | [diff] [blame] | 4324 | insertTaskAtTop(tr, null); |
Wale Ogunwale | d80c263 | 2015-03-13 10:26:26 -0700 | [diff] [blame] | 4325 | |
Chong Zhang | 45c25ce | 2015-08-10 22:18:26 -0700 | [diff] [blame] | 4326 | // Don't refocus if invisible to current user |
| 4327 | ActivityRecord top = tr.getTopActivity(); |
Chong Zhang | 8776197 | 2016-08-22 13:53:24 -0700 | [diff] [blame] | 4328 | if (top == null || !top.okToShowLocked()) { |
Chong Zhang | 45c25ce | 2015-08-10 22:18:26 -0700 | [diff] [blame] | 4329 | addRecentActivityLocked(top); |
| 4330 | ActivityOptions.abort(options); |
| 4331 | return; |
| 4332 | } |
| 4333 | |
Wale Ogunwale | d80c263 | 2015-03-13 10:26:26 -0700 | [diff] [blame] | 4334 | // Set focus to the top running activity of this stack. |
Filip Gruszczynski | 3e85ba2 | 2015-10-05 22:48:30 -0700 | [diff] [blame] | 4335 | ActivityRecord r = topRunningActivityLocked(); |
Chong Zhang | 6cda19c | 2016-06-14 19:07:56 -0700 | [diff] [blame] | 4336 | mStackSupervisor.moveFocusableActivityStackToFrontLocked(r, reason); |
Craig Mautner | 11bf9a5 | 2013-02-19 14:08:51 -0800 | [diff] [blame] | 4337 | |
Wale Ogunwale | ee006da | 2015-03-30 14:49:25 -0700 | [diff] [blame] | 4338 | 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] | 4339 | if (noAnimation) { |
Jorim Jaggi | af80db4 | 2016-04-07 19:19:15 -0700 | [diff] [blame] | 4340 | mWindowManager.prepareAppTransition(TRANSIT_NONE, false); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 4341 | if (r != null) { |
| 4342 | mNoAnimActivities.add(r); |
| 4343 | } |
Dianne Hackborn | 8078d8c | 2012-03-20 11:11:26 -0700 | [diff] [blame] | 4344 | ActivityOptions.abort(options); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 4345 | } else { |
Jorim Jaggi | af80db4 | 2016-04-07 19:19:15 -0700 | [diff] [blame] | 4346 | updateTransitLocked(TRANSIT_TASK_TO_FRONT, options); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 4347 | } |
Craig Mautner | 30e2d72 | 2013-02-12 11:30:16 -0800 | [diff] [blame] | 4348 | |
Wale Ogunwale | d046a01 | 2015-12-24 13:05:59 -0800 | [diff] [blame] | 4349 | mStackSupervisor.resumeFocusedStackTopActivityLocked(); |
Craig Mautner | 5854780 | 2013-03-05 08:23:53 -0800 | [diff] [blame] | 4350 | EventLog.writeEvent(EventLogTags.AM_TASK_TO_FRONT, tr.userId, tr.taskId); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 4351 | } |
| 4352 | |
| 4353 | /** |
Craig Mautner | ce5f3cb | 2013-04-22 08:58:54 -0700 | [diff] [blame] | 4354 | * Worker method for rearranging history stack. Implements the function of moving all |
| 4355 | * 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] | 4356 | * bottom of the stack. |
Craig Mautner | ce5f3cb | 2013-04-22 08:58:54 -0700 | [diff] [blame] | 4357 | * |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 4358 | * If a watcher is installed, the action is preflighted and the watcher has an opportunity |
| 4359 | * to premeptively cancel the move. |
Craig Mautner | ce5f3cb | 2013-04-22 08:58:54 -0700 | [diff] [blame] | 4360 | * |
Craig Mautner | ae7ecab | 2013-09-18 11:48:14 -0700 | [diff] [blame] | 4361 | * @param taskId The taskId to collect and move to the bottom. |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 4362 | * @return Returns true if the move completed, false if not. |
| 4363 | */ |
Craig Mautner | 299f960 | 2015-01-26 09:47:33 -0800 | [diff] [blame] | 4364 | final boolean moveTaskToBackLocked(int taskId) { |
Craig Mautner | aea74a5 | 2014-03-08 14:23:10 -0800 | [diff] [blame] | 4365 | final TaskRecord tr = taskForIdLocked(taskId); |
| 4366 | if (tr == null) { |
| 4367 | Slog.i(TAG, "moveTaskToBack: bad taskId=" + taskId); |
| 4368 | return false; |
| 4369 | } |
| 4370 | |
| 4371 | Slog.i(TAG, "moveTaskToBack: " + tr); |
Craig Mautner | 15df08a | 2015-04-01 12:17:18 -0700 | [diff] [blame] | 4372 | mStackSupervisor.removeLockedTaskLocked(tr); |
Craig Mautner | b44de0d | 2013-02-21 20:00:58 -0800 | [diff] [blame] | 4373 | |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 4374 | // If we have a watcher, preflight the move before committing to it. First check |
| 4375 | // for *other* available tasks, but if none are available, then try again allowing the |
| 4376 | // current task to be selected. |
Craig Mautner | de4ef02 | 2013-04-07 19:01:33 -0700 | [diff] [blame] | 4377 | if (mStackSupervisor.isFrontStack(this) && mService.mController != null) { |
Craig Mautner | ae7ecab | 2013-09-18 11:48:14 -0700 | [diff] [blame] | 4378 | ActivityRecord next = topRunningActivityLocked(null, taskId); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 4379 | if (next == null) { |
| 4380 | next = topRunningActivityLocked(null, 0); |
| 4381 | } |
| 4382 | if (next != null) { |
| 4383 | // ask watcher if this is allowed |
| 4384 | boolean moveOK = true; |
| 4385 | try { |
| 4386 | moveOK = mService.mController.activityResuming(next.packageName); |
| 4387 | } catch (RemoteException e) { |
| 4388 | mService.mController = null; |
Kenny Root | add5821 | 2013-05-07 09:47:34 -0700 | [diff] [blame] | 4389 | Watchdog.getInstance().setActivityController(null); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 4390 | } |
| 4391 | if (!moveOK) { |
| 4392 | return false; |
| 4393 | } |
| 4394 | } |
| 4395 | } |
| 4396 | |
Wale Ogunwale | ee006da | 2015-03-30 14:49:25 -0700 | [diff] [blame] | 4397 | 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] | 4398 | |
Wale Ogunwale | 285ccef | 2015-12-11 14:56:37 -0800 | [diff] [blame] | 4399 | if (mStackId == HOME_STACK_ID && topTask().isHomeTask()) { |
Jiaquan He | e13e964 | 2016-06-15 15:16:13 -0700 | [diff] [blame] | 4400 | if (topTask().isOnTopLauncher()) { |
| 4401 | // An on-top launcher doesn't affect the visibility of activities on other stacks |
| 4402 | // behind it. So if we're moving an on-top launcher to the back, we want to move the |
| 4403 | // focus to the next focusable stack and resume an activity there. |
| 4404 | // Besides, when the docked stack is visible, we should also move the home stack to |
| 4405 | // the back to avoid the recents pops up on top of a fullscreen or freeform |
| 4406 | // activity. |
| 4407 | |
| 4408 | // Move the home stack to back. |
| 4409 | moveToBack(topTask()); |
| 4410 | |
| 4411 | // Resume an activity in the next focusable stack. |
| 4412 | adjustFocusToNextFocusableStackLocked(APPLICATION_ACTIVITY_TYPE, "moveTaskToBack"); |
| 4413 | mStackSupervisor.resumeFocusedStackTopActivityLocked(); |
| 4414 | return true; |
| 4415 | } |
| 4416 | |
Wale Ogunwale | 285ccef | 2015-12-11 14:56:37 -0800 | [diff] [blame] | 4417 | // For the case where we are moving the home task back and there is an activity visible |
| 4418 | // behind it on the fullscreen stack, we want to move the focus to the visible behind |
| 4419 | // activity to maintain order with what the user is seeing. |
| 4420 | final ActivityStack fullscreenStack = |
| 4421 | mStackSupervisor.getStack(FULLSCREEN_WORKSPACE_STACK_ID); |
| 4422 | if (fullscreenStack != null && fullscreenStack.hasVisibleBehindActivity()) { |
| 4423 | final ActivityRecord visibleBehind = fullscreenStack.getVisibleBehindActivity(); |
Chong Zhang | 6cda19c | 2016-06-14 19:07:56 -0700 | [diff] [blame] | 4424 | mStackSupervisor.moveFocusableActivityStackToFrontLocked(visibleBehind, "moveTaskToBack"); |
Wale Ogunwale | d046a01 | 2015-12-24 13:05:59 -0800 | [diff] [blame] | 4425 | mStackSupervisor.resumeFocusedStackTopActivityLocked(); |
Wale Ogunwale | 285ccef | 2015-12-11 14:56:37 -0800 | [diff] [blame] | 4426 | return true; |
| 4427 | } |
| 4428 | } |
| 4429 | |
riddle_hsu | c215a4f | 2014-12-27 12:10:45 +0800 | [diff] [blame] | 4430 | boolean prevIsHome = false; |
Wale Ogunwale | 4270924 | 2015-08-11 13:54:42 -0700 | [diff] [blame] | 4431 | |
| 4432 | // If true, we should resume the home activity next if the task we are moving to the |
| 4433 | // back is over the home stack. We force to false if the task we are moving to back |
| 4434 | // is the home task and we don't want it resumed after moving to the back. |
| 4435 | final boolean canGoHome = !tr.isHomeTask() && tr.isOverHomeStack(); |
| 4436 | if (canGoHome) { |
riddle_hsu | c215a4f | 2014-12-27 12:10:45 +0800 | [diff] [blame] | 4437 | final TaskRecord nextTask = getNextTask(tr); |
| 4438 | if (nextTask != null) { |
| 4439 | nextTask.setTaskToReturnTo(tr.getTaskToReturnTo()); |
| 4440 | } else { |
| 4441 | prevIsHome = true; |
| 4442 | } |
| 4443 | } |
Craig Mautner | 11bf9a5 | 2013-02-19 14:08:51 -0800 | [diff] [blame] | 4444 | mTaskHistory.remove(tr); |
| 4445 | mTaskHistory.add(0, tr); |
Craig Mautner | 21d24a2 | 2014-04-23 11:45:37 -0700 | [diff] [blame] | 4446 | updateTaskMovement(tr, false); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 4447 | |
Craig Mautner | c8143c6 | 2013-09-03 12:15:57 -0700 | [diff] [blame] | 4448 | // There is an assumption that moving a task to the back moves it behind the home activity. |
| 4449 | // 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] | 4450 | int numTasks = mTaskHistory.size(); |
Craig Mautner | ae7ecab | 2013-09-18 11:48:14 -0700 | [diff] [blame] | 4451 | for (int taskNdx = numTasks - 1; taskNdx >= 1; --taskNdx) { |
| 4452 | final TaskRecord task = mTaskHistory.get(taskNdx); |
Craig Mautner | 84984fa | 2014-06-19 11:19:20 -0700 | [diff] [blame] | 4453 | if (task.isOverHomeStack()) { |
Craig Mautner | c8143c6 | 2013-09-03 12:15:57 -0700 | [diff] [blame] | 4454 | break; |
| 4455 | } |
Craig Mautner | ae7ecab | 2013-09-18 11:48:14 -0700 | [diff] [blame] | 4456 | if (taskNdx == 1) { |
| 4457 | // Set the last task before tr to go to home. |
Craig Mautner | 84984fa | 2014-06-19 11:19:20 -0700 | [diff] [blame] | 4458 | task.setTaskToReturnTo(HOME_ACTIVITY_TYPE); |
Craig Mautner | ae7ecab | 2013-09-18 11:48:14 -0700 | [diff] [blame] | 4459 | } |
Craig Mautner | c8143c6 | 2013-09-03 12:15:57 -0700 | [diff] [blame] | 4460 | } |
| 4461 | |
Jorim Jaggi | af80db4 | 2016-04-07 19:19:15 -0700 | [diff] [blame] | 4462 | mWindowManager.prepareAppTransition(TRANSIT_TASK_TO_BACK, false); |
Craig Mautner | ae7ecab | 2013-09-18 11:48:14 -0700 | [diff] [blame] | 4463 | mWindowManager.moveTaskToBottom(taskId); |
Craig Mautner | b44de0d | 2013-02-21 20:00:58 -0800 | [diff] [blame] | 4464 | |
Craig Mautner | ae7ecab | 2013-09-18 11:48:14 -0700 | [diff] [blame] | 4465 | final TaskRecord task = mResumedActivity != null ? mResumedActivity.task : null; |
Wale Ogunwale | 4270924 | 2015-08-11 13:54:42 -0700 | [diff] [blame] | 4466 | if (prevIsHome || (task == tr && canGoHome) || (numTasks <= 1 && isOnHomeDisplay())) { |
Dianne Hackborn | 7622a0f | 2014-09-30 14:31:42 -0700 | [diff] [blame] | 4467 | if (!mService.mBooting && !mService.mBooted) { |
| 4468 | // Not ready yet! |
| 4469 | return false; |
| 4470 | } |
Craig Mautner | 84984fa | 2014-06-19 11:19:20 -0700 | [diff] [blame] | 4471 | final int taskToReturnTo = tr.getTaskToReturnTo(); |
| 4472 | tr.setTaskToReturnTo(APPLICATION_ACTIVITY_TYPE); |
Craig Mautner | 299f960 | 2015-01-26 09:47:33 -0800 | [diff] [blame] | 4473 | return mStackSupervisor.resumeHomeStackTask(taskToReturnTo, null, "moveTaskToBack"); |
Craig Mautner | de4ef02 | 2013-04-07 19:01:33 -0700 | [diff] [blame] | 4474 | } |
| 4475 | |
Wale Ogunwale | d046a01 | 2015-12-24 13:05:59 -0800 | [diff] [blame] | 4476 | mStackSupervisor.resumeFocusedStackTopActivityLocked(); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 4477 | return true; |
| 4478 | } |
Dianne Hackborn | 15491c6 | 2012-09-19 10:59:14 -0700 | [diff] [blame] | 4479 | |
Craig Mautner | 8849a5e | 2013-04-02 16:41:03 -0700 | [diff] [blame] | 4480 | static final void logStartActivity(int tag, ActivityRecord r, |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 4481 | TaskRecord task) { |
Santos Cordon | 73ff7d8 | 2013-03-06 17:24:11 -0800 | [diff] [blame] | 4482 | final Uri data = r.intent.getData(); |
| 4483 | final String strData = data != null ? data.toSafeString() : null; |
| 4484 | |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 4485 | EventLog.writeEvent(tag, |
Dianne Hackborn | b12e135 | 2012-09-26 11:39:20 -0700 | [diff] [blame] | 4486 | r.userId, System.identityHashCode(r), task.taskId, |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 4487 | r.shortComponentName, r.intent.getAction(), |
Santos Cordon | 73ff7d8 | 2013-03-06 17:24:11 -0800 | [diff] [blame] | 4488 | r.intent.getType(), strData, r.intent.getFlags()); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 4489 | } |
| 4490 | |
| 4491 | /** |
Wale Ogunwale | db0fa12 | 2016-05-16 15:12:03 -0700 | [diff] [blame] | 4492 | * Ensures all visible activities at or below the input activity have the right configuration. |
| 4493 | */ |
| 4494 | void ensureVisibleActivitiesConfigurationLocked(ActivityRecord start, boolean preserveWindow) { |
| 4495 | if (start == null || !start.visible) { |
| 4496 | return; |
| 4497 | } |
| 4498 | |
| 4499 | final TaskRecord startTask = start.task; |
| 4500 | boolean behindFullscreen = false; |
| 4501 | boolean updatedConfig = false; |
| 4502 | |
| 4503 | for (int taskIndex = mTaskHistory.indexOf(startTask); taskIndex >= 0; --taskIndex) { |
| 4504 | final TaskRecord task = mTaskHistory.get(taskIndex); |
| 4505 | final ArrayList<ActivityRecord> activities = task.mActivities; |
| 4506 | int activityIndex = |
| 4507 | (start.task == task) ? activities.indexOf(start) : activities.size() - 1; |
| 4508 | for (; activityIndex >= 0; --activityIndex) { |
| 4509 | final ActivityRecord r = activities.get(activityIndex); |
| 4510 | updatedConfig |= ensureActivityConfigurationLocked(r, 0, preserveWindow); |
| 4511 | if (r.fullscreen) { |
| 4512 | behindFullscreen = true; |
| 4513 | break; |
| 4514 | } |
| 4515 | } |
| 4516 | if (behindFullscreen) { |
| 4517 | break; |
| 4518 | } |
| 4519 | } |
| 4520 | if (updatedConfig) { |
Wale Ogunwale | 089586f | 2016-06-20 14:16:22 -0700 | [diff] [blame] | 4521 | // 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] | 4522 | // any activity. |
| 4523 | mStackSupervisor.resumeFocusedStackTopActivityLocked(); |
| 4524 | } |
| 4525 | } |
| 4526 | |
| 4527 | /** |
| 4528 | * Make sure the given activity matches the current configuration. Returns false if the activity |
| 4529 | * had to be destroyed. Returns true if the configuration is the same, or the activity will |
| 4530 | * 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] | 4531 | * correct configuration and all other bookkeeping is handled. |
| 4532 | */ |
Wale Ogunwale | db0fa12 | 2016-05-16 15:12:03 -0700 | [diff] [blame] | 4533 | boolean ensureActivityConfigurationLocked( |
| 4534 | ActivityRecord r, int globalChanges, boolean preserveWindow) { |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 4535 | if (mConfigWillChange) { |
Wale Ogunwale | 3ab9a27 | 2015-03-16 09:55:45 -0700 | [diff] [blame] | 4536 | if (DEBUG_SWITCH || DEBUG_CONFIGURATION) Slog.v(TAG_CONFIGURATION, |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 4537 | "Skipping config check (will change): " + r); |
| 4538 | return true; |
| 4539 | } |
Craig Mautner | ce5f3cb | 2013-04-22 08:58:54 -0700 | [diff] [blame] | 4540 | |
Wale Ogunwale | 3ab9a27 | 2015-03-16 09:55:45 -0700 | [diff] [blame] | 4541 | if (DEBUG_SWITCH || DEBUG_CONFIGURATION) Slog.v(TAG_CONFIGURATION, |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 4542 | "Ensuring correct configuration: " + r); |
Craig Mautner | 9db9a0b | 2013-04-29 17:05:56 -0700 | [diff] [blame] | 4543 | |
Wale Ogunwale | f7dab1e | 2016-04-16 11:38:50 -0700 | [diff] [blame] | 4544 | // Short circuit: if the two configurations are equal (the common case), then there is |
| 4545 | // nothing to do. |
Wale Ogunwale | e4a0c57 | 2015-06-30 08:40:31 -0700 | [diff] [blame] | 4546 | final Configuration newConfig = mService.mConfiguration; |
Andrii Kulian | f12fce1 | 2016-05-27 17:30:16 -0700 | [diff] [blame] | 4547 | r.task.sanitizeOverrideConfiguration(newConfig); |
Wale Ogunwale | e4a0c57 | 2015-06-30 08:40:31 -0700 | [diff] [blame] | 4548 | final Configuration taskConfig = r.task.mOverrideConfig; |
Wale Ogunwale | f7dab1e | 2016-04-16 11:38:50 -0700 | [diff] [blame] | 4549 | if (r.configuration.equals(newConfig) |
| 4550 | && r.taskConfigOverride.equals(taskConfig) |
Wale Ogunwale | 60454db | 2015-01-23 16:05:07 -0800 | [diff] [blame] | 4551 | && !r.forceNewConfig) { |
Wale Ogunwale | 3ab9a27 | 2015-03-16 09:55:45 -0700 | [diff] [blame] | 4552 | if (DEBUG_SWITCH || DEBUG_CONFIGURATION) Slog.v(TAG_CONFIGURATION, |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 4553 | "Configuration unchanged in " + r); |
| 4554 | return true; |
| 4555 | } |
Craig Mautner | ce5f3cb | 2013-04-22 08:58:54 -0700 | [diff] [blame] | 4556 | |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 4557 | // We don't worry about activities that are finishing. |
| 4558 | if (r.finishing) { |
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 in finishing " + r); |
| 4561 | r.stopFreezingScreenLocked(false); |
| 4562 | return true; |
| 4563 | } |
Craig Mautner | ce5f3cb | 2013-04-22 08:58:54 -0700 | [diff] [blame] | 4564 | |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 4565 | // Okay we now are going to make this activity have the new config. |
| 4566 | // 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] | 4567 | final Configuration oldConfig = r.configuration; |
Wale Ogunwale | e4a0c57 | 2015-06-30 08:40:31 -0700 | [diff] [blame] | 4568 | final Configuration oldTaskOverride = r.taskConfigOverride; |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 4569 | r.configuration = newConfig; |
Wale Ogunwale | e4a0c57 | 2015-06-30 08:40:31 -0700 | [diff] [blame] | 4570 | r.taskConfigOverride = taskConfig; |
Dianne Hackborn | 58f42a5 | 2011-10-10 13:46:34 -0700 | [diff] [blame] | 4571 | |
Filip Gruszczynski | 2349332 | 2015-07-29 17:02:59 -0700 | [diff] [blame] | 4572 | int taskChanges = getTaskConfigurationChanges(r, taskConfig, oldTaskOverride); |
Wale Ogunwale | e4a0c57 | 2015-06-30 08:40:31 -0700 | [diff] [blame] | 4573 | final int changes = oldConfig.diff(newConfig) | taskChanges; |
Dianne Hackborn | 58f42a5 | 2011-10-10 13:46:34 -0700 | [diff] [blame] | 4574 | if (changes == 0 && !r.forceNewConfig) { |
Wale Ogunwale | 3ab9a27 | 2015-03-16 09:55:45 -0700 | [diff] [blame] | 4575 | if (DEBUG_SWITCH || DEBUG_CONFIGURATION) Slog.v(TAG_CONFIGURATION, |
Dianne Hackborn | 58f42a5 | 2011-10-10 13:46:34 -0700 | [diff] [blame] | 4576 | "Configuration no differences in " + r); |
Filip Gruszczynski | ca66481 | 2015-12-04 12:43:36 -0800 | [diff] [blame] | 4577 | // There are no significant differences, so we won't relaunch but should still deliver |
| 4578 | // the new configuration to the client process. |
Wale Ogunwale | f7dab1e | 2016-04-16 11:38:50 -0700 | [diff] [blame] | 4579 | r.scheduleConfigurationChanged(taskConfig, true); |
Dianne Hackborn | 58f42a5 | 2011-10-10 13:46:34 -0700 | [diff] [blame] | 4580 | return true; |
| 4581 | } |
| 4582 | |
Filip Gruszczynski | bc5a6c5 | 2015-09-22 13:13:24 -0700 | [diff] [blame] | 4583 | if (DEBUG_SWITCH || DEBUG_CONFIGURATION) Slog.v(TAG_CONFIGURATION, |
| 4584 | "Configuration changes for " + r + " ; taskChanges=" |
| 4585 | + Configuration.configurationDiffToString(taskChanges) + ", allChanges=" |
| 4586 | + Configuration.configurationDiffToString(changes)); |
| 4587 | |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 4588 | // If the activity isn't currently running, just leave the new |
| 4589 | // configuration and it will pick that up next time it starts. |
| 4590 | if (r.app == null || r.app.thread == null) { |
Wale Ogunwale | 3ab9a27 | 2015-03-16 09:55:45 -0700 | [diff] [blame] | 4591 | if (DEBUG_SWITCH || DEBUG_CONFIGURATION) Slog.v(TAG_CONFIGURATION, |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 4592 | "Configuration doesn't matter not running " + r); |
| 4593 | r.stopFreezingScreenLocked(false); |
Dianne Hackborn | e2515ee | 2011-04-27 18:52:56 -0400 | [diff] [blame] | 4594 | r.forceNewConfig = false; |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 4595 | return true; |
| 4596 | } |
Craig Mautner | ce5f3cb | 2013-04-22 08:58:54 -0700 | [diff] [blame] | 4597 | |
Dianne Hackborn | 58f42a5 | 2011-10-10 13:46:34 -0700 | [diff] [blame] | 4598 | // Figure out how to handle the changes between the configurations. |
Wale Ogunwale | 3ab9a27 | 2015-03-16 09:55:45 -0700 | [diff] [blame] | 4599 | if (DEBUG_SWITCH || DEBUG_CONFIGURATION) Slog.v(TAG_CONFIGURATION, |
| 4600 | "Checking to restart " + r.info.name + ": changed=0x" |
| 4601 | + Integer.toHexString(changes) + ", handles=0x" |
Filip Gruszczynski | ca66481 | 2015-12-04 12:43:36 -0800 | [diff] [blame] | 4602 | + Integer.toHexString(r.info.getRealConfigChanged()) + ", newConfig=" + newConfig |
| 4603 | + ", taskConfig=" + taskConfig); |
Wale Ogunwale | 3ab9a27 | 2015-03-16 09:55:45 -0700 | [diff] [blame] | 4604 | |
Dianne Hackborn | e667635 | 2011-06-01 16:51:20 -0700 | [diff] [blame] | 4605 | if ((changes&(~r.info.getRealConfigChanged())) != 0 || r.forceNewConfig) { |
Dianne Hackborn | 3c4c2b7 | 2010-10-05 18:07:54 -0700 | [diff] [blame] | 4606 | // Aha, the activity isn't handling the change, so DIE DIE DIE. |
| 4607 | r.configChangeFlags |= changes; |
| 4608 | r.startFreezingScreenLocked(r.app, globalChanges); |
Dianne Hackborn | e2515ee | 2011-04-27 18:52:56 -0400 | [diff] [blame] | 4609 | r.forceNewConfig = false; |
Wale Ogunwale | f81c1d1 | 2016-01-12 12:20:18 -0800 | [diff] [blame] | 4610 | preserveWindow &= isResizeOnlyChange(changes); |
Dianne Hackborn | 3c4c2b7 | 2010-10-05 18:07:54 -0700 | [diff] [blame] | 4611 | if (r.app == null || r.app.thread == null) { |
Wale Ogunwale | 3ab9a27 | 2015-03-16 09:55:45 -0700 | [diff] [blame] | 4612 | if (DEBUG_SWITCH || DEBUG_CONFIGURATION) Slog.v(TAG_CONFIGURATION, |
Dianne Hackborn | b61a026 | 2012-05-14 17:19:18 -0700 | [diff] [blame] | 4613 | "Config is destroying non-running " + r); |
Craig Mautner | ee2e45a | 2014-06-27 12:10:03 -0700 | [diff] [blame] | 4614 | destroyActivityLocked(r, true, "config"); |
Dianne Hackborn | 3c4c2b7 | 2010-10-05 18:07:54 -0700 | [diff] [blame] | 4615 | } else if (r.state == ActivityState.PAUSING) { |
Wale Ogunwale | f81c1d1 | 2016-01-12 12:20:18 -0800 | [diff] [blame] | 4616 | // A little annoying: we are waiting for this activity to finish pausing. Let's not |
| 4617 | // 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] | 4618 | if (DEBUG_SWITCH || DEBUG_CONFIGURATION) Slog.v(TAG_CONFIGURATION, |
Dianne Hackborn | b61a026 | 2012-05-14 17:19:18 -0700 | [diff] [blame] | 4619 | "Config is skipping already pausing " + r); |
Wale Ogunwale | f81c1d1 | 2016-01-12 12:20:18 -0800 | [diff] [blame] | 4620 | r.deferRelaunchUntilPaused = true; |
| 4621 | r.preserveWindowOnDeferredRelaunch = preserveWindow; |
Dianne Hackborn | 3c4c2b7 | 2010-10-05 18:07:54 -0700 | [diff] [blame] | 4622 | return true; |
| 4623 | } else if (r.state == ActivityState.RESUMED) { |
Wale Ogunwale | f81c1d1 | 2016-01-12 12:20:18 -0800 | [diff] [blame] | 4624 | // Try to optimize this case: the configuration is changing and we need to restart |
| 4625 | // the top, resumed activity. Instead of doing the normal handshaking, just say |
Dianne Hackborn | 3c4c2b7 | 2010-10-05 18:07:54 -0700 | [diff] [blame] | 4626 | // "restart!". |
Wale Ogunwale | 3ab9a27 | 2015-03-16 09:55:45 -0700 | [diff] [blame] | 4627 | if (DEBUG_SWITCH || DEBUG_CONFIGURATION) Slog.v(TAG_CONFIGURATION, |
Dianne Hackborn | b61a026 | 2012-05-14 17:19:18 -0700 | [diff] [blame] | 4628 | "Config is relaunching resumed " + r); |
Chong Zhang | 2b79af1 | 2016-02-10 18:47:06 -0800 | [diff] [blame] | 4629 | |
| 4630 | if (DEBUG_STATES && !r.visible) { |
| 4631 | Slog.v(TAG_STATES, "Config is relaunching resumed invisible activity " + r |
| 4632 | + " called by " + Debug.getCallers(4)); |
| 4633 | } |
| 4634 | |
Wale Ogunwale | f81c1d1 | 2016-01-12 12:20:18 -0800 | [diff] [blame] | 4635 | relaunchActivityLocked(r, r.configChangeFlags, true, preserveWindow); |
Dianne Hackborn | 3c4c2b7 | 2010-10-05 18:07:54 -0700 | [diff] [blame] | 4636 | } else { |
Wale Ogunwale | 3ab9a27 | 2015-03-16 09:55:45 -0700 | [diff] [blame] | 4637 | if (DEBUG_SWITCH || DEBUG_CONFIGURATION) Slog.v(TAG_CONFIGURATION, |
Dianne Hackborn | b61a026 | 2012-05-14 17:19:18 -0700 | [diff] [blame] | 4638 | "Config is relaunching non-resumed " + r); |
Wale Ogunwale | f81c1d1 | 2016-01-12 12:20:18 -0800 | [diff] [blame] | 4639 | relaunchActivityLocked(r, r.configChangeFlags, false, preserveWindow); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 4640 | } |
Craig Mautner | ce5f3cb | 2013-04-22 08:58:54 -0700 | [diff] [blame] | 4641 | |
Wale Ogunwale | f81c1d1 | 2016-01-12 12:20:18 -0800 | [diff] [blame] | 4642 | // 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] | 4643 | return false; |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 4644 | } |
Craig Mautner | ce5f3cb | 2013-04-22 08:58:54 -0700 | [diff] [blame] | 4645 | |
Wale Ogunwale | c2607b4 | 2015-02-07 16:16:59 -0800 | [diff] [blame] | 4646 | // 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] | 4647 | // 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] | 4648 | // changes is always sent to all processes when they happen so it can just use whatever |
| 4649 | // system level configuration it last got. |
Filip Gruszczynski | ca66481 | 2015-12-04 12:43:36 -0800 | [diff] [blame] | 4650 | r.scheduleConfigurationChanged(taskConfig, true); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 4651 | r.stopFreezingScreenLocked(false); |
Craig Mautner | ce5f3cb | 2013-04-22 08:58:54 -0700 | [diff] [blame] | 4652 | |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 4653 | return true; |
| 4654 | } |
| 4655 | |
Filip Gruszczynski | 2349332 | 2015-07-29 17:02:59 -0700 | [diff] [blame] | 4656 | private int getTaskConfigurationChanges(ActivityRecord record, Configuration taskConfig, |
| 4657 | Configuration oldTaskOverride) { |
Jorim Jaggi | a95ca8d | 2016-01-15 22:54:46 -0800 | [diff] [blame] | 4658 | |
| 4659 | // If we went from full-screen to non-full-screen, make sure to use the correct |
| 4660 | // configuration task diff, so the diff stays as small as possible. |
| 4661 | if (Configuration.EMPTY.equals(oldTaskOverride) |
| 4662 | && !Configuration.EMPTY.equals(taskConfig)) { |
| 4663 | oldTaskOverride = record.task.extractOverrideConfig(record.configuration); |
| 4664 | } |
| 4665 | |
Jorim Jaggi | 1b025a6 | 2016-02-03 19:27:49 -0800 | [diff] [blame] | 4666 | // Conversely, do the same when going the other direction. |
| 4667 | if (Configuration.EMPTY.equals(taskConfig) |
| 4668 | && !Configuration.EMPTY.equals(oldTaskOverride)) { |
| 4669 | taskConfig = record.task.extractOverrideConfig(record.configuration); |
| 4670 | } |
| 4671 | |
Filip Gruszczynski | 2349332 | 2015-07-29 17:02:59 -0700 | [diff] [blame] | 4672 | // Determine what has changed. May be nothing, if this is a config |
| 4673 | // that has come back from the app after going idle. In that case |
| 4674 | // we just want to leave the official config object now in the |
| 4675 | // activity and do nothing else. |
| 4676 | int taskChanges = oldTaskOverride.diff(taskConfig); |
| 4677 | // We don't want to use size changes if they don't cross boundaries that are important to |
| 4678 | // the app. |
Filip Gruszczynski | 3c2db1d1 | 2016-01-06 17:39:14 -0800 | [diff] [blame] | 4679 | if ((taskChanges & CONFIG_SCREEN_SIZE) != 0) { |
Filip Gruszczynski | 2349332 | 2015-07-29 17:02:59 -0700 | [diff] [blame] | 4680 | final boolean crosses = record.crossesHorizontalSizeThreshold( |
| 4681 | oldTaskOverride.screenWidthDp, taskConfig.screenWidthDp) |
| 4682 | || record.crossesVerticalSizeThreshold( |
| 4683 | oldTaskOverride.screenHeightDp, taskConfig.screenHeightDp); |
| 4684 | if (!crosses) { |
Filip Gruszczynski | 3c2db1d1 | 2016-01-06 17:39:14 -0800 | [diff] [blame] | 4685 | taskChanges &= ~CONFIG_SCREEN_SIZE; |
Filip Gruszczynski | 2349332 | 2015-07-29 17:02:59 -0700 | [diff] [blame] | 4686 | } |
| 4687 | } |
Filip Gruszczynski | 3c2db1d1 | 2016-01-06 17:39:14 -0800 | [diff] [blame] | 4688 | if ((taskChanges & CONFIG_SMALLEST_SCREEN_SIZE) != 0) { |
Filip Gruszczynski | 2349332 | 2015-07-29 17:02:59 -0700 | [diff] [blame] | 4689 | final int oldSmallest = oldTaskOverride.smallestScreenWidthDp; |
| 4690 | final int newSmallest = taskConfig.smallestScreenWidthDp; |
Filip Gruszczynski | 20aa0ae | 2015-10-30 10:08:27 -0700 | [diff] [blame] | 4691 | if (!record.crossesSmallestSizeThreshold(oldSmallest, newSmallest)) { |
Filip Gruszczynski | 3c2db1d1 | 2016-01-06 17:39:14 -0800 | [diff] [blame] | 4692 | taskChanges &= ~CONFIG_SMALLEST_SCREEN_SIZE; |
Filip Gruszczynski | 2349332 | 2015-07-29 17:02:59 -0700 | [diff] [blame] | 4693 | } |
| 4694 | } |
| 4695 | return catchConfigChangesFromUnset(taskConfig, oldTaskOverride, taskChanges); |
| 4696 | } |
| 4697 | |
| 4698 | private static int catchConfigChangesFromUnset(Configuration taskConfig, |
| 4699 | Configuration oldTaskOverride, int taskChanges) { |
| 4700 | if (taskChanges == 0) { |
| 4701 | // {@link Configuration#diff} doesn't catch changes from unset values. |
| 4702 | // Check for changes we care about. |
| 4703 | if (oldTaskOverride.orientation != taskConfig.orientation) { |
Filip Gruszczynski | 3c2db1d1 | 2016-01-06 17:39:14 -0800 | [diff] [blame] | 4704 | taskChanges |= CONFIG_ORIENTATION; |
Filip Gruszczynski | 2349332 | 2015-07-29 17:02:59 -0700 | [diff] [blame] | 4705 | } |
| 4706 | // We want to explicitly track situations where the size configuration goes from |
| 4707 | // undefined to defined. We don't care about crossing the threshold in that case, |
| 4708 | // because there is no threshold. |
| 4709 | final int oldHeight = oldTaskOverride.screenHeightDp; |
| 4710 | final int newHeight = taskConfig.screenHeightDp; |
| 4711 | final int undefinedHeight = Configuration.SCREEN_HEIGHT_DP_UNDEFINED; |
| 4712 | if ((oldHeight == undefinedHeight && newHeight != undefinedHeight) |
| 4713 | || (oldHeight != undefinedHeight && newHeight == undefinedHeight)) { |
Filip Gruszczynski | 3c2db1d1 | 2016-01-06 17:39:14 -0800 | [diff] [blame] | 4714 | taskChanges |= CONFIG_SCREEN_SIZE; |
Filip Gruszczynski | 2349332 | 2015-07-29 17:02:59 -0700 | [diff] [blame] | 4715 | } |
| 4716 | final int oldWidth = oldTaskOverride.screenWidthDp; |
| 4717 | final int newWidth = taskConfig.screenWidthDp; |
| 4718 | final int undefinedWidth = Configuration.SCREEN_WIDTH_DP_UNDEFINED; |
| 4719 | if ((oldWidth == undefinedWidth && newWidth != undefinedWidth) |
| 4720 | || (oldWidth != undefinedWidth && newWidth == undefinedWidth)) { |
Filip Gruszczynski | 3c2db1d1 | 2016-01-06 17:39:14 -0800 | [diff] [blame] | 4721 | taskChanges |= CONFIG_SCREEN_SIZE; |
Filip Gruszczynski | 2349332 | 2015-07-29 17:02:59 -0700 | [diff] [blame] | 4722 | } |
| 4723 | final int oldSmallest = oldTaskOverride.smallestScreenWidthDp; |
| 4724 | final int newSmallest = taskConfig.smallestScreenWidthDp; |
| 4725 | final int undefinedSmallest = Configuration.SMALLEST_SCREEN_WIDTH_DP_UNDEFINED; |
| 4726 | if ((oldSmallest == undefinedSmallest && newSmallest != undefinedSmallest) |
| 4727 | || (oldSmallest != undefinedSmallest && newSmallest == undefinedSmallest)) { |
Filip Gruszczynski | 3c2db1d1 | 2016-01-06 17:39:14 -0800 | [diff] [blame] | 4728 | taskChanges |= CONFIG_SMALLEST_SCREEN_SIZE; |
| 4729 | } |
| 4730 | final int oldLayout = oldTaskOverride.screenLayout; |
| 4731 | final int newLayout = taskConfig.screenLayout; |
| 4732 | if ((oldLayout == SCREENLAYOUT_UNDEFINED && newLayout != SCREENLAYOUT_UNDEFINED) |
| 4733 | || (oldLayout != SCREENLAYOUT_UNDEFINED && newLayout == SCREENLAYOUT_UNDEFINED)) { |
| 4734 | taskChanges |= CONFIG_SCREEN_LAYOUT; |
Filip Gruszczynski | 2349332 | 2015-07-29 17:02:59 -0700 | [diff] [blame] | 4735 | } |
| 4736 | } |
| 4737 | return taskChanges; |
| 4738 | } |
| 4739 | |
Filip Gruszczynski | a59ac9c | 2015-09-10 18:28:48 -0700 | [diff] [blame] | 4740 | private static boolean isResizeOnlyChange(int change) { |
Filip Gruszczynski | 3c2db1d1 | 2016-01-06 17:39:14 -0800 | [diff] [blame] | 4741 | return (change & ~(CONFIG_SCREEN_SIZE | CONFIG_SMALLEST_SCREEN_SIZE | CONFIG_ORIENTATION |
| 4742 | | CONFIG_SCREEN_LAYOUT)) == 0; |
Filip Gruszczynski | a59ac9c | 2015-09-10 18:28:48 -0700 | [diff] [blame] | 4743 | } |
| 4744 | |
Wale Ogunwale | 83301a9 | 2015-09-24 15:54:08 -0700 | [diff] [blame] | 4745 | private void relaunchActivityLocked( |
| 4746 | ActivityRecord r, int changes, boolean andResume, boolean preserveWindow) { |
| 4747 | if (mService.mSuppressResizeConfigChanges && preserveWindow) { |
Wale Ogunwale | f81c1d1 | 2016-01-12 12:20:18 -0800 | [diff] [blame] | 4748 | r.configChangeFlags = 0; |
Wale Ogunwale | 83301a9 | 2015-09-24 15:54:08 -0700 | [diff] [blame] | 4749 | return; |
| 4750 | } |
| 4751 | |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 4752 | List<ResultInfo> results = null; |
Dianne Hackborn | 85d558c | 2014-11-04 10:31:54 -0800 | [diff] [blame] | 4753 | List<ReferrerIntent> newIntents = null; |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 4754 | if (andResume) { |
| 4755 | results = r.results; |
| 4756 | newIntents = r.newIntents; |
| 4757 | } |
Wale Ogunwale | ee006da | 2015-03-30 14:49:25 -0700 | [diff] [blame] | 4758 | if (DEBUG_SWITCH) Slog.v(TAG_SWITCH, |
| 4759 | "Relaunching: " + r + " with results=" + results + " newIntents=" + newIntents |
Filip Gruszczynski | a59ac9c | 2015-09-10 18:28:48 -0700 | [diff] [blame] | 4760 | + " andResume=" + andResume + " preserveWindow=" + preserveWindow); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 4761 | EventLog.writeEvent(andResume ? EventLogTags.AM_RELAUNCH_RESUME_ACTIVITY |
Dianne Hackborn | b12e135 | 2012-09-26 11:39:20 -0700 | [diff] [blame] | 4762 | : EventLogTags.AM_RELAUNCH_ACTIVITY, r.userId, System.identityHashCode(r), |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 4763 | r.task.taskId, r.shortComponentName); |
Craig Mautner | 9db9a0b | 2013-04-29 17:05:56 -0700 | [diff] [blame] | 4764 | |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 4765 | r.startFreezingScreenLocked(r.app, 0); |
Craig Mautner | 9db9a0b | 2013-04-29 17:05:56 -0700 | [diff] [blame] | 4766 | |
Craig Mautner | 34b73df | 2014-01-12 21:11:08 -0800 | [diff] [blame] | 4767 | mStackSupervisor.removeChildActivityContainers(r); |
| 4768 | |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 4769 | try { |
Wale Ogunwale | ee006da | 2015-03-30 14:49:25 -0700 | [diff] [blame] | 4770 | if (DEBUG_SWITCH || DEBUG_STATES) Slog.i(TAG_SWITCH, |
Wale Ogunwale | 5658e4b | 2016-02-12 12:22:19 -0800 | [diff] [blame] | 4771 | "Moving to " + (andResume ? "RESUMED" : "PAUSED") + " Relaunching " + r |
| 4772 | + " callers=" + Debug.getCallers(6)); |
Dianne Hackborn | e2515ee | 2011-04-27 18:52:56 -0400 | [diff] [blame] | 4773 | r.forceNewConfig = false; |
Chong Zhang | d78ddb4 | 2016-03-02 17:01:14 -0800 | [diff] [blame] | 4774 | mStackSupervisor.activityRelaunchingLocked(r); |
Wale Ogunwale | 60454db | 2015-01-23 16:05:07 -0800 | [diff] [blame] | 4775 | r.app.thread.scheduleRelaunchActivity(r.appToken, results, newIntents, changes, |
| 4776 | !andResume, new Configuration(mService.mConfiguration), |
Filip Gruszczynski | a59ac9c | 2015-09-10 18:28:48 -0700 | [diff] [blame] | 4777 | new Configuration(r.task.mOverrideConfig), preserveWindow); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 4778 | // Note: don't need to call pauseIfSleepingLocked() here, because |
| 4779 | // the caller will only pass in 'andResume' if this activity is |
| 4780 | // currently resumed, which implies we aren't sleeping. |
| 4781 | } catch (RemoteException e) { |
Wale Ogunwale | ee006da | 2015-03-30 14:49:25 -0700 | [diff] [blame] | 4782 | if (DEBUG_SWITCH || DEBUG_STATES) Slog.i(TAG_SWITCH, "Relaunch failed", e); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 4783 | } |
| 4784 | |
| 4785 | if (andResume) { |
Chong Zhang | 2b79af1 | 2016-02-10 18:47:06 -0800 | [diff] [blame] | 4786 | if (DEBUG_STATES) { |
| 4787 | Slog.d(TAG_STATES, "Resumed after relaunch " + r); |
| 4788 | } |
Chong Zhang | d2cb311 | 2016-07-20 11:13:22 -0700 | [diff] [blame] | 4789 | r.results = null; |
| 4790 | r.newIntents = null; |
Andrii Kulian | f42cbe8 | 2016-06-22 14:49:58 -0700 | [diff] [blame] | 4791 | mService.showUnsupportedZoomDialogIfNeededLocked(r); |
| 4792 | mService.showAskCompatModeDialogLocked(r); |
Dianne Hackborn | b61a026 | 2012-05-14 17:19:18 -0700 | [diff] [blame] | 4793 | } else { |
| 4794 | mHandler.removeMessages(PAUSE_TIMEOUT_MSG, r); |
| 4795 | r.state = ActivityState.PAUSED; |
Chong Zhang | fec694e | 2016-08-09 12:57:38 -0700 | [diff] [blame] | 4796 | // if the app is relaunched when it's stopped, and we're not resuming, |
| 4797 | // put it back into stopped state. |
| 4798 | if (r.stopped) { |
| 4799 | addToStopping(r, true /* immediate */); |
| 4800 | } |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 4801 | } |
Wale Ogunwale | f81c1d1 | 2016-01-12 12:20:18 -0800 | [diff] [blame] | 4802 | |
| 4803 | r.configChangeFlags = 0; |
Chong Zhang | 225d1b6 | 2016-03-31 14:09:33 -0700 | [diff] [blame] | 4804 | r.deferRelaunchUntilPaused = false; |
| 4805 | r.preserveWindowOnDeferredRelaunch = false; |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 4806 | } |
Craig Mautner | cae015f | 2013-02-08 14:31:27 -0800 | [diff] [blame] | 4807 | |
| 4808 | boolean willActivityBeVisibleLocked(IBinder token) { |
Craig Mautner | d44711d | 2013-02-23 11:24:36 -0800 | [diff] [blame] | 4809 | for (int taskNdx = mTaskHistory.size() - 1; taskNdx >= 0; --taskNdx) { |
| 4810 | final ArrayList<ActivityRecord> activities = mTaskHistory.get(taskNdx).mActivities; |
| 4811 | for (int activityNdx = activities.size() - 1; activityNdx >= 0; --activityNdx) { |
| 4812 | final ActivityRecord r = activities.get(activityNdx); |
| 4813 | if (r.appToken == token) { |
Craig Mautner | 34b73df | 2014-01-12 21:11:08 -0800 | [diff] [blame] | 4814 | return true; |
Craig Mautner | d44711d | 2013-02-23 11:24:36 -0800 | [diff] [blame] | 4815 | } |
| 4816 | if (r.fullscreen && !r.finishing) { |
| 4817 | return false; |
| 4818 | } |
Craig Mautner | cae015f | 2013-02-08 14:31:27 -0800 | [diff] [blame] | 4819 | } |
| 4820 | } |
Wale Ogunwale | 7d70117 | 2015-03-11 15:36:30 -0700 | [diff] [blame] | 4821 | final ActivityRecord r = ActivityRecord.forTokenLocked(token); |
Craig Mautner | 34b73df | 2014-01-12 21:11:08 -0800 | [diff] [blame] | 4822 | if (r == null) { |
| 4823 | return false; |
| 4824 | } |
| 4825 | if (r.finishing) Slog.e(TAG, "willActivityBeVisibleLocked: Returning false," |
| 4826 | + " would have returned true for r=" + r); |
| 4827 | return !r.finishing; |
Craig Mautner | cae015f | 2013-02-08 14:31:27 -0800 | [diff] [blame] | 4828 | } |
| 4829 | |
| 4830 | void closeSystemDialogsLocked() { |
Craig Mautner | d44711d | 2013-02-23 11:24:36 -0800 | [diff] [blame] | 4831 | for (int taskNdx = mTaskHistory.size() - 1; taskNdx >= 0; --taskNdx) { |
| 4832 | final ArrayList<ActivityRecord> activities = mTaskHistory.get(taskNdx).mActivities; |
| 4833 | for (int activityNdx = activities.size() - 1; activityNdx >= 0; --activityNdx) { |
| 4834 | final ActivityRecord r = activities.get(activityNdx); |
| 4835 | if ((r.info.flags&ActivityInfo.FLAG_FINISH_ON_CLOSE_SYSTEM_DIALOGS) != 0) { |
Craig Mautner | d232895 | 2013-03-05 12:46:26 -0800 | [diff] [blame] | 4836 | finishActivityLocked(r, Activity.RESULT_CANCELED, null, "close-sys", true); |
Craig Mautner | d44711d | 2013-02-23 11:24:36 -0800 | [diff] [blame] | 4837 | } |
Craig Mautner | cae015f | 2013-02-08 14:31:27 -0800 | [diff] [blame] | 4838 | } |
| 4839 | } |
| 4840 | } |
| 4841 | |
Wale Ogunwale | 540e123 | 2015-05-01 15:35:39 -0700 | [diff] [blame] | 4842 | boolean finishDisabledPackageActivitiesLocked(String packageName, Set<String> filterByClasses, |
| 4843 | boolean doit, boolean evenPersistent, int userId) { |
Craig Mautner | cae015f | 2013-02-08 14:31:27 -0800 | [diff] [blame] | 4844 | boolean didSomething = false; |
| 4845 | TaskRecord lastTask = null; |
Craig Mautner | 9d8a30d | 2014-07-07 17:26:20 +0000 | [diff] [blame] | 4846 | ComponentName homeActivity = null; |
Craig Mautner | 56f52db | 2013-02-25 10:03:01 -0800 | [diff] [blame] | 4847 | for (int taskNdx = mTaskHistory.size() - 1; taskNdx >= 0; --taskNdx) { |
| 4848 | final ArrayList<ActivityRecord> activities = mTaskHistory.get(taskNdx).mActivities; |
| 4849 | int numActivities = activities.size(); |
| 4850 | for (int activityNdx = 0; activityNdx < numActivities; ++activityNdx) { |
| 4851 | ActivityRecord r = activities.get(activityNdx); |
Wale Ogunwale | 540e123 | 2015-05-01 15:35:39 -0700 | [diff] [blame] | 4852 | final boolean sameComponent = |
| 4853 | (r.packageName.equals(packageName) && (filterByClasses == null |
| 4854 | || filterByClasses.contains(r.realActivity.getClassName()))) |
| 4855 | || (packageName == null && r.userId == userId); |
Craig Mautner | 56f52db | 2013-02-25 10:03:01 -0800 | [diff] [blame] | 4856 | if ((userId == UserHandle.USER_ALL || r.userId == userId) |
Wale Ogunwale | 540e123 | 2015-05-01 15:35:39 -0700 | [diff] [blame] | 4857 | && (sameComponent || r.task == lastTask) |
Craig Mautner | 56f52db | 2013-02-25 10:03:01 -0800 | [diff] [blame] | 4858 | && (r.app == null || evenPersistent || !r.app.persistent)) { |
| 4859 | if (!doit) { |
| 4860 | if (r.finishing) { |
| 4861 | // If this activity is just finishing, then it is not |
| 4862 | // interesting as far as something to stop. |
| 4863 | continue; |
| 4864 | } |
| 4865 | return true; |
Craig Mautner | cae015f | 2013-02-08 14:31:27 -0800 | [diff] [blame] | 4866 | } |
Craig Mautner | 9d8a30d | 2014-07-07 17:26:20 +0000 | [diff] [blame] | 4867 | if (r.isHomeActivity()) { |
| 4868 | if (homeActivity != null && homeActivity.equals(r.realActivity)) { |
| 4869 | Slog.i(TAG, "Skip force-stop again " + r); |
| 4870 | continue; |
| 4871 | } else { |
| 4872 | homeActivity = r.realActivity; |
| 4873 | } |
| 4874 | } |
Craig Mautner | 56f52db | 2013-02-25 10:03:01 -0800 | [diff] [blame] | 4875 | didSomething = true; |
| 4876 | Slog.i(TAG, " Force finishing activity " + r); |
Wale Ogunwale | 540e123 | 2015-05-01 15:35:39 -0700 | [diff] [blame] | 4877 | if (sameComponent) { |
Craig Mautner | 56f52db | 2013-02-25 10:03:01 -0800 | [diff] [blame] | 4878 | if (r.app != null) { |
| 4879 | r.app.removed = true; |
| 4880 | } |
| 4881 | r.app = null; |
Craig Mautner | cae015f | 2013-02-08 14:31:27 -0800 | [diff] [blame] | 4882 | } |
Craig Mautner | 56f52db | 2013-02-25 10:03:01 -0800 | [diff] [blame] | 4883 | lastTask = r.task; |
Craig Mautner | d94b1b4 | 2013-05-01 11:58:03 -0700 | [diff] [blame] | 4884 | if (finishActivityLocked(r, Activity.RESULT_CANCELED, null, "force-stop", |
| 4885 | true)) { |
| 4886 | // r has been deleted from mActivities, accommodate. |
| 4887 | --numActivities; |
| 4888 | --activityNdx; |
| 4889 | } |
Craig Mautner | cae015f | 2013-02-08 14:31:27 -0800 | [diff] [blame] | 4890 | } |
| 4891 | } |
| 4892 | } |
| 4893 | return didSomething; |
| 4894 | } |
| 4895 | |
Dianne Hackborn | 0923328 | 2014-04-30 11:33:59 -0700 | [diff] [blame] | 4896 | void getTasksLocked(List<RunningTaskInfo> list, int callingUid, boolean allowed) { |
riddle_hsu | ddc7415 | 2015-04-07 11:30:09 +0800 | [diff] [blame] | 4897 | boolean focusedStack = mStackSupervisor.getFocusedStack() == this; |
| 4898 | boolean topTask = true; |
Craig Mautner | c0fd805 | 2013-09-19 11:20:17 -0700 | [diff] [blame] | 4899 | for (int taskNdx = mTaskHistory.size() - 1; taskNdx >= 0; --taskNdx) { |
Craig Mautner | aab647e | 2013-02-28 16:31:36 -0800 | [diff] [blame] | 4900 | final TaskRecord task = mTaskHistory.get(taskNdx); |
riddle_hsu | ddc7415 | 2015-04-07 11:30:09 +0800 | [diff] [blame] | 4901 | if (task.getTopActivity() == null) { |
| 4902 | continue; |
| 4903 | } |
Craig Mautner | aab647e | 2013-02-28 16:31:36 -0800 | [diff] [blame] | 4904 | ActivityRecord r = null; |
| 4905 | ActivityRecord top = null; |
Wale Ogunwale | 6035e01 | 2015-04-14 15:54:10 -0700 | [diff] [blame] | 4906 | ActivityRecord tmp; |
Craig Mautner | aab647e | 2013-02-28 16:31:36 -0800 | [diff] [blame] | 4907 | int numActivities = 0; |
| 4908 | int numRunning = 0; |
| 4909 | final ArrayList<ActivityRecord> activities = task.mActivities; |
Dianne Hackborn | 885fbe5 | 2014-08-23 15:23:58 -0700 | [diff] [blame] | 4910 | if (!allowed && !task.isHomeTask() && task.effectiveUid != callingUid) { |
Dianne Hackborn | 0923328 | 2014-04-30 11:33:59 -0700 | [diff] [blame] | 4911 | continue; |
| 4912 | } |
Craig Mautner | aab647e | 2013-02-28 16:31:36 -0800 | [diff] [blame] | 4913 | for (int activityNdx = activities.size() - 1; activityNdx >= 0; --activityNdx) { |
Wale Ogunwale | 6035e01 | 2015-04-14 15:54:10 -0700 | [diff] [blame] | 4914 | tmp = activities.get(activityNdx); |
| 4915 | if (tmp.finishing) { |
| 4916 | continue; |
| 4917 | } |
| 4918 | r = tmp; |
Craig Mautner | cae015f | 2013-02-08 14:31:27 -0800 | [diff] [blame] | 4919 | |
Craig Mautner | aab647e | 2013-02-28 16:31:36 -0800 | [diff] [blame] | 4920 | // Initialize state for next task if needed. |
| 4921 | if (top == null || (top.state == ActivityState.INITIALIZING)) { |
| 4922 | top = r; |
| 4923 | numActivities = numRunning = 0; |
Craig Mautner | cae015f | 2013-02-08 14:31:27 -0800 | [diff] [blame] | 4924 | } |
Craig Mautner | aab647e | 2013-02-28 16:31:36 -0800 | [diff] [blame] | 4925 | |
| 4926 | // Add 'r' into the current task. |
| 4927 | numActivities++; |
| 4928 | if (r.app != null && r.app.thread != null) { |
| 4929 | numRunning++; |
| 4930 | } |
| 4931 | |
Wale Ogunwale | e23149f | 2015-03-06 15:39:44 -0800 | [diff] [blame] | 4932 | if (DEBUG_ALL) Slog.v( |
Craig Mautner | aab647e | 2013-02-28 16:31:36 -0800 | [diff] [blame] | 4933 | TAG, r.intent.getComponent().flattenToShortString() |
| 4934 | + ": task=" + r.task); |
| 4935 | } |
| 4936 | |
| 4937 | RunningTaskInfo ci = new RunningTaskInfo(); |
| 4938 | ci.id = task.taskId; |
Filip Gruszczynski | d64ef3e | 2015-10-27 17:58:02 -0700 | [diff] [blame] | 4939 | ci.stackId = mStackId; |
Craig Mautner | aab647e | 2013-02-28 16:31:36 -0800 | [diff] [blame] | 4940 | ci.baseActivity = r.intent.getComponent(); |
| 4941 | ci.topActivity = top.intent.getComponent(); |
Craig Mautner | c0fd805 | 2013-09-19 11:20:17 -0700 | [diff] [blame] | 4942 | ci.lastActiveTime = task.lastActiveTime; |
riddle_hsu | ddc7415 | 2015-04-07 11:30:09 +0800 | [diff] [blame] | 4943 | if (focusedStack && topTask) { |
| 4944 | // Give the latest time to ensure foreground task can be sorted |
| 4945 | // at the first, because lastActiveTime of creating task is 0. |
| 4946 | ci.lastActiveTime = System.currentTimeMillis(); |
| 4947 | topTask = false; |
| 4948 | } |
Craig Mautner | c0fd805 | 2013-09-19 11:20:17 -0700 | [diff] [blame] | 4949 | |
Craig Mautner | c0ffce5 | 2014-07-01 12:38:52 -0700 | [diff] [blame] | 4950 | if (top.task != null) { |
| 4951 | ci.description = top.task.lastDescription; |
Craig Mautner | aab647e | 2013-02-28 16:31:36 -0800 | [diff] [blame] | 4952 | } |
| 4953 | ci.numActivities = numActivities; |
| 4954 | ci.numRunning = numRunning; |
Wale Ogunwale | 21b6058 | 2016-01-27 12:34:16 -0800 | [diff] [blame] | 4955 | ci.isDockable = task.canGoInDockedStack(); |
Jorim Jaggi | 29379ec | 2016-04-11 23:43:42 -0700 | [diff] [blame] | 4956 | ci.resizeMode = task.mResizeMode; |
Craig Mautner | aab647e | 2013-02-28 16:31:36 -0800 | [diff] [blame] | 4957 | list.add(ci); |
Craig Mautner | cae015f | 2013-02-08 14:31:27 -0800 | [diff] [blame] | 4958 | } |
Craig Mautner | cae015f | 2013-02-08 14:31:27 -0800 | [diff] [blame] | 4959 | } |
| 4960 | |
| 4961 | public void unhandledBackLocked() { |
Craig Mautner | aab647e | 2013-02-28 16:31:36 -0800 | [diff] [blame] | 4962 | final int top = mTaskHistory.size() - 1; |
Wale Ogunwale | ee006da | 2015-03-30 14:49:25 -0700 | [diff] [blame] | 4963 | 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] | 4964 | if (top >= 0) { |
| 4965 | final ArrayList<ActivityRecord> activities = mTaskHistory.get(top).mActivities; |
| 4966 | int activityTop = activities.size() - 1; |
| 4967 | if (activityTop > 0) { |
| 4968 | finishActivityLocked(activities.get(activityTop), Activity.RESULT_CANCELED, null, |
| 4969 | "unhandled-back", true); |
| 4970 | } |
Craig Mautner | cae015f | 2013-02-08 14:31:27 -0800 | [diff] [blame] | 4971 | } |
| 4972 | } |
| 4973 | |
Craig Mautner | 6b74cb5 | 2013-09-27 17:02:21 -0700 | [diff] [blame] | 4974 | /** |
| 4975 | * Reset local parameters because an app's activity died. |
| 4976 | * @param app The app of the activity that died. |
Craig Mautner | 1909125 | 2013-10-05 00:03:53 -0700 | [diff] [blame] | 4977 | * @return result from removeHistoryRecordsForAppLocked. |
Craig Mautner | 6b74cb5 | 2013-09-27 17:02:21 -0700 | [diff] [blame] | 4978 | */ |
| 4979 | boolean handleAppDiedLocked(ProcessRecord app) { |
Craig Mautner | e79d4268 | 2013-04-01 19:01:53 -0700 | [diff] [blame] | 4980 | if (mPausingActivity != null && mPausingActivity.app == app) { |
Wale Ogunwale | ee006da | 2015-03-30 14:49:25 -0700 | [diff] [blame] | 4981 | if (DEBUG_PAUSE || DEBUG_CLEANUP) Slog.v(TAG_PAUSE, |
Craig Mautner | e79d4268 | 2013-04-01 19:01:53 -0700 | [diff] [blame] | 4982 | "App died while pausing: " + mPausingActivity); |
| 4983 | mPausingActivity = null; |
| 4984 | } |
| 4985 | if (mLastPausedActivity != null && mLastPausedActivity.app == app) { |
| 4986 | mLastPausedActivity = null; |
Craig Mautner | 0f92274 | 2013-08-06 08:44:42 -0700 | [diff] [blame] | 4987 | mLastNoHistoryActivity = null; |
Craig Mautner | e79d4268 | 2013-04-01 19:01:53 -0700 | [diff] [blame] | 4988 | } |
| 4989 | |
Craig Mautner | 1909125 | 2013-10-05 00:03:53 -0700 | [diff] [blame] | 4990 | return removeHistoryRecordsForAppLocked(app); |
Craig Mautner | e79d4268 | 2013-04-01 19:01:53 -0700 | [diff] [blame] | 4991 | } |
| 4992 | |
Craig Mautner | cae015f | 2013-02-08 14:31:27 -0800 | [diff] [blame] | 4993 | void handleAppCrashLocked(ProcessRecord app) { |
Craig Mautner | d44711d | 2013-02-23 11:24:36 -0800 | [diff] [blame] | 4994 | for (int taskNdx = mTaskHistory.size() - 1; taskNdx >= 0; --taskNdx) { |
| 4995 | final ArrayList<ActivityRecord> activities = mTaskHistory.get(taskNdx).mActivities; |
| 4996 | for (int activityNdx = activities.size() - 1; activityNdx >= 0; --activityNdx) { |
| 4997 | final ActivityRecord r = activities.get(activityNdx); |
| 4998 | if (r.app == app) { |
| 4999 | Slog.w(TAG, " Force finishing activity " |
| 5000 | + r.intent.getComponent().flattenToShortString()); |
Craig Mautner | 8e5b133 | 2014-07-24 13:32:37 -0700 | [diff] [blame] | 5001 | // Force the destroy to skip right to removal. |
| 5002 | r.app = null; |
| 5003 | finishCurrentActivityLocked(r, FINISH_IMMEDIATELY, false); |
Craig Mautner | d44711d | 2013-02-23 11:24:36 -0800 | [diff] [blame] | 5004 | } |
Craig Mautner | cae015f | 2013-02-08 14:31:27 -0800 | [diff] [blame] | 5005 | } |
| 5006 | } |
| 5007 | } |
| 5008 | |
Dianne Hackborn | 390517b | 2013-05-30 15:03:32 -0700 | [diff] [blame] | 5009 | boolean dumpActivitiesLocked(FileDescriptor fd, PrintWriter pw, boolean dumpAll, |
Dianne Hackborn | 7ad34e5 | 2013-06-05 18:41:45 -0700 | [diff] [blame] | 5010 | boolean dumpClient, String dumpPackage, boolean needSep, String header) { |
Dianne Hackborn | 390517b | 2013-05-30 15:03:32 -0700 | [diff] [blame] | 5011 | boolean printed = false; |
Craig Mautner | aab647e | 2013-02-28 16:31:36 -0800 | [diff] [blame] | 5012 | for (int taskNdx = mTaskHistory.size() - 1; taskNdx >= 0; --taskNdx) { |
| 5013 | final TaskRecord task = mTaskHistory.get(taskNdx); |
Dianne Hackborn | 390517b | 2013-05-30 15:03:32 -0700 | [diff] [blame] | 5014 | printed |= ActivityStackSupervisor.dumpHistoryList(fd, pw, |
| 5015 | mTaskHistory.get(taskNdx).mActivities, " ", "Hist", true, !dumpAll, |
Dianne Hackborn | 7ad34e5 | 2013-06-05 18:41:45 -0700 | [diff] [blame] | 5016 | dumpClient, dumpPackage, needSep, header, |
Wale Ogunwale | b34a7ad | 2015-08-14 11:05:30 -0700 | [diff] [blame] | 5017 | " Task id #" + task.taskId + "\n" + |
| 5018 | " mFullscreen=" + task.mFullscreen + "\n" + |
| 5019 | " mBounds=" + task.mBounds + "\n" + |
Andrii Kulian | f66a83d | 2016-05-17 12:17:44 -0700 | [diff] [blame] | 5020 | " mMinWidth=" + task.mMinWidth + "\n" + |
| 5021 | " mMinHeight=" + task.mMinHeight + "\n" + |
Wale Ogunwale | b34a7ad | 2015-08-14 11:05:30 -0700 | [diff] [blame] | 5022 | " mLastNonFullscreenBounds=" + task.mLastNonFullscreenBounds); |
Dianne Hackborn | 7ad34e5 | 2013-06-05 18:41:45 -0700 | [diff] [blame] | 5023 | if (printed) { |
| 5024 | header = null; |
| 5025 | } |
Craig Mautner | aab647e | 2013-02-28 16:31:36 -0800 | [diff] [blame] | 5026 | } |
Dianne Hackborn | 390517b | 2013-05-30 15:03:32 -0700 | [diff] [blame] | 5027 | return printed; |
Craig Mautner | cae015f | 2013-02-08 14:31:27 -0800 | [diff] [blame] | 5028 | } |
| 5029 | |
| 5030 | ArrayList<ActivityRecord> getDumpActivitiesLocked(String name) { |
| 5031 | ArrayList<ActivityRecord> activities = new ArrayList<ActivityRecord>(); |
| 5032 | |
| 5033 | if ("all".equals(name)) { |
Craig Mautner | aab647e | 2013-02-28 16:31:36 -0800 | [diff] [blame] | 5034 | for (int taskNdx = mTaskHistory.size() - 1; taskNdx >= 0; --taskNdx) { |
| 5035 | activities.addAll(mTaskHistory.get(taskNdx).mActivities); |
Craig Mautner | cae015f | 2013-02-08 14:31:27 -0800 | [diff] [blame] | 5036 | } |
| 5037 | } else if ("top".equals(name)) { |
Craig Mautner | aab647e | 2013-02-28 16:31:36 -0800 | [diff] [blame] | 5038 | final int top = mTaskHistory.size() - 1; |
| 5039 | if (top >= 0) { |
| 5040 | final ArrayList<ActivityRecord> list = mTaskHistory.get(top).mActivities; |
| 5041 | int listTop = list.size() - 1; |
| 5042 | if (listTop >= 0) { |
| 5043 | activities.add(list.get(listTop)); |
| 5044 | } |
Craig Mautner | cae015f | 2013-02-08 14:31:27 -0800 | [diff] [blame] | 5045 | } |
| 5046 | } else { |
| 5047 | ItemMatcher matcher = new ItemMatcher(); |
| 5048 | matcher.build(name); |
| 5049 | |
Craig Mautner | aab647e | 2013-02-28 16:31:36 -0800 | [diff] [blame] | 5050 | for (int taskNdx = mTaskHistory.size() - 1; taskNdx >= 0; --taskNdx) { |
| 5051 | for (ActivityRecord r1 : mTaskHistory.get(taskNdx).mActivities) { |
| 5052 | if (matcher.match(r1, r1.intent.getComponent())) { |
| 5053 | activities.add(r1); |
| 5054 | } |
Craig Mautner | cae015f | 2013-02-08 14:31:27 -0800 | [diff] [blame] | 5055 | } |
| 5056 | } |
| 5057 | } |
| 5058 | |
| 5059 | return activities; |
| 5060 | } |
| 5061 | |
| 5062 | ActivityRecord restartPackage(String packageName) { |
Filip Gruszczynski | 3e85ba2 | 2015-10-05 22:48:30 -0700 | [diff] [blame] | 5063 | ActivityRecord starting = topRunningActivityLocked(); |
Craig Mautner | cae015f | 2013-02-08 14:31:27 -0800 | [diff] [blame] | 5064 | |
| 5065 | // All activities that came from the package must be |
| 5066 | // restarted as if there was a config change. |
Craig Mautner | aab647e | 2013-02-28 16:31:36 -0800 | [diff] [blame] | 5067 | for (int taskNdx = mTaskHistory.size() - 1; taskNdx >= 0; --taskNdx) { |
| 5068 | final ArrayList<ActivityRecord> activities = mTaskHistory.get(taskNdx).mActivities; |
| 5069 | for (int activityNdx = activities.size() - 1; activityNdx >= 0; --activityNdx) { |
| 5070 | final ActivityRecord a = activities.get(activityNdx); |
| 5071 | if (a.info.packageName.equals(packageName)) { |
| 5072 | a.forceNewConfig = true; |
| 5073 | if (starting != null && a == starting && a.visible) { |
| 5074 | a.startFreezingScreenLocked(starting.app, |
Filip Gruszczynski | 3c2db1d1 | 2016-01-06 17:39:14 -0800 | [diff] [blame] | 5075 | CONFIG_SCREEN_LAYOUT); |
Craig Mautner | aab647e | 2013-02-28 16:31:36 -0800 | [diff] [blame] | 5076 | } |
Craig Mautner | cae015f | 2013-02-08 14:31:27 -0800 | [diff] [blame] | 5077 | } |
| 5078 | } |
| 5079 | } |
| 5080 | |
| 5081 | return starting; |
| 5082 | } |
Craig Mautner | 5d9c7be | 2013-02-15 14:02:56 -0800 | [diff] [blame] | 5083 | |
Craig Mautner | 299f960 | 2015-01-26 09:47:33 -0800 | [diff] [blame] | 5084 | void removeTask(TaskRecord task, String reason) { |
Wale Ogunwale | 06579d6 | 2016-04-30 15:29:06 -0700 | [diff] [blame] | 5085 | removeTask(task, reason, REMOVE_TASK_MODE_DESTROYING); |
Wale Ogunwale | 53a29a9 | 2015-02-23 15:42:52 -0800 | [diff] [blame] | 5086 | } |
| 5087 | |
Wale Ogunwale | 000957c | 2015-04-03 08:19:12 -0700 | [diff] [blame] | 5088 | /** |
| 5089 | * Removes the input task from this stack. |
| 5090 | * @param task to remove. |
| 5091 | * @param reason for removal. |
Wale Ogunwale | 06579d6 | 2016-04-30 15:29:06 -0700 | [diff] [blame] | 5092 | * @param mode task removal mode. Either {@link #REMOVE_TASK_MODE_DESTROYING}, |
| 5093 | * {@link #REMOVE_TASK_MODE_MOVING}, {@link #REMOVE_TASK_MODE_MOVING_TO_TOP}. |
Wale Ogunwale | 000957c | 2015-04-03 08:19:12 -0700 | [diff] [blame] | 5094 | */ |
Wale Ogunwale | 06579d6 | 2016-04-30 15:29:06 -0700 | [diff] [blame] | 5095 | void removeTask(TaskRecord task, String reason, int mode) { |
| 5096 | if (mode == REMOVE_TASK_MODE_DESTROYING) { |
Craig Mautner | 15df08a | 2015-04-01 12:17:18 -0700 | [diff] [blame] | 5097 | mStackSupervisor.removeLockedTaskLocked(task); |
Wale Ogunwale | 53a29a9 | 2015-02-23 15:42:52 -0800 | [diff] [blame] | 5098 | mWindowManager.removeTask(task.taskId); |
Wale Ogunwale | b317b22 | 2015-11-09 11:14:10 -0800 | [diff] [blame] | 5099 | if (!StackId.persistTaskBounds(mStackId)) { |
| 5100 | // Reset current bounds for task whose bounds shouldn't be persisted so it uses |
| 5101 | // default configuration the next time it launches. |
| 5102 | task.updateOverrideConfiguration(null); |
| 5103 | } |
Wale Ogunwale | 53a29a9 | 2015-02-23 15:42:52 -0800 | [diff] [blame] | 5104 | } |
Wale Ogunwale | 000957c | 2015-04-03 08:19:12 -0700 | [diff] [blame] | 5105 | |
Craig Mautner | 04a0ea6 | 2014-01-13 12:51:26 -0800 | [diff] [blame] | 5106 | final ActivityRecord r = mResumedActivity; |
| 5107 | if (r != null && r.task == task) { |
| 5108 | mResumedActivity = null; |
| 5109 | } |
| 5110 | |
Craig Mautner | ae7ecab | 2013-09-18 11:48:14 -0700 | [diff] [blame] | 5111 | final int taskNdx = mTaskHistory.indexOf(task); |
| 5112 | final int topTaskNdx = mTaskHistory.size() - 1; |
Craig Mautner | 84984fa | 2014-06-19 11:19:20 -0700 | [diff] [blame] | 5113 | if (task.isOverHomeStack() && taskNdx < topTaskNdx) { |
| 5114 | final TaskRecord nextTask = mTaskHistory.get(taskNdx + 1); |
| 5115 | if (!nextTask.isOverHomeStack()) { |
| 5116 | nextTask.setTaskToReturnTo(HOME_ACTIVITY_TYPE); |
| 5117 | } |
Craig Mautner | ae7ecab | 2013-09-18 11:48:14 -0700 | [diff] [blame] | 5118 | } |
Craig Mautner | de4ef02 | 2013-04-07 19:01:33 -0700 | [diff] [blame] | 5119 | mTaskHistory.remove(task); |
Craig Mautner | 21d24a2 | 2014-04-23 11:45:37 -0700 | [diff] [blame] | 5120 | updateTaskMovement(task, true); |
Craig Mautner | 41db4a7 | 2014-05-07 17:20:56 -0700 | [diff] [blame] | 5121 | |
Wale Ogunwale | 06579d6 | 2016-04-30 15:29:06 -0700 | [diff] [blame] | 5122 | if (mode == REMOVE_TASK_MODE_DESTROYING && task.mActivities.isEmpty()) { |
Amith Yamasani | 0af6fa7 | 2016-01-17 15:36:19 -0800 | [diff] [blame] | 5123 | // TODO: VI what about activity? |
Craig Mautner | 41db4a7 | 2014-05-07 17:20:56 -0700 | [diff] [blame] | 5124 | final boolean isVoiceSession = task.voiceSession != null; |
| 5125 | if (isVoiceSession) { |
| 5126 | try { |
| 5127 | task.voiceSession.taskFinished(task.intent, task.taskId); |
| 5128 | } catch (RemoteException e) { |
| 5129 | } |
Dianne Hackborn | c03c916 | 2014-05-02 10:45:59 -0700 | [diff] [blame] | 5130 | } |
Craig Mautner | 41db4a7 | 2014-05-07 17:20:56 -0700 | [diff] [blame] | 5131 | if (task.autoRemoveFromRecents() || isVoiceSession) { |
| 5132 | // Task creator asked to remove this when done, or this task was a voice |
| 5133 | // interaction, so it should not remain on the recent tasks list. |
Wale Ogunwale | c82f2f5 | 2014-12-09 09:32:50 -0800 | [diff] [blame] | 5134 | mRecentTasks.remove(task); |
Winson Chung | 740c3ac | 2014-11-12 16:14:38 -0800 | [diff] [blame] | 5135 | task.removedFromRecents(); |
Craig Mautner | 41db4a7 | 2014-05-07 17:20:56 -0700 | [diff] [blame] | 5136 | } |
Dianne Hackborn | 91097de | 2014-04-04 18:02:06 -0700 | [diff] [blame] | 5137 | } |
Craig Mautner | 04a0ea6 | 2014-01-13 12:51:26 -0800 | [diff] [blame] | 5138 | |
| 5139 | if (mTaskHistory.isEmpty()) { |
Wale Ogunwale | ee006da | 2015-03-30 14:49:25 -0700 | [diff] [blame] | 5140 | if (DEBUG_STACK) Slog.i(TAG_STACK, "removeTask: removing stack=" + this); |
Wale Ogunwale | 06579d6 | 2016-04-30 15:29:06 -0700 | [diff] [blame] | 5141 | // We only need to adjust focused stack if this stack is in focus and we are not in the |
| 5142 | // process of moving the task to the top of the stack that will be focused. |
| 5143 | if (isOnHomeDisplay() && mode != REMOVE_TASK_MODE_MOVING_TO_TOP |
| 5144 | && mStackSupervisor.isFocusedStack(this)) { |
Wale Ogunwale | d697cea | 2015-02-20 17:19:49 -0800 | [diff] [blame] | 5145 | String myReason = reason + " leftTaskHistoryEmpty"; |
Wale Ogunwale | d34e80c | 2016-03-23 17:08:44 -0700 | [diff] [blame] | 5146 | if (mFullscreen |
| 5147 | || !adjustFocusToNextFocusableStackLocked( |
| 5148 | task.getTaskToReturnTo(), myReason)) { |
Wale Ogunwale | 925d0d1 | 2015-09-23 15:40:07 -0700 | [diff] [blame] | 5149 | mStackSupervisor.moveHomeStackToFront(myReason); |
Wale Ogunwale | d697cea | 2015-02-20 17:19:49 -0800 | [diff] [blame] | 5150 | } |
Craig Mautner | 04a0ea6 | 2014-01-13 12:51:26 -0800 | [diff] [blame] | 5151 | } |
Craig Mautner | 593a4e6 | 2014-01-15 17:55:51 -0800 | [diff] [blame] | 5152 | if (mStacks != null) { |
| 5153 | mStacks.remove(this); |
| 5154 | mStacks.add(0, this); |
| 5155 | } |
Wale Ogunwale | 925d0d1 | 2015-09-23 15:40:07 -0700 | [diff] [blame] | 5156 | if (!isHomeStack()) { |
Wale Ogunwale | 49853bf | 2015-02-23 09:24:42 -0800 | [diff] [blame] | 5157 | mActivityContainer.onTaskListEmptyLocked(); |
| 5158 | } |
Craig Mautner | 04a0ea6 | 2014-01-13 12:51:26 -0800 | [diff] [blame] | 5159 | } |
Wale Ogunwale | 04f4d6b | 2015-03-11 09:23:25 -0700 | [diff] [blame] | 5160 | |
| 5161 | task.stack = null; |
Craig Mautner | 0247fc8 | 2013-02-28 14:32:06 -0800 | [diff] [blame] | 5162 | } |
| 5163 | |
Dianne Hackborn | 91097de | 2014-04-04 18:02:06 -0700 | [diff] [blame] | 5164 | TaskRecord createTaskRecord(int taskId, ActivityInfo info, Intent intent, |
| 5165 | IVoiceInteractionSession voiceSession, IVoiceInteractor voiceInteractor, |
| 5166 | boolean toTop) { |
Craig Mautner | 21d24a2 | 2014-04-23 11:45:37 -0700 | [diff] [blame] | 5167 | TaskRecord task = new TaskRecord(mService, taskId, info, intent, voiceSession, |
| 5168 | voiceInteractor); |
Chong Zhang | 0fa656b | 2015-08-31 15:17:21 -0700 | [diff] [blame] | 5169 | // add the task to stack first, mTaskPositioner might need the stack association |
Wale Ogunwale | 5f98609 | 2015-12-04 15:35:38 -0800 | [diff] [blame] | 5170 | addTask(task, toTop, "createTaskRecord"); |
Chong Zhang | 75b3720 | 2015-12-04 14:16:36 -0800 | [diff] [blame] | 5171 | final boolean isLockscreenShown = mService.mLockScreenShown == LOCK_SCREEN_SHOWN; |
Andrii Kulian | 2e751b8 | 2016-03-16 16:59:32 -0700 | [diff] [blame] | 5172 | if (!layoutTaskInStack(task, info.windowLayout) && mBounds != null && task.isResizeable() |
Chong Zhang | 75b3720 | 2015-12-04 14:16:36 -0800 | [diff] [blame] | 5173 | && !isLockscreenShown) { |
Wale Ogunwale | a6e902e | 2015-09-21 18:37:15 -0700 | [diff] [blame] | 5174 | task.updateOverrideConfiguration(mBounds); |
Filip Gruszczynski | e5390e7 | 2015-08-18 16:39:00 -0700 | [diff] [blame] | 5175 | } |
Craig Mautner | 5d9c7be | 2013-02-15 14:02:56 -0800 | [diff] [blame] | 5176 | return task; |
| 5177 | } |
Craig Mautner | c00204b | 2013-03-05 15:02:14 -0800 | [diff] [blame] | 5178 | |
Andrii Kulian | 2e751b8 | 2016-03-16 16:59:32 -0700 | [diff] [blame] | 5179 | boolean layoutTaskInStack(TaskRecord task, ActivityInfo.WindowLayout windowLayout) { |
Wale Ogunwale | 935e502 | 2015-11-10 12:36:10 -0800 | [diff] [blame] | 5180 | if (mTaskPositioner == null) { |
| 5181 | return false; |
| 5182 | } |
Andrii Kulian | 2e751b8 | 2016-03-16 16:59:32 -0700 | [diff] [blame] | 5183 | mTaskPositioner.updateDefaultBounds(task, mTaskHistory, windowLayout); |
Wale Ogunwale | 935e502 | 2015-11-10 12:36:10 -0800 | [diff] [blame] | 5184 | return true; |
| 5185 | } |
| 5186 | |
Craig Mautner | c00204b | 2013-03-05 15:02:14 -0800 | [diff] [blame] | 5187 | ArrayList<TaskRecord> getAllTasks() { |
Wale Ogunwale | 9d3de4c | 2015-02-01 16:49:44 -0800 | [diff] [blame] | 5188 | return new ArrayList<>(mTaskHistory); |
Craig Mautner | c00204b | 2013-03-05 15:02:14 -0800 | [diff] [blame] | 5189 | } |
| 5190 | |
Wale Ogunwale | 5f98609 | 2015-12-04 15:35:38 -0800 | [diff] [blame] | 5191 | void addTask(final TaskRecord task, final boolean toTop, String reason) { |
Wale Ogunwale | 06579d6 | 2016-04-30 15:29:06 -0700 | [diff] [blame] | 5192 | final ActivityStack prevStack = preAddTask(task, reason, toTop); |
Wale Ogunwale | 5f98609 | 2015-12-04 15:35:38 -0800 | [diff] [blame] | 5193 | |
Craig Mautner | c00204b | 2013-03-05 15:02:14 -0800 | [diff] [blame] | 5194 | task.stack = this; |
| 5195 | if (toTop) { |
Wale Ogunwale | 3fcb4a8 | 2015-04-06 14:00:13 -0700 | [diff] [blame] | 5196 | insertTaskAtTop(task, null); |
Craig Mautner | c00204b | 2013-03-05 15:02:14 -0800 | [diff] [blame] | 5197 | } else { |
| 5198 | mTaskHistory.add(0, task); |
Craig Mautner | 21d24a2 | 2014-04-23 11:45:37 -0700 | [diff] [blame] | 5199 | updateTaskMovement(task, false); |
Craig Mautner | c00204b | 2013-03-05 15:02:14 -0800 | [diff] [blame] | 5200 | } |
Wale Ogunwale | 5f98609 | 2015-12-04 15:35:38 -0800 | [diff] [blame] | 5201 | postAddTask(task, prevStack); |
Craig Mautner | c00204b | 2013-03-05 15:02:14 -0800 | [diff] [blame] | 5202 | } |
| 5203 | |
Wale Ogunwale | 5f98609 | 2015-12-04 15:35:38 -0800 | [diff] [blame] | 5204 | void positionTask(final TaskRecord task, int position) { |
Jorim Jaggi | 023da53 | 2016-04-20 22:42:32 -0700 | [diff] [blame] | 5205 | final ActivityRecord topRunningActivity = task.topRunningActivityLocked(); |
| 5206 | final boolean wasResumed = topRunningActivity == task.stack.mResumedActivity; |
Wale Ogunwale | ed811d7 | 2016-05-06 08:41:19 -0700 | [diff] [blame] | 5207 | final ActivityStack prevStack = preAddTask(task, "positionTask", !ON_TOP); |
Wale Ogunwale | ddc1cb2 | 2015-07-25 19:23:04 -0700 | [diff] [blame] | 5208 | task.stack = this; |
| 5209 | insertTaskAtPosition(task, position); |
Wale Ogunwale | 5f98609 | 2015-12-04 15:35:38 -0800 | [diff] [blame] | 5210 | postAddTask(task, prevStack); |
Jorim Jaggi | 023da53 | 2016-04-20 22:42:32 -0700 | [diff] [blame] | 5211 | if (wasResumed) { |
| 5212 | if (mResumedActivity != null) { |
| 5213 | Log.wtf(TAG, "mResumedActivity was already set when moving mResumedActivity from" |
| 5214 | + " other stack to this stack mResumedActivity=" + mResumedActivity |
| 5215 | + " other mResumedActivity=" + topRunningActivity); |
| 5216 | } |
| 5217 | mResumedActivity = topRunningActivity; |
| 5218 | } |
Wale Ogunwale | 5f98609 | 2015-12-04 15:35:38 -0800 | [diff] [blame] | 5219 | } |
| 5220 | |
Wale Ogunwale | 06579d6 | 2016-04-30 15:29:06 -0700 | [diff] [blame] | 5221 | private ActivityStack preAddTask(TaskRecord task, String reason, boolean toTop) { |
Wale Ogunwale | 5f98609 | 2015-12-04 15:35:38 -0800 | [diff] [blame] | 5222 | final ActivityStack prevStack = task.stack; |
| 5223 | if (prevStack != null && prevStack != this) { |
Wale Ogunwale | 06579d6 | 2016-04-30 15:29:06 -0700 | [diff] [blame] | 5224 | prevStack.removeTask(task, reason, |
| 5225 | toTop ? REMOVE_TASK_MODE_MOVING_TO_TOP : REMOVE_TASK_MODE_MOVING); |
Wale Ogunwale | 5f98609 | 2015-12-04 15:35:38 -0800 | [diff] [blame] | 5226 | } |
| 5227 | return prevStack; |
| 5228 | } |
| 5229 | |
| 5230 | private void postAddTask(TaskRecord task, ActivityStack prevStack) { |
| 5231 | if (prevStack != null) { |
Andrii Kulian | 933076d | 2016-03-29 17:04:42 -0700 | [diff] [blame] | 5232 | mStackSupervisor.scheduleReportPictureInPictureModeChangedIfNeeded(task, prevStack); |
Wale Ogunwale | 5f98609 | 2015-12-04 15:35:38 -0800 | [diff] [blame] | 5233 | } else if (task.voiceSession != null) { |
Wale Ogunwale | ddc1cb2 | 2015-07-25 19:23:04 -0700 | [diff] [blame] | 5234 | try { |
| 5235 | task.voiceSession.taskStarted(task.intent, task.taskId); |
| 5236 | } catch (RemoteException e) { |
| 5237 | } |
| 5238 | } |
| 5239 | } |
| 5240 | |
Filip Gruszczynski | e5390e7 | 2015-08-18 16:39:00 -0700 | [diff] [blame] | 5241 | void addConfigOverride(ActivityRecord r, TaskRecord task) { |
Filip Gruszczynski | dce2d16 | 2016-01-12 15:40:13 -0800 | [diff] [blame] | 5242 | final Rect bounds = task.updateOverrideConfigurationFromLaunchBounds(); |
Amith Yamasani | 0af6fa7 | 2016-01-17 15:36:19 -0800 | [diff] [blame] | 5243 | // TODO: VI deal with activity |
Filip Gruszczynski | ebcc875 | 2015-08-25 16:51:05 -0700 | [diff] [blame] | 5244 | mWindowManager.addAppToken(task.mActivities.indexOf(r), r.appToken, |
| 5245 | r.task.taskId, mStackId, r.info.screenOrientation, r.fullscreen, |
Wale Ogunwale | 6cae765 | 2015-12-26 07:36:26 -0800 | [diff] [blame] | 5246 | (r.info.flags & FLAG_SHOW_FOR_ALL_USERS) != 0, r.userId, r.info.configChanges, |
| 5247 | task.voiceSession != null, r.mLaunchTaskBehind, bounds, task.mOverrideConfig, |
Yorke Lee | 0e85247 | 2016-06-15 10:03:18 -0700 | [diff] [blame] | 5248 | task.mResizeMode, r.isAlwaysFocusable(), task.isHomeTask(), |
Jiaquan He | dd1e66f | 2016-06-15 15:15:12 -0700 | [diff] [blame] | 5249 | r.appInfo.targetSdkVersion, r.mRotationAnimationHint, task.isOnTopLauncher()); |
Wale Ogunwale | 706ed79 | 2015-08-02 10:29:44 -0700 | [diff] [blame] | 5250 | r.taskConfigOverride = task.mOverrideConfig; |
| 5251 | } |
| 5252 | |
Wale Ogunwale | d046a01 | 2015-12-24 13:05:59 -0800 | [diff] [blame] | 5253 | void moveToFrontAndResumeStateIfNeeded( |
| 5254 | ActivityRecord r, boolean moveToFront, boolean setResume, String reason) { |
| 5255 | if (!moveToFront) { |
| 5256 | return; |
Wale Ogunwale | 079a004 | 2015-10-24 11:44:07 -0700 | [diff] [blame] | 5257 | } |
Wale Ogunwale | d046a01 | 2015-12-24 13:05:59 -0800 | [diff] [blame] | 5258 | |
| 5259 | // If the activity owns the last resumed activity, transfer that together, |
| 5260 | // so that we don't resume the same activity again in the new stack. |
| 5261 | // Apps may depend on onResume()/onPause() being called in pairs. |
| 5262 | if (setResume) { |
| 5263 | mResumedActivity = r; |
| 5264 | } |
| 5265 | // Move the stack in which we are placing the activity to the front. The call will also |
| 5266 | // make sure the activity focus is set. |
| 5267 | moveToFront(reason); |
Wale Ogunwale | 079a004 | 2015-10-24 11:44:07 -0700 | [diff] [blame] | 5268 | } |
| 5269 | |
| 5270 | /** |
| 5271 | * Moves the input activity from its current stack to this one. |
| 5272 | * NOTE: The current task of the activity isn't moved to this stack. Instead a new task is |
| 5273 | * created on this stack which the activity is added to. |
| 5274 | * */ |
| 5275 | void moveActivityToStack(ActivityRecord r) { |
| 5276 | final ActivityStack prevStack = r.task.stack; |
| 5277 | if (prevStack.mStackId == mStackId) { |
| 5278 | // You are already in the right stack silly... |
| 5279 | return; |
| 5280 | } |
| 5281 | |
Wale Ogunwale | 1e60e0c | 2015-10-28 13:36:10 -0700 | [diff] [blame] | 5282 | final boolean wasFocused = mStackSupervisor.isFocusedStack(prevStack) |
Wale Ogunwale | 079a004 | 2015-10-24 11:44:07 -0700 | [diff] [blame] | 5283 | && (mStackSupervisor.topRunningActivityLocked() == r); |
| 5284 | final boolean wasResumed = wasFocused && (prevStack.mResumedActivity == r); |
| 5285 | |
| 5286 | final TaskRecord task = createTaskRecord( |
Suprabh Shukla | 09a88f5 | 2015-12-02 14:36:31 -0800 | [diff] [blame] | 5287 | mStackSupervisor.getNextTaskIdForUserLocked(r.userId), |
| 5288 | r.info, r.intent, null, null, true); |
Wale Ogunwale | 079a004 | 2015-10-24 11:44:07 -0700 | [diff] [blame] | 5289 | r.setTask(task, null); |
| 5290 | task.addActivityToTop(r); |
| 5291 | setAppTask(r, task); |
Andrii Kulian | 933076d | 2016-03-29 17:04:42 -0700 | [diff] [blame] | 5292 | mStackSupervisor.scheduleReportPictureInPictureModeChangedIfNeeded(task, prevStack); |
Wale Ogunwale | d046a01 | 2015-12-24 13:05:59 -0800 | [diff] [blame] | 5293 | moveToFrontAndResumeStateIfNeeded(r, wasFocused, wasResumed, "moveActivityToStack"); |
| 5294 | if (wasResumed) { |
| 5295 | prevStack.mResumedActivity = null; |
| 5296 | } |
Wale Ogunwale | 079a004 | 2015-10-24 11:44:07 -0700 | [diff] [blame] | 5297 | } |
| 5298 | |
Wale Ogunwale | 706ed79 | 2015-08-02 10:29:44 -0700 | [diff] [blame] | 5299 | private void setAppTask(ActivityRecord r, TaskRecord task) { |
Filip Gruszczynski | dce2d16 | 2016-01-12 15:40:13 -0800 | [diff] [blame] | 5300 | final Rect bounds = task.updateOverrideConfigurationFromLaunchBounds(); |
Wale Ogunwale | b1faf60 | 2016-01-27 09:12:31 -0800 | [diff] [blame] | 5301 | mWindowManager.setAppTask(r.appToken, task.taskId, mStackId, bounds, task.mOverrideConfig, |
Jiaquan He | dd1e66f | 2016-06-15 15:15:12 -0700 | [diff] [blame] | 5302 | task.mResizeMode, task.isHomeTask(), task.isOnTopLauncher()); |
Wale Ogunwale | 706ed79 | 2015-08-02 10:29:44 -0700 | [diff] [blame] | 5303 | r.taskConfigOverride = task.mOverrideConfig; |
| 5304 | } |
| 5305 | |
Craig Mautner | c00204b | 2013-03-05 15:02:14 -0800 | [diff] [blame] | 5306 | public int getStackId() { |
| 5307 | return mStackId; |
| 5308 | } |
Craig Mautner | de4ef02 | 2013-04-07 19:01:33 -0700 | [diff] [blame] | 5309 | |
| 5310 | @Override |
| 5311 | public String toString() { |
Dianne Hackborn | 2a272d4 | 2013-10-16 13:34:33 -0700 | [diff] [blame] | 5312 | return "ActivityStack{" + Integer.toHexString(System.identityHashCode(this)) |
| 5313 | + " stackId=" + mStackId + ", " + mTaskHistory.size() + " tasks}"; |
Craig Mautner | de4ef02 | 2013-04-07 19:01:33 -0700 | [diff] [blame] | 5314 | } |
Wale Ogunwale | 60454db | 2015-01-23 16:05:07 -0800 | [diff] [blame] | 5315 | |
Craig Mautner | 15df08a | 2015-04-01 12:17:18 -0700 | [diff] [blame] | 5316 | void onLockTaskPackagesUpdatedLocked() { |
| 5317 | for (int taskNdx = mTaskHistory.size() - 1; taskNdx >= 0; --taskNdx) { |
| 5318 | mTaskHistory.get(taskNdx).setLockTaskAuth(); |
| 5319 | } |
| 5320 | } |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 5321 | } |