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 | |
Wale Ogunwale | 5950709 | 2018-10-29 09:00:30 -0700 | [diff] [blame] | 17 | package com.android.server.wm; |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 18 | |
Wale Ogunwale | 30e441d | 2017-11-09 08:28:45 -0800 | [diff] [blame] | 19 | import static android.app.ITaskStackListener.FORCED_RESIZEABLE_REASON_SPLIT_SCREEN; |
Matthew Ng | a51dcaa | 2018-05-07 15:36:06 -0700 | [diff] [blame] | 20 | import static android.app.WindowConfiguration.ACTIVITY_TYPE_ASSISTANT; |
Matthew Ng | 99b3cdc | 2018-05-01 14:24:38 -0700 | [diff] [blame] | 21 | import static android.app.WindowConfiguration.ACTIVITY_TYPE_HOME; |
Wale Ogunwale | 30e441d | 2017-11-09 08:28:45 -0800 | [diff] [blame] | 22 | import static android.app.WindowConfiguration.ACTIVITY_TYPE_RECENTS; |
Wale Ogunwale | 6fbde9f | 2017-08-24 07:24:12 -0700 | [diff] [blame] | 23 | import static android.app.WindowConfiguration.ACTIVITY_TYPE_STANDARD; |
| 24 | import static android.app.WindowConfiguration.ACTIVITY_TYPE_UNDEFINED; |
Wale Ogunwale | 44f036f | 2017-09-29 05:09:09 -0700 | [diff] [blame] | 25 | import static android.app.WindowConfiguration.WINDOWING_MODE_FREEFORM; |
Wale Ogunwale | 6827856 | 2017-09-23 17:13:55 -0700 | [diff] [blame] | 26 | import static android.app.WindowConfiguration.WINDOWING_MODE_FULLSCREEN; |
Wale Ogunwale | 2b07da8 | 2017-11-08 14:52:40 -0800 | [diff] [blame] | 27 | import static android.app.WindowConfiguration.WINDOWING_MODE_PINNED; |
Wale Ogunwale | 9dcf946 | 2017-09-19 15:13:01 -0700 | [diff] [blame] | 28 | import static android.app.WindowConfiguration.WINDOWING_MODE_SPLIT_SCREEN_PRIMARY; |
Wale Ogunwale | 6827856 | 2017-09-23 17:13:55 -0700 | [diff] [blame] | 29 | import static android.app.WindowConfiguration.WINDOWING_MODE_SPLIT_SCREEN_SECONDARY; |
Wale Ogunwale | f75962a | 2017-08-23 14:58:04 -0700 | [diff] [blame] | 30 | import static android.app.WindowConfiguration.WINDOWING_MODE_UNDEFINED; |
Wale Ogunwale | 44f036f | 2017-09-29 05:09:09 -0700 | [diff] [blame] | 31 | import static android.app.WindowConfiguration.activityTypeToString; |
| 32 | import static android.app.WindowConfiguration.windowingModeToString; |
Filip Gruszczynski | 3c2db1d1 | 2016-01-06 17:39:14 -0800 | [diff] [blame] | 33 | import static android.content.pm.ActivityInfo.CONFIG_SCREEN_LAYOUT; |
Wale Ogunwale | 5658e4b | 2016-02-12 12:22:19 -0800 | [diff] [blame] | 34 | import static android.content.pm.ActivityInfo.FLAG_RESUME_WHILE_PAUSING; |
Wale Ogunwale | 6dfdfd6 | 2015-04-15 12:01:38 -0700 | [diff] [blame] | 35 | import static android.content.pm.ActivityInfo.FLAG_SHOW_FOR_ALL_USERS; |
Wale Ogunwale | f5d1e35 | 2016-09-22 08:34:42 -0700 | [diff] [blame] | 36 | import static android.view.Display.DEFAULT_DISPLAY; |
Andrii Kulian | 7211d2e | 2017-01-27 15:58:05 -0800 | [diff] [blame] | 37 | import static android.view.Display.FLAG_CAN_SHOW_WITH_INSECURE_KEYGUARD; |
Andrii Kulian | 94e82d9b0 | 2017-07-13 15:33:06 -0700 | [diff] [blame] | 38 | import static android.view.Display.INVALID_DISPLAY; |
Louis Chang | 7d0037c | 2018-08-13 12:42:06 +0800 | [diff] [blame] | 39 | import static android.view.WindowManager.TRANSIT_ACTIVITY_CLOSE; |
| 40 | import static android.view.WindowManager.TRANSIT_ACTIVITY_OPEN; |
| 41 | import static android.view.WindowManager.TRANSIT_CRASHING_ACTIVITY_CLOSE; |
| 42 | import static android.view.WindowManager.TRANSIT_NONE; |
| 43 | import static android.view.WindowManager.TRANSIT_TASK_CLOSE; |
| 44 | import static android.view.WindowManager.TRANSIT_TASK_OPEN; |
| 45 | import static android.view.WindowManager.TRANSIT_TASK_OPEN_BEHIND; |
| 46 | import static android.view.WindowManager.TRANSIT_TASK_TO_BACK; |
| 47 | import static android.view.WindowManager.TRANSIT_TASK_TO_FRONT; |
Winson Chung | 1dbc811 | 2017-09-28 18:05:31 -0700 | [diff] [blame] | 48 | |
Evan Rosky | e747c3e | 2018-10-30 20:06:41 -0700 | [diff] [blame] | 49 | import static com.android.server.am.ActivityStackProto.BOUNDS; |
| 50 | import static com.android.server.am.ActivityStackProto.CONFIGURATION_CONTAINER; |
| 51 | import static com.android.server.am.ActivityStackProto.DISPLAY_ID; |
| 52 | import static com.android.server.am.ActivityStackProto.FULLSCREEN; |
| 53 | import static com.android.server.am.ActivityStackProto.ID; |
| 54 | import static com.android.server.am.ActivityStackProto.RESUMED_ACTIVITY; |
| 55 | import static com.android.server.am.ActivityStackProto.TASKS; |
Wale Ogunwale | 5950709 | 2018-10-29 09:00:30 -0700 | [diff] [blame] | 56 | import static com.android.server.wm.ActivityDisplay.POSITION_BOTTOM; |
| 57 | import static com.android.server.wm.ActivityDisplay.POSITION_TOP; |
| 58 | import static com.android.server.wm.ActivityStack.ActivityState.DESTROYED; |
| 59 | import static com.android.server.wm.ActivityStack.ActivityState.DESTROYING; |
| 60 | import static com.android.server.wm.ActivityStack.ActivityState.FINISHING; |
| 61 | import static com.android.server.wm.ActivityStack.ActivityState.PAUSED; |
| 62 | import static com.android.server.wm.ActivityStack.ActivityState.PAUSING; |
| 63 | import static com.android.server.wm.ActivityStack.ActivityState.RESUMED; |
| 64 | import static com.android.server.wm.ActivityStack.ActivityState.STOPPED; |
| 65 | import static com.android.server.wm.ActivityStack.ActivityState.STOPPING; |
Wale Ogunwale | 5950709 | 2018-10-29 09:00:30 -0700 | [diff] [blame] | 66 | import static com.android.server.wm.ActivityStackSupervisor.PAUSE_IMMEDIATELY; |
| 67 | import static com.android.server.wm.ActivityStackSupervisor.PRESERVE_WINDOWS; |
| 68 | import static com.android.server.wm.ActivityStackSupervisor.REMOVE_FROM_RECENTS; |
Garfield Tan | 347bd60 | 2018-12-21 15:11:12 -0800 | [diff] [blame] | 69 | import static com.android.server.wm.ActivityStackSupervisor.dumpHistoryList; |
| 70 | import static com.android.server.wm.ActivityStackSupervisor.printThisActivity; |
Wale Ogunwale | 5950709 | 2018-10-29 09:00:30 -0700 | [diff] [blame] | 71 | import static com.android.server.wm.ActivityTaskManagerDebugConfig.DEBUG_ADD_REMOVE; |
| 72 | import static com.android.server.wm.ActivityTaskManagerDebugConfig.DEBUG_ALL; |
| 73 | import static com.android.server.wm.ActivityTaskManagerDebugConfig.DEBUG_APP; |
| 74 | import static com.android.server.wm.ActivityTaskManagerDebugConfig.DEBUG_CLEANUP; |
| 75 | import static com.android.server.wm.ActivityTaskManagerDebugConfig.DEBUG_CONTAINERS; |
| 76 | import static com.android.server.wm.ActivityTaskManagerDebugConfig.DEBUG_PAUSE; |
| 77 | import static com.android.server.wm.ActivityTaskManagerDebugConfig.DEBUG_RELEASE; |
| 78 | import static com.android.server.wm.ActivityTaskManagerDebugConfig.DEBUG_RESULTS; |
| 79 | import static com.android.server.wm.ActivityTaskManagerDebugConfig.DEBUG_SAVED_STATE; |
| 80 | import static com.android.server.wm.ActivityTaskManagerDebugConfig.DEBUG_STACK; |
| 81 | import static com.android.server.wm.ActivityTaskManagerDebugConfig.DEBUG_STATES; |
| 82 | import static com.android.server.wm.ActivityTaskManagerDebugConfig.DEBUG_SWITCH; |
| 83 | import static com.android.server.wm.ActivityTaskManagerDebugConfig.DEBUG_TASKS; |
| 84 | import static com.android.server.wm.ActivityTaskManagerDebugConfig.DEBUG_TRANSITION; |
| 85 | import static com.android.server.wm.ActivityTaskManagerDebugConfig.DEBUG_USER_LEAVING; |
| 86 | import static com.android.server.wm.ActivityTaskManagerDebugConfig.DEBUG_VISIBILITY; |
| 87 | import static com.android.server.wm.ActivityTaskManagerDebugConfig.POSTFIX_ADD_REMOVE; |
| 88 | import static com.android.server.wm.ActivityTaskManagerDebugConfig.POSTFIX_APP; |
| 89 | import static com.android.server.wm.ActivityTaskManagerDebugConfig.POSTFIX_CLEANUP; |
| 90 | import static com.android.server.wm.ActivityTaskManagerDebugConfig.POSTFIX_CONTAINERS; |
| 91 | import static com.android.server.wm.ActivityTaskManagerDebugConfig.POSTFIX_PAUSE; |
| 92 | import static com.android.server.wm.ActivityTaskManagerDebugConfig.POSTFIX_RELEASE; |
| 93 | import static com.android.server.wm.ActivityTaskManagerDebugConfig.POSTFIX_RESULTS; |
| 94 | import static com.android.server.wm.ActivityTaskManagerDebugConfig.POSTFIX_SAVED_STATE; |
| 95 | import static com.android.server.wm.ActivityTaskManagerDebugConfig.POSTFIX_STACK; |
| 96 | import static com.android.server.wm.ActivityTaskManagerDebugConfig.POSTFIX_STATES; |
| 97 | import static com.android.server.wm.ActivityTaskManagerDebugConfig.POSTFIX_SWITCH; |
| 98 | import static com.android.server.wm.ActivityTaskManagerDebugConfig.POSTFIX_TASKS; |
| 99 | import static com.android.server.wm.ActivityTaskManagerDebugConfig.POSTFIX_TRANSITION; |
| 100 | import static com.android.server.wm.ActivityTaskManagerDebugConfig.POSTFIX_USER_LEAVING; |
| 101 | import static com.android.server.wm.ActivityTaskManagerDebugConfig.POSTFIX_VISIBILITY; |
| 102 | import static com.android.server.wm.ActivityTaskManagerDebugConfig.TAG_ATM; |
| 103 | import static com.android.server.wm.ActivityTaskManagerDebugConfig.TAG_WITH_CLASS_NAME; |
| 104 | import static com.android.server.wm.ActivityTaskManagerService.H.FIRST_ACTIVITY_STACK_MSG; |
| 105 | import static com.android.server.wm.ActivityTaskManagerService.RELAUNCH_REASON_FREE_RESIZE; |
| 106 | import static com.android.server.wm.ActivityTaskManagerService.RELAUNCH_REASON_WINDOWING_MODE_RESIZE; |
Wale Ogunwale | d32da47 | 2018-11-16 07:19:28 -0800 | [diff] [blame] | 107 | import static com.android.server.wm.RootActivityContainer.FindTaskResult; |
Louis Chang | f2835df | 2018-10-17 15:14:45 +0800 | [diff] [blame] | 108 | |
Wale Ogunwale | c5cc301 | 2017-01-13 13:26:16 -0800 | [diff] [blame] | 109 | import static java.lang.Integer.MAX_VALUE; |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 110 | |
Andrii Kulian | 0c869cc | 2019-02-06 19:50:32 -0800 | [diff] [blame] | 111 | import android.annotation.IntDef; |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 112 | import android.app.Activity; |
Dianne Hackborn | 0c5001d | 2011-04-12 18:16:08 -0700 | [diff] [blame] | 113 | import android.app.ActivityManager; |
Wale Ogunwale | 5378374 | 2018-09-16 10:21:51 -0700 | [diff] [blame] | 114 | import android.app.ActivityManagerInternal; |
Dianne Hackborn | 7a2195c | 2012-03-19 17:38:00 -0700 | [diff] [blame] | 115 | import android.app.ActivityOptions; |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 116 | import android.app.AppGlobals; |
Craig Mautner | 05d6272ba | 2013-02-11 09:39:27 -0800 | [diff] [blame] | 117 | import android.app.IActivityController; |
Yunfan Chen | 279f558 | 2018-12-12 15:24:50 -0800 | [diff] [blame] | 118 | import android.app.RemoteAction; |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 119 | import android.app.ResultInfo; |
Winson Chung | 61c9e5a | 2017-10-11 10:39:32 -0700 | [diff] [blame] | 120 | import android.app.WindowConfiguration.ActivityType; |
| 121 | import android.app.WindowConfiguration.WindowingMode; |
Andrii Kulian | 446e824 | 2017-10-26 15:17:29 -0700 | [diff] [blame] | 122 | import android.app.servertransaction.ActivityResultItem; |
Andrii Kulian | 9956d89 | 2018-02-14 13:48:56 -0800 | [diff] [blame] | 123 | import android.app.servertransaction.ClientTransaction; |
Andrii Kulian | 446e824 | 2017-10-26 15:17:29 -0700 | [diff] [blame] | 124 | import android.app.servertransaction.DestroyActivityItem; |
Louis Chang | 7d0037c | 2018-08-13 12:42:06 +0800 | [diff] [blame] | 125 | import android.app.servertransaction.NewIntentItem; |
Andrii Kulian | 446e824 | 2017-10-26 15:17:29 -0700 | [diff] [blame] | 126 | import android.app.servertransaction.PauseActivityItem; |
| 127 | import android.app.servertransaction.ResumeActivityItem; |
| 128 | import android.app.servertransaction.StopActivityItem; |
Louis Chang | 7d0037c | 2018-08-13 12:42:06 +0800 | [diff] [blame] | 129 | import android.app.servertransaction.WindowVisibilityItem; |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 130 | import android.content.ComponentName; |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 131 | import android.content.Intent; |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 132 | import android.content.pm.ActivityInfo; |
Todd Kennedy | 39bfee5 | 2016-02-24 10:28:21 -0800 | [diff] [blame] | 133 | import android.content.pm.ApplicationInfo; |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 134 | import android.content.res.Configuration; |
Jorim Jaggi | af80db4 | 2016-04-07 19:19:15 -0700 | [diff] [blame] | 135 | import android.graphics.Rect; |
Santos Cordon | 73ff7d8 | 2013-03-06 17:24:11 -0800 | [diff] [blame] | 136 | import android.net.Uri; |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 137 | import android.os.Binder; |
Craig Mautner | 329f412 | 2013-11-07 09:10:42 -0800 | [diff] [blame] | 138 | import android.os.Debug; |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 139 | import android.os.Handler; |
| 140 | import android.os.IBinder; |
Zoran Marceta | f958b32 | 2012-08-09 20:27:12 +0900 | [diff] [blame] | 141 | import android.os.Looper; |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 142 | import android.os.Message; |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 143 | import android.os.RemoteException; |
| 144 | import android.os.SystemClock; |
Dianne Hackborn | f02b60a | 2012-08-16 10:48:27 -0700 | [diff] [blame] | 145 | import android.os.UserHandle; |
Craig Mautner | 4c07d02 | 2014-06-11 17:12:59 -0700 | [diff] [blame] | 146 | import android.service.voice.IVoiceInteractionSession; |
Jorim Jaggi | af80db4 | 2016-04-07 19:19:15 -0700 | [diff] [blame] | 147 | import android.util.ArraySet; |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 148 | import android.util.EventLog; |
Andrii Kulian | fb1bf69 | 2017-01-17 11:17:34 -0800 | [diff] [blame] | 149 | import android.util.IntArray; |
Jorim Jaggi | 023da53 | 2016-04-20 22:42:32 -0700 | [diff] [blame] | 150 | import android.util.Log; |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 151 | import android.util.Slog; |
Steven Timotius | 4346f0a | 2017-09-12 11:07:21 -0700 | [diff] [blame] | 152 | import android.util.proto.ProtoOutputStream; |
Craig Mautner | 59c0097 | 2012-07-30 12:10:24 -0700 | [diff] [blame] | 153 | import android.view.Display; |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 154 | |
Andreas Gampe | a36dc62 | 2018-02-05 17:19:22 -0800 | [diff] [blame] | 155 | import com.android.internal.annotations.GuardedBy; |
Bryce Lee | 840c566 | 2017-04-13 10:02:51 -0700 | [diff] [blame] | 156 | import com.android.internal.annotations.VisibleForTesting; |
Jorim Jaggi | af80db4 | 2016-04-07 19:19:15 -0700 | [diff] [blame] | 157 | import com.android.internal.app.IVoiceInteractor; |
Wale Ogunwale | 5378374 | 2018-09-16 10:21:51 -0700 | [diff] [blame] | 158 | import com.android.internal.util.function.pooled.PooledLambda; |
Jorim Jaggi | af80db4 | 2016-04-07 19:19:15 -0700 | [diff] [blame] | 159 | import com.android.server.Watchdog; |
Wale Ogunwale | 5950709 | 2018-10-29 09:00:30 -0700 | [diff] [blame] | 160 | import com.android.server.am.ActivityManagerService; |
Jorim Jaggi | af80db4 | 2016-04-07 19:19:15 -0700 | [diff] [blame] | 161 | import com.android.server.am.ActivityManagerService.ItemMatcher; |
Wale Ogunwale | 5950709 | 2018-10-29 09:00:30 -0700 | [diff] [blame] | 162 | import com.android.server.am.AppTimeTracker; |
| 163 | import com.android.server.am.EventLogTags; |
| 164 | import com.android.server.am.PendingIntentRecord; |
Jorim Jaggi | af80db4 | 2016-04-07 19:19:15 -0700 | [diff] [blame] | 165 | |
Craig Mautner | cae015f | 2013-02-08 14:31:27 -0800 | [diff] [blame] | 166 | import java.io.FileDescriptor; |
Craig Mautner | cae015f | 2013-02-08 14:31:27 -0800 | [diff] [blame] | 167 | import java.io.PrintWriter; |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 168 | import java.lang.ref.WeakReference; |
| 169 | import java.util.ArrayList; |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 170 | import java.util.List; |
Kenny Root | e6585b3 | 2013-12-13 12:00:26 -0800 | [diff] [blame] | 171 | import java.util.Objects; |
Wale Ogunwale | 540e123 | 2015-05-01 15:35:39 -0700 | [diff] [blame] | 172 | import java.util.Set; |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 173 | |
| 174 | /** |
| 175 | * State and management of a single stack of activities. |
| 176 | */ |
Yunfan Chen | 279f558 | 2018-12-12 15:24:50 -0800 | [diff] [blame] | 177 | class ActivityStack extends ConfigurationContainer { |
Wale Ogunwale | 9887561 | 2018-10-12 07:53:02 -0700 | [diff] [blame] | 178 | private static final String TAG = TAG_WITH_CLASS_NAME ? "ActivityStack" : TAG_ATM; |
Wale Ogunwale | 0fc365c | 2015-05-25 19:35:42 -0700 | [diff] [blame] | 179 | private static final String TAG_ADD_REMOVE = TAG + POSTFIX_ADD_REMOVE; |
| 180 | private static final String TAG_APP = TAG + POSTFIX_APP; |
Wale Ogunwale | e23149f | 2015-03-06 15:39:44 -0800 | [diff] [blame] | 181 | private static final String TAG_CLEANUP = TAG + POSTFIX_CLEANUP; |
Wale Ogunwale | 0fc365c | 2015-05-25 19:35:42 -0700 | [diff] [blame] | 182 | private static final String TAG_CONTAINERS = TAG + POSTFIX_CONTAINERS; |
Wale Ogunwale | ee006da | 2015-03-30 14:49:25 -0700 | [diff] [blame] | 183 | private static final String TAG_PAUSE = TAG + POSTFIX_PAUSE; |
Wale Ogunwale | 0fc365c | 2015-05-25 19:35:42 -0700 | [diff] [blame] | 184 | private static final String TAG_RELEASE = TAG + POSTFIX_RELEASE; |
Wale Ogunwale | ee006da | 2015-03-30 14:49:25 -0700 | [diff] [blame] | 185 | private static final String TAG_RESULTS = TAG + POSTFIX_RESULTS; |
Wale Ogunwale | 0fc365c | 2015-05-25 19:35:42 -0700 | [diff] [blame] | 186 | private static final String TAG_SAVED_STATE = TAG + POSTFIX_SAVED_STATE; |
Wale Ogunwale | ee006da | 2015-03-30 14:49:25 -0700 | [diff] [blame] | 187 | private static final String TAG_STACK = TAG + POSTFIX_STACK; |
Wale Ogunwale | 0fc365c | 2015-05-25 19:35:42 -0700 | [diff] [blame] | 188 | private static final String TAG_STATES = TAG + POSTFIX_STATES; |
Wale Ogunwale | ee006da | 2015-03-30 14:49:25 -0700 | [diff] [blame] | 189 | private static final String TAG_SWITCH = TAG + POSTFIX_SWITCH; |
| 190 | private static final String TAG_TASKS = TAG + POSTFIX_TASKS; |
| 191 | private static final String TAG_TRANSITION = TAG + POSTFIX_TRANSITION; |
| 192 | private static final String TAG_USER_LEAVING = TAG + POSTFIX_USER_LEAVING; |
| 193 | private static final String TAG_VISIBILITY = TAG + POSTFIX_VISIBILITY; |
Wale Ogunwale | 3ab9a27 | 2015-03-16 09:55:45 -0700 | [diff] [blame] | 194 | |
Dianne Hackborn | 2a29b3a | 2012-03-15 15:48:38 -0700 | [diff] [blame] | 195 | // Ticks during which we check progress while waiting for an app to launch. |
| 196 | static final int LAUNCH_TICK = 500; |
| 197 | |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 198 | // How long we wait until giving up on the last activity to pause. This |
| 199 | // is short because it directly impacts the responsiveness of starting the |
| 200 | // next activity. |
Andrii Kulian | 21713ac | 2016-10-12 22:05:05 -0700 | [diff] [blame] | 201 | private static final int PAUSE_TIMEOUT = 500; |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 202 | |
Dianne Hackborn | 162bc0e | 2012-04-09 14:06:16 -0700 | [diff] [blame] | 203 | // How long we wait for the activity to tell us it has stopped before |
| 204 | // giving up. This is a good amount of time because we really need this |
Robert Carr | 3406d46 | 2018-03-15 16:19:07 -0700 | [diff] [blame] | 205 | // from the application in order to get its saved state. Once the stop |
| 206 | // is complete we may start destroying client resources triggering |
| 207 | // crashes if the UI thread was hung. We put this timeout one second behind |
| 208 | // the ANR timeout so these situations will generate ANR instead of |
| 209 | // Surface lost or other errors. |
| 210 | private static final int STOP_TIMEOUT = 11 * 1000; |
Dianne Hackborn | 162bc0e | 2012-04-09 14:06:16 -0700 | [diff] [blame] | 211 | |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 212 | // How long we wait until giving up on an activity telling us it has |
| 213 | // finished destroying itself. |
Andrii Kulian | 21713ac | 2016-10-12 22:05:05 -0700 | [diff] [blame] | 214 | private static final int DESTROY_TIMEOUT = 10 * 1000; |
Craig Mautner | d74f7d7 | 2013-02-26 13:41:02 -0800 | [diff] [blame] | 215 | |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 216 | // Set to false to disable the preview that is shown while a new activity |
| 217 | // is being started. |
Andrii Kulian | 21713ac | 2016-10-12 22:05:05 -0700 | [diff] [blame] | 218 | private static final boolean SHOW_APP_STARTING_PREVIEW = true; |
Craig Mautner | 5d9c7be | 2013-02-15 14:02:56 -0800 | [diff] [blame] | 219 | |
Craig Mautner | 5eda9b3 | 2013-07-02 11:58:16 -0700 | [diff] [blame] | 220 | // How long to wait for all background Activities to redraw following a call to |
| 221 | // convertToTranslucent(). |
Andrii Kulian | 21713ac | 2016-10-12 22:05:05 -0700 | [diff] [blame] | 222 | private static final long TRANSLUCENT_CONVERSION_TIMEOUT = 2000; |
Craig Mautner | 5eda9b3 | 2013-07-02 11:58:16 -0700 | [diff] [blame] | 223 | |
Filip Gruszczynski | ef2f72b | 2015-12-04 14:52:25 -0800 | [diff] [blame] | 224 | // How many activities have to be scheduled to stop to force a stop pass. |
| 225 | private static final int MAX_STOPPING_TO_FORCE = 3; |
| 226 | |
Andrii Kulian | 0c869cc | 2019-02-06 19:50:32 -0800 | [diff] [blame] | 227 | @IntDef(prefix = {"STACK_VISIBILITY"}, value = { |
| 228 | STACK_VISIBILITY_VISIBLE, |
| 229 | STACK_VISIBILITY_VISIBLE_BEHIND_TRANSLUCENT, |
| 230 | STACK_VISIBILITY_INVISIBLE, |
| 231 | }) |
| 232 | @interface StackVisibility {} |
| 233 | |
| 234 | /** Stack is visible. No other stacks on top that fully or partially occlude it. */ |
| 235 | static final int STACK_VISIBILITY_VISIBLE = 0; |
| 236 | |
| 237 | /** Stack is partially occluded by other translucent stack(s) on top of it. */ |
| 238 | static final int STACK_VISIBILITY_VISIBLE_BEHIND_TRANSLUCENT = 1; |
| 239 | |
| 240 | /** Stack is completely invisible. */ |
| 241 | static final int STACK_VISIBILITY_INVISIBLE = 2; |
| 242 | |
Andrii Kulian | 1779e61 | 2016-10-12 21:58:25 -0700 | [diff] [blame] | 243 | @Override |
| 244 | protected int getChildCount() { |
| 245 | return mTaskHistory.size(); |
| 246 | } |
| 247 | |
| 248 | @Override |
Garfield Tan | b5cc09f | 2018-09-28 10:06:52 -0700 | [diff] [blame] | 249 | protected TaskRecord getChildAt(int index) { |
Andrii Kulian | 1779e61 | 2016-10-12 21:58:25 -0700 | [diff] [blame] | 250 | return mTaskHistory.get(index); |
| 251 | } |
| 252 | |
| 253 | @Override |
Evan Rosky | c5abbd8 | 2018-10-05 16:02:19 -0700 | [diff] [blame] | 254 | protected ActivityDisplay getParent() { |
Andrii Kulian | 94e82d9b0 | 2017-07-13 15:33:06 -0700 | [diff] [blame] | 255 | return getDisplay(); |
Andrii Kulian | 1779e61 | 2016-10-12 21:58:25 -0700 | [diff] [blame] | 256 | } |
| 257 | |
Evan Rosky | c5abbd8 | 2018-10-05 16:02:19 -0700 | [diff] [blame] | 258 | void setParent(ActivityDisplay parent) { |
| 259 | ActivityDisplay current = getParent(); |
| 260 | if (current != parent) { |
| 261 | mDisplayId = parent.mDisplayId; |
| 262 | onParentChanged(); |
| 263 | } |
| 264 | } |
| 265 | |
Andrii Kulian | fb1bf69 | 2017-01-17 11:17:34 -0800 | [diff] [blame] | 266 | @Override |
Wale Ogunwale | 98d6231 | 2017-07-12 09:24:56 -0700 | [diff] [blame] | 267 | protected void onParentChanged() { |
Evan Rosky | c5abbd8 | 2018-10-05 16:02:19 -0700 | [diff] [blame] | 268 | ActivityDisplay display = getParent(); |
| 269 | if (display != null) { |
| 270 | // Rotations are relative to the display. This means if there are 2 displays rotated |
| 271 | // differently (eg. 2 monitors with one landscape and one portrait), moving a stack |
| 272 | // from one to the other could look like a rotation change. To prevent this |
| 273 | // apparent rotation change (and corresponding bounds rotation), pretend like our |
| 274 | // current rotation is already the same as the new display. |
| 275 | // Note, if ActivityStack or related logic ever gets nested, this logic will need |
| 276 | // to move to onConfigurationChanged. |
| 277 | getConfiguration().windowConfiguration.setRotation( |
| 278 | display.getWindowConfiguration().getRotation()); |
| 279 | } |
Andrii Kulian | fb1bf69 | 2017-01-17 11:17:34 -0800 | [diff] [blame] | 280 | super.onParentChanged(); |
Evan Rosky | c5abbd8 | 2018-10-05 16:02:19 -0700 | [diff] [blame] | 281 | if (display != null && inSplitScreenPrimaryWindowingMode()) { |
| 282 | // If we created a docked stack we want to resize it so it resizes all other stacks |
| 283 | // in the system. |
| 284 | getStackDockedModeBounds(null, null, mTmpRect2, mTmpRect3); |
Evan Rosky | dfe3da7 | 2018-10-26 17:21:06 -0700 | [diff] [blame] | 285 | mStackSupervisor.resizeDockedStackLocked(getRequestedOverrideBounds(), mTmpRect2, |
| 286 | mTmpRect2, null, null, PRESERVE_WINDOWS); |
Evan Rosky | c5abbd8 | 2018-10-05 16:02:19 -0700 | [diff] [blame] | 287 | } |
Wale Ogunwale | d32da47 | 2018-11-16 07:19:28 -0800 | [diff] [blame] | 288 | mRootActivityContainer.updateUIDsPresentOnDisplay(); |
Andrii Kulian | fb1bf69 | 2017-01-17 11:17:34 -0800 | [diff] [blame] | 289 | } |
| 290 | |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 291 | enum ActivityState { |
| 292 | INITIALIZING, |
| 293 | RESUMED, |
| 294 | PAUSING, |
| 295 | PAUSED, |
| 296 | STOPPING, |
| 297 | STOPPED, |
| 298 | FINISHING, |
| 299 | DESTROYING, |
Riddle Hsu | 7b766fd | 2019-01-28 21:14:59 +0800 | [diff] [blame] | 300 | DESTROYED, |
| 301 | RESTARTING_PROCESS |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 302 | } |
| 303 | |
Bryce Lee | 840c566 | 2017-04-13 10:02:51 -0700 | [diff] [blame] | 304 | @VisibleForTesting |
Wale Ogunwale | 06579d6 | 2016-04-30 15:29:06 -0700 | [diff] [blame] | 305 | /* The various modes for the method {@link #removeTask}. */ |
| 306 | // Task is being completely removed from all stacks in the system. |
Bryce Lee | 840c566 | 2017-04-13 10:02:51 -0700 | [diff] [blame] | 307 | protected static final int REMOVE_TASK_MODE_DESTROYING = 0; |
Wale Ogunwale | 06579d6 | 2016-04-30 15:29:06 -0700 | [diff] [blame] | 308 | // Task is being removed from this stack so we can add it to another stack. In the case we are |
| 309 | // moving we don't want to perform some operations on the task like removing it from window |
| 310 | // manager or recents. |
| 311 | static final int REMOVE_TASK_MODE_MOVING = 1; |
| 312 | // Similar to {@link #REMOVE_TASK_MODE_MOVING} and the task will be added to the top of its new |
| 313 | // stack and the new stack will be on top of all stacks. |
Wale Ogunwale | 56d8d16 | 2017-05-30 11:12:20 -0700 | [diff] [blame] | 314 | static final int REMOVE_TASK_MODE_MOVING_TO_TOP = 2; |
Wale Ogunwale | 06579d6 | 2016-04-30 15:29:06 -0700 | [diff] [blame] | 315 | |
Wale Ogunwale | 5fa8a8c | 2018-05-08 13:43:21 -0700 | [diff] [blame] | 316 | final ActivityTaskManagerService mService; |
Yunfan Chen | 279f558 | 2018-12-12 15:24:50 -0800 | [diff] [blame] | 317 | final WindowManagerService mWindowManager; |
Craig Mautner | d74f7d7 | 2013-02-26 13:41:02 -0800 | [diff] [blame] | 318 | |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 319 | /** |
| 320 | * The back history of all previous (and possibly still |
Craig Mautner | 5d9c7be | 2013-02-15 14:02:56 -0800 | [diff] [blame] | 321 | * running) activities. It contains #TaskRecord objects. |
| 322 | */ |
Todd Kennedy | 39bfee5 | 2016-02-24 10:28:21 -0800 | [diff] [blame] | 323 | private final ArrayList<TaskRecord> mTaskHistory = new ArrayList<>(); |
Craig Mautner | 5d9c7be | 2013-02-15 14:02:56 -0800 | [diff] [blame] | 324 | |
| 325 | /** |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 326 | * List of running activities, sorted by recent usage. |
| 327 | * The first entry in the list is the least recently used. |
| 328 | * It contains HistoryRecord objects. |
| 329 | */ |
Garfield Tan | 347bd60 | 2018-12-21 15:11:12 -0800 | [diff] [blame] | 330 | private final ArrayList<ActivityRecord> mLRUActivities = new ArrayList<>(); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 331 | |
| 332 | /** |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 333 | * When we are in the process of pausing an activity, before starting the |
| 334 | * next one, this variable holds the activity that is currently being paused. |
| 335 | */ |
Dianne Hackborn | 621e2fe | 2012-02-16 17:07:33 -0800 | [diff] [blame] | 336 | ActivityRecord mPausingActivity = null; |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 337 | |
| 338 | /** |
| 339 | * This is the last activity that we put into the paused state. This is |
| 340 | * used to determine if we need to do an activity transition while sleeping, |
| 341 | * when we normally hold the top activity paused. |
| 342 | */ |
| 343 | ActivityRecord mLastPausedActivity = null; |
| 344 | |
| 345 | /** |
Craig Mautner | 0f92274 | 2013-08-06 08:44:42 -0700 | [diff] [blame] | 346 | * Activities that specify No History must be removed once the user navigates away from them. |
| 347 | * If the device goes to sleep with such an activity in the paused state then we save it here |
| 348 | * and finish it later if another activity replaces it on wakeup. |
| 349 | */ |
| 350 | ActivityRecord mLastNoHistoryActivity = null; |
| 351 | |
| 352 | /** |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 353 | * Current activity that is resumed, or null if there is none. |
| 354 | */ |
| 355 | ActivityRecord mResumedActivity = null; |
Craig Mautner | d74f7d7 | 2013-02-26 13:41:02 -0800 | [diff] [blame] | 356 | |
Craig Mautner | 5eda9b3 | 2013-07-02 11:58:16 -0700 | [diff] [blame] | 357 | // The topmost Activity passed to convertToTranslucent(). When non-null it means we are |
| 358 | // waiting for all Activities in mUndrawnActivitiesBelowTopTranslucent to be removed as they |
| 359 | // are drawn. When the last member of mUndrawnActivitiesBelowTopTranslucent is removed the |
| 360 | // Activity in mTranslucentActivityWaiting is notified via |
| 361 | // Activity.onTranslucentConversionComplete(false). If a timeout occurs prior to the last |
| 362 | // background activity being drawn then the same call will be made with a true value. |
| 363 | ActivityRecord mTranslucentActivityWaiting = null; |
Andrii Kulian | 21713ac | 2016-10-12 22:05:05 -0700 | [diff] [blame] | 364 | ArrayList<ActivityRecord> mUndrawnActivitiesBelowTopTranslucent = new ArrayList<>(); |
Craig Mautner | 5eda9b3 | 2013-07-02 11:58:16 -0700 | [diff] [blame] | 365 | |
Dianne Hackborn | 0dad364 | 2010-09-09 21:25:35 -0700 | [diff] [blame] | 366 | /** |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 367 | * Set when we know we are going to be calling updateConfiguration() |
| 368 | * soon, so want to skip intermediate config checks. |
| 369 | */ |
| 370 | boolean mConfigWillChange; |
| 371 | |
Winson Chung | 4790065 | 2017-04-06 18:44:25 -0700 | [diff] [blame] | 372 | /** |
| 373 | * When set, will force the stack to report as invisible. |
| 374 | */ |
| 375 | boolean mForceHidden = false; |
| 376 | |
Andrii Kulian | 6b32151 | 2019-01-23 06:37:00 +0000 | [diff] [blame] | 377 | /** |
| 378 | * Used to keep resumeTopActivityUncheckedLocked() from being entered recursively |
| 379 | */ |
| 380 | boolean mInResumeTopActivity = false; |
| 381 | |
Andrii Kulian | 21713ac | 2016-10-12 22:05:05 -0700 | [diff] [blame] | 382 | private boolean mUpdateBoundsDeferred; |
| 383 | private boolean mUpdateBoundsDeferredCalled; |
Evan Rosky | 1ac8446 | 2018-11-13 11:25:30 -0800 | [diff] [blame] | 384 | private boolean mUpdateDisplayedBoundsDeferredCalled; |
Andrii Kulian | 21713ac | 2016-10-12 22:05:05 -0700 | [diff] [blame] | 385 | private final Rect mDeferredBounds = new Rect(); |
Evan Rosky | 1ac8446 | 2018-11-13 11:25:30 -0800 | [diff] [blame] | 386 | private final Rect mDeferredDisplayedBounds = new Rect(); |
Jorim Jaggi | 192086e | 2016-03-11 17:17:03 +0100 | [diff] [blame] | 387 | |
Craig Mautner | 858d8a6 | 2013-04-23 17:08:34 -0700 | [diff] [blame] | 388 | int mCurrentUser; |
Amith Yamasani | 742a671 | 2011-05-04 14:49:28 -0700 | [diff] [blame] | 389 | |
Craig Mautner | c00204b | 2013-03-05 15:02:14 -0800 | [diff] [blame] | 390 | final int mStackId; |
Craig Mautner | e0a3884 | 2013-12-16 16:14:02 -0800 | [diff] [blame] | 391 | /** The attached Display's unique identifier, or -1 if detached */ |
| 392 | int mDisplayId; |
Craig Mautner | 4a1cb22 | 2013-12-04 16:14:06 -0800 | [diff] [blame] | 393 | |
Evan Rosky | 1047574 | 2018-09-05 19:02:48 -0700 | [diff] [blame] | 394 | /** Stores the override windowing-mode from before a transient mode change (eg. split) */ |
| 395 | private int mRestoreOverrideWindowingMode = WINDOWING_MODE_UNDEFINED; |
| 396 | |
Evan Rosky | c5abbd8 | 2018-10-05 16:02:19 -0700 | [diff] [blame] | 397 | private final Rect mTmpRect = new Rect(); |
Wale Ogunwale | 1666e31 | 2016-12-16 11:27:18 -0800 | [diff] [blame] | 398 | private final Rect mTmpRect2 = new Rect(); |
Evan Rosky | c5abbd8 | 2018-10-05 16:02:19 -0700 | [diff] [blame] | 399 | private final Rect mTmpRect3 = new Rect(); |
Wale Ogunwale | 30e441d | 2017-11-09 08:28:45 -0800 | [diff] [blame] | 400 | private final ActivityOptions mTmpOptions = ActivityOptions.makeBasic(); |
Andrii Kulian | 1e32e02 | 2016-09-16 15:29:34 -0700 | [diff] [blame] | 401 | |
Bryce Lee | fbd263b4 | 2018-03-07 10:33:55 -0800 | [diff] [blame] | 402 | /** List for processing through a set of activities */ |
| 403 | private final ArrayList<ActivityRecord> mTmpActivities = new ArrayList<>(); |
| 404 | |
Craig Mautner | 2708430 | 2013-03-25 08:05:25 -0700 | [diff] [blame] | 405 | /** Run all ActivityStacks through this */ |
Winson Chung | 5af42fc | 2017-03-24 17:11:33 -0700 | [diff] [blame] | 406 | protected final ActivityStackSupervisor mStackSupervisor; |
Wale Ogunwale | d32da47 | 2018-11-16 07:19:28 -0800 | [diff] [blame] | 407 | protected final RootActivityContainer mRootActivityContainer; |
Craig Mautner | 2708430 | 2013-03-25 08:05:25 -0700 | [diff] [blame] | 408 | |
Jorim Jaggi | fe76234 | 2016-10-13 14:33:27 +0200 | [diff] [blame] | 409 | private boolean mTopActivityOccludesKeyguard; |
| 410 | private ActivityRecord mTopDismissingKeyguardActivity; |
| 411 | |
Wale Ogunwale | 9887561 | 2018-10-12 07:53:02 -0700 | [diff] [blame] | 412 | static final int PAUSE_TIMEOUT_MSG = FIRST_ACTIVITY_STACK_MSG + 1; |
| 413 | static final int DESTROY_TIMEOUT_MSG = FIRST_ACTIVITY_STACK_MSG + 2; |
| 414 | static final int LAUNCH_TICK_MSG = FIRST_ACTIVITY_STACK_MSG + 3; |
| 415 | static final int STOP_TIMEOUT_MSG = FIRST_ACTIVITY_STACK_MSG + 4; |
| 416 | static final int DESTROY_ACTIVITIES_MSG = FIRST_ACTIVITY_STACK_MSG + 5; |
| 417 | static final int TRANSLUCENT_TIMEOUT_MSG = FIRST_ACTIVITY_STACK_MSG + 6; |
Dianne Hackborn | 755c8bf | 2012-05-07 15:06:09 -0700 | [diff] [blame] | 418 | |
Yunfan Chen | 279f558 | 2018-12-12 15:24:50 -0800 | [diff] [blame] | 419 | // TODO: remove after unification. |
| 420 | TaskStack mTaskStack; |
| 421 | |
Andrii Kulian | 21713ac | 2016-10-12 22:05:05 -0700 | [diff] [blame] | 422 | private static class ScheduleDestroyArgs { |
Wale Ogunwale | 9e4f3e0 | 2018-05-17 09:35:39 -0700 | [diff] [blame] | 423 | final WindowProcessController mOwner; |
Dianne Hackborn | 755c8bf | 2012-05-07 15:06:09 -0700 | [diff] [blame] | 424 | final String mReason; |
Wale Ogunwale | 9e4f3e0 | 2018-05-17 09:35:39 -0700 | [diff] [blame] | 425 | ScheduleDestroyArgs(WindowProcessController owner, String reason) { |
Dianne Hackborn | 755c8bf | 2012-05-07 15:06:09 -0700 | [diff] [blame] | 426 | mOwner = owner; |
Dianne Hackborn | 755c8bf | 2012-05-07 15:06:09 -0700 | [diff] [blame] | 427 | mReason = reason; |
| 428 | } |
| 429 | } |
| 430 | |
Zoran Marceta | f958b32 | 2012-08-09 20:27:12 +0900 | [diff] [blame] | 431 | final Handler mHandler; |
| 432 | |
Andrii Kulian | 21713ac | 2016-10-12 22:05:05 -0700 | [diff] [blame] | 433 | private class ActivityStackHandler extends Handler { |
Wale Ogunwale | e23149f | 2015-03-06 15:39:44 -0800 | [diff] [blame] | 434 | |
Craig Mautner | c8143c6 | 2013-09-03 12:15:57 -0700 | [diff] [blame] | 435 | ActivityStackHandler(Looper looper) { |
Zoran Marceta | f958b32 | 2012-08-09 20:27:12 +0900 | [diff] [blame] | 436 | super(looper); |
| 437 | } |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 438 | |
Zoran Marceta | f958b32 | 2012-08-09 20:27:12 +0900 | [diff] [blame] | 439 | @Override |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 440 | public void handleMessage(Message msg) { |
| 441 | switch (msg.what) { |
| 442 | case PAUSE_TIMEOUT_MSG: { |
Dianne Hackborn | be70785 | 2011-11-11 14:32:10 -0800 | [diff] [blame] | 443 | ActivityRecord r = (ActivityRecord)msg.obj; |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 444 | // We don't at this point know if the activity is fullscreen, |
| 445 | // so we need to be conservative and assume it isn't. |
Dianne Hackborn | be70785 | 2011-11-11 14:32:10 -0800 | [diff] [blame] | 446 | Slog.w(TAG, "Activity pause timeout for " + r); |
Wale Ogunwale | 5fa8a8c | 2018-05-08 13:43:21 -0700 | [diff] [blame] | 447 | synchronized (mService.mGlobalLock) { |
Wale Ogunwale | 9e4f3e0 | 2018-05-17 09:35:39 -0700 | [diff] [blame] | 448 | if (r.hasProcess()) { |
| 449 | mService.logAppTooSlow(r.app, r.pauseTime, "pausing " + r); |
Dianne Hackborn | 2a29b3a | 2012-03-15 15:48:38 -0700 | [diff] [blame] | 450 | } |
Dianne Hackborn | a4e102e | 2014-09-04 22:52:27 -0700 | [diff] [blame] | 451 | activityPausedLocked(r.appToken, true); |
Craig Mautner | d232895 | 2013-03-05 12:46:26 -0800 | [diff] [blame] | 452 | } |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 453 | } break; |
Dianne Hackborn | 2a29b3a | 2012-03-15 15:48:38 -0700 | [diff] [blame] | 454 | case LAUNCH_TICK_MSG: { |
| 455 | ActivityRecord r = (ActivityRecord)msg.obj; |
Wale Ogunwale | 5fa8a8c | 2018-05-08 13:43:21 -0700 | [diff] [blame] | 456 | synchronized (mService.mGlobalLock) { |
Dianne Hackborn | 2a29b3a | 2012-03-15 15:48:38 -0700 | [diff] [blame] | 457 | if (r.continueLaunchTickingLocked()) { |
Wale Ogunwale | 9e4f3e0 | 2018-05-17 09:35:39 -0700 | [diff] [blame] | 458 | mService.logAppTooSlow(r.app, r.launchTickTime, "launching " + r); |
Dianne Hackborn | 2a29b3a | 2012-03-15 15:48:38 -0700 | [diff] [blame] | 459 | } |
| 460 | } |
| 461 | } break; |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 462 | case DESTROY_TIMEOUT_MSG: { |
Dianne Hackborn | be70785 | 2011-11-11 14:32:10 -0800 | [diff] [blame] | 463 | ActivityRecord r = (ActivityRecord)msg.obj; |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 464 | // We don't at this point know if the activity is fullscreen, |
| 465 | // so we need to be conservative and assume it isn't. |
Dianne Hackborn | be70785 | 2011-11-11 14:32:10 -0800 | [diff] [blame] | 466 | Slog.w(TAG, "Activity destroy timeout for " + r); |
Wale Ogunwale | 5fa8a8c | 2018-05-08 13:43:21 -0700 | [diff] [blame] | 467 | synchronized (mService.mGlobalLock) { |
Craig Mautner | 299f960 | 2015-01-26 09:47:33 -0800 | [diff] [blame] | 468 | activityDestroyedLocked(r != null ? r.appToken : null, "destroyTimeout"); |
Craig Mautner | d232895 | 2013-03-05 12:46:26 -0800 | [diff] [blame] | 469 | } |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 470 | } break; |
Dianne Hackborn | 162bc0e | 2012-04-09 14:06:16 -0700 | [diff] [blame] | 471 | case STOP_TIMEOUT_MSG: { |
| 472 | ActivityRecord r = (ActivityRecord)msg.obj; |
| 473 | // We don't at this point know if the activity is fullscreen, |
| 474 | // so we need to be conservative and assume it isn't. |
| 475 | Slog.w(TAG, "Activity stop timeout for " + r); |
Wale Ogunwale | 5fa8a8c | 2018-05-08 13:43:21 -0700 | [diff] [blame] | 476 | synchronized (mService.mGlobalLock) { |
Dianne Hackborn | 162bc0e | 2012-04-09 14:06:16 -0700 | [diff] [blame] | 477 | if (r.isInHistory()) { |
Andrii Kulian | 21713ac | 2016-10-12 22:05:05 -0700 | [diff] [blame] | 478 | r.activityStoppedLocked(null /* icicle */, |
| 479 | null /* persistentState */, null /* description */); |
Dianne Hackborn | 162bc0e | 2012-04-09 14:06:16 -0700 | [diff] [blame] | 480 | } |
| 481 | } |
| 482 | } break; |
Dianne Hackborn | 755c8bf | 2012-05-07 15:06:09 -0700 | [diff] [blame] | 483 | case DESTROY_ACTIVITIES_MSG: { |
| 484 | ScheduleDestroyArgs args = (ScheduleDestroyArgs)msg.obj; |
Wale Ogunwale | 5fa8a8c | 2018-05-08 13:43:21 -0700 | [diff] [blame] | 485 | synchronized (mService.mGlobalLock) { |
Craig Mautner | ee2e45a | 2014-06-27 12:10:03 -0700 | [diff] [blame] | 486 | destroyActivitiesLocked(args.mOwner, args.mReason); |
Dianne Hackborn | 755c8bf | 2012-05-07 15:06:09 -0700 | [diff] [blame] | 487 | } |
Craig Mautner | 5eda9b3 | 2013-07-02 11:58:16 -0700 | [diff] [blame] | 488 | } break; |
| 489 | case TRANSLUCENT_TIMEOUT_MSG: { |
Wale Ogunwale | 5fa8a8c | 2018-05-08 13:43:21 -0700 | [diff] [blame] | 490 | synchronized (mService.mGlobalLock) { |
Craig Mautner | 5eda9b3 | 2013-07-02 11:58:16 -0700 | [diff] [blame] | 491 | notifyActivityDrawnLocked(null); |
| 492 | } |
| 493 | } break; |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 494 | } |
| 495 | } |
Craig Mautner | 4b71aa1 | 2012-12-27 17:20:01 -0800 | [diff] [blame] | 496 | } |
| 497 | |
Craig Mautner | 34b73df | 2014-01-12 21:11:08 -0800 | [diff] [blame] | 498 | int numActivities() { |
Craig Mautner | 000f002 | 2013-02-26 15:04:29 -0800 | [diff] [blame] | 499 | int count = 0; |
| 500 | for (int taskNdx = mTaskHistory.size() - 1; taskNdx >= 0; --taskNdx) { |
| 501 | count += mTaskHistory.get(taskNdx).mActivities.size(); |
| 502 | } |
| 503 | return count; |
| 504 | } |
| 505 | |
Wale Ogunwale | 9dcf946 | 2017-09-19 15:13:01 -0700 | [diff] [blame] | 506 | ActivityStack(ActivityDisplay display, int stackId, ActivityStackSupervisor supervisor, |
Wale Ogunwale | 04a05ac | 2017-09-17 21:35:02 -0700 | [diff] [blame] | 507 | int windowingMode, int activityType, boolean onTop) { |
Andrii Kulian | 94e82d9b0 | 2017-07-13 15:33:06 -0700 | [diff] [blame] | 508 | mStackSupervisor = supervisor; |
Wale Ogunwale | c9e57de | 2018-05-08 14:28:07 -0700 | [diff] [blame] | 509 | mService = supervisor.mService; |
Wale Ogunwale | d32da47 | 2018-11-16 07:19:28 -0800 | [diff] [blame] | 510 | mRootActivityContainer = mService.mRootActivityContainer; |
Wale Ogunwale | 5fa8a8c | 2018-05-08 13:43:21 -0700 | [diff] [blame] | 511 | mHandler = new ActivityStackHandler(supervisor.mLooper); |
Craig Mautner | 4a1cb22 | 2013-12-04 16:14:06 -0800 | [diff] [blame] | 512 | mWindowManager = mService.mWindowManager; |
Andrii Kulian | 94e82d9b0 | 2017-07-13 15:33:06 -0700 | [diff] [blame] | 513 | mStackId = stackId; |
Wale Ogunwale | 86b7446 | 2018-07-02 08:42:43 -0700 | [diff] [blame] | 514 | mCurrentUser = mService.mAmInternal.getCurrentUserId(); |
Wale Ogunwale | 1666e31 | 2016-12-16 11:27:18 -0800 | [diff] [blame] | 515 | mTmpRect2.setEmpty(); |
Andrii Kulian | 2fcc451 | 2018-01-25 16:39:27 -0800 | [diff] [blame] | 516 | // Set display id before setting activity and window type to make sure it won't affect |
| 517 | // stacks on a wrong display. |
| 518 | mDisplayId = display.mDisplayId; |
Wale Ogunwale | 04a05ac | 2017-09-17 21:35:02 -0700 | [diff] [blame] | 519 | setActivityType(activityType); |
Yunfan Chen | 279f558 | 2018-12-12 15:24:50 -0800 | [diff] [blame] | 520 | createTaskStack(display.mDisplayId, onTop, mTmpRect2); |
Evan Rosky | c5abbd8 | 2018-10-05 16:02:19 -0700 | [diff] [blame] | 521 | setWindowingMode(windowingMode, false /* animate */, false /* showRecents */, |
| 522 | false /* enteringSplitScreenMode */, false /* deferEnsuringVisibility */, |
| 523 | true /* creating */); |
| 524 | display.addChild(this, onTop ? POSITION_TOP : POSITION_BOTTOM); |
Wale Ogunwale | 1666e31 | 2016-12-16 11:27:18 -0800 | [diff] [blame] | 525 | } |
| 526 | |
Yunfan Chen | 279f558 | 2018-12-12 15:24:50 -0800 | [diff] [blame] | 527 | void createTaskStack(int displayId, boolean onTop, Rect outBounds) { |
| 528 | final DisplayContent dc = mWindowManager.mRoot.getDisplayContent(displayId); |
| 529 | if (dc == null) { |
| 530 | throw new IllegalArgumentException("Trying to add stackId=" + mStackId |
| 531 | + " to unknown displayId=" + displayId); |
| 532 | } |
| 533 | mTaskStack = new TaskStack(mWindowManager, mStackId, this); |
| 534 | dc.setStackOnDisplay(mStackId, onTop, mTaskStack); |
| 535 | if (mTaskStack.matchParentBounds()) { |
| 536 | outBounds.setEmpty(); |
| 537 | } else { |
| 538 | mTaskStack.getRawBounds(outBounds); |
| 539 | } |
Winson Chung | 5589333 | 2017-02-17 17:13:10 -0800 | [diff] [blame] | 540 | } |
| 541 | |
Yunfan Chen | 279f558 | 2018-12-12 15:24:50 -0800 | [diff] [blame] | 542 | TaskStack getTaskStack() { |
| 543 | return mTaskStack; |
Filip Gruszczynski | e5390e7 | 2015-08-18 16:39:00 -0700 | [diff] [blame] | 544 | } |
| 545 | |
Bryce Lee | c4ab62a | 2018-03-05 14:19:26 -0800 | [diff] [blame] | 546 | /** |
| 547 | * This should be called when an activity in a child task changes state. This should only |
| 548 | * be called from |
| 549 | * {@link TaskRecord#onActivityStateChanged(ActivityRecord, ActivityState, String)}. |
| 550 | * @param record The {@link ActivityRecord} whose state has changed. |
| 551 | * @param state The new state. |
| 552 | * @param reason The reason for the change. |
| 553 | */ |
| 554 | void onActivityStateChanged(ActivityRecord record, ActivityState state, String reason) { |
| 555 | if (record == mResumedActivity && state != RESUMED) { |
Bryce Lee | 84730a0 | 2018-04-03 14:10:04 -0700 | [diff] [blame] | 556 | setResumedActivity(null, reason + " - onActivityStateChanged"); |
Bryce Lee | c4ab62a | 2018-03-05 14:19:26 -0800 | [diff] [blame] | 557 | } |
| 558 | |
| 559 | if (state == RESUMED) { |
| 560 | if (DEBUG_STACK) Slog.v(TAG_STACK, "set resumed activity to:" + record + " reason:" |
| 561 | + reason); |
Bryce Lee | 84730a0 | 2018-04-03 14:10:04 -0700 | [diff] [blame] | 562 | setResumedActivity(record, reason + " - onActivityStateChanged"); |
Wale Ogunwale | d32da47 | 2018-11-16 07:19:28 -0800 | [diff] [blame] | 563 | if (record == mRootActivityContainer.getTopResumedActivity()) { |
Riddle Hsu | 3026e8d | 2018-08-03 15:50:53 +0800 | [diff] [blame] | 564 | // TODO(b/111361570): Support multiple focused apps in WM |
Andrii Kulian | ab132ee | 2018-07-24 22:10:21 +0800 | [diff] [blame] | 565 | mService.setResumedActivityUncheckLocked(record, reason); |
| 566 | } |
Wale Ogunwale | 8b19de9 | 2018-11-29 19:58:26 -0800 | [diff] [blame] | 567 | mStackSupervisor.mRecentTasks.add(record.getTaskRecord()); |
Bryce Lee | c4ab62a | 2018-03-05 14:19:26 -0800 | [diff] [blame] | 568 | } |
| 569 | } |
| 570 | |
Wale Ogunwale | a0f5b5e | 2017-10-11 09:37:23 -0700 | [diff] [blame] | 571 | @Override |
| 572 | public void onConfigurationChanged(Configuration newParentConfig) { |
| 573 | final int prevWindowingMode = getWindowingMode(); |
Kazuki Takise | 048e266 | 2018-06-27 17:05:11 +0900 | [diff] [blame] | 574 | final boolean prevIsAlwaysOnTop = isAlwaysOnTop(); |
Wale Ogunwale | a0f5b5e | 2017-10-11 09:37:23 -0700 | [diff] [blame] | 575 | final ActivityDisplay display = getDisplay(); |
Evan Rosky | c5abbd8 | 2018-10-05 16:02:19 -0700 | [diff] [blame] | 576 | final int prevRotation = getWindowConfiguration().getRotation(); |
| 577 | final int prevDensity = getConfiguration().densityDpi; |
| 578 | final int prevScreenW = getConfiguration().screenWidthDp; |
| 579 | final int prevScreenH = getConfiguration().screenHeightDp; |
Evan Rosky | e747c3e | 2018-10-30 20:06:41 -0700 | [diff] [blame] | 580 | |
Evan Rosky | c5abbd8 | 2018-10-05 16:02:19 -0700 | [diff] [blame] | 581 | getBounds(mTmpRect); // previous bounds |
Evan Rosky | e747c3e | 2018-10-30 20:06:41 -0700 | [diff] [blame] | 582 | |
| 583 | super.onConfigurationChanged(newParentConfig); |
Kazuki Takise | 048e266 | 2018-06-27 17:05:11 +0900 | [diff] [blame] | 584 | if (display == null) { |
Evan Rosky | c5abbd8 | 2018-10-05 16:02:19 -0700 | [diff] [blame] | 585 | return; |
| 586 | } |
Yunfan Chen | 279f558 | 2018-12-12 15:24:50 -0800 | [diff] [blame] | 587 | if (getTaskStack() == null) { |
| 588 | return; |
| 589 | } |
Evan Rosky | c5abbd8 | 2018-10-05 16:02:19 -0700 | [diff] [blame] | 590 | |
| 591 | // Update bounds if applicable |
| 592 | boolean hasNewOverrideBounds = false; |
| 593 | // Use override windowing mode to prevent extra bounds changes if inheriting the mode. |
Evan Rosky | dfe3da7 | 2018-10-26 17:21:06 -0700 | [diff] [blame] | 594 | if (getRequestedOverrideWindowingMode() == WINDOWING_MODE_PINNED) { |
Evan Rosky | c5abbd8 | 2018-10-05 16:02:19 -0700 | [diff] [blame] | 595 | // Pinned calculation already includes rotation |
| 596 | mTmpRect2.set(mTmpRect); |
Yunfan Chen | 279f558 | 2018-12-12 15:24:50 -0800 | [diff] [blame] | 597 | hasNewOverrideBounds = getTaskStack().calculatePinnedBoundsForConfigChange(mTmpRect2); |
Evan Rosky | c5abbd8 | 2018-10-05 16:02:19 -0700 | [diff] [blame] | 598 | } else { |
| 599 | final int newRotation = getWindowConfiguration().getRotation(); |
| 600 | if (!matchParentBounds()) { |
| 601 | // If the parent (display) has rotated, rotate our bounds to best-fit where their |
| 602 | // bounds were on the pre-rotated display. |
| 603 | if (prevRotation != newRotation) { |
| 604 | mTmpRect2.set(mTmpRect); |
Wale Ogunwale | 3a256e6 | 2018-12-06 14:41:18 -0800 | [diff] [blame] | 605 | getDisplay().mDisplayContent |
Evan Rosky | c5abbd8 | 2018-10-05 16:02:19 -0700 | [diff] [blame] | 606 | .rotateBounds(newParentConfig.windowConfiguration.getBounds(), |
| 607 | prevRotation, newRotation, mTmpRect2); |
| 608 | hasNewOverrideBounds = true; |
| 609 | } |
| 610 | |
| 611 | // If entering split screen or if something about the available split area changes, |
| 612 | // recalculate the split windows to match the new configuration. |
| 613 | if (prevRotation != newRotation |
| 614 | || prevDensity != getConfiguration().densityDpi |
| 615 | || prevWindowingMode != getWindowingMode() |
| 616 | || prevScreenW != getConfiguration().screenWidthDp |
| 617 | || prevScreenH != getConfiguration().screenHeightDp) { |
| 618 | // Use override windowing mode to prevent extra bounds changes if inheriting |
| 619 | // the mode. |
Evan Rosky | dfe3da7 | 2018-10-26 17:21:06 -0700 | [diff] [blame] | 620 | if (getRequestedOverrideWindowingMode() == WINDOWING_MODE_SPLIT_SCREEN_PRIMARY |
| 621 | || getRequestedOverrideWindowingMode() |
Evan Rosky | c5abbd8 | 2018-10-05 16:02:19 -0700 | [diff] [blame] | 622 | == WINDOWING_MODE_SPLIT_SCREEN_SECONDARY) { |
| 623 | mTmpRect2.set(mTmpRect); |
Yunfan Chen | 279f558 | 2018-12-12 15:24:50 -0800 | [diff] [blame] | 624 | getTaskStack() |
Evan Rosky | c5abbd8 | 2018-10-05 16:02:19 -0700 | [diff] [blame] | 625 | .calculateDockedBoundsForConfigChange(newParentConfig, mTmpRect2); |
| 626 | hasNewOverrideBounds = true; |
| 627 | } |
| 628 | } |
| 629 | } |
| 630 | } |
| 631 | if (getWindowingMode() != prevWindowingMode) { |
| 632 | // Use override windowing mode to prevent extra bounds changes if inheriting the mode. |
Evan Rosky | dfe3da7 | 2018-10-26 17:21:06 -0700 | [diff] [blame] | 633 | if (getRequestedOverrideWindowingMode() == WINDOWING_MODE_SPLIT_SCREEN_PRIMARY) { |
Evan Rosky | c5abbd8 | 2018-10-05 16:02:19 -0700 | [diff] [blame] | 634 | getStackDockedModeBounds(null, null, mTmpRect2, mTmpRect3); |
| 635 | // immediately resize so docked bounds are available in onSplitScreenModeActivated |
Evan Rosky | 1ac8446 | 2018-11-13 11:25:30 -0800 | [diff] [blame] | 636 | setTaskDisplayedBounds(null); |
| 637 | setTaskBounds(mTmpRect2); |
| 638 | setBounds(mTmpRect2); |
Evan Rosky | dfe3da7 | 2018-10-26 17:21:06 -0700 | [diff] [blame] | 639 | } else if ( |
| 640 | getRequestedOverrideWindowingMode() == WINDOWING_MODE_SPLIT_SCREEN_SECONDARY) { |
Evan Rosky | c5abbd8 | 2018-10-05 16:02:19 -0700 | [diff] [blame] | 641 | Rect dockedBounds = display.getSplitScreenPrimaryStack().getBounds(); |
Wale Ogunwale | 3a256e6 | 2018-12-06 14:41:18 -0800 | [diff] [blame] | 642 | final boolean isMinimizedDock = |
| 643 | getDisplay().mDisplayContent.getDockedDividerController().isMinimizedDock(); |
Evan Rosky | c5abbd8 | 2018-10-05 16:02:19 -0700 | [diff] [blame] | 644 | if (isMinimizedDock) { |
| 645 | TaskRecord topTask = display.getSplitScreenPrimaryStack().topTask(); |
| 646 | if (topTask != null) { |
| 647 | dockedBounds = topTask.getBounds(); |
| 648 | } |
| 649 | } |
| 650 | getStackDockedModeBounds(dockedBounds, null, mTmpRect2, mTmpRect3); |
| 651 | hasNewOverrideBounds = true; |
| 652 | } |
Kazuki Takise | 048e266 | 2018-06-27 17:05:11 +0900 | [diff] [blame] | 653 | } |
| 654 | if (prevWindowingMode != getWindowingMode()) { |
Wale Ogunwale | a0f5b5e | 2017-10-11 09:37:23 -0700 | [diff] [blame] | 655 | display.onStackWindowingModeChanged(this); |
| 656 | } |
Evan Rosky | c5abbd8 | 2018-10-05 16:02:19 -0700 | [diff] [blame] | 657 | if (hasNewOverrideBounds) { |
Wale Ogunwale | d32da47 | 2018-11-16 07:19:28 -0800 | [diff] [blame] | 658 | mRootActivityContainer.resizeStack(this, mTmpRect2, null, null, PRESERVE_WINDOWS, |
Evan Rosky | c5abbd8 | 2018-10-05 16:02:19 -0700 | [diff] [blame] | 659 | true /* allowResizeInDockedMode */, true /* deferResume */); |
Evan Rosky | e747c3e | 2018-10-30 20:06:41 -0700 | [diff] [blame] | 660 | } |
Kazuki Takise | 048e266 | 2018-06-27 17:05:11 +0900 | [diff] [blame] | 661 | if (prevIsAlwaysOnTop != isAlwaysOnTop()) { |
| 662 | // Since always on top is only on when the stack is freeform or pinned, the state |
| 663 | // can be toggled when the windowing mode changes. We must make sure the stack is |
| 664 | // placed properly when always on top state changes. |
Riddle Hsu | 57831b5 | 2018-07-27 00:31:48 +0800 | [diff] [blame] | 665 | display.positionChildAtTop(this, false /* includingParents */); |
Kazuki Takise | 048e266 | 2018-06-27 17:05:11 +0900 | [diff] [blame] | 666 | } |
Wale Ogunwale | a0f5b5e | 2017-10-11 09:37:23 -0700 | [diff] [blame] | 667 | } |
| 668 | |
Wale Ogunwale | ab5de37 | 2017-10-18 06:46:31 -0700 | [diff] [blame] | 669 | @Override |
Wale Ogunwale | 30e441d | 2017-11-09 08:28:45 -0800 | [diff] [blame] | 670 | public void setWindowingMode(int windowingMode) { |
Winson Chung | 3e36f82 | 2018-01-16 12:06:04 -0800 | [diff] [blame] | 671 | setWindowingMode(windowingMode, false /* animate */, false /* showRecents */, |
Evan Rosky | c5abbd8 | 2018-10-05 16:02:19 -0700 | [diff] [blame] | 672 | false /* enteringSplitScreenMode */, false /* deferEnsuringVisibility */, |
| 673 | false /* creating */); |
Wale Ogunwale | 30e441d | 2017-11-09 08:28:45 -0800 | [diff] [blame] | 674 | } |
| 675 | |
Evan Rosky | 1047574 | 2018-09-05 19:02:48 -0700 | [diff] [blame] | 676 | /** |
| 677 | * A transient windowing mode is one which activities enter into temporarily. Examples of this |
| 678 | * are Split window modes and pip. Non-transient modes are modes that displays can adopt. |
| 679 | * |
| 680 | * @param windowingMode the windowingMode to test for transient-ness. |
| 681 | * @return {@code true} if the windowing mode is transient, {@code false} otherwise. |
| 682 | */ |
| 683 | private static boolean isTransientWindowingMode(int windowingMode) { |
| 684 | // TODO(b/114842032): add PIP if/when it uses mode transitions instead of task reparenting |
| 685 | return windowingMode == WINDOWING_MODE_SPLIT_SCREEN_PRIMARY |
| 686 | || windowingMode == WINDOWING_MODE_SPLIT_SCREEN_SECONDARY; |
| 687 | } |
| 688 | |
| 689 | /** |
| 690 | * Specialization of {@link #setWindowingMode(int)} for this subclass. |
| 691 | * |
| 692 | * @param preferredWindowingMode the preferred windowing mode. This may not be honored depending |
| 693 | * on the state of things. For example, WINDOWING_MODE_UNDEFINED will resolve to the |
| 694 | * previous non-transient mode if this stack is currently in a transient mode. |
| 695 | * @param animate Can be used to prevent animation. |
| 696 | * @param showRecents Controls whether recents is shown on the other side of a split while |
| 697 | * entering split mode. |
| 698 | * @param enteringSplitScreenMode {@code true} if entering split mode. |
| 699 | * @param deferEnsuringVisibility Whether visibility updates are deferred. This is set when |
| 700 | * many operations (which can effect visibility) are being performed in bulk. |
Evan Rosky | c5abbd8 | 2018-10-05 16:02:19 -0700 | [diff] [blame] | 701 | * @param creating {@code true} if this is being run during ActivityStack construction. |
Evan Rosky | 1047574 | 2018-09-05 19:02:48 -0700 | [diff] [blame] | 702 | */ |
Wale Ogunwale | df262f5 | 2017-12-07 18:17:12 -0800 | [diff] [blame] | 703 | void setWindowingMode(int preferredWindowingMode, boolean animate, boolean showRecents, |
Evan Rosky | c5abbd8 | 2018-10-05 16:02:19 -0700 | [diff] [blame] | 704 | boolean enteringSplitScreenMode, boolean deferEnsuringVisibility, boolean creating) { |
Tiger Huang | 6dcbee6 | 2019-02-20 21:45:55 +0800 | [diff] [blame] | 705 | mWindowManager.inSurfaceTransaction(() -> setWindowingModeInSurfaceTransaction( |
| 706 | preferredWindowingMode, animate, showRecents, enteringSplitScreenMode, |
| 707 | deferEnsuringVisibility, creating)); |
| 708 | } |
| 709 | |
| 710 | private void setWindowingModeInSurfaceTransaction(int preferredWindowingMode, boolean animate, |
| 711 | boolean showRecents, boolean enteringSplitScreenMode, boolean deferEnsuringVisibility, |
| 712 | boolean creating) { |
Wale Ogunwale | 30e441d | 2017-11-09 08:28:45 -0800 | [diff] [blame] | 713 | final int currentMode = getWindowingMode(); |
Evan Rosky | dfe3da7 | 2018-10-26 17:21:06 -0700 | [diff] [blame] | 714 | final int currentOverrideMode = getRequestedOverrideWindowingMode(); |
Wale Ogunwale | 30e441d | 2017-11-09 08:28:45 -0800 | [diff] [blame] | 715 | final ActivityDisplay display = getDisplay(); |
| 716 | final TaskRecord topTask = topTask(); |
| 717 | final ActivityStack splitScreenStack = display.getSplitScreenPrimaryStack(); |
Evan Rosky | 9ba524e | 2018-01-03 16:27:56 -0800 | [diff] [blame] | 718 | int windowingMode = preferredWindowingMode; |
Evan Rosky | 1047574 | 2018-09-05 19:02:48 -0700 | [diff] [blame] | 719 | if (preferredWindowingMode == WINDOWING_MODE_UNDEFINED |
| 720 | && isTransientWindowingMode(currentMode)) { |
| 721 | // Leaving a transient mode. Interpret UNDEFINED as "restore" |
| 722 | windowingMode = mRestoreOverrideWindowingMode; |
| 723 | } |
| 724 | mTmpOptions.setLaunchWindowingMode(windowingMode); |
| 725 | |
Wale Ogunwale | 1dbc5c8 | 2017-12-08 08:12:20 -0800 | [diff] [blame] | 726 | // Need to make sure windowing mode is supported. If we in the process of creating the stack |
| 727 | // no need to resolve the windowing mode again as it is already resolved to the right mode. |
Evan Rosky | 9ba524e | 2018-01-03 16:27:56 -0800 | [diff] [blame] | 728 | if (!creating) { |
| 729 | windowingMode = display.validateWindowingMode(windowingMode, |
| 730 | null /* ActivityRecord */, topTask, getActivityType()); |
| 731 | } |
| 732 | if (splitScreenStack == this |
| 733 | && windowingMode == WINDOWING_MODE_SPLIT_SCREEN_SECONDARY) { |
| 734 | // Resolution to split-screen secondary for the primary split-screen stack means |
Evan Rosky | 1047574 | 2018-09-05 19:02:48 -0700 | [diff] [blame] | 735 | // we want to leave split-screen mode. |
| 736 | windowingMode = mRestoreOverrideWindowingMode; |
Wale Ogunwale | 30e441d | 2017-11-09 08:28:45 -0800 | [diff] [blame] | 737 | } |
| 738 | |
Wale Ogunwale | ac36e4d | 2017-11-29 13:30:26 -0800 | [diff] [blame] | 739 | final boolean alreadyInSplitScreenMode = display.hasSplitScreenPrimaryStack(); |
| 740 | |
Wale Ogunwale | 1dbc5c8 | 2017-12-08 08:12:20 -0800 | [diff] [blame] | 741 | // Don't send non-resizeable notifications if the windowing mode changed was a side effect |
| 742 | // of us entering split-screen mode. |
| 743 | final boolean sendNonResizeableNotification = !enteringSplitScreenMode; |
Wale Ogunwale | 30e441d | 2017-11-09 08:28:45 -0800 | [diff] [blame] | 744 | // Take any required action due to us not supporting the preferred windowing mode. |
Wale Ogunwale | 1dbc5c8 | 2017-12-08 08:12:20 -0800 | [diff] [blame] | 745 | if (alreadyInSplitScreenMode && windowingMode == WINDOWING_MODE_FULLSCREEN |
| 746 | && sendNonResizeableNotification && isActivityTypeStandardOrUndefined()) { |
| 747 | final boolean preferredSplitScreen = |
| 748 | preferredWindowingMode == WINDOWING_MODE_SPLIT_SCREEN_PRIMARY |
| 749 | || preferredWindowingMode == WINDOWING_MODE_SPLIT_SCREEN_SECONDARY; |
| 750 | if (preferredSplitScreen || creating) { |
| 751 | // Looks like we can't launch in split screen mode or the stack we are launching |
| 752 | // doesn't support split-screen mode, go ahead an dismiss split-screen and display a |
| 753 | // warning toast about it. |
Wale Ogunwale | 5fa8a8c | 2018-05-08 13:43:21 -0700 | [diff] [blame] | 754 | mService.getTaskChangeNotificationController().notifyActivityDismissingDockedStack(); |
Evan Rosky | c5abbd8 | 2018-10-05 16:02:19 -0700 | [diff] [blame] | 755 | final ActivityStack primarySplitStack = display.getSplitScreenPrimaryStack(); |
Tiger Huang | 6dcbee6 | 2019-02-20 21:45:55 +0800 | [diff] [blame] | 756 | primarySplitStack.setWindowingModeInSurfaceTransaction(WINDOWING_MODE_UNDEFINED, |
Andrii Kulian | 9da138a | 2018-04-24 17:12:44 -0700 | [diff] [blame] | 757 | false /* animate */, false /* showRecents */, |
Evan Rosky | c5abbd8 | 2018-10-05 16:02:19 -0700 | [diff] [blame] | 758 | false /* enteringSplitScreenMode */, true /* deferEnsuringVisibility */, |
| 759 | primarySplitStack == this ? creating : false); |
Wale Ogunwale | 30e441d | 2017-11-09 08:28:45 -0800 | [diff] [blame] | 760 | } |
| 761 | } |
| 762 | |
| 763 | if (currentMode == windowingMode) { |
Evan Rosky | 1047574 | 2018-09-05 19:02:48 -0700 | [diff] [blame] | 764 | // You are already in the window mode, so we can skip most of the work below. However, |
| 765 | // it's possible that we have inherited the current windowing mode from a parent. So, |
| 766 | // fulfill this method's contract by setting the override mode directly. |
Evan Rosky | dfe3da7 | 2018-10-26 17:21:06 -0700 | [diff] [blame] | 767 | getRequestedOverrideConfiguration().windowConfiguration.setWindowingMode(windowingMode); |
Wale Ogunwale | 30e441d | 2017-11-09 08:28:45 -0800 | [diff] [blame] | 768 | return; |
| 769 | } |
| 770 | |
| 771 | final WindowManagerService wm = mService.mWindowManager; |
| 772 | final ActivityRecord topActivity = getTopActivity(); |
| 773 | |
Evan Rosky | 1047574 | 2018-09-05 19:02:48 -0700 | [diff] [blame] | 774 | // For now, assume that the Stack's windowing mode is what will actually be used |
| 775 | // by it's activities. In the future, there may be situations where this doesn't |
| 776 | // happen; so at that point, this message will need to handle that. |
| 777 | int likelyResolvedMode = windowingMode; |
| 778 | if (windowingMode == WINDOWING_MODE_UNDEFINED) { |
| 779 | final ConfigurationContainer parent = getParent(); |
| 780 | likelyResolvedMode = parent != null ? parent.getWindowingMode() |
| 781 | : WINDOWING_MODE_FULLSCREEN; |
| 782 | } |
| 783 | if (sendNonResizeableNotification && likelyResolvedMode != WINDOWING_MODE_FULLSCREEN |
Wale Ogunwale | df262f5 | 2017-12-07 18:17:12 -0800 | [diff] [blame] | 784 | && topActivity != null && topActivity.isNonResizableOrForcedResizable() |
| 785 | && !topActivity.noDisplay) { |
Wale Ogunwale | 30e441d | 2017-11-09 08:28:45 -0800 | [diff] [blame] | 786 | // Inform the user that they are starting an app that may not work correctly in |
| 787 | // multi-window mode. |
| 788 | final String packageName = topActivity.appInfo.packageName; |
Wale Ogunwale | 5fa8a8c | 2018-05-08 13:43:21 -0700 | [diff] [blame] | 789 | mService.getTaskChangeNotificationController().notifyActivityForcedResizable( |
Wale Ogunwale | 30e441d | 2017-11-09 08:28:45 -0800 | [diff] [blame] | 790 | topTask.taskId, FORCED_RESIZEABLE_REASON_SPLIT_SCREEN, packageName); |
| 791 | } |
| 792 | |
| 793 | wm.deferSurfaceLayout(); |
| 794 | try { |
| 795 | if (!animate && topActivity != null) { |
Jorim Jaggi | fa9ed96 | 2018-01-25 00:16:49 +0100 | [diff] [blame] | 796 | mStackSupervisor.mNoAnimActivities.add(topActivity); |
Wale Ogunwale | 30e441d | 2017-11-09 08:28:45 -0800 | [diff] [blame] | 797 | } |
| 798 | super.setWindowingMode(windowingMode); |
Evan Rosky | 7d0705f | 2018-07-30 12:30:13 -0700 | [diff] [blame] | 799 | // setWindowingMode triggers an onConfigurationChanged cascade which can result in a |
| 800 | // different resolved windowing mode (usually when preferredWindowingMode is UNDEFINED). |
Evan Rosky | 9ba524e | 2018-01-03 16:27:56 -0800 | [diff] [blame] | 801 | windowingMode = getWindowingMode(); |
Wale Ogunwale | 30e441d | 2017-11-09 08:28:45 -0800 | [diff] [blame] | 802 | |
Wale Ogunwale | 1dbc5c8 | 2017-12-08 08:12:20 -0800 | [diff] [blame] | 803 | if (creating) { |
Wale Ogunwale | 30e441d | 2017-11-09 08:28:45 -0800 | [diff] [blame] | 804 | // Nothing else to do if we don't have a window container yet. E.g. call from ctor. |
| 805 | return; |
| 806 | } |
| 807 | |
| 808 | if (windowingMode == WINDOWING_MODE_PINNED || currentMode == WINDOWING_MODE_PINNED) { |
| 809 | // TODO: Need to remove use of PinnedActivityStack for this to be supported. |
| 810 | // NOTE: Need to ASS.scheduleUpdatePictureInPictureModeIfNeeded() in |
| 811 | // setWindowModeUnchecked() when this support is added. See TaskRecord.reparent() |
| 812 | throw new IllegalArgumentException( |
| 813 | "Changing pinned windowing mode not currently supported"); |
| 814 | } |
| 815 | |
| 816 | if (windowingMode == WINDOWING_MODE_SPLIT_SCREEN_PRIMARY && splitScreenStack != null) { |
| 817 | // We already have a split-screen stack in this display, so just move the tasks over. |
| 818 | // TODO: Figure-out how to do all the stuff in |
| 819 | // AMS.setTaskWindowingModeSplitScreenPrimary |
| 820 | throw new IllegalArgumentException("Setting primary split-screen windowing mode" |
| 821 | + " while there is already one isn't currently supported"); |
| 822 | //return; |
| 823 | } |
Evan Rosky | 1047574 | 2018-09-05 19:02:48 -0700 | [diff] [blame] | 824 | if (isTransientWindowingMode(windowingMode) && !isTransientWindowingMode(currentMode)) { |
| 825 | mRestoreOverrideWindowingMode = currentOverrideMode; |
| 826 | } |
Wale Ogunwale | 30e441d | 2017-11-09 08:28:45 -0800 | [diff] [blame] | 827 | |
| 828 | mTmpRect2.setEmpty(); |
| 829 | if (windowingMode != WINDOWING_MODE_FULLSCREEN) { |
Yunfan Chen | 279f558 | 2018-12-12 15:24:50 -0800 | [diff] [blame] | 830 | if (mTaskStack.matchParentBounds()) { |
| 831 | mTmpRect2.setEmpty(); |
| 832 | } else { |
| 833 | mTaskStack.getRawBounds(mTmpRect2); |
| 834 | } |
Wale Ogunwale | 30e441d | 2017-11-09 08:28:45 -0800 | [diff] [blame] | 835 | } |
| 836 | |
Evan Rosky | dfe3da7 | 2018-10-26 17:21:06 -0700 | [diff] [blame] | 837 | if (!Objects.equals(getRequestedOverrideBounds(), mTmpRect2)) { |
Wale Ogunwale | 30e441d | 2017-11-09 08:28:45 -0800 | [diff] [blame] | 838 | resize(mTmpRect2, null /* tempTaskBounds */, null /* tempTaskInsetBounds */); |
| 839 | } |
| 840 | } finally { |
Wale Ogunwale | c59b4f6 | 2017-11-30 11:05:43 -0800 | [diff] [blame] | 841 | if (showRecents && !alreadyInSplitScreenMode && mDisplayId == DEFAULT_DISPLAY |
Wale Ogunwale | 30e441d | 2017-11-09 08:28:45 -0800 | [diff] [blame] | 842 | && windowingMode == WINDOWING_MODE_SPLIT_SCREEN_PRIMARY) { |
| 843 | // Make sure recents stack exist when creating a dock stack as it normally needs to |
| 844 | // be on the other side of the docked stack and we make visibility decisions based |
| 845 | // on that. |
| 846 | // TODO: This is only here to help out with the case where recents stack doesn't |
| 847 | // exist yet. For that case the initial size of the split-screen stack will be the |
| 848 | // the one where the home stack is visible since recents isn't visible yet, but the |
| 849 | // divider will be off. I think we should just make the initial bounds that of home |
| 850 | // so that the divider matches and remove this logic. |
Winson Chung | c167427 | 2018-02-21 10:15:17 -0800 | [diff] [blame] | 851 | // TODO: This is currently only called when entering split-screen while in another |
| 852 | // task, and from the tests |
Matthew Ng | 3030712 | 2018-04-13 11:36:34 -0700 | [diff] [blame] | 853 | // TODO (b/78247419): Check if launcher and overview are same then move home stack |
| 854 | // instead of recents stack. Then fix the rotation animation from fullscreen to |
| 855 | // minimized mode |
Wale Ogunwale | 1dbc5c8 | 2017-12-08 08:12:20 -0800 | [diff] [blame] | 856 | final ActivityStack recentStack = display.getOrCreateStack( |
| 857 | WINDOWING_MODE_SPLIT_SCREEN_SECONDARY, ACTIVITY_TYPE_RECENTS, |
| 858 | true /* onTop */); |
| 859 | recentStack.moveToFront("setWindowingMode"); |
Wale Ogunwale | 30e441d | 2017-11-09 08:28:45 -0800 | [diff] [blame] | 860 | // If task moved to docked stack - show recents if needed. |
Winson Chung | dff7a73 | 2017-12-11 12:17:06 -0800 | [diff] [blame] | 861 | mService.mWindowManager.showRecentApps(); |
Wale Ogunwale | 30e441d | 2017-11-09 08:28:45 -0800 | [diff] [blame] | 862 | } |
| 863 | wm.continueSurfaceLayout(); |
| 864 | } |
| 865 | |
Andrii Kulian | 9da138a | 2018-04-24 17:12:44 -0700 | [diff] [blame] | 866 | if (!deferEnsuringVisibility) { |
Wale Ogunwale | d32da47 | 2018-11-16 07:19:28 -0800 | [diff] [blame] | 867 | mRootActivityContainer.ensureActivitiesVisible(null, 0, PRESERVE_WINDOWS); |
| 868 | mRootActivityContainer.resumeFocusedStacksTopActivities(); |
Wale Ogunwale | 1dbc5c8 | 2017-12-08 08:12:20 -0800 | [diff] [blame] | 869 | } |
Wale Ogunwale | 30e441d | 2017-11-09 08:28:45 -0800 | [diff] [blame] | 870 | } |
| 871 | |
| 872 | @Override |
Wale Ogunwale | ab5de37 | 2017-10-18 06:46:31 -0700 | [diff] [blame] | 873 | public boolean isCompatible(int windowingMode, int activityType) { |
| 874 | // TODO: Should we just move this to ConfigurationContainer? |
| 875 | if (activityType == ACTIVITY_TYPE_UNDEFINED) { |
| 876 | // Undefined activity types end up in a standard stack once the stack is created on a |
| 877 | // display, so they should be considered compatible. |
| 878 | activityType = ACTIVITY_TYPE_STANDARD; |
| 879 | } |
Wale Ogunwale | ab5de37 | 2017-10-18 06:46:31 -0700 | [diff] [blame] | 880 | return super.isCompatible(windowingMode, activityType); |
| 881 | } |
| 882 | |
Andrii Kulian | 839def9 | 2016-11-02 10:58:58 -0700 | [diff] [blame] | 883 | /** Adds the stack to specified display and calls WindowManager to do the same. */ |
Riddle Hsu | 402b440 | 2018-11-06 17:23:15 +0800 | [diff] [blame] | 884 | void reparent(ActivityDisplay activityDisplay, boolean onTop, boolean displayRemoved) { |
Wale Ogunwale | 7e1f5f5 | 2017-10-18 15:19:59 -0700 | [diff] [blame] | 885 | // TODO: We should probably resolve the windowing mode for the stack on the new display here |
| 886 | // so that it end up in a compatible mode in the new display. e.g. split-screen secondary. |
Wale Ogunwale | 1666e31 | 2016-12-16 11:27:18 -0800 | [diff] [blame] | 887 | removeFromDisplay(); |
Winson Chung | f34c602 | 2018-01-25 09:44:30 -0800 | [diff] [blame] | 888 | // Reparent the window container before we try to update the position when adding it to |
| 889 | // the new display below |
Wale Ogunwale | 1666e31 | 2016-12-16 11:27:18 -0800 | [diff] [blame] | 890 | mTmpRect2.setEmpty(); |
Yunfan Chen | 279f558 | 2018-12-12 15:24:50 -0800 | [diff] [blame] | 891 | if (mTaskStack == null) { |
| 892 | // TODO: Remove after unification. |
| 893 | Log.w(TAG, "Task stack is not valid when reparenting."); |
| 894 | } else { |
| 895 | mTaskStack.reparent(activityDisplay.mDisplayId, mTmpRect2, onTop); |
| 896 | } |
Evan Rosky | c5abbd8 | 2018-10-05 16:02:19 -0700 | [diff] [blame] | 897 | setBounds(mTmpRect2.isEmpty() ? null : mTmpRect2); |
| 898 | activityDisplay.addChild(this, onTop ? POSITION_TOP : POSITION_BOTTOM); |
Riddle Hsu | 402b440 | 2018-11-06 17:23:15 +0800 | [diff] [blame] | 899 | if (!displayRemoved) { |
| 900 | postReparent(); |
| 901 | } |
| 902 | } |
| 903 | |
| 904 | /** Resume next focusable stack after reparenting to another display. */ |
| 905 | void postReparent() { |
Wale Ogunwale | 66e1685 | 2017-10-19 13:35:52 -0700 | [diff] [blame] | 906 | adjustFocusToNextFocusableStack("reparent", true /* allowFocusSelf */); |
Wale Ogunwale | d32da47 | 2018-11-16 07:19:28 -0800 | [diff] [blame] | 907 | mRootActivityContainer.resumeFocusedStacksTopActivities(); |
Andrii Kulian | 51c1b67 | 2017-04-07 18:39:32 -0700 | [diff] [blame] | 908 | // Update visibility of activities before notifying WM. This way it won't try to resize |
| 909 | // windows that are no longer visible. |
Wale Ogunwale | d32da47 | 2018-11-16 07:19:28 -0800 | [diff] [blame] | 910 | mRootActivityContainer.ensureActivitiesVisible(null /* starting */, 0 /* configChanges */, |
Andrii Kulian | 51c1b67 | 2017-04-07 18:39:32 -0700 | [diff] [blame] | 911 | !PRESERVE_WINDOWS); |
Andrii Kulian | 839def9 | 2016-11-02 10:58:58 -0700 | [diff] [blame] | 912 | } |
| 913 | |
| 914 | /** |
Andrii Kulian | 839def9 | 2016-11-02 10:58:58 -0700 | [diff] [blame] | 915 | * Updates the inner state of the stack to remove it from its current parent, so it can be |
| 916 | * either destroyed completely or re-parented. |
| 917 | */ |
| 918 | private void removeFromDisplay() { |
Wale Ogunwale | 9dcf946 | 2017-09-19 15:13:01 -0700 | [diff] [blame] | 919 | final ActivityDisplay display = getDisplay(); |
| 920 | if (display != null) { |
| 921 | display.removeChild(this); |
| 922 | } |
| 923 | mDisplayId = INVALID_DISPLAY; |
Andrii Kulian | 839def9 | 2016-11-02 10:58:58 -0700 | [diff] [blame] | 924 | } |
| 925 | |
| 926 | /** Removes the stack completely. Also calls WindowManager to do the same on its side. */ |
| 927 | void remove() { |
| 928 | removeFromDisplay(); |
Yunfan Chen | 279f558 | 2018-12-12 15:24:50 -0800 | [diff] [blame] | 929 | if (mTaskStack != null) { |
| 930 | mTaskStack.removeIfPossible(); |
| 931 | mTaskStack = null; |
| 932 | } |
Andrii Kulian | 6d6fb40 | 2016-10-26 16:15:25 -0700 | [diff] [blame] | 933 | onParentChanged(); |
Filip Gruszczynski | e5390e7 | 2015-08-18 16:39:00 -0700 | [diff] [blame] | 934 | } |
| 935 | |
Wale Ogunwale | 9dcf946 | 2017-09-19 15:13:01 -0700 | [diff] [blame] | 936 | ActivityDisplay getDisplay() { |
Wale Ogunwale | d32da47 | 2018-11-16 07:19:28 -0800 | [diff] [blame] | 937 | return mRootActivityContainer.getActivityDisplay(mDisplayId); |
Andrii Kulian | 94e82d9b0 | 2017-07-13 15:33:06 -0700 | [diff] [blame] | 938 | } |
| 939 | |
Matthew Ng | aa2b620 | 2017-02-10 14:48:21 -0800 | [diff] [blame] | 940 | /** |
Evan Rosky | c5abbd8 | 2018-10-05 16:02:19 -0700 | [diff] [blame] | 941 | * @see #getStackDockedModeBounds(Rect, Rect, Rect, Rect) |
Matthew Ng | aa2b620 | 2017-02-10 14:48:21 -0800 | [diff] [blame] | 942 | */ |
Evan Rosky | c5abbd8 | 2018-10-05 16:02:19 -0700 | [diff] [blame] | 943 | void getStackDockedModeBounds(Rect dockedBounds, Rect currentTempTaskBounds, |
| 944 | Rect outStackBounds, Rect outTempTaskBounds) { |
Yunfan Chen | 279f558 | 2018-12-12 15:24:50 -0800 | [diff] [blame] | 945 | if (mTaskStack != null) { |
| 946 | mTaskStack.getStackDockedModeBoundsLocked(getParent().getConfiguration(), dockedBounds, |
| 947 | currentTempTaskBounds, outStackBounds, outTempTaskBounds); |
| 948 | } else { |
| 949 | outStackBounds.setEmpty(); |
| 950 | outTempTaskBounds.setEmpty(); |
| 951 | } |
Wale Ogunwale | 1666e31 | 2016-12-16 11:27:18 -0800 | [diff] [blame] | 952 | } |
| 953 | |
| 954 | void prepareFreezingTaskBounds() { |
Yunfan Chen | 279f558 | 2018-12-12 15:24:50 -0800 | [diff] [blame] | 955 | if (mTaskStack != null) { |
| 956 | // TODO: This cannot be false after unification. |
| 957 | mTaskStack.prepareFreezingTaskBounds(); |
| 958 | } |
Wale Ogunwale | 1666e31 | 2016-12-16 11:27:18 -0800 | [diff] [blame] | 959 | } |
| 960 | |
Wale Ogunwale | 1666e31 | 2016-12-16 11:27:18 -0800 | [diff] [blame] | 961 | void getWindowContainerBounds(Rect outBounds) { |
Yunfan Chen | 279f558 | 2018-12-12 15:24:50 -0800 | [diff] [blame] | 962 | if (mTaskStack != null) { |
| 963 | mTaskStack.getBounds(outBounds); |
Winson Chung | b00dc5e | 2017-01-25 09:44:25 -0800 | [diff] [blame] | 964 | return; |
Wale Ogunwale | 1666e31 | 2016-12-16 11:27:18 -0800 | [diff] [blame] | 965 | } |
| 966 | outBounds.setEmpty(); |
| 967 | } |
| 968 | |
Wale Ogunwale | 1666e31 | 2016-12-16 11:27:18 -0800 | [diff] [blame] | 969 | void positionChildWindowContainerAtTop(TaskRecord child) { |
Yunfan Chen | 279f558 | 2018-12-12 15:24:50 -0800 | [diff] [blame] | 970 | if (mTaskStack != null) { |
| 971 | // TODO: Remove after unification. This cannot be false after that. |
| 972 | mTaskStack.positionChildAtTop(child.getTask(), true /* includingParents */); |
| 973 | } |
Wale Ogunwale | 1666e31 | 2016-12-16 11:27:18 -0800 | [diff] [blame] | 974 | } |
| 975 | |
Riddle Hsu | 86cb7de | 2018-08-13 23:29:58 +0800 | [diff] [blame] | 976 | void positionChildWindowContainerAtBottom(TaskRecord child) { |
Riddle Hsu | 138ef93 | 2018-10-26 17:12:06 +0800 | [diff] [blame] | 977 | // If there are other focusable stacks on the display, the z-order of the display should not |
| 978 | // be changed just because a task was placed at the bottom. E.g. if it is moving the topmost |
| 979 | // task to bottom, the next focusable stack on the same display should be focused. |
| 980 | final ActivityStack nextFocusableStack = getDisplay().getNextFocusableStack( |
| 981 | child.getStack(), true /* ignoreCurrent */); |
Yunfan Chen | 279f558 | 2018-12-12 15:24:50 -0800 | [diff] [blame] | 982 | if (mTaskStack != null) { |
| 983 | // TODO: Remove after unification. This cannot be false after that. |
| 984 | mTaskStack.positionChildAtBottom(child.getTask(), |
| 985 | nextFocusableStack == null /* includingParents */); |
| 986 | } |
Riddle Hsu | 86cb7de | 2018-08-13 23:29:58 +0800 | [diff] [blame] | 987 | } |
| 988 | |
Jorim Jaggi | 192086e | 2016-03-11 17:17:03 +0100 | [diff] [blame] | 989 | /** |
Winson Chung | 8bca9e4 | 2017-04-16 15:59:43 -0700 | [diff] [blame] | 990 | * Returns whether to defer the scheduling of the multi-window mode. |
| 991 | */ |
| 992 | boolean deferScheduleMultiWindowModeChanged() { |
Yunfan Chen | 279f558 | 2018-12-12 15:24:50 -0800 | [diff] [blame] | 993 | if (inPinnedWindowingMode()) { |
| 994 | // For the pinned stack, the deferring of the multi-window mode changed is tied to the |
| 995 | // transition animation into picture-in-picture, and is called once the animation |
| 996 | // completes, or is interrupted in a way that would leave the stack in a non-fullscreen |
| 997 | // state. |
| 998 | // @see BoundsAnimationController |
| 999 | // @see BoundsAnimationControllerTests |
| 1000 | if (getTaskStack() == null) return false; |
| 1001 | return getTaskStack().deferScheduleMultiWindowModeChanged(); |
| 1002 | } |
Winson Chung | 8bca9e4 | 2017-04-16 15:59:43 -0700 | [diff] [blame] | 1003 | return false; |
| 1004 | } |
| 1005 | |
| 1006 | /** |
Jorim Jaggi | 192086e | 2016-03-11 17:17:03 +0100 | [diff] [blame] | 1007 | * Defers updating the bounds of the stack. If the stack was resized/repositioned while |
| 1008 | * deferring, the bounds will update in {@link #continueUpdateBounds()}. |
| 1009 | */ |
| 1010 | void deferUpdateBounds() { |
| 1011 | if (!mUpdateBoundsDeferred) { |
| 1012 | mUpdateBoundsDeferred = true; |
| 1013 | mUpdateBoundsDeferredCalled = false; |
| 1014 | } |
| 1015 | } |
| 1016 | |
| 1017 | /** |
| 1018 | * Continues updating bounds after updates have been deferred. If there was a resize attempt |
| 1019 | * between {@link #deferUpdateBounds()} and {@link #continueUpdateBounds()}, the stack will |
| 1020 | * be resized to that bounds. |
| 1021 | */ |
| 1022 | void continueUpdateBounds() { |
Evan Rosky | 1ac8446 | 2018-11-13 11:25:30 -0800 | [diff] [blame] | 1023 | if (mUpdateBoundsDeferred) { |
| 1024 | mUpdateBoundsDeferred = false; |
| 1025 | if (mUpdateBoundsDeferredCalled) { |
| 1026 | setTaskBounds(mDeferredBounds); |
| 1027 | setBounds(mDeferredBounds); |
| 1028 | } |
| 1029 | if (mUpdateDisplayedBoundsDeferredCalled) { |
| 1030 | setTaskDisplayedBounds(mDeferredDisplayedBounds); |
| 1031 | } |
Jorim Jaggi | 192086e | 2016-03-11 17:17:03 +0100 | [diff] [blame] | 1032 | } |
| 1033 | } |
| 1034 | |
Evan Rosky | 1ac8446 | 2018-11-13 11:25:30 -0800 | [diff] [blame] | 1035 | boolean updateBoundsAllowed(Rect bounds) { |
Jorim Jaggi | 192086e | 2016-03-11 17:17:03 +0100 | [diff] [blame] | 1036 | if (!mUpdateBoundsDeferred) { |
| 1037 | return true; |
| 1038 | } |
| 1039 | if (bounds != null) { |
| 1040 | mDeferredBounds.set(bounds); |
| 1041 | } else { |
| 1042 | mDeferredBounds.setEmpty(); |
| 1043 | } |
Jorim Jaggi | 192086e | 2016-03-11 17:17:03 +0100 | [diff] [blame] | 1044 | mUpdateBoundsDeferredCalled = true; |
| 1045 | return false; |
| 1046 | } |
| 1047 | |
Evan Rosky | 1ac8446 | 2018-11-13 11:25:30 -0800 | [diff] [blame] | 1048 | boolean updateDisplayedBoundsAllowed(Rect bounds) { |
| 1049 | if (!mUpdateBoundsDeferred) { |
| 1050 | return true; |
| 1051 | } |
| 1052 | if (bounds != null) { |
| 1053 | mDeferredDisplayedBounds.set(bounds); |
| 1054 | } else { |
| 1055 | mDeferredDisplayedBounds.setEmpty(); |
| 1056 | } |
| 1057 | mUpdateDisplayedBoundsDeferredCalled = true; |
| 1058 | return false; |
| 1059 | } |
| 1060 | |
Bryce Lee | f3c6a47 | 2017-11-14 14:53:06 -0800 | [diff] [blame] | 1061 | @Override |
| 1062 | public int setBounds(Rect bounds) { |
| 1063 | return super.setBounds(!inMultiWindowMode() ? null : bounds); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 1064 | } |
Craig Mautner | 5962b12 | 2012-10-05 14:45:52 -0700 | [diff] [blame] | 1065 | |
Wale Ogunwale | 42f07d9 | 2017-05-01 21:32:58 -0700 | [diff] [blame] | 1066 | ActivityRecord topRunningActivityLocked() { |
Winson Chung | 3f103eb | 2017-04-12 21:53:59 -0700 | [diff] [blame] | 1067 | return topRunningActivityLocked(false /* focusableOnly */); |
| 1068 | } |
| 1069 | |
Jorim Jaggi | ea039a8 | 2017-08-02 14:37:49 +0200 | [diff] [blame] | 1070 | void getAllRunningVisibleActivitiesLocked(ArrayList<ActivityRecord> outActivities) { |
| 1071 | outActivities.clear(); |
| 1072 | for (int taskNdx = mTaskHistory.size() - 1; taskNdx >= 0; --taskNdx) { |
| 1073 | mTaskHistory.get(taskNdx).getAllRunningVisibleActivitiesLocked(outActivities); |
| 1074 | } |
| 1075 | } |
| 1076 | |
Andrii Kulian | 52d255c | 2018-07-13 11:32:19 -0700 | [diff] [blame] | 1077 | ActivityRecord topRunningActivityLocked(boolean focusableOnly) { |
Craig Mautner | d74f7d7 | 2013-02-26 13:41:02 -0800 | [diff] [blame] | 1078 | for (int taskNdx = mTaskHistory.size() - 1; taskNdx >= 0; --taskNdx) { |
Filip Gruszczynski | 3e85ba2 | 2015-10-05 22:48:30 -0700 | [diff] [blame] | 1079 | ActivityRecord r = mTaskHistory.get(taskNdx).topRunningActivityLocked(); |
Winson Chung | 3f103eb | 2017-04-12 21:53:59 -0700 | [diff] [blame] | 1080 | if (r != null && (!focusableOnly || r.isFocusable())) { |
Craig Mautner | 6b74cb5 | 2013-09-27 17:02:21 -0700 | [diff] [blame] | 1081 | return r; |
Craig Mautner | 11bf9a5 | 2013-02-19 14:08:51 -0800 | [diff] [blame] | 1082 | } |
| 1083 | } |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 1084 | return null; |
| 1085 | } |
| 1086 | |
Wale Ogunwale | 42f07d9 | 2017-05-01 21:32:58 -0700 | [diff] [blame] | 1087 | ActivityRecord topRunningNonOverlayTaskActivity() { |
| 1088 | for (int taskNdx = mTaskHistory.size() - 1; taskNdx >= 0; --taskNdx) { |
| 1089 | final TaskRecord task = mTaskHistory.get(taskNdx); |
| 1090 | final ArrayList<ActivityRecord> activities = task.mActivities; |
| 1091 | for (int activityNdx = activities.size() - 1; activityNdx >= 0; --activityNdx) { |
| 1092 | final ActivityRecord r = activities.get(activityNdx); |
| 1093 | if (!r.finishing && !r.mTaskOverlay) { |
| 1094 | return r; |
| 1095 | } |
| 1096 | } |
| 1097 | } |
| 1098 | return null; |
| 1099 | } |
| 1100 | |
| 1101 | ActivityRecord topRunningNonDelayedActivityLocked(ActivityRecord notTop) { |
Craig Mautner | d74f7d7 | 2013-02-26 13:41:02 -0800 | [diff] [blame] | 1102 | for (int taskNdx = mTaskHistory.size() - 1; taskNdx >= 0; --taskNdx) { |
| 1103 | final TaskRecord task = mTaskHistory.get(taskNdx); |
Craig Mautner | 11bf9a5 | 2013-02-19 14:08:51 -0800 | [diff] [blame] | 1104 | final ArrayList<ActivityRecord> activities = task.mActivities; |
Craig Mautner | d74f7d7 | 2013-02-26 13:41:02 -0800 | [diff] [blame] | 1105 | for (int activityNdx = activities.size() - 1; activityNdx >= 0; --activityNdx) { |
| 1106 | ActivityRecord r = activities.get(activityNdx); |
Chong Zhang | 8776197 | 2016-08-22 13:53:24 -0700 | [diff] [blame] | 1107 | if (!r.finishing && !r.delayedResume && r != notTop && r.okToShowLocked()) { |
Craig Mautner | 11bf9a5 | 2013-02-19 14:08:51 -0800 | [diff] [blame] | 1108 | return r; |
| 1109 | } |
| 1110 | } |
| 1111 | } |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 1112 | return null; |
| 1113 | } |
| 1114 | |
| 1115 | /** |
Wale Ogunwale | d32da47 | 2018-11-16 07:19:28 -0800 | [diff] [blame] | 1116 | * This is a simplified version of topRunningActivity that provides a number of |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 1117 | * 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] | 1118 | * |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 1119 | * @param token If non-null, any history records matching this token will be skipped. |
| 1120 | * @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] | 1121 | * |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 1122 | * @return Returns the HistoryRecord of the next activity on the stack. |
| 1123 | */ |
| 1124 | final ActivityRecord topRunningActivityLocked(IBinder token, int taskId) { |
Craig Mautner | 11bf9a5 | 2013-02-19 14:08:51 -0800 | [diff] [blame] | 1125 | for (int taskNdx = mTaskHistory.size() - 1; taskNdx >= 0; --taskNdx) { |
| 1126 | TaskRecord task = mTaskHistory.get(taskNdx); |
| 1127 | if (task.taskId == taskId) { |
| 1128 | continue; |
| 1129 | } |
| 1130 | ArrayList<ActivityRecord> activities = task.mActivities; |
| 1131 | for (int i = activities.size() - 1; i >= 0; --i) { |
| 1132 | final ActivityRecord r = activities.get(i); |
| 1133 | // Note: the taskId check depends on real taskId fields being non-zero |
Chong Zhang | 8776197 | 2016-08-22 13:53:24 -0700 | [diff] [blame] | 1134 | if (!r.finishing && (token != r.appToken) && r.okToShowLocked()) { |
Craig Mautner | 11bf9a5 | 2013-02-19 14:08:51 -0800 | [diff] [blame] | 1135 | return r; |
| 1136 | } |
| 1137 | } |
| 1138 | } |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 1139 | return null; |
| 1140 | } |
| 1141 | |
Wale Ogunwale | 30e441d | 2017-11-09 08:28:45 -0800 | [diff] [blame] | 1142 | ActivityRecord getTopActivity() { |
Craig Mautner | 8849a5e | 2013-04-02 16:41:03 -0700 | [diff] [blame] | 1143 | for (int taskNdx = mTaskHistory.size() - 1; taskNdx >= 0; --taskNdx) { |
Wale Ogunwale | 30e441d | 2017-11-09 08:28:45 -0800 | [diff] [blame] | 1144 | final ActivityRecord r = mTaskHistory.get(taskNdx).getTopActivity(); |
| 1145 | if (r != null) { |
| 1146 | return r; |
Craig Mautner | 8849a5e | 2013-04-02 16:41:03 -0700 | [diff] [blame] | 1147 | } |
| 1148 | } |
Craig Mautner | de4ef02 | 2013-04-07 19:01:33 -0700 | [diff] [blame] | 1149 | return null; |
Craig Mautner | 8849a5e | 2013-04-02 16:41:03 -0700 | [diff] [blame] | 1150 | } |
| 1151 | |
Craig Mautner | 9e14d0f | 2013-05-01 11:26:09 -0700 | [diff] [blame] | 1152 | final TaskRecord topTask() { |
| 1153 | final int size = mTaskHistory.size(); |
| 1154 | if (size > 0) { |
| 1155 | return mTaskHistory.get(size - 1); |
| 1156 | } |
| 1157 | return null; |
| 1158 | } |
| 1159 | |
Wale Ogunwale | 30e441d | 2017-11-09 08:28:45 -0800 | [diff] [blame] | 1160 | private TaskRecord bottomTask() { |
Winson Chung | 1cebea6 | 2017-06-26 17:22:27 -0700 | [diff] [blame] | 1161 | if (mTaskHistory.isEmpty()) { |
| 1162 | return null; |
| 1163 | } |
| 1164 | return mTaskHistory.get(0); |
| 1165 | } |
| 1166 | |
Craig Mautner | d232895 | 2013-03-05 12:46:26 -0800 | [diff] [blame] | 1167 | TaskRecord taskForIdLocked(int id) { |
| 1168 | for (int taskNdx = mTaskHistory.size() - 1; taskNdx >= 0; --taskNdx) { |
| 1169 | final TaskRecord task = mTaskHistory.get(taskNdx); |
| 1170 | if (task.taskId == id) { |
| 1171 | return task; |
Craig Mautner | 5d9c7be | 2013-02-15 14:02:56 -0800 | [diff] [blame] | 1172 | } |
| 1173 | } |
Dianne Hackborn | ce86ba8 | 2011-07-13 19:33:41 -0700 | [diff] [blame] | 1174 | return null; |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 1175 | } |
| 1176 | |
Craig Mautner | d232895 | 2013-03-05 12:46:26 -0800 | [diff] [blame] | 1177 | ActivityRecord isInStackLocked(IBinder token) { |
Wale Ogunwale | 7d70117 | 2015-03-11 15:36:30 -0700 | [diff] [blame] | 1178 | final ActivityRecord r = ActivityRecord.forTokenLocked(token); |
Wale Ogunwale | 60454db | 2015-01-23 16:05:07 -0800 | [diff] [blame] | 1179 | return isInStackLocked(r); |
| 1180 | } |
| 1181 | |
| 1182 | ActivityRecord isInStackLocked(ActivityRecord r) { |
| 1183 | if (r == null) { |
| 1184 | return null; |
| 1185 | } |
Wale Ogunwale | 8b19de9 | 2018-11-29 19:58:26 -0800 | [diff] [blame] | 1186 | final TaskRecord task = r.getTaskRecord(); |
| 1187 | final ActivityStack stack = r.getActivityStack(); |
Andrii Kulian | 02b7a83 | 2016-10-06 23:11:56 -0700 | [diff] [blame] | 1188 | if (stack != null && task.mActivities.contains(r) && mTaskHistory.contains(task)) { |
| 1189 | if (stack != this) Slog.w(TAG, |
Craig Mautner | d232895 | 2013-03-05 12:46:26 -0800 | [diff] [blame] | 1190 | "Illegal state! task does not point to stack it is in."); |
Wale Ogunwale | 60454db | 2015-01-23 16:05:07 -0800 | [diff] [blame] | 1191 | return r; |
Craig Mautner | 5d9c7be | 2013-02-15 14:02:56 -0800 | [diff] [blame] | 1192 | } |
Craig Mautner | d232895 | 2013-03-05 12:46:26 -0800 | [diff] [blame] | 1193 | return null; |
Craig Mautner | 5d9c7be | 2013-02-15 14:02:56 -0800 | [diff] [blame] | 1194 | } |
| 1195 | |
Andrii Kulian | fb1bf69 | 2017-01-17 11:17:34 -0800 | [diff] [blame] | 1196 | boolean isInStackLocked(TaskRecord task) { |
| 1197 | return mTaskHistory.contains(task); |
| 1198 | } |
| 1199 | |
| 1200 | /** Checks if there are tasks with specific UID in the stack. */ |
| 1201 | boolean isUidPresent(int uid) { |
| 1202 | for (TaskRecord task : mTaskHistory) { |
David Stevens | 82ea6cb | 2017-03-03 16:18:50 -0800 | [diff] [blame] | 1203 | for (ActivityRecord r : task.mActivities) { |
| 1204 | if (r.getUid() == uid) { |
| 1205 | return true; |
| 1206 | } |
Andrii Kulian | fb1bf69 | 2017-01-17 11:17:34 -0800 | [diff] [blame] | 1207 | } |
| 1208 | } |
| 1209 | return false; |
| 1210 | } |
| 1211 | |
| 1212 | /** Get all UIDs that are present in the stack. */ |
| 1213 | void getPresentUIDs(IntArray presentUIDs) { |
| 1214 | for (TaskRecord task : mTaskHistory) { |
David Stevens | 82ea6cb | 2017-03-03 16:18:50 -0800 | [diff] [blame] | 1215 | for (ActivityRecord r : task.mActivities) { |
| 1216 | presentUIDs.add(r.getUid()); |
| 1217 | } |
Andrii Kulian | fb1bf69 | 2017-01-17 11:17:34 -0800 | [diff] [blame] | 1218 | } |
| 1219 | } |
| 1220 | |
Wale Ogunwale | 9e737db | 2018-12-17 15:42:37 -0800 | [diff] [blame] | 1221 | /** @return true if the stack can only contain one task */ |
| 1222 | boolean isSingleTaskInstance() { |
| 1223 | final ActivityDisplay display = getDisplay(); |
| 1224 | return display != null && display.isSingleTaskInstance(); |
| 1225 | } |
| 1226 | |
Winson Chung | abb433b | 2017-03-24 09:35:42 -0700 | [diff] [blame] | 1227 | final void removeActivitiesFromLRUListLocked(TaskRecord task) { |
| 1228 | for (ActivityRecord r : task.mActivities) { |
| 1229 | mLRUActivities.remove(r); |
| 1230 | } |
| 1231 | } |
| 1232 | |
Craig Mautner | 2420ead | 2013-04-01 17:13:20 -0700 | [diff] [blame] | 1233 | final boolean updateLRUListLocked(ActivityRecord r) { |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 1234 | final boolean hadit = mLRUActivities.remove(r); |
| 1235 | mLRUActivities.add(r); |
| 1236 | return hadit; |
| 1237 | } |
| 1238 | |
Matthew Ng | ae1ff4f | 2016-11-10 15:49:14 -0800 | [diff] [blame] | 1239 | final boolean isHomeOrRecentsStack() { |
Wale Ogunwale | 6827856 | 2017-09-23 17:13:55 -0700 | [diff] [blame] | 1240 | return isActivityTypeHome() || isActivityTypeRecents(); |
Matthew Ng | ae1ff4f | 2016-11-10 15:49:14 -0800 | [diff] [blame] | 1241 | } |
| 1242 | |
Craig Mautner | e0a3884 | 2013-12-16 16:14:02 -0800 | [diff] [blame] | 1243 | final boolean isOnHomeDisplay() { |
Wale Ogunwale | 9dcf946 | 2017-09-19 15:13:01 -0700 | [diff] [blame] | 1244 | return mDisplayId == DEFAULT_DISPLAY; |
Craig Mautner | e0a3884 | 2013-12-16 16:14:02 -0800 | [diff] [blame] | 1245 | } |
| 1246 | |
Wale Ogunwale | 66e1685 | 2017-10-19 13:35:52 -0700 | [diff] [blame] | 1247 | private boolean returnsToHomeStack() { |
| 1248 | return !inMultiWindowMode() |
| 1249 | && !mTaskHistory.isEmpty() |
| 1250 | && mTaskHistory.get(0).returnsToHomeStack(); |
| 1251 | } |
| 1252 | |
Wale Ogunwale | eae451e | 2015-08-04 15:20:50 -0700 | [diff] [blame] | 1253 | void moveToFront(String reason) { |
| 1254 | moveToFront(reason, null); |
| 1255 | } |
| 1256 | |
| 1257 | /** |
| 1258 | * @param reason The reason for moving the stack to the front. |
| 1259 | * @param task If non-null, the task will be moved to the top of the stack. |
| 1260 | * */ |
| 1261 | void moveToFront(String reason, TaskRecord task) { |
Wale Ogunwale | 1e60e0c | 2015-10-28 13:36:10 -0700 | [diff] [blame] | 1262 | if (!isAttached()) { |
| 1263 | return; |
| 1264 | } |
Wale Ogunwale | 925d0d1 | 2015-09-23 15:40:07 -0700 | [diff] [blame] | 1265 | |
Wale Ogunwale | bb28587 | 2018-03-01 13:05:30 -0800 | [diff] [blame] | 1266 | final ActivityDisplay display = getDisplay(); |
| 1267 | |
| 1268 | if (inSplitScreenSecondaryWindowingMode()) { |
| 1269 | // If the stack is in split-screen seconardy mode, we need to make sure we move the |
| 1270 | // primary split-screen stack forward in the case it is currently behind a fullscreen |
| 1271 | // stack so both halves of the split-screen appear on-top and the fullscreen stack isn't |
| 1272 | // cutting between them. |
| 1273 | // TODO(b/70677280): This is a workaround until we can fix as part of b/70677280. |
| 1274 | final ActivityStack topFullScreenStack = |
| 1275 | display.getTopStackInWindowingMode(WINDOWING_MODE_FULLSCREEN); |
| 1276 | if (topFullScreenStack != null) { |
| 1277 | final ActivityStack primarySplitScreenStack = display.getSplitScreenPrimaryStack(); |
| 1278 | if (display.getIndexOf(topFullScreenStack) |
| 1279 | > display.getIndexOf(primarySplitScreenStack)) { |
| 1280 | primarySplitScreenStack.moveToFront(reason + " splitScreenToTop"); |
| 1281 | } |
| 1282 | } |
| 1283 | } |
| 1284 | |
Wale Ogunwale | 66e1685 | 2017-10-19 13:35:52 -0700 | [diff] [blame] | 1285 | if (!isActivityTypeHome() && returnsToHomeStack()) { |
| 1286 | // Make sure the home stack is behind this stack since that is where we should return to |
| 1287 | // when this stack is no longer visible. |
Louis Chang | bd48dca | 2018-08-29 17:44:34 +0800 | [diff] [blame] | 1288 | display.moveHomeStackToFront(reason + " returnToHome"); |
Wale Ogunwale | 66e1685 | 2017-10-19 13:35:52 -0700 | [diff] [blame] | 1289 | } |
| 1290 | |
Riddle Hsu | bbb63c2 | 2018-10-03 12:28:29 +0800 | [diff] [blame] | 1291 | final boolean movingTask = task != null; |
| 1292 | display.positionChildAtTop(this, !movingTask /* includingParents */, reason); |
| 1293 | if (movingTask) { |
Andrii Kulian | 52d255c | 2018-07-13 11:32:19 -0700 | [diff] [blame] | 1294 | // This also moves the entire hierarchy branch to top, including parents |
Riddle Hsu | bbb63c2 | 2018-10-03 12:28:29 +0800 | [diff] [blame] | 1295 | insertTaskAtTop(task, null /* starting */); |
Wale Ogunwale | 1e60e0c | 2015-10-28 13:36:10 -0700 | [diff] [blame] | 1296 | } |
Craig Mautner | e0a3884 | 2013-12-16 16:14:02 -0800 | [diff] [blame] | 1297 | } |
| 1298 | |
Evan Rosky | 9c44817 | 2017-11-02 14:19:27 -0700 | [diff] [blame] | 1299 | /** |
| 1300 | * @param reason The reason for moving the stack to the back. |
| 1301 | * @param task If non-null, the task will be moved to the bottom of the stack. |
| 1302 | **/ |
| 1303 | void moveToBack(String reason, TaskRecord task) { |
| 1304 | if (!isAttached()) { |
| 1305 | return; |
| 1306 | } |
| 1307 | |
Bryce Lee | 8cab4a0 | 2018-01-05 09:00:49 -0800 | [diff] [blame] | 1308 | /** |
| 1309 | * The intent behind moving a primary split screen stack to the back is usually to hide |
| 1310 | * behind the home stack. Exit split screen in this case. |
| 1311 | */ |
| 1312 | if (getWindowingMode() == WINDOWING_MODE_SPLIT_SCREEN_PRIMARY) { |
Evan Rosky | 1047574 | 2018-09-05 19:02:48 -0700 | [diff] [blame] | 1313 | setWindowingMode(WINDOWING_MODE_UNDEFINED); |
Bryce Lee | 8cab4a0 | 2018-01-05 09:00:49 -0800 | [diff] [blame] | 1314 | } |
| 1315 | |
Riddle Hsu | bbb63c2 | 2018-10-03 12:28:29 +0800 | [diff] [blame] | 1316 | getDisplay().positionChildAtBottom(this, reason); |
Evan Rosky | 9c44817 | 2017-11-02 14:19:27 -0700 | [diff] [blame] | 1317 | if (task != null) { |
| 1318 | insertTaskAtBottom(task); |
Evan Rosky | 9c44817 | 2017-11-02 14:19:27 -0700 | [diff] [blame] | 1319 | } |
| 1320 | } |
| 1321 | |
Wale Ogunwale | d046a01 | 2015-12-24 13:05:59 -0800 | [diff] [blame] | 1322 | boolean isFocusable() { |
Wale Ogunwale | 4cea0f5 | 2015-12-25 06:30:31 -0800 | [diff] [blame] | 1323 | final ActivityRecord r = topRunningActivityLocked(); |
Wale Ogunwale | d32da47 | 2018-11-16 07:19:28 -0800 | [diff] [blame] | 1324 | return mRootActivityContainer.isFocusable(this, r != null && r.isFocusable()); |
Wale Ogunwale | d046a01 | 2015-12-24 13:05:59 -0800 | [diff] [blame] | 1325 | } |
| 1326 | |
Riddle Hsu | 7501699 | 2018-09-20 20:37:14 +0800 | [diff] [blame] | 1327 | boolean isFocusableAndVisible() { |
| 1328 | return isFocusable() && shouldBeVisible(null /* starting */); |
| 1329 | } |
| 1330 | |
Craig Mautner | e0a3884 | 2013-12-16 16:14:02 -0800 | [diff] [blame] | 1331 | final boolean isAttached() { |
Riddle Hsu | 402b440 | 2018-11-06 17:23:15 +0800 | [diff] [blame] | 1332 | final ActivityDisplay display = getDisplay(); |
| 1333 | return display != null && !display.isRemoved(); |
Craig Mautner | 4a1cb22 | 2013-12-04 16:14:06 -0800 | [diff] [blame] | 1334 | } |
| 1335 | |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 1336 | /** |
Wale Ogunwale | 3938197 | 2015-12-17 17:15:29 -0800 | [diff] [blame] | 1337 | * Returns the top activity in any existing task matching the given Intent in the input result. |
| 1338 | * Returns null if no such task is found. |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 1339 | */ |
Wale Ogunwale | 3938197 | 2015-12-17 17:15:29 -0800 | [diff] [blame] | 1340 | void findTaskLocked(ActivityRecord target, FindTaskResult result) { |
Craig Mautner | ac6f843 | 2013-07-17 13:24:59 -0700 | [diff] [blame] | 1341 | Intent intent = target.intent; |
| 1342 | ActivityInfo info = target.info; |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 1343 | ComponentName cls = intent.getComponent(); |
| 1344 | if (info.targetActivity != null) { |
| 1345 | cls = new ComponentName(info.packageName, info.targetActivity); |
| 1346 | } |
Dianne Hackborn | f02b60a | 2012-08-16 10:48:27 -0700 | [diff] [blame] | 1347 | final int userId = UserHandle.getUserId(info.applicationInfo.uid); |
Craig Mautner | d00f474 | 2014-03-12 14:17:26 -0700 | [diff] [blame] | 1348 | boolean isDocument = intent != null & intent.isDocument(); |
| 1349 | // If documentData is non-null then it must match the existing task data. |
| 1350 | Uri documentData = isDocument ? intent.getData() : null; |
Craig Mautner | 000f002 | 2013-02-26 15:04:29 -0800 | [diff] [blame] | 1351 | |
Wale Ogunwale | ee006da | 2015-03-30 14:49:25 -0700 | [diff] [blame] | 1352 | 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] | 1353 | for (int taskNdx = mTaskHistory.size() - 1; taskNdx >= 0; --taskNdx) { |
| 1354 | final TaskRecord task = mTaskHistory.get(taskNdx); |
Dianne Hackborn | 91097de | 2014-04-04 18:02:06 -0700 | [diff] [blame] | 1355 | if (task.voiceSession != null) { |
| 1356 | // We never match voice sessions; those always run independently. |
Wale Ogunwale | ee006da | 2015-03-30 14:49:25 -0700 | [diff] [blame] | 1357 | if (DEBUG_TASKS) Slog.d(TAG_TASKS, "Skipping " + task + ": voice session"); |
Dianne Hackborn | 91097de | 2014-04-04 18:02:06 -0700 | [diff] [blame] | 1358 | continue; |
| 1359 | } |
Craig Mautner | ac6f843 | 2013-07-17 13:24:59 -0700 | [diff] [blame] | 1360 | if (task.userId != userId) { |
| 1361 | // Looking for a different task. |
Wale Ogunwale | ee006da | 2015-03-30 14:49:25 -0700 | [diff] [blame] | 1362 | if (DEBUG_TASKS) Slog.d(TAG_TASKS, "Skipping " + task + ": different user"); |
Craig Mautner | ac6f843 | 2013-07-17 13:24:59 -0700 | [diff] [blame] | 1363 | continue; |
| 1364 | } |
Bryce Lee | 9f6affd | 2017-09-01 09:18:35 -0700 | [diff] [blame] | 1365 | |
| 1366 | // Overlays should not be considered as the task's logical top activity. |
| 1367 | final ActivityRecord r = task.getTopActivity(false /* includeOverlays */); |
Wale Ogunwale | 8b19de9 | 2018-11-29 19:58:26 -0800 | [diff] [blame] | 1368 | if (r == null || r.finishing || r.mUserId != userId || |
Craig Mautner | 000f002 | 2013-02-26 15:04:29 -0800 | [diff] [blame] | 1369 | r.launchMode == ActivityInfo.LAUNCH_SINGLE_INSTANCE) { |
Wale Ogunwale | ee006da | 2015-03-30 14:49:25 -0700 | [diff] [blame] | 1370 | if (DEBUG_TASKS) Slog.d(TAG_TASKS, "Skipping " + task + ": mismatch root " + r); |
Craig Mautner | 000f002 | 2013-02-26 15:04:29 -0800 | [diff] [blame] | 1371 | continue; |
| 1372 | } |
Wale Ogunwale | 6fbde9f | 2017-08-24 07:24:12 -0700 | [diff] [blame] | 1373 | if (!r.hasCompatibleActivityType(target)) { |
Chong Zhang | b546f7e | 2015-08-05 14:21:36 -0700 | [diff] [blame] | 1374 | if (DEBUG_TASKS) Slog.d(TAG_TASKS, "Skipping " + task + ": mismatch activity type"); |
| 1375 | continue; |
| 1376 | } |
Craig Mautner | 000f002 | 2013-02-26 15:04:29 -0800 | [diff] [blame] | 1377 | |
Craig Mautner | d00f474 | 2014-03-12 14:17:26 -0700 | [diff] [blame] | 1378 | final Intent taskIntent = task.intent; |
| 1379 | final Intent affinityIntent = task.affinityIntent; |
| 1380 | final boolean taskIsDocument; |
| 1381 | final Uri taskDocumentData; |
| 1382 | if (taskIntent != null && taskIntent.isDocument()) { |
| 1383 | taskIsDocument = true; |
| 1384 | taskDocumentData = taskIntent.getData(); |
| 1385 | } else if (affinityIntent != null && affinityIntent.isDocument()) { |
| 1386 | taskIsDocument = true; |
| 1387 | taskDocumentData = affinityIntent.getData(); |
| 1388 | } else { |
| 1389 | taskIsDocument = false; |
| 1390 | taskDocumentData = null; |
| 1391 | } |
| 1392 | |
Wale Ogunwale | ee006da | 2015-03-30 14:49:25 -0700 | [diff] [blame] | 1393 | if (DEBUG_TASKS) Slog.d(TAG_TASKS, "Comparing existing cls=" |
Craig Mautner | d00f474 | 2014-03-12 14:17:26 -0700 | [diff] [blame] | 1394 | + taskIntent.getComponent().flattenToShortString() |
Wale Ogunwale | 8b19de9 | 2018-11-29 19:58:26 -0800 | [diff] [blame] | 1395 | + "/aff=" + r.getTaskRecord().rootAffinity + " to new cls=" |
Dianne Hackborn | 2a272d4 | 2013-10-16 13:34:33 -0700 | [diff] [blame] | 1396 | + intent.getComponent().flattenToShortString() + "/aff=" + info.taskAffinity); |
Andrii Kulian | 206b9fa | 2016-06-02 13:18:01 -0700 | [diff] [blame] | 1397 | // TODO Refactor to remove duplications. Check if logic can be simplified. |
| 1398 | if (taskIntent != null && taskIntent.getComponent() != null && |
Craig Mautner | ffcfcaa | 2014-06-05 09:54:38 -0700 | [diff] [blame] | 1399 | taskIntent.getComponent().compareTo(cls) == 0 && |
Craig Mautner | d00f474 | 2014-03-12 14:17:26 -0700 | [diff] [blame] | 1400 | Objects.equals(documentData, taskDocumentData)) { |
Wale Ogunwale | ee006da | 2015-03-30 14:49:25 -0700 | [diff] [blame] | 1401 | if (DEBUG_TASKS) Slog.d(TAG_TASKS, "Found matching class!"); |
Craig Mautner | 000f002 | 2013-02-26 15:04:29 -0800 | [diff] [blame] | 1402 | //dump(); |
Wale Ogunwale | ee006da | 2015-03-30 14:49:25 -0700 | [diff] [blame] | 1403 | if (DEBUG_TASKS) Slog.d(TAG_TASKS, |
| 1404 | "For Intent " + intent + " bringing to top: " + r.intent); |
Louis Chang | c85b1a3 | 2018-08-14 16:40:53 +0800 | [diff] [blame] | 1405 | result.mRecord = r; |
| 1406 | result.mIdealMatch = true; |
Wale Ogunwale | 3938197 | 2015-12-17 17:15:29 -0800 | [diff] [blame] | 1407 | break; |
Craig Mautner | ffcfcaa | 2014-06-05 09:54:38 -0700 | [diff] [blame] | 1408 | } else if (affinityIntent != null && affinityIntent.getComponent() != null && |
| 1409 | affinityIntent.getComponent().compareTo(cls) == 0 && |
Craig Mautner | d00f474 | 2014-03-12 14:17:26 -0700 | [diff] [blame] | 1410 | Objects.equals(documentData, taskDocumentData)) { |
Wale Ogunwale | ee006da | 2015-03-30 14:49:25 -0700 | [diff] [blame] | 1411 | if (DEBUG_TASKS) Slog.d(TAG_TASKS, "Found matching class!"); |
Craig Mautner | 000f002 | 2013-02-26 15:04:29 -0800 | [diff] [blame] | 1412 | //dump(); |
Wale Ogunwale | ee006da | 2015-03-30 14:49:25 -0700 | [diff] [blame] | 1413 | if (DEBUG_TASKS) Slog.d(TAG_TASKS, |
| 1414 | "For Intent " + intent + " bringing to top: " + r.intent); |
Louis Chang | c85b1a3 | 2018-08-14 16:40:53 +0800 | [diff] [blame] | 1415 | result.mRecord = r; |
| 1416 | result.mIdealMatch = true; |
Wale Ogunwale | 3938197 | 2015-12-17 17:15:29 -0800 | [diff] [blame] | 1417 | break; |
Andrii Kulian | 206b9fa | 2016-06-02 13:18:01 -0700 | [diff] [blame] | 1418 | } else if (!isDocument && !taskIsDocument |
Louis Chang | c85b1a3 | 2018-08-14 16:40:53 +0800 | [diff] [blame] | 1419 | && result.mRecord == null && task.rootAffinity != null) { |
Andrii Kulian | 206b9fa | 2016-06-02 13:18:01 -0700 | [diff] [blame] | 1420 | if (task.rootAffinity.equals(target.taskAffinity)) { |
| 1421 | if (DEBUG_TASKS) Slog.d(TAG_TASKS, "Found matching affinity candidate!"); |
| 1422 | // It is possible for multiple tasks to have the same root affinity especially |
| 1423 | // if they are in separate stacks. We save off this candidate, but keep looking |
| 1424 | // to see if there is a better candidate. |
Louis Chang | c85b1a3 | 2018-08-14 16:40:53 +0800 | [diff] [blame] | 1425 | result.mRecord = r; |
| 1426 | result.mIdealMatch = false; |
Andrii Kulian | 206b9fa | 2016-06-02 13:18:01 -0700 | [diff] [blame] | 1427 | } |
Wale Ogunwale | ee006da | 2015-03-30 14:49:25 -0700 | [diff] [blame] | 1428 | } else if (DEBUG_TASKS) Slog.d(TAG_TASKS, "Not a match: " + task); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 1429 | } |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 1430 | } |
| 1431 | |
| 1432 | /** |
| 1433 | * Returns the first activity (starting from the top of the stack) that |
| 1434 | * is the same as the given activity. Returns null if no such activity |
| 1435 | * is found. |
| 1436 | */ |
Andrii Kulian | d3bbb13 | 2016-06-16 16:00:20 -0700 | [diff] [blame] | 1437 | ActivityRecord findActivityLocked(Intent intent, ActivityInfo info, |
| 1438 | boolean compareIntentFilters) { |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 1439 | ComponentName cls = intent.getComponent(); |
| 1440 | if (info.targetActivity != null) { |
| 1441 | cls = new ComponentName(info.packageName, info.targetActivity); |
| 1442 | } |
Dianne Hackborn | f02b60a | 2012-08-16 10:48:27 -0700 | [diff] [blame] | 1443 | final int userId = UserHandle.getUserId(info.applicationInfo.uid); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 1444 | |
Craig Mautner | 000f002 | 2013-02-26 15:04:29 -0800 | [diff] [blame] | 1445 | for (int taskNdx = mTaskHistory.size() - 1; taskNdx >= 0; --taskNdx) { |
Wale Ogunwale | 3fcb4a8 | 2015-04-06 14:00:13 -0700 | [diff] [blame] | 1446 | final TaskRecord task = mTaskHistory.get(taskNdx); |
Craig Mautner | ac6f843 | 2013-07-17 13:24:59 -0700 | [diff] [blame] | 1447 | final ArrayList<ActivityRecord> activities = task.mActivities; |
Wale Ogunwale | 3fcb4a8 | 2015-04-06 14:00:13 -0700 | [diff] [blame] | 1448 | |
Craig Mautner | 000f002 | 2013-02-26 15:04:29 -0800 | [diff] [blame] | 1449 | for (int activityNdx = activities.size() - 1; activityNdx >= 0; --activityNdx) { |
| 1450 | ActivityRecord r = activities.get(activityNdx); |
Chong Zhang | 8776197 | 2016-08-22 13:53:24 -0700 | [diff] [blame] | 1451 | if (!r.okToShowLocked()) { |
Wale Ogunwale | 25073dd | 2015-07-21 16:54:54 -0700 | [diff] [blame] | 1452 | continue; |
Wale Ogunwale | 3fcb4a8 | 2015-04-06 14:00:13 -0700 | [diff] [blame] | 1453 | } |
Wale Ogunwale | 8b19de9 | 2018-11-29 19:58:26 -0800 | [diff] [blame] | 1454 | if (!r.finishing && r.mUserId == userId) { |
Andrii Kulian | d3bbb13 | 2016-06-16 16:00:20 -0700 | [diff] [blame] | 1455 | if (compareIntentFilters) { |
| 1456 | if (r.intent.filterEquals(intent)) { |
| 1457 | return r; |
| 1458 | } |
| 1459 | } else { |
| 1460 | if (r.intent.getComponent().equals(cls)) { |
| 1461 | return r; |
| 1462 | } |
| 1463 | } |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 1464 | } |
| 1465 | } |
| 1466 | } |
| 1467 | |
| 1468 | return null; |
| 1469 | } |
| 1470 | |
Amith Yamasani | 742a671 | 2011-05-04 14:49:28 -0700 | [diff] [blame] | 1471 | /* |
Craig Mautner | ac6f843 | 2013-07-17 13:24:59 -0700 | [diff] [blame] | 1472 | * 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] | 1473 | */ |
Craig Mautner | 93529a4 | 2013-10-04 15:03:13 -0700 | [diff] [blame] | 1474 | final void switchUserLocked(int userId) { |
Craig Mautner | 5d9c7be | 2013-02-15 14:02:56 -0800 | [diff] [blame] | 1475 | if (mCurrentUser == userId) { |
Craig Mautner | 93529a4 | 2013-10-04 15:03:13 -0700 | [diff] [blame] | 1476 | return; |
Craig Mautner | 5d9c7be | 2013-02-15 14:02:56 -0800 | [diff] [blame] | 1477 | } |
| 1478 | mCurrentUser = userId; |
| 1479 | |
| 1480 | // Move userId's tasks to the top. |
Craig Mautner | 5d9c7be | 2013-02-15 14:02:56 -0800 | [diff] [blame] | 1481 | int index = mTaskHistory.size(); |
Craig Mautner | db5c4fb | 2013-11-06 13:55:08 -0800 | [diff] [blame] | 1482 | for (int i = 0; i < index; ) { |
Wale Ogunwale | 3fcb4a8 | 2015-04-06 14:00:13 -0700 | [diff] [blame] | 1483 | final TaskRecord task = mTaskHistory.get(i); |
| 1484 | |
Chong Zhang | 8776197 | 2016-08-22 13:53:24 -0700 | [diff] [blame] | 1485 | if (task.okToShowLocked()) { |
Wale Ogunwale | d32da47 | 2018-11-16 07:19:28 -0800 | [diff] [blame] | 1486 | if (DEBUG_TASKS) Slog.d(TAG_TASKS, "switchUser: stack=" + getStackId() + |
Craig Mautner | 4f1df4f | 2013-10-15 15:44:14 -0700 | [diff] [blame] | 1487 | " moving " + task + " to top"); |
Craig Mautner | 5d9c7be | 2013-02-15 14:02:56 -0800 | [diff] [blame] | 1488 | mTaskHistory.remove(i); |
| 1489 | mTaskHistory.add(task); |
| 1490 | --index; |
Craig Mautner | db5c4fb | 2013-11-06 13:55:08 -0800 | [diff] [blame] | 1491 | // Use same value for i. |
| 1492 | } else { |
| 1493 | ++i; |
Craig Mautner | 5d9c7be | 2013-02-15 14:02:56 -0800 | [diff] [blame] | 1494 | } |
| 1495 | } |
Amith Yamasani | 742a671 | 2011-05-04 14:49:28 -0700 | [diff] [blame] | 1496 | } |
| 1497 | |
Craig Mautner | 2420ead | 2013-04-01 17:13:20 -0700 | [diff] [blame] | 1498 | void minimalResumeActivityLocked(ActivityRecord r) { |
Wale Ogunwale | 5658e4b | 2016-02-12 12:22:19 -0800 | [diff] [blame] | 1499 | if (DEBUG_STATES) Slog.v(TAG_STATES, "Moving to RESUMED: " + r + " (starting new instance)" |
| 1500 | + " callers=" + Debug.getCallers(5)); |
Bryce Lee | c4ab62a | 2018-03-05 14:19:26 -0800 | [diff] [blame] | 1501 | r.setState(RESUMED, "minimalResumeActivityLocked"); |
Andrii Kulian | 21713ac | 2016-10-12 22:05:05 -0700 | [diff] [blame] | 1502 | r.completeResumeLocked(); |
Andrii Kulian | 86e70fc | 2019-02-12 11:04:10 +0000 | [diff] [blame] | 1503 | mStackSupervisor.updateTopResumedActivityIfNeeded(); |
Wale Ogunwale | 0fc365c | 2015-05-25 19:35:42 -0700 | [diff] [blame] | 1504 | if (DEBUG_SAVED_STATE) Slog.i(TAG_SAVED_STATE, |
| 1505 | "Launch completed; removing icicle of " + r.icicle); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 1506 | } |
| 1507 | |
Andrii Kulian | 21713ac | 2016-10-12 22:05:05 -0700 | [diff] [blame] | 1508 | private void clearLaunchTime(ActivityRecord r) { |
Craig Mautner | 5c49454 | 2013-09-06 11:59:38 -0700 | [diff] [blame] | 1509 | // Make sure that there is no activity waiting for this to launch. |
Vishnu Nair | 132ee83 | 2018-09-28 15:00:05 -0700 | [diff] [blame] | 1510 | if (!mStackSupervisor.mWaitingActivityLaunched.isEmpty()) { |
Craig Mautner | 5c49454 | 2013-09-06 11:59:38 -0700 | [diff] [blame] | 1511 | mStackSupervisor.removeTimeoutsForActivityLocked(r); |
| 1512 | mStackSupervisor.scheduleIdleTimeoutLocked(r); |
| 1513 | } |
Dianne Hackborn | 2286cdc | 2013-07-01 19:10:06 -0700 | [diff] [blame] | 1514 | } |
| 1515 | |
Dianne Hackborn | 4eba96b | 2011-01-21 13:34:36 -0800 | [diff] [blame] | 1516 | void awakeFromSleepingLocked() { |
Dianne Hackborn | 4eba96b | 2011-01-21 13:34:36 -0800 | [diff] [blame] | 1517 | // Ensure activities are no longer sleeping. |
Craig Mautner | d44711d | 2013-02-23 11:24:36 -0800 | [diff] [blame] | 1518 | for (int taskNdx = mTaskHistory.size() - 1; taskNdx >= 0; --taskNdx) { |
| 1519 | final ArrayList<ActivityRecord> activities = mTaskHistory.get(taskNdx).mActivities; |
| 1520 | for (int activityNdx = activities.size() - 1; activityNdx >= 0; --activityNdx) { |
| 1521 | activities.get(activityNdx).setSleeping(false); |
| 1522 | } |
Dianne Hackborn | 4eba96b | 2011-01-21 13:34:36 -0800 | [diff] [blame] | 1523 | } |
Craig Mautner | f49b0a4 | 2014-11-20 15:06:40 -0800 | [diff] [blame] | 1524 | if (mPausingActivity != null) { |
| 1525 | Slog.d(TAG, "awakeFromSleepingLocked: previously pausing activity didn't pause"); |
| 1526 | activityPausedLocked(mPausingActivity.appToken, true); |
| 1527 | } |
Dianne Hackborn | 4eba96b | 2011-01-21 13:34:36 -0800 | [diff] [blame] | 1528 | } |
| 1529 | |
Todd Kennedy | 39bfee5 | 2016-02-24 10:28:21 -0800 | [diff] [blame] | 1530 | void updateActivityApplicationInfoLocked(ApplicationInfo aInfo) { |
| 1531 | final String packageName = aInfo.packageName; |
Makoto Onuki | 8b9963a | 2017-05-18 13:56:30 -0700 | [diff] [blame] | 1532 | final int userId = UserHandle.getUserId(aInfo.uid); |
| 1533 | |
Todd Kennedy | 39bfee5 | 2016-02-24 10:28:21 -0800 | [diff] [blame] | 1534 | for (int taskNdx = mTaskHistory.size() - 1; taskNdx >= 0; --taskNdx) { |
| 1535 | final List<ActivityRecord> activities = mTaskHistory.get(taskNdx).mActivities; |
| 1536 | for (int activityNdx = activities.size() - 1; activityNdx >= 0; --activityNdx) { |
Makoto Onuki | 8b9963a | 2017-05-18 13:56:30 -0700 | [diff] [blame] | 1537 | final ActivityRecord ar = activities.get(activityNdx); |
| 1538 | |
Wale Ogunwale | 8b19de9 | 2018-11-29 19:58:26 -0800 | [diff] [blame] | 1539 | if ((userId == ar.mUserId) && packageName.equals(ar.packageName)) { |
Philip P. Moltmann | cff8f0f | 2018-03-27 12:51:51 -0700 | [diff] [blame] | 1540 | ar.updateApplicationInfo(aInfo); |
Todd Kennedy | 39bfee5 | 2016-02-24 10:28:21 -0800 | [diff] [blame] | 1541 | } |
| 1542 | } |
| 1543 | } |
| 1544 | } |
| 1545 | |
David Stevens | 9440dc8 | 2017-03-16 19:00:20 -0700 | [diff] [blame] | 1546 | void checkReadyForSleep() { |
| 1547 | if (shouldSleepActivities() && goToSleepIfPossible(false /* shuttingDown */)) { |
| 1548 | mStackSupervisor.checkReadyForSleepLocked(true /* allowDelay */); |
| 1549 | } |
| 1550 | } |
| 1551 | |
Craig Mautner | 0eea92c | 2013-05-16 13:35:39 -0700 | [diff] [blame] | 1552 | /** |
David Stevens | 9440dc8 | 2017-03-16 19:00:20 -0700 | [diff] [blame] | 1553 | * Tries to put the activities in the stack to sleep. |
| 1554 | * |
| 1555 | * If the stack is not in a state where its activities can be put to sleep, this function will |
| 1556 | * start any necessary actions to move the stack into such a state. It is expected that this |
| 1557 | * function get called again when those actions complete. |
| 1558 | * |
| 1559 | * @param shuttingDown true when the called because the device is shutting down. |
David Stevens | 18abd0e | 2017-08-17 14:55:47 -0700 | [diff] [blame] | 1560 | * @return true if the stack finished going to sleep, false if the stack only started the |
| 1561 | * process of going to sleep (checkReadyForSleep will be called when that process finishes). |
Craig Mautner | 0eea92c | 2013-05-16 13:35:39 -0700 | [diff] [blame] | 1562 | */ |
David Stevens | 9440dc8 | 2017-03-16 19:00:20 -0700 | [diff] [blame] | 1563 | boolean goToSleepIfPossible(boolean shuttingDown) { |
| 1564 | boolean shouldSleep = true; |
| 1565 | |
Craig Mautner | 0eea92c | 2013-05-16 13:35:39 -0700 | [diff] [blame] | 1566 | if (mResumedActivity != null) { |
| 1567 | // Still have something resumed; can't sleep until it is paused. |
Wale Ogunwale | ee006da | 2015-03-30 14:49:25 -0700 | [diff] [blame] | 1568 | if (DEBUG_PAUSE) Slog.v(TAG_PAUSE, "Sleep needs to pause " + mResumedActivity); |
| 1569 | if (DEBUG_USER_LEAVING) Slog.v(TAG_USER_LEAVING, |
| 1570 | "Sleep => pause with userLeaving=false"); |
Bryce Lee | 5daa312 | 2017-04-19 10:40:42 -0700 | [diff] [blame] | 1571 | |
chaviw | a1d6853 | 2018-03-16 15:33:43 -0700 | [diff] [blame] | 1572 | startPausingLocked(false, true, null, false); |
David Stevens | 9440dc8 | 2017-03-16 19:00:20 -0700 | [diff] [blame] | 1573 | shouldSleep = false ; |
| 1574 | } else if (mPausingActivity != null) { |
Craig Mautner | 0eea92c | 2013-05-16 13:35:39 -0700 | [diff] [blame] | 1575 | // Still waiting for something to pause; can't sleep yet. |
Wale Ogunwale | ee006da | 2015-03-30 14:49:25 -0700 | [diff] [blame] | 1576 | if (DEBUG_PAUSE) Slog.v(TAG_PAUSE, "Sleep still waiting to pause " + mPausingActivity); |
David Stevens | 9440dc8 | 2017-03-16 19:00:20 -0700 | [diff] [blame] | 1577 | shouldSleep = false; |
Dianne Hackborn | 4eba96b | 2011-01-21 13:34:36 -0800 | [diff] [blame] | 1578 | } |
David Stevens | 9440dc8 | 2017-03-16 19:00:20 -0700 | [diff] [blame] | 1579 | |
| 1580 | if (!shuttingDown) { |
| 1581 | if (containsActivityFromStack(mStackSupervisor.mStoppingActivities)) { |
| 1582 | // Still need to tell some activities to stop; can't sleep yet. |
| 1583 | if (DEBUG_PAUSE) Slog.v(TAG_PAUSE, "Sleep still need to stop " |
| 1584 | + mStackSupervisor.mStoppingActivities.size() + " activities"); |
| 1585 | |
| 1586 | mStackSupervisor.scheduleIdleLocked(); |
| 1587 | shouldSleep = false; |
| 1588 | } |
| 1589 | |
| 1590 | if (containsActivityFromStack(mStackSupervisor.mGoingToSleepActivities)) { |
| 1591 | // Still need to tell some activities to sleep; can't sleep yet. |
| 1592 | if (DEBUG_PAUSE) Slog.v(TAG_PAUSE, "Sleep still need to sleep " |
| 1593 | + mStackSupervisor.mGoingToSleepActivities.size() + " activities"); |
| 1594 | shouldSleep = false; |
| 1595 | } |
| 1596 | } |
| 1597 | |
| 1598 | if (shouldSleep) { |
| 1599 | goToSleep(); |
| 1600 | } |
| 1601 | |
David Stevens | 18abd0e | 2017-08-17 14:55:47 -0700 | [diff] [blame] | 1602 | return shouldSleep; |
Craig Mautner | 0eea92c | 2013-05-16 13:35:39 -0700 | [diff] [blame] | 1603 | } |
Dianne Hackborn | 4eba96b | 2011-01-21 13:34:36 -0800 | [diff] [blame] | 1604 | |
David Stevens | 18abd0e | 2017-08-17 14:55:47 -0700 | [diff] [blame] | 1605 | void goToSleep() { |
Andrii Kulian | f4479ee | 2018-05-23 17:52:48 -0700 | [diff] [blame] | 1606 | // Ensure visibility without updating configuration, as activities are about to sleep. |
Andrii Kulian | a39ae3e | 2018-05-31 12:43:54 -0700 | [diff] [blame] | 1607 | ensureActivitiesVisibleLocked(null /* starting */, 0 /* configChanges */, |
| 1608 | !PRESERVE_WINDOWS); |
Dianne Hackborn | 4eba96b | 2011-01-21 13:34:36 -0800 | [diff] [blame] | 1609 | |
Andrii Kulian | f9949d5 | 2016-05-06 12:53:25 -0700 | [diff] [blame] | 1610 | // Make sure any paused or stopped but visible activities are now sleeping. |
Craig Mautner | 0eea92c | 2013-05-16 13:35:39 -0700 | [diff] [blame] | 1611 | // This ensures that the activity's onStop() is called. |
| 1612 | for (int taskNdx = mTaskHistory.size() - 1; taskNdx >= 0; --taskNdx) { |
| 1613 | final ArrayList<ActivityRecord> activities = mTaskHistory.get(taskNdx).mActivities; |
| 1614 | for (int activityNdx = activities.size() - 1; activityNdx >= 0; --activityNdx) { |
| 1615 | final ActivityRecord r = activities.get(activityNdx); |
Bryce Lee | 7ace395 | 2018-02-16 14:34:32 -0800 | [diff] [blame] | 1616 | if (r.isState(STOPPING, STOPPED, PAUSED, PAUSING)) { |
Craig Mautner | 0eea92c | 2013-05-16 13:35:39 -0700 | [diff] [blame] | 1617 | r.setSleeping(true); |
Dianne Hackborn | 4eba96b | 2011-01-21 13:34:36 -0800 | [diff] [blame] | 1618 | } |
| 1619 | } |
Dianne Hackborn | 4eba96b | 2011-01-21 13:34:36 -0800 | [diff] [blame] | 1620 | } |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 1621 | } |
Craig Mautner | 59c0097 | 2012-07-30 12:10:24 -0700 | [diff] [blame] | 1622 | |
David Stevens | 9440dc8 | 2017-03-16 19:00:20 -0700 | [diff] [blame] | 1623 | private boolean containsActivityFromStack(List<ActivityRecord> rs) { |
| 1624 | for (ActivityRecord r : rs) { |
Wale Ogunwale | 8b19de9 | 2018-11-29 19:58:26 -0800 | [diff] [blame] | 1625 | if (r.getActivityStack() == this) { |
David Stevens | 9440dc8 | 2017-03-16 19:00:20 -0700 | [diff] [blame] | 1626 | return true; |
| 1627 | } |
| 1628 | } |
| 1629 | return false; |
| 1630 | } |
| 1631 | |
Dianne Hackborn | a4e102e | 2014-09-04 22:52:27 -0700 | [diff] [blame] | 1632 | /** |
Winson Chung | 4dabf23 | 2017-01-25 13:25:22 -0800 | [diff] [blame] | 1633 | * Schedule a pause timeout in case the app doesn't respond. We don't give it much time because |
| 1634 | * this directly impacts the responsiveness seen by the user. |
| 1635 | */ |
| 1636 | private void schedulePauseTimeout(ActivityRecord r) { |
| 1637 | final Message msg = mHandler.obtainMessage(PAUSE_TIMEOUT_MSG); |
| 1638 | msg.obj = r; |
| 1639 | r.pauseTime = SystemClock.uptimeMillis(); |
| 1640 | mHandler.sendMessageDelayed(msg, PAUSE_TIMEOUT); |
| 1641 | if (DEBUG_PAUSE) Slog.v(TAG_PAUSE, "Waiting for pause to complete..."); |
| 1642 | } |
| 1643 | |
| 1644 | /** |
Dianne Hackborn | a4e102e | 2014-09-04 22:52:27 -0700 | [diff] [blame] | 1645 | * Start pausing the currently resumed activity. It is an error to call this if there |
| 1646 | * is already an activity being paused or there is no resumed activity. |
| 1647 | * |
| 1648 | * @param userLeaving True if this should result in an onUserLeaving to the current activity. |
| 1649 | * @param uiSleeping True if this is happening with the user interface going to sleep (the |
| 1650 | * screen turning off). |
Wale Ogunwale | 950faff | 2016-08-08 09:51:04 -0700 | [diff] [blame] | 1651 | * @param resuming The activity we are currently trying to resume or null if this is not being |
| 1652 | * called as part of resuming the top activity, so we shouldn't try to instigate |
| 1653 | * a resume here if not null. |
Winson Chung | 6954fc9 | 2017-03-24 16:22:12 -0700 | [diff] [blame] | 1654 | * @param pauseImmediately True if the caller does not want to wait for the activity callback to |
| 1655 | * complete pausing. |
Dianne Hackborn | a4e102e | 2014-09-04 22:52:27 -0700 | [diff] [blame] | 1656 | * @return Returns true if an activity now is in the PAUSING state, and we are waiting for |
| 1657 | * it to tell us when it is done. |
| 1658 | */ |
Wale Ogunwale | 950faff | 2016-08-08 09:51:04 -0700 | [diff] [blame] | 1659 | final boolean startPausingLocked(boolean userLeaving, boolean uiSleeping, |
Winson Chung | 6954fc9 | 2017-03-24 16:22:12 -0700 | [diff] [blame] | 1660 | ActivityRecord resuming, boolean pauseImmediately) { |
Dianne Hackborn | 621e2fe | 2012-02-16 17:07:33 -0800 | [diff] [blame] | 1661 | if (mPausingActivity != null) { |
riddle_hsu | 7dfe4d7 | 2015-02-16 18:43:49 +0800 | [diff] [blame] | 1662 | Slog.wtf(TAG, "Going to pause when pause is already pending for " + mPausingActivity |
Bryce Lee | 7ace395 | 2018-02-16 14:34:32 -0800 | [diff] [blame] | 1663 | + " state=" + mPausingActivity.getState()); |
David Stevens | 9440dc8 | 2017-03-16 19:00:20 -0700 | [diff] [blame] | 1664 | if (!shouldSleepActivities()) { |
riddle_hsu | 7dfe4d7 | 2015-02-16 18:43:49 +0800 | [diff] [blame] | 1665 | // Avoid recursion among check for sleep and complete pause during sleeping. |
| 1666 | // Because activity will be paused immediately after resume, just let pause |
| 1667 | // be completed by the order of activity paused from clients. |
Wale Ogunwale | 950faff | 2016-08-08 09:51:04 -0700 | [diff] [blame] | 1668 | completePauseLocked(false, resuming); |
riddle_hsu | 7dfe4d7 | 2015-02-16 18:43:49 +0800 | [diff] [blame] | 1669 | } |
Dianne Hackborn | 621e2fe | 2012-02-16 17:07:33 -0800 | [diff] [blame] | 1670 | } |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 1671 | ActivityRecord prev = mResumedActivity; |
Bryce Lee | 5daa312 | 2017-04-19 10:40:42 -0700 | [diff] [blame] | 1672 | |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 1673 | if (prev == null) { |
Wale Ogunwale | 950faff | 2016-08-08 09:51:04 -0700 | [diff] [blame] | 1674 | if (resuming == null) { |
Dianne Hackborn | a4e102e | 2014-09-04 22:52:27 -0700 | [diff] [blame] | 1675 | Slog.wtf(TAG, "Trying to pause when nothing is resumed"); |
Wale Ogunwale | d32da47 | 2018-11-16 07:19:28 -0800 | [diff] [blame] | 1676 | mRootActivityContainer.resumeFocusedStacksTopActivities(); |
Dianne Hackborn | a4e102e | 2014-09-04 22:52:27 -0700 | [diff] [blame] | 1677 | } |
| 1678 | return false; |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 1679 | } |
Craig Mautner | df88d73 | 2014-01-27 09:21:32 -0800 | [diff] [blame] | 1680 | |
Andrii Kulian | b1888aa | 2018-02-16 14:40:42 -0800 | [diff] [blame] | 1681 | if (prev == resuming) { |
| 1682 | Slog.wtf(TAG, "Trying to pause activity that is in process of being resumed"); |
| 1683 | return false; |
| 1684 | } |
| 1685 | |
Wale Ogunwale | 0fc365c | 2015-05-25 19:35:42 -0700 | [diff] [blame] | 1686 | if (DEBUG_STATES) Slog.v(TAG_STATES, "Moving to PAUSING: " + prev); |
Wale Ogunwale | ee006da | 2015-03-30 14:49:25 -0700 | [diff] [blame] | 1687 | else if (DEBUG_PAUSE) Slog.v(TAG_PAUSE, "Start pausing: " + prev); |
Dianne Hackborn | 621e2fe | 2012-02-16 17:07:33 -0800 | [diff] [blame] | 1688 | mPausingActivity = prev; |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 1689 | mLastPausedActivity = prev; |
Craig Mautner | 0f92274 | 2013-08-06 08:44:42 -0700 | [diff] [blame] | 1690 | mLastNoHistoryActivity = (prev.intent.getFlags() & Intent.FLAG_ACTIVITY_NO_HISTORY) != 0 |
| 1691 | || (prev.info.flags & ActivityInfo.FLAG_NO_HISTORY) != 0 ? prev : null; |
Bryce Lee | 7ace395 | 2018-02-16 14:34:32 -0800 | [diff] [blame] | 1692 | prev.setState(PAUSING, "startPausingLocked"); |
Wale Ogunwale | 8b19de9 | 2018-11-29 19:58:26 -0800 | [diff] [blame] | 1693 | prev.getTaskRecord().touchActiveTime(); |
Dianne Hackborn | 2286cdc | 2013-07-01 19:10:06 -0700 | [diff] [blame] | 1694 | clearLaunchTime(prev); |
Jorim Jaggi | e7d2b85 | 2017-08-28 17:55:15 +0200 | [diff] [blame] | 1695 | |
Wale Ogunwale | 5378374 | 2018-09-16 10:21:51 -0700 | [diff] [blame] | 1696 | mService.updateCpuStats(); |
Craig Mautner | aab647e | 2013-02-28 16:31:36 -0800 | [diff] [blame] | 1697 | |
Wale Ogunwale | 9e4f3e0 | 2018-05-17 09:35:39 -0700 | [diff] [blame] | 1698 | if (prev.attachedToProcess()) { |
Wale Ogunwale | ee006da | 2015-03-30 14:49:25 -0700 | [diff] [blame] | 1699 | if (DEBUG_PAUSE) Slog.v(TAG_PAUSE, "Enqueueing pending pause: " + prev); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 1700 | try { |
Wale Ogunwale | 8b19de9 | 2018-11-29 19:58:26 -0800 | [diff] [blame] | 1701 | EventLogTags.writeAmPauseActivity(prev.mUserId, System.identityHashCode(prev), |
Wale Ogunwale | c59b4f6 | 2017-11-30 11:05:43 -0800 | [diff] [blame] | 1702 | prev.shortComponentName, "userLeaving=" + userLeaving); |
Andrii Kulian | 446e824 | 2017-10-26 15:17:29 -0700 | [diff] [blame] | 1703 | |
Wale Ogunwale | 9e4f3e0 | 2018-05-17 09:35:39 -0700 | [diff] [blame] | 1704 | mService.getLifecycleManager().scheduleTransaction(prev.app.getThread(), |
| 1705 | prev.appToken, PauseActivityItem.obtain(prev.finishing, userLeaving, |
Bryce Lee | 1d0d514 | 2018-04-12 10:35:07 -0700 | [diff] [blame] | 1706 | prev.configChangeFlags, pauseImmediately)); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 1707 | } catch (Exception e) { |
| 1708 | // Ignore exception, if process died other code will cleanup. |
| 1709 | Slog.w(TAG, "Exception thrown during pause", e); |
Dianne Hackborn | 621e2fe | 2012-02-16 17:07:33 -0800 | [diff] [blame] | 1710 | mPausingActivity = null; |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 1711 | mLastPausedActivity = null; |
Craig Mautner | 0f92274 | 2013-08-06 08:44:42 -0700 | [diff] [blame] | 1712 | mLastNoHistoryActivity = null; |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 1713 | } |
| 1714 | } else { |
Dianne Hackborn | 621e2fe | 2012-02-16 17:07:33 -0800 | [diff] [blame] | 1715 | mPausingActivity = null; |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 1716 | mLastPausedActivity = null; |
Craig Mautner | 0f92274 | 2013-08-06 08:44:42 -0700 | [diff] [blame] | 1717 | mLastNoHistoryActivity = null; |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 1718 | } |
| 1719 | |
| 1720 | // If we are not going to sleep, we want to ensure the device is |
| 1721 | // awake until the next activity is started. |
Wale Ogunwale | f673393 | 2018-06-27 05:14:34 -0700 | [diff] [blame] | 1722 | if (!uiSleeping && !mService.isSleepingOrShuttingDownLocked()) { |
Craig Mautner | 7ea5bd4 | 2013-07-05 15:27:08 -0700 | [diff] [blame] | 1723 | mStackSupervisor.acquireLaunchWakelock(); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 1724 | } |
| 1725 | |
Dianne Hackborn | 621e2fe | 2012-02-16 17:07:33 -0800 | [diff] [blame] | 1726 | if (mPausingActivity != null) { |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 1727 | // Have the window manager pause its key dispatching until the new |
| 1728 | // activity has started. If we're pausing the activity just because |
| 1729 | // the screen is being turned off and the UI is sleeping, don't interrupt |
| 1730 | // key dispatch; the same activity will pick it up again on wakeup. |
| 1731 | if (!uiSleeping) { |
Dianne Hackborn | 621e2fe | 2012-02-16 17:07:33 -0800 | [diff] [blame] | 1732 | prev.pauseKeyDispatchingLocked(); |
Wale Ogunwale | ee006da | 2015-03-30 14:49:25 -0700 | [diff] [blame] | 1733 | } else if (DEBUG_PAUSE) { |
| 1734 | Slog.v(TAG_PAUSE, "Key dispatch not paused for screen off"); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 1735 | } |
| 1736 | |
Winson Chung | 6954fc9 | 2017-03-24 16:22:12 -0700 | [diff] [blame] | 1737 | if (pauseImmediately) { |
Dianne Hackborn | a4e102e | 2014-09-04 22:52:27 -0700 | [diff] [blame] | 1738 | // If the caller said they don't want to wait for the pause, then complete |
| 1739 | // the pause now. |
Wale Ogunwale | 950faff | 2016-08-08 09:51:04 -0700 | [diff] [blame] | 1740 | completePauseLocked(false, resuming); |
Dianne Hackborn | a4e102e | 2014-09-04 22:52:27 -0700 | [diff] [blame] | 1741 | return false; |
| 1742 | |
| 1743 | } else { |
Winson Chung | 4dabf23 | 2017-01-25 13:25:22 -0800 | [diff] [blame] | 1744 | schedulePauseTimeout(prev); |
Dianne Hackborn | a4e102e | 2014-09-04 22:52:27 -0700 | [diff] [blame] | 1745 | return true; |
| 1746 | } |
| 1747 | |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 1748 | } else { |
| 1749 | // This activity failed to schedule the |
| 1750 | // pause, so just treat it as being paused now. |
Wale Ogunwale | ee006da | 2015-03-30 14:49:25 -0700 | [diff] [blame] | 1751 | if (DEBUG_PAUSE) Slog.v(TAG_PAUSE, "Activity not running, resuming next."); |
Wale Ogunwale | 950faff | 2016-08-08 09:51:04 -0700 | [diff] [blame] | 1752 | if (resuming == null) { |
Wale Ogunwale | d32da47 | 2018-11-16 07:19:28 -0800 | [diff] [blame] | 1753 | mRootActivityContainer.resumeFocusedStacksTopActivities(); |
Dianne Hackborn | a4e102e | 2014-09-04 22:52:27 -0700 | [diff] [blame] | 1754 | } |
| 1755 | return false; |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 1756 | } |
| 1757 | } |
Dianne Hackborn | ad9b3211 | 2012-09-17 15:35:01 -0700 | [diff] [blame] | 1758 | |
Dianne Hackborn | a4e102e | 2014-09-04 22:52:27 -0700 | [diff] [blame] | 1759 | final void activityPausedLocked(IBinder token, boolean timeout) { |
Wale Ogunwale | ee006da | 2015-03-30 14:49:25 -0700 | [diff] [blame] | 1760 | if (DEBUG_PAUSE) Slog.v(TAG_PAUSE, |
| 1761 | "Activity paused: token=" + token + ", timeout=" + timeout); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 1762 | |
Craig Mautner | d232895 | 2013-03-05 12:46:26 -0800 | [diff] [blame] | 1763 | final ActivityRecord r = isInStackLocked(token); |
Andrii Kulian | 6b32151 | 2019-01-23 06:37:00 +0000 | [diff] [blame] | 1764 | |
Craig Mautner | d232895 | 2013-03-05 12:46:26 -0800 | [diff] [blame] | 1765 | if (r != null) { |
| 1766 | mHandler.removeMessages(PAUSE_TIMEOUT_MSG, r); |
| 1767 | if (mPausingActivity == r) { |
Wale Ogunwale | 0fc365c | 2015-05-25 19:35:42 -0700 | [diff] [blame] | 1768 | if (DEBUG_STATES) Slog.v(TAG_STATES, "Moving to PAUSED: " + r |
Craig Mautner | d232895 | 2013-03-05 12:46:26 -0800 | [diff] [blame] | 1769 | + (timeout ? " (due to timeout)" : " (pause complete)")); |
Jorim Jaggi | fe76234 | 2016-10-13 14:33:27 +0200 | [diff] [blame] | 1770 | mService.mWindowManager.deferSurfaceLayout(); |
| 1771 | try { |
Winson Chung | 3f103eb | 2017-04-12 21:53:59 -0700 | [diff] [blame] | 1772 | completePauseLocked(true /* resumeNext */, null /* resumingActivity */); |
Jorim Jaggi | fe76234 | 2016-10-13 14:33:27 +0200 | [diff] [blame] | 1773 | } finally { |
| 1774 | mService.mWindowManager.continueSurfaceLayout(); |
| 1775 | } |
Wale Ogunwale | 5658e4b | 2016-02-12 12:22:19 -0800 | [diff] [blame] | 1776 | return; |
Craig Mautner | d232895 | 2013-03-05 12:46:26 -0800 | [diff] [blame] | 1777 | } else { |
| 1778 | EventLog.writeEvent(EventLogTags.AM_FAILED_TO_PAUSE, |
Wale Ogunwale | 8b19de9 | 2018-11-29 19:58:26 -0800 | [diff] [blame] | 1779 | r.mUserId, System.identityHashCode(r), r.shortComponentName, |
Craig Mautner | d232895 | 2013-03-05 12:46:26 -0800 | [diff] [blame] | 1780 | mPausingActivity != null |
| 1781 | ? mPausingActivity.shortComponentName : "(none)"); |
Bryce Lee | 7ace395 | 2018-02-16 14:34:32 -0800 | [diff] [blame] | 1782 | if (r.isState(PAUSING)) { |
| 1783 | r.setState(PAUSED, "activityPausedLocked"); |
riddle_hsu | 9caeef7 | 2015-10-20 16:34:05 +0800 | [diff] [blame] | 1784 | if (r.finishing) { |
| 1785 | if (DEBUG_PAUSE) Slog.v(TAG, |
| 1786 | "Executing finish of failed to pause activity: " + r); |
Bryce Lee | f52974c | 2018-02-14 15:12:01 -0800 | [diff] [blame] | 1787 | finishCurrentActivityLocked(r, FINISH_AFTER_VISIBLE, false, |
| 1788 | "activityPausedLocked"); |
riddle_hsu | 9caeef7 | 2015-10-20 16:34:05 +0800 | [diff] [blame] | 1789 | } |
louis_chang | 047dfd4 | 2015-04-08 16:35:55 +0800 | [diff] [blame] | 1790 | } |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 1791 | } |
| 1792 | } |
Wale Ogunwale | d32da47 | 2018-11-16 07:19:28 -0800 | [diff] [blame] | 1793 | mRootActivityContainer.ensureActivitiesVisible(null, 0, !PRESERVE_WINDOWS); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 1794 | } |
| 1795 | |
Wale Ogunwale | 950faff | 2016-08-08 09:51:04 -0700 | [diff] [blame] | 1796 | private void completePauseLocked(boolean resumeNext, ActivityRecord resuming) { |
Dianne Hackborn | 621e2fe | 2012-02-16 17:07:33 -0800 | [diff] [blame] | 1797 | ActivityRecord prev = mPausingActivity; |
Wale Ogunwale | ee006da | 2015-03-30 14:49:25 -0700 | [diff] [blame] | 1798 | if (DEBUG_PAUSE) Slog.v(TAG_PAUSE, "Complete pause: " + prev); |
Craig Mautner | aab647e | 2013-02-28 16:31:36 -0800 | [diff] [blame] | 1799 | |
Dianne Hackborn | 621e2fe | 2012-02-16 17:07:33 -0800 | [diff] [blame] | 1800 | if (prev != null) { |
chaviw | 4ad5491 | 2018-05-30 11:05:44 -0700 | [diff] [blame] | 1801 | prev.setWillCloseOrEnterPip(false); |
Bryce Lee | 7ace395 | 2018-02-16 14:34:32 -0800 | [diff] [blame] | 1802 | final boolean wasStopping = prev.isState(STOPPING); |
| 1803 | prev.setState(PAUSED, "completePausedLocked"); |
Dianne Hackborn | 621e2fe | 2012-02-16 17:07:33 -0800 | [diff] [blame] | 1804 | if (prev.finishing) { |
Wale Ogunwale | ee006da | 2015-03-30 14:49:25 -0700 | [diff] [blame] | 1805 | if (DEBUG_PAUSE) Slog.v(TAG_PAUSE, "Executing finish of activity: " + prev); |
Bryce Lee | f52974c | 2018-02-14 15:12:01 -0800 | [diff] [blame] | 1806 | prev = finishCurrentActivityLocked(prev, FINISH_AFTER_VISIBLE, false, |
| 1807 | "completedPausedLocked"); |
Wale Ogunwale | 9e4f3e0 | 2018-05-17 09:35:39 -0700 | [diff] [blame] | 1808 | } else if (prev.hasProcess()) { |
Wale Ogunwale | d802664 | 2016-02-09 20:40:18 -0800 | [diff] [blame] | 1809 | if (DEBUG_PAUSE) Slog.v(TAG_PAUSE, "Enqueue pending stop if needed: " + prev |
| 1810 | + " wasStopping=" + wasStopping + " visible=" + prev.visible); |
Wale Ogunwale | f81c1d1 | 2016-01-12 12:20:18 -0800 | [diff] [blame] | 1811 | if (prev.deferRelaunchUntilPaused) { |
| 1812 | // Complete the deferred relaunch that was waiting for pause to complete. |
| 1813 | if (DEBUG_PAUSE) Slog.v(TAG_PAUSE, "Re-launching after pause: " + prev); |
Andrii Kulian | 21713ac | 2016-10-12 22:05:05 -0700 | [diff] [blame] | 1814 | prev.relaunchActivityLocked(false /* andResume */, |
Wale Ogunwale | f81c1d1 | 2016-01-12 12:20:18 -0800 | [diff] [blame] | 1815 | prev.preserveWindowOnDeferredRelaunch); |
Filip Gruszczynski | dba623a | 2015-12-04 15:45:35 -0800 | [diff] [blame] | 1816 | } else if (wasStopping) { |
| 1817 | // We are also stopping, the stop request must have gone soon after the pause. |
| 1818 | // We can't clobber it, because the stop confirmation will not be handled. |
| 1819 | // We don't need to schedule another stop, we only need to let it happen. |
Bryce Lee | 7ace395 | 2018-02-16 14:34:32 -0800 | [diff] [blame] | 1820 | prev.setState(STOPPING, "completePausedLocked"); |
David Stevens | 9440dc8 | 2017-03-16 19:00:20 -0700 | [diff] [blame] | 1821 | } else if (!prev.visible || shouldSleepOrShutDownActivities()) { |
Wale Ogunwale | ec95064 | 2017-04-25 07:44:21 -0700 | [diff] [blame] | 1822 | // Clear out any deferred client hide we might currently have. |
| 1823 | prev.setDeferHidingClient(false); |
Jose Lima | 4b6c669 | 2014-08-12 17:41:12 -0700 | [diff] [blame] | 1824 | // If we were visible then resumeTopActivities will release resources before |
Wale Ogunwale | ec95064 | 2017-04-25 07:44:21 -0700 | [diff] [blame] | 1825 | // stopping. |
Winson Chung | 4dabf23 | 2017-01-25 13:25:22 -0800 | [diff] [blame] | 1826 | addToStopping(prev, true /* scheduleIdle */, false /* idleDelayed */); |
Dianne Hackborn | 621e2fe | 2012-02-16 17:07:33 -0800 | [diff] [blame] | 1827 | } |
| 1828 | } else { |
Wale Ogunwale | ee006da | 2015-03-30 14:49:25 -0700 | [diff] [blame] | 1829 | 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] | 1830 | prev = null; |
Dianne Hackborn | cbb722e | 2012-02-07 18:33:49 -0800 | [diff] [blame] | 1831 | } |
Wale Ogunwale | 07927bf | 2015-03-28 17:21:05 -0700 | [diff] [blame] | 1832 | // It is possible the activity was freezing the screen before it was paused. |
| 1833 | // In that case go ahead and remove the freeze this activity has on the screen |
| 1834 | // since it is no longer visible. |
Wale Ogunwale | e852400 | 2016-09-13 16:34:57 -0700 | [diff] [blame] | 1835 | if (prev != null) { |
| 1836 | prev.stopFreezingScreenLocked(true /*force*/); |
| 1837 | } |
Dianne Hackborn | 621e2fe | 2012-02-16 17:07:33 -0800 | [diff] [blame] | 1838 | mPausingActivity = null; |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 1839 | } |
Dianne Hackborn | cbb722e | 2012-02-07 18:33:49 -0800 | [diff] [blame] | 1840 | |
Dianne Hackborn | a4e102e | 2014-09-04 22:52:27 -0700 | [diff] [blame] | 1841 | if (resumeNext) { |
Wale Ogunwale | d32da47 | 2018-11-16 07:19:28 -0800 | [diff] [blame] | 1842 | final ActivityStack topStack = mRootActivityContainer.getTopDisplayFocusedStack(); |
David Stevens | 9440dc8 | 2017-03-16 19:00:20 -0700 | [diff] [blame] | 1843 | if (!topStack.shouldSleepOrShutDownActivities()) { |
Wale Ogunwale | d32da47 | 2018-11-16 07:19:28 -0800 | [diff] [blame] | 1844 | mRootActivityContainer.resumeFocusedStacksTopActivities(topStack, prev, null); |
Dianne Hackborn | a4e102e | 2014-09-04 22:52:27 -0700 | [diff] [blame] | 1845 | } else { |
David Stevens | 9440dc8 | 2017-03-16 19:00:20 -0700 | [diff] [blame] | 1846 | checkReadyForSleep(); |
Filip Gruszczynski | 3e85ba2 | 2015-10-05 22:48:30 -0700 | [diff] [blame] | 1847 | ActivityRecord top = topStack.topRunningActivityLocked(); |
Dianne Hackborn | a4e102e | 2014-09-04 22:52:27 -0700 | [diff] [blame] | 1848 | if (top == null || (prev != null && top != prev)) { |
Wale Ogunwale | d046a01 | 2015-12-24 13:05:59 -0800 | [diff] [blame] | 1849 | // If there are no more activities available to run, do resume anyway to start |
| 1850 | // something. Also if the top activity on the stack is not the just paused |
| 1851 | // activity, we need to go ahead and resume it to ensure we complete an |
| 1852 | // in-flight app switch. |
Wale Ogunwale | d32da47 | 2018-11-16 07:19:28 -0800 | [diff] [blame] | 1853 | mRootActivityContainer.resumeFocusedStacksTopActivities(); |
Dianne Hackborn | a4e102e | 2014-09-04 22:52:27 -0700 | [diff] [blame] | 1854 | } |
Dianne Hackborn | 42e620c | 2012-06-24 13:20:51 -0700 | [diff] [blame] | 1855 | } |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 1856 | } |
Craig Mautner | aab647e | 2013-02-28 16:31:36 -0800 | [diff] [blame] | 1857 | |
Dianne Hackborn | 621e2fe | 2012-02-16 17:07:33 -0800 | [diff] [blame] | 1858 | if (prev != null) { |
| 1859 | prev.resumeKeyDispatchingLocked(); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 1860 | |
Louis Chang | 1bb884a | 2018-10-08 19:29:18 +0800 | [diff] [blame] | 1861 | if (prev.hasProcess() && prev.cpuTimeAtResume > 0) { |
| 1862 | final long diff = prev.app.getCpuTime() - prev.cpuTimeAtResume; |
| 1863 | if (diff > 0) { |
| 1864 | final Runnable r = PooledLambda.obtainRunnable( |
| 1865 | ActivityManagerInternal::updateForegroundTimeIfOnBattery, |
| 1866 | mService.mAmInternal, prev.info.packageName, |
| 1867 | prev.info.applicationInfo.uid, |
| 1868 | diff); |
| 1869 | mService.mH.post(r); |
| 1870 | } |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 1871 | } |
Craig Mautner | 525f3d9 | 2013-05-07 14:01:50 -0700 | [diff] [blame] | 1872 | prev.cpuTimeAtResume = 0; // reset it |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 1873 | } |
Winson Chung | 740c3ac | 2014-11-12 16:14:38 -0800 | [diff] [blame] | 1874 | |
Andrii Kulian | 8290f8f | 2016-06-30 17:51:32 -0700 | [diff] [blame] | 1875 | // Notify when the task stack has changed, but only if visibilities changed (not just |
| 1876 | // focus). Also if there is an active pinned stack - we always want to notify it about |
| 1877 | // task stack changes, because its positioning may depend on it. |
| 1878 | if (mStackSupervisor.mAppVisibilitiesChangedSinceLastPause |
Louis Chang | 24f7a03 | 2018-12-11 10:49:48 +0800 | [diff] [blame] | 1879 | || (getDisplay() != null && getDisplay().hasPinnedStack())) { |
Wale Ogunwale | 5fa8a8c | 2018-05-08 13:43:21 -0700 | [diff] [blame] | 1880 | mService.getTaskChangeNotificationController().notifyTaskStackChanged(); |
Jorim Jaggi | a0fdeec | 2016-01-07 14:42:28 +0100 | [diff] [blame] | 1881 | mStackSupervisor.mAppVisibilitiesChangedSinceLastPause = false; |
| 1882 | } |
Wale Ogunwale | 5658e4b | 2016-02-12 12:22:19 -0800 | [diff] [blame] | 1883 | |
Wale Ogunwale | d32da47 | 2018-11-16 07:19:28 -0800 | [diff] [blame] | 1884 | mRootActivityContainer.ensureActivitiesVisible(resuming, 0, !PRESERVE_WINDOWS); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 1885 | } |
| 1886 | |
Wale Ogunwale | 5378374 | 2018-09-16 10:21:51 -0700 | [diff] [blame] | 1887 | private void addToStopping(ActivityRecord r, boolean scheduleIdle, boolean idleDelayed) { |
Chong Zhang | 46b1ac6 | 2016-02-18 17:53:57 -0800 | [diff] [blame] | 1888 | if (!mStackSupervisor.mStoppingActivities.contains(r)) { |
| 1889 | mStackSupervisor.mStoppingActivities.add(r); |
| 1890 | } |
| 1891 | |
| 1892 | // If we already have a few activities waiting to stop, then give up |
| 1893 | // on things going idle and start clearing them out. Or if r is the |
| 1894 | // last of activity of the last task the stack will be empty and must |
| 1895 | // be cleared immediately. |
| 1896 | boolean forceIdle = mStackSupervisor.mStoppingActivities.size() > MAX_STOPPING_TO_FORCE |
| 1897 | || (r.frontOfTask && mTaskHistory.size() <= 1); |
Winson Chung | 4dabf23 | 2017-01-25 13:25:22 -0800 | [diff] [blame] | 1898 | if (scheduleIdle || forceIdle) { |
Chong Zhang | 46b1ac6 | 2016-02-18 17:53:57 -0800 | [diff] [blame] | 1899 | if (DEBUG_PAUSE) Slog.v(TAG_PAUSE, "Scheduling idle now: forceIdle=" |
Winson Chung | 4dabf23 | 2017-01-25 13:25:22 -0800 | [diff] [blame] | 1900 | + forceIdle + "immediate=" + !idleDelayed); |
| 1901 | if (!idleDelayed) { |
| 1902 | mStackSupervisor.scheduleIdleLocked(); |
| 1903 | } else { |
| 1904 | mStackSupervisor.scheduleIdleTimeoutLocked(r); |
| 1905 | } |
Filip Gruszczynski | ef2f72b | 2015-12-04 14:52:25 -0800 | [diff] [blame] | 1906 | } else { |
David Stevens | 9440dc8 | 2017-03-16 19:00:20 -0700 | [diff] [blame] | 1907 | checkReadyForSleep(); |
Filip Gruszczynski | ef2f72b | 2015-12-04 14:52:25 -0800 | [diff] [blame] | 1908 | } |
| 1909 | } |
| 1910 | |
Wale Ogunwale | 8051c5c | 2016-03-04 10:27:32 -0800 | [diff] [blame] | 1911 | /** |
| 1912 | * Returns true if the stack is translucent and can have other contents visible behind it if |
| 1913 | * needed. A stack is considered translucent if it don't contain a visible or |
| 1914 | * starting (about to be visible) activity that is fullscreen (opaque). |
| 1915 | * @param starting The currently starting activity or null if there is none. |
| 1916 | */ |
Wale Ogunwale | 7e1f5f5 | 2017-10-18 15:19:59 -0700 | [diff] [blame] | 1917 | @VisibleForTesting |
Wale Ogunwale | 66e1685 | 2017-10-19 13:35:52 -0700 | [diff] [blame] | 1918 | boolean isStackTranslucent(ActivityRecord starting) { |
Wale Ogunwale | 7e1f5f5 | 2017-10-18 15:19:59 -0700 | [diff] [blame] | 1919 | if (!isAttached() || mForceHidden) { |
| 1920 | return true; |
| 1921 | } |
Wale Ogunwale | 8051c5c | 2016-03-04 10:27:32 -0800 | [diff] [blame] | 1922 | for (int taskNdx = mTaskHistory.size() - 1; taskNdx >= 0; --taskNdx) { |
| 1923 | final TaskRecord task = mTaskHistory.get(taskNdx); |
Wale Ogunwale | 1e3523c | 2015-09-16 13:11:10 -0700 | [diff] [blame] | 1924 | final ArrayList<ActivityRecord> activities = task.mActivities; |
| 1925 | for (int activityNdx = activities.size() - 1; activityNdx >= 0; --activityNdx) { |
| 1926 | final ActivityRecord r = activities.get(activityNdx); |
Wale Ogunwale | b34a7ad | 2015-08-14 11:05:30 -0700 | [diff] [blame] | 1927 | |
Wale Ogunwale | 56d75cf | 2016-03-09 15:14:47 -0800 | [diff] [blame] | 1928 | if (r.finishing) { |
| 1929 | // We don't factor in finishing activities when determining translucency since |
| 1930 | // they will be gone soon. |
| 1931 | continue; |
| 1932 | } |
| 1933 | |
Wale Ogunwale | 2cca862 | 2017-12-11 08:40:13 -0800 | [diff] [blame] | 1934 | if (!r.visibleIgnoringKeyguard && r != starting) { |
Wale Ogunwale | 56d75cf | 2016-03-09 15:14:47 -0800 | [diff] [blame] | 1935 | // Also ignore invisible activities that are not the currently starting |
| 1936 | // activity (about to be visible). |
| 1937 | continue; |
| 1938 | } |
| 1939 | |
Wale Ogunwale | 7e1f5f5 | 2017-10-18 15:19:59 -0700 | [diff] [blame] | 1940 | if (r.fullscreen || r.hasWallpaper) { |
Wale Ogunwale | 56d75cf | 2016-03-09 15:14:47 -0800 | [diff] [blame] | 1941 | // Stack isn't translucent if it has at least one fullscreen activity |
| 1942 | // that is visible. |
| 1943 | return false; |
| 1944 | } |
Wale Ogunwale | b34a7ad | 2015-08-14 11:05:30 -0700 | [diff] [blame] | 1945 | } |
| 1946 | } |
Wale Ogunwale | 1e3523c | 2015-09-16 13:11:10 -0700 | [diff] [blame] | 1947 | return true; |
Wale Ogunwale | b34a7ad | 2015-08-14 11:05:30 -0700 | [diff] [blame] | 1948 | } |
| 1949 | |
Wale Ogunwale | a0f5b5e | 2017-10-11 09:37:23 -0700 | [diff] [blame] | 1950 | boolean isTopStackOnDisplay() { |
Andrii Kulian | 52d255c | 2018-07-13 11:32:19 -0700 | [diff] [blame] | 1951 | final ActivityDisplay display = getDisplay(); |
| 1952 | return display != null && display.isTopStack(this); |
| 1953 | } |
| 1954 | |
| 1955 | /** |
| 1956 | * @return {@code true} if this is the focused stack on its current display, {@code false} |
| 1957 | * otherwise. |
| 1958 | */ |
| 1959 | boolean isFocusedStackOnDisplay() { |
| 1960 | final ActivityDisplay display = getDisplay(); |
| 1961 | return display != null && this == display.getFocusedStack(); |
Wale Ogunwale | a0f5b5e | 2017-10-11 09:37:23 -0700 | [diff] [blame] | 1962 | } |
| 1963 | |
Adrian Roos | a6d6aab | 2018-04-19 18:58:22 +0200 | [diff] [blame] | 1964 | boolean isTopActivityVisible() { |
| 1965 | final ActivityRecord topActivity = getTopActivity(); |
| 1966 | return topActivity != null && topActivity.visible; |
| 1967 | } |
| 1968 | |
Filip Gruszczynski | 0e381e2 | 2016-01-14 16:31:33 -0800 | [diff] [blame] | 1969 | /** |
Wale Ogunwale | 9dcf946 | 2017-09-19 15:13:01 -0700 | [diff] [blame] | 1970 | * Returns true if the stack should be visible. |
Wale Ogunwale | cd501ec | 2017-04-07 08:53:41 -0700 | [diff] [blame] | 1971 | * |
Wale Ogunwale | 8051c5c | 2016-03-04 10:27:32 -0800 | [diff] [blame] | 1972 | * @param starting The currently starting activity or null if there is none. |
Filip Gruszczynski | 0e381e2 | 2016-01-14 16:31:33 -0800 | [diff] [blame] | 1973 | */ |
Wale Ogunwale | 9dcf946 | 2017-09-19 15:13:01 -0700 | [diff] [blame] | 1974 | boolean shouldBeVisible(ActivityRecord starting) { |
Andrii Kulian | 0c869cc | 2019-02-06 19:50:32 -0800 | [diff] [blame] | 1975 | return getVisibility(starting) != STACK_VISIBILITY_INVISIBLE; |
| 1976 | } |
| 1977 | |
| 1978 | /** |
| 1979 | * Returns true if the stack should be visible. |
| 1980 | * |
| 1981 | * @param starting The currently starting activity or null if there is none. |
| 1982 | */ |
| 1983 | @StackVisibility |
| 1984 | int getVisibility(ActivityRecord starting) { |
Winson Chung | 4790065 | 2017-04-06 18:44:25 -0700 | [diff] [blame] | 1985 | if (!isAttached() || mForceHidden) { |
Andrii Kulian | 0c869cc | 2019-02-06 19:50:32 -0800 | [diff] [blame] | 1986 | return STACK_VISIBILITY_INVISIBLE; |
Jose Lima | 7ba7125 | 2014-04-30 12:59:27 -0700 | [diff] [blame] | 1987 | } |
Wale Ogunwale | 99db186 | 2015-10-23 20:08:22 -0700 | [diff] [blame] | 1988 | |
Wale Ogunwale | 7e1f5f5 | 2017-10-18 15:19:59 -0700 | [diff] [blame] | 1989 | final ActivityDisplay display = getDisplay(); |
Wale Ogunwale | 8e923af | 2018-03-23 08:48:11 -0700 | [diff] [blame] | 1990 | boolean gotSplitScreenStack = false; |
Wale Ogunwale | 7e1f5f5 | 2017-10-18 15:19:59 -0700 | [diff] [blame] | 1991 | boolean gotOpaqueSplitScreenPrimary = false; |
| 1992 | boolean gotOpaqueSplitScreenSecondary = false; |
Andrii Kulian | 0c869cc | 2019-02-06 19:50:32 -0800 | [diff] [blame] | 1993 | boolean gotTranslucentFullscreen = false; |
| 1994 | boolean gotTranslucentSplitScreenPrimary = false; |
| 1995 | boolean gotTranslucentSplitScreenSecondary = false; |
| 1996 | boolean shouldBeVisible = true; |
Wale Ogunwale | 6827856 | 2017-09-23 17:13:55 -0700 | [diff] [blame] | 1997 | final int windowingMode = getWindowingMode(); |
Wale Ogunwale | 8e923af | 2018-03-23 08:48:11 -0700 | [diff] [blame] | 1998 | final boolean isAssistantType = isActivityTypeAssistant(); |
Wale Ogunwale | 7e1f5f5 | 2017-10-18 15:19:59 -0700 | [diff] [blame] | 1999 | for (int i = display.getChildCount() - 1; i >= 0; --i) { |
| 2000 | final ActivityStack other = display.getChildAt(i); |
Louis Chang | f2835df | 2018-10-17 15:14:45 +0800 | [diff] [blame] | 2001 | final boolean hasRunningActivities = other.topRunningActivityLocked() != null; |
Wale Ogunwale | 7e1f5f5 | 2017-10-18 15:19:59 -0700 | [diff] [blame] | 2002 | if (other == this) { |
Louis Chang | f2835df | 2018-10-17 15:14:45 +0800 | [diff] [blame] | 2003 | // Should be visible if there is no other stack occluding it, unless it doesn't |
| 2004 | // have any running activities, not starting one and not home stack. |
Andrii Kulian | 0c869cc | 2019-02-06 19:50:32 -0800 | [diff] [blame] | 2005 | shouldBeVisible = hasRunningActivities || isInStackLocked(starting) != null |
Louis Chang | f2835df | 2018-10-17 15:14:45 +0800 | [diff] [blame] | 2006 | || isActivityTypeHome(); |
Andrii Kulian | 0c869cc | 2019-02-06 19:50:32 -0800 | [diff] [blame] | 2007 | break; |
Louis Chang | f2835df | 2018-10-17 15:14:45 +0800 | [diff] [blame] | 2008 | } |
| 2009 | |
| 2010 | if (!hasRunningActivities) { |
| 2011 | continue; |
Wale Ogunwale | 7e1f5f5 | 2017-10-18 15:19:59 -0700 | [diff] [blame] | 2012 | } |
Wale Ogunwale | 6827856 | 2017-09-23 17:13:55 -0700 | [diff] [blame] | 2013 | |
Wale Ogunwale | 7e1f5f5 | 2017-10-18 15:19:59 -0700 | [diff] [blame] | 2014 | final int otherWindowingMode = other.getWindowingMode(); |
Wale Ogunwale | 7e1f5f5 | 2017-10-18 15:19:59 -0700 | [diff] [blame] | 2015 | |
| 2016 | if (otherWindowingMode == WINDOWING_MODE_FULLSCREEN) { |
Matthew Ng | 99b3cdc | 2018-05-01 14:24:38 -0700 | [diff] [blame] | 2017 | // In this case the home stack isn't resizeable even though we are in split-screen |
| 2018 | // mode. We still want the primary splitscreen stack to be visible as there will be |
| 2019 | // a slight hint of it in the status bar area above the non-resizeable home |
Matthew Ng | a51dcaa | 2018-05-07 15:36:06 -0700 | [diff] [blame] | 2020 | // activity. In addition, if the fullscreen assistant is over primary splitscreen |
| 2021 | // stack, the stack should still be visible in the background as long as the recents |
| 2022 | // animation is running. |
| 2023 | final int activityType = other.getActivityType(); |
| 2024 | if (windowingMode == WINDOWING_MODE_SPLIT_SCREEN_PRIMARY) { |
| 2025 | if (activityType == ACTIVITY_TYPE_HOME |
| 2026 | || (activityType == ACTIVITY_TYPE_ASSISTANT |
Andrii Kulian | 0c869cc | 2019-02-06 19:50:32 -0800 | [diff] [blame] | 2027 | && mWindowManager.getRecentsAnimationController() != null)) { |
| 2028 | break; |
Matthew Ng | a51dcaa | 2018-05-07 15:36:06 -0700 | [diff] [blame] | 2029 | } |
Matthew Ng | 99b3cdc | 2018-05-01 14:24:38 -0700 | [diff] [blame] | 2030 | } |
Wale Ogunwale | 66e1685 | 2017-10-19 13:35:52 -0700 | [diff] [blame] | 2031 | if (other.isStackTranslucent(starting)) { |
Wale Ogunwale | 7e1f5f5 | 2017-10-18 15:19:59 -0700 | [diff] [blame] | 2032 | // Can be visible behind a translucent fullscreen stack. |
Andrii Kulian | 0c869cc | 2019-02-06 19:50:32 -0800 | [diff] [blame] | 2033 | gotTranslucentFullscreen = true; |
Wale Ogunwale | 7e1f5f5 | 2017-10-18 15:19:59 -0700 | [diff] [blame] | 2034 | continue; |
| 2035 | } |
Andrii Kulian | 0c869cc | 2019-02-06 19:50:32 -0800 | [diff] [blame] | 2036 | return STACK_VISIBILITY_INVISIBLE; |
Wale Ogunwale | 7e1f5f5 | 2017-10-18 15:19:59 -0700 | [diff] [blame] | 2037 | } else if (otherWindowingMode == WINDOWING_MODE_SPLIT_SCREEN_PRIMARY |
| 2038 | && !gotOpaqueSplitScreenPrimary) { |
Wale Ogunwale | 8e923af | 2018-03-23 08:48:11 -0700 | [diff] [blame] | 2039 | gotSplitScreenStack = true; |
Andrii Kulian | 0c869cc | 2019-02-06 19:50:32 -0800 | [diff] [blame] | 2040 | gotTranslucentSplitScreenPrimary = other.isStackTranslucent(starting); |
| 2041 | gotOpaqueSplitScreenPrimary = !gotTranslucentSplitScreenPrimary; |
Wale Ogunwale | 7e1f5f5 | 2017-10-18 15:19:59 -0700 | [diff] [blame] | 2042 | if (windowingMode == WINDOWING_MODE_SPLIT_SCREEN_PRIMARY |
| 2043 | && gotOpaqueSplitScreenPrimary) { |
| 2044 | // Can not be visible behind another opaque stack in split-screen-primary mode. |
Andrii Kulian | 0c869cc | 2019-02-06 19:50:32 -0800 | [diff] [blame] | 2045 | return STACK_VISIBILITY_INVISIBLE; |
Wale Ogunwale | 7e1f5f5 | 2017-10-18 15:19:59 -0700 | [diff] [blame] | 2046 | } |
| 2047 | } else if (otherWindowingMode == WINDOWING_MODE_SPLIT_SCREEN_SECONDARY |
| 2048 | && !gotOpaqueSplitScreenSecondary) { |
Wale Ogunwale | 8e923af | 2018-03-23 08:48:11 -0700 | [diff] [blame] | 2049 | gotSplitScreenStack = true; |
Andrii Kulian | 0c869cc | 2019-02-06 19:50:32 -0800 | [diff] [blame] | 2050 | gotTranslucentSplitScreenSecondary = other.isStackTranslucent(starting); |
| 2051 | gotOpaqueSplitScreenSecondary = !gotTranslucentSplitScreenSecondary; |
Wale Ogunwale | 7e1f5f5 | 2017-10-18 15:19:59 -0700 | [diff] [blame] | 2052 | if (windowingMode == WINDOWING_MODE_SPLIT_SCREEN_SECONDARY |
| 2053 | && gotOpaqueSplitScreenSecondary) { |
| 2054 | // Can not be visible behind another opaque stack in split-screen-secondary mode. |
Andrii Kulian | 0c869cc | 2019-02-06 19:50:32 -0800 | [diff] [blame] | 2055 | return STACK_VISIBILITY_INVISIBLE; |
Wale Ogunwale | 7e1f5f5 | 2017-10-18 15:19:59 -0700 | [diff] [blame] | 2056 | } |
| 2057 | } |
| 2058 | if (gotOpaqueSplitScreenPrimary && gotOpaqueSplitScreenSecondary) { |
| 2059 | // Can not be visible if we are in split-screen windowing mode and both halves of |
| 2060 | // the screen are opaque. |
Andrii Kulian | 0c869cc | 2019-02-06 19:50:32 -0800 | [diff] [blame] | 2061 | return STACK_VISIBILITY_INVISIBLE; |
Wale Ogunwale | 7e1f5f5 | 2017-10-18 15:19:59 -0700 | [diff] [blame] | 2062 | } |
Wale Ogunwale | 8e923af | 2018-03-23 08:48:11 -0700 | [diff] [blame] | 2063 | if (isAssistantType && gotSplitScreenStack) { |
| 2064 | // Assistant stack can't be visible behind split-screen. In addition to this not |
| 2065 | // making sense, it also works around an issue here we boost the z-order of the |
| 2066 | // assistant window surfaces in window manager whenever it is visible. |
Andrii Kulian | 0c869cc | 2019-02-06 19:50:32 -0800 | [diff] [blame] | 2067 | return STACK_VISIBILITY_INVISIBLE; |
Wale Ogunwale | 8e923af | 2018-03-23 08:48:11 -0700 | [diff] [blame] | 2068 | } |
Wale Ogunwale | 7e1f5f5 | 2017-10-18 15:19:59 -0700 | [diff] [blame] | 2069 | } |
| 2070 | |
Andrii Kulian | 0c869cc | 2019-02-06 19:50:32 -0800 | [diff] [blame] | 2071 | if (!shouldBeVisible) { |
| 2072 | return STACK_VISIBILITY_INVISIBLE; |
| 2073 | } |
| 2074 | |
| 2075 | // Handle cases when there can be a translucent split-screen stack on top. |
| 2076 | switch (windowingMode) { |
| 2077 | case WINDOWING_MODE_FULLSCREEN: |
| 2078 | if (gotTranslucentSplitScreenPrimary || gotTranslucentSplitScreenSecondary) { |
| 2079 | // At least one of the split-screen stacks that covers this one is translucent. |
| 2080 | return STACK_VISIBILITY_VISIBLE_BEHIND_TRANSLUCENT; |
| 2081 | } |
| 2082 | break; |
| 2083 | case WINDOWING_MODE_SPLIT_SCREEN_PRIMARY: |
| 2084 | if (gotTranslucentSplitScreenPrimary) { |
| 2085 | // Covered by translucent primary split-screen on top. |
| 2086 | return STACK_VISIBILITY_VISIBLE_BEHIND_TRANSLUCENT; |
| 2087 | } |
| 2088 | break; |
| 2089 | case WINDOWING_MODE_SPLIT_SCREEN_SECONDARY: |
| 2090 | if (gotTranslucentSplitScreenSecondary) { |
| 2091 | // Covered by translucent secondary split-screen on top. |
| 2092 | return STACK_VISIBILITY_VISIBLE_BEHIND_TRANSLUCENT; |
| 2093 | } |
| 2094 | break; |
| 2095 | } |
| 2096 | |
| 2097 | // Lastly - check if there is a translucent fullscreen stack on top. |
| 2098 | return gotTranslucentFullscreen ? STACK_VISIBILITY_VISIBLE_BEHIND_TRANSLUCENT |
| 2099 | : STACK_VISIBILITY_VISIBLE; |
Wale Ogunwale | 6827856 | 2017-09-23 17:13:55 -0700 | [diff] [blame] | 2100 | } |
| 2101 | |
Chong Zhang | fdcc4d4 | 2015-10-14 16:50:12 -0700 | [diff] [blame] | 2102 | final int rankTaskLayers(int baseLayer) { |
| 2103 | int layer = 0; |
| 2104 | for (int taskNdx = mTaskHistory.size() - 1; taskNdx >= 0; --taskNdx) { |
| 2105 | final TaskRecord task = mTaskHistory.get(taskNdx); |
| 2106 | ActivityRecord r = task.topRunningActivityLocked(); |
| 2107 | if (r == null || r.finishing || !r.visible) { |
| 2108 | task.mLayerRank = -1; |
| 2109 | } else { |
| 2110 | task.mLayerRank = baseLayer + layer++; |
| 2111 | } |
| 2112 | } |
| 2113 | return layer; |
| 2114 | } |
| 2115 | |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 2116 | /** |
Andrii Kulian | f4479ee | 2018-05-23 17:52:48 -0700 | [diff] [blame] | 2117 | * Make sure that all activities that need to be visible in the stack (that is, they |
| 2118 | * currently can be seen by the user) actually are and update their configuration. |
| 2119 | */ |
| 2120 | final void ensureActivitiesVisibleLocked(ActivityRecord starting, int configChanges, |
| 2121 | boolean preserveWindows) { |
| 2122 | ensureActivitiesVisibleLocked(starting, configChanges, preserveWindows, |
Andrii Kulian | a39ae3e | 2018-05-31 12:43:54 -0700 | [diff] [blame] | 2123 | true /* notifyClients */); |
Andrii Kulian | f4479ee | 2018-05-23 17:52:48 -0700 | [diff] [blame] | 2124 | } |
| 2125 | |
| 2126 | /** |
| 2127 | * Ensure visibility with an option to also update the configuration of visible activities. |
| 2128 | * @see #ensureActivitiesVisibleLocked(ActivityRecord, int, boolean) |
Wale Ogunwale | d32da47 | 2018-11-16 07:19:28 -0800 | [diff] [blame] | 2129 | * @see RootActivityContainer#ensureActivitiesVisible(ActivityRecord, int, boolean) |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 2130 | */ |
Wale Ogunwale | 66e1685 | 2017-10-19 13:35:52 -0700 | [diff] [blame] | 2131 | // TODO: Should be re-worked based on the fact that each task as a stack in most cases. |
Filip Gruszczynski | bc5a6c5 | 2015-09-22 13:13:24 -0700 | [diff] [blame] | 2132 | final void ensureActivitiesVisibleLocked(ActivityRecord starting, int configChanges, |
Andrii Kulian | a39ae3e | 2018-05-31 12:43:54 -0700 | [diff] [blame] | 2133 | boolean preserveWindows, boolean notifyClients) { |
Jorim Jaggi | fe76234 | 2016-10-13 14:33:27 +0200 | [diff] [blame] | 2134 | mTopActivityOccludesKeyguard = false; |
| 2135 | mTopDismissingKeyguardActivity = null; |
Bryce Lee | 2a3cc46 | 2017-10-27 10:57:35 -0700 | [diff] [blame] | 2136 | mStackSupervisor.getKeyguardController().beginActivityVisibilityUpdate(); |
Jorim Jaggi | fe76234 | 2016-10-13 14:33:27 +0200 | [diff] [blame] | 2137 | try { |
| 2138 | ActivityRecord top = topRunningActivityLocked(); |
| 2139 | if (DEBUG_VISIBILITY) Slog.v(TAG_VISIBILITY, "ensureActivitiesVisible behind " + top |
| 2140 | + " configChanges=0x" + Integer.toHexString(configChanges)); |
| 2141 | if (top != null) { |
| 2142 | checkTranslucentActivityWaiting(top); |
| 2143 | } |
Craig Mautner | 5eda9b3 | 2013-07-02 11:58:16 -0700 | [diff] [blame] | 2144 | |
Jorim Jaggi | fe76234 | 2016-10-13 14:33:27 +0200 | [diff] [blame] | 2145 | // If the top activity is not fullscreen, then we need to |
| 2146 | // make sure any activities under it are now visible. |
| 2147 | boolean aboveTop = top != null; |
Wale Ogunwale | 04a05ac | 2017-09-17 21:35:02 -0700 | [diff] [blame] | 2148 | final boolean stackShouldBeVisible = shouldBeVisible(starting); |
| 2149 | boolean behindFullscreenActivity = !stackShouldBeVisible; |
Andrii Kulian | 6b32151 | 2019-01-23 06:37:00 +0000 | [diff] [blame] | 2150 | boolean resumeNextActivity = isFocusable() && isInStackLocked(starting) == null; |
Jorim Jaggi | fe76234 | 2016-10-13 14:33:27 +0200 | [diff] [blame] | 2151 | for (int taskNdx = mTaskHistory.size() - 1; taskNdx >= 0; --taskNdx) { |
| 2152 | final TaskRecord task = mTaskHistory.get(taskNdx); |
| 2153 | final ArrayList<ActivityRecord> activities = task.mActivities; |
| 2154 | for (int activityNdx = activities.size() - 1; activityNdx >= 0; --activityNdx) { |
| 2155 | final ActivityRecord r = activities.get(activityNdx); |
| 2156 | if (r.finishing) { |
Jorim Jaggi | fe76234 | 2016-10-13 14:33:27 +0200 | [diff] [blame] | 2157 | continue; |
Chong Zhang | 22bc851 | 2016-04-07 13:47:18 -0700 | [diff] [blame] | 2158 | } |
Jorim Jaggi | fe76234 | 2016-10-13 14:33:27 +0200 | [diff] [blame] | 2159 | final boolean isTop = r == top; |
| 2160 | if (aboveTop && !isTop) { |
| 2161 | continue; |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 2162 | } |
Jorim Jaggi | fe76234 | 2016-10-13 14:33:27 +0200 | [diff] [blame] | 2163 | aboveTop = false; |
Craig Mautner | d44711d | 2013-02-23 11:24:36 -0800 | [diff] [blame] | 2164 | |
Jorim Jaggi | fe76234 | 2016-10-13 14:33:27 +0200 | [diff] [blame] | 2165 | // Check whether activity should be visible without Keyguard influence |
Jorim Jaggi | 241ae10 | 2016-11-02 21:57:33 -0700 | [diff] [blame] | 2166 | final boolean visibleIgnoringKeyguard = r.shouldBeVisibleIgnoringKeyguard( |
Jorim Jaggi | 241ae10 | 2016-11-02 21:57:33 -0700 | [diff] [blame] | 2167 | behindFullscreenActivity); |
Garfield Tan | 47e576c | 2019-01-28 10:26:23 -0800 | [diff] [blame] | 2168 | final boolean reallyVisible = r.shouldBeVisible(behindFullscreenActivity); |
Jorim Jaggi | 241ae10 | 2016-11-02 21:57:33 -0700 | [diff] [blame] | 2169 | if (visibleIgnoringKeyguard) { |
Wale Ogunwale | 04a05ac | 2017-09-17 21:35:02 -0700 | [diff] [blame] | 2170 | behindFullscreenActivity = updateBehindFullscreen(!stackShouldBeVisible, |
Wale Ogunwale | 66e1685 | 2017-10-19 13:35:52 -0700 | [diff] [blame] | 2171 | behindFullscreenActivity, r); |
Jorim Jaggi | fe76234 | 2016-10-13 14:33:27 +0200 | [diff] [blame] | 2172 | } |
| 2173 | if (reallyVisible) { |
| 2174 | if (DEBUG_VISIBILITY) Slog.v(TAG_VISIBILITY, "Make visible? " + r |
Bryce Lee | 7ace395 | 2018-02-16 14:34:32 -0800 | [diff] [blame] | 2175 | + " finishing=" + r.finishing + " state=" + r.getState()); |
Jorim Jaggi | fe76234 | 2016-10-13 14:33:27 +0200 | [diff] [blame] | 2176 | // First: if this is not the current activity being started, make |
| 2177 | // sure it matches the current configuration. |
Andrii Kulian | a39ae3e | 2018-05-31 12:43:54 -0700 | [diff] [blame] | 2178 | if (r != starting && notifyClients) { |
Wale Ogunwale | b6d75f3 | 2018-02-22 20:44:56 -0800 | [diff] [blame] | 2179 | r.ensureActivityConfiguration(0 /* globalChanges */, preserveWindows, |
| 2180 | true /* ignoreStopState */); |
Jorim Jaggi | fe76234 | 2016-10-13 14:33:27 +0200 | [diff] [blame] | 2181 | } |
| 2182 | |
Wale Ogunwale | 9e4f3e0 | 2018-05-17 09:35:39 -0700 | [diff] [blame] | 2183 | if (!r.attachedToProcess()) { |
Jorim Jaggi | fe76234 | 2016-10-13 14:33:27 +0200 | [diff] [blame] | 2184 | if (makeVisibleAndRestartIfNeeded(starting, configChanges, isTop, |
| 2185 | resumeNextActivity, r)) { |
| 2186 | if (activityNdx >= activities.size()) { |
| 2187 | // Record may be removed if its process needs to restart. |
| 2188 | activityNdx = activities.size() - 1; |
| 2189 | } else { |
| 2190 | resumeNextActivity = false; |
| 2191 | } |
| 2192 | } |
| 2193 | } else if (r.visible) { |
| 2194 | // If this activity is already visible, then there is nothing to do here. |
| 2195 | if (DEBUG_VISIBILITY) Slog.v(TAG_VISIBILITY, |
| 2196 | "Skipping: already visible at " + r); |
| 2197 | |
Andrii Kulian | a39ae3e | 2018-05-31 12:43:54 -0700 | [diff] [blame] | 2198 | if (r.mClientVisibilityDeferred && notifyClients) { |
| 2199 | r.makeClientVisible(); |
| 2200 | } |
| 2201 | |
Jorim Jaggi | fe76234 | 2016-10-13 14:33:27 +0200 | [diff] [blame] | 2202 | if (r.handleAlreadyVisible()) { |
Wale Ogunwale | d046a01 | 2015-12-24 13:05:59 -0800 | [diff] [blame] | 2203 | resumeNextActivity = false; |
riddle_hsu | 36ee73d | 2015-06-05 16:38:38 +0800 | [diff] [blame] | 2204 | } |
Andrii Kulian | 6b32151 | 2019-01-23 06:37:00 +0000 | [diff] [blame] | 2205 | |
| 2206 | if (notifyClients) { |
| 2207 | r.makeActiveIfNeeded(starting); |
| 2208 | } |
Jorim Jaggi | fe76234 | 2016-10-13 14:33:27 +0200 | [diff] [blame] | 2209 | } else { |
Andrii Kulian | a39ae3e | 2018-05-31 12:43:54 -0700 | [diff] [blame] | 2210 | r.makeVisibleIfNeeded(starting, notifyClients); |
Craig Mautner | d44711d | 2013-02-23 11:24:36 -0800 | [diff] [blame] | 2211 | } |
Jorim Jaggi | fe76234 | 2016-10-13 14:33:27 +0200 | [diff] [blame] | 2212 | // Aggregate current change flags. |
| 2213 | configChanges |= r.configChangeFlags; |
Craig Mautner | bb74246 | 2014-07-07 15:28:55 -0700 | [diff] [blame] | 2214 | } else { |
Jorim Jaggi | fe76234 | 2016-10-13 14:33:27 +0200 | [diff] [blame] | 2215 | if (DEBUG_VISIBILITY) Slog.v(TAG_VISIBILITY, "Make invisible? " + r |
Bryce Lee | 7ace395 | 2018-02-16 14:34:32 -0800 | [diff] [blame] | 2216 | + " finishing=" + r.finishing + " state=" + r.getState() |
Wale Ogunwale | 04a05ac | 2017-09-17 21:35:02 -0700 | [diff] [blame] | 2217 | + " stackShouldBeVisible=" + stackShouldBeVisible |
Wale Ogunwale | 9dcf946 | 2017-09-19 15:13:01 -0700 | [diff] [blame] | 2218 | + " behindFullscreenActivity=" + behindFullscreenActivity |
| 2219 | + " mLaunchTaskBehind=" + r.mLaunchTaskBehind); |
Wale Ogunwale | c981ad5 | 2017-06-13 11:40:06 -0700 | [diff] [blame] | 2220 | makeInvisible(r); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 2221 | } |
Jorim Jaggi | fe76234 | 2016-10-13 14:33:27 +0200 | [diff] [blame] | 2222 | } |
Wale Ogunwale | 44f036f | 2017-09-29 05:09:09 -0700 | [diff] [blame] | 2223 | final int windowingMode = getWindowingMode(); |
| 2224 | if (windowingMode == WINDOWING_MODE_FREEFORM) { |
Jorim Jaggi | fe76234 | 2016-10-13 14:33:27 +0200 | [diff] [blame] | 2225 | // The visibility of tasks and the activities they contain in freeform stack are |
| 2226 | // determined individually unlike other stacks where the visibility or fullscreen |
| 2227 | // status of an activity in a previous task affects other. |
Wale Ogunwale | 04a05ac | 2017-09-17 21:35:02 -0700 | [diff] [blame] | 2228 | behindFullscreenActivity = !stackShouldBeVisible; |
Wale Ogunwale | 6827856 | 2017-09-23 17:13:55 -0700 | [diff] [blame] | 2229 | } else if (isActivityTypeHome()) { |
Wale Ogunwale | 6fbde9f | 2017-08-24 07:24:12 -0700 | [diff] [blame] | 2230 | if (DEBUG_VISIBILITY) Slog.v(TAG_VISIBILITY, "Home task: at " + task |
Wale Ogunwale | 04a05ac | 2017-09-17 21:35:02 -0700 | [diff] [blame] | 2231 | + " stackShouldBeVisible=" + stackShouldBeVisible |
Wale Ogunwale | 6fbde9f | 2017-08-24 07:24:12 -0700 | [diff] [blame] | 2232 | + " behindFullscreenActivity=" + behindFullscreenActivity); |
| 2233 | // No other task in the home stack should be visible behind the home activity. |
| 2234 | // Home activities is usually a translucent activity with the wallpaper behind |
| 2235 | // them. However, when they don't have the wallpaper behind them, we want to |
| 2236 | // show activities in the next application stack behind them vs. another |
| 2237 | // task in the home stack like recents. |
| 2238 | behindFullscreenActivity = true; |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 2239 | } |
| 2240 | } |
Wale Ogunwale | 74e2659 | 2016-02-05 11:48:37 -0800 | [diff] [blame] | 2241 | |
Jorim Jaggi | fe76234 | 2016-10-13 14:33:27 +0200 | [diff] [blame] | 2242 | if (mTranslucentActivityWaiting != null && |
| 2243 | mUndrawnActivitiesBelowTopTranslucent.isEmpty()) { |
| 2244 | // Nothing is getting drawn or everything was already visible, don't wait for timeout. |
| 2245 | notifyActivityDrawnLocked(null); |
| 2246 | } |
| 2247 | } finally { |
Bryce Lee | 2a3cc46 | 2017-10-27 10:57:35 -0700 | [diff] [blame] | 2248 | mStackSupervisor.getKeyguardController().endActivityVisibilityUpdate(); |
Jorim Jaggi | fe76234 | 2016-10-13 14:33:27 +0200 | [diff] [blame] | 2249 | } |
| 2250 | } |
| 2251 | |
Jorim Jaggi | 8b702ed | 2017-01-20 16:59:03 +0100 | [diff] [blame] | 2252 | void addStartingWindowsForVisibleActivities(boolean taskSwitch) { |
| 2253 | for (int taskNdx = mTaskHistory.size() - 1; taskNdx >= 0; --taskNdx) { |
| 2254 | mTaskHistory.get(taskNdx).addStartingWindowsForVisibleActivities(taskSwitch); |
| 2255 | } |
| 2256 | } |
| 2257 | |
Jorim Jaggi | fe76234 | 2016-10-13 14:33:27 +0200 | [diff] [blame] | 2258 | /** |
| 2259 | * @return true if the top visible activity wants to occlude the Keyguard, false otherwise |
| 2260 | */ |
| 2261 | boolean topActivityOccludesKeyguard() { |
| 2262 | return mTopActivityOccludesKeyguard; |
| 2263 | } |
| 2264 | |
| 2265 | /** |
Wale Ogunwale | 44f036f | 2017-09-29 05:09:09 -0700 | [diff] [blame] | 2266 | * Returns true if this stack should be resized to match the bounds specified by |
| 2267 | * {@link ActivityOptions#setLaunchBounds} when launching an activity into the stack. |
| 2268 | */ |
| 2269 | boolean resizeStackWithLaunchBounds() { |
| 2270 | return inPinnedWindowingMode(); |
| 2271 | } |
| 2272 | |
Wale Ogunwale | 30e441d | 2017-11-09 08:28:45 -0800 | [diff] [blame] | 2273 | @Override |
| 2274 | public boolean supportsSplitScreenWindowingMode() { |
| 2275 | final TaskRecord topTask = topTask(); |
| 2276 | return super.supportsSplitScreenWindowingMode() |
| 2277 | && (topTask == null || topTask.supportsSplitScreenWindowingMode()); |
| 2278 | } |
| 2279 | |
Wale Ogunwale | 2b07da8 | 2017-11-08 14:52:40 -0800 | [diff] [blame] | 2280 | /** @return True if the resizing of the primary-split-screen stack affects this stack size. */ |
| 2281 | boolean affectedBySplitScreenResize() { |
| 2282 | if (!supportsSplitScreenWindowingMode()) { |
| 2283 | return false; |
| 2284 | } |
| 2285 | final int windowingMode = getWindowingMode(); |
| 2286 | return windowingMode != WINDOWING_MODE_FREEFORM && windowingMode != WINDOWING_MODE_PINNED; |
| 2287 | } |
| 2288 | |
Wale Ogunwale | 44f036f | 2017-09-29 05:09:09 -0700 | [diff] [blame] | 2289 | /** |
Jorim Jaggi | fe76234 | 2016-10-13 14:33:27 +0200 | [diff] [blame] | 2290 | * @return the top most visible activity that wants to dismiss Keyguard |
| 2291 | */ |
| 2292 | ActivityRecord getTopDismissingKeyguardActivity() { |
| 2293 | return mTopDismissingKeyguardActivity; |
| 2294 | } |
| 2295 | |
| 2296 | /** |
| 2297 | * Checks whether {@param r} should be visible depending on Keyguard state and updates |
| 2298 | * {@link #mTopActivityOccludesKeyguard} and {@link #mTopDismissingKeyguardActivity} if |
| 2299 | * necessary. |
| 2300 | * |
| 2301 | * @return true if {@param r} is visible taken Keyguard state into account, false otherwise |
| 2302 | */ |
Wale Ogunwale | 2cca862 | 2017-12-11 08:40:13 -0800 | [diff] [blame] | 2303 | boolean checkKeyguardVisibility(ActivityRecord r, boolean shouldBeVisible, boolean isTop) { |
Lucas Dupin | 47a65c7 | 2018-02-15 14:16:18 -0800 | [diff] [blame] | 2304 | final int displayId = mDisplayId != INVALID_DISPLAY ? mDisplayId : DEFAULT_DISPLAY; |
| 2305 | final boolean keyguardOrAodShowing = mStackSupervisor.getKeyguardController() |
| 2306 | .isKeyguardOrAodShowing(displayId); |
Bryce Lee | 2a3cc46 | 2017-10-27 10:57:35 -0700 | [diff] [blame] | 2307 | final boolean keyguardLocked = mStackSupervisor.getKeyguardController().isKeyguardLocked(); |
Wale Ogunwale | 2cca862 | 2017-12-11 08:40:13 -0800 | [diff] [blame] | 2308 | final boolean showWhenLocked = r.canShowWhenLocked(); |
Issei Suzuki | 74e1eb2 | 2018-12-20 17:42:52 +0100 | [diff] [blame] | 2309 | final boolean dismissKeyguard = r.mAppWindowToken != null |
| 2310 | && r.mAppWindowToken.containsDismissKeyguardWindow(); |
Jorim Jaggi | fe76234 | 2016-10-13 14:33:27 +0200 | [diff] [blame] | 2311 | if (shouldBeVisible) { |
Jorim Jaggi | e69c931 | 2016-10-31 18:24:38 -0700 | [diff] [blame] | 2312 | if (dismissKeyguard && mTopDismissingKeyguardActivity == null) { |
Jorim Jaggi | fe76234 | 2016-10-13 14:33:27 +0200 | [diff] [blame] | 2313 | mTopDismissingKeyguardActivity = r; |
| 2314 | } |
| 2315 | |
| 2316 | // Only the top activity may control occluded, as we can't occlude the Keyguard if the |
| 2317 | // top app doesn't want to occlude it. |
| 2318 | if (isTop) { |
| 2319 | mTopActivityOccludesKeyguard |= showWhenLocked; |
Wale Ogunwale | c219c0b | 2015-09-12 09:18:07 -0700 | [diff] [blame] | 2320 | } |
Andrii Kulian | fc8f82b | 2017-01-26 13:17:27 -0800 | [diff] [blame] | 2321 | |
Andrii Kulian | 7211d2e | 2017-01-27 15:58:05 -0800 | [diff] [blame] | 2322 | final boolean canShowWithKeyguard = canShowWithInsecureKeyguard() |
Bryce Lee | 2a3cc46 | 2017-10-27 10:57:35 -0700 | [diff] [blame] | 2323 | && mStackSupervisor.getKeyguardController().canDismissKeyguard(); |
Andrii Kulian | fc8f82b | 2017-01-26 13:17:27 -0800 | [diff] [blame] | 2324 | if (canShowWithKeyguard) { |
| 2325 | return true; |
| 2326 | } |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 2327 | } |
Lucas Dupin | 47a65c7 | 2018-02-15 14:16:18 -0800 | [diff] [blame] | 2328 | if (keyguardOrAodShowing) { |
Jorim Jaggi | e69c931 | 2016-10-31 18:24:38 -0700 | [diff] [blame] | 2329 | // If keyguard is showing, nothing is visible, except if we are able to dismiss Keyguard |
Lucas Dupin | 47a65c7 | 2018-02-15 14:16:18 -0800 | [diff] [blame] | 2330 | // right away and AOD isn't visible. |
Bryce Lee | 2a3cc46 | 2017-10-27 10:57:35 -0700 | [diff] [blame] | 2331 | return shouldBeVisible && mStackSupervisor.getKeyguardController() |
Jorim Jaggi | 0796187 | 2016-11-23 11:28:57 +0100 | [diff] [blame] | 2332 | .canShowActivityWhileKeyguardShowing(r, dismissKeyguard); |
Jorim Jaggi | fe76234 | 2016-10-13 14:33:27 +0200 | [diff] [blame] | 2333 | } else if (keyguardLocked) { |
Bryce Lee | 2a3cc46 | 2017-10-27 10:57:35 -0700 | [diff] [blame] | 2334 | return shouldBeVisible && mStackSupervisor.getKeyguardController().canShowWhileOccluded( |
Jorim Jaggi | 0796187 | 2016-11-23 11:28:57 +0100 | [diff] [blame] | 2335 | dismissKeyguard, showWhenLocked); |
Jorim Jaggi | fe76234 | 2016-10-13 14:33:27 +0200 | [diff] [blame] | 2336 | } else { |
| 2337 | return shouldBeVisible; |
Craig Mautner | eb8abf7 | 2014-07-02 15:04:09 -0700 | [diff] [blame] | 2338 | } |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 2339 | } |
Craig Mautner | 5854780 | 2013-03-05 08:23:53 -0800 | [diff] [blame] | 2340 | |
Andrii Kulian | fc8f82b | 2017-01-26 13:17:27 -0800 | [diff] [blame] | 2341 | /** |
| 2342 | * Check if the display to which this stack is attached has |
Andrii Kulian | 7211d2e | 2017-01-27 15:58:05 -0800 | [diff] [blame] | 2343 | * {@link Display#FLAG_CAN_SHOW_WITH_INSECURE_KEYGUARD} applied. |
Andrii Kulian | fc8f82b | 2017-01-26 13:17:27 -0800 | [diff] [blame] | 2344 | */ |
wilsonshih | 498a4b8 | 2018-12-11 16:10:16 +0800 | [diff] [blame] | 2345 | boolean canShowWithInsecureKeyguard() { |
Wale Ogunwale | 9dcf946 | 2017-09-19 15:13:01 -0700 | [diff] [blame] | 2346 | final ActivityDisplay activityDisplay = getDisplay(); |
Andrii Kulian | fc8f82b | 2017-01-26 13:17:27 -0800 | [diff] [blame] | 2347 | if (activityDisplay == null) { |
| 2348 | throw new IllegalStateException("Stack is not attached to any display, stackId=" |
| 2349 | + mStackId); |
| 2350 | } |
| 2351 | |
| 2352 | final int flags = activityDisplay.mDisplay.getFlags(); |
Andrii Kulian | 7211d2e | 2017-01-27 15:58:05 -0800 | [diff] [blame] | 2353 | return (flags & FLAG_CAN_SHOW_WITH_INSECURE_KEYGUARD) != 0; |
Andrii Kulian | fc8f82b | 2017-01-26 13:17:27 -0800 | [diff] [blame] | 2354 | } |
| 2355 | |
Filip Gruszczynski | 9104aea | 2015-11-13 16:42:05 -0800 | [diff] [blame] | 2356 | private void checkTranslucentActivityWaiting(ActivityRecord top) { |
| 2357 | if (mTranslucentActivityWaiting != top) { |
| 2358 | mUndrawnActivitiesBelowTopTranslucent.clear(); |
| 2359 | if (mTranslucentActivityWaiting != null) { |
| 2360 | // Call the callback with a timeout indication. |
| 2361 | notifyActivityDrawnLocked(null); |
| 2362 | mTranslucentActivityWaiting = null; |
| 2363 | } |
| 2364 | mHandler.removeMessages(TRANSLUCENT_TIMEOUT_MSG); |
| 2365 | } |
| 2366 | } |
| 2367 | |
| 2368 | private boolean makeVisibleAndRestartIfNeeded(ActivityRecord starting, int configChanges, |
Wale Ogunwale | d046a01 | 2015-12-24 13:05:59 -0800 | [diff] [blame] | 2369 | boolean isTop, boolean andResume, ActivityRecord r) { |
Filip Gruszczynski | 9104aea | 2015-11-13 16:42:05 -0800 | [diff] [blame] | 2370 | // We need to make sure the app is running if it's the top, or it is just made visible from |
| 2371 | // invisible. If the app is already visible, it must have died while it was visible. In this |
| 2372 | // case, we'll show the dead window but will not restart the app. Otherwise we could end up |
| 2373 | // thrashing. |
Filip Gruszczynski | 21199bd | 2015-12-02 12:49:58 -0800 | [diff] [blame] | 2374 | if (isTop || !r.visible) { |
Filip Gruszczynski | 9104aea | 2015-11-13 16:42:05 -0800 | [diff] [blame] | 2375 | // This activity needs to be visible, but isn't even running... |
| 2376 | // get it started and resume if no other stack in this stack is resumed. |
| 2377 | if (DEBUG_VISIBILITY) Slog.v(TAG_VISIBILITY, "Start and freeze screen for " + r); |
| 2378 | if (r != starting) { |
| 2379 | r.startFreezingScreenLocked(r.app, configChanges); |
| 2380 | } |
| 2381 | if (!r.visible || r.mLaunchTaskBehind) { |
| 2382 | if (DEBUG_VISIBILITY) Slog.v(TAG_VISIBILITY, "Starting and making visible: " + r); |
Andrii Kulian | 21713ac | 2016-10-12 22:05:05 -0700 | [diff] [blame] | 2383 | r.setVisible(true); |
Filip Gruszczynski | 9104aea | 2015-11-13 16:42:05 -0800 | [diff] [blame] | 2384 | } |
| 2385 | if (r != starting) { |
Andrii Kulian | 6b32151 | 2019-01-23 06:37:00 +0000 | [diff] [blame] | 2386 | mStackSupervisor.startSpecificActivityLocked(r, andResume, true /* checkConfig */); |
Filip Gruszczynski | 9104aea | 2015-11-13 16:42:05 -0800 | [diff] [blame] | 2387 | return true; |
| 2388 | } |
| 2389 | } |
| 2390 | return false; |
| 2391 | } |
| 2392 | |
Wale Ogunwale | c981ad5 | 2017-06-13 11:40:06 -0700 | [diff] [blame] | 2393 | // TODO: Should probably be moved into ActivityRecord. |
| 2394 | private void makeInvisible(ActivityRecord r) { |
Filip Gruszczynski | 9104aea | 2015-11-13 16:42:05 -0800 | [diff] [blame] | 2395 | if (!r.visible) { |
| 2396 | if (DEBUG_VISIBILITY) Slog.v(TAG_VISIBILITY, "Already invisible: " + r); |
| 2397 | return; |
| 2398 | } |
| 2399 | // Now for any activities that aren't visible to the user, make sure they no longer are |
| 2400 | // keeping the screen frozen. |
Bryce Lee | 7ace395 | 2018-02-16 14:34:32 -0800 | [diff] [blame] | 2401 | if (DEBUG_VISIBILITY) Slog.v(TAG_VISIBILITY, "Making invisible: " + r + " " + r.getState()); |
Filip Gruszczynski | 9104aea | 2015-11-13 16:42:05 -0800 | [diff] [blame] | 2402 | try { |
Wale Ogunwale | b9a0c99 | 2017-04-18 07:25:20 -0700 | [diff] [blame] | 2403 | final boolean canEnterPictureInPicture = r.checkEnterPictureInPictureState( |
Winson Chung | 298f95b | 2017-08-10 15:57:18 -0700 | [diff] [blame] | 2404 | "makeInvisible", true /* beforeStopping */); |
Wale Ogunwale | 08488a6 | 2017-09-05 12:37:03 -0700 | [diff] [blame] | 2405 | // Defer telling the client it is hidden if it can enter Pip and isn't current paused, |
| 2406 | // stopped or stopping. This gives it a chance to enter Pip in onPause(). |
| 2407 | // TODO: There is still a question surrounding activities in multi-window mode that want |
| 2408 | // to enter Pip after they are paused, but are still visible. I they should be okay to |
| 2409 | // enter Pip in those cases, but not "auto-Pip" which is what this condition covers and |
| 2410 | // the current contract for "auto-Pip" is that the app should enter it before onPause |
| 2411 | // returns. Just need to confirm this reasoning makes sense. |
Wale Ogunwale | 8997322 | 2017-04-23 18:39:45 -0700 | [diff] [blame] | 2412 | final boolean deferHidingClient = canEnterPictureInPicture |
Bryce Lee | 7ace395 | 2018-02-16 14:34:32 -0800 | [diff] [blame] | 2413 | && !r.isState(STOPPING, STOPPED, PAUSED); |
Wale Ogunwale | ec95064 | 2017-04-25 07:44:21 -0700 | [diff] [blame] | 2414 | r.setDeferHidingClient(deferHidingClient); |
| 2415 | r.setVisible(false); |
Wale Ogunwale | b9a0c99 | 2017-04-18 07:25:20 -0700 | [diff] [blame] | 2416 | |
Bryce Lee | 7ace395 | 2018-02-16 14:34:32 -0800 | [diff] [blame] | 2417 | switch (r.getState()) { |
Filip Gruszczynski | 9104aea | 2015-11-13 16:42:05 -0800 | [diff] [blame] | 2418 | case STOPPING: |
| 2419 | case STOPPED: |
Wale Ogunwale | 9e4f3e0 | 2018-05-17 09:35:39 -0700 | [diff] [blame] | 2420 | if (r.attachedToProcess()) { |
Filip Gruszczynski | 9104aea | 2015-11-13 16:42:05 -0800 | [diff] [blame] | 2421 | if (DEBUG_VISIBILITY) Slog.v(TAG_VISIBILITY, |
| 2422 | "Scheduling invisibility: " + r); |
Wale Ogunwale | 9e4f3e0 | 2018-05-17 09:35:39 -0700 | [diff] [blame] | 2423 | mService.getLifecycleManager().scheduleTransaction(r.app.getThread(), |
| 2424 | r.appToken, WindowVisibilityItem.obtain(false /* showWindow */)); |
Filip Gruszczynski | 9104aea | 2015-11-13 16:42:05 -0800 | [diff] [blame] | 2425 | } |
Winson Chung | c2baac0 | 2017-01-11 13:34:47 -0800 | [diff] [blame] | 2426 | |
| 2427 | // Reset the flag indicating that an app can enter picture-in-picture once the |
| 2428 | // activity is hidden |
Winson Chung | f7e03e1 | 2017-08-22 11:32:16 -0700 | [diff] [blame] | 2429 | r.supportsEnterPipOnTaskSwitch = false; |
Filip Gruszczynski | 9104aea | 2015-11-13 16:42:05 -0800 | [diff] [blame] | 2430 | break; |
| 2431 | |
| 2432 | case INITIALIZING: |
| 2433 | case RESUMED: |
| 2434 | case PAUSING: |
| 2435 | case PAUSED: |
Wale Ogunwale | c981ad5 | 2017-06-13 11:40:06 -0700 | [diff] [blame] | 2436 | addToStopping(r, true /* scheduleIdle */, |
| 2437 | canEnterPictureInPicture /* idleDelayed */); |
Filip Gruszczynski | 9104aea | 2015-11-13 16:42:05 -0800 | [diff] [blame] | 2438 | break; |
| 2439 | |
| 2440 | default: |
| 2441 | break; |
| 2442 | } |
| 2443 | } catch (Exception e) { |
| 2444 | // Just skip on any failure; we'll make it visible when it next restarts. |
| 2445 | Slog.w(TAG, "Exception thrown making hidden: " + r.intent.getComponent(), e); |
| 2446 | } |
| 2447 | } |
| 2448 | |
| 2449 | private boolean updateBehindFullscreen(boolean stackInvisible, boolean behindFullscreenActivity, |
Wale Ogunwale | 66e1685 | 2017-10-19 13:35:52 -0700 | [diff] [blame] | 2450 | ActivityRecord r) { |
Filip Gruszczynski | 9104aea | 2015-11-13 16:42:05 -0800 | [diff] [blame] | 2451 | if (r.fullscreen) { |
Filip Gruszczynski | 9104aea | 2015-11-13 16:42:05 -0800 | [diff] [blame] | 2452 | if (DEBUG_VISIBILITY) Slog.v(TAG_VISIBILITY, "Fullscreen: at " + r |
Wale Ogunwale | 673cbd2 | 2016-01-30 18:30:55 -0800 | [diff] [blame] | 2453 | + " stackInvisible=" + stackInvisible |
| 2454 | + " behindFullscreenActivity=" + behindFullscreenActivity); |
Filip Gruszczynski | 0e381e2 | 2016-01-14 16:31:33 -0800 | [diff] [blame] | 2455 | // At this point, nothing else needs to be shown in this task. |
Filip Gruszczynski | 9104aea | 2015-11-13 16:42:05 -0800 | [diff] [blame] | 2456 | behindFullscreenActivity = true; |
Filip Gruszczynski | 9104aea | 2015-11-13 16:42:05 -0800 | [diff] [blame] | 2457 | } |
| 2458 | return behindFullscreenActivity; |
| 2459 | } |
| 2460 | |
Todd Kennedy | aab56db | 2015-01-30 09:39:53 -0800 | [diff] [blame] | 2461 | void convertActivityToTranslucent(ActivityRecord r) { |
Craig Mautner | 5eda9b3 | 2013-07-02 11:58:16 -0700 | [diff] [blame] | 2462 | mTranslucentActivityWaiting = r; |
| 2463 | mUndrawnActivitiesBelowTopTranslucent.clear(); |
| 2464 | mHandler.sendEmptyMessageDelayed(TRANSLUCENT_TIMEOUT_MSG, TRANSLUCENT_CONVERSION_TIMEOUT); |
| 2465 | } |
| 2466 | |
Dianne Hackborn | b5a380d | 2015-05-20 18:18:46 -0700 | [diff] [blame] | 2467 | void clearOtherAppTimeTrackers(AppTimeTracker except) { |
| 2468 | for (int taskNdx = mTaskHistory.size() - 1; taskNdx >= 0; --taskNdx) { |
| 2469 | final TaskRecord task = mTaskHistory.get(taskNdx); |
| 2470 | final ArrayList<ActivityRecord> activities = task.mActivities; |
| 2471 | for (int activityNdx = activities.size() - 1; activityNdx >= 0; --activityNdx) { |
| 2472 | final ActivityRecord r = activities.get(activityNdx); |
| 2473 | if ( r.appTimeTracker != except) { |
| 2474 | r.appTimeTracker = null; |
| 2475 | } |
| 2476 | } |
| 2477 | } |
| 2478 | } |
| 2479 | |
Craig Mautner | 5eda9b3 | 2013-07-02 11:58:16 -0700 | [diff] [blame] | 2480 | /** |
| 2481 | * Called as activities below the top translucent activity are redrawn. When the last one is |
| 2482 | * redrawn notify the top activity by calling |
| 2483 | * {@link Activity#onTranslucentConversionComplete}. |
| 2484 | * |
| 2485 | * @param r The most recent background activity to be drawn. Or, if r is null then a timeout |
| 2486 | * occurred and the activity will be notified immediately. |
| 2487 | */ |
| 2488 | void notifyActivityDrawnLocked(ActivityRecord r) { |
| 2489 | if ((r == null) |
| 2490 | || (mUndrawnActivitiesBelowTopTranslucent.remove(r) && |
| 2491 | mUndrawnActivitiesBelowTopTranslucent.isEmpty())) { |
| 2492 | // The last undrawn activity below the top has just been drawn. If there is an |
| 2493 | // opaque activity at the top, notify it that it can become translucent safely now. |
| 2494 | final ActivityRecord waitingActivity = mTranslucentActivityWaiting; |
| 2495 | mTranslucentActivityWaiting = null; |
| 2496 | mUndrawnActivitiesBelowTopTranslucent.clear(); |
| 2497 | mHandler.removeMessages(TRANSLUCENT_TIMEOUT_MSG); |
| 2498 | |
Craig Mautner | 71dd1b6 | 2014-02-18 15:48:52 -0800 | [diff] [blame] | 2499 | if (waitingActivity != null) { |
| 2500 | mWindowManager.setWindowOpaque(waitingActivity.appToken, false); |
Wale Ogunwale | 9e4f3e0 | 2018-05-17 09:35:39 -0700 | [diff] [blame] | 2501 | if (waitingActivity.attachedToProcess()) { |
Craig Mautner | 71dd1b6 | 2014-02-18 15:48:52 -0800 | [diff] [blame] | 2502 | try { |
Wale Ogunwale | 9e4f3e0 | 2018-05-17 09:35:39 -0700 | [diff] [blame] | 2503 | waitingActivity.app.getThread().scheduleTranslucentConversionComplete( |
Craig Mautner | 71dd1b6 | 2014-02-18 15:48:52 -0800 | [diff] [blame] | 2504 | waitingActivity.appToken, r != null); |
| 2505 | } catch (RemoteException e) { |
| 2506 | } |
Craig Mautner | 5eda9b3 | 2013-07-02 11:58:16 -0700 | [diff] [blame] | 2507 | } |
| 2508 | } |
| 2509 | } |
| 2510 | } |
| 2511 | |
Craig Mautner | a61bc65 | 2013-10-28 15:43:18 -0700 | [diff] [blame] | 2512 | /** If any activities below the top running one are in the INITIALIZING state and they have a |
| 2513 | * starting window displayed then remove that starting window. It is possible that the activity |
| 2514 | * in this state will never resumed in which case that starting window will be orphaned. */ |
| 2515 | void cancelInitializingActivities() { |
Filip Gruszczynski | 3e85ba2 | 2015-10-05 22:48:30 -0700 | [diff] [blame] | 2516 | final ActivityRecord topActivity = topRunningActivityLocked(); |
Craig Mautner | a61bc65 | 2013-10-28 15:43:18 -0700 | [diff] [blame] | 2517 | boolean aboveTop = true; |
Wale Ogunwale | 6874114 | 2016-05-17 09:40:02 -0700 | [diff] [blame] | 2518 | // We don't want to clear starting window for activities that aren't behind fullscreen |
| 2519 | // activities as we need to display their starting window until they are done initializing. |
| 2520 | boolean behindFullscreenActivity = false; |
Wale Ogunwale | 98742a5 | 2016-07-12 10:29:12 -0700 | [diff] [blame] | 2521 | |
Wale Ogunwale | 9dcf946 | 2017-09-19 15:13:01 -0700 | [diff] [blame] | 2522 | if (!shouldBeVisible(null)) { |
Wale Ogunwale | 98742a5 | 2016-07-12 10:29:12 -0700 | [diff] [blame] | 2523 | // The stack is not visible, so no activity in it should be displaying a starting |
| 2524 | // window. Mark all activities below top and behind fullscreen. |
| 2525 | aboveTop = false; |
| 2526 | behindFullscreenActivity = true; |
| 2527 | } |
| 2528 | |
Craig Mautner | a61bc65 | 2013-10-28 15:43:18 -0700 | [diff] [blame] | 2529 | for (int taskNdx = mTaskHistory.size() - 1; taskNdx >= 0; --taskNdx) { |
| 2530 | final ArrayList<ActivityRecord> activities = mTaskHistory.get(taskNdx).mActivities; |
| 2531 | for (int activityNdx = activities.size() - 1; activityNdx >= 0; --activityNdx) { |
| 2532 | final ActivityRecord r = activities.get(activityNdx); |
| 2533 | if (aboveTop) { |
| 2534 | if (r == topActivity) { |
| 2535 | aboveTop = false; |
| 2536 | } |
Wale Ogunwale | 6874114 | 2016-05-17 09:40:02 -0700 | [diff] [blame] | 2537 | behindFullscreenActivity |= r.fullscreen; |
Craig Mautner | a61bc65 | 2013-10-28 15:43:18 -0700 | [diff] [blame] | 2538 | continue; |
| 2539 | } |
| 2540 | |
Wale Ogunwale | 26c0dfe | 2016-12-14 14:42:30 -0800 | [diff] [blame] | 2541 | r.removeOrphanedStartingWindow(behindFullscreenActivity); |
Wale Ogunwale | 6874114 | 2016-05-17 09:40:02 -0700 | [diff] [blame] | 2542 | behindFullscreenActivity |= r.fullscreen; |
Craig Mautner | a61bc65 | 2013-10-28 15:43:18 -0700 | [diff] [blame] | 2543 | } |
| 2544 | } |
| 2545 | } |
| 2546 | |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 2547 | /** |
| 2548 | * Ensure that the top activity in the stack is resumed. |
| 2549 | * |
| 2550 | * @param prev The previously resumed activity, for when in the process |
| 2551 | * of pausing; can be null to call from elsewhere. |
Wale Ogunwale | d046a01 | 2015-12-24 13:05:59 -0800 | [diff] [blame] | 2552 | * @param options Activity options. |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 2553 | * |
| 2554 | * @return Returns true if something is being resumed, or false if |
| 2555 | * nothing happened. |
Wale Ogunwale | d046a01 | 2015-12-24 13:05:59 -0800 | [diff] [blame] | 2556 | * |
| 2557 | * NOTE: It is not safe to call this method directly as it can cause an activity in a |
| 2558 | * non-focused stack to be resumed. |
Wale Ogunwale | d32da47 | 2018-11-16 07:19:28 -0800 | [diff] [blame] | 2559 | * Use {@link RootActivityContainer#resumeFocusedStacksTopActivities} to resume the |
Wale Ogunwale | d046a01 | 2015-12-24 13:05:59 -0800 | [diff] [blame] | 2560 | * right activity for the current system state. |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 2561 | */ |
Andreas Gampe | a36dc62 | 2018-02-05 17:19:22 -0800 | [diff] [blame] | 2562 | @GuardedBy("mService") |
Wale Ogunwale | d046a01 | 2015-12-24 13:05:59 -0800 | [diff] [blame] | 2563 | boolean resumeTopActivityUncheckedLocked(ActivityRecord prev, ActivityOptions options) { |
Andrii Kulian | 6b32151 | 2019-01-23 06:37:00 +0000 | [diff] [blame] | 2564 | if (mInResumeTopActivity) { |
Craig Mautner | 544efa7 | 2014-09-04 16:41:20 -0700 | [diff] [blame] | 2565 | // Don't even start recursing. |
| 2566 | return false; |
| 2567 | } |
| 2568 | |
| 2569 | boolean result = false; |
| 2570 | try { |
| 2571 | // Protect against recursion. |
Andrii Kulian | 6b32151 | 2019-01-23 06:37:00 +0000 | [diff] [blame] | 2572 | mInResumeTopActivity = true; |
Bryce Lee | 69ad818 | 2017-09-28 10:01:36 -0700 | [diff] [blame] | 2573 | result = resumeTopActivityInnerLocked(prev, options); |
Andrii Kulian | 86e70fc | 2019-02-12 11:04:10 +0000 | [diff] [blame] | 2574 | mStackSupervisor.updateTopResumedActivityIfNeeded(); |
Bryce Lee | fc7cedd | 2018-03-01 15:38:07 -0800 | [diff] [blame] | 2575 | |
| 2576 | // When resuming the top activity, it may be necessary to pause the top activity (for |
| 2577 | // example, returning to the lock screen. We suppress the normal pause logic in |
| 2578 | // {@link #resumeTopActivityUncheckedLocked}, since the top activity is resumed at the |
| 2579 | // end. We call the {@link ActivityStackSupervisor#checkReadyForSleepLocked} again here |
| 2580 | // to ensure any necessary pause logic occurs. In the case where the Activity will be |
| 2581 | // shown regardless of the lock screen, the call to |
| 2582 | // {@link ActivityStackSupervisor#checkReadyForSleepLocked} is skipped. |
| 2583 | final ActivityRecord next = topRunningActivityLocked(true /* focusableOnly */); |
| 2584 | if (next == null || !next.canTurnScreenOn()) { |
| 2585 | checkReadyForSleep(); |
| 2586 | } |
Craig Mautner | 544efa7 | 2014-09-04 16:41:20 -0700 | [diff] [blame] | 2587 | } finally { |
Andrii Kulian | 6b32151 | 2019-01-23 06:37:00 +0000 | [diff] [blame] | 2588 | mInResumeTopActivity = false; |
Craig Mautner | 544efa7 | 2014-09-04 16:41:20 -0700 | [diff] [blame] | 2589 | } |
chaviw | 59b9885 | 2017-06-13 12:05:44 -0700 | [diff] [blame] | 2590 | |
Craig Mautner | 544efa7 | 2014-09-04 16:41:20 -0700 | [diff] [blame] | 2591 | return result; |
| 2592 | } |
| 2593 | |
Bryce Lee | c4ab62a | 2018-03-05 14:19:26 -0800 | [diff] [blame] | 2594 | /** |
| 2595 | * Returns the currently resumed activity. |
| 2596 | */ |
| 2597 | protected ActivityRecord getResumedActivity() { |
| 2598 | return mResumedActivity; |
| 2599 | } |
| 2600 | |
Bryce Lee | 84730a0 | 2018-04-03 14:10:04 -0700 | [diff] [blame] | 2601 | private void setResumedActivity(ActivityRecord r, String reason) { |
| 2602 | if (mResumedActivity == r) { |
| 2603 | return; |
| 2604 | } |
Bryce Lee | c4ab62a | 2018-03-05 14:19:26 -0800 | [diff] [blame] | 2605 | |
Bryce Lee | 84730a0 | 2018-04-03 14:10:04 -0700 | [diff] [blame] | 2606 | if (DEBUG_STACK) Slog.d(TAG_STACK, "setResumedActivity stack:" + this + " + from: " |
| 2607 | + mResumedActivity + " to:" + r + " reason:" + reason); |
| 2608 | mResumedActivity = r; |
Chong Zhang | 6cda19c | 2016-06-14 19:07:56 -0700 | [diff] [blame] | 2609 | } |
| 2610 | |
Andreas Gampe | a36dc62 | 2018-02-05 17:19:22 -0800 | [diff] [blame] | 2611 | @GuardedBy("mService") |
Chong Zhang | 280d332 | 2015-11-03 17:27:26 -0800 | [diff] [blame] | 2612 | private boolean resumeTopActivityInnerLocked(ActivityRecord prev, ActivityOptions options) { |
Wale Ogunwale | 5378374 | 2018-09-16 10:21:51 -0700 | [diff] [blame] | 2613 | if (!mService.isBooting() && !mService.isBooted()) { |
Dianne Hackborn | 7622a0f | 2014-09-30 14:31:42 -0700 | [diff] [blame] | 2614 | // Not ready yet! |
| 2615 | return false; |
| 2616 | } |
| 2617 | |
Winson Chung | 3f103eb | 2017-04-12 21:53:59 -0700 | [diff] [blame] | 2618 | // Find the next top-most activity to resume in this stack that is not finishing and is |
| 2619 | // focusable. If it is not focusable, we will fall into the case below to resume the |
| 2620 | // top activity in the next focusable task. |
Andrii Kulian | 6b32151 | 2019-01-23 06:37:00 +0000 | [diff] [blame] | 2621 | ActivityRecord next = topRunningActivityLocked(true /* focusableOnly */); |
Andrii Kulian | 7fc2281 | 2016-12-28 13:04:11 -0800 | [diff] [blame] | 2622 | |
| 2623 | final boolean hasRunningActivity = next != null; |
| 2624 | |
Andrii Kulian | 94e82d9b0 | 2017-07-13 15:33:06 -0700 | [diff] [blame] | 2625 | // TODO: Maybe this entire condition can get removed? |
Wale Ogunwale | 66e1685 | 2017-10-19 13:35:52 -0700 | [diff] [blame] | 2626 | if (hasRunningActivity && !isAttached()) { |
Craig Mautner | df88d73 | 2014-01-27 09:21:32 -0800 | [diff] [blame] | 2627 | return false; |
| 2628 | } |
| 2629 | |
Wale Ogunwale | d32da47 | 2018-11-16 07:19:28 -0800 | [diff] [blame] | 2630 | mRootActivityContainer.cancelInitializingActivities(); |
Craig Mautner | a61bc65 | 2013-10-28 15:43:18 -0700 | [diff] [blame] | 2631 | |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 2632 | // Remember how we'll process this pause/resume situation, and ensure |
| 2633 | // that the state is reset however we wind up proceeding. |
Wale Ogunwale | c59b4f6 | 2017-11-30 11:05:43 -0800 | [diff] [blame] | 2634 | boolean userLeaving = mStackSupervisor.mUserLeaving; |
Craig Mautner | de4ef02 | 2013-04-07 19:01:33 -0700 | [diff] [blame] | 2635 | mStackSupervisor.mUserLeaving = false; |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 2636 | |
Andrii Kulian | 7fc2281 | 2016-12-28 13:04:11 -0800 | [diff] [blame] | 2637 | if (!hasRunningActivity) { |
| 2638 | // There are no activities left in the stack, let's look somewhere else. |
| 2639 | return resumeTopActivityInNextFocusableStack(prev, options, "noMoreActivities"); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 2640 | } |
| 2641 | |
| 2642 | next.delayedResume = false; |
Riddle Hsu | bbb63c2 | 2018-10-03 12:28:29 +0800 | [diff] [blame] | 2643 | final ActivityDisplay display = getDisplay(); |
Craig Mautner | 5854780 | 2013-03-05 08:23:53 -0800 | [diff] [blame] | 2644 | |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 2645 | // If the top activity is the resumed one, nothing to do. |
Bryce Lee | 7ace395 | 2018-02-16 14:34:32 -0800 | [diff] [blame] | 2646 | if (mResumedActivity == next && next.isState(RESUMED) |
Riddle Hsu | bbb63c2 | 2018-10-03 12:28:29 +0800 | [diff] [blame] | 2647 | && display.allResumedActivitiesComplete()) { |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 2648 | // Make sure we have executed any pending transitions, since there |
| 2649 | // should be nothing left to do at this point. |
skuhne@google.com | 1b974dc | 2016-12-09 13:41:29 -0800 | [diff] [blame] | 2650 | executeAppTransition(options); |
Wale Ogunwale | 0fc365c | 2015-05-25 19:35:42 -0700 | [diff] [blame] | 2651 | if (DEBUG_STATES) Slog.d(TAG_STATES, |
| 2652 | "resumeTopActivityLocked: Top activity resumed " + next); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 2653 | return false; |
| 2654 | } |
| 2655 | |
Louis Chang | 77ce34d | 2019-01-03 15:45:12 +0800 | [diff] [blame] | 2656 | if (!next.canResumeByCompat()) { |
| 2657 | return false; |
| 2658 | } |
| 2659 | |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 2660 | // If we are sleeping, and there is no resumed activity, and the top |
| 2661 | // activity is paused, well that is the state we want. |
David Stevens | 9440dc8 | 2017-03-16 19:00:20 -0700 | [diff] [blame] | 2662 | if (shouldSleepOrShutDownActivities() |
p13451 | dbad287 | 2012-04-18 11:39:23 +0900 | [diff] [blame] | 2663 | && mLastPausedActivity == next |
Wale Ogunwale | d32da47 | 2018-11-16 07:19:28 -0800 | [diff] [blame] | 2664 | && mRootActivityContainer.allPausedActivitiesComplete()) { |
Riddle Hsu | ef71377 | 2018-09-18 01:28:53 +0800 | [diff] [blame] | 2665 | // If the current top activity may be able to occlude keyguard but the occluded state |
| 2666 | // has not been set, update visibility and check again if we should continue to resume. |
| 2667 | boolean nothingToResume = true; |
Riddle Hsu | 32a87b8 | 2018-11-21 00:08:19 +0800 | [diff] [blame] | 2668 | if (!mService.mShuttingDown) { |
| 2669 | final boolean canShowWhenLocked = !mTopActivityOccludesKeyguard |
| 2670 | && next.canShowWhenLocked(); |
| 2671 | final boolean mayDismissKeyguard = mTopDismissingKeyguardActivity != next |
Issei Suzuki | 74e1eb2 | 2018-12-20 17:42:52 +0100 | [diff] [blame] | 2672 | && next.mAppWindowToken != null |
| 2673 | && next.mAppWindowToken.containsDismissKeyguardWindow(); |
| 2674 | |
Riddle Hsu | 32a87b8 | 2018-11-21 00:08:19 +0800 | [diff] [blame] | 2675 | if (canShowWhenLocked || mayDismissKeyguard) { |
| 2676 | ensureActivitiesVisibleLocked(null /* starting */, 0 /* configChanges */, |
| 2677 | !PRESERVE_WINDOWS); |
| 2678 | nothingToResume = shouldSleepActivities(); |
| 2679 | } |
Riddle Hsu | ef71377 | 2018-09-18 01:28:53 +0800 | [diff] [blame] | 2680 | } |
| 2681 | if (nothingToResume) { |
| 2682 | // Make sure we have executed any pending transitions, since there |
| 2683 | // should be nothing left to do at this point. |
| 2684 | executeAppTransition(options); |
| 2685 | if (DEBUG_STATES) Slog.d(TAG_STATES, |
| 2686 | "resumeTopActivityLocked: Going to sleep and all paused"); |
Riddle Hsu | ef71377 | 2018-09-18 01:28:53 +0800 | [diff] [blame] | 2687 | return false; |
| 2688 | } |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 2689 | } |
Dianne Hackborn | 80a4af2 | 2012-08-27 19:18:31 -0700 | [diff] [blame] | 2690 | |
| 2691 | // Make sure that the user who owns this activity is started. If not, |
| 2692 | // we will just leave it as is because someone should be bringing |
| 2693 | // another user's activities to the top of the stack. |
Wale Ogunwale | 8b19de9 | 2018-11-29 19:58:26 -0800 | [diff] [blame] | 2694 | if (!mService.mAmInternal.hasStartedUserState(next.mUserId)) { |
Dianne Hackborn | 80a4af2 | 2012-08-27 19:18:31 -0700 | [diff] [blame] | 2695 | Slog.w(TAG, "Skipping resume of top activity " + next |
Wale Ogunwale | 8b19de9 | 2018-11-29 19:58:26 -0800 | [diff] [blame] | 2696 | + ": user " + next.mUserId + " is stopped"); |
Dianne Hackborn | 80a4af2 | 2012-08-27 19:18:31 -0700 | [diff] [blame] | 2697 | return false; |
| 2698 | } |
| 2699 | |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 2700 | // The activity may be waiting for stop, but that is no longer |
| 2701 | // appropriate for it. |
Craig Mautner | de4ef02 | 2013-04-07 19:01:33 -0700 | [diff] [blame] | 2702 | mStackSupervisor.mStoppingActivities.remove(next); |
Craig Mautner | 0eea92c | 2013-05-16 13:35:39 -0700 | [diff] [blame] | 2703 | mStackSupervisor.mGoingToSleepActivities.remove(next); |
Dianne Hackborn | 4eba96b | 2011-01-21 13:34:36 -0800 | [diff] [blame] | 2704 | next.sleeping = false; |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 2705 | |
Wale Ogunwale | ee006da | 2015-03-30 14:49:25 -0700 | [diff] [blame] | 2706 | if (DEBUG_SWITCH) Slog.v(TAG_SWITCH, "Resuming " + next); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 2707 | |
Wale Ogunwale | 5658e4b | 2016-02-12 12:22:19 -0800 | [diff] [blame] | 2708 | // If we are currently pausing an activity, then don't do anything until that is done. |
Wale Ogunwale | d32da47 | 2018-11-16 07:19:28 -0800 | [diff] [blame] | 2709 | if (!mRootActivityContainer.allPausedActivitiesComplete()) { |
Wale Ogunwale | ee006da | 2015-03-30 14:49:25 -0700 | [diff] [blame] | 2710 | if (DEBUG_SWITCH || DEBUG_PAUSE || DEBUG_STATES) Slog.v(TAG_PAUSE, |
Craig Mautner | ac6f843 | 2013-07-17 13:24:59 -0700 | [diff] [blame] | 2711 | "resumeTopActivityLocked: Skip resume: some activity pausing."); |
Andrii Kulian | 6b32151 | 2019-01-23 06:37:00 +0000 | [diff] [blame] | 2712 | |
Dianne Hackborn | 621e2fe | 2012-02-16 17:07:33 -0800 | [diff] [blame] | 2713 | return false; |
| 2714 | } |
| 2715 | |
Dianne Hackborn | 3d07c94 | 2015-03-13 18:02:54 -0700 | [diff] [blame] | 2716 | mStackSupervisor.setLaunchSource(next.info.applicationInfo.uid); |
| 2717 | |
Wale Ogunwale | 8997322 | 2017-04-23 18:39:45 -0700 | [diff] [blame] | 2718 | boolean lastResumedCanPip = false; |
chaviw | 4ad5491 | 2018-05-30 11:05:44 -0700 | [diff] [blame] | 2719 | ActivityRecord lastResumed = null; |
Riddle Hsu | bbb63c2 | 2018-10-03 12:28:29 +0800 | [diff] [blame] | 2720 | final ActivityStack lastFocusedStack = display.getLastFocusedStack(); |
Wale Ogunwale | 8997322 | 2017-04-23 18:39:45 -0700 | [diff] [blame] | 2721 | if (lastFocusedStack != null && lastFocusedStack != this) { |
| 2722 | // So, why aren't we using prev here??? See the param comment on the method. prev doesn't |
| 2723 | // represent the last resumed activity. However, the last focus stack does if it isn't null. |
chaviw | 4ad5491 | 2018-05-30 11:05:44 -0700 | [diff] [blame] | 2724 | lastResumed = lastFocusedStack.mResumedActivity; |
Wale Ogunwale | c59b4f6 | 2017-11-30 11:05:43 -0800 | [diff] [blame] | 2725 | if (userLeaving && inMultiWindowMode() && lastFocusedStack.shouldBeVisible(next)) { |
| 2726 | // The user isn't leaving if this stack is the multi-window mode and the last |
| 2727 | // focused stack should still be visible. |
| 2728 | if(DEBUG_USER_LEAVING) Slog.i(TAG_USER_LEAVING, "Overriding userLeaving to false" |
| 2729 | + " next=" + next + " lastResumed=" + lastResumed); |
| 2730 | userLeaving = false; |
| 2731 | } |
Wale Ogunwale | 8997322 | 2017-04-23 18:39:45 -0700 | [diff] [blame] | 2732 | lastResumedCanPip = lastResumed != null && lastResumed.checkEnterPictureInPictureState( |
Winson Chung | 298f95b | 2017-08-10 15:57:18 -0700 | [diff] [blame] | 2733 | "resumeTopActivity", userLeaving /* beforeStopping */); |
Wale Ogunwale | 8997322 | 2017-04-23 18:39:45 -0700 | [diff] [blame] | 2734 | } |
Winson Chung | c2baac0 | 2017-01-11 13:34:47 -0800 | [diff] [blame] | 2735 | // If the flag RESUME_WHILE_PAUSING is set, then continue to schedule the previous activity |
Wale Ogunwale | b9a0c99 | 2017-04-18 07:25:20 -0700 | [diff] [blame] | 2736 | // to be paused, while at the same time resuming the new resume activity only if the |
| 2737 | // previous activity can't go into Pip since we want to give Pip activities a chance to |
| 2738 | // enter Pip before resuming the next activity. |
Wale Ogunwale | 8997322 | 2017-04-23 18:39:45 -0700 | [diff] [blame] | 2739 | final boolean resumeWhilePausing = (next.info.flags & FLAG_RESUME_WHILE_PAUSING) != 0 |
| 2740 | && !lastResumedCanPip; |
| 2741 | |
Andrii Kulian | ab132ee | 2018-07-24 22:10:21 +0800 | [diff] [blame] | 2742 | boolean pausing = getDisplay().pauseBackStacks(userLeaving, next, false); |
Craig Mautner | eb95786 | 2013-04-24 15:34:32 -0700 | [diff] [blame] | 2743 | if (mResumedActivity != null) { |
Wale Ogunwale | 0fc365c | 2015-05-25 19:35:42 -0700 | [diff] [blame] | 2744 | if (DEBUG_STATES) Slog.d(TAG_STATES, |
| 2745 | "resumeTopActivityLocked: Pausing " + mResumedActivity); |
Winson Chung | c2baac0 | 2017-01-11 13:34:47 -0800 | [diff] [blame] | 2746 | pausing |= startPausingLocked(userLeaving, false, next, false); |
Craig Mautner | eb95786 | 2013-04-24 15:34:32 -0700 | [diff] [blame] | 2747 | } |
Winson Chung | c2baac0 | 2017-01-11 13:34:47 -0800 | [diff] [blame] | 2748 | if (pausing && !resumeWhilePausing) { |
Wale Ogunwale | 0fc365c | 2015-05-25 19:35:42 -0700 | [diff] [blame] | 2749 | if (DEBUG_SWITCH || DEBUG_STATES) Slog.v(TAG_STATES, |
Craig Mautner | ac6f843 | 2013-07-17 13:24:59 -0700 | [diff] [blame] | 2750 | "resumeTopActivityLocked: Skip resume: need to start pausing"); |
Dianne Hackborn | ad9b3211 | 2012-09-17 15:35:01 -0700 | [diff] [blame] | 2751 | // At this point we want to put the upcoming activity's process |
| 2752 | // at the top of the LRU list, since we know we will be needing it |
| 2753 | // very soon and it would be a waste to let it get killed if it |
| 2754 | // happens to be sitting towards the end. |
Wale Ogunwale | 9e4f3e0 | 2018-05-17 09:35:39 -0700 | [diff] [blame] | 2755 | if (next.attachedToProcess()) { |
| 2756 | next.app.updateProcessInfo(false /* updateServiceConnectionActivities */, |
| 2757 | true /* updateLru */, true /* activityChange */, false /* updateOomAdj */); |
Dianne Hackborn | ad9b3211 | 2012-09-17 15:35:01 -0700 | [diff] [blame] | 2758 | } |
chaviw | 4ad5491 | 2018-05-30 11:05:44 -0700 | [diff] [blame] | 2759 | if (lastResumed != null) { |
| 2760 | lastResumed.setWillCloseOrEnterPip(true); |
| 2761 | } |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 2762 | return true; |
Bryce Lee | 7ace395 | 2018-02-16 14:34:32 -0800 | [diff] [blame] | 2763 | } else if (mResumedActivity == next && next.isState(RESUMED) |
Riddle Hsu | bbb63c2 | 2018-10-03 12:28:29 +0800 | [diff] [blame] | 2764 | && display.allResumedActivitiesComplete()) { |
Wale Ogunwale | cac5c32 | 2016-05-23 10:56:33 -0700 | [diff] [blame] | 2765 | // It is possible for the activity to be resumed when we paused back stacks above if the |
| 2766 | // next activity doesn't have to wait for pause to complete. |
| 2767 | // So, nothing else to-do except: |
| 2768 | // Make sure we have executed any pending transitions, since there |
| 2769 | // should be nothing left to do at this point. |
skuhne@google.com | 1b974dc | 2016-12-09 13:41:29 -0800 | [diff] [blame] | 2770 | executeAppTransition(options); |
Wale Ogunwale | cac5c32 | 2016-05-23 10:56:33 -0700 | [diff] [blame] | 2771 | if (DEBUG_STATES) Slog.d(TAG_STATES, |
| 2772 | "resumeTopActivityLocked: Top activity resumed (dontWaitForPause) " + next); |
Wale Ogunwale | cac5c32 | 2016-05-23 10:56:33 -0700 | [diff] [blame] | 2773 | return true; |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 2774 | } |
| 2775 | |
Christopher Tate | d3f175c | 2012-06-14 14:16:54 -0700 | [diff] [blame] | 2776 | // If the most recent activity was noHistory but was only stopped rather |
| 2777 | // than stopped+finished because the device went to sleep, we need to make |
| 2778 | // sure to finish it as we're making a new activity topmost. |
David Stevens | 9440dc8 | 2017-03-16 19:00:20 -0700 | [diff] [blame] | 2779 | if (shouldSleepActivities() && mLastNoHistoryActivity != null && |
Craig Mautner | 0f92274 | 2013-08-06 08:44:42 -0700 | [diff] [blame] | 2780 | !mLastNoHistoryActivity.finishing) { |
Wale Ogunwale | 0fc365c | 2015-05-25 19:35:42 -0700 | [diff] [blame] | 2781 | if (DEBUG_STATES) Slog.d(TAG_STATES, |
| 2782 | "no-history finish of " + mLastNoHistoryActivity + " on new resume"); |
Craig Mautner | 0f92274 | 2013-08-06 08:44:42 -0700 | [diff] [blame] | 2783 | requestFinishActivityLocked(mLastNoHistoryActivity.appToken, Activity.RESULT_CANCELED, |
Todd Kennedy | 539db51 | 2014-12-15 09:57:55 -0800 | [diff] [blame] | 2784 | null, "resume-no-history", false); |
Craig Mautner | 0f92274 | 2013-08-06 08:44:42 -0700 | [diff] [blame] | 2785 | mLastNoHistoryActivity = null; |
Christopher Tate | d3f175c | 2012-06-14 14:16:54 -0700 | [diff] [blame] | 2786 | } |
| 2787 | |
Jorim Jaggi | 9b5e331 | 2019-03-01 18:08:00 +0100 | [diff] [blame] | 2788 | if (prev != null && prev != next && next.nowVisible) { |
| 2789 | |
| 2790 | // The next activity is already visible, so hide the previous |
| 2791 | // activity's windows right now so we can show the new one ASAP. |
| 2792 | // We only do this if the previous is finishing, which should mean |
| 2793 | // it is on top of the one being resumed so hiding it quickly |
| 2794 | // is good. Otherwise, we want to do the normal route of allowing |
| 2795 | // the resumed activity to be shown so we can decide if the |
| 2796 | // previous should actually be hidden depending on whether the |
| 2797 | // new one is found to be full-screen or not. |
| 2798 | if (prev.finishing) { |
| 2799 | prev.setVisibility(false); |
Wale Ogunwale | ee006da | 2015-03-30 14:49:25 -0700 | [diff] [blame] | 2800 | if (DEBUG_SWITCH) Slog.v(TAG_SWITCH, |
Jorim Jaggi | 9b5e331 | 2019-03-01 18:08:00 +0100 | [diff] [blame] | 2801 | "Not waiting for visible to hide: " + prev |
| 2802 | + ", nowVisible=" + next.nowVisible); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 2803 | } else { |
Jorim Jaggi | 9b5e331 | 2019-03-01 18:08:00 +0100 | [diff] [blame] | 2804 | if (DEBUG_SWITCH) Slog.v(TAG_SWITCH, |
| 2805 | "Previous already visible but still waiting to hide: " + prev |
| 2806 | + ", nowVisible=" + next.nowVisible); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 2807 | } |
Jorim Jaggi | 9b5e331 | 2019-03-01 18:08:00 +0100 | [diff] [blame] | 2808 | |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 2809 | } |
| 2810 | |
Dianne Hackborn | e7f9721 | 2011-02-24 14:40:20 -0800 | [diff] [blame] | 2811 | // Launching this app's activity, make sure the app is no longer |
| 2812 | // considered stopped. |
| 2813 | try { |
| 2814 | AppGlobals.getPackageManager().setPackageStoppedState( |
Wale Ogunwale | 8b19de9 | 2018-11-29 19:58:26 -0800 | [diff] [blame] | 2815 | next.packageName, false, next.mUserId); /* TODO: Verify if correct userid */ |
Dianne Hackborn | e7f9721 | 2011-02-24 14:40:20 -0800 | [diff] [blame] | 2816 | } catch (RemoteException e1) { |
Dianne Hackborn | a925cd4 | 2011-03-10 13:18:20 -0800 | [diff] [blame] | 2817 | } catch (IllegalArgumentException e) { |
| 2818 | Slog.w(TAG, "Failed trying to unstop package " |
| 2819 | + next.packageName + ": " + e); |
Dianne Hackborn | e7f9721 | 2011-02-24 14:40:20 -0800 | [diff] [blame] | 2820 | } |
| 2821 | |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 2822 | // We are starting up the next activity, so tell the window manager |
| 2823 | // that the previous one will be hidden soon. This way it can know |
| 2824 | // to ignore it when computing the desired screen orientation. |
Craig Mautner | 525f3d9 | 2013-05-07 14:01:50 -0700 | [diff] [blame] | 2825 | boolean anim = true; |
Wale Ogunwale | 3a256e6 | 2018-12-06 14:41:18 -0800 | [diff] [blame] | 2826 | final DisplayContent dc = getDisplay().mDisplayContent; |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 2827 | if (prev != null) { |
| 2828 | if (prev.finishing) { |
Wale Ogunwale | ee006da | 2015-03-30 14:49:25 -0700 | [diff] [blame] | 2829 | if (DEBUG_TRANSITION) Slog.v(TAG_TRANSITION, |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 2830 | "Prepare close transition: prev=" + prev); |
Jorim Jaggi | fa9ed96 | 2018-01-25 00:16:49 +0100 | [diff] [blame] | 2831 | if (mStackSupervisor.mNoAnimActivities.contains(prev)) { |
Craig Mautner | 525f3d9 | 2013-05-07 14:01:50 -0700 | [diff] [blame] | 2832 | anim = false; |
Wale Ogunwale | 3a256e6 | 2018-12-06 14:41:18 -0800 | [diff] [blame] | 2833 | dc.prepareAppTransition(TRANSIT_NONE, false); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 2834 | } else { |
Wale Ogunwale | 3a256e6 | 2018-12-06 14:41:18 -0800 | [diff] [blame] | 2835 | dc.prepareAppTransition( |
Wale Ogunwale | 8b19de9 | 2018-11-29 19:58:26 -0800 | [diff] [blame] | 2836 | prev.getTaskRecord() == next.getTaskRecord() ? TRANSIT_ACTIVITY_CLOSE |
lumark | 588a3e8 | 2018-07-20 18:53:54 +0800 | [diff] [blame] | 2837 | : TRANSIT_TASK_CLOSE, false); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 2838 | } |
Wale Ogunwale | 26c0dfe | 2016-12-14 14:42:30 -0800 | [diff] [blame] | 2839 | prev.setVisibility(false); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 2840 | } else { |
Wale Ogunwale | ee006da | 2015-03-30 14:49:25 -0700 | [diff] [blame] | 2841 | if (DEBUG_TRANSITION) Slog.v(TAG_TRANSITION, |
| 2842 | "Prepare open transition: prev=" + prev); |
Jorim Jaggi | fa9ed96 | 2018-01-25 00:16:49 +0100 | [diff] [blame] | 2843 | if (mStackSupervisor.mNoAnimActivities.contains(next)) { |
Craig Mautner | 525f3d9 | 2013-05-07 14:01:50 -0700 | [diff] [blame] | 2844 | anim = false; |
Wale Ogunwale | 3a256e6 | 2018-12-06 14:41:18 -0800 | [diff] [blame] | 2845 | dc.prepareAppTransition(TRANSIT_NONE, false); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 2846 | } else { |
Wale Ogunwale | 3a256e6 | 2018-12-06 14:41:18 -0800 | [diff] [blame] | 2847 | dc.prepareAppTransition( |
Wale Ogunwale | 8b19de9 | 2018-11-29 19:58:26 -0800 | [diff] [blame] | 2848 | prev.getTaskRecord() == next.getTaskRecord() ? TRANSIT_ACTIVITY_OPEN |
lumark | 588a3e8 | 2018-07-20 18:53:54 +0800 | [diff] [blame] | 2849 | : next.mLaunchTaskBehind ? TRANSIT_TASK_OPEN_BEHIND |
| 2850 | : TRANSIT_TASK_OPEN, false); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 2851 | } |
| 2852 | } |
Craig Mautner | 967212c | 2013-04-13 21:10:58 -0700 | [diff] [blame] | 2853 | } else { |
Wale Ogunwale | ee006da | 2015-03-30 14:49:25 -0700 | [diff] [blame] | 2854 | if (DEBUG_TRANSITION) Slog.v(TAG_TRANSITION, "Prepare open transition: no previous"); |
Jorim Jaggi | fa9ed96 | 2018-01-25 00:16:49 +0100 | [diff] [blame] | 2855 | if (mStackSupervisor.mNoAnimActivities.contains(next)) { |
Craig Mautner | 525f3d9 | 2013-05-07 14:01:50 -0700 | [diff] [blame] | 2856 | anim = false; |
Wale Ogunwale | 3a256e6 | 2018-12-06 14:41:18 -0800 | [diff] [blame] | 2857 | dc.prepareAppTransition(TRANSIT_NONE, false); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 2858 | } else { |
Wale Ogunwale | 3a256e6 | 2018-12-06 14:41:18 -0800 | [diff] [blame] | 2859 | dc.prepareAppTransition(TRANSIT_ACTIVITY_OPEN, false); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 2860 | } |
| 2861 | } |
Adam Powell | cfbe9be | 2013-11-06 14:58:58 -0800 | [diff] [blame] | 2862 | |
Craig Mautner | 525f3d9 | 2013-05-07 14:01:50 -0700 | [diff] [blame] | 2863 | if (anim) { |
Dianne Hackborn | 7a2195c | 2012-03-19 17:38:00 -0700 | [diff] [blame] | 2864 | next.applyOptionsLocked(); |
| 2865 | } else { |
| 2866 | next.clearOptionsLocked(); |
| 2867 | } |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 2868 | |
Jorim Jaggi | fa9ed96 | 2018-01-25 00:16:49 +0100 | [diff] [blame] | 2869 | mStackSupervisor.mNoAnimActivities.clear(); |
| 2870 | |
Wale Ogunwale | 9e4f3e0 | 2018-05-17 09:35:39 -0700 | [diff] [blame] | 2871 | if (next.attachedToProcess()) { |
Chong Zhang | dea4bd9 | 2016-03-15 12:50:03 -0700 | [diff] [blame] | 2872 | if (DEBUG_SWITCH) Slog.v(TAG_SWITCH, "Resume running: " + next |
| 2873 | + " stopped=" + next.stopped + " visible=" + next.visible); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 2874 | |
Chong Zhang | d127c6d | 2016-05-02 16:36:41 -0700 | [diff] [blame] | 2875 | // If the previous activity is translucent, force a visibility update of |
| 2876 | // the next activity, so that it's added to WM's opening app list, and |
| 2877 | // transition animation can be set up properly. |
| 2878 | // For example, pressing Home button with a translucent activity in focus. |
| 2879 | // Launcher is already visible in this case. If we don't add it to opening |
| 2880 | // apps, maybeUpdateTransitToWallpaper() will fail to identify this as a |
| 2881 | // TRANSIT_WALLPAPER_OPEN animation, and run some funny animation. |
Riddle Hsu | bbb63c2 | 2018-10-03 12:28:29 +0800 | [diff] [blame] | 2882 | final boolean lastActivityTranslucent = lastFocusedStack != null |
| 2883 | && (lastFocusedStack.inMultiWindowMode() |
| 2884 | || (lastFocusedStack.mLastPausedActivity != null |
| 2885 | && !lastFocusedStack.mLastPausedActivity.fullscreen)); |
Chong Zhang | d127c6d | 2016-05-02 16:36:41 -0700 | [diff] [blame] | 2886 | |
Wale Ogunwale | 1f5e53d | 2018-11-05 05:12:46 -0800 | [diff] [blame] | 2887 | // This activity is now becoming visible. |
| 2888 | if (!next.visible || next.stopped || lastActivityTranslucent) { |
| 2889 | next.setVisibility(true); |
| 2890 | } |
| 2891 | |
| 2892 | // schedule launch ticks to collect information about slow apps. |
| 2893 | next.startLaunchTickingLocked(); |
| 2894 | |
| 2895 | ActivityRecord lastResumedActivity = |
| 2896 | lastFocusedStack == null ? null : lastFocusedStack.mResumedActivity; |
| 2897 | final ActivityState lastState = next.getState(); |
| 2898 | |
| 2899 | mService.updateCpuStats(); |
| 2900 | |
| 2901 | if (DEBUG_STATES) Slog.v(TAG_STATES, "Moving to RESUMED: " + next |
| 2902 | + " (in existing)"); |
| 2903 | |
| 2904 | next.setState(RESUMED, "resumeTopActivityInnerLocked"); |
| 2905 | |
| 2906 | next.app.updateProcessInfo(false /* updateServiceConnectionActivities */, |
| 2907 | true /* updateLru */, true /* activityChange */, true /* updateOomAdj */); |
| 2908 | updateLRUListLocked(next); |
| 2909 | |
| 2910 | // Have the window manager re-evaluate the orientation of |
| 2911 | // the screen based on the new activity order. |
| 2912 | boolean notUpdated = true; |
| 2913 | |
Andrii Kulian | 6b32151 | 2019-01-23 06:37:00 +0000 | [diff] [blame] | 2914 | // Activity should also be visible if set mLaunchTaskBehind to true (see |
| 2915 | // ActivityRecord#shouldBeVisibleIgnoringKeyguard()). |
| 2916 | if (shouldBeVisible(next)) { |
Wale Ogunwale | 1f5e53d | 2018-11-05 05:12:46 -0800 | [diff] [blame] | 2917 | // We have special rotation behavior when here is some active activity that |
| 2918 | // requests specific orientation or Keyguard is locked. Make sure all activity |
| 2919 | // visibilities are set correctly as well as the transition is updated if needed |
| 2920 | // to get the correct rotation behavior. Otherwise the following call to update |
| 2921 | // the orientation may cause incorrect configurations delivered to client as a |
| 2922 | // result of invisible window resize. |
| 2923 | // TODO: Remove this once visibilities are set correctly immediately when |
| 2924 | // starting an activity. |
Wale Ogunwale | d32da47 | 2018-11-16 07:19:28 -0800 | [diff] [blame] | 2925 | notUpdated = !mRootActivityContainer.ensureVisibilityAndConfig(next, mDisplayId, |
Wale Ogunwale | 1f5e53d | 2018-11-05 05:12:46 -0800 | [diff] [blame] | 2926 | true /* markFrozenIfConfigChanged */, false /* deferResume */); |
| 2927 | } |
| 2928 | |
| 2929 | if (notUpdated) { |
| 2930 | // The configuration update wasn't able to keep the existing |
| 2931 | // instance of the activity, and instead started a new one. |
| 2932 | // We should be all done, but let's just make sure our activity |
| 2933 | // is still at the top and schedule another run if something |
| 2934 | // weird happened. |
| 2935 | ActivityRecord nextNext = topRunningActivityLocked(); |
| 2936 | if (DEBUG_SWITCH || DEBUG_STATES) Slog.i(TAG_STATES, |
| 2937 | "Activity config changed during resume: " + next |
| 2938 | + ", new next: " + nextNext); |
| 2939 | if (nextNext != next) { |
| 2940 | // Do over! |
| 2941 | mStackSupervisor.scheduleResumeTopActivities(); |
| 2942 | } |
| 2943 | if (!next.visible || next.stopped) { |
Wale Ogunwale | 26c0dfe | 2016-12-14 14:42:30 -0800 | [diff] [blame] | 2944 | next.setVisibility(true); |
Craig Mautner | de4ef02 | 2013-04-07 19:01:33 -0700 | [diff] [blame] | 2945 | } |
Wale Ogunwale | 1f5e53d | 2018-11-05 05:12:46 -0800 | [diff] [blame] | 2946 | next.completeResumeLocked(); |
Wale Ogunwale | 1f5e53d | 2018-11-05 05:12:46 -0800 | [diff] [blame] | 2947 | return true; |
| 2948 | } |
Craig Mautner | 5854780 | 2013-03-05 08:23:53 -0800 | [diff] [blame] | 2949 | |
Wale Ogunwale | 1f5e53d | 2018-11-05 05:12:46 -0800 | [diff] [blame] | 2950 | try { |
| 2951 | final ClientTransaction transaction = |
| 2952 | ClientTransaction.obtain(next.app.getThread(), next.appToken); |
| 2953 | // Deliver all pending results. |
| 2954 | ArrayList<ResultInfo> a = next.results; |
| 2955 | if (a != null) { |
| 2956 | final int N = a.size(); |
| 2957 | if (!next.finishing && N > 0) { |
| 2958 | if (DEBUG_RESULTS) Slog.v(TAG_RESULTS, |
| 2959 | "Delivering results to " + next + ": " + a); |
| 2960 | transaction.addCallback(ActivityResultItem.obtain(a)); |
| 2961 | } |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 2962 | } |
| 2963 | |
Wale Ogunwale | 1f5e53d | 2018-11-05 05:12:46 -0800 | [diff] [blame] | 2964 | if (next.newIntents != null) { |
| 2965 | transaction.addCallback(NewIntentItem.obtain(next.newIntents, |
| 2966 | false /* andPause */)); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 2967 | } |
| 2968 | |
Wale Ogunwale | 1f5e53d | 2018-11-05 05:12:46 -0800 | [diff] [blame] | 2969 | // Well the app will no longer be stopped. |
| 2970 | // Clear app token stopped state in window manager if needed. |
| 2971 | next.notifyAppResumed(next.stopped); |
Wale Ogunwale | 8d5a542 | 2016-03-03 18:28:21 -0800 | [diff] [blame] | 2972 | |
Wale Ogunwale | 8b19de9 | 2018-11-29 19:58:26 -0800 | [diff] [blame] | 2973 | EventLog.writeEvent(EventLogTags.AM_RESUME_ACTIVITY, next.mUserId, |
| 2974 | System.identityHashCode(next), next.getTaskRecord().taskId, |
Wale Ogunwale | 1f5e53d | 2018-11-05 05:12:46 -0800 | [diff] [blame] | 2975 | next.shortComponentName); |
Craig Mautner | 5854780 | 2013-03-05 08:23:53 -0800 | [diff] [blame] | 2976 | |
Wale Ogunwale | 1f5e53d | 2018-11-05 05:12:46 -0800 | [diff] [blame] | 2977 | next.sleeping = false; |
| 2978 | mService.getAppWarningsLocked().onResumeActivity(next); |
| 2979 | next.app.setPendingUiCleanAndForceProcessStateUpTo(mService.mTopProcessState); |
| 2980 | next.clearOptionsLocked(); |
| 2981 | transaction.setLifecycleStateRequest( |
| 2982 | ResumeActivityItem.obtain(next.app.getReportedProcState(), |
Wale Ogunwale | 3a256e6 | 2018-12-06 14:41:18 -0800 | [diff] [blame] | 2983 | getDisplay().mDisplayContent.isNextTransitionForward())); |
Wale Ogunwale | 1f5e53d | 2018-11-05 05:12:46 -0800 | [diff] [blame] | 2984 | mService.getLifecycleManager().scheduleTransaction(transaction); |
Craig Mautner | 5854780 | 2013-03-05 08:23:53 -0800 | [diff] [blame] | 2985 | |
Wale Ogunwale | 1f5e53d | 2018-11-05 05:12:46 -0800 | [diff] [blame] | 2986 | if (DEBUG_STATES) Slog.d(TAG_STATES, "resumeTopActivityLocked: Resumed " |
| 2987 | + next); |
| 2988 | } catch (Exception e) { |
| 2989 | // Whoops, need to restart this activity! |
| 2990 | if (DEBUG_STATES) Slog.v(TAG_STATES, "Resume failed; resetting state to " |
| 2991 | + lastState + ": " + next); |
| 2992 | next.setState(lastState, "resumeTopActivityInnerLocked"); |
Bryce Lee | 69ad818 | 2017-09-28 10:01:36 -0700 | [diff] [blame] | 2993 | |
Wale Ogunwale | 1f5e53d | 2018-11-05 05:12:46 -0800 | [diff] [blame] | 2994 | // lastResumedActivity being non-null implies there is a lastStack present. |
| 2995 | if (lastResumedActivity != null) { |
| 2996 | lastResumedActivity.setState(RESUMED, "resumeTopActivityInnerLocked"); |
Craig Mautner | f88c50f | 2013-04-18 19:25:12 -0700 | [diff] [blame] | 2997 | } |
Wale Ogunwale | 1f5e53d | 2018-11-05 05:12:46 -0800 | [diff] [blame] | 2998 | |
| 2999 | Slog.i(TAG, "Restarting because process died: " + next); |
| 3000 | if (!next.hasBeenLaunched) { |
| 3001 | next.hasBeenLaunched = true; |
| 3002 | } else if (SHOW_APP_STARTING_PREVIEW && lastFocusedStack != null |
| 3003 | && lastFocusedStack.isTopStackOnDisplay()) { |
| 3004 | next.showStartingWindow(null /* prev */, false /* newTask */, |
| 3005 | false /* taskSwitch */); |
| 3006 | } |
| 3007 | mStackSupervisor.startSpecificActivityLocked(next, true, false); |
Wale Ogunwale | 1f5e53d | 2018-11-05 05:12:46 -0800 | [diff] [blame] | 3008 | return true; |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 3009 | } |
| 3010 | |
| 3011 | // From this point on, if something goes wrong there is no way |
| 3012 | // to recover the activity. |
| 3013 | try { |
Andrii Kulian | 21713ac | 2016-10-12 22:05:05 -0700 | [diff] [blame] | 3014 | next.completeResumeLocked(); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 3015 | } catch (Exception e) { |
| 3016 | // If any exception gets thrown, toss away this |
| 3017 | // activity and try the next one. |
| 3018 | Slog.w(TAG, "Exception thrown during resume of " + next, e); |
Dianne Hackborn | be70785 | 2011-11-11 14:32:10 -0800 | [diff] [blame] | 3019 | requestFinishActivityLocked(next.appToken, Activity.RESULT_CANCELED, null, |
Dianne Hackborn | 2d1b378 | 2012-09-09 17:49:39 -0700 | [diff] [blame] | 3020 | "resume-exception", true); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 3021 | return true; |
| 3022 | } |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 3023 | } else { |
| 3024 | // Whoops, need to restart this activity! |
| 3025 | if (!next.hasBeenLaunched) { |
| 3026 | next.hasBeenLaunched = true; |
| 3027 | } else { |
| 3028 | if (SHOW_APP_STARTING_PREVIEW) { |
Jorim Jaggi | 02886a8 | 2016-12-06 09:10:06 -0800 | [diff] [blame] | 3029 | next.showStartingWindow(null /* prev */, false /* newTask */, |
| 3030 | false /* taskSwich */); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 3031 | } |
Wale Ogunwale | ee006da | 2015-03-30 14:49:25 -0700 | [diff] [blame] | 3032 | if (DEBUG_SWITCH) Slog.v(TAG_SWITCH, "Restarting: " + next); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 3033 | } |
Wale Ogunwale | 0fc365c | 2015-05-25 19:35:42 -0700 | [diff] [blame] | 3034 | if (DEBUG_STATES) Slog.d(TAG_STATES, "resumeTopActivityLocked: Restarting " + next); |
George Mount | 2c92c97 | 2014-03-20 09:38:23 -0700 | [diff] [blame] | 3035 | mStackSupervisor.startSpecificActivityLocked(next, true, true); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 3036 | } |
| 3037 | |
| 3038 | return true; |
| 3039 | } |
| 3040 | |
Andrii Kulian | 7fc2281 | 2016-12-28 13:04:11 -0800 | [diff] [blame] | 3041 | private boolean resumeTopActivityInNextFocusableStack(ActivityRecord prev, |
| 3042 | ActivityOptions options, String reason) { |
Andrii Kulian | ab132ee | 2018-07-24 22:10:21 +0800 | [diff] [blame] | 3043 | final ActivityStack nextFocusedStack = adjustFocusToNextFocusableStack(reason); |
| 3044 | if (nextFocusedStack != null) { |
Andrii Kulian | 7fc2281 | 2016-12-28 13:04:11 -0800 | [diff] [blame] | 3045 | // Try to move focus to the next visible stack with a running activity if this |
| 3046 | // stack is not covering the entire screen or is on a secondary display (with no home |
| 3047 | // stack). |
Wale Ogunwale | d32da47 | 2018-11-16 07:19:28 -0800 | [diff] [blame] | 3048 | return mRootActivityContainer.resumeFocusedStacksTopActivities(nextFocusedStack, prev, |
Andrii Kulian | ab132ee | 2018-07-24 22:10:21 +0800 | [diff] [blame] | 3049 | null /* targetOptions */); |
Andrii Kulian | 7fc2281 | 2016-12-28 13:04:11 -0800 | [diff] [blame] | 3050 | } |
| 3051 | |
| 3052 | // Let's just start up the Launcher... |
| 3053 | ActivityOptions.abort(options); |
| 3054 | if (DEBUG_STATES) Slog.d(TAG_STATES, |
| 3055 | "resumeTopActivityInNextFocusableStack: " + reason + ", go home"); |
Louis Chang | cc56871 | 2019-03-08 14:54:41 +0800 | [diff] [blame^] | 3056 | if (isActivityTypeHome()) { |
| 3057 | // resumeTopActivityUncheckedLocked has been prevented to run recursively. Post a |
| 3058 | // runnable to resume home since we are currently in the process of resuming top |
| 3059 | // activity in home stack. |
| 3060 | // See {@link #mInResumeTopActivity}. |
| 3061 | mService.mH.post( |
| 3062 | () -> mRootActivityContainer.resumeHomeActivity(prev, reason, mDisplayId)); |
| 3063 | return true; |
| 3064 | } else { |
| 3065 | return mRootActivityContainer.resumeHomeActivity(prev, reason, mDisplayId); |
| 3066 | } |
Andrii Kulian | 7fc2281 | 2016-12-28 13:04:11 -0800 | [diff] [blame] | 3067 | } |
| 3068 | |
Wale Ogunwale | c5cc301 | 2017-01-13 13:26:16 -0800 | [diff] [blame] | 3069 | /** Returns the position the input task should be placed in this stack. */ |
| 3070 | int getAdjustedPositionForTask(TaskRecord task, int suggestedPosition, |
| 3071 | ActivityRecord starting) { |
| 3072 | |
| 3073 | int maxPosition = mTaskHistory.size(); |
| 3074 | if ((starting != null && starting.okToShowLocked()) |
| 3075 | || (starting == null && task.okToShowLocked())) { |
| 3076 | // If the task or starting activity can be shown, then whatever position is okay. |
| 3077 | return Math.min(suggestedPosition, maxPosition); |
| 3078 | } |
| 3079 | |
| 3080 | // The task can't be shown, put non-current user tasks below current user tasks. |
| 3081 | while (maxPosition > 0) { |
| 3082 | final TaskRecord tmpTask = mTaskHistory.get(maxPosition - 1); |
| 3083 | if (!mStackSupervisor.isCurrentProfileLocked(tmpTask.userId) |
| 3084 | || tmpTask.topRunningActivityLocked() == null) { |
| 3085 | break; |
| 3086 | } |
| 3087 | maxPosition--; |
| 3088 | } |
| 3089 | |
| 3090 | return Math.min(suggestedPosition, maxPosition); |
| 3091 | } |
| 3092 | |
Andrii Kulian | d276563 | 2016-12-12 22:26:34 -0800 | [diff] [blame] | 3093 | /** |
| 3094 | * Used from {@link ActivityStack#positionTask(TaskRecord, int)}. |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 3095 | * @see ActivityTaskManagerService#positionTaskInStack(int, int, int). |
Andrii Kulian | d276563 | 2016-12-12 22:26:34 -0800 | [diff] [blame] | 3096 | */ |
Wale Ogunwale | ddc1cb2 | 2015-07-25 19:23:04 -0700 | [diff] [blame] | 3097 | private void insertTaskAtPosition(TaskRecord task, int position) { |
| 3098 | if (position >= mTaskHistory.size()) { |
| 3099 | insertTaskAtTop(task, null); |
| 3100 | return; |
Evan Rosky | 9c44817 | 2017-11-02 14:19:27 -0700 | [diff] [blame] | 3101 | } else if (position <= 0) { |
| 3102 | insertTaskAtBottom(task); |
| 3103 | return; |
Wale Ogunwale | ddc1cb2 | 2015-07-25 19:23:04 -0700 | [diff] [blame] | 3104 | } |
Wale Ogunwale | c5cc301 | 2017-01-13 13:26:16 -0800 | [diff] [blame] | 3105 | position = getAdjustedPositionForTask(task, position, null /* starting */); |
Wale Ogunwale | ddc1cb2 | 2015-07-25 19:23:04 -0700 | [diff] [blame] | 3106 | mTaskHistory.remove(task); |
| 3107 | mTaskHistory.add(position, task); |
Yunfan Chen | 279f558 | 2018-12-12 15:24:50 -0800 | [diff] [blame] | 3108 | if (mTaskStack != null) { |
| 3109 | // TODO: this could not be false after unification. |
| 3110 | mTaskStack.positionChildAt(task.getTask(), position); |
| 3111 | } |
Wale Ogunwale | ddc1cb2 | 2015-07-25 19:23:04 -0700 | [diff] [blame] | 3112 | updateTaskMovement(task, true); |
| 3113 | } |
| 3114 | |
Wale Ogunwale | c5cc301 | 2017-01-13 13:26:16 -0800 | [diff] [blame] | 3115 | private void insertTaskAtTop(TaskRecord task, ActivityRecord starting) { |
Wale Ogunwale | c5cc301 | 2017-01-13 13:26:16 -0800 | [diff] [blame] | 3116 | // TODO: Better place to put all the code below...may be addTask... |
| 3117 | mTaskHistory.remove(task); |
| 3118 | // Now put task at top. |
| 3119 | final int position = getAdjustedPositionForTask(task, mTaskHistory.size(), starting); |
| 3120 | mTaskHistory.add(position, task); |
| 3121 | updateTaskMovement(task, true); |
Riddle Hsu | 86cb7de | 2018-08-13 23:29:58 +0800 | [diff] [blame] | 3122 | positionChildWindowContainerAtTop(task); |
Wale Ogunwale | e1fe7fa2 | 2016-12-15 18:27:00 -0800 | [diff] [blame] | 3123 | } |
| 3124 | |
Evan Rosky | 9c44817 | 2017-11-02 14:19:27 -0700 | [diff] [blame] | 3125 | private void insertTaskAtBottom(TaskRecord task) { |
Evan Rosky | 9c44817 | 2017-11-02 14:19:27 -0700 | [diff] [blame] | 3126 | mTaskHistory.remove(task); |
| 3127 | final int position = getAdjustedPositionForTask(task, 0, null); |
| 3128 | mTaskHistory.add(position, task); |
| 3129 | updateTaskMovement(task, true); |
Riddle Hsu | 86cb7de | 2018-08-13 23:29:58 +0800 | [diff] [blame] | 3130 | positionChildWindowContainerAtBottom(task); |
Evan Rosky | 9c44817 | 2017-11-02 14:19:27 -0700 | [diff] [blame] | 3131 | } |
| 3132 | |
Bryce Lee | ad5b832 | 2018-03-08 14:28:52 -0800 | [diff] [blame] | 3133 | void startActivityLocked(ActivityRecord r, ActivityRecord focusedTopActivity, |
Winson Chung | b5c41b7 | 2016-12-07 15:00:47 -0800 | [diff] [blame] | 3134 | boolean newTask, boolean keepCurTransition, ActivityOptions options) { |
Wale Ogunwale | 8b19de9 | 2018-11-29 19:58:26 -0800 | [diff] [blame] | 3135 | TaskRecord rTask = r.getTaskRecord(); |
Craig Mautner | d232895 | 2013-03-05 12:46:26 -0800 | [diff] [blame] | 3136 | final int taskId = rTask.taskId; |
Craig Mautner | bb74246 | 2014-07-07 15:28:55 -0700 | [diff] [blame] | 3137 | // mLaunchTaskBehind tasks get placed at the back of the task stack. |
| 3138 | if (!r.mLaunchTaskBehind && (taskForIdLocked(taskId) == null || newTask)) { |
Craig Mautner | 7787877 | 2013-03-04 19:46:24 -0800 | [diff] [blame] | 3139 | // Last activity in task had been removed or ActivityManagerService is reusing task. |
| 3140 | // Insert or replace. |
Craig Mautner | 7787877 | 2013-03-04 19:46:24 -0800 | [diff] [blame] | 3141 | // Might not even be in. |
Wale Ogunwale | 3fcb4a8 | 2015-04-06 14:00:13 -0700 | [diff] [blame] | 3142 | insertTaskAtTop(rTask, r); |
Craig Mautner | 7787877 | 2013-03-04 19:46:24 -0800 | [diff] [blame] | 3143 | } |
Craig Mautner | 525f3d9 | 2013-05-07 14:01:50 -0700 | [diff] [blame] | 3144 | TaskRecord task = null; |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 3145 | if (!newTask) { |
| 3146 | // If starting in an existing task, find where that is... |
Craig Mautner | 70a8693 | 2013-02-28 22:37:44 -0800 | [diff] [blame] | 3147 | boolean startIt = true; |
| 3148 | for (int taskNdx = mTaskHistory.size() - 1; taskNdx >= 0; --taskNdx) { |
| 3149 | task = mTaskHistory.get(taskNdx); |
riddle_hsu | 9bcc6e8 | 2014-07-31 00:26:51 +0800 | [diff] [blame] | 3150 | if (task.getTopActivity() == null) { |
| 3151 | // All activities in task are finishing. |
| 3152 | continue; |
| 3153 | } |
Bryce Lee | af691c0 | 2017-03-20 14:20:22 -0700 | [diff] [blame] | 3154 | if (task == rTask) { |
Craig Mautner | 70a8693 | 2013-02-28 22:37:44 -0800 | [diff] [blame] | 3155 | // Here it is! Now, if this is not yet visible to the |
| 3156 | // user, then just add it without starting; it will |
| 3157 | // get started when the user navigates back to it. |
Craig Mautner | 70a8693 | 2013-02-28 22:37:44 -0800 | [diff] [blame] | 3158 | if (!startIt) { |
| 3159 | if (DEBUG_ADD_REMOVE) Slog.i(TAG, "Adding activity " + r + " to task " |
| 3160 | + task, new RuntimeException("here").fillInStackTrace()); |
Yunfan Chen | 1ee84ea | 2018-11-13 16:03:37 -0800 | [diff] [blame] | 3161 | r.createAppWindowToken(); |
Dianne Hackborn | 8078d8c | 2012-03-20 11:11:26 -0700 | [diff] [blame] | 3162 | ActivityOptions.abort(options); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 3163 | return; |
| 3164 | } |
| 3165 | break; |
Craig Mautner | 70a8693 | 2013-02-28 22:37:44 -0800 | [diff] [blame] | 3166 | } else if (task.numFullscreen > 0) { |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 3167 | startIt = false; |
| 3168 | } |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 3169 | } |
| 3170 | } |
| 3171 | |
Wale Ogunwale | 26c0dfe | 2016-12-14 14:42:30 -0800 | [diff] [blame] | 3172 | // Place a new activity at top of stack, so it is next to interact with the user. |
Craig Mautner | 70a8693 | 2013-02-28 22:37:44 -0800 | [diff] [blame] | 3173 | |
Wale Ogunwale | 26c0dfe | 2016-12-14 14:42:30 -0800 | [diff] [blame] | 3174 | // If we are not placing the new activity frontmost, we do not want to deliver the |
| 3175 | // onUserLeaving callback to the actual frontmost activity |
Wale Ogunwale | 8b19de9 | 2018-11-29 19:58:26 -0800 | [diff] [blame] | 3176 | final TaskRecord activityTask = r.getTaskRecord(); |
Bryce Lee | af691c0 | 2017-03-20 14:20:22 -0700 | [diff] [blame] | 3177 | if (task == activityTask && mTaskHistory.indexOf(task) != (mTaskHistory.size() - 1)) { |
Craig Mautner | de4ef02 | 2013-04-07 19:01:33 -0700 | [diff] [blame] | 3178 | mStackSupervisor.mUserLeaving = false; |
Wale Ogunwale | ee006da | 2015-03-30 14:49:25 -0700 | [diff] [blame] | 3179 | if (DEBUG_USER_LEAVING) Slog.v(TAG_USER_LEAVING, |
Craig Mautner | 70a8693 | 2013-02-28 22:37:44 -0800 | [diff] [blame] | 3180 | "startActivity() behind front, mUserLeaving=false"); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 3181 | } |
Craig Mautner | 70a8693 | 2013-02-28 22:37:44 -0800 | [diff] [blame] | 3182 | |
Bryce Lee | af691c0 | 2017-03-20 14:20:22 -0700 | [diff] [blame] | 3183 | task = activityTask; |
Craig Mautner | 70a8693 | 2013-02-28 22:37:44 -0800 | [diff] [blame] | 3184 | |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 3185 | // Slot the activity into the history stack and proceed |
Craig Mautner | 70a8693 | 2013-02-28 22:37:44 -0800 | [diff] [blame] | 3186 | 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] | 3187 | new RuntimeException("here").fillInStackTrace()); |
Wale Ogunwale | a0cd15e | 2017-02-01 15:33:08 -0800 | [diff] [blame] | 3188 | // TODO: Need to investigate if it is okay for the controller to already be created by the |
| 3189 | // time we get to this point. I think it is, but need to double check. |
| 3190 | // Use test in b/34179495 to trace the call path. |
Yunfan Chen | 1ee84ea | 2018-11-13 16:03:37 -0800 | [diff] [blame] | 3191 | if (r.mAppWindowToken == null) { |
| 3192 | r.createAppWindowToken(); |
Wale Ogunwale | a0cd15e | 2017-02-01 15:33:08 -0800 | [diff] [blame] | 3193 | } |
Yunfan Chen | 1ee84ea | 2018-11-13 16:03:37 -0800 | [diff] [blame] | 3194 | |
Craig Mautner | 1aa9d0d3f | 2013-12-16 15:58:31 -0800 | [diff] [blame] | 3195 | task.setFrontOfTask(); |
Craig Mautner | 70a8693 | 2013-02-28 22:37:44 -0800 | [diff] [blame] | 3196 | |
Matthew Ng | ae1ff4f | 2016-11-10 15:49:14 -0800 | [diff] [blame] | 3197 | if (!isHomeOrRecentsStack() || numActivities() > 0) { |
Wale Ogunwale | 3a256e6 | 2018-12-06 14:41:18 -0800 | [diff] [blame] | 3198 | final DisplayContent dc = getDisplay().mDisplayContent; |
Wale Ogunwale | ee006da | 2015-03-30 14:49:25 -0700 | [diff] [blame] | 3199 | if (DEBUG_TRANSITION) Slog.v(TAG_TRANSITION, |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 3200 | "Prepare open transition: starting " + r); |
Wale Ogunwale | ee006da | 2015-03-30 14:49:25 -0700 | [diff] [blame] | 3201 | if ((r.intent.getFlags() & Intent.FLAG_ACTIVITY_NO_ANIMATION) != 0) { |
Wale Ogunwale | 3a256e6 | 2018-12-06 14:41:18 -0800 | [diff] [blame] | 3202 | dc.prepareAppTransition(TRANSIT_NONE, keepCurTransition); |
Jorim Jaggi | fa9ed96 | 2018-01-25 00:16:49 +0100 | [diff] [blame] | 3203 | mStackSupervisor.mNoAnimActivities.add(r); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 3204 | } else { |
Winson Chung | b5c41b7 | 2016-12-07 15:00:47 -0800 | [diff] [blame] | 3205 | int transit = TRANSIT_ACTIVITY_OPEN; |
| 3206 | if (newTask) { |
| 3207 | if (r.mLaunchTaskBehind) { |
| 3208 | transit = TRANSIT_TASK_OPEN_BEHIND; |
| 3209 | } else { |
Winson Chung | c2baac0 | 2017-01-11 13:34:47 -0800 | [diff] [blame] | 3210 | // If a new task is being launched, then mark the existing top activity as |
Winson Chung | 942a85c | 2017-07-11 15:07:45 -0700 | [diff] [blame] | 3211 | // supporting picture-in-picture while pausing only if the starting activity |
| 3212 | // would not be considered an overlay on top of the current activity |
| 3213 | // (eg. not fullscreen, or the assistant) |
Winson Chung | f7e03e1 | 2017-08-22 11:32:16 -0700 | [diff] [blame] | 3214 | if (canEnterPipOnTaskSwitch(focusedTopActivity, |
| 3215 | null /* toFrontTask */, r, options)) { |
| 3216 | focusedTopActivity.supportsEnterPipOnTaskSwitch = true; |
Winson Chung | b5c41b7 | 2016-12-07 15:00:47 -0800 | [diff] [blame] | 3217 | } |
| 3218 | transit = TRANSIT_TASK_OPEN; |
| 3219 | } |
| 3220 | } |
Wale Ogunwale | 3a256e6 | 2018-12-06 14:41:18 -0800 | [diff] [blame] | 3221 | dc.prepareAppTransition(transit, keepCurTransition); |
Jorim Jaggi | fa9ed96 | 2018-01-25 00:16:49 +0100 | [diff] [blame] | 3222 | mStackSupervisor.mNoAnimActivities.remove(r); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 3223 | } |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 3224 | boolean doShow = true; |
| 3225 | if (newTask) { |
| 3226 | // Even though this activity is starting fresh, we still need |
| 3227 | // to reset it to make sure we apply affinities to move any |
| 3228 | // existing activities from other tasks in to it. |
| 3229 | // If the caller has requested that the target task be |
| 3230 | // reset, then do so. |
Craig Mautner | 9d4e9bc | 2014-06-18 18:34:56 -0700 | [diff] [blame] | 3231 | if ((r.intent.getFlags() & Intent.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED) != 0) { |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 3232 | resetTaskIfNeededLocked(r, r); |
| 3233 | doShow = topRunningNonDelayedActivityLocked(null) == r; |
| 3234 | } |
Chong Zhang | 280d332 | 2015-11-03 17:27:26 -0800 | [diff] [blame] | 3235 | } else if (options != null && options.getAnimationType() |
George Mount | 70778d7 | 2014-07-01 16:33:45 -0700 | [diff] [blame] | 3236 | == ActivityOptions.ANIM_SCENE_TRANSITION) { |
| 3237 | doShow = false; |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 3238 | } |
Craig Mautner | bb74246 | 2014-07-07 15:28:55 -0700 | [diff] [blame] | 3239 | if (r.mLaunchTaskBehind) { |
| 3240 | // Don't do a starting window for mLaunchTaskBehind. More importantly make sure we |
| 3241 | // tell WindowManager that r is visible even though it is at the back of the stack. |
Wale Ogunwale | 26c0dfe | 2016-12-14 14:42:30 -0800 | [diff] [blame] | 3242 | r.setVisibility(true); |
Filip Gruszczynski | bc5a6c5 | 2015-09-22 13:13:24 -0700 | [diff] [blame] | 3243 | ensureActivitiesVisibleLocked(null, 0, !PRESERVE_WINDOWS); |
Craig Mautner | bb74246 | 2014-07-07 15:28:55 -0700 | [diff] [blame] | 3244 | } else if (SHOW_APP_STARTING_PREVIEW && doShow) { |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 3245 | // Figure out if we are transitioning from another activity that is |
| 3246 | // "has the same starting icon" as the next one. This allows the |
| 3247 | // window manager to keep the previous window it had previously |
| 3248 | // created, if it still had one. |
Wale Ogunwale | 8b19de9 | 2018-11-29 19:58:26 -0800 | [diff] [blame] | 3249 | TaskRecord prevTask = r.getTaskRecord(); |
Bryce Lee | af691c0 | 2017-03-20 14:20:22 -0700 | [diff] [blame] | 3250 | ActivityRecord prev = prevTask.topRunningActivityWithStartingWindowLocked(); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 3251 | if (prev != null) { |
| 3252 | // We don't want to reuse the previous starting preview if: |
| 3253 | // (1) The current activity is in a different task. |
Wale Ogunwale | 8b19de9 | 2018-11-29 19:58:26 -0800 | [diff] [blame] | 3254 | if (prev.getTaskRecord() != prevTask) { |
Craig Mautner | 29219d9 | 2013-04-16 20:19:12 -0700 | [diff] [blame] | 3255 | prev = null; |
| 3256 | } |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 3257 | // (2) The current activity is already displayed. |
Craig Mautner | 29219d9 | 2013-04-16 20:19:12 -0700 | [diff] [blame] | 3258 | else if (prev.nowVisible) { |
| 3259 | prev = null; |
| 3260 | } |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 3261 | } |
Jorim Jaggi | 02886a8 | 2016-12-06 09:10:06 -0800 | [diff] [blame] | 3262 | r.showStartingWindow(prev, newTask, isTaskSwitch(r, focusedTopActivity)); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 3263 | } |
| 3264 | } else { |
| 3265 | // If this is the first activity, don't do any fancy animations, |
| 3266 | // because there is nothing for it to animate on top of. |
Dianne Hackborn | 8078d8c | 2012-03-20 11:11:26 -0700 | [diff] [blame] | 3267 | ActivityOptions.abort(options); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 3268 | } |
Dianne Hackborn | be70785 | 2011-11-11 14:32:10 -0800 | [diff] [blame] | 3269 | } |
| 3270 | |
Winson Chung | f7e03e1 | 2017-08-22 11:32:16 -0700 | [diff] [blame] | 3271 | /** |
| 3272 | * @return Whether the switch to another task can trigger the currently running activity to |
| 3273 | * enter PiP while it is pausing (if supported). Only one of {@param toFrontTask} or |
| 3274 | * {@param toFrontActivity} should be set. |
| 3275 | */ |
| 3276 | private boolean canEnterPipOnTaskSwitch(ActivityRecord pipCandidate, |
| 3277 | TaskRecord toFrontTask, ActivityRecord toFrontActivity, ActivityOptions opts) { |
| 3278 | if (opts != null && opts.disallowEnterPictureInPictureWhileLaunching()) { |
| 3279 | // Ensure the caller has requested not to trigger auto-enter PiP |
| 3280 | return false; |
| 3281 | } |
Wale Ogunwale | 44f036f | 2017-09-29 05:09:09 -0700 | [diff] [blame] | 3282 | if (pipCandidate == null || pipCandidate.inPinnedWindowingMode()) { |
Winson Chung | f7e03e1 | 2017-08-22 11:32:16 -0700 | [diff] [blame] | 3283 | // Ensure that we do not trigger entering PiP an activity on the pinned stack |
| 3284 | return false; |
| 3285 | } |
Wale Ogunwale | 6827856 | 2017-09-23 17:13:55 -0700 | [diff] [blame] | 3286 | final ActivityStack targetStack = toFrontTask != null |
Wale Ogunwale | 8b19de9 | 2018-11-29 19:58:26 -0800 | [diff] [blame] | 3287 | ? toFrontTask.getStack() : toFrontActivity.getActivityStack(); |
Wale Ogunwale | 6827856 | 2017-09-23 17:13:55 -0700 | [diff] [blame] | 3288 | if (targetStack != null && targetStack.isActivityTypeAssistant()) { |
Winson Chung | f7e03e1 | 2017-08-22 11:32:16 -0700 | [diff] [blame] | 3289 | // Ensure the task/activity being brought forward is not the assistant |
| 3290 | return false; |
| 3291 | } |
Winson Chung | f7e03e1 | 2017-08-22 11:32:16 -0700 | [diff] [blame] | 3292 | return true; |
| 3293 | } |
| 3294 | |
Jorim Jaggi | 02886a8 | 2016-12-06 09:10:06 -0800 | [diff] [blame] | 3295 | private boolean isTaskSwitch(ActivityRecord r, |
| 3296 | ActivityRecord topFocusedActivity) { |
Wale Ogunwale | 8b19de9 | 2018-11-29 19:58:26 -0800 | [diff] [blame] | 3297 | return topFocusedActivity != null && r.getTaskRecord() != topFocusedActivity.getTaskRecord(); |
Jorim Jaggi | 02886a8 | 2016-12-06 09:10:06 -0800 | [diff] [blame] | 3298 | } |
| 3299 | |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 3300 | /** |
| 3301 | * Perform a reset of the given task, if needed as part of launching it. |
| 3302 | * Returns the new HistoryRecord at the top of the task. |
| 3303 | */ |
Craig Mautner | e3a74d5 | 2013-02-22 14:14:58 -0800 | [diff] [blame] | 3304 | /** |
| 3305 | * Helper method for #resetTaskIfNeededLocked. |
| 3306 | * We are inside of the task being reset... we'll either finish this activity, push it out |
| 3307 | * for another task, or leave it as-is. |
| 3308 | * @param task The task containing the Activity (taskTop) that might be reset. |
| 3309 | * @param forceReset |
| 3310 | * @return An ActivityOptions that needs to be processed. |
| 3311 | */ |
Andrii Kulian | 21713ac | 2016-10-12 22:05:05 -0700 | [diff] [blame] | 3312 | private ActivityOptions resetTargetTaskIfNeededLocked(TaskRecord task, boolean forceReset) { |
Craig Mautner | e3a74d5 | 2013-02-22 14:14:58 -0800 | [diff] [blame] | 3313 | ActivityOptions topOptions = null; |
| 3314 | |
| 3315 | int replyChainEnd = -1; |
| 3316 | boolean canMoveOptions = true; |
| 3317 | |
| 3318 | // We only do this for activities that are not the root of the task (since if we finish |
| 3319 | // the root, we may no longer have the task!). |
| 3320 | final ArrayList<ActivityRecord> activities = task.mActivities; |
| 3321 | final int numActivities = activities.size(); |
Craig Mautner | 9d4e9bc | 2014-06-18 18:34:56 -0700 | [diff] [blame] | 3322 | final int rootActivityNdx = task.findEffectiveRootIndex(); |
| 3323 | for (int i = numActivities - 1; i > rootActivityNdx; --i ) { |
Craig Mautner | e3a74d5 | 2013-02-22 14:14:58 -0800 | [diff] [blame] | 3324 | ActivityRecord target = activities.get(i); |
Craig Mautner | 76ae2f0 | 2014-07-16 16:16:19 +0000 | [diff] [blame] | 3325 | if (target.frontOfTask) |
| 3326 | break; |
Craig Mautner | e3a74d5 | 2013-02-22 14:14:58 -0800 | [diff] [blame] | 3327 | |
| 3328 | final int flags = target.info.flags; |
| 3329 | final boolean finishOnTaskLaunch = |
| 3330 | (flags & ActivityInfo.FLAG_FINISH_ON_TASK_LAUNCH) != 0; |
| 3331 | final boolean allowTaskReparenting = |
| 3332 | (flags & ActivityInfo.FLAG_ALLOW_TASK_REPARENTING) != 0; |
| 3333 | final boolean clearWhenTaskReset = |
| 3334 | (target.intent.getFlags() & Intent.FLAG_ACTIVITY_CLEAR_WHEN_TASK_RESET) != 0; |
| 3335 | |
| 3336 | if (!finishOnTaskLaunch |
| 3337 | && !clearWhenTaskReset |
| 3338 | && target.resultTo != null) { |
| 3339 | // If this activity is sending a reply to a previous |
| 3340 | // activity, we can't do anything with it now until |
| 3341 | // we reach the start of the reply chain. |
| 3342 | // XXX note that we are assuming the result is always |
| 3343 | // to the previous activity, which is almost always |
| 3344 | // the case but we really shouldn't count on. |
| 3345 | if (replyChainEnd < 0) { |
| 3346 | replyChainEnd = i; |
| 3347 | } |
| 3348 | } else if (!finishOnTaskLaunch |
| 3349 | && !clearWhenTaskReset |
| 3350 | && allowTaskReparenting |
| 3351 | && target.taskAffinity != null |
| 3352 | && !target.taskAffinity.equals(task.affinity)) { |
| 3353 | // If this activity has an affinity for another |
| 3354 | // task, then we need to move it out of here. We will |
| 3355 | // move it as far out of the way as possible, to the |
| 3356 | // bottom of the activity stack. This also keeps it |
| 3357 | // correctly ordered with any activities we previously |
| 3358 | // moved. |
Craig Mautner | 329f412 | 2013-11-07 09:10:42 -0800 | [diff] [blame] | 3359 | final TaskRecord targetTask; |
Craig Mautner | dccb770 | 2013-09-17 15:53:34 -0700 | [diff] [blame] | 3360 | final ActivityRecord bottom = |
| 3361 | !mTaskHistory.isEmpty() && !mTaskHistory.get(0).mActivities.isEmpty() ? |
Craig Mautner | 329f412 | 2013-11-07 09:10:42 -0800 | [diff] [blame] | 3362 | mTaskHistory.get(0).mActivities.get(0) : null; |
Craig Mautner | dccb770 | 2013-09-17 15:53:34 -0700 | [diff] [blame] | 3363 | if (bottom != null && target.taskAffinity != null |
Wale Ogunwale | 8b19de9 | 2018-11-29 19:58:26 -0800 | [diff] [blame] | 3364 | && target.taskAffinity.equals(bottom.getTaskRecord().affinity)) { |
Craig Mautner | e3a74d5 | 2013-02-22 14:14:58 -0800 | [diff] [blame] | 3365 | // If the activity currently at the bottom has the |
| 3366 | // same task affinity as the one we are moving, |
| 3367 | // then merge it into the same task. |
Wale Ogunwale | 8b19de9 | 2018-11-29 19:58:26 -0800 | [diff] [blame] | 3368 | targetTask = bottom.getTaskRecord(); |
Wale Ogunwale | ee006da | 2015-03-30 14:49:25 -0700 | [diff] [blame] | 3369 | if (DEBUG_TASKS) Slog.v(TAG_TASKS, "Start pushing activity " + target |
Bryce Lee | af691c0 | 2017-03-20 14:20:22 -0700 | [diff] [blame] | 3370 | + " out to bottom task " + targetTask); |
Craig Mautner | e3a74d5 | 2013-02-22 14:14:58 -0800 | [diff] [blame] | 3371 | } else { |
Suprabh Shukla | 09a88f5 | 2015-12-02 14:36:31 -0800 | [diff] [blame] | 3372 | targetTask = createTaskRecord( |
Wale Ogunwale | 8b19de9 | 2018-11-29 19:58:26 -0800 | [diff] [blame] | 3373 | mStackSupervisor.getNextTaskIdForUserLocked(target.mUserId), |
Wale Ogunwale | 6fbde9f | 2017-08-24 07:24:12 -0700 | [diff] [blame] | 3374 | target.info, null, null, null, false); |
Craig Mautner | 329f412 | 2013-11-07 09:10:42 -0800 | [diff] [blame] | 3375 | targetTask.affinityIntent = target.intent; |
Wale Ogunwale | ee006da | 2015-03-30 14:49:25 -0700 | [diff] [blame] | 3376 | if (DEBUG_TASKS) Slog.v(TAG_TASKS, "Start pushing activity " + target |
Bryce Lee | af691c0 | 2017-03-20 14:20:22 -0700 | [diff] [blame] | 3377 | + " out to new task " + targetTask); |
Craig Mautner | e3a74d5 | 2013-02-22 14:14:58 -0800 | [diff] [blame] | 3378 | } |
| 3379 | |
Craig Mautner | 525f3d9 | 2013-05-07 14:01:50 -0700 | [diff] [blame] | 3380 | boolean noOptions = canMoveOptions; |
Craig Mautner | e3a74d5 | 2013-02-22 14:14:58 -0800 | [diff] [blame] | 3381 | final int start = replyChainEnd < 0 ? i : replyChainEnd; |
| 3382 | for (int srcPos = start; srcPos >= i; --srcPos) { |
Craig Mautner | dccb770 | 2013-09-17 15:53:34 -0700 | [diff] [blame] | 3383 | final ActivityRecord p = activities.get(srcPos); |
Craig Mautner | e3a74d5 | 2013-02-22 14:14:58 -0800 | [diff] [blame] | 3384 | if (p.finishing) { |
| 3385 | continue; |
| 3386 | } |
| 3387 | |
Craig Mautner | e3a74d5 | 2013-02-22 14:14:58 -0800 | [diff] [blame] | 3388 | canMoveOptions = false; |
Craig Mautner | 525f3d9 | 2013-05-07 14:01:50 -0700 | [diff] [blame] | 3389 | if (noOptions && topOptions == null) { |
Craig Mautner | e3a74d5 | 2013-02-22 14:14:58 -0800 | [diff] [blame] | 3390 | topOptions = p.takeOptionsLocked(); |
| 3391 | if (topOptions != null) { |
Craig Mautner | 525f3d9 | 2013-05-07 14:01:50 -0700 | [diff] [blame] | 3392 | noOptions = false; |
Craig Mautner | e3a74d5 | 2013-02-22 14:14:58 -0800 | [diff] [blame] | 3393 | } |
| 3394 | } |
Wale Ogunwale | 0fc365c | 2015-05-25 19:35:42 -0700 | [diff] [blame] | 3395 | if (DEBUG_ADD_REMOVE) Slog.i(TAG_ADD_REMOVE, |
| 3396 | "Removing activity " + p + " from task=" + task + " adding to task=" |
| 3397 | + targetTask + " Callers=" + Debug.getCallers(4)); |
Wale Ogunwale | ee006da | 2015-03-30 14:49:25 -0700 | [diff] [blame] | 3398 | if (DEBUG_TASKS) Slog.v(TAG_TASKS, |
Bryce Lee | af691c0 | 2017-03-20 14:20:22 -0700 | [diff] [blame] | 3399 | "Pushing next activity " + p + " out to target's task " + target); |
Wale Ogunwale | a0cd15e | 2017-02-01 15:33:08 -0800 | [diff] [blame] | 3400 | p.reparent(targetTask, 0 /* position - bottom */, "resetTargetTaskIfNeeded"); |
Craig Mautner | e3a74d5 | 2013-02-22 14:14:58 -0800 | [diff] [blame] | 3401 | } |
| 3402 | |
Riddle Hsu | 86cb7de | 2018-08-13 23:29:58 +0800 | [diff] [blame] | 3403 | positionChildWindowContainerAtBottom(targetTask); |
Craig Mautner | e3a74d5 | 2013-02-22 14:14:58 -0800 | [diff] [blame] | 3404 | replyChainEnd = -1; |
| 3405 | } else if (forceReset || finishOnTaskLaunch || clearWhenTaskReset) { |
| 3406 | // If the activity should just be removed -- either |
| 3407 | // because it asks for it, or the task should be |
| 3408 | // cleared -- then finish it and anything that is |
| 3409 | // part of its reply chain. |
| 3410 | int end; |
| 3411 | if (clearWhenTaskReset) { |
| 3412 | // In this case, we want to finish this activity |
| 3413 | // and everything above it, so be sneaky and pretend |
| 3414 | // like these are all in the reply chain. |
Mark Lu | 4b5a9a0 | 2014-12-09 14:47:13 +0800 | [diff] [blame] | 3415 | end = activities.size() - 1; |
Craig Mautner | e3a74d5 | 2013-02-22 14:14:58 -0800 | [diff] [blame] | 3416 | } else if (replyChainEnd < 0) { |
| 3417 | end = i; |
| 3418 | } else { |
| 3419 | end = replyChainEnd; |
| 3420 | } |
Craig Mautner | 525f3d9 | 2013-05-07 14:01:50 -0700 | [diff] [blame] | 3421 | boolean noOptions = canMoveOptions; |
Craig Mautner | e3a74d5 | 2013-02-22 14:14:58 -0800 | [diff] [blame] | 3422 | for (int srcPos = i; srcPos <= end; srcPos++) { |
Craig Mautner | 525f3d9 | 2013-05-07 14:01:50 -0700 | [diff] [blame] | 3423 | ActivityRecord p = activities.get(srcPos); |
Craig Mautner | e3a74d5 | 2013-02-22 14:14:58 -0800 | [diff] [blame] | 3424 | if (p.finishing) { |
| 3425 | continue; |
| 3426 | } |
| 3427 | canMoveOptions = false; |
Craig Mautner | 525f3d9 | 2013-05-07 14:01:50 -0700 | [diff] [blame] | 3428 | if (noOptions && topOptions == null) { |
Craig Mautner | e3a74d5 | 2013-02-22 14:14:58 -0800 | [diff] [blame] | 3429 | topOptions = p.takeOptionsLocked(); |
| 3430 | if (topOptions != null) { |
Craig Mautner | 525f3d9 | 2013-05-07 14:01:50 -0700 | [diff] [blame] | 3431 | noOptions = false; |
Craig Mautner | e3a74d5 | 2013-02-22 14:14:58 -0800 | [diff] [blame] | 3432 | } |
| 3433 | } |
Wale Ogunwale | ee006da | 2015-03-30 14:49:25 -0700 | [diff] [blame] | 3434 | if (DEBUG_TASKS) Slog.w(TAG_TASKS, |
Craig Mautner | 5854780 | 2013-03-05 08:23:53 -0800 | [diff] [blame] | 3435 | "resetTaskIntendedTask: calling finishActivity on " + p); |
Todd Kennedy | 539db51 | 2014-12-15 09:57:55 -0800 | [diff] [blame] | 3436 | if (finishActivityLocked( |
| 3437 | p, Activity.RESULT_CANCELED, null, "reset-task", false)) { |
Craig Mautner | e3a74d5 | 2013-02-22 14:14:58 -0800 | [diff] [blame] | 3438 | end--; |
| 3439 | srcPos--; |
| 3440 | } |
| 3441 | } |
| 3442 | replyChainEnd = -1; |
| 3443 | } else { |
| 3444 | // If we were in the middle of a chain, well the |
| 3445 | // activity that started it all doesn't want anything |
| 3446 | // special, so leave it all as-is. |
| 3447 | replyChainEnd = -1; |
| 3448 | } |
| 3449 | } |
| 3450 | |
| 3451 | return topOptions; |
| 3452 | } |
| 3453 | |
| 3454 | /** |
| 3455 | * Helper method for #resetTaskIfNeededLocked. Processes all of the activities in a given |
| 3456 | * TaskRecord looking for an affinity with the task of resetTaskIfNeededLocked.taskTop. |
| 3457 | * @param affinityTask The task we are looking for an affinity to. |
| 3458 | * @param task Task that resetTaskIfNeededLocked.taskTop belongs to. |
| 3459 | * @param topTaskIsHigher True if #task has already been processed by resetTaskIfNeededLocked. |
| 3460 | * @param forceReset Flag passed in to resetTaskIfNeededLocked. |
| 3461 | */ |
Craig Mautner | 525f3d9 | 2013-05-07 14:01:50 -0700 | [diff] [blame] | 3462 | private int resetAffinityTaskIfNeededLocked(TaskRecord affinityTask, TaskRecord task, |
Craig Mautner | 7787877 | 2013-03-04 19:46:24 -0800 | [diff] [blame] | 3463 | boolean topTaskIsHigher, boolean forceReset, int taskInsertionPoint) { |
Craig Mautner | e3a74d5 | 2013-02-22 14:14:58 -0800 | [diff] [blame] | 3464 | int replyChainEnd = -1; |
| 3465 | final int taskId = task.taskId; |
| 3466 | final String taskAffinity = task.affinity; |
| 3467 | |
| 3468 | final ArrayList<ActivityRecord> activities = affinityTask.mActivities; |
| 3469 | final int numActivities = activities.size(); |
Craig Mautner | 9d4e9bc | 2014-06-18 18:34:56 -0700 | [diff] [blame] | 3470 | final int rootActivityNdx = affinityTask.findEffectiveRootIndex(); |
| 3471 | |
| 3472 | // Do not operate on or below the effective root Activity. |
| 3473 | for (int i = numActivities - 1; i > rootActivityNdx; --i) { |
Craig Mautner | e3a74d5 | 2013-02-22 14:14:58 -0800 | [diff] [blame] | 3474 | ActivityRecord target = activities.get(i); |
Craig Mautner | 76ae2f0 | 2014-07-16 16:16:19 +0000 | [diff] [blame] | 3475 | if (target.frontOfTask) |
| 3476 | break; |
Craig Mautner | e3a74d5 | 2013-02-22 14:14:58 -0800 | [diff] [blame] | 3477 | |
| 3478 | final int flags = target.info.flags; |
| 3479 | boolean finishOnTaskLaunch = (flags & ActivityInfo.FLAG_FINISH_ON_TASK_LAUNCH) != 0; |
| 3480 | boolean allowTaskReparenting = (flags & ActivityInfo.FLAG_ALLOW_TASK_REPARENTING) != 0; |
| 3481 | |
| 3482 | if (target.resultTo != null) { |
| 3483 | // If this activity is sending a reply to a previous |
| 3484 | // activity, we can't do anything with it now until |
| 3485 | // we reach the start of the reply chain. |
| 3486 | // XXX note that we are assuming the result is always |
| 3487 | // to the previous activity, which is almost always |
| 3488 | // the case but we really shouldn't count on. |
| 3489 | if (replyChainEnd < 0) { |
| 3490 | replyChainEnd = i; |
| 3491 | } |
| 3492 | } else if (topTaskIsHigher |
| 3493 | && allowTaskReparenting |
| 3494 | && taskAffinity != null |
| 3495 | && taskAffinity.equals(target.taskAffinity)) { |
| 3496 | // This activity has an affinity for our task. Either remove it if we are |
| 3497 | // clearing or move it over to our task. Note that |
| 3498 | // we currently punt on the case where we are resetting a |
| 3499 | // task that is not at the top but who has activities above |
| 3500 | // with an affinity to it... this is really not a normal |
| 3501 | // case, and we will need to later pull that task to the front |
| 3502 | // and usually at that point we will do the reset and pick |
| 3503 | // up those remaining activities. (This only happens if |
| 3504 | // someone starts an activity in a new task from an activity |
| 3505 | // in a task that is not currently on top.) |
| 3506 | if (forceReset || finishOnTaskLaunch) { |
| 3507 | final int start = replyChainEnd >= 0 ? replyChainEnd : i; |
Wale Ogunwale | ee006da | 2015-03-30 14:49:25 -0700 | [diff] [blame] | 3508 | if (DEBUG_TASKS) Slog.v(TAG_TASKS, |
| 3509 | "Finishing task at index " + start + " to " + i); |
Craig Mautner | e3a74d5 | 2013-02-22 14:14:58 -0800 | [diff] [blame] | 3510 | for (int srcPos = start; srcPos >= i; --srcPos) { |
| 3511 | final ActivityRecord p = activities.get(srcPos); |
| 3512 | if (p.finishing) { |
| 3513 | continue; |
| 3514 | } |
Todd Kennedy | 539db51 | 2014-12-15 09:57:55 -0800 | [diff] [blame] | 3515 | finishActivityLocked( |
| 3516 | p, Activity.RESULT_CANCELED, null, "move-affinity", false); |
Craig Mautner | e3a74d5 | 2013-02-22 14:14:58 -0800 | [diff] [blame] | 3517 | } |
| 3518 | } else { |
Craig Mautner | 7787877 | 2013-03-04 19:46:24 -0800 | [diff] [blame] | 3519 | if (taskInsertionPoint < 0) { |
| 3520 | taskInsertionPoint = task.mActivities.size(); |
Craig Mautner | d232895 | 2013-03-05 12:46:26 -0800 | [diff] [blame] | 3521 | |
Craig Mautner | 7787877 | 2013-03-04 19:46:24 -0800 | [diff] [blame] | 3522 | } |
Craig Mautner | 7787877 | 2013-03-04 19:46:24 -0800 | [diff] [blame] | 3523 | |
| 3524 | final int start = replyChainEnd >= 0 ? replyChainEnd : i; |
Wale Ogunwale | ee006da | 2015-03-30 14:49:25 -0700 | [diff] [blame] | 3525 | if (DEBUG_TASKS) Slog.v(TAG_TASKS, |
| 3526 | "Reparenting from task=" + affinityTask + ":" + start + "-" + i |
| 3527 | + " to task=" + task + ":" + taskInsertionPoint); |
Craig Mautner | 7787877 | 2013-03-04 19:46:24 -0800 | [diff] [blame] | 3528 | for (int srcPos = start; srcPos >= i; --srcPos) { |
Craig Mautner | e3a74d5 | 2013-02-22 14:14:58 -0800 | [diff] [blame] | 3529 | final ActivityRecord p = activities.get(srcPos); |
Winson Chung | 3048004 | 2017-01-26 10:55:34 -0800 | [diff] [blame] | 3530 | p.reparent(task, taskInsertionPoint, "resetAffinityTaskIfNeededLocked"); |
Craig Mautner | e3a74d5 | 2013-02-22 14:14:58 -0800 | [diff] [blame] | 3531 | |
Wale Ogunwale | 0fc365c | 2015-05-25 19:35:42 -0700 | [diff] [blame] | 3532 | if (DEBUG_ADD_REMOVE) Slog.i(TAG_ADD_REMOVE, |
| 3533 | "Removing and adding activity " + p + " to stack at " + task |
| 3534 | + " callers=" + Debug.getCallers(3)); |
Wale Ogunwale | ee006da | 2015-03-30 14:49:25 -0700 | [diff] [blame] | 3535 | if (DEBUG_TASKS) Slog.v(TAG_TASKS, "Pulling activity " + p |
| 3536 | + " from " + srcPos + " in to resetting task " + task); |
Craig Mautner | e3a74d5 | 2013-02-22 14:14:58 -0800 | [diff] [blame] | 3537 | } |
Riddle Hsu | 86cb7de | 2018-08-13 23:29:58 +0800 | [diff] [blame] | 3538 | positionChildWindowContainerAtTop(task); |
Craig Mautner | e3a74d5 | 2013-02-22 14:14:58 -0800 | [diff] [blame] | 3539 | |
| 3540 | // Now we've moved it in to place... but what if this is |
| 3541 | // a singleTop activity and we have put it on top of another |
| 3542 | // instance of the same activity? Then we drop the instance |
| 3543 | // below so it remains singleTop. |
| 3544 | if (target.info.launchMode == ActivityInfo.LAUNCH_SINGLE_TOP) { |
| 3545 | ArrayList<ActivityRecord> taskActivities = task.mActivities; |
Craig Mautner | e3a74d5 | 2013-02-22 14:14:58 -0800 | [diff] [blame] | 3546 | int targetNdx = taskActivities.indexOf(target); |
| 3547 | if (targetNdx > 0) { |
| 3548 | ActivityRecord p = taskActivities.get(targetNdx - 1); |
| 3549 | if (p.intent.getComponent().equals(target.intent.getComponent())) { |
Craig Mautner | 5854780 | 2013-03-05 08:23:53 -0800 | [diff] [blame] | 3550 | finishActivityLocked(p, Activity.RESULT_CANCELED, null, "replace", |
| 3551 | false); |
Craig Mautner | e3a74d5 | 2013-02-22 14:14:58 -0800 | [diff] [blame] | 3552 | } |
| 3553 | } |
| 3554 | } |
| 3555 | } |
| 3556 | |
| 3557 | replyChainEnd = -1; |
| 3558 | } |
| 3559 | } |
Craig Mautner | 7787877 | 2013-03-04 19:46:24 -0800 | [diff] [blame] | 3560 | return taskInsertionPoint; |
Craig Mautner | e3a74d5 | 2013-02-22 14:14:58 -0800 | [diff] [blame] | 3561 | } |
| 3562 | |
Craig Mautner | 8849a5e | 2013-04-02 16:41:03 -0700 | [diff] [blame] | 3563 | final ActivityRecord resetTaskIfNeededLocked(ActivityRecord taskTop, |
Craig Mautner | e3a74d5 | 2013-02-22 14:14:58 -0800 | [diff] [blame] | 3564 | ActivityRecord newActivity) { |
Winson Chung | 5fa3975 | 2017-10-04 14:50:15 -0700 | [diff] [blame] | 3565 | final boolean forceReset = |
Craig Mautner | e3a74d5 | 2013-02-22 14:14:58 -0800 | [diff] [blame] | 3566 | (newActivity.info.flags & ActivityInfo.FLAG_CLEAR_TASK_ON_LAUNCH) != 0; |
Wale Ogunwale | 8b19de9 | 2018-11-29 19:58:26 -0800 | [diff] [blame] | 3567 | final TaskRecord task = taskTop.getTaskRecord(); |
Craig Mautner | e3a74d5 | 2013-02-22 14:14:58 -0800 | [diff] [blame] | 3568 | |
| 3569 | /** False until we evaluate the TaskRecord associated with taskTop. Switches to true |
| 3570 | * for remaining tasks. Used for later tasks to reparent to task. */ |
| 3571 | boolean taskFound = false; |
| 3572 | |
| 3573 | /** If ActivityOptions are moved out and need to be aborted or moved to taskTop. */ |
| 3574 | ActivityOptions topOptions = null; |
| 3575 | |
Craig Mautner | 7787877 | 2013-03-04 19:46:24 -0800 | [diff] [blame] | 3576 | // Preserve the location for reparenting in the new task. |
| 3577 | int reparentInsertionPoint = -1; |
| 3578 | |
Craig Mautner | e3a74d5 | 2013-02-22 14:14:58 -0800 | [diff] [blame] | 3579 | for (int i = mTaskHistory.size() - 1; i >= 0; --i) { |
| 3580 | final TaskRecord targetTask = mTaskHistory.get(i); |
| 3581 | |
| 3582 | if (targetTask == task) { |
| 3583 | topOptions = resetTargetTaskIfNeededLocked(task, forceReset); |
| 3584 | taskFound = true; |
| 3585 | } else { |
Craig Mautner | 7787877 | 2013-03-04 19:46:24 -0800 | [diff] [blame] | 3586 | reparentInsertionPoint = resetAffinityTaskIfNeededLocked(targetTask, task, |
| 3587 | taskFound, forceReset, reparentInsertionPoint); |
Craig Mautner | e3a74d5 | 2013-02-22 14:14:58 -0800 | [diff] [blame] | 3588 | } |
| 3589 | } |
| 3590 | |
Craig Mautner | 70a8693 | 2013-02-28 22:37:44 -0800 | [diff] [blame] | 3591 | int taskNdx = mTaskHistory.indexOf(task); |
riddle_hsu | 1d7919a | 2015-03-11 17:09:50 +0800 | [diff] [blame] | 3592 | if (taskNdx >= 0) { |
| 3593 | do { |
| 3594 | taskTop = mTaskHistory.get(taskNdx--).getTopActivity(); |
| 3595 | } while (taskTop == null && taskNdx >= 0); |
| 3596 | } |
Craig Mautner | 70a8693 | 2013-02-28 22:37:44 -0800 | [diff] [blame] | 3597 | |
Craig Mautner | e3a74d5 | 2013-02-22 14:14:58 -0800 | [diff] [blame] | 3598 | if (topOptions != null) { |
| 3599 | // If we got some ActivityOptions from an activity on top that |
| 3600 | // was removed from the task, propagate them to the new real top. |
| 3601 | if (taskTop != null) { |
Craig Mautner | e3a74d5 | 2013-02-22 14:14:58 -0800 | [diff] [blame] | 3602 | taskTop.updateOptionsLocked(topOptions); |
| 3603 | } else { |
Craig Mautner | e3a74d5 | 2013-02-22 14:14:58 -0800 | [diff] [blame] | 3604 | topOptions.abort(); |
| 3605 | } |
| 3606 | } |
| 3607 | |
| 3608 | return taskTop; |
| 3609 | } |
| 3610 | |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 3611 | void sendActivityResultLocked(int callingUid, ActivityRecord r, |
| 3612 | String resultWho, int requestCode, int resultCode, Intent data) { |
| 3613 | |
| 3614 | if (callingUid > 0) { |
Wale Ogunwale | 6d50dcc | 2018-07-21 23:00:40 -0700 | [diff] [blame] | 3615 | mService.mUgmInternal.grantUriPermissionFromIntent(callingUid, r.packageName, |
Wale Ogunwale | 8b19de9 | 2018-11-29 19:58:26 -0800 | [diff] [blame] | 3616 | data, r.getUriPermissionsLocked(), r.mUserId); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 3617 | } |
| 3618 | |
| 3619 | if (DEBUG_RESULTS) Slog.v(TAG, "Send activity result to " + r |
| 3620 | + " : who=" + resultWho + " req=" + requestCode |
| 3621 | + " res=" + resultCode + " data=" + data); |
Wale Ogunwale | 9e4f3e0 | 2018-05-17 09:35:39 -0700 | [diff] [blame] | 3622 | if (mResumedActivity == r && r.attachedToProcess()) { |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 3623 | try { |
| 3624 | ArrayList<ResultInfo> list = new ArrayList<ResultInfo>(); |
| 3625 | list.add(new ResultInfo(resultWho, requestCode, |
| 3626 | resultCode, data)); |
Wale Ogunwale | 9e4f3e0 | 2018-05-17 09:35:39 -0700 | [diff] [blame] | 3627 | mService.getLifecycleManager().scheduleTransaction(r.app.getThread(), r.appToken, |
Andrii Kulian | 9c5ea9c | 2017-12-07 09:31:01 -0800 | [diff] [blame] | 3628 | ActivityResultItem.obtain(list)); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 3629 | return; |
| 3630 | } catch (Exception e) { |
| 3631 | Slog.w(TAG, "Exception thrown sending result to " + r, e); |
| 3632 | } |
| 3633 | } |
| 3634 | |
| 3635 | r.addResultLocked(null, resultWho, requestCode, resultCode, data); |
| 3636 | } |
| 3637 | |
Shunta Sato | 63b8ee3 | 2016-07-11 13:32:52 +0900 | [diff] [blame] | 3638 | /** Returns true if the task is one of the task finishing on-top of the top running task. */ |
Wale Ogunwale | 66e1685 | 2017-10-19 13:35:52 -0700 | [diff] [blame] | 3639 | private boolean isATopFinishingTask(TaskRecord task) { |
Shunta Sato | 63b8ee3 | 2016-07-11 13:32:52 +0900 | [diff] [blame] | 3640 | for (int i = mTaskHistory.size() - 1; i >= 0; --i) { |
| 3641 | final TaskRecord current = mTaskHistory.get(i); |
| 3642 | final ActivityRecord r = current.topRunningActivityLocked(); |
| 3643 | if (r != null) { |
| 3644 | // We got a top running activity, so there isn't a top finishing task... |
| 3645 | return false; |
| 3646 | } |
| 3647 | if (current == task) { |
| 3648 | return true; |
| 3649 | } |
| 3650 | } |
| 3651 | return false; |
| 3652 | } |
| 3653 | |
Wale Ogunwale | 66e1685 | 2017-10-19 13:35:52 -0700 | [diff] [blame] | 3654 | private void adjustFocusedActivityStack(ActivityRecord r, String reason) { |
Wale Ogunwale | d32da47 | 2018-11-16 07:19:28 -0800 | [diff] [blame] | 3655 | if (!mRootActivityContainer.isTopDisplayFocusedStack(this) || |
Shunta Sato | 63b8ee3 | 2016-07-11 13:32:52 +0900 | [diff] [blame] | 3656 | ((mResumedActivity != r) && (mResumedActivity != null))) { |
Wale Ogunwale | d045c82 | 2015-12-02 09:14:28 -0800 | [diff] [blame] | 3657 | return; |
| 3658 | } |
| 3659 | |
| 3660 | final ActivityRecord next = topRunningActivityLocked(); |
| 3661 | final String myReason = reason + " adjustFocus"; |
Bryce Lee | 3345c4e | 2017-04-25 07:40:41 -0700 | [diff] [blame] | 3662 | |
Wale Ogunwale | 66e1685 | 2017-10-19 13:35:52 -0700 | [diff] [blame] | 3663 | if (next == r) { |
Wale Ogunwale | d32da47 | 2018-11-16 07:19:28 -0800 | [diff] [blame] | 3664 | final ActivityRecord top = mRootActivityContainer.topRunningActivity(); |
Louis Chang | 1944345 | 2018-10-09 12:10:21 +0800 | [diff] [blame] | 3665 | if (top != null) { |
| 3666 | top.moveFocusableActivityToTop(myReason); |
| 3667 | } |
Wale Ogunwale | 66e1685 | 2017-10-19 13:35:52 -0700 | [diff] [blame] | 3668 | return; |
Wale Ogunwale | d045c82 | 2015-12-02 09:14:28 -0800 | [diff] [blame] | 3669 | } |
Wale Ogunwale | d697cea | 2015-02-20 17:19:49 -0800 | [diff] [blame] | 3670 | |
Wale Ogunwale | 66e1685 | 2017-10-19 13:35:52 -0700 | [diff] [blame] | 3671 | if (next != null && isFocusable()) { |
| 3672 | // Keep focus in stack if we have a top running activity and are focusable. |
| 3673 | return; |
| 3674 | } |
| 3675 | |
| 3676 | // Task is not guaranteed to be non-null. For example, destroying the |
| 3677 | // {@link ActivityRecord} will disassociate the task from the activity. |
Wale Ogunwale | 8b19de9 | 2018-11-29 19:58:26 -0800 | [diff] [blame] | 3678 | final TaskRecord task = r.getTaskRecord(); |
Wale Ogunwale | 66e1685 | 2017-10-19 13:35:52 -0700 | [diff] [blame] | 3679 | |
| 3680 | if (task == null) { |
| 3681 | throw new IllegalStateException("activity no longer associated with task:" + r); |
| 3682 | } |
| 3683 | |
| 3684 | // Move focus to next focusable stack if possible. |
Riddle Hsu | 3026e8d | 2018-08-03 15:50:53 +0800 | [diff] [blame] | 3685 | final ActivityStack nextFocusableStack = adjustFocusToNextFocusableStack(myReason); |
| 3686 | if (nextFocusableStack != null) { |
| 3687 | final ActivityRecord top = nextFocusableStack.topRunningActivityLocked(); |
Wale Ogunwale | d32da47 | 2018-11-16 07:19:28 -0800 | [diff] [blame] | 3688 | if (top != null && top == mRootActivityContainer.getTopResumedActivity()) { |
Riddle Hsu | 3026e8d | 2018-08-03 15:50:53 +0800 | [diff] [blame] | 3689 | // TODO(b/111361570): Remove this and update focused app per-display in |
| 3690 | // WindowManager every time an activity becomes resumed in |
| 3691 | // ActivityTaskManagerService#setResumedActivityUncheckLocked(). |
| 3692 | mService.setResumedActivityUncheckLocked(top, reason); |
| 3693 | } |
Wale Ogunwale | 66e1685 | 2017-10-19 13:35:52 -0700 | [diff] [blame] | 3694 | return; |
| 3695 | } |
| 3696 | |
| 3697 | // Whatever...go home. |
Louis Chang | bd48dca | 2018-08-29 17:44:34 +0800 | [diff] [blame] | 3698 | getDisplay().moveHomeActivityToTop(myReason); |
Craig Mautner | 04f0b70 | 2013-10-22 12:31:01 -0700 | [diff] [blame] | 3699 | } |
| 3700 | |
Andrii Kulian | ab132ee | 2018-07-24 22:10:21 +0800 | [diff] [blame] | 3701 | /** |
| 3702 | * Find next proper focusable stack and make it focused. |
| 3703 | * @return The stack that now got the focus, {@code null} if none found. |
| 3704 | */ |
| 3705 | ActivityStack adjustFocusToNextFocusableStack(String reason) { |
Wale Ogunwale | 66e1685 | 2017-10-19 13:35:52 -0700 | [diff] [blame] | 3706 | return adjustFocusToNextFocusableStack(reason, false /* allowFocusSelf */); |
Andrii Kulian | 250d653 | 2017-02-08 23:30:45 -0800 | [diff] [blame] | 3707 | } |
| 3708 | |
| 3709 | /** |
| 3710 | * Find next proper focusable stack and make it focused. |
| 3711 | * @param allowFocusSelf Is the focus allowed to remain on the same stack. |
Andrii Kulian | ab132ee | 2018-07-24 22:10:21 +0800 | [diff] [blame] | 3712 | * @return The stack that now got the focus, {@code null} if none found. |
Andrii Kulian | 250d653 | 2017-02-08 23:30:45 -0800 | [diff] [blame] | 3713 | */ |
Andrii Kulian | ab132ee | 2018-07-24 22:10:21 +0800 | [diff] [blame] | 3714 | private ActivityStack adjustFocusToNextFocusableStack(String reason, boolean allowFocusSelf) { |
Wale Ogunwale | e1f68ce | 2018-03-09 08:58:54 -0800 | [diff] [blame] | 3715 | final ActivityStack stack = |
Wale Ogunwale | d32da47 | 2018-11-16 07:19:28 -0800 | [diff] [blame] | 3716 | mRootActivityContainer.getNextFocusableStack(this, !allowFocusSelf); |
Wale Ogunwale | 4cea0f5 | 2015-12-25 06:30:31 -0800 | [diff] [blame] | 3717 | final String myReason = reason + " adjustFocusToNextFocusableStack"; |
Wale Ogunwale | d697cea | 2015-02-20 17:19:49 -0800 | [diff] [blame] | 3718 | if (stack == null) { |
Andrii Kulian | ab132ee | 2018-07-24 22:10:21 +0800 | [diff] [blame] | 3719 | return null; |
Wale Ogunwale | d697cea | 2015-02-20 17:19:49 -0800 | [diff] [blame] | 3720 | } |
Wale Ogunwale | d34e80c | 2016-03-23 17:08:44 -0700 | [diff] [blame] | 3721 | |
Wale Ogunwale | c750f5f | 2016-03-28 07:43:51 -0700 | [diff] [blame] | 3722 | final ActivityRecord top = stack.topRunningActivityLocked(); |
| 3723 | |
Wale Ogunwale | 66e1685 | 2017-10-19 13:35:52 -0700 | [diff] [blame] | 3724 | if (stack.isActivityTypeHome() && (top == null || !top.visible)) { |
Wale Ogunwale | c750f5f | 2016-03-28 07:43:51 -0700 | [diff] [blame] | 3725 | // If we will be focusing on the home stack next and its current top activity isn't |
Wale Ogunwale | 66e1685 | 2017-10-19 13:35:52 -0700 | [diff] [blame] | 3726 | // visible, then use the move the home stack task to top to make the activity visible. |
Louis Chang | bd48dca | 2018-08-29 17:44:34 +0800 | [diff] [blame] | 3727 | stack.getDisplay().moveHomeActivityToTop(reason); |
Andrii Kulian | ab132ee | 2018-07-24 22:10:21 +0800 | [diff] [blame] | 3728 | return stack; |
Wale Ogunwale | d34e80c | 2016-03-23 17:08:44 -0700 | [diff] [blame] | 3729 | } |
Chong Zhang | 6cda19c | 2016-06-14 19:07:56 -0700 | [diff] [blame] | 3730 | |
| 3731 | stack.moveToFront(myReason); |
Andrii Kulian | ab132ee | 2018-07-24 22:10:21 +0800 | [diff] [blame] | 3732 | return stack; |
Wale Ogunwale | d697cea | 2015-02-20 17:19:49 -0800 | [diff] [blame] | 3733 | } |
| 3734 | |
Craig Mautner | f333327 | 2013-04-22 10:55:53 -0700 | [diff] [blame] | 3735 | final void stopActivityLocked(ActivityRecord r) { |
Wale Ogunwale | ee006da | 2015-03-30 14:49:25 -0700 | [diff] [blame] | 3736 | if (DEBUG_SWITCH) Slog.d(TAG_SWITCH, "Stopping: " + r); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 3737 | if ((r.intent.getFlags()&Intent.FLAG_ACTIVITY_NO_HISTORY) != 0 |
| 3738 | || (r.info.flags&ActivityInfo.FLAG_NO_HISTORY) != 0) { |
| 3739 | if (!r.finishing) { |
David Stevens | 9440dc8 | 2017-03-16 19:00:20 -0700 | [diff] [blame] | 3740 | if (!shouldSleepActivities()) { |
Wale Ogunwale | 0fc365c | 2015-05-25 19:35:42 -0700 | [diff] [blame] | 3741 | if (DEBUG_STATES) Slog.d(TAG_STATES, "no-history finish of " + r); |
Wale Ogunwale | 3f529ee | 2015-07-12 15:14:01 -0700 | [diff] [blame] | 3742 | if (requestFinishActivityLocked(r.appToken, Activity.RESULT_CANCELED, null, |
| 3743 | "stop-no-history", false)) { |
Bryce Lee | 3345c4e | 2017-04-25 07:40:41 -0700 | [diff] [blame] | 3744 | // If {@link requestFinishActivityLocked} returns {@code true}, |
Wale Ogunwale | 66e1685 | 2017-10-19 13:35:52 -0700 | [diff] [blame] | 3745 | // {@link adjustFocusedActivityStack} would have been already called. |
Wale Ogunwale | 3f529ee | 2015-07-12 15:14:01 -0700 | [diff] [blame] | 3746 | r.resumeKeyDispatchingLocked(); |
| 3747 | return; |
| 3748 | } |
Christopher Tate | d3f175c | 2012-06-14 14:16:54 -0700 | [diff] [blame] | 3749 | } else { |
Wale Ogunwale | 0fc365c | 2015-05-25 19:35:42 -0700 | [diff] [blame] | 3750 | if (DEBUG_STATES) Slog.d(TAG_STATES, "Not finishing noHistory " + r |
Christopher Tate | d3f175c | 2012-06-14 14:16:54 -0700 | [diff] [blame] | 3751 | + " on stop because we're just sleeping"); |
| 3752 | } |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 3753 | } |
Christopher Tate | 5007ddd | 2012-06-12 13:08:18 -0700 | [diff] [blame] | 3754 | } |
| 3755 | |
Wale Ogunwale | 9e4f3e0 | 2018-05-17 09:35:39 -0700 | [diff] [blame] | 3756 | if (r.attachedToProcess()) { |
Wale Ogunwale | 66e1685 | 2017-10-19 13:35:52 -0700 | [diff] [blame] | 3757 | adjustFocusedActivityStack(r, "stopActivity"); |
Dianne Hackborn | 621e2fe | 2012-02-16 17:07:33 -0800 | [diff] [blame] | 3758 | r.resumeKeyDispatchingLocked(); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 3759 | try { |
| 3760 | r.stopped = false; |
Wale Ogunwale | 0fc365c | 2015-05-25 19:35:42 -0700 | [diff] [blame] | 3761 | if (DEBUG_STATES) Slog.v(TAG_STATES, |
| 3762 | "Moving to STOPPING: " + r + " (stop requested)"); |
Bryce Lee | 7ace395 | 2018-02-16 14:34:32 -0800 | [diff] [blame] | 3763 | r.setState(STOPPING, "stopActivityLocked"); |
Wale Ogunwale | ee006da | 2015-03-30 14:49:25 -0700 | [diff] [blame] | 3764 | if (DEBUG_VISIBILITY) Slog.v(TAG_VISIBILITY, |
| 3765 | "Stopping visible=" + r.visible + " for " + r); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 3766 | if (!r.visible) { |
Wale Ogunwale | b9a0c99 | 2017-04-18 07:25:20 -0700 | [diff] [blame] | 3767 | r.setVisible(false); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 3768 | } |
Wale Ogunwale | cd7043e | 2016-02-27 17:37:46 -0800 | [diff] [blame] | 3769 | EventLogTags.writeAmStopActivity( |
Wale Ogunwale | 8b19de9 | 2018-11-29 19:58:26 -0800 | [diff] [blame] | 3770 | r.mUserId, System.identityHashCode(r), r.shortComponentName); |
Wale Ogunwale | 9e4f3e0 | 2018-05-17 09:35:39 -0700 | [diff] [blame] | 3771 | mService.getLifecycleManager().scheduleTransaction(r.app.getThread(), r.appToken, |
Bryce Lee | 1d0d514 | 2018-04-12 10:35:07 -0700 | [diff] [blame] | 3772 | StopActivityItem.obtain(r.visible, r.configChangeFlags)); |
David Stevens | 9440dc8 | 2017-03-16 19:00:20 -0700 | [diff] [blame] | 3773 | if (shouldSleepOrShutDownActivities()) { |
Dianne Hackborn | 4eba96b | 2011-01-21 13:34:36 -0800 | [diff] [blame] | 3774 | r.setSleeping(true); |
| 3775 | } |
Craig Mautner | f7bfefb | 2013-05-16 17:30:44 -0700 | [diff] [blame] | 3776 | Message msg = mHandler.obtainMessage(STOP_TIMEOUT_MSG, r); |
Dianne Hackborn | 162bc0e | 2012-04-09 14:06:16 -0700 | [diff] [blame] | 3777 | mHandler.sendMessageDelayed(msg, STOP_TIMEOUT); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 3778 | } catch (Exception e) { |
| 3779 | // Maybe just ignore exceptions here... if the process |
| 3780 | // has crashed, our death notification will clean things |
| 3781 | // up. |
| 3782 | Slog.w(TAG, "Exception thrown during pause", e); |
| 3783 | // Just in case, assume it to be stopped. |
| 3784 | r.stopped = true; |
Wale Ogunwale | 0fc365c | 2015-05-25 19:35:42 -0700 | [diff] [blame] | 3785 | if (DEBUG_STATES) Slog.v(TAG_STATES, "Stop failed; moving to STOPPED: " + r); |
Bryce Lee | 7ace395 | 2018-02-16 14:34:32 -0800 | [diff] [blame] | 3786 | r.setState(STOPPED, "stopActivityLocked"); |
Wale Ogunwale | f81c1d1 | 2016-01-12 12:20:18 -0800 | [diff] [blame] | 3787 | if (r.deferRelaunchUntilPaused) { |
Craig Mautner | ee2e45a | 2014-06-27 12:10:03 -0700 | [diff] [blame] | 3788 | destroyActivityLocked(r, true, "stop-except"); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 3789 | } |
| 3790 | } |
| 3791 | } |
| 3792 | } |
Craig Mautner | 23ac33b | 2013-04-01 16:26:35 -0700 | [diff] [blame] | 3793 | |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 3794 | /** |
| 3795 | * @return Returns true if the activity is being finished, false if for |
| 3796 | * some reason it is being left as-is. |
| 3797 | */ |
| 3798 | final boolean requestFinishActivityLocked(IBinder token, int resultCode, |
Dianne Hackborn | 2d1b378 | 2012-09-09 17:49:39 -0700 | [diff] [blame] | 3799 | Intent resultData, String reason, boolean oomAdj) { |
Craig Mautner | d74f7d7 | 2013-02-26 13:41:02 -0800 | [diff] [blame] | 3800 | ActivityRecord r = isInStackLocked(token); |
Wale Ogunwale | 0fc365c | 2015-05-25 19:35:42 -0700 | [diff] [blame] | 3801 | if (DEBUG_RESULTS || DEBUG_STATES) Slog.v(TAG_STATES, |
| 3802 | "Finishing activity token=" + token + " r=" |
Christopher Tate | d3f175c | 2012-06-14 14:16:54 -0700 | [diff] [blame] | 3803 | + ", result=" + resultCode + ", data=" + resultData |
| 3804 | + ", reason=" + reason); |
Craig Mautner | d74f7d7 | 2013-02-26 13:41:02 -0800 | [diff] [blame] | 3805 | if (r == null) { |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 3806 | return false; |
| 3807 | } |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 3808 | |
Craig Mautner | d44711d | 2013-02-23 11:24:36 -0800 | [diff] [blame] | 3809 | finishActivityLocked(r, resultCode, resultData, reason, oomAdj); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 3810 | return true; |
| 3811 | } |
| 3812 | |
Craig Mautner | d232895 | 2013-03-05 12:46:26 -0800 | [diff] [blame] | 3813 | final void finishSubActivityLocked(ActivityRecord self, String resultWho, int requestCode) { |
Craig Mautner | 9658b31 | 2013-02-28 10:55:59 -0800 | [diff] [blame] | 3814 | for (int taskNdx = mTaskHistory.size() - 1; taskNdx >= 0; --taskNdx) { |
| 3815 | ArrayList<ActivityRecord> activities = mTaskHistory.get(taskNdx).mActivities; |
| 3816 | for (int activityNdx = activities.size() - 1; activityNdx >= 0; --activityNdx) { |
| 3817 | ActivityRecord r = activities.get(activityNdx); |
| 3818 | if (r.resultTo == self && r.requestCode == requestCode) { |
| 3819 | if ((r.resultWho == null && resultWho == null) || |
| 3820 | (r.resultWho != null && r.resultWho.equals(resultWho))) { |
| 3821 | finishActivityLocked(r, Activity.RESULT_CANCELED, null, "request-sub", |
| 3822 | false); |
| 3823 | } |
Dianne Hackborn | ecc5a9c | 2012-04-26 18:56:09 -0700 | [diff] [blame] | 3824 | } |
| 3825 | } |
| 3826 | } |
Wale Ogunwale | f673393 | 2018-06-27 05:14:34 -0700 | [diff] [blame] | 3827 | mService.updateOomAdj(); |
Dianne Hackborn | ecc5a9c | 2012-04-26 18:56:09 -0700 | [diff] [blame] | 3828 | } |
| 3829 | |
Andrii Kulian | 8cc92ac6 | 2018-04-02 23:14:18 -0700 | [diff] [blame] | 3830 | /** |
| 3831 | * Finish the topmost activity that belongs to the crashed app. We may also finish the activity |
| 3832 | * that requested launch of the crashed one to prevent launch-crash loop. |
| 3833 | * @param app The app that crashed. |
| 3834 | * @param reason Reason to perform this action. |
| 3835 | * @return The task that was finished in this stack, {@code null} if top running activity does |
| 3836 | * not belong to the crashed app. |
| 3837 | */ |
Wale Ogunwale | 9e4f3e0 | 2018-05-17 09:35:39 -0700 | [diff] [blame] | 3838 | final TaskRecord finishTopCrashedActivityLocked(WindowProcessController app, String reason) { |
Filip Gruszczynski | 3e85ba2 | 2015-10-05 22:48:30 -0700 | [diff] [blame] | 3839 | ActivityRecord r = topRunningActivityLocked(); |
Adrian Roos | 20d7df3 | 2016-01-12 18:59:43 +0100 | [diff] [blame] | 3840 | TaskRecord finishedTask = null; |
| 3841 | if (r == null || r.app != app) { |
| 3842 | return null; |
| 3843 | } |
| 3844 | Slog.w(TAG, " Force finishing activity " |
| 3845 | + r.intent.getComponent().flattenToShortString()); |
Wale Ogunwale | 8b19de9 | 2018-11-29 19:58:26 -0800 | [diff] [blame] | 3846 | finishedTask = r.getTaskRecord(); |
Bryce Lee | af691c0 | 2017-03-20 14:20:22 -0700 | [diff] [blame] | 3847 | int taskNdx = mTaskHistory.indexOf(finishedTask); |
| 3848 | final TaskRecord task = finishedTask; |
| 3849 | int activityNdx = task.mActivities.indexOf(r); |
Wale Ogunwale | 3a256e6 | 2018-12-06 14:41:18 -0800 | [diff] [blame] | 3850 | getDisplay().mDisplayContent.prepareAppTransition( |
lumark | 588a3e8 | 2018-07-20 18:53:54 +0800 | [diff] [blame] | 3851 | TRANSIT_CRASHING_ACTIVITY_CLOSE, false /* alwaysKeepCurrent */); |
Adrian Roos | 20d7df3 | 2016-01-12 18:59:43 +0100 | [diff] [blame] | 3852 | finishActivityLocked(r, Activity.RESULT_CANCELED, null, reason, false); |
Bryce Lee | af691c0 | 2017-03-20 14:20:22 -0700 | [diff] [blame] | 3853 | finishedTask = task; |
Adrian Roos | 20d7df3 | 2016-01-12 18:59:43 +0100 | [diff] [blame] | 3854 | // Also terminate any activities below it that aren't yet |
| 3855 | // stopped, to avoid a situation where one will get |
| 3856 | // re-start our crashing activity once it gets resumed again. |
| 3857 | --activityNdx; |
| 3858 | if (activityNdx < 0) { |
| 3859 | do { |
| 3860 | --taskNdx; |
| 3861 | if (taskNdx < 0) { |
| 3862 | break; |
| 3863 | } |
| 3864 | activityNdx = mTaskHistory.get(taskNdx).mActivities.size() - 1; |
| 3865 | } while (activityNdx < 0); |
| 3866 | } |
| 3867 | if (activityNdx >= 0) { |
| 3868 | r = mTaskHistory.get(taskNdx).mActivities.get(activityNdx); |
Bryce Lee | 7ace395 | 2018-02-16 14:34:32 -0800 | [diff] [blame] | 3869 | if (r.isState(RESUMED, PAUSING, PAUSED)) { |
Wale Ogunwale | 9e4f3e0 | 2018-05-17 09:35:39 -0700 | [diff] [blame] | 3870 | if (!r.isActivityTypeHome() || mService.mHomeProcess != r.app) { |
Adrian Roos | 20d7df3 | 2016-01-12 18:59:43 +0100 | [diff] [blame] | 3871 | Slog.w(TAG, " Force finishing activity " |
| 3872 | + r.intent.getComponent().flattenToShortString()); |
| 3873 | finishActivityLocked(r, Activity.RESULT_CANCELED, null, reason, false); |
Craig Mautner | 05d6272ba | 2013-02-11 09:39:27 -0800 | [diff] [blame] | 3874 | } |
| 3875 | } |
| 3876 | } |
Adrian Roos | 20d7df3 | 2016-01-12 18:59:43 +0100 | [diff] [blame] | 3877 | return finishedTask; |
Craig Mautner | 05d6272ba | 2013-02-11 09:39:27 -0800 | [diff] [blame] | 3878 | } |
| 3879 | |
Dianne Hackborn | 6ea0d0a | 2014-07-02 16:23:21 -0700 | [diff] [blame] | 3880 | final void finishVoiceTask(IVoiceInteractionSession session) { |
| 3881 | IBinder sessionBinder = session.asBinder(); |
| 3882 | boolean didOne = false; |
| 3883 | for (int taskNdx = mTaskHistory.size() - 1; taskNdx >= 0; --taskNdx) { |
| 3884 | TaskRecord tr = mTaskHistory.get(taskNdx); |
| 3885 | if (tr.voiceSession != null && tr.voiceSession.asBinder() == sessionBinder) { |
| 3886 | for (int activityNdx = tr.mActivities.size() - 1; activityNdx >= 0; --activityNdx) { |
| 3887 | ActivityRecord r = tr.mActivities.get(activityNdx); |
| 3888 | if (!r.finishing) { |
| 3889 | finishActivityLocked(r, Activity.RESULT_CANCELED, null, "finish-voice", |
| 3890 | false); |
| 3891 | didOne = true; |
| 3892 | } |
| 3893 | } |
Amith Yamasani | 0af6fa7 | 2016-01-17 15:36:19 -0800 | [diff] [blame] | 3894 | } else { |
| 3895 | // Check if any of the activities are using voice |
| 3896 | for (int activityNdx = tr.mActivities.size() - 1; activityNdx >= 0; --activityNdx) { |
| 3897 | ActivityRecord r = tr.mActivities.get(activityNdx); |
Wale Ogunwale | 9e4f3e0 | 2018-05-17 09:35:39 -0700 | [diff] [blame] | 3898 | if (r.voiceSession != null && r.voiceSession.asBinder() == sessionBinder) { |
Amith Yamasani | 0af6fa7 | 2016-01-17 15:36:19 -0800 | [diff] [blame] | 3899 | // Inform of cancellation |
| 3900 | r.clearVoiceSessionLocked(); |
| 3901 | try { |
Wale Ogunwale | 9e4f3e0 | 2018-05-17 09:35:39 -0700 | [diff] [blame] | 3902 | r.app.getThread().scheduleLocalVoiceInteractionStarted( |
| 3903 | r.appToken, null); |
Amith Yamasani | 0af6fa7 | 2016-01-17 15:36:19 -0800 | [diff] [blame] | 3904 | } catch (RemoteException re) { |
| 3905 | // Ok |
| 3906 | } |
Wale Ogunwale | f673393 | 2018-06-27 05:14:34 -0700 | [diff] [blame] | 3907 | mService.finishRunningVoiceLocked(); |
Amith Yamasani | 0af6fa7 | 2016-01-17 15:36:19 -0800 | [diff] [blame] | 3908 | break; |
| 3909 | } |
| 3910 | } |
Dianne Hackborn | 6ea0d0a | 2014-07-02 16:23:21 -0700 | [diff] [blame] | 3911 | } |
| 3912 | } |
Amith Yamasani | 0af6fa7 | 2016-01-17 15:36:19 -0800 | [diff] [blame] | 3913 | |
Dianne Hackborn | 6ea0d0a | 2014-07-02 16:23:21 -0700 | [diff] [blame] | 3914 | if (didOne) { |
Wale Ogunwale | f673393 | 2018-06-27 05:14:34 -0700 | [diff] [blame] | 3915 | mService.updateOomAdj(); |
Dianne Hackborn | 6ea0d0a | 2014-07-02 16:23:21 -0700 | [diff] [blame] | 3916 | } |
| 3917 | } |
| 3918 | |
Craig Mautner | d232895 | 2013-03-05 12:46:26 -0800 | [diff] [blame] | 3919 | final boolean finishActivityAffinityLocked(ActivityRecord r) { |
Wale Ogunwale | 8b19de9 | 2018-11-29 19:58:26 -0800 | [diff] [blame] | 3920 | ArrayList<ActivityRecord> activities = r.getTaskRecord().mActivities; |
Craig Mautner | d74f7d7 | 2013-02-26 13:41:02 -0800 | [diff] [blame] | 3921 | for (int index = activities.indexOf(r); index >= 0; --index) { |
| 3922 | ActivityRecord cur = activities.get(index); |
Kenny Root | e6585b3 | 2013-12-13 12:00:26 -0800 | [diff] [blame] | 3923 | if (!Objects.equals(cur.taskAffinity, r.taskAffinity)) { |
Dianne Hackborn | ecc5a9c | 2012-04-26 18:56:09 -0700 | [diff] [blame] | 3924 | break; |
| 3925 | } |
Craig Mautner | de4ef02 | 2013-04-07 19:01:33 -0700 | [diff] [blame] | 3926 | finishActivityLocked(cur, Activity.RESULT_CANCELED, null, "request-affinity", true); |
Dianne Hackborn | ecc5a9c | 2012-04-26 18:56:09 -0700 | [diff] [blame] | 3927 | } |
| 3928 | return true; |
| 3929 | } |
| 3930 | |
Andrii Kulian | 21713ac | 2016-10-12 22:05:05 -0700 | [diff] [blame] | 3931 | private void finishActivityResultsLocked(ActivityRecord r, int resultCode, Intent resultData) { |
Dianne Hackborn | 5c60743 | 2012-02-28 14:44:19 -0800 | [diff] [blame] | 3932 | // send the result |
| 3933 | ActivityRecord resultTo = r.resultTo; |
| 3934 | if (resultTo != null) { |
Wale Ogunwale | ee006da | 2015-03-30 14:49:25 -0700 | [diff] [blame] | 3935 | if (DEBUG_RESULTS) Slog.v(TAG_RESULTS, "Adding result to " + resultTo |
Dianne Hackborn | 5c60743 | 2012-02-28 14:44:19 -0800 | [diff] [blame] | 3936 | + " who=" + r.resultWho + " req=" + r.requestCode |
| 3937 | + " res=" + resultCode + " data=" + resultData); |
Wale Ogunwale | 8b19de9 | 2018-11-29 19:58:26 -0800 | [diff] [blame] | 3938 | if (resultTo.mUserId != r.mUserId) { |
Nicolas Prevot | 6b942b8 | 2014-06-02 15:20:42 +0100 | [diff] [blame] | 3939 | if (resultData != null) { |
Wale Ogunwale | 8b19de9 | 2018-11-29 19:58:26 -0800 | [diff] [blame] | 3940 | resultData.prepareToLeaveUser(r.mUserId); |
Nicolas Prevot | 6b942b8 | 2014-06-02 15:20:42 +0100 | [diff] [blame] | 3941 | } |
Nicolas Prevot | c6cf95c | 2014-05-29 11:30:36 +0100 | [diff] [blame] | 3942 | } |
Dianne Hackborn | 5c60743 | 2012-02-28 14:44:19 -0800 | [diff] [blame] | 3943 | if (r.info.applicationInfo.uid > 0) { |
Wale Ogunwale | 6d50dcc | 2018-07-21 23:00:40 -0700 | [diff] [blame] | 3944 | mService.mUgmInternal.grantUriPermissionFromIntent(r.info.applicationInfo.uid, |
Dianne Hackborn | 5c60743 | 2012-02-28 14:44:19 -0800 | [diff] [blame] | 3945 | resultTo.packageName, resultData, |
Wale Ogunwale | 8b19de9 | 2018-11-29 19:58:26 -0800 | [diff] [blame] | 3946 | resultTo.getUriPermissionsLocked(), resultTo.mUserId); |
Dianne Hackborn | 5c60743 | 2012-02-28 14:44:19 -0800 | [diff] [blame] | 3947 | } |
Wale Ogunwale | 5fa8a8c | 2018-05-08 13:43:21 -0700 | [diff] [blame] | 3948 | resultTo.addResultLocked(r, r.resultWho, r.requestCode, resultCode, resultData); |
Dianne Hackborn | 5c60743 | 2012-02-28 14:44:19 -0800 | [diff] [blame] | 3949 | r.resultTo = null; |
| 3950 | } |
Wale Ogunwale | ee006da | 2015-03-30 14:49:25 -0700 | [diff] [blame] | 3951 | 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] | 3952 | |
| 3953 | // Make sure this HistoryRecord is not holding on to other resources, |
| 3954 | // because clients have remote IPC references to this object so we |
| 3955 | // can't assume that will go away and want to avoid circular IPC refs. |
| 3956 | r.results = null; |
| 3957 | r.pendingResults = null; |
| 3958 | r.newIntents = null; |
| 3959 | r.icicle = null; |
| 3960 | } |
| 3961 | |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 3962 | /** |
Winson Chung | 6954fc9 | 2017-03-24 16:22:12 -0700 | [diff] [blame] | 3963 | * See {@link #finishActivityLocked(ActivityRecord, int, Intent, String, boolean, boolean)} |
| 3964 | */ |
| 3965 | final boolean finishActivityLocked(ActivityRecord r, int resultCode, Intent resultData, |
| 3966 | String reason, boolean oomAdj) { |
| 3967 | return finishActivityLocked(r, resultCode, resultData, reason, oomAdj, !PAUSE_IMMEDIATELY); |
| 3968 | } |
| 3969 | |
| 3970 | /** |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 3971 | * @return Returns true if this activity has been removed from the history |
| 3972 | * list, or false if it is still in the list and will be removed later. |
| 3973 | */ |
Craig Mautner | f333327 | 2013-04-22 10:55:53 -0700 | [diff] [blame] | 3974 | final boolean finishActivityLocked(ActivityRecord r, int resultCode, Intent resultData, |
Winson Chung | 6954fc9 | 2017-03-24 16:22:12 -0700 | [diff] [blame] | 3975 | String reason, boolean oomAdj, boolean pauseImmediately) { |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 3976 | if (r.finishing) { |
| 3977 | Slog.w(TAG, "Duplicate finish request for " + r); |
| 3978 | return false; |
| 3979 | } |
| 3980 | |
Jorim Jaggi | fe76234 | 2016-10-13 14:33:27 +0200 | [diff] [blame] | 3981 | mWindowManager.deferSurfaceLayout(); |
| 3982 | try { |
| 3983 | r.makeFinishingLocked(); |
Wale Ogunwale | 8b19de9 | 2018-11-29 19:58:26 -0800 | [diff] [blame] | 3984 | final TaskRecord task = r.getTaskRecord(); |
Jorim Jaggi | fe76234 | 2016-10-13 14:33:27 +0200 | [diff] [blame] | 3985 | EventLog.writeEvent(EventLogTags.AM_FINISH_ACTIVITY, |
Wale Ogunwale | 8b19de9 | 2018-11-29 19:58:26 -0800 | [diff] [blame] | 3986 | r.mUserId, System.identityHashCode(r), |
Jorim Jaggi | fe76234 | 2016-10-13 14:33:27 +0200 | [diff] [blame] | 3987 | task.taskId, r.shortComponentName, reason); |
| 3988 | final ArrayList<ActivityRecord> activities = task.mActivities; |
| 3989 | final int index = activities.indexOf(r); |
| 3990 | if (index < (activities.size() - 1)) { |
| 3991 | task.setFrontOfTask(); |
| 3992 | if ((r.intent.getFlags() & Intent.FLAG_ACTIVITY_CLEAR_WHEN_TASK_RESET) != 0) { |
| 3993 | // If the caller asked that this activity (and all above it) |
| 3994 | // be cleared when the task is reset, don't lose that information, |
| 3995 | // but propagate it up to the next activity. |
| 3996 | ActivityRecord next = activities.get(index+1); |
| 3997 | next.intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_WHEN_TASK_RESET); |
| 3998 | } |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 3999 | } |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 4000 | |
Jorim Jaggi | fe76234 | 2016-10-13 14:33:27 +0200 | [diff] [blame] | 4001 | r.pauseKeyDispatchingLocked(); |
Craig Mautner | 04f0b70 | 2013-10-22 12:31:01 -0700 | [diff] [blame] | 4002 | |
Wale Ogunwale | 66e1685 | 2017-10-19 13:35:52 -0700 | [diff] [blame] | 4003 | adjustFocusedActivityStack(r, "finishActivity"); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 4004 | |
Jorim Jaggi | fe76234 | 2016-10-13 14:33:27 +0200 | [diff] [blame] | 4005 | finishActivityResultsLocked(r, resultCode, resultData); |
Craig Mautner | 2420ead | 2013-04-01 17:13:20 -0700 | [diff] [blame] | 4006 | |
Yorke Lee | bdef537 | 2017-04-10 16:38:51 -0700 | [diff] [blame] | 4007 | final boolean endTask = index <= 0 && !task.isClearingToReuseTask(); |
Jorim Jaggi | fe76234 | 2016-10-13 14:33:27 +0200 | [diff] [blame] | 4008 | final int transit = endTask ? TRANSIT_TASK_CLOSE : TRANSIT_ACTIVITY_CLOSE; |
| 4009 | if (mResumedActivity == r) { |
| 4010 | if (DEBUG_VISIBILITY || DEBUG_TRANSITION) Slog.v(TAG_TRANSITION, |
| 4011 | "Prepare close transition: finishing " + r); |
Winson Chung | 6954fc9 | 2017-03-24 16:22:12 -0700 | [diff] [blame] | 4012 | if (endTask) { |
Wale Ogunwale | 5fa8a8c | 2018-05-08 13:43:21 -0700 | [diff] [blame] | 4013 | mService.getTaskChangeNotificationController().notifyTaskRemovalStarted( |
Mark Renouf | c808f06 | 2019-02-07 15:20:37 -0500 | [diff] [blame] | 4014 | task.getTaskInfo()); |
Winson Chung | 6954fc9 | 2017-03-24 16:22:12 -0700 | [diff] [blame] | 4015 | } |
Wale Ogunwale | 3a256e6 | 2018-12-06 14:41:18 -0800 | [diff] [blame] | 4016 | getDisplay().mDisplayContent.prepareAppTransition(transit, false); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 4017 | |
Jorim Jaggi | fe76234 | 2016-10-13 14:33:27 +0200 | [diff] [blame] | 4018 | // Tell window manager to prepare for this one to be removed. |
Wale Ogunwale | 26c0dfe | 2016-12-14 14:42:30 -0800 | [diff] [blame] | 4019 | r.setVisibility(false); |
Jorim Jaggi | fe76234 | 2016-10-13 14:33:27 +0200 | [diff] [blame] | 4020 | |
| 4021 | if (mPausingActivity == null) { |
| 4022 | if (DEBUG_PAUSE) Slog.v(TAG_PAUSE, "Finish needs to pause: " + r); |
| 4023 | if (DEBUG_USER_LEAVING) Slog.v(TAG_USER_LEAVING, |
| 4024 | "finish() => pause with userLeaving=false"); |
Winson Chung | 6954fc9 | 2017-03-24 16:22:12 -0700 | [diff] [blame] | 4025 | startPausingLocked(false, false, null, pauseImmediately); |
Jorim Jaggi | fe76234 | 2016-10-13 14:33:27 +0200 | [diff] [blame] | 4026 | } |
| 4027 | |
| 4028 | if (endTask) { |
Wale Ogunwale | 5fa8a8c | 2018-05-08 13:43:21 -0700 | [diff] [blame] | 4029 | mService.getLockTaskController().clearLockedTask(task); |
Jorim Jaggi | fe76234 | 2016-10-13 14:33:27 +0200 | [diff] [blame] | 4030 | } |
Bryce Lee | 7ace395 | 2018-02-16 14:34:32 -0800 | [diff] [blame] | 4031 | } else if (!r.isState(PAUSING)) { |
Jorim Jaggi | fe76234 | 2016-10-13 14:33:27 +0200 | [diff] [blame] | 4032 | // If the activity is PAUSING, we will complete the finish once |
| 4033 | // it is done pausing; else we can just directly finish it here. |
| 4034 | if (DEBUG_PAUSE) Slog.v(TAG_PAUSE, "Finish not pausing: " + r); |
| 4035 | if (r.visible) { |
Winson Chung | 6954fc9 | 2017-03-24 16:22:12 -0700 | [diff] [blame] | 4036 | prepareActivityHideTransitionAnimation(r, transit); |
| 4037 | } |
| 4038 | |
| 4039 | final int finishMode = (r.visible || r.nowVisible) ? FINISH_AFTER_VISIBLE |
| 4040 | : FINISH_AFTER_PAUSE; |
Bryce Lee | f52974c | 2018-02-14 15:12:01 -0800 | [diff] [blame] | 4041 | final boolean removedActivity = finishCurrentActivityLocked(r, finishMode, oomAdj, |
| 4042 | "finishActivityLocked") == null; |
Winson Chung | 6954fc9 | 2017-03-24 16:22:12 -0700 | [diff] [blame] | 4043 | |
| 4044 | // The following code is an optimization. When the last non-task overlay activity |
| 4045 | // is removed from the task, we remove the entire task from the stack. However, |
| 4046 | // since that is done after the scheduled destroy callback from the activity, that |
| 4047 | // call to change the visibility of the task overlay activities would be out of |
| 4048 | // sync with the activitiy visibility being set for this finishing activity above. |
| 4049 | // In this case, we can set the visibility of all the task overlay activities when |
| 4050 | // we detect the last one is finishing to keep them in sync. |
| 4051 | if (task.onlyHasTaskOverlayActivities(true /* excludeFinishing */)) { |
| 4052 | for (ActivityRecord taskOverlay : task.mActivities) { |
| 4053 | if (!taskOverlay.mTaskOverlay) { |
| 4054 | continue; |
| 4055 | } |
| 4056 | prepareActivityHideTransitionAnimation(taskOverlay, transit); |
Jorim Jaggi | fe76234 | 2016-10-13 14:33:27 +0200 | [diff] [blame] | 4057 | } |
| 4058 | } |
Winson Chung | 6954fc9 | 2017-03-24 16:22:12 -0700 | [diff] [blame] | 4059 | return removedActivity; |
Jorim Jaggi | fe76234 | 2016-10-13 14:33:27 +0200 | [diff] [blame] | 4060 | } else { |
| 4061 | if (DEBUG_PAUSE) Slog.v(TAG_PAUSE, "Finish waiting for pause of: " + r); |
| 4062 | } |
| 4063 | |
| 4064 | return false; |
| 4065 | } finally { |
| 4066 | mWindowManager.continueSurfaceLayout(); |
| 4067 | } |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 4068 | } |
| 4069 | |
Winson Chung | 6954fc9 | 2017-03-24 16:22:12 -0700 | [diff] [blame] | 4070 | private void prepareActivityHideTransitionAnimation(ActivityRecord r, int transit) { |
Wale Ogunwale | 3a256e6 | 2018-12-06 14:41:18 -0800 | [diff] [blame] | 4071 | final DisplayContent dc = getDisplay().mDisplayContent; |
| 4072 | dc.prepareAppTransition(transit, false); |
Winson Chung | 6954fc9 | 2017-03-24 16:22:12 -0700 | [diff] [blame] | 4073 | r.setVisibility(false); |
Wale Ogunwale | 3a256e6 | 2018-12-06 14:41:18 -0800 | [diff] [blame] | 4074 | dc.executeAppTransition(); |
Winson Chung | 6954fc9 | 2017-03-24 16:22:12 -0700 | [diff] [blame] | 4075 | } |
| 4076 | |
Craig Mautner | f333327 | 2013-04-22 10:55:53 -0700 | [diff] [blame] | 4077 | static final int FINISH_IMMEDIATELY = 0; |
| 4078 | static final int FINISH_AFTER_PAUSE = 1; |
| 4079 | static final int FINISH_AFTER_VISIBLE = 2; |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 4080 | |
Bryce Lee | f52974c | 2018-02-14 15:12:01 -0800 | [diff] [blame] | 4081 | final ActivityRecord finishCurrentActivityLocked(ActivityRecord r, int mode, boolean oomAdj, |
| 4082 | String reason) { |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 4083 | // First things first: if this activity is currently visible, |
| 4084 | // and the resumed activity is not yet visible, then hold off on |
| 4085 | // finishing until the resumed one becomes visible. |
Chong Zhang | 824b6dc | 2016-04-27 14:11:12 -0700 | [diff] [blame] | 4086 | |
Bryce Lee | c961e0a | 2018-04-13 17:58:02 -0700 | [diff] [blame] | 4087 | // The activity that we are finishing may be over the lock screen. In this case, we do not |
| 4088 | // want to consider activities that cannot be shown on the lock screen as running and should |
| 4089 | // proceed with finishing the activity if there is no valid next top running activity. |
Riddle Hsu | e10cea5 | 2018-10-16 23:33:23 +0800 | [diff] [blame] | 4090 | final ActivityDisplay display = getDisplay(); |
| 4091 | final ActivityRecord next = display.topRunningActivity(true /* considerKeyguardState */); |
Chong Zhang | 824b6dc | 2016-04-27 14:11:12 -0700 | [diff] [blame] | 4092 | |
Chong Zhang | efd9a5b | 2016-04-26 16:21:07 -0700 | [diff] [blame] | 4093 | if (mode == FINISH_AFTER_VISIBLE && (r.visible || r.nowVisible) |
Chong Zhang | 824b6dc | 2016-04-27 14:11:12 -0700 | [diff] [blame] | 4094 | && next != null && !next.nowVisible) { |
Craig Mautner | de4ef02 | 2013-04-07 19:01:33 -0700 | [diff] [blame] | 4095 | if (!mStackSupervisor.mStoppingActivities.contains(r)) { |
Winson Chung | 4dabf23 | 2017-01-25 13:25:22 -0800 | [diff] [blame] | 4096 | addToStopping(r, false /* scheduleIdle */, false /* idleDelayed */); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 4097 | } |
Wale Ogunwale | 0fc365c | 2015-05-25 19:35:42 -0700 | [diff] [blame] | 4098 | if (DEBUG_STATES) Slog.v(TAG_STATES, |
| 4099 | "Moving to STOPPING: "+ r + " (finish requested)"); |
Bryce Lee | 7ace395 | 2018-02-16 14:34:32 -0800 | [diff] [blame] | 4100 | r.setState(STOPPING, "finishCurrentActivityLocked"); |
Dianne Hackborn | 2d1b378 | 2012-09-09 17:49:39 -0700 | [diff] [blame] | 4101 | if (oomAdj) { |
Wale Ogunwale | f673393 | 2018-06-27 05:14:34 -0700 | [diff] [blame] | 4102 | mService.updateOomAdj(); |
Dianne Hackborn | 2d1b378 | 2012-09-09 17:49:39 -0700 | [diff] [blame] | 4103 | } |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 4104 | return r; |
| 4105 | } |
| 4106 | |
| 4107 | // make sure the record is cleaned out of other places. |
Craig Mautner | de4ef02 | 2013-04-07 19:01:33 -0700 | [diff] [blame] | 4108 | mStackSupervisor.mStoppingActivities.remove(r); |
Craig Mautner | 0eea92c | 2013-05-16 13:35:39 -0700 | [diff] [blame] | 4109 | mStackSupervisor.mGoingToSleepActivities.remove(r); |
Bryce Lee | 7ace395 | 2018-02-16 14:34:32 -0800 | [diff] [blame] | 4110 | final ActivityState prevState = r.getState(); |
Wale Ogunwale | 0fc365c | 2015-05-25 19:35:42 -0700 | [diff] [blame] | 4111 | if (DEBUG_STATES) Slog.v(TAG_STATES, "Moving to FINISHING: " + r); |
Bryce Lee | b0f993f | 2018-03-02 15:38:01 -0800 | [diff] [blame] | 4112 | |
Bryce Lee | 7ace395 | 2018-02-16 14:34:32 -0800 | [diff] [blame] | 4113 | r.setState(FINISHING, "finishCurrentActivityLocked"); |
Riddle Hsu | e10cea5 | 2018-10-16 23:33:23 +0800 | [diff] [blame] | 4114 | final boolean finishingInNonFocusedStackOrNoRunning = mode == FINISH_AFTER_VISIBLE |
Wale Ogunwale | 8b19de9 | 2018-11-29 19:58:26 -0800 | [diff] [blame] | 4115 | && prevState == PAUSED && (r.getActivityStack() != display.getFocusedStack() |
Riddle Hsu | e10cea5 | 2018-10-16 23:33:23 +0800 | [diff] [blame] | 4116 | || (next == null && display.topRunningActivity() == null)); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 4117 | |
| 4118 | if (mode == FINISH_IMMEDIATELY |
Bryce Lee | 7ace395 | 2018-02-16 14:34:32 -0800 | [diff] [blame] | 4119 | || (prevState == PAUSED |
Wale Ogunwale | 44f036f | 2017-09-29 05:09:09 -0700 | [diff] [blame] | 4120 | && (mode == FINISH_AFTER_PAUSE || inPinnedWindowingMode())) |
Riddle Hsu | e10cea5 | 2018-10-16 23:33:23 +0800 | [diff] [blame] | 4121 | || finishingInNonFocusedStackOrNoRunning |
Wale Ogunwale | b9a0c99 | 2017-04-18 07:25:20 -0700 | [diff] [blame] | 4122 | || prevState == STOPPING |
| 4123 | || prevState == STOPPED |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 4124 | || prevState == ActivityState.INITIALIZING) { |
Wale Ogunwale | 7d70117 | 2015-03-11 15:36:30 -0700 | [diff] [blame] | 4125 | r.makeFinishingLocked(); |
Bryce Lee | f52974c | 2018-02-14 15:12:01 -0800 | [diff] [blame] | 4126 | boolean activityRemoved = destroyActivityLocked(r, true, "finish-imm:" + reason); |
Andrii Kulian | 7318d63 | 2016-07-20 18:59:28 -0700 | [diff] [blame] | 4127 | |
Riddle Hsu | e10cea5 | 2018-10-16 23:33:23 +0800 | [diff] [blame] | 4128 | if (finishingInNonFocusedStackOrNoRunning) { |
Andrii Kulian | 995fa2b | 2016-07-29 12:55:41 -0700 | [diff] [blame] | 4129 | // Finishing activity that was in paused state and it was in not currently focused |
Riddle Hsu | e10cea5 | 2018-10-16 23:33:23 +0800 | [diff] [blame] | 4130 | // stack, need to make something visible in its place. Also if the display does not |
| 4131 | // have running activity, the configuration may need to be updated for restoring |
| 4132 | // original orientation of the display. |
Wale Ogunwale | d32da47 | 2018-11-16 07:19:28 -0800 | [diff] [blame] | 4133 | mRootActivityContainer.ensureVisibilityAndConfig(next, mDisplayId, |
Andrii Kulian | f4479ee | 2018-05-23 17:52:48 -0700 | [diff] [blame] | 4134 | false /* markFrozenIfConfigChanged */, true /* deferResume */); |
Andrii Kulian | 7318d63 | 2016-07-20 18:59:28 -0700 | [diff] [blame] | 4135 | } |
Dianne Hackborn | 42e620c | 2012-06-24 13:20:51 -0700 | [diff] [blame] | 4136 | if (activityRemoved) { |
Wale Ogunwale | d32da47 | 2018-11-16 07:19:28 -0800 | [diff] [blame] | 4137 | mRootActivityContainer.resumeFocusedStacksTopActivities(); |
Dianne Hackborn | 42e620c | 2012-06-24 13:20:51 -0700 | [diff] [blame] | 4138 | } |
Wale Ogunwale | 0fc365c | 2015-05-25 19:35:42 -0700 | [diff] [blame] | 4139 | if (DEBUG_CONTAINERS) Slog.d(TAG_CONTAINERS, |
Craig Mautner | d163e75 | 2014-06-13 17:18:47 -0700 | [diff] [blame] | 4140 | "destroyActivityLocked: finishCurrentActivityLocked r=" + r + |
| 4141 | " destroy returned removed=" + activityRemoved); |
Dianne Hackborn | 42e620c | 2012-06-24 13:20:51 -0700 | [diff] [blame] | 4142 | return activityRemoved ? null : r; |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 4143 | } |
Craig Mautner | 05d6272ba | 2013-02-11 09:39:27 -0800 | [diff] [blame] | 4144 | |
| 4145 | // Need to go through the full pause cycle to get this |
| 4146 | // activity into the stopped state and then finish it. |
Wale Ogunwale | e23149f | 2015-03-06 15:39:44 -0800 | [diff] [blame] | 4147 | if (DEBUG_ALL) Slog.v(TAG, "Enqueueing pending finish: " + r); |
Craig Mautner | f333327 | 2013-04-22 10:55:53 -0700 | [diff] [blame] | 4148 | mStackSupervisor.mFinishingActivities.add(r); |
Martin Wallgren | c8733b8 | 2011-08-31 12:39:31 +0200 | [diff] [blame] | 4149 | r.resumeKeyDispatchingLocked(); |
Wale Ogunwale | d32da47 | 2018-11-16 07:19:28 -0800 | [diff] [blame] | 4150 | mRootActivityContainer.resumeFocusedStacksTopActivities(); |
Andrii Kulian | 6b32151 | 2019-01-23 06:37:00 +0000 | [diff] [blame] | 4151 | // If activity was not paused at this point - explicitly pause it to start finishing |
| 4152 | // process. Finishing will be completed once it reports pause back. |
| 4153 | if (r.isState(RESUMED) && mPausingActivity != null) { |
| 4154 | startPausingLocked(false /* userLeaving */, false /* uiSleeping */, next /* resuming */, |
| 4155 | false /* dontWait */); |
| 4156 | } |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 4157 | return r; |
| 4158 | } |
| 4159 | |
Craig Mautner | ee36c77 | 2014-07-16 14:56:05 -0700 | [diff] [blame] | 4160 | void finishAllActivitiesLocked(boolean immediately) { |
| 4161 | boolean noActivitiesInStack = true; |
Craig Mautner | f4c909b | 2014-04-17 18:39:38 -0700 | [diff] [blame] | 4162 | for (int taskNdx = mTaskHistory.size() - 1; taskNdx >= 0; --taskNdx) { |
| 4163 | final ArrayList<ActivityRecord> activities = mTaskHistory.get(taskNdx).mActivities; |
| 4164 | for (int activityNdx = activities.size() - 1; activityNdx >= 0; --activityNdx) { |
| 4165 | final ActivityRecord r = activities.get(activityNdx); |
Craig Mautner | ee36c77 | 2014-07-16 14:56:05 -0700 | [diff] [blame] | 4166 | noActivitiesInStack = false; |
| 4167 | if (r.finishing && !immediately) { |
Craig Mautner | f4c909b | 2014-04-17 18:39:38 -0700 | [diff] [blame] | 4168 | continue; |
| 4169 | } |
Craig Mautner | ee36c77 | 2014-07-16 14:56:05 -0700 | [diff] [blame] | 4170 | Slog.d(TAG, "finishAllActivitiesLocked: finishing " + r + " immediately"); |
Bryce Lee | f52974c | 2018-02-14 15:12:01 -0800 | [diff] [blame] | 4171 | finishCurrentActivityLocked(r, FINISH_IMMEDIATELY, false, |
| 4172 | "finishAllActivitiesLocked"); |
Craig Mautner | f4c909b | 2014-04-17 18:39:38 -0700 | [diff] [blame] | 4173 | } |
| 4174 | } |
Craig Mautner | ee36c77 | 2014-07-16 14:56:05 -0700 | [diff] [blame] | 4175 | if (noActivitiesInStack) { |
Andrii Kulian | 94e82d9b0 | 2017-07-13 15:33:06 -0700 | [diff] [blame] | 4176 | remove(); |
Craig Mautner | ee36c77 | 2014-07-16 14:56:05 -0700 | [diff] [blame] | 4177 | } |
Craig Mautner | f4c909b | 2014-04-17 18:39:38 -0700 | [diff] [blame] | 4178 | } |
| 4179 | |
Wale Ogunwale | 66e1685 | 2017-10-19 13:35:52 -0700 | [diff] [blame] | 4180 | /** @return true if the stack behind this one is a standard activity type. */ |
| 4181 | boolean inFrontOfStandardStack() { |
| 4182 | final ActivityDisplay display = getDisplay(); |
| 4183 | if (display == null) { |
| 4184 | return false; |
| 4185 | } |
| 4186 | final int index = display.getIndexOf(this); |
| 4187 | if (index == 0) { |
| 4188 | return false; |
| 4189 | } |
| 4190 | final ActivityStack stackBehind = display.getChildAt(index - 1); |
| 4191 | return stackBehind.isActivityTypeStandard(); |
| 4192 | } |
| 4193 | |
| 4194 | boolean shouldUpRecreateTaskLocked(ActivityRecord srec, String destAffinity) { |
Dianne Hackborn | 6f4d61f | 2014-08-21 17:50:42 -0700 | [diff] [blame] | 4195 | // Basic case: for simple app-centric recents, we need to recreate |
| 4196 | // the task if the affinity has changed. |
Wale Ogunwale | 8b19de9 | 2018-11-29 19:58:26 -0800 | [diff] [blame] | 4197 | if (srec == null || srec.getTaskRecord().affinity == null || |
| 4198 | !srec.getTaskRecord().affinity.equals(destAffinity)) { |
Dianne Hackborn | 6f4d61f | 2014-08-21 17:50:42 -0700 | [diff] [blame] | 4199 | return true; |
| 4200 | } |
| 4201 | // Document-centric case: an app may be split in to multiple documents; |
| 4202 | // they need to re-create their task if this current activity is the root |
| 4203 | // of a document, unless simply finishing it will return them to the the |
| 4204 | // correct app behind. |
Wale Ogunwale | 8b19de9 | 2018-11-29 19:58:26 -0800 | [diff] [blame] | 4205 | final TaskRecord task = srec.getTaskRecord(); |
Wale Ogunwale | 66e1685 | 2017-10-19 13:35:52 -0700 | [diff] [blame] | 4206 | if (srec.frontOfTask && task.getBaseIntent() != null && task.getBaseIntent().isDocument()) { |
Dianne Hackborn | 6f4d61f | 2014-08-21 17:50:42 -0700 | [diff] [blame] | 4207 | // Okay, this activity is at the root of its task. What to do, what to do... |
Wale Ogunwale | 66e1685 | 2017-10-19 13:35:52 -0700 | [diff] [blame] | 4208 | if (!inFrontOfStandardStack()) { |
Dianne Hackborn | 6f4d61f | 2014-08-21 17:50:42 -0700 | [diff] [blame] | 4209 | // Finishing won't return to an application, so we need to recreate. |
| 4210 | return true; |
| 4211 | } |
| 4212 | // We now need to get the task below it to determine what to do. |
Bryce Lee | af691c0 | 2017-03-20 14:20:22 -0700 | [diff] [blame] | 4213 | int taskIdx = mTaskHistory.indexOf(task); |
Dianne Hackborn | 6f4d61f | 2014-08-21 17:50:42 -0700 | [diff] [blame] | 4214 | if (taskIdx <= 0) { |
| 4215 | Slog.w(TAG, "shouldUpRecreateTask: task not in history for " + srec); |
| 4216 | return false; |
| 4217 | } |
Wale Ogunwale | 6fbde9f | 2017-08-24 07:24:12 -0700 | [diff] [blame] | 4218 | final TaskRecord prevTask = mTaskHistory.get(taskIdx); |
Bryce Lee | af691c0 | 2017-03-20 14:20:22 -0700 | [diff] [blame] | 4219 | if (!task.affinity.equals(prevTask.affinity)) { |
Dianne Hackborn | 6f4d61f | 2014-08-21 17:50:42 -0700 | [diff] [blame] | 4220 | // These are different apps, so need to recreate. |
| 4221 | return true; |
| 4222 | } |
| 4223 | } |
| 4224 | return false; |
| 4225 | } |
| 4226 | |
Wale Ogunwale | 7d70117 | 2015-03-11 15:36:30 -0700 | [diff] [blame] | 4227 | final boolean navigateUpToLocked(ActivityRecord srec, Intent destIntent, int resultCode, |
Craig Mautner | 05d6272ba | 2013-02-11 09:39:27 -0800 | [diff] [blame] | 4228 | Intent resultData) { |
Wale Ogunwale | 8b19de9 | 2018-11-29 19:58:26 -0800 | [diff] [blame] | 4229 | final TaskRecord task = srec.getTaskRecord(); |
Craig Mautner | 0247fc8 | 2013-02-28 14:32:06 -0800 | [diff] [blame] | 4230 | final ArrayList<ActivityRecord> activities = task.mActivities; |
| 4231 | final int start = activities.indexOf(srec); |
| 4232 | if (!mTaskHistory.contains(task) || (start < 0)) { |
Craig Mautner | 05d6272ba | 2013-02-11 09:39:27 -0800 | [diff] [blame] | 4233 | return false; |
| 4234 | } |
| 4235 | int finishTo = start - 1; |
Craig Mautner | 0247fc8 | 2013-02-28 14:32:06 -0800 | [diff] [blame] | 4236 | ActivityRecord parent = finishTo < 0 ? null : activities.get(finishTo); |
Craig Mautner | 05d6272ba | 2013-02-11 09:39:27 -0800 | [diff] [blame] | 4237 | boolean foundParentInTask = false; |
Craig Mautner | 0247fc8 | 2013-02-28 14:32:06 -0800 | [diff] [blame] | 4238 | final ComponentName dest = destIntent.getComponent(); |
| 4239 | if (start > 0 && dest != null) { |
| 4240 | for (int i = finishTo; i >= 0; i--) { |
| 4241 | ActivityRecord r = activities.get(i); |
| 4242 | if (r.info.packageName.equals(dest.getPackageName()) && |
Craig Mautner | 05d6272ba | 2013-02-11 09:39:27 -0800 | [diff] [blame] | 4243 | r.info.name.equals(dest.getClassName())) { |
| 4244 | finishTo = i; |
| 4245 | parent = r; |
| 4246 | foundParentInTask = true; |
| 4247 | break; |
| 4248 | } |
| 4249 | } |
| 4250 | } |
| 4251 | |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 4252 | // TODO: There is a dup. of this block of code in ActivityTaskManagerService.finishActivity |
| 4253 | // We should consolidate. |
| 4254 | IActivityController controller = mService.mController; |
Craig Mautner | 05d6272ba | 2013-02-11 09:39:27 -0800 | [diff] [blame] | 4255 | if (controller != null) { |
| 4256 | ActivityRecord next = topRunningActivityLocked(srec.appToken, 0); |
| 4257 | if (next != null) { |
| 4258 | // ask watcher if this is allowed |
| 4259 | boolean resumeOK = true; |
| 4260 | try { |
| 4261 | resumeOK = controller.activityResuming(next.packageName); |
| 4262 | } catch (RemoteException e) { |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 4263 | mService.mController = null; |
Kenny Root | add5821 | 2013-05-07 09:47:34 -0700 | [diff] [blame] | 4264 | Watchdog.getInstance().setActivityController(null); |
Craig Mautner | 05d6272ba | 2013-02-11 09:39:27 -0800 | [diff] [blame] | 4265 | } |
| 4266 | |
| 4267 | if (!resumeOK) { |
| 4268 | return false; |
| 4269 | } |
| 4270 | } |
| 4271 | } |
| 4272 | final long origId = Binder.clearCallingIdentity(); |
| 4273 | for (int i = start; i > finishTo; i--) { |
Craig Mautner | 0247fc8 | 2013-02-28 14:32:06 -0800 | [diff] [blame] | 4274 | ActivityRecord r = activities.get(i); |
| 4275 | requestFinishActivityLocked(r.appToken, resultCode, resultData, "navigate-up", true); |
Craig Mautner | 05d6272ba | 2013-02-11 09:39:27 -0800 | [diff] [blame] | 4276 | // Only return the supplied result for the first activity finished |
| 4277 | resultCode = Activity.RESULT_CANCELED; |
| 4278 | resultData = null; |
| 4279 | } |
| 4280 | |
| 4281 | if (parent != null && foundParentInTask) { |
| 4282 | final int parentLaunchMode = parent.info.launchMode; |
| 4283 | final int destIntentFlags = destIntent.getFlags(); |
| 4284 | if (parentLaunchMode == ActivityInfo.LAUNCH_SINGLE_INSTANCE || |
| 4285 | parentLaunchMode == ActivityInfo.LAUNCH_SINGLE_TASK || |
| 4286 | parentLaunchMode == ActivityInfo.LAUNCH_SINGLE_TOP || |
| 4287 | (destIntentFlags & Intent.FLAG_ACTIVITY_CLEAR_TOP) != 0) { |
Dianne Hackborn | 85d558c | 2014-11-04 10:31:54 -0800 | [diff] [blame] | 4288 | parent.deliverNewIntentLocked(srec.info.applicationInfo.uid, destIntent, |
| 4289 | srec.packageName); |
Craig Mautner | 05d6272ba | 2013-02-11 09:39:27 -0800 | [diff] [blame] | 4290 | } else { |
| 4291 | try { |
| 4292 | ActivityInfo aInfo = AppGlobals.getPackageManager().getActivityInfo( |
Philip P. Moltmann | cff8f0f | 2018-03-27 12:51:51 -0700 | [diff] [blame] | 4293 | destIntent.getComponent(), ActivityManagerService.STOCK_PM_FLAGS, |
Wale Ogunwale | 8b19de9 | 2018-11-29 19:58:26 -0800 | [diff] [blame] | 4294 | srec.mUserId); |
Bryce Lee | 4c9a597 | 2017-12-01 22:14:24 -0800 | [diff] [blame] | 4295 | // TODO(b/64750076): Check if calling pid should really be -1. |
| 4296 | final int res = mService.getActivityStartController() |
| 4297 | .obtainStarter(destIntent, "navigateUpTo") |
Wale Ogunwale | 9e4f3e0 | 2018-05-17 09:35:39 -0700 | [diff] [blame] | 4298 | .setCaller(srec.app.getThread()) |
Bryce Lee | 4c9a597 | 2017-12-01 22:14:24 -0800 | [diff] [blame] | 4299 | .setActivityInfo(aInfo) |
| 4300 | .setResultTo(parent.appToken) |
| 4301 | .setCallingPid(-1) |
| 4302 | .setCallingUid(parent.launchedFromUid) |
| 4303 | .setCallingPackage(parent.launchedFromPackage) |
| 4304 | .setRealCallingPid(-1) |
| 4305 | .setRealCallingUid(parent.launchedFromUid) |
| 4306 | .setComponentSpecified(true) |
| 4307 | .execute(); |
Craig Mautner | 05d6272ba | 2013-02-11 09:39:27 -0800 | [diff] [blame] | 4308 | foundParentInTask = res == ActivityManager.START_SUCCESS; |
| 4309 | } catch (RemoteException e) { |
| 4310 | foundParentInTask = false; |
| 4311 | } |
| 4312 | requestFinishActivityLocked(parent.appToken, resultCode, |
Todd Kennedy | 539db51 | 2014-12-15 09:57:55 -0800 | [diff] [blame] | 4313 | resultData, "navigate-top", true); |
Craig Mautner | 05d6272ba | 2013-02-11 09:39:27 -0800 | [diff] [blame] | 4314 | } |
| 4315 | } |
| 4316 | Binder.restoreCallingIdentity(origId); |
| 4317 | return foundParentInTask; |
| 4318 | } |
Bryce Lee | af691c0 | 2017-03-20 14:20:22 -0700 | [diff] [blame] | 4319 | |
| 4320 | /** |
| 4321 | * Remove any state associated with the {@link ActivityRecord}. This should be called whenever |
| 4322 | * an activity moves away from the stack. |
| 4323 | */ |
| 4324 | void onActivityRemovedFromStack(ActivityRecord r) { |
Bryce Lee | 84730a0 | 2018-04-03 14:10:04 -0700 | [diff] [blame] | 4325 | removeTimeoutsForActivityLocked(r); |
| 4326 | |
| 4327 | if (mResumedActivity != null && mResumedActivity == r) { |
| 4328 | setResumedActivity(null, "onActivityRemovedFromStack"); |
Bryce Lee | af691c0 | 2017-03-20 14:20:22 -0700 | [diff] [blame] | 4329 | } |
Bryce Lee | 84730a0 | 2018-04-03 14:10:04 -0700 | [diff] [blame] | 4330 | if (mPausingActivity != null && mPausingActivity == r) { |
Bryce Lee | af691c0 | 2017-03-20 14:20:22 -0700 | [diff] [blame] | 4331 | mPausingActivity = null; |
| 4332 | } |
Bryce Lee | 84730a0 | 2018-04-03 14:10:04 -0700 | [diff] [blame] | 4333 | } |
Bryce Lee | af691c0 | 2017-03-20 14:20:22 -0700 | [diff] [blame] | 4334 | |
Bryce Lee | 84730a0 | 2018-04-03 14:10:04 -0700 | [diff] [blame] | 4335 | void onActivityAddedToStack(ActivityRecord r) { |
| 4336 | if(r.getState() == RESUMED) { |
| 4337 | setResumedActivity(r, "onActivityAddedToStack"); |
| 4338 | } |
Bryce Lee | af691c0 | 2017-03-20 14:20:22 -0700 | [diff] [blame] | 4339 | } |
| 4340 | |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 4341 | /** |
| 4342 | * Perform the common clean-up of an activity record. This is called both |
| 4343 | * as part of destroyActivityLocked() (when destroying the client-side |
| 4344 | * representation) and cleaning things up as a result of its hosting |
| 4345 | * processing going away, in which case there is no remaining client-side |
| 4346 | * state to destroy so only the cleanup here is needed. |
Craig Mautner | acebdc8 | 2015-02-24 10:53:03 -0800 | [diff] [blame] | 4347 | * |
| 4348 | * Note: Call before #removeActivityFromHistoryLocked. |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 4349 | */ |
Bryce Lee | c940660 | 2018-03-09 11:02:10 -0800 | [diff] [blame] | 4350 | private void cleanUpActivityLocked(ActivityRecord r, boolean cleanServices, boolean setState) { |
Bryce Lee | af691c0 | 2017-03-20 14:20:22 -0700 | [diff] [blame] | 4351 | onActivityRemovedFromStack(r); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 4352 | |
Wale Ogunwale | f81c1d1 | 2016-01-12 12:20:18 -0800 | [diff] [blame] | 4353 | r.deferRelaunchUntilPaused = false; |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 4354 | r.frozenBeforeDestroy = false; |
| 4355 | |
Bryce Lee | c940660 | 2018-03-09 11:02:10 -0800 | [diff] [blame] | 4356 | if (setState) { |
Wale Ogunwale | 0fc365c | 2015-05-25 19:35:42 -0700 | [diff] [blame] | 4357 | if (DEBUG_STATES) Slog.v(TAG_STATES, "Moving to DESTROYED: " + r + " (cleaning up)"); |
Bryce Lee | 7ace395 | 2018-02-16 14:34:32 -0800 | [diff] [blame] | 4358 | r.setState(DESTROYED, "cleanupActivityLocked"); |
Wale Ogunwale | 0fc365c | 2015-05-25 19:35:42 -0700 | [diff] [blame] | 4359 | 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] | 4360 | r.app = null; |
Dianne Hackborn | ce86ba8 | 2011-07-13 19:33:41 -0700 | [diff] [blame] | 4361 | } |
| 4362 | |
Bryce Lee | 4a19438 | 2017-04-04 14:32:48 -0700 | [diff] [blame] | 4363 | // Inform supervisor the activity has been removed. |
| 4364 | mStackSupervisor.cleanupActivity(r); |
| 4365 | |
Craig Mautner | 2420ead | 2013-04-01 17:13:20 -0700 | [diff] [blame] | 4366 | |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 4367 | // Remove any pending results. |
| 4368 | if (r.finishing && r.pendingResults != null) { |
| 4369 | for (WeakReference<PendingIntentRecord> apr : r.pendingResults) { |
| 4370 | PendingIntentRecord rec = apr.get(); |
| 4371 | if (rec != null) { |
Wale Ogunwale | ee6eca1 | 2018-09-19 20:37:53 -0700 | [diff] [blame] | 4372 | mService.mPendingIntentController.cancelIntentSender(rec, false); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 4373 | } |
| 4374 | } |
| 4375 | r.pendingResults = null; |
| 4376 | } |
| 4377 | |
| 4378 | if (cleanServices) { |
Craig Mautner | 2420ead | 2013-04-01 17:13:20 -0700 | [diff] [blame] | 4379 | cleanUpActivityServicesLocked(r); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 4380 | } |
| 4381 | |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 4382 | // Get rid of any pending idle timeouts. |
Dianne Hackborn | 42e620c | 2012-06-24 13:20:51 -0700 | [diff] [blame] | 4383 | removeTimeoutsForActivityLocked(r); |
Wale Ogunwale | 8fd7542 | 2016-06-24 14:20:37 -0700 | [diff] [blame] | 4384 | // Clean-up activities are no longer relaunching (e.g. app process died). Notify window |
| 4385 | // manager so it can update its bookkeeping. |
| 4386 | mWindowManager.notifyAppRelaunchesCleared(r.appToken); |
Dianne Hackborn | 42e620c | 2012-06-24 13:20:51 -0700 | [diff] [blame] | 4387 | } |
| 4388 | |
Wale Ogunwale | 5378374 | 2018-09-16 10:21:51 -0700 | [diff] [blame] | 4389 | private void removeTimeoutsForActivityLocked(ActivityRecord r) { |
Craig Mautner | f333327 | 2013-04-22 10:55:53 -0700 | [diff] [blame] | 4390 | mStackSupervisor.removeTimeoutsForActivityLocked(r); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 4391 | mHandler.removeMessages(PAUSE_TIMEOUT_MSG, r); |
Dianne Hackborn | 162bc0e | 2012-04-09 14:06:16 -0700 | [diff] [blame] | 4392 | mHandler.removeMessages(STOP_TIMEOUT_MSG, r); |
Dianne Hackborn | 0c5001d | 2011-04-12 18:16:08 -0700 | [diff] [blame] | 4393 | mHandler.removeMessages(DESTROY_TIMEOUT_MSG, r); |
Dianne Hackborn | 2a29b3a | 2012-03-15 15:48:38 -0700 | [diff] [blame] | 4394 | r.finishLaunchTickingLocked(); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 4395 | } |
| 4396 | |
Chong Zhang | bffd889 | 2016-08-08 11:16:06 -0700 | [diff] [blame] | 4397 | private void removeActivityFromHistoryLocked(ActivityRecord r, String reason) { |
Dianne Hackborn | cc5a055 | 2012-10-01 16:32:39 -0700 | [diff] [blame] | 4398 | finishActivityResultsLocked(r, Activity.RESULT_CANCELED, null); |
Wale Ogunwale | 7d70117 | 2015-03-11 15:36:30 -0700 | [diff] [blame] | 4399 | r.makeFinishingLocked(); |
Wale Ogunwale | 0fc365c | 2015-05-25 19:35:42 -0700 | [diff] [blame] | 4400 | if (DEBUG_ADD_REMOVE) Slog.i(TAG_ADD_REMOVE, |
| 4401 | "Removing activity " + r + " from stack callers=" + Debug.getCallers(5)); |
| 4402 | |
Dianne Hackborn | cc5a055 | 2012-10-01 16:32:39 -0700 | [diff] [blame] | 4403 | r.takeFromHistory(); |
| 4404 | removeTimeoutsForActivityLocked(r); |
Wale Ogunwale | 0fc365c | 2015-05-25 19:35:42 -0700 | [diff] [blame] | 4405 | if (DEBUG_STATES) Slog.v(TAG_STATES, |
| 4406 | "Moving to DESTROYED: " + r + " (removed from history)"); |
Bryce Lee | 7ace395 | 2018-02-16 14:34:32 -0800 | [diff] [blame] | 4407 | r.setState(DESTROYED, "removeActivityFromHistoryLocked"); |
Wale Ogunwale | 0fc365c | 2015-05-25 19:35:42 -0700 | [diff] [blame] | 4408 | 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] | 4409 | r.app = null; |
Wale Ogunwale | 26c0dfe | 2016-12-14 14:42:30 -0800 | [diff] [blame] | 4410 | r.removeWindowContainer(); |
Wale Ogunwale | 8b19de9 | 2018-11-29 19:58:26 -0800 | [diff] [blame] | 4411 | final TaskRecord task = r.getTaskRecord(); |
Bryce Lee | aa5e8c3 | 2017-03-01 16:01:06 -0800 | [diff] [blame] | 4412 | final boolean lastActivity = task != null ? task.removeActivity(r) : false; |
Winson Chung | 6954fc9 | 2017-03-24 16:22:12 -0700 | [diff] [blame] | 4413 | // If we are removing the last activity in the task, not including task overlay activities, |
| 4414 | // then fall through into the block below to remove the entire task itself |
| 4415 | final boolean onlyHasTaskOverlays = task != null |
| 4416 | ? task.onlyHasTaskOverlayActivities(false /* excludingFinishing */) : false; |
Bryce Lee | aa5e8c3 | 2017-03-01 16:01:06 -0800 | [diff] [blame] | 4417 | |
Winson Chung | 6954fc9 | 2017-03-24 16:22:12 -0700 | [diff] [blame] | 4418 | if (lastActivity || onlyHasTaskOverlays) { |
| 4419 | if (DEBUG_STACK) { |
| 4420 | Slog.i(TAG_STACK, |
| 4421 | "removeActivityFromHistoryLocked: last activity removed from " + this |
| 4422 | + " onlyHasTaskOverlays=" + onlyHasTaskOverlays); |
| 4423 | } |
| 4424 | |
Bryce Lee | d6d2675 | 2017-05-25 13:57:46 -0700 | [diff] [blame] | 4425 | // The following block can be executed multiple times if there is more than one overlay. |
| 4426 | // {@link ActivityStackSupervisor#removeTaskByIdLocked} handles this by reverse lookup |
| 4427 | // of the task by id and exiting early if not found. |
Winson Chung | e3c21e0 | 2017-04-11 18:02:17 -0700 | [diff] [blame] | 4428 | if (onlyHasTaskOverlays) { |
| 4429 | // When destroying a task, tell the supervisor to remove it so that any activity it |
| 4430 | // has can be cleaned up correctly. This is currently the only place where we remove |
| 4431 | // a task with the DESTROYING mode, so instead of passing the onlyHasTaskOverlays |
| 4432 | // state into removeTask(), we just clear the task here before the other residual |
| 4433 | // work. |
| 4434 | // TODO: If the callers to removeTask() changes such that we have multiple places |
| 4435 | // where we are destroying the task, move this back into removeTask() |
| 4436 | mStackSupervisor.removeTaskByIdLocked(task.taskId, false /* killProcess */, |
Winson Chung | 0ec2a35 | 2017-10-26 11:38:30 -0700 | [diff] [blame] | 4437 | !REMOVE_FROM_RECENTS, PAUSE_IMMEDIATELY, reason); |
Winson Chung | e3c21e0 | 2017-04-11 18:02:17 -0700 | [diff] [blame] | 4438 | } |
Bryce Lee | 1d93058 | 2017-05-01 08:35:24 -0700 | [diff] [blame] | 4439 | |
Bryce Lee | d6d2675 | 2017-05-25 13:57:46 -0700 | [diff] [blame] | 4440 | // We must keep the task around until all activities are destroyed. The following |
| 4441 | // statement will only execute once since overlays are also considered activities. |
Bryce Lee | 1d93058 | 2017-05-01 08:35:24 -0700 | [diff] [blame] | 4442 | if (lastActivity) { |
| 4443 | removeTask(task, reason, REMOVE_TASK_MODE_DESTROYING); |
| 4444 | } |
Craig Mautner | 312ba86 | 2014-02-10 17:55:01 -0800 | [diff] [blame] | 4445 | } |
Dianne Hackborn | cc5a055 | 2012-10-01 16:32:39 -0700 | [diff] [blame] | 4446 | cleanUpActivityServicesLocked(r); |
| 4447 | r.removeUriPermissionsLocked(); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 4448 | } |
Craig Mautner | dbcb31f | 2013-04-02 12:32:53 -0700 | [diff] [blame] | 4449 | |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 4450 | /** |
| 4451 | * Perform clean-up of service connections in an activity record. |
| 4452 | */ |
Andrii Kulian | 21713ac | 2016-10-12 22:05:05 -0700 | [diff] [blame] | 4453 | private void cleanUpActivityServicesLocked(ActivityRecord r) { |
Wale Ogunwale | c4e63a4 | 2018-10-02 13:19:54 -0700 | [diff] [blame] | 4454 | if (r.mServiceConnectionsHolder == null) { |
| 4455 | return; |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 4456 | } |
Wale Ogunwale | c4e63a4 | 2018-10-02 13:19:54 -0700 | [diff] [blame] | 4457 | // Throw away any services that have been bound by this activity. |
| 4458 | r.mServiceConnectionsHolder.disconnectActivityFromServices(); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 4459 | } |
Dianne Hackborn | 755c8bf | 2012-05-07 15:06:09 -0700 | [diff] [blame] | 4460 | |
Wale Ogunwale | 9e4f3e0 | 2018-05-17 09:35:39 -0700 | [diff] [blame] | 4461 | final void scheduleDestroyActivities(WindowProcessController owner, String reason) { |
Dianne Hackborn | 755c8bf | 2012-05-07 15:06:09 -0700 | [diff] [blame] | 4462 | Message msg = mHandler.obtainMessage(DESTROY_ACTIVITIES_MSG); |
Craig Mautner | ee2e45a | 2014-06-27 12:10:03 -0700 | [diff] [blame] | 4463 | msg.obj = new ScheduleDestroyArgs(owner, reason); |
Dianne Hackborn | 755c8bf | 2012-05-07 15:06:09 -0700 | [diff] [blame] | 4464 | mHandler.sendMessage(msg); |
| 4465 | } |
| 4466 | |
Wale Ogunwale | 9e4f3e0 | 2018-05-17 09:35:39 -0700 | [diff] [blame] | 4467 | private void destroyActivitiesLocked(WindowProcessController owner, String reason) { |
Dianne Hackborn | 755c8bf | 2012-05-07 15:06:09 -0700 | [diff] [blame] | 4468 | boolean lastIsOpaque = false; |
Dianne Hackborn | 42e620c | 2012-06-24 13:20:51 -0700 | [diff] [blame] | 4469 | boolean activityRemoved = false; |
Craig Mautner | d44711d | 2013-02-23 11:24:36 -0800 | [diff] [blame] | 4470 | for (int taskNdx = mTaskHistory.size() - 1; taskNdx >= 0; --taskNdx) { |
| 4471 | final ArrayList<ActivityRecord> activities = mTaskHistory.get(taskNdx).mActivities; |
| 4472 | for (int activityNdx = activities.size() - 1; activityNdx >= 0; --activityNdx) { |
| 4473 | final ActivityRecord r = activities.get(activityNdx); |
| 4474 | if (r.finishing) { |
| 4475 | continue; |
| 4476 | } |
| 4477 | if (r.fullscreen) { |
| 4478 | lastIsOpaque = true; |
| 4479 | } |
| 4480 | if (owner != null && r.app != owner) { |
| 4481 | continue; |
| 4482 | } |
| 4483 | if (!lastIsOpaque) { |
| 4484 | continue; |
| 4485 | } |
Dianne Hackborn | 89ad456 | 2014-08-24 16:45:38 -0700 | [diff] [blame] | 4486 | if (r.isDestroyable()) { |
Bryce Lee | 7ace395 | 2018-02-16 14:34:32 -0800 | [diff] [blame] | 4487 | if (DEBUG_SWITCH) Slog.v(TAG_SWITCH, "Destroying " + r |
| 4488 | + " in state " + r.getState() |
Craig Mautner | d44711d | 2013-02-23 11:24:36 -0800 | [diff] [blame] | 4489 | + " resumed=" + mResumedActivity |
Dianne Hackborn | 89ad456 | 2014-08-24 16:45:38 -0700 | [diff] [blame] | 4490 | + " pausing=" + mPausingActivity + " for reason " + reason); |
Craig Mautner | ee2e45a | 2014-06-27 12:10:03 -0700 | [diff] [blame] | 4491 | if (destroyActivityLocked(r, true, reason)) { |
Craig Mautner | d44711d | 2013-02-23 11:24:36 -0800 | [diff] [blame] | 4492 | activityRemoved = true; |
| 4493 | } |
Dianne Hackborn | 42e620c | 2012-06-24 13:20:51 -0700 | [diff] [blame] | 4494 | } |
Dianne Hackborn | ce86ba8 | 2011-07-13 19:33:41 -0700 | [diff] [blame] | 4495 | } |
| 4496 | } |
Dianne Hackborn | 42e620c | 2012-06-24 13:20:51 -0700 | [diff] [blame] | 4497 | if (activityRemoved) { |
Wale Ogunwale | d32da47 | 2018-11-16 07:19:28 -0800 | [diff] [blame] | 4498 | mRootActivityContainer.resumeFocusedStacksTopActivities(); |
Dianne Hackborn | 42e620c | 2012-06-24 13:20:51 -0700 | [diff] [blame] | 4499 | } |
Dianne Hackborn | ce86ba8 | 2011-07-13 19:33:41 -0700 | [diff] [blame] | 4500 | } |
| 4501 | |
Dianne Hackborn | 89ad456 | 2014-08-24 16:45:38 -0700 | [diff] [blame] | 4502 | final boolean safelyDestroyActivityLocked(ActivityRecord r, String reason) { |
| 4503 | if (r.isDestroyable()) { |
Wale Ogunwale | ee006da | 2015-03-30 14:49:25 -0700 | [diff] [blame] | 4504 | if (DEBUG_SWITCH) Slog.v(TAG_SWITCH, |
Bryce Lee | 7ace395 | 2018-02-16 14:34:32 -0800 | [diff] [blame] | 4505 | "Destroying " + r + " in state " + r.getState() + " resumed=" + mResumedActivity |
Dianne Hackborn | 89ad456 | 2014-08-24 16:45:38 -0700 | [diff] [blame] | 4506 | + " pausing=" + mPausingActivity + " for reason " + reason); |
| 4507 | return destroyActivityLocked(r, true, reason); |
| 4508 | } |
| 4509 | return false; |
| 4510 | } |
| 4511 | |
Wale Ogunwale | 9e4f3e0 | 2018-05-17 09:35:39 -0700 | [diff] [blame] | 4512 | final int releaseSomeActivitiesLocked(WindowProcessController app, ArraySet<TaskRecord> tasks, |
Dianne Hackborn | 89ad456 | 2014-08-24 16:45:38 -0700 | [diff] [blame] | 4513 | String reason) { |
| 4514 | // Iterate over tasks starting at the back (oldest) first. |
Wale Ogunwale | 0fc365c | 2015-05-25 19:35:42 -0700 | [diff] [blame] | 4515 | 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] | 4516 | int maxTasks = tasks.size() / 4; |
| 4517 | if (maxTasks < 1) { |
| 4518 | maxTasks = 1; |
| 4519 | } |
| 4520 | int numReleased = 0; |
| 4521 | for (int taskNdx = 0; taskNdx < mTaskHistory.size() && maxTasks > 0; taskNdx++) { |
| 4522 | final TaskRecord task = mTaskHistory.get(taskNdx); |
| 4523 | if (!tasks.contains(task)) { |
| 4524 | continue; |
| 4525 | } |
Wale Ogunwale | 0fc365c | 2015-05-25 19:35:42 -0700 | [diff] [blame] | 4526 | 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] | 4527 | int curNum = 0; |
| 4528 | final ArrayList<ActivityRecord> activities = task.mActivities; |
| 4529 | for (int actNdx = 0; actNdx < activities.size(); actNdx++) { |
| 4530 | final ActivityRecord activity = activities.get(actNdx); |
| 4531 | if (activity.app == app && activity.isDestroyable()) { |
Wale Ogunwale | 0fc365c | 2015-05-25 19:35:42 -0700 | [diff] [blame] | 4532 | if (DEBUG_RELEASE) Slog.v(TAG_RELEASE, "Destroying " + activity |
Bryce Lee | 7ace395 | 2018-02-16 14:34:32 -0800 | [diff] [blame] | 4533 | + " in state " + activity.getState() + " resumed=" + mResumedActivity |
Dianne Hackborn | 89ad456 | 2014-08-24 16:45:38 -0700 | [diff] [blame] | 4534 | + " pausing=" + mPausingActivity + " for reason " + reason); |
| 4535 | destroyActivityLocked(activity, true, reason); |
| 4536 | if (activities.get(actNdx) != activity) { |
| 4537 | // Was removed from list, back up so we don't miss the next one. |
| 4538 | actNdx--; |
| 4539 | } |
| 4540 | curNum++; |
| 4541 | } |
| 4542 | } |
| 4543 | if (curNum > 0) { |
| 4544 | numReleased += curNum; |
| 4545 | maxTasks--; |
| 4546 | if (mTaskHistory.get(taskNdx) != task) { |
| 4547 | // The entire task got removed, back up so we don't miss the next one. |
| 4548 | taskNdx--; |
| 4549 | } |
| 4550 | } |
| 4551 | } |
Wale Ogunwale | 0fc365c | 2015-05-25 19:35:42 -0700 | [diff] [blame] | 4552 | if (DEBUG_RELEASE) Slog.d(TAG_RELEASE, |
| 4553 | "Done releasing: did " + numReleased + " activities"); |
Dianne Hackborn | 89ad456 | 2014-08-24 16:45:38 -0700 | [diff] [blame] | 4554 | return numReleased; |
| 4555 | } |
| 4556 | |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 4557 | /** |
| 4558 | * Destroy the current CLIENT SIDE instance of an activity. This may be |
| 4559 | * called both when actually finishing an activity, or when performing |
| 4560 | * a configuration switch where we destroy the current client-side object |
| 4561 | * but then create a new client-side object for this same HistoryRecord. |
| 4562 | */ |
Craig Mautner | ee2e45a | 2014-06-27 12:10:03 -0700 | [diff] [blame] | 4563 | final boolean destroyActivityLocked(ActivityRecord r, boolean removeFromApp, String reason) { |
Wale Ogunwale | ee006da | 2015-03-30 14:49:25 -0700 | [diff] [blame] | 4564 | if (DEBUG_SWITCH || DEBUG_CLEANUP) Slog.v(TAG_SWITCH, |
| 4565 | "Removing activity from " + reason + ": token=" + r |
Wale Ogunwale | 9e4f3e0 | 2018-05-17 09:35:39 -0700 | [diff] [blame] | 4566 | + ", app=" + (r.hasProcess() ? r.app.mName : "(null)")); |
Bryce Lee | b0f993f | 2018-03-02 15:38:01 -0800 | [diff] [blame] | 4567 | |
| 4568 | if (r.isState(DESTROYING, DESTROYED)) { |
Bryce Lee | c940660 | 2018-03-09 11:02:10 -0800 | [diff] [blame] | 4569 | if (DEBUG_STATES) Slog.v(TAG_STATES, "activity " + r + " already destroying." |
Bryce Lee | b0f993f | 2018-03-02 15:38:01 -0800 | [diff] [blame] | 4570 | + "skipping request with reason:" + reason); |
| 4571 | return false; |
| 4572 | } |
| 4573 | |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 4574 | EventLog.writeEvent(EventLogTags.AM_DESTROY_ACTIVITY, |
Wale Ogunwale | 8b19de9 | 2018-11-29 19:58:26 -0800 | [diff] [blame] | 4575 | r.mUserId, System.identityHashCode(r), |
| 4576 | r.getTaskRecord().taskId, r.shortComponentName, reason); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 4577 | |
| 4578 | boolean removedFromHistory = false; |
Dianne Hackborn | cc5a055 | 2012-10-01 16:32:39 -0700 | [diff] [blame] | 4579 | |
Bryce Lee | c940660 | 2018-03-09 11:02:10 -0800 | [diff] [blame] | 4580 | cleanUpActivityLocked(r, false, false); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 4581 | |
Wale Ogunwale | 9e4f3e0 | 2018-05-17 09:35:39 -0700 | [diff] [blame] | 4582 | final boolean hadApp = r.hasProcess(); |
Dianne Hackborn | cc5a055 | 2012-10-01 16:32:39 -0700 | [diff] [blame] | 4583 | |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 4584 | if (hadApp) { |
| 4585 | if (removeFromApp) { |
Wale Ogunwale | 9e4f3e0 | 2018-05-17 09:35:39 -0700 | [diff] [blame] | 4586 | r.app.removeActivity(r); |
Wale Ogunwale | 5378374 | 2018-09-16 10:21:51 -0700 | [diff] [blame] | 4587 | if (!r.app.hasActivities()) { |
| 4588 | mService.clearHeavyWeightProcessIfEquals(r.app); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 4589 | } |
Wale Ogunwale | 9e4f3e0 | 2018-05-17 09:35:39 -0700 | [diff] [blame] | 4590 | if (!r.app.hasActivities()) { |
Dianne Hackborn | 465fa39 | 2014-09-14 14:21:18 -0700 | [diff] [blame] | 4591 | // Update any services we are bound to that might care about whether |
| 4592 | // their client may have activities. |
Dianne Hackborn | 3bc8f78d | 2013-09-19 13:34:35 -0700 | [diff] [blame] | 4593 | // No longer have activities, so update LRU list and oom adj. |
Wale Ogunwale | 9e4f3e0 | 2018-05-17 09:35:39 -0700 | [diff] [blame] | 4594 | r.app.updateProcessInfo(true, true, false, true); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 4595 | } |
| 4596 | } |
| 4597 | |
| 4598 | boolean skipDestroy = false; |
Craig Mautner | dbcb31f | 2013-04-02 12:32:53 -0700 | [diff] [blame] | 4599 | |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 4600 | try { |
Wale Ogunwale | ee006da | 2015-03-30 14:49:25 -0700 | [diff] [blame] | 4601 | if (DEBUG_SWITCH) Slog.i(TAG_SWITCH, "Destroying: " + r); |
Wale Ogunwale | 9e4f3e0 | 2018-05-17 09:35:39 -0700 | [diff] [blame] | 4602 | mService.getLifecycleManager().scheduleTransaction(r.app.getThread(), r.appToken, |
Bryce Lee | 1d0d514 | 2018-04-12 10:35:07 -0700 | [diff] [blame] | 4603 | DestroyActivityItem.obtain(r.finishing, r.configChangeFlags)); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 4604 | } catch (Exception e) { |
| 4605 | // We can just ignore exceptions here... if the process |
| 4606 | // has crashed, our death notification will clean things |
| 4607 | // up. |
| 4608 | //Slog.w(TAG, "Exception thrown during finish", e); |
| 4609 | if (r.finishing) { |
Chong Zhang | bffd889 | 2016-08-08 11:16:06 -0700 | [diff] [blame] | 4610 | removeActivityFromHistoryLocked(r, reason + " exceptionInScheduleDestroy"); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 4611 | removedFromHistory = true; |
| 4612 | skipDestroy = true; |
| 4613 | } |
| 4614 | } |
| 4615 | |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 4616 | r.nowVisible = false; |
Craig Mautner | dbcb31f | 2013-04-02 12:32:53 -0700 | [diff] [blame] | 4617 | |
Dianne Hackborn | ce86ba8 | 2011-07-13 19:33:41 -0700 | [diff] [blame] | 4618 | // If the activity is finishing, we need to wait on removing it |
| 4619 | // from the list to give it a chance to do its cleanup. During |
| 4620 | // that time it may make calls back with its token so we need to |
| 4621 | // be able to find it on the list and so we don't want to remove |
| 4622 | // it from the list yet. Otherwise, we can just immediately put |
| 4623 | // it in the destroyed state since we are not removing it from the |
| 4624 | // list. |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 4625 | if (r.finishing && !skipDestroy) { |
Wale Ogunwale | 0fc365c | 2015-05-25 19:35:42 -0700 | [diff] [blame] | 4626 | if (DEBUG_STATES) Slog.v(TAG_STATES, "Moving to DESTROYING: " + r |
Dianne Hackborn | ce86ba8 | 2011-07-13 19:33:41 -0700 | [diff] [blame] | 4627 | + " (destroy requested)"); |
Bryce Lee | 7ace395 | 2018-02-16 14:34:32 -0800 | [diff] [blame] | 4628 | r.setState(DESTROYING, |
| 4629 | "destroyActivityLocked. finishing and not skipping destroy"); |
Craig Mautner | f7bfefb | 2013-05-16 17:30:44 -0700 | [diff] [blame] | 4630 | Message msg = mHandler.obtainMessage(DESTROY_TIMEOUT_MSG, r); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 4631 | mHandler.sendMessageDelayed(msg, DESTROY_TIMEOUT); |
| 4632 | } else { |
Wale Ogunwale | 0fc365c | 2015-05-25 19:35:42 -0700 | [diff] [blame] | 4633 | if (DEBUG_STATES) Slog.v(TAG_STATES, |
| 4634 | "Moving to DESTROYED: " + r + " (destroy skipped)"); |
Bryce Lee | 7ace395 | 2018-02-16 14:34:32 -0800 | [diff] [blame] | 4635 | r.setState(DESTROYED, |
| 4636 | "destroyActivityLocked. not finishing or skipping destroy"); |
Wale Ogunwale | 0fc365c | 2015-05-25 19:35:42 -0700 | [diff] [blame] | 4637 | 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] | 4638 | r.app = null; |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 4639 | } |
| 4640 | } else { |
| 4641 | // remove this record from the history. |
| 4642 | if (r.finishing) { |
Chong Zhang | bffd889 | 2016-08-08 11:16:06 -0700 | [diff] [blame] | 4643 | removeActivityFromHistoryLocked(r, reason + " hadNoApp"); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 4644 | removedFromHistory = true; |
| 4645 | } else { |
Wale Ogunwale | 0fc365c | 2015-05-25 19:35:42 -0700 | [diff] [blame] | 4646 | if (DEBUG_STATES) Slog.v(TAG_STATES, "Moving to DESTROYED: " + r + " (no app)"); |
Bryce Lee | 7ace395 | 2018-02-16 14:34:32 -0800 | [diff] [blame] | 4647 | r.setState(DESTROYED, "destroyActivityLocked. not finishing and had no app"); |
Wale Ogunwale | 0fc365c | 2015-05-25 19:35:42 -0700 | [diff] [blame] | 4648 | 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] | 4649 | r.app = null; |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 4650 | } |
| 4651 | } |
| 4652 | |
| 4653 | r.configChangeFlags = 0; |
Craig Mautner | dbcb31f | 2013-04-02 12:32:53 -0700 | [diff] [blame] | 4654 | |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 4655 | if (!mLRUActivities.remove(r) && hadApp) { |
| 4656 | Slog.w(TAG, "Activity " + r + " being finished, but not in LRU list"); |
| 4657 | } |
Craig Mautner | dbcb31f | 2013-04-02 12:32:53 -0700 | [diff] [blame] | 4658 | |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 4659 | return removedFromHistory; |
| 4660 | } |
| 4661 | |
Craig Mautner | 299f960 | 2015-01-26 09:47:33 -0800 | [diff] [blame] | 4662 | final void activityDestroyedLocked(IBinder token, String reason) { |
Craig Mautner | d232895 | 2013-03-05 12:46:26 -0800 | [diff] [blame] | 4663 | final long origId = Binder.clearCallingIdentity(); |
| 4664 | try { |
Bryce Lee | 7ace395 | 2018-02-16 14:34:32 -0800 | [diff] [blame] | 4665 | activityDestroyedLocked(ActivityRecord.forTokenLocked(token), reason); |
Craig Mautner | d232895 | 2013-03-05 12:46:26 -0800 | [diff] [blame] | 4666 | } finally { |
| 4667 | Binder.restoreCallingIdentity(origId); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 4668 | } |
| 4669 | } |
Craig Mautner | de4ef02 | 2013-04-07 19:01:33 -0700 | [diff] [blame] | 4670 | |
Bryce Lee | c940660 | 2018-03-09 11:02:10 -0800 | [diff] [blame] | 4671 | /** |
| 4672 | * This method is to only be called from the client via binder when the activity is destroyed |
| 4673 | * AND finished. |
| 4674 | */ |
Bryce Lee | 7ace395 | 2018-02-16 14:34:32 -0800 | [diff] [blame] | 4675 | final void activityDestroyedLocked(ActivityRecord record, String reason) { |
| 4676 | if (record != null) { |
| 4677 | mHandler.removeMessages(DESTROY_TIMEOUT_MSG, record); |
| 4678 | } |
| 4679 | |
| 4680 | if (DEBUG_CONTAINERS) Slog.d(TAG_CONTAINERS, "activityDestroyedLocked: r=" + record); |
| 4681 | |
| 4682 | if (isInStackLocked(record) != null) { |
| 4683 | if (record.isState(DESTROYING, DESTROYED)) { |
Bryce Lee | c940660 | 2018-03-09 11:02:10 -0800 | [diff] [blame] | 4684 | cleanUpActivityLocked(record, true, false); |
Bryce Lee | 7ace395 | 2018-02-16 14:34:32 -0800 | [diff] [blame] | 4685 | removeActivityFromHistoryLocked(record, reason); |
| 4686 | } |
| 4687 | } |
| 4688 | |
Wale Ogunwale | d32da47 | 2018-11-16 07:19:28 -0800 | [diff] [blame] | 4689 | mRootActivityContainer.resumeFocusedStacksTopActivities(); |
Bryce Lee | 7ace395 | 2018-02-16 14:34:32 -0800 | [diff] [blame] | 4690 | } |
| 4691 | |
Craig Mautner | 05d6272ba | 2013-02-11 09:39:27 -0800 | [diff] [blame] | 4692 | private void removeHistoryRecordsForAppLocked(ArrayList<ActivityRecord> list, |
Wale Ogunwale | 9e4f3e0 | 2018-05-17 09:35:39 -0700 | [diff] [blame] | 4693 | WindowProcessController app, String listName) { |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 4694 | int i = list.size(); |
Wale Ogunwale | e23149f | 2015-03-06 15:39:44 -0800 | [diff] [blame] | 4695 | if (DEBUG_CLEANUP) Slog.v(TAG_CLEANUP, |
| 4696 | "Removing app " + app + " from list " + listName + " with " + i + " entries"); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 4697 | while (i > 0) { |
| 4698 | i--; |
Craig Mautner | 05d6272ba | 2013-02-11 09:39:27 -0800 | [diff] [blame] | 4699 | ActivityRecord r = list.get(i); |
Wale Ogunwale | e23149f | 2015-03-06 15:39:44 -0800 | [diff] [blame] | 4700 | if (DEBUG_CLEANUP) Slog.v(TAG_CLEANUP, "Record #" + i + " " + r); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 4701 | if (r.app == app) { |
Wale Ogunwale | e23149f | 2015-03-06 15:39:44 -0800 | [diff] [blame] | 4702 | if (DEBUG_CLEANUP) Slog.v(TAG_CLEANUP, "---> REMOVING this entry!"); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 4703 | list.remove(i); |
Dianne Hackborn | 42e620c | 2012-06-24 13:20:51 -0700 | [diff] [blame] | 4704 | removeTimeoutsForActivityLocked(r); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 4705 | } |
| 4706 | } |
| 4707 | } |
| 4708 | |
Wale Ogunwale | 9e4f3e0 | 2018-05-17 09:35:39 -0700 | [diff] [blame] | 4709 | private boolean removeHistoryRecordsForAppLocked(WindowProcessController app) { |
Dianne Hackborn | cc5a055 | 2012-10-01 16:32:39 -0700 | [diff] [blame] | 4710 | removeHistoryRecordsForAppLocked(mLRUActivities, app, "mLRUActivities"); |
Craig Mautner | de4ef02 | 2013-04-07 19:01:33 -0700 | [diff] [blame] | 4711 | removeHistoryRecordsForAppLocked(mStackSupervisor.mStoppingActivities, app, |
| 4712 | "mStoppingActivities"); |
Craig Mautner | 0eea92c | 2013-05-16 13:35:39 -0700 | [diff] [blame] | 4713 | removeHistoryRecordsForAppLocked(mStackSupervisor.mGoingToSleepActivities, app, |
| 4714 | "mGoingToSleepActivities"); |
Craig Mautner | f333327 | 2013-04-22 10:55:53 -0700 | [diff] [blame] | 4715 | removeHistoryRecordsForAppLocked(mStackSupervisor.mFinishingActivities, app, |
| 4716 | "mFinishingActivities"); |
Dianne Hackborn | cc5a055 | 2012-10-01 16:32:39 -0700 | [diff] [blame] | 4717 | |
Riddle Hsu | aaef731 | 2019-01-24 19:00:58 +0800 | [diff] [blame] | 4718 | final boolean isProcessRemoved = app.isRemoved(); |
| 4719 | if (isProcessRemoved) { |
| 4720 | // The package of the died process should be force-stopped, so make its activities as |
| 4721 | // finishing to prevent the process from being started again if the next top (or being |
| 4722 | // visible) activity also resides in the same process. |
| 4723 | app.makeFinishingForProcessRemoved(); |
| 4724 | } |
| 4725 | |
Dianne Hackborn | cc5a055 | 2012-10-01 16:32:39 -0700 | [diff] [blame] | 4726 | boolean hasVisibleActivities = false; |
| 4727 | |
| 4728 | // Clean out the history list. |
Craig Mautner | 0247fc8 | 2013-02-28 14:32:06 -0800 | [diff] [blame] | 4729 | int i = numActivities(); |
Wale Ogunwale | e23149f | 2015-03-06 15:39:44 -0800 | [diff] [blame] | 4730 | if (DEBUG_CLEANUP) Slog.v(TAG_CLEANUP, |
| 4731 | "Removing app " + app + " from history with " + i + " entries"); |
Craig Mautner | 0247fc8 | 2013-02-28 14:32:06 -0800 | [diff] [blame] | 4732 | for (int taskNdx = mTaskHistory.size() - 1; taskNdx >= 0; --taskNdx) { |
| 4733 | final ArrayList<ActivityRecord> activities = mTaskHistory.get(taskNdx).mActivities; |
Bryce Lee | fbd263b4 | 2018-03-07 10:33:55 -0800 | [diff] [blame] | 4734 | mTmpActivities.clear(); |
| 4735 | mTmpActivities.addAll(activities); |
| 4736 | |
| 4737 | while (!mTmpActivities.isEmpty()) { |
| 4738 | final int targetIndex = mTmpActivities.size() - 1; |
| 4739 | final ActivityRecord r = mTmpActivities.remove(targetIndex); |
Wale Ogunwale | e23149f | 2015-03-06 15:39:44 -0800 | [diff] [blame] | 4740 | if (DEBUG_CLEANUP) Slog.v(TAG_CLEANUP, |
Bryce Lee | fbd263b4 | 2018-03-07 10:33:55 -0800 | [diff] [blame] | 4741 | "Record #" + targetIndex + " " + r + ": app=" + r.app); |
| 4742 | |
Craig Mautner | 0247fc8 | 2013-02-28 14:32:06 -0800 | [diff] [blame] | 4743 | if (r.app == app) { |
riddle_hsu | 558e849 | 2015-04-02 16:43:13 +0800 | [diff] [blame] | 4744 | if (r.visible) { |
| 4745 | hasVisibleActivities = true; |
| 4746 | } |
Craig Mautner | acebdc8 | 2015-02-24 10:53:03 -0800 | [diff] [blame] | 4747 | final boolean remove; |
Garfield Tan | 2746ab5 | 2018-07-25 12:33:01 -0700 | [diff] [blame] | 4748 | if ((r.mRelaunchReason == RELAUNCH_REASON_WINDOWING_MODE_RESIZE |
| 4749 | || r.mRelaunchReason == RELAUNCH_REASON_FREE_RESIZE) |
| 4750 | && r.launchCount < 3 && !r.finishing) { |
| 4751 | // If the process crashed during a resize, always try to relaunch it, unless |
| 4752 | // it has failed more than twice. Skip activities that's already finishing |
| 4753 | // cleanly by itself. |
| 4754 | remove = false; |
Riddle Hsu | 7b766fd | 2019-01-28 21:14:59 +0800 | [diff] [blame] | 4755 | } else if ((!r.haveState && !r.stateNotNeeded |
| 4756 | && !r.isState(ActivityState.RESTARTING_PROCESS)) || r.finishing) { |
Craig Mautner | 0247fc8 | 2013-02-28 14:32:06 -0800 | [diff] [blame] | 4757 | // Don't currently have state for the activity, or |
| 4758 | // it is finishing -- always remove it. |
| 4759 | remove = true; |
Chong Zhang | 112eb8c | 2015-11-02 11:17:00 -0800 | [diff] [blame] | 4760 | } else if (!r.visible && r.launchCount > 2 && |
| 4761 | r.lastLaunchTime > (SystemClock.uptimeMillis() - 60000)) { |
Craig Mautner | 0247fc8 | 2013-02-28 14:32:06 -0800 | [diff] [blame] | 4762 | // We have launched this activity too many times since it was |
| 4763 | // able to run, so give up and remove it. |
Chong Zhang | 112eb8c | 2015-11-02 11:17:00 -0800 | [diff] [blame] | 4764 | // (Note if the activity is visible, we don't remove the record. |
| 4765 | // We leave the dead window on the screen but the process will |
| 4766 | // not be restarted unless user explicitly tap on it.) |
Craig Mautner | 0247fc8 | 2013-02-28 14:32:06 -0800 | [diff] [blame] | 4767 | remove = true; |
| 4768 | } else { |
| 4769 | // The process may be gone, but the activity lives on! |
| 4770 | remove = false; |
Dianne Hackborn | cc5a055 | 2012-10-01 16:32:39 -0700 | [diff] [blame] | 4771 | } |
Craig Mautner | 0247fc8 | 2013-02-28 14:32:06 -0800 | [diff] [blame] | 4772 | if (remove) { |
Wale Ogunwale | 0fc365c | 2015-05-25 19:35:42 -0700 | [diff] [blame] | 4773 | if (DEBUG_ADD_REMOVE || DEBUG_CLEANUP) Slog.i(TAG_ADD_REMOVE, |
| 4774 | "Removing activity " + r + " from stack at " + i |
| 4775 | + ": haveState=" + r.haveState |
| 4776 | + " stateNotNeeded=" + r.stateNotNeeded |
| 4777 | + " finishing=" + r.finishing |
Bryce Lee | 7ace395 | 2018-02-16 14:34:32 -0800 | [diff] [blame] | 4778 | + " state=" + r.getState() + " callers=" + Debug.getCallers(5)); |
Riddle Hsu | aaef731 | 2019-01-24 19:00:58 +0800 | [diff] [blame] | 4779 | if (!r.finishing || isProcessRemoved) { |
Craig Mautner | 0247fc8 | 2013-02-28 14:32:06 -0800 | [diff] [blame] | 4780 | Slog.w(TAG, "Force removing " + r + ": app died, no saved state"); |
| 4781 | EventLog.writeEvent(EventLogTags.AM_FINISH_ACTIVITY, |
Wale Ogunwale | 8b19de9 | 2018-11-29 19:58:26 -0800 | [diff] [blame] | 4782 | r.mUserId, System.identityHashCode(r), |
| 4783 | r.getTaskRecord().taskId, r.shortComponentName, |
Craig Mautner | 0247fc8 | 2013-02-28 14:32:06 -0800 | [diff] [blame] | 4784 | "proc died without state saved"); |
| 4785 | } |
Craig Mautner | 0247fc8 | 2013-02-28 14:32:06 -0800 | [diff] [blame] | 4786 | } else { |
| 4787 | // We have the current state for this activity, so |
| 4788 | // it can be restarted later when needed. |
Wale Ogunwale | 0fc365c | 2015-05-25 19:35:42 -0700 | [diff] [blame] | 4789 | if (DEBUG_ALL) Slog.v(TAG, "Keeping entry, setting app to null"); |
| 4790 | if (DEBUG_APP) Slog.v(TAG_APP, |
| 4791 | "Clearing app during removeHistory for activity " + r); |
Craig Mautner | 0247fc8 | 2013-02-28 14:32:06 -0800 | [diff] [blame] | 4792 | r.app = null; |
Chong Zhang | 112eb8c | 2015-11-02 11:17:00 -0800 | [diff] [blame] | 4793 | // Set nowVisible to previous visible state. If the app was visible while |
| 4794 | // it died, we leave the dead window on screen so it's basically visible. |
| 4795 | // This is needed when user later tap on the dead window, we need to stop |
| 4796 | // other apps when user transfers focus to the restarted activity. |
| 4797 | r.nowVisible = r.visible; |
Craig Mautner | 0247fc8 | 2013-02-28 14:32:06 -0800 | [diff] [blame] | 4798 | if (!r.haveState) { |
Wale Ogunwale | 0fc365c | 2015-05-25 19:35:42 -0700 | [diff] [blame] | 4799 | if (DEBUG_SAVED_STATE) Slog.i(TAG_SAVED_STATE, |
Craig Mautner | 0247fc8 | 2013-02-28 14:32:06 -0800 | [diff] [blame] | 4800 | "App died, clearing saved state of " + r); |
| 4801 | r.icicle = null; |
| 4802 | } |
Dianne Hackborn | cc5a055 | 2012-10-01 16:32:39 -0700 | [diff] [blame] | 4803 | } |
Bryce Lee | c940660 | 2018-03-09 11:02:10 -0800 | [diff] [blame] | 4804 | cleanUpActivityLocked(r, true, true); |
Craig Mautner | acebdc8 | 2015-02-24 10:53:03 -0800 | [diff] [blame] | 4805 | if (remove) { |
Chong Zhang | bffd889 | 2016-08-08 11:16:06 -0700 | [diff] [blame] | 4806 | removeActivityFromHistoryLocked(r, "appDied"); |
Craig Mautner | acebdc8 | 2015-02-24 10:53:03 -0800 | [diff] [blame] | 4807 | } |
Craig Mautner | 0247fc8 | 2013-02-28 14:32:06 -0800 | [diff] [blame] | 4808 | } |
Dianne Hackborn | cc5a055 | 2012-10-01 16:32:39 -0700 | [diff] [blame] | 4809 | } |
| 4810 | } |
| 4811 | |
| 4812 | return hasVisibleActivities; |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 4813 | } |
Craig Mautner | 0247fc8 | 2013-02-28 14:32:06 -0800 | [diff] [blame] | 4814 | |
chaviw | 0d562bf | 2018-03-15 14:24:14 -0700 | [diff] [blame] | 4815 | private void updateTransitLocked(int transit, ActivityOptions options) { |
Dianne Hackborn | 7f58b95 | 2012-04-18 12:59:29 -0700 | [diff] [blame] | 4816 | if (options != null) { |
chaviw | 0d562bf | 2018-03-15 14:24:14 -0700 | [diff] [blame] | 4817 | ActivityRecord r = topRunningActivityLocked(); |
| 4818 | if (r != null && !r.isState(RESUMED)) { |
| 4819 | r.updateOptionsLocked(options); |
Dianne Hackborn | 7f58b95 | 2012-04-18 12:59:29 -0700 | [diff] [blame] | 4820 | } else { |
| 4821 | ActivityOptions.abort(options); |
| 4822 | } |
| 4823 | } |
Wale Ogunwale | 3a256e6 | 2018-12-06 14:41:18 -0800 | [diff] [blame] | 4824 | getDisplay().mDisplayContent.prepareAppTransition(transit, false); |
Dianne Hackborn | 7f58b95 | 2012-04-18 12:59:29 -0700 | [diff] [blame] | 4825 | } |
Dianne Hackborn | 621e17d | 2010-11-22 15:59:56 -0800 | [diff] [blame] | 4826 | |
Andrii Kulian | 21713ac | 2016-10-12 22:05:05 -0700 | [diff] [blame] | 4827 | private void updateTaskMovement(TaskRecord task, boolean toFront) { |
Craig Mautner | 21d24a2 | 2014-04-23 11:45:37 -0700 | [diff] [blame] | 4828 | if (task.isPersistable) { |
| 4829 | task.mLastTimeMoved = System.currentTimeMillis(); |
| 4830 | // Sign is used to keep tasks sorted when persisted. Tasks sent to the bottom most |
| 4831 | // recently will be most negative, tasks sent to the bottom before that will be less |
| 4832 | // negative. Similarly for recent tasks moved to the top which will be most positive. |
| 4833 | if (!toFront) { |
| 4834 | task.mLastTimeMoved *= -1; |
| 4835 | } |
| 4836 | } |
Wale Ogunwale | d32da47 | 2018-11-16 07:19:28 -0800 | [diff] [blame] | 4837 | mRootActivityContainer.invalidateTaskLayers(); |
Craig Mautner | 21d24a2 | 2014-04-23 11:45:37 -0700 | [diff] [blame] | 4838 | } |
| 4839 | |
chaviw | 0d562bf | 2018-03-15 14:24:14 -0700 | [diff] [blame] | 4840 | final void moveTaskToFrontLocked(TaskRecord tr, boolean noAnimation, ActivityOptions options, |
| 4841 | AppTimeTracker timeTracker, String reason) { |
Wale Ogunwale | ee006da | 2015-03-30 14:49:25 -0700 | [diff] [blame] | 4842 | if (DEBUG_SWITCH) Slog.v(TAG_SWITCH, "moveTaskToFront: " + tr); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 4843 | |
Wale Ogunwale | a0f5b5e | 2017-10-11 09:37:23 -0700 | [diff] [blame] | 4844 | final ActivityStack topStack = getDisplay().getTopStack(); |
Wale Ogunwale | 30e441d | 2017-11-09 08:28:45 -0800 | [diff] [blame] | 4845 | final ActivityRecord topActivity = topStack != null ? topStack.getTopActivity() : null; |
Craig Mautner | 11bf9a5 | 2013-02-19 14:08:51 -0800 | [diff] [blame] | 4846 | final int numTasks = mTaskHistory.size(); |
| 4847 | final int index = mTaskHistory.indexOf(tr); |
Craig Mautner | 86d67a4 | 2013-05-14 10:34:38 -0700 | [diff] [blame] | 4848 | if (numTasks == 0 || index < 0) { |
Craig Mautner | 11bf9a5 | 2013-02-19 14:08:51 -0800 | [diff] [blame] | 4849 | // nothing to do! |
Craig Mautner | 8f5f7e9 | 2015-01-26 18:03:13 -0800 | [diff] [blame] | 4850 | if (noAnimation) { |
Craig Mautner | 11bf9a5 | 2013-02-19 14:08:51 -0800 | [diff] [blame] | 4851 | ActivityOptions.abort(options); |
| 4852 | } else { |
chaviw | 0d562bf | 2018-03-15 14:24:14 -0700 | [diff] [blame] | 4853 | updateTransitLocked(TRANSIT_TASK_TO_FRONT, options); |
Craig Mautner | 11bf9a5 | 2013-02-19 14:08:51 -0800 | [diff] [blame] | 4854 | } |
| 4855 | return; |
| 4856 | } |
| 4857 | |
Dianne Hackborn | b5a380d | 2015-05-20 18:18:46 -0700 | [diff] [blame] | 4858 | if (timeTracker != null) { |
| 4859 | // The caller wants a time tracker associated with this task. |
| 4860 | for (int i = tr.mActivities.size() - 1; i >= 0; i--) { |
| 4861 | tr.mActivities.get(i).appTimeTracker = timeTracker; |
| 4862 | } |
| 4863 | } |
| 4864 | |
Chavi Weingarten | 3a74855 | 2018-05-14 17:32:42 +0000 | [diff] [blame] | 4865 | try { |
| 4866 | // Defer updating the IME target since the new IME target will try to get computed |
| 4867 | // before updating all closing and opening apps, which can cause the ime target to |
| 4868 | // get calculated incorrectly. |
| 4869 | getDisplay().deferUpdateImeTarget(); |
Wale Ogunwale | d80c263 | 2015-03-13 10:26:26 -0700 | [diff] [blame] | 4870 | |
Chavi Weingarten | 3a74855 | 2018-05-14 17:32:42 +0000 | [diff] [blame] | 4871 | // Shift all activities with this task up to the top |
| 4872 | // of the stack, keeping them in the same internal order. |
| 4873 | insertTaskAtTop(tr, null); |
| 4874 | |
| 4875 | // Don't refocus if invisible to current user |
| 4876 | final ActivityRecord top = tr.getTopActivity(); |
| 4877 | if (top == null || !top.okToShowLocked()) { |
| 4878 | if (top != null) { |
Wale Ogunwale | 8b19de9 | 2018-11-29 19:58:26 -0800 | [diff] [blame] | 4879 | mStackSupervisor.mRecentTasks.add(top.getTaskRecord()); |
Chavi Weingarten | 3a74855 | 2018-05-14 17:32:42 +0000 | [diff] [blame] | 4880 | } |
| 4881 | ActivityOptions.abort(options); |
| 4882 | return; |
Winson Chung | 1dbc811 | 2017-09-28 18:05:31 -0700 | [diff] [blame] | 4883 | } |
Chavi Weingarten | 9e875b6 | 2018-05-14 16:10:59 +0000 | [diff] [blame] | 4884 | |
Chavi Weingarten | 3a74855 | 2018-05-14 17:32:42 +0000 | [diff] [blame] | 4885 | // Set focus to the top running activity of this stack. |
| 4886 | final ActivityRecord r = topRunningActivityLocked(); |
Louis Chang | 1944345 | 2018-10-09 12:10:21 +0800 | [diff] [blame] | 4887 | if (r != null) { |
| 4888 | r.moveFocusableActivityToTop(reason); |
| 4889 | } |
Chavi Weingarten | 9e875b6 | 2018-05-14 16:10:59 +0000 | [diff] [blame] | 4890 | |
Chavi Weingarten | 3a74855 | 2018-05-14 17:32:42 +0000 | [diff] [blame] | 4891 | if (DEBUG_TRANSITION) Slog.v(TAG_TRANSITION, "Prepare to front transition: task=" + tr); |
| 4892 | if (noAnimation) { |
Wale Ogunwale | 3a256e6 | 2018-12-06 14:41:18 -0800 | [diff] [blame] | 4893 | getDisplay().mDisplayContent.prepareAppTransition(TRANSIT_NONE, false); |
Chavi Weingarten | 3a74855 | 2018-05-14 17:32:42 +0000 | [diff] [blame] | 4894 | if (r != null) { |
| 4895 | mStackSupervisor.mNoAnimActivities.add(r); |
| 4896 | } |
| 4897 | ActivityOptions.abort(options); |
| 4898 | } else { |
| 4899 | updateTransitLocked(TRANSIT_TASK_TO_FRONT, options); |
Chavi Weingarten | 9e875b6 | 2018-05-14 16:10:59 +0000 | [diff] [blame] | 4900 | } |
Chavi Weingarten | 3a74855 | 2018-05-14 17:32:42 +0000 | [diff] [blame] | 4901 | // If a new task is moved to the front, then mark the existing top activity as |
| 4902 | // supporting |
Chavi Weingarten | 9e875b6 | 2018-05-14 16:10:59 +0000 | [diff] [blame] | 4903 | |
Chavi Weingarten | 3a74855 | 2018-05-14 17:32:42 +0000 | [diff] [blame] | 4904 | // picture-in-picture while paused only if the task would not be considered an oerlay |
| 4905 | // on top |
| 4906 | // of the current activity (eg. not fullscreen, or the assistant) |
| 4907 | if (canEnterPipOnTaskSwitch(topActivity, tr, null /* toFrontActivity */, |
| 4908 | options)) { |
| 4909 | topActivity.supportsEnterPipOnTaskSwitch = true; |
| 4910 | } |
Chavi Weingarten | 9e875b6 | 2018-05-14 16:10:59 +0000 | [diff] [blame] | 4911 | |
Wale Ogunwale | d32da47 | 2018-11-16 07:19:28 -0800 | [diff] [blame] | 4912 | mRootActivityContainer.resumeFocusedStacksTopActivities(); |
Chavi Weingarten | 3a74855 | 2018-05-14 17:32:42 +0000 | [diff] [blame] | 4913 | EventLog.writeEvent(EventLogTags.AM_TASK_TO_FRONT, tr.userId, tr.taskId); |
Mark Renouf | c808f06 | 2019-02-07 15:20:37 -0500 | [diff] [blame] | 4914 | mService.getTaskChangeNotificationController().notifyTaskMovedToFront(tr.getTaskInfo()); |
Chavi Weingarten | 3a74855 | 2018-05-14 17:32:42 +0000 | [diff] [blame] | 4915 | } finally { |
| 4916 | getDisplay().continueUpdateImeTarget(); |
| 4917 | } |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 4918 | } |
| 4919 | |
| 4920 | /** |
Craig Mautner | ce5f3cb | 2013-04-22 08:58:54 -0700 | [diff] [blame] | 4921 | * Worker method for rearranging history stack. Implements the function of moving all |
| 4922 | * 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] | 4923 | * bottom of the stack. |
Craig Mautner | ce5f3cb | 2013-04-22 08:58:54 -0700 | [diff] [blame] | 4924 | * |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 4925 | * If a watcher is installed, the action is preflighted and the watcher has an opportunity |
| 4926 | * to premeptively cancel the move. |
Craig Mautner | ce5f3cb | 2013-04-22 08:58:54 -0700 | [diff] [blame] | 4927 | * |
Craig Mautner | ae7ecab | 2013-09-18 11:48:14 -0700 | [diff] [blame] | 4928 | * @param taskId The taskId to collect and move to the bottom. |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 4929 | * @return Returns true if the move completed, false if not. |
| 4930 | */ |
Craig Mautner | 299f960 | 2015-01-26 09:47:33 -0800 | [diff] [blame] | 4931 | final boolean moveTaskToBackLocked(int taskId) { |
Craig Mautner | aea74a5 | 2014-03-08 14:23:10 -0800 | [diff] [blame] | 4932 | final TaskRecord tr = taskForIdLocked(taskId); |
| 4933 | if (tr == null) { |
| 4934 | Slog.i(TAG, "moveTaskToBack: bad taskId=" + taskId); |
| 4935 | return false; |
| 4936 | } |
Craig Mautner | aea74a5 | 2014-03-08 14:23:10 -0800 | [diff] [blame] | 4937 | Slog.i(TAG, "moveTaskToBack: " + tr); |
Winson Chung | 261c0f3 | 2017-03-07 16:54:31 -0800 | [diff] [blame] | 4938 | |
Charles He | ff9b4dff | 2017-09-22 10:18:37 +0100 | [diff] [blame] | 4939 | // In LockTask mode, moving a locked task to the back of the stack may expose unlocked |
| 4940 | // ones. Therefore we need to check if this operation is allowed. |
Wale Ogunwale | 5fa8a8c | 2018-05-08 13:43:21 -0700 | [diff] [blame] | 4941 | if (!mService.getLockTaskController().canMoveTaskToBack(tr)) { |
Winson Chung | 261c0f3 | 2017-03-07 16:54:31 -0800 | [diff] [blame] | 4942 | return false; |
| 4943 | } |
Craig Mautner | b44de0d | 2013-02-21 20:00:58 -0800 | [diff] [blame] | 4944 | |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 4945 | // If we have a watcher, preflight the move before committing to it. First check |
| 4946 | // for *other* available tasks, but if none are available, then try again allowing the |
| 4947 | // current task to be selected. |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 4948 | if (isTopStackOnDisplay() && mService.mController != null) { |
Craig Mautner | ae7ecab | 2013-09-18 11:48:14 -0700 | [diff] [blame] | 4949 | ActivityRecord next = topRunningActivityLocked(null, taskId); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 4950 | if (next == null) { |
| 4951 | next = topRunningActivityLocked(null, 0); |
| 4952 | } |
| 4953 | if (next != null) { |
| 4954 | // ask watcher if this is allowed |
| 4955 | boolean moveOK = true; |
| 4956 | try { |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 4957 | moveOK = mService.mController.activityResuming(next.packageName); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 4958 | } catch (RemoteException e) { |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 4959 | mService.mController = null; |
Kenny Root | add5821 | 2013-05-07 09:47:34 -0700 | [diff] [blame] | 4960 | Watchdog.getInstance().setActivityController(null); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 4961 | } |
| 4962 | if (!moveOK) { |
| 4963 | return false; |
| 4964 | } |
| 4965 | } |
| 4966 | } |
| 4967 | |
Wale Ogunwale | ee006da | 2015-03-30 14:49:25 -0700 | [diff] [blame] | 4968 | 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] | 4969 | |
Wale Ogunwale | 66e1685 | 2017-10-19 13:35:52 -0700 | [diff] [blame] | 4970 | mTaskHistory.remove(tr); |
| 4971 | mTaskHistory.add(0, tr); |
| 4972 | updateTaskMovement(tr, false); |
Wale Ogunwale | 4270924 | 2015-08-11 13:54:42 -0700 | [diff] [blame] | 4973 | |
Wale Ogunwale | 3a256e6 | 2018-12-06 14:41:18 -0800 | [diff] [blame] | 4974 | getDisplay().mDisplayContent.prepareAppTransition(TRANSIT_TASK_TO_BACK, false); |
Evan Rosky | 9c44817 | 2017-11-02 14:19:27 -0700 | [diff] [blame] | 4975 | moveToBack("moveTaskToBackLocked", tr); |
Winson Chung | 261c0f3 | 2017-03-07 16:54:31 -0800 | [diff] [blame] | 4976 | |
Wale Ogunwale | 44f036f | 2017-09-29 05:09:09 -0700 | [diff] [blame] | 4977 | if (inPinnedWindowingMode()) { |
Wale Ogunwale | a0f5b5e | 2017-10-11 09:37:23 -0700 | [diff] [blame] | 4978 | mStackSupervisor.removeStack(this); |
Winson Chung | 261c0f3 | 2017-03-07 16:54:31 -0800 | [diff] [blame] | 4979 | return true; |
| 4980 | } |
| 4981 | |
Wale Ogunwale | d32da47 | 2018-11-16 07:19:28 -0800 | [diff] [blame] | 4982 | mRootActivityContainer.resumeFocusedStacksTopActivities(); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 4983 | return true; |
| 4984 | } |
Dianne Hackborn | 15491c6 | 2012-09-19 10:59:14 -0700 | [diff] [blame] | 4985 | |
Andrii Kulian | 21713ac | 2016-10-12 22:05:05 -0700 | [diff] [blame] | 4986 | static void logStartActivity(int tag, ActivityRecord r, TaskRecord task) { |
Santos Cordon | 73ff7d8 | 2013-03-06 17:24:11 -0800 | [diff] [blame] | 4987 | final Uri data = r.intent.getData(); |
| 4988 | final String strData = data != null ? data.toSafeString() : null; |
| 4989 | |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 4990 | EventLog.writeEvent(tag, |
Wale Ogunwale | 8b19de9 | 2018-11-29 19:58:26 -0800 | [diff] [blame] | 4991 | r.mUserId, System.identityHashCode(r), task.taskId, |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 4992 | r.shortComponentName, r.intent.getAction(), |
Santos Cordon | 73ff7d8 | 2013-03-06 17:24:11 -0800 | [diff] [blame] | 4993 | r.intent.getType(), strData, r.intent.getFlags()); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 4994 | } |
| 4995 | |
| 4996 | /** |
Wale Ogunwale | db0fa12 | 2016-05-16 15:12:03 -0700 | [diff] [blame] | 4997 | * Ensures all visible activities at or below the input activity have the right configuration. |
| 4998 | */ |
| 4999 | void ensureVisibleActivitiesConfigurationLocked(ActivityRecord start, boolean preserveWindow) { |
| 5000 | if (start == null || !start.visible) { |
| 5001 | return; |
| 5002 | } |
| 5003 | |
Wale Ogunwale | 8b19de9 | 2018-11-29 19:58:26 -0800 | [diff] [blame] | 5004 | final TaskRecord startTask = start.getTaskRecord(); |
Wale Ogunwale | db0fa12 | 2016-05-16 15:12:03 -0700 | [diff] [blame] | 5005 | boolean behindFullscreen = false; |
| 5006 | boolean updatedConfig = false; |
| 5007 | |
| 5008 | for (int taskIndex = mTaskHistory.indexOf(startTask); taskIndex >= 0; --taskIndex) { |
| 5009 | final TaskRecord task = mTaskHistory.get(taskIndex); |
| 5010 | final ArrayList<ActivityRecord> activities = task.mActivities; |
Wale Ogunwale | 8b19de9 | 2018-11-29 19:58:26 -0800 | [diff] [blame] | 5011 | int activityIndex = (start.getTaskRecord() == task) |
| 5012 | ? activities.indexOf(start) : activities.size() - 1; |
Wale Ogunwale | db0fa12 | 2016-05-16 15:12:03 -0700 | [diff] [blame] | 5013 | for (; activityIndex >= 0; --activityIndex) { |
| 5014 | final ActivityRecord r = activities.get(activityIndex); |
Wale Ogunwale | b6d75f3 | 2018-02-22 20:44:56 -0800 | [diff] [blame] | 5015 | updatedConfig |= r.ensureActivityConfiguration(0 /* globalChanges */, |
Andrii Kulian | 21713ac | 2016-10-12 22:05:05 -0700 | [diff] [blame] | 5016 | preserveWindow); |
Wale Ogunwale | db0fa12 | 2016-05-16 15:12:03 -0700 | [diff] [blame] | 5017 | if (r.fullscreen) { |
| 5018 | behindFullscreen = true; |
| 5019 | break; |
| 5020 | } |
| 5021 | } |
| 5022 | if (behindFullscreen) { |
| 5023 | break; |
| 5024 | } |
| 5025 | } |
| 5026 | if (updatedConfig) { |
Wale Ogunwale | 089586f | 2016-06-20 14:16:22 -0700 | [diff] [blame] | 5027 | // 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] | 5028 | // any activity. |
Wale Ogunwale | d32da47 | 2018-11-16 07:19:28 -0800 | [diff] [blame] | 5029 | mRootActivityContainer.resumeFocusedStacksTopActivities(); |
Wale Ogunwale | db0fa12 | 2016-05-16 15:12:03 -0700 | [diff] [blame] | 5030 | } |
| 5031 | } |
| 5032 | |
Wale Ogunwale | 1666e31 | 2016-12-16 11:27:18 -0800 | [diff] [blame] | 5033 | // TODO: Figure-out a way to consolidate with resize() method below. |
Yunfan Chen | 279f558 | 2018-12-12 15:24:50 -0800 | [diff] [blame] | 5034 | void requestResize(Rect bounds) { |
Wale Ogunwale | 5fa8a8c | 2018-05-08 13:43:21 -0700 | [diff] [blame] | 5035 | mService.resizeStack(mStackId, bounds, |
Wale Ogunwale | 65ebd95 | 2018-04-25 15:41:44 -0700 | [diff] [blame] | 5036 | true /* allowResizeInDockedMode */, false /* preserveWindows */, |
| 5037 | false /* animate */, -1 /* animationDuration */); |
Wale Ogunwale | 1666e31 | 2016-12-16 11:27:18 -0800 | [diff] [blame] | 5038 | } |
Andrii Kulian | 1e32e02 | 2016-09-16 15:29:34 -0700 | [diff] [blame] | 5039 | |
Wale Ogunwale | 1666e31 | 2016-12-16 11:27:18 -0800 | [diff] [blame] | 5040 | // TODO: Can only be called from special methods in ActivityStackSupervisor. |
| 5041 | // Need to consolidate those calls points into this resize method so anyone can call directly. |
| 5042 | void resize(Rect bounds, Rect tempTaskBounds, Rect tempTaskInsetBounds) { |
Evan Rosky | 1ac8446 | 2018-11-13 11:25:30 -0800 | [diff] [blame] | 5043 | if (!updateBoundsAllowed(bounds)) { |
Wale Ogunwale | 1666e31 | 2016-12-16 11:27:18 -0800 | [diff] [blame] | 5044 | return; |
| 5045 | } |
| 5046 | |
| 5047 | // Update override configurations of all tasks in the stack. |
| 5048 | final Rect taskBounds = tempTaskBounds != null ? tempTaskBounds : bounds; |
Andrii Kulian | 1e32e02 | 2016-09-16 15:29:34 -0700 | [diff] [blame] | 5049 | |
Wale Ogunwale | 1f5e53d | 2018-11-05 05:12:46 -0800 | [diff] [blame] | 5050 | for (int i = mTaskHistory.size() - 1; i >= 0; i--) { |
| 5051 | final TaskRecord task = mTaskHistory.get(i); |
| 5052 | if (task.isResizeable()) { |
Garfield Tan | 020607d | 2018-12-17 17:01:58 -0800 | [diff] [blame] | 5053 | task.updateOverrideConfiguration(taskBounds, tempTaskInsetBounds); |
Andrii Kulian | 1e32e02 | 2016-09-16 15:29:34 -0700 | [diff] [blame] | 5054 | } |
Andrii Kulian | 1e32e02 | 2016-09-16 15:29:34 -0700 | [diff] [blame] | 5055 | } |
Wale Ogunwale | 1f5e53d | 2018-11-05 05:12:46 -0800 | [diff] [blame] | 5056 | |
Wale Ogunwale | 1f5e53d | 2018-11-05 05:12:46 -0800 | [diff] [blame] | 5057 | setBounds(bounds); |
Andrii Kulian | 1e32e02 | 2016-09-16 15:29:34 -0700 | [diff] [blame] | 5058 | } |
| 5059 | |
Winson Chung | 15036ca | 2018-05-31 15:51:47 -0700 | [diff] [blame] | 5060 | void onPipAnimationEndResize() { |
Yunfan Chen | 279f558 | 2018-12-12 15:24:50 -0800 | [diff] [blame] | 5061 | if (mTaskStack == null) return; |
| 5062 | mTaskStack.onPipAnimationEndResize(); |
Winson Chung | 15036ca | 2018-05-31 15:51:47 -0700 | [diff] [blame] | 5063 | } |
| 5064 | |
Andrii Kulian | 1e32e02 | 2016-09-16 15:29:34 -0700 | [diff] [blame] | 5065 | |
| 5066 | /** |
Evan Rosky | 1ac8446 | 2018-11-13 11:25:30 -0800 | [diff] [blame] | 5067 | * Until we can break this "set task bounds to same as stack bounds" behavior, this |
| 5068 | * basically resizes both stack and task bounds to the same bounds. |
Andrii Kulian | 1e32e02 | 2016-09-16 15:29:34 -0700 | [diff] [blame] | 5069 | */ |
Evan Rosky | 1ac8446 | 2018-11-13 11:25:30 -0800 | [diff] [blame] | 5070 | void setTaskBounds(Rect bounds) { |
| 5071 | if (!updateBoundsAllowed(bounds)) { |
Andrii Kulian | 1e32e02 | 2016-09-16 15:29:34 -0700 | [diff] [blame] | 5072 | return; |
| 5073 | } |
| 5074 | |
Evan Rosky | 1ac8446 | 2018-11-13 11:25:30 -0800 | [diff] [blame] | 5075 | for (int i = mTaskHistory.size() - 1; i >= 0; i--) { |
| 5076 | final TaskRecord task = mTaskHistory.get(i); |
| 5077 | if (task.isResizeable()) { |
| 5078 | task.setBounds(bounds); |
| 5079 | } else { |
| 5080 | task.setBounds(null); |
Andrii Kulian | 1e32e02 | 2016-09-16 15:29:34 -0700 | [diff] [blame] | 5081 | } |
Evan Rosky | 1ac8446 | 2018-11-13 11:25:30 -0800 | [diff] [blame] | 5082 | } |
| 5083 | } |
| 5084 | |
| 5085 | /** Helper to setDisplayedBounds on all child tasks */ |
| 5086 | void setTaskDisplayedBounds(Rect bounds) { |
| 5087 | if (!updateDisplayedBoundsAllowed(bounds)) { |
| 5088 | return; |
Andrii Kulian | 1e32e02 | 2016-09-16 15:29:34 -0700 | [diff] [blame] | 5089 | } |
| 5090 | |
Evan Rosky | 1ac8446 | 2018-11-13 11:25:30 -0800 | [diff] [blame] | 5091 | for (int i = mTaskHistory.size() - 1; i >= 0; i--) { |
| 5092 | final TaskRecord task = mTaskHistory.get(i); |
| 5093 | if (bounds == null || bounds.isEmpty()) { |
| 5094 | task.setDisplayedBounds(null); |
| 5095 | } else if (task.isResizeable()) { |
| 5096 | task.setDisplayedBounds(bounds); |
Andrii Kulian | 1e32e02 | 2016-09-16 15:29:34 -0700 | [diff] [blame] | 5097 | } |
Andrii Kulian | 1e32e02 | 2016-09-16 15:29:34 -0700 | [diff] [blame] | 5098 | } |
| 5099 | } |
| 5100 | |
Craig Mautner | cae015f | 2013-02-08 14:31:27 -0800 | [diff] [blame] | 5101 | boolean willActivityBeVisibleLocked(IBinder token) { |
Craig Mautner | d44711d | 2013-02-23 11:24:36 -0800 | [diff] [blame] | 5102 | for (int taskNdx = mTaskHistory.size() - 1; taskNdx >= 0; --taskNdx) { |
| 5103 | final ArrayList<ActivityRecord> activities = mTaskHistory.get(taskNdx).mActivities; |
| 5104 | for (int activityNdx = activities.size() - 1; activityNdx >= 0; --activityNdx) { |
| 5105 | final ActivityRecord r = activities.get(activityNdx); |
| 5106 | if (r.appToken == token) { |
Craig Mautner | 34b73df | 2014-01-12 21:11:08 -0800 | [diff] [blame] | 5107 | return true; |
Craig Mautner | d44711d | 2013-02-23 11:24:36 -0800 | [diff] [blame] | 5108 | } |
| 5109 | if (r.fullscreen && !r.finishing) { |
| 5110 | return false; |
| 5111 | } |
Craig Mautner | cae015f | 2013-02-08 14:31:27 -0800 | [diff] [blame] | 5112 | } |
| 5113 | } |
Wale Ogunwale | 7d70117 | 2015-03-11 15:36:30 -0700 | [diff] [blame] | 5114 | final ActivityRecord r = ActivityRecord.forTokenLocked(token); |
Craig Mautner | 34b73df | 2014-01-12 21:11:08 -0800 | [diff] [blame] | 5115 | if (r == null) { |
| 5116 | return false; |
| 5117 | } |
| 5118 | if (r.finishing) Slog.e(TAG, "willActivityBeVisibleLocked: Returning false," |
| 5119 | + " would have returned true for r=" + r); |
| 5120 | return !r.finishing; |
Craig Mautner | cae015f | 2013-02-08 14:31:27 -0800 | [diff] [blame] | 5121 | } |
| 5122 | |
| 5123 | void closeSystemDialogsLocked() { |
Craig Mautner | d44711d | 2013-02-23 11:24:36 -0800 | [diff] [blame] | 5124 | for (int taskNdx = mTaskHistory.size() - 1; taskNdx >= 0; --taskNdx) { |
| 5125 | final ArrayList<ActivityRecord> activities = mTaskHistory.get(taskNdx).mActivities; |
| 5126 | for (int activityNdx = activities.size() - 1; activityNdx >= 0; --activityNdx) { |
| 5127 | final ActivityRecord r = activities.get(activityNdx); |
| 5128 | if ((r.info.flags&ActivityInfo.FLAG_FINISH_ON_CLOSE_SYSTEM_DIALOGS) != 0) { |
Craig Mautner | d232895 | 2013-03-05 12:46:26 -0800 | [diff] [blame] | 5129 | finishActivityLocked(r, Activity.RESULT_CANCELED, null, "close-sys", true); |
Craig Mautner | d44711d | 2013-02-23 11:24:36 -0800 | [diff] [blame] | 5130 | } |
Craig Mautner | cae015f | 2013-02-08 14:31:27 -0800 | [diff] [blame] | 5131 | } |
| 5132 | } |
| 5133 | } |
| 5134 | |
Wale Ogunwale | 540e123 | 2015-05-01 15:35:39 -0700 | [diff] [blame] | 5135 | boolean finishDisabledPackageActivitiesLocked(String packageName, Set<String> filterByClasses, |
| 5136 | boolean doit, boolean evenPersistent, int userId) { |
Craig Mautner | cae015f | 2013-02-08 14:31:27 -0800 | [diff] [blame] | 5137 | boolean didSomething = false; |
| 5138 | TaskRecord lastTask = null; |
Craig Mautner | 9d8a30d | 2014-07-07 17:26:20 +0000 | [diff] [blame] | 5139 | ComponentName homeActivity = null; |
Craig Mautner | 56f52db | 2013-02-25 10:03:01 -0800 | [diff] [blame] | 5140 | for (int taskNdx = mTaskHistory.size() - 1; taskNdx >= 0; --taskNdx) { |
| 5141 | final ArrayList<ActivityRecord> activities = mTaskHistory.get(taskNdx).mActivities; |
Bryce Lee | fbd263b4 | 2018-03-07 10:33:55 -0800 | [diff] [blame] | 5142 | mTmpActivities.clear(); |
| 5143 | mTmpActivities.addAll(activities); |
| 5144 | |
| 5145 | while (!mTmpActivities.isEmpty()) { |
| 5146 | ActivityRecord r = mTmpActivities.remove(0); |
Wale Ogunwale | 540e123 | 2015-05-01 15:35:39 -0700 | [diff] [blame] | 5147 | final boolean sameComponent = |
| 5148 | (r.packageName.equals(packageName) && (filterByClasses == null |
Wale Ogunwale | 8b19de9 | 2018-11-29 19:58:26 -0800 | [diff] [blame] | 5149 | || filterByClasses.contains(r.mActivityComponent.getClassName()))) |
| 5150 | || (packageName == null && r.mUserId == userId); |
| 5151 | if ((userId == UserHandle.USER_ALL || r.mUserId == userId) |
| 5152 | && (sameComponent || r.getTaskRecord() == lastTask) |
Wale Ogunwale | 9e4f3e0 | 2018-05-17 09:35:39 -0700 | [diff] [blame] | 5153 | && (r.app == null || evenPersistent || !r.app.isPersistent())) { |
Craig Mautner | 56f52db | 2013-02-25 10:03:01 -0800 | [diff] [blame] | 5154 | if (!doit) { |
| 5155 | if (r.finishing) { |
| 5156 | // If this activity is just finishing, then it is not |
| 5157 | // interesting as far as something to stop. |
| 5158 | continue; |
| 5159 | } |
| 5160 | return true; |
Craig Mautner | cae015f | 2013-02-08 14:31:27 -0800 | [diff] [blame] | 5161 | } |
Wale Ogunwale | 6fbde9f | 2017-08-24 07:24:12 -0700 | [diff] [blame] | 5162 | if (r.isActivityTypeHome()) { |
Wale Ogunwale | 8b19de9 | 2018-11-29 19:58:26 -0800 | [diff] [blame] | 5163 | if (homeActivity != null && homeActivity.equals(r.mActivityComponent)) { |
Craig Mautner | 9d8a30d | 2014-07-07 17:26:20 +0000 | [diff] [blame] | 5164 | Slog.i(TAG, "Skip force-stop again " + r); |
| 5165 | continue; |
| 5166 | } else { |
Wale Ogunwale | 8b19de9 | 2018-11-29 19:58:26 -0800 | [diff] [blame] | 5167 | homeActivity = r.mActivityComponent; |
Craig Mautner | 9d8a30d | 2014-07-07 17:26:20 +0000 | [diff] [blame] | 5168 | } |
| 5169 | } |
Craig Mautner | 56f52db | 2013-02-25 10:03:01 -0800 | [diff] [blame] | 5170 | didSomething = true; |
| 5171 | Slog.i(TAG, " Force finishing activity " + r); |
Wale Ogunwale | 8b19de9 | 2018-11-29 19:58:26 -0800 | [diff] [blame] | 5172 | lastTask = r.getTaskRecord(); |
Bryce Lee | fbd263b4 | 2018-03-07 10:33:55 -0800 | [diff] [blame] | 5173 | finishActivityLocked(r, Activity.RESULT_CANCELED, null, "force-stop", |
| 5174 | true); |
Craig Mautner | cae015f | 2013-02-08 14:31:27 -0800 | [diff] [blame] | 5175 | } |
| 5176 | } |
| 5177 | } |
| 5178 | return didSomething; |
| 5179 | } |
| 5180 | |
Winson Chung | 61c9e5a | 2017-10-11 10:39:32 -0700 | [diff] [blame] | 5181 | /** |
| 5182 | * @return The set of running tasks through {@param tasksOut} that are available to the caller. |
| 5183 | * If {@param ignoreActivityType} or {@param ignoreWindowingMode} are not undefined, |
| 5184 | * then skip running tasks that match those types. |
| 5185 | */ |
| 5186 | void getRunningTasks(List<TaskRecord> tasksOut, @ActivityType int ignoreActivityType, |
| 5187 | @WindowingMode int ignoreWindowingMode, int callingUid, boolean allowed) { |
Wale Ogunwale | d32da47 | 2018-11-16 07:19:28 -0800 | [diff] [blame] | 5188 | boolean focusedStack = mRootActivityContainer.getTopDisplayFocusedStack() == this; |
riddle_hsu | ddc7415 | 2015-04-07 11:30:09 +0800 | [diff] [blame] | 5189 | boolean topTask = true; |
Craig Mautner | c0fd805 | 2013-09-19 11:20:17 -0700 | [diff] [blame] | 5190 | for (int taskNdx = mTaskHistory.size() - 1; taskNdx >= 0; --taskNdx) { |
Craig Mautner | aab647e | 2013-02-28 16:31:36 -0800 | [diff] [blame] | 5191 | final TaskRecord task = mTaskHistory.get(taskNdx); |
riddle_hsu | ddc7415 | 2015-04-07 11:30:09 +0800 | [diff] [blame] | 5192 | if (task.getTopActivity() == null) { |
Winson Chung | 61c9e5a | 2017-10-11 10:39:32 -0700 | [diff] [blame] | 5193 | // Skip if there are no activities in the task |
riddle_hsu | ddc7415 | 2015-04-07 11:30:09 +0800 | [diff] [blame] | 5194 | continue; |
| 5195 | } |
Wale Ogunwale | 6fbde9f | 2017-08-24 07:24:12 -0700 | [diff] [blame] | 5196 | if (!allowed && !task.isActivityTypeHome() && task.effectiveUid != callingUid) { |
Winson Chung | 61c9e5a | 2017-10-11 10:39:32 -0700 | [diff] [blame] | 5197 | // Skip if the caller can't fetch this task |
Dianne Hackborn | 0923328 | 2014-04-30 11:33:59 -0700 | [diff] [blame] | 5198 | continue; |
| 5199 | } |
Winson Chung | 61c9e5a | 2017-10-11 10:39:32 -0700 | [diff] [blame] | 5200 | if (ignoreActivityType != ACTIVITY_TYPE_UNDEFINED |
| 5201 | && task.getActivityType() == ignoreActivityType) { |
| 5202 | // Skip ignored activity type |
| 5203 | continue; |
Craig Mautner | aab647e | 2013-02-28 16:31:36 -0800 | [diff] [blame] | 5204 | } |
Winson Chung | 61c9e5a | 2017-10-11 10:39:32 -0700 | [diff] [blame] | 5205 | if (ignoreWindowingMode != WINDOWING_MODE_UNDEFINED |
| 5206 | && task.getWindowingMode() == ignoreWindowingMode) { |
| 5207 | // Skip ignored windowing mode |
| 5208 | continue; |
| 5209 | } |
riddle_hsu | ddc7415 | 2015-04-07 11:30:09 +0800 | [diff] [blame] | 5210 | if (focusedStack && topTask) { |
Winson Chung | 61c9e5a | 2017-10-11 10:39:32 -0700 | [diff] [blame] | 5211 | // For the focused stack top task, update the last stack active time so that it can |
| 5212 | // be used to determine the order of the tasks (it may not be set for newly created |
| 5213 | // tasks) |
| 5214 | task.lastActiveTime = SystemClock.elapsedRealtime(); |
riddle_hsu | ddc7415 | 2015-04-07 11:30:09 +0800 | [diff] [blame] | 5215 | topTask = false; |
| 5216 | } |
Winson Chung | 61c9e5a | 2017-10-11 10:39:32 -0700 | [diff] [blame] | 5217 | tasksOut.add(task); |
Craig Mautner | cae015f | 2013-02-08 14:31:27 -0800 | [diff] [blame] | 5218 | } |
Craig Mautner | cae015f | 2013-02-08 14:31:27 -0800 | [diff] [blame] | 5219 | } |
| 5220 | |
Andrii Kulian | 21713ac | 2016-10-12 22:05:05 -0700 | [diff] [blame] | 5221 | void unhandledBackLocked() { |
Craig Mautner | aab647e | 2013-02-28 16:31:36 -0800 | [diff] [blame] | 5222 | final int top = mTaskHistory.size() - 1; |
Wale Ogunwale | ee006da | 2015-03-30 14:49:25 -0700 | [diff] [blame] | 5223 | 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] | 5224 | if (top >= 0) { |
| 5225 | final ArrayList<ActivityRecord> activities = mTaskHistory.get(top).mActivities; |
| 5226 | int activityTop = activities.size() - 1; |
Dianne Hackborn | 354736e | 2016-08-22 17:00:05 -0700 | [diff] [blame] | 5227 | if (activityTop >= 0) { |
Craig Mautner | aab647e | 2013-02-28 16:31:36 -0800 | [diff] [blame] | 5228 | finishActivityLocked(activities.get(activityTop), Activity.RESULT_CANCELED, null, |
| 5229 | "unhandled-back", true); |
| 5230 | } |
Craig Mautner | cae015f | 2013-02-08 14:31:27 -0800 | [diff] [blame] | 5231 | } |
| 5232 | } |
| 5233 | |
Craig Mautner | 6b74cb5 | 2013-09-27 17:02:21 -0700 | [diff] [blame] | 5234 | /** |
| 5235 | * Reset local parameters because an app's activity died. |
| 5236 | * @param app The app of the activity that died. |
Craig Mautner | 1909125 | 2013-10-05 00:03:53 -0700 | [diff] [blame] | 5237 | * @return result from removeHistoryRecordsForAppLocked. |
Craig Mautner | 6b74cb5 | 2013-09-27 17:02:21 -0700 | [diff] [blame] | 5238 | */ |
Wale Ogunwale | 9e4f3e0 | 2018-05-17 09:35:39 -0700 | [diff] [blame] | 5239 | boolean handleAppDiedLocked(WindowProcessController app) { |
Craig Mautner | e79d4268 | 2013-04-01 19:01:53 -0700 | [diff] [blame] | 5240 | if (mPausingActivity != null && mPausingActivity.app == app) { |
Wale Ogunwale | ee006da | 2015-03-30 14:49:25 -0700 | [diff] [blame] | 5241 | if (DEBUG_PAUSE || DEBUG_CLEANUP) Slog.v(TAG_PAUSE, |
Craig Mautner | e79d4268 | 2013-04-01 19:01:53 -0700 | [diff] [blame] | 5242 | "App died while pausing: " + mPausingActivity); |
| 5243 | mPausingActivity = null; |
| 5244 | } |
| 5245 | if (mLastPausedActivity != null && mLastPausedActivity.app == app) { |
| 5246 | mLastPausedActivity = null; |
Craig Mautner | 0f92274 | 2013-08-06 08:44:42 -0700 | [diff] [blame] | 5247 | mLastNoHistoryActivity = null; |
Craig Mautner | e79d4268 | 2013-04-01 19:01:53 -0700 | [diff] [blame] | 5248 | } |
| 5249 | |
Craig Mautner | 1909125 | 2013-10-05 00:03:53 -0700 | [diff] [blame] | 5250 | return removeHistoryRecordsForAppLocked(app); |
Craig Mautner | e79d4268 | 2013-04-01 19:01:53 -0700 | [diff] [blame] | 5251 | } |
| 5252 | |
Wale Ogunwale | d32da47 | 2018-11-16 07:19:28 -0800 | [diff] [blame] | 5253 | void handleAppCrash(WindowProcessController app) { |
Craig Mautner | d44711d | 2013-02-23 11:24:36 -0800 | [diff] [blame] | 5254 | for (int taskNdx = mTaskHistory.size() - 1; taskNdx >= 0; --taskNdx) { |
| 5255 | final ArrayList<ActivityRecord> activities = mTaskHistory.get(taskNdx).mActivities; |
| 5256 | for (int activityNdx = activities.size() - 1; activityNdx >= 0; --activityNdx) { |
| 5257 | final ActivityRecord r = activities.get(activityNdx); |
| 5258 | if (r.app == app) { |
| 5259 | Slog.w(TAG, " Force finishing activity " |
| 5260 | + r.intent.getComponent().flattenToShortString()); |
Craig Mautner | 8e5b133 | 2014-07-24 13:32:37 -0700 | [diff] [blame] | 5261 | // Force the destroy to skip right to removal. |
| 5262 | r.app = null; |
Wale Ogunwale | 3a256e6 | 2018-12-06 14:41:18 -0800 | [diff] [blame] | 5263 | getDisplay().mDisplayContent.prepareAppTransition( |
lumark | 588a3e8 | 2018-07-20 18:53:54 +0800 | [diff] [blame] | 5264 | TRANSIT_CRASHING_ACTIVITY_CLOSE, false /* alwaysKeepCurrent */); |
Bryce Lee | f52974c | 2018-02-14 15:12:01 -0800 | [diff] [blame] | 5265 | finishCurrentActivityLocked(r, FINISH_IMMEDIATELY, false, |
| 5266 | "handleAppCrashedLocked"); |
Craig Mautner | d44711d | 2013-02-23 11:24:36 -0800 | [diff] [blame] | 5267 | } |
Craig Mautner | cae015f | 2013-02-08 14:31:27 -0800 | [diff] [blame] | 5268 | } |
| 5269 | } |
| 5270 | } |
| 5271 | |
Garfield Tan | 347bd60 | 2018-12-21 15:11:12 -0800 | [diff] [blame] | 5272 | boolean dump(FileDescriptor fd, PrintWriter pw, boolean dumpAll, boolean dumpClient, |
| 5273 | String dumpPackage, boolean needSep) { |
| 5274 | pw.println(" Stack #" + mStackId |
| 5275 | + ": type=" + activityTypeToString(getActivityType()) |
| 5276 | + " mode=" + windowingModeToString(getWindowingMode())); |
| 5277 | pw.println(" isSleeping=" + shouldSleepActivities()); |
| 5278 | pw.println(" mBounds=" + getRequestedOverrideBounds()); |
| 5279 | |
| 5280 | boolean printed = dumpActivitiesLocked(fd, pw, dumpAll, dumpClient, dumpPackage, |
| 5281 | needSep); |
| 5282 | |
| 5283 | printed |= dumpHistoryList(fd, pw, mLRUActivities, " ", "Run", false, |
| 5284 | !dumpAll, false, dumpPackage, true, |
| 5285 | " Running activities (most recent first):", null); |
| 5286 | |
| 5287 | needSep = printed; |
| 5288 | boolean pr = printThisActivity(pw, mPausingActivity, dumpPackage, needSep, |
| 5289 | " mPausingActivity: "); |
| 5290 | if (pr) { |
| 5291 | printed = true; |
| 5292 | needSep = false; |
| 5293 | } |
| 5294 | pr = printThisActivity(pw, getResumedActivity(), dumpPackage, needSep, |
| 5295 | " mResumedActivity: "); |
| 5296 | if (pr) { |
| 5297 | printed = true; |
| 5298 | needSep = false; |
| 5299 | } |
| 5300 | if (dumpAll) { |
| 5301 | pr = printThisActivity(pw, mLastPausedActivity, dumpPackage, needSep, |
| 5302 | " mLastPausedActivity: "); |
| 5303 | if (pr) { |
| 5304 | printed = true; |
| 5305 | needSep = true; |
| 5306 | } |
| 5307 | printed |= printThisActivity(pw, mLastNoHistoryActivity, dumpPackage, |
| 5308 | needSep, " mLastNoHistoryActivity: "); |
| 5309 | } |
| 5310 | return printed; |
| 5311 | } |
| 5312 | |
Dianne Hackborn | 390517b | 2013-05-30 15:03:32 -0700 | [diff] [blame] | 5313 | boolean dumpActivitiesLocked(FileDescriptor fd, PrintWriter pw, boolean dumpAll, |
Wale Ogunwale | 34a5b57 | 2017-08-31 08:29:41 -0700 | [diff] [blame] | 5314 | boolean dumpClient, String dumpPackage, boolean needSep) { |
| 5315 | |
| 5316 | if (mTaskHistory.isEmpty()) { |
| 5317 | return false; |
| 5318 | } |
| 5319 | final String prefix = " "; |
Craig Mautner | aab647e | 2013-02-28 16:31:36 -0800 | [diff] [blame] | 5320 | for (int taskNdx = mTaskHistory.size() - 1; taskNdx >= 0; --taskNdx) { |
| 5321 | final TaskRecord task = mTaskHistory.get(taskNdx); |
Wale Ogunwale | 34a5b57 | 2017-08-31 08:29:41 -0700 | [diff] [blame] | 5322 | if (needSep) { |
| 5323 | pw.println(""); |
Dianne Hackborn | 7ad34e5 | 2013-06-05 18:41:45 -0700 | [diff] [blame] | 5324 | } |
Wale Ogunwale | 34a5b57 | 2017-08-31 08:29:41 -0700 | [diff] [blame] | 5325 | pw.println(prefix + "Task id #" + task.taskId); |
Evan Rosky | dfe3da7 | 2018-10-26 17:21:06 -0700 | [diff] [blame] | 5326 | pw.println(prefix + "mBounds=" + task.getRequestedOverrideBounds()); |
Wale Ogunwale | 34a5b57 | 2017-08-31 08:29:41 -0700 | [diff] [blame] | 5327 | pw.println(prefix + "mMinWidth=" + task.mMinWidth); |
| 5328 | pw.println(prefix + "mMinHeight=" + task.mMinHeight); |
| 5329 | pw.println(prefix + "mLastNonFullscreenBounds=" + task.mLastNonFullscreenBounds); |
| 5330 | pw.println(prefix + "* " + task); |
| 5331 | task.dump(pw, prefix + " "); |
Garfield Tan | 347bd60 | 2018-12-21 15:11:12 -0800 | [diff] [blame] | 5332 | dumpHistoryList(fd, pw, mTaskHistory.get(taskNdx).mActivities, |
Wale Ogunwale | 34a5b57 | 2017-08-31 08:29:41 -0700 | [diff] [blame] | 5333 | prefix, "Hist", true, !dumpAll, dumpClient, dumpPackage, false, null, task); |
Craig Mautner | aab647e | 2013-02-28 16:31:36 -0800 | [diff] [blame] | 5334 | } |
Wale Ogunwale | 34a5b57 | 2017-08-31 08:29:41 -0700 | [diff] [blame] | 5335 | return true; |
Craig Mautner | cae015f | 2013-02-08 14:31:27 -0800 | [diff] [blame] | 5336 | } |
| 5337 | |
| 5338 | ArrayList<ActivityRecord> getDumpActivitiesLocked(String name) { |
Winson Chung | 6998bc4 | 2017-02-28 17:07:05 -0800 | [diff] [blame] | 5339 | ArrayList<ActivityRecord> activities = new ArrayList<>(); |
Craig Mautner | cae015f | 2013-02-08 14:31:27 -0800 | [diff] [blame] | 5340 | |
| 5341 | if ("all".equals(name)) { |
Craig Mautner | aab647e | 2013-02-28 16:31:36 -0800 | [diff] [blame] | 5342 | for (int taskNdx = mTaskHistory.size() - 1; taskNdx >= 0; --taskNdx) { |
| 5343 | activities.addAll(mTaskHistory.get(taskNdx).mActivities); |
Craig Mautner | cae015f | 2013-02-08 14:31:27 -0800 | [diff] [blame] | 5344 | } |
| 5345 | } else if ("top".equals(name)) { |
Craig Mautner | aab647e | 2013-02-28 16:31:36 -0800 | [diff] [blame] | 5346 | final int top = mTaskHistory.size() - 1; |
| 5347 | if (top >= 0) { |
| 5348 | final ArrayList<ActivityRecord> list = mTaskHistory.get(top).mActivities; |
| 5349 | int listTop = list.size() - 1; |
| 5350 | if (listTop >= 0) { |
| 5351 | activities.add(list.get(listTop)); |
| 5352 | } |
Craig Mautner | cae015f | 2013-02-08 14:31:27 -0800 | [diff] [blame] | 5353 | } |
| 5354 | } else { |
| 5355 | ItemMatcher matcher = new ItemMatcher(); |
| 5356 | matcher.build(name); |
| 5357 | |
Craig Mautner | aab647e | 2013-02-28 16:31:36 -0800 | [diff] [blame] | 5358 | for (int taskNdx = mTaskHistory.size() - 1; taskNdx >= 0; --taskNdx) { |
| 5359 | for (ActivityRecord r1 : mTaskHistory.get(taskNdx).mActivities) { |
| 5360 | if (matcher.match(r1, r1.intent.getComponent())) { |
| 5361 | activities.add(r1); |
| 5362 | } |
Craig Mautner | cae015f | 2013-02-08 14:31:27 -0800 | [diff] [blame] | 5363 | } |
| 5364 | } |
| 5365 | } |
| 5366 | |
| 5367 | return activities; |
| 5368 | } |
| 5369 | |
| 5370 | ActivityRecord restartPackage(String packageName) { |
Filip Gruszczynski | 3e85ba2 | 2015-10-05 22:48:30 -0700 | [diff] [blame] | 5371 | ActivityRecord starting = topRunningActivityLocked(); |
Craig Mautner | cae015f | 2013-02-08 14:31:27 -0800 | [diff] [blame] | 5372 | |
| 5373 | // All activities that came from the package must be |
| 5374 | // restarted as if there was a config change. |
Craig Mautner | aab647e | 2013-02-28 16:31:36 -0800 | [diff] [blame] | 5375 | for (int taskNdx = mTaskHistory.size() - 1; taskNdx >= 0; --taskNdx) { |
| 5376 | final ArrayList<ActivityRecord> activities = mTaskHistory.get(taskNdx).mActivities; |
| 5377 | for (int activityNdx = activities.size() - 1; activityNdx >= 0; --activityNdx) { |
| 5378 | final ActivityRecord a = activities.get(activityNdx); |
| 5379 | if (a.info.packageName.equals(packageName)) { |
| 5380 | a.forceNewConfig = true; |
| 5381 | if (starting != null && a == starting && a.visible) { |
| 5382 | a.startFreezingScreenLocked(starting.app, |
Filip Gruszczynski | 3c2db1d1 | 2016-01-06 17:39:14 -0800 | [diff] [blame] | 5383 | CONFIG_SCREEN_LAYOUT); |
Craig Mautner | aab647e | 2013-02-28 16:31:36 -0800 | [diff] [blame] | 5384 | } |
Craig Mautner | cae015f | 2013-02-08 14:31:27 -0800 | [diff] [blame] | 5385 | } |
| 5386 | } |
| 5387 | } |
| 5388 | |
| 5389 | return starting; |
| 5390 | } |
Craig Mautner | 5d9c7be | 2013-02-15 14:02:56 -0800 | [diff] [blame] | 5391 | |
Wale Ogunwale | 000957c | 2015-04-03 08:19:12 -0700 | [diff] [blame] | 5392 | /** |
| 5393 | * Removes the input task from this stack. |
Garfield Tan | 891146c | 2018-10-09 12:14:00 -0700 | [diff] [blame] | 5394 | * |
Wale Ogunwale | 000957c | 2015-04-03 08:19:12 -0700 | [diff] [blame] | 5395 | * @param task to remove. |
| 5396 | * @param reason for removal. |
Wale Ogunwale | 06579d6 | 2016-04-30 15:29:06 -0700 | [diff] [blame] | 5397 | * @param mode task removal mode. Either {@link #REMOVE_TASK_MODE_DESTROYING}, |
| 5398 | * {@link #REMOVE_TASK_MODE_MOVING}, {@link #REMOVE_TASK_MODE_MOVING_TO_TOP}. |
Wale Ogunwale | 000957c | 2015-04-03 08:19:12 -0700 | [diff] [blame] | 5399 | */ |
Wale Ogunwale | 06579d6 | 2016-04-30 15:29:06 -0700 | [diff] [blame] | 5400 | void removeTask(TaskRecord task, String reason, int mode) { |
Bryce Lee | 2b8e037 | 2018-04-05 17:01:37 -0700 | [diff] [blame] | 5401 | final boolean removed = mTaskHistory.remove(task); |
| 5402 | |
| 5403 | if (removed) { |
| 5404 | EventLog.writeEvent(EventLogTags.AM_REMOVE_TASK, task.taskId, getStackId()); |
| 5405 | } |
| 5406 | |
Winson Chung | abb433b | 2017-03-24 09:35:42 -0700 | [diff] [blame] | 5407 | removeActivitiesFromLRUListLocked(task); |
Craig Mautner | 21d24a2 | 2014-04-23 11:45:37 -0700 | [diff] [blame] | 5408 | updateTaskMovement(task, true); |
Craig Mautner | 41db4a7 | 2014-05-07 17:20:56 -0700 | [diff] [blame] | 5409 | |
Garfield Tan | 347bd60 | 2018-12-21 15:11:12 -0800 | [diff] [blame] | 5410 | if (mode == REMOVE_TASK_MODE_DESTROYING) { |
| 5411 | task.cleanUpResourcesForDestroy(); |
Dianne Hackborn | 91097de | 2014-04-04 18:02:06 -0700 | [diff] [blame] | 5412 | } |
Craig Mautner | 04a0ea6 | 2014-01-13 12:51:26 -0800 | [diff] [blame] | 5413 | |
| 5414 | if (mTaskHistory.isEmpty()) { |
Wale Ogunwale | ee006da | 2015-03-30 14:49:25 -0700 | [diff] [blame] | 5415 | if (DEBUG_STACK) Slog.i(TAG_STACK, "removeTask: removing stack=" + this); |
Wale Ogunwale | 06579d6 | 2016-04-30 15:29:06 -0700 | [diff] [blame] | 5416 | // We only need to adjust focused stack if this stack is in focus and we are not in the |
| 5417 | // process of moving the task to the top of the stack that will be focused. |
Louis Chang | bd48dca | 2018-08-29 17:44:34 +0800 | [diff] [blame] | 5418 | if (mode != REMOVE_TASK_MODE_MOVING_TO_TOP |
Wale Ogunwale | d32da47 | 2018-11-16 07:19:28 -0800 | [diff] [blame] | 5419 | && mRootActivityContainer.isTopDisplayFocusedStack(this)) { |
Wale Ogunwale | d697cea | 2015-02-20 17:19:49 -0800 | [diff] [blame] | 5420 | String myReason = reason + " leftTaskHistoryEmpty"; |
Andrii Kulian | ab132ee | 2018-07-24 22:10:21 +0800 | [diff] [blame] | 5421 | if (!inMultiWindowMode() || adjustFocusToNextFocusableStack(myReason) == null) { |
Louis Chang | bd48dca | 2018-08-29 17:44:34 +0800 | [diff] [blame] | 5422 | getDisplay().moveHomeStackToFront(myReason); |
Wale Ogunwale | d697cea | 2015-02-20 17:19:49 -0800 | [diff] [blame] | 5423 | } |
Craig Mautner | 04a0ea6 | 2014-01-13 12:51:26 -0800 | [diff] [blame] | 5424 | } |
Wale Ogunwale | 9dcf946 | 2017-09-19 15:13:01 -0700 | [diff] [blame] | 5425 | if (isAttached()) { |
| 5426 | getDisplay().positionChildAtBottom(this); |
Craig Mautner | 593a4e6 | 2014-01-15 17:55:51 -0800 | [diff] [blame] | 5427 | } |
Louis Chang | 7d0037c | 2018-08-13 12:42:06 +0800 | [diff] [blame] | 5428 | if (!isActivityTypeHome() || getDisplay().isRemoved()) { |
Andrii Kulian | 94e82d9b0 | 2017-07-13 15:33:06 -0700 | [diff] [blame] | 5429 | remove(); |
Wale Ogunwale | 49853bf | 2015-02-23 09:24:42 -0800 | [diff] [blame] | 5430 | } |
Craig Mautner | 04a0ea6 | 2014-01-13 12:51:26 -0800 | [diff] [blame] | 5431 | } |
Wale Ogunwale | 04f4d6b | 2015-03-11 09:23:25 -0700 | [diff] [blame] | 5432 | |
Andrii Kulian | 02b7a83 | 2016-10-06 23:11:56 -0700 | [diff] [blame] | 5433 | task.setStack(null); |
Winson Chung | c81c0ce | 2017-03-17 12:27:30 -0700 | [diff] [blame] | 5434 | |
| 5435 | // Notify if a task from the pinned stack is being removed (or moved depending on the mode) |
Wale Ogunwale | 44f036f | 2017-09-29 05:09:09 -0700 | [diff] [blame] | 5436 | if (inPinnedWindowingMode()) { |
Wale Ogunwale | 5fa8a8c | 2018-05-08 13:43:21 -0700 | [diff] [blame] | 5437 | mService.getTaskChangeNotificationController().notifyActivityUnpinned(); |
Winson Chung | c81c0ce | 2017-03-17 12:27:30 -0700 | [diff] [blame] | 5438 | } |
Craig Mautner | 0247fc8 | 2013-02-28 14:32:06 -0800 | [diff] [blame] | 5439 | } |
| 5440 | |
Dianne Hackborn | 91097de | 2014-04-04 18:02:06 -0700 | [diff] [blame] | 5441 | TaskRecord createTaskRecord(int taskId, ActivityInfo info, Intent intent, |
| 5442 | IVoiceInteractionSession voiceSession, IVoiceInteractor voiceInteractor, |
Wale Ogunwale | 6fbde9f | 2017-08-24 07:24:12 -0700 | [diff] [blame] | 5443 | boolean toTop) { |
Bryce Lee | b802ea1 | 2017-11-15 21:25:03 -0800 | [diff] [blame] | 5444 | return createTaskRecord(taskId, info, intent, voiceSession, voiceInteractor, toTop, |
| 5445 | null /*activity*/, null /*source*/, null /*options*/); |
| 5446 | } |
| 5447 | |
| 5448 | TaskRecord createTaskRecord(int taskId, ActivityInfo info, Intent intent, |
| 5449 | IVoiceInteractionSession voiceSession, IVoiceInteractor voiceInteractor, |
| 5450 | boolean toTop, ActivityRecord activity, ActivityRecord source, |
| 5451 | ActivityOptions options) { |
Garfield Tan | 9b1efea | 2017-12-05 16:43:46 -0800 | [diff] [blame] | 5452 | final TaskRecord task = TaskRecord.create( |
Wale Ogunwale | 5fa8a8c | 2018-05-08 13:43:21 -0700 | [diff] [blame] | 5453 | mService, taskId, info, intent, voiceSession, voiceInteractor); |
Chong Zhang | 0fa656b | 2015-08-31 15:17:21 -0700 | [diff] [blame] | 5454 | // add the task to stack first, mTaskPositioner might need the stack association |
Wale Ogunwale | 5f98609 | 2015-12-04 15:35:38 -0800 | [diff] [blame] | 5455 | addTask(task, toTop, "createTaskRecord"); |
Lucas Dupin | 47a65c7 | 2018-02-15 14:16:18 -0800 | [diff] [blame] | 5456 | final int displayId = mDisplayId != INVALID_DISPLAY ? mDisplayId : DEFAULT_DISPLAY; |
Bryce Lee | 2a3cc46 | 2017-10-27 10:57:35 -0700 | [diff] [blame] | 5457 | final boolean isLockscreenShown = mService.mStackSupervisor.getKeyguardController() |
Lucas Dupin | 47a65c7 | 2018-02-15 14:16:18 -0800 | [diff] [blame] | 5458 | .isKeyguardOrAodShowing(displayId); |
Bryce Lee | ec55eb0 | 2017-12-05 20:51:27 -0800 | [diff] [blame] | 5459 | if (!mStackSupervisor.getLaunchParamsController() |
Bryce Lee | b802ea1 | 2017-11-15 21:25:03 -0800 | [diff] [blame] | 5460 | .layoutTask(task, info.windowLayout, activity, source, options) |
Bryce Lee | f3c6a47 | 2017-11-14 14:53:06 -0800 | [diff] [blame] | 5461 | && !matchParentBounds() && task.isResizeable() && !isLockscreenShown) { |
Evan Rosky | dfe3da7 | 2018-10-26 17:21:06 -0700 | [diff] [blame] | 5462 | task.updateOverrideConfiguration(getRequestedOverrideBounds()); |
Filip Gruszczynski | e5390e7 | 2015-08-18 16:39:00 -0700 | [diff] [blame] | 5463 | } |
Yunfan Chen | 0e7aff9 | 2018-12-05 16:35:32 -0800 | [diff] [blame] | 5464 | task.createTask(toTop, (info.flags & FLAG_SHOW_FOR_ALL_USERS) != 0); |
Craig Mautner | 5d9c7be | 2013-02-15 14:02:56 -0800 | [diff] [blame] | 5465 | return task; |
| 5466 | } |
Craig Mautner | c00204b | 2013-03-05 15:02:14 -0800 | [diff] [blame] | 5467 | |
| 5468 | ArrayList<TaskRecord> getAllTasks() { |
Wale Ogunwale | 9d3de4c | 2015-02-01 16:49:44 -0800 | [diff] [blame] | 5469 | return new ArrayList<>(mTaskHistory); |
Craig Mautner | c00204b | 2013-03-05 15:02:14 -0800 | [diff] [blame] | 5470 | } |
| 5471 | |
Wale Ogunwale | 5f98609 | 2015-12-04 15:35:38 -0800 | [diff] [blame] | 5472 | void addTask(final TaskRecord task, final boolean toTop, String reason) { |
Winson Chung | 5af42fc | 2017-03-24 17:11:33 -0700 | [diff] [blame] | 5473 | addTask(task, toTop ? MAX_VALUE : 0, true /* schedulePictureInPictureModeChange */, reason); |
Wale Ogunwale | c5cc301 | 2017-01-13 13:26:16 -0800 | [diff] [blame] | 5474 | if (toTop) { |
| 5475 | // TODO: figure-out a way to remove this call. |
Riddle Hsu | 86cb7de | 2018-08-13 23:29:58 +0800 | [diff] [blame] | 5476 | positionChildWindowContainerAtTop(task); |
Wale Ogunwale | c5cc301 | 2017-01-13 13:26:16 -0800 | [diff] [blame] | 5477 | } |
Wale Ogunwale | e1fe7fa2 | 2016-12-15 18:27:00 -0800 | [diff] [blame] | 5478 | } |
| 5479 | |
Wale Ogunwale | c5cc301 | 2017-01-13 13:26:16 -0800 | [diff] [blame] | 5480 | // TODO: This shouldn't allow automatic reparenting. Remove the call to preAddTask and deal |
| 5481 | // with the fall-out... |
Winson Chung | 5af42fc | 2017-03-24 17:11:33 -0700 | [diff] [blame] | 5482 | void addTask(final TaskRecord task, int position, boolean schedulePictureInPictureModeChange, |
| 5483 | String reason) { |
Wale Ogunwale | c5cc301 | 2017-01-13 13:26:16 -0800 | [diff] [blame] | 5484 | // TODO: Is this remove really needed? Need to look into the call path for the other addTask |
| 5485 | mTaskHistory.remove(task); |
Wale Ogunwale | 9e737db | 2018-12-17 15:42:37 -0800 | [diff] [blame] | 5486 | if (isSingleTaskInstance() && !mTaskHistory.isEmpty()) { |
| 5487 | throw new IllegalStateException("Can only have one child on stack=" + this); |
| 5488 | } |
| 5489 | |
Wale Ogunwale | c5cc301 | 2017-01-13 13:26:16 -0800 | [diff] [blame] | 5490 | position = getAdjustedPositionForTask(task, position, null /* starting */); |
| 5491 | final boolean toTop = position >= mTaskHistory.size(); |
Wale Ogunwale | 06579d6 | 2016-04-30 15:29:06 -0700 | [diff] [blame] | 5492 | final ActivityStack prevStack = preAddTask(task, reason, toTop); |
Wale Ogunwale | 5f98609 | 2015-12-04 15:35:38 -0800 | [diff] [blame] | 5493 | |
Andrii Kulian | fb1bf69 | 2017-01-17 11:17:34 -0800 | [diff] [blame] | 5494 | mTaskHistory.add(position, task); |
Andrii Kulian | 02b7a83 | 2016-10-06 23:11:56 -0700 | [diff] [blame] | 5495 | task.setStack(this); |
Wale Ogunwale | c5cc301 | 2017-01-13 13:26:16 -0800 | [diff] [blame] | 5496 | |
Wale Ogunwale | c5cc301 | 2017-01-13 13:26:16 -0800 | [diff] [blame] | 5497 | updateTaskMovement(task, toTop); |
| 5498 | |
Winson Chung | 5af42fc | 2017-03-24 17:11:33 -0700 | [diff] [blame] | 5499 | postAddTask(task, prevStack, schedulePictureInPictureModeChange); |
Craig Mautner | c00204b | 2013-03-05 15:02:14 -0800 | [diff] [blame] | 5500 | } |
| 5501 | |
Wale Ogunwale | c5cc301 | 2017-01-13 13:26:16 -0800 | [diff] [blame] | 5502 | void positionChildAt(TaskRecord task, int index) { |
| 5503 | |
| 5504 | if (task.getStack() != this) { |
| 5505 | throw new IllegalArgumentException("AS.positionChildAt: task=" + task |
| 5506 | + " is not a child of stack=" + this + " current parent=" + task.getStack()); |
Wale Ogunwale | e1fe7fa2 | 2016-12-15 18:27:00 -0800 | [diff] [blame] | 5507 | } |
| 5508 | |
| 5509 | task.updateOverrideConfigurationForStack(this); |
| 5510 | |
Jorim Jaggi | 023da53 | 2016-04-20 22:42:32 -0700 | [diff] [blame] | 5511 | final ActivityRecord topRunningActivity = task.topRunningActivityLocked(); |
Andrii Kulian | 02b7a83 | 2016-10-06 23:11:56 -0700 | [diff] [blame] | 5512 | final boolean wasResumed = topRunningActivity == task.getStack().mResumedActivity; |
Wale Ogunwale | e1fe7fa2 | 2016-12-15 18:27:00 -0800 | [diff] [blame] | 5513 | insertTaskAtPosition(task, index); |
Andrii Kulian | fb1bf69 | 2017-01-17 11:17:34 -0800 | [diff] [blame] | 5514 | task.setStack(this); |
Winson Chung | 5af42fc | 2017-03-24 17:11:33 -0700 | [diff] [blame] | 5515 | postAddTask(task, null /* prevStack */, true /* schedulePictureInPictureModeChange */); |
Wale Ogunwale | c5cc301 | 2017-01-13 13:26:16 -0800 | [diff] [blame] | 5516 | |
Jorim Jaggi | 023da53 | 2016-04-20 22:42:32 -0700 | [diff] [blame] | 5517 | if (wasResumed) { |
| 5518 | if (mResumedActivity != null) { |
| 5519 | Log.wtf(TAG, "mResumedActivity was already set when moving mResumedActivity from" |
| 5520 | + " other stack to this stack mResumedActivity=" + mResumedActivity |
| 5521 | + " other mResumedActivity=" + topRunningActivity); |
| 5522 | } |
Bryce Lee | c4ab62a | 2018-03-05 14:19:26 -0800 | [diff] [blame] | 5523 | topRunningActivity.setState(RESUMED, "positionChildAt"); |
Jorim Jaggi | 023da53 | 2016-04-20 22:42:32 -0700 | [diff] [blame] | 5524 | } |
Wale Ogunwale | e1fe7fa2 | 2016-12-15 18:27:00 -0800 | [diff] [blame] | 5525 | |
| 5526 | // The task might have already been running and its visibility needs to be synchronized with |
| 5527 | // the visibility of the stack / windows. |
| 5528 | ensureActivitiesVisibleLocked(null, 0, !PRESERVE_WINDOWS); |
Wale Ogunwale | d32da47 | 2018-11-16 07:19:28 -0800 | [diff] [blame] | 5529 | mRootActivityContainer.resumeFocusedStacksTopActivities(); |
Wale Ogunwale | 5f98609 | 2015-12-04 15:35:38 -0800 | [diff] [blame] | 5530 | } |
| 5531 | |
Wale Ogunwale | 06579d6 | 2016-04-30 15:29:06 -0700 | [diff] [blame] | 5532 | private ActivityStack preAddTask(TaskRecord task, String reason, boolean toTop) { |
Andrii Kulian | 02b7a83 | 2016-10-06 23:11:56 -0700 | [diff] [blame] | 5533 | final ActivityStack prevStack = task.getStack(); |
Wale Ogunwale | 5f98609 | 2015-12-04 15:35:38 -0800 | [diff] [blame] | 5534 | if (prevStack != null && prevStack != this) { |
Wale Ogunwale | 06579d6 | 2016-04-30 15:29:06 -0700 | [diff] [blame] | 5535 | prevStack.removeTask(task, reason, |
| 5536 | toTop ? REMOVE_TASK_MODE_MOVING_TO_TOP : REMOVE_TASK_MODE_MOVING); |
Wale Ogunwale | 5f98609 | 2015-12-04 15:35:38 -0800 | [diff] [blame] | 5537 | } |
| 5538 | return prevStack; |
| 5539 | } |
| 5540 | |
Winson Chung | 5af42fc | 2017-03-24 17:11:33 -0700 | [diff] [blame] | 5541 | /** |
| 5542 | * @param schedulePictureInPictureModeChange specifies whether or not to schedule the PiP mode |
| 5543 | * change. Callers may set this to false if they are explicitly scheduling PiP mode |
| 5544 | * changes themselves, like during the PiP animation |
| 5545 | */ |
| 5546 | private void postAddTask(TaskRecord task, ActivityStack prevStack, |
| 5547 | boolean schedulePictureInPictureModeChange) { |
| 5548 | if (schedulePictureInPictureModeChange && prevStack != null) { |
| 5549 | mStackSupervisor.scheduleUpdatePictureInPictureModeIfNeeded(task, prevStack); |
Wale Ogunwale | 5f98609 | 2015-12-04 15:35:38 -0800 | [diff] [blame] | 5550 | } else if (task.voiceSession != null) { |
Wale Ogunwale | ddc1cb2 | 2015-07-25 19:23:04 -0700 | [diff] [blame] | 5551 | try { |
| 5552 | task.voiceSession.taskStarted(task.intent, task.taskId); |
| 5553 | } catch (RemoteException e) { |
| 5554 | } |
| 5555 | } |
| 5556 | } |
| 5557 | |
Kazuki Takise | f85197b | 2018-06-18 18:18:36 +0900 | [diff] [blame] | 5558 | public void setAlwaysOnTop(boolean alwaysOnTop) { |
| 5559 | if (isAlwaysOnTop() == alwaysOnTop) { |
| 5560 | return; |
| 5561 | } |
| 5562 | super.setAlwaysOnTop(alwaysOnTop); |
| 5563 | final ActivityDisplay display = getDisplay(); |
| 5564 | // positionChildAtTop() must be called even when always on top gets turned off because we |
| 5565 | // need to make sure that the stack is moved from among always on top windows to below other |
| 5566 | // always on top windows. Since the position the stack should be inserted into is calculated |
| 5567 | // properly in {@link ActivityDisplay#getTopInsertPosition()} in both cases, we can just |
| 5568 | // request that the stack is put at top here. |
Riddle Hsu | 57831b5 | 2018-07-27 00:31:48 +0800 | [diff] [blame] | 5569 | display.positionChildAtTop(this, false /* includingParents */); |
Kazuki Takise | f85197b | 2018-06-18 18:18:36 +0900 | [diff] [blame] | 5570 | } |
| 5571 | |
Riddle Hsu | 1656713 | 2018-08-16 21:37:47 +0800 | [diff] [blame] | 5572 | /** NOTE: Should only be called from {@link TaskRecord#reparent}. */ |
Winson Chung | c2baac0 | 2017-01-11 13:34:47 -0800 | [diff] [blame] | 5573 | void moveToFrontAndResumeStateIfNeeded(ActivityRecord r, boolean moveToFront, boolean setResume, |
| 5574 | boolean setPause, String reason) { |
Wale Ogunwale | d046a01 | 2015-12-24 13:05:59 -0800 | [diff] [blame] | 5575 | if (!moveToFront) { |
| 5576 | return; |
Wale Ogunwale | 079a004 | 2015-10-24 11:44:07 -0700 | [diff] [blame] | 5577 | } |
Wale Ogunwale | d046a01 | 2015-12-24 13:05:59 -0800 | [diff] [blame] | 5578 | |
Riddle Hsu | 1656713 | 2018-08-16 21:37:47 +0800 | [diff] [blame] | 5579 | final ActivityState origState = r.getState(); |
Wale Ogunwale | d046a01 | 2015-12-24 13:05:59 -0800 | [diff] [blame] | 5580 | // If the activity owns the last resumed activity, transfer that together, |
| 5581 | // so that we don't resume the same activity again in the new stack. |
| 5582 | // Apps may depend on onResume()/onPause() being called in pairs. |
| 5583 | if (setResume) { |
Bryce Lee | c4ab62a | 2018-03-05 14:19:26 -0800 | [diff] [blame] | 5584 | r.setState(RESUMED, "moveToFrontAndResumeStateIfNeeded"); |
Winson Chung | abb433b | 2017-03-24 09:35:42 -0700 | [diff] [blame] | 5585 | updateLRUListLocked(r); |
Wale Ogunwale | d046a01 | 2015-12-24 13:05:59 -0800 | [diff] [blame] | 5586 | } |
Winson Chung | c2baac0 | 2017-01-11 13:34:47 -0800 | [diff] [blame] | 5587 | // If the activity was previously pausing, then ensure we transfer that as well |
| 5588 | if (setPause) { |
| 5589 | mPausingActivity = r; |
Winson Chung | 4dabf23 | 2017-01-25 13:25:22 -0800 | [diff] [blame] | 5590 | schedulePauseTimeout(r); |
Winson Chung | c2baac0 | 2017-01-11 13:34:47 -0800 | [diff] [blame] | 5591 | } |
Riddle Hsu | 1656713 | 2018-08-16 21:37:47 +0800 | [diff] [blame] | 5592 | // Move the stack in which we are placing the activity to the front. |
Wale Ogunwale | d046a01 | 2015-12-24 13:05:59 -0800 | [diff] [blame] | 5593 | moveToFront(reason); |
Riddle Hsu | 1656713 | 2018-08-16 21:37:47 +0800 | [diff] [blame] | 5594 | // If the original state is resumed, there is no state change to update focused app. |
| 5595 | // So here makes sure the activity focus is set if it is the top. |
Wale Ogunwale | d32da47 | 2018-11-16 07:19:28 -0800 | [diff] [blame] | 5596 | if (origState == RESUMED && r == mRootActivityContainer.getTopResumedActivity()) { |
Riddle Hsu | 1656713 | 2018-08-16 21:37:47 +0800 | [diff] [blame] | 5597 | // TODO(b/111361570): Support multiple focused apps in WM |
| 5598 | mService.setResumedActivityUncheckLocked(r, reason); |
| 5599 | } |
Wale Ogunwale | 079a004 | 2015-10-24 11:44:07 -0700 | [diff] [blame] | 5600 | } |
| 5601 | |
Yunfan Chen | 279f558 | 2018-12-12 15:24:50 -0800 | [diff] [blame] | 5602 | |
| 5603 | Rect getDefaultPictureInPictureBounds(float aspectRatio) { |
| 5604 | if (getTaskStack() == null) return null; |
| 5605 | return getTaskStack().getPictureInPictureBounds(aspectRatio, null /* currentStackBounds */); |
| 5606 | } |
| 5607 | |
| 5608 | void animateResizePinnedStack(Rect sourceHintBounds, Rect toBounds, int animationDuration, |
| 5609 | boolean fromFullscreen) { |
| 5610 | if (!inPinnedWindowingMode()) return; |
| 5611 | if (skipResizeAnimation(toBounds == null /* toFullscreen */)) { |
| 5612 | mService.moveTasksToFullscreenStack(mStackId, true /* onTop */); |
| 5613 | } else { |
| 5614 | if (getTaskStack() == null) return; |
| 5615 | getTaskStack().animateResizePinnedStack(toBounds, sourceHintBounds, |
| 5616 | animationDuration, fromFullscreen); |
| 5617 | } |
| 5618 | } |
| 5619 | |
wilsonshih | 5c4cf52 | 2019-01-25 09:03:47 +0800 | [diff] [blame] | 5620 | /** |
| 5621 | * Get current bounds of this stack, return empty when it is unavailable. |
| 5622 | * @see TaskStack#getAnimationOrCurrentBounds(Rect) |
| 5623 | */ |
| 5624 | void getAnimationOrCurrentBounds(Rect outBounds) { |
| 5625 | final TaskStack stack = getTaskStack(); |
| 5626 | if (stack == null) { |
| 5627 | outBounds.setEmpty(); |
| 5628 | return; |
| 5629 | } |
| 5630 | stack.getAnimationOrCurrentBounds(outBounds); |
| 5631 | } |
| 5632 | |
Yunfan Chen | 279f558 | 2018-12-12 15:24:50 -0800 | [diff] [blame] | 5633 | private boolean skipResizeAnimation(boolean toFullscreen) { |
| 5634 | if (!toFullscreen) { |
| 5635 | return false; |
| 5636 | } |
| 5637 | final Configuration parentConfig = getParent().getConfiguration(); |
| 5638 | final ActivityRecord top = topRunningNonOverlayTaskActivity(); |
| 5639 | return top != null && !top.isConfigurationCompatible(parentConfig); |
| 5640 | } |
| 5641 | |
| 5642 | void setPictureInPictureAspectRatio(float aspectRatio) { |
| 5643 | if (getTaskStack() == null) return; |
| 5644 | getTaskStack().setPictureInPictureAspectRatio(aspectRatio); |
| 5645 | } |
| 5646 | |
| 5647 | void setPictureInPictureActions(List<RemoteAction> actions) { |
| 5648 | if (getTaskStack() == null) return; |
| 5649 | getTaskStack().setPictureInPictureActions(actions); |
| 5650 | } |
| 5651 | |
| 5652 | boolean isAnimatingBoundsToFullscreen() { |
| 5653 | if (getTaskStack() == null) return false; |
| 5654 | return getTaskStack().isAnimatingBoundsToFullscreen(); |
| 5655 | } |
| 5656 | |
| 5657 | public void updatePictureInPictureModeForPinnedStackAnimation(Rect targetStackBounds, |
| 5658 | boolean forceUpdate) { |
| 5659 | // It is guaranteed that the activities requiring the update will be in the pinned stack at |
| 5660 | // this point (either reparented before the animation into PiP, or before reparenting after |
| 5661 | // the animation out of PiP) |
| 5662 | synchronized (mService.mGlobalLock) { |
| 5663 | if (!isAttached()) { |
| 5664 | return; |
| 5665 | } |
| 5666 | ArrayList<TaskRecord> tasks = getAllTasks(); |
| 5667 | for (int i = 0; i < tasks.size(); i++) { |
| 5668 | mStackSupervisor.updatePictureInPictureMode(tasks.get(i), targetStackBounds, |
| 5669 | forceUpdate); |
| 5670 | } |
| 5671 | } |
| 5672 | } |
| 5673 | |
Craig Mautner | c00204b | 2013-03-05 15:02:14 -0800 | [diff] [blame] | 5674 | public int getStackId() { |
| 5675 | return mStackId; |
| 5676 | } |
Craig Mautner | de4ef02 | 2013-04-07 19:01:33 -0700 | [diff] [blame] | 5677 | |
| 5678 | @Override |
| 5679 | public String toString() { |
Dianne Hackborn | 2a272d4 | 2013-10-16 13:34:33 -0700 | [diff] [blame] | 5680 | return "ActivityStack{" + Integer.toHexString(System.identityHashCode(this)) |
Wale Ogunwale | 44f036f | 2017-09-29 05:09:09 -0700 | [diff] [blame] | 5681 | + " stackId=" + mStackId + " type=" + activityTypeToString(getActivityType()) |
Wale Ogunwale | 7e1f5f5 | 2017-10-18 15:19:59 -0700 | [diff] [blame] | 5682 | + " mode=" + windowingModeToString(getWindowingMode()) |
Wale Ogunwale | 8e923af | 2018-03-23 08:48:11 -0700 | [diff] [blame] | 5683 | + " visible=" + shouldBeVisible(null /* starting */) |
| 5684 | + " translucent=" + isStackTranslucent(null /* starting */) |
| 5685 | + ", " |
Wale Ogunwale | 44f036f | 2017-09-29 05:09:09 -0700 | [diff] [blame] | 5686 | + mTaskHistory.size() + " tasks}"; |
Craig Mautner | de4ef02 | 2013-04-07 19:01:33 -0700 | [diff] [blame] | 5687 | } |
Wale Ogunwale | 60454db | 2015-01-23 16:05:07 -0800 | [diff] [blame] | 5688 | |
Wale Ogunwale | a0f5b5e | 2017-10-11 09:37:23 -0700 | [diff] [blame] | 5689 | void onLockTaskPackagesUpdated() { |
Craig Mautner | 15df08a | 2015-04-01 12:17:18 -0700 | [diff] [blame] | 5690 | for (int taskNdx = mTaskHistory.size() - 1; taskNdx >= 0; --taskNdx) { |
| 5691 | mTaskHistory.get(taskNdx).setLockTaskAuth(); |
| 5692 | } |
| 5693 | } |
skuhne@google.com | 1b974dc | 2016-12-09 13:41:29 -0800 | [diff] [blame] | 5694 | |
| 5695 | void executeAppTransition(ActivityOptions options) { |
Wale Ogunwale | 3a256e6 | 2018-12-06 14:41:18 -0800 | [diff] [blame] | 5696 | getDisplay().mDisplayContent.executeAppTransition(); |
skuhne@google.com | 1b974dc | 2016-12-09 13:41:29 -0800 | [diff] [blame] | 5697 | ActivityOptions.abort(options); |
| 5698 | } |
David Stevens | 9440dc8 | 2017-03-16 19:00:20 -0700 | [diff] [blame] | 5699 | |
| 5700 | boolean shouldSleepActivities() { |
Wale Ogunwale | 9dcf946 | 2017-09-19 15:13:01 -0700 | [diff] [blame] | 5701 | final ActivityDisplay display = getDisplay(); |
Bryce Lee | 271617a | 2018-03-15 10:39:12 -0700 | [diff] [blame] | 5702 | |
| 5703 | // Do not sleep activities in this stack if we're marked as focused and the keyguard |
| 5704 | // is in the process of going away. |
Tiger Huang | 1e5b10a | 2018-07-30 20:19:51 +0800 | [diff] [blame] | 5705 | if (isFocusedStackOnDisplay() |
Bryce Lee | 271617a | 2018-03-15 10:39:12 -0700 | [diff] [blame] | 5706 | && mStackSupervisor.getKeyguardController().isKeyguardGoingAway()) { |
| 5707 | return false; |
| 5708 | } |
| 5709 | |
Wale Ogunwale | f673393 | 2018-06-27 05:14:34 -0700 | [diff] [blame] | 5710 | return display != null ? display.isSleeping() : mService.isSleepingLocked(); |
David Stevens | 9440dc8 | 2017-03-16 19:00:20 -0700 | [diff] [blame] | 5711 | } |
| 5712 | |
| 5713 | boolean shouldSleepOrShutDownActivities() { |
Wale Ogunwale | f673393 | 2018-06-27 05:14:34 -0700 | [diff] [blame] | 5714 | return shouldSleepActivities() || mService.mShuttingDown; |
David Stevens | 9440dc8 | 2017-03-16 19:00:20 -0700 | [diff] [blame] | 5715 | } |
Steven Timotius | 4346f0a | 2017-09-12 11:07:21 -0700 | [diff] [blame] | 5716 | |
Nataniel Borges | 023ecb5 | 2019-01-16 14:15:43 -0800 | [diff] [blame] | 5717 | public void writeToProto(ProtoOutputStream proto, long fieldId, |
| 5718 | @WindowTraceLogLevel int logLevel) { |
Steven Timotius | 4346f0a | 2017-09-12 11:07:21 -0700 | [diff] [blame] | 5719 | final long token = proto.start(fieldId); |
Nataniel Borges | 023ecb5 | 2019-01-16 14:15:43 -0800 | [diff] [blame] | 5720 | super.writeToProto(proto, CONFIGURATION_CONTAINER, logLevel); |
Steven Timotius | 4346f0a | 2017-09-12 11:07:21 -0700 | [diff] [blame] | 5721 | proto.write(ID, mStackId); |
| 5722 | for (int taskNdx = mTaskHistory.size() - 1; taskNdx >= 0; --taskNdx) { |
| 5723 | final TaskRecord task = mTaskHistory.get(taskNdx); |
Nataniel Borges | 023ecb5 | 2019-01-16 14:15:43 -0800 | [diff] [blame] | 5724 | task.writeToProto(proto, TASKS, logLevel); |
Steven Timotius | 4346f0a | 2017-09-12 11:07:21 -0700 | [diff] [blame] | 5725 | } |
| 5726 | if (mResumedActivity != null) { |
| 5727 | mResumedActivity.writeIdentifierToProto(proto, RESUMED_ACTIVITY); |
| 5728 | } |
| 5729 | proto.write(DISPLAY_ID, mDisplayId); |
Bryce Lee | f3c6a47 | 2017-11-14 14:53:06 -0800 | [diff] [blame] | 5730 | if (!matchParentBounds()) { |
Evan Rosky | dfe3da7 | 2018-10-26 17:21:06 -0700 | [diff] [blame] | 5731 | final Rect bounds = getRequestedOverrideBounds(); |
Bryce Lee | f3c6a47 | 2017-11-14 14:53:06 -0800 | [diff] [blame] | 5732 | bounds.writeToProto(proto, BOUNDS); |
Steven Timotius | 4346f0a | 2017-09-12 11:07:21 -0700 | [diff] [blame] | 5733 | } |
Bryce Lee | f3c6a47 | 2017-11-14 14:53:06 -0800 | [diff] [blame] | 5734 | |
| 5735 | // TODO: Remove, no longer needed with windowingMode. |
| 5736 | proto.write(FULLSCREEN, matchParentBounds()); |
Steven Timotius | 4346f0a | 2017-09-12 11:07:21 -0700 | [diff] [blame] | 5737 | proto.end(token); |
| 5738 | } |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 5739 | } |