Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2010 The Android Open Source Project |
| 3 | * |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | * you may not use this file except in compliance with the License. |
| 6 | * You may obtain a copy of the License at |
| 7 | * |
| 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | * |
| 10 | * Unless required by applicable law or agreed to in writing, software |
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | * See the License for the specific language governing permissions and |
| 14 | * limitations under the License. |
| 15 | */ |
| 16 | |
| 17 | package com.android.server.am; |
| 18 | |
Wale Ogunwale | 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; |
Winson Chung | 1dbc811 | 2017-09-28 18:05:31 -0700 | [diff] [blame] | 39 | |
Wale Ogunwale | 9dcf946 | 2017-09-19 15:13:01 -0700 | [diff] [blame] | 40 | import static com.android.server.am.ActivityDisplay.POSITION_BOTTOM; |
| 41 | import static com.android.server.am.ActivityDisplay.POSITION_TOP; |
Jorim Jaggi | af80db4 | 2016-04-07 19:19:15 -0700 | [diff] [blame] | 42 | import static com.android.server.am.ActivityManagerDebugConfig.DEBUG_ADD_REMOVE; |
| 43 | import static com.android.server.am.ActivityManagerDebugConfig.DEBUG_ALL; |
| 44 | import static com.android.server.am.ActivityManagerDebugConfig.DEBUG_APP; |
| 45 | import static com.android.server.am.ActivityManagerDebugConfig.DEBUG_CLEANUP; |
Jorim Jaggi | af80db4 | 2016-04-07 19:19:15 -0700 | [diff] [blame] | 46 | import static com.android.server.am.ActivityManagerDebugConfig.DEBUG_CONTAINERS; |
Jorim Jaggi | af80db4 | 2016-04-07 19:19:15 -0700 | [diff] [blame] | 47 | import static com.android.server.am.ActivityManagerDebugConfig.DEBUG_PAUSE; |
| 48 | import static com.android.server.am.ActivityManagerDebugConfig.DEBUG_RELEASE; |
| 49 | import static com.android.server.am.ActivityManagerDebugConfig.DEBUG_RESULTS; |
| 50 | import static com.android.server.am.ActivityManagerDebugConfig.DEBUG_SAVED_STATE; |
Jorim Jaggi | af80db4 | 2016-04-07 19:19:15 -0700 | [diff] [blame] | 51 | import static com.android.server.am.ActivityManagerDebugConfig.DEBUG_STACK; |
| 52 | import static com.android.server.am.ActivityManagerDebugConfig.DEBUG_STATES; |
| 53 | import static com.android.server.am.ActivityManagerDebugConfig.DEBUG_SWITCH; |
| 54 | import static com.android.server.am.ActivityManagerDebugConfig.DEBUG_TASKS; |
| 55 | import static com.android.server.am.ActivityManagerDebugConfig.DEBUG_TRANSITION; |
| 56 | import static com.android.server.am.ActivityManagerDebugConfig.DEBUG_USER_LEAVING; |
| 57 | import static com.android.server.am.ActivityManagerDebugConfig.DEBUG_VISIBILITY; |
| 58 | import static com.android.server.am.ActivityManagerDebugConfig.POSTFIX_ADD_REMOVE; |
| 59 | import static com.android.server.am.ActivityManagerDebugConfig.POSTFIX_APP; |
| 60 | import static com.android.server.am.ActivityManagerDebugConfig.POSTFIX_CLEANUP; |
Jorim Jaggi | af80db4 | 2016-04-07 19:19:15 -0700 | [diff] [blame] | 61 | import static com.android.server.am.ActivityManagerDebugConfig.POSTFIX_CONTAINERS; |
| 62 | import static com.android.server.am.ActivityManagerDebugConfig.POSTFIX_PAUSE; |
| 63 | import static com.android.server.am.ActivityManagerDebugConfig.POSTFIX_RELEASE; |
| 64 | import static com.android.server.am.ActivityManagerDebugConfig.POSTFIX_RESULTS; |
| 65 | import static com.android.server.am.ActivityManagerDebugConfig.POSTFIX_SAVED_STATE; |
Jorim Jaggi | af80db4 | 2016-04-07 19:19:15 -0700 | [diff] [blame] | 66 | import static com.android.server.am.ActivityManagerDebugConfig.POSTFIX_STACK; |
| 67 | import static com.android.server.am.ActivityManagerDebugConfig.POSTFIX_STATES; |
| 68 | import static com.android.server.am.ActivityManagerDebugConfig.POSTFIX_SWITCH; |
| 69 | import static com.android.server.am.ActivityManagerDebugConfig.POSTFIX_TASKS; |
| 70 | import static com.android.server.am.ActivityManagerDebugConfig.POSTFIX_TRANSITION; |
| 71 | import static com.android.server.am.ActivityManagerDebugConfig.POSTFIX_USER_LEAVING; |
| 72 | import static com.android.server.am.ActivityManagerDebugConfig.POSTFIX_VISIBILITY; |
| 73 | import static com.android.server.am.ActivityManagerDebugConfig.TAG_AM; |
| 74 | import static com.android.server.am.ActivityManagerDebugConfig.TAG_WITH_CLASS_NAME; |
Bryce Lee | 7ace395 | 2018-02-16 14:34:32 -0800 | [diff] [blame] | 75 | import static com.android.server.am.ActivityStack.ActivityState.DESTROYED; |
| 76 | import static com.android.server.am.ActivityStack.ActivityState.DESTROYING; |
| 77 | import static com.android.server.am.ActivityStack.ActivityState.FINISHING; |
Wale Ogunwale | 08488a6 | 2017-09-05 12:37:03 -0700 | [diff] [blame] | 78 | import static com.android.server.am.ActivityStack.ActivityState.PAUSED; |
Bryce Lee | 7ace395 | 2018-02-16 14:34:32 -0800 | [diff] [blame] | 79 | import static com.android.server.am.ActivityStack.ActivityState.PAUSING; |
| 80 | import static com.android.server.am.ActivityStack.ActivityState.RESUMED; |
Wale Ogunwale | b9a0c99 | 2017-04-18 07:25:20 -0700 | [diff] [blame] | 81 | import static com.android.server.am.ActivityStack.ActivityState.STOPPED; |
| 82 | import static com.android.server.am.ActivityStack.ActivityState.STOPPING; |
Wale Ogunwale | 3938197 | 2015-12-17 17:15:29 -0800 | [diff] [blame] | 83 | import static com.android.server.am.ActivityStackSupervisor.FindTaskResult; |
Winson Chung | 6954fc9 | 2017-03-24 16:22:12 -0700 | [diff] [blame] | 84 | import static com.android.server.am.ActivityStackSupervisor.PAUSE_IMMEDIATELY; |
Filip Gruszczynski | bc5a6c5 | 2015-09-22 13:13:24 -0700 | [diff] [blame] | 85 | import static com.android.server.am.ActivityStackSupervisor.PRESERVE_WINDOWS; |
Winson Chung | 6954fc9 | 2017-03-24 16:22:12 -0700 | [diff] [blame] | 86 | import static com.android.server.am.ActivityStackSupervisor.REMOVE_FROM_RECENTS; |
Yi Jin | 6c6e9ca | 2018-03-20 16:53:35 -0700 | [diff] [blame] | 87 | import static com.android.server.am.ActivityStackProto.BOUNDS; |
| 88 | import static com.android.server.am.ActivityStackProto.CONFIGURATION_CONTAINER; |
| 89 | import static com.android.server.am.ActivityStackProto.DISPLAY_ID; |
| 90 | import static com.android.server.am.ActivityStackProto.FULLSCREEN; |
| 91 | import static com.android.server.am.ActivityStackProto.ID; |
| 92 | import static com.android.server.am.ActivityStackProto.RESUMED_ACTIVITY; |
| 93 | import static com.android.server.am.ActivityStackProto.TASKS; |
Jorim Jaggi | f84e2f6 | 2018-01-16 14:17:59 +0100 | [diff] [blame] | 94 | import static android.view.WindowManager.TRANSIT_ACTIVITY_CLOSE; |
| 95 | import static android.view.WindowManager.TRANSIT_ACTIVITY_OPEN; |
Adrian Roos | 9357721 | 2018-04-10 14:12:10 -0700 | [diff] [blame] | 96 | import static android.view.WindowManager.TRANSIT_CRASHING_ACTIVITY_CLOSE; |
Jorim Jaggi | f84e2f6 | 2018-01-16 14:17:59 +0100 | [diff] [blame] | 97 | import static android.view.WindowManager.TRANSIT_NONE; |
| 98 | import static android.view.WindowManager.TRANSIT_TASK_CLOSE; |
| 99 | import static android.view.WindowManager.TRANSIT_TASK_OPEN; |
| 100 | import static android.view.WindowManager.TRANSIT_TASK_OPEN_BEHIND; |
| 101 | import static android.view.WindowManager.TRANSIT_TASK_TO_BACK; |
| 102 | import static android.view.WindowManager.TRANSIT_TASK_TO_FRONT; |
Steven Timotius | 4346f0a | 2017-09-12 11:07:21 -0700 | [diff] [blame] | 103 | |
Wale Ogunwale | c5cc301 | 2017-01-13 13:26:16 -0800 | [diff] [blame] | 104 | import static java.lang.Integer.MAX_VALUE; |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 105 | |
| 106 | import android.app.Activity; |
Dianne Hackborn | 0c5001d | 2011-04-12 18:16:08 -0700 | [diff] [blame] | 107 | import android.app.ActivityManager; |
Dianne Hackborn | 7a2195c | 2012-03-19 17:38:00 -0700 | [diff] [blame] | 108 | import android.app.ActivityOptions; |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 109 | import android.app.AppGlobals; |
Craig Mautner | 05d6272ba | 2013-02-11 09:39:27 -0800 | [diff] [blame] | 110 | import android.app.IActivityController; |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 111 | import android.app.ResultInfo; |
Winson Chung | 61c9e5a | 2017-10-11 10:39:32 -0700 | [diff] [blame] | 112 | import android.app.WindowConfiguration.ActivityType; |
| 113 | import android.app.WindowConfiguration.WindowingMode; |
Andrii Kulian | 446e824 | 2017-10-26 15:17:29 -0700 | [diff] [blame] | 114 | import android.app.servertransaction.ActivityResultItem; |
Andrii Kulian | 9956d89 | 2018-02-14 13:48:56 -0800 | [diff] [blame] | 115 | import android.app.servertransaction.ClientTransaction; |
Andrii Kulian | 446e824 | 2017-10-26 15:17:29 -0700 | [diff] [blame] | 116 | import android.app.servertransaction.NewIntentItem; |
| 117 | import android.app.servertransaction.WindowVisibilityItem; |
| 118 | import android.app.servertransaction.DestroyActivityItem; |
| 119 | import android.app.servertransaction.PauseActivityItem; |
| 120 | import android.app.servertransaction.ResumeActivityItem; |
| 121 | import android.app.servertransaction.StopActivityItem; |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 122 | import android.content.ComponentName; |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 123 | import android.content.Intent; |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 124 | import android.content.pm.ActivityInfo; |
Todd Kennedy | 39bfee5 | 2016-02-24 10:28:21 -0800 | [diff] [blame] | 125 | import android.content.pm.ApplicationInfo; |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 126 | import android.content.res.Configuration; |
Jorim Jaggi | af80db4 | 2016-04-07 19:19:15 -0700 | [diff] [blame] | 127 | import android.graphics.Rect; |
Santos Cordon | 73ff7d8 | 2013-03-06 17:24:11 -0800 | [diff] [blame] | 128 | import android.net.Uri; |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 129 | import android.os.Binder; |
Craig Mautner | 329f412 | 2013-11-07 09:10:42 -0800 | [diff] [blame] | 130 | import android.os.Debug; |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 131 | import android.os.Handler; |
| 132 | import android.os.IBinder; |
Zoran Marceta | f958b32 | 2012-08-09 20:27:12 +0900 | [diff] [blame] | 133 | import android.os.Looper; |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 134 | import android.os.Message; |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 135 | import android.os.RemoteException; |
| 136 | import android.os.SystemClock; |
Dianne Hackborn | f02b60a | 2012-08-16 10:48:27 -0700 | [diff] [blame] | 137 | import android.os.UserHandle; |
Craig Mautner | 4c07d02 | 2014-06-11 17:12:59 -0700 | [diff] [blame] | 138 | import android.service.voice.IVoiceInteractionSession; |
Jorim Jaggi | af80db4 | 2016-04-07 19:19:15 -0700 | [diff] [blame] | 139 | import android.util.ArraySet; |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 140 | import android.util.EventLog; |
Andrii Kulian | fb1bf69 | 2017-01-17 11:17:34 -0800 | [diff] [blame] | 141 | import android.util.IntArray; |
Jorim Jaggi | 023da53 | 2016-04-20 22:42:32 -0700 | [diff] [blame] | 142 | import android.util.Log; |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 143 | import android.util.Slog; |
Andrii Kulian | 1e32e02 | 2016-09-16 15:29:34 -0700 | [diff] [blame] | 144 | import android.util.SparseArray; |
Steven Timotius | 4346f0a | 2017-09-12 11:07:21 -0700 | [diff] [blame] | 145 | import android.util.proto.ProtoOutputStream; |
Craig Mautner | 59c0097 | 2012-07-30 12:10:24 -0700 | [diff] [blame] | 146 | import android.view.Display; |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 147 | |
Andreas Gampe | a36dc62 | 2018-02-05 17:19:22 -0800 | [diff] [blame] | 148 | import com.android.internal.annotations.GuardedBy; |
Bryce Lee | 840c566 | 2017-04-13 10:02:51 -0700 | [diff] [blame] | 149 | import com.android.internal.annotations.VisibleForTesting; |
Jorim Jaggi | af80db4 | 2016-04-07 19:19:15 -0700 | [diff] [blame] | 150 | import com.android.internal.app.IVoiceInteractor; |
Jorim Jaggi | af80db4 | 2016-04-07 19:19:15 -0700 | [diff] [blame] | 151 | import com.android.internal.os.BatteryStatsImpl; |
| 152 | import com.android.server.Watchdog; |
| 153 | import com.android.server.am.ActivityManagerService.ItemMatcher; |
Wale Ogunwale | 98d6231 | 2017-07-12 09:24:56 -0700 | [diff] [blame] | 154 | import com.android.server.wm.ConfigurationContainer; |
Wale Ogunwale | 1666e31 | 2016-12-16 11:27:18 -0800 | [diff] [blame] | 155 | import com.android.server.wm.StackWindowController; |
| 156 | import com.android.server.wm.StackWindowListener; |
Jorim Jaggi | af80db4 | 2016-04-07 19:19:15 -0700 | [diff] [blame] | 157 | import com.android.server.wm.WindowManagerService; |
| 158 | |
Craig Mautner | cae015f | 2013-02-08 14:31:27 -0800 | [diff] [blame] | 159 | import java.io.FileDescriptor; |
Craig Mautner | cae015f | 2013-02-08 14:31:27 -0800 | [diff] [blame] | 160 | import java.io.PrintWriter; |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 161 | import java.lang.ref.WeakReference; |
| 162 | import java.util.ArrayList; |
| 163 | import java.util.Iterator; |
| 164 | import java.util.List; |
Kenny Root | e6585b3 | 2013-12-13 12:00:26 -0800 | [diff] [blame] | 165 | import java.util.Objects; |
Wale Ogunwale | 540e123 | 2015-05-01 15:35:39 -0700 | [diff] [blame] | 166 | import java.util.Set; |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 167 | |
| 168 | /** |
| 169 | * State and management of a single stack of activities. |
| 170 | */ |
Winson Chung | 5589333 | 2017-02-17 17:13:10 -0800 | [diff] [blame] | 171 | class ActivityStack<T extends StackWindowController> extends ConfigurationContainer |
| 172 | implements StackWindowListener { |
Wale Ogunwale | e23149f | 2015-03-06 15:39:44 -0800 | [diff] [blame] | 173 | private static final String TAG = TAG_WITH_CLASS_NAME ? "ActivityStack" : TAG_AM; |
Wale Ogunwale | 0fc365c | 2015-05-25 19:35:42 -0700 | [diff] [blame] | 174 | private static final String TAG_ADD_REMOVE = TAG + POSTFIX_ADD_REMOVE; |
| 175 | private static final String TAG_APP = TAG + POSTFIX_APP; |
Wale Ogunwale | e23149f | 2015-03-06 15:39:44 -0800 | [diff] [blame] | 176 | private static final String TAG_CLEANUP = TAG + POSTFIX_CLEANUP; |
Wale Ogunwale | 0fc365c | 2015-05-25 19:35:42 -0700 | [diff] [blame] | 177 | private static final String TAG_CONTAINERS = TAG + POSTFIX_CONTAINERS; |
Wale Ogunwale | ee006da | 2015-03-30 14:49:25 -0700 | [diff] [blame] | 178 | private static final String TAG_PAUSE = TAG + POSTFIX_PAUSE; |
Wale Ogunwale | 0fc365c | 2015-05-25 19:35:42 -0700 | [diff] [blame] | 179 | private static final String TAG_RELEASE = TAG + POSTFIX_RELEASE; |
Wale Ogunwale | ee006da | 2015-03-30 14:49:25 -0700 | [diff] [blame] | 180 | private static final String TAG_RESULTS = TAG + POSTFIX_RESULTS; |
Wale Ogunwale | 0fc365c | 2015-05-25 19:35:42 -0700 | [diff] [blame] | 181 | private static final String TAG_SAVED_STATE = TAG + POSTFIX_SAVED_STATE; |
Wale Ogunwale | ee006da | 2015-03-30 14:49:25 -0700 | [diff] [blame] | 182 | private static final String TAG_STACK = TAG + POSTFIX_STACK; |
Wale Ogunwale | 0fc365c | 2015-05-25 19:35:42 -0700 | [diff] [blame] | 183 | private static final String TAG_STATES = TAG + POSTFIX_STATES; |
Wale Ogunwale | ee006da | 2015-03-30 14:49:25 -0700 | [diff] [blame] | 184 | private static final String TAG_SWITCH = TAG + POSTFIX_SWITCH; |
| 185 | private static final String TAG_TASKS = TAG + POSTFIX_TASKS; |
| 186 | private static final String TAG_TRANSITION = TAG + POSTFIX_TRANSITION; |
| 187 | private static final String TAG_USER_LEAVING = TAG + POSTFIX_USER_LEAVING; |
| 188 | private static final String TAG_VISIBILITY = TAG + POSTFIX_VISIBILITY; |
Wale Ogunwale | 3ab9a27 | 2015-03-16 09:55:45 -0700 | [diff] [blame] | 189 | |
Dianne Hackborn | 2a29b3a | 2012-03-15 15:48:38 -0700 | [diff] [blame] | 190 | // Ticks during which we check progress while waiting for an app to launch. |
| 191 | static final int LAUNCH_TICK = 500; |
| 192 | |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 193 | // How long we wait until giving up on the last activity to pause. This |
| 194 | // is short because it directly impacts the responsiveness of starting the |
| 195 | // next activity. |
Andrii Kulian | 21713ac | 2016-10-12 22:05:05 -0700 | [diff] [blame] | 196 | private static final int PAUSE_TIMEOUT = 500; |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 197 | |
Dianne Hackborn | 162bc0e | 2012-04-09 14:06:16 -0700 | [diff] [blame] | 198 | // How long we wait for the activity to tell us it has stopped before |
| 199 | // 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] | 200 | // from the application in order to get its saved state. Once the stop |
| 201 | // is complete we may start destroying client resources triggering |
| 202 | // crashes if the UI thread was hung. We put this timeout one second behind |
| 203 | // the ANR timeout so these situations will generate ANR instead of |
| 204 | // Surface lost or other errors. |
| 205 | private static final int STOP_TIMEOUT = 11 * 1000; |
Dianne Hackborn | 162bc0e | 2012-04-09 14:06:16 -0700 | [diff] [blame] | 206 | |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 207 | // How long we wait until giving up on an activity telling us it has |
| 208 | // finished destroying itself. |
Andrii Kulian | 21713ac | 2016-10-12 22:05:05 -0700 | [diff] [blame] | 209 | private static final int DESTROY_TIMEOUT = 10 * 1000; |
Craig Mautner | d74f7d7 | 2013-02-26 13:41:02 -0800 | [diff] [blame] | 210 | |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 211 | // Set to false to disable the preview that is shown while a new activity |
| 212 | // is being started. |
Andrii Kulian | 21713ac | 2016-10-12 22:05:05 -0700 | [diff] [blame] | 213 | private static final boolean SHOW_APP_STARTING_PREVIEW = true; |
Craig Mautner | 5d9c7be | 2013-02-15 14:02:56 -0800 | [diff] [blame] | 214 | |
Craig Mautner | 5eda9b3 | 2013-07-02 11:58:16 -0700 | [diff] [blame] | 215 | // How long to wait for all background Activities to redraw following a call to |
| 216 | // convertToTranslucent(). |
Andrii Kulian | 21713ac | 2016-10-12 22:05:05 -0700 | [diff] [blame] | 217 | private static final long TRANSLUCENT_CONVERSION_TIMEOUT = 2000; |
Craig Mautner | 5eda9b3 | 2013-07-02 11:58:16 -0700 | [diff] [blame] | 218 | |
Filip Gruszczynski | ef2f72b | 2015-12-04 14:52:25 -0800 | [diff] [blame] | 219 | // How many activities have to be scheduled to stop to force a stop pass. |
| 220 | private static final int MAX_STOPPING_TO_FORCE = 3; |
| 221 | |
Andrii Kulian | 1779e61 | 2016-10-12 21:58:25 -0700 | [diff] [blame] | 222 | @Override |
| 223 | protected int getChildCount() { |
| 224 | return mTaskHistory.size(); |
| 225 | } |
| 226 | |
| 227 | @Override |
| 228 | protected ConfigurationContainer getChildAt(int index) { |
| 229 | return mTaskHistory.get(index); |
| 230 | } |
| 231 | |
| 232 | @Override |
| 233 | protected ConfigurationContainer getParent() { |
Andrii Kulian | 94e82d9b0 | 2017-07-13 15:33:06 -0700 | [diff] [blame] | 234 | return getDisplay(); |
Andrii Kulian | 1779e61 | 2016-10-12 21:58:25 -0700 | [diff] [blame] | 235 | } |
| 236 | |
Andrii Kulian | fb1bf69 | 2017-01-17 11:17:34 -0800 | [diff] [blame] | 237 | @Override |
Wale Ogunwale | 98d6231 | 2017-07-12 09:24:56 -0700 | [diff] [blame] | 238 | protected void onParentChanged() { |
Andrii Kulian | fb1bf69 | 2017-01-17 11:17:34 -0800 | [diff] [blame] | 239 | super.onParentChanged(); |
| 240 | mStackSupervisor.updateUIDsPresentOnDisplay(); |
| 241 | } |
| 242 | |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 243 | enum ActivityState { |
| 244 | INITIALIZING, |
| 245 | RESUMED, |
| 246 | PAUSING, |
| 247 | PAUSED, |
| 248 | STOPPING, |
| 249 | STOPPED, |
| 250 | FINISHING, |
| 251 | DESTROYING, |
| 252 | DESTROYED |
| 253 | } |
| 254 | |
Bryce Lee | 840c566 | 2017-04-13 10:02:51 -0700 | [diff] [blame] | 255 | @VisibleForTesting |
Wale Ogunwale | 06579d6 | 2016-04-30 15:29:06 -0700 | [diff] [blame] | 256 | /* The various modes for the method {@link #removeTask}. */ |
| 257 | // Task is being completely removed from all stacks in the system. |
Bryce Lee | 840c566 | 2017-04-13 10:02:51 -0700 | [diff] [blame] | 258 | protected static final int REMOVE_TASK_MODE_DESTROYING = 0; |
Wale Ogunwale | 06579d6 | 2016-04-30 15:29:06 -0700 | [diff] [blame] | 259 | // Task is being removed from this stack so we can add it to another stack. In the case we are |
| 260 | // moving we don't want to perform some operations on the task like removing it from window |
| 261 | // manager or recents. |
| 262 | static final int REMOVE_TASK_MODE_MOVING = 1; |
| 263 | // Similar to {@link #REMOVE_TASK_MODE_MOVING} and the task will be added to the top of its new |
| 264 | // stack and the new stack will be on top of all stacks. |
Wale Ogunwale | 56d8d16 | 2017-05-30 11:12:20 -0700 | [diff] [blame] | 265 | static final int REMOVE_TASK_MODE_MOVING_TO_TOP = 2; |
Wale Ogunwale | 06579d6 | 2016-04-30 15:29:06 -0700 | [diff] [blame] | 266 | |
Andrii Kulian | 1e32e02 | 2016-09-16 15:29:34 -0700 | [diff] [blame] | 267 | // The height/width divide used when fitting a task within a bounds with method |
| 268 | // {@link #fitWithinBounds}. |
| 269 | // We always want the task to to be visible in the bounds without affecting its size when |
| 270 | // fitting. To make sure this is the case, we don't adjust the task left or top side pass |
| 271 | // the input bounds right or bottom side minus the width or height divided by this value. |
| 272 | private static final int FIT_WITHIN_BOUNDS_DIVIDER = 3; |
| 273 | |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 274 | final ActivityManagerService mService; |
Andrii Kulian | 21713ac | 2016-10-12 22:05:05 -0700 | [diff] [blame] | 275 | private final WindowManagerService mWindowManager; |
Winson Chung | 5589333 | 2017-02-17 17:13:10 -0800 | [diff] [blame] | 276 | T mWindowContainerController; |
Craig Mautner | d74f7d7 | 2013-02-26 13:41:02 -0800 | [diff] [blame] | 277 | |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 278 | /** |
| 279 | * The back history of all previous (and possibly still |
Craig Mautner | 5d9c7be | 2013-02-15 14:02:56 -0800 | [diff] [blame] | 280 | * running) activities. It contains #TaskRecord objects. |
| 281 | */ |
Todd Kennedy | 39bfee5 | 2016-02-24 10:28:21 -0800 | [diff] [blame] | 282 | private final ArrayList<TaskRecord> mTaskHistory = new ArrayList<>(); |
Craig Mautner | 5d9c7be | 2013-02-15 14:02:56 -0800 | [diff] [blame] | 283 | |
| 284 | /** |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 285 | * List of running activities, sorted by recent usage. |
| 286 | * The first entry in the list is the least recently used. |
| 287 | * It contains HistoryRecord objects. |
| 288 | */ |
Wale Ogunwale | 53a29a9 | 2015-02-23 15:42:52 -0800 | [diff] [blame] | 289 | final ArrayList<ActivityRecord> mLRUActivities = new ArrayList<>(); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 290 | |
| 291 | /** |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 292 | * When we are in the process of pausing an activity, before starting the |
| 293 | * next one, this variable holds the activity that is currently being paused. |
| 294 | */ |
Dianne Hackborn | 621e2fe | 2012-02-16 17:07:33 -0800 | [diff] [blame] | 295 | ActivityRecord mPausingActivity = null; |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 296 | |
| 297 | /** |
| 298 | * This is the last activity that we put into the paused state. This is |
| 299 | * used to determine if we need to do an activity transition while sleeping, |
| 300 | * when we normally hold the top activity paused. |
| 301 | */ |
| 302 | ActivityRecord mLastPausedActivity = null; |
| 303 | |
| 304 | /** |
Craig Mautner | 0f92274 | 2013-08-06 08:44:42 -0700 | [diff] [blame] | 305 | * Activities that specify No History must be removed once the user navigates away from them. |
| 306 | * If the device goes to sleep with such an activity in the paused state then we save it here |
| 307 | * and finish it later if another activity replaces it on wakeup. |
| 308 | */ |
| 309 | ActivityRecord mLastNoHistoryActivity = null; |
| 310 | |
| 311 | /** |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 312 | * Current activity that is resumed, or null if there is none. |
| 313 | */ |
| 314 | ActivityRecord mResumedActivity = null; |
Craig Mautner | d74f7d7 | 2013-02-26 13:41:02 -0800 | [diff] [blame] | 315 | |
Craig Mautner | 5eda9b3 | 2013-07-02 11:58:16 -0700 | [diff] [blame] | 316 | // The topmost Activity passed to convertToTranslucent(). When non-null it means we are |
| 317 | // waiting for all Activities in mUndrawnActivitiesBelowTopTranslucent to be removed as they |
| 318 | // are drawn. When the last member of mUndrawnActivitiesBelowTopTranslucent is removed the |
| 319 | // Activity in mTranslucentActivityWaiting is notified via |
| 320 | // Activity.onTranslucentConversionComplete(false). If a timeout occurs prior to the last |
| 321 | // background activity being drawn then the same call will be made with a true value. |
| 322 | ActivityRecord mTranslucentActivityWaiting = null; |
Andrii Kulian | 21713ac | 2016-10-12 22:05:05 -0700 | [diff] [blame] | 323 | ArrayList<ActivityRecord> mUndrawnActivitiesBelowTopTranslucent = new ArrayList<>(); |
Craig Mautner | 5eda9b3 | 2013-07-02 11:58:16 -0700 | [diff] [blame] | 324 | |
Dianne Hackborn | 0dad364 | 2010-09-09 21:25:35 -0700 | [diff] [blame] | 325 | /** |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 326 | * Set when we know we are going to be calling updateConfiguration() |
| 327 | * soon, so want to skip intermediate config checks. |
| 328 | */ |
| 329 | boolean mConfigWillChange; |
| 330 | |
Winson Chung | 4790065 | 2017-04-06 18:44:25 -0700 | [diff] [blame] | 331 | /** |
| 332 | * When set, will force the stack to report as invisible. |
| 333 | */ |
| 334 | boolean mForceHidden = false; |
| 335 | |
Andrii Kulian | 21713ac | 2016-10-12 22:05:05 -0700 | [diff] [blame] | 336 | private boolean mUpdateBoundsDeferred; |
| 337 | private boolean mUpdateBoundsDeferredCalled; |
| 338 | private final Rect mDeferredBounds = new Rect(); |
| 339 | private final Rect mDeferredTaskBounds = new Rect(); |
| 340 | private final Rect mDeferredTaskInsetBounds = new Rect(); |
Jorim Jaggi | 192086e | 2016-03-11 17:17:03 +0100 | [diff] [blame] | 341 | |
Craig Mautner | 858d8a6 | 2013-04-23 17:08:34 -0700 | [diff] [blame] | 342 | int mCurrentUser; |
Amith Yamasani | 742a671 | 2011-05-04 14:49:28 -0700 | [diff] [blame] | 343 | |
Craig Mautner | c00204b | 2013-03-05 15:02:14 -0800 | [diff] [blame] | 344 | final int mStackId; |
Craig Mautner | e0a3884 | 2013-12-16 16:14:02 -0800 | [diff] [blame] | 345 | /** The attached Display's unique identifier, or -1 if detached */ |
| 346 | int mDisplayId; |
Craig Mautner | 4a1cb22 | 2013-12-04 16:14:06 -0800 | [diff] [blame] | 347 | |
Andrii Kulian | 1e32e02 | 2016-09-16 15:29:34 -0700 | [diff] [blame] | 348 | private final SparseArray<Rect> mTmpBounds = new SparseArray<>(); |
| 349 | private final SparseArray<Rect> mTmpInsetBounds = new SparseArray<>(); |
Wale Ogunwale | 1666e31 | 2016-12-16 11:27:18 -0800 | [diff] [blame] | 350 | private final Rect mTmpRect2 = new Rect(); |
Wale Ogunwale | 30e441d | 2017-11-09 08:28:45 -0800 | [diff] [blame] | 351 | private final ActivityOptions mTmpOptions = ActivityOptions.makeBasic(); |
Andrii Kulian | 1e32e02 | 2016-09-16 15:29:34 -0700 | [diff] [blame] | 352 | |
Bryce Lee | fbd263b4 | 2018-03-07 10:33:55 -0800 | [diff] [blame] | 353 | /** List for processing through a set of activities */ |
| 354 | private final ArrayList<ActivityRecord> mTmpActivities = new ArrayList<>(); |
| 355 | |
Craig Mautner | 2708430 | 2013-03-25 08:05:25 -0700 | [diff] [blame] | 356 | /** Run all ActivityStacks through this */ |
Winson Chung | 5af42fc | 2017-03-24 17:11:33 -0700 | [diff] [blame] | 357 | protected final ActivityStackSupervisor mStackSupervisor; |
Craig Mautner | 2708430 | 2013-03-25 08:05:25 -0700 | [diff] [blame] | 358 | |
Jorim Jaggi | fe76234 | 2016-10-13 14:33:27 +0200 | [diff] [blame] | 359 | private boolean mTopActivityOccludesKeyguard; |
| 360 | private ActivityRecord mTopDismissingKeyguardActivity; |
| 361 | |
Craig Mautner | 7ea5bd4 | 2013-07-05 15:27:08 -0700 | [diff] [blame] | 362 | static final int PAUSE_TIMEOUT_MSG = ActivityManagerService.FIRST_ACTIVITY_STACK_MSG + 1; |
Craig Mautner | 0eea92c | 2013-05-16 13:35:39 -0700 | [diff] [blame] | 363 | static final int DESTROY_TIMEOUT_MSG = ActivityManagerService.FIRST_ACTIVITY_STACK_MSG + 2; |
| 364 | static final int LAUNCH_TICK_MSG = ActivityManagerService.FIRST_ACTIVITY_STACK_MSG + 3; |
| 365 | static final int STOP_TIMEOUT_MSG = ActivityManagerService.FIRST_ACTIVITY_STACK_MSG + 4; |
| 366 | static final int DESTROY_ACTIVITIES_MSG = ActivityManagerService.FIRST_ACTIVITY_STACK_MSG + 5; |
Craig Mautner | 5eda9b3 | 2013-07-02 11:58:16 -0700 | [diff] [blame] | 367 | static final int TRANSLUCENT_TIMEOUT_MSG = ActivityManagerService.FIRST_ACTIVITY_STACK_MSG + 6; |
Dianne Hackborn | 755c8bf | 2012-05-07 15:06:09 -0700 | [diff] [blame] | 368 | |
Andrii Kulian | 21713ac | 2016-10-12 22:05:05 -0700 | [diff] [blame] | 369 | private static class ScheduleDestroyArgs { |
Dianne Hackborn | 755c8bf | 2012-05-07 15:06:09 -0700 | [diff] [blame] | 370 | final ProcessRecord mOwner; |
Dianne Hackborn | 755c8bf | 2012-05-07 15:06:09 -0700 | [diff] [blame] | 371 | final String mReason; |
Craig Mautner | ee2e45a | 2014-06-27 12:10:03 -0700 | [diff] [blame] | 372 | ScheduleDestroyArgs(ProcessRecord owner, String reason) { |
Dianne Hackborn | 755c8bf | 2012-05-07 15:06:09 -0700 | [diff] [blame] | 373 | mOwner = owner; |
Dianne Hackborn | 755c8bf | 2012-05-07 15:06:09 -0700 | [diff] [blame] | 374 | mReason = reason; |
| 375 | } |
| 376 | } |
| 377 | |
Zoran Marceta | f958b32 | 2012-08-09 20:27:12 +0900 | [diff] [blame] | 378 | final Handler mHandler; |
| 379 | |
Andrii Kulian | 21713ac | 2016-10-12 22:05:05 -0700 | [diff] [blame] | 380 | private class ActivityStackHandler extends Handler { |
Wale Ogunwale | e23149f | 2015-03-06 15:39:44 -0800 | [diff] [blame] | 381 | |
Craig Mautner | c8143c6 | 2013-09-03 12:15:57 -0700 | [diff] [blame] | 382 | ActivityStackHandler(Looper looper) { |
Zoran Marceta | f958b32 | 2012-08-09 20:27:12 +0900 | [diff] [blame] | 383 | super(looper); |
| 384 | } |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 385 | |
Zoran Marceta | f958b32 | 2012-08-09 20:27:12 +0900 | [diff] [blame] | 386 | @Override |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 387 | public void handleMessage(Message msg) { |
| 388 | switch (msg.what) { |
| 389 | case PAUSE_TIMEOUT_MSG: { |
Dianne Hackborn | be70785 | 2011-11-11 14:32:10 -0800 | [diff] [blame] | 390 | ActivityRecord r = (ActivityRecord)msg.obj; |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 391 | // We don't at this point know if the activity is fullscreen, |
| 392 | // so we need to be conservative and assume it isn't. |
Dianne Hackborn | be70785 | 2011-11-11 14:32:10 -0800 | [diff] [blame] | 393 | Slog.w(TAG, "Activity pause timeout for " + r); |
Dianne Hackborn | 2a29b3a | 2012-03-15 15:48:38 -0700 | [diff] [blame] | 394 | synchronized (mService) { |
| 395 | if (r.app != null) { |
Craig Mautner | f7bfefb | 2013-05-16 17:30:44 -0700 | [diff] [blame] | 396 | mService.logAppTooSlow(r.app, r.pauseTime, "pausing " + r); |
Dianne Hackborn | 2a29b3a | 2012-03-15 15:48:38 -0700 | [diff] [blame] | 397 | } |
Dianne Hackborn | a4e102e | 2014-09-04 22:52:27 -0700 | [diff] [blame] | 398 | activityPausedLocked(r.appToken, true); |
Craig Mautner | d232895 | 2013-03-05 12:46:26 -0800 | [diff] [blame] | 399 | } |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 400 | } break; |
Dianne Hackborn | 2a29b3a | 2012-03-15 15:48:38 -0700 | [diff] [blame] | 401 | case LAUNCH_TICK_MSG: { |
| 402 | ActivityRecord r = (ActivityRecord)msg.obj; |
| 403 | synchronized (mService) { |
| 404 | if (r.continueLaunchTickingLocked()) { |
Craig Mautner | f7bfefb | 2013-05-16 17:30:44 -0700 | [diff] [blame] | 405 | mService.logAppTooSlow(r.app, r.launchTickTime, "launching " + r); |
Dianne Hackborn | 2a29b3a | 2012-03-15 15:48:38 -0700 | [diff] [blame] | 406 | } |
| 407 | } |
| 408 | } break; |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 409 | case DESTROY_TIMEOUT_MSG: { |
Dianne Hackborn | be70785 | 2011-11-11 14:32:10 -0800 | [diff] [blame] | 410 | ActivityRecord r = (ActivityRecord)msg.obj; |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 411 | // We don't at this point know if the activity is fullscreen, |
| 412 | // so we need to be conservative and assume it isn't. |
Dianne Hackborn | be70785 | 2011-11-11 14:32:10 -0800 | [diff] [blame] | 413 | Slog.w(TAG, "Activity destroy timeout for " + r); |
Craig Mautner | d232895 | 2013-03-05 12:46:26 -0800 | [diff] [blame] | 414 | synchronized (mService) { |
Craig Mautner | 299f960 | 2015-01-26 09:47:33 -0800 | [diff] [blame] | 415 | activityDestroyedLocked(r != null ? r.appToken : null, "destroyTimeout"); |
Craig Mautner | d232895 | 2013-03-05 12:46:26 -0800 | [diff] [blame] | 416 | } |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 417 | } break; |
Dianne Hackborn | 162bc0e | 2012-04-09 14:06:16 -0700 | [diff] [blame] | 418 | case STOP_TIMEOUT_MSG: { |
| 419 | ActivityRecord r = (ActivityRecord)msg.obj; |
| 420 | // We don't at this point know if the activity is fullscreen, |
| 421 | // so we need to be conservative and assume it isn't. |
| 422 | Slog.w(TAG, "Activity stop timeout for " + r); |
| 423 | synchronized (mService) { |
| 424 | if (r.isInHistory()) { |
Andrii Kulian | 21713ac | 2016-10-12 22:05:05 -0700 | [diff] [blame] | 425 | r.activityStoppedLocked(null /* icicle */, |
| 426 | null /* persistentState */, null /* description */); |
Dianne Hackborn | 162bc0e | 2012-04-09 14:06:16 -0700 | [diff] [blame] | 427 | } |
| 428 | } |
| 429 | } break; |
Dianne Hackborn | 755c8bf | 2012-05-07 15:06:09 -0700 | [diff] [blame] | 430 | case DESTROY_ACTIVITIES_MSG: { |
| 431 | ScheduleDestroyArgs args = (ScheduleDestroyArgs)msg.obj; |
| 432 | synchronized (mService) { |
Craig Mautner | ee2e45a | 2014-06-27 12:10:03 -0700 | [diff] [blame] | 433 | destroyActivitiesLocked(args.mOwner, args.mReason); |
Dianne Hackborn | 755c8bf | 2012-05-07 15:06:09 -0700 | [diff] [blame] | 434 | } |
Craig Mautner | 5eda9b3 | 2013-07-02 11:58:16 -0700 | [diff] [blame] | 435 | } break; |
| 436 | case TRANSLUCENT_TIMEOUT_MSG: { |
| 437 | synchronized (mService) { |
| 438 | notifyActivityDrawnLocked(null); |
| 439 | } |
| 440 | } break; |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 441 | } |
| 442 | } |
Craig Mautner | 4b71aa1 | 2012-12-27 17:20:01 -0800 | [diff] [blame] | 443 | } |
| 444 | |
Craig Mautner | 34b73df | 2014-01-12 21:11:08 -0800 | [diff] [blame] | 445 | int numActivities() { |
Craig Mautner | 000f002 | 2013-02-26 15:04:29 -0800 | [diff] [blame] | 446 | int count = 0; |
| 447 | for (int taskNdx = mTaskHistory.size() - 1; taskNdx >= 0; --taskNdx) { |
| 448 | count += mTaskHistory.get(taskNdx).mActivities.size(); |
| 449 | } |
| 450 | return count; |
| 451 | } |
| 452 | |
Wale Ogunwale | 9dcf946 | 2017-09-19 15:13:01 -0700 | [diff] [blame] | 453 | ActivityStack(ActivityDisplay display, int stackId, ActivityStackSupervisor supervisor, |
Wale Ogunwale | 04a05ac | 2017-09-17 21:35:02 -0700 | [diff] [blame] | 454 | int windowingMode, int activityType, boolean onTop) { |
Andrii Kulian | 94e82d9b0 | 2017-07-13 15:33:06 -0700 | [diff] [blame] | 455 | mStackSupervisor = supervisor; |
| 456 | mService = supervisor.mService; |
Craig Mautner | 4a1cb22 | 2013-12-04 16:14:06 -0800 | [diff] [blame] | 457 | mHandler = new ActivityStackHandler(mService.mHandler.getLooper()); |
| 458 | mWindowManager = mService.mWindowManager; |
Andrii Kulian | 94e82d9b0 | 2017-07-13 15:33:06 -0700 | [diff] [blame] | 459 | mStackId = stackId; |
Fyodor Kupolov | 1b3edac | 2017-09-19 15:48:06 -0700 | [diff] [blame] | 460 | mCurrentUser = mService.mUserController.getCurrentUserId(); |
Wale Ogunwale | 1666e31 | 2016-12-16 11:27:18 -0800 | [diff] [blame] | 461 | mTmpRect2.setEmpty(); |
Andrii Kulian | 2fcc451 | 2018-01-25 16:39:27 -0800 | [diff] [blame] | 462 | // Set display id before setting activity and window type to make sure it won't affect |
| 463 | // stacks on a wrong display. |
| 464 | mDisplayId = display.mDisplayId; |
Wale Ogunwale | 04a05ac | 2017-09-17 21:35:02 -0700 | [diff] [blame] | 465 | setActivityType(activityType); |
Wale Ogunwale | 30e441d | 2017-11-09 08:28:45 -0800 | [diff] [blame] | 466 | setWindowingMode(windowingMode); |
Winson Chung | 5589333 | 2017-02-17 17:13:10 -0800 | [diff] [blame] | 467 | mWindowContainerController = createStackWindowController(display.mDisplayId, onTop, |
Wale Ogunwale | 034a8ec | 2017-09-02 17:14:40 -0700 | [diff] [blame] | 468 | mTmpRect2); |
Wale Ogunwale | 1666e31 | 2016-12-16 11:27:18 -0800 | [diff] [blame] | 469 | postAddToDisplay(display, mTmpRect2.isEmpty() ? null : mTmpRect2, onTop); |
| 470 | } |
| 471 | |
Wale Ogunwale | 034a8ec | 2017-09-02 17:14:40 -0700 | [diff] [blame] | 472 | T createStackWindowController(int displayId, boolean onTop, Rect outBounds) { |
Bryce Lee | 4e4a3ec | 2017-09-27 08:25:03 -0700 | [diff] [blame] | 473 | return (T) new StackWindowController(mStackId, this, displayId, onTop, outBounds, |
| 474 | mStackSupervisor.mWindowManager); |
Winson Chung | 5589333 | 2017-02-17 17:13:10 -0800 | [diff] [blame] | 475 | } |
| 476 | |
| 477 | T getWindowContainerController() { |
Wale Ogunwale | 1666e31 | 2016-12-16 11:27:18 -0800 | [diff] [blame] | 478 | return mWindowContainerController; |
Filip Gruszczynski | e5390e7 | 2015-08-18 16:39:00 -0700 | [diff] [blame] | 479 | } |
| 480 | |
Bryce Lee | c4ab62a | 2018-03-05 14:19:26 -0800 | [diff] [blame] | 481 | /** |
| 482 | * This should be called when an activity in a child task changes state. This should only |
| 483 | * be called from |
| 484 | * {@link TaskRecord#onActivityStateChanged(ActivityRecord, ActivityState, String)}. |
| 485 | * @param record The {@link ActivityRecord} whose state has changed. |
| 486 | * @param state The new state. |
| 487 | * @param reason The reason for the change. |
| 488 | */ |
| 489 | void onActivityStateChanged(ActivityRecord record, ActivityState state, String reason) { |
| 490 | if (record == mResumedActivity && state != RESUMED) { |
Bryce Lee | 84730a0 | 2018-04-03 14:10:04 -0700 | [diff] [blame] | 491 | setResumedActivity(null, reason + " - onActivityStateChanged"); |
Bryce Lee | c4ab62a | 2018-03-05 14:19:26 -0800 | [diff] [blame] | 492 | } |
| 493 | |
| 494 | if (state == RESUMED) { |
| 495 | if (DEBUG_STACK) Slog.v(TAG_STACK, "set resumed activity to:" + record + " reason:" |
| 496 | + reason); |
Bryce Lee | 84730a0 | 2018-04-03 14:10:04 -0700 | [diff] [blame] | 497 | setResumedActivity(record, reason + " - onActivityStateChanged"); |
Bryce Lee | c4ab62a | 2018-03-05 14:19:26 -0800 | [diff] [blame] | 498 | mService.setResumedActivityUncheckLocked(record, reason); |
| 499 | mStackSupervisor.mRecentTasks.add(record.getTask()); |
| 500 | } |
| 501 | } |
| 502 | |
Wale Ogunwale | a0f5b5e | 2017-10-11 09:37:23 -0700 | [diff] [blame] | 503 | @Override |
| 504 | public void onConfigurationChanged(Configuration newParentConfig) { |
| 505 | final int prevWindowingMode = getWindowingMode(); |
| 506 | super.onConfigurationChanged(newParentConfig); |
| 507 | final ActivityDisplay display = getDisplay(); |
| 508 | if (display != null && prevWindowingMode != getWindowingMode()) { |
| 509 | display.onStackWindowingModeChanged(this); |
| 510 | } |
| 511 | } |
| 512 | |
Wale Ogunwale | ab5de37 | 2017-10-18 06:46:31 -0700 | [diff] [blame] | 513 | @Override |
Wale Ogunwale | 30e441d | 2017-11-09 08:28:45 -0800 | [diff] [blame] | 514 | public void setWindowingMode(int windowingMode) { |
Winson Chung | 3e36f82 | 2018-01-16 12:06:04 -0800 | [diff] [blame] | 515 | setWindowingMode(windowingMode, false /* animate */, false /* showRecents */, |
Andrii Kulian | 9da138a | 2018-04-24 17:12:44 -0700 | [diff] [blame] | 516 | false /* enteringSplitScreenMode */, false /* deferEnsuringVisibility */); |
Wale Ogunwale | 30e441d | 2017-11-09 08:28:45 -0800 | [diff] [blame] | 517 | } |
| 518 | |
Wale Ogunwale | df262f5 | 2017-12-07 18:17:12 -0800 | [diff] [blame] | 519 | void setWindowingMode(int preferredWindowingMode, boolean animate, boolean showRecents, |
Andrii Kulian | 9da138a | 2018-04-24 17:12:44 -0700 | [diff] [blame] | 520 | boolean enteringSplitScreenMode, boolean deferEnsuringVisibility) { |
Wale Ogunwale | 1dbc5c8 | 2017-12-08 08:12:20 -0800 | [diff] [blame] | 521 | final boolean creating = mWindowContainerController == null; |
Wale Ogunwale | 30e441d | 2017-11-09 08:28:45 -0800 | [diff] [blame] | 522 | final int currentMode = getWindowingMode(); |
| 523 | final ActivityDisplay display = getDisplay(); |
| 524 | final TaskRecord topTask = topTask(); |
| 525 | final ActivityStack splitScreenStack = display.getSplitScreenPrimaryStack(); |
| 526 | mTmpOptions.setLaunchWindowingMode(preferredWindowingMode); |
| 527 | |
Wale Ogunwale | 1dbc5c8 | 2017-12-08 08:12:20 -0800 | [diff] [blame] | 528 | // Need to make sure windowing mode is supported. If we in the process of creating the stack |
| 529 | // no need to resolve the windowing mode again as it is already resolved to the right mode. |
| 530 | int windowingMode = creating |
| 531 | ? preferredWindowingMode |
| 532 | : display.resolveWindowingMode( |
| 533 | null /* ActivityRecord */, mTmpOptions, topTask, getActivityType()); |
Wale Ogunwale | 30e441d | 2017-11-09 08:28:45 -0800 | [diff] [blame] | 534 | if (splitScreenStack == this && windowingMode == WINDOWING_MODE_SPLIT_SCREEN_SECONDARY) { |
| 535 | // Resolution to split-screen secondary for the primary split-screen stack means we want |
| 536 | // to go fullscreen. |
| 537 | windowingMode = WINDOWING_MODE_FULLSCREEN; |
| 538 | } |
| 539 | |
Wale Ogunwale | ac36e4d | 2017-11-29 13:30:26 -0800 | [diff] [blame] | 540 | final boolean alreadyInSplitScreenMode = display.hasSplitScreenPrimaryStack(); |
| 541 | |
Wale Ogunwale | 1dbc5c8 | 2017-12-08 08:12:20 -0800 | [diff] [blame] | 542 | // Don't send non-resizeable notifications if the windowing mode changed was a side effect |
| 543 | // of us entering split-screen mode. |
| 544 | final boolean sendNonResizeableNotification = !enteringSplitScreenMode; |
Wale Ogunwale | 30e441d | 2017-11-09 08:28:45 -0800 | [diff] [blame] | 545 | // 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] | 546 | if (alreadyInSplitScreenMode && windowingMode == WINDOWING_MODE_FULLSCREEN |
| 547 | && sendNonResizeableNotification && isActivityTypeStandardOrUndefined()) { |
| 548 | final boolean preferredSplitScreen = |
| 549 | preferredWindowingMode == WINDOWING_MODE_SPLIT_SCREEN_PRIMARY |
| 550 | || preferredWindowingMode == WINDOWING_MODE_SPLIT_SCREEN_SECONDARY; |
| 551 | if (preferredSplitScreen || creating) { |
| 552 | // Looks like we can't launch in split screen mode or the stack we are launching |
| 553 | // doesn't support split-screen mode, go ahead an dismiss split-screen and display a |
| 554 | // warning toast about it. |
Wale Ogunwale | 30e441d | 2017-11-09 08:28:45 -0800 | [diff] [blame] | 555 | mService.mTaskChangeNotificationController.notifyActivityDismissingDockedStack(); |
Andrii Kulian | 9da138a | 2018-04-24 17:12:44 -0700 | [diff] [blame] | 556 | display.getSplitScreenPrimaryStack().setWindowingMode(WINDOWING_MODE_FULLSCREEN, |
| 557 | false /* animate */, false /* showRecents */, |
| 558 | false /* enteringSplitScreenMode */, true /* deferEnsuringVisibility */); |
Wale Ogunwale | 30e441d | 2017-11-09 08:28:45 -0800 | [diff] [blame] | 559 | } |
| 560 | } |
| 561 | |
| 562 | if (currentMode == windowingMode) { |
| 563 | // You are already in the window mode silly... |
| 564 | return; |
| 565 | } |
| 566 | |
| 567 | final WindowManagerService wm = mService.mWindowManager; |
| 568 | final ActivityRecord topActivity = getTopActivity(); |
| 569 | |
Wale Ogunwale | df262f5 | 2017-12-07 18:17:12 -0800 | [diff] [blame] | 570 | if (sendNonResizeableNotification && windowingMode != WINDOWING_MODE_FULLSCREEN |
| 571 | && topActivity != null && topActivity.isNonResizableOrForcedResizable() |
| 572 | && !topActivity.noDisplay) { |
Wale Ogunwale | 30e441d | 2017-11-09 08:28:45 -0800 | [diff] [blame] | 573 | // Inform the user that they are starting an app that may not work correctly in |
| 574 | // multi-window mode. |
| 575 | final String packageName = topActivity.appInfo.packageName; |
| 576 | mService.mTaskChangeNotificationController.notifyActivityForcedResizable( |
| 577 | topTask.taskId, FORCED_RESIZEABLE_REASON_SPLIT_SCREEN, packageName); |
| 578 | } |
| 579 | |
| 580 | wm.deferSurfaceLayout(); |
| 581 | try { |
| 582 | if (!animate && topActivity != null) { |
Jorim Jaggi | fa9ed96 | 2018-01-25 00:16:49 +0100 | [diff] [blame] | 583 | mStackSupervisor.mNoAnimActivities.add(topActivity); |
Wale Ogunwale | 30e441d | 2017-11-09 08:28:45 -0800 | [diff] [blame] | 584 | } |
| 585 | super.setWindowingMode(windowingMode); |
| 586 | |
Wale Ogunwale | 1dbc5c8 | 2017-12-08 08:12:20 -0800 | [diff] [blame] | 587 | if (creating) { |
Wale Ogunwale | 30e441d | 2017-11-09 08:28:45 -0800 | [diff] [blame] | 588 | // Nothing else to do if we don't have a window container yet. E.g. call from ctor. |
| 589 | return; |
| 590 | } |
| 591 | |
| 592 | if (windowingMode == WINDOWING_MODE_PINNED || currentMode == WINDOWING_MODE_PINNED) { |
| 593 | // TODO: Need to remove use of PinnedActivityStack for this to be supported. |
| 594 | // NOTE: Need to ASS.scheduleUpdatePictureInPictureModeIfNeeded() in |
| 595 | // setWindowModeUnchecked() when this support is added. See TaskRecord.reparent() |
| 596 | throw new IllegalArgumentException( |
| 597 | "Changing pinned windowing mode not currently supported"); |
| 598 | } |
| 599 | |
| 600 | if (windowingMode == WINDOWING_MODE_SPLIT_SCREEN_PRIMARY && splitScreenStack != null) { |
| 601 | // We already have a split-screen stack in this display, so just move the tasks over. |
| 602 | // TODO: Figure-out how to do all the stuff in |
| 603 | // AMS.setTaskWindowingModeSplitScreenPrimary |
| 604 | throw new IllegalArgumentException("Setting primary split-screen windowing mode" |
| 605 | + " while there is already one isn't currently supported"); |
| 606 | //return; |
| 607 | } |
| 608 | |
| 609 | mTmpRect2.setEmpty(); |
| 610 | if (windowingMode != WINDOWING_MODE_FULLSCREEN) { |
| 611 | mWindowContainerController.getRawBounds(mTmpRect2); |
| 612 | if (windowingMode == WINDOWING_MODE_FREEFORM) { |
| 613 | if (topTask != null) { |
| 614 | // TODO: Can we consolidate this and other sites that call this methods? |
| 615 | Rect bounds = topTask().getLaunchBounds(); |
| 616 | if (bounds != null) { |
| 617 | mTmpRect2.set(bounds); |
| 618 | } |
| 619 | } |
| 620 | } |
| 621 | } |
| 622 | |
Bryce Lee | f3c6a47 | 2017-11-14 14:53:06 -0800 | [diff] [blame] | 623 | if (!Objects.equals(getOverrideBounds(), mTmpRect2)) { |
Wale Ogunwale | 30e441d | 2017-11-09 08:28:45 -0800 | [diff] [blame] | 624 | resize(mTmpRect2, null /* tempTaskBounds */, null /* tempTaskInsetBounds */); |
| 625 | } |
| 626 | } finally { |
Wale Ogunwale | c59b4f6 | 2017-11-30 11:05:43 -0800 | [diff] [blame] | 627 | if (showRecents && !alreadyInSplitScreenMode && mDisplayId == DEFAULT_DISPLAY |
Wale Ogunwale | 30e441d | 2017-11-09 08:28:45 -0800 | [diff] [blame] | 628 | && windowingMode == WINDOWING_MODE_SPLIT_SCREEN_PRIMARY) { |
| 629 | // Make sure recents stack exist when creating a dock stack as it normally needs to |
| 630 | // be on the other side of the docked stack and we make visibility decisions based |
| 631 | // on that. |
| 632 | // TODO: This is only here to help out with the case where recents stack doesn't |
| 633 | // exist yet. For that case the initial size of the split-screen stack will be the |
| 634 | // the one where the home stack is visible since recents isn't visible yet, but the |
| 635 | // divider will be off. I think we should just make the initial bounds that of home |
| 636 | // so that the divider matches and remove this logic. |
Winson Chung | c167427 | 2018-02-21 10:15:17 -0800 | [diff] [blame] | 637 | // TODO: This is currently only called when entering split-screen while in another |
| 638 | // task, and from the tests |
Matthew Ng | 3030712 | 2018-04-13 11:36:34 -0700 | [diff] [blame] | 639 | // TODO (b/78247419): Check if launcher and overview are same then move home stack |
| 640 | // instead of recents stack. Then fix the rotation animation from fullscreen to |
| 641 | // minimized mode |
Wale Ogunwale | 1dbc5c8 | 2017-12-08 08:12:20 -0800 | [diff] [blame] | 642 | final ActivityStack recentStack = display.getOrCreateStack( |
| 643 | WINDOWING_MODE_SPLIT_SCREEN_SECONDARY, ACTIVITY_TYPE_RECENTS, |
| 644 | true /* onTop */); |
| 645 | recentStack.moveToFront("setWindowingMode"); |
Wale Ogunwale | 30e441d | 2017-11-09 08:28:45 -0800 | [diff] [blame] | 646 | // If task moved to docked stack - show recents if needed. |
Winson Chung | dff7a73 | 2017-12-11 12:17:06 -0800 | [diff] [blame] | 647 | mService.mWindowManager.showRecentApps(); |
Wale Ogunwale | 30e441d | 2017-11-09 08:28:45 -0800 | [diff] [blame] | 648 | } |
| 649 | wm.continueSurfaceLayout(); |
| 650 | } |
| 651 | |
Andrii Kulian | 9da138a | 2018-04-24 17:12:44 -0700 | [diff] [blame] | 652 | if (!deferEnsuringVisibility) { |
Wale Ogunwale | 1dbc5c8 | 2017-12-08 08:12:20 -0800 | [diff] [blame] | 653 | mStackSupervisor.ensureActivitiesVisibleLocked(null, 0, PRESERVE_WINDOWS); |
| 654 | mStackSupervisor.resumeFocusedStackTopActivityLocked(); |
| 655 | } |
Wale Ogunwale | 30e441d | 2017-11-09 08:28:45 -0800 | [diff] [blame] | 656 | } |
| 657 | |
| 658 | @Override |
Wale Ogunwale | ab5de37 | 2017-10-18 06:46:31 -0700 | [diff] [blame] | 659 | public boolean isCompatible(int windowingMode, int activityType) { |
| 660 | // TODO: Should we just move this to ConfigurationContainer? |
| 661 | if (activityType == ACTIVITY_TYPE_UNDEFINED) { |
| 662 | // Undefined activity types end up in a standard stack once the stack is created on a |
| 663 | // display, so they should be considered compatible. |
| 664 | activityType = ACTIVITY_TYPE_STANDARD; |
| 665 | } |
| 666 | final ActivityDisplay display = getDisplay(); |
Wale Ogunwale | 7e1f5f5 | 2017-10-18 15:19:59 -0700 | [diff] [blame] | 667 | if (display != null && activityType == ACTIVITY_TYPE_STANDARD |
Wale Ogunwale | ab5de37 | 2017-10-18 06:46:31 -0700 | [diff] [blame] | 668 | && windowingMode == WINDOWING_MODE_UNDEFINED) { |
Wale Ogunwale | 7e1f5f5 | 2017-10-18 15:19:59 -0700 | [diff] [blame] | 669 | // Standard activity types will mostly take on the windowing mode of the display if one |
| 670 | // isn't specified, so look-up a compatible stack based on the display's windowing mode. |
| 671 | windowingMode = display.getWindowingMode(); |
Wale Ogunwale | ab5de37 | 2017-10-18 06:46:31 -0700 | [diff] [blame] | 672 | } |
| 673 | return super.isCompatible(windowingMode, activityType); |
| 674 | } |
| 675 | |
Andrii Kulian | 839def9 | 2016-11-02 10:58:58 -0700 | [diff] [blame] | 676 | /** Adds the stack to specified display and calls WindowManager to do the same. */ |
Wale Ogunwale | 9dcf946 | 2017-09-19 15:13:01 -0700 | [diff] [blame] | 677 | void reparent(ActivityDisplay activityDisplay, boolean onTop) { |
Wale Ogunwale | 7e1f5f5 | 2017-10-18 15:19:59 -0700 | [diff] [blame] | 678 | // TODO: We should probably resolve the windowing mode for the stack on the new display here |
| 679 | // 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] | 680 | removeFromDisplay(); |
Winson Chung | f34c602 | 2018-01-25 09:44:30 -0800 | [diff] [blame] | 681 | // Reparent the window container before we try to update the position when adding it to |
| 682 | // the new display below |
Wale Ogunwale | 1666e31 | 2016-12-16 11:27:18 -0800 | [diff] [blame] | 683 | mTmpRect2.setEmpty(); |
Winson Chung | f34c602 | 2018-01-25 09:44:30 -0800 | [diff] [blame] | 684 | mWindowContainerController.reparent(activityDisplay.mDisplayId, mTmpRect2, onTop); |
Wale Ogunwale | 1666e31 | 2016-12-16 11:27:18 -0800 | [diff] [blame] | 685 | postAddToDisplay(activityDisplay, mTmpRect2.isEmpty() ? null : mTmpRect2, onTop); |
Wale Ogunwale | 66e1685 | 2017-10-19 13:35:52 -0700 | [diff] [blame] | 686 | adjustFocusToNextFocusableStack("reparent", true /* allowFocusSelf */); |
Andrii Kulian | 250d653 | 2017-02-08 23:30:45 -0800 | [diff] [blame] | 687 | mStackSupervisor.resumeFocusedStackTopActivityLocked(); |
Andrii Kulian | 51c1b67 | 2017-04-07 18:39:32 -0700 | [diff] [blame] | 688 | // Update visibility of activities before notifying WM. This way it won't try to resize |
| 689 | // windows that are no longer visible. |
| 690 | mStackSupervisor.ensureActivitiesVisibleLocked(null /* starting */, 0 /* configChanges */, |
| 691 | !PRESERVE_WINDOWS); |
Andrii Kulian | 839def9 | 2016-11-02 10:58:58 -0700 | [diff] [blame] | 692 | } |
| 693 | |
| 694 | /** |
| 695 | * Updates internal state after adding to new display. |
| 696 | * @param activityDisplay New display to which this stack was attached. |
| 697 | * @param bounds Updated bounds. |
| 698 | */ |
Wale Ogunwale | 04a05ac | 2017-09-17 21:35:02 -0700 | [diff] [blame] | 699 | private void postAddToDisplay(ActivityDisplay activityDisplay, Rect bounds, boolean onTop) { |
Filip Gruszczynski | e5390e7 | 2015-08-18 16:39:00 -0700 | [diff] [blame] | 700 | mDisplayId = activityDisplay.mDisplayId; |
Bryce Lee | f3c6a47 | 2017-11-14 14:53:06 -0800 | [diff] [blame] | 701 | setBounds(bounds); |
Andrii Kulian | 1779e61 | 2016-10-12 21:58:25 -0700 | [diff] [blame] | 702 | onParentChanged(); |
Wale Ogunwale | 961f485 | 2016-02-01 20:25:54 -0800 | [diff] [blame] | 703 | |
Wale Ogunwale | 9dcf946 | 2017-09-19 15:13:01 -0700 | [diff] [blame] | 704 | activityDisplay.addChild(this, onTop ? POSITION_TOP : POSITION_BOTTOM); |
Wale Ogunwale | 44f036f | 2017-09-29 05:09:09 -0700 | [diff] [blame] | 705 | if (inSplitScreenPrimaryWindowingMode()) { |
Wale Ogunwale | 961f485 | 2016-02-01 20:25:54 -0800 | [diff] [blame] | 706 | // If we created a docked stack we want to resize it so it resizes all other stacks |
| 707 | // in the system. |
| 708 | mStackSupervisor.resizeDockedStackLocked( |
Bryce Lee | f3c6a47 | 2017-11-14 14:53:06 -0800 | [diff] [blame] | 709 | getOverrideBounds(), null, null, null, null, PRESERVE_WINDOWS); |
Wale Ogunwale | 961f485 | 2016-02-01 20:25:54 -0800 | [diff] [blame] | 710 | } |
Filip Gruszczynski | e5390e7 | 2015-08-18 16:39:00 -0700 | [diff] [blame] | 711 | } |
| 712 | |
Andrii Kulian | 839def9 | 2016-11-02 10:58:58 -0700 | [diff] [blame] | 713 | /** |
Andrii Kulian | 839def9 | 2016-11-02 10:58:58 -0700 | [diff] [blame] | 714 | * Updates the inner state of the stack to remove it from its current parent, so it can be |
| 715 | * either destroyed completely or re-parented. |
| 716 | */ |
| 717 | private void removeFromDisplay() { |
Wale Ogunwale | 9dcf946 | 2017-09-19 15:13:01 -0700 | [diff] [blame] | 718 | final ActivityDisplay display = getDisplay(); |
| 719 | if (display != null) { |
| 720 | display.removeChild(this); |
| 721 | } |
| 722 | mDisplayId = INVALID_DISPLAY; |
Andrii Kulian | 839def9 | 2016-11-02 10:58:58 -0700 | [diff] [blame] | 723 | } |
| 724 | |
| 725 | /** Removes the stack completely. Also calls WindowManager to do the same on its side. */ |
| 726 | void remove() { |
| 727 | removeFromDisplay(); |
Wale Ogunwale | 1666e31 | 2016-12-16 11:27:18 -0800 | [diff] [blame] | 728 | mWindowContainerController.removeContainer(); |
| 729 | mWindowContainerController = null; |
Andrii Kulian | 6d6fb40 | 2016-10-26 16:15:25 -0700 | [diff] [blame] | 730 | onParentChanged(); |
Filip Gruszczynski | e5390e7 | 2015-08-18 16:39:00 -0700 | [diff] [blame] | 731 | } |
| 732 | |
Wale Ogunwale | 9dcf946 | 2017-09-19 15:13:01 -0700 | [diff] [blame] | 733 | ActivityDisplay getDisplay() { |
Andrii Kulian | 94e82d9b0 | 2017-07-13 15:33:06 -0700 | [diff] [blame] | 734 | return mStackSupervisor.getActivityDisplay(mDisplayId); |
| 735 | } |
| 736 | |
Matthew Ng | aa2b620 | 2017-02-10 14:48:21 -0800 | [diff] [blame] | 737 | /** |
Wale Ogunwale | 04a05ac | 2017-09-17 21:35:02 -0700 | [diff] [blame] | 738 | * @see #getStackDockedModeBounds(Rect, Rect, Rect, boolean) |
Matthew Ng | aa2b620 | 2017-02-10 14:48:21 -0800 | [diff] [blame] | 739 | */ |
| 740 | void getStackDockedModeBounds(Rect currentTempTaskBounds, Rect outStackBounds, |
| 741 | Rect outTempTaskBounds, boolean ignoreVisibility) { |
| 742 | mWindowContainerController.getStackDockedModeBounds(currentTempTaskBounds, |
| 743 | outStackBounds, outTempTaskBounds, ignoreVisibility); |
Wale Ogunwale | 1666e31 | 2016-12-16 11:27:18 -0800 | [diff] [blame] | 744 | } |
| 745 | |
| 746 | void prepareFreezingTaskBounds() { |
| 747 | mWindowContainerController.prepareFreezingTaskBounds(); |
| 748 | } |
| 749 | |
Wale Ogunwale | 1666e31 | 2016-12-16 11:27:18 -0800 | [diff] [blame] | 750 | void getWindowContainerBounds(Rect outBounds) { |
| 751 | if (mWindowContainerController != null) { |
| 752 | mWindowContainerController.getBounds(outBounds); |
Winson Chung | b00dc5e | 2017-01-25 09:44:25 -0800 | [diff] [blame] | 753 | return; |
Wale Ogunwale | 1666e31 | 2016-12-16 11:27:18 -0800 | [diff] [blame] | 754 | } |
| 755 | outBounds.setEmpty(); |
| 756 | } |
| 757 | |
Matthew Ng | aa2b620 | 2017-02-10 14:48:21 -0800 | [diff] [blame] | 758 | void getBoundsForNewConfiguration(Rect outBounds) { |
| 759 | mWindowContainerController.getBoundsForNewConfiguration(outBounds); |
Wale Ogunwale | 1666e31 | 2016-12-16 11:27:18 -0800 | [diff] [blame] | 760 | } |
| 761 | |
| 762 | void positionChildWindowContainerAtTop(TaskRecord child) { |
| 763 | mWindowContainerController.positionChildAtTop(child.getWindowContainerController(), |
| 764 | true /* includingParents */); |
| 765 | } |
| 766 | |
Jorim Jaggi | 192086e | 2016-03-11 17:17:03 +0100 | [diff] [blame] | 767 | /** |
Winson Chung | 8bca9e4 | 2017-04-16 15:59:43 -0700 | [diff] [blame] | 768 | * Returns whether to defer the scheduling of the multi-window mode. |
| 769 | */ |
| 770 | boolean deferScheduleMultiWindowModeChanged() { |
| 771 | return false; |
| 772 | } |
| 773 | |
| 774 | /** |
Jorim Jaggi | 192086e | 2016-03-11 17:17:03 +0100 | [diff] [blame] | 775 | * Defers updating the bounds of the stack. If the stack was resized/repositioned while |
| 776 | * deferring, the bounds will update in {@link #continueUpdateBounds()}. |
| 777 | */ |
| 778 | void deferUpdateBounds() { |
| 779 | if (!mUpdateBoundsDeferred) { |
| 780 | mUpdateBoundsDeferred = true; |
| 781 | mUpdateBoundsDeferredCalled = false; |
| 782 | } |
| 783 | } |
| 784 | |
| 785 | /** |
| 786 | * Continues updating bounds after updates have been deferred. If there was a resize attempt |
| 787 | * between {@link #deferUpdateBounds()} and {@link #continueUpdateBounds()}, the stack will |
| 788 | * be resized to that bounds. |
| 789 | */ |
| 790 | void continueUpdateBounds() { |
| 791 | final boolean wasDeferred = mUpdateBoundsDeferred; |
| 792 | mUpdateBoundsDeferred = false; |
| 793 | if (wasDeferred && mUpdateBoundsDeferredCalled) { |
Wale Ogunwale | 1666e31 | 2016-12-16 11:27:18 -0800 | [diff] [blame] | 794 | resize(mDeferredBounds.isEmpty() ? null : mDeferredBounds, |
Jorim Jaggi | 192086e | 2016-03-11 17:17:03 +0100 | [diff] [blame] | 795 | mDeferredTaskBounds.isEmpty() ? null : mDeferredTaskBounds, |
| 796 | mDeferredTaskInsetBounds.isEmpty() ? null : mDeferredTaskInsetBounds); |
| 797 | } |
| 798 | } |
| 799 | |
| 800 | boolean updateBoundsAllowed(Rect bounds, Rect tempTaskBounds, |
| 801 | Rect tempTaskInsetBounds) { |
| 802 | if (!mUpdateBoundsDeferred) { |
| 803 | return true; |
| 804 | } |
| 805 | if (bounds != null) { |
| 806 | mDeferredBounds.set(bounds); |
| 807 | } else { |
| 808 | mDeferredBounds.setEmpty(); |
| 809 | } |
| 810 | if (tempTaskBounds != null) { |
| 811 | mDeferredTaskBounds.set(tempTaskBounds); |
| 812 | } else { |
| 813 | mDeferredTaskBounds.setEmpty(); |
| 814 | } |
| 815 | if (tempTaskInsetBounds != null) { |
| 816 | mDeferredTaskInsetBounds.set(tempTaskInsetBounds); |
| 817 | } else { |
| 818 | mDeferredTaskInsetBounds.setEmpty(); |
| 819 | } |
| 820 | mUpdateBoundsDeferredCalled = true; |
| 821 | return false; |
| 822 | } |
| 823 | |
Bryce Lee | f3c6a47 | 2017-11-14 14:53:06 -0800 | [diff] [blame] | 824 | @Override |
| 825 | public int setBounds(Rect bounds) { |
| 826 | return super.setBounds(!inMultiWindowMode() ? null : bounds); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 827 | } |
Craig Mautner | 5962b12 | 2012-10-05 14:45:52 -0700 | [diff] [blame] | 828 | |
Wale Ogunwale | 42f07d9 | 2017-05-01 21:32:58 -0700 | [diff] [blame] | 829 | ActivityRecord topRunningActivityLocked() { |
Winson Chung | 3f103eb | 2017-04-12 21:53:59 -0700 | [diff] [blame] | 830 | return topRunningActivityLocked(false /* focusableOnly */); |
| 831 | } |
| 832 | |
Jorim Jaggi | ea039a8 | 2017-08-02 14:37:49 +0200 | [diff] [blame] | 833 | void getAllRunningVisibleActivitiesLocked(ArrayList<ActivityRecord> outActivities) { |
| 834 | outActivities.clear(); |
| 835 | for (int taskNdx = mTaskHistory.size() - 1; taskNdx >= 0; --taskNdx) { |
| 836 | mTaskHistory.get(taskNdx).getAllRunningVisibleActivitiesLocked(outActivities); |
| 837 | } |
| 838 | } |
| 839 | |
Wale Ogunwale | 42f07d9 | 2017-05-01 21:32:58 -0700 | [diff] [blame] | 840 | private ActivityRecord topRunningActivityLocked(boolean focusableOnly) { |
Craig Mautner | d74f7d7 | 2013-02-26 13:41:02 -0800 | [diff] [blame] | 841 | for (int taskNdx = mTaskHistory.size() - 1; taskNdx >= 0; --taskNdx) { |
Filip Gruszczynski | 3e85ba2 | 2015-10-05 22:48:30 -0700 | [diff] [blame] | 842 | ActivityRecord r = mTaskHistory.get(taskNdx).topRunningActivityLocked(); |
Winson Chung | 3f103eb | 2017-04-12 21:53:59 -0700 | [diff] [blame] | 843 | if (r != null && (!focusableOnly || r.isFocusable())) { |
Craig Mautner | 6b74cb5 | 2013-09-27 17:02:21 -0700 | [diff] [blame] | 844 | return r; |
Craig Mautner | 11bf9a5 | 2013-02-19 14:08:51 -0800 | [diff] [blame] | 845 | } |
| 846 | } |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 847 | return null; |
| 848 | } |
| 849 | |
Wale Ogunwale | 42f07d9 | 2017-05-01 21:32:58 -0700 | [diff] [blame] | 850 | ActivityRecord topRunningNonOverlayTaskActivity() { |
| 851 | for (int taskNdx = mTaskHistory.size() - 1; taskNdx >= 0; --taskNdx) { |
| 852 | final TaskRecord task = mTaskHistory.get(taskNdx); |
| 853 | final ArrayList<ActivityRecord> activities = task.mActivities; |
| 854 | for (int activityNdx = activities.size() - 1; activityNdx >= 0; --activityNdx) { |
| 855 | final ActivityRecord r = activities.get(activityNdx); |
| 856 | if (!r.finishing && !r.mTaskOverlay) { |
| 857 | return r; |
| 858 | } |
| 859 | } |
| 860 | } |
| 861 | return null; |
| 862 | } |
| 863 | |
| 864 | ActivityRecord topRunningNonDelayedActivityLocked(ActivityRecord notTop) { |
Craig Mautner | d74f7d7 | 2013-02-26 13:41:02 -0800 | [diff] [blame] | 865 | for (int taskNdx = mTaskHistory.size() - 1; taskNdx >= 0; --taskNdx) { |
| 866 | final TaskRecord task = mTaskHistory.get(taskNdx); |
Craig Mautner | 11bf9a5 | 2013-02-19 14:08:51 -0800 | [diff] [blame] | 867 | final ArrayList<ActivityRecord> activities = task.mActivities; |
Craig Mautner | d74f7d7 | 2013-02-26 13:41:02 -0800 | [diff] [blame] | 868 | for (int activityNdx = activities.size() - 1; activityNdx >= 0; --activityNdx) { |
| 869 | ActivityRecord r = activities.get(activityNdx); |
Chong Zhang | 8776197 | 2016-08-22 13:53:24 -0700 | [diff] [blame] | 870 | if (!r.finishing && !r.delayedResume && r != notTop && r.okToShowLocked()) { |
Craig Mautner | 11bf9a5 | 2013-02-19 14:08:51 -0800 | [diff] [blame] | 871 | return r; |
| 872 | } |
| 873 | } |
| 874 | } |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 875 | return null; |
| 876 | } |
| 877 | |
| 878 | /** |
| 879 | * This is a simplified version of topRunningActivityLocked that provides a number of |
| 880 | * 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] | 881 | * |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 882 | * @param token If non-null, any history records matching this token will be skipped. |
| 883 | * @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] | 884 | * |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 885 | * @return Returns the HistoryRecord of the next activity on the stack. |
| 886 | */ |
| 887 | final ActivityRecord topRunningActivityLocked(IBinder token, int taskId) { |
Craig Mautner | 11bf9a5 | 2013-02-19 14:08:51 -0800 | [diff] [blame] | 888 | for (int taskNdx = mTaskHistory.size() - 1; taskNdx >= 0; --taskNdx) { |
| 889 | TaskRecord task = mTaskHistory.get(taskNdx); |
| 890 | if (task.taskId == taskId) { |
| 891 | continue; |
| 892 | } |
| 893 | ArrayList<ActivityRecord> activities = task.mActivities; |
| 894 | for (int i = activities.size() - 1; i >= 0; --i) { |
| 895 | final ActivityRecord r = activities.get(i); |
| 896 | // Note: the taskId check depends on real taskId fields being non-zero |
Chong Zhang | 8776197 | 2016-08-22 13:53:24 -0700 | [diff] [blame] | 897 | if (!r.finishing && (token != r.appToken) && r.okToShowLocked()) { |
Craig Mautner | 11bf9a5 | 2013-02-19 14:08:51 -0800 | [diff] [blame] | 898 | return r; |
| 899 | } |
| 900 | } |
| 901 | } |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 902 | return null; |
| 903 | } |
| 904 | |
Wale Ogunwale | 30e441d | 2017-11-09 08:28:45 -0800 | [diff] [blame] | 905 | ActivityRecord getTopActivity() { |
Craig Mautner | 8849a5e | 2013-04-02 16:41:03 -0700 | [diff] [blame] | 906 | for (int taskNdx = mTaskHistory.size() - 1; taskNdx >= 0; --taskNdx) { |
Wale Ogunwale | 30e441d | 2017-11-09 08:28:45 -0800 | [diff] [blame] | 907 | final ActivityRecord r = mTaskHistory.get(taskNdx).getTopActivity(); |
| 908 | if (r != null) { |
| 909 | return r; |
Craig Mautner | 8849a5e | 2013-04-02 16:41:03 -0700 | [diff] [blame] | 910 | } |
| 911 | } |
Craig Mautner | de4ef02 | 2013-04-07 19:01:33 -0700 | [diff] [blame] | 912 | return null; |
Craig Mautner | 8849a5e | 2013-04-02 16:41:03 -0700 | [diff] [blame] | 913 | } |
| 914 | |
Craig Mautner | 9e14d0f | 2013-05-01 11:26:09 -0700 | [diff] [blame] | 915 | final TaskRecord topTask() { |
| 916 | final int size = mTaskHistory.size(); |
| 917 | if (size > 0) { |
| 918 | return mTaskHistory.get(size - 1); |
| 919 | } |
| 920 | return null; |
| 921 | } |
| 922 | |
Wale Ogunwale | 30e441d | 2017-11-09 08:28:45 -0800 | [diff] [blame] | 923 | private TaskRecord bottomTask() { |
Winson Chung | 1cebea6 | 2017-06-26 17:22:27 -0700 | [diff] [blame] | 924 | if (mTaskHistory.isEmpty()) { |
| 925 | return null; |
| 926 | } |
| 927 | return mTaskHistory.get(0); |
| 928 | } |
| 929 | |
Craig Mautner | d232895 | 2013-03-05 12:46:26 -0800 | [diff] [blame] | 930 | TaskRecord taskForIdLocked(int id) { |
| 931 | for (int taskNdx = mTaskHistory.size() - 1; taskNdx >= 0; --taskNdx) { |
| 932 | final TaskRecord task = mTaskHistory.get(taskNdx); |
| 933 | if (task.taskId == id) { |
| 934 | return task; |
Craig Mautner | 5d9c7be | 2013-02-15 14:02:56 -0800 | [diff] [blame] | 935 | } |
| 936 | } |
Dianne Hackborn | ce86ba8 | 2011-07-13 19:33:41 -0700 | [diff] [blame] | 937 | return null; |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 938 | } |
| 939 | |
Craig Mautner | d232895 | 2013-03-05 12:46:26 -0800 | [diff] [blame] | 940 | ActivityRecord isInStackLocked(IBinder token) { |
Wale Ogunwale | 7d70117 | 2015-03-11 15:36:30 -0700 | [diff] [blame] | 941 | final ActivityRecord r = ActivityRecord.forTokenLocked(token); |
Wale Ogunwale | 60454db | 2015-01-23 16:05:07 -0800 | [diff] [blame] | 942 | return isInStackLocked(r); |
| 943 | } |
| 944 | |
| 945 | ActivityRecord isInStackLocked(ActivityRecord r) { |
| 946 | if (r == null) { |
| 947 | return null; |
| 948 | } |
Bryce Lee | af691c0 | 2017-03-20 14:20:22 -0700 | [diff] [blame] | 949 | final TaskRecord task = r.getTask(); |
Andrii Kulian | 02b7a83 | 2016-10-06 23:11:56 -0700 | [diff] [blame] | 950 | final ActivityStack stack = r.getStack(); |
| 951 | if (stack != null && task.mActivities.contains(r) && mTaskHistory.contains(task)) { |
| 952 | if (stack != this) Slog.w(TAG, |
Craig Mautner | d232895 | 2013-03-05 12:46:26 -0800 | [diff] [blame] | 953 | "Illegal state! task does not point to stack it is in."); |
Wale Ogunwale | 60454db | 2015-01-23 16:05:07 -0800 | [diff] [blame] | 954 | return r; |
Craig Mautner | 5d9c7be | 2013-02-15 14:02:56 -0800 | [diff] [blame] | 955 | } |
Craig Mautner | d232895 | 2013-03-05 12:46:26 -0800 | [diff] [blame] | 956 | return null; |
Craig Mautner | 5d9c7be | 2013-02-15 14:02:56 -0800 | [diff] [blame] | 957 | } |
| 958 | |
Andrii Kulian | fb1bf69 | 2017-01-17 11:17:34 -0800 | [diff] [blame] | 959 | boolean isInStackLocked(TaskRecord task) { |
| 960 | return mTaskHistory.contains(task); |
| 961 | } |
| 962 | |
| 963 | /** Checks if there are tasks with specific UID in the stack. */ |
| 964 | boolean isUidPresent(int uid) { |
| 965 | for (TaskRecord task : mTaskHistory) { |
David Stevens | 82ea6cb | 2017-03-03 16:18:50 -0800 | [diff] [blame] | 966 | for (ActivityRecord r : task.mActivities) { |
| 967 | if (r.getUid() == uid) { |
| 968 | return true; |
| 969 | } |
Andrii Kulian | fb1bf69 | 2017-01-17 11:17:34 -0800 | [diff] [blame] | 970 | } |
| 971 | } |
| 972 | return false; |
| 973 | } |
| 974 | |
| 975 | /** Get all UIDs that are present in the stack. */ |
| 976 | void getPresentUIDs(IntArray presentUIDs) { |
| 977 | for (TaskRecord task : mTaskHistory) { |
David Stevens | 82ea6cb | 2017-03-03 16:18:50 -0800 | [diff] [blame] | 978 | for (ActivityRecord r : task.mActivities) { |
| 979 | presentUIDs.add(r.getUid()); |
| 980 | } |
Andrii Kulian | fb1bf69 | 2017-01-17 11:17:34 -0800 | [diff] [blame] | 981 | } |
| 982 | } |
| 983 | |
Winson Chung | abb433b | 2017-03-24 09:35:42 -0700 | [diff] [blame] | 984 | final void removeActivitiesFromLRUListLocked(TaskRecord task) { |
| 985 | for (ActivityRecord r : task.mActivities) { |
| 986 | mLRUActivities.remove(r); |
| 987 | } |
| 988 | } |
| 989 | |
Craig Mautner | 2420ead | 2013-04-01 17:13:20 -0700 | [diff] [blame] | 990 | final boolean updateLRUListLocked(ActivityRecord r) { |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 991 | final boolean hadit = mLRUActivities.remove(r); |
| 992 | mLRUActivities.add(r); |
| 993 | return hadit; |
| 994 | } |
| 995 | |
Matthew Ng | ae1ff4f | 2016-11-10 15:49:14 -0800 | [diff] [blame] | 996 | final boolean isHomeOrRecentsStack() { |
Wale Ogunwale | 6827856 | 2017-09-23 17:13:55 -0700 | [diff] [blame] | 997 | return isActivityTypeHome() || isActivityTypeRecents(); |
Matthew Ng | ae1ff4f | 2016-11-10 15:49:14 -0800 | [diff] [blame] | 998 | } |
| 999 | |
Craig Mautner | e0a3884 | 2013-12-16 16:14:02 -0800 | [diff] [blame] | 1000 | final boolean isOnHomeDisplay() { |
Wale Ogunwale | 9dcf946 | 2017-09-19 15:13:01 -0700 | [diff] [blame] | 1001 | return mDisplayId == DEFAULT_DISPLAY; |
Craig Mautner | e0a3884 | 2013-12-16 16:14:02 -0800 | [diff] [blame] | 1002 | } |
| 1003 | |
Wale Ogunwale | 66e1685 | 2017-10-19 13:35:52 -0700 | [diff] [blame] | 1004 | private boolean returnsToHomeStack() { |
| 1005 | return !inMultiWindowMode() |
| 1006 | && !mTaskHistory.isEmpty() |
| 1007 | && mTaskHistory.get(0).returnsToHomeStack(); |
| 1008 | } |
| 1009 | |
Wale Ogunwale | eae451e | 2015-08-04 15:20:50 -0700 | [diff] [blame] | 1010 | void moveToFront(String reason) { |
| 1011 | moveToFront(reason, null); |
| 1012 | } |
| 1013 | |
| 1014 | /** |
| 1015 | * @param reason The reason for moving the stack to the front. |
| 1016 | * @param task If non-null, the task will be moved to the top of the stack. |
| 1017 | * */ |
| 1018 | void moveToFront(String reason, TaskRecord task) { |
Wale Ogunwale | 1e60e0c | 2015-10-28 13:36:10 -0700 | [diff] [blame] | 1019 | if (!isAttached()) { |
| 1020 | return; |
| 1021 | } |
Wale Ogunwale | 925d0d1 | 2015-09-23 15:40:07 -0700 | [diff] [blame] | 1022 | |
Wale Ogunwale | bb28587 | 2018-03-01 13:05:30 -0800 | [diff] [blame] | 1023 | final ActivityDisplay display = getDisplay(); |
| 1024 | |
| 1025 | if (inSplitScreenSecondaryWindowingMode()) { |
| 1026 | // If the stack is in split-screen seconardy mode, we need to make sure we move the |
| 1027 | // primary split-screen stack forward in the case it is currently behind a fullscreen |
| 1028 | // stack so both halves of the split-screen appear on-top and the fullscreen stack isn't |
| 1029 | // cutting between them. |
| 1030 | // TODO(b/70677280): This is a workaround until we can fix as part of b/70677280. |
| 1031 | final ActivityStack topFullScreenStack = |
| 1032 | display.getTopStackInWindowingMode(WINDOWING_MODE_FULLSCREEN); |
| 1033 | if (topFullScreenStack != null) { |
| 1034 | final ActivityStack primarySplitScreenStack = display.getSplitScreenPrimaryStack(); |
| 1035 | if (display.getIndexOf(topFullScreenStack) |
| 1036 | > display.getIndexOf(primarySplitScreenStack)) { |
| 1037 | primarySplitScreenStack.moveToFront(reason + " splitScreenToTop"); |
| 1038 | } |
| 1039 | } |
| 1040 | } |
| 1041 | |
Wale Ogunwale | 66e1685 | 2017-10-19 13:35:52 -0700 | [diff] [blame] | 1042 | if (!isActivityTypeHome() && returnsToHomeStack()) { |
| 1043 | // Make sure the home stack is behind this stack since that is where we should return to |
| 1044 | // when this stack is no longer visible. |
| 1045 | mStackSupervisor.moveHomeStackToFront(reason + " returnToHome"); |
| 1046 | } |
| 1047 | |
Wale Ogunwale | bb28587 | 2018-03-01 13:05:30 -0800 | [diff] [blame] | 1048 | display.positionChildAtTop(this); |
Andrii Kulian | 839def9 | 2016-11-02 10:58:58 -0700 | [diff] [blame] | 1049 | mStackSupervisor.setFocusStackUnchecked(reason, this); |
Wale Ogunwale | 1e60e0c | 2015-10-28 13:36:10 -0700 | [diff] [blame] | 1050 | if (task != null) { |
| 1051 | insertTaskAtTop(task, null); |
Wale Ogunwale | aa47c12 | 2016-09-23 16:39:53 -0700 | [diff] [blame] | 1052 | return; |
Wale Ogunwale | 1e60e0c | 2015-10-28 13:36:10 -0700 | [diff] [blame] | 1053 | } |
Craig Mautner | e0a3884 | 2013-12-16 16:14:02 -0800 | [diff] [blame] | 1054 | } |
| 1055 | |
Evan Rosky | 9c44817 | 2017-11-02 14:19:27 -0700 | [diff] [blame] | 1056 | /** |
| 1057 | * @param reason The reason for moving the stack to the back. |
| 1058 | * @param task If non-null, the task will be moved to the bottom of the stack. |
| 1059 | **/ |
| 1060 | void moveToBack(String reason, TaskRecord task) { |
| 1061 | if (!isAttached()) { |
| 1062 | return; |
| 1063 | } |
| 1064 | |
Bryce Lee | 8cab4a0 | 2018-01-05 09:00:49 -0800 | [diff] [blame] | 1065 | /** |
| 1066 | * The intent behind moving a primary split screen stack to the back is usually to hide |
| 1067 | * behind the home stack. Exit split screen in this case. |
| 1068 | */ |
| 1069 | if (getWindowingMode() == WINDOWING_MODE_SPLIT_SCREEN_PRIMARY) { |
| 1070 | setWindowingMode(WINDOWING_MODE_FULLSCREEN); |
| 1071 | } |
| 1072 | |
Evan Rosky | 9c44817 | 2017-11-02 14:19:27 -0700 | [diff] [blame] | 1073 | getDisplay().positionChildAtBottom(this); |
| 1074 | mStackSupervisor.setFocusStackUnchecked(reason, getDisplay().getTopStack()); |
| 1075 | if (task != null) { |
| 1076 | insertTaskAtBottom(task); |
| 1077 | return; |
Evan Rosky | 9c44817 | 2017-11-02 14:19:27 -0700 | [diff] [blame] | 1078 | } |
| 1079 | } |
| 1080 | |
Wale Ogunwale | d046a01 | 2015-12-24 13:05:59 -0800 | [diff] [blame] | 1081 | boolean isFocusable() { |
Wale Ogunwale | 4cea0f5 | 2015-12-25 06:30:31 -0800 | [diff] [blame] | 1082 | final ActivityRecord r = topRunningActivityLocked(); |
Bryce Lee | 7b851cc | 2018-04-10 14:53:13 -0700 | [diff] [blame] | 1083 | return mStackSupervisor.isFocusable(this, r != null && r.isFocusable()); |
Wale Ogunwale | d046a01 | 2015-12-24 13:05:59 -0800 | [diff] [blame] | 1084 | } |
| 1085 | |
Craig Mautner | e0a3884 | 2013-12-16 16:14:02 -0800 | [diff] [blame] | 1086 | final boolean isAttached() { |
Wale Ogunwale | 9dcf946 | 2017-09-19 15:13:01 -0700 | [diff] [blame] | 1087 | return getParent() != null; |
Craig Mautner | 4a1cb22 | 2013-12-04 16:14:06 -0800 | [diff] [blame] | 1088 | } |
| 1089 | |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 1090 | /** |
Wale Ogunwale | 3938197 | 2015-12-17 17:15:29 -0800 | [diff] [blame] | 1091 | * Returns the top activity in any existing task matching the given Intent in the input result. |
| 1092 | * Returns null if no such task is found. |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 1093 | */ |
Wale Ogunwale | 3938197 | 2015-12-17 17:15:29 -0800 | [diff] [blame] | 1094 | void findTaskLocked(ActivityRecord target, FindTaskResult result) { |
Craig Mautner | ac6f843 | 2013-07-17 13:24:59 -0700 | [diff] [blame] | 1095 | Intent intent = target.intent; |
| 1096 | ActivityInfo info = target.info; |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 1097 | ComponentName cls = intent.getComponent(); |
| 1098 | if (info.targetActivity != null) { |
| 1099 | cls = new ComponentName(info.packageName, info.targetActivity); |
| 1100 | } |
Dianne Hackborn | f02b60a | 2012-08-16 10:48:27 -0700 | [diff] [blame] | 1101 | final int userId = UserHandle.getUserId(info.applicationInfo.uid); |
Craig Mautner | d00f474 | 2014-03-12 14:17:26 -0700 | [diff] [blame] | 1102 | boolean isDocument = intent != null & intent.isDocument(); |
| 1103 | // If documentData is non-null then it must match the existing task data. |
| 1104 | Uri documentData = isDocument ? intent.getData() : null; |
Craig Mautner | 000f002 | 2013-02-26 15:04:29 -0800 | [diff] [blame] | 1105 | |
Wale Ogunwale | ee006da | 2015-03-30 14:49:25 -0700 | [diff] [blame] | 1106 | 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] | 1107 | for (int taskNdx = mTaskHistory.size() - 1; taskNdx >= 0; --taskNdx) { |
| 1108 | final TaskRecord task = mTaskHistory.get(taskNdx); |
Dianne Hackborn | 91097de | 2014-04-04 18:02:06 -0700 | [diff] [blame] | 1109 | if (task.voiceSession != null) { |
| 1110 | // We never match voice sessions; those always run independently. |
Wale Ogunwale | ee006da | 2015-03-30 14:49:25 -0700 | [diff] [blame] | 1111 | if (DEBUG_TASKS) Slog.d(TAG_TASKS, "Skipping " + task + ": voice session"); |
Dianne Hackborn | 91097de | 2014-04-04 18:02:06 -0700 | [diff] [blame] | 1112 | continue; |
| 1113 | } |
Craig Mautner | ac6f843 | 2013-07-17 13:24:59 -0700 | [diff] [blame] | 1114 | if (task.userId != userId) { |
| 1115 | // Looking for a different task. |
Wale Ogunwale | ee006da | 2015-03-30 14:49:25 -0700 | [diff] [blame] | 1116 | if (DEBUG_TASKS) Slog.d(TAG_TASKS, "Skipping " + task + ": different user"); |
Craig Mautner | ac6f843 | 2013-07-17 13:24:59 -0700 | [diff] [blame] | 1117 | continue; |
| 1118 | } |
Bryce Lee | 9f6affd | 2017-09-01 09:18:35 -0700 | [diff] [blame] | 1119 | |
| 1120 | // Overlays should not be considered as the task's logical top activity. |
| 1121 | final ActivityRecord r = task.getTopActivity(false /* includeOverlays */); |
Craig Mautner | 000f002 | 2013-02-26 15:04:29 -0800 | [diff] [blame] | 1122 | if (r == null || r.finishing || r.userId != userId || |
| 1123 | r.launchMode == ActivityInfo.LAUNCH_SINGLE_INSTANCE) { |
Wale Ogunwale | ee006da | 2015-03-30 14:49:25 -0700 | [diff] [blame] | 1124 | if (DEBUG_TASKS) Slog.d(TAG_TASKS, "Skipping " + task + ": mismatch root " + r); |
Craig Mautner | 000f002 | 2013-02-26 15:04:29 -0800 | [diff] [blame] | 1125 | continue; |
| 1126 | } |
Wale Ogunwale | 6fbde9f | 2017-08-24 07:24:12 -0700 | [diff] [blame] | 1127 | if (!r.hasCompatibleActivityType(target)) { |
Chong Zhang | b546f7e | 2015-08-05 14:21:36 -0700 | [diff] [blame] | 1128 | if (DEBUG_TASKS) Slog.d(TAG_TASKS, "Skipping " + task + ": mismatch activity type"); |
| 1129 | continue; |
| 1130 | } |
Craig Mautner | 000f002 | 2013-02-26 15:04:29 -0800 | [diff] [blame] | 1131 | |
Craig Mautner | d00f474 | 2014-03-12 14:17:26 -0700 | [diff] [blame] | 1132 | final Intent taskIntent = task.intent; |
| 1133 | final Intent affinityIntent = task.affinityIntent; |
| 1134 | final boolean taskIsDocument; |
| 1135 | final Uri taskDocumentData; |
| 1136 | if (taskIntent != null && taskIntent.isDocument()) { |
| 1137 | taskIsDocument = true; |
| 1138 | taskDocumentData = taskIntent.getData(); |
| 1139 | } else if (affinityIntent != null && affinityIntent.isDocument()) { |
| 1140 | taskIsDocument = true; |
| 1141 | taskDocumentData = affinityIntent.getData(); |
| 1142 | } else { |
| 1143 | taskIsDocument = false; |
| 1144 | taskDocumentData = null; |
| 1145 | } |
| 1146 | |
Wale Ogunwale | ee006da | 2015-03-30 14:49:25 -0700 | [diff] [blame] | 1147 | if (DEBUG_TASKS) Slog.d(TAG_TASKS, "Comparing existing cls=" |
Craig Mautner | d00f474 | 2014-03-12 14:17:26 -0700 | [diff] [blame] | 1148 | + taskIntent.getComponent().flattenToShortString() |
Bryce Lee | af691c0 | 2017-03-20 14:20:22 -0700 | [diff] [blame] | 1149 | + "/aff=" + r.getTask().rootAffinity + " to new cls=" |
Dianne Hackborn | 2a272d4 | 2013-10-16 13:34:33 -0700 | [diff] [blame] | 1150 | + intent.getComponent().flattenToShortString() + "/aff=" + info.taskAffinity); |
Andrii Kulian | 206b9fa | 2016-06-02 13:18:01 -0700 | [diff] [blame] | 1151 | // TODO Refactor to remove duplications. Check if logic can be simplified. |
| 1152 | if (taskIntent != null && taskIntent.getComponent() != null && |
Craig Mautner | ffcfcaa | 2014-06-05 09:54:38 -0700 | [diff] [blame] | 1153 | taskIntent.getComponent().compareTo(cls) == 0 && |
Craig Mautner | d00f474 | 2014-03-12 14:17:26 -0700 | [diff] [blame] | 1154 | Objects.equals(documentData, taskDocumentData)) { |
Wale Ogunwale | ee006da | 2015-03-30 14:49:25 -0700 | [diff] [blame] | 1155 | if (DEBUG_TASKS) Slog.d(TAG_TASKS, "Found matching class!"); |
Craig Mautner | 000f002 | 2013-02-26 15:04:29 -0800 | [diff] [blame] | 1156 | //dump(); |
Wale Ogunwale | ee006da | 2015-03-30 14:49:25 -0700 | [diff] [blame] | 1157 | if (DEBUG_TASKS) Slog.d(TAG_TASKS, |
| 1158 | "For Intent " + intent + " bringing to top: " + r.intent); |
Wale Ogunwale | 3938197 | 2015-12-17 17:15:29 -0800 | [diff] [blame] | 1159 | result.r = r; |
| 1160 | result.matchedByRootAffinity = false; |
| 1161 | break; |
Craig Mautner | ffcfcaa | 2014-06-05 09:54:38 -0700 | [diff] [blame] | 1162 | } else if (affinityIntent != null && affinityIntent.getComponent() != null && |
| 1163 | affinityIntent.getComponent().compareTo(cls) == 0 && |
Craig Mautner | d00f474 | 2014-03-12 14:17:26 -0700 | [diff] [blame] | 1164 | Objects.equals(documentData, taskDocumentData)) { |
Wale Ogunwale | ee006da | 2015-03-30 14:49:25 -0700 | [diff] [blame] | 1165 | if (DEBUG_TASKS) Slog.d(TAG_TASKS, "Found matching class!"); |
Craig Mautner | 000f002 | 2013-02-26 15:04:29 -0800 | [diff] [blame] | 1166 | //dump(); |
Wale Ogunwale | ee006da | 2015-03-30 14:49:25 -0700 | [diff] [blame] | 1167 | if (DEBUG_TASKS) Slog.d(TAG_TASKS, |
| 1168 | "For Intent " + intent + " bringing to top: " + r.intent); |
Wale Ogunwale | 3938197 | 2015-12-17 17:15:29 -0800 | [diff] [blame] | 1169 | result.r = r; |
| 1170 | result.matchedByRootAffinity = false; |
| 1171 | break; |
Andrii Kulian | 206b9fa | 2016-06-02 13:18:01 -0700 | [diff] [blame] | 1172 | } else if (!isDocument && !taskIsDocument |
Winson Chung | 5b895b7 | 2017-05-01 13:46:25 -0700 | [diff] [blame] | 1173 | && result.r == null && task.rootAffinity != null) { |
Andrii Kulian | 206b9fa | 2016-06-02 13:18:01 -0700 | [diff] [blame] | 1174 | if (task.rootAffinity.equals(target.taskAffinity)) { |
| 1175 | if (DEBUG_TASKS) Slog.d(TAG_TASKS, "Found matching affinity candidate!"); |
| 1176 | // It is possible for multiple tasks to have the same root affinity especially |
| 1177 | // if they are in separate stacks. We save off this candidate, but keep looking |
| 1178 | // to see if there is a better candidate. |
| 1179 | result.r = r; |
| 1180 | result.matchedByRootAffinity = true; |
| 1181 | } |
Wale Ogunwale | ee006da | 2015-03-30 14:49:25 -0700 | [diff] [blame] | 1182 | } else if (DEBUG_TASKS) Slog.d(TAG_TASKS, "Not a match: " + task); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 1183 | } |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 1184 | } |
| 1185 | |
| 1186 | /** |
| 1187 | * Returns the first activity (starting from the top of the stack) that |
| 1188 | * is the same as the given activity. Returns null if no such activity |
| 1189 | * is found. |
| 1190 | */ |
Andrii Kulian | d3bbb13 | 2016-06-16 16:00:20 -0700 | [diff] [blame] | 1191 | ActivityRecord findActivityLocked(Intent intent, ActivityInfo info, |
| 1192 | boolean compareIntentFilters) { |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 1193 | ComponentName cls = intent.getComponent(); |
| 1194 | if (info.targetActivity != null) { |
| 1195 | cls = new ComponentName(info.packageName, info.targetActivity); |
| 1196 | } |
Dianne Hackborn | f02b60a | 2012-08-16 10:48:27 -0700 | [diff] [blame] | 1197 | final int userId = UserHandle.getUserId(info.applicationInfo.uid); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 1198 | |
Craig Mautner | 000f002 | 2013-02-26 15:04:29 -0800 | [diff] [blame] | 1199 | for (int taskNdx = mTaskHistory.size() - 1; taskNdx >= 0; --taskNdx) { |
Wale Ogunwale | 3fcb4a8 | 2015-04-06 14:00:13 -0700 | [diff] [blame] | 1200 | final TaskRecord task = mTaskHistory.get(taskNdx); |
Craig Mautner | ac6f843 | 2013-07-17 13:24:59 -0700 | [diff] [blame] | 1201 | final ArrayList<ActivityRecord> activities = task.mActivities; |
Wale Ogunwale | 3fcb4a8 | 2015-04-06 14:00:13 -0700 | [diff] [blame] | 1202 | |
Craig Mautner | 000f002 | 2013-02-26 15:04:29 -0800 | [diff] [blame] | 1203 | for (int activityNdx = activities.size() - 1; activityNdx >= 0; --activityNdx) { |
| 1204 | ActivityRecord r = activities.get(activityNdx); |
Chong Zhang | 8776197 | 2016-08-22 13:53:24 -0700 | [diff] [blame] | 1205 | if (!r.okToShowLocked()) { |
Wale Ogunwale | 25073dd | 2015-07-21 16:54:54 -0700 | [diff] [blame] | 1206 | continue; |
Wale Ogunwale | 3fcb4a8 | 2015-04-06 14:00:13 -0700 | [diff] [blame] | 1207 | } |
Andrii Kulian | d3bbb13 | 2016-06-16 16:00:20 -0700 | [diff] [blame] | 1208 | if (!r.finishing && r.userId == userId) { |
| 1209 | if (compareIntentFilters) { |
| 1210 | if (r.intent.filterEquals(intent)) { |
| 1211 | return r; |
| 1212 | } |
| 1213 | } else { |
| 1214 | if (r.intent.getComponent().equals(cls)) { |
| 1215 | return r; |
| 1216 | } |
| 1217 | } |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 1218 | } |
| 1219 | } |
| 1220 | } |
| 1221 | |
| 1222 | return null; |
| 1223 | } |
| 1224 | |
Amith Yamasani | 742a671 | 2011-05-04 14:49:28 -0700 | [diff] [blame] | 1225 | /* |
Craig Mautner | ac6f843 | 2013-07-17 13:24:59 -0700 | [diff] [blame] | 1226 | * 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] | 1227 | */ |
Craig Mautner | 93529a4 | 2013-10-04 15:03:13 -0700 | [diff] [blame] | 1228 | final void switchUserLocked(int userId) { |
Craig Mautner | 5d9c7be | 2013-02-15 14:02:56 -0800 | [diff] [blame] | 1229 | if (mCurrentUser == userId) { |
Craig Mautner | 93529a4 | 2013-10-04 15:03:13 -0700 | [diff] [blame] | 1230 | return; |
Craig Mautner | 5d9c7be | 2013-02-15 14:02:56 -0800 | [diff] [blame] | 1231 | } |
| 1232 | mCurrentUser = userId; |
| 1233 | |
| 1234 | // Move userId's tasks to the top. |
Craig Mautner | 5d9c7be | 2013-02-15 14:02:56 -0800 | [diff] [blame] | 1235 | int index = mTaskHistory.size(); |
Craig Mautner | db5c4fb | 2013-11-06 13:55:08 -0800 | [diff] [blame] | 1236 | for (int i = 0; i < index; ) { |
Wale Ogunwale | 3fcb4a8 | 2015-04-06 14:00:13 -0700 | [diff] [blame] | 1237 | final TaskRecord task = mTaskHistory.get(i); |
| 1238 | |
Chong Zhang | 8776197 | 2016-08-22 13:53:24 -0700 | [diff] [blame] | 1239 | if (task.okToShowLocked()) { |
Wale Ogunwale | ee006da | 2015-03-30 14:49:25 -0700 | [diff] [blame] | 1240 | if (DEBUG_TASKS) Slog.d(TAG_TASKS, "switchUserLocked: stack=" + getStackId() + |
Craig Mautner | 4f1df4f | 2013-10-15 15:44:14 -0700 | [diff] [blame] | 1241 | " moving " + task + " to top"); |
Craig Mautner | 5d9c7be | 2013-02-15 14:02:56 -0800 | [diff] [blame] | 1242 | mTaskHistory.remove(i); |
| 1243 | mTaskHistory.add(task); |
| 1244 | --index; |
Craig Mautner | db5c4fb | 2013-11-06 13:55:08 -0800 | [diff] [blame] | 1245 | // Use same value for i. |
| 1246 | } else { |
| 1247 | ++i; |
Craig Mautner | 5d9c7be | 2013-02-15 14:02:56 -0800 | [diff] [blame] | 1248 | } |
| 1249 | } |
Amith Yamasani | 742a671 | 2011-05-04 14:49:28 -0700 | [diff] [blame] | 1250 | } |
| 1251 | |
Craig Mautner | 2420ead | 2013-04-01 17:13:20 -0700 | [diff] [blame] | 1252 | void minimalResumeActivityLocked(ActivityRecord r) { |
Wale Ogunwale | 5658e4b | 2016-02-12 12:22:19 -0800 | [diff] [blame] | 1253 | if (DEBUG_STATES) Slog.v(TAG_STATES, "Moving to RESUMED: " + r + " (starting new instance)" |
| 1254 | + " callers=" + Debug.getCallers(5)); |
Bryce Lee | c4ab62a | 2018-03-05 14:19:26 -0800 | [diff] [blame] | 1255 | r.setState(RESUMED, "minimalResumeActivityLocked"); |
Andrii Kulian | 21713ac | 2016-10-12 22:05:05 -0700 | [diff] [blame] | 1256 | r.completeResumeLocked(); |
Wale Ogunwale | 0fc365c | 2015-05-25 19:35:42 -0700 | [diff] [blame] | 1257 | if (DEBUG_SAVED_STATE) Slog.i(TAG_SAVED_STATE, |
| 1258 | "Launch completed; removing icicle of " + r.icicle); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 1259 | } |
| 1260 | |
Andrii Kulian | 21713ac | 2016-10-12 22:05:05 -0700 | [diff] [blame] | 1261 | private void clearLaunchTime(ActivityRecord r) { |
Craig Mautner | 5c49454 | 2013-09-06 11:59:38 -0700 | [diff] [blame] | 1262 | // Make sure that there is no activity waiting for this to launch. |
Vishnu Nair | cf23504 | 2018-11-02 13:27:00 -0700 | [diff] [blame] | 1263 | if (!mStackSupervisor.mWaitingActivityLaunched.isEmpty()) { |
Craig Mautner | 5c49454 | 2013-09-06 11:59:38 -0700 | [diff] [blame] | 1264 | mStackSupervisor.removeTimeoutsForActivityLocked(r); |
| 1265 | mStackSupervisor.scheduleIdleTimeoutLocked(r); |
| 1266 | } |
Dianne Hackborn | 2286cdc | 2013-07-01 19:10:06 -0700 | [diff] [blame] | 1267 | } |
| 1268 | |
Dianne Hackborn | 4eba96b | 2011-01-21 13:34:36 -0800 | [diff] [blame] | 1269 | void awakeFromSleepingLocked() { |
Dianne Hackborn | 4eba96b | 2011-01-21 13:34:36 -0800 | [diff] [blame] | 1270 | // Ensure activities are no longer sleeping. |
Craig Mautner | d44711d | 2013-02-23 11:24:36 -0800 | [diff] [blame] | 1271 | for (int taskNdx = mTaskHistory.size() - 1; taskNdx >= 0; --taskNdx) { |
| 1272 | final ArrayList<ActivityRecord> activities = mTaskHistory.get(taskNdx).mActivities; |
| 1273 | for (int activityNdx = activities.size() - 1; activityNdx >= 0; --activityNdx) { |
| 1274 | activities.get(activityNdx).setSleeping(false); |
| 1275 | } |
Dianne Hackborn | 4eba96b | 2011-01-21 13:34:36 -0800 | [diff] [blame] | 1276 | } |
Craig Mautner | f49b0a4 | 2014-11-20 15:06:40 -0800 | [diff] [blame] | 1277 | if (mPausingActivity != null) { |
| 1278 | Slog.d(TAG, "awakeFromSleepingLocked: previously pausing activity didn't pause"); |
| 1279 | activityPausedLocked(mPausingActivity.appToken, true); |
| 1280 | } |
Dianne Hackborn | 4eba96b | 2011-01-21 13:34:36 -0800 | [diff] [blame] | 1281 | } |
| 1282 | |
Todd Kennedy | 39bfee5 | 2016-02-24 10:28:21 -0800 | [diff] [blame] | 1283 | void updateActivityApplicationInfoLocked(ApplicationInfo aInfo) { |
| 1284 | final String packageName = aInfo.packageName; |
Makoto Onuki | 8b9963a | 2017-05-18 13:56:30 -0700 | [diff] [blame] | 1285 | final int userId = UserHandle.getUserId(aInfo.uid); |
| 1286 | |
Todd Kennedy | 39bfee5 | 2016-02-24 10:28:21 -0800 | [diff] [blame] | 1287 | for (int taskNdx = mTaskHistory.size() - 1; taskNdx >= 0; --taskNdx) { |
| 1288 | final List<ActivityRecord> activities = mTaskHistory.get(taskNdx).mActivities; |
| 1289 | for (int activityNdx = activities.size() - 1; activityNdx >= 0; --activityNdx) { |
Makoto Onuki | 8b9963a | 2017-05-18 13:56:30 -0700 | [diff] [blame] | 1290 | final ActivityRecord ar = activities.get(activityNdx); |
| 1291 | |
| 1292 | if ((userId == ar.userId) && packageName.equals(ar.packageName)) { |
Philip P. Moltmann | cff8f0f | 2018-03-27 12:51:51 -0700 | [diff] [blame] | 1293 | ar.updateApplicationInfo(aInfo); |
Todd Kennedy | 39bfee5 | 2016-02-24 10:28:21 -0800 | [diff] [blame] | 1294 | } |
| 1295 | } |
| 1296 | } |
| 1297 | } |
| 1298 | |
David Stevens | 9440dc8 | 2017-03-16 19:00:20 -0700 | [diff] [blame] | 1299 | void checkReadyForSleep() { |
| 1300 | if (shouldSleepActivities() && goToSleepIfPossible(false /* shuttingDown */)) { |
| 1301 | mStackSupervisor.checkReadyForSleepLocked(true /* allowDelay */); |
| 1302 | } |
| 1303 | } |
| 1304 | |
Craig Mautner | 0eea92c | 2013-05-16 13:35:39 -0700 | [diff] [blame] | 1305 | /** |
David Stevens | 9440dc8 | 2017-03-16 19:00:20 -0700 | [diff] [blame] | 1306 | * Tries to put the activities in the stack to sleep. |
| 1307 | * |
| 1308 | * If the stack is not in a state where its activities can be put to sleep, this function will |
| 1309 | * start any necessary actions to move the stack into such a state. It is expected that this |
| 1310 | * function get called again when those actions complete. |
| 1311 | * |
| 1312 | * @param shuttingDown true when the called because the device is shutting down. |
David Stevens | 18abd0e | 2017-08-17 14:55:47 -0700 | [diff] [blame] | 1313 | * @return true if the stack finished going to sleep, false if the stack only started the |
| 1314 | * 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] | 1315 | */ |
David Stevens | 9440dc8 | 2017-03-16 19:00:20 -0700 | [diff] [blame] | 1316 | boolean goToSleepIfPossible(boolean shuttingDown) { |
| 1317 | boolean shouldSleep = true; |
| 1318 | |
Craig Mautner | 0eea92c | 2013-05-16 13:35:39 -0700 | [diff] [blame] | 1319 | if (mResumedActivity != null) { |
| 1320 | // Still have something resumed; can't sleep until it is paused. |
Wale Ogunwale | ee006da | 2015-03-30 14:49:25 -0700 | [diff] [blame] | 1321 | if (DEBUG_PAUSE) Slog.v(TAG_PAUSE, "Sleep needs to pause " + mResumedActivity); |
| 1322 | if (DEBUG_USER_LEAVING) Slog.v(TAG_USER_LEAVING, |
| 1323 | "Sleep => pause with userLeaving=false"); |
Bryce Lee | 5daa312 | 2017-04-19 10:40:42 -0700 | [diff] [blame] | 1324 | |
chaviw | a1d6853 | 2018-03-16 15:33:43 -0700 | [diff] [blame] | 1325 | startPausingLocked(false, true, null, false); |
David Stevens | 9440dc8 | 2017-03-16 19:00:20 -0700 | [diff] [blame] | 1326 | shouldSleep = false ; |
| 1327 | } else if (mPausingActivity != null) { |
Craig Mautner | 0eea92c | 2013-05-16 13:35:39 -0700 | [diff] [blame] | 1328 | // Still waiting for something to pause; can't sleep yet. |
Wale Ogunwale | ee006da | 2015-03-30 14:49:25 -0700 | [diff] [blame] | 1329 | 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] | 1330 | shouldSleep = false; |
Dianne Hackborn | 4eba96b | 2011-01-21 13:34:36 -0800 | [diff] [blame] | 1331 | } |
David Stevens | 9440dc8 | 2017-03-16 19:00:20 -0700 | [diff] [blame] | 1332 | |
| 1333 | if (!shuttingDown) { |
| 1334 | if (containsActivityFromStack(mStackSupervisor.mStoppingActivities)) { |
| 1335 | // Still need to tell some activities to stop; can't sleep yet. |
| 1336 | if (DEBUG_PAUSE) Slog.v(TAG_PAUSE, "Sleep still need to stop " |
| 1337 | + mStackSupervisor.mStoppingActivities.size() + " activities"); |
| 1338 | |
| 1339 | mStackSupervisor.scheduleIdleLocked(); |
| 1340 | shouldSleep = false; |
| 1341 | } |
| 1342 | |
| 1343 | if (containsActivityFromStack(mStackSupervisor.mGoingToSleepActivities)) { |
| 1344 | // Still need to tell some activities to sleep; can't sleep yet. |
| 1345 | if (DEBUG_PAUSE) Slog.v(TAG_PAUSE, "Sleep still need to sleep " |
| 1346 | + mStackSupervisor.mGoingToSleepActivities.size() + " activities"); |
| 1347 | shouldSleep = false; |
| 1348 | } |
| 1349 | } |
| 1350 | |
| 1351 | if (shouldSleep) { |
| 1352 | goToSleep(); |
| 1353 | } |
| 1354 | |
David Stevens | 18abd0e | 2017-08-17 14:55:47 -0700 | [diff] [blame] | 1355 | return shouldSleep; |
Craig Mautner | 0eea92c | 2013-05-16 13:35:39 -0700 | [diff] [blame] | 1356 | } |
Dianne Hackborn | 4eba96b | 2011-01-21 13:34:36 -0800 | [diff] [blame] | 1357 | |
David Stevens | 18abd0e | 2017-08-17 14:55:47 -0700 | [diff] [blame] | 1358 | void goToSleep() { |
Andrii Kulian | f4479ee | 2018-05-23 17:52:48 -0700 | [diff] [blame] | 1359 | // Ensure visibility without updating configuration, as activities are about to sleep. |
Andrii Kulian | a39ae3e | 2018-05-31 12:43:54 -0700 | [diff] [blame] | 1360 | ensureActivitiesVisibleLocked(null /* starting */, 0 /* configChanges */, |
| 1361 | !PRESERVE_WINDOWS); |
Dianne Hackborn | 4eba96b | 2011-01-21 13:34:36 -0800 | [diff] [blame] | 1362 | |
Andrii Kulian | f9949d5 | 2016-05-06 12:53:25 -0700 | [diff] [blame] | 1363 | // Make sure any paused or stopped but visible activities are now sleeping. |
Craig Mautner | 0eea92c | 2013-05-16 13:35:39 -0700 | [diff] [blame] | 1364 | // This ensures that the activity's onStop() is called. |
| 1365 | for (int taskNdx = mTaskHistory.size() - 1; taskNdx >= 0; --taskNdx) { |
| 1366 | final ArrayList<ActivityRecord> activities = mTaskHistory.get(taskNdx).mActivities; |
| 1367 | for (int activityNdx = activities.size() - 1; activityNdx >= 0; --activityNdx) { |
| 1368 | final ActivityRecord r = activities.get(activityNdx); |
Bryce Lee | 7ace395 | 2018-02-16 14:34:32 -0800 | [diff] [blame] | 1369 | if (r.isState(STOPPING, STOPPED, PAUSED, PAUSING)) { |
Craig Mautner | 0eea92c | 2013-05-16 13:35:39 -0700 | [diff] [blame] | 1370 | r.setSleeping(true); |
Dianne Hackborn | 4eba96b | 2011-01-21 13:34:36 -0800 | [diff] [blame] | 1371 | } |
| 1372 | } |
Dianne Hackborn | 4eba96b | 2011-01-21 13:34:36 -0800 | [diff] [blame] | 1373 | } |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 1374 | } |
Craig Mautner | 59c0097 | 2012-07-30 12:10:24 -0700 | [diff] [blame] | 1375 | |
David Stevens | 9440dc8 | 2017-03-16 19:00:20 -0700 | [diff] [blame] | 1376 | private boolean containsActivityFromStack(List<ActivityRecord> rs) { |
| 1377 | for (ActivityRecord r : rs) { |
| 1378 | if (r.getStack() == this) { |
| 1379 | return true; |
| 1380 | } |
| 1381 | } |
| 1382 | return false; |
| 1383 | } |
| 1384 | |
Dianne Hackborn | a4e102e | 2014-09-04 22:52:27 -0700 | [diff] [blame] | 1385 | /** |
Winson Chung | 4dabf23 | 2017-01-25 13:25:22 -0800 | [diff] [blame] | 1386 | * Schedule a pause timeout in case the app doesn't respond. We don't give it much time because |
| 1387 | * this directly impacts the responsiveness seen by the user. |
| 1388 | */ |
| 1389 | private void schedulePauseTimeout(ActivityRecord r) { |
| 1390 | final Message msg = mHandler.obtainMessage(PAUSE_TIMEOUT_MSG); |
| 1391 | msg.obj = r; |
| 1392 | r.pauseTime = SystemClock.uptimeMillis(); |
| 1393 | mHandler.sendMessageDelayed(msg, PAUSE_TIMEOUT); |
| 1394 | if (DEBUG_PAUSE) Slog.v(TAG_PAUSE, "Waiting for pause to complete..."); |
| 1395 | } |
| 1396 | |
| 1397 | /** |
Dianne Hackborn | a4e102e | 2014-09-04 22:52:27 -0700 | [diff] [blame] | 1398 | * Start pausing the currently resumed activity. It is an error to call this if there |
| 1399 | * is already an activity being paused or there is no resumed activity. |
| 1400 | * |
| 1401 | * @param userLeaving True if this should result in an onUserLeaving to the current activity. |
| 1402 | * @param uiSleeping True if this is happening with the user interface going to sleep (the |
| 1403 | * screen turning off). |
Wale Ogunwale | 950faff | 2016-08-08 09:51:04 -0700 | [diff] [blame] | 1404 | * @param resuming The activity we are currently trying to resume or null if this is not being |
| 1405 | * called as part of resuming the top activity, so we shouldn't try to instigate |
| 1406 | * a resume here if not null. |
Winson Chung | 6954fc9 | 2017-03-24 16:22:12 -0700 | [diff] [blame] | 1407 | * @param pauseImmediately True if the caller does not want to wait for the activity callback to |
| 1408 | * complete pausing. |
Dianne Hackborn | a4e102e | 2014-09-04 22:52:27 -0700 | [diff] [blame] | 1409 | * @return Returns true if an activity now is in the PAUSING state, and we are waiting for |
| 1410 | * it to tell us when it is done. |
| 1411 | */ |
Wale Ogunwale | 950faff | 2016-08-08 09:51:04 -0700 | [diff] [blame] | 1412 | final boolean startPausingLocked(boolean userLeaving, boolean uiSleeping, |
Winson Chung | 6954fc9 | 2017-03-24 16:22:12 -0700 | [diff] [blame] | 1413 | ActivityRecord resuming, boolean pauseImmediately) { |
Dianne Hackborn | 621e2fe | 2012-02-16 17:07:33 -0800 | [diff] [blame] | 1414 | if (mPausingActivity != null) { |
riddle_hsu | 7dfe4d7 | 2015-02-16 18:43:49 +0800 | [diff] [blame] | 1415 | 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] | 1416 | + " state=" + mPausingActivity.getState()); |
David Stevens | 9440dc8 | 2017-03-16 19:00:20 -0700 | [diff] [blame] | 1417 | if (!shouldSleepActivities()) { |
riddle_hsu | 7dfe4d7 | 2015-02-16 18:43:49 +0800 | [diff] [blame] | 1418 | // Avoid recursion among check for sleep and complete pause during sleeping. |
| 1419 | // Because activity will be paused immediately after resume, just let pause |
| 1420 | // be completed by the order of activity paused from clients. |
Wale Ogunwale | 950faff | 2016-08-08 09:51:04 -0700 | [diff] [blame] | 1421 | completePauseLocked(false, resuming); |
riddle_hsu | 7dfe4d7 | 2015-02-16 18:43:49 +0800 | [diff] [blame] | 1422 | } |
Dianne Hackborn | 621e2fe | 2012-02-16 17:07:33 -0800 | [diff] [blame] | 1423 | } |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 1424 | ActivityRecord prev = mResumedActivity; |
Bryce Lee | 5daa312 | 2017-04-19 10:40:42 -0700 | [diff] [blame] | 1425 | |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 1426 | if (prev == null) { |
Wale Ogunwale | 950faff | 2016-08-08 09:51:04 -0700 | [diff] [blame] | 1427 | if (resuming == null) { |
Dianne Hackborn | a4e102e | 2014-09-04 22:52:27 -0700 | [diff] [blame] | 1428 | Slog.wtf(TAG, "Trying to pause when nothing is resumed"); |
Wale Ogunwale | d046a01 | 2015-12-24 13:05:59 -0800 | [diff] [blame] | 1429 | mStackSupervisor.resumeFocusedStackTopActivityLocked(); |
Dianne Hackborn | a4e102e | 2014-09-04 22:52:27 -0700 | [diff] [blame] | 1430 | } |
| 1431 | return false; |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 1432 | } |
Craig Mautner | df88d73 | 2014-01-27 09:21:32 -0800 | [diff] [blame] | 1433 | |
Andrii Kulian | b1888aa | 2018-02-16 14:40:42 -0800 | [diff] [blame] | 1434 | if (prev == resuming) { |
| 1435 | Slog.wtf(TAG, "Trying to pause activity that is in process of being resumed"); |
| 1436 | return false; |
| 1437 | } |
| 1438 | |
Wale Ogunwale | 0fc365c | 2015-05-25 19:35:42 -0700 | [diff] [blame] | 1439 | if (DEBUG_STATES) Slog.v(TAG_STATES, "Moving to PAUSING: " + prev); |
Wale Ogunwale | ee006da | 2015-03-30 14:49:25 -0700 | [diff] [blame] | 1440 | else if (DEBUG_PAUSE) Slog.v(TAG_PAUSE, "Start pausing: " + prev); |
Dianne Hackborn | 621e2fe | 2012-02-16 17:07:33 -0800 | [diff] [blame] | 1441 | mPausingActivity = prev; |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 1442 | mLastPausedActivity = prev; |
Craig Mautner | 0f92274 | 2013-08-06 08:44:42 -0700 | [diff] [blame] | 1443 | mLastNoHistoryActivity = (prev.intent.getFlags() & Intent.FLAG_ACTIVITY_NO_HISTORY) != 0 |
| 1444 | || (prev.info.flags & ActivityInfo.FLAG_NO_HISTORY) != 0 ? prev : null; |
Bryce Lee | 7ace395 | 2018-02-16 14:34:32 -0800 | [diff] [blame] | 1445 | prev.setState(PAUSING, "startPausingLocked"); |
Bryce Lee | af691c0 | 2017-03-20 14:20:22 -0700 | [diff] [blame] | 1446 | prev.getTask().touchActiveTime(); |
Dianne Hackborn | 2286cdc | 2013-07-01 19:10:06 -0700 | [diff] [blame] | 1447 | clearLaunchTime(prev); |
Jorim Jaggi | e7d2b85 | 2017-08-28 17:55:15 +0200 | [diff] [blame] | 1448 | |
Vishnu Nair | cf23504 | 2018-11-02 13:27:00 -0700 | [diff] [blame] | 1449 | mStackSupervisor.getActivityMetricsLogger().stopFullyDrawnTraceIfNeeded(); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 1450 | |
| 1451 | mService.updateCpuStats(); |
Craig Mautner | aab647e | 2013-02-28 16:31:36 -0800 | [diff] [blame] | 1452 | |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 1453 | if (prev.app != null && prev.app.thread != null) { |
Wale Ogunwale | ee006da | 2015-03-30 14:49:25 -0700 | [diff] [blame] | 1454 | if (DEBUG_PAUSE) Slog.v(TAG_PAUSE, "Enqueueing pending pause: " + prev); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 1455 | try { |
Wale Ogunwale | c59b4f6 | 2017-11-30 11:05:43 -0800 | [diff] [blame] | 1456 | EventLogTags.writeAmPauseActivity(prev.userId, System.identityHashCode(prev), |
| 1457 | prev.shortComponentName, "userLeaving=" + userLeaving); |
Jeff Sharkey | 5782da7 | 2013-04-25 14:32:30 -0700 | [diff] [blame] | 1458 | mService.updateUsageStats(prev, false); |
Andrii Kulian | 446e824 | 2017-10-26 15:17:29 -0700 | [diff] [blame] | 1459 | |
Bryce Lee | b0f993f | 2018-03-02 15:38:01 -0800 | [diff] [blame] | 1460 | mService.getLifecycleManager().scheduleTransaction(prev.app.thread, prev.appToken, |
Andrii Kulian | 9c5ea9c | 2017-12-07 09:31:01 -0800 | [diff] [blame] | 1461 | PauseActivityItem.obtain(prev.finishing, userLeaving, |
Bryce Lee | 1d0d514 | 2018-04-12 10:35:07 -0700 | [diff] [blame] | 1462 | prev.configChangeFlags, pauseImmediately)); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 1463 | } catch (Exception e) { |
| 1464 | // Ignore exception, if process died other code will cleanup. |
| 1465 | Slog.w(TAG, "Exception thrown during pause", e); |
Dianne Hackborn | 621e2fe | 2012-02-16 17:07:33 -0800 | [diff] [blame] | 1466 | mPausingActivity = null; |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 1467 | mLastPausedActivity = null; |
Craig Mautner | 0f92274 | 2013-08-06 08:44:42 -0700 | [diff] [blame] | 1468 | mLastNoHistoryActivity = null; |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 1469 | } |
| 1470 | } else { |
Dianne Hackborn | 621e2fe | 2012-02-16 17:07:33 -0800 | [diff] [blame] | 1471 | mPausingActivity = null; |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 1472 | mLastPausedActivity = null; |
Craig Mautner | 0f92274 | 2013-08-06 08:44:42 -0700 | [diff] [blame] | 1473 | mLastNoHistoryActivity = null; |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 1474 | } |
| 1475 | |
| 1476 | // If we are not going to sleep, we want to ensure the device is |
| 1477 | // awake until the next activity is started. |
Fyodor Kupolov | 9b80b94 | 2016-06-16 16:29:05 -0700 | [diff] [blame] | 1478 | if (!uiSleeping && !mService.isSleepingOrShuttingDownLocked()) { |
Craig Mautner | 7ea5bd4 | 2013-07-05 15:27:08 -0700 | [diff] [blame] | 1479 | mStackSupervisor.acquireLaunchWakelock(); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 1480 | } |
| 1481 | |
Dianne Hackborn | 621e2fe | 2012-02-16 17:07:33 -0800 | [diff] [blame] | 1482 | if (mPausingActivity != null) { |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 1483 | // Have the window manager pause its key dispatching until the new |
| 1484 | // activity has started. If we're pausing the activity just because |
| 1485 | // the screen is being turned off and the UI is sleeping, don't interrupt |
| 1486 | // key dispatch; the same activity will pick it up again on wakeup. |
| 1487 | if (!uiSleeping) { |
Dianne Hackborn | 621e2fe | 2012-02-16 17:07:33 -0800 | [diff] [blame] | 1488 | prev.pauseKeyDispatchingLocked(); |
Wale Ogunwale | ee006da | 2015-03-30 14:49:25 -0700 | [diff] [blame] | 1489 | } else if (DEBUG_PAUSE) { |
| 1490 | Slog.v(TAG_PAUSE, "Key dispatch not paused for screen off"); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 1491 | } |
| 1492 | |
Winson Chung | 6954fc9 | 2017-03-24 16:22:12 -0700 | [diff] [blame] | 1493 | if (pauseImmediately) { |
Dianne Hackborn | a4e102e | 2014-09-04 22:52:27 -0700 | [diff] [blame] | 1494 | // If the caller said they don't want to wait for the pause, then complete |
| 1495 | // the pause now. |
Wale Ogunwale | 950faff | 2016-08-08 09:51:04 -0700 | [diff] [blame] | 1496 | completePauseLocked(false, resuming); |
Dianne Hackborn | a4e102e | 2014-09-04 22:52:27 -0700 | [diff] [blame] | 1497 | return false; |
| 1498 | |
| 1499 | } else { |
Winson Chung | 4dabf23 | 2017-01-25 13:25:22 -0800 | [diff] [blame] | 1500 | schedulePauseTimeout(prev); |
Dianne Hackborn | a4e102e | 2014-09-04 22:52:27 -0700 | [diff] [blame] | 1501 | return true; |
| 1502 | } |
| 1503 | |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 1504 | } else { |
| 1505 | // This activity failed to schedule the |
| 1506 | // pause, so just treat it as being paused now. |
Wale Ogunwale | ee006da | 2015-03-30 14:49:25 -0700 | [diff] [blame] | 1507 | if (DEBUG_PAUSE) Slog.v(TAG_PAUSE, "Activity not running, resuming next."); |
Wale Ogunwale | 950faff | 2016-08-08 09:51:04 -0700 | [diff] [blame] | 1508 | if (resuming == null) { |
Wale Ogunwale | d046a01 | 2015-12-24 13:05:59 -0800 | [diff] [blame] | 1509 | mStackSupervisor.resumeFocusedStackTopActivityLocked(); |
Dianne Hackborn | a4e102e | 2014-09-04 22:52:27 -0700 | [diff] [blame] | 1510 | } |
| 1511 | return false; |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 1512 | } |
| 1513 | } |
Dianne Hackborn | ad9b3211 | 2012-09-17 15:35:01 -0700 | [diff] [blame] | 1514 | |
Dianne Hackborn | a4e102e | 2014-09-04 22:52:27 -0700 | [diff] [blame] | 1515 | final void activityPausedLocked(IBinder token, boolean timeout) { |
Wale Ogunwale | ee006da | 2015-03-30 14:49:25 -0700 | [diff] [blame] | 1516 | if (DEBUG_PAUSE) Slog.v(TAG_PAUSE, |
| 1517 | "Activity paused: token=" + token + ", timeout=" + timeout); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 1518 | |
Craig Mautner | d232895 | 2013-03-05 12:46:26 -0800 | [diff] [blame] | 1519 | final ActivityRecord r = isInStackLocked(token); |
| 1520 | if (r != null) { |
| 1521 | mHandler.removeMessages(PAUSE_TIMEOUT_MSG, r); |
| 1522 | if (mPausingActivity == r) { |
Wale Ogunwale | 0fc365c | 2015-05-25 19:35:42 -0700 | [diff] [blame] | 1523 | if (DEBUG_STATES) Slog.v(TAG_STATES, "Moving to PAUSED: " + r |
Craig Mautner | d232895 | 2013-03-05 12:46:26 -0800 | [diff] [blame] | 1524 | + (timeout ? " (due to timeout)" : " (pause complete)")); |
Jorim Jaggi | fe76234 | 2016-10-13 14:33:27 +0200 | [diff] [blame] | 1525 | mService.mWindowManager.deferSurfaceLayout(); |
| 1526 | try { |
Winson Chung | 3f103eb | 2017-04-12 21:53:59 -0700 | [diff] [blame] | 1527 | completePauseLocked(true /* resumeNext */, null /* resumingActivity */); |
Jorim Jaggi | fe76234 | 2016-10-13 14:33:27 +0200 | [diff] [blame] | 1528 | } finally { |
| 1529 | mService.mWindowManager.continueSurfaceLayout(); |
| 1530 | } |
Wale Ogunwale | 5658e4b | 2016-02-12 12:22:19 -0800 | [diff] [blame] | 1531 | return; |
Craig Mautner | d232895 | 2013-03-05 12:46:26 -0800 | [diff] [blame] | 1532 | } else { |
| 1533 | EventLog.writeEvent(EventLogTags.AM_FAILED_TO_PAUSE, |
| 1534 | r.userId, System.identityHashCode(r), r.shortComponentName, |
| 1535 | mPausingActivity != null |
| 1536 | ? mPausingActivity.shortComponentName : "(none)"); |
Bryce Lee | 7ace395 | 2018-02-16 14:34:32 -0800 | [diff] [blame] | 1537 | if (r.isState(PAUSING)) { |
| 1538 | r.setState(PAUSED, "activityPausedLocked"); |
riddle_hsu | 9caeef7 | 2015-10-20 16:34:05 +0800 | [diff] [blame] | 1539 | if (r.finishing) { |
| 1540 | if (DEBUG_PAUSE) Slog.v(TAG, |
| 1541 | "Executing finish of failed to pause activity: " + r); |
Bryce Lee | f52974c | 2018-02-14 15:12:01 -0800 | [diff] [blame] | 1542 | finishCurrentActivityLocked(r, FINISH_AFTER_VISIBLE, false, |
| 1543 | "activityPausedLocked"); |
riddle_hsu | 9caeef7 | 2015-10-20 16:34:05 +0800 | [diff] [blame] | 1544 | } |
louis_chang | 047dfd4 | 2015-04-08 16:35:55 +0800 | [diff] [blame] | 1545 | } |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 1546 | } |
| 1547 | } |
Wale Ogunwale | 5658e4b | 2016-02-12 12:22:19 -0800 | [diff] [blame] | 1548 | mStackSupervisor.ensureActivitiesVisibleLocked(null, 0, !PRESERVE_WINDOWS); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 1549 | } |
| 1550 | |
Wale Ogunwale | 950faff | 2016-08-08 09:51:04 -0700 | [diff] [blame] | 1551 | private void completePauseLocked(boolean resumeNext, ActivityRecord resuming) { |
Dianne Hackborn | 621e2fe | 2012-02-16 17:07:33 -0800 | [diff] [blame] | 1552 | ActivityRecord prev = mPausingActivity; |
Wale Ogunwale | ee006da | 2015-03-30 14:49:25 -0700 | [diff] [blame] | 1553 | if (DEBUG_PAUSE) Slog.v(TAG_PAUSE, "Complete pause: " + prev); |
Craig Mautner | aab647e | 2013-02-28 16:31:36 -0800 | [diff] [blame] | 1554 | |
Dianne Hackborn | 621e2fe | 2012-02-16 17:07:33 -0800 | [diff] [blame] | 1555 | if (prev != null) { |
chaviw | 4ad5491 | 2018-05-30 11:05:44 -0700 | [diff] [blame] | 1556 | prev.setWillCloseOrEnterPip(false); |
Bryce Lee | 7ace395 | 2018-02-16 14:34:32 -0800 | [diff] [blame] | 1557 | final boolean wasStopping = prev.isState(STOPPING); |
| 1558 | prev.setState(PAUSED, "completePausedLocked"); |
Dianne Hackborn | 621e2fe | 2012-02-16 17:07:33 -0800 | [diff] [blame] | 1559 | if (prev.finishing) { |
Wale Ogunwale | ee006da | 2015-03-30 14:49:25 -0700 | [diff] [blame] | 1560 | if (DEBUG_PAUSE) Slog.v(TAG_PAUSE, "Executing finish of activity: " + prev); |
Bryce Lee | f52974c | 2018-02-14 15:12:01 -0800 | [diff] [blame] | 1561 | prev = finishCurrentActivityLocked(prev, FINISH_AFTER_VISIBLE, false, |
| 1562 | "completedPausedLocked"); |
Dianne Hackborn | 621e2fe | 2012-02-16 17:07:33 -0800 | [diff] [blame] | 1563 | } else if (prev.app != null) { |
Wale Ogunwale | d802664 | 2016-02-09 20:40:18 -0800 | [diff] [blame] | 1564 | if (DEBUG_PAUSE) Slog.v(TAG_PAUSE, "Enqueue pending stop if needed: " + prev |
| 1565 | + " wasStopping=" + wasStopping + " visible=" + prev.visible); |
Bryce Lee | 4a19438 | 2017-04-04 14:32:48 -0700 | [diff] [blame] | 1566 | if (mStackSupervisor.mActivitiesWaitingForVisibleActivity.remove(prev)) { |
Wale Ogunwale | ee006da | 2015-03-30 14:49:25 -0700 | [diff] [blame] | 1567 | if (DEBUG_SWITCH || DEBUG_PAUSE) Slog.v(TAG_PAUSE, |
| 1568 | "Complete pause, no longer waiting: " + prev); |
Dianne Hackborn | cbb722e | 2012-02-07 18:33:49 -0800 | [diff] [blame] | 1569 | } |
Wale Ogunwale | f81c1d1 | 2016-01-12 12:20:18 -0800 | [diff] [blame] | 1570 | if (prev.deferRelaunchUntilPaused) { |
| 1571 | // Complete the deferred relaunch that was waiting for pause to complete. |
| 1572 | if (DEBUG_PAUSE) Slog.v(TAG_PAUSE, "Re-launching after pause: " + prev); |
Andrii Kulian | 21713ac | 2016-10-12 22:05:05 -0700 | [diff] [blame] | 1573 | prev.relaunchActivityLocked(false /* andResume */, |
Wale Ogunwale | f81c1d1 | 2016-01-12 12:20:18 -0800 | [diff] [blame] | 1574 | prev.preserveWindowOnDeferredRelaunch); |
Filip Gruszczynski | dba623a | 2015-12-04 15:45:35 -0800 | [diff] [blame] | 1575 | } else if (wasStopping) { |
| 1576 | // We are also stopping, the stop request must have gone soon after the pause. |
| 1577 | // We can't clobber it, because the stop confirmation will not be handled. |
| 1578 | // 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] | 1579 | prev.setState(STOPPING, "completePausedLocked"); |
David Stevens | 9440dc8 | 2017-03-16 19:00:20 -0700 | [diff] [blame] | 1580 | } else if (!prev.visible || shouldSleepOrShutDownActivities()) { |
Wale Ogunwale | ec95064 | 2017-04-25 07:44:21 -0700 | [diff] [blame] | 1581 | // Clear out any deferred client hide we might currently have. |
| 1582 | prev.setDeferHidingClient(false); |
Jose Lima | 4b6c669 | 2014-08-12 17:41:12 -0700 | [diff] [blame] | 1583 | // If we were visible then resumeTopActivities will release resources before |
Wale Ogunwale | ec95064 | 2017-04-25 07:44:21 -0700 | [diff] [blame] | 1584 | // stopping. |
Winson Chung | 4dabf23 | 2017-01-25 13:25:22 -0800 | [diff] [blame] | 1585 | addToStopping(prev, true /* scheduleIdle */, false /* idleDelayed */); |
Dianne Hackborn | 621e2fe | 2012-02-16 17:07:33 -0800 | [diff] [blame] | 1586 | } |
| 1587 | } else { |
Wale Ogunwale | ee006da | 2015-03-30 14:49:25 -0700 | [diff] [blame] | 1588 | 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] | 1589 | prev = null; |
Dianne Hackborn | cbb722e | 2012-02-07 18:33:49 -0800 | [diff] [blame] | 1590 | } |
Wale Ogunwale | 07927bf | 2015-03-28 17:21:05 -0700 | [diff] [blame] | 1591 | // It is possible the activity was freezing the screen before it was paused. |
| 1592 | // In that case go ahead and remove the freeze this activity has on the screen |
| 1593 | // since it is no longer visible. |
Wale Ogunwale | e852400 | 2016-09-13 16:34:57 -0700 | [diff] [blame] | 1594 | if (prev != null) { |
| 1595 | prev.stopFreezingScreenLocked(true /*force*/); |
| 1596 | } |
Dianne Hackborn | 621e2fe | 2012-02-16 17:07:33 -0800 | [diff] [blame] | 1597 | mPausingActivity = null; |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 1598 | } |
Dianne Hackborn | cbb722e | 2012-02-07 18:33:49 -0800 | [diff] [blame] | 1599 | |
Dianne Hackborn | a4e102e | 2014-09-04 22:52:27 -0700 | [diff] [blame] | 1600 | if (resumeNext) { |
| 1601 | final ActivityStack topStack = mStackSupervisor.getFocusedStack(); |
David Stevens | 9440dc8 | 2017-03-16 19:00:20 -0700 | [diff] [blame] | 1602 | if (!topStack.shouldSleepOrShutDownActivities()) { |
Wale Ogunwale | d046a01 | 2015-12-24 13:05:59 -0800 | [diff] [blame] | 1603 | mStackSupervisor.resumeFocusedStackTopActivityLocked(topStack, prev, null); |
Dianne Hackborn | a4e102e | 2014-09-04 22:52:27 -0700 | [diff] [blame] | 1604 | } else { |
David Stevens | 9440dc8 | 2017-03-16 19:00:20 -0700 | [diff] [blame] | 1605 | checkReadyForSleep(); |
Filip Gruszczynski | 3e85ba2 | 2015-10-05 22:48:30 -0700 | [diff] [blame] | 1606 | ActivityRecord top = topStack.topRunningActivityLocked(); |
Dianne Hackborn | a4e102e | 2014-09-04 22:52:27 -0700 | [diff] [blame] | 1607 | if (top == null || (prev != null && top != prev)) { |
Wale Ogunwale | d046a01 | 2015-12-24 13:05:59 -0800 | [diff] [blame] | 1608 | // If there are no more activities available to run, do resume anyway to start |
| 1609 | // something. Also if the top activity on the stack is not the just paused |
| 1610 | // activity, we need to go ahead and resume it to ensure we complete an |
| 1611 | // in-flight app switch. |
| 1612 | mStackSupervisor.resumeFocusedStackTopActivityLocked(); |
Dianne Hackborn | a4e102e | 2014-09-04 22:52:27 -0700 | [diff] [blame] | 1613 | } |
Dianne Hackborn | 42e620c | 2012-06-24 13:20:51 -0700 | [diff] [blame] | 1614 | } |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 1615 | } |
Craig Mautner | aab647e | 2013-02-28 16:31:36 -0800 | [diff] [blame] | 1616 | |
Dianne Hackborn | 621e2fe | 2012-02-16 17:07:33 -0800 | [diff] [blame] | 1617 | if (prev != null) { |
| 1618 | prev.resumeKeyDispatchingLocked(); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 1619 | |
Craig Mautner | 525f3d9 | 2013-05-07 14:01:50 -0700 | [diff] [blame] | 1620 | if (prev.app != null && prev.cpuTimeAtResume > 0 |
| 1621 | && mService.mBatteryStatsService.isOnBattery()) { |
Dianne Hackborn | 652973f | 2014-09-10 17:08:48 -0700 | [diff] [blame] | 1622 | long diff = mService.mProcessCpuTracker.getCpuTimeForPid(prev.app.pid) |
| 1623 | - prev.cpuTimeAtResume; |
Craig Mautner | 525f3d9 | 2013-05-07 14:01:50 -0700 | [diff] [blame] | 1624 | if (diff > 0) { |
| 1625 | BatteryStatsImpl bsi = mService.mBatteryStatsService.getActiveStatistics(); |
| 1626 | synchronized (bsi) { |
| 1627 | BatteryStatsImpl.Uid.Proc ps = |
| 1628 | bsi.getProcessStatsLocked(prev.info.applicationInfo.uid, |
Dianne Hackborn | d293224 | 2013-08-05 18:18:42 -0700 | [diff] [blame] | 1629 | prev.info.packageName); |
Craig Mautner | 525f3d9 | 2013-05-07 14:01:50 -0700 | [diff] [blame] | 1630 | if (ps != null) { |
| 1631 | ps.addForegroundTimeLocked(diff); |
| 1632 | } |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 1633 | } |
| 1634 | } |
| 1635 | } |
Craig Mautner | 525f3d9 | 2013-05-07 14:01:50 -0700 | [diff] [blame] | 1636 | prev.cpuTimeAtResume = 0; // reset it |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 1637 | } |
Winson Chung | 740c3ac | 2014-11-12 16:14:38 -0800 | [diff] [blame] | 1638 | |
Andrii Kulian | 8290f8f | 2016-06-30 17:51:32 -0700 | [diff] [blame] | 1639 | // Notify when the task stack has changed, but only if visibilities changed (not just |
| 1640 | // focus). Also if there is an active pinned stack - we always want to notify it about |
| 1641 | // task stack changes, because its positioning may depend on it. |
| 1642 | if (mStackSupervisor.mAppVisibilitiesChangedSinceLastPause |
Wale Ogunwale | 04a05ac | 2017-09-17 21:35:02 -0700 | [diff] [blame] | 1643 | || getDisplay().hasPinnedStack()) { |
Yorke Lee | bd54c2a | 2016-10-25 13:49:23 -0700 | [diff] [blame] | 1644 | mService.mTaskChangeNotificationController.notifyTaskStackChanged(); |
Jorim Jaggi | a0fdeec | 2016-01-07 14:42:28 +0100 | [diff] [blame] | 1645 | mStackSupervisor.mAppVisibilitiesChangedSinceLastPause = false; |
| 1646 | } |
Wale Ogunwale | 5658e4b | 2016-02-12 12:22:19 -0800 | [diff] [blame] | 1647 | |
Wale Ogunwale | 950faff | 2016-08-08 09:51:04 -0700 | [diff] [blame] | 1648 | mStackSupervisor.ensureActivitiesVisibleLocked(resuming, 0, !PRESERVE_WINDOWS); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 1649 | } |
| 1650 | |
Winson Chung | 4dabf23 | 2017-01-25 13:25:22 -0800 | [diff] [blame] | 1651 | void addToStopping(ActivityRecord r, boolean scheduleIdle, boolean idleDelayed) { |
Chong Zhang | 46b1ac6 | 2016-02-18 17:53:57 -0800 | [diff] [blame] | 1652 | if (!mStackSupervisor.mStoppingActivities.contains(r)) { |
| 1653 | mStackSupervisor.mStoppingActivities.add(r); |
Jorim Jaggi | 5db9ae4 | 2018-06-25 16:14:50 +0200 | [diff] [blame] | 1654 | |
| 1655 | // Some activity is waiting for another activity to become visible before it's being |
| 1656 | // stopped, which means that we also want to wait with stopping this one to avoid |
| 1657 | // flickers. |
| 1658 | if (!mStackSupervisor.mActivitiesWaitingForVisibleActivity.isEmpty() |
| 1659 | && !mStackSupervisor.mActivitiesWaitingForVisibleActivity.contains(r)) { |
| 1660 | if (DEBUG_SWITCH) Slog.i(TAG_SWITCH, "adding to waiting visible activity=" + r |
| 1661 | + " existing=" + mStackSupervisor.mActivitiesWaitingForVisibleActivity); |
| 1662 | mStackSupervisor.mActivitiesWaitingForVisibleActivity.add(r); |
| 1663 | } |
Chong Zhang | 46b1ac6 | 2016-02-18 17:53:57 -0800 | [diff] [blame] | 1664 | } |
| 1665 | |
| 1666 | // If we already have a few activities waiting to stop, then give up |
| 1667 | // on things going idle and start clearing them out. Or if r is the |
| 1668 | // last of activity of the last task the stack will be empty and must |
| 1669 | // be cleared immediately. |
| 1670 | boolean forceIdle = mStackSupervisor.mStoppingActivities.size() > MAX_STOPPING_TO_FORCE |
| 1671 | || (r.frontOfTask && mTaskHistory.size() <= 1); |
Winson Chung | 4dabf23 | 2017-01-25 13:25:22 -0800 | [diff] [blame] | 1672 | if (scheduleIdle || forceIdle) { |
Chong Zhang | 46b1ac6 | 2016-02-18 17:53:57 -0800 | [diff] [blame] | 1673 | if (DEBUG_PAUSE) Slog.v(TAG_PAUSE, "Scheduling idle now: forceIdle=" |
Winson Chung | 4dabf23 | 2017-01-25 13:25:22 -0800 | [diff] [blame] | 1674 | + forceIdle + "immediate=" + !idleDelayed); |
| 1675 | if (!idleDelayed) { |
| 1676 | mStackSupervisor.scheduleIdleLocked(); |
| 1677 | } else { |
| 1678 | mStackSupervisor.scheduleIdleTimeoutLocked(r); |
| 1679 | } |
Filip Gruszczynski | ef2f72b | 2015-12-04 14:52:25 -0800 | [diff] [blame] | 1680 | } else { |
David Stevens | 9440dc8 | 2017-03-16 19:00:20 -0700 | [diff] [blame] | 1681 | checkReadyForSleep(); |
Filip Gruszczynski | ef2f72b | 2015-12-04 14:52:25 -0800 | [diff] [blame] | 1682 | } |
| 1683 | } |
| 1684 | |
Wale Ogunwale | 8051c5c | 2016-03-04 10:27:32 -0800 | [diff] [blame] | 1685 | /** |
| 1686 | * Returns true if the stack is translucent and can have other contents visible behind it if |
| 1687 | * needed. A stack is considered translucent if it don't contain a visible or |
| 1688 | * starting (about to be visible) activity that is fullscreen (opaque). |
| 1689 | * @param starting The currently starting activity or null if there is none. |
| 1690 | */ |
Wale Ogunwale | 7e1f5f5 | 2017-10-18 15:19:59 -0700 | [diff] [blame] | 1691 | @VisibleForTesting |
Wale Ogunwale | 66e1685 | 2017-10-19 13:35:52 -0700 | [diff] [blame] | 1692 | boolean isStackTranslucent(ActivityRecord starting) { |
Wale Ogunwale | 7e1f5f5 | 2017-10-18 15:19:59 -0700 | [diff] [blame] | 1693 | if (!isAttached() || mForceHidden) { |
| 1694 | return true; |
| 1695 | } |
Wale Ogunwale | 8051c5c | 2016-03-04 10:27:32 -0800 | [diff] [blame] | 1696 | for (int taskNdx = mTaskHistory.size() - 1; taskNdx >= 0; --taskNdx) { |
| 1697 | final TaskRecord task = mTaskHistory.get(taskNdx); |
Wale Ogunwale | 1e3523c | 2015-09-16 13:11:10 -0700 | [diff] [blame] | 1698 | final ArrayList<ActivityRecord> activities = task.mActivities; |
| 1699 | for (int activityNdx = activities.size() - 1; activityNdx >= 0; --activityNdx) { |
| 1700 | final ActivityRecord r = activities.get(activityNdx); |
Wale Ogunwale | b34a7ad | 2015-08-14 11:05:30 -0700 | [diff] [blame] | 1701 | |
Wale Ogunwale | 56d75cf | 2016-03-09 15:14:47 -0800 | [diff] [blame] | 1702 | if (r.finishing) { |
| 1703 | // We don't factor in finishing activities when determining translucency since |
| 1704 | // they will be gone soon. |
| 1705 | continue; |
| 1706 | } |
| 1707 | |
Wale Ogunwale | 2cca862 | 2017-12-11 08:40:13 -0800 | [diff] [blame] | 1708 | if (!r.visibleIgnoringKeyguard && r != starting) { |
Wale Ogunwale | 56d75cf | 2016-03-09 15:14:47 -0800 | [diff] [blame] | 1709 | // Also ignore invisible activities that are not the currently starting |
| 1710 | // activity (about to be visible). |
| 1711 | continue; |
| 1712 | } |
| 1713 | |
Wale Ogunwale | 7e1f5f5 | 2017-10-18 15:19:59 -0700 | [diff] [blame] | 1714 | if (r.fullscreen || r.hasWallpaper) { |
Wale Ogunwale | 56d75cf | 2016-03-09 15:14:47 -0800 | [diff] [blame] | 1715 | // Stack isn't translucent if it has at least one fullscreen activity |
| 1716 | // that is visible. |
| 1717 | return false; |
| 1718 | } |
Wale Ogunwale | b34a7ad | 2015-08-14 11:05:30 -0700 | [diff] [blame] | 1719 | } |
| 1720 | } |
Wale Ogunwale | 1e3523c | 2015-09-16 13:11:10 -0700 | [diff] [blame] | 1721 | return true; |
Wale Ogunwale | b34a7ad | 2015-08-14 11:05:30 -0700 | [diff] [blame] | 1722 | } |
| 1723 | |
Wale Ogunwale | a0f5b5e | 2017-10-11 09:37:23 -0700 | [diff] [blame] | 1724 | boolean isTopStackOnDisplay() { |
| 1725 | return getDisplay().isTopStack(this); |
| 1726 | } |
| 1727 | |
Adrian Roos | a6d6aab | 2018-04-19 18:58:22 +0200 | [diff] [blame] | 1728 | boolean isTopActivityVisible() { |
| 1729 | final ActivityRecord topActivity = getTopActivity(); |
| 1730 | return topActivity != null && topActivity.visible; |
| 1731 | } |
| 1732 | |
Filip Gruszczynski | 0e381e2 | 2016-01-14 16:31:33 -0800 | [diff] [blame] | 1733 | /** |
Wale Ogunwale | 9dcf946 | 2017-09-19 15:13:01 -0700 | [diff] [blame] | 1734 | * Returns true if the stack should be visible. |
Wale Ogunwale | cd501ec | 2017-04-07 08:53:41 -0700 | [diff] [blame] | 1735 | * |
Wale Ogunwale | 8051c5c | 2016-03-04 10:27:32 -0800 | [diff] [blame] | 1736 | * @param starting The currently starting activity or null if there is none. |
Filip Gruszczynski | 0e381e2 | 2016-01-14 16:31:33 -0800 | [diff] [blame] | 1737 | */ |
Wale Ogunwale | 9dcf946 | 2017-09-19 15:13:01 -0700 | [diff] [blame] | 1738 | boolean shouldBeVisible(ActivityRecord starting) { |
Winson Chung | 4790065 | 2017-04-06 18:44:25 -0700 | [diff] [blame] | 1739 | if (!isAttached() || mForceHidden) { |
Wale Ogunwale | 9dcf946 | 2017-09-19 15:13:01 -0700 | [diff] [blame] | 1740 | return false; |
Jose Lima | 7ba7125 | 2014-04-30 12:59:27 -0700 | [diff] [blame] | 1741 | } |
Wale Ogunwale | 7e1f5f5 | 2017-10-18 15:19:59 -0700 | [diff] [blame] | 1742 | if (mStackSupervisor.isFocusedStack(this)) { |
Wale Ogunwale | 9dcf946 | 2017-09-19 15:13:01 -0700 | [diff] [blame] | 1743 | return true; |
Wale Ogunwale | 99db186 | 2015-10-23 20:08:22 -0700 | [diff] [blame] | 1744 | } |
| 1745 | |
Wale Ogunwale | 7e1f5f5 | 2017-10-18 15:19:59 -0700 | [diff] [blame] | 1746 | final ActivityRecord top = topRunningActivityLocked(); |
| 1747 | if (top == null && isInStackLocked(starting) == null && !isTopStackOnDisplay()) { |
| 1748 | // Shouldn't be visible if you don't have any running activities, not starting one, and |
| 1749 | // not the top stack on display. |
Wale Ogunwale | 9dcf946 | 2017-09-19 15:13:01 -0700 | [diff] [blame] | 1750 | return false; |
Wale Ogunwale | ddc1cb2 | 2015-07-25 19:23:04 -0700 | [diff] [blame] | 1751 | } |
| 1752 | |
Wale Ogunwale | 7e1f5f5 | 2017-10-18 15:19:59 -0700 | [diff] [blame] | 1753 | final ActivityDisplay display = getDisplay(); |
Wale Ogunwale | 8e923af | 2018-03-23 08:48:11 -0700 | [diff] [blame] | 1754 | boolean gotSplitScreenStack = false; |
Wale Ogunwale | 7e1f5f5 | 2017-10-18 15:19:59 -0700 | [diff] [blame] | 1755 | boolean gotOpaqueSplitScreenPrimary = false; |
| 1756 | boolean gotOpaqueSplitScreenSecondary = false; |
Wale Ogunwale | 6827856 | 2017-09-23 17:13:55 -0700 | [diff] [blame] | 1757 | final int windowingMode = getWindowingMode(); |
Wale Ogunwale | 8e923af | 2018-03-23 08:48:11 -0700 | [diff] [blame] | 1758 | final boolean isAssistantType = isActivityTypeAssistant(); |
Wale Ogunwale | 7e1f5f5 | 2017-10-18 15:19:59 -0700 | [diff] [blame] | 1759 | for (int i = display.getChildCount() - 1; i >= 0; --i) { |
| 1760 | final ActivityStack other = display.getChildAt(i); |
| 1761 | if (other == this) { |
| 1762 | // Should be visible if there is no other stack occluding it. |
| 1763 | return true; |
| 1764 | } |
Wale Ogunwale | 6827856 | 2017-09-23 17:13:55 -0700 | [diff] [blame] | 1765 | |
Wale Ogunwale | 7e1f5f5 | 2017-10-18 15:19:59 -0700 | [diff] [blame] | 1766 | final int otherWindowingMode = other.getWindowingMode(); |
Wale Ogunwale | 7e1f5f5 | 2017-10-18 15:19:59 -0700 | [diff] [blame] | 1767 | |
| 1768 | if (otherWindowingMode == WINDOWING_MODE_FULLSCREEN) { |
Matthew Ng | 99b3cdc | 2018-05-01 14:24:38 -0700 | [diff] [blame] | 1769 | // In this case the home stack isn't resizeable even though we are in split-screen |
| 1770 | // mode. We still want the primary splitscreen stack to be visible as there will be |
| 1771 | // 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] | 1772 | // activity. In addition, if the fullscreen assistant is over primary splitscreen |
| 1773 | // stack, the stack should still be visible in the background as long as the recents |
| 1774 | // animation is running. |
| 1775 | final int activityType = other.getActivityType(); |
| 1776 | if (windowingMode == WINDOWING_MODE_SPLIT_SCREEN_PRIMARY) { |
| 1777 | if (activityType == ACTIVITY_TYPE_HOME |
| 1778 | || (activityType == ACTIVITY_TYPE_ASSISTANT |
| 1779 | && mWindowManager.getRecentsAnimationController() != null)) { |
| 1780 | return true; |
| 1781 | } |
Matthew Ng | 99b3cdc | 2018-05-01 14:24:38 -0700 | [diff] [blame] | 1782 | } |
Wale Ogunwale | 66e1685 | 2017-10-19 13:35:52 -0700 | [diff] [blame] | 1783 | if (other.isStackTranslucent(starting)) { |
Wale Ogunwale | 7e1f5f5 | 2017-10-18 15:19:59 -0700 | [diff] [blame] | 1784 | // Can be visible behind a translucent fullscreen stack. |
| 1785 | continue; |
| 1786 | } |
| 1787 | return false; |
| 1788 | } else if (otherWindowingMode == WINDOWING_MODE_SPLIT_SCREEN_PRIMARY |
| 1789 | && !gotOpaqueSplitScreenPrimary) { |
Wale Ogunwale | 8e923af | 2018-03-23 08:48:11 -0700 | [diff] [blame] | 1790 | gotSplitScreenStack = true; |
Wale Ogunwale | 7e1f5f5 | 2017-10-18 15:19:59 -0700 | [diff] [blame] | 1791 | gotOpaqueSplitScreenPrimary = |
Wale Ogunwale | 66e1685 | 2017-10-19 13:35:52 -0700 | [diff] [blame] | 1792 | !other.isStackTranslucent(starting); |
Wale Ogunwale | 7e1f5f5 | 2017-10-18 15:19:59 -0700 | [diff] [blame] | 1793 | if (windowingMode == WINDOWING_MODE_SPLIT_SCREEN_PRIMARY |
| 1794 | && gotOpaqueSplitScreenPrimary) { |
| 1795 | // Can not be visible behind another opaque stack in split-screen-primary mode. |
| 1796 | return false; |
| 1797 | } |
| 1798 | } else if (otherWindowingMode == WINDOWING_MODE_SPLIT_SCREEN_SECONDARY |
| 1799 | && !gotOpaqueSplitScreenSecondary) { |
Wale Ogunwale | 8e923af | 2018-03-23 08:48:11 -0700 | [diff] [blame] | 1800 | gotSplitScreenStack = true; |
Wale Ogunwale | 7e1f5f5 | 2017-10-18 15:19:59 -0700 | [diff] [blame] | 1801 | gotOpaqueSplitScreenSecondary = |
Wale Ogunwale | 66e1685 | 2017-10-19 13:35:52 -0700 | [diff] [blame] | 1802 | !other.isStackTranslucent(starting); |
Wale Ogunwale | 7e1f5f5 | 2017-10-18 15:19:59 -0700 | [diff] [blame] | 1803 | if (windowingMode == WINDOWING_MODE_SPLIT_SCREEN_SECONDARY |
| 1804 | && gotOpaqueSplitScreenSecondary) { |
| 1805 | // Can not be visible behind another opaque stack in split-screen-secondary mode. |
| 1806 | return false; |
| 1807 | } |
| 1808 | } |
| 1809 | if (gotOpaqueSplitScreenPrimary && gotOpaqueSplitScreenSecondary) { |
| 1810 | // Can not be visible if we are in split-screen windowing mode and both halves of |
| 1811 | // the screen are opaque. |
| 1812 | return false; |
| 1813 | } |
Wale Ogunwale | 8e923af | 2018-03-23 08:48:11 -0700 | [diff] [blame] | 1814 | if (isAssistantType && gotSplitScreenStack) { |
| 1815 | // Assistant stack can't be visible behind split-screen. In addition to this not |
| 1816 | // making sense, it also works around an issue here we boost the z-order of the |
| 1817 | // assistant window surfaces in window manager whenever it is visible. |
| 1818 | return false; |
| 1819 | } |
Wale Ogunwale | 7e1f5f5 | 2017-10-18 15:19:59 -0700 | [diff] [blame] | 1820 | } |
| 1821 | |
| 1822 | // Well, nothing is stopping you from being visible... |
| 1823 | return true; |
Wale Ogunwale | 6827856 | 2017-09-23 17:13:55 -0700 | [diff] [blame] | 1824 | } |
| 1825 | |
Chong Zhang | fdcc4d4 | 2015-10-14 16:50:12 -0700 | [diff] [blame] | 1826 | final int rankTaskLayers(int baseLayer) { |
| 1827 | int layer = 0; |
| 1828 | for (int taskNdx = mTaskHistory.size() - 1; taskNdx >= 0; --taskNdx) { |
| 1829 | final TaskRecord task = mTaskHistory.get(taskNdx); |
| 1830 | ActivityRecord r = task.topRunningActivityLocked(); |
| 1831 | if (r == null || r.finishing || !r.visible) { |
| 1832 | task.mLayerRank = -1; |
| 1833 | } else { |
| 1834 | task.mLayerRank = baseLayer + layer++; |
| 1835 | } |
| 1836 | } |
| 1837 | return layer; |
| 1838 | } |
| 1839 | |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 1840 | /** |
Andrii Kulian | f4479ee | 2018-05-23 17:52:48 -0700 | [diff] [blame] | 1841 | * Make sure that all activities that need to be visible in the stack (that is, they |
| 1842 | * currently can be seen by the user) actually are and update their configuration. |
| 1843 | */ |
| 1844 | final void ensureActivitiesVisibleLocked(ActivityRecord starting, int configChanges, |
| 1845 | boolean preserveWindows) { |
| 1846 | ensureActivitiesVisibleLocked(starting, configChanges, preserveWindows, |
Andrii Kulian | a39ae3e | 2018-05-31 12:43:54 -0700 | [diff] [blame] | 1847 | true /* notifyClients */); |
Andrii Kulian | f4479ee | 2018-05-23 17:52:48 -0700 | [diff] [blame] | 1848 | } |
| 1849 | |
| 1850 | /** |
| 1851 | * Ensure visibility with an option to also update the configuration of visible activities. |
| 1852 | * @see #ensureActivitiesVisibleLocked(ActivityRecord, int, boolean) |
| 1853 | * @see ActivityStackSupervisor#ensureActivitiesVisibleLocked(ActivityRecord, int, boolean) |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 1854 | */ |
Wale Ogunwale | 66e1685 | 2017-10-19 13:35:52 -0700 | [diff] [blame] | 1855 | // 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] | 1856 | final void ensureActivitiesVisibleLocked(ActivityRecord starting, int configChanges, |
Andrii Kulian | a39ae3e | 2018-05-31 12:43:54 -0700 | [diff] [blame] | 1857 | boolean preserveWindows, boolean notifyClients) { |
Jorim Jaggi | fe76234 | 2016-10-13 14:33:27 +0200 | [diff] [blame] | 1858 | mTopActivityOccludesKeyguard = false; |
| 1859 | mTopDismissingKeyguardActivity = null; |
Bryce Lee | 2a3cc46 | 2017-10-27 10:57:35 -0700 | [diff] [blame] | 1860 | mStackSupervisor.getKeyguardController().beginActivityVisibilityUpdate(); |
Jorim Jaggi | fe76234 | 2016-10-13 14:33:27 +0200 | [diff] [blame] | 1861 | try { |
| 1862 | ActivityRecord top = topRunningActivityLocked(); |
| 1863 | if (DEBUG_VISIBILITY) Slog.v(TAG_VISIBILITY, "ensureActivitiesVisible behind " + top |
| 1864 | + " configChanges=0x" + Integer.toHexString(configChanges)); |
| 1865 | if (top != null) { |
| 1866 | checkTranslucentActivityWaiting(top); |
| 1867 | } |
Craig Mautner | 5eda9b3 | 2013-07-02 11:58:16 -0700 | [diff] [blame] | 1868 | |
Jorim Jaggi | fe76234 | 2016-10-13 14:33:27 +0200 | [diff] [blame] | 1869 | // If the top activity is not fullscreen, then we need to |
| 1870 | // make sure any activities under it are now visible. |
| 1871 | boolean aboveTop = top != null; |
Wale Ogunwale | 04a05ac | 2017-09-17 21:35:02 -0700 | [diff] [blame] | 1872 | final boolean stackShouldBeVisible = shouldBeVisible(starting); |
| 1873 | boolean behindFullscreenActivity = !stackShouldBeVisible; |
Jorim Jaggi | fe76234 | 2016-10-13 14:33:27 +0200 | [diff] [blame] | 1874 | boolean resumeNextActivity = mStackSupervisor.isFocusedStack(this) |
| 1875 | && (isInStackLocked(starting) == null); |
Wale Ogunwale | 86dde2b | 2018-01-18 06:15:45 -0800 | [diff] [blame] | 1876 | final boolean isTopNotPinnedStack = |
| 1877 | isAttached() && getDisplay().isTopNotPinnedStack(this); |
Jorim Jaggi | fe76234 | 2016-10-13 14:33:27 +0200 | [diff] [blame] | 1878 | for (int taskNdx = mTaskHistory.size() - 1; taskNdx >= 0; --taskNdx) { |
| 1879 | final TaskRecord task = mTaskHistory.get(taskNdx); |
| 1880 | final ArrayList<ActivityRecord> activities = task.mActivities; |
| 1881 | for (int activityNdx = activities.size() - 1; activityNdx >= 0; --activityNdx) { |
| 1882 | final ActivityRecord r = activities.get(activityNdx); |
| 1883 | if (r.finishing) { |
Jorim Jaggi | fe76234 | 2016-10-13 14:33:27 +0200 | [diff] [blame] | 1884 | continue; |
Chong Zhang | 22bc851 | 2016-04-07 13:47:18 -0700 | [diff] [blame] | 1885 | } |
Jorim Jaggi | fe76234 | 2016-10-13 14:33:27 +0200 | [diff] [blame] | 1886 | final boolean isTop = r == top; |
| 1887 | if (aboveTop && !isTop) { |
| 1888 | continue; |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 1889 | } |
Jorim Jaggi | fe76234 | 2016-10-13 14:33:27 +0200 | [diff] [blame] | 1890 | aboveTop = false; |
Craig Mautner | d44711d | 2013-02-23 11:24:36 -0800 | [diff] [blame] | 1891 | |
Jorim Jaggi | fe76234 | 2016-10-13 14:33:27 +0200 | [diff] [blame] | 1892 | // Check whether activity should be visible without Keyguard influence |
Jorim Jaggi | 241ae10 | 2016-11-02 21:57:33 -0700 | [diff] [blame] | 1893 | final boolean visibleIgnoringKeyguard = r.shouldBeVisibleIgnoringKeyguard( |
Jorim Jaggi | 241ae10 | 2016-11-02 21:57:33 -0700 | [diff] [blame] | 1894 | behindFullscreenActivity); |
| 1895 | r.visibleIgnoringKeyguard = visibleIgnoringKeyguard; |
Jorim Jaggi | fe76234 | 2016-10-13 14:33:27 +0200 | [diff] [blame] | 1896 | |
| 1897 | // Now check whether it's really visible depending on Keyguard state. |
Jorim Jaggi | 241ae10 | 2016-11-02 21:57:33 -0700 | [diff] [blame] | 1898 | final boolean reallyVisible = checkKeyguardVisibility(r, |
chaviw | 2c50098 | 2018-01-04 17:05:05 -0800 | [diff] [blame] | 1899 | visibleIgnoringKeyguard, isTop && isTopNotPinnedStack); |
Jorim Jaggi | 241ae10 | 2016-11-02 21:57:33 -0700 | [diff] [blame] | 1900 | if (visibleIgnoringKeyguard) { |
Wale Ogunwale | 04a05ac | 2017-09-17 21:35:02 -0700 | [diff] [blame] | 1901 | behindFullscreenActivity = updateBehindFullscreen(!stackShouldBeVisible, |
Wale Ogunwale | 66e1685 | 2017-10-19 13:35:52 -0700 | [diff] [blame] | 1902 | behindFullscreenActivity, r); |
Jorim Jaggi | fe76234 | 2016-10-13 14:33:27 +0200 | [diff] [blame] | 1903 | } |
| 1904 | if (reallyVisible) { |
| 1905 | if (DEBUG_VISIBILITY) Slog.v(TAG_VISIBILITY, "Make visible? " + r |
Bryce Lee | 7ace395 | 2018-02-16 14:34:32 -0800 | [diff] [blame] | 1906 | + " finishing=" + r.finishing + " state=" + r.getState()); |
Jorim Jaggi | fe76234 | 2016-10-13 14:33:27 +0200 | [diff] [blame] | 1907 | // First: if this is not the current activity being started, make |
| 1908 | // sure it matches the current configuration. |
Andrii Kulian | a39ae3e | 2018-05-31 12:43:54 -0700 | [diff] [blame] | 1909 | if (r != starting && notifyClients) { |
Wale Ogunwale | b6d75f3 | 2018-02-22 20:44:56 -0800 | [diff] [blame] | 1910 | r.ensureActivityConfiguration(0 /* globalChanges */, preserveWindows, |
| 1911 | true /* ignoreStopState */); |
Jorim Jaggi | fe76234 | 2016-10-13 14:33:27 +0200 | [diff] [blame] | 1912 | } |
| 1913 | |
| 1914 | if (r.app == null || r.app.thread == null) { |
| 1915 | if (makeVisibleAndRestartIfNeeded(starting, configChanges, isTop, |
| 1916 | resumeNextActivity, r)) { |
| 1917 | if (activityNdx >= activities.size()) { |
| 1918 | // Record may be removed if its process needs to restart. |
| 1919 | activityNdx = activities.size() - 1; |
| 1920 | } else { |
| 1921 | resumeNextActivity = false; |
| 1922 | } |
| 1923 | } |
| 1924 | } else if (r.visible) { |
| 1925 | // If this activity is already visible, then there is nothing to do here. |
| 1926 | if (DEBUG_VISIBILITY) Slog.v(TAG_VISIBILITY, |
| 1927 | "Skipping: already visible at " + r); |
| 1928 | |
Andrii Kulian | a39ae3e | 2018-05-31 12:43:54 -0700 | [diff] [blame] | 1929 | if (r.mClientVisibilityDeferred && notifyClients) { |
| 1930 | r.makeClientVisible(); |
| 1931 | } |
| 1932 | |
Jorim Jaggi | fe76234 | 2016-10-13 14:33:27 +0200 | [diff] [blame] | 1933 | if (r.handleAlreadyVisible()) { |
Wale Ogunwale | d046a01 | 2015-12-24 13:05:59 -0800 | [diff] [blame] | 1934 | resumeNextActivity = false; |
riddle_hsu | 36ee73d | 2015-06-05 16:38:38 +0800 | [diff] [blame] | 1935 | } |
Jorim Jaggi | fe76234 | 2016-10-13 14:33:27 +0200 | [diff] [blame] | 1936 | } else { |
Andrii Kulian | a39ae3e | 2018-05-31 12:43:54 -0700 | [diff] [blame] | 1937 | r.makeVisibleIfNeeded(starting, notifyClients); |
Craig Mautner | d44711d | 2013-02-23 11:24:36 -0800 | [diff] [blame] | 1938 | } |
Jorim Jaggi | fe76234 | 2016-10-13 14:33:27 +0200 | [diff] [blame] | 1939 | // Aggregate current change flags. |
| 1940 | configChanges |= r.configChangeFlags; |
Craig Mautner | bb74246 | 2014-07-07 15:28:55 -0700 | [diff] [blame] | 1941 | } else { |
Jorim Jaggi | fe76234 | 2016-10-13 14:33:27 +0200 | [diff] [blame] | 1942 | if (DEBUG_VISIBILITY) Slog.v(TAG_VISIBILITY, "Make invisible? " + r |
Bryce Lee | 7ace395 | 2018-02-16 14:34:32 -0800 | [diff] [blame] | 1943 | + " finishing=" + r.finishing + " state=" + r.getState() |
Wale Ogunwale | 04a05ac | 2017-09-17 21:35:02 -0700 | [diff] [blame] | 1944 | + " stackShouldBeVisible=" + stackShouldBeVisible |
Wale Ogunwale | 9dcf946 | 2017-09-19 15:13:01 -0700 | [diff] [blame] | 1945 | + " behindFullscreenActivity=" + behindFullscreenActivity |
| 1946 | + " mLaunchTaskBehind=" + r.mLaunchTaskBehind); |
Wale Ogunwale | c981ad5 | 2017-06-13 11:40:06 -0700 | [diff] [blame] | 1947 | makeInvisible(r); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 1948 | } |
Jorim Jaggi | fe76234 | 2016-10-13 14:33:27 +0200 | [diff] [blame] | 1949 | } |
Wale Ogunwale | 44f036f | 2017-09-29 05:09:09 -0700 | [diff] [blame] | 1950 | final int windowingMode = getWindowingMode(); |
| 1951 | if (windowingMode == WINDOWING_MODE_FREEFORM) { |
Jorim Jaggi | fe76234 | 2016-10-13 14:33:27 +0200 | [diff] [blame] | 1952 | // The visibility of tasks and the activities they contain in freeform stack are |
| 1953 | // determined individually unlike other stacks where the visibility or fullscreen |
| 1954 | // status of an activity in a previous task affects other. |
Wale Ogunwale | 04a05ac | 2017-09-17 21:35:02 -0700 | [diff] [blame] | 1955 | behindFullscreenActivity = !stackShouldBeVisible; |
Wale Ogunwale | 6827856 | 2017-09-23 17:13:55 -0700 | [diff] [blame] | 1956 | } else if (isActivityTypeHome()) { |
Wale Ogunwale | 6fbde9f | 2017-08-24 07:24:12 -0700 | [diff] [blame] | 1957 | if (DEBUG_VISIBILITY) Slog.v(TAG_VISIBILITY, "Home task: at " + task |
Wale Ogunwale | 04a05ac | 2017-09-17 21:35:02 -0700 | [diff] [blame] | 1958 | + " stackShouldBeVisible=" + stackShouldBeVisible |
Wale Ogunwale | 6fbde9f | 2017-08-24 07:24:12 -0700 | [diff] [blame] | 1959 | + " behindFullscreenActivity=" + behindFullscreenActivity); |
| 1960 | // No other task in the home stack should be visible behind the home activity. |
| 1961 | // Home activities is usually a translucent activity with the wallpaper behind |
| 1962 | // them. However, when they don't have the wallpaper behind them, we want to |
| 1963 | // show activities in the next application stack behind them vs. another |
| 1964 | // task in the home stack like recents. |
| 1965 | behindFullscreenActivity = true; |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 1966 | } |
| 1967 | } |
Wale Ogunwale | 74e2659 | 2016-02-05 11:48:37 -0800 | [diff] [blame] | 1968 | |
Jorim Jaggi | fe76234 | 2016-10-13 14:33:27 +0200 | [diff] [blame] | 1969 | if (mTranslucentActivityWaiting != null && |
| 1970 | mUndrawnActivitiesBelowTopTranslucent.isEmpty()) { |
| 1971 | // Nothing is getting drawn or everything was already visible, don't wait for timeout. |
| 1972 | notifyActivityDrawnLocked(null); |
| 1973 | } |
| 1974 | } finally { |
Bryce Lee | 2a3cc46 | 2017-10-27 10:57:35 -0700 | [diff] [blame] | 1975 | mStackSupervisor.getKeyguardController().endActivityVisibilityUpdate(); |
Jorim Jaggi | fe76234 | 2016-10-13 14:33:27 +0200 | [diff] [blame] | 1976 | } |
| 1977 | } |
| 1978 | |
Jorim Jaggi | 8b702ed | 2017-01-20 16:59:03 +0100 | [diff] [blame] | 1979 | void addStartingWindowsForVisibleActivities(boolean taskSwitch) { |
| 1980 | for (int taskNdx = mTaskHistory.size() - 1; taskNdx >= 0; --taskNdx) { |
| 1981 | mTaskHistory.get(taskNdx).addStartingWindowsForVisibleActivities(taskSwitch); |
| 1982 | } |
| 1983 | } |
| 1984 | |
Jorim Jaggi | fe76234 | 2016-10-13 14:33:27 +0200 | [diff] [blame] | 1985 | /** |
| 1986 | * @return true if the top visible activity wants to occlude the Keyguard, false otherwise |
| 1987 | */ |
| 1988 | boolean topActivityOccludesKeyguard() { |
| 1989 | return mTopActivityOccludesKeyguard; |
| 1990 | } |
| 1991 | |
| 1992 | /** |
Wale Ogunwale | 44f036f | 2017-09-29 05:09:09 -0700 | [diff] [blame] | 1993 | * Returns true if this stack should be resized to match the bounds specified by |
| 1994 | * {@link ActivityOptions#setLaunchBounds} when launching an activity into the stack. |
| 1995 | */ |
| 1996 | boolean resizeStackWithLaunchBounds() { |
| 1997 | return inPinnedWindowingMode(); |
| 1998 | } |
| 1999 | |
Wale Ogunwale | 30e441d | 2017-11-09 08:28:45 -0800 | [diff] [blame] | 2000 | @Override |
| 2001 | public boolean supportsSplitScreenWindowingMode() { |
| 2002 | final TaskRecord topTask = topTask(); |
| 2003 | return super.supportsSplitScreenWindowingMode() |
| 2004 | && (topTask == null || topTask.supportsSplitScreenWindowingMode()); |
| 2005 | } |
| 2006 | |
Wale Ogunwale | 2b07da8 | 2017-11-08 14:52:40 -0800 | [diff] [blame] | 2007 | /** @return True if the resizing of the primary-split-screen stack affects this stack size. */ |
| 2008 | boolean affectedBySplitScreenResize() { |
| 2009 | if (!supportsSplitScreenWindowingMode()) { |
| 2010 | return false; |
| 2011 | } |
| 2012 | final int windowingMode = getWindowingMode(); |
| 2013 | return windowingMode != WINDOWING_MODE_FREEFORM && windowingMode != WINDOWING_MODE_PINNED; |
| 2014 | } |
| 2015 | |
Wale Ogunwale | 44f036f | 2017-09-29 05:09:09 -0700 | [diff] [blame] | 2016 | /** |
Jorim Jaggi | fe76234 | 2016-10-13 14:33:27 +0200 | [diff] [blame] | 2017 | * @return the top most visible activity that wants to dismiss Keyguard |
| 2018 | */ |
| 2019 | ActivityRecord getTopDismissingKeyguardActivity() { |
| 2020 | return mTopDismissingKeyguardActivity; |
| 2021 | } |
| 2022 | |
| 2023 | /** |
| 2024 | * Checks whether {@param r} should be visible depending on Keyguard state and updates |
| 2025 | * {@link #mTopActivityOccludesKeyguard} and {@link #mTopDismissingKeyguardActivity} if |
| 2026 | * necessary. |
| 2027 | * |
| 2028 | * @return true if {@param r} is visible taken Keyguard state into account, false otherwise |
| 2029 | */ |
Wale Ogunwale | 2cca862 | 2017-12-11 08:40:13 -0800 | [diff] [blame] | 2030 | boolean checkKeyguardVisibility(ActivityRecord r, boolean shouldBeVisible, boolean isTop) { |
Lucas Dupin | 47a65c7 | 2018-02-15 14:16:18 -0800 | [diff] [blame] | 2031 | final int displayId = mDisplayId != INVALID_DISPLAY ? mDisplayId : DEFAULT_DISPLAY; |
| 2032 | final boolean keyguardOrAodShowing = mStackSupervisor.getKeyguardController() |
| 2033 | .isKeyguardOrAodShowing(displayId); |
Bryce Lee | 2a3cc46 | 2017-10-27 10:57:35 -0700 | [diff] [blame] | 2034 | final boolean keyguardLocked = mStackSupervisor.getKeyguardController().isKeyguardLocked(); |
Wale Ogunwale | 2cca862 | 2017-12-11 08:40:13 -0800 | [diff] [blame] | 2035 | final boolean showWhenLocked = r.canShowWhenLocked(); |
Jorim Jaggi | e69c931 | 2016-10-31 18:24:38 -0700 | [diff] [blame] | 2036 | final boolean dismissKeyguard = r.hasDismissKeyguardWindows(); |
Jorim Jaggi | fe76234 | 2016-10-13 14:33:27 +0200 | [diff] [blame] | 2037 | if (shouldBeVisible) { |
Jorim Jaggi | e69c931 | 2016-10-31 18:24:38 -0700 | [diff] [blame] | 2038 | if (dismissKeyguard && mTopDismissingKeyguardActivity == null) { |
Jorim Jaggi | fe76234 | 2016-10-13 14:33:27 +0200 | [diff] [blame] | 2039 | mTopDismissingKeyguardActivity = r; |
| 2040 | } |
| 2041 | |
| 2042 | // Only the top activity may control occluded, as we can't occlude the Keyguard if the |
| 2043 | // top app doesn't want to occlude it. |
| 2044 | if (isTop) { |
| 2045 | mTopActivityOccludesKeyguard |= showWhenLocked; |
Wale Ogunwale | c219c0b | 2015-09-12 09:18:07 -0700 | [diff] [blame] | 2046 | } |
Andrii Kulian | fc8f82b | 2017-01-26 13:17:27 -0800 | [diff] [blame] | 2047 | |
Andrii Kulian | 7211d2e | 2017-01-27 15:58:05 -0800 | [diff] [blame] | 2048 | final boolean canShowWithKeyguard = canShowWithInsecureKeyguard() |
Bryce Lee | 2a3cc46 | 2017-10-27 10:57:35 -0700 | [diff] [blame] | 2049 | && mStackSupervisor.getKeyguardController().canDismissKeyguard(); |
Andrii Kulian | fc8f82b | 2017-01-26 13:17:27 -0800 | [diff] [blame] | 2050 | if (canShowWithKeyguard) { |
| 2051 | return true; |
| 2052 | } |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 2053 | } |
Lucas Dupin | 47a65c7 | 2018-02-15 14:16:18 -0800 | [diff] [blame] | 2054 | if (keyguardOrAodShowing) { |
Jorim Jaggi | e69c931 | 2016-10-31 18:24:38 -0700 | [diff] [blame] | 2055 | // 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] | 2056 | // right away and AOD isn't visible. |
Bryce Lee | 2a3cc46 | 2017-10-27 10:57:35 -0700 | [diff] [blame] | 2057 | return shouldBeVisible && mStackSupervisor.getKeyguardController() |
Jorim Jaggi | 0796187 | 2016-11-23 11:28:57 +0100 | [diff] [blame] | 2058 | .canShowActivityWhileKeyguardShowing(r, dismissKeyguard); |
Jorim Jaggi | fe76234 | 2016-10-13 14:33:27 +0200 | [diff] [blame] | 2059 | } else if (keyguardLocked) { |
Bryce Lee | 2a3cc46 | 2017-10-27 10:57:35 -0700 | [diff] [blame] | 2060 | return shouldBeVisible && mStackSupervisor.getKeyguardController().canShowWhileOccluded( |
Jorim Jaggi | 0796187 | 2016-11-23 11:28:57 +0100 | [diff] [blame] | 2061 | dismissKeyguard, showWhenLocked); |
Jorim Jaggi | fe76234 | 2016-10-13 14:33:27 +0200 | [diff] [blame] | 2062 | } else { |
| 2063 | return shouldBeVisible; |
Craig Mautner | eb8abf7 | 2014-07-02 15:04:09 -0700 | [diff] [blame] | 2064 | } |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 2065 | } |
Craig Mautner | 5854780 | 2013-03-05 08:23:53 -0800 | [diff] [blame] | 2066 | |
Andrii Kulian | fc8f82b | 2017-01-26 13:17:27 -0800 | [diff] [blame] | 2067 | /** |
| 2068 | * Check if the display to which this stack is attached has |
Andrii Kulian | 7211d2e | 2017-01-27 15:58:05 -0800 | [diff] [blame] | 2069 | * {@link Display#FLAG_CAN_SHOW_WITH_INSECURE_KEYGUARD} applied. |
Andrii Kulian | fc8f82b | 2017-01-26 13:17:27 -0800 | [diff] [blame] | 2070 | */ |
Andrii Kulian | 7211d2e | 2017-01-27 15:58:05 -0800 | [diff] [blame] | 2071 | private boolean canShowWithInsecureKeyguard() { |
Wale Ogunwale | 9dcf946 | 2017-09-19 15:13:01 -0700 | [diff] [blame] | 2072 | final ActivityDisplay activityDisplay = getDisplay(); |
Andrii Kulian | fc8f82b | 2017-01-26 13:17:27 -0800 | [diff] [blame] | 2073 | if (activityDisplay == null) { |
| 2074 | throw new IllegalStateException("Stack is not attached to any display, stackId=" |
| 2075 | + mStackId); |
| 2076 | } |
| 2077 | |
| 2078 | final int flags = activityDisplay.mDisplay.getFlags(); |
Andrii Kulian | 7211d2e | 2017-01-27 15:58:05 -0800 | [diff] [blame] | 2079 | return (flags & FLAG_CAN_SHOW_WITH_INSECURE_KEYGUARD) != 0; |
Andrii Kulian | fc8f82b | 2017-01-26 13:17:27 -0800 | [diff] [blame] | 2080 | } |
| 2081 | |
Filip Gruszczynski | 9104aea | 2015-11-13 16:42:05 -0800 | [diff] [blame] | 2082 | private void checkTranslucentActivityWaiting(ActivityRecord top) { |
| 2083 | if (mTranslucentActivityWaiting != top) { |
| 2084 | mUndrawnActivitiesBelowTopTranslucent.clear(); |
| 2085 | if (mTranslucentActivityWaiting != null) { |
| 2086 | // Call the callback with a timeout indication. |
| 2087 | notifyActivityDrawnLocked(null); |
| 2088 | mTranslucentActivityWaiting = null; |
| 2089 | } |
| 2090 | mHandler.removeMessages(TRANSLUCENT_TIMEOUT_MSG); |
| 2091 | } |
| 2092 | } |
| 2093 | |
| 2094 | private boolean makeVisibleAndRestartIfNeeded(ActivityRecord starting, int configChanges, |
Wale Ogunwale | d046a01 | 2015-12-24 13:05:59 -0800 | [diff] [blame] | 2095 | boolean isTop, boolean andResume, ActivityRecord r) { |
Filip Gruszczynski | 9104aea | 2015-11-13 16:42:05 -0800 | [diff] [blame] | 2096 | // We need to make sure the app is running if it's the top, or it is just made visible from |
| 2097 | // invisible. If the app is already visible, it must have died while it was visible. In this |
| 2098 | // case, we'll show the dead window but will not restart the app. Otherwise we could end up |
| 2099 | // thrashing. |
Filip Gruszczynski | 21199bd | 2015-12-02 12:49:58 -0800 | [diff] [blame] | 2100 | if (isTop || !r.visible) { |
Filip Gruszczynski | 9104aea | 2015-11-13 16:42:05 -0800 | [diff] [blame] | 2101 | // This activity needs to be visible, but isn't even running... |
| 2102 | // get it started and resume if no other stack in this stack is resumed. |
| 2103 | if (DEBUG_VISIBILITY) Slog.v(TAG_VISIBILITY, "Start and freeze screen for " + r); |
| 2104 | if (r != starting) { |
| 2105 | r.startFreezingScreenLocked(r.app, configChanges); |
| 2106 | } |
| 2107 | if (!r.visible || r.mLaunchTaskBehind) { |
| 2108 | if (DEBUG_VISIBILITY) Slog.v(TAG_VISIBILITY, "Starting and making visible: " + r); |
Andrii Kulian | 21713ac | 2016-10-12 22:05:05 -0700 | [diff] [blame] | 2109 | r.setVisible(true); |
Filip Gruszczynski | 9104aea | 2015-11-13 16:42:05 -0800 | [diff] [blame] | 2110 | } |
| 2111 | if (r != starting) { |
Wale Ogunwale | d046a01 | 2015-12-24 13:05:59 -0800 | [diff] [blame] | 2112 | mStackSupervisor.startSpecificActivityLocked(r, andResume, false); |
Filip Gruszczynski | 9104aea | 2015-11-13 16:42:05 -0800 | [diff] [blame] | 2113 | return true; |
| 2114 | } |
| 2115 | } |
| 2116 | return false; |
| 2117 | } |
| 2118 | |
Wale Ogunwale | c981ad5 | 2017-06-13 11:40:06 -0700 | [diff] [blame] | 2119 | // TODO: Should probably be moved into ActivityRecord. |
| 2120 | private void makeInvisible(ActivityRecord r) { |
Filip Gruszczynski | 9104aea | 2015-11-13 16:42:05 -0800 | [diff] [blame] | 2121 | if (!r.visible) { |
| 2122 | if (DEBUG_VISIBILITY) Slog.v(TAG_VISIBILITY, "Already invisible: " + r); |
| 2123 | return; |
| 2124 | } |
| 2125 | // Now for any activities that aren't visible to the user, make sure they no longer are |
| 2126 | // keeping the screen frozen. |
Bryce Lee | 7ace395 | 2018-02-16 14:34:32 -0800 | [diff] [blame] | 2127 | if (DEBUG_VISIBILITY) Slog.v(TAG_VISIBILITY, "Making invisible: " + r + " " + r.getState()); |
Filip Gruszczynski | 9104aea | 2015-11-13 16:42:05 -0800 | [diff] [blame] | 2128 | try { |
Wale Ogunwale | b9a0c99 | 2017-04-18 07:25:20 -0700 | [diff] [blame] | 2129 | final boolean canEnterPictureInPicture = r.checkEnterPictureInPictureState( |
Winson Chung | 298f95b | 2017-08-10 15:57:18 -0700 | [diff] [blame] | 2130 | "makeInvisible", true /* beforeStopping */); |
Wale Ogunwale | 08488a6 | 2017-09-05 12:37:03 -0700 | [diff] [blame] | 2131 | // Defer telling the client it is hidden if it can enter Pip and isn't current paused, |
| 2132 | // stopped or stopping. This gives it a chance to enter Pip in onPause(). |
| 2133 | // TODO: There is still a question surrounding activities in multi-window mode that want |
| 2134 | // to enter Pip after they are paused, but are still visible. I they should be okay to |
| 2135 | // enter Pip in those cases, but not "auto-Pip" which is what this condition covers and |
| 2136 | // the current contract for "auto-Pip" is that the app should enter it before onPause |
| 2137 | // returns. Just need to confirm this reasoning makes sense. |
Wale Ogunwale | 8997322 | 2017-04-23 18:39:45 -0700 | [diff] [blame] | 2138 | final boolean deferHidingClient = canEnterPictureInPicture |
Bryce Lee | 7ace395 | 2018-02-16 14:34:32 -0800 | [diff] [blame] | 2139 | && !r.isState(STOPPING, STOPPED, PAUSED); |
Wale Ogunwale | ec95064 | 2017-04-25 07:44:21 -0700 | [diff] [blame] | 2140 | r.setDeferHidingClient(deferHidingClient); |
| 2141 | r.setVisible(false); |
Wale Ogunwale | b9a0c99 | 2017-04-18 07:25:20 -0700 | [diff] [blame] | 2142 | |
Bryce Lee | 7ace395 | 2018-02-16 14:34:32 -0800 | [diff] [blame] | 2143 | switch (r.getState()) { |
Filip Gruszczynski | 9104aea | 2015-11-13 16:42:05 -0800 | [diff] [blame] | 2144 | case STOPPING: |
| 2145 | case STOPPED: |
| 2146 | if (r.app != null && r.app.thread != null) { |
| 2147 | if (DEBUG_VISIBILITY) Slog.v(TAG_VISIBILITY, |
| 2148 | "Scheduling invisibility: " + r); |
Bryce Lee | b0f993f | 2018-03-02 15:38:01 -0800 | [diff] [blame] | 2149 | mService.getLifecycleManager().scheduleTransaction(r.app.thread, r.appToken, |
Andrii Kulian | 9c5ea9c | 2017-12-07 09:31:01 -0800 | [diff] [blame] | 2150 | WindowVisibilityItem.obtain(false /* showWindow */)); |
Filip Gruszczynski | 9104aea | 2015-11-13 16:42:05 -0800 | [diff] [blame] | 2151 | } |
Winson Chung | c2baac0 | 2017-01-11 13:34:47 -0800 | [diff] [blame] | 2152 | |
| 2153 | // Reset the flag indicating that an app can enter picture-in-picture once the |
| 2154 | // activity is hidden |
Winson Chung | f7e03e1 | 2017-08-22 11:32:16 -0700 | [diff] [blame] | 2155 | r.supportsEnterPipOnTaskSwitch = false; |
Filip Gruszczynski | 9104aea | 2015-11-13 16:42:05 -0800 | [diff] [blame] | 2156 | break; |
| 2157 | |
| 2158 | case INITIALIZING: |
| 2159 | case RESUMED: |
| 2160 | case PAUSING: |
| 2161 | case PAUSED: |
Wale Ogunwale | c981ad5 | 2017-06-13 11:40:06 -0700 | [diff] [blame] | 2162 | addToStopping(r, true /* scheduleIdle */, |
| 2163 | canEnterPictureInPicture /* idleDelayed */); |
Filip Gruszczynski | 9104aea | 2015-11-13 16:42:05 -0800 | [diff] [blame] | 2164 | break; |
| 2165 | |
| 2166 | default: |
| 2167 | break; |
| 2168 | } |
| 2169 | } catch (Exception e) { |
| 2170 | // Just skip on any failure; we'll make it visible when it next restarts. |
| 2171 | Slog.w(TAG, "Exception thrown making hidden: " + r.intent.getComponent(), e); |
| 2172 | } |
| 2173 | } |
| 2174 | |
| 2175 | private boolean updateBehindFullscreen(boolean stackInvisible, boolean behindFullscreenActivity, |
Wale Ogunwale | 66e1685 | 2017-10-19 13:35:52 -0700 | [diff] [blame] | 2176 | ActivityRecord r) { |
Filip Gruszczynski | 9104aea | 2015-11-13 16:42:05 -0800 | [diff] [blame] | 2177 | if (r.fullscreen) { |
Filip Gruszczynski | 9104aea | 2015-11-13 16:42:05 -0800 | [diff] [blame] | 2178 | if (DEBUG_VISIBILITY) Slog.v(TAG_VISIBILITY, "Fullscreen: at " + r |
Wale Ogunwale | 673cbd2 | 2016-01-30 18:30:55 -0800 | [diff] [blame] | 2179 | + " stackInvisible=" + stackInvisible |
| 2180 | + " behindFullscreenActivity=" + behindFullscreenActivity); |
Filip Gruszczynski | 0e381e2 | 2016-01-14 16:31:33 -0800 | [diff] [blame] | 2181 | // At this point, nothing else needs to be shown in this task. |
Filip Gruszczynski | 9104aea | 2015-11-13 16:42:05 -0800 | [diff] [blame] | 2182 | behindFullscreenActivity = true; |
Filip Gruszczynski | 9104aea | 2015-11-13 16:42:05 -0800 | [diff] [blame] | 2183 | } |
| 2184 | return behindFullscreenActivity; |
| 2185 | } |
| 2186 | |
Todd Kennedy | aab56db | 2015-01-30 09:39:53 -0800 | [diff] [blame] | 2187 | void convertActivityToTranslucent(ActivityRecord r) { |
Craig Mautner | 5eda9b3 | 2013-07-02 11:58:16 -0700 | [diff] [blame] | 2188 | mTranslucentActivityWaiting = r; |
| 2189 | mUndrawnActivitiesBelowTopTranslucent.clear(); |
| 2190 | mHandler.sendEmptyMessageDelayed(TRANSLUCENT_TIMEOUT_MSG, TRANSLUCENT_CONVERSION_TIMEOUT); |
| 2191 | } |
| 2192 | |
Dianne Hackborn | b5a380d | 2015-05-20 18:18:46 -0700 | [diff] [blame] | 2193 | void clearOtherAppTimeTrackers(AppTimeTracker except) { |
| 2194 | for (int taskNdx = mTaskHistory.size() - 1; taskNdx >= 0; --taskNdx) { |
| 2195 | final TaskRecord task = mTaskHistory.get(taskNdx); |
| 2196 | final ArrayList<ActivityRecord> activities = task.mActivities; |
| 2197 | for (int activityNdx = activities.size() - 1; activityNdx >= 0; --activityNdx) { |
| 2198 | final ActivityRecord r = activities.get(activityNdx); |
| 2199 | if ( r.appTimeTracker != except) { |
| 2200 | r.appTimeTracker = null; |
| 2201 | } |
| 2202 | } |
| 2203 | } |
| 2204 | } |
| 2205 | |
Craig Mautner | 5eda9b3 | 2013-07-02 11:58:16 -0700 | [diff] [blame] | 2206 | /** |
| 2207 | * Called as activities below the top translucent activity are redrawn. When the last one is |
| 2208 | * redrawn notify the top activity by calling |
| 2209 | * {@link Activity#onTranslucentConversionComplete}. |
| 2210 | * |
| 2211 | * @param r The most recent background activity to be drawn. Or, if r is null then a timeout |
| 2212 | * occurred and the activity will be notified immediately. |
| 2213 | */ |
| 2214 | void notifyActivityDrawnLocked(ActivityRecord r) { |
| 2215 | if ((r == null) |
| 2216 | || (mUndrawnActivitiesBelowTopTranslucent.remove(r) && |
| 2217 | mUndrawnActivitiesBelowTopTranslucent.isEmpty())) { |
| 2218 | // The last undrawn activity below the top has just been drawn. If there is an |
| 2219 | // opaque activity at the top, notify it that it can become translucent safely now. |
| 2220 | final ActivityRecord waitingActivity = mTranslucentActivityWaiting; |
| 2221 | mTranslucentActivityWaiting = null; |
| 2222 | mUndrawnActivitiesBelowTopTranslucent.clear(); |
| 2223 | mHandler.removeMessages(TRANSLUCENT_TIMEOUT_MSG); |
| 2224 | |
Craig Mautner | 71dd1b6 | 2014-02-18 15:48:52 -0800 | [diff] [blame] | 2225 | if (waitingActivity != null) { |
| 2226 | mWindowManager.setWindowOpaque(waitingActivity.appToken, false); |
| 2227 | if (waitingActivity.app != null && waitingActivity.app.thread != null) { |
| 2228 | try { |
| 2229 | waitingActivity.app.thread.scheduleTranslucentConversionComplete( |
| 2230 | waitingActivity.appToken, r != null); |
| 2231 | } catch (RemoteException e) { |
| 2232 | } |
Craig Mautner | 5eda9b3 | 2013-07-02 11:58:16 -0700 | [diff] [blame] | 2233 | } |
| 2234 | } |
| 2235 | } |
| 2236 | } |
| 2237 | |
Craig Mautner | a61bc65 | 2013-10-28 15:43:18 -0700 | [diff] [blame] | 2238 | /** If any activities below the top running one are in the INITIALIZING state and they have a |
| 2239 | * starting window displayed then remove that starting window. It is possible that the activity |
| 2240 | * in this state will never resumed in which case that starting window will be orphaned. */ |
| 2241 | void cancelInitializingActivities() { |
Filip Gruszczynski | 3e85ba2 | 2015-10-05 22:48:30 -0700 | [diff] [blame] | 2242 | final ActivityRecord topActivity = topRunningActivityLocked(); |
Craig Mautner | a61bc65 | 2013-10-28 15:43:18 -0700 | [diff] [blame] | 2243 | boolean aboveTop = true; |
Wale Ogunwale | 6874114 | 2016-05-17 09:40:02 -0700 | [diff] [blame] | 2244 | // We don't want to clear starting window for activities that aren't behind fullscreen |
| 2245 | // activities as we need to display their starting window until they are done initializing. |
| 2246 | boolean behindFullscreenActivity = false; |
Wale Ogunwale | 98742a5 | 2016-07-12 10:29:12 -0700 | [diff] [blame] | 2247 | |
Wale Ogunwale | 9dcf946 | 2017-09-19 15:13:01 -0700 | [diff] [blame] | 2248 | if (!shouldBeVisible(null)) { |
Wale Ogunwale | 98742a5 | 2016-07-12 10:29:12 -0700 | [diff] [blame] | 2249 | // The stack is not visible, so no activity in it should be displaying a starting |
| 2250 | // window. Mark all activities below top and behind fullscreen. |
| 2251 | aboveTop = false; |
| 2252 | behindFullscreenActivity = true; |
| 2253 | } |
| 2254 | |
Craig Mautner | a61bc65 | 2013-10-28 15:43:18 -0700 | [diff] [blame] | 2255 | for (int taskNdx = mTaskHistory.size() - 1; taskNdx >= 0; --taskNdx) { |
| 2256 | final ArrayList<ActivityRecord> activities = mTaskHistory.get(taskNdx).mActivities; |
| 2257 | for (int activityNdx = activities.size() - 1; activityNdx >= 0; --activityNdx) { |
| 2258 | final ActivityRecord r = activities.get(activityNdx); |
| 2259 | if (aboveTop) { |
| 2260 | if (r == topActivity) { |
| 2261 | aboveTop = false; |
| 2262 | } |
Wale Ogunwale | 6874114 | 2016-05-17 09:40:02 -0700 | [diff] [blame] | 2263 | behindFullscreenActivity |= r.fullscreen; |
Craig Mautner | a61bc65 | 2013-10-28 15:43:18 -0700 | [diff] [blame] | 2264 | continue; |
| 2265 | } |
| 2266 | |
Wale Ogunwale | 26c0dfe | 2016-12-14 14:42:30 -0800 | [diff] [blame] | 2267 | r.removeOrphanedStartingWindow(behindFullscreenActivity); |
Wale Ogunwale | 6874114 | 2016-05-17 09:40:02 -0700 | [diff] [blame] | 2268 | behindFullscreenActivity |= r.fullscreen; |
Craig Mautner | a61bc65 | 2013-10-28 15:43:18 -0700 | [diff] [blame] | 2269 | } |
| 2270 | } |
| 2271 | } |
| 2272 | |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 2273 | /** |
| 2274 | * Ensure that the top activity in the stack is resumed. |
| 2275 | * |
| 2276 | * @param prev The previously resumed activity, for when in the process |
| 2277 | * of pausing; can be null to call from elsewhere. |
Wale Ogunwale | d046a01 | 2015-12-24 13:05:59 -0800 | [diff] [blame] | 2278 | * @param options Activity options. |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 2279 | * |
| 2280 | * @return Returns true if something is being resumed, or false if |
| 2281 | * nothing happened. |
Wale Ogunwale | d046a01 | 2015-12-24 13:05:59 -0800 | [diff] [blame] | 2282 | * |
| 2283 | * NOTE: It is not safe to call this method directly as it can cause an activity in a |
| 2284 | * non-focused stack to be resumed. |
| 2285 | * Use {@link ActivityStackSupervisor#resumeFocusedStackTopActivityLocked} to resume the |
| 2286 | * right activity for the current system state. |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 2287 | */ |
Andreas Gampe | a36dc62 | 2018-02-05 17:19:22 -0800 | [diff] [blame] | 2288 | @GuardedBy("mService") |
Wale Ogunwale | d046a01 | 2015-12-24 13:05:59 -0800 | [diff] [blame] | 2289 | boolean resumeTopActivityUncheckedLocked(ActivityRecord prev, ActivityOptions options) { |
Craig Mautner | 42d04db | 2014-11-06 12:13:23 -0800 | [diff] [blame] | 2290 | if (mStackSupervisor.inResumeTopActivity) { |
Craig Mautner | 544efa7 | 2014-09-04 16:41:20 -0700 | [diff] [blame] | 2291 | // Don't even start recursing. |
| 2292 | return false; |
| 2293 | } |
| 2294 | |
| 2295 | boolean result = false; |
| 2296 | try { |
| 2297 | // Protect against recursion. |
Craig Mautner | 42d04db | 2014-11-06 12:13:23 -0800 | [diff] [blame] | 2298 | mStackSupervisor.inResumeTopActivity = true; |
Bryce Lee | 69ad818 | 2017-09-28 10:01:36 -0700 | [diff] [blame] | 2299 | result = resumeTopActivityInnerLocked(prev, options); |
Bryce Lee | fc7cedd | 2018-03-01 15:38:07 -0800 | [diff] [blame] | 2300 | |
| 2301 | // When resuming the top activity, it may be necessary to pause the top activity (for |
| 2302 | // example, returning to the lock screen. We suppress the normal pause logic in |
| 2303 | // {@link #resumeTopActivityUncheckedLocked}, since the top activity is resumed at the |
| 2304 | // end. We call the {@link ActivityStackSupervisor#checkReadyForSleepLocked} again here |
| 2305 | // to ensure any necessary pause logic occurs. In the case where the Activity will be |
| 2306 | // shown regardless of the lock screen, the call to |
| 2307 | // {@link ActivityStackSupervisor#checkReadyForSleepLocked} is skipped. |
| 2308 | final ActivityRecord next = topRunningActivityLocked(true /* focusableOnly */); |
| 2309 | if (next == null || !next.canTurnScreenOn()) { |
| 2310 | checkReadyForSleep(); |
| 2311 | } |
Craig Mautner | 544efa7 | 2014-09-04 16:41:20 -0700 | [diff] [blame] | 2312 | } finally { |
Craig Mautner | 42d04db | 2014-11-06 12:13:23 -0800 | [diff] [blame] | 2313 | mStackSupervisor.inResumeTopActivity = false; |
Craig Mautner | 544efa7 | 2014-09-04 16:41:20 -0700 | [diff] [blame] | 2314 | } |
chaviw | 59b9885 | 2017-06-13 12:05:44 -0700 | [diff] [blame] | 2315 | |
Craig Mautner | 544efa7 | 2014-09-04 16:41:20 -0700 | [diff] [blame] | 2316 | return result; |
| 2317 | } |
| 2318 | |
Bryce Lee | c4ab62a | 2018-03-05 14:19:26 -0800 | [diff] [blame] | 2319 | /** |
| 2320 | * Returns the currently resumed activity. |
| 2321 | */ |
| 2322 | protected ActivityRecord getResumedActivity() { |
| 2323 | return mResumedActivity; |
| 2324 | } |
| 2325 | |
Bryce Lee | 84730a0 | 2018-04-03 14:10:04 -0700 | [diff] [blame] | 2326 | private void setResumedActivity(ActivityRecord r, String reason) { |
| 2327 | if (mResumedActivity == r) { |
| 2328 | return; |
| 2329 | } |
Bryce Lee | c4ab62a | 2018-03-05 14:19:26 -0800 | [diff] [blame] | 2330 | |
Bryce Lee | 84730a0 | 2018-04-03 14:10:04 -0700 | [diff] [blame] | 2331 | if (DEBUG_STACK) Slog.d(TAG_STACK, "setResumedActivity stack:" + this + " + from: " |
| 2332 | + mResumedActivity + " to:" + r + " reason:" + reason); |
| 2333 | mResumedActivity = r; |
Chong Zhang | 6cda19c | 2016-06-14 19:07:56 -0700 | [diff] [blame] | 2334 | } |
| 2335 | |
Andreas Gampe | a36dc62 | 2018-02-05 17:19:22 -0800 | [diff] [blame] | 2336 | @GuardedBy("mService") |
Chong Zhang | 280d332 | 2015-11-03 17:27:26 -0800 | [diff] [blame] | 2337 | private boolean resumeTopActivityInnerLocked(ActivityRecord prev, ActivityOptions options) { |
Dianne Hackborn | 7622a0f | 2014-09-30 14:31:42 -0700 | [diff] [blame] | 2338 | if (!mService.mBooting && !mService.mBooted) { |
| 2339 | // Not ready yet! |
| 2340 | return false; |
| 2341 | } |
| 2342 | |
Winson Chung | 3f103eb | 2017-04-12 21:53:59 -0700 | [diff] [blame] | 2343 | // Find the next top-most activity to resume in this stack that is not finishing and is |
| 2344 | // focusable. If it is not focusable, we will fall into the case below to resume the |
| 2345 | // top activity in the next focusable task. |
| 2346 | final ActivityRecord next = topRunningActivityLocked(true /* focusableOnly */); |
Andrii Kulian | 7fc2281 | 2016-12-28 13:04:11 -0800 | [diff] [blame] | 2347 | |
| 2348 | final boolean hasRunningActivity = next != null; |
| 2349 | |
Andrii Kulian | 94e82d9b0 | 2017-07-13 15:33:06 -0700 | [diff] [blame] | 2350 | // TODO: Maybe this entire condition can get removed? |
Wale Ogunwale | 66e1685 | 2017-10-19 13:35:52 -0700 | [diff] [blame] | 2351 | if (hasRunningActivity && !isAttached()) { |
Craig Mautner | df88d73 | 2014-01-27 09:21:32 -0800 | [diff] [blame] | 2352 | return false; |
| 2353 | } |
| 2354 | |
Wale Ogunwale | 2be760d | 2016-02-17 11:16:10 -0800 | [diff] [blame] | 2355 | mStackSupervisor.cancelInitializingActivities(); |
Craig Mautner | a61bc65 | 2013-10-28 15:43:18 -0700 | [diff] [blame] | 2356 | |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 2357 | // Remember how we'll process this pause/resume situation, and ensure |
| 2358 | // that the state is reset however we wind up proceeding. |
Wale Ogunwale | c59b4f6 | 2017-11-30 11:05:43 -0800 | [diff] [blame] | 2359 | boolean userLeaving = mStackSupervisor.mUserLeaving; |
Craig Mautner | de4ef02 | 2013-04-07 19:01:33 -0700 | [diff] [blame] | 2360 | mStackSupervisor.mUserLeaving = false; |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 2361 | |
Andrii Kulian | 7fc2281 | 2016-12-28 13:04:11 -0800 | [diff] [blame] | 2362 | if (!hasRunningActivity) { |
| 2363 | // There are no activities left in the stack, let's look somewhere else. |
| 2364 | return resumeTopActivityInNextFocusableStack(prev, options, "noMoreActivities"); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 2365 | } |
| 2366 | |
| 2367 | next.delayedResume = false; |
Craig Mautner | 5854780 | 2013-03-05 08:23:53 -0800 | [diff] [blame] | 2368 | |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 2369 | // If the top activity is the resumed one, nothing to do. |
Bryce Lee | 7ace395 | 2018-02-16 14:34:32 -0800 | [diff] [blame] | 2370 | if (mResumedActivity == next && next.isState(RESUMED) |
| 2371 | && mStackSupervisor.allResumedActivitiesComplete()) { |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 2372 | // Make sure we have executed any pending transitions, since there |
| 2373 | // should be nothing left to do at this point. |
skuhne@google.com | 1b974dc | 2016-12-09 13:41:29 -0800 | [diff] [blame] | 2374 | executeAppTransition(options); |
Wale Ogunwale | 0fc365c | 2015-05-25 19:35:42 -0700 | [diff] [blame] | 2375 | if (DEBUG_STATES) Slog.d(TAG_STATES, |
| 2376 | "resumeTopActivityLocked: Top activity resumed " + next); |
Craig Mautner | cf910b0 | 2013-04-23 11:23:27 -0700 | [diff] [blame] | 2377 | if (DEBUG_STACK) mStackSupervisor.validateTopActivitiesLocked(); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 2378 | return false; |
| 2379 | } |
| 2380 | |
| 2381 | // If we are sleeping, and there is no resumed activity, and the top |
| 2382 | // activity is paused, well that is the state we want. |
David Stevens | 9440dc8 | 2017-03-16 19:00:20 -0700 | [diff] [blame] | 2383 | if (shouldSleepOrShutDownActivities() |
p13451 | dbad287 | 2012-04-18 11:39:23 +0900 | [diff] [blame] | 2384 | && mLastPausedActivity == next |
Craig Mautner | 5314a40 | 2013-09-26 12:40:16 -0700 | [diff] [blame] | 2385 | && mStackSupervisor.allPausedActivitiesComplete()) { |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 2386 | // Make sure we have executed any pending transitions, since there |
| 2387 | // should be nothing left to do at this point. |
skuhne@google.com | 1b974dc | 2016-12-09 13:41:29 -0800 | [diff] [blame] | 2388 | executeAppTransition(options); |
Wale Ogunwale | 0fc365c | 2015-05-25 19:35:42 -0700 | [diff] [blame] | 2389 | if (DEBUG_STATES) Slog.d(TAG_STATES, |
| 2390 | "resumeTopActivityLocked: Going to sleep and all paused"); |
Craig Mautner | cf910b0 | 2013-04-23 11:23:27 -0700 | [diff] [blame] | 2391 | if (DEBUG_STACK) mStackSupervisor.validateTopActivitiesLocked(); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 2392 | return false; |
| 2393 | } |
Dianne Hackborn | 80a4af2 | 2012-08-27 19:18:31 -0700 | [diff] [blame] | 2394 | |
| 2395 | // Make sure that the user who owns this activity is started. If not, |
| 2396 | // we will just leave it as is because someone should be bringing |
| 2397 | // another user's activities to the top of the stack. |
Fyodor Kupolov | 610acda | 2015-10-19 18:44:07 -0700 | [diff] [blame] | 2398 | if (!mService.mUserController.hasStartedUserState(next.userId)) { |
Dianne Hackborn | 80a4af2 | 2012-08-27 19:18:31 -0700 | [diff] [blame] | 2399 | Slog.w(TAG, "Skipping resume of top activity " + next |
| 2400 | + ": user " + next.userId + " is stopped"); |
Craig Mautner | cf910b0 | 2013-04-23 11:23:27 -0700 | [diff] [blame] | 2401 | if (DEBUG_STACK) mStackSupervisor.validateTopActivitiesLocked(); |
Dianne Hackborn | 80a4af2 | 2012-08-27 19:18:31 -0700 | [diff] [blame] | 2402 | return false; |
| 2403 | } |
| 2404 | |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 2405 | // The activity may be waiting for stop, but that is no longer |
| 2406 | // appropriate for it. |
Craig Mautner | de4ef02 | 2013-04-07 19:01:33 -0700 | [diff] [blame] | 2407 | mStackSupervisor.mStoppingActivities.remove(next); |
Craig Mautner | 0eea92c | 2013-05-16 13:35:39 -0700 | [diff] [blame] | 2408 | mStackSupervisor.mGoingToSleepActivities.remove(next); |
Dianne Hackborn | 4eba96b | 2011-01-21 13:34:36 -0800 | [diff] [blame] | 2409 | next.sleeping = false; |
Bryce Lee | 4a19438 | 2017-04-04 14:32:48 -0700 | [diff] [blame] | 2410 | mStackSupervisor.mActivitiesWaitingForVisibleActivity.remove(next); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 2411 | |
Wale Ogunwale | ee006da | 2015-03-30 14:49:25 -0700 | [diff] [blame] | 2412 | if (DEBUG_SWITCH) Slog.v(TAG_SWITCH, "Resuming " + next); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 2413 | |
Wale Ogunwale | 5658e4b | 2016-02-12 12:22:19 -0800 | [diff] [blame] | 2414 | // If we are currently pausing an activity, then don't do anything until that is done. |
Craig Mautner | 69ada55 | 2013-04-18 13:51:51 -0700 | [diff] [blame] | 2415 | if (!mStackSupervisor.allPausedActivitiesComplete()) { |
Wale Ogunwale | ee006da | 2015-03-30 14:49:25 -0700 | [diff] [blame] | 2416 | if (DEBUG_SWITCH || DEBUG_PAUSE || DEBUG_STATES) Slog.v(TAG_PAUSE, |
Craig Mautner | ac6f843 | 2013-07-17 13:24:59 -0700 | [diff] [blame] | 2417 | "resumeTopActivityLocked: Skip resume: some activity pausing."); |
Craig Mautner | cf910b0 | 2013-04-23 11:23:27 -0700 | [diff] [blame] | 2418 | if (DEBUG_STACK) mStackSupervisor.validateTopActivitiesLocked(); |
Dianne Hackborn | 621e2fe | 2012-02-16 17:07:33 -0800 | [diff] [blame] | 2419 | return false; |
| 2420 | } |
| 2421 | |
Dianne Hackborn | 3d07c94 | 2015-03-13 18:02:54 -0700 | [diff] [blame] | 2422 | mStackSupervisor.setLaunchSource(next.info.applicationInfo.uid); |
| 2423 | |
Wale Ogunwale | 8997322 | 2017-04-23 18:39:45 -0700 | [diff] [blame] | 2424 | boolean lastResumedCanPip = false; |
chaviw | 4ad5491 | 2018-05-30 11:05:44 -0700 | [diff] [blame] | 2425 | ActivityRecord lastResumed = null; |
Wale Ogunwale | 8997322 | 2017-04-23 18:39:45 -0700 | [diff] [blame] | 2426 | final ActivityStack lastFocusedStack = mStackSupervisor.getLastStack(); |
| 2427 | if (lastFocusedStack != null && lastFocusedStack != this) { |
| 2428 | // So, why aren't we using prev here??? See the param comment on the method. prev doesn't |
| 2429 | // 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] | 2430 | lastResumed = lastFocusedStack.mResumedActivity; |
Wale Ogunwale | c59b4f6 | 2017-11-30 11:05:43 -0800 | [diff] [blame] | 2431 | if (userLeaving && inMultiWindowMode() && lastFocusedStack.shouldBeVisible(next)) { |
| 2432 | // The user isn't leaving if this stack is the multi-window mode and the last |
| 2433 | // focused stack should still be visible. |
| 2434 | if(DEBUG_USER_LEAVING) Slog.i(TAG_USER_LEAVING, "Overriding userLeaving to false" |
| 2435 | + " next=" + next + " lastResumed=" + lastResumed); |
| 2436 | userLeaving = false; |
| 2437 | } |
Wale Ogunwale | 8997322 | 2017-04-23 18:39:45 -0700 | [diff] [blame] | 2438 | lastResumedCanPip = lastResumed != null && lastResumed.checkEnterPictureInPictureState( |
Winson Chung | 298f95b | 2017-08-10 15:57:18 -0700 | [diff] [blame] | 2439 | "resumeTopActivity", userLeaving /* beforeStopping */); |
Wale Ogunwale | 8997322 | 2017-04-23 18:39:45 -0700 | [diff] [blame] | 2440 | } |
Winson Chung | c2baac0 | 2017-01-11 13:34:47 -0800 | [diff] [blame] | 2441 | // 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] | 2442 | // to be paused, while at the same time resuming the new resume activity only if the |
| 2443 | // previous activity can't go into Pip since we want to give Pip activities a chance to |
| 2444 | // enter Pip before resuming the next activity. |
Wale Ogunwale | 8997322 | 2017-04-23 18:39:45 -0700 | [diff] [blame] | 2445 | final boolean resumeWhilePausing = (next.info.flags & FLAG_RESUME_WHILE_PAUSING) != 0 |
| 2446 | && !lastResumedCanPip; |
| 2447 | |
Winson Chung | c2baac0 | 2017-01-11 13:34:47 -0800 | [diff] [blame] | 2448 | boolean pausing = mStackSupervisor.pauseBackStacks(userLeaving, next, false); |
Craig Mautner | eb95786 | 2013-04-24 15:34:32 -0700 | [diff] [blame] | 2449 | if (mResumedActivity != null) { |
Wale Ogunwale | 0fc365c | 2015-05-25 19:35:42 -0700 | [diff] [blame] | 2450 | if (DEBUG_STATES) Slog.d(TAG_STATES, |
| 2451 | "resumeTopActivityLocked: Pausing " + mResumedActivity); |
Winson Chung | c2baac0 | 2017-01-11 13:34:47 -0800 | [diff] [blame] | 2452 | pausing |= startPausingLocked(userLeaving, false, next, false); |
Craig Mautner | eb95786 | 2013-04-24 15:34:32 -0700 | [diff] [blame] | 2453 | } |
Winson Chung | c2baac0 | 2017-01-11 13:34:47 -0800 | [diff] [blame] | 2454 | if (pausing && !resumeWhilePausing) { |
Wale Ogunwale | 0fc365c | 2015-05-25 19:35:42 -0700 | [diff] [blame] | 2455 | if (DEBUG_SWITCH || DEBUG_STATES) Slog.v(TAG_STATES, |
Craig Mautner | ac6f843 | 2013-07-17 13:24:59 -0700 | [diff] [blame] | 2456 | "resumeTopActivityLocked: Skip resume: need to start pausing"); |
Dianne Hackborn | ad9b3211 | 2012-09-17 15:35:01 -0700 | [diff] [blame] | 2457 | // At this point we want to put the upcoming activity's process |
| 2458 | // at the top of the LRU list, since we know we will be needing it |
| 2459 | // very soon and it would be a waste to let it get killed if it |
| 2460 | // happens to be sitting towards the end. |
| 2461 | if (next.app != null && next.app.thread != null) { |
Dianne Hackborn | db92608 | 2013-10-31 16:32:44 -0700 | [diff] [blame] | 2462 | mService.updateLruProcessLocked(next.app, true, null); |
Dianne Hackborn | ad9b3211 | 2012-09-17 15:35:01 -0700 | [diff] [blame] | 2463 | } |
Craig Mautner | cf910b0 | 2013-04-23 11:23:27 -0700 | [diff] [blame] | 2464 | if (DEBUG_STACK) mStackSupervisor.validateTopActivitiesLocked(); |
chaviw | 4ad5491 | 2018-05-30 11:05:44 -0700 | [diff] [blame] | 2465 | if (lastResumed != null) { |
| 2466 | lastResumed.setWillCloseOrEnterPip(true); |
| 2467 | } |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 2468 | return true; |
Bryce Lee | 7ace395 | 2018-02-16 14:34:32 -0800 | [diff] [blame] | 2469 | } else if (mResumedActivity == next && next.isState(RESUMED) |
| 2470 | && mStackSupervisor.allResumedActivitiesComplete()) { |
Wale Ogunwale | cac5c32 | 2016-05-23 10:56:33 -0700 | [diff] [blame] | 2471 | // It is possible for the activity to be resumed when we paused back stacks above if the |
| 2472 | // next activity doesn't have to wait for pause to complete. |
| 2473 | // So, nothing else to-do except: |
| 2474 | // Make sure we have executed any pending transitions, since there |
| 2475 | // should be nothing left to do at this point. |
skuhne@google.com | 1b974dc | 2016-12-09 13:41:29 -0800 | [diff] [blame] | 2476 | executeAppTransition(options); |
Wale Ogunwale | cac5c32 | 2016-05-23 10:56:33 -0700 | [diff] [blame] | 2477 | if (DEBUG_STATES) Slog.d(TAG_STATES, |
| 2478 | "resumeTopActivityLocked: Top activity resumed (dontWaitForPause) " + next); |
| 2479 | if (DEBUG_STACK) mStackSupervisor.validateTopActivitiesLocked(); |
| 2480 | return true; |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 2481 | } |
| 2482 | |
Christopher Tate | d3f175c | 2012-06-14 14:16:54 -0700 | [diff] [blame] | 2483 | // If the most recent activity was noHistory but was only stopped rather |
| 2484 | // than stopped+finished because the device went to sleep, we need to make |
| 2485 | // sure to finish it as we're making a new activity topmost. |
David Stevens | 9440dc8 | 2017-03-16 19:00:20 -0700 | [diff] [blame] | 2486 | if (shouldSleepActivities() && mLastNoHistoryActivity != null && |
Craig Mautner | 0f92274 | 2013-08-06 08:44:42 -0700 | [diff] [blame] | 2487 | !mLastNoHistoryActivity.finishing) { |
Wale Ogunwale | 0fc365c | 2015-05-25 19:35:42 -0700 | [diff] [blame] | 2488 | if (DEBUG_STATES) Slog.d(TAG_STATES, |
| 2489 | "no-history finish of " + mLastNoHistoryActivity + " on new resume"); |
Craig Mautner | 0f92274 | 2013-08-06 08:44:42 -0700 | [diff] [blame] | 2490 | requestFinishActivityLocked(mLastNoHistoryActivity.appToken, Activity.RESULT_CANCELED, |
Todd Kennedy | 539db51 | 2014-12-15 09:57:55 -0800 | [diff] [blame] | 2491 | null, "resume-no-history", false); |
Craig Mautner | 0f92274 | 2013-08-06 08:44:42 -0700 | [diff] [blame] | 2492 | mLastNoHistoryActivity = null; |
Christopher Tate | d3f175c | 2012-06-14 14:16:54 -0700 | [diff] [blame] | 2493 | } |
| 2494 | |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 2495 | if (prev != null && prev != next) { |
Bryce Lee | 4a19438 | 2017-04-04 14:32:48 -0700 | [diff] [blame] | 2496 | if (!mStackSupervisor.mActivitiesWaitingForVisibleActivity.contains(prev) |
Craig Mautner | 8c14c15 | 2015-01-15 17:32:07 -0800 | [diff] [blame] | 2497 | && next != null && !next.nowVisible) { |
Bryce Lee | 4a19438 | 2017-04-04 14:32:48 -0700 | [diff] [blame] | 2498 | mStackSupervisor.mActivitiesWaitingForVisibleActivity.add(prev); |
Wale Ogunwale | ee006da | 2015-03-30 14:49:25 -0700 | [diff] [blame] | 2499 | if (DEBUG_SWITCH) Slog.v(TAG_SWITCH, |
| 2500 | "Resuming top, waiting visible to hide: " + prev); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 2501 | } else { |
| 2502 | // The next activity is already visible, so hide the previous |
| 2503 | // activity's windows right now so we can show the new one ASAP. |
| 2504 | // We only do this if the previous is finishing, which should mean |
| 2505 | // it is on top of the one being resumed so hiding it quickly |
| 2506 | // is good. Otherwise, we want to do the normal route of allowing |
| 2507 | // the resumed activity to be shown so we can decide if the |
| 2508 | // previous should actually be hidden depending on whether the |
| 2509 | // new one is found to be full-screen or not. |
| 2510 | if (prev.finishing) { |
Wale Ogunwale | 26c0dfe | 2016-12-14 14:42:30 -0800 | [diff] [blame] | 2511 | prev.setVisibility(false); |
Wale Ogunwale | ee006da | 2015-03-30 14:49:25 -0700 | [diff] [blame] | 2512 | if (DEBUG_SWITCH) Slog.v(TAG_SWITCH, |
| 2513 | "Not waiting for visible to hide: " + prev + ", waitingVisible=" |
Bryce Lee | 4a19438 | 2017-04-04 14:32:48 -0700 | [diff] [blame] | 2514 | + mStackSupervisor.mActivitiesWaitingForVisibleActivity.contains(prev) |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 2515 | + ", nowVisible=" + next.nowVisible); |
| 2516 | } else { |
Wale Ogunwale | ee006da | 2015-03-30 14:49:25 -0700 | [diff] [blame] | 2517 | if (DEBUG_SWITCH) Slog.v(TAG_SWITCH, |
Craig Mautner | 8c14c15 | 2015-01-15 17:32:07 -0800 | [diff] [blame] | 2518 | "Previous already visible but still waiting to hide: " + prev |
Wale Ogunwale | ee006da | 2015-03-30 14:49:25 -0700 | [diff] [blame] | 2519 | + ", waitingVisible=" |
Bryce Lee | 4a19438 | 2017-04-04 14:32:48 -0700 | [diff] [blame] | 2520 | + mStackSupervisor.mActivitiesWaitingForVisibleActivity.contains(prev) |
Wale Ogunwale | ee006da | 2015-03-30 14:49:25 -0700 | [diff] [blame] | 2521 | + ", nowVisible=" + next.nowVisible); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 2522 | } |
| 2523 | } |
| 2524 | } |
| 2525 | |
Dianne Hackborn | e7f9721 | 2011-02-24 14:40:20 -0800 | [diff] [blame] | 2526 | // Launching this app's activity, make sure the app is no longer |
| 2527 | // considered stopped. |
| 2528 | try { |
| 2529 | AppGlobals.getPackageManager().setPackageStoppedState( |
Amith Yamasani | 483f3b0 | 2012-03-13 16:08:00 -0700 | [diff] [blame] | 2530 | next.packageName, false, next.userId); /* TODO: Verify if correct userid */ |
Dianne Hackborn | e7f9721 | 2011-02-24 14:40:20 -0800 | [diff] [blame] | 2531 | } catch (RemoteException e1) { |
Dianne Hackborn | a925cd4 | 2011-03-10 13:18:20 -0800 | [diff] [blame] | 2532 | } catch (IllegalArgumentException e) { |
| 2533 | Slog.w(TAG, "Failed trying to unstop package " |
| 2534 | + next.packageName + ": " + e); |
Dianne Hackborn | e7f9721 | 2011-02-24 14:40:20 -0800 | [diff] [blame] | 2535 | } |
| 2536 | |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 2537 | // We are starting up the next activity, so tell the window manager |
| 2538 | // that the previous one will be hidden soon. This way it can know |
| 2539 | // to ignore it when computing the desired screen orientation. |
Craig Mautner | 525f3d9 | 2013-05-07 14:01:50 -0700 | [diff] [blame] | 2540 | boolean anim = true; |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 2541 | if (prev != null) { |
| 2542 | if (prev.finishing) { |
Wale Ogunwale | ee006da | 2015-03-30 14:49:25 -0700 | [diff] [blame] | 2543 | if (DEBUG_TRANSITION) Slog.v(TAG_TRANSITION, |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 2544 | "Prepare close transition: prev=" + prev); |
Jorim Jaggi | fa9ed96 | 2018-01-25 00:16:49 +0100 | [diff] [blame] | 2545 | if (mStackSupervisor.mNoAnimActivities.contains(prev)) { |
Craig Mautner | 525f3d9 | 2013-05-07 14:01:50 -0700 | [diff] [blame] | 2546 | anim = false; |
Jorim Jaggi | af80db4 | 2016-04-07 19:19:15 -0700 | [diff] [blame] | 2547 | mWindowManager.prepareAppTransition(TRANSIT_NONE, false); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 2548 | } else { |
Bryce Lee | af691c0 | 2017-03-20 14:20:22 -0700 | [diff] [blame] | 2549 | mWindowManager.prepareAppTransition(prev.getTask() == next.getTask() |
Jorim Jaggi | af80db4 | 2016-04-07 19:19:15 -0700 | [diff] [blame] | 2550 | ? TRANSIT_ACTIVITY_CLOSE |
| 2551 | : TRANSIT_TASK_CLOSE, false); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 2552 | } |
Wale Ogunwale | 26c0dfe | 2016-12-14 14:42:30 -0800 | [diff] [blame] | 2553 | prev.setVisibility(false); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 2554 | } else { |
Wale Ogunwale | ee006da | 2015-03-30 14:49:25 -0700 | [diff] [blame] | 2555 | if (DEBUG_TRANSITION) Slog.v(TAG_TRANSITION, |
| 2556 | "Prepare open transition: prev=" + prev); |
Jorim Jaggi | fa9ed96 | 2018-01-25 00:16:49 +0100 | [diff] [blame] | 2557 | if (mStackSupervisor.mNoAnimActivities.contains(next)) { |
Craig Mautner | 525f3d9 | 2013-05-07 14:01:50 -0700 | [diff] [blame] | 2558 | anim = false; |
Jorim Jaggi | af80db4 | 2016-04-07 19:19:15 -0700 | [diff] [blame] | 2559 | mWindowManager.prepareAppTransition(TRANSIT_NONE, false); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 2560 | } else { |
Bryce Lee | af691c0 | 2017-03-20 14:20:22 -0700 | [diff] [blame] | 2561 | mWindowManager.prepareAppTransition(prev.getTask() == next.getTask() |
Jorim Jaggi | af80db4 | 2016-04-07 19:19:15 -0700 | [diff] [blame] | 2562 | ? TRANSIT_ACTIVITY_OPEN |
Craig Mautner | bb74246 | 2014-07-07 15:28:55 -0700 | [diff] [blame] | 2563 | : next.mLaunchTaskBehind |
Jorim Jaggi | af80db4 | 2016-04-07 19:19:15 -0700 | [diff] [blame] | 2564 | ? TRANSIT_TASK_OPEN_BEHIND |
| 2565 | : TRANSIT_TASK_OPEN, false); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 2566 | } |
| 2567 | } |
Craig Mautner | 967212c | 2013-04-13 21:10:58 -0700 | [diff] [blame] | 2568 | } else { |
Wale Ogunwale | ee006da | 2015-03-30 14:49:25 -0700 | [diff] [blame] | 2569 | if (DEBUG_TRANSITION) Slog.v(TAG_TRANSITION, "Prepare open transition: no previous"); |
Jorim Jaggi | fa9ed96 | 2018-01-25 00:16:49 +0100 | [diff] [blame] | 2570 | if (mStackSupervisor.mNoAnimActivities.contains(next)) { |
Craig Mautner | 525f3d9 | 2013-05-07 14:01:50 -0700 | [diff] [blame] | 2571 | anim = false; |
Jorim Jaggi | af80db4 | 2016-04-07 19:19:15 -0700 | [diff] [blame] | 2572 | mWindowManager.prepareAppTransition(TRANSIT_NONE, false); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 2573 | } else { |
Jorim Jaggi | af80db4 | 2016-04-07 19:19:15 -0700 | [diff] [blame] | 2574 | mWindowManager.prepareAppTransition(TRANSIT_ACTIVITY_OPEN, false); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 2575 | } |
| 2576 | } |
Adam Powell | cfbe9be | 2013-11-06 14:58:58 -0800 | [diff] [blame] | 2577 | |
Craig Mautner | 525f3d9 | 2013-05-07 14:01:50 -0700 | [diff] [blame] | 2578 | if (anim) { |
Dianne Hackborn | 7a2195c | 2012-03-19 17:38:00 -0700 | [diff] [blame] | 2579 | next.applyOptionsLocked(); |
| 2580 | } else { |
| 2581 | next.clearOptionsLocked(); |
| 2582 | } |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 2583 | |
Jorim Jaggi | fa9ed96 | 2018-01-25 00:16:49 +0100 | [diff] [blame] | 2584 | mStackSupervisor.mNoAnimActivities.clear(); |
| 2585 | |
Craig Mautner | cf910b0 | 2013-04-23 11:23:27 -0700 | [diff] [blame] | 2586 | ActivityStack lastStack = mStackSupervisor.getLastStack(); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 2587 | if (next.app != null && next.app.thread != null) { |
Chong Zhang | dea4bd9 | 2016-03-15 12:50:03 -0700 | [diff] [blame] | 2588 | if (DEBUG_SWITCH) Slog.v(TAG_SWITCH, "Resume running: " + next |
| 2589 | + " stopped=" + next.stopped + " visible=" + next.visible); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 2590 | |
Chong Zhang | d127c6d | 2016-05-02 16:36:41 -0700 | [diff] [blame] | 2591 | // If the previous activity is translucent, force a visibility update of |
| 2592 | // the next activity, so that it's added to WM's opening app list, and |
| 2593 | // transition animation can be set up properly. |
| 2594 | // For example, pressing Home button with a translucent activity in focus. |
| 2595 | // Launcher is already visible in this case. If we don't add it to opening |
| 2596 | // apps, maybeUpdateTransitToWallpaper() will fail to identify this as a |
| 2597 | // TRANSIT_WALLPAPER_OPEN animation, and run some funny animation. |
| 2598 | final boolean lastActivityTranslucent = lastStack != null |
Bryce Lee | f3c6a47 | 2017-11-14 14:53:06 -0800 | [diff] [blame] | 2599 | && (lastStack.inMultiWindowMode() |
Chong Zhang | d127c6d | 2016-05-02 16:36:41 -0700 | [diff] [blame] | 2600 | || (lastStack.mLastPausedActivity != null |
| 2601 | && !lastStack.mLastPausedActivity.fullscreen)); |
| 2602 | |
Bryce Lee | 69ad818 | 2017-09-28 10:01:36 -0700 | [diff] [blame] | 2603 | // The contained logic must be synchronized, since we are both changing the visibility |
| 2604 | // and updating the {@link Configuration}. {@link ActivityRecord#setVisibility} will |
| 2605 | // ultimately cause the client code to schedule a layout. Since layouts retrieve the |
| 2606 | // current {@link Configuration}, we must ensure that the below code updates it before |
| 2607 | // the layout can occur. |
| 2608 | synchronized(mWindowManager.getWindowManagerLock()) { |
| 2609 | // This activity is now becoming visible. |
| 2610 | if (!next.visible || next.stopped || lastActivityTranslucent) { |
Wale Ogunwale | 26c0dfe | 2016-12-14 14:42:30 -0800 | [diff] [blame] | 2611 | next.setVisibility(true); |
Craig Mautner | de4ef02 | 2013-04-07 19:01:33 -0700 | [diff] [blame] | 2612 | } |
Craig Mautner | 5854780 | 2013-03-05 08:23:53 -0800 | [diff] [blame] | 2613 | |
Bryce Lee | 69ad818 | 2017-09-28 10:01:36 -0700 | [diff] [blame] | 2614 | // schedule launch ticks to collect information about slow apps. |
| 2615 | next.startLaunchTickingLocked(); |
| 2616 | |
| 2617 | ActivityRecord lastResumedActivity = |
| 2618 | lastStack == null ? null :lastStack.mResumedActivity; |
Bryce Lee | 7ace395 | 2018-02-16 14:34:32 -0800 | [diff] [blame] | 2619 | final ActivityState lastState = next.getState(); |
Bryce Lee | 69ad818 | 2017-09-28 10:01:36 -0700 | [diff] [blame] | 2620 | |
| 2621 | mService.updateCpuStats(); |
| 2622 | |
| 2623 | if (DEBUG_STATES) Slog.v(TAG_STATES, "Moving to RESUMED: " + next |
| 2624 | + " (in existing)"); |
| 2625 | |
Bryce Lee | c4ab62a | 2018-03-05 14:19:26 -0800 | [diff] [blame] | 2626 | next.setState(RESUMED, "resumeTopActivityInnerLocked"); |
Bryce Lee | 69ad818 | 2017-09-28 10:01:36 -0700 | [diff] [blame] | 2627 | |
| 2628 | mService.updateLruProcessLocked(next.app, true, null); |
| 2629 | updateLRUListLocked(next); |
| 2630 | mService.updateOomAdjLocked(); |
| 2631 | |
| 2632 | // Have the window manager re-evaluate the orientation of |
| 2633 | // the screen based on the new activity order. |
| 2634 | boolean notUpdated = true; |
| 2635 | |
| 2636 | if (mStackSupervisor.isFocusedStack(this)) { |
Andrii Kulian | f4479ee | 2018-05-23 17:52:48 -0700 | [diff] [blame] | 2637 | // We have special rotation behavior when here is some active activity that |
| 2638 | // requests specific orientation or Keyguard is locked. Make sure all activity |
| 2639 | // visibilities are set correctly as well as the transition is updated if needed |
| 2640 | // to get the correct rotation behavior. Otherwise the following call to update |
| 2641 | // the orientation may cause incorrect configurations delivered to client as a |
| 2642 | // result of invisible window resize. |
Bryce Lee | 69ad818 | 2017-09-28 10:01:36 -0700 | [diff] [blame] | 2643 | // TODO: Remove this once visibilities are set correctly immediately when |
| 2644 | // starting an activity. |
Andrii Kulian | f4479ee | 2018-05-23 17:52:48 -0700 | [diff] [blame] | 2645 | notUpdated = !mStackSupervisor.ensureVisibilityAndConfig(next, mDisplayId, |
| 2646 | true /* markFrozenIfConfigChanged */, false /* deferResume */); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 2647 | } |
| 2648 | |
Bryce Lee | 69ad818 | 2017-09-28 10:01:36 -0700 | [diff] [blame] | 2649 | if (notUpdated) { |
| 2650 | // The configuration update wasn't able to keep the existing |
| 2651 | // instance of the activity, and instead started a new one. |
| 2652 | // We should be all done, but let's just make sure our activity |
| 2653 | // is still at the top and schedule another run if something |
| 2654 | // weird happened. |
| 2655 | ActivityRecord nextNext = topRunningActivityLocked(); |
| 2656 | if (DEBUG_SWITCH || DEBUG_STATES) Slog.i(TAG_STATES, |
| 2657 | "Activity config changed during resume: " + next |
| 2658 | + ", new next: " + nextNext); |
| 2659 | if (nextNext != next) { |
| 2660 | // Do over! |
| 2661 | mStackSupervisor.scheduleResumeTopActivities(); |
| 2662 | } |
| 2663 | if (!next.visible || next.stopped) { |
| 2664 | next.setVisibility(true); |
| 2665 | } |
| 2666 | next.completeResumeLocked(); |
| 2667 | if (DEBUG_STACK) mStackSupervisor.validateTopActivitiesLocked(); |
| 2668 | return true; |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 2669 | } |
| 2670 | |
Bryce Lee | 69ad818 | 2017-09-28 10:01:36 -0700 | [diff] [blame] | 2671 | try { |
Andrii Kulian | 9956d89 | 2018-02-14 13:48:56 -0800 | [diff] [blame] | 2672 | final ClientTransaction transaction = ClientTransaction.obtain(next.app.thread, |
| 2673 | next.appToken); |
Bryce Lee | 69ad818 | 2017-09-28 10:01:36 -0700 | [diff] [blame] | 2674 | // Deliver all pending results. |
| 2675 | ArrayList<ResultInfo> a = next.results; |
| 2676 | if (a != null) { |
| 2677 | final int N = a.size(); |
| 2678 | if (!next.finishing && N > 0) { |
| 2679 | if (DEBUG_RESULTS) Slog.v(TAG_RESULTS, |
| 2680 | "Delivering results to " + next + ": " + a); |
Andrii Kulian | 9956d89 | 2018-02-14 13:48:56 -0800 | [diff] [blame] | 2681 | transaction.addCallback(ActivityResultItem.obtain(a)); |
Bryce Lee | 69ad818 | 2017-09-28 10:01:36 -0700 | [diff] [blame] | 2682 | } |
| 2683 | } |
Wale Ogunwale | 8d5a542 | 2016-03-03 18:28:21 -0800 | [diff] [blame] | 2684 | |
Bryce Lee | 69ad818 | 2017-09-28 10:01:36 -0700 | [diff] [blame] | 2685 | if (next.newIntents != null) { |
Andrii Kulian | 9956d89 | 2018-02-14 13:48:56 -0800 | [diff] [blame] | 2686 | transaction.addCallback(NewIntentItem.obtain(next.newIntents, |
| 2687 | false /* andPause */)); |
Bryce Lee | 69ad818 | 2017-09-28 10:01:36 -0700 | [diff] [blame] | 2688 | } |
Craig Mautner | 5854780 | 2013-03-05 08:23:53 -0800 | [diff] [blame] | 2689 | |
Bryce Lee | 69ad818 | 2017-09-28 10:01:36 -0700 | [diff] [blame] | 2690 | // Well the app will no longer be stopped. |
| 2691 | // Clear app token stopped state in window manager if needed. |
| 2692 | next.notifyAppResumed(next.stopped); |
Craig Mautner | 5854780 | 2013-03-05 08:23:53 -0800 | [diff] [blame] | 2693 | |
Bryce Lee | 69ad818 | 2017-09-28 10:01:36 -0700 | [diff] [blame] | 2694 | EventLog.writeEvent(EventLogTags.AM_RESUME_ACTIVITY, next.userId, |
| 2695 | System.identityHashCode(next), next.getTask().taskId, |
| 2696 | next.shortComponentName); |
| 2697 | |
| 2698 | next.sleeping = false; |
Alan Viverette | b6a2573 | 2017-11-21 14:49:24 -0500 | [diff] [blame] | 2699 | mService.getAppWarningsLocked().onResumeActivity(next); |
Bryce Lee | 69ad818 | 2017-09-28 10:01:36 -0700 | [diff] [blame] | 2700 | mService.showAskCompatModeDialogLocked(next); |
| 2701 | next.app.pendingUiClean = true; |
| 2702 | next.app.forceProcessStateUpTo(mService.mTopProcessState); |
| 2703 | next.clearOptionsLocked(); |
Andrii Kulian | 9956d89 | 2018-02-14 13:48:56 -0800 | [diff] [blame] | 2704 | transaction.setLifecycleStateRequest( |
Andrii Kulian | 9c5ea9c | 2017-12-07 09:31:01 -0800 | [diff] [blame] | 2705 | ResumeActivityItem.obtain(next.app.repProcState, |
Bryce Lee | 1d0d514 | 2018-04-12 10:35:07 -0700 | [diff] [blame] | 2706 | mService.isNextTransitionForward())); |
Bryce Lee | b0f993f | 2018-03-02 15:38:01 -0800 | [diff] [blame] | 2707 | mService.getLifecycleManager().scheduleTransaction(transaction); |
Bryce Lee | 69ad818 | 2017-09-28 10:01:36 -0700 | [diff] [blame] | 2708 | |
| 2709 | if (DEBUG_STATES) Slog.d(TAG_STATES, "resumeTopActivityLocked: Resumed " |
| 2710 | + next); |
| 2711 | } catch (Exception e) { |
| 2712 | // Whoops, need to restart this activity! |
| 2713 | if (DEBUG_STATES) Slog.v(TAG_STATES, "Resume failed; resetting state to " |
| 2714 | + lastState + ": " + next); |
Bryce Lee | 7ace395 | 2018-02-16 14:34:32 -0800 | [diff] [blame] | 2715 | next.setState(lastState, "resumeTopActivityInnerLocked"); |
Bryce Lee | 4c40138 | 2018-03-13 19:23:03 -0700 | [diff] [blame] | 2716 | |
| 2717 | // lastResumedActivity being non-null implies there is a lastStack present. |
| 2718 | if (lastResumedActivity != null) { |
Bryce Lee | c4ab62a | 2018-03-05 14:19:26 -0800 | [diff] [blame] | 2719 | lastResumedActivity.setState(RESUMED, "resumeTopActivityInnerLocked"); |
Bryce Lee | 69ad818 | 2017-09-28 10:01:36 -0700 | [diff] [blame] | 2720 | } |
Bryce Lee | 4c40138 | 2018-03-13 19:23:03 -0700 | [diff] [blame] | 2721 | |
Bryce Lee | 69ad818 | 2017-09-28 10:01:36 -0700 | [diff] [blame] | 2722 | Slog.i(TAG, "Restarting because process died: " + next); |
| 2723 | if (!next.hasBeenLaunched) { |
| 2724 | next.hasBeenLaunched = true; |
Wale Ogunwale | a0f5b5e | 2017-10-11 09:37:23 -0700 | [diff] [blame] | 2725 | } else if (SHOW_APP_STARTING_PREVIEW && lastStack != null |
| 2726 | && lastStack.isTopStackOnDisplay()) { |
Bryce Lee | 69ad818 | 2017-09-28 10:01:36 -0700 | [diff] [blame] | 2727 | next.showStartingWindow(null /* prev */, false /* newTask */, |
| 2728 | false /* taskSwitch */); |
| 2729 | } |
| 2730 | mStackSupervisor.startSpecificActivityLocked(next, true, false); |
| 2731 | if (DEBUG_STACK) mStackSupervisor.validateTopActivitiesLocked(); |
| 2732 | return true; |
Craig Mautner | f88c50f | 2013-04-18 19:25:12 -0700 | [diff] [blame] | 2733 | } |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 2734 | } |
| 2735 | |
| 2736 | // From this point on, if something goes wrong there is no way |
| 2737 | // to recover the activity. |
| 2738 | try { |
Andrii Kulian | 21713ac | 2016-10-12 22:05:05 -0700 | [diff] [blame] | 2739 | next.completeResumeLocked(); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 2740 | } catch (Exception e) { |
| 2741 | // If any exception gets thrown, toss away this |
| 2742 | // activity and try the next one. |
| 2743 | Slog.w(TAG, "Exception thrown during resume of " + next, e); |
Dianne Hackborn | be70785 | 2011-11-11 14:32:10 -0800 | [diff] [blame] | 2744 | requestFinishActivityLocked(next.appToken, Activity.RESULT_CANCELED, null, |
Dianne Hackborn | 2d1b378 | 2012-09-09 17:49:39 -0700 | [diff] [blame] | 2745 | "resume-exception", true); |
Craig Mautner | cf910b0 | 2013-04-23 11:23:27 -0700 | [diff] [blame] | 2746 | if (DEBUG_STACK) mStackSupervisor.validateTopActivitiesLocked(); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 2747 | return true; |
| 2748 | } |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 2749 | } else { |
| 2750 | // Whoops, need to restart this activity! |
| 2751 | if (!next.hasBeenLaunched) { |
| 2752 | next.hasBeenLaunched = true; |
| 2753 | } else { |
| 2754 | if (SHOW_APP_STARTING_PREVIEW) { |
Jorim Jaggi | 02886a8 | 2016-12-06 09:10:06 -0800 | [diff] [blame] | 2755 | next.showStartingWindow(null /* prev */, false /* newTask */, |
| 2756 | false /* taskSwich */); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 2757 | } |
Wale Ogunwale | ee006da | 2015-03-30 14:49:25 -0700 | [diff] [blame] | 2758 | if (DEBUG_SWITCH) Slog.v(TAG_SWITCH, "Restarting: " + next); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 2759 | } |
Wale Ogunwale | 0fc365c | 2015-05-25 19:35:42 -0700 | [diff] [blame] | 2760 | if (DEBUG_STATES) Slog.d(TAG_STATES, "resumeTopActivityLocked: Restarting " + next); |
George Mount | 2c92c97 | 2014-03-20 09:38:23 -0700 | [diff] [blame] | 2761 | mStackSupervisor.startSpecificActivityLocked(next, true, true); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 2762 | } |
| 2763 | |
Craig Mautner | cf910b0 | 2013-04-23 11:23:27 -0700 | [diff] [blame] | 2764 | if (DEBUG_STACK) mStackSupervisor.validateTopActivitiesLocked(); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 2765 | return true; |
| 2766 | } |
| 2767 | |
Andrii Kulian | 7fc2281 | 2016-12-28 13:04:11 -0800 | [diff] [blame] | 2768 | private boolean resumeTopActivityInNextFocusableStack(ActivityRecord prev, |
| 2769 | ActivityOptions options, String reason) { |
Wale Ogunwale | 66e1685 | 2017-10-19 13:35:52 -0700 | [diff] [blame] | 2770 | if (adjustFocusToNextFocusableStack(reason)) { |
Andrii Kulian | 7fc2281 | 2016-12-28 13:04:11 -0800 | [diff] [blame] | 2771 | // Try to move focus to the next visible stack with a running activity if this |
| 2772 | // stack is not covering the entire screen or is on a secondary display (with no home |
| 2773 | // stack). |
| 2774 | return mStackSupervisor.resumeFocusedStackTopActivityLocked( |
| 2775 | mStackSupervisor.getFocusedStack(), prev, null); |
| 2776 | } |
| 2777 | |
| 2778 | // Let's just start up the Launcher... |
| 2779 | ActivityOptions.abort(options); |
| 2780 | if (DEBUG_STATES) Slog.d(TAG_STATES, |
| 2781 | "resumeTopActivityInNextFocusableStack: " + reason + ", go home"); |
| 2782 | if (DEBUG_STACK) mStackSupervisor.validateTopActivitiesLocked(); |
| 2783 | // Only resume home if on home display |
| 2784 | return isOnHomeDisplay() && |
| 2785 | mStackSupervisor.resumeHomeStackTask(prev, reason); |
| 2786 | } |
| 2787 | |
riddle_hsu | c215a4f | 2014-12-27 12:10:45 +0800 | [diff] [blame] | 2788 | private TaskRecord getNextTask(TaskRecord targetTask) { |
| 2789 | final int index = mTaskHistory.indexOf(targetTask); |
| 2790 | if (index >= 0) { |
| 2791 | final int numTasks = mTaskHistory.size(); |
| 2792 | for (int i = index + 1; i < numTasks; ++i) { |
| 2793 | TaskRecord task = mTaskHistory.get(i); |
| 2794 | if (task.userId == targetTask.userId) { |
| 2795 | return task; |
| 2796 | } |
| 2797 | } |
| 2798 | } |
| 2799 | return null; |
| 2800 | } |
| 2801 | |
Wale Ogunwale | c5cc301 | 2017-01-13 13:26:16 -0800 | [diff] [blame] | 2802 | /** Returns the position the input task should be placed in this stack. */ |
| 2803 | int getAdjustedPositionForTask(TaskRecord task, int suggestedPosition, |
| 2804 | ActivityRecord starting) { |
| 2805 | |
| 2806 | int maxPosition = mTaskHistory.size(); |
| 2807 | if ((starting != null && starting.okToShowLocked()) |
| 2808 | || (starting == null && task.okToShowLocked())) { |
| 2809 | // If the task or starting activity can be shown, then whatever position is okay. |
| 2810 | return Math.min(suggestedPosition, maxPosition); |
| 2811 | } |
| 2812 | |
| 2813 | // The task can't be shown, put non-current user tasks below current user tasks. |
| 2814 | while (maxPosition > 0) { |
| 2815 | final TaskRecord tmpTask = mTaskHistory.get(maxPosition - 1); |
| 2816 | if (!mStackSupervisor.isCurrentProfileLocked(tmpTask.userId) |
| 2817 | || tmpTask.topRunningActivityLocked() == null) { |
| 2818 | break; |
| 2819 | } |
| 2820 | maxPosition--; |
| 2821 | } |
| 2822 | |
| 2823 | return Math.min(suggestedPosition, maxPosition); |
| 2824 | } |
| 2825 | |
Andrii Kulian | d276563 | 2016-12-12 22:26:34 -0800 | [diff] [blame] | 2826 | /** |
| 2827 | * Used from {@link ActivityStack#positionTask(TaskRecord, int)}. |
| 2828 | * @see ActivityManagerService#positionTaskInStack(int, int, int). |
| 2829 | */ |
Wale Ogunwale | ddc1cb2 | 2015-07-25 19:23:04 -0700 | [diff] [blame] | 2830 | private void insertTaskAtPosition(TaskRecord task, int position) { |
| 2831 | if (position >= mTaskHistory.size()) { |
| 2832 | insertTaskAtTop(task, null); |
| 2833 | return; |
Evan Rosky | 9c44817 | 2017-11-02 14:19:27 -0700 | [diff] [blame] | 2834 | } else if (position <= 0) { |
| 2835 | insertTaskAtBottom(task); |
| 2836 | return; |
Wale Ogunwale | ddc1cb2 | 2015-07-25 19:23:04 -0700 | [diff] [blame] | 2837 | } |
Wale Ogunwale | c5cc301 | 2017-01-13 13:26:16 -0800 | [diff] [blame] | 2838 | position = getAdjustedPositionForTask(task, position, null /* starting */); |
Wale Ogunwale | ddc1cb2 | 2015-07-25 19:23:04 -0700 | [diff] [blame] | 2839 | mTaskHistory.remove(task); |
| 2840 | mTaskHistory.add(position, task); |
Bryce Lee | f3c6a47 | 2017-11-14 14:53:06 -0800 | [diff] [blame] | 2841 | mWindowContainerController.positionChildAt(task.getWindowContainerController(), position); |
Wale Ogunwale | ddc1cb2 | 2015-07-25 19:23:04 -0700 | [diff] [blame] | 2842 | updateTaskMovement(task, true); |
| 2843 | } |
| 2844 | |
Wale Ogunwale | c5cc301 | 2017-01-13 13:26:16 -0800 | [diff] [blame] | 2845 | private void insertTaskAtTop(TaskRecord task, ActivityRecord starting) { |
Wale Ogunwale | c5cc301 | 2017-01-13 13:26:16 -0800 | [diff] [blame] | 2846 | // TODO: Better place to put all the code below...may be addTask... |
| 2847 | mTaskHistory.remove(task); |
| 2848 | // Now put task at top. |
| 2849 | final int position = getAdjustedPositionForTask(task, mTaskHistory.size(), starting); |
| 2850 | mTaskHistory.add(position, task); |
| 2851 | updateTaskMovement(task, true); |
Wale Ogunwale | 1666e31 | 2016-12-16 11:27:18 -0800 | [diff] [blame] | 2852 | mWindowContainerController.positionChildAtTop(task.getWindowContainerController(), |
| 2853 | true /* includingParents */); |
Wale Ogunwale | e1fe7fa2 | 2016-12-15 18:27:00 -0800 | [diff] [blame] | 2854 | } |
| 2855 | |
Evan Rosky | 9c44817 | 2017-11-02 14:19:27 -0700 | [diff] [blame] | 2856 | private void insertTaskAtBottom(TaskRecord task) { |
| 2857 | // Unlike insertTaskAtPosition, this will also position parents of the windowcontroller. |
| 2858 | mTaskHistory.remove(task); |
| 2859 | final int position = getAdjustedPositionForTask(task, 0, null); |
| 2860 | mTaskHistory.add(position, task); |
| 2861 | updateTaskMovement(task, true); |
| 2862 | mWindowContainerController.positionChildAtBottom(task.getWindowContainerController(), |
| 2863 | true /* includingParents */); |
| 2864 | } |
| 2865 | |
Bryce Lee | ad5b832 | 2018-03-08 14:28:52 -0800 | [diff] [blame] | 2866 | void startActivityLocked(ActivityRecord r, ActivityRecord focusedTopActivity, |
Winson Chung | b5c41b7 | 2016-12-07 15:00:47 -0800 | [diff] [blame] | 2867 | boolean newTask, boolean keepCurTransition, ActivityOptions options) { |
Bryce Lee | af691c0 | 2017-03-20 14:20:22 -0700 | [diff] [blame] | 2868 | TaskRecord rTask = r.getTask(); |
Craig Mautner | d232895 | 2013-03-05 12:46:26 -0800 | [diff] [blame] | 2869 | final int taskId = rTask.taskId; |
Craig Mautner | bb74246 | 2014-07-07 15:28:55 -0700 | [diff] [blame] | 2870 | // mLaunchTaskBehind tasks get placed at the back of the task stack. |
| 2871 | if (!r.mLaunchTaskBehind && (taskForIdLocked(taskId) == null || newTask)) { |
Craig Mautner | 7787877 | 2013-03-04 19:46:24 -0800 | [diff] [blame] | 2872 | // Last activity in task had been removed or ActivityManagerService is reusing task. |
| 2873 | // Insert or replace. |
Craig Mautner | 7787877 | 2013-03-04 19:46:24 -0800 | [diff] [blame] | 2874 | // Might not even be in. |
Wale Ogunwale | 3fcb4a8 | 2015-04-06 14:00:13 -0700 | [diff] [blame] | 2875 | insertTaskAtTop(rTask, r); |
Craig Mautner | 7787877 | 2013-03-04 19:46:24 -0800 | [diff] [blame] | 2876 | } |
Craig Mautner | 525f3d9 | 2013-05-07 14:01:50 -0700 | [diff] [blame] | 2877 | TaskRecord task = null; |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 2878 | if (!newTask) { |
| 2879 | // If starting in an existing task, find where that is... |
Craig Mautner | 70a8693 | 2013-02-28 22:37:44 -0800 | [diff] [blame] | 2880 | boolean startIt = true; |
| 2881 | for (int taskNdx = mTaskHistory.size() - 1; taskNdx >= 0; --taskNdx) { |
| 2882 | task = mTaskHistory.get(taskNdx); |
riddle_hsu | 9bcc6e8 | 2014-07-31 00:26:51 +0800 | [diff] [blame] | 2883 | if (task.getTopActivity() == null) { |
| 2884 | // All activities in task are finishing. |
| 2885 | continue; |
| 2886 | } |
Bryce Lee | af691c0 | 2017-03-20 14:20:22 -0700 | [diff] [blame] | 2887 | if (task == rTask) { |
Craig Mautner | 70a8693 | 2013-02-28 22:37:44 -0800 | [diff] [blame] | 2888 | // Here it is! Now, if this is not yet visible to the |
| 2889 | // user, then just add it without starting; it will |
| 2890 | // get started when the user navigates back to it. |
Craig Mautner | 70a8693 | 2013-02-28 22:37:44 -0800 | [diff] [blame] | 2891 | if (!startIt) { |
| 2892 | if (DEBUG_ADD_REMOVE) Slog.i(TAG, "Adding activity " + r + " to task " |
| 2893 | + task, new RuntimeException("here").fillInStackTrace()); |
Wale Ogunwale | 26c0dfe | 2016-12-14 14:42:30 -0800 | [diff] [blame] | 2894 | r.createWindowContainer(); |
Dianne Hackborn | 8078d8c | 2012-03-20 11:11:26 -0700 | [diff] [blame] | 2895 | ActivityOptions.abort(options); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 2896 | return; |
| 2897 | } |
| 2898 | break; |
Craig Mautner | 70a8693 | 2013-02-28 22:37:44 -0800 | [diff] [blame] | 2899 | } else if (task.numFullscreen > 0) { |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 2900 | startIt = false; |
| 2901 | } |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 2902 | } |
| 2903 | } |
| 2904 | |
Wale Ogunwale | 26c0dfe | 2016-12-14 14:42:30 -0800 | [diff] [blame] | 2905 | // 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] | 2906 | |
Wale Ogunwale | 26c0dfe | 2016-12-14 14:42:30 -0800 | [diff] [blame] | 2907 | // If we are not placing the new activity frontmost, we do not want to deliver the |
| 2908 | // onUserLeaving callback to the actual frontmost activity |
Bryce Lee | af691c0 | 2017-03-20 14:20:22 -0700 | [diff] [blame] | 2909 | final TaskRecord activityTask = r.getTask(); |
| 2910 | if (task == activityTask && mTaskHistory.indexOf(task) != (mTaskHistory.size() - 1)) { |
Craig Mautner | de4ef02 | 2013-04-07 19:01:33 -0700 | [diff] [blame] | 2911 | mStackSupervisor.mUserLeaving = false; |
Wale Ogunwale | ee006da | 2015-03-30 14:49:25 -0700 | [diff] [blame] | 2912 | if (DEBUG_USER_LEAVING) Slog.v(TAG_USER_LEAVING, |
Craig Mautner | 70a8693 | 2013-02-28 22:37:44 -0800 | [diff] [blame] | 2913 | "startActivity() behind front, mUserLeaving=false"); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 2914 | } |
Craig Mautner | 70a8693 | 2013-02-28 22:37:44 -0800 | [diff] [blame] | 2915 | |
Bryce Lee | af691c0 | 2017-03-20 14:20:22 -0700 | [diff] [blame] | 2916 | task = activityTask; |
Craig Mautner | 70a8693 | 2013-02-28 22:37:44 -0800 | [diff] [blame] | 2917 | |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 2918 | // Slot the activity into the history stack and proceed |
Craig Mautner | 70a8693 | 2013-02-28 22:37:44 -0800 | [diff] [blame] | 2919 | 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] | 2920 | new RuntimeException("here").fillInStackTrace()); |
Wale Ogunwale | a0cd15e | 2017-02-01 15:33:08 -0800 | [diff] [blame] | 2921 | // TODO: Need to investigate if it is okay for the controller to already be created by the |
| 2922 | // time we get to this point. I think it is, but need to double check. |
| 2923 | // Use test in b/34179495 to trace the call path. |
| 2924 | if (r.getWindowContainerController() == null) { |
| 2925 | r.createWindowContainer(); |
| 2926 | } |
Craig Mautner | 1aa9d0d3f | 2013-12-16 15:58:31 -0800 | [diff] [blame] | 2927 | task.setFrontOfTask(); |
Craig Mautner | 70a8693 | 2013-02-28 22:37:44 -0800 | [diff] [blame] | 2928 | |
Matthew Ng | ae1ff4f | 2016-11-10 15:49:14 -0800 | [diff] [blame] | 2929 | if (!isHomeOrRecentsStack() || numActivities() > 0) { |
Wale Ogunwale | ee006da | 2015-03-30 14:49:25 -0700 | [diff] [blame] | 2930 | if (DEBUG_TRANSITION) Slog.v(TAG_TRANSITION, |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 2931 | "Prepare open transition: starting " + r); |
Wale Ogunwale | ee006da | 2015-03-30 14:49:25 -0700 | [diff] [blame] | 2932 | if ((r.intent.getFlags() & Intent.FLAG_ACTIVITY_NO_ANIMATION) != 0) { |
Jorim Jaggi | af80db4 | 2016-04-07 19:19:15 -0700 | [diff] [blame] | 2933 | mWindowManager.prepareAppTransition(TRANSIT_NONE, keepCurTransition); |
Jorim Jaggi | fa9ed96 | 2018-01-25 00:16:49 +0100 | [diff] [blame] | 2934 | mStackSupervisor.mNoAnimActivities.add(r); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 2935 | } else { |
Winson Chung | b5c41b7 | 2016-12-07 15:00:47 -0800 | [diff] [blame] | 2936 | int transit = TRANSIT_ACTIVITY_OPEN; |
| 2937 | if (newTask) { |
| 2938 | if (r.mLaunchTaskBehind) { |
| 2939 | transit = TRANSIT_TASK_OPEN_BEHIND; |
| 2940 | } else { |
Winson Chung | c2baac0 | 2017-01-11 13:34:47 -0800 | [diff] [blame] | 2941 | // 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] | 2942 | // supporting picture-in-picture while pausing only if the starting activity |
| 2943 | // would not be considered an overlay on top of the current activity |
| 2944 | // (eg. not fullscreen, or the assistant) |
Winson Chung | f7e03e1 | 2017-08-22 11:32:16 -0700 | [diff] [blame] | 2945 | if (canEnterPipOnTaskSwitch(focusedTopActivity, |
| 2946 | null /* toFrontTask */, r, options)) { |
| 2947 | focusedTopActivity.supportsEnterPipOnTaskSwitch = true; |
Winson Chung | b5c41b7 | 2016-12-07 15:00:47 -0800 | [diff] [blame] | 2948 | } |
| 2949 | transit = TRANSIT_TASK_OPEN; |
| 2950 | } |
| 2951 | } |
| 2952 | mWindowManager.prepareAppTransition(transit, keepCurTransition); |
Jorim Jaggi | fa9ed96 | 2018-01-25 00:16:49 +0100 | [diff] [blame] | 2953 | mStackSupervisor.mNoAnimActivities.remove(r); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 2954 | } |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 2955 | boolean doShow = true; |
| 2956 | if (newTask) { |
| 2957 | // Even though this activity is starting fresh, we still need |
| 2958 | // to reset it to make sure we apply affinities to move any |
| 2959 | // existing activities from other tasks in to it. |
| 2960 | // If the caller has requested that the target task be |
| 2961 | // reset, then do so. |
Craig Mautner | 9d4e9bc | 2014-06-18 18:34:56 -0700 | [diff] [blame] | 2962 | if ((r.intent.getFlags() & Intent.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED) != 0) { |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 2963 | resetTaskIfNeededLocked(r, r); |
| 2964 | doShow = topRunningNonDelayedActivityLocked(null) == r; |
| 2965 | } |
Chong Zhang | 280d332 | 2015-11-03 17:27:26 -0800 | [diff] [blame] | 2966 | } else if (options != null && options.getAnimationType() |
George Mount | 70778d7 | 2014-07-01 16:33:45 -0700 | [diff] [blame] | 2967 | == ActivityOptions.ANIM_SCENE_TRANSITION) { |
| 2968 | doShow = false; |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 2969 | } |
Craig Mautner | bb74246 | 2014-07-07 15:28:55 -0700 | [diff] [blame] | 2970 | if (r.mLaunchTaskBehind) { |
| 2971 | // Don't do a starting window for mLaunchTaskBehind. More importantly make sure we |
| 2972 | // 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] | 2973 | r.setVisibility(true); |
Filip Gruszczynski | bc5a6c5 | 2015-09-22 13:13:24 -0700 | [diff] [blame] | 2974 | ensureActivitiesVisibleLocked(null, 0, !PRESERVE_WINDOWS); |
Craig Mautner | bb74246 | 2014-07-07 15:28:55 -0700 | [diff] [blame] | 2975 | } else if (SHOW_APP_STARTING_PREVIEW && doShow) { |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 2976 | // Figure out if we are transitioning from another activity that is |
| 2977 | // "has the same starting icon" as the next one. This allows the |
| 2978 | // window manager to keep the previous window it had previously |
| 2979 | // created, if it still had one. |
Bryce Lee | af691c0 | 2017-03-20 14:20:22 -0700 | [diff] [blame] | 2980 | TaskRecord prevTask = r.getTask(); |
| 2981 | ActivityRecord prev = prevTask.topRunningActivityWithStartingWindowLocked(); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 2982 | if (prev != null) { |
| 2983 | // We don't want to reuse the previous starting preview if: |
| 2984 | // (1) The current activity is in a different task. |
Bryce Lee | af691c0 | 2017-03-20 14:20:22 -0700 | [diff] [blame] | 2985 | if (prev.getTask() != prevTask) { |
Craig Mautner | 29219d9 | 2013-04-16 20:19:12 -0700 | [diff] [blame] | 2986 | prev = null; |
| 2987 | } |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 2988 | // (2) The current activity is already displayed. |
Craig Mautner | 29219d9 | 2013-04-16 20:19:12 -0700 | [diff] [blame] | 2989 | else if (prev.nowVisible) { |
| 2990 | prev = null; |
| 2991 | } |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 2992 | } |
Jorim Jaggi | 02886a8 | 2016-12-06 09:10:06 -0800 | [diff] [blame] | 2993 | r.showStartingWindow(prev, newTask, isTaskSwitch(r, focusedTopActivity)); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 2994 | } |
| 2995 | } else { |
| 2996 | // If this is the first activity, don't do any fancy animations, |
| 2997 | // because there is nothing for it to animate on top of. |
Dianne Hackborn | 8078d8c | 2012-03-20 11:11:26 -0700 | [diff] [blame] | 2998 | ActivityOptions.abort(options); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 2999 | } |
Dianne Hackborn | be70785 | 2011-11-11 14:32:10 -0800 | [diff] [blame] | 3000 | } |
| 3001 | |
Winson Chung | f7e03e1 | 2017-08-22 11:32:16 -0700 | [diff] [blame] | 3002 | /** |
| 3003 | * @return Whether the switch to another task can trigger the currently running activity to |
| 3004 | * enter PiP while it is pausing (if supported). Only one of {@param toFrontTask} or |
| 3005 | * {@param toFrontActivity} should be set. |
| 3006 | */ |
| 3007 | private boolean canEnterPipOnTaskSwitch(ActivityRecord pipCandidate, |
| 3008 | TaskRecord toFrontTask, ActivityRecord toFrontActivity, ActivityOptions opts) { |
| 3009 | if (opts != null && opts.disallowEnterPictureInPictureWhileLaunching()) { |
| 3010 | // Ensure the caller has requested not to trigger auto-enter PiP |
| 3011 | return false; |
| 3012 | } |
Wale Ogunwale | 44f036f | 2017-09-29 05:09:09 -0700 | [diff] [blame] | 3013 | if (pipCandidate == null || pipCandidate.inPinnedWindowingMode()) { |
Winson Chung | f7e03e1 | 2017-08-22 11:32:16 -0700 | [diff] [blame] | 3014 | // Ensure that we do not trigger entering PiP an activity on the pinned stack |
| 3015 | return false; |
| 3016 | } |
Wale Ogunwale | 6827856 | 2017-09-23 17:13:55 -0700 | [diff] [blame] | 3017 | final ActivityStack targetStack = toFrontTask != null |
| 3018 | ? toFrontTask.getStack() : toFrontActivity.getStack(); |
| 3019 | if (targetStack != null && targetStack.isActivityTypeAssistant()) { |
Winson Chung | f7e03e1 | 2017-08-22 11:32:16 -0700 | [diff] [blame] | 3020 | // Ensure the task/activity being brought forward is not the assistant |
| 3021 | return false; |
| 3022 | } |
Winson Chung | f7e03e1 | 2017-08-22 11:32:16 -0700 | [diff] [blame] | 3023 | return true; |
| 3024 | } |
| 3025 | |
Jorim Jaggi | 02886a8 | 2016-12-06 09:10:06 -0800 | [diff] [blame] | 3026 | private boolean isTaskSwitch(ActivityRecord r, |
| 3027 | ActivityRecord topFocusedActivity) { |
Bryce Lee | af691c0 | 2017-03-20 14:20:22 -0700 | [diff] [blame] | 3028 | return topFocusedActivity != null && r.getTask() != topFocusedActivity.getTask(); |
Jorim Jaggi | 02886a8 | 2016-12-06 09:10:06 -0800 | [diff] [blame] | 3029 | } |
| 3030 | |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 3031 | /** |
| 3032 | * Perform a reset of the given task, if needed as part of launching it. |
| 3033 | * Returns the new HistoryRecord at the top of the task. |
| 3034 | */ |
Craig Mautner | e3a74d5 | 2013-02-22 14:14:58 -0800 | [diff] [blame] | 3035 | /** |
| 3036 | * Helper method for #resetTaskIfNeededLocked. |
| 3037 | * We are inside of the task being reset... we'll either finish this activity, push it out |
| 3038 | * for another task, or leave it as-is. |
| 3039 | * @param task The task containing the Activity (taskTop) that might be reset. |
| 3040 | * @param forceReset |
| 3041 | * @return An ActivityOptions that needs to be processed. |
| 3042 | */ |
Andrii Kulian | 21713ac | 2016-10-12 22:05:05 -0700 | [diff] [blame] | 3043 | private ActivityOptions resetTargetTaskIfNeededLocked(TaskRecord task, boolean forceReset) { |
Craig Mautner | e3a74d5 | 2013-02-22 14:14:58 -0800 | [diff] [blame] | 3044 | ActivityOptions topOptions = null; |
| 3045 | |
| 3046 | int replyChainEnd = -1; |
| 3047 | boolean canMoveOptions = true; |
| 3048 | |
| 3049 | // We only do this for activities that are not the root of the task (since if we finish |
| 3050 | // the root, we may no longer have the task!). |
| 3051 | final ArrayList<ActivityRecord> activities = task.mActivities; |
| 3052 | final int numActivities = activities.size(); |
Craig Mautner | 9d4e9bc | 2014-06-18 18:34:56 -0700 | [diff] [blame] | 3053 | final int rootActivityNdx = task.findEffectiveRootIndex(); |
| 3054 | for (int i = numActivities - 1; i > rootActivityNdx; --i ) { |
Craig Mautner | e3a74d5 | 2013-02-22 14:14:58 -0800 | [diff] [blame] | 3055 | ActivityRecord target = activities.get(i); |
Craig Mautner | 76ae2f0 | 2014-07-16 16:16:19 +0000 | [diff] [blame] | 3056 | if (target.frontOfTask) |
| 3057 | break; |
Craig Mautner | e3a74d5 | 2013-02-22 14:14:58 -0800 | [diff] [blame] | 3058 | |
| 3059 | final int flags = target.info.flags; |
| 3060 | final boolean finishOnTaskLaunch = |
| 3061 | (flags & ActivityInfo.FLAG_FINISH_ON_TASK_LAUNCH) != 0; |
| 3062 | final boolean allowTaskReparenting = |
| 3063 | (flags & ActivityInfo.FLAG_ALLOW_TASK_REPARENTING) != 0; |
| 3064 | final boolean clearWhenTaskReset = |
| 3065 | (target.intent.getFlags() & Intent.FLAG_ACTIVITY_CLEAR_WHEN_TASK_RESET) != 0; |
| 3066 | |
| 3067 | if (!finishOnTaskLaunch |
| 3068 | && !clearWhenTaskReset |
| 3069 | && target.resultTo != null) { |
| 3070 | // If this activity is sending a reply to a previous |
| 3071 | // activity, we can't do anything with it now until |
| 3072 | // we reach the start of the reply chain. |
| 3073 | // XXX note that we are assuming the result is always |
| 3074 | // to the previous activity, which is almost always |
| 3075 | // the case but we really shouldn't count on. |
| 3076 | if (replyChainEnd < 0) { |
| 3077 | replyChainEnd = i; |
| 3078 | } |
| 3079 | } else if (!finishOnTaskLaunch |
| 3080 | && !clearWhenTaskReset |
| 3081 | && allowTaskReparenting |
| 3082 | && target.taskAffinity != null |
| 3083 | && !target.taskAffinity.equals(task.affinity)) { |
| 3084 | // If this activity has an affinity for another |
| 3085 | // task, then we need to move it out of here. We will |
| 3086 | // move it as far out of the way as possible, to the |
| 3087 | // bottom of the activity stack. This also keeps it |
| 3088 | // correctly ordered with any activities we previously |
| 3089 | // moved. |
Craig Mautner | 329f412 | 2013-11-07 09:10:42 -0800 | [diff] [blame] | 3090 | final TaskRecord targetTask; |
Craig Mautner | dccb770 | 2013-09-17 15:53:34 -0700 | [diff] [blame] | 3091 | final ActivityRecord bottom = |
| 3092 | !mTaskHistory.isEmpty() && !mTaskHistory.get(0).mActivities.isEmpty() ? |
Craig Mautner | 329f412 | 2013-11-07 09:10:42 -0800 | [diff] [blame] | 3093 | mTaskHistory.get(0).mActivities.get(0) : null; |
Craig Mautner | dccb770 | 2013-09-17 15:53:34 -0700 | [diff] [blame] | 3094 | if (bottom != null && target.taskAffinity != null |
Bryce Lee | af691c0 | 2017-03-20 14:20:22 -0700 | [diff] [blame] | 3095 | && target.taskAffinity.equals(bottom.getTask().affinity)) { |
Craig Mautner | e3a74d5 | 2013-02-22 14:14:58 -0800 | [diff] [blame] | 3096 | // If the activity currently at the bottom has the |
| 3097 | // same task affinity as the one we are moving, |
| 3098 | // then merge it into the same task. |
Bryce Lee | af691c0 | 2017-03-20 14:20:22 -0700 | [diff] [blame] | 3099 | targetTask = bottom.getTask(); |
Wale Ogunwale | ee006da | 2015-03-30 14:49:25 -0700 | [diff] [blame] | 3100 | if (DEBUG_TASKS) Slog.v(TAG_TASKS, "Start pushing activity " + target |
Bryce Lee | af691c0 | 2017-03-20 14:20:22 -0700 | [diff] [blame] | 3101 | + " out to bottom task " + targetTask); |
Craig Mautner | e3a74d5 | 2013-02-22 14:14:58 -0800 | [diff] [blame] | 3102 | } else { |
Suprabh Shukla | 09a88f5 | 2015-12-02 14:36:31 -0800 | [diff] [blame] | 3103 | targetTask = createTaskRecord( |
| 3104 | mStackSupervisor.getNextTaskIdForUserLocked(target.userId), |
Wale Ogunwale | 6fbde9f | 2017-08-24 07:24:12 -0700 | [diff] [blame] | 3105 | target.info, null, null, null, false); |
Craig Mautner | 329f412 | 2013-11-07 09:10:42 -0800 | [diff] [blame] | 3106 | targetTask.affinityIntent = target.intent; |
Wale Ogunwale | ee006da | 2015-03-30 14:49:25 -0700 | [diff] [blame] | 3107 | if (DEBUG_TASKS) Slog.v(TAG_TASKS, "Start pushing activity " + target |
Bryce Lee | af691c0 | 2017-03-20 14:20:22 -0700 | [diff] [blame] | 3108 | + " out to new task " + targetTask); |
Craig Mautner | e3a74d5 | 2013-02-22 14:14:58 -0800 | [diff] [blame] | 3109 | } |
| 3110 | |
Craig Mautner | 525f3d9 | 2013-05-07 14:01:50 -0700 | [diff] [blame] | 3111 | boolean noOptions = canMoveOptions; |
Craig Mautner | e3a74d5 | 2013-02-22 14:14:58 -0800 | [diff] [blame] | 3112 | final int start = replyChainEnd < 0 ? i : replyChainEnd; |
| 3113 | for (int srcPos = start; srcPos >= i; --srcPos) { |
Craig Mautner | dccb770 | 2013-09-17 15:53:34 -0700 | [diff] [blame] | 3114 | final ActivityRecord p = activities.get(srcPos); |
Craig Mautner | e3a74d5 | 2013-02-22 14:14:58 -0800 | [diff] [blame] | 3115 | if (p.finishing) { |
| 3116 | continue; |
| 3117 | } |
| 3118 | |
Craig Mautner | e3a74d5 | 2013-02-22 14:14:58 -0800 | [diff] [blame] | 3119 | canMoveOptions = false; |
Craig Mautner | 525f3d9 | 2013-05-07 14:01:50 -0700 | [diff] [blame] | 3120 | if (noOptions && topOptions == null) { |
Craig Mautner | e3a74d5 | 2013-02-22 14:14:58 -0800 | [diff] [blame] | 3121 | topOptions = p.takeOptionsLocked(); |
| 3122 | if (topOptions != null) { |
Craig Mautner | 525f3d9 | 2013-05-07 14:01:50 -0700 | [diff] [blame] | 3123 | noOptions = false; |
Craig Mautner | e3a74d5 | 2013-02-22 14:14:58 -0800 | [diff] [blame] | 3124 | } |
| 3125 | } |
Wale Ogunwale | 0fc365c | 2015-05-25 19:35:42 -0700 | [diff] [blame] | 3126 | if (DEBUG_ADD_REMOVE) Slog.i(TAG_ADD_REMOVE, |
| 3127 | "Removing activity " + p + " from task=" + task + " adding to task=" |
| 3128 | + targetTask + " Callers=" + Debug.getCallers(4)); |
Wale Ogunwale | ee006da | 2015-03-30 14:49:25 -0700 | [diff] [blame] | 3129 | if (DEBUG_TASKS) Slog.v(TAG_TASKS, |
Bryce Lee | af691c0 | 2017-03-20 14:20:22 -0700 | [diff] [blame] | 3130 | "Pushing next activity " + p + " out to target's task " + target); |
Wale Ogunwale | a0cd15e | 2017-02-01 15:33:08 -0800 | [diff] [blame] | 3131 | p.reparent(targetTask, 0 /* position - bottom */, "resetTargetTaskIfNeeded"); |
Craig Mautner | e3a74d5 | 2013-02-22 14:14:58 -0800 | [diff] [blame] | 3132 | } |
| 3133 | |
Wale Ogunwale | 1666e31 | 2016-12-16 11:27:18 -0800 | [diff] [blame] | 3134 | mWindowContainerController.positionChildAtBottom( |
Wale Ogunwale | 66e1685 | 2017-10-19 13:35:52 -0700 | [diff] [blame] | 3135 | targetTask.getWindowContainerController(), false /* includingParents */); |
Craig Mautner | e3a74d5 | 2013-02-22 14:14:58 -0800 | [diff] [blame] | 3136 | replyChainEnd = -1; |
| 3137 | } else if (forceReset || finishOnTaskLaunch || clearWhenTaskReset) { |
| 3138 | // If the activity should just be removed -- either |
| 3139 | // because it asks for it, or the task should be |
| 3140 | // cleared -- then finish it and anything that is |
| 3141 | // part of its reply chain. |
| 3142 | int end; |
| 3143 | if (clearWhenTaskReset) { |
| 3144 | // In this case, we want to finish this activity |
| 3145 | // and everything above it, so be sneaky and pretend |
| 3146 | // like these are all in the reply chain. |
Mark Lu | 4b5a9a0 | 2014-12-09 14:47:13 +0800 | [diff] [blame] | 3147 | end = activities.size() - 1; |
Craig Mautner | e3a74d5 | 2013-02-22 14:14:58 -0800 | [diff] [blame] | 3148 | } else if (replyChainEnd < 0) { |
| 3149 | end = i; |
| 3150 | } else { |
| 3151 | end = replyChainEnd; |
| 3152 | } |
Craig Mautner | 525f3d9 | 2013-05-07 14:01:50 -0700 | [diff] [blame] | 3153 | boolean noOptions = canMoveOptions; |
Craig Mautner | e3a74d5 | 2013-02-22 14:14:58 -0800 | [diff] [blame] | 3154 | for (int srcPos = i; srcPos <= end; srcPos++) { |
Craig Mautner | 525f3d9 | 2013-05-07 14:01:50 -0700 | [diff] [blame] | 3155 | ActivityRecord p = activities.get(srcPos); |
Craig Mautner | e3a74d5 | 2013-02-22 14:14:58 -0800 | [diff] [blame] | 3156 | if (p.finishing) { |
| 3157 | continue; |
| 3158 | } |
| 3159 | canMoveOptions = false; |
Craig Mautner | 525f3d9 | 2013-05-07 14:01:50 -0700 | [diff] [blame] | 3160 | if (noOptions && topOptions == null) { |
Craig Mautner | e3a74d5 | 2013-02-22 14:14:58 -0800 | [diff] [blame] | 3161 | topOptions = p.takeOptionsLocked(); |
| 3162 | if (topOptions != null) { |
Craig Mautner | 525f3d9 | 2013-05-07 14:01:50 -0700 | [diff] [blame] | 3163 | noOptions = false; |
Craig Mautner | e3a74d5 | 2013-02-22 14:14:58 -0800 | [diff] [blame] | 3164 | } |
| 3165 | } |
Wale Ogunwale | ee006da | 2015-03-30 14:49:25 -0700 | [diff] [blame] | 3166 | if (DEBUG_TASKS) Slog.w(TAG_TASKS, |
Craig Mautner | 5854780 | 2013-03-05 08:23:53 -0800 | [diff] [blame] | 3167 | "resetTaskIntendedTask: calling finishActivity on " + p); |
Todd Kennedy | 539db51 | 2014-12-15 09:57:55 -0800 | [diff] [blame] | 3168 | if (finishActivityLocked( |
| 3169 | p, Activity.RESULT_CANCELED, null, "reset-task", false)) { |
Craig Mautner | e3a74d5 | 2013-02-22 14:14:58 -0800 | [diff] [blame] | 3170 | end--; |
| 3171 | srcPos--; |
| 3172 | } |
| 3173 | } |
| 3174 | replyChainEnd = -1; |
| 3175 | } else { |
| 3176 | // If we were in the middle of a chain, well the |
| 3177 | // activity that started it all doesn't want anything |
| 3178 | // special, so leave it all as-is. |
| 3179 | replyChainEnd = -1; |
| 3180 | } |
| 3181 | } |
| 3182 | |
| 3183 | return topOptions; |
| 3184 | } |
| 3185 | |
| 3186 | /** |
| 3187 | * Helper method for #resetTaskIfNeededLocked. Processes all of the activities in a given |
| 3188 | * TaskRecord looking for an affinity with the task of resetTaskIfNeededLocked.taskTop. |
| 3189 | * @param affinityTask The task we are looking for an affinity to. |
| 3190 | * @param task Task that resetTaskIfNeededLocked.taskTop belongs to. |
| 3191 | * @param topTaskIsHigher True if #task has already been processed by resetTaskIfNeededLocked. |
| 3192 | * @param forceReset Flag passed in to resetTaskIfNeededLocked. |
| 3193 | */ |
Craig Mautner | 525f3d9 | 2013-05-07 14:01:50 -0700 | [diff] [blame] | 3194 | private int resetAffinityTaskIfNeededLocked(TaskRecord affinityTask, TaskRecord task, |
Craig Mautner | 7787877 | 2013-03-04 19:46:24 -0800 | [diff] [blame] | 3195 | boolean topTaskIsHigher, boolean forceReset, int taskInsertionPoint) { |
Craig Mautner | e3a74d5 | 2013-02-22 14:14:58 -0800 | [diff] [blame] | 3196 | int replyChainEnd = -1; |
| 3197 | final int taskId = task.taskId; |
| 3198 | final String taskAffinity = task.affinity; |
| 3199 | |
| 3200 | final ArrayList<ActivityRecord> activities = affinityTask.mActivities; |
| 3201 | final int numActivities = activities.size(); |
Craig Mautner | 9d4e9bc | 2014-06-18 18:34:56 -0700 | [diff] [blame] | 3202 | final int rootActivityNdx = affinityTask.findEffectiveRootIndex(); |
| 3203 | |
| 3204 | // Do not operate on or below the effective root Activity. |
| 3205 | for (int i = numActivities - 1; i > rootActivityNdx; --i) { |
Craig Mautner | e3a74d5 | 2013-02-22 14:14:58 -0800 | [diff] [blame] | 3206 | ActivityRecord target = activities.get(i); |
Craig Mautner | 76ae2f0 | 2014-07-16 16:16:19 +0000 | [diff] [blame] | 3207 | if (target.frontOfTask) |
| 3208 | break; |
Craig Mautner | e3a74d5 | 2013-02-22 14:14:58 -0800 | [diff] [blame] | 3209 | |
| 3210 | final int flags = target.info.flags; |
| 3211 | boolean finishOnTaskLaunch = (flags & ActivityInfo.FLAG_FINISH_ON_TASK_LAUNCH) != 0; |
| 3212 | boolean allowTaskReparenting = (flags & ActivityInfo.FLAG_ALLOW_TASK_REPARENTING) != 0; |
| 3213 | |
| 3214 | if (target.resultTo != null) { |
| 3215 | // If this activity is sending a reply to a previous |
| 3216 | // activity, we can't do anything with it now until |
| 3217 | // we reach the start of the reply chain. |
| 3218 | // XXX note that we are assuming the result is always |
| 3219 | // to the previous activity, which is almost always |
| 3220 | // the case but we really shouldn't count on. |
| 3221 | if (replyChainEnd < 0) { |
| 3222 | replyChainEnd = i; |
| 3223 | } |
| 3224 | } else if (topTaskIsHigher |
| 3225 | && allowTaskReparenting |
| 3226 | && taskAffinity != null |
| 3227 | && taskAffinity.equals(target.taskAffinity)) { |
| 3228 | // This activity has an affinity for our task. Either remove it if we are |
| 3229 | // clearing or move it over to our task. Note that |
| 3230 | // we currently punt on the case where we are resetting a |
| 3231 | // task that is not at the top but who has activities above |
| 3232 | // with an affinity to it... this is really not a normal |
| 3233 | // case, and we will need to later pull that task to the front |
| 3234 | // and usually at that point we will do the reset and pick |
| 3235 | // up those remaining activities. (This only happens if |
| 3236 | // someone starts an activity in a new task from an activity |
| 3237 | // in a task that is not currently on top.) |
| 3238 | if (forceReset || finishOnTaskLaunch) { |
| 3239 | final int start = replyChainEnd >= 0 ? replyChainEnd : i; |
Wale Ogunwale | ee006da | 2015-03-30 14:49:25 -0700 | [diff] [blame] | 3240 | if (DEBUG_TASKS) Slog.v(TAG_TASKS, |
| 3241 | "Finishing task at index " + start + " to " + i); |
Craig Mautner | e3a74d5 | 2013-02-22 14:14:58 -0800 | [diff] [blame] | 3242 | for (int srcPos = start; srcPos >= i; --srcPos) { |
| 3243 | final ActivityRecord p = activities.get(srcPos); |
| 3244 | if (p.finishing) { |
| 3245 | continue; |
| 3246 | } |
Todd Kennedy | 539db51 | 2014-12-15 09:57:55 -0800 | [diff] [blame] | 3247 | finishActivityLocked( |
| 3248 | p, Activity.RESULT_CANCELED, null, "move-affinity", false); |
Craig Mautner | e3a74d5 | 2013-02-22 14:14:58 -0800 | [diff] [blame] | 3249 | } |
| 3250 | } else { |
Craig Mautner | 7787877 | 2013-03-04 19:46:24 -0800 | [diff] [blame] | 3251 | if (taskInsertionPoint < 0) { |
| 3252 | taskInsertionPoint = task.mActivities.size(); |
Craig Mautner | d232895 | 2013-03-05 12:46:26 -0800 | [diff] [blame] | 3253 | |
Craig Mautner | 7787877 | 2013-03-04 19:46:24 -0800 | [diff] [blame] | 3254 | } |
Craig Mautner | 7787877 | 2013-03-04 19:46:24 -0800 | [diff] [blame] | 3255 | |
| 3256 | final int start = replyChainEnd >= 0 ? replyChainEnd : i; |
Wale Ogunwale | ee006da | 2015-03-30 14:49:25 -0700 | [diff] [blame] | 3257 | if (DEBUG_TASKS) Slog.v(TAG_TASKS, |
| 3258 | "Reparenting from task=" + affinityTask + ":" + start + "-" + i |
| 3259 | + " to task=" + task + ":" + taskInsertionPoint); |
Craig Mautner | 7787877 | 2013-03-04 19:46:24 -0800 | [diff] [blame] | 3260 | for (int srcPos = start; srcPos >= i; --srcPos) { |
Craig Mautner | e3a74d5 | 2013-02-22 14:14:58 -0800 | [diff] [blame] | 3261 | final ActivityRecord p = activities.get(srcPos); |
Winson Chung | 3048004 | 2017-01-26 10:55:34 -0800 | [diff] [blame] | 3262 | p.reparent(task, taskInsertionPoint, "resetAffinityTaskIfNeededLocked"); |
Craig Mautner | e3a74d5 | 2013-02-22 14:14:58 -0800 | [diff] [blame] | 3263 | |
Wale Ogunwale | 0fc365c | 2015-05-25 19:35:42 -0700 | [diff] [blame] | 3264 | if (DEBUG_ADD_REMOVE) Slog.i(TAG_ADD_REMOVE, |
| 3265 | "Removing and adding activity " + p + " to stack at " + task |
| 3266 | + " callers=" + Debug.getCallers(3)); |
Wale Ogunwale | ee006da | 2015-03-30 14:49:25 -0700 | [diff] [blame] | 3267 | if (DEBUG_TASKS) Slog.v(TAG_TASKS, "Pulling activity " + p |
| 3268 | + " from " + srcPos + " in to resetting task " + task); |
Craig Mautner | e3a74d5 | 2013-02-22 14:14:58 -0800 | [diff] [blame] | 3269 | } |
Wale Ogunwale | 1666e31 | 2016-12-16 11:27:18 -0800 | [diff] [blame] | 3270 | mWindowContainerController.positionChildAtTop( |
| 3271 | task.getWindowContainerController(), true /* includingParents */); |
Craig Mautner | e3a74d5 | 2013-02-22 14:14:58 -0800 | [diff] [blame] | 3272 | |
| 3273 | // Now we've moved it in to place... but what if this is |
| 3274 | // a singleTop activity and we have put it on top of another |
| 3275 | // instance of the same activity? Then we drop the instance |
| 3276 | // below so it remains singleTop. |
| 3277 | if (target.info.launchMode == ActivityInfo.LAUNCH_SINGLE_TOP) { |
| 3278 | ArrayList<ActivityRecord> taskActivities = task.mActivities; |
Craig Mautner | e3a74d5 | 2013-02-22 14:14:58 -0800 | [diff] [blame] | 3279 | int targetNdx = taskActivities.indexOf(target); |
| 3280 | if (targetNdx > 0) { |
| 3281 | ActivityRecord p = taskActivities.get(targetNdx - 1); |
| 3282 | if (p.intent.getComponent().equals(target.intent.getComponent())) { |
Craig Mautner | 5854780 | 2013-03-05 08:23:53 -0800 | [diff] [blame] | 3283 | finishActivityLocked(p, Activity.RESULT_CANCELED, null, "replace", |
| 3284 | false); |
Craig Mautner | e3a74d5 | 2013-02-22 14:14:58 -0800 | [diff] [blame] | 3285 | } |
| 3286 | } |
| 3287 | } |
| 3288 | } |
| 3289 | |
| 3290 | replyChainEnd = -1; |
| 3291 | } |
| 3292 | } |
Craig Mautner | 7787877 | 2013-03-04 19:46:24 -0800 | [diff] [blame] | 3293 | return taskInsertionPoint; |
Craig Mautner | e3a74d5 | 2013-02-22 14:14:58 -0800 | [diff] [blame] | 3294 | } |
| 3295 | |
Craig Mautner | 8849a5e | 2013-04-02 16:41:03 -0700 | [diff] [blame] | 3296 | final ActivityRecord resetTaskIfNeededLocked(ActivityRecord taskTop, |
Craig Mautner | e3a74d5 | 2013-02-22 14:14:58 -0800 | [diff] [blame] | 3297 | ActivityRecord newActivity) { |
Winson Chung | 5fa3975 | 2017-10-04 14:50:15 -0700 | [diff] [blame] | 3298 | final boolean forceReset = |
Craig Mautner | e3a74d5 | 2013-02-22 14:14:58 -0800 | [diff] [blame] | 3299 | (newActivity.info.flags & ActivityInfo.FLAG_CLEAR_TASK_ON_LAUNCH) != 0; |
Bryce Lee | af691c0 | 2017-03-20 14:20:22 -0700 | [diff] [blame] | 3300 | final TaskRecord task = taskTop.getTask(); |
Craig Mautner | e3a74d5 | 2013-02-22 14:14:58 -0800 | [diff] [blame] | 3301 | |
| 3302 | /** False until we evaluate the TaskRecord associated with taskTop. Switches to true |
| 3303 | * for remaining tasks. Used for later tasks to reparent to task. */ |
| 3304 | boolean taskFound = false; |
| 3305 | |
| 3306 | /** If ActivityOptions are moved out and need to be aborted or moved to taskTop. */ |
| 3307 | ActivityOptions topOptions = null; |
| 3308 | |
Craig Mautner | 7787877 | 2013-03-04 19:46:24 -0800 | [diff] [blame] | 3309 | // Preserve the location for reparenting in the new task. |
| 3310 | int reparentInsertionPoint = -1; |
| 3311 | |
Craig Mautner | e3a74d5 | 2013-02-22 14:14:58 -0800 | [diff] [blame] | 3312 | for (int i = mTaskHistory.size() - 1; i >= 0; --i) { |
| 3313 | final TaskRecord targetTask = mTaskHistory.get(i); |
| 3314 | |
| 3315 | if (targetTask == task) { |
| 3316 | topOptions = resetTargetTaskIfNeededLocked(task, forceReset); |
| 3317 | taskFound = true; |
| 3318 | } else { |
Craig Mautner | 7787877 | 2013-03-04 19:46:24 -0800 | [diff] [blame] | 3319 | reparentInsertionPoint = resetAffinityTaskIfNeededLocked(targetTask, task, |
| 3320 | taskFound, forceReset, reparentInsertionPoint); |
Craig Mautner | e3a74d5 | 2013-02-22 14:14:58 -0800 | [diff] [blame] | 3321 | } |
| 3322 | } |
| 3323 | |
Craig Mautner | 70a8693 | 2013-02-28 22:37:44 -0800 | [diff] [blame] | 3324 | int taskNdx = mTaskHistory.indexOf(task); |
riddle_hsu | 1d7919a | 2015-03-11 17:09:50 +0800 | [diff] [blame] | 3325 | if (taskNdx >= 0) { |
| 3326 | do { |
| 3327 | taskTop = mTaskHistory.get(taskNdx--).getTopActivity(); |
| 3328 | } while (taskTop == null && taskNdx >= 0); |
| 3329 | } |
Craig Mautner | 70a8693 | 2013-02-28 22:37:44 -0800 | [diff] [blame] | 3330 | |
Craig Mautner | e3a74d5 | 2013-02-22 14:14:58 -0800 | [diff] [blame] | 3331 | if (topOptions != null) { |
| 3332 | // If we got some ActivityOptions from an activity on top that |
| 3333 | // was removed from the task, propagate them to the new real top. |
| 3334 | if (taskTop != null) { |
Craig Mautner | e3a74d5 | 2013-02-22 14:14:58 -0800 | [diff] [blame] | 3335 | taskTop.updateOptionsLocked(topOptions); |
| 3336 | } else { |
Craig Mautner | e3a74d5 | 2013-02-22 14:14:58 -0800 | [diff] [blame] | 3337 | topOptions.abort(); |
| 3338 | } |
| 3339 | } |
| 3340 | |
| 3341 | return taskTop; |
| 3342 | } |
| 3343 | |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 3344 | void sendActivityResultLocked(int callingUid, ActivityRecord r, |
| 3345 | String resultWho, int requestCode, int resultCode, Intent data) { |
| 3346 | |
| 3347 | if (callingUid > 0) { |
| 3348 | mService.grantUriPermissionFromIntentLocked(callingUid, r.packageName, |
Nicolas Prevot | c6cf95c | 2014-05-29 11:30:36 +0100 | [diff] [blame] | 3349 | data, r.getUriPermissionsLocked(), r.userId); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 3350 | } |
| 3351 | |
| 3352 | if (DEBUG_RESULTS) Slog.v(TAG, "Send activity result to " + r |
| 3353 | + " : who=" + resultWho + " req=" + requestCode |
| 3354 | + " res=" + resultCode + " data=" + data); |
| 3355 | if (mResumedActivity == r && r.app != null && r.app.thread != null) { |
| 3356 | try { |
| 3357 | ArrayList<ResultInfo> list = new ArrayList<ResultInfo>(); |
| 3358 | list.add(new ResultInfo(resultWho, requestCode, |
| 3359 | resultCode, data)); |
Bryce Lee | b0f993f | 2018-03-02 15:38:01 -0800 | [diff] [blame] | 3360 | mService.getLifecycleManager().scheduleTransaction(r.app.thread, r.appToken, |
Andrii Kulian | 9c5ea9c | 2017-12-07 09:31:01 -0800 | [diff] [blame] | 3361 | ActivityResultItem.obtain(list)); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 3362 | return; |
| 3363 | } catch (Exception e) { |
| 3364 | Slog.w(TAG, "Exception thrown sending result to " + r, e); |
| 3365 | } |
| 3366 | } |
| 3367 | |
| 3368 | r.addResultLocked(null, resultWho, requestCode, resultCode, data); |
| 3369 | } |
| 3370 | |
Shunta Sato | 63b8ee3 | 2016-07-11 13:32:52 +0900 | [diff] [blame] | 3371 | /** 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] | 3372 | private boolean isATopFinishingTask(TaskRecord task) { |
Shunta Sato | 63b8ee3 | 2016-07-11 13:32:52 +0900 | [diff] [blame] | 3373 | for (int i = mTaskHistory.size() - 1; i >= 0; --i) { |
| 3374 | final TaskRecord current = mTaskHistory.get(i); |
| 3375 | final ActivityRecord r = current.topRunningActivityLocked(); |
| 3376 | if (r != null) { |
| 3377 | // We got a top running activity, so there isn't a top finishing task... |
| 3378 | return false; |
| 3379 | } |
| 3380 | if (current == task) { |
| 3381 | return true; |
| 3382 | } |
| 3383 | } |
| 3384 | return false; |
| 3385 | } |
| 3386 | |
Wale Ogunwale | 66e1685 | 2017-10-19 13:35:52 -0700 | [diff] [blame] | 3387 | private void adjustFocusedActivityStack(ActivityRecord r, String reason) { |
Shunta Sato | 63b8ee3 | 2016-07-11 13:32:52 +0900 | [diff] [blame] | 3388 | if (!mStackSupervisor.isFocusedStack(this) || |
| 3389 | ((mResumedActivity != r) && (mResumedActivity != null))) { |
Wale Ogunwale | d045c82 | 2015-12-02 09:14:28 -0800 | [diff] [blame] | 3390 | return; |
| 3391 | } |
| 3392 | |
| 3393 | final ActivityRecord next = topRunningActivityLocked(); |
| 3394 | final String myReason = reason + " adjustFocus"; |
Bryce Lee | 3345c4e | 2017-04-25 07:40:41 -0700 | [diff] [blame] | 3395 | |
Wale Ogunwale | 66e1685 | 2017-10-19 13:35:52 -0700 | [diff] [blame] | 3396 | if (next == r) { |
| 3397 | mStackSupervisor.moveFocusableActivityStackToFrontLocked( |
| 3398 | mStackSupervisor.topRunningActivityLocked(), myReason); |
| 3399 | return; |
Wale Ogunwale | d045c82 | 2015-12-02 09:14:28 -0800 | [diff] [blame] | 3400 | } |
Wale Ogunwale | d697cea | 2015-02-20 17:19:49 -0800 | [diff] [blame] | 3401 | |
Wale Ogunwale | 66e1685 | 2017-10-19 13:35:52 -0700 | [diff] [blame] | 3402 | if (next != null && isFocusable()) { |
| 3403 | // Keep focus in stack if we have a top running activity and are focusable. |
| 3404 | return; |
| 3405 | } |
| 3406 | |
| 3407 | // Task is not guaranteed to be non-null. For example, destroying the |
| 3408 | // {@link ActivityRecord} will disassociate the task from the activity. |
| 3409 | final TaskRecord task = r.getTask(); |
| 3410 | |
| 3411 | if (task == null) { |
| 3412 | throw new IllegalStateException("activity no longer associated with task:" + r); |
| 3413 | } |
| 3414 | |
| 3415 | // Move focus to next focusable stack if possible. |
| 3416 | if (adjustFocusToNextFocusableStack(myReason)) { |
| 3417 | return; |
| 3418 | } |
| 3419 | |
| 3420 | // Whatever...go home. |
| 3421 | mStackSupervisor.moveHomeStackTaskToTop(myReason); |
Craig Mautner | 04f0b70 | 2013-10-22 12:31:01 -0700 | [diff] [blame] | 3422 | } |
| 3423 | |
Andrii Kulian | 250d653 | 2017-02-08 23:30:45 -0800 | [diff] [blame] | 3424 | /** Find next proper focusable stack and make it focused. */ |
Wale Ogunwale | 17696de | 2018-03-15 16:41:05 -0700 | [diff] [blame] | 3425 | boolean adjustFocusToNextFocusableStack(String reason) { |
Wale Ogunwale | 66e1685 | 2017-10-19 13:35:52 -0700 | [diff] [blame] | 3426 | return adjustFocusToNextFocusableStack(reason, false /* allowFocusSelf */); |
Andrii Kulian | 250d653 | 2017-02-08 23:30:45 -0800 | [diff] [blame] | 3427 | } |
| 3428 | |
| 3429 | /** |
| 3430 | * Find next proper focusable stack and make it focused. |
| 3431 | * @param allowFocusSelf Is the focus allowed to remain on the same stack. |
| 3432 | */ |
Wale Ogunwale | 66e1685 | 2017-10-19 13:35:52 -0700 | [diff] [blame] | 3433 | private boolean adjustFocusToNextFocusableStack(String reason, boolean allowFocusSelf) { |
Wale Ogunwale | e1f68ce | 2018-03-09 08:58:54 -0800 | [diff] [blame] | 3434 | final ActivityStack stack = |
| 3435 | mStackSupervisor.getNextFocusableStackLocked(this, !allowFocusSelf); |
Wale Ogunwale | 4cea0f5 | 2015-12-25 06:30:31 -0800 | [diff] [blame] | 3436 | final String myReason = reason + " adjustFocusToNextFocusableStack"; |
Wale Ogunwale | d697cea | 2015-02-20 17:19:49 -0800 | [diff] [blame] | 3437 | if (stack == null) { |
| 3438 | return false; |
| 3439 | } |
Wale Ogunwale | d34e80c | 2016-03-23 17:08:44 -0700 | [diff] [blame] | 3440 | |
Wale Ogunwale | c750f5f | 2016-03-28 07:43:51 -0700 | [diff] [blame] | 3441 | final ActivityRecord top = stack.topRunningActivityLocked(); |
| 3442 | |
Wale Ogunwale | 66e1685 | 2017-10-19 13:35:52 -0700 | [diff] [blame] | 3443 | if (stack.isActivityTypeHome() && (top == null || !top.visible)) { |
Wale Ogunwale | c750f5f | 2016-03-28 07:43:51 -0700 | [diff] [blame] | 3444 | // 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] | 3445 | // visible, then use the move the home stack task to top to make the activity visible. |
Matthew Ng | ae1ff4f | 2016-11-10 15:49:14 -0800 | [diff] [blame] | 3446 | return mStackSupervisor.moveHomeStackTaskToTop(reason); |
Wale Ogunwale | d34e80c | 2016-03-23 17:08:44 -0700 | [diff] [blame] | 3447 | } |
Chong Zhang | 6cda19c | 2016-06-14 19:07:56 -0700 | [diff] [blame] | 3448 | |
| 3449 | stack.moveToFront(myReason); |
| 3450 | return true; |
Wale Ogunwale | d697cea | 2015-02-20 17:19:49 -0800 | [diff] [blame] | 3451 | } |
| 3452 | |
Craig Mautner | f333327 | 2013-04-22 10:55:53 -0700 | [diff] [blame] | 3453 | final void stopActivityLocked(ActivityRecord r) { |
Wale Ogunwale | ee006da | 2015-03-30 14:49:25 -0700 | [diff] [blame] | 3454 | if (DEBUG_SWITCH) Slog.d(TAG_SWITCH, "Stopping: " + r); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 3455 | if ((r.intent.getFlags()&Intent.FLAG_ACTIVITY_NO_HISTORY) != 0 |
| 3456 | || (r.info.flags&ActivityInfo.FLAG_NO_HISTORY) != 0) { |
| 3457 | if (!r.finishing) { |
David Stevens | 9440dc8 | 2017-03-16 19:00:20 -0700 | [diff] [blame] | 3458 | if (!shouldSleepActivities()) { |
Wale Ogunwale | 0fc365c | 2015-05-25 19:35:42 -0700 | [diff] [blame] | 3459 | if (DEBUG_STATES) Slog.d(TAG_STATES, "no-history finish of " + r); |
Wale Ogunwale | 3f529ee | 2015-07-12 15:14:01 -0700 | [diff] [blame] | 3460 | if (requestFinishActivityLocked(r.appToken, Activity.RESULT_CANCELED, null, |
| 3461 | "stop-no-history", false)) { |
Bryce Lee | 3345c4e | 2017-04-25 07:40:41 -0700 | [diff] [blame] | 3462 | // If {@link requestFinishActivityLocked} returns {@code true}, |
Wale Ogunwale | 66e1685 | 2017-10-19 13:35:52 -0700 | [diff] [blame] | 3463 | // {@link adjustFocusedActivityStack} would have been already called. |
Wale Ogunwale | 3f529ee | 2015-07-12 15:14:01 -0700 | [diff] [blame] | 3464 | r.resumeKeyDispatchingLocked(); |
| 3465 | return; |
| 3466 | } |
Christopher Tate | d3f175c | 2012-06-14 14:16:54 -0700 | [diff] [blame] | 3467 | } else { |
Wale Ogunwale | 0fc365c | 2015-05-25 19:35:42 -0700 | [diff] [blame] | 3468 | if (DEBUG_STATES) Slog.d(TAG_STATES, "Not finishing noHistory " + r |
Christopher Tate | d3f175c | 2012-06-14 14:16:54 -0700 | [diff] [blame] | 3469 | + " on stop because we're just sleeping"); |
| 3470 | } |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 3471 | } |
Christopher Tate | 5007ddd | 2012-06-12 13:08:18 -0700 | [diff] [blame] | 3472 | } |
| 3473 | |
| 3474 | if (r.app != null && r.app.thread != null) { |
Wale Ogunwale | 66e1685 | 2017-10-19 13:35:52 -0700 | [diff] [blame] | 3475 | adjustFocusedActivityStack(r, "stopActivity"); |
Dianne Hackborn | 621e2fe | 2012-02-16 17:07:33 -0800 | [diff] [blame] | 3476 | r.resumeKeyDispatchingLocked(); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 3477 | try { |
| 3478 | r.stopped = false; |
Wale Ogunwale | 0fc365c | 2015-05-25 19:35:42 -0700 | [diff] [blame] | 3479 | if (DEBUG_STATES) Slog.v(TAG_STATES, |
| 3480 | "Moving to STOPPING: " + r + " (stop requested)"); |
Bryce Lee | 7ace395 | 2018-02-16 14:34:32 -0800 | [diff] [blame] | 3481 | r.setState(STOPPING, "stopActivityLocked"); |
Wale Ogunwale | ee006da | 2015-03-30 14:49:25 -0700 | [diff] [blame] | 3482 | if (DEBUG_VISIBILITY) Slog.v(TAG_VISIBILITY, |
| 3483 | "Stopping visible=" + r.visible + " for " + r); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 3484 | if (!r.visible) { |
Wale Ogunwale | b9a0c99 | 2017-04-18 07:25:20 -0700 | [diff] [blame] | 3485 | r.setVisible(false); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 3486 | } |
Wale Ogunwale | cd7043e | 2016-02-27 17:37:46 -0800 | [diff] [blame] | 3487 | EventLogTags.writeAmStopActivity( |
| 3488 | r.userId, System.identityHashCode(r), r.shortComponentName); |
Bryce Lee | b0f993f | 2018-03-02 15:38:01 -0800 | [diff] [blame] | 3489 | mService.getLifecycleManager().scheduleTransaction(r.app.thread, r.appToken, |
Bryce Lee | 1d0d514 | 2018-04-12 10:35:07 -0700 | [diff] [blame] | 3490 | StopActivityItem.obtain(r.visible, r.configChangeFlags)); |
David Stevens | 9440dc8 | 2017-03-16 19:00:20 -0700 | [diff] [blame] | 3491 | if (shouldSleepOrShutDownActivities()) { |
Dianne Hackborn | 4eba96b | 2011-01-21 13:34:36 -0800 | [diff] [blame] | 3492 | r.setSleeping(true); |
| 3493 | } |
Craig Mautner | f7bfefb | 2013-05-16 17:30:44 -0700 | [diff] [blame] | 3494 | Message msg = mHandler.obtainMessage(STOP_TIMEOUT_MSG, r); |
Dianne Hackborn | 162bc0e | 2012-04-09 14:06:16 -0700 | [diff] [blame] | 3495 | mHandler.sendMessageDelayed(msg, STOP_TIMEOUT); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 3496 | } catch (Exception e) { |
| 3497 | // Maybe just ignore exceptions here... if the process |
| 3498 | // has crashed, our death notification will clean things |
| 3499 | // up. |
| 3500 | Slog.w(TAG, "Exception thrown during pause", e); |
| 3501 | // Just in case, assume it to be stopped. |
| 3502 | r.stopped = true; |
Wale Ogunwale | 0fc365c | 2015-05-25 19:35:42 -0700 | [diff] [blame] | 3503 | 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] | 3504 | r.setState(STOPPED, "stopActivityLocked"); |
Wale Ogunwale | f81c1d1 | 2016-01-12 12:20:18 -0800 | [diff] [blame] | 3505 | if (r.deferRelaunchUntilPaused) { |
Craig Mautner | ee2e45a | 2014-06-27 12:10:03 -0700 | [diff] [blame] | 3506 | destroyActivityLocked(r, true, "stop-except"); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 3507 | } |
| 3508 | } |
| 3509 | } |
| 3510 | } |
Craig Mautner | 23ac33b | 2013-04-01 16:26:35 -0700 | [diff] [blame] | 3511 | |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 3512 | /** |
| 3513 | * @return Returns true if the activity is being finished, false if for |
| 3514 | * some reason it is being left as-is. |
| 3515 | */ |
| 3516 | final boolean requestFinishActivityLocked(IBinder token, int resultCode, |
Dianne Hackborn | 2d1b378 | 2012-09-09 17:49:39 -0700 | [diff] [blame] | 3517 | Intent resultData, String reason, boolean oomAdj) { |
Craig Mautner | d74f7d7 | 2013-02-26 13:41:02 -0800 | [diff] [blame] | 3518 | ActivityRecord r = isInStackLocked(token); |
Wale Ogunwale | 0fc365c | 2015-05-25 19:35:42 -0700 | [diff] [blame] | 3519 | if (DEBUG_RESULTS || DEBUG_STATES) Slog.v(TAG_STATES, |
| 3520 | "Finishing activity token=" + token + " r=" |
Christopher Tate | d3f175c | 2012-06-14 14:16:54 -0700 | [diff] [blame] | 3521 | + ", result=" + resultCode + ", data=" + resultData |
| 3522 | + ", reason=" + reason); |
Craig Mautner | d74f7d7 | 2013-02-26 13:41:02 -0800 | [diff] [blame] | 3523 | if (r == null) { |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 3524 | return false; |
| 3525 | } |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 3526 | |
Craig Mautner | d44711d | 2013-02-23 11:24:36 -0800 | [diff] [blame] | 3527 | finishActivityLocked(r, resultCode, resultData, reason, oomAdj); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 3528 | return true; |
| 3529 | } |
| 3530 | |
Craig Mautner | d232895 | 2013-03-05 12:46:26 -0800 | [diff] [blame] | 3531 | final void finishSubActivityLocked(ActivityRecord self, String resultWho, int requestCode) { |
Craig Mautner | 9658b31 | 2013-02-28 10:55:59 -0800 | [diff] [blame] | 3532 | for (int taskNdx = mTaskHistory.size() - 1; taskNdx >= 0; --taskNdx) { |
| 3533 | ArrayList<ActivityRecord> activities = mTaskHistory.get(taskNdx).mActivities; |
| 3534 | for (int activityNdx = activities.size() - 1; activityNdx >= 0; --activityNdx) { |
| 3535 | ActivityRecord r = activities.get(activityNdx); |
| 3536 | if (r.resultTo == self && r.requestCode == requestCode) { |
| 3537 | if ((r.resultWho == null && resultWho == null) || |
| 3538 | (r.resultWho != null && r.resultWho.equals(resultWho))) { |
| 3539 | finishActivityLocked(r, Activity.RESULT_CANCELED, null, "request-sub", |
| 3540 | false); |
| 3541 | } |
Dianne Hackborn | ecc5a9c | 2012-04-26 18:56:09 -0700 | [diff] [blame] | 3542 | } |
| 3543 | } |
| 3544 | } |
Dianne Hackborn | 2d1b378 | 2012-09-09 17:49:39 -0700 | [diff] [blame] | 3545 | mService.updateOomAdjLocked(); |
Dianne Hackborn | ecc5a9c | 2012-04-26 18:56:09 -0700 | [diff] [blame] | 3546 | } |
| 3547 | |
Andrii Kulian | 8cc92ac6 | 2018-04-02 23:14:18 -0700 | [diff] [blame] | 3548 | /** |
| 3549 | * Finish the topmost activity that belongs to the crashed app. We may also finish the activity |
| 3550 | * that requested launch of the crashed one to prevent launch-crash loop. |
| 3551 | * @param app The app that crashed. |
| 3552 | * @param reason Reason to perform this action. |
| 3553 | * @return The task that was finished in this stack, {@code null} if top running activity does |
| 3554 | * not belong to the crashed app. |
| 3555 | */ |
| 3556 | final TaskRecord finishTopCrashedActivityLocked(ProcessRecord app, String reason) { |
Filip Gruszczynski | 3e85ba2 | 2015-10-05 22:48:30 -0700 | [diff] [blame] | 3557 | ActivityRecord r = topRunningActivityLocked(); |
Adrian Roos | 20d7df3 | 2016-01-12 18:59:43 +0100 | [diff] [blame] | 3558 | TaskRecord finishedTask = null; |
| 3559 | if (r == null || r.app != app) { |
| 3560 | return null; |
| 3561 | } |
| 3562 | Slog.w(TAG, " Force finishing activity " |
| 3563 | + r.intent.getComponent().flattenToShortString()); |
Bryce Lee | af691c0 | 2017-03-20 14:20:22 -0700 | [diff] [blame] | 3564 | finishedTask = r.getTask(); |
| 3565 | int taskNdx = mTaskHistory.indexOf(finishedTask); |
| 3566 | final TaskRecord task = finishedTask; |
| 3567 | int activityNdx = task.mActivities.indexOf(r); |
Jorim Jaggi | 9c52ebb | 2018-06-01 14:45:24 +0200 | [diff] [blame] | 3568 | mWindowManager.prepareAppTransition(TRANSIT_CRASHING_ACTIVITY_CLOSE, |
| 3569 | false /* alwaysKeepCurrent */); |
Adrian Roos | 20d7df3 | 2016-01-12 18:59:43 +0100 | [diff] [blame] | 3570 | finishActivityLocked(r, Activity.RESULT_CANCELED, null, reason, false); |
Bryce Lee | af691c0 | 2017-03-20 14:20:22 -0700 | [diff] [blame] | 3571 | finishedTask = task; |
Adrian Roos | 20d7df3 | 2016-01-12 18:59:43 +0100 | [diff] [blame] | 3572 | // Also terminate any activities below it that aren't yet |
| 3573 | // stopped, to avoid a situation where one will get |
| 3574 | // re-start our crashing activity once it gets resumed again. |
| 3575 | --activityNdx; |
| 3576 | if (activityNdx < 0) { |
| 3577 | do { |
| 3578 | --taskNdx; |
| 3579 | if (taskNdx < 0) { |
| 3580 | break; |
| 3581 | } |
| 3582 | activityNdx = mTaskHistory.get(taskNdx).mActivities.size() - 1; |
| 3583 | } while (activityNdx < 0); |
| 3584 | } |
| 3585 | if (activityNdx >= 0) { |
| 3586 | r = mTaskHistory.get(taskNdx).mActivities.get(activityNdx); |
Bryce Lee | 7ace395 | 2018-02-16 14:34:32 -0800 | [diff] [blame] | 3587 | if (r.isState(RESUMED, PAUSING, PAUSED)) { |
Wale Ogunwale | 6fbde9f | 2017-08-24 07:24:12 -0700 | [diff] [blame] | 3588 | if (!r.isActivityTypeHome() || mService.mHomeProcess != r.app) { |
Adrian Roos | 20d7df3 | 2016-01-12 18:59:43 +0100 | [diff] [blame] | 3589 | Slog.w(TAG, " Force finishing activity " |
| 3590 | + r.intent.getComponent().flattenToShortString()); |
| 3591 | finishActivityLocked(r, Activity.RESULT_CANCELED, null, reason, false); |
Craig Mautner | 05d6272ba | 2013-02-11 09:39:27 -0800 | [diff] [blame] | 3592 | } |
| 3593 | } |
| 3594 | } |
Adrian Roos | 20d7df3 | 2016-01-12 18:59:43 +0100 | [diff] [blame] | 3595 | return finishedTask; |
Craig Mautner | 05d6272ba | 2013-02-11 09:39:27 -0800 | [diff] [blame] | 3596 | } |
| 3597 | |
Dianne Hackborn | 6ea0d0a | 2014-07-02 16:23:21 -0700 | [diff] [blame] | 3598 | final void finishVoiceTask(IVoiceInteractionSession session) { |
| 3599 | IBinder sessionBinder = session.asBinder(); |
| 3600 | boolean didOne = false; |
| 3601 | for (int taskNdx = mTaskHistory.size() - 1; taskNdx >= 0; --taskNdx) { |
| 3602 | TaskRecord tr = mTaskHistory.get(taskNdx); |
| 3603 | if (tr.voiceSession != null && tr.voiceSession.asBinder() == sessionBinder) { |
| 3604 | for (int activityNdx = tr.mActivities.size() - 1; activityNdx >= 0; --activityNdx) { |
| 3605 | ActivityRecord r = tr.mActivities.get(activityNdx); |
| 3606 | if (!r.finishing) { |
| 3607 | finishActivityLocked(r, Activity.RESULT_CANCELED, null, "finish-voice", |
| 3608 | false); |
| 3609 | didOne = true; |
| 3610 | } |
| 3611 | } |
Amith Yamasani | 0af6fa7 | 2016-01-17 15:36:19 -0800 | [diff] [blame] | 3612 | } else { |
| 3613 | // Check if any of the activities are using voice |
| 3614 | for (int activityNdx = tr.mActivities.size() - 1; activityNdx >= 0; --activityNdx) { |
| 3615 | ActivityRecord r = tr.mActivities.get(activityNdx); |
| 3616 | if (r.voiceSession != null |
| 3617 | && r.voiceSession.asBinder() == sessionBinder) { |
| 3618 | // Inform of cancellation |
| 3619 | r.clearVoiceSessionLocked(); |
| 3620 | try { |
| 3621 | r.app.thread.scheduleLocalVoiceInteractionStarted((IBinder) r.appToken, |
| 3622 | null); |
| 3623 | } catch (RemoteException re) { |
| 3624 | // Ok |
| 3625 | } |
Amith Yamasani | 0af6fa7 | 2016-01-17 15:36:19 -0800 | [diff] [blame] | 3626 | mService.finishRunningVoiceLocked(); |
| 3627 | break; |
| 3628 | } |
| 3629 | } |
Dianne Hackborn | 6ea0d0a | 2014-07-02 16:23:21 -0700 | [diff] [blame] | 3630 | } |
| 3631 | } |
Amith Yamasani | 0af6fa7 | 2016-01-17 15:36:19 -0800 | [diff] [blame] | 3632 | |
Dianne Hackborn | 6ea0d0a | 2014-07-02 16:23:21 -0700 | [diff] [blame] | 3633 | if (didOne) { |
| 3634 | mService.updateOomAdjLocked(); |
| 3635 | } |
| 3636 | } |
| 3637 | |
Craig Mautner | d232895 | 2013-03-05 12:46:26 -0800 | [diff] [blame] | 3638 | final boolean finishActivityAffinityLocked(ActivityRecord r) { |
Bryce Lee | af691c0 | 2017-03-20 14:20:22 -0700 | [diff] [blame] | 3639 | ArrayList<ActivityRecord> activities = r.getTask().mActivities; |
Craig Mautner | d74f7d7 | 2013-02-26 13:41:02 -0800 | [diff] [blame] | 3640 | for (int index = activities.indexOf(r); index >= 0; --index) { |
| 3641 | ActivityRecord cur = activities.get(index); |
Kenny Root | e6585b3 | 2013-12-13 12:00:26 -0800 | [diff] [blame] | 3642 | if (!Objects.equals(cur.taskAffinity, r.taskAffinity)) { |
Dianne Hackborn | ecc5a9c | 2012-04-26 18:56:09 -0700 | [diff] [blame] | 3643 | break; |
| 3644 | } |
Craig Mautner | de4ef02 | 2013-04-07 19:01:33 -0700 | [diff] [blame] | 3645 | finishActivityLocked(cur, Activity.RESULT_CANCELED, null, "request-affinity", true); |
Dianne Hackborn | ecc5a9c | 2012-04-26 18:56:09 -0700 | [diff] [blame] | 3646 | } |
| 3647 | return true; |
| 3648 | } |
| 3649 | |
Andrii Kulian | 21713ac | 2016-10-12 22:05:05 -0700 | [diff] [blame] | 3650 | private void finishActivityResultsLocked(ActivityRecord r, int resultCode, Intent resultData) { |
Dianne Hackborn | 5c60743 | 2012-02-28 14:44:19 -0800 | [diff] [blame] | 3651 | // send the result |
| 3652 | ActivityRecord resultTo = r.resultTo; |
| 3653 | if (resultTo != null) { |
Wale Ogunwale | ee006da | 2015-03-30 14:49:25 -0700 | [diff] [blame] | 3654 | if (DEBUG_RESULTS) Slog.v(TAG_RESULTS, "Adding result to " + resultTo |
Dianne Hackborn | 5c60743 | 2012-02-28 14:44:19 -0800 | [diff] [blame] | 3655 | + " who=" + r.resultWho + " req=" + r.requestCode |
| 3656 | + " res=" + resultCode + " data=" + resultData); |
Nicolas Prevot | c6cf95c | 2014-05-29 11:30:36 +0100 | [diff] [blame] | 3657 | if (resultTo.userId != r.userId) { |
Nicolas Prevot | 6b942b8 | 2014-06-02 15:20:42 +0100 | [diff] [blame] | 3658 | if (resultData != null) { |
Nicolas Prevot | 107f7b7 | 2015-07-01 16:31:48 +0100 | [diff] [blame] | 3659 | resultData.prepareToLeaveUser(r.userId); |
Nicolas Prevot | 6b942b8 | 2014-06-02 15:20:42 +0100 | [diff] [blame] | 3660 | } |
Nicolas Prevot | c6cf95c | 2014-05-29 11:30:36 +0100 | [diff] [blame] | 3661 | } |
Dianne Hackborn | 5c60743 | 2012-02-28 14:44:19 -0800 | [diff] [blame] | 3662 | if (r.info.applicationInfo.uid > 0) { |
| 3663 | mService.grantUriPermissionFromIntentLocked(r.info.applicationInfo.uid, |
| 3664 | resultTo.packageName, resultData, |
Nicolas Prevot | c6cf95c | 2014-05-29 11:30:36 +0100 | [diff] [blame] | 3665 | resultTo.getUriPermissionsLocked(), resultTo.userId); |
Dianne Hackborn | 5c60743 | 2012-02-28 14:44:19 -0800 | [diff] [blame] | 3666 | } |
| 3667 | resultTo.addResultLocked(r, r.resultWho, r.requestCode, resultCode, |
| 3668 | resultData); |
| 3669 | r.resultTo = null; |
| 3670 | } |
Wale Ogunwale | ee006da | 2015-03-30 14:49:25 -0700 | [diff] [blame] | 3671 | 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] | 3672 | |
| 3673 | // Make sure this HistoryRecord is not holding on to other resources, |
| 3674 | // because clients have remote IPC references to this object so we |
| 3675 | // can't assume that will go away and want to avoid circular IPC refs. |
| 3676 | r.results = null; |
| 3677 | r.pendingResults = null; |
| 3678 | r.newIntents = null; |
| 3679 | r.icicle = null; |
| 3680 | } |
| 3681 | |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 3682 | /** |
Winson Chung | 6954fc9 | 2017-03-24 16:22:12 -0700 | [diff] [blame] | 3683 | * See {@link #finishActivityLocked(ActivityRecord, int, Intent, String, boolean, boolean)} |
| 3684 | */ |
| 3685 | final boolean finishActivityLocked(ActivityRecord r, int resultCode, Intent resultData, |
| 3686 | String reason, boolean oomAdj) { |
| 3687 | return finishActivityLocked(r, resultCode, resultData, reason, oomAdj, !PAUSE_IMMEDIATELY); |
| 3688 | } |
| 3689 | |
| 3690 | /** |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 3691 | * @return Returns true if this activity has been removed from the history |
| 3692 | * list, or false if it is still in the list and will be removed later. |
| 3693 | */ |
Craig Mautner | f333327 | 2013-04-22 10:55:53 -0700 | [diff] [blame] | 3694 | final boolean finishActivityLocked(ActivityRecord r, int resultCode, Intent resultData, |
Winson Chung | 6954fc9 | 2017-03-24 16:22:12 -0700 | [diff] [blame] | 3695 | String reason, boolean oomAdj, boolean pauseImmediately) { |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 3696 | if (r.finishing) { |
| 3697 | Slog.w(TAG, "Duplicate finish request for " + r); |
| 3698 | return false; |
| 3699 | } |
| 3700 | |
Jorim Jaggi | fe76234 | 2016-10-13 14:33:27 +0200 | [diff] [blame] | 3701 | mWindowManager.deferSurfaceLayout(); |
| 3702 | try { |
| 3703 | r.makeFinishingLocked(); |
Bryce Lee | af691c0 | 2017-03-20 14:20:22 -0700 | [diff] [blame] | 3704 | final TaskRecord task = r.getTask(); |
Jorim Jaggi | fe76234 | 2016-10-13 14:33:27 +0200 | [diff] [blame] | 3705 | EventLog.writeEvent(EventLogTags.AM_FINISH_ACTIVITY, |
| 3706 | r.userId, System.identityHashCode(r), |
| 3707 | task.taskId, r.shortComponentName, reason); |
| 3708 | final ArrayList<ActivityRecord> activities = task.mActivities; |
| 3709 | final int index = activities.indexOf(r); |
| 3710 | if (index < (activities.size() - 1)) { |
| 3711 | task.setFrontOfTask(); |
| 3712 | if ((r.intent.getFlags() & Intent.FLAG_ACTIVITY_CLEAR_WHEN_TASK_RESET) != 0) { |
| 3713 | // If the caller asked that this activity (and all above it) |
| 3714 | // be cleared when the task is reset, don't lose that information, |
| 3715 | // but propagate it up to the next activity. |
| 3716 | ActivityRecord next = activities.get(index+1); |
| 3717 | next.intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_WHEN_TASK_RESET); |
| 3718 | } |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 3719 | } |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 3720 | |
Jorim Jaggi | fe76234 | 2016-10-13 14:33:27 +0200 | [diff] [blame] | 3721 | r.pauseKeyDispatchingLocked(); |
Craig Mautner | 04f0b70 | 2013-10-22 12:31:01 -0700 | [diff] [blame] | 3722 | |
Wale Ogunwale | 66e1685 | 2017-10-19 13:35:52 -0700 | [diff] [blame] | 3723 | adjustFocusedActivityStack(r, "finishActivity"); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 3724 | |
Jorim Jaggi | fe76234 | 2016-10-13 14:33:27 +0200 | [diff] [blame] | 3725 | finishActivityResultsLocked(r, resultCode, resultData); |
Craig Mautner | 2420ead | 2013-04-01 17:13:20 -0700 | [diff] [blame] | 3726 | |
Yorke Lee | bdef537 | 2017-04-10 16:38:51 -0700 | [diff] [blame] | 3727 | final boolean endTask = index <= 0 && !task.isClearingToReuseTask(); |
Jorim Jaggi | fe76234 | 2016-10-13 14:33:27 +0200 | [diff] [blame] | 3728 | final int transit = endTask ? TRANSIT_TASK_CLOSE : TRANSIT_ACTIVITY_CLOSE; |
| 3729 | if (mResumedActivity == r) { |
| 3730 | if (DEBUG_VISIBILITY || DEBUG_TRANSITION) Slog.v(TAG_TRANSITION, |
| 3731 | "Prepare close transition: finishing " + r); |
Winson Chung | 6954fc9 | 2017-03-24 16:22:12 -0700 | [diff] [blame] | 3732 | if (endTask) { |
| 3733 | mService.mTaskChangeNotificationController.notifyTaskRemovalStarted( |
| 3734 | task.taskId); |
| 3735 | } |
Jorim Jaggi | af80db4 | 2016-04-07 19:19:15 -0700 | [diff] [blame] | 3736 | mWindowManager.prepareAppTransition(transit, false); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 3737 | |
Jorim Jaggi | fe76234 | 2016-10-13 14:33:27 +0200 | [diff] [blame] | 3738 | // Tell window manager to prepare for this one to be removed. |
Wale Ogunwale | 26c0dfe | 2016-12-14 14:42:30 -0800 | [diff] [blame] | 3739 | r.setVisibility(false); |
Jorim Jaggi | fe76234 | 2016-10-13 14:33:27 +0200 | [diff] [blame] | 3740 | |
| 3741 | if (mPausingActivity == null) { |
| 3742 | if (DEBUG_PAUSE) Slog.v(TAG_PAUSE, "Finish needs to pause: " + r); |
| 3743 | if (DEBUG_USER_LEAVING) Slog.v(TAG_USER_LEAVING, |
| 3744 | "finish() => pause with userLeaving=false"); |
Winson Chung | 6954fc9 | 2017-03-24 16:22:12 -0700 | [diff] [blame] | 3745 | startPausingLocked(false, false, null, pauseImmediately); |
Jorim Jaggi | fe76234 | 2016-10-13 14:33:27 +0200 | [diff] [blame] | 3746 | } |
| 3747 | |
| 3748 | if (endTask) { |
Bryce Lee | 2b8e037 | 2018-04-05 17:01:37 -0700 | [diff] [blame] | 3749 | mService.getLockTaskController().clearLockedTask(task); |
Jorim Jaggi | fe76234 | 2016-10-13 14:33:27 +0200 | [diff] [blame] | 3750 | } |
Bryce Lee | 7ace395 | 2018-02-16 14:34:32 -0800 | [diff] [blame] | 3751 | } else if (!r.isState(PAUSING)) { |
Jorim Jaggi | fe76234 | 2016-10-13 14:33:27 +0200 | [diff] [blame] | 3752 | // If the activity is PAUSING, we will complete the finish once |
| 3753 | // it is done pausing; else we can just directly finish it here. |
| 3754 | if (DEBUG_PAUSE) Slog.v(TAG_PAUSE, "Finish not pausing: " + r); |
| 3755 | if (r.visible) { |
Winson Chung | 6954fc9 | 2017-03-24 16:22:12 -0700 | [diff] [blame] | 3756 | prepareActivityHideTransitionAnimation(r, transit); |
| 3757 | } |
| 3758 | |
| 3759 | final int finishMode = (r.visible || r.nowVisible) ? FINISH_AFTER_VISIBLE |
| 3760 | : FINISH_AFTER_PAUSE; |
Bryce Lee | f52974c | 2018-02-14 15:12:01 -0800 | [diff] [blame] | 3761 | final boolean removedActivity = finishCurrentActivityLocked(r, finishMode, oomAdj, |
| 3762 | "finishActivityLocked") == null; |
Winson Chung | 6954fc9 | 2017-03-24 16:22:12 -0700 | [diff] [blame] | 3763 | |
| 3764 | // The following code is an optimization. When the last non-task overlay activity |
| 3765 | // is removed from the task, we remove the entire task from the stack. However, |
| 3766 | // since that is done after the scheduled destroy callback from the activity, that |
| 3767 | // call to change the visibility of the task overlay activities would be out of |
| 3768 | // sync with the activitiy visibility being set for this finishing activity above. |
| 3769 | // In this case, we can set the visibility of all the task overlay activities when |
| 3770 | // we detect the last one is finishing to keep them in sync. |
| 3771 | if (task.onlyHasTaskOverlayActivities(true /* excludeFinishing */)) { |
| 3772 | for (ActivityRecord taskOverlay : task.mActivities) { |
| 3773 | if (!taskOverlay.mTaskOverlay) { |
| 3774 | continue; |
| 3775 | } |
| 3776 | prepareActivityHideTransitionAnimation(taskOverlay, transit); |
Jorim Jaggi | fe76234 | 2016-10-13 14:33:27 +0200 | [diff] [blame] | 3777 | } |
| 3778 | } |
Winson Chung | 6954fc9 | 2017-03-24 16:22:12 -0700 | [diff] [blame] | 3779 | return removedActivity; |
Jorim Jaggi | fe76234 | 2016-10-13 14:33:27 +0200 | [diff] [blame] | 3780 | } else { |
| 3781 | if (DEBUG_PAUSE) Slog.v(TAG_PAUSE, "Finish waiting for pause of: " + r); |
| 3782 | } |
| 3783 | |
| 3784 | return false; |
| 3785 | } finally { |
| 3786 | mWindowManager.continueSurfaceLayout(); |
| 3787 | } |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 3788 | } |
| 3789 | |
Winson Chung | 6954fc9 | 2017-03-24 16:22:12 -0700 | [diff] [blame] | 3790 | private void prepareActivityHideTransitionAnimation(ActivityRecord r, int transit) { |
| 3791 | mWindowManager.prepareAppTransition(transit, false); |
| 3792 | r.setVisibility(false); |
| 3793 | mWindowManager.executeAppTransition(); |
Bryce Lee | 4a19438 | 2017-04-04 14:32:48 -0700 | [diff] [blame] | 3794 | if (!mStackSupervisor.mActivitiesWaitingForVisibleActivity.contains(r)) { |
| 3795 | mStackSupervisor.mActivitiesWaitingForVisibleActivity.add(r); |
Winson Chung | 6954fc9 | 2017-03-24 16:22:12 -0700 | [diff] [blame] | 3796 | } |
| 3797 | } |
| 3798 | |
Craig Mautner | f333327 | 2013-04-22 10:55:53 -0700 | [diff] [blame] | 3799 | static final int FINISH_IMMEDIATELY = 0; |
| 3800 | static final int FINISH_AFTER_PAUSE = 1; |
| 3801 | static final int FINISH_AFTER_VISIBLE = 2; |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 3802 | |
Bryce Lee | f52974c | 2018-02-14 15:12:01 -0800 | [diff] [blame] | 3803 | final ActivityRecord finishCurrentActivityLocked(ActivityRecord r, int mode, boolean oomAdj, |
| 3804 | String reason) { |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 3805 | // First things first: if this activity is currently visible, |
| 3806 | // and the resumed activity is not yet visible, then hold off on |
| 3807 | // finishing until the resumed one becomes visible. |
Chong Zhang | 824b6dc | 2016-04-27 14:11:12 -0700 | [diff] [blame] | 3808 | |
Bryce Lee | c961e0a | 2018-04-13 17:58:02 -0700 | [diff] [blame] | 3809 | // The activity that we are finishing may be over the lock screen. In this case, we do not |
| 3810 | // want to consider activities that cannot be shown on the lock screen as running and should |
| 3811 | // proceed with finishing the activity if there is no valid next top running activity. |
| 3812 | final ActivityRecord next = mStackSupervisor.topRunningActivityLocked( |
| 3813 | true /* considerKeyguardState */); |
Chong Zhang | 824b6dc | 2016-04-27 14:11:12 -0700 | [diff] [blame] | 3814 | |
Chong Zhang | efd9a5b | 2016-04-26 16:21:07 -0700 | [diff] [blame] | 3815 | if (mode == FINISH_AFTER_VISIBLE && (r.visible || r.nowVisible) |
Chong Zhang | 824b6dc | 2016-04-27 14:11:12 -0700 | [diff] [blame] | 3816 | && next != null && !next.nowVisible) { |
Craig Mautner | de4ef02 | 2013-04-07 19:01:33 -0700 | [diff] [blame] | 3817 | if (!mStackSupervisor.mStoppingActivities.contains(r)) { |
Winson Chung | 4dabf23 | 2017-01-25 13:25:22 -0800 | [diff] [blame] | 3818 | addToStopping(r, false /* scheduleIdle */, false /* idleDelayed */); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 3819 | } |
Wale Ogunwale | 0fc365c | 2015-05-25 19:35:42 -0700 | [diff] [blame] | 3820 | if (DEBUG_STATES) Slog.v(TAG_STATES, |
| 3821 | "Moving to STOPPING: "+ r + " (finish requested)"); |
Bryce Lee | 7ace395 | 2018-02-16 14:34:32 -0800 | [diff] [blame] | 3822 | r.setState(STOPPING, "finishCurrentActivityLocked"); |
Dianne Hackborn | 2d1b378 | 2012-09-09 17:49:39 -0700 | [diff] [blame] | 3823 | if (oomAdj) { |
| 3824 | mService.updateOomAdjLocked(); |
| 3825 | } |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 3826 | return r; |
| 3827 | } |
| 3828 | |
| 3829 | // make sure the record is cleaned out of other places. |
Craig Mautner | de4ef02 | 2013-04-07 19:01:33 -0700 | [diff] [blame] | 3830 | mStackSupervisor.mStoppingActivities.remove(r); |
Craig Mautner | 0eea92c | 2013-05-16 13:35:39 -0700 | [diff] [blame] | 3831 | mStackSupervisor.mGoingToSleepActivities.remove(r); |
Bryce Lee | 4a19438 | 2017-04-04 14:32:48 -0700 | [diff] [blame] | 3832 | mStackSupervisor.mActivitiesWaitingForVisibleActivity.remove(r); |
Bryce Lee | 7ace395 | 2018-02-16 14:34:32 -0800 | [diff] [blame] | 3833 | final ActivityState prevState = r.getState(); |
Wale Ogunwale | 0fc365c | 2015-05-25 19:35:42 -0700 | [diff] [blame] | 3834 | if (DEBUG_STATES) Slog.v(TAG_STATES, "Moving to FINISHING: " + r); |
Bryce Lee | b0f993f | 2018-03-02 15:38:01 -0800 | [diff] [blame] | 3835 | |
Bryce Lee | 7ace395 | 2018-02-16 14:34:32 -0800 | [diff] [blame] | 3836 | r.setState(FINISHING, "finishCurrentActivityLocked"); |
Andrii Kulian | 995fa2b | 2016-07-29 12:55:41 -0700 | [diff] [blame] | 3837 | final boolean finishingActivityInNonFocusedStack |
Andrii Kulian | 02b7a83 | 2016-10-06 23:11:56 -0700 | [diff] [blame] | 3838 | = r.getStack() != mStackSupervisor.getFocusedStack() |
Bryce Lee | 7ace395 | 2018-02-16 14:34:32 -0800 | [diff] [blame] | 3839 | && prevState == PAUSED && mode == FINISH_AFTER_VISIBLE; |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 3840 | |
| 3841 | if (mode == FINISH_IMMEDIATELY |
Bryce Lee | 7ace395 | 2018-02-16 14:34:32 -0800 | [diff] [blame] | 3842 | || (prevState == PAUSED |
Wale Ogunwale | 44f036f | 2017-09-29 05:09:09 -0700 | [diff] [blame] | 3843 | && (mode == FINISH_AFTER_PAUSE || inPinnedWindowingMode())) |
Andrii Kulian | 995fa2b | 2016-07-29 12:55:41 -0700 | [diff] [blame] | 3844 | || finishingActivityInNonFocusedStack |
Wale Ogunwale | b9a0c99 | 2017-04-18 07:25:20 -0700 | [diff] [blame] | 3845 | || prevState == STOPPING |
| 3846 | || prevState == STOPPED |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 3847 | || prevState == ActivityState.INITIALIZING) { |
Wale Ogunwale | 7d70117 | 2015-03-11 15:36:30 -0700 | [diff] [blame] | 3848 | r.makeFinishingLocked(); |
Bryce Lee | f52974c | 2018-02-14 15:12:01 -0800 | [diff] [blame] | 3849 | boolean activityRemoved = destroyActivityLocked(r, true, "finish-imm:" + reason); |
Andrii Kulian | 7318d63 | 2016-07-20 18:59:28 -0700 | [diff] [blame] | 3850 | |
Andrii Kulian | 995fa2b | 2016-07-29 12:55:41 -0700 | [diff] [blame] | 3851 | if (finishingActivityInNonFocusedStack) { |
| 3852 | // Finishing activity that was in paused state and it was in not currently focused |
| 3853 | // stack, need to make something visible in its place. |
Andrii Kulian | a39ae3e | 2018-05-31 12:43:54 -0700 | [diff] [blame] | 3854 | mStackSupervisor.ensureVisibilityAndConfig(next, mDisplayId, |
Andrii Kulian | f4479ee | 2018-05-23 17:52:48 -0700 | [diff] [blame] | 3855 | false /* markFrozenIfConfigChanged */, true /* deferResume */); |
Andrii Kulian | 7318d63 | 2016-07-20 18:59:28 -0700 | [diff] [blame] | 3856 | } |
Dianne Hackborn | 42e620c | 2012-06-24 13:20:51 -0700 | [diff] [blame] | 3857 | if (activityRemoved) { |
Wale Ogunwale | d046a01 | 2015-12-24 13:05:59 -0800 | [diff] [blame] | 3858 | mStackSupervisor.resumeFocusedStackTopActivityLocked(); |
Dianne Hackborn | 42e620c | 2012-06-24 13:20:51 -0700 | [diff] [blame] | 3859 | } |
Wale Ogunwale | 0fc365c | 2015-05-25 19:35:42 -0700 | [diff] [blame] | 3860 | if (DEBUG_CONTAINERS) Slog.d(TAG_CONTAINERS, |
Craig Mautner | d163e75 | 2014-06-13 17:18:47 -0700 | [diff] [blame] | 3861 | "destroyActivityLocked: finishCurrentActivityLocked r=" + r + |
| 3862 | " destroy returned removed=" + activityRemoved); |
Dianne Hackborn | 42e620c | 2012-06-24 13:20:51 -0700 | [diff] [blame] | 3863 | return activityRemoved ? null : r; |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 3864 | } |
Craig Mautner | 05d6272ba | 2013-02-11 09:39:27 -0800 | [diff] [blame] | 3865 | |
| 3866 | // Need to go through the full pause cycle to get this |
| 3867 | // activity into the stopped state and then finish it. |
Wale Ogunwale | e23149f | 2015-03-06 15:39:44 -0800 | [diff] [blame] | 3868 | if (DEBUG_ALL) Slog.v(TAG, "Enqueueing pending finish: " + r); |
Craig Mautner | f333327 | 2013-04-22 10:55:53 -0700 | [diff] [blame] | 3869 | mStackSupervisor.mFinishingActivities.add(r); |
Martin Wallgren | c8733b8 | 2011-08-31 12:39:31 +0200 | [diff] [blame] | 3870 | r.resumeKeyDispatchingLocked(); |
Wale Ogunwale | d046a01 | 2015-12-24 13:05:59 -0800 | [diff] [blame] | 3871 | mStackSupervisor.resumeFocusedStackTopActivityLocked(); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 3872 | return r; |
| 3873 | } |
| 3874 | |
Craig Mautner | ee36c77 | 2014-07-16 14:56:05 -0700 | [diff] [blame] | 3875 | void finishAllActivitiesLocked(boolean immediately) { |
| 3876 | boolean noActivitiesInStack = true; |
Craig Mautner | f4c909b | 2014-04-17 18:39:38 -0700 | [diff] [blame] | 3877 | for (int taskNdx = mTaskHistory.size() - 1; taskNdx >= 0; --taskNdx) { |
| 3878 | final ArrayList<ActivityRecord> activities = mTaskHistory.get(taskNdx).mActivities; |
| 3879 | for (int activityNdx = activities.size() - 1; activityNdx >= 0; --activityNdx) { |
| 3880 | final ActivityRecord r = activities.get(activityNdx); |
Craig Mautner | ee36c77 | 2014-07-16 14:56:05 -0700 | [diff] [blame] | 3881 | noActivitiesInStack = false; |
| 3882 | if (r.finishing && !immediately) { |
Craig Mautner | f4c909b | 2014-04-17 18:39:38 -0700 | [diff] [blame] | 3883 | continue; |
| 3884 | } |
Craig Mautner | ee36c77 | 2014-07-16 14:56:05 -0700 | [diff] [blame] | 3885 | Slog.d(TAG, "finishAllActivitiesLocked: finishing " + r + " immediately"); |
Bryce Lee | f52974c | 2018-02-14 15:12:01 -0800 | [diff] [blame] | 3886 | finishCurrentActivityLocked(r, FINISH_IMMEDIATELY, false, |
| 3887 | "finishAllActivitiesLocked"); |
Craig Mautner | f4c909b | 2014-04-17 18:39:38 -0700 | [diff] [blame] | 3888 | } |
| 3889 | } |
Craig Mautner | ee36c77 | 2014-07-16 14:56:05 -0700 | [diff] [blame] | 3890 | if (noActivitiesInStack) { |
Andrii Kulian | 94e82d9b0 | 2017-07-13 15:33:06 -0700 | [diff] [blame] | 3891 | remove(); |
Craig Mautner | ee36c77 | 2014-07-16 14:56:05 -0700 | [diff] [blame] | 3892 | } |
Craig Mautner | f4c909b | 2014-04-17 18:39:38 -0700 | [diff] [blame] | 3893 | } |
| 3894 | |
Wale Ogunwale | 66e1685 | 2017-10-19 13:35:52 -0700 | [diff] [blame] | 3895 | /** @return true if the stack behind this one is a standard activity type. */ |
| 3896 | boolean inFrontOfStandardStack() { |
| 3897 | final ActivityDisplay display = getDisplay(); |
| 3898 | if (display == null) { |
| 3899 | return false; |
| 3900 | } |
| 3901 | final int index = display.getIndexOf(this); |
| 3902 | if (index == 0) { |
| 3903 | return false; |
| 3904 | } |
| 3905 | final ActivityStack stackBehind = display.getChildAt(index - 1); |
| 3906 | return stackBehind.isActivityTypeStandard(); |
| 3907 | } |
| 3908 | |
| 3909 | boolean shouldUpRecreateTaskLocked(ActivityRecord srec, String destAffinity) { |
Dianne Hackborn | 6f4d61f | 2014-08-21 17:50:42 -0700 | [diff] [blame] | 3910 | // Basic case: for simple app-centric recents, we need to recreate |
| 3911 | // the task if the affinity has changed. |
Bryce Lee | af691c0 | 2017-03-20 14:20:22 -0700 | [diff] [blame] | 3912 | if (srec == null || srec.getTask().affinity == null || |
| 3913 | !srec.getTask().affinity.equals(destAffinity)) { |
Dianne Hackborn | 6f4d61f | 2014-08-21 17:50:42 -0700 | [diff] [blame] | 3914 | return true; |
| 3915 | } |
| 3916 | // Document-centric case: an app may be split in to multiple documents; |
| 3917 | // they need to re-create their task if this current activity is the root |
| 3918 | // of a document, unless simply finishing it will return them to the the |
| 3919 | // correct app behind. |
Bryce Lee | af691c0 | 2017-03-20 14:20:22 -0700 | [diff] [blame] | 3920 | final TaskRecord task = srec.getTask(); |
Wale Ogunwale | 66e1685 | 2017-10-19 13:35:52 -0700 | [diff] [blame] | 3921 | if (srec.frontOfTask && task.getBaseIntent() != null && task.getBaseIntent().isDocument()) { |
Dianne Hackborn | 6f4d61f | 2014-08-21 17:50:42 -0700 | [diff] [blame] | 3922 | // 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] | 3923 | if (!inFrontOfStandardStack()) { |
Dianne Hackborn | 6f4d61f | 2014-08-21 17:50:42 -0700 | [diff] [blame] | 3924 | // Finishing won't return to an application, so we need to recreate. |
| 3925 | return true; |
| 3926 | } |
| 3927 | // 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] | 3928 | int taskIdx = mTaskHistory.indexOf(task); |
Dianne Hackborn | 6f4d61f | 2014-08-21 17:50:42 -0700 | [diff] [blame] | 3929 | if (taskIdx <= 0) { |
| 3930 | Slog.w(TAG, "shouldUpRecreateTask: task not in history for " + srec); |
| 3931 | return false; |
| 3932 | } |
Wale Ogunwale | 6fbde9f | 2017-08-24 07:24:12 -0700 | [diff] [blame] | 3933 | final TaskRecord prevTask = mTaskHistory.get(taskIdx); |
Bryce Lee | af691c0 | 2017-03-20 14:20:22 -0700 | [diff] [blame] | 3934 | if (!task.affinity.equals(prevTask.affinity)) { |
Dianne Hackborn | 6f4d61f | 2014-08-21 17:50:42 -0700 | [diff] [blame] | 3935 | // These are different apps, so need to recreate. |
| 3936 | return true; |
| 3937 | } |
| 3938 | } |
| 3939 | return false; |
| 3940 | } |
| 3941 | |
Wale Ogunwale | 7d70117 | 2015-03-11 15:36:30 -0700 | [diff] [blame] | 3942 | final boolean navigateUpToLocked(ActivityRecord srec, Intent destIntent, int resultCode, |
Craig Mautner | 05d6272ba | 2013-02-11 09:39:27 -0800 | [diff] [blame] | 3943 | Intent resultData) { |
Bryce Lee | af691c0 | 2017-03-20 14:20:22 -0700 | [diff] [blame] | 3944 | final TaskRecord task = srec.getTask(); |
Craig Mautner | 0247fc8 | 2013-02-28 14:32:06 -0800 | [diff] [blame] | 3945 | final ArrayList<ActivityRecord> activities = task.mActivities; |
| 3946 | final int start = activities.indexOf(srec); |
| 3947 | if (!mTaskHistory.contains(task) || (start < 0)) { |
Craig Mautner | 05d6272ba | 2013-02-11 09:39:27 -0800 | [diff] [blame] | 3948 | return false; |
| 3949 | } |
| 3950 | int finishTo = start - 1; |
Craig Mautner | 0247fc8 | 2013-02-28 14:32:06 -0800 | [diff] [blame] | 3951 | ActivityRecord parent = finishTo < 0 ? null : activities.get(finishTo); |
Craig Mautner | 05d6272ba | 2013-02-11 09:39:27 -0800 | [diff] [blame] | 3952 | boolean foundParentInTask = false; |
Craig Mautner | 0247fc8 | 2013-02-28 14:32:06 -0800 | [diff] [blame] | 3953 | final ComponentName dest = destIntent.getComponent(); |
| 3954 | if (start > 0 && dest != null) { |
| 3955 | for (int i = finishTo; i >= 0; i--) { |
| 3956 | ActivityRecord r = activities.get(i); |
| 3957 | if (r.info.packageName.equals(dest.getPackageName()) && |
Craig Mautner | 05d6272ba | 2013-02-11 09:39:27 -0800 | [diff] [blame] | 3958 | r.info.name.equals(dest.getClassName())) { |
| 3959 | finishTo = i; |
| 3960 | parent = r; |
| 3961 | foundParentInTask = true; |
| 3962 | break; |
| 3963 | } |
| 3964 | } |
| 3965 | } |
| 3966 | |
| 3967 | IActivityController controller = mService.mController; |
| 3968 | if (controller != null) { |
| 3969 | ActivityRecord next = topRunningActivityLocked(srec.appToken, 0); |
| 3970 | if (next != null) { |
| 3971 | // ask watcher if this is allowed |
| 3972 | boolean resumeOK = true; |
| 3973 | try { |
| 3974 | resumeOK = controller.activityResuming(next.packageName); |
| 3975 | } catch (RemoteException e) { |
| 3976 | mService.mController = null; |
Kenny Root | add5821 | 2013-05-07 09:47:34 -0700 | [diff] [blame] | 3977 | Watchdog.getInstance().setActivityController(null); |
Craig Mautner | 05d6272ba | 2013-02-11 09:39:27 -0800 | [diff] [blame] | 3978 | } |
| 3979 | |
| 3980 | if (!resumeOK) { |
| 3981 | return false; |
| 3982 | } |
| 3983 | } |
| 3984 | } |
| 3985 | final long origId = Binder.clearCallingIdentity(); |
| 3986 | for (int i = start; i > finishTo; i--) { |
Craig Mautner | 0247fc8 | 2013-02-28 14:32:06 -0800 | [diff] [blame] | 3987 | ActivityRecord r = activities.get(i); |
| 3988 | requestFinishActivityLocked(r.appToken, resultCode, resultData, "navigate-up", true); |
Craig Mautner | 05d6272ba | 2013-02-11 09:39:27 -0800 | [diff] [blame] | 3989 | // Only return the supplied result for the first activity finished |
| 3990 | resultCode = Activity.RESULT_CANCELED; |
| 3991 | resultData = null; |
| 3992 | } |
| 3993 | |
| 3994 | if (parent != null && foundParentInTask) { |
| 3995 | final int parentLaunchMode = parent.info.launchMode; |
| 3996 | final int destIntentFlags = destIntent.getFlags(); |
| 3997 | if (parentLaunchMode == ActivityInfo.LAUNCH_SINGLE_INSTANCE || |
| 3998 | parentLaunchMode == ActivityInfo.LAUNCH_SINGLE_TASK || |
| 3999 | parentLaunchMode == ActivityInfo.LAUNCH_SINGLE_TOP || |
| 4000 | (destIntentFlags & Intent.FLAG_ACTIVITY_CLEAR_TOP) != 0) { |
Dianne Hackborn | 85d558c | 2014-11-04 10:31:54 -0800 | [diff] [blame] | 4001 | parent.deliverNewIntentLocked(srec.info.applicationInfo.uid, destIntent, |
| 4002 | srec.packageName); |
Craig Mautner | 05d6272ba | 2013-02-11 09:39:27 -0800 | [diff] [blame] | 4003 | } else { |
| 4004 | try { |
| 4005 | ActivityInfo aInfo = AppGlobals.getPackageManager().getActivityInfo( |
Philip P. Moltmann | cff8f0f | 2018-03-27 12:51:51 -0700 | [diff] [blame] | 4006 | destIntent.getComponent(), ActivityManagerService.STOCK_PM_FLAGS, |
| 4007 | srec.userId); |
Bryce Lee | 4c9a597 | 2017-12-01 22:14:24 -0800 | [diff] [blame] | 4008 | // TODO(b/64750076): Check if calling pid should really be -1. |
| 4009 | final int res = mService.getActivityStartController() |
| 4010 | .obtainStarter(destIntent, "navigateUpTo") |
| 4011 | .setCaller(srec.app.thread) |
| 4012 | .setActivityInfo(aInfo) |
| 4013 | .setResultTo(parent.appToken) |
| 4014 | .setCallingPid(-1) |
| 4015 | .setCallingUid(parent.launchedFromUid) |
| 4016 | .setCallingPackage(parent.launchedFromPackage) |
| 4017 | .setRealCallingPid(-1) |
| 4018 | .setRealCallingUid(parent.launchedFromUid) |
| 4019 | .setComponentSpecified(true) |
| 4020 | .execute(); |
Craig Mautner | 05d6272ba | 2013-02-11 09:39:27 -0800 | [diff] [blame] | 4021 | foundParentInTask = res == ActivityManager.START_SUCCESS; |
| 4022 | } catch (RemoteException e) { |
| 4023 | foundParentInTask = false; |
| 4024 | } |
| 4025 | requestFinishActivityLocked(parent.appToken, resultCode, |
Todd Kennedy | 539db51 | 2014-12-15 09:57:55 -0800 | [diff] [blame] | 4026 | resultData, "navigate-top", true); |
Craig Mautner | 05d6272ba | 2013-02-11 09:39:27 -0800 | [diff] [blame] | 4027 | } |
| 4028 | } |
| 4029 | Binder.restoreCallingIdentity(origId); |
| 4030 | return foundParentInTask; |
| 4031 | } |
Bryce Lee | af691c0 | 2017-03-20 14:20:22 -0700 | [diff] [blame] | 4032 | |
| 4033 | /** |
| 4034 | * Remove any state associated with the {@link ActivityRecord}. This should be called whenever |
| 4035 | * an activity moves away from the stack. |
| 4036 | */ |
| 4037 | void onActivityRemovedFromStack(ActivityRecord r) { |
Bryce Lee | 84730a0 | 2018-04-03 14:10:04 -0700 | [diff] [blame] | 4038 | removeTimeoutsForActivityLocked(r); |
| 4039 | |
| 4040 | if (mResumedActivity != null && mResumedActivity == r) { |
| 4041 | setResumedActivity(null, "onActivityRemovedFromStack"); |
Bryce Lee | af691c0 | 2017-03-20 14:20:22 -0700 | [diff] [blame] | 4042 | } |
Bryce Lee | 84730a0 | 2018-04-03 14:10:04 -0700 | [diff] [blame] | 4043 | if (mPausingActivity != null && mPausingActivity == r) { |
Bryce Lee | af691c0 | 2017-03-20 14:20:22 -0700 | [diff] [blame] | 4044 | mPausingActivity = null; |
| 4045 | } |
Bryce Lee | 84730a0 | 2018-04-03 14:10:04 -0700 | [diff] [blame] | 4046 | } |
Bryce Lee | af691c0 | 2017-03-20 14:20:22 -0700 | [diff] [blame] | 4047 | |
Bryce Lee | 84730a0 | 2018-04-03 14:10:04 -0700 | [diff] [blame] | 4048 | void onActivityAddedToStack(ActivityRecord r) { |
| 4049 | if(r.getState() == RESUMED) { |
| 4050 | setResumedActivity(r, "onActivityAddedToStack"); |
| 4051 | } |
Bryce Lee | af691c0 | 2017-03-20 14:20:22 -0700 | [diff] [blame] | 4052 | } |
| 4053 | |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 4054 | /** |
| 4055 | * Perform the common clean-up of an activity record. This is called both |
| 4056 | * as part of destroyActivityLocked() (when destroying the client-side |
| 4057 | * representation) and cleaning things up as a result of its hosting |
| 4058 | * processing going away, in which case there is no remaining client-side |
| 4059 | * state to destroy so only the cleanup here is needed. |
Craig Mautner | acebdc8 | 2015-02-24 10:53:03 -0800 | [diff] [blame] | 4060 | * |
| 4061 | * Note: Call before #removeActivityFromHistoryLocked. |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 4062 | */ |
Bryce Lee | c940660 | 2018-03-09 11:02:10 -0800 | [diff] [blame] | 4063 | private void cleanUpActivityLocked(ActivityRecord r, boolean cleanServices, boolean setState) { |
Bryce Lee | af691c0 | 2017-03-20 14:20:22 -0700 | [diff] [blame] | 4064 | onActivityRemovedFromStack(r); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 4065 | |
Wale Ogunwale | f81c1d1 | 2016-01-12 12:20:18 -0800 | [diff] [blame] | 4066 | r.deferRelaunchUntilPaused = false; |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 4067 | r.frozenBeforeDestroy = false; |
| 4068 | |
Bryce Lee | c940660 | 2018-03-09 11:02:10 -0800 | [diff] [blame] | 4069 | if (setState) { |
Wale Ogunwale | 0fc365c | 2015-05-25 19:35:42 -0700 | [diff] [blame] | 4070 | 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] | 4071 | r.setState(DESTROYED, "cleanupActivityLocked"); |
Wale Ogunwale | 0fc365c | 2015-05-25 19:35:42 -0700 | [diff] [blame] | 4072 | 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] | 4073 | r.app = null; |
Dianne Hackborn | ce86ba8 | 2011-07-13 19:33:41 -0700 | [diff] [blame] | 4074 | } |
| 4075 | |
Bryce Lee | 4a19438 | 2017-04-04 14:32:48 -0700 | [diff] [blame] | 4076 | // Inform supervisor the activity has been removed. |
| 4077 | mStackSupervisor.cleanupActivity(r); |
| 4078 | |
Craig Mautner | 2420ead | 2013-04-01 17:13:20 -0700 | [diff] [blame] | 4079 | |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 4080 | // Remove any pending results. |
| 4081 | if (r.finishing && r.pendingResults != null) { |
| 4082 | for (WeakReference<PendingIntentRecord> apr : r.pendingResults) { |
| 4083 | PendingIntentRecord rec = apr.get(); |
| 4084 | if (rec != null) { |
| 4085 | mService.cancelIntentSenderLocked(rec, false); |
| 4086 | } |
| 4087 | } |
| 4088 | r.pendingResults = null; |
| 4089 | } |
| 4090 | |
| 4091 | if (cleanServices) { |
Craig Mautner | 2420ead | 2013-04-01 17:13:20 -0700 | [diff] [blame] | 4092 | cleanUpActivityServicesLocked(r); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 4093 | } |
| 4094 | |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 4095 | // Get rid of any pending idle timeouts. |
Dianne Hackborn | 42e620c | 2012-06-24 13:20:51 -0700 | [diff] [blame] | 4096 | removeTimeoutsForActivityLocked(r); |
Wale Ogunwale | 8fd7542 | 2016-06-24 14:20:37 -0700 | [diff] [blame] | 4097 | // Clean-up activities are no longer relaunching (e.g. app process died). Notify window |
| 4098 | // manager so it can update its bookkeeping. |
| 4099 | mWindowManager.notifyAppRelaunchesCleared(r.appToken); |
Dianne Hackborn | 42e620c | 2012-06-24 13:20:51 -0700 | [diff] [blame] | 4100 | } |
| 4101 | |
Winson Chung | 4dabf23 | 2017-01-25 13:25:22 -0800 | [diff] [blame] | 4102 | void removeTimeoutsForActivityLocked(ActivityRecord r) { |
Craig Mautner | f333327 | 2013-04-22 10:55:53 -0700 | [diff] [blame] | 4103 | mStackSupervisor.removeTimeoutsForActivityLocked(r); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 4104 | mHandler.removeMessages(PAUSE_TIMEOUT_MSG, r); |
Dianne Hackborn | 162bc0e | 2012-04-09 14:06:16 -0700 | [diff] [blame] | 4105 | mHandler.removeMessages(STOP_TIMEOUT_MSG, r); |
Dianne Hackborn | 0c5001d | 2011-04-12 18:16:08 -0700 | [diff] [blame] | 4106 | mHandler.removeMessages(DESTROY_TIMEOUT_MSG, r); |
Dianne Hackborn | 2a29b3a | 2012-03-15 15:48:38 -0700 | [diff] [blame] | 4107 | r.finishLaunchTickingLocked(); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 4108 | } |
| 4109 | |
Chong Zhang | bffd889 | 2016-08-08 11:16:06 -0700 | [diff] [blame] | 4110 | private void removeActivityFromHistoryLocked(ActivityRecord r, String reason) { |
Dianne Hackborn | cc5a055 | 2012-10-01 16:32:39 -0700 | [diff] [blame] | 4111 | finishActivityResultsLocked(r, Activity.RESULT_CANCELED, null); |
Wale Ogunwale | 7d70117 | 2015-03-11 15:36:30 -0700 | [diff] [blame] | 4112 | r.makeFinishingLocked(); |
Wale Ogunwale | 0fc365c | 2015-05-25 19:35:42 -0700 | [diff] [blame] | 4113 | if (DEBUG_ADD_REMOVE) Slog.i(TAG_ADD_REMOVE, |
| 4114 | "Removing activity " + r + " from stack callers=" + Debug.getCallers(5)); |
| 4115 | |
Dianne Hackborn | cc5a055 | 2012-10-01 16:32:39 -0700 | [diff] [blame] | 4116 | r.takeFromHistory(); |
| 4117 | removeTimeoutsForActivityLocked(r); |
Wale Ogunwale | 0fc365c | 2015-05-25 19:35:42 -0700 | [diff] [blame] | 4118 | if (DEBUG_STATES) Slog.v(TAG_STATES, |
| 4119 | "Moving to DESTROYED: " + r + " (removed from history)"); |
Bryce Lee | 7ace395 | 2018-02-16 14:34:32 -0800 | [diff] [blame] | 4120 | r.setState(DESTROYED, "removeActivityFromHistoryLocked"); |
Wale Ogunwale | 0fc365c | 2015-05-25 19:35:42 -0700 | [diff] [blame] | 4121 | 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] | 4122 | r.app = null; |
Wale Ogunwale | 26c0dfe | 2016-12-14 14:42:30 -0800 | [diff] [blame] | 4123 | r.removeWindowContainer(); |
Bryce Lee | af691c0 | 2017-03-20 14:20:22 -0700 | [diff] [blame] | 4124 | final TaskRecord task = r.getTask(); |
Bryce Lee | aa5e8c3 | 2017-03-01 16:01:06 -0800 | [diff] [blame] | 4125 | final boolean lastActivity = task != null ? task.removeActivity(r) : false; |
Winson Chung | 6954fc9 | 2017-03-24 16:22:12 -0700 | [diff] [blame] | 4126 | // If we are removing the last activity in the task, not including task overlay activities, |
| 4127 | // then fall through into the block below to remove the entire task itself |
| 4128 | final boolean onlyHasTaskOverlays = task != null |
| 4129 | ? task.onlyHasTaskOverlayActivities(false /* excludingFinishing */) : false; |
Bryce Lee | aa5e8c3 | 2017-03-01 16:01:06 -0800 | [diff] [blame] | 4130 | |
Winson Chung | 6954fc9 | 2017-03-24 16:22:12 -0700 | [diff] [blame] | 4131 | if (lastActivity || onlyHasTaskOverlays) { |
| 4132 | if (DEBUG_STACK) { |
| 4133 | Slog.i(TAG_STACK, |
| 4134 | "removeActivityFromHistoryLocked: last activity removed from " + this |
| 4135 | + " onlyHasTaskOverlays=" + onlyHasTaskOverlays); |
| 4136 | } |
| 4137 | |
Bryce Lee | d6d2675 | 2017-05-25 13:57:46 -0700 | [diff] [blame] | 4138 | // The following block can be executed multiple times if there is more than one overlay. |
| 4139 | // {@link ActivityStackSupervisor#removeTaskByIdLocked} handles this by reverse lookup |
| 4140 | // of the task by id and exiting early if not found. |
Winson Chung | e3c21e0 | 2017-04-11 18:02:17 -0700 | [diff] [blame] | 4141 | if (onlyHasTaskOverlays) { |
| 4142 | // When destroying a task, tell the supervisor to remove it so that any activity it |
| 4143 | // has can be cleaned up correctly. This is currently the only place where we remove |
| 4144 | // a task with the DESTROYING mode, so instead of passing the onlyHasTaskOverlays |
| 4145 | // state into removeTask(), we just clear the task here before the other residual |
| 4146 | // work. |
| 4147 | // TODO: If the callers to removeTask() changes such that we have multiple places |
| 4148 | // where we are destroying the task, move this back into removeTask() |
| 4149 | mStackSupervisor.removeTaskByIdLocked(task.taskId, false /* killProcess */, |
Winson Chung | 0ec2a35 | 2017-10-26 11:38:30 -0700 | [diff] [blame] | 4150 | !REMOVE_FROM_RECENTS, PAUSE_IMMEDIATELY, reason); |
Winson Chung | e3c21e0 | 2017-04-11 18:02:17 -0700 | [diff] [blame] | 4151 | } |
Bryce Lee | 1d93058 | 2017-05-01 08:35:24 -0700 | [diff] [blame] | 4152 | |
Bryce Lee | d6d2675 | 2017-05-25 13:57:46 -0700 | [diff] [blame] | 4153 | // We must keep the task around until all activities are destroyed. The following |
| 4154 | // statement will only execute once since overlays are also considered activities. |
Bryce Lee | 1d93058 | 2017-05-01 08:35:24 -0700 | [diff] [blame] | 4155 | if (lastActivity) { |
| 4156 | removeTask(task, reason, REMOVE_TASK_MODE_DESTROYING); |
| 4157 | } |
Craig Mautner | 312ba86 | 2014-02-10 17:55:01 -0800 | [diff] [blame] | 4158 | } |
Dianne Hackborn | cc5a055 | 2012-10-01 16:32:39 -0700 | [diff] [blame] | 4159 | cleanUpActivityServicesLocked(r); |
| 4160 | r.removeUriPermissionsLocked(); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 4161 | } |
Craig Mautner | dbcb31f | 2013-04-02 12:32:53 -0700 | [diff] [blame] | 4162 | |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 4163 | /** |
| 4164 | * Perform clean-up of service connections in an activity record. |
| 4165 | */ |
Andrii Kulian | 21713ac | 2016-10-12 22:05:05 -0700 | [diff] [blame] | 4166 | private void cleanUpActivityServicesLocked(ActivityRecord r) { |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 4167 | // Throw away any services that have been bound by this activity. |
| 4168 | if (r.connections != null) { |
| 4169 | Iterator<ConnectionRecord> it = r.connections.iterator(); |
| 4170 | while (it.hasNext()) { |
| 4171 | ConnectionRecord c = it.next(); |
Dianne Hackborn | 599db5c | 2012-08-03 19:28:48 -0700 | [diff] [blame] | 4172 | mService.mServices.removeConnectionLocked(c, null, r); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 4173 | } |
| 4174 | r.connections = null; |
| 4175 | } |
| 4176 | } |
Dianne Hackborn | 755c8bf | 2012-05-07 15:06:09 -0700 | [diff] [blame] | 4177 | |
Craig Mautner | ee2e45a | 2014-06-27 12:10:03 -0700 | [diff] [blame] | 4178 | final void scheduleDestroyActivities(ProcessRecord owner, String reason) { |
Dianne Hackborn | 755c8bf | 2012-05-07 15:06:09 -0700 | [diff] [blame] | 4179 | Message msg = mHandler.obtainMessage(DESTROY_ACTIVITIES_MSG); |
Craig Mautner | ee2e45a | 2014-06-27 12:10:03 -0700 | [diff] [blame] | 4180 | msg.obj = new ScheduleDestroyArgs(owner, reason); |
Dianne Hackborn | 755c8bf | 2012-05-07 15:06:09 -0700 | [diff] [blame] | 4181 | mHandler.sendMessage(msg); |
| 4182 | } |
| 4183 | |
Andrii Kulian | 21713ac | 2016-10-12 22:05:05 -0700 | [diff] [blame] | 4184 | private void destroyActivitiesLocked(ProcessRecord owner, String reason) { |
Dianne Hackborn | 755c8bf | 2012-05-07 15:06:09 -0700 | [diff] [blame] | 4185 | boolean lastIsOpaque = false; |
Dianne Hackborn | 42e620c | 2012-06-24 13:20:51 -0700 | [diff] [blame] | 4186 | boolean activityRemoved = false; |
Craig Mautner | d44711d | 2013-02-23 11:24:36 -0800 | [diff] [blame] | 4187 | for (int taskNdx = mTaskHistory.size() - 1; taskNdx >= 0; --taskNdx) { |
| 4188 | final ArrayList<ActivityRecord> activities = mTaskHistory.get(taskNdx).mActivities; |
| 4189 | for (int activityNdx = activities.size() - 1; activityNdx >= 0; --activityNdx) { |
| 4190 | final ActivityRecord r = activities.get(activityNdx); |
| 4191 | if (r.finishing) { |
| 4192 | continue; |
| 4193 | } |
| 4194 | if (r.fullscreen) { |
| 4195 | lastIsOpaque = true; |
| 4196 | } |
| 4197 | if (owner != null && r.app != owner) { |
| 4198 | continue; |
| 4199 | } |
| 4200 | if (!lastIsOpaque) { |
| 4201 | continue; |
| 4202 | } |
Dianne Hackborn | 89ad456 | 2014-08-24 16:45:38 -0700 | [diff] [blame] | 4203 | if (r.isDestroyable()) { |
Bryce Lee | 7ace395 | 2018-02-16 14:34:32 -0800 | [diff] [blame] | 4204 | if (DEBUG_SWITCH) Slog.v(TAG_SWITCH, "Destroying " + r |
| 4205 | + " in state " + r.getState() |
Craig Mautner | d44711d | 2013-02-23 11:24:36 -0800 | [diff] [blame] | 4206 | + " resumed=" + mResumedActivity |
Dianne Hackborn | 89ad456 | 2014-08-24 16:45:38 -0700 | [diff] [blame] | 4207 | + " pausing=" + mPausingActivity + " for reason " + reason); |
Craig Mautner | ee2e45a | 2014-06-27 12:10:03 -0700 | [diff] [blame] | 4208 | if (destroyActivityLocked(r, true, reason)) { |
Craig Mautner | d44711d | 2013-02-23 11:24:36 -0800 | [diff] [blame] | 4209 | activityRemoved = true; |
| 4210 | } |
Dianne Hackborn | 42e620c | 2012-06-24 13:20:51 -0700 | [diff] [blame] | 4211 | } |
Dianne Hackborn | ce86ba8 | 2011-07-13 19:33:41 -0700 | [diff] [blame] | 4212 | } |
| 4213 | } |
Dianne Hackborn | 42e620c | 2012-06-24 13:20:51 -0700 | [diff] [blame] | 4214 | if (activityRemoved) { |
Wale Ogunwale | d046a01 | 2015-12-24 13:05:59 -0800 | [diff] [blame] | 4215 | mStackSupervisor.resumeFocusedStackTopActivityLocked(); |
Dianne Hackborn | 42e620c | 2012-06-24 13:20:51 -0700 | [diff] [blame] | 4216 | } |
Dianne Hackborn | ce86ba8 | 2011-07-13 19:33:41 -0700 | [diff] [blame] | 4217 | } |
| 4218 | |
Dianne Hackborn | 89ad456 | 2014-08-24 16:45:38 -0700 | [diff] [blame] | 4219 | final boolean safelyDestroyActivityLocked(ActivityRecord r, String reason) { |
| 4220 | if (r.isDestroyable()) { |
Wale Ogunwale | ee006da | 2015-03-30 14:49:25 -0700 | [diff] [blame] | 4221 | if (DEBUG_SWITCH) Slog.v(TAG_SWITCH, |
Bryce Lee | 7ace395 | 2018-02-16 14:34:32 -0800 | [diff] [blame] | 4222 | "Destroying " + r + " in state " + r.getState() + " resumed=" + mResumedActivity |
Dianne Hackborn | 89ad456 | 2014-08-24 16:45:38 -0700 | [diff] [blame] | 4223 | + " pausing=" + mPausingActivity + " for reason " + reason); |
| 4224 | return destroyActivityLocked(r, true, reason); |
| 4225 | } |
| 4226 | return false; |
| 4227 | } |
| 4228 | |
| 4229 | final int releaseSomeActivitiesLocked(ProcessRecord app, ArraySet<TaskRecord> tasks, |
| 4230 | String reason) { |
| 4231 | // Iterate over tasks starting at the back (oldest) first. |
Wale Ogunwale | 0fc365c | 2015-05-25 19:35:42 -0700 | [diff] [blame] | 4232 | 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] | 4233 | int maxTasks = tasks.size() / 4; |
| 4234 | if (maxTasks < 1) { |
| 4235 | maxTasks = 1; |
| 4236 | } |
| 4237 | int numReleased = 0; |
| 4238 | for (int taskNdx = 0; taskNdx < mTaskHistory.size() && maxTasks > 0; taskNdx++) { |
| 4239 | final TaskRecord task = mTaskHistory.get(taskNdx); |
| 4240 | if (!tasks.contains(task)) { |
| 4241 | continue; |
| 4242 | } |
Wale Ogunwale | 0fc365c | 2015-05-25 19:35:42 -0700 | [diff] [blame] | 4243 | 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] | 4244 | int curNum = 0; |
| 4245 | final ArrayList<ActivityRecord> activities = task.mActivities; |
| 4246 | for (int actNdx = 0; actNdx < activities.size(); actNdx++) { |
| 4247 | final ActivityRecord activity = activities.get(actNdx); |
| 4248 | if (activity.app == app && activity.isDestroyable()) { |
Wale Ogunwale | 0fc365c | 2015-05-25 19:35:42 -0700 | [diff] [blame] | 4249 | if (DEBUG_RELEASE) Slog.v(TAG_RELEASE, "Destroying " + activity |
Bryce Lee | 7ace395 | 2018-02-16 14:34:32 -0800 | [diff] [blame] | 4250 | + " in state " + activity.getState() + " resumed=" + mResumedActivity |
Dianne Hackborn | 89ad456 | 2014-08-24 16:45:38 -0700 | [diff] [blame] | 4251 | + " pausing=" + mPausingActivity + " for reason " + reason); |
| 4252 | destroyActivityLocked(activity, true, reason); |
| 4253 | if (activities.get(actNdx) != activity) { |
| 4254 | // Was removed from list, back up so we don't miss the next one. |
| 4255 | actNdx--; |
| 4256 | } |
| 4257 | curNum++; |
| 4258 | } |
| 4259 | } |
| 4260 | if (curNum > 0) { |
| 4261 | numReleased += curNum; |
| 4262 | maxTasks--; |
| 4263 | if (mTaskHistory.get(taskNdx) != task) { |
| 4264 | // The entire task got removed, back up so we don't miss the next one. |
| 4265 | taskNdx--; |
| 4266 | } |
| 4267 | } |
| 4268 | } |
Wale Ogunwale | 0fc365c | 2015-05-25 19:35:42 -0700 | [diff] [blame] | 4269 | if (DEBUG_RELEASE) Slog.d(TAG_RELEASE, |
| 4270 | "Done releasing: did " + numReleased + " activities"); |
Dianne Hackborn | 89ad456 | 2014-08-24 16:45:38 -0700 | [diff] [blame] | 4271 | return numReleased; |
| 4272 | } |
| 4273 | |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 4274 | /** |
| 4275 | * Destroy the current CLIENT SIDE instance of an activity. This may be |
| 4276 | * called both when actually finishing an activity, or when performing |
| 4277 | * a configuration switch where we destroy the current client-side object |
| 4278 | * but then create a new client-side object for this same HistoryRecord. |
| 4279 | */ |
Craig Mautner | ee2e45a | 2014-06-27 12:10:03 -0700 | [diff] [blame] | 4280 | final boolean destroyActivityLocked(ActivityRecord r, boolean removeFromApp, String reason) { |
Wale Ogunwale | ee006da | 2015-03-30 14:49:25 -0700 | [diff] [blame] | 4281 | if (DEBUG_SWITCH || DEBUG_CLEANUP) Slog.v(TAG_SWITCH, |
| 4282 | "Removing activity from " + reason + ": token=" + r |
Filip Gruszczynski | a59ac9c | 2015-09-10 18:28:48 -0700 | [diff] [blame] | 4283 | + ", app=" + (r.app != null ? r.app.processName : "(null)")); |
Bryce Lee | b0f993f | 2018-03-02 15:38:01 -0800 | [diff] [blame] | 4284 | |
| 4285 | if (r.isState(DESTROYING, DESTROYED)) { |
Bryce Lee | c940660 | 2018-03-09 11:02:10 -0800 | [diff] [blame] | 4286 | if (DEBUG_STATES) Slog.v(TAG_STATES, "activity " + r + " already destroying." |
Bryce Lee | b0f993f | 2018-03-02 15:38:01 -0800 | [diff] [blame] | 4287 | + "skipping request with reason:" + reason); |
| 4288 | return false; |
| 4289 | } |
| 4290 | |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 4291 | EventLog.writeEvent(EventLogTags.AM_DESTROY_ACTIVITY, |
Dianne Hackborn | b12e135 | 2012-09-26 11:39:20 -0700 | [diff] [blame] | 4292 | r.userId, System.identityHashCode(r), |
Bryce Lee | af691c0 | 2017-03-20 14:20:22 -0700 | [diff] [blame] | 4293 | r.getTask().taskId, r.shortComponentName, reason); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 4294 | |
| 4295 | boolean removedFromHistory = false; |
Dianne Hackborn | cc5a055 | 2012-10-01 16:32:39 -0700 | [diff] [blame] | 4296 | |
Bryce Lee | c940660 | 2018-03-09 11:02:10 -0800 | [diff] [blame] | 4297 | cleanUpActivityLocked(r, false, false); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 4298 | |
| 4299 | final boolean hadApp = r.app != null; |
Dianne Hackborn | cc5a055 | 2012-10-01 16:32:39 -0700 | [diff] [blame] | 4300 | |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 4301 | if (hadApp) { |
| 4302 | if (removeFromApp) { |
Craig Mautner | d232895 | 2013-03-05 12:46:26 -0800 | [diff] [blame] | 4303 | r.app.activities.remove(r); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 4304 | if (mService.mHeavyWeightProcess == r.app && r.app.activities.size() <= 0) { |
| 4305 | mService.mHeavyWeightProcess = null; |
| 4306 | mService.mHandler.sendEmptyMessage( |
| 4307 | ActivityManagerService.CANCEL_HEAVY_NOTIFICATION_MSG); |
| 4308 | } |
Craig Mautner | c8143c6 | 2013-09-03 12:15:57 -0700 | [diff] [blame] | 4309 | if (r.app.activities.isEmpty()) { |
Dianne Hackborn | 465fa39 | 2014-09-14 14:21:18 -0700 | [diff] [blame] | 4310 | // Update any services we are bound to that might care about whether |
| 4311 | // their client may have activities. |
| 4312 | mService.mServices.updateServiceConnectionActivitiesLocked(r.app); |
Dianne Hackborn | 3bc8f78d | 2013-09-19 13:34:35 -0700 | [diff] [blame] | 4313 | // No longer have activities, so update LRU list and oom adj. |
Dianne Hackborn | db92608 | 2013-10-31 16:32:44 -0700 | [diff] [blame] | 4314 | mService.updateLruProcessLocked(r.app, false, null); |
Dianne Hackborn | 2d1b378 | 2012-09-09 17:49:39 -0700 | [diff] [blame] | 4315 | mService.updateOomAdjLocked(); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 4316 | } |
| 4317 | } |
| 4318 | |
| 4319 | boolean skipDestroy = false; |
Craig Mautner | dbcb31f | 2013-04-02 12:32:53 -0700 | [diff] [blame] | 4320 | |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 4321 | try { |
Wale Ogunwale | ee006da | 2015-03-30 14:49:25 -0700 | [diff] [blame] | 4322 | if (DEBUG_SWITCH) Slog.i(TAG_SWITCH, "Destroying: " + r); |
Bryce Lee | b0f993f | 2018-03-02 15:38:01 -0800 | [diff] [blame] | 4323 | mService.getLifecycleManager().scheduleTransaction(r.app.thread, r.appToken, |
Bryce Lee | 1d0d514 | 2018-04-12 10:35:07 -0700 | [diff] [blame] | 4324 | DestroyActivityItem.obtain(r.finishing, r.configChangeFlags)); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 4325 | } catch (Exception e) { |
| 4326 | // We can just ignore exceptions here... if the process |
| 4327 | // has crashed, our death notification will clean things |
| 4328 | // up. |
| 4329 | //Slog.w(TAG, "Exception thrown during finish", e); |
| 4330 | if (r.finishing) { |
Chong Zhang | bffd889 | 2016-08-08 11:16:06 -0700 | [diff] [blame] | 4331 | removeActivityFromHistoryLocked(r, reason + " exceptionInScheduleDestroy"); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 4332 | removedFromHistory = true; |
| 4333 | skipDestroy = true; |
| 4334 | } |
| 4335 | } |
| 4336 | |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 4337 | r.nowVisible = false; |
Craig Mautner | dbcb31f | 2013-04-02 12:32:53 -0700 | [diff] [blame] | 4338 | |
Dianne Hackborn | ce86ba8 | 2011-07-13 19:33:41 -0700 | [diff] [blame] | 4339 | // If the activity is finishing, we need to wait on removing it |
| 4340 | // from the list to give it a chance to do its cleanup. During |
| 4341 | // that time it may make calls back with its token so we need to |
| 4342 | // be able to find it on the list and so we don't want to remove |
| 4343 | // it from the list yet. Otherwise, we can just immediately put |
| 4344 | // it in the destroyed state since we are not removing it from the |
| 4345 | // list. |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 4346 | if (r.finishing && !skipDestroy) { |
Wale Ogunwale | 0fc365c | 2015-05-25 19:35:42 -0700 | [diff] [blame] | 4347 | if (DEBUG_STATES) Slog.v(TAG_STATES, "Moving to DESTROYING: " + r |
Dianne Hackborn | ce86ba8 | 2011-07-13 19:33:41 -0700 | [diff] [blame] | 4348 | + " (destroy requested)"); |
Bryce Lee | 7ace395 | 2018-02-16 14:34:32 -0800 | [diff] [blame] | 4349 | r.setState(DESTROYING, |
| 4350 | "destroyActivityLocked. finishing and not skipping destroy"); |
Craig Mautner | f7bfefb | 2013-05-16 17:30:44 -0700 | [diff] [blame] | 4351 | Message msg = mHandler.obtainMessage(DESTROY_TIMEOUT_MSG, r); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 4352 | mHandler.sendMessageDelayed(msg, DESTROY_TIMEOUT); |
| 4353 | } else { |
Wale Ogunwale | 0fc365c | 2015-05-25 19:35:42 -0700 | [diff] [blame] | 4354 | if (DEBUG_STATES) Slog.v(TAG_STATES, |
| 4355 | "Moving to DESTROYED: " + r + " (destroy skipped)"); |
Bryce Lee | 7ace395 | 2018-02-16 14:34:32 -0800 | [diff] [blame] | 4356 | r.setState(DESTROYED, |
| 4357 | "destroyActivityLocked. not finishing or skipping destroy"); |
Wale Ogunwale | 0fc365c | 2015-05-25 19:35:42 -0700 | [diff] [blame] | 4358 | 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] | 4359 | r.app = null; |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 4360 | } |
| 4361 | } else { |
| 4362 | // remove this record from the history. |
| 4363 | if (r.finishing) { |
Chong Zhang | bffd889 | 2016-08-08 11:16:06 -0700 | [diff] [blame] | 4364 | removeActivityFromHistoryLocked(r, reason + " hadNoApp"); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 4365 | removedFromHistory = true; |
| 4366 | } else { |
Wale Ogunwale | 0fc365c | 2015-05-25 19:35:42 -0700 | [diff] [blame] | 4367 | 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] | 4368 | r.setState(DESTROYED, "destroyActivityLocked. not finishing and had no app"); |
Wale Ogunwale | 0fc365c | 2015-05-25 19:35:42 -0700 | [diff] [blame] | 4369 | 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] | 4370 | r.app = null; |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 4371 | } |
| 4372 | } |
| 4373 | |
| 4374 | r.configChangeFlags = 0; |
Craig Mautner | dbcb31f | 2013-04-02 12:32:53 -0700 | [diff] [blame] | 4375 | |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 4376 | if (!mLRUActivities.remove(r) && hadApp) { |
| 4377 | Slog.w(TAG, "Activity " + r + " being finished, but not in LRU list"); |
| 4378 | } |
Craig Mautner | dbcb31f | 2013-04-02 12:32:53 -0700 | [diff] [blame] | 4379 | |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 4380 | return removedFromHistory; |
| 4381 | } |
| 4382 | |
Craig Mautner | 299f960 | 2015-01-26 09:47:33 -0800 | [diff] [blame] | 4383 | final void activityDestroyedLocked(IBinder token, String reason) { |
Craig Mautner | d232895 | 2013-03-05 12:46:26 -0800 | [diff] [blame] | 4384 | final long origId = Binder.clearCallingIdentity(); |
| 4385 | try { |
Bryce Lee | 7ace395 | 2018-02-16 14:34:32 -0800 | [diff] [blame] | 4386 | activityDestroyedLocked(ActivityRecord.forTokenLocked(token), reason); |
Craig Mautner | d232895 | 2013-03-05 12:46:26 -0800 | [diff] [blame] | 4387 | } finally { |
| 4388 | Binder.restoreCallingIdentity(origId); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 4389 | } |
| 4390 | } |
Craig Mautner | de4ef02 | 2013-04-07 19:01:33 -0700 | [diff] [blame] | 4391 | |
Bryce Lee | c940660 | 2018-03-09 11:02:10 -0800 | [diff] [blame] | 4392 | /** |
| 4393 | * This method is to only be called from the client via binder when the activity is destroyed |
| 4394 | * AND finished. |
| 4395 | */ |
Bryce Lee | 7ace395 | 2018-02-16 14:34:32 -0800 | [diff] [blame] | 4396 | final void activityDestroyedLocked(ActivityRecord record, String reason) { |
| 4397 | if (record != null) { |
| 4398 | mHandler.removeMessages(DESTROY_TIMEOUT_MSG, record); |
| 4399 | } |
| 4400 | |
| 4401 | if (DEBUG_CONTAINERS) Slog.d(TAG_CONTAINERS, "activityDestroyedLocked: r=" + record); |
| 4402 | |
| 4403 | if (isInStackLocked(record) != null) { |
| 4404 | if (record.isState(DESTROYING, DESTROYED)) { |
Bryce Lee | c940660 | 2018-03-09 11:02:10 -0800 | [diff] [blame] | 4405 | cleanUpActivityLocked(record, true, false); |
Bryce Lee | 7ace395 | 2018-02-16 14:34:32 -0800 | [diff] [blame] | 4406 | removeActivityFromHistoryLocked(record, reason); |
| 4407 | } |
| 4408 | } |
| 4409 | |
| 4410 | mStackSupervisor.resumeFocusedStackTopActivityLocked(); |
| 4411 | } |
| 4412 | |
Craig Mautner | 05d6272ba | 2013-02-11 09:39:27 -0800 | [diff] [blame] | 4413 | private void removeHistoryRecordsForAppLocked(ArrayList<ActivityRecord> list, |
| 4414 | ProcessRecord app, String listName) { |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 4415 | int i = list.size(); |
Wale Ogunwale | e23149f | 2015-03-06 15:39:44 -0800 | [diff] [blame] | 4416 | if (DEBUG_CLEANUP) Slog.v(TAG_CLEANUP, |
| 4417 | "Removing app " + app + " from list " + listName + " with " + i + " entries"); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 4418 | while (i > 0) { |
| 4419 | i--; |
Craig Mautner | 05d6272ba | 2013-02-11 09:39:27 -0800 | [diff] [blame] | 4420 | ActivityRecord r = list.get(i); |
Wale Ogunwale | e23149f | 2015-03-06 15:39:44 -0800 | [diff] [blame] | 4421 | if (DEBUG_CLEANUP) Slog.v(TAG_CLEANUP, "Record #" + i + " " + r); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 4422 | if (r.app == app) { |
Wale Ogunwale | e23149f | 2015-03-06 15:39:44 -0800 | [diff] [blame] | 4423 | if (DEBUG_CLEANUP) Slog.v(TAG_CLEANUP, "---> REMOVING this entry!"); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 4424 | list.remove(i); |
Dianne Hackborn | 42e620c | 2012-06-24 13:20:51 -0700 | [diff] [blame] | 4425 | removeTimeoutsForActivityLocked(r); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 4426 | } |
| 4427 | } |
| 4428 | } |
| 4429 | |
Andrii Kulian | 21713ac | 2016-10-12 22:05:05 -0700 | [diff] [blame] | 4430 | private boolean removeHistoryRecordsForAppLocked(ProcessRecord app) { |
Dianne Hackborn | cc5a055 | 2012-10-01 16:32:39 -0700 | [diff] [blame] | 4431 | removeHistoryRecordsForAppLocked(mLRUActivities, app, "mLRUActivities"); |
Craig Mautner | de4ef02 | 2013-04-07 19:01:33 -0700 | [diff] [blame] | 4432 | removeHistoryRecordsForAppLocked(mStackSupervisor.mStoppingActivities, app, |
| 4433 | "mStoppingActivities"); |
Craig Mautner | 0eea92c | 2013-05-16 13:35:39 -0700 | [diff] [blame] | 4434 | removeHistoryRecordsForAppLocked(mStackSupervisor.mGoingToSleepActivities, app, |
| 4435 | "mGoingToSleepActivities"); |
Bryce Lee | 4a19438 | 2017-04-04 14:32:48 -0700 | [diff] [blame] | 4436 | removeHistoryRecordsForAppLocked(mStackSupervisor.mActivitiesWaitingForVisibleActivity, app, |
| 4437 | "mActivitiesWaitingForVisibleActivity"); |
Craig Mautner | f333327 | 2013-04-22 10:55:53 -0700 | [diff] [blame] | 4438 | removeHistoryRecordsForAppLocked(mStackSupervisor.mFinishingActivities, app, |
| 4439 | "mFinishingActivities"); |
Dianne Hackborn | cc5a055 | 2012-10-01 16:32:39 -0700 | [diff] [blame] | 4440 | |
| 4441 | boolean hasVisibleActivities = false; |
| 4442 | |
| 4443 | // Clean out the history list. |
Craig Mautner | 0247fc8 | 2013-02-28 14:32:06 -0800 | [diff] [blame] | 4444 | int i = numActivities(); |
Wale Ogunwale | e23149f | 2015-03-06 15:39:44 -0800 | [diff] [blame] | 4445 | if (DEBUG_CLEANUP) Slog.v(TAG_CLEANUP, |
| 4446 | "Removing app " + app + " from history with " + i + " entries"); |
Craig Mautner | 0247fc8 | 2013-02-28 14:32:06 -0800 | [diff] [blame] | 4447 | for (int taskNdx = mTaskHistory.size() - 1; taskNdx >= 0; --taskNdx) { |
| 4448 | final ArrayList<ActivityRecord> activities = mTaskHistory.get(taskNdx).mActivities; |
Bryce Lee | fbd263b4 | 2018-03-07 10:33:55 -0800 | [diff] [blame] | 4449 | mTmpActivities.clear(); |
| 4450 | mTmpActivities.addAll(activities); |
| 4451 | |
| 4452 | while (!mTmpActivities.isEmpty()) { |
| 4453 | final int targetIndex = mTmpActivities.size() - 1; |
| 4454 | final ActivityRecord r = mTmpActivities.remove(targetIndex); |
Wale Ogunwale | e23149f | 2015-03-06 15:39:44 -0800 | [diff] [blame] | 4455 | if (DEBUG_CLEANUP) Slog.v(TAG_CLEANUP, |
Bryce Lee | fbd263b4 | 2018-03-07 10:33:55 -0800 | [diff] [blame] | 4456 | "Record #" + targetIndex + " " + r + ": app=" + r.app); |
| 4457 | |
Craig Mautner | 0247fc8 | 2013-02-28 14:32:06 -0800 | [diff] [blame] | 4458 | if (r.app == app) { |
riddle_hsu | 558e849 | 2015-04-02 16:43:13 +0800 | [diff] [blame] | 4459 | if (r.visible) { |
| 4460 | hasVisibleActivities = true; |
| 4461 | } |
Craig Mautner | acebdc8 | 2015-02-24 10:53:03 -0800 | [diff] [blame] | 4462 | final boolean remove; |
Craig Mautner | 0247fc8 | 2013-02-28 14:32:06 -0800 | [diff] [blame] | 4463 | if ((!r.haveState && !r.stateNotNeeded) || r.finishing) { |
| 4464 | // Don't currently have state for the activity, or |
| 4465 | // it is finishing -- always remove it. |
| 4466 | remove = true; |
Chong Zhang | 112eb8c | 2015-11-02 11:17:00 -0800 | [diff] [blame] | 4467 | } else if (!r.visible && r.launchCount > 2 && |
| 4468 | r.lastLaunchTime > (SystemClock.uptimeMillis() - 60000)) { |
Craig Mautner | 0247fc8 | 2013-02-28 14:32:06 -0800 | [diff] [blame] | 4469 | // We have launched this activity too many times since it was |
| 4470 | // able to run, so give up and remove it. |
Chong Zhang | 112eb8c | 2015-11-02 11:17:00 -0800 | [diff] [blame] | 4471 | // (Note if the activity is visible, we don't remove the record. |
| 4472 | // We leave the dead window on the screen but the process will |
| 4473 | // not be restarted unless user explicitly tap on it.) |
Craig Mautner | 0247fc8 | 2013-02-28 14:32:06 -0800 | [diff] [blame] | 4474 | remove = true; |
| 4475 | } else { |
| 4476 | // The process may be gone, but the activity lives on! |
| 4477 | remove = false; |
Dianne Hackborn | cc5a055 | 2012-10-01 16:32:39 -0700 | [diff] [blame] | 4478 | } |
Craig Mautner | 0247fc8 | 2013-02-28 14:32:06 -0800 | [diff] [blame] | 4479 | if (remove) { |
Wale Ogunwale | 0fc365c | 2015-05-25 19:35:42 -0700 | [diff] [blame] | 4480 | if (DEBUG_ADD_REMOVE || DEBUG_CLEANUP) Slog.i(TAG_ADD_REMOVE, |
| 4481 | "Removing activity " + r + " from stack at " + i |
| 4482 | + ": haveState=" + r.haveState |
| 4483 | + " stateNotNeeded=" + r.stateNotNeeded |
| 4484 | + " finishing=" + r.finishing |
Bryce Lee | 7ace395 | 2018-02-16 14:34:32 -0800 | [diff] [blame] | 4485 | + " state=" + r.getState() + " callers=" + Debug.getCallers(5)); |
Craig Mautner | 0247fc8 | 2013-02-28 14:32:06 -0800 | [diff] [blame] | 4486 | if (!r.finishing) { |
| 4487 | Slog.w(TAG, "Force removing " + r + ": app died, no saved state"); |
| 4488 | EventLog.writeEvent(EventLogTags.AM_FINISH_ACTIVITY, |
| 4489 | r.userId, System.identityHashCode(r), |
Bryce Lee | af691c0 | 2017-03-20 14:20:22 -0700 | [diff] [blame] | 4490 | r.getTask().taskId, r.shortComponentName, |
Craig Mautner | 0247fc8 | 2013-02-28 14:32:06 -0800 | [diff] [blame] | 4491 | "proc died without state saved"); |
Bryce Lee | 7ace395 | 2018-02-16 14:34:32 -0800 | [diff] [blame] | 4492 | if (r.getState() == RESUMED) { |
Jeff Sharkey | 5782da7 | 2013-04-25 14:32:30 -0700 | [diff] [blame] | 4493 | mService.updateUsageStats(r, false); |
| 4494 | } |
Craig Mautner | 0247fc8 | 2013-02-28 14:32:06 -0800 | [diff] [blame] | 4495 | } |
Craig Mautner | 0247fc8 | 2013-02-28 14:32:06 -0800 | [diff] [blame] | 4496 | } else { |
| 4497 | // We have the current state for this activity, so |
| 4498 | // it can be restarted later when needed. |
Wale Ogunwale | 0fc365c | 2015-05-25 19:35:42 -0700 | [diff] [blame] | 4499 | if (DEBUG_ALL) Slog.v(TAG, "Keeping entry, setting app to null"); |
| 4500 | if (DEBUG_APP) Slog.v(TAG_APP, |
| 4501 | "Clearing app during removeHistory for activity " + r); |
Craig Mautner | 0247fc8 | 2013-02-28 14:32:06 -0800 | [diff] [blame] | 4502 | r.app = null; |
Chong Zhang | 112eb8c | 2015-11-02 11:17:00 -0800 | [diff] [blame] | 4503 | // Set nowVisible to previous visible state. If the app was visible while |
| 4504 | // it died, we leave the dead window on screen so it's basically visible. |
| 4505 | // This is needed when user later tap on the dead window, we need to stop |
| 4506 | // other apps when user transfers focus to the restarted activity. |
| 4507 | r.nowVisible = r.visible; |
Craig Mautner | 0247fc8 | 2013-02-28 14:32:06 -0800 | [diff] [blame] | 4508 | if (!r.haveState) { |
Wale Ogunwale | 0fc365c | 2015-05-25 19:35:42 -0700 | [diff] [blame] | 4509 | if (DEBUG_SAVED_STATE) Slog.i(TAG_SAVED_STATE, |
Craig Mautner | 0247fc8 | 2013-02-28 14:32:06 -0800 | [diff] [blame] | 4510 | "App died, clearing saved state of " + r); |
| 4511 | r.icicle = null; |
| 4512 | } |
Dianne Hackborn | cc5a055 | 2012-10-01 16:32:39 -0700 | [diff] [blame] | 4513 | } |
Bryce Lee | c940660 | 2018-03-09 11:02:10 -0800 | [diff] [blame] | 4514 | cleanUpActivityLocked(r, true, true); |
Craig Mautner | acebdc8 | 2015-02-24 10:53:03 -0800 | [diff] [blame] | 4515 | if (remove) { |
Chong Zhang | bffd889 | 2016-08-08 11:16:06 -0700 | [diff] [blame] | 4516 | removeActivityFromHistoryLocked(r, "appDied"); |
Craig Mautner | acebdc8 | 2015-02-24 10:53:03 -0800 | [diff] [blame] | 4517 | } |
Craig Mautner | 0247fc8 | 2013-02-28 14:32:06 -0800 | [diff] [blame] | 4518 | } |
Dianne Hackborn | cc5a055 | 2012-10-01 16:32:39 -0700 | [diff] [blame] | 4519 | } |
| 4520 | } |
| 4521 | |
| 4522 | return hasVisibleActivities; |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 4523 | } |
Craig Mautner | 0247fc8 | 2013-02-28 14:32:06 -0800 | [diff] [blame] | 4524 | |
chaviw | 0d562bf | 2018-03-15 14:24:14 -0700 | [diff] [blame] | 4525 | private void updateTransitLocked(int transit, ActivityOptions options) { |
Dianne Hackborn | 7f58b95 | 2012-04-18 12:59:29 -0700 | [diff] [blame] | 4526 | if (options != null) { |
chaviw | 0d562bf | 2018-03-15 14:24:14 -0700 | [diff] [blame] | 4527 | ActivityRecord r = topRunningActivityLocked(); |
| 4528 | if (r != null && !r.isState(RESUMED)) { |
| 4529 | r.updateOptionsLocked(options); |
Dianne Hackborn | 7f58b95 | 2012-04-18 12:59:29 -0700 | [diff] [blame] | 4530 | } else { |
| 4531 | ActivityOptions.abort(options); |
| 4532 | } |
| 4533 | } |
Craig Mautner | ce5f3cb | 2013-04-22 08:58:54 -0700 | [diff] [blame] | 4534 | mWindowManager.prepareAppTransition(transit, false); |
Dianne Hackborn | 7f58b95 | 2012-04-18 12:59:29 -0700 | [diff] [blame] | 4535 | } |
Dianne Hackborn | 621e17d | 2010-11-22 15:59:56 -0800 | [diff] [blame] | 4536 | |
Andrii Kulian | 21713ac | 2016-10-12 22:05:05 -0700 | [diff] [blame] | 4537 | private void updateTaskMovement(TaskRecord task, boolean toFront) { |
Craig Mautner | 21d24a2 | 2014-04-23 11:45:37 -0700 | [diff] [blame] | 4538 | if (task.isPersistable) { |
| 4539 | task.mLastTimeMoved = System.currentTimeMillis(); |
| 4540 | // Sign is used to keep tasks sorted when persisted. Tasks sent to the bottom most |
| 4541 | // recently will be most negative, tasks sent to the bottom before that will be less |
| 4542 | // negative. Similarly for recent tasks moved to the top which will be most positive. |
| 4543 | if (!toFront) { |
| 4544 | task.mLastTimeMoved *= -1; |
| 4545 | } |
| 4546 | } |
Chong Zhang | fdcc4d4 | 2015-10-14 16:50:12 -0700 | [diff] [blame] | 4547 | mStackSupervisor.invalidateTaskLayers(); |
Craig Mautner | 21d24a2 | 2014-04-23 11:45:37 -0700 | [diff] [blame] | 4548 | } |
| 4549 | |
Matthew Ng | ae1ff4f | 2016-11-10 15:49:14 -0800 | [diff] [blame] | 4550 | void moveHomeStackTaskToTop() { |
Wale Ogunwale | 6fbde9f | 2017-08-24 07:24:12 -0700 | [diff] [blame] | 4551 | if (!isActivityTypeHome()) { |
| 4552 | throw new IllegalStateException("Calling moveHomeStackTaskToTop() on non-home stack: " |
| 4553 | + this); |
| 4554 | } |
Craig Mautner | a82aa09 | 2013-09-13 15:34:08 -0700 | [diff] [blame] | 4555 | final int top = mTaskHistory.size() - 1; |
Wale Ogunwale | 6fbde9f | 2017-08-24 07:24:12 -0700 | [diff] [blame] | 4556 | if (top >= 0) { |
| 4557 | final TaskRecord task = mTaskHistory.get(top); |
| 4558 | if (DEBUG_TASKS || DEBUG_STACK) Slog.d(TAG_STACK, |
| 4559 | "moveHomeStackTaskToTop: moving " + task); |
| 4560 | mTaskHistory.remove(top); |
| 4561 | mTaskHistory.add(top, task); |
| 4562 | updateTaskMovement(task, true); |
Craig Mautner | a82aa09 | 2013-09-13 15:34:08 -0700 | [diff] [blame] | 4563 | } |
| 4564 | } |
| 4565 | |
chaviw | 0d562bf | 2018-03-15 14:24:14 -0700 | [diff] [blame] | 4566 | final void moveTaskToFrontLocked(TaskRecord tr, boolean noAnimation, ActivityOptions options, |
| 4567 | AppTimeTracker timeTracker, String reason) { |
Wale Ogunwale | ee006da | 2015-03-30 14:49:25 -0700 | [diff] [blame] | 4568 | if (DEBUG_SWITCH) Slog.v(TAG_SWITCH, "moveTaskToFront: " + tr); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 4569 | |
Wale Ogunwale | a0f5b5e | 2017-10-11 09:37:23 -0700 | [diff] [blame] | 4570 | final ActivityStack topStack = getDisplay().getTopStack(); |
Wale Ogunwale | 30e441d | 2017-11-09 08:28:45 -0800 | [diff] [blame] | 4571 | final ActivityRecord topActivity = topStack != null ? topStack.getTopActivity() : null; |
Craig Mautner | 11bf9a5 | 2013-02-19 14:08:51 -0800 | [diff] [blame] | 4572 | final int numTasks = mTaskHistory.size(); |
| 4573 | final int index = mTaskHistory.indexOf(tr); |
Craig Mautner | 86d67a4 | 2013-05-14 10:34:38 -0700 | [diff] [blame] | 4574 | if (numTasks == 0 || index < 0) { |
Craig Mautner | 11bf9a5 | 2013-02-19 14:08:51 -0800 | [diff] [blame] | 4575 | // nothing to do! |
Craig Mautner | 8f5f7e9 | 2015-01-26 18:03:13 -0800 | [diff] [blame] | 4576 | if (noAnimation) { |
Craig Mautner | 11bf9a5 | 2013-02-19 14:08:51 -0800 | [diff] [blame] | 4577 | ActivityOptions.abort(options); |
| 4578 | } else { |
chaviw | 0d562bf | 2018-03-15 14:24:14 -0700 | [diff] [blame] | 4579 | updateTransitLocked(TRANSIT_TASK_TO_FRONT, options); |
Craig Mautner | 11bf9a5 | 2013-02-19 14:08:51 -0800 | [diff] [blame] | 4580 | } |
| 4581 | return; |
| 4582 | } |
| 4583 | |
Dianne Hackborn | b5a380d | 2015-05-20 18:18:46 -0700 | [diff] [blame] | 4584 | if (timeTracker != null) { |
| 4585 | // The caller wants a time tracker associated with this task. |
| 4586 | for (int i = tr.mActivities.size() - 1; i >= 0; i--) { |
| 4587 | tr.mActivities.get(i).appTimeTracker = timeTracker; |
| 4588 | } |
| 4589 | } |
| 4590 | |
Chavi Weingarten | 3a74855 | 2018-05-14 17:32:42 +0000 | [diff] [blame] | 4591 | try { |
| 4592 | // Defer updating the IME target since the new IME target will try to get computed |
| 4593 | // before updating all closing and opening apps, which can cause the ime target to |
| 4594 | // get calculated incorrectly. |
| 4595 | getDisplay().deferUpdateImeTarget(); |
Wale Ogunwale | d80c263 | 2015-03-13 10:26:26 -0700 | [diff] [blame] | 4596 | |
Chavi Weingarten | 3a74855 | 2018-05-14 17:32:42 +0000 | [diff] [blame] | 4597 | // Shift all activities with this task up to the top |
| 4598 | // of the stack, keeping them in the same internal order. |
| 4599 | insertTaskAtTop(tr, null); |
| 4600 | |
| 4601 | // Don't refocus if invisible to current user |
| 4602 | final ActivityRecord top = tr.getTopActivity(); |
| 4603 | if (top == null || !top.okToShowLocked()) { |
| 4604 | if (top != null) { |
| 4605 | mStackSupervisor.mRecentTasks.add(top.getTask()); |
| 4606 | } |
| 4607 | ActivityOptions.abort(options); |
| 4608 | return; |
Winson Chung | 1dbc811 | 2017-09-28 18:05:31 -0700 | [diff] [blame] | 4609 | } |
Chavi Weingarten | 9e875b6 | 2018-05-14 16:10:59 +0000 | [diff] [blame] | 4610 | |
Chavi Weingarten | 3a74855 | 2018-05-14 17:32:42 +0000 | [diff] [blame] | 4611 | // Set focus to the top running activity of this stack. |
| 4612 | final ActivityRecord r = topRunningActivityLocked(); |
| 4613 | mStackSupervisor.moveFocusableActivityStackToFrontLocked(r, reason); |
Chavi Weingarten | 9e875b6 | 2018-05-14 16:10:59 +0000 | [diff] [blame] | 4614 | |
Chavi Weingarten | 3a74855 | 2018-05-14 17:32:42 +0000 | [diff] [blame] | 4615 | if (DEBUG_TRANSITION) Slog.v(TAG_TRANSITION, "Prepare to front transition: task=" + tr); |
| 4616 | if (noAnimation) { |
| 4617 | mWindowManager.prepareAppTransition(TRANSIT_NONE, false); |
| 4618 | if (r != null) { |
| 4619 | mStackSupervisor.mNoAnimActivities.add(r); |
| 4620 | } |
| 4621 | ActivityOptions.abort(options); |
| 4622 | } else { |
| 4623 | updateTransitLocked(TRANSIT_TASK_TO_FRONT, options); |
Chavi Weingarten | 9e875b6 | 2018-05-14 16:10:59 +0000 | [diff] [blame] | 4624 | } |
Chavi Weingarten | 3a74855 | 2018-05-14 17:32:42 +0000 | [diff] [blame] | 4625 | // If a new task is moved to the front, then mark the existing top activity as |
| 4626 | // supporting |
Chavi Weingarten | 9e875b6 | 2018-05-14 16:10:59 +0000 | [diff] [blame] | 4627 | |
Chavi Weingarten | 3a74855 | 2018-05-14 17:32:42 +0000 | [diff] [blame] | 4628 | // picture-in-picture while paused only if the task would not be considered an oerlay |
| 4629 | // on top |
| 4630 | // of the current activity (eg. not fullscreen, or the assistant) |
| 4631 | if (canEnterPipOnTaskSwitch(topActivity, tr, null /* toFrontActivity */, |
| 4632 | options)) { |
| 4633 | topActivity.supportsEnterPipOnTaskSwitch = true; |
| 4634 | } |
Chavi Weingarten | 9e875b6 | 2018-05-14 16:10:59 +0000 | [diff] [blame] | 4635 | |
Chavi Weingarten | 3a74855 | 2018-05-14 17:32:42 +0000 | [diff] [blame] | 4636 | mStackSupervisor.resumeFocusedStackTopActivityLocked(); |
| 4637 | EventLog.writeEvent(EventLogTags.AM_TASK_TO_FRONT, tr.userId, tr.taskId); |
| 4638 | |
| 4639 | mService.mTaskChangeNotificationController.notifyTaskMovedToFront(tr.taskId); |
| 4640 | } finally { |
| 4641 | getDisplay().continueUpdateImeTarget(); |
| 4642 | } |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 4643 | } |
| 4644 | |
| 4645 | /** |
Craig Mautner | ce5f3cb | 2013-04-22 08:58:54 -0700 | [diff] [blame] | 4646 | * Worker method for rearranging history stack. Implements the function of moving all |
| 4647 | * 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] | 4648 | * bottom of the stack. |
Craig Mautner | ce5f3cb | 2013-04-22 08:58:54 -0700 | [diff] [blame] | 4649 | * |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 4650 | * If a watcher is installed, the action is preflighted and the watcher has an opportunity |
| 4651 | * to premeptively cancel the move. |
Craig Mautner | ce5f3cb | 2013-04-22 08:58:54 -0700 | [diff] [blame] | 4652 | * |
Craig Mautner | ae7ecab | 2013-09-18 11:48:14 -0700 | [diff] [blame] | 4653 | * @param taskId The taskId to collect and move to the bottom. |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 4654 | * @return Returns true if the move completed, false if not. |
| 4655 | */ |
Craig Mautner | 299f960 | 2015-01-26 09:47:33 -0800 | [diff] [blame] | 4656 | final boolean moveTaskToBackLocked(int taskId) { |
Craig Mautner | aea74a5 | 2014-03-08 14:23:10 -0800 | [diff] [blame] | 4657 | final TaskRecord tr = taskForIdLocked(taskId); |
| 4658 | if (tr == null) { |
| 4659 | Slog.i(TAG, "moveTaskToBack: bad taskId=" + taskId); |
| 4660 | return false; |
| 4661 | } |
Craig Mautner | aea74a5 | 2014-03-08 14:23:10 -0800 | [diff] [blame] | 4662 | Slog.i(TAG, "moveTaskToBack: " + tr); |
Winson Chung | 261c0f3 | 2017-03-07 16:54:31 -0800 | [diff] [blame] | 4663 | |
Charles He | ff9b4dff | 2017-09-22 10:18:37 +0100 | [diff] [blame] | 4664 | // In LockTask mode, moving a locked task to the back of the stack may expose unlocked |
| 4665 | // ones. Therefore we need to check if this operation is allowed. |
Bryce Lee | 2b8e037 | 2018-04-05 17:01:37 -0700 | [diff] [blame] | 4666 | if (!mService.getLockTaskController().canMoveTaskToBack(tr)) { |
Winson Chung | 261c0f3 | 2017-03-07 16:54:31 -0800 | [diff] [blame] | 4667 | return false; |
| 4668 | } |
Craig Mautner | b44de0d | 2013-02-21 20:00:58 -0800 | [diff] [blame] | 4669 | |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 4670 | // If we have a watcher, preflight the move before committing to it. First check |
| 4671 | // for *other* available tasks, but if none are available, then try again allowing the |
| 4672 | // current task to be selected. |
Wale Ogunwale | a0f5b5e | 2017-10-11 09:37:23 -0700 | [diff] [blame] | 4673 | if (isTopStackOnDisplay() && mService.mController != null) { |
Craig Mautner | ae7ecab | 2013-09-18 11:48:14 -0700 | [diff] [blame] | 4674 | ActivityRecord next = topRunningActivityLocked(null, taskId); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 4675 | if (next == null) { |
| 4676 | next = topRunningActivityLocked(null, 0); |
| 4677 | } |
| 4678 | if (next != null) { |
| 4679 | // ask watcher if this is allowed |
| 4680 | boolean moveOK = true; |
| 4681 | try { |
| 4682 | moveOK = mService.mController.activityResuming(next.packageName); |
| 4683 | } catch (RemoteException e) { |
| 4684 | mService.mController = null; |
Kenny Root | add5821 | 2013-05-07 09:47:34 -0700 | [diff] [blame] | 4685 | Watchdog.getInstance().setActivityController(null); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 4686 | } |
| 4687 | if (!moveOK) { |
| 4688 | return false; |
| 4689 | } |
| 4690 | } |
| 4691 | } |
| 4692 | |
Wale Ogunwale | ee006da | 2015-03-30 14:49:25 -0700 | [diff] [blame] | 4693 | 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] | 4694 | |
Wale Ogunwale | 66e1685 | 2017-10-19 13:35:52 -0700 | [diff] [blame] | 4695 | mTaskHistory.remove(tr); |
| 4696 | mTaskHistory.add(0, tr); |
| 4697 | updateTaskMovement(tr, false); |
Wale Ogunwale | 4270924 | 2015-08-11 13:54:42 -0700 | [diff] [blame] | 4698 | |
Wale Ogunwale | 66e1685 | 2017-10-19 13:35:52 -0700 | [diff] [blame] | 4699 | mWindowManager.prepareAppTransition(TRANSIT_TASK_TO_BACK, false); |
Evan Rosky | 9c44817 | 2017-11-02 14:19:27 -0700 | [diff] [blame] | 4700 | moveToBack("moveTaskToBackLocked", tr); |
Winson Chung | 261c0f3 | 2017-03-07 16:54:31 -0800 | [diff] [blame] | 4701 | |
Wale Ogunwale | 44f036f | 2017-09-29 05:09:09 -0700 | [diff] [blame] | 4702 | if (inPinnedWindowingMode()) { |
Wale Ogunwale | a0f5b5e | 2017-10-11 09:37:23 -0700 | [diff] [blame] | 4703 | mStackSupervisor.removeStack(this); |
Winson Chung | 261c0f3 | 2017-03-07 16:54:31 -0800 | [diff] [blame] | 4704 | return true; |
| 4705 | } |
| 4706 | |
Wale Ogunwale | d046a01 | 2015-12-24 13:05:59 -0800 | [diff] [blame] | 4707 | mStackSupervisor.resumeFocusedStackTopActivityLocked(); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 4708 | return true; |
| 4709 | } |
Dianne Hackborn | 15491c6 | 2012-09-19 10:59:14 -0700 | [diff] [blame] | 4710 | |
Andrii Kulian | 21713ac | 2016-10-12 22:05:05 -0700 | [diff] [blame] | 4711 | static void logStartActivity(int tag, ActivityRecord r, TaskRecord task) { |
Santos Cordon | 73ff7d8 | 2013-03-06 17:24:11 -0800 | [diff] [blame] | 4712 | final Uri data = r.intent.getData(); |
| 4713 | final String strData = data != null ? data.toSafeString() : null; |
| 4714 | |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 4715 | EventLog.writeEvent(tag, |
Dianne Hackborn | b12e135 | 2012-09-26 11:39:20 -0700 | [diff] [blame] | 4716 | r.userId, System.identityHashCode(r), task.taskId, |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 4717 | r.shortComponentName, r.intent.getAction(), |
Santos Cordon | 73ff7d8 | 2013-03-06 17:24:11 -0800 | [diff] [blame] | 4718 | r.intent.getType(), strData, r.intent.getFlags()); |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 4719 | } |
| 4720 | |
| 4721 | /** |
Wale Ogunwale | db0fa12 | 2016-05-16 15:12:03 -0700 | [diff] [blame] | 4722 | * Ensures all visible activities at or below the input activity have the right configuration. |
| 4723 | */ |
| 4724 | void ensureVisibleActivitiesConfigurationLocked(ActivityRecord start, boolean preserveWindow) { |
| 4725 | if (start == null || !start.visible) { |
| 4726 | return; |
| 4727 | } |
| 4728 | |
Bryce Lee | af691c0 | 2017-03-20 14:20:22 -0700 | [diff] [blame] | 4729 | final TaskRecord startTask = start.getTask(); |
Wale Ogunwale | db0fa12 | 2016-05-16 15:12:03 -0700 | [diff] [blame] | 4730 | boolean behindFullscreen = false; |
| 4731 | boolean updatedConfig = false; |
| 4732 | |
| 4733 | for (int taskIndex = mTaskHistory.indexOf(startTask); taskIndex >= 0; --taskIndex) { |
| 4734 | final TaskRecord task = mTaskHistory.get(taskIndex); |
| 4735 | final ArrayList<ActivityRecord> activities = task.mActivities; |
| 4736 | int activityIndex = |
Bryce Lee | af691c0 | 2017-03-20 14:20:22 -0700 | [diff] [blame] | 4737 | (start.getTask() == task) ? activities.indexOf(start) : activities.size() - 1; |
Wale Ogunwale | db0fa12 | 2016-05-16 15:12:03 -0700 | [diff] [blame] | 4738 | for (; activityIndex >= 0; --activityIndex) { |
| 4739 | final ActivityRecord r = activities.get(activityIndex); |
Wale Ogunwale | b6d75f3 | 2018-02-22 20:44:56 -0800 | [diff] [blame] | 4740 | updatedConfig |= r.ensureActivityConfiguration(0 /* globalChanges */, |
Andrii Kulian | 21713ac | 2016-10-12 22:05:05 -0700 | [diff] [blame] | 4741 | preserveWindow); |
Wale Ogunwale | db0fa12 | 2016-05-16 15:12:03 -0700 | [diff] [blame] | 4742 | if (r.fullscreen) { |
| 4743 | behindFullscreen = true; |
| 4744 | break; |
| 4745 | } |
| 4746 | } |
| 4747 | if (behindFullscreen) { |
| 4748 | break; |
| 4749 | } |
| 4750 | } |
| 4751 | if (updatedConfig) { |
Wale Ogunwale | 089586f | 2016-06-20 14:16:22 -0700 | [diff] [blame] | 4752 | // 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] | 4753 | // any activity. |
| 4754 | mStackSupervisor.resumeFocusedStackTopActivityLocked(); |
| 4755 | } |
| 4756 | } |
| 4757 | |
Wale Ogunwale | 1666e31 | 2016-12-16 11:27:18 -0800 | [diff] [blame] | 4758 | // TODO: Figure-out a way to consolidate with resize() method below. |
| 4759 | @Override |
| 4760 | public void requestResize(Rect bounds) { |
| 4761 | mService.resizeStack(mStackId, bounds, true /* allowResizeInDockedMode */, |
| 4762 | false /* preserveWindows */, false /* animate */, -1 /* animationDuration */); |
| 4763 | } |
Andrii Kulian | 1e32e02 | 2016-09-16 15:29:34 -0700 | [diff] [blame] | 4764 | |
Wale Ogunwale | 1666e31 | 2016-12-16 11:27:18 -0800 | [diff] [blame] | 4765 | // TODO: Can only be called from special methods in ActivityStackSupervisor. |
| 4766 | // Need to consolidate those calls points into this resize method so anyone can call directly. |
| 4767 | void resize(Rect bounds, Rect tempTaskBounds, Rect tempTaskInsetBounds) { |
Wale Ogunwale | 1666e31 | 2016-12-16 11:27:18 -0800 | [diff] [blame] | 4768 | if (!updateBoundsAllowed(bounds, tempTaskBounds, tempTaskInsetBounds)) { |
| 4769 | return; |
| 4770 | } |
| 4771 | |
| 4772 | // Update override configurations of all tasks in the stack. |
| 4773 | final Rect taskBounds = tempTaskBounds != null ? tempTaskBounds : bounds; |
Andrii Kulian | 1e32e02 | 2016-09-16 15:29:34 -0700 | [diff] [blame] | 4774 | final Rect insetBounds = tempTaskInsetBounds != null ? tempTaskInsetBounds : taskBounds; |
| 4775 | |
| 4776 | mTmpBounds.clear(); |
Andrii Kulian | 1e32e02 | 2016-09-16 15:29:34 -0700 | [diff] [blame] | 4777 | mTmpInsetBounds.clear(); |
| 4778 | |
chaviw | be43ac8 | 2018-04-04 15:14:49 -0700 | [diff] [blame] | 4779 | synchronized (mWindowManager.getWindowManagerLock()) { |
| 4780 | for (int i = mTaskHistory.size() - 1; i >= 0; i--) { |
| 4781 | final TaskRecord task = mTaskHistory.get(i); |
| 4782 | if (task.isResizeable()) { |
| 4783 | if (inFreeformWindowingMode()) { |
| 4784 | // TODO: Can be removed now since each freeform task is in its own stack. |
| 4785 | // For freeform stack we don't adjust the size of the tasks to match that |
| 4786 | // of the stack, but we do try to make sure the tasks are still contained |
| 4787 | // with the bounds of the stack. |
| 4788 | mTmpRect2.set(task.getOverrideBounds()); |
| 4789 | fitWithinBounds(mTmpRect2, bounds); |
| 4790 | task.updateOverrideConfiguration(mTmpRect2); |
| 4791 | } else { |
| 4792 | task.updateOverrideConfiguration(taskBounds, insetBounds); |
| 4793 | } |
| 4794 | } |
| 4795 | |
| 4796 | mTmpBounds.put(task.taskId, task.getOverrideBounds()); |
| 4797 | if (tempTaskInsetBounds != null) { |
| 4798 | mTmpInsetBounds.put(task.taskId, tempTaskInsetBounds); |
Andrii Kulian | 1e32e02 | 2016-09-16 15:29:34 -0700 | [diff] [blame] | 4799 | } |
| 4800 | } |
| 4801 | |
chaviw | be43ac8 | 2018-04-04 15:14:49 -0700 | [diff] [blame] | 4802 | mWindowContainerController.resize(bounds, mTmpBounds, mTmpInsetBounds); |
| 4803 | setBounds(bounds); |
Andrii Kulian | 1e32e02 | 2016-09-16 15:29:34 -0700 | [diff] [blame] | 4804 | } |
Andrii Kulian | 1e32e02 | 2016-09-16 15:29:34 -0700 | [diff] [blame] | 4805 | } |
| 4806 | |
Winson Chung | 15036ca | 2018-05-31 15:51:47 -0700 | [diff] [blame] | 4807 | void onPipAnimationEndResize() { |
| 4808 | mWindowContainerController.onPipAnimationEndResize(); |
| 4809 | } |
| 4810 | |
Andrii Kulian | 1e32e02 | 2016-09-16 15:29:34 -0700 | [diff] [blame] | 4811 | |
| 4812 | /** |
| 4813 | * Adjust bounds to stay within stack bounds. |
| 4814 | * |
| 4815 | * Since bounds might be outside of stack bounds, this method tries to move the bounds in a way |
| 4816 | * that keep them unchanged, but be contained within the stack bounds. |
| 4817 | * |
| 4818 | * @param bounds Bounds to be adjusted. |
| 4819 | * @param stackBounds Bounds within which the other bounds should remain. |
| 4820 | */ |
| 4821 | private static void fitWithinBounds(Rect bounds, Rect stackBounds) { |
Bryce Lee | f3c6a47 | 2017-11-14 14:53:06 -0800 | [diff] [blame] | 4822 | if (stackBounds == null || stackBounds.isEmpty() || stackBounds.contains(bounds)) { |
Andrii Kulian | 1e32e02 | 2016-09-16 15:29:34 -0700 | [diff] [blame] | 4823 | return; |
| 4824 | } |
| 4825 | |
| 4826 | if (bounds.left < stackBounds.left || bounds.right > stackBounds.right) { |
| 4827 | final int maxRight = stackBounds.right |
| 4828 | - (stackBounds.width() / FIT_WITHIN_BOUNDS_DIVIDER); |
| 4829 | int horizontalDiff = stackBounds.left - bounds.left; |
| 4830 | if ((horizontalDiff < 0 && bounds.left >= maxRight) |
| 4831 | || (bounds.left + horizontalDiff >= maxRight)) { |
| 4832 | horizontalDiff = maxRight - bounds.left; |
| 4833 | } |
| 4834 | bounds.left += horizontalDiff; |
| 4835 | bounds.right += horizontalDiff; |
| 4836 | } |
| 4837 | |
| 4838 | if (bounds.top < stackBounds.top || bounds.bottom > stackBounds.bottom) { |
| 4839 | final int maxBottom = stackBounds.bottom |
| 4840 | - (stackBounds.height() / FIT_WITHIN_BOUNDS_DIVIDER); |
| 4841 | int verticalDiff = stackBounds.top - bounds.top; |
| 4842 | if ((verticalDiff < 0 && bounds.top >= maxBottom) |
| 4843 | || (bounds.top + verticalDiff >= maxBottom)) { |
| 4844 | verticalDiff = maxBottom - bounds.top; |
| 4845 | } |
| 4846 | bounds.top += verticalDiff; |
| 4847 | bounds.bottom += verticalDiff; |
| 4848 | } |
| 4849 | } |
| 4850 | |
Craig Mautner | cae015f | 2013-02-08 14:31:27 -0800 | [diff] [blame] | 4851 | boolean willActivityBeVisibleLocked(IBinder token) { |
Craig Mautner | d44711d | 2013-02-23 11:24:36 -0800 | [diff] [blame] | 4852 | for (int taskNdx = mTaskHistory.size() - 1; taskNdx >= 0; --taskNdx) { |
| 4853 | final ArrayList<ActivityRecord> activities = mTaskHistory.get(taskNdx).mActivities; |
| 4854 | for (int activityNdx = activities.size() - 1; activityNdx >= 0; --activityNdx) { |
| 4855 | final ActivityRecord r = activities.get(activityNdx); |
| 4856 | if (r.appToken == token) { |
Craig Mautner | 34b73df | 2014-01-12 21:11:08 -0800 | [diff] [blame] | 4857 | return true; |
Craig Mautner | d44711d | 2013-02-23 11:24:36 -0800 | [diff] [blame] | 4858 | } |
| 4859 | if (r.fullscreen && !r.finishing) { |
| 4860 | return false; |
| 4861 | } |
Craig Mautner | cae015f | 2013-02-08 14:31:27 -0800 | [diff] [blame] | 4862 | } |
| 4863 | } |
Wale Ogunwale | 7d70117 | 2015-03-11 15:36:30 -0700 | [diff] [blame] | 4864 | final ActivityRecord r = ActivityRecord.forTokenLocked(token); |
Craig Mautner | 34b73df | 2014-01-12 21:11:08 -0800 | [diff] [blame] | 4865 | if (r == null) { |
| 4866 | return false; |
| 4867 | } |
| 4868 | if (r.finishing) Slog.e(TAG, "willActivityBeVisibleLocked: Returning false," |
| 4869 | + " would have returned true for r=" + r); |
| 4870 | return !r.finishing; |
Craig Mautner | cae015f | 2013-02-08 14:31:27 -0800 | [diff] [blame] | 4871 | } |
| 4872 | |
| 4873 | void closeSystemDialogsLocked() { |
Craig Mautner | d44711d | 2013-02-23 11:24:36 -0800 | [diff] [blame] | 4874 | for (int taskNdx = mTaskHistory.size() - 1; taskNdx >= 0; --taskNdx) { |
| 4875 | final ArrayList<ActivityRecord> activities = mTaskHistory.get(taskNdx).mActivities; |
| 4876 | for (int activityNdx = activities.size() - 1; activityNdx >= 0; --activityNdx) { |
| 4877 | final ActivityRecord r = activities.get(activityNdx); |
| 4878 | if ((r.info.flags&ActivityInfo.FLAG_FINISH_ON_CLOSE_SYSTEM_DIALOGS) != 0) { |
Craig Mautner | d232895 | 2013-03-05 12:46:26 -0800 | [diff] [blame] | 4879 | finishActivityLocked(r, Activity.RESULT_CANCELED, null, "close-sys", true); |
Craig Mautner | d44711d | 2013-02-23 11:24:36 -0800 | [diff] [blame] | 4880 | } |
Craig Mautner | cae015f | 2013-02-08 14:31:27 -0800 | [diff] [blame] | 4881 | } |
| 4882 | } |
| 4883 | } |
| 4884 | |
Wale Ogunwale | 540e123 | 2015-05-01 15:35:39 -0700 | [diff] [blame] | 4885 | boolean finishDisabledPackageActivitiesLocked(String packageName, Set<String> filterByClasses, |
| 4886 | boolean doit, boolean evenPersistent, int userId) { |
Craig Mautner | cae015f | 2013-02-08 14:31:27 -0800 | [diff] [blame] | 4887 | boolean didSomething = false; |
| 4888 | TaskRecord lastTask = null; |
Craig Mautner | 9d8a30d | 2014-07-07 17:26:20 +0000 | [diff] [blame] | 4889 | ComponentName homeActivity = null; |
Craig Mautner | 56f52db | 2013-02-25 10:03:01 -0800 | [diff] [blame] | 4890 | for (int taskNdx = mTaskHistory.size() - 1; taskNdx >= 0; --taskNdx) { |
| 4891 | final ArrayList<ActivityRecord> activities = mTaskHistory.get(taskNdx).mActivities; |
Bryce Lee | fbd263b4 | 2018-03-07 10:33:55 -0800 | [diff] [blame] | 4892 | mTmpActivities.clear(); |
| 4893 | mTmpActivities.addAll(activities); |
| 4894 | |
| 4895 | while (!mTmpActivities.isEmpty()) { |
| 4896 | ActivityRecord r = mTmpActivities.remove(0); |
Wale Ogunwale | 540e123 | 2015-05-01 15:35:39 -0700 | [diff] [blame] | 4897 | final boolean sameComponent = |
| 4898 | (r.packageName.equals(packageName) && (filterByClasses == null |
| 4899 | || filterByClasses.contains(r.realActivity.getClassName()))) |
| 4900 | || (packageName == null && r.userId == userId); |
Craig Mautner | 56f52db | 2013-02-25 10:03:01 -0800 | [diff] [blame] | 4901 | if ((userId == UserHandle.USER_ALL || r.userId == userId) |
Bryce Lee | af691c0 | 2017-03-20 14:20:22 -0700 | [diff] [blame] | 4902 | && (sameComponent || r.getTask() == lastTask) |
Craig Mautner | 56f52db | 2013-02-25 10:03:01 -0800 | [diff] [blame] | 4903 | && (r.app == null || evenPersistent || !r.app.persistent)) { |
| 4904 | if (!doit) { |
| 4905 | if (r.finishing) { |
| 4906 | // If this activity is just finishing, then it is not |
| 4907 | // interesting as far as something to stop. |
| 4908 | continue; |
| 4909 | } |
| 4910 | return true; |
Craig Mautner | cae015f | 2013-02-08 14:31:27 -0800 | [diff] [blame] | 4911 | } |
Wale Ogunwale | 6fbde9f | 2017-08-24 07:24:12 -0700 | [diff] [blame] | 4912 | if (r.isActivityTypeHome()) { |
Craig Mautner | 9d8a30d | 2014-07-07 17:26:20 +0000 | [diff] [blame] | 4913 | if (homeActivity != null && homeActivity.equals(r.realActivity)) { |
| 4914 | Slog.i(TAG, "Skip force-stop again " + r); |
| 4915 | continue; |
| 4916 | } else { |
| 4917 | homeActivity = r.realActivity; |
| 4918 | } |
| 4919 | } |
Craig Mautner | 56f52db | 2013-02-25 10:03:01 -0800 | [diff] [blame] | 4920 | didSomething = true; |
| 4921 | Slog.i(TAG, " Force finishing activity " + r); |
Wale Ogunwale | 540e123 | 2015-05-01 15:35:39 -0700 | [diff] [blame] | 4922 | if (sameComponent) { |
Craig Mautner | 56f52db | 2013-02-25 10:03:01 -0800 | [diff] [blame] | 4923 | if (r.app != null) { |
| 4924 | r.app.removed = true; |
| 4925 | } |
| 4926 | r.app = null; |
Craig Mautner | cae015f | 2013-02-08 14:31:27 -0800 | [diff] [blame] | 4927 | } |
Bryce Lee | af691c0 | 2017-03-20 14:20:22 -0700 | [diff] [blame] | 4928 | lastTask = r.getTask(); |
Bryce Lee | fbd263b4 | 2018-03-07 10:33:55 -0800 | [diff] [blame] | 4929 | finishActivityLocked(r, Activity.RESULT_CANCELED, null, "force-stop", |
| 4930 | true); |
Craig Mautner | cae015f | 2013-02-08 14:31:27 -0800 | [diff] [blame] | 4931 | } |
| 4932 | } |
| 4933 | } |
| 4934 | return didSomething; |
| 4935 | } |
| 4936 | |
Winson Chung | 61c9e5a | 2017-10-11 10:39:32 -0700 | [diff] [blame] | 4937 | /** |
| 4938 | * @return The set of running tasks through {@param tasksOut} that are available to the caller. |
| 4939 | * If {@param ignoreActivityType} or {@param ignoreWindowingMode} are not undefined, |
| 4940 | * then skip running tasks that match those types. |
| 4941 | */ |
| 4942 | void getRunningTasks(List<TaskRecord> tasksOut, @ActivityType int ignoreActivityType, |
| 4943 | @WindowingMode int ignoreWindowingMode, int callingUid, boolean allowed) { |
riddle_hsu | ddc7415 | 2015-04-07 11:30:09 +0800 | [diff] [blame] | 4944 | boolean focusedStack = mStackSupervisor.getFocusedStack() == this; |
| 4945 | boolean topTask = true; |
Craig Mautner | c0fd805 | 2013-09-19 11:20:17 -0700 | [diff] [blame] | 4946 | for (int taskNdx = mTaskHistory.size() - 1; taskNdx >= 0; --taskNdx) { |
Craig Mautner | aab647e | 2013-02-28 16:31:36 -0800 | [diff] [blame] | 4947 | final TaskRecord task = mTaskHistory.get(taskNdx); |
riddle_hsu | ddc7415 | 2015-04-07 11:30:09 +0800 | [diff] [blame] | 4948 | if (task.getTopActivity() == null) { |
Winson Chung | 61c9e5a | 2017-10-11 10:39:32 -0700 | [diff] [blame] | 4949 | // Skip if there are no activities in the task |
riddle_hsu | ddc7415 | 2015-04-07 11:30:09 +0800 | [diff] [blame] | 4950 | continue; |
| 4951 | } |
Wale Ogunwale | 6fbde9f | 2017-08-24 07:24:12 -0700 | [diff] [blame] | 4952 | if (!allowed && !task.isActivityTypeHome() && task.effectiveUid != callingUid) { |
Winson Chung | 61c9e5a | 2017-10-11 10:39:32 -0700 | [diff] [blame] | 4953 | // Skip if the caller can't fetch this task |
Dianne Hackborn | 0923328 | 2014-04-30 11:33:59 -0700 | [diff] [blame] | 4954 | continue; |
| 4955 | } |
Winson Chung | 61c9e5a | 2017-10-11 10:39:32 -0700 | [diff] [blame] | 4956 | if (ignoreActivityType != ACTIVITY_TYPE_UNDEFINED |
| 4957 | && task.getActivityType() == ignoreActivityType) { |
| 4958 | // Skip ignored activity type |
| 4959 | continue; |
Craig Mautner | aab647e | 2013-02-28 16:31:36 -0800 | [diff] [blame] | 4960 | } |
Winson Chung | 61c9e5a | 2017-10-11 10:39:32 -0700 | [diff] [blame] | 4961 | if (ignoreWindowingMode != WINDOWING_MODE_UNDEFINED |
| 4962 | && task.getWindowingMode() == ignoreWindowingMode) { |
| 4963 | // Skip ignored windowing mode |
| 4964 | continue; |
| 4965 | } |
riddle_hsu | ddc7415 | 2015-04-07 11:30:09 +0800 | [diff] [blame] | 4966 | if (focusedStack && topTask) { |
Winson Chung | 61c9e5a | 2017-10-11 10:39:32 -0700 | [diff] [blame] | 4967 | // For the focused stack top task, update the last stack active time so that it can |
| 4968 | // be used to determine the order of the tasks (it may not be set for newly created |
| 4969 | // tasks) |
| 4970 | task.lastActiveTime = SystemClock.elapsedRealtime(); |
riddle_hsu | ddc7415 | 2015-04-07 11:30:09 +0800 | [diff] [blame] | 4971 | topTask = false; |
| 4972 | } |
Winson Chung | 61c9e5a | 2017-10-11 10:39:32 -0700 | [diff] [blame] | 4973 | tasksOut.add(task); |
Craig Mautner | cae015f | 2013-02-08 14:31:27 -0800 | [diff] [blame] | 4974 | } |
Craig Mautner | cae015f | 2013-02-08 14:31:27 -0800 | [diff] [blame] | 4975 | } |
| 4976 | |
Andrii Kulian | 21713ac | 2016-10-12 22:05:05 -0700 | [diff] [blame] | 4977 | void unhandledBackLocked() { |
Craig Mautner | aab647e | 2013-02-28 16:31:36 -0800 | [diff] [blame] | 4978 | final int top = mTaskHistory.size() - 1; |
Wale Ogunwale | ee006da | 2015-03-30 14:49:25 -0700 | [diff] [blame] | 4979 | 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] | 4980 | if (top >= 0) { |
| 4981 | final ArrayList<ActivityRecord> activities = mTaskHistory.get(top).mActivities; |
| 4982 | int activityTop = activities.size() - 1; |
Dianne Hackborn | 354736e | 2016-08-22 17:00:05 -0700 | [diff] [blame] | 4983 | if (activityTop >= 0) { |
Craig Mautner | aab647e | 2013-02-28 16:31:36 -0800 | [diff] [blame] | 4984 | finishActivityLocked(activities.get(activityTop), Activity.RESULT_CANCELED, null, |
| 4985 | "unhandled-back", true); |
| 4986 | } |
Craig Mautner | cae015f | 2013-02-08 14:31:27 -0800 | [diff] [blame] | 4987 | } |
| 4988 | } |
| 4989 | |
Craig Mautner | 6b74cb5 | 2013-09-27 17:02:21 -0700 | [diff] [blame] | 4990 | /** |
| 4991 | * Reset local parameters because an app's activity died. |
| 4992 | * @param app The app of the activity that died. |
Craig Mautner | 1909125 | 2013-10-05 00:03:53 -0700 | [diff] [blame] | 4993 | * @return result from removeHistoryRecordsForAppLocked. |
Craig Mautner | 6b74cb5 | 2013-09-27 17:02:21 -0700 | [diff] [blame] | 4994 | */ |
| 4995 | boolean handleAppDiedLocked(ProcessRecord app) { |
Craig Mautner | e79d4268 | 2013-04-01 19:01:53 -0700 | [diff] [blame] | 4996 | if (mPausingActivity != null && mPausingActivity.app == app) { |
Wale Ogunwale | ee006da | 2015-03-30 14:49:25 -0700 | [diff] [blame] | 4997 | if (DEBUG_PAUSE || DEBUG_CLEANUP) Slog.v(TAG_PAUSE, |
Craig Mautner | e79d4268 | 2013-04-01 19:01:53 -0700 | [diff] [blame] | 4998 | "App died while pausing: " + mPausingActivity); |
| 4999 | mPausingActivity = null; |
| 5000 | } |
| 5001 | if (mLastPausedActivity != null && mLastPausedActivity.app == app) { |
| 5002 | mLastPausedActivity = null; |
Craig Mautner | 0f92274 | 2013-08-06 08:44:42 -0700 | [diff] [blame] | 5003 | mLastNoHistoryActivity = null; |
Craig Mautner | e79d4268 | 2013-04-01 19:01:53 -0700 | [diff] [blame] | 5004 | } |
| 5005 | |
Craig Mautner | 1909125 | 2013-10-05 00:03:53 -0700 | [diff] [blame] | 5006 | return removeHistoryRecordsForAppLocked(app); |
Craig Mautner | e79d4268 | 2013-04-01 19:01:53 -0700 | [diff] [blame] | 5007 | } |
| 5008 | |
Craig Mautner | cae015f | 2013-02-08 14:31:27 -0800 | [diff] [blame] | 5009 | void handleAppCrashLocked(ProcessRecord app) { |
Craig Mautner | d44711d | 2013-02-23 11:24:36 -0800 | [diff] [blame] | 5010 | for (int taskNdx = mTaskHistory.size() - 1; taskNdx >= 0; --taskNdx) { |
| 5011 | final ArrayList<ActivityRecord> activities = mTaskHistory.get(taskNdx).mActivities; |
| 5012 | for (int activityNdx = activities.size() - 1; activityNdx >= 0; --activityNdx) { |
| 5013 | final ActivityRecord r = activities.get(activityNdx); |
| 5014 | if (r.app == app) { |
| 5015 | Slog.w(TAG, " Force finishing activity " |
| 5016 | + r.intent.getComponent().flattenToShortString()); |
Craig Mautner | 8e5b133 | 2014-07-24 13:32:37 -0700 | [diff] [blame] | 5017 | // Force the destroy to skip right to removal. |
| 5018 | r.app = null; |
Adrian Roos | 9357721 | 2018-04-10 14:12:10 -0700 | [diff] [blame] | 5019 | mWindowManager.prepareAppTransition(TRANSIT_CRASHING_ACTIVITY_CLOSE, |
Jorim Jaggi | 9c52ebb | 2018-06-01 14:45:24 +0200 | [diff] [blame] | 5020 | false /* alwaysKeepCurrent */); |
Bryce Lee | f52974c | 2018-02-14 15:12:01 -0800 | [diff] [blame] | 5021 | finishCurrentActivityLocked(r, FINISH_IMMEDIATELY, false, |
| 5022 | "handleAppCrashedLocked"); |
Craig Mautner | d44711d | 2013-02-23 11:24:36 -0800 | [diff] [blame] | 5023 | } |
Craig Mautner | cae015f | 2013-02-08 14:31:27 -0800 | [diff] [blame] | 5024 | } |
| 5025 | } |
| 5026 | } |
| 5027 | |
Dianne Hackborn | 390517b | 2013-05-30 15:03:32 -0700 | [diff] [blame] | 5028 | boolean dumpActivitiesLocked(FileDescriptor fd, PrintWriter pw, boolean dumpAll, |
Wale Ogunwale | 34a5b57 | 2017-08-31 08:29:41 -0700 | [diff] [blame] | 5029 | boolean dumpClient, String dumpPackage, boolean needSep) { |
| 5030 | |
| 5031 | if (mTaskHistory.isEmpty()) { |
| 5032 | return false; |
| 5033 | } |
| 5034 | final String prefix = " "; |
Craig Mautner | aab647e | 2013-02-28 16:31:36 -0800 | [diff] [blame] | 5035 | for (int taskNdx = mTaskHistory.size() - 1; taskNdx >= 0; --taskNdx) { |
| 5036 | final TaskRecord task = mTaskHistory.get(taskNdx); |
Wale Ogunwale | 34a5b57 | 2017-08-31 08:29:41 -0700 | [diff] [blame] | 5037 | if (needSep) { |
| 5038 | pw.println(""); |
Dianne Hackborn | 7ad34e5 | 2013-06-05 18:41:45 -0700 | [diff] [blame] | 5039 | } |
Wale Ogunwale | 34a5b57 | 2017-08-31 08:29:41 -0700 | [diff] [blame] | 5040 | pw.println(prefix + "Task id #" + task.taskId); |
Bryce Lee | f3c6a47 | 2017-11-14 14:53:06 -0800 | [diff] [blame] | 5041 | pw.println(prefix + "mBounds=" + task.getOverrideBounds()); |
Wale Ogunwale | 34a5b57 | 2017-08-31 08:29:41 -0700 | [diff] [blame] | 5042 | pw.println(prefix + "mMinWidth=" + task.mMinWidth); |
| 5043 | pw.println(prefix + "mMinHeight=" + task.mMinHeight); |
| 5044 | pw.println(prefix + "mLastNonFullscreenBounds=" + task.mLastNonFullscreenBounds); |
| 5045 | pw.println(prefix + "* " + task); |
| 5046 | task.dump(pw, prefix + " "); |
| 5047 | ActivityStackSupervisor.dumpHistoryList(fd, pw, mTaskHistory.get(taskNdx).mActivities, |
| 5048 | prefix, "Hist", true, !dumpAll, dumpClient, dumpPackage, false, null, task); |
Craig Mautner | aab647e | 2013-02-28 16:31:36 -0800 | [diff] [blame] | 5049 | } |
Wale Ogunwale | 34a5b57 | 2017-08-31 08:29:41 -0700 | [diff] [blame] | 5050 | return true; |
Craig Mautner | cae015f | 2013-02-08 14:31:27 -0800 | [diff] [blame] | 5051 | } |
| 5052 | |
| 5053 | ArrayList<ActivityRecord> getDumpActivitiesLocked(String name) { |
Winson Chung | 6998bc4 | 2017-02-28 17:07:05 -0800 | [diff] [blame] | 5054 | ArrayList<ActivityRecord> activities = new ArrayList<>(); |
Craig Mautner | cae015f | 2013-02-08 14:31:27 -0800 | [diff] [blame] | 5055 | |
| 5056 | if ("all".equals(name)) { |
Craig Mautner | aab647e | 2013-02-28 16:31:36 -0800 | [diff] [blame] | 5057 | for (int taskNdx = mTaskHistory.size() - 1; taskNdx >= 0; --taskNdx) { |
| 5058 | activities.addAll(mTaskHistory.get(taskNdx).mActivities); |
Craig Mautner | cae015f | 2013-02-08 14:31:27 -0800 | [diff] [blame] | 5059 | } |
| 5060 | } else if ("top".equals(name)) { |
Craig Mautner | aab647e | 2013-02-28 16:31:36 -0800 | [diff] [blame] | 5061 | final int top = mTaskHistory.size() - 1; |
| 5062 | if (top >= 0) { |
| 5063 | final ArrayList<ActivityRecord> list = mTaskHistory.get(top).mActivities; |
| 5064 | int listTop = list.size() - 1; |
| 5065 | if (listTop >= 0) { |
| 5066 | activities.add(list.get(listTop)); |
| 5067 | } |
Craig Mautner | cae015f | 2013-02-08 14:31:27 -0800 | [diff] [blame] | 5068 | } |
| 5069 | } else { |
| 5070 | ItemMatcher matcher = new ItemMatcher(); |
| 5071 | matcher.build(name); |
| 5072 | |
Craig Mautner | aab647e | 2013-02-28 16:31:36 -0800 | [diff] [blame] | 5073 | for (int taskNdx = mTaskHistory.size() - 1; taskNdx >= 0; --taskNdx) { |
| 5074 | for (ActivityRecord r1 : mTaskHistory.get(taskNdx).mActivities) { |
| 5075 | if (matcher.match(r1, r1.intent.getComponent())) { |
| 5076 | activities.add(r1); |
| 5077 | } |
Craig Mautner | cae015f | 2013-02-08 14:31:27 -0800 | [diff] [blame] | 5078 | } |
| 5079 | } |
| 5080 | } |
| 5081 | |
| 5082 | return activities; |
| 5083 | } |
| 5084 | |
| 5085 | ActivityRecord restartPackage(String packageName) { |
Filip Gruszczynski | 3e85ba2 | 2015-10-05 22:48:30 -0700 | [diff] [blame] | 5086 | ActivityRecord starting = topRunningActivityLocked(); |
Craig Mautner | cae015f | 2013-02-08 14:31:27 -0800 | [diff] [blame] | 5087 | |
| 5088 | // All activities that came from the package must be |
| 5089 | // restarted as if there was a config change. |
Craig Mautner | aab647e | 2013-02-28 16:31:36 -0800 | [diff] [blame] | 5090 | for (int taskNdx = mTaskHistory.size() - 1; taskNdx >= 0; --taskNdx) { |
| 5091 | final ArrayList<ActivityRecord> activities = mTaskHistory.get(taskNdx).mActivities; |
| 5092 | for (int activityNdx = activities.size() - 1; activityNdx >= 0; --activityNdx) { |
| 5093 | final ActivityRecord a = activities.get(activityNdx); |
| 5094 | if (a.info.packageName.equals(packageName)) { |
| 5095 | a.forceNewConfig = true; |
| 5096 | if (starting != null && a == starting && a.visible) { |
| 5097 | a.startFreezingScreenLocked(starting.app, |
Filip Gruszczynski | 3c2db1d1 | 2016-01-06 17:39:14 -0800 | [diff] [blame] | 5098 | CONFIG_SCREEN_LAYOUT); |
Craig Mautner | aab647e | 2013-02-28 16:31:36 -0800 | [diff] [blame] | 5099 | } |
Craig Mautner | cae015f | 2013-02-08 14:31:27 -0800 | [diff] [blame] | 5100 | } |
| 5101 | } |
| 5102 | } |
| 5103 | |
| 5104 | return starting; |
| 5105 | } |
Craig Mautner | 5d9c7be | 2013-02-15 14:02:56 -0800 | [diff] [blame] | 5106 | |
Wale Ogunwale | 000957c | 2015-04-03 08:19:12 -0700 | [diff] [blame] | 5107 | /** |
| 5108 | * Removes the input task from this stack. |
| 5109 | * @param task to remove. |
| 5110 | * @param reason for removal. |
Wale Ogunwale | 06579d6 | 2016-04-30 15:29:06 -0700 | [diff] [blame] | 5111 | * @param mode task removal mode. Either {@link #REMOVE_TASK_MODE_DESTROYING}, |
| 5112 | * {@link #REMOVE_TASK_MODE_MOVING}, {@link #REMOVE_TASK_MODE_MOVING_TO_TOP}. |
Wale Ogunwale | 000957c | 2015-04-03 08:19:12 -0700 | [diff] [blame] | 5113 | */ |
Wale Ogunwale | 06579d6 | 2016-04-30 15:29:06 -0700 | [diff] [blame] | 5114 | void removeTask(TaskRecord task, String reason, int mode) { |
Bryce Lee | af691c0 | 2017-03-20 14:20:22 -0700 | [diff] [blame] | 5115 | for (ActivityRecord record : task.mActivities) { |
| 5116 | onActivityRemovedFromStack(record); |
Craig Mautner | 04a0ea6 | 2014-01-13 12:51:26 -0800 | [diff] [blame] | 5117 | } |
| 5118 | |
Bryce Lee | 2b8e037 | 2018-04-05 17:01:37 -0700 | [diff] [blame] | 5119 | final boolean removed = mTaskHistory.remove(task); |
| 5120 | |
| 5121 | if (removed) { |
| 5122 | EventLog.writeEvent(EventLogTags.AM_REMOVE_TASK, task.taskId, getStackId()); |
| 5123 | } |
| 5124 | |
Winson Chung | abb433b | 2017-03-24 09:35:42 -0700 | [diff] [blame] | 5125 | removeActivitiesFromLRUListLocked(task); |
Craig Mautner | 21d24a2 | 2014-04-23 11:45:37 -0700 | [diff] [blame] | 5126 | updateTaskMovement(task, true); |
Craig Mautner | 41db4a7 | 2014-05-07 17:20:56 -0700 | [diff] [blame] | 5127 | |
Wale Ogunwale | 06579d6 | 2016-04-30 15:29:06 -0700 | [diff] [blame] | 5128 | if (mode == REMOVE_TASK_MODE_DESTROYING && task.mActivities.isEmpty()) { |
Amith Yamasani | 0af6fa7 | 2016-01-17 15:36:19 -0800 | [diff] [blame] | 5129 | // TODO: VI what about activity? |
Craig Mautner | 41db4a7 | 2014-05-07 17:20:56 -0700 | [diff] [blame] | 5130 | final boolean isVoiceSession = task.voiceSession != null; |
| 5131 | if (isVoiceSession) { |
| 5132 | try { |
| 5133 | task.voiceSession.taskFinished(task.intent, task.taskId); |
| 5134 | } catch (RemoteException e) { |
| 5135 | } |
Dianne Hackborn | c03c916 | 2014-05-02 10:45:59 -0700 | [diff] [blame] | 5136 | } |
Craig Mautner | 41db4a7 | 2014-05-07 17:20:56 -0700 | [diff] [blame] | 5137 | if (task.autoRemoveFromRecents() || isVoiceSession) { |
| 5138 | // Task creator asked to remove this when done, or this task was a voice |
| 5139 | // interaction, so it should not remain on the recent tasks list. |
Winson Chung | 1dbc811 | 2017-09-28 18:05:31 -0700 | [diff] [blame] | 5140 | mStackSupervisor.mRecentTasks.remove(task); |
Craig Mautner | 41db4a7 | 2014-05-07 17:20:56 -0700 | [diff] [blame] | 5141 | } |
Bryce Lee | 840c566 | 2017-04-13 10:02:51 -0700 | [diff] [blame] | 5142 | |
| 5143 | task.removeWindowContainer(); |
Dianne Hackborn | 91097de | 2014-04-04 18:02:06 -0700 | [diff] [blame] | 5144 | } |
Craig Mautner | 04a0ea6 | 2014-01-13 12:51:26 -0800 | [diff] [blame] | 5145 | |
| 5146 | if (mTaskHistory.isEmpty()) { |
Wale Ogunwale | ee006da | 2015-03-30 14:49:25 -0700 | [diff] [blame] | 5147 | if (DEBUG_STACK) Slog.i(TAG_STACK, "removeTask: removing stack=" + this); |
Wale Ogunwale | 06579d6 | 2016-04-30 15:29:06 -0700 | [diff] [blame] | 5148 | // We only need to adjust focused stack if this stack is in focus and we are not in the |
| 5149 | // process of moving the task to the top of the stack that will be focused. |
| 5150 | if (isOnHomeDisplay() && mode != REMOVE_TASK_MODE_MOVING_TO_TOP |
| 5151 | && mStackSupervisor.isFocusedStack(this)) { |
Wale Ogunwale | d697cea | 2015-02-20 17:19:49 -0800 | [diff] [blame] | 5152 | String myReason = reason + " leftTaskHistoryEmpty"; |
Bryce Lee | f3c6a47 | 2017-11-14 14:53:06 -0800 | [diff] [blame] | 5153 | if (!inMultiWindowMode() || !adjustFocusToNextFocusableStack(myReason)) { |
Wale Ogunwale | 925d0d1 | 2015-09-23 15:40:07 -0700 | [diff] [blame] | 5154 | mStackSupervisor.moveHomeStackToFront(myReason); |
Wale Ogunwale | d697cea | 2015-02-20 17:19:49 -0800 | [diff] [blame] | 5155 | } |
Craig Mautner | 04a0ea6 | 2014-01-13 12:51:26 -0800 | [diff] [blame] | 5156 | } |
Wale Ogunwale | 9dcf946 | 2017-09-19 15:13:01 -0700 | [diff] [blame] | 5157 | if (isAttached()) { |
| 5158 | getDisplay().positionChildAtBottom(this); |
Craig Mautner | 593a4e6 | 2014-01-15 17:55:51 -0800 | [diff] [blame] | 5159 | } |
Wale Ogunwale | 388945c | 2017-10-04 12:13:46 -0700 | [diff] [blame] | 5160 | if (!isActivityTypeHome()) { |
Andrii Kulian | 94e82d9b0 | 2017-07-13 15:33:06 -0700 | [diff] [blame] | 5161 | remove(); |
Wale Ogunwale | 49853bf | 2015-02-23 09:24:42 -0800 | [diff] [blame] | 5162 | } |
Craig Mautner | 04a0ea6 | 2014-01-13 12:51:26 -0800 | [diff] [blame] | 5163 | } |
Wale Ogunwale | 04f4d6b | 2015-03-11 09:23:25 -0700 | [diff] [blame] | 5164 | |
Andrii Kulian | 02b7a83 | 2016-10-06 23:11:56 -0700 | [diff] [blame] | 5165 | task.setStack(null); |
Winson Chung | c81c0ce | 2017-03-17 12:27:30 -0700 | [diff] [blame] | 5166 | |
| 5167 | // 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] | 5168 | if (inPinnedWindowingMode()) { |
Winson Chung | c81c0ce | 2017-03-17 12:27:30 -0700 | [diff] [blame] | 5169 | mService.mTaskChangeNotificationController.notifyActivityUnpinned(); |
| 5170 | } |
Craig Mautner | 0247fc8 | 2013-02-28 14:32:06 -0800 | [diff] [blame] | 5171 | } |
| 5172 | |
Dianne Hackborn | 91097de | 2014-04-04 18:02:06 -0700 | [diff] [blame] | 5173 | TaskRecord createTaskRecord(int taskId, ActivityInfo info, Intent intent, |
| 5174 | IVoiceInteractionSession voiceSession, IVoiceInteractor voiceInteractor, |
Wale Ogunwale | 6fbde9f | 2017-08-24 07:24:12 -0700 | [diff] [blame] | 5175 | boolean toTop) { |
Bryce Lee | b802ea1 | 2017-11-15 21:25:03 -0800 | [diff] [blame] | 5176 | return createTaskRecord(taskId, info, intent, voiceSession, voiceInteractor, toTop, |
| 5177 | null /*activity*/, null /*source*/, null /*options*/); |
| 5178 | } |
| 5179 | |
| 5180 | TaskRecord createTaskRecord(int taskId, ActivityInfo info, Intent intent, |
| 5181 | IVoiceInteractionSession voiceSession, IVoiceInteractor voiceInteractor, |
| 5182 | boolean toTop, ActivityRecord activity, ActivityRecord source, |
| 5183 | ActivityOptions options) { |
Garfield Tan | 9b1efea | 2017-12-05 16:43:46 -0800 | [diff] [blame] | 5184 | final TaskRecord task = TaskRecord.create( |
| 5185 | mService, taskId, info, intent, voiceSession, voiceInteractor); |
Chong Zhang | 0fa656b | 2015-08-31 15:17:21 -0700 | [diff] [blame] | 5186 | // add the task to stack first, mTaskPositioner might need the stack association |
Wale Ogunwale | 5f98609 | 2015-12-04 15:35:38 -0800 | [diff] [blame] | 5187 | addTask(task, toTop, "createTaskRecord"); |
Lucas Dupin | 47a65c7 | 2018-02-15 14:16:18 -0800 | [diff] [blame] | 5188 | final int displayId = mDisplayId != INVALID_DISPLAY ? mDisplayId : DEFAULT_DISPLAY; |
Bryce Lee | 2a3cc46 | 2017-10-27 10:57:35 -0700 | [diff] [blame] | 5189 | final boolean isLockscreenShown = mService.mStackSupervisor.getKeyguardController() |
Lucas Dupin | 47a65c7 | 2018-02-15 14:16:18 -0800 | [diff] [blame] | 5190 | .isKeyguardOrAodShowing(displayId); |
Bryce Lee | ec55eb0 | 2017-12-05 20:51:27 -0800 | [diff] [blame] | 5191 | if (!mStackSupervisor.getLaunchParamsController() |
Bryce Lee | b802ea1 | 2017-11-15 21:25:03 -0800 | [diff] [blame] | 5192 | .layoutTask(task, info.windowLayout, activity, source, options) |
Bryce Lee | f3c6a47 | 2017-11-14 14:53:06 -0800 | [diff] [blame] | 5193 | && !matchParentBounds() && task.isResizeable() && !isLockscreenShown) { |
| 5194 | task.updateOverrideConfiguration(getOverrideBounds()); |
Filip Gruszczynski | e5390e7 | 2015-08-18 16:39:00 -0700 | [diff] [blame] | 5195 | } |
Wale Ogunwale | e1fe7fa2 | 2016-12-15 18:27:00 -0800 | [diff] [blame] | 5196 | task.createWindowContainer(toTop, (info.flags & FLAG_SHOW_FOR_ALL_USERS) != 0); |
Craig Mautner | 5d9c7be | 2013-02-15 14:02:56 -0800 | [diff] [blame] | 5197 | return task; |
| 5198 | } |
Craig Mautner | c00204b | 2013-03-05 15:02:14 -0800 | [diff] [blame] | 5199 | |
| 5200 | ArrayList<TaskRecord> getAllTasks() { |
Wale Ogunwale | 9d3de4c | 2015-02-01 16:49:44 -0800 | [diff] [blame] | 5201 | return new ArrayList<>(mTaskHistory); |
Craig Mautner | c00204b | 2013-03-05 15:02:14 -0800 | [diff] [blame] | 5202 | } |
| 5203 | |
Wale Ogunwale | 5f98609 | 2015-12-04 15:35:38 -0800 | [diff] [blame] | 5204 | void addTask(final TaskRecord task, final boolean toTop, String reason) { |
Winson Chung | 5af42fc | 2017-03-24 17:11:33 -0700 | [diff] [blame] | 5205 | addTask(task, toTop ? MAX_VALUE : 0, true /* schedulePictureInPictureModeChange */, reason); |
Wale Ogunwale | c5cc301 | 2017-01-13 13:26:16 -0800 | [diff] [blame] | 5206 | if (toTop) { |
| 5207 | // TODO: figure-out a way to remove this call. |
Wale Ogunwale | 1666e31 | 2016-12-16 11:27:18 -0800 | [diff] [blame] | 5208 | mWindowContainerController.positionChildAtTop(task.getWindowContainerController(), |
| 5209 | true /* includingParents */); |
Wale Ogunwale | c5cc301 | 2017-01-13 13:26:16 -0800 | [diff] [blame] | 5210 | } |
Wale Ogunwale | e1fe7fa2 | 2016-12-15 18:27:00 -0800 | [diff] [blame] | 5211 | } |
| 5212 | |
Wale Ogunwale | c5cc301 | 2017-01-13 13:26:16 -0800 | [diff] [blame] | 5213 | // TODO: This shouldn't allow automatic reparenting. Remove the call to preAddTask and deal |
| 5214 | // with the fall-out... |
Winson Chung | 5af42fc | 2017-03-24 17:11:33 -0700 | [diff] [blame] | 5215 | void addTask(final TaskRecord task, int position, boolean schedulePictureInPictureModeChange, |
| 5216 | String reason) { |
Wale Ogunwale | c5cc301 | 2017-01-13 13:26:16 -0800 | [diff] [blame] | 5217 | // TODO: Is this remove really needed? Need to look into the call path for the other addTask |
| 5218 | mTaskHistory.remove(task); |
| 5219 | position = getAdjustedPositionForTask(task, position, null /* starting */); |
| 5220 | final boolean toTop = position >= mTaskHistory.size(); |
Wale Ogunwale | 06579d6 | 2016-04-30 15:29:06 -0700 | [diff] [blame] | 5221 | final ActivityStack prevStack = preAddTask(task, reason, toTop); |
Wale Ogunwale | 5f98609 | 2015-12-04 15:35:38 -0800 | [diff] [blame] | 5222 | |
Andrii Kulian | fb1bf69 | 2017-01-17 11:17:34 -0800 | [diff] [blame] | 5223 | mTaskHistory.add(position, task); |
Andrii Kulian | 02b7a83 | 2016-10-06 23:11:56 -0700 | [diff] [blame] | 5224 | task.setStack(this); |
Wale Ogunwale | c5cc301 | 2017-01-13 13:26:16 -0800 | [diff] [blame] | 5225 | |
Wale Ogunwale | c5cc301 | 2017-01-13 13:26:16 -0800 | [diff] [blame] | 5226 | updateTaskMovement(task, toTop); |
| 5227 | |
Winson Chung | 5af42fc | 2017-03-24 17:11:33 -0700 | [diff] [blame] | 5228 | postAddTask(task, prevStack, schedulePictureInPictureModeChange); |
Craig Mautner | c00204b | 2013-03-05 15:02:14 -0800 | [diff] [blame] | 5229 | } |
| 5230 | |
Wale Ogunwale | c5cc301 | 2017-01-13 13:26:16 -0800 | [diff] [blame] | 5231 | void positionChildAt(TaskRecord task, int index) { |
| 5232 | |
| 5233 | if (task.getStack() != this) { |
| 5234 | throw new IllegalArgumentException("AS.positionChildAt: task=" + task |
| 5235 | + " is not a child of stack=" + this + " current parent=" + task.getStack()); |
Wale Ogunwale | e1fe7fa2 | 2016-12-15 18:27:00 -0800 | [diff] [blame] | 5236 | } |
| 5237 | |
| 5238 | task.updateOverrideConfigurationForStack(this); |
| 5239 | |
Jorim Jaggi | 023da53 | 2016-04-20 22:42:32 -0700 | [diff] [blame] | 5240 | final ActivityRecord topRunningActivity = task.topRunningActivityLocked(); |
Andrii Kulian | 02b7a83 | 2016-10-06 23:11:56 -0700 | [diff] [blame] | 5241 | final boolean wasResumed = topRunningActivity == task.getStack().mResumedActivity; |
Wale Ogunwale | e1fe7fa2 | 2016-12-15 18:27:00 -0800 | [diff] [blame] | 5242 | insertTaskAtPosition(task, index); |
Andrii Kulian | fb1bf69 | 2017-01-17 11:17:34 -0800 | [diff] [blame] | 5243 | task.setStack(this); |
Winson Chung | 5af42fc | 2017-03-24 17:11:33 -0700 | [diff] [blame] | 5244 | postAddTask(task, null /* prevStack */, true /* schedulePictureInPictureModeChange */); |
Wale Ogunwale | c5cc301 | 2017-01-13 13:26:16 -0800 | [diff] [blame] | 5245 | |
Jorim Jaggi | 023da53 | 2016-04-20 22:42:32 -0700 | [diff] [blame] | 5246 | if (wasResumed) { |
| 5247 | if (mResumedActivity != null) { |
| 5248 | Log.wtf(TAG, "mResumedActivity was already set when moving mResumedActivity from" |
| 5249 | + " other stack to this stack mResumedActivity=" + mResumedActivity |
| 5250 | + " other mResumedActivity=" + topRunningActivity); |
| 5251 | } |
Bryce Lee | c4ab62a | 2018-03-05 14:19:26 -0800 | [diff] [blame] | 5252 | topRunningActivity.setState(RESUMED, "positionChildAt"); |
Jorim Jaggi | 023da53 | 2016-04-20 22:42:32 -0700 | [diff] [blame] | 5253 | } |
Wale Ogunwale | e1fe7fa2 | 2016-12-15 18:27:00 -0800 | [diff] [blame] | 5254 | |
| 5255 | // The task might have already been running and its visibility needs to be synchronized with |
| 5256 | // the visibility of the stack / windows. |
| 5257 | ensureActivitiesVisibleLocked(null, 0, !PRESERVE_WINDOWS); |
| 5258 | mStackSupervisor.resumeFocusedStackTopActivityLocked(); |
Wale Ogunwale | 5f98609 | 2015-12-04 15:35:38 -0800 | [diff] [blame] | 5259 | } |
| 5260 | |
Wale Ogunwale | 06579d6 | 2016-04-30 15:29:06 -0700 | [diff] [blame] | 5261 | private ActivityStack preAddTask(TaskRecord task, String reason, boolean toTop) { |
Andrii Kulian | 02b7a83 | 2016-10-06 23:11:56 -0700 | [diff] [blame] | 5262 | final ActivityStack prevStack = task.getStack(); |
Wale Ogunwale | 5f98609 | 2015-12-04 15:35:38 -0800 | [diff] [blame] | 5263 | if (prevStack != null && prevStack != this) { |
Wale Ogunwale | 06579d6 | 2016-04-30 15:29:06 -0700 | [diff] [blame] | 5264 | prevStack.removeTask(task, reason, |
| 5265 | toTop ? REMOVE_TASK_MODE_MOVING_TO_TOP : REMOVE_TASK_MODE_MOVING); |
Wale Ogunwale | 5f98609 | 2015-12-04 15:35:38 -0800 | [diff] [blame] | 5266 | } |
| 5267 | return prevStack; |
| 5268 | } |
| 5269 | |
Winson Chung | 5af42fc | 2017-03-24 17:11:33 -0700 | [diff] [blame] | 5270 | /** |
| 5271 | * @param schedulePictureInPictureModeChange specifies whether or not to schedule the PiP mode |
| 5272 | * change. Callers may set this to false if they are explicitly scheduling PiP mode |
| 5273 | * changes themselves, like during the PiP animation |
| 5274 | */ |
| 5275 | private void postAddTask(TaskRecord task, ActivityStack prevStack, |
| 5276 | boolean schedulePictureInPictureModeChange) { |
| 5277 | if (schedulePictureInPictureModeChange && prevStack != null) { |
| 5278 | mStackSupervisor.scheduleUpdatePictureInPictureModeIfNeeded(task, prevStack); |
Wale Ogunwale | 5f98609 | 2015-12-04 15:35:38 -0800 | [diff] [blame] | 5279 | } else if (task.voiceSession != null) { |
Wale Ogunwale | ddc1cb2 | 2015-07-25 19:23:04 -0700 | [diff] [blame] | 5280 | try { |
| 5281 | task.voiceSession.taskStarted(task.intent, task.taskId); |
| 5282 | } catch (RemoteException e) { |
| 5283 | } |
| 5284 | } |
| 5285 | } |
| 5286 | |
Winson Chung | c2baac0 | 2017-01-11 13:34:47 -0800 | [diff] [blame] | 5287 | void moveToFrontAndResumeStateIfNeeded(ActivityRecord r, boolean moveToFront, boolean setResume, |
| 5288 | boolean setPause, String reason) { |
Wale Ogunwale | d046a01 | 2015-12-24 13:05:59 -0800 | [diff] [blame] | 5289 | if (!moveToFront) { |
| 5290 | return; |
Wale Ogunwale | 079a004 | 2015-10-24 11:44:07 -0700 | [diff] [blame] | 5291 | } |
Wale Ogunwale | d046a01 | 2015-12-24 13:05:59 -0800 | [diff] [blame] | 5292 | |
| 5293 | // If the activity owns the last resumed activity, transfer that together, |
| 5294 | // so that we don't resume the same activity again in the new stack. |
| 5295 | // Apps may depend on onResume()/onPause() being called in pairs. |
| 5296 | if (setResume) { |
Bryce Lee | c4ab62a | 2018-03-05 14:19:26 -0800 | [diff] [blame] | 5297 | r.setState(RESUMED, "moveToFrontAndResumeStateIfNeeded"); |
Winson Chung | abb433b | 2017-03-24 09:35:42 -0700 | [diff] [blame] | 5298 | updateLRUListLocked(r); |
Wale Ogunwale | d046a01 | 2015-12-24 13:05:59 -0800 | [diff] [blame] | 5299 | } |
Winson Chung | c2baac0 | 2017-01-11 13:34:47 -0800 | [diff] [blame] | 5300 | // If the activity was previously pausing, then ensure we transfer that as well |
| 5301 | if (setPause) { |
| 5302 | mPausingActivity = r; |
Winson Chung | 4dabf23 | 2017-01-25 13:25:22 -0800 | [diff] [blame] | 5303 | schedulePauseTimeout(r); |
Winson Chung | c2baac0 | 2017-01-11 13:34:47 -0800 | [diff] [blame] | 5304 | } |
Wale Ogunwale | d046a01 | 2015-12-24 13:05:59 -0800 | [diff] [blame] | 5305 | // Move the stack in which we are placing the activity to the front. The call will also |
| 5306 | // make sure the activity focus is set. |
| 5307 | moveToFront(reason); |
Wale Ogunwale | 079a004 | 2015-10-24 11:44:07 -0700 | [diff] [blame] | 5308 | } |
| 5309 | |
Craig Mautner | c00204b | 2013-03-05 15:02:14 -0800 | [diff] [blame] | 5310 | public int getStackId() { |
| 5311 | return mStackId; |
| 5312 | } |
Craig Mautner | de4ef02 | 2013-04-07 19:01:33 -0700 | [diff] [blame] | 5313 | |
| 5314 | @Override |
| 5315 | public String toString() { |
Dianne Hackborn | 2a272d4 | 2013-10-16 13:34:33 -0700 | [diff] [blame] | 5316 | return "ActivityStack{" + Integer.toHexString(System.identityHashCode(this)) |
Wale Ogunwale | 44f036f | 2017-09-29 05:09:09 -0700 | [diff] [blame] | 5317 | + " stackId=" + mStackId + " type=" + activityTypeToString(getActivityType()) |
Wale Ogunwale | 7e1f5f5 | 2017-10-18 15:19:59 -0700 | [diff] [blame] | 5318 | + " mode=" + windowingModeToString(getWindowingMode()) |
Wale Ogunwale | 8e923af | 2018-03-23 08:48:11 -0700 | [diff] [blame] | 5319 | + " visible=" + shouldBeVisible(null /* starting */) |
| 5320 | + " translucent=" + isStackTranslucent(null /* starting */) |
| 5321 | + ", " |
Wale Ogunwale | 44f036f | 2017-09-29 05:09:09 -0700 | [diff] [blame] | 5322 | + mTaskHistory.size() + " tasks}"; |
Craig Mautner | de4ef02 | 2013-04-07 19:01:33 -0700 | [diff] [blame] | 5323 | } |
Wale Ogunwale | 60454db | 2015-01-23 16:05:07 -0800 | [diff] [blame] | 5324 | |
Wale Ogunwale | a0f5b5e | 2017-10-11 09:37:23 -0700 | [diff] [blame] | 5325 | void onLockTaskPackagesUpdated() { |
Craig Mautner | 15df08a | 2015-04-01 12:17:18 -0700 | [diff] [blame] | 5326 | for (int taskNdx = mTaskHistory.size() - 1; taskNdx >= 0; --taskNdx) { |
| 5327 | mTaskHistory.get(taskNdx).setLockTaskAuth(); |
| 5328 | } |
| 5329 | } |
skuhne@google.com | 1b974dc | 2016-12-09 13:41:29 -0800 | [diff] [blame] | 5330 | |
| 5331 | void executeAppTransition(ActivityOptions options) { |
| 5332 | mWindowManager.executeAppTransition(); |
skuhne@google.com | 1b974dc | 2016-12-09 13:41:29 -0800 | [diff] [blame] | 5333 | ActivityOptions.abort(options); |
| 5334 | } |
David Stevens | 9440dc8 | 2017-03-16 19:00:20 -0700 | [diff] [blame] | 5335 | |
| 5336 | boolean shouldSleepActivities() { |
Wale Ogunwale | 9dcf946 | 2017-09-19 15:13:01 -0700 | [diff] [blame] | 5337 | final ActivityDisplay display = getDisplay(); |
Bryce Lee | 271617a | 2018-03-15 10:39:12 -0700 | [diff] [blame] | 5338 | |
| 5339 | // Do not sleep activities in this stack if we're marked as focused and the keyguard |
| 5340 | // is in the process of going away. |
| 5341 | if (mStackSupervisor.getFocusedStack() == this |
| 5342 | && mStackSupervisor.getKeyguardController().isKeyguardGoingAway()) { |
| 5343 | return false; |
| 5344 | } |
| 5345 | |
David Stevens | 9440dc8 | 2017-03-16 19:00:20 -0700 | [diff] [blame] | 5346 | return display != null ? display.isSleeping() : mService.isSleepingLocked(); |
| 5347 | } |
| 5348 | |
| 5349 | boolean shouldSleepOrShutDownActivities() { |
| 5350 | return shouldSleepActivities() || mService.isShuttingDownLocked(); |
| 5351 | } |
Steven Timotius | 4346f0a | 2017-09-12 11:07:21 -0700 | [diff] [blame] | 5352 | |
| 5353 | public void writeToProto(ProtoOutputStream proto, long fieldId) { |
| 5354 | final long token = proto.start(fieldId); |
Adrian Roos | 4921ccf | 2017-09-28 16:54:06 +0200 | [diff] [blame] | 5355 | super.writeToProto(proto, CONFIGURATION_CONTAINER, false /* trim */); |
Steven Timotius | 4346f0a | 2017-09-12 11:07:21 -0700 | [diff] [blame] | 5356 | proto.write(ID, mStackId); |
| 5357 | for (int taskNdx = mTaskHistory.size() - 1; taskNdx >= 0; --taskNdx) { |
| 5358 | final TaskRecord task = mTaskHistory.get(taskNdx); |
| 5359 | task.writeToProto(proto, TASKS); |
| 5360 | } |
| 5361 | if (mResumedActivity != null) { |
| 5362 | mResumedActivity.writeIdentifierToProto(proto, RESUMED_ACTIVITY); |
| 5363 | } |
| 5364 | proto.write(DISPLAY_ID, mDisplayId); |
Bryce Lee | f3c6a47 | 2017-11-14 14:53:06 -0800 | [diff] [blame] | 5365 | if (!matchParentBounds()) { |
| 5366 | final Rect bounds = getOverrideBounds(); |
| 5367 | bounds.writeToProto(proto, BOUNDS); |
Steven Timotius | 4346f0a | 2017-09-12 11:07:21 -0700 | [diff] [blame] | 5368 | } |
Bryce Lee | f3c6a47 | 2017-11-14 14:53:06 -0800 | [diff] [blame] | 5369 | |
| 5370 | // TODO: Remove, no longer needed with windowingMode. |
| 5371 | proto.write(FULLSCREEN, matchParentBounds()); |
Steven Timotius | 4346f0a | 2017-09-12 11:07:21 -0700 | [diff] [blame] | 5372 | proto.end(token); |
| 5373 | } |
Dianne Hackborn | 50dc3bc | 2010-06-25 10:05:59 -0700 | [diff] [blame] | 5374 | } |