Craig Mautner | 2708430 | 2013-03-25 08:05:25 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2013 The Android Open Source Project |
| 3 | * |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | * you may not use this file except in compliance with the License. |
| 6 | * You may obtain a copy of the License at |
| 7 | * |
| 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | * |
| 10 | * Unless required by applicable law or agreed to in writing, software |
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | * See the License for the specific language governing permissions and |
| 14 | * limitations under the License. |
| 15 | */ |
| 16 | |
Wale Ogunwale | 5950709 | 2018-10-29 09:00:30 -0700 | [diff] [blame] | 17 | package com.android.server.wm; |
Craig Mautner | 2708430 | 2013-03-25 08:05:25 -0700 | [diff] [blame] | 18 | |
Andrii Kulian | 3c9ad07 | 2017-08-01 11:45:22 -0700 | [diff] [blame] | 19 | import static android.Manifest.permission.ACTIVITY_EMBEDDING; |
Andrii Kulian | 3a95edc | 2017-06-28 16:21:07 -0700 | [diff] [blame] | 20 | import static android.Manifest.permission.INTERNAL_SYSTEM_WINDOW; |
Jorim Jaggi | fe76234 | 2016-10-13 14:33:27 +0200 | [diff] [blame] | 21 | import static android.Manifest.permission.START_ANY_ACTIVITY; |
Charles He | ff9b4dff | 2017-09-22 10:18:37 +0100 | [diff] [blame] | 22 | import static android.app.ActivityManager.LOCK_TASK_MODE_LOCKED; |
Bryce Lee | 5f0e28f | 2018-01-30 16:00:03 -0800 | [diff] [blame] | 23 | import static android.app.ActivityManager.START_DELIVERED_TO_TOP; |
Wale Ogunwale | 7056a06 | 2018-10-18 15:02:50 -0700 | [diff] [blame] | 24 | import static android.app.ActivityManager.START_FLAG_DEBUG; |
| 25 | import static android.app.ActivityManager.START_FLAG_NATIVE_DEBUGGING; |
| 26 | import static android.app.ActivityManager.START_FLAG_TRACK_ALLOCATION; |
Jorim Jaggi | fe76234 | 2016-10-13 14:33:27 +0200 | [diff] [blame] | 27 | import static android.app.ActivityManager.START_TASK_TO_FRONT; |
Wale Ogunwale | 65ebd95 | 2018-04-25 15:41:44 -0700 | [diff] [blame] | 28 | import static android.app.ActivityTaskManager.INVALID_STACK_ID; |
Louis Chang | 39ba54b | 2018-10-18 11:28:57 +0800 | [diff] [blame] | 29 | import static android.app.ActivityTaskManager.INVALID_TASK_ID; |
Andrii Kulian | 036e3ad | 2017-04-19 10:55:10 -0700 | [diff] [blame] | 30 | import static android.app.ITaskStackListener.FORCED_RESIZEABLE_REASON_SECONDARY_DISPLAY; |
| 31 | import static android.app.ITaskStackListener.FORCED_RESIZEABLE_REASON_SPLIT_SCREEN; |
Vishnu Nair | 132ee83 | 2018-09-28 15:00:05 -0700 | [diff] [blame] | 32 | import static android.app.WaitResult.INVALID_DELAY; |
Wale Ogunwale | 6827856 | 2017-09-23 17:13:55 -0700 | [diff] [blame] | 33 | import static android.app.WindowConfiguration.ACTIVITY_TYPE_ASSISTANT; |
Wale Ogunwale | 6fbde9f | 2017-08-24 07:24:12 -0700 | [diff] [blame] | 34 | import static android.app.WindowConfiguration.ACTIVITY_TYPE_HOME; |
Wale Ogunwale | 0568aed | 2017-09-08 13:29:37 -0700 | [diff] [blame] | 35 | import static android.app.WindowConfiguration.ACTIVITY_TYPE_RECENTS; |
Wale Ogunwale | 6fbde9f | 2017-08-24 07:24:12 -0700 | [diff] [blame] | 36 | import static android.app.WindowConfiguration.ACTIVITY_TYPE_STANDARD; |
| 37 | import static android.app.WindowConfiguration.ACTIVITY_TYPE_UNDEFINED; |
Wale Ogunwale | 0568aed | 2017-09-08 13:29:37 -0700 | [diff] [blame] | 38 | import static android.app.WindowConfiguration.WINDOWING_MODE_FREEFORM; |
Wale Ogunwale | 926aade | 2017-08-29 11:24:37 -0700 | [diff] [blame] | 39 | import static android.app.WindowConfiguration.WINDOWING_MODE_FULLSCREEN; |
Wale Ogunwale | 44f036f | 2017-09-29 05:09:09 -0700 | [diff] [blame] | 40 | import static android.app.WindowConfiguration.WINDOWING_MODE_FULLSCREEN_OR_SPLIT_SCREEN_SECONDARY; |
Wale Ogunwale | 0568aed | 2017-09-08 13:29:37 -0700 | [diff] [blame] | 41 | import static android.app.WindowConfiguration.WINDOWING_MODE_PINNED; |
| 42 | import static android.app.WindowConfiguration.WINDOWING_MODE_SPLIT_SCREEN_PRIMARY; |
Wale Ogunwale | 926aade | 2017-08-29 11:24:37 -0700 | [diff] [blame] | 43 | import static android.app.WindowConfiguration.WINDOWING_MODE_SPLIT_SCREEN_SECONDARY; |
Wale Ogunwale | 0568aed | 2017-09-08 13:29:37 -0700 | [diff] [blame] | 44 | import static android.app.WindowConfiguration.WINDOWING_MODE_UNDEFINED; |
Wale Ogunwale | 44f036f | 2017-09-29 05:09:09 -0700 | [diff] [blame] | 45 | import static android.app.WindowConfiguration.activityTypeToString; |
| 46 | import static android.app.WindowConfiguration.windowingModeToString; |
Louis Chang | 89f43fc | 2018-10-05 10:59:14 +0800 | [diff] [blame] | 47 | import static android.content.Intent.FLAG_ACTIVITY_NEW_TASK; |
Louis Chang | bd48dca | 2018-08-29 17:44:34 +0800 | [diff] [blame] | 48 | import static android.content.pm.ActivityInfo.LAUNCH_SINGLE_INSTANCE; |
| 49 | import static android.content.pm.ActivityInfo.LAUNCH_SINGLE_TASK; |
Wale Ogunwale | 214f348 | 2018-10-04 11:00:47 -0700 | [diff] [blame] | 50 | import static android.content.pm.PackageManager.NOTIFY_PACKAGE_USE_ACTIVITY; |
Andrii Kulian | 3c9ad07 | 2017-08-01 11:45:22 -0700 | [diff] [blame] | 51 | import static android.content.pm.PackageManager.PERMISSION_DENIED; |
Jorim Jaggi | fe76234 | 2016-10-13 14:33:27 +0200 | [diff] [blame] | 52 | import static android.content.pm.PackageManager.PERMISSION_GRANTED; |
Adrian Roos | a6d6aab | 2018-04-19 18:58:22 +0200 | [diff] [blame] | 53 | import static android.graphics.Rect.copyOrNull; |
chaviw | 59b9885 | 2017-06-13 12:05:44 -0700 | [diff] [blame] | 54 | import static android.os.PowerManager.PARTIAL_WAKE_LOCK; |
Benjamin Franz | a83859f | 2017-07-03 16:34:14 +0100 | [diff] [blame] | 55 | import static android.os.Process.SYSTEM_UID; |
Jorim Jaggi | fe76234 | 2016-10-13 14:33:27 +0200 | [diff] [blame] | 56 | import static android.os.Trace.TRACE_TAG_ACTIVITY_MANAGER; |
| 57 | import static android.view.Display.DEFAULT_DISPLAY; |
Andrii Kulian | 16802aa | 2016-11-02 12:21:33 -0700 | [diff] [blame] | 58 | import static android.view.Display.INVALID_DISPLAY; |
Andrii Kulian | 1cba31c | 2017-06-28 09:42:48 -0700 | [diff] [blame] | 59 | import static android.view.Display.TYPE_VIRTUAL; |
Louis Chang | 7d0037c | 2018-08-13 12:42:06 +0800 | [diff] [blame] | 60 | import static android.view.WindowManager.TRANSIT_DOCK_TASK_FROM_RECENTS; |
Louis Chang | ceeb506 | 2018-09-17 18:13:52 +0800 | [diff] [blame] | 61 | |
Louis Chang | 1eff248 | 2018-11-01 15:46:31 +0800 | [diff] [blame] | 62 | import static com.android.server.am.ActivityStackSupervisorProto.CONFIGURATION_CONTAINER; |
| 63 | import static com.android.server.am.ActivityStackSupervisorProto.DISPLAYS; |
| 64 | import static com.android.server.am.ActivityStackSupervisorProto.FOCUSED_STACK_ID; |
| 65 | import static com.android.server.am.ActivityStackSupervisorProto.IS_HOME_RECENTS_COMPONENT; |
| 66 | import static com.android.server.am.ActivityStackSupervisorProto.KEYGUARD_CONTROLLER; |
| 67 | import static com.android.server.am.ActivityStackSupervisorProto.PENDING_ACTIVITIES; |
| 68 | import static com.android.server.am.ActivityStackSupervisorProto.RESUMED_ACTIVITY; |
Wale Ogunwale | 5950709 | 2018-10-29 09:00:30 -0700 | [diff] [blame] | 69 | import static com.android.server.wm.ActivityStack.ActivityState.DESTROYED; |
| 70 | import static com.android.server.wm.ActivityStack.ActivityState.INITIALIZING; |
| 71 | import static com.android.server.wm.ActivityStack.ActivityState.PAUSED; |
| 72 | import static com.android.server.wm.ActivityStack.ActivityState.PAUSING; |
| 73 | import static com.android.server.wm.ActivityStack.ActivityState.RESUMED; |
| 74 | import static com.android.server.wm.ActivityStack.ActivityState.STOPPED; |
| 75 | import static com.android.server.wm.ActivityStack.ActivityState.STOPPING; |
| 76 | import static com.android.server.wm.ActivityStack.REMOVE_TASK_MODE_MOVING; |
Wale Ogunwale | 5950709 | 2018-10-29 09:00:30 -0700 | [diff] [blame] | 77 | import static com.android.server.wm.ActivityTaskManagerDebugConfig.DEBUG_ALL; |
| 78 | import static com.android.server.wm.ActivityTaskManagerDebugConfig.DEBUG_IDLE; |
| 79 | import static com.android.server.wm.ActivityTaskManagerDebugConfig.DEBUG_PAUSE; |
| 80 | import static com.android.server.wm.ActivityTaskManagerDebugConfig.DEBUG_RECENTS; |
| 81 | import static com.android.server.wm.ActivityTaskManagerDebugConfig.DEBUG_RELEASE; |
| 82 | import static com.android.server.wm.ActivityTaskManagerDebugConfig.DEBUG_STACK; |
| 83 | import static com.android.server.wm.ActivityTaskManagerDebugConfig.DEBUG_STATES; |
| 84 | import static com.android.server.wm.ActivityTaskManagerDebugConfig.DEBUG_SWITCH; |
| 85 | import static com.android.server.wm.ActivityTaskManagerDebugConfig.DEBUG_TASKS; |
| 86 | import static com.android.server.wm.ActivityTaskManagerDebugConfig.POSTFIX_IDLE; |
| 87 | import static com.android.server.wm.ActivityTaskManagerDebugConfig.POSTFIX_PAUSE; |
| 88 | import static com.android.server.wm.ActivityTaskManagerDebugConfig.POSTFIX_RECENTS; |
| 89 | import static com.android.server.wm.ActivityTaskManagerDebugConfig.POSTFIX_RELEASE; |
| 90 | import static com.android.server.wm.ActivityTaskManagerDebugConfig.POSTFIX_STACK; |
| 91 | import static com.android.server.wm.ActivityTaskManagerDebugConfig.POSTFIX_STATES; |
| 92 | import static com.android.server.wm.ActivityTaskManagerDebugConfig.POSTFIX_SWITCH; |
| 93 | import static com.android.server.wm.ActivityTaskManagerDebugConfig.POSTFIX_TASKS; |
| 94 | import static com.android.server.wm.ActivityTaskManagerDebugConfig.TAG_ATM; |
| 95 | import static com.android.server.wm.ActivityTaskManagerDebugConfig.TAG_WITH_CLASS_NAME; |
| 96 | import static com.android.server.wm.ActivityTaskManagerService.ANIMATE; |
| 97 | import static com.android.server.wm.ActivityTaskManagerService.H.FIRST_SUPERVISOR_STACK_MSG; |
| 98 | import static com.android.server.wm.ActivityTaskManagerService.RELAUNCH_REASON_NONE; |
| 99 | import static com.android.server.wm.TaskRecord.LOCK_TASK_AUTH_LAUNCHABLE; |
| 100 | import static com.android.server.wm.TaskRecord.LOCK_TASK_AUTH_LAUNCHABLE_PRIV; |
| 101 | import static com.android.server.wm.TaskRecord.LOCK_TASK_AUTH_WHITELISTED; |
| 102 | import static com.android.server.wm.TaskRecord.REPARENT_KEEP_STACK_AT_FRONT; |
| 103 | import static com.android.server.wm.TaskRecord.REPARENT_LEAVE_STACK_IN_PLACE; |
| 104 | import static com.android.server.wm.TaskRecord.REPARENT_MOVE_STACK_TO_FRONT; |
Louis Chang | ceeb506 | 2018-09-17 18:13:52 +0800 | [diff] [blame] | 105 | |
Wale Ogunwale | e1fe7fa2 | 2016-12-15 18:27:00 -0800 | [diff] [blame] | 106 | import static java.lang.Integer.MAX_VALUE; |
Jorim Jaggi | fe76234 | 2016-10-13 14:33:27 +0200 | [diff] [blame] | 107 | |
Svetoslav | 7008b51 | 2015-06-24 18:47:07 -0700 | [diff] [blame] | 108 | import android.Manifest; |
Winson Chung | 7900bee | 2017-03-10 08:59:25 -0800 | [diff] [blame] | 109 | import android.annotation.IntDef; |
Andrii Kulian | 16802aa | 2016-11-02 12:21:33 -0700 | [diff] [blame] | 110 | import android.annotation.NonNull; |
Wale Ogunwale | 0568aed | 2017-09-08 13:29:37 -0700 | [diff] [blame] | 111 | import android.annotation.Nullable; |
Tony Mak | 853304c | 2016-04-18 15:17:41 +0100 | [diff] [blame] | 112 | import android.annotation.UserIdInt; |
Craig Mautner | 2420ead | 2013-04-01 17:13:20 -0700 | [diff] [blame] | 113 | import android.app.Activity; |
Craig Mautner | 23ac33b | 2013-04-01 16:26:35 -0700 | [diff] [blame] | 114 | import android.app.ActivityManager; |
Filip Gruszczynski | 80e29f1 | 2015-12-14 14:58:30 -0800 | [diff] [blame] | 115 | import android.app.ActivityManager.RunningTaskInfo; |
Craig Mautner | ed6649f | 2013-12-02 14:08:25 -0800 | [diff] [blame] | 116 | import android.app.ActivityManager.StackInfo; |
Wale Ogunwale | 9e4f3e0 | 2018-05-17 09:35:39 -0700 | [diff] [blame] | 117 | import android.app.ActivityManagerInternal; |
Craig Mautner | 23ac33b | 2013-04-01 16:26:35 -0700 | [diff] [blame] | 118 | import android.app.ActivityOptions; |
Louis Chang | 89f43fc | 2018-10-05 10:59:14 +0800 | [diff] [blame] | 119 | import android.app.AppGlobals; |
Svetoslav | 7008b51 | 2015-06-24 18:47:07 -0700 | [diff] [blame] | 120 | import android.app.AppOpsManager; |
Jeff Hao | 1b012d3 | 2014-08-20 10:35:34 -0700 | [diff] [blame] | 121 | import android.app.ProfilerInfo; |
Craig Mautner | 2420ead | 2013-04-01 17:13:20 -0700 | [diff] [blame] | 122 | import android.app.ResultInfo; |
Sudheer Shanka | fc46e9b | 2016-10-21 17:55:27 -0700 | [diff] [blame] | 123 | import android.app.WaitResult; |
Winson Chung | 61c9e5a | 2017-10-11 10:39:32 -0700 | [diff] [blame] | 124 | import android.app.WindowConfiguration.ActivityType; |
| 125 | import android.app.WindowConfiguration.WindowingMode; |
Andrii Kulian | 88e05cb | 2017-12-05 17:21:10 -0800 | [diff] [blame] | 126 | import android.app.servertransaction.ActivityLifecycleItem; |
| 127 | import android.app.servertransaction.ClientTransaction; |
Andrii Kulian | 446e824 | 2017-10-26 15:17:29 -0700 | [diff] [blame] | 128 | import android.app.servertransaction.LaunchActivityItem; |
Andrii Kulian | 88e05cb | 2017-12-05 17:21:10 -0800 | [diff] [blame] | 129 | import android.app.servertransaction.PauseActivityItem; |
| 130 | import android.app.servertransaction.ResumeActivityItem; |
Craig Mautner | 23ac33b | 2013-04-01 16:26:35 -0700 | [diff] [blame] | 131 | import android.content.ComponentName; |
Craig Mautner | 2219a1b | 2013-03-25 09:44:30 -0700 | [diff] [blame] | 132 | import android.content.Context; |
| 133 | import android.content.Intent; |
| 134 | import android.content.pm.ActivityInfo; |
Craig Mautner | 23ac33b | 2013-04-01 16:26:35 -0700 | [diff] [blame] | 135 | import android.content.pm.ApplicationInfo; |
Svetoslav | 7008b51 | 2015-06-24 18:47:07 -0700 | [diff] [blame] | 136 | import android.content.pm.PackageInfo; |
Craig Mautner | 23ac33b | 2013-04-01 16:26:35 -0700 | [diff] [blame] | 137 | import android.content.pm.PackageManager; |
| 138 | import android.content.pm.ResolveInfo; |
Clara Bayarri | f7fea16 | 2015-10-22 16:09:52 +0100 | [diff] [blame] | 139 | import android.content.pm.UserInfo; |
Craig Mautner | 23ac33b | 2013-04-01 16:26:35 -0700 | [diff] [blame] | 140 | import android.content.res.Configuration; |
Garfield Tan | 4a48a7f | 2018-10-02 14:23:55 -0700 | [diff] [blame] | 141 | import android.content.res.Resources; |
Wale Ogunwale | 60454db | 2015-01-23 16:05:07 -0800 | [diff] [blame] | 142 | import android.graphics.Rect; |
Craig Mautner | 4a1cb22 | 2013-12-04 16:14:06 -0800 | [diff] [blame] | 143 | import android.hardware.display.DisplayManager; |
| 144 | import android.hardware.display.DisplayManager.DisplayListener; |
Andrii Kulian | fb1bf69 | 2017-01-17 11:17:34 -0800 | [diff] [blame] | 145 | import android.hardware.display.DisplayManagerInternal; |
Bryce Lee | d3624e1 | 2017-11-30 08:51:45 -0800 | [diff] [blame] | 146 | import android.hardware.power.V1_0.PowerHint; |
Craig Mautner | 23ac33b | 2013-04-01 16:26:35 -0700 | [diff] [blame] | 147 | import android.os.Binder; |
Jorim Jaggi | 0b46f3c | 2016-03-14 12:21:37 +0100 | [diff] [blame] | 148 | import android.os.Bundle; |
Craig Mautner | b59dcfd | 2013-05-06 13:12:58 -0700 | [diff] [blame] | 149 | import android.os.Debug; |
Louis Chang | 89f43fc | 2018-10-05 10:59:14 +0800 | [diff] [blame] | 150 | import android.os.FactoryTest; |
Craig Mautner | ce5f3cb | 2013-04-22 08:58:54 -0700 | [diff] [blame] | 151 | import android.os.Handler; |
Craig Mautner | 23ac33b | 2013-04-01 16:26:35 -0700 | [diff] [blame] | 152 | import android.os.IBinder; |
Craig Mautner | 2219a1b | 2013-03-25 09:44:30 -0700 | [diff] [blame] | 153 | import android.os.Looper; |
Craig Mautner | 2420ead | 2013-04-01 17:13:20 -0700 | [diff] [blame] | 154 | import android.os.Message; |
Craig Mautner | 0eea92c | 2013-05-16 13:35:39 -0700 | [diff] [blame] | 155 | import android.os.PowerManager; |
Craig Mautner | 7ea5bd4 | 2013-07-05 15:27:08 -0700 | [diff] [blame] | 156 | import android.os.Process; |
Craig Mautner | 8d341ef | 2013-03-26 09:03:27 -0700 | [diff] [blame] | 157 | import android.os.RemoteException; |
Craig Mautner | 23ac33b | 2013-04-01 16:26:35 -0700 | [diff] [blame] | 158 | import android.os.SystemClock; |
Wale Ogunwale | cad05a0 | 2015-09-25 10:41:44 -0700 | [diff] [blame] | 159 | import android.os.Trace; |
Craig Mautner | 6170f73 | 2013-04-02 13:05:23 -0700 | [diff] [blame] | 160 | import android.os.UserHandle; |
Clara Bayarri | f7fea16 | 2015-10-22 16:09:52 +0100 | [diff] [blame] | 161 | import android.os.UserManager; |
Dianne Hackborn | 3d07c94 | 2015-03-13 18:02:54 -0700 | [diff] [blame] | 162 | import android.os.WorkSource; |
Svetoslav | 7008b51 | 2015-06-24 18:47:07 -0700 | [diff] [blame] | 163 | import android.provider.MediaStore; |
Dianne Hackborn | 91097de | 2014-04-04 18:02:06 -0700 | [diff] [blame] | 164 | import android.service.voice.IVoiceInteractionSession; |
Svetoslav | 7008b51 | 2015-06-24 18:47:07 -0700 | [diff] [blame] | 165 | import android.util.ArrayMap; |
Dianne Hackborn | 89ad456 | 2014-08-24 16:45:38 -0700 | [diff] [blame] | 166 | import android.util.ArraySet; |
Garfield Tan | 4a48a7f | 2018-10-02 14:23:55 -0700 | [diff] [blame] | 167 | import android.util.DisplayMetrics; |
Craig Mautner | 2420ead | 2013-04-01 17:13:20 -0700 | [diff] [blame] | 168 | import android.util.EventLog; |
Andrii Kulian | fb1bf69 | 2017-01-17 11:17:34 -0800 | [diff] [blame] | 169 | import android.util.IntArray; |
Wale Ogunwale | e610d3d | 2017-04-25 10:23:48 -0700 | [diff] [blame] | 170 | import android.util.MergedConfiguration; |
Craig Mautner | 8d341ef | 2013-03-26 09:03:27 -0700 | [diff] [blame] | 171 | import android.util.Slog; |
Craig Mautner | 4a1cb22 | 2013-12-04 16:14:06 -0800 | [diff] [blame] | 172 | import android.util.SparseArray; |
Craig Mautner | 4a1cb22 | 2013-12-04 16:14:06 -0800 | [diff] [blame] | 173 | import android.util.SparseIntArray; |
David Stevens | 9440dc8 | 2017-03-16 19:00:20 -0700 | [diff] [blame] | 174 | import android.util.TimeUtils; |
Steven Timotius | 4346f0a | 2017-09-12 11:07:21 -0700 | [diff] [blame] | 175 | import android.util.proto.ProtoOutputStream; |
Craig Mautner | ed6649f | 2013-12-02 14:08:25 -0800 | [diff] [blame] | 176 | import android.view.Display; |
Chong Zhang | b15758a | 2015-11-17 12:12:03 -0800 | [diff] [blame] | 177 | |
Andreas Gampe | a36dc62 | 2018-02-05 17:19:22 -0800 | [diff] [blame] | 178 | import com.android.internal.annotations.GuardedBy; |
Andrii Kulian | 94e82d9b0 | 2017-07-13 15:33:06 -0700 | [diff] [blame] | 179 | import com.android.internal.annotations.VisibleForTesting; |
Dianne Hackborn | 85d558c | 2014-11-04 10:31:54 -0800 | [diff] [blame] | 180 | import com.android.internal.content.ReferrerIntent; |
Dianne Hackborn | cbfd23e | 2013-06-11 14:26:53 -0700 | [diff] [blame] | 181 | import com.android.internal.os.TransferPipe; |
Louis Chang | 7d0037c | 2018-08-13 12:42:06 +0800 | [diff] [blame] | 182 | import com.android.internal.os.logging.MetricsLoggerWrapper; |
Svetoslav | 7008b51 | 2015-06-24 18:47:07 -0700 | [diff] [blame] | 183 | import com.android.internal.util.ArrayUtils; |
Louis Chang | 7d0037c | 2018-08-13 12:42:06 +0800 | [diff] [blame] | 184 | import com.android.internal.util.function.pooled.PooledLambda; |
Jeff Brown | ca9bc70 | 2014-02-11 14:32:56 -0800 | [diff] [blame] | 185 | import com.android.server.LocalServices; |
Wale Ogunwale | 5950709 | 2018-10-29 09:00:30 -0700 | [diff] [blame] | 186 | import com.android.server.am.ActivityManagerService; |
| 187 | import com.android.server.am.AppTimeTracker; |
| 188 | import com.android.server.am.EventLogTags; |
| 189 | import com.android.server.am.UserState; |
| 190 | import com.android.server.wm.ActivityStack.ActivityState; |
Louis Chang | 7d0037c | 2018-08-13 12:42:06 +0800 | [diff] [blame] | 191 | import com.android.server.wm.ActivityTaskManagerInternal.SleepToken; |
Craig Mautner | 23ac33b | 2013-04-01 16:26:35 -0700 | [diff] [blame] | 192 | |
Craig Mautner | 8d341ef | 2013-03-26 09:03:27 -0700 | [diff] [blame] | 193 | import java.io.FileDescriptor; |
| 194 | import java.io.IOException; |
Craig Mautner | 2708430 | 2013-03-25 08:05:25 -0700 | [diff] [blame] | 195 | import java.io.PrintWriter; |
Winson Chung | 7900bee | 2017-03-10 08:59:25 -0800 | [diff] [blame] | 196 | import java.lang.annotation.Retention; |
| 197 | import java.lang.annotation.RetentionPolicy; |
Craig Mautner | 2219a1b | 2013-03-25 09:44:30 -0700 | [diff] [blame] | 198 | import java.util.ArrayList; |
David Stevens | 9440dc8 | 2017-03-16 19:00:20 -0700 | [diff] [blame] | 199 | import java.util.Iterator; |
Craig Mautner | 8d341ef | 2013-03-26 09:03:27 -0700 | [diff] [blame] | 200 | import java.util.List; |
Wale Ogunwale | 540e123 | 2015-05-01 15:35:39 -0700 | [diff] [blame] | 201 | import java.util.Set; |
Craig Mautner | 2708430 | 2013-03-25 08:05:25 -0700 | [diff] [blame] | 202 | |
Winson Chung | 1dbc811 | 2017-09-28 18:05:31 -0700 | [diff] [blame] | 203 | public class ActivityStackSupervisor extends ConfigurationContainer implements DisplayListener, |
Riddle Hsu | 86cb7de | 2018-08-13 23:29:58 +0800 | [diff] [blame] | 204 | RecentTasks.Callbacks, RootWindowContainerListener { |
Wale Ogunwale | 9887561 | 2018-10-12 07:53:02 -0700 | [diff] [blame] | 205 | private static final String TAG = TAG_WITH_CLASS_NAME ? "ActivityStackSupervisor" : TAG_ATM; |
Wale Ogunwale | 0fc365c | 2015-05-25 19:35:42 -0700 | [diff] [blame] | 206 | private static final String TAG_IDLE = TAG + POSTFIX_IDLE; |
Wale Ogunwale | ee006da | 2015-03-30 14:49:25 -0700 | [diff] [blame] | 207 | private static final String TAG_PAUSE = TAG + POSTFIX_PAUSE; |
Wale Ogunwale | ee006da | 2015-03-30 14:49:25 -0700 | [diff] [blame] | 208 | private static final String TAG_RECENTS = TAG + POSTFIX_RECENTS; |
Wale Ogunwale | 0fc365c | 2015-05-25 19:35:42 -0700 | [diff] [blame] | 209 | private static final String TAG_RELEASE = TAG + POSTFIX_RELEASE; |
Wale Ogunwale | ee006da | 2015-03-30 14:49:25 -0700 | [diff] [blame] | 210 | private static final String TAG_STACK = TAG + POSTFIX_STACK; |
| 211 | private static final String TAG_SWITCH = TAG + POSTFIX_SWITCH; |
Andrii Kulian | ab132ee | 2018-07-24 22:10:21 +0800 | [diff] [blame] | 212 | static final String TAG_STATES = TAG + POSTFIX_STATES; |
Filip Gruszczynski | 07a0e49 | 2015-12-17 14:16:38 -0800 | [diff] [blame] | 213 | static final String TAG_TASKS = TAG + POSTFIX_TASKS; |
Wale Ogunwale | e23149f | 2015-03-06 15:39:44 -0800 | [diff] [blame] | 214 | |
Craig Mautner | f333327 | 2013-04-22 10:55:53 -0700 | [diff] [blame] | 215 | /** How long we wait until giving up on the last activity telling us it is idle. */ |
Wale Ogunwale | 0fc365c | 2015-05-25 19:35:42 -0700 | [diff] [blame] | 216 | static final int IDLE_TIMEOUT = 10 * 1000; |
Craig Mautner | f333327 | 2013-04-22 10:55:53 -0700 | [diff] [blame] | 217 | |
Craig Mautner | 0eea92c | 2013-05-16 13:35:39 -0700 | [diff] [blame] | 218 | /** How long we can hold the sleep wake lock before giving up. */ |
Wale Ogunwale | 0fc365c | 2015-05-25 19:35:42 -0700 | [diff] [blame] | 219 | static final int SLEEP_TIMEOUT = 5 * 1000; |
Craig Mautner | 0eea92c | 2013-05-16 13:35:39 -0700 | [diff] [blame] | 220 | |
Craig Mautner | 7ea5bd4 | 2013-07-05 15:27:08 -0700 | [diff] [blame] | 221 | // How long we can hold the launch wake lock before giving up. |
Wale Ogunwale | 0fc365c | 2015-05-25 19:35:42 -0700 | [diff] [blame] | 222 | static final int LAUNCH_TIMEOUT = 10 * 1000; |
Craig Mautner | 7ea5bd4 | 2013-07-05 15:27:08 -0700 | [diff] [blame] | 223 | |
Craig Mautner | 05d2903 | 2013-05-03 13:40:13 -0700 | [diff] [blame] | 224 | static final int IDLE_TIMEOUT_MSG = FIRST_SUPERVISOR_STACK_MSG; |
| 225 | static final int IDLE_NOW_MSG = FIRST_SUPERVISOR_STACK_MSG + 1; |
| 226 | static final int RESUME_TOP_ACTIVITY_MSG = FIRST_SUPERVISOR_STACK_MSG + 2; |
Craig Mautner | 0eea92c | 2013-05-16 13:35:39 -0700 | [diff] [blame] | 227 | static final int SLEEP_TIMEOUT_MSG = FIRST_SUPERVISOR_STACK_MSG + 3; |
Craig Mautner | 7ea5bd4 | 2013-07-05 15:27:08 -0700 | [diff] [blame] | 228 | static final int LAUNCH_TIMEOUT_MSG = FIRST_SUPERVISOR_STACK_MSG + 4; |
Wale Ogunwale | 73eba74 | 2015-04-07 14:23:14 -0700 | [diff] [blame] | 229 | static final int LAUNCH_TASK_BEHIND_COMPLETE = FIRST_SUPERVISOR_STACK_MSG + 12; |
Wale Ogunwale | 22e2526 | 2016-02-01 10:32:02 -0800 | [diff] [blame] | 230 | static final int REPORT_MULTI_WINDOW_MODE_CHANGED_MSG = FIRST_SUPERVISOR_STACK_MSG + 14; |
| 231 | static final int REPORT_PIP_MODE_CHANGED_MSG = FIRST_SUPERVISOR_STACK_MSG + 15; |
Craig Mautner | 4a1cb22 | 2013-12-04 16:14:06 -0800 | [diff] [blame] | 232 | |
Wale Ogunwale | 040b470 | 2015-08-06 18:10:50 -0700 | [diff] [blame] | 233 | private static final String VIRTUAL_DISPLAY_BASE_NAME = "ActivityViewVirtualDisplay"; |
Craig Mautner | 7ea5bd4 | 2013-07-05 15:27:08 -0700 | [diff] [blame] | 234 | |
Wale Ogunwale | 040b470 | 2015-08-06 18:10:50 -0700 | [diff] [blame] | 235 | // Used to indicate if an object (e.g. stack) that we are trying to get |
| 236 | // should be created if it doesn't exist already. |
Filip Gruszczynski | 07a0e49 | 2015-12-17 14:16:38 -0800 | [diff] [blame] | 237 | static final boolean CREATE_IF_NEEDED = true; |
Wale Ogunwale | 040b470 | 2015-08-06 18:10:50 -0700 | [diff] [blame] | 238 | |
Filip Gruszczynski | bc5a6c5 | 2015-09-22 13:13:24 -0700 | [diff] [blame] | 239 | // Used to indicate that windows of activities should be preserved during the resize. |
| 240 | static final boolean PRESERVE_WINDOWS = true; |
| 241 | |
Wale Ogunwale | 040b470 | 2015-08-06 18:10:50 -0700 | [diff] [blame] | 242 | // Used to indicate if an object (e.g. task) should be moved/created |
| 243 | // at the top of its container (e.g. stack). |
Wale Ogunwale | b30daaa | 2015-08-07 21:50:49 -0700 | [diff] [blame] | 244 | static final boolean ON_TOP = true; |
Wale Ogunwale | 040b470 | 2015-08-06 18:10:50 -0700 | [diff] [blame] | 245 | |
Wale Ogunwale | c8da41e | 2016-04-16 13:27:23 -0700 | [diff] [blame] | 246 | // Don't execute any calls to resume. |
| 247 | static final boolean DEFER_RESUME = true; |
| 248 | |
Winson Chung | 010927a | 2016-12-15 16:12:35 -0800 | [diff] [blame] | 249 | // Used to indicate that a task is removed it should also be removed from recents. |
| 250 | static final boolean REMOVE_FROM_RECENTS = true; |
| 251 | |
Winson Chung | 6954fc9 | 2017-03-24 16:22:12 -0700 | [diff] [blame] | 252 | // Used to indicate that pausing an activity should occur immediately without waiting for |
| 253 | // the activity callback indicating that it has completed pausing |
| 254 | static final boolean PAUSE_IMMEDIATELY = true; |
| 255 | |
Adrian Roos | a6d6aab | 2018-04-19 18:58:22 +0200 | [diff] [blame] | 256 | /** True if the docked stack is currently being resized. */ |
| 257 | private boolean mDockedStackResizing; |
| 258 | |
| 259 | /** |
| 260 | * True if there are pending docked bounds that need to be applied after |
| 261 | * {@link #mDockedStackResizing} is reset to false. |
| 262 | */ |
| 263 | private boolean mHasPendingDockedBounds; |
| 264 | private Rect mPendingDockedBounds; |
| 265 | private Rect mPendingTempDockedTaskBounds; |
| 266 | private Rect mPendingTempDockedTaskInsetBounds; |
| 267 | private Rect mPendingTempOtherTaskBounds; |
| 268 | private Rect mPendingTempOtherTaskInsetBounds; |
| 269 | |
Winson Chung | 7900bee | 2017-03-10 08:59:25 -0800 | [diff] [blame] | 270 | /** |
| 271 | * The modes which affect which tasks are returned when calling |
| 272 | * {@link ActivityStackSupervisor#anyTaskForIdLocked(int)}. |
| 273 | */ |
| 274 | @Retention(RetentionPolicy.SOURCE) |
| 275 | @IntDef({ |
| 276 | MATCH_TASK_IN_STACKS_ONLY, |
| 277 | MATCH_TASK_IN_STACKS_OR_RECENT_TASKS, |
| 278 | MATCH_TASK_IN_STACKS_OR_RECENT_TASKS_AND_RESTORE |
| 279 | }) |
| 280 | public @interface AnyTaskForIdMatchTaskMode {} |
| 281 | // Match only tasks in the current stacks |
| 282 | static final int MATCH_TASK_IN_STACKS_ONLY = 0; |
| 283 | // Match either tasks in the current stacks, or in the recent tasks if not found in the stacks |
| 284 | static final int MATCH_TASK_IN_STACKS_OR_RECENT_TASKS = 1; |
| 285 | // Match either tasks in the current stacks, or in the recent tasks, restoring it to the |
| 286 | // provided stack id |
| 287 | static final int MATCH_TASK_IN_STACKS_OR_RECENT_TASKS_AND_RESTORE = 2; |
| 288 | |
Svetoslav | 7008b51 | 2015-06-24 18:47:07 -0700 | [diff] [blame] | 289 | // Activity actions an app cannot start if it uses a permission which is not granted. |
| 290 | private static final ArrayMap<String, String> ACTION_TO_RUNTIME_PERMISSION = |
| 291 | new ArrayMap<>(); |
Filip Gruszczynski | bc5a6c5 | 2015-09-22 13:13:24 -0700 | [diff] [blame] | 292 | |
Svetoslav | 7008b51 | 2015-06-24 18:47:07 -0700 | [diff] [blame] | 293 | static { |
| 294 | ACTION_TO_RUNTIME_PERMISSION.put(MediaStore.ACTION_IMAGE_CAPTURE, |
| 295 | Manifest.permission.CAMERA); |
| 296 | ACTION_TO_RUNTIME_PERMISSION.put(MediaStore.ACTION_VIDEO_CAPTURE, |
| 297 | Manifest.permission.CAMERA); |
| 298 | ACTION_TO_RUNTIME_PERMISSION.put(Intent.ACTION_CALL, |
| 299 | Manifest.permission.CALL_PHONE); |
| 300 | } |
| 301 | |
Svet Ganov | 99b6043 | 2015-06-27 13:15:22 -0700 | [diff] [blame] | 302 | /** Action restriction: launching the activity is not restricted. */ |
| 303 | private static final int ACTIVITY_RESTRICTION_NONE = 0; |
| 304 | /** Action restriction: launching the activity is restricted by a permission. */ |
| 305 | private static final int ACTIVITY_RESTRICTION_PERMISSION = 1; |
| 306 | /** Action restriction: launching the activity is restricted by an app op. */ |
| 307 | private static final int ACTIVITY_RESTRICTION_APPOP = 2; |
Svetoslav | 7008b51 | 2015-06-24 18:47:07 -0700 | [diff] [blame] | 308 | |
Craig Mautner | 7ea5bd4 | 2013-07-05 15:27:08 -0700 | [diff] [blame] | 309 | // For debugging to make sure the caller when acquiring/releasing our |
| 310 | // wake lock is the system process. |
| 311 | static final boolean VALIDATE_WAKE_LOCK_CALLER = false; |
Suprabh Shukla | 09a88f5 | 2015-12-02 14:36:31 -0800 | [diff] [blame] | 312 | /** The number of distinct task ids that can be assigned to the tasks of a single user */ |
| 313 | private static final int MAX_TASK_IDS_PER_USER = UserHandle.PER_USER_RANGE; |
Craig Mautner | f333327 | 2013-04-22 10:55:53 -0700 | [diff] [blame] | 314 | |
Wale Ogunwale | c9e57de | 2018-05-08 14:28:07 -0700 | [diff] [blame] | 315 | ActivityTaskManagerService mService; |
Craig Mautner | 2708430 | 2013-03-25 08:05:25 -0700 | [diff] [blame] | 316 | |
Winson Chung | 61c9e5a | 2017-10-11 10:39:32 -0700 | [diff] [blame] | 317 | /** The historial list of recent tasks including inactive tasks */ |
Winson Chung | 1dbc811 | 2017-09-28 18:05:31 -0700 | [diff] [blame] | 318 | RecentTasks mRecentTasks; |
Wale Ogunwale | c82f2f5 | 2014-12-09 09:32:50 -0800 | [diff] [blame] | 319 | |
Winson Chung | 61c9e5a | 2017-10-11 10:39:32 -0700 | [diff] [blame] | 320 | /** Helper class to abstract out logic for fetching the set of currently running tasks */ |
Winson Chung | 3f0e59a | 2017-10-25 10:19:05 -0700 | [diff] [blame] | 321 | private RunningTasks mRunningTasks; |
Winson Chung | 61c9e5a | 2017-10-11 10:39:32 -0700 | [diff] [blame] | 322 | |
Craig Mautner | ce5f3cb | 2013-04-22 08:58:54 -0700 | [diff] [blame] | 323 | final ActivityStackSupervisorHandler mHandler; |
Winson Chung | e2d7217 | 2018-01-25 17:46:20 +0000 | [diff] [blame] | 324 | final Looper mLooper; |
Craig Mautner | ce5f3cb | 2013-04-22 08:58:54 -0700 | [diff] [blame] | 325 | |
| 326 | /** Short cut */ |
| 327 | WindowManagerService mWindowManager; |
Craig Mautner | 4a1cb22 | 2013-12-04 16:14:06 -0800 | [diff] [blame] | 328 | DisplayManager mDisplayManager; |
Craig Mautner | ce5f3cb | 2013-04-22 08:58:54 -0700 | [diff] [blame] | 329 | |
Bryce Lee | ec55eb0 | 2017-12-05 20:51:27 -0800 | [diff] [blame] | 330 | private LaunchParamsController mLaunchParamsController; |
Bryce Lee | 9ad3eb3 | 2017-10-10 10:10:31 -0700 | [diff] [blame] | 331 | |
Suprabh Shukla | 09a88f5 | 2015-12-02 14:36:31 -0800 | [diff] [blame] | 332 | /** |
| 333 | * Maps the task identifier that activities are currently being started in to the userId of the |
| 334 | * task. Each time a new task is created, the entry for the userId of the task is incremented |
| 335 | */ |
| 336 | private final SparseIntArray mCurTaskIdForUser = new SparseIntArray(20); |
Craig Mautner | 8d341ef | 2013-03-26 09:03:27 -0700 | [diff] [blame] | 337 | |
Craig Mautner | 2420ead | 2013-04-01 17:13:20 -0700 | [diff] [blame] | 338 | /** The current user */ |
Filip Gruszczynski | 07a0e49 | 2015-12-17 14:16:38 -0800 | [diff] [blame] | 339 | int mCurrentUser; |
Craig Mautner | 2420ead | 2013-04-01 17:13:20 -0700 | [diff] [blame] | 340 | |
Craig Mautner | de4ef02 | 2013-04-07 19:01:33 -0700 | [diff] [blame] | 341 | /** List of activities that are waiting for a new activity to become visible before completing |
| 342 | * whatever operation they are supposed to do. */ |
Bryce Lee | 4a19438 | 2017-04-04 14:32:48 -0700 | [diff] [blame] | 343 | // TODO: Remove mActivitiesWaitingForVisibleActivity list and just remove activity from |
| 344 | // mStoppingActivities when something else comes up. |
| 345 | final ArrayList<ActivityRecord> mActivitiesWaitingForVisibleActivity = new ArrayList<>(); |
Craig Mautner | de4ef02 | 2013-04-07 19:01:33 -0700 | [diff] [blame] | 346 | |
Bryce Lee | 4a19438 | 2017-04-04 14:32:48 -0700 | [diff] [blame] | 347 | /** List of processes waiting to find out when a specific activity becomes visible. */ |
| 348 | private final ArrayList<WaitInfo> mWaitingForActivityVisible = new ArrayList<>(); |
Craig Mautner | ce5f3cb | 2013-04-22 08:58:54 -0700 | [diff] [blame] | 349 | |
| 350 | /** List of processes waiting to find out about the next launched activity. */ |
Sudheer Shanka | fc46e9b | 2016-10-21 17:55:27 -0700 | [diff] [blame] | 351 | final ArrayList<WaitResult> mWaitingActivityLaunched = new ArrayList<>(); |
Craig Mautner | ce5f3cb | 2013-04-22 08:58:54 -0700 | [diff] [blame] | 352 | |
Craig Mautner | de4ef02 | 2013-04-07 19:01:33 -0700 | [diff] [blame] | 353 | /** List of activities that are ready to be stopped, but waiting for the next activity to |
| 354 | * settle down before doing so. */ |
Craig Mautner | 8c14c15 | 2015-01-15 17:32:07 -0800 | [diff] [blame] | 355 | final ArrayList<ActivityRecord> mStoppingActivities = new ArrayList<>(); |
Craig Mautner | de4ef02 | 2013-04-07 19:01:33 -0700 | [diff] [blame] | 356 | |
Craig Mautner | f333327 | 2013-04-22 10:55:53 -0700 | [diff] [blame] | 357 | /** List of activities that are ready to be finished, but waiting for the previous activity to |
| 358 | * settle down before doing so. It contains ActivityRecord objects. */ |
Craig Mautner | 8c14c15 | 2015-01-15 17:32:07 -0800 | [diff] [blame] | 359 | final ArrayList<ActivityRecord> mFinishingActivities = new ArrayList<>(); |
Craig Mautner | f333327 | 2013-04-22 10:55:53 -0700 | [diff] [blame] | 360 | |
Craig Mautner | 0eea92c | 2013-05-16 13:35:39 -0700 | [diff] [blame] | 361 | /** List of activities that are in the process of going to sleep. */ |
Craig Mautner | 8c14c15 | 2015-01-15 17:32:07 -0800 | [diff] [blame] | 362 | final ArrayList<ActivityRecord> mGoingToSleepActivities = new ArrayList<>(); |
Craig Mautner | 0eea92c | 2013-05-16 13:35:39 -0700 | [diff] [blame] | 363 | |
Wale Ogunwale | 22e2526 | 2016-02-01 10:32:02 -0800 | [diff] [blame] | 364 | /** List of activities whose multi-window mode changed that we need to report to the |
| 365 | * application */ |
| 366 | final ArrayList<ActivityRecord> mMultiWindowModeChangedActivities = new ArrayList<>(); |
| 367 | |
| 368 | /** List of activities whose picture-in-picture mode changed that we need to report to the |
| 369 | * application */ |
| 370 | final ArrayList<ActivityRecord> mPipModeChangedActivities = new ArrayList<>(); |
| 371 | |
Jorim Jaggi | fa9ed96 | 2018-01-25 00:16:49 +0100 | [diff] [blame] | 372 | /** |
| 373 | * Animations that for the current transition have requested not to |
| 374 | * be considered for the transition animation. |
| 375 | */ |
| 376 | final ArrayList<ActivityRecord> mNoAnimActivities = new ArrayList<>(); |
| 377 | |
Winson Chung | 5af42fc | 2017-03-24 17:11:33 -0700 | [diff] [blame] | 378 | /** The target stack bounds for the picture-in-picture mode changed that we need to report to |
| 379 | * the application */ |
| 380 | Rect mPipModeChangedTargetStackBounds; |
| 381 | |
Craig Mautner | f333327 | 2013-04-22 10:55:53 -0700 | [diff] [blame] | 382 | /** Used on user changes */ |
Amith Yamasani | 37a40c2 | 2015-06-17 13:25:42 -0700 | [diff] [blame] | 383 | final ArrayList<UserState> mStartingUsers = new ArrayList<>(); |
Craig Mautner | f333327 | 2013-04-22 10:55:53 -0700 | [diff] [blame] | 384 | |
Craig Mautner | de4ef02 | 2013-04-07 19:01:33 -0700 | [diff] [blame] | 385 | /** Set to indicate whether to issue an onUserLeaving callback when a newly launched activity |
| 386 | * is being brought in front of us. */ |
| 387 | boolean mUserLeaving = false; |
| 388 | |
Bryce Lee | d3624e1 | 2017-11-30 08:51:45 -0800 | [diff] [blame] | 389 | /** Set when a power hint has started, but not ended. */ |
| 390 | private boolean mPowerHintSent; |
| 391 | |
Craig Mautner | 0eea92c | 2013-05-16 13:35:39 -0700 | [diff] [blame] | 392 | /** |
Craig Mautner | 7ea5bd4 | 2013-07-05 15:27:08 -0700 | [diff] [blame] | 393 | * We don't want to allow the device to go to sleep while in the process |
| 394 | * of launching an activity. This is primarily to allow alarm intent |
| 395 | * receivers to launch an activity and get that to run before the device |
| 396 | * goes back to sleep. |
| 397 | */ |
Jeff Brown | 2c43c33 | 2014-06-12 22:38:59 -0700 | [diff] [blame] | 398 | PowerManager.WakeLock mLaunchingActivity; |
Craig Mautner | 7ea5bd4 | 2013-07-05 15:27:08 -0700 | [diff] [blame] | 399 | |
| 400 | /** |
Craig Mautner | 0eea92c | 2013-05-16 13:35:39 -0700 | [diff] [blame] | 401 | * Set when the system is going to sleep, until we have |
| 402 | * successfully paused the current activity and released our wake lock. |
| 403 | * At that point the system is allowed to actually sleep. |
| 404 | */ |
Jeff Brown | 2c43c33 | 2014-06-12 22:38:59 -0700 | [diff] [blame] | 405 | PowerManager.WakeLock mGoingToSleep; |
Craig Mautner | 0eea92c | 2013-05-16 13:35:39 -0700 | [diff] [blame] | 406 | |
David Stevens | 9440dc8 | 2017-03-16 19:00:20 -0700 | [diff] [blame] | 407 | /** |
| 408 | * A list of tokens that cause the top activity to be put to sleep. |
| 409 | * They are used by components that may hide and block interaction with underlying |
| 410 | * activities. |
| 411 | */ |
Wale Ogunwale | 9dcf946 | 2017-09-19 15:13:01 -0700 | [diff] [blame] | 412 | final ArrayList<SleepToken> mSleepTokens = new ArrayList<>(); |
David Stevens | 9440dc8 | 2017-03-16 19:00:20 -0700 | [diff] [blame] | 413 | |
Craig Mautner | 4f1df4f | 2013-10-15 15:44:14 -0700 | [diff] [blame] | 414 | /** Stack id of the front stack when user switched, indexed by userId. */ |
| 415 | SparseIntArray mUserStackInFront = new SparseIntArray(2); |
Craig Mautner | 93529a4 | 2013-10-04 15:03:13 -0700 | [diff] [blame] | 416 | |
Riddle Hsu | 86cb7de | 2018-08-13 23:29:58 +0800 | [diff] [blame] | 417 | /** Reference to default display so we can quickly look it up. */ |
| 418 | private ActivityDisplay mDefaultDisplay; |
| 419 | |
| 420 | /** |
| 421 | * List of displays which contain activities, sorted by z-order. |
| 422 | * The last entry in the list is the topmost. |
| 423 | */ |
| 424 | private final ArrayList<ActivityDisplay> mActivityDisplays = new ArrayList<>(); |
Craig Mautner | 4a1cb22 | 2013-12-04 16:14:06 -0800 | [diff] [blame] | 425 | |
Andrii Kulian | fb1bf69 | 2017-01-17 11:17:34 -0800 | [diff] [blame] | 426 | private final SparseArray<IntArray> mDisplayAccessUIDs = new SparseArray<>(); |
| 427 | |
| 428 | private DisplayManagerInternal mDisplayManagerInternal; |
Jeff Brown | ca9bc70 | 2014-02-11 14:32:56 -0800 | [diff] [blame] | 429 | |
Wale Ogunwale | d046a01 | 2015-12-24 13:05:59 -0800 | [diff] [blame] | 430 | /** Used to keep resumeTopActivityUncheckedLocked() from being entered recursively */ |
Craig Mautner | 42d04db | 2014-11-06 12:13:23 -0800 | [diff] [blame] | 431 | boolean inResumeTopActivity; |
| 432 | |
Andrii Kulian | 1e32e02 | 2016-09-16 15:29:34 -0700 | [diff] [blame] | 433 | /** |
| 434 | * Temporary rect used during docked stack resize calculation so we don't need to create a new |
| 435 | * object each time. |
| 436 | */ |
Wale Ogunwale | b34a7ad | 2015-08-14 11:05:30 -0700 | [diff] [blame] | 437 | private final Rect tempRect = new Rect(); |
Wale Ogunwale | 7e1f5f5 | 2017-10-18 15:19:59 -0700 | [diff] [blame] | 438 | private final ActivityOptions mTmpOptions = ActivityOptions.makeBasic(); |
Filip Gruszczynski | ebcc875 | 2015-08-25 16:51:05 -0700 | [diff] [blame] | 439 | |
Filip Gruszczynski | d2f1d94 | 2015-10-14 15:10:12 -0700 | [diff] [blame] | 440 | // The default minimal size that will be used if the activity doesn't specify its minimal size. |
| 441 | // It will be calculated when the default display gets added. |
Garfield Tan | 4a48a7f | 2018-10-02 14:23:55 -0700 | [diff] [blame] | 442 | int mDefaultMinSizeOfResizeableTaskDp = -1; |
Filip Gruszczynski | d2f1d94 | 2015-10-14 15:10:12 -0700 | [diff] [blame] | 443 | |
Chong Zhang | fdcc4d4 | 2015-10-14 16:50:12 -0700 | [diff] [blame] | 444 | // Whether tasks have moved and we need to rank the tasks before next OOM scoring |
| 445 | private boolean mTaskLayersChanged = true; |
| 446 | |
Bryce Lee | 2a3cc46 | 2017-10-27 10:57:35 -0700 | [diff] [blame] | 447 | private ActivityMetricsLogger mActivityMetricsLogger; |
Filip Gruszczynski | 77d9448 | 2015-12-11 13:59:52 -0800 | [diff] [blame] | 448 | |
Jorim Jaggi | ea039a8 | 2017-08-02 14:37:49 +0200 | [diff] [blame] | 449 | private final ArrayList<ActivityRecord> mTmpActivityList = new ArrayList<>(); |
| 450 | |
Andrii Kulian | 1779e61 | 2016-10-12 21:58:25 -0700 | [diff] [blame] | 451 | @Override |
| 452 | protected int getChildCount() { |
| 453 | return mActivityDisplays.size(); |
| 454 | } |
| 455 | |
| 456 | @Override |
Andrii Kulian | 5406e7a | 2016-10-21 11:55:23 -0700 | [diff] [blame] | 457 | protected ActivityDisplay getChildAt(int index) { |
Riddle Hsu | 86cb7de | 2018-08-13 23:29:58 +0800 | [diff] [blame] | 458 | return mActivityDisplays.get(index); |
Andrii Kulian | 1779e61 | 2016-10-12 21:58:25 -0700 | [diff] [blame] | 459 | } |
| 460 | |
| 461 | @Override |
| 462 | protected ConfigurationContainer getParent() { |
| 463 | return null; |
| 464 | } |
| 465 | |
Andrii Kulian | 5406e7a | 2016-10-21 11:55:23 -0700 | [diff] [blame] | 466 | Configuration getDisplayOverrideConfiguration(int displayId) { |
Andrii Kulian | 62e6f25 | 2017-05-30 22:46:53 -0700 | [diff] [blame] | 467 | final ActivityDisplay activityDisplay = getActivityDisplayOrCreateLocked(displayId); |
Andrii Kulian | 5406e7a | 2016-10-21 11:55:23 -0700 | [diff] [blame] | 468 | if (activityDisplay == null) { |
| 469 | throw new IllegalArgumentException("No display found with id: " + displayId); |
| 470 | } |
| 471 | |
| 472 | return activityDisplay.getOverrideConfiguration(); |
| 473 | } |
| 474 | |
| 475 | void setDisplayOverrideConfiguration(Configuration overrideConfiguration, int displayId) { |
Andrii Kulian | 62e6f25 | 2017-05-30 22:46:53 -0700 | [diff] [blame] | 476 | final ActivityDisplay activityDisplay = getActivityDisplayOrCreateLocked(displayId); |
Andrii Kulian | 5406e7a | 2016-10-21 11:55:23 -0700 | [diff] [blame] | 477 | if (activityDisplay == null) { |
| 478 | throw new IllegalArgumentException("No display found with id: " + displayId); |
| 479 | } |
| 480 | |
| 481 | activityDisplay.onOverrideConfigurationChanged(overrideConfiguration); |
| 482 | } |
| 483 | |
Andrii Kulian | 036e3ad | 2017-04-19 10:55:10 -0700 | [diff] [blame] | 484 | /** Check if placing task or activity on specified display is allowed. */ |
Riddle Hsu | 1656713 | 2018-08-16 21:37:47 +0800 | [diff] [blame] | 485 | boolean canPlaceEntityOnDisplay(int displayId, int callingPid, int callingUid, |
| 486 | ActivityInfo activityInfo) { |
Andrii Kulian | 02689a7 | 2017-07-06 14:28:59 -0700 | [diff] [blame] | 487 | if (displayId == DEFAULT_DISPLAY) { |
| 488 | // No restrictions for the default display. |
| 489 | return true; |
| 490 | } |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 491 | if (!mService.mSupportsMultiDisplay) { |
Andrii Kulian | 02689a7 | 2017-07-06 14:28:59 -0700 | [diff] [blame] | 492 | // Can't launch on secondary displays if feature is not supported. |
| 493 | return false; |
| 494 | } |
Andrii Kulian | 02689a7 | 2017-07-06 14:28:59 -0700 | [diff] [blame] | 495 | if (!isCallerAllowedToLaunchOnDisplay(callingPid, callingUid, displayId, activityInfo)) { |
| 496 | // Can't place activities to a display that has restricted launch rules. |
| 497 | // In this case the request should be made by explicitly adding target display id and |
| 498 | // by caller with corresponding permissions. See #isCallerAllowedToLaunchOnDisplay(). |
| 499 | return false; |
| 500 | } |
| 501 | return true; |
Andrii Kulian | 036e3ad | 2017-04-19 10:55:10 -0700 | [diff] [blame] | 502 | } |
| 503 | |
| 504 | /** |
| 505 | * Check if configuration of specified display matches current global config. |
| 506 | * Used to check if we can put a non-resizeable activity on a secondary display and it will get |
| 507 | * the same config as on the default display. |
| 508 | * @param displayId Id of the display to check. |
| 509 | * @return {@code true} if configuration matches. |
| 510 | */ |
| 511 | private boolean displayConfigMatchesGlobal(int displayId) { |
| 512 | if (displayId == DEFAULT_DISPLAY) { |
| 513 | return true; |
| 514 | } |
| 515 | if (displayId == INVALID_DISPLAY) { |
| 516 | return false; |
| 517 | } |
Andrii Kulian | 62e6f25 | 2017-05-30 22:46:53 -0700 | [diff] [blame] | 518 | final ActivityDisplay targetDisplay = getActivityDisplayOrCreateLocked(displayId); |
Andrii Kulian | 036e3ad | 2017-04-19 10:55:10 -0700 | [diff] [blame] | 519 | if (targetDisplay == null) { |
| 520 | throw new IllegalArgumentException("No display found with id: " + displayId); |
| 521 | } |
| 522 | return getConfiguration().equals(targetDisplay.getConfiguration()); |
| 523 | } |
| 524 | |
Wale Ogunwale | 3938197 | 2015-12-17 17:15:29 -0800 | [diff] [blame] | 525 | static class FindTaskResult { |
Louis Chang | c85b1a3 | 2018-08-14 16:40:53 +0800 | [diff] [blame] | 526 | ActivityRecord mRecord; |
| 527 | boolean mIdealMatch; |
| 528 | |
| 529 | void clear() { |
| 530 | mRecord = null; |
| 531 | mIdealMatch = false; |
| 532 | } |
| 533 | |
| 534 | void setTo(FindTaskResult result) { |
| 535 | mRecord = result.mRecord; |
| 536 | mIdealMatch = result.mIdealMatch; |
| 537 | } |
Wale Ogunwale | 3938197 | 2015-12-17 17:15:29 -0800 | [diff] [blame] | 538 | } |
Louis Chang | c85b1a3 | 2018-08-14 16:40:53 +0800 | [diff] [blame] | 539 | |
Wale Ogunwale | 3938197 | 2015-12-17 17:15:29 -0800 | [diff] [blame] | 540 | private final FindTaskResult mTmpFindTaskResult = new FindTaskResult(); |
| 541 | |
Craig Mautner | ee36c77 | 2014-07-16 14:56:05 -0700 | [diff] [blame] | 542 | /** |
Jorim Jaggi | a0fdeec | 2016-01-07 14:42:28 +0100 | [diff] [blame] | 543 | * Used to keep track whether app visibilities got changed since the last pause. Useful to |
| 544 | * determine whether to invoke the task stack change listener after pausing. |
| 545 | */ |
| 546 | boolean mAppVisibilitiesChangedSinceLastPause; |
| 547 | |
| 548 | /** |
Jorim Jaggi | 0b46f3c | 2016-03-14 12:21:37 +0100 | [diff] [blame] | 549 | * Set of tasks that are in resizing mode during an app transition to fill the "void". |
| 550 | */ |
| 551 | private final ArraySet<Integer> mResizingTasksDuringAnimation = new ArraySet<>(); |
| 552 | |
Wale Ogunwale | c8da41e | 2016-04-16 13:27:23 -0700 | [diff] [blame] | 553 | |
| 554 | /** |
| 555 | * If set to {@code false} all calls to resize the docked stack {@link #resizeDockedStackLocked} |
| 556 | * will be ignored. Useful for the case where the caller is handling resizing of other stack and |
| 557 | * moving tasks around and doesn't want dock stack to be resized due to an automatic trigger |
| 558 | * like the docked stack going empty. |
| 559 | */ |
| 560 | private boolean mAllowDockedStackResize = true; |
| 561 | |
Jorim Jaggi | 0b46f3c | 2016-03-14 12:21:37 +0100 | [diff] [blame] | 562 | /** |
Tony Mak | 853304c | 2016-04-18 15:17:41 +0100 | [diff] [blame] | 563 | * Is dock currently minimized. |
| 564 | */ |
| 565 | boolean mIsDockMinimized; |
| 566 | |
Bryce Lee | 2a3cc46 | 2017-10-27 10:57:35 -0700 | [diff] [blame] | 567 | private KeyguardController mKeyguardController; |
Jorim Jaggi | fe76234 | 2016-10-13 14:33:27 +0200 | [diff] [blame] | 568 | |
chaviw | 59b9885 | 2017-06-13 12:05:44 -0700 | [diff] [blame] | 569 | private PowerManager mPowerManager; |
| 570 | private int mDeferResumeCount; |
| 571 | |
Bryce Lee | 2a3cc46 | 2017-10-27 10:57:35 -0700 | [diff] [blame] | 572 | private boolean mInitialized; |
| 573 | |
Riddle Hsu | 86cb7de | 2018-08-13 23:29:58 +0800 | [diff] [blame] | 574 | private RootWindowContainerController mWindowContainerController; |
| 575 | |
Tony Mak | 853304c | 2016-04-18 15:17:41 +0100 | [diff] [blame] | 576 | /** |
Craig Mautner | ee36c77 | 2014-07-16 14:56:05 -0700 | [diff] [blame] | 577 | * Description of a request to start a new activity, which has been held |
| 578 | * due to app switches being disabled. |
| 579 | */ |
| 580 | static class PendingActivityLaunch { |
| 581 | final ActivityRecord r; |
| 582 | final ActivityRecord sourceRecord; |
| 583 | final int startFlags; |
| 584 | final ActivityStack stack; |
Wale Ogunwale | 9e4f3e0 | 2018-05-17 09:35:39 -0700 | [diff] [blame] | 585 | final WindowProcessController callerApp; |
Craig Mautner | ee36c77 | 2014-07-16 14:56:05 -0700 | [diff] [blame] | 586 | |
| 587 | PendingActivityLaunch(ActivityRecord _r, ActivityRecord _sourceRecord, |
Wale Ogunwale | 9e4f3e0 | 2018-05-17 09:35:39 -0700 | [diff] [blame] | 588 | int _startFlags, ActivityStack _stack, WindowProcessController app) { |
Craig Mautner | ee36c77 | 2014-07-16 14:56:05 -0700 | [diff] [blame] | 589 | r = _r; |
| 590 | sourceRecord = _sourceRecord; |
| 591 | startFlags = _startFlags; |
| 592 | stack = _stack; |
Wale Ogunwale | 9e4f3e0 | 2018-05-17 09:35:39 -0700 | [diff] [blame] | 593 | callerApp = app; |
Robert Carr | 13997f5 | 2015-10-23 13:13:39 -0700 | [diff] [blame] | 594 | } |
| 595 | |
| 596 | void sendErrorResult(String message) { |
| 597 | try { |
Wale Ogunwale | 9e4f3e0 | 2018-05-17 09:35:39 -0700 | [diff] [blame] | 598 | if (callerApp.hasThread()) { |
| 599 | callerApp.getThread().scheduleCrash(message); |
Robert Carr | 13997f5 | 2015-10-23 13:13:39 -0700 | [diff] [blame] | 600 | } |
| 601 | } catch (RemoteException e) { |
| 602 | Slog.e(TAG, "Exception scheduling crash of failed " |
| 603 | + "activity launcher sourceRecord=" + sourceRecord, e); |
| 604 | } |
Craig Mautner | ee36c77 | 2014-07-16 14:56:05 -0700 | [diff] [blame] | 605 | } |
| 606 | } |
| 607 | |
Wale Ogunwale | c9e57de | 2018-05-08 14:28:07 -0700 | [diff] [blame] | 608 | public ActivityStackSupervisor(ActivityTaskManagerService service, Looper looper) { |
Craig Mautner | 2708430 | 2013-03-25 08:05:25 -0700 | [diff] [blame] | 609 | mService = service; |
Winson Chung | e2d7217 | 2018-01-25 17:46:20 +0000 | [diff] [blame] | 610 | mLooper = looper; |
Bryce Lee | af691c0 | 2017-03-20 14:20:22 -0700 | [diff] [blame] | 611 | mHandler = new ActivityStackSupervisorHandler(looper); |
Bryce Lee | 2a3cc46 | 2017-10-27 10:57:35 -0700 | [diff] [blame] | 612 | } |
| 613 | |
Wale Ogunwale | 65ebd95 | 2018-04-25 15:41:44 -0700 | [diff] [blame] | 614 | @VisibleForTesting |
Wale Ogunwale | c9e57de | 2018-05-08 14:28:07 -0700 | [diff] [blame] | 615 | void setService(ActivityTaskManagerService service) { |
Wale Ogunwale | 65ebd95 | 2018-04-25 15:41:44 -0700 | [diff] [blame] | 616 | mService = service; |
| 617 | } |
| 618 | |
Riddle Hsu | 86cb7de | 2018-08-13 23:29:58 +0800 | [diff] [blame] | 619 | @VisibleForTesting |
| 620 | void setWindowContainerController(RootWindowContainerController controller) { |
| 621 | mWindowContainerController = controller; |
| 622 | } |
| 623 | |
Bryce Lee | 2a3cc46 | 2017-10-27 10:57:35 -0700 | [diff] [blame] | 624 | public void initialize() { |
| 625 | if (mInitialized) { |
| 626 | return; |
| 627 | } |
| 628 | |
| 629 | mInitialized = true; |
Winson Chung | 3f0e59a | 2017-10-25 10:19:05 -0700 | [diff] [blame] | 630 | mRunningTasks = createRunningTasks(); |
Wale Ogunwale | c9e57de | 2018-05-08 14:28:07 -0700 | [diff] [blame] | 631 | mActivityMetricsLogger = new ActivityMetricsLogger(this, mService.mContext, mHandler.getLooper()); |
Wale Ogunwale | f673393 | 2018-06-27 05:14:34 -0700 | [diff] [blame] | 632 | mKeyguardController = new KeyguardController(mService, this); |
Bryce Lee | dacefc4 | 2017-10-10 12:56:02 -0700 | [diff] [blame] | 633 | |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 634 | mLaunchParamsController = new LaunchParamsController(mService); |
Bryce Lee | ec55eb0 | 2017-12-05 20:51:27 -0800 | [diff] [blame] | 635 | mLaunchParamsController.registerDefaultModifiers(this); |
Jeff Brown | 2c43c33 | 2014-06-12 22:38:59 -0700 | [diff] [blame] | 636 | } |
| 637 | |
Bryce Lee | 2a3cc46 | 2017-10-27 10:57:35 -0700 | [diff] [blame] | 638 | |
| 639 | public ActivityMetricsLogger getActivityMetricsLogger() { |
| 640 | return mActivityMetricsLogger; |
| 641 | } |
| 642 | |
| 643 | public KeyguardController getKeyguardController() { |
| 644 | return mKeyguardController; |
| 645 | } |
| 646 | |
Suprabh Shukla | 09a88f5 | 2015-12-02 14:36:31 -0800 | [diff] [blame] | 647 | void setRecentTasks(RecentTasks recentTasks) { |
| 648 | mRecentTasks = recentTasks; |
Winson Chung | 1dbc811 | 2017-09-28 18:05:31 -0700 | [diff] [blame] | 649 | mRecentTasks.registerCallback(this); |
Suprabh Shukla | 09a88f5 | 2015-12-02 14:36:31 -0800 | [diff] [blame] | 650 | } |
| 651 | |
Winson Chung | 3f0e59a | 2017-10-25 10:19:05 -0700 | [diff] [blame] | 652 | @VisibleForTesting |
| 653 | RunningTasks createRunningTasks() { |
| 654 | return new RunningTasks(); |
| 655 | } |
| 656 | |
Jeff Brown | 2c43c33 | 2014-06-12 22:38:59 -0700 | [diff] [blame] | 657 | /** |
| 658 | * At the time when the constructor runs, the power manager has not yet been |
| 659 | * initialized. So we initialize our wakelocks afterwards. |
| 660 | */ |
| 661 | void initPowerManagement() { |
chaviw | 59b9885 | 2017-06-13 12:05:44 -0700 | [diff] [blame] | 662 | mPowerManager = (PowerManager)mService.mContext.getSystemService(Context.POWER_SERVICE); |
| 663 | mGoingToSleep = mPowerManager |
| 664 | .newWakeLock(PARTIAL_WAKE_LOCK, "ActivityManager-Sleep"); |
| 665 | mLaunchingActivity = mPowerManager.newWakeLock(PARTIAL_WAKE_LOCK, "*launch*"); |
Craig Mautner | 7ea5bd4 | 2013-07-05 15:27:08 -0700 | [diff] [blame] | 666 | mLaunchingActivity.setReferenceCounted(false); |
Craig Mautner | 2219a1b | 2013-03-25 09:44:30 -0700 | [diff] [blame] | 667 | } |
| 668 | |
Craig Mautner | ce5f3cb | 2013-04-22 08:58:54 -0700 | [diff] [blame] | 669 | void setWindowManager(WindowManagerService wm) { |
Wale Ogunwale | 65ebd95 | 2018-04-25 15:41:44 -0700 | [diff] [blame] | 670 | mWindowManager = wm; |
| 671 | getKeyguardController().setWindowManager(wm); |
Riddle Hsu | 86cb7de | 2018-08-13 23:29:58 +0800 | [diff] [blame] | 672 | setWindowContainerController(new RootWindowContainerController(this)); |
Craig Mautner | 4a1cb22 | 2013-12-04 16:14:06 -0800 | [diff] [blame] | 673 | |
Riddle Hsu | 86cb7de | 2018-08-13 23:29:58 +0800 | [diff] [blame] | 674 | mDisplayManager = mService.mContext.getSystemService(DisplayManager.class); |
Riddle Hsu | f53da81 | 2018-08-15 22:00:27 +0800 | [diff] [blame] | 675 | mDisplayManager.registerDisplayListener(this, mHandler); |
Wale Ogunwale | 65ebd95 | 2018-04-25 15:41:44 -0700 | [diff] [blame] | 676 | mDisplayManagerInternal = LocalServices.getService(DisplayManagerInternal.class); |
Craig Mautner | 4a1cb22 | 2013-12-04 16:14:06 -0800 | [diff] [blame] | 677 | |
Riddle Hsu | 86cb7de | 2018-08-13 23:29:58 +0800 | [diff] [blame] | 678 | final Display[] displays = mDisplayManager.getDisplays(); |
Andrii Kulian | c543add | 2018-09-19 19:02:20 -0700 | [diff] [blame] | 679 | for (int displayNdx = 0; displayNdx < displays.length; ++displayNdx) { |
Wale Ogunwale | 65ebd95 | 2018-04-25 15:41:44 -0700 | [diff] [blame] | 680 | final Display display = displays[displayNdx]; |
Riddle Hsu | 86cb7de | 2018-08-13 23:29:58 +0800 | [diff] [blame] | 681 | final ActivityDisplay activityDisplay = new ActivityDisplay(this, display); |
| 682 | if (activityDisplay.mDisplayId == DEFAULT_DISPLAY) { |
| 683 | mDefaultDisplay = activityDisplay; |
| 684 | } |
| 685 | addChild(activityDisplay, ActivityDisplay.POSITION_TOP); |
Craig Mautner | 4a1cb22 | 2013-12-04 16:14:06 -0800 | [diff] [blame] | 686 | } |
Garfield Tan | 4a48a7f | 2018-10-02 14:23:55 -0700 | [diff] [blame] | 687 | calculateDefaultMinimalSizeOfResizeableTasks(); |
Wale Ogunwale | 65ebd95 | 2018-04-25 15:41:44 -0700 | [diff] [blame] | 688 | |
Andrii Kulian | 52d255c | 2018-07-13 11:32:19 -0700 | [diff] [blame] | 689 | final ActivityDisplay defaultDisplay = getDefaultDisplay(); |
Louis Chang | bd48dca | 2018-08-29 17:44:34 +0800 | [diff] [blame] | 690 | |
Riddle Hsu | bbb63c2 | 2018-10-03 12:28:29 +0800 | [diff] [blame] | 691 | defaultDisplay.getOrCreateStack(WINDOWING_MODE_FULLSCREEN, ACTIVITY_TYPE_HOME, ON_TOP); |
Riddle Hsu | 86cb7de | 2018-08-13 23:29:58 +0800 | [diff] [blame] | 692 | positionChildAt(defaultDisplay, ActivityDisplay.POSITION_TOP); |
| 693 | } |
| 694 | |
| 695 | /** Change the z-order of the given display. */ |
| 696 | private void positionChildAt(ActivityDisplay display, int position) { |
| 697 | if (position >= mActivityDisplays.size()) { |
| 698 | position = mActivityDisplays.size() - 1; |
| 699 | } else if (position < 0) { |
| 700 | position = 0; |
| 701 | } |
| 702 | |
| 703 | if (mActivityDisplays.isEmpty()) { |
| 704 | mActivityDisplays.add(display); |
| 705 | } else if (mActivityDisplays.get(position) != display) { |
| 706 | mActivityDisplays.remove(display); |
| 707 | mActivityDisplays.add(position, display); |
| 708 | } |
| 709 | } |
| 710 | |
| 711 | @Override |
| 712 | public void onChildPositionChanged(DisplayWindowController childController, int position) { |
| 713 | // Assume AM lock is held from positionChildAt of controller in each hierarchy. |
| 714 | final ActivityDisplay display = getActivityDisplay(childController.getDisplayId()); |
| 715 | if (display != null) { |
| 716 | positionChildAt(display, position); |
| 717 | } |
Craig Mautner | 2708430 | 2013-03-25 08:05:25 -0700 | [diff] [blame] | 718 | } |
| 719 | |
Andrii Kulian | 5f750bc | 2018-07-17 08:57:23 -0700 | [diff] [blame] | 720 | ActivityStack getTopDisplayFocusedStack() { |
Riddle Hsu | 86cb7de | 2018-08-13 23:29:58 +0800 | [diff] [blame] | 721 | for (int i = mActivityDisplays.size() - 1; i >= 0; --i) { |
| 722 | final ActivityStack focusedStack = mActivityDisplays.get(i).getFocusedStack(); |
Andrii Kulian | 52d255c | 2018-07-13 11:32:19 -0700 | [diff] [blame] | 723 | if (focusedStack != null) { |
| 724 | return focusedStack; |
| 725 | } |
| 726 | } |
| 727 | return null; |
| 728 | } |
| 729 | |
| 730 | ActivityRecord getTopResumedActivity() { |
Andrii Kulian | 5f750bc | 2018-07-17 08:57:23 -0700 | [diff] [blame] | 731 | final ActivityStack focusedStack = getTopDisplayFocusedStack(); |
Andrii Kulian | 52d255c | 2018-07-13 11:32:19 -0700 | [diff] [blame] | 732 | if (focusedStack == null) { |
| 733 | return null; |
| 734 | } |
| 735 | final ActivityRecord resumedActivity = focusedStack.getResumedActivity(); |
| 736 | if (resumedActivity != null && resumedActivity.app != null) { |
| 737 | return resumedActivity; |
| 738 | } |
| 739 | // The top focused stack might not have a resumed activity yet - look on all displays in |
| 740 | // focus order. |
Riddle Hsu | 86cb7de | 2018-08-13 23:29:58 +0800 | [diff] [blame] | 741 | for (int i = mActivityDisplays.size() - 1; i >= 0; --i) { |
| 742 | final ActivityDisplay display = mActivityDisplays.get(i); |
Andrii Kulian | 52d255c | 2018-07-13 11:32:19 -0700 | [diff] [blame] | 743 | final ActivityRecord resumedActivityOnDisplay = display.getResumedActivity(); |
| 744 | if (resumedActivityOnDisplay != null) { |
| 745 | return resumedActivityOnDisplay; |
| 746 | } |
| 747 | } |
| 748 | return null; |
Craig Mautner | 20e7227 | 2013-04-01 13:45:53 -0700 | [diff] [blame] | 749 | } |
| 750 | |
Bryce Lee | 7b851cc | 2018-04-10 14:53:13 -0700 | [diff] [blame] | 751 | boolean isFocusable(ConfigurationContainer container, boolean alwaysFocusable) { |
| 752 | if (container.inSplitScreenPrimaryWindowingMode() && mIsDockMinimized) { |
| 753 | return false; |
| 754 | } |
| 755 | |
| 756 | return container.getWindowConfiguration().canReceiveKeys() || alwaysFocusable; |
| 757 | } |
| 758 | |
Andrii Kulian | 5f750bc | 2018-07-17 08:57:23 -0700 | [diff] [blame] | 759 | boolean isTopDisplayFocusedStack(ActivityStack stack) { |
| 760 | return stack != null && stack == getTopDisplayFocusedStack(); |
Craig Mautner | 20e7227 | 2013-04-01 13:45:53 -0700 | [diff] [blame] | 761 | } |
| 762 | |
Matthew Ng | 330757d | 2017-02-28 14:19:17 -0800 | [diff] [blame] | 763 | void moveRecentsStackToFront(String reason) { |
Wale Ogunwale | 04a05ac | 2017-09-17 21:35:02 -0700 | [diff] [blame] | 764 | final ActivityStack recentsStack = getDefaultDisplay().getStack( |
| 765 | WINDOWING_MODE_UNDEFINED, ACTIVITY_TYPE_RECENTS); |
Matthew Ng | 330757d | 2017-02-28 14:19:17 -0800 | [diff] [blame] | 766 | if (recentsStack != null) { |
| 767 | recentsStack.moveToFront(reason); |
| 768 | } |
| 769 | } |
| 770 | |
Louis Chang | bd48dca | 2018-08-29 17:44:34 +0800 | [diff] [blame] | 771 | boolean resumeHomeActivity(ActivityRecord prev, String reason, int displayId) { |
Wale Ogunwale | 5378374 | 2018-09-16 10:21:51 -0700 | [diff] [blame] | 772 | if (!mService.isBooting() && !mService.isBooted()) { |
Dianne Hackborn | 7622a0f | 2014-09-30 14:31:42 -0700 | [diff] [blame] | 773 | // Not ready yet! |
| 774 | return false; |
| 775 | } |
| 776 | |
Louis Chang | bd48dca | 2018-08-29 17:44:34 +0800 | [diff] [blame] | 777 | if (displayId == INVALID_DISPLAY) { |
| 778 | displayId = DEFAULT_DISPLAY; |
| 779 | } |
| 780 | |
| 781 | final ActivityRecord r = getActivityDisplay(displayId).getHomeActivity(); |
| 782 | final String myReason = reason + " resumeHomeActivity"; |
Wale Ogunwale | d046a01 | 2015-12-24 13:05:59 -0800 | [diff] [blame] | 783 | |
Mark Lu | a56ea12 | 2015-10-08 13:31:01 +0800 | [diff] [blame] | 784 | // Only resume home activity if isn't finishing. |
| 785 | if (r != null && !r.finishing) { |
Louis Chang | 1944345 | 2018-10-09 12:10:21 +0800 | [diff] [blame] | 786 | r.moveFocusableActivityToTop(myReason); |
Louis Chang | bd48dca | 2018-08-29 17:44:34 +0800 | [diff] [blame] | 787 | return resumeFocusedStacksTopActivitiesLocked(r.getStack(), prev, null); |
Craig Mautner | 69ada55 | 2013-04-18 13:51:51 -0700 | [diff] [blame] | 788 | } |
Louis Chang | 89f43fc | 2018-10-05 10:59:14 +0800 | [diff] [blame] | 789 | return startHomeOnDisplay(mCurrentUser, myReason, displayId); |
Louis Chang | bd48dca | 2018-08-29 17:44:34 +0800 | [diff] [blame] | 790 | } |
| 791 | |
Louis Chang | dd3592a | 2018-11-05 11:04:14 +0800 | [diff] [blame] | 792 | /** |
| 793 | * Check if home activity start should be allowed on a display. |
| 794 | * @param homeInfo {@code ActivityInfo} of the home activity that is going to be launched. |
| 795 | * @param displayId The id of the target display. |
| 796 | * @param allowInstrumenting Whether launching home should be allowed if being instrumented. |
| 797 | * @return {@code true} if allow to launch, {@code false} otherwise. |
| 798 | */ |
| 799 | boolean canStartHomeOnDisplay(ActivityInfo homeInfo, int displayId, |
| 800 | boolean allowInstrumenting) { |
Louis Chang | 89f43fc | 2018-10-05 10:59:14 +0800 | [diff] [blame] | 801 | if (mService.mFactoryTest == FactoryTest.FACTORY_TEST_LOW_LEVEL |
| 802 | && mService.mTopAction == null) { |
| 803 | // We are running in factory test mode, but unable to find the factory test app, so |
| 804 | // just sit around displaying the error message and don't try to start anything. |
| 805 | return false; |
| 806 | } |
| 807 | |
| 808 | final WindowProcessController app = |
| 809 | mService.getProcessController(homeInfo.processName, homeInfo.applicationInfo.uid); |
Louis Chang | dd3592a | 2018-11-05 11:04:14 +0800 | [diff] [blame] | 810 | if (!allowInstrumenting && app != null && app.isInstrumenting()) { |
Louis Chang | 89f43fc | 2018-10-05 10:59:14 +0800 | [diff] [blame] | 811 | // Don't do this if the home app is currently being instrumented. |
| 812 | return false; |
| 813 | } |
| 814 | |
Louis Chang | 39ba54b | 2018-10-18 11:28:57 +0800 | [diff] [blame] | 815 | if (displayId == DEFAULT_DISPLAY || (displayId != INVALID_DISPLAY |
| 816 | && displayId == mService.mVr2dDisplayId)) { |
| 817 | // No restrictions to default display or vr 2d display. |
Louis Chang | bd48dca | 2018-08-29 17:44:34 +0800 | [diff] [blame] | 818 | return true; |
| 819 | } |
| 820 | |
| 821 | final ActivityDisplay display = getActivityDisplay(displayId); |
| 822 | if (display == null || display.isRemoved() || !display.supportsSystemDecorations()) { |
| 823 | // Can't launch home on display that doesn't support system decorations. |
| 824 | return false; |
| 825 | } |
| 826 | |
Louis Chang | 89f43fc | 2018-10-05 10:59:14 +0800 | [diff] [blame] | 827 | final boolean supportMultipleInstance = homeInfo.launchMode != LAUNCH_SINGLE_TASK |
| 828 | && homeInfo.launchMode != LAUNCH_SINGLE_INSTANCE; |
Louis Chang | bd48dca | 2018-08-29 17:44:34 +0800 | [diff] [blame] | 829 | if (!supportMultipleInstance) { |
| 830 | // Can't launch home on other displays if it requested to be single instance. |
| 831 | return false; |
| 832 | } |
| 833 | |
| 834 | return true; |
Craig Mautner | 69ada55 | 2013-04-18 13:51:51 -0700 | [diff] [blame] | 835 | } |
| 836 | |
Craig Mautner | 8d341ef | 2013-03-26 09:03:27 -0700 | [diff] [blame] | 837 | TaskRecord anyTaskForIdLocked(int id) { |
Wale Ogunwale | 0568aed | 2017-09-08 13:29:37 -0700 | [diff] [blame] | 838 | return anyTaskForIdLocked(id, MATCH_TASK_IN_STACKS_OR_RECENT_TASKS_AND_RESTORE); |
| 839 | } |
| 840 | |
| 841 | TaskRecord anyTaskForIdLocked(int id, @AnyTaskForIdMatchTaskMode int matchMode) { |
Wale Ogunwale | ab5de37 | 2017-10-18 06:46:31 -0700 | [diff] [blame] | 842 | return anyTaskForIdLocked(id, matchMode, null, !ON_TOP); |
Wale Ogunwale | 04f4d6b | 2015-03-11 09:23:25 -0700 | [diff] [blame] | 843 | } |
| 844 | |
| 845 | /** |
Bryce Lee | 92b7b65 | 2017-04-03 08:33:11 -0700 | [diff] [blame] | 846 | * Returns a {@link TaskRecord} for the input id if available. {@code null} otherwise. |
Wale Ogunwale | 04f4d6b | 2015-03-11 09:23:25 -0700 | [diff] [blame] | 847 | * @param id Id of the task we would like returned. |
Winson Chung | 7900bee | 2017-03-10 08:59:25 -0800 | [diff] [blame] | 848 | * @param matchMode The mode to match the given task id in. |
Wale Ogunwale | 0568aed | 2017-09-08 13:29:37 -0700 | [diff] [blame] | 849 | * @param aOptions The activity options to use for restoration. Can be null. |
Wale Ogunwale | ab5de37 | 2017-10-18 06:46:31 -0700 | [diff] [blame] | 850 | * @param onTop If the stack for the task should be the topmost on the display. |
Wale Ogunwale | 04f4d6b | 2015-03-11 09:23:25 -0700 | [diff] [blame] | 851 | */ |
Wale Ogunwale | 0568aed | 2017-09-08 13:29:37 -0700 | [diff] [blame] | 852 | TaskRecord anyTaskForIdLocked(int id, @AnyTaskForIdMatchTaskMode int matchMode, |
Wale Ogunwale | ab5de37 | 2017-10-18 06:46:31 -0700 | [diff] [blame] | 853 | @Nullable ActivityOptions aOptions, boolean onTop) { |
| 854 | // If options are set, ensure that we are attempting to actually restore a task |
Wale Ogunwale | 0568aed | 2017-09-08 13:29:37 -0700 | [diff] [blame] | 855 | if (matchMode != MATCH_TASK_IN_STACKS_OR_RECENT_TASKS_AND_RESTORE && aOptions != null) { |
| 856 | throw new IllegalArgumentException("Should not specify activity options for non-restore" |
| 857 | + " lookup"); |
Winson Chung | 7900bee | 2017-03-10 08:59:25 -0800 | [diff] [blame] | 858 | } |
| 859 | |
Craig Mautner | e0a3884 | 2013-12-16 16:14:02 -0800 | [diff] [blame] | 860 | int numDisplays = mActivityDisplays.size(); |
Craig Mautner | 4a1cb22 | 2013-12-04 16:14:06 -0800 | [diff] [blame] | 861 | for (int displayNdx = 0; displayNdx < numDisplays; ++displayNdx) { |
Riddle Hsu | 86cb7de | 2018-08-13 23:29:58 +0800 | [diff] [blame] | 862 | final ActivityDisplay display = mActivityDisplays.get(displayNdx); |
Wale Ogunwale | a0f5b5e | 2017-10-11 09:37:23 -0700 | [diff] [blame] | 863 | for (int stackNdx = display.getChildCount() - 1; stackNdx >= 0; --stackNdx) { |
| 864 | final ActivityStack stack = display.getChildAt(stackNdx); |
Bryce Lee | 92b7b65 | 2017-04-03 08:33:11 -0700 | [diff] [blame] | 865 | final TaskRecord task = stack.taskForIdLocked(id); |
Wale Ogunwale | ab5de37 | 2017-10-18 06:46:31 -0700 | [diff] [blame] | 866 | if (task == null) { |
| 867 | continue; |
Craig Mautner | 4a1cb22 | 2013-12-04 16:14:06 -0800 | [diff] [blame] | 868 | } |
Wale Ogunwale | ab5de37 | 2017-10-18 06:46:31 -0700 | [diff] [blame] | 869 | if (aOptions != null) { |
| 870 | // Resolve the stack the task should be placed in now based on options |
| 871 | // and reparent if needed. |
| 872 | final ActivityStack launchStack = getLaunchStack(null, aOptions, task, onTop); |
| 873 | if (launchStack != null && stack != launchStack) { |
| 874 | final int reparentMode = onTop |
| 875 | ? REPARENT_MOVE_STACK_TO_FRONT : REPARENT_LEAVE_STACK_IN_PLACE; |
| 876 | task.reparent(launchStack, onTop, reparentMode, ANIMATE, DEFER_RESUME, |
| 877 | "anyTaskForIdLocked"); |
| 878 | } |
| 879 | } |
| 880 | return task; |
Craig Mautner | 8d341ef | 2013-03-26 09:03:27 -0700 | [diff] [blame] | 881 | } |
| 882 | } |
Wale Ogunwale | 7de0535 | 2014-12-12 15:21:33 -0800 | [diff] [blame] | 883 | |
Winson Chung | 7900bee | 2017-03-10 08:59:25 -0800 | [diff] [blame] | 884 | // If we are matching stack tasks only, return now |
| 885 | if (matchMode == MATCH_TASK_IN_STACKS_ONLY) { |
Wale Ogunwale | 7de0535 | 2014-12-12 15:21:33 -0800 | [diff] [blame] | 886 | return null; |
| 887 | } |
| 888 | |
Winson Chung | 7900bee | 2017-03-10 08:59:25 -0800 | [diff] [blame] | 889 | // Otherwise, check the recent tasks and return if we find it there and we are not restoring |
| 890 | // the task from recents |
| 891 | if (DEBUG_RECENTS) Slog.v(TAG_RECENTS, "Looking for task id=" + id + " in recents"); |
Winson Chung | 1dbc811 | 2017-09-28 18:05:31 -0700 | [diff] [blame] | 892 | final TaskRecord task = mRecentTasks.getTask(id); |
Bryce Lee | 92b7b65 | 2017-04-03 08:33:11 -0700 | [diff] [blame] | 893 | |
| 894 | if (task == null) { |
| 895 | if (DEBUG_RECENTS) { |
Winson Chung | 7900bee | 2017-03-10 08:59:25 -0800 | [diff] [blame] | 896 | Slog.d(TAG_RECENTS, "\tDidn't find task id=" + id + " in recents"); |
| 897 | } |
Bryce Lee | 92b7b65 | 2017-04-03 08:33:11 -0700 | [diff] [blame] | 898 | |
| 899 | return null; |
| 900 | } |
| 901 | |
| 902 | if (matchMode == MATCH_TASK_IN_STACKS_OR_RECENT_TASKS) { |
Wale Ogunwale | 04f4d6b | 2015-03-11 09:23:25 -0700 | [diff] [blame] | 903 | return task; |
| 904 | } |
| 905 | |
Winson Chung | 7900bee | 2017-03-10 08:59:25 -0800 | [diff] [blame] | 906 | // Implicitly, this case is MATCH_TASK_IN_STACKS_OR_RECENT_TASKS_AND_RESTORE |
Wale Ogunwale | ab5de37 | 2017-10-18 06:46:31 -0700 | [diff] [blame] | 907 | if (!restoreRecentTaskLocked(task, aOptions, onTop)) { |
Wale Ogunwale | ee006da | 2015-03-30 14:49:25 -0700 | [diff] [blame] | 908 | if (DEBUG_RECENTS) Slog.w(TAG_RECENTS, |
| 909 | "Couldn't restore task id=" + id + " found in recents"); |
Wale Ogunwale | 7de0535 | 2014-12-12 15:21:33 -0800 | [diff] [blame] | 910 | return null; |
| 911 | } |
Wale Ogunwale | ee006da | 2015-03-30 14:49:25 -0700 | [diff] [blame] | 912 | if (DEBUG_RECENTS) Slog.w(TAG_RECENTS, "Restored task id=" + id + " from in recents"); |
Wale Ogunwale | 7de0535 | 2014-12-12 15:21:33 -0800 | [diff] [blame] | 913 | return task; |
Craig Mautner | 8d341ef | 2013-03-26 09:03:27 -0700 | [diff] [blame] | 914 | } |
| 915 | |
Craig Mautner | 6170f73 | 2013-04-02 13:05:23 -0700 | [diff] [blame] | 916 | ActivityRecord isInAnyStackLocked(IBinder token) { |
Craig Mautner | e0a3884 | 2013-12-16 16:14:02 -0800 | [diff] [blame] | 917 | int numDisplays = mActivityDisplays.size(); |
Craig Mautner | 4a1cb22 | 2013-12-04 16:14:06 -0800 | [diff] [blame] | 918 | for (int displayNdx = 0; displayNdx < numDisplays; ++displayNdx) { |
Riddle Hsu | 86cb7de | 2018-08-13 23:29:58 +0800 | [diff] [blame] | 919 | final ActivityDisplay display = mActivityDisplays.get(displayNdx); |
Wale Ogunwale | a0f5b5e | 2017-10-11 09:37:23 -0700 | [diff] [blame] | 920 | for (int stackNdx = display.getChildCount() - 1; stackNdx >= 0; --stackNdx) { |
| 921 | final ActivityStack stack = display.getChildAt(stackNdx); |
| 922 | final ActivityRecord r = stack.isInStackLocked(token); |
Craig Mautner | 4a1cb22 | 2013-12-04 16:14:06 -0800 | [diff] [blame] | 923 | if (r != null) { |
| 924 | return r; |
| 925 | } |
Craig Mautner | 6170f73 | 2013-04-02 13:05:23 -0700 | [diff] [blame] | 926 | } |
| 927 | } |
| 928 | return null; |
| 929 | } |
| 930 | |
Tony Mak | 853304c | 2016-04-18 15:17:41 +0100 | [diff] [blame] | 931 | /** |
Robin Lee | 3fef1f2 | 2016-12-20 14:50:13 +0000 | [diff] [blame] | 932 | * Detects whether we should show a lock screen in front of this task for a locked user. |
| 933 | * <p> |
| 934 | * We'll do this if either of the following holds: |
| 935 | * <ul> |
| 936 | * <li>The top activity explicitly belongs to {@param userId}.</li> |
| 937 | * <li>The top activity returns a result to an activity belonging to {@param userId}.</li> |
| 938 | * </ul> |
| 939 | * |
| 940 | * @return {@code true} if the top activity looks like it belongs to {@param userId}. |
Tony Mak | 853304c | 2016-04-18 15:17:41 +0100 | [diff] [blame] | 941 | */ |
Robin Lee | 3fef1f2 | 2016-12-20 14:50:13 +0000 | [diff] [blame] | 942 | private boolean taskTopActivityIsUser(TaskRecord task, @UserIdInt int userId) { |
| 943 | // To handle the case that work app is in the task but just is not the top one. |
| 944 | final ActivityRecord activityRecord = task.getTopActivity(); |
| 945 | final ActivityRecord resultTo = (activityRecord != null ? activityRecord.resultTo : null); |
| 946 | |
| 947 | return (activityRecord != null && activityRecord.userId == userId) |
| 948 | || (resultTo != null && resultTo.userId == userId); |
| 949 | } |
| 950 | |
| 951 | /** |
| 952 | * Find all visible task stacks containing {@param userId} and intercept them with an activity |
| 953 | * to block out the contents and possibly start a credential-confirming intent. |
| 954 | * |
| 955 | * @param userId user handle for the locked managed profile. |
| 956 | */ |
| 957 | void lockAllProfileTasks(@UserIdInt int userId) { |
| 958 | mWindowManager.deferSurfaceLayout(); |
| 959 | try { |
Wale Ogunwale | a0f5b5e | 2017-10-11 09:37:23 -0700 | [diff] [blame] | 960 | for (int displayNdx = mActivityDisplays.size() - 1; displayNdx >= 0; --displayNdx) { |
Riddle Hsu | 86cb7de | 2018-08-13 23:29:58 +0800 | [diff] [blame] | 961 | final ActivityDisplay display = mActivityDisplays.get(displayNdx); |
Wale Ogunwale | a0f5b5e | 2017-10-11 09:37:23 -0700 | [diff] [blame] | 962 | for (int stackNdx = display.getChildCount() - 1; stackNdx >= 0; --stackNdx) { |
| 963 | final ActivityStack stack = display.getChildAt(stackNdx); |
| 964 | final List<TaskRecord> tasks = stack.getAllTasks(); |
| 965 | for (int taskNdx = tasks.size() - 1; taskNdx >= 0; taskNdx--) { |
| 966 | final TaskRecord task = tasks.get(taskNdx); |
Robin Lee | 3fef1f2 | 2016-12-20 14:50:13 +0000 | [diff] [blame] | 967 | |
Wale Ogunwale | a0f5b5e | 2017-10-11 09:37:23 -0700 | [diff] [blame] | 968 | // Check the task for a top activity belonging to userId, or returning a |
| 969 | // result to an activity belonging to userId. Example case: a document |
| 970 | // picker for personal files, opened by a work app, should still get locked. |
| 971 | if (taskTopActivityIsUser(task, userId)) { |
Wale Ogunwale | f673393 | 2018-06-27 05:14:34 -0700 | [diff] [blame] | 972 | mService.getTaskChangeNotificationController().notifyTaskProfileLocked( |
Wale Ogunwale | a0f5b5e | 2017-10-11 09:37:23 -0700 | [diff] [blame] | 973 | task.taskId, userId); |
| 974 | } |
Robin Lee | 3fef1f2 | 2016-12-20 14:50:13 +0000 | [diff] [blame] | 975 | } |
Tony Mak | 853304c | 2016-04-18 15:17:41 +0100 | [diff] [blame] | 976 | } |
| 977 | } |
Robin Lee | 3fef1f2 | 2016-12-20 14:50:13 +0000 | [diff] [blame] | 978 | } finally { |
| 979 | mWindowManager.continueSurfaceLayout(); |
Tony Mak | 853304c | 2016-04-18 15:17:41 +0100 | [diff] [blame] | 980 | } |
Clara Bayarri | f0649ce | 2016-01-14 12:30:42 +0000 | [diff] [blame] | 981 | } |
| 982 | |
Suprabh Shukla | 09a88f5 | 2015-12-02 14:36:31 -0800 | [diff] [blame] | 983 | void setNextTaskIdForUserLocked(int taskId, int userId) { |
| 984 | final int currentTaskId = mCurTaskIdForUser.get(userId, -1); |
| 985 | if (taskId > currentTaskId) { |
| 986 | mCurTaskIdForUser.put(userId, taskId); |
Craig Mautner | ef73ee1 | 2014-04-23 11:45:37 -0700 | [diff] [blame] | 987 | } |
| 988 | } |
| 989 | |
Chong Zhang | d9d35bd | 2016-08-04 17:55:21 -0700 | [diff] [blame] | 990 | static int nextTaskIdForUser(int taskId, int userId) { |
| 991 | int nextTaskId = taskId + 1; |
| 992 | if (nextTaskId == (userId + 1) * MAX_TASK_IDS_PER_USER) { |
| 993 | // Wrap around as there will be smaller task ids that are available now. |
| 994 | nextTaskId -= MAX_TASK_IDS_PER_USER; |
| 995 | } |
| 996 | return nextTaskId; |
| 997 | } |
| 998 | |
Suprabh Shukla | 09a88f5 | 2015-12-02 14:36:31 -0800 | [diff] [blame] | 999 | int getNextTaskIdForUserLocked(int userId) { |
Suprabh Shukla | 09a88f5 | 2015-12-02 14:36:31 -0800 | [diff] [blame] | 1000 | final int currentTaskId = mCurTaskIdForUser.get(userId, userId * MAX_TASK_IDS_PER_USER); |
| 1001 | // for a userId u, a taskId can only be in the range |
| 1002 | // [u*MAX_TASK_IDS_PER_USER, (u+1)*MAX_TASK_IDS_PER_USER-1], so if MAX_TASK_IDS_PER_USER |
| 1003 | // was 10, user 0 could only have taskIds 0 to 9, user 1: 10 to 19, user 2: 20 to 29, so on. |
Chong Zhang | d9d35bd | 2016-08-04 17:55:21 -0700 | [diff] [blame] | 1004 | int candidateTaskId = nextTaskIdForUser(currentTaskId, userId); |
Winson Chung | 1dbc811 | 2017-09-28 18:05:31 -0700 | [diff] [blame] | 1005 | while (mRecentTasks.containsTaskId(candidateTaskId, userId) |
Wale Ogunwale | 0568aed | 2017-09-08 13:29:37 -0700 | [diff] [blame] | 1006 | || anyTaskForIdLocked( |
| 1007 | candidateTaskId, MATCH_TASK_IN_STACKS_OR_RECENT_TASKS) != null) { |
Chong Zhang | d9d35bd | 2016-08-04 17:55:21 -0700 | [diff] [blame] | 1008 | candidateTaskId = nextTaskIdForUser(candidateTaskId, userId); |
Suprabh Shukla | 09a88f5 | 2015-12-02 14:36:31 -0800 | [diff] [blame] | 1009 | if (candidateTaskId == currentTaskId) { |
| 1010 | // Something wrong! |
| 1011 | // All MAX_TASK_IDS_PER_USER task ids are taken up by running tasks for this user |
| 1012 | throw new IllegalStateException("Cannot get an available task id." |
| 1013 | + " Reached limit of " + MAX_TASK_IDS_PER_USER |
| 1014 | + " running tasks per user."); |
| 1015 | } |
| 1016 | } |
| 1017 | mCurTaskIdForUser.put(userId, candidateTaskId); |
| 1018 | return candidateTaskId; |
Craig Mautner | 8d341ef | 2013-03-26 09:03:27 -0700 | [diff] [blame] | 1019 | } |
| 1020 | |
Wale Ogunwale | 31913b5 | 2018-10-13 08:29:31 -0700 | [diff] [blame] | 1021 | boolean attachApplicationLocked(WindowProcessController app) throws RemoteException { |
| 1022 | final String processName = app.mName; |
Craig Mautner | 4a1cb22 | 2013-12-04 16:14:06 -0800 | [diff] [blame] | 1023 | boolean didSomething = false; |
Craig Mautner | e0a3884 | 2013-12-16 16:14:02 -0800 | [diff] [blame] | 1024 | for (int displayNdx = mActivityDisplays.size() - 1; displayNdx >= 0; --displayNdx) { |
Riddle Hsu | 86cb7de | 2018-08-13 23:29:58 +0800 | [diff] [blame] | 1025 | final ActivityDisplay display = mActivityDisplays.get(displayNdx); |
Wale Ogunwale | a0f5b5e | 2017-10-11 09:37:23 -0700 | [diff] [blame] | 1026 | for (int stackNdx = display.getChildCount() - 1; stackNdx >= 0; --stackNdx) { |
| 1027 | final ActivityStack stack = display.getChildAt(stackNdx); |
Andrii Kulian | 5f750bc | 2018-07-17 08:57:23 -0700 | [diff] [blame] | 1028 | if (!isTopDisplayFocusedStack(stack)) { |
Craig Mautner | 4a1cb22 | 2013-12-04 16:14:06 -0800 | [diff] [blame] | 1029 | continue; |
| 1030 | } |
Jorim Jaggi | ea039a8 | 2017-08-02 14:37:49 +0200 | [diff] [blame] | 1031 | stack.getAllRunningVisibleActivitiesLocked(mTmpActivityList); |
| 1032 | final ActivityRecord top = stack.topRunningActivityLocked(); |
| 1033 | final int size = mTmpActivityList.size(); |
| 1034 | for (int i = 0; i < size; i++) { |
| 1035 | final ActivityRecord activity = mTmpActivityList.get(i); |
Wale Ogunwale | 31913b5 | 2018-10-13 08:29:31 -0700 | [diff] [blame] | 1036 | if (activity.app == null && app.mUid == activity.info.applicationInfo.uid |
Jorim Jaggi | ea039a8 | 2017-08-02 14:37:49 +0200 | [diff] [blame] | 1037 | && processName.equals(activity.processName)) { |
Craig Mautner | 4a1cb22 | 2013-12-04 16:14:06 -0800 | [diff] [blame] | 1038 | try { |
Wale Ogunwale | 9c10302 | 2018-10-18 07:44:54 -0700 | [diff] [blame] | 1039 | if (realStartActivityLocked(activity, app, |
Jorim Jaggi | ea039a8 | 2017-08-02 14:37:49 +0200 | [diff] [blame] | 1040 | top == activity /* andResume */, true /* checkConfig */)) { |
Craig Mautner | 4a1cb22 | 2013-12-04 16:14:06 -0800 | [diff] [blame] | 1041 | didSomething = true; |
| 1042 | } |
Dianne Hackborn | ff07272 | 2014-09-24 10:56:28 -0700 | [diff] [blame] | 1043 | } catch (RemoteException e) { |
Craig Mautner | 4a1cb22 | 2013-12-04 16:14:06 -0800 | [diff] [blame] | 1044 | Slog.w(TAG, "Exception in new application when starting activity " |
Jorim Jaggi | ea039a8 | 2017-08-02 14:37:49 +0200 | [diff] [blame] | 1045 | + top.intent.getComponent().flattenToShortString(), e); |
Craig Mautner | 4a1cb22 | 2013-12-04 16:14:06 -0800 | [diff] [blame] | 1046 | throw e; |
Craig Mautner | 20e7227 | 2013-04-01 13:45:53 -0700 | [diff] [blame] | 1047 | } |
Craig Mautner | 20e7227 | 2013-04-01 13:45:53 -0700 | [diff] [blame] | 1048 | } |
Craig Mautner | 20e7227 | 2013-04-01 13:45:53 -0700 | [diff] [blame] | 1049 | } |
| 1050 | } |
| 1051 | } |
Craig Mautner | b59dcfd | 2013-05-06 13:12:58 -0700 | [diff] [blame] | 1052 | if (!didSomething) { |
Filip Gruszczynski | bc5a6c5 | 2015-09-22 13:13:24 -0700 | [diff] [blame] | 1053 | ensureActivitiesVisibleLocked(null, 0, !PRESERVE_WINDOWS); |
Craig Mautner | b59dcfd | 2013-05-06 13:12:58 -0700 | [diff] [blame] | 1054 | } |
Craig Mautner | 20e7227 | 2013-04-01 13:45:53 -0700 | [diff] [blame] | 1055 | return didSomething; |
| 1056 | } |
| 1057 | |
| 1058 | boolean allResumedActivitiesIdle() { |
Craig Mautner | e0a3884 | 2013-12-16 16:14:02 -0800 | [diff] [blame] | 1059 | for (int displayNdx = mActivityDisplays.size() - 1; displayNdx >= 0; --displayNdx) { |
Louis Chang | d17c657 | 2018-11-07 16:27:20 +0800 | [diff] [blame] | 1060 | // TODO(b/117135575): Check resumed activities on all visible stacks. |
Riddle Hsu | 86cb7de | 2018-08-13 23:29:58 +0800 | [diff] [blame] | 1061 | final ActivityDisplay display = mActivityDisplays.get(displayNdx); |
Louis Chang | d17c657 | 2018-11-07 16:27:20 +0800 | [diff] [blame] | 1062 | if (display.isSleeping()) { |
| 1063 | // No resumed activities while display is sleeping. |
| 1064 | continue; |
| 1065 | } |
| 1066 | |
| 1067 | // If the focused stack is not null or not empty, there should have some activities |
| 1068 | // resuming or resumed. Make sure these activities are idle. |
| 1069 | final ActivityStack stack = display.getFocusedStack(); |
| 1070 | if (stack == null || stack.numActivities() == 0) { |
| 1071 | continue; |
| 1072 | } |
| 1073 | final ActivityRecord resumedActivity = stack.getResumedActivity(); |
| 1074 | if (resumedActivity == null || !resumedActivity.idle) { |
| 1075 | if (DEBUG_STATES) { |
| 1076 | Slog.d(TAG_STATES, "allResumedActivitiesIdle: stack=" |
| 1077 | + stack.mStackId + " " + resumedActivity + " not idle"); |
Craig Mautner | 4a1cb22 | 2013-12-04 16:14:06 -0800 | [diff] [blame] | 1078 | } |
Louis Chang | d17c657 | 2018-11-07 16:27:20 +0800 | [diff] [blame] | 1079 | return false; |
Craig Mautner | 20e7227 | 2013-04-01 13:45:53 -0700 | [diff] [blame] | 1080 | } |
| 1081 | } |
Wei Wang | 65c7a15 | 2016-06-02 18:51:22 -0700 | [diff] [blame] | 1082 | // Send launch end powerhint when idle |
Bryce Lee | d3624e1 | 2017-11-30 08:51:45 -0800 | [diff] [blame] | 1083 | sendPowerHintForLaunchEndIfNeeded(); |
Craig Mautner | 20e7227 | 2013-04-01 13:45:53 -0700 | [diff] [blame] | 1084 | return true; |
| 1085 | } |
| 1086 | |
Wale Ogunwale | a0f5b5e | 2017-10-11 09:37:23 -0700 | [diff] [blame] | 1087 | private boolean allResumedActivitiesVisible() { |
riddle_hsu | db46d6b | 2015-04-01 18:58:07 +0800 | [diff] [blame] | 1088 | boolean foundResumed = false; |
Craig Mautner | e0a3884 | 2013-12-16 16:14:02 -0800 | [diff] [blame] | 1089 | for (int displayNdx = mActivityDisplays.size() - 1; displayNdx >= 0; --displayNdx) { |
Riddle Hsu | 86cb7de | 2018-08-13 23:29:58 +0800 | [diff] [blame] | 1090 | final ActivityDisplay display = mActivityDisplays.get(displayNdx); |
Wale Ogunwale | a0f5b5e | 2017-10-11 09:37:23 -0700 | [diff] [blame] | 1091 | for (int stackNdx = display.getChildCount() - 1; stackNdx >= 0; --stackNdx) { |
| 1092 | final ActivityStack stack = display.getChildAt(stackNdx); |
Bryce Lee | c4ab62a | 2018-03-05 14:19:26 -0800 | [diff] [blame] | 1093 | final ActivityRecord r = stack.getResumedActivity(); |
riddle_hsu | db46d6b | 2015-04-01 18:58:07 +0800 | [diff] [blame] | 1094 | if (r != null) { |
Bryce Lee | 4a19438 | 2017-04-04 14:32:48 -0700 | [diff] [blame] | 1095 | if (!r.nowVisible || mActivitiesWaitingForVisibleActivity.contains(r)) { |
riddle_hsu | db46d6b | 2015-04-01 18:58:07 +0800 | [diff] [blame] | 1096 | return false; |
| 1097 | } |
| 1098 | foundResumed = true; |
Craig Mautner | 4a1cb22 | 2013-12-04 16:14:06 -0800 | [diff] [blame] | 1099 | } |
Craig Mautner | de4ef02 | 2013-04-07 19:01:33 -0700 | [diff] [blame] | 1100 | } |
| 1101 | } |
riddle_hsu | db46d6b | 2015-04-01 18:58:07 +0800 | [diff] [blame] | 1102 | return foundResumed; |
Craig Mautner | de4ef02 | 2013-04-07 19:01:33 -0700 | [diff] [blame] | 1103 | } |
| 1104 | |
lumark | 588a3e8 | 2018-07-20 18:53:54 +0800 | [diff] [blame] | 1105 | private void executeAppTransitionForAllDisplay() { |
| 1106 | for (int displayNdx = mActivityDisplays.size() - 1; displayNdx >= 0; --displayNdx) { |
| 1107 | final ActivityDisplay display = mActivityDisplays.get(displayNdx); |
| 1108 | display.getWindowContainerController().executeAppTransition(); |
| 1109 | } |
| 1110 | } |
| 1111 | |
Craig Mautner | 2acc389 | 2013-09-23 10:28:14 -0700 | [diff] [blame] | 1112 | /** |
| 1113 | * Pause all activities in either all of the stacks or just the back stacks. |
| 1114 | * @param userLeaving Passed to pauseActivity() to indicate whether to call onUserLeaving(). |
Wale Ogunwale | 950faff | 2016-08-08 09:51:04 -0700 | [diff] [blame] | 1115 | * @param resuming The resuming activity. |
| 1116 | * @param dontWait The resuming activity isn't going to wait for all activities to be paused |
| 1117 | * before resuming. |
Craig Mautner | 2acc389 | 2013-09-23 10:28:14 -0700 | [diff] [blame] | 1118 | * @return true if any activity was paused as a result of this call. |
| 1119 | */ |
Wale Ogunwale | 950faff | 2016-08-08 09:51:04 -0700 | [diff] [blame] | 1120 | boolean pauseBackStacks(boolean userLeaving, ActivityRecord resuming, boolean dontWait) { |
Craig Mautner | cf910b0 | 2013-04-23 11:23:27 -0700 | [diff] [blame] | 1121 | boolean someActivityPaused = false; |
Craig Mautner | e0a3884 | 2013-12-16 16:14:02 -0800 | [diff] [blame] | 1122 | for (int displayNdx = mActivityDisplays.size() - 1; displayNdx >= 0; --displayNdx) { |
Riddle Hsu | 86cb7de | 2018-08-13 23:29:58 +0800 | [diff] [blame] | 1123 | someActivityPaused |= mActivityDisplays.get(displayNdx) |
Andrii Kulian | ab132ee | 2018-07-24 22:10:21 +0800 | [diff] [blame] | 1124 | .pauseBackStacks(userLeaving, resuming, dontWait); |
Craig Mautner | cf910b0 | 2013-04-23 11:23:27 -0700 | [diff] [blame] | 1125 | } |
| 1126 | return someActivityPaused; |
| 1127 | } |
| 1128 | |
Craig Mautner | de4ef02 | 2013-04-07 19:01:33 -0700 | [diff] [blame] | 1129 | boolean allPausedActivitiesComplete() { |
Craig Mautner | ac6f843 | 2013-07-17 13:24:59 -0700 | [diff] [blame] | 1130 | boolean pausing = true; |
Craig Mautner | e0a3884 | 2013-12-16 16:14:02 -0800 | [diff] [blame] | 1131 | for (int displayNdx = mActivityDisplays.size() - 1; displayNdx >= 0; --displayNdx) { |
Riddle Hsu | 86cb7de | 2018-08-13 23:29:58 +0800 | [diff] [blame] | 1132 | final ActivityDisplay display = mActivityDisplays.get(displayNdx); |
Wale Ogunwale | a0f5b5e | 2017-10-11 09:37:23 -0700 | [diff] [blame] | 1133 | for (int stackNdx = display.getChildCount() - 1; stackNdx >= 0; --stackNdx) { |
| 1134 | final ActivityStack stack = display.getChildAt(stackNdx); |
Craig Mautner | 4a1cb22 | 2013-12-04 16:14:06 -0800 | [diff] [blame] | 1135 | final ActivityRecord r = stack.mPausingActivity; |
Bryce Lee | 7ace395 | 2018-02-16 14:34:32 -0800 | [diff] [blame] | 1136 | if (r != null && !r.isState(PAUSED, STOPPED, STOPPING)) { |
Craig Mautner | 4a1cb22 | 2013-12-04 16:14:06 -0800 | [diff] [blame] | 1137 | if (DEBUG_STATES) { |
Wale Ogunwale | 0fc365c | 2015-05-25 19:35:42 -0700 | [diff] [blame] | 1138 | Slog.d(TAG_STATES, |
Bryce Lee | 7ace395 | 2018-02-16 14:34:32 -0800 | [diff] [blame] | 1139 | "allPausedActivitiesComplete: r=" + r + " state=" + r.getState()); |
Craig Mautner | 4a1cb22 | 2013-12-04 16:14:06 -0800 | [diff] [blame] | 1140 | pausing = false; |
| 1141 | } else { |
| 1142 | return false; |
| 1143 | } |
Craig Mautner | ac6f843 | 2013-07-17 13:24:59 -0700 | [diff] [blame] | 1144 | } |
Craig Mautner | de4ef02 | 2013-04-07 19:01:33 -0700 | [diff] [blame] | 1145 | } |
| 1146 | } |
Craig Mautner | ac6f843 | 2013-07-17 13:24:59 -0700 | [diff] [blame] | 1147 | return pausing; |
Craig Mautner | de4ef02 | 2013-04-07 19:01:33 -0700 | [diff] [blame] | 1148 | } |
| 1149 | |
Wale Ogunwale | 2be760d | 2016-02-17 11:16:10 -0800 | [diff] [blame] | 1150 | void cancelInitializingActivities() { |
| 1151 | for (int displayNdx = mActivityDisplays.size() - 1; displayNdx >= 0; --displayNdx) { |
Riddle Hsu | 86cb7de | 2018-08-13 23:29:58 +0800 | [diff] [blame] | 1152 | final ActivityDisplay display = mActivityDisplays.get(displayNdx); |
Wale Ogunwale | a0f5b5e | 2017-10-11 09:37:23 -0700 | [diff] [blame] | 1153 | for (int stackNdx = display.getChildCount() - 1; stackNdx >= 0; --stackNdx) { |
| 1154 | final ActivityStack stack = display.getChildAt(stackNdx); |
| 1155 | stack.cancelInitializingActivities(); |
Wale Ogunwale | 2be760d | 2016-02-17 11:16:10 -0800 | [diff] [blame] | 1156 | } |
| 1157 | } |
| 1158 | } |
| 1159 | |
Vishnu Nair | 132ee83 | 2018-09-28 15:00:05 -0700 | [diff] [blame] | 1160 | void waitActivityVisible(ComponentName name, WaitResult result, long startTimeMs) { |
| 1161 | final WaitInfo waitInfo = new WaitInfo(name, result, startTimeMs); |
Bryce Lee | 4a19438 | 2017-04-04 14:32:48 -0700 | [diff] [blame] | 1162 | mWaitingForActivityVisible.add(waitInfo); |
| 1163 | } |
| 1164 | |
| 1165 | void cleanupActivity(ActivityRecord r) { |
| 1166 | // Make sure this record is no longer in the pending finishes list. |
| 1167 | // This could happen, for example, if we are trimming activities |
| 1168 | // down to the max limit while they are still waiting to finish. |
| 1169 | mFinishingActivities.remove(r); |
| 1170 | mActivitiesWaitingForVisibleActivity.remove(r); |
| 1171 | |
| 1172 | for (int i = mWaitingForActivityVisible.size() - 1; i >= 0; --i) { |
Wale Ogunwale | 3270f17 | 2017-04-26 07:29:42 -0700 | [diff] [blame] | 1173 | if (mWaitingForActivityVisible.get(i).matches(r.realActivity)) { |
Bryce Lee | 4a19438 | 2017-04-04 14:32:48 -0700 | [diff] [blame] | 1174 | mWaitingForActivityVisible.remove(i); |
| 1175 | } |
| 1176 | } |
| 1177 | } |
| 1178 | |
Craig Mautner | ce5f3cb | 2013-04-22 08:58:54 -0700 | [diff] [blame] | 1179 | void reportActivityVisibleLocked(ActivityRecord r) { |
Dianne Hackborn | 6cfbb71 | 2014-09-17 12:47:35 -0700 | [diff] [blame] | 1180 | sendWaitingVisibleReportLocked(r); |
Dianne Hackborn | 6cfbb71 | 2014-09-17 12:47:35 -0700 | [diff] [blame] | 1181 | } |
| 1182 | |
| 1183 | void sendWaitingVisibleReportLocked(ActivityRecord r) { |
| 1184 | boolean changed = false; |
Bryce Lee | 4a19438 | 2017-04-04 14:32:48 -0700 | [diff] [blame] | 1185 | for (int i = mWaitingForActivityVisible.size() - 1; i >= 0; --i) { |
| 1186 | final WaitInfo w = mWaitingForActivityVisible.get(i); |
Wale Ogunwale | 3270f17 | 2017-04-26 07:29:42 -0700 | [diff] [blame] | 1187 | if (w.matches(r.realActivity)) { |
Bryce Lee | 4a19438 | 2017-04-04 14:32:48 -0700 | [diff] [blame] | 1188 | final WaitResult result = w.getResult(); |
Dianne Hackborn | 6cfbb71 | 2014-09-17 12:47:35 -0700 | [diff] [blame] | 1189 | changed = true; |
Bryce Lee | 4a19438 | 2017-04-04 14:32:48 -0700 | [diff] [blame] | 1190 | result.timeout = false; |
| 1191 | result.who = w.getComponent(); |
Vishnu Nair | 132ee83 | 2018-09-28 15:00:05 -0700 | [diff] [blame] | 1192 | result.totalTime = SystemClock.uptimeMillis() - w.getStartTime(); |
Bryce Lee | 4a19438 | 2017-04-04 14:32:48 -0700 | [diff] [blame] | 1193 | mWaitingForActivityVisible.remove(w); |
Craig Mautner | ce5f3cb | 2013-04-22 08:58:54 -0700 | [diff] [blame] | 1194 | } |
Craig Mautner | ce5f3cb | 2013-04-22 08:58:54 -0700 | [diff] [blame] | 1195 | } |
Dianne Hackborn | 6cfbb71 | 2014-09-17 12:47:35 -0700 | [diff] [blame] | 1196 | if (changed) { |
Wale Ogunwale | f673393 | 2018-06-27 05:14:34 -0700 | [diff] [blame] | 1197 | mService.mGlobalLock.notifyAll(); |
Dianne Hackborn | 6cfbb71 | 2014-09-17 12:47:35 -0700 | [diff] [blame] | 1198 | } |
Craig Mautner | ce5f3cb | 2013-04-22 08:58:54 -0700 | [diff] [blame] | 1199 | } |
| 1200 | |
Bryce Lee | 5f0e28f | 2018-01-30 16:00:03 -0800 | [diff] [blame] | 1201 | void reportWaitingActivityLaunchedIfNeeded(ActivityRecord r, int result) { |
| 1202 | if (mWaitingActivityLaunched.isEmpty()) { |
| 1203 | return; |
| 1204 | } |
| 1205 | |
| 1206 | if (result != START_DELIVERED_TO_TOP && result != START_TASK_TO_FRONT) { |
| 1207 | return; |
| 1208 | } |
| 1209 | |
Chong Zhang | 5022da3 | 2016-06-21 16:31:37 -0700 | [diff] [blame] | 1210 | boolean changed = false; |
Bryce Lee | 5f0e28f | 2018-01-30 16:00:03 -0800 | [diff] [blame] | 1211 | |
Chong Zhang | 5022da3 | 2016-06-21 16:31:37 -0700 | [diff] [blame] | 1212 | for (int i = mWaitingActivityLaunched.size() - 1; i >= 0; i--) { |
| 1213 | WaitResult w = mWaitingActivityLaunched.remove(i); |
| 1214 | if (w.who == null) { |
| 1215 | changed = true; |
Bryce Lee | 5f0e28f | 2018-01-30 16:00:03 -0800 | [diff] [blame] | 1216 | w.result = result; |
| 1217 | |
| 1218 | // Unlike START_TASK_TO_FRONT, When an intent is delivered to top, there |
| 1219 | // will be no followup launch signals. Assign the result and launched component. |
| 1220 | if (result == START_DELIVERED_TO_TOP) { |
| 1221 | w.who = r.realActivity; |
| 1222 | } |
Chong Zhang | 5022da3 | 2016-06-21 16:31:37 -0700 | [diff] [blame] | 1223 | } |
| 1224 | } |
Bryce Lee | 5f0e28f | 2018-01-30 16:00:03 -0800 | [diff] [blame] | 1225 | |
Chong Zhang | 5022da3 | 2016-06-21 16:31:37 -0700 | [diff] [blame] | 1226 | if (changed) { |
Wale Ogunwale | f673393 | 2018-06-27 05:14:34 -0700 | [diff] [blame] | 1227 | mService.mGlobalLock.notifyAll(); |
Chong Zhang | 5022da3 | 2016-06-21 16:31:37 -0700 | [diff] [blame] | 1228 | } |
| 1229 | } |
| 1230 | |
Vishnu Nair | 132ee83 | 2018-09-28 15:00:05 -0700 | [diff] [blame] | 1231 | void reportActivityLaunchedLocked(boolean timeout, ActivityRecord r, long totalTime) { |
Dianne Hackborn | 6cfbb71 | 2014-09-17 12:47:35 -0700 | [diff] [blame] | 1232 | boolean changed = false; |
Craig Mautner | ce5f3cb | 2013-04-22 08:58:54 -0700 | [diff] [blame] | 1233 | for (int i = mWaitingActivityLaunched.size() - 1; i >= 0; i--) { |
Craig Mautner | c64f73e | 2013-04-24 16:44:56 -0700 | [diff] [blame] | 1234 | WaitResult w = mWaitingActivityLaunched.remove(i); |
Dianne Hackborn | 6cfbb71 | 2014-09-17 12:47:35 -0700 | [diff] [blame] | 1235 | if (w.who == null) { |
| 1236 | changed = true; |
| 1237 | w.timeout = timeout; |
| 1238 | if (r != null) { |
| 1239 | w.who = new ComponentName(r.info.packageName, r.info.name); |
| 1240 | } |
Dianne Hackborn | 6cfbb71 | 2014-09-17 12:47:35 -0700 | [diff] [blame] | 1241 | w.totalTime = totalTime; |
Chong Zhang | 5022da3 | 2016-06-21 16:31:37 -0700 | [diff] [blame] | 1242 | // Do not modify w.result. |
Craig Mautner | ce5f3cb | 2013-04-22 08:58:54 -0700 | [diff] [blame] | 1243 | } |
Craig Mautner | ce5f3cb | 2013-04-22 08:58:54 -0700 | [diff] [blame] | 1244 | } |
Dianne Hackborn | 6cfbb71 | 2014-09-17 12:47:35 -0700 | [diff] [blame] | 1245 | if (changed) { |
Wale Ogunwale | f673393 | 2018-06-27 05:14:34 -0700 | [diff] [blame] | 1246 | mService.mGlobalLock.notifyAll(); |
Dianne Hackborn | 6cfbb71 | 2014-09-17 12:47:35 -0700 | [diff] [blame] | 1247 | } |
Craig Mautner | ce5f3cb | 2013-04-22 08:58:54 -0700 | [diff] [blame] | 1248 | } |
| 1249 | |
Craig Mautner | 29219d9 | 2013-04-16 20:19:12 -0700 | [diff] [blame] | 1250 | ActivityRecord topRunningActivityLocked() { |
Riddle Hsu | 86cb7de | 2018-08-13 23:29:58 +0800 | [diff] [blame] | 1251 | for (int i = mActivityDisplays.size() - 1; i >= 0; --i) { |
Riddle Hsu | e10cea5 | 2018-10-16 23:33:23 +0800 | [diff] [blame] | 1252 | final ActivityRecord topActivity = mActivityDisplays.get(i).topRunningActivity(); |
| 1253 | if (topActivity != null) { |
Bryce Lee | c961e0a | 2018-04-13 17:58:02 -0700 | [diff] [blame] | 1254 | return topActivity; |
Craig Mautner | 29219d9 | 2013-04-16 20:19:12 -0700 | [diff] [blame] | 1255 | } |
| 1256 | } |
| 1257 | return null; |
| 1258 | } |
| 1259 | |
Winson Chung | 61c9e5a | 2017-10-11 10:39:32 -0700 | [diff] [blame] | 1260 | @VisibleForTesting |
| 1261 | void getRunningTasks(int maxNum, List<RunningTaskInfo> list, |
| 1262 | @ActivityType int ignoreActivityType, @WindowingMode int ignoreWindowingMode, |
| 1263 | int callingUid, boolean allowed) { |
| 1264 | mRunningTasks.getTasks(maxNum, list, ignoreActivityType, ignoreWindowingMode, |
| 1265 | mActivityDisplays, callingUid, allowed); |
Craig Mautner | 20e7227 | 2013-04-01 13:45:53 -0700 | [diff] [blame] | 1266 | } |
| 1267 | |
Todd Kennedy | 7440f17 | 2015-12-09 14:31:22 -0800 | [diff] [blame] | 1268 | ActivityInfo resolveActivity(Intent intent, ResolveInfo rInfo, int startFlags, |
| 1269 | ProfilerInfo profilerInfo) { |
| 1270 | final ActivityInfo aInfo = rInfo != null ? rInfo.activityInfo : null; |
Craig Mautner | 23ac33b | 2013-04-01 16:26:35 -0700 | [diff] [blame] | 1271 | if (aInfo != null) { |
| 1272 | // Store the found target back into the intent, because now that |
| 1273 | // we have it we never want to do this again. For example, if the |
| 1274 | // user navigates back to this point in the history, we should |
| 1275 | // always restart the exact same activity. |
| 1276 | intent.setComponent(new ComponentName( |
| 1277 | aInfo.applicationInfo.packageName, aInfo.name)); |
| 1278 | |
| 1279 | // Don't debug things in the system process |
Man Cao | cfa78b2 | 2015-06-11 20:14:34 -0700 | [diff] [blame] | 1280 | if (!aInfo.processName.equals("system")) { |
Wale Ogunwale | 7056a06 | 2018-10-18 15:02:50 -0700 | [diff] [blame] | 1281 | if ((startFlags & (START_FLAG_DEBUG | START_FLAG_NATIVE_DEBUGGING |
| 1282 | | START_FLAG_TRACK_ALLOCATION)) != 0 || profilerInfo != null) { |
| 1283 | /** |
| 1284 | * Assume safe to call into AMS synchronously because the call that set these |
| 1285 | * flags should have originated from AMS which will already have its lock held. |
| 1286 | * @see ActivityManagerService#startActivityAndWait(IApplicationThread, String, |
| 1287 | * Intent, String, IBinder, String, int, int, ProfilerInfo, Bundle, int) |
| 1288 | * TODO(b/80414790): Investigate a better way of untangling this. |
| 1289 | */ |
| 1290 | mService.mAmInternal.setDebugFlagsForStartingActivity( |
| 1291 | aInfo, startFlags, profilerInfo); |
Craig Mautner | 23ac33b | 2013-04-01 16:26:35 -0700 | [diff] [blame] | 1292 | } |
| 1293 | } |
Todd Kennedy | b3b43130 | 2017-03-20 16:05:48 -0700 | [diff] [blame] | 1294 | final String intentLaunchToken = intent.getLaunchToken(); |
| 1295 | if (aInfo.launchToken == null && intentLaunchToken != null) { |
| 1296 | aInfo.launchToken = intentLaunchToken; |
| 1297 | } |
Craig Mautner | 23ac33b | 2013-04-01 16:26:35 -0700 | [diff] [blame] | 1298 | } |
| 1299 | return aInfo; |
| 1300 | } |
| 1301 | |
Patrick Baumann | 7838027 | 2018-04-04 10:41:01 -0700 | [diff] [blame] | 1302 | ResolveInfo resolveIntent(Intent intent, String resolvedType, int userId, int flags, |
| 1303 | int filterCallingUid) { |
Wale Ogunwale | c9e57de | 2018-05-08 14:28:07 -0700 | [diff] [blame] | 1304 | synchronized (mService.mGlobalLock) { |
Jorim Jaggi | ffe128d | 2017-11-30 13:54:36 +0100 | [diff] [blame] | 1305 | try { |
| 1306 | Trace.traceBegin(TRACE_TAG_ACTIVITY_MANAGER, "resolveIntent"); |
Patrick Baumann | 577d402 | 2018-01-31 16:55:10 +0000 | [diff] [blame] | 1307 | int modifiedFlags = flags |
| 1308 | | PackageManager.MATCH_DEFAULT_ONLY | ActivityManagerService.STOCK_PM_FLAGS; |
Patrick Baumann | 0da8537 | 2018-02-02 16:07:35 -0800 | [diff] [blame] | 1309 | if (intent.isWebIntent() |
Patrick Baumann | 577d402 | 2018-01-31 16:55:10 +0000 | [diff] [blame] | 1310 | || (intent.getFlags() & Intent.FLAG_ACTIVITY_MATCH_EXTERNAL) != 0) { |
| 1311 | modifiedFlags |= PackageManager.MATCH_INSTANT; |
| 1312 | } |
Jorim Jaggi | ffe128d | 2017-11-30 13:54:36 +0100 | [diff] [blame] | 1313 | |
Makoto Onuki | 1a34274 | 2018-04-26 14:56:59 -0700 | [diff] [blame] | 1314 | // In order to allow cross-profile lookup, we clear the calling identity here. |
| 1315 | // Note the binder identity won't affect the result, but filterCallingUid will. |
| 1316 | |
| 1317 | // Cross-user/profile call check are done at the entry points |
| 1318 | // (e.g. AMS.startActivityAsUser). |
| 1319 | final long token = Binder.clearCallingIdentity(); |
| 1320 | try { |
Wale Ogunwale | 906f9c6 | 2018-07-23 11:23:44 -0700 | [diff] [blame] | 1321 | return mService.getPackageManagerInternalLocked().resolveIntent( |
Makoto Onuki | 1a34274 | 2018-04-26 14:56:59 -0700 | [diff] [blame] | 1322 | intent, resolvedType, modifiedFlags, userId, true, filterCallingUid); |
| 1323 | } finally { |
| 1324 | Binder.restoreCallingIdentity(token); |
| 1325 | } |
Jorim Jaggi | ffe128d | 2017-11-30 13:54:36 +0100 | [diff] [blame] | 1326 | } finally { |
| 1327 | Trace.traceEnd(TRACE_TAG_ACTIVITY_MANAGER); |
| 1328 | } |
Todd Kennedy | 7440f17 | 2015-12-09 14:31:22 -0800 | [diff] [blame] | 1329 | } |
Todd Kennedy | 7440f17 | 2015-12-09 14:31:22 -0800 | [diff] [blame] | 1330 | } |
| 1331 | |
| 1332 | ActivityInfo resolveActivity(Intent intent, String resolvedType, int startFlags, |
Patrick Baumann | 7838027 | 2018-04-04 10:41:01 -0700 | [diff] [blame] | 1333 | ProfilerInfo profilerInfo, int userId, int filterCallingUid) { |
| 1334 | final ResolveInfo rInfo = resolveIntent(intent, resolvedType, userId, 0, filterCallingUid); |
Todd Kennedy | 7440f17 | 2015-12-09 14:31:22 -0800 | [diff] [blame] | 1335 | return resolveActivity(intent, rInfo, startFlags, profilerInfo); |
| 1336 | } |
| 1337 | |
Wale Ogunwale | 9c10302 | 2018-10-18 07:44:54 -0700 | [diff] [blame] | 1338 | private boolean realStartActivityLocked(ActivityRecord r, WindowProcessController proc, |
Wale Ogunwale | 5658e4b | 2016-02-12 12:22:19 -0800 | [diff] [blame] | 1339 | boolean andResume, boolean checkConfig) throws RemoteException { |
| 1340 | |
| 1341 | if (!allPausedActivitiesComplete()) { |
| 1342 | // While there are activities pausing we skipping starting any new activities until |
| 1343 | // pauses are complete. NOTE: that we also do this for activities that are starting in |
| 1344 | // the paused state because they will first be resumed then paused on the client side. |
| 1345 | if (DEBUG_SWITCH || DEBUG_PAUSE || DEBUG_STATES) Slog.v(TAG_PAUSE, |
| 1346 | "realStartActivityLocked: Skipping start of r=" + r |
| 1347 | + " some activities pausing..."); |
| 1348 | return false; |
| 1349 | } |
Craig Mautner | 2420ead | 2013-04-01 17:13:20 -0700 | [diff] [blame] | 1350 | |
Bryce Lee | af691c0 | 2017-03-20 14:20:22 -0700 | [diff] [blame] | 1351 | final TaskRecord task = r.getTask(); |
Andrii Kulian | 02b7a83 | 2016-10-06 23:11:56 -0700 | [diff] [blame] | 1352 | final ActivityStack stack = task.getStack(); |
chaviw | 59b9885 | 2017-06-13 12:05:44 -0700 | [diff] [blame] | 1353 | |
| 1354 | beginDeferResume(); |
| 1355 | |
Craig Mautner | 2420ead | 2013-04-01 17:13:20 -0700 | [diff] [blame] | 1356 | try { |
Wale Ogunwale | 9e4f3e0 | 2018-05-17 09:35:39 -0700 | [diff] [blame] | 1357 | r.startFreezingScreenLocked(proc, 0); |
chaviw | 59b9885 | 2017-06-13 12:05:44 -0700 | [diff] [blame] | 1358 | |
| 1359 | // schedule launch ticks to collect information about slow apps. |
| 1360 | r.startLaunchTickingLocked(); |
| 1361 | |
Wale Ogunwale | 9e4f3e0 | 2018-05-17 09:35:39 -0700 | [diff] [blame] | 1362 | r.setProcess(proc); |
chaviw | 59b9885 | 2017-06-13 12:05:44 -0700 | [diff] [blame] | 1363 | |
Bryce Lee | 459c062 | 2018-03-19 11:04:01 -0700 | [diff] [blame] | 1364 | if (getKeyguardController().isKeyguardLocked()) { |
Jorim Jaggi | 838c245 | 2017-08-28 15:44:43 +0200 | [diff] [blame] | 1365 | r.notifyUnknownVisibilityLaunched(); |
| 1366 | } |
| 1367 | |
chaviw | 59b9885 | 2017-06-13 12:05:44 -0700 | [diff] [blame] | 1368 | // Have the window manager re-evaluate the orientation of the screen based on the new |
| 1369 | // activity order. Note that as a result of this, it can call back into the activity |
| 1370 | // manager with a new orientation. We don't care about that, because the activity is |
| 1371 | // not currently running so we are just restarting it anyway. |
| 1372 | if (checkConfig) { |
chaviw | 59b9885 | 2017-06-13 12:05:44 -0700 | [diff] [blame] | 1373 | // Deferring resume here because we're going to launch new activity shortly. |
| 1374 | // We don't want to perform a redundant launch of the same record while ensuring |
| 1375 | // configurations and trying to resume top activity of focused stack. |
Andrii Kulian | f4479ee | 2018-05-23 17:52:48 -0700 | [diff] [blame] | 1376 | ensureVisibilityAndConfig(r, r.getDisplayId(), |
| 1377 | false /* markFrozenIfConfigChanged */, true /* deferResume */); |
Craig Mautner | 2420ead | 2013-04-01 17:13:20 -0700 | [diff] [blame] | 1378 | } |
chaviw | 59b9885 | 2017-06-13 12:05:44 -0700 | [diff] [blame] | 1379 | |
| 1380 | if (r.getStack().checkKeyguardVisibility(r, true /* shouldBeVisible */, |
| 1381 | true /* isTop */)) { |
| 1382 | // We only set the visibility to true if the activity is allowed to be visible |
| 1383 | // based on |
| 1384 | // keyguard state. This avoids setting this into motion in window manager that is |
| 1385 | // later cancelled due to later calls to ensure visible activities that set |
| 1386 | // visibility back to false. |
| 1387 | r.setVisibility(true); |
Craig Mautner | 2420ead | 2013-04-01 17:13:20 -0700 | [diff] [blame] | 1388 | } |
chaviw | 59b9885 | 2017-06-13 12:05:44 -0700 | [diff] [blame] | 1389 | |
chaviw | 59b9885 | 2017-06-13 12:05:44 -0700 | [diff] [blame] | 1390 | final int applicationInfoUid = |
| 1391 | (r.info.applicationInfo != null) ? r.info.applicationInfo.uid : -1; |
Wale Ogunwale | 9c10302 | 2018-10-18 07:44:54 -0700 | [diff] [blame] | 1392 | if ((r.userId != proc.mUserId) || (r.appInfo.uid != applicationInfoUid)) { |
chaviw | 59b9885 | 2017-06-13 12:05:44 -0700 | [diff] [blame] | 1393 | Slog.wtf(TAG, |
| 1394 | "User ID for activity changing for " + r |
| 1395 | + " appInfo.uid=" + r.appInfo.uid |
| 1396 | + " info.ai.uid=" + applicationInfoUid |
Wale Ogunwale | 9c10302 | 2018-10-18 07:44:54 -0700 | [diff] [blame] | 1397 | + " old=" + r.app + " new=" + proc); |
chaviw | 59b9885 | 2017-06-13 12:05:44 -0700 | [diff] [blame] | 1398 | } |
| 1399 | |
Wale Ogunwale | 9c10302 | 2018-10-18 07:44:54 -0700 | [diff] [blame] | 1400 | proc.clearWaitingToKill(); |
chaviw | 59b9885 | 2017-06-13 12:05:44 -0700 | [diff] [blame] | 1401 | r.launchCount++; |
| 1402 | r.lastLaunchTime = SystemClock.uptimeMillis(); |
| 1403 | |
| 1404 | if (DEBUG_ALL) Slog.v(TAG, "Launching: " + r); |
| 1405 | |
Wale Ogunwale | 9e4f3e0 | 2018-05-17 09:35:39 -0700 | [diff] [blame] | 1406 | proc.addActivityIfNeeded(r); |
| 1407 | proc.updateProcessInfo(false, true, true, true); |
chaviw | 59b9885 | 2017-06-13 12:05:44 -0700 | [diff] [blame] | 1408 | |
Wale Ogunwale | c9e57de | 2018-05-08 14:28:07 -0700 | [diff] [blame] | 1409 | final LockTaskController lockTaskController = mService.getLockTaskController(); |
Charles He | ff9b4dff | 2017-09-22 10:18:37 +0100 | [diff] [blame] | 1410 | if (task.mLockTaskAuth == LOCK_TASK_AUTH_LAUNCHABLE |
| 1411 | || task.mLockTaskAuth == LOCK_TASK_AUTH_LAUNCHABLE_PRIV |
| 1412 | || (task.mLockTaskAuth == LOCK_TASK_AUTH_WHITELISTED |
Bryce Lee | 2b8e037 | 2018-04-05 17:01:37 -0700 | [diff] [blame] | 1413 | && lockTaskController.getLockTaskModeState() |
| 1414 | == LOCK_TASK_MODE_LOCKED)) { |
| 1415 | lockTaskController.startLockTaskMode(task, false, 0 /* blank UID */); |
chaviw | 59b9885 | 2017-06-13 12:05:44 -0700 | [diff] [blame] | 1416 | } |
| 1417 | |
| 1418 | try { |
Wale Ogunwale | 9c10302 | 2018-10-18 07:44:54 -0700 | [diff] [blame] | 1419 | if (!proc.hasThread()) { |
chaviw | 59b9885 | 2017-06-13 12:05:44 -0700 | [diff] [blame] | 1420 | throw new RemoteException(); |
| 1421 | } |
| 1422 | List<ResultInfo> results = null; |
| 1423 | List<ReferrerIntent> newIntents = null; |
| 1424 | if (andResume) { |
| 1425 | // We don't need to deliver new intents and/or set results if activity is going |
| 1426 | // to pause immediately after launch. |
| 1427 | results = r.results; |
| 1428 | newIntents = r.newIntents; |
| 1429 | } |
| 1430 | if (DEBUG_SWITCH) Slog.v(TAG_SWITCH, |
| 1431 | "Launching: " + r + " icicle=" + r.icicle + " with results=" + results |
| 1432 | + " newIntents=" + newIntents + " andResume=" + andResume); |
| 1433 | EventLog.writeEvent(EventLogTags.AM_RESTART_ACTIVITY, r.userId, |
| 1434 | System.identityHashCode(r), task.taskId, r.shortComponentName); |
Wale Ogunwale | 6fbde9f | 2017-08-24 07:24:12 -0700 | [diff] [blame] | 1435 | if (r.isActivityTypeHome()) { |
chaviw | 59b9885 | 2017-06-13 12:05:44 -0700 | [diff] [blame] | 1436 | // Home process is the root process of the task. |
Wale Ogunwale | 9e4f3e0 | 2018-05-17 09:35:39 -0700 | [diff] [blame] | 1437 | mService.mHomeProcess = task.mActivities.get(0).app; |
chaviw | 59b9885 | 2017-06-13 12:05:44 -0700 | [diff] [blame] | 1438 | } |
Wale Ogunwale | 214f348 | 2018-10-04 11:00:47 -0700 | [diff] [blame] | 1439 | mService.getPackageManagerInternalLocked().notifyPackageUse( |
| 1440 | r.intent.getComponent().getPackageName(), NOTIFY_PACKAGE_USE_ACTIVITY); |
chaviw | 59b9885 | 2017-06-13 12:05:44 -0700 | [diff] [blame] | 1441 | r.sleeping = false; |
| 1442 | r.forceNewConfig = false; |
Wale Ogunwale | 008163e | 2018-07-23 23:11:08 -0700 | [diff] [blame] | 1443 | mService.getAppWarningsLocked().onStartActivity(r); |
Wale Ogunwale | 5378374 | 2018-09-16 10:21:51 -0700 | [diff] [blame] | 1444 | r.compat = mService.compatibilityInfoForPackageLocked(r.info.applicationInfo); |
Wale Ogunwale | 9c10302 | 2018-10-18 07:44:54 -0700 | [diff] [blame] | 1445 | ProfilerInfo profilerInfo = proc.onStartActivity(mService.mTopProcessState); |
chaviw | 59b9885 | 2017-06-13 12:05:44 -0700 | [diff] [blame] | 1446 | |
chaviw | 59b9885 | 2017-06-13 12:05:44 -0700 | [diff] [blame] | 1447 | // Because we could be starting an Activity in the system process this may not go |
| 1448 | // across a Binder interface which would create a new Configuration. Consequently |
| 1449 | // we have to always create a new Configuration here. |
Bryce Lee | a163b76 | 2017-01-24 11:05:01 -0800 | [diff] [blame] | 1450 | |
chaviw | 59b9885 | 2017-06-13 12:05:44 -0700 | [diff] [blame] | 1451 | final MergedConfiguration mergedConfiguration = new MergedConfiguration( |
Wale Ogunwale | 9c10302 | 2018-10-18 07:44:54 -0700 | [diff] [blame] | 1452 | proc.getConfiguration(), r.getMergedOverrideConfiguration()); |
chaviw | 59b9885 | 2017-06-13 12:05:44 -0700 | [diff] [blame] | 1453 | r.setLastReportedConfiguration(mergedConfiguration); |
Bryce Lee | a163b76 | 2017-01-24 11:05:01 -0800 | [diff] [blame] | 1454 | |
chaviw | 59b9885 | 2017-06-13 12:05:44 -0700 | [diff] [blame] | 1455 | logIfTransactionTooLarge(r.intent, r.icicle); |
Andrii Kulian | 88e05cb | 2017-12-05 17:21:10 -0800 | [diff] [blame] | 1456 | |
| 1457 | |
| 1458 | // Create activity launch transaction. |
Wale Ogunwale | 9c10302 | 2018-10-18 07:44:54 -0700 | [diff] [blame] | 1459 | final ClientTransaction clientTransaction = ClientTransaction.obtain( |
| 1460 | proc.getThread(), r.appToken); |
lumark | 588a3e8 | 2018-07-20 18:53:54 +0800 | [diff] [blame] | 1461 | |
| 1462 | final DisplayWindowController dwc = r.getDisplay().getWindowContainerController(); |
Andrii Kulian | 9c5ea9c | 2017-12-07 09:31:01 -0800 | [diff] [blame] | 1463 | clientTransaction.addCallback(LaunchActivityItem.obtain(new Intent(r.intent), |
chaviw | 59b9885 | 2017-06-13 12:05:44 -0700 | [diff] [blame] | 1464 | System.identityHashCode(r), r.info, |
| 1465 | // TODO: Have this take the merged configuration instead of separate global |
| 1466 | // and override configs. |
| 1467 | mergedConfiguration.getGlobalConfiguration(), |
| 1468 | mergedConfiguration.getOverrideConfiguration(), r.compat, |
Wale Ogunwale | 9c10302 | 2018-10-18 07:44:54 -0700 | [diff] [blame] | 1469 | r.launchedFromPackage, task.voiceInteractor, proc.getReportedProcState(), |
Wale Ogunwale | 9e4f3e0 | 2018-05-17 09:35:39 -0700 | [diff] [blame] | 1470 | r.icicle, r.persistentState, results, newIntents, |
lumark | 588a3e8 | 2018-07-20 18:53:54 +0800 | [diff] [blame] | 1471 | dwc.isNextTransitionForward(), profilerInfo)); |
Andrii Kulian | 88e05cb | 2017-12-05 17:21:10 -0800 | [diff] [blame] | 1472 | |
| 1473 | // Set desired final state. |
| 1474 | final ActivityLifecycleItem lifecycleItem; |
| 1475 | if (andResume) { |
lumark | 588a3e8 | 2018-07-20 18:53:54 +0800 | [diff] [blame] | 1476 | lifecycleItem = ResumeActivityItem.obtain(dwc.isNextTransitionForward()); |
Andrii Kulian | 88e05cb | 2017-12-05 17:21:10 -0800 | [diff] [blame] | 1477 | } else { |
Bryce Lee | 1d0d514 | 2018-04-12 10:35:07 -0700 | [diff] [blame] | 1478 | lifecycleItem = PauseActivityItem.obtain(); |
Andrii Kulian | 88e05cb | 2017-12-05 17:21:10 -0800 | [diff] [blame] | 1479 | } |
| 1480 | clientTransaction.setLifecycleStateRequest(lifecycleItem); |
| 1481 | |
| 1482 | // Schedule transaction. |
Wale Ogunwale | c9e57de | 2018-05-08 14:28:07 -0700 | [diff] [blame] | 1483 | mService.getLifecycleManager().scheduleTransaction(clientTransaction); |
Craig Mautner | 2420ead | 2013-04-01 17:13:20 -0700 | [diff] [blame] | 1484 | |
Wale Ogunwale | 9c10302 | 2018-10-18 07:44:54 -0700 | [diff] [blame] | 1485 | if ((proc.mInfo.privateFlags & ApplicationInfo.PRIVATE_FLAG_CANT_SAVE_STATE) != 0 |
Wale Ogunwale | 214f348 | 2018-10-04 11:00:47 -0700 | [diff] [blame] | 1486 | && mService.mHasHeavyWeightFeature) { |
Wale Ogunwale | 5378374 | 2018-09-16 10:21:51 -0700 | [diff] [blame] | 1487 | // This may be a heavy-weight process! Note that the package manager will ensure |
| 1488 | // that only activity can run in the main process of the .apk, which is the only |
| 1489 | // thing that will be considered heavy-weight. |
Wale Ogunwale | 9c10302 | 2018-10-18 07:44:54 -0700 | [diff] [blame] | 1490 | if (proc.mName.equals(proc.mInfo.packageName)) { |
Wale Ogunwale | 5378374 | 2018-09-16 10:21:51 -0700 | [diff] [blame] | 1491 | if (mService.mHeavyWeightProcess != null |
| 1492 | && mService.mHeavyWeightProcess != proc) { |
| 1493 | Slog.w(TAG, "Starting new heavy weight process " + proc |
chaviw | 59b9885 | 2017-06-13 12:05:44 -0700 | [diff] [blame] | 1494 | + " when already running " |
Wale Ogunwale | 5378374 | 2018-09-16 10:21:51 -0700 | [diff] [blame] | 1495 | + mService.mHeavyWeightProcess); |
chaviw | 59b9885 | 2017-06-13 12:05:44 -0700 | [diff] [blame] | 1496 | } |
Wale Ogunwale | 5378374 | 2018-09-16 10:21:51 -0700 | [diff] [blame] | 1497 | mService.setHeavyWeightProcess(r); |
Craig Mautner | 2420ead | 2013-04-01 17:13:20 -0700 | [diff] [blame] | 1498 | } |
Craig Mautner | 2420ead | 2013-04-01 17:13:20 -0700 | [diff] [blame] | 1499 | } |
Craig Mautner | 2420ead | 2013-04-01 17:13:20 -0700 | [diff] [blame] | 1500 | |
chaviw | 59b9885 | 2017-06-13 12:05:44 -0700 | [diff] [blame] | 1501 | } catch (RemoteException e) { |
| 1502 | if (r.launchFailed) { |
Wale Ogunwale | 9c10302 | 2018-10-18 07:44:54 -0700 | [diff] [blame] | 1503 | // This is the second time we failed -- finish activity and give up. |
chaviw | 59b9885 | 2017-06-13 12:05:44 -0700 | [diff] [blame] | 1504 | Slog.e(TAG, "Second failure launching " |
Wale Ogunwale | 9c10302 | 2018-10-18 07:44:54 -0700 | [diff] [blame] | 1505 | + r.intent.getComponent().flattenToShortString() + ", giving up", e); |
| 1506 | proc.appDied(); |
chaviw | 59b9885 | 2017-06-13 12:05:44 -0700 | [diff] [blame] | 1507 | stack.requestFinishActivityLocked(r.appToken, Activity.RESULT_CANCELED, null, |
| 1508 | "2nd-crash", false); |
| 1509 | return false; |
| 1510 | } |
Craig Mautner | 2420ead | 2013-04-01 17:13:20 -0700 | [diff] [blame] | 1511 | |
chaviw | 59b9885 | 2017-06-13 12:05:44 -0700 | [diff] [blame] | 1512 | // This is the first time we failed -- restart process and |
| 1513 | // retry. |
| 1514 | r.launchFailed = true; |
Wale Ogunwale | 9e4f3e0 | 2018-05-17 09:35:39 -0700 | [diff] [blame] | 1515 | proc.removeActivity(r); |
chaviw | 59b9885 | 2017-06-13 12:05:44 -0700 | [diff] [blame] | 1516 | throw e; |
| 1517 | } |
| 1518 | } finally { |
| 1519 | endDeferResume(); |
Craig Mautner | 2420ead | 2013-04-01 17:13:20 -0700 | [diff] [blame] | 1520 | } |
| 1521 | |
| 1522 | r.launchFailed = false; |
| 1523 | if (stack.updateLRUListLocked(r)) { |
Filip Gruszczynski | 49b80af | 2015-09-24 09:04:26 -0700 | [diff] [blame] | 1524 | Slog.w(TAG, "Activity " + r + " being launched, but already in LRU list"); |
Craig Mautner | 2420ead | 2013-04-01 17:13:20 -0700 | [diff] [blame] | 1525 | } |
| 1526 | |
Andrii Kulian | b372da6 | 2018-01-18 10:46:24 -0800 | [diff] [blame] | 1527 | // TODO(lifecycler): Resume or pause requests are done as part of launch transaction, |
| 1528 | // so updating the state should be done accordingly. |
chaviw | 59b9885 | 2017-06-13 12:05:44 -0700 | [diff] [blame] | 1529 | if (andResume && readyToResume()) { |
Craig Mautner | 2420ead | 2013-04-01 17:13:20 -0700 | [diff] [blame] | 1530 | // As part of the process of launching, ActivityThread also performs |
| 1531 | // a resume. |
| 1532 | stack.minimalResumeActivityLocked(r); |
| 1533 | } else { |
Wale Ogunwale | d046a01 | 2015-12-24 13:05:59 -0800 | [diff] [blame] | 1534 | // This activity is not starting in the resumed state... which should look like we asked |
Wale Ogunwale | 919a05d | 2017-04-13 00:36:34 +0000 | [diff] [blame] | 1535 | // it to pause+stop (but remain visible), and it has done so and reported back the |
Wale Ogunwale | d046a01 | 2015-12-24 13:05:59 -0800 | [diff] [blame] | 1536 | // current icicle and other state. |
Wale Ogunwale | 0fc365c | 2015-05-25 19:35:42 -0700 | [diff] [blame] | 1537 | if (DEBUG_STATES) Slog.v(TAG_STATES, |
Wale Ogunwale | d046a01 | 2015-12-24 13:05:59 -0800 | [diff] [blame] | 1538 | "Moving to PAUSED: " + r + " (starting in paused state)"); |
Bryce Lee | 7ace395 | 2018-02-16 14:34:32 -0800 | [diff] [blame] | 1539 | r.setState(PAUSED, "realStartActivityLocked"); |
Craig Mautner | 2420ead | 2013-04-01 17:13:20 -0700 | [diff] [blame] | 1540 | } |
| 1541 | |
| 1542 | // Launch the new version setup screen if needed. We do this -after- |
| 1543 | // launching the initial activity (that is, home), so that it can have |
| 1544 | // a chance to initialize itself while in the background, making the |
| 1545 | // switch back to it faster and look better. |
Andrii Kulian | 5f750bc | 2018-07-17 08:57:23 -0700 | [diff] [blame] | 1546 | if (isTopDisplayFocusedStack(stack)) { |
Wale Ogunwale | c9e57de | 2018-05-08 14:28:07 -0700 | [diff] [blame] | 1547 | mService.getActivityStartController().startSetupActivity(); |
Craig Mautner | 2420ead | 2013-04-01 17:13:20 -0700 | [diff] [blame] | 1548 | } |
| 1549 | |
Dianne Hackborn | 465fa39 | 2014-09-14 14:21:18 -0700 | [diff] [blame] | 1550 | // Update any services we are bound to that might care about whether |
| 1551 | // their client may have activities. |
Wale Ogunwale | d6ac762 | 2016-05-26 09:02:25 -0700 | [diff] [blame] | 1552 | if (r.app != null) { |
Wale Ogunwale | 9e4f3e0 | 2018-05-17 09:35:39 -0700 | [diff] [blame] | 1553 | r.app.updateServiceConnectionActivities(); |
Wale Ogunwale | d6ac762 | 2016-05-26 09:02:25 -0700 | [diff] [blame] | 1554 | } |
Dianne Hackborn | 465fa39 | 2014-09-14 14:21:18 -0700 | [diff] [blame] | 1555 | |
Craig Mautner | 2420ead | 2013-04-01 17:13:20 -0700 | [diff] [blame] | 1556 | return true; |
| 1557 | } |
| 1558 | |
Andrii Kulian | f4479ee | 2018-05-23 17:52:48 -0700 | [diff] [blame] | 1559 | /** |
| 1560 | * Ensure all activities visibility, update orientation and configuration. |
Andrii Kulian | a39ae3e | 2018-05-31 12:43:54 -0700 | [diff] [blame] | 1561 | * |
| 1562 | * @param starting The currently starting activity or {@code null} if there is none. |
| 1563 | * @param displayId The id of the display where operation is executed. |
| 1564 | * @param markFrozenIfConfigChanged Whether to set {@link ActivityRecord#frozenBeforeDestroy} to |
| 1565 | * {@code true} if config changed. |
| 1566 | * @param deferResume Whether to defer resume while updating config. |
Andrii Kulian | 2f0d73c | 2018-06-15 14:32:04 -0700 | [diff] [blame] | 1567 | * @return 'true' if starting activity was kept or wasn't provided, 'false' if it was relaunched |
| 1568 | * because of configuration update. |
Andrii Kulian | f4479ee | 2018-05-23 17:52:48 -0700 | [diff] [blame] | 1569 | */ |
Andrii Kulian | a39ae3e | 2018-05-31 12:43:54 -0700 | [diff] [blame] | 1570 | boolean ensureVisibilityAndConfig(ActivityRecord starting, int displayId, |
Andrii Kulian | f4479ee | 2018-05-23 17:52:48 -0700 | [diff] [blame] | 1571 | boolean markFrozenIfConfigChanged, boolean deferResume) { |
| 1572 | // First ensure visibility without updating the config just yet. We need this to know what |
| 1573 | // activities are affecting configuration now. |
Andrii Kulian | a39ae3e | 2018-05-31 12:43:54 -0700 | [diff] [blame] | 1574 | // Passing null here for 'starting' param value, so that visibility of actual starting |
| 1575 | // activity will be properly updated. |
Andrii Kulian | f4479ee | 2018-05-23 17:52:48 -0700 | [diff] [blame] | 1576 | ensureActivitiesVisibleLocked(null /* starting */, 0 /* configChanges */, |
Andrii Kulian | a39ae3e | 2018-05-31 12:43:54 -0700 | [diff] [blame] | 1577 | false /* preserveWindows */, false /* notifyClients */); |
Andrii Kulian | f4479ee | 2018-05-23 17:52:48 -0700 | [diff] [blame] | 1578 | |
Andrii Kulian | 2f0d73c | 2018-06-15 14:32:04 -0700 | [diff] [blame] | 1579 | if (displayId == INVALID_DISPLAY) { |
| 1580 | // The caller didn't provide a valid display id, skip updating config. |
| 1581 | return true; |
| 1582 | } |
| 1583 | |
Andrii Kulian | f4479ee | 2018-05-23 17:52:48 -0700 | [diff] [blame] | 1584 | // Force-update the orientation from the WindowManager, since we need the true configuration |
| 1585 | // to send to the client now. |
| 1586 | final Configuration config = mWindowManager.updateOrientationFromAppTokens( |
| 1587 | getDisplayOverrideConfiguration(displayId), |
Andrii Kulian | a39ae3e | 2018-05-31 12:43:54 -0700 | [diff] [blame] | 1588 | starting != null && starting.mayFreezeScreenLocked(starting.app) |
| 1589 | ? starting.appToken : null, |
Andrii Kulian | 6cdcfe4 | 2018-05-23 17:59:43 -0700 | [diff] [blame] | 1590 | displayId, true /* forceUpdate */); |
Andrii Kulian | a39ae3e | 2018-05-31 12:43:54 -0700 | [diff] [blame] | 1591 | if (starting != null && markFrozenIfConfigChanged && config != null) { |
| 1592 | starting.frozenBeforeDestroy = true; |
Andrii Kulian | f4479ee | 2018-05-23 17:52:48 -0700 | [diff] [blame] | 1593 | } |
| 1594 | |
| 1595 | // Update the configuration of the activities on the display. |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 1596 | return mService.updateDisplayOverrideConfigurationLocked(config, starting, deferResume, |
Andrii Kulian | a39ae3e | 2018-05-31 12:43:54 -0700 | [diff] [blame] | 1597 | displayId); |
Andrii Kulian | f4479ee | 2018-05-23 17:52:48 -0700 | [diff] [blame] | 1598 | } |
| 1599 | |
Sudheer Shanka | fab200f | 2017-05-17 20:41:53 -0700 | [diff] [blame] | 1600 | private void logIfTransactionTooLarge(Intent intent, Bundle icicle) { |
| 1601 | int extrasSize = 0; |
| 1602 | if (intent != null) { |
| 1603 | final Bundle extras = intent.getExtras(); |
| 1604 | if (extras != null) { |
| 1605 | extrasSize = extras.getSize(); |
| 1606 | } |
| 1607 | } |
| 1608 | int icicleSize = (icicle == null ? 0 : icicle.getSize()); |
| 1609 | if (extrasSize + icicleSize > 200000) { |
| 1610 | Slog.e(TAG, "Transaction too large, intent: " + intent + ", extras size: " + extrasSize |
| 1611 | + ", icicle size: " + icicleSize); |
| 1612 | } |
| 1613 | } |
| 1614 | |
Wale Ogunwale | 9c10302 | 2018-10-18 07:44:54 -0700 | [diff] [blame] | 1615 | void startSpecificActivityLocked(ActivityRecord r, boolean andResume, boolean checkConfig) { |
Craig Mautner | e79d4268 | 2013-04-01 19:01:53 -0700 | [diff] [blame] | 1616 | // Is this activity's application already running? |
Wale Ogunwale | 9c10302 | 2018-10-18 07:44:54 -0700 | [diff] [blame] | 1617 | final WindowProcessController wpc = |
| 1618 | mService.getProcessController(r.processName, r.info.applicationInfo.uid); |
Craig Mautner | e79d4268 | 2013-04-01 19:01:53 -0700 | [diff] [blame] | 1619 | |
Wale Ogunwale | 9c10302 | 2018-10-18 07:44:54 -0700 | [diff] [blame] | 1620 | if (wpc != null && wpc.hasThread()) { |
Craig Mautner | e79d4268 | 2013-04-01 19:01:53 -0700 | [diff] [blame] | 1621 | try { |
Wale Ogunwale | 9c10302 | 2018-10-18 07:44:54 -0700 | [diff] [blame] | 1622 | if ((r.info.flags & ActivityInfo.FLAG_MULTIPROCESS) == 0 |
Dianne Hackborn | 237cefb | 2013-10-22 18:45:27 -0700 | [diff] [blame] | 1623 | || !"android".equals(r.info.packageName)) { |
Wale Ogunwale | 9c10302 | 2018-10-18 07:44:54 -0700 | [diff] [blame] | 1624 | // Don't add this if it is a platform component that is marked to run in |
| 1625 | // multiple processes, because this is actually part of the framework so doesn't |
| 1626 | // make sense to track as a separate apk in the process. |
| 1627 | wpc.addPackage(r.info.packageName, r.info.applicationInfo.longVersionCode); |
Dianne Hackborn | 237cefb | 2013-10-22 18:45:27 -0700 | [diff] [blame] | 1628 | } |
Wale Ogunwale | 9c10302 | 2018-10-18 07:44:54 -0700 | [diff] [blame] | 1629 | realStartActivityLocked(r, wpc, andResume, checkConfig); |
Craig Mautner | e79d4268 | 2013-04-01 19:01:53 -0700 | [diff] [blame] | 1630 | return; |
| 1631 | } catch (RemoteException e) { |
| 1632 | Slog.w(TAG, "Exception when starting activity " |
| 1633 | + r.intent.getComponent().flattenToShortString(), e); |
| 1634 | } |
| 1635 | |
| 1636 | // If a dead object exception was thrown -- fall through to |
| 1637 | // restart the application. |
| 1638 | } |
| 1639 | |
Wale Ogunwale | 5c91870 | 2018-10-18 11:06:33 -0700 | [diff] [blame] | 1640 | // Post message to start process to avoid possible deadlock of calling into AMS with the |
| 1641 | // ATMS lock held. |
| 1642 | final Message msg = PooledLambda.obtainMessage( |
| 1643 | ActivityManagerInternal::startProcess, mService.mAmInternal, r.processName, |
| 1644 | r.info.applicationInfo, true, "activity", r.intent.getComponent()); |
| 1645 | mService.mH.sendMessage(msg); |
Craig Mautner | e79d4268 | 2013-04-01 19:01:53 -0700 | [diff] [blame] | 1646 | } |
| 1647 | |
Bryce Lee | d3624e1 | 2017-11-30 08:51:45 -0800 | [diff] [blame] | 1648 | void sendPowerHintForLaunchStartIfNeeded(boolean forceSend, ActivityRecord targetActivity) { |
| 1649 | boolean sendHint = forceSend; |
| 1650 | |
| 1651 | if (!sendHint) { |
Andrii Kulian | 52d255c | 2018-07-13 11:32:19 -0700 | [diff] [blame] | 1652 | // Send power hint if we don't know what we're launching yet |
| 1653 | sendHint = targetActivity == null || targetActivity.app == null; |
| 1654 | } |
| 1655 | |
| 1656 | if (!sendHint) { // targetActivity != null |
| 1657 | // Send power hint when the activity's process is different than the current resumed |
| 1658 | // activity on all displays, or if there are no resumed activities in the system. |
| 1659 | boolean noResumedActivities = true; |
| 1660 | boolean allFocusedProcessesDiffer = true; |
| 1661 | for (int displayNdx = 0; displayNdx < mActivityDisplays.size(); ++displayNdx) { |
Riddle Hsu | 86cb7de | 2018-08-13 23:29:58 +0800 | [diff] [blame] | 1662 | final ActivityDisplay activityDisplay = mActivityDisplays.get(displayNdx); |
Andrii Kulian | 52d255c | 2018-07-13 11:32:19 -0700 | [diff] [blame] | 1663 | final ActivityRecord resumedActivity = activityDisplay.getResumedActivity(); |
| 1664 | final WindowProcessController resumedActivityProcess = |
| 1665 | resumedActivity == null ? null : resumedActivity.app; |
| 1666 | |
| 1667 | noResumedActivities &= resumedActivityProcess == null; |
| 1668 | if (resumedActivityProcess != null) { |
| 1669 | allFocusedProcessesDiffer &= !resumedActivityProcess.equals(targetActivity.app); |
| 1670 | } |
| 1671 | } |
| 1672 | sendHint = noResumedActivities || allFocusedProcessesDiffer; |
Bryce Lee | d3624e1 | 2017-11-30 08:51:45 -0800 | [diff] [blame] | 1673 | } |
| 1674 | |
Wale Ogunwale | 342fbe9 | 2018-10-09 08:44:10 -0700 | [diff] [blame] | 1675 | if (sendHint && mService.mPowerManagerInternal != null) { |
| 1676 | mService.mPowerManagerInternal.powerHint(PowerHint.LAUNCH, 1); |
Bryce Lee | d3624e1 | 2017-11-30 08:51:45 -0800 | [diff] [blame] | 1677 | mPowerHintSent = true; |
| 1678 | } |
| 1679 | } |
| 1680 | |
| 1681 | void sendPowerHintForLaunchEndIfNeeded() { |
| 1682 | // Trigger launch power hint if activity is launched |
Wale Ogunwale | 342fbe9 | 2018-10-09 08:44:10 -0700 | [diff] [blame] | 1683 | if (mPowerHintSent && mService.mPowerManagerInternal != null) { |
| 1684 | mService.mPowerManagerInternal.powerHint(PowerHint.LAUNCH, 0); |
Bryce Lee | d3624e1 | 2017-11-30 08:51:45 -0800 | [diff] [blame] | 1685 | mPowerHintSent = false; |
| 1686 | } |
| 1687 | } |
| 1688 | |
Wale Ogunwale | 342fbe9 | 2018-10-09 08:44:10 -0700 | [diff] [blame] | 1689 | boolean checkStartAnyActivityPermission(Intent intent, ActivityInfo aInfo, String resultWho, |
| 1690 | int requestCode, int callingPid, int callingUid, String callingPackage, |
| 1691 | boolean ignoreTargetSecurity, boolean launchingInTask, |
| 1692 | WindowProcessController callerApp, ActivityRecord resultRecord, |
| 1693 | ActivityStack resultStack) { |
Wale Ogunwale | c9e57de | 2018-05-08 14:28:07 -0700 | [diff] [blame] | 1694 | final boolean isCallerRecents = mService.getRecentTasks() != null |
| 1695 | && mService.getRecentTasks().isCallerRecents(callingUid); |
Wale Ogunwale | f673393 | 2018-06-27 05:14:34 -0700 | [diff] [blame] | 1696 | final int startAnyPerm = mService.checkPermission(START_ANY_ACTIVITY, callingPid, |
Filip Gruszczynski | dc39490 | 2015-12-14 10:20:22 -0800 | [diff] [blame] | 1697 | callingUid); |
Winson Chung | c9804e7 | 2018-05-15 11:01:44 -0700 | [diff] [blame] | 1698 | if (startAnyPerm == PERMISSION_GRANTED || (isCallerRecents && launchingInTask)) { |
| 1699 | // If the caller has START_ANY_ACTIVITY, ignore all checks below. In addition, if the |
| 1700 | // caller is the recents component and we are specifically starting an activity in an |
| 1701 | // existing task, then also allow the activity to be fully relaunched. |
Filip Gruszczynski | dc39490 | 2015-12-14 10:20:22 -0800 | [diff] [blame] | 1702 | return true; |
| 1703 | } |
| 1704 | final int componentRestriction = getComponentRestrictionForCallingPackage( |
| 1705 | aInfo, callingPackage, callingPid, callingUid, ignoreTargetSecurity); |
| 1706 | final int actionRestriction = getActionRestrictionForCallingPackage( |
| 1707 | intent.getAction(), callingPackage, callingPid, callingUid); |
| 1708 | if (componentRestriction == ACTIVITY_RESTRICTION_PERMISSION |
| 1709 | || actionRestriction == ACTIVITY_RESTRICTION_PERMISSION) { |
| 1710 | if (resultRecord != null) { |
| 1711 | resultStack.sendActivityResultLocked(-1, |
| 1712 | resultRecord, resultWho, requestCode, |
| 1713 | Activity.RESULT_CANCELED, null); |
| 1714 | } |
| 1715 | final String msg; |
| 1716 | if (actionRestriction == ACTIVITY_RESTRICTION_PERMISSION) { |
| 1717 | msg = "Permission Denial: starting " + intent.toString() |
| 1718 | + " from " + callerApp + " (pid=" + callingPid |
| 1719 | + ", uid=" + callingUid + ")" + " with revoked permission " |
| 1720 | + ACTION_TO_RUNTIME_PERMISSION.get(intent.getAction()); |
| 1721 | } else if (!aInfo.exported) { |
| 1722 | msg = "Permission Denial: starting " + intent.toString() |
| 1723 | + " from " + callerApp + " (pid=" + callingPid |
| 1724 | + ", uid=" + callingUid + ")" |
| 1725 | + " not exported from uid " + aInfo.applicationInfo.uid; |
| 1726 | } else { |
| 1727 | msg = "Permission Denial: starting " + intent.toString() |
| 1728 | + " from " + callerApp + " (pid=" + callingPid |
| 1729 | + ", uid=" + callingUid + ")" |
| 1730 | + " requires " + aInfo.permission; |
| 1731 | } |
| 1732 | Slog.w(TAG, msg); |
| 1733 | throw new SecurityException(msg); |
| 1734 | } |
| 1735 | |
| 1736 | if (actionRestriction == ACTIVITY_RESTRICTION_APPOP) { |
| 1737 | final String message = "Appop Denial: starting " + intent.toString() |
| 1738 | + " from " + callerApp + " (pid=" + callingPid |
| 1739 | + ", uid=" + callingUid + ")" |
| 1740 | + " requires " + AppOpsManager.permissionToOp( |
| 1741 | ACTION_TO_RUNTIME_PERMISSION.get(intent.getAction())); |
| 1742 | Slog.w(TAG, message); |
| 1743 | return false; |
| 1744 | } else if (componentRestriction == ACTIVITY_RESTRICTION_APPOP) { |
| 1745 | final String message = "Appop Denial: starting " + intent.toString() |
| 1746 | + " from " + callerApp + " (pid=" + callingPid |
| 1747 | + ", uid=" + callingUid + ")" |
| 1748 | + " requires appop " + AppOpsManager.permissionToOp(aInfo.permission); |
| 1749 | Slog.w(TAG, message); |
| 1750 | return false; |
| 1751 | } |
Jorim Jaggi | 2adba07 | 2016-03-03 13:43:39 +0100 | [diff] [blame] | 1752 | |
Filip Gruszczynski | dc39490 | 2015-12-14 10:20:22 -0800 | [diff] [blame] | 1753 | return true; |
| 1754 | } |
| 1755 | |
Andrii Kulian | fb1bf69 | 2017-01-17 11:17:34 -0800 | [diff] [blame] | 1756 | /** Check if caller is allowed to launch activities on specified display. */ |
Andrii Kulian | 02689a7 | 2017-07-06 14:28:59 -0700 | [diff] [blame] | 1757 | boolean isCallerAllowedToLaunchOnDisplay(int callingPid, int callingUid, int launchDisplayId, |
| 1758 | ActivityInfo aInfo) { |
Andrii Kulian | fb1bf69 | 2017-01-17 11:17:34 -0800 | [diff] [blame] | 1759 | if (DEBUG_TASKS) Slog.d(TAG, "Launch on display check: displayId=" + launchDisplayId |
| 1760 | + " callingPid=" + callingPid + " callingUid=" + callingUid); |
| 1761 | |
Andrii Kulian | 02689a7 | 2017-07-06 14:28:59 -0700 | [diff] [blame] | 1762 | if (callingPid == -1 && callingUid == -1) { |
| 1763 | if (DEBUG_TASKS) Slog.d(TAG, "Launch on display check: no caller info, skip check"); |
| 1764 | return true; |
| 1765 | } |
| 1766 | |
Andrii Kulian | 62e6f25 | 2017-05-30 22:46:53 -0700 | [diff] [blame] | 1767 | final ActivityDisplay activityDisplay = getActivityDisplayOrCreateLocked(launchDisplayId); |
Louis Chang | 7d0037c | 2018-08-13 12:42:06 +0800 | [diff] [blame] | 1768 | if (activityDisplay == null || activityDisplay.isRemoved()) { |
Andrii Kulian | fb1bf69 | 2017-01-17 11:17:34 -0800 | [diff] [blame] | 1769 | Slog.w(TAG, "Launch on display check: display not found"); |
| 1770 | return false; |
| 1771 | } |
| 1772 | |
Andrii Kulian | 02689a7 | 2017-07-06 14:28:59 -0700 | [diff] [blame] | 1773 | // Check if the caller has enough privileges to embed activities and launch to private |
| 1774 | // displays. |
Wale Ogunwale | f673393 | 2018-06-27 05:14:34 -0700 | [diff] [blame] | 1775 | final int startAnyPerm = mService.checkPermission(INTERNAL_SYSTEM_WINDOW, callingPid, |
Andrii Kulian | 1cba31c | 2017-06-28 09:42:48 -0700 | [diff] [blame] | 1776 | callingUid); |
| 1777 | if (startAnyPerm == PERMISSION_GRANTED) { |
| 1778 | if (DEBUG_TASKS) Slog.d(TAG, "Launch on display check:" |
| 1779 | + " allow launch any on display"); |
| 1780 | return true; |
| 1781 | } |
| 1782 | |
Andrii Kulian | 8f07029 | 2017-09-12 22:56:49 -0700 | [diff] [blame] | 1783 | // Check if caller is already present on display |
| 1784 | final boolean uidPresentOnDisplay = activityDisplay.isUidPresent(callingUid); |
| 1785 | |
Andrii Kulian | 3c9ad07 | 2017-08-01 11:45:22 -0700 | [diff] [blame] | 1786 | final int displayOwnerUid = activityDisplay.mDisplay.getOwnerUid(); |
| 1787 | if (activityDisplay.mDisplay.getType() == TYPE_VIRTUAL && displayOwnerUid != SYSTEM_UID |
| 1788 | && displayOwnerUid != aInfo.applicationInfo.uid) { |
Andrii Kulian | 1cba31c | 2017-06-28 09:42:48 -0700 | [diff] [blame] | 1789 | // Limit launching on virtual displays, because their contents can be read from Surface |
| 1790 | // by apps that created them. |
Andrii Kulian | 02689a7 | 2017-07-06 14:28:59 -0700 | [diff] [blame] | 1791 | if ((aInfo.flags & ActivityInfo.FLAG_ALLOW_EMBEDDED) == 0) { |
| 1792 | if (DEBUG_TASKS) Slog.d(TAG, "Launch on display check:" |
| 1793 | + " disallow launch on virtual display for not-embedded activity."); |
| 1794 | return false; |
| 1795 | } |
Andrii Kulian | 3c9ad07 | 2017-08-01 11:45:22 -0700 | [diff] [blame] | 1796 | // Check if the caller is allowed to embed activities from other apps. |
Wale Ogunwale | f673393 | 2018-06-27 05:14:34 -0700 | [diff] [blame] | 1797 | if (mService.checkPermission(ACTIVITY_EMBEDDING, callingPid, callingUid) |
Andrii Kulian | 8f07029 | 2017-09-12 22:56:49 -0700 | [diff] [blame] | 1798 | == PERMISSION_DENIED && !uidPresentOnDisplay) { |
Andrii Kulian | 3c9ad07 | 2017-08-01 11:45:22 -0700 | [diff] [blame] | 1799 | if (DEBUG_TASKS) Slog.d(TAG, "Launch on display check:" |
| 1800 | + " disallow activity embedding without permission."); |
| 1801 | return false; |
| 1802 | } |
Andrii Kulian | 1cba31c | 2017-06-28 09:42:48 -0700 | [diff] [blame] | 1803 | } |
| 1804 | |
Andrii Kulian | fb1bf69 | 2017-01-17 11:17:34 -0800 | [diff] [blame] | 1805 | if (!activityDisplay.isPrivate()) { |
| 1806 | // Anyone can launch on a public display. |
| 1807 | if (DEBUG_TASKS) Slog.d(TAG, "Launch on display check:" |
| 1808 | + " allow launch on public display"); |
| 1809 | return true; |
| 1810 | } |
| 1811 | |
| 1812 | // Check if the caller is the owner of the display. |
Andrii Kulian | 3c9ad07 | 2017-08-01 11:45:22 -0700 | [diff] [blame] | 1813 | if (displayOwnerUid == callingUid) { |
Andrii Kulian | fb1bf69 | 2017-01-17 11:17:34 -0800 | [diff] [blame] | 1814 | if (DEBUG_TASKS) Slog.d(TAG, "Launch on display check:" |
| 1815 | + " allow launch for owner of the display"); |
| 1816 | return true; |
| 1817 | } |
| 1818 | |
Andrii Kulian | 8f07029 | 2017-09-12 22:56:49 -0700 | [diff] [blame] | 1819 | if (uidPresentOnDisplay) { |
Andrii Kulian | fb1bf69 | 2017-01-17 11:17:34 -0800 | [diff] [blame] | 1820 | if (DEBUG_TASKS) Slog.d(TAG, "Launch on display check:" |
| 1821 | + " allow launch for caller present on the display"); |
| 1822 | return true; |
| 1823 | } |
| 1824 | |
Andrii Kulian | fb1bf69 | 2017-01-17 11:17:34 -0800 | [diff] [blame] | 1825 | Slog.w(TAG, "Launch on display check: denied"); |
| 1826 | return false; |
| 1827 | } |
| 1828 | |
| 1829 | /** Update lists of UIDs that are present on displays and have access to them. */ |
| 1830 | void updateUIDsPresentOnDisplay() { |
| 1831 | mDisplayAccessUIDs.clear(); |
| 1832 | for (int displayNdx = mActivityDisplays.size() - 1; displayNdx >= 0; --displayNdx) { |
Riddle Hsu | 86cb7de | 2018-08-13 23:29:58 +0800 | [diff] [blame] | 1833 | final ActivityDisplay activityDisplay = mActivityDisplays.get(displayNdx); |
David Stevens | 82ea6cb | 2017-03-03 16:18:50 -0800 | [diff] [blame] | 1834 | // Only bother calculating the whitelist for private displays |
| 1835 | if (activityDisplay.isPrivate()) { |
| 1836 | mDisplayAccessUIDs.append( |
| 1837 | activityDisplay.mDisplayId, activityDisplay.getPresentUIDs()); |
| 1838 | } |
Andrii Kulian | fb1bf69 | 2017-01-17 11:17:34 -0800 | [diff] [blame] | 1839 | } |
| 1840 | // Store updated lists in DisplayManager. Callers from outside of AM should get them there. |
| 1841 | mDisplayManagerInternal.setDisplayAccessUIDs(mDisplayAccessUIDs); |
| 1842 | } |
| 1843 | |
Filip Gruszczynski | 07a0e49 | 2015-12-17 14:16:38 -0800 | [diff] [blame] | 1844 | UserInfo getUserInfo(int userId) { |
Clara Bayarri | f7fea16 | 2015-10-22 16:09:52 +0100 | [diff] [blame] | 1845 | final long identity = Binder.clearCallingIdentity(); |
| 1846 | try { |
| 1847 | return UserManager.get(mService.mContext).getUserInfo(userId); |
| 1848 | } finally { |
| 1849 | Binder.restoreCallingIdentity(identity); |
| 1850 | } |
| 1851 | } |
| 1852 | |
Svet Ganov | 99b6043 | 2015-06-27 13:15:22 -0700 | [diff] [blame] | 1853 | private int getComponentRestrictionForCallingPackage(ActivityInfo activityInfo, |
Dianne Hackborn | a7cfbe0 | 2015-07-16 10:52:52 -0700 | [diff] [blame] | 1854 | String callingPackage, int callingPid, int callingUid, boolean ignoreTargetSecurity) { |
Wale Ogunwale | 214f348 | 2018-10-04 11:00:47 -0700 | [diff] [blame] | 1855 | if (!ignoreTargetSecurity && mService.checkComponentPermission(activityInfo.permission, |
Dianne Hackborn | a7cfbe0 | 2015-07-16 10:52:52 -0700 | [diff] [blame] | 1856 | callingPid, callingUid, activityInfo.applicationInfo.uid, activityInfo.exported) |
Andrii Kulian | 3c9ad07 | 2017-08-01 11:45:22 -0700 | [diff] [blame] | 1857 | == PERMISSION_DENIED) { |
Svet Ganov | 99b6043 | 2015-06-27 13:15:22 -0700 | [diff] [blame] | 1858 | return ACTIVITY_RESTRICTION_PERMISSION; |
| 1859 | } |
| 1860 | |
Christopher Tate | ff7add0 | 2015-08-17 10:23:22 -0700 | [diff] [blame] | 1861 | if (activityInfo.permission == null) { |
| 1862 | return ACTIVITY_RESTRICTION_NONE; |
| 1863 | } |
| 1864 | |
Svet Ganov | 99b6043 | 2015-06-27 13:15:22 -0700 | [diff] [blame] | 1865 | final int opCode = AppOpsManager.permissionToOpCode(activityInfo.permission); |
| 1866 | if (opCode == AppOpsManager.OP_NONE) { |
| 1867 | return ACTIVITY_RESTRICTION_NONE; |
| 1868 | } |
| 1869 | |
Wale Ogunwale | f673393 | 2018-06-27 05:14:34 -0700 | [diff] [blame] | 1870 | if (mService.getAppOpsService().noteOperation(opCode, callingUid, callingPackage) |
| 1871 | != AppOpsManager.MODE_ALLOWED) { |
Dianne Hackborn | a7cfbe0 | 2015-07-16 10:52:52 -0700 | [diff] [blame] | 1872 | if (!ignoreTargetSecurity) { |
| 1873 | return ACTIVITY_RESTRICTION_APPOP; |
| 1874 | } |
Svet Ganov | 99b6043 | 2015-06-27 13:15:22 -0700 | [diff] [blame] | 1875 | } |
| 1876 | |
| 1877 | return ACTIVITY_RESTRICTION_NONE; |
| 1878 | } |
| 1879 | |
Svetoslav | 7008b51 | 2015-06-24 18:47:07 -0700 | [diff] [blame] | 1880 | private int getActionRestrictionForCallingPackage(String action, |
| 1881 | String callingPackage, int callingPid, int callingUid) { |
| 1882 | if (action == null) { |
Svet Ganov | 99b6043 | 2015-06-27 13:15:22 -0700 | [diff] [blame] | 1883 | return ACTIVITY_RESTRICTION_NONE; |
Svetoslav | 7008b51 | 2015-06-24 18:47:07 -0700 | [diff] [blame] | 1884 | } |
| 1885 | |
| 1886 | String permission = ACTION_TO_RUNTIME_PERMISSION.get(action); |
| 1887 | if (permission == null) { |
Svet Ganov | 99b6043 | 2015-06-27 13:15:22 -0700 | [diff] [blame] | 1888 | return ACTIVITY_RESTRICTION_NONE; |
Svetoslav | 7008b51 | 2015-06-24 18:47:07 -0700 | [diff] [blame] | 1889 | } |
| 1890 | |
| 1891 | final PackageInfo packageInfo; |
| 1892 | try { |
| 1893 | packageInfo = mService.mContext.getPackageManager() |
| 1894 | .getPackageInfo(callingPackage, PackageManager.GET_PERMISSIONS); |
| 1895 | } catch (PackageManager.NameNotFoundException e) { |
| 1896 | Slog.i(TAG, "Cannot find package info for " + callingPackage); |
Svet Ganov | 99b6043 | 2015-06-27 13:15:22 -0700 | [diff] [blame] | 1897 | return ACTIVITY_RESTRICTION_NONE; |
Svetoslav | 7008b51 | 2015-06-24 18:47:07 -0700 | [diff] [blame] | 1898 | } |
| 1899 | |
| 1900 | if (!ArrayUtils.contains(packageInfo.requestedPermissions, permission)) { |
Svet Ganov | 99b6043 | 2015-06-27 13:15:22 -0700 | [diff] [blame] | 1901 | return ACTIVITY_RESTRICTION_NONE; |
Svetoslav | 7008b51 | 2015-06-24 18:47:07 -0700 | [diff] [blame] | 1902 | } |
| 1903 | |
Wale Ogunwale | f673393 | 2018-06-27 05:14:34 -0700 | [diff] [blame] | 1904 | if (mService.checkPermission(permission, callingPid, callingUid) == PERMISSION_DENIED) { |
Svet Ganov | 99b6043 | 2015-06-27 13:15:22 -0700 | [diff] [blame] | 1905 | return ACTIVITY_RESTRICTION_PERMISSION; |
Svetoslav | 7008b51 | 2015-06-24 18:47:07 -0700 | [diff] [blame] | 1906 | } |
| 1907 | |
| 1908 | final int opCode = AppOpsManager.permissionToOpCode(permission); |
| 1909 | if (opCode == AppOpsManager.OP_NONE) { |
Svet Ganov | 99b6043 | 2015-06-27 13:15:22 -0700 | [diff] [blame] | 1910 | return ACTIVITY_RESTRICTION_NONE; |
Svetoslav | 7008b51 | 2015-06-24 18:47:07 -0700 | [diff] [blame] | 1911 | } |
| 1912 | |
Wale Ogunwale | f673393 | 2018-06-27 05:14:34 -0700 | [diff] [blame] | 1913 | if (mService.getAppOpsService().noteOperation(opCode, callingUid, callingPackage) |
| 1914 | != AppOpsManager.MODE_ALLOWED) { |
Svet Ganov | 99b6043 | 2015-06-27 13:15:22 -0700 | [diff] [blame] | 1915 | return ACTIVITY_RESTRICTION_APPOP; |
Svetoslav | 7008b51 | 2015-06-24 18:47:07 -0700 | [diff] [blame] | 1916 | } |
| 1917 | |
Svet Ganov | 99b6043 | 2015-06-27 13:15:22 -0700 | [diff] [blame] | 1918 | return ACTIVITY_RESTRICTION_NONE; |
Svetoslav | 7008b51 | 2015-06-24 18:47:07 -0700 | [diff] [blame] | 1919 | } |
| 1920 | |
Dianne Hackborn | 3d07c94 | 2015-03-13 18:02:54 -0700 | [diff] [blame] | 1921 | void setLaunchSource(int uid) { |
| 1922 | mLaunchingActivity.setWorkSource(new WorkSource(uid)); |
| 1923 | } |
| 1924 | |
Craig Mautner | 7ea5bd4 | 2013-07-05 15:27:08 -0700 | [diff] [blame] | 1925 | void acquireLaunchWakelock() { |
| 1926 | if (VALIDATE_WAKE_LOCK_CALLER && Binder.getCallingUid() != Process.myUid()) { |
| 1927 | throw new IllegalStateException("Calling must be system uid"); |
| 1928 | } |
| 1929 | mLaunchingActivity.acquire(); |
| 1930 | if (!mHandler.hasMessages(LAUNCH_TIMEOUT_MSG)) { |
| 1931 | // To be safe, don't allow the wake lock to be held for too long. |
| 1932 | mHandler.sendEmptyMessageDelayed(LAUNCH_TIMEOUT_MSG, LAUNCH_TIMEOUT); |
| 1933 | } |
| 1934 | } |
| 1935 | |
Craig Mautner | f3ea23a | 2015-01-13 09:37:08 -0800 | [diff] [blame] | 1936 | /** |
Louis Chang | 89f43fc | 2018-10-05 10:59:14 +0800 | [diff] [blame] | 1937 | * Called when all resumed tasks/stacks are idle. |
Wale Ogunwale | c9e57de | 2018-05-08 14:28:07 -0700 | [diff] [blame] | 1938 | * @return the state of mService.mAm.mBooting before this was called. |
Craig Mautner | f3ea23a | 2015-01-13 09:37:08 -0800 | [diff] [blame] | 1939 | */ |
Andreas Gampe | a36dc62 | 2018-02-05 17:19:22 -0800 | [diff] [blame] | 1940 | @GuardedBy("mService") |
Craig Mautner | f3ea23a | 2015-01-13 09:37:08 -0800 | [diff] [blame] | 1941 | private boolean checkFinishBootingLocked() { |
Wale Ogunwale | 5378374 | 2018-09-16 10:21:51 -0700 | [diff] [blame] | 1942 | final boolean booting = mService.isBooting(); |
Craig Mautner | f3ea23a | 2015-01-13 09:37:08 -0800 | [diff] [blame] | 1943 | boolean enableScreen = false; |
Wale Ogunwale | 5378374 | 2018-09-16 10:21:51 -0700 | [diff] [blame] | 1944 | mService.setBooting(false); |
| 1945 | if (!mService.isBooted()) { |
| 1946 | mService.setBooted(true); |
Craig Mautner | f3ea23a | 2015-01-13 09:37:08 -0800 | [diff] [blame] | 1947 | enableScreen = true; |
| 1948 | } |
| 1949 | if (booting || enableScreen) { |
Wale Ogunwale | 5378374 | 2018-09-16 10:21:51 -0700 | [diff] [blame] | 1950 | mService.postFinishBooting(booting, enableScreen); |
Craig Mautner | f3ea23a | 2015-01-13 09:37:08 -0800 | [diff] [blame] | 1951 | } |
| 1952 | return booting; |
| 1953 | } |
| 1954 | |
Craig Mautner | f333327 | 2013-04-22 10:55:53 -0700 | [diff] [blame] | 1955 | // Checked. |
Andreas Gampe | a36dc62 | 2018-02-05 17:19:22 -0800 | [diff] [blame] | 1956 | @GuardedBy("mService") |
Craig Mautner | f333327 | 2013-04-22 10:55:53 -0700 | [diff] [blame] | 1957 | final ActivityRecord activityIdleInternalLocked(final IBinder token, boolean fromTimeout, |
Winson Chung | 4dabf23 | 2017-01-25 13:25:22 -0800 | [diff] [blame] | 1958 | boolean processPausingActivities, Configuration config) { |
Wale Ogunwale | e23149f | 2015-03-06 15:39:44 -0800 | [diff] [blame] | 1959 | if (DEBUG_ALL) Slog.v(TAG, "Activity idle: " + token); |
Craig Mautner | f333327 | 2013-04-22 10:55:53 -0700 | [diff] [blame] | 1960 | |
Craig Mautner | f333327 | 2013-04-22 10:55:53 -0700 | [diff] [blame] | 1961 | ArrayList<ActivityRecord> finishes = null; |
Amith Yamasani | 37a40c2 | 2015-06-17 13:25:42 -0700 | [diff] [blame] | 1962 | ArrayList<UserState> startingUsers = null; |
Craig Mautner | f333327 | 2013-04-22 10:55:53 -0700 | [diff] [blame] | 1963 | int NS = 0; |
| 1964 | int NF = 0; |
Craig Mautner | f333327 | 2013-04-22 10:55:53 -0700 | [diff] [blame] | 1965 | boolean booting = false; |
Craig Mautner | f333327 | 2013-04-22 10:55:53 -0700 | [diff] [blame] | 1966 | boolean activityRemoved = false; |
| 1967 | |
Wale Ogunwale | 7d70117 | 2015-03-11 15:36:30 -0700 | [diff] [blame] | 1968 | ActivityRecord r = ActivityRecord.forTokenLocked(token); |
Craig Mautner | f333327 | 2013-04-22 10:55:53 -0700 | [diff] [blame] | 1969 | if (r != null) { |
Wale Ogunwale | 0fc365c | 2015-05-25 19:35:42 -0700 | [diff] [blame] | 1970 | if (DEBUG_IDLE) Slog.d(TAG_IDLE, "activityIdleInternalLocked: Callers=" |
| 1971 | + Debug.getCallers(4)); |
Craig Mautner | f333327 | 2013-04-22 10:55:53 -0700 | [diff] [blame] | 1972 | mHandler.removeMessages(IDLE_TIMEOUT_MSG, r); |
| 1973 | r.finishLaunchTickingLocked(); |
Craig Mautner | 7ea5bd4 | 2013-07-05 15:27:08 -0700 | [diff] [blame] | 1974 | if (fromTimeout) { |
Vishnu Nair | 132ee83 | 2018-09-28 15:00:05 -0700 | [diff] [blame] | 1975 | reportActivityLaunchedLocked(fromTimeout, r, INVALID_DELAY); |
Craig Mautner | f333327 | 2013-04-22 10:55:53 -0700 | [diff] [blame] | 1976 | } |
Craig Mautner | 7ea5bd4 | 2013-07-05 15:27:08 -0700 | [diff] [blame] | 1977 | |
| 1978 | // This is a hack to semi-deal with a race condition |
| 1979 | // in the client where it can be constructed with a |
| 1980 | // newer configuration from when we asked it to launch. |
| 1981 | // We'll update with whatever configuration it now says |
| 1982 | // it used to launch. |
| 1983 | if (config != null) { |
Bryce Lee | a163b76 | 2017-01-24 11:05:01 -0800 | [diff] [blame] | 1984 | r.setLastReportedGlobalConfiguration(config); |
Craig Mautner | 7ea5bd4 | 2013-07-05 15:27:08 -0700 | [diff] [blame] | 1985 | } |
| 1986 | |
| 1987 | // We are now idle. If someone is waiting for a thumbnail from |
| 1988 | // us, we can now deliver. |
| 1989 | r.idle = true; |
| 1990 | |
Craig Mautner | 7ea5bd4 | 2013-07-05 15:27:08 -0700 | [diff] [blame] | 1991 | //Slog.i(TAG, "IDLE: mBooted=" + mBooted + ", fromTimeout=" + fromTimeout); |
Louis Chang | 89f43fc | 2018-10-05 10:59:14 +0800 | [diff] [blame] | 1992 | |
Louis Chang | 1eff248 | 2018-11-01 15:46:31 +0800 | [diff] [blame] | 1993 | // Check if able to finish booting when device is booting and all resumed activities |
| 1994 | // are idle. |
| 1995 | if ((mService.isBooting() && allResumedActivitiesIdle()) || fromTimeout) { |
Craig Mautner | f3ea23a | 2015-01-13 09:37:08 -0800 | [diff] [blame] | 1996 | booting = checkFinishBootingLocked(); |
Craig Mautner | 7ea5bd4 | 2013-07-05 15:27:08 -0700 | [diff] [blame] | 1997 | } |
Garfield Tan | 2746ab5 | 2018-07-25 12:33:01 -0700 | [diff] [blame] | 1998 | |
| 1999 | // When activity is idle, we consider the relaunch must be successful, so let's clear |
| 2000 | // the flag. |
| 2001 | r.mRelaunchReason = RELAUNCH_REASON_NONE; |
Craig Mautner | 7ea5bd4 | 2013-07-05 15:27:08 -0700 | [diff] [blame] | 2002 | } |
| 2003 | |
| 2004 | if (allResumedActivitiesIdle()) { |
| 2005 | if (r != null) { |
Wale Ogunwale | 906f9c6 | 2018-07-23 11:23:44 -0700 | [diff] [blame] | 2006 | mService.scheduleAppGcsLocked(); |
Craig Mautner | 7ea5bd4 | 2013-07-05 15:27:08 -0700 | [diff] [blame] | 2007 | } |
| 2008 | |
| 2009 | if (mLaunchingActivity.isHeld()) { |
| 2010 | mHandler.removeMessages(LAUNCH_TIMEOUT_MSG); |
| 2011 | if (VALIDATE_WAKE_LOCK_CALLER && |
| 2012 | Binder.getCallingUid() != Process.myUid()) { |
| 2013 | throw new IllegalStateException("Calling must be system uid"); |
| 2014 | } |
| 2015 | mLaunchingActivity.release(); |
| 2016 | } |
Filip Gruszczynski | bc5a6c5 | 2015-09-22 13:13:24 -0700 | [diff] [blame] | 2017 | ensureActivitiesVisibleLocked(null, 0, !PRESERVE_WINDOWS); |
Craig Mautner | f333327 | 2013-04-22 10:55:53 -0700 | [diff] [blame] | 2018 | } |
| 2019 | |
| 2020 | // Atomically retrieve all of the other things to do. |
Winson Chung | 4dabf23 | 2017-01-25 13:25:22 -0800 | [diff] [blame] | 2021 | final ArrayList<ActivityRecord> stops = processStoppingActivitiesLocked(r, |
| 2022 | true /* remove */, processPausingActivities); |
Craig Mautner | f333327 | 2013-04-22 10:55:53 -0700 | [diff] [blame] | 2023 | NS = stops != null ? stops.size() : 0; |
Wale Ogunwale | 7d70117 | 2015-03-11 15:36:30 -0700 | [diff] [blame] | 2024 | if ((NF = mFinishingActivities.size()) > 0) { |
| 2025 | finishes = new ArrayList<>(mFinishingActivities); |
Craig Mautner | f333327 | 2013-04-22 10:55:53 -0700 | [diff] [blame] | 2026 | mFinishingActivities.clear(); |
| 2027 | } |
| 2028 | |
Craig Mautner | f333327 | 2013-04-22 10:55:53 -0700 | [diff] [blame] | 2029 | if (mStartingUsers.size() > 0) { |
Wale Ogunwale | 7d70117 | 2015-03-11 15:36:30 -0700 | [diff] [blame] | 2030 | startingUsers = new ArrayList<>(mStartingUsers); |
Craig Mautner | f333327 | 2013-04-22 10:55:53 -0700 | [diff] [blame] | 2031 | mStartingUsers.clear(); |
| 2032 | } |
| 2033 | |
Craig Mautner | f333327 | 2013-04-22 10:55:53 -0700 | [diff] [blame] | 2034 | // Stop any activities that are scheduled to do so but have been |
| 2035 | // waiting for the next one to start. |
| 2036 | for (int i = 0; i < NS; i++) { |
| 2037 | r = stops.get(i); |
Andrii Kulian | 02b7a83 | 2016-10-06 23:11:56 -0700 | [diff] [blame] | 2038 | final ActivityStack stack = r.getStack(); |
Wale Ogunwale | 7d70117 | 2015-03-11 15:36:30 -0700 | [diff] [blame] | 2039 | if (stack != null) { |
| 2040 | if (r.finishing) { |
Bryce Lee | f52974c | 2018-02-14 15:12:01 -0800 | [diff] [blame] | 2041 | stack.finishCurrentActivityLocked(r, ActivityStack.FINISH_IMMEDIATELY, false, |
| 2042 | "activityIdleInternalLocked"); |
Wale Ogunwale | 7d70117 | 2015-03-11 15:36:30 -0700 | [diff] [blame] | 2043 | } else { |
| 2044 | stack.stopActivityLocked(r); |
| 2045 | } |
Craig Mautner | f333327 | 2013-04-22 10:55:53 -0700 | [diff] [blame] | 2046 | } |
| 2047 | } |
| 2048 | |
| 2049 | // Finish any activities that are scheduled to do so but have been |
| 2050 | // waiting for the next one to start. |
| 2051 | for (int i = 0; i < NF; i++) { |
| 2052 | r = finishes.get(i); |
Andrii Kulian | 02b7a83 | 2016-10-06 23:11:56 -0700 | [diff] [blame] | 2053 | final ActivityStack stack = r.getStack(); |
Wale Ogunwale | 7d70117 | 2015-03-11 15:36:30 -0700 | [diff] [blame] | 2054 | if (stack != null) { |
| 2055 | activityRemoved |= stack.destroyActivityLocked(r, true, "finish-idle"); |
| 2056 | } |
Craig Mautner | f333327 | 2013-04-22 10:55:53 -0700 | [diff] [blame] | 2057 | } |
| 2058 | |
Dianne Hackborn | 7622a0f | 2014-09-30 14:31:42 -0700 | [diff] [blame] | 2059 | if (!booting) { |
Amith Yamasani | 1a7eaaa5 | 2014-05-07 10:22:15 -0700 | [diff] [blame] | 2060 | // Complete user switch |
| 2061 | if (startingUsers != null) { |
| 2062 | for (int i = 0; i < startingUsers.size(); i++) { |
Wale Ogunwale | 86b7446 | 2018-07-02 08:42:43 -0700 | [diff] [blame] | 2063 | mService.mAmInternal.finishUserSwitch(startingUsers.get(i)); |
Amith Yamasani | 1a7eaaa5 | 2014-05-07 10:22:15 -0700 | [diff] [blame] | 2064 | } |
| 2065 | } |
Craig Mautner | f333327 | 2013-04-22 10:55:53 -0700 | [diff] [blame] | 2066 | } |
| 2067 | |
Wale Ogunwale | 1f5e53d | 2018-11-05 05:12:46 -0800 | [diff] [blame] | 2068 | mService.mH.post(() -> mService.mAmInternal.trimApplications()); |
Craig Mautner | f333327 | 2013-04-22 10:55:53 -0700 | [diff] [blame] | 2069 | //dump(); |
| 2070 | //mWindowManager.dump(); |
| 2071 | |
Craig Mautner | f333327 | 2013-04-22 10:55:53 -0700 | [diff] [blame] | 2072 | if (activityRemoved) { |
Andrii Kulian | ab132ee | 2018-07-24 22:10:21 +0800 | [diff] [blame] | 2073 | resumeFocusedStacksTopActivitiesLocked(); |
Craig Mautner | f333327 | 2013-04-22 10:55:53 -0700 | [diff] [blame] | 2074 | } |
| 2075 | |
Craig Mautner | 7ea5bd4 | 2013-07-05 15:27:08 -0700 | [diff] [blame] | 2076 | return r; |
Craig Mautner | f333327 | 2013-04-22 10:55:53 -0700 | [diff] [blame] | 2077 | } |
| 2078 | |
Wale Ogunwale | 9e4f3e0 | 2018-05-17 09:35:39 -0700 | [diff] [blame] | 2079 | boolean handleAppDiedLocked(WindowProcessController app) { |
Craig Mautner | 1909125 | 2013-10-05 00:03:53 -0700 | [diff] [blame] | 2080 | boolean hasVisibleActivities = false; |
Craig Mautner | e0a3884 | 2013-12-16 16:14:02 -0800 | [diff] [blame] | 2081 | for (int displayNdx = mActivityDisplays.size() - 1; displayNdx >= 0; --displayNdx) { |
Riddle Hsu | 86cb7de | 2018-08-13 23:29:58 +0800 | [diff] [blame] | 2082 | final ActivityDisplay display = mActivityDisplays.get(displayNdx); |
Wale Ogunwale | a0f5b5e | 2017-10-11 09:37:23 -0700 | [diff] [blame] | 2083 | for (int stackNdx = display.getChildCount() - 1; stackNdx >= 0; --stackNdx) { |
| 2084 | final ActivityStack stack = display.getChildAt(stackNdx); |
| 2085 | hasVisibleActivities |= stack.handleAppDiedLocked(app); |
Craig Mautner | 4a1cb22 | 2013-12-04 16:14:06 -0800 | [diff] [blame] | 2086 | } |
Craig Mautner | 6b74cb5 | 2013-09-27 17:02:21 -0700 | [diff] [blame] | 2087 | } |
Craig Mautner | 1909125 | 2013-10-05 00:03:53 -0700 | [diff] [blame] | 2088 | return hasVisibleActivities; |
Craig Mautner | 8d341ef | 2013-03-26 09:03:27 -0700 | [diff] [blame] | 2089 | } |
| 2090 | |
| 2091 | void closeSystemDialogsLocked() { |
Craig Mautner | e0a3884 | 2013-12-16 16:14:02 -0800 | [diff] [blame] | 2092 | for (int displayNdx = mActivityDisplays.size() - 1; displayNdx >= 0; --displayNdx) { |
Riddle Hsu | 86cb7de | 2018-08-13 23:29:58 +0800 | [diff] [blame] | 2093 | final ActivityDisplay display = mActivityDisplays.get(displayNdx); |
Wale Ogunwale | a0f5b5e | 2017-10-11 09:37:23 -0700 | [diff] [blame] | 2094 | for (int stackNdx = display.getChildCount() - 1; stackNdx >= 0; --stackNdx) { |
| 2095 | final ActivityStack stack = display.getChildAt(stackNdx); |
| 2096 | stack.closeSystemDialogsLocked(); |
Craig Mautner | 4a1cb22 | 2013-12-04 16:14:06 -0800 | [diff] [blame] | 2097 | } |
Craig Mautner | 8d341ef | 2013-03-26 09:03:27 -0700 | [diff] [blame] | 2098 | } |
| 2099 | } |
| 2100 | |
Craig Mautner | 93529a4 | 2013-10-04 15:03:13 -0700 | [diff] [blame] | 2101 | void removeUserLocked(int userId) { |
Craig Mautner | 4f1df4f | 2013-10-15 15:44:14 -0700 | [diff] [blame] | 2102 | mUserStackInFront.delete(userId); |
Craig Mautner | 93529a4 | 2013-10-04 15:03:13 -0700 | [diff] [blame] | 2103 | } |
| 2104 | |
Craig Mautner | 8d341ef | 2013-03-26 09:03:27 -0700 | [diff] [blame] | 2105 | /** |
Chong Zhang | 45c25ce | 2015-08-10 22:18:26 -0700 | [diff] [blame] | 2106 | * Update the last used stack id for non-current user (current user's last |
| 2107 | * used stack is the focused stack) |
| 2108 | */ |
| 2109 | void updateUserStackLocked(int userId, ActivityStack stack) { |
| 2110 | if (userId != mCurrentUser) { |
Louis Chang | bd48dca | 2018-08-29 17:44:34 +0800 | [diff] [blame] | 2111 | mUserStackInFront.put(userId, stack != null ? stack.getStackId() |
| 2112 | : getDefaultDisplay().getHomeStack().mStackId); |
Chong Zhang | 45c25ce | 2015-08-10 22:18:26 -0700 | [diff] [blame] | 2113 | } |
| 2114 | } |
| 2115 | |
| 2116 | /** |
Craig Mautner | 8d341ef | 2013-03-26 09:03:27 -0700 | [diff] [blame] | 2117 | * @return true if some activity was finished (or would have finished if doit were true). |
| 2118 | */ |
Wale Ogunwale | 540e123 | 2015-05-01 15:35:39 -0700 | [diff] [blame] | 2119 | boolean finishDisabledPackageActivitiesLocked(String packageName, Set<String> filterByClasses, |
| 2120 | boolean doit, boolean evenPersistent, int userId) { |
Craig Mautner | 8d341ef | 2013-03-26 09:03:27 -0700 | [diff] [blame] | 2121 | boolean didSomething = false; |
Craig Mautner | e0a3884 | 2013-12-16 16:14:02 -0800 | [diff] [blame] | 2122 | for (int displayNdx = mActivityDisplays.size() - 1; displayNdx >= 0; --displayNdx) { |
Riddle Hsu | 86cb7de | 2018-08-13 23:29:58 +0800 | [diff] [blame] | 2123 | final ActivityDisplay display = mActivityDisplays.get(displayNdx); |
Wale Ogunwale | a0f5b5e | 2017-10-11 09:37:23 -0700 | [diff] [blame] | 2124 | for (int stackNdx = display.getChildCount() - 1; stackNdx >= 0; --stackNdx) { |
| 2125 | final ActivityStack stack = display.getChildAt(stackNdx); |
Wale Ogunwale | 540e123 | 2015-05-01 15:35:39 -0700 | [diff] [blame] | 2126 | if (stack.finishDisabledPackageActivitiesLocked( |
| 2127 | packageName, filterByClasses, doit, evenPersistent, userId)) { |
Craig Mautner | 4a1cb22 | 2013-12-04 16:14:06 -0800 | [diff] [blame] | 2128 | didSomething = true; |
| 2129 | } |
Craig Mautner | 8d341ef | 2013-03-26 09:03:27 -0700 | [diff] [blame] | 2130 | } |
| 2131 | } |
| 2132 | return didSomething; |
| 2133 | } |
| 2134 | |
Dianne Hackborn | a413dc0 | 2013-07-12 12:02:55 -0700 | [diff] [blame] | 2135 | void updatePreviousProcessLocked(ActivityRecord r) { |
| 2136 | // Now that this process has stopped, we may want to consider |
| 2137 | // it to be the previous app to try to keep around in case |
| 2138 | // the user wants to return to it. |
| 2139 | |
| 2140 | // First, found out what is currently the foreground app, so that |
| 2141 | // we don't blow away the previous app if this activity is being |
| 2142 | // hosted by the process that is actually still the foreground. |
Wale Ogunwale | 9e4f3e0 | 2018-05-17 09:35:39 -0700 | [diff] [blame] | 2143 | WindowProcessController fgApp = null; |
Craig Mautner | e0a3884 | 2013-12-16 16:14:02 -0800 | [diff] [blame] | 2144 | for (int displayNdx = mActivityDisplays.size() - 1; displayNdx >= 0; --displayNdx) { |
Riddle Hsu | 86cb7de | 2018-08-13 23:29:58 +0800 | [diff] [blame] | 2145 | final ActivityDisplay display = mActivityDisplays.get(displayNdx); |
Wale Ogunwale | a0f5b5e | 2017-10-11 09:37:23 -0700 | [diff] [blame] | 2146 | for (int stackNdx = display.getChildCount() - 1; stackNdx >= 0; --stackNdx) { |
| 2147 | final ActivityStack stack = display.getChildAt(stackNdx); |
Andrii Kulian | 5f750bc | 2018-07-17 08:57:23 -0700 | [diff] [blame] | 2148 | if (isTopDisplayFocusedStack(stack)) { |
Bryce Lee | c4ab62a | 2018-03-05 14:19:26 -0800 | [diff] [blame] | 2149 | final ActivityRecord resumedActivity = stack.getResumedActivity(); |
| 2150 | if (resumedActivity != null) { |
| 2151 | fgApp = resumedActivity.app; |
Craig Mautner | 4a1cb22 | 2013-12-04 16:14:06 -0800 | [diff] [blame] | 2152 | } else if (stack.mPausingActivity != null) { |
| 2153 | fgApp = stack.mPausingActivity.app; |
| 2154 | } |
| 2155 | break; |
Dianne Hackborn | a413dc0 | 2013-07-12 12:02:55 -0700 | [diff] [blame] | 2156 | } |
Dianne Hackborn | a413dc0 | 2013-07-12 12:02:55 -0700 | [diff] [blame] | 2157 | } |
| 2158 | } |
| 2159 | |
| 2160 | // Now set this one as the previous process, only if that really |
| 2161 | // makes sense to. |
Wale Ogunwale | 9e4f3e0 | 2018-05-17 09:35:39 -0700 | [diff] [blame] | 2162 | if (r.hasProcess() && fgApp != null && r.app != fgApp |
| 2163 | && r.lastVisibleTime > mService.mPreviousProcessVisibleTime |
| 2164 | && r.app != mService.mHomeProcess) { |
| 2165 | mService.mPreviousProcess = r.app; |
| 2166 | mService.mPreviousProcessVisibleTime = r.lastVisibleTime; |
Dianne Hackborn | a413dc0 | 2013-07-12 12:02:55 -0700 | [diff] [blame] | 2167 | } |
| 2168 | } |
| 2169 | |
Andrii Kulian | ab132ee | 2018-07-24 22:10:21 +0800 | [diff] [blame] | 2170 | boolean resumeFocusedStacksTopActivitiesLocked() { |
| 2171 | return resumeFocusedStacksTopActivitiesLocked(null, null, null); |
Craig Mautner | 05d2903 | 2013-05-03 13:40:13 -0700 | [diff] [blame] | 2172 | } |
| 2173 | |
Andrii Kulian | ab132ee | 2018-07-24 22:10:21 +0800 | [diff] [blame] | 2174 | boolean resumeFocusedStacksTopActivitiesLocked( |
Chong Zhang | 280d332 | 2015-11-03 17:27:26 -0800 | [diff] [blame] | 2175 | ActivityStack targetStack, ActivityRecord target, ActivityOptions targetOptions) { |
chaviw | 59b9885 | 2017-06-13 12:05:44 -0700 | [diff] [blame] | 2176 | |
| 2177 | if (!readyToResume()) { |
| 2178 | return false; |
| 2179 | } |
| 2180 | |
Riddle Hsu | 7501699 | 2018-09-20 20:37:14 +0800 | [diff] [blame] | 2181 | if (targetStack != null && (targetStack.isTopStackOnDisplay() |
| 2182 | || getTopDisplayFocusedStack() == targetStack)) { |
Wale Ogunwale | d046a01 | 2015-12-24 13:05:59 -0800 | [diff] [blame] | 2183 | return targetStack.resumeTopActivityUncheckedLocked(target, targetOptions); |
Craig Mautner | 05d2903 | 2013-05-03 13:40:13 -0700 | [diff] [blame] | 2184 | } |
chaviw | 59b9885 | 2017-06-13 12:05:44 -0700 | [diff] [blame] | 2185 | |
Andrii Kulian | ab132ee | 2018-07-24 22:10:21 +0800 | [diff] [blame] | 2186 | // Resume all top activities in focused stacks on all displays. |
| 2187 | for (int displayNdx = mActivityDisplays.size() - 1; displayNdx >= 0; --displayNdx) { |
Riddle Hsu | 86cb7de | 2018-08-13 23:29:58 +0800 | [diff] [blame] | 2188 | final ActivityDisplay display = mActivityDisplays.get(displayNdx); |
Andrii Kulian | ab132ee | 2018-07-24 22:10:21 +0800 | [diff] [blame] | 2189 | final ActivityStack focusedStack = display.getFocusedStack(); |
| 2190 | if (focusedStack == null) { |
| 2191 | continue; |
| 2192 | } |
| 2193 | final ActivityRecord r = focusedStack.topRunningActivityLocked(); |
| 2194 | if (r == null || !r.isState(RESUMED)) { |
| 2195 | focusedStack.resumeTopActivityUncheckedLocked(null, null); |
| 2196 | } else if (r.isState(RESUMED)) { |
| 2197 | // Kick off any lingering app transitions form the MoveTaskToFront operation. |
| 2198 | focusedStack.executeAppTransition(targetOptions); |
| 2199 | } |
Wale Ogunwale | 06579d6 | 2016-04-30 15:29:06 -0700 | [diff] [blame] | 2200 | } |
chaviw | 59b9885 | 2017-06-13 12:05:44 -0700 | [diff] [blame] | 2201 | |
Wale Ogunwale | d046a01 | 2015-12-24 13:05:59 -0800 | [diff] [blame] | 2202 | return false; |
Craig Mautner | 8d341ef | 2013-03-26 09:03:27 -0700 | [diff] [blame] | 2203 | } |
| 2204 | |
Todd Kennedy | 39bfee5 | 2016-02-24 10:28:21 -0800 | [diff] [blame] | 2205 | void updateActivityApplicationInfoLocked(ApplicationInfo aInfo) { |
| 2206 | for (int displayNdx = mActivityDisplays.size() - 1; displayNdx >= 0; --displayNdx) { |
Riddle Hsu | 86cb7de | 2018-08-13 23:29:58 +0800 | [diff] [blame] | 2207 | final ActivityDisplay display = mActivityDisplays.get(displayNdx); |
Wale Ogunwale | a0f5b5e | 2017-10-11 09:37:23 -0700 | [diff] [blame] | 2208 | for (int stackNdx = display.getChildCount() - 1; stackNdx >= 0; --stackNdx) { |
| 2209 | final ActivityStack stack = display.getChildAt(stackNdx); |
| 2210 | stack.updateActivityApplicationInfoLocked(aInfo); |
Todd Kennedy | 39bfee5 | 2016-02-24 10:28:21 -0800 | [diff] [blame] | 2211 | } |
| 2212 | } |
| 2213 | } |
| 2214 | |
Andrii Kulian | 8cc92ac6 | 2018-04-02 23:14:18 -0700 | [diff] [blame] | 2215 | /** |
| 2216 | * Finish the topmost activities in all stacks that belong to the crashed app. |
| 2217 | * @param app The app that crashed. |
| 2218 | * @param reason Reason to perform this action. |
Wale Ogunwale | 6425836 | 2018-10-16 15:13:37 -0700 | [diff] [blame] | 2219 | * @return The task id that was finished in this stack, or INVALID_TASK_ID if none was finished. |
Andrii Kulian | 8cc92ac6 | 2018-04-02 23:14:18 -0700 | [diff] [blame] | 2220 | */ |
Wale Ogunwale | 6425836 | 2018-10-16 15:13:37 -0700 | [diff] [blame] | 2221 | int finishTopCrashedActivitiesLocked(WindowProcessController app, String reason) { |
Adrian Roos | 20d7df3 | 2016-01-12 18:59:43 +0100 | [diff] [blame] | 2222 | TaskRecord finishedTask = null; |
Andrii Kulian | 5f750bc | 2018-07-17 08:57:23 -0700 | [diff] [blame] | 2223 | ActivityStack focusedStack = getTopDisplayFocusedStack(); |
Craig Mautner | e0a3884 | 2013-12-16 16:14:02 -0800 | [diff] [blame] | 2224 | for (int displayNdx = mActivityDisplays.size() - 1; displayNdx >= 0; --displayNdx) { |
Riddle Hsu | 86cb7de | 2018-08-13 23:29:58 +0800 | [diff] [blame] | 2225 | final ActivityDisplay display = mActivityDisplays.get(displayNdx); |
Andrii Kulian | 8cc92ac6 | 2018-04-02 23:14:18 -0700 | [diff] [blame] | 2226 | // It is possible that request to finish activity might also remove its task and stack, |
| 2227 | // so we need to be careful with indexes in the loop and check child count every time. |
| 2228 | for (int stackNdx = 0; stackNdx < display.getChildCount(); ++stackNdx) { |
Wale Ogunwale | a0f5b5e | 2017-10-11 09:37:23 -0700 | [diff] [blame] | 2229 | final ActivityStack stack = display.getChildAt(stackNdx); |
Andrii Kulian | 8cc92ac6 | 2018-04-02 23:14:18 -0700 | [diff] [blame] | 2230 | final TaskRecord t = stack.finishTopCrashedActivityLocked(app, reason); |
Adrian Roos | 20d7df3 | 2016-01-12 18:59:43 +0100 | [diff] [blame] | 2231 | if (stack == focusedStack || finishedTask == null) { |
| 2232 | finishedTask = t; |
| 2233 | } |
Craig Mautner | 4a1cb22 | 2013-12-04 16:14:06 -0800 | [diff] [blame] | 2234 | } |
Craig Mautner | 8d341ef | 2013-03-26 09:03:27 -0700 | [diff] [blame] | 2235 | } |
Wale Ogunwale | 6425836 | 2018-10-16 15:13:37 -0700 | [diff] [blame] | 2236 | return finishedTask != null ? finishedTask.taskId : INVALID_TASK_ID; |
Craig Mautner | 8d341ef | 2013-03-26 09:03:27 -0700 | [diff] [blame] | 2237 | } |
| 2238 | |
Dianne Hackborn | 6ea0d0a | 2014-07-02 16:23:21 -0700 | [diff] [blame] | 2239 | void finishVoiceTask(IVoiceInteractionSession session) { |
| 2240 | for (int displayNdx = mActivityDisplays.size() - 1; displayNdx >= 0; --displayNdx) { |
Riddle Hsu | 86cb7de | 2018-08-13 23:29:58 +0800 | [diff] [blame] | 2241 | final ActivityDisplay display = mActivityDisplays.get(displayNdx); |
Wale Ogunwale | a0f5b5e | 2017-10-11 09:37:23 -0700 | [diff] [blame] | 2242 | final int numStacks = display.getChildCount(); |
Dianne Hackborn | 6ea0d0a | 2014-07-02 16:23:21 -0700 | [diff] [blame] | 2243 | for (int stackNdx = 0; stackNdx < numStacks; ++stackNdx) { |
Wale Ogunwale | a0f5b5e | 2017-10-11 09:37:23 -0700 | [diff] [blame] | 2244 | final ActivityStack stack = display.getChildAt(stackNdx); |
Dianne Hackborn | 6ea0d0a | 2014-07-02 16:23:21 -0700 | [diff] [blame] | 2245 | stack.finishVoiceTask(session); |
| 2246 | } |
| 2247 | } |
| 2248 | } |
| 2249 | |
Evan Rosky | 9ba524e | 2018-01-03 16:27:56 -0800 | [diff] [blame] | 2250 | /** |
| 2251 | * This doesn't just find a task, it also moves the task to front. |
| 2252 | */ |
Jorim Jaggi | 4d8d32c | 2018-01-19 15:57:41 +0100 | [diff] [blame] | 2253 | void findTaskToMoveToFront(TaskRecord task, int flags, ActivityOptions options, String reason, |
| 2254 | boolean forceNonResizeable) { |
Louis Chang | bd48dca | 2018-08-29 17:44:34 +0800 | [diff] [blame] | 2255 | ActivityStack currentStack = task.getStack(); |
Wale Ogunwale | 66e1685 | 2017-10-19 13:35:52 -0700 | [diff] [blame] | 2256 | if (currentStack == null) { |
| 2257 | Slog.e(TAG, "findTaskToMoveToFront: can't move task=" |
| 2258 | + task + " to front. Stack is null"); |
| 2259 | return; |
| 2260 | } |
| 2261 | |
Craig Mautner | aea74a5 | 2014-03-08 14:23:10 -0800 | [diff] [blame] | 2262 | if ((flags & ActivityManager.MOVE_TASK_NO_USER_ACTION) == 0) { |
| 2263 | mUserLeaving = true; |
Craig Mautner | 8d341ef | 2013-03-26 09:03:27 -0700 | [diff] [blame] | 2264 | } |
Wale Ogunwale | 66e1685 | 2017-10-19 13:35:52 -0700 | [diff] [blame] | 2265 | |
Louis Chang | c8b6411 | 2018-10-11 09:22:14 +0800 | [diff] [blame] | 2266 | reason = reason + " findTaskToMoveToFront"; |
| 2267 | boolean reparented = false; |
Wale Ogunwale | 0568aed | 2017-09-08 13:29:37 -0700 | [diff] [blame] | 2268 | if (task.isResizeable() && canUseActivityOptionsLaunchBounds(options)) { |
Bryce Lee | f3c6a47 | 2017-11-14 14:53:06 -0800 | [diff] [blame] | 2269 | final Rect bounds = options.getLaunchBounds(); |
Wale Ogunwale | 0568aed | 2017-09-08 13:29:37 -0700 | [diff] [blame] | 2270 | task.updateOverrideConfiguration(bounds); |
| 2271 | |
Wale Ogunwale | 04a05ac | 2017-09-17 21:35:02 -0700 | [diff] [blame] | 2272 | ActivityStack stack = getLaunchStack(null, options, task, ON_TOP); |
Wale Ogunwale | 0568aed | 2017-09-08 13:29:37 -0700 | [diff] [blame] | 2273 | |
Wale Ogunwale | 04a05ac | 2017-09-17 21:35:02 -0700 | [diff] [blame] | 2274 | if (stack != currentStack) { |
Louis Chang | c8b6411 | 2018-10-11 09:22:14 +0800 | [diff] [blame] | 2275 | moveHomeStackToFrontIfNeeded(flags, stack.getDisplay(), reason); |
Wale Ogunwale | 04a05ac | 2017-09-17 21:35:02 -0700 | [diff] [blame] | 2276 | task.reparent(stack, ON_TOP, REPARENT_KEEP_STACK_AT_FRONT, !ANIMATE, DEFER_RESUME, |
Louis Chang | c8b6411 | 2018-10-11 09:22:14 +0800 | [diff] [blame] | 2277 | reason); |
Louis Chang | bd48dca | 2018-08-29 17:44:34 +0800 | [diff] [blame] | 2278 | currentStack = stack; |
Louis Chang | c8b6411 | 2018-10-11 09:22:14 +0800 | [diff] [blame] | 2279 | reparented = true; |
| 2280 | // task.reparent() should already placed the task on top, |
Wale Ogunwale | 0568aed | 2017-09-08 13:29:37 -0700 | [diff] [blame] | 2281 | // still need moveTaskToFrontLocked() below for any transition settings. |
| 2282 | } |
Wale Ogunwale | 44f036f | 2017-09-29 05:09:09 -0700 | [diff] [blame] | 2283 | if (stack.resizeStackWithLaunchBounds()) { |
| 2284 | resizeStackLocked(stack, bounds, null /* tempTaskBounds */, |
Wale Ogunwale | 04a05ac | 2017-09-17 21:35:02 -0700 | [diff] [blame] | 2285 | null /* tempTaskInsetBounds */, !PRESERVE_WINDOWS, |
| 2286 | true /* allowResizeInDockedMode */, !DEFER_RESUME); |
Wale Ogunwale | 0568aed | 2017-09-08 13:29:37 -0700 | [diff] [blame] | 2287 | } else { |
| 2288 | // WM resizeTask must be done after the task is moved to the correct stack, |
| 2289 | // because Task's setBounds() also updates dim layer's bounds, but that has |
| 2290 | // dependency on the stack. |
| 2291 | task.resizeWindowContainer(); |
Chong Zhang | 0fa656b | 2015-08-31 15:17:21 -0700 | [diff] [blame] | 2292 | } |
| 2293 | } |
| 2294 | |
Louis Chang | c8b6411 | 2018-10-11 09:22:14 +0800 | [diff] [blame] | 2295 | if (!reparented) { |
| 2296 | moveHomeStackToFrontIfNeeded(flags, currentStack.getDisplay(), reason); |
| 2297 | } |
| 2298 | |
Chong Zhang | db20b5f | 2015-10-23 14:01:43 -0700 | [diff] [blame] | 2299 | final ActivityRecord r = task.getTopActivity(); |
chaviw | 0d562bf | 2018-03-15 14:24:14 -0700 | [diff] [blame] | 2300 | currentStack.moveTaskToFrontLocked(task, false /* noAnimation */, options, |
Chong Zhang | db20b5f | 2015-10-23 14:01:43 -0700 | [diff] [blame] | 2301 | r == null ? null : r.appTimeTracker, reason); |
| 2302 | |
Wale Ogunwale | ee006da | 2015-03-30 14:49:25 -0700 | [diff] [blame] | 2303 | if (DEBUG_STACK) Slog.d(TAG_STACK, |
Andrii Kulian | 02b7a83 | 2016-10-06 23:11:56 -0700 | [diff] [blame] | 2304 | "findTaskToMoveToFront: moved to front of stack=" + currentStack); |
Jorim Jaggi | 2adba07 | 2016-03-03 13:43:39 +0100 | [diff] [blame] | 2305 | |
Wale Ogunwale | 0568aed | 2017-09-08 13:29:37 -0700 | [diff] [blame] | 2306 | handleNonResizableTaskIfNeeded(task, WINDOWING_MODE_UNDEFINED, DEFAULT_DISPLAY, |
Wale Ogunwale | a0f5b5e | 2017-10-11 09:37:23 -0700 | [diff] [blame] | 2307 | currentStack, forceNonResizeable); |
Craig Mautner | 8d341ef | 2013-03-26 09:03:27 -0700 | [diff] [blame] | 2308 | } |
| 2309 | |
Louis Chang | c8b6411 | 2018-10-11 09:22:14 +0800 | [diff] [blame] | 2310 | private void moveHomeStackToFrontIfNeeded(int flags, ActivityDisplay display, String reason) { |
| 2311 | final ActivityStack focusedStack = display.getFocusedStack(); |
| 2312 | |
| 2313 | if ((display.getWindowingMode() == WINDOWING_MODE_FULLSCREEN |
| 2314 | && (flags & ActivityManager.MOVE_TASK_WITH_HOME) != 0) |
| 2315 | || (focusedStack != null && focusedStack.isActivityTypeRecents())) { |
| 2316 | // We move home stack to front when we are on a fullscreen display and caller has |
| 2317 | // requested the home activity to move with it. Or the previous stack is recents. |
| 2318 | display.moveHomeStackToFront(reason); |
| 2319 | } |
| 2320 | } |
| 2321 | |
Wale Ogunwale | 0568aed | 2017-09-08 13:29:37 -0700 | [diff] [blame] | 2322 | boolean canUseActivityOptionsLaunchBounds(ActivityOptions options) { |
Wale Ogunwale | 7a8fa60 | 2015-11-18 15:56:57 -0800 | [diff] [blame] | 2323 | // We use the launch bounds in the activity options is the device supports freeform |
Wale Ogunwale | 854809c | 2015-12-27 16:18:19 -0800 | [diff] [blame] | 2324 | // window management or is launching into the pinned stack. |
Wale Ogunwale | 0568aed | 2017-09-08 13:29:37 -0700 | [diff] [blame] | 2325 | if (options == null || options.getLaunchBounds() == null) { |
Wale Ogunwale | 854809c | 2015-12-27 16:18:19 -0800 | [diff] [blame] | 2326 | return false; |
| 2327 | } |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 2328 | return (mService.mSupportsPictureInPicture |
Wale Ogunwale | 0568aed | 2017-09-08 13:29:37 -0700 | [diff] [blame] | 2329 | && options.getLaunchWindowingMode() == WINDOWING_MODE_PINNED) |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 2330 | || mService.mSupportsFreeformWindowManagement; |
Wale Ogunwale | 7a8fa60 | 2015-11-18 15:56:57 -0800 | [diff] [blame] | 2331 | } |
| 2332 | |
Bryce Lee | ec55eb0 | 2017-12-05 20:51:27 -0800 | [diff] [blame] | 2333 | LaunchParamsController getLaunchParamsController() { |
| 2334 | return mLaunchParamsController; |
Bryce Lee | 9ad3eb3 | 2017-10-10 10:10:31 -0700 | [diff] [blame] | 2335 | } |
| 2336 | |
Winson Chung | 5589333 | 2017-02-17 17:13:10 -0800 | [diff] [blame] | 2337 | protected <T extends ActivityStack> T getStack(int stackId) { |
Wale Ogunwale | 9dcf946 | 2017-09-19 15:13:01 -0700 | [diff] [blame] | 2338 | for (int i = mActivityDisplays.size() - 1; i >= 0; --i) { |
Riddle Hsu | 86cb7de | 2018-08-13 23:29:58 +0800 | [diff] [blame] | 2339 | final T stack = mActivityDisplays.get(i).getStack(stackId); |
Wale Ogunwale | 9dcf946 | 2017-09-19 15:13:01 -0700 | [diff] [blame] | 2340 | if (stack != null) { |
| 2341 | return stack; |
| 2342 | } |
| 2343 | } |
| 2344 | return null; |
Wale Ogunwale | ddc1cb2 | 2015-07-25 19:23:04 -0700 | [diff] [blame] | 2345 | } |
| 2346 | |
Wale Ogunwale | 6827856 | 2017-09-23 17:13:55 -0700 | [diff] [blame] | 2347 | /** @see ActivityDisplay#getStack(int, int) */ |
| 2348 | private <T extends ActivityStack> T getStack(int windowingMode, int activityType) { |
| 2349 | for (int i = mActivityDisplays.size() - 1; i >= 0; --i) { |
Riddle Hsu | 86cb7de | 2018-08-13 23:29:58 +0800 | [diff] [blame] | 2350 | final T stack = mActivityDisplays.get(i).getStack(windowingMode, activityType); |
Wale Ogunwale | 6827856 | 2017-09-23 17:13:55 -0700 | [diff] [blame] | 2351 | if (stack != null) { |
| 2352 | return stack; |
| 2353 | } |
| 2354 | } |
| 2355 | return null; |
| 2356 | } |
| 2357 | |
Wale Ogunwale | 04a05ac | 2017-09-17 21:35:02 -0700 | [diff] [blame] | 2358 | int resolveActivityType(@Nullable ActivityRecord r, @Nullable ActivityOptions options, |
Wale Ogunwale | 0568aed | 2017-09-08 13:29:37 -0700 | [diff] [blame] | 2359 | @Nullable TaskRecord task) { |
Wale Ogunwale | 04a05ac | 2017-09-17 21:35:02 -0700 | [diff] [blame] | 2360 | // Preference is given to the activity type for the activity then the task since the type |
| 2361 | // once set shouldn't change. |
| 2362 | int activityType = r != null ? r.getActivityType() : ACTIVITY_TYPE_UNDEFINED; |
| 2363 | if (activityType == ACTIVITY_TYPE_UNDEFINED && task != null) { |
| 2364 | activityType = task.getActivityType(); |
| 2365 | } |
Wale Ogunwale | 0568aed | 2017-09-08 13:29:37 -0700 | [diff] [blame] | 2366 | if (activityType != ACTIVITY_TYPE_UNDEFINED) { |
| 2367 | return activityType; |
| 2368 | } |
Wale Ogunwale | ab5de37 | 2017-10-18 06:46:31 -0700 | [diff] [blame] | 2369 | if (options != null) { |
| 2370 | activityType = options.getLaunchActivityType(); |
| 2371 | } |
| 2372 | return activityType != ACTIVITY_TYPE_UNDEFINED ? activityType : ACTIVITY_TYPE_STANDARD; |
Wale Ogunwale | 0568aed | 2017-09-08 13:29:37 -0700 | [diff] [blame] | 2373 | } |
| 2374 | |
Wale Ogunwale | 04a05ac | 2017-09-17 21:35:02 -0700 | [diff] [blame] | 2375 | <T extends ActivityStack> T getLaunchStack(@Nullable ActivityRecord r, |
| 2376 | @Nullable ActivityOptions options, @Nullable TaskRecord candidateTask, boolean onTop) { |
| 2377 | return getLaunchStack(r, options, candidateTask, onTop, INVALID_DISPLAY); |
Wale Ogunwale | 0568aed | 2017-09-08 13:29:37 -0700 | [diff] [blame] | 2378 | } |
| 2379 | |
| 2380 | /** |
| 2381 | * Returns the right stack to use for launching factoring in all the input parameters. |
| 2382 | * |
| 2383 | * @param r The activity we are trying to launch. Can be null. |
| 2384 | * @param options The activity options used to the launch. Can be null. |
| 2385 | * @param candidateTask The possible task the activity might be launched in. Can be null. |
| 2386 | * |
| 2387 | * @return The stack to use for the launch or INVALID_STACK_ID. |
| 2388 | */ |
Wale Ogunwale | 04a05ac | 2017-09-17 21:35:02 -0700 | [diff] [blame] | 2389 | <T extends ActivityStack> T getLaunchStack(@Nullable ActivityRecord r, |
| 2390 | @Nullable ActivityOptions options, @Nullable TaskRecord candidateTask, boolean onTop, |
| 2391 | int candidateDisplayId) { |
Wale Ogunwale | 0568aed | 2017-09-08 13:29:37 -0700 | [diff] [blame] | 2392 | int taskId = INVALID_TASK_ID; |
| 2393 | int displayId = INVALID_DISPLAY; |
| 2394 | //Rect bounds = null; |
| 2395 | |
| 2396 | // We give preference to the launch preference in activity options. |
| 2397 | if (options != null) { |
| 2398 | taskId = options.getLaunchTaskId(); |
| 2399 | displayId = options.getLaunchDisplayId(); |
| 2400 | // TODO: Need to work this into the equation... |
| 2401 | //bounds = options.getLaunchBounds(); |
| 2402 | } |
| 2403 | |
| 2404 | // First preference for stack goes to the task Id set in the activity options. Use the stack |
| 2405 | // associated with that if possible. |
| 2406 | if (taskId != INVALID_TASK_ID) { |
| 2407 | // Temporarily set the task id to invalid in case in re-entry. |
| 2408 | options.setLaunchTaskId(INVALID_TASK_ID); |
| 2409 | final TaskRecord task = anyTaskForIdLocked(taskId, |
Wale Ogunwale | ab5de37 | 2017-10-18 06:46:31 -0700 | [diff] [blame] | 2410 | MATCH_TASK_IN_STACKS_OR_RECENT_TASKS_AND_RESTORE, options, onTop); |
Wale Ogunwale | 0568aed | 2017-09-08 13:29:37 -0700 | [diff] [blame] | 2411 | options.setLaunchTaskId(taskId); |
| 2412 | if (task != null) { |
Wale Ogunwale | 04a05ac | 2017-09-17 21:35:02 -0700 | [diff] [blame] | 2413 | return task.getStack(); |
Wale Ogunwale | 0568aed | 2017-09-08 13:29:37 -0700 | [diff] [blame] | 2414 | } |
| 2415 | } |
| 2416 | |
Wale Ogunwale | 0568aed | 2017-09-08 13:29:37 -0700 | [diff] [blame] | 2417 | final int activityType = resolveActivityType(r, options, candidateTask); |
Wale Ogunwale | 04a05ac | 2017-09-17 21:35:02 -0700 | [diff] [blame] | 2418 | T stack = null; |
Wale Ogunwale | 0568aed | 2017-09-08 13:29:37 -0700 | [diff] [blame] | 2419 | |
| 2420 | // Next preference for stack goes to the display Id set in the activity options or the |
| 2421 | // candidate display. |
| 2422 | if (displayId == INVALID_DISPLAY) { |
| 2423 | displayId = candidateDisplayId; |
| 2424 | } |
Andrii Kulian | b850ea5 | 2017-12-12 23:49:10 -0800 | [diff] [blame] | 2425 | if (displayId != INVALID_DISPLAY && canLaunchOnDisplay(r, displayId)) { |
Wale Ogunwale | 0568aed | 2017-09-08 13:29:37 -0700 | [diff] [blame] | 2426 | if (r != null) { |
Riddle Hsu | fd4a050 | 2018-10-16 01:05:16 +0800 | [diff] [blame] | 2427 | stack = (T) getValidLaunchStackOnDisplay(displayId, r, candidateTask, options); |
Wale Ogunwale | 0568aed | 2017-09-08 13:29:37 -0700 | [diff] [blame] | 2428 | if (stack != null) { |
Wale Ogunwale | 04a05ac | 2017-09-17 21:35:02 -0700 | [diff] [blame] | 2429 | return stack; |
Wale Ogunwale | 0568aed | 2017-09-08 13:29:37 -0700 | [diff] [blame] | 2430 | } |
| 2431 | } |
| 2432 | final ActivityDisplay display = getActivityDisplayOrCreateLocked(displayId); |
| 2433 | if (display != null) { |
Wale Ogunwale | 7e1f5f5 | 2017-10-18 15:19:59 -0700 | [diff] [blame] | 2434 | stack = display.getOrCreateStack(r, options, candidateTask, activityType, onTop); |
Wale Ogunwale | ab5de37 | 2017-10-18 06:46:31 -0700 | [diff] [blame] | 2435 | if (stack != null) { |
| 2436 | return stack; |
Wale Ogunwale | 0568aed | 2017-09-08 13:29:37 -0700 | [diff] [blame] | 2437 | } |
Wale Ogunwale | 0568aed | 2017-09-08 13:29:37 -0700 | [diff] [blame] | 2438 | } |
| 2439 | } |
| 2440 | |
| 2441 | // Give preference to the stack and display of the input task and activity if they match the |
| 2442 | // mode we want to launch into. |
Wale Ogunwale | 04a05ac | 2017-09-17 21:35:02 -0700 | [diff] [blame] | 2443 | stack = null; |
| 2444 | ActivityDisplay display = null; |
Wale Ogunwale | 0568aed | 2017-09-08 13:29:37 -0700 | [diff] [blame] | 2445 | if (candidateTask != null) { |
| 2446 | stack = candidateTask.getStack(); |
| 2447 | } |
| 2448 | if (stack == null && r != null) { |
| 2449 | stack = r.getStack(); |
| 2450 | } |
| 2451 | if (stack != null) { |
Wale Ogunwale | 04a05ac | 2017-09-17 21:35:02 -0700 | [diff] [blame] | 2452 | display = stack.getDisplay(); |
Andrii Kulian | b850ea5 | 2017-12-12 23:49:10 -0800 | [diff] [blame] | 2453 | if (display != null && canLaunchOnDisplay(r, display.mDisplayId)) { |
Wale Ogunwale | 7e1f5f5 | 2017-10-18 15:19:59 -0700 | [diff] [blame] | 2454 | final int windowingMode = |
| 2455 | display.resolveWindowingMode(r, options, candidateTask, activityType); |
| 2456 | if (stack.isCompatible(windowingMode, activityType)) { |
| 2457 | return stack; |
| 2458 | } |
Andrii Kulian | ec7d4c4 | 2018-04-26 18:31:58 -0700 | [diff] [blame] | 2459 | if (windowingMode == WINDOWING_MODE_FULLSCREEN_OR_SPLIT_SCREEN_SECONDARY |
| 2460 | && display.getSplitScreenPrimaryStack() == stack |
| 2461 | && candidateTask == stack.topTask()) { |
| 2462 | // This is a special case when we try to launch an activity that is currently on |
| 2463 | // top of split-screen primary stack, but is targeting split-screen secondary. |
| 2464 | // In this case we don't want to move it to another stack. |
| 2465 | // TODO(b/78788972): Remove after differentiating between preferred and required |
| 2466 | // launch options. |
| 2467 | return stack; |
| 2468 | } |
Wale Ogunwale | 7e1f5f5 | 2017-10-18 15:19:59 -0700 | [diff] [blame] | 2469 | } |
Wale Ogunwale | 0568aed | 2017-09-08 13:29:37 -0700 | [diff] [blame] | 2470 | } |
| 2471 | |
Louis Chang | 6322c42 | 2018-07-18 18:37:28 +0800 | [diff] [blame] | 2472 | if (display == null || !canLaunchOnDisplay(r, display.mDisplayId)) { |
Wale Ogunwale | 04a05ac | 2017-09-17 21:35:02 -0700 | [diff] [blame] | 2473 | display = getDefaultDisplay(); |
Wale Ogunwale | 0568aed | 2017-09-08 13:29:37 -0700 | [diff] [blame] | 2474 | } |
Wale Ogunwale | 04a05ac | 2017-09-17 21:35:02 -0700 | [diff] [blame] | 2475 | |
Wale Ogunwale | 7e1f5f5 | 2017-10-18 15:19:59 -0700 | [diff] [blame] | 2476 | return display.getOrCreateStack(r, options, candidateTask, activityType, onTop); |
Wale Ogunwale | 0568aed | 2017-09-08 13:29:37 -0700 | [diff] [blame] | 2477 | } |
| 2478 | |
Andrii Kulian | b850ea5 | 2017-12-12 23:49:10 -0800 | [diff] [blame] | 2479 | /** @return true if activity record is null or can be launched on provided display. */ |
| 2480 | private boolean canLaunchOnDisplay(ActivityRecord r, int displayId) { |
| 2481 | if (r == null) { |
| 2482 | return true; |
| 2483 | } |
| 2484 | return r.canBeLaunchedOnDisplay(displayId); |
| 2485 | } |
| 2486 | |
Andrii Kulian | 16802aa | 2016-11-02 12:21:33 -0700 | [diff] [blame] | 2487 | /** |
| 2488 | * Get a topmost stack on the display, that is a valid launch stack for specified activity. |
| 2489 | * If there is no such stack, new dynamic stack can be created. |
| 2490 | * @param displayId Target display. |
| 2491 | * @param r Activity that should be launched there. |
Riddle Hsu | fd4a050 | 2018-10-16 01:05:16 +0800 | [diff] [blame] | 2492 | * @param candidateTask The possible task the activity might be put in. |
Andrii Kulian | 16802aa | 2016-11-02 12:21:33 -0700 | [diff] [blame] | 2493 | * @return Existing stack if there is a valid one, new dynamic stack if it is valid or null. |
| 2494 | */ |
Louis Chang | 6322c42 | 2018-07-18 18:37:28 +0800 | [diff] [blame] | 2495 | ActivityStack getValidLaunchStackOnDisplay(int displayId, @NonNull ActivityRecord r, |
Riddle Hsu | fd4a050 | 2018-10-16 01:05:16 +0800 | [diff] [blame] | 2496 | @Nullable TaskRecord candidateTask, @Nullable ActivityOptions options) { |
Andrii Kulian | 62e6f25 | 2017-05-30 22:46:53 -0700 | [diff] [blame] | 2497 | final ActivityDisplay activityDisplay = getActivityDisplayOrCreateLocked(displayId); |
Andrii Kulian | 16802aa | 2016-11-02 12:21:33 -0700 | [diff] [blame] | 2498 | if (activityDisplay == null) { |
| 2499 | throw new IllegalArgumentException( |
| 2500 | "Display with displayId=" + displayId + " not found."); |
| 2501 | } |
| 2502 | |
Wale Ogunwale | 04a05ac | 2017-09-17 21:35:02 -0700 | [diff] [blame] | 2503 | if (!r.canBeLaunchedOnDisplay(displayId)) { |
| 2504 | return null; |
| 2505 | } |
| 2506 | |
Riddle Hsu | fd4a050 | 2018-10-16 01:05:16 +0800 | [diff] [blame] | 2507 | // If {@code r} is already in target display and its task is the same as the candidate task, |
| 2508 | // the intention should be getting a launch stack for the reusable activity, so we can use |
| 2509 | // the existing stack. |
| 2510 | if (r.getDisplayId() == displayId && r.getTask() == candidateTask) { |
| 2511 | return candidateTask.getStack(); |
| 2512 | } |
| 2513 | |
Andrii Kulian | 16802aa | 2016-11-02 12:21:33 -0700 | [diff] [blame] | 2514 | // Return the topmost valid stack on the display. |
Wale Ogunwale | a0f5b5e | 2017-10-11 09:37:23 -0700 | [diff] [blame] | 2515 | for (int i = activityDisplay.getChildCount() - 1; i >= 0; --i) { |
| 2516 | final ActivityStack stack = activityDisplay.getChildAt(i); |
Wale Ogunwale | 6827856 | 2017-09-23 17:13:55 -0700 | [diff] [blame] | 2517 | if (isValidLaunchStack(stack, displayId, r)) { |
Andrii Kulian | 16802aa | 2016-11-02 12:21:33 -0700 | [diff] [blame] | 2518 | return stack; |
| 2519 | } |
| 2520 | } |
| 2521 | |
| 2522 | // If there is no valid stack on the external display - check if new dynamic stack will do. |
Wale Ogunwale | 04a05ac | 2017-09-17 21:35:02 -0700 | [diff] [blame] | 2523 | if (displayId != DEFAULT_DISPLAY) { |
| 2524 | return activityDisplay.createStack( |
Louis Chang | 6322c42 | 2018-07-18 18:37:28 +0800 | [diff] [blame] | 2525 | options != null ? options.getLaunchWindowingMode() : r.getWindowingMode(), |
| 2526 | options != null ? options.getLaunchActivityType() : r.getActivityType(), |
| 2527 | true /*onTop*/); |
Andrii Kulian | 16802aa | 2016-11-02 12:21:33 -0700 | [diff] [blame] | 2528 | } |
| 2529 | |
| 2530 | Slog.w(TAG, "getValidLaunchStackOnDisplay: can't launch on displayId " + displayId); |
| 2531 | return null; |
| 2532 | } |
| 2533 | |
Riddle Hsu | fd4a050 | 2018-10-16 01:05:16 +0800 | [diff] [blame] | 2534 | ActivityStack getValidLaunchStackOnDisplay(int displayId, @NonNull ActivityRecord r, |
| 2535 | @Nullable ActivityOptions options) { |
| 2536 | return getValidLaunchStackOnDisplay(displayId, r, null /* candidateTask */, options); |
| 2537 | } |
| 2538 | |
Wale Ogunwale | 6827856 | 2017-09-23 17:13:55 -0700 | [diff] [blame] | 2539 | // TODO: Can probably be consolidated into getLaunchStack()... |
| 2540 | private boolean isValidLaunchStack(ActivityStack stack, int displayId, ActivityRecord r) { |
| 2541 | switch (stack.getActivityType()) { |
| 2542 | case ACTIVITY_TYPE_HOME: return r.isActivityTypeHome(); |
| 2543 | case ACTIVITY_TYPE_RECENTS: return r.isActivityTypeRecents(); |
| 2544 | case ACTIVITY_TYPE_ASSISTANT: return r.isActivityTypeAssistant(); |
Wale Ogunwale | 0568aed | 2017-09-08 13:29:37 -0700 | [diff] [blame] | 2545 | } |
Evan Rosky | 9ba524e | 2018-01-03 16:27:56 -0800 | [diff] [blame] | 2546 | // There is a 1-to-1 relationship between stack and task when not in |
| 2547 | // primary split-windowing mode. |
| 2548 | if (stack.getWindowingMode() != WINDOWING_MODE_SPLIT_SCREEN_PRIMARY) { |
| 2549 | return false; |
| 2550 | } else { |
| 2551 | return r.supportsSplitScreenWindowingMode(); |
Wale Ogunwale | 6827856 | 2017-09-23 17:13:55 -0700 | [diff] [blame] | 2552 | } |
Wale Ogunwale | 0568aed | 2017-09-08 13:29:37 -0700 | [diff] [blame] | 2553 | } |
| 2554 | |
Andrii Kulian | 7fc2281 | 2016-12-28 13:04:11 -0800 | [diff] [blame] | 2555 | /** |
Andrii Kulian | ab132ee | 2018-07-24 22:10:21 +0800 | [diff] [blame] | 2556 | * Get next focusable stack in the system. This will search through the stack on the same |
| 2557 | * display as the current focused stack, looking for a focusable and visible stack, different |
| 2558 | * from the target stack. If no valid candidates will be found, it will then go through all |
| 2559 | * displays and stacks in last-focused order. |
Andrii Kulian | 7fc2281 | 2016-12-28 13:04:11 -0800 | [diff] [blame] | 2560 | * |
Wale Ogunwale | e1f68ce | 2018-03-09 08:58:54 -0800 | [diff] [blame] | 2561 | * @param currentFocus The stack that previously had focus. |
| 2562 | * @param ignoreCurrent If we should ignore {@param currentFocus} when searching for next |
| 2563 | * candidate. |
Andrii Kulian | ab132ee | 2018-07-24 22:10:21 +0800 | [diff] [blame] | 2564 | * @return Next focusable {@link ActivityStack}, {@code null} if not found. |
Andrii Kulian | 7fc2281 | 2016-12-28 13:04:11 -0800 | [diff] [blame] | 2565 | */ |
Andrii Kulian | ab132ee | 2018-07-24 22:10:21 +0800 | [diff] [blame] | 2566 | ActivityStack getNextFocusableStackLocked(@NonNull ActivityStack currentFocus, |
| 2567 | boolean ignoreCurrent) { |
| 2568 | // First look for next focusable stack on the same display |
| 2569 | final ActivityDisplay preferredDisplay = currentFocus.getDisplay(); |
| 2570 | final ActivityStack preferredFocusableStack = preferredDisplay.getNextFocusableStack( |
| 2571 | currentFocus, ignoreCurrent); |
| 2572 | if (preferredFocusableStack != null) { |
| 2573 | return preferredFocusableStack; |
| 2574 | } |
Louis Chang | bd48dca | 2018-08-29 17:44:34 +0800 | [diff] [blame] | 2575 | if (preferredDisplay.supportsSystemDecorations()) { |
| 2576 | // Stop looking for focusable stack on other displays because the preferred display |
| 2577 | // supports system decorations. Home activity would be launched on the same display if |
| 2578 | // no focusable stack found. |
| 2579 | return null; |
| 2580 | } |
Andrii Kulian | 7fc2281 | 2016-12-28 13:04:11 -0800 | [diff] [blame] | 2581 | |
Andrii Kulian | ab132ee | 2018-07-24 22:10:21 +0800 | [diff] [blame] | 2582 | // Now look through all displays |
Riddle Hsu | 86cb7de | 2018-08-13 23:29:58 +0800 | [diff] [blame] | 2583 | for (int i = mActivityDisplays.size() - 1; i >= 0; --i) { |
| 2584 | final ActivityDisplay display = mActivityDisplays.get(i); |
| 2585 | if (display == preferredDisplay) { |
Andrii Kulian | ab132ee | 2018-07-24 22:10:21 +0800 | [diff] [blame] | 2586 | // We've already checked this one |
| 2587 | continue; |
| 2588 | } |
Andrii Kulian | ab132ee | 2018-07-24 22:10:21 +0800 | [diff] [blame] | 2589 | final ActivityStack nextFocusableStack = display.getNextFocusableStack(currentFocus, |
| 2590 | ignoreCurrent); |
| 2591 | if (nextFocusableStack != null) { |
| 2592 | return nextFocusableStack; |
Andrii Kulian | 7fc2281 | 2016-12-28 13:04:11 -0800 | [diff] [blame] | 2593 | } |
| 2594 | } |
| 2595 | |
Andrii Kulian | ab132ee | 2018-07-24 22:10:21 +0800 | [diff] [blame] | 2596 | return null; |
Andrii Kulian | 7fc2281 | 2016-12-28 13:04:11 -0800 | [diff] [blame] | 2597 | } |
| 2598 | |
Andrii Kulian | a8fe3df | 2017-06-16 15:29:26 -0700 | [diff] [blame] | 2599 | /** |
| 2600 | * Get next valid stack for launching provided activity in the system. This will search across |
| 2601 | * displays and stacks in last-focused order for a focusable and visible stack, except those |
| 2602 | * that are on a currently focused display. |
| 2603 | * |
| 2604 | * @param r The activity that is being launched. |
| 2605 | * @param currentFocus The display that previously had focus and thus needs to be ignored when |
| 2606 | * searching for the next candidate. |
| 2607 | * @return Next valid {@link ActivityStack}, null if not found. |
| 2608 | */ |
| 2609 | ActivityStack getNextValidLaunchStackLocked(@NonNull ActivityRecord r, int currentFocus) { |
Riddle Hsu | 86cb7de | 2018-08-13 23:29:58 +0800 | [diff] [blame] | 2610 | for (int i = mActivityDisplays.size() - 1; i >= 0; --i) { |
| 2611 | final ActivityDisplay display = mActivityDisplays.get(i); |
| 2612 | if (display.mDisplayId == currentFocus) { |
Andrii Kulian | a8fe3df | 2017-06-16 15:29:26 -0700 | [diff] [blame] | 2613 | continue; |
| 2614 | } |
Riddle Hsu | 86cb7de | 2018-08-13 23:29:58 +0800 | [diff] [blame] | 2615 | final ActivityStack stack = getValidLaunchStackOnDisplay(display.mDisplayId, r, |
Louis Chang | 6322c42 | 2018-07-18 18:37:28 +0800 | [diff] [blame] | 2616 | null /* options */); |
Andrii Kulian | a8fe3df | 2017-06-16 15:29:26 -0700 | [diff] [blame] | 2617 | if (stack != null) { |
| 2618 | return stack; |
| 2619 | } |
| 2620 | } |
| 2621 | return null; |
| 2622 | } |
| 2623 | |
Louis Chang | bd48dca | 2018-08-29 17:44:34 +0800 | [diff] [blame] | 2624 | ActivityRecord getDefaultDisplayHomeActivity() { |
| 2625 | return getDefaultDisplayHomeActivityForUser(mCurrentUser); |
Fyodor Kupolov | b501330 | 2015-04-17 17:59:14 -0700 | [diff] [blame] | 2626 | } |
| 2627 | |
Louis Chang | bd48dca | 2018-08-29 17:44:34 +0800 | [diff] [blame] | 2628 | ActivityRecord getDefaultDisplayHomeActivityForUser(int userId) { |
Martijn Coenen | 2a5c839 | 2018-10-01 10:17:06 +0200 | [diff] [blame] | 2629 | return getActivityDisplay(DEFAULT_DISPLAY).getHomeActivityForUser(userId); |
Craig Mautner | 4a1cb22 | 2013-12-04 16:14:06 -0800 | [diff] [blame] | 2630 | } |
| 2631 | |
Wale Ogunwale | 44f036f | 2017-09-29 05:09:09 -0700 | [diff] [blame] | 2632 | void resizeStackLocked(ActivityStack stack, Rect bounds, Rect tempTaskBounds, |
| 2633 | Rect tempTaskInsetBounds, boolean preserveWindows, boolean allowResizeInDockedMode, |
| 2634 | boolean deferResume) { |
| 2635 | |
| 2636 | if (stack.inSplitScreenPrimaryWindowingMode()) { |
Jorim Jaggi | dc249c4 | 2015-12-15 14:57:31 -0800 | [diff] [blame] | 2637 | resizeDockedStackLocked(bounds, tempTaskBounds, tempTaskInsetBounds, null, null, |
Andrii Kulian | db3e4ec | 2016-07-12 17:11:35 -0700 | [diff] [blame] | 2638 | preserveWindows, deferResume); |
Jorim Jaggi | dc249c4 | 2015-12-15 14:57:31 -0800 | [diff] [blame] | 2639 | return; |
| 2640 | } |
Wale Ogunwale | 9d3de4c | 2015-02-01 16:49:44 -0800 | [diff] [blame] | 2641 | |
Wale Ogunwale | a0f5b5e | 2017-10-11 09:37:23 -0700 | [diff] [blame] | 2642 | final boolean splitScreenActive = getDefaultDisplay().hasSplitScreenPrimaryStack(); |
Wale Ogunwale | 3382ab1 | 2017-07-27 08:55:03 -0700 | [diff] [blame] | 2643 | if (!allowResizeInDockedMode |
Wale Ogunwale | 926aade | 2017-08-29 11:24:37 -0700 | [diff] [blame] | 2644 | && !stack.getWindowConfiguration().tasksAreFloating() && splitScreenActive) { |
Winson Chung | a2249ac | 2017-03-30 18:15:30 -0700 | [diff] [blame] | 2645 | // If the docked stack exists, don't resize non-floating stacks independently of the |
| 2646 | // size computed from the docked stack size (otherwise they will be out of sync) |
Wale Ogunwale | ffc11bb | 2015-10-10 13:05:45 -0700 | [diff] [blame] | 2647 | return; |
| 2648 | } |
| 2649 | |
Wale Ogunwale | 44f036f | 2017-09-29 05:09:09 -0700 | [diff] [blame] | 2650 | Trace.traceBegin(TRACE_TAG_ACTIVITY_MANAGER, "am.resizeStack_" + stack.mStackId); |
Jorim Jaggi | c402520 | 2015-10-22 16:43:34 +0200 | [diff] [blame] | 2651 | mWindowManager.deferSurfaceLayout(); |
| 2652 | try { |
Wale Ogunwale | 2b07da8 | 2017-11-08 14:52:40 -0800 | [diff] [blame] | 2653 | if (stack.affectedBySplitScreenResize()) { |
Wale Ogunwale | 926aade | 2017-08-29 11:24:37 -0700 | [diff] [blame] | 2654 | if (bounds == null && stack.inSplitScreenWindowingMode()) { |
| 2655 | // null bounds = fullscreen windowing mode...at least for now. |
| 2656 | stack.setWindowingMode(WINDOWING_MODE_FULLSCREEN); |
| 2657 | } else if (splitScreenActive) { |
| 2658 | // If we are in split-screen mode and this stack support split-screen, then |
| 2659 | // it should be split-screen secondary mode. i.e. adjacent to the docked stack. |
| 2660 | stack.setWindowingMode(WINDOWING_MODE_SPLIT_SCREEN_SECONDARY); |
| 2661 | } |
| 2662 | } |
Wale Ogunwale | 1666e31 | 2016-12-16 11:27:18 -0800 | [diff] [blame] | 2663 | stack.resize(bounds, tempTaskBounds, tempTaskInsetBounds); |
Wale Ogunwale | c8da41e | 2016-04-16 13:27:23 -0700 | [diff] [blame] | 2664 | if (!deferResume) { |
Wale Ogunwale | db0fa12 | 2016-05-16 15:12:03 -0700 | [diff] [blame] | 2665 | stack.ensureVisibleActivitiesConfigurationLocked( |
| 2666 | stack.topRunningActivityLocked(), preserveWindows); |
Wale Ogunwale | c8da41e | 2016-04-16 13:27:23 -0700 | [diff] [blame] | 2667 | } |
Jorim Jaggi | c402520 | 2015-10-22 16:43:34 +0200 | [diff] [blame] | 2668 | } finally { |
| 2669 | mWindowManager.continueSurfaceLayout(); |
| 2670 | Trace.traceEnd(TRACE_TAG_ACTIVITY_MANAGER); |
Wale Ogunwale | e4a0c57 | 2015-06-30 08:40:31 -0700 | [diff] [blame] | 2671 | } |
| 2672 | } |
| 2673 | |
Winson Chung | c167427 | 2018-02-21 10:15:17 -0800 | [diff] [blame] | 2674 | void deferUpdateRecentsHomeStackBounds() { |
| 2675 | deferUpdateBounds(ACTIVITY_TYPE_RECENTS); |
| 2676 | deferUpdateBounds(ACTIVITY_TYPE_HOME); |
| 2677 | } |
| 2678 | |
Bryce Lee | d3624e1 | 2017-11-30 08:51:45 -0800 | [diff] [blame] | 2679 | void deferUpdateBounds(int activityType) { |
Wale Ogunwale | 6827856 | 2017-09-23 17:13:55 -0700 | [diff] [blame] | 2680 | final ActivityStack stack = getStack(WINDOWING_MODE_UNDEFINED, activityType); |
Jorim Jaggi | 192086e | 2016-03-11 17:17:03 +0100 | [diff] [blame] | 2681 | if (stack != null) { |
| 2682 | stack.deferUpdateBounds(); |
| 2683 | } |
| 2684 | } |
| 2685 | |
Winson Chung | c167427 | 2018-02-21 10:15:17 -0800 | [diff] [blame] | 2686 | void continueUpdateRecentsHomeStackBounds() { |
| 2687 | continueUpdateBounds(ACTIVITY_TYPE_RECENTS); |
| 2688 | continueUpdateBounds(ACTIVITY_TYPE_HOME); |
| 2689 | } |
| 2690 | |
Bryce Lee | d3624e1 | 2017-11-30 08:51:45 -0800 | [diff] [blame] | 2691 | void continueUpdateBounds(int activityType) { |
Wale Ogunwale | 6827856 | 2017-09-23 17:13:55 -0700 | [diff] [blame] | 2692 | final ActivityStack stack = getStack(WINDOWING_MODE_UNDEFINED, activityType); |
Jorim Jaggi | 192086e | 2016-03-11 17:17:03 +0100 | [diff] [blame] | 2693 | if (stack != null) { |
| 2694 | stack.continueUpdateBounds(); |
| 2695 | } |
| 2696 | } |
| 2697 | |
Jorim Jaggi | 0b46f3c | 2016-03-14 12:21:37 +0100 | [diff] [blame] | 2698 | void notifyAppTransitionDone() { |
Winson Chung | c167427 | 2018-02-21 10:15:17 -0800 | [diff] [blame] | 2699 | continueUpdateRecentsHomeStackBounds(); |
Jorim Jaggi | 0b46f3c | 2016-03-14 12:21:37 +0100 | [diff] [blame] | 2700 | for (int i = mResizingTasksDuringAnimation.size() - 1; i >= 0; i--) { |
| 2701 | final int taskId = mResizingTasksDuringAnimation.valueAt(i); |
Wale Ogunwale | 0568aed | 2017-09-08 13:29:37 -0700 | [diff] [blame] | 2702 | final TaskRecord task = anyTaskForIdLocked(taskId, MATCH_TASK_IN_STACKS_ONLY); |
Wale Ogunwale | e1fe7fa2 | 2016-12-15 18:27:00 -0800 | [diff] [blame] | 2703 | if (task != null) { |
| 2704 | task.setTaskDockedResizing(false); |
Jorim Jaggi | 0b46f3c | 2016-03-14 12:21:37 +0100 | [diff] [blame] | 2705 | } |
| 2706 | } |
| 2707 | mResizingTasksDuringAnimation.clear(); |
| 2708 | } |
| 2709 | |
Wale Ogunwale | 04a05ac | 2017-09-17 21:35:02 -0700 | [diff] [blame] | 2710 | /** |
| 2711 | * TODO: This should just change the windowing mode and resize vs. actually moving task around. |
Wale Ogunwale | 44f036f | 2017-09-29 05:09:09 -0700 | [diff] [blame] | 2712 | * Can do that once we are no longer using static stack ids. |
Wale Ogunwale | 04a05ac | 2017-09-17 21:35:02 -0700 | [diff] [blame] | 2713 | */ |
Wale Ogunwale | 9dcf946 | 2017-09-19 15:13:01 -0700 | [diff] [blame] | 2714 | private void moveTasksToFullscreenStackInSurfaceTransaction(ActivityStack fromStack, |
Wale Ogunwale | 04a05ac | 2017-09-17 21:35:02 -0700 | [diff] [blame] | 2715 | int toDisplayId, boolean onTop) { |
Robert Carr | 6914f08 | 2017-03-20 19:04:30 -0700 | [diff] [blame] | 2716 | |
Wale Ogunwale | c8da41e | 2016-04-16 13:27:23 -0700 | [diff] [blame] | 2717 | mWindowManager.deferSurfaceLayout(); |
| 2718 | try { |
Wale Ogunwale | 04a05ac | 2017-09-17 21:35:02 -0700 | [diff] [blame] | 2719 | final int windowingMode = fromStack.getWindowingMode(); |
| 2720 | final boolean inPinnedWindowingMode = windowingMode == WINDOWING_MODE_PINNED; |
| 2721 | final ActivityDisplay toDisplay = getActivityDisplay(toDisplayId); |
| 2722 | |
| 2723 | if (windowingMode == WINDOWING_MODE_SPLIT_SCREEN_PRIMARY) { |
Wale Ogunwale | 7e1f5f5 | 2017-10-18 15:19:59 -0700 | [diff] [blame] | 2724 | // Tell the display we are exiting split-screen mode. |
| 2725 | toDisplay.onExitingSplitScreenMode(); |
Wale Ogunwale | c8da41e | 2016-04-16 13:27:23 -0700 | [diff] [blame] | 2726 | // We are moving all tasks from the docked stack to the fullscreen stack, |
| 2727 | // which is dismissing the docked stack, so resize all other stacks to |
| 2728 | // fullscreen here already so we don't end up with resize trashing. |
Wale Ogunwale | a0f5b5e | 2017-10-11 09:37:23 -0700 | [diff] [blame] | 2729 | for (int i = toDisplay.getChildCount() - 1; i >= 0; --i) { |
| 2730 | final ActivityStack otherStack = toDisplay.getChildAt(i); |
Wale Ogunwale | 926aade | 2017-08-29 11:24:37 -0700 | [diff] [blame] | 2731 | if (!otherStack.inSplitScreenSecondaryWindowingMode()) { |
| 2732 | continue; |
| 2733 | } |
Evan Rosky | 1047574 | 2018-09-05 19:02:48 -0700 | [diff] [blame] | 2734 | otherStack.setWindowingMode(WINDOWING_MODE_UNDEFINED); |
Wale Ogunwale | c8da41e | 2016-04-16 13:27:23 -0700 | [diff] [blame] | 2735 | } |
| 2736 | |
| 2737 | // Also disable docked stack resizing since we have manually adjusted the |
| 2738 | // size of other stacks above and we don't want to trigger a docked stack |
| 2739 | // resize when we remove task from it below and it is detached from the |
| 2740 | // display because it no longer contains any tasks. |
| 2741 | mAllowDockedStackResize = false; |
| 2742 | } |
Wale Ogunwale | 04a05ac | 2017-09-17 21:35:02 -0700 | [diff] [blame] | 2743 | |
Winson Chung | 5af42fc | 2017-03-24 17:11:33 -0700 | [diff] [blame] | 2744 | // If we are moving from the pinned stack, then the animation takes care of updating |
| 2745 | // the picture-in-picture mode. |
Wale Ogunwale | 04a05ac | 2017-09-17 21:35:02 -0700 | [diff] [blame] | 2746 | final boolean schedulePictureInPictureModeChange = inPinnedWindowingMode; |
Wale Ogunwale | 9dcf946 | 2017-09-19 15:13:01 -0700 | [diff] [blame] | 2747 | final ArrayList<TaskRecord> tasks = fromStack.getAllTasks(); |
Wale Ogunwale | 04a05ac | 2017-09-17 21:35:02 -0700 | [diff] [blame] | 2748 | |
Wale Ogunwale | 388945c | 2017-10-04 12:13:46 -0700 | [diff] [blame] | 2749 | if (!tasks.isEmpty()) { |
Wale Ogunwale | 7e1f5f5 | 2017-10-18 15:19:59 -0700 | [diff] [blame] | 2750 | mTmpOptions.setLaunchWindowingMode(WINDOWING_MODE_FULLSCREEN); |
Wale Ogunwale | 388945c | 2017-10-04 12:13:46 -0700 | [diff] [blame] | 2751 | final int size = tasks.size(); |
Wale Ogunwale | 7e1f5f5 | 2017-10-18 15:19:59 -0700 | [diff] [blame] | 2752 | for (int i = 0; i < size; ++i) { |
| 2753 | final TaskRecord task = tasks.get(i); |
| 2754 | final ActivityStack toStack = toDisplay.getOrCreateStack( |
| 2755 | null, mTmpOptions, task, task.getActivityType(), onTop); |
Wale Ogunwale | 388945c | 2017-10-04 12:13:46 -0700 | [diff] [blame] | 2756 | |
Wale Ogunwale | 7e1f5f5 | 2017-10-18 15:19:59 -0700 | [diff] [blame] | 2757 | if (onTop) { |
Wale Ogunwale | 388945c | 2017-10-04 12:13:46 -0700 | [diff] [blame] | 2758 | final boolean isTopTask = i == (size - 1); |
Wale Ogunwale | 388945c | 2017-10-04 12:13:46 -0700 | [diff] [blame] | 2759 | // Defer resume until all the tasks have been moved to the fullscreen stack |
Wale Ogunwale | 7e1f5f5 | 2017-10-18 15:19:59 -0700 | [diff] [blame] | 2760 | task.reparent(toStack, ON_TOP, REPARENT_MOVE_STACK_TO_FRONT, |
Wale Ogunwale | 388945c | 2017-10-04 12:13:46 -0700 | [diff] [blame] | 2761 | isTopTask /* animate */, DEFER_RESUME, |
| 2762 | schedulePictureInPictureModeChange, |
| 2763 | "moveTasksToFullscreenStack - onTop"); |
Chenjie Yu | ae9fdf04 | 2018-02-15 10:19:32 -0800 | [diff] [blame] | 2764 | MetricsLoggerWrapper.logPictureInPictureFullScreen(mService.mContext, |
| 2765 | task.effectiveUid, task.realActivity.flattenToString()); |
Wale Ogunwale | 7e1f5f5 | 2017-10-18 15:19:59 -0700 | [diff] [blame] | 2766 | } else { |
Wale Ogunwale | 388945c | 2017-10-04 12:13:46 -0700 | [diff] [blame] | 2767 | // Position the tasks in the fullscreen stack in order at the bottom of the |
| 2768 | // stack. Also defer resume until all the tasks have been moved to the |
| 2769 | // fullscreen stack. |
Wale Ogunwale | 7e1f5f5 | 2017-10-18 15:19:59 -0700 | [diff] [blame] | 2770 | task.reparent(toStack, ON_TOP, |
Wale Ogunwale | 388945c | 2017-10-04 12:13:46 -0700 | [diff] [blame] | 2771 | REPARENT_LEAVE_STACK_IN_PLACE, !ANIMATE, DEFER_RESUME, |
| 2772 | schedulePictureInPictureModeChange, |
| 2773 | "moveTasksToFullscreenStack - NOT_onTop"); |
| 2774 | } |
Wale Ogunwale | c8da41e | 2016-04-16 13:27:23 -0700 | [diff] [blame] | 2775 | } |
| 2776 | } |
Winson Chung | 7466610 | 2017-02-22 17:49:24 -0800 | [diff] [blame] | 2777 | |
| 2778 | ensureActivitiesVisibleLocked(null, 0, PRESERVE_WINDOWS); |
Andrii Kulian | ab132ee | 2018-07-24 22:10:21 +0800 | [diff] [blame] | 2779 | resumeFocusedStacksTopActivitiesLocked(); |
Wale Ogunwale | c8da41e | 2016-04-16 13:27:23 -0700 | [diff] [blame] | 2780 | } finally { |
| 2781 | mAllowDockedStackResize = true; |
| 2782 | mWindowManager.continueSurfaceLayout(); |
| 2783 | } |
| 2784 | } |
| 2785 | |
Wale Ogunwale | 9dcf946 | 2017-09-19 15:13:01 -0700 | [diff] [blame] | 2786 | void moveTasksToFullscreenStackLocked(ActivityStack fromStack, boolean onTop) { |
Wale Ogunwale | 04a05ac | 2017-09-17 21:35:02 -0700 | [diff] [blame] | 2787 | moveTasksToFullscreenStackLocked(fromStack, DEFAULT_DISPLAY, onTop); |
| 2788 | } |
| 2789 | |
| 2790 | void moveTasksToFullscreenStackLocked(ActivityStack fromStack, int toDisplayId, boolean onTop) { |
| 2791 | mWindowManager.inSurfaceTransaction(() -> |
| 2792 | moveTasksToFullscreenStackInSurfaceTransaction(fromStack, toDisplayId, onTop)); |
Robert Carr | 6914f08 | 2017-03-20 19:04:30 -0700 | [diff] [blame] | 2793 | } |
| 2794 | |
Adrian Roos | a6d6aab | 2018-04-19 18:58:22 +0200 | [diff] [blame] | 2795 | void setSplitScreenResizing(boolean resizing) { |
| 2796 | if (resizing == mDockedStackResizing) { |
| 2797 | return; |
| 2798 | } |
| 2799 | |
| 2800 | mDockedStackResizing = resizing; |
| 2801 | mWindowManager.setDockedStackResizing(resizing); |
| 2802 | |
| 2803 | if (!resizing && mHasPendingDockedBounds) { |
| 2804 | resizeDockedStackLocked(mPendingDockedBounds, mPendingTempDockedTaskBounds, |
| 2805 | mPendingTempDockedTaskInsetBounds, mPendingTempOtherTaskBounds, |
| 2806 | mPendingTempOtherTaskInsetBounds, PRESERVE_WINDOWS); |
| 2807 | |
| 2808 | mHasPendingDockedBounds = false; |
| 2809 | mPendingDockedBounds = null; |
| 2810 | mPendingTempDockedTaskBounds = null; |
| 2811 | mPendingTempDockedTaskInsetBounds = null; |
| 2812 | mPendingTempOtherTaskBounds = null; |
| 2813 | mPendingTempOtherTaskInsetBounds = null; |
| 2814 | } |
| 2815 | } |
| 2816 | |
Jorim Jaggi | dc249c4 | 2015-12-15 14:57:31 -0800 | [diff] [blame] | 2817 | void resizeDockedStackLocked(Rect dockedBounds, Rect tempDockedTaskBounds, |
Andrii Kulian | db3e4ec | 2016-07-12 17:11:35 -0700 | [diff] [blame] | 2818 | Rect tempDockedTaskInsetBounds, Rect tempOtherTaskBounds, Rect tempOtherTaskInsetBounds, |
| 2819 | boolean preserveWindows) { |
| 2820 | resizeDockedStackLocked(dockedBounds, tempDockedTaskBounds, tempDockedTaskInsetBounds, |
| 2821 | tempOtherTaskBounds, tempOtherTaskInsetBounds, preserveWindows, |
| 2822 | false /* deferResume */); |
| 2823 | } |
| 2824 | |
Wale Ogunwale | 04a05ac | 2017-09-17 21:35:02 -0700 | [diff] [blame] | 2825 | private void resizeDockedStackLocked(Rect dockedBounds, Rect tempDockedTaskBounds, |
Andrii Kulian | db3e4ec | 2016-07-12 17:11:35 -0700 | [diff] [blame] | 2826 | Rect tempDockedTaskInsetBounds, Rect tempOtherTaskBounds, Rect tempOtherTaskInsetBounds, |
| 2827 | boolean preserveWindows, boolean deferResume) { |
Wale Ogunwale | c8da41e | 2016-04-16 13:27:23 -0700 | [diff] [blame] | 2828 | |
| 2829 | if (!mAllowDockedStackResize) { |
| 2830 | // Docked stack resize currently disabled. |
| 2831 | return; |
| 2832 | } |
| 2833 | |
Wale Ogunwale | a0f5b5e | 2017-10-11 09:37:23 -0700 | [diff] [blame] | 2834 | final ActivityStack stack = getDefaultDisplay().getSplitScreenPrimaryStack(); |
Jorim Jaggi | dc249c4 | 2015-12-15 14:57:31 -0800 | [diff] [blame] | 2835 | if (stack == null) { |
| 2836 | Slog.w(TAG, "resizeDockedStackLocked: docked stack not found"); |
| 2837 | return; |
| 2838 | } |
| 2839 | |
Adrian Roos | a6d6aab | 2018-04-19 18:58:22 +0200 | [diff] [blame] | 2840 | if (mDockedStackResizing) { |
| 2841 | mHasPendingDockedBounds = true; |
| 2842 | mPendingDockedBounds = copyOrNull(dockedBounds); |
| 2843 | mPendingTempDockedTaskBounds = copyOrNull(tempDockedTaskBounds); |
| 2844 | mPendingTempDockedTaskInsetBounds = copyOrNull(tempDockedTaskInsetBounds); |
| 2845 | mPendingTempOtherTaskBounds = copyOrNull(tempOtherTaskBounds); |
| 2846 | mPendingTempOtherTaskInsetBounds = copyOrNull(tempOtherTaskInsetBounds); |
| 2847 | } |
| 2848 | |
Jorim Jaggi | dc249c4 | 2015-12-15 14:57:31 -0800 | [diff] [blame] | 2849 | Trace.traceBegin(TRACE_TAG_ACTIVITY_MANAGER, "am.resizeDockedStack"); |
| 2850 | mWindowManager.deferSurfaceLayout(); |
| 2851 | try { |
Wale Ogunwale | c8da41e | 2016-04-16 13:27:23 -0700 | [diff] [blame] | 2852 | // Don't allow re-entry while resizing. E.g. due to docked stack detaching. |
| 2853 | mAllowDockedStackResize = false; |
Jorim Jaggi | dc249c4 | 2015-12-15 14:57:31 -0800 | [diff] [blame] | 2854 | ActivityRecord r = stack.topRunningActivityLocked(); |
Wale Ogunwale | 1666e31 | 2016-12-16 11:27:18 -0800 | [diff] [blame] | 2855 | stack.resize(dockedBounds, tempDockedTaskBounds, tempDockedTaskInsetBounds); |
Jorim Jaggi | dc249c4 | 2015-12-15 14:57:31 -0800 | [diff] [blame] | 2856 | |
Andrii Kulian | 69fb5e4 | 2016-04-05 16:47:29 -0700 | [diff] [blame] | 2857 | // TODO: Checking for isAttached might not be needed as if the user passes in null |
| 2858 | // dockedBounds then they want the docked stack to be dismissed. |
Bryce Lee | f3c6a47 | 2017-11-14 14:53:06 -0800 | [diff] [blame] | 2859 | if (stack.getWindowingMode() == WINDOWING_MODE_FULLSCREEN |
| 2860 | || (dockedBounds == null && !stack.isAttached())) { |
Andrii Kulian | 69fb5e4 | 2016-04-05 16:47:29 -0700 | [diff] [blame] | 2861 | // The dock stack either was dismissed or went fullscreen, which is kinda the same. |
Jorim Jaggi | dc249c4 | 2015-12-15 14:57:31 -0800 | [diff] [blame] | 2862 | // In this case we make all other static stacks fullscreen and move all |
| 2863 | // docked stack tasks to the fullscreen stack. |
Wale Ogunwale | 9dcf946 | 2017-09-19 15:13:01 -0700 | [diff] [blame] | 2864 | moveTasksToFullscreenStackLocked(stack, ON_TOP); |
Jorim Jaggi | dc249c4 | 2015-12-15 14:57:31 -0800 | [diff] [blame] | 2865 | |
| 2866 | // stack shouldn't contain anymore activities, so nothing to resume. |
| 2867 | r = null; |
| 2868 | } else { |
| 2869 | // Docked stacks occupy a dedicated region on screen so the size of all other |
| 2870 | // static stacks need to be adjusted so they don't overlap with the docked stack. |
| 2871 | // We get the bounds to use from window manager which has been adjusted for any |
| 2872 | // screen controls and is also the same for all stacks. |
Wale Ogunwale | a0f5b5e | 2017-10-11 09:37:23 -0700 | [diff] [blame] | 2873 | final ActivityDisplay display = getDefaultDisplay(); |
Matthew Ng | aa2b620 | 2017-02-10 14:48:21 -0800 | [diff] [blame] | 2874 | final Rect otherTaskRect = new Rect(); |
Wale Ogunwale | a0f5b5e | 2017-10-11 09:37:23 -0700 | [diff] [blame] | 2875 | for (int i = display.getChildCount() - 1; i >= 0; --i) { |
| 2876 | final ActivityStack current = display.getChildAt(i); |
Wale Ogunwale | 04a05ac | 2017-09-17 21:35:02 -0700 | [diff] [blame] | 2877 | if (current.getWindowingMode() == WINDOWING_MODE_SPLIT_SCREEN_PRIMARY) { |
Wale Ogunwale | 926aade | 2017-08-29 11:24:37 -0700 | [diff] [blame] | 2878 | continue; |
Jorim Jaggi | dc249c4 | 2015-12-15 14:57:31 -0800 | [diff] [blame] | 2879 | } |
Wale Ogunwale | 2b07da8 | 2017-11-08 14:52:40 -0800 | [diff] [blame] | 2880 | if (!current.affectedBySplitScreenResize()) { |
Wale Ogunwale | 926aade | 2017-08-29 11:24:37 -0700 | [diff] [blame] | 2881 | continue; |
| 2882 | } |
Adrian Roos | a6d6aab | 2018-04-19 18:58:22 +0200 | [diff] [blame] | 2883 | if (mDockedStackResizing && !current.isTopActivityVisible()) { |
| 2884 | // Non-visible stacks get resized once we're done with the resize |
| 2885 | // interaction. |
| 2886 | continue; |
| 2887 | } |
Wale Ogunwale | 926aade | 2017-08-29 11:24:37 -0700 | [diff] [blame] | 2888 | // Need to set windowing mode here before we try to get the dock bounds. |
| 2889 | current.setWindowingMode(WINDOWING_MODE_SPLIT_SCREEN_SECONDARY); |
| 2890 | current.getStackDockedModeBounds( |
| 2891 | tempOtherTaskBounds /* currentTempTaskBounds */, |
| 2892 | tempRect /* outStackBounds */, |
| 2893 | otherTaskRect /* outTempTaskBounds */, true /* ignoreVisibility */); |
| 2894 | |
Wale Ogunwale | 44f036f | 2017-09-29 05:09:09 -0700 | [diff] [blame] | 2895 | resizeStackLocked(current, !tempRect.isEmpty() ? tempRect : null, |
Wale Ogunwale | 926aade | 2017-08-29 11:24:37 -0700 | [diff] [blame] | 2896 | !otherTaskRect.isEmpty() ? otherTaskRect : tempOtherTaskBounds, |
| 2897 | tempOtherTaskInsetBounds, preserveWindows, |
| 2898 | true /* allowResizeInDockedMode */, deferResume); |
Jorim Jaggi | dc249c4 | 2015-12-15 14:57:31 -0800 | [diff] [blame] | 2899 | } |
| 2900 | } |
Andrii Kulian | db3e4ec | 2016-07-12 17:11:35 -0700 | [diff] [blame] | 2901 | if (!deferResume) { |
| 2902 | stack.ensureVisibleActivitiesConfigurationLocked(r, preserveWindows); |
| 2903 | } |
Jorim Jaggi | dc249c4 | 2015-12-15 14:57:31 -0800 | [diff] [blame] | 2904 | } finally { |
Wale Ogunwale | c8da41e | 2016-04-16 13:27:23 -0700 | [diff] [blame] | 2905 | mAllowDockedStackResize = true; |
Jorim Jaggi | dc249c4 | 2015-12-15 14:57:31 -0800 | [diff] [blame] | 2906 | mWindowManager.continueSurfaceLayout(); |
| 2907 | Trace.traceEnd(TRACE_TAG_ACTIVITY_MANAGER); |
| 2908 | } |
Jorim Jaggi | dc249c4 | 2015-12-15 14:57:31 -0800 | [diff] [blame] | 2909 | } |
| 2910 | |
Robert Carr | 0d00c2e | 2016-02-29 17:45:02 -0800 | [diff] [blame] | 2911 | void resizePinnedStackLocked(Rect pinnedBounds, Rect tempPinnedTaskBounds) { |
Wale Ogunwale | 04a05ac | 2017-09-17 21:35:02 -0700 | [diff] [blame] | 2912 | // TODO(multi-display): Pinned stack display should be passed in. |
Wale Ogunwale | a0f5b5e | 2017-10-11 09:37:23 -0700 | [diff] [blame] | 2913 | final PinnedActivityStack stack = getDefaultDisplay().getPinnedStack(); |
Robert Carr | 0d00c2e | 2016-02-29 17:45:02 -0800 | [diff] [blame] | 2914 | if (stack == null) { |
| 2915 | Slog.w(TAG, "resizePinnedStackLocked: pinned stack not found"); |
| 2916 | return; |
| 2917 | } |
Winson Chung | 19953ca | 2017-04-11 11:19:23 -0700 | [diff] [blame] | 2918 | |
| 2919 | // It is possible for the bounds animation from the WM to call this but be delayed by |
| 2920 | // another AM call that is holding the AMS lock. In such a case, the pinnedBounds may be |
| 2921 | // incorrect if AMS.resizeStackWithBoundsFromWindowManager() is already called while waiting |
| 2922 | // for the AMS lock to be freed. So check and make sure these bounds are still good. |
| 2923 | final PinnedStackWindowController stackController = stack.getWindowContainerController(); |
Winson Chung | 8bca9e4 | 2017-04-16 15:59:43 -0700 | [diff] [blame] | 2924 | if (stackController.pinnedStackResizeDisallowed()) { |
Winson Chung | 19953ca | 2017-04-11 11:19:23 -0700 | [diff] [blame] | 2925 | return; |
| 2926 | } |
| 2927 | |
Robert Carr | 0d00c2e | 2016-02-29 17:45:02 -0800 | [diff] [blame] | 2928 | Trace.traceBegin(TRACE_TAG_ACTIVITY_MANAGER, "am.resizePinnedStack"); |
| 2929 | mWindowManager.deferSurfaceLayout(); |
| 2930 | try { |
| 2931 | ActivityRecord r = stack.topRunningActivityLocked(); |
Robert Carr | 7e4c90e | 2017-02-15 19:52:38 -0800 | [diff] [blame] | 2932 | Rect insetBounds = null; |
Adrian Roos | 3e80b60 | 2018-04-30 12:42:36 +0200 | [diff] [blame] | 2933 | if (tempPinnedTaskBounds != null && stack.isAnimatingBoundsToFullscreen()) { |
| 2934 | // Use 0,0 as the position for the inset rect because we are headed for fullscreen. |
Robert Carr | 7e4c90e | 2017-02-15 19:52:38 -0800 | [diff] [blame] | 2935 | insetBounds = tempRect; |
| 2936 | insetBounds.top = 0; |
| 2937 | insetBounds.left = 0; |
| 2938 | insetBounds.right = tempPinnedTaskBounds.width(); |
| 2939 | insetBounds.bottom = tempPinnedTaskBounds.height(); |
| 2940 | } |
Winson Chung | 15036ca | 2018-05-31 15:51:47 -0700 | [diff] [blame] | 2941 | if (pinnedBounds != null && tempPinnedTaskBounds == null) { |
| 2942 | // We have finished the animation into PiP, and are resizing the tasks to match the |
| 2943 | // stack bounds, while layouts are deferred, update any task state as a part of |
| 2944 | // transitioning it from fullscreen into a floating state. |
| 2945 | stack.onPipAnimationEndResize(); |
| 2946 | } |
Robert Carr | 7e4c90e | 2017-02-15 19:52:38 -0800 | [diff] [blame] | 2947 | stack.resize(pinnedBounds, tempPinnedTaskBounds, insetBounds); |
Wale Ogunwale | db0fa12 | 2016-05-16 15:12:03 -0700 | [diff] [blame] | 2948 | stack.ensureVisibleActivitiesConfigurationLocked(r, false); |
Robert Carr | 0d00c2e | 2016-02-29 17:45:02 -0800 | [diff] [blame] | 2949 | } finally { |
| 2950 | mWindowManager.continueSurfaceLayout(); |
| 2951 | Trace.traceEnd(TRACE_TAG_ACTIVITY_MANAGER); |
| 2952 | } |
| 2953 | } |
| 2954 | |
Wale Ogunwale | a0f5b5e | 2017-10-11 09:37:23 -0700 | [diff] [blame] | 2955 | private void removeStackInSurfaceTransaction(ActivityStack stack) { |
Winson Chung | 010927a | 2016-12-15 16:12:35 -0800 | [diff] [blame] | 2956 | final ArrayList<TaskRecord> tasks = stack.getAllTasks(); |
Wale Ogunwale | 04a05ac | 2017-09-17 21:35:02 -0700 | [diff] [blame] | 2957 | if (stack.getWindowingMode() == WINDOWING_MODE_PINNED) { |
Winson Chung | 4790065 | 2017-04-06 18:44:25 -0700 | [diff] [blame] | 2958 | /** |
| 2959 | * Workaround: Force-stop all the activities in the pinned stack before we reparent them |
| 2960 | * to the fullscreen stack. This is to guarantee that when we are removing a stack, |
| 2961 | * that the client receives onStop() before it is reparented. We do this by detaching |
| 2962 | * the stack from the display so that it will be considered invisible when |
| 2963 | * ensureActivitiesVisibleLocked() is called, and all of its activitys will be marked |
| 2964 | * invisible as well and added to the stopping list. After which we process the |
| 2965 | * stopping list by handling the idle. |
| 2966 | */ |
| 2967 | final PinnedActivityStack pinnedStack = (PinnedActivityStack) stack; |
| 2968 | pinnedStack.mForceHidden = true; |
| 2969 | pinnedStack.ensureActivitiesVisibleLocked(null, 0, PRESERVE_WINDOWS); |
| 2970 | pinnedStack.mForceHidden = false; |
| 2971 | activityIdleInternalLocked(null, false /* fromTimeout */, |
| 2972 | true /* processPausingActivites */, null /* configuration */); |
| 2973 | |
| 2974 | // Move all the tasks to the bottom of the fullscreen stack |
Wale Ogunwale | 9dcf946 | 2017-09-19 15:13:01 -0700 | [diff] [blame] | 2975 | moveTasksToFullscreenStackLocked(pinnedStack, !ON_TOP); |
Winson Chung | 010927a | 2016-12-15 16:12:35 -0800 | [diff] [blame] | 2976 | } else { |
| 2977 | for (int i = tasks.size() - 1; i >= 0; i--) { |
| 2978 | removeTaskByIdLocked(tasks.get(i).taskId, true /* killProcess */, |
Winson Chung | 0ec2a35 | 2017-10-26 11:38:30 -0700 | [diff] [blame] | 2979 | REMOVE_FROM_RECENTS, "remove-stack"); |
Winson Chung | 010927a | 2016-12-15 16:12:35 -0800 | [diff] [blame] | 2980 | } |
| 2981 | } |
| 2982 | } |
| 2983 | |
| 2984 | /** |
Wale Ogunwale | a0f5b5e | 2017-10-11 09:37:23 -0700 | [diff] [blame] | 2985 | * Removes the stack associated with the given {@param stack}. If the {@param stack} is the |
Robert Carr | 6914f08 | 2017-03-20 19:04:30 -0700 | [diff] [blame] | 2986 | * pinned stack, then its tasks are not explicitly removed when the stack is destroyed, but |
| 2987 | * instead moved back onto the fullscreen stack. |
| 2988 | */ |
Wale Ogunwale | a0f5b5e | 2017-10-11 09:37:23 -0700 | [diff] [blame] | 2989 | void removeStack(ActivityStack stack) { |
| 2990 | mWindowManager.inSurfaceTransaction(() -> removeStackInSurfaceTransaction(stack)); |
Wale Ogunwale | 04a05ac | 2017-09-17 21:35:02 -0700 | [diff] [blame] | 2991 | } |
| 2992 | |
Wale Ogunwale | 6827856 | 2017-09-23 17:13:55 -0700 | [diff] [blame] | 2993 | /** |
| 2994 | * Removes stacks in the input windowing modes from the system if they are of activity type |
| 2995 | * ACTIVITY_TYPE_STANDARD or ACTIVITY_TYPE_UNDEFINED |
| 2996 | */ |
| 2997 | void removeStacksInWindowingModes(int... windowingModes) { |
Wale Ogunwale | 04a05ac | 2017-09-17 21:35:02 -0700 | [diff] [blame] | 2998 | for (int i = mActivityDisplays.size() - 1; i >= 0; --i) { |
Riddle Hsu | 86cb7de | 2018-08-13 23:29:58 +0800 | [diff] [blame] | 2999 | mActivityDisplays.get(i).removeStacksInWindowingModes(windowingModes); |
Wale Ogunwale | 6827856 | 2017-09-23 17:13:55 -0700 | [diff] [blame] | 3000 | } |
| 3001 | } |
| 3002 | |
| 3003 | void removeStacksWithActivityTypes(int... activityTypes) { |
| 3004 | for (int i = mActivityDisplays.size() - 1; i >= 0; --i) { |
Riddle Hsu | 86cb7de | 2018-08-13 23:29:58 +0800 | [diff] [blame] | 3005 | mActivityDisplays.get(i).removeStacksWithActivityTypes(activityTypes); |
Wale Ogunwale | 04a05ac | 2017-09-17 21:35:02 -0700 | [diff] [blame] | 3006 | } |
Robert Carr | 6914f08 | 2017-03-20 19:04:30 -0700 | [diff] [blame] | 3007 | } |
| 3008 | |
| 3009 | /** |
Winson Chung | 6954fc9 | 2017-03-24 16:22:12 -0700 | [diff] [blame] | 3010 | * See {@link #removeTaskByIdLocked(int, boolean, boolean, boolean)} |
| 3011 | */ |
Winson Chung | 0ec2a35 | 2017-10-26 11:38:30 -0700 | [diff] [blame] | 3012 | boolean removeTaskByIdLocked(int taskId, boolean killProcess, boolean removeFromRecents, |
| 3013 | String reason) { |
| 3014 | return removeTaskByIdLocked(taskId, killProcess, removeFromRecents, !PAUSE_IMMEDIATELY, |
| 3015 | reason); |
Winson Chung | 6954fc9 | 2017-03-24 16:22:12 -0700 | [diff] [blame] | 3016 | } |
| 3017 | |
| 3018 | /** |
Winson Chung | 010927a | 2016-12-15 16:12:35 -0800 | [diff] [blame] | 3019 | * Removes the task with the specified task id. |
| 3020 | * |
| 3021 | * @param taskId Identifier of the task to be removed. |
| 3022 | * @param killProcess Kill any process associated with the task if possible. |
| 3023 | * @param removeFromRecents Whether to also remove the task from recents. |
Winson Chung | 6954fc9 | 2017-03-24 16:22:12 -0700 | [diff] [blame] | 3024 | * @param pauseImmediately Pauses all task activities immediately without waiting for the |
| 3025 | * pause-complete callback from the activity. |
Winson Chung | 010927a | 2016-12-15 16:12:35 -0800 | [diff] [blame] | 3026 | * @return Returns true if the given task was found and removed. |
| 3027 | */ |
Winson Chung | 6954fc9 | 2017-03-24 16:22:12 -0700 | [diff] [blame] | 3028 | boolean removeTaskByIdLocked(int taskId, boolean killProcess, boolean removeFromRecents, |
Winson Chung | 0ec2a35 | 2017-10-26 11:38:30 -0700 | [diff] [blame] | 3029 | boolean pauseImmediately, String reason) { |
Wale Ogunwale | 0568aed | 2017-09-08 13:29:37 -0700 | [diff] [blame] | 3030 | final TaskRecord tr = anyTaskForIdLocked(taskId, MATCH_TASK_IN_STACKS_OR_RECENT_TASKS); |
Winson Chung | 010927a | 2016-12-15 16:12:35 -0800 | [diff] [blame] | 3031 | if (tr != null) { |
Winson Chung | 0ec2a35 | 2017-10-26 11:38:30 -0700 | [diff] [blame] | 3032 | tr.removeTaskActivitiesLocked(pauseImmediately, reason); |
Winson Chung | 010927a | 2016-12-15 16:12:35 -0800 | [diff] [blame] | 3033 | cleanUpRemovedTaskLocked(tr, killProcess, removeFromRecents); |
Wale Ogunwale | c9e57de | 2018-05-08 14:28:07 -0700 | [diff] [blame] | 3034 | mService.getLockTaskController().clearLockedTask(tr); |
Winson Chung | 010927a | 2016-12-15 16:12:35 -0800 | [diff] [blame] | 3035 | if (tr.isPersistable) { |
Wale Ogunwale | c9e57de | 2018-05-08 14:28:07 -0700 | [diff] [blame] | 3036 | mService.notifyTaskPersisterLocked(null, true); |
Winson Chung | 010927a | 2016-12-15 16:12:35 -0800 | [diff] [blame] | 3037 | } |
| 3038 | return true; |
| 3039 | } |
| 3040 | Slog.w(TAG, "Request to remove task ignored for non-existent task " + taskId); |
| 3041 | return false; |
| 3042 | } |
| 3043 | |
| 3044 | void cleanUpRemovedTaskLocked(TaskRecord tr, boolean killProcess, boolean removeFromRecents) { |
| 3045 | if (removeFromRecents) { |
Winson Chung | 1dbc811 | 2017-09-28 18:05:31 -0700 | [diff] [blame] | 3046 | mRecentTasks.remove(tr); |
Winson Chung | 010927a | 2016-12-15 16:12:35 -0800 | [diff] [blame] | 3047 | } |
| 3048 | ComponentName component = tr.getBaseIntent().getComponent(); |
| 3049 | if (component == null) { |
| 3050 | Slog.w(TAG, "No component for base intent of task: " + tr); |
| 3051 | return; |
| 3052 | } |
| 3053 | |
| 3054 | // Find any running services associated with this app and stop if needed. |
Wale Ogunwale | 342fbe9 | 2018-10-09 08:44:10 -0700 | [diff] [blame] | 3055 | final Message msg = PooledLambda.obtainMessage(ActivityManagerInternal::cleanUpServices, |
| 3056 | mService.mAmInternal, tr.userId, component, new Intent(tr.getBaseIntent())); |
| 3057 | mService.mH.sendMessage(msg); |
Winson Chung | 010927a | 2016-12-15 16:12:35 -0800 | [diff] [blame] | 3058 | |
| 3059 | if (!killProcess) { |
| 3060 | return; |
| 3061 | } |
| 3062 | |
| 3063 | // Determine if the process(es) for this task should be killed. |
| 3064 | final String pkg = component.getPackageName(); |
Wale Ogunwale | 9e4f3e0 | 2018-05-17 09:35:39 -0700 | [diff] [blame] | 3065 | ArrayList<Object> procsToKill = new ArrayList<>(); |
| 3066 | ArrayMap<String, SparseArray<WindowProcessController>> pmap = |
| 3067 | mService.mProcessNames.getMap(); |
Winson Chung | 010927a | 2016-12-15 16:12:35 -0800 | [diff] [blame] | 3068 | for (int i = 0; i < pmap.size(); i++) { |
| 3069 | |
Wale Ogunwale | 9e4f3e0 | 2018-05-17 09:35:39 -0700 | [diff] [blame] | 3070 | SparseArray<WindowProcessController> uids = pmap.valueAt(i); |
Winson Chung | 010927a | 2016-12-15 16:12:35 -0800 | [diff] [blame] | 3071 | for (int j = 0; j < uids.size(); j++) { |
Wale Ogunwale | 9e4f3e0 | 2018-05-17 09:35:39 -0700 | [diff] [blame] | 3072 | WindowProcessController proc = uids.valueAt(j); |
| 3073 | if (proc.mUserId != tr.userId) { |
Winson Chung | 010927a | 2016-12-15 16:12:35 -0800 | [diff] [blame] | 3074 | // Don't kill process for a different user. |
| 3075 | continue; |
| 3076 | } |
Wale Ogunwale | 9e4f3e0 | 2018-05-17 09:35:39 -0700 | [diff] [blame] | 3077 | if (proc == mService.mHomeProcess) { |
Winson Chung | 010927a | 2016-12-15 16:12:35 -0800 | [diff] [blame] | 3078 | // Don't kill the home process along with tasks from the same package. |
| 3079 | continue; |
| 3080 | } |
Wale Ogunwale | 9e4f3e0 | 2018-05-17 09:35:39 -0700 | [diff] [blame] | 3081 | if (!proc.mPkgList.contains(pkg)) { |
Winson Chung | 010927a | 2016-12-15 16:12:35 -0800 | [diff] [blame] | 3082 | // Don't kill process that is not associated with this task. |
| 3083 | continue; |
| 3084 | } |
| 3085 | |
Wale Ogunwale | 9e4f3e0 | 2018-05-17 09:35:39 -0700 | [diff] [blame] | 3086 | if (!proc.shouldKillProcessForRemovedTask(tr)) { |
| 3087 | // Don't kill process(es) that has an activity in a different task that is also |
Yunfan Chen | afc1583 | 2018-07-26 16:34:28 +0900 | [diff] [blame] | 3088 | // in recents, or has an activity not stopped. |
Wale Ogunwale | 9e4f3e0 | 2018-05-17 09:35:39 -0700 | [diff] [blame] | 3089 | return; |
Winson Chung | 010927a | 2016-12-15 16:12:35 -0800 | [diff] [blame] | 3090 | } |
| 3091 | |
Wale Ogunwale | 9e4f3e0 | 2018-05-17 09:35:39 -0700 | [diff] [blame] | 3092 | if (proc.hasForegroundServices()) { |
Winson Chung | 010927a | 2016-12-15 16:12:35 -0800 | [diff] [blame] | 3093 | // Don't kill process(es) with foreground service. |
| 3094 | return; |
| 3095 | } |
| 3096 | |
| 3097 | // Add process to kill list. |
| 3098 | procsToKill.add(proc); |
| 3099 | } |
| 3100 | } |
| 3101 | |
Wale Ogunwale | 9e4f3e0 | 2018-05-17 09:35:39 -0700 | [diff] [blame] | 3102 | // Kill the running processes. Post on handle since we don't want to hold the service lock |
| 3103 | // while calling into AM. |
Yohei Yukawa | e2fa39e | 2018-09-22 13:13:10 -0700 | [diff] [blame] | 3104 | final Message m = PooledLambda.obtainMessage( |
Wale Ogunwale | 9e4f3e0 | 2018-05-17 09:35:39 -0700 | [diff] [blame] | 3105 | ActivityManagerInternal::killProcessesForRemovedTask, mService.mAmInternal, |
| 3106 | procsToKill); |
Yohei Yukawa | e2fa39e | 2018-09-22 13:13:10 -0700 | [diff] [blame] | 3107 | mService.mH.sendMessage(m); |
Winson Chung | 010927a | 2016-12-15 16:12:35 -0800 | [diff] [blame] | 3108 | } |
| 3109 | |
Chong Zhang | 5dcb275 | 2015-08-18 13:50:26 -0700 | [diff] [blame] | 3110 | /** |
Winson Chung | 1dbc811 | 2017-09-28 18:05:31 -0700 | [diff] [blame] | 3111 | * Called to restore the state of the task into the stack that it's supposed to go into. |
| 3112 | * |
Chong Zhang | 5dcb275 | 2015-08-18 13:50:26 -0700 | [diff] [blame] | 3113 | * @param task The recent task to be restored. |
Wale Ogunwale | 0568aed | 2017-09-08 13:29:37 -0700 | [diff] [blame] | 3114 | * @param aOptions The activity options to use for restoration. |
Wale Ogunwale | ab5de37 | 2017-10-18 06:46:31 -0700 | [diff] [blame] | 3115 | * @param onTop If the stack for the task should be the topmost on the display. |
Chong Zhang | 5dcb275 | 2015-08-18 13:50:26 -0700 | [diff] [blame] | 3116 | * @return true if the task has been restored successfully. |
| 3117 | */ |
Wale Ogunwale | ab5de37 | 2017-10-18 06:46:31 -0700 | [diff] [blame] | 3118 | boolean restoreRecentTaskLocked(TaskRecord task, ActivityOptions aOptions, boolean onTop) { |
| 3119 | final ActivityStack stack = getLaunchStack(null, aOptions, task, onTop); |
Andrii Kulian | 02b7a83 | 2016-10-06 23:11:56 -0700 | [diff] [blame] | 3120 | final ActivityStack currentStack = task.getStack(); |
| 3121 | if (currentStack != null) { |
Wale Ogunwale | 706ed79 | 2015-08-02 10:29:44 -0700 | [diff] [blame] | 3122 | // Task has already been restored once. See if we need to do anything more |
Wale Ogunwale | 04a05ac | 2017-09-17 21:35:02 -0700 | [diff] [blame] | 3123 | if (currentStack == stack) { |
Wale Ogunwale | 706ed79 | 2015-08-02 10:29:44 -0700 | [diff] [blame] | 3124 | // Nothing else to do since it is already restored in the right stack. |
| 3125 | return true; |
| 3126 | } |
| 3127 | // Remove current stack association, so we can re-associate the task with the |
| 3128 | // right stack below. |
Andrii Kulian | 02b7a83 | 2016-10-06 23:11:56 -0700 | [diff] [blame] | 3129 | currentStack.removeTask(task, "restoreRecentTaskLocked", REMOVE_TASK_MODE_MOVING); |
Wale Ogunwale | 706ed79 | 2015-08-02 10:29:44 -0700 | [diff] [blame] | 3130 | } |
| 3131 | |
Wale Ogunwale | ab5de37 | 2017-10-18 06:46:31 -0700 | [diff] [blame] | 3132 | stack.addTask(task, onTop, "restoreRecentTask"); |
Wale Ogunwale | e1fe7fa2 | 2016-12-15 18:27:00 -0800 | [diff] [blame] | 3133 | // TODO: move call for creation here and other place into Stack.addTask() |
Wale Ogunwale | ab5de37 | 2017-10-18 06:46:31 -0700 | [diff] [blame] | 3134 | task.createWindowContainer(onTop, true /* showForAllUsers */); |
Wale Ogunwale | ee006da | 2015-03-30 14:49:25 -0700 | [diff] [blame] | 3135 | if (DEBUG_RECENTS) Slog.v(TAG_RECENTS, |
| 3136 | "Added restored task=" + task + " to stack=" + stack); |
Wale Ogunwale | 7de0535 | 2014-12-12 15:21:33 -0800 | [diff] [blame] | 3137 | final ArrayList<ActivityRecord> activities = task.mActivities; |
| 3138 | for (int activityNdx = activities.size() - 1; activityNdx >= 0; --activityNdx) { |
Wale Ogunwale | 26c0dfe | 2016-12-14 14:42:30 -0800 | [diff] [blame] | 3139 | activities.get(activityNdx).createWindowContainer(); |
Wale Ogunwale | 7de0535 | 2014-12-12 15:21:33 -0800 | [diff] [blame] | 3140 | } |
| 3141 | return true; |
Craig Mautner | ef73ee1 | 2014-04-23 11:45:37 -0700 | [diff] [blame] | 3142 | } |
| 3143 | |
Winson Chung | 1dbc811 | 2017-09-28 18:05:31 -0700 | [diff] [blame] | 3144 | @Override |
| 3145 | public void onRecentTaskAdded(TaskRecord task) { |
| 3146 | task.touchActiveTime(); |
| 3147 | } |
| 3148 | |
| 3149 | @Override |
Winson Chung | e643910 | 2018-07-30 15:48:01 -0700 | [diff] [blame] | 3150 | public void onRecentTaskRemoved(TaskRecord task, boolean wasTrimmed, boolean killProcess) { |
Winson Chung | 0ec2a35 | 2017-10-26 11:38:30 -0700 | [diff] [blame] | 3151 | if (wasTrimmed) { |
| 3152 | // Task was trimmed from the recent tasks list -- remove the active task record as well |
| 3153 | // since the user won't really be able to go back to it |
Winson Chung | e643910 | 2018-07-30 15:48:01 -0700 | [diff] [blame] | 3154 | removeTaskByIdLocked(task.taskId, killProcess, false /* removeFromRecents */, |
| 3155 | !PAUSE_IMMEDIATELY, "recent-task-trimmed"); |
Winson Chung | 0ec2a35 | 2017-10-26 11:38:30 -0700 | [diff] [blame] | 3156 | } |
Winson Chung | 1dbc811 | 2017-09-28 18:05:31 -0700 | [diff] [blame] | 3157 | task.removedFromRecents(); |
| 3158 | } |
| 3159 | |
Wale Ogunwale | 040b470 | 2015-08-06 18:10:50 -0700 | [diff] [blame] | 3160 | /** |
Andrii Kulian | 839def9 | 2016-11-02 10:58:58 -0700 | [diff] [blame] | 3161 | * Move stack with all its existing content to specified display. |
| 3162 | * @param stackId Id of stack to move. |
| 3163 | * @param displayId Id of display to move stack to. |
Andrii Kulian | 250d653 | 2017-02-08 23:30:45 -0800 | [diff] [blame] | 3164 | * @param onTop Indicates whether container should be place on top or on bottom. |
Andrii Kulian | 839def9 | 2016-11-02 10:58:58 -0700 | [diff] [blame] | 3165 | */ |
Andrii Kulian | 250d653 | 2017-02-08 23:30:45 -0800 | [diff] [blame] | 3166 | void moveStackToDisplayLocked(int stackId, int displayId, boolean onTop) { |
Andrii Kulian | 62e6f25 | 2017-05-30 22:46:53 -0700 | [diff] [blame] | 3167 | final ActivityDisplay activityDisplay = getActivityDisplayOrCreateLocked(displayId); |
Andrii Kulian | 839def9 | 2016-11-02 10:58:58 -0700 | [diff] [blame] | 3168 | if (activityDisplay == null) { |
| 3169 | throw new IllegalArgumentException("moveStackToDisplayLocked: Unknown displayId=" |
| 3170 | + displayId); |
| 3171 | } |
Wale Ogunwale | 9dcf946 | 2017-09-19 15:13:01 -0700 | [diff] [blame] | 3172 | final ActivityStack stack = getStack(stackId); |
Andrii Kulian | 94e82d9b0 | 2017-07-13 15:33:06 -0700 | [diff] [blame] | 3173 | if (stack == null) { |
Andrii Kulian | 839def9 | 2016-11-02 10:58:58 -0700 | [diff] [blame] | 3174 | throw new IllegalArgumentException("moveStackToDisplayLocked: Unknown stackId=" |
| 3175 | + stackId); |
| 3176 | } |
Andrii Kulian | 94e82d9b0 | 2017-07-13 15:33:06 -0700 | [diff] [blame] | 3177 | |
| 3178 | final ActivityDisplay currentDisplay = stack.getDisplay(); |
| 3179 | if (currentDisplay == null) { |
| 3180 | throw new IllegalStateException("moveStackToDisplayLocked: Stack with stack=" + stack |
| 3181 | + " is not attached to any display."); |
| 3182 | } |
| 3183 | |
| 3184 | if (currentDisplay.mDisplayId == displayId) { |
| 3185 | throw new IllegalArgumentException("Trying to move stack=" + stack |
| 3186 | + " to its current displayId=" + displayId); |
| 3187 | } |
| 3188 | |
Riddle Hsu | 402b440 | 2018-11-06 17:23:15 +0800 | [diff] [blame] | 3189 | stack.reparent(activityDisplay, onTop, false /* displayRemoved */); |
Andrii Kulian | 839def9 | 2016-11-02 10:58:58 -0700 | [diff] [blame] | 3190 | // TODO(multi-display): resize stacks properly if moved from split-screen. |
| 3191 | } |
| 3192 | |
| 3193 | /** |
Winson Chung | 7466610 | 2017-02-22 17:49:24 -0800 | [diff] [blame] | 3194 | * Returns the reparent target stack, creating the stack if necessary. This call also enforces |
| 3195 | * the various checks on tasks that are going to be reparented from one stack to another. |
Wale Ogunwale | 040b470 | 2015-08-06 18:10:50 -0700 | [diff] [blame] | 3196 | */ |
Wale Ogunwale | 30e441d | 2017-11-09 08:28:45 -0800 | [diff] [blame] | 3197 | // TODO: Look into changing users to this method to ActivityDisplay.resolveWindowingMode() |
Wale Ogunwale | 04a05ac | 2017-09-17 21:35:02 -0700 | [diff] [blame] | 3198 | ActivityStack getReparentTargetStack(TaskRecord task, ActivityStack stack, boolean toTop) { |
Andrii Kulian | 02b7a83 | 2016-10-06 23:11:56 -0700 | [diff] [blame] | 3199 | final ActivityStack prevStack = task.getStack(); |
Wale Ogunwale | 04a05ac | 2017-09-17 21:35:02 -0700 | [diff] [blame] | 3200 | final int stackId = stack.mStackId; |
| 3201 | final boolean inMultiWindowMode = stack.inMultiWindowMode(); |
Chong Zhang | 0289835 | 2015-08-21 17:27:14 -0700 | [diff] [blame] | 3202 | |
Winson Chung | 7466610 | 2017-02-22 17:49:24 -0800 | [diff] [blame] | 3203 | // Check that we aren't reparenting to the same stack that the task is already in |
| 3204 | if (prevStack != null && prevStack.mStackId == stackId) { |
| 3205 | Slog.w(TAG, "Can not reparent to same stack, task=" + task |
| 3206 | + " already in stackId=" + stackId); |
| 3207 | return prevStack; |
Wale Ogunwale | 513346d | 2016-01-27 10:55:01 -0800 | [diff] [blame] | 3208 | } |
| 3209 | |
Winson Chung | 7466610 | 2017-02-22 17:49:24 -0800 | [diff] [blame] | 3210 | // Ensure that we aren't trying to move into a multi-window stack without multi-window |
| 3211 | // support |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 3212 | if (inMultiWindowMode && !mService.mSupportsMultiWindow) { |
Winson Chung | 7466610 | 2017-02-22 17:49:24 -0800 | [diff] [blame] | 3213 | throw new IllegalArgumentException("Device doesn't support multi-window, can not" |
Wale Ogunwale | 04a05ac | 2017-09-17 21:35:02 -0700 | [diff] [blame] | 3214 | + " reparent task=" + task + " to stack=" + stack); |
Winson Chung | c2baac0 | 2017-01-11 13:34:47 -0800 | [diff] [blame] | 3215 | } |
| 3216 | |
Andrii Kulian | eafd9db | 2017-04-05 22:01:35 -0700 | [diff] [blame] | 3217 | // Ensure that we're not moving a task to a dynamic stack if device doesn't support |
| 3218 | // multi-display. |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 3219 | if (stack.mDisplayId != DEFAULT_DISPLAY && !mService.mSupportsMultiDisplay) { |
Andrii Kulian | eafd9db | 2017-04-05 22:01:35 -0700 | [diff] [blame] | 3220 | throw new IllegalArgumentException("Device doesn't support multi-display, can not" |
| 3221 | + " reparent task=" + task + " to stackId=" + stackId); |
| 3222 | } |
| 3223 | |
Wale Ogunwale | 30e441d | 2017-11-09 08:28:45 -0800 | [diff] [blame] | 3224 | // Ensure that we aren't trying to move into a freeform stack without freeform support |
Wale Ogunwale | 04a05ac | 2017-09-17 21:35:02 -0700 | [diff] [blame] | 3225 | if (stack.getWindowingMode() == WINDOWING_MODE_FREEFORM |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 3226 | && !mService.mSupportsFreeformWindowManagement) { |
Winson Chung | 7466610 | 2017-02-22 17:49:24 -0800 | [diff] [blame] | 3227 | throw new IllegalArgumentException("Device doesn't support freeform, can not reparent" |
| 3228 | + " task=" + task); |
Wale Ogunwale | 08559dc | 2016-02-23 12:20:08 -0800 | [diff] [blame] | 3229 | } |
| 3230 | |
Wale Ogunwale | 7e1f5f5 | 2017-10-18 15:19:59 -0700 | [diff] [blame] | 3231 | // Leave the task in its current stack or a fullscreen stack if it isn't resizeable and the |
| 3232 | // preferred stack is in multi-window mode. |
Wale Ogunwale | 04a05ac | 2017-09-17 21:35:02 -0700 | [diff] [blame] | 3233 | if (inMultiWindowMode && !task.isResizeable()) { |
Wale Ogunwale | 7e1f5f5 | 2017-10-18 15:19:59 -0700 | [diff] [blame] | 3234 | Slog.w(TAG, "Can not move unresizeable task=" + task + " to multi-window stack=" + stack |
| 3235 | + " Moving to a fullscreen stack instead."); |
| 3236 | if (prevStack != null) { |
| 3237 | return prevStack; |
Wale Ogunwale | 04a05ac | 2017-09-17 21:35:02 -0700 | [diff] [blame] | 3238 | } |
Wale Ogunwale | 7e1f5f5 | 2017-10-18 15:19:59 -0700 | [diff] [blame] | 3239 | stack = stack.getDisplay().createStack( |
| 3240 | WINDOWING_MODE_FULLSCREEN, stack.getActivityType(), toTop); |
Filip Gruszczynski | 49b80af | 2015-09-24 09:04:26 -0700 | [diff] [blame] | 3241 | } |
Wale Ogunwale | 04a05ac | 2017-09-17 21:35:02 -0700 | [diff] [blame] | 3242 | return stack; |
Craig Mautner | 8d341ef | 2013-03-26 09:03:27 -0700 | [diff] [blame] | 3243 | } |
| 3244 | |
Winson Chung | 08f8189 | 2017-03-02 15:40:51 -0800 | [diff] [blame] | 3245 | boolean moveTopStackActivityToPinnedStackLocked(int stackId, Rect destBounds) { |
Wale Ogunwale | 04a05ac | 2017-09-17 21:35:02 -0700 | [diff] [blame] | 3246 | final ActivityStack stack = getStack(stackId); |
Wale Ogunwale | 079a004 | 2015-10-24 11:44:07 -0700 | [diff] [blame] | 3247 | if (stack == null) { |
| 3248 | throw new IllegalArgumentException( |
| 3249 | "moveTopStackActivityToPinnedStackLocked: Unknown stackId=" + stackId); |
| 3250 | } |
| 3251 | |
| 3252 | final ActivityRecord r = stack.topRunningActivityLocked(); |
| 3253 | if (r == null) { |
| 3254 | Slog.w(TAG, "moveTopStackActivityToPinnedStackLocked: No top running activity" |
| 3255 | + " in stack=" + stack); |
| 3256 | return false; |
| 3257 | } |
| 3258 | |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 3259 | if (!mService.mForceResizableActivities && !r.supportsPictureInPicture()) { |
Wale Ogunwale | b60692e | 2015-10-24 12:35:56 -0700 | [diff] [blame] | 3260 | Slog.w(TAG, |
| 3261 | "moveTopStackActivityToPinnedStackLocked: Picture-In-Picture not supported for " |
Filip Gruszczynski | 77d9448 | 2015-12-11 13:59:52 -0800 | [diff] [blame] | 3262 | + " r=" + r); |
Wale Ogunwale | 079a004 | 2015-10-24 11:44:07 -0700 | [diff] [blame] | 3263 | return false; |
| 3264 | } |
| 3265 | |
Winson Chung | 3a68287 | 2017-04-10 14:38:05 -0700 | [diff] [blame] | 3266 | moveActivityToPinnedStackLocked(r, null /* sourceBounds */, 0f /* aspectRatio */, |
Wale Ogunwale | 66e1685 | 2017-10-19 13:35:52 -0700 | [diff] [blame] | 3267 | "moveTopActivityToPinnedStack"); |
Wale Ogunwale | 9c604c7 | 2015-12-06 18:42:57 -0800 | [diff] [blame] | 3268 | return true; |
| 3269 | } |
| 3270 | |
Winson Chung | 8bca9e4 | 2017-04-16 15:59:43 -0700 | [diff] [blame] | 3271 | void moveActivityToPinnedStackLocked(ActivityRecord r, Rect sourceHintBounds, float aspectRatio, |
Wale Ogunwale | 66e1685 | 2017-10-19 13:35:52 -0700 | [diff] [blame] | 3272 | String reason) { |
Winson Chung | 08f8189 | 2017-03-02 15:40:51 -0800 | [diff] [blame] | 3273 | |
Wale Ogunwale | 480dca0 | 2016-02-06 13:58:29 -0800 | [diff] [blame] | 3274 | mWindowManager.deferSurfaceLayout(); |
Winson Chung | 7466610 | 2017-02-22 17:49:24 -0800 | [diff] [blame] | 3275 | |
Wale Ogunwale | 04a05ac | 2017-09-17 21:35:02 -0700 | [diff] [blame] | 3276 | final ActivityDisplay display = r.getStack().getDisplay(); |
| 3277 | PinnedActivityStack stack = display.getPinnedStack(); |
Wale Ogunwale | 9dcf946 | 2017-09-19 15:13:01 -0700 | [diff] [blame] | 3278 | |
Bryce Lee | 04ab346 | 2017-04-10 15:06:33 -0700 | [diff] [blame] | 3279 | // This will clear the pinned stack by moving an existing task to the full screen stack, |
| 3280 | // ensuring only one task is present. |
Wale Ogunwale | 9dcf946 | 2017-09-19 15:13:01 -0700 | [diff] [blame] | 3281 | if (stack != null) { |
| 3282 | moveTasksToFullscreenStackLocked(stack, !ON_TOP); |
| 3283 | } |
Bryce Lee | 04ab346 | 2017-04-10 15:06:33 -0700 | [diff] [blame] | 3284 | |
Wale Ogunwale | 1666e31 | 2016-12-16 11:27:18 -0800 | [diff] [blame] | 3285 | // Need to make sure the pinned stack exist so we can resize it below... |
Wale Ogunwale | 04a05ac | 2017-09-17 21:35:02 -0700 | [diff] [blame] | 3286 | stack = display.getOrCreateStack(WINDOWING_MODE_PINNED, r.getActivityType(), ON_TOP); |
Wale Ogunwale | 1666e31 | 2016-12-16 11:27:18 -0800 | [diff] [blame] | 3287 | |
Winson Chung | e55c019 | 2017-08-24 14:50:48 -0700 | [diff] [blame] | 3288 | // Calculate the target bounds here before the task is reparented back into pinned windowing |
| 3289 | // mode (which will reset the saved bounds) |
| 3290 | final Rect destBounds = stack.getDefaultPictureInPictureBounds(aspectRatio); |
| 3291 | |
Wale Ogunwale | 480dca0 | 2016-02-06 13:58:29 -0800 | [diff] [blame] | 3292 | try { |
Bryce Lee | af691c0 | 2017-03-20 14:20:22 -0700 | [diff] [blame] | 3293 | final TaskRecord task = r.getTask(); |
Wale Ogunwale | 480dca0 | 2016-02-06 13:58:29 -0800 | [diff] [blame] | 3294 | // Resize the pinned stack to match the current size of the task the activity we are |
| 3295 | // going to be moving is currently contained in. We do this to have the right starting |
| 3296 | // animation bounds for the pinned stack to the desired bounds the caller wants. |
Bryce Lee | f3c6a47 | 2017-11-14 14:53:06 -0800 | [diff] [blame] | 3297 | resizeStackLocked(stack, task.getOverrideBounds(), null /* tempTaskBounds */, |
Wale Ogunwale | 480dca0 | 2016-02-06 13:58:29 -0800 | [diff] [blame] | 3298 | null /* tempTaskInsetBounds */, !PRESERVE_WINDOWS, |
Wale Ogunwale | c8da41e | 2016-04-16 13:27:23 -0700 | [diff] [blame] | 3299 | true /* allowResizeInDockedMode */, !DEFER_RESUME); |
Wale Ogunwale | 480dca0 | 2016-02-06 13:58:29 -0800 | [diff] [blame] | 3300 | |
| 3301 | if (task.mActivities.size() == 1) { |
Winson Chung | 5af42fc | 2017-03-24 17:11:33 -0700 | [diff] [blame] | 3302 | // Defer resume until below, and do not schedule PiP changes until we animate below |
Wale Ogunwale | 04a05ac | 2017-09-17 21:35:02 -0700 | [diff] [blame] | 3303 | task.reparent(stack, ON_TOP, REPARENT_MOVE_STACK_TO_FRONT, !ANIMATE, DEFER_RESUME, |
| 3304 | false /* schedulePictureInPictureModeChange */, reason); |
Wale Ogunwale | 480dca0 | 2016-02-06 13:58:29 -0800 | [diff] [blame] | 3305 | } else { |
Winson Chung | b5c41b7 | 2016-12-07 15:00:47 -0800 | [diff] [blame] | 3306 | // There are multiple activities in the task and moving the top activity should |
Winson Chung | 7466610 | 2017-02-22 17:49:24 -0800 | [diff] [blame] | 3307 | // reveal/leave the other activities in their original task. |
| 3308 | |
| 3309 | // Currently, we don't support reparenting activities across tasks in two different |
| 3310 | // stacks, so instead, just create a new task in the same stack, reparent the |
| 3311 | // activity into that task, and then reparent the whole task to the new stack. This |
| 3312 | // ensures that all the necessary work to migrate states in the old and new stacks |
| 3313 | // is also done. |
| 3314 | final TaskRecord newTask = task.getStack().createTaskRecord( |
Wale Ogunwale | 6fbde9f | 2017-08-24 07:24:12 -0700 | [diff] [blame] | 3315 | getNextTaskIdForUserLocked(r.userId), r.info, r.intent, null, null, true); |
Winson Chung | 7466610 | 2017-02-22 17:49:24 -0800 | [diff] [blame] | 3316 | r.reparent(newTask, MAX_VALUE, "moveActivityToStack"); |
| 3317 | |
Winson Chung | 5af42fc | 2017-03-24 17:11:33 -0700 | [diff] [blame] | 3318 | // Defer resume until below, and do not schedule PiP changes until we animate below |
Wale Ogunwale | 04a05ac | 2017-09-17 21:35:02 -0700 | [diff] [blame] | 3319 | newTask.reparent(stack, ON_TOP, REPARENT_MOVE_STACK_TO_FRONT, !ANIMATE, |
Winson Chung | 5af42fc | 2017-03-24 17:11:33 -0700 | [diff] [blame] | 3320 | DEFER_RESUME, false /* schedulePictureInPictureModeChange */, reason); |
Wale Ogunwale | 480dca0 | 2016-02-06 13:58:29 -0800 | [diff] [blame] | 3321 | } |
Winson Chung | c2baac0 | 2017-01-11 13:34:47 -0800 | [diff] [blame] | 3322 | |
| 3323 | // Reset the state that indicates it can enter PiP while pausing after we've moved it |
| 3324 | // to the pinned stack |
Winson Chung | f7e03e1 | 2017-08-22 11:32:16 -0700 | [diff] [blame] | 3325 | r.supportsEnterPipOnTaskSwitch = false; |
Wale Ogunwale | 480dca0 | 2016-02-06 13:58:29 -0800 | [diff] [blame] | 3326 | } finally { |
| 3327 | mWindowManager.continueSurfaceLayout(); |
Wale Ogunwale | 079a004 | 2015-10-24 11:44:07 -0700 | [diff] [blame] | 3328 | } |
| 3329 | |
Winson Chung | e7ba686 | 2017-05-24 12:13:33 -0700 | [diff] [blame] | 3330 | stack.animateResizePinnedStack(sourceHintBounds, destBounds, -1 /* animationDuration */, |
| 3331 | true /* fromFullscreen */); |
| 3332 | |
| 3333 | // Update the visibility of all activities after the they have been reparented to the new |
| 3334 | // stack. This MUST run after the animation above is scheduled to ensure that the windows |
| 3335 | // drawn signal is scheduled after the bounds animation start call on the bounds animator |
| 3336 | // thread. |
Wale Ogunwale | 079a004 | 2015-10-24 11:44:07 -0700 | [diff] [blame] | 3337 | ensureActivitiesVisibleLocked(null, 0, !PRESERVE_WINDOWS); |
Andrii Kulian | ab132ee | 2018-07-24 22:10:21 +0800 | [diff] [blame] | 3338 | resumeFocusedStacksTopActivitiesLocked(); |
Wale Ogunwale | 03ce863 | 2015-12-29 16:15:22 -0800 | [diff] [blame] | 3339 | |
Wale Ogunwale | c9e57de | 2018-05-08 14:28:07 -0700 | [diff] [blame] | 3340 | mService.getTaskChangeNotificationController().notifyActivityPinned(r); |
Wale Ogunwale | 079a004 | 2015-10-24 11:44:07 -0700 | [diff] [blame] | 3341 | } |
| 3342 | |
Louis Chang | c85b1a3 | 2018-08-14 16:40:53 +0800 | [diff] [blame] | 3343 | ActivityRecord findTaskLocked(ActivityRecord r, int preferredDisplayId) { |
Wale Ogunwale | ee006da | 2015-03-30 14:49:25 -0700 | [diff] [blame] | 3344 | if (DEBUG_TASKS) Slog.d(TAG_TASKS, "Looking for task of " + r); |
Louis Chang | c85b1a3 | 2018-08-14 16:40:53 +0800 | [diff] [blame] | 3345 | mTmpFindTaskResult.clear(); |
| 3346 | |
| 3347 | // Looking up task on preferred display first |
| 3348 | final ActivityDisplay preferredDisplay = getActivityDisplay(preferredDisplayId); |
| 3349 | if (preferredDisplay != null) { |
| 3350 | preferredDisplay.findTaskLocked(r, true /* isPreferredDisplay */, mTmpFindTaskResult); |
| 3351 | if (mTmpFindTaskResult.mIdealMatch) { |
| 3352 | return mTmpFindTaskResult.mRecord; |
Craig Mautner | 8849a5e | 2013-04-02 16:41:03 -0700 | [diff] [blame] | 3353 | } |
| 3354 | } |
Winson Chung | 5b895b7 | 2017-05-01 13:46:25 -0700 | [diff] [blame] | 3355 | |
Louis Chang | c85b1a3 | 2018-08-14 16:40:53 +0800 | [diff] [blame] | 3356 | for (int displayNdx = mActivityDisplays.size() - 1; displayNdx >= 0; --displayNdx) { |
| 3357 | final ActivityDisplay display = mActivityDisplays.get(displayNdx); |
| 3358 | if (display.mDisplayId == preferredDisplayId) { |
| 3359 | continue; |
| 3360 | } |
| 3361 | |
| 3362 | display.findTaskLocked(r, false /* isPreferredDisplay */, mTmpFindTaskResult); |
| 3363 | if (mTmpFindTaskResult.mIdealMatch) { |
| 3364 | return mTmpFindTaskResult.mRecord; |
| 3365 | } |
| 3366 | } |
| 3367 | |
| 3368 | if (DEBUG_TASKS && mTmpFindTaskResult.mRecord == null) Slog.d(TAG_TASKS, "No task found"); |
| 3369 | return mTmpFindTaskResult.mRecord; |
Craig Mautner | 8849a5e | 2013-04-02 16:41:03 -0700 | [diff] [blame] | 3370 | } |
| 3371 | |
Andrii Kulian | d3bbb13 | 2016-06-16 16:00:20 -0700 | [diff] [blame] | 3372 | ActivityRecord findActivityLocked(Intent intent, ActivityInfo info, |
Wale Ogunwale | a0f5b5e | 2017-10-11 09:37:23 -0700 | [diff] [blame] | 3373 | boolean compareIntentFilters) { |
Craig Mautner | e0a3884 | 2013-12-16 16:14:02 -0800 | [diff] [blame] | 3374 | for (int displayNdx = mActivityDisplays.size() - 1; displayNdx >= 0; --displayNdx) { |
Riddle Hsu | 86cb7de | 2018-08-13 23:29:58 +0800 | [diff] [blame] | 3375 | final ActivityDisplay display = mActivityDisplays.get(displayNdx); |
Wale Ogunwale | a0f5b5e | 2017-10-11 09:37:23 -0700 | [diff] [blame] | 3376 | for (int stackNdx = display.getChildCount() - 1; stackNdx >= 0; --stackNdx) { |
| 3377 | final ActivityStack stack = display.getChildAt(stackNdx); |
| 3378 | final ActivityRecord ar = stack.findActivityLocked( |
| 3379 | intent, info, compareIntentFilters); |
Craig Mautner | 4a1cb22 | 2013-12-04 16:14:06 -0800 | [diff] [blame] | 3380 | if (ar != null) { |
| 3381 | return ar; |
| 3382 | } |
Craig Mautner | 8849a5e | 2013-04-02 16:41:03 -0700 | [diff] [blame] | 3383 | } |
| 3384 | } |
| 3385 | return null; |
| 3386 | } |
| 3387 | |
David Stevens | 9440dc8 | 2017-03-16 19:00:20 -0700 | [diff] [blame] | 3388 | boolean hasAwakeDisplay() { |
| 3389 | for (int displayNdx = mActivityDisplays.size() - 1; displayNdx >= 0; --displayNdx) { |
Riddle Hsu | 86cb7de | 2018-08-13 23:29:58 +0800 | [diff] [blame] | 3390 | final ActivityDisplay display = mActivityDisplays.get(displayNdx); |
David Stevens | 9440dc8 | 2017-03-16 19:00:20 -0700 | [diff] [blame] | 3391 | if (!display.shouldSleep()) { |
| 3392 | return true; |
| 3393 | } |
| 3394 | } |
| 3395 | return false; |
| 3396 | } |
| 3397 | |
Craig Mautner | 8d341ef | 2013-03-26 09:03:27 -0700 | [diff] [blame] | 3398 | void goingToSleepLocked() { |
Craig Mautner | 0eea92c | 2013-05-16 13:35:39 -0700 | [diff] [blame] | 3399 | scheduleSleepTimeout(); |
| 3400 | if (!mGoingToSleep.isHeld()) { |
| 3401 | mGoingToSleep.acquire(); |
Craig Mautner | 7ea5bd4 | 2013-07-05 15:27:08 -0700 | [diff] [blame] | 3402 | if (mLaunchingActivity.isHeld()) { |
| 3403 | if (VALIDATE_WAKE_LOCK_CALLER && Binder.getCallingUid() != Process.myUid()) { |
| 3404 | throw new IllegalStateException("Calling must be system uid"); |
Craig Mautner | 0eea92c | 2013-05-16 13:35:39 -0700 | [diff] [blame] | 3405 | } |
Craig Mautner | 7ea5bd4 | 2013-07-05 15:27:08 -0700 | [diff] [blame] | 3406 | mLaunchingActivity.release(); |
Wale Ogunwale | 342fbe9 | 2018-10-09 08:44:10 -0700 | [diff] [blame] | 3407 | mHandler.removeMessages(LAUNCH_TIMEOUT_MSG); |
Craig Mautner | 0eea92c | 2013-05-16 13:35:39 -0700 | [diff] [blame] | 3408 | } |
Craig Mautner | 8d341ef | 2013-03-26 09:03:27 -0700 | [diff] [blame] | 3409 | } |
David Stevens | 9440dc8 | 2017-03-16 19:00:20 -0700 | [diff] [blame] | 3410 | |
| 3411 | applySleepTokensLocked(false /* applyToStacks */); |
| 3412 | |
| 3413 | checkReadyForSleepLocked(true /* allowDelay */); |
| 3414 | } |
| 3415 | |
| 3416 | void prepareForShutdownLocked() { |
| 3417 | for (int i = 0; i < mActivityDisplays.size(); i++) { |
Riddle Hsu | 86cb7de | 2018-08-13 23:29:58 +0800 | [diff] [blame] | 3418 | createSleepTokenLocked("shutdown", mActivityDisplays.get(i).mDisplayId); |
David Stevens | 9440dc8 | 2017-03-16 19:00:20 -0700 | [diff] [blame] | 3419 | } |
Craig Mautner | 8d341ef | 2013-03-26 09:03:27 -0700 | [diff] [blame] | 3420 | } |
| 3421 | |
| 3422 | boolean shutdownLocked(int timeout) { |
Craig Mautner | 0eea92c | 2013-05-16 13:35:39 -0700 | [diff] [blame] | 3423 | goingToSleepLocked(); |
Craig Mautner | 0eea92c | 2013-05-16 13:35:39 -0700 | [diff] [blame] | 3424 | |
Craig Mautner | f4c909b | 2014-04-17 18:39:38 -0700 | [diff] [blame] | 3425 | boolean timedout = false; |
Craig Mautner | 0eea92c | 2013-05-16 13:35:39 -0700 | [diff] [blame] | 3426 | final long endTime = System.currentTimeMillis() + timeout; |
| 3427 | while (true) { |
David Stevens | 18abd0e | 2017-08-17 14:55:47 -0700 | [diff] [blame] | 3428 | if (!putStacksToSleepLocked(true /* allowDelay */, true /* shuttingDown */)) { |
Craig Mautner | 0eea92c | 2013-05-16 13:35:39 -0700 | [diff] [blame] | 3429 | long timeRemaining = endTime - System.currentTimeMillis(); |
| 3430 | if (timeRemaining > 0) { |
Craig Mautner | 8d341ef | 2013-03-26 09:03:27 -0700 | [diff] [blame] | 3431 | try { |
Wale Ogunwale | f673393 | 2018-06-27 05:14:34 -0700 | [diff] [blame] | 3432 | mService.mGlobalLock.wait(timeRemaining); |
Craig Mautner | 8d341ef | 2013-03-26 09:03:27 -0700 | [diff] [blame] | 3433 | } catch (InterruptedException e) { |
| 3434 | } |
Craig Mautner | 0eea92c | 2013-05-16 13:35:39 -0700 | [diff] [blame] | 3435 | } else { |
| 3436 | Slog.w(TAG, "Activity manager shutdown timed out"); |
| 3437 | timedout = true; |
| 3438 | break; |
Craig Mautner | 8d341ef | 2013-03-26 09:03:27 -0700 | [diff] [blame] | 3439 | } |
Craig Mautner | 0eea92c | 2013-05-16 13:35:39 -0700 | [diff] [blame] | 3440 | } else { |
| 3441 | break; |
Craig Mautner | 8d341ef | 2013-03-26 09:03:27 -0700 | [diff] [blame] | 3442 | } |
| 3443 | } |
Craig Mautner | 0eea92c | 2013-05-16 13:35:39 -0700 | [diff] [blame] | 3444 | |
| 3445 | // Force checkReadyForSleep to complete. |
David Stevens | 9440dc8 | 2017-03-16 19:00:20 -0700 | [diff] [blame] | 3446 | checkReadyForSleepLocked(false /* allowDelay */); |
Craig Mautner | 0eea92c | 2013-05-16 13:35:39 -0700 | [diff] [blame] | 3447 | |
Craig Mautner | 8d341ef | 2013-03-26 09:03:27 -0700 | [diff] [blame] | 3448 | return timedout; |
| 3449 | } |
| 3450 | |
| 3451 | void comeOutOfSleepIfNeededLocked() { |
Craig Mautner | 0eea92c | 2013-05-16 13:35:39 -0700 | [diff] [blame] | 3452 | removeSleepTimeouts(); |
| 3453 | if (mGoingToSleep.isHeld()) { |
| 3454 | mGoingToSleep.release(); |
| 3455 | } |
David Stevens | 9440dc8 | 2017-03-16 19:00:20 -0700 | [diff] [blame] | 3456 | } |
| 3457 | |
| 3458 | void applySleepTokensLocked(boolean applyToStacks) { |
Craig Mautner | e0a3884 | 2013-12-16 16:14:02 -0800 | [diff] [blame] | 3459 | for (int displayNdx = mActivityDisplays.size() - 1; displayNdx >= 0; --displayNdx) { |
David Stevens | 9440dc8 | 2017-03-16 19:00:20 -0700 | [diff] [blame] | 3460 | // Set the sleeping state of the display. |
Riddle Hsu | 86cb7de | 2018-08-13 23:29:58 +0800 | [diff] [blame] | 3461 | final ActivityDisplay display = mActivityDisplays.get(displayNdx); |
David Stevens | 9440dc8 | 2017-03-16 19:00:20 -0700 | [diff] [blame] | 3462 | final boolean displayShouldSleep = display.shouldSleep(); |
| 3463 | if (displayShouldSleep == display.isSleeping()) { |
| 3464 | continue; |
| 3465 | } |
| 3466 | display.setIsSleeping(displayShouldSleep); |
| 3467 | |
| 3468 | if (!applyToStacks) { |
| 3469 | continue; |
| 3470 | } |
| 3471 | |
| 3472 | // Set the sleeping state of the stacks on the display. |
Wale Ogunwale | a0f5b5e | 2017-10-11 09:37:23 -0700 | [diff] [blame] | 3473 | for (int stackNdx = display.getChildCount() - 1; stackNdx >= 0; --stackNdx) { |
| 3474 | final ActivityStack stack = display.getChildAt(stackNdx); |
David Stevens | 9440dc8 | 2017-03-16 19:00:20 -0700 | [diff] [blame] | 3475 | if (displayShouldSleep) { |
| 3476 | stack.goToSleepIfPossible(false /* shuttingDown */); |
| 3477 | } else { |
| 3478 | stack.awakeFromSleepingLocked(); |
Tiger Huang | 1e5b10a | 2018-07-30 20:19:51 +0800 | [diff] [blame] | 3479 | if (stack.isFocusedStackOnDisplay() && !getKeyguardController() |
Andrii Kulian | 5f750bc | 2018-07-17 08:57:23 -0700 | [diff] [blame] | 3480 | .isKeyguardOrAodShowing(display.mDisplayId)) { |
Bryce Lee | d939cf0 | 2018-03-12 09:04:44 -0700 | [diff] [blame] | 3481 | // If the keyguard is unlocked - resume immediately. |
| 3482 | // It is possible that the display will not be awake at the time we |
| 3483 | // process the keyguard going away, which can happen before the sleep token |
| 3484 | // is released. As a result, it is important we resume the activity here. |
Andrii Kulian | ab132ee | 2018-07-24 22:10:21 +0800 | [diff] [blame] | 3485 | resumeFocusedStacksTopActivitiesLocked(); |
David Stevens | 9440dc8 | 2017-03-16 19:00:20 -0700 | [diff] [blame] | 3486 | } |
| 3487 | } |
| 3488 | } |
| 3489 | |
| 3490 | if (displayShouldSleep || mGoingToSleepActivities.isEmpty()) { |
| 3491 | continue; |
| 3492 | } |
| 3493 | // The display is awake now, so clean up the going to sleep list. |
| 3494 | for (Iterator<ActivityRecord> it = mGoingToSleepActivities.iterator(); it.hasNext(); ) { |
| 3495 | final ActivityRecord r = it.next(); |
| 3496 | if (r.getDisplayId() == display.mDisplayId) { |
| 3497 | it.remove(); |
Craig Mautner | 4a1cb22 | 2013-12-04 16:14:06 -0800 | [diff] [blame] | 3498 | } |
Craig Mautner | 5314a40 | 2013-09-26 12:40:16 -0700 | [diff] [blame] | 3499 | } |
Craig Mautner | 8d341ef | 2013-03-26 09:03:27 -0700 | [diff] [blame] | 3500 | } |
Craig Mautner | 0eea92c | 2013-05-16 13:35:39 -0700 | [diff] [blame] | 3501 | } |
| 3502 | |
| 3503 | void activitySleptLocked(ActivityRecord r) { |
| 3504 | mGoingToSleepActivities.remove(r); |
David Stevens | 9440dc8 | 2017-03-16 19:00:20 -0700 | [diff] [blame] | 3505 | final ActivityStack s = r.getStack(); |
| 3506 | if (s != null) { |
| 3507 | s.checkReadyForSleep(); |
| 3508 | } else { |
| 3509 | checkReadyForSleepLocked(true); |
| 3510 | } |
Craig Mautner | 0eea92c | 2013-05-16 13:35:39 -0700 | [diff] [blame] | 3511 | } |
| 3512 | |
David Stevens | 9440dc8 | 2017-03-16 19:00:20 -0700 | [diff] [blame] | 3513 | void checkReadyForSleepLocked(boolean allowDelay) { |
Wale Ogunwale | f673393 | 2018-06-27 05:14:34 -0700 | [diff] [blame] | 3514 | if (!mService.isSleepingOrShuttingDownLocked()) { |
Craig Mautner | 0eea92c | 2013-05-16 13:35:39 -0700 | [diff] [blame] | 3515 | // Do not care. |
| 3516 | return; |
| 3517 | } |
| 3518 | |
David Stevens | 18abd0e | 2017-08-17 14:55:47 -0700 | [diff] [blame] | 3519 | if (!putStacksToSleepLocked(allowDelay, false /* shuttingDown */)) { |
| 3520 | return; |
Craig Mautner | 0eea92c | 2013-05-16 13:35:39 -0700 | [diff] [blame] | 3521 | } |
| 3522 | |
Wei Wang | 65c7a15 | 2016-06-02 18:51:22 -0700 | [diff] [blame] | 3523 | // Send launch end powerhint before going sleep |
Bryce Lee | d3624e1 | 2017-11-30 08:51:45 -0800 | [diff] [blame] | 3524 | sendPowerHintForLaunchEndIfNeeded(); |
Wei Wang | 65c7a15 | 2016-06-02 18:51:22 -0700 | [diff] [blame] | 3525 | |
Craig Mautner | 0eea92c | 2013-05-16 13:35:39 -0700 | [diff] [blame] | 3526 | removeSleepTimeouts(); |
| 3527 | |
| 3528 | if (mGoingToSleep.isHeld()) { |
| 3529 | mGoingToSleep.release(); |
| 3530 | } |
Wale Ogunwale | f673393 | 2018-06-27 05:14:34 -0700 | [diff] [blame] | 3531 | if (mService.mShuttingDown) { |
| 3532 | mService.mGlobalLock.notifyAll(); |
Craig Mautner | 0eea92c | 2013-05-16 13:35:39 -0700 | [diff] [blame] | 3533 | } |
Craig Mautner | 8d341ef | 2013-03-26 09:03:27 -0700 | [diff] [blame] | 3534 | } |
| 3535 | |
David Stevens | 18abd0e | 2017-08-17 14:55:47 -0700 | [diff] [blame] | 3536 | // Tries to put all activity stacks to sleep. Returns true if all stacks were |
| 3537 | // successfully put to sleep. |
| 3538 | private boolean putStacksToSleepLocked(boolean allowDelay, boolean shuttingDown) { |
| 3539 | boolean allSleep = true; |
| 3540 | for (int displayNdx = mActivityDisplays.size() - 1; displayNdx >= 0; --displayNdx) { |
Riddle Hsu | 86cb7de | 2018-08-13 23:29:58 +0800 | [diff] [blame] | 3541 | final ActivityDisplay display = mActivityDisplays.get(displayNdx); |
Wale Ogunwale | a0f5b5e | 2017-10-11 09:37:23 -0700 | [diff] [blame] | 3542 | for (int stackNdx = display.getChildCount() - 1; stackNdx >= 0; --stackNdx) { |
| 3543 | final ActivityStack stack = display.getChildAt(stackNdx); |
David Stevens | 18abd0e | 2017-08-17 14:55:47 -0700 | [diff] [blame] | 3544 | if (allowDelay) { |
Wale Ogunwale | a0f5b5e | 2017-10-11 09:37:23 -0700 | [diff] [blame] | 3545 | allSleep &= stack.goToSleepIfPossible(shuttingDown); |
David Stevens | 18abd0e | 2017-08-17 14:55:47 -0700 | [diff] [blame] | 3546 | } else { |
Wale Ogunwale | a0f5b5e | 2017-10-11 09:37:23 -0700 | [diff] [blame] | 3547 | stack.goToSleep(); |
David Stevens | 18abd0e | 2017-08-17 14:55:47 -0700 | [diff] [blame] | 3548 | } |
| 3549 | } |
| 3550 | } |
| 3551 | return allSleep; |
| 3552 | } |
| 3553 | |
Craig Mautner | ce5f3cb | 2013-04-22 08:58:54 -0700 | [diff] [blame] | 3554 | boolean reportResumedActivityLocked(ActivityRecord r) { |
Bryce Lee | 29a649d | 2017-08-18 13:52:31 -0700 | [diff] [blame] | 3555 | // A resumed activity cannot be stopping. remove from list |
| 3556 | mStoppingActivities.remove(r); |
| 3557 | |
Andrii Kulian | 02b7a83 | 2016-10-06 23:11:56 -0700 | [diff] [blame] | 3558 | final ActivityStack stack = r.getStack(); |
Andrii Kulian | 5f750bc | 2018-07-17 08:57:23 -0700 | [diff] [blame] | 3559 | if (isTopDisplayFocusedStack(stack)) { |
Wale Ogunwale | 5378374 | 2018-09-16 10:21:51 -0700 | [diff] [blame] | 3560 | mService.updateUsageStats(r, true); |
Craig Mautner | ce5f3cb | 2013-04-22 08:58:54 -0700 | [diff] [blame] | 3561 | } |
Riddle Hsu | bbb63c2 | 2018-10-03 12:28:29 +0800 | [diff] [blame] | 3562 | if (stack.getDisplay().allResumedActivitiesComplete()) { |
Filip Gruszczynski | bc5a6c5 | 2015-09-22 13:13:24 -0700 | [diff] [blame] | 3563 | ensureActivitiesVisibleLocked(null, 0, !PRESERVE_WINDOWS); |
lumark | 588a3e8 | 2018-07-20 18:53:54 +0800 | [diff] [blame] | 3564 | // Make sure activity & window visibility should be identical |
| 3565 | // for all displays in this stage. |
| 3566 | executeAppTransitionForAllDisplay(); |
Craig Mautner | ce5f3cb | 2013-04-22 08:58:54 -0700 | [diff] [blame] | 3567 | return true; |
| 3568 | } |
| 3569 | return false; |
| 3570 | } |
| 3571 | |
Wale Ogunwale | 9e4f3e0 | 2018-05-17 09:35:39 -0700 | [diff] [blame] | 3572 | void handleAppCrashLocked(WindowProcessController app) { |
Craig Mautner | e0a3884 | 2013-12-16 16:14:02 -0800 | [diff] [blame] | 3573 | for (int displayNdx = mActivityDisplays.size() - 1; displayNdx >= 0; --displayNdx) { |
Riddle Hsu | 86cb7de | 2018-08-13 23:29:58 +0800 | [diff] [blame] | 3574 | final ActivityDisplay display = mActivityDisplays.get(displayNdx); |
Wale Ogunwale | a0f5b5e | 2017-10-11 09:37:23 -0700 | [diff] [blame] | 3575 | for (int stackNdx = display.getChildCount() - 1; stackNdx >= 0; --stackNdx) { |
| 3576 | final ActivityStack stack = display.getChildAt(stackNdx); |
| 3577 | stack.handleAppCrashLocked(app); |
Craig Mautner | 4a1cb22 | 2013-12-04 16:14:06 -0800 | [diff] [blame] | 3578 | } |
Craig Mautner | 8d341ef | 2013-03-26 09:03:27 -0700 | [diff] [blame] | 3579 | } |
| 3580 | } |
| 3581 | |
Craig Mautner | bb74246 | 2014-07-07 15:28:55 -0700 | [diff] [blame] | 3582 | // Called when WindowManager has finished animating the launchingBehind activity to the back. |
Andrii Kulian | 21713ac | 2016-10-12 22:05:05 -0700 | [diff] [blame] | 3583 | private void handleLaunchTaskBehindCompleteLocked(ActivityRecord r) { |
Bryce Lee | af691c0 | 2017-03-20 14:20:22 -0700 | [diff] [blame] | 3584 | final TaskRecord task = r.getTask(); |
Andrii Kulian | 02b7a83 | 2016-10-06 23:11:56 -0700 | [diff] [blame] | 3585 | final ActivityStack stack = task.getStack(); |
Winson | 730bf06 | 2016-03-31 18:04:56 -0700 | [diff] [blame] | 3586 | |
| 3587 | r.mLaunchTaskBehind = false; |
Winson Chung | 1dbc811 | 2017-09-28 18:05:31 -0700 | [diff] [blame] | 3588 | mRecentTasks.add(task); |
Wale Ogunwale | c9e57de | 2018-05-08 14:28:07 -0700 | [diff] [blame] | 3589 | mService.getTaskChangeNotificationController().notifyTaskStackChanged(); |
Wale Ogunwale | 26c0dfe | 2016-12-14 14:42:30 -0800 | [diff] [blame] | 3590 | r.setVisibility(false); |
Winson | 730bf06 | 2016-03-31 18:04:56 -0700 | [diff] [blame] | 3591 | |
| 3592 | // When launching tasks behind, update the last active time of the top task after the new |
| 3593 | // task has been shown briefly |
Wale Ogunwale | 30e441d | 2017-11-09 08:28:45 -0800 | [diff] [blame] | 3594 | final ActivityRecord top = stack.getTopActivity(); |
Winson | 730bf06 | 2016-03-31 18:04:56 -0700 | [diff] [blame] | 3595 | if (top != null) { |
Bryce Lee | af691c0 | 2017-03-20 14:20:22 -0700 | [diff] [blame] | 3596 | top.getTask().touchActiveTime(); |
Winson | 730bf06 | 2016-03-31 18:04:56 -0700 | [diff] [blame] | 3597 | } |
Craig Mautner | bb74246 | 2014-07-07 15:28:55 -0700 | [diff] [blame] | 3598 | } |
| 3599 | |
| 3600 | void scheduleLaunchTaskBehindComplete(IBinder token) { |
| 3601 | mHandler.obtainMessage(LAUNCH_TASK_BEHIND_COMPLETE, token).sendToTarget(); |
| 3602 | } |
| 3603 | |
Andrii Kulian | f4479ee | 2018-05-23 17:52:48 -0700 | [diff] [blame] | 3604 | /** |
| 3605 | * Make sure that all activities that need to be visible in the system actually are and update |
| 3606 | * their configuration. |
| 3607 | */ |
Filip Gruszczynski | bc5a6c5 | 2015-09-22 13:13:24 -0700 | [diff] [blame] | 3608 | void ensureActivitiesVisibleLocked(ActivityRecord starting, int configChanges, |
| 3609 | boolean preserveWindows) { |
Andrii Kulian | f4479ee | 2018-05-23 17:52:48 -0700 | [diff] [blame] | 3610 | ensureActivitiesVisibleLocked(starting, configChanges, preserveWindows, |
Andrii Kulian | a39ae3e | 2018-05-31 12:43:54 -0700 | [diff] [blame] | 3611 | true /* notifyClients */); |
Andrii Kulian | f4479ee | 2018-05-23 17:52:48 -0700 | [diff] [blame] | 3612 | } |
| 3613 | |
| 3614 | /** |
| 3615 | * @see #ensureActivitiesVisibleLocked(ActivityRecord, int, boolean) |
| 3616 | */ |
| 3617 | void ensureActivitiesVisibleLocked(ActivityRecord starting, int configChanges, |
Andrii Kulian | a39ae3e | 2018-05-31 12:43:54 -0700 | [diff] [blame] | 3618 | boolean preserveWindows, boolean notifyClients) { |
Bryce Lee | 459c062 | 2018-03-19 11:04:01 -0700 | [diff] [blame] | 3619 | getKeyguardController().beginActivityVisibilityUpdate(); |
Jorim Jaggi | fe76234 | 2016-10-13 14:33:27 +0200 | [diff] [blame] | 3620 | try { |
| 3621 | // First the front stacks. In case any are not fullscreen and are in front of home. |
| 3622 | for (int displayNdx = mActivityDisplays.size() - 1; displayNdx >= 0; --displayNdx) { |
Riddle Hsu | 86cb7de | 2018-08-13 23:29:58 +0800 | [diff] [blame] | 3623 | final ActivityDisplay display = mActivityDisplays.get(displayNdx); |
Wale Ogunwale | a0f5b5e | 2017-10-11 09:37:23 -0700 | [diff] [blame] | 3624 | for (int stackNdx = display.getChildCount() - 1; stackNdx >= 0; --stackNdx) { |
| 3625 | final ActivityStack stack = display.getChildAt(stackNdx); |
Andrii Kulian | f4479ee | 2018-05-23 17:52:48 -0700 | [diff] [blame] | 3626 | stack.ensureActivitiesVisibleLocked(starting, configChanges, preserveWindows, |
Andrii Kulian | a39ae3e | 2018-05-31 12:43:54 -0700 | [diff] [blame] | 3627 | notifyClients); |
Jorim Jaggi | fe76234 | 2016-10-13 14:33:27 +0200 | [diff] [blame] | 3628 | } |
Craig Mautner | 580ea81 | 2013-04-25 12:58:38 -0700 | [diff] [blame] | 3629 | } |
Jorim Jaggi | fe76234 | 2016-10-13 14:33:27 +0200 | [diff] [blame] | 3630 | } finally { |
Bryce Lee | 459c062 | 2018-03-19 11:04:01 -0700 | [diff] [blame] | 3631 | getKeyguardController().endActivityVisibilityUpdate(); |
Craig Mautner | 8d341ef | 2013-03-26 09:03:27 -0700 | [diff] [blame] | 3632 | } |
Craig Mautner | 8d341ef | 2013-03-26 09:03:27 -0700 | [diff] [blame] | 3633 | } |
| 3634 | |
Jorim Jaggi | 8b702ed | 2017-01-20 16:59:03 +0100 | [diff] [blame] | 3635 | void addStartingWindowsForVisibleActivities(boolean taskSwitch) { |
| 3636 | for (int displayNdx = mActivityDisplays.size() - 1; displayNdx >= 0; --displayNdx) { |
Riddle Hsu | 86cb7de | 2018-08-13 23:29:58 +0800 | [diff] [blame] | 3637 | final ActivityDisplay display = mActivityDisplays.get(displayNdx); |
Wale Ogunwale | a0f5b5e | 2017-10-11 09:37:23 -0700 | [diff] [blame] | 3638 | for (int stackNdx = display.getChildCount() - 1; stackNdx >= 0; --stackNdx) { |
| 3639 | final ActivityStack stack = display.getChildAt(stackNdx); |
Jorim Jaggi | 8b702ed | 2017-01-20 16:59:03 +0100 | [diff] [blame] | 3640 | stack.addStartingWindowsForVisibleActivities(taskSwitch); |
| 3641 | } |
| 3642 | } |
| 3643 | } |
| 3644 | |
Chong Zhang | fdcc4d4 | 2015-10-14 16:50:12 -0700 | [diff] [blame] | 3645 | void invalidateTaskLayers() { |
| 3646 | mTaskLayersChanged = true; |
| 3647 | } |
| 3648 | |
| 3649 | void rankTaskLayersIfNeeded() { |
| 3650 | if (!mTaskLayersChanged) { |
| 3651 | return; |
| 3652 | } |
| 3653 | mTaskLayersChanged = false; |
| 3654 | for (int displayNdx = 0; displayNdx < mActivityDisplays.size(); displayNdx++) { |
Riddle Hsu | 86cb7de | 2018-08-13 23:29:58 +0800 | [diff] [blame] | 3655 | final ActivityDisplay display = mActivityDisplays.get(displayNdx); |
Chong Zhang | fdcc4d4 | 2015-10-14 16:50:12 -0700 | [diff] [blame] | 3656 | int baseLayer = 0; |
Wale Ogunwale | a0f5b5e | 2017-10-11 09:37:23 -0700 | [diff] [blame] | 3657 | for (int stackNdx = display.getChildCount() - 1; stackNdx >= 0; --stackNdx) { |
| 3658 | final ActivityStack stack = display.getChildAt(stackNdx); |
| 3659 | baseLayer += stack.rankTaskLayers(baseLayer); |
Chong Zhang | fdcc4d4 | 2015-10-14 16:50:12 -0700 | [diff] [blame] | 3660 | } |
| 3661 | } |
| 3662 | } |
| 3663 | |
Dianne Hackborn | b5a380d | 2015-05-20 18:18:46 -0700 | [diff] [blame] | 3664 | void clearOtherAppTimeTrackers(AppTimeTracker except) { |
| 3665 | for (int displayNdx = mActivityDisplays.size() - 1; displayNdx >= 0; --displayNdx) { |
Riddle Hsu | 86cb7de | 2018-08-13 23:29:58 +0800 | [diff] [blame] | 3666 | final ActivityDisplay display = mActivityDisplays.get(displayNdx); |
Wale Ogunwale | a0f5b5e | 2017-10-11 09:37:23 -0700 | [diff] [blame] | 3667 | for (int stackNdx = display.getChildCount() - 1; stackNdx >= 0; --stackNdx) { |
| 3668 | final ActivityStack stack = display.getChildAt(stackNdx); |
Dianne Hackborn | b5a380d | 2015-05-20 18:18:46 -0700 | [diff] [blame] | 3669 | stack.clearOtherAppTimeTrackers(except); |
| 3670 | } |
| 3671 | } |
| 3672 | } |
| 3673 | |
Wale Ogunwale | 9e4f3e0 | 2018-05-17 09:35:39 -0700 | [diff] [blame] | 3674 | void scheduleDestroyAllActivities(WindowProcessController app, String reason) { |
Craig Mautner | e0a3884 | 2013-12-16 16:14:02 -0800 | [diff] [blame] | 3675 | for (int displayNdx = mActivityDisplays.size() - 1; displayNdx >= 0; --displayNdx) { |
Riddle Hsu | 86cb7de | 2018-08-13 23:29:58 +0800 | [diff] [blame] | 3676 | final ActivityDisplay display = mActivityDisplays.get(displayNdx); |
Wale Ogunwale | a0f5b5e | 2017-10-11 09:37:23 -0700 | [diff] [blame] | 3677 | for (int stackNdx = display.getChildCount() - 1; stackNdx >= 0; --stackNdx) { |
| 3678 | final ActivityStack stack = display.getChildAt(stackNdx); |
Craig Mautner | ee2e45a | 2014-06-27 12:10:03 -0700 | [diff] [blame] | 3679 | stack.scheduleDestroyActivities(app, reason); |
Craig Mautner | 4a1cb22 | 2013-12-04 16:14:06 -0800 | [diff] [blame] | 3680 | } |
Craig Mautner | 8d341ef | 2013-03-26 09:03:27 -0700 | [diff] [blame] | 3681 | } |
| 3682 | } |
| 3683 | |
Wale Ogunwale | 9e4f3e0 | 2018-05-17 09:35:39 -0700 | [diff] [blame] | 3684 | void releaseSomeActivitiesLocked(WindowProcessController app, String reason) { |
Dianne Hackborn | 89ad456 | 2014-08-24 16:45:38 -0700 | [diff] [blame] | 3685 | // Tasks is non-null only if two or more tasks are found. |
Wale Ogunwale | 9e4f3e0 | 2018-05-17 09:35:39 -0700 | [diff] [blame] | 3686 | ArraySet<TaskRecord> tasks = app.getReleaseSomeActivitiesTasks(); |
Dianne Hackborn | 89ad456 | 2014-08-24 16:45:38 -0700 | [diff] [blame] | 3687 | if (tasks == null) { |
Wale Ogunwale | 0fc365c | 2015-05-25 19:35:42 -0700 | [diff] [blame] | 3688 | if (DEBUG_RELEASE) Slog.d(TAG_RELEASE, "Didn't find two or more tasks to release"); |
Dianne Hackborn | 89ad456 | 2014-08-24 16:45:38 -0700 | [diff] [blame] | 3689 | return; |
| 3690 | } |
| 3691 | // If we have activities in multiple tasks that are in a position to be destroyed, |
| 3692 | // let's iterate through the tasks and release the oldest one. |
| 3693 | final int numDisplays = mActivityDisplays.size(); |
| 3694 | for (int displayNdx = 0; displayNdx < numDisplays; ++displayNdx) { |
Riddle Hsu | 86cb7de | 2018-08-13 23:29:58 +0800 | [diff] [blame] | 3695 | final ActivityDisplay display = mActivityDisplays.get(displayNdx); |
Wale Ogunwale | a0f5b5e | 2017-10-11 09:37:23 -0700 | [diff] [blame] | 3696 | final int stackCount = display.getChildCount(); |
Dianne Hackborn | 89ad456 | 2014-08-24 16:45:38 -0700 | [diff] [blame] | 3697 | // Step through all stacks starting from behind, to hit the oldest things first. |
Wale Ogunwale | a0f5b5e | 2017-10-11 09:37:23 -0700 | [diff] [blame] | 3698 | for (int stackNdx = 0; stackNdx < stackCount; stackNdx++) { |
| 3699 | final ActivityStack stack = display.getChildAt(stackNdx); |
Dianne Hackborn | 89ad456 | 2014-08-24 16:45:38 -0700 | [diff] [blame] | 3700 | // Try to release activities in this stack; if we manage to, we are done. |
| 3701 | if (stack.releaseSomeActivitiesLocked(app, tasks, reason) > 0) { |
| 3702 | return; |
| 3703 | } |
| 3704 | } |
| 3705 | } |
| 3706 | } |
| 3707 | |
Amith Yamasani | 37a40c2 | 2015-06-17 13:25:42 -0700 | [diff] [blame] | 3708 | boolean switchUserLocked(int userId, UserState uss) { |
Andrii Kulian | 5f750bc | 2018-07-17 08:57:23 -0700 | [diff] [blame] | 3709 | final int focusStackId = getTopDisplayFocusedStack().getStackId(); |
Wale Ogunwale | 9a98c52 | 2016-04-27 09:23:55 -0700 | [diff] [blame] | 3710 | // We dismiss the docked stack whenever we switch users. |
Wale Ogunwale | a0f5b5e | 2017-10-11 09:37:23 -0700 | [diff] [blame] | 3711 | final ActivityStack dockedStack = getDefaultDisplay().getSplitScreenPrimaryStack(); |
Wale Ogunwale | 9dcf946 | 2017-09-19 15:13:01 -0700 | [diff] [blame] | 3712 | if (dockedStack != null) { |
Andrii Kulian | 52d255c | 2018-07-13 11:32:19 -0700 | [diff] [blame] | 3713 | moveTasksToFullscreenStackLocked(dockedStack, dockedStack.isFocusedStackOnDisplay()); |
Wale Ogunwale | 9dcf946 | 2017-09-19 15:13:01 -0700 | [diff] [blame] | 3714 | } |
Winson Chung | c2b23a5 | 2017-01-09 15:44:55 -0800 | [diff] [blame] | 3715 | // Also dismiss the pinned stack whenever we switch users. Removing the pinned stack will |
| 3716 | // also cause all tasks to be moved to the fullscreen stack at a position that is |
| 3717 | // appropriate. |
Wale Ogunwale | 44f036f | 2017-09-29 05:09:09 -0700 | [diff] [blame] | 3718 | removeStacksInWindowingModes(WINDOWING_MODE_PINNED); |
Wale Ogunwale | 9a98c52 | 2016-04-27 09:23:55 -0700 | [diff] [blame] | 3719 | |
| 3720 | mUserStackInFront.put(mCurrentUser, focusStackId); |
Louis Chang | bd48dca | 2018-08-29 17:44:34 +0800 | [diff] [blame] | 3721 | final int restoreStackId = |
| 3722 | mUserStackInFront.get(userId, getDefaultDisplay().getHomeStack().mStackId); |
Craig Mautner | 2420ead | 2013-04-01 17:13:20 -0700 | [diff] [blame] | 3723 | mCurrentUser = userId; |
Craig Mautner | ac6f843 | 2013-07-17 13:24:59 -0700 | [diff] [blame] | 3724 | |
Craig Mautner | 858d8a6 | 2013-04-23 17:08:34 -0700 | [diff] [blame] | 3725 | mStartingUsers.add(uss); |
Craig Mautner | e0a3884 | 2013-12-16 16:14:02 -0800 | [diff] [blame] | 3726 | for (int displayNdx = mActivityDisplays.size() - 1; displayNdx >= 0; --displayNdx) { |
Riddle Hsu | 86cb7de | 2018-08-13 23:29:58 +0800 | [diff] [blame] | 3727 | final ActivityDisplay display = mActivityDisplays.get(displayNdx); |
Wale Ogunwale | a0f5b5e | 2017-10-11 09:37:23 -0700 | [diff] [blame] | 3728 | for (int stackNdx = display.getChildCount() - 1; stackNdx >= 0; --stackNdx) { |
| 3729 | final ActivityStack stack = display.getChildAt(stackNdx); |
Craig Mautner | e0a3884 | 2013-12-16 16:14:02 -0800 | [diff] [blame] | 3730 | stack.switchUserLocked(userId); |
Alexandra Gherghina | dae57a1 | 2014-03-12 19:15:26 +0000 | [diff] [blame] | 3731 | TaskRecord task = stack.topTask(); |
| 3732 | if (task != null) { |
Wale Ogunwale | 1666e31 | 2016-12-16 11:27:18 -0800 | [diff] [blame] | 3733 | stack.positionChildWindowContainerAtTop(task); |
Alexandra Gherghina | dae57a1 | 2014-03-12 19:15:26 +0000 | [diff] [blame] | 3734 | } |
Craig Mautner | 4a1cb22 | 2013-12-04 16:14:06 -0800 | [diff] [blame] | 3735 | } |
Craig Mautner | ac6f843 | 2013-07-17 13:24:59 -0700 | [diff] [blame] | 3736 | } |
Craig Mautner | 858d8a6 | 2013-04-23 17:08:34 -0700 | [diff] [blame] | 3737 | |
Craig Mautner | 4f1df4f | 2013-10-15 15:44:14 -0700 | [diff] [blame] | 3738 | ActivityStack stack = getStack(restoreStackId); |
| 3739 | if (stack == null) { |
Louis Chang | bd48dca | 2018-08-29 17:44:34 +0800 | [diff] [blame] | 3740 | stack = getDefaultDisplay().getHomeStack(); |
Craig Mautner | 4f1df4f | 2013-10-15 15:44:14 -0700 | [diff] [blame] | 3741 | } |
Wale Ogunwale | 6fbde9f | 2017-08-24 07:24:12 -0700 | [diff] [blame] | 3742 | final boolean homeInFront = stack.isActivityTypeHome(); |
Craig Mautner | e0a3884 | 2013-12-16 16:14:02 -0800 | [diff] [blame] | 3743 | if (stack.isOnHomeDisplay()) { |
Wale Ogunwale | 925d0d1 | 2015-09-23 15:40:07 -0700 | [diff] [blame] | 3744 | stack.moveToFront("switchUserOnHomeDisplay"); |
Craig Mautner | e0a3884 | 2013-12-16 16:14:02 -0800 | [diff] [blame] | 3745 | } else { |
| 3746 | // Stack was moved to another display while user was swapped out. |
Louis Chang | bd48dca | 2018-08-29 17:44:34 +0800 | [diff] [blame] | 3747 | resumeHomeActivity(null, "switchUserOnOtherDisplay", DEFAULT_DISPLAY); |
Craig Mautner | e0a3884 | 2013-12-16 16:14:02 -0800 | [diff] [blame] | 3748 | } |
Craig Mautner | 93529a4 | 2013-10-04 15:03:13 -0700 | [diff] [blame] | 3749 | return homeInFront; |
Craig Mautner | 2219a1b | 2013-03-25 09:44:30 -0700 | [diff] [blame] | 3750 | } |
| 3751 | |
Wale Ogunwale | 0bd2aa7 | 2015-04-16 13:50:44 -0700 | [diff] [blame] | 3752 | /** Checks whether the userid is a profile of the current user. */ |
| 3753 | boolean isCurrentProfileLocked(int userId) { |
| 3754 | if (userId == mCurrentUser) return true; |
Wale Ogunwale | 86b7446 | 2018-07-02 08:42:43 -0700 | [diff] [blame] | 3755 | return mService.mAmInternal.isCurrentProfile(userId); |
Wale Ogunwale | 0bd2aa7 | 2015-04-16 13:50:44 -0700 | [diff] [blame] | 3756 | } |
| 3757 | |
Bryce Lee | b7c9b80 | 2017-05-02 14:20:24 -0700 | [diff] [blame] | 3758 | /** |
| 3759 | * Returns whether a stopping activity is present that should be stopped after visible, rather |
| 3760 | * than idle. |
| 3761 | * @return {@code true} if such activity is present. {@code false} otherwise. |
| 3762 | */ |
| 3763 | boolean isStoppingNoHistoryActivity() { |
| 3764 | // Activities that are marked as nohistory should be stopped immediately after the resumed |
| 3765 | // activity has become visible. |
| 3766 | for (ActivityRecord record : mStoppingActivities) { |
| 3767 | if (record.isNoHistory()) { |
| 3768 | return true; |
| 3769 | } |
| 3770 | } |
| 3771 | |
| 3772 | return false; |
| 3773 | } |
| 3774 | |
Winson Chung | 4dabf23 | 2017-01-25 13:25:22 -0800 | [diff] [blame] | 3775 | final ArrayList<ActivityRecord> processStoppingActivitiesLocked(ActivityRecord idleActivity, |
| 3776 | boolean remove, boolean processPausingActivities) { |
Craig Mautner | de4ef02 | 2013-04-07 19:01:33 -0700 | [diff] [blame] | 3777 | ArrayList<ActivityRecord> stops = null; |
| 3778 | |
| 3779 | final boolean nowVisible = allResumedActivitiesVisible(); |
Craig Mautner | 8c14c15 | 2015-01-15 17:32:07 -0800 | [diff] [blame] | 3780 | for (int activityNdx = mStoppingActivities.size() - 1; activityNdx >= 0; --activityNdx) { |
| 3781 | ActivityRecord s = mStoppingActivities.get(activityNdx); |
Bryce Lee | 4a19438 | 2017-04-04 14:32:48 -0700 | [diff] [blame] | 3782 | boolean waitingVisible = mActivitiesWaitingForVisibleActivity.contains(s); |
Wale Ogunwale | f81c1d1 | 2016-01-12 12:20:18 -0800 | [diff] [blame] | 3783 | if (DEBUG_STATES) Slog.v(TAG, "Stopping " + s + ": nowVisible=" + nowVisible |
Craig Mautner | 8c14c15 | 2015-01-15 17:32:07 -0800 | [diff] [blame] | 3784 | + " waitingVisible=" + waitingVisible + " finishing=" + s.finishing); |
| 3785 | if (waitingVisible && nowVisible) { |
Bryce Lee | 4a19438 | 2017-04-04 14:32:48 -0700 | [diff] [blame] | 3786 | mActivitiesWaitingForVisibleActivity.remove(s); |
Andrii Kulian | ee05681 | 2016-09-21 15:34:45 -0700 | [diff] [blame] | 3787 | waitingVisible = false; |
Craig Mautner | de4ef02 | 2013-04-07 19:01:33 -0700 | [diff] [blame] | 3788 | if (s.finishing) { |
| 3789 | // If this activity is finishing, it is sitting on top of |
| 3790 | // everyone else but we now know it is no longer needed... |
| 3791 | // so get rid of it. Otherwise, we need to go through the |
| 3792 | // normal flow and hide it once we determine that it is |
| 3793 | // hidden by the activities in front of it. |
Wale Ogunwale | f81c1d1 | 2016-01-12 12:20:18 -0800 | [diff] [blame] | 3794 | if (DEBUG_STATES) Slog.v(TAG, "Before stopping, can hide: " + s); |
Wale Ogunwale | 26c0dfe | 2016-12-14 14:42:30 -0800 | [diff] [blame] | 3795 | s.setVisibility(false); |
Craig Mautner | de4ef02 | 2013-04-07 19:01:33 -0700 | [diff] [blame] | 3796 | } |
| 3797 | } |
David Stevens | 9440dc8 | 2017-03-16 19:00:20 -0700 | [diff] [blame] | 3798 | if (remove) { |
| 3799 | final ActivityStack stack = s.getStack(); |
| 3800 | final boolean shouldSleepOrShutDown = stack != null |
| 3801 | ? stack.shouldSleepOrShutDownActivities() |
Wale Ogunwale | f673393 | 2018-06-27 05:14:34 -0700 | [diff] [blame] | 3802 | : mService.isSleepingOrShuttingDownLocked(); |
David Stevens | 9440dc8 | 2017-03-16 19:00:20 -0700 | [diff] [blame] | 3803 | if (!waitingVisible || shouldSleepOrShutDown) { |
Bryce Lee | 7ace395 | 2018-02-16 14:34:32 -0800 | [diff] [blame] | 3804 | if (!processPausingActivities && s.isState(PAUSING)) { |
David Stevens | 9440dc8 | 2017-03-16 19:00:20 -0700 | [diff] [blame] | 3805 | // Defer processing pausing activities in this iteration and reschedule |
| 3806 | // a delayed idle to reprocess it again |
| 3807 | removeTimeoutsForActivityLocked(idleActivity); |
| 3808 | scheduleIdleTimeoutLocked(idleActivity); |
| 3809 | continue; |
| 3810 | } |
Winson Chung | 4dabf23 | 2017-01-25 13:25:22 -0800 | [diff] [blame] | 3811 | |
David Stevens | 9440dc8 | 2017-03-16 19:00:20 -0700 | [diff] [blame] | 3812 | if (DEBUG_STATES) Slog.v(TAG, "Ready to stop: " + s); |
| 3813 | if (stops == null) { |
| 3814 | stops = new ArrayList<>(); |
| 3815 | } |
| 3816 | stops.add(s); |
Jorim Jaggi | 5db9ae4 | 2018-06-25 16:14:50 +0200 | [diff] [blame] | 3817 | |
| 3818 | // Make sure to remove it in all cases in case we entered this block with |
| 3819 | // shouldSleepOrShutDown |
| 3820 | mActivitiesWaitingForVisibleActivity.remove(s); |
David Stevens | 9440dc8 | 2017-03-16 19:00:20 -0700 | [diff] [blame] | 3821 | mStoppingActivities.remove(activityNdx); |
Craig Mautner | de4ef02 | 2013-04-07 19:01:33 -0700 | [diff] [blame] | 3822 | } |
Craig Mautner | de4ef02 | 2013-04-07 19:01:33 -0700 | [diff] [blame] | 3823 | } |
| 3824 | } |
| 3825 | |
| 3826 | return stops; |
| 3827 | } |
| 3828 | |
Craig Mautner | cf910b0 | 2013-04-23 11:23:27 -0700 | [diff] [blame] | 3829 | void validateTopActivitiesLocked() { |
Wale Ogunwale | ee006da | 2015-03-30 14:49:25 -0700 | [diff] [blame] | 3830 | for (int displayNdx = mActivityDisplays.size() - 1; displayNdx >= 0; --displayNdx) { |
Riddle Hsu | 86cb7de | 2018-08-13 23:29:58 +0800 | [diff] [blame] | 3831 | final ActivityDisplay display = mActivityDisplays.get(displayNdx); |
Wale Ogunwale | a0f5b5e | 2017-10-11 09:37:23 -0700 | [diff] [blame] | 3832 | for (int stackNdx = display.getChildCount() - 1; stackNdx >= 0; --stackNdx) { |
| 3833 | final ActivityStack stack = display.getChildAt(stackNdx); |
Filip Gruszczynski | 3e85ba2 | 2015-10-05 22:48:30 -0700 | [diff] [blame] | 3834 | final ActivityRecord r = stack.topRunningActivityLocked(); |
Bryce Lee | 7ace395 | 2018-02-16 14:34:32 -0800 | [diff] [blame] | 3835 | final ActivityState state = r == null ? DESTROYED : r.getState(); |
Andrii Kulian | 5f750bc | 2018-07-17 08:57:23 -0700 | [diff] [blame] | 3836 | if (isTopDisplayFocusedStack(stack)) { |
Wale Ogunwale | ee006da | 2015-03-30 14:49:25 -0700 | [diff] [blame] | 3837 | if (r == null) Slog.e(TAG, |
| 3838 | "validateTop...: null top activity, stack=" + stack); |
| 3839 | else { |
| 3840 | final ActivityRecord pausing = stack.mPausingActivity; |
| 3841 | if (pausing != null && pausing == r) Slog.e(TAG, |
| 3842 | "validateTop...: top stack has pausing activity r=" + r |
| 3843 | + " state=" + state); |
| 3844 | if (state != INITIALIZING && state != RESUMED) Slog.e(TAG, |
| 3845 | "validateTop...: activity in front not resumed r=" + r |
| 3846 | + " state=" + state); |
| 3847 | } |
Craig Mautner | cf910b0 | 2013-04-23 11:23:27 -0700 | [diff] [blame] | 3848 | } else { |
Bryce Lee | c4ab62a | 2018-03-05 14:19:26 -0800 | [diff] [blame] | 3849 | final ActivityRecord resumed = stack.getResumedActivity(); |
Wale Ogunwale | ee006da | 2015-03-30 14:49:25 -0700 | [diff] [blame] | 3850 | if (resumed != null && resumed == r) Slog.e(TAG, |
| 3851 | "validateTop...: back stack has resumed activity r=" + r |
| 3852 | + " state=" + state); |
| 3853 | if (r != null && (state == INITIALIZING || state == RESUMED)) Slog.e(TAG, |
| 3854 | "validateTop...: activity in back resumed r=" + r + " state=" + state); |
Craig Mautner | cf910b0 | 2013-04-23 11:23:27 -0700 | [diff] [blame] | 3855 | } |
| 3856 | } |
| 3857 | } |
Craig Mautner | 76ea224 | 2013-05-15 11:40:05 -0700 | [diff] [blame] | 3858 | } |
| 3859 | |
Bryce Lee | 77a7dd6 | 2018-01-22 15:47:09 -0800 | [diff] [blame] | 3860 | public void dumpDisplays(PrintWriter pw) { |
| 3861 | for (int i = mActivityDisplays.size() - 1; i >= 0; --i) { |
Riddle Hsu | 86cb7de | 2018-08-13 23:29:58 +0800 | [diff] [blame] | 3862 | final ActivityDisplay display = mActivityDisplays.get(i); |
Bryce Lee | 77a7dd6 | 2018-01-22 15:47:09 -0800 | [diff] [blame] | 3863 | pw.print("[id:" + display.mDisplayId + " stacks:"); |
| 3864 | display.dumpStacks(pw); |
| 3865 | pw.print("]"); |
| 3866 | } |
| 3867 | } |
| 3868 | |
Craig Mautner | 2708430 | 2013-03-25 08:05:25 -0700 | [diff] [blame] | 3869 | public void dump(PrintWriter pw, String prefix) { |
Riddle Hsu | 7501699 | 2018-09-20 20:37:14 +0800 | [diff] [blame] | 3870 | pw.println(); |
| 3871 | pw.println("ActivityStackSupervisor state:"); |
| 3872 | pw.print(prefix); |
| 3873 | pw.println("topDisplayFocusedStack=" + getTopDisplayFocusedStack()); |
| 3874 | pw.print(prefix); |
Suprabh Shukla | 09a88f5 | 2015-12-02 14:36:31 -0800 | [diff] [blame] | 3875 | pw.println("mCurTaskIdForUser=" + mCurTaskIdForUser); |
Craig Mautner | d1bbdb462 | 2013-10-22 09:53:20 -0700 | [diff] [blame] | 3876 | pw.print(prefix); pw.println("mUserStackInFront=" + mUserStackInFront); |
Wale Ogunwale | 9dcf946 | 2017-09-19 15:13:01 -0700 | [diff] [blame] | 3877 | for (int i = mActivityDisplays.size() - 1; i >= 0; --i) { |
Riddle Hsu | 86cb7de | 2018-08-13 23:29:58 +0800 | [diff] [blame] | 3878 | final ActivityDisplay display = mActivityDisplays.get(i); |
Wale Ogunwale | a0f5b5e | 2017-10-11 09:37:23 -0700 | [diff] [blame] | 3879 | display.dump(pw, prefix); |
Wale Ogunwale | 9dcf946 | 2017-09-19 15:13:01 -0700 | [diff] [blame] | 3880 | } |
Bryce Lee | 4a19438 | 2017-04-04 14:32:48 -0700 | [diff] [blame] | 3881 | if (!mWaitingForActivityVisible.isEmpty()) { |
| 3882 | pw.print(prefix); pw.println("mWaitingForActivityVisible="); |
| 3883 | for (int i = 0; i < mWaitingForActivityVisible.size(); ++i) { |
| 3884 | pw.print(prefix); pw.print(prefix); mWaitingForActivityVisible.get(i).dump(pw, prefix); |
| 3885 | } |
| 3886 | } |
Winson Chung | c167427 | 2018-02-21 10:15:17 -0800 | [diff] [blame] | 3887 | pw.print(prefix); pw.print("isHomeRecentsComponent="); |
| 3888 | pw.print(mRecentTasks.isRecentsComponentHomeActivity(mCurrentUser)); |
Bryce Lee | 4a19438 | 2017-04-04 14:32:48 -0700 | [diff] [blame] | 3889 | |
Bryce Lee | 459c062 | 2018-03-19 11:04:01 -0700 | [diff] [blame] | 3890 | getKeyguardController().dump(pw, prefix); |
Wale Ogunwale | c9e57de | 2018-05-08 14:28:07 -0700 | [diff] [blame] | 3891 | mService.getLockTaskController().dump(pw, prefix); |
Craig Mautner | 2708430 | 2013-03-25 08:05:25 -0700 | [diff] [blame] | 3892 | } |
Craig Mautner | 8d341ef | 2013-03-26 09:03:27 -0700 | [diff] [blame] | 3893 | |
Yi Jin | 2b30f32 | 2018-02-20 15:41:47 -0800 | [diff] [blame] | 3894 | public void writeToProto(ProtoOutputStream proto, long fieldId) { |
| 3895 | final long token = proto.start(fieldId); |
Adrian Roos | 4921ccf | 2017-09-28 16:54:06 +0200 | [diff] [blame] | 3896 | super.writeToProto(proto, CONFIGURATION_CONTAINER, false /* trim */); |
Steven Timotius | 4346f0a | 2017-09-12 11:07:21 -0700 | [diff] [blame] | 3897 | for (int displayNdx = 0; displayNdx < mActivityDisplays.size(); ++displayNdx) { |
Riddle Hsu | 86cb7de | 2018-08-13 23:29:58 +0800 | [diff] [blame] | 3898 | final ActivityDisplay activityDisplay = mActivityDisplays.get(displayNdx); |
Steven Timotius | 4346f0a | 2017-09-12 11:07:21 -0700 | [diff] [blame] | 3899 | activityDisplay.writeToProto(proto, DISPLAYS); |
| 3900 | } |
Bryce Lee | 459c062 | 2018-03-19 11:04:01 -0700 | [diff] [blame] | 3901 | getKeyguardController().writeToProto(proto, KEYGUARD_CONTROLLER); |
Andrii Kulian | 52d255c | 2018-07-13 11:32:19 -0700 | [diff] [blame] | 3902 | // TODO(b/111541062): Update tests to look for resumed activities on all displays |
Andrii Kulian | 5f750bc | 2018-07-17 08:57:23 -0700 | [diff] [blame] | 3903 | final ActivityStack focusedStack = getTopDisplayFocusedStack(); |
Andrii Kulian | 52d255c | 2018-07-13 11:32:19 -0700 | [diff] [blame] | 3904 | if (focusedStack != null) { |
| 3905 | proto.write(FOCUSED_STACK_ID, focusedStack.mStackId); |
| 3906 | final ActivityRecord focusedActivity = focusedStack.getDisplay().getResumedActivity(); |
Steven Timotius | 4346f0a | 2017-09-12 11:07:21 -0700 | [diff] [blame] | 3907 | if (focusedActivity != null) { |
| 3908 | focusedActivity.writeIdentifierToProto(proto, RESUMED_ACTIVITY); |
| 3909 | } |
| 3910 | } else { |
| 3911 | proto.write(FOCUSED_STACK_ID, INVALID_STACK_ID); |
| 3912 | } |
Winson Chung | c167427 | 2018-02-21 10:15:17 -0800 | [diff] [blame] | 3913 | proto.write(IS_HOME_RECENTS_COMPONENT, |
| 3914 | mRecentTasks.isRecentsComponentHomeActivity(mCurrentUser)); |
wilsonshih | 468b7c0 | 2018-06-29 10:21:40 +0800 | [diff] [blame] | 3915 | mService.getActivityStartController().writeToProto(proto, PENDING_ACTIVITIES); |
Yi Jin | 2b30f32 | 2018-02-20 15:41:47 -0800 | [diff] [blame] | 3916 | proto.end(token); |
Steven Timotius | 4346f0a | 2017-09-12 11:07:21 -0700 | [diff] [blame] | 3917 | } |
| 3918 | |
Winson | 43d1f26 | 2016-06-14 16:05:55 -0700 | [diff] [blame] | 3919 | /** |
Andrii Kulian | 5406e7a | 2016-10-21 11:55:23 -0700 | [diff] [blame] | 3920 | * Dump all connected displays' configurations. |
| 3921 | * @param prefix Prefix to apply to each line of the dump. |
| 3922 | */ |
| 3923 | void dumpDisplayConfigs(PrintWriter pw, String prefix) { |
| 3924 | pw.print(prefix); pw.println("Display override configurations:"); |
| 3925 | final int displayCount = mActivityDisplays.size(); |
| 3926 | for (int i = 0; i < displayCount; i++) { |
Riddle Hsu | 86cb7de | 2018-08-13 23:29:58 +0800 | [diff] [blame] | 3927 | final ActivityDisplay activityDisplay = mActivityDisplays.get(i); |
Andrii Kulian | 5406e7a | 2016-10-21 11:55:23 -0700 | [diff] [blame] | 3928 | pw.print(prefix); pw.print(" "); pw.print(activityDisplay.mDisplayId); pw.print(": "); |
| 3929 | pw.println(activityDisplay.getOverrideConfiguration()); |
| 3930 | } |
| 3931 | } |
| 3932 | |
| 3933 | /** |
Winson | 43d1f26 | 2016-06-14 16:05:55 -0700 | [diff] [blame] | 3934 | * Dumps the activities matching the given {@param name} in the either the focused stack |
| 3935 | * or all visible stacks if {@param dumpVisibleStacks} is true. |
| 3936 | */ |
Winson Chung | 6998bc4 | 2017-02-28 17:07:05 -0800 | [diff] [blame] | 3937 | ArrayList<ActivityRecord> getDumpActivitiesLocked(String name, boolean dumpVisibleStacksOnly, |
| 3938 | boolean dumpFocusedStackOnly) { |
| 3939 | if (dumpFocusedStackOnly) { |
Andrii Kulian | 5f750bc | 2018-07-17 08:57:23 -0700 | [diff] [blame] | 3940 | return getTopDisplayFocusedStack().getDumpActivitiesLocked(name); |
Winson Chung | 6998bc4 | 2017-02-28 17:07:05 -0800 | [diff] [blame] | 3941 | } else { |
Winson | 43d1f26 | 2016-06-14 16:05:55 -0700 | [diff] [blame] | 3942 | ArrayList<ActivityRecord> activities = new ArrayList<>(); |
| 3943 | int numDisplays = mActivityDisplays.size(); |
| 3944 | for (int displayNdx = 0; displayNdx < numDisplays; ++displayNdx) { |
Riddle Hsu | 86cb7de | 2018-08-13 23:29:58 +0800 | [diff] [blame] | 3945 | final ActivityDisplay display = mActivityDisplays.get(displayNdx); |
Wale Ogunwale | a0f5b5e | 2017-10-11 09:37:23 -0700 | [diff] [blame] | 3946 | for (int stackNdx = display.getChildCount() - 1; stackNdx >= 0; --stackNdx) { |
| 3947 | final ActivityStack stack = display.getChildAt(stackNdx); |
Wale Ogunwale | 9dcf946 | 2017-09-19 15:13:01 -0700 | [diff] [blame] | 3948 | if (!dumpVisibleStacksOnly || stack.shouldBeVisible(null)) { |
Winson | 43d1f26 | 2016-06-14 16:05:55 -0700 | [diff] [blame] | 3949 | activities.addAll(stack.getDumpActivitiesLocked(name)); |
| 3950 | } |
| 3951 | } |
| 3952 | } |
| 3953 | return activities; |
Winson | 43d1f26 | 2016-06-14 16:05:55 -0700 | [diff] [blame] | 3954 | } |
Craig Mautner | 20e7227 | 2013-04-01 13:45:53 -0700 | [diff] [blame] | 3955 | } |
| 3956 | |
Dianne Hackborn | 390517b | 2013-05-30 15:03:32 -0700 | [diff] [blame] | 3957 | static boolean printThisActivity(PrintWriter pw, ActivityRecord activity, String dumpPackage, |
| 3958 | boolean needSep, String prefix) { |
| 3959 | if (activity != null) { |
| 3960 | if (dumpPackage == null || dumpPackage.equals(activity.packageName)) { |
| 3961 | if (needSep) { |
| 3962 | pw.println(); |
Dianne Hackborn | 390517b | 2013-05-30 15:03:32 -0700 | [diff] [blame] | 3963 | } |
| 3964 | pw.print(prefix); |
| 3965 | pw.println(activity); |
Dianne Hackborn | 7ad34e5 | 2013-06-05 18:41:45 -0700 | [diff] [blame] | 3966 | return true; |
Dianne Hackborn | 390517b | 2013-05-30 15:03:32 -0700 | [diff] [blame] | 3967 | } |
| 3968 | } |
Dianne Hackborn | 7ad34e5 | 2013-06-05 18:41:45 -0700 | [diff] [blame] | 3969 | return false; |
Dianne Hackborn | 390517b | 2013-05-30 15:03:32 -0700 | [diff] [blame] | 3970 | } |
| 3971 | |
Craig Mautner | 8d341ef | 2013-03-26 09:03:27 -0700 | [diff] [blame] | 3972 | boolean dumpActivitiesLocked(FileDescriptor fd, PrintWriter pw, boolean dumpAll, |
| 3973 | boolean dumpClient, String dumpPackage) { |
Dianne Hackborn | 7ad34e5 | 2013-06-05 18:41:45 -0700 | [diff] [blame] | 3974 | boolean printed = false; |
| 3975 | boolean needSep = false; |
Riddle Hsu | 86cb7de | 2018-08-13 23:29:58 +0800 | [diff] [blame] | 3976 | for (int displayNdx = mActivityDisplays.size() - 1; displayNdx >= 0; --displayNdx) { |
| 3977 | ActivityDisplay activityDisplay = mActivityDisplays.get(displayNdx); |
Craig Mautner | ee2e45a | 2014-06-27 12:10:03 -0700 | [diff] [blame] | 3978 | pw.print("Display #"); pw.print(activityDisplay.mDisplayId); |
Craig Mautner | 737fae2 | 2014-10-15 12:52:10 -0700 | [diff] [blame] | 3979 | pw.println(" (activities from top to bottom):"); |
Riddle Hsu | 86cb7de | 2018-08-13 23:29:58 +0800 | [diff] [blame] | 3980 | final ActivityDisplay display = mActivityDisplays.get(displayNdx); |
Wale Ogunwale | a0f5b5e | 2017-10-11 09:37:23 -0700 | [diff] [blame] | 3981 | for (int stackNdx = display.getChildCount() - 1; stackNdx >= 0; --stackNdx) { |
| 3982 | final ActivityStack stack = display.getChildAt(stackNdx); |
Wale Ogunwale | 34a5b57 | 2017-08-31 08:29:41 -0700 | [diff] [blame] | 3983 | pw.println(); |
Wale Ogunwale | 44f036f | 2017-09-29 05:09:09 -0700 | [diff] [blame] | 3984 | pw.println(" Stack #" + stack.mStackId |
Wale Ogunwale | 6191149 | 2017-10-11 08:50:50 -0700 | [diff] [blame] | 3985 | + ": type=" + activityTypeToString(stack.getActivityType()) |
| 3986 | + " mode=" + windowingModeToString(stack.getWindowingMode())); |
Wale Ogunwale | 34a5b57 | 2017-08-31 08:29:41 -0700 | [diff] [blame] | 3987 | pw.println(" isSleeping=" + stack.shouldSleepActivities()); |
Bryce Lee | f3c6a47 | 2017-11-14 14:53:06 -0800 | [diff] [blame] | 3988 | pw.println(" mBounds=" + stack.getOverrideBounds()); |
Winson Chung | abb433b | 2017-03-24 09:35:42 -0700 | [diff] [blame] | 3989 | |
Wale Ogunwale | 34a5b57 | 2017-08-31 08:29:41 -0700 | [diff] [blame] | 3990 | printed |= stack.dumpActivitiesLocked(fd, pw, dumpAll, dumpClient, dumpPackage, |
| 3991 | needSep); |
Winson Chung | abb433b | 2017-03-24 09:35:42 -0700 | [diff] [blame] | 3992 | |
Craig Mautner | 4a1cb22 | 2013-12-04 16:14:06 -0800 | [diff] [blame] | 3993 | printed |= dumpHistoryList(fd, pw, stack.mLRUActivities, " ", "Run", false, |
| 3994 | !dumpAll, false, dumpPackage, true, |
| 3995 | " Running activities (most recent first):", null); |
Craig Mautner | 8d341ef | 2013-03-26 09:03:27 -0700 | [diff] [blame] | 3996 | |
Craig Mautner | 4a1cb22 | 2013-12-04 16:14:06 -0800 | [diff] [blame] | 3997 | needSep = printed; |
| 3998 | boolean pr = printThisActivity(pw, stack.mPausingActivity, dumpPackage, needSep, |
| 3999 | " mPausingActivity: "); |
Dianne Hackborn | 7ad34e5 | 2013-06-05 18:41:45 -0700 | [diff] [blame] | 4000 | if (pr) { |
| 4001 | printed = true; |
Craig Mautner | 4a1cb22 | 2013-12-04 16:14:06 -0800 | [diff] [blame] | 4002 | needSep = false; |
Dianne Hackborn | 7ad34e5 | 2013-06-05 18:41:45 -0700 | [diff] [blame] | 4003 | } |
Bryce Lee | c4ab62a | 2018-03-05 14:19:26 -0800 | [diff] [blame] | 4004 | pr = printThisActivity(pw, stack.getResumedActivity(), dumpPackage, needSep, |
Craig Mautner | 4a1cb22 | 2013-12-04 16:14:06 -0800 | [diff] [blame] | 4005 | " mResumedActivity: "); |
| 4006 | if (pr) { |
| 4007 | printed = true; |
| 4008 | needSep = false; |
| 4009 | } |
| 4010 | if (dumpAll) { |
| 4011 | pr = printThisActivity(pw, stack.mLastPausedActivity, dumpPackage, needSep, |
| 4012 | " mLastPausedActivity: "); |
| 4013 | if (pr) { |
| 4014 | printed = true; |
| 4015 | needSep = true; |
| 4016 | } |
| 4017 | printed |= printThisActivity(pw, stack.mLastNoHistoryActivity, dumpPackage, |
| 4018 | needSep, " mLastNoHistoryActivity: "); |
| 4019 | } |
| 4020 | needSep = printed; |
Craig Mautner | 8d341ef | 2013-03-26 09:03:27 -0700 | [diff] [blame] | 4021 | } |
Andrii Kulian | 52d255c | 2018-07-13 11:32:19 -0700 | [diff] [blame] | 4022 | printThisActivity(pw, activityDisplay.getResumedActivity(), dumpPackage, needSep, |
| 4023 | " ResumedActivity:"); |
Craig Mautner | 8d341ef | 2013-03-26 09:03:27 -0700 | [diff] [blame] | 4024 | } |
| 4025 | |
Dianne Hackborn | 7ad34e5 | 2013-06-05 18:41:45 -0700 | [diff] [blame] | 4026 | printed |= dumpHistoryList(fd, pw, mFinishingActivities, " ", "Fin", false, !dumpAll, |
| 4027 | false, dumpPackage, true, " Activities waiting to finish:", null); |
| 4028 | printed |= dumpHistoryList(fd, pw, mStoppingActivities, " ", "Stop", false, !dumpAll, |
| 4029 | false, dumpPackage, true, " Activities waiting to stop:", null); |
Bryce Lee | 4a19438 | 2017-04-04 14:32:48 -0700 | [diff] [blame] | 4030 | printed |= dumpHistoryList(fd, pw, mActivitiesWaitingForVisibleActivity, " ", "Wait", |
| 4031 | false, !dumpAll, false, dumpPackage, true, |
| 4032 | " Activities waiting for another to become visible:", null); |
Dianne Hackborn | 7ad34e5 | 2013-06-05 18:41:45 -0700 | [diff] [blame] | 4033 | printed |= dumpHistoryList(fd, pw, mGoingToSleepActivities, " ", "Sleep", false, !dumpAll, |
| 4034 | false, dumpPackage, true, " Activities waiting to sleep:", null); |
Craig Mautner | f333327 | 2013-04-22 10:55:53 -0700 | [diff] [blame] | 4035 | |
Dianne Hackborn | 7ad34e5 | 2013-06-05 18:41:45 -0700 | [diff] [blame] | 4036 | return printed; |
Craig Mautner | 8d341ef | 2013-03-26 09:03:27 -0700 | [diff] [blame] | 4037 | } |
| 4038 | |
Dianne Hackborn | 390517b | 2013-05-30 15:03:32 -0700 | [diff] [blame] | 4039 | static boolean dumpHistoryList(FileDescriptor fd, PrintWriter pw, List<ActivityRecord> list, |
Craig Mautner | 8d341ef | 2013-03-26 09:03:27 -0700 | [diff] [blame] | 4040 | String prefix, String label, boolean complete, boolean brief, boolean client, |
Wale Ogunwale | 34a5b57 | 2017-08-31 08:29:41 -0700 | [diff] [blame] | 4041 | String dumpPackage, boolean needNL, String header, TaskRecord lastTask) { |
Dianne Hackborn | 390517b | 2013-05-30 15:03:32 -0700 | [diff] [blame] | 4042 | String innerPrefix = null; |
| 4043 | String[] args = null; |
| 4044 | boolean printed = false; |
Craig Mautner | 8d341ef | 2013-03-26 09:03:27 -0700 | [diff] [blame] | 4045 | for (int i=list.size()-1; i>=0; i--) { |
| 4046 | final ActivityRecord r = list.get(i); |
| 4047 | if (dumpPackage != null && !dumpPackage.equals(r.packageName)) { |
| 4048 | continue; |
| 4049 | } |
Dianne Hackborn | 390517b | 2013-05-30 15:03:32 -0700 | [diff] [blame] | 4050 | if (innerPrefix == null) { |
| 4051 | innerPrefix = prefix + " "; |
| 4052 | args = new String[0]; |
| 4053 | } |
| 4054 | printed = true; |
Craig Mautner | 8d341ef | 2013-03-26 09:03:27 -0700 | [diff] [blame] | 4055 | final boolean full = !brief && (complete || !r.isInHistory()); |
| 4056 | if (needNL) { |
Dianne Hackborn | 390517b | 2013-05-30 15:03:32 -0700 | [diff] [blame] | 4057 | pw.println(""); |
Craig Mautner | 8d341ef | 2013-03-26 09:03:27 -0700 | [diff] [blame] | 4058 | needNL = false; |
| 4059 | } |
Wale Ogunwale | 34a5b57 | 2017-08-31 08:29:41 -0700 | [diff] [blame] | 4060 | if (header != null) { |
| 4061 | pw.println(header); |
| 4062 | header = null; |
Dianne Hackborn | 390517b | 2013-05-30 15:03:32 -0700 | [diff] [blame] | 4063 | } |
Bryce Lee | af691c0 | 2017-03-20 14:20:22 -0700 | [diff] [blame] | 4064 | if (lastTask != r.getTask()) { |
| 4065 | lastTask = r.getTask(); |
Craig Mautner | 8d341ef | 2013-03-26 09:03:27 -0700 | [diff] [blame] | 4066 | pw.print(prefix); |
| 4067 | pw.print(full ? "* " : " "); |
| 4068 | pw.println(lastTask); |
| 4069 | if (full) { |
| 4070 | lastTask.dump(pw, prefix + " "); |
| 4071 | } else if (complete) { |
| 4072 | // Complete + brief == give a summary. Isn't that obvious?!? |
| 4073 | if (lastTask.intent != null) { |
| 4074 | pw.print(prefix); pw.print(" "); |
| 4075 | pw.println(lastTask.intent.toInsecureStringWithClip()); |
| 4076 | } |
| 4077 | } |
| 4078 | } |
| 4079 | pw.print(prefix); pw.print(full ? " * " : " "); pw.print(label); |
| 4080 | pw.print(" #"); pw.print(i); pw.print(": "); |
| 4081 | pw.println(r); |
| 4082 | if (full) { |
| 4083 | r.dump(pw, innerPrefix); |
| 4084 | } else if (complete) { |
| 4085 | // Complete + brief == give a summary. Isn't that obvious?!? |
| 4086 | pw.print(innerPrefix); pw.println(r.intent.toInsecureString()); |
| 4087 | if (r.app != null) { |
| 4088 | pw.print(innerPrefix); pw.println(r.app); |
| 4089 | } |
| 4090 | } |
Wale Ogunwale | 9e4f3e0 | 2018-05-17 09:35:39 -0700 | [diff] [blame] | 4091 | if (client && r.attachedToProcess()) { |
Craig Mautner | 8d341ef | 2013-03-26 09:03:27 -0700 | [diff] [blame] | 4092 | // flush anything that is already in the PrintWriter since the thread is going |
| 4093 | // to write to the file descriptor directly |
| 4094 | pw.flush(); |
| 4095 | try { |
| 4096 | TransferPipe tp = new TransferPipe(); |
| 4097 | try { |
Wale Ogunwale | 9e4f3e0 | 2018-05-17 09:35:39 -0700 | [diff] [blame] | 4098 | r.app.getThread().dumpActivity( |
| 4099 | tp.getWriteFd(), r.appToken, innerPrefix, args); |
| 4100 | // Short timeout, since blocking here can deadlock with the application. |
Craig Mautner | 8d341ef | 2013-03-26 09:03:27 -0700 | [diff] [blame] | 4101 | tp.go(fd, 2000); |
| 4102 | } finally { |
| 4103 | tp.kill(); |
| 4104 | } |
| 4105 | } catch (IOException e) { |
| 4106 | pw.println(innerPrefix + "Failure while dumping the activity: " + e); |
| 4107 | } catch (RemoteException e) { |
| 4108 | pw.println(innerPrefix + "Got a RemoteException while dumping the activity"); |
| 4109 | } |
| 4110 | needNL = true; |
| 4111 | } |
| 4112 | } |
Dianne Hackborn | 390517b | 2013-05-30 15:03:32 -0700 | [diff] [blame] | 4113 | return printed; |
Craig Mautner | 8d341ef | 2013-03-26 09:03:27 -0700 | [diff] [blame] | 4114 | } |
Craig Mautner | ce5f3cb | 2013-04-22 08:58:54 -0700 | [diff] [blame] | 4115 | |
Craig Mautner | f333327 | 2013-04-22 10:55:53 -0700 | [diff] [blame] | 4116 | void scheduleIdleTimeoutLocked(ActivityRecord next) { |
Wale Ogunwale | 0fc365c | 2015-05-25 19:35:42 -0700 | [diff] [blame] | 4117 | if (DEBUG_IDLE) Slog.d(TAG_IDLE, |
| 4118 | "scheduleIdleTimeoutLocked: Callers=" + Debug.getCallers(4)); |
Craig Mautner | c64f73e | 2013-04-24 16:44:56 -0700 | [diff] [blame] | 4119 | Message msg = mHandler.obtainMessage(IDLE_TIMEOUT_MSG, next); |
| 4120 | mHandler.sendMessageDelayed(msg, IDLE_TIMEOUT); |
Craig Mautner | f333327 | 2013-04-22 10:55:53 -0700 | [diff] [blame] | 4121 | } |
| 4122 | |
| 4123 | final void scheduleIdleLocked() { |
Craig Mautner | 05d2903 | 2013-05-03 13:40:13 -0700 | [diff] [blame] | 4124 | mHandler.sendEmptyMessage(IDLE_NOW_MSG); |
Craig Mautner | f333327 | 2013-04-22 10:55:53 -0700 | [diff] [blame] | 4125 | } |
| 4126 | |
| 4127 | void removeTimeoutsForActivityLocked(ActivityRecord r) { |
Wale Ogunwale | 0fc365c | 2015-05-25 19:35:42 -0700 | [diff] [blame] | 4128 | if (DEBUG_IDLE) Slog.d(TAG_IDLE, "removeTimeoutsForActivity: Callers=" |
| 4129 | + Debug.getCallers(4)); |
Craig Mautner | f333327 | 2013-04-22 10:55:53 -0700 | [diff] [blame] | 4130 | mHandler.removeMessages(IDLE_TIMEOUT_MSG, r); |
| 4131 | } |
| 4132 | |
Craig Mautner | 05d2903 | 2013-05-03 13:40:13 -0700 | [diff] [blame] | 4133 | final void scheduleResumeTopActivities() { |
Craig Mautner | 34b73df | 2014-01-12 21:11:08 -0800 | [diff] [blame] | 4134 | if (!mHandler.hasMessages(RESUME_TOP_ACTIVITY_MSG)) { |
| 4135 | mHandler.sendEmptyMessage(RESUME_TOP_ACTIVITY_MSG); |
| 4136 | } |
Craig Mautner | 05d2903 | 2013-05-03 13:40:13 -0700 | [diff] [blame] | 4137 | } |
| 4138 | |
Craig Mautner | 0eea92c | 2013-05-16 13:35:39 -0700 | [diff] [blame] | 4139 | void removeSleepTimeouts() { |
Craig Mautner | 0eea92c | 2013-05-16 13:35:39 -0700 | [diff] [blame] | 4140 | mHandler.removeMessages(SLEEP_TIMEOUT_MSG); |
| 4141 | } |
| 4142 | |
| 4143 | final void scheduleSleepTimeout() { |
| 4144 | removeSleepTimeouts(); |
| 4145 | mHandler.sendEmptyMessageDelayed(SLEEP_TIMEOUT_MSG, SLEEP_TIMEOUT); |
| 4146 | } |
| 4147 | |
Craig Mautner | 4a1cb22 | 2013-12-04 16:14:06 -0800 | [diff] [blame] | 4148 | @Override |
| 4149 | public void onDisplayAdded(int displayId) { |
Dianne Hackborn | fb81d09 | 2015-08-03 17:14:46 -0700 | [diff] [blame] | 4150 | if (DEBUG_STACK) Slog.v(TAG, "Display added displayId=" + displayId); |
Riddle Hsu | f53da81 | 2018-08-15 22:00:27 +0800 | [diff] [blame] | 4151 | synchronized (mService.mGlobalLock) { |
| 4152 | getActivityDisplayOrCreateLocked(displayId); |
Louis Chang | 1eff248 | 2018-11-01 15:46:31 +0800 | [diff] [blame] | 4153 | // Do not start home before booting, or it may accidentally finish booting before it |
| 4154 | // starts. Instead, we expect home activities to be launched when the system is ready |
| 4155 | // (ActivityManagerService#systemReady). |
| 4156 | if (mService.isBooted() || mService.isBooting()) { |
| 4157 | startHomeOnDisplay(mCurrentUser, "displayAdded", displayId); |
| 4158 | } |
Riddle Hsu | f53da81 | 2018-08-15 22:00:27 +0800 | [diff] [blame] | 4159 | } |
Craig Mautner | 4a1cb22 | 2013-12-04 16:14:06 -0800 | [diff] [blame] | 4160 | } |
| 4161 | |
| 4162 | @Override |
| 4163 | public void onDisplayRemoved(int displayId) { |
Dianne Hackborn | fb81d09 | 2015-08-03 17:14:46 -0700 | [diff] [blame] | 4164 | if (DEBUG_STACK) Slog.v(TAG, "Display removed displayId=" + displayId); |
Riddle Hsu | f53da81 | 2018-08-15 22:00:27 +0800 | [diff] [blame] | 4165 | if (displayId == DEFAULT_DISPLAY) { |
| 4166 | throw new IllegalArgumentException("Can't remove the primary display."); |
| 4167 | } |
| 4168 | |
| 4169 | synchronized (mService.mGlobalLock) { |
| 4170 | final ActivityDisplay activityDisplay = getActivityDisplay(displayId); |
| 4171 | if (activityDisplay == null) { |
| 4172 | return; |
| 4173 | } |
| 4174 | |
| 4175 | activityDisplay.remove(); |
| 4176 | } |
Craig Mautner | 4a1cb22 | 2013-12-04 16:14:06 -0800 | [diff] [blame] | 4177 | } |
| 4178 | |
| 4179 | @Override |
| 4180 | public void onDisplayChanged(int displayId) { |
Dianne Hackborn | fb81d09 | 2015-08-03 17:14:46 -0700 | [diff] [blame] | 4181 | if (DEBUG_STACK) Slog.v(TAG, "Display changed displayId=" + displayId); |
Wale Ogunwale | c9e57de | 2018-05-08 14:28:07 -0700 | [diff] [blame] | 4182 | synchronized (mService.mGlobalLock) { |
Riddle Hsu | f53da81 | 2018-08-15 22:00:27 +0800 | [diff] [blame] | 4183 | final ActivityDisplay activityDisplay = getActivityDisplay(displayId); |
| 4184 | if (activityDisplay != null) { |
| 4185 | activityDisplay.onDisplayChanged(); |
| 4186 | } |
Craig Mautner | 4a1cb22 | 2013-12-04 16:14:06 -0800 | [diff] [blame] | 4187 | } |
Craig Mautner | 4a1cb22 | 2013-12-04 16:14:06 -0800 | [diff] [blame] | 4188 | } |
| 4189 | |
Andrii Kulian | ca007a6 | 2016-11-22 16:33:28 -0800 | [diff] [blame] | 4190 | /** Check if display with specified id is added to the list. */ |
| 4191 | boolean isDisplayAdded(int displayId) { |
Andrii Kulian | 62e6f25 | 2017-05-30 22:46:53 -0700 | [diff] [blame] | 4192 | return getActivityDisplayOrCreateLocked(displayId) != null; |
| 4193 | } |
| 4194 | |
Wale Ogunwale | 04a05ac | 2017-09-17 21:35:02 -0700 | [diff] [blame] | 4195 | // TODO: Look into consolidating with getActivityDisplayOrCreateLocked() |
Andrii Kulian | 94e82d9b0 | 2017-07-13 15:33:06 -0700 | [diff] [blame] | 4196 | ActivityDisplay getActivityDisplay(int displayId) { |
Riddle Hsu | 86cb7de | 2018-08-13 23:29:58 +0800 | [diff] [blame] | 4197 | for (int i = mActivityDisplays.size() - 1; i >= 0; --i) { |
| 4198 | final ActivityDisplay activityDisplay = mActivityDisplays.get(i); |
| 4199 | if (activityDisplay.mDisplayId == displayId) { |
| 4200 | return activityDisplay; |
| 4201 | } |
| 4202 | } |
| 4203 | return null; |
Andrii Kulian | 94e82d9b0 | 2017-07-13 15:33:06 -0700 | [diff] [blame] | 4204 | } |
| 4205 | |
Wale Ogunwale | 04a05ac | 2017-09-17 21:35:02 -0700 | [diff] [blame] | 4206 | // TODO(multi-display): Look at all callpoints to make sure they make sense in multi-display. |
| 4207 | ActivityDisplay getDefaultDisplay() { |
Riddle Hsu | 86cb7de | 2018-08-13 23:29:58 +0800 | [diff] [blame] | 4208 | return mDefaultDisplay; |
Wale Ogunwale | 04a05ac | 2017-09-17 21:35:02 -0700 | [diff] [blame] | 4209 | } |
| 4210 | |
Andrii Kulian | 62e6f25 | 2017-05-30 22:46:53 -0700 | [diff] [blame] | 4211 | /** |
| 4212 | * Get an existing instance of {@link ActivityDisplay} or create new if there is a |
| 4213 | * corresponding record in display manager. |
| 4214 | */ |
Wale Ogunwale | 04a05ac | 2017-09-17 21:35:02 -0700 | [diff] [blame] | 4215 | // TODO: Look into consolidating with getActivityDisplay() |
| 4216 | ActivityDisplay getActivityDisplayOrCreateLocked(int displayId) { |
Riddle Hsu | 86cb7de | 2018-08-13 23:29:58 +0800 | [diff] [blame] | 4217 | ActivityDisplay activityDisplay = getActivityDisplay(displayId); |
Andrii Kulian | 62e6f25 | 2017-05-30 22:46:53 -0700 | [diff] [blame] | 4218 | if (activityDisplay != null) { |
| 4219 | return activityDisplay; |
| 4220 | } |
| 4221 | if (mDisplayManager == null) { |
| 4222 | // The system isn't fully initialized yet. |
| 4223 | return null; |
| 4224 | } |
| 4225 | final Display display = mDisplayManager.getDisplay(displayId); |
| 4226 | if (display == null) { |
| 4227 | // The display is not registered in DisplayManager. |
| 4228 | return null; |
| 4229 | } |
| 4230 | // The display hasn't been added to ActivityManager yet, create a new record now. |
Wale Ogunwale | 45477b5 | 2018-03-06 12:24:19 -0800 | [diff] [blame] | 4231 | activityDisplay = new ActivityDisplay(this, display); |
Riddle Hsu | 86cb7de | 2018-08-13 23:29:58 +0800 | [diff] [blame] | 4232 | addChild(activityDisplay, ActivityDisplay.POSITION_BOTTOM); |
Andrii Kulian | 62e6f25 | 2017-05-30 22:46:53 -0700 | [diff] [blame] | 4233 | return activityDisplay; |
Andrii Kulian | ca007a6 | 2016-11-22 16:33:28 -0800 | [diff] [blame] | 4234 | } |
| 4235 | |
Louis Chang | 89f43fc | 2018-10-05 10:59:14 +0800 | [diff] [blame] | 4236 | boolean startHomeOnAllDisplays(int userId, String reason) { |
| 4237 | boolean homeStarted = false; |
| 4238 | for (int i = mActivityDisplays.size() - 1; i >= 0; i--) { |
| 4239 | final int displayId = mActivityDisplays.get(i).mDisplayId; |
| 4240 | homeStarted |= startHomeOnDisplay(userId, reason, displayId); |
| 4241 | } |
| 4242 | return homeStarted; |
| 4243 | } |
| 4244 | |
| 4245 | /** |
| 4246 | * This starts home activity on displays that can have system decorations and only if the |
| 4247 | * home activity can have multiple instances. |
| 4248 | */ |
| 4249 | boolean startHomeOnDisplay(int userId, String reason, int displayId) { |
| 4250 | final Intent homeIntent = mService.getHomeIntent(); |
| 4251 | final ActivityInfo aInfo = resolveHomeActivity(userId, homeIntent); |
| 4252 | if (aInfo == null) { |
| 4253 | return false; |
| 4254 | } |
| 4255 | |
Louis Chang | dd3592a | 2018-11-05 11:04:14 +0800 | [diff] [blame] | 4256 | if (!canStartHomeOnDisplay(aInfo, displayId, false /* allowInstrumenting */)) { |
Louis Chang | 89f43fc | 2018-10-05 10:59:14 +0800 | [diff] [blame] | 4257 | return false; |
| 4258 | } |
| 4259 | |
| 4260 | // Update the reason for ANR debugging to verify if the user activity is the one that |
| 4261 | // actually launched. |
| 4262 | final String myReason = reason + ":" + userId + ":" + UserHandle.getUserId( |
| 4263 | aInfo.applicationInfo.uid); |
| 4264 | mService.getActivityStartController().startHomeActivity(homeIntent, aInfo, myReason, |
| 4265 | displayId); |
| 4266 | return true; |
| 4267 | } |
| 4268 | |
| 4269 | /** |
| 4270 | * This resolves the home activity info and updates the home component of the given intent. |
| 4271 | * @return the home activity info if any. |
| 4272 | */ |
| 4273 | private ActivityInfo resolveHomeActivity(int userId, Intent homeIntent) { |
| 4274 | final int flags = ActivityManagerService.STOCK_PM_FLAGS; |
| 4275 | final ComponentName comp = homeIntent.getComponent(); |
| 4276 | ActivityInfo aInfo = null; |
| 4277 | try { |
| 4278 | if (comp != null) { |
| 4279 | // Factory test. |
| 4280 | aInfo = AppGlobals.getPackageManager().getActivityInfo(comp, flags, userId); |
| 4281 | } else { |
| 4282 | final String resolvedType = |
| 4283 | homeIntent.resolveTypeIfNeeded(mService.mContext.getContentResolver()); |
| 4284 | final ResolveInfo info = AppGlobals.getPackageManager() |
| 4285 | .resolveIntent(homeIntent, resolvedType, flags, userId); |
| 4286 | if (info != null) { |
| 4287 | aInfo = info.activityInfo; |
| 4288 | } |
| 4289 | } |
| 4290 | } catch (RemoteException e) { |
| 4291 | // ignore |
| 4292 | } |
| 4293 | |
| 4294 | if (aInfo == null) { |
| 4295 | Slog.wtf(TAG, "No home screen found for " + homeIntent, new Throwable()); |
| 4296 | return null; |
| 4297 | } |
| 4298 | |
| 4299 | homeIntent.setComponent(new ComponentName(aInfo.applicationInfo.packageName, aInfo.name)); |
| 4300 | aInfo = new ActivityInfo(aInfo); |
| 4301 | aInfo.applicationInfo = mService.getAppInfoForUser(aInfo.applicationInfo, userId); |
| 4302 | homeIntent.setFlags(homeIntent.getFlags() | FLAG_ACTIVITY_NEW_TASK); |
| 4303 | return aInfo; |
| 4304 | } |
| 4305 | |
Wale Ogunwale | 9dcf946 | 2017-09-19 15:13:01 -0700 | [diff] [blame] | 4306 | @VisibleForTesting |
Riddle Hsu | 86cb7de | 2018-08-13 23:29:58 +0800 | [diff] [blame] | 4307 | void addChild(ActivityDisplay activityDisplay, int position) { |
| 4308 | positionChildAt(activityDisplay, position); |
| 4309 | mWindowContainerController.positionChildAt( |
| 4310 | activityDisplay.getWindowContainerController(), position); |
| 4311 | } |
| 4312 | |
| 4313 | void removeChild(ActivityDisplay activityDisplay) { |
| 4314 | // The caller must tell the controller of {@link ActivityDisplay} to release its container |
| 4315 | // {@link DisplayContent}. That is done in {@link ActivityDisplay#releaseSelfIfNeeded}). |
| 4316 | mActivityDisplays.remove(activityDisplay); |
Wale Ogunwale | 9dcf946 | 2017-09-19 15:13:01 -0700 | [diff] [blame] | 4317 | } |
| 4318 | |
Garfield Tan | 4a48a7f | 2018-10-02 14:23:55 -0700 | [diff] [blame] | 4319 | private void calculateDefaultMinimalSizeOfResizeableTasks() { |
| 4320 | final Resources res = mService.mContext.getResources(); |
| 4321 | final float minimalSize = res.getDimension( |
| 4322 | com.android.internal.R.dimen.default_minimal_size_resizable_task); |
| 4323 | final DisplayMetrics dm = res.getDisplayMetrics(); |
| 4324 | |
| 4325 | mDefaultMinSizeOfResizeableTaskDp = (int) (minimalSize / dm.density); |
Filip Gruszczynski | d2f1d94 | 2015-10-14 15:10:12 -0700 | [diff] [blame] | 4326 | } |
| 4327 | |
David Stevens | 9440dc8 | 2017-03-16 19:00:20 -0700 | [diff] [blame] | 4328 | SleepToken createSleepTokenLocked(String tag, int displayId) { |
Riddle Hsu | 86cb7de | 2018-08-13 23:29:58 +0800 | [diff] [blame] | 4329 | final ActivityDisplay display = getActivityDisplay(displayId); |
David Stevens | 9440dc8 | 2017-03-16 19:00:20 -0700 | [diff] [blame] | 4330 | if (display == null) { |
| 4331 | throw new IllegalArgumentException("Invalid display: " + displayId); |
| 4332 | } |
| 4333 | |
| 4334 | final SleepTokenImpl token = new SleepTokenImpl(tag, displayId); |
| 4335 | mSleepTokens.add(token); |
| 4336 | display.mAllSleepTokens.add(token); |
| 4337 | return token; |
| 4338 | } |
| 4339 | |
| 4340 | private void removeSleepTokenLocked(SleepTokenImpl token) { |
| 4341 | mSleepTokens.remove(token); |
| 4342 | |
Riddle Hsu | 86cb7de | 2018-08-13 23:29:58 +0800 | [diff] [blame] | 4343 | final ActivityDisplay display = getActivityDisplay(token.mDisplayId); |
David Stevens | 9440dc8 | 2017-03-16 19:00:20 -0700 | [diff] [blame] | 4344 | if (display != null) { |
| 4345 | display.mAllSleepTokens.remove(token); |
| 4346 | if (display.mAllSleepTokens.isEmpty()) { |
Wale Ogunwale | f673393 | 2018-06-27 05:14:34 -0700 | [diff] [blame] | 4347 | mService.updateSleepIfNeededLocked(); |
David Stevens | 9440dc8 | 2017-03-16 19:00:20 -0700 | [diff] [blame] | 4348 | } |
| 4349 | } |
| 4350 | } |
| 4351 | |
Wale Ogunwale | 6827856 | 2017-09-23 17:13:55 -0700 | [diff] [blame] | 4352 | private StackInfo getStackInfo(ActivityStack stack) { |
Andrii Kulian | 7e215d7 | 2017-04-26 18:33:28 -0700 | [diff] [blame] | 4353 | final int displayId = stack.mDisplayId; |
Riddle Hsu | 86cb7de | 2018-08-13 23:29:58 +0800 | [diff] [blame] | 4354 | final ActivityDisplay display = getActivityDisplay(displayId); |
Craig Mautner | 4a1cb22 | 2013-12-04 16:14:06 -0800 | [diff] [blame] | 4355 | StackInfo info = new StackInfo(); |
Wale Ogunwale | 1666e31 | 2016-12-16 11:27:18 -0800 | [diff] [blame] | 4356 | stack.getWindowContainerBounds(info.bounds); |
Andrii Kulian | 7e215d7 | 2017-04-26 18:33:28 -0700 | [diff] [blame] | 4357 | info.displayId = displayId; |
Craig Mautner | 4a1cb22 | 2013-12-04 16:14:06 -0800 | [diff] [blame] | 4358 | info.stackId = stack.mStackId; |
Filip Gruszczynski | 21199bd | 2015-12-02 12:49:58 -0800 | [diff] [blame] | 4359 | info.userId = stack.mCurrentUser; |
Wale Ogunwale | 9dcf946 | 2017-09-19 15:13:01 -0700 | [diff] [blame] | 4360 | info.visible = stack.shouldBeVisible(null); |
Andrii Kulian | 62e6f25 | 2017-05-30 22:46:53 -0700 | [diff] [blame] | 4361 | // A stack might be not attached to a display. |
Wale Ogunwale | a0f5b5e | 2017-10-11 09:37:23 -0700 | [diff] [blame] | 4362 | info.position = display != null ? display.getIndexOf(stack) : 0; |
Wale Ogunwale | 6827856 | 2017-09-23 17:13:55 -0700 | [diff] [blame] | 4363 | info.configuration.setTo(stack.getConfiguration()); |
Craig Mautner | 4a1cb22 | 2013-12-04 16:14:06 -0800 | [diff] [blame] | 4364 | |
| 4365 | ArrayList<TaskRecord> tasks = stack.getAllTasks(); |
| 4366 | final int numTasks = tasks.size(); |
| 4367 | int[] taskIds = new int[numTasks]; |
| 4368 | String[] taskNames = new String[numTasks]; |
Wale Ogunwale | e4a0c57 | 2015-06-30 08:40:31 -0700 | [diff] [blame] | 4369 | Rect[] taskBounds = new Rect[numTasks]; |
Filip Gruszczynski | 21199bd | 2015-12-02 12:49:58 -0800 | [diff] [blame] | 4370 | int[] taskUserIds = new int[numTasks]; |
Craig Mautner | 4a1cb22 | 2013-12-04 16:14:06 -0800 | [diff] [blame] | 4371 | for (int i = 0; i < numTasks; ++i) { |
| 4372 | final TaskRecord task = tasks.get(i); |
| 4373 | taskIds[i] = task.taskId; |
| 4374 | taskNames[i] = task.origActivity != null ? task.origActivity.flattenToString() |
| 4375 | : task.realActivity != null ? task.realActivity.flattenToString() |
| 4376 | : task.getTopActivity() != null ? task.getTopActivity().packageName |
| 4377 | : "unknown"; |
Wale Ogunwale | e4a0c57 | 2015-06-30 08:40:31 -0700 | [diff] [blame] | 4378 | taskBounds[i] = new Rect(); |
Wale Ogunwale | e1fe7fa2 | 2016-12-15 18:27:00 -0800 | [diff] [blame] | 4379 | task.getWindowContainerBounds(taskBounds[i]); |
Filip Gruszczynski | 21199bd | 2015-12-02 12:49:58 -0800 | [diff] [blame] | 4380 | taskUserIds[i] = task.userId; |
Craig Mautner | 4a1cb22 | 2013-12-04 16:14:06 -0800 | [diff] [blame] | 4381 | } |
| 4382 | info.taskIds = taskIds; |
| 4383 | info.taskNames = taskNames; |
Wale Ogunwale | 868a5e1 | 2015-08-02 16:19:20 -0700 | [diff] [blame] | 4384 | info.taskBounds = taskBounds; |
Filip Gruszczynski | 21199bd | 2015-12-02 12:49:58 -0800 | [diff] [blame] | 4385 | info.taskUserIds = taskUserIds; |
Winson | d46b727 | 2016-04-20 11:54:27 -0700 | [diff] [blame] | 4386 | |
| 4387 | final ActivityRecord top = stack.topRunningActivityLocked(); |
| 4388 | info.topActivity = top != null ? top.intent.getComponent() : null; |
Craig Mautner | 4a1cb22 | 2013-12-04 16:14:06 -0800 | [diff] [blame] | 4389 | return info; |
| 4390 | } |
| 4391 | |
Wale Ogunwale | 6827856 | 2017-09-23 17:13:55 -0700 | [diff] [blame] | 4392 | StackInfo getStackInfo(int stackId) { |
Craig Mautner | 4a1cb22 | 2013-12-04 16:14:06 -0800 | [diff] [blame] | 4393 | ActivityStack stack = getStack(stackId); |
| 4394 | if (stack != null) { |
Wale Ogunwale | 6827856 | 2017-09-23 17:13:55 -0700 | [diff] [blame] | 4395 | return getStackInfo(stack); |
Craig Mautner | 4a1cb22 | 2013-12-04 16:14:06 -0800 | [diff] [blame] | 4396 | } |
| 4397 | return null; |
| 4398 | } |
| 4399 | |
Wale Ogunwale | 6827856 | 2017-09-23 17:13:55 -0700 | [diff] [blame] | 4400 | StackInfo getStackInfo(int windowingMode, int activityType) { |
| 4401 | final ActivityStack stack = getStack(windowingMode, activityType); |
| 4402 | return (stack != null) ? getStackInfo(stack) : null; |
| 4403 | } |
| 4404 | |
Craig Mautner | 4a1cb22 | 2013-12-04 16:14:06 -0800 | [diff] [blame] | 4405 | ArrayList<StackInfo> getAllStackInfosLocked() { |
Wale Ogunwale | e4a0c57 | 2015-06-30 08:40:31 -0700 | [diff] [blame] | 4406 | ArrayList<StackInfo> list = new ArrayList<>(); |
Craig Mautner | e0a3884 | 2013-12-16 16:14:02 -0800 | [diff] [blame] | 4407 | for (int displayNdx = 0; displayNdx < mActivityDisplays.size(); ++displayNdx) { |
Riddle Hsu | 86cb7de | 2018-08-13 23:29:58 +0800 | [diff] [blame] | 4408 | final ActivityDisplay display = mActivityDisplays.get(displayNdx); |
Wale Ogunwale | a0f5b5e | 2017-10-11 09:37:23 -0700 | [diff] [blame] | 4409 | for (int stackNdx = display.getChildCount() - 1; stackNdx >= 0; --stackNdx) { |
| 4410 | final ActivityStack stack = display.getChildAt(stackNdx); |
| 4411 | list.add(getStackInfo(stack)); |
Craig Mautner | 4a1cb22 | 2013-12-04 16:14:06 -0800 | [diff] [blame] | 4412 | } |
| 4413 | } |
| 4414 | return list; |
| 4415 | } |
| 4416 | |
Wale Ogunwale | 0568aed | 2017-09-08 13:29:37 -0700 | [diff] [blame] | 4417 | void handleNonResizableTaskIfNeeded(TaskRecord task, int preferredWindowingMode, |
Wale Ogunwale | a0f5b5e | 2017-10-11 09:37:23 -0700 | [diff] [blame] | 4418 | int preferredDisplayId, ActivityStack actualStack) { |
Wale Ogunwale | 0568aed | 2017-09-08 13:29:37 -0700 | [diff] [blame] | 4419 | handleNonResizableTaskIfNeeded(task, preferredWindowingMode, preferredDisplayId, |
Wale Ogunwale | a0f5b5e | 2017-10-11 09:37:23 -0700 | [diff] [blame] | 4420 | actualStack, false /* forceNonResizable */); |
Andrii Kulian | c2791664 | 2016-04-12 17:59:27 -0700 | [diff] [blame] | 4421 | } |
| 4422 | |
Wale Ogunwale | 0568aed | 2017-09-08 13:29:37 -0700 | [diff] [blame] | 4423 | void handleNonResizableTaskIfNeeded(TaskRecord task, int preferredWindowingMode, |
Wale Ogunwale | a0f5b5e | 2017-10-11 09:37:23 -0700 | [diff] [blame] | 4424 | int preferredDisplayId, ActivityStack actualStack, boolean forceNonResizable) { |
Andrii Kulian | 036e3ad | 2017-04-19 10:55:10 -0700 | [diff] [blame] | 4425 | final boolean isSecondaryDisplayPreferred = |
Wale Ogunwale | 0568aed | 2017-09-08 13:29:37 -0700 | [diff] [blame] | 4426 | (preferredDisplayId != DEFAULT_DISPLAY && preferredDisplayId != INVALID_DISPLAY); |
Wale Ogunwale | 926aade | 2017-08-29 11:24:37 -0700 | [diff] [blame] | 4427 | final boolean inSplitScreenMode = actualStack != null |
Wale Ogunwale | 7e1f5f5 | 2017-10-18 15:19:59 -0700 | [diff] [blame] | 4428 | && actualStack.getDisplay().hasSplitScreenPrimaryStack(); |
Wale Ogunwale | 0568aed | 2017-09-08 13:29:37 -0700 | [diff] [blame] | 4429 | if (((!inSplitScreenMode && preferredWindowingMode != WINDOWING_MODE_SPLIT_SCREEN_PRIMARY) |
Wale Ogunwale | 7e1f5f5 | 2017-10-18 15:19:59 -0700 | [diff] [blame] | 4430 | && !isSecondaryDisplayPreferred) || !task.isActivityTypeStandardOrUndefined()) { |
Wale Ogunwale | b9b16a7 | 2016-01-27 12:24:44 -0800 | [diff] [blame] | 4431 | return; |
| 4432 | } |
| 4433 | |
Andrii Kulian | 036e3ad | 2017-04-19 10:55:10 -0700 | [diff] [blame] | 4434 | // Handle incorrect launch/move to secondary display if needed. |
Andrii Kulian | 036e3ad | 2017-04-19 10:55:10 -0700 | [diff] [blame] | 4435 | if (isSecondaryDisplayPreferred) { |
| 4436 | final int actualDisplayId = task.getStack().mDisplayId; |
| 4437 | if (!task.canBeLaunchedOnDisplay(actualDisplayId)) { |
Andrii Kulian | b850ea5 | 2017-12-12 23:49:10 -0800 | [diff] [blame] | 4438 | throw new IllegalStateException("Task resolved to incompatible display"); |
Andrii Kulian | 036e3ad | 2017-04-19 10:55:10 -0700 | [diff] [blame] | 4439 | } |
Andrii Kulian | b850ea5 | 2017-12-12 23:49:10 -0800 | [diff] [blame] | 4440 | if (preferredDisplayId != actualDisplayId) { |
Riddle Hsu | 1656713 | 2018-08-16 21:37:47 +0800 | [diff] [blame] | 4441 | Slog.w(TAG, "Failed to put " + task + " on display " + preferredDisplayId); |
| 4442 | // Display a warning toast that we failed to put a task on a secondary display. |
Wale Ogunwale | c9e57de | 2018-05-08 14:28:07 -0700 | [diff] [blame] | 4443 | mService.getTaskChangeNotificationController() |
Andrii Kulian | 036e3ad | 2017-04-19 10:55:10 -0700 | [diff] [blame] | 4444 | .notifyActivityLaunchOnSecondaryDisplayFailed(); |
Wale Ogunwale | 2b07da8 | 2017-11-08 14:52:40 -0800 | [diff] [blame] | 4445 | return; |
Riddle Hsu | 1656713 | 2018-08-16 21:37:47 +0800 | [diff] [blame] | 4446 | } else if (!forceNonResizable && handleForcedResizableTask(task, |
| 4447 | FORCED_RESIZEABLE_REASON_SECONDARY_DISPLAY)) { |
| 4448 | return; |
Andrii Kulian | 036e3ad | 2017-04-19 10:55:10 -0700 | [diff] [blame] | 4449 | } |
Wale Ogunwale | 2b07da8 | 2017-11-08 14:52:40 -0800 | [diff] [blame] | 4450 | } |
| 4451 | |
Wale Ogunwale | 2b07da8 | 2017-11-08 14:52:40 -0800 | [diff] [blame] | 4452 | if (!task.supportsSplitScreenWindowingMode() || forceNonResizable) { |
Wale Ogunwale | 30e441d | 2017-11-09 08:28:45 -0800 | [diff] [blame] | 4453 | // Display a warning toast that we tried to put an app that doesn't support split-screen |
| 4454 | // in split-screen. |
Wale Ogunwale | c9e57de | 2018-05-08 14:28:07 -0700 | [diff] [blame] | 4455 | mService.getTaskChangeNotificationController().notifyActivityDismissingDockedStack(); |
Jorim Jaggi | d53f092 | 2016-04-06 22:16:23 -0700 | [diff] [blame] | 4456 | |
Andrii Kulian | c2791664 | 2016-04-12 17:59:27 -0700 | [diff] [blame] | 4457 | // Dismiss docked stack. If task appeared to be in docked stack but is not resizable - |
| 4458 | // we need to move it to top of fullscreen stack, otherwise it will be covered. |
Wale Ogunwale | 04a05ac | 2017-09-17 21:35:02 -0700 | [diff] [blame] | 4459 | |
Wale Ogunwale | 2b07da8 | 2017-11-08 14:52:40 -0800 | [diff] [blame] | 4460 | final ActivityStack dockedStack = |
| 4461 | task.getStack().getDisplay().getSplitScreenPrimaryStack(); |
Wale Ogunwale | 9dcf946 | 2017-09-19 15:13:01 -0700 | [diff] [blame] | 4462 | if (dockedStack != null) { |
Wale Ogunwale | a0f5b5e | 2017-10-11 09:37:23 -0700 | [diff] [blame] | 4463 | moveTasksToFullscreenStackLocked(dockedStack, actualStack == dockedStack); |
Wale Ogunwale | 9dcf946 | 2017-09-19 15:13:01 -0700 | [diff] [blame] | 4464 | } |
Wale Ogunwale | 2b07da8 | 2017-11-08 14:52:40 -0800 | [diff] [blame] | 4465 | return; |
| 4466 | } |
| 4467 | |
Riddle Hsu | 1656713 | 2018-08-16 21:37:47 +0800 | [diff] [blame] | 4468 | handleForcedResizableTask(task, FORCED_RESIZEABLE_REASON_SPLIT_SCREEN); |
| 4469 | } |
| 4470 | |
| 4471 | /** |
| 4472 | * @return {@code true} if the top activity of the task is forced to be resizable and the user |
| 4473 | * was notified about activity being forced resized. |
| 4474 | */ |
| 4475 | private boolean handleForcedResizableTask(TaskRecord task, int reason) { |
Wale Ogunwale | 30e441d | 2017-11-09 08:28:45 -0800 | [diff] [blame] | 4476 | final ActivityRecord topActivity = task.getTopActivity(); |
Wale Ogunwale | 2b07da8 | 2017-11-08 14:52:40 -0800 | [diff] [blame] | 4477 | if (topActivity != null && topActivity.isNonResizableOrForcedResizable() |
Riddle Hsu | 1656713 | 2018-08-16 21:37:47 +0800 | [diff] [blame] | 4478 | && !topActivity.noDisplay) { |
Andrii Kulian | 036e3ad | 2017-04-19 10:55:10 -0700 | [diff] [blame] | 4479 | final String packageName = topActivity.appInfo.packageName; |
Wale Ogunwale | c9e57de | 2018-05-08 14:28:07 -0700 | [diff] [blame] | 4480 | mService.getTaskChangeNotificationController().notifyActivityForcedResizable( |
Andrii Kulian | 036e3ad | 2017-04-19 10:55:10 -0700 | [diff] [blame] | 4481 | task.taskId, reason, packageName); |
Riddle Hsu | 1656713 | 2018-08-16 21:37:47 +0800 | [diff] [blame] | 4482 | return true; |
Wale Ogunwale | b9b16a7 | 2016-01-27 12:24:44 -0800 | [diff] [blame] | 4483 | } |
Riddle Hsu | 1656713 | 2018-08-16 21:37:47 +0800 | [diff] [blame] | 4484 | return false; |
Chong Zhang | b15758a | 2015-11-17 12:12:03 -0800 | [diff] [blame] | 4485 | } |
| 4486 | |
Jorim Jaggi | fe89d12 | 2015-12-22 16:28:44 +0100 | [diff] [blame] | 4487 | void activityRelaunchedLocked(IBinder token) { |
| 4488 | mWindowManager.notifyAppRelaunchingFinished(token); |
David Stevens | 9440dc8 | 2017-03-16 19:00:20 -0700 | [diff] [blame] | 4489 | final ActivityRecord r = ActivityRecord.isInStackLocked(token); |
| 4490 | if (r != null) { |
| 4491 | if (r.getStack().shouldSleepOrShutDownActivities()) { |
Wale Ogunwale | 3e99736 | 2016-09-06 10:37:56 -0700 | [diff] [blame] | 4492 | r.setSleeping(true, true); |
| 4493 | } |
| 4494 | } |
Jorim Jaggi | fe89d12 | 2015-12-22 16:28:44 +0100 | [diff] [blame] | 4495 | } |
| 4496 | |
| 4497 | void activityRelaunchingLocked(ActivityRecord r) { |
| 4498 | mWindowManager.notifyAppRelaunching(r.appToken); |
| 4499 | } |
| 4500 | |
Filip Gruszczynski | 77d9448 | 2015-12-11 13:59:52 -0800 | [diff] [blame] | 4501 | void logStackState() { |
| 4502 | mActivityMetricsLogger.logWindowState(); |
| 4503 | } |
| 4504 | |
Winson Chung | 5af42fc | 2017-03-24 17:11:33 -0700 | [diff] [blame] | 4505 | void scheduleUpdateMultiWindowMode(TaskRecord task) { |
Winson Chung | 8bca9e4 | 2017-04-16 15:59:43 -0700 | [diff] [blame] | 4506 | // If the stack is animating in a way where we will be forcing a multi-mode change at the |
| 4507 | // end, then ensure that we defer all in between multi-window mode changes |
| 4508 | if (task.getStack().deferScheduleMultiWindowModeChanged()) { |
| 4509 | return; |
| 4510 | } |
| 4511 | |
Wale Ogunwale | 22e2526 | 2016-02-01 10:32:02 -0800 | [diff] [blame] | 4512 | for (int i = task.mActivities.size() - 1; i >= 0; i--) { |
| 4513 | final ActivityRecord r = task.mActivities.get(i); |
Wale Ogunwale | 9e4f3e0 | 2018-05-17 09:35:39 -0700 | [diff] [blame] | 4514 | if (r.attachedToProcess()) { |
Wale Ogunwale | 22e2526 | 2016-02-01 10:32:02 -0800 | [diff] [blame] | 4515 | mMultiWindowModeChangedActivities.add(r); |
| 4516 | } |
| 4517 | } |
| 4518 | |
| 4519 | if (!mHandler.hasMessages(REPORT_MULTI_WINDOW_MODE_CHANGED_MSG)) { |
| 4520 | mHandler.sendEmptyMessage(REPORT_MULTI_WINDOW_MODE_CHANGED_MSG); |
| 4521 | } |
| 4522 | } |
| 4523 | |
Winson Chung | 5af42fc | 2017-03-24 17:11:33 -0700 | [diff] [blame] | 4524 | void scheduleUpdatePictureInPictureModeIfNeeded(TaskRecord task, ActivityStack prevStack) { |
Andrii Kulian | 02b7a83 | 2016-10-06 23:11:56 -0700 | [diff] [blame] | 4525 | final ActivityStack stack = task.getStack(); |
Wale Ogunwale | 22e2526 | 2016-02-01 10:32:02 -0800 | [diff] [blame] | 4526 | if (prevStack == null || prevStack == stack |
Wale Ogunwale | 44f036f | 2017-09-29 05:09:09 -0700 | [diff] [blame] | 4527 | || (!prevStack.inPinnedWindowingMode() && !stack.inPinnedWindowingMode())) { |
Wale Ogunwale | 22e2526 | 2016-02-01 10:32:02 -0800 | [diff] [blame] | 4528 | return; |
| 4529 | } |
| 4530 | |
Bryce Lee | f3c6a47 | 2017-11-14 14:53:06 -0800 | [diff] [blame] | 4531 | scheduleUpdatePictureInPictureModeIfNeeded(task, stack.getOverrideBounds()); |
Winson Chung | 5af42fc | 2017-03-24 17:11:33 -0700 | [diff] [blame] | 4532 | } |
Wale Ogunwale | 22e2526 | 2016-02-01 10:32:02 -0800 | [diff] [blame] | 4533 | |
Winson Chung | ab76bbc | 2017-08-14 13:33:51 -0700 | [diff] [blame] | 4534 | void scheduleUpdatePictureInPictureModeIfNeeded(TaskRecord task, Rect targetStackBounds) { |
| 4535 | for (int i = task.mActivities.size() - 1; i >= 0; i--) { |
| 4536 | final ActivityRecord r = task.mActivities.get(i); |
Wale Ogunwale | 9e4f3e0 | 2018-05-17 09:35:39 -0700 | [diff] [blame] | 4537 | if (r.attachedToProcess()) { |
Winson Chung | ab76bbc | 2017-08-14 13:33:51 -0700 | [diff] [blame] | 4538 | mPipModeChangedActivities.add(r); |
Wale Ogunwale | eb76b76 | 2017-11-17 10:08:04 -0800 | [diff] [blame] | 4539 | // If we are scheduling pip change, then remove this activity from multi-window |
| 4540 | // change list as the processing of pip change will make sure multi-window changed |
| 4541 | // message is processed in the right order relative to pip changed. |
| 4542 | mMultiWindowModeChangedActivities.remove(r); |
Winson Chung | 5af42fc | 2017-03-24 17:11:33 -0700 | [diff] [blame] | 4543 | } |
Winson Chung | ab76bbc | 2017-08-14 13:33:51 -0700 | [diff] [blame] | 4544 | } |
| 4545 | mPipModeChangedTargetStackBounds = targetStackBounds; |
Winson Chung | 5af42fc | 2017-03-24 17:11:33 -0700 | [diff] [blame] | 4546 | |
Winson Chung | ab76bbc | 2017-08-14 13:33:51 -0700 | [diff] [blame] | 4547 | if (!mHandler.hasMessages(REPORT_PIP_MODE_CHANGED_MSG)) { |
| 4548 | mHandler.sendEmptyMessage(REPORT_PIP_MODE_CHANGED_MSG); |
| 4549 | } |
| 4550 | } |
| 4551 | |
| 4552 | void updatePictureInPictureMode(TaskRecord task, Rect targetStackBounds, boolean forceUpdate) { |
| 4553 | mHandler.removeMessages(REPORT_PIP_MODE_CHANGED_MSG); |
| 4554 | for (int i = task.mActivities.size() - 1; i >= 0; i--) { |
| 4555 | final ActivityRecord r = task.mActivities.get(i); |
Wale Ogunwale | 9e4f3e0 | 2018-05-17 09:35:39 -0700 | [diff] [blame] | 4556 | if (r.attachedToProcess()) { |
Winson Chung | ab76bbc | 2017-08-14 13:33:51 -0700 | [diff] [blame] | 4557 | r.updatePictureInPictureMode(targetStackBounds, forceUpdate); |
Winson Chung | 5af42fc | 2017-03-24 17:11:33 -0700 | [diff] [blame] | 4558 | } |
Wale Ogunwale | 22e2526 | 2016-02-01 10:32:02 -0800 | [diff] [blame] | 4559 | } |
| 4560 | } |
| 4561 | |
Tony Mak | 853304c | 2016-04-18 15:17:41 +0100 | [diff] [blame] | 4562 | void setDockedStackMinimized(boolean minimized) { |
Andrii Kulian | 52d255c | 2018-07-13 11:32:19 -0700 | [diff] [blame] | 4563 | // Get currently focused stack before setting mIsDockMinimized. We do this because if |
| 4564 | // split-screen is active, primary stack will not be focusable (see #isFocusable) while |
Andrii Kulian | 5f750bc | 2018-07-17 08:57:23 -0700 | [diff] [blame] | 4565 | // still occluding other stacks. This will cause getTopDisplayFocusedStack() to return null. |
| 4566 | final ActivityStack current = getTopDisplayFocusedStack(); |
Tony Mak | 853304c | 2016-04-18 15:17:41 +0100 | [diff] [blame] | 4567 | mIsDockMinimized = minimized; |
Wale Ogunwale | 17696de | 2018-03-15 16:41:05 -0700 | [diff] [blame] | 4568 | if (mIsDockMinimized) { |
Wale Ogunwale | 17696de | 2018-03-15 16:41:05 -0700 | [diff] [blame] | 4569 | if (current.inSplitScreenPrimaryWindowingMode()) { |
| 4570 | // The primary split-screen stack can't be focused while it is minimize, so move |
| 4571 | // focus to something else. |
| 4572 | current.adjustFocusToNextFocusableStack("setDockedStackMinimized"); |
| 4573 | } |
| 4574 | } |
Tony Mak | 853304c | 2016-04-18 15:17:41 +0100 | [diff] [blame] | 4575 | } |
| 4576 | |
chaviw | 59b9885 | 2017-06-13 12:05:44 -0700 | [diff] [blame] | 4577 | void wakeUp(String reason) { |
| 4578 | mPowerManager.wakeUp(SystemClock.uptimeMillis(), "android.server.am:TURN_ON:" + reason); |
| 4579 | } |
| 4580 | |
| 4581 | /** |
| 4582 | * Begin deferring resume to avoid duplicate resumes in one pass. |
| 4583 | */ |
Riddle Hsu | 402b440 | 2018-11-06 17:23:15 +0800 | [diff] [blame] | 4584 | void beginDeferResume() { |
chaviw | 59b9885 | 2017-06-13 12:05:44 -0700 | [diff] [blame] | 4585 | mDeferResumeCount++; |
| 4586 | } |
| 4587 | |
| 4588 | /** |
| 4589 | * End deferring resume and determine if resume can be called. |
| 4590 | */ |
Riddle Hsu | 402b440 | 2018-11-06 17:23:15 +0800 | [diff] [blame] | 4591 | void endDeferResume() { |
chaviw | 59b9885 | 2017-06-13 12:05:44 -0700 | [diff] [blame] | 4592 | mDeferResumeCount--; |
| 4593 | } |
| 4594 | |
| 4595 | /** |
| 4596 | * @return True if resume can be called. |
| 4597 | */ |
| 4598 | private boolean readyToResume() { |
| 4599 | return mDeferResumeCount == 0; |
| 4600 | } |
| 4601 | |
Craig Mautner | ce5f3cb | 2013-04-22 08:58:54 -0700 | [diff] [blame] | 4602 | private final class ActivityStackSupervisorHandler extends Handler { |
Craig Mautner | f333327 | 2013-04-22 10:55:53 -0700 | [diff] [blame] | 4603 | |
Craig Mautner | ce5f3cb | 2013-04-22 08:58:54 -0700 | [diff] [blame] | 4604 | public ActivityStackSupervisorHandler(Looper looper) { |
| 4605 | super(looper); |
| 4606 | } |
| 4607 | |
Winson Chung | 4dabf23 | 2017-01-25 13:25:22 -0800 | [diff] [blame] | 4608 | void activityIdleInternal(ActivityRecord r, boolean processPausingActivities) { |
Wale Ogunwale | c9e57de | 2018-05-08 14:28:07 -0700 | [diff] [blame] | 4609 | synchronized (mService.mGlobalLock) { |
Winson Chung | 4dabf23 | 2017-01-25 13:25:22 -0800 | [diff] [blame] | 4610 | activityIdleInternalLocked(r != null ? r.appToken : null, true /* fromTimeout */, |
| 4611 | processPausingActivities, null); |
Craig Mautner | f333327 | 2013-04-22 10:55:53 -0700 | [diff] [blame] | 4612 | } |
Craig Mautner | 7ea5bd4 | 2013-07-05 15:27:08 -0700 | [diff] [blame] | 4613 | } |
| 4614 | |
Craig Mautner | ce5f3cb | 2013-04-22 08:58:54 -0700 | [diff] [blame] | 4615 | @Override |
| 4616 | public void handleMessage(Message msg) { |
| 4617 | switch (msg.what) { |
Wale Ogunwale | 22e2526 | 2016-02-01 10:32:02 -0800 | [diff] [blame] | 4618 | case REPORT_MULTI_WINDOW_MODE_CHANGED_MSG: { |
Wale Ogunwale | c9e57de | 2018-05-08 14:28:07 -0700 | [diff] [blame] | 4619 | synchronized (mService.mGlobalLock) { |
Wale Ogunwale | 22e2526 | 2016-02-01 10:32:02 -0800 | [diff] [blame] | 4620 | for (int i = mMultiWindowModeChangedActivities.size() - 1; i >= 0; i--) { |
| 4621 | final ActivityRecord r = mMultiWindowModeChangedActivities.remove(i); |
Winson Chung | 5af42fc | 2017-03-24 17:11:33 -0700 | [diff] [blame] | 4622 | r.updateMultiWindowMode(); |
Wale Ogunwale | 22e2526 | 2016-02-01 10:32:02 -0800 | [diff] [blame] | 4623 | } |
| 4624 | } |
| 4625 | } break; |
| 4626 | case REPORT_PIP_MODE_CHANGED_MSG: { |
Wale Ogunwale | c9e57de | 2018-05-08 14:28:07 -0700 | [diff] [blame] | 4627 | synchronized (mService.mGlobalLock) { |
Wale Ogunwale | 22e2526 | 2016-02-01 10:32:02 -0800 | [diff] [blame] | 4628 | for (int i = mPipModeChangedActivities.size() - 1; i >= 0; i--) { |
| 4629 | final ActivityRecord r = mPipModeChangedActivities.remove(i); |
Winson Chung | ab76bbc | 2017-08-14 13:33:51 -0700 | [diff] [blame] | 4630 | r.updatePictureInPictureMode(mPipModeChangedTargetStackBounds, |
| 4631 | false /* forceUpdate */); |
Wale Ogunwale | 22e2526 | 2016-02-01 10:32:02 -0800 | [diff] [blame] | 4632 | } |
| 4633 | } |
| 4634 | } break; |
Craig Mautner | f333327 | 2013-04-22 10:55:53 -0700 | [diff] [blame] | 4635 | case IDLE_TIMEOUT_MSG: { |
Wale Ogunwale | 0fc365c | 2015-05-25 19:35:42 -0700 | [diff] [blame] | 4636 | if (DEBUG_IDLE) Slog.d(TAG_IDLE, |
| 4637 | "handleMessage: IDLE_TIMEOUT_MSG: r=" + msg.obj); |
Craig Mautner | f333327 | 2013-04-22 10:55:53 -0700 | [diff] [blame] | 4638 | // We don't at this point know if the activity is fullscreen, |
| 4639 | // so we need to be conservative and assume it isn't. |
Winson Chung | 4dabf23 | 2017-01-25 13:25:22 -0800 | [diff] [blame] | 4640 | activityIdleInternal((ActivityRecord) msg.obj, |
| 4641 | true /* processPausingActivities */); |
Craig Mautner | f333327 | 2013-04-22 10:55:53 -0700 | [diff] [blame] | 4642 | } break; |
| 4643 | case IDLE_NOW_MSG: { |
Wale Ogunwale | 0fc365c | 2015-05-25 19:35:42 -0700 | [diff] [blame] | 4644 | if (DEBUG_IDLE) Slog.d(TAG_IDLE, "handleMessage: IDLE_NOW_MSG: r=" + msg.obj); |
Winson Chung | 4dabf23 | 2017-01-25 13:25:22 -0800 | [diff] [blame] | 4645 | activityIdleInternal((ActivityRecord) msg.obj, |
| 4646 | false /* processPausingActivities */); |
Craig Mautner | f333327 | 2013-04-22 10:55:53 -0700 | [diff] [blame] | 4647 | } break; |
Craig Mautner | 05d2903 | 2013-05-03 13:40:13 -0700 | [diff] [blame] | 4648 | case RESUME_TOP_ACTIVITY_MSG: { |
Wale Ogunwale | c9e57de | 2018-05-08 14:28:07 -0700 | [diff] [blame] | 4649 | synchronized (mService.mGlobalLock) { |
Andrii Kulian | ab132ee | 2018-07-24 22:10:21 +0800 | [diff] [blame] | 4650 | resumeFocusedStacksTopActivitiesLocked(); |
Craig Mautner | 05d2903 | 2013-05-03 13:40:13 -0700 | [diff] [blame] | 4651 | } |
| 4652 | } break; |
Craig Mautner | 0eea92c | 2013-05-16 13:35:39 -0700 | [diff] [blame] | 4653 | case SLEEP_TIMEOUT_MSG: { |
Wale Ogunwale | c9e57de | 2018-05-08 14:28:07 -0700 | [diff] [blame] | 4654 | synchronized (mService.mGlobalLock) { |
Wale Ogunwale | f673393 | 2018-06-27 05:14:34 -0700 | [diff] [blame] | 4655 | if (mService.isSleepingOrShuttingDownLocked()) { |
Craig Mautner | 0eea92c | 2013-05-16 13:35:39 -0700 | [diff] [blame] | 4656 | Slog.w(TAG, "Sleep timeout! Sleeping now."); |
David Stevens | 9440dc8 | 2017-03-16 19:00:20 -0700 | [diff] [blame] | 4657 | checkReadyForSleepLocked(false /* allowDelay */); |
Craig Mautner | 0eea92c | 2013-05-16 13:35:39 -0700 | [diff] [blame] | 4658 | } |
| 4659 | } |
| 4660 | } break; |
Craig Mautner | 7ea5bd4 | 2013-07-05 15:27:08 -0700 | [diff] [blame] | 4661 | case LAUNCH_TIMEOUT_MSG: { |
Wale Ogunwale | c9e57de | 2018-05-08 14:28:07 -0700 | [diff] [blame] | 4662 | synchronized (mService.mGlobalLock) { |
Craig Mautner | 7ea5bd4 | 2013-07-05 15:27:08 -0700 | [diff] [blame] | 4663 | if (mLaunchingActivity.isHeld()) { |
| 4664 | Slog.w(TAG, "Launch timeout has expired, giving up wake lock!"); |
| 4665 | if (VALIDATE_WAKE_LOCK_CALLER |
| 4666 | && Binder.getCallingUid() != Process.myUid()) { |
| 4667 | throw new IllegalStateException("Calling must be system uid"); |
| 4668 | } |
| 4669 | mLaunchingActivity.release(); |
| 4670 | } |
| 4671 | } |
| 4672 | } break; |
Craig Mautner | bb74246 | 2014-07-07 15:28:55 -0700 | [diff] [blame] | 4673 | case LAUNCH_TASK_BEHIND_COMPLETE: { |
Wale Ogunwale | c9e57de | 2018-05-08 14:28:07 -0700 | [diff] [blame] | 4674 | synchronized (mService.mGlobalLock) { |
Wale Ogunwale | 7d70117 | 2015-03-11 15:36:30 -0700 | [diff] [blame] | 4675 | ActivityRecord r = ActivityRecord.forTokenLocked((IBinder) msg.obj); |
Craig Mautner | bb74246 | 2014-07-07 15:28:55 -0700 | [diff] [blame] | 4676 | if (r != null) { |
| 4677 | handleLaunchTaskBehindCompleteLocked(r); |
| 4678 | } |
| 4679 | } |
| 4680 | } break; |
Chong Zhang | c806d90 | 2015-11-30 09:44:27 -0800 | [diff] [blame] | 4681 | |
Craig Mautner | ce5f3cb | 2013-04-22 08:58:54 -0700 | [diff] [blame] | 4682 | } |
| 4683 | } |
| 4684 | } |
Craig Mautner | ed6649f | 2013-12-02 14:08:25 -0800 | [diff] [blame] | 4685 | |
Filip Gruszczynski | caae14e | 2015-12-16 14:40:04 -0800 | [diff] [blame] | 4686 | ActivityStack findStackBehind(ActivityStack stack) { |
Riddle Hsu | 86cb7de | 2018-08-13 23:29:58 +0800 | [diff] [blame] | 4687 | final ActivityDisplay display = getActivityDisplay(stack.mDisplayId); |
| 4688 | if (display != null) { |
| 4689 | for (int i = display.getChildCount() - 1; i >= 0; i--) { |
| 4690 | if (display.getChildAt(i) == stack && i > 0) { |
| 4691 | return display.getChildAt(i - 1); |
| 4692 | } |
Filip Gruszczynski | caae14e | 2015-12-16 14:40:04 -0800 | [diff] [blame] | 4693 | } |
| 4694 | } |
| 4695 | throw new IllegalStateException("Failed to find a stack behind stack=" + stack |
Wale Ogunwale | a0f5b5e | 2017-10-11 09:37:23 -0700 | [diff] [blame] | 4696 | + " in=" + display); |
Filip Gruszczynski | caae14e | 2015-12-16 14:40:04 -0800 | [diff] [blame] | 4697 | } |
Jorim Jaggi | 0b46f3c | 2016-03-14 12:21:37 +0100 | [diff] [blame] | 4698 | |
Jorim Jaggi | c69bd22 | 2016-03-15 14:38:37 +0100 | [diff] [blame] | 4699 | /** |
| 4700 | * Puts a task into resizing mode during the next app transition. |
| 4701 | * |
Wale Ogunwale | e1fe7fa2 | 2016-12-15 18:27:00 -0800 | [diff] [blame] | 4702 | * @param task The task to put into resizing mode |
Jorim Jaggi | c69bd22 | 2016-03-15 14:38:37 +0100 | [diff] [blame] | 4703 | */ |
Bryce Lee | d3624e1 | 2017-11-30 08:51:45 -0800 | [diff] [blame] | 4704 | void setResizingDuringAnimation(TaskRecord task) { |
Wale Ogunwale | e1fe7fa2 | 2016-12-15 18:27:00 -0800 | [diff] [blame] | 4705 | mResizingTasksDuringAnimation.add(task.taskId); |
| 4706 | task.setTaskDockedResizing(true); |
Jorim Jaggi | c69bd22 | 2016-03-15 14:38:37 +0100 | [diff] [blame] | 4707 | } |
| 4708 | |
Jorim Jaggi | 4d8d32c | 2018-01-19 15:57:41 +0100 | [diff] [blame] | 4709 | int startActivityFromRecents(int callingPid, int callingUid, int taskId, |
| 4710 | SafeActivityOptions options) { |
Wale Ogunwale | dd2ae3d | 2018-02-15 13:58:46 -0800 | [diff] [blame] | 4711 | TaskRecord task = null; |
Jorim Jaggi | 0b46f3c | 2016-03-14 12:21:37 +0100 | [diff] [blame] | 4712 | final String callingPackage; |
| 4713 | final Intent intent; |
| 4714 | final int userId; |
Wale Ogunwale | 0568aed | 2017-09-08 13:29:37 -0700 | [diff] [blame] | 4715 | int activityType = ACTIVITY_TYPE_UNDEFINED; |
| 4716 | int windowingMode = WINDOWING_MODE_UNDEFINED; |
Jorim Jaggi | 4d8d32c | 2018-01-19 15:57:41 +0100 | [diff] [blame] | 4717 | final ActivityOptions activityOptions = options != null |
| 4718 | ? options.getOptions(this) |
| 4719 | : null; |
Wale Ogunwale | 0568aed | 2017-09-08 13:29:37 -0700 | [diff] [blame] | 4720 | if (activityOptions != null) { |
| 4721 | activityType = activityOptions.getLaunchActivityType(); |
| 4722 | windowingMode = activityOptions.getLaunchWindowingMode(); |
| 4723 | } |
| 4724 | if (activityType == ACTIVITY_TYPE_HOME || activityType == ACTIVITY_TYPE_RECENTS) { |
Wale Ogunwale | ab5de37 | 2017-10-18 06:46:31 -0700 | [diff] [blame] | 4725 | throw new IllegalArgumentException("startActivityFromRecents: Task " |
Matthew Ng | ae1ff4f | 2016-11-10 15:49:14 -0800 | [diff] [blame] | 4726 | + taskId + " can't be launch in the home/recents stack."); |
Jorim Jaggi | 0b46f3c | 2016-03-14 12:21:37 +0100 | [diff] [blame] | 4727 | } |
Jorim Jaggi | 3c800a4 | 2016-04-15 19:44:50 -0700 | [diff] [blame] | 4728 | |
Matthew Ng | 606dd80 | 2017-06-05 14:06:32 -0700 | [diff] [blame] | 4729 | mWindowManager.deferSurfaceLayout(); |
| 4730 | try { |
Wale Ogunwale | 0568aed | 2017-09-08 13:29:37 -0700 | [diff] [blame] | 4731 | if (windowingMode == WINDOWING_MODE_SPLIT_SCREEN_PRIMARY) { |
Matthew Ng | 606dd80 | 2017-06-05 14:06:32 -0700 | [diff] [blame] | 4732 | mWindowManager.setDockedStackCreateState( |
Matthew Ng | bf15587 | 2017-10-27 15:24:39 -0700 | [diff] [blame] | 4733 | activityOptions.getSplitScreenCreateMode(), null /* initialBounds */); |
Jorim Jaggi | 3c800a4 | 2016-04-15 19:44:50 -0700 | [diff] [blame] | 4734 | |
Matthew Ng | 606dd80 | 2017-06-05 14:06:32 -0700 | [diff] [blame] | 4735 | // Defer updating the stack in which recents is until the app transition is done, to |
| 4736 | // not run into issues where we still need to draw the task in recents but the |
| 4737 | // docked stack is already created. |
Winson Chung | c167427 | 2018-02-21 10:15:17 -0800 | [diff] [blame] | 4738 | deferUpdateRecentsHomeStackBounds(); |
lumark | 588a3e8 | 2018-07-20 18:53:54 +0800 | [diff] [blame] | 4739 | // TODO(multi-display): currently recents animation only support default display. |
Matthew Ng | 606dd80 | 2017-06-05 14:06:32 -0700 | [diff] [blame] | 4740 | mWindowManager.prepareAppTransition(TRANSIT_DOCK_TASK_FROM_RECENTS, false); |
Jorim Jaggi | 0b46f3c | 2016-03-14 12:21:37 +0100 | [diff] [blame] | 4741 | } |
Jorim Jaggi | 0b46f3c | 2016-03-14 12:21:37 +0100 | [diff] [blame] | 4742 | |
Matthew Ng | 606dd80 | 2017-06-05 14:06:32 -0700 | [diff] [blame] | 4743 | task = anyTaskForIdLocked(taskId, MATCH_TASK_IN_STACKS_OR_RECENT_TASKS_AND_RESTORE, |
Wale Ogunwale | ab5de37 | 2017-10-18 06:46:31 -0700 | [diff] [blame] | 4744 | activityOptions, ON_TOP); |
Matthew Ng | 606dd80 | 2017-06-05 14:06:32 -0700 | [diff] [blame] | 4745 | if (task == null) { |
Winson Chung | c167427 | 2018-02-21 10:15:17 -0800 | [diff] [blame] | 4746 | continueUpdateRecentsHomeStackBounds(); |
Matthew Ng | 606dd80 | 2017-06-05 14:06:32 -0700 | [diff] [blame] | 4747 | mWindowManager.executeAppTransition(); |
| 4748 | throw new IllegalArgumentException( |
Wale Ogunwale | ab5de37 | 2017-10-18 06:46:31 -0700 | [diff] [blame] | 4749 | "startActivityFromRecents: Task " + taskId + " not found."); |
Matthew Ng | 606dd80 | 2017-06-05 14:06:32 -0700 | [diff] [blame] | 4750 | } |
| 4751 | |
Wale Ogunwale | abc44d0 | 2017-11-08 08:58:03 -0800 | [diff] [blame] | 4752 | if (windowingMode != WINDOWING_MODE_SPLIT_SCREEN_PRIMARY) { |
| 4753 | // We always want to return to the home activity instead of the recents activity |
| 4754 | // from whatever is started from the recents activity, so move the home stack |
| 4755 | // forward. |
Louis Chang | bd48dca | 2018-08-29 17:44:34 +0800 | [diff] [blame] | 4756 | // TODO (b/115289124): Multi-display supports for recents. |
| 4757 | getDefaultDisplay().moveHomeStackToFront("startActivityFromRecents"); |
Wale Ogunwale | abc44d0 | 2017-11-08 08:58:03 -0800 | [diff] [blame] | 4758 | } |
Wale Ogunwale | 66e1685 | 2017-10-19 13:35:52 -0700 | [diff] [blame] | 4759 | |
Matthew Ng | 606dd80 | 2017-06-05 14:06:32 -0700 | [diff] [blame] | 4760 | // If the user must confirm credentials (e.g. when first launching a work app and the |
| 4761 | // Work Challenge is present) let startActivityInPackage handle the intercepting. |
Wale Ogunwale | 86b7446 | 2018-07-02 08:42:43 -0700 | [diff] [blame] | 4762 | if (!mService.mAmInternal.shouldConfirmCredentials(task.userId) |
Matthew Ng | 606dd80 | 2017-06-05 14:06:32 -0700 | [diff] [blame] | 4763 | && task.getRootActivity() != null) { |
Bryce Lee | 28d8042 | 2017-07-21 13:25:13 -0700 | [diff] [blame] | 4764 | final ActivityRecord targetActivity = task.getTopActivity(); |
| 4765 | |
Bryce Lee | d3624e1 | 2017-11-30 08:51:45 -0800 | [diff] [blame] | 4766 | sendPowerHintForLaunchStartIfNeeded(true /* forceSend */, targetActivity); |
Igor Murashkin | 212d06c | 2018-10-22 16:34:39 -0700 | [diff] [blame] | 4767 | mActivityMetricsLogger.notifyActivityLaunching(task.intent); |
Jorim Jaggi | 172e99f | 2017-10-20 14:33:18 +0200 | [diff] [blame] | 4768 | try { |
Wale Ogunwale | c9e57de | 2018-05-08 14:28:07 -0700 | [diff] [blame] | 4769 | mService.moveTaskToFrontLocked(task.taskId, 0, options, |
Jorim Jaggi | 172e99f | 2017-10-20 14:33:18 +0200 | [diff] [blame] | 4770 | true /* fromRecents */); |
| 4771 | } finally { |
| 4772 | mActivityMetricsLogger.notifyActivityLaunched(START_TASK_TO_FRONT, |
| 4773 | targetActivity); |
| 4774 | } |
Matthew Ng | 606dd80 | 2017-06-05 14:06:32 -0700 | [diff] [blame] | 4775 | |
Wale Ogunwale | c9e57de | 2018-05-08 14:28:07 -0700 | [diff] [blame] | 4776 | mService.getActivityStartController().postStartActivityProcessingForLastStarter( |
Bryce Lee | d3624e1 | 2017-11-30 08:51:45 -0800 | [diff] [blame] | 4777 | task.getTopActivity(), ActivityManager.START_TASK_TO_FRONT, |
| 4778 | task.getStack()); |
Matthew Ng | 606dd80 | 2017-06-05 14:06:32 -0700 | [diff] [blame] | 4779 | return ActivityManager.START_TASK_TO_FRONT; |
| 4780 | } |
Matthew Ng | 606dd80 | 2017-06-05 14:06:32 -0700 | [diff] [blame] | 4781 | callingPackage = task.mCallingPackage; |
| 4782 | intent = task.intent; |
| 4783 | intent.addFlags(Intent.FLAG_ACTIVITY_LAUNCHED_FROM_HISTORY); |
| 4784 | userId = task.userId; |
Wale Ogunwale | c9e57de | 2018-05-08 14:28:07 -0700 | [diff] [blame] | 4785 | return mService.getActivityStartController().startActivityInPackage( |
Jorim Jaggi | 4d8d32c | 2018-01-19 15:57:41 +0100 | [diff] [blame] | 4786 | task.mCallingUid, callingPid, callingUid, callingPackage, intent, null, null, |
Makoto Onuki | c00ea71 | 2018-04-13 12:06:39 -0700 | [diff] [blame] | 4787 | null, 0, 0, options, userId, task, "startActivityFromRecents", |
Michal Karpinski | 201bc0c | 2018-07-20 15:32:00 +0100 | [diff] [blame] | 4788 | false /* validateIncomingUser */, null /* originatingPendingIntent */); |
Matthew Ng | 606dd80 | 2017-06-05 14:06:32 -0700 | [diff] [blame] | 4789 | } finally { |
Wale Ogunwale | dd2ae3d | 2018-02-15 13:58:46 -0800 | [diff] [blame] | 4790 | if (windowingMode == WINDOWING_MODE_SPLIT_SCREEN_PRIMARY && task != null) { |
| 4791 | // If we are launching the task in the docked stack, put it into resizing mode so |
| 4792 | // the window renders full-screen with the background filling the void. Also only |
| 4793 | // call this at the end to make sure that tasks exists on the window manager side. |
| 4794 | setResizingDuringAnimation(task); |
| 4795 | |
| 4796 | final ActivityDisplay display = task.getStack().getDisplay(); |
| 4797 | final ActivityStack topSecondaryStack = |
| 4798 | display.getTopStackInWindowingMode(WINDOWING_MODE_SPLIT_SCREEN_SECONDARY); |
| 4799 | if (topSecondaryStack.isActivityTypeHome()) { |
Louis Chang | bd48dca | 2018-08-29 17:44:34 +0800 | [diff] [blame] | 4800 | // If the home activity is the top split-screen secondary stack, then the |
Wale Ogunwale | dd2ae3d | 2018-02-15 13:58:46 -0800 | [diff] [blame] | 4801 | // primary split-screen stack is in the minimized mode which means it can't |
| 4802 | // receive input keys, so we should move the focused app to the home app so that |
| 4803 | // window manager can correctly calculate the focus window that can receive |
| 4804 | // input keys. |
Louis Chang | bd48dca | 2018-08-29 17:44:34 +0800 | [diff] [blame] | 4805 | display.moveHomeStackToFront( |
| 4806 | "startActivityFromRecents: homeVisibleInSplitScreen"); |
Winson Chung | c167427 | 2018-02-21 10:15:17 -0800 | [diff] [blame] | 4807 | |
| 4808 | // Immediately update the minimized docked stack mode, the upcoming animation |
| 4809 | // for the docked activity (WMS.overridePendingAppTransitionMultiThumbFuture) |
| 4810 | // will do the animation to the target bounds |
| 4811 | mWindowManager.checkSplitScreenMinimizedChanged(false /* animate */); |
Wale Ogunwale | dd2ae3d | 2018-02-15 13:58:46 -0800 | [diff] [blame] | 4812 | } |
| 4813 | } |
Matthew Ng | 606dd80 | 2017-06-05 14:06:32 -0700 | [diff] [blame] | 4814 | mWindowManager.continueSurfaceLayout(); |
Jorim Jaggi | 0b46f3c | 2016-03-14 12:21:37 +0100 | [diff] [blame] | 4815 | } |
Jorim Jaggi | 0b46f3c | 2016-03-14 12:21:37 +0100 | [diff] [blame] | 4816 | } |
Amith Yamasani | e8222e5 | 2016-04-08 15:28:47 -0700 | [diff] [blame] | 4817 | |
| 4818 | /** |
| 4819 | * @return a list of activities which are the top ones in each visible stack. The first |
| 4820 | * entry will be the focused activity. |
| 4821 | */ |
Andrii Kulian | 0864bbb | 2017-02-16 15:45:58 -0800 | [diff] [blame] | 4822 | List<IBinder> getTopVisibleActivities() { |
| 4823 | final ArrayList<IBinder> topActivityTokens = new ArrayList<>(); |
Andrii Kulian | 5f750bc | 2018-07-17 08:57:23 -0700 | [diff] [blame] | 4824 | final ActivityStack topFocusedStack = getTopDisplayFocusedStack(); |
Andrii Kulian | 0864bbb | 2017-02-16 15:45:58 -0800 | [diff] [blame] | 4825 | // Traverse all displays. |
Robert Carr | 22374c0 | 2017-02-21 13:01:47 -0800 | [diff] [blame] | 4826 | for (int i = mActivityDisplays.size() - 1; i >= 0; i--) { |
Riddle Hsu | 86cb7de | 2018-08-13 23:29:58 +0800 | [diff] [blame] | 4827 | final ActivityDisplay display = mActivityDisplays.get(i); |
Andrii Kulian | 0864bbb | 2017-02-16 15:45:58 -0800 | [diff] [blame] | 4828 | // Traverse all stacks on a display. |
Wale Ogunwale | a0f5b5e | 2017-10-11 09:37:23 -0700 | [diff] [blame] | 4829 | for (int j = display.getChildCount() - 1; j >= 0; --j) { |
| 4830 | final ActivityStack stack = display.getChildAt(j); |
Andrii Kulian | 0864bbb | 2017-02-16 15:45:58 -0800 | [diff] [blame] | 4831 | // Get top activity from a visible stack and add it to the list. |
Wale Ogunwale | 9dcf946 | 2017-09-19 15:13:01 -0700 | [diff] [blame] | 4832 | if (stack.shouldBeVisible(null /* starting */)) { |
Wale Ogunwale | 30e441d | 2017-11-09 08:28:45 -0800 | [diff] [blame] | 4833 | final ActivityRecord top = stack.getTopActivity(); |
Andrii Kulian | 0864bbb | 2017-02-16 15:45:58 -0800 | [diff] [blame] | 4834 | if (top != null) { |
Andrii Kulian | 52d255c | 2018-07-13 11:32:19 -0700 | [diff] [blame] | 4835 | if (stack == topFocusedStack) { |
Andrii Kulian | 0864bbb | 2017-02-16 15:45:58 -0800 | [diff] [blame] | 4836 | topActivityTokens.add(0, top.appToken); |
| 4837 | } else { |
| 4838 | topActivityTokens.add(top.appToken); |
| 4839 | } |
Amith Yamasani | e8222e5 | 2016-04-08 15:28:47 -0700 | [diff] [blame] | 4840 | } |
| 4841 | } |
| 4842 | } |
| 4843 | } |
| 4844 | return topActivityTokens; |
| 4845 | } |
Bryce Lee | 4a19438 | 2017-04-04 14:32:48 -0700 | [diff] [blame] | 4846 | |
| 4847 | /** |
| 4848 | * Internal container to store a match qualifier alongside a WaitResult. |
| 4849 | */ |
| 4850 | static class WaitInfo { |
| 4851 | private final ComponentName mTargetComponent; |
| 4852 | private final WaitResult mResult; |
Vishnu Nair | 132ee83 | 2018-09-28 15:00:05 -0700 | [diff] [blame] | 4853 | /** Time stamp when we started to wait for {@link WaitResult}. */ |
| 4854 | private final long mStartTimeMs; |
Bryce Lee | 4a19438 | 2017-04-04 14:32:48 -0700 | [diff] [blame] | 4855 | |
Vishnu Nair | 132ee83 | 2018-09-28 15:00:05 -0700 | [diff] [blame] | 4856 | WaitInfo(ComponentName targetComponent, WaitResult result, long startTimeMs) { |
Bryce Lee | 4a19438 | 2017-04-04 14:32:48 -0700 | [diff] [blame] | 4857 | this.mTargetComponent = targetComponent; |
| 4858 | this.mResult = result; |
Vishnu Nair | 132ee83 | 2018-09-28 15:00:05 -0700 | [diff] [blame] | 4859 | this.mStartTimeMs = startTimeMs; |
Bryce Lee | 4a19438 | 2017-04-04 14:32:48 -0700 | [diff] [blame] | 4860 | } |
| 4861 | |
Wale Ogunwale | 3270f17 | 2017-04-26 07:29:42 -0700 | [diff] [blame] | 4862 | public boolean matches(ComponentName targetComponent) { |
| 4863 | return mTargetComponent == null || mTargetComponent.equals(targetComponent); |
Bryce Lee | 4a19438 | 2017-04-04 14:32:48 -0700 | [diff] [blame] | 4864 | } |
| 4865 | |
| 4866 | public WaitResult getResult() { |
| 4867 | return mResult; |
| 4868 | } |
| 4869 | |
Vishnu Nair | 132ee83 | 2018-09-28 15:00:05 -0700 | [diff] [blame] | 4870 | public long getStartTime() { |
| 4871 | return mStartTimeMs; |
| 4872 | } |
| 4873 | |
Bryce Lee | 4a19438 | 2017-04-04 14:32:48 -0700 | [diff] [blame] | 4874 | public ComponentName getComponent() { |
| 4875 | return mTargetComponent; |
| 4876 | } |
| 4877 | |
| 4878 | public void dump(PrintWriter pw, String prefix) { |
| 4879 | pw.println(prefix + "WaitInfo:"); |
| 4880 | pw.println(prefix + " mTargetComponent=" + mTargetComponent); |
| 4881 | pw.println(prefix + " mResult="); |
| 4882 | mResult.dump(pw, prefix); |
| 4883 | } |
| 4884 | } |
David Stevens | 9440dc8 | 2017-03-16 19:00:20 -0700 | [diff] [blame] | 4885 | |
| 4886 | private final class SleepTokenImpl extends SleepToken { |
| 4887 | private final String mTag; |
| 4888 | private final long mAcquireTime; |
| 4889 | private final int mDisplayId; |
| 4890 | |
| 4891 | public SleepTokenImpl(String tag, int displayId) { |
| 4892 | mTag = tag; |
| 4893 | mDisplayId = displayId; |
| 4894 | mAcquireTime = SystemClock.uptimeMillis(); |
| 4895 | } |
| 4896 | |
| 4897 | @Override |
| 4898 | public void release() { |
Wale Ogunwale | c9e57de | 2018-05-08 14:28:07 -0700 | [diff] [blame] | 4899 | synchronized (mService.mGlobalLock) { |
David Stevens | 9440dc8 | 2017-03-16 19:00:20 -0700 | [diff] [blame] | 4900 | removeSleepTokenLocked(this); |
| 4901 | } |
| 4902 | } |
| 4903 | |
| 4904 | @Override |
| 4905 | public String toString() { |
| 4906 | return "{\"" + mTag + "\", display " + mDisplayId |
| 4907 | + ", acquire at " + TimeUtils.formatUptime(mAcquireTime) + "}"; |
| 4908 | } |
| 4909 | } |
| 4910 | |
Craig Mautner | 2708430 | 2013-03-25 08:05:25 -0700 | [diff] [blame] | 4911 | } |