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"); |
Wale Ogunwale | d32da47 | 2018-11-16 07:19:28 -0800 | [diff] [blame] | 3056 | return mRootActivityContainer.resumeHomeActivity(prev, reason, mDisplayId); |
Andrii Kulian | 7fc2281 | 2016-12-28 13:04:11 -0800 | [diff] [blame] | 3057 | } |
| 3058 | |
Wale Ogunwale | c5cc301 | 2017-01-13 13:26:16 -0800 | [diff] [blame] | 3059 | /** Returns the position the input task should be placed in this stack. */ |
| 3060 | int getAdjustedPositionForTask(TaskRecord task, int suggestedPosition, |
| 3061 | ActivityRecord starting) { |
| 3062 | |
| 3063 | int maxPosition = mTaskHistory.size(); |
| 3064 | if ((starting != null && starting.okToShowLocked()) |
| 3065 | || (starting == null && task.okToShowLocked())) { |
| 3066 | // If the task or starting activity can be shown, then whatever position is okay. |
| 3067 | return Math.min(suggestedPosition, maxPosition); |
| 3068 | } |
| 3069 | |
| 3070 | // The task can't be shown, put non-current user tasks below current user tasks. |
| 3071 | while (maxPosition > 0) { |
| 3072 | final TaskRecord tmpTask = mTaskHistory.get(maxPosition - 1); |
| 3073 | if (!mStackSupervisor.isCurrentProfileLocked(tmpTask.userId) |
| 3074 | || tmpTask.topRunningActivityLocked() == null) { |
| 3075 | break; |
| 3076 | } |
| 3077 | maxPosition--; |
| 3078 | } |
| 3079 | |
| 3080 | return Math.min(suggestedPosition, maxPosition); |
| 3081 | } |
| 3082 | |
Andrii Kulian | d276563 | 2016-12-12 22:26:34 -0800 | [diff] [blame] | 3083 | /** |
| 3084 | * Used from {@link ActivityStack#positionTask(TaskRecord, int)}. |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 3085 | * @see ActivityTaskManagerService#positionTaskInStack(int, int, int). |
Andrii Kulian | d276563 | 2016-12-12 22:26:34 -0800 | [diff] [blame] | 3086 | */ |
Wale Ogunwale | ddc1cb2 | 2015-07-25 19:23:04 -0700 | [diff] [blame] | 3087 | private void insertTaskAtPosition(TaskRecord task, int position) { |
| 3088 | if (position >= mTaskHistory.size()) { |
| 3089 | insertTaskAtTop(task, null); |
| 3090 | return; |
Evan Rosky | 9c44817 | 2017-11-02 14:19:27 -0700 | [diff] [blame] | 3091 | } else if (position <= 0) { |
| 3092 | insertTaskAtBottom(task); |
| 3093 | return; |
Wale Ogunwale | ddc1cb2 | 2015-07-25 19:23:04 -0700 | [diff] [blame] | 3094 | } |
Wale Ogunwale | c5cc301 | 2017-01-13 13:26:16 -0800 | [diff] [blame] | 3095 | position = getAdjustedPositionForTask(task, position, null /* starting */); |
Wale Ogunwale | ddc1cb2 | 2015-07-25 19:23:04 -0700 | [diff] [blame] | 3096 | mTaskHistory.remove(task); |
| 3097 | mTaskHistory.add(position, task); |
Yunfan Chen | 279f558 | 2018-12-12 15:24:50 -0800 | [diff] [blame] | 3098 | if (mTaskStack != null) { |
| 3099 | // TODO: this could not be false after unification. |
| 3100 | mTaskStack.positionChildAt(task.getTask(), position); |
| 3101 | } |
Wale Ogunwale | ddc1cb2 | 2015-07-25 19:23:04 -0700 | [diff] [blame] | 3102 | updateTaskMovement(task, true); |
| 3103 | } |
| 3104 | |
Wale Ogunwale | c5cc301 | 2017-01-13 13:26:16 -0800 | [diff] [blame] | 3105 | private void insertTaskAtTop(TaskRecord task, ActivityRecord starting) { |
Wale Ogunwale | c5cc301 | 2017-01-13 13:26:16 -0800 | [diff] [blame] | 3106 | // TODO: Better place to put all the code below...may be addTask... |
| 3107 | mTaskHistory.remove(task); |
| 3108 | // Now put task at top. |
| 3109 | final int position = getAdjustedPositionForTask(task, mTaskHistory.size(), starting); |
| 3110 | mTaskHistory.add(position, task); |
| 3111 | updateTaskMovement(task, true); |
Riddle Hsu | 86cb7de | 2018-08-13 23:29:58 +0800 | [diff] [blame] | 3112 | positionChildWindowContainerAtTop(task); |
Wale Ogunwale | e1fe7fa2 | 2016-12-15 18:27:00 -0800 | [diff] [blame] | 3113 | } |
| 3114 | |
Evan Rosky | 9c44817 | 2017-11-02 14:19:27 -0700 | [diff] [blame] | 3115 | private void insertTaskAtBottom(TaskRecord task) { |
Evan Rosky | 9c44817 | 2017-11-02 14:19:27 -0700 | [diff] [blame] | 3116 | mTaskHistory.remove(task); |
| 3117 | final int position = getAdjustedPositionForTask(task, 0, null); |
| 3118 | mTaskHistory.add(position, task); |
| 3119 | updateTaskMovement(task, true); |
Riddle Hsu | 86cb7de | 2018-08-13 23:29:58 +0800 | [diff] [blame] | 3120 | positionChildWindowContainerAtBottom(task); |
Evan Rosky | 9c44817 | 2017-11-02 14:19:27 -0700 | [diff] [blame] | 3121 | } |
| 3122 | |
Bryce Lee | ad5b832 | 2018-03-08 14:28:52 -0800 | [diff] [blame] | 3123 | void startActivityLocked(ActivityRecord r, ActivityRecord focusedTopActivity, |
Winson Chung | b5c41b7 | 2016-12-07 15:00:47 -0800 | [diff] [blame] | 3124 | boolean newTask, boolean keepCurTransition, ActivityOptions options) { |
Wale Ogunwale | 8b19de9 | 2018-11-29 19:58:26 -0800 | [diff] [blame] | 3125 | TaskRecord rTask = r.getTaskRecord(); |
Craig Mautner | d232895 | 2013-03-05 12:46:26 -0800 | [diff] [blame] | 3126 | final int taskId = rTask.taskId; |
Craig Mautner | bb74246 | 2014-07-07 15:28:55 -0700 | [diff] [blame] | 3127 | // mLaunchTaskBehind tasks get placed at the back of the task stack. |
| 3128 | if (!r.mLaunchTaskBehind && (taskForIdLocked(taskId) == null || newTask)) { |
Craig Mautner | 7787877 | 2013-03-04 19:46:24 -0800 | [diff] [blame] | 3129 | // Last activity in task had been removed or ActivityManagerService is reusing task. |
| 3130 | // Insert or replace. |
Craig Mautner | 7787877 | 2013-03-04 19:46:24 -0800 | [diff] [blame] | 3131 | // Might not even be in. |
Wale Ogunwale | 3fcb4a8 | 2015-04-06 14:00:13 -0700 | [diff] [blame] | 3132 | insertTaskAtTop(rTask, r); |
Craig Mautner | 7787877 | 2013-03-04 19:46:24 -0800 | [diff] [blame] | 3133 | } |
Craig Mautner | 525f3d9 | 2013-05-07 14:01:50 -0700 | [diff] [blame] | 3134 | TaskRecord task = null; |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 3135 | if (!newTask) { |
| 3136 | // If starting in an existing task, find where that is... |
Craig Mautner | 70a8693 | 2013-02-28 22:37:44 -0800 | [diff] [blame] | 3137 | boolean startIt = true; |
| 3138 | for (int taskNdx = mTaskHistory.size() - 1; taskNdx >= 0; --taskNdx) { |
| 3139 | task = mTaskHistory.get(taskNdx); |
riddle_hsu | 9bcc6e8 | 2014-07-31 00:26:51 +0800 | [diff] [blame] | 3140 | if (task.getTopActivity() == null) { |
| 3141 | // All activities in task are finishing. |
| 3142 | continue; |
| 3143 | } |
Bryce Lee | af691c0 | 2017-03-20 14:20:22 -0700 | [diff] [blame] | 3144 | if (task == rTask) { |
Craig Mautner | 70a8693 | 2013-02-28 22:37:44 -0800 | [diff] [blame] | 3145 | // Here it is! Now, if this is not yet visible to the |
| 3146 | // user, then just add it without starting; it will |
| 3147 | // get started when the user navigates back to it. |
Craig Mautner | 70a8693 | 2013-02-28 22:37:44 -0800 | [diff] [blame] | 3148 | if (!startIt) { |
| 3149 | if (DEBUG_ADD_REMOVE) Slog.i(TAG, "Adding activity " + r + " to task " |
| 3150 | + task, new RuntimeException("here").fillInStackTrace()); |
Yunfan Chen | 1ee84ea | 2018-11-13 16:03:37 -0800 | [diff] [blame] | 3151 | r.createAppWindowToken(); |
Dianne Hackborn | 8078d8c | 2012-03-20 11:11:26 -0700 | [diff] [blame] | 3152 | ActivityOptions.abort(options); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 3153 | return; |
| 3154 | } |
| 3155 | break; |
Craig Mautner | 70a8693 | 2013-02-28 22:37:44 -0800 | [diff] [blame] | 3156 | } else if (task.numFullscreen > 0) { |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 3157 | startIt = false; |
| 3158 | } |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 3159 | } |
| 3160 | } |
| 3161 | |
Wale Ogunwale | 26c0dfe | 2016-12-14 14:42:30 -0800 | [diff] [blame] | 3162 | // 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] | 3163 | |
Wale Ogunwale | 26c0dfe | 2016-12-14 14:42:30 -0800 | [diff] [blame] | 3164 | // If we are not placing the new activity frontmost, we do not want to deliver the |
| 3165 | // onUserLeaving callback to the actual frontmost activity |
Wale Ogunwale | 8b19de9 | 2018-11-29 19:58:26 -0800 | [diff] [blame] | 3166 | final TaskRecord activityTask = r.getTaskRecord(); |
Bryce Lee | af691c0 | 2017-03-20 14:20:22 -0700 | [diff] [blame] | 3167 | if (task == activityTask && mTaskHistory.indexOf(task) != (mTaskHistory.size() - 1)) { |
Craig Mautner | de4ef02 | 2013-04-07 19:01:33 -0700 | [diff] [blame] | 3168 | mStackSupervisor.mUserLeaving = false; |
Wale Ogunwale | ee006da | 2015-03-30 14:49:25 -0700 | [diff] [blame] | 3169 | if (DEBUG_USER_LEAVING) Slog.v(TAG_USER_LEAVING, |
Craig Mautner | 70a8693 | 2013-02-28 22:37:44 -0800 | [diff] [blame] | 3170 | "startActivity() behind front, mUserLeaving=false"); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 3171 | } |
Craig Mautner | 70a8693 | 2013-02-28 22:37:44 -0800 | [diff] [blame] | 3172 | |
Bryce Lee | af691c0 | 2017-03-20 14:20:22 -0700 | [diff] [blame] | 3173 | task = activityTask; |
Craig Mautner | 70a8693 | 2013-02-28 22:37:44 -0800 | [diff] [blame] | 3174 | |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 3175 | // Slot the activity into the history stack and proceed |
Craig Mautner | 70a8693 | 2013-02-28 22:37:44 -0800 | [diff] [blame] | 3176 | 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] | 3177 | new RuntimeException("here").fillInStackTrace()); |
Wale Ogunwale | a0cd15e | 2017-02-01 15:33:08 -0800 | [diff] [blame] | 3178 | // TODO: Need to investigate if it is okay for the controller to already be created by the |
| 3179 | // time we get to this point. I think it is, but need to double check. |
| 3180 | // Use test in b/34179495 to trace the call path. |
Yunfan Chen | 1ee84ea | 2018-11-13 16:03:37 -0800 | [diff] [blame] | 3181 | if (r.mAppWindowToken == null) { |
| 3182 | r.createAppWindowToken(); |
Wale Ogunwale | a0cd15e | 2017-02-01 15:33:08 -0800 | [diff] [blame] | 3183 | } |
Yunfan Chen | 1ee84ea | 2018-11-13 16:03:37 -0800 | [diff] [blame] | 3184 | |
Craig Mautner | 1aa9d0d3f | 2013-12-16 15:58:31 -0800 | [diff] [blame] | 3185 | task.setFrontOfTask(); |
Craig Mautner | 70a8693 | 2013-02-28 22:37:44 -0800 | [diff] [blame] | 3186 | |
Matthew Ng | ae1ff4f | 2016-11-10 15:49:14 -0800 | [diff] [blame] | 3187 | if (!isHomeOrRecentsStack() || numActivities() > 0) { |
Wale Ogunwale | 3a256e6 | 2018-12-06 14:41:18 -0800 | [diff] [blame] | 3188 | final DisplayContent dc = getDisplay().mDisplayContent; |
Wale Ogunwale | ee006da | 2015-03-30 14:49:25 -0700 | [diff] [blame] | 3189 | if (DEBUG_TRANSITION) Slog.v(TAG_TRANSITION, |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 3190 | "Prepare open transition: starting " + r); |
Wale Ogunwale | ee006da | 2015-03-30 14:49:25 -0700 | [diff] [blame] | 3191 | if ((r.intent.getFlags() & Intent.FLAG_ACTIVITY_NO_ANIMATION) != 0) { |
Wale Ogunwale | 3a256e6 | 2018-12-06 14:41:18 -0800 | [diff] [blame] | 3192 | dc.prepareAppTransition(TRANSIT_NONE, keepCurTransition); |
Jorim Jaggi | fa9ed96 | 2018-01-25 00:16:49 +0100 | [diff] [blame] | 3193 | mStackSupervisor.mNoAnimActivities.add(r); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 3194 | } else { |
Winson Chung | b5c41b7 | 2016-12-07 15:00:47 -0800 | [diff] [blame] | 3195 | int transit = TRANSIT_ACTIVITY_OPEN; |
| 3196 | if (newTask) { |
| 3197 | if (r.mLaunchTaskBehind) { |
| 3198 | transit = TRANSIT_TASK_OPEN_BEHIND; |
| 3199 | } else { |
Winson Chung | c2baac0 | 2017-01-11 13:34:47 -0800 | [diff] [blame] | 3200 | // 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] | 3201 | // supporting picture-in-picture while pausing only if the starting activity |
| 3202 | // would not be considered an overlay on top of the current activity |
| 3203 | // (eg. not fullscreen, or the assistant) |
Winson Chung | f7e03e1 | 2017-08-22 11:32:16 -0700 | [diff] [blame] | 3204 | if (canEnterPipOnTaskSwitch(focusedTopActivity, |
| 3205 | null /* toFrontTask */, r, options)) { |
| 3206 | focusedTopActivity.supportsEnterPipOnTaskSwitch = true; |
Winson Chung | b5c41b7 | 2016-12-07 15:00:47 -0800 | [diff] [blame] | 3207 | } |
| 3208 | transit = TRANSIT_TASK_OPEN; |
| 3209 | } |
| 3210 | } |
Wale Ogunwale | 3a256e6 | 2018-12-06 14:41:18 -0800 | [diff] [blame] | 3211 | dc.prepareAppTransition(transit, keepCurTransition); |
Jorim Jaggi | fa9ed96 | 2018-01-25 00:16:49 +0100 | [diff] [blame] | 3212 | mStackSupervisor.mNoAnimActivities.remove(r); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 3213 | } |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 3214 | boolean doShow = true; |
| 3215 | if (newTask) { |
| 3216 | // Even though this activity is starting fresh, we still need |
| 3217 | // to reset it to make sure we apply affinities to move any |
| 3218 | // existing activities from other tasks in to it. |
| 3219 | // If the caller has requested that the target task be |
| 3220 | // reset, then do so. |
Craig Mautner | 9d4e9bc | 2014-06-18 18:34:56 -0700 | [diff] [blame] | 3221 | if ((r.intent.getFlags() & Intent.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED) != 0) { |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 3222 | resetTaskIfNeededLocked(r, r); |
| 3223 | doShow = topRunningNonDelayedActivityLocked(null) == r; |
| 3224 | } |
Chong Zhang | 280d332 | 2015-11-03 17:27:26 -0800 | [diff] [blame] | 3225 | } else if (options != null && options.getAnimationType() |
George Mount | 70778d7 | 2014-07-01 16:33:45 -0700 | [diff] [blame] | 3226 | == ActivityOptions.ANIM_SCENE_TRANSITION) { |
| 3227 | doShow = false; |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 3228 | } |
Craig Mautner | bb74246 | 2014-07-07 15:28:55 -0700 | [diff] [blame] | 3229 | if (r.mLaunchTaskBehind) { |
| 3230 | // Don't do a starting window for mLaunchTaskBehind. More importantly make sure we |
| 3231 | // 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] | 3232 | r.setVisibility(true); |
Filip Gruszczynski | bc5a6c5 | 2015-09-22 13:13:24 -0700 | [diff] [blame] | 3233 | ensureActivitiesVisibleLocked(null, 0, !PRESERVE_WINDOWS); |
Craig Mautner | bb74246 | 2014-07-07 15:28:55 -0700 | [diff] [blame] | 3234 | } else if (SHOW_APP_STARTING_PREVIEW && doShow) { |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 3235 | // Figure out if we are transitioning from another activity that is |
| 3236 | // "has the same starting icon" as the next one. This allows the |
| 3237 | // window manager to keep the previous window it had previously |
| 3238 | // created, if it still had one. |
Wale Ogunwale | 8b19de9 | 2018-11-29 19:58:26 -0800 | [diff] [blame] | 3239 | TaskRecord prevTask = r.getTaskRecord(); |
Bryce Lee | af691c0 | 2017-03-20 14:20:22 -0700 | [diff] [blame] | 3240 | ActivityRecord prev = prevTask.topRunningActivityWithStartingWindowLocked(); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 3241 | if (prev != null) { |
| 3242 | // We don't want to reuse the previous starting preview if: |
| 3243 | // (1) The current activity is in a different task. |
Wale Ogunwale | 8b19de9 | 2018-11-29 19:58:26 -0800 | [diff] [blame] | 3244 | if (prev.getTaskRecord() != prevTask) { |
Craig Mautner | 29219d9 | 2013-04-16 20:19:12 -0700 | [diff] [blame] | 3245 | prev = null; |
| 3246 | } |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 3247 | // (2) The current activity is already displayed. |
Craig Mautner | 29219d9 | 2013-04-16 20:19:12 -0700 | [diff] [blame] | 3248 | else if (prev.nowVisible) { |
| 3249 | prev = null; |
| 3250 | } |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 3251 | } |
Jorim Jaggi | 02886a8 | 2016-12-06 09:10:06 -0800 | [diff] [blame] | 3252 | r.showStartingWindow(prev, newTask, isTaskSwitch(r, focusedTopActivity)); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 3253 | } |
| 3254 | } else { |
| 3255 | // If this is the first activity, don't do any fancy animations, |
| 3256 | // because there is nothing for it to animate on top of. |
Dianne Hackborn | 8078d8c | 2012-03-20 11:11:26 -0700 | [diff] [blame] | 3257 | ActivityOptions.abort(options); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 3258 | } |
Dianne Hackborn | be70785 | 2011-11-11 14:32:10 -0800 | [diff] [blame] | 3259 | } |
| 3260 | |
Winson Chung | f7e03e1 | 2017-08-22 11:32:16 -0700 | [diff] [blame] | 3261 | /** |
| 3262 | * @return Whether the switch to another task can trigger the currently running activity to |
| 3263 | * enter PiP while it is pausing (if supported). Only one of {@param toFrontTask} or |
| 3264 | * {@param toFrontActivity} should be set. |
| 3265 | */ |
| 3266 | private boolean canEnterPipOnTaskSwitch(ActivityRecord pipCandidate, |
| 3267 | TaskRecord toFrontTask, ActivityRecord toFrontActivity, ActivityOptions opts) { |
| 3268 | if (opts != null && opts.disallowEnterPictureInPictureWhileLaunching()) { |
| 3269 | // Ensure the caller has requested not to trigger auto-enter PiP |
| 3270 | return false; |
| 3271 | } |
Wale Ogunwale | 44f036f | 2017-09-29 05:09:09 -0700 | [diff] [blame] | 3272 | if (pipCandidate == null || pipCandidate.inPinnedWindowingMode()) { |
Winson Chung | f7e03e1 | 2017-08-22 11:32:16 -0700 | [diff] [blame] | 3273 | // Ensure that we do not trigger entering PiP an activity on the pinned stack |
| 3274 | return false; |
| 3275 | } |
Wale Ogunwale | 6827856 | 2017-09-23 17:13:55 -0700 | [diff] [blame] | 3276 | final ActivityStack targetStack = toFrontTask != null |
Wale Ogunwale | 8b19de9 | 2018-11-29 19:58:26 -0800 | [diff] [blame] | 3277 | ? toFrontTask.getStack() : toFrontActivity.getActivityStack(); |
Wale Ogunwale | 6827856 | 2017-09-23 17:13:55 -0700 | [diff] [blame] | 3278 | if (targetStack != null && targetStack.isActivityTypeAssistant()) { |
Winson Chung | f7e03e1 | 2017-08-22 11:32:16 -0700 | [diff] [blame] | 3279 | // Ensure the task/activity being brought forward is not the assistant |
| 3280 | return false; |
| 3281 | } |
Winson Chung | f7e03e1 | 2017-08-22 11:32:16 -0700 | [diff] [blame] | 3282 | return true; |
| 3283 | } |
| 3284 | |
Jorim Jaggi | 02886a8 | 2016-12-06 09:10:06 -0800 | [diff] [blame] | 3285 | private boolean isTaskSwitch(ActivityRecord r, |
| 3286 | ActivityRecord topFocusedActivity) { |
Wale Ogunwale | 8b19de9 | 2018-11-29 19:58:26 -0800 | [diff] [blame] | 3287 | return topFocusedActivity != null && r.getTaskRecord() != topFocusedActivity.getTaskRecord(); |
Jorim Jaggi | 02886a8 | 2016-12-06 09:10:06 -0800 | [diff] [blame] | 3288 | } |
| 3289 | |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 3290 | /** |
| 3291 | * Perform a reset of the given task, if needed as part of launching it. |
| 3292 | * Returns the new HistoryRecord at the top of the task. |
| 3293 | */ |
Craig Mautner | e3a74d5 | 2013-02-22 14:14:58 -0800 | [diff] [blame] | 3294 | /** |
| 3295 | * Helper method for #resetTaskIfNeededLocked. |
| 3296 | * We are inside of the task being reset... we'll either finish this activity, push it out |
| 3297 | * for another task, or leave it as-is. |
| 3298 | * @param task The task containing the Activity (taskTop) that might be reset. |
| 3299 | * @param forceReset |
| 3300 | * @return An ActivityOptions that needs to be processed. |
| 3301 | */ |
Andrii Kulian | 21713ac | 2016-10-12 22:05:05 -0700 | [diff] [blame] | 3302 | private ActivityOptions resetTargetTaskIfNeededLocked(TaskRecord task, boolean forceReset) { |
Craig Mautner | e3a74d5 | 2013-02-22 14:14:58 -0800 | [diff] [blame] | 3303 | ActivityOptions topOptions = null; |
| 3304 | |
| 3305 | int replyChainEnd = -1; |
| 3306 | boolean canMoveOptions = true; |
| 3307 | |
| 3308 | // We only do this for activities that are not the root of the task (since if we finish |
| 3309 | // the root, we may no longer have the task!). |
| 3310 | final ArrayList<ActivityRecord> activities = task.mActivities; |
| 3311 | final int numActivities = activities.size(); |
Craig Mautner | 9d4e9bc | 2014-06-18 18:34:56 -0700 | [diff] [blame] | 3312 | final int rootActivityNdx = task.findEffectiveRootIndex(); |
| 3313 | for (int i = numActivities - 1; i > rootActivityNdx; --i ) { |
Craig Mautner | e3a74d5 | 2013-02-22 14:14:58 -0800 | [diff] [blame] | 3314 | ActivityRecord target = activities.get(i); |
Craig Mautner | 76ae2f0 | 2014-07-16 16:16:19 +0000 | [diff] [blame] | 3315 | if (target.frontOfTask) |
| 3316 | break; |
Craig Mautner | e3a74d5 | 2013-02-22 14:14:58 -0800 | [diff] [blame] | 3317 | |
| 3318 | final int flags = target.info.flags; |
| 3319 | final boolean finishOnTaskLaunch = |
| 3320 | (flags & ActivityInfo.FLAG_FINISH_ON_TASK_LAUNCH) != 0; |
| 3321 | final boolean allowTaskReparenting = |
| 3322 | (flags & ActivityInfo.FLAG_ALLOW_TASK_REPARENTING) != 0; |
| 3323 | final boolean clearWhenTaskReset = |
| 3324 | (target.intent.getFlags() & Intent.FLAG_ACTIVITY_CLEAR_WHEN_TASK_RESET) != 0; |
| 3325 | |
| 3326 | if (!finishOnTaskLaunch |
| 3327 | && !clearWhenTaskReset |
| 3328 | && target.resultTo != null) { |
| 3329 | // If this activity is sending a reply to a previous |
| 3330 | // activity, we can't do anything with it now until |
| 3331 | // we reach the start of the reply chain. |
| 3332 | // XXX note that we are assuming the result is always |
| 3333 | // to the previous activity, which is almost always |
| 3334 | // the case but we really shouldn't count on. |
| 3335 | if (replyChainEnd < 0) { |
| 3336 | replyChainEnd = i; |
| 3337 | } |
| 3338 | } else if (!finishOnTaskLaunch |
| 3339 | && !clearWhenTaskReset |
| 3340 | && allowTaskReparenting |
| 3341 | && target.taskAffinity != null |
| 3342 | && !target.taskAffinity.equals(task.affinity)) { |
| 3343 | // If this activity has an affinity for another |
| 3344 | // task, then we need to move it out of here. We will |
| 3345 | // move it as far out of the way as possible, to the |
| 3346 | // bottom of the activity stack. This also keeps it |
| 3347 | // correctly ordered with any activities we previously |
| 3348 | // moved. |
Craig Mautner | 329f412 | 2013-11-07 09:10:42 -0800 | [diff] [blame] | 3349 | final TaskRecord targetTask; |
Craig Mautner | dccb770 | 2013-09-17 15:53:34 -0700 | [diff] [blame] | 3350 | final ActivityRecord bottom = |
| 3351 | !mTaskHistory.isEmpty() && !mTaskHistory.get(0).mActivities.isEmpty() ? |
Craig Mautner | 329f412 | 2013-11-07 09:10:42 -0800 | [diff] [blame] | 3352 | mTaskHistory.get(0).mActivities.get(0) : null; |
Craig Mautner | dccb770 | 2013-09-17 15:53:34 -0700 | [diff] [blame] | 3353 | if (bottom != null && target.taskAffinity != null |
Wale Ogunwale | 8b19de9 | 2018-11-29 19:58:26 -0800 | [diff] [blame] | 3354 | && target.taskAffinity.equals(bottom.getTaskRecord().affinity)) { |
Craig Mautner | e3a74d5 | 2013-02-22 14:14:58 -0800 | [diff] [blame] | 3355 | // If the activity currently at the bottom has the |
| 3356 | // same task affinity as the one we are moving, |
| 3357 | // then merge it into the same task. |
Wale Ogunwale | 8b19de9 | 2018-11-29 19:58:26 -0800 | [diff] [blame] | 3358 | targetTask = bottom.getTaskRecord(); |
Wale Ogunwale | ee006da | 2015-03-30 14:49:25 -0700 | [diff] [blame] | 3359 | if (DEBUG_TASKS) Slog.v(TAG_TASKS, "Start pushing activity " + target |
Bryce Lee | af691c0 | 2017-03-20 14:20:22 -0700 | [diff] [blame] | 3360 | + " out to bottom task " + targetTask); |
Craig Mautner | e3a74d5 | 2013-02-22 14:14:58 -0800 | [diff] [blame] | 3361 | } else { |
Suprabh Shukla | 09a88f5 | 2015-12-02 14:36:31 -0800 | [diff] [blame] | 3362 | targetTask = createTaskRecord( |
Wale Ogunwale | 8b19de9 | 2018-11-29 19:58:26 -0800 | [diff] [blame] | 3363 | mStackSupervisor.getNextTaskIdForUserLocked(target.mUserId), |
Wale Ogunwale | 6fbde9f | 2017-08-24 07:24:12 -0700 | [diff] [blame] | 3364 | target.info, null, null, null, false); |
Craig Mautner | 329f412 | 2013-11-07 09:10:42 -0800 | [diff] [blame] | 3365 | targetTask.affinityIntent = target.intent; |
Wale Ogunwale | ee006da | 2015-03-30 14:49:25 -0700 | [diff] [blame] | 3366 | if (DEBUG_TASKS) Slog.v(TAG_TASKS, "Start pushing activity " + target |
Bryce Lee | af691c0 | 2017-03-20 14:20:22 -0700 | [diff] [blame] | 3367 | + " out to new task " + targetTask); |
Craig Mautner | e3a74d5 | 2013-02-22 14:14:58 -0800 | [diff] [blame] | 3368 | } |
| 3369 | |
Craig Mautner | 525f3d9 | 2013-05-07 14:01:50 -0700 | [diff] [blame] | 3370 | boolean noOptions = canMoveOptions; |
Craig Mautner | e3a74d5 | 2013-02-22 14:14:58 -0800 | [diff] [blame] | 3371 | final int start = replyChainEnd < 0 ? i : replyChainEnd; |
| 3372 | for (int srcPos = start; srcPos >= i; --srcPos) { |
Craig Mautner | dccb770 | 2013-09-17 15:53:34 -0700 | [diff] [blame] | 3373 | final ActivityRecord p = activities.get(srcPos); |
Craig Mautner | e3a74d5 | 2013-02-22 14:14:58 -0800 | [diff] [blame] | 3374 | if (p.finishing) { |
| 3375 | continue; |
| 3376 | } |
| 3377 | |
Craig Mautner | e3a74d5 | 2013-02-22 14:14:58 -0800 | [diff] [blame] | 3378 | canMoveOptions = false; |
Craig Mautner | 525f3d9 | 2013-05-07 14:01:50 -0700 | [diff] [blame] | 3379 | if (noOptions && topOptions == null) { |
Craig Mautner | e3a74d5 | 2013-02-22 14:14:58 -0800 | [diff] [blame] | 3380 | topOptions = p.takeOptionsLocked(); |
| 3381 | if (topOptions != null) { |
Craig Mautner | 525f3d9 | 2013-05-07 14:01:50 -0700 | [diff] [blame] | 3382 | noOptions = false; |
Craig Mautner | e3a74d5 | 2013-02-22 14:14:58 -0800 | [diff] [blame] | 3383 | } |
| 3384 | } |
Wale Ogunwale | 0fc365c | 2015-05-25 19:35:42 -0700 | [diff] [blame] | 3385 | if (DEBUG_ADD_REMOVE) Slog.i(TAG_ADD_REMOVE, |
| 3386 | "Removing activity " + p + " from task=" + task + " adding to task=" |
| 3387 | + targetTask + " Callers=" + Debug.getCallers(4)); |
Wale Ogunwale | ee006da | 2015-03-30 14:49:25 -0700 | [diff] [blame] | 3388 | if (DEBUG_TASKS) Slog.v(TAG_TASKS, |
Bryce Lee | af691c0 | 2017-03-20 14:20:22 -0700 | [diff] [blame] | 3389 | "Pushing next activity " + p + " out to target's task " + target); |
Wale Ogunwale | a0cd15e | 2017-02-01 15:33:08 -0800 | [diff] [blame] | 3390 | p.reparent(targetTask, 0 /* position - bottom */, "resetTargetTaskIfNeeded"); |
Craig Mautner | e3a74d5 | 2013-02-22 14:14:58 -0800 | [diff] [blame] | 3391 | } |
| 3392 | |
Riddle Hsu | 86cb7de | 2018-08-13 23:29:58 +0800 | [diff] [blame] | 3393 | positionChildWindowContainerAtBottom(targetTask); |
Craig Mautner | e3a74d5 | 2013-02-22 14:14:58 -0800 | [diff] [blame] | 3394 | replyChainEnd = -1; |
| 3395 | } else if (forceReset || finishOnTaskLaunch || clearWhenTaskReset) { |
| 3396 | // If the activity should just be removed -- either |
| 3397 | // because it asks for it, or the task should be |
| 3398 | // cleared -- then finish it and anything that is |
| 3399 | // part of its reply chain. |
| 3400 | int end; |
| 3401 | if (clearWhenTaskReset) { |
| 3402 | // In this case, we want to finish this activity |
| 3403 | // and everything above it, so be sneaky and pretend |
| 3404 | // like these are all in the reply chain. |
Mark Lu | 4b5a9a0 | 2014-12-09 14:47:13 +0800 | [diff] [blame] | 3405 | end = activities.size() - 1; |
Craig Mautner | e3a74d5 | 2013-02-22 14:14:58 -0800 | [diff] [blame] | 3406 | } else if (replyChainEnd < 0) { |
| 3407 | end = i; |
| 3408 | } else { |
| 3409 | end = replyChainEnd; |
| 3410 | } |
Craig Mautner | 525f3d9 | 2013-05-07 14:01:50 -0700 | [diff] [blame] | 3411 | boolean noOptions = canMoveOptions; |
Craig Mautner | e3a74d5 | 2013-02-22 14:14:58 -0800 | [diff] [blame] | 3412 | for (int srcPos = i; srcPos <= end; srcPos++) { |
Craig Mautner | 525f3d9 | 2013-05-07 14:01:50 -0700 | [diff] [blame] | 3413 | ActivityRecord p = activities.get(srcPos); |
Craig Mautner | e3a74d5 | 2013-02-22 14:14:58 -0800 | [diff] [blame] | 3414 | if (p.finishing) { |
| 3415 | continue; |
| 3416 | } |
| 3417 | canMoveOptions = false; |
Craig Mautner | 525f3d9 | 2013-05-07 14:01:50 -0700 | [diff] [blame] | 3418 | if (noOptions && topOptions == null) { |
Craig Mautner | e3a74d5 | 2013-02-22 14:14:58 -0800 | [diff] [blame] | 3419 | topOptions = p.takeOptionsLocked(); |
| 3420 | if (topOptions != null) { |
Craig Mautner | 525f3d9 | 2013-05-07 14:01:50 -0700 | [diff] [blame] | 3421 | noOptions = false; |
Craig Mautner | e3a74d5 | 2013-02-22 14:14:58 -0800 | [diff] [blame] | 3422 | } |
| 3423 | } |
Wale Ogunwale | ee006da | 2015-03-30 14:49:25 -0700 | [diff] [blame] | 3424 | if (DEBUG_TASKS) Slog.w(TAG_TASKS, |
Craig Mautner | 5854780 | 2013-03-05 08:23:53 -0800 | [diff] [blame] | 3425 | "resetTaskIntendedTask: calling finishActivity on " + p); |
Todd Kennedy | 539db51 | 2014-12-15 09:57:55 -0800 | [diff] [blame] | 3426 | if (finishActivityLocked( |
| 3427 | p, Activity.RESULT_CANCELED, null, "reset-task", false)) { |
Craig Mautner | e3a74d5 | 2013-02-22 14:14:58 -0800 | [diff] [blame] | 3428 | end--; |
| 3429 | srcPos--; |
| 3430 | } |
| 3431 | } |
| 3432 | replyChainEnd = -1; |
| 3433 | } else { |
| 3434 | // If we were in the middle of a chain, well the |
| 3435 | // activity that started it all doesn't want anything |
| 3436 | // special, so leave it all as-is. |
| 3437 | replyChainEnd = -1; |
| 3438 | } |
| 3439 | } |
| 3440 | |
| 3441 | return topOptions; |
| 3442 | } |
| 3443 | |
| 3444 | /** |
| 3445 | * Helper method for #resetTaskIfNeededLocked. Processes all of the activities in a given |
| 3446 | * TaskRecord looking for an affinity with the task of resetTaskIfNeededLocked.taskTop. |
| 3447 | * @param affinityTask The task we are looking for an affinity to. |
| 3448 | * @param task Task that resetTaskIfNeededLocked.taskTop belongs to. |
| 3449 | * @param topTaskIsHigher True if #task has already been processed by resetTaskIfNeededLocked. |
| 3450 | * @param forceReset Flag passed in to resetTaskIfNeededLocked. |
| 3451 | */ |
Craig Mautner | 525f3d9 | 2013-05-07 14:01:50 -0700 | [diff] [blame] | 3452 | private int resetAffinityTaskIfNeededLocked(TaskRecord affinityTask, TaskRecord task, |
Craig Mautner | 7787877 | 2013-03-04 19:46:24 -0800 | [diff] [blame] | 3453 | boolean topTaskIsHigher, boolean forceReset, int taskInsertionPoint) { |
Craig Mautner | e3a74d5 | 2013-02-22 14:14:58 -0800 | [diff] [blame] | 3454 | int replyChainEnd = -1; |
| 3455 | final int taskId = task.taskId; |
| 3456 | final String taskAffinity = task.affinity; |
| 3457 | |
| 3458 | final ArrayList<ActivityRecord> activities = affinityTask.mActivities; |
| 3459 | final int numActivities = activities.size(); |
Craig Mautner | 9d4e9bc | 2014-06-18 18:34:56 -0700 | [diff] [blame] | 3460 | final int rootActivityNdx = affinityTask.findEffectiveRootIndex(); |
| 3461 | |
| 3462 | // Do not operate on or below the effective root Activity. |
| 3463 | for (int i = numActivities - 1; i > rootActivityNdx; --i) { |
Craig Mautner | e3a74d5 | 2013-02-22 14:14:58 -0800 | [diff] [blame] | 3464 | ActivityRecord target = activities.get(i); |
Craig Mautner | 76ae2f0 | 2014-07-16 16:16:19 +0000 | [diff] [blame] | 3465 | if (target.frontOfTask) |
| 3466 | break; |
Craig Mautner | e3a74d5 | 2013-02-22 14:14:58 -0800 | [diff] [blame] | 3467 | |
| 3468 | final int flags = target.info.flags; |
| 3469 | boolean finishOnTaskLaunch = (flags & ActivityInfo.FLAG_FINISH_ON_TASK_LAUNCH) != 0; |
| 3470 | boolean allowTaskReparenting = (flags & ActivityInfo.FLAG_ALLOW_TASK_REPARENTING) != 0; |
| 3471 | |
| 3472 | if (target.resultTo != null) { |
| 3473 | // If this activity is sending a reply to a previous |
| 3474 | // activity, we can't do anything with it now until |
| 3475 | // we reach the start of the reply chain. |
| 3476 | // XXX note that we are assuming the result is always |
| 3477 | // to the previous activity, which is almost always |
| 3478 | // the case but we really shouldn't count on. |
| 3479 | if (replyChainEnd < 0) { |
| 3480 | replyChainEnd = i; |
| 3481 | } |
| 3482 | } else if (topTaskIsHigher |
| 3483 | && allowTaskReparenting |
| 3484 | && taskAffinity != null |
| 3485 | && taskAffinity.equals(target.taskAffinity)) { |
| 3486 | // This activity has an affinity for our task. Either remove it if we are |
| 3487 | // clearing or move it over to our task. Note that |
| 3488 | // we currently punt on the case where we are resetting a |
| 3489 | // task that is not at the top but who has activities above |
| 3490 | // with an affinity to it... this is really not a normal |
| 3491 | // case, and we will need to later pull that task to the front |
| 3492 | // and usually at that point we will do the reset and pick |
| 3493 | // up those remaining activities. (This only happens if |
| 3494 | // someone starts an activity in a new task from an activity |
| 3495 | // in a task that is not currently on top.) |
| 3496 | if (forceReset || finishOnTaskLaunch) { |
| 3497 | final int start = replyChainEnd >= 0 ? replyChainEnd : i; |
Wale Ogunwale | ee006da | 2015-03-30 14:49:25 -0700 | [diff] [blame] | 3498 | if (DEBUG_TASKS) Slog.v(TAG_TASKS, |
| 3499 | "Finishing task at index " + start + " to " + i); |
Craig Mautner | e3a74d5 | 2013-02-22 14:14:58 -0800 | [diff] [blame] | 3500 | for (int srcPos = start; srcPos >= i; --srcPos) { |
| 3501 | final ActivityRecord p = activities.get(srcPos); |
| 3502 | if (p.finishing) { |
| 3503 | continue; |
| 3504 | } |
Todd Kennedy | 539db51 | 2014-12-15 09:57:55 -0800 | [diff] [blame] | 3505 | finishActivityLocked( |
| 3506 | p, Activity.RESULT_CANCELED, null, "move-affinity", false); |
Craig Mautner | e3a74d5 | 2013-02-22 14:14:58 -0800 | [diff] [blame] | 3507 | } |
| 3508 | } else { |
Craig Mautner | 7787877 | 2013-03-04 19:46:24 -0800 | [diff] [blame] | 3509 | if (taskInsertionPoint < 0) { |
| 3510 | taskInsertionPoint = task.mActivities.size(); |
Craig Mautner | d232895 | 2013-03-05 12:46:26 -0800 | [diff] [blame] | 3511 | |
Craig Mautner | 7787877 | 2013-03-04 19:46:24 -0800 | [diff] [blame] | 3512 | } |
Craig Mautner | 7787877 | 2013-03-04 19:46:24 -0800 | [diff] [blame] | 3513 | |
| 3514 | final int start = replyChainEnd >= 0 ? replyChainEnd : i; |
Wale Ogunwale | ee006da | 2015-03-30 14:49:25 -0700 | [diff] [blame] | 3515 | if (DEBUG_TASKS) Slog.v(TAG_TASKS, |
| 3516 | "Reparenting from task=" + affinityTask + ":" + start + "-" + i |
| 3517 | + " to task=" + task + ":" + taskInsertionPoint); |
Craig Mautner | 7787877 | 2013-03-04 19:46:24 -0800 | [diff] [blame] | 3518 | for (int srcPos = start; srcPos >= i; --srcPos) { |
Craig Mautner | e3a74d5 | 2013-02-22 14:14:58 -0800 | [diff] [blame] | 3519 | final ActivityRecord p = activities.get(srcPos); |
Winson Chung | 3048004 | 2017-01-26 10:55:34 -0800 | [diff] [blame] | 3520 | p.reparent(task, taskInsertionPoint, "resetAffinityTaskIfNeededLocked"); |
Craig Mautner | e3a74d5 | 2013-02-22 14:14:58 -0800 | [diff] [blame] | 3521 | |
Wale Ogunwale | 0fc365c | 2015-05-25 19:35:42 -0700 | [diff] [blame] | 3522 | if (DEBUG_ADD_REMOVE) Slog.i(TAG_ADD_REMOVE, |
| 3523 | "Removing and adding activity " + p + " to stack at " + task |
| 3524 | + " callers=" + Debug.getCallers(3)); |
Wale Ogunwale | ee006da | 2015-03-30 14:49:25 -0700 | [diff] [blame] | 3525 | if (DEBUG_TASKS) Slog.v(TAG_TASKS, "Pulling activity " + p |
| 3526 | + " from " + srcPos + " in to resetting task " + task); |
Craig Mautner | e3a74d5 | 2013-02-22 14:14:58 -0800 | [diff] [blame] | 3527 | } |
Riddle Hsu | 86cb7de | 2018-08-13 23:29:58 +0800 | [diff] [blame] | 3528 | positionChildWindowContainerAtTop(task); |
Craig Mautner | e3a74d5 | 2013-02-22 14:14:58 -0800 | [diff] [blame] | 3529 | |
| 3530 | // Now we've moved it in to place... but what if this is |
| 3531 | // a singleTop activity and we have put it on top of another |
| 3532 | // instance of the same activity? Then we drop the instance |
| 3533 | // below so it remains singleTop. |
| 3534 | if (target.info.launchMode == ActivityInfo.LAUNCH_SINGLE_TOP) { |
| 3535 | ArrayList<ActivityRecord> taskActivities = task.mActivities; |
Craig Mautner | e3a74d5 | 2013-02-22 14:14:58 -0800 | [diff] [blame] | 3536 | int targetNdx = taskActivities.indexOf(target); |
| 3537 | if (targetNdx > 0) { |
| 3538 | ActivityRecord p = taskActivities.get(targetNdx - 1); |
| 3539 | if (p.intent.getComponent().equals(target.intent.getComponent())) { |
Craig Mautner | 5854780 | 2013-03-05 08:23:53 -0800 | [diff] [blame] | 3540 | finishActivityLocked(p, Activity.RESULT_CANCELED, null, "replace", |
| 3541 | false); |
Craig Mautner | e3a74d5 | 2013-02-22 14:14:58 -0800 | [diff] [blame] | 3542 | } |
| 3543 | } |
| 3544 | } |
| 3545 | } |
| 3546 | |
| 3547 | replyChainEnd = -1; |
| 3548 | } |
| 3549 | } |
Craig Mautner | 7787877 | 2013-03-04 19:46:24 -0800 | [diff] [blame] | 3550 | return taskInsertionPoint; |
Craig Mautner | e3a74d5 | 2013-02-22 14:14:58 -0800 | [diff] [blame] | 3551 | } |
| 3552 | |
Craig Mautner | 8849a5e | 2013-04-02 16:41:03 -0700 | [diff] [blame] | 3553 | final ActivityRecord resetTaskIfNeededLocked(ActivityRecord taskTop, |
Craig Mautner | e3a74d5 | 2013-02-22 14:14:58 -0800 | [diff] [blame] | 3554 | ActivityRecord newActivity) { |
Winson Chung | 5fa3975 | 2017-10-04 14:50:15 -0700 | [diff] [blame] | 3555 | final boolean forceReset = |
Craig Mautner | e3a74d5 | 2013-02-22 14:14:58 -0800 | [diff] [blame] | 3556 | (newActivity.info.flags & ActivityInfo.FLAG_CLEAR_TASK_ON_LAUNCH) != 0; |
Wale Ogunwale | 8b19de9 | 2018-11-29 19:58:26 -0800 | [diff] [blame] | 3557 | final TaskRecord task = taskTop.getTaskRecord(); |
Craig Mautner | e3a74d5 | 2013-02-22 14:14:58 -0800 | [diff] [blame] | 3558 | |
| 3559 | /** False until we evaluate the TaskRecord associated with taskTop. Switches to true |
| 3560 | * for remaining tasks. Used for later tasks to reparent to task. */ |
| 3561 | boolean taskFound = false; |
| 3562 | |
| 3563 | /** If ActivityOptions are moved out and need to be aborted or moved to taskTop. */ |
| 3564 | ActivityOptions topOptions = null; |
| 3565 | |
Craig Mautner | 7787877 | 2013-03-04 19:46:24 -0800 | [diff] [blame] | 3566 | // Preserve the location for reparenting in the new task. |
| 3567 | int reparentInsertionPoint = -1; |
| 3568 | |
Craig Mautner | e3a74d5 | 2013-02-22 14:14:58 -0800 | [diff] [blame] | 3569 | for (int i = mTaskHistory.size() - 1; i >= 0; --i) { |
| 3570 | final TaskRecord targetTask = mTaskHistory.get(i); |
| 3571 | |
| 3572 | if (targetTask == task) { |
| 3573 | topOptions = resetTargetTaskIfNeededLocked(task, forceReset); |
| 3574 | taskFound = true; |
| 3575 | } else { |
Craig Mautner | 7787877 | 2013-03-04 19:46:24 -0800 | [diff] [blame] | 3576 | reparentInsertionPoint = resetAffinityTaskIfNeededLocked(targetTask, task, |
| 3577 | taskFound, forceReset, reparentInsertionPoint); |
Craig Mautner | e3a74d5 | 2013-02-22 14:14:58 -0800 | [diff] [blame] | 3578 | } |
| 3579 | } |
| 3580 | |
Craig Mautner | 70a8693 | 2013-02-28 22:37:44 -0800 | [diff] [blame] | 3581 | int taskNdx = mTaskHistory.indexOf(task); |
riddle_hsu | 1d7919a | 2015-03-11 17:09:50 +0800 | [diff] [blame] | 3582 | if (taskNdx >= 0) { |
| 3583 | do { |
| 3584 | taskTop = mTaskHistory.get(taskNdx--).getTopActivity(); |
| 3585 | } while (taskTop == null && taskNdx >= 0); |
| 3586 | } |
Craig Mautner | 70a8693 | 2013-02-28 22:37:44 -0800 | [diff] [blame] | 3587 | |
Craig Mautner | e3a74d5 | 2013-02-22 14:14:58 -0800 | [diff] [blame] | 3588 | if (topOptions != null) { |
| 3589 | // If we got some ActivityOptions from an activity on top that |
| 3590 | // was removed from the task, propagate them to the new real top. |
| 3591 | if (taskTop != null) { |
Craig Mautner | e3a74d5 | 2013-02-22 14:14:58 -0800 | [diff] [blame] | 3592 | taskTop.updateOptionsLocked(topOptions); |
| 3593 | } else { |
Craig Mautner | e3a74d5 | 2013-02-22 14:14:58 -0800 | [diff] [blame] | 3594 | topOptions.abort(); |
| 3595 | } |
| 3596 | } |
| 3597 | |
| 3598 | return taskTop; |
| 3599 | } |
| 3600 | |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 3601 | void sendActivityResultLocked(int callingUid, ActivityRecord r, |
| 3602 | String resultWho, int requestCode, int resultCode, Intent data) { |
| 3603 | |
| 3604 | if (callingUid > 0) { |
Wale Ogunwale | 6d50dcc | 2018-07-21 23:00:40 -0700 | [diff] [blame] | 3605 | mService.mUgmInternal.grantUriPermissionFromIntent(callingUid, r.packageName, |
Wale Ogunwale | 8b19de9 | 2018-11-29 19:58:26 -0800 | [diff] [blame] | 3606 | data, r.getUriPermissionsLocked(), r.mUserId); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 3607 | } |
| 3608 | |
| 3609 | if (DEBUG_RESULTS) Slog.v(TAG, "Send activity result to " + r |
| 3610 | + " : who=" + resultWho + " req=" + requestCode |
| 3611 | + " res=" + resultCode + " data=" + data); |
Wale Ogunwale | 9e4f3e0 | 2018-05-17 09:35:39 -0700 | [diff] [blame] | 3612 | if (mResumedActivity == r && r.attachedToProcess()) { |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 3613 | try { |
| 3614 | ArrayList<ResultInfo> list = new ArrayList<ResultInfo>(); |
| 3615 | list.add(new ResultInfo(resultWho, requestCode, |
| 3616 | resultCode, data)); |
Wale Ogunwale | 9e4f3e0 | 2018-05-17 09:35:39 -0700 | [diff] [blame] | 3617 | mService.getLifecycleManager().scheduleTransaction(r.app.getThread(), r.appToken, |
Andrii Kulian | 9c5ea9c | 2017-12-07 09:31:01 -0800 | [diff] [blame] | 3618 | ActivityResultItem.obtain(list)); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 3619 | return; |
| 3620 | } catch (Exception e) { |
| 3621 | Slog.w(TAG, "Exception thrown sending result to " + r, e); |
| 3622 | } |
| 3623 | } |
| 3624 | |
| 3625 | r.addResultLocked(null, resultWho, requestCode, resultCode, data); |
| 3626 | } |
| 3627 | |
Shunta Sato | 63b8ee3 | 2016-07-11 13:32:52 +0900 | [diff] [blame] | 3628 | /** 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] | 3629 | private boolean isATopFinishingTask(TaskRecord task) { |
Shunta Sato | 63b8ee3 | 2016-07-11 13:32:52 +0900 | [diff] [blame] | 3630 | for (int i = mTaskHistory.size() - 1; i >= 0; --i) { |
| 3631 | final TaskRecord current = mTaskHistory.get(i); |
| 3632 | final ActivityRecord r = current.topRunningActivityLocked(); |
| 3633 | if (r != null) { |
| 3634 | // We got a top running activity, so there isn't a top finishing task... |
| 3635 | return false; |
| 3636 | } |
| 3637 | if (current == task) { |
| 3638 | return true; |
| 3639 | } |
| 3640 | } |
| 3641 | return false; |
| 3642 | } |
| 3643 | |
Wale Ogunwale | 66e1685 | 2017-10-19 13:35:52 -0700 | [diff] [blame] | 3644 | private void adjustFocusedActivityStack(ActivityRecord r, String reason) { |
Wale Ogunwale | d32da47 | 2018-11-16 07:19:28 -0800 | [diff] [blame] | 3645 | if (!mRootActivityContainer.isTopDisplayFocusedStack(this) || |
Shunta Sato | 63b8ee3 | 2016-07-11 13:32:52 +0900 | [diff] [blame] | 3646 | ((mResumedActivity != r) && (mResumedActivity != null))) { |
Wale Ogunwale | d045c82 | 2015-12-02 09:14:28 -0800 | [diff] [blame] | 3647 | return; |
| 3648 | } |
| 3649 | |
| 3650 | final ActivityRecord next = topRunningActivityLocked(); |
| 3651 | final String myReason = reason + " adjustFocus"; |
Bryce Lee | 3345c4e | 2017-04-25 07:40:41 -0700 | [diff] [blame] | 3652 | |
Wale Ogunwale | 66e1685 | 2017-10-19 13:35:52 -0700 | [diff] [blame] | 3653 | if (next == r) { |
Wale Ogunwale | d32da47 | 2018-11-16 07:19:28 -0800 | [diff] [blame] | 3654 | final ActivityRecord top = mRootActivityContainer.topRunningActivity(); |
Louis Chang | 1944345 | 2018-10-09 12:10:21 +0800 | [diff] [blame] | 3655 | if (top != null) { |
| 3656 | top.moveFocusableActivityToTop(myReason); |
| 3657 | } |
Wale Ogunwale | 66e1685 | 2017-10-19 13:35:52 -0700 | [diff] [blame] | 3658 | return; |
Wale Ogunwale | d045c82 | 2015-12-02 09:14:28 -0800 | [diff] [blame] | 3659 | } |
Wale Ogunwale | d697cea | 2015-02-20 17:19:49 -0800 | [diff] [blame] | 3660 | |
Wale Ogunwale | 66e1685 | 2017-10-19 13:35:52 -0700 | [diff] [blame] | 3661 | if (next != null && isFocusable()) { |
| 3662 | // Keep focus in stack if we have a top running activity and are focusable. |
| 3663 | return; |
| 3664 | } |
| 3665 | |
| 3666 | // Task is not guaranteed to be non-null. For example, destroying the |
| 3667 | // {@link ActivityRecord} will disassociate the task from the activity. |
Wale Ogunwale | 8b19de9 | 2018-11-29 19:58:26 -0800 | [diff] [blame] | 3668 | final TaskRecord task = r.getTaskRecord(); |
Wale Ogunwale | 66e1685 | 2017-10-19 13:35:52 -0700 | [diff] [blame] | 3669 | |
| 3670 | if (task == null) { |
| 3671 | throw new IllegalStateException("activity no longer associated with task:" + r); |
| 3672 | } |
| 3673 | |
| 3674 | // Move focus to next focusable stack if possible. |
Riddle Hsu | 3026e8d | 2018-08-03 15:50:53 +0800 | [diff] [blame] | 3675 | final ActivityStack nextFocusableStack = adjustFocusToNextFocusableStack(myReason); |
| 3676 | if (nextFocusableStack != null) { |
| 3677 | final ActivityRecord top = nextFocusableStack.topRunningActivityLocked(); |
Wale Ogunwale | d32da47 | 2018-11-16 07:19:28 -0800 | [diff] [blame] | 3678 | if (top != null && top == mRootActivityContainer.getTopResumedActivity()) { |
Riddle Hsu | 3026e8d | 2018-08-03 15:50:53 +0800 | [diff] [blame] | 3679 | // TODO(b/111361570): Remove this and update focused app per-display in |
| 3680 | // WindowManager every time an activity becomes resumed in |
| 3681 | // ActivityTaskManagerService#setResumedActivityUncheckLocked(). |
| 3682 | mService.setResumedActivityUncheckLocked(top, reason); |
| 3683 | } |
Wale Ogunwale | 66e1685 | 2017-10-19 13:35:52 -0700 | [diff] [blame] | 3684 | return; |
| 3685 | } |
| 3686 | |
| 3687 | // Whatever...go home. |
Louis Chang | bd48dca | 2018-08-29 17:44:34 +0800 | [diff] [blame] | 3688 | getDisplay().moveHomeActivityToTop(myReason); |
Craig Mautner | 04f0b70 | 2013-10-22 12:31:01 -0700 | [diff] [blame] | 3689 | } |
| 3690 | |
Andrii Kulian | ab132ee | 2018-07-24 22:10:21 +0800 | [diff] [blame] | 3691 | /** |
| 3692 | * Find next proper focusable stack and make it focused. |
| 3693 | * @return The stack that now got the focus, {@code null} if none found. |
| 3694 | */ |
| 3695 | ActivityStack adjustFocusToNextFocusableStack(String reason) { |
Wale Ogunwale | 66e1685 | 2017-10-19 13:35:52 -0700 | [diff] [blame] | 3696 | return adjustFocusToNextFocusableStack(reason, false /* allowFocusSelf */); |
Andrii Kulian | 250d653 | 2017-02-08 23:30:45 -0800 | [diff] [blame] | 3697 | } |
| 3698 | |
| 3699 | /** |
| 3700 | * Find next proper focusable stack and make it focused. |
| 3701 | * @param allowFocusSelf Is the focus allowed to remain on the same stack. |
Andrii Kulian | ab132ee | 2018-07-24 22:10:21 +0800 | [diff] [blame] | 3702 | * @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] | 3703 | */ |
Andrii Kulian | ab132ee | 2018-07-24 22:10:21 +0800 | [diff] [blame] | 3704 | private ActivityStack adjustFocusToNextFocusableStack(String reason, boolean allowFocusSelf) { |
Wale Ogunwale | e1f68ce | 2018-03-09 08:58:54 -0800 | [diff] [blame] | 3705 | final ActivityStack stack = |
Wale Ogunwale | d32da47 | 2018-11-16 07:19:28 -0800 | [diff] [blame] | 3706 | mRootActivityContainer.getNextFocusableStack(this, !allowFocusSelf); |
Wale Ogunwale | 4cea0f5 | 2015-12-25 06:30:31 -0800 | [diff] [blame] | 3707 | final String myReason = reason + " adjustFocusToNextFocusableStack"; |
Wale Ogunwale | d697cea | 2015-02-20 17:19:49 -0800 | [diff] [blame] | 3708 | if (stack == null) { |
Andrii Kulian | ab132ee | 2018-07-24 22:10:21 +0800 | [diff] [blame] | 3709 | return null; |
Wale Ogunwale | d697cea | 2015-02-20 17:19:49 -0800 | [diff] [blame] | 3710 | } |
Wale Ogunwale | d34e80c | 2016-03-23 17:08:44 -0700 | [diff] [blame] | 3711 | |
Wale Ogunwale | c750f5f | 2016-03-28 07:43:51 -0700 | [diff] [blame] | 3712 | final ActivityRecord top = stack.topRunningActivityLocked(); |
| 3713 | |
Wale Ogunwale | 66e1685 | 2017-10-19 13:35:52 -0700 | [diff] [blame] | 3714 | if (stack.isActivityTypeHome() && (top == null || !top.visible)) { |
Wale Ogunwale | c750f5f | 2016-03-28 07:43:51 -0700 | [diff] [blame] | 3715 | // 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] | 3716 | // 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] | 3717 | stack.getDisplay().moveHomeActivityToTop(reason); |
Andrii Kulian | ab132ee | 2018-07-24 22:10:21 +0800 | [diff] [blame] | 3718 | return stack; |
Wale Ogunwale | d34e80c | 2016-03-23 17:08:44 -0700 | [diff] [blame] | 3719 | } |
Chong Zhang | 6cda19c | 2016-06-14 19:07:56 -0700 | [diff] [blame] | 3720 | |
| 3721 | stack.moveToFront(myReason); |
Andrii Kulian | ab132ee | 2018-07-24 22:10:21 +0800 | [diff] [blame] | 3722 | return stack; |
Wale Ogunwale | d697cea | 2015-02-20 17:19:49 -0800 | [diff] [blame] | 3723 | } |
| 3724 | |
Craig Mautner | f333327 | 2013-04-22 10:55:53 -0700 | [diff] [blame] | 3725 | final void stopActivityLocked(ActivityRecord r) { |
Wale Ogunwale | ee006da | 2015-03-30 14:49:25 -0700 | [diff] [blame] | 3726 | if (DEBUG_SWITCH) Slog.d(TAG_SWITCH, "Stopping: " + r); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 3727 | if ((r.intent.getFlags()&Intent.FLAG_ACTIVITY_NO_HISTORY) != 0 |
| 3728 | || (r.info.flags&ActivityInfo.FLAG_NO_HISTORY) != 0) { |
| 3729 | if (!r.finishing) { |
David Stevens | 9440dc8 | 2017-03-16 19:00:20 -0700 | [diff] [blame] | 3730 | if (!shouldSleepActivities()) { |
Wale Ogunwale | 0fc365c | 2015-05-25 19:35:42 -0700 | [diff] [blame] | 3731 | if (DEBUG_STATES) Slog.d(TAG_STATES, "no-history finish of " + r); |
Wale Ogunwale | 3f529ee | 2015-07-12 15:14:01 -0700 | [diff] [blame] | 3732 | if (requestFinishActivityLocked(r.appToken, Activity.RESULT_CANCELED, null, |
| 3733 | "stop-no-history", false)) { |
Bryce Lee | 3345c4e | 2017-04-25 07:40:41 -0700 | [diff] [blame] | 3734 | // If {@link requestFinishActivityLocked} returns {@code true}, |
Wale Ogunwale | 66e1685 | 2017-10-19 13:35:52 -0700 | [diff] [blame] | 3735 | // {@link adjustFocusedActivityStack} would have been already called. |
Wale Ogunwale | 3f529ee | 2015-07-12 15:14:01 -0700 | [diff] [blame] | 3736 | r.resumeKeyDispatchingLocked(); |
| 3737 | return; |
| 3738 | } |
Christopher Tate | d3f175c | 2012-06-14 14:16:54 -0700 | [diff] [blame] | 3739 | } else { |
Wale Ogunwale | 0fc365c | 2015-05-25 19:35:42 -0700 | [diff] [blame] | 3740 | if (DEBUG_STATES) Slog.d(TAG_STATES, "Not finishing noHistory " + r |
Christopher Tate | d3f175c | 2012-06-14 14:16:54 -0700 | [diff] [blame] | 3741 | + " on stop because we're just sleeping"); |
| 3742 | } |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 3743 | } |
Christopher Tate | 5007ddd | 2012-06-12 13:08:18 -0700 | [diff] [blame] | 3744 | } |
| 3745 | |
Wale Ogunwale | 9e4f3e0 | 2018-05-17 09:35:39 -0700 | [diff] [blame] | 3746 | if (r.attachedToProcess()) { |
Wale Ogunwale | 66e1685 | 2017-10-19 13:35:52 -0700 | [diff] [blame] | 3747 | adjustFocusedActivityStack(r, "stopActivity"); |
Dianne Hackborn | 621e2fe | 2012-02-16 17:07:33 -0800 | [diff] [blame] | 3748 | r.resumeKeyDispatchingLocked(); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 3749 | try { |
| 3750 | r.stopped = false; |
Wale Ogunwale | 0fc365c | 2015-05-25 19:35:42 -0700 | [diff] [blame] | 3751 | if (DEBUG_STATES) Slog.v(TAG_STATES, |
| 3752 | "Moving to STOPPING: " + r + " (stop requested)"); |
Bryce Lee | 7ace395 | 2018-02-16 14:34:32 -0800 | [diff] [blame] | 3753 | r.setState(STOPPING, "stopActivityLocked"); |
Wale Ogunwale | ee006da | 2015-03-30 14:49:25 -0700 | [diff] [blame] | 3754 | if (DEBUG_VISIBILITY) Slog.v(TAG_VISIBILITY, |
| 3755 | "Stopping visible=" + r.visible + " for " + r); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 3756 | if (!r.visible) { |
Wale Ogunwale | b9a0c99 | 2017-04-18 07:25:20 -0700 | [diff] [blame] | 3757 | r.setVisible(false); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 3758 | } |
Wale Ogunwale | cd7043e | 2016-02-27 17:37:46 -0800 | [diff] [blame] | 3759 | EventLogTags.writeAmStopActivity( |
Wale Ogunwale | 8b19de9 | 2018-11-29 19:58:26 -0800 | [diff] [blame] | 3760 | r.mUserId, System.identityHashCode(r), r.shortComponentName); |
Wale Ogunwale | 9e4f3e0 | 2018-05-17 09:35:39 -0700 | [diff] [blame] | 3761 | mService.getLifecycleManager().scheduleTransaction(r.app.getThread(), r.appToken, |
Bryce Lee | 1d0d514 | 2018-04-12 10:35:07 -0700 | [diff] [blame] | 3762 | StopActivityItem.obtain(r.visible, r.configChangeFlags)); |
David Stevens | 9440dc8 | 2017-03-16 19:00:20 -0700 | [diff] [blame] | 3763 | if (shouldSleepOrShutDownActivities()) { |
Dianne Hackborn | 4eba96b | 2011-01-21 13:34:36 -0800 | [diff] [blame] | 3764 | r.setSleeping(true); |
| 3765 | } |
Craig Mautner | f7bfefb | 2013-05-16 17:30:44 -0700 | [diff] [blame] | 3766 | Message msg = mHandler.obtainMessage(STOP_TIMEOUT_MSG, r); |
Dianne Hackborn | 162bc0e | 2012-04-09 14:06:16 -0700 | [diff] [blame] | 3767 | mHandler.sendMessageDelayed(msg, STOP_TIMEOUT); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 3768 | } catch (Exception e) { |
| 3769 | // Maybe just ignore exceptions here... if the process |
| 3770 | // has crashed, our death notification will clean things |
| 3771 | // up. |
| 3772 | Slog.w(TAG, "Exception thrown during pause", e); |
| 3773 | // Just in case, assume it to be stopped. |
| 3774 | r.stopped = true; |
Wale Ogunwale | 0fc365c | 2015-05-25 19:35:42 -0700 | [diff] [blame] | 3775 | 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] | 3776 | r.setState(STOPPED, "stopActivityLocked"); |
Wale Ogunwale | f81c1d1 | 2016-01-12 12:20:18 -0800 | [diff] [blame] | 3777 | if (r.deferRelaunchUntilPaused) { |
Craig Mautner | ee2e45a | 2014-06-27 12:10:03 -0700 | [diff] [blame] | 3778 | destroyActivityLocked(r, true, "stop-except"); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 3779 | } |
| 3780 | } |
| 3781 | } |
| 3782 | } |
Craig Mautner | 23ac33b | 2013-04-01 16:26:35 -0700 | [diff] [blame] | 3783 | |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 3784 | /** |
| 3785 | * @return Returns true if the activity is being finished, false if for |
| 3786 | * some reason it is being left as-is. |
| 3787 | */ |
| 3788 | final boolean requestFinishActivityLocked(IBinder token, int resultCode, |
Dianne Hackborn | 2d1b378 | 2012-09-09 17:49:39 -0700 | [diff] [blame] | 3789 | Intent resultData, String reason, boolean oomAdj) { |
Craig Mautner | d74f7d7 | 2013-02-26 13:41:02 -0800 | [diff] [blame] | 3790 | ActivityRecord r = isInStackLocked(token); |
Wale Ogunwale | 0fc365c | 2015-05-25 19:35:42 -0700 | [diff] [blame] | 3791 | if (DEBUG_RESULTS || DEBUG_STATES) Slog.v(TAG_STATES, |
| 3792 | "Finishing activity token=" + token + " r=" |
Christopher Tate | d3f175c | 2012-06-14 14:16:54 -0700 | [diff] [blame] | 3793 | + ", result=" + resultCode + ", data=" + resultData |
| 3794 | + ", reason=" + reason); |
Craig Mautner | d74f7d7 | 2013-02-26 13:41:02 -0800 | [diff] [blame] | 3795 | if (r == null) { |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 3796 | return false; |
| 3797 | } |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 3798 | |
Craig Mautner | d44711d | 2013-02-23 11:24:36 -0800 | [diff] [blame] | 3799 | finishActivityLocked(r, resultCode, resultData, reason, oomAdj); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 3800 | return true; |
| 3801 | } |
| 3802 | |
Craig Mautner | d232895 | 2013-03-05 12:46:26 -0800 | [diff] [blame] | 3803 | final void finishSubActivityLocked(ActivityRecord self, String resultWho, int requestCode) { |
Craig Mautner | 9658b31 | 2013-02-28 10:55:59 -0800 | [diff] [blame] | 3804 | for (int taskNdx = mTaskHistory.size() - 1; taskNdx >= 0; --taskNdx) { |
| 3805 | ArrayList<ActivityRecord> activities = mTaskHistory.get(taskNdx).mActivities; |
| 3806 | for (int activityNdx = activities.size() - 1; activityNdx >= 0; --activityNdx) { |
| 3807 | ActivityRecord r = activities.get(activityNdx); |
| 3808 | if (r.resultTo == self && r.requestCode == requestCode) { |
| 3809 | if ((r.resultWho == null && resultWho == null) || |
| 3810 | (r.resultWho != null && r.resultWho.equals(resultWho))) { |
| 3811 | finishActivityLocked(r, Activity.RESULT_CANCELED, null, "request-sub", |
| 3812 | false); |
| 3813 | } |
Dianne Hackborn | ecc5a9c | 2012-04-26 18:56:09 -0700 | [diff] [blame] | 3814 | } |
| 3815 | } |
| 3816 | } |
Wale Ogunwale | f673393 | 2018-06-27 05:14:34 -0700 | [diff] [blame] | 3817 | mService.updateOomAdj(); |
Dianne Hackborn | ecc5a9c | 2012-04-26 18:56:09 -0700 | [diff] [blame] | 3818 | } |
| 3819 | |
Andrii Kulian | 8cc92ac6 | 2018-04-02 23:14:18 -0700 | [diff] [blame] | 3820 | /** |
| 3821 | * Finish the topmost activity that belongs to the crashed app. We may also finish the activity |
| 3822 | * that requested launch of the crashed one to prevent launch-crash loop. |
| 3823 | * @param app The app that crashed. |
| 3824 | * @param reason Reason to perform this action. |
| 3825 | * @return The task that was finished in this stack, {@code null} if top running activity does |
| 3826 | * not belong to the crashed app. |
| 3827 | */ |
Wale Ogunwale | 9e4f3e0 | 2018-05-17 09:35:39 -0700 | [diff] [blame] | 3828 | final TaskRecord finishTopCrashedActivityLocked(WindowProcessController app, String reason) { |
Filip Gruszczynski | 3e85ba2 | 2015-10-05 22:48:30 -0700 | [diff] [blame] | 3829 | ActivityRecord r = topRunningActivityLocked(); |
Adrian Roos | 20d7df3 | 2016-01-12 18:59:43 +0100 | [diff] [blame] | 3830 | TaskRecord finishedTask = null; |
| 3831 | if (r == null || r.app != app) { |
| 3832 | return null; |
| 3833 | } |
| 3834 | Slog.w(TAG, " Force finishing activity " |
| 3835 | + r.intent.getComponent().flattenToShortString()); |
Wale Ogunwale | 8b19de9 | 2018-11-29 19:58:26 -0800 | [diff] [blame] | 3836 | finishedTask = r.getTaskRecord(); |
Bryce Lee | af691c0 | 2017-03-20 14:20:22 -0700 | [diff] [blame] | 3837 | int taskNdx = mTaskHistory.indexOf(finishedTask); |
| 3838 | final TaskRecord task = finishedTask; |
| 3839 | int activityNdx = task.mActivities.indexOf(r); |
Wale Ogunwale | 3a256e6 | 2018-12-06 14:41:18 -0800 | [diff] [blame] | 3840 | getDisplay().mDisplayContent.prepareAppTransition( |
lumark | 588a3e8 | 2018-07-20 18:53:54 +0800 | [diff] [blame] | 3841 | TRANSIT_CRASHING_ACTIVITY_CLOSE, false /* alwaysKeepCurrent */); |
Adrian Roos | 20d7df3 | 2016-01-12 18:59:43 +0100 | [diff] [blame] | 3842 | finishActivityLocked(r, Activity.RESULT_CANCELED, null, reason, false); |
Bryce Lee | af691c0 | 2017-03-20 14:20:22 -0700 | [diff] [blame] | 3843 | finishedTask = task; |
Adrian Roos | 20d7df3 | 2016-01-12 18:59:43 +0100 | [diff] [blame] | 3844 | // Also terminate any activities below it that aren't yet |
| 3845 | // stopped, to avoid a situation where one will get |
| 3846 | // re-start our crashing activity once it gets resumed again. |
| 3847 | --activityNdx; |
| 3848 | if (activityNdx < 0) { |
| 3849 | do { |
| 3850 | --taskNdx; |
| 3851 | if (taskNdx < 0) { |
| 3852 | break; |
| 3853 | } |
| 3854 | activityNdx = mTaskHistory.get(taskNdx).mActivities.size() - 1; |
| 3855 | } while (activityNdx < 0); |
| 3856 | } |
| 3857 | if (activityNdx >= 0) { |
| 3858 | r = mTaskHistory.get(taskNdx).mActivities.get(activityNdx); |
Bryce Lee | 7ace395 | 2018-02-16 14:34:32 -0800 | [diff] [blame] | 3859 | if (r.isState(RESUMED, PAUSING, PAUSED)) { |
Wale Ogunwale | 9e4f3e0 | 2018-05-17 09:35:39 -0700 | [diff] [blame] | 3860 | if (!r.isActivityTypeHome() || mService.mHomeProcess != r.app) { |
Adrian Roos | 20d7df3 | 2016-01-12 18:59:43 +0100 | [diff] [blame] | 3861 | Slog.w(TAG, " Force finishing activity " |
| 3862 | + r.intent.getComponent().flattenToShortString()); |
| 3863 | finishActivityLocked(r, Activity.RESULT_CANCELED, null, reason, false); |
Craig Mautner | 05d6272ba | 2013-02-11 09:39:27 -0800 | [diff] [blame] | 3864 | } |
| 3865 | } |
| 3866 | } |
Adrian Roos | 20d7df3 | 2016-01-12 18:59:43 +0100 | [diff] [blame] | 3867 | return finishedTask; |
Craig Mautner | 05d6272ba | 2013-02-11 09:39:27 -0800 | [diff] [blame] | 3868 | } |
| 3869 | |
Dianne Hackborn | 6ea0d0a | 2014-07-02 16:23:21 -0700 | [diff] [blame] | 3870 | final void finishVoiceTask(IVoiceInteractionSession session) { |
| 3871 | IBinder sessionBinder = session.asBinder(); |
| 3872 | boolean didOne = false; |
| 3873 | for (int taskNdx = mTaskHistory.size() - 1; taskNdx >= 0; --taskNdx) { |
| 3874 | TaskRecord tr = mTaskHistory.get(taskNdx); |
| 3875 | if (tr.voiceSession != null && tr.voiceSession.asBinder() == sessionBinder) { |
| 3876 | for (int activityNdx = tr.mActivities.size() - 1; activityNdx >= 0; --activityNdx) { |
| 3877 | ActivityRecord r = tr.mActivities.get(activityNdx); |
| 3878 | if (!r.finishing) { |
| 3879 | finishActivityLocked(r, Activity.RESULT_CANCELED, null, "finish-voice", |
| 3880 | false); |
| 3881 | didOne = true; |
| 3882 | } |
| 3883 | } |
Amith Yamasani | 0af6fa7 | 2016-01-17 15:36:19 -0800 | [diff] [blame] | 3884 | } else { |
| 3885 | // Check if any of the activities are using voice |
| 3886 | for (int activityNdx = tr.mActivities.size() - 1; activityNdx >= 0; --activityNdx) { |
| 3887 | ActivityRecord r = tr.mActivities.get(activityNdx); |
Wale Ogunwale | 9e4f3e0 | 2018-05-17 09:35:39 -0700 | [diff] [blame] | 3888 | if (r.voiceSession != null && r.voiceSession.asBinder() == sessionBinder) { |
Amith Yamasani | 0af6fa7 | 2016-01-17 15:36:19 -0800 | [diff] [blame] | 3889 | // Inform of cancellation |
| 3890 | r.clearVoiceSessionLocked(); |
| 3891 | try { |
Wale Ogunwale | 9e4f3e0 | 2018-05-17 09:35:39 -0700 | [diff] [blame] | 3892 | r.app.getThread().scheduleLocalVoiceInteractionStarted( |
| 3893 | r.appToken, null); |
Amith Yamasani | 0af6fa7 | 2016-01-17 15:36:19 -0800 | [diff] [blame] | 3894 | } catch (RemoteException re) { |
| 3895 | // Ok |
| 3896 | } |
Wale Ogunwale | f673393 | 2018-06-27 05:14:34 -0700 | [diff] [blame] | 3897 | mService.finishRunningVoiceLocked(); |
Amith Yamasani | 0af6fa7 | 2016-01-17 15:36:19 -0800 | [diff] [blame] | 3898 | break; |
| 3899 | } |
| 3900 | } |
Dianne Hackborn | 6ea0d0a | 2014-07-02 16:23:21 -0700 | [diff] [blame] | 3901 | } |
| 3902 | } |
Amith Yamasani | 0af6fa7 | 2016-01-17 15:36:19 -0800 | [diff] [blame] | 3903 | |
Dianne Hackborn | 6ea0d0a | 2014-07-02 16:23:21 -0700 | [diff] [blame] | 3904 | if (didOne) { |
Wale Ogunwale | f673393 | 2018-06-27 05:14:34 -0700 | [diff] [blame] | 3905 | mService.updateOomAdj(); |
Dianne Hackborn | 6ea0d0a | 2014-07-02 16:23:21 -0700 | [diff] [blame] | 3906 | } |
| 3907 | } |
| 3908 | |
Craig Mautner | d232895 | 2013-03-05 12:46:26 -0800 | [diff] [blame] | 3909 | final boolean finishActivityAffinityLocked(ActivityRecord r) { |
Wale Ogunwale | 8b19de9 | 2018-11-29 19:58:26 -0800 | [diff] [blame] | 3910 | ArrayList<ActivityRecord> activities = r.getTaskRecord().mActivities; |
Craig Mautner | d74f7d7 | 2013-02-26 13:41:02 -0800 | [diff] [blame] | 3911 | for (int index = activities.indexOf(r); index >= 0; --index) { |
| 3912 | ActivityRecord cur = activities.get(index); |
Kenny Root | e6585b3 | 2013-12-13 12:00:26 -0800 | [diff] [blame] | 3913 | if (!Objects.equals(cur.taskAffinity, r.taskAffinity)) { |
Dianne Hackborn | ecc5a9c | 2012-04-26 18:56:09 -0700 | [diff] [blame] | 3914 | break; |
| 3915 | } |
Craig Mautner | de4ef02 | 2013-04-07 19:01:33 -0700 | [diff] [blame] | 3916 | finishActivityLocked(cur, Activity.RESULT_CANCELED, null, "request-affinity", true); |
Dianne Hackborn | ecc5a9c | 2012-04-26 18:56:09 -0700 | [diff] [blame] | 3917 | } |
| 3918 | return true; |
| 3919 | } |
| 3920 | |
Andrii Kulian | 21713ac | 2016-10-12 22:05:05 -0700 | [diff] [blame] | 3921 | private void finishActivityResultsLocked(ActivityRecord r, int resultCode, Intent resultData) { |
Dianne Hackborn | 5c60743 | 2012-02-28 14:44:19 -0800 | [diff] [blame] | 3922 | // send the result |
| 3923 | ActivityRecord resultTo = r.resultTo; |
| 3924 | if (resultTo != null) { |
Wale Ogunwale | ee006da | 2015-03-30 14:49:25 -0700 | [diff] [blame] | 3925 | if (DEBUG_RESULTS) Slog.v(TAG_RESULTS, "Adding result to " + resultTo |
Dianne Hackborn | 5c60743 | 2012-02-28 14:44:19 -0800 | [diff] [blame] | 3926 | + " who=" + r.resultWho + " req=" + r.requestCode |
| 3927 | + " res=" + resultCode + " data=" + resultData); |
Wale Ogunwale | 8b19de9 | 2018-11-29 19:58:26 -0800 | [diff] [blame] | 3928 | if (resultTo.mUserId != r.mUserId) { |
Nicolas Prevot | 6b942b8 | 2014-06-02 15:20:42 +0100 | [diff] [blame] | 3929 | if (resultData != null) { |
Wale Ogunwale | 8b19de9 | 2018-11-29 19:58:26 -0800 | [diff] [blame] | 3930 | resultData.prepareToLeaveUser(r.mUserId); |
Nicolas Prevot | 6b942b8 | 2014-06-02 15:20:42 +0100 | [diff] [blame] | 3931 | } |
Nicolas Prevot | c6cf95c | 2014-05-29 11:30:36 +0100 | [diff] [blame] | 3932 | } |
Dianne Hackborn | 5c60743 | 2012-02-28 14:44:19 -0800 | [diff] [blame] | 3933 | if (r.info.applicationInfo.uid > 0) { |
Wale Ogunwale | 6d50dcc | 2018-07-21 23:00:40 -0700 | [diff] [blame] | 3934 | mService.mUgmInternal.grantUriPermissionFromIntent(r.info.applicationInfo.uid, |
Dianne Hackborn | 5c60743 | 2012-02-28 14:44:19 -0800 | [diff] [blame] | 3935 | resultTo.packageName, resultData, |
Wale Ogunwale | 8b19de9 | 2018-11-29 19:58:26 -0800 | [diff] [blame] | 3936 | resultTo.getUriPermissionsLocked(), resultTo.mUserId); |
Dianne Hackborn | 5c60743 | 2012-02-28 14:44:19 -0800 | [diff] [blame] | 3937 | } |
Wale Ogunwale | 5fa8a8c | 2018-05-08 13:43:21 -0700 | [diff] [blame] | 3938 | resultTo.addResultLocked(r, r.resultWho, r.requestCode, resultCode, resultData); |
Dianne Hackborn | 5c60743 | 2012-02-28 14:44:19 -0800 | [diff] [blame] | 3939 | r.resultTo = null; |
| 3940 | } |
Wale Ogunwale | ee006da | 2015-03-30 14:49:25 -0700 | [diff] [blame] | 3941 | 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] | 3942 | |
| 3943 | // Make sure this HistoryRecord is not holding on to other resources, |
| 3944 | // because clients have remote IPC references to this object so we |
| 3945 | // can't assume that will go away and want to avoid circular IPC refs. |
| 3946 | r.results = null; |
| 3947 | r.pendingResults = null; |
| 3948 | r.newIntents = null; |
| 3949 | r.icicle = null; |
| 3950 | } |
| 3951 | |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 3952 | /** |
Winson Chung | 6954fc9 | 2017-03-24 16:22:12 -0700 | [diff] [blame] | 3953 | * See {@link #finishActivityLocked(ActivityRecord, int, Intent, String, boolean, boolean)} |
| 3954 | */ |
| 3955 | final boolean finishActivityLocked(ActivityRecord r, int resultCode, Intent resultData, |
| 3956 | String reason, boolean oomAdj) { |
| 3957 | return finishActivityLocked(r, resultCode, resultData, reason, oomAdj, !PAUSE_IMMEDIATELY); |
| 3958 | } |
| 3959 | |
| 3960 | /** |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 3961 | * @return Returns true if this activity has been removed from the history |
| 3962 | * list, or false if it is still in the list and will be removed later. |
| 3963 | */ |
Craig Mautner | f333327 | 2013-04-22 10:55:53 -0700 | [diff] [blame] | 3964 | final boolean finishActivityLocked(ActivityRecord r, int resultCode, Intent resultData, |
Winson Chung | 6954fc9 | 2017-03-24 16:22:12 -0700 | [diff] [blame] | 3965 | String reason, boolean oomAdj, boolean pauseImmediately) { |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 3966 | if (r.finishing) { |
| 3967 | Slog.w(TAG, "Duplicate finish request for " + r); |
| 3968 | return false; |
| 3969 | } |
| 3970 | |
Jorim Jaggi | fe76234 | 2016-10-13 14:33:27 +0200 | [diff] [blame] | 3971 | mWindowManager.deferSurfaceLayout(); |
| 3972 | try { |
| 3973 | r.makeFinishingLocked(); |
Wale Ogunwale | 8b19de9 | 2018-11-29 19:58:26 -0800 | [diff] [blame] | 3974 | final TaskRecord task = r.getTaskRecord(); |
Jorim Jaggi | fe76234 | 2016-10-13 14:33:27 +0200 | [diff] [blame] | 3975 | EventLog.writeEvent(EventLogTags.AM_FINISH_ACTIVITY, |
Wale Ogunwale | 8b19de9 | 2018-11-29 19:58:26 -0800 | [diff] [blame] | 3976 | r.mUserId, System.identityHashCode(r), |
Jorim Jaggi | fe76234 | 2016-10-13 14:33:27 +0200 | [diff] [blame] | 3977 | task.taskId, r.shortComponentName, reason); |
| 3978 | final ArrayList<ActivityRecord> activities = task.mActivities; |
| 3979 | final int index = activities.indexOf(r); |
| 3980 | if (index < (activities.size() - 1)) { |
| 3981 | task.setFrontOfTask(); |
| 3982 | if ((r.intent.getFlags() & Intent.FLAG_ACTIVITY_CLEAR_WHEN_TASK_RESET) != 0) { |
| 3983 | // If the caller asked that this activity (and all above it) |
| 3984 | // be cleared when the task is reset, don't lose that information, |
| 3985 | // but propagate it up to the next activity. |
| 3986 | ActivityRecord next = activities.get(index+1); |
| 3987 | next.intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_WHEN_TASK_RESET); |
| 3988 | } |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 3989 | } |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 3990 | |
Jorim Jaggi | fe76234 | 2016-10-13 14:33:27 +0200 | [diff] [blame] | 3991 | r.pauseKeyDispatchingLocked(); |
Craig Mautner | 04f0b70 | 2013-10-22 12:31:01 -0700 | [diff] [blame] | 3992 | |
Wale Ogunwale | 66e1685 | 2017-10-19 13:35:52 -0700 | [diff] [blame] | 3993 | adjustFocusedActivityStack(r, "finishActivity"); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 3994 | |
Jorim Jaggi | fe76234 | 2016-10-13 14:33:27 +0200 | [diff] [blame] | 3995 | finishActivityResultsLocked(r, resultCode, resultData); |
Craig Mautner | 2420ead | 2013-04-01 17:13:20 -0700 | [diff] [blame] | 3996 | |
Yorke Lee | bdef537 | 2017-04-10 16:38:51 -0700 | [diff] [blame] | 3997 | final boolean endTask = index <= 0 && !task.isClearingToReuseTask(); |
Jorim Jaggi | fe76234 | 2016-10-13 14:33:27 +0200 | [diff] [blame] | 3998 | final int transit = endTask ? TRANSIT_TASK_CLOSE : TRANSIT_ACTIVITY_CLOSE; |
| 3999 | if (mResumedActivity == r) { |
| 4000 | if (DEBUG_VISIBILITY || DEBUG_TRANSITION) Slog.v(TAG_TRANSITION, |
| 4001 | "Prepare close transition: finishing " + r); |
Winson Chung | 6954fc9 | 2017-03-24 16:22:12 -0700 | [diff] [blame] | 4002 | if (endTask) { |
Wale Ogunwale | 5fa8a8c | 2018-05-08 13:43:21 -0700 | [diff] [blame] | 4003 | mService.getTaskChangeNotificationController().notifyTaskRemovalStarted( |
Mark Renouf | c808f06 | 2019-02-07 15:20:37 -0500 | [diff] [blame] | 4004 | task.getTaskInfo()); |
Winson Chung | 6954fc9 | 2017-03-24 16:22:12 -0700 | [diff] [blame] | 4005 | } |
Wale Ogunwale | 3a256e6 | 2018-12-06 14:41:18 -0800 | [diff] [blame] | 4006 | getDisplay().mDisplayContent.prepareAppTransition(transit, false); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 4007 | |
Jorim Jaggi | fe76234 | 2016-10-13 14:33:27 +0200 | [diff] [blame] | 4008 | // Tell window manager to prepare for this one to be removed. |
Wale Ogunwale | 26c0dfe | 2016-12-14 14:42:30 -0800 | [diff] [blame] | 4009 | r.setVisibility(false); |
Jorim Jaggi | fe76234 | 2016-10-13 14:33:27 +0200 | [diff] [blame] | 4010 | |
| 4011 | if (mPausingActivity == null) { |
| 4012 | if (DEBUG_PAUSE) Slog.v(TAG_PAUSE, "Finish needs to pause: " + r); |
| 4013 | if (DEBUG_USER_LEAVING) Slog.v(TAG_USER_LEAVING, |
| 4014 | "finish() => pause with userLeaving=false"); |
Winson Chung | 6954fc9 | 2017-03-24 16:22:12 -0700 | [diff] [blame] | 4015 | startPausingLocked(false, false, null, pauseImmediately); |
Jorim Jaggi | fe76234 | 2016-10-13 14:33:27 +0200 | [diff] [blame] | 4016 | } |
| 4017 | |
| 4018 | if (endTask) { |
Wale Ogunwale | 5fa8a8c | 2018-05-08 13:43:21 -0700 | [diff] [blame] | 4019 | mService.getLockTaskController().clearLockedTask(task); |
Jorim Jaggi | fe76234 | 2016-10-13 14:33:27 +0200 | [diff] [blame] | 4020 | } |
Bryce Lee | 7ace395 | 2018-02-16 14:34:32 -0800 | [diff] [blame] | 4021 | } else if (!r.isState(PAUSING)) { |
Jorim Jaggi | fe76234 | 2016-10-13 14:33:27 +0200 | [diff] [blame] | 4022 | // If the activity is PAUSING, we will complete the finish once |
| 4023 | // it is done pausing; else we can just directly finish it here. |
| 4024 | if (DEBUG_PAUSE) Slog.v(TAG_PAUSE, "Finish not pausing: " + r); |
| 4025 | if (r.visible) { |
Winson Chung | 6954fc9 | 2017-03-24 16:22:12 -0700 | [diff] [blame] | 4026 | prepareActivityHideTransitionAnimation(r, transit); |
| 4027 | } |
| 4028 | |
| 4029 | final int finishMode = (r.visible || r.nowVisible) ? FINISH_AFTER_VISIBLE |
| 4030 | : FINISH_AFTER_PAUSE; |
Bryce Lee | f52974c | 2018-02-14 15:12:01 -0800 | [diff] [blame] | 4031 | final boolean removedActivity = finishCurrentActivityLocked(r, finishMode, oomAdj, |
| 4032 | "finishActivityLocked") == null; |
Winson Chung | 6954fc9 | 2017-03-24 16:22:12 -0700 | [diff] [blame] | 4033 | |
| 4034 | // The following code is an optimization. When the last non-task overlay activity |
| 4035 | // is removed from the task, we remove the entire task from the stack. However, |
| 4036 | // since that is done after the scheduled destroy callback from the activity, that |
| 4037 | // call to change the visibility of the task overlay activities would be out of |
| 4038 | // sync with the activitiy visibility being set for this finishing activity above. |
| 4039 | // In this case, we can set the visibility of all the task overlay activities when |
| 4040 | // we detect the last one is finishing to keep them in sync. |
| 4041 | if (task.onlyHasTaskOverlayActivities(true /* excludeFinishing */)) { |
| 4042 | for (ActivityRecord taskOverlay : task.mActivities) { |
| 4043 | if (!taskOverlay.mTaskOverlay) { |
| 4044 | continue; |
| 4045 | } |
| 4046 | prepareActivityHideTransitionAnimation(taskOverlay, transit); |
Jorim Jaggi | fe76234 | 2016-10-13 14:33:27 +0200 | [diff] [blame] | 4047 | } |
| 4048 | } |
Winson Chung | 6954fc9 | 2017-03-24 16:22:12 -0700 | [diff] [blame] | 4049 | return removedActivity; |
Jorim Jaggi | fe76234 | 2016-10-13 14:33:27 +0200 | [diff] [blame] | 4050 | } else { |
| 4051 | if (DEBUG_PAUSE) Slog.v(TAG_PAUSE, "Finish waiting for pause of: " + r); |
| 4052 | } |
| 4053 | |
| 4054 | return false; |
| 4055 | } finally { |
| 4056 | mWindowManager.continueSurfaceLayout(); |
| 4057 | } |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 4058 | } |
| 4059 | |
Winson Chung | 6954fc9 | 2017-03-24 16:22:12 -0700 | [diff] [blame] | 4060 | private void prepareActivityHideTransitionAnimation(ActivityRecord r, int transit) { |
Wale Ogunwale | 3a256e6 | 2018-12-06 14:41:18 -0800 | [diff] [blame] | 4061 | final DisplayContent dc = getDisplay().mDisplayContent; |
| 4062 | dc.prepareAppTransition(transit, false); |
Winson Chung | 6954fc9 | 2017-03-24 16:22:12 -0700 | [diff] [blame] | 4063 | r.setVisibility(false); |
Wale Ogunwale | 3a256e6 | 2018-12-06 14:41:18 -0800 | [diff] [blame] | 4064 | dc.executeAppTransition(); |
Winson Chung | 6954fc9 | 2017-03-24 16:22:12 -0700 | [diff] [blame] | 4065 | } |
| 4066 | |
Craig Mautner | f333327 | 2013-04-22 10:55:53 -0700 | [diff] [blame] | 4067 | static final int FINISH_IMMEDIATELY = 0; |
| 4068 | static final int FINISH_AFTER_PAUSE = 1; |
| 4069 | static final int FINISH_AFTER_VISIBLE = 2; |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 4070 | |
Bryce Lee | f52974c | 2018-02-14 15:12:01 -0800 | [diff] [blame] | 4071 | final ActivityRecord finishCurrentActivityLocked(ActivityRecord r, int mode, boolean oomAdj, |
| 4072 | String reason) { |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 4073 | // First things first: if this activity is currently visible, |
| 4074 | // and the resumed activity is not yet visible, then hold off on |
| 4075 | // finishing until the resumed one becomes visible. |
Chong Zhang | 824b6dc | 2016-04-27 14:11:12 -0700 | [diff] [blame] | 4076 | |
Bryce Lee | c961e0a | 2018-04-13 17:58:02 -0700 | [diff] [blame] | 4077 | // The activity that we are finishing may be over the lock screen. In this case, we do not |
| 4078 | // want to consider activities that cannot be shown on the lock screen as running and should |
| 4079 | // 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] | 4080 | final ActivityDisplay display = getDisplay(); |
| 4081 | final ActivityRecord next = display.topRunningActivity(true /* considerKeyguardState */); |
Chong Zhang | 824b6dc | 2016-04-27 14:11:12 -0700 | [diff] [blame] | 4082 | |
Chong Zhang | efd9a5b | 2016-04-26 16:21:07 -0700 | [diff] [blame] | 4083 | if (mode == FINISH_AFTER_VISIBLE && (r.visible || r.nowVisible) |
Chong Zhang | 824b6dc | 2016-04-27 14:11:12 -0700 | [diff] [blame] | 4084 | && next != null && !next.nowVisible) { |
Craig Mautner | de4ef02 | 2013-04-07 19:01:33 -0700 | [diff] [blame] | 4085 | if (!mStackSupervisor.mStoppingActivities.contains(r)) { |
Winson Chung | 4dabf23 | 2017-01-25 13:25:22 -0800 | [diff] [blame] | 4086 | addToStopping(r, false /* scheduleIdle */, false /* idleDelayed */); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 4087 | } |
Wale Ogunwale | 0fc365c | 2015-05-25 19:35:42 -0700 | [diff] [blame] | 4088 | if (DEBUG_STATES) Slog.v(TAG_STATES, |
| 4089 | "Moving to STOPPING: "+ r + " (finish requested)"); |
Bryce Lee | 7ace395 | 2018-02-16 14:34:32 -0800 | [diff] [blame] | 4090 | r.setState(STOPPING, "finishCurrentActivityLocked"); |
Dianne Hackborn | 2d1b378 | 2012-09-09 17:49:39 -0700 | [diff] [blame] | 4091 | if (oomAdj) { |
Wale Ogunwale | f673393 | 2018-06-27 05:14:34 -0700 | [diff] [blame] | 4092 | mService.updateOomAdj(); |
Dianne Hackborn | 2d1b378 | 2012-09-09 17:49:39 -0700 | [diff] [blame] | 4093 | } |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 4094 | return r; |
| 4095 | } |
| 4096 | |
| 4097 | // make sure the record is cleaned out of other places. |
Craig Mautner | de4ef02 | 2013-04-07 19:01:33 -0700 | [diff] [blame] | 4098 | mStackSupervisor.mStoppingActivities.remove(r); |
Craig Mautner | 0eea92c | 2013-05-16 13:35:39 -0700 | [diff] [blame] | 4099 | mStackSupervisor.mGoingToSleepActivities.remove(r); |
Bryce Lee | 7ace395 | 2018-02-16 14:34:32 -0800 | [diff] [blame] | 4100 | final ActivityState prevState = r.getState(); |
Wale Ogunwale | 0fc365c | 2015-05-25 19:35:42 -0700 | [diff] [blame] | 4101 | if (DEBUG_STATES) Slog.v(TAG_STATES, "Moving to FINISHING: " + r); |
Bryce Lee | b0f993f | 2018-03-02 15:38:01 -0800 | [diff] [blame] | 4102 | |
Bryce Lee | 7ace395 | 2018-02-16 14:34:32 -0800 | [diff] [blame] | 4103 | r.setState(FINISHING, "finishCurrentActivityLocked"); |
Riddle Hsu | e10cea5 | 2018-10-16 23:33:23 +0800 | [diff] [blame] | 4104 | final boolean finishingInNonFocusedStackOrNoRunning = mode == FINISH_AFTER_VISIBLE |
Wale Ogunwale | 8b19de9 | 2018-11-29 19:58:26 -0800 | [diff] [blame] | 4105 | && prevState == PAUSED && (r.getActivityStack() != display.getFocusedStack() |
Riddle Hsu | e10cea5 | 2018-10-16 23:33:23 +0800 | [diff] [blame] | 4106 | || (next == null && display.topRunningActivity() == null)); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 4107 | |
| 4108 | if (mode == FINISH_IMMEDIATELY |
Bryce Lee | 7ace395 | 2018-02-16 14:34:32 -0800 | [diff] [blame] | 4109 | || (prevState == PAUSED |
Wale Ogunwale | 44f036f | 2017-09-29 05:09:09 -0700 | [diff] [blame] | 4110 | && (mode == FINISH_AFTER_PAUSE || inPinnedWindowingMode())) |
Riddle Hsu | e10cea5 | 2018-10-16 23:33:23 +0800 | [diff] [blame] | 4111 | || finishingInNonFocusedStackOrNoRunning |
Wale Ogunwale | b9a0c99 | 2017-04-18 07:25:20 -0700 | [diff] [blame] | 4112 | || prevState == STOPPING |
| 4113 | || prevState == STOPPED |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 4114 | || prevState == ActivityState.INITIALIZING) { |
Wale Ogunwale | 7d70117 | 2015-03-11 15:36:30 -0700 | [diff] [blame] | 4115 | r.makeFinishingLocked(); |
Bryce Lee | f52974c | 2018-02-14 15:12:01 -0800 | [diff] [blame] | 4116 | boolean activityRemoved = destroyActivityLocked(r, true, "finish-imm:" + reason); |
Andrii Kulian | 7318d63 | 2016-07-20 18:59:28 -0700 | [diff] [blame] | 4117 | |
Riddle Hsu | e10cea5 | 2018-10-16 23:33:23 +0800 | [diff] [blame] | 4118 | if (finishingInNonFocusedStackOrNoRunning) { |
Andrii Kulian | 995fa2b | 2016-07-29 12:55:41 -0700 | [diff] [blame] | 4119 | // 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] | 4120 | // stack, need to make something visible in its place. Also if the display does not |
| 4121 | // have running activity, the configuration may need to be updated for restoring |
| 4122 | // original orientation of the display. |
Wale Ogunwale | d32da47 | 2018-11-16 07:19:28 -0800 | [diff] [blame] | 4123 | mRootActivityContainer.ensureVisibilityAndConfig(next, mDisplayId, |
Andrii Kulian | f4479ee | 2018-05-23 17:52:48 -0700 | [diff] [blame] | 4124 | false /* markFrozenIfConfigChanged */, true /* deferResume */); |
Andrii Kulian | 7318d63 | 2016-07-20 18:59:28 -0700 | [diff] [blame] | 4125 | } |
Dianne Hackborn | 42e620c | 2012-06-24 13:20:51 -0700 | [diff] [blame] | 4126 | if (activityRemoved) { |
Wale Ogunwale | d32da47 | 2018-11-16 07:19:28 -0800 | [diff] [blame] | 4127 | mRootActivityContainer.resumeFocusedStacksTopActivities(); |
Dianne Hackborn | 42e620c | 2012-06-24 13:20:51 -0700 | [diff] [blame] | 4128 | } |
Wale Ogunwale | 0fc365c | 2015-05-25 19:35:42 -0700 | [diff] [blame] | 4129 | if (DEBUG_CONTAINERS) Slog.d(TAG_CONTAINERS, |
Craig Mautner | d163e75 | 2014-06-13 17:18:47 -0700 | [diff] [blame] | 4130 | "destroyActivityLocked: finishCurrentActivityLocked r=" + r + |
| 4131 | " destroy returned removed=" + activityRemoved); |
Dianne Hackborn | 42e620c | 2012-06-24 13:20:51 -0700 | [diff] [blame] | 4132 | return activityRemoved ? null : r; |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 4133 | } |
Craig Mautner | 05d6272ba | 2013-02-11 09:39:27 -0800 | [diff] [blame] | 4134 | |
| 4135 | // Need to go through the full pause cycle to get this |
| 4136 | // activity into the stopped state and then finish it. |
Wale Ogunwale | e23149f | 2015-03-06 15:39:44 -0800 | [diff] [blame] | 4137 | if (DEBUG_ALL) Slog.v(TAG, "Enqueueing pending finish: " + r); |
Craig Mautner | f333327 | 2013-04-22 10:55:53 -0700 | [diff] [blame] | 4138 | mStackSupervisor.mFinishingActivities.add(r); |
Martin Wallgren | c8733b8 | 2011-08-31 12:39:31 +0200 | [diff] [blame] | 4139 | r.resumeKeyDispatchingLocked(); |
Wale Ogunwale | d32da47 | 2018-11-16 07:19:28 -0800 | [diff] [blame] | 4140 | mRootActivityContainer.resumeFocusedStacksTopActivities(); |
Andrii Kulian | 6b32151 | 2019-01-23 06:37:00 +0000 | [diff] [blame] | 4141 | // If activity was not paused at this point - explicitly pause it to start finishing |
| 4142 | // process. Finishing will be completed once it reports pause back. |
| 4143 | if (r.isState(RESUMED) && mPausingActivity != null) { |
| 4144 | startPausingLocked(false /* userLeaving */, false /* uiSleeping */, next /* resuming */, |
| 4145 | false /* dontWait */); |
| 4146 | } |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 4147 | return r; |
| 4148 | } |
| 4149 | |
Craig Mautner | ee36c77 | 2014-07-16 14:56:05 -0700 | [diff] [blame] | 4150 | void finishAllActivitiesLocked(boolean immediately) { |
| 4151 | boolean noActivitiesInStack = true; |
Craig Mautner | f4c909b | 2014-04-17 18:39:38 -0700 | [diff] [blame] | 4152 | for (int taskNdx = mTaskHistory.size() - 1; taskNdx >= 0; --taskNdx) { |
| 4153 | final ArrayList<ActivityRecord> activities = mTaskHistory.get(taskNdx).mActivities; |
| 4154 | for (int activityNdx = activities.size() - 1; activityNdx >= 0; --activityNdx) { |
| 4155 | final ActivityRecord r = activities.get(activityNdx); |
Craig Mautner | ee36c77 | 2014-07-16 14:56:05 -0700 | [diff] [blame] | 4156 | noActivitiesInStack = false; |
| 4157 | if (r.finishing && !immediately) { |
Craig Mautner | f4c909b | 2014-04-17 18:39:38 -0700 | [diff] [blame] | 4158 | continue; |
| 4159 | } |
Craig Mautner | ee36c77 | 2014-07-16 14:56:05 -0700 | [diff] [blame] | 4160 | Slog.d(TAG, "finishAllActivitiesLocked: finishing " + r + " immediately"); |
Bryce Lee | f52974c | 2018-02-14 15:12:01 -0800 | [diff] [blame] | 4161 | finishCurrentActivityLocked(r, FINISH_IMMEDIATELY, false, |
| 4162 | "finishAllActivitiesLocked"); |
Craig Mautner | f4c909b | 2014-04-17 18:39:38 -0700 | [diff] [blame] | 4163 | } |
| 4164 | } |
Craig Mautner | ee36c77 | 2014-07-16 14:56:05 -0700 | [diff] [blame] | 4165 | if (noActivitiesInStack) { |
Andrii Kulian | 94e82d9b0 | 2017-07-13 15:33:06 -0700 | [diff] [blame] | 4166 | remove(); |
Craig Mautner | ee36c77 | 2014-07-16 14:56:05 -0700 | [diff] [blame] | 4167 | } |
Craig Mautner | f4c909b | 2014-04-17 18:39:38 -0700 | [diff] [blame] | 4168 | } |
| 4169 | |
Wale Ogunwale | 66e1685 | 2017-10-19 13:35:52 -0700 | [diff] [blame] | 4170 | /** @return true if the stack behind this one is a standard activity type. */ |
| 4171 | boolean inFrontOfStandardStack() { |
| 4172 | final ActivityDisplay display = getDisplay(); |
| 4173 | if (display == null) { |
| 4174 | return false; |
| 4175 | } |
| 4176 | final int index = display.getIndexOf(this); |
| 4177 | if (index == 0) { |
| 4178 | return false; |
| 4179 | } |
| 4180 | final ActivityStack stackBehind = display.getChildAt(index - 1); |
| 4181 | return stackBehind.isActivityTypeStandard(); |
| 4182 | } |
| 4183 | |
| 4184 | boolean shouldUpRecreateTaskLocked(ActivityRecord srec, String destAffinity) { |
Dianne Hackborn | 6f4d61f | 2014-08-21 17:50:42 -0700 | [diff] [blame] | 4185 | // Basic case: for simple app-centric recents, we need to recreate |
| 4186 | // the task if the affinity has changed. |
Wale Ogunwale | 8b19de9 | 2018-11-29 19:58:26 -0800 | [diff] [blame] | 4187 | if (srec == null || srec.getTaskRecord().affinity == null || |
| 4188 | !srec.getTaskRecord().affinity.equals(destAffinity)) { |
Dianne Hackborn | 6f4d61f | 2014-08-21 17:50:42 -0700 | [diff] [blame] | 4189 | return true; |
| 4190 | } |
| 4191 | // Document-centric case: an app may be split in to multiple documents; |
| 4192 | // they need to re-create their task if this current activity is the root |
| 4193 | // of a document, unless simply finishing it will return them to the the |
| 4194 | // correct app behind. |
Wale Ogunwale | 8b19de9 | 2018-11-29 19:58:26 -0800 | [diff] [blame] | 4195 | final TaskRecord task = srec.getTaskRecord(); |
Wale Ogunwale | 66e1685 | 2017-10-19 13:35:52 -0700 | [diff] [blame] | 4196 | if (srec.frontOfTask && task.getBaseIntent() != null && task.getBaseIntent().isDocument()) { |
Dianne Hackborn | 6f4d61f | 2014-08-21 17:50:42 -0700 | [diff] [blame] | 4197 | // 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] | 4198 | if (!inFrontOfStandardStack()) { |
Dianne Hackborn | 6f4d61f | 2014-08-21 17:50:42 -0700 | [diff] [blame] | 4199 | // Finishing won't return to an application, so we need to recreate. |
| 4200 | return true; |
| 4201 | } |
| 4202 | // 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] | 4203 | int taskIdx = mTaskHistory.indexOf(task); |
Dianne Hackborn | 6f4d61f | 2014-08-21 17:50:42 -0700 | [diff] [blame] | 4204 | if (taskIdx <= 0) { |
| 4205 | Slog.w(TAG, "shouldUpRecreateTask: task not in history for " + srec); |
| 4206 | return false; |
| 4207 | } |
Wale Ogunwale | 6fbde9f | 2017-08-24 07:24:12 -0700 | [diff] [blame] | 4208 | final TaskRecord prevTask = mTaskHistory.get(taskIdx); |
Bryce Lee | af691c0 | 2017-03-20 14:20:22 -0700 | [diff] [blame] | 4209 | if (!task.affinity.equals(prevTask.affinity)) { |
Dianne Hackborn | 6f4d61f | 2014-08-21 17:50:42 -0700 | [diff] [blame] | 4210 | // These are different apps, so need to recreate. |
| 4211 | return true; |
| 4212 | } |
| 4213 | } |
| 4214 | return false; |
| 4215 | } |
| 4216 | |
Wale Ogunwale | 7d70117 | 2015-03-11 15:36:30 -0700 | [diff] [blame] | 4217 | final boolean navigateUpToLocked(ActivityRecord srec, Intent destIntent, int resultCode, |
Craig Mautner | 05d6272ba | 2013-02-11 09:39:27 -0800 | [diff] [blame] | 4218 | Intent resultData) { |
Wale Ogunwale | 8b19de9 | 2018-11-29 19:58:26 -0800 | [diff] [blame] | 4219 | final TaskRecord task = srec.getTaskRecord(); |
Craig Mautner | 0247fc8 | 2013-02-28 14:32:06 -0800 | [diff] [blame] | 4220 | final ArrayList<ActivityRecord> activities = task.mActivities; |
| 4221 | final int start = activities.indexOf(srec); |
| 4222 | if (!mTaskHistory.contains(task) || (start < 0)) { |
Craig Mautner | 05d6272ba | 2013-02-11 09:39:27 -0800 | [diff] [blame] | 4223 | return false; |
| 4224 | } |
| 4225 | int finishTo = start - 1; |
Craig Mautner | 0247fc8 | 2013-02-28 14:32:06 -0800 | [diff] [blame] | 4226 | ActivityRecord parent = finishTo < 0 ? null : activities.get(finishTo); |
Craig Mautner | 05d6272ba | 2013-02-11 09:39:27 -0800 | [diff] [blame] | 4227 | boolean foundParentInTask = false; |
Craig Mautner | 0247fc8 | 2013-02-28 14:32:06 -0800 | [diff] [blame] | 4228 | final ComponentName dest = destIntent.getComponent(); |
| 4229 | if (start > 0 && dest != null) { |
| 4230 | for (int i = finishTo; i >= 0; i--) { |
| 4231 | ActivityRecord r = activities.get(i); |
| 4232 | if (r.info.packageName.equals(dest.getPackageName()) && |
Craig Mautner | 05d6272ba | 2013-02-11 09:39:27 -0800 | [diff] [blame] | 4233 | r.info.name.equals(dest.getClassName())) { |
| 4234 | finishTo = i; |
| 4235 | parent = r; |
| 4236 | foundParentInTask = true; |
| 4237 | break; |
| 4238 | } |
| 4239 | } |
| 4240 | } |
| 4241 | |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 4242 | // TODO: There is a dup. of this block of code in ActivityTaskManagerService.finishActivity |
| 4243 | // We should consolidate. |
| 4244 | IActivityController controller = mService.mController; |
Craig Mautner | 05d6272ba | 2013-02-11 09:39:27 -0800 | [diff] [blame] | 4245 | if (controller != null) { |
| 4246 | ActivityRecord next = topRunningActivityLocked(srec.appToken, 0); |
| 4247 | if (next != null) { |
| 4248 | // ask watcher if this is allowed |
| 4249 | boolean resumeOK = true; |
| 4250 | try { |
| 4251 | resumeOK = controller.activityResuming(next.packageName); |
| 4252 | } catch (RemoteException e) { |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 4253 | mService.mController = null; |
Kenny Root | add5821 | 2013-05-07 09:47:34 -0700 | [diff] [blame] | 4254 | Watchdog.getInstance().setActivityController(null); |
Craig Mautner | 05d6272ba | 2013-02-11 09:39:27 -0800 | [diff] [blame] | 4255 | } |
| 4256 | |
| 4257 | if (!resumeOK) { |
| 4258 | return false; |
| 4259 | } |
| 4260 | } |
| 4261 | } |
| 4262 | final long origId = Binder.clearCallingIdentity(); |
| 4263 | for (int i = start; i > finishTo; i--) { |
Craig Mautner | 0247fc8 | 2013-02-28 14:32:06 -0800 | [diff] [blame] | 4264 | ActivityRecord r = activities.get(i); |
| 4265 | requestFinishActivityLocked(r.appToken, resultCode, resultData, "navigate-up", true); |
Craig Mautner | 05d6272ba | 2013-02-11 09:39:27 -0800 | [diff] [blame] | 4266 | // Only return the supplied result for the first activity finished |
| 4267 | resultCode = Activity.RESULT_CANCELED; |
| 4268 | resultData = null; |
| 4269 | } |
| 4270 | |
| 4271 | if (parent != null && foundParentInTask) { |
| 4272 | final int parentLaunchMode = parent.info.launchMode; |
| 4273 | final int destIntentFlags = destIntent.getFlags(); |
| 4274 | if (parentLaunchMode == ActivityInfo.LAUNCH_SINGLE_INSTANCE || |
| 4275 | parentLaunchMode == ActivityInfo.LAUNCH_SINGLE_TASK || |
| 4276 | parentLaunchMode == ActivityInfo.LAUNCH_SINGLE_TOP || |
| 4277 | (destIntentFlags & Intent.FLAG_ACTIVITY_CLEAR_TOP) != 0) { |
Dianne Hackborn | 85d558c | 2014-11-04 10:31:54 -0800 | [diff] [blame] | 4278 | parent.deliverNewIntentLocked(srec.info.applicationInfo.uid, destIntent, |
| 4279 | srec.packageName); |
Craig Mautner | 05d6272ba | 2013-02-11 09:39:27 -0800 | [diff] [blame] | 4280 | } else { |
| 4281 | try { |
| 4282 | ActivityInfo aInfo = AppGlobals.getPackageManager().getActivityInfo( |
Philip P. Moltmann | cff8f0f | 2018-03-27 12:51:51 -0700 | [diff] [blame] | 4283 | destIntent.getComponent(), ActivityManagerService.STOCK_PM_FLAGS, |
Wale Ogunwale | 8b19de9 | 2018-11-29 19:58:26 -0800 | [diff] [blame] | 4284 | srec.mUserId); |
Bryce Lee | 4c9a597 | 2017-12-01 22:14:24 -0800 | [diff] [blame] | 4285 | // TODO(b/64750076): Check if calling pid should really be -1. |
| 4286 | final int res = mService.getActivityStartController() |
| 4287 | .obtainStarter(destIntent, "navigateUpTo") |
Wale Ogunwale | 9e4f3e0 | 2018-05-17 09:35:39 -0700 | [diff] [blame] | 4288 | .setCaller(srec.app.getThread()) |
Bryce Lee | 4c9a597 | 2017-12-01 22:14:24 -0800 | [diff] [blame] | 4289 | .setActivityInfo(aInfo) |
| 4290 | .setResultTo(parent.appToken) |
| 4291 | .setCallingPid(-1) |
| 4292 | .setCallingUid(parent.launchedFromUid) |
| 4293 | .setCallingPackage(parent.launchedFromPackage) |
| 4294 | .setRealCallingPid(-1) |
| 4295 | .setRealCallingUid(parent.launchedFromUid) |
| 4296 | .setComponentSpecified(true) |
| 4297 | .execute(); |
Craig Mautner | 05d6272ba | 2013-02-11 09:39:27 -0800 | [diff] [blame] | 4298 | foundParentInTask = res == ActivityManager.START_SUCCESS; |
| 4299 | } catch (RemoteException e) { |
| 4300 | foundParentInTask = false; |
| 4301 | } |
| 4302 | requestFinishActivityLocked(parent.appToken, resultCode, |
Todd Kennedy | 539db51 | 2014-12-15 09:57:55 -0800 | [diff] [blame] | 4303 | resultData, "navigate-top", true); |
Craig Mautner | 05d6272ba | 2013-02-11 09:39:27 -0800 | [diff] [blame] | 4304 | } |
| 4305 | } |
| 4306 | Binder.restoreCallingIdentity(origId); |
| 4307 | return foundParentInTask; |
| 4308 | } |
Bryce Lee | af691c0 | 2017-03-20 14:20:22 -0700 | [diff] [blame] | 4309 | |
| 4310 | /** |
| 4311 | * Remove any state associated with the {@link ActivityRecord}. This should be called whenever |
| 4312 | * an activity moves away from the stack. |
| 4313 | */ |
| 4314 | void onActivityRemovedFromStack(ActivityRecord r) { |
Bryce Lee | 84730a0 | 2018-04-03 14:10:04 -0700 | [diff] [blame] | 4315 | removeTimeoutsForActivityLocked(r); |
| 4316 | |
| 4317 | if (mResumedActivity != null && mResumedActivity == r) { |
| 4318 | setResumedActivity(null, "onActivityRemovedFromStack"); |
Bryce Lee | af691c0 | 2017-03-20 14:20:22 -0700 | [diff] [blame] | 4319 | } |
Bryce Lee | 84730a0 | 2018-04-03 14:10:04 -0700 | [diff] [blame] | 4320 | if (mPausingActivity != null && mPausingActivity == r) { |
Bryce Lee | af691c0 | 2017-03-20 14:20:22 -0700 | [diff] [blame] | 4321 | mPausingActivity = null; |
| 4322 | } |
Bryce Lee | 84730a0 | 2018-04-03 14:10:04 -0700 | [diff] [blame] | 4323 | } |
Bryce Lee | af691c0 | 2017-03-20 14:20:22 -0700 | [diff] [blame] | 4324 | |
Bryce Lee | 84730a0 | 2018-04-03 14:10:04 -0700 | [diff] [blame] | 4325 | void onActivityAddedToStack(ActivityRecord r) { |
| 4326 | if(r.getState() == RESUMED) { |
| 4327 | setResumedActivity(r, "onActivityAddedToStack"); |
| 4328 | } |
Bryce Lee | af691c0 | 2017-03-20 14:20:22 -0700 | [diff] [blame] | 4329 | } |
| 4330 | |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 4331 | /** |
| 4332 | * Perform the common clean-up of an activity record. This is called both |
| 4333 | * as part of destroyActivityLocked() (when destroying the client-side |
| 4334 | * representation) and cleaning things up as a result of its hosting |
| 4335 | * processing going away, in which case there is no remaining client-side |
| 4336 | * state to destroy so only the cleanup here is needed. |
Craig Mautner | acebdc8 | 2015-02-24 10:53:03 -0800 | [diff] [blame] | 4337 | * |
| 4338 | * Note: Call before #removeActivityFromHistoryLocked. |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 4339 | */ |
Bryce Lee | c940660 | 2018-03-09 11:02:10 -0800 | [diff] [blame] | 4340 | private void cleanUpActivityLocked(ActivityRecord r, boolean cleanServices, boolean setState) { |
Bryce Lee | af691c0 | 2017-03-20 14:20:22 -0700 | [diff] [blame] | 4341 | onActivityRemovedFromStack(r); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 4342 | |
Wale Ogunwale | f81c1d1 | 2016-01-12 12:20:18 -0800 | [diff] [blame] | 4343 | r.deferRelaunchUntilPaused = false; |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 4344 | r.frozenBeforeDestroy = false; |
| 4345 | |
Bryce Lee | c940660 | 2018-03-09 11:02:10 -0800 | [diff] [blame] | 4346 | if (setState) { |
Wale Ogunwale | 0fc365c | 2015-05-25 19:35:42 -0700 | [diff] [blame] | 4347 | 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] | 4348 | r.setState(DESTROYED, "cleanupActivityLocked"); |
Wale Ogunwale | 0fc365c | 2015-05-25 19:35:42 -0700 | [diff] [blame] | 4349 | 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] | 4350 | r.app = null; |
Dianne Hackborn | ce86ba8 | 2011-07-13 19:33:41 -0700 | [diff] [blame] | 4351 | } |
| 4352 | |
Bryce Lee | 4a19438 | 2017-04-04 14:32:48 -0700 | [diff] [blame] | 4353 | // Inform supervisor the activity has been removed. |
| 4354 | mStackSupervisor.cleanupActivity(r); |
| 4355 | |
Craig Mautner | 2420ead | 2013-04-01 17:13:20 -0700 | [diff] [blame] | 4356 | |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 4357 | // Remove any pending results. |
| 4358 | if (r.finishing && r.pendingResults != null) { |
| 4359 | for (WeakReference<PendingIntentRecord> apr : r.pendingResults) { |
| 4360 | PendingIntentRecord rec = apr.get(); |
| 4361 | if (rec != null) { |
Wale Ogunwale | ee6eca1 | 2018-09-19 20:37:53 -0700 | [diff] [blame] | 4362 | mService.mPendingIntentController.cancelIntentSender(rec, false); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 4363 | } |
| 4364 | } |
| 4365 | r.pendingResults = null; |
| 4366 | } |
| 4367 | |
| 4368 | if (cleanServices) { |
Craig Mautner | 2420ead | 2013-04-01 17:13:20 -0700 | [diff] [blame] | 4369 | cleanUpActivityServicesLocked(r); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 4370 | } |
| 4371 | |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 4372 | // Get rid of any pending idle timeouts. |
Dianne Hackborn | 42e620c | 2012-06-24 13:20:51 -0700 | [diff] [blame] | 4373 | removeTimeoutsForActivityLocked(r); |
Wale Ogunwale | 8fd7542 | 2016-06-24 14:20:37 -0700 | [diff] [blame] | 4374 | // Clean-up activities are no longer relaunching (e.g. app process died). Notify window |
| 4375 | // manager so it can update its bookkeeping. |
| 4376 | mWindowManager.notifyAppRelaunchesCleared(r.appToken); |
Dianne Hackborn | 42e620c | 2012-06-24 13:20:51 -0700 | [diff] [blame] | 4377 | } |
| 4378 | |
Wale Ogunwale | 5378374 | 2018-09-16 10:21:51 -0700 | [diff] [blame] | 4379 | private void removeTimeoutsForActivityLocked(ActivityRecord r) { |
Craig Mautner | f333327 | 2013-04-22 10:55:53 -0700 | [diff] [blame] | 4380 | mStackSupervisor.removeTimeoutsForActivityLocked(r); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 4381 | mHandler.removeMessages(PAUSE_TIMEOUT_MSG, r); |
Dianne Hackborn | 162bc0e | 2012-04-09 14:06:16 -0700 | [diff] [blame] | 4382 | mHandler.removeMessages(STOP_TIMEOUT_MSG, r); |
Dianne Hackborn | 0c5001d | 2011-04-12 18:16:08 -0700 | [diff] [blame] | 4383 | mHandler.removeMessages(DESTROY_TIMEOUT_MSG, r); |
Dianne Hackborn | 2a29b3a | 2012-03-15 15:48:38 -0700 | [diff] [blame] | 4384 | r.finishLaunchTickingLocked(); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 4385 | } |
| 4386 | |
Chong Zhang | bffd889 | 2016-08-08 11:16:06 -0700 | [diff] [blame] | 4387 | private void removeActivityFromHistoryLocked(ActivityRecord r, String reason) { |
Dianne Hackborn | cc5a055 | 2012-10-01 16:32:39 -0700 | [diff] [blame] | 4388 | finishActivityResultsLocked(r, Activity.RESULT_CANCELED, null); |
Wale Ogunwale | 7d70117 | 2015-03-11 15:36:30 -0700 | [diff] [blame] | 4389 | r.makeFinishingLocked(); |
Wale Ogunwale | 0fc365c | 2015-05-25 19:35:42 -0700 | [diff] [blame] | 4390 | if (DEBUG_ADD_REMOVE) Slog.i(TAG_ADD_REMOVE, |
| 4391 | "Removing activity " + r + " from stack callers=" + Debug.getCallers(5)); |
| 4392 | |
Dianne Hackborn | cc5a055 | 2012-10-01 16:32:39 -0700 | [diff] [blame] | 4393 | r.takeFromHistory(); |
| 4394 | removeTimeoutsForActivityLocked(r); |
Wale Ogunwale | 0fc365c | 2015-05-25 19:35:42 -0700 | [diff] [blame] | 4395 | if (DEBUG_STATES) Slog.v(TAG_STATES, |
| 4396 | "Moving to DESTROYED: " + r + " (removed from history)"); |
Bryce Lee | 7ace395 | 2018-02-16 14:34:32 -0800 | [diff] [blame] | 4397 | r.setState(DESTROYED, "removeActivityFromHistoryLocked"); |
Wale Ogunwale | 0fc365c | 2015-05-25 19:35:42 -0700 | [diff] [blame] | 4398 | 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] | 4399 | r.app = null; |
Wale Ogunwale | 26c0dfe | 2016-12-14 14:42:30 -0800 | [diff] [blame] | 4400 | r.removeWindowContainer(); |
Wale Ogunwale | 8b19de9 | 2018-11-29 19:58:26 -0800 | [diff] [blame] | 4401 | final TaskRecord task = r.getTaskRecord(); |
Bryce Lee | aa5e8c3 | 2017-03-01 16:01:06 -0800 | [diff] [blame] | 4402 | final boolean lastActivity = task != null ? task.removeActivity(r) : false; |
Winson Chung | 6954fc9 | 2017-03-24 16:22:12 -0700 | [diff] [blame] | 4403 | // If we are removing the last activity in the task, not including task overlay activities, |
| 4404 | // then fall through into the block below to remove the entire task itself |
| 4405 | final boolean onlyHasTaskOverlays = task != null |
| 4406 | ? task.onlyHasTaskOverlayActivities(false /* excludingFinishing */) : false; |
Bryce Lee | aa5e8c3 | 2017-03-01 16:01:06 -0800 | [diff] [blame] | 4407 | |
Winson Chung | 6954fc9 | 2017-03-24 16:22:12 -0700 | [diff] [blame] | 4408 | if (lastActivity || onlyHasTaskOverlays) { |
| 4409 | if (DEBUG_STACK) { |
| 4410 | Slog.i(TAG_STACK, |
| 4411 | "removeActivityFromHistoryLocked: last activity removed from " + this |
| 4412 | + " onlyHasTaskOverlays=" + onlyHasTaskOverlays); |
| 4413 | } |
| 4414 | |
Bryce Lee | d6d2675 | 2017-05-25 13:57:46 -0700 | [diff] [blame] | 4415 | // The following block can be executed multiple times if there is more than one overlay. |
| 4416 | // {@link ActivityStackSupervisor#removeTaskByIdLocked} handles this by reverse lookup |
| 4417 | // of the task by id and exiting early if not found. |
Winson Chung | e3c21e0 | 2017-04-11 18:02:17 -0700 | [diff] [blame] | 4418 | if (onlyHasTaskOverlays) { |
| 4419 | // When destroying a task, tell the supervisor to remove it so that any activity it |
| 4420 | // has can be cleaned up correctly. This is currently the only place where we remove |
| 4421 | // a task with the DESTROYING mode, so instead of passing the onlyHasTaskOverlays |
| 4422 | // state into removeTask(), we just clear the task here before the other residual |
| 4423 | // work. |
| 4424 | // TODO: If the callers to removeTask() changes such that we have multiple places |
| 4425 | // where we are destroying the task, move this back into removeTask() |
| 4426 | mStackSupervisor.removeTaskByIdLocked(task.taskId, false /* killProcess */, |
Winson Chung | 0ec2a35 | 2017-10-26 11:38:30 -0700 | [diff] [blame] | 4427 | !REMOVE_FROM_RECENTS, PAUSE_IMMEDIATELY, reason); |
Winson Chung | e3c21e0 | 2017-04-11 18:02:17 -0700 | [diff] [blame] | 4428 | } |
Bryce Lee | 1d93058 | 2017-05-01 08:35:24 -0700 | [diff] [blame] | 4429 | |
Bryce Lee | d6d2675 | 2017-05-25 13:57:46 -0700 | [diff] [blame] | 4430 | // We must keep the task around until all activities are destroyed. The following |
| 4431 | // statement will only execute once since overlays are also considered activities. |
Bryce Lee | 1d93058 | 2017-05-01 08:35:24 -0700 | [diff] [blame] | 4432 | if (lastActivity) { |
| 4433 | removeTask(task, reason, REMOVE_TASK_MODE_DESTROYING); |
| 4434 | } |
Craig Mautner | 312ba86 | 2014-02-10 17:55:01 -0800 | [diff] [blame] | 4435 | } |
Dianne Hackborn | cc5a055 | 2012-10-01 16:32:39 -0700 | [diff] [blame] | 4436 | cleanUpActivityServicesLocked(r); |
| 4437 | r.removeUriPermissionsLocked(); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 4438 | } |
Craig Mautner | dbcb31f | 2013-04-02 12:32:53 -0700 | [diff] [blame] | 4439 | |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 4440 | /** |
| 4441 | * Perform clean-up of service connections in an activity record. |
| 4442 | */ |
Andrii Kulian | 21713ac | 2016-10-12 22:05:05 -0700 | [diff] [blame] | 4443 | private void cleanUpActivityServicesLocked(ActivityRecord r) { |
Wale Ogunwale | c4e63a4 | 2018-10-02 13:19:54 -0700 | [diff] [blame] | 4444 | if (r.mServiceConnectionsHolder == null) { |
| 4445 | return; |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 4446 | } |
Wale Ogunwale | c4e63a4 | 2018-10-02 13:19:54 -0700 | [diff] [blame] | 4447 | // Throw away any services that have been bound by this activity. |
| 4448 | r.mServiceConnectionsHolder.disconnectActivityFromServices(); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 4449 | } |
Dianne Hackborn | 755c8bf | 2012-05-07 15:06:09 -0700 | [diff] [blame] | 4450 | |
Wale Ogunwale | 9e4f3e0 | 2018-05-17 09:35:39 -0700 | [diff] [blame] | 4451 | final void scheduleDestroyActivities(WindowProcessController owner, String reason) { |
Dianne Hackborn | 755c8bf | 2012-05-07 15:06:09 -0700 | [diff] [blame] | 4452 | Message msg = mHandler.obtainMessage(DESTROY_ACTIVITIES_MSG); |
Craig Mautner | ee2e45a | 2014-06-27 12:10:03 -0700 | [diff] [blame] | 4453 | msg.obj = new ScheduleDestroyArgs(owner, reason); |
Dianne Hackborn | 755c8bf | 2012-05-07 15:06:09 -0700 | [diff] [blame] | 4454 | mHandler.sendMessage(msg); |
| 4455 | } |
| 4456 | |
Wale Ogunwale | 9e4f3e0 | 2018-05-17 09:35:39 -0700 | [diff] [blame] | 4457 | private void destroyActivitiesLocked(WindowProcessController owner, String reason) { |
Dianne Hackborn | 755c8bf | 2012-05-07 15:06:09 -0700 | [diff] [blame] | 4458 | boolean lastIsOpaque = false; |
Dianne Hackborn | 42e620c | 2012-06-24 13:20:51 -0700 | [diff] [blame] | 4459 | boolean activityRemoved = false; |
Craig Mautner | d44711d | 2013-02-23 11:24:36 -0800 | [diff] [blame] | 4460 | for (int taskNdx = mTaskHistory.size() - 1; taskNdx >= 0; --taskNdx) { |
| 4461 | final ArrayList<ActivityRecord> activities = mTaskHistory.get(taskNdx).mActivities; |
| 4462 | for (int activityNdx = activities.size() - 1; activityNdx >= 0; --activityNdx) { |
| 4463 | final ActivityRecord r = activities.get(activityNdx); |
| 4464 | if (r.finishing) { |
| 4465 | continue; |
| 4466 | } |
| 4467 | if (r.fullscreen) { |
| 4468 | lastIsOpaque = true; |
| 4469 | } |
| 4470 | if (owner != null && r.app != owner) { |
| 4471 | continue; |
| 4472 | } |
| 4473 | if (!lastIsOpaque) { |
| 4474 | continue; |
| 4475 | } |
Dianne Hackborn | 89ad456 | 2014-08-24 16:45:38 -0700 | [diff] [blame] | 4476 | if (r.isDestroyable()) { |
Bryce Lee | 7ace395 | 2018-02-16 14:34:32 -0800 | [diff] [blame] | 4477 | if (DEBUG_SWITCH) Slog.v(TAG_SWITCH, "Destroying " + r |
| 4478 | + " in state " + r.getState() |
Craig Mautner | d44711d | 2013-02-23 11:24:36 -0800 | [diff] [blame] | 4479 | + " resumed=" + mResumedActivity |
Dianne Hackborn | 89ad456 | 2014-08-24 16:45:38 -0700 | [diff] [blame] | 4480 | + " pausing=" + mPausingActivity + " for reason " + reason); |
Craig Mautner | ee2e45a | 2014-06-27 12:10:03 -0700 | [diff] [blame] | 4481 | if (destroyActivityLocked(r, true, reason)) { |
Craig Mautner | d44711d | 2013-02-23 11:24:36 -0800 | [diff] [blame] | 4482 | activityRemoved = true; |
| 4483 | } |
Dianne Hackborn | 42e620c | 2012-06-24 13:20:51 -0700 | [diff] [blame] | 4484 | } |
Dianne Hackborn | ce86ba8 | 2011-07-13 19:33:41 -0700 | [diff] [blame] | 4485 | } |
| 4486 | } |
Dianne Hackborn | 42e620c | 2012-06-24 13:20:51 -0700 | [diff] [blame] | 4487 | if (activityRemoved) { |
Wale Ogunwale | d32da47 | 2018-11-16 07:19:28 -0800 | [diff] [blame] | 4488 | mRootActivityContainer.resumeFocusedStacksTopActivities(); |
Dianne Hackborn | 42e620c | 2012-06-24 13:20:51 -0700 | [diff] [blame] | 4489 | } |
Dianne Hackborn | ce86ba8 | 2011-07-13 19:33:41 -0700 | [diff] [blame] | 4490 | } |
| 4491 | |
Dianne Hackborn | 89ad456 | 2014-08-24 16:45:38 -0700 | [diff] [blame] | 4492 | final boolean safelyDestroyActivityLocked(ActivityRecord r, String reason) { |
| 4493 | if (r.isDestroyable()) { |
Wale Ogunwale | ee006da | 2015-03-30 14:49:25 -0700 | [diff] [blame] | 4494 | if (DEBUG_SWITCH) Slog.v(TAG_SWITCH, |
Bryce Lee | 7ace395 | 2018-02-16 14:34:32 -0800 | [diff] [blame] | 4495 | "Destroying " + r + " in state " + r.getState() + " resumed=" + mResumedActivity |
Dianne Hackborn | 89ad456 | 2014-08-24 16:45:38 -0700 | [diff] [blame] | 4496 | + " pausing=" + mPausingActivity + " for reason " + reason); |
| 4497 | return destroyActivityLocked(r, true, reason); |
| 4498 | } |
| 4499 | return false; |
| 4500 | } |
| 4501 | |
Wale Ogunwale | 9e4f3e0 | 2018-05-17 09:35:39 -0700 | [diff] [blame] | 4502 | final int releaseSomeActivitiesLocked(WindowProcessController app, ArraySet<TaskRecord> tasks, |
Dianne Hackborn | 89ad456 | 2014-08-24 16:45:38 -0700 | [diff] [blame] | 4503 | String reason) { |
| 4504 | // Iterate over tasks starting at the back (oldest) first. |
Wale Ogunwale | 0fc365c | 2015-05-25 19:35:42 -0700 | [diff] [blame] | 4505 | 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] | 4506 | int maxTasks = tasks.size() / 4; |
| 4507 | if (maxTasks < 1) { |
| 4508 | maxTasks = 1; |
| 4509 | } |
| 4510 | int numReleased = 0; |
| 4511 | for (int taskNdx = 0; taskNdx < mTaskHistory.size() && maxTasks > 0; taskNdx++) { |
| 4512 | final TaskRecord task = mTaskHistory.get(taskNdx); |
| 4513 | if (!tasks.contains(task)) { |
| 4514 | continue; |
| 4515 | } |
Wale Ogunwale | 0fc365c | 2015-05-25 19:35:42 -0700 | [diff] [blame] | 4516 | 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] | 4517 | int curNum = 0; |
| 4518 | final ArrayList<ActivityRecord> activities = task.mActivities; |
| 4519 | for (int actNdx = 0; actNdx < activities.size(); actNdx++) { |
| 4520 | final ActivityRecord activity = activities.get(actNdx); |
| 4521 | if (activity.app == app && activity.isDestroyable()) { |
Wale Ogunwale | 0fc365c | 2015-05-25 19:35:42 -0700 | [diff] [blame] | 4522 | if (DEBUG_RELEASE) Slog.v(TAG_RELEASE, "Destroying " + activity |
Bryce Lee | 7ace395 | 2018-02-16 14:34:32 -0800 | [diff] [blame] | 4523 | + " in state " + activity.getState() + " resumed=" + mResumedActivity |
Dianne Hackborn | 89ad456 | 2014-08-24 16:45:38 -0700 | [diff] [blame] | 4524 | + " pausing=" + mPausingActivity + " for reason " + reason); |
| 4525 | destroyActivityLocked(activity, true, reason); |
| 4526 | if (activities.get(actNdx) != activity) { |
| 4527 | // Was removed from list, back up so we don't miss the next one. |
| 4528 | actNdx--; |
| 4529 | } |
| 4530 | curNum++; |
| 4531 | } |
| 4532 | } |
| 4533 | if (curNum > 0) { |
| 4534 | numReleased += curNum; |
| 4535 | maxTasks--; |
| 4536 | if (mTaskHistory.get(taskNdx) != task) { |
| 4537 | // The entire task got removed, back up so we don't miss the next one. |
| 4538 | taskNdx--; |
| 4539 | } |
| 4540 | } |
| 4541 | } |
Wale Ogunwale | 0fc365c | 2015-05-25 19:35:42 -0700 | [diff] [blame] | 4542 | if (DEBUG_RELEASE) Slog.d(TAG_RELEASE, |
| 4543 | "Done releasing: did " + numReleased + " activities"); |
Dianne Hackborn | 89ad456 | 2014-08-24 16:45:38 -0700 | [diff] [blame] | 4544 | return numReleased; |
| 4545 | } |
| 4546 | |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 4547 | /** |
| 4548 | * Destroy the current CLIENT SIDE instance of an activity. This may be |
| 4549 | * called both when actually finishing an activity, or when performing |
| 4550 | * a configuration switch where we destroy the current client-side object |
| 4551 | * but then create a new client-side object for this same HistoryRecord. |
| 4552 | */ |
Craig Mautner | ee2e45a | 2014-06-27 12:10:03 -0700 | [diff] [blame] | 4553 | final boolean destroyActivityLocked(ActivityRecord r, boolean removeFromApp, String reason) { |
Wale Ogunwale | ee006da | 2015-03-30 14:49:25 -0700 | [diff] [blame] | 4554 | if (DEBUG_SWITCH || DEBUG_CLEANUP) Slog.v(TAG_SWITCH, |
| 4555 | "Removing activity from " + reason + ": token=" + r |
Wale Ogunwale | 9e4f3e0 | 2018-05-17 09:35:39 -0700 | [diff] [blame] | 4556 | + ", app=" + (r.hasProcess() ? r.app.mName : "(null)")); |
Bryce Lee | b0f993f | 2018-03-02 15:38:01 -0800 | [diff] [blame] | 4557 | |
| 4558 | if (r.isState(DESTROYING, DESTROYED)) { |
Bryce Lee | c940660 | 2018-03-09 11:02:10 -0800 | [diff] [blame] | 4559 | if (DEBUG_STATES) Slog.v(TAG_STATES, "activity " + r + " already destroying." |
Bryce Lee | b0f993f | 2018-03-02 15:38:01 -0800 | [diff] [blame] | 4560 | + "skipping request with reason:" + reason); |
| 4561 | return false; |
| 4562 | } |
| 4563 | |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 4564 | EventLog.writeEvent(EventLogTags.AM_DESTROY_ACTIVITY, |
Wale Ogunwale | 8b19de9 | 2018-11-29 19:58:26 -0800 | [diff] [blame] | 4565 | r.mUserId, System.identityHashCode(r), |
| 4566 | r.getTaskRecord().taskId, r.shortComponentName, reason); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 4567 | |
| 4568 | boolean removedFromHistory = false; |
Dianne Hackborn | cc5a055 | 2012-10-01 16:32:39 -0700 | [diff] [blame] | 4569 | |
Bryce Lee | c940660 | 2018-03-09 11:02:10 -0800 | [diff] [blame] | 4570 | cleanUpActivityLocked(r, false, false); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 4571 | |
Wale Ogunwale | 9e4f3e0 | 2018-05-17 09:35:39 -0700 | [diff] [blame] | 4572 | final boolean hadApp = r.hasProcess(); |
Dianne Hackborn | cc5a055 | 2012-10-01 16:32:39 -0700 | [diff] [blame] | 4573 | |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 4574 | if (hadApp) { |
| 4575 | if (removeFromApp) { |
Wale Ogunwale | 9e4f3e0 | 2018-05-17 09:35:39 -0700 | [diff] [blame] | 4576 | r.app.removeActivity(r); |
Wale Ogunwale | 5378374 | 2018-09-16 10:21:51 -0700 | [diff] [blame] | 4577 | if (!r.app.hasActivities()) { |
| 4578 | mService.clearHeavyWeightProcessIfEquals(r.app); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 4579 | } |
Wale Ogunwale | 9e4f3e0 | 2018-05-17 09:35:39 -0700 | [diff] [blame] | 4580 | if (!r.app.hasActivities()) { |
Dianne Hackborn | 465fa39 | 2014-09-14 14:21:18 -0700 | [diff] [blame] | 4581 | // Update any services we are bound to that might care about whether |
| 4582 | // their client may have activities. |
Dianne Hackborn | 3bc8f78d | 2013-09-19 13:34:35 -0700 | [diff] [blame] | 4583 | // No longer have activities, so update LRU list and oom adj. |
Wale Ogunwale | 9e4f3e0 | 2018-05-17 09:35:39 -0700 | [diff] [blame] | 4584 | r.app.updateProcessInfo(true, true, false, true); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 4585 | } |
| 4586 | } |
| 4587 | |
| 4588 | boolean skipDestroy = false; |
Craig Mautner | dbcb31f | 2013-04-02 12:32:53 -0700 | [diff] [blame] | 4589 | |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 4590 | try { |
Wale Ogunwale | ee006da | 2015-03-30 14:49:25 -0700 | [diff] [blame] | 4591 | if (DEBUG_SWITCH) Slog.i(TAG_SWITCH, "Destroying: " + r); |
Wale Ogunwale | 9e4f3e0 | 2018-05-17 09:35:39 -0700 | [diff] [blame] | 4592 | mService.getLifecycleManager().scheduleTransaction(r.app.getThread(), r.appToken, |
Bryce Lee | 1d0d514 | 2018-04-12 10:35:07 -0700 | [diff] [blame] | 4593 | DestroyActivityItem.obtain(r.finishing, r.configChangeFlags)); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 4594 | } catch (Exception e) { |
| 4595 | // We can just ignore exceptions here... if the process |
| 4596 | // has crashed, our death notification will clean things |
| 4597 | // up. |
| 4598 | //Slog.w(TAG, "Exception thrown during finish", e); |
| 4599 | if (r.finishing) { |
Chong Zhang | bffd889 | 2016-08-08 11:16:06 -0700 | [diff] [blame] | 4600 | removeActivityFromHistoryLocked(r, reason + " exceptionInScheduleDestroy"); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 4601 | removedFromHistory = true; |
| 4602 | skipDestroy = true; |
| 4603 | } |
| 4604 | } |
| 4605 | |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 4606 | r.nowVisible = false; |
Craig Mautner | dbcb31f | 2013-04-02 12:32:53 -0700 | [diff] [blame] | 4607 | |
Dianne Hackborn | ce86ba8 | 2011-07-13 19:33:41 -0700 | [diff] [blame] | 4608 | // If the activity is finishing, we need to wait on removing it |
| 4609 | // from the list to give it a chance to do its cleanup. During |
| 4610 | // that time it may make calls back with its token so we need to |
| 4611 | // be able to find it on the list and so we don't want to remove |
| 4612 | // it from the list yet. Otherwise, we can just immediately put |
| 4613 | // it in the destroyed state since we are not removing it from the |
| 4614 | // list. |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 4615 | if (r.finishing && !skipDestroy) { |
Wale Ogunwale | 0fc365c | 2015-05-25 19:35:42 -0700 | [diff] [blame] | 4616 | if (DEBUG_STATES) Slog.v(TAG_STATES, "Moving to DESTROYING: " + r |
Dianne Hackborn | ce86ba8 | 2011-07-13 19:33:41 -0700 | [diff] [blame] | 4617 | + " (destroy requested)"); |
Bryce Lee | 7ace395 | 2018-02-16 14:34:32 -0800 | [diff] [blame] | 4618 | r.setState(DESTROYING, |
| 4619 | "destroyActivityLocked. finishing and not skipping destroy"); |
Craig Mautner | f7bfefb | 2013-05-16 17:30:44 -0700 | [diff] [blame] | 4620 | Message msg = mHandler.obtainMessage(DESTROY_TIMEOUT_MSG, r); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 4621 | mHandler.sendMessageDelayed(msg, DESTROY_TIMEOUT); |
| 4622 | } else { |
Wale Ogunwale | 0fc365c | 2015-05-25 19:35:42 -0700 | [diff] [blame] | 4623 | if (DEBUG_STATES) Slog.v(TAG_STATES, |
| 4624 | "Moving to DESTROYED: " + r + " (destroy skipped)"); |
Bryce Lee | 7ace395 | 2018-02-16 14:34:32 -0800 | [diff] [blame] | 4625 | r.setState(DESTROYED, |
| 4626 | "destroyActivityLocked. not finishing or skipping destroy"); |
Wale Ogunwale | 0fc365c | 2015-05-25 19:35:42 -0700 | [diff] [blame] | 4627 | 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] | 4628 | r.app = null; |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 4629 | } |
| 4630 | } else { |
| 4631 | // remove this record from the history. |
| 4632 | if (r.finishing) { |
Chong Zhang | bffd889 | 2016-08-08 11:16:06 -0700 | [diff] [blame] | 4633 | removeActivityFromHistoryLocked(r, reason + " hadNoApp"); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 4634 | removedFromHistory = true; |
| 4635 | } else { |
Wale Ogunwale | 0fc365c | 2015-05-25 19:35:42 -0700 | [diff] [blame] | 4636 | 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] | 4637 | r.setState(DESTROYED, "destroyActivityLocked. not finishing and had no app"); |
Wale Ogunwale | 0fc365c | 2015-05-25 19:35:42 -0700 | [diff] [blame] | 4638 | 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] | 4639 | r.app = null; |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 4640 | } |
| 4641 | } |
| 4642 | |
| 4643 | r.configChangeFlags = 0; |
Craig Mautner | dbcb31f | 2013-04-02 12:32:53 -0700 | [diff] [blame] | 4644 | |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 4645 | if (!mLRUActivities.remove(r) && hadApp) { |
| 4646 | Slog.w(TAG, "Activity " + r + " being finished, but not in LRU list"); |
| 4647 | } |
Craig Mautner | dbcb31f | 2013-04-02 12:32:53 -0700 | [diff] [blame] | 4648 | |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 4649 | return removedFromHistory; |
| 4650 | } |
| 4651 | |
Craig Mautner | 299f960 | 2015-01-26 09:47:33 -0800 | [diff] [blame] | 4652 | final void activityDestroyedLocked(IBinder token, String reason) { |
Craig Mautner | d232895 | 2013-03-05 12:46:26 -0800 | [diff] [blame] | 4653 | final long origId = Binder.clearCallingIdentity(); |
| 4654 | try { |
Bryce Lee | 7ace395 | 2018-02-16 14:34:32 -0800 | [diff] [blame] | 4655 | activityDestroyedLocked(ActivityRecord.forTokenLocked(token), reason); |
Craig Mautner | d232895 | 2013-03-05 12:46:26 -0800 | [diff] [blame] | 4656 | } finally { |
| 4657 | Binder.restoreCallingIdentity(origId); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 4658 | } |
| 4659 | } |
Craig Mautner | de4ef02 | 2013-04-07 19:01:33 -0700 | [diff] [blame] | 4660 | |
Bryce Lee | c940660 | 2018-03-09 11:02:10 -0800 | [diff] [blame] | 4661 | /** |
| 4662 | * This method is to only be called from the client via binder when the activity is destroyed |
| 4663 | * AND finished. |
| 4664 | */ |
Bryce Lee | 7ace395 | 2018-02-16 14:34:32 -0800 | [diff] [blame] | 4665 | final void activityDestroyedLocked(ActivityRecord record, String reason) { |
| 4666 | if (record != null) { |
| 4667 | mHandler.removeMessages(DESTROY_TIMEOUT_MSG, record); |
| 4668 | } |
| 4669 | |
| 4670 | if (DEBUG_CONTAINERS) Slog.d(TAG_CONTAINERS, "activityDestroyedLocked: r=" + record); |
| 4671 | |
| 4672 | if (isInStackLocked(record) != null) { |
| 4673 | if (record.isState(DESTROYING, DESTROYED)) { |
Bryce Lee | c940660 | 2018-03-09 11:02:10 -0800 | [diff] [blame] | 4674 | cleanUpActivityLocked(record, true, false); |
Bryce Lee | 7ace395 | 2018-02-16 14:34:32 -0800 | [diff] [blame] | 4675 | removeActivityFromHistoryLocked(record, reason); |
| 4676 | } |
| 4677 | } |
| 4678 | |
Wale Ogunwale | d32da47 | 2018-11-16 07:19:28 -0800 | [diff] [blame] | 4679 | mRootActivityContainer.resumeFocusedStacksTopActivities(); |
Bryce Lee | 7ace395 | 2018-02-16 14:34:32 -0800 | [diff] [blame] | 4680 | } |
| 4681 | |
Craig Mautner | 05d6272ba | 2013-02-11 09:39:27 -0800 | [diff] [blame] | 4682 | private void removeHistoryRecordsForAppLocked(ArrayList<ActivityRecord> list, |
Wale Ogunwale | 9e4f3e0 | 2018-05-17 09:35:39 -0700 | [diff] [blame] | 4683 | WindowProcessController app, String listName) { |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 4684 | int i = list.size(); |
Wale Ogunwale | e23149f | 2015-03-06 15:39:44 -0800 | [diff] [blame] | 4685 | if (DEBUG_CLEANUP) Slog.v(TAG_CLEANUP, |
| 4686 | "Removing app " + app + " from list " + listName + " with " + i + " entries"); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 4687 | while (i > 0) { |
| 4688 | i--; |
Craig Mautner | 05d6272ba | 2013-02-11 09:39:27 -0800 | [diff] [blame] | 4689 | ActivityRecord r = list.get(i); |
Wale Ogunwale | e23149f | 2015-03-06 15:39:44 -0800 | [diff] [blame] | 4690 | if (DEBUG_CLEANUP) Slog.v(TAG_CLEANUP, "Record #" + i + " " + r); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 4691 | if (r.app == app) { |
Wale Ogunwale | e23149f | 2015-03-06 15:39:44 -0800 | [diff] [blame] | 4692 | if (DEBUG_CLEANUP) Slog.v(TAG_CLEANUP, "---> REMOVING this entry!"); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 4693 | list.remove(i); |
Dianne Hackborn | 42e620c | 2012-06-24 13:20:51 -0700 | [diff] [blame] | 4694 | removeTimeoutsForActivityLocked(r); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 4695 | } |
| 4696 | } |
| 4697 | } |
| 4698 | |
Wale Ogunwale | 9e4f3e0 | 2018-05-17 09:35:39 -0700 | [diff] [blame] | 4699 | private boolean removeHistoryRecordsForAppLocked(WindowProcessController app) { |
Dianne Hackborn | cc5a055 | 2012-10-01 16:32:39 -0700 | [diff] [blame] | 4700 | removeHistoryRecordsForAppLocked(mLRUActivities, app, "mLRUActivities"); |
Craig Mautner | de4ef02 | 2013-04-07 19:01:33 -0700 | [diff] [blame] | 4701 | removeHistoryRecordsForAppLocked(mStackSupervisor.mStoppingActivities, app, |
| 4702 | "mStoppingActivities"); |
Craig Mautner | 0eea92c | 2013-05-16 13:35:39 -0700 | [diff] [blame] | 4703 | removeHistoryRecordsForAppLocked(mStackSupervisor.mGoingToSleepActivities, app, |
| 4704 | "mGoingToSleepActivities"); |
Craig Mautner | f333327 | 2013-04-22 10:55:53 -0700 | [diff] [blame] | 4705 | removeHistoryRecordsForAppLocked(mStackSupervisor.mFinishingActivities, app, |
| 4706 | "mFinishingActivities"); |
Dianne Hackborn | cc5a055 | 2012-10-01 16:32:39 -0700 | [diff] [blame] | 4707 | |
Riddle Hsu | aaef731 | 2019-01-24 19:00:58 +0800 | [diff] [blame] | 4708 | final boolean isProcessRemoved = app.isRemoved(); |
| 4709 | if (isProcessRemoved) { |
| 4710 | // The package of the died process should be force-stopped, so make its activities as |
| 4711 | // finishing to prevent the process from being started again if the next top (or being |
| 4712 | // visible) activity also resides in the same process. |
| 4713 | app.makeFinishingForProcessRemoved(); |
| 4714 | } |
| 4715 | |
Dianne Hackborn | cc5a055 | 2012-10-01 16:32:39 -0700 | [diff] [blame] | 4716 | boolean hasVisibleActivities = false; |
| 4717 | |
| 4718 | // Clean out the history list. |
Craig Mautner | 0247fc8 | 2013-02-28 14:32:06 -0800 | [diff] [blame] | 4719 | int i = numActivities(); |
Wale Ogunwale | e23149f | 2015-03-06 15:39:44 -0800 | [diff] [blame] | 4720 | if (DEBUG_CLEANUP) Slog.v(TAG_CLEANUP, |
| 4721 | "Removing app " + app + " from history with " + i + " entries"); |
Craig Mautner | 0247fc8 | 2013-02-28 14:32:06 -0800 | [diff] [blame] | 4722 | for (int taskNdx = mTaskHistory.size() - 1; taskNdx >= 0; --taskNdx) { |
| 4723 | final ArrayList<ActivityRecord> activities = mTaskHistory.get(taskNdx).mActivities; |
Bryce Lee | fbd263b4 | 2018-03-07 10:33:55 -0800 | [diff] [blame] | 4724 | mTmpActivities.clear(); |
| 4725 | mTmpActivities.addAll(activities); |
| 4726 | |
| 4727 | while (!mTmpActivities.isEmpty()) { |
| 4728 | final int targetIndex = mTmpActivities.size() - 1; |
| 4729 | final ActivityRecord r = mTmpActivities.remove(targetIndex); |
Wale Ogunwale | e23149f | 2015-03-06 15:39:44 -0800 | [diff] [blame] | 4730 | if (DEBUG_CLEANUP) Slog.v(TAG_CLEANUP, |
Bryce Lee | fbd263b4 | 2018-03-07 10:33:55 -0800 | [diff] [blame] | 4731 | "Record #" + targetIndex + " " + r + ": app=" + r.app); |
| 4732 | |
Craig Mautner | 0247fc8 | 2013-02-28 14:32:06 -0800 | [diff] [blame] | 4733 | if (r.app == app) { |
riddle_hsu | 558e849 | 2015-04-02 16:43:13 +0800 | [diff] [blame] | 4734 | if (r.visible) { |
| 4735 | hasVisibleActivities = true; |
| 4736 | } |
Craig Mautner | acebdc8 | 2015-02-24 10:53:03 -0800 | [diff] [blame] | 4737 | final boolean remove; |
Garfield Tan | 2746ab5 | 2018-07-25 12:33:01 -0700 | [diff] [blame] | 4738 | if ((r.mRelaunchReason == RELAUNCH_REASON_WINDOWING_MODE_RESIZE |
| 4739 | || r.mRelaunchReason == RELAUNCH_REASON_FREE_RESIZE) |
| 4740 | && r.launchCount < 3 && !r.finishing) { |
| 4741 | // If the process crashed during a resize, always try to relaunch it, unless |
| 4742 | // it has failed more than twice. Skip activities that's already finishing |
| 4743 | // cleanly by itself. |
| 4744 | remove = false; |
Riddle Hsu | 7b766fd | 2019-01-28 21:14:59 +0800 | [diff] [blame] | 4745 | } else if ((!r.haveState && !r.stateNotNeeded |
| 4746 | && !r.isState(ActivityState.RESTARTING_PROCESS)) || r.finishing) { |
Craig Mautner | 0247fc8 | 2013-02-28 14:32:06 -0800 | [diff] [blame] | 4747 | // Don't currently have state for the activity, or |
| 4748 | // it is finishing -- always remove it. |
| 4749 | remove = true; |
Chong Zhang | 112eb8c | 2015-11-02 11:17:00 -0800 | [diff] [blame] | 4750 | } else if (!r.visible && r.launchCount > 2 && |
| 4751 | r.lastLaunchTime > (SystemClock.uptimeMillis() - 60000)) { |
Craig Mautner | 0247fc8 | 2013-02-28 14:32:06 -0800 | [diff] [blame] | 4752 | // We have launched this activity too many times since it was |
| 4753 | // able to run, so give up and remove it. |
Chong Zhang | 112eb8c | 2015-11-02 11:17:00 -0800 | [diff] [blame] | 4754 | // (Note if the activity is visible, we don't remove the record. |
| 4755 | // We leave the dead window on the screen but the process will |
| 4756 | // not be restarted unless user explicitly tap on it.) |
Craig Mautner | 0247fc8 | 2013-02-28 14:32:06 -0800 | [diff] [blame] | 4757 | remove = true; |
| 4758 | } else { |
| 4759 | // The process may be gone, but the activity lives on! |
| 4760 | remove = false; |
Dianne Hackborn | cc5a055 | 2012-10-01 16:32:39 -0700 | [diff] [blame] | 4761 | } |
Craig Mautner | 0247fc8 | 2013-02-28 14:32:06 -0800 | [diff] [blame] | 4762 | if (remove) { |
Wale Ogunwale | 0fc365c | 2015-05-25 19:35:42 -0700 | [diff] [blame] | 4763 | if (DEBUG_ADD_REMOVE || DEBUG_CLEANUP) Slog.i(TAG_ADD_REMOVE, |
| 4764 | "Removing activity " + r + " from stack at " + i |
| 4765 | + ": haveState=" + r.haveState |
| 4766 | + " stateNotNeeded=" + r.stateNotNeeded |
| 4767 | + " finishing=" + r.finishing |
Bryce Lee | 7ace395 | 2018-02-16 14:34:32 -0800 | [diff] [blame] | 4768 | + " state=" + r.getState() + " callers=" + Debug.getCallers(5)); |
Riddle Hsu | aaef731 | 2019-01-24 19:00:58 +0800 | [diff] [blame] | 4769 | if (!r.finishing || isProcessRemoved) { |
Craig Mautner | 0247fc8 | 2013-02-28 14:32:06 -0800 | [diff] [blame] | 4770 | Slog.w(TAG, "Force removing " + r + ": app died, no saved state"); |
| 4771 | EventLog.writeEvent(EventLogTags.AM_FINISH_ACTIVITY, |
Wale Ogunwale | 8b19de9 | 2018-11-29 19:58:26 -0800 | [diff] [blame] | 4772 | r.mUserId, System.identityHashCode(r), |
| 4773 | r.getTaskRecord().taskId, r.shortComponentName, |
Craig Mautner | 0247fc8 | 2013-02-28 14:32:06 -0800 | [diff] [blame] | 4774 | "proc died without state saved"); |
| 4775 | } |
Craig Mautner | 0247fc8 | 2013-02-28 14:32:06 -0800 | [diff] [blame] | 4776 | } else { |
| 4777 | // We have the current state for this activity, so |
| 4778 | // it can be restarted later when needed. |
Wale Ogunwale | 0fc365c | 2015-05-25 19:35:42 -0700 | [diff] [blame] | 4779 | if (DEBUG_ALL) Slog.v(TAG, "Keeping entry, setting app to null"); |
| 4780 | if (DEBUG_APP) Slog.v(TAG_APP, |
| 4781 | "Clearing app during removeHistory for activity " + r); |
Craig Mautner | 0247fc8 | 2013-02-28 14:32:06 -0800 | [diff] [blame] | 4782 | r.app = null; |
Chong Zhang | 112eb8c | 2015-11-02 11:17:00 -0800 | [diff] [blame] | 4783 | // Set nowVisible to previous visible state. If the app was visible while |
| 4784 | // it died, we leave the dead window on screen so it's basically visible. |
| 4785 | // This is needed when user later tap on the dead window, we need to stop |
| 4786 | // other apps when user transfers focus to the restarted activity. |
| 4787 | r.nowVisible = r.visible; |
Craig Mautner | 0247fc8 | 2013-02-28 14:32:06 -0800 | [diff] [blame] | 4788 | if (!r.haveState) { |
Wale Ogunwale | 0fc365c | 2015-05-25 19:35:42 -0700 | [diff] [blame] | 4789 | if (DEBUG_SAVED_STATE) Slog.i(TAG_SAVED_STATE, |
Craig Mautner | 0247fc8 | 2013-02-28 14:32:06 -0800 | [diff] [blame] | 4790 | "App died, clearing saved state of " + r); |
| 4791 | r.icicle = null; |
| 4792 | } |
Dianne Hackborn | cc5a055 | 2012-10-01 16:32:39 -0700 | [diff] [blame] | 4793 | } |
Bryce Lee | c940660 | 2018-03-09 11:02:10 -0800 | [diff] [blame] | 4794 | cleanUpActivityLocked(r, true, true); |
Craig Mautner | acebdc8 | 2015-02-24 10:53:03 -0800 | [diff] [blame] | 4795 | if (remove) { |
Chong Zhang | bffd889 | 2016-08-08 11:16:06 -0700 | [diff] [blame] | 4796 | removeActivityFromHistoryLocked(r, "appDied"); |
Craig Mautner | acebdc8 | 2015-02-24 10:53:03 -0800 | [diff] [blame] | 4797 | } |
Craig Mautner | 0247fc8 | 2013-02-28 14:32:06 -0800 | [diff] [blame] | 4798 | } |
Dianne Hackborn | cc5a055 | 2012-10-01 16:32:39 -0700 | [diff] [blame] | 4799 | } |
| 4800 | } |
| 4801 | |
| 4802 | return hasVisibleActivities; |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 4803 | } |
Craig Mautner | 0247fc8 | 2013-02-28 14:32:06 -0800 | [diff] [blame] | 4804 | |
chaviw | 0d562bf | 2018-03-15 14:24:14 -0700 | [diff] [blame] | 4805 | private void updateTransitLocked(int transit, ActivityOptions options) { |
Dianne Hackborn | 7f58b95 | 2012-04-18 12:59:29 -0700 | [diff] [blame] | 4806 | if (options != null) { |
chaviw | 0d562bf | 2018-03-15 14:24:14 -0700 | [diff] [blame] | 4807 | ActivityRecord r = topRunningActivityLocked(); |
| 4808 | if (r != null && !r.isState(RESUMED)) { |
| 4809 | r.updateOptionsLocked(options); |
Dianne Hackborn | 7f58b95 | 2012-04-18 12:59:29 -0700 | [diff] [blame] | 4810 | } else { |
| 4811 | ActivityOptions.abort(options); |
| 4812 | } |
| 4813 | } |
Wale Ogunwale | 3a256e6 | 2018-12-06 14:41:18 -0800 | [diff] [blame] | 4814 | getDisplay().mDisplayContent.prepareAppTransition(transit, false); |
Dianne Hackborn | 7f58b95 | 2012-04-18 12:59:29 -0700 | [diff] [blame] | 4815 | } |
Dianne Hackborn | 621e17d | 2010-11-22 15:59:56 -0800 | [diff] [blame] | 4816 | |
Andrii Kulian | 21713ac | 2016-10-12 22:05:05 -0700 | [diff] [blame] | 4817 | private void updateTaskMovement(TaskRecord task, boolean toFront) { |
Craig Mautner | 21d24a2 | 2014-04-23 11:45:37 -0700 | [diff] [blame] | 4818 | if (task.isPersistable) { |
| 4819 | task.mLastTimeMoved = System.currentTimeMillis(); |
| 4820 | // Sign is used to keep tasks sorted when persisted. Tasks sent to the bottom most |
| 4821 | // recently will be most negative, tasks sent to the bottom before that will be less |
| 4822 | // negative. Similarly for recent tasks moved to the top which will be most positive. |
| 4823 | if (!toFront) { |
| 4824 | task.mLastTimeMoved *= -1; |
| 4825 | } |
| 4826 | } |
Wale Ogunwale | d32da47 | 2018-11-16 07:19:28 -0800 | [diff] [blame] | 4827 | mRootActivityContainer.invalidateTaskLayers(); |
Craig Mautner | 21d24a2 | 2014-04-23 11:45:37 -0700 | [diff] [blame] | 4828 | } |
| 4829 | |
chaviw | 0d562bf | 2018-03-15 14:24:14 -0700 | [diff] [blame] | 4830 | final void moveTaskToFrontLocked(TaskRecord tr, boolean noAnimation, ActivityOptions options, |
| 4831 | AppTimeTracker timeTracker, String reason) { |
Wale Ogunwale | ee006da | 2015-03-30 14:49:25 -0700 | [diff] [blame] | 4832 | if (DEBUG_SWITCH) Slog.v(TAG_SWITCH, "moveTaskToFront: " + tr); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 4833 | |
Wale Ogunwale | a0f5b5e | 2017-10-11 09:37:23 -0700 | [diff] [blame] | 4834 | final ActivityStack topStack = getDisplay().getTopStack(); |
Wale Ogunwale | 30e441d | 2017-11-09 08:28:45 -0800 | [diff] [blame] | 4835 | final ActivityRecord topActivity = topStack != null ? topStack.getTopActivity() : null; |
Craig Mautner | 11bf9a5 | 2013-02-19 14:08:51 -0800 | [diff] [blame] | 4836 | final int numTasks = mTaskHistory.size(); |
| 4837 | final int index = mTaskHistory.indexOf(tr); |
Craig Mautner | 86d67a4 | 2013-05-14 10:34:38 -0700 | [diff] [blame] | 4838 | if (numTasks == 0 || index < 0) { |
Craig Mautner | 11bf9a5 | 2013-02-19 14:08:51 -0800 | [diff] [blame] | 4839 | // nothing to do! |
Craig Mautner | 8f5f7e9 | 2015-01-26 18:03:13 -0800 | [diff] [blame] | 4840 | if (noAnimation) { |
Craig Mautner | 11bf9a5 | 2013-02-19 14:08:51 -0800 | [diff] [blame] | 4841 | ActivityOptions.abort(options); |
| 4842 | } else { |
chaviw | 0d562bf | 2018-03-15 14:24:14 -0700 | [diff] [blame] | 4843 | updateTransitLocked(TRANSIT_TASK_TO_FRONT, options); |
Craig Mautner | 11bf9a5 | 2013-02-19 14:08:51 -0800 | [diff] [blame] | 4844 | } |
| 4845 | return; |
| 4846 | } |
| 4847 | |
Dianne Hackborn | b5a380d | 2015-05-20 18:18:46 -0700 | [diff] [blame] | 4848 | if (timeTracker != null) { |
| 4849 | // The caller wants a time tracker associated with this task. |
| 4850 | for (int i = tr.mActivities.size() - 1; i >= 0; i--) { |
| 4851 | tr.mActivities.get(i).appTimeTracker = timeTracker; |
| 4852 | } |
| 4853 | } |
| 4854 | |
Chavi Weingarten | 3a74855 | 2018-05-14 17:32:42 +0000 | [diff] [blame] | 4855 | try { |
| 4856 | // Defer updating the IME target since the new IME target will try to get computed |
| 4857 | // before updating all closing and opening apps, which can cause the ime target to |
| 4858 | // get calculated incorrectly. |
| 4859 | getDisplay().deferUpdateImeTarget(); |
Wale Ogunwale | d80c263 | 2015-03-13 10:26:26 -0700 | [diff] [blame] | 4860 | |
Chavi Weingarten | 3a74855 | 2018-05-14 17:32:42 +0000 | [diff] [blame] | 4861 | // Shift all activities with this task up to the top |
| 4862 | // of the stack, keeping them in the same internal order. |
| 4863 | insertTaskAtTop(tr, null); |
| 4864 | |
| 4865 | // Don't refocus if invisible to current user |
| 4866 | final ActivityRecord top = tr.getTopActivity(); |
| 4867 | if (top == null || !top.okToShowLocked()) { |
| 4868 | if (top != null) { |
Wale Ogunwale | 8b19de9 | 2018-11-29 19:58:26 -0800 | [diff] [blame] | 4869 | mStackSupervisor.mRecentTasks.add(top.getTaskRecord()); |
Chavi Weingarten | 3a74855 | 2018-05-14 17:32:42 +0000 | [diff] [blame] | 4870 | } |
| 4871 | ActivityOptions.abort(options); |
| 4872 | return; |
Winson Chung | 1dbc811 | 2017-09-28 18:05:31 -0700 | [diff] [blame] | 4873 | } |
Chavi Weingarten | 9e875b6 | 2018-05-14 16:10:59 +0000 | [diff] [blame] | 4874 | |
Chavi Weingarten | 3a74855 | 2018-05-14 17:32:42 +0000 | [diff] [blame] | 4875 | // Set focus to the top running activity of this stack. |
| 4876 | final ActivityRecord r = topRunningActivityLocked(); |
Louis Chang | 1944345 | 2018-10-09 12:10:21 +0800 | [diff] [blame] | 4877 | if (r != null) { |
| 4878 | r.moveFocusableActivityToTop(reason); |
| 4879 | } |
Chavi Weingarten | 9e875b6 | 2018-05-14 16:10:59 +0000 | [diff] [blame] | 4880 | |
Chavi Weingarten | 3a74855 | 2018-05-14 17:32:42 +0000 | [diff] [blame] | 4881 | if (DEBUG_TRANSITION) Slog.v(TAG_TRANSITION, "Prepare to front transition: task=" + tr); |
| 4882 | if (noAnimation) { |
Wale Ogunwale | 3a256e6 | 2018-12-06 14:41:18 -0800 | [diff] [blame] | 4883 | getDisplay().mDisplayContent.prepareAppTransition(TRANSIT_NONE, false); |
Chavi Weingarten | 3a74855 | 2018-05-14 17:32:42 +0000 | [diff] [blame] | 4884 | if (r != null) { |
| 4885 | mStackSupervisor.mNoAnimActivities.add(r); |
| 4886 | } |
| 4887 | ActivityOptions.abort(options); |
| 4888 | } else { |
| 4889 | updateTransitLocked(TRANSIT_TASK_TO_FRONT, options); |
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 a new task is moved to the front, then mark the existing top activity as |
| 4892 | // supporting |
Chavi Weingarten | 9e875b6 | 2018-05-14 16:10:59 +0000 | [diff] [blame] | 4893 | |
Chavi Weingarten | 3a74855 | 2018-05-14 17:32:42 +0000 | [diff] [blame] | 4894 | // picture-in-picture while paused only if the task would not be considered an oerlay |
| 4895 | // on top |
| 4896 | // of the current activity (eg. not fullscreen, or the assistant) |
| 4897 | if (canEnterPipOnTaskSwitch(topActivity, tr, null /* toFrontActivity */, |
| 4898 | options)) { |
| 4899 | topActivity.supportsEnterPipOnTaskSwitch = true; |
| 4900 | } |
Chavi Weingarten | 9e875b6 | 2018-05-14 16:10:59 +0000 | [diff] [blame] | 4901 | |
Wale Ogunwale | d32da47 | 2018-11-16 07:19:28 -0800 | [diff] [blame] | 4902 | mRootActivityContainer.resumeFocusedStacksTopActivities(); |
Chavi Weingarten | 3a74855 | 2018-05-14 17:32:42 +0000 | [diff] [blame] | 4903 | EventLog.writeEvent(EventLogTags.AM_TASK_TO_FRONT, tr.userId, tr.taskId); |
Mark Renouf | c808f06 | 2019-02-07 15:20:37 -0500 | [diff] [blame] | 4904 | mService.getTaskChangeNotificationController().notifyTaskMovedToFront(tr.getTaskInfo()); |
Chavi Weingarten | 3a74855 | 2018-05-14 17:32:42 +0000 | [diff] [blame] | 4905 | } finally { |
| 4906 | getDisplay().continueUpdateImeTarget(); |
| 4907 | } |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 4908 | } |
| 4909 | |
| 4910 | /** |
Craig Mautner | ce5f3cb | 2013-04-22 08:58:54 -0700 | [diff] [blame] | 4911 | * Worker method for rearranging history stack. Implements the function of moving all |
| 4912 | * 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] | 4913 | * bottom of the stack. |
Craig Mautner | ce5f3cb | 2013-04-22 08:58:54 -0700 | [diff] [blame] | 4914 | * |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 4915 | * If a watcher is installed, the action is preflighted and the watcher has an opportunity |
| 4916 | * to premeptively cancel the move. |
Craig Mautner | ce5f3cb | 2013-04-22 08:58:54 -0700 | [diff] [blame] | 4917 | * |
Craig Mautner | ae7ecab | 2013-09-18 11:48:14 -0700 | [diff] [blame] | 4918 | * @param taskId The taskId to collect and move to the bottom. |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 4919 | * @return Returns true if the move completed, false if not. |
| 4920 | */ |
Craig Mautner | 299f960 | 2015-01-26 09:47:33 -0800 | [diff] [blame] | 4921 | final boolean moveTaskToBackLocked(int taskId) { |
Craig Mautner | aea74a5 | 2014-03-08 14:23:10 -0800 | [diff] [blame] | 4922 | final TaskRecord tr = taskForIdLocked(taskId); |
| 4923 | if (tr == null) { |
| 4924 | Slog.i(TAG, "moveTaskToBack: bad taskId=" + taskId); |
| 4925 | return false; |
| 4926 | } |
Craig Mautner | aea74a5 | 2014-03-08 14:23:10 -0800 | [diff] [blame] | 4927 | Slog.i(TAG, "moveTaskToBack: " + tr); |
Winson Chung | 261c0f3 | 2017-03-07 16:54:31 -0800 | [diff] [blame] | 4928 | |
Charles He | ff9b4dff | 2017-09-22 10:18:37 +0100 | [diff] [blame] | 4929 | // In LockTask mode, moving a locked task to the back of the stack may expose unlocked |
| 4930 | // ones. Therefore we need to check if this operation is allowed. |
Wale Ogunwale | 5fa8a8c | 2018-05-08 13:43:21 -0700 | [diff] [blame] | 4931 | if (!mService.getLockTaskController().canMoveTaskToBack(tr)) { |
Winson Chung | 261c0f3 | 2017-03-07 16:54:31 -0800 | [diff] [blame] | 4932 | return false; |
| 4933 | } |
Craig Mautner | b44de0d | 2013-02-21 20:00:58 -0800 | [diff] [blame] | 4934 | |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 4935 | // If we have a watcher, preflight the move before committing to it. First check |
| 4936 | // for *other* available tasks, but if none are available, then try again allowing the |
| 4937 | // current task to be selected. |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 4938 | if (isTopStackOnDisplay() && mService.mController != null) { |
Craig Mautner | ae7ecab | 2013-09-18 11:48:14 -0700 | [diff] [blame] | 4939 | ActivityRecord next = topRunningActivityLocked(null, taskId); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 4940 | if (next == null) { |
| 4941 | next = topRunningActivityLocked(null, 0); |
| 4942 | } |
| 4943 | if (next != null) { |
| 4944 | // ask watcher if this is allowed |
| 4945 | boolean moveOK = true; |
| 4946 | try { |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 4947 | moveOK = mService.mController.activityResuming(next.packageName); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 4948 | } catch (RemoteException e) { |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 4949 | mService.mController = null; |
Kenny Root | add5821 | 2013-05-07 09:47:34 -0700 | [diff] [blame] | 4950 | Watchdog.getInstance().setActivityController(null); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 4951 | } |
| 4952 | if (!moveOK) { |
| 4953 | return false; |
| 4954 | } |
| 4955 | } |
| 4956 | } |
| 4957 | |
Wale Ogunwale | ee006da | 2015-03-30 14:49:25 -0700 | [diff] [blame] | 4958 | 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] | 4959 | |
Wale Ogunwale | 66e1685 | 2017-10-19 13:35:52 -0700 | [diff] [blame] | 4960 | mTaskHistory.remove(tr); |
| 4961 | mTaskHistory.add(0, tr); |
| 4962 | updateTaskMovement(tr, false); |
Wale Ogunwale | 4270924 | 2015-08-11 13:54:42 -0700 | [diff] [blame] | 4963 | |
Wale Ogunwale | 3a256e6 | 2018-12-06 14:41:18 -0800 | [diff] [blame] | 4964 | getDisplay().mDisplayContent.prepareAppTransition(TRANSIT_TASK_TO_BACK, false); |
Evan Rosky | 9c44817 | 2017-11-02 14:19:27 -0700 | [diff] [blame] | 4965 | moveToBack("moveTaskToBackLocked", tr); |
Winson Chung | 261c0f3 | 2017-03-07 16:54:31 -0800 | [diff] [blame] | 4966 | |
Wale Ogunwale | 44f036f | 2017-09-29 05:09:09 -0700 | [diff] [blame] | 4967 | if (inPinnedWindowingMode()) { |
Wale Ogunwale | a0f5b5e | 2017-10-11 09:37:23 -0700 | [diff] [blame] | 4968 | mStackSupervisor.removeStack(this); |
Winson Chung | 261c0f3 | 2017-03-07 16:54:31 -0800 | [diff] [blame] | 4969 | return true; |
| 4970 | } |
| 4971 | |
Wale Ogunwale | d32da47 | 2018-11-16 07:19:28 -0800 | [diff] [blame] | 4972 | mRootActivityContainer.resumeFocusedStacksTopActivities(); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 4973 | return true; |
| 4974 | } |
Dianne Hackborn | 15491c6 | 2012-09-19 10:59:14 -0700 | [diff] [blame] | 4975 | |
Andrii Kulian | 21713ac | 2016-10-12 22:05:05 -0700 | [diff] [blame] | 4976 | static void logStartActivity(int tag, ActivityRecord r, TaskRecord task) { |
Santos Cordon | 73ff7d8 | 2013-03-06 17:24:11 -0800 | [diff] [blame] | 4977 | final Uri data = r.intent.getData(); |
| 4978 | final String strData = data != null ? data.toSafeString() : null; |
| 4979 | |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 4980 | EventLog.writeEvent(tag, |
Wale Ogunwale | 8b19de9 | 2018-11-29 19:58:26 -0800 | [diff] [blame] | 4981 | r.mUserId, System.identityHashCode(r), task.taskId, |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 4982 | r.shortComponentName, r.intent.getAction(), |
Santos Cordon | 73ff7d8 | 2013-03-06 17:24:11 -0800 | [diff] [blame] | 4983 | r.intent.getType(), strData, r.intent.getFlags()); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 4984 | } |
| 4985 | |
| 4986 | /** |
Wale Ogunwale | db0fa12 | 2016-05-16 15:12:03 -0700 | [diff] [blame] | 4987 | * Ensures all visible activities at or below the input activity have the right configuration. |
| 4988 | */ |
| 4989 | void ensureVisibleActivitiesConfigurationLocked(ActivityRecord start, boolean preserveWindow) { |
| 4990 | if (start == null || !start.visible) { |
| 4991 | return; |
| 4992 | } |
| 4993 | |
Wale Ogunwale | 8b19de9 | 2018-11-29 19:58:26 -0800 | [diff] [blame] | 4994 | final TaskRecord startTask = start.getTaskRecord(); |
Wale Ogunwale | db0fa12 | 2016-05-16 15:12:03 -0700 | [diff] [blame] | 4995 | boolean behindFullscreen = false; |
| 4996 | boolean updatedConfig = false; |
| 4997 | |
| 4998 | for (int taskIndex = mTaskHistory.indexOf(startTask); taskIndex >= 0; --taskIndex) { |
| 4999 | final TaskRecord task = mTaskHistory.get(taskIndex); |
| 5000 | final ArrayList<ActivityRecord> activities = task.mActivities; |
Wale Ogunwale | 8b19de9 | 2018-11-29 19:58:26 -0800 | [diff] [blame] | 5001 | int activityIndex = (start.getTaskRecord() == task) |
| 5002 | ? activities.indexOf(start) : activities.size() - 1; |
Wale Ogunwale | db0fa12 | 2016-05-16 15:12:03 -0700 | [diff] [blame] | 5003 | for (; activityIndex >= 0; --activityIndex) { |
| 5004 | final ActivityRecord r = activities.get(activityIndex); |
Wale Ogunwale | b6d75f3 | 2018-02-22 20:44:56 -0800 | [diff] [blame] | 5005 | updatedConfig |= r.ensureActivityConfiguration(0 /* globalChanges */, |
Andrii Kulian | 21713ac | 2016-10-12 22:05:05 -0700 | [diff] [blame] | 5006 | preserveWindow); |
Wale Ogunwale | db0fa12 | 2016-05-16 15:12:03 -0700 | [diff] [blame] | 5007 | if (r.fullscreen) { |
| 5008 | behindFullscreen = true; |
| 5009 | break; |
| 5010 | } |
| 5011 | } |
| 5012 | if (behindFullscreen) { |
| 5013 | break; |
| 5014 | } |
| 5015 | } |
| 5016 | if (updatedConfig) { |
Wale Ogunwale | 089586f | 2016-06-20 14:16:22 -0700 | [diff] [blame] | 5017 | // 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] | 5018 | // any activity. |
Wale Ogunwale | d32da47 | 2018-11-16 07:19:28 -0800 | [diff] [blame] | 5019 | mRootActivityContainer.resumeFocusedStacksTopActivities(); |
Wale Ogunwale | db0fa12 | 2016-05-16 15:12:03 -0700 | [diff] [blame] | 5020 | } |
| 5021 | } |
| 5022 | |
Wale Ogunwale | 1666e31 | 2016-12-16 11:27:18 -0800 | [diff] [blame] | 5023 | // TODO: Figure-out a way to consolidate with resize() method below. |
Yunfan Chen | 279f558 | 2018-12-12 15:24:50 -0800 | [diff] [blame] | 5024 | void requestResize(Rect bounds) { |
Wale Ogunwale | 5fa8a8c | 2018-05-08 13:43:21 -0700 | [diff] [blame] | 5025 | mService.resizeStack(mStackId, bounds, |
Wale Ogunwale | 65ebd95 | 2018-04-25 15:41:44 -0700 | [diff] [blame] | 5026 | true /* allowResizeInDockedMode */, false /* preserveWindows */, |
| 5027 | false /* animate */, -1 /* animationDuration */); |
Wale Ogunwale | 1666e31 | 2016-12-16 11:27:18 -0800 | [diff] [blame] | 5028 | } |
Andrii Kulian | 1e32e02 | 2016-09-16 15:29:34 -0700 | [diff] [blame] | 5029 | |
Wale Ogunwale | 1666e31 | 2016-12-16 11:27:18 -0800 | [diff] [blame] | 5030 | // TODO: Can only be called from special methods in ActivityStackSupervisor. |
| 5031 | // Need to consolidate those calls points into this resize method so anyone can call directly. |
| 5032 | void resize(Rect bounds, Rect tempTaskBounds, Rect tempTaskInsetBounds) { |
Evan Rosky | 1ac8446 | 2018-11-13 11:25:30 -0800 | [diff] [blame] | 5033 | if (!updateBoundsAllowed(bounds)) { |
Wale Ogunwale | 1666e31 | 2016-12-16 11:27:18 -0800 | [diff] [blame] | 5034 | return; |
| 5035 | } |
| 5036 | |
| 5037 | // Update override configurations of all tasks in the stack. |
| 5038 | final Rect taskBounds = tempTaskBounds != null ? tempTaskBounds : bounds; |
Andrii Kulian | 1e32e02 | 2016-09-16 15:29:34 -0700 | [diff] [blame] | 5039 | |
Wale Ogunwale | 1f5e53d | 2018-11-05 05:12:46 -0800 | [diff] [blame] | 5040 | for (int i = mTaskHistory.size() - 1; i >= 0; i--) { |
| 5041 | final TaskRecord task = mTaskHistory.get(i); |
| 5042 | if (task.isResizeable()) { |
Garfield Tan | 020607d | 2018-12-17 17:01:58 -0800 | [diff] [blame] | 5043 | task.updateOverrideConfiguration(taskBounds, tempTaskInsetBounds); |
Andrii Kulian | 1e32e02 | 2016-09-16 15:29:34 -0700 | [diff] [blame] | 5044 | } |
Andrii Kulian | 1e32e02 | 2016-09-16 15:29:34 -0700 | [diff] [blame] | 5045 | } |
Wale Ogunwale | 1f5e53d | 2018-11-05 05:12:46 -0800 | [diff] [blame] | 5046 | |
Wale Ogunwale | 1f5e53d | 2018-11-05 05:12:46 -0800 | [diff] [blame] | 5047 | setBounds(bounds); |
Andrii Kulian | 1e32e02 | 2016-09-16 15:29:34 -0700 | [diff] [blame] | 5048 | } |
| 5049 | |
Winson Chung | 15036ca | 2018-05-31 15:51:47 -0700 | [diff] [blame] | 5050 | void onPipAnimationEndResize() { |
Yunfan Chen | 279f558 | 2018-12-12 15:24:50 -0800 | [diff] [blame] | 5051 | if (mTaskStack == null) return; |
| 5052 | mTaskStack.onPipAnimationEndResize(); |
Winson Chung | 15036ca | 2018-05-31 15:51:47 -0700 | [diff] [blame] | 5053 | } |
| 5054 | |
Andrii Kulian | 1e32e02 | 2016-09-16 15:29:34 -0700 | [diff] [blame] | 5055 | |
| 5056 | /** |
Evan Rosky | 1ac8446 | 2018-11-13 11:25:30 -0800 | [diff] [blame] | 5057 | * Until we can break this "set task bounds to same as stack bounds" behavior, this |
| 5058 | * basically resizes both stack and task bounds to the same bounds. |
Andrii Kulian | 1e32e02 | 2016-09-16 15:29:34 -0700 | [diff] [blame] | 5059 | */ |
Evan Rosky | 1ac8446 | 2018-11-13 11:25:30 -0800 | [diff] [blame] | 5060 | void setTaskBounds(Rect bounds) { |
| 5061 | if (!updateBoundsAllowed(bounds)) { |
Andrii Kulian | 1e32e02 | 2016-09-16 15:29:34 -0700 | [diff] [blame] | 5062 | return; |
| 5063 | } |
| 5064 | |
Evan Rosky | 1ac8446 | 2018-11-13 11:25:30 -0800 | [diff] [blame] | 5065 | for (int i = mTaskHistory.size() - 1; i >= 0; i--) { |
| 5066 | final TaskRecord task = mTaskHistory.get(i); |
| 5067 | if (task.isResizeable()) { |
| 5068 | task.setBounds(bounds); |
| 5069 | } else { |
| 5070 | task.setBounds(null); |
Andrii Kulian | 1e32e02 | 2016-09-16 15:29:34 -0700 | [diff] [blame] | 5071 | } |
Evan Rosky | 1ac8446 | 2018-11-13 11:25:30 -0800 | [diff] [blame] | 5072 | } |
| 5073 | } |
| 5074 | |
| 5075 | /** Helper to setDisplayedBounds on all child tasks */ |
| 5076 | void setTaskDisplayedBounds(Rect bounds) { |
| 5077 | if (!updateDisplayedBoundsAllowed(bounds)) { |
| 5078 | return; |
Andrii Kulian | 1e32e02 | 2016-09-16 15:29:34 -0700 | [diff] [blame] | 5079 | } |
| 5080 | |
Evan Rosky | 1ac8446 | 2018-11-13 11:25:30 -0800 | [diff] [blame] | 5081 | for (int i = mTaskHistory.size() - 1; i >= 0; i--) { |
| 5082 | final TaskRecord task = mTaskHistory.get(i); |
| 5083 | if (bounds == null || bounds.isEmpty()) { |
| 5084 | task.setDisplayedBounds(null); |
| 5085 | } else if (task.isResizeable()) { |
| 5086 | task.setDisplayedBounds(bounds); |
Andrii Kulian | 1e32e02 | 2016-09-16 15:29:34 -0700 | [diff] [blame] | 5087 | } |
Andrii Kulian | 1e32e02 | 2016-09-16 15:29:34 -0700 | [diff] [blame] | 5088 | } |
| 5089 | } |
| 5090 | |
Craig Mautner | cae015f | 2013-02-08 14:31:27 -0800 | [diff] [blame] | 5091 | boolean willActivityBeVisibleLocked(IBinder token) { |
Craig Mautner | d44711d | 2013-02-23 11:24:36 -0800 | [diff] [blame] | 5092 | for (int taskNdx = mTaskHistory.size() - 1; taskNdx >= 0; --taskNdx) { |
| 5093 | final ArrayList<ActivityRecord> activities = mTaskHistory.get(taskNdx).mActivities; |
| 5094 | for (int activityNdx = activities.size() - 1; activityNdx >= 0; --activityNdx) { |
| 5095 | final ActivityRecord r = activities.get(activityNdx); |
| 5096 | if (r.appToken == token) { |
Craig Mautner | 34b73df | 2014-01-12 21:11:08 -0800 | [diff] [blame] | 5097 | return true; |
Craig Mautner | d44711d | 2013-02-23 11:24:36 -0800 | [diff] [blame] | 5098 | } |
| 5099 | if (r.fullscreen && !r.finishing) { |
| 5100 | return false; |
| 5101 | } |
Craig Mautner | cae015f | 2013-02-08 14:31:27 -0800 | [diff] [blame] | 5102 | } |
| 5103 | } |
Wale Ogunwale | 7d70117 | 2015-03-11 15:36:30 -0700 | [diff] [blame] | 5104 | final ActivityRecord r = ActivityRecord.forTokenLocked(token); |
Craig Mautner | 34b73df | 2014-01-12 21:11:08 -0800 | [diff] [blame] | 5105 | if (r == null) { |
| 5106 | return false; |
| 5107 | } |
| 5108 | if (r.finishing) Slog.e(TAG, "willActivityBeVisibleLocked: Returning false," |
| 5109 | + " would have returned true for r=" + r); |
| 5110 | return !r.finishing; |
Craig Mautner | cae015f | 2013-02-08 14:31:27 -0800 | [diff] [blame] | 5111 | } |
| 5112 | |
| 5113 | void closeSystemDialogsLocked() { |
Craig Mautner | d44711d | 2013-02-23 11:24:36 -0800 | [diff] [blame] | 5114 | for (int taskNdx = mTaskHistory.size() - 1; taskNdx >= 0; --taskNdx) { |
| 5115 | final ArrayList<ActivityRecord> activities = mTaskHistory.get(taskNdx).mActivities; |
| 5116 | for (int activityNdx = activities.size() - 1; activityNdx >= 0; --activityNdx) { |
| 5117 | final ActivityRecord r = activities.get(activityNdx); |
| 5118 | if ((r.info.flags&ActivityInfo.FLAG_FINISH_ON_CLOSE_SYSTEM_DIALOGS) != 0) { |
Craig Mautner | d232895 | 2013-03-05 12:46:26 -0800 | [diff] [blame] | 5119 | finishActivityLocked(r, Activity.RESULT_CANCELED, null, "close-sys", true); |
Craig Mautner | d44711d | 2013-02-23 11:24:36 -0800 | [diff] [blame] | 5120 | } |
Craig Mautner | cae015f | 2013-02-08 14:31:27 -0800 | [diff] [blame] | 5121 | } |
| 5122 | } |
| 5123 | } |
| 5124 | |
Wale Ogunwale | 540e123 | 2015-05-01 15:35:39 -0700 | [diff] [blame] | 5125 | boolean finishDisabledPackageActivitiesLocked(String packageName, Set<String> filterByClasses, |
| 5126 | boolean doit, boolean evenPersistent, int userId) { |
Craig Mautner | cae015f | 2013-02-08 14:31:27 -0800 | [diff] [blame] | 5127 | boolean didSomething = false; |
| 5128 | TaskRecord lastTask = null; |
Craig Mautner | 9d8a30d | 2014-07-07 17:26:20 +0000 | [diff] [blame] | 5129 | ComponentName homeActivity = null; |
Craig Mautner | 56f52db | 2013-02-25 10:03:01 -0800 | [diff] [blame] | 5130 | for (int taskNdx = mTaskHistory.size() - 1; taskNdx >= 0; --taskNdx) { |
| 5131 | final ArrayList<ActivityRecord> activities = mTaskHistory.get(taskNdx).mActivities; |
Bryce Lee | fbd263b4 | 2018-03-07 10:33:55 -0800 | [diff] [blame] | 5132 | mTmpActivities.clear(); |
| 5133 | mTmpActivities.addAll(activities); |
| 5134 | |
| 5135 | while (!mTmpActivities.isEmpty()) { |
| 5136 | ActivityRecord r = mTmpActivities.remove(0); |
Wale Ogunwale | 540e123 | 2015-05-01 15:35:39 -0700 | [diff] [blame] | 5137 | final boolean sameComponent = |
| 5138 | (r.packageName.equals(packageName) && (filterByClasses == null |
Wale Ogunwale | 8b19de9 | 2018-11-29 19:58:26 -0800 | [diff] [blame] | 5139 | || filterByClasses.contains(r.mActivityComponent.getClassName()))) |
| 5140 | || (packageName == null && r.mUserId == userId); |
| 5141 | if ((userId == UserHandle.USER_ALL || r.mUserId == userId) |
| 5142 | && (sameComponent || r.getTaskRecord() == lastTask) |
Wale Ogunwale | 9e4f3e0 | 2018-05-17 09:35:39 -0700 | [diff] [blame] | 5143 | && (r.app == null || evenPersistent || !r.app.isPersistent())) { |
Craig Mautner | 56f52db | 2013-02-25 10:03:01 -0800 | [diff] [blame] | 5144 | if (!doit) { |
| 5145 | if (r.finishing) { |
| 5146 | // If this activity is just finishing, then it is not |
| 5147 | // interesting as far as something to stop. |
| 5148 | continue; |
| 5149 | } |
| 5150 | return true; |
Craig Mautner | cae015f | 2013-02-08 14:31:27 -0800 | [diff] [blame] | 5151 | } |
Wale Ogunwale | 6fbde9f | 2017-08-24 07:24:12 -0700 | [diff] [blame] | 5152 | if (r.isActivityTypeHome()) { |
Wale Ogunwale | 8b19de9 | 2018-11-29 19:58:26 -0800 | [diff] [blame] | 5153 | if (homeActivity != null && homeActivity.equals(r.mActivityComponent)) { |
Craig Mautner | 9d8a30d | 2014-07-07 17:26:20 +0000 | [diff] [blame] | 5154 | Slog.i(TAG, "Skip force-stop again " + r); |
| 5155 | continue; |
| 5156 | } else { |
Wale Ogunwale | 8b19de9 | 2018-11-29 19:58:26 -0800 | [diff] [blame] | 5157 | homeActivity = r.mActivityComponent; |
Craig Mautner | 9d8a30d | 2014-07-07 17:26:20 +0000 | [diff] [blame] | 5158 | } |
| 5159 | } |
Craig Mautner | 56f52db | 2013-02-25 10:03:01 -0800 | [diff] [blame] | 5160 | didSomething = true; |
| 5161 | Slog.i(TAG, " Force finishing activity " + r); |
Wale Ogunwale | 8b19de9 | 2018-11-29 19:58:26 -0800 | [diff] [blame] | 5162 | lastTask = r.getTaskRecord(); |
Bryce Lee | fbd263b4 | 2018-03-07 10:33:55 -0800 | [diff] [blame] | 5163 | finishActivityLocked(r, Activity.RESULT_CANCELED, null, "force-stop", |
| 5164 | true); |
Craig Mautner | cae015f | 2013-02-08 14:31:27 -0800 | [diff] [blame] | 5165 | } |
| 5166 | } |
| 5167 | } |
| 5168 | return didSomething; |
| 5169 | } |
| 5170 | |
Winson Chung | 61c9e5a | 2017-10-11 10:39:32 -0700 | [diff] [blame] | 5171 | /** |
| 5172 | * @return The set of running tasks through {@param tasksOut} that are available to the caller. |
| 5173 | * If {@param ignoreActivityType} or {@param ignoreWindowingMode} are not undefined, |
| 5174 | * then skip running tasks that match those types. |
| 5175 | */ |
| 5176 | void getRunningTasks(List<TaskRecord> tasksOut, @ActivityType int ignoreActivityType, |
| 5177 | @WindowingMode int ignoreWindowingMode, int callingUid, boolean allowed) { |
Wale Ogunwale | d32da47 | 2018-11-16 07:19:28 -0800 | [diff] [blame] | 5178 | boolean focusedStack = mRootActivityContainer.getTopDisplayFocusedStack() == this; |
riddle_hsu | ddc7415 | 2015-04-07 11:30:09 +0800 | [diff] [blame] | 5179 | boolean topTask = true; |
Craig Mautner | c0fd805 | 2013-09-19 11:20:17 -0700 | [diff] [blame] | 5180 | for (int taskNdx = mTaskHistory.size() - 1; taskNdx >= 0; --taskNdx) { |
Craig Mautner | aab647e | 2013-02-28 16:31:36 -0800 | [diff] [blame] | 5181 | final TaskRecord task = mTaskHistory.get(taskNdx); |
riddle_hsu | ddc7415 | 2015-04-07 11:30:09 +0800 | [diff] [blame] | 5182 | if (task.getTopActivity() == null) { |
Winson Chung | 61c9e5a | 2017-10-11 10:39:32 -0700 | [diff] [blame] | 5183 | // Skip if there are no activities in the task |
riddle_hsu | ddc7415 | 2015-04-07 11:30:09 +0800 | [diff] [blame] | 5184 | continue; |
| 5185 | } |
Wale Ogunwale | 6fbde9f | 2017-08-24 07:24:12 -0700 | [diff] [blame] | 5186 | if (!allowed && !task.isActivityTypeHome() && task.effectiveUid != callingUid) { |
Winson Chung | 61c9e5a | 2017-10-11 10:39:32 -0700 | [diff] [blame] | 5187 | // Skip if the caller can't fetch this task |
Dianne Hackborn | 0923328 | 2014-04-30 11:33:59 -0700 | [diff] [blame] | 5188 | continue; |
| 5189 | } |
Winson Chung | 61c9e5a | 2017-10-11 10:39:32 -0700 | [diff] [blame] | 5190 | if (ignoreActivityType != ACTIVITY_TYPE_UNDEFINED |
| 5191 | && task.getActivityType() == ignoreActivityType) { |
| 5192 | // Skip ignored activity type |
| 5193 | continue; |
Craig Mautner | aab647e | 2013-02-28 16:31:36 -0800 | [diff] [blame] | 5194 | } |
Winson Chung | 61c9e5a | 2017-10-11 10:39:32 -0700 | [diff] [blame] | 5195 | if (ignoreWindowingMode != WINDOWING_MODE_UNDEFINED |
| 5196 | && task.getWindowingMode() == ignoreWindowingMode) { |
| 5197 | // Skip ignored windowing mode |
| 5198 | continue; |
| 5199 | } |
riddle_hsu | ddc7415 | 2015-04-07 11:30:09 +0800 | [diff] [blame] | 5200 | if (focusedStack && topTask) { |
Winson Chung | 61c9e5a | 2017-10-11 10:39:32 -0700 | [diff] [blame] | 5201 | // For the focused stack top task, update the last stack active time so that it can |
| 5202 | // be used to determine the order of the tasks (it may not be set for newly created |
| 5203 | // tasks) |
| 5204 | task.lastActiveTime = SystemClock.elapsedRealtime(); |
riddle_hsu | ddc7415 | 2015-04-07 11:30:09 +0800 | [diff] [blame] | 5205 | topTask = false; |
| 5206 | } |
Winson Chung | 61c9e5a | 2017-10-11 10:39:32 -0700 | [diff] [blame] | 5207 | tasksOut.add(task); |
Craig Mautner | cae015f | 2013-02-08 14:31:27 -0800 | [diff] [blame] | 5208 | } |
Craig Mautner | cae015f | 2013-02-08 14:31:27 -0800 | [diff] [blame] | 5209 | } |
| 5210 | |
Andrii Kulian | 21713ac | 2016-10-12 22:05:05 -0700 | [diff] [blame] | 5211 | void unhandledBackLocked() { |
Craig Mautner | aab647e | 2013-02-28 16:31:36 -0800 | [diff] [blame] | 5212 | final int top = mTaskHistory.size() - 1; |
Wale Ogunwale | ee006da | 2015-03-30 14:49:25 -0700 | [diff] [blame] | 5213 | 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] | 5214 | if (top >= 0) { |
| 5215 | final ArrayList<ActivityRecord> activities = mTaskHistory.get(top).mActivities; |
| 5216 | int activityTop = activities.size() - 1; |
Dianne Hackborn | 354736e | 2016-08-22 17:00:05 -0700 | [diff] [blame] | 5217 | if (activityTop >= 0) { |
Craig Mautner | aab647e | 2013-02-28 16:31:36 -0800 | [diff] [blame] | 5218 | finishActivityLocked(activities.get(activityTop), Activity.RESULT_CANCELED, null, |
| 5219 | "unhandled-back", true); |
| 5220 | } |
Craig Mautner | cae015f | 2013-02-08 14:31:27 -0800 | [diff] [blame] | 5221 | } |
| 5222 | } |
| 5223 | |
Craig Mautner | 6b74cb5 | 2013-09-27 17:02:21 -0700 | [diff] [blame] | 5224 | /** |
| 5225 | * Reset local parameters because an app's activity died. |
| 5226 | * @param app The app of the activity that died. |
Craig Mautner | 1909125 | 2013-10-05 00:03:53 -0700 | [diff] [blame] | 5227 | * @return result from removeHistoryRecordsForAppLocked. |
Craig Mautner | 6b74cb5 | 2013-09-27 17:02:21 -0700 | [diff] [blame] | 5228 | */ |
Wale Ogunwale | 9e4f3e0 | 2018-05-17 09:35:39 -0700 | [diff] [blame] | 5229 | boolean handleAppDiedLocked(WindowProcessController app) { |
Craig Mautner | e79d4268 | 2013-04-01 19:01:53 -0700 | [diff] [blame] | 5230 | if (mPausingActivity != null && mPausingActivity.app == app) { |
Wale Ogunwale | ee006da | 2015-03-30 14:49:25 -0700 | [diff] [blame] | 5231 | if (DEBUG_PAUSE || DEBUG_CLEANUP) Slog.v(TAG_PAUSE, |
Craig Mautner | e79d4268 | 2013-04-01 19:01:53 -0700 | [diff] [blame] | 5232 | "App died while pausing: " + mPausingActivity); |
| 5233 | mPausingActivity = null; |
| 5234 | } |
| 5235 | if (mLastPausedActivity != null && mLastPausedActivity.app == app) { |
| 5236 | mLastPausedActivity = null; |
Craig Mautner | 0f92274 | 2013-08-06 08:44:42 -0700 | [diff] [blame] | 5237 | mLastNoHistoryActivity = null; |
Craig Mautner | e79d4268 | 2013-04-01 19:01:53 -0700 | [diff] [blame] | 5238 | } |
| 5239 | |
Craig Mautner | 1909125 | 2013-10-05 00:03:53 -0700 | [diff] [blame] | 5240 | return removeHistoryRecordsForAppLocked(app); |
Craig Mautner | e79d4268 | 2013-04-01 19:01:53 -0700 | [diff] [blame] | 5241 | } |
| 5242 | |
Wale Ogunwale | d32da47 | 2018-11-16 07:19:28 -0800 | [diff] [blame] | 5243 | void handleAppCrash(WindowProcessController app) { |
Craig Mautner | d44711d | 2013-02-23 11:24:36 -0800 | [diff] [blame] | 5244 | for (int taskNdx = mTaskHistory.size() - 1; taskNdx >= 0; --taskNdx) { |
| 5245 | final ArrayList<ActivityRecord> activities = mTaskHistory.get(taskNdx).mActivities; |
| 5246 | for (int activityNdx = activities.size() - 1; activityNdx >= 0; --activityNdx) { |
| 5247 | final ActivityRecord r = activities.get(activityNdx); |
| 5248 | if (r.app == app) { |
| 5249 | Slog.w(TAG, " Force finishing activity " |
| 5250 | + r.intent.getComponent().flattenToShortString()); |
Craig Mautner | 8e5b133 | 2014-07-24 13:32:37 -0700 | [diff] [blame] | 5251 | // Force the destroy to skip right to removal. |
| 5252 | r.app = null; |
Wale Ogunwale | 3a256e6 | 2018-12-06 14:41:18 -0800 | [diff] [blame] | 5253 | getDisplay().mDisplayContent.prepareAppTransition( |
lumark | 588a3e8 | 2018-07-20 18:53:54 +0800 | [diff] [blame] | 5254 | TRANSIT_CRASHING_ACTIVITY_CLOSE, false /* alwaysKeepCurrent */); |
Bryce Lee | f52974c | 2018-02-14 15:12:01 -0800 | [diff] [blame] | 5255 | finishCurrentActivityLocked(r, FINISH_IMMEDIATELY, false, |
| 5256 | "handleAppCrashedLocked"); |
Craig Mautner | d44711d | 2013-02-23 11:24:36 -0800 | [diff] [blame] | 5257 | } |
Craig Mautner | cae015f | 2013-02-08 14:31:27 -0800 | [diff] [blame] | 5258 | } |
| 5259 | } |
| 5260 | } |
| 5261 | |
Garfield Tan | 347bd60 | 2018-12-21 15:11:12 -0800 | [diff] [blame] | 5262 | boolean dump(FileDescriptor fd, PrintWriter pw, boolean dumpAll, boolean dumpClient, |
| 5263 | String dumpPackage, boolean needSep) { |
| 5264 | pw.println(" Stack #" + mStackId |
| 5265 | + ": type=" + activityTypeToString(getActivityType()) |
| 5266 | + " mode=" + windowingModeToString(getWindowingMode())); |
| 5267 | pw.println(" isSleeping=" + shouldSleepActivities()); |
| 5268 | pw.println(" mBounds=" + getRequestedOverrideBounds()); |
| 5269 | |
| 5270 | boolean printed = dumpActivitiesLocked(fd, pw, dumpAll, dumpClient, dumpPackage, |
| 5271 | needSep); |
| 5272 | |
| 5273 | printed |= dumpHistoryList(fd, pw, mLRUActivities, " ", "Run", false, |
| 5274 | !dumpAll, false, dumpPackage, true, |
| 5275 | " Running activities (most recent first):", null); |
| 5276 | |
| 5277 | needSep = printed; |
| 5278 | boolean pr = printThisActivity(pw, mPausingActivity, dumpPackage, needSep, |
| 5279 | " mPausingActivity: "); |
| 5280 | if (pr) { |
| 5281 | printed = true; |
| 5282 | needSep = false; |
| 5283 | } |
| 5284 | pr = printThisActivity(pw, getResumedActivity(), dumpPackage, needSep, |
| 5285 | " mResumedActivity: "); |
| 5286 | if (pr) { |
| 5287 | printed = true; |
| 5288 | needSep = false; |
| 5289 | } |
| 5290 | if (dumpAll) { |
| 5291 | pr = printThisActivity(pw, mLastPausedActivity, dumpPackage, needSep, |
| 5292 | " mLastPausedActivity: "); |
| 5293 | if (pr) { |
| 5294 | printed = true; |
| 5295 | needSep = true; |
| 5296 | } |
| 5297 | printed |= printThisActivity(pw, mLastNoHistoryActivity, dumpPackage, |
| 5298 | needSep, " mLastNoHistoryActivity: "); |
| 5299 | } |
| 5300 | return printed; |
| 5301 | } |
| 5302 | |
Dianne Hackborn | 390517b | 2013-05-30 15:03:32 -0700 | [diff] [blame] | 5303 | boolean dumpActivitiesLocked(FileDescriptor fd, PrintWriter pw, boolean dumpAll, |
Wale Ogunwale | 34a5b57 | 2017-08-31 08:29:41 -0700 | [diff] [blame] | 5304 | boolean dumpClient, String dumpPackage, boolean needSep) { |
| 5305 | |
| 5306 | if (mTaskHistory.isEmpty()) { |
| 5307 | return false; |
| 5308 | } |
| 5309 | final String prefix = " "; |
Craig Mautner | aab647e | 2013-02-28 16:31:36 -0800 | [diff] [blame] | 5310 | for (int taskNdx = mTaskHistory.size() - 1; taskNdx >= 0; --taskNdx) { |
| 5311 | final TaskRecord task = mTaskHistory.get(taskNdx); |
Wale Ogunwale | 34a5b57 | 2017-08-31 08:29:41 -0700 | [diff] [blame] | 5312 | if (needSep) { |
| 5313 | pw.println(""); |
Dianne Hackborn | 7ad34e5 | 2013-06-05 18:41:45 -0700 | [diff] [blame] | 5314 | } |
Wale Ogunwale | 34a5b57 | 2017-08-31 08:29:41 -0700 | [diff] [blame] | 5315 | pw.println(prefix + "Task id #" + task.taskId); |
Evan Rosky | dfe3da7 | 2018-10-26 17:21:06 -0700 | [diff] [blame] | 5316 | pw.println(prefix + "mBounds=" + task.getRequestedOverrideBounds()); |
Wale Ogunwale | 34a5b57 | 2017-08-31 08:29:41 -0700 | [diff] [blame] | 5317 | pw.println(prefix + "mMinWidth=" + task.mMinWidth); |
| 5318 | pw.println(prefix + "mMinHeight=" + task.mMinHeight); |
| 5319 | pw.println(prefix + "mLastNonFullscreenBounds=" + task.mLastNonFullscreenBounds); |
| 5320 | pw.println(prefix + "* " + task); |
| 5321 | task.dump(pw, prefix + " "); |
Garfield Tan | 347bd60 | 2018-12-21 15:11:12 -0800 | [diff] [blame] | 5322 | dumpHistoryList(fd, pw, mTaskHistory.get(taskNdx).mActivities, |
Wale Ogunwale | 34a5b57 | 2017-08-31 08:29:41 -0700 | [diff] [blame] | 5323 | prefix, "Hist", true, !dumpAll, dumpClient, dumpPackage, false, null, task); |
Craig Mautner | aab647e | 2013-02-28 16:31:36 -0800 | [diff] [blame] | 5324 | } |
Wale Ogunwale | 34a5b57 | 2017-08-31 08:29:41 -0700 | [diff] [blame] | 5325 | return true; |
Craig Mautner | cae015f | 2013-02-08 14:31:27 -0800 | [diff] [blame] | 5326 | } |
| 5327 | |
| 5328 | ArrayList<ActivityRecord> getDumpActivitiesLocked(String name) { |
Winson Chung | 6998bc4 | 2017-02-28 17:07:05 -0800 | [diff] [blame] | 5329 | ArrayList<ActivityRecord> activities = new ArrayList<>(); |
Craig Mautner | cae015f | 2013-02-08 14:31:27 -0800 | [diff] [blame] | 5330 | |
| 5331 | if ("all".equals(name)) { |
Craig Mautner | aab647e | 2013-02-28 16:31:36 -0800 | [diff] [blame] | 5332 | for (int taskNdx = mTaskHistory.size() - 1; taskNdx >= 0; --taskNdx) { |
| 5333 | activities.addAll(mTaskHistory.get(taskNdx).mActivities); |
Craig Mautner | cae015f | 2013-02-08 14:31:27 -0800 | [diff] [blame] | 5334 | } |
| 5335 | } else if ("top".equals(name)) { |
Craig Mautner | aab647e | 2013-02-28 16:31:36 -0800 | [diff] [blame] | 5336 | final int top = mTaskHistory.size() - 1; |
| 5337 | if (top >= 0) { |
| 5338 | final ArrayList<ActivityRecord> list = mTaskHistory.get(top).mActivities; |
| 5339 | int listTop = list.size() - 1; |
| 5340 | if (listTop >= 0) { |
| 5341 | activities.add(list.get(listTop)); |
| 5342 | } |
Craig Mautner | cae015f | 2013-02-08 14:31:27 -0800 | [diff] [blame] | 5343 | } |
| 5344 | } else { |
| 5345 | ItemMatcher matcher = new ItemMatcher(); |
| 5346 | matcher.build(name); |
| 5347 | |
Craig Mautner | aab647e | 2013-02-28 16:31:36 -0800 | [diff] [blame] | 5348 | for (int taskNdx = mTaskHistory.size() - 1; taskNdx >= 0; --taskNdx) { |
| 5349 | for (ActivityRecord r1 : mTaskHistory.get(taskNdx).mActivities) { |
| 5350 | if (matcher.match(r1, r1.intent.getComponent())) { |
| 5351 | activities.add(r1); |
| 5352 | } |
Craig Mautner | cae015f | 2013-02-08 14:31:27 -0800 | [diff] [blame] | 5353 | } |
| 5354 | } |
| 5355 | } |
| 5356 | |
| 5357 | return activities; |
| 5358 | } |
| 5359 | |
| 5360 | ActivityRecord restartPackage(String packageName) { |
Filip Gruszczynski | 3e85ba2 | 2015-10-05 22:48:30 -0700 | [diff] [blame] | 5361 | ActivityRecord starting = topRunningActivityLocked(); |
Craig Mautner | cae015f | 2013-02-08 14:31:27 -0800 | [diff] [blame] | 5362 | |
| 5363 | // All activities that came from the package must be |
| 5364 | // restarted as if there was a config change. |
Craig Mautner | aab647e | 2013-02-28 16:31:36 -0800 | [diff] [blame] | 5365 | for (int taskNdx = mTaskHistory.size() - 1; taskNdx >= 0; --taskNdx) { |
| 5366 | final ArrayList<ActivityRecord> activities = mTaskHistory.get(taskNdx).mActivities; |
| 5367 | for (int activityNdx = activities.size() - 1; activityNdx >= 0; --activityNdx) { |
| 5368 | final ActivityRecord a = activities.get(activityNdx); |
| 5369 | if (a.info.packageName.equals(packageName)) { |
| 5370 | a.forceNewConfig = true; |
| 5371 | if (starting != null && a == starting && a.visible) { |
| 5372 | a.startFreezingScreenLocked(starting.app, |
Filip Gruszczynski | 3c2db1d1 | 2016-01-06 17:39:14 -0800 | [diff] [blame] | 5373 | CONFIG_SCREEN_LAYOUT); |
Craig Mautner | aab647e | 2013-02-28 16:31:36 -0800 | [diff] [blame] | 5374 | } |
Craig Mautner | cae015f | 2013-02-08 14:31:27 -0800 | [diff] [blame] | 5375 | } |
| 5376 | } |
| 5377 | } |
| 5378 | |
| 5379 | return starting; |
| 5380 | } |
Craig Mautner | 5d9c7be | 2013-02-15 14:02:56 -0800 | [diff] [blame] | 5381 | |
Wale Ogunwale | 000957c | 2015-04-03 08:19:12 -0700 | [diff] [blame] | 5382 | /** |
| 5383 | * Removes the input task from this stack. |
Garfield Tan | 891146c | 2018-10-09 12:14:00 -0700 | [diff] [blame] | 5384 | * |
Wale Ogunwale | 000957c | 2015-04-03 08:19:12 -0700 | [diff] [blame] | 5385 | * @param task to remove. |
| 5386 | * @param reason for removal. |
Wale Ogunwale | 06579d6 | 2016-04-30 15:29:06 -0700 | [diff] [blame] | 5387 | * @param mode task removal mode. Either {@link #REMOVE_TASK_MODE_DESTROYING}, |
| 5388 | * {@link #REMOVE_TASK_MODE_MOVING}, {@link #REMOVE_TASK_MODE_MOVING_TO_TOP}. |
Wale Ogunwale | 000957c | 2015-04-03 08:19:12 -0700 | [diff] [blame] | 5389 | */ |
Wale Ogunwale | 06579d6 | 2016-04-30 15:29:06 -0700 | [diff] [blame] | 5390 | void removeTask(TaskRecord task, String reason, int mode) { |
Bryce Lee | 2b8e037 | 2018-04-05 17:01:37 -0700 | [diff] [blame] | 5391 | final boolean removed = mTaskHistory.remove(task); |
| 5392 | |
| 5393 | if (removed) { |
| 5394 | EventLog.writeEvent(EventLogTags.AM_REMOVE_TASK, task.taskId, getStackId()); |
| 5395 | } |
| 5396 | |
Winson Chung | abb433b | 2017-03-24 09:35:42 -0700 | [diff] [blame] | 5397 | removeActivitiesFromLRUListLocked(task); |
Craig Mautner | 21d24a2 | 2014-04-23 11:45:37 -0700 | [diff] [blame] | 5398 | updateTaskMovement(task, true); |
Craig Mautner | 41db4a7 | 2014-05-07 17:20:56 -0700 | [diff] [blame] | 5399 | |
Garfield Tan | 347bd60 | 2018-12-21 15:11:12 -0800 | [diff] [blame] | 5400 | if (mode == REMOVE_TASK_MODE_DESTROYING) { |
| 5401 | task.cleanUpResourcesForDestroy(); |
Dianne Hackborn | 91097de | 2014-04-04 18:02:06 -0700 | [diff] [blame] | 5402 | } |
Craig Mautner | 04a0ea6 | 2014-01-13 12:51:26 -0800 | [diff] [blame] | 5403 | |
| 5404 | if (mTaskHistory.isEmpty()) { |
Wale Ogunwale | ee006da | 2015-03-30 14:49:25 -0700 | [diff] [blame] | 5405 | if (DEBUG_STACK) Slog.i(TAG_STACK, "removeTask: removing stack=" + this); |
Wale Ogunwale | 06579d6 | 2016-04-30 15:29:06 -0700 | [diff] [blame] | 5406 | // We only need to adjust focused stack if this stack is in focus and we are not in the |
| 5407 | // 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] | 5408 | if (mode != REMOVE_TASK_MODE_MOVING_TO_TOP |
Wale Ogunwale | d32da47 | 2018-11-16 07:19:28 -0800 | [diff] [blame] | 5409 | && mRootActivityContainer.isTopDisplayFocusedStack(this)) { |
Wale Ogunwale | d697cea | 2015-02-20 17:19:49 -0800 | [diff] [blame] | 5410 | String myReason = reason + " leftTaskHistoryEmpty"; |
Andrii Kulian | ab132ee | 2018-07-24 22:10:21 +0800 | [diff] [blame] | 5411 | if (!inMultiWindowMode() || adjustFocusToNextFocusableStack(myReason) == null) { |
Louis Chang | bd48dca | 2018-08-29 17:44:34 +0800 | [diff] [blame] | 5412 | getDisplay().moveHomeStackToFront(myReason); |
Wale Ogunwale | d697cea | 2015-02-20 17:19:49 -0800 | [diff] [blame] | 5413 | } |
Craig Mautner | 04a0ea6 | 2014-01-13 12:51:26 -0800 | [diff] [blame] | 5414 | } |
Wale Ogunwale | 9dcf946 | 2017-09-19 15:13:01 -0700 | [diff] [blame] | 5415 | if (isAttached()) { |
| 5416 | getDisplay().positionChildAtBottom(this); |
Craig Mautner | 593a4e6 | 2014-01-15 17:55:51 -0800 | [diff] [blame] | 5417 | } |
Louis Chang | 7d0037c | 2018-08-13 12:42:06 +0800 | [diff] [blame] | 5418 | if (!isActivityTypeHome() || getDisplay().isRemoved()) { |
Andrii Kulian | 94e82d9b0 | 2017-07-13 15:33:06 -0700 | [diff] [blame] | 5419 | remove(); |
Wale Ogunwale | 49853bf | 2015-02-23 09:24:42 -0800 | [diff] [blame] | 5420 | } |
Craig Mautner | 04a0ea6 | 2014-01-13 12:51:26 -0800 | [diff] [blame] | 5421 | } |
Wale Ogunwale | 04f4d6b | 2015-03-11 09:23:25 -0700 | [diff] [blame] | 5422 | |
Andrii Kulian | 02b7a83 | 2016-10-06 23:11:56 -0700 | [diff] [blame] | 5423 | task.setStack(null); |
Winson Chung | c81c0ce | 2017-03-17 12:27:30 -0700 | [diff] [blame] | 5424 | |
| 5425 | // 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] | 5426 | if (inPinnedWindowingMode()) { |
Wale Ogunwale | 5fa8a8c | 2018-05-08 13:43:21 -0700 | [diff] [blame] | 5427 | mService.getTaskChangeNotificationController().notifyActivityUnpinned(); |
Winson Chung | c81c0ce | 2017-03-17 12:27:30 -0700 | [diff] [blame] | 5428 | } |
Craig Mautner | 0247fc8 | 2013-02-28 14:32:06 -0800 | [diff] [blame] | 5429 | } |
| 5430 | |
Dianne Hackborn | 91097de | 2014-04-04 18:02:06 -0700 | [diff] [blame] | 5431 | TaskRecord createTaskRecord(int taskId, ActivityInfo info, Intent intent, |
| 5432 | IVoiceInteractionSession voiceSession, IVoiceInteractor voiceInteractor, |
Wale Ogunwale | 6fbde9f | 2017-08-24 07:24:12 -0700 | [diff] [blame] | 5433 | boolean toTop) { |
Bryce Lee | b802ea1 | 2017-11-15 21:25:03 -0800 | [diff] [blame] | 5434 | return createTaskRecord(taskId, info, intent, voiceSession, voiceInteractor, toTop, |
| 5435 | null /*activity*/, null /*source*/, null /*options*/); |
| 5436 | } |
| 5437 | |
| 5438 | TaskRecord createTaskRecord(int taskId, ActivityInfo info, Intent intent, |
| 5439 | IVoiceInteractionSession voiceSession, IVoiceInteractor voiceInteractor, |
| 5440 | boolean toTop, ActivityRecord activity, ActivityRecord source, |
| 5441 | ActivityOptions options) { |
Garfield Tan | 9b1efea | 2017-12-05 16:43:46 -0800 | [diff] [blame] | 5442 | final TaskRecord task = TaskRecord.create( |
Wale Ogunwale | 5fa8a8c | 2018-05-08 13:43:21 -0700 | [diff] [blame] | 5443 | mService, taskId, info, intent, voiceSession, voiceInteractor); |
Chong Zhang | 0fa656b | 2015-08-31 15:17:21 -0700 | [diff] [blame] | 5444 | // add the task to stack first, mTaskPositioner might need the stack association |
Wale Ogunwale | 5f98609 | 2015-12-04 15:35:38 -0800 | [diff] [blame] | 5445 | addTask(task, toTop, "createTaskRecord"); |
Lucas Dupin | 47a65c7 | 2018-02-15 14:16:18 -0800 | [diff] [blame] | 5446 | final int displayId = mDisplayId != INVALID_DISPLAY ? mDisplayId : DEFAULT_DISPLAY; |
Bryce Lee | 2a3cc46 | 2017-10-27 10:57:35 -0700 | [diff] [blame] | 5447 | final boolean isLockscreenShown = mService.mStackSupervisor.getKeyguardController() |
Lucas Dupin | 47a65c7 | 2018-02-15 14:16:18 -0800 | [diff] [blame] | 5448 | .isKeyguardOrAodShowing(displayId); |
Bryce Lee | ec55eb0 | 2017-12-05 20:51:27 -0800 | [diff] [blame] | 5449 | if (!mStackSupervisor.getLaunchParamsController() |
Bryce Lee | b802ea1 | 2017-11-15 21:25:03 -0800 | [diff] [blame] | 5450 | .layoutTask(task, info.windowLayout, activity, source, options) |
Bryce Lee | f3c6a47 | 2017-11-14 14:53:06 -0800 | [diff] [blame] | 5451 | && !matchParentBounds() && task.isResizeable() && !isLockscreenShown) { |
Evan Rosky | dfe3da7 | 2018-10-26 17:21:06 -0700 | [diff] [blame] | 5452 | task.updateOverrideConfiguration(getRequestedOverrideBounds()); |
Filip Gruszczynski | e5390e7 | 2015-08-18 16:39:00 -0700 | [diff] [blame] | 5453 | } |
Yunfan Chen | 0e7aff9 | 2018-12-05 16:35:32 -0800 | [diff] [blame] | 5454 | task.createTask(toTop, (info.flags & FLAG_SHOW_FOR_ALL_USERS) != 0); |
Craig Mautner | 5d9c7be | 2013-02-15 14:02:56 -0800 | [diff] [blame] | 5455 | return task; |
| 5456 | } |
Craig Mautner | c00204b | 2013-03-05 15:02:14 -0800 | [diff] [blame] | 5457 | |
| 5458 | ArrayList<TaskRecord> getAllTasks() { |
Wale Ogunwale | 9d3de4c | 2015-02-01 16:49:44 -0800 | [diff] [blame] | 5459 | return new ArrayList<>(mTaskHistory); |
Craig Mautner | c00204b | 2013-03-05 15:02:14 -0800 | [diff] [blame] | 5460 | } |
| 5461 | |
Wale Ogunwale | 5f98609 | 2015-12-04 15:35:38 -0800 | [diff] [blame] | 5462 | void addTask(final TaskRecord task, final boolean toTop, String reason) { |
Winson Chung | 5af42fc | 2017-03-24 17:11:33 -0700 | [diff] [blame] | 5463 | addTask(task, toTop ? MAX_VALUE : 0, true /* schedulePictureInPictureModeChange */, reason); |
Wale Ogunwale | c5cc301 | 2017-01-13 13:26:16 -0800 | [diff] [blame] | 5464 | if (toTop) { |
| 5465 | // TODO: figure-out a way to remove this call. |
Riddle Hsu | 86cb7de | 2018-08-13 23:29:58 +0800 | [diff] [blame] | 5466 | positionChildWindowContainerAtTop(task); |
Wale Ogunwale | c5cc301 | 2017-01-13 13:26:16 -0800 | [diff] [blame] | 5467 | } |
Wale Ogunwale | e1fe7fa2 | 2016-12-15 18:27:00 -0800 | [diff] [blame] | 5468 | } |
| 5469 | |
Wale Ogunwale | c5cc301 | 2017-01-13 13:26:16 -0800 | [diff] [blame] | 5470 | // TODO: This shouldn't allow automatic reparenting. Remove the call to preAddTask and deal |
| 5471 | // with the fall-out... |
Winson Chung | 5af42fc | 2017-03-24 17:11:33 -0700 | [diff] [blame] | 5472 | void addTask(final TaskRecord task, int position, boolean schedulePictureInPictureModeChange, |
| 5473 | String reason) { |
Wale Ogunwale | c5cc301 | 2017-01-13 13:26:16 -0800 | [diff] [blame] | 5474 | // TODO: Is this remove really needed? Need to look into the call path for the other addTask |
| 5475 | mTaskHistory.remove(task); |
Wale Ogunwale | 9e737db | 2018-12-17 15:42:37 -0800 | [diff] [blame] | 5476 | if (isSingleTaskInstance() && !mTaskHistory.isEmpty()) { |
| 5477 | throw new IllegalStateException("Can only have one child on stack=" + this); |
| 5478 | } |
| 5479 | |
Wale Ogunwale | c5cc301 | 2017-01-13 13:26:16 -0800 | [diff] [blame] | 5480 | position = getAdjustedPositionForTask(task, position, null /* starting */); |
| 5481 | final boolean toTop = position >= mTaskHistory.size(); |
Wale Ogunwale | 06579d6 | 2016-04-30 15:29:06 -0700 | [diff] [blame] | 5482 | final ActivityStack prevStack = preAddTask(task, reason, toTop); |
Wale Ogunwale | 5f98609 | 2015-12-04 15:35:38 -0800 | [diff] [blame] | 5483 | |
Andrii Kulian | fb1bf69 | 2017-01-17 11:17:34 -0800 | [diff] [blame] | 5484 | mTaskHistory.add(position, task); |
Andrii Kulian | 02b7a83 | 2016-10-06 23:11:56 -0700 | [diff] [blame] | 5485 | task.setStack(this); |
Wale Ogunwale | c5cc301 | 2017-01-13 13:26:16 -0800 | [diff] [blame] | 5486 | |
Wale Ogunwale | c5cc301 | 2017-01-13 13:26:16 -0800 | [diff] [blame] | 5487 | updateTaskMovement(task, toTop); |
| 5488 | |
Winson Chung | 5af42fc | 2017-03-24 17:11:33 -0700 | [diff] [blame] | 5489 | postAddTask(task, prevStack, schedulePictureInPictureModeChange); |
Craig Mautner | c00204b | 2013-03-05 15:02:14 -0800 | [diff] [blame] | 5490 | } |
| 5491 | |
Wale Ogunwale | c5cc301 | 2017-01-13 13:26:16 -0800 | [diff] [blame] | 5492 | void positionChildAt(TaskRecord task, int index) { |
| 5493 | |
| 5494 | if (task.getStack() != this) { |
| 5495 | throw new IllegalArgumentException("AS.positionChildAt: task=" + task |
| 5496 | + " is not a child of stack=" + this + " current parent=" + task.getStack()); |
Wale Ogunwale | e1fe7fa2 | 2016-12-15 18:27:00 -0800 | [diff] [blame] | 5497 | } |
| 5498 | |
| 5499 | task.updateOverrideConfigurationForStack(this); |
| 5500 | |
Jorim Jaggi | 023da53 | 2016-04-20 22:42:32 -0700 | [diff] [blame] | 5501 | final ActivityRecord topRunningActivity = task.topRunningActivityLocked(); |
Andrii Kulian | 02b7a83 | 2016-10-06 23:11:56 -0700 | [diff] [blame] | 5502 | final boolean wasResumed = topRunningActivity == task.getStack().mResumedActivity; |
Wale Ogunwale | e1fe7fa2 | 2016-12-15 18:27:00 -0800 | [diff] [blame] | 5503 | insertTaskAtPosition(task, index); |
Andrii Kulian | fb1bf69 | 2017-01-17 11:17:34 -0800 | [diff] [blame] | 5504 | task.setStack(this); |
Winson Chung | 5af42fc | 2017-03-24 17:11:33 -0700 | [diff] [blame] | 5505 | postAddTask(task, null /* prevStack */, true /* schedulePictureInPictureModeChange */); |
Wale Ogunwale | c5cc301 | 2017-01-13 13:26:16 -0800 | [diff] [blame] | 5506 | |
Jorim Jaggi | 023da53 | 2016-04-20 22:42:32 -0700 | [diff] [blame] | 5507 | if (wasResumed) { |
| 5508 | if (mResumedActivity != null) { |
| 5509 | Log.wtf(TAG, "mResumedActivity was already set when moving mResumedActivity from" |
| 5510 | + " other stack to this stack mResumedActivity=" + mResumedActivity |
| 5511 | + " other mResumedActivity=" + topRunningActivity); |
| 5512 | } |
Bryce Lee | c4ab62a | 2018-03-05 14:19:26 -0800 | [diff] [blame] | 5513 | topRunningActivity.setState(RESUMED, "positionChildAt"); |
Jorim Jaggi | 023da53 | 2016-04-20 22:42:32 -0700 | [diff] [blame] | 5514 | } |
Wale Ogunwale | e1fe7fa2 | 2016-12-15 18:27:00 -0800 | [diff] [blame] | 5515 | |
| 5516 | // The task might have already been running and its visibility needs to be synchronized with |
| 5517 | // the visibility of the stack / windows. |
| 5518 | ensureActivitiesVisibleLocked(null, 0, !PRESERVE_WINDOWS); |
Wale Ogunwale | d32da47 | 2018-11-16 07:19:28 -0800 | [diff] [blame] | 5519 | mRootActivityContainer.resumeFocusedStacksTopActivities(); |
Wale Ogunwale | 5f98609 | 2015-12-04 15:35:38 -0800 | [diff] [blame] | 5520 | } |
| 5521 | |
Wale Ogunwale | 06579d6 | 2016-04-30 15:29:06 -0700 | [diff] [blame] | 5522 | private ActivityStack preAddTask(TaskRecord task, String reason, boolean toTop) { |
Andrii Kulian | 02b7a83 | 2016-10-06 23:11:56 -0700 | [diff] [blame] | 5523 | final ActivityStack prevStack = task.getStack(); |
Wale Ogunwale | 5f98609 | 2015-12-04 15:35:38 -0800 | [diff] [blame] | 5524 | if (prevStack != null && prevStack != this) { |
Wale Ogunwale | 06579d6 | 2016-04-30 15:29:06 -0700 | [diff] [blame] | 5525 | prevStack.removeTask(task, reason, |
| 5526 | toTop ? REMOVE_TASK_MODE_MOVING_TO_TOP : REMOVE_TASK_MODE_MOVING); |
Wale Ogunwale | 5f98609 | 2015-12-04 15:35:38 -0800 | [diff] [blame] | 5527 | } |
| 5528 | return prevStack; |
| 5529 | } |
| 5530 | |
Winson Chung | 5af42fc | 2017-03-24 17:11:33 -0700 | [diff] [blame] | 5531 | /** |
| 5532 | * @param schedulePictureInPictureModeChange specifies whether or not to schedule the PiP mode |
| 5533 | * change. Callers may set this to false if they are explicitly scheduling PiP mode |
| 5534 | * changes themselves, like during the PiP animation |
| 5535 | */ |
| 5536 | private void postAddTask(TaskRecord task, ActivityStack prevStack, |
| 5537 | boolean schedulePictureInPictureModeChange) { |
| 5538 | if (schedulePictureInPictureModeChange && prevStack != null) { |
| 5539 | mStackSupervisor.scheduleUpdatePictureInPictureModeIfNeeded(task, prevStack); |
Wale Ogunwale | 5f98609 | 2015-12-04 15:35:38 -0800 | [diff] [blame] | 5540 | } else if (task.voiceSession != null) { |
Wale Ogunwale | ddc1cb2 | 2015-07-25 19:23:04 -0700 | [diff] [blame] | 5541 | try { |
| 5542 | task.voiceSession.taskStarted(task.intent, task.taskId); |
| 5543 | } catch (RemoteException e) { |
| 5544 | } |
| 5545 | } |
| 5546 | } |
| 5547 | |
Kazuki Takise | f85197b | 2018-06-18 18:18:36 +0900 | [diff] [blame] | 5548 | public void setAlwaysOnTop(boolean alwaysOnTop) { |
| 5549 | if (isAlwaysOnTop() == alwaysOnTop) { |
| 5550 | return; |
| 5551 | } |
| 5552 | super.setAlwaysOnTop(alwaysOnTop); |
| 5553 | final ActivityDisplay display = getDisplay(); |
| 5554 | // positionChildAtTop() must be called even when always on top gets turned off because we |
| 5555 | // need to make sure that the stack is moved from among always on top windows to below other |
| 5556 | // always on top windows. Since the position the stack should be inserted into is calculated |
| 5557 | // properly in {@link ActivityDisplay#getTopInsertPosition()} in both cases, we can just |
| 5558 | // request that the stack is put at top here. |
Riddle Hsu | 57831b5 | 2018-07-27 00:31:48 +0800 | [diff] [blame] | 5559 | display.positionChildAtTop(this, false /* includingParents */); |
Kazuki Takise | f85197b | 2018-06-18 18:18:36 +0900 | [diff] [blame] | 5560 | } |
| 5561 | |
Riddle Hsu | 1656713 | 2018-08-16 21:37:47 +0800 | [diff] [blame] | 5562 | /** NOTE: Should only be called from {@link TaskRecord#reparent}. */ |
Winson Chung | c2baac0 | 2017-01-11 13:34:47 -0800 | [diff] [blame] | 5563 | void moveToFrontAndResumeStateIfNeeded(ActivityRecord r, boolean moveToFront, boolean setResume, |
| 5564 | boolean setPause, String reason) { |
Wale Ogunwale | d046a01 | 2015-12-24 13:05:59 -0800 | [diff] [blame] | 5565 | if (!moveToFront) { |
| 5566 | return; |
Wale Ogunwale | 079a004 | 2015-10-24 11:44:07 -0700 | [diff] [blame] | 5567 | } |
Wale Ogunwale | d046a01 | 2015-12-24 13:05:59 -0800 | [diff] [blame] | 5568 | |
Riddle Hsu | 1656713 | 2018-08-16 21:37:47 +0800 | [diff] [blame] | 5569 | final ActivityState origState = r.getState(); |
Wale Ogunwale | d046a01 | 2015-12-24 13:05:59 -0800 | [diff] [blame] | 5570 | // If the activity owns the last resumed activity, transfer that together, |
| 5571 | // so that we don't resume the same activity again in the new stack. |
| 5572 | // Apps may depend on onResume()/onPause() being called in pairs. |
| 5573 | if (setResume) { |
Bryce Lee | c4ab62a | 2018-03-05 14:19:26 -0800 | [diff] [blame] | 5574 | r.setState(RESUMED, "moveToFrontAndResumeStateIfNeeded"); |
Winson Chung | abb433b | 2017-03-24 09:35:42 -0700 | [diff] [blame] | 5575 | updateLRUListLocked(r); |
Wale Ogunwale | d046a01 | 2015-12-24 13:05:59 -0800 | [diff] [blame] | 5576 | } |
Winson Chung | c2baac0 | 2017-01-11 13:34:47 -0800 | [diff] [blame] | 5577 | // If the activity was previously pausing, then ensure we transfer that as well |
| 5578 | if (setPause) { |
| 5579 | mPausingActivity = r; |
Winson Chung | 4dabf23 | 2017-01-25 13:25:22 -0800 | [diff] [blame] | 5580 | schedulePauseTimeout(r); |
Winson Chung | c2baac0 | 2017-01-11 13:34:47 -0800 | [diff] [blame] | 5581 | } |
Riddle Hsu | 1656713 | 2018-08-16 21:37:47 +0800 | [diff] [blame] | 5582 | // 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] | 5583 | moveToFront(reason); |
Riddle Hsu | 1656713 | 2018-08-16 21:37:47 +0800 | [diff] [blame] | 5584 | // If the original state is resumed, there is no state change to update focused app. |
| 5585 | // 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] | 5586 | if (origState == RESUMED && r == mRootActivityContainer.getTopResumedActivity()) { |
Riddle Hsu | 1656713 | 2018-08-16 21:37:47 +0800 | [diff] [blame] | 5587 | // TODO(b/111361570): Support multiple focused apps in WM |
| 5588 | mService.setResumedActivityUncheckLocked(r, reason); |
| 5589 | } |
Wale Ogunwale | 079a004 | 2015-10-24 11:44:07 -0700 | [diff] [blame] | 5590 | } |
| 5591 | |
Yunfan Chen | 279f558 | 2018-12-12 15:24:50 -0800 | [diff] [blame] | 5592 | |
| 5593 | Rect getDefaultPictureInPictureBounds(float aspectRatio) { |
| 5594 | if (getTaskStack() == null) return null; |
| 5595 | return getTaskStack().getPictureInPictureBounds(aspectRatio, null /* currentStackBounds */); |
| 5596 | } |
| 5597 | |
| 5598 | void animateResizePinnedStack(Rect sourceHintBounds, Rect toBounds, int animationDuration, |
| 5599 | boolean fromFullscreen) { |
| 5600 | if (!inPinnedWindowingMode()) return; |
| 5601 | if (skipResizeAnimation(toBounds == null /* toFullscreen */)) { |
| 5602 | mService.moveTasksToFullscreenStack(mStackId, true /* onTop */); |
| 5603 | } else { |
| 5604 | if (getTaskStack() == null) return; |
| 5605 | getTaskStack().animateResizePinnedStack(toBounds, sourceHintBounds, |
| 5606 | animationDuration, fromFullscreen); |
| 5607 | } |
| 5608 | } |
| 5609 | |
wilsonshih | 5c4cf52 | 2019-01-25 09:03:47 +0800 | [diff] [blame] | 5610 | /** |
| 5611 | * Get current bounds of this stack, return empty when it is unavailable. |
| 5612 | * @see TaskStack#getAnimationOrCurrentBounds(Rect) |
| 5613 | */ |
| 5614 | void getAnimationOrCurrentBounds(Rect outBounds) { |
| 5615 | final TaskStack stack = getTaskStack(); |
| 5616 | if (stack == null) { |
| 5617 | outBounds.setEmpty(); |
| 5618 | return; |
| 5619 | } |
| 5620 | stack.getAnimationOrCurrentBounds(outBounds); |
| 5621 | } |
| 5622 | |
Yunfan Chen | 279f558 | 2018-12-12 15:24:50 -0800 | [diff] [blame] | 5623 | private boolean skipResizeAnimation(boolean toFullscreen) { |
| 5624 | if (!toFullscreen) { |
| 5625 | return false; |
| 5626 | } |
| 5627 | final Configuration parentConfig = getParent().getConfiguration(); |
| 5628 | final ActivityRecord top = topRunningNonOverlayTaskActivity(); |
| 5629 | return top != null && !top.isConfigurationCompatible(parentConfig); |
| 5630 | } |
| 5631 | |
| 5632 | void setPictureInPictureAspectRatio(float aspectRatio) { |
| 5633 | if (getTaskStack() == null) return; |
| 5634 | getTaskStack().setPictureInPictureAspectRatio(aspectRatio); |
| 5635 | } |
| 5636 | |
| 5637 | void setPictureInPictureActions(List<RemoteAction> actions) { |
| 5638 | if (getTaskStack() == null) return; |
| 5639 | getTaskStack().setPictureInPictureActions(actions); |
| 5640 | } |
| 5641 | |
| 5642 | boolean isAnimatingBoundsToFullscreen() { |
| 5643 | if (getTaskStack() == null) return false; |
| 5644 | return getTaskStack().isAnimatingBoundsToFullscreen(); |
| 5645 | } |
| 5646 | |
| 5647 | public void updatePictureInPictureModeForPinnedStackAnimation(Rect targetStackBounds, |
| 5648 | boolean forceUpdate) { |
| 5649 | // It is guaranteed that the activities requiring the update will be in the pinned stack at |
| 5650 | // this point (either reparented before the animation into PiP, or before reparenting after |
| 5651 | // the animation out of PiP) |
| 5652 | synchronized (mService.mGlobalLock) { |
| 5653 | if (!isAttached()) { |
| 5654 | return; |
| 5655 | } |
| 5656 | ArrayList<TaskRecord> tasks = getAllTasks(); |
| 5657 | for (int i = 0; i < tasks.size(); i++) { |
| 5658 | mStackSupervisor.updatePictureInPictureMode(tasks.get(i), targetStackBounds, |
| 5659 | forceUpdate); |
| 5660 | } |
| 5661 | } |
| 5662 | } |
| 5663 | |
Craig Mautner | c00204b | 2013-03-05 15:02:14 -0800 | [diff] [blame] | 5664 | public int getStackId() { |
| 5665 | return mStackId; |
| 5666 | } |
Craig Mautner | de4ef02 | 2013-04-07 19:01:33 -0700 | [diff] [blame] | 5667 | |
| 5668 | @Override |
| 5669 | public String toString() { |
Dianne Hackborn | 2a272d4 | 2013-10-16 13:34:33 -0700 | [diff] [blame] | 5670 | return "ActivityStack{" + Integer.toHexString(System.identityHashCode(this)) |
Wale Ogunwale | 44f036f | 2017-09-29 05:09:09 -0700 | [diff] [blame] | 5671 | + " stackId=" + mStackId + " type=" + activityTypeToString(getActivityType()) |
Wale Ogunwale | 7e1f5f5 | 2017-10-18 15:19:59 -0700 | [diff] [blame] | 5672 | + " mode=" + windowingModeToString(getWindowingMode()) |
Wale Ogunwale | 8e923af | 2018-03-23 08:48:11 -0700 | [diff] [blame] | 5673 | + " visible=" + shouldBeVisible(null /* starting */) |
| 5674 | + " translucent=" + isStackTranslucent(null /* starting */) |
| 5675 | + ", " |
Wale Ogunwale | 44f036f | 2017-09-29 05:09:09 -0700 | [diff] [blame] | 5676 | + mTaskHistory.size() + " tasks}"; |
Craig Mautner | de4ef02 | 2013-04-07 19:01:33 -0700 | [diff] [blame] | 5677 | } |
Wale Ogunwale | 60454db | 2015-01-23 16:05:07 -0800 | [diff] [blame] | 5678 | |
Wale Ogunwale | a0f5b5e | 2017-10-11 09:37:23 -0700 | [diff] [blame] | 5679 | void onLockTaskPackagesUpdated() { |
Craig Mautner | 15df08a | 2015-04-01 12:17:18 -0700 | [diff] [blame] | 5680 | for (int taskNdx = mTaskHistory.size() - 1; taskNdx >= 0; --taskNdx) { |
| 5681 | mTaskHistory.get(taskNdx).setLockTaskAuth(); |
| 5682 | } |
| 5683 | } |
skuhne@google.com | 1b974dc | 2016-12-09 13:41:29 -0800 | [diff] [blame] | 5684 | |
| 5685 | void executeAppTransition(ActivityOptions options) { |
Wale Ogunwale | 3a256e6 | 2018-12-06 14:41:18 -0800 | [diff] [blame] | 5686 | getDisplay().mDisplayContent.executeAppTransition(); |
skuhne@google.com | 1b974dc | 2016-12-09 13:41:29 -0800 | [diff] [blame] | 5687 | ActivityOptions.abort(options); |
| 5688 | } |
David Stevens | 9440dc8 | 2017-03-16 19:00:20 -0700 | [diff] [blame] | 5689 | |
| 5690 | boolean shouldSleepActivities() { |
Wale Ogunwale | 9dcf946 | 2017-09-19 15:13:01 -0700 | [diff] [blame] | 5691 | final ActivityDisplay display = getDisplay(); |
Bryce Lee | 271617a | 2018-03-15 10:39:12 -0700 | [diff] [blame] | 5692 | |
| 5693 | // Do not sleep activities in this stack if we're marked as focused and the keyguard |
| 5694 | // is in the process of going away. |
Tiger Huang | 1e5b10a | 2018-07-30 20:19:51 +0800 | [diff] [blame] | 5695 | if (isFocusedStackOnDisplay() |
Bryce Lee | 271617a | 2018-03-15 10:39:12 -0700 | [diff] [blame] | 5696 | && mStackSupervisor.getKeyguardController().isKeyguardGoingAway()) { |
| 5697 | return false; |
| 5698 | } |
| 5699 | |
Wale Ogunwale | f673393 | 2018-06-27 05:14:34 -0700 | [diff] [blame] | 5700 | return display != null ? display.isSleeping() : mService.isSleepingLocked(); |
David Stevens | 9440dc8 | 2017-03-16 19:00:20 -0700 | [diff] [blame] | 5701 | } |
| 5702 | |
| 5703 | boolean shouldSleepOrShutDownActivities() { |
Wale Ogunwale | f673393 | 2018-06-27 05:14:34 -0700 | [diff] [blame] | 5704 | return shouldSleepActivities() || mService.mShuttingDown; |
David Stevens | 9440dc8 | 2017-03-16 19:00:20 -0700 | [diff] [blame] | 5705 | } |
Steven Timotius | 4346f0a | 2017-09-12 11:07:21 -0700 | [diff] [blame] | 5706 | |
Nataniel Borges | 023ecb5 | 2019-01-16 14:15:43 -0800 | [diff] [blame] | 5707 | public void writeToProto(ProtoOutputStream proto, long fieldId, |
| 5708 | @WindowTraceLogLevel int logLevel) { |
Steven Timotius | 4346f0a | 2017-09-12 11:07:21 -0700 | [diff] [blame] | 5709 | final long token = proto.start(fieldId); |
Nataniel Borges | 023ecb5 | 2019-01-16 14:15:43 -0800 | [diff] [blame] | 5710 | super.writeToProto(proto, CONFIGURATION_CONTAINER, logLevel); |
Steven Timotius | 4346f0a | 2017-09-12 11:07:21 -0700 | [diff] [blame] | 5711 | proto.write(ID, mStackId); |
| 5712 | for (int taskNdx = mTaskHistory.size() - 1; taskNdx >= 0; --taskNdx) { |
| 5713 | final TaskRecord task = mTaskHistory.get(taskNdx); |
Nataniel Borges | 023ecb5 | 2019-01-16 14:15:43 -0800 | [diff] [blame] | 5714 | task.writeToProto(proto, TASKS, logLevel); |
Steven Timotius | 4346f0a | 2017-09-12 11:07:21 -0700 | [diff] [blame] | 5715 | } |
| 5716 | if (mResumedActivity != null) { |
| 5717 | mResumedActivity.writeIdentifierToProto(proto, RESUMED_ACTIVITY); |
| 5718 | } |
| 5719 | proto.write(DISPLAY_ID, mDisplayId); |
Bryce Lee | f3c6a47 | 2017-11-14 14:53:06 -0800 | [diff] [blame] | 5720 | if (!matchParentBounds()) { |
Evan Rosky | dfe3da7 | 2018-10-26 17:21:06 -0700 | [diff] [blame] | 5721 | final Rect bounds = getRequestedOverrideBounds(); |
Bryce Lee | f3c6a47 | 2017-11-14 14:53:06 -0800 | [diff] [blame] | 5722 | bounds.writeToProto(proto, BOUNDS); |
Steven Timotius | 4346f0a | 2017-09-12 11:07:21 -0700 | [diff] [blame] | 5723 | } |
Bryce Lee | f3c6a47 | 2017-11-14 14:53:06 -0800 | [diff] [blame] | 5724 | |
| 5725 | // TODO: Remove, no longer needed with windowingMode. |
| 5726 | proto.write(FULLSCREEN, matchParentBounds()); |
Steven Timotius | 4346f0a | 2017-09-12 11:07:21 -0700 | [diff] [blame] | 5727 | proto.end(token); |
| 5728 | } |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 5729 | } |