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; |
Issei Suzuki | cac2a50 | 2019-04-16 16:52:50 +0200 | [diff] [blame] | 43 | import static android.view.WindowManager.TRANSIT_SHOW_SINGLE_TASK_DISPLAY; |
Louis Chang | 7d0037c | 2018-08-13 12:42:06 +0800 | [diff] [blame] | 44 | import static android.view.WindowManager.TRANSIT_TASK_CLOSE; |
| 45 | import static android.view.WindowManager.TRANSIT_TASK_OPEN; |
| 46 | import static android.view.WindowManager.TRANSIT_TASK_OPEN_BEHIND; |
| 47 | import static android.view.WindowManager.TRANSIT_TASK_TO_BACK; |
| 48 | import static android.view.WindowManager.TRANSIT_TASK_TO_FRONT; |
Winson Chung | 1dbc811 | 2017-09-28 18:05:31 -0700 | [diff] [blame] | 49 | |
Evan Rosky | e747c3e | 2018-10-30 20:06:41 -0700 | [diff] [blame] | 50 | import static com.android.server.am.ActivityStackProto.BOUNDS; |
| 51 | import static com.android.server.am.ActivityStackProto.CONFIGURATION_CONTAINER; |
| 52 | import static com.android.server.am.ActivityStackProto.DISPLAY_ID; |
| 53 | import static com.android.server.am.ActivityStackProto.FULLSCREEN; |
| 54 | import static com.android.server.am.ActivityStackProto.ID; |
| 55 | import static com.android.server.am.ActivityStackProto.RESUMED_ACTIVITY; |
| 56 | import static com.android.server.am.ActivityStackProto.TASKS; |
Wale Ogunwale | 5950709 | 2018-10-29 09:00:30 -0700 | [diff] [blame] | 57 | import static com.android.server.wm.ActivityDisplay.POSITION_BOTTOM; |
| 58 | import static com.android.server.wm.ActivityDisplay.POSITION_TOP; |
| 59 | import static com.android.server.wm.ActivityStack.ActivityState.DESTROYED; |
| 60 | import static com.android.server.wm.ActivityStack.ActivityState.DESTROYING; |
| 61 | import static com.android.server.wm.ActivityStack.ActivityState.FINISHING; |
| 62 | import static com.android.server.wm.ActivityStack.ActivityState.PAUSED; |
| 63 | import static com.android.server.wm.ActivityStack.ActivityState.PAUSING; |
| 64 | import static com.android.server.wm.ActivityStack.ActivityState.RESUMED; |
| 65 | import static com.android.server.wm.ActivityStack.ActivityState.STOPPED; |
| 66 | import static com.android.server.wm.ActivityStack.ActivityState.STOPPING; |
Wale Ogunwale | 5950709 | 2018-10-29 09:00:30 -0700 | [diff] [blame] | 67 | import static com.android.server.wm.ActivityStackSupervisor.PAUSE_IMMEDIATELY; |
| 68 | import static com.android.server.wm.ActivityStackSupervisor.PRESERVE_WINDOWS; |
| 69 | import static com.android.server.wm.ActivityStackSupervisor.REMOVE_FROM_RECENTS; |
Garfield Tan | 347bd60 | 2018-12-21 15:11:12 -0800 | [diff] [blame] | 70 | import static com.android.server.wm.ActivityStackSupervisor.dumpHistoryList; |
| 71 | import static com.android.server.wm.ActivityStackSupervisor.printThisActivity; |
Wale Ogunwale | 5950709 | 2018-10-29 09:00:30 -0700 | [diff] [blame] | 72 | import static com.android.server.wm.ActivityTaskManagerDebugConfig.DEBUG_ADD_REMOVE; |
| 73 | import static com.android.server.wm.ActivityTaskManagerDebugConfig.DEBUG_ALL; |
| 74 | import static com.android.server.wm.ActivityTaskManagerDebugConfig.DEBUG_APP; |
| 75 | import static com.android.server.wm.ActivityTaskManagerDebugConfig.DEBUG_CLEANUP; |
| 76 | import static com.android.server.wm.ActivityTaskManagerDebugConfig.DEBUG_CONTAINERS; |
| 77 | import static com.android.server.wm.ActivityTaskManagerDebugConfig.DEBUG_PAUSE; |
| 78 | import static com.android.server.wm.ActivityTaskManagerDebugConfig.DEBUG_RELEASE; |
| 79 | import static com.android.server.wm.ActivityTaskManagerDebugConfig.DEBUG_RESULTS; |
| 80 | import static com.android.server.wm.ActivityTaskManagerDebugConfig.DEBUG_SAVED_STATE; |
| 81 | import static com.android.server.wm.ActivityTaskManagerDebugConfig.DEBUG_STACK; |
| 82 | import static com.android.server.wm.ActivityTaskManagerDebugConfig.DEBUG_STATES; |
| 83 | import static com.android.server.wm.ActivityTaskManagerDebugConfig.DEBUG_SWITCH; |
| 84 | import static com.android.server.wm.ActivityTaskManagerDebugConfig.DEBUG_TASKS; |
| 85 | import static com.android.server.wm.ActivityTaskManagerDebugConfig.DEBUG_TRANSITION; |
| 86 | import static com.android.server.wm.ActivityTaskManagerDebugConfig.DEBUG_USER_LEAVING; |
| 87 | import static com.android.server.wm.ActivityTaskManagerDebugConfig.DEBUG_VISIBILITY; |
| 88 | import static com.android.server.wm.ActivityTaskManagerDebugConfig.POSTFIX_ADD_REMOVE; |
| 89 | import static com.android.server.wm.ActivityTaskManagerDebugConfig.POSTFIX_APP; |
| 90 | import static com.android.server.wm.ActivityTaskManagerDebugConfig.POSTFIX_CLEANUP; |
| 91 | import static com.android.server.wm.ActivityTaskManagerDebugConfig.POSTFIX_CONTAINERS; |
| 92 | import static com.android.server.wm.ActivityTaskManagerDebugConfig.POSTFIX_PAUSE; |
| 93 | import static com.android.server.wm.ActivityTaskManagerDebugConfig.POSTFIX_RELEASE; |
| 94 | import static com.android.server.wm.ActivityTaskManagerDebugConfig.POSTFIX_RESULTS; |
| 95 | import static com.android.server.wm.ActivityTaskManagerDebugConfig.POSTFIX_SAVED_STATE; |
| 96 | import static com.android.server.wm.ActivityTaskManagerDebugConfig.POSTFIX_STACK; |
| 97 | import static com.android.server.wm.ActivityTaskManagerDebugConfig.POSTFIX_STATES; |
| 98 | import static com.android.server.wm.ActivityTaskManagerDebugConfig.POSTFIX_SWITCH; |
| 99 | import static com.android.server.wm.ActivityTaskManagerDebugConfig.POSTFIX_TASKS; |
| 100 | import static com.android.server.wm.ActivityTaskManagerDebugConfig.POSTFIX_TRANSITION; |
| 101 | import static com.android.server.wm.ActivityTaskManagerDebugConfig.POSTFIX_USER_LEAVING; |
| 102 | import static com.android.server.wm.ActivityTaskManagerDebugConfig.POSTFIX_VISIBILITY; |
| 103 | import static com.android.server.wm.ActivityTaskManagerDebugConfig.TAG_ATM; |
| 104 | import static com.android.server.wm.ActivityTaskManagerDebugConfig.TAG_WITH_CLASS_NAME; |
| 105 | import static com.android.server.wm.ActivityTaskManagerService.H.FIRST_ACTIVITY_STACK_MSG; |
| 106 | import static com.android.server.wm.ActivityTaskManagerService.RELAUNCH_REASON_FREE_RESIZE; |
| 107 | import static com.android.server.wm.ActivityTaskManagerService.RELAUNCH_REASON_WINDOWING_MODE_RESIZE; |
Wale Ogunwale | d32da47 | 2018-11-16 07:19:28 -0800 | [diff] [blame] | 108 | import static com.android.server.wm.RootActivityContainer.FindTaskResult; |
Louis Chang | f2835df | 2018-10-17 15:14:45 +0800 | [diff] [blame] | 109 | |
Wale Ogunwale | c5cc301 | 2017-01-13 13:26:16 -0800 | [diff] [blame] | 110 | import static java.lang.Integer.MAX_VALUE; |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 111 | |
Andrii Kulian | 0c869cc | 2019-02-06 19:50:32 -0800 | [diff] [blame] | 112 | import android.annotation.IntDef; |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 113 | import android.app.Activity; |
Dianne Hackborn | 0c5001d | 2011-04-12 18:16:08 -0700 | [diff] [blame] | 114 | import android.app.ActivityManager; |
Wale Ogunwale | 5378374 | 2018-09-16 10:21:51 -0700 | [diff] [blame] | 115 | import android.app.ActivityManagerInternal; |
Dianne Hackborn | 7a2195c | 2012-03-19 17:38:00 -0700 | [diff] [blame] | 116 | import android.app.ActivityOptions; |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 117 | import android.app.AppGlobals; |
Craig Mautner | 05d6272ba | 2013-02-11 09:39:27 -0800 | [diff] [blame] | 118 | import android.app.IActivityController; |
Yunfan Chen | 279f558 | 2018-12-12 15:24:50 -0800 | [diff] [blame] | 119 | import android.app.RemoteAction; |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 120 | import android.app.ResultInfo; |
Winson Chung | 61c9e5a | 2017-10-11 10:39:32 -0700 | [diff] [blame] | 121 | import android.app.WindowConfiguration.ActivityType; |
| 122 | import android.app.WindowConfiguration.WindowingMode; |
Andrii Kulian | 446e824 | 2017-10-26 15:17:29 -0700 | [diff] [blame] | 123 | import android.app.servertransaction.ActivityResultItem; |
Andrii Kulian | 9956d89 | 2018-02-14 13:48:56 -0800 | [diff] [blame] | 124 | import android.app.servertransaction.ClientTransaction; |
Andrii Kulian | 446e824 | 2017-10-26 15:17:29 -0700 | [diff] [blame] | 125 | import android.app.servertransaction.DestroyActivityItem; |
Louis Chang | 7d0037c | 2018-08-13 12:42:06 +0800 | [diff] [blame] | 126 | import android.app.servertransaction.NewIntentItem; |
Andrii Kulian | 446e824 | 2017-10-26 15:17:29 -0700 | [diff] [blame] | 127 | import android.app.servertransaction.PauseActivityItem; |
| 128 | import android.app.servertransaction.ResumeActivityItem; |
| 129 | import android.app.servertransaction.StopActivityItem; |
Louis Chang | 7d0037c | 2018-08-13 12:42:06 +0800 | [diff] [blame] | 130 | import android.app.servertransaction.WindowVisibilityItem; |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 131 | import android.content.ComponentName; |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 132 | import android.content.Intent; |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 133 | import android.content.pm.ActivityInfo; |
Todd Kennedy | 39bfee5 | 2016-02-24 10:28:21 -0800 | [diff] [blame] | 134 | import android.content.pm.ApplicationInfo; |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 135 | import android.content.res.Configuration; |
Jorim Jaggi | af80db4 | 2016-04-07 19:19:15 -0700 | [diff] [blame] | 136 | import android.graphics.Rect; |
Santos Cordon | 73ff7d8 | 2013-03-06 17:24:11 -0800 | [diff] [blame] | 137 | import android.net.Uri; |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 138 | import android.os.Binder; |
Craig Mautner | 329f412 | 2013-11-07 09:10:42 -0800 | [diff] [blame] | 139 | import android.os.Debug; |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 140 | import android.os.Handler; |
| 141 | import android.os.IBinder; |
Zoran Marceta | f958b32 | 2012-08-09 20:27:12 +0900 | [diff] [blame] | 142 | import android.os.Looper; |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 143 | import android.os.Message; |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 144 | import android.os.RemoteException; |
| 145 | import android.os.SystemClock; |
Dianne Hackborn | f02b60a | 2012-08-16 10:48:27 -0700 | [diff] [blame] | 146 | import android.os.UserHandle; |
Craig Mautner | 4c07d02 | 2014-06-11 17:12:59 -0700 | [diff] [blame] | 147 | import android.service.voice.IVoiceInteractionSession; |
Jorim Jaggi | af80db4 | 2016-04-07 19:19:15 -0700 | [diff] [blame] | 148 | import android.util.ArraySet; |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 149 | import android.util.EventLog; |
Andrii Kulian | fb1bf69 | 2017-01-17 11:17:34 -0800 | [diff] [blame] | 150 | import android.util.IntArray; |
Jorim Jaggi | 023da53 | 2016-04-20 22:42:32 -0700 | [diff] [blame] | 151 | import android.util.Log; |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 152 | import android.util.Slog; |
Steven Timotius | 4346f0a | 2017-09-12 11:07:21 -0700 | [diff] [blame] | 153 | import android.util.proto.ProtoOutputStream; |
Craig Mautner | 59c0097 | 2012-07-30 12:10:24 -0700 | [diff] [blame] | 154 | import android.view.Display; |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 155 | |
Andreas Gampe | a36dc62 | 2018-02-05 17:19:22 -0800 | [diff] [blame] | 156 | import com.android.internal.annotations.GuardedBy; |
Bryce Lee | 840c566 | 2017-04-13 10:02:51 -0700 | [diff] [blame] | 157 | import com.android.internal.annotations.VisibleForTesting; |
Jorim Jaggi | af80db4 | 2016-04-07 19:19:15 -0700 | [diff] [blame] | 158 | import com.android.internal.app.IVoiceInteractor; |
Wale Ogunwale | 5378374 | 2018-09-16 10:21:51 -0700 | [diff] [blame] | 159 | import com.android.internal.util.function.pooled.PooledLambda; |
Jorim Jaggi | af80db4 | 2016-04-07 19:19:15 -0700 | [diff] [blame] | 160 | import com.android.server.Watchdog; |
Wale Ogunwale | 5950709 | 2018-10-29 09:00:30 -0700 | [diff] [blame] | 161 | import com.android.server.am.ActivityManagerService; |
Jorim Jaggi | af80db4 | 2016-04-07 19:19:15 -0700 | [diff] [blame] | 162 | import com.android.server.am.ActivityManagerService.ItemMatcher; |
Wale Ogunwale | 5950709 | 2018-10-29 09:00:30 -0700 | [diff] [blame] | 163 | import com.android.server.am.AppTimeTracker; |
| 164 | import com.android.server.am.EventLogTags; |
| 165 | import com.android.server.am.PendingIntentRecord; |
Jorim Jaggi | af80db4 | 2016-04-07 19:19:15 -0700 | [diff] [blame] | 166 | |
Craig Mautner | cae015f | 2013-02-08 14:31:27 -0800 | [diff] [blame] | 167 | import java.io.FileDescriptor; |
Craig Mautner | cae015f | 2013-02-08 14:31:27 -0800 | [diff] [blame] | 168 | import java.io.PrintWriter; |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 169 | import java.lang.ref.WeakReference; |
| 170 | import java.util.ArrayList; |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 171 | import java.util.List; |
Kenny Root | e6585b3 | 2013-12-13 12:00:26 -0800 | [diff] [blame] | 172 | import java.util.Objects; |
Wale Ogunwale | 540e123 | 2015-05-01 15:35:39 -0700 | [diff] [blame] | 173 | import java.util.Set; |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 174 | |
| 175 | /** |
| 176 | * State and management of a single stack of activities. |
| 177 | */ |
Yunfan Chen | 279f558 | 2018-12-12 15:24:50 -0800 | [diff] [blame] | 178 | class ActivityStack extends ConfigurationContainer { |
Wale Ogunwale | 9887561 | 2018-10-12 07:53:02 -0700 | [diff] [blame] | 179 | private static final String TAG = TAG_WITH_CLASS_NAME ? "ActivityStack" : TAG_ATM; |
Wale Ogunwale | 0fc365c | 2015-05-25 19:35:42 -0700 | [diff] [blame] | 180 | private static final String TAG_ADD_REMOVE = TAG + POSTFIX_ADD_REMOVE; |
| 181 | private static final String TAG_APP = TAG + POSTFIX_APP; |
Wale Ogunwale | e23149f | 2015-03-06 15:39:44 -0800 | [diff] [blame] | 182 | private static final String TAG_CLEANUP = TAG + POSTFIX_CLEANUP; |
Wale Ogunwale | 0fc365c | 2015-05-25 19:35:42 -0700 | [diff] [blame] | 183 | private static final String TAG_CONTAINERS = TAG + POSTFIX_CONTAINERS; |
Wale Ogunwale | ee006da | 2015-03-30 14:49:25 -0700 | [diff] [blame] | 184 | private static final String TAG_PAUSE = TAG + POSTFIX_PAUSE; |
Wale Ogunwale | 0fc365c | 2015-05-25 19:35:42 -0700 | [diff] [blame] | 185 | private static final String TAG_RELEASE = TAG + POSTFIX_RELEASE; |
Wale Ogunwale | ee006da | 2015-03-30 14:49:25 -0700 | [diff] [blame] | 186 | private static final String TAG_RESULTS = TAG + POSTFIX_RESULTS; |
Wale Ogunwale | 0fc365c | 2015-05-25 19:35:42 -0700 | [diff] [blame] | 187 | private static final String TAG_SAVED_STATE = TAG + POSTFIX_SAVED_STATE; |
Wale Ogunwale | ee006da | 2015-03-30 14:49:25 -0700 | [diff] [blame] | 188 | private static final String TAG_STACK = TAG + POSTFIX_STACK; |
Wale Ogunwale | 0fc365c | 2015-05-25 19:35:42 -0700 | [diff] [blame] | 189 | private static final String TAG_STATES = TAG + POSTFIX_STATES; |
Wale Ogunwale | ee006da | 2015-03-30 14:49:25 -0700 | [diff] [blame] | 190 | private static final String TAG_SWITCH = TAG + POSTFIX_SWITCH; |
| 191 | private static final String TAG_TASKS = TAG + POSTFIX_TASKS; |
| 192 | private static final String TAG_TRANSITION = TAG + POSTFIX_TRANSITION; |
| 193 | private static final String TAG_USER_LEAVING = TAG + POSTFIX_USER_LEAVING; |
| 194 | private static final String TAG_VISIBILITY = TAG + POSTFIX_VISIBILITY; |
Wale Ogunwale | 3ab9a27 | 2015-03-16 09:55:45 -0700 | [diff] [blame] | 195 | |
Dianne Hackborn | 2a29b3a | 2012-03-15 15:48:38 -0700 | [diff] [blame] | 196 | // Ticks during which we check progress while waiting for an app to launch. |
| 197 | static final int LAUNCH_TICK = 500; |
| 198 | |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 199 | // How long we wait until giving up on the last activity to pause. This |
| 200 | // is short because it directly impacts the responsiveness of starting the |
| 201 | // next activity. |
Andrii Kulian | 21713ac | 2016-10-12 22:05:05 -0700 | [diff] [blame] | 202 | private static final int PAUSE_TIMEOUT = 500; |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 203 | |
Dianne Hackborn | 162bc0e | 2012-04-09 14:06:16 -0700 | [diff] [blame] | 204 | // How long we wait for the activity to tell us it has stopped before |
| 205 | // 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] | 206 | // from the application in order to get its saved state. Once the stop |
| 207 | // is complete we may start destroying client resources triggering |
| 208 | // crashes if the UI thread was hung. We put this timeout one second behind |
| 209 | // the ANR timeout so these situations will generate ANR instead of |
| 210 | // Surface lost or other errors. |
| 211 | private static final int STOP_TIMEOUT = 11 * 1000; |
Dianne Hackborn | 162bc0e | 2012-04-09 14:06:16 -0700 | [diff] [blame] | 212 | |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 213 | // How long we wait until giving up on an activity telling us it has |
| 214 | // finished destroying itself. |
Andrii Kulian | 21713ac | 2016-10-12 22:05:05 -0700 | [diff] [blame] | 215 | private static final int DESTROY_TIMEOUT = 10 * 1000; |
Craig Mautner | d74f7d7 | 2013-02-26 13:41:02 -0800 | [diff] [blame] | 216 | |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 217 | // Set to false to disable the preview that is shown while a new activity |
| 218 | // is being started. |
Andrii Kulian | 21713ac | 2016-10-12 22:05:05 -0700 | [diff] [blame] | 219 | private static final boolean SHOW_APP_STARTING_PREVIEW = true; |
Craig Mautner | 5d9c7be | 2013-02-15 14:02:56 -0800 | [diff] [blame] | 220 | |
Craig Mautner | 5eda9b3 | 2013-07-02 11:58:16 -0700 | [diff] [blame] | 221 | // How long to wait for all background Activities to redraw following a call to |
| 222 | // convertToTranslucent(). |
Andrii Kulian | 21713ac | 2016-10-12 22:05:05 -0700 | [diff] [blame] | 223 | private static final long TRANSLUCENT_CONVERSION_TIMEOUT = 2000; |
Craig Mautner | 5eda9b3 | 2013-07-02 11:58:16 -0700 | [diff] [blame] | 224 | |
Filip Gruszczynski | ef2f72b | 2015-12-04 14:52:25 -0800 | [diff] [blame] | 225 | // How many activities have to be scheduled to stop to force a stop pass. |
| 226 | private static final int MAX_STOPPING_TO_FORCE = 3; |
| 227 | |
Andrii Kulian | 0c869cc | 2019-02-06 19:50:32 -0800 | [diff] [blame] | 228 | @IntDef(prefix = {"STACK_VISIBILITY"}, value = { |
| 229 | STACK_VISIBILITY_VISIBLE, |
| 230 | STACK_VISIBILITY_VISIBLE_BEHIND_TRANSLUCENT, |
| 231 | STACK_VISIBILITY_INVISIBLE, |
| 232 | }) |
| 233 | @interface StackVisibility {} |
| 234 | |
| 235 | /** Stack is visible. No other stacks on top that fully or partially occlude it. */ |
| 236 | static final int STACK_VISIBILITY_VISIBLE = 0; |
| 237 | |
| 238 | /** Stack is partially occluded by other translucent stack(s) on top of it. */ |
| 239 | static final int STACK_VISIBILITY_VISIBLE_BEHIND_TRANSLUCENT = 1; |
| 240 | |
| 241 | /** Stack is completely invisible. */ |
| 242 | static final int STACK_VISIBILITY_INVISIBLE = 2; |
| 243 | |
Andrii Kulian | 1779e61 | 2016-10-12 21:58:25 -0700 | [diff] [blame] | 244 | @Override |
| 245 | protected int getChildCount() { |
| 246 | return mTaskHistory.size(); |
| 247 | } |
| 248 | |
| 249 | @Override |
Garfield Tan | b5cc09f | 2018-09-28 10:06:52 -0700 | [diff] [blame] | 250 | protected TaskRecord getChildAt(int index) { |
Andrii Kulian | 1779e61 | 2016-10-12 21:58:25 -0700 | [diff] [blame] | 251 | return mTaskHistory.get(index); |
| 252 | } |
| 253 | |
| 254 | @Override |
Evan Rosky | c5abbd8 | 2018-10-05 16:02:19 -0700 | [diff] [blame] | 255 | protected ActivityDisplay getParent() { |
Andrii Kulian | 94e82d9b0 | 2017-07-13 15:33:06 -0700 | [diff] [blame] | 256 | return getDisplay(); |
Andrii Kulian | 1779e61 | 2016-10-12 21:58:25 -0700 | [diff] [blame] | 257 | } |
| 258 | |
Evan Rosky | c5abbd8 | 2018-10-05 16:02:19 -0700 | [diff] [blame] | 259 | void setParent(ActivityDisplay parent) { |
| 260 | ActivityDisplay current = getParent(); |
| 261 | if (current != parent) { |
| 262 | mDisplayId = parent.mDisplayId; |
| 263 | onParentChanged(); |
| 264 | } |
| 265 | } |
| 266 | |
Andrii Kulian | fb1bf69 | 2017-01-17 11:17:34 -0800 | [diff] [blame] | 267 | @Override |
Wale Ogunwale | 98d6231 | 2017-07-12 09:24:56 -0700 | [diff] [blame] | 268 | protected void onParentChanged() { |
Evan Rosky | c5abbd8 | 2018-10-05 16:02:19 -0700 | [diff] [blame] | 269 | ActivityDisplay display = getParent(); |
| 270 | if (display != null) { |
| 271 | // Rotations are relative to the display. This means if there are 2 displays rotated |
| 272 | // differently (eg. 2 monitors with one landscape and one portrait), moving a stack |
| 273 | // from one to the other could look like a rotation change. To prevent this |
| 274 | // apparent rotation change (and corresponding bounds rotation), pretend like our |
| 275 | // current rotation is already the same as the new display. |
| 276 | // Note, if ActivityStack or related logic ever gets nested, this logic will need |
| 277 | // to move to onConfigurationChanged. |
| 278 | getConfiguration().windowConfiguration.setRotation( |
| 279 | display.getWindowConfiguration().getRotation()); |
| 280 | } |
Andrii Kulian | fb1bf69 | 2017-01-17 11:17:34 -0800 | [diff] [blame] | 281 | super.onParentChanged(); |
Evan Rosky | c5abbd8 | 2018-10-05 16:02:19 -0700 | [diff] [blame] | 282 | if (display != null && inSplitScreenPrimaryWindowingMode()) { |
| 283 | // If we created a docked stack we want to resize it so it resizes all other stacks |
| 284 | // in the system. |
Riddle Hsu | d106973 | 2019-05-09 17:04:31 +0800 | [diff] [blame] | 285 | getStackDockedModeBounds(null /* dockedBounds */, null /* currentTempTaskBounds */, |
| 286 | mTmpRect /* outStackBounds */, mTmpRect2 /* outTempTaskBounds */); |
| 287 | mStackSupervisor.resizeDockedStackLocked(getRequestedOverrideBounds(), mTmpRect, |
Evan Rosky | dfe3da7 | 2018-10-26 17:21:06 -0700 | [diff] [blame] | 288 | mTmpRect2, null, null, PRESERVE_WINDOWS); |
Evan Rosky | c5abbd8 | 2018-10-05 16:02:19 -0700 | [diff] [blame] | 289 | } |
Wale Ogunwale | d32da47 | 2018-11-16 07:19:28 -0800 | [diff] [blame] | 290 | mRootActivityContainer.updateUIDsPresentOnDisplay(); |
Andrii Kulian | fb1bf69 | 2017-01-17 11:17:34 -0800 | [diff] [blame] | 291 | } |
| 292 | |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 293 | enum ActivityState { |
| 294 | INITIALIZING, |
| 295 | RESUMED, |
| 296 | PAUSING, |
| 297 | PAUSED, |
| 298 | STOPPING, |
| 299 | STOPPED, |
| 300 | FINISHING, |
| 301 | DESTROYING, |
Riddle Hsu | 7b766fd | 2019-01-28 21:14:59 +0800 | [diff] [blame] | 302 | DESTROYED, |
| 303 | RESTARTING_PROCESS |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 304 | } |
| 305 | |
Bryce Lee | 840c566 | 2017-04-13 10:02:51 -0700 | [diff] [blame] | 306 | @VisibleForTesting |
Wale Ogunwale | 06579d6 | 2016-04-30 15:29:06 -0700 | [diff] [blame] | 307 | /* The various modes for the method {@link #removeTask}. */ |
| 308 | // Task is being completely removed from all stacks in the system. |
Bryce Lee | 840c566 | 2017-04-13 10:02:51 -0700 | [diff] [blame] | 309 | protected static final int REMOVE_TASK_MODE_DESTROYING = 0; |
Wale Ogunwale | 06579d6 | 2016-04-30 15:29:06 -0700 | [diff] [blame] | 310 | // Task is being removed from this stack so we can add it to another stack. In the case we are |
| 311 | // moving we don't want to perform some operations on the task like removing it from window |
| 312 | // manager or recents. |
| 313 | static final int REMOVE_TASK_MODE_MOVING = 1; |
| 314 | // Similar to {@link #REMOVE_TASK_MODE_MOVING} and the task will be added to the top of its new |
| 315 | // stack and the new stack will be on top of all stacks. |
Wale Ogunwale | 56d8d16 | 2017-05-30 11:12:20 -0700 | [diff] [blame] | 316 | static final int REMOVE_TASK_MODE_MOVING_TO_TOP = 2; |
Wale Ogunwale | 06579d6 | 2016-04-30 15:29:06 -0700 | [diff] [blame] | 317 | |
Wale Ogunwale | 5fa8a8c | 2018-05-08 13:43:21 -0700 | [diff] [blame] | 318 | final ActivityTaskManagerService mService; |
Yunfan Chen | 279f558 | 2018-12-12 15:24:50 -0800 | [diff] [blame] | 319 | final WindowManagerService mWindowManager; |
Craig Mautner | d74f7d7 | 2013-02-26 13:41:02 -0800 | [diff] [blame] | 320 | |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 321 | /** |
| 322 | * The back history of all previous (and possibly still |
Craig Mautner | 5d9c7be | 2013-02-15 14:02:56 -0800 | [diff] [blame] | 323 | * running) activities. It contains #TaskRecord objects. |
| 324 | */ |
Todd Kennedy | 39bfee5 | 2016-02-24 10:28:21 -0800 | [diff] [blame] | 325 | private final ArrayList<TaskRecord> mTaskHistory = new ArrayList<>(); |
Craig Mautner | 5d9c7be | 2013-02-15 14:02:56 -0800 | [diff] [blame] | 326 | |
| 327 | /** |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 328 | * List of running activities, sorted by recent usage. |
| 329 | * The first entry in the list is the least recently used. |
| 330 | * It contains HistoryRecord objects. |
| 331 | */ |
Garfield Tan | 347bd60 | 2018-12-21 15:11:12 -0800 | [diff] [blame] | 332 | private final ArrayList<ActivityRecord> mLRUActivities = new ArrayList<>(); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 333 | |
| 334 | /** |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 335 | * When we are in the process of pausing an activity, before starting the |
| 336 | * next one, this variable holds the activity that is currently being paused. |
| 337 | */ |
Dianne Hackborn | 621e2fe | 2012-02-16 17:07:33 -0800 | [diff] [blame] | 338 | ActivityRecord mPausingActivity = null; |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 339 | |
| 340 | /** |
| 341 | * This is the last activity that we put into the paused state. This is |
| 342 | * used to determine if we need to do an activity transition while sleeping, |
| 343 | * when we normally hold the top activity paused. |
| 344 | */ |
| 345 | ActivityRecord mLastPausedActivity = null; |
| 346 | |
| 347 | /** |
Craig Mautner | 0f92274 | 2013-08-06 08:44:42 -0700 | [diff] [blame] | 348 | * Activities that specify No History must be removed once the user navigates away from them. |
| 349 | * If the device goes to sleep with such an activity in the paused state then we save it here |
| 350 | * and finish it later if another activity replaces it on wakeup. |
| 351 | */ |
| 352 | ActivityRecord mLastNoHistoryActivity = null; |
| 353 | |
| 354 | /** |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 355 | * Current activity that is resumed, or null if there is none. |
| 356 | */ |
| 357 | ActivityRecord mResumedActivity = null; |
Craig Mautner | d74f7d7 | 2013-02-26 13:41:02 -0800 | [diff] [blame] | 358 | |
Craig Mautner | 5eda9b3 | 2013-07-02 11:58:16 -0700 | [diff] [blame] | 359 | // The topmost Activity passed to convertToTranslucent(). When non-null it means we are |
| 360 | // waiting for all Activities in mUndrawnActivitiesBelowTopTranslucent to be removed as they |
| 361 | // are drawn. When the last member of mUndrawnActivitiesBelowTopTranslucent is removed the |
| 362 | // Activity in mTranslucentActivityWaiting is notified via |
| 363 | // Activity.onTranslucentConversionComplete(false). If a timeout occurs prior to the last |
| 364 | // background activity being drawn then the same call will be made with a true value. |
| 365 | ActivityRecord mTranslucentActivityWaiting = null; |
Andrii Kulian | 21713ac | 2016-10-12 22:05:05 -0700 | [diff] [blame] | 366 | ArrayList<ActivityRecord> mUndrawnActivitiesBelowTopTranslucent = new ArrayList<>(); |
Craig Mautner | 5eda9b3 | 2013-07-02 11:58:16 -0700 | [diff] [blame] | 367 | |
Dianne Hackborn | 0dad364 | 2010-09-09 21:25:35 -0700 | [diff] [blame] | 368 | /** |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 369 | * Set when we know we are going to be calling updateConfiguration() |
| 370 | * soon, so want to skip intermediate config checks. |
| 371 | */ |
| 372 | boolean mConfigWillChange; |
| 373 | |
Winson Chung | 4790065 | 2017-04-06 18:44:25 -0700 | [diff] [blame] | 374 | /** |
| 375 | * When set, will force the stack to report as invisible. |
| 376 | */ |
| 377 | boolean mForceHidden = false; |
| 378 | |
Andrii Kulian | 6b32151 | 2019-01-23 06:37:00 +0000 | [diff] [blame] | 379 | /** |
| 380 | * Used to keep resumeTopActivityUncheckedLocked() from being entered recursively |
| 381 | */ |
| 382 | boolean mInResumeTopActivity = false; |
| 383 | |
Andrii Kulian | 21713ac | 2016-10-12 22:05:05 -0700 | [diff] [blame] | 384 | private boolean mUpdateBoundsDeferred; |
| 385 | private boolean mUpdateBoundsDeferredCalled; |
Evan Rosky | 1ac8446 | 2018-11-13 11:25:30 -0800 | [diff] [blame] | 386 | private boolean mUpdateDisplayedBoundsDeferredCalled; |
Andrii Kulian | 21713ac | 2016-10-12 22:05:05 -0700 | [diff] [blame] | 387 | private final Rect mDeferredBounds = new Rect(); |
Evan Rosky | 1ac8446 | 2018-11-13 11:25:30 -0800 | [diff] [blame] | 388 | private final Rect mDeferredDisplayedBounds = new Rect(); |
Jorim Jaggi | 192086e | 2016-03-11 17:17:03 +0100 | [diff] [blame] | 389 | |
Craig Mautner | 858d8a6 | 2013-04-23 17:08:34 -0700 | [diff] [blame] | 390 | int mCurrentUser; |
Amith Yamasani | 742a671 | 2011-05-04 14:49:28 -0700 | [diff] [blame] | 391 | |
Craig Mautner | c00204b | 2013-03-05 15:02:14 -0800 | [diff] [blame] | 392 | final int mStackId; |
Craig Mautner | e0a3884 | 2013-12-16 16:14:02 -0800 | [diff] [blame] | 393 | /** The attached Display's unique identifier, or -1 if detached */ |
| 394 | int mDisplayId; |
Craig Mautner | 4a1cb22 | 2013-12-04 16:14:06 -0800 | [diff] [blame] | 395 | |
Evan Rosky | 1047574 | 2018-09-05 19:02:48 -0700 | [diff] [blame] | 396 | /** Stores the override windowing-mode from before a transient mode change (eg. split) */ |
| 397 | private int mRestoreOverrideWindowingMode = WINDOWING_MODE_UNDEFINED; |
| 398 | |
Evan Rosky | c5abbd8 | 2018-10-05 16:02:19 -0700 | [diff] [blame] | 399 | private final Rect mTmpRect = new Rect(); |
Wale Ogunwale | 1666e31 | 2016-12-16 11:27:18 -0800 | [diff] [blame] | 400 | private final Rect mTmpRect2 = new Rect(); |
Wale Ogunwale | 30e441d | 2017-11-09 08:28:45 -0800 | [diff] [blame] | 401 | private final ActivityOptions mTmpOptions = ActivityOptions.makeBasic(); |
Andrii Kulian | 1e32e02 | 2016-09-16 15:29:34 -0700 | [diff] [blame] | 402 | |
Bryce Lee | fbd263b4 | 2018-03-07 10:33:55 -0800 | [diff] [blame] | 403 | /** List for processing through a set of activities */ |
| 404 | private final ArrayList<ActivityRecord> mTmpActivities = new ArrayList<>(); |
| 405 | |
Craig Mautner | 2708430 | 2013-03-25 08:05:25 -0700 | [diff] [blame] | 406 | /** Run all ActivityStacks through this */ |
Winson Chung | 5af42fc | 2017-03-24 17:11:33 -0700 | [diff] [blame] | 407 | protected final ActivityStackSupervisor mStackSupervisor; |
Wale Ogunwale | d32da47 | 2018-11-16 07:19:28 -0800 | [diff] [blame] | 408 | protected final RootActivityContainer mRootActivityContainer; |
Craig Mautner | 2708430 | 2013-03-25 08:05:25 -0700 | [diff] [blame] | 409 | |
Jorim Jaggi | fe76234 | 2016-10-13 14:33:27 +0200 | [diff] [blame] | 410 | private boolean mTopActivityOccludesKeyguard; |
| 411 | private ActivityRecord mTopDismissingKeyguardActivity; |
| 412 | |
Wale Ogunwale | 9887561 | 2018-10-12 07:53:02 -0700 | [diff] [blame] | 413 | static final int PAUSE_TIMEOUT_MSG = FIRST_ACTIVITY_STACK_MSG + 1; |
| 414 | static final int DESTROY_TIMEOUT_MSG = FIRST_ACTIVITY_STACK_MSG + 2; |
| 415 | static final int LAUNCH_TICK_MSG = FIRST_ACTIVITY_STACK_MSG + 3; |
| 416 | static final int STOP_TIMEOUT_MSG = FIRST_ACTIVITY_STACK_MSG + 4; |
| 417 | static final int DESTROY_ACTIVITIES_MSG = FIRST_ACTIVITY_STACK_MSG + 5; |
| 418 | static final int TRANSLUCENT_TIMEOUT_MSG = FIRST_ACTIVITY_STACK_MSG + 6; |
Dianne Hackborn | 755c8bf | 2012-05-07 15:06:09 -0700 | [diff] [blame] | 419 | |
Yunfan Chen | 279f558 | 2018-12-12 15:24:50 -0800 | [diff] [blame] | 420 | // TODO: remove after unification. |
| 421 | TaskStack mTaskStack; |
| 422 | |
Andrii Kulian | 21713ac | 2016-10-12 22:05:05 -0700 | [diff] [blame] | 423 | private static class ScheduleDestroyArgs { |
Wale Ogunwale | 9e4f3e0 | 2018-05-17 09:35:39 -0700 | [diff] [blame] | 424 | final WindowProcessController mOwner; |
Dianne Hackborn | 755c8bf | 2012-05-07 15:06:09 -0700 | [diff] [blame] | 425 | final String mReason; |
Wale Ogunwale | 9e4f3e0 | 2018-05-17 09:35:39 -0700 | [diff] [blame] | 426 | ScheduleDestroyArgs(WindowProcessController owner, String reason) { |
Dianne Hackborn | 755c8bf | 2012-05-07 15:06:09 -0700 | [diff] [blame] | 427 | mOwner = owner; |
Dianne Hackborn | 755c8bf | 2012-05-07 15:06:09 -0700 | [diff] [blame] | 428 | mReason = reason; |
| 429 | } |
| 430 | } |
| 431 | |
Zoran Marceta | f958b32 | 2012-08-09 20:27:12 +0900 | [diff] [blame] | 432 | final Handler mHandler; |
| 433 | |
Andrii Kulian | 21713ac | 2016-10-12 22:05:05 -0700 | [diff] [blame] | 434 | private class ActivityStackHandler extends Handler { |
Wale Ogunwale | e23149f | 2015-03-06 15:39:44 -0800 | [diff] [blame] | 435 | |
Craig Mautner | c8143c6 | 2013-09-03 12:15:57 -0700 | [diff] [blame] | 436 | ActivityStackHandler(Looper looper) { |
Zoran Marceta | f958b32 | 2012-08-09 20:27:12 +0900 | [diff] [blame] | 437 | super(looper); |
| 438 | } |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 439 | |
Zoran Marceta | f958b32 | 2012-08-09 20:27:12 +0900 | [diff] [blame] | 440 | @Override |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 441 | public void handleMessage(Message msg) { |
| 442 | switch (msg.what) { |
| 443 | case PAUSE_TIMEOUT_MSG: { |
Dianne Hackborn | be70785 | 2011-11-11 14:32:10 -0800 | [diff] [blame] | 444 | ActivityRecord r = (ActivityRecord)msg.obj; |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 445 | // We don't at this point know if the activity is fullscreen, |
| 446 | // so we need to be conservative and assume it isn't. |
Dianne Hackborn | be70785 | 2011-11-11 14:32:10 -0800 | [diff] [blame] | 447 | Slog.w(TAG, "Activity pause timeout for " + r); |
Wale Ogunwale | 5fa8a8c | 2018-05-08 13:43:21 -0700 | [diff] [blame] | 448 | synchronized (mService.mGlobalLock) { |
Wale Ogunwale | 9e4f3e0 | 2018-05-17 09:35:39 -0700 | [diff] [blame] | 449 | if (r.hasProcess()) { |
| 450 | mService.logAppTooSlow(r.app, r.pauseTime, "pausing " + r); |
Dianne Hackborn | 2a29b3a | 2012-03-15 15:48:38 -0700 | [diff] [blame] | 451 | } |
Dianne Hackborn | a4e102e | 2014-09-04 22:52:27 -0700 | [diff] [blame] | 452 | activityPausedLocked(r.appToken, true); |
Craig Mautner | d232895 | 2013-03-05 12:46:26 -0800 | [diff] [blame] | 453 | } |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 454 | } break; |
Dianne Hackborn | 2a29b3a | 2012-03-15 15:48:38 -0700 | [diff] [blame] | 455 | case LAUNCH_TICK_MSG: { |
| 456 | ActivityRecord r = (ActivityRecord)msg.obj; |
Wale Ogunwale | 5fa8a8c | 2018-05-08 13:43:21 -0700 | [diff] [blame] | 457 | synchronized (mService.mGlobalLock) { |
Dianne Hackborn | 2a29b3a | 2012-03-15 15:48:38 -0700 | [diff] [blame] | 458 | if (r.continueLaunchTickingLocked()) { |
Wale Ogunwale | 9e4f3e0 | 2018-05-17 09:35:39 -0700 | [diff] [blame] | 459 | mService.logAppTooSlow(r.app, r.launchTickTime, "launching " + r); |
Dianne Hackborn | 2a29b3a | 2012-03-15 15:48:38 -0700 | [diff] [blame] | 460 | } |
| 461 | } |
| 462 | } break; |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 463 | case DESTROY_TIMEOUT_MSG: { |
Dianne Hackborn | be70785 | 2011-11-11 14:32:10 -0800 | [diff] [blame] | 464 | ActivityRecord r = (ActivityRecord)msg.obj; |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 465 | // We don't at this point know if the activity is fullscreen, |
| 466 | // so we need to be conservative and assume it isn't. |
Dianne Hackborn | be70785 | 2011-11-11 14:32:10 -0800 | [diff] [blame] | 467 | Slog.w(TAG, "Activity destroy timeout for " + r); |
Wale Ogunwale | 5fa8a8c | 2018-05-08 13:43:21 -0700 | [diff] [blame] | 468 | synchronized (mService.mGlobalLock) { |
Craig Mautner | 299f960 | 2015-01-26 09:47:33 -0800 | [diff] [blame] | 469 | activityDestroyedLocked(r != null ? r.appToken : null, "destroyTimeout"); |
Craig Mautner | d232895 | 2013-03-05 12:46:26 -0800 | [diff] [blame] | 470 | } |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 471 | } break; |
Dianne Hackborn | 162bc0e | 2012-04-09 14:06:16 -0700 | [diff] [blame] | 472 | case STOP_TIMEOUT_MSG: { |
| 473 | ActivityRecord r = (ActivityRecord)msg.obj; |
| 474 | // We don't at this point know if the activity is fullscreen, |
| 475 | // so we need to be conservative and assume it isn't. |
| 476 | Slog.w(TAG, "Activity stop timeout for " + r); |
Wale Ogunwale | 5fa8a8c | 2018-05-08 13:43:21 -0700 | [diff] [blame] | 477 | synchronized (mService.mGlobalLock) { |
Dianne Hackborn | 162bc0e | 2012-04-09 14:06:16 -0700 | [diff] [blame] | 478 | if (r.isInHistory()) { |
Andrii Kulian | 21713ac | 2016-10-12 22:05:05 -0700 | [diff] [blame] | 479 | r.activityStoppedLocked(null /* icicle */, |
| 480 | null /* persistentState */, null /* description */); |
Dianne Hackborn | 162bc0e | 2012-04-09 14:06:16 -0700 | [diff] [blame] | 481 | } |
| 482 | } |
| 483 | } break; |
Dianne Hackborn | 755c8bf | 2012-05-07 15:06:09 -0700 | [diff] [blame] | 484 | case DESTROY_ACTIVITIES_MSG: { |
| 485 | ScheduleDestroyArgs args = (ScheduleDestroyArgs)msg.obj; |
Wale Ogunwale | 5fa8a8c | 2018-05-08 13:43:21 -0700 | [diff] [blame] | 486 | synchronized (mService.mGlobalLock) { |
Craig Mautner | ee2e45a | 2014-06-27 12:10:03 -0700 | [diff] [blame] | 487 | destroyActivitiesLocked(args.mOwner, args.mReason); |
Dianne Hackborn | 755c8bf | 2012-05-07 15:06:09 -0700 | [diff] [blame] | 488 | } |
Craig Mautner | 5eda9b3 | 2013-07-02 11:58:16 -0700 | [diff] [blame] | 489 | } break; |
| 490 | case TRANSLUCENT_TIMEOUT_MSG: { |
Wale Ogunwale | 5fa8a8c | 2018-05-08 13:43:21 -0700 | [diff] [blame] | 491 | synchronized (mService.mGlobalLock) { |
Craig Mautner | 5eda9b3 | 2013-07-02 11:58:16 -0700 | [diff] [blame] | 492 | notifyActivityDrawnLocked(null); |
| 493 | } |
| 494 | } break; |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 495 | } |
| 496 | } |
Craig Mautner | 4b71aa1 | 2012-12-27 17:20:01 -0800 | [diff] [blame] | 497 | } |
| 498 | |
Craig Mautner | 34b73df | 2014-01-12 21:11:08 -0800 | [diff] [blame] | 499 | int numActivities() { |
Craig Mautner | 000f002 | 2013-02-26 15:04:29 -0800 | [diff] [blame] | 500 | int count = 0; |
| 501 | for (int taskNdx = mTaskHistory.size() - 1; taskNdx >= 0; --taskNdx) { |
| 502 | count += mTaskHistory.get(taskNdx).mActivities.size(); |
| 503 | } |
| 504 | return count; |
| 505 | } |
| 506 | |
Wale Ogunwale | 9dcf946 | 2017-09-19 15:13:01 -0700 | [diff] [blame] | 507 | ActivityStack(ActivityDisplay display, int stackId, ActivityStackSupervisor supervisor, |
Wale Ogunwale | 04a05ac | 2017-09-17 21:35:02 -0700 | [diff] [blame] | 508 | int windowingMode, int activityType, boolean onTop) { |
Andrii Kulian | 94e82d9b0 | 2017-07-13 15:33:06 -0700 | [diff] [blame] | 509 | mStackSupervisor = supervisor; |
Wale Ogunwale | c9e57de | 2018-05-08 14:28:07 -0700 | [diff] [blame] | 510 | mService = supervisor.mService; |
Wale Ogunwale | d32da47 | 2018-11-16 07:19:28 -0800 | [diff] [blame] | 511 | mRootActivityContainer = mService.mRootActivityContainer; |
Wale Ogunwale | 5fa8a8c | 2018-05-08 13:43:21 -0700 | [diff] [blame] | 512 | mHandler = new ActivityStackHandler(supervisor.mLooper); |
Craig Mautner | 4a1cb22 | 2013-12-04 16:14:06 -0800 | [diff] [blame] | 513 | mWindowManager = mService.mWindowManager; |
Andrii Kulian | 94e82d9b0 | 2017-07-13 15:33:06 -0700 | [diff] [blame] | 514 | mStackId = stackId; |
Wale Ogunwale | 86b7446 | 2018-07-02 08:42:43 -0700 | [diff] [blame] | 515 | mCurrentUser = mService.mAmInternal.getCurrentUserId(); |
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(); |
Evan Rosky | c5abbd8 | 2018-10-05 16:02:19 -0700 | [diff] [blame] | 575 | final int prevRotation = getWindowConfiguration().getRotation(); |
| 576 | final int prevDensity = getConfiguration().densityDpi; |
| 577 | final int prevScreenW = getConfiguration().screenWidthDp; |
| 578 | final int prevScreenH = getConfiguration().screenHeightDp; |
Riddle Hsu | d106973 | 2019-05-09 17:04:31 +0800 | [diff] [blame] | 579 | final Rect newBounds = mTmpRect; |
| 580 | // Initialize the new bounds by previous bounds as the input and output for calculating |
| 581 | // override bounds in pinned (pip) or split-screen mode. |
| 582 | getBounds(newBounds); |
Evan Rosky | e747c3e | 2018-10-30 20:06:41 -0700 | [diff] [blame] | 583 | |
| 584 | super.onConfigurationChanged(newParentConfig); |
Riddle Hsu | d106973 | 2019-05-09 17:04:31 +0800 | [diff] [blame] | 585 | final ActivityDisplay display = getDisplay(); |
| 586 | if (display == null || getTaskStack() == null) { |
Yunfan Chen | 279f558 | 2018-12-12 15:24:50 -0800 | [diff] [blame] | 587 | return; |
| 588 | } |
Evan Rosky | c5abbd8 | 2018-10-05 16:02:19 -0700 | [diff] [blame] | 589 | |
Riddle Hsu | d106973 | 2019-05-09 17:04:31 +0800 | [diff] [blame] | 590 | final boolean windowingModeChanged = prevWindowingMode != getWindowingMode(); |
| 591 | final int overrideWindowingMode = getRequestedOverrideWindowingMode(); |
Evan Rosky | c5abbd8 | 2018-10-05 16:02:19 -0700 | [diff] [blame] | 592 | // Update bounds if applicable |
| 593 | boolean hasNewOverrideBounds = false; |
| 594 | // Use override windowing mode to prevent extra bounds changes if inheriting the mode. |
Riddle Hsu | d106973 | 2019-05-09 17:04:31 +0800 | [diff] [blame] | 595 | if (overrideWindowingMode == WINDOWING_MODE_PINNED) { |
Evan Rosky | c5abbd8 | 2018-10-05 16:02:19 -0700 | [diff] [blame] | 596 | // Pinned calculation already includes rotation |
Riddle Hsu | d106973 | 2019-05-09 17:04:31 +0800 | [diff] [blame] | 597 | hasNewOverrideBounds = getTaskStack().calculatePinnedBoundsForConfigChange(newBounds); |
| 598 | } else if (!matchParentBounds()) { |
| 599 | // If the parent (display) has rotated, rotate our bounds to best-fit where their |
| 600 | // bounds were on the pre-rotated display. |
Evan Rosky | c5abbd8 | 2018-10-05 16:02:19 -0700 | [diff] [blame] | 601 | final int newRotation = getWindowConfiguration().getRotation(); |
Riddle Hsu | d106973 | 2019-05-09 17:04:31 +0800 | [diff] [blame] | 602 | final boolean rotationChanged = prevRotation != newRotation; |
| 603 | if (rotationChanged) { |
| 604 | display.mDisplayContent.rotateBounds( |
| 605 | newParentConfig.windowConfiguration.getBounds(), prevRotation, newRotation, |
| 606 | newBounds); |
| 607 | hasNewOverrideBounds = true; |
| 608 | } |
Evan Rosky | c5abbd8 | 2018-10-05 16:02:19 -0700 | [diff] [blame] | 609 | |
Riddle Hsu | d106973 | 2019-05-09 17:04:31 +0800 | [diff] [blame] | 610 | // Use override windowing mode to prevent extra bounds changes if inheriting the mode. |
| 611 | if (overrideWindowingMode == WINDOWING_MODE_SPLIT_SCREEN_PRIMARY |
| 612 | || overrideWindowingMode == WINDOWING_MODE_SPLIT_SCREEN_SECONDARY) { |
Evan Rosky | c5abbd8 | 2018-10-05 16:02:19 -0700 | [diff] [blame] | 613 | // If entering split screen or if something about the available split area changes, |
| 614 | // recalculate the split windows to match the new configuration. |
Riddle Hsu | d106973 | 2019-05-09 17:04:31 +0800 | [diff] [blame] | 615 | if (rotationChanged || windowingModeChanged |
Evan Rosky | c5abbd8 | 2018-10-05 16:02:19 -0700 | [diff] [blame] | 616 | || prevDensity != getConfiguration().densityDpi |
Evan Rosky | c5abbd8 | 2018-10-05 16:02:19 -0700 | [diff] [blame] | 617 | || prevScreenW != getConfiguration().screenWidthDp |
| 618 | || prevScreenH != getConfiguration().screenHeightDp) { |
Riddle Hsu | d106973 | 2019-05-09 17:04:31 +0800 | [diff] [blame] | 619 | getTaskStack().calculateDockedBoundsForConfigChange(newParentConfig, newBounds); |
| 620 | hasNewOverrideBounds = true; |
Evan Rosky | c5abbd8 | 2018-10-05 16:02:19 -0700 | [diff] [blame] | 621 | } |
| 622 | } |
| 623 | } |
Riddle Hsu | d106973 | 2019-05-09 17:04:31 +0800 | [diff] [blame] | 624 | |
| 625 | if (windowingModeChanged) { |
Evan Rosky | c5abbd8 | 2018-10-05 16:02:19 -0700 | [diff] [blame] | 626 | // Use override windowing mode to prevent extra bounds changes if inheriting the mode. |
Riddle Hsu | d106973 | 2019-05-09 17:04:31 +0800 | [diff] [blame] | 627 | if (overrideWindowingMode == WINDOWING_MODE_SPLIT_SCREEN_PRIMARY) { |
| 628 | getStackDockedModeBounds(null /* dockedBounds */, null /* currentTempTaskBounds */, |
| 629 | newBounds /* outStackBounds */, mTmpRect2 /* outTempTaskBounds */); |
Evan Rosky | c5abbd8 | 2018-10-05 16:02:19 -0700 | [diff] [blame] | 630 | // immediately resize so docked bounds are available in onSplitScreenModeActivated |
Evan Rosky | 1ac8446 | 2018-11-13 11:25:30 -0800 | [diff] [blame] | 631 | setTaskDisplayedBounds(null); |
Riddle Hsu | d106973 | 2019-05-09 17:04:31 +0800 | [diff] [blame] | 632 | setTaskBounds(newBounds); |
| 633 | setBounds(newBounds); |
| 634 | newBounds.set(newBounds); |
| 635 | } else if (overrideWindowingMode == WINDOWING_MODE_SPLIT_SCREEN_SECONDARY) { |
Evan Rosky | c5abbd8 | 2018-10-05 16:02:19 -0700 | [diff] [blame] | 636 | Rect dockedBounds = display.getSplitScreenPrimaryStack().getBounds(); |
Wale Ogunwale | 3a256e6 | 2018-12-06 14:41:18 -0800 | [diff] [blame] | 637 | final boolean isMinimizedDock = |
Riddle Hsu | d106973 | 2019-05-09 17:04:31 +0800 | [diff] [blame] | 638 | display.mDisplayContent.getDockedDividerController().isMinimizedDock(); |
Evan Rosky | c5abbd8 | 2018-10-05 16:02:19 -0700 | [diff] [blame] | 639 | if (isMinimizedDock) { |
| 640 | TaskRecord topTask = display.getSplitScreenPrimaryStack().topTask(); |
| 641 | if (topTask != null) { |
| 642 | dockedBounds = topTask.getBounds(); |
| 643 | } |
| 644 | } |
Riddle Hsu | d106973 | 2019-05-09 17:04:31 +0800 | [diff] [blame] | 645 | getStackDockedModeBounds(dockedBounds, null /* currentTempTaskBounds */, |
| 646 | newBounds /* outStackBounds */, mTmpRect2 /* outTempTaskBounds */); |
Evan Rosky | c5abbd8 | 2018-10-05 16:02:19 -0700 | [diff] [blame] | 647 | hasNewOverrideBounds = true; |
| 648 | } |
Wale Ogunwale | a0f5b5e | 2017-10-11 09:37:23 -0700 | [diff] [blame] | 649 | display.onStackWindowingModeChanged(this); |
| 650 | } |
Evan Rosky | c5abbd8 | 2018-10-05 16:02:19 -0700 | [diff] [blame] | 651 | if (hasNewOverrideBounds) { |
Riddle Hsu | d106973 | 2019-05-09 17:04:31 +0800 | [diff] [blame] | 652 | // Note the resizeStack may enter onConfigurationChanged recursively, so we make a copy |
| 653 | // of the temporary bounds (newBounds is mTmpRect) to avoid it being modified. |
| 654 | mRootActivityContainer.resizeStack(this, new Rect(newBounds), null /* tempTaskBounds */, |
| 655 | null /* tempTaskInsetBounds */, PRESERVE_WINDOWS, |
Evan Rosky | c5abbd8 | 2018-10-05 16:02:19 -0700 | [diff] [blame] | 656 | true /* allowResizeInDockedMode */, true /* deferResume */); |
Evan Rosky | e747c3e | 2018-10-30 20:06:41 -0700 | [diff] [blame] | 657 | } |
Kazuki Takise | 048e266 | 2018-06-27 17:05:11 +0900 | [diff] [blame] | 658 | if (prevIsAlwaysOnTop != isAlwaysOnTop()) { |
| 659 | // Since always on top is only on when the stack is freeform or pinned, the state |
| 660 | // can be toggled when the windowing mode changes. We must make sure the stack is |
| 661 | // placed properly when always on top state changes. |
Riddle Hsu | 57831b5 | 2018-07-27 00:31:48 +0800 | [diff] [blame] | 662 | display.positionChildAtTop(this, false /* includingParents */); |
Kazuki Takise | 048e266 | 2018-06-27 17:05:11 +0900 | [diff] [blame] | 663 | } |
Wale Ogunwale | a0f5b5e | 2017-10-11 09:37:23 -0700 | [diff] [blame] | 664 | } |
| 665 | |
Wale Ogunwale | ab5de37 | 2017-10-18 06:46:31 -0700 | [diff] [blame] | 666 | @Override |
Wale Ogunwale | 30e441d | 2017-11-09 08:28:45 -0800 | [diff] [blame] | 667 | public void setWindowingMode(int windowingMode) { |
Winson Chung | 3e36f82 | 2018-01-16 12:06:04 -0800 | [diff] [blame] | 668 | setWindowingMode(windowingMode, false /* animate */, false /* showRecents */, |
Evan Rosky | c5abbd8 | 2018-10-05 16:02:19 -0700 | [diff] [blame] | 669 | false /* enteringSplitScreenMode */, false /* deferEnsuringVisibility */, |
| 670 | false /* creating */); |
Wale Ogunwale | 30e441d | 2017-11-09 08:28:45 -0800 | [diff] [blame] | 671 | } |
| 672 | |
Evan Rosky | 1047574 | 2018-09-05 19:02:48 -0700 | [diff] [blame] | 673 | /** |
| 674 | * A transient windowing mode is one which activities enter into temporarily. Examples of this |
| 675 | * are Split window modes and pip. Non-transient modes are modes that displays can adopt. |
| 676 | * |
| 677 | * @param windowingMode the windowingMode to test for transient-ness. |
| 678 | * @return {@code true} if the windowing mode is transient, {@code false} otherwise. |
| 679 | */ |
| 680 | private static boolean isTransientWindowingMode(int windowingMode) { |
| 681 | // TODO(b/114842032): add PIP if/when it uses mode transitions instead of task reparenting |
| 682 | return windowingMode == WINDOWING_MODE_SPLIT_SCREEN_PRIMARY |
| 683 | || windowingMode == WINDOWING_MODE_SPLIT_SCREEN_SECONDARY; |
| 684 | } |
| 685 | |
| 686 | /** |
| 687 | * Specialization of {@link #setWindowingMode(int)} for this subclass. |
| 688 | * |
| 689 | * @param preferredWindowingMode the preferred windowing mode. This may not be honored depending |
| 690 | * on the state of things. For example, WINDOWING_MODE_UNDEFINED will resolve to the |
| 691 | * previous non-transient mode if this stack is currently in a transient mode. |
| 692 | * @param animate Can be used to prevent animation. |
| 693 | * @param showRecents Controls whether recents is shown on the other side of a split while |
| 694 | * entering split mode. |
| 695 | * @param enteringSplitScreenMode {@code true} if entering split mode. |
| 696 | * @param deferEnsuringVisibility Whether visibility updates are deferred. This is set when |
| 697 | * many operations (which can effect visibility) are being performed in bulk. |
Evan Rosky | c5abbd8 | 2018-10-05 16:02:19 -0700 | [diff] [blame] | 698 | * @param creating {@code true} if this is being run during ActivityStack construction. |
Evan Rosky | 1047574 | 2018-09-05 19:02:48 -0700 | [diff] [blame] | 699 | */ |
Wale Ogunwale | df262f5 | 2017-12-07 18:17:12 -0800 | [diff] [blame] | 700 | void setWindowingMode(int preferredWindowingMode, boolean animate, boolean showRecents, |
Evan Rosky | c5abbd8 | 2018-10-05 16:02:19 -0700 | [diff] [blame] | 701 | boolean enteringSplitScreenMode, boolean deferEnsuringVisibility, boolean creating) { |
Tiger Huang | 6dcbee6 | 2019-02-20 21:45:55 +0800 | [diff] [blame] | 702 | mWindowManager.inSurfaceTransaction(() -> setWindowingModeInSurfaceTransaction( |
| 703 | preferredWindowingMode, animate, showRecents, enteringSplitScreenMode, |
| 704 | deferEnsuringVisibility, creating)); |
| 705 | } |
| 706 | |
| 707 | private void setWindowingModeInSurfaceTransaction(int preferredWindowingMode, boolean animate, |
| 708 | boolean showRecents, boolean enteringSplitScreenMode, boolean deferEnsuringVisibility, |
| 709 | boolean creating) { |
Wale Ogunwale | 30e441d | 2017-11-09 08:28:45 -0800 | [diff] [blame] | 710 | final int currentMode = getWindowingMode(); |
Evan Rosky | dfe3da7 | 2018-10-26 17:21:06 -0700 | [diff] [blame] | 711 | final int currentOverrideMode = getRequestedOverrideWindowingMode(); |
Wale Ogunwale | 30e441d | 2017-11-09 08:28:45 -0800 | [diff] [blame] | 712 | final ActivityDisplay display = getDisplay(); |
| 713 | final TaskRecord topTask = topTask(); |
| 714 | final ActivityStack splitScreenStack = display.getSplitScreenPrimaryStack(); |
Evan Rosky | 9ba524e | 2018-01-03 16:27:56 -0800 | [diff] [blame] | 715 | int windowingMode = preferredWindowingMode; |
Evan Rosky | 1047574 | 2018-09-05 19:02:48 -0700 | [diff] [blame] | 716 | if (preferredWindowingMode == WINDOWING_MODE_UNDEFINED |
| 717 | && isTransientWindowingMode(currentMode)) { |
| 718 | // Leaving a transient mode. Interpret UNDEFINED as "restore" |
| 719 | windowingMode = mRestoreOverrideWindowingMode; |
| 720 | } |
| 721 | mTmpOptions.setLaunchWindowingMode(windowingMode); |
| 722 | |
Wale Ogunwale | 1dbc5c8 | 2017-12-08 08:12:20 -0800 | [diff] [blame] | 723 | // Need to make sure windowing mode is supported. If we in the process of creating the stack |
| 724 | // 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] | 725 | if (!creating) { |
| 726 | windowingMode = display.validateWindowingMode(windowingMode, |
| 727 | null /* ActivityRecord */, topTask, getActivityType()); |
| 728 | } |
| 729 | if (splitScreenStack == this |
| 730 | && windowingMode == WINDOWING_MODE_SPLIT_SCREEN_SECONDARY) { |
| 731 | // Resolution to split-screen secondary for the primary split-screen stack means |
Evan Rosky | 1047574 | 2018-09-05 19:02:48 -0700 | [diff] [blame] | 732 | // we want to leave split-screen mode. |
| 733 | windowingMode = mRestoreOverrideWindowingMode; |
Wale Ogunwale | 30e441d | 2017-11-09 08:28:45 -0800 | [diff] [blame] | 734 | } |
| 735 | |
Wale Ogunwale | ac36e4d | 2017-11-29 13:30:26 -0800 | [diff] [blame] | 736 | final boolean alreadyInSplitScreenMode = display.hasSplitScreenPrimaryStack(); |
| 737 | |
Wale Ogunwale | 1dbc5c8 | 2017-12-08 08:12:20 -0800 | [diff] [blame] | 738 | // Don't send non-resizeable notifications if the windowing mode changed was a side effect |
| 739 | // of us entering split-screen mode. |
| 740 | final boolean sendNonResizeableNotification = !enteringSplitScreenMode; |
Wale Ogunwale | 30e441d | 2017-11-09 08:28:45 -0800 | [diff] [blame] | 741 | // 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] | 742 | if (alreadyInSplitScreenMode && windowingMode == WINDOWING_MODE_FULLSCREEN |
| 743 | && sendNonResizeableNotification && isActivityTypeStandardOrUndefined()) { |
| 744 | final boolean preferredSplitScreen = |
| 745 | preferredWindowingMode == WINDOWING_MODE_SPLIT_SCREEN_PRIMARY |
| 746 | || preferredWindowingMode == WINDOWING_MODE_SPLIT_SCREEN_SECONDARY; |
| 747 | if (preferredSplitScreen || creating) { |
| 748 | // Looks like we can't launch in split screen mode or the stack we are launching |
| 749 | // doesn't support split-screen mode, go ahead an dismiss split-screen and display a |
| 750 | // warning toast about it. |
Wale Ogunwale | 5fa8a8c | 2018-05-08 13:43:21 -0700 | [diff] [blame] | 751 | mService.getTaskChangeNotificationController().notifyActivityDismissingDockedStack(); |
Evan Rosky | c5abbd8 | 2018-10-05 16:02:19 -0700 | [diff] [blame] | 752 | final ActivityStack primarySplitStack = display.getSplitScreenPrimaryStack(); |
Tiger Huang | 6dcbee6 | 2019-02-20 21:45:55 +0800 | [diff] [blame] | 753 | primarySplitStack.setWindowingModeInSurfaceTransaction(WINDOWING_MODE_UNDEFINED, |
Andrii Kulian | 9da138a | 2018-04-24 17:12:44 -0700 | [diff] [blame] | 754 | false /* animate */, false /* showRecents */, |
Evan Rosky | c5abbd8 | 2018-10-05 16:02:19 -0700 | [diff] [blame] | 755 | false /* enteringSplitScreenMode */, true /* deferEnsuringVisibility */, |
| 756 | primarySplitStack == this ? creating : false); |
Wale Ogunwale | 30e441d | 2017-11-09 08:28:45 -0800 | [diff] [blame] | 757 | } |
| 758 | } |
| 759 | |
| 760 | if (currentMode == windowingMode) { |
Evan Rosky | 1047574 | 2018-09-05 19:02:48 -0700 | [diff] [blame] | 761 | // You are already in the window mode, so we can skip most of the work below. However, |
| 762 | // it's possible that we have inherited the current windowing mode from a parent. So, |
| 763 | // fulfill this method's contract by setting the override mode directly. |
Evan Rosky | dfe3da7 | 2018-10-26 17:21:06 -0700 | [diff] [blame] | 764 | getRequestedOverrideConfiguration().windowConfiguration.setWindowingMode(windowingMode); |
Wale Ogunwale | 30e441d | 2017-11-09 08:28:45 -0800 | [diff] [blame] | 765 | return; |
| 766 | } |
| 767 | |
| 768 | final WindowManagerService wm = mService.mWindowManager; |
| 769 | final ActivityRecord topActivity = getTopActivity(); |
| 770 | |
Evan Rosky | 1047574 | 2018-09-05 19:02:48 -0700 | [diff] [blame] | 771 | // For now, assume that the Stack's windowing mode is what will actually be used |
| 772 | // by it's activities. In the future, there may be situations where this doesn't |
| 773 | // happen; so at that point, this message will need to handle that. |
| 774 | int likelyResolvedMode = windowingMode; |
| 775 | if (windowingMode == WINDOWING_MODE_UNDEFINED) { |
| 776 | final ConfigurationContainer parent = getParent(); |
| 777 | likelyResolvedMode = parent != null ? parent.getWindowingMode() |
| 778 | : WINDOWING_MODE_FULLSCREEN; |
| 779 | } |
| 780 | if (sendNonResizeableNotification && likelyResolvedMode != WINDOWING_MODE_FULLSCREEN |
Wale Ogunwale | df262f5 | 2017-12-07 18:17:12 -0800 | [diff] [blame] | 781 | && topActivity != null && topActivity.isNonResizableOrForcedResizable() |
| 782 | && !topActivity.noDisplay) { |
Wale Ogunwale | 30e441d | 2017-11-09 08:28:45 -0800 | [diff] [blame] | 783 | // Inform the user that they are starting an app that may not work correctly in |
| 784 | // multi-window mode. |
| 785 | final String packageName = topActivity.appInfo.packageName; |
Wale Ogunwale | 5fa8a8c | 2018-05-08 13:43:21 -0700 | [diff] [blame] | 786 | mService.getTaskChangeNotificationController().notifyActivityForcedResizable( |
Wale Ogunwale | 30e441d | 2017-11-09 08:28:45 -0800 | [diff] [blame] | 787 | topTask.taskId, FORCED_RESIZEABLE_REASON_SPLIT_SCREEN, packageName); |
| 788 | } |
| 789 | |
| 790 | wm.deferSurfaceLayout(); |
| 791 | try { |
| 792 | if (!animate && topActivity != null) { |
Jorim Jaggi | fa9ed96 | 2018-01-25 00:16:49 +0100 | [diff] [blame] | 793 | mStackSupervisor.mNoAnimActivities.add(topActivity); |
Wale Ogunwale | 30e441d | 2017-11-09 08:28:45 -0800 | [diff] [blame] | 794 | } |
| 795 | super.setWindowingMode(windowingMode); |
Evan Rosky | 7d0705f | 2018-07-30 12:30:13 -0700 | [diff] [blame] | 796 | // setWindowingMode triggers an onConfigurationChanged cascade which can result in a |
| 797 | // different resolved windowing mode (usually when preferredWindowingMode is UNDEFINED). |
Evan Rosky | 9ba524e | 2018-01-03 16:27:56 -0800 | [diff] [blame] | 798 | windowingMode = getWindowingMode(); |
Wale Ogunwale | 30e441d | 2017-11-09 08:28:45 -0800 | [diff] [blame] | 799 | |
Wale Ogunwale | 1dbc5c8 | 2017-12-08 08:12:20 -0800 | [diff] [blame] | 800 | if (creating) { |
Wale Ogunwale | 30e441d | 2017-11-09 08:28:45 -0800 | [diff] [blame] | 801 | // Nothing else to do if we don't have a window container yet. E.g. call from ctor. |
| 802 | return; |
| 803 | } |
| 804 | |
| 805 | if (windowingMode == WINDOWING_MODE_PINNED || currentMode == WINDOWING_MODE_PINNED) { |
| 806 | // TODO: Need to remove use of PinnedActivityStack for this to be supported. |
| 807 | // NOTE: Need to ASS.scheduleUpdatePictureInPictureModeIfNeeded() in |
| 808 | // setWindowModeUnchecked() when this support is added. See TaskRecord.reparent() |
| 809 | throw new IllegalArgumentException( |
| 810 | "Changing pinned windowing mode not currently supported"); |
| 811 | } |
| 812 | |
| 813 | if (windowingMode == WINDOWING_MODE_SPLIT_SCREEN_PRIMARY && splitScreenStack != null) { |
| 814 | // We already have a split-screen stack in this display, so just move the tasks over. |
| 815 | // TODO: Figure-out how to do all the stuff in |
| 816 | // AMS.setTaskWindowingModeSplitScreenPrimary |
| 817 | throw new IllegalArgumentException("Setting primary split-screen windowing mode" |
| 818 | + " while there is already one isn't currently supported"); |
| 819 | //return; |
| 820 | } |
Evan Rosky | 1047574 | 2018-09-05 19:02:48 -0700 | [diff] [blame] | 821 | if (isTransientWindowingMode(windowingMode) && !isTransientWindowingMode(currentMode)) { |
| 822 | mRestoreOverrideWindowingMode = currentOverrideMode; |
| 823 | } |
Wale Ogunwale | 30e441d | 2017-11-09 08:28:45 -0800 | [diff] [blame] | 824 | |
| 825 | mTmpRect2.setEmpty(); |
| 826 | if (windowingMode != WINDOWING_MODE_FULLSCREEN) { |
Yunfan Chen | 279f558 | 2018-12-12 15:24:50 -0800 | [diff] [blame] | 827 | if (mTaskStack.matchParentBounds()) { |
| 828 | mTmpRect2.setEmpty(); |
| 829 | } else { |
| 830 | mTaskStack.getRawBounds(mTmpRect2); |
| 831 | } |
Wale Ogunwale | 30e441d | 2017-11-09 08:28:45 -0800 | [diff] [blame] | 832 | } |
| 833 | |
Evan Rosky | dfe3da7 | 2018-10-26 17:21:06 -0700 | [diff] [blame] | 834 | if (!Objects.equals(getRequestedOverrideBounds(), mTmpRect2)) { |
Wale Ogunwale | 30e441d | 2017-11-09 08:28:45 -0800 | [diff] [blame] | 835 | resize(mTmpRect2, null /* tempTaskBounds */, null /* tempTaskInsetBounds */); |
| 836 | } |
| 837 | } finally { |
Wale Ogunwale | c59b4f6 | 2017-11-30 11:05:43 -0800 | [diff] [blame] | 838 | if (showRecents && !alreadyInSplitScreenMode && mDisplayId == DEFAULT_DISPLAY |
Wale Ogunwale | 30e441d | 2017-11-09 08:28:45 -0800 | [diff] [blame] | 839 | && windowingMode == WINDOWING_MODE_SPLIT_SCREEN_PRIMARY) { |
| 840 | // Make sure recents stack exist when creating a dock stack as it normally needs to |
| 841 | // be on the other side of the docked stack and we make visibility decisions based |
| 842 | // on that. |
| 843 | // TODO: This is only here to help out with the case where recents stack doesn't |
| 844 | // exist yet. For that case the initial size of the split-screen stack will be the |
| 845 | // the one where the home stack is visible since recents isn't visible yet, but the |
| 846 | // divider will be off. I think we should just make the initial bounds that of home |
| 847 | // so that the divider matches and remove this logic. |
Winson Chung | c167427 | 2018-02-21 10:15:17 -0800 | [diff] [blame] | 848 | // TODO: This is currently only called when entering split-screen while in another |
| 849 | // task, and from the tests |
Matthew Ng | 3030712 | 2018-04-13 11:36:34 -0700 | [diff] [blame] | 850 | // TODO (b/78247419): Check if launcher and overview are same then move home stack |
| 851 | // instead of recents stack. Then fix the rotation animation from fullscreen to |
| 852 | // minimized mode |
Wale Ogunwale | 1dbc5c8 | 2017-12-08 08:12:20 -0800 | [diff] [blame] | 853 | final ActivityStack recentStack = display.getOrCreateStack( |
| 854 | WINDOWING_MODE_SPLIT_SCREEN_SECONDARY, ACTIVITY_TYPE_RECENTS, |
| 855 | true /* onTop */); |
| 856 | recentStack.moveToFront("setWindowingMode"); |
Wale Ogunwale | 30e441d | 2017-11-09 08:28:45 -0800 | [diff] [blame] | 857 | // If task moved to docked stack - show recents if needed. |
Winson Chung | dff7a73 | 2017-12-11 12:17:06 -0800 | [diff] [blame] | 858 | mService.mWindowManager.showRecentApps(); |
Wale Ogunwale | 30e441d | 2017-11-09 08:28:45 -0800 | [diff] [blame] | 859 | } |
| 860 | wm.continueSurfaceLayout(); |
| 861 | } |
| 862 | |
Andrii Kulian | 9da138a | 2018-04-24 17:12:44 -0700 | [diff] [blame] | 863 | if (!deferEnsuringVisibility) { |
Wale Ogunwale | d32da47 | 2018-11-16 07:19:28 -0800 | [diff] [blame] | 864 | mRootActivityContainer.ensureActivitiesVisible(null, 0, PRESERVE_WINDOWS); |
| 865 | mRootActivityContainer.resumeFocusedStacksTopActivities(); |
Wale Ogunwale | 1dbc5c8 | 2017-12-08 08:12:20 -0800 | [diff] [blame] | 866 | } |
Wale Ogunwale | 30e441d | 2017-11-09 08:28:45 -0800 | [diff] [blame] | 867 | } |
| 868 | |
| 869 | @Override |
Wale Ogunwale | ab5de37 | 2017-10-18 06:46:31 -0700 | [diff] [blame] | 870 | public boolean isCompatible(int windowingMode, int activityType) { |
| 871 | // TODO: Should we just move this to ConfigurationContainer? |
| 872 | if (activityType == ACTIVITY_TYPE_UNDEFINED) { |
| 873 | // Undefined activity types end up in a standard stack once the stack is created on a |
| 874 | // display, so they should be considered compatible. |
| 875 | activityType = ACTIVITY_TYPE_STANDARD; |
| 876 | } |
Wale Ogunwale | ab5de37 | 2017-10-18 06:46:31 -0700 | [diff] [blame] | 877 | return super.isCompatible(windowingMode, activityType); |
| 878 | } |
| 879 | |
Andrii Kulian | 839def9 | 2016-11-02 10:58:58 -0700 | [diff] [blame] | 880 | /** 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] | 881 | void reparent(ActivityDisplay activityDisplay, boolean onTop, boolean displayRemoved) { |
Wale Ogunwale | 7e1f5f5 | 2017-10-18 15:19:59 -0700 | [diff] [blame] | 882 | // TODO: We should probably resolve the windowing mode for the stack on the new display here |
| 883 | // 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] | 884 | removeFromDisplay(); |
Winson Chung | f34c602 | 2018-01-25 09:44:30 -0800 | [diff] [blame] | 885 | // Reparent the window container before we try to update the position when adding it to |
| 886 | // the new display below |
Wale Ogunwale | 1666e31 | 2016-12-16 11:27:18 -0800 | [diff] [blame] | 887 | mTmpRect2.setEmpty(); |
Yunfan Chen | 279f558 | 2018-12-12 15:24:50 -0800 | [diff] [blame] | 888 | if (mTaskStack == null) { |
| 889 | // TODO: Remove after unification. |
| 890 | Log.w(TAG, "Task stack is not valid when reparenting."); |
| 891 | } else { |
| 892 | mTaskStack.reparent(activityDisplay.mDisplayId, mTmpRect2, onTop); |
| 893 | } |
Evan Rosky | c5abbd8 | 2018-10-05 16:02:19 -0700 | [diff] [blame] | 894 | setBounds(mTmpRect2.isEmpty() ? null : mTmpRect2); |
| 895 | activityDisplay.addChild(this, onTop ? POSITION_TOP : POSITION_BOTTOM); |
Riddle Hsu | 402b440 | 2018-11-06 17:23:15 +0800 | [diff] [blame] | 896 | if (!displayRemoved) { |
| 897 | postReparent(); |
| 898 | } |
| 899 | } |
| 900 | |
| 901 | /** Resume next focusable stack after reparenting to another display. */ |
| 902 | void postReparent() { |
Wale Ogunwale | 66e1685 | 2017-10-19 13:35:52 -0700 | [diff] [blame] | 903 | adjustFocusToNextFocusableStack("reparent", true /* allowFocusSelf */); |
Wale Ogunwale | d32da47 | 2018-11-16 07:19:28 -0800 | [diff] [blame] | 904 | mRootActivityContainer.resumeFocusedStacksTopActivities(); |
Andrii Kulian | 51c1b67 | 2017-04-07 18:39:32 -0700 | [diff] [blame] | 905 | // Update visibility of activities before notifying WM. This way it won't try to resize |
| 906 | // windows that are no longer visible. |
Wale Ogunwale | d32da47 | 2018-11-16 07:19:28 -0800 | [diff] [blame] | 907 | mRootActivityContainer.ensureActivitiesVisible(null /* starting */, 0 /* configChanges */, |
Andrii Kulian | 51c1b67 | 2017-04-07 18:39:32 -0700 | [diff] [blame] | 908 | !PRESERVE_WINDOWS); |
Andrii Kulian | 839def9 | 2016-11-02 10:58:58 -0700 | [diff] [blame] | 909 | } |
| 910 | |
| 911 | /** |
Andrii Kulian | 839def9 | 2016-11-02 10:58:58 -0700 | [diff] [blame] | 912 | * Updates the inner state of the stack to remove it from its current parent, so it can be |
| 913 | * either destroyed completely or re-parented. |
| 914 | */ |
| 915 | private void removeFromDisplay() { |
Wale Ogunwale | 9dcf946 | 2017-09-19 15:13:01 -0700 | [diff] [blame] | 916 | final ActivityDisplay display = getDisplay(); |
| 917 | if (display != null) { |
| 918 | display.removeChild(this); |
| 919 | } |
| 920 | mDisplayId = INVALID_DISPLAY; |
Andrii Kulian | 839def9 | 2016-11-02 10:58:58 -0700 | [diff] [blame] | 921 | } |
| 922 | |
| 923 | /** Removes the stack completely. Also calls WindowManager to do the same on its side. */ |
| 924 | void remove() { |
| 925 | removeFromDisplay(); |
Yunfan Chen | 279f558 | 2018-12-12 15:24:50 -0800 | [diff] [blame] | 926 | if (mTaskStack != null) { |
| 927 | mTaskStack.removeIfPossible(); |
| 928 | mTaskStack = null; |
| 929 | } |
Andrii Kulian | 6d6fb40 | 2016-10-26 16:15:25 -0700 | [diff] [blame] | 930 | onParentChanged(); |
Filip Gruszczynski | e5390e7 | 2015-08-18 16:39:00 -0700 | [diff] [blame] | 931 | } |
| 932 | |
Wale Ogunwale | 9dcf946 | 2017-09-19 15:13:01 -0700 | [diff] [blame] | 933 | ActivityDisplay getDisplay() { |
Wale Ogunwale | d32da47 | 2018-11-16 07:19:28 -0800 | [diff] [blame] | 934 | return mRootActivityContainer.getActivityDisplay(mDisplayId); |
Andrii Kulian | 94e82d9b0 | 2017-07-13 15:33:06 -0700 | [diff] [blame] | 935 | } |
| 936 | |
Matthew Ng | aa2b620 | 2017-02-10 14:48:21 -0800 | [diff] [blame] | 937 | /** |
Evan Rosky | c5abbd8 | 2018-10-05 16:02:19 -0700 | [diff] [blame] | 938 | * @see #getStackDockedModeBounds(Rect, Rect, Rect, Rect) |
Matthew Ng | aa2b620 | 2017-02-10 14:48:21 -0800 | [diff] [blame] | 939 | */ |
Evan Rosky | c5abbd8 | 2018-10-05 16:02:19 -0700 | [diff] [blame] | 940 | void getStackDockedModeBounds(Rect dockedBounds, Rect currentTempTaskBounds, |
| 941 | Rect outStackBounds, Rect outTempTaskBounds) { |
Yunfan Chen | 279f558 | 2018-12-12 15:24:50 -0800 | [diff] [blame] | 942 | if (mTaskStack != null) { |
| 943 | mTaskStack.getStackDockedModeBoundsLocked(getParent().getConfiguration(), dockedBounds, |
| 944 | currentTempTaskBounds, outStackBounds, outTempTaskBounds); |
| 945 | } else { |
| 946 | outStackBounds.setEmpty(); |
| 947 | outTempTaskBounds.setEmpty(); |
| 948 | } |
Wale Ogunwale | 1666e31 | 2016-12-16 11:27:18 -0800 | [diff] [blame] | 949 | } |
| 950 | |
| 951 | void prepareFreezingTaskBounds() { |
Yunfan Chen | 279f558 | 2018-12-12 15:24:50 -0800 | [diff] [blame] | 952 | if (mTaskStack != null) { |
| 953 | // TODO: This cannot be false after unification. |
| 954 | mTaskStack.prepareFreezingTaskBounds(); |
| 955 | } |
Wale Ogunwale | 1666e31 | 2016-12-16 11:27:18 -0800 | [diff] [blame] | 956 | } |
| 957 | |
Wale Ogunwale | 1666e31 | 2016-12-16 11:27:18 -0800 | [diff] [blame] | 958 | void getWindowContainerBounds(Rect outBounds) { |
Yunfan Chen | 279f558 | 2018-12-12 15:24:50 -0800 | [diff] [blame] | 959 | if (mTaskStack != null) { |
| 960 | mTaskStack.getBounds(outBounds); |
Winson Chung | b00dc5e | 2017-01-25 09:44:25 -0800 | [diff] [blame] | 961 | return; |
Wale Ogunwale | 1666e31 | 2016-12-16 11:27:18 -0800 | [diff] [blame] | 962 | } |
| 963 | outBounds.setEmpty(); |
| 964 | } |
| 965 | |
Wale Ogunwale | 1666e31 | 2016-12-16 11:27:18 -0800 | [diff] [blame] | 966 | void positionChildWindowContainerAtTop(TaskRecord child) { |
Yunfan Chen | 279f558 | 2018-12-12 15:24:50 -0800 | [diff] [blame] | 967 | if (mTaskStack != null) { |
| 968 | // TODO: Remove after unification. This cannot be false after that. |
| 969 | mTaskStack.positionChildAtTop(child.getTask(), true /* includingParents */); |
| 970 | } |
Wale Ogunwale | 1666e31 | 2016-12-16 11:27:18 -0800 | [diff] [blame] | 971 | } |
| 972 | |
Riddle Hsu | 86cb7de | 2018-08-13 23:29:58 +0800 | [diff] [blame] | 973 | void positionChildWindowContainerAtBottom(TaskRecord child) { |
Riddle Hsu | 138ef93 | 2018-10-26 17:12:06 +0800 | [diff] [blame] | 974 | // If there are other focusable stacks on the display, the z-order of the display should not |
| 975 | // be changed just because a task was placed at the bottom. E.g. if it is moving the topmost |
| 976 | // task to bottom, the next focusable stack on the same display should be focused. |
| 977 | final ActivityStack nextFocusableStack = getDisplay().getNextFocusableStack( |
| 978 | child.getStack(), true /* ignoreCurrent */); |
Yunfan Chen | 279f558 | 2018-12-12 15:24:50 -0800 | [diff] [blame] | 979 | if (mTaskStack != null) { |
| 980 | // TODO: Remove after unification. This cannot be false after that. |
| 981 | mTaskStack.positionChildAtBottom(child.getTask(), |
| 982 | nextFocusableStack == null /* includingParents */); |
| 983 | } |
Riddle Hsu | 86cb7de | 2018-08-13 23:29:58 +0800 | [diff] [blame] | 984 | } |
| 985 | |
Jorim Jaggi | 192086e | 2016-03-11 17:17:03 +0100 | [diff] [blame] | 986 | /** |
Winson Chung | 8bca9e4 | 2017-04-16 15:59:43 -0700 | [diff] [blame] | 987 | * Returns whether to defer the scheduling of the multi-window mode. |
| 988 | */ |
| 989 | boolean deferScheduleMultiWindowModeChanged() { |
Yunfan Chen | 279f558 | 2018-12-12 15:24:50 -0800 | [diff] [blame] | 990 | if (inPinnedWindowingMode()) { |
| 991 | // For the pinned stack, the deferring of the multi-window mode changed is tied to the |
| 992 | // transition animation into picture-in-picture, and is called once the animation |
| 993 | // completes, or is interrupted in a way that would leave the stack in a non-fullscreen |
| 994 | // state. |
| 995 | // @see BoundsAnimationController |
| 996 | // @see BoundsAnimationControllerTests |
| 997 | if (getTaskStack() == null) return false; |
| 998 | return getTaskStack().deferScheduleMultiWindowModeChanged(); |
| 999 | } |
Winson Chung | 8bca9e4 | 2017-04-16 15:59:43 -0700 | [diff] [blame] | 1000 | return false; |
| 1001 | } |
| 1002 | |
| 1003 | /** |
Jorim Jaggi | 192086e | 2016-03-11 17:17:03 +0100 | [diff] [blame] | 1004 | * Defers updating the bounds of the stack. If the stack was resized/repositioned while |
| 1005 | * deferring, the bounds will update in {@link #continueUpdateBounds()}. |
| 1006 | */ |
| 1007 | void deferUpdateBounds() { |
| 1008 | if (!mUpdateBoundsDeferred) { |
| 1009 | mUpdateBoundsDeferred = true; |
| 1010 | mUpdateBoundsDeferredCalled = false; |
| 1011 | } |
| 1012 | } |
| 1013 | |
| 1014 | /** |
| 1015 | * Continues updating bounds after updates have been deferred. If there was a resize attempt |
| 1016 | * between {@link #deferUpdateBounds()} and {@link #continueUpdateBounds()}, the stack will |
| 1017 | * be resized to that bounds. |
| 1018 | */ |
| 1019 | void continueUpdateBounds() { |
Evan Rosky | 1ac8446 | 2018-11-13 11:25:30 -0800 | [diff] [blame] | 1020 | if (mUpdateBoundsDeferred) { |
| 1021 | mUpdateBoundsDeferred = false; |
| 1022 | if (mUpdateBoundsDeferredCalled) { |
| 1023 | setTaskBounds(mDeferredBounds); |
| 1024 | setBounds(mDeferredBounds); |
| 1025 | } |
| 1026 | if (mUpdateDisplayedBoundsDeferredCalled) { |
| 1027 | setTaskDisplayedBounds(mDeferredDisplayedBounds); |
| 1028 | } |
Jorim Jaggi | 192086e | 2016-03-11 17:17:03 +0100 | [diff] [blame] | 1029 | } |
| 1030 | } |
| 1031 | |
Evan Rosky | 1ac8446 | 2018-11-13 11:25:30 -0800 | [diff] [blame] | 1032 | boolean updateBoundsAllowed(Rect bounds) { |
Jorim Jaggi | 192086e | 2016-03-11 17:17:03 +0100 | [diff] [blame] | 1033 | if (!mUpdateBoundsDeferred) { |
| 1034 | return true; |
| 1035 | } |
| 1036 | if (bounds != null) { |
| 1037 | mDeferredBounds.set(bounds); |
| 1038 | } else { |
| 1039 | mDeferredBounds.setEmpty(); |
| 1040 | } |
Jorim Jaggi | 192086e | 2016-03-11 17:17:03 +0100 | [diff] [blame] | 1041 | mUpdateBoundsDeferredCalled = true; |
| 1042 | return false; |
| 1043 | } |
| 1044 | |
Evan Rosky | 1ac8446 | 2018-11-13 11:25:30 -0800 | [diff] [blame] | 1045 | boolean updateDisplayedBoundsAllowed(Rect bounds) { |
| 1046 | if (!mUpdateBoundsDeferred) { |
| 1047 | return true; |
| 1048 | } |
| 1049 | if (bounds != null) { |
| 1050 | mDeferredDisplayedBounds.set(bounds); |
| 1051 | } else { |
| 1052 | mDeferredDisplayedBounds.setEmpty(); |
| 1053 | } |
| 1054 | mUpdateDisplayedBoundsDeferredCalled = true; |
| 1055 | return false; |
| 1056 | } |
| 1057 | |
Bryce Lee | f3c6a47 | 2017-11-14 14:53:06 -0800 | [diff] [blame] | 1058 | @Override |
| 1059 | public int setBounds(Rect bounds) { |
| 1060 | return super.setBounds(!inMultiWindowMode() ? null : bounds); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 1061 | } |
Craig Mautner | 5962b12 | 2012-10-05 14:45:52 -0700 | [diff] [blame] | 1062 | |
Wale Ogunwale | 42f07d9 | 2017-05-01 21:32:58 -0700 | [diff] [blame] | 1063 | ActivityRecord topRunningActivityLocked() { |
Winson Chung | 3f103eb | 2017-04-12 21:53:59 -0700 | [diff] [blame] | 1064 | return topRunningActivityLocked(false /* focusableOnly */); |
| 1065 | } |
| 1066 | |
Jorim Jaggi | ea039a8 | 2017-08-02 14:37:49 +0200 | [diff] [blame] | 1067 | void getAllRunningVisibleActivitiesLocked(ArrayList<ActivityRecord> outActivities) { |
| 1068 | outActivities.clear(); |
| 1069 | for (int taskNdx = mTaskHistory.size() - 1; taskNdx >= 0; --taskNdx) { |
| 1070 | mTaskHistory.get(taskNdx).getAllRunningVisibleActivitiesLocked(outActivities); |
| 1071 | } |
| 1072 | } |
| 1073 | |
Andrii Kulian | 52d255c | 2018-07-13 11:32:19 -0700 | [diff] [blame] | 1074 | ActivityRecord topRunningActivityLocked(boolean focusableOnly) { |
Craig Mautner | d74f7d7 | 2013-02-26 13:41:02 -0800 | [diff] [blame] | 1075 | for (int taskNdx = mTaskHistory.size() - 1; taskNdx >= 0; --taskNdx) { |
Filip Gruszczynski | 3e85ba2 | 2015-10-05 22:48:30 -0700 | [diff] [blame] | 1076 | ActivityRecord r = mTaskHistory.get(taskNdx).topRunningActivityLocked(); |
Winson Chung | 3f103eb | 2017-04-12 21:53:59 -0700 | [diff] [blame] | 1077 | if (r != null && (!focusableOnly || r.isFocusable())) { |
Craig Mautner | 6b74cb5 | 2013-09-27 17:02:21 -0700 | [diff] [blame] | 1078 | return r; |
Craig Mautner | 11bf9a5 | 2013-02-19 14:08:51 -0800 | [diff] [blame] | 1079 | } |
| 1080 | } |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 1081 | return null; |
| 1082 | } |
| 1083 | |
Wale Ogunwale | 42f07d9 | 2017-05-01 21:32:58 -0700 | [diff] [blame] | 1084 | ActivityRecord topRunningNonOverlayTaskActivity() { |
| 1085 | for (int taskNdx = mTaskHistory.size() - 1; taskNdx >= 0; --taskNdx) { |
| 1086 | final TaskRecord task = mTaskHistory.get(taskNdx); |
| 1087 | final ArrayList<ActivityRecord> activities = task.mActivities; |
| 1088 | for (int activityNdx = activities.size() - 1; activityNdx >= 0; --activityNdx) { |
| 1089 | final ActivityRecord r = activities.get(activityNdx); |
| 1090 | if (!r.finishing && !r.mTaskOverlay) { |
| 1091 | return r; |
| 1092 | } |
| 1093 | } |
| 1094 | } |
| 1095 | return null; |
| 1096 | } |
| 1097 | |
| 1098 | ActivityRecord topRunningNonDelayedActivityLocked(ActivityRecord notTop) { |
Craig Mautner | d74f7d7 | 2013-02-26 13:41:02 -0800 | [diff] [blame] | 1099 | for (int taskNdx = mTaskHistory.size() - 1; taskNdx >= 0; --taskNdx) { |
| 1100 | final TaskRecord task = mTaskHistory.get(taskNdx); |
Craig Mautner | 11bf9a5 | 2013-02-19 14:08:51 -0800 | [diff] [blame] | 1101 | final ArrayList<ActivityRecord> activities = task.mActivities; |
Craig Mautner | d74f7d7 | 2013-02-26 13:41:02 -0800 | [diff] [blame] | 1102 | for (int activityNdx = activities.size() - 1; activityNdx >= 0; --activityNdx) { |
| 1103 | ActivityRecord r = activities.get(activityNdx); |
Chong Zhang | 8776197 | 2016-08-22 13:53:24 -0700 | [diff] [blame] | 1104 | if (!r.finishing && !r.delayedResume && r != notTop && r.okToShowLocked()) { |
Craig Mautner | 11bf9a5 | 2013-02-19 14:08:51 -0800 | [diff] [blame] | 1105 | return r; |
| 1106 | } |
| 1107 | } |
| 1108 | } |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 1109 | return null; |
| 1110 | } |
| 1111 | |
| 1112 | /** |
Wale Ogunwale | d32da47 | 2018-11-16 07:19:28 -0800 | [diff] [blame] | 1113 | * This is a simplified version of topRunningActivity that provides a number of |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 1114 | * 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] | 1115 | * |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 1116 | * @param token If non-null, any history records matching this token will be skipped. |
| 1117 | * @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] | 1118 | * |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 1119 | * @return Returns the HistoryRecord of the next activity on the stack. |
| 1120 | */ |
| 1121 | final ActivityRecord topRunningActivityLocked(IBinder token, int taskId) { |
Craig Mautner | 11bf9a5 | 2013-02-19 14:08:51 -0800 | [diff] [blame] | 1122 | for (int taskNdx = mTaskHistory.size() - 1; taskNdx >= 0; --taskNdx) { |
| 1123 | TaskRecord task = mTaskHistory.get(taskNdx); |
| 1124 | if (task.taskId == taskId) { |
| 1125 | continue; |
| 1126 | } |
| 1127 | ArrayList<ActivityRecord> activities = task.mActivities; |
| 1128 | for (int i = activities.size() - 1; i >= 0; --i) { |
| 1129 | final ActivityRecord r = activities.get(i); |
| 1130 | // Note: the taskId check depends on real taskId fields being non-zero |
Chong Zhang | 8776197 | 2016-08-22 13:53:24 -0700 | [diff] [blame] | 1131 | if (!r.finishing && (token != r.appToken) && r.okToShowLocked()) { |
Craig Mautner | 11bf9a5 | 2013-02-19 14:08:51 -0800 | [diff] [blame] | 1132 | return r; |
| 1133 | } |
| 1134 | } |
| 1135 | } |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 1136 | return null; |
| 1137 | } |
| 1138 | |
Wale Ogunwale | 30e441d | 2017-11-09 08:28:45 -0800 | [diff] [blame] | 1139 | ActivityRecord getTopActivity() { |
Craig Mautner | 8849a5e | 2013-04-02 16:41:03 -0700 | [diff] [blame] | 1140 | for (int taskNdx = mTaskHistory.size() - 1; taskNdx >= 0; --taskNdx) { |
Wale Ogunwale | 30e441d | 2017-11-09 08:28:45 -0800 | [diff] [blame] | 1141 | final ActivityRecord r = mTaskHistory.get(taskNdx).getTopActivity(); |
| 1142 | if (r != null) { |
| 1143 | return r; |
Craig Mautner | 8849a5e | 2013-04-02 16:41:03 -0700 | [diff] [blame] | 1144 | } |
| 1145 | } |
Craig Mautner | de4ef02 | 2013-04-07 19:01:33 -0700 | [diff] [blame] | 1146 | return null; |
Craig Mautner | 8849a5e | 2013-04-02 16:41:03 -0700 | [diff] [blame] | 1147 | } |
| 1148 | |
Craig Mautner | 9e14d0f | 2013-05-01 11:26:09 -0700 | [diff] [blame] | 1149 | final TaskRecord topTask() { |
| 1150 | final int size = mTaskHistory.size(); |
| 1151 | if (size > 0) { |
| 1152 | return mTaskHistory.get(size - 1); |
| 1153 | } |
| 1154 | return null; |
| 1155 | } |
| 1156 | |
Wale Ogunwale | 30e441d | 2017-11-09 08:28:45 -0800 | [diff] [blame] | 1157 | private TaskRecord bottomTask() { |
Winson Chung | 1cebea6 | 2017-06-26 17:22:27 -0700 | [diff] [blame] | 1158 | if (mTaskHistory.isEmpty()) { |
| 1159 | return null; |
| 1160 | } |
| 1161 | return mTaskHistory.get(0); |
| 1162 | } |
| 1163 | |
Craig Mautner | d232895 | 2013-03-05 12:46:26 -0800 | [diff] [blame] | 1164 | TaskRecord taskForIdLocked(int id) { |
| 1165 | for (int taskNdx = mTaskHistory.size() - 1; taskNdx >= 0; --taskNdx) { |
| 1166 | final TaskRecord task = mTaskHistory.get(taskNdx); |
| 1167 | if (task.taskId == id) { |
| 1168 | return task; |
Craig Mautner | 5d9c7be | 2013-02-15 14:02:56 -0800 | [diff] [blame] | 1169 | } |
| 1170 | } |
Dianne Hackborn | ce86ba8 | 2011-07-13 19:33:41 -0700 | [diff] [blame] | 1171 | return null; |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 1172 | } |
| 1173 | |
Craig Mautner | d232895 | 2013-03-05 12:46:26 -0800 | [diff] [blame] | 1174 | ActivityRecord isInStackLocked(IBinder token) { |
Wale Ogunwale | 7d70117 | 2015-03-11 15:36:30 -0700 | [diff] [blame] | 1175 | final ActivityRecord r = ActivityRecord.forTokenLocked(token); |
Wale Ogunwale | 60454db | 2015-01-23 16:05:07 -0800 | [diff] [blame] | 1176 | return isInStackLocked(r); |
| 1177 | } |
| 1178 | |
| 1179 | ActivityRecord isInStackLocked(ActivityRecord r) { |
| 1180 | if (r == null) { |
| 1181 | return null; |
| 1182 | } |
Wale Ogunwale | 8b19de9 | 2018-11-29 19:58:26 -0800 | [diff] [blame] | 1183 | final TaskRecord task = r.getTaskRecord(); |
| 1184 | final ActivityStack stack = r.getActivityStack(); |
Andrii Kulian | 02b7a83 | 2016-10-06 23:11:56 -0700 | [diff] [blame] | 1185 | if (stack != null && task.mActivities.contains(r) && mTaskHistory.contains(task)) { |
| 1186 | if (stack != this) Slog.w(TAG, |
Craig Mautner | d232895 | 2013-03-05 12:46:26 -0800 | [diff] [blame] | 1187 | "Illegal state! task does not point to stack it is in."); |
Wale Ogunwale | 60454db | 2015-01-23 16:05:07 -0800 | [diff] [blame] | 1188 | return r; |
Craig Mautner | 5d9c7be | 2013-02-15 14:02:56 -0800 | [diff] [blame] | 1189 | } |
Craig Mautner | d232895 | 2013-03-05 12:46:26 -0800 | [diff] [blame] | 1190 | return null; |
Craig Mautner | 5d9c7be | 2013-02-15 14:02:56 -0800 | [diff] [blame] | 1191 | } |
| 1192 | |
Andrii Kulian | fb1bf69 | 2017-01-17 11:17:34 -0800 | [diff] [blame] | 1193 | boolean isInStackLocked(TaskRecord task) { |
| 1194 | return mTaskHistory.contains(task); |
| 1195 | } |
| 1196 | |
| 1197 | /** Checks if there are tasks with specific UID in the stack. */ |
| 1198 | boolean isUidPresent(int uid) { |
| 1199 | for (TaskRecord task : mTaskHistory) { |
David Stevens | 82ea6cb | 2017-03-03 16:18:50 -0800 | [diff] [blame] | 1200 | for (ActivityRecord r : task.mActivities) { |
| 1201 | if (r.getUid() == uid) { |
| 1202 | return true; |
| 1203 | } |
Andrii Kulian | fb1bf69 | 2017-01-17 11:17:34 -0800 | [diff] [blame] | 1204 | } |
| 1205 | } |
| 1206 | return false; |
| 1207 | } |
| 1208 | |
| 1209 | /** Get all UIDs that are present in the stack. */ |
| 1210 | void getPresentUIDs(IntArray presentUIDs) { |
| 1211 | for (TaskRecord task : mTaskHistory) { |
David Stevens | 82ea6cb | 2017-03-03 16:18:50 -0800 | [diff] [blame] | 1212 | for (ActivityRecord r : task.mActivities) { |
| 1213 | presentUIDs.add(r.getUid()); |
| 1214 | } |
Andrii Kulian | fb1bf69 | 2017-01-17 11:17:34 -0800 | [diff] [blame] | 1215 | } |
| 1216 | } |
| 1217 | |
Wale Ogunwale | 9e737db | 2018-12-17 15:42:37 -0800 | [diff] [blame] | 1218 | /** @return true if the stack can only contain one task */ |
| 1219 | boolean isSingleTaskInstance() { |
| 1220 | final ActivityDisplay display = getDisplay(); |
| 1221 | return display != null && display.isSingleTaskInstance(); |
| 1222 | } |
| 1223 | |
Winson Chung | abb433b | 2017-03-24 09:35:42 -0700 | [diff] [blame] | 1224 | final void removeActivitiesFromLRUListLocked(TaskRecord task) { |
| 1225 | for (ActivityRecord r : task.mActivities) { |
| 1226 | mLRUActivities.remove(r); |
| 1227 | } |
| 1228 | } |
| 1229 | |
Craig Mautner | 2420ead | 2013-04-01 17:13:20 -0700 | [diff] [blame] | 1230 | final boolean updateLRUListLocked(ActivityRecord r) { |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 1231 | final boolean hadit = mLRUActivities.remove(r); |
| 1232 | mLRUActivities.add(r); |
| 1233 | return hadit; |
| 1234 | } |
| 1235 | |
Matthew Ng | ae1ff4f | 2016-11-10 15:49:14 -0800 | [diff] [blame] | 1236 | final boolean isHomeOrRecentsStack() { |
Wale Ogunwale | 6827856 | 2017-09-23 17:13:55 -0700 | [diff] [blame] | 1237 | return isActivityTypeHome() || isActivityTypeRecents(); |
Matthew Ng | ae1ff4f | 2016-11-10 15:49:14 -0800 | [diff] [blame] | 1238 | } |
| 1239 | |
Craig Mautner | e0a3884 | 2013-12-16 16:14:02 -0800 | [diff] [blame] | 1240 | final boolean isOnHomeDisplay() { |
Wale Ogunwale | 9dcf946 | 2017-09-19 15:13:01 -0700 | [diff] [blame] | 1241 | return mDisplayId == DEFAULT_DISPLAY; |
Craig Mautner | e0a3884 | 2013-12-16 16:14:02 -0800 | [diff] [blame] | 1242 | } |
| 1243 | |
Wale Ogunwale | 66e1685 | 2017-10-19 13:35:52 -0700 | [diff] [blame] | 1244 | private boolean returnsToHomeStack() { |
| 1245 | return !inMultiWindowMode() |
| 1246 | && !mTaskHistory.isEmpty() |
| 1247 | && mTaskHistory.get(0).returnsToHomeStack(); |
| 1248 | } |
| 1249 | |
Wale Ogunwale | eae451e | 2015-08-04 15:20:50 -0700 | [diff] [blame] | 1250 | void moveToFront(String reason) { |
| 1251 | moveToFront(reason, null); |
| 1252 | } |
| 1253 | |
| 1254 | /** |
| 1255 | * @param reason The reason for moving the stack to the front. |
| 1256 | * @param task If non-null, the task will be moved to the top of the stack. |
| 1257 | * */ |
| 1258 | void moveToFront(String reason, TaskRecord task) { |
Wale Ogunwale | 1e60e0c | 2015-10-28 13:36:10 -0700 | [diff] [blame] | 1259 | if (!isAttached()) { |
| 1260 | return; |
| 1261 | } |
Wale Ogunwale | 925d0d1 | 2015-09-23 15:40:07 -0700 | [diff] [blame] | 1262 | |
Wale Ogunwale | bb28587 | 2018-03-01 13:05:30 -0800 | [diff] [blame] | 1263 | final ActivityDisplay display = getDisplay(); |
| 1264 | |
| 1265 | if (inSplitScreenSecondaryWindowingMode()) { |
| 1266 | // If the stack is in split-screen seconardy mode, we need to make sure we move the |
| 1267 | // primary split-screen stack forward in the case it is currently behind a fullscreen |
| 1268 | // stack so both halves of the split-screen appear on-top and the fullscreen stack isn't |
| 1269 | // cutting between them. |
| 1270 | // TODO(b/70677280): This is a workaround until we can fix as part of b/70677280. |
| 1271 | final ActivityStack topFullScreenStack = |
| 1272 | display.getTopStackInWindowingMode(WINDOWING_MODE_FULLSCREEN); |
| 1273 | if (topFullScreenStack != null) { |
| 1274 | final ActivityStack primarySplitScreenStack = display.getSplitScreenPrimaryStack(); |
| 1275 | if (display.getIndexOf(topFullScreenStack) |
| 1276 | > display.getIndexOf(primarySplitScreenStack)) { |
| 1277 | primarySplitScreenStack.moveToFront(reason + " splitScreenToTop"); |
| 1278 | } |
| 1279 | } |
| 1280 | } |
| 1281 | |
Wale Ogunwale | 66e1685 | 2017-10-19 13:35:52 -0700 | [diff] [blame] | 1282 | if (!isActivityTypeHome() && returnsToHomeStack()) { |
| 1283 | // Make sure the home stack is behind this stack since that is where we should return to |
| 1284 | // when this stack is no longer visible. |
Louis Chang | bd48dca | 2018-08-29 17:44:34 +0800 | [diff] [blame] | 1285 | display.moveHomeStackToFront(reason + " returnToHome"); |
Wale Ogunwale | 66e1685 | 2017-10-19 13:35:52 -0700 | [diff] [blame] | 1286 | } |
| 1287 | |
Riddle Hsu | bbb63c2 | 2018-10-03 12:28:29 +0800 | [diff] [blame] | 1288 | final boolean movingTask = task != null; |
| 1289 | display.positionChildAtTop(this, !movingTask /* includingParents */, reason); |
| 1290 | if (movingTask) { |
Andrii Kulian | 52d255c | 2018-07-13 11:32:19 -0700 | [diff] [blame] | 1291 | // This also moves the entire hierarchy branch to top, including parents |
Riddle Hsu | bbb63c2 | 2018-10-03 12:28:29 +0800 | [diff] [blame] | 1292 | insertTaskAtTop(task, null /* starting */); |
Wale Ogunwale | 1e60e0c | 2015-10-28 13:36:10 -0700 | [diff] [blame] | 1293 | } |
Craig Mautner | e0a3884 | 2013-12-16 16:14:02 -0800 | [diff] [blame] | 1294 | } |
| 1295 | |
Evan Rosky | 9c44817 | 2017-11-02 14:19:27 -0700 | [diff] [blame] | 1296 | /** |
| 1297 | * @param reason The reason for moving the stack to the back. |
| 1298 | * @param task If non-null, the task will be moved to the bottom of the stack. |
| 1299 | **/ |
| 1300 | void moveToBack(String reason, TaskRecord task) { |
| 1301 | if (!isAttached()) { |
| 1302 | return; |
| 1303 | } |
| 1304 | |
Bryce Lee | 8cab4a0 | 2018-01-05 09:00:49 -0800 | [diff] [blame] | 1305 | /** |
| 1306 | * The intent behind moving a primary split screen stack to the back is usually to hide |
| 1307 | * behind the home stack. Exit split screen in this case. |
| 1308 | */ |
| 1309 | if (getWindowingMode() == WINDOWING_MODE_SPLIT_SCREEN_PRIMARY) { |
Evan Rosky | 1047574 | 2018-09-05 19:02:48 -0700 | [diff] [blame] | 1310 | setWindowingMode(WINDOWING_MODE_UNDEFINED); |
Bryce Lee | 8cab4a0 | 2018-01-05 09:00:49 -0800 | [diff] [blame] | 1311 | } |
| 1312 | |
Riddle Hsu | bbb63c2 | 2018-10-03 12:28:29 +0800 | [diff] [blame] | 1313 | getDisplay().positionChildAtBottom(this, reason); |
Evan Rosky | 9c44817 | 2017-11-02 14:19:27 -0700 | [diff] [blame] | 1314 | if (task != null) { |
| 1315 | insertTaskAtBottom(task); |
Evan Rosky | 9c44817 | 2017-11-02 14:19:27 -0700 | [diff] [blame] | 1316 | } |
| 1317 | } |
| 1318 | |
Wale Ogunwale | d046a01 | 2015-12-24 13:05:59 -0800 | [diff] [blame] | 1319 | boolean isFocusable() { |
Wale Ogunwale | 4cea0f5 | 2015-12-25 06:30:31 -0800 | [diff] [blame] | 1320 | final ActivityRecord r = topRunningActivityLocked(); |
Wale Ogunwale | d32da47 | 2018-11-16 07:19:28 -0800 | [diff] [blame] | 1321 | return mRootActivityContainer.isFocusable(this, r != null && r.isFocusable()); |
Wale Ogunwale | d046a01 | 2015-12-24 13:05:59 -0800 | [diff] [blame] | 1322 | } |
| 1323 | |
Riddle Hsu | 7501699 | 2018-09-20 20:37:14 +0800 | [diff] [blame] | 1324 | boolean isFocusableAndVisible() { |
| 1325 | return isFocusable() && shouldBeVisible(null /* starting */); |
| 1326 | } |
| 1327 | |
Craig Mautner | e0a3884 | 2013-12-16 16:14:02 -0800 | [diff] [blame] | 1328 | final boolean isAttached() { |
Riddle Hsu | 402b440 | 2018-11-06 17:23:15 +0800 | [diff] [blame] | 1329 | final ActivityDisplay display = getDisplay(); |
| 1330 | return display != null && !display.isRemoved(); |
Craig Mautner | 4a1cb22 | 2013-12-04 16:14:06 -0800 | [diff] [blame] | 1331 | } |
| 1332 | |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 1333 | /** |
Wale Ogunwale | 3938197 | 2015-12-17 17:15:29 -0800 | [diff] [blame] | 1334 | * Returns the top activity in any existing task matching the given Intent in the input result. |
| 1335 | * Returns null if no such task is found. |
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 | void findTaskLocked(ActivityRecord target, FindTaskResult result) { |
Craig Mautner | ac6f843 | 2013-07-17 13:24:59 -0700 | [diff] [blame] | 1338 | Intent intent = target.intent; |
| 1339 | ActivityInfo info = target.info; |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 1340 | ComponentName cls = intent.getComponent(); |
| 1341 | if (info.targetActivity != null) { |
| 1342 | cls = new ComponentName(info.packageName, info.targetActivity); |
| 1343 | } |
Dianne Hackborn | f02b60a | 2012-08-16 10:48:27 -0700 | [diff] [blame] | 1344 | final int userId = UserHandle.getUserId(info.applicationInfo.uid); |
Craig Mautner | d00f474 | 2014-03-12 14:17:26 -0700 | [diff] [blame] | 1345 | boolean isDocument = intent != null & intent.isDocument(); |
| 1346 | // If documentData is non-null then it must match the existing task data. |
| 1347 | Uri documentData = isDocument ? intent.getData() : null; |
Craig Mautner | 000f002 | 2013-02-26 15:04:29 -0800 | [diff] [blame] | 1348 | |
Wale Ogunwale | ee006da | 2015-03-30 14:49:25 -0700 | [diff] [blame] | 1349 | 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] | 1350 | for (int taskNdx = mTaskHistory.size() - 1; taskNdx >= 0; --taskNdx) { |
| 1351 | final TaskRecord task = mTaskHistory.get(taskNdx); |
Dianne Hackborn | 91097de | 2014-04-04 18:02:06 -0700 | [diff] [blame] | 1352 | if (task.voiceSession != null) { |
| 1353 | // We never match voice sessions; those always run independently. |
Wale Ogunwale | ee006da | 2015-03-30 14:49:25 -0700 | [diff] [blame] | 1354 | if (DEBUG_TASKS) Slog.d(TAG_TASKS, "Skipping " + task + ": voice session"); |
Dianne Hackborn | 91097de | 2014-04-04 18:02:06 -0700 | [diff] [blame] | 1355 | continue; |
| 1356 | } |
Craig Mautner | ac6f843 | 2013-07-17 13:24:59 -0700 | [diff] [blame] | 1357 | if (task.userId != userId) { |
| 1358 | // Looking for a different task. |
Wale Ogunwale | ee006da | 2015-03-30 14:49:25 -0700 | [diff] [blame] | 1359 | if (DEBUG_TASKS) Slog.d(TAG_TASKS, "Skipping " + task + ": different user"); |
Craig Mautner | ac6f843 | 2013-07-17 13:24:59 -0700 | [diff] [blame] | 1360 | continue; |
| 1361 | } |
Bryce Lee | 9f6affd | 2017-09-01 09:18:35 -0700 | [diff] [blame] | 1362 | |
| 1363 | // Overlays should not be considered as the task's logical top activity. |
| 1364 | final ActivityRecord r = task.getTopActivity(false /* includeOverlays */); |
Wale Ogunwale | 8b19de9 | 2018-11-29 19:58:26 -0800 | [diff] [blame] | 1365 | if (r == null || r.finishing || r.mUserId != userId || |
Craig Mautner | 000f002 | 2013-02-26 15:04:29 -0800 | [diff] [blame] | 1366 | r.launchMode == ActivityInfo.LAUNCH_SINGLE_INSTANCE) { |
Wale Ogunwale | ee006da | 2015-03-30 14:49:25 -0700 | [diff] [blame] | 1367 | if (DEBUG_TASKS) Slog.d(TAG_TASKS, "Skipping " + task + ": mismatch root " + r); |
Craig Mautner | 000f002 | 2013-02-26 15:04:29 -0800 | [diff] [blame] | 1368 | continue; |
| 1369 | } |
Wale Ogunwale | 6fbde9f | 2017-08-24 07:24:12 -0700 | [diff] [blame] | 1370 | if (!r.hasCompatibleActivityType(target)) { |
Chong Zhang | b546f7e | 2015-08-05 14:21:36 -0700 | [diff] [blame] | 1371 | if (DEBUG_TASKS) Slog.d(TAG_TASKS, "Skipping " + task + ": mismatch activity type"); |
| 1372 | continue; |
| 1373 | } |
Craig Mautner | 000f002 | 2013-02-26 15:04:29 -0800 | [diff] [blame] | 1374 | |
Craig Mautner | d00f474 | 2014-03-12 14:17:26 -0700 | [diff] [blame] | 1375 | final Intent taskIntent = task.intent; |
| 1376 | final Intent affinityIntent = task.affinityIntent; |
| 1377 | final boolean taskIsDocument; |
| 1378 | final Uri taskDocumentData; |
| 1379 | if (taskIntent != null && taskIntent.isDocument()) { |
| 1380 | taskIsDocument = true; |
| 1381 | taskDocumentData = taskIntent.getData(); |
| 1382 | } else if (affinityIntent != null && affinityIntent.isDocument()) { |
| 1383 | taskIsDocument = true; |
| 1384 | taskDocumentData = affinityIntent.getData(); |
| 1385 | } else { |
| 1386 | taskIsDocument = false; |
| 1387 | taskDocumentData = null; |
| 1388 | } |
| 1389 | |
Wale Ogunwale | ee006da | 2015-03-30 14:49:25 -0700 | [diff] [blame] | 1390 | if (DEBUG_TASKS) Slog.d(TAG_TASKS, "Comparing existing cls=" |
Louis Chang | b05c8d8 | 2019-06-25 11:56:55 +0800 | [diff] [blame] | 1391 | + (task.realActivity != null ? task.realActivity.flattenToShortString() : "") |
Wale Ogunwale | 8b19de9 | 2018-11-29 19:58:26 -0800 | [diff] [blame] | 1392 | + "/aff=" + r.getTaskRecord().rootAffinity + " to new cls=" |
Dianne Hackborn | 2a272d4 | 2013-10-16 13:34:33 -0700 | [diff] [blame] | 1393 | + intent.getComponent().flattenToShortString() + "/aff=" + info.taskAffinity); |
Andrii Kulian | 206b9fa | 2016-06-02 13:18:01 -0700 | [diff] [blame] | 1394 | // TODO Refactor to remove duplications. Check if logic can be simplified. |
Louis Chang | b05c8d8 | 2019-06-25 11:56:55 +0800 | [diff] [blame] | 1395 | if (task.realActivity != null && task.realActivity.compareTo(cls) == 0 |
| 1396 | && Objects.equals(documentData, taskDocumentData)) { |
Wale Ogunwale | ee006da | 2015-03-30 14:49:25 -0700 | [diff] [blame] | 1397 | if (DEBUG_TASKS) Slog.d(TAG_TASKS, "Found matching class!"); |
Craig Mautner | 000f002 | 2013-02-26 15:04:29 -0800 | [diff] [blame] | 1398 | //dump(); |
Wale Ogunwale | ee006da | 2015-03-30 14:49:25 -0700 | [diff] [blame] | 1399 | if (DEBUG_TASKS) Slog.d(TAG_TASKS, |
| 1400 | "For Intent " + intent + " bringing to top: " + r.intent); |
Louis Chang | c85b1a3 | 2018-08-14 16:40:53 +0800 | [diff] [blame] | 1401 | result.mRecord = r; |
| 1402 | result.mIdealMatch = true; |
Wale Ogunwale | 3938197 | 2015-12-17 17:15:29 -0800 | [diff] [blame] | 1403 | break; |
Craig Mautner | ffcfcaa | 2014-06-05 09:54:38 -0700 | [diff] [blame] | 1404 | } else if (affinityIntent != null && affinityIntent.getComponent() != null && |
| 1405 | affinityIntent.getComponent().compareTo(cls) == 0 && |
Craig Mautner | d00f474 | 2014-03-12 14:17:26 -0700 | [diff] [blame] | 1406 | Objects.equals(documentData, taskDocumentData)) { |
Wale Ogunwale | ee006da | 2015-03-30 14:49:25 -0700 | [diff] [blame] | 1407 | if (DEBUG_TASKS) Slog.d(TAG_TASKS, "Found matching class!"); |
Craig Mautner | 000f002 | 2013-02-26 15:04:29 -0800 | [diff] [blame] | 1408 | //dump(); |
Wale Ogunwale | ee006da | 2015-03-30 14:49:25 -0700 | [diff] [blame] | 1409 | if (DEBUG_TASKS) Slog.d(TAG_TASKS, |
| 1410 | "For Intent " + intent + " bringing to top: " + r.intent); |
Louis Chang | c85b1a3 | 2018-08-14 16:40:53 +0800 | [diff] [blame] | 1411 | result.mRecord = r; |
| 1412 | result.mIdealMatch = true; |
Wale Ogunwale | 3938197 | 2015-12-17 17:15:29 -0800 | [diff] [blame] | 1413 | break; |
Andrii Kulian | 206b9fa | 2016-06-02 13:18:01 -0700 | [diff] [blame] | 1414 | } else if (!isDocument && !taskIsDocument |
Louis Chang | c85b1a3 | 2018-08-14 16:40:53 +0800 | [diff] [blame] | 1415 | && result.mRecord == null && task.rootAffinity != null) { |
Andrii Kulian | 206b9fa | 2016-06-02 13:18:01 -0700 | [diff] [blame] | 1416 | if (task.rootAffinity.equals(target.taskAffinity)) { |
| 1417 | if (DEBUG_TASKS) Slog.d(TAG_TASKS, "Found matching affinity candidate!"); |
| 1418 | // It is possible for multiple tasks to have the same root affinity especially |
| 1419 | // if they are in separate stacks. We save off this candidate, but keep looking |
| 1420 | // to see if there is a better candidate. |
Louis Chang | c85b1a3 | 2018-08-14 16:40:53 +0800 | [diff] [blame] | 1421 | result.mRecord = r; |
| 1422 | result.mIdealMatch = false; |
Andrii Kulian | 206b9fa | 2016-06-02 13:18:01 -0700 | [diff] [blame] | 1423 | } |
Wale Ogunwale | ee006da | 2015-03-30 14:49:25 -0700 | [diff] [blame] | 1424 | } else if (DEBUG_TASKS) Slog.d(TAG_TASKS, "Not a match: " + task); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 1425 | } |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 1426 | } |
| 1427 | |
| 1428 | /** |
| 1429 | * Returns the first activity (starting from the top of the stack) that |
| 1430 | * is the same as the given activity. Returns null if no such activity |
| 1431 | * is found. |
| 1432 | */ |
Andrii Kulian | d3bbb13 | 2016-06-16 16:00:20 -0700 | [diff] [blame] | 1433 | ActivityRecord findActivityLocked(Intent intent, ActivityInfo info, |
| 1434 | boolean compareIntentFilters) { |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 1435 | ComponentName cls = intent.getComponent(); |
| 1436 | if (info.targetActivity != null) { |
| 1437 | cls = new ComponentName(info.packageName, info.targetActivity); |
| 1438 | } |
Dianne Hackborn | f02b60a | 2012-08-16 10:48:27 -0700 | [diff] [blame] | 1439 | final int userId = UserHandle.getUserId(info.applicationInfo.uid); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 1440 | |
Craig Mautner | 000f002 | 2013-02-26 15:04:29 -0800 | [diff] [blame] | 1441 | for (int taskNdx = mTaskHistory.size() - 1; taskNdx >= 0; --taskNdx) { |
Wale Ogunwale | 3fcb4a8 | 2015-04-06 14:00:13 -0700 | [diff] [blame] | 1442 | final TaskRecord task = mTaskHistory.get(taskNdx); |
Craig Mautner | ac6f843 | 2013-07-17 13:24:59 -0700 | [diff] [blame] | 1443 | final ArrayList<ActivityRecord> activities = task.mActivities; |
Wale Ogunwale | 3fcb4a8 | 2015-04-06 14:00:13 -0700 | [diff] [blame] | 1444 | |
Craig Mautner | 000f002 | 2013-02-26 15:04:29 -0800 | [diff] [blame] | 1445 | for (int activityNdx = activities.size() - 1; activityNdx >= 0; --activityNdx) { |
| 1446 | ActivityRecord r = activities.get(activityNdx); |
Chong Zhang | 8776197 | 2016-08-22 13:53:24 -0700 | [diff] [blame] | 1447 | if (!r.okToShowLocked()) { |
Wale Ogunwale | 25073dd | 2015-07-21 16:54:54 -0700 | [diff] [blame] | 1448 | continue; |
Wale Ogunwale | 3fcb4a8 | 2015-04-06 14:00:13 -0700 | [diff] [blame] | 1449 | } |
Wale Ogunwale | 8b19de9 | 2018-11-29 19:58:26 -0800 | [diff] [blame] | 1450 | if (!r.finishing && r.mUserId == userId) { |
Andrii Kulian | d3bbb13 | 2016-06-16 16:00:20 -0700 | [diff] [blame] | 1451 | if (compareIntentFilters) { |
| 1452 | if (r.intent.filterEquals(intent)) { |
| 1453 | return r; |
| 1454 | } |
| 1455 | } else { |
| 1456 | if (r.intent.getComponent().equals(cls)) { |
| 1457 | return r; |
| 1458 | } |
| 1459 | } |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 1460 | } |
| 1461 | } |
| 1462 | } |
| 1463 | |
| 1464 | return null; |
| 1465 | } |
| 1466 | |
Amith Yamasani | 742a671 | 2011-05-04 14:49:28 -0700 | [diff] [blame] | 1467 | /* |
Craig Mautner | ac6f843 | 2013-07-17 13:24:59 -0700 | [diff] [blame] | 1468 | * 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] | 1469 | */ |
Craig Mautner | 93529a4 | 2013-10-04 15:03:13 -0700 | [diff] [blame] | 1470 | final void switchUserLocked(int userId) { |
Craig Mautner | 5d9c7be | 2013-02-15 14:02:56 -0800 | [diff] [blame] | 1471 | if (mCurrentUser == userId) { |
Craig Mautner | 93529a4 | 2013-10-04 15:03:13 -0700 | [diff] [blame] | 1472 | return; |
Craig Mautner | 5d9c7be | 2013-02-15 14:02:56 -0800 | [diff] [blame] | 1473 | } |
| 1474 | mCurrentUser = userId; |
| 1475 | |
| 1476 | // Move userId's tasks to the top. |
Craig Mautner | 5d9c7be | 2013-02-15 14:02:56 -0800 | [diff] [blame] | 1477 | int index = mTaskHistory.size(); |
Craig Mautner | db5c4fb | 2013-11-06 13:55:08 -0800 | [diff] [blame] | 1478 | for (int i = 0; i < index; ) { |
Wale Ogunwale | 3fcb4a8 | 2015-04-06 14:00:13 -0700 | [diff] [blame] | 1479 | final TaskRecord task = mTaskHistory.get(i); |
| 1480 | |
Chong Zhang | 8776197 | 2016-08-22 13:53:24 -0700 | [diff] [blame] | 1481 | if (task.okToShowLocked()) { |
Wale Ogunwale | d32da47 | 2018-11-16 07:19:28 -0800 | [diff] [blame] | 1482 | if (DEBUG_TASKS) Slog.d(TAG_TASKS, "switchUser: stack=" + getStackId() + |
Craig Mautner | 4f1df4f | 2013-10-15 15:44:14 -0700 | [diff] [blame] | 1483 | " moving " + task + " to top"); |
Craig Mautner | 5d9c7be | 2013-02-15 14:02:56 -0800 | [diff] [blame] | 1484 | mTaskHistory.remove(i); |
| 1485 | mTaskHistory.add(task); |
| 1486 | --index; |
Craig Mautner | db5c4fb | 2013-11-06 13:55:08 -0800 | [diff] [blame] | 1487 | // Use same value for i. |
| 1488 | } else { |
| 1489 | ++i; |
Craig Mautner | 5d9c7be | 2013-02-15 14:02:56 -0800 | [diff] [blame] | 1490 | } |
| 1491 | } |
Amith Yamasani | 742a671 | 2011-05-04 14:49:28 -0700 | [diff] [blame] | 1492 | } |
| 1493 | |
Craig Mautner | 2420ead | 2013-04-01 17:13:20 -0700 | [diff] [blame] | 1494 | void minimalResumeActivityLocked(ActivityRecord r) { |
Wale Ogunwale | 5658e4b | 2016-02-12 12:22:19 -0800 | [diff] [blame] | 1495 | if (DEBUG_STATES) Slog.v(TAG_STATES, "Moving to RESUMED: " + r + " (starting new instance)" |
| 1496 | + " callers=" + Debug.getCallers(5)); |
Bryce Lee | c4ab62a | 2018-03-05 14:19:26 -0800 | [diff] [blame] | 1497 | r.setState(RESUMED, "minimalResumeActivityLocked"); |
Andrii Kulian | 21713ac | 2016-10-12 22:05:05 -0700 | [diff] [blame] | 1498 | r.completeResumeLocked(); |
Wale Ogunwale | 0fc365c | 2015-05-25 19:35:42 -0700 | [diff] [blame] | 1499 | if (DEBUG_SAVED_STATE) Slog.i(TAG_SAVED_STATE, |
| 1500 | "Launch completed; removing icicle of " + r.icicle); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 1501 | } |
| 1502 | |
Andrii Kulian | 21713ac | 2016-10-12 22:05:05 -0700 | [diff] [blame] | 1503 | private void clearLaunchTime(ActivityRecord r) { |
Craig Mautner | 5c49454 | 2013-09-06 11:59:38 -0700 | [diff] [blame] | 1504 | // Make sure that there is no activity waiting for this to launch. |
Vishnu Nair | 132ee83 | 2018-09-28 15:00:05 -0700 | [diff] [blame] | 1505 | if (!mStackSupervisor.mWaitingActivityLaunched.isEmpty()) { |
Craig Mautner | 5c49454 | 2013-09-06 11:59:38 -0700 | [diff] [blame] | 1506 | mStackSupervisor.removeTimeoutsForActivityLocked(r); |
| 1507 | mStackSupervisor.scheduleIdleTimeoutLocked(r); |
| 1508 | } |
Dianne Hackborn | 2286cdc | 2013-07-01 19:10:06 -0700 | [diff] [blame] | 1509 | } |
| 1510 | |
Dianne Hackborn | 4eba96b | 2011-01-21 13:34:36 -0800 | [diff] [blame] | 1511 | void awakeFromSleepingLocked() { |
Dianne Hackborn | 4eba96b | 2011-01-21 13:34:36 -0800 | [diff] [blame] | 1512 | // Ensure activities are no longer sleeping. |
Craig Mautner | d44711d | 2013-02-23 11:24:36 -0800 | [diff] [blame] | 1513 | for (int taskNdx = mTaskHistory.size() - 1; taskNdx >= 0; --taskNdx) { |
| 1514 | final ArrayList<ActivityRecord> activities = mTaskHistory.get(taskNdx).mActivities; |
| 1515 | for (int activityNdx = activities.size() - 1; activityNdx >= 0; --activityNdx) { |
| 1516 | activities.get(activityNdx).setSleeping(false); |
| 1517 | } |
Dianne Hackborn | 4eba96b | 2011-01-21 13:34:36 -0800 | [diff] [blame] | 1518 | } |
Craig Mautner | f49b0a4 | 2014-11-20 15:06:40 -0800 | [diff] [blame] | 1519 | if (mPausingActivity != null) { |
| 1520 | Slog.d(TAG, "awakeFromSleepingLocked: previously pausing activity didn't pause"); |
| 1521 | activityPausedLocked(mPausingActivity.appToken, true); |
| 1522 | } |
Dianne Hackborn | 4eba96b | 2011-01-21 13:34:36 -0800 | [diff] [blame] | 1523 | } |
| 1524 | |
Todd Kennedy | 39bfee5 | 2016-02-24 10:28:21 -0800 | [diff] [blame] | 1525 | void updateActivityApplicationInfoLocked(ApplicationInfo aInfo) { |
| 1526 | final String packageName = aInfo.packageName; |
Makoto Onuki | 8b9963a | 2017-05-18 13:56:30 -0700 | [diff] [blame] | 1527 | final int userId = UserHandle.getUserId(aInfo.uid); |
| 1528 | |
Todd Kennedy | 39bfee5 | 2016-02-24 10:28:21 -0800 | [diff] [blame] | 1529 | for (int taskNdx = mTaskHistory.size() - 1; taskNdx >= 0; --taskNdx) { |
| 1530 | final List<ActivityRecord> activities = mTaskHistory.get(taskNdx).mActivities; |
| 1531 | for (int activityNdx = activities.size() - 1; activityNdx >= 0; --activityNdx) { |
Makoto Onuki | 8b9963a | 2017-05-18 13:56:30 -0700 | [diff] [blame] | 1532 | final ActivityRecord ar = activities.get(activityNdx); |
| 1533 | |
Wale Ogunwale | 8b19de9 | 2018-11-29 19:58:26 -0800 | [diff] [blame] | 1534 | if ((userId == ar.mUserId) && packageName.equals(ar.packageName)) { |
Philip P. Moltmann | cff8f0f | 2018-03-27 12:51:51 -0700 | [diff] [blame] | 1535 | ar.updateApplicationInfo(aInfo); |
Todd Kennedy | 39bfee5 | 2016-02-24 10:28:21 -0800 | [diff] [blame] | 1536 | } |
| 1537 | } |
| 1538 | } |
| 1539 | } |
| 1540 | |
David Stevens | 9440dc8 | 2017-03-16 19:00:20 -0700 | [diff] [blame] | 1541 | void checkReadyForSleep() { |
| 1542 | if (shouldSleepActivities() && goToSleepIfPossible(false /* shuttingDown */)) { |
| 1543 | mStackSupervisor.checkReadyForSleepLocked(true /* allowDelay */); |
| 1544 | } |
| 1545 | } |
| 1546 | |
Craig Mautner | 0eea92c | 2013-05-16 13:35:39 -0700 | [diff] [blame] | 1547 | /** |
David Stevens | 9440dc8 | 2017-03-16 19:00:20 -0700 | [diff] [blame] | 1548 | * Tries to put the activities in the stack to sleep. |
| 1549 | * |
| 1550 | * If the stack is not in a state where its activities can be put to sleep, this function will |
| 1551 | * start any necessary actions to move the stack into such a state. It is expected that this |
| 1552 | * function get called again when those actions complete. |
| 1553 | * |
| 1554 | * @param shuttingDown true when the called because the device is shutting down. |
David Stevens | 18abd0e | 2017-08-17 14:55:47 -0700 | [diff] [blame] | 1555 | * @return true if the stack finished going to sleep, false if the stack only started the |
| 1556 | * 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] | 1557 | */ |
David Stevens | 9440dc8 | 2017-03-16 19:00:20 -0700 | [diff] [blame] | 1558 | boolean goToSleepIfPossible(boolean shuttingDown) { |
| 1559 | boolean shouldSleep = true; |
| 1560 | |
Craig Mautner | 0eea92c | 2013-05-16 13:35:39 -0700 | [diff] [blame] | 1561 | if (mResumedActivity != null) { |
| 1562 | // Still have something resumed; can't sleep until it is paused. |
Wale Ogunwale | ee006da | 2015-03-30 14:49:25 -0700 | [diff] [blame] | 1563 | if (DEBUG_PAUSE) Slog.v(TAG_PAUSE, "Sleep needs to pause " + mResumedActivity); |
| 1564 | if (DEBUG_USER_LEAVING) Slog.v(TAG_USER_LEAVING, |
| 1565 | "Sleep => pause with userLeaving=false"); |
Bryce Lee | 5daa312 | 2017-04-19 10:40:42 -0700 | [diff] [blame] | 1566 | |
chaviw | a1d6853 | 2018-03-16 15:33:43 -0700 | [diff] [blame] | 1567 | startPausingLocked(false, true, null, false); |
David Stevens | 9440dc8 | 2017-03-16 19:00:20 -0700 | [diff] [blame] | 1568 | shouldSleep = false ; |
| 1569 | } else if (mPausingActivity != null) { |
Craig Mautner | 0eea92c | 2013-05-16 13:35:39 -0700 | [diff] [blame] | 1570 | // Still waiting for something to pause; can't sleep yet. |
Wale Ogunwale | ee006da | 2015-03-30 14:49:25 -0700 | [diff] [blame] | 1571 | 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] | 1572 | shouldSleep = false; |
Dianne Hackborn | 4eba96b | 2011-01-21 13:34:36 -0800 | [diff] [blame] | 1573 | } |
David Stevens | 9440dc8 | 2017-03-16 19:00:20 -0700 | [diff] [blame] | 1574 | |
| 1575 | if (!shuttingDown) { |
| 1576 | if (containsActivityFromStack(mStackSupervisor.mStoppingActivities)) { |
| 1577 | // Still need to tell some activities to stop; can't sleep yet. |
| 1578 | if (DEBUG_PAUSE) Slog.v(TAG_PAUSE, "Sleep still need to stop " |
| 1579 | + mStackSupervisor.mStoppingActivities.size() + " activities"); |
| 1580 | |
| 1581 | mStackSupervisor.scheduleIdleLocked(); |
| 1582 | shouldSleep = false; |
| 1583 | } |
| 1584 | |
| 1585 | if (containsActivityFromStack(mStackSupervisor.mGoingToSleepActivities)) { |
| 1586 | // Still need to tell some activities to sleep; can't sleep yet. |
| 1587 | if (DEBUG_PAUSE) Slog.v(TAG_PAUSE, "Sleep still need to sleep " |
| 1588 | + mStackSupervisor.mGoingToSleepActivities.size() + " activities"); |
| 1589 | shouldSleep = false; |
| 1590 | } |
| 1591 | } |
| 1592 | |
| 1593 | if (shouldSleep) { |
| 1594 | goToSleep(); |
| 1595 | } |
| 1596 | |
David Stevens | 18abd0e | 2017-08-17 14:55:47 -0700 | [diff] [blame] | 1597 | return shouldSleep; |
Craig Mautner | 0eea92c | 2013-05-16 13:35:39 -0700 | [diff] [blame] | 1598 | } |
Dianne Hackborn | 4eba96b | 2011-01-21 13:34:36 -0800 | [diff] [blame] | 1599 | |
David Stevens | 18abd0e | 2017-08-17 14:55:47 -0700 | [diff] [blame] | 1600 | void goToSleep() { |
Andrii Kulian | f4479ee | 2018-05-23 17:52:48 -0700 | [diff] [blame] | 1601 | // Ensure visibility without updating configuration, as activities are about to sleep. |
Andrii Kulian | a39ae3e | 2018-05-31 12:43:54 -0700 | [diff] [blame] | 1602 | ensureActivitiesVisibleLocked(null /* starting */, 0 /* configChanges */, |
| 1603 | !PRESERVE_WINDOWS); |
Dianne Hackborn | 4eba96b | 2011-01-21 13:34:36 -0800 | [diff] [blame] | 1604 | |
Andrii Kulian | f9949d5 | 2016-05-06 12:53:25 -0700 | [diff] [blame] | 1605 | // Make sure any paused or stopped but visible activities are now sleeping. |
Craig Mautner | 0eea92c | 2013-05-16 13:35:39 -0700 | [diff] [blame] | 1606 | // This ensures that the activity's onStop() is called. |
| 1607 | for (int taskNdx = mTaskHistory.size() - 1; taskNdx >= 0; --taskNdx) { |
| 1608 | final ArrayList<ActivityRecord> activities = mTaskHistory.get(taskNdx).mActivities; |
| 1609 | for (int activityNdx = activities.size() - 1; activityNdx >= 0; --activityNdx) { |
| 1610 | final ActivityRecord r = activities.get(activityNdx); |
Bryce Lee | 7ace395 | 2018-02-16 14:34:32 -0800 | [diff] [blame] | 1611 | if (r.isState(STOPPING, STOPPED, PAUSED, PAUSING)) { |
Craig Mautner | 0eea92c | 2013-05-16 13:35:39 -0700 | [diff] [blame] | 1612 | r.setSleeping(true); |
Dianne Hackborn | 4eba96b | 2011-01-21 13:34:36 -0800 | [diff] [blame] | 1613 | } |
| 1614 | } |
Dianne Hackborn | 4eba96b | 2011-01-21 13:34:36 -0800 | [diff] [blame] | 1615 | } |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 1616 | } |
Craig Mautner | 59c0097 | 2012-07-30 12:10:24 -0700 | [diff] [blame] | 1617 | |
David Stevens | 9440dc8 | 2017-03-16 19:00:20 -0700 | [diff] [blame] | 1618 | private boolean containsActivityFromStack(List<ActivityRecord> rs) { |
| 1619 | for (ActivityRecord r : rs) { |
Wale Ogunwale | 8b19de9 | 2018-11-29 19:58:26 -0800 | [diff] [blame] | 1620 | if (r.getActivityStack() == this) { |
David Stevens | 9440dc8 | 2017-03-16 19:00:20 -0700 | [diff] [blame] | 1621 | return true; |
| 1622 | } |
| 1623 | } |
| 1624 | return false; |
| 1625 | } |
| 1626 | |
Dianne Hackborn | a4e102e | 2014-09-04 22:52:27 -0700 | [diff] [blame] | 1627 | /** |
Winson Chung | 4dabf23 | 2017-01-25 13:25:22 -0800 | [diff] [blame] | 1628 | * Schedule a pause timeout in case the app doesn't respond. We don't give it much time because |
| 1629 | * this directly impacts the responsiveness seen by the user. |
| 1630 | */ |
| 1631 | private void schedulePauseTimeout(ActivityRecord r) { |
| 1632 | final Message msg = mHandler.obtainMessage(PAUSE_TIMEOUT_MSG); |
| 1633 | msg.obj = r; |
| 1634 | r.pauseTime = SystemClock.uptimeMillis(); |
| 1635 | mHandler.sendMessageDelayed(msg, PAUSE_TIMEOUT); |
| 1636 | if (DEBUG_PAUSE) Slog.v(TAG_PAUSE, "Waiting for pause to complete..."); |
| 1637 | } |
| 1638 | |
| 1639 | /** |
Dianne Hackborn | a4e102e | 2014-09-04 22:52:27 -0700 | [diff] [blame] | 1640 | * Start pausing the currently resumed activity. It is an error to call this if there |
| 1641 | * is already an activity being paused or there is no resumed activity. |
| 1642 | * |
| 1643 | * @param userLeaving True if this should result in an onUserLeaving to the current activity. |
| 1644 | * @param uiSleeping True if this is happening with the user interface going to sleep (the |
| 1645 | * screen turning off). |
Wale Ogunwale | 950faff | 2016-08-08 09:51:04 -0700 | [diff] [blame] | 1646 | * @param resuming The activity we are currently trying to resume or null if this is not being |
| 1647 | * called as part of resuming the top activity, so we shouldn't try to instigate |
| 1648 | * a resume here if not null. |
Winson Chung | 6954fc9 | 2017-03-24 16:22:12 -0700 | [diff] [blame] | 1649 | * @param pauseImmediately True if the caller does not want to wait for the activity callback to |
| 1650 | * complete pausing. |
Dianne Hackborn | a4e102e | 2014-09-04 22:52:27 -0700 | [diff] [blame] | 1651 | * @return Returns true if an activity now is in the PAUSING state, and we are waiting for |
| 1652 | * it to tell us when it is done. |
| 1653 | */ |
Wale Ogunwale | 950faff | 2016-08-08 09:51:04 -0700 | [diff] [blame] | 1654 | final boolean startPausingLocked(boolean userLeaving, boolean uiSleeping, |
Winson Chung | 6954fc9 | 2017-03-24 16:22:12 -0700 | [diff] [blame] | 1655 | ActivityRecord resuming, boolean pauseImmediately) { |
Dianne Hackborn | 621e2fe | 2012-02-16 17:07:33 -0800 | [diff] [blame] | 1656 | if (mPausingActivity != null) { |
riddle_hsu | 7dfe4d7 | 2015-02-16 18:43:49 +0800 | [diff] [blame] | 1657 | 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] | 1658 | + " state=" + mPausingActivity.getState()); |
David Stevens | 9440dc8 | 2017-03-16 19:00:20 -0700 | [diff] [blame] | 1659 | if (!shouldSleepActivities()) { |
riddle_hsu | 7dfe4d7 | 2015-02-16 18:43:49 +0800 | [diff] [blame] | 1660 | // Avoid recursion among check for sleep and complete pause during sleeping. |
| 1661 | // Because activity will be paused immediately after resume, just let pause |
| 1662 | // be completed by the order of activity paused from clients. |
Wale Ogunwale | 950faff | 2016-08-08 09:51:04 -0700 | [diff] [blame] | 1663 | completePauseLocked(false, resuming); |
riddle_hsu | 7dfe4d7 | 2015-02-16 18:43:49 +0800 | [diff] [blame] | 1664 | } |
Dianne Hackborn | 621e2fe | 2012-02-16 17:07:33 -0800 | [diff] [blame] | 1665 | } |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 1666 | ActivityRecord prev = mResumedActivity; |
Bryce Lee | 5daa312 | 2017-04-19 10:40:42 -0700 | [diff] [blame] | 1667 | |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 1668 | if (prev == null) { |
Wale Ogunwale | 950faff | 2016-08-08 09:51:04 -0700 | [diff] [blame] | 1669 | if (resuming == null) { |
Dianne Hackborn | a4e102e | 2014-09-04 22:52:27 -0700 | [diff] [blame] | 1670 | Slog.wtf(TAG, "Trying to pause when nothing is resumed"); |
Wale Ogunwale | d32da47 | 2018-11-16 07:19:28 -0800 | [diff] [blame] | 1671 | mRootActivityContainer.resumeFocusedStacksTopActivities(); |
Dianne Hackborn | a4e102e | 2014-09-04 22:52:27 -0700 | [diff] [blame] | 1672 | } |
| 1673 | return false; |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 1674 | } |
Craig Mautner | df88d73 | 2014-01-27 09:21:32 -0800 | [diff] [blame] | 1675 | |
Andrii Kulian | b1888aa | 2018-02-16 14:40:42 -0800 | [diff] [blame] | 1676 | if (prev == resuming) { |
| 1677 | Slog.wtf(TAG, "Trying to pause activity that is in process of being resumed"); |
| 1678 | return false; |
| 1679 | } |
| 1680 | |
Wale Ogunwale | 0fc365c | 2015-05-25 19:35:42 -0700 | [diff] [blame] | 1681 | if (DEBUG_STATES) Slog.v(TAG_STATES, "Moving to PAUSING: " + prev); |
Wale Ogunwale | ee006da | 2015-03-30 14:49:25 -0700 | [diff] [blame] | 1682 | else if (DEBUG_PAUSE) Slog.v(TAG_PAUSE, "Start pausing: " + prev); |
Dianne Hackborn | 621e2fe | 2012-02-16 17:07:33 -0800 | [diff] [blame] | 1683 | mPausingActivity = prev; |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 1684 | mLastPausedActivity = prev; |
Craig Mautner | 0f92274 | 2013-08-06 08:44:42 -0700 | [diff] [blame] | 1685 | mLastNoHistoryActivity = (prev.intent.getFlags() & Intent.FLAG_ACTIVITY_NO_HISTORY) != 0 |
| 1686 | || (prev.info.flags & ActivityInfo.FLAG_NO_HISTORY) != 0 ? prev : null; |
Bryce Lee | 7ace395 | 2018-02-16 14:34:32 -0800 | [diff] [blame] | 1687 | prev.setState(PAUSING, "startPausingLocked"); |
Wale Ogunwale | 8b19de9 | 2018-11-29 19:58:26 -0800 | [diff] [blame] | 1688 | prev.getTaskRecord().touchActiveTime(); |
Dianne Hackborn | 2286cdc | 2013-07-01 19:10:06 -0700 | [diff] [blame] | 1689 | clearLaunchTime(prev); |
Jorim Jaggi | e7d2b85 | 2017-08-28 17:55:15 +0200 | [diff] [blame] | 1690 | |
Wale Ogunwale | 5378374 | 2018-09-16 10:21:51 -0700 | [diff] [blame] | 1691 | mService.updateCpuStats(); |
Craig Mautner | aab647e | 2013-02-28 16:31:36 -0800 | [diff] [blame] | 1692 | |
Wale Ogunwale | 9e4f3e0 | 2018-05-17 09:35:39 -0700 | [diff] [blame] | 1693 | if (prev.attachedToProcess()) { |
Wale Ogunwale | ee006da | 2015-03-30 14:49:25 -0700 | [diff] [blame] | 1694 | if (DEBUG_PAUSE) Slog.v(TAG_PAUSE, "Enqueueing pending pause: " + prev); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 1695 | try { |
Wale Ogunwale | 8b19de9 | 2018-11-29 19:58:26 -0800 | [diff] [blame] | 1696 | EventLogTags.writeAmPauseActivity(prev.mUserId, System.identityHashCode(prev), |
Wale Ogunwale | c59b4f6 | 2017-11-30 11:05:43 -0800 | [diff] [blame] | 1697 | prev.shortComponentName, "userLeaving=" + userLeaving); |
Andrii Kulian | 446e824 | 2017-10-26 15:17:29 -0700 | [diff] [blame] | 1698 | |
Wale Ogunwale | 9e4f3e0 | 2018-05-17 09:35:39 -0700 | [diff] [blame] | 1699 | mService.getLifecycleManager().scheduleTransaction(prev.app.getThread(), |
| 1700 | prev.appToken, PauseActivityItem.obtain(prev.finishing, userLeaving, |
Bryce Lee | 1d0d514 | 2018-04-12 10:35:07 -0700 | [diff] [blame] | 1701 | prev.configChangeFlags, pauseImmediately)); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 1702 | } catch (Exception e) { |
| 1703 | // Ignore exception, if process died other code will cleanup. |
| 1704 | Slog.w(TAG, "Exception thrown during pause", e); |
Dianne Hackborn | 621e2fe | 2012-02-16 17:07:33 -0800 | [diff] [blame] | 1705 | mPausingActivity = null; |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 1706 | mLastPausedActivity = null; |
Craig Mautner | 0f92274 | 2013-08-06 08:44:42 -0700 | [diff] [blame] | 1707 | mLastNoHistoryActivity = null; |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 1708 | } |
| 1709 | } else { |
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 | |
| 1715 | // If we are not going to sleep, we want to ensure the device is |
| 1716 | // awake until the next activity is started. |
Wale Ogunwale | f673393 | 2018-06-27 05:14:34 -0700 | [diff] [blame] | 1717 | if (!uiSleeping && !mService.isSleepingOrShuttingDownLocked()) { |
Craig Mautner | 7ea5bd4 | 2013-07-05 15:27:08 -0700 | [diff] [blame] | 1718 | mStackSupervisor.acquireLaunchWakelock(); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 1719 | } |
| 1720 | |
Dianne Hackborn | 621e2fe | 2012-02-16 17:07:33 -0800 | [diff] [blame] | 1721 | if (mPausingActivity != null) { |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 1722 | // Have the window manager pause its key dispatching until the new |
| 1723 | // activity has started. If we're pausing the activity just because |
| 1724 | // the screen is being turned off and the UI is sleeping, don't interrupt |
| 1725 | // key dispatch; the same activity will pick it up again on wakeup. |
| 1726 | if (!uiSleeping) { |
Dianne Hackborn | 621e2fe | 2012-02-16 17:07:33 -0800 | [diff] [blame] | 1727 | prev.pauseKeyDispatchingLocked(); |
Wale Ogunwale | ee006da | 2015-03-30 14:49:25 -0700 | [diff] [blame] | 1728 | } else if (DEBUG_PAUSE) { |
| 1729 | Slog.v(TAG_PAUSE, "Key dispatch not paused for screen off"); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 1730 | } |
| 1731 | |
Winson Chung | 6954fc9 | 2017-03-24 16:22:12 -0700 | [diff] [blame] | 1732 | if (pauseImmediately) { |
Dianne Hackborn | a4e102e | 2014-09-04 22:52:27 -0700 | [diff] [blame] | 1733 | // If the caller said they don't want to wait for the pause, then complete |
| 1734 | // the pause now. |
Wale Ogunwale | 950faff | 2016-08-08 09:51:04 -0700 | [diff] [blame] | 1735 | completePauseLocked(false, resuming); |
Dianne Hackborn | a4e102e | 2014-09-04 22:52:27 -0700 | [diff] [blame] | 1736 | return false; |
| 1737 | |
| 1738 | } else { |
Winson Chung | 4dabf23 | 2017-01-25 13:25:22 -0800 | [diff] [blame] | 1739 | schedulePauseTimeout(prev); |
Dianne Hackborn | a4e102e | 2014-09-04 22:52:27 -0700 | [diff] [blame] | 1740 | return true; |
| 1741 | } |
| 1742 | |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 1743 | } else { |
| 1744 | // This activity failed to schedule the |
| 1745 | // pause, so just treat it as being paused now. |
Wale Ogunwale | ee006da | 2015-03-30 14:49:25 -0700 | [diff] [blame] | 1746 | if (DEBUG_PAUSE) Slog.v(TAG_PAUSE, "Activity not running, resuming next."); |
Wale Ogunwale | 950faff | 2016-08-08 09:51:04 -0700 | [diff] [blame] | 1747 | if (resuming == null) { |
Wale Ogunwale | d32da47 | 2018-11-16 07:19:28 -0800 | [diff] [blame] | 1748 | mRootActivityContainer.resumeFocusedStacksTopActivities(); |
Dianne Hackborn | a4e102e | 2014-09-04 22:52:27 -0700 | [diff] [blame] | 1749 | } |
| 1750 | return false; |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 1751 | } |
| 1752 | } |
Dianne Hackborn | ad9b3211 | 2012-09-17 15:35:01 -0700 | [diff] [blame] | 1753 | |
Dianne Hackborn | a4e102e | 2014-09-04 22:52:27 -0700 | [diff] [blame] | 1754 | final void activityPausedLocked(IBinder token, boolean timeout) { |
Wale Ogunwale | ee006da | 2015-03-30 14:49:25 -0700 | [diff] [blame] | 1755 | if (DEBUG_PAUSE) Slog.v(TAG_PAUSE, |
| 1756 | "Activity paused: token=" + token + ", timeout=" + timeout); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 1757 | |
Craig Mautner | d232895 | 2013-03-05 12:46:26 -0800 | [diff] [blame] | 1758 | final ActivityRecord r = isInStackLocked(token); |
Andrii Kulian | 6b32151 | 2019-01-23 06:37:00 +0000 | [diff] [blame] | 1759 | |
Craig Mautner | d232895 | 2013-03-05 12:46:26 -0800 | [diff] [blame] | 1760 | if (r != null) { |
| 1761 | mHandler.removeMessages(PAUSE_TIMEOUT_MSG, r); |
| 1762 | if (mPausingActivity == r) { |
Wale Ogunwale | 0fc365c | 2015-05-25 19:35:42 -0700 | [diff] [blame] | 1763 | if (DEBUG_STATES) Slog.v(TAG_STATES, "Moving to PAUSED: " + r |
Craig Mautner | d232895 | 2013-03-05 12:46:26 -0800 | [diff] [blame] | 1764 | + (timeout ? " (due to timeout)" : " (pause complete)")); |
Jorim Jaggi | fe76234 | 2016-10-13 14:33:27 +0200 | [diff] [blame] | 1765 | mService.mWindowManager.deferSurfaceLayout(); |
| 1766 | try { |
Winson Chung | 3f103eb | 2017-04-12 21:53:59 -0700 | [diff] [blame] | 1767 | completePauseLocked(true /* resumeNext */, null /* resumingActivity */); |
Jorim Jaggi | fe76234 | 2016-10-13 14:33:27 +0200 | [diff] [blame] | 1768 | } finally { |
| 1769 | mService.mWindowManager.continueSurfaceLayout(); |
| 1770 | } |
Wale Ogunwale | 5658e4b | 2016-02-12 12:22:19 -0800 | [diff] [blame] | 1771 | return; |
Craig Mautner | d232895 | 2013-03-05 12:46:26 -0800 | [diff] [blame] | 1772 | } else { |
| 1773 | EventLog.writeEvent(EventLogTags.AM_FAILED_TO_PAUSE, |
Wale Ogunwale | 8b19de9 | 2018-11-29 19:58:26 -0800 | [diff] [blame] | 1774 | r.mUserId, System.identityHashCode(r), r.shortComponentName, |
Craig Mautner | d232895 | 2013-03-05 12:46:26 -0800 | [diff] [blame] | 1775 | mPausingActivity != null |
| 1776 | ? mPausingActivity.shortComponentName : "(none)"); |
Bryce Lee | 7ace395 | 2018-02-16 14:34:32 -0800 | [diff] [blame] | 1777 | if (r.isState(PAUSING)) { |
| 1778 | r.setState(PAUSED, "activityPausedLocked"); |
riddle_hsu | 9caeef7 | 2015-10-20 16:34:05 +0800 | [diff] [blame] | 1779 | if (r.finishing) { |
| 1780 | if (DEBUG_PAUSE) Slog.v(TAG, |
| 1781 | "Executing finish of failed to pause activity: " + r); |
Bryce Lee | f52974c | 2018-02-14 15:12:01 -0800 | [diff] [blame] | 1782 | finishCurrentActivityLocked(r, FINISH_AFTER_VISIBLE, false, |
| 1783 | "activityPausedLocked"); |
riddle_hsu | 9caeef7 | 2015-10-20 16:34:05 +0800 | [diff] [blame] | 1784 | } |
louis_chang | 047dfd4 | 2015-04-08 16:35:55 +0800 | [diff] [blame] | 1785 | } |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 1786 | } |
| 1787 | } |
Wale Ogunwale | d32da47 | 2018-11-16 07:19:28 -0800 | [diff] [blame] | 1788 | mRootActivityContainer.ensureActivitiesVisible(null, 0, !PRESERVE_WINDOWS); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 1789 | } |
| 1790 | |
Wale Ogunwale | 950faff | 2016-08-08 09:51:04 -0700 | [diff] [blame] | 1791 | private void completePauseLocked(boolean resumeNext, ActivityRecord resuming) { |
Dianne Hackborn | 621e2fe | 2012-02-16 17:07:33 -0800 | [diff] [blame] | 1792 | ActivityRecord prev = mPausingActivity; |
Wale Ogunwale | ee006da | 2015-03-30 14:49:25 -0700 | [diff] [blame] | 1793 | if (DEBUG_PAUSE) Slog.v(TAG_PAUSE, "Complete pause: " + prev); |
Craig Mautner | aab647e | 2013-02-28 16:31:36 -0800 | [diff] [blame] | 1794 | |
Dianne Hackborn | 621e2fe | 2012-02-16 17:07:33 -0800 | [diff] [blame] | 1795 | if (prev != null) { |
chaviw | 4ad5491 | 2018-05-30 11:05:44 -0700 | [diff] [blame] | 1796 | prev.setWillCloseOrEnterPip(false); |
Bryce Lee | 7ace395 | 2018-02-16 14:34:32 -0800 | [diff] [blame] | 1797 | final boolean wasStopping = prev.isState(STOPPING); |
| 1798 | prev.setState(PAUSED, "completePausedLocked"); |
Dianne Hackborn | 621e2fe | 2012-02-16 17:07:33 -0800 | [diff] [blame] | 1799 | if (prev.finishing) { |
Wale Ogunwale | ee006da | 2015-03-30 14:49:25 -0700 | [diff] [blame] | 1800 | if (DEBUG_PAUSE) Slog.v(TAG_PAUSE, "Executing finish of activity: " + prev); |
Bryce Lee | f52974c | 2018-02-14 15:12:01 -0800 | [diff] [blame] | 1801 | prev = finishCurrentActivityLocked(prev, FINISH_AFTER_VISIBLE, false, |
Charles Chen | 69362cd | 2019-03-29 15:18:45 +0800 | [diff] [blame] | 1802 | "completePausedLocked"); |
Wale Ogunwale | 9e4f3e0 | 2018-05-17 09:35:39 -0700 | [diff] [blame] | 1803 | } else if (prev.hasProcess()) { |
Wale Ogunwale | d802664 | 2016-02-09 20:40:18 -0800 | [diff] [blame] | 1804 | if (DEBUG_PAUSE) Slog.v(TAG_PAUSE, "Enqueue pending stop if needed: " + prev |
| 1805 | + " wasStopping=" + wasStopping + " visible=" + prev.visible); |
Wale Ogunwale | f81c1d1 | 2016-01-12 12:20:18 -0800 | [diff] [blame] | 1806 | if (prev.deferRelaunchUntilPaused) { |
| 1807 | // Complete the deferred relaunch that was waiting for pause to complete. |
| 1808 | if (DEBUG_PAUSE) Slog.v(TAG_PAUSE, "Re-launching after pause: " + prev); |
Andrii Kulian | 21713ac | 2016-10-12 22:05:05 -0700 | [diff] [blame] | 1809 | prev.relaunchActivityLocked(false /* andResume */, |
Wale Ogunwale | f81c1d1 | 2016-01-12 12:20:18 -0800 | [diff] [blame] | 1810 | prev.preserveWindowOnDeferredRelaunch); |
Filip Gruszczynski | dba623a | 2015-12-04 15:45:35 -0800 | [diff] [blame] | 1811 | } else if (wasStopping) { |
| 1812 | // We are also stopping, the stop request must have gone soon after the pause. |
| 1813 | // We can't clobber it, because the stop confirmation will not be handled. |
| 1814 | // 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] | 1815 | prev.setState(STOPPING, "completePausedLocked"); |
David Stevens | 9440dc8 | 2017-03-16 19:00:20 -0700 | [diff] [blame] | 1816 | } else if (!prev.visible || shouldSleepOrShutDownActivities()) { |
Wale Ogunwale | ec95064 | 2017-04-25 07:44:21 -0700 | [diff] [blame] | 1817 | // Clear out any deferred client hide we might currently have. |
| 1818 | prev.setDeferHidingClient(false); |
Jose Lima | 4b6c669 | 2014-08-12 17:41:12 -0700 | [diff] [blame] | 1819 | // If we were visible then resumeTopActivities will release resources before |
Wale Ogunwale | ec95064 | 2017-04-25 07:44:21 -0700 | [diff] [blame] | 1820 | // stopping. |
wilsonshih | 401e50f | 2019-04-30 12:55:48 +0800 | [diff] [blame] | 1821 | addToStopping(prev, true /* scheduleIdle */, false /* idleDelayed */, |
| 1822 | "completePauseLocked"); |
Dianne Hackborn | 621e2fe | 2012-02-16 17:07:33 -0800 | [diff] [blame] | 1823 | } |
| 1824 | } else { |
Wale Ogunwale | ee006da | 2015-03-30 14:49:25 -0700 | [diff] [blame] | 1825 | 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] | 1826 | prev = null; |
Dianne Hackborn | cbb722e | 2012-02-07 18:33:49 -0800 | [diff] [blame] | 1827 | } |
Wale Ogunwale | 07927bf | 2015-03-28 17:21:05 -0700 | [diff] [blame] | 1828 | // It is possible the activity was freezing the screen before it was paused. |
| 1829 | // In that case go ahead and remove the freeze this activity has on the screen |
| 1830 | // since it is no longer visible. |
Wale Ogunwale | e852400 | 2016-09-13 16:34:57 -0700 | [diff] [blame] | 1831 | if (prev != null) { |
| 1832 | prev.stopFreezingScreenLocked(true /*force*/); |
| 1833 | } |
Dianne Hackborn | 621e2fe | 2012-02-16 17:07:33 -0800 | [diff] [blame] | 1834 | mPausingActivity = null; |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 1835 | } |
Dianne Hackborn | cbb722e | 2012-02-07 18:33:49 -0800 | [diff] [blame] | 1836 | |
Dianne Hackborn | a4e102e | 2014-09-04 22:52:27 -0700 | [diff] [blame] | 1837 | if (resumeNext) { |
Wale Ogunwale | d32da47 | 2018-11-16 07:19:28 -0800 | [diff] [blame] | 1838 | final ActivityStack topStack = mRootActivityContainer.getTopDisplayFocusedStack(); |
David Stevens | 9440dc8 | 2017-03-16 19:00:20 -0700 | [diff] [blame] | 1839 | if (!topStack.shouldSleepOrShutDownActivities()) { |
Wale Ogunwale | d32da47 | 2018-11-16 07:19:28 -0800 | [diff] [blame] | 1840 | mRootActivityContainer.resumeFocusedStacksTopActivities(topStack, prev, null); |
Dianne Hackborn | a4e102e | 2014-09-04 22:52:27 -0700 | [diff] [blame] | 1841 | } else { |
David Stevens | 9440dc8 | 2017-03-16 19:00:20 -0700 | [diff] [blame] | 1842 | checkReadyForSleep(); |
Filip Gruszczynski | 3e85ba2 | 2015-10-05 22:48:30 -0700 | [diff] [blame] | 1843 | ActivityRecord top = topStack.topRunningActivityLocked(); |
Dianne Hackborn | a4e102e | 2014-09-04 22:52:27 -0700 | [diff] [blame] | 1844 | if (top == null || (prev != null && top != prev)) { |
Wale Ogunwale | d046a01 | 2015-12-24 13:05:59 -0800 | [diff] [blame] | 1845 | // If there are no more activities available to run, do resume anyway to start |
| 1846 | // something. Also if the top activity on the stack is not the just paused |
| 1847 | // activity, we need to go ahead and resume it to ensure we complete an |
| 1848 | // in-flight app switch. |
Wale Ogunwale | d32da47 | 2018-11-16 07:19:28 -0800 | [diff] [blame] | 1849 | mRootActivityContainer.resumeFocusedStacksTopActivities(); |
Dianne Hackborn | a4e102e | 2014-09-04 22:52:27 -0700 | [diff] [blame] | 1850 | } |
Dianne Hackborn | 42e620c | 2012-06-24 13:20:51 -0700 | [diff] [blame] | 1851 | } |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 1852 | } |
Craig Mautner | aab647e | 2013-02-28 16:31:36 -0800 | [diff] [blame] | 1853 | |
Dianne Hackborn | 621e2fe | 2012-02-16 17:07:33 -0800 | [diff] [blame] | 1854 | if (prev != null) { |
| 1855 | prev.resumeKeyDispatchingLocked(); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 1856 | |
Louis Chang | 1bb884a | 2018-10-08 19:29:18 +0800 | [diff] [blame] | 1857 | if (prev.hasProcess() && prev.cpuTimeAtResume > 0) { |
| 1858 | final long diff = prev.app.getCpuTime() - prev.cpuTimeAtResume; |
| 1859 | if (diff > 0) { |
| 1860 | final Runnable r = PooledLambda.obtainRunnable( |
| 1861 | ActivityManagerInternal::updateForegroundTimeIfOnBattery, |
| 1862 | mService.mAmInternal, prev.info.packageName, |
| 1863 | prev.info.applicationInfo.uid, |
| 1864 | diff); |
| 1865 | mService.mH.post(r); |
| 1866 | } |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 1867 | } |
Craig Mautner | 525f3d9 | 2013-05-07 14:01:50 -0700 | [diff] [blame] | 1868 | prev.cpuTimeAtResume = 0; // reset it |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 1869 | } |
Winson Chung | 740c3ac | 2014-11-12 16:14:38 -0800 | [diff] [blame] | 1870 | |
Andrii Kulian | 8290f8f | 2016-06-30 17:51:32 -0700 | [diff] [blame] | 1871 | // Notify when the task stack has changed, but only if visibilities changed (not just |
| 1872 | // focus). Also if there is an active pinned stack - we always want to notify it about |
| 1873 | // task stack changes, because its positioning may depend on it. |
| 1874 | if (mStackSupervisor.mAppVisibilitiesChangedSinceLastPause |
Louis Chang | 24f7a03 | 2018-12-11 10:49:48 +0800 | [diff] [blame] | 1875 | || (getDisplay() != null && getDisplay().hasPinnedStack())) { |
Wale Ogunwale | 5fa8a8c | 2018-05-08 13:43:21 -0700 | [diff] [blame] | 1876 | mService.getTaskChangeNotificationController().notifyTaskStackChanged(); |
Jorim Jaggi | a0fdeec | 2016-01-07 14:42:28 +0100 | [diff] [blame] | 1877 | mStackSupervisor.mAppVisibilitiesChangedSinceLastPause = false; |
| 1878 | } |
Wale Ogunwale | 5658e4b | 2016-02-12 12:22:19 -0800 | [diff] [blame] | 1879 | |
Wale Ogunwale | d32da47 | 2018-11-16 07:19:28 -0800 | [diff] [blame] | 1880 | mRootActivityContainer.ensureActivitiesVisible(resuming, 0, !PRESERVE_WINDOWS); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 1881 | } |
| 1882 | |
wilsonshih | 401e50f | 2019-04-30 12:55:48 +0800 | [diff] [blame] | 1883 | private void addToStopping(ActivityRecord r, boolean scheduleIdle, boolean idleDelayed, |
| 1884 | String reason) { |
Chong Zhang | 46b1ac6 | 2016-02-18 17:53:57 -0800 | [diff] [blame] | 1885 | if (!mStackSupervisor.mStoppingActivities.contains(r)) { |
wilsonshih | 401e50f | 2019-04-30 12:55:48 +0800 | [diff] [blame] | 1886 | EventLog.writeEvent(EventLogTags.AM_ADD_TO_STOPPING, r.mUserId, |
| 1887 | System.identityHashCode(r), r.shortComponentName, reason); |
Chong Zhang | 46b1ac6 | 2016-02-18 17:53:57 -0800 | [diff] [blame] | 1888 | mStackSupervisor.mStoppingActivities.add(r); |
| 1889 | } |
| 1890 | |
| 1891 | // If we already have a few activities waiting to stop, then give up |
| 1892 | // on things going idle and start clearing them out. Or if r is the |
| 1893 | // last of activity of the last task the stack will be empty and must |
| 1894 | // be cleared immediately. |
| 1895 | boolean forceIdle = mStackSupervisor.mStoppingActivities.size() > MAX_STOPPING_TO_FORCE |
| 1896 | || (r.frontOfTask && mTaskHistory.size() <= 1); |
Winson Chung | 4dabf23 | 2017-01-25 13:25:22 -0800 | [diff] [blame] | 1897 | if (scheduleIdle || forceIdle) { |
Chong Zhang | 46b1ac6 | 2016-02-18 17:53:57 -0800 | [diff] [blame] | 1898 | if (DEBUG_PAUSE) Slog.v(TAG_PAUSE, "Scheduling idle now: forceIdle=" |
Winson Chung | 4dabf23 | 2017-01-25 13:25:22 -0800 | [diff] [blame] | 1899 | + forceIdle + "immediate=" + !idleDelayed); |
| 1900 | if (!idleDelayed) { |
| 1901 | mStackSupervisor.scheduleIdleLocked(); |
| 1902 | } else { |
| 1903 | mStackSupervisor.scheduleIdleTimeoutLocked(r); |
| 1904 | } |
Filip Gruszczynski | ef2f72b | 2015-12-04 14:52:25 -0800 | [diff] [blame] | 1905 | } else { |
David Stevens | 9440dc8 | 2017-03-16 19:00:20 -0700 | [diff] [blame] | 1906 | checkReadyForSleep(); |
Filip Gruszczynski | ef2f72b | 2015-12-04 14:52:25 -0800 | [diff] [blame] | 1907 | } |
| 1908 | } |
| 1909 | |
Wale Ogunwale | 8051c5c | 2016-03-04 10:27:32 -0800 | [diff] [blame] | 1910 | /** |
| 1911 | * Returns true if the stack is translucent and can have other contents visible behind it if |
| 1912 | * needed. A stack is considered translucent if it don't contain a visible or |
| 1913 | * starting (about to be visible) activity that is fullscreen (opaque). |
| 1914 | * @param starting The currently starting activity or null if there is none. |
| 1915 | */ |
Wale Ogunwale | 7e1f5f5 | 2017-10-18 15:19:59 -0700 | [diff] [blame] | 1916 | @VisibleForTesting |
Wale Ogunwale | 66e1685 | 2017-10-19 13:35:52 -0700 | [diff] [blame] | 1917 | boolean isStackTranslucent(ActivityRecord starting) { |
Wale Ogunwale | 7e1f5f5 | 2017-10-18 15:19:59 -0700 | [diff] [blame] | 1918 | if (!isAttached() || mForceHidden) { |
| 1919 | return true; |
| 1920 | } |
Wale Ogunwale | 8051c5c | 2016-03-04 10:27:32 -0800 | [diff] [blame] | 1921 | for (int taskNdx = mTaskHistory.size() - 1; taskNdx >= 0; --taskNdx) { |
| 1922 | final TaskRecord task = mTaskHistory.get(taskNdx); |
Wale Ogunwale | 1e3523c | 2015-09-16 13:11:10 -0700 | [diff] [blame] | 1923 | final ArrayList<ActivityRecord> activities = task.mActivities; |
| 1924 | for (int activityNdx = activities.size() - 1; activityNdx >= 0; --activityNdx) { |
| 1925 | final ActivityRecord r = activities.get(activityNdx); |
Wale Ogunwale | b34a7ad | 2015-08-14 11:05:30 -0700 | [diff] [blame] | 1926 | |
Wale Ogunwale | 56d75cf | 2016-03-09 15:14:47 -0800 | [diff] [blame] | 1927 | if (r.finishing) { |
| 1928 | // We don't factor in finishing activities when determining translucency since |
| 1929 | // they will be gone soon. |
| 1930 | continue; |
| 1931 | } |
| 1932 | |
Wale Ogunwale | 2cca862 | 2017-12-11 08:40:13 -0800 | [diff] [blame] | 1933 | if (!r.visibleIgnoringKeyguard && r != starting) { |
Wale Ogunwale | 56d75cf | 2016-03-09 15:14:47 -0800 | [diff] [blame] | 1934 | // Also ignore invisible activities that are not the currently starting |
| 1935 | // activity (about to be visible). |
| 1936 | continue; |
| 1937 | } |
| 1938 | |
Wale Ogunwale | 7e1f5f5 | 2017-10-18 15:19:59 -0700 | [diff] [blame] | 1939 | if (r.fullscreen || r.hasWallpaper) { |
Wale Ogunwale | 56d75cf | 2016-03-09 15:14:47 -0800 | [diff] [blame] | 1940 | // Stack isn't translucent if it has at least one fullscreen activity |
| 1941 | // that is visible. |
| 1942 | return false; |
| 1943 | } |
Wale Ogunwale | b34a7ad | 2015-08-14 11:05:30 -0700 | [diff] [blame] | 1944 | } |
| 1945 | } |
Wale Ogunwale | 1e3523c | 2015-09-16 13:11:10 -0700 | [diff] [blame] | 1946 | return true; |
Wale Ogunwale | b34a7ad | 2015-08-14 11:05:30 -0700 | [diff] [blame] | 1947 | } |
| 1948 | |
Wale Ogunwale | a0f5b5e | 2017-10-11 09:37:23 -0700 | [diff] [blame] | 1949 | boolean isTopStackOnDisplay() { |
Andrii Kulian | 52d255c | 2018-07-13 11:32:19 -0700 | [diff] [blame] | 1950 | final ActivityDisplay display = getDisplay(); |
| 1951 | return display != null && display.isTopStack(this); |
| 1952 | } |
| 1953 | |
| 1954 | /** |
| 1955 | * @return {@code true} if this is the focused stack on its current display, {@code false} |
| 1956 | * otherwise. |
| 1957 | */ |
| 1958 | boolean isFocusedStackOnDisplay() { |
| 1959 | final ActivityDisplay display = getDisplay(); |
| 1960 | return display != null && this == display.getFocusedStack(); |
Wale Ogunwale | a0f5b5e | 2017-10-11 09:37:23 -0700 | [diff] [blame] | 1961 | } |
| 1962 | |
Adrian Roos | a6d6aab | 2018-04-19 18:58:22 +0200 | [diff] [blame] | 1963 | boolean isTopActivityVisible() { |
| 1964 | final ActivityRecord topActivity = getTopActivity(); |
| 1965 | return topActivity != null && topActivity.visible; |
| 1966 | } |
| 1967 | |
Filip Gruszczynski | 0e381e2 | 2016-01-14 16:31:33 -0800 | [diff] [blame] | 1968 | /** |
Wale Ogunwale | 9dcf946 | 2017-09-19 15:13:01 -0700 | [diff] [blame] | 1969 | * Returns true if the stack should be visible. |
Wale Ogunwale | cd501ec | 2017-04-07 08:53:41 -0700 | [diff] [blame] | 1970 | * |
Wale Ogunwale | 8051c5c | 2016-03-04 10:27:32 -0800 | [diff] [blame] | 1971 | * @param starting The currently starting activity or null if there is none. |
Filip Gruszczynski | 0e381e2 | 2016-01-14 16:31:33 -0800 | [diff] [blame] | 1972 | */ |
Wale Ogunwale | 9dcf946 | 2017-09-19 15:13:01 -0700 | [diff] [blame] | 1973 | boolean shouldBeVisible(ActivityRecord starting) { |
Andrii Kulian | 0c869cc | 2019-02-06 19:50:32 -0800 | [diff] [blame] | 1974 | return getVisibility(starting) != STACK_VISIBILITY_INVISIBLE; |
| 1975 | } |
| 1976 | |
| 1977 | /** |
| 1978 | * Returns true if the stack should be visible. |
| 1979 | * |
| 1980 | * @param starting The currently starting activity or null if there is none. |
| 1981 | */ |
| 1982 | @StackVisibility |
| 1983 | int getVisibility(ActivityRecord starting) { |
Winson Chung | 4790065 | 2017-04-06 18:44:25 -0700 | [diff] [blame] | 1984 | if (!isAttached() || mForceHidden) { |
Andrii Kulian | 0c869cc | 2019-02-06 19:50:32 -0800 | [diff] [blame] | 1985 | return STACK_VISIBILITY_INVISIBLE; |
Jose Lima | 7ba7125 | 2014-04-30 12:59:27 -0700 | [diff] [blame] | 1986 | } |
Wale Ogunwale | 99db186 | 2015-10-23 20:08:22 -0700 | [diff] [blame] | 1987 | |
Wale Ogunwale | 7e1f5f5 | 2017-10-18 15:19:59 -0700 | [diff] [blame] | 1988 | final ActivityDisplay display = getDisplay(); |
Wale Ogunwale | 8e923af | 2018-03-23 08:48:11 -0700 | [diff] [blame] | 1989 | boolean gotSplitScreenStack = false; |
Wale Ogunwale | 7e1f5f5 | 2017-10-18 15:19:59 -0700 | [diff] [blame] | 1990 | boolean gotOpaqueSplitScreenPrimary = false; |
| 1991 | boolean gotOpaqueSplitScreenSecondary = false; |
Andrii Kulian | 0c869cc | 2019-02-06 19:50:32 -0800 | [diff] [blame] | 1992 | boolean gotTranslucentFullscreen = false; |
| 1993 | boolean gotTranslucentSplitScreenPrimary = false; |
| 1994 | boolean gotTranslucentSplitScreenSecondary = false; |
| 1995 | boolean shouldBeVisible = true; |
Wale Ogunwale | 6827856 | 2017-09-23 17:13:55 -0700 | [diff] [blame] | 1996 | final int windowingMode = getWindowingMode(); |
Wale Ogunwale | 8e923af | 2018-03-23 08:48:11 -0700 | [diff] [blame] | 1997 | final boolean isAssistantType = isActivityTypeAssistant(); |
Wale Ogunwale | 7e1f5f5 | 2017-10-18 15:19:59 -0700 | [diff] [blame] | 1998 | for (int i = display.getChildCount() - 1; i >= 0; --i) { |
| 1999 | final ActivityStack other = display.getChildAt(i); |
Louis Chang | f2835df | 2018-10-17 15:14:45 +0800 | [diff] [blame] | 2000 | final boolean hasRunningActivities = other.topRunningActivityLocked() != null; |
Wale Ogunwale | 7e1f5f5 | 2017-10-18 15:19:59 -0700 | [diff] [blame] | 2001 | if (other == this) { |
Louis Chang | f2835df | 2018-10-17 15:14:45 +0800 | [diff] [blame] | 2002 | // Should be visible if there is no other stack occluding it, unless it doesn't |
| 2003 | // have any running activities, not starting one and not home stack. |
Andrii Kulian | 0c869cc | 2019-02-06 19:50:32 -0800 | [diff] [blame] | 2004 | shouldBeVisible = hasRunningActivities || isInStackLocked(starting) != null |
Louis Chang | f2835df | 2018-10-17 15:14:45 +0800 | [diff] [blame] | 2005 | || isActivityTypeHome(); |
Andrii Kulian | 0c869cc | 2019-02-06 19:50:32 -0800 | [diff] [blame] | 2006 | break; |
Louis Chang | f2835df | 2018-10-17 15:14:45 +0800 | [diff] [blame] | 2007 | } |
| 2008 | |
| 2009 | if (!hasRunningActivities) { |
| 2010 | continue; |
Wale Ogunwale | 7e1f5f5 | 2017-10-18 15:19:59 -0700 | [diff] [blame] | 2011 | } |
Wale Ogunwale | 6827856 | 2017-09-23 17:13:55 -0700 | [diff] [blame] | 2012 | |
Wale Ogunwale | 7e1f5f5 | 2017-10-18 15:19:59 -0700 | [diff] [blame] | 2013 | final int otherWindowingMode = other.getWindowingMode(); |
Wale Ogunwale | 7e1f5f5 | 2017-10-18 15:19:59 -0700 | [diff] [blame] | 2014 | |
| 2015 | if (otherWindowingMode == WINDOWING_MODE_FULLSCREEN) { |
Matthew Ng | 99b3cdc | 2018-05-01 14:24:38 -0700 | [diff] [blame] | 2016 | // In this case the home stack isn't resizeable even though we are in split-screen |
| 2017 | // mode. We still want the primary splitscreen stack to be visible as there will be |
| 2018 | // 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] | 2019 | // activity. In addition, if the fullscreen assistant is over primary splitscreen |
| 2020 | // stack, the stack should still be visible in the background as long as the recents |
| 2021 | // animation is running. |
| 2022 | final int activityType = other.getActivityType(); |
| 2023 | if (windowingMode == WINDOWING_MODE_SPLIT_SCREEN_PRIMARY) { |
| 2024 | if (activityType == ACTIVITY_TYPE_HOME |
| 2025 | || (activityType == ACTIVITY_TYPE_ASSISTANT |
Andrii Kulian | 0c869cc | 2019-02-06 19:50:32 -0800 | [diff] [blame] | 2026 | && mWindowManager.getRecentsAnimationController() != null)) { |
| 2027 | break; |
Matthew Ng | a51dcaa | 2018-05-07 15:36:06 -0700 | [diff] [blame] | 2028 | } |
Matthew Ng | 99b3cdc | 2018-05-01 14:24:38 -0700 | [diff] [blame] | 2029 | } |
Wale Ogunwale | 66e1685 | 2017-10-19 13:35:52 -0700 | [diff] [blame] | 2030 | if (other.isStackTranslucent(starting)) { |
Wale Ogunwale | 7e1f5f5 | 2017-10-18 15:19:59 -0700 | [diff] [blame] | 2031 | // Can be visible behind a translucent fullscreen stack. |
Andrii Kulian | 0c869cc | 2019-02-06 19:50:32 -0800 | [diff] [blame] | 2032 | gotTranslucentFullscreen = true; |
Wale Ogunwale | 7e1f5f5 | 2017-10-18 15:19:59 -0700 | [diff] [blame] | 2033 | continue; |
| 2034 | } |
Andrii Kulian | 0c869cc | 2019-02-06 19:50:32 -0800 | [diff] [blame] | 2035 | return STACK_VISIBILITY_INVISIBLE; |
Wale Ogunwale | 7e1f5f5 | 2017-10-18 15:19:59 -0700 | [diff] [blame] | 2036 | } else if (otherWindowingMode == WINDOWING_MODE_SPLIT_SCREEN_PRIMARY |
| 2037 | && !gotOpaqueSplitScreenPrimary) { |
Wale Ogunwale | 8e923af | 2018-03-23 08:48:11 -0700 | [diff] [blame] | 2038 | gotSplitScreenStack = true; |
Andrii Kulian | 0c869cc | 2019-02-06 19:50:32 -0800 | [diff] [blame] | 2039 | gotTranslucentSplitScreenPrimary = other.isStackTranslucent(starting); |
| 2040 | gotOpaqueSplitScreenPrimary = !gotTranslucentSplitScreenPrimary; |
Wale Ogunwale | 7e1f5f5 | 2017-10-18 15:19:59 -0700 | [diff] [blame] | 2041 | if (windowingMode == WINDOWING_MODE_SPLIT_SCREEN_PRIMARY |
| 2042 | && gotOpaqueSplitScreenPrimary) { |
| 2043 | // 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] | 2044 | return STACK_VISIBILITY_INVISIBLE; |
Wale Ogunwale | 7e1f5f5 | 2017-10-18 15:19:59 -0700 | [diff] [blame] | 2045 | } |
| 2046 | } else if (otherWindowingMode == WINDOWING_MODE_SPLIT_SCREEN_SECONDARY |
| 2047 | && !gotOpaqueSplitScreenSecondary) { |
Wale Ogunwale | 8e923af | 2018-03-23 08:48:11 -0700 | [diff] [blame] | 2048 | gotSplitScreenStack = true; |
Andrii Kulian | 0c869cc | 2019-02-06 19:50:32 -0800 | [diff] [blame] | 2049 | gotTranslucentSplitScreenSecondary = other.isStackTranslucent(starting); |
| 2050 | gotOpaqueSplitScreenSecondary = !gotTranslucentSplitScreenSecondary; |
Wale Ogunwale | 7e1f5f5 | 2017-10-18 15:19:59 -0700 | [diff] [blame] | 2051 | if (windowingMode == WINDOWING_MODE_SPLIT_SCREEN_SECONDARY |
| 2052 | && gotOpaqueSplitScreenSecondary) { |
| 2053 | // 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] | 2054 | return STACK_VISIBILITY_INVISIBLE; |
Wale Ogunwale | 7e1f5f5 | 2017-10-18 15:19:59 -0700 | [diff] [blame] | 2055 | } |
| 2056 | } |
| 2057 | if (gotOpaqueSplitScreenPrimary && gotOpaqueSplitScreenSecondary) { |
| 2058 | // Can not be visible if we are in split-screen windowing mode and both halves of |
| 2059 | // the screen are opaque. |
Andrii Kulian | 0c869cc | 2019-02-06 19:50:32 -0800 | [diff] [blame] | 2060 | return STACK_VISIBILITY_INVISIBLE; |
Wale Ogunwale | 7e1f5f5 | 2017-10-18 15:19:59 -0700 | [diff] [blame] | 2061 | } |
Wale Ogunwale | 8e923af | 2018-03-23 08:48:11 -0700 | [diff] [blame] | 2062 | if (isAssistantType && gotSplitScreenStack) { |
| 2063 | // Assistant stack can't be visible behind split-screen. In addition to this not |
| 2064 | // making sense, it also works around an issue here we boost the z-order of the |
| 2065 | // assistant window surfaces in window manager whenever it is visible. |
Andrii Kulian | 0c869cc | 2019-02-06 19:50:32 -0800 | [diff] [blame] | 2066 | return STACK_VISIBILITY_INVISIBLE; |
Wale Ogunwale | 8e923af | 2018-03-23 08:48:11 -0700 | [diff] [blame] | 2067 | } |
Wale Ogunwale | 7e1f5f5 | 2017-10-18 15:19:59 -0700 | [diff] [blame] | 2068 | } |
| 2069 | |
Andrii Kulian | 0c869cc | 2019-02-06 19:50:32 -0800 | [diff] [blame] | 2070 | if (!shouldBeVisible) { |
| 2071 | return STACK_VISIBILITY_INVISIBLE; |
| 2072 | } |
| 2073 | |
| 2074 | // Handle cases when there can be a translucent split-screen stack on top. |
| 2075 | switch (windowingMode) { |
| 2076 | case WINDOWING_MODE_FULLSCREEN: |
| 2077 | if (gotTranslucentSplitScreenPrimary || gotTranslucentSplitScreenSecondary) { |
| 2078 | // At least one of the split-screen stacks that covers this one is translucent. |
| 2079 | return STACK_VISIBILITY_VISIBLE_BEHIND_TRANSLUCENT; |
| 2080 | } |
| 2081 | break; |
| 2082 | case WINDOWING_MODE_SPLIT_SCREEN_PRIMARY: |
| 2083 | if (gotTranslucentSplitScreenPrimary) { |
| 2084 | // Covered by translucent primary split-screen on top. |
| 2085 | return STACK_VISIBILITY_VISIBLE_BEHIND_TRANSLUCENT; |
| 2086 | } |
| 2087 | break; |
| 2088 | case WINDOWING_MODE_SPLIT_SCREEN_SECONDARY: |
| 2089 | if (gotTranslucentSplitScreenSecondary) { |
| 2090 | // Covered by translucent secondary split-screen on top. |
| 2091 | return STACK_VISIBILITY_VISIBLE_BEHIND_TRANSLUCENT; |
| 2092 | } |
| 2093 | break; |
| 2094 | } |
| 2095 | |
| 2096 | // Lastly - check if there is a translucent fullscreen stack on top. |
| 2097 | return gotTranslucentFullscreen ? STACK_VISIBILITY_VISIBLE_BEHIND_TRANSLUCENT |
| 2098 | : STACK_VISIBILITY_VISIBLE; |
Wale Ogunwale | 6827856 | 2017-09-23 17:13:55 -0700 | [diff] [blame] | 2099 | } |
| 2100 | |
Chong Zhang | fdcc4d4 | 2015-10-14 16:50:12 -0700 | [diff] [blame] | 2101 | final int rankTaskLayers(int baseLayer) { |
| 2102 | int layer = 0; |
| 2103 | for (int taskNdx = mTaskHistory.size() - 1; taskNdx >= 0; --taskNdx) { |
| 2104 | final TaskRecord task = mTaskHistory.get(taskNdx); |
| 2105 | ActivityRecord r = task.topRunningActivityLocked(); |
| 2106 | if (r == null || r.finishing || !r.visible) { |
| 2107 | task.mLayerRank = -1; |
| 2108 | } else { |
| 2109 | task.mLayerRank = baseLayer + layer++; |
| 2110 | } |
| 2111 | } |
| 2112 | return layer; |
| 2113 | } |
| 2114 | |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 2115 | /** |
Andrii Kulian | f4479ee | 2018-05-23 17:52:48 -0700 | [diff] [blame] | 2116 | * Make sure that all activities that need to be visible in the stack (that is, they |
| 2117 | * currently can be seen by the user) actually are and update their configuration. |
| 2118 | */ |
| 2119 | final void ensureActivitiesVisibleLocked(ActivityRecord starting, int configChanges, |
| 2120 | boolean preserveWindows) { |
| 2121 | ensureActivitiesVisibleLocked(starting, configChanges, preserveWindows, |
Andrii Kulian | a39ae3e | 2018-05-31 12:43:54 -0700 | [diff] [blame] | 2122 | true /* notifyClients */); |
Andrii Kulian | f4479ee | 2018-05-23 17:52:48 -0700 | [diff] [blame] | 2123 | } |
| 2124 | |
| 2125 | /** |
| 2126 | * Ensure visibility with an option to also update the configuration of visible activities. |
| 2127 | * @see #ensureActivitiesVisibleLocked(ActivityRecord, int, boolean) |
Wale Ogunwale | d32da47 | 2018-11-16 07:19:28 -0800 | [diff] [blame] | 2128 | * @see RootActivityContainer#ensureActivitiesVisible(ActivityRecord, int, boolean) |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 2129 | */ |
Wale Ogunwale | 66e1685 | 2017-10-19 13:35:52 -0700 | [diff] [blame] | 2130 | // 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] | 2131 | final void ensureActivitiesVisibleLocked(ActivityRecord starting, int configChanges, |
Andrii Kulian | a39ae3e | 2018-05-31 12:43:54 -0700 | [diff] [blame] | 2132 | boolean preserveWindows, boolean notifyClients) { |
Jorim Jaggi | fe76234 | 2016-10-13 14:33:27 +0200 | [diff] [blame] | 2133 | mTopActivityOccludesKeyguard = false; |
| 2134 | mTopDismissingKeyguardActivity = null; |
Bryce Lee | 2a3cc46 | 2017-10-27 10:57:35 -0700 | [diff] [blame] | 2135 | mStackSupervisor.getKeyguardController().beginActivityVisibilityUpdate(); |
Jorim Jaggi | fe76234 | 2016-10-13 14:33:27 +0200 | [diff] [blame] | 2136 | try { |
| 2137 | ActivityRecord top = topRunningActivityLocked(); |
| 2138 | if (DEBUG_VISIBILITY) Slog.v(TAG_VISIBILITY, "ensureActivitiesVisible behind " + top |
| 2139 | + " configChanges=0x" + Integer.toHexString(configChanges)); |
| 2140 | if (top != null) { |
| 2141 | checkTranslucentActivityWaiting(top); |
| 2142 | } |
Craig Mautner | 5eda9b3 | 2013-07-02 11:58:16 -0700 | [diff] [blame] | 2143 | |
Jorim Jaggi | fe76234 | 2016-10-13 14:33:27 +0200 | [diff] [blame] | 2144 | // If the top activity is not fullscreen, then we need to |
| 2145 | // make sure any activities under it are now visible. |
| 2146 | boolean aboveTop = top != null; |
Wale Ogunwale | 04a05ac | 2017-09-17 21:35:02 -0700 | [diff] [blame] | 2147 | final boolean stackShouldBeVisible = shouldBeVisible(starting); |
| 2148 | boolean behindFullscreenActivity = !stackShouldBeVisible; |
Andrii Kulian | 6b32151 | 2019-01-23 06:37:00 +0000 | [diff] [blame] | 2149 | boolean resumeNextActivity = isFocusable() && isInStackLocked(starting) == null; |
Jorim Jaggi | fe76234 | 2016-10-13 14:33:27 +0200 | [diff] [blame] | 2150 | for (int taskNdx = mTaskHistory.size() - 1; taskNdx >= 0; --taskNdx) { |
| 2151 | final TaskRecord task = mTaskHistory.get(taskNdx); |
| 2152 | final ArrayList<ActivityRecord> activities = task.mActivities; |
| 2153 | for (int activityNdx = activities.size() - 1; activityNdx >= 0; --activityNdx) { |
| 2154 | final ActivityRecord r = activities.get(activityNdx); |
| 2155 | if (r.finishing) { |
Jorim Jaggi | fe76234 | 2016-10-13 14:33:27 +0200 | [diff] [blame] | 2156 | continue; |
Chong Zhang | 22bc851 | 2016-04-07 13:47:18 -0700 | [diff] [blame] | 2157 | } |
Jorim Jaggi | fe76234 | 2016-10-13 14:33:27 +0200 | [diff] [blame] | 2158 | final boolean isTop = r == top; |
| 2159 | if (aboveTop && !isTop) { |
| 2160 | continue; |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 2161 | } |
Jorim Jaggi | fe76234 | 2016-10-13 14:33:27 +0200 | [diff] [blame] | 2162 | aboveTop = false; |
Craig Mautner | d44711d | 2013-02-23 11:24:36 -0800 | [diff] [blame] | 2163 | |
Jorim Jaggi | fe76234 | 2016-10-13 14:33:27 +0200 | [diff] [blame] | 2164 | // Check whether activity should be visible without Keyguard influence |
Jorim Jaggi | 241ae10 | 2016-11-02 21:57:33 -0700 | [diff] [blame] | 2165 | final boolean visibleIgnoringKeyguard = r.shouldBeVisibleIgnoringKeyguard( |
Jorim Jaggi | 241ae10 | 2016-11-02 21:57:33 -0700 | [diff] [blame] | 2166 | behindFullscreenActivity); |
Garfield Tan | 47e576c | 2019-01-28 10:26:23 -0800 | [diff] [blame] | 2167 | final boolean reallyVisible = r.shouldBeVisible(behindFullscreenActivity); |
Jorim Jaggi | 241ae10 | 2016-11-02 21:57:33 -0700 | [diff] [blame] | 2168 | if (visibleIgnoringKeyguard) { |
Wale Ogunwale | 04a05ac | 2017-09-17 21:35:02 -0700 | [diff] [blame] | 2169 | behindFullscreenActivity = updateBehindFullscreen(!stackShouldBeVisible, |
Wale Ogunwale | 66e1685 | 2017-10-19 13:35:52 -0700 | [diff] [blame] | 2170 | behindFullscreenActivity, r); |
Jorim Jaggi | fe76234 | 2016-10-13 14:33:27 +0200 | [diff] [blame] | 2171 | } |
| 2172 | if (reallyVisible) { |
| 2173 | if (DEBUG_VISIBILITY) Slog.v(TAG_VISIBILITY, "Make visible? " + r |
Bryce Lee | 7ace395 | 2018-02-16 14:34:32 -0800 | [diff] [blame] | 2174 | + " finishing=" + r.finishing + " state=" + r.getState()); |
Jorim Jaggi | fe76234 | 2016-10-13 14:33:27 +0200 | [diff] [blame] | 2175 | // First: if this is not the current activity being started, make |
| 2176 | // sure it matches the current configuration. |
Andrii Kulian | a39ae3e | 2018-05-31 12:43:54 -0700 | [diff] [blame] | 2177 | if (r != starting && notifyClients) { |
Wale Ogunwale | b6d75f3 | 2018-02-22 20:44:56 -0800 | [diff] [blame] | 2178 | r.ensureActivityConfiguration(0 /* globalChanges */, preserveWindows, |
| 2179 | true /* ignoreStopState */); |
Jorim Jaggi | fe76234 | 2016-10-13 14:33:27 +0200 | [diff] [blame] | 2180 | } |
| 2181 | |
Wale Ogunwale | 9e4f3e0 | 2018-05-17 09:35:39 -0700 | [diff] [blame] | 2182 | if (!r.attachedToProcess()) { |
Jorim Jaggi | fe76234 | 2016-10-13 14:33:27 +0200 | [diff] [blame] | 2183 | if (makeVisibleAndRestartIfNeeded(starting, configChanges, isTop, |
| 2184 | resumeNextActivity, r)) { |
| 2185 | if (activityNdx >= activities.size()) { |
| 2186 | // Record may be removed if its process needs to restart. |
| 2187 | activityNdx = activities.size() - 1; |
| 2188 | } else { |
| 2189 | resumeNextActivity = false; |
| 2190 | } |
| 2191 | } |
| 2192 | } else if (r.visible) { |
| 2193 | // If this activity is already visible, then there is nothing to do here. |
| 2194 | if (DEBUG_VISIBILITY) Slog.v(TAG_VISIBILITY, |
| 2195 | "Skipping: already visible at " + r); |
| 2196 | |
Andrii Kulian | a39ae3e | 2018-05-31 12:43:54 -0700 | [diff] [blame] | 2197 | if (r.mClientVisibilityDeferred && notifyClients) { |
| 2198 | r.makeClientVisible(); |
| 2199 | } |
| 2200 | |
Jorim Jaggi | fe76234 | 2016-10-13 14:33:27 +0200 | [diff] [blame] | 2201 | if (r.handleAlreadyVisible()) { |
Wale Ogunwale | d046a01 | 2015-12-24 13:05:59 -0800 | [diff] [blame] | 2202 | resumeNextActivity = false; |
riddle_hsu | 36ee73d | 2015-06-05 16:38:38 +0800 | [diff] [blame] | 2203 | } |
Andrii Kulian | 6b32151 | 2019-01-23 06:37:00 +0000 | [diff] [blame] | 2204 | |
| 2205 | if (notifyClients) { |
| 2206 | r.makeActiveIfNeeded(starting); |
| 2207 | } |
Jorim Jaggi | fe76234 | 2016-10-13 14:33:27 +0200 | [diff] [blame] | 2208 | } else { |
Andrii Kulian | a39ae3e | 2018-05-31 12:43:54 -0700 | [diff] [blame] | 2209 | r.makeVisibleIfNeeded(starting, notifyClients); |
Craig Mautner | d44711d | 2013-02-23 11:24:36 -0800 | [diff] [blame] | 2210 | } |
Jorim Jaggi | fe76234 | 2016-10-13 14:33:27 +0200 | [diff] [blame] | 2211 | // Aggregate current change flags. |
| 2212 | configChanges |= r.configChangeFlags; |
Craig Mautner | bb74246 | 2014-07-07 15:28:55 -0700 | [diff] [blame] | 2213 | } else { |
Jorim Jaggi | fe76234 | 2016-10-13 14:33:27 +0200 | [diff] [blame] | 2214 | if (DEBUG_VISIBILITY) Slog.v(TAG_VISIBILITY, "Make invisible? " + r |
Bryce Lee | 7ace395 | 2018-02-16 14:34:32 -0800 | [diff] [blame] | 2215 | + " finishing=" + r.finishing + " state=" + r.getState() |
Wale Ogunwale | 04a05ac | 2017-09-17 21:35:02 -0700 | [diff] [blame] | 2216 | + " stackShouldBeVisible=" + stackShouldBeVisible |
Wale Ogunwale | 9dcf946 | 2017-09-19 15:13:01 -0700 | [diff] [blame] | 2217 | + " behindFullscreenActivity=" + behindFullscreenActivity |
| 2218 | + " mLaunchTaskBehind=" + r.mLaunchTaskBehind); |
Wale Ogunwale | c981ad5 | 2017-06-13 11:40:06 -0700 | [diff] [blame] | 2219 | makeInvisible(r); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 2220 | } |
Jorim Jaggi | fe76234 | 2016-10-13 14:33:27 +0200 | [diff] [blame] | 2221 | } |
Wale Ogunwale | 44f036f | 2017-09-29 05:09:09 -0700 | [diff] [blame] | 2222 | final int windowingMode = getWindowingMode(); |
| 2223 | if (windowingMode == WINDOWING_MODE_FREEFORM) { |
Jorim Jaggi | fe76234 | 2016-10-13 14:33:27 +0200 | [diff] [blame] | 2224 | // The visibility of tasks and the activities they contain in freeform stack are |
| 2225 | // determined individually unlike other stacks where the visibility or fullscreen |
| 2226 | // status of an activity in a previous task affects other. |
Wale Ogunwale | 04a05ac | 2017-09-17 21:35:02 -0700 | [diff] [blame] | 2227 | behindFullscreenActivity = !stackShouldBeVisible; |
Wale Ogunwale | 6827856 | 2017-09-23 17:13:55 -0700 | [diff] [blame] | 2228 | } else if (isActivityTypeHome()) { |
Wale Ogunwale | 6fbde9f | 2017-08-24 07:24:12 -0700 | [diff] [blame] | 2229 | if (DEBUG_VISIBILITY) Slog.v(TAG_VISIBILITY, "Home task: at " + task |
Wale Ogunwale | 04a05ac | 2017-09-17 21:35:02 -0700 | [diff] [blame] | 2230 | + " stackShouldBeVisible=" + stackShouldBeVisible |
Wale Ogunwale | 6fbde9f | 2017-08-24 07:24:12 -0700 | [diff] [blame] | 2231 | + " behindFullscreenActivity=" + behindFullscreenActivity); |
| 2232 | // No other task in the home stack should be visible behind the home activity. |
| 2233 | // Home activities is usually a translucent activity with the wallpaper behind |
| 2234 | // them. However, when they don't have the wallpaper behind them, we want to |
| 2235 | // show activities in the next application stack behind them vs. another |
| 2236 | // task in the home stack like recents. |
| 2237 | behindFullscreenActivity = true; |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 2238 | } |
| 2239 | } |
Wale Ogunwale | 74e2659 | 2016-02-05 11:48:37 -0800 | [diff] [blame] | 2240 | |
Jorim Jaggi | fe76234 | 2016-10-13 14:33:27 +0200 | [diff] [blame] | 2241 | if (mTranslucentActivityWaiting != null && |
| 2242 | mUndrawnActivitiesBelowTopTranslucent.isEmpty()) { |
| 2243 | // Nothing is getting drawn or everything was already visible, don't wait for timeout. |
| 2244 | notifyActivityDrawnLocked(null); |
| 2245 | } |
| 2246 | } finally { |
Bryce Lee | 2a3cc46 | 2017-10-27 10:57:35 -0700 | [diff] [blame] | 2247 | mStackSupervisor.getKeyguardController().endActivityVisibilityUpdate(); |
Jorim Jaggi | fe76234 | 2016-10-13 14:33:27 +0200 | [diff] [blame] | 2248 | } |
| 2249 | } |
| 2250 | |
Jorim Jaggi | 8b702ed | 2017-01-20 16:59:03 +0100 | [diff] [blame] | 2251 | void addStartingWindowsForVisibleActivities(boolean taskSwitch) { |
| 2252 | for (int taskNdx = mTaskHistory.size() - 1; taskNdx >= 0; --taskNdx) { |
| 2253 | mTaskHistory.get(taskNdx).addStartingWindowsForVisibleActivities(taskSwitch); |
| 2254 | } |
| 2255 | } |
| 2256 | |
Jorim Jaggi | fe76234 | 2016-10-13 14:33:27 +0200 | [diff] [blame] | 2257 | /** |
| 2258 | * @return true if the top visible activity wants to occlude the Keyguard, false otherwise |
| 2259 | */ |
| 2260 | boolean topActivityOccludesKeyguard() { |
| 2261 | return mTopActivityOccludesKeyguard; |
| 2262 | } |
| 2263 | |
| 2264 | /** |
Wale Ogunwale | 44f036f | 2017-09-29 05:09:09 -0700 | [diff] [blame] | 2265 | * Returns true if this stack should be resized to match the bounds specified by |
| 2266 | * {@link ActivityOptions#setLaunchBounds} when launching an activity into the stack. |
| 2267 | */ |
| 2268 | boolean resizeStackWithLaunchBounds() { |
| 2269 | return inPinnedWindowingMode(); |
| 2270 | } |
| 2271 | |
Wale Ogunwale | 30e441d | 2017-11-09 08:28:45 -0800 | [diff] [blame] | 2272 | @Override |
| 2273 | public boolean supportsSplitScreenWindowingMode() { |
| 2274 | final TaskRecord topTask = topTask(); |
| 2275 | return super.supportsSplitScreenWindowingMode() |
| 2276 | && (topTask == null || topTask.supportsSplitScreenWindowingMode()); |
| 2277 | } |
| 2278 | |
Wale Ogunwale | 2b07da8 | 2017-11-08 14:52:40 -0800 | [diff] [blame] | 2279 | /** @return True if the resizing of the primary-split-screen stack affects this stack size. */ |
| 2280 | boolean affectedBySplitScreenResize() { |
| 2281 | if (!supportsSplitScreenWindowingMode()) { |
| 2282 | return false; |
| 2283 | } |
| 2284 | final int windowingMode = getWindowingMode(); |
| 2285 | return windowingMode != WINDOWING_MODE_FREEFORM && windowingMode != WINDOWING_MODE_PINNED; |
| 2286 | } |
| 2287 | |
Wale Ogunwale | 44f036f | 2017-09-29 05:09:09 -0700 | [diff] [blame] | 2288 | /** |
Jorim Jaggi | fe76234 | 2016-10-13 14:33:27 +0200 | [diff] [blame] | 2289 | * @return the top most visible activity that wants to dismiss Keyguard |
| 2290 | */ |
| 2291 | ActivityRecord getTopDismissingKeyguardActivity() { |
| 2292 | return mTopDismissingKeyguardActivity; |
| 2293 | } |
| 2294 | |
| 2295 | /** |
| 2296 | * Checks whether {@param r} should be visible depending on Keyguard state and updates |
| 2297 | * {@link #mTopActivityOccludesKeyguard} and {@link #mTopDismissingKeyguardActivity} if |
| 2298 | * necessary. |
| 2299 | * |
| 2300 | * @return true if {@param r} is visible taken Keyguard state into account, false otherwise |
| 2301 | */ |
Wale Ogunwale | 2cca862 | 2017-12-11 08:40:13 -0800 | [diff] [blame] | 2302 | boolean checkKeyguardVisibility(ActivityRecord r, boolean shouldBeVisible, boolean isTop) { |
Lucas Dupin | 47a65c7 | 2018-02-15 14:16:18 -0800 | [diff] [blame] | 2303 | final int displayId = mDisplayId != INVALID_DISPLAY ? mDisplayId : DEFAULT_DISPLAY; |
| 2304 | final boolean keyguardOrAodShowing = mStackSupervisor.getKeyguardController() |
| 2305 | .isKeyguardOrAodShowing(displayId); |
Bryce Lee | 2a3cc46 | 2017-10-27 10:57:35 -0700 | [diff] [blame] | 2306 | final boolean keyguardLocked = mStackSupervisor.getKeyguardController().isKeyguardLocked(); |
Wale Ogunwale | 2cca862 | 2017-12-11 08:40:13 -0800 | [diff] [blame] | 2307 | final boolean showWhenLocked = r.canShowWhenLocked(); |
Issei Suzuki | 74e1eb2 | 2018-12-20 17:42:52 +0100 | [diff] [blame] | 2308 | final boolean dismissKeyguard = r.mAppWindowToken != null |
| 2309 | && r.mAppWindowToken.containsDismissKeyguardWindow(); |
Jorim Jaggi | fe76234 | 2016-10-13 14:33:27 +0200 | [diff] [blame] | 2310 | if (shouldBeVisible) { |
Jorim Jaggi | e69c931 | 2016-10-31 18:24:38 -0700 | [diff] [blame] | 2311 | if (dismissKeyguard && mTopDismissingKeyguardActivity == null) { |
Jorim Jaggi | fe76234 | 2016-10-13 14:33:27 +0200 | [diff] [blame] | 2312 | mTopDismissingKeyguardActivity = r; |
| 2313 | } |
| 2314 | |
| 2315 | // Only the top activity may control occluded, as we can't occlude the Keyguard if the |
| 2316 | // top app doesn't want to occlude it. |
| 2317 | if (isTop) { |
| 2318 | mTopActivityOccludesKeyguard |= showWhenLocked; |
Wale Ogunwale | c219c0b | 2015-09-12 09:18:07 -0700 | [diff] [blame] | 2319 | } |
Andrii Kulian | fc8f82b | 2017-01-26 13:17:27 -0800 | [diff] [blame] | 2320 | |
Andrii Kulian | 7211d2e | 2017-01-27 15:58:05 -0800 | [diff] [blame] | 2321 | final boolean canShowWithKeyguard = canShowWithInsecureKeyguard() |
Bryce Lee | 2a3cc46 | 2017-10-27 10:57:35 -0700 | [diff] [blame] | 2322 | && mStackSupervisor.getKeyguardController().canDismissKeyguard(); |
Andrii Kulian | fc8f82b | 2017-01-26 13:17:27 -0800 | [diff] [blame] | 2323 | if (canShowWithKeyguard) { |
| 2324 | return true; |
| 2325 | } |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 2326 | } |
Lucas Dupin | 47a65c7 | 2018-02-15 14:16:18 -0800 | [diff] [blame] | 2327 | if (keyguardOrAodShowing) { |
Jorim Jaggi | e69c931 | 2016-10-31 18:24:38 -0700 | [diff] [blame] | 2328 | // 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] | 2329 | // right away and AOD isn't visible. |
Bryce Lee | 2a3cc46 | 2017-10-27 10:57:35 -0700 | [diff] [blame] | 2330 | return shouldBeVisible && mStackSupervisor.getKeyguardController() |
Jorim Jaggi | 0796187 | 2016-11-23 11:28:57 +0100 | [diff] [blame] | 2331 | .canShowActivityWhileKeyguardShowing(r, dismissKeyguard); |
Jorim Jaggi | fe76234 | 2016-10-13 14:33:27 +0200 | [diff] [blame] | 2332 | } else if (keyguardLocked) { |
Bryce Lee | 2a3cc46 | 2017-10-27 10:57:35 -0700 | [diff] [blame] | 2333 | return shouldBeVisible && mStackSupervisor.getKeyguardController().canShowWhileOccluded( |
Jorim Jaggi | 0796187 | 2016-11-23 11:28:57 +0100 | [diff] [blame] | 2334 | dismissKeyguard, showWhenLocked); |
Jorim Jaggi | fe76234 | 2016-10-13 14:33:27 +0200 | [diff] [blame] | 2335 | } else { |
| 2336 | return shouldBeVisible; |
Craig Mautner | eb8abf7 | 2014-07-02 15:04:09 -0700 | [diff] [blame] | 2337 | } |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 2338 | } |
Craig Mautner | 5854780 | 2013-03-05 08:23:53 -0800 | [diff] [blame] | 2339 | |
Andrii Kulian | fc8f82b | 2017-01-26 13:17:27 -0800 | [diff] [blame] | 2340 | /** |
| 2341 | * Check if the display to which this stack is attached has |
Andrii Kulian | 7211d2e | 2017-01-27 15:58:05 -0800 | [diff] [blame] | 2342 | * {@link Display#FLAG_CAN_SHOW_WITH_INSECURE_KEYGUARD} applied. |
Andrii Kulian | fc8f82b | 2017-01-26 13:17:27 -0800 | [diff] [blame] | 2343 | */ |
wilsonshih | 498a4b8 | 2018-12-11 16:10:16 +0800 | [diff] [blame] | 2344 | boolean canShowWithInsecureKeyguard() { |
Wale Ogunwale | 9dcf946 | 2017-09-19 15:13:01 -0700 | [diff] [blame] | 2345 | final ActivityDisplay activityDisplay = getDisplay(); |
Andrii Kulian | fc8f82b | 2017-01-26 13:17:27 -0800 | [diff] [blame] | 2346 | if (activityDisplay == null) { |
| 2347 | throw new IllegalStateException("Stack is not attached to any display, stackId=" |
| 2348 | + mStackId); |
| 2349 | } |
| 2350 | |
| 2351 | final int flags = activityDisplay.mDisplay.getFlags(); |
Andrii Kulian | 7211d2e | 2017-01-27 15:58:05 -0800 | [diff] [blame] | 2352 | return (flags & FLAG_CAN_SHOW_WITH_INSECURE_KEYGUARD) != 0; |
Andrii Kulian | fc8f82b | 2017-01-26 13:17:27 -0800 | [diff] [blame] | 2353 | } |
| 2354 | |
Filip Gruszczynski | 9104aea | 2015-11-13 16:42:05 -0800 | [diff] [blame] | 2355 | private void checkTranslucentActivityWaiting(ActivityRecord top) { |
| 2356 | if (mTranslucentActivityWaiting != top) { |
| 2357 | mUndrawnActivitiesBelowTopTranslucent.clear(); |
| 2358 | if (mTranslucentActivityWaiting != null) { |
| 2359 | // Call the callback with a timeout indication. |
| 2360 | notifyActivityDrawnLocked(null); |
| 2361 | mTranslucentActivityWaiting = null; |
| 2362 | } |
| 2363 | mHandler.removeMessages(TRANSLUCENT_TIMEOUT_MSG); |
| 2364 | } |
| 2365 | } |
| 2366 | |
| 2367 | private boolean makeVisibleAndRestartIfNeeded(ActivityRecord starting, int configChanges, |
Wale Ogunwale | d046a01 | 2015-12-24 13:05:59 -0800 | [diff] [blame] | 2368 | boolean isTop, boolean andResume, ActivityRecord r) { |
Filip Gruszczynski | 9104aea | 2015-11-13 16:42:05 -0800 | [diff] [blame] | 2369 | // We need to make sure the app is running if it's the top, or it is just made visible from |
| 2370 | // invisible. If the app is already visible, it must have died while it was visible. In this |
| 2371 | // case, we'll show the dead window but will not restart the app. Otherwise we could end up |
| 2372 | // thrashing. |
Filip Gruszczynski | 21199bd | 2015-12-02 12:49:58 -0800 | [diff] [blame] | 2373 | if (isTop || !r.visible) { |
Filip Gruszczynski | 9104aea | 2015-11-13 16:42:05 -0800 | [diff] [blame] | 2374 | // This activity needs to be visible, but isn't even running... |
| 2375 | // get it started and resume if no other stack in this stack is resumed. |
| 2376 | if (DEBUG_VISIBILITY) Slog.v(TAG_VISIBILITY, "Start and freeze screen for " + r); |
| 2377 | if (r != starting) { |
| 2378 | r.startFreezingScreenLocked(r.app, configChanges); |
| 2379 | } |
| 2380 | if (!r.visible || r.mLaunchTaskBehind) { |
| 2381 | if (DEBUG_VISIBILITY) Slog.v(TAG_VISIBILITY, "Starting and making visible: " + r); |
Andrii Kulian | 21713ac | 2016-10-12 22:05:05 -0700 | [diff] [blame] | 2382 | r.setVisible(true); |
Filip Gruszczynski | 9104aea | 2015-11-13 16:42:05 -0800 | [diff] [blame] | 2383 | } |
| 2384 | if (r != starting) { |
Louis Chang | 7cf8460 | 2019-05-30 15:35:40 +0800 | [diff] [blame] | 2385 | // We should not resume activities that being launched behind because these |
| 2386 | // activities are actually behind other fullscreen activities, but still required |
| 2387 | // to be visible (such as performing Recents animation). |
| 2388 | mStackSupervisor.startSpecificActivityLocked(r, andResume && !r.mLaunchTaskBehind, |
| 2389 | true /* checkConfig */); |
Filip Gruszczynski | 9104aea | 2015-11-13 16:42:05 -0800 | [diff] [blame] | 2390 | return true; |
| 2391 | } |
| 2392 | } |
| 2393 | return false; |
| 2394 | } |
| 2395 | |
Wale Ogunwale | c981ad5 | 2017-06-13 11:40:06 -0700 | [diff] [blame] | 2396 | // TODO: Should probably be moved into ActivityRecord. |
| 2397 | private void makeInvisible(ActivityRecord r) { |
Filip Gruszczynski | 9104aea | 2015-11-13 16:42:05 -0800 | [diff] [blame] | 2398 | if (!r.visible) { |
| 2399 | if (DEBUG_VISIBILITY) Slog.v(TAG_VISIBILITY, "Already invisible: " + r); |
| 2400 | return; |
| 2401 | } |
| 2402 | // Now for any activities that aren't visible to the user, make sure they no longer are |
| 2403 | // keeping the screen frozen. |
Bryce Lee | 7ace395 | 2018-02-16 14:34:32 -0800 | [diff] [blame] | 2404 | if (DEBUG_VISIBILITY) Slog.v(TAG_VISIBILITY, "Making invisible: " + r + " " + r.getState()); |
Filip Gruszczynski | 9104aea | 2015-11-13 16:42:05 -0800 | [diff] [blame] | 2405 | try { |
Wale Ogunwale | b9a0c99 | 2017-04-18 07:25:20 -0700 | [diff] [blame] | 2406 | final boolean canEnterPictureInPicture = r.checkEnterPictureInPictureState( |
Winson Chung | 298f95b | 2017-08-10 15:57:18 -0700 | [diff] [blame] | 2407 | "makeInvisible", true /* beforeStopping */); |
Wale Ogunwale | 08488a6 | 2017-09-05 12:37:03 -0700 | [diff] [blame] | 2408 | // Defer telling the client it is hidden if it can enter Pip and isn't current paused, |
| 2409 | // stopped or stopping. This gives it a chance to enter Pip in onPause(). |
| 2410 | // TODO: There is still a question surrounding activities in multi-window mode that want |
| 2411 | // to enter Pip after they are paused, but are still visible. I they should be okay to |
| 2412 | // enter Pip in those cases, but not "auto-Pip" which is what this condition covers and |
| 2413 | // the current contract for "auto-Pip" is that the app should enter it before onPause |
| 2414 | // returns. Just need to confirm this reasoning makes sense. |
Wale Ogunwale | 8997322 | 2017-04-23 18:39:45 -0700 | [diff] [blame] | 2415 | final boolean deferHidingClient = canEnterPictureInPicture |
Bryce Lee | 7ace395 | 2018-02-16 14:34:32 -0800 | [diff] [blame] | 2416 | && !r.isState(STOPPING, STOPPED, PAUSED); |
Wale Ogunwale | ec95064 | 2017-04-25 07:44:21 -0700 | [diff] [blame] | 2417 | r.setDeferHidingClient(deferHidingClient); |
| 2418 | r.setVisible(false); |
Wale Ogunwale | b9a0c99 | 2017-04-18 07:25:20 -0700 | [diff] [blame] | 2419 | |
Bryce Lee | 7ace395 | 2018-02-16 14:34:32 -0800 | [diff] [blame] | 2420 | switch (r.getState()) { |
Filip Gruszczynski | 9104aea | 2015-11-13 16:42:05 -0800 | [diff] [blame] | 2421 | case STOPPING: |
| 2422 | case STOPPED: |
Wale Ogunwale | 9e4f3e0 | 2018-05-17 09:35:39 -0700 | [diff] [blame] | 2423 | if (r.attachedToProcess()) { |
Filip Gruszczynski | 9104aea | 2015-11-13 16:42:05 -0800 | [diff] [blame] | 2424 | if (DEBUG_VISIBILITY) Slog.v(TAG_VISIBILITY, |
| 2425 | "Scheduling invisibility: " + r); |
Wale Ogunwale | 9e4f3e0 | 2018-05-17 09:35:39 -0700 | [diff] [blame] | 2426 | mService.getLifecycleManager().scheduleTransaction(r.app.getThread(), |
| 2427 | r.appToken, WindowVisibilityItem.obtain(false /* showWindow */)); |
Filip Gruszczynski | 9104aea | 2015-11-13 16:42:05 -0800 | [diff] [blame] | 2428 | } |
Winson Chung | c2baac0 | 2017-01-11 13:34:47 -0800 | [diff] [blame] | 2429 | |
| 2430 | // Reset the flag indicating that an app can enter picture-in-picture once the |
| 2431 | // activity is hidden |
Winson Chung | f7e03e1 | 2017-08-22 11:32:16 -0700 | [diff] [blame] | 2432 | r.supportsEnterPipOnTaskSwitch = false; |
Filip Gruszczynski | 9104aea | 2015-11-13 16:42:05 -0800 | [diff] [blame] | 2433 | break; |
| 2434 | |
| 2435 | case INITIALIZING: |
| 2436 | case RESUMED: |
| 2437 | case PAUSING: |
| 2438 | case PAUSED: |
Wale Ogunwale | c981ad5 | 2017-06-13 11:40:06 -0700 | [diff] [blame] | 2439 | addToStopping(r, true /* scheduleIdle */, |
wilsonshih | 401e50f | 2019-04-30 12:55:48 +0800 | [diff] [blame] | 2440 | canEnterPictureInPicture /* idleDelayed */, "makeInvisible"); |
Filip Gruszczynski | 9104aea | 2015-11-13 16:42:05 -0800 | [diff] [blame] | 2441 | break; |
| 2442 | |
| 2443 | default: |
| 2444 | break; |
| 2445 | } |
| 2446 | } catch (Exception e) { |
| 2447 | // Just skip on any failure; we'll make it visible when it next restarts. |
| 2448 | Slog.w(TAG, "Exception thrown making hidden: " + r.intent.getComponent(), e); |
| 2449 | } |
| 2450 | } |
| 2451 | |
| 2452 | private boolean updateBehindFullscreen(boolean stackInvisible, boolean behindFullscreenActivity, |
Wale Ogunwale | 66e1685 | 2017-10-19 13:35:52 -0700 | [diff] [blame] | 2453 | ActivityRecord r) { |
Filip Gruszczynski | 9104aea | 2015-11-13 16:42:05 -0800 | [diff] [blame] | 2454 | if (r.fullscreen) { |
Filip Gruszczynski | 9104aea | 2015-11-13 16:42:05 -0800 | [diff] [blame] | 2455 | if (DEBUG_VISIBILITY) Slog.v(TAG_VISIBILITY, "Fullscreen: at " + r |
Wale Ogunwale | 673cbd2 | 2016-01-30 18:30:55 -0800 | [diff] [blame] | 2456 | + " stackInvisible=" + stackInvisible |
| 2457 | + " behindFullscreenActivity=" + behindFullscreenActivity); |
Filip Gruszczynski | 0e381e2 | 2016-01-14 16:31:33 -0800 | [diff] [blame] | 2458 | // At this point, nothing else needs to be shown in this task. |
Filip Gruszczynski | 9104aea | 2015-11-13 16:42:05 -0800 | [diff] [blame] | 2459 | behindFullscreenActivity = true; |
Filip Gruszczynski | 9104aea | 2015-11-13 16:42:05 -0800 | [diff] [blame] | 2460 | } |
| 2461 | return behindFullscreenActivity; |
| 2462 | } |
| 2463 | |
Todd Kennedy | aab56db | 2015-01-30 09:39:53 -0800 | [diff] [blame] | 2464 | void convertActivityToTranslucent(ActivityRecord r) { |
Craig Mautner | 5eda9b3 | 2013-07-02 11:58:16 -0700 | [diff] [blame] | 2465 | mTranslucentActivityWaiting = r; |
| 2466 | mUndrawnActivitiesBelowTopTranslucent.clear(); |
| 2467 | mHandler.sendEmptyMessageDelayed(TRANSLUCENT_TIMEOUT_MSG, TRANSLUCENT_CONVERSION_TIMEOUT); |
| 2468 | } |
| 2469 | |
Dianne Hackborn | b5a380d | 2015-05-20 18:18:46 -0700 | [diff] [blame] | 2470 | void clearOtherAppTimeTrackers(AppTimeTracker except) { |
| 2471 | for (int taskNdx = mTaskHistory.size() - 1; taskNdx >= 0; --taskNdx) { |
| 2472 | final TaskRecord task = mTaskHistory.get(taskNdx); |
| 2473 | final ArrayList<ActivityRecord> activities = task.mActivities; |
| 2474 | for (int activityNdx = activities.size() - 1; activityNdx >= 0; --activityNdx) { |
| 2475 | final ActivityRecord r = activities.get(activityNdx); |
| 2476 | if ( r.appTimeTracker != except) { |
| 2477 | r.appTimeTracker = null; |
| 2478 | } |
| 2479 | } |
| 2480 | } |
| 2481 | } |
| 2482 | |
Craig Mautner | 5eda9b3 | 2013-07-02 11:58:16 -0700 | [diff] [blame] | 2483 | /** |
| 2484 | * Called as activities below the top translucent activity are redrawn. When the last one is |
| 2485 | * redrawn notify the top activity by calling |
| 2486 | * {@link Activity#onTranslucentConversionComplete}. |
| 2487 | * |
| 2488 | * @param r The most recent background activity to be drawn. Or, if r is null then a timeout |
| 2489 | * occurred and the activity will be notified immediately. |
| 2490 | */ |
| 2491 | void notifyActivityDrawnLocked(ActivityRecord r) { |
| 2492 | if ((r == null) |
| 2493 | || (mUndrawnActivitiesBelowTopTranslucent.remove(r) && |
| 2494 | mUndrawnActivitiesBelowTopTranslucent.isEmpty())) { |
| 2495 | // The last undrawn activity below the top has just been drawn. If there is an |
| 2496 | // opaque activity at the top, notify it that it can become translucent safely now. |
| 2497 | final ActivityRecord waitingActivity = mTranslucentActivityWaiting; |
| 2498 | mTranslucentActivityWaiting = null; |
| 2499 | mUndrawnActivitiesBelowTopTranslucent.clear(); |
| 2500 | mHandler.removeMessages(TRANSLUCENT_TIMEOUT_MSG); |
| 2501 | |
Craig Mautner | 71dd1b6 | 2014-02-18 15:48:52 -0800 | [diff] [blame] | 2502 | if (waitingActivity != null) { |
| 2503 | mWindowManager.setWindowOpaque(waitingActivity.appToken, false); |
Wale Ogunwale | 9e4f3e0 | 2018-05-17 09:35:39 -0700 | [diff] [blame] | 2504 | if (waitingActivity.attachedToProcess()) { |
Craig Mautner | 71dd1b6 | 2014-02-18 15:48:52 -0800 | [diff] [blame] | 2505 | try { |
Wale Ogunwale | 9e4f3e0 | 2018-05-17 09:35:39 -0700 | [diff] [blame] | 2506 | waitingActivity.app.getThread().scheduleTranslucentConversionComplete( |
Craig Mautner | 71dd1b6 | 2014-02-18 15:48:52 -0800 | [diff] [blame] | 2507 | waitingActivity.appToken, r != null); |
| 2508 | } catch (RemoteException e) { |
| 2509 | } |
Craig Mautner | 5eda9b3 | 2013-07-02 11:58:16 -0700 | [diff] [blame] | 2510 | } |
| 2511 | } |
| 2512 | } |
| 2513 | } |
| 2514 | |
Craig Mautner | a61bc65 | 2013-10-28 15:43:18 -0700 | [diff] [blame] | 2515 | /** If any activities below the top running one are in the INITIALIZING state and they have a |
| 2516 | * starting window displayed then remove that starting window. It is possible that the activity |
| 2517 | * in this state will never resumed in which case that starting window will be orphaned. */ |
| 2518 | void cancelInitializingActivities() { |
Filip Gruszczynski | 3e85ba2 | 2015-10-05 22:48:30 -0700 | [diff] [blame] | 2519 | final ActivityRecord topActivity = topRunningActivityLocked(); |
Craig Mautner | a61bc65 | 2013-10-28 15:43:18 -0700 | [diff] [blame] | 2520 | boolean aboveTop = true; |
Wale Ogunwale | 6874114 | 2016-05-17 09:40:02 -0700 | [diff] [blame] | 2521 | // We don't want to clear starting window for activities that aren't behind fullscreen |
| 2522 | // activities as we need to display their starting window until they are done initializing. |
| 2523 | boolean behindFullscreenActivity = false; |
Wale Ogunwale | 98742a5 | 2016-07-12 10:29:12 -0700 | [diff] [blame] | 2524 | |
Wale Ogunwale | 9dcf946 | 2017-09-19 15:13:01 -0700 | [diff] [blame] | 2525 | if (!shouldBeVisible(null)) { |
Wale Ogunwale | 98742a5 | 2016-07-12 10:29:12 -0700 | [diff] [blame] | 2526 | // The stack is not visible, so no activity in it should be displaying a starting |
| 2527 | // window. Mark all activities below top and behind fullscreen. |
| 2528 | aboveTop = false; |
| 2529 | behindFullscreenActivity = true; |
| 2530 | } |
| 2531 | |
Craig Mautner | a61bc65 | 2013-10-28 15:43:18 -0700 | [diff] [blame] | 2532 | for (int taskNdx = mTaskHistory.size() - 1; taskNdx >= 0; --taskNdx) { |
| 2533 | final ArrayList<ActivityRecord> activities = mTaskHistory.get(taskNdx).mActivities; |
| 2534 | for (int activityNdx = activities.size() - 1; activityNdx >= 0; --activityNdx) { |
| 2535 | final ActivityRecord r = activities.get(activityNdx); |
| 2536 | if (aboveTop) { |
| 2537 | if (r == topActivity) { |
| 2538 | aboveTop = false; |
| 2539 | } |
Wale Ogunwale | 6874114 | 2016-05-17 09:40:02 -0700 | [diff] [blame] | 2540 | behindFullscreenActivity |= r.fullscreen; |
Craig Mautner | a61bc65 | 2013-10-28 15:43:18 -0700 | [diff] [blame] | 2541 | continue; |
| 2542 | } |
| 2543 | |
Wale Ogunwale | 26c0dfe | 2016-12-14 14:42:30 -0800 | [diff] [blame] | 2544 | r.removeOrphanedStartingWindow(behindFullscreenActivity); |
Wale Ogunwale | 6874114 | 2016-05-17 09:40:02 -0700 | [diff] [blame] | 2545 | behindFullscreenActivity |= r.fullscreen; |
Craig Mautner | a61bc65 | 2013-10-28 15:43:18 -0700 | [diff] [blame] | 2546 | } |
| 2547 | } |
| 2548 | } |
| 2549 | |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 2550 | /** |
| 2551 | * Ensure that the top activity in the stack is resumed. |
| 2552 | * |
| 2553 | * @param prev The previously resumed activity, for when in the process |
| 2554 | * of pausing; can be null to call from elsewhere. |
Wale Ogunwale | d046a01 | 2015-12-24 13:05:59 -0800 | [diff] [blame] | 2555 | * @param options Activity options. |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 2556 | * |
| 2557 | * @return Returns true if something is being resumed, or false if |
| 2558 | * nothing happened. |
Wale Ogunwale | d046a01 | 2015-12-24 13:05:59 -0800 | [diff] [blame] | 2559 | * |
| 2560 | * NOTE: It is not safe to call this method directly as it can cause an activity in a |
| 2561 | * non-focused stack to be resumed. |
Wale Ogunwale | d32da47 | 2018-11-16 07:19:28 -0800 | [diff] [blame] | 2562 | * Use {@link RootActivityContainer#resumeFocusedStacksTopActivities} to resume the |
Wale Ogunwale | d046a01 | 2015-12-24 13:05:59 -0800 | [diff] [blame] | 2563 | * right activity for the current system state. |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 2564 | */ |
Andreas Gampe | a36dc62 | 2018-02-05 17:19:22 -0800 | [diff] [blame] | 2565 | @GuardedBy("mService") |
Wale Ogunwale | d046a01 | 2015-12-24 13:05:59 -0800 | [diff] [blame] | 2566 | boolean resumeTopActivityUncheckedLocked(ActivityRecord prev, ActivityOptions options) { |
Andrii Kulian | 6b32151 | 2019-01-23 06:37:00 +0000 | [diff] [blame] | 2567 | if (mInResumeTopActivity) { |
Craig Mautner | 544efa7 | 2014-09-04 16:41:20 -0700 | [diff] [blame] | 2568 | // Don't even start recursing. |
| 2569 | return false; |
| 2570 | } |
| 2571 | |
| 2572 | boolean result = false; |
| 2573 | try { |
| 2574 | // Protect against recursion. |
Andrii Kulian | 6b32151 | 2019-01-23 06:37:00 +0000 | [diff] [blame] | 2575 | mInResumeTopActivity = true; |
Bryce Lee | 69ad818 | 2017-09-28 10:01:36 -0700 | [diff] [blame] | 2576 | result = resumeTopActivityInnerLocked(prev, options); |
Bryce Lee | fc7cedd | 2018-03-01 15:38:07 -0800 | [diff] [blame] | 2577 | |
| 2578 | // When resuming the top activity, it may be necessary to pause the top activity (for |
| 2579 | // example, returning to the lock screen. We suppress the normal pause logic in |
| 2580 | // {@link #resumeTopActivityUncheckedLocked}, since the top activity is resumed at the |
| 2581 | // end. We call the {@link ActivityStackSupervisor#checkReadyForSleepLocked} again here |
| 2582 | // to ensure any necessary pause logic occurs. In the case where the Activity will be |
| 2583 | // shown regardless of the lock screen, the call to |
| 2584 | // {@link ActivityStackSupervisor#checkReadyForSleepLocked} is skipped. |
| 2585 | final ActivityRecord next = topRunningActivityLocked(true /* focusableOnly */); |
| 2586 | if (next == null || !next.canTurnScreenOn()) { |
| 2587 | checkReadyForSleep(); |
| 2588 | } |
Craig Mautner | 544efa7 | 2014-09-04 16:41:20 -0700 | [diff] [blame] | 2589 | } finally { |
Andrii Kulian | 6b32151 | 2019-01-23 06:37:00 +0000 | [diff] [blame] | 2590 | mInResumeTopActivity = false; |
Craig Mautner | 544efa7 | 2014-09-04 16:41:20 -0700 | [diff] [blame] | 2591 | } |
chaviw | 59b9885 | 2017-06-13 12:05:44 -0700 | [diff] [blame] | 2592 | |
Craig Mautner | 544efa7 | 2014-09-04 16:41:20 -0700 | [diff] [blame] | 2593 | return result; |
| 2594 | } |
| 2595 | |
Bryce Lee | c4ab62a | 2018-03-05 14:19:26 -0800 | [diff] [blame] | 2596 | /** |
| 2597 | * Returns the currently resumed activity. |
| 2598 | */ |
| 2599 | protected ActivityRecord getResumedActivity() { |
| 2600 | return mResumedActivity; |
| 2601 | } |
| 2602 | |
Bryce Lee | 84730a0 | 2018-04-03 14:10:04 -0700 | [diff] [blame] | 2603 | private void setResumedActivity(ActivityRecord r, String reason) { |
| 2604 | if (mResumedActivity == r) { |
| 2605 | return; |
| 2606 | } |
Bryce Lee | c4ab62a | 2018-03-05 14:19:26 -0800 | [diff] [blame] | 2607 | |
Bryce Lee | 84730a0 | 2018-04-03 14:10:04 -0700 | [diff] [blame] | 2608 | if (DEBUG_STACK) Slog.d(TAG_STACK, "setResumedActivity stack:" + this + " + from: " |
| 2609 | + mResumedActivity + " to:" + r + " reason:" + reason); |
| 2610 | mResumedActivity = r; |
Louis Chang | 3b21bdc | 2019-03-25 15:49:14 +0800 | [diff] [blame] | 2611 | mStackSupervisor.updateTopResumedActivityIfNeeded(); |
Chong Zhang | 6cda19c | 2016-06-14 19:07:56 -0700 | [diff] [blame] | 2612 | } |
| 2613 | |
Andreas Gampe | a36dc62 | 2018-02-05 17:19:22 -0800 | [diff] [blame] | 2614 | @GuardedBy("mService") |
Chong Zhang | 280d332 | 2015-11-03 17:27:26 -0800 | [diff] [blame] | 2615 | private boolean resumeTopActivityInnerLocked(ActivityRecord prev, ActivityOptions options) { |
Wale Ogunwale | 5378374 | 2018-09-16 10:21:51 -0700 | [diff] [blame] | 2616 | if (!mService.isBooting() && !mService.isBooted()) { |
Dianne Hackborn | 7622a0f | 2014-09-30 14:31:42 -0700 | [diff] [blame] | 2617 | // Not ready yet! |
| 2618 | return false; |
| 2619 | } |
| 2620 | |
Winson Chung | 3f103eb | 2017-04-12 21:53:59 -0700 | [diff] [blame] | 2621 | // Find the next top-most activity to resume in this stack that is not finishing and is |
| 2622 | // focusable. If it is not focusable, we will fall into the case below to resume the |
| 2623 | // top activity in the next focusable task. |
Andrii Kulian | 6b32151 | 2019-01-23 06:37:00 +0000 | [diff] [blame] | 2624 | ActivityRecord next = topRunningActivityLocked(true /* focusableOnly */); |
Andrii Kulian | 7fc2281 | 2016-12-28 13:04:11 -0800 | [diff] [blame] | 2625 | |
| 2626 | final boolean hasRunningActivity = next != null; |
| 2627 | |
Andrii Kulian | 94e82d9b0 | 2017-07-13 15:33:06 -0700 | [diff] [blame] | 2628 | // TODO: Maybe this entire condition can get removed? |
Wale Ogunwale | 66e1685 | 2017-10-19 13:35:52 -0700 | [diff] [blame] | 2629 | if (hasRunningActivity && !isAttached()) { |
Craig Mautner | df88d73 | 2014-01-27 09:21:32 -0800 | [diff] [blame] | 2630 | return false; |
| 2631 | } |
| 2632 | |
Wale Ogunwale | d32da47 | 2018-11-16 07:19:28 -0800 | [diff] [blame] | 2633 | mRootActivityContainer.cancelInitializingActivities(); |
Craig Mautner | a61bc65 | 2013-10-28 15:43:18 -0700 | [diff] [blame] | 2634 | |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 2635 | // Remember how we'll process this pause/resume situation, and ensure |
| 2636 | // that the state is reset however we wind up proceeding. |
Wale Ogunwale | c59b4f6 | 2017-11-30 11:05:43 -0800 | [diff] [blame] | 2637 | boolean userLeaving = mStackSupervisor.mUserLeaving; |
Craig Mautner | de4ef02 | 2013-04-07 19:01:33 -0700 | [diff] [blame] | 2638 | mStackSupervisor.mUserLeaving = false; |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 2639 | |
Andrii Kulian | 7fc2281 | 2016-12-28 13:04:11 -0800 | [diff] [blame] | 2640 | if (!hasRunningActivity) { |
| 2641 | // There are no activities left in the stack, let's look somewhere else. |
Andrii Kulian | 3ff5a0b | 2019-05-16 13:18:04 -0700 | [diff] [blame] | 2642 | return resumeNextFocusableActivityWhenStackIsEmpty(prev, options); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 2643 | } |
| 2644 | |
| 2645 | next.delayedResume = false; |
Riddle Hsu | bbb63c2 | 2018-10-03 12:28:29 +0800 | [diff] [blame] | 2646 | final ActivityDisplay display = getDisplay(); |
Craig Mautner | 5854780 | 2013-03-05 08:23:53 -0800 | [diff] [blame] | 2647 | |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 2648 | // If the top activity is the resumed one, nothing to do. |
Bryce Lee | 7ace395 | 2018-02-16 14:34:32 -0800 | [diff] [blame] | 2649 | if (mResumedActivity == next && next.isState(RESUMED) |
Riddle Hsu | bbb63c2 | 2018-10-03 12:28:29 +0800 | [diff] [blame] | 2650 | && display.allResumedActivitiesComplete()) { |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 2651 | // Make sure we have executed any pending transitions, since there |
| 2652 | // should be nothing left to do at this point. |
skuhne@google.com | 1b974dc | 2016-12-09 13:41:29 -0800 | [diff] [blame] | 2653 | executeAppTransition(options); |
Wale Ogunwale | 0fc365c | 2015-05-25 19:35:42 -0700 | [diff] [blame] | 2654 | if (DEBUG_STATES) Slog.d(TAG_STATES, |
| 2655 | "resumeTopActivityLocked: Top activity resumed " + next); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 2656 | return false; |
| 2657 | } |
| 2658 | |
Louis Chang | 77ce34d | 2019-01-03 15:45:12 +0800 | [diff] [blame] | 2659 | if (!next.canResumeByCompat()) { |
| 2660 | return false; |
| 2661 | } |
| 2662 | |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 2663 | // If we are sleeping, and there is no resumed activity, and the top |
| 2664 | // activity is paused, well that is the state we want. |
David Stevens | 9440dc8 | 2017-03-16 19:00:20 -0700 | [diff] [blame] | 2665 | if (shouldSleepOrShutDownActivities() |
p13451 | dbad287 | 2012-04-18 11:39:23 +0900 | [diff] [blame] | 2666 | && mLastPausedActivity == next |
Wale Ogunwale | d32da47 | 2018-11-16 07:19:28 -0800 | [diff] [blame] | 2667 | && mRootActivityContainer.allPausedActivitiesComplete()) { |
Riddle Hsu | ef71377 | 2018-09-18 01:28:53 +0800 | [diff] [blame] | 2668 | // If the current top activity may be able to occlude keyguard but the occluded state |
| 2669 | // has not been set, update visibility and check again if we should continue to resume. |
| 2670 | boolean nothingToResume = true; |
Riddle Hsu | 32a87b8 | 2018-11-21 00:08:19 +0800 | [diff] [blame] | 2671 | if (!mService.mShuttingDown) { |
| 2672 | final boolean canShowWhenLocked = !mTopActivityOccludesKeyguard |
| 2673 | && next.canShowWhenLocked(); |
| 2674 | final boolean mayDismissKeyguard = mTopDismissingKeyguardActivity != next |
Issei Suzuki | 74e1eb2 | 2018-12-20 17:42:52 +0100 | [diff] [blame] | 2675 | && next.mAppWindowToken != null |
| 2676 | && next.mAppWindowToken.containsDismissKeyguardWindow(); |
| 2677 | |
Riddle Hsu | 32a87b8 | 2018-11-21 00:08:19 +0800 | [diff] [blame] | 2678 | if (canShowWhenLocked || mayDismissKeyguard) { |
| 2679 | ensureActivitiesVisibleLocked(null /* starting */, 0 /* configChanges */, |
| 2680 | !PRESERVE_WINDOWS); |
| 2681 | nothingToResume = shouldSleepActivities(); |
| 2682 | } |
Riddle Hsu | ef71377 | 2018-09-18 01:28:53 +0800 | [diff] [blame] | 2683 | } |
| 2684 | if (nothingToResume) { |
| 2685 | // Make sure we have executed any pending transitions, since there |
| 2686 | // should be nothing left to do at this point. |
| 2687 | executeAppTransition(options); |
| 2688 | if (DEBUG_STATES) Slog.d(TAG_STATES, |
| 2689 | "resumeTopActivityLocked: Going to sleep and all paused"); |
Riddle Hsu | ef71377 | 2018-09-18 01:28:53 +0800 | [diff] [blame] | 2690 | return false; |
| 2691 | } |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 2692 | } |
Dianne Hackborn | 80a4af2 | 2012-08-27 19:18:31 -0700 | [diff] [blame] | 2693 | |
| 2694 | // Make sure that the user who owns this activity is started. If not, |
| 2695 | // we will just leave it as is because someone should be bringing |
| 2696 | // another user's activities to the top of the stack. |
Wale Ogunwale | 8b19de9 | 2018-11-29 19:58:26 -0800 | [diff] [blame] | 2697 | if (!mService.mAmInternal.hasStartedUserState(next.mUserId)) { |
Dianne Hackborn | 80a4af2 | 2012-08-27 19:18:31 -0700 | [diff] [blame] | 2698 | Slog.w(TAG, "Skipping resume of top activity " + next |
Wale Ogunwale | 8b19de9 | 2018-11-29 19:58:26 -0800 | [diff] [blame] | 2699 | + ": user " + next.mUserId + " is stopped"); |
Dianne Hackborn | 80a4af2 | 2012-08-27 19:18:31 -0700 | [diff] [blame] | 2700 | return false; |
| 2701 | } |
| 2702 | |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 2703 | // The activity may be waiting for stop, but that is no longer |
| 2704 | // appropriate for it. |
Craig Mautner | de4ef02 | 2013-04-07 19:01:33 -0700 | [diff] [blame] | 2705 | mStackSupervisor.mStoppingActivities.remove(next); |
Craig Mautner | 0eea92c | 2013-05-16 13:35:39 -0700 | [diff] [blame] | 2706 | mStackSupervisor.mGoingToSleepActivities.remove(next); |
Dianne Hackborn | 4eba96b | 2011-01-21 13:34:36 -0800 | [diff] [blame] | 2707 | next.sleeping = false; |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 2708 | |
Wale Ogunwale | ee006da | 2015-03-30 14:49:25 -0700 | [diff] [blame] | 2709 | if (DEBUG_SWITCH) Slog.v(TAG_SWITCH, "Resuming " + next); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 2710 | |
Wale Ogunwale | 5658e4b | 2016-02-12 12:22:19 -0800 | [diff] [blame] | 2711 | // 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] | 2712 | if (!mRootActivityContainer.allPausedActivitiesComplete()) { |
Wale Ogunwale | ee006da | 2015-03-30 14:49:25 -0700 | [diff] [blame] | 2713 | if (DEBUG_SWITCH || DEBUG_PAUSE || DEBUG_STATES) Slog.v(TAG_PAUSE, |
Craig Mautner | ac6f843 | 2013-07-17 13:24:59 -0700 | [diff] [blame] | 2714 | "resumeTopActivityLocked: Skip resume: some activity pausing."); |
Andrii Kulian | 6b32151 | 2019-01-23 06:37:00 +0000 | [diff] [blame] | 2715 | |
Dianne Hackborn | 621e2fe | 2012-02-16 17:07:33 -0800 | [diff] [blame] | 2716 | return false; |
| 2717 | } |
| 2718 | |
Dianne Hackborn | 3d07c94 | 2015-03-13 18:02:54 -0700 | [diff] [blame] | 2719 | mStackSupervisor.setLaunchSource(next.info.applicationInfo.uid); |
| 2720 | |
Wale Ogunwale | 8997322 | 2017-04-23 18:39:45 -0700 | [diff] [blame] | 2721 | boolean lastResumedCanPip = false; |
chaviw | 4ad5491 | 2018-05-30 11:05:44 -0700 | [diff] [blame] | 2722 | ActivityRecord lastResumed = null; |
Riddle Hsu | bbb63c2 | 2018-10-03 12:28:29 +0800 | [diff] [blame] | 2723 | final ActivityStack lastFocusedStack = display.getLastFocusedStack(); |
Wale Ogunwale | 8997322 | 2017-04-23 18:39:45 -0700 | [diff] [blame] | 2724 | if (lastFocusedStack != null && lastFocusedStack != this) { |
| 2725 | // So, why aren't we using prev here??? See the param comment on the method. prev doesn't |
| 2726 | // 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] | 2727 | lastResumed = lastFocusedStack.mResumedActivity; |
Wale Ogunwale | c59b4f6 | 2017-11-30 11:05:43 -0800 | [diff] [blame] | 2728 | if (userLeaving && inMultiWindowMode() && lastFocusedStack.shouldBeVisible(next)) { |
| 2729 | // The user isn't leaving if this stack is the multi-window mode and the last |
| 2730 | // focused stack should still be visible. |
| 2731 | if(DEBUG_USER_LEAVING) Slog.i(TAG_USER_LEAVING, "Overriding userLeaving to false" |
| 2732 | + " next=" + next + " lastResumed=" + lastResumed); |
| 2733 | userLeaving = false; |
| 2734 | } |
Wale Ogunwale | 8997322 | 2017-04-23 18:39:45 -0700 | [diff] [blame] | 2735 | lastResumedCanPip = lastResumed != null && lastResumed.checkEnterPictureInPictureState( |
Winson Chung | 298f95b | 2017-08-10 15:57:18 -0700 | [diff] [blame] | 2736 | "resumeTopActivity", userLeaving /* beforeStopping */); |
Wale Ogunwale | 8997322 | 2017-04-23 18:39:45 -0700 | [diff] [blame] | 2737 | } |
Winson Chung | c2baac0 | 2017-01-11 13:34:47 -0800 | [diff] [blame] | 2738 | // 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] | 2739 | // to be paused, while at the same time resuming the new resume activity only if the |
| 2740 | // previous activity can't go into Pip since we want to give Pip activities a chance to |
| 2741 | // enter Pip before resuming the next activity. |
Wale Ogunwale | 8997322 | 2017-04-23 18:39:45 -0700 | [diff] [blame] | 2742 | final boolean resumeWhilePausing = (next.info.flags & FLAG_RESUME_WHILE_PAUSING) != 0 |
| 2743 | && !lastResumedCanPip; |
| 2744 | |
Andrii Kulian | ab132ee | 2018-07-24 22:10:21 +0800 | [diff] [blame] | 2745 | boolean pausing = getDisplay().pauseBackStacks(userLeaving, next, false); |
Craig Mautner | eb95786 | 2013-04-24 15:34:32 -0700 | [diff] [blame] | 2746 | if (mResumedActivity != null) { |
Wale Ogunwale | 0fc365c | 2015-05-25 19:35:42 -0700 | [diff] [blame] | 2747 | if (DEBUG_STATES) Slog.d(TAG_STATES, |
| 2748 | "resumeTopActivityLocked: Pausing " + mResumedActivity); |
Winson Chung | c2baac0 | 2017-01-11 13:34:47 -0800 | [diff] [blame] | 2749 | pausing |= startPausingLocked(userLeaving, false, next, false); |
Craig Mautner | eb95786 | 2013-04-24 15:34:32 -0700 | [diff] [blame] | 2750 | } |
Winson Chung | c2baac0 | 2017-01-11 13:34:47 -0800 | [diff] [blame] | 2751 | if (pausing && !resumeWhilePausing) { |
Wale Ogunwale | 0fc365c | 2015-05-25 19:35:42 -0700 | [diff] [blame] | 2752 | if (DEBUG_SWITCH || DEBUG_STATES) Slog.v(TAG_STATES, |
Craig Mautner | ac6f843 | 2013-07-17 13:24:59 -0700 | [diff] [blame] | 2753 | "resumeTopActivityLocked: Skip resume: need to start pausing"); |
Dianne Hackborn | ad9b3211 | 2012-09-17 15:35:01 -0700 | [diff] [blame] | 2754 | // At this point we want to put the upcoming activity's process |
| 2755 | // at the top of the LRU list, since we know we will be needing it |
| 2756 | // very soon and it would be a waste to let it get killed if it |
| 2757 | // happens to be sitting towards the end. |
Wale Ogunwale | 9e4f3e0 | 2018-05-17 09:35:39 -0700 | [diff] [blame] | 2758 | if (next.attachedToProcess()) { |
| 2759 | next.app.updateProcessInfo(false /* updateServiceConnectionActivities */, |
Riddle Hsu | 17e3842 | 2019-04-12 16:55:11 +0800 | [diff] [blame] | 2760 | true /* activityChange */, false /* updateOomAdj */); |
Dianne Hackborn | ad9b3211 | 2012-09-17 15:35:01 -0700 | [diff] [blame] | 2761 | } |
chaviw | 4ad5491 | 2018-05-30 11:05:44 -0700 | [diff] [blame] | 2762 | if (lastResumed != null) { |
| 2763 | lastResumed.setWillCloseOrEnterPip(true); |
| 2764 | } |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 2765 | return true; |
Bryce Lee | 7ace395 | 2018-02-16 14:34:32 -0800 | [diff] [blame] | 2766 | } else if (mResumedActivity == next && next.isState(RESUMED) |
Riddle Hsu | bbb63c2 | 2018-10-03 12:28:29 +0800 | [diff] [blame] | 2767 | && display.allResumedActivitiesComplete()) { |
Wale Ogunwale | cac5c32 | 2016-05-23 10:56:33 -0700 | [diff] [blame] | 2768 | // It is possible for the activity to be resumed when we paused back stacks above if the |
| 2769 | // next activity doesn't have to wait for pause to complete. |
| 2770 | // So, nothing else to-do except: |
| 2771 | // Make sure we have executed any pending transitions, since there |
| 2772 | // should be nothing left to do at this point. |
skuhne@google.com | 1b974dc | 2016-12-09 13:41:29 -0800 | [diff] [blame] | 2773 | executeAppTransition(options); |
Wale Ogunwale | cac5c32 | 2016-05-23 10:56:33 -0700 | [diff] [blame] | 2774 | if (DEBUG_STATES) Slog.d(TAG_STATES, |
| 2775 | "resumeTopActivityLocked: Top activity resumed (dontWaitForPause) " + next); |
Wale Ogunwale | cac5c32 | 2016-05-23 10:56:33 -0700 | [diff] [blame] | 2776 | return true; |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 2777 | } |
| 2778 | |
Christopher Tate | d3f175c | 2012-06-14 14:16:54 -0700 | [diff] [blame] | 2779 | // If the most recent activity was noHistory but was only stopped rather |
| 2780 | // than stopped+finished because the device went to sleep, we need to make |
| 2781 | // sure to finish it as we're making a new activity topmost. |
David Stevens | 9440dc8 | 2017-03-16 19:00:20 -0700 | [diff] [blame] | 2782 | if (shouldSleepActivities() && mLastNoHistoryActivity != null && |
Craig Mautner | 0f92274 | 2013-08-06 08:44:42 -0700 | [diff] [blame] | 2783 | !mLastNoHistoryActivity.finishing) { |
Wale Ogunwale | 0fc365c | 2015-05-25 19:35:42 -0700 | [diff] [blame] | 2784 | if (DEBUG_STATES) Slog.d(TAG_STATES, |
| 2785 | "no-history finish of " + mLastNoHistoryActivity + " on new resume"); |
Craig Mautner | 0f92274 | 2013-08-06 08:44:42 -0700 | [diff] [blame] | 2786 | requestFinishActivityLocked(mLastNoHistoryActivity.appToken, Activity.RESULT_CANCELED, |
Wale Ogunwale | 586a8ee | 2019-06-04 13:44:14 +0000 | [diff] [blame] | 2787 | null, "resume-no-history", false); |
Craig Mautner | 0f92274 | 2013-08-06 08:44:42 -0700 | [diff] [blame] | 2788 | mLastNoHistoryActivity = null; |
Christopher Tate | d3f175c | 2012-06-14 14:16:54 -0700 | [diff] [blame] | 2789 | } |
| 2790 | |
Jorim Jaggi | 9b5e331 | 2019-03-01 18:08:00 +0100 | [diff] [blame] | 2791 | if (prev != null && prev != next && next.nowVisible) { |
| 2792 | |
| 2793 | // The next activity is already visible, so hide the previous |
| 2794 | // activity's windows right now so we can show the new one ASAP. |
| 2795 | // We only do this if the previous is finishing, which should mean |
| 2796 | // it is on top of the one being resumed so hiding it quickly |
| 2797 | // is good. Otherwise, we want to do the normal route of allowing |
| 2798 | // the resumed activity to be shown so we can decide if the |
| 2799 | // previous should actually be hidden depending on whether the |
| 2800 | // new one is found to be full-screen or not. |
| 2801 | if (prev.finishing) { |
| 2802 | prev.setVisibility(false); |
Wale Ogunwale | ee006da | 2015-03-30 14:49:25 -0700 | [diff] [blame] | 2803 | if (DEBUG_SWITCH) Slog.v(TAG_SWITCH, |
Jorim Jaggi | 9b5e331 | 2019-03-01 18:08:00 +0100 | [diff] [blame] | 2804 | "Not waiting for visible to hide: " + prev |
| 2805 | + ", nowVisible=" + next.nowVisible); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 2806 | } else { |
Jorim Jaggi | 9b5e331 | 2019-03-01 18:08:00 +0100 | [diff] [blame] | 2807 | if (DEBUG_SWITCH) Slog.v(TAG_SWITCH, |
| 2808 | "Previous already visible but still waiting to hide: " + prev |
| 2809 | + ", nowVisible=" + next.nowVisible); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 2810 | } |
Jorim Jaggi | 9b5e331 | 2019-03-01 18:08:00 +0100 | [diff] [blame] | 2811 | |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 2812 | } |
| 2813 | |
Dianne Hackborn | e7f9721 | 2011-02-24 14:40:20 -0800 | [diff] [blame] | 2814 | // Launching this app's activity, make sure the app is no longer |
| 2815 | // considered stopped. |
| 2816 | try { |
| 2817 | AppGlobals.getPackageManager().setPackageStoppedState( |
Wale Ogunwale | 8b19de9 | 2018-11-29 19:58:26 -0800 | [diff] [blame] | 2818 | next.packageName, false, next.mUserId); /* TODO: Verify if correct userid */ |
Dianne Hackborn | e7f9721 | 2011-02-24 14:40:20 -0800 | [diff] [blame] | 2819 | } catch (RemoteException e1) { |
Dianne Hackborn | a925cd4 | 2011-03-10 13:18:20 -0800 | [diff] [blame] | 2820 | } catch (IllegalArgumentException e) { |
| 2821 | Slog.w(TAG, "Failed trying to unstop package " |
| 2822 | + next.packageName + ": " + e); |
Dianne Hackborn | e7f9721 | 2011-02-24 14:40:20 -0800 | [diff] [blame] | 2823 | } |
| 2824 | |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 2825 | // We are starting up the next activity, so tell the window manager |
| 2826 | // that the previous one will be hidden soon. This way it can know |
| 2827 | // to ignore it when computing the desired screen orientation. |
Craig Mautner | 525f3d9 | 2013-05-07 14:01:50 -0700 | [diff] [blame] | 2828 | boolean anim = true; |
Wale Ogunwale | 3a256e6 | 2018-12-06 14:41:18 -0800 | [diff] [blame] | 2829 | final DisplayContent dc = getDisplay().mDisplayContent; |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 2830 | if (prev != null) { |
| 2831 | if (prev.finishing) { |
Wale Ogunwale | ee006da | 2015-03-30 14:49:25 -0700 | [diff] [blame] | 2832 | if (DEBUG_TRANSITION) Slog.v(TAG_TRANSITION, |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 2833 | "Prepare close transition: prev=" + prev); |
Jorim Jaggi | fa9ed96 | 2018-01-25 00:16:49 +0100 | [diff] [blame] | 2834 | if (mStackSupervisor.mNoAnimActivities.contains(prev)) { |
Craig Mautner | 525f3d9 | 2013-05-07 14:01:50 -0700 | [diff] [blame] | 2835 | anim = false; |
Wale Ogunwale | 3a256e6 | 2018-12-06 14:41:18 -0800 | [diff] [blame] | 2836 | dc.prepareAppTransition(TRANSIT_NONE, false); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 2837 | } else { |
Wale Ogunwale | 3a256e6 | 2018-12-06 14:41:18 -0800 | [diff] [blame] | 2838 | dc.prepareAppTransition( |
Wale Ogunwale | 8b19de9 | 2018-11-29 19:58:26 -0800 | [diff] [blame] | 2839 | prev.getTaskRecord() == next.getTaskRecord() ? TRANSIT_ACTIVITY_CLOSE |
lumark | 588a3e8 | 2018-07-20 18:53:54 +0800 | [diff] [blame] | 2840 | : TRANSIT_TASK_CLOSE, false); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 2841 | } |
Wale Ogunwale | 26c0dfe | 2016-12-14 14:42:30 -0800 | [diff] [blame] | 2842 | prev.setVisibility(false); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 2843 | } else { |
Wale Ogunwale | ee006da | 2015-03-30 14:49:25 -0700 | [diff] [blame] | 2844 | if (DEBUG_TRANSITION) Slog.v(TAG_TRANSITION, |
| 2845 | "Prepare open transition: prev=" + prev); |
Jorim Jaggi | fa9ed96 | 2018-01-25 00:16:49 +0100 | [diff] [blame] | 2846 | if (mStackSupervisor.mNoAnimActivities.contains(next)) { |
Craig Mautner | 525f3d9 | 2013-05-07 14:01:50 -0700 | [diff] [blame] | 2847 | anim = false; |
Wale Ogunwale | 3a256e6 | 2018-12-06 14:41:18 -0800 | [diff] [blame] | 2848 | dc.prepareAppTransition(TRANSIT_NONE, false); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 2849 | } else { |
Wale Ogunwale | 3a256e6 | 2018-12-06 14:41:18 -0800 | [diff] [blame] | 2850 | dc.prepareAppTransition( |
Wale Ogunwale | 8b19de9 | 2018-11-29 19:58:26 -0800 | [diff] [blame] | 2851 | prev.getTaskRecord() == next.getTaskRecord() ? TRANSIT_ACTIVITY_OPEN |
lumark | 588a3e8 | 2018-07-20 18:53:54 +0800 | [diff] [blame] | 2852 | : next.mLaunchTaskBehind ? TRANSIT_TASK_OPEN_BEHIND |
| 2853 | : TRANSIT_TASK_OPEN, false); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 2854 | } |
| 2855 | } |
Craig Mautner | 967212c | 2013-04-13 21:10:58 -0700 | [diff] [blame] | 2856 | } else { |
Wale Ogunwale | ee006da | 2015-03-30 14:49:25 -0700 | [diff] [blame] | 2857 | if (DEBUG_TRANSITION) Slog.v(TAG_TRANSITION, "Prepare open transition: no previous"); |
Jorim Jaggi | fa9ed96 | 2018-01-25 00:16:49 +0100 | [diff] [blame] | 2858 | if (mStackSupervisor.mNoAnimActivities.contains(next)) { |
Craig Mautner | 525f3d9 | 2013-05-07 14:01:50 -0700 | [diff] [blame] | 2859 | anim = false; |
Wale Ogunwale | 3a256e6 | 2018-12-06 14:41:18 -0800 | [diff] [blame] | 2860 | dc.prepareAppTransition(TRANSIT_NONE, false); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 2861 | } else { |
Wale Ogunwale | 3a256e6 | 2018-12-06 14:41:18 -0800 | [diff] [blame] | 2862 | dc.prepareAppTransition(TRANSIT_ACTIVITY_OPEN, false); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 2863 | } |
| 2864 | } |
Adam Powell | cfbe9be | 2013-11-06 14:58:58 -0800 | [diff] [blame] | 2865 | |
Craig Mautner | 525f3d9 | 2013-05-07 14:01:50 -0700 | [diff] [blame] | 2866 | if (anim) { |
Dianne Hackborn | 7a2195c | 2012-03-19 17:38:00 -0700 | [diff] [blame] | 2867 | next.applyOptionsLocked(); |
| 2868 | } else { |
| 2869 | next.clearOptionsLocked(); |
| 2870 | } |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 2871 | |
Jorim Jaggi | fa9ed96 | 2018-01-25 00:16:49 +0100 | [diff] [blame] | 2872 | mStackSupervisor.mNoAnimActivities.clear(); |
| 2873 | |
Wale Ogunwale | 9e4f3e0 | 2018-05-17 09:35:39 -0700 | [diff] [blame] | 2874 | if (next.attachedToProcess()) { |
Chong Zhang | dea4bd9 | 2016-03-15 12:50:03 -0700 | [diff] [blame] | 2875 | if (DEBUG_SWITCH) Slog.v(TAG_SWITCH, "Resume running: " + next |
| 2876 | + " stopped=" + next.stopped + " visible=" + next.visible); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 2877 | |
Chong Zhang | d127c6d | 2016-05-02 16:36:41 -0700 | [diff] [blame] | 2878 | // If the previous activity is translucent, force a visibility update of |
| 2879 | // the next activity, so that it's added to WM's opening app list, and |
| 2880 | // transition animation can be set up properly. |
| 2881 | // For example, pressing Home button with a translucent activity in focus. |
| 2882 | // Launcher is already visible in this case. If we don't add it to opening |
| 2883 | // apps, maybeUpdateTransitToWallpaper() will fail to identify this as a |
| 2884 | // TRANSIT_WALLPAPER_OPEN animation, and run some funny animation. |
Riddle Hsu | bbb63c2 | 2018-10-03 12:28:29 +0800 | [diff] [blame] | 2885 | final boolean lastActivityTranslucent = lastFocusedStack != null |
| 2886 | && (lastFocusedStack.inMultiWindowMode() |
| 2887 | || (lastFocusedStack.mLastPausedActivity != null |
| 2888 | && !lastFocusedStack.mLastPausedActivity.fullscreen)); |
Chong Zhang | d127c6d | 2016-05-02 16:36:41 -0700 | [diff] [blame] | 2889 | |
Wale Ogunwale | 1f5e53d | 2018-11-05 05:12:46 -0800 | [diff] [blame] | 2890 | // This activity is now becoming visible. |
| 2891 | if (!next.visible || next.stopped || lastActivityTranslucent) { |
| 2892 | next.setVisibility(true); |
| 2893 | } |
| 2894 | |
| 2895 | // schedule launch ticks to collect information about slow apps. |
| 2896 | next.startLaunchTickingLocked(); |
| 2897 | |
| 2898 | ActivityRecord lastResumedActivity = |
| 2899 | lastFocusedStack == null ? null : lastFocusedStack.mResumedActivity; |
| 2900 | final ActivityState lastState = next.getState(); |
| 2901 | |
| 2902 | mService.updateCpuStats(); |
| 2903 | |
| 2904 | if (DEBUG_STATES) Slog.v(TAG_STATES, "Moving to RESUMED: " + next |
| 2905 | + " (in existing)"); |
| 2906 | |
| 2907 | next.setState(RESUMED, "resumeTopActivityInnerLocked"); |
| 2908 | |
| 2909 | next.app.updateProcessInfo(false /* updateServiceConnectionActivities */, |
Riddle Hsu | 17e3842 | 2019-04-12 16:55:11 +0800 | [diff] [blame] | 2910 | true /* activityChange */, true /* updateOomAdj */); |
Wale Ogunwale | 1f5e53d | 2018-11-05 05:12:46 -0800 | [diff] [blame] | 2911 | updateLRUListLocked(next); |
| 2912 | |
| 2913 | // Have the window manager re-evaluate the orientation of |
| 2914 | // the screen based on the new activity order. |
| 2915 | boolean notUpdated = true; |
| 2916 | |
Andrii Kulian | 6b32151 | 2019-01-23 06:37:00 +0000 | [diff] [blame] | 2917 | // Activity should also be visible if set mLaunchTaskBehind to true (see |
| 2918 | // ActivityRecord#shouldBeVisibleIgnoringKeyguard()). |
| 2919 | if (shouldBeVisible(next)) { |
Wale Ogunwale | 1f5e53d | 2018-11-05 05:12:46 -0800 | [diff] [blame] | 2920 | // We have special rotation behavior when here is some active activity that |
| 2921 | // requests specific orientation or Keyguard is locked. Make sure all activity |
| 2922 | // visibilities are set correctly as well as the transition is updated if needed |
| 2923 | // to get the correct rotation behavior. Otherwise the following call to update |
| 2924 | // the orientation may cause incorrect configurations delivered to client as a |
| 2925 | // result of invisible window resize. |
| 2926 | // TODO: Remove this once visibilities are set correctly immediately when |
| 2927 | // starting an activity. |
Wale Ogunwale | d32da47 | 2018-11-16 07:19:28 -0800 | [diff] [blame] | 2928 | notUpdated = !mRootActivityContainer.ensureVisibilityAndConfig(next, mDisplayId, |
Wale Ogunwale | 1f5e53d | 2018-11-05 05:12:46 -0800 | [diff] [blame] | 2929 | true /* markFrozenIfConfigChanged */, false /* deferResume */); |
| 2930 | } |
| 2931 | |
| 2932 | if (notUpdated) { |
| 2933 | // The configuration update wasn't able to keep the existing |
| 2934 | // instance of the activity, and instead started a new one. |
| 2935 | // We should be all done, but let's just make sure our activity |
| 2936 | // is still at the top and schedule another run if something |
| 2937 | // weird happened. |
| 2938 | ActivityRecord nextNext = topRunningActivityLocked(); |
| 2939 | if (DEBUG_SWITCH || DEBUG_STATES) Slog.i(TAG_STATES, |
| 2940 | "Activity config changed during resume: " + next |
| 2941 | + ", new next: " + nextNext); |
| 2942 | if (nextNext != next) { |
| 2943 | // Do over! |
| 2944 | mStackSupervisor.scheduleResumeTopActivities(); |
| 2945 | } |
| 2946 | if (!next.visible || next.stopped) { |
Wale Ogunwale | 26c0dfe | 2016-12-14 14:42:30 -0800 | [diff] [blame] | 2947 | next.setVisibility(true); |
Craig Mautner | de4ef02 | 2013-04-07 19:01:33 -0700 | [diff] [blame] | 2948 | } |
Wale Ogunwale | 1f5e53d | 2018-11-05 05:12:46 -0800 | [diff] [blame] | 2949 | next.completeResumeLocked(); |
Wale Ogunwale | 1f5e53d | 2018-11-05 05:12:46 -0800 | [diff] [blame] | 2950 | return true; |
| 2951 | } |
Craig Mautner | 5854780 | 2013-03-05 08:23:53 -0800 | [diff] [blame] | 2952 | |
Wale Ogunwale | 1f5e53d | 2018-11-05 05:12:46 -0800 | [diff] [blame] | 2953 | try { |
| 2954 | final ClientTransaction transaction = |
| 2955 | ClientTransaction.obtain(next.app.getThread(), next.appToken); |
| 2956 | // Deliver all pending results. |
| 2957 | ArrayList<ResultInfo> a = next.results; |
| 2958 | if (a != null) { |
| 2959 | final int N = a.size(); |
| 2960 | if (!next.finishing && N > 0) { |
| 2961 | if (DEBUG_RESULTS) Slog.v(TAG_RESULTS, |
| 2962 | "Delivering results to " + next + ": " + a); |
| 2963 | transaction.addCallback(ActivityResultItem.obtain(a)); |
| 2964 | } |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 2965 | } |
| 2966 | |
Wale Ogunwale | 1f5e53d | 2018-11-05 05:12:46 -0800 | [diff] [blame] | 2967 | if (next.newIntents != null) { |
Louis Chang | 92d1652 | 2019-02-27 12:56:18 +0800 | [diff] [blame] | 2968 | transaction.addCallback(NewIntentItem.obtain(next.newIntents)); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 2969 | } |
| 2970 | |
Wale Ogunwale | 1f5e53d | 2018-11-05 05:12:46 -0800 | [diff] [blame] | 2971 | // Well the app will no longer be stopped. |
| 2972 | // Clear app token stopped state in window manager if needed. |
| 2973 | next.notifyAppResumed(next.stopped); |
Wale Ogunwale | 8d5a542 | 2016-03-03 18:28:21 -0800 | [diff] [blame] | 2974 | |
Wale Ogunwale | 8b19de9 | 2018-11-29 19:58:26 -0800 | [diff] [blame] | 2975 | EventLog.writeEvent(EventLogTags.AM_RESUME_ACTIVITY, next.mUserId, |
| 2976 | System.identityHashCode(next), next.getTaskRecord().taskId, |
Wale Ogunwale | 1f5e53d | 2018-11-05 05:12:46 -0800 | [diff] [blame] | 2977 | next.shortComponentName); |
Craig Mautner | 5854780 | 2013-03-05 08:23:53 -0800 | [diff] [blame] | 2978 | |
Wale Ogunwale | 1f5e53d | 2018-11-05 05:12:46 -0800 | [diff] [blame] | 2979 | next.sleeping = false; |
| 2980 | mService.getAppWarningsLocked().onResumeActivity(next); |
| 2981 | next.app.setPendingUiCleanAndForceProcessStateUpTo(mService.mTopProcessState); |
| 2982 | next.clearOptionsLocked(); |
| 2983 | transaction.setLifecycleStateRequest( |
| 2984 | ResumeActivityItem.obtain(next.app.getReportedProcState(), |
Wale Ogunwale | 3a256e6 | 2018-12-06 14:41:18 -0800 | [diff] [blame] | 2985 | getDisplay().mDisplayContent.isNextTransitionForward())); |
Wale Ogunwale | 1f5e53d | 2018-11-05 05:12:46 -0800 | [diff] [blame] | 2986 | mService.getLifecycleManager().scheduleTransaction(transaction); |
Craig Mautner | 5854780 | 2013-03-05 08:23:53 -0800 | [diff] [blame] | 2987 | |
Wale Ogunwale | 1f5e53d | 2018-11-05 05:12:46 -0800 | [diff] [blame] | 2988 | if (DEBUG_STATES) Slog.d(TAG_STATES, "resumeTopActivityLocked: Resumed " |
| 2989 | + next); |
| 2990 | } catch (Exception e) { |
| 2991 | // Whoops, need to restart this activity! |
| 2992 | if (DEBUG_STATES) Slog.v(TAG_STATES, "Resume failed; resetting state to " |
| 2993 | + lastState + ": " + next); |
| 2994 | next.setState(lastState, "resumeTopActivityInnerLocked"); |
Bryce Lee | 69ad818 | 2017-09-28 10:01:36 -0700 | [diff] [blame] | 2995 | |
Wale Ogunwale | 1f5e53d | 2018-11-05 05:12:46 -0800 | [diff] [blame] | 2996 | // lastResumedActivity being non-null implies there is a lastStack present. |
| 2997 | if (lastResumedActivity != null) { |
| 2998 | lastResumedActivity.setState(RESUMED, "resumeTopActivityInnerLocked"); |
Craig Mautner | f88c50f | 2013-04-18 19:25:12 -0700 | [diff] [blame] | 2999 | } |
Wale Ogunwale | 1f5e53d | 2018-11-05 05:12:46 -0800 | [diff] [blame] | 3000 | |
| 3001 | Slog.i(TAG, "Restarting because process died: " + next); |
| 3002 | if (!next.hasBeenLaunched) { |
| 3003 | next.hasBeenLaunched = true; |
| 3004 | } else if (SHOW_APP_STARTING_PREVIEW && lastFocusedStack != null |
| 3005 | && lastFocusedStack.isTopStackOnDisplay()) { |
| 3006 | next.showStartingWindow(null /* prev */, false /* newTask */, |
| 3007 | false /* taskSwitch */); |
| 3008 | } |
| 3009 | mStackSupervisor.startSpecificActivityLocked(next, true, false); |
Wale Ogunwale | 1f5e53d | 2018-11-05 05:12:46 -0800 | [diff] [blame] | 3010 | return true; |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 3011 | } |
| 3012 | |
| 3013 | // From this point on, if something goes wrong there is no way |
| 3014 | // to recover the activity. |
| 3015 | try { |
Andrii Kulian | 21713ac | 2016-10-12 22:05:05 -0700 | [diff] [blame] | 3016 | next.completeResumeLocked(); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 3017 | } catch (Exception e) { |
| 3018 | // If any exception gets thrown, toss away this |
| 3019 | // activity and try the next one. |
| 3020 | Slog.w(TAG, "Exception thrown during resume of " + next, e); |
Wale Ogunwale | 586a8ee | 2019-06-04 13:44:14 +0000 | [diff] [blame] | 3021 | requestFinishActivityLocked(next.appToken, Activity.RESULT_CANCELED, null, |
Dianne Hackborn | 2d1b378 | 2012-09-09 17:49:39 -0700 | [diff] [blame] | 3022 | "resume-exception", true); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 3023 | return true; |
| 3024 | } |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 3025 | } else { |
| 3026 | // Whoops, need to restart this activity! |
| 3027 | if (!next.hasBeenLaunched) { |
| 3028 | next.hasBeenLaunched = true; |
| 3029 | } else { |
| 3030 | if (SHOW_APP_STARTING_PREVIEW) { |
Jorim Jaggi | 02886a8 | 2016-12-06 09:10:06 -0800 | [diff] [blame] | 3031 | next.showStartingWindow(null /* prev */, false /* newTask */, |
| 3032 | false /* taskSwich */); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 3033 | } |
Wale Ogunwale | ee006da | 2015-03-30 14:49:25 -0700 | [diff] [blame] | 3034 | if (DEBUG_SWITCH) Slog.v(TAG_SWITCH, "Restarting: " + next); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 3035 | } |
Wale Ogunwale | 0fc365c | 2015-05-25 19:35:42 -0700 | [diff] [blame] | 3036 | if (DEBUG_STATES) Slog.d(TAG_STATES, "resumeTopActivityLocked: Restarting " + next); |
George Mount | 2c92c97 | 2014-03-20 09:38:23 -0700 | [diff] [blame] | 3037 | mStackSupervisor.startSpecificActivityLocked(next, true, true); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 3038 | } |
| 3039 | |
| 3040 | return true; |
| 3041 | } |
| 3042 | |
Andrii Kulian | 3ff5a0b | 2019-05-16 13:18:04 -0700 | [diff] [blame] | 3043 | /** |
| 3044 | * Resume the next eligible activity in a focusable stack when this one does not have any |
| 3045 | * running activities left. The focus will be adjusted to the next focusable stack and |
| 3046 | * top running activities will be resumed in all focusable stacks. However, if the current stack |
| 3047 | * is a home stack - we have to keep it focused, start and resume a home activity on the current |
| 3048 | * display instead to make sure that the display is not empty. |
| 3049 | */ |
| 3050 | private boolean resumeNextFocusableActivityWhenStackIsEmpty(ActivityRecord prev, |
| 3051 | ActivityOptions options) { |
| 3052 | final String reason = "noMoreActivities"; |
| 3053 | |
| 3054 | if (!isActivityTypeHome()) { |
| 3055 | final ActivityStack nextFocusedStack = adjustFocusToNextFocusableStack(reason); |
| 3056 | if (nextFocusedStack != null) { |
| 3057 | // Try to move focus to the next visible stack with a running activity if this |
| 3058 | // stack is not covering the entire screen or is on a secondary display with no home |
| 3059 | // stack. |
| 3060 | return mRootActivityContainer.resumeFocusedStacksTopActivities(nextFocusedStack, |
| 3061 | prev, null /* targetOptions */); |
| 3062 | } |
Andrii Kulian | 7fc2281 | 2016-12-28 13:04:11 -0800 | [diff] [blame] | 3063 | } |
| 3064 | |
Andrii Kulian | 3ff5a0b | 2019-05-16 13:18:04 -0700 | [diff] [blame] | 3065 | // If the current stack is a home stack, or if focus didn't switch to a different stack - |
| 3066 | // just start up the Launcher... |
Andrii Kulian | 7fc2281 | 2016-12-28 13:04:11 -0800 | [diff] [blame] | 3067 | ActivityOptions.abort(options); |
| 3068 | if (DEBUG_STATES) Slog.d(TAG_STATES, |
Andrii Kulian | 3ff5a0b | 2019-05-16 13:18:04 -0700 | [diff] [blame] | 3069 | "resumeNextFocusableActivityWhenStackIsEmpty: " + reason + ", go home"); |
Louis Chang | 77551ed | 2019-04-29 12:42:19 +0800 | [diff] [blame] | 3070 | return mRootActivityContainer.resumeHomeActivity(prev, reason, mDisplayId); |
Andrii Kulian | 7fc2281 | 2016-12-28 13:04:11 -0800 | [diff] [blame] | 3071 | } |
| 3072 | |
Wale Ogunwale | c5cc301 | 2017-01-13 13:26:16 -0800 | [diff] [blame] | 3073 | /** Returns the position the input task should be placed in this stack. */ |
| 3074 | int getAdjustedPositionForTask(TaskRecord task, int suggestedPosition, |
| 3075 | ActivityRecord starting) { |
| 3076 | |
| 3077 | int maxPosition = mTaskHistory.size(); |
| 3078 | if ((starting != null && starting.okToShowLocked()) |
| 3079 | || (starting == null && task.okToShowLocked())) { |
| 3080 | // If the task or starting activity can be shown, then whatever position is okay. |
| 3081 | return Math.min(suggestedPosition, maxPosition); |
| 3082 | } |
| 3083 | |
| 3084 | // The task can't be shown, put non-current user tasks below current user tasks. |
| 3085 | while (maxPosition > 0) { |
| 3086 | final TaskRecord tmpTask = mTaskHistory.get(maxPosition - 1); |
| 3087 | if (!mStackSupervisor.isCurrentProfileLocked(tmpTask.userId) |
| 3088 | || tmpTask.topRunningActivityLocked() == null) { |
| 3089 | break; |
| 3090 | } |
| 3091 | maxPosition--; |
| 3092 | } |
| 3093 | |
| 3094 | return Math.min(suggestedPosition, maxPosition); |
| 3095 | } |
| 3096 | |
Andrii Kulian | d276563 | 2016-12-12 22:26:34 -0800 | [diff] [blame] | 3097 | /** |
| 3098 | * Used from {@link ActivityStack#positionTask(TaskRecord, int)}. |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 3099 | * @see ActivityTaskManagerService#positionTaskInStack(int, int, int). |
Andrii Kulian | d276563 | 2016-12-12 22:26:34 -0800 | [diff] [blame] | 3100 | */ |
Wale Ogunwale | ddc1cb2 | 2015-07-25 19:23:04 -0700 | [diff] [blame] | 3101 | private void insertTaskAtPosition(TaskRecord task, int position) { |
| 3102 | if (position >= mTaskHistory.size()) { |
| 3103 | insertTaskAtTop(task, null); |
| 3104 | return; |
Evan Rosky | 9c44817 | 2017-11-02 14:19:27 -0700 | [diff] [blame] | 3105 | } else if (position <= 0) { |
| 3106 | insertTaskAtBottom(task); |
| 3107 | return; |
Wale Ogunwale | ddc1cb2 | 2015-07-25 19:23:04 -0700 | [diff] [blame] | 3108 | } |
Wale Ogunwale | c5cc301 | 2017-01-13 13:26:16 -0800 | [diff] [blame] | 3109 | position = getAdjustedPositionForTask(task, position, null /* starting */); |
Wale Ogunwale | ddc1cb2 | 2015-07-25 19:23:04 -0700 | [diff] [blame] | 3110 | mTaskHistory.remove(task); |
| 3111 | mTaskHistory.add(position, task); |
Yunfan Chen | 279f558 | 2018-12-12 15:24:50 -0800 | [diff] [blame] | 3112 | if (mTaskStack != null) { |
| 3113 | // TODO: this could not be false after unification. |
| 3114 | mTaskStack.positionChildAt(task.getTask(), position); |
| 3115 | } |
Wale Ogunwale | ddc1cb2 | 2015-07-25 19:23:04 -0700 | [diff] [blame] | 3116 | updateTaskMovement(task, true); |
| 3117 | } |
| 3118 | |
Wale Ogunwale | c5cc301 | 2017-01-13 13:26:16 -0800 | [diff] [blame] | 3119 | private void insertTaskAtTop(TaskRecord task, ActivityRecord starting) { |
Wale Ogunwale | c5cc301 | 2017-01-13 13:26:16 -0800 | [diff] [blame] | 3120 | // TODO: Better place to put all the code below...may be addTask... |
| 3121 | mTaskHistory.remove(task); |
| 3122 | // Now put task at top. |
| 3123 | final int position = getAdjustedPositionForTask(task, mTaskHistory.size(), starting); |
| 3124 | mTaskHistory.add(position, task); |
| 3125 | updateTaskMovement(task, true); |
Riddle Hsu | 86cb7de | 2018-08-13 23:29:58 +0800 | [diff] [blame] | 3126 | positionChildWindowContainerAtTop(task); |
Wale Ogunwale | e1fe7fa2 | 2016-12-15 18:27:00 -0800 | [diff] [blame] | 3127 | } |
| 3128 | |
Evan Rosky | 9c44817 | 2017-11-02 14:19:27 -0700 | [diff] [blame] | 3129 | private void insertTaskAtBottom(TaskRecord task) { |
Evan Rosky | 9c44817 | 2017-11-02 14:19:27 -0700 | [diff] [blame] | 3130 | mTaskHistory.remove(task); |
| 3131 | final int position = getAdjustedPositionForTask(task, 0, null); |
| 3132 | mTaskHistory.add(position, task); |
| 3133 | updateTaskMovement(task, true); |
Riddle Hsu | 86cb7de | 2018-08-13 23:29:58 +0800 | [diff] [blame] | 3134 | positionChildWindowContainerAtBottom(task); |
Evan Rosky | 9c44817 | 2017-11-02 14:19:27 -0700 | [diff] [blame] | 3135 | } |
| 3136 | |
Bryce Lee | ad5b832 | 2018-03-08 14:28:52 -0800 | [diff] [blame] | 3137 | void startActivityLocked(ActivityRecord r, ActivityRecord focusedTopActivity, |
Winson Chung | b5c41b7 | 2016-12-07 15:00:47 -0800 | [diff] [blame] | 3138 | boolean newTask, boolean keepCurTransition, ActivityOptions options) { |
Wale Ogunwale | 8b19de9 | 2018-11-29 19:58:26 -0800 | [diff] [blame] | 3139 | TaskRecord rTask = r.getTaskRecord(); |
Craig Mautner | d232895 | 2013-03-05 12:46:26 -0800 | [diff] [blame] | 3140 | final int taskId = rTask.taskId; |
Craig Mautner | bb74246 | 2014-07-07 15:28:55 -0700 | [diff] [blame] | 3141 | // mLaunchTaskBehind tasks get placed at the back of the task stack. |
| 3142 | if (!r.mLaunchTaskBehind && (taskForIdLocked(taskId) == null || newTask)) { |
Craig Mautner | 7787877 | 2013-03-04 19:46:24 -0800 | [diff] [blame] | 3143 | // Last activity in task had been removed or ActivityManagerService is reusing task. |
| 3144 | // Insert or replace. |
Craig Mautner | 7787877 | 2013-03-04 19:46:24 -0800 | [diff] [blame] | 3145 | // Might not even be in. |
Wale Ogunwale | 3fcb4a8 | 2015-04-06 14:00:13 -0700 | [diff] [blame] | 3146 | insertTaskAtTop(rTask, r); |
Craig Mautner | 7787877 | 2013-03-04 19:46:24 -0800 | [diff] [blame] | 3147 | } |
Craig Mautner | 525f3d9 | 2013-05-07 14:01:50 -0700 | [diff] [blame] | 3148 | TaskRecord task = null; |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 3149 | if (!newTask) { |
| 3150 | // If starting in an existing task, find where that is... |
Craig Mautner | 70a8693 | 2013-02-28 22:37:44 -0800 | [diff] [blame] | 3151 | boolean startIt = true; |
| 3152 | for (int taskNdx = mTaskHistory.size() - 1; taskNdx >= 0; --taskNdx) { |
| 3153 | task = mTaskHistory.get(taskNdx); |
riddle_hsu | 9bcc6e8 | 2014-07-31 00:26:51 +0800 | [diff] [blame] | 3154 | if (task.getTopActivity() == null) { |
| 3155 | // All activities in task are finishing. |
| 3156 | continue; |
| 3157 | } |
Bryce Lee | af691c0 | 2017-03-20 14:20:22 -0700 | [diff] [blame] | 3158 | if (task == rTask) { |
Craig Mautner | 70a8693 | 2013-02-28 22:37:44 -0800 | [diff] [blame] | 3159 | // Here it is! Now, if this is not yet visible to the |
| 3160 | // user, then just add it without starting; it will |
| 3161 | // get started when the user navigates back to it. |
Craig Mautner | 70a8693 | 2013-02-28 22:37:44 -0800 | [diff] [blame] | 3162 | if (!startIt) { |
| 3163 | if (DEBUG_ADD_REMOVE) Slog.i(TAG, "Adding activity " + r + " to task " |
| 3164 | + task, new RuntimeException("here").fillInStackTrace()); |
Yunfan Chen | 1ee84ea | 2018-11-13 16:03:37 -0800 | [diff] [blame] | 3165 | r.createAppWindowToken(); |
Dianne Hackborn | 8078d8c | 2012-03-20 11:11:26 -0700 | [diff] [blame] | 3166 | ActivityOptions.abort(options); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 3167 | return; |
| 3168 | } |
| 3169 | break; |
Craig Mautner | 70a8693 | 2013-02-28 22:37:44 -0800 | [diff] [blame] | 3170 | } else if (task.numFullscreen > 0) { |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 3171 | startIt = false; |
| 3172 | } |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 3173 | } |
| 3174 | } |
| 3175 | |
Wale Ogunwale | 26c0dfe | 2016-12-14 14:42:30 -0800 | [diff] [blame] | 3176 | // 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] | 3177 | |
Wale Ogunwale | 26c0dfe | 2016-12-14 14:42:30 -0800 | [diff] [blame] | 3178 | // If we are not placing the new activity frontmost, we do not want to deliver the |
| 3179 | // onUserLeaving callback to the actual frontmost activity |
Wale Ogunwale | 8b19de9 | 2018-11-29 19:58:26 -0800 | [diff] [blame] | 3180 | final TaskRecord activityTask = r.getTaskRecord(); |
Bryce Lee | af691c0 | 2017-03-20 14:20:22 -0700 | [diff] [blame] | 3181 | if (task == activityTask && mTaskHistory.indexOf(task) != (mTaskHistory.size() - 1)) { |
Craig Mautner | de4ef02 | 2013-04-07 19:01:33 -0700 | [diff] [blame] | 3182 | mStackSupervisor.mUserLeaving = false; |
Wale Ogunwale | ee006da | 2015-03-30 14:49:25 -0700 | [diff] [blame] | 3183 | if (DEBUG_USER_LEAVING) Slog.v(TAG_USER_LEAVING, |
Craig Mautner | 70a8693 | 2013-02-28 22:37:44 -0800 | [diff] [blame] | 3184 | "startActivity() behind front, mUserLeaving=false"); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 3185 | } |
Craig Mautner | 70a8693 | 2013-02-28 22:37:44 -0800 | [diff] [blame] | 3186 | |
Bryce Lee | af691c0 | 2017-03-20 14:20:22 -0700 | [diff] [blame] | 3187 | task = activityTask; |
Craig Mautner | 70a8693 | 2013-02-28 22:37:44 -0800 | [diff] [blame] | 3188 | |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 3189 | // Slot the activity into the history stack and proceed |
Craig Mautner | 70a8693 | 2013-02-28 22:37:44 -0800 | [diff] [blame] | 3190 | 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] | 3191 | new RuntimeException("here").fillInStackTrace()); |
Wale Ogunwale | a0cd15e | 2017-02-01 15:33:08 -0800 | [diff] [blame] | 3192 | // TODO: Need to investigate if it is okay for the controller to already be created by the |
| 3193 | // time we get to this point. I think it is, but need to double check. |
| 3194 | // Use test in b/34179495 to trace the call path. |
Yunfan Chen | 1ee84ea | 2018-11-13 16:03:37 -0800 | [diff] [blame] | 3195 | if (r.mAppWindowToken == null) { |
| 3196 | r.createAppWindowToken(); |
Wale Ogunwale | a0cd15e | 2017-02-01 15:33:08 -0800 | [diff] [blame] | 3197 | } |
Yunfan Chen | 1ee84ea | 2018-11-13 16:03:37 -0800 | [diff] [blame] | 3198 | |
Craig Mautner | 1aa9d0d3f | 2013-12-16 15:58:31 -0800 | [diff] [blame] | 3199 | task.setFrontOfTask(); |
Craig Mautner | 70a8693 | 2013-02-28 22:37:44 -0800 | [diff] [blame] | 3200 | |
Matthew Ng | ae1ff4f | 2016-11-10 15:49:14 -0800 | [diff] [blame] | 3201 | if (!isHomeOrRecentsStack() || numActivities() > 0) { |
Wale Ogunwale | 3a256e6 | 2018-12-06 14:41:18 -0800 | [diff] [blame] | 3202 | final DisplayContent dc = getDisplay().mDisplayContent; |
Wale Ogunwale | ee006da | 2015-03-30 14:49:25 -0700 | [diff] [blame] | 3203 | if (DEBUG_TRANSITION) Slog.v(TAG_TRANSITION, |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 3204 | "Prepare open transition: starting " + r); |
Wale Ogunwale | ee006da | 2015-03-30 14:49:25 -0700 | [diff] [blame] | 3205 | if ((r.intent.getFlags() & Intent.FLAG_ACTIVITY_NO_ANIMATION) != 0) { |
Wale Ogunwale | 3a256e6 | 2018-12-06 14:41:18 -0800 | [diff] [blame] | 3206 | dc.prepareAppTransition(TRANSIT_NONE, keepCurTransition); |
Jorim Jaggi | fa9ed96 | 2018-01-25 00:16:49 +0100 | [diff] [blame] | 3207 | mStackSupervisor.mNoAnimActivities.add(r); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 3208 | } else { |
Winson Chung | b5c41b7 | 2016-12-07 15:00:47 -0800 | [diff] [blame] | 3209 | int transit = TRANSIT_ACTIVITY_OPEN; |
| 3210 | if (newTask) { |
| 3211 | if (r.mLaunchTaskBehind) { |
| 3212 | transit = TRANSIT_TASK_OPEN_BEHIND; |
Issei Suzuki | cac2a50 | 2019-04-16 16:52:50 +0200 | [diff] [blame] | 3213 | } else if (getDisplay().isSingleTaskInstance()) { |
| 3214 | transit = TRANSIT_SHOW_SINGLE_TASK_DISPLAY; |
Winson Chung | b5c41b7 | 2016-12-07 15:00:47 -0800 | [diff] [blame] | 3215 | } else { |
Winson Chung | c2baac0 | 2017-01-11 13:34:47 -0800 | [diff] [blame] | 3216 | // 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] | 3217 | // supporting picture-in-picture while pausing only if the starting activity |
| 3218 | // would not be considered an overlay on top of the current activity |
| 3219 | // (eg. not fullscreen, or the assistant) |
Winson Chung | f7e03e1 | 2017-08-22 11:32:16 -0700 | [diff] [blame] | 3220 | if (canEnterPipOnTaskSwitch(focusedTopActivity, |
| 3221 | null /* toFrontTask */, r, options)) { |
| 3222 | focusedTopActivity.supportsEnterPipOnTaskSwitch = true; |
Winson Chung | b5c41b7 | 2016-12-07 15:00:47 -0800 | [diff] [blame] | 3223 | } |
| 3224 | transit = TRANSIT_TASK_OPEN; |
| 3225 | } |
| 3226 | } |
Wale Ogunwale | 3a256e6 | 2018-12-06 14:41:18 -0800 | [diff] [blame] | 3227 | dc.prepareAppTransition(transit, keepCurTransition); |
Jorim Jaggi | fa9ed96 | 2018-01-25 00:16:49 +0100 | [diff] [blame] | 3228 | mStackSupervisor.mNoAnimActivities.remove(r); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 3229 | } |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 3230 | boolean doShow = true; |
| 3231 | if (newTask) { |
| 3232 | // Even though this activity is starting fresh, we still need |
| 3233 | // to reset it to make sure we apply affinities to move any |
| 3234 | // existing activities from other tasks in to it. |
| 3235 | // If the caller has requested that the target task be |
| 3236 | // reset, then do so. |
Craig Mautner | 9d4e9bc | 2014-06-18 18:34:56 -0700 | [diff] [blame] | 3237 | if ((r.intent.getFlags() & Intent.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED) != 0) { |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 3238 | resetTaskIfNeededLocked(r, r); |
| 3239 | doShow = topRunningNonDelayedActivityLocked(null) == r; |
| 3240 | } |
Chong Zhang | 280d332 | 2015-11-03 17:27:26 -0800 | [diff] [blame] | 3241 | } else if (options != null && options.getAnimationType() |
George Mount | 70778d7 | 2014-07-01 16:33:45 -0700 | [diff] [blame] | 3242 | == ActivityOptions.ANIM_SCENE_TRANSITION) { |
| 3243 | doShow = false; |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 3244 | } |
Craig Mautner | bb74246 | 2014-07-07 15:28:55 -0700 | [diff] [blame] | 3245 | if (r.mLaunchTaskBehind) { |
| 3246 | // Don't do a starting window for mLaunchTaskBehind. More importantly make sure we |
| 3247 | // 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] | 3248 | r.setVisibility(true); |
Filip Gruszczynski | bc5a6c5 | 2015-09-22 13:13:24 -0700 | [diff] [blame] | 3249 | ensureActivitiesVisibleLocked(null, 0, !PRESERVE_WINDOWS); |
Craig Mautner | bb74246 | 2014-07-07 15:28:55 -0700 | [diff] [blame] | 3250 | } else if (SHOW_APP_STARTING_PREVIEW && doShow) { |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 3251 | // Figure out if we are transitioning from another activity that is |
| 3252 | // "has the same starting icon" as the next one. This allows the |
| 3253 | // window manager to keep the previous window it had previously |
| 3254 | // created, if it still had one. |
Wale Ogunwale | 8b19de9 | 2018-11-29 19:58:26 -0800 | [diff] [blame] | 3255 | TaskRecord prevTask = r.getTaskRecord(); |
Bryce Lee | af691c0 | 2017-03-20 14:20:22 -0700 | [diff] [blame] | 3256 | ActivityRecord prev = prevTask.topRunningActivityWithStartingWindowLocked(); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 3257 | if (prev != null) { |
| 3258 | // We don't want to reuse the previous starting preview if: |
| 3259 | // (1) The current activity is in a different task. |
Wale Ogunwale | 8b19de9 | 2018-11-29 19:58:26 -0800 | [diff] [blame] | 3260 | if (prev.getTaskRecord() != prevTask) { |
Craig Mautner | 29219d9 | 2013-04-16 20:19:12 -0700 | [diff] [blame] | 3261 | prev = null; |
| 3262 | } |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 3263 | // (2) The current activity is already displayed. |
Craig Mautner | 29219d9 | 2013-04-16 20:19:12 -0700 | [diff] [blame] | 3264 | else if (prev.nowVisible) { |
| 3265 | prev = null; |
| 3266 | } |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 3267 | } |
Jorim Jaggi | 02886a8 | 2016-12-06 09:10:06 -0800 | [diff] [blame] | 3268 | r.showStartingWindow(prev, newTask, isTaskSwitch(r, focusedTopActivity)); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 3269 | } |
| 3270 | } else { |
| 3271 | // If this is the first activity, don't do any fancy animations, |
| 3272 | // because there is nothing for it to animate on top of. |
Dianne Hackborn | 8078d8c | 2012-03-20 11:11:26 -0700 | [diff] [blame] | 3273 | ActivityOptions.abort(options); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 3274 | } |
Dianne Hackborn | be70785 | 2011-11-11 14:32:10 -0800 | [diff] [blame] | 3275 | } |
| 3276 | |
Winson Chung | f7e03e1 | 2017-08-22 11:32:16 -0700 | [diff] [blame] | 3277 | /** |
| 3278 | * @return Whether the switch to another task can trigger the currently running activity to |
| 3279 | * enter PiP while it is pausing (if supported). Only one of {@param toFrontTask} or |
| 3280 | * {@param toFrontActivity} should be set. |
| 3281 | */ |
| 3282 | private boolean canEnterPipOnTaskSwitch(ActivityRecord pipCandidate, |
| 3283 | TaskRecord toFrontTask, ActivityRecord toFrontActivity, ActivityOptions opts) { |
| 3284 | if (opts != null && opts.disallowEnterPictureInPictureWhileLaunching()) { |
| 3285 | // Ensure the caller has requested not to trigger auto-enter PiP |
| 3286 | return false; |
| 3287 | } |
Wale Ogunwale | 44f036f | 2017-09-29 05:09:09 -0700 | [diff] [blame] | 3288 | if (pipCandidate == null || pipCandidate.inPinnedWindowingMode()) { |
Winson Chung | f7e03e1 | 2017-08-22 11:32:16 -0700 | [diff] [blame] | 3289 | // Ensure that we do not trigger entering PiP an activity on the pinned stack |
| 3290 | return false; |
| 3291 | } |
Wale Ogunwale | 6827856 | 2017-09-23 17:13:55 -0700 | [diff] [blame] | 3292 | final ActivityStack targetStack = toFrontTask != null |
Wale Ogunwale | 8b19de9 | 2018-11-29 19:58:26 -0800 | [diff] [blame] | 3293 | ? toFrontTask.getStack() : toFrontActivity.getActivityStack(); |
Wale Ogunwale | 6827856 | 2017-09-23 17:13:55 -0700 | [diff] [blame] | 3294 | if (targetStack != null && targetStack.isActivityTypeAssistant()) { |
Winson Chung | f7e03e1 | 2017-08-22 11:32:16 -0700 | [diff] [blame] | 3295 | // Ensure the task/activity being brought forward is not the assistant |
| 3296 | return false; |
| 3297 | } |
Winson Chung | f7e03e1 | 2017-08-22 11:32:16 -0700 | [diff] [blame] | 3298 | return true; |
| 3299 | } |
| 3300 | |
Jorim Jaggi | 02886a8 | 2016-12-06 09:10:06 -0800 | [diff] [blame] | 3301 | private boolean isTaskSwitch(ActivityRecord r, |
| 3302 | ActivityRecord topFocusedActivity) { |
Wale Ogunwale | 8b19de9 | 2018-11-29 19:58:26 -0800 | [diff] [blame] | 3303 | return topFocusedActivity != null && r.getTaskRecord() != topFocusedActivity.getTaskRecord(); |
Jorim Jaggi | 02886a8 | 2016-12-06 09:10:06 -0800 | [diff] [blame] | 3304 | } |
| 3305 | |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 3306 | /** |
| 3307 | * Perform a reset of the given task, if needed as part of launching it. |
| 3308 | * Returns the new HistoryRecord at the top of the task. |
| 3309 | */ |
Craig Mautner | e3a74d5 | 2013-02-22 14:14:58 -0800 | [diff] [blame] | 3310 | /** |
| 3311 | * Helper method for #resetTaskIfNeededLocked. |
| 3312 | * We are inside of the task being reset... we'll either finish this activity, push it out |
| 3313 | * for another task, or leave it as-is. |
| 3314 | * @param task The task containing the Activity (taskTop) that might be reset. |
| 3315 | * @param forceReset |
| 3316 | * @return An ActivityOptions that needs to be processed. |
| 3317 | */ |
Andrii Kulian | 21713ac | 2016-10-12 22:05:05 -0700 | [diff] [blame] | 3318 | private ActivityOptions resetTargetTaskIfNeededLocked(TaskRecord task, boolean forceReset) { |
Craig Mautner | e3a74d5 | 2013-02-22 14:14:58 -0800 | [diff] [blame] | 3319 | ActivityOptions topOptions = null; |
| 3320 | |
| 3321 | int replyChainEnd = -1; |
| 3322 | boolean canMoveOptions = true; |
| 3323 | |
| 3324 | // We only do this for activities that are not the root of the task (since if we finish |
| 3325 | // the root, we may no longer have the task!). |
| 3326 | final ArrayList<ActivityRecord> activities = task.mActivities; |
| 3327 | final int numActivities = activities.size(); |
Craig Mautner | 9d4e9bc | 2014-06-18 18:34:56 -0700 | [diff] [blame] | 3328 | final int rootActivityNdx = task.findEffectiveRootIndex(); |
| 3329 | for (int i = numActivities - 1; i > rootActivityNdx; --i ) { |
Craig Mautner | e3a74d5 | 2013-02-22 14:14:58 -0800 | [diff] [blame] | 3330 | ActivityRecord target = activities.get(i); |
Craig Mautner | 76ae2f0 | 2014-07-16 16:16:19 +0000 | [diff] [blame] | 3331 | if (target.frontOfTask) |
| 3332 | break; |
Craig Mautner | e3a74d5 | 2013-02-22 14:14:58 -0800 | [diff] [blame] | 3333 | |
| 3334 | final int flags = target.info.flags; |
| 3335 | final boolean finishOnTaskLaunch = |
| 3336 | (flags & ActivityInfo.FLAG_FINISH_ON_TASK_LAUNCH) != 0; |
| 3337 | final boolean allowTaskReparenting = |
| 3338 | (flags & ActivityInfo.FLAG_ALLOW_TASK_REPARENTING) != 0; |
| 3339 | final boolean clearWhenTaskReset = |
| 3340 | (target.intent.getFlags() & Intent.FLAG_ACTIVITY_CLEAR_WHEN_TASK_RESET) != 0; |
| 3341 | |
| 3342 | if (!finishOnTaskLaunch |
| 3343 | && !clearWhenTaskReset |
| 3344 | && target.resultTo != null) { |
| 3345 | // If this activity is sending a reply to a previous |
| 3346 | // activity, we can't do anything with it now until |
| 3347 | // we reach the start of the reply chain. |
| 3348 | // XXX note that we are assuming the result is always |
| 3349 | // to the previous activity, which is almost always |
| 3350 | // the case but we really shouldn't count on. |
| 3351 | if (replyChainEnd < 0) { |
| 3352 | replyChainEnd = i; |
| 3353 | } |
| 3354 | } else if (!finishOnTaskLaunch |
| 3355 | && !clearWhenTaskReset |
| 3356 | && allowTaskReparenting |
| 3357 | && target.taskAffinity != null |
| 3358 | && !target.taskAffinity.equals(task.affinity)) { |
| 3359 | // If this activity has an affinity for another |
| 3360 | // task, then we need to move it out of here. We will |
| 3361 | // move it as far out of the way as possible, to the |
| 3362 | // bottom of the activity stack. This also keeps it |
| 3363 | // correctly ordered with any activities we previously |
| 3364 | // moved. |
Craig Mautner | 329f412 | 2013-11-07 09:10:42 -0800 | [diff] [blame] | 3365 | final TaskRecord targetTask; |
Craig Mautner | dccb770 | 2013-09-17 15:53:34 -0700 | [diff] [blame] | 3366 | final ActivityRecord bottom = |
| 3367 | !mTaskHistory.isEmpty() && !mTaskHistory.get(0).mActivities.isEmpty() ? |
Craig Mautner | 329f412 | 2013-11-07 09:10:42 -0800 | [diff] [blame] | 3368 | mTaskHistory.get(0).mActivities.get(0) : null; |
Craig Mautner | dccb770 | 2013-09-17 15:53:34 -0700 | [diff] [blame] | 3369 | if (bottom != null && target.taskAffinity != null |
Wale Ogunwale | 8b19de9 | 2018-11-29 19:58:26 -0800 | [diff] [blame] | 3370 | && target.taskAffinity.equals(bottom.getTaskRecord().affinity)) { |
Craig Mautner | e3a74d5 | 2013-02-22 14:14:58 -0800 | [diff] [blame] | 3371 | // If the activity currently at the bottom has the |
| 3372 | // same task affinity as the one we are moving, |
| 3373 | // then merge it into the same task. |
Wale Ogunwale | 8b19de9 | 2018-11-29 19:58:26 -0800 | [diff] [blame] | 3374 | targetTask = bottom.getTaskRecord(); |
Wale Ogunwale | ee006da | 2015-03-30 14:49:25 -0700 | [diff] [blame] | 3375 | if (DEBUG_TASKS) Slog.v(TAG_TASKS, "Start pushing activity " + target |
Bryce Lee | af691c0 | 2017-03-20 14:20:22 -0700 | [diff] [blame] | 3376 | + " out to bottom task " + targetTask); |
Craig Mautner | e3a74d5 | 2013-02-22 14:14:58 -0800 | [diff] [blame] | 3377 | } else { |
Suprabh Shukla | 09a88f5 | 2015-12-02 14:36:31 -0800 | [diff] [blame] | 3378 | targetTask = createTaskRecord( |
Wale Ogunwale | 8b19de9 | 2018-11-29 19:58:26 -0800 | [diff] [blame] | 3379 | mStackSupervisor.getNextTaskIdForUserLocked(target.mUserId), |
Wale Ogunwale | 6fbde9f | 2017-08-24 07:24:12 -0700 | [diff] [blame] | 3380 | target.info, null, null, null, false); |
Craig Mautner | 329f412 | 2013-11-07 09:10:42 -0800 | [diff] [blame] | 3381 | targetTask.affinityIntent = target.intent; |
Wale Ogunwale | ee006da | 2015-03-30 14:49:25 -0700 | [diff] [blame] | 3382 | if (DEBUG_TASKS) Slog.v(TAG_TASKS, "Start pushing activity " + target |
Bryce Lee | af691c0 | 2017-03-20 14:20:22 -0700 | [diff] [blame] | 3383 | + " out to new task " + targetTask); |
Craig Mautner | e3a74d5 | 2013-02-22 14:14:58 -0800 | [diff] [blame] | 3384 | } |
| 3385 | |
Craig Mautner | 525f3d9 | 2013-05-07 14:01:50 -0700 | [diff] [blame] | 3386 | boolean noOptions = canMoveOptions; |
Craig Mautner | e3a74d5 | 2013-02-22 14:14:58 -0800 | [diff] [blame] | 3387 | final int start = replyChainEnd < 0 ? i : replyChainEnd; |
| 3388 | for (int srcPos = start; srcPos >= i; --srcPos) { |
Craig Mautner | dccb770 | 2013-09-17 15:53:34 -0700 | [diff] [blame] | 3389 | final ActivityRecord p = activities.get(srcPos); |
Craig Mautner | e3a74d5 | 2013-02-22 14:14:58 -0800 | [diff] [blame] | 3390 | if (p.finishing) { |
| 3391 | continue; |
| 3392 | } |
| 3393 | |
Craig Mautner | e3a74d5 | 2013-02-22 14:14:58 -0800 | [diff] [blame] | 3394 | canMoveOptions = false; |
Craig Mautner | 525f3d9 | 2013-05-07 14:01:50 -0700 | [diff] [blame] | 3395 | if (noOptions && topOptions == null) { |
Jorim Jaggi | 346702a | 2019-05-08 17:49:33 +0200 | [diff] [blame] | 3396 | topOptions = p.takeOptionsLocked(false /* fromClient */); |
Craig Mautner | e3a74d5 | 2013-02-22 14:14:58 -0800 | [diff] [blame] | 3397 | if (topOptions != null) { |
Craig Mautner | 525f3d9 | 2013-05-07 14:01:50 -0700 | [diff] [blame] | 3398 | noOptions = false; |
Craig Mautner | e3a74d5 | 2013-02-22 14:14:58 -0800 | [diff] [blame] | 3399 | } |
| 3400 | } |
Wale Ogunwale | 0fc365c | 2015-05-25 19:35:42 -0700 | [diff] [blame] | 3401 | if (DEBUG_ADD_REMOVE) Slog.i(TAG_ADD_REMOVE, |
| 3402 | "Removing activity " + p + " from task=" + task + " adding to task=" |
| 3403 | + targetTask + " Callers=" + Debug.getCallers(4)); |
Wale Ogunwale | ee006da | 2015-03-30 14:49:25 -0700 | [diff] [blame] | 3404 | if (DEBUG_TASKS) Slog.v(TAG_TASKS, |
Bryce Lee | af691c0 | 2017-03-20 14:20:22 -0700 | [diff] [blame] | 3405 | "Pushing next activity " + p + " out to target's task " + target); |
Wale Ogunwale | a0cd15e | 2017-02-01 15:33:08 -0800 | [diff] [blame] | 3406 | p.reparent(targetTask, 0 /* position - bottom */, "resetTargetTaskIfNeeded"); |
Craig Mautner | e3a74d5 | 2013-02-22 14:14:58 -0800 | [diff] [blame] | 3407 | } |
| 3408 | |
Riddle Hsu | 86cb7de | 2018-08-13 23:29:58 +0800 | [diff] [blame] | 3409 | positionChildWindowContainerAtBottom(targetTask); |
Craig Mautner | e3a74d5 | 2013-02-22 14:14:58 -0800 | [diff] [blame] | 3410 | replyChainEnd = -1; |
| 3411 | } else if (forceReset || finishOnTaskLaunch || clearWhenTaskReset) { |
| 3412 | // If the activity should just be removed -- either |
| 3413 | // because it asks for it, or the task should be |
| 3414 | // cleared -- then finish it and anything that is |
| 3415 | // part of its reply chain. |
| 3416 | int end; |
| 3417 | if (clearWhenTaskReset) { |
| 3418 | // In this case, we want to finish this activity |
| 3419 | // and everything above it, so be sneaky and pretend |
| 3420 | // like these are all in the reply chain. |
Mark Lu | 4b5a9a0 | 2014-12-09 14:47:13 +0800 | [diff] [blame] | 3421 | end = activities.size() - 1; |
Craig Mautner | e3a74d5 | 2013-02-22 14:14:58 -0800 | [diff] [blame] | 3422 | } else if (replyChainEnd < 0) { |
| 3423 | end = i; |
| 3424 | } else { |
| 3425 | end = replyChainEnd; |
| 3426 | } |
Craig Mautner | 525f3d9 | 2013-05-07 14:01:50 -0700 | [diff] [blame] | 3427 | boolean noOptions = canMoveOptions; |
Craig Mautner | e3a74d5 | 2013-02-22 14:14:58 -0800 | [diff] [blame] | 3428 | for (int srcPos = i; srcPos <= end; srcPos++) { |
Craig Mautner | 525f3d9 | 2013-05-07 14:01:50 -0700 | [diff] [blame] | 3429 | ActivityRecord p = activities.get(srcPos); |
Craig Mautner | e3a74d5 | 2013-02-22 14:14:58 -0800 | [diff] [blame] | 3430 | if (p.finishing) { |
| 3431 | continue; |
| 3432 | } |
| 3433 | canMoveOptions = false; |
Craig Mautner | 525f3d9 | 2013-05-07 14:01:50 -0700 | [diff] [blame] | 3434 | if (noOptions && topOptions == null) { |
Jorim Jaggi | 346702a | 2019-05-08 17:49:33 +0200 | [diff] [blame] | 3435 | topOptions = p.takeOptionsLocked(false /* fromClient */); |
Craig Mautner | e3a74d5 | 2013-02-22 14:14:58 -0800 | [diff] [blame] | 3436 | if (topOptions != null) { |
Craig Mautner | 525f3d9 | 2013-05-07 14:01:50 -0700 | [diff] [blame] | 3437 | noOptions = false; |
Craig Mautner | e3a74d5 | 2013-02-22 14:14:58 -0800 | [diff] [blame] | 3438 | } |
| 3439 | } |
Wale Ogunwale | ee006da | 2015-03-30 14:49:25 -0700 | [diff] [blame] | 3440 | if (DEBUG_TASKS) Slog.w(TAG_TASKS, |
Craig Mautner | 5854780 | 2013-03-05 08:23:53 -0800 | [diff] [blame] | 3441 | "resetTaskIntendedTask: calling finishActivity on " + p); |
Todd Kennedy | 539db51 | 2014-12-15 09:57:55 -0800 | [diff] [blame] | 3442 | if (finishActivityLocked( |
Wale Ogunwale | 586a8ee | 2019-06-04 13:44:14 +0000 | [diff] [blame] | 3443 | p, Activity.RESULT_CANCELED, null, "reset-task", false)) { |
Craig Mautner | e3a74d5 | 2013-02-22 14:14:58 -0800 | [diff] [blame] | 3444 | end--; |
| 3445 | srcPos--; |
| 3446 | } |
| 3447 | } |
| 3448 | replyChainEnd = -1; |
| 3449 | } else { |
| 3450 | // If we were in the middle of a chain, well the |
| 3451 | // activity that started it all doesn't want anything |
| 3452 | // special, so leave it all as-is. |
| 3453 | replyChainEnd = -1; |
| 3454 | } |
| 3455 | } |
| 3456 | |
| 3457 | return topOptions; |
| 3458 | } |
| 3459 | |
| 3460 | /** |
| 3461 | * Helper method for #resetTaskIfNeededLocked. Processes all of the activities in a given |
| 3462 | * TaskRecord looking for an affinity with the task of resetTaskIfNeededLocked.taskTop. |
| 3463 | * @param affinityTask The task we are looking for an affinity to. |
| 3464 | * @param task Task that resetTaskIfNeededLocked.taskTop belongs to. |
| 3465 | * @param topTaskIsHigher True if #task has already been processed by resetTaskIfNeededLocked. |
| 3466 | * @param forceReset Flag passed in to resetTaskIfNeededLocked. |
| 3467 | */ |
Craig Mautner | 525f3d9 | 2013-05-07 14:01:50 -0700 | [diff] [blame] | 3468 | private int resetAffinityTaskIfNeededLocked(TaskRecord affinityTask, TaskRecord task, |
Craig Mautner | 7787877 | 2013-03-04 19:46:24 -0800 | [diff] [blame] | 3469 | boolean topTaskIsHigher, boolean forceReset, int taskInsertionPoint) { |
Craig Mautner | e3a74d5 | 2013-02-22 14:14:58 -0800 | [diff] [blame] | 3470 | int replyChainEnd = -1; |
| 3471 | final int taskId = task.taskId; |
| 3472 | final String taskAffinity = task.affinity; |
| 3473 | |
| 3474 | final ArrayList<ActivityRecord> activities = affinityTask.mActivities; |
| 3475 | final int numActivities = activities.size(); |
Craig Mautner | 9d4e9bc | 2014-06-18 18:34:56 -0700 | [diff] [blame] | 3476 | final int rootActivityNdx = affinityTask.findEffectiveRootIndex(); |
| 3477 | |
| 3478 | // Do not operate on or below the effective root Activity. |
| 3479 | for (int i = numActivities - 1; i > rootActivityNdx; --i) { |
Craig Mautner | e3a74d5 | 2013-02-22 14:14:58 -0800 | [diff] [blame] | 3480 | ActivityRecord target = activities.get(i); |
Craig Mautner | 76ae2f0 | 2014-07-16 16:16:19 +0000 | [diff] [blame] | 3481 | if (target.frontOfTask) |
| 3482 | break; |
Craig Mautner | e3a74d5 | 2013-02-22 14:14:58 -0800 | [diff] [blame] | 3483 | |
| 3484 | final int flags = target.info.flags; |
| 3485 | boolean finishOnTaskLaunch = (flags & ActivityInfo.FLAG_FINISH_ON_TASK_LAUNCH) != 0; |
| 3486 | boolean allowTaskReparenting = (flags & ActivityInfo.FLAG_ALLOW_TASK_REPARENTING) != 0; |
| 3487 | |
| 3488 | if (target.resultTo != null) { |
| 3489 | // If this activity is sending a reply to a previous |
| 3490 | // activity, we can't do anything with it now until |
| 3491 | // we reach the start of the reply chain. |
| 3492 | // XXX note that we are assuming the result is always |
| 3493 | // to the previous activity, which is almost always |
| 3494 | // the case but we really shouldn't count on. |
| 3495 | if (replyChainEnd < 0) { |
| 3496 | replyChainEnd = i; |
| 3497 | } |
| 3498 | } else if (topTaskIsHigher |
| 3499 | && allowTaskReparenting |
| 3500 | && taskAffinity != null |
| 3501 | && taskAffinity.equals(target.taskAffinity)) { |
| 3502 | // This activity has an affinity for our task. Either remove it if we are |
| 3503 | // clearing or move it over to our task. Note that |
| 3504 | // we currently punt on the case where we are resetting a |
| 3505 | // task that is not at the top but who has activities above |
| 3506 | // with an affinity to it... this is really not a normal |
| 3507 | // case, and we will need to later pull that task to the front |
| 3508 | // and usually at that point we will do the reset and pick |
| 3509 | // up those remaining activities. (This only happens if |
| 3510 | // someone starts an activity in a new task from an activity |
| 3511 | // in a task that is not currently on top.) |
| 3512 | if (forceReset || finishOnTaskLaunch) { |
| 3513 | final int start = replyChainEnd >= 0 ? replyChainEnd : i; |
Wale Ogunwale | ee006da | 2015-03-30 14:49:25 -0700 | [diff] [blame] | 3514 | if (DEBUG_TASKS) Slog.v(TAG_TASKS, |
| 3515 | "Finishing task at index " + start + " to " + i); |
Craig Mautner | e3a74d5 | 2013-02-22 14:14:58 -0800 | [diff] [blame] | 3516 | for (int srcPos = start; srcPos >= i; --srcPos) { |
| 3517 | final ActivityRecord p = activities.get(srcPos); |
| 3518 | if (p.finishing) { |
| 3519 | continue; |
| 3520 | } |
Todd Kennedy | 539db51 | 2014-12-15 09:57:55 -0800 | [diff] [blame] | 3521 | finishActivityLocked( |
Wale Ogunwale | 586a8ee | 2019-06-04 13:44:14 +0000 | [diff] [blame] | 3522 | p, Activity.RESULT_CANCELED, null, "move-affinity", false); |
Craig Mautner | e3a74d5 | 2013-02-22 14:14:58 -0800 | [diff] [blame] | 3523 | } |
| 3524 | } else { |
Craig Mautner | 7787877 | 2013-03-04 19:46:24 -0800 | [diff] [blame] | 3525 | if (taskInsertionPoint < 0) { |
| 3526 | taskInsertionPoint = task.mActivities.size(); |
Craig Mautner | d232895 | 2013-03-05 12:46:26 -0800 | [diff] [blame] | 3527 | |
Craig Mautner | 7787877 | 2013-03-04 19:46:24 -0800 | [diff] [blame] | 3528 | } |
Craig Mautner | 7787877 | 2013-03-04 19:46:24 -0800 | [diff] [blame] | 3529 | |
| 3530 | final int start = replyChainEnd >= 0 ? replyChainEnd : i; |
Wale Ogunwale | ee006da | 2015-03-30 14:49:25 -0700 | [diff] [blame] | 3531 | if (DEBUG_TASKS) Slog.v(TAG_TASKS, |
| 3532 | "Reparenting from task=" + affinityTask + ":" + start + "-" + i |
| 3533 | + " to task=" + task + ":" + taskInsertionPoint); |
Craig Mautner | 7787877 | 2013-03-04 19:46:24 -0800 | [diff] [blame] | 3534 | for (int srcPos = start; srcPos >= i; --srcPos) { |
Craig Mautner | e3a74d5 | 2013-02-22 14:14:58 -0800 | [diff] [blame] | 3535 | final ActivityRecord p = activities.get(srcPos); |
Winson Chung | 3048004 | 2017-01-26 10:55:34 -0800 | [diff] [blame] | 3536 | p.reparent(task, taskInsertionPoint, "resetAffinityTaskIfNeededLocked"); |
Craig Mautner | e3a74d5 | 2013-02-22 14:14:58 -0800 | [diff] [blame] | 3537 | |
Wale Ogunwale | 0fc365c | 2015-05-25 19:35:42 -0700 | [diff] [blame] | 3538 | if (DEBUG_ADD_REMOVE) Slog.i(TAG_ADD_REMOVE, |
| 3539 | "Removing and adding activity " + p + " to stack at " + task |
| 3540 | + " callers=" + Debug.getCallers(3)); |
Wale Ogunwale | ee006da | 2015-03-30 14:49:25 -0700 | [diff] [blame] | 3541 | if (DEBUG_TASKS) Slog.v(TAG_TASKS, "Pulling activity " + p |
| 3542 | + " from " + srcPos + " in to resetting task " + task); |
Craig Mautner | e3a74d5 | 2013-02-22 14:14:58 -0800 | [diff] [blame] | 3543 | } |
Riddle Hsu | 86cb7de | 2018-08-13 23:29:58 +0800 | [diff] [blame] | 3544 | positionChildWindowContainerAtTop(task); |
Craig Mautner | e3a74d5 | 2013-02-22 14:14:58 -0800 | [diff] [blame] | 3545 | |
| 3546 | // Now we've moved it in to place... but what if this is |
| 3547 | // a singleTop activity and we have put it on top of another |
| 3548 | // instance of the same activity? Then we drop the instance |
| 3549 | // below so it remains singleTop. |
| 3550 | if (target.info.launchMode == ActivityInfo.LAUNCH_SINGLE_TOP) { |
| 3551 | ArrayList<ActivityRecord> taskActivities = task.mActivities; |
Craig Mautner | e3a74d5 | 2013-02-22 14:14:58 -0800 | [diff] [blame] | 3552 | int targetNdx = taskActivities.indexOf(target); |
| 3553 | if (targetNdx > 0) { |
| 3554 | ActivityRecord p = taskActivities.get(targetNdx - 1); |
| 3555 | if (p.intent.getComponent().equals(target.intent.getComponent())) { |
Wale Ogunwale | 586a8ee | 2019-06-04 13:44:14 +0000 | [diff] [blame] | 3556 | finishActivityLocked(p, Activity.RESULT_CANCELED, null, "replace", |
| 3557 | false); |
Craig Mautner | e3a74d5 | 2013-02-22 14:14:58 -0800 | [diff] [blame] | 3558 | } |
| 3559 | } |
| 3560 | } |
| 3561 | } |
| 3562 | |
| 3563 | replyChainEnd = -1; |
| 3564 | } |
| 3565 | } |
Craig Mautner | 7787877 | 2013-03-04 19:46:24 -0800 | [diff] [blame] | 3566 | return taskInsertionPoint; |
Craig Mautner | e3a74d5 | 2013-02-22 14:14:58 -0800 | [diff] [blame] | 3567 | } |
| 3568 | |
Craig Mautner | 8849a5e | 2013-04-02 16:41:03 -0700 | [diff] [blame] | 3569 | final ActivityRecord resetTaskIfNeededLocked(ActivityRecord taskTop, |
Craig Mautner | e3a74d5 | 2013-02-22 14:14:58 -0800 | [diff] [blame] | 3570 | ActivityRecord newActivity) { |
Winson Chung | 5fa3975 | 2017-10-04 14:50:15 -0700 | [diff] [blame] | 3571 | final boolean forceReset = |
Craig Mautner | e3a74d5 | 2013-02-22 14:14:58 -0800 | [diff] [blame] | 3572 | (newActivity.info.flags & ActivityInfo.FLAG_CLEAR_TASK_ON_LAUNCH) != 0; |
Wale Ogunwale | 8b19de9 | 2018-11-29 19:58:26 -0800 | [diff] [blame] | 3573 | final TaskRecord task = taskTop.getTaskRecord(); |
Craig Mautner | e3a74d5 | 2013-02-22 14:14:58 -0800 | [diff] [blame] | 3574 | |
| 3575 | /** False until we evaluate the TaskRecord associated with taskTop. Switches to true |
| 3576 | * for remaining tasks. Used for later tasks to reparent to task. */ |
| 3577 | boolean taskFound = false; |
| 3578 | |
| 3579 | /** If ActivityOptions are moved out and need to be aborted or moved to taskTop. */ |
| 3580 | ActivityOptions topOptions = null; |
| 3581 | |
Craig Mautner | 7787877 | 2013-03-04 19:46:24 -0800 | [diff] [blame] | 3582 | // Preserve the location for reparenting in the new task. |
| 3583 | int reparentInsertionPoint = -1; |
| 3584 | |
Craig Mautner | e3a74d5 | 2013-02-22 14:14:58 -0800 | [diff] [blame] | 3585 | for (int i = mTaskHistory.size() - 1; i >= 0; --i) { |
| 3586 | final TaskRecord targetTask = mTaskHistory.get(i); |
| 3587 | |
| 3588 | if (targetTask == task) { |
| 3589 | topOptions = resetTargetTaskIfNeededLocked(task, forceReset); |
| 3590 | taskFound = true; |
| 3591 | } else { |
Craig Mautner | 7787877 | 2013-03-04 19:46:24 -0800 | [diff] [blame] | 3592 | reparentInsertionPoint = resetAffinityTaskIfNeededLocked(targetTask, task, |
| 3593 | taskFound, forceReset, reparentInsertionPoint); |
Craig Mautner | e3a74d5 | 2013-02-22 14:14:58 -0800 | [diff] [blame] | 3594 | } |
| 3595 | } |
| 3596 | |
Craig Mautner | 70a8693 | 2013-02-28 22:37:44 -0800 | [diff] [blame] | 3597 | int taskNdx = mTaskHistory.indexOf(task); |
riddle_hsu | 1d7919a | 2015-03-11 17:09:50 +0800 | [diff] [blame] | 3598 | if (taskNdx >= 0) { |
| 3599 | do { |
| 3600 | taskTop = mTaskHistory.get(taskNdx--).getTopActivity(); |
| 3601 | } while (taskTop == null && taskNdx >= 0); |
| 3602 | } |
Craig Mautner | 70a8693 | 2013-02-28 22:37:44 -0800 | [diff] [blame] | 3603 | |
Craig Mautner | e3a74d5 | 2013-02-22 14:14:58 -0800 | [diff] [blame] | 3604 | if (topOptions != null) { |
| 3605 | // If we got some ActivityOptions from an activity on top that |
| 3606 | // was removed from the task, propagate them to the new real top. |
| 3607 | if (taskTop != null) { |
Craig Mautner | e3a74d5 | 2013-02-22 14:14:58 -0800 | [diff] [blame] | 3608 | taskTop.updateOptionsLocked(topOptions); |
| 3609 | } else { |
Craig Mautner | e3a74d5 | 2013-02-22 14:14:58 -0800 | [diff] [blame] | 3610 | topOptions.abort(); |
| 3611 | } |
| 3612 | } |
| 3613 | |
| 3614 | return taskTop; |
| 3615 | } |
| 3616 | |
Wale Ogunwale | 586a8ee | 2019-06-04 13:44:14 +0000 | [diff] [blame] | 3617 | void sendActivityResultLocked(int callingUid, ActivityRecord r, |
| 3618 | String resultWho, int requestCode, int resultCode, Intent data) { |
| 3619 | |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 3620 | if (callingUid > 0) { |
Wale Ogunwale | 586a8ee | 2019-06-04 13:44:14 +0000 | [diff] [blame] | 3621 | mService.mUgmInternal.grantUriPermissionFromIntent(callingUid, r.packageName, |
| 3622 | data, r.getUriPermissionsLocked(), r.mUserId); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 3623 | } |
| 3624 | |
| 3625 | if (DEBUG_RESULTS) Slog.v(TAG, "Send activity result to " + r |
| 3626 | + " : who=" + resultWho + " req=" + requestCode |
Wale Ogunwale | 586a8ee | 2019-06-04 13:44:14 +0000 | [diff] [blame] | 3627 | + " res=" + resultCode + " data=" + data); |
Wale Ogunwale | 9e4f3e0 | 2018-05-17 09:35:39 -0700 | [diff] [blame] | 3628 | if (mResumedActivity == r && r.attachedToProcess()) { |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 3629 | try { |
| 3630 | ArrayList<ResultInfo> list = new ArrayList<ResultInfo>(); |
| 3631 | list.add(new ResultInfo(resultWho, requestCode, |
Wale Ogunwale | 586a8ee | 2019-06-04 13:44:14 +0000 | [diff] [blame] | 3632 | resultCode, data)); |
Wale Ogunwale | 9e4f3e0 | 2018-05-17 09:35:39 -0700 | [diff] [blame] | 3633 | mService.getLifecycleManager().scheduleTransaction(r.app.getThread(), r.appToken, |
Andrii Kulian | 9c5ea9c | 2017-12-07 09:31:01 -0800 | [diff] [blame] | 3634 | ActivityResultItem.obtain(list)); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 3635 | return; |
| 3636 | } catch (Exception e) { |
| 3637 | Slog.w(TAG, "Exception thrown sending result to " + r, e); |
| 3638 | } |
| 3639 | } |
| 3640 | |
Wale Ogunwale | 586a8ee | 2019-06-04 13:44:14 +0000 | [diff] [blame] | 3641 | r.addResultLocked(null, resultWho, requestCode, resultCode, data); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 3642 | } |
| 3643 | |
Shunta Sato | 63b8ee3 | 2016-07-11 13:32:52 +0900 | [diff] [blame] | 3644 | /** 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] | 3645 | private boolean isATopFinishingTask(TaskRecord task) { |
Shunta Sato | 63b8ee3 | 2016-07-11 13:32:52 +0900 | [diff] [blame] | 3646 | for (int i = mTaskHistory.size() - 1; i >= 0; --i) { |
| 3647 | final TaskRecord current = mTaskHistory.get(i); |
| 3648 | final ActivityRecord r = current.topRunningActivityLocked(); |
| 3649 | if (r != null) { |
| 3650 | // We got a top running activity, so there isn't a top finishing task... |
| 3651 | return false; |
| 3652 | } |
| 3653 | if (current == task) { |
| 3654 | return true; |
| 3655 | } |
| 3656 | } |
| 3657 | return false; |
| 3658 | } |
| 3659 | |
Wale Ogunwale | 66e1685 | 2017-10-19 13:35:52 -0700 | [diff] [blame] | 3660 | private void adjustFocusedActivityStack(ActivityRecord r, String reason) { |
Wale Ogunwale | d32da47 | 2018-11-16 07:19:28 -0800 | [diff] [blame] | 3661 | if (!mRootActivityContainer.isTopDisplayFocusedStack(this) || |
Shunta Sato | 63b8ee3 | 2016-07-11 13:32:52 +0900 | [diff] [blame] | 3662 | ((mResumedActivity != r) && (mResumedActivity != null))) { |
Wale Ogunwale | d045c82 | 2015-12-02 09:14:28 -0800 | [diff] [blame] | 3663 | return; |
| 3664 | } |
| 3665 | |
| 3666 | final ActivityRecord next = topRunningActivityLocked(); |
| 3667 | final String myReason = reason + " adjustFocus"; |
Bryce Lee | 3345c4e | 2017-04-25 07:40:41 -0700 | [diff] [blame] | 3668 | |
Wale Ogunwale | 66e1685 | 2017-10-19 13:35:52 -0700 | [diff] [blame] | 3669 | if (next == r) { |
Wale Ogunwale | d32da47 | 2018-11-16 07:19:28 -0800 | [diff] [blame] | 3670 | final ActivityRecord top = mRootActivityContainer.topRunningActivity(); |
Louis Chang | 1944345 | 2018-10-09 12:10:21 +0800 | [diff] [blame] | 3671 | if (top != null) { |
| 3672 | top.moveFocusableActivityToTop(myReason); |
| 3673 | } |
Wale Ogunwale | 66e1685 | 2017-10-19 13:35:52 -0700 | [diff] [blame] | 3674 | return; |
Wale Ogunwale | d045c82 | 2015-12-02 09:14:28 -0800 | [diff] [blame] | 3675 | } |
Wale Ogunwale | d697cea | 2015-02-20 17:19:49 -0800 | [diff] [blame] | 3676 | |
Wale Ogunwale | 66e1685 | 2017-10-19 13:35:52 -0700 | [diff] [blame] | 3677 | if (next != null && isFocusable()) { |
| 3678 | // Keep focus in stack if we have a top running activity and are focusable. |
| 3679 | return; |
| 3680 | } |
| 3681 | |
| 3682 | // Task is not guaranteed to be non-null. For example, destroying the |
| 3683 | // {@link ActivityRecord} will disassociate the task from the activity. |
Wale Ogunwale | 8b19de9 | 2018-11-29 19:58:26 -0800 | [diff] [blame] | 3684 | final TaskRecord task = r.getTaskRecord(); |
Wale Ogunwale | 66e1685 | 2017-10-19 13:35:52 -0700 | [diff] [blame] | 3685 | |
| 3686 | if (task == null) { |
| 3687 | throw new IllegalStateException("activity no longer associated with task:" + r); |
| 3688 | } |
| 3689 | |
| 3690 | // Move focus to next focusable stack if possible. |
Riddle Hsu | 3026e8d | 2018-08-03 15:50:53 +0800 | [diff] [blame] | 3691 | final ActivityStack nextFocusableStack = adjustFocusToNextFocusableStack(myReason); |
| 3692 | if (nextFocusableStack != null) { |
| 3693 | final ActivityRecord top = nextFocusableStack.topRunningActivityLocked(); |
Wale Ogunwale | d32da47 | 2018-11-16 07:19:28 -0800 | [diff] [blame] | 3694 | if (top != null && top == mRootActivityContainer.getTopResumedActivity()) { |
Riddle Hsu | 3026e8d | 2018-08-03 15:50:53 +0800 | [diff] [blame] | 3695 | // TODO(b/111361570): Remove this and update focused app per-display in |
| 3696 | // WindowManager every time an activity becomes resumed in |
| 3697 | // ActivityTaskManagerService#setResumedActivityUncheckLocked(). |
| 3698 | mService.setResumedActivityUncheckLocked(top, reason); |
| 3699 | } |
Wale Ogunwale | 66e1685 | 2017-10-19 13:35:52 -0700 | [diff] [blame] | 3700 | return; |
| 3701 | } |
| 3702 | |
| 3703 | // Whatever...go home. |
Louis Chang | bd48dca | 2018-08-29 17:44:34 +0800 | [diff] [blame] | 3704 | getDisplay().moveHomeActivityToTop(myReason); |
Craig Mautner | 04f0b70 | 2013-10-22 12:31:01 -0700 | [diff] [blame] | 3705 | } |
| 3706 | |
Andrii Kulian | ab132ee | 2018-07-24 22:10:21 +0800 | [diff] [blame] | 3707 | /** |
| 3708 | * Find next proper focusable stack and make it focused. |
| 3709 | * @return The stack that now got the focus, {@code null} if none found. |
| 3710 | */ |
| 3711 | ActivityStack adjustFocusToNextFocusableStack(String reason) { |
Wale Ogunwale | 66e1685 | 2017-10-19 13:35:52 -0700 | [diff] [blame] | 3712 | return adjustFocusToNextFocusableStack(reason, false /* allowFocusSelf */); |
Andrii Kulian | 250d653 | 2017-02-08 23:30:45 -0800 | [diff] [blame] | 3713 | } |
| 3714 | |
| 3715 | /** |
| 3716 | * Find next proper focusable stack and make it focused. |
| 3717 | * @param allowFocusSelf Is the focus allowed to remain on the same stack. |
Andrii Kulian | ab132ee | 2018-07-24 22:10:21 +0800 | [diff] [blame] | 3718 | * @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] | 3719 | */ |
Andrii Kulian | ab132ee | 2018-07-24 22:10:21 +0800 | [diff] [blame] | 3720 | private ActivityStack adjustFocusToNextFocusableStack(String reason, boolean allowFocusSelf) { |
Wale Ogunwale | e1f68ce | 2018-03-09 08:58:54 -0800 | [diff] [blame] | 3721 | final ActivityStack stack = |
Wale Ogunwale | d32da47 | 2018-11-16 07:19:28 -0800 | [diff] [blame] | 3722 | mRootActivityContainer.getNextFocusableStack(this, !allowFocusSelf); |
Wale Ogunwale | 4cea0f5 | 2015-12-25 06:30:31 -0800 | [diff] [blame] | 3723 | final String myReason = reason + " adjustFocusToNextFocusableStack"; |
Wale Ogunwale | d697cea | 2015-02-20 17:19:49 -0800 | [diff] [blame] | 3724 | if (stack == null) { |
Andrii Kulian | ab132ee | 2018-07-24 22:10:21 +0800 | [diff] [blame] | 3725 | return null; |
Wale Ogunwale | d697cea | 2015-02-20 17:19:49 -0800 | [diff] [blame] | 3726 | } |
Wale Ogunwale | d34e80c | 2016-03-23 17:08:44 -0700 | [diff] [blame] | 3727 | |
Wale Ogunwale | c750f5f | 2016-03-28 07:43:51 -0700 | [diff] [blame] | 3728 | final ActivityRecord top = stack.topRunningActivityLocked(); |
| 3729 | |
Wale Ogunwale | 66e1685 | 2017-10-19 13:35:52 -0700 | [diff] [blame] | 3730 | if (stack.isActivityTypeHome() && (top == null || !top.visible)) { |
Wale Ogunwale | c750f5f | 2016-03-28 07:43:51 -0700 | [diff] [blame] | 3731 | // 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] | 3732 | // 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] | 3733 | stack.getDisplay().moveHomeActivityToTop(reason); |
Andrii Kulian | ab132ee | 2018-07-24 22:10:21 +0800 | [diff] [blame] | 3734 | return stack; |
Wale Ogunwale | d34e80c | 2016-03-23 17:08:44 -0700 | [diff] [blame] | 3735 | } |
Chong Zhang | 6cda19c | 2016-06-14 19:07:56 -0700 | [diff] [blame] | 3736 | |
| 3737 | stack.moveToFront(myReason); |
Andrii Kulian | ab132ee | 2018-07-24 22:10:21 +0800 | [diff] [blame] | 3738 | return stack; |
Wale Ogunwale | d697cea | 2015-02-20 17:19:49 -0800 | [diff] [blame] | 3739 | } |
| 3740 | |
Craig Mautner | f333327 | 2013-04-22 10:55:53 -0700 | [diff] [blame] | 3741 | final void stopActivityLocked(ActivityRecord r) { |
Wale Ogunwale | ee006da | 2015-03-30 14:49:25 -0700 | [diff] [blame] | 3742 | if (DEBUG_SWITCH) Slog.d(TAG_SWITCH, "Stopping: " + r); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 3743 | if ((r.intent.getFlags()&Intent.FLAG_ACTIVITY_NO_HISTORY) != 0 |
| 3744 | || (r.info.flags&ActivityInfo.FLAG_NO_HISTORY) != 0) { |
| 3745 | if (!r.finishing) { |
David Stevens | 9440dc8 | 2017-03-16 19:00:20 -0700 | [diff] [blame] | 3746 | if (!shouldSleepActivities()) { |
Wale Ogunwale | 0fc365c | 2015-05-25 19:35:42 -0700 | [diff] [blame] | 3747 | if (DEBUG_STATES) Slog.d(TAG_STATES, "no-history finish of " + r); |
Wale Ogunwale | 586a8ee | 2019-06-04 13:44:14 +0000 | [diff] [blame] | 3748 | if (requestFinishActivityLocked(r.appToken, Activity.RESULT_CANCELED, null, |
| 3749 | "stop-no-history", false)) { |
Bryce Lee | 3345c4e | 2017-04-25 07:40:41 -0700 | [diff] [blame] | 3750 | // If {@link requestFinishActivityLocked} returns {@code true}, |
Wale Ogunwale | 66e1685 | 2017-10-19 13:35:52 -0700 | [diff] [blame] | 3751 | // {@link adjustFocusedActivityStack} would have been already called. |
Wale Ogunwale | 3f529ee | 2015-07-12 15:14:01 -0700 | [diff] [blame] | 3752 | r.resumeKeyDispatchingLocked(); |
| 3753 | return; |
| 3754 | } |
Christopher Tate | d3f175c | 2012-06-14 14:16:54 -0700 | [diff] [blame] | 3755 | } else { |
Wale Ogunwale | 0fc365c | 2015-05-25 19:35:42 -0700 | [diff] [blame] | 3756 | if (DEBUG_STATES) Slog.d(TAG_STATES, "Not finishing noHistory " + r |
Christopher Tate | d3f175c | 2012-06-14 14:16:54 -0700 | [diff] [blame] | 3757 | + " on stop because we're just sleeping"); |
| 3758 | } |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 3759 | } |
Christopher Tate | 5007ddd | 2012-06-12 13:08:18 -0700 | [diff] [blame] | 3760 | } |
| 3761 | |
Wale Ogunwale | 9e4f3e0 | 2018-05-17 09:35:39 -0700 | [diff] [blame] | 3762 | if (r.attachedToProcess()) { |
Wale Ogunwale | 66e1685 | 2017-10-19 13:35:52 -0700 | [diff] [blame] | 3763 | adjustFocusedActivityStack(r, "stopActivity"); |
Dianne Hackborn | 621e2fe | 2012-02-16 17:07:33 -0800 | [diff] [blame] | 3764 | r.resumeKeyDispatchingLocked(); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 3765 | try { |
| 3766 | r.stopped = false; |
Wale Ogunwale | 0fc365c | 2015-05-25 19:35:42 -0700 | [diff] [blame] | 3767 | if (DEBUG_STATES) Slog.v(TAG_STATES, |
| 3768 | "Moving to STOPPING: " + r + " (stop requested)"); |
Bryce Lee | 7ace395 | 2018-02-16 14:34:32 -0800 | [diff] [blame] | 3769 | r.setState(STOPPING, "stopActivityLocked"); |
Wale Ogunwale | ee006da | 2015-03-30 14:49:25 -0700 | [diff] [blame] | 3770 | if (DEBUG_VISIBILITY) Slog.v(TAG_VISIBILITY, |
| 3771 | "Stopping visible=" + r.visible + " for " + r); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 3772 | if (!r.visible) { |
Wale Ogunwale | b9a0c99 | 2017-04-18 07:25:20 -0700 | [diff] [blame] | 3773 | r.setVisible(false); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 3774 | } |
Wale Ogunwale | cd7043e | 2016-02-27 17:37:46 -0800 | [diff] [blame] | 3775 | EventLogTags.writeAmStopActivity( |
Wale Ogunwale | 8b19de9 | 2018-11-29 19:58:26 -0800 | [diff] [blame] | 3776 | r.mUserId, System.identityHashCode(r), r.shortComponentName); |
Wale Ogunwale | 9e4f3e0 | 2018-05-17 09:35:39 -0700 | [diff] [blame] | 3777 | mService.getLifecycleManager().scheduleTransaction(r.app.getThread(), r.appToken, |
Bryce Lee | 1d0d514 | 2018-04-12 10:35:07 -0700 | [diff] [blame] | 3778 | StopActivityItem.obtain(r.visible, r.configChangeFlags)); |
David Stevens | 9440dc8 | 2017-03-16 19:00:20 -0700 | [diff] [blame] | 3779 | if (shouldSleepOrShutDownActivities()) { |
Dianne Hackborn | 4eba96b | 2011-01-21 13:34:36 -0800 | [diff] [blame] | 3780 | r.setSleeping(true); |
| 3781 | } |
Craig Mautner | f7bfefb | 2013-05-16 17:30:44 -0700 | [diff] [blame] | 3782 | Message msg = mHandler.obtainMessage(STOP_TIMEOUT_MSG, r); |
Dianne Hackborn | 162bc0e | 2012-04-09 14:06:16 -0700 | [diff] [blame] | 3783 | mHandler.sendMessageDelayed(msg, STOP_TIMEOUT); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 3784 | } catch (Exception e) { |
| 3785 | // Maybe just ignore exceptions here... if the process |
| 3786 | // has crashed, our death notification will clean things |
| 3787 | // up. |
| 3788 | Slog.w(TAG, "Exception thrown during pause", e); |
| 3789 | // Just in case, assume it to be stopped. |
| 3790 | r.stopped = true; |
Wale Ogunwale | 0fc365c | 2015-05-25 19:35:42 -0700 | [diff] [blame] | 3791 | 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] | 3792 | r.setState(STOPPED, "stopActivityLocked"); |
Wale Ogunwale | f81c1d1 | 2016-01-12 12:20:18 -0800 | [diff] [blame] | 3793 | if (r.deferRelaunchUntilPaused) { |
Craig Mautner | ee2e45a | 2014-06-27 12:10:03 -0700 | [diff] [blame] | 3794 | destroyActivityLocked(r, true, "stop-except"); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 3795 | } |
| 3796 | } |
| 3797 | } |
| 3798 | } |
Craig Mautner | 23ac33b | 2013-04-01 16:26:35 -0700 | [diff] [blame] | 3799 | |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 3800 | /** |
| 3801 | * @return Returns true if the activity is being finished, false if for |
| 3802 | * some reason it is being left as-is. |
| 3803 | */ |
| 3804 | final boolean requestFinishActivityLocked(IBinder token, int resultCode, |
Wale Ogunwale | 586a8ee | 2019-06-04 13:44:14 +0000 | [diff] [blame] | 3805 | Intent resultData, String reason, boolean oomAdj) { |
Craig Mautner | d74f7d7 | 2013-02-26 13:41:02 -0800 | [diff] [blame] | 3806 | ActivityRecord r = isInStackLocked(token); |
Wale Ogunwale | 0fc365c | 2015-05-25 19:35:42 -0700 | [diff] [blame] | 3807 | if (DEBUG_RESULTS || DEBUG_STATES) Slog.v(TAG_STATES, |
| 3808 | "Finishing activity token=" + token + " r=" |
Christopher Tate | d3f175c | 2012-06-14 14:16:54 -0700 | [diff] [blame] | 3809 | + ", result=" + resultCode + ", data=" + resultData |
| 3810 | + ", reason=" + reason); |
Craig Mautner | d74f7d7 | 2013-02-26 13:41:02 -0800 | [diff] [blame] | 3811 | if (r == null) { |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 3812 | return false; |
| 3813 | } |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 3814 | |
Wale Ogunwale | 586a8ee | 2019-06-04 13:44:14 +0000 | [diff] [blame] | 3815 | finishActivityLocked(r, resultCode, resultData, reason, oomAdj); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 3816 | return true; |
| 3817 | } |
| 3818 | |
Craig Mautner | d232895 | 2013-03-05 12:46:26 -0800 | [diff] [blame] | 3819 | final void finishSubActivityLocked(ActivityRecord self, String resultWho, int requestCode) { |
Craig Mautner | 9658b31 | 2013-02-28 10:55:59 -0800 | [diff] [blame] | 3820 | for (int taskNdx = mTaskHistory.size() - 1; taskNdx >= 0; --taskNdx) { |
| 3821 | ArrayList<ActivityRecord> activities = mTaskHistory.get(taskNdx).mActivities; |
| 3822 | for (int activityNdx = activities.size() - 1; activityNdx >= 0; --activityNdx) { |
| 3823 | ActivityRecord r = activities.get(activityNdx); |
| 3824 | if (r.resultTo == self && r.requestCode == requestCode) { |
| 3825 | if ((r.resultWho == null && resultWho == null) || |
| 3826 | (r.resultWho != null && r.resultWho.equals(resultWho))) { |
Wale Ogunwale | 586a8ee | 2019-06-04 13:44:14 +0000 | [diff] [blame] | 3827 | finishActivityLocked(r, Activity.RESULT_CANCELED, null, "request-sub", |
| 3828 | false); |
Craig Mautner | 9658b31 | 2013-02-28 10:55:59 -0800 | [diff] [blame] | 3829 | } |
Dianne Hackborn | ecc5a9c | 2012-04-26 18:56:09 -0700 | [diff] [blame] | 3830 | } |
| 3831 | } |
| 3832 | } |
Wale Ogunwale | f673393 | 2018-06-27 05:14:34 -0700 | [diff] [blame] | 3833 | mService.updateOomAdj(); |
Dianne Hackborn | ecc5a9c | 2012-04-26 18:56:09 -0700 | [diff] [blame] | 3834 | } |
| 3835 | |
Andrii Kulian | 8cc92ac6 | 2018-04-02 23:14:18 -0700 | [diff] [blame] | 3836 | /** |
| 3837 | * Finish the topmost activity that belongs to the crashed app. We may also finish the activity |
| 3838 | * that requested launch of the crashed one to prevent launch-crash loop. |
| 3839 | * @param app The app that crashed. |
| 3840 | * @param reason Reason to perform this action. |
| 3841 | * @return The task that was finished in this stack, {@code null} if top running activity does |
| 3842 | * not belong to the crashed app. |
| 3843 | */ |
Wale Ogunwale | 9e4f3e0 | 2018-05-17 09:35:39 -0700 | [diff] [blame] | 3844 | final TaskRecord finishTopCrashedActivityLocked(WindowProcessController app, String reason) { |
Filip Gruszczynski | 3e85ba2 | 2015-10-05 22:48:30 -0700 | [diff] [blame] | 3845 | ActivityRecord r = topRunningActivityLocked(); |
Adrian Roos | 20d7df3 | 2016-01-12 18:59:43 +0100 | [diff] [blame] | 3846 | TaskRecord finishedTask = null; |
| 3847 | if (r == null || r.app != app) { |
| 3848 | return null; |
| 3849 | } |
| 3850 | Slog.w(TAG, " Force finishing activity " |
| 3851 | + r.intent.getComponent().flattenToShortString()); |
Wale Ogunwale | 8b19de9 | 2018-11-29 19:58:26 -0800 | [diff] [blame] | 3852 | finishedTask = r.getTaskRecord(); |
Bryce Lee | af691c0 | 2017-03-20 14:20:22 -0700 | [diff] [blame] | 3853 | int taskNdx = mTaskHistory.indexOf(finishedTask); |
| 3854 | final TaskRecord task = finishedTask; |
| 3855 | int activityNdx = task.mActivities.indexOf(r); |
Wale Ogunwale | 3a256e6 | 2018-12-06 14:41:18 -0800 | [diff] [blame] | 3856 | getDisplay().mDisplayContent.prepareAppTransition( |
lumark | 588a3e8 | 2018-07-20 18:53:54 +0800 | [diff] [blame] | 3857 | TRANSIT_CRASHING_ACTIVITY_CLOSE, false /* alwaysKeepCurrent */); |
Wale Ogunwale | 586a8ee | 2019-06-04 13:44:14 +0000 | [diff] [blame] | 3858 | finishActivityLocked(r, Activity.RESULT_CANCELED, null, reason, false); |
Bryce Lee | af691c0 | 2017-03-20 14:20:22 -0700 | [diff] [blame] | 3859 | finishedTask = task; |
Adrian Roos | 20d7df3 | 2016-01-12 18:59:43 +0100 | [diff] [blame] | 3860 | // Also terminate any activities below it that aren't yet |
| 3861 | // stopped, to avoid a situation where one will get |
| 3862 | // re-start our crashing activity once it gets resumed again. |
| 3863 | --activityNdx; |
| 3864 | if (activityNdx < 0) { |
| 3865 | do { |
| 3866 | --taskNdx; |
| 3867 | if (taskNdx < 0) { |
| 3868 | break; |
| 3869 | } |
| 3870 | activityNdx = mTaskHistory.get(taskNdx).mActivities.size() - 1; |
| 3871 | } while (activityNdx < 0); |
| 3872 | } |
| 3873 | if (activityNdx >= 0) { |
| 3874 | r = mTaskHistory.get(taskNdx).mActivities.get(activityNdx); |
Bryce Lee | 7ace395 | 2018-02-16 14:34:32 -0800 | [diff] [blame] | 3875 | if (r.isState(RESUMED, PAUSING, PAUSED)) { |
Wale Ogunwale | 9e4f3e0 | 2018-05-17 09:35:39 -0700 | [diff] [blame] | 3876 | if (!r.isActivityTypeHome() || mService.mHomeProcess != r.app) { |
Adrian Roos | 20d7df3 | 2016-01-12 18:59:43 +0100 | [diff] [blame] | 3877 | Slog.w(TAG, " Force finishing activity " |
| 3878 | + r.intent.getComponent().flattenToShortString()); |
Wale Ogunwale | 586a8ee | 2019-06-04 13:44:14 +0000 | [diff] [blame] | 3879 | finishActivityLocked(r, Activity.RESULT_CANCELED, null, reason, false); |
Craig Mautner | 05d6272ba | 2013-02-11 09:39:27 -0800 | [diff] [blame] | 3880 | } |
| 3881 | } |
| 3882 | } |
Adrian Roos | 20d7df3 | 2016-01-12 18:59:43 +0100 | [diff] [blame] | 3883 | return finishedTask; |
Craig Mautner | 05d6272ba | 2013-02-11 09:39:27 -0800 | [diff] [blame] | 3884 | } |
| 3885 | |
Dianne Hackborn | 6ea0d0a | 2014-07-02 16:23:21 -0700 | [diff] [blame] | 3886 | final void finishVoiceTask(IVoiceInteractionSession session) { |
| 3887 | IBinder sessionBinder = session.asBinder(); |
| 3888 | boolean didOne = false; |
| 3889 | for (int taskNdx = mTaskHistory.size() - 1; taskNdx >= 0; --taskNdx) { |
| 3890 | TaskRecord tr = mTaskHistory.get(taskNdx); |
| 3891 | if (tr.voiceSession != null && tr.voiceSession.asBinder() == sessionBinder) { |
| 3892 | for (int activityNdx = tr.mActivities.size() - 1; activityNdx >= 0; --activityNdx) { |
| 3893 | ActivityRecord r = tr.mActivities.get(activityNdx); |
| 3894 | if (!r.finishing) { |
Wale Ogunwale | 586a8ee | 2019-06-04 13:44:14 +0000 | [diff] [blame] | 3895 | finishActivityLocked(r, Activity.RESULT_CANCELED, null, "finish-voice", |
| 3896 | false); |
Dianne Hackborn | 6ea0d0a | 2014-07-02 16:23:21 -0700 | [diff] [blame] | 3897 | didOne = true; |
| 3898 | } |
| 3899 | } |
Amith Yamasani | 0af6fa7 | 2016-01-17 15:36:19 -0800 | [diff] [blame] | 3900 | } else { |
| 3901 | // Check if any of the activities are using voice |
| 3902 | for (int activityNdx = tr.mActivities.size() - 1; activityNdx >= 0; --activityNdx) { |
| 3903 | ActivityRecord r = tr.mActivities.get(activityNdx); |
Wale Ogunwale | 9e4f3e0 | 2018-05-17 09:35:39 -0700 | [diff] [blame] | 3904 | if (r.voiceSession != null && r.voiceSession.asBinder() == sessionBinder) { |
Amith Yamasani | 0af6fa7 | 2016-01-17 15:36:19 -0800 | [diff] [blame] | 3905 | // Inform of cancellation |
| 3906 | r.clearVoiceSessionLocked(); |
| 3907 | try { |
Wale Ogunwale | 9e4f3e0 | 2018-05-17 09:35:39 -0700 | [diff] [blame] | 3908 | r.app.getThread().scheduleLocalVoiceInteractionStarted( |
| 3909 | r.appToken, null); |
Amith Yamasani | 0af6fa7 | 2016-01-17 15:36:19 -0800 | [diff] [blame] | 3910 | } catch (RemoteException re) { |
| 3911 | // Ok |
| 3912 | } |
Wale Ogunwale | f673393 | 2018-06-27 05:14:34 -0700 | [diff] [blame] | 3913 | mService.finishRunningVoiceLocked(); |
Amith Yamasani | 0af6fa7 | 2016-01-17 15:36:19 -0800 | [diff] [blame] | 3914 | break; |
| 3915 | } |
| 3916 | } |
Dianne Hackborn | 6ea0d0a | 2014-07-02 16:23:21 -0700 | [diff] [blame] | 3917 | } |
| 3918 | } |
Amith Yamasani | 0af6fa7 | 2016-01-17 15:36:19 -0800 | [diff] [blame] | 3919 | |
Dianne Hackborn | 6ea0d0a | 2014-07-02 16:23:21 -0700 | [diff] [blame] | 3920 | if (didOne) { |
Wale Ogunwale | f673393 | 2018-06-27 05:14:34 -0700 | [diff] [blame] | 3921 | mService.updateOomAdj(); |
Dianne Hackborn | 6ea0d0a | 2014-07-02 16:23:21 -0700 | [diff] [blame] | 3922 | } |
| 3923 | } |
| 3924 | |
Craig Mautner | d232895 | 2013-03-05 12:46:26 -0800 | [diff] [blame] | 3925 | final boolean finishActivityAffinityLocked(ActivityRecord r) { |
Wale Ogunwale | 8b19de9 | 2018-11-29 19:58:26 -0800 | [diff] [blame] | 3926 | ArrayList<ActivityRecord> activities = r.getTaskRecord().mActivities; |
Craig Mautner | d74f7d7 | 2013-02-26 13:41:02 -0800 | [diff] [blame] | 3927 | for (int index = activities.indexOf(r); index >= 0; --index) { |
| 3928 | ActivityRecord cur = activities.get(index); |
Kenny Root | e6585b3 | 2013-12-13 12:00:26 -0800 | [diff] [blame] | 3929 | if (!Objects.equals(cur.taskAffinity, r.taskAffinity)) { |
Dianne Hackborn | ecc5a9c | 2012-04-26 18:56:09 -0700 | [diff] [blame] | 3930 | break; |
| 3931 | } |
Wale Ogunwale | 586a8ee | 2019-06-04 13:44:14 +0000 | [diff] [blame] | 3932 | finishActivityLocked(cur, Activity.RESULT_CANCELED, null, "request-affinity", true); |
Dianne Hackborn | ecc5a9c | 2012-04-26 18:56:09 -0700 | [diff] [blame] | 3933 | } |
| 3934 | return true; |
| 3935 | } |
| 3936 | |
Wale Ogunwale | 586a8ee | 2019-06-04 13:44:14 +0000 | [diff] [blame] | 3937 | private void finishActivityResultsLocked(ActivityRecord r, int resultCode, Intent resultData) { |
Dianne Hackborn | 5c60743 | 2012-02-28 14:44:19 -0800 | [diff] [blame] | 3938 | // send the result |
| 3939 | ActivityRecord resultTo = r.resultTo; |
| 3940 | if (resultTo != null) { |
Wale Ogunwale | ee006da | 2015-03-30 14:49:25 -0700 | [diff] [blame] | 3941 | if (DEBUG_RESULTS) Slog.v(TAG_RESULTS, "Adding result to " + resultTo |
Dianne Hackborn | 5c60743 | 2012-02-28 14:44:19 -0800 | [diff] [blame] | 3942 | + " who=" + r.resultWho + " req=" + r.requestCode |
| 3943 | + " res=" + resultCode + " data=" + resultData); |
Wale Ogunwale | 8b19de9 | 2018-11-29 19:58:26 -0800 | [diff] [blame] | 3944 | if (resultTo.mUserId != r.mUserId) { |
Nicolas Prevot | 6b942b8 | 2014-06-02 15:20:42 +0100 | [diff] [blame] | 3945 | if (resultData != null) { |
Wale Ogunwale | 8b19de9 | 2018-11-29 19:58:26 -0800 | [diff] [blame] | 3946 | resultData.prepareToLeaveUser(r.mUserId); |
Nicolas Prevot | 6b942b8 | 2014-06-02 15:20:42 +0100 | [diff] [blame] | 3947 | } |
Nicolas Prevot | c6cf95c | 2014-05-29 11:30:36 +0100 | [diff] [blame] | 3948 | } |
Dianne Hackborn | 5c60743 | 2012-02-28 14:44:19 -0800 | [diff] [blame] | 3949 | if (r.info.applicationInfo.uid > 0) { |
Wale Ogunwale | 586a8ee | 2019-06-04 13:44:14 +0000 | [diff] [blame] | 3950 | mService.mUgmInternal.grantUriPermissionFromIntent(r.info.applicationInfo.uid, |
| 3951 | resultTo.packageName, resultData, |
| 3952 | resultTo.getUriPermissionsLocked(), resultTo.mUserId); |
Dianne Hackborn | 5c60743 | 2012-02-28 14:44:19 -0800 | [diff] [blame] | 3953 | } |
Wale Ogunwale | 5fa8a8c | 2018-05-08 13:43:21 -0700 | [diff] [blame] | 3954 | resultTo.addResultLocked(r, r.resultWho, r.requestCode, resultCode, resultData); |
Dianne Hackborn | 5c60743 | 2012-02-28 14:44:19 -0800 | [diff] [blame] | 3955 | r.resultTo = null; |
| 3956 | } |
Wale Ogunwale | ee006da | 2015-03-30 14:49:25 -0700 | [diff] [blame] | 3957 | 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] | 3958 | |
| 3959 | // Make sure this HistoryRecord is not holding on to other resources, |
| 3960 | // because clients have remote IPC references to this object so we |
| 3961 | // can't assume that will go away and want to avoid circular IPC refs. |
| 3962 | r.results = null; |
| 3963 | r.pendingResults = null; |
| 3964 | r.newIntents = null; |
| 3965 | r.icicle = null; |
| 3966 | } |
| 3967 | |
Wale Ogunwale | 586a8ee | 2019-06-04 13:44:14 +0000 | [diff] [blame] | 3968 | /** |
| 3969 | * See {@link #finishActivityLocked(ActivityRecord, int, Intent, String, boolean, boolean)} |
| 3970 | */ |
Winson Chung | 6954fc9 | 2017-03-24 16:22:12 -0700 | [diff] [blame] | 3971 | final boolean finishActivityLocked(ActivityRecord r, int resultCode, Intent resultData, |
Wale Ogunwale | 586a8ee | 2019-06-04 13:44:14 +0000 | [diff] [blame] | 3972 | String reason, boolean oomAdj) { |
| 3973 | return finishActivityLocked(r, resultCode, resultData, reason, oomAdj, !PAUSE_IMMEDIATELY); |
Winson Chung | 6954fc9 | 2017-03-24 16:22:12 -0700 | [diff] [blame] | 3974 | } |
| 3975 | |
| 3976 | /** |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 3977 | * @return Returns true if this activity has been removed from the history |
| 3978 | * list, or false if it is still in the list and will be removed later. |
| 3979 | */ |
Craig Mautner | f333327 | 2013-04-22 10:55:53 -0700 | [diff] [blame] | 3980 | final boolean finishActivityLocked(ActivityRecord r, int resultCode, Intent resultData, |
Wale Ogunwale | 586a8ee | 2019-06-04 13:44:14 +0000 | [diff] [blame] | 3981 | String reason, boolean oomAdj, boolean pauseImmediately) { |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 3982 | if (r.finishing) { |
| 3983 | Slog.w(TAG, "Duplicate finish request for " + r); |
| 3984 | return false; |
| 3985 | } |
| 3986 | |
Jorim Jaggi | fe76234 | 2016-10-13 14:33:27 +0200 | [diff] [blame] | 3987 | mWindowManager.deferSurfaceLayout(); |
| 3988 | try { |
| 3989 | r.makeFinishingLocked(); |
Wale Ogunwale | 8b19de9 | 2018-11-29 19:58:26 -0800 | [diff] [blame] | 3990 | final TaskRecord task = r.getTaskRecord(); |
Jorim Jaggi | fe76234 | 2016-10-13 14:33:27 +0200 | [diff] [blame] | 3991 | EventLog.writeEvent(EventLogTags.AM_FINISH_ACTIVITY, |
Wale Ogunwale | 8b19de9 | 2018-11-29 19:58:26 -0800 | [diff] [blame] | 3992 | r.mUserId, System.identityHashCode(r), |
Jorim Jaggi | fe76234 | 2016-10-13 14:33:27 +0200 | [diff] [blame] | 3993 | task.taskId, r.shortComponentName, reason); |
| 3994 | final ArrayList<ActivityRecord> activities = task.mActivities; |
| 3995 | final int index = activities.indexOf(r); |
| 3996 | if (index < (activities.size() - 1)) { |
| 3997 | task.setFrontOfTask(); |
| 3998 | if ((r.intent.getFlags() & Intent.FLAG_ACTIVITY_CLEAR_WHEN_TASK_RESET) != 0) { |
| 3999 | // If the caller asked that this activity (and all above it) |
| 4000 | // be cleared when the task is reset, don't lose that information, |
| 4001 | // but propagate it up to the next activity. |
| 4002 | ActivityRecord next = activities.get(index+1); |
| 4003 | next.intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_WHEN_TASK_RESET); |
| 4004 | } |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 4005 | } |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 4006 | |
Jorim Jaggi | fe76234 | 2016-10-13 14:33:27 +0200 | [diff] [blame] | 4007 | r.pauseKeyDispatchingLocked(); |
Craig Mautner | 04f0b70 | 2013-10-22 12:31:01 -0700 | [diff] [blame] | 4008 | |
Wale Ogunwale | 66e1685 | 2017-10-19 13:35:52 -0700 | [diff] [blame] | 4009 | adjustFocusedActivityStack(r, "finishActivity"); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 4010 | |
Wale Ogunwale | 586a8ee | 2019-06-04 13:44:14 +0000 | [diff] [blame] | 4011 | finishActivityResultsLocked(r, resultCode, resultData); |
Craig Mautner | 2420ead | 2013-04-01 17:13:20 -0700 | [diff] [blame] | 4012 | |
Yorke Lee | bdef537 | 2017-04-10 16:38:51 -0700 | [diff] [blame] | 4013 | final boolean endTask = index <= 0 && !task.isClearingToReuseTask(); |
Jorim Jaggi | fe76234 | 2016-10-13 14:33:27 +0200 | [diff] [blame] | 4014 | final int transit = endTask ? TRANSIT_TASK_CLOSE : TRANSIT_ACTIVITY_CLOSE; |
| 4015 | if (mResumedActivity == r) { |
| 4016 | if (DEBUG_VISIBILITY || DEBUG_TRANSITION) Slog.v(TAG_TRANSITION, |
| 4017 | "Prepare close transition: finishing " + r); |
Winson Chung | 6954fc9 | 2017-03-24 16:22:12 -0700 | [diff] [blame] | 4018 | if (endTask) { |
Wale Ogunwale | 5fa8a8c | 2018-05-08 13:43:21 -0700 | [diff] [blame] | 4019 | mService.getTaskChangeNotificationController().notifyTaskRemovalStarted( |
Mark Renouf | c808f06 | 2019-02-07 15:20:37 -0500 | [diff] [blame] | 4020 | task.getTaskInfo()); |
Winson Chung | 6954fc9 | 2017-03-24 16:22:12 -0700 | [diff] [blame] | 4021 | } |
Wale Ogunwale | 3a256e6 | 2018-12-06 14:41:18 -0800 | [diff] [blame] | 4022 | getDisplay().mDisplayContent.prepareAppTransition(transit, false); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 4023 | |
Jorim Jaggi | fe76234 | 2016-10-13 14:33:27 +0200 | [diff] [blame] | 4024 | // Tell window manager to prepare for this one to be removed. |
Wale Ogunwale | 26c0dfe | 2016-12-14 14:42:30 -0800 | [diff] [blame] | 4025 | r.setVisibility(false); |
Jorim Jaggi | fe76234 | 2016-10-13 14:33:27 +0200 | [diff] [blame] | 4026 | |
| 4027 | if (mPausingActivity == null) { |
| 4028 | if (DEBUG_PAUSE) Slog.v(TAG_PAUSE, "Finish needs to pause: " + r); |
| 4029 | if (DEBUG_USER_LEAVING) Slog.v(TAG_USER_LEAVING, |
| 4030 | "finish() => pause with userLeaving=false"); |
Winson Chung | 6954fc9 | 2017-03-24 16:22:12 -0700 | [diff] [blame] | 4031 | startPausingLocked(false, false, null, pauseImmediately); |
Jorim Jaggi | fe76234 | 2016-10-13 14:33:27 +0200 | [diff] [blame] | 4032 | } |
| 4033 | |
| 4034 | if (endTask) { |
Wale Ogunwale | 5fa8a8c | 2018-05-08 13:43:21 -0700 | [diff] [blame] | 4035 | mService.getLockTaskController().clearLockedTask(task); |
Jorim Jaggi | fe76234 | 2016-10-13 14:33:27 +0200 | [diff] [blame] | 4036 | } |
Bryce Lee | 7ace395 | 2018-02-16 14:34:32 -0800 | [diff] [blame] | 4037 | } else if (!r.isState(PAUSING)) { |
Jorim Jaggi | fe76234 | 2016-10-13 14:33:27 +0200 | [diff] [blame] | 4038 | // If the activity is PAUSING, we will complete the finish once |
| 4039 | // it is done pausing; else we can just directly finish it here. |
| 4040 | if (DEBUG_PAUSE) Slog.v(TAG_PAUSE, "Finish not pausing: " + r); |
| 4041 | if (r.visible) { |
Winson Chung | 6954fc9 | 2017-03-24 16:22:12 -0700 | [diff] [blame] | 4042 | prepareActivityHideTransitionAnimation(r, transit); |
| 4043 | } |
| 4044 | |
| 4045 | final int finishMode = (r.visible || r.nowVisible) ? FINISH_AFTER_VISIBLE |
| 4046 | : FINISH_AFTER_PAUSE; |
Bryce Lee | f52974c | 2018-02-14 15:12:01 -0800 | [diff] [blame] | 4047 | final boolean removedActivity = finishCurrentActivityLocked(r, finishMode, oomAdj, |
| 4048 | "finishActivityLocked") == null; |
Winson Chung | 6954fc9 | 2017-03-24 16:22:12 -0700 | [diff] [blame] | 4049 | |
| 4050 | // The following code is an optimization. When the last non-task overlay activity |
| 4051 | // is removed from the task, we remove the entire task from the stack. However, |
| 4052 | // since that is done after the scheduled destroy callback from the activity, that |
| 4053 | // call to change the visibility of the task overlay activities would be out of |
| 4054 | // sync with the activitiy visibility being set for this finishing activity above. |
| 4055 | // In this case, we can set the visibility of all the task overlay activities when |
| 4056 | // we detect the last one is finishing to keep them in sync. |
| 4057 | if (task.onlyHasTaskOverlayActivities(true /* excludeFinishing */)) { |
| 4058 | for (ActivityRecord taskOverlay : task.mActivities) { |
| 4059 | if (!taskOverlay.mTaskOverlay) { |
| 4060 | continue; |
| 4061 | } |
| 4062 | prepareActivityHideTransitionAnimation(taskOverlay, transit); |
Jorim Jaggi | fe76234 | 2016-10-13 14:33:27 +0200 | [diff] [blame] | 4063 | } |
| 4064 | } |
Winson Chung | 6954fc9 | 2017-03-24 16:22:12 -0700 | [diff] [blame] | 4065 | return removedActivity; |
Jorim Jaggi | fe76234 | 2016-10-13 14:33:27 +0200 | [diff] [blame] | 4066 | } else { |
| 4067 | if (DEBUG_PAUSE) Slog.v(TAG_PAUSE, "Finish waiting for pause of: " + r); |
| 4068 | } |
| 4069 | |
| 4070 | return false; |
| 4071 | } finally { |
| 4072 | mWindowManager.continueSurfaceLayout(); |
| 4073 | } |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 4074 | } |
| 4075 | |
Winson Chung | 6954fc9 | 2017-03-24 16:22:12 -0700 | [diff] [blame] | 4076 | private void prepareActivityHideTransitionAnimation(ActivityRecord r, int transit) { |
Wale Ogunwale | 3a256e6 | 2018-12-06 14:41:18 -0800 | [diff] [blame] | 4077 | final DisplayContent dc = getDisplay().mDisplayContent; |
| 4078 | dc.prepareAppTransition(transit, false); |
Winson Chung | 6954fc9 | 2017-03-24 16:22:12 -0700 | [diff] [blame] | 4079 | r.setVisibility(false); |
Wale Ogunwale | 3a256e6 | 2018-12-06 14:41:18 -0800 | [diff] [blame] | 4080 | dc.executeAppTransition(); |
Winson Chung | 6954fc9 | 2017-03-24 16:22:12 -0700 | [diff] [blame] | 4081 | } |
| 4082 | |
Craig Mautner | f333327 | 2013-04-22 10:55:53 -0700 | [diff] [blame] | 4083 | static final int FINISH_IMMEDIATELY = 0; |
| 4084 | static final int FINISH_AFTER_PAUSE = 1; |
| 4085 | static final int FINISH_AFTER_VISIBLE = 2; |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 4086 | |
Bryce Lee | f52974c | 2018-02-14 15:12:01 -0800 | [diff] [blame] | 4087 | final ActivityRecord finishCurrentActivityLocked(ActivityRecord r, int mode, boolean oomAdj, |
| 4088 | String reason) { |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 4089 | // First things first: if this activity is currently visible, |
| 4090 | // and the resumed activity is not yet visible, then hold off on |
| 4091 | // finishing until the resumed one becomes visible. |
Chong Zhang | 824b6dc | 2016-04-27 14:11:12 -0700 | [diff] [blame] | 4092 | |
Bryce Lee | c961e0a | 2018-04-13 17:58:02 -0700 | [diff] [blame] | 4093 | // The activity that we are finishing may be over the lock screen. In this case, we do not |
| 4094 | // want to consider activities that cannot be shown on the lock screen as running and should |
| 4095 | // proceed with finishing the activity if there is no valid next top running activity. |
lumark | a668116 | 2019-04-12 01:47:54 +0800 | [diff] [blame] | 4096 | // Note that if this finishing activity is floating task, we don't need to wait the |
| 4097 | // next activity resume and can destroy it directly. |
Riddle Hsu | e10cea5 | 2018-10-16 23:33:23 +0800 | [diff] [blame] | 4098 | final ActivityDisplay display = getDisplay(); |
| 4099 | final ActivityRecord next = display.topRunningActivity(true /* considerKeyguardState */); |
lumark | a668116 | 2019-04-12 01:47:54 +0800 | [diff] [blame] | 4100 | final boolean isFloating = r.getConfiguration().windowConfiguration.tasksAreFloating(); |
Chong Zhang | 824b6dc | 2016-04-27 14:11:12 -0700 | [diff] [blame] | 4101 | |
Chong Zhang | efd9a5b | 2016-04-26 16:21:07 -0700 | [diff] [blame] | 4102 | if (mode == FINISH_AFTER_VISIBLE && (r.visible || r.nowVisible) |
lumark | a668116 | 2019-04-12 01:47:54 +0800 | [diff] [blame] | 4103 | && next != null && !next.nowVisible && !isFloating) { |
Craig Mautner | de4ef02 | 2013-04-07 19:01:33 -0700 | [diff] [blame] | 4104 | if (!mStackSupervisor.mStoppingActivities.contains(r)) { |
wilsonshih | 401e50f | 2019-04-30 12:55:48 +0800 | [diff] [blame] | 4105 | addToStopping(r, false /* scheduleIdle */, false /* idleDelayed */, |
| 4106 | "finishCurrentActivityLocked"); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 4107 | } |
Wale Ogunwale | 0fc365c | 2015-05-25 19:35:42 -0700 | [diff] [blame] | 4108 | if (DEBUG_STATES) Slog.v(TAG_STATES, |
| 4109 | "Moving to STOPPING: "+ r + " (finish requested)"); |
Bryce Lee | 7ace395 | 2018-02-16 14:34:32 -0800 | [diff] [blame] | 4110 | r.setState(STOPPING, "finishCurrentActivityLocked"); |
Dianne Hackborn | 2d1b378 | 2012-09-09 17:49:39 -0700 | [diff] [blame] | 4111 | if (oomAdj) { |
Wale Ogunwale | f673393 | 2018-06-27 05:14:34 -0700 | [diff] [blame] | 4112 | mService.updateOomAdj(); |
Dianne Hackborn | 2d1b378 | 2012-09-09 17:49:39 -0700 | [diff] [blame] | 4113 | } |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 4114 | return r; |
| 4115 | } |
| 4116 | |
| 4117 | // make sure the record is cleaned out of other places. |
Craig Mautner | de4ef02 | 2013-04-07 19:01:33 -0700 | [diff] [blame] | 4118 | mStackSupervisor.mStoppingActivities.remove(r); |
Craig Mautner | 0eea92c | 2013-05-16 13:35:39 -0700 | [diff] [blame] | 4119 | mStackSupervisor.mGoingToSleepActivities.remove(r); |
Bryce Lee | 7ace395 | 2018-02-16 14:34:32 -0800 | [diff] [blame] | 4120 | final ActivityState prevState = r.getState(); |
Wale Ogunwale | 0fc365c | 2015-05-25 19:35:42 -0700 | [diff] [blame] | 4121 | if (DEBUG_STATES) Slog.v(TAG_STATES, "Moving to FINISHING: " + r); |
Bryce Lee | b0f993f | 2018-03-02 15:38:01 -0800 | [diff] [blame] | 4122 | |
Bryce Lee | 7ace395 | 2018-02-16 14:34:32 -0800 | [diff] [blame] | 4123 | r.setState(FINISHING, "finishCurrentActivityLocked"); |
wilsonshih | 8824a8a | 2019-03-12 17:21:35 +0800 | [diff] [blame] | 4124 | |
| 4125 | // Don't destroy activity immediately if the display contains home stack, although there is |
| 4126 | // no next activity at the moment but another home activity should be started later. Keep |
| 4127 | // this activity alive until next home activity is resumed then user won't see a temporary |
| 4128 | // black screen. |
| 4129 | final boolean noRunningStack = next == null && display.topRunningActivity() == null |
| 4130 | && display.getHomeStack() == null; |
| 4131 | final boolean noFocusedStack = r.getActivityStack() != display.getFocusedStack(); |
Riddle Hsu | e10cea5 | 2018-10-16 23:33:23 +0800 | [diff] [blame] | 4132 | final boolean finishingInNonFocusedStackOrNoRunning = mode == FINISH_AFTER_VISIBLE |
wilsonshih | 8824a8a | 2019-03-12 17:21:35 +0800 | [diff] [blame] | 4133 | && prevState == PAUSED && (noFocusedStack || noRunningStack); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 4134 | |
| 4135 | if (mode == FINISH_IMMEDIATELY |
Bryce Lee | 7ace395 | 2018-02-16 14:34:32 -0800 | [diff] [blame] | 4136 | || (prevState == PAUSED |
Wale Ogunwale | 44f036f | 2017-09-29 05:09:09 -0700 | [diff] [blame] | 4137 | && (mode == FINISH_AFTER_PAUSE || inPinnedWindowingMode())) |
Riddle Hsu | e10cea5 | 2018-10-16 23:33:23 +0800 | [diff] [blame] | 4138 | || finishingInNonFocusedStackOrNoRunning |
Wale Ogunwale | b9a0c99 | 2017-04-18 07:25:20 -0700 | [diff] [blame] | 4139 | || prevState == STOPPING |
| 4140 | || prevState == STOPPED |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 4141 | || prevState == ActivityState.INITIALIZING) { |
Wale Ogunwale | 7d70117 | 2015-03-11 15:36:30 -0700 | [diff] [blame] | 4142 | r.makeFinishingLocked(); |
Bryce Lee | f52974c | 2018-02-14 15:12:01 -0800 | [diff] [blame] | 4143 | boolean activityRemoved = destroyActivityLocked(r, true, "finish-imm:" + reason); |
Andrii Kulian | 7318d63 | 2016-07-20 18:59:28 -0700 | [diff] [blame] | 4144 | |
Riddle Hsu | e10cea5 | 2018-10-16 23:33:23 +0800 | [diff] [blame] | 4145 | if (finishingInNonFocusedStackOrNoRunning) { |
Andrii Kulian | 995fa2b | 2016-07-29 12:55:41 -0700 | [diff] [blame] | 4146 | // 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] | 4147 | // stack, need to make something visible in its place. Also if the display does not |
| 4148 | // have running activity, the configuration may need to be updated for restoring |
| 4149 | // original orientation of the display. |
Wale Ogunwale | d32da47 | 2018-11-16 07:19:28 -0800 | [diff] [blame] | 4150 | mRootActivityContainer.ensureVisibilityAndConfig(next, mDisplayId, |
Andrii Kulian | f4479ee | 2018-05-23 17:52:48 -0700 | [diff] [blame] | 4151 | false /* markFrozenIfConfigChanged */, true /* deferResume */); |
Andrii Kulian | 7318d63 | 2016-07-20 18:59:28 -0700 | [diff] [blame] | 4152 | } |
Dianne Hackborn | 42e620c | 2012-06-24 13:20:51 -0700 | [diff] [blame] | 4153 | if (activityRemoved) { |
Wale Ogunwale | d32da47 | 2018-11-16 07:19:28 -0800 | [diff] [blame] | 4154 | mRootActivityContainer.resumeFocusedStacksTopActivities(); |
Dianne Hackborn | 42e620c | 2012-06-24 13:20:51 -0700 | [diff] [blame] | 4155 | } |
Wale Ogunwale | 0fc365c | 2015-05-25 19:35:42 -0700 | [diff] [blame] | 4156 | if (DEBUG_CONTAINERS) Slog.d(TAG_CONTAINERS, |
Craig Mautner | d163e75 | 2014-06-13 17:18:47 -0700 | [diff] [blame] | 4157 | "destroyActivityLocked: finishCurrentActivityLocked r=" + r + |
| 4158 | " destroy returned removed=" + activityRemoved); |
Dianne Hackborn | 42e620c | 2012-06-24 13:20:51 -0700 | [diff] [blame] | 4159 | return activityRemoved ? null : r; |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 4160 | } |
Craig Mautner | 05d6272ba | 2013-02-11 09:39:27 -0800 | [diff] [blame] | 4161 | |
| 4162 | // Need to go through the full pause cycle to get this |
| 4163 | // activity into the stopped state and then finish it. |
Wale Ogunwale | e23149f | 2015-03-06 15:39:44 -0800 | [diff] [blame] | 4164 | if (DEBUG_ALL) Slog.v(TAG, "Enqueueing pending finish: " + r); |
Craig Mautner | f333327 | 2013-04-22 10:55:53 -0700 | [diff] [blame] | 4165 | mStackSupervisor.mFinishingActivities.add(r); |
Martin Wallgren | c8733b8 | 2011-08-31 12:39:31 +0200 | [diff] [blame] | 4166 | r.resumeKeyDispatchingLocked(); |
Wale Ogunwale | d32da47 | 2018-11-16 07:19:28 -0800 | [diff] [blame] | 4167 | mRootActivityContainer.resumeFocusedStacksTopActivities(); |
Andrii Kulian | 6b32151 | 2019-01-23 06:37:00 +0000 | [diff] [blame] | 4168 | // If activity was not paused at this point - explicitly pause it to start finishing |
| 4169 | // process. Finishing will be completed once it reports pause back. |
| 4170 | if (r.isState(RESUMED) && mPausingActivity != null) { |
| 4171 | startPausingLocked(false /* userLeaving */, false /* uiSleeping */, next /* resuming */, |
| 4172 | false /* dontWait */); |
| 4173 | } |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 4174 | return r; |
| 4175 | } |
| 4176 | |
Craig Mautner | ee36c77 | 2014-07-16 14:56:05 -0700 | [diff] [blame] | 4177 | void finishAllActivitiesLocked(boolean immediately) { |
| 4178 | boolean noActivitiesInStack = true; |
Craig Mautner | f4c909b | 2014-04-17 18:39:38 -0700 | [diff] [blame] | 4179 | for (int taskNdx = mTaskHistory.size() - 1; taskNdx >= 0; --taskNdx) { |
| 4180 | final ArrayList<ActivityRecord> activities = mTaskHistory.get(taskNdx).mActivities; |
| 4181 | for (int activityNdx = activities.size() - 1; activityNdx >= 0; --activityNdx) { |
| 4182 | final ActivityRecord r = activities.get(activityNdx); |
Craig Mautner | ee36c77 | 2014-07-16 14:56:05 -0700 | [diff] [blame] | 4183 | noActivitiesInStack = false; |
| 4184 | if (r.finishing && !immediately) { |
Craig Mautner | f4c909b | 2014-04-17 18:39:38 -0700 | [diff] [blame] | 4185 | continue; |
| 4186 | } |
Craig Mautner | ee36c77 | 2014-07-16 14:56:05 -0700 | [diff] [blame] | 4187 | Slog.d(TAG, "finishAllActivitiesLocked: finishing " + r + " immediately"); |
Bryce Lee | f52974c | 2018-02-14 15:12:01 -0800 | [diff] [blame] | 4188 | finishCurrentActivityLocked(r, FINISH_IMMEDIATELY, false, |
| 4189 | "finishAllActivitiesLocked"); |
Craig Mautner | f4c909b | 2014-04-17 18:39:38 -0700 | [diff] [blame] | 4190 | } |
| 4191 | } |
Craig Mautner | ee36c77 | 2014-07-16 14:56:05 -0700 | [diff] [blame] | 4192 | if (noActivitiesInStack) { |
Andrii Kulian | 94e82d9b0 | 2017-07-13 15:33:06 -0700 | [diff] [blame] | 4193 | remove(); |
Craig Mautner | ee36c77 | 2014-07-16 14:56:05 -0700 | [diff] [blame] | 4194 | } |
Craig Mautner | f4c909b | 2014-04-17 18:39:38 -0700 | [diff] [blame] | 4195 | } |
| 4196 | |
Wale Ogunwale | 66e1685 | 2017-10-19 13:35:52 -0700 | [diff] [blame] | 4197 | /** @return true if the stack behind this one is a standard activity type. */ |
| 4198 | boolean inFrontOfStandardStack() { |
| 4199 | final ActivityDisplay display = getDisplay(); |
| 4200 | if (display == null) { |
| 4201 | return false; |
| 4202 | } |
| 4203 | final int index = display.getIndexOf(this); |
| 4204 | if (index == 0) { |
| 4205 | return false; |
| 4206 | } |
| 4207 | final ActivityStack stackBehind = display.getChildAt(index - 1); |
| 4208 | return stackBehind.isActivityTypeStandard(); |
| 4209 | } |
| 4210 | |
| 4211 | boolean shouldUpRecreateTaskLocked(ActivityRecord srec, String destAffinity) { |
Dianne Hackborn | 6f4d61f | 2014-08-21 17:50:42 -0700 | [diff] [blame] | 4212 | // Basic case: for simple app-centric recents, we need to recreate |
| 4213 | // the task if the affinity has changed. |
Wale Ogunwale | 8b19de9 | 2018-11-29 19:58:26 -0800 | [diff] [blame] | 4214 | if (srec == null || srec.getTaskRecord().affinity == null || |
| 4215 | !srec.getTaskRecord().affinity.equals(destAffinity)) { |
Dianne Hackborn | 6f4d61f | 2014-08-21 17:50:42 -0700 | [diff] [blame] | 4216 | return true; |
| 4217 | } |
| 4218 | // Document-centric case: an app may be split in to multiple documents; |
| 4219 | // they need to re-create their task if this current activity is the root |
| 4220 | // of a document, unless simply finishing it will return them to the the |
| 4221 | // correct app behind. |
Wale Ogunwale | 8b19de9 | 2018-11-29 19:58:26 -0800 | [diff] [blame] | 4222 | final TaskRecord task = srec.getTaskRecord(); |
Wale Ogunwale | 66e1685 | 2017-10-19 13:35:52 -0700 | [diff] [blame] | 4223 | if (srec.frontOfTask && task.getBaseIntent() != null && task.getBaseIntent().isDocument()) { |
Dianne Hackborn | 6f4d61f | 2014-08-21 17:50:42 -0700 | [diff] [blame] | 4224 | // 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] | 4225 | if (!inFrontOfStandardStack()) { |
Dianne Hackborn | 6f4d61f | 2014-08-21 17:50:42 -0700 | [diff] [blame] | 4226 | // Finishing won't return to an application, so we need to recreate. |
| 4227 | return true; |
| 4228 | } |
| 4229 | // 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] | 4230 | int taskIdx = mTaskHistory.indexOf(task); |
Dianne Hackborn | 6f4d61f | 2014-08-21 17:50:42 -0700 | [diff] [blame] | 4231 | if (taskIdx <= 0) { |
| 4232 | Slog.w(TAG, "shouldUpRecreateTask: task not in history for " + srec); |
| 4233 | return false; |
| 4234 | } |
Wale Ogunwale | 6fbde9f | 2017-08-24 07:24:12 -0700 | [diff] [blame] | 4235 | final TaskRecord prevTask = mTaskHistory.get(taskIdx); |
Bryce Lee | af691c0 | 2017-03-20 14:20:22 -0700 | [diff] [blame] | 4236 | if (!task.affinity.equals(prevTask.affinity)) { |
Dianne Hackborn | 6f4d61f | 2014-08-21 17:50:42 -0700 | [diff] [blame] | 4237 | // These are different apps, so need to recreate. |
| 4238 | return true; |
| 4239 | } |
| 4240 | } |
| 4241 | return false; |
| 4242 | } |
| 4243 | |
Wale Ogunwale | 586a8ee | 2019-06-04 13:44:14 +0000 | [diff] [blame] | 4244 | final boolean navigateUpToLocked(ActivityRecord srec, Intent destIntent, int resultCode, |
| 4245 | Intent resultData) { |
Wale Ogunwale | 8b19de9 | 2018-11-29 19:58:26 -0800 | [diff] [blame] | 4246 | final TaskRecord task = srec.getTaskRecord(); |
Craig Mautner | 0247fc8 | 2013-02-28 14:32:06 -0800 | [diff] [blame] | 4247 | final ArrayList<ActivityRecord> activities = task.mActivities; |
| 4248 | final int start = activities.indexOf(srec); |
| 4249 | if (!mTaskHistory.contains(task) || (start < 0)) { |
Craig Mautner | 05d6272ba | 2013-02-11 09:39:27 -0800 | [diff] [blame] | 4250 | return false; |
| 4251 | } |
| 4252 | int finishTo = start - 1; |
Craig Mautner | 0247fc8 | 2013-02-28 14:32:06 -0800 | [diff] [blame] | 4253 | ActivityRecord parent = finishTo < 0 ? null : activities.get(finishTo); |
Craig Mautner | 05d6272ba | 2013-02-11 09:39:27 -0800 | [diff] [blame] | 4254 | boolean foundParentInTask = false; |
Craig Mautner | 0247fc8 | 2013-02-28 14:32:06 -0800 | [diff] [blame] | 4255 | final ComponentName dest = destIntent.getComponent(); |
| 4256 | if (start > 0 && dest != null) { |
| 4257 | for (int i = finishTo; i >= 0; i--) { |
| 4258 | ActivityRecord r = activities.get(i); |
| 4259 | if (r.info.packageName.equals(dest.getPackageName()) && |
Craig Mautner | 05d6272ba | 2013-02-11 09:39:27 -0800 | [diff] [blame] | 4260 | r.info.name.equals(dest.getClassName())) { |
| 4261 | finishTo = i; |
| 4262 | parent = r; |
| 4263 | foundParentInTask = true; |
| 4264 | break; |
| 4265 | } |
| 4266 | } |
| 4267 | } |
| 4268 | |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 4269 | // TODO: There is a dup. of this block of code in ActivityTaskManagerService.finishActivity |
| 4270 | // We should consolidate. |
| 4271 | IActivityController controller = mService.mController; |
Craig Mautner | 05d6272ba | 2013-02-11 09:39:27 -0800 | [diff] [blame] | 4272 | if (controller != null) { |
| 4273 | ActivityRecord next = topRunningActivityLocked(srec.appToken, 0); |
| 4274 | if (next != null) { |
| 4275 | // ask watcher if this is allowed |
| 4276 | boolean resumeOK = true; |
| 4277 | try { |
| 4278 | resumeOK = controller.activityResuming(next.packageName); |
| 4279 | } catch (RemoteException e) { |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 4280 | mService.mController = null; |
Kenny Root | add5821 | 2013-05-07 09:47:34 -0700 | [diff] [blame] | 4281 | Watchdog.getInstance().setActivityController(null); |
Craig Mautner | 05d6272ba | 2013-02-11 09:39:27 -0800 | [diff] [blame] | 4282 | } |
| 4283 | |
| 4284 | if (!resumeOK) { |
| 4285 | return false; |
| 4286 | } |
| 4287 | } |
| 4288 | } |
| 4289 | final long origId = Binder.clearCallingIdentity(); |
| 4290 | for (int i = start; i > finishTo; i--) { |
Craig Mautner | 0247fc8 | 2013-02-28 14:32:06 -0800 | [diff] [blame] | 4291 | ActivityRecord r = activities.get(i); |
Wale Ogunwale | 586a8ee | 2019-06-04 13:44:14 +0000 | [diff] [blame] | 4292 | requestFinishActivityLocked(r.appToken, resultCode, resultData, "navigate-up", true); |
Craig Mautner | 05d6272ba | 2013-02-11 09:39:27 -0800 | [diff] [blame] | 4293 | // Only return the supplied result for the first activity finished |
| 4294 | resultCode = Activity.RESULT_CANCELED; |
| 4295 | resultData = null; |
| 4296 | } |
| 4297 | |
| 4298 | if (parent != null && foundParentInTask) { |
| 4299 | final int parentLaunchMode = parent.info.launchMode; |
| 4300 | final int destIntentFlags = destIntent.getFlags(); |
| 4301 | if (parentLaunchMode == ActivityInfo.LAUNCH_SINGLE_INSTANCE || |
| 4302 | parentLaunchMode == ActivityInfo.LAUNCH_SINGLE_TASK || |
| 4303 | parentLaunchMode == ActivityInfo.LAUNCH_SINGLE_TOP || |
| 4304 | (destIntentFlags & Intent.FLAG_ACTIVITY_CLEAR_TOP) != 0) { |
Dianne Hackborn | 85d558c | 2014-11-04 10:31:54 -0800 | [diff] [blame] | 4305 | parent.deliverNewIntentLocked(srec.info.applicationInfo.uid, destIntent, |
Wale Ogunwale | 586a8ee | 2019-06-04 13:44:14 +0000 | [diff] [blame] | 4306 | srec.packageName); |
Craig Mautner | 05d6272ba | 2013-02-11 09:39:27 -0800 | [diff] [blame] | 4307 | } else { |
| 4308 | try { |
| 4309 | ActivityInfo aInfo = AppGlobals.getPackageManager().getActivityInfo( |
Philip P. Moltmann | cff8f0f | 2018-03-27 12:51:51 -0700 | [diff] [blame] | 4310 | destIntent.getComponent(), ActivityManagerService.STOCK_PM_FLAGS, |
Wale Ogunwale | 8b19de9 | 2018-11-29 19:58:26 -0800 | [diff] [blame] | 4311 | srec.mUserId); |
Bryce Lee | 4c9a597 | 2017-12-01 22:14:24 -0800 | [diff] [blame] | 4312 | // TODO(b/64750076): Check if calling pid should really be -1. |
| 4313 | final int res = mService.getActivityStartController() |
| 4314 | .obtainStarter(destIntent, "navigateUpTo") |
Wale Ogunwale | 9e4f3e0 | 2018-05-17 09:35:39 -0700 | [diff] [blame] | 4315 | .setCaller(srec.app.getThread()) |
Bryce Lee | 4c9a597 | 2017-12-01 22:14:24 -0800 | [diff] [blame] | 4316 | .setActivityInfo(aInfo) |
| 4317 | .setResultTo(parent.appToken) |
| 4318 | .setCallingPid(-1) |
| 4319 | .setCallingUid(parent.launchedFromUid) |
| 4320 | .setCallingPackage(parent.launchedFromPackage) |
| 4321 | .setRealCallingPid(-1) |
| 4322 | .setRealCallingUid(parent.launchedFromUid) |
| 4323 | .setComponentSpecified(true) |
| 4324 | .execute(); |
Craig Mautner | 05d6272ba | 2013-02-11 09:39:27 -0800 | [diff] [blame] | 4325 | foundParentInTask = res == ActivityManager.START_SUCCESS; |
| 4326 | } catch (RemoteException e) { |
| 4327 | foundParentInTask = false; |
| 4328 | } |
| 4329 | requestFinishActivityLocked(parent.appToken, resultCode, |
Wale Ogunwale | 586a8ee | 2019-06-04 13:44:14 +0000 | [diff] [blame] | 4330 | resultData, "navigate-top", true); |
Craig Mautner | 05d6272ba | 2013-02-11 09:39:27 -0800 | [diff] [blame] | 4331 | } |
| 4332 | } |
| 4333 | Binder.restoreCallingIdentity(origId); |
| 4334 | return foundParentInTask; |
| 4335 | } |
Bryce Lee | af691c0 | 2017-03-20 14:20:22 -0700 | [diff] [blame] | 4336 | |
| 4337 | /** |
| 4338 | * Remove any state associated with the {@link ActivityRecord}. This should be called whenever |
| 4339 | * an activity moves away from the stack. |
| 4340 | */ |
| 4341 | void onActivityRemovedFromStack(ActivityRecord r) { |
Bryce Lee | 84730a0 | 2018-04-03 14:10:04 -0700 | [diff] [blame] | 4342 | removeTimeoutsForActivityLocked(r); |
| 4343 | |
| 4344 | if (mResumedActivity != null && mResumedActivity == r) { |
| 4345 | setResumedActivity(null, "onActivityRemovedFromStack"); |
Bryce Lee | af691c0 | 2017-03-20 14:20:22 -0700 | [diff] [blame] | 4346 | } |
Bryce Lee | 84730a0 | 2018-04-03 14:10:04 -0700 | [diff] [blame] | 4347 | if (mPausingActivity != null && mPausingActivity == r) { |
Bryce Lee | af691c0 | 2017-03-20 14:20:22 -0700 | [diff] [blame] | 4348 | mPausingActivity = null; |
| 4349 | } |
Bryce Lee | 84730a0 | 2018-04-03 14:10:04 -0700 | [diff] [blame] | 4350 | } |
Bryce Lee | af691c0 | 2017-03-20 14:20:22 -0700 | [diff] [blame] | 4351 | |
Bryce Lee | 84730a0 | 2018-04-03 14:10:04 -0700 | [diff] [blame] | 4352 | void onActivityAddedToStack(ActivityRecord r) { |
| 4353 | if(r.getState() == RESUMED) { |
| 4354 | setResumedActivity(r, "onActivityAddedToStack"); |
| 4355 | } |
Bryce Lee | af691c0 | 2017-03-20 14:20:22 -0700 | [diff] [blame] | 4356 | } |
| 4357 | |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 4358 | /** |
| 4359 | * Perform the common clean-up of an activity record. This is called both |
| 4360 | * as part of destroyActivityLocked() (when destroying the client-side |
| 4361 | * representation) and cleaning things up as a result of its hosting |
| 4362 | * processing going away, in which case there is no remaining client-side |
| 4363 | * state to destroy so only the cleanup here is needed. |
Craig Mautner | acebdc8 | 2015-02-24 10:53:03 -0800 | [diff] [blame] | 4364 | * |
| 4365 | * Note: Call before #removeActivityFromHistoryLocked. |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 4366 | */ |
Bryce Lee | c940660 | 2018-03-09 11:02:10 -0800 | [diff] [blame] | 4367 | private void cleanUpActivityLocked(ActivityRecord r, boolean cleanServices, boolean setState) { |
Bryce Lee | af691c0 | 2017-03-20 14:20:22 -0700 | [diff] [blame] | 4368 | onActivityRemovedFromStack(r); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 4369 | |
Wale Ogunwale | f81c1d1 | 2016-01-12 12:20:18 -0800 | [diff] [blame] | 4370 | r.deferRelaunchUntilPaused = false; |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 4371 | r.frozenBeforeDestroy = false; |
| 4372 | |
Bryce Lee | c940660 | 2018-03-09 11:02:10 -0800 | [diff] [blame] | 4373 | if (setState) { |
Wale Ogunwale | 0fc365c | 2015-05-25 19:35:42 -0700 | [diff] [blame] | 4374 | 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] | 4375 | r.setState(DESTROYED, "cleanupActivityLocked"); |
Wale Ogunwale | 0fc365c | 2015-05-25 19:35:42 -0700 | [diff] [blame] | 4376 | 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] | 4377 | r.app = null; |
Dianne Hackborn | ce86ba8 | 2011-07-13 19:33:41 -0700 | [diff] [blame] | 4378 | } |
| 4379 | |
Bryce Lee | 4a19438 | 2017-04-04 14:32:48 -0700 | [diff] [blame] | 4380 | // Inform supervisor the activity has been removed. |
| 4381 | mStackSupervisor.cleanupActivity(r); |
| 4382 | |
Craig Mautner | 2420ead | 2013-04-01 17:13:20 -0700 | [diff] [blame] | 4383 | |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 4384 | // Remove any pending results. |
| 4385 | if (r.finishing && r.pendingResults != null) { |
| 4386 | for (WeakReference<PendingIntentRecord> apr : r.pendingResults) { |
| 4387 | PendingIntentRecord rec = apr.get(); |
| 4388 | if (rec != null) { |
Wale Ogunwale | ee6eca1 | 2018-09-19 20:37:53 -0700 | [diff] [blame] | 4389 | mService.mPendingIntentController.cancelIntentSender(rec, false); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 4390 | } |
| 4391 | } |
| 4392 | r.pendingResults = null; |
| 4393 | } |
| 4394 | |
| 4395 | if (cleanServices) { |
Craig Mautner | 2420ead | 2013-04-01 17:13:20 -0700 | [diff] [blame] | 4396 | cleanUpActivityServicesLocked(r); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 4397 | } |
| 4398 | |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 4399 | // Get rid of any pending idle timeouts. |
Dianne Hackborn | 42e620c | 2012-06-24 13:20:51 -0700 | [diff] [blame] | 4400 | removeTimeoutsForActivityLocked(r); |
Wale Ogunwale | 8fd7542 | 2016-06-24 14:20:37 -0700 | [diff] [blame] | 4401 | // Clean-up activities are no longer relaunching (e.g. app process died). Notify window |
| 4402 | // manager so it can update its bookkeeping. |
| 4403 | mWindowManager.notifyAppRelaunchesCleared(r.appToken); |
Dianne Hackborn | 42e620c | 2012-06-24 13:20:51 -0700 | [diff] [blame] | 4404 | } |
| 4405 | |
Wale Ogunwale | 5378374 | 2018-09-16 10:21:51 -0700 | [diff] [blame] | 4406 | private void removeTimeoutsForActivityLocked(ActivityRecord r) { |
Craig Mautner | f333327 | 2013-04-22 10:55:53 -0700 | [diff] [blame] | 4407 | mStackSupervisor.removeTimeoutsForActivityLocked(r); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 4408 | mHandler.removeMessages(PAUSE_TIMEOUT_MSG, r); |
Dianne Hackborn | 162bc0e | 2012-04-09 14:06:16 -0700 | [diff] [blame] | 4409 | mHandler.removeMessages(STOP_TIMEOUT_MSG, r); |
Dianne Hackborn | 0c5001d | 2011-04-12 18:16:08 -0700 | [diff] [blame] | 4410 | mHandler.removeMessages(DESTROY_TIMEOUT_MSG, r); |
Dianne Hackborn | 2a29b3a | 2012-03-15 15:48:38 -0700 | [diff] [blame] | 4411 | r.finishLaunchTickingLocked(); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 4412 | } |
| 4413 | |
Chong Zhang | bffd889 | 2016-08-08 11:16:06 -0700 | [diff] [blame] | 4414 | private void removeActivityFromHistoryLocked(ActivityRecord r, String reason) { |
Wale Ogunwale | 586a8ee | 2019-06-04 13:44:14 +0000 | [diff] [blame] | 4415 | finishActivityResultsLocked(r, Activity.RESULT_CANCELED, null); |
Wale Ogunwale | 7d70117 | 2015-03-11 15:36:30 -0700 | [diff] [blame] | 4416 | r.makeFinishingLocked(); |
Wale Ogunwale | 0fc365c | 2015-05-25 19:35:42 -0700 | [diff] [blame] | 4417 | if (DEBUG_ADD_REMOVE) Slog.i(TAG_ADD_REMOVE, |
| 4418 | "Removing activity " + r + " from stack callers=" + Debug.getCallers(5)); |
| 4419 | |
Dianne Hackborn | cc5a055 | 2012-10-01 16:32:39 -0700 | [diff] [blame] | 4420 | r.takeFromHistory(); |
| 4421 | removeTimeoutsForActivityLocked(r); |
Wale Ogunwale | 0fc365c | 2015-05-25 19:35:42 -0700 | [diff] [blame] | 4422 | if (DEBUG_STATES) Slog.v(TAG_STATES, |
| 4423 | "Moving to DESTROYED: " + r + " (removed from history)"); |
Bryce Lee | 7ace395 | 2018-02-16 14:34:32 -0800 | [diff] [blame] | 4424 | r.setState(DESTROYED, "removeActivityFromHistoryLocked"); |
Wale Ogunwale | 0fc365c | 2015-05-25 19:35:42 -0700 | [diff] [blame] | 4425 | 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] | 4426 | r.app = null; |
Wale Ogunwale | 26c0dfe | 2016-12-14 14:42:30 -0800 | [diff] [blame] | 4427 | r.removeWindowContainer(); |
Wale Ogunwale | 8b19de9 | 2018-11-29 19:58:26 -0800 | [diff] [blame] | 4428 | final TaskRecord task = r.getTaskRecord(); |
Bryce Lee | aa5e8c3 | 2017-03-01 16:01:06 -0800 | [diff] [blame] | 4429 | final boolean lastActivity = task != null ? task.removeActivity(r) : false; |
Winson Chung | 6954fc9 | 2017-03-24 16:22:12 -0700 | [diff] [blame] | 4430 | // If we are removing the last activity in the task, not including task overlay activities, |
| 4431 | // then fall through into the block below to remove the entire task itself |
| 4432 | final boolean onlyHasTaskOverlays = task != null |
| 4433 | ? task.onlyHasTaskOverlayActivities(false /* excludingFinishing */) : false; |
Bryce Lee | aa5e8c3 | 2017-03-01 16:01:06 -0800 | [diff] [blame] | 4434 | |
Winson Chung | 6954fc9 | 2017-03-24 16:22:12 -0700 | [diff] [blame] | 4435 | if (lastActivity || onlyHasTaskOverlays) { |
| 4436 | if (DEBUG_STACK) { |
| 4437 | Slog.i(TAG_STACK, |
| 4438 | "removeActivityFromHistoryLocked: last activity removed from " + this |
| 4439 | + " onlyHasTaskOverlays=" + onlyHasTaskOverlays); |
| 4440 | } |
| 4441 | |
Bryce Lee | d6d2675 | 2017-05-25 13:57:46 -0700 | [diff] [blame] | 4442 | // The following block can be executed multiple times if there is more than one overlay. |
| 4443 | // {@link ActivityStackSupervisor#removeTaskByIdLocked} handles this by reverse lookup |
| 4444 | // of the task by id and exiting early if not found. |
Winson Chung | e3c21e0 | 2017-04-11 18:02:17 -0700 | [diff] [blame] | 4445 | if (onlyHasTaskOverlays) { |
| 4446 | // When destroying a task, tell the supervisor to remove it so that any activity it |
| 4447 | // has can be cleaned up correctly. This is currently the only place where we remove |
| 4448 | // a task with the DESTROYING mode, so instead of passing the onlyHasTaskOverlays |
| 4449 | // state into removeTask(), we just clear the task here before the other residual |
| 4450 | // work. |
| 4451 | // TODO: If the callers to removeTask() changes such that we have multiple places |
| 4452 | // where we are destroying the task, move this back into removeTask() |
| 4453 | mStackSupervisor.removeTaskByIdLocked(task.taskId, false /* killProcess */, |
Winson Chung | 0ec2a35 | 2017-10-26 11:38:30 -0700 | [diff] [blame] | 4454 | !REMOVE_FROM_RECENTS, PAUSE_IMMEDIATELY, reason); |
Winson Chung | e3c21e0 | 2017-04-11 18:02:17 -0700 | [diff] [blame] | 4455 | } |
Bryce Lee | 1d93058 | 2017-05-01 08:35:24 -0700 | [diff] [blame] | 4456 | |
Bryce Lee | d6d2675 | 2017-05-25 13:57:46 -0700 | [diff] [blame] | 4457 | // We must keep the task around until all activities are destroyed. The following |
| 4458 | // statement will only execute once since overlays are also considered activities. |
Bryce Lee | 1d93058 | 2017-05-01 08:35:24 -0700 | [diff] [blame] | 4459 | if (lastActivity) { |
| 4460 | removeTask(task, reason, REMOVE_TASK_MODE_DESTROYING); |
| 4461 | } |
Craig Mautner | 312ba86 | 2014-02-10 17:55:01 -0800 | [diff] [blame] | 4462 | } |
Dianne Hackborn | cc5a055 | 2012-10-01 16:32:39 -0700 | [diff] [blame] | 4463 | cleanUpActivityServicesLocked(r); |
| 4464 | r.removeUriPermissionsLocked(); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 4465 | } |
Craig Mautner | dbcb31f | 2013-04-02 12:32:53 -0700 | [diff] [blame] | 4466 | |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 4467 | /** |
| 4468 | * Perform clean-up of service connections in an activity record. |
| 4469 | */ |
Andrii Kulian | 21713ac | 2016-10-12 22:05:05 -0700 | [diff] [blame] | 4470 | private void cleanUpActivityServicesLocked(ActivityRecord r) { |
Wale Ogunwale | c4e63a4 | 2018-10-02 13:19:54 -0700 | [diff] [blame] | 4471 | if (r.mServiceConnectionsHolder == null) { |
| 4472 | return; |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 4473 | } |
Wale Ogunwale | c4e63a4 | 2018-10-02 13:19:54 -0700 | [diff] [blame] | 4474 | // Throw away any services that have been bound by this activity. |
| 4475 | r.mServiceConnectionsHolder.disconnectActivityFromServices(); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 4476 | } |
Dianne Hackborn | 755c8bf | 2012-05-07 15:06:09 -0700 | [diff] [blame] | 4477 | |
Wale Ogunwale | 9e4f3e0 | 2018-05-17 09:35:39 -0700 | [diff] [blame] | 4478 | final void scheduleDestroyActivities(WindowProcessController owner, String reason) { |
Dianne Hackborn | 755c8bf | 2012-05-07 15:06:09 -0700 | [diff] [blame] | 4479 | Message msg = mHandler.obtainMessage(DESTROY_ACTIVITIES_MSG); |
Craig Mautner | ee2e45a | 2014-06-27 12:10:03 -0700 | [diff] [blame] | 4480 | msg.obj = new ScheduleDestroyArgs(owner, reason); |
Dianne Hackborn | 755c8bf | 2012-05-07 15:06:09 -0700 | [diff] [blame] | 4481 | mHandler.sendMessage(msg); |
| 4482 | } |
| 4483 | |
Wale Ogunwale | 9e4f3e0 | 2018-05-17 09:35:39 -0700 | [diff] [blame] | 4484 | private void destroyActivitiesLocked(WindowProcessController owner, String reason) { |
Dianne Hackborn | 755c8bf | 2012-05-07 15:06:09 -0700 | [diff] [blame] | 4485 | boolean lastIsOpaque = false; |
Dianne Hackborn | 42e620c | 2012-06-24 13:20:51 -0700 | [diff] [blame] | 4486 | boolean activityRemoved = false; |
Craig Mautner | d44711d | 2013-02-23 11:24:36 -0800 | [diff] [blame] | 4487 | for (int taskNdx = mTaskHistory.size() - 1; taskNdx >= 0; --taskNdx) { |
| 4488 | final ArrayList<ActivityRecord> activities = mTaskHistory.get(taskNdx).mActivities; |
| 4489 | for (int activityNdx = activities.size() - 1; activityNdx >= 0; --activityNdx) { |
| 4490 | final ActivityRecord r = activities.get(activityNdx); |
| 4491 | if (r.finishing) { |
| 4492 | continue; |
| 4493 | } |
| 4494 | if (r.fullscreen) { |
| 4495 | lastIsOpaque = true; |
| 4496 | } |
| 4497 | if (owner != null && r.app != owner) { |
| 4498 | continue; |
| 4499 | } |
| 4500 | if (!lastIsOpaque) { |
| 4501 | continue; |
| 4502 | } |
Dianne Hackborn | 89ad456 | 2014-08-24 16:45:38 -0700 | [diff] [blame] | 4503 | if (r.isDestroyable()) { |
Bryce Lee | 7ace395 | 2018-02-16 14:34:32 -0800 | [diff] [blame] | 4504 | if (DEBUG_SWITCH) Slog.v(TAG_SWITCH, "Destroying " + r |
| 4505 | + " in state " + r.getState() |
Craig Mautner | d44711d | 2013-02-23 11:24:36 -0800 | [diff] [blame] | 4506 | + " resumed=" + mResumedActivity |
Dianne Hackborn | 89ad456 | 2014-08-24 16:45:38 -0700 | [diff] [blame] | 4507 | + " pausing=" + mPausingActivity + " for reason " + reason); |
Craig Mautner | ee2e45a | 2014-06-27 12:10:03 -0700 | [diff] [blame] | 4508 | if (destroyActivityLocked(r, true, reason)) { |
Craig Mautner | d44711d | 2013-02-23 11:24:36 -0800 | [diff] [blame] | 4509 | activityRemoved = true; |
| 4510 | } |
Dianne Hackborn | 42e620c | 2012-06-24 13:20:51 -0700 | [diff] [blame] | 4511 | } |
Dianne Hackborn | ce86ba8 | 2011-07-13 19:33:41 -0700 | [diff] [blame] | 4512 | } |
| 4513 | } |
Dianne Hackborn | 42e620c | 2012-06-24 13:20:51 -0700 | [diff] [blame] | 4514 | if (activityRemoved) { |
Wale Ogunwale | d32da47 | 2018-11-16 07:19:28 -0800 | [diff] [blame] | 4515 | mRootActivityContainer.resumeFocusedStacksTopActivities(); |
Dianne Hackborn | 42e620c | 2012-06-24 13:20:51 -0700 | [diff] [blame] | 4516 | } |
Dianne Hackborn | ce86ba8 | 2011-07-13 19:33:41 -0700 | [diff] [blame] | 4517 | } |
| 4518 | |
Dianne Hackborn | 89ad456 | 2014-08-24 16:45:38 -0700 | [diff] [blame] | 4519 | final boolean safelyDestroyActivityLocked(ActivityRecord r, String reason) { |
| 4520 | if (r.isDestroyable()) { |
Wale Ogunwale | ee006da | 2015-03-30 14:49:25 -0700 | [diff] [blame] | 4521 | if (DEBUG_SWITCH) Slog.v(TAG_SWITCH, |
Bryce Lee | 7ace395 | 2018-02-16 14:34:32 -0800 | [diff] [blame] | 4522 | "Destroying " + r + " in state " + r.getState() + " resumed=" + mResumedActivity |
Dianne Hackborn | 89ad456 | 2014-08-24 16:45:38 -0700 | [diff] [blame] | 4523 | + " pausing=" + mPausingActivity + " for reason " + reason); |
| 4524 | return destroyActivityLocked(r, true, reason); |
| 4525 | } |
| 4526 | return false; |
| 4527 | } |
| 4528 | |
Wale Ogunwale | 9e4f3e0 | 2018-05-17 09:35:39 -0700 | [diff] [blame] | 4529 | final int releaseSomeActivitiesLocked(WindowProcessController app, ArraySet<TaskRecord> tasks, |
Dianne Hackborn | 89ad456 | 2014-08-24 16:45:38 -0700 | [diff] [blame] | 4530 | String reason) { |
| 4531 | // Iterate over tasks starting at the back (oldest) first. |
Wale Ogunwale | 0fc365c | 2015-05-25 19:35:42 -0700 | [diff] [blame] | 4532 | 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] | 4533 | int maxTasks = tasks.size() / 4; |
| 4534 | if (maxTasks < 1) { |
| 4535 | maxTasks = 1; |
| 4536 | } |
| 4537 | int numReleased = 0; |
| 4538 | for (int taskNdx = 0; taskNdx < mTaskHistory.size() && maxTasks > 0; taskNdx++) { |
| 4539 | final TaskRecord task = mTaskHistory.get(taskNdx); |
| 4540 | if (!tasks.contains(task)) { |
| 4541 | continue; |
| 4542 | } |
Wale Ogunwale | 0fc365c | 2015-05-25 19:35:42 -0700 | [diff] [blame] | 4543 | 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] | 4544 | int curNum = 0; |
| 4545 | final ArrayList<ActivityRecord> activities = task.mActivities; |
| 4546 | for (int actNdx = 0; actNdx < activities.size(); actNdx++) { |
| 4547 | final ActivityRecord activity = activities.get(actNdx); |
| 4548 | if (activity.app == app && activity.isDestroyable()) { |
Wale Ogunwale | 0fc365c | 2015-05-25 19:35:42 -0700 | [diff] [blame] | 4549 | if (DEBUG_RELEASE) Slog.v(TAG_RELEASE, "Destroying " + activity |
Bryce Lee | 7ace395 | 2018-02-16 14:34:32 -0800 | [diff] [blame] | 4550 | + " in state " + activity.getState() + " resumed=" + mResumedActivity |
Dianne Hackborn | 89ad456 | 2014-08-24 16:45:38 -0700 | [diff] [blame] | 4551 | + " pausing=" + mPausingActivity + " for reason " + reason); |
| 4552 | destroyActivityLocked(activity, true, reason); |
| 4553 | if (activities.get(actNdx) != activity) { |
| 4554 | // Was removed from list, back up so we don't miss the next one. |
| 4555 | actNdx--; |
| 4556 | } |
| 4557 | curNum++; |
| 4558 | } |
| 4559 | } |
| 4560 | if (curNum > 0) { |
| 4561 | numReleased += curNum; |
| 4562 | maxTasks--; |
| 4563 | if (mTaskHistory.get(taskNdx) != task) { |
| 4564 | // The entire task got removed, back up so we don't miss the next one. |
| 4565 | taskNdx--; |
| 4566 | } |
| 4567 | } |
| 4568 | } |
Wale Ogunwale | 0fc365c | 2015-05-25 19:35:42 -0700 | [diff] [blame] | 4569 | if (DEBUG_RELEASE) Slog.d(TAG_RELEASE, |
| 4570 | "Done releasing: did " + numReleased + " activities"); |
Dianne Hackborn | 89ad456 | 2014-08-24 16:45:38 -0700 | [diff] [blame] | 4571 | return numReleased; |
| 4572 | } |
| 4573 | |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 4574 | /** |
| 4575 | * Destroy the current CLIENT SIDE instance of an activity. This may be |
| 4576 | * called both when actually finishing an activity, or when performing |
| 4577 | * a configuration switch where we destroy the current client-side object |
| 4578 | * but then create a new client-side object for this same HistoryRecord. |
| 4579 | */ |
Craig Mautner | ee2e45a | 2014-06-27 12:10:03 -0700 | [diff] [blame] | 4580 | final boolean destroyActivityLocked(ActivityRecord r, boolean removeFromApp, String reason) { |
Wale Ogunwale | ee006da | 2015-03-30 14:49:25 -0700 | [diff] [blame] | 4581 | if (DEBUG_SWITCH || DEBUG_CLEANUP) Slog.v(TAG_SWITCH, |
| 4582 | "Removing activity from " + reason + ": token=" + r |
Wale Ogunwale | 9e4f3e0 | 2018-05-17 09:35:39 -0700 | [diff] [blame] | 4583 | + ", app=" + (r.hasProcess() ? r.app.mName : "(null)")); |
Bryce Lee | b0f993f | 2018-03-02 15:38:01 -0800 | [diff] [blame] | 4584 | |
| 4585 | if (r.isState(DESTROYING, DESTROYED)) { |
Bryce Lee | c940660 | 2018-03-09 11:02:10 -0800 | [diff] [blame] | 4586 | if (DEBUG_STATES) Slog.v(TAG_STATES, "activity " + r + " already destroying." |
Bryce Lee | b0f993f | 2018-03-02 15:38:01 -0800 | [diff] [blame] | 4587 | + "skipping request with reason:" + reason); |
| 4588 | return false; |
| 4589 | } |
| 4590 | |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 4591 | EventLog.writeEvent(EventLogTags.AM_DESTROY_ACTIVITY, |
Wale Ogunwale | 8b19de9 | 2018-11-29 19:58:26 -0800 | [diff] [blame] | 4592 | r.mUserId, System.identityHashCode(r), |
| 4593 | r.getTaskRecord().taskId, r.shortComponentName, reason); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 4594 | |
| 4595 | boolean removedFromHistory = false; |
Dianne Hackborn | cc5a055 | 2012-10-01 16:32:39 -0700 | [diff] [blame] | 4596 | |
Bryce Lee | c940660 | 2018-03-09 11:02:10 -0800 | [diff] [blame] | 4597 | cleanUpActivityLocked(r, false, false); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 4598 | |
Wale Ogunwale | 9e4f3e0 | 2018-05-17 09:35:39 -0700 | [diff] [blame] | 4599 | final boolean hadApp = r.hasProcess(); |
Dianne Hackborn | cc5a055 | 2012-10-01 16:32:39 -0700 | [diff] [blame] | 4600 | |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 4601 | if (hadApp) { |
| 4602 | if (removeFromApp) { |
Wale Ogunwale | 9e4f3e0 | 2018-05-17 09:35:39 -0700 | [diff] [blame] | 4603 | r.app.removeActivity(r); |
Wale Ogunwale | 5378374 | 2018-09-16 10:21:51 -0700 | [diff] [blame] | 4604 | if (!r.app.hasActivities()) { |
| 4605 | mService.clearHeavyWeightProcessIfEquals(r.app); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 4606 | } |
Wale Ogunwale | 9e4f3e0 | 2018-05-17 09:35:39 -0700 | [diff] [blame] | 4607 | if (!r.app.hasActivities()) { |
Dianne Hackborn | 465fa39 | 2014-09-14 14:21:18 -0700 | [diff] [blame] | 4608 | // Update any services we are bound to that might care about whether |
| 4609 | // their client may have activities. |
Dianne Hackborn | 3bc8f78d | 2013-09-19 13:34:35 -0700 | [diff] [blame] | 4610 | // No longer have activities, so update LRU list and oom adj. |
Riddle Hsu | 17e3842 | 2019-04-12 16:55:11 +0800 | [diff] [blame] | 4611 | r.app.updateProcessInfo(true /* updateServiceConnectionActivities */, |
| 4612 | false /* activityChange */, true /* updateOomAdj */); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 4613 | } |
| 4614 | } |
| 4615 | |
| 4616 | boolean skipDestroy = false; |
Craig Mautner | dbcb31f | 2013-04-02 12:32:53 -0700 | [diff] [blame] | 4617 | |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 4618 | try { |
Wale Ogunwale | ee006da | 2015-03-30 14:49:25 -0700 | [diff] [blame] | 4619 | if (DEBUG_SWITCH) Slog.i(TAG_SWITCH, "Destroying: " + r); |
Wale Ogunwale | 9e4f3e0 | 2018-05-17 09:35:39 -0700 | [diff] [blame] | 4620 | mService.getLifecycleManager().scheduleTransaction(r.app.getThread(), r.appToken, |
Bryce Lee | 1d0d514 | 2018-04-12 10:35:07 -0700 | [diff] [blame] | 4621 | DestroyActivityItem.obtain(r.finishing, r.configChangeFlags)); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 4622 | } catch (Exception e) { |
| 4623 | // We can just ignore exceptions here... if the process |
| 4624 | // has crashed, our death notification will clean things |
| 4625 | // up. |
| 4626 | //Slog.w(TAG, "Exception thrown during finish", e); |
| 4627 | if (r.finishing) { |
Chong Zhang | bffd889 | 2016-08-08 11:16:06 -0700 | [diff] [blame] | 4628 | removeActivityFromHistoryLocked(r, reason + " exceptionInScheduleDestroy"); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 4629 | removedFromHistory = true; |
| 4630 | skipDestroy = true; |
| 4631 | } |
| 4632 | } |
| 4633 | |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 4634 | r.nowVisible = false; |
Craig Mautner | dbcb31f | 2013-04-02 12:32:53 -0700 | [diff] [blame] | 4635 | |
Dianne Hackborn | ce86ba8 | 2011-07-13 19:33:41 -0700 | [diff] [blame] | 4636 | // If the activity is finishing, we need to wait on removing it |
| 4637 | // from the list to give it a chance to do its cleanup. During |
| 4638 | // that time it may make calls back with its token so we need to |
| 4639 | // be able to find it on the list and so we don't want to remove |
| 4640 | // it from the list yet. Otherwise, we can just immediately put |
| 4641 | // it in the destroyed state since we are not removing it from the |
| 4642 | // list. |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 4643 | if (r.finishing && !skipDestroy) { |
Wale Ogunwale | 0fc365c | 2015-05-25 19:35:42 -0700 | [diff] [blame] | 4644 | if (DEBUG_STATES) Slog.v(TAG_STATES, "Moving to DESTROYING: " + r |
Dianne Hackborn | ce86ba8 | 2011-07-13 19:33:41 -0700 | [diff] [blame] | 4645 | + " (destroy requested)"); |
Bryce Lee | 7ace395 | 2018-02-16 14:34:32 -0800 | [diff] [blame] | 4646 | r.setState(DESTROYING, |
| 4647 | "destroyActivityLocked. finishing and not skipping destroy"); |
Craig Mautner | f7bfefb | 2013-05-16 17:30:44 -0700 | [diff] [blame] | 4648 | Message msg = mHandler.obtainMessage(DESTROY_TIMEOUT_MSG, r); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 4649 | mHandler.sendMessageDelayed(msg, DESTROY_TIMEOUT); |
| 4650 | } else { |
Wale Ogunwale | 0fc365c | 2015-05-25 19:35:42 -0700 | [diff] [blame] | 4651 | if (DEBUG_STATES) Slog.v(TAG_STATES, |
| 4652 | "Moving to DESTROYED: " + r + " (destroy skipped)"); |
Bryce Lee | 7ace395 | 2018-02-16 14:34:32 -0800 | [diff] [blame] | 4653 | r.setState(DESTROYED, |
| 4654 | "destroyActivityLocked. not finishing or skipping destroy"); |
Wale Ogunwale | 0fc365c | 2015-05-25 19:35:42 -0700 | [diff] [blame] | 4655 | 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] | 4656 | r.app = null; |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 4657 | } |
| 4658 | } else { |
| 4659 | // remove this record from the history. |
| 4660 | if (r.finishing) { |
Chong Zhang | bffd889 | 2016-08-08 11:16:06 -0700 | [diff] [blame] | 4661 | removeActivityFromHistoryLocked(r, reason + " hadNoApp"); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 4662 | removedFromHistory = true; |
| 4663 | } else { |
Wale Ogunwale | 0fc365c | 2015-05-25 19:35:42 -0700 | [diff] [blame] | 4664 | 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] | 4665 | r.setState(DESTROYED, "destroyActivityLocked. not finishing and had no app"); |
Wale Ogunwale | 0fc365c | 2015-05-25 19:35:42 -0700 | [diff] [blame] | 4666 | 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] | 4667 | r.app = null; |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 4668 | } |
| 4669 | } |
| 4670 | |
| 4671 | r.configChangeFlags = 0; |
Craig Mautner | dbcb31f | 2013-04-02 12:32:53 -0700 | [diff] [blame] | 4672 | |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 4673 | if (!mLRUActivities.remove(r) && hadApp) { |
| 4674 | Slog.w(TAG, "Activity " + r + " being finished, but not in LRU list"); |
| 4675 | } |
Craig Mautner | dbcb31f | 2013-04-02 12:32:53 -0700 | [diff] [blame] | 4676 | |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 4677 | return removedFromHistory; |
| 4678 | } |
| 4679 | |
Craig Mautner | 299f960 | 2015-01-26 09:47:33 -0800 | [diff] [blame] | 4680 | final void activityDestroyedLocked(IBinder token, String reason) { |
Craig Mautner | d232895 | 2013-03-05 12:46:26 -0800 | [diff] [blame] | 4681 | final long origId = Binder.clearCallingIdentity(); |
| 4682 | try { |
Bryce Lee | 7ace395 | 2018-02-16 14:34:32 -0800 | [diff] [blame] | 4683 | activityDestroyedLocked(ActivityRecord.forTokenLocked(token), reason); |
Craig Mautner | d232895 | 2013-03-05 12:46:26 -0800 | [diff] [blame] | 4684 | } finally { |
| 4685 | Binder.restoreCallingIdentity(origId); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 4686 | } |
| 4687 | } |
Craig Mautner | de4ef02 | 2013-04-07 19:01:33 -0700 | [diff] [blame] | 4688 | |
Bryce Lee | c940660 | 2018-03-09 11:02:10 -0800 | [diff] [blame] | 4689 | /** |
| 4690 | * This method is to only be called from the client via binder when the activity is destroyed |
| 4691 | * AND finished. |
| 4692 | */ |
Bryce Lee | 7ace395 | 2018-02-16 14:34:32 -0800 | [diff] [blame] | 4693 | final void activityDestroyedLocked(ActivityRecord record, String reason) { |
| 4694 | if (record != null) { |
| 4695 | mHandler.removeMessages(DESTROY_TIMEOUT_MSG, record); |
| 4696 | } |
| 4697 | |
| 4698 | if (DEBUG_CONTAINERS) Slog.d(TAG_CONTAINERS, "activityDestroyedLocked: r=" + record); |
| 4699 | |
| 4700 | if (isInStackLocked(record) != null) { |
| 4701 | if (record.isState(DESTROYING, DESTROYED)) { |
Bryce Lee | c940660 | 2018-03-09 11:02:10 -0800 | [diff] [blame] | 4702 | cleanUpActivityLocked(record, true, false); |
Bryce Lee | 7ace395 | 2018-02-16 14:34:32 -0800 | [diff] [blame] | 4703 | removeActivityFromHistoryLocked(record, reason); |
| 4704 | } |
| 4705 | } |
| 4706 | |
Wale Ogunwale | d32da47 | 2018-11-16 07:19:28 -0800 | [diff] [blame] | 4707 | mRootActivityContainer.resumeFocusedStacksTopActivities(); |
Bryce Lee | 7ace395 | 2018-02-16 14:34:32 -0800 | [diff] [blame] | 4708 | } |
| 4709 | |
Craig Mautner | 05d6272ba | 2013-02-11 09:39:27 -0800 | [diff] [blame] | 4710 | private void removeHistoryRecordsForAppLocked(ArrayList<ActivityRecord> list, |
Wale Ogunwale | 9e4f3e0 | 2018-05-17 09:35:39 -0700 | [diff] [blame] | 4711 | WindowProcessController app, String listName) { |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 4712 | int i = list.size(); |
Wale Ogunwale | e23149f | 2015-03-06 15:39:44 -0800 | [diff] [blame] | 4713 | if (DEBUG_CLEANUP) Slog.v(TAG_CLEANUP, |
| 4714 | "Removing app " + app + " from list " + listName + " with " + i + " entries"); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 4715 | while (i > 0) { |
| 4716 | i--; |
Craig Mautner | 05d6272ba | 2013-02-11 09:39:27 -0800 | [diff] [blame] | 4717 | ActivityRecord r = list.get(i); |
Wale Ogunwale | e23149f | 2015-03-06 15:39:44 -0800 | [diff] [blame] | 4718 | if (DEBUG_CLEANUP) Slog.v(TAG_CLEANUP, "Record #" + i + " " + r); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 4719 | if (r.app == app) { |
Wale Ogunwale | e23149f | 2015-03-06 15:39:44 -0800 | [diff] [blame] | 4720 | if (DEBUG_CLEANUP) Slog.v(TAG_CLEANUP, "---> REMOVING this entry!"); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 4721 | list.remove(i); |
Dianne Hackborn | 42e620c | 2012-06-24 13:20:51 -0700 | [diff] [blame] | 4722 | removeTimeoutsForActivityLocked(r); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 4723 | } |
| 4724 | } |
| 4725 | } |
| 4726 | |
Wale Ogunwale | 9e4f3e0 | 2018-05-17 09:35:39 -0700 | [diff] [blame] | 4727 | private boolean removeHistoryRecordsForAppLocked(WindowProcessController app) { |
Dianne Hackborn | cc5a055 | 2012-10-01 16:32:39 -0700 | [diff] [blame] | 4728 | removeHistoryRecordsForAppLocked(mLRUActivities, app, "mLRUActivities"); |
Craig Mautner | de4ef02 | 2013-04-07 19:01:33 -0700 | [diff] [blame] | 4729 | removeHistoryRecordsForAppLocked(mStackSupervisor.mStoppingActivities, app, |
| 4730 | "mStoppingActivities"); |
Craig Mautner | 0eea92c | 2013-05-16 13:35:39 -0700 | [diff] [blame] | 4731 | removeHistoryRecordsForAppLocked(mStackSupervisor.mGoingToSleepActivities, app, |
| 4732 | "mGoingToSleepActivities"); |
Craig Mautner | f333327 | 2013-04-22 10:55:53 -0700 | [diff] [blame] | 4733 | removeHistoryRecordsForAppLocked(mStackSupervisor.mFinishingActivities, app, |
| 4734 | "mFinishingActivities"); |
Dianne Hackborn | cc5a055 | 2012-10-01 16:32:39 -0700 | [diff] [blame] | 4735 | |
Riddle Hsu | aaef731 | 2019-01-24 19:00:58 +0800 | [diff] [blame] | 4736 | final boolean isProcessRemoved = app.isRemoved(); |
| 4737 | if (isProcessRemoved) { |
| 4738 | // The package of the died process should be force-stopped, so make its activities as |
| 4739 | // finishing to prevent the process from being started again if the next top (or being |
| 4740 | // visible) activity also resides in the same process. |
| 4741 | app.makeFinishingForProcessRemoved(); |
| 4742 | } |
| 4743 | |
Dianne Hackborn | cc5a055 | 2012-10-01 16:32:39 -0700 | [diff] [blame] | 4744 | boolean hasVisibleActivities = false; |
| 4745 | |
| 4746 | // Clean out the history list. |
Craig Mautner | 0247fc8 | 2013-02-28 14:32:06 -0800 | [diff] [blame] | 4747 | int i = numActivities(); |
Wale Ogunwale | e23149f | 2015-03-06 15:39:44 -0800 | [diff] [blame] | 4748 | if (DEBUG_CLEANUP) Slog.v(TAG_CLEANUP, |
| 4749 | "Removing app " + app + " from history with " + i + " entries"); |
Craig Mautner | 0247fc8 | 2013-02-28 14:32:06 -0800 | [diff] [blame] | 4750 | for (int taskNdx = mTaskHistory.size() - 1; taskNdx >= 0; --taskNdx) { |
| 4751 | final ArrayList<ActivityRecord> activities = mTaskHistory.get(taskNdx).mActivities; |
Bryce Lee | fbd263b4 | 2018-03-07 10:33:55 -0800 | [diff] [blame] | 4752 | mTmpActivities.clear(); |
| 4753 | mTmpActivities.addAll(activities); |
| 4754 | |
| 4755 | while (!mTmpActivities.isEmpty()) { |
| 4756 | final int targetIndex = mTmpActivities.size() - 1; |
| 4757 | final ActivityRecord r = mTmpActivities.remove(targetIndex); |
Wale Ogunwale | e23149f | 2015-03-06 15:39:44 -0800 | [diff] [blame] | 4758 | if (DEBUG_CLEANUP) Slog.v(TAG_CLEANUP, |
Bryce Lee | fbd263b4 | 2018-03-07 10:33:55 -0800 | [diff] [blame] | 4759 | "Record #" + targetIndex + " " + r + ": app=" + r.app); |
| 4760 | |
Craig Mautner | 0247fc8 | 2013-02-28 14:32:06 -0800 | [diff] [blame] | 4761 | if (r.app == app) { |
riddle_hsu | 558e849 | 2015-04-02 16:43:13 +0800 | [diff] [blame] | 4762 | if (r.visible) { |
| 4763 | hasVisibleActivities = true; |
| 4764 | } |
Craig Mautner | acebdc8 | 2015-02-24 10:53:03 -0800 | [diff] [blame] | 4765 | final boolean remove; |
Garfield Tan | 2746ab5 | 2018-07-25 12:33:01 -0700 | [diff] [blame] | 4766 | if ((r.mRelaunchReason == RELAUNCH_REASON_WINDOWING_MODE_RESIZE |
| 4767 | || r.mRelaunchReason == RELAUNCH_REASON_FREE_RESIZE) |
| 4768 | && r.launchCount < 3 && !r.finishing) { |
| 4769 | // If the process crashed during a resize, always try to relaunch it, unless |
| 4770 | // it has failed more than twice. Skip activities that's already finishing |
| 4771 | // cleanly by itself. |
| 4772 | remove = false; |
Riddle Hsu | 7b766fd | 2019-01-28 21:14:59 +0800 | [diff] [blame] | 4773 | } else if ((!r.haveState && !r.stateNotNeeded |
| 4774 | && !r.isState(ActivityState.RESTARTING_PROCESS)) || r.finishing) { |
Craig Mautner | 0247fc8 | 2013-02-28 14:32:06 -0800 | [diff] [blame] | 4775 | // Don't currently have state for the activity, or |
| 4776 | // it is finishing -- always remove it. |
| 4777 | remove = true; |
Chong Zhang | 112eb8c | 2015-11-02 11:17:00 -0800 | [diff] [blame] | 4778 | } else if (!r.visible && r.launchCount > 2 && |
| 4779 | r.lastLaunchTime > (SystemClock.uptimeMillis() - 60000)) { |
Craig Mautner | 0247fc8 | 2013-02-28 14:32:06 -0800 | [diff] [blame] | 4780 | // We have launched this activity too many times since it was |
| 4781 | // able to run, so give up and remove it. |
Chong Zhang | 112eb8c | 2015-11-02 11:17:00 -0800 | [diff] [blame] | 4782 | // (Note if the activity is visible, we don't remove the record. |
| 4783 | // We leave the dead window on the screen but the process will |
| 4784 | // not be restarted unless user explicitly tap on it.) |
Craig Mautner | 0247fc8 | 2013-02-28 14:32:06 -0800 | [diff] [blame] | 4785 | remove = true; |
| 4786 | } else { |
| 4787 | // The process may be gone, but the activity lives on! |
| 4788 | remove = false; |
Dianne Hackborn | cc5a055 | 2012-10-01 16:32:39 -0700 | [diff] [blame] | 4789 | } |
Craig Mautner | 0247fc8 | 2013-02-28 14:32:06 -0800 | [diff] [blame] | 4790 | if (remove) { |
Wale Ogunwale | 0fc365c | 2015-05-25 19:35:42 -0700 | [diff] [blame] | 4791 | if (DEBUG_ADD_REMOVE || DEBUG_CLEANUP) Slog.i(TAG_ADD_REMOVE, |
| 4792 | "Removing activity " + r + " from stack at " + i |
| 4793 | + ": haveState=" + r.haveState |
| 4794 | + " stateNotNeeded=" + r.stateNotNeeded |
| 4795 | + " finishing=" + r.finishing |
Bryce Lee | 7ace395 | 2018-02-16 14:34:32 -0800 | [diff] [blame] | 4796 | + " state=" + r.getState() + " callers=" + Debug.getCallers(5)); |
Riddle Hsu | aaef731 | 2019-01-24 19:00:58 +0800 | [diff] [blame] | 4797 | if (!r.finishing || isProcessRemoved) { |
Craig Mautner | 0247fc8 | 2013-02-28 14:32:06 -0800 | [diff] [blame] | 4798 | Slog.w(TAG, "Force removing " + r + ": app died, no saved state"); |
| 4799 | EventLog.writeEvent(EventLogTags.AM_FINISH_ACTIVITY, |
Wale Ogunwale | 8b19de9 | 2018-11-29 19:58:26 -0800 | [diff] [blame] | 4800 | r.mUserId, System.identityHashCode(r), |
| 4801 | r.getTaskRecord().taskId, r.shortComponentName, |
Craig Mautner | 0247fc8 | 2013-02-28 14:32:06 -0800 | [diff] [blame] | 4802 | "proc died without state saved"); |
| 4803 | } |
Craig Mautner | 0247fc8 | 2013-02-28 14:32:06 -0800 | [diff] [blame] | 4804 | } else { |
| 4805 | // We have the current state for this activity, so |
| 4806 | // it can be restarted later when needed. |
Wale Ogunwale | 0fc365c | 2015-05-25 19:35:42 -0700 | [diff] [blame] | 4807 | if (DEBUG_ALL) Slog.v(TAG, "Keeping entry, setting app to null"); |
| 4808 | if (DEBUG_APP) Slog.v(TAG_APP, |
| 4809 | "Clearing app during removeHistory for activity " + r); |
Craig Mautner | 0247fc8 | 2013-02-28 14:32:06 -0800 | [diff] [blame] | 4810 | r.app = null; |
Chong Zhang | 112eb8c | 2015-11-02 11:17:00 -0800 | [diff] [blame] | 4811 | // Set nowVisible to previous visible state. If the app was visible while |
| 4812 | // it died, we leave the dead window on screen so it's basically visible. |
| 4813 | // This is needed when user later tap on the dead window, we need to stop |
| 4814 | // other apps when user transfers focus to the restarted activity. |
| 4815 | r.nowVisible = r.visible; |
Craig Mautner | 0247fc8 | 2013-02-28 14:32:06 -0800 | [diff] [blame] | 4816 | if (!r.haveState) { |
Wale Ogunwale | 0fc365c | 2015-05-25 19:35:42 -0700 | [diff] [blame] | 4817 | if (DEBUG_SAVED_STATE) Slog.i(TAG_SAVED_STATE, |
Craig Mautner | 0247fc8 | 2013-02-28 14:32:06 -0800 | [diff] [blame] | 4818 | "App died, clearing saved state of " + r); |
| 4819 | r.icicle = null; |
| 4820 | } |
Dianne Hackborn | cc5a055 | 2012-10-01 16:32:39 -0700 | [diff] [blame] | 4821 | } |
Bryce Lee | c940660 | 2018-03-09 11:02:10 -0800 | [diff] [blame] | 4822 | cleanUpActivityLocked(r, true, true); |
Craig Mautner | acebdc8 | 2015-02-24 10:53:03 -0800 | [diff] [blame] | 4823 | if (remove) { |
Chong Zhang | bffd889 | 2016-08-08 11:16:06 -0700 | [diff] [blame] | 4824 | removeActivityFromHistoryLocked(r, "appDied"); |
Craig Mautner | acebdc8 | 2015-02-24 10:53:03 -0800 | [diff] [blame] | 4825 | } |
Craig Mautner | 0247fc8 | 2013-02-28 14:32:06 -0800 | [diff] [blame] | 4826 | } |
Dianne Hackborn | cc5a055 | 2012-10-01 16:32:39 -0700 | [diff] [blame] | 4827 | } |
| 4828 | } |
| 4829 | |
| 4830 | return hasVisibleActivities; |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 4831 | } |
Craig Mautner | 0247fc8 | 2013-02-28 14:32:06 -0800 | [diff] [blame] | 4832 | |
chaviw | 0d562bf | 2018-03-15 14:24:14 -0700 | [diff] [blame] | 4833 | private void updateTransitLocked(int transit, ActivityOptions options) { |
Dianne Hackborn | 7f58b95 | 2012-04-18 12:59:29 -0700 | [diff] [blame] | 4834 | if (options != null) { |
chaviw | 0d562bf | 2018-03-15 14:24:14 -0700 | [diff] [blame] | 4835 | ActivityRecord r = topRunningActivityLocked(); |
| 4836 | if (r != null && !r.isState(RESUMED)) { |
| 4837 | r.updateOptionsLocked(options); |
Dianne Hackborn | 7f58b95 | 2012-04-18 12:59:29 -0700 | [diff] [blame] | 4838 | } else { |
| 4839 | ActivityOptions.abort(options); |
| 4840 | } |
| 4841 | } |
Wale Ogunwale | 3a256e6 | 2018-12-06 14:41:18 -0800 | [diff] [blame] | 4842 | getDisplay().mDisplayContent.prepareAppTransition(transit, false); |
Dianne Hackborn | 7f58b95 | 2012-04-18 12:59:29 -0700 | [diff] [blame] | 4843 | } |
Dianne Hackborn | 621e17d | 2010-11-22 15:59:56 -0800 | [diff] [blame] | 4844 | |
Andrii Kulian | 21713ac | 2016-10-12 22:05:05 -0700 | [diff] [blame] | 4845 | private void updateTaskMovement(TaskRecord task, boolean toFront) { |
Craig Mautner | 21d24a2 | 2014-04-23 11:45:37 -0700 | [diff] [blame] | 4846 | if (task.isPersistable) { |
| 4847 | task.mLastTimeMoved = System.currentTimeMillis(); |
| 4848 | // Sign is used to keep tasks sorted when persisted. Tasks sent to the bottom most |
| 4849 | // recently will be most negative, tasks sent to the bottom before that will be less |
| 4850 | // negative. Similarly for recent tasks moved to the top which will be most positive. |
| 4851 | if (!toFront) { |
| 4852 | task.mLastTimeMoved *= -1; |
| 4853 | } |
| 4854 | } |
Wale Ogunwale | d32da47 | 2018-11-16 07:19:28 -0800 | [diff] [blame] | 4855 | mRootActivityContainer.invalidateTaskLayers(); |
Craig Mautner | 21d24a2 | 2014-04-23 11:45:37 -0700 | [diff] [blame] | 4856 | } |
| 4857 | |
chaviw | 0d562bf | 2018-03-15 14:24:14 -0700 | [diff] [blame] | 4858 | final void moveTaskToFrontLocked(TaskRecord tr, boolean noAnimation, ActivityOptions options, |
| 4859 | AppTimeTracker timeTracker, String reason) { |
Wale Ogunwale | ee006da | 2015-03-30 14:49:25 -0700 | [diff] [blame] | 4860 | if (DEBUG_SWITCH) Slog.v(TAG_SWITCH, "moveTaskToFront: " + tr); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 4861 | |
Wale Ogunwale | a0f5b5e | 2017-10-11 09:37:23 -0700 | [diff] [blame] | 4862 | final ActivityStack topStack = getDisplay().getTopStack(); |
Wale Ogunwale | 30e441d | 2017-11-09 08:28:45 -0800 | [diff] [blame] | 4863 | final ActivityRecord topActivity = topStack != null ? topStack.getTopActivity() : null; |
Craig Mautner | 11bf9a5 | 2013-02-19 14:08:51 -0800 | [diff] [blame] | 4864 | final int numTasks = mTaskHistory.size(); |
| 4865 | final int index = mTaskHistory.indexOf(tr); |
Craig Mautner | 86d67a4 | 2013-05-14 10:34:38 -0700 | [diff] [blame] | 4866 | if (numTasks == 0 || index < 0) { |
Craig Mautner | 11bf9a5 | 2013-02-19 14:08:51 -0800 | [diff] [blame] | 4867 | // nothing to do! |
Craig Mautner | 8f5f7e9 | 2015-01-26 18:03:13 -0800 | [diff] [blame] | 4868 | if (noAnimation) { |
Craig Mautner | 11bf9a5 | 2013-02-19 14:08:51 -0800 | [diff] [blame] | 4869 | ActivityOptions.abort(options); |
| 4870 | } else { |
chaviw | 0d562bf | 2018-03-15 14:24:14 -0700 | [diff] [blame] | 4871 | updateTransitLocked(TRANSIT_TASK_TO_FRONT, options); |
Craig Mautner | 11bf9a5 | 2013-02-19 14:08:51 -0800 | [diff] [blame] | 4872 | } |
| 4873 | return; |
| 4874 | } |
| 4875 | |
Dianne Hackborn | b5a380d | 2015-05-20 18:18:46 -0700 | [diff] [blame] | 4876 | if (timeTracker != null) { |
| 4877 | // The caller wants a time tracker associated with this task. |
| 4878 | for (int i = tr.mActivities.size() - 1; i >= 0; i--) { |
| 4879 | tr.mActivities.get(i).appTimeTracker = timeTracker; |
| 4880 | } |
| 4881 | } |
| 4882 | |
Chavi Weingarten | 3a74855 | 2018-05-14 17:32:42 +0000 | [diff] [blame] | 4883 | try { |
| 4884 | // Defer updating the IME target since the new IME target will try to get computed |
| 4885 | // before updating all closing and opening apps, which can cause the ime target to |
| 4886 | // get calculated incorrectly. |
| 4887 | getDisplay().deferUpdateImeTarget(); |
Wale Ogunwale | d80c263 | 2015-03-13 10:26:26 -0700 | [diff] [blame] | 4888 | |
Chavi Weingarten | 3a74855 | 2018-05-14 17:32:42 +0000 | [diff] [blame] | 4889 | // Shift all activities with this task up to the top |
| 4890 | // of the stack, keeping them in the same internal order. |
| 4891 | insertTaskAtTop(tr, null); |
| 4892 | |
| 4893 | // Don't refocus if invisible to current user |
| 4894 | final ActivityRecord top = tr.getTopActivity(); |
| 4895 | if (top == null || !top.okToShowLocked()) { |
| 4896 | if (top != null) { |
Wale Ogunwale | 8b19de9 | 2018-11-29 19:58:26 -0800 | [diff] [blame] | 4897 | mStackSupervisor.mRecentTasks.add(top.getTaskRecord()); |
Chavi Weingarten | 3a74855 | 2018-05-14 17:32:42 +0000 | [diff] [blame] | 4898 | } |
| 4899 | ActivityOptions.abort(options); |
| 4900 | return; |
Winson Chung | 1dbc811 | 2017-09-28 18:05:31 -0700 | [diff] [blame] | 4901 | } |
Chavi Weingarten | 9e875b6 | 2018-05-14 16:10:59 +0000 | [diff] [blame] | 4902 | |
Chavi Weingarten | 3a74855 | 2018-05-14 17:32:42 +0000 | [diff] [blame] | 4903 | // Set focus to the top running activity of this stack. |
| 4904 | final ActivityRecord r = topRunningActivityLocked(); |
Louis Chang | 1944345 | 2018-10-09 12:10:21 +0800 | [diff] [blame] | 4905 | if (r != null) { |
| 4906 | r.moveFocusableActivityToTop(reason); |
| 4907 | } |
Chavi Weingarten | 9e875b6 | 2018-05-14 16:10:59 +0000 | [diff] [blame] | 4908 | |
Chavi Weingarten | 3a74855 | 2018-05-14 17:32:42 +0000 | [diff] [blame] | 4909 | if (DEBUG_TRANSITION) Slog.v(TAG_TRANSITION, "Prepare to front transition: task=" + tr); |
| 4910 | if (noAnimation) { |
Wale Ogunwale | 3a256e6 | 2018-12-06 14:41:18 -0800 | [diff] [blame] | 4911 | getDisplay().mDisplayContent.prepareAppTransition(TRANSIT_NONE, false); |
Chavi Weingarten | 3a74855 | 2018-05-14 17:32:42 +0000 | [diff] [blame] | 4912 | if (r != null) { |
| 4913 | mStackSupervisor.mNoAnimActivities.add(r); |
| 4914 | } |
| 4915 | ActivityOptions.abort(options); |
| 4916 | } else { |
| 4917 | updateTransitLocked(TRANSIT_TASK_TO_FRONT, options); |
Chavi Weingarten | 9e875b6 | 2018-05-14 16:10:59 +0000 | [diff] [blame] | 4918 | } |
Chavi Weingarten | 3a74855 | 2018-05-14 17:32:42 +0000 | [diff] [blame] | 4919 | // If a new task is moved to the front, then mark the existing top activity as |
| 4920 | // supporting |
Chavi Weingarten | 9e875b6 | 2018-05-14 16:10:59 +0000 | [diff] [blame] | 4921 | |
Chavi Weingarten | 3a74855 | 2018-05-14 17:32:42 +0000 | [diff] [blame] | 4922 | // picture-in-picture while paused only if the task would not be considered an oerlay |
| 4923 | // on top |
| 4924 | // of the current activity (eg. not fullscreen, or the assistant) |
| 4925 | if (canEnterPipOnTaskSwitch(topActivity, tr, null /* toFrontActivity */, |
| 4926 | options)) { |
| 4927 | topActivity.supportsEnterPipOnTaskSwitch = true; |
| 4928 | } |
Chavi Weingarten | 9e875b6 | 2018-05-14 16:10:59 +0000 | [diff] [blame] | 4929 | |
Wale Ogunwale | d32da47 | 2018-11-16 07:19:28 -0800 | [diff] [blame] | 4930 | mRootActivityContainer.resumeFocusedStacksTopActivities(); |
Chavi Weingarten | 3a74855 | 2018-05-14 17:32:42 +0000 | [diff] [blame] | 4931 | EventLog.writeEvent(EventLogTags.AM_TASK_TO_FRONT, tr.userId, tr.taskId); |
Mark Renouf | c808f06 | 2019-02-07 15:20:37 -0500 | [diff] [blame] | 4932 | mService.getTaskChangeNotificationController().notifyTaskMovedToFront(tr.getTaskInfo()); |
Chavi Weingarten | 3a74855 | 2018-05-14 17:32:42 +0000 | [diff] [blame] | 4933 | } finally { |
| 4934 | getDisplay().continueUpdateImeTarget(); |
| 4935 | } |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 4936 | } |
| 4937 | |
| 4938 | /** |
Craig Mautner | ce5f3cb | 2013-04-22 08:58:54 -0700 | [diff] [blame] | 4939 | * Worker method for rearranging history stack. Implements the function of moving all |
| 4940 | * 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] | 4941 | * bottom of the stack. |
Craig Mautner | ce5f3cb | 2013-04-22 08:58:54 -0700 | [diff] [blame] | 4942 | * |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 4943 | * If a watcher is installed, the action is preflighted and the watcher has an opportunity |
| 4944 | * to premeptively cancel the move. |
Craig Mautner | ce5f3cb | 2013-04-22 08:58:54 -0700 | [diff] [blame] | 4945 | * |
Craig Mautner | ae7ecab | 2013-09-18 11:48:14 -0700 | [diff] [blame] | 4946 | * @param taskId The taskId to collect and move to the bottom. |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 4947 | * @return Returns true if the move completed, false if not. |
| 4948 | */ |
Craig Mautner | 299f960 | 2015-01-26 09:47:33 -0800 | [diff] [blame] | 4949 | final boolean moveTaskToBackLocked(int taskId) { |
Craig Mautner | aea74a5 | 2014-03-08 14:23:10 -0800 | [diff] [blame] | 4950 | final TaskRecord tr = taskForIdLocked(taskId); |
| 4951 | if (tr == null) { |
| 4952 | Slog.i(TAG, "moveTaskToBack: bad taskId=" + taskId); |
| 4953 | return false; |
| 4954 | } |
Craig Mautner | aea74a5 | 2014-03-08 14:23:10 -0800 | [diff] [blame] | 4955 | Slog.i(TAG, "moveTaskToBack: " + tr); |
Winson Chung | 261c0f3 | 2017-03-07 16:54:31 -0800 | [diff] [blame] | 4956 | |
Charles He | ff9b4dff | 2017-09-22 10:18:37 +0100 | [diff] [blame] | 4957 | // In LockTask mode, moving a locked task to the back of the stack may expose unlocked |
| 4958 | // ones. Therefore we need to check if this operation is allowed. |
Wale Ogunwale | 5fa8a8c | 2018-05-08 13:43:21 -0700 | [diff] [blame] | 4959 | if (!mService.getLockTaskController().canMoveTaskToBack(tr)) { |
Winson Chung | 261c0f3 | 2017-03-07 16:54:31 -0800 | [diff] [blame] | 4960 | return false; |
| 4961 | } |
Craig Mautner | b44de0d | 2013-02-21 20:00:58 -0800 | [diff] [blame] | 4962 | |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 4963 | // If we have a watcher, preflight the move before committing to it. First check |
| 4964 | // for *other* available tasks, but if none are available, then try again allowing the |
| 4965 | // current task to be selected. |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 4966 | if (isTopStackOnDisplay() && mService.mController != null) { |
Craig Mautner | ae7ecab | 2013-09-18 11:48:14 -0700 | [diff] [blame] | 4967 | ActivityRecord next = topRunningActivityLocked(null, taskId); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 4968 | if (next == null) { |
| 4969 | next = topRunningActivityLocked(null, 0); |
| 4970 | } |
| 4971 | if (next != null) { |
| 4972 | // ask watcher if this is allowed |
| 4973 | boolean moveOK = true; |
| 4974 | try { |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 4975 | moveOK = mService.mController.activityResuming(next.packageName); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 4976 | } catch (RemoteException e) { |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 4977 | mService.mController = null; |
Kenny Root | add5821 | 2013-05-07 09:47:34 -0700 | [diff] [blame] | 4978 | Watchdog.getInstance().setActivityController(null); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 4979 | } |
| 4980 | if (!moveOK) { |
| 4981 | return false; |
| 4982 | } |
| 4983 | } |
| 4984 | } |
| 4985 | |
Wale Ogunwale | ee006da | 2015-03-30 14:49:25 -0700 | [diff] [blame] | 4986 | 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] | 4987 | |
Wale Ogunwale | 66e1685 | 2017-10-19 13:35:52 -0700 | [diff] [blame] | 4988 | mTaskHistory.remove(tr); |
| 4989 | mTaskHistory.add(0, tr); |
| 4990 | updateTaskMovement(tr, false); |
Wale Ogunwale | 4270924 | 2015-08-11 13:54:42 -0700 | [diff] [blame] | 4991 | |
Wale Ogunwale | 3a256e6 | 2018-12-06 14:41:18 -0800 | [diff] [blame] | 4992 | getDisplay().mDisplayContent.prepareAppTransition(TRANSIT_TASK_TO_BACK, false); |
Evan Rosky | 9c44817 | 2017-11-02 14:19:27 -0700 | [diff] [blame] | 4993 | moveToBack("moveTaskToBackLocked", tr); |
Winson Chung | 261c0f3 | 2017-03-07 16:54:31 -0800 | [diff] [blame] | 4994 | |
Wale Ogunwale | 44f036f | 2017-09-29 05:09:09 -0700 | [diff] [blame] | 4995 | if (inPinnedWindowingMode()) { |
Wale Ogunwale | a0f5b5e | 2017-10-11 09:37:23 -0700 | [diff] [blame] | 4996 | mStackSupervisor.removeStack(this); |
Winson Chung | 261c0f3 | 2017-03-07 16:54:31 -0800 | [diff] [blame] | 4997 | return true; |
| 4998 | } |
| 4999 | |
Evan Rosky | 80b2cb7 | 2019-05-31 20:18:02 -0700 | [diff] [blame] | 5000 | ActivityRecord topActivity = getDisplay().topRunningActivity(); |
| 5001 | ActivityStack topStack = topActivity.getActivityStack(); |
| 5002 | if (topStack != null && topStack != this && topActivity.isState(RESUMED)) { |
| 5003 | // The new top activity is already resumed, so there's a good chance that nothing will |
| 5004 | // get resumed below. So, update visibility now in case the transition is closed |
| 5005 | // prematurely. |
| 5006 | mRootActivityContainer.ensureVisibilityAndConfig(null /* starting */, |
| 5007 | getDisplay().mDisplayId, false /* markFrozenIfConfigChanged */, |
| 5008 | false /* deferResume */); |
| 5009 | } |
| 5010 | |
Wale Ogunwale | d32da47 | 2018-11-16 07:19:28 -0800 | [diff] [blame] | 5011 | mRootActivityContainer.resumeFocusedStacksTopActivities(); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 5012 | return true; |
| 5013 | } |
Dianne Hackborn | 15491c6 | 2012-09-19 10:59:14 -0700 | [diff] [blame] | 5014 | |
Andrii Kulian | 21713ac | 2016-10-12 22:05:05 -0700 | [diff] [blame] | 5015 | static void logStartActivity(int tag, ActivityRecord r, TaskRecord task) { |
Santos Cordon | 73ff7d8 | 2013-03-06 17:24:11 -0800 | [diff] [blame] | 5016 | final Uri data = r.intent.getData(); |
| 5017 | final String strData = data != null ? data.toSafeString() : null; |
| 5018 | |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 5019 | EventLog.writeEvent(tag, |
Wale Ogunwale | 8b19de9 | 2018-11-29 19:58:26 -0800 | [diff] [blame] | 5020 | r.mUserId, System.identityHashCode(r), task.taskId, |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 5021 | r.shortComponentName, r.intent.getAction(), |
Santos Cordon | 73ff7d8 | 2013-03-06 17:24:11 -0800 | [diff] [blame] | 5022 | r.intent.getType(), strData, r.intent.getFlags()); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 5023 | } |
| 5024 | |
| 5025 | /** |
Wale Ogunwale | db0fa12 | 2016-05-16 15:12:03 -0700 | [diff] [blame] | 5026 | * Ensures all visible activities at or below the input activity have the right configuration. |
| 5027 | */ |
| 5028 | void ensureVisibleActivitiesConfigurationLocked(ActivityRecord start, boolean preserveWindow) { |
| 5029 | if (start == null || !start.visible) { |
| 5030 | return; |
| 5031 | } |
| 5032 | |
Wale Ogunwale | 8b19de9 | 2018-11-29 19:58:26 -0800 | [diff] [blame] | 5033 | final TaskRecord startTask = start.getTaskRecord(); |
Wale Ogunwale | db0fa12 | 2016-05-16 15:12:03 -0700 | [diff] [blame] | 5034 | boolean behindFullscreen = false; |
| 5035 | boolean updatedConfig = false; |
| 5036 | |
| 5037 | for (int taskIndex = mTaskHistory.indexOf(startTask); taskIndex >= 0; --taskIndex) { |
| 5038 | final TaskRecord task = mTaskHistory.get(taskIndex); |
| 5039 | final ArrayList<ActivityRecord> activities = task.mActivities; |
Wale Ogunwale | 8b19de9 | 2018-11-29 19:58:26 -0800 | [diff] [blame] | 5040 | int activityIndex = (start.getTaskRecord() == task) |
| 5041 | ? activities.indexOf(start) : activities.size() - 1; |
Wale Ogunwale | db0fa12 | 2016-05-16 15:12:03 -0700 | [diff] [blame] | 5042 | for (; activityIndex >= 0; --activityIndex) { |
| 5043 | final ActivityRecord r = activities.get(activityIndex); |
Wale Ogunwale | b6d75f3 | 2018-02-22 20:44:56 -0800 | [diff] [blame] | 5044 | updatedConfig |= r.ensureActivityConfiguration(0 /* globalChanges */, |
Andrii Kulian | 21713ac | 2016-10-12 22:05:05 -0700 | [diff] [blame] | 5045 | preserveWindow); |
Wale Ogunwale | db0fa12 | 2016-05-16 15:12:03 -0700 | [diff] [blame] | 5046 | if (r.fullscreen) { |
| 5047 | behindFullscreen = true; |
| 5048 | break; |
| 5049 | } |
| 5050 | } |
| 5051 | if (behindFullscreen) { |
| 5052 | break; |
| 5053 | } |
| 5054 | } |
| 5055 | if (updatedConfig) { |
Wale Ogunwale | 089586f | 2016-06-20 14:16:22 -0700 | [diff] [blame] | 5056 | // 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] | 5057 | // any activity. |
Wale Ogunwale | d32da47 | 2018-11-16 07:19:28 -0800 | [diff] [blame] | 5058 | mRootActivityContainer.resumeFocusedStacksTopActivities(); |
Wale Ogunwale | db0fa12 | 2016-05-16 15:12:03 -0700 | [diff] [blame] | 5059 | } |
| 5060 | } |
| 5061 | |
Wale Ogunwale | 1666e31 | 2016-12-16 11:27:18 -0800 | [diff] [blame] | 5062 | // TODO: Figure-out a way to consolidate with resize() method below. |
Yunfan Chen | 279f558 | 2018-12-12 15:24:50 -0800 | [diff] [blame] | 5063 | void requestResize(Rect bounds) { |
Wale Ogunwale | 5fa8a8c | 2018-05-08 13:43:21 -0700 | [diff] [blame] | 5064 | mService.resizeStack(mStackId, bounds, |
Wale Ogunwale | 65ebd95 | 2018-04-25 15:41:44 -0700 | [diff] [blame] | 5065 | true /* allowResizeInDockedMode */, false /* preserveWindows */, |
| 5066 | false /* animate */, -1 /* animationDuration */); |
Wale Ogunwale | 1666e31 | 2016-12-16 11:27:18 -0800 | [diff] [blame] | 5067 | } |
Andrii Kulian | 1e32e02 | 2016-09-16 15:29:34 -0700 | [diff] [blame] | 5068 | |
Wale Ogunwale | 1666e31 | 2016-12-16 11:27:18 -0800 | [diff] [blame] | 5069 | // TODO: Can only be called from special methods in ActivityStackSupervisor. |
| 5070 | // Need to consolidate those calls points into this resize method so anyone can call directly. |
| 5071 | void resize(Rect bounds, Rect tempTaskBounds, Rect tempTaskInsetBounds) { |
Evan Rosky | 1ac8446 | 2018-11-13 11:25:30 -0800 | [diff] [blame] | 5072 | if (!updateBoundsAllowed(bounds)) { |
Wale Ogunwale | 1666e31 | 2016-12-16 11:27:18 -0800 | [diff] [blame] | 5073 | return; |
| 5074 | } |
| 5075 | |
| 5076 | // Update override configurations of all tasks in the stack. |
| 5077 | final Rect taskBounds = tempTaskBounds != null ? tempTaskBounds : bounds; |
Andrii Kulian | 1e32e02 | 2016-09-16 15:29:34 -0700 | [diff] [blame] | 5078 | |
Wale Ogunwale | 1f5e53d | 2018-11-05 05:12:46 -0800 | [diff] [blame] | 5079 | for (int i = mTaskHistory.size() - 1; i >= 0; i--) { |
| 5080 | final TaskRecord task = mTaskHistory.get(i); |
| 5081 | if (task.isResizeable()) { |
Garfield Tan | 020607d | 2018-12-17 17:01:58 -0800 | [diff] [blame] | 5082 | task.updateOverrideConfiguration(taskBounds, tempTaskInsetBounds); |
Andrii Kulian | 1e32e02 | 2016-09-16 15:29:34 -0700 | [diff] [blame] | 5083 | } |
Andrii Kulian | 1e32e02 | 2016-09-16 15:29:34 -0700 | [diff] [blame] | 5084 | } |
Wale Ogunwale | 1f5e53d | 2018-11-05 05:12:46 -0800 | [diff] [blame] | 5085 | |
Wale Ogunwale | 1f5e53d | 2018-11-05 05:12:46 -0800 | [diff] [blame] | 5086 | setBounds(bounds); |
Andrii Kulian | 1e32e02 | 2016-09-16 15:29:34 -0700 | [diff] [blame] | 5087 | } |
| 5088 | |
Winson Chung | 15036ca | 2018-05-31 15:51:47 -0700 | [diff] [blame] | 5089 | void onPipAnimationEndResize() { |
Yunfan Chen | 279f558 | 2018-12-12 15:24:50 -0800 | [diff] [blame] | 5090 | if (mTaskStack == null) return; |
| 5091 | mTaskStack.onPipAnimationEndResize(); |
Winson Chung | 15036ca | 2018-05-31 15:51:47 -0700 | [diff] [blame] | 5092 | } |
| 5093 | |
Andrii Kulian | 1e32e02 | 2016-09-16 15:29:34 -0700 | [diff] [blame] | 5094 | |
| 5095 | /** |
Evan Rosky | 1ac8446 | 2018-11-13 11:25:30 -0800 | [diff] [blame] | 5096 | * Until we can break this "set task bounds to same as stack bounds" behavior, this |
| 5097 | * basically resizes both stack and task bounds to the same bounds. |
Andrii Kulian | 1e32e02 | 2016-09-16 15:29:34 -0700 | [diff] [blame] | 5098 | */ |
Evan Rosky | 1ac8446 | 2018-11-13 11:25:30 -0800 | [diff] [blame] | 5099 | void setTaskBounds(Rect bounds) { |
| 5100 | if (!updateBoundsAllowed(bounds)) { |
Andrii Kulian | 1e32e02 | 2016-09-16 15:29:34 -0700 | [diff] [blame] | 5101 | return; |
| 5102 | } |
| 5103 | |
Evan Rosky | 1ac8446 | 2018-11-13 11:25:30 -0800 | [diff] [blame] | 5104 | for (int i = mTaskHistory.size() - 1; i >= 0; i--) { |
| 5105 | final TaskRecord task = mTaskHistory.get(i); |
| 5106 | if (task.isResizeable()) { |
| 5107 | task.setBounds(bounds); |
| 5108 | } else { |
| 5109 | task.setBounds(null); |
Andrii Kulian | 1e32e02 | 2016-09-16 15:29:34 -0700 | [diff] [blame] | 5110 | } |
Evan Rosky | 1ac8446 | 2018-11-13 11:25:30 -0800 | [diff] [blame] | 5111 | } |
| 5112 | } |
| 5113 | |
| 5114 | /** Helper to setDisplayedBounds on all child tasks */ |
| 5115 | void setTaskDisplayedBounds(Rect bounds) { |
| 5116 | if (!updateDisplayedBoundsAllowed(bounds)) { |
| 5117 | return; |
Andrii Kulian | 1e32e02 | 2016-09-16 15:29:34 -0700 | [diff] [blame] | 5118 | } |
| 5119 | |
Evan Rosky | 1ac8446 | 2018-11-13 11:25:30 -0800 | [diff] [blame] | 5120 | for (int i = mTaskHistory.size() - 1; i >= 0; i--) { |
| 5121 | final TaskRecord task = mTaskHistory.get(i); |
| 5122 | if (bounds == null || bounds.isEmpty()) { |
| 5123 | task.setDisplayedBounds(null); |
| 5124 | } else if (task.isResizeable()) { |
| 5125 | task.setDisplayedBounds(bounds); |
Andrii Kulian | 1e32e02 | 2016-09-16 15:29:34 -0700 | [diff] [blame] | 5126 | } |
Andrii Kulian | 1e32e02 | 2016-09-16 15:29:34 -0700 | [diff] [blame] | 5127 | } |
| 5128 | } |
| 5129 | |
Craig Mautner | cae015f | 2013-02-08 14:31:27 -0800 | [diff] [blame] | 5130 | boolean willActivityBeVisibleLocked(IBinder token) { |
Craig Mautner | d44711d | 2013-02-23 11:24:36 -0800 | [diff] [blame] | 5131 | for (int taskNdx = mTaskHistory.size() - 1; taskNdx >= 0; --taskNdx) { |
| 5132 | final ArrayList<ActivityRecord> activities = mTaskHistory.get(taskNdx).mActivities; |
| 5133 | for (int activityNdx = activities.size() - 1; activityNdx >= 0; --activityNdx) { |
| 5134 | final ActivityRecord r = activities.get(activityNdx); |
| 5135 | if (r.appToken == token) { |
Craig Mautner | 34b73df | 2014-01-12 21:11:08 -0800 | [diff] [blame] | 5136 | return true; |
Craig Mautner | d44711d | 2013-02-23 11:24:36 -0800 | [diff] [blame] | 5137 | } |
| 5138 | if (r.fullscreen && !r.finishing) { |
| 5139 | return false; |
| 5140 | } |
Craig Mautner | cae015f | 2013-02-08 14:31:27 -0800 | [diff] [blame] | 5141 | } |
| 5142 | } |
Wale Ogunwale | 7d70117 | 2015-03-11 15:36:30 -0700 | [diff] [blame] | 5143 | final ActivityRecord r = ActivityRecord.forTokenLocked(token); |
Craig Mautner | 34b73df | 2014-01-12 21:11:08 -0800 | [diff] [blame] | 5144 | if (r == null) { |
| 5145 | return false; |
| 5146 | } |
| 5147 | if (r.finishing) Slog.e(TAG, "willActivityBeVisibleLocked: Returning false," |
| 5148 | + " would have returned true for r=" + r); |
| 5149 | return !r.finishing; |
Craig Mautner | cae015f | 2013-02-08 14:31:27 -0800 | [diff] [blame] | 5150 | } |
| 5151 | |
| 5152 | void closeSystemDialogsLocked() { |
Craig Mautner | d44711d | 2013-02-23 11:24:36 -0800 | [diff] [blame] | 5153 | for (int taskNdx = mTaskHistory.size() - 1; taskNdx >= 0; --taskNdx) { |
| 5154 | final ArrayList<ActivityRecord> activities = mTaskHistory.get(taskNdx).mActivities; |
| 5155 | for (int activityNdx = activities.size() - 1; activityNdx >= 0; --activityNdx) { |
| 5156 | final ActivityRecord r = activities.get(activityNdx); |
| 5157 | if ((r.info.flags&ActivityInfo.FLAG_FINISH_ON_CLOSE_SYSTEM_DIALOGS) != 0) { |
Wale Ogunwale | 586a8ee | 2019-06-04 13:44:14 +0000 | [diff] [blame] | 5158 | finishActivityLocked(r, Activity.RESULT_CANCELED, null, "close-sys", true); |
Craig Mautner | d44711d | 2013-02-23 11:24:36 -0800 | [diff] [blame] | 5159 | } |
Craig Mautner | cae015f | 2013-02-08 14:31:27 -0800 | [diff] [blame] | 5160 | } |
| 5161 | } |
| 5162 | } |
| 5163 | |
Wale Ogunwale | 540e123 | 2015-05-01 15:35:39 -0700 | [diff] [blame] | 5164 | boolean finishDisabledPackageActivitiesLocked(String packageName, Set<String> filterByClasses, |
| 5165 | boolean doit, boolean evenPersistent, int userId) { |
Craig Mautner | cae015f | 2013-02-08 14:31:27 -0800 | [diff] [blame] | 5166 | boolean didSomething = false; |
| 5167 | TaskRecord lastTask = null; |
Craig Mautner | 9d8a30d | 2014-07-07 17:26:20 +0000 | [diff] [blame] | 5168 | ComponentName homeActivity = null; |
Craig Mautner | 56f52db | 2013-02-25 10:03:01 -0800 | [diff] [blame] | 5169 | for (int taskNdx = mTaskHistory.size() - 1; taskNdx >= 0; --taskNdx) { |
| 5170 | final ArrayList<ActivityRecord> activities = mTaskHistory.get(taskNdx).mActivities; |
Bryce Lee | fbd263b4 | 2018-03-07 10:33:55 -0800 | [diff] [blame] | 5171 | mTmpActivities.clear(); |
| 5172 | mTmpActivities.addAll(activities); |
| 5173 | |
| 5174 | while (!mTmpActivities.isEmpty()) { |
| 5175 | ActivityRecord r = mTmpActivities.remove(0); |
Wale Ogunwale | 540e123 | 2015-05-01 15:35:39 -0700 | [diff] [blame] | 5176 | final boolean sameComponent = |
| 5177 | (r.packageName.equals(packageName) && (filterByClasses == null |
Wale Ogunwale | 8b19de9 | 2018-11-29 19:58:26 -0800 | [diff] [blame] | 5178 | || filterByClasses.contains(r.mActivityComponent.getClassName()))) |
| 5179 | || (packageName == null && r.mUserId == userId); |
| 5180 | if ((userId == UserHandle.USER_ALL || r.mUserId == userId) |
| 5181 | && (sameComponent || r.getTaskRecord() == lastTask) |
Wale Ogunwale | 9e4f3e0 | 2018-05-17 09:35:39 -0700 | [diff] [blame] | 5182 | && (r.app == null || evenPersistent || !r.app.isPersistent())) { |
Craig Mautner | 56f52db | 2013-02-25 10:03:01 -0800 | [diff] [blame] | 5183 | if (!doit) { |
| 5184 | if (r.finishing) { |
| 5185 | // If this activity is just finishing, then it is not |
| 5186 | // interesting as far as something to stop. |
| 5187 | continue; |
| 5188 | } |
| 5189 | return true; |
Craig Mautner | cae015f | 2013-02-08 14:31:27 -0800 | [diff] [blame] | 5190 | } |
Wale Ogunwale | 6fbde9f | 2017-08-24 07:24:12 -0700 | [diff] [blame] | 5191 | if (r.isActivityTypeHome()) { |
Wale Ogunwale | 8b19de9 | 2018-11-29 19:58:26 -0800 | [diff] [blame] | 5192 | if (homeActivity != null && homeActivity.equals(r.mActivityComponent)) { |
Craig Mautner | 9d8a30d | 2014-07-07 17:26:20 +0000 | [diff] [blame] | 5193 | Slog.i(TAG, "Skip force-stop again " + r); |
| 5194 | continue; |
| 5195 | } else { |
Wale Ogunwale | 8b19de9 | 2018-11-29 19:58:26 -0800 | [diff] [blame] | 5196 | homeActivity = r.mActivityComponent; |
Craig Mautner | 9d8a30d | 2014-07-07 17:26:20 +0000 | [diff] [blame] | 5197 | } |
| 5198 | } |
Craig Mautner | 56f52db | 2013-02-25 10:03:01 -0800 | [diff] [blame] | 5199 | didSomething = true; |
| 5200 | Slog.i(TAG, " Force finishing activity " + r); |
Wale Ogunwale | 8b19de9 | 2018-11-29 19:58:26 -0800 | [diff] [blame] | 5201 | lastTask = r.getTaskRecord(); |
Wale Ogunwale | 586a8ee | 2019-06-04 13:44:14 +0000 | [diff] [blame] | 5202 | finishActivityLocked(r, Activity.RESULT_CANCELED, null, "force-stop", |
| 5203 | true); |
Craig Mautner | cae015f | 2013-02-08 14:31:27 -0800 | [diff] [blame] | 5204 | } |
| 5205 | } |
| 5206 | } |
| 5207 | return didSomething; |
| 5208 | } |
| 5209 | |
Winson Chung | 61c9e5a | 2017-10-11 10:39:32 -0700 | [diff] [blame] | 5210 | /** |
| 5211 | * @return The set of running tasks through {@param tasksOut} that are available to the caller. |
| 5212 | * If {@param ignoreActivityType} or {@param ignoreWindowingMode} are not undefined, |
| 5213 | * then skip running tasks that match those types. |
| 5214 | */ |
| 5215 | void getRunningTasks(List<TaskRecord> tasksOut, @ActivityType int ignoreActivityType, |
| 5216 | @WindowingMode int ignoreWindowingMode, int callingUid, boolean allowed) { |
Wale Ogunwale | d32da47 | 2018-11-16 07:19:28 -0800 | [diff] [blame] | 5217 | boolean focusedStack = mRootActivityContainer.getTopDisplayFocusedStack() == this; |
riddle_hsu | ddc7415 | 2015-04-07 11:30:09 +0800 | [diff] [blame] | 5218 | boolean topTask = true; |
Craig Mautner | c0fd805 | 2013-09-19 11:20:17 -0700 | [diff] [blame] | 5219 | for (int taskNdx = mTaskHistory.size() - 1; taskNdx >= 0; --taskNdx) { |
Craig Mautner | aab647e | 2013-02-28 16:31:36 -0800 | [diff] [blame] | 5220 | final TaskRecord task = mTaskHistory.get(taskNdx); |
riddle_hsu | ddc7415 | 2015-04-07 11:30:09 +0800 | [diff] [blame] | 5221 | if (task.getTopActivity() == null) { |
Winson Chung | 61c9e5a | 2017-10-11 10:39:32 -0700 | [diff] [blame] | 5222 | // Skip if there are no activities in the task |
riddle_hsu | ddc7415 | 2015-04-07 11:30:09 +0800 | [diff] [blame] | 5223 | continue; |
| 5224 | } |
Wale Ogunwale | 6fbde9f | 2017-08-24 07:24:12 -0700 | [diff] [blame] | 5225 | if (!allowed && !task.isActivityTypeHome() && task.effectiveUid != callingUid) { |
Winson Chung | 61c9e5a | 2017-10-11 10:39:32 -0700 | [diff] [blame] | 5226 | // Skip if the caller can't fetch this task |
Dianne Hackborn | 0923328 | 2014-04-30 11:33:59 -0700 | [diff] [blame] | 5227 | continue; |
| 5228 | } |
Winson Chung | 61c9e5a | 2017-10-11 10:39:32 -0700 | [diff] [blame] | 5229 | if (ignoreActivityType != ACTIVITY_TYPE_UNDEFINED |
| 5230 | && task.getActivityType() == ignoreActivityType) { |
| 5231 | // Skip ignored activity type |
| 5232 | continue; |
Craig Mautner | aab647e | 2013-02-28 16:31:36 -0800 | [diff] [blame] | 5233 | } |
Winson Chung | 61c9e5a | 2017-10-11 10:39:32 -0700 | [diff] [blame] | 5234 | if (ignoreWindowingMode != WINDOWING_MODE_UNDEFINED |
| 5235 | && task.getWindowingMode() == ignoreWindowingMode) { |
| 5236 | // Skip ignored windowing mode |
| 5237 | continue; |
| 5238 | } |
riddle_hsu | ddc7415 | 2015-04-07 11:30:09 +0800 | [diff] [blame] | 5239 | if (focusedStack && topTask) { |
Winson Chung | 61c9e5a | 2017-10-11 10:39:32 -0700 | [diff] [blame] | 5240 | // For the focused stack top task, update the last stack active time so that it can |
| 5241 | // be used to determine the order of the tasks (it may not be set for newly created |
| 5242 | // tasks) |
| 5243 | task.lastActiveTime = SystemClock.elapsedRealtime(); |
riddle_hsu | ddc7415 | 2015-04-07 11:30:09 +0800 | [diff] [blame] | 5244 | topTask = false; |
| 5245 | } |
Winson Chung | 61c9e5a | 2017-10-11 10:39:32 -0700 | [diff] [blame] | 5246 | tasksOut.add(task); |
Craig Mautner | cae015f | 2013-02-08 14:31:27 -0800 | [diff] [blame] | 5247 | } |
Craig Mautner | cae015f | 2013-02-08 14:31:27 -0800 | [diff] [blame] | 5248 | } |
| 5249 | |
Andrii Kulian | 21713ac | 2016-10-12 22:05:05 -0700 | [diff] [blame] | 5250 | void unhandledBackLocked() { |
Craig Mautner | aab647e | 2013-02-28 16:31:36 -0800 | [diff] [blame] | 5251 | final int top = mTaskHistory.size() - 1; |
Wale Ogunwale | ee006da | 2015-03-30 14:49:25 -0700 | [diff] [blame] | 5252 | 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] | 5253 | if (top >= 0) { |
| 5254 | final ArrayList<ActivityRecord> activities = mTaskHistory.get(top).mActivities; |
| 5255 | int activityTop = activities.size() - 1; |
Dianne Hackborn | 354736e | 2016-08-22 17:00:05 -0700 | [diff] [blame] | 5256 | if (activityTop >= 0) { |
Wale Ogunwale | 586a8ee | 2019-06-04 13:44:14 +0000 | [diff] [blame] | 5257 | finishActivityLocked(activities.get(activityTop), Activity.RESULT_CANCELED, null, |
| 5258 | "unhandled-back", true); |
Craig Mautner | aab647e | 2013-02-28 16:31:36 -0800 | [diff] [blame] | 5259 | } |
Craig Mautner | cae015f | 2013-02-08 14:31:27 -0800 | [diff] [blame] | 5260 | } |
| 5261 | } |
| 5262 | |
Craig Mautner | 6b74cb5 | 2013-09-27 17:02:21 -0700 | [diff] [blame] | 5263 | /** |
| 5264 | * Reset local parameters because an app's activity died. |
| 5265 | * @param app The app of the activity that died. |
Craig Mautner | 1909125 | 2013-10-05 00:03:53 -0700 | [diff] [blame] | 5266 | * @return result from removeHistoryRecordsForAppLocked. |
Craig Mautner | 6b74cb5 | 2013-09-27 17:02:21 -0700 | [diff] [blame] | 5267 | */ |
Wale Ogunwale | 9e4f3e0 | 2018-05-17 09:35:39 -0700 | [diff] [blame] | 5268 | boolean handleAppDiedLocked(WindowProcessController app) { |
Craig Mautner | e79d4268 | 2013-04-01 19:01:53 -0700 | [diff] [blame] | 5269 | if (mPausingActivity != null && mPausingActivity.app == app) { |
Wale Ogunwale | ee006da | 2015-03-30 14:49:25 -0700 | [diff] [blame] | 5270 | if (DEBUG_PAUSE || DEBUG_CLEANUP) Slog.v(TAG_PAUSE, |
Craig Mautner | e79d4268 | 2013-04-01 19:01:53 -0700 | [diff] [blame] | 5271 | "App died while pausing: " + mPausingActivity); |
| 5272 | mPausingActivity = null; |
| 5273 | } |
| 5274 | if (mLastPausedActivity != null && mLastPausedActivity.app == app) { |
| 5275 | mLastPausedActivity = null; |
Craig Mautner | 0f92274 | 2013-08-06 08:44:42 -0700 | [diff] [blame] | 5276 | mLastNoHistoryActivity = null; |
Craig Mautner | e79d4268 | 2013-04-01 19:01:53 -0700 | [diff] [blame] | 5277 | } |
| 5278 | |
Craig Mautner | 1909125 | 2013-10-05 00:03:53 -0700 | [diff] [blame] | 5279 | return removeHistoryRecordsForAppLocked(app); |
Craig Mautner | e79d4268 | 2013-04-01 19:01:53 -0700 | [diff] [blame] | 5280 | } |
| 5281 | |
Wale Ogunwale | d32da47 | 2018-11-16 07:19:28 -0800 | [diff] [blame] | 5282 | void handleAppCrash(WindowProcessController app) { |
Craig Mautner | d44711d | 2013-02-23 11:24:36 -0800 | [diff] [blame] | 5283 | for (int taskNdx = mTaskHistory.size() - 1; taskNdx >= 0; --taskNdx) { |
| 5284 | final ArrayList<ActivityRecord> activities = mTaskHistory.get(taskNdx).mActivities; |
| 5285 | for (int activityNdx = activities.size() - 1; activityNdx >= 0; --activityNdx) { |
| 5286 | final ActivityRecord r = activities.get(activityNdx); |
| 5287 | if (r.app == app) { |
| 5288 | Slog.w(TAG, " Force finishing activity " |
| 5289 | + r.intent.getComponent().flattenToShortString()); |
Craig Mautner | 8e5b133 | 2014-07-24 13:32:37 -0700 | [diff] [blame] | 5290 | // Force the destroy to skip right to removal. |
| 5291 | r.app = null; |
Wale Ogunwale | 3a256e6 | 2018-12-06 14:41:18 -0800 | [diff] [blame] | 5292 | getDisplay().mDisplayContent.prepareAppTransition( |
lumark | 588a3e8 | 2018-07-20 18:53:54 +0800 | [diff] [blame] | 5293 | TRANSIT_CRASHING_ACTIVITY_CLOSE, false /* alwaysKeepCurrent */); |
Bryce Lee | f52974c | 2018-02-14 15:12:01 -0800 | [diff] [blame] | 5294 | finishCurrentActivityLocked(r, FINISH_IMMEDIATELY, false, |
| 5295 | "handleAppCrashedLocked"); |
Craig Mautner | d44711d | 2013-02-23 11:24:36 -0800 | [diff] [blame] | 5296 | } |
Craig Mautner | cae015f | 2013-02-08 14:31:27 -0800 | [diff] [blame] | 5297 | } |
| 5298 | } |
| 5299 | } |
| 5300 | |
Garfield Tan | 347bd60 | 2018-12-21 15:11:12 -0800 | [diff] [blame] | 5301 | boolean dump(FileDescriptor fd, PrintWriter pw, boolean dumpAll, boolean dumpClient, |
| 5302 | String dumpPackage, boolean needSep) { |
| 5303 | pw.println(" Stack #" + mStackId |
| 5304 | + ": type=" + activityTypeToString(getActivityType()) |
| 5305 | + " mode=" + windowingModeToString(getWindowingMode())); |
| 5306 | pw.println(" isSleeping=" + shouldSleepActivities()); |
| 5307 | pw.println(" mBounds=" + getRequestedOverrideBounds()); |
| 5308 | |
| 5309 | boolean printed = dumpActivitiesLocked(fd, pw, dumpAll, dumpClient, dumpPackage, |
| 5310 | needSep); |
| 5311 | |
| 5312 | printed |= dumpHistoryList(fd, pw, mLRUActivities, " ", "Run", false, |
| 5313 | !dumpAll, false, dumpPackage, true, |
| 5314 | " Running activities (most recent first):", null); |
| 5315 | |
| 5316 | needSep = printed; |
| 5317 | boolean pr = printThisActivity(pw, mPausingActivity, dumpPackage, needSep, |
| 5318 | " mPausingActivity: "); |
| 5319 | if (pr) { |
| 5320 | printed = true; |
| 5321 | needSep = false; |
| 5322 | } |
| 5323 | pr = printThisActivity(pw, getResumedActivity(), dumpPackage, needSep, |
| 5324 | " mResumedActivity: "); |
| 5325 | if (pr) { |
| 5326 | printed = true; |
| 5327 | needSep = false; |
| 5328 | } |
| 5329 | if (dumpAll) { |
| 5330 | pr = printThisActivity(pw, mLastPausedActivity, dumpPackage, needSep, |
| 5331 | " mLastPausedActivity: "); |
| 5332 | if (pr) { |
| 5333 | printed = true; |
| 5334 | needSep = true; |
| 5335 | } |
| 5336 | printed |= printThisActivity(pw, mLastNoHistoryActivity, dumpPackage, |
| 5337 | needSep, " mLastNoHistoryActivity: "); |
| 5338 | } |
| 5339 | return printed; |
| 5340 | } |
| 5341 | |
Dianne Hackborn | 390517b | 2013-05-30 15:03:32 -0700 | [diff] [blame] | 5342 | boolean dumpActivitiesLocked(FileDescriptor fd, PrintWriter pw, boolean dumpAll, |
Wale Ogunwale | 34a5b57 | 2017-08-31 08:29:41 -0700 | [diff] [blame] | 5343 | boolean dumpClient, String dumpPackage, boolean needSep) { |
| 5344 | |
| 5345 | if (mTaskHistory.isEmpty()) { |
| 5346 | return false; |
| 5347 | } |
| 5348 | final String prefix = " "; |
Craig Mautner | aab647e | 2013-02-28 16:31:36 -0800 | [diff] [blame] | 5349 | for (int taskNdx = mTaskHistory.size() - 1; taskNdx >= 0; --taskNdx) { |
| 5350 | final TaskRecord task = mTaskHistory.get(taskNdx); |
Wale Ogunwale | 34a5b57 | 2017-08-31 08:29:41 -0700 | [diff] [blame] | 5351 | if (needSep) { |
| 5352 | pw.println(""); |
Dianne Hackborn | 7ad34e5 | 2013-06-05 18:41:45 -0700 | [diff] [blame] | 5353 | } |
Wale Ogunwale | 34a5b57 | 2017-08-31 08:29:41 -0700 | [diff] [blame] | 5354 | pw.println(prefix + "Task id #" + task.taskId); |
Evan Rosky | dfe3da7 | 2018-10-26 17:21:06 -0700 | [diff] [blame] | 5355 | pw.println(prefix + "mBounds=" + task.getRequestedOverrideBounds()); |
Wale Ogunwale | 34a5b57 | 2017-08-31 08:29:41 -0700 | [diff] [blame] | 5356 | pw.println(prefix + "mMinWidth=" + task.mMinWidth); |
| 5357 | pw.println(prefix + "mMinHeight=" + task.mMinHeight); |
| 5358 | pw.println(prefix + "mLastNonFullscreenBounds=" + task.mLastNonFullscreenBounds); |
| 5359 | pw.println(prefix + "* " + task); |
| 5360 | task.dump(pw, prefix + " "); |
Garfield Tan | 347bd60 | 2018-12-21 15:11:12 -0800 | [diff] [blame] | 5361 | dumpHistoryList(fd, pw, mTaskHistory.get(taskNdx).mActivities, |
Wale Ogunwale | 34a5b57 | 2017-08-31 08:29:41 -0700 | [diff] [blame] | 5362 | prefix, "Hist", true, !dumpAll, dumpClient, dumpPackage, false, null, task); |
Craig Mautner | aab647e | 2013-02-28 16:31:36 -0800 | [diff] [blame] | 5363 | } |
Wale Ogunwale | 34a5b57 | 2017-08-31 08:29:41 -0700 | [diff] [blame] | 5364 | return true; |
Craig Mautner | cae015f | 2013-02-08 14:31:27 -0800 | [diff] [blame] | 5365 | } |
| 5366 | |
| 5367 | ArrayList<ActivityRecord> getDumpActivitiesLocked(String name) { |
Winson Chung | 6998bc4 | 2017-02-28 17:07:05 -0800 | [diff] [blame] | 5368 | ArrayList<ActivityRecord> activities = new ArrayList<>(); |
Craig Mautner | cae015f | 2013-02-08 14:31:27 -0800 | [diff] [blame] | 5369 | |
| 5370 | if ("all".equals(name)) { |
Craig Mautner | aab647e | 2013-02-28 16:31:36 -0800 | [diff] [blame] | 5371 | for (int taskNdx = mTaskHistory.size() - 1; taskNdx >= 0; --taskNdx) { |
| 5372 | activities.addAll(mTaskHistory.get(taskNdx).mActivities); |
Craig Mautner | cae015f | 2013-02-08 14:31:27 -0800 | [diff] [blame] | 5373 | } |
| 5374 | } else if ("top".equals(name)) { |
Craig Mautner | aab647e | 2013-02-28 16:31:36 -0800 | [diff] [blame] | 5375 | final int top = mTaskHistory.size() - 1; |
| 5376 | if (top >= 0) { |
| 5377 | final ArrayList<ActivityRecord> list = mTaskHistory.get(top).mActivities; |
| 5378 | int listTop = list.size() - 1; |
| 5379 | if (listTop >= 0) { |
| 5380 | activities.add(list.get(listTop)); |
| 5381 | } |
Craig Mautner | cae015f | 2013-02-08 14:31:27 -0800 | [diff] [blame] | 5382 | } |
| 5383 | } else { |
| 5384 | ItemMatcher matcher = new ItemMatcher(); |
| 5385 | matcher.build(name); |
| 5386 | |
Craig Mautner | aab647e | 2013-02-28 16:31:36 -0800 | [diff] [blame] | 5387 | for (int taskNdx = mTaskHistory.size() - 1; taskNdx >= 0; --taskNdx) { |
| 5388 | for (ActivityRecord r1 : mTaskHistory.get(taskNdx).mActivities) { |
| 5389 | if (matcher.match(r1, r1.intent.getComponent())) { |
| 5390 | activities.add(r1); |
| 5391 | } |
Craig Mautner | cae015f | 2013-02-08 14:31:27 -0800 | [diff] [blame] | 5392 | } |
| 5393 | } |
| 5394 | } |
| 5395 | |
| 5396 | return activities; |
| 5397 | } |
| 5398 | |
| 5399 | ActivityRecord restartPackage(String packageName) { |
Filip Gruszczynski | 3e85ba2 | 2015-10-05 22:48:30 -0700 | [diff] [blame] | 5400 | ActivityRecord starting = topRunningActivityLocked(); |
Craig Mautner | cae015f | 2013-02-08 14:31:27 -0800 | [diff] [blame] | 5401 | |
| 5402 | // All activities that came from the package must be |
| 5403 | // restarted as if there was a config change. |
Craig Mautner | aab647e | 2013-02-28 16:31:36 -0800 | [diff] [blame] | 5404 | for (int taskNdx = mTaskHistory.size() - 1; taskNdx >= 0; --taskNdx) { |
| 5405 | final ArrayList<ActivityRecord> activities = mTaskHistory.get(taskNdx).mActivities; |
| 5406 | for (int activityNdx = activities.size() - 1; activityNdx >= 0; --activityNdx) { |
| 5407 | final ActivityRecord a = activities.get(activityNdx); |
| 5408 | if (a.info.packageName.equals(packageName)) { |
| 5409 | a.forceNewConfig = true; |
| 5410 | if (starting != null && a == starting && a.visible) { |
| 5411 | a.startFreezingScreenLocked(starting.app, |
Filip Gruszczynski | 3c2db1d1 | 2016-01-06 17:39:14 -0800 | [diff] [blame] | 5412 | CONFIG_SCREEN_LAYOUT); |
Craig Mautner | aab647e | 2013-02-28 16:31:36 -0800 | [diff] [blame] | 5413 | } |
Craig Mautner | cae015f | 2013-02-08 14:31:27 -0800 | [diff] [blame] | 5414 | } |
| 5415 | } |
| 5416 | } |
| 5417 | |
| 5418 | return starting; |
| 5419 | } |
Craig Mautner | 5d9c7be | 2013-02-15 14:02:56 -0800 | [diff] [blame] | 5420 | |
Wale Ogunwale | 000957c | 2015-04-03 08:19:12 -0700 | [diff] [blame] | 5421 | /** |
| 5422 | * Removes the input task from this stack. |
Garfield Tan | 891146c | 2018-10-09 12:14:00 -0700 | [diff] [blame] | 5423 | * |
Wale Ogunwale | 000957c | 2015-04-03 08:19:12 -0700 | [diff] [blame] | 5424 | * @param task to remove. |
| 5425 | * @param reason for removal. |
Wale Ogunwale | 06579d6 | 2016-04-30 15:29:06 -0700 | [diff] [blame] | 5426 | * @param mode task removal mode. Either {@link #REMOVE_TASK_MODE_DESTROYING}, |
| 5427 | * {@link #REMOVE_TASK_MODE_MOVING}, {@link #REMOVE_TASK_MODE_MOVING_TO_TOP}. |
Wale Ogunwale | 000957c | 2015-04-03 08:19:12 -0700 | [diff] [blame] | 5428 | */ |
Wale Ogunwale | 06579d6 | 2016-04-30 15:29:06 -0700 | [diff] [blame] | 5429 | void removeTask(TaskRecord task, String reason, int mode) { |
Bryce Lee | 2b8e037 | 2018-04-05 17:01:37 -0700 | [diff] [blame] | 5430 | final boolean removed = mTaskHistory.remove(task); |
| 5431 | |
| 5432 | if (removed) { |
| 5433 | EventLog.writeEvent(EventLogTags.AM_REMOVE_TASK, task.taskId, getStackId()); |
| 5434 | } |
| 5435 | |
Winson Chung | abb433b | 2017-03-24 09:35:42 -0700 | [diff] [blame] | 5436 | removeActivitiesFromLRUListLocked(task); |
Craig Mautner | 21d24a2 | 2014-04-23 11:45:37 -0700 | [diff] [blame] | 5437 | updateTaskMovement(task, true); |
Craig Mautner | 41db4a7 | 2014-05-07 17:20:56 -0700 | [diff] [blame] | 5438 | |
Garfield Tan | 347bd60 | 2018-12-21 15:11:12 -0800 | [diff] [blame] | 5439 | if (mode == REMOVE_TASK_MODE_DESTROYING) { |
| 5440 | task.cleanUpResourcesForDestroy(); |
Dianne Hackborn | 91097de | 2014-04-04 18:02:06 -0700 | [diff] [blame] | 5441 | } |
Craig Mautner | 04a0ea6 | 2014-01-13 12:51:26 -0800 | [diff] [blame] | 5442 | |
| 5443 | if (mTaskHistory.isEmpty()) { |
Wale Ogunwale | ee006da | 2015-03-30 14:49:25 -0700 | [diff] [blame] | 5444 | if (DEBUG_STACK) Slog.i(TAG_STACK, "removeTask: removing stack=" + this); |
Wale Ogunwale | 06579d6 | 2016-04-30 15:29:06 -0700 | [diff] [blame] | 5445 | // We only need to adjust focused stack if this stack is in focus and we are not in the |
| 5446 | // 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] | 5447 | if (mode != REMOVE_TASK_MODE_MOVING_TO_TOP |
Wale Ogunwale | d32da47 | 2018-11-16 07:19:28 -0800 | [diff] [blame] | 5448 | && mRootActivityContainer.isTopDisplayFocusedStack(this)) { |
Wale Ogunwale | d697cea | 2015-02-20 17:19:49 -0800 | [diff] [blame] | 5449 | String myReason = reason + " leftTaskHistoryEmpty"; |
Andrii Kulian | ab132ee | 2018-07-24 22:10:21 +0800 | [diff] [blame] | 5450 | if (!inMultiWindowMode() || adjustFocusToNextFocusableStack(myReason) == null) { |
Louis Chang | bd48dca | 2018-08-29 17:44:34 +0800 | [diff] [blame] | 5451 | getDisplay().moveHomeStackToFront(myReason); |
Wale Ogunwale | d697cea | 2015-02-20 17:19:49 -0800 | [diff] [blame] | 5452 | } |
Craig Mautner | 04a0ea6 | 2014-01-13 12:51:26 -0800 | [diff] [blame] | 5453 | } |
Wale Ogunwale | 9dcf946 | 2017-09-19 15:13:01 -0700 | [diff] [blame] | 5454 | if (isAttached()) { |
| 5455 | getDisplay().positionChildAtBottom(this); |
Craig Mautner | 593a4e6 | 2014-01-15 17:55:51 -0800 | [diff] [blame] | 5456 | } |
Jeff Chang | a2ee83d | 2018-12-26 20:24:47 +0800 | [diff] [blame] | 5457 | if (!isActivityTypeHome() || !isAttached()) { |
Andrii Kulian | 94e82d9b0 | 2017-07-13 15:33:06 -0700 | [diff] [blame] | 5458 | remove(); |
Wale Ogunwale | 49853bf | 2015-02-23 09:24:42 -0800 | [diff] [blame] | 5459 | } |
Craig Mautner | 04a0ea6 | 2014-01-13 12:51:26 -0800 | [diff] [blame] | 5460 | } |
Wale Ogunwale | 04f4d6b | 2015-03-11 09:23:25 -0700 | [diff] [blame] | 5461 | |
Andrii Kulian | 02b7a83 | 2016-10-06 23:11:56 -0700 | [diff] [blame] | 5462 | task.setStack(null); |
Winson Chung | c81c0ce | 2017-03-17 12:27:30 -0700 | [diff] [blame] | 5463 | |
| 5464 | // 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] | 5465 | if (inPinnedWindowingMode()) { |
Wale Ogunwale | 5fa8a8c | 2018-05-08 13:43:21 -0700 | [diff] [blame] | 5466 | mService.getTaskChangeNotificationController().notifyActivityUnpinned(); |
Winson Chung | c81c0ce | 2017-03-17 12:27:30 -0700 | [diff] [blame] | 5467 | } |
Craig Mautner | 0247fc8 | 2013-02-28 14:32:06 -0800 | [diff] [blame] | 5468 | } |
| 5469 | |
Dianne Hackborn | 91097de | 2014-04-04 18:02:06 -0700 | [diff] [blame] | 5470 | TaskRecord createTaskRecord(int taskId, ActivityInfo info, Intent intent, |
| 5471 | IVoiceInteractionSession voiceSession, IVoiceInteractor voiceInteractor, |
Wale Ogunwale | 6fbde9f | 2017-08-24 07:24:12 -0700 | [diff] [blame] | 5472 | boolean toTop) { |
Bryce Lee | b802ea1 | 2017-11-15 21:25:03 -0800 | [diff] [blame] | 5473 | return createTaskRecord(taskId, info, intent, voiceSession, voiceInteractor, toTop, |
| 5474 | null /*activity*/, null /*source*/, null /*options*/); |
| 5475 | } |
| 5476 | |
| 5477 | TaskRecord createTaskRecord(int taskId, ActivityInfo info, Intent intent, |
| 5478 | IVoiceInteractionSession voiceSession, IVoiceInteractor voiceInteractor, |
| 5479 | boolean toTop, ActivityRecord activity, ActivityRecord source, |
| 5480 | ActivityOptions options) { |
Garfield Tan | 9b1efea | 2017-12-05 16:43:46 -0800 | [diff] [blame] | 5481 | final TaskRecord task = TaskRecord.create( |
Wale Ogunwale | 5fa8a8c | 2018-05-08 13:43:21 -0700 | [diff] [blame] | 5482 | mService, taskId, info, intent, voiceSession, voiceInteractor); |
Chong Zhang | 0fa656b | 2015-08-31 15:17:21 -0700 | [diff] [blame] | 5483 | // add the task to stack first, mTaskPositioner might need the stack association |
Wale Ogunwale | 5f98609 | 2015-12-04 15:35:38 -0800 | [diff] [blame] | 5484 | addTask(task, toTop, "createTaskRecord"); |
Lucas Dupin | 47a65c7 | 2018-02-15 14:16:18 -0800 | [diff] [blame] | 5485 | final int displayId = mDisplayId != INVALID_DISPLAY ? mDisplayId : DEFAULT_DISPLAY; |
Bryce Lee | 2a3cc46 | 2017-10-27 10:57:35 -0700 | [diff] [blame] | 5486 | final boolean isLockscreenShown = mService.mStackSupervisor.getKeyguardController() |
Lucas Dupin | 47a65c7 | 2018-02-15 14:16:18 -0800 | [diff] [blame] | 5487 | .isKeyguardOrAodShowing(displayId); |
Bryce Lee | ec55eb0 | 2017-12-05 20:51:27 -0800 | [diff] [blame] | 5488 | if (!mStackSupervisor.getLaunchParamsController() |
Bryce Lee | b802ea1 | 2017-11-15 21:25:03 -0800 | [diff] [blame] | 5489 | .layoutTask(task, info.windowLayout, activity, source, options) |
Bryce Lee | f3c6a47 | 2017-11-14 14:53:06 -0800 | [diff] [blame] | 5490 | && !matchParentBounds() && task.isResizeable() && !isLockscreenShown) { |
Evan Rosky | dfe3da7 | 2018-10-26 17:21:06 -0700 | [diff] [blame] | 5491 | task.updateOverrideConfiguration(getRequestedOverrideBounds()); |
Filip Gruszczynski | e5390e7 | 2015-08-18 16:39:00 -0700 | [diff] [blame] | 5492 | } |
Yunfan Chen | 0e7aff9 | 2018-12-05 16:35:32 -0800 | [diff] [blame] | 5493 | task.createTask(toTop, (info.flags & FLAG_SHOW_FOR_ALL_USERS) != 0); |
Craig Mautner | 5d9c7be | 2013-02-15 14:02:56 -0800 | [diff] [blame] | 5494 | return task; |
| 5495 | } |
Craig Mautner | c00204b | 2013-03-05 15:02:14 -0800 | [diff] [blame] | 5496 | |
| 5497 | ArrayList<TaskRecord> getAllTasks() { |
Wale Ogunwale | 9d3de4c | 2015-02-01 16:49:44 -0800 | [diff] [blame] | 5498 | return new ArrayList<>(mTaskHistory); |
Craig Mautner | c00204b | 2013-03-05 15:02:14 -0800 | [diff] [blame] | 5499 | } |
| 5500 | |
Wale Ogunwale | 5f98609 | 2015-12-04 15:35:38 -0800 | [diff] [blame] | 5501 | void addTask(final TaskRecord task, final boolean toTop, String reason) { |
Winson Chung | 5af42fc | 2017-03-24 17:11:33 -0700 | [diff] [blame] | 5502 | addTask(task, toTop ? MAX_VALUE : 0, true /* schedulePictureInPictureModeChange */, reason); |
Wale Ogunwale | c5cc301 | 2017-01-13 13:26:16 -0800 | [diff] [blame] | 5503 | if (toTop) { |
| 5504 | // TODO: figure-out a way to remove this call. |
Riddle Hsu | 86cb7de | 2018-08-13 23:29:58 +0800 | [diff] [blame] | 5505 | positionChildWindowContainerAtTop(task); |
Wale Ogunwale | c5cc301 | 2017-01-13 13:26:16 -0800 | [diff] [blame] | 5506 | } |
Wale Ogunwale | e1fe7fa2 | 2016-12-15 18:27:00 -0800 | [diff] [blame] | 5507 | } |
| 5508 | |
Wale Ogunwale | c5cc301 | 2017-01-13 13:26:16 -0800 | [diff] [blame] | 5509 | // TODO: This shouldn't allow automatic reparenting. Remove the call to preAddTask and deal |
| 5510 | // with the fall-out... |
Winson Chung | 5af42fc | 2017-03-24 17:11:33 -0700 | [diff] [blame] | 5511 | void addTask(final TaskRecord task, int position, boolean schedulePictureInPictureModeChange, |
| 5512 | String reason) { |
Wale Ogunwale | c5cc301 | 2017-01-13 13:26:16 -0800 | [diff] [blame] | 5513 | // TODO: Is this remove really needed? Need to look into the call path for the other addTask |
| 5514 | mTaskHistory.remove(task); |
Wale Ogunwale | 9e737db | 2018-12-17 15:42:37 -0800 | [diff] [blame] | 5515 | if (isSingleTaskInstance() && !mTaskHistory.isEmpty()) { |
| 5516 | throw new IllegalStateException("Can only have one child on stack=" + this); |
| 5517 | } |
| 5518 | |
Wale Ogunwale | c5cc301 | 2017-01-13 13:26:16 -0800 | [diff] [blame] | 5519 | position = getAdjustedPositionForTask(task, position, null /* starting */); |
| 5520 | final boolean toTop = position >= mTaskHistory.size(); |
Wale Ogunwale | 06579d6 | 2016-04-30 15:29:06 -0700 | [diff] [blame] | 5521 | final ActivityStack prevStack = preAddTask(task, reason, toTop); |
Wale Ogunwale | 5f98609 | 2015-12-04 15:35:38 -0800 | [diff] [blame] | 5522 | |
Andrii Kulian | fb1bf69 | 2017-01-17 11:17:34 -0800 | [diff] [blame] | 5523 | mTaskHistory.add(position, task); |
Andrii Kulian | 02b7a83 | 2016-10-06 23:11:56 -0700 | [diff] [blame] | 5524 | task.setStack(this); |
Wale Ogunwale | c5cc301 | 2017-01-13 13:26:16 -0800 | [diff] [blame] | 5525 | |
Wale Ogunwale | c5cc301 | 2017-01-13 13:26:16 -0800 | [diff] [blame] | 5526 | updateTaskMovement(task, toTop); |
| 5527 | |
Winson Chung | 5af42fc | 2017-03-24 17:11:33 -0700 | [diff] [blame] | 5528 | postAddTask(task, prevStack, schedulePictureInPictureModeChange); |
Craig Mautner | c00204b | 2013-03-05 15:02:14 -0800 | [diff] [blame] | 5529 | } |
| 5530 | |
Wale Ogunwale | c5cc301 | 2017-01-13 13:26:16 -0800 | [diff] [blame] | 5531 | void positionChildAt(TaskRecord task, int index) { |
| 5532 | |
| 5533 | if (task.getStack() != this) { |
| 5534 | throw new IllegalArgumentException("AS.positionChildAt: task=" + task |
| 5535 | + " is not a child of stack=" + this + " current parent=" + task.getStack()); |
Wale Ogunwale | e1fe7fa2 | 2016-12-15 18:27:00 -0800 | [diff] [blame] | 5536 | } |
| 5537 | |
| 5538 | task.updateOverrideConfigurationForStack(this); |
| 5539 | |
Jorim Jaggi | 023da53 | 2016-04-20 22:42:32 -0700 | [diff] [blame] | 5540 | final ActivityRecord topRunningActivity = task.topRunningActivityLocked(); |
Andrii Kulian | 02b7a83 | 2016-10-06 23:11:56 -0700 | [diff] [blame] | 5541 | final boolean wasResumed = topRunningActivity == task.getStack().mResumedActivity; |
Wale Ogunwale | e1fe7fa2 | 2016-12-15 18:27:00 -0800 | [diff] [blame] | 5542 | insertTaskAtPosition(task, index); |
Andrii Kulian | fb1bf69 | 2017-01-17 11:17:34 -0800 | [diff] [blame] | 5543 | task.setStack(this); |
Winson Chung | 5af42fc | 2017-03-24 17:11:33 -0700 | [diff] [blame] | 5544 | postAddTask(task, null /* prevStack */, true /* schedulePictureInPictureModeChange */); |
Wale Ogunwale | c5cc301 | 2017-01-13 13:26:16 -0800 | [diff] [blame] | 5545 | |
Jorim Jaggi | 023da53 | 2016-04-20 22:42:32 -0700 | [diff] [blame] | 5546 | if (wasResumed) { |
| 5547 | if (mResumedActivity != null) { |
| 5548 | Log.wtf(TAG, "mResumedActivity was already set when moving mResumedActivity from" |
| 5549 | + " other stack to this stack mResumedActivity=" + mResumedActivity |
| 5550 | + " other mResumedActivity=" + topRunningActivity); |
| 5551 | } |
Bryce Lee | c4ab62a | 2018-03-05 14:19:26 -0800 | [diff] [blame] | 5552 | topRunningActivity.setState(RESUMED, "positionChildAt"); |
Jorim Jaggi | 023da53 | 2016-04-20 22:42:32 -0700 | [diff] [blame] | 5553 | } |
Wale Ogunwale | e1fe7fa2 | 2016-12-15 18:27:00 -0800 | [diff] [blame] | 5554 | |
| 5555 | // The task might have already been running and its visibility needs to be synchronized with |
| 5556 | // the visibility of the stack / windows. |
| 5557 | ensureActivitiesVisibleLocked(null, 0, !PRESERVE_WINDOWS); |
Wale Ogunwale | d32da47 | 2018-11-16 07:19:28 -0800 | [diff] [blame] | 5558 | mRootActivityContainer.resumeFocusedStacksTopActivities(); |
Wale Ogunwale | 5f98609 | 2015-12-04 15:35:38 -0800 | [diff] [blame] | 5559 | } |
| 5560 | |
Wale Ogunwale | 06579d6 | 2016-04-30 15:29:06 -0700 | [diff] [blame] | 5561 | private ActivityStack preAddTask(TaskRecord task, String reason, boolean toTop) { |
Andrii Kulian | 02b7a83 | 2016-10-06 23:11:56 -0700 | [diff] [blame] | 5562 | final ActivityStack prevStack = task.getStack(); |
Wale Ogunwale | 5f98609 | 2015-12-04 15:35:38 -0800 | [diff] [blame] | 5563 | if (prevStack != null && prevStack != this) { |
Wale Ogunwale | 06579d6 | 2016-04-30 15:29:06 -0700 | [diff] [blame] | 5564 | prevStack.removeTask(task, reason, |
| 5565 | toTop ? REMOVE_TASK_MODE_MOVING_TO_TOP : REMOVE_TASK_MODE_MOVING); |
Wale Ogunwale | 5f98609 | 2015-12-04 15:35:38 -0800 | [diff] [blame] | 5566 | } |
| 5567 | return prevStack; |
| 5568 | } |
| 5569 | |
Winson Chung | 5af42fc | 2017-03-24 17:11:33 -0700 | [diff] [blame] | 5570 | /** |
| 5571 | * @param schedulePictureInPictureModeChange specifies whether or not to schedule the PiP mode |
| 5572 | * change. Callers may set this to false if they are explicitly scheduling PiP mode |
| 5573 | * changes themselves, like during the PiP animation |
| 5574 | */ |
| 5575 | private void postAddTask(TaskRecord task, ActivityStack prevStack, |
| 5576 | boolean schedulePictureInPictureModeChange) { |
| 5577 | if (schedulePictureInPictureModeChange && prevStack != null) { |
| 5578 | mStackSupervisor.scheduleUpdatePictureInPictureModeIfNeeded(task, prevStack); |
Wale Ogunwale | 5f98609 | 2015-12-04 15:35:38 -0800 | [diff] [blame] | 5579 | } else if (task.voiceSession != null) { |
Wale Ogunwale | ddc1cb2 | 2015-07-25 19:23:04 -0700 | [diff] [blame] | 5580 | try { |
| 5581 | task.voiceSession.taskStarted(task.intent, task.taskId); |
| 5582 | } catch (RemoteException e) { |
| 5583 | } |
| 5584 | } |
| 5585 | } |
| 5586 | |
Kazuki Takise | f85197b | 2018-06-18 18:18:36 +0900 | [diff] [blame] | 5587 | public void setAlwaysOnTop(boolean alwaysOnTop) { |
| 5588 | if (isAlwaysOnTop() == alwaysOnTop) { |
| 5589 | return; |
| 5590 | } |
| 5591 | super.setAlwaysOnTop(alwaysOnTop); |
| 5592 | final ActivityDisplay display = getDisplay(); |
| 5593 | // positionChildAtTop() must be called even when always on top gets turned off because we |
| 5594 | // need to make sure that the stack is moved from among always on top windows to below other |
| 5595 | // always on top windows. Since the position the stack should be inserted into is calculated |
| 5596 | // properly in {@link ActivityDisplay#getTopInsertPosition()} in both cases, we can just |
| 5597 | // request that the stack is put at top here. |
Riddle Hsu | 57831b5 | 2018-07-27 00:31:48 +0800 | [diff] [blame] | 5598 | display.positionChildAtTop(this, false /* includingParents */); |
Kazuki Takise | f85197b | 2018-06-18 18:18:36 +0900 | [diff] [blame] | 5599 | } |
| 5600 | |
Riddle Hsu | 1656713 | 2018-08-16 21:37:47 +0800 | [diff] [blame] | 5601 | /** NOTE: Should only be called from {@link TaskRecord#reparent}. */ |
Winson Chung | c2baac0 | 2017-01-11 13:34:47 -0800 | [diff] [blame] | 5602 | void moveToFrontAndResumeStateIfNeeded(ActivityRecord r, boolean moveToFront, boolean setResume, |
| 5603 | boolean setPause, String reason) { |
Wale Ogunwale | d046a01 | 2015-12-24 13:05:59 -0800 | [diff] [blame] | 5604 | if (!moveToFront) { |
| 5605 | return; |
Wale Ogunwale | 079a004 | 2015-10-24 11:44:07 -0700 | [diff] [blame] | 5606 | } |
Wale Ogunwale | d046a01 | 2015-12-24 13:05:59 -0800 | [diff] [blame] | 5607 | |
Riddle Hsu | 1656713 | 2018-08-16 21:37:47 +0800 | [diff] [blame] | 5608 | final ActivityState origState = r.getState(); |
Wale Ogunwale | d046a01 | 2015-12-24 13:05:59 -0800 | [diff] [blame] | 5609 | // If the activity owns the last resumed activity, transfer that together, |
| 5610 | // so that we don't resume the same activity again in the new stack. |
| 5611 | // Apps may depend on onResume()/onPause() being called in pairs. |
| 5612 | if (setResume) { |
Bryce Lee | c4ab62a | 2018-03-05 14:19:26 -0800 | [diff] [blame] | 5613 | r.setState(RESUMED, "moveToFrontAndResumeStateIfNeeded"); |
Winson Chung | abb433b | 2017-03-24 09:35:42 -0700 | [diff] [blame] | 5614 | updateLRUListLocked(r); |
Wale Ogunwale | d046a01 | 2015-12-24 13:05:59 -0800 | [diff] [blame] | 5615 | } |
Winson Chung | c2baac0 | 2017-01-11 13:34:47 -0800 | [diff] [blame] | 5616 | // If the activity was previously pausing, then ensure we transfer that as well |
| 5617 | if (setPause) { |
| 5618 | mPausingActivity = r; |
Winson Chung | 4dabf23 | 2017-01-25 13:25:22 -0800 | [diff] [blame] | 5619 | schedulePauseTimeout(r); |
Winson Chung | c2baac0 | 2017-01-11 13:34:47 -0800 | [diff] [blame] | 5620 | } |
Riddle Hsu | 1656713 | 2018-08-16 21:37:47 +0800 | [diff] [blame] | 5621 | // 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] | 5622 | moveToFront(reason); |
Riddle Hsu | 1656713 | 2018-08-16 21:37:47 +0800 | [diff] [blame] | 5623 | // If the original state is resumed, there is no state change to update focused app. |
| 5624 | // 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] | 5625 | if (origState == RESUMED && r == mRootActivityContainer.getTopResumedActivity()) { |
Riddle Hsu | 1656713 | 2018-08-16 21:37:47 +0800 | [diff] [blame] | 5626 | // TODO(b/111361570): Support multiple focused apps in WM |
| 5627 | mService.setResumedActivityUncheckLocked(r, reason); |
| 5628 | } |
Wale Ogunwale | 079a004 | 2015-10-24 11:44:07 -0700 | [diff] [blame] | 5629 | } |
| 5630 | |
Yunfan Chen | 279f558 | 2018-12-12 15:24:50 -0800 | [diff] [blame] | 5631 | |
| 5632 | Rect getDefaultPictureInPictureBounds(float aspectRatio) { |
| 5633 | if (getTaskStack() == null) return null; |
| 5634 | return getTaskStack().getPictureInPictureBounds(aspectRatio, null /* currentStackBounds */); |
| 5635 | } |
| 5636 | |
| 5637 | void animateResizePinnedStack(Rect sourceHintBounds, Rect toBounds, int animationDuration, |
| 5638 | boolean fromFullscreen) { |
| 5639 | if (!inPinnedWindowingMode()) return; |
| 5640 | if (skipResizeAnimation(toBounds == null /* toFullscreen */)) { |
| 5641 | mService.moveTasksToFullscreenStack(mStackId, true /* onTop */); |
| 5642 | } else { |
| 5643 | if (getTaskStack() == null) return; |
| 5644 | getTaskStack().animateResizePinnedStack(toBounds, sourceHintBounds, |
| 5645 | animationDuration, fromFullscreen); |
| 5646 | } |
| 5647 | } |
| 5648 | |
wilsonshih | 5c4cf52 | 2019-01-25 09:03:47 +0800 | [diff] [blame] | 5649 | /** |
| 5650 | * Get current bounds of this stack, return empty when it is unavailable. |
| 5651 | * @see TaskStack#getAnimationOrCurrentBounds(Rect) |
| 5652 | */ |
| 5653 | void getAnimationOrCurrentBounds(Rect outBounds) { |
| 5654 | final TaskStack stack = getTaskStack(); |
| 5655 | if (stack == null) { |
| 5656 | outBounds.setEmpty(); |
| 5657 | return; |
| 5658 | } |
| 5659 | stack.getAnimationOrCurrentBounds(outBounds); |
| 5660 | } |
| 5661 | |
Yunfan Chen | 279f558 | 2018-12-12 15:24:50 -0800 | [diff] [blame] | 5662 | private boolean skipResizeAnimation(boolean toFullscreen) { |
| 5663 | if (!toFullscreen) { |
| 5664 | return false; |
| 5665 | } |
| 5666 | final Configuration parentConfig = getParent().getConfiguration(); |
| 5667 | final ActivityRecord top = topRunningNonOverlayTaskActivity(); |
| 5668 | return top != null && !top.isConfigurationCompatible(parentConfig); |
| 5669 | } |
| 5670 | |
| 5671 | void setPictureInPictureAspectRatio(float aspectRatio) { |
| 5672 | if (getTaskStack() == null) return; |
| 5673 | getTaskStack().setPictureInPictureAspectRatio(aspectRatio); |
| 5674 | } |
| 5675 | |
| 5676 | void setPictureInPictureActions(List<RemoteAction> actions) { |
| 5677 | if (getTaskStack() == null) return; |
| 5678 | getTaskStack().setPictureInPictureActions(actions); |
| 5679 | } |
| 5680 | |
| 5681 | boolean isAnimatingBoundsToFullscreen() { |
| 5682 | if (getTaskStack() == null) return false; |
| 5683 | return getTaskStack().isAnimatingBoundsToFullscreen(); |
| 5684 | } |
| 5685 | |
| 5686 | public void updatePictureInPictureModeForPinnedStackAnimation(Rect targetStackBounds, |
| 5687 | boolean forceUpdate) { |
| 5688 | // It is guaranteed that the activities requiring the update will be in the pinned stack at |
| 5689 | // this point (either reparented before the animation into PiP, or before reparenting after |
| 5690 | // the animation out of PiP) |
| 5691 | synchronized (mService.mGlobalLock) { |
| 5692 | if (!isAttached()) { |
| 5693 | return; |
| 5694 | } |
| 5695 | ArrayList<TaskRecord> tasks = getAllTasks(); |
| 5696 | for (int i = 0; i < tasks.size(); i++) { |
| 5697 | mStackSupervisor.updatePictureInPictureMode(tasks.get(i), targetStackBounds, |
| 5698 | forceUpdate); |
| 5699 | } |
| 5700 | } |
| 5701 | } |
| 5702 | |
Craig Mautner | c00204b | 2013-03-05 15:02:14 -0800 | [diff] [blame] | 5703 | public int getStackId() { |
| 5704 | return mStackId; |
| 5705 | } |
Craig Mautner | de4ef02 | 2013-04-07 19:01:33 -0700 | [diff] [blame] | 5706 | |
| 5707 | @Override |
| 5708 | public String toString() { |
Dianne Hackborn | 2a272d4 | 2013-10-16 13:34:33 -0700 | [diff] [blame] | 5709 | return "ActivityStack{" + Integer.toHexString(System.identityHashCode(this)) |
Wale Ogunwale | 44f036f | 2017-09-29 05:09:09 -0700 | [diff] [blame] | 5710 | + " stackId=" + mStackId + " type=" + activityTypeToString(getActivityType()) |
Wale Ogunwale | 7e1f5f5 | 2017-10-18 15:19:59 -0700 | [diff] [blame] | 5711 | + " mode=" + windowingModeToString(getWindowingMode()) |
Wale Ogunwale | 8e923af | 2018-03-23 08:48:11 -0700 | [diff] [blame] | 5712 | + " visible=" + shouldBeVisible(null /* starting */) |
| 5713 | + " translucent=" + isStackTranslucent(null /* starting */) |
| 5714 | + ", " |
Wale Ogunwale | 44f036f | 2017-09-29 05:09:09 -0700 | [diff] [blame] | 5715 | + mTaskHistory.size() + " tasks}"; |
Craig Mautner | de4ef02 | 2013-04-07 19:01:33 -0700 | [diff] [blame] | 5716 | } |
Wale Ogunwale | 60454db | 2015-01-23 16:05:07 -0800 | [diff] [blame] | 5717 | |
Wale Ogunwale | a0f5b5e | 2017-10-11 09:37:23 -0700 | [diff] [blame] | 5718 | void onLockTaskPackagesUpdated() { |
Craig Mautner | 15df08a | 2015-04-01 12:17:18 -0700 | [diff] [blame] | 5719 | for (int taskNdx = mTaskHistory.size() - 1; taskNdx >= 0; --taskNdx) { |
| 5720 | mTaskHistory.get(taskNdx).setLockTaskAuth(); |
| 5721 | } |
| 5722 | } |
skuhne@google.com | 1b974dc | 2016-12-09 13:41:29 -0800 | [diff] [blame] | 5723 | |
| 5724 | void executeAppTransition(ActivityOptions options) { |
Wale Ogunwale | 3a256e6 | 2018-12-06 14:41:18 -0800 | [diff] [blame] | 5725 | getDisplay().mDisplayContent.executeAppTransition(); |
skuhne@google.com | 1b974dc | 2016-12-09 13:41:29 -0800 | [diff] [blame] | 5726 | ActivityOptions.abort(options); |
| 5727 | } |
David Stevens | 9440dc8 | 2017-03-16 19:00:20 -0700 | [diff] [blame] | 5728 | |
| 5729 | boolean shouldSleepActivities() { |
Wale Ogunwale | 9dcf946 | 2017-09-19 15:13:01 -0700 | [diff] [blame] | 5730 | final ActivityDisplay display = getDisplay(); |
Bryce Lee | 271617a | 2018-03-15 10:39:12 -0700 | [diff] [blame] | 5731 | |
| 5732 | // Do not sleep activities in this stack if we're marked as focused and the keyguard |
| 5733 | // is in the process of going away. |
Tiger Huang | 1e5b10a | 2018-07-30 20:19:51 +0800 | [diff] [blame] | 5734 | if (isFocusedStackOnDisplay() |
Bryce Lee | 271617a | 2018-03-15 10:39:12 -0700 | [diff] [blame] | 5735 | && mStackSupervisor.getKeyguardController().isKeyguardGoingAway()) { |
| 5736 | return false; |
| 5737 | } |
| 5738 | |
Wale Ogunwale | f673393 | 2018-06-27 05:14:34 -0700 | [diff] [blame] | 5739 | return display != null ? display.isSleeping() : mService.isSleepingLocked(); |
David Stevens | 9440dc8 | 2017-03-16 19:00:20 -0700 | [diff] [blame] | 5740 | } |
| 5741 | |
| 5742 | boolean shouldSleepOrShutDownActivities() { |
Wale Ogunwale | f673393 | 2018-06-27 05:14:34 -0700 | [diff] [blame] | 5743 | return shouldSleepActivities() || mService.mShuttingDown; |
David Stevens | 9440dc8 | 2017-03-16 19:00:20 -0700 | [diff] [blame] | 5744 | } |
Steven Timotius | 4346f0a | 2017-09-12 11:07:21 -0700 | [diff] [blame] | 5745 | |
Nataniel Borges | 023ecb5 | 2019-01-16 14:15:43 -0800 | [diff] [blame] | 5746 | public void writeToProto(ProtoOutputStream proto, long fieldId, |
| 5747 | @WindowTraceLogLevel int logLevel) { |
Steven Timotius | 4346f0a | 2017-09-12 11:07:21 -0700 | [diff] [blame] | 5748 | final long token = proto.start(fieldId); |
Nataniel Borges | 023ecb5 | 2019-01-16 14:15:43 -0800 | [diff] [blame] | 5749 | super.writeToProto(proto, CONFIGURATION_CONTAINER, logLevel); |
Steven Timotius | 4346f0a | 2017-09-12 11:07:21 -0700 | [diff] [blame] | 5750 | proto.write(ID, mStackId); |
| 5751 | for (int taskNdx = mTaskHistory.size() - 1; taskNdx >= 0; --taskNdx) { |
| 5752 | final TaskRecord task = mTaskHistory.get(taskNdx); |
Nataniel Borges | 023ecb5 | 2019-01-16 14:15:43 -0800 | [diff] [blame] | 5753 | task.writeToProto(proto, TASKS, logLevel); |
Steven Timotius | 4346f0a | 2017-09-12 11:07:21 -0700 | [diff] [blame] | 5754 | } |
| 5755 | if (mResumedActivity != null) { |
| 5756 | mResumedActivity.writeIdentifierToProto(proto, RESUMED_ACTIVITY); |
| 5757 | } |
| 5758 | proto.write(DISPLAY_ID, mDisplayId); |
Bryce Lee | f3c6a47 | 2017-11-14 14:53:06 -0800 | [diff] [blame] | 5759 | if (!matchParentBounds()) { |
Evan Rosky | dfe3da7 | 2018-10-26 17:21:06 -0700 | [diff] [blame] | 5760 | final Rect bounds = getRequestedOverrideBounds(); |
Bryce Lee | f3c6a47 | 2017-11-14 14:53:06 -0800 | [diff] [blame] | 5761 | bounds.writeToProto(proto, BOUNDS); |
Steven Timotius | 4346f0a | 2017-09-12 11:07:21 -0700 | [diff] [blame] | 5762 | } |
Bryce Lee | f3c6a47 | 2017-11-14 14:53:06 -0800 | [diff] [blame] | 5763 | |
| 5764 | // TODO: Remove, no longer needed with windowingMode. |
| 5765 | proto.write(FULLSCREEN, matchParentBounds()); |
Steven Timotius | 4346f0a | 2017-09-12 11:07:21 -0700 | [diff] [blame] | 5766 | proto.end(token); |
| 5767 | } |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 5768 | } |