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 | |
| 17 | package com.android.server.am; |
| 18 | |
Andrii Kulian | 3c9ad07 | 2017-08-01 11:45:22 -0700 | [diff] [blame] | 19 | import static android.Manifest.permission.ACTIVITY_EMBEDDING; |
Jorim Jaggi | 33a701a | 2017-12-01 14:58:18 +0100 | [diff] [blame] | 20 | import static android.Manifest.permission.CONTROL_REMOTE_APP_TRANSITION_ANIMATIONS; |
Andrii Kulian | 3a95edc | 2017-06-28 16:21:07 -0700 | [diff] [blame] | 21 | import static android.Manifest.permission.INTERNAL_SYSTEM_WINDOW; |
Jorim Jaggi | fe76234 | 2016-10-13 14:33:27 +0200 | [diff] [blame] | 22 | import static android.Manifest.permission.START_ANY_ACTIVITY; |
| 23 | import static android.Manifest.permission.START_TASKS_FROM_RECENTS; |
Charles He | ff9b4dff | 2017-09-22 10:18:37 +0100 | [diff] [blame] | 24 | import static android.app.ActivityManager.LOCK_TASK_MODE_LOCKED; |
Bryce Lee | 5f0e28f | 2018-01-30 16:00:03 -0800 | [diff] [blame] | 25 | import static android.app.ActivityManager.START_DELIVERED_TO_TOP; |
Jorim Jaggi | fe76234 | 2016-10-13 14:33:27 +0200 | [diff] [blame] | 26 | import static android.app.ActivityManager.START_TASK_TO_FRONT; |
Jorim Jaggi | fe76234 | 2016-10-13 14:33:27 +0200 | [diff] [blame] | 27 | import static android.app.ActivityManager.StackId.INVALID_STACK_ID; |
Andrii Kulian | 036e3ad | 2017-04-19 10:55:10 -0700 | [diff] [blame] | 28 | import static android.app.ITaskStackListener.FORCED_RESIZEABLE_REASON_SECONDARY_DISPLAY; |
| 29 | import static android.app.ITaskStackListener.FORCED_RESIZEABLE_REASON_SPLIT_SCREEN; |
Wale Ogunwale | 6827856 | 2017-09-23 17:13:55 -0700 | [diff] [blame] | 30 | import static android.app.WindowConfiguration.ACTIVITY_TYPE_ASSISTANT; |
Wale Ogunwale | 6fbde9f | 2017-08-24 07:24:12 -0700 | [diff] [blame] | 31 | import static android.app.WindowConfiguration.ACTIVITY_TYPE_HOME; |
Wale Ogunwale | 0568aed | 2017-09-08 13:29:37 -0700 | [diff] [blame] | 32 | import static android.app.WindowConfiguration.ACTIVITY_TYPE_RECENTS; |
Wale Ogunwale | 6fbde9f | 2017-08-24 07:24:12 -0700 | [diff] [blame] | 33 | import static android.app.WindowConfiguration.ACTIVITY_TYPE_STANDARD; |
| 34 | import static android.app.WindowConfiguration.ACTIVITY_TYPE_UNDEFINED; |
Wale Ogunwale | 0568aed | 2017-09-08 13:29:37 -0700 | [diff] [blame] | 35 | import static android.app.WindowConfiguration.WINDOWING_MODE_FREEFORM; |
Wale Ogunwale | 926aade | 2017-08-29 11:24:37 -0700 | [diff] [blame] | 36 | import static android.app.WindowConfiguration.WINDOWING_MODE_FULLSCREEN; |
Wale Ogunwale | 44f036f | 2017-09-29 05:09:09 -0700 | [diff] [blame] | 37 | import static android.app.WindowConfiguration.WINDOWING_MODE_FULLSCREEN_OR_SPLIT_SCREEN_SECONDARY; |
Wale Ogunwale | 0568aed | 2017-09-08 13:29:37 -0700 | [diff] [blame] | 38 | import static android.app.WindowConfiguration.WINDOWING_MODE_PINNED; |
| 39 | import static android.app.WindowConfiguration.WINDOWING_MODE_SPLIT_SCREEN_PRIMARY; |
Wale Ogunwale | 926aade | 2017-08-29 11:24:37 -0700 | [diff] [blame] | 40 | import static android.app.WindowConfiguration.WINDOWING_MODE_SPLIT_SCREEN_SECONDARY; |
Wale Ogunwale | 0568aed | 2017-09-08 13:29:37 -0700 | [diff] [blame] | 41 | import static android.app.WindowConfiguration.WINDOWING_MODE_UNDEFINED; |
Wale Ogunwale | 44f036f | 2017-09-29 05:09:09 -0700 | [diff] [blame] | 42 | import static android.app.WindowConfiguration.activityTypeToString; |
| 43 | import static android.app.WindowConfiguration.windowingModeToString; |
Andrii Kulian | 3c9ad07 | 2017-08-01 11:45:22 -0700 | [diff] [blame] | 44 | import static android.content.pm.PackageManager.PERMISSION_DENIED; |
Jorim Jaggi | fe76234 | 2016-10-13 14:33:27 +0200 | [diff] [blame] | 45 | import static android.content.pm.PackageManager.PERMISSION_GRANTED; |
chaviw | 59b9885 | 2017-06-13 12:05:44 -0700 | [diff] [blame] | 46 | import static android.os.PowerManager.PARTIAL_WAKE_LOCK; |
Benjamin Franz | a83859f | 2017-07-03 16:34:14 +0100 | [diff] [blame] | 47 | import static android.os.Process.SYSTEM_UID; |
Jorim Jaggi | fe76234 | 2016-10-13 14:33:27 +0200 | [diff] [blame] | 48 | import static android.os.Trace.TRACE_TAG_ACTIVITY_MANAGER; |
| 49 | import static android.view.Display.DEFAULT_DISPLAY; |
Andrii Kulian | 16802aa | 2016-11-02 12:21:33 -0700 | [diff] [blame] | 50 | import static android.view.Display.INVALID_DISPLAY; |
Andrii Kulian | 1cba31c | 2017-06-28 09:42:48 -0700 | [diff] [blame] | 51 | import static android.view.Display.TYPE_VIRTUAL; |
Winson Chung | 1dbc811 | 2017-09-28 18:05:31 -0700 | [diff] [blame] | 52 | |
Winson Chung | 4790065 | 2017-04-06 18:44:25 -0700 | [diff] [blame] | 53 | import static com.android.internal.logging.nano.MetricsProto.MetricsEvent.ACTION_PICTURE_IN_PICTURE_EXPANDED_TO_FULLSCREEN; |
Jorim Jaggi | fe76234 | 2016-10-13 14:33:27 +0200 | [diff] [blame] | 54 | import static com.android.server.am.ActivityManagerDebugConfig.DEBUG_ALL; |
Jorim Jaggi | fe76234 | 2016-10-13 14:33:27 +0200 | [diff] [blame] | 55 | import static com.android.server.am.ActivityManagerDebugConfig.DEBUG_FOCUS; |
| 56 | import static com.android.server.am.ActivityManagerDebugConfig.DEBUG_IDLE; |
Jorim Jaggi | fe76234 | 2016-10-13 14:33:27 +0200 | [diff] [blame] | 57 | import static com.android.server.am.ActivityManagerDebugConfig.DEBUG_PAUSE; |
| 58 | import static com.android.server.am.ActivityManagerDebugConfig.DEBUG_RECENTS; |
| 59 | import static com.android.server.am.ActivityManagerDebugConfig.DEBUG_RELEASE; |
| 60 | import static com.android.server.am.ActivityManagerDebugConfig.DEBUG_STACK; |
| 61 | import static com.android.server.am.ActivityManagerDebugConfig.DEBUG_STATES; |
| 62 | import static com.android.server.am.ActivityManagerDebugConfig.DEBUG_SWITCH; |
| 63 | import static com.android.server.am.ActivityManagerDebugConfig.DEBUG_TASKS; |
Jorim Jaggi | fe76234 | 2016-10-13 14:33:27 +0200 | [diff] [blame] | 64 | import static com.android.server.am.ActivityManagerDebugConfig.POSTFIX_FOCUS; |
| 65 | import static com.android.server.am.ActivityManagerDebugConfig.POSTFIX_IDLE; |
Jorim Jaggi | fe76234 | 2016-10-13 14:33:27 +0200 | [diff] [blame] | 66 | import static com.android.server.am.ActivityManagerDebugConfig.POSTFIX_PAUSE; |
| 67 | import static com.android.server.am.ActivityManagerDebugConfig.POSTFIX_RECENTS; |
| 68 | import static com.android.server.am.ActivityManagerDebugConfig.POSTFIX_RELEASE; |
| 69 | import static com.android.server.am.ActivityManagerDebugConfig.POSTFIX_STACK; |
| 70 | import static com.android.server.am.ActivityManagerDebugConfig.POSTFIX_STATES; |
| 71 | import static com.android.server.am.ActivityManagerDebugConfig.POSTFIX_SWITCH; |
| 72 | import static com.android.server.am.ActivityManagerDebugConfig.POSTFIX_TASKS; |
Jorim Jaggi | fe76234 | 2016-10-13 14:33:27 +0200 | [diff] [blame] | 73 | import static com.android.server.am.ActivityManagerDebugConfig.TAG_AM; |
| 74 | import static com.android.server.am.ActivityManagerDebugConfig.TAG_WITH_CLASS_NAME; |
| 75 | import static com.android.server.am.ActivityManagerService.ANIMATE; |
| 76 | import static com.android.server.am.ActivityManagerService.FIRST_SUPERVISOR_STACK_MSG; |
Jorim Jaggi | fe76234 | 2016-10-13 14:33:27 +0200 | [diff] [blame] | 77 | import static com.android.server.am.ActivityStack.ActivityState.DESTROYED; |
| 78 | import static com.android.server.am.ActivityStack.ActivityState.DESTROYING; |
| 79 | import static com.android.server.am.ActivityStack.ActivityState.INITIALIZING; |
| 80 | import static com.android.server.am.ActivityStack.ActivityState.PAUSED; |
| 81 | import static com.android.server.am.ActivityStack.ActivityState.PAUSING; |
| 82 | import static com.android.server.am.ActivityStack.ActivityState.RESUMED; |
| 83 | import static com.android.server.am.ActivityStack.ActivityState.STOPPED; |
| 84 | import static com.android.server.am.ActivityStack.ActivityState.STOPPING; |
| 85 | import static com.android.server.am.ActivityStack.REMOVE_TASK_MODE_MOVING; |
Wale Ogunwale | 0568aed | 2017-09-08 13:29:37 -0700 | [diff] [blame] | 86 | import static com.android.server.am.TaskRecord.INVALID_TASK_ID; |
Jorim Jaggi | fe76234 | 2016-10-13 14:33:27 +0200 | [diff] [blame] | 87 | import static com.android.server.am.TaskRecord.LOCK_TASK_AUTH_LAUNCHABLE; |
| 88 | import static com.android.server.am.TaskRecord.LOCK_TASK_AUTH_LAUNCHABLE_PRIV; |
Charles He | ff9b4dff | 2017-09-22 10:18:37 +0100 | [diff] [blame] | 89 | import static com.android.server.am.TaskRecord.LOCK_TASK_AUTH_WHITELISTED; |
Winson Chung | 7466610 | 2017-02-22 17:49:24 -0800 | [diff] [blame] | 90 | import static com.android.server.am.TaskRecord.REPARENT_KEEP_STACK_AT_FRONT; |
| 91 | import static com.android.server.am.TaskRecord.REPARENT_LEAVE_STACK_IN_PLACE; |
| 92 | import static com.android.server.am.TaskRecord.REPARENT_MOVE_STACK_TO_FRONT; |
Winson Chung | 1dbc811 | 2017-09-28 18:05:31 -0700 | [diff] [blame] | 93 | import static com.android.server.am.proto.ActivityStackSupervisorProto.CONFIGURATION_CONTAINER; |
Steven Timotius | 4346f0a | 2017-09-12 11:07:21 -0700 | [diff] [blame] | 94 | import static com.android.server.am.proto.ActivityStackSupervisorProto.DISPLAYS; |
| 95 | import static com.android.server.am.proto.ActivityStackSupervisorProto.FOCUSED_STACK_ID; |
| 96 | import static com.android.server.am.proto.ActivityStackSupervisorProto.KEYGUARD_CONTROLLER; |
| 97 | import static com.android.server.am.proto.ActivityStackSupervisorProto.RESUMED_ACTIVITY; |
Jorim Jaggi | f84e2f6 | 2018-01-16 14:17:59 +0100 | [diff] [blame] | 98 | import static android.view.WindowManager.TRANSIT_DOCK_TASK_FROM_RECENTS; |
Winson Chung | 1dbc811 | 2017-09-28 18:05:31 -0700 | [diff] [blame] | 99 | |
Wale Ogunwale | e1fe7fa2 | 2016-12-15 18:27:00 -0800 | [diff] [blame] | 100 | import static java.lang.Integer.MAX_VALUE; |
Jorim Jaggi | fe76234 | 2016-10-13 14:33:27 +0200 | [diff] [blame] | 101 | |
Svetoslav | 7008b51 | 2015-06-24 18:47:07 -0700 | [diff] [blame] | 102 | import android.Manifest; |
Winson Chung | 7900bee | 2017-03-10 08:59:25 -0800 | [diff] [blame] | 103 | import android.annotation.IntDef; |
Andrii Kulian | 16802aa | 2016-11-02 12:21:33 -0700 | [diff] [blame] | 104 | import android.annotation.NonNull; |
Wale Ogunwale | 0568aed | 2017-09-08 13:29:37 -0700 | [diff] [blame] | 105 | import android.annotation.Nullable; |
Tony Mak | 853304c | 2016-04-18 15:17:41 +0100 | [diff] [blame] | 106 | import android.annotation.UserIdInt; |
Craig Mautner | 2420ead | 2013-04-01 17:13:20 -0700 | [diff] [blame] | 107 | import android.app.Activity; |
Craig Mautner | 23ac33b | 2013-04-01 16:26:35 -0700 | [diff] [blame] | 108 | import android.app.ActivityManager; |
Filip Gruszczynski | 80e29f1 | 2015-12-14 14:58:30 -0800 | [diff] [blame] | 109 | import android.app.ActivityManager.RunningTaskInfo; |
Craig Mautner | ed6649f | 2013-12-02 14:08:25 -0800 | [diff] [blame] | 110 | import android.app.ActivityManager.StackInfo; |
David Stevens | 9440dc8 | 2017-03-16 19:00:20 -0700 | [diff] [blame] | 111 | import android.app.ActivityManagerInternal.SleepToken; |
Craig Mautner | 23ac33b | 2013-04-01 16:26:35 -0700 | [diff] [blame] | 112 | import android.app.ActivityOptions; |
Svetoslav | 7008b51 | 2015-06-24 18:47:07 -0700 | [diff] [blame] | 113 | import android.app.AppOpsManager; |
Jeff Hao | 1b012d3 | 2014-08-20 10:35:34 -0700 | [diff] [blame] | 114 | import android.app.ProfilerInfo; |
Craig Mautner | 2420ead | 2013-04-01 17:13:20 -0700 | [diff] [blame] | 115 | import android.app.ResultInfo; |
Sudheer Shanka | fc46e9b | 2016-10-21 17:55:27 -0700 | [diff] [blame] | 116 | import android.app.WaitResult; |
Winson Chung | 61c9e5a | 2017-10-11 10:39:32 -0700 | [diff] [blame] | 117 | import android.app.WindowConfiguration.ActivityType; |
| 118 | import android.app.WindowConfiguration.WindowingMode; |
Andrii Kulian | 88e05cb | 2017-12-05 17:21:10 -0800 | [diff] [blame] | 119 | import android.app.servertransaction.ActivityLifecycleItem; |
| 120 | import android.app.servertransaction.ClientTransaction; |
Andrii Kulian | 446e824 | 2017-10-26 15:17:29 -0700 | [diff] [blame] | 121 | import android.app.servertransaction.LaunchActivityItem; |
Andrii Kulian | 88e05cb | 2017-12-05 17:21:10 -0800 | [diff] [blame] | 122 | import android.app.servertransaction.PauseActivityItem; |
| 123 | import android.app.servertransaction.ResumeActivityItem; |
Craig Mautner | 23ac33b | 2013-04-01 16:26:35 -0700 | [diff] [blame] | 124 | import android.content.ComponentName; |
Craig Mautner | 2219a1b | 2013-03-25 09:44:30 -0700 | [diff] [blame] | 125 | import android.content.Context; |
| 126 | import android.content.Intent; |
| 127 | import android.content.pm.ActivityInfo; |
Craig Mautner | 23ac33b | 2013-04-01 16:26:35 -0700 | [diff] [blame] | 128 | import android.content.pm.ApplicationInfo; |
Svetoslav | 7008b51 | 2015-06-24 18:47:07 -0700 | [diff] [blame] | 129 | import android.content.pm.PackageInfo; |
Craig Mautner | 23ac33b | 2013-04-01 16:26:35 -0700 | [diff] [blame] | 130 | import android.content.pm.PackageManager; |
| 131 | import android.content.pm.ResolveInfo; |
Clara Bayarri | f7fea16 | 2015-10-22 16:09:52 +0100 | [diff] [blame] | 132 | import android.content.pm.UserInfo; |
Craig Mautner | 23ac33b | 2013-04-01 16:26:35 -0700 | [diff] [blame] | 133 | import android.content.res.Configuration; |
Wale Ogunwale | 60454db | 2015-01-23 16:05:07 -0800 | [diff] [blame] | 134 | import android.graphics.Rect; |
Craig Mautner | 4a1cb22 | 2013-12-04 16:14:06 -0800 | [diff] [blame] | 135 | import android.hardware.display.DisplayManager; |
| 136 | import android.hardware.display.DisplayManager.DisplayListener; |
Andrii Kulian | fb1bf69 | 2017-01-17 11:17:34 -0800 | [diff] [blame] | 137 | import android.hardware.display.DisplayManagerInternal; |
Bryce Lee | d3624e1 | 2017-11-30 08:51:45 -0800 | [diff] [blame] | 138 | import android.hardware.power.V1_0.PowerHint; |
Craig Mautner | 23ac33b | 2013-04-01 16:26:35 -0700 | [diff] [blame] | 139 | import android.os.Binder; |
Jorim Jaggi | 0b46f3c | 2016-03-14 12:21:37 +0100 | [diff] [blame] | 140 | import android.os.Bundle; |
Craig Mautner | b59dcfd | 2013-05-06 13:12:58 -0700 | [diff] [blame] | 141 | import android.os.Debug; |
Craig Mautner | ce5f3cb | 2013-04-22 08:58:54 -0700 | [diff] [blame] | 142 | import android.os.Handler; |
Craig Mautner | 23ac33b | 2013-04-01 16:26:35 -0700 | [diff] [blame] | 143 | import android.os.IBinder; |
Craig Mautner | 2219a1b | 2013-03-25 09:44:30 -0700 | [diff] [blame] | 144 | import android.os.Looper; |
Craig Mautner | 2420ead | 2013-04-01 17:13:20 -0700 | [diff] [blame] | 145 | import android.os.Message; |
Craig Mautner | 0eea92c | 2013-05-16 13:35:39 -0700 | [diff] [blame] | 146 | import android.os.PowerManager; |
Craig Mautner | 7ea5bd4 | 2013-07-05 15:27:08 -0700 | [diff] [blame] | 147 | import android.os.Process; |
Craig Mautner | 8d341ef | 2013-03-26 09:03:27 -0700 | [diff] [blame] | 148 | import android.os.RemoteException; |
Craig Mautner | 23ac33b | 2013-04-01 16:26:35 -0700 | [diff] [blame] | 149 | import android.os.SystemClock; |
Wale Ogunwale | cad05a0 | 2015-09-25 10:41:44 -0700 | [diff] [blame] | 150 | import android.os.Trace; |
Craig Mautner | 6170f73 | 2013-04-02 13:05:23 -0700 | [diff] [blame] | 151 | import android.os.UserHandle; |
Clara Bayarri | f7fea16 | 2015-10-22 16:09:52 +0100 | [diff] [blame] | 152 | import android.os.UserManager; |
Dianne Hackborn | 3d07c94 | 2015-03-13 18:02:54 -0700 | [diff] [blame] | 153 | import android.os.WorkSource; |
Svetoslav | 7008b51 | 2015-06-24 18:47:07 -0700 | [diff] [blame] | 154 | import android.provider.MediaStore; |
Dianne Hackborn | 91097de | 2014-04-04 18:02:06 -0700 | [diff] [blame] | 155 | import android.service.voice.IVoiceInteractionSession; |
Svetoslav | 7008b51 | 2015-06-24 18:47:07 -0700 | [diff] [blame] | 156 | import android.util.ArrayMap; |
Dianne Hackborn | 89ad456 | 2014-08-24 16:45:38 -0700 | [diff] [blame] | 157 | import android.util.ArraySet; |
Craig Mautner | 2420ead | 2013-04-01 17:13:20 -0700 | [diff] [blame] | 158 | import android.util.EventLog; |
Andrii Kulian | fb1bf69 | 2017-01-17 11:17:34 -0800 | [diff] [blame] | 159 | import android.util.IntArray; |
Wale Ogunwale | e610d3d | 2017-04-25 10:23:48 -0700 | [diff] [blame] | 160 | import android.util.MergedConfiguration; |
Craig Mautner | 8d341ef | 2013-03-26 09:03:27 -0700 | [diff] [blame] | 161 | import android.util.Slog; |
Craig Mautner | 4a1cb22 | 2013-12-04 16:14:06 -0800 | [diff] [blame] | 162 | import android.util.SparseArray; |
Craig Mautner | 4a1cb22 | 2013-12-04 16:14:06 -0800 | [diff] [blame] | 163 | import android.util.SparseIntArray; |
David Stevens | 9440dc8 | 2017-03-16 19:00:20 -0700 | [diff] [blame] | 164 | import android.util.TimeUtils; |
Steven Timotius | 4346f0a | 2017-09-12 11:07:21 -0700 | [diff] [blame] | 165 | import android.util.proto.ProtoOutputStream; |
Craig Mautner | ed6649f | 2013-12-02 14:08:25 -0800 | [diff] [blame] | 166 | import android.view.Display; |
Jorim Jaggi | 33a701a | 2017-12-01 14:58:18 +0100 | [diff] [blame] | 167 | import android.view.RemoteAnimationAdapter; |
Chong Zhang | b15758a | 2015-11-17 12:12:03 -0800 | [diff] [blame] | 168 | |
Andreas Gampe | a36dc62 | 2018-02-05 17:19:22 -0800 | [diff] [blame] | 169 | import com.android.internal.annotations.GuardedBy; |
Andrii Kulian | 94e82d9b0 | 2017-07-13 15:33:06 -0700 | [diff] [blame] | 170 | import com.android.internal.annotations.VisibleForTesting; |
Dianne Hackborn | 85d558c | 2014-11-04 10:31:54 -0800 | [diff] [blame] | 171 | import com.android.internal.content.ReferrerIntent; |
Chenjie Yu | 52cacc6 | 2017-12-08 18:11:45 -0800 | [diff] [blame] | 172 | import com.android.internal.os.logging.MetricsLoggerWrapper; |
Dianne Hackborn | cbfd23e | 2013-06-11 14:26:53 -0700 | [diff] [blame] | 173 | import com.android.internal.os.TransferPipe; |
Svetoslav | 7008b51 | 2015-06-24 18:47:07 -0700 | [diff] [blame] | 174 | import com.android.internal.util.ArrayUtils; |
Jeff Brown | ca9bc70 | 2014-02-11 14:32:56 -0800 | [diff] [blame] | 175 | import com.android.server.LocalServices; |
Craig Mautner | 2420ead | 2013-04-01 17:13:20 -0700 | [diff] [blame] | 176 | import com.android.server.am.ActivityStack.ActivityState; |
Wale Ogunwale | 98d6231 | 2017-07-12 09:24:56 -0700 | [diff] [blame] | 177 | import com.android.server.wm.ConfigurationContainer; |
Winson Chung | 19953ca | 2017-04-11 11:19:23 -0700 | [diff] [blame] | 178 | import com.android.server.wm.PinnedStackWindowController; |
Craig Mautner | ce5f3cb | 2013-04-22 08:58:54 -0700 | [diff] [blame] | 179 | import com.android.server.wm.WindowManagerService; |
Craig Mautner | 23ac33b | 2013-04-01 16:26:35 -0700 | [diff] [blame] | 180 | |
Craig Mautner | 8d341ef | 2013-03-26 09:03:27 -0700 | [diff] [blame] | 181 | import java.io.FileDescriptor; |
| 182 | import java.io.IOException; |
Craig Mautner | 2708430 | 2013-03-25 08:05:25 -0700 | [diff] [blame] | 183 | import java.io.PrintWriter; |
Winson Chung | 7900bee | 2017-03-10 08:59:25 -0800 | [diff] [blame] | 184 | import java.lang.annotation.Retention; |
| 185 | import java.lang.annotation.RetentionPolicy; |
Craig Mautner | 2219a1b | 2013-03-25 09:44:30 -0700 | [diff] [blame] | 186 | import java.util.ArrayList; |
David Stevens | 9440dc8 | 2017-03-16 19:00:20 -0700 | [diff] [blame] | 187 | import java.util.Iterator; |
Craig Mautner | 8d341ef | 2013-03-26 09:03:27 -0700 | [diff] [blame] | 188 | import java.util.List; |
Wale Ogunwale | 540e123 | 2015-05-01 15:35:39 -0700 | [diff] [blame] | 189 | import java.util.Set; |
Craig Mautner | 2708430 | 2013-03-25 08:05:25 -0700 | [diff] [blame] | 190 | |
Winson Chung | 1dbc811 | 2017-09-28 18:05:31 -0700 | [diff] [blame] | 191 | public class ActivityStackSupervisor extends ConfigurationContainer implements DisplayListener, |
| 192 | RecentTasks.Callbacks { |
Wale Ogunwale | e23149f | 2015-03-06 15:39:44 -0800 | [diff] [blame] | 193 | private static final String TAG = TAG_WITH_CLASS_NAME ? "ActivityStackSupervisor" : TAG_AM; |
Chong Zhang | 6cda19c | 2016-06-14 19:07:56 -0700 | [diff] [blame] | 194 | private static final String TAG_FOCUS = TAG + POSTFIX_FOCUS; |
Wale Ogunwale | 0fc365c | 2015-05-25 19:35:42 -0700 | [diff] [blame] | 195 | private static final String TAG_IDLE = TAG + POSTFIX_IDLE; |
Wale Ogunwale | ee006da | 2015-03-30 14:49:25 -0700 | [diff] [blame] | 196 | private static final String TAG_PAUSE = TAG + POSTFIX_PAUSE; |
Wale Ogunwale | ee006da | 2015-03-30 14:49:25 -0700 | [diff] [blame] | 197 | private static final String TAG_RECENTS = TAG + POSTFIX_RECENTS; |
Wale Ogunwale | 0fc365c | 2015-05-25 19:35:42 -0700 | [diff] [blame] | 198 | private static final String TAG_RELEASE = TAG + POSTFIX_RELEASE; |
Wale Ogunwale | ee006da | 2015-03-30 14:49:25 -0700 | [diff] [blame] | 199 | private static final String TAG_STACK = TAG + POSTFIX_STACK; |
Wale Ogunwale | 0fc365c | 2015-05-25 19:35:42 -0700 | [diff] [blame] | 200 | private static final String TAG_STATES = TAG + POSTFIX_STATES; |
Wale Ogunwale | ee006da | 2015-03-30 14:49:25 -0700 | [diff] [blame] | 201 | private static final String TAG_SWITCH = TAG + POSTFIX_SWITCH; |
Filip Gruszczynski | 07a0e49 | 2015-12-17 14:16:38 -0800 | [diff] [blame] | 202 | static final String TAG_TASKS = TAG + POSTFIX_TASKS; |
Wale Ogunwale | e23149f | 2015-03-06 15:39:44 -0800 | [diff] [blame] | 203 | |
Craig Mautner | f333327 | 2013-04-22 10:55:53 -0700 | [diff] [blame] | 204 | /** 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] | 205 | static final int IDLE_TIMEOUT = 10 * 1000; |
Craig Mautner | f333327 | 2013-04-22 10:55:53 -0700 | [diff] [blame] | 206 | |
Craig Mautner | 0eea92c | 2013-05-16 13:35:39 -0700 | [diff] [blame] | 207 | /** How long we can hold the sleep wake lock before giving up. */ |
Wale Ogunwale | 0fc365c | 2015-05-25 19:35:42 -0700 | [diff] [blame] | 208 | static final int SLEEP_TIMEOUT = 5 * 1000; |
Craig Mautner | 0eea92c | 2013-05-16 13:35:39 -0700 | [diff] [blame] | 209 | |
Craig Mautner | 7ea5bd4 | 2013-07-05 15:27:08 -0700 | [diff] [blame] | 210 | // How long we can hold the launch wake lock before giving up. |
Wale Ogunwale | 0fc365c | 2015-05-25 19:35:42 -0700 | [diff] [blame] | 211 | static final int LAUNCH_TIMEOUT = 10 * 1000; |
Craig Mautner | 7ea5bd4 | 2013-07-05 15:27:08 -0700 | [diff] [blame] | 212 | |
Craig Mautner | 05d2903 | 2013-05-03 13:40:13 -0700 | [diff] [blame] | 213 | static final int IDLE_TIMEOUT_MSG = FIRST_SUPERVISOR_STACK_MSG; |
| 214 | static final int IDLE_NOW_MSG = FIRST_SUPERVISOR_STACK_MSG + 1; |
| 215 | static final int RESUME_TOP_ACTIVITY_MSG = FIRST_SUPERVISOR_STACK_MSG + 2; |
Craig Mautner | 0eea92c | 2013-05-16 13:35:39 -0700 | [diff] [blame] | 216 | static final int SLEEP_TIMEOUT_MSG = FIRST_SUPERVISOR_STACK_MSG + 3; |
Craig Mautner | 7ea5bd4 | 2013-07-05 15:27:08 -0700 | [diff] [blame] | 217 | static final int LAUNCH_TIMEOUT_MSG = FIRST_SUPERVISOR_STACK_MSG + 4; |
Craig Mautner | 4a1cb22 | 2013-12-04 16:14:06 -0800 | [diff] [blame] | 218 | static final int HANDLE_DISPLAY_ADDED = FIRST_SUPERVISOR_STACK_MSG + 5; |
| 219 | static final int HANDLE_DISPLAY_CHANGED = FIRST_SUPERVISOR_STACK_MSG + 6; |
| 220 | static final int HANDLE_DISPLAY_REMOVED = FIRST_SUPERVISOR_STACK_MSG + 7; |
Wale Ogunwale | 73eba74 | 2015-04-07 14:23:14 -0700 | [diff] [blame] | 221 | static final int LAUNCH_TASK_BEHIND_COMPLETE = FIRST_SUPERVISOR_STACK_MSG + 12; |
Wale Ogunwale | 22e2526 | 2016-02-01 10:32:02 -0800 | [diff] [blame] | 222 | static final int REPORT_MULTI_WINDOW_MODE_CHANGED_MSG = FIRST_SUPERVISOR_STACK_MSG + 14; |
| 223 | 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] | 224 | |
Wale Ogunwale | 040b470 | 2015-08-06 18:10:50 -0700 | [diff] [blame] | 225 | private static final String VIRTUAL_DISPLAY_BASE_NAME = "ActivityViewVirtualDisplay"; |
Craig Mautner | 7ea5bd4 | 2013-07-05 15:27:08 -0700 | [diff] [blame] | 226 | |
Wale Ogunwale | 040b470 | 2015-08-06 18:10:50 -0700 | [diff] [blame] | 227 | // Used to indicate if an object (e.g. stack) that we are trying to get |
| 228 | // should be created if it doesn't exist already. |
Filip Gruszczynski | 07a0e49 | 2015-12-17 14:16:38 -0800 | [diff] [blame] | 229 | static final boolean CREATE_IF_NEEDED = true; |
Wale Ogunwale | 040b470 | 2015-08-06 18:10:50 -0700 | [diff] [blame] | 230 | |
Filip Gruszczynski | bc5a6c5 | 2015-09-22 13:13:24 -0700 | [diff] [blame] | 231 | // Used to indicate that windows of activities should be preserved during the resize. |
| 232 | static final boolean PRESERVE_WINDOWS = true; |
| 233 | |
Wale Ogunwale | 040b470 | 2015-08-06 18:10:50 -0700 | [diff] [blame] | 234 | // Used to indicate if an object (e.g. task) should be moved/created |
| 235 | // at the top of its container (e.g. stack). |
Wale Ogunwale | b30daaa | 2015-08-07 21:50:49 -0700 | [diff] [blame] | 236 | static final boolean ON_TOP = true; |
Wale Ogunwale | 040b470 | 2015-08-06 18:10:50 -0700 | [diff] [blame] | 237 | |
Wale Ogunwale | c8da41e | 2016-04-16 13:27:23 -0700 | [diff] [blame] | 238 | // Don't execute any calls to resume. |
| 239 | static final boolean DEFER_RESUME = true; |
| 240 | |
Winson Chung | 010927a | 2016-12-15 16:12:35 -0800 | [diff] [blame] | 241 | // Used to indicate that a task is removed it should also be removed from recents. |
| 242 | static final boolean REMOVE_FROM_RECENTS = true; |
| 243 | |
Winson Chung | 6954fc9 | 2017-03-24 16:22:12 -0700 | [diff] [blame] | 244 | // Used to indicate that pausing an activity should occur immediately without waiting for |
| 245 | // the activity callback indicating that it has completed pausing |
| 246 | static final boolean PAUSE_IMMEDIATELY = true; |
| 247 | |
Winson Chung | 7900bee | 2017-03-10 08:59:25 -0800 | [diff] [blame] | 248 | /** |
| 249 | * The modes which affect which tasks are returned when calling |
| 250 | * {@link ActivityStackSupervisor#anyTaskForIdLocked(int)}. |
| 251 | */ |
| 252 | @Retention(RetentionPolicy.SOURCE) |
| 253 | @IntDef({ |
| 254 | MATCH_TASK_IN_STACKS_ONLY, |
| 255 | MATCH_TASK_IN_STACKS_OR_RECENT_TASKS, |
| 256 | MATCH_TASK_IN_STACKS_OR_RECENT_TASKS_AND_RESTORE |
| 257 | }) |
| 258 | public @interface AnyTaskForIdMatchTaskMode {} |
| 259 | // Match only tasks in the current stacks |
| 260 | static final int MATCH_TASK_IN_STACKS_ONLY = 0; |
| 261 | // Match either tasks in the current stacks, or in the recent tasks if not found in the stacks |
| 262 | static final int MATCH_TASK_IN_STACKS_OR_RECENT_TASKS = 1; |
| 263 | // Match either tasks in the current stacks, or in the recent tasks, restoring it to the |
| 264 | // provided stack id |
| 265 | static final int MATCH_TASK_IN_STACKS_OR_RECENT_TASKS_AND_RESTORE = 2; |
| 266 | |
Svetoslav | 7008b51 | 2015-06-24 18:47:07 -0700 | [diff] [blame] | 267 | // Activity actions an app cannot start if it uses a permission which is not granted. |
| 268 | private static final ArrayMap<String, String> ACTION_TO_RUNTIME_PERMISSION = |
| 269 | new ArrayMap<>(); |
Filip Gruszczynski | bc5a6c5 | 2015-09-22 13:13:24 -0700 | [diff] [blame] | 270 | |
Svetoslav | 7008b51 | 2015-06-24 18:47:07 -0700 | [diff] [blame] | 271 | static { |
| 272 | ACTION_TO_RUNTIME_PERMISSION.put(MediaStore.ACTION_IMAGE_CAPTURE, |
| 273 | Manifest.permission.CAMERA); |
| 274 | ACTION_TO_RUNTIME_PERMISSION.put(MediaStore.ACTION_VIDEO_CAPTURE, |
| 275 | Manifest.permission.CAMERA); |
| 276 | ACTION_TO_RUNTIME_PERMISSION.put(Intent.ACTION_CALL, |
| 277 | Manifest.permission.CALL_PHONE); |
| 278 | } |
| 279 | |
Svet Ganov | 99b6043 | 2015-06-27 13:15:22 -0700 | [diff] [blame] | 280 | /** Action restriction: launching the activity is not restricted. */ |
| 281 | private static final int ACTIVITY_RESTRICTION_NONE = 0; |
| 282 | /** Action restriction: launching the activity is restricted by a permission. */ |
| 283 | private static final int ACTIVITY_RESTRICTION_PERMISSION = 1; |
| 284 | /** Action restriction: launching the activity is restricted by an app op. */ |
| 285 | private static final int ACTIVITY_RESTRICTION_APPOP = 2; |
Svetoslav | 7008b51 | 2015-06-24 18:47:07 -0700 | [diff] [blame] | 286 | |
Craig Mautner | 7ea5bd4 | 2013-07-05 15:27:08 -0700 | [diff] [blame] | 287 | // For debugging to make sure the caller when acquiring/releasing our |
| 288 | // wake lock is the system process. |
| 289 | static final boolean VALIDATE_WAKE_LOCK_CALLER = false; |
Suprabh Shukla | 09a88f5 | 2015-12-02 14:36:31 -0800 | [diff] [blame] | 290 | /** The number of distinct task ids that can be assigned to the tasks of a single user */ |
| 291 | 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] | 292 | |
Craig Mautner | 2708430 | 2013-03-25 08:05:25 -0700 | [diff] [blame] | 293 | final ActivityManagerService mService; |
| 294 | |
Winson Chung | 61c9e5a | 2017-10-11 10:39:32 -0700 | [diff] [blame] | 295 | /** The historial list of recent tasks including inactive tasks */ |
Winson Chung | 1dbc811 | 2017-09-28 18:05:31 -0700 | [diff] [blame] | 296 | RecentTasks mRecentTasks; |
Wale Ogunwale | c82f2f5 | 2014-12-09 09:32:50 -0800 | [diff] [blame] | 297 | |
Winson Chung | 61c9e5a | 2017-10-11 10:39:32 -0700 | [diff] [blame] | 298 | /** 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] | 299 | private RunningTasks mRunningTasks; |
Winson Chung | 61c9e5a | 2017-10-11 10:39:32 -0700 | [diff] [blame] | 300 | |
Craig Mautner | ce5f3cb | 2013-04-22 08:58:54 -0700 | [diff] [blame] | 301 | final ActivityStackSupervisorHandler mHandler; |
Winson Chung | e2d7217 | 2018-01-25 17:46:20 +0000 | [diff] [blame] | 302 | final Looper mLooper; |
Craig Mautner | ce5f3cb | 2013-04-22 08:58:54 -0700 | [diff] [blame] | 303 | |
| 304 | /** Short cut */ |
| 305 | WindowManagerService mWindowManager; |
Craig Mautner | 4a1cb22 | 2013-12-04 16:14:06 -0800 | [diff] [blame] | 306 | DisplayManager mDisplayManager; |
Craig Mautner | ce5f3cb | 2013-04-22 08:58:54 -0700 | [diff] [blame] | 307 | |
Bryce Lee | ec55eb0 | 2017-12-05 20:51:27 -0800 | [diff] [blame] | 308 | private LaunchParamsController mLaunchParamsController; |
Bryce Lee | 9ad3eb3 | 2017-10-10 10:10:31 -0700 | [diff] [blame] | 309 | |
Suprabh Shukla | 09a88f5 | 2015-12-02 14:36:31 -0800 | [diff] [blame] | 310 | /** |
| 311 | * Maps the task identifier that activities are currently being started in to the userId of the |
| 312 | * task. Each time a new task is created, the entry for the userId of the task is incremented |
| 313 | */ |
| 314 | private final SparseIntArray mCurTaskIdForUser = new SparseIntArray(20); |
Craig Mautner | 8d341ef | 2013-03-26 09:03:27 -0700 | [diff] [blame] | 315 | |
Craig Mautner | 2420ead | 2013-04-01 17:13:20 -0700 | [diff] [blame] | 316 | /** The current user */ |
Filip Gruszczynski | 07a0e49 | 2015-12-17 14:16:38 -0800 | [diff] [blame] | 317 | int mCurrentUser; |
Craig Mautner | 2420ead | 2013-04-01 17:13:20 -0700 | [diff] [blame] | 318 | |
Craig Mautner | e0a3884 | 2013-12-16 16:14:02 -0800 | [diff] [blame] | 319 | /** The stack containing the launcher app. Assumed to always be attached to |
| 320 | * Display.DEFAULT_DISPLAY. */ |
Filip Gruszczynski | 07a0e49 | 2015-12-17 14:16:38 -0800 | [diff] [blame] | 321 | ActivityStack mHomeStack; |
Craig Mautner | 20e7227 | 2013-04-01 13:45:53 -0700 | [diff] [blame] | 322 | |
Craig Mautner | e0a3884 | 2013-12-16 16:14:02 -0800 | [diff] [blame] | 323 | /** The stack currently receiving input or launching the next activity. */ |
Filip Gruszczynski | 07a0e49 | 2015-12-17 14:16:38 -0800 | [diff] [blame] | 324 | ActivityStack mFocusedStack; |
Craig Mautner | 8d341ef | 2013-03-26 09:03:27 -0700 | [diff] [blame] | 325 | |
Craig Mautner | 4a1cb22 | 2013-12-04 16:14:06 -0800 | [diff] [blame] | 326 | /** If this is the same as mFocusedStack then the activity on the top of the focused stack has |
| 327 | * been resumed. If stacks are changing position this will hold the old stack until the new |
Craig Mautner | e0a3884 | 2013-12-16 16:14:02 -0800 | [diff] [blame] | 328 | * stack becomes resumed after which it will be set to mFocusedStack. */ |
Craig Mautner | 4a1cb22 | 2013-12-04 16:14:06 -0800 | [diff] [blame] | 329 | private ActivityStack mLastFocusedStack; |
Craig Mautner | de4ef02 | 2013-04-07 19:01:33 -0700 | [diff] [blame] | 330 | |
| 331 | /** List of activities that are waiting for a new activity to become visible before completing |
| 332 | * whatever operation they are supposed to do. */ |
Bryce Lee | 4a19438 | 2017-04-04 14:32:48 -0700 | [diff] [blame] | 333 | // TODO: Remove mActivitiesWaitingForVisibleActivity list and just remove activity from |
| 334 | // mStoppingActivities when something else comes up. |
| 335 | final ArrayList<ActivityRecord> mActivitiesWaitingForVisibleActivity = new ArrayList<>(); |
Craig Mautner | de4ef02 | 2013-04-07 19:01:33 -0700 | [diff] [blame] | 336 | |
Bryce Lee | 4a19438 | 2017-04-04 14:32:48 -0700 | [diff] [blame] | 337 | /** List of processes waiting to find out when a specific activity becomes visible. */ |
| 338 | private final ArrayList<WaitInfo> mWaitingForActivityVisible = new ArrayList<>(); |
Craig Mautner | ce5f3cb | 2013-04-22 08:58:54 -0700 | [diff] [blame] | 339 | |
| 340 | /** List of processes waiting to find out about the next launched activity. */ |
Sudheer Shanka | fc46e9b | 2016-10-21 17:55:27 -0700 | [diff] [blame] | 341 | final ArrayList<WaitResult> mWaitingActivityLaunched = new ArrayList<>(); |
Craig Mautner | ce5f3cb | 2013-04-22 08:58:54 -0700 | [diff] [blame] | 342 | |
Craig Mautner | de4ef02 | 2013-04-07 19:01:33 -0700 | [diff] [blame] | 343 | /** List of activities that are ready to be stopped, but waiting for the next activity to |
| 344 | * settle down before doing so. */ |
Craig Mautner | 8c14c15 | 2015-01-15 17:32:07 -0800 | [diff] [blame] | 345 | final ArrayList<ActivityRecord> mStoppingActivities = new ArrayList<>(); |
Craig Mautner | de4ef02 | 2013-04-07 19:01:33 -0700 | [diff] [blame] | 346 | |
Craig Mautner | f333327 | 2013-04-22 10:55:53 -0700 | [diff] [blame] | 347 | /** List of activities that are ready to be finished, but waiting for the previous activity to |
| 348 | * settle down before doing so. It contains ActivityRecord objects. */ |
Craig Mautner | 8c14c15 | 2015-01-15 17:32:07 -0800 | [diff] [blame] | 349 | final ArrayList<ActivityRecord> mFinishingActivities = new ArrayList<>(); |
Craig Mautner | f333327 | 2013-04-22 10:55:53 -0700 | [diff] [blame] | 350 | |
Craig Mautner | 0eea92c | 2013-05-16 13:35:39 -0700 | [diff] [blame] | 351 | /** List of activities that are in the process of going to sleep. */ |
Craig Mautner | 8c14c15 | 2015-01-15 17:32:07 -0800 | [diff] [blame] | 352 | final ArrayList<ActivityRecord> mGoingToSleepActivities = new ArrayList<>(); |
Craig Mautner | 0eea92c | 2013-05-16 13:35:39 -0700 | [diff] [blame] | 353 | |
Wale Ogunwale | 22e2526 | 2016-02-01 10:32:02 -0800 | [diff] [blame] | 354 | /** List of activities whose multi-window mode changed that we need to report to the |
| 355 | * application */ |
| 356 | final ArrayList<ActivityRecord> mMultiWindowModeChangedActivities = new ArrayList<>(); |
| 357 | |
| 358 | /** List of activities whose picture-in-picture mode changed that we need to report to the |
| 359 | * application */ |
| 360 | final ArrayList<ActivityRecord> mPipModeChangedActivities = new ArrayList<>(); |
| 361 | |
Jorim Jaggi | fa9ed96 | 2018-01-25 00:16:49 +0100 | [diff] [blame] | 362 | /** |
| 363 | * Animations that for the current transition have requested not to |
| 364 | * be considered for the transition animation. |
| 365 | */ |
| 366 | final ArrayList<ActivityRecord> mNoAnimActivities = new ArrayList<>(); |
| 367 | |
Winson Chung | 5af42fc | 2017-03-24 17:11:33 -0700 | [diff] [blame] | 368 | /** The target stack bounds for the picture-in-picture mode changed that we need to report to |
| 369 | * the application */ |
| 370 | Rect mPipModeChangedTargetStackBounds; |
| 371 | |
Craig Mautner | f333327 | 2013-04-22 10:55:53 -0700 | [diff] [blame] | 372 | /** Used on user changes */ |
Amith Yamasani | 37a40c2 | 2015-06-17 13:25:42 -0700 | [diff] [blame] | 373 | final ArrayList<UserState> mStartingUsers = new ArrayList<>(); |
Craig Mautner | f333327 | 2013-04-22 10:55:53 -0700 | [diff] [blame] | 374 | |
Craig Mautner | de4ef02 | 2013-04-07 19:01:33 -0700 | [diff] [blame] | 375 | /** Set to indicate whether to issue an onUserLeaving callback when a newly launched activity |
| 376 | * is being brought in front of us. */ |
| 377 | boolean mUserLeaving = false; |
| 378 | |
Bryce Lee | d3624e1 | 2017-11-30 08:51:45 -0800 | [diff] [blame] | 379 | /** Set when a power hint has started, but not ended. */ |
| 380 | private boolean mPowerHintSent; |
| 381 | |
Craig Mautner | 0eea92c | 2013-05-16 13:35:39 -0700 | [diff] [blame] | 382 | /** |
Craig Mautner | 7ea5bd4 | 2013-07-05 15:27:08 -0700 | [diff] [blame] | 383 | * We don't want to allow the device to go to sleep while in the process |
| 384 | * of launching an activity. This is primarily to allow alarm intent |
| 385 | * receivers to launch an activity and get that to run before the device |
| 386 | * goes back to sleep. |
| 387 | */ |
Jeff Brown | 2c43c33 | 2014-06-12 22:38:59 -0700 | [diff] [blame] | 388 | PowerManager.WakeLock mLaunchingActivity; |
Craig Mautner | 7ea5bd4 | 2013-07-05 15:27:08 -0700 | [diff] [blame] | 389 | |
| 390 | /** |
Craig Mautner | 0eea92c | 2013-05-16 13:35:39 -0700 | [diff] [blame] | 391 | * Set when the system is going to sleep, until we have |
| 392 | * successfully paused the current activity and released our wake lock. |
| 393 | * At that point the system is allowed to actually sleep. |
| 394 | */ |
Jeff Brown | 2c43c33 | 2014-06-12 22:38:59 -0700 | [diff] [blame] | 395 | PowerManager.WakeLock mGoingToSleep; |
Craig Mautner | 0eea92c | 2013-05-16 13:35:39 -0700 | [diff] [blame] | 396 | |
David Stevens | 9440dc8 | 2017-03-16 19:00:20 -0700 | [diff] [blame] | 397 | /** |
| 398 | * A list of tokens that cause the top activity to be put to sleep. |
| 399 | * They are used by components that may hide and block interaction with underlying |
| 400 | * activities. |
| 401 | */ |
Wale Ogunwale | 9dcf946 | 2017-09-19 15:13:01 -0700 | [diff] [blame] | 402 | final ArrayList<SleepToken> mSleepTokens = new ArrayList<>(); |
David Stevens | 9440dc8 | 2017-03-16 19:00:20 -0700 | [diff] [blame] | 403 | |
Craig Mautner | 4f1df4f | 2013-10-15 15:44:14 -0700 | [diff] [blame] | 404 | /** Stack id of the front stack when user switched, indexed by userId. */ |
| 405 | SparseIntArray mUserStackInFront = new SparseIntArray(2); |
Craig Mautner | 93529a4 | 2013-10-04 15:03:13 -0700 | [diff] [blame] | 406 | |
Bryce Lee | af3a400 | 2017-03-20 10:37:12 -0700 | [diff] [blame] | 407 | // TODO: There should be an ActivityDisplayController coordinating am/wm interaction. |
Craig Mautner | 4a1cb22 | 2013-12-04 16:14:06 -0800 | [diff] [blame] | 408 | /** Mapping from displayId to display current state */ |
Craig Mautner | 15df08a | 2015-04-01 12:17:18 -0700 | [diff] [blame] | 409 | private final SparseArray<ActivityDisplay> mActivityDisplays = new SparseArray<>(); |
Craig Mautner | 4a1cb22 | 2013-12-04 16:14:06 -0800 | [diff] [blame] | 410 | |
Andrii Kulian | fb1bf69 | 2017-01-17 11:17:34 -0800 | [diff] [blame] | 411 | private final SparseArray<IntArray> mDisplayAccessUIDs = new SparseArray<>(); |
| 412 | |
| 413 | private DisplayManagerInternal mDisplayManagerInternal; |
Jeff Brown | ca9bc70 | 2014-02-11 14:32:56 -0800 | [diff] [blame] | 414 | |
Wale Ogunwale | d046a01 | 2015-12-24 13:05:59 -0800 | [diff] [blame] | 415 | /** Used to keep resumeTopActivityUncheckedLocked() from being entered recursively */ |
Craig Mautner | 42d04db | 2014-11-06 12:13:23 -0800 | [diff] [blame] | 416 | boolean inResumeTopActivity; |
| 417 | |
Andrii Kulian | 1e32e02 | 2016-09-16 15:29:34 -0700 | [diff] [blame] | 418 | /** |
| 419 | * Temporary rect used during docked stack resize calculation so we don't need to create a new |
| 420 | * object each time. |
| 421 | */ |
Wale Ogunwale | b34a7ad | 2015-08-14 11:05:30 -0700 | [diff] [blame] | 422 | private final Rect tempRect = new Rect(); |
Wale Ogunwale | 7e1f5f5 | 2017-10-18 15:19:59 -0700 | [diff] [blame] | 423 | private final ActivityOptions mTmpOptions = ActivityOptions.makeBasic(); |
Filip Gruszczynski | ebcc875 | 2015-08-25 16:51:05 -0700 | [diff] [blame] | 424 | |
Filip Gruszczynski | d2f1d94 | 2015-10-14 15:10:12 -0700 | [diff] [blame] | 425 | // The default minimal size that will be used if the activity doesn't specify its minimal size. |
| 426 | // It will be calculated when the default display gets added. |
Andrii Kulian | f66a83d | 2016-05-17 12:17:44 -0700 | [diff] [blame] | 427 | int mDefaultMinSizeOfResizeableTask = -1; |
Filip Gruszczynski | d2f1d94 | 2015-10-14 15:10:12 -0700 | [diff] [blame] | 428 | |
Chong Zhang | fdcc4d4 | 2015-10-14 16:50:12 -0700 | [diff] [blame] | 429 | // Whether tasks have moved and we need to rank the tasks before next OOM scoring |
| 430 | private boolean mTaskLayersChanged = true; |
| 431 | |
Bryce Lee | 2a3cc46 | 2017-10-27 10:57:35 -0700 | [diff] [blame] | 432 | private ActivityMetricsLogger mActivityMetricsLogger; |
Filip Gruszczynski | 77d9448 | 2015-12-11 13:59:52 -0800 | [diff] [blame] | 433 | |
Jorim Jaggi | ea039a8 | 2017-08-02 14:37:49 +0200 | [diff] [blame] | 434 | private final ArrayList<ActivityRecord> mTmpActivityList = new ArrayList<>(); |
| 435 | |
Andrii Kulian | 1779e61 | 2016-10-12 21:58:25 -0700 | [diff] [blame] | 436 | @Override |
| 437 | protected int getChildCount() { |
| 438 | return mActivityDisplays.size(); |
| 439 | } |
| 440 | |
| 441 | @Override |
Andrii Kulian | 5406e7a | 2016-10-21 11:55:23 -0700 | [diff] [blame] | 442 | protected ActivityDisplay getChildAt(int index) { |
Andrii Kulian | 1779e61 | 2016-10-12 21:58:25 -0700 | [diff] [blame] | 443 | return mActivityDisplays.valueAt(index); |
| 444 | } |
| 445 | |
| 446 | @Override |
| 447 | protected ConfigurationContainer getParent() { |
| 448 | return null; |
| 449 | } |
| 450 | |
Andrii Kulian | 5406e7a | 2016-10-21 11:55:23 -0700 | [diff] [blame] | 451 | Configuration getDisplayOverrideConfiguration(int displayId) { |
Andrii Kulian | 62e6f25 | 2017-05-30 22:46:53 -0700 | [diff] [blame] | 452 | final ActivityDisplay activityDisplay = getActivityDisplayOrCreateLocked(displayId); |
Andrii Kulian | 5406e7a | 2016-10-21 11:55:23 -0700 | [diff] [blame] | 453 | if (activityDisplay == null) { |
| 454 | throw new IllegalArgumentException("No display found with id: " + displayId); |
| 455 | } |
| 456 | |
| 457 | return activityDisplay.getOverrideConfiguration(); |
| 458 | } |
| 459 | |
| 460 | void setDisplayOverrideConfiguration(Configuration overrideConfiguration, int displayId) { |
Andrii Kulian | 62e6f25 | 2017-05-30 22:46:53 -0700 | [diff] [blame] | 461 | final ActivityDisplay activityDisplay = getActivityDisplayOrCreateLocked(displayId); |
Andrii Kulian | 5406e7a | 2016-10-21 11:55:23 -0700 | [diff] [blame] | 462 | if (activityDisplay == null) { |
| 463 | throw new IllegalArgumentException("No display found with id: " + displayId); |
| 464 | } |
| 465 | |
| 466 | activityDisplay.onOverrideConfigurationChanged(overrideConfiguration); |
| 467 | } |
| 468 | |
Andrii Kulian | 036e3ad | 2017-04-19 10:55:10 -0700 | [diff] [blame] | 469 | /** Check if placing task or activity on specified display is allowed. */ |
Andrii Kulian | 02689a7 | 2017-07-06 14:28:59 -0700 | [diff] [blame] | 470 | boolean canPlaceEntityOnDisplay(int displayId, boolean resizeable, int callingPid, |
| 471 | int callingUid, ActivityInfo activityInfo) { |
| 472 | if (displayId == DEFAULT_DISPLAY) { |
| 473 | // No restrictions for the default display. |
| 474 | return true; |
| 475 | } |
| 476 | if (!mService.mSupportsMultiDisplay) { |
| 477 | // Can't launch on secondary displays if feature is not supported. |
| 478 | return false; |
| 479 | } |
| 480 | if (!resizeable && !displayConfigMatchesGlobal(displayId)) { |
| 481 | // Can't apply wrong configuration to non-resizeable activities. |
| 482 | return false; |
| 483 | } |
| 484 | if (!isCallerAllowedToLaunchOnDisplay(callingPid, callingUid, displayId, activityInfo)) { |
| 485 | // Can't place activities to a display that has restricted launch rules. |
| 486 | // In this case the request should be made by explicitly adding target display id and |
| 487 | // by caller with corresponding permissions. See #isCallerAllowedToLaunchOnDisplay(). |
| 488 | return false; |
| 489 | } |
| 490 | return true; |
Andrii Kulian | 036e3ad | 2017-04-19 10:55:10 -0700 | [diff] [blame] | 491 | } |
| 492 | |
| 493 | /** |
| 494 | * Check if configuration of specified display matches current global config. |
| 495 | * Used to check if we can put a non-resizeable activity on a secondary display and it will get |
| 496 | * the same config as on the default display. |
| 497 | * @param displayId Id of the display to check. |
| 498 | * @return {@code true} if configuration matches. |
| 499 | */ |
| 500 | private boolean displayConfigMatchesGlobal(int displayId) { |
| 501 | if (displayId == DEFAULT_DISPLAY) { |
| 502 | return true; |
| 503 | } |
| 504 | if (displayId == INVALID_DISPLAY) { |
| 505 | return false; |
| 506 | } |
Andrii Kulian | 62e6f25 | 2017-05-30 22:46:53 -0700 | [diff] [blame] | 507 | final ActivityDisplay targetDisplay = getActivityDisplayOrCreateLocked(displayId); |
Andrii Kulian | 036e3ad | 2017-04-19 10:55:10 -0700 | [diff] [blame] | 508 | if (targetDisplay == null) { |
| 509 | throw new IllegalArgumentException("No display found with id: " + displayId); |
| 510 | } |
| 511 | return getConfiguration().equals(targetDisplay.getConfiguration()); |
| 512 | } |
| 513 | |
Wale Ogunwale | 3938197 | 2015-12-17 17:15:29 -0800 | [diff] [blame] | 514 | static class FindTaskResult { |
| 515 | ActivityRecord r; |
| 516 | boolean matchedByRootAffinity; |
| 517 | } |
| 518 | private final FindTaskResult mTmpFindTaskResult = new FindTaskResult(); |
| 519 | |
Craig Mautner | ee36c77 | 2014-07-16 14:56:05 -0700 | [diff] [blame] | 520 | /** |
Andrii Kulian | 7fc2281 | 2016-12-28 13:04:11 -0800 | [diff] [blame] | 521 | * Temp storage for display ids sorted in focus order. |
| 522 | * Maps position to id. Using {@link SparseIntArray} instead of {@link ArrayList} because |
| 523 | * it's more efficient, as the number of displays is usually small. |
| 524 | */ |
| 525 | private SparseIntArray mTmpOrderedDisplayIds = new SparseIntArray(); |
| 526 | |
| 527 | /** |
Jorim Jaggi | a0fdeec | 2016-01-07 14:42:28 +0100 | [diff] [blame] | 528 | * Used to keep track whether app visibilities got changed since the last pause. Useful to |
| 529 | * determine whether to invoke the task stack change listener after pausing. |
| 530 | */ |
| 531 | boolean mAppVisibilitiesChangedSinceLastPause; |
| 532 | |
| 533 | /** |
Jorim Jaggi | 0b46f3c | 2016-03-14 12:21:37 +0100 | [diff] [blame] | 534 | * Set of tasks that are in resizing mode during an app transition to fill the "void". |
| 535 | */ |
| 536 | private final ArraySet<Integer> mResizingTasksDuringAnimation = new ArraySet<>(); |
| 537 | |
Wale Ogunwale | c8da41e | 2016-04-16 13:27:23 -0700 | [diff] [blame] | 538 | |
| 539 | /** |
| 540 | * If set to {@code false} all calls to resize the docked stack {@link #resizeDockedStackLocked} |
| 541 | * will be ignored. Useful for the case where the caller is handling resizing of other stack and |
| 542 | * moving tasks around and doesn't want dock stack to be resized due to an automatic trigger |
| 543 | * like the docked stack going empty. |
| 544 | */ |
| 545 | private boolean mAllowDockedStackResize = true; |
| 546 | |
Jorim Jaggi | 0b46f3c | 2016-03-14 12:21:37 +0100 | [diff] [blame] | 547 | /** |
Tony Mak | 853304c | 2016-04-18 15:17:41 +0100 | [diff] [blame] | 548 | * Is dock currently minimized. |
| 549 | */ |
| 550 | boolean mIsDockMinimized; |
| 551 | |
Bryce Lee | 2a3cc46 | 2017-10-27 10:57:35 -0700 | [diff] [blame] | 552 | private KeyguardController mKeyguardController; |
Jorim Jaggi | fe76234 | 2016-10-13 14:33:27 +0200 | [diff] [blame] | 553 | |
chaviw | 59b9885 | 2017-06-13 12:05:44 -0700 | [diff] [blame] | 554 | private PowerManager mPowerManager; |
| 555 | private int mDeferResumeCount; |
| 556 | |
Bryce Lee | 2a3cc46 | 2017-10-27 10:57:35 -0700 | [diff] [blame] | 557 | private boolean mInitialized; |
| 558 | |
Tony Mak | 853304c | 2016-04-18 15:17:41 +0100 | [diff] [blame] | 559 | /** |
Craig Mautner | ee36c77 | 2014-07-16 14:56:05 -0700 | [diff] [blame] | 560 | * Description of a request to start a new activity, which has been held |
| 561 | * due to app switches being disabled. |
| 562 | */ |
| 563 | static class PendingActivityLaunch { |
| 564 | final ActivityRecord r; |
| 565 | final ActivityRecord sourceRecord; |
| 566 | final int startFlags; |
| 567 | final ActivityStack stack; |
Robert Carr | 13997f5 | 2015-10-23 13:13:39 -0700 | [diff] [blame] | 568 | final ProcessRecord callerApp; |
Craig Mautner | ee36c77 | 2014-07-16 14:56:05 -0700 | [diff] [blame] | 569 | |
| 570 | PendingActivityLaunch(ActivityRecord _r, ActivityRecord _sourceRecord, |
Robert Carr | 13997f5 | 2015-10-23 13:13:39 -0700 | [diff] [blame] | 571 | int _startFlags, ActivityStack _stack, ProcessRecord _callerApp) { |
Craig Mautner | ee36c77 | 2014-07-16 14:56:05 -0700 | [diff] [blame] | 572 | r = _r; |
| 573 | sourceRecord = _sourceRecord; |
| 574 | startFlags = _startFlags; |
| 575 | stack = _stack; |
Robert Carr | 13997f5 | 2015-10-23 13:13:39 -0700 | [diff] [blame] | 576 | callerApp = _callerApp; |
| 577 | } |
| 578 | |
| 579 | void sendErrorResult(String message) { |
| 580 | try { |
| 581 | if (callerApp.thread != null) { |
| 582 | callerApp.thread.scheduleCrash(message); |
| 583 | } |
| 584 | } catch (RemoteException e) { |
| 585 | Slog.e(TAG, "Exception scheduling crash of failed " |
| 586 | + "activity launcher sourceRecord=" + sourceRecord, e); |
| 587 | } |
Craig Mautner | ee36c77 | 2014-07-16 14:56:05 -0700 | [diff] [blame] | 588 | } |
| 589 | } |
| 590 | |
Bryce Lee | af691c0 | 2017-03-20 14:20:22 -0700 | [diff] [blame] | 591 | public ActivityStackSupervisor(ActivityManagerService service, Looper looper) { |
Craig Mautner | 2708430 | 2013-03-25 08:05:25 -0700 | [diff] [blame] | 592 | mService = service; |
Winson Chung | e2d7217 | 2018-01-25 17:46:20 +0000 | [diff] [blame] | 593 | mLooper = looper; |
Bryce Lee | af691c0 | 2017-03-20 14:20:22 -0700 | [diff] [blame] | 594 | mHandler = new ActivityStackSupervisorHandler(looper); |
Bryce Lee | 2a3cc46 | 2017-10-27 10:57:35 -0700 | [diff] [blame] | 595 | } |
| 596 | |
| 597 | public void initialize() { |
| 598 | if (mInitialized) { |
| 599 | return; |
| 600 | } |
| 601 | |
| 602 | mInitialized = true; |
Winson Chung | 3f0e59a | 2017-10-25 10:19:05 -0700 | [diff] [blame] | 603 | mRunningTasks = createRunningTasks(); |
Bryce Lee | 2a3cc46 | 2017-10-27 10:57:35 -0700 | [diff] [blame] | 604 | mActivityMetricsLogger = new ActivityMetricsLogger(this, mService.mContext, |
| 605 | mHandler.getLooper()); |
| 606 | mKeyguardController = new KeyguardController(mService, this); |
Bryce Lee | dacefc4 | 2017-10-10 12:56:02 -0700 | [diff] [blame] | 607 | |
Bryce Lee | ec55eb0 | 2017-12-05 20:51:27 -0800 | [diff] [blame] | 608 | mLaunchParamsController = new LaunchParamsController(mService); |
| 609 | mLaunchParamsController.registerDefaultModifiers(this); |
Jeff Brown | 2c43c33 | 2014-06-12 22:38:59 -0700 | [diff] [blame] | 610 | } |
| 611 | |
Bryce Lee | 2a3cc46 | 2017-10-27 10:57:35 -0700 | [diff] [blame] | 612 | |
| 613 | public ActivityMetricsLogger getActivityMetricsLogger() { |
| 614 | return mActivityMetricsLogger; |
| 615 | } |
| 616 | |
| 617 | public KeyguardController getKeyguardController() { |
| 618 | return mKeyguardController; |
| 619 | } |
| 620 | |
Suprabh Shukla | 09a88f5 | 2015-12-02 14:36:31 -0800 | [diff] [blame] | 621 | void setRecentTasks(RecentTasks recentTasks) { |
| 622 | mRecentTasks = recentTasks; |
Winson Chung | 1dbc811 | 2017-09-28 18:05:31 -0700 | [diff] [blame] | 623 | mRecentTasks.registerCallback(this); |
Suprabh Shukla | 09a88f5 | 2015-12-02 14:36:31 -0800 | [diff] [blame] | 624 | } |
| 625 | |
Winson Chung | 3f0e59a | 2017-10-25 10:19:05 -0700 | [diff] [blame] | 626 | @VisibleForTesting |
| 627 | RunningTasks createRunningTasks() { |
| 628 | return new RunningTasks(); |
| 629 | } |
| 630 | |
Jeff Brown | 2c43c33 | 2014-06-12 22:38:59 -0700 | [diff] [blame] | 631 | /** |
| 632 | * At the time when the constructor runs, the power manager has not yet been |
| 633 | * initialized. So we initialize our wakelocks afterwards. |
| 634 | */ |
| 635 | void initPowerManagement() { |
chaviw | 59b9885 | 2017-06-13 12:05:44 -0700 | [diff] [blame] | 636 | mPowerManager = (PowerManager)mService.mContext.getSystemService(Context.POWER_SERVICE); |
| 637 | mGoingToSleep = mPowerManager |
| 638 | .newWakeLock(PARTIAL_WAKE_LOCK, "ActivityManager-Sleep"); |
| 639 | mLaunchingActivity = mPowerManager.newWakeLock(PARTIAL_WAKE_LOCK, "*launch*"); |
Craig Mautner | 7ea5bd4 | 2013-07-05 15:27:08 -0700 | [diff] [blame] | 640 | mLaunchingActivity.setReferenceCounted(false); |
Craig Mautner | 2219a1b | 2013-03-25 09:44:30 -0700 | [diff] [blame] | 641 | } |
| 642 | |
Craig Mautner | ce5f3cb | 2013-04-22 08:58:54 -0700 | [diff] [blame] | 643 | void setWindowManager(WindowManagerService wm) { |
Craig Mautner | 4a1cb22 | 2013-12-04 16:14:06 -0800 | [diff] [blame] | 644 | synchronized (mService) { |
| 645 | mWindowManager = wm; |
Jorim Jaggi | fe76234 | 2016-10-13 14:33:27 +0200 | [diff] [blame] | 646 | mKeyguardController.setWindowManager(wm); |
Craig Mautner | 4a1cb22 | 2013-12-04 16:14:06 -0800 | [diff] [blame] | 647 | |
| 648 | mDisplayManager = |
| 649 | (DisplayManager)mService.mContext.getSystemService(Context.DISPLAY_SERVICE); |
| 650 | mDisplayManager.registerDisplayListener(this, null); |
Andrii Kulian | fb1bf69 | 2017-01-17 11:17:34 -0800 | [diff] [blame] | 651 | mDisplayManagerInternal = LocalServices.getService(DisplayManagerInternal.class); |
Craig Mautner | 4a1cb22 | 2013-12-04 16:14:06 -0800 | [diff] [blame] | 652 | |
| 653 | Display[] displays = mDisplayManager.getDisplays(); |
| 654 | for (int displayNdx = displays.length - 1; displayNdx >= 0; --displayNdx) { |
| 655 | final int displayId = displays[displayNdx].getDisplayId(); |
Wale Ogunwale | 9dcf946 | 2017-09-19 15:13:01 -0700 | [diff] [blame] | 656 | ActivityDisplay activityDisplay = new ActivityDisplay(this, displayId); |
Craig Mautner | e0a3884 | 2013-12-16 16:14:02 -0800 | [diff] [blame] | 657 | mActivityDisplays.put(displayId, activityDisplay); |
Filip Gruszczynski | 7be9a8c | 2015-10-15 18:20:30 -0700 | [diff] [blame] | 658 | calculateDefaultMinimalSizeOfResizeableTasks(activityDisplay); |
Craig Mautner | 4a1cb22 | 2013-12-04 16:14:06 -0800 | [diff] [blame] | 659 | } |
| 660 | |
Wale Ogunwale | 04a05ac | 2017-09-17 21:35:02 -0700 | [diff] [blame] | 661 | mHomeStack = mFocusedStack = mLastFocusedStack = getDefaultDisplay().getOrCreateStack( |
| 662 | WINDOWING_MODE_FULLSCREEN, ACTIVITY_TYPE_HOME, ON_TOP); |
Craig Mautner | 4a1cb22 | 2013-12-04 16:14:06 -0800 | [diff] [blame] | 663 | } |
Craig Mautner | 2708430 | 2013-03-25 08:05:25 -0700 | [diff] [blame] | 664 | } |
| 665 | |
Craig Mautner | ce5f3cb | 2013-04-22 08:58:54 -0700 | [diff] [blame] | 666 | ActivityStack getFocusedStack() { |
Craig Mautner | 4a1cb22 | 2013-12-04 16:14:06 -0800 | [diff] [blame] | 667 | return mFocusedStack; |
Craig Mautner | 20e7227 | 2013-04-01 13:45:53 -0700 | [diff] [blame] | 668 | } |
| 669 | |
Craig Mautner | de4ef02 | 2013-04-07 19:01:33 -0700 | [diff] [blame] | 670 | ActivityStack getLastStack() { |
Craig Mautner | 4a1cb22 | 2013-12-04 16:14:06 -0800 | [diff] [blame] | 671 | return mLastFocusedStack; |
Craig Mautner | 2219a1b | 2013-03-25 09:44:30 -0700 | [diff] [blame] | 672 | } |
| 673 | |
Wale Ogunwale | 1e60e0c | 2015-10-28 13:36:10 -0700 | [diff] [blame] | 674 | boolean isFocusedStack(ActivityStack stack) { |
Andrii Kulian | 94e82d9b0 | 2017-07-13 15:33:06 -0700 | [diff] [blame] | 675 | return stack != null && stack == mFocusedStack; |
Craig Mautner | 20e7227 | 2013-04-01 13:45:53 -0700 | [diff] [blame] | 676 | } |
| 677 | |
Wale Ogunwale | d046a01 | 2015-12-24 13:05:59 -0800 | [diff] [blame] | 678 | /** NOTE: Should only be called from {@link ActivityStack#moveToFront} */ |
Wale Ogunwale | 4cea0f5 | 2015-12-25 06:30:31 -0800 | [diff] [blame] | 679 | void setFocusStackUnchecked(String reason, ActivityStack focusCandidate) { |
| 680 | if (!focusCandidate.isFocusable()) { |
| 681 | // The focus candidate isn't focusable. Move focus to the top stack that is focusable. |
Andrii Kulian | 7fc2281 | 2016-12-28 13:04:11 -0800 | [diff] [blame] | 682 | focusCandidate = getNextFocusableStackLocked(focusCandidate); |
Wale Ogunwale | 4cea0f5 | 2015-12-25 06:30:31 -0800 | [diff] [blame] | 683 | } |
| 684 | |
| 685 | if (focusCandidate != mFocusedStack) { |
Wale Ogunwale | d046a01 | 2015-12-24 13:05:59 -0800 | [diff] [blame] | 686 | mLastFocusedStack = mFocusedStack; |
Wale Ogunwale | 4cea0f5 | 2015-12-25 06:30:31 -0800 | [diff] [blame] | 687 | mFocusedStack = focusCandidate; |
Wale Ogunwale | cb82f30 | 2015-02-25 07:53:40 -0800 | [diff] [blame] | 688 | |
Wale Ogunwale | d046a01 | 2015-12-24 13:05:59 -0800 | [diff] [blame] | 689 | EventLogTags.writeAmFocusedStack( |
| 690 | mCurrentUser, mFocusedStack == null ? -1 : mFocusedStack.getStackId(), |
| 691 | mLastFocusedStack == null ? -1 : mLastFocusedStack.getStackId(), reason); |
| 692 | } |
| 693 | |
| 694 | final ActivityRecord r = topRunningActivityLocked(); |
Craig Mautner | f3ea23a | 2015-01-13 09:37:08 -0800 | [diff] [blame] | 695 | if (mService.mBooting || !mService.mBooted) { |
Craig Mautner | f3ea23a | 2015-01-13 09:37:08 -0800 | [diff] [blame] | 696 | if (r != null && r.idle) { |
| 697 | checkFinishBootingLocked(); |
| 698 | } |
| 699 | } |
Craig Mautner | de4ef02 | 2013-04-07 19:01:33 -0700 | [diff] [blame] | 700 | } |
| 701 | |
Wale Ogunwale | 925d0d1 | 2015-09-23 15:40:07 -0700 | [diff] [blame] | 702 | void moveHomeStackToFront(String reason) { |
| 703 | mHomeStack.moveToFront(reason); |
| 704 | } |
| 705 | |
Matthew Ng | 330757d | 2017-02-28 14:19:17 -0800 | [diff] [blame] | 706 | void moveRecentsStackToFront(String reason) { |
Wale Ogunwale | 04a05ac | 2017-09-17 21:35:02 -0700 | [diff] [blame] | 707 | final ActivityStack recentsStack = getDefaultDisplay().getStack( |
| 708 | WINDOWING_MODE_UNDEFINED, ACTIVITY_TYPE_RECENTS); |
Matthew Ng | 330757d | 2017-02-28 14:19:17 -0800 | [diff] [blame] | 709 | if (recentsStack != null) { |
| 710 | recentsStack.moveToFront(reason); |
| 711 | } |
| 712 | } |
| 713 | |
Wale Ogunwale | d80c263 | 2015-03-13 10:26:26 -0700 | [diff] [blame] | 714 | /** Returns true if the focus activity was adjusted to the home stack top activity. */ |
Matthew Ng | ae1ff4f | 2016-11-10 15:49:14 -0800 | [diff] [blame] | 715 | boolean moveHomeStackTaskToTop(String reason) { |
| 716 | mHomeStack.moveHomeStackTaskToTop(); |
Wale Ogunwale | d80c263 | 2015-03-13 10:26:26 -0700 | [diff] [blame] | 717 | |
Wale Ogunwale | 2d0f39b | 2015-04-17 15:35:39 -0700 | [diff] [blame] | 718 | final ActivityRecord top = getHomeActivity(); |
Wale Ogunwale | d80c263 | 2015-03-13 10:26:26 -0700 | [diff] [blame] | 719 | if (top == null) { |
| 720 | return false; |
| 721 | } |
Chong Zhang | 6cda19c | 2016-06-14 19:07:56 -0700 | [diff] [blame] | 722 | moveFocusableActivityStackToFrontLocked(top, reason); |
Wale Ogunwale | d80c263 | 2015-03-13 10:26:26 -0700 | [diff] [blame] | 723 | return true; |
Craig Mautner | 8e56957 | 2013-10-11 17:36:59 -0700 | [diff] [blame] | 724 | } |
| 725 | |
Matthew Ng | ae1ff4f | 2016-11-10 15:49:14 -0800 | [diff] [blame] | 726 | boolean resumeHomeStackTask(ActivityRecord prev, String reason) { |
Dianne Hackborn | 7622a0f | 2014-09-30 14:31:42 -0700 | [diff] [blame] | 727 | if (!mService.mBooting && !mService.mBooted) { |
| 728 | // Not ready yet! |
| 729 | return false; |
| 730 | } |
| 731 | |
Matthew Ng | ae1ff4f | 2016-11-10 15:49:14 -0800 | [diff] [blame] | 732 | mHomeStack.moveHomeStackTaskToTop(); |
Wale Ogunwale | 2d0f39b | 2015-04-17 15:35:39 -0700 | [diff] [blame] | 733 | ActivityRecord r = getHomeActivity(); |
Wale Ogunwale | d046a01 | 2015-12-24 13:05:59 -0800 | [diff] [blame] | 734 | final String myReason = reason + " resumeHomeStackTask"; |
| 735 | |
Mark Lu | a56ea12 | 2015-10-08 13:31:01 +0800 | [diff] [blame] | 736 | // Only resume home activity if isn't finishing. |
| 737 | if (r != null && !r.finishing) { |
Chong Zhang | 6cda19c | 2016-06-14 19:07:56 -0700 | [diff] [blame] | 738 | moveFocusableActivityStackToFrontLocked(r, myReason); |
Wale Ogunwale | d046a01 | 2015-12-24 13:05:59 -0800 | [diff] [blame] | 739 | return resumeFocusedStackTopActivityLocked(mHomeStack, prev, null); |
Craig Mautner | 69ada55 | 2013-04-18 13:51:51 -0700 | [diff] [blame] | 740 | } |
Wale Ogunwale | d046a01 | 2015-12-24 13:05:59 -0800 | [diff] [blame] | 741 | return mService.startHomeActivityLocked(mCurrentUser, myReason); |
Craig Mautner | 69ada55 | 2013-04-18 13:51:51 -0700 | [diff] [blame] | 742 | } |
| 743 | |
Craig Mautner | 8d341ef | 2013-03-26 09:03:27 -0700 | [diff] [blame] | 744 | TaskRecord anyTaskForIdLocked(int id) { |
Wale Ogunwale | 0568aed | 2017-09-08 13:29:37 -0700 | [diff] [blame] | 745 | return anyTaskForIdLocked(id, MATCH_TASK_IN_STACKS_OR_RECENT_TASKS_AND_RESTORE); |
| 746 | } |
| 747 | |
| 748 | TaskRecord anyTaskForIdLocked(int id, @AnyTaskForIdMatchTaskMode int matchMode) { |
Wale Ogunwale | ab5de37 | 2017-10-18 06:46:31 -0700 | [diff] [blame] | 749 | return anyTaskForIdLocked(id, matchMode, null, !ON_TOP); |
Wale Ogunwale | 04f4d6b | 2015-03-11 09:23:25 -0700 | [diff] [blame] | 750 | } |
| 751 | |
| 752 | /** |
Bryce Lee | 92b7b65 | 2017-04-03 08:33:11 -0700 | [diff] [blame] | 753 | * 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] | 754 | * @param id Id of the task we would like returned. |
Winson Chung | 7900bee | 2017-03-10 08:59:25 -0800 | [diff] [blame] | 755 | * @param matchMode The mode to match the given task id in. |
Wale Ogunwale | 0568aed | 2017-09-08 13:29:37 -0700 | [diff] [blame] | 756 | * @param aOptions The activity options to use for restoration. Can be null. |
Wale Ogunwale | ab5de37 | 2017-10-18 06:46:31 -0700 | [diff] [blame] | 757 | * @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] | 758 | */ |
Wale Ogunwale | 0568aed | 2017-09-08 13:29:37 -0700 | [diff] [blame] | 759 | TaskRecord anyTaskForIdLocked(int id, @AnyTaskForIdMatchTaskMode int matchMode, |
Wale Ogunwale | ab5de37 | 2017-10-18 06:46:31 -0700 | [diff] [blame] | 760 | @Nullable ActivityOptions aOptions, boolean onTop) { |
| 761 | // 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] | 762 | if (matchMode != MATCH_TASK_IN_STACKS_OR_RECENT_TASKS_AND_RESTORE && aOptions != null) { |
| 763 | throw new IllegalArgumentException("Should not specify activity options for non-restore" |
| 764 | + " lookup"); |
Winson Chung | 7900bee | 2017-03-10 08:59:25 -0800 | [diff] [blame] | 765 | } |
| 766 | |
Craig Mautner | e0a3884 | 2013-12-16 16:14:02 -0800 | [diff] [blame] | 767 | int numDisplays = mActivityDisplays.size(); |
Craig Mautner | 4a1cb22 | 2013-12-04 16:14:06 -0800 | [diff] [blame] | 768 | for (int displayNdx = 0; displayNdx < numDisplays; ++displayNdx) { |
Wale Ogunwale | a0f5b5e | 2017-10-11 09:37:23 -0700 | [diff] [blame] | 769 | final ActivityDisplay display = mActivityDisplays.valueAt(displayNdx); |
| 770 | for (int stackNdx = display.getChildCount() - 1; stackNdx >= 0; --stackNdx) { |
| 771 | final ActivityStack stack = display.getChildAt(stackNdx); |
Bryce Lee | 92b7b65 | 2017-04-03 08:33:11 -0700 | [diff] [blame] | 772 | final TaskRecord task = stack.taskForIdLocked(id); |
Wale Ogunwale | ab5de37 | 2017-10-18 06:46:31 -0700 | [diff] [blame] | 773 | if (task == null) { |
| 774 | continue; |
Craig Mautner | 4a1cb22 | 2013-12-04 16:14:06 -0800 | [diff] [blame] | 775 | } |
Wale Ogunwale | ab5de37 | 2017-10-18 06:46:31 -0700 | [diff] [blame] | 776 | if (aOptions != null) { |
| 777 | // Resolve the stack the task should be placed in now based on options |
| 778 | // and reparent if needed. |
| 779 | final ActivityStack launchStack = getLaunchStack(null, aOptions, task, onTop); |
| 780 | if (launchStack != null && stack != launchStack) { |
| 781 | final int reparentMode = onTop |
| 782 | ? REPARENT_MOVE_STACK_TO_FRONT : REPARENT_LEAVE_STACK_IN_PLACE; |
| 783 | task.reparent(launchStack, onTop, reparentMode, ANIMATE, DEFER_RESUME, |
| 784 | "anyTaskForIdLocked"); |
| 785 | } |
| 786 | } |
| 787 | return task; |
Craig Mautner | 8d341ef | 2013-03-26 09:03:27 -0700 | [diff] [blame] | 788 | } |
| 789 | } |
Wale Ogunwale | 7de0535 | 2014-12-12 15:21:33 -0800 | [diff] [blame] | 790 | |
Winson Chung | 7900bee | 2017-03-10 08:59:25 -0800 | [diff] [blame] | 791 | // If we are matching stack tasks only, return now |
| 792 | if (matchMode == MATCH_TASK_IN_STACKS_ONLY) { |
Wale Ogunwale | 7de0535 | 2014-12-12 15:21:33 -0800 | [diff] [blame] | 793 | return null; |
| 794 | } |
| 795 | |
Winson Chung | 7900bee | 2017-03-10 08:59:25 -0800 | [diff] [blame] | 796 | // Otherwise, check the recent tasks and return if we find it there and we are not restoring |
| 797 | // the task from recents |
| 798 | 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] | 799 | final TaskRecord task = mRecentTasks.getTask(id); |
Bryce Lee | 92b7b65 | 2017-04-03 08:33:11 -0700 | [diff] [blame] | 800 | |
| 801 | if (task == null) { |
| 802 | if (DEBUG_RECENTS) { |
Winson Chung | 7900bee | 2017-03-10 08:59:25 -0800 | [diff] [blame] | 803 | Slog.d(TAG_RECENTS, "\tDidn't find task id=" + id + " in recents"); |
| 804 | } |
Bryce Lee | 92b7b65 | 2017-04-03 08:33:11 -0700 | [diff] [blame] | 805 | |
| 806 | return null; |
| 807 | } |
| 808 | |
| 809 | if (matchMode == MATCH_TASK_IN_STACKS_OR_RECENT_TASKS) { |
Wale Ogunwale | 04f4d6b | 2015-03-11 09:23:25 -0700 | [diff] [blame] | 810 | return task; |
| 811 | } |
| 812 | |
Winson Chung | 7900bee | 2017-03-10 08:59:25 -0800 | [diff] [blame] | 813 | // 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] | 814 | if (!restoreRecentTaskLocked(task, aOptions, onTop)) { |
Wale Ogunwale | ee006da | 2015-03-30 14:49:25 -0700 | [diff] [blame] | 815 | if (DEBUG_RECENTS) Slog.w(TAG_RECENTS, |
| 816 | "Couldn't restore task id=" + id + " found in recents"); |
Wale Ogunwale | 7de0535 | 2014-12-12 15:21:33 -0800 | [diff] [blame] | 817 | return null; |
| 818 | } |
Wale Ogunwale | ee006da | 2015-03-30 14:49:25 -0700 | [diff] [blame] | 819 | 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] | 820 | return task; |
Craig Mautner | 8d341ef | 2013-03-26 09:03:27 -0700 | [diff] [blame] | 821 | } |
| 822 | |
Craig Mautner | 6170f73 | 2013-04-02 13:05:23 -0700 | [diff] [blame] | 823 | ActivityRecord isInAnyStackLocked(IBinder token) { |
Craig Mautner | e0a3884 | 2013-12-16 16:14:02 -0800 | [diff] [blame] | 824 | int numDisplays = mActivityDisplays.size(); |
Craig Mautner | 4a1cb22 | 2013-12-04 16:14:06 -0800 | [diff] [blame] | 825 | for (int displayNdx = 0; displayNdx < numDisplays; ++displayNdx) { |
Wale Ogunwale | a0f5b5e | 2017-10-11 09:37:23 -0700 | [diff] [blame] | 826 | final ActivityDisplay display = mActivityDisplays.valueAt(displayNdx); |
| 827 | for (int stackNdx = display.getChildCount() - 1; stackNdx >= 0; --stackNdx) { |
| 828 | final ActivityStack stack = display.getChildAt(stackNdx); |
| 829 | final ActivityRecord r = stack.isInStackLocked(token); |
Craig Mautner | 4a1cb22 | 2013-12-04 16:14:06 -0800 | [diff] [blame] | 830 | if (r != null) { |
| 831 | return r; |
| 832 | } |
Craig Mautner | 6170f73 | 2013-04-02 13:05:23 -0700 | [diff] [blame] | 833 | } |
| 834 | } |
| 835 | return null; |
| 836 | } |
| 837 | |
Tony Mak | 853304c | 2016-04-18 15:17:41 +0100 | [diff] [blame] | 838 | /** |
Robin Lee | 3fef1f2 | 2016-12-20 14:50:13 +0000 | [diff] [blame] | 839 | * Detects whether we should show a lock screen in front of this task for a locked user. |
| 840 | * <p> |
| 841 | * We'll do this if either of the following holds: |
| 842 | * <ul> |
| 843 | * <li>The top activity explicitly belongs to {@param userId}.</li> |
| 844 | * <li>The top activity returns a result to an activity belonging to {@param userId}.</li> |
| 845 | * </ul> |
| 846 | * |
| 847 | * @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] | 848 | */ |
Robin Lee | 3fef1f2 | 2016-12-20 14:50:13 +0000 | [diff] [blame] | 849 | private boolean taskTopActivityIsUser(TaskRecord task, @UserIdInt int userId) { |
| 850 | // To handle the case that work app is in the task but just is not the top one. |
| 851 | final ActivityRecord activityRecord = task.getTopActivity(); |
| 852 | final ActivityRecord resultTo = (activityRecord != null ? activityRecord.resultTo : null); |
| 853 | |
| 854 | return (activityRecord != null && activityRecord.userId == userId) |
| 855 | || (resultTo != null && resultTo.userId == userId); |
| 856 | } |
| 857 | |
| 858 | /** |
| 859 | * Find all visible task stacks containing {@param userId} and intercept them with an activity |
| 860 | * to block out the contents and possibly start a credential-confirming intent. |
| 861 | * |
| 862 | * @param userId user handle for the locked managed profile. |
| 863 | */ |
| 864 | void lockAllProfileTasks(@UserIdInt int userId) { |
| 865 | mWindowManager.deferSurfaceLayout(); |
| 866 | try { |
Wale Ogunwale | a0f5b5e | 2017-10-11 09:37:23 -0700 | [diff] [blame] | 867 | for (int displayNdx = mActivityDisplays.size() - 1; displayNdx >= 0; --displayNdx) { |
| 868 | final ActivityDisplay display = mActivityDisplays.valueAt(displayNdx); |
| 869 | for (int stackNdx = display.getChildCount() - 1; stackNdx >= 0; --stackNdx) { |
| 870 | final ActivityStack stack = display.getChildAt(stackNdx); |
| 871 | final List<TaskRecord> tasks = stack.getAllTasks(); |
| 872 | for (int taskNdx = tasks.size() - 1; taskNdx >= 0; taskNdx--) { |
| 873 | final TaskRecord task = tasks.get(taskNdx); |
Robin Lee | 3fef1f2 | 2016-12-20 14:50:13 +0000 | [diff] [blame] | 874 | |
Wale Ogunwale | a0f5b5e | 2017-10-11 09:37:23 -0700 | [diff] [blame] | 875 | // Check the task for a top activity belonging to userId, or returning a |
| 876 | // result to an activity belonging to userId. Example case: a document |
| 877 | // picker for personal files, opened by a work app, should still get locked. |
| 878 | if (taskTopActivityIsUser(task, userId)) { |
| 879 | mService.mTaskChangeNotificationController.notifyTaskProfileLocked( |
| 880 | task.taskId, userId); |
| 881 | } |
Robin Lee | 3fef1f2 | 2016-12-20 14:50:13 +0000 | [diff] [blame] | 882 | } |
Tony Mak | 853304c | 2016-04-18 15:17:41 +0100 | [diff] [blame] | 883 | } |
| 884 | } |
Robin Lee | 3fef1f2 | 2016-12-20 14:50:13 +0000 | [diff] [blame] | 885 | } finally { |
| 886 | mWindowManager.continueSurfaceLayout(); |
Tony Mak | 853304c | 2016-04-18 15:17:41 +0100 | [diff] [blame] | 887 | } |
Clara Bayarri | f0649ce | 2016-01-14 12:30:42 +0000 | [diff] [blame] | 888 | } |
| 889 | |
Suprabh Shukla | 09a88f5 | 2015-12-02 14:36:31 -0800 | [diff] [blame] | 890 | void setNextTaskIdForUserLocked(int taskId, int userId) { |
| 891 | final int currentTaskId = mCurTaskIdForUser.get(userId, -1); |
| 892 | if (taskId > currentTaskId) { |
| 893 | mCurTaskIdForUser.put(userId, taskId); |
Craig Mautner | ef73ee1 | 2014-04-23 11:45:37 -0700 | [diff] [blame] | 894 | } |
| 895 | } |
| 896 | |
Chong Zhang | d9d35bd | 2016-08-04 17:55:21 -0700 | [diff] [blame] | 897 | static int nextTaskIdForUser(int taskId, int userId) { |
| 898 | int nextTaskId = taskId + 1; |
| 899 | if (nextTaskId == (userId + 1) * MAX_TASK_IDS_PER_USER) { |
| 900 | // Wrap around as there will be smaller task ids that are available now. |
| 901 | nextTaskId -= MAX_TASK_IDS_PER_USER; |
| 902 | } |
| 903 | return nextTaskId; |
| 904 | } |
| 905 | |
Suprabh Shukla | 09a88f5 | 2015-12-02 14:36:31 -0800 | [diff] [blame] | 906 | int getNextTaskIdForUserLocked(int userId) { |
Suprabh Shukla | 09a88f5 | 2015-12-02 14:36:31 -0800 | [diff] [blame] | 907 | final int currentTaskId = mCurTaskIdForUser.get(userId, userId * MAX_TASK_IDS_PER_USER); |
| 908 | // for a userId u, a taskId can only be in the range |
| 909 | // [u*MAX_TASK_IDS_PER_USER, (u+1)*MAX_TASK_IDS_PER_USER-1], so if MAX_TASK_IDS_PER_USER |
| 910 | // 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] | 911 | int candidateTaskId = nextTaskIdForUser(currentTaskId, userId); |
Winson Chung | 1dbc811 | 2017-09-28 18:05:31 -0700 | [diff] [blame] | 912 | while (mRecentTasks.containsTaskId(candidateTaskId, userId) |
Wale Ogunwale | 0568aed | 2017-09-08 13:29:37 -0700 | [diff] [blame] | 913 | || anyTaskForIdLocked( |
| 914 | candidateTaskId, MATCH_TASK_IN_STACKS_OR_RECENT_TASKS) != null) { |
Chong Zhang | d9d35bd | 2016-08-04 17:55:21 -0700 | [diff] [blame] | 915 | candidateTaskId = nextTaskIdForUser(candidateTaskId, userId); |
Suprabh Shukla | 09a88f5 | 2015-12-02 14:36:31 -0800 | [diff] [blame] | 916 | if (candidateTaskId == currentTaskId) { |
| 917 | // Something wrong! |
| 918 | // All MAX_TASK_IDS_PER_USER task ids are taken up by running tasks for this user |
| 919 | throw new IllegalStateException("Cannot get an available task id." |
| 920 | + " Reached limit of " + MAX_TASK_IDS_PER_USER |
| 921 | + " running tasks per user."); |
| 922 | } |
| 923 | } |
| 924 | mCurTaskIdForUser.put(userId, candidateTaskId); |
| 925 | return candidateTaskId; |
Craig Mautner | 8d341ef | 2013-03-26 09:03:27 -0700 | [diff] [blame] | 926 | } |
| 927 | |
Chong Zhang | 6cda19c | 2016-06-14 19:07:56 -0700 | [diff] [blame] | 928 | ActivityRecord getResumedActivityLocked() { |
Wale Ogunwale | d697cea | 2015-02-20 17:19:49 -0800 | [diff] [blame] | 929 | ActivityStack stack = mFocusedStack; |
Craig Mautner | ce5f3cb | 2013-04-22 08:58:54 -0700 | [diff] [blame] | 930 | if (stack == null) { |
| 931 | return null; |
| 932 | } |
Craig Mautner | de4ef02 | 2013-04-07 19:01:33 -0700 | [diff] [blame] | 933 | ActivityRecord resumedActivity = stack.mResumedActivity; |
| 934 | if (resumedActivity == null || resumedActivity.app == null) { |
| 935 | resumedActivity = stack.mPausingActivity; |
| 936 | if (resumedActivity == null || resumedActivity.app == null) { |
Filip Gruszczynski | 3e85ba2 | 2015-10-05 22:48:30 -0700 | [diff] [blame] | 937 | resumedActivity = stack.topRunningActivityLocked(); |
Craig Mautner | de4ef02 | 2013-04-07 19:01:33 -0700 | [diff] [blame] | 938 | } |
| 939 | } |
| 940 | return resumedActivity; |
| 941 | } |
| 942 | |
Dianne Hackborn | ff07272 | 2014-09-24 10:56:28 -0700 | [diff] [blame] | 943 | boolean attachApplicationLocked(ProcessRecord app) throws RemoteException { |
Craig Mautner | 20e7227 | 2013-04-01 13:45:53 -0700 | [diff] [blame] | 944 | final String processName = app.processName; |
Craig Mautner | 4a1cb22 | 2013-12-04 16:14:06 -0800 | [diff] [blame] | 945 | boolean didSomething = false; |
Craig Mautner | e0a3884 | 2013-12-16 16:14:02 -0800 | [diff] [blame] | 946 | for (int displayNdx = mActivityDisplays.size() - 1; displayNdx >= 0; --displayNdx) { |
Wale Ogunwale | a0f5b5e | 2017-10-11 09:37:23 -0700 | [diff] [blame] | 947 | final ActivityDisplay display = mActivityDisplays.valueAt(displayNdx); |
| 948 | for (int stackNdx = display.getChildCount() - 1; stackNdx >= 0; --stackNdx) { |
| 949 | final ActivityStack stack = display.getChildAt(stackNdx); |
Wale Ogunwale | 1e60e0c | 2015-10-28 13:36:10 -0700 | [diff] [blame] | 950 | if (!isFocusedStack(stack)) { |
Craig Mautner | 4a1cb22 | 2013-12-04 16:14:06 -0800 | [diff] [blame] | 951 | continue; |
| 952 | } |
Jorim Jaggi | ea039a8 | 2017-08-02 14:37:49 +0200 | [diff] [blame] | 953 | stack.getAllRunningVisibleActivitiesLocked(mTmpActivityList); |
| 954 | final ActivityRecord top = stack.topRunningActivityLocked(); |
| 955 | final int size = mTmpActivityList.size(); |
| 956 | for (int i = 0; i < size; i++) { |
| 957 | final ActivityRecord activity = mTmpActivityList.get(i); |
| 958 | if (activity.app == null && app.uid == activity.info.applicationInfo.uid |
| 959 | && processName.equals(activity.processName)) { |
Craig Mautner | 4a1cb22 | 2013-12-04 16:14:06 -0800 | [diff] [blame] | 960 | try { |
Jorim Jaggi | ea039a8 | 2017-08-02 14:37:49 +0200 | [diff] [blame] | 961 | if (realStartActivityLocked(activity, app, |
| 962 | top == activity /* andResume */, true /* checkConfig */)) { |
Craig Mautner | 4a1cb22 | 2013-12-04 16:14:06 -0800 | [diff] [blame] | 963 | didSomething = true; |
| 964 | } |
Dianne Hackborn | ff07272 | 2014-09-24 10:56:28 -0700 | [diff] [blame] | 965 | } catch (RemoteException e) { |
Craig Mautner | 4a1cb22 | 2013-12-04 16:14:06 -0800 | [diff] [blame] | 966 | Slog.w(TAG, "Exception in new application when starting activity " |
Jorim Jaggi | ea039a8 | 2017-08-02 14:37:49 +0200 | [diff] [blame] | 967 | + top.intent.getComponent().flattenToShortString(), e); |
Craig Mautner | 4a1cb22 | 2013-12-04 16:14:06 -0800 | [diff] [blame] | 968 | throw e; |
Craig Mautner | 20e7227 | 2013-04-01 13:45:53 -0700 | [diff] [blame] | 969 | } |
Craig Mautner | 20e7227 | 2013-04-01 13:45:53 -0700 | [diff] [blame] | 970 | } |
Craig Mautner | 20e7227 | 2013-04-01 13:45:53 -0700 | [diff] [blame] | 971 | } |
| 972 | } |
| 973 | } |
Craig Mautner | b59dcfd | 2013-05-06 13:12:58 -0700 | [diff] [blame] | 974 | if (!didSomething) { |
Filip Gruszczynski | bc5a6c5 | 2015-09-22 13:13:24 -0700 | [diff] [blame] | 975 | ensureActivitiesVisibleLocked(null, 0, !PRESERVE_WINDOWS); |
Craig Mautner | b59dcfd | 2013-05-06 13:12:58 -0700 | [diff] [blame] | 976 | } |
Craig Mautner | 20e7227 | 2013-04-01 13:45:53 -0700 | [diff] [blame] | 977 | return didSomething; |
| 978 | } |
| 979 | |
| 980 | boolean allResumedActivitiesIdle() { |
Craig Mautner | e0a3884 | 2013-12-16 16:14:02 -0800 | [diff] [blame] | 981 | for (int displayNdx = mActivityDisplays.size() - 1; displayNdx >= 0; --displayNdx) { |
Wale Ogunwale | a0f5b5e | 2017-10-11 09:37:23 -0700 | [diff] [blame] | 982 | final ActivityDisplay display = mActivityDisplays.valueAt(displayNdx); |
| 983 | for (int stackNdx = display.getChildCount() - 1; stackNdx >= 0; --stackNdx) { |
| 984 | final ActivityStack stack = display.getChildAt(stackNdx); |
Wale Ogunwale | 1e60e0c | 2015-10-28 13:36:10 -0700 | [diff] [blame] | 985 | if (!isFocusedStack(stack) || stack.numActivities() == 0) { |
Craig Mautner | 4a1cb22 | 2013-12-04 16:14:06 -0800 | [diff] [blame] | 986 | continue; |
| 987 | } |
| 988 | final ActivityRecord resumedActivity = stack.mResumedActivity; |
| 989 | if (resumedActivity == null || !resumedActivity.idle) { |
Wale Ogunwale | 0fc365c | 2015-05-25 19:35:42 -0700 | [diff] [blame] | 990 | if (DEBUG_STATES) Slog.d(TAG_STATES, "allResumedActivitiesIdle: stack=" |
Craig Mautner | 34b73df | 2014-01-12 21:11:08 -0800 | [diff] [blame] | 991 | + stack.mStackId + " " + resumedActivity + " not idle"); |
Craig Mautner | 4a1cb22 | 2013-12-04 16:14:06 -0800 | [diff] [blame] | 992 | return false; |
| 993 | } |
Craig Mautner | 20e7227 | 2013-04-01 13:45:53 -0700 | [diff] [blame] | 994 | } |
| 995 | } |
Wei Wang | 65c7a15 | 2016-06-02 18:51:22 -0700 | [diff] [blame] | 996 | // Send launch end powerhint when idle |
Bryce Lee | d3624e1 | 2017-11-30 08:51:45 -0800 | [diff] [blame] | 997 | sendPowerHintForLaunchEndIfNeeded(); |
Craig Mautner | 20e7227 | 2013-04-01 13:45:53 -0700 | [diff] [blame] | 998 | return true; |
| 999 | } |
| 1000 | |
Craig Mautner | de4ef02 | 2013-04-07 19:01:33 -0700 | [diff] [blame] | 1001 | boolean allResumedActivitiesComplete() { |
Craig Mautner | e0a3884 | 2013-12-16 16:14:02 -0800 | [diff] [blame] | 1002 | for (int displayNdx = mActivityDisplays.size() - 1; displayNdx >= 0; --displayNdx) { |
Wale Ogunwale | a0f5b5e | 2017-10-11 09:37:23 -0700 | [diff] [blame] | 1003 | final ActivityDisplay display = mActivityDisplays.valueAt(displayNdx); |
| 1004 | for (int stackNdx = display.getChildCount() - 1; stackNdx >= 0; --stackNdx) { |
| 1005 | final ActivityStack stack = display.getChildAt(stackNdx); |
Wale Ogunwale | 1e60e0c | 2015-10-28 13:36:10 -0700 | [diff] [blame] | 1006 | if (isFocusedStack(stack)) { |
Craig Mautner | 4a1cb22 | 2013-12-04 16:14:06 -0800 | [diff] [blame] | 1007 | final ActivityRecord r = stack.mResumedActivity; |
Wale Ogunwale | ee006da | 2015-03-30 14:49:25 -0700 | [diff] [blame] | 1008 | if (r != null && r.state != RESUMED) { |
Craig Mautner | 4a1cb22 | 2013-12-04 16:14:06 -0800 | [diff] [blame] | 1009 | return false; |
| 1010 | } |
Craig Mautner | de4ef02 | 2013-04-07 19:01:33 -0700 | [diff] [blame] | 1011 | } |
| 1012 | } |
| 1013 | } |
| 1014 | // TODO: Not sure if this should check if all Paused are complete too. |
Wale Ogunwale | ee006da | 2015-03-30 14:49:25 -0700 | [diff] [blame] | 1015 | if (DEBUG_STACK) Slog.d(TAG_STACK, |
Craig Mautner | 4a1cb22 | 2013-12-04 16:14:06 -0800 | [diff] [blame] | 1016 | "allResumedActivitiesComplete: mLastFocusedStack changing from=" + |
| 1017 | mLastFocusedStack + " to=" + mFocusedStack); |
| 1018 | mLastFocusedStack = mFocusedStack; |
Craig Mautner | de4ef02 | 2013-04-07 19:01:33 -0700 | [diff] [blame] | 1019 | return true; |
| 1020 | } |
| 1021 | |
Wale Ogunwale | a0f5b5e | 2017-10-11 09:37:23 -0700 | [diff] [blame] | 1022 | private boolean allResumedActivitiesVisible() { |
riddle_hsu | db46d6b | 2015-04-01 18:58:07 +0800 | [diff] [blame] | 1023 | boolean foundResumed = false; |
Craig Mautner | e0a3884 | 2013-12-16 16:14:02 -0800 | [diff] [blame] | 1024 | for (int displayNdx = mActivityDisplays.size() - 1; displayNdx >= 0; --displayNdx) { |
Wale Ogunwale | a0f5b5e | 2017-10-11 09:37:23 -0700 | [diff] [blame] | 1025 | final ActivityDisplay display = mActivityDisplays.valueAt(displayNdx); |
| 1026 | for (int stackNdx = display.getChildCount() - 1; stackNdx >= 0; --stackNdx) { |
| 1027 | final ActivityStack stack = display.getChildAt(stackNdx); |
Craig Mautner | 4a1cb22 | 2013-12-04 16:14:06 -0800 | [diff] [blame] | 1028 | final ActivityRecord r = stack.mResumedActivity; |
riddle_hsu | db46d6b | 2015-04-01 18:58:07 +0800 | [diff] [blame] | 1029 | if (r != null) { |
Bryce Lee | 4a19438 | 2017-04-04 14:32:48 -0700 | [diff] [blame] | 1030 | if (!r.nowVisible || mActivitiesWaitingForVisibleActivity.contains(r)) { |
riddle_hsu | db46d6b | 2015-04-01 18:58:07 +0800 | [diff] [blame] | 1031 | return false; |
| 1032 | } |
| 1033 | foundResumed = true; |
Craig Mautner | 4a1cb22 | 2013-12-04 16:14:06 -0800 | [diff] [blame] | 1034 | } |
Craig Mautner | de4ef02 | 2013-04-07 19:01:33 -0700 | [diff] [blame] | 1035 | } |
| 1036 | } |
riddle_hsu | db46d6b | 2015-04-01 18:58:07 +0800 | [diff] [blame] | 1037 | return foundResumed; |
Craig Mautner | de4ef02 | 2013-04-07 19:01:33 -0700 | [diff] [blame] | 1038 | } |
| 1039 | |
Craig Mautner | 2acc389 | 2013-09-23 10:28:14 -0700 | [diff] [blame] | 1040 | /** |
| 1041 | * Pause all activities in either all of the stacks or just the back stacks. |
| 1042 | * @param userLeaving Passed to pauseActivity() to indicate whether to call onUserLeaving(). |
Wale Ogunwale | 950faff | 2016-08-08 09:51:04 -0700 | [diff] [blame] | 1043 | * @param resuming The resuming activity. |
| 1044 | * @param dontWait The resuming activity isn't going to wait for all activities to be paused |
| 1045 | * before resuming. |
Craig Mautner | 2acc389 | 2013-09-23 10:28:14 -0700 | [diff] [blame] | 1046 | * @return true if any activity was paused as a result of this call. |
| 1047 | */ |
Wale Ogunwale | 950faff | 2016-08-08 09:51:04 -0700 | [diff] [blame] | 1048 | boolean pauseBackStacks(boolean userLeaving, ActivityRecord resuming, boolean dontWait) { |
Craig Mautner | cf910b0 | 2013-04-23 11:23:27 -0700 | [diff] [blame] | 1049 | boolean someActivityPaused = false; |
Craig Mautner | e0a3884 | 2013-12-16 16:14:02 -0800 | [diff] [blame] | 1050 | for (int displayNdx = mActivityDisplays.size() - 1; displayNdx >= 0; --displayNdx) { |
Wale Ogunwale | a0f5b5e | 2017-10-11 09:37:23 -0700 | [diff] [blame] | 1051 | final ActivityDisplay display = mActivityDisplays.valueAt(displayNdx); |
| 1052 | for (int stackNdx = display.getChildCount() - 1; stackNdx >= 0; --stackNdx) { |
| 1053 | final ActivityStack stack = display.getChildAt(stackNdx); |
Wale Ogunwale | 1e60e0c | 2015-10-28 13:36:10 -0700 | [diff] [blame] | 1054 | if (!isFocusedStack(stack) && stack.mResumedActivity != null) { |
Wale Ogunwale | 0fc365c | 2015-05-25 19:35:42 -0700 | [diff] [blame] | 1055 | if (DEBUG_STATES) Slog.d(TAG_STATES, "pauseBackStacks: stack=" + stack + |
Craig Mautner | 4a1cb22 | 2013-12-04 16:14:06 -0800 | [diff] [blame] | 1056 | " mResumedActivity=" + stack.mResumedActivity); |
Dianne Hackborn | a4e102e | 2014-09-04 22:52:27 -0700 | [diff] [blame] | 1057 | someActivityPaused |= stack.startPausingLocked(userLeaving, false, resuming, |
| 1058 | dontWait); |
Craig Mautner | 4a1cb22 | 2013-12-04 16:14:06 -0800 | [diff] [blame] | 1059 | } |
Craig Mautner | cf910b0 | 2013-04-23 11:23:27 -0700 | [diff] [blame] | 1060 | } |
| 1061 | } |
| 1062 | return someActivityPaused; |
| 1063 | } |
| 1064 | |
Craig Mautner | de4ef02 | 2013-04-07 19:01:33 -0700 | [diff] [blame] | 1065 | boolean allPausedActivitiesComplete() { |
Craig Mautner | ac6f843 | 2013-07-17 13:24:59 -0700 | [diff] [blame] | 1066 | boolean pausing = true; |
Craig Mautner | e0a3884 | 2013-12-16 16:14:02 -0800 | [diff] [blame] | 1067 | for (int displayNdx = mActivityDisplays.size() - 1; displayNdx >= 0; --displayNdx) { |
Wale Ogunwale | a0f5b5e | 2017-10-11 09:37:23 -0700 | [diff] [blame] | 1068 | final ActivityDisplay display = mActivityDisplays.valueAt(displayNdx); |
| 1069 | for (int stackNdx = display.getChildCount() - 1; stackNdx >= 0; --stackNdx) { |
| 1070 | final ActivityStack stack = display.getChildAt(stackNdx); |
Craig Mautner | 4a1cb22 | 2013-12-04 16:14:06 -0800 | [diff] [blame] | 1071 | final ActivityRecord r = stack.mPausingActivity; |
Wale Ogunwale | ee006da | 2015-03-30 14:49:25 -0700 | [diff] [blame] | 1072 | if (r != null && r.state != PAUSED && r.state != STOPPED && r.state != STOPPING) { |
Craig Mautner | 4a1cb22 | 2013-12-04 16:14:06 -0800 | [diff] [blame] | 1073 | if (DEBUG_STATES) { |
Wale Ogunwale | 0fc365c | 2015-05-25 19:35:42 -0700 | [diff] [blame] | 1074 | Slog.d(TAG_STATES, |
| 1075 | "allPausedActivitiesComplete: r=" + r + " state=" + r.state); |
Craig Mautner | 4a1cb22 | 2013-12-04 16:14:06 -0800 | [diff] [blame] | 1076 | pausing = false; |
| 1077 | } else { |
| 1078 | return false; |
| 1079 | } |
Craig Mautner | ac6f843 | 2013-07-17 13:24:59 -0700 | [diff] [blame] | 1080 | } |
Craig Mautner | de4ef02 | 2013-04-07 19:01:33 -0700 | [diff] [blame] | 1081 | } |
| 1082 | } |
Craig Mautner | ac6f843 | 2013-07-17 13:24:59 -0700 | [diff] [blame] | 1083 | return pausing; |
Craig Mautner | de4ef02 | 2013-04-07 19:01:33 -0700 | [diff] [blame] | 1084 | } |
| 1085 | |
Wale Ogunwale | 2be760d | 2016-02-17 11:16:10 -0800 | [diff] [blame] | 1086 | void cancelInitializingActivities() { |
| 1087 | for (int displayNdx = mActivityDisplays.size() - 1; displayNdx >= 0; --displayNdx) { |
Wale Ogunwale | a0f5b5e | 2017-10-11 09:37:23 -0700 | [diff] [blame] | 1088 | final ActivityDisplay display = mActivityDisplays.valueAt(displayNdx); |
| 1089 | for (int stackNdx = display.getChildCount() - 1; stackNdx >= 0; --stackNdx) { |
| 1090 | final ActivityStack stack = display.getChildAt(stackNdx); |
| 1091 | stack.cancelInitializingActivities(); |
Wale Ogunwale | 2be760d | 2016-02-17 11:16:10 -0800 | [diff] [blame] | 1092 | } |
| 1093 | } |
| 1094 | } |
| 1095 | |
Bryce Lee | 4a19438 | 2017-04-04 14:32:48 -0700 | [diff] [blame] | 1096 | void waitActivityVisible(ComponentName name, WaitResult result) { |
| 1097 | final WaitInfo waitInfo = new WaitInfo(name, result); |
| 1098 | mWaitingForActivityVisible.add(waitInfo); |
| 1099 | } |
| 1100 | |
| 1101 | void cleanupActivity(ActivityRecord r) { |
| 1102 | // Make sure this record is no longer in the pending finishes list. |
| 1103 | // This could happen, for example, if we are trimming activities |
| 1104 | // down to the max limit while they are still waiting to finish. |
| 1105 | mFinishingActivities.remove(r); |
| 1106 | mActivitiesWaitingForVisibleActivity.remove(r); |
| 1107 | |
| 1108 | for (int i = mWaitingForActivityVisible.size() - 1; i >= 0; --i) { |
Wale Ogunwale | 3270f17 | 2017-04-26 07:29:42 -0700 | [diff] [blame] | 1109 | if (mWaitingForActivityVisible.get(i).matches(r.realActivity)) { |
Bryce Lee | 4a19438 | 2017-04-04 14:32:48 -0700 | [diff] [blame] | 1110 | mWaitingForActivityVisible.remove(i); |
| 1111 | } |
| 1112 | } |
| 1113 | } |
| 1114 | |
Craig Mautner | ce5f3cb | 2013-04-22 08:58:54 -0700 | [diff] [blame] | 1115 | void reportActivityVisibleLocked(ActivityRecord r) { |
Dianne Hackborn | 6cfbb71 | 2014-09-17 12:47:35 -0700 | [diff] [blame] | 1116 | sendWaitingVisibleReportLocked(r); |
Dianne Hackborn | 6cfbb71 | 2014-09-17 12:47:35 -0700 | [diff] [blame] | 1117 | } |
| 1118 | |
| 1119 | void sendWaitingVisibleReportLocked(ActivityRecord r) { |
| 1120 | boolean changed = false; |
Bryce Lee | 4a19438 | 2017-04-04 14:32:48 -0700 | [diff] [blame] | 1121 | for (int i = mWaitingForActivityVisible.size() - 1; i >= 0; --i) { |
| 1122 | final WaitInfo w = mWaitingForActivityVisible.get(i); |
Wale Ogunwale | 3270f17 | 2017-04-26 07:29:42 -0700 | [diff] [blame] | 1123 | if (w.matches(r.realActivity)) { |
Bryce Lee | 4a19438 | 2017-04-04 14:32:48 -0700 | [diff] [blame] | 1124 | final WaitResult result = w.getResult(); |
Dianne Hackborn | 6cfbb71 | 2014-09-17 12:47:35 -0700 | [diff] [blame] | 1125 | changed = true; |
Bryce Lee | 4a19438 | 2017-04-04 14:32:48 -0700 | [diff] [blame] | 1126 | result.timeout = false; |
| 1127 | result.who = w.getComponent(); |
| 1128 | result.totalTime = SystemClock.uptimeMillis() - result.thisTime; |
| 1129 | result.thisTime = result.totalTime; |
| 1130 | mWaitingForActivityVisible.remove(w); |
Craig Mautner | ce5f3cb | 2013-04-22 08:58:54 -0700 | [diff] [blame] | 1131 | } |
Craig Mautner | ce5f3cb | 2013-04-22 08:58:54 -0700 | [diff] [blame] | 1132 | } |
Dianne Hackborn | 6cfbb71 | 2014-09-17 12:47:35 -0700 | [diff] [blame] | 1133 | if (changed) { |
| 1134 | mService.notifyAll(); |
| 1135 | } |
Craig Mautner | ce5f3cb | 2013-04-22 08:58:54 -0700 | [diff] [blame] | 1136 | } |
| 1137 | |
Bryce Lee | 5f0e28f | 2018-01-30 16:00:03 -0800 | [diff] [blame] | 1138 | void reportWaitingActivityLaunchedIfNeeded(ActivityRecord r, int result) { |
| 1139 | if (mWaitingActivityLaunched.isEmpty()) { |
| 1140 | return; |
| 1141 | } |
| 1142 | |
| 1143 | if (result != START_DELIVERED_TO_TOP && result != START_TASK_TO_FRONT) { |
| 1144 | return; |
| 1145 | } |
| 1146 | |
Chong Zhang | 5022da3 | 2016-06-21 16:31:37 -0700 | [diff] [blame] | 1147 | boolean changed = false; |
Bryce Lee | 5f0e28f | 2018-01-30 16:00:03 -0800 | [diff] [blame] | 1148 | |
Chong Zhang | 5022da3 | 2016-06-21 16:31:37 -0700 | [diff] [blame] | 1149 | for (int i = mWaitingActivityLaunched.size() - 1; i >= 0; i--) { |
| 1150 | WaitResult w = mWaitingActivityLaunched.remove(i); |
| 1151 | if (w.who == null) { |
| 1152 | changed = true; |
Bryce Lee | 5f0e28f | 2018-01-30 16:00:03 -0800 | [diff] [blame] | 1153 | w.result = result; |
| 1154 | |
| 1155 | // Unlike START_TASK_TO_FRONT, When an intent is delivered to top, there |
| 1156 | // will be no followup launch signals. Assign the result and launched component. |
| 1157 | if (result == START_DELIVERED_TO_TOP) { |
| 1158 | w.who = r.realActivity; |
| 1159 | } |
Chong Zhang | 5022da3 | 2016-06-21 16:31:37 -0700 | [diff] [blame] | 1160 | } |
| 1161 | } |
Bryce Lee | 5f0e28f | 2018-01-30 16:00:03 -0800 | [diff] [blame] | 1162 | |
Chong Zhang | 5022da3 | 2016-06-21 16:31:37 -0700 | [diff] [blame] | 1163 | if (changed) { |
| 1164 | mService.notifyAll(); |
| 1165 | } |
| 1166 | } |
| 1167 | |
Craig Mautner | ce5f3cb | 2013-04-22 08:58:54 -0700 | [diff] [blame] | 1168 | void reportActivityLaunchedLocked(boolean timeout, ActivityRecord r, |
| 1169 | long thisTime, long totalTime) { |
Dianne Hackborn | 6cfbb71 | 2014-09-17 12:47:35 -0700 | [diff] [blame] | 1170 | boolean changed = false; |
Craig Mautner | ce5f3cb | 2013-04-22 08:58:54 -0700 | [diff] [blame] | 1171 | for (int i = mWaitingActivityLaunched.size() - 1; i >= 0; i--) { |
Craig Mautner | c64f73e | 2013-04-24 16:44:56 -0700 | [diff] [blame] | 1172 | WaitResult w = mWaitingActivityLaunched.remove(i); |
Dianne Hackborn | 6cfbb71 | 2014-09-17 12:47:35 -0700 | [diff] [blame] | 1173 | if (w.who == null) { |
| 1174 | changed = true; |
| 1175 | w.timeout = timeout; |
| 1176 | if (r != null) { |
| 1177 | w.who = new ComponentName(r.info.packageName, r.info.name); |
| 1178 | } |
| 1179 | w.thisTime = thisTime; |
| 1180 | w.totalTime = totalTime; |
Chong Zhang | 5022da3 | 2016-06-21 16:31:37 -0700 | [diff] [blame] | 1181 | // Do not modify w.result. |
Craig Mautner | ce5f3cb | 2013-04-22 08:58:54 -0700 | [diff] [blame] | 1182 | } |
Craig Mautner | ce5f3cb | 2013-04-22 08:58:54 -0700 | [diff] [blame] | 1183 | } |
Dianne Hackborn | 6cfbb71 | 2014-09-17 12:47:35 -0700 | [diff] [blame] | 1184 | if (changed) { |
| 1185 | mService.notifyAll(); |
| 1186 | } |
Craig Mautner | ce5f3cb | 2013-04-22 08:58:54 -0700 | [diff] [blame] | 1187 | } |
| 1188 | |
Craig Mautner | 29219d9 | 2013-04-16 20:19:12 -0700 | [diff] [blame] | 1189 | ActivityRecord topRunningActivityLocked() { |
Wale Ogunwale | d697cea | 2015-02-20 17:19:49 -0800 | [diff] [blame] | 1190 | final ActivityStack focusedStack = mFocusedStack; |
Filip Gruszczynski | 3e85ba2 | 2015-10-05 22:48:30 -0700 | [diff] [blame] | 1191 | ActivityRecord r = focusedStack.topRunningActivityLocked(); |
Craig Mautner | 1602ec2 | 2013-05-12 10:24:27 -0700 | [diff] [blame] | 1192 | if (r != null) { |
| 1193 | return r; |
Craig Mautner | 29219d9 | 2013-04-16 20:19:12 -0700 | [diff] [blame] | 1194 | } |
Craig Mautner | 1602ec2 | 2013-05-12 10:24:27 -0700 | [diff] [blame] | 1195 | |
Andrii Kulian | 7318d63 | 2016-07-20 18:59:28 -0700 | [diff] [blame] | 1196 | // Look in other non-focused and non-home stacks. |
Andrii Kulian | 7d95df4 | 2017-02-15 10:11:48 -0800 | [diff] [blame] | 1197 | mWindowManager.getDisplaysInFocusOrder(mTmpOrderedDisplayIds); |
| 1198 | |
| 1199 | for (int i = mTmpOrderedDisplayIds.size() - 1; i >= 0; --i) { |
| 1200 | final int displayId = mTmpOrderedDisplayIds.get(i); |
Wale Ogunwale | a0f5b5e | 2017-10-11 09:37:23 -0700 | [diff] [blame] | 1201 | final ActivityDisplay display = mActivityDisplays.get(displayId); |
| 1202 | for (int j = display.getChildCount() - 1; j >= 0; --j) { |
| 1203 | final ActivityStack stack = display.getChildAt(j); |
| 1204 | if (stack != focusedStack && stack.isTopStackOnDisplay() && stack.isFocusable()) { |
Andrii Kulian | 7d95df4 | 2017-02-15 10:11:48 -0800 | [diff] [blame] | 1205 | r = stack.topRunningActivityLocked(); |
| 1206 | if (r != null) { |
| 1207 | return r; |
| 1208 | } |
Craig Mautner | 29219d9 | 2013-04-16 20:19:12 -0700 | [diff] [blame] | 1209 | } |
| 1210 | } |
| 1211 | } |
| 1212 | return null; |
| 1213 | } |
| 1214 | |
Winson Chung | 61c9e5a | 2017-10-11 10:39:32 -0700 | [diff] [blame] | 1215 | @VisibleForTesting |
| 1216 | void getRunningTasks(int maxNum, List<RunningTaskInfo> list, |
| 1217 | @ActivityType int ignoreActivityType, @WindowingMode int ignoreWindowingMode, |
| 1218 | int callingUid, boolean allowed) { |
| 1219 | mRunningTasks.getTasks(maxNum, list, ignoreActivityType, ignoreWindowingMode, |
| 1220 | mActivityDisplays, callingUid, allowed); |
Craig Mautner | 20e7227 | 2013-04-01 13:45:53 -0700 | [diff] [blame] | 1221 | } |
| 1222 | |
Todd Kennedy | 7440f17 | 2015-12-09 14:31:22 -0800 | [diff] [blame] | 1223 | ActivityInfo resolveActivity(Intent intent, ResolveInfo rInfo, int startFlags, |
| 1224 | ProfilerInfo profilerInfo) { |
| 1225 | final ActivityInfo aInfo = rInfo != null ? rInfo.activityInfo : null; |
Craig Mautner | 23ac33b | 2013-04-01 16:26:35 -0700 | [diff] [blame] | 1226 | if (aInfo != null) { |
| 1227 | // Store the found target back into the intent, because now that |
| 1228 | // we have it we never want to do this again. For example, if the |
| 1229 | // user navigates back to this point in the history, we should |
| 1230 | // always restart the exact same activity. |
| 1231 | intent.setComponent(new ComponentName( |
| 1232 | aInfo.applicationInfo.packageName, aInfo.name)); |
| 1233 | |
| 1234 | // Don't debug things in the system process |
Man Cao | cfa78b2 | 2015-06-11 20:14:34 -0700 | [diff] [blame] | 1235 | if (!aInfo.processName.equals("system")) { |
| 1236 | if ((startFlags & ActivityManager.START_FLAG_DEBUG) != 0) { |
Chong Zhang | d25944e | 2016-06-09 16:15:27 -0700 | [diff] [blame] | 1237 | mService.setDebugApp(aInfo.processName, true, false); |
Craig Mautner | 23ac33b | 2013-04-01 16:26:35 -0700 | [diff] [blame] | 1238 | } |
Craig Mautner | 23ac33b | 2013-04-01 16:26:35 -0700 | [diff] [blame] | 1239 | |
Tamas Berghammer | df6cb28 | 2016-01-29 12:07:00 +0000 | [diff] [blame] | 1240 | if ((startFlags & ActivityManager.START_FLAG_NATIVE_DEBUGGING) != 0) { |
| 1241 | mService.setNativeDebuggingAppLocked(aInfo.applicationInfo, aInfo.processName); |
| 1242 | } |
| 1243 | |
Man Cao | cfa78b2 | 2015-06-11 20:14:34 -0700 | [diff] [blame] | 1244 | if ((startFlags & ActivityManager.START_FLAG_TRACK_ALLOCATION) != 0) { |
| 1245 | mService.setTrackAllocationApp(aInfo.applicationInfo, aInfo.processName); |
| 1246 | } |
| 1247 | |
| 1248 | if (profilerInfo != null) { |
Jeff Hao | 1b012d3 | 2014-08-20 10:35:34 -0700 | [diff] [blame] | 1249 | mService.setProfileApp(aInfo.applicationInfo, aInfo.processName, profilerInfo); |
Craig Mautner | 23ac33b | 2013-04-01 16:26:35 -0700 | [diff] [blame] | 1250 | } |
| 1251 | } |
Todd Kennedy | b3b43130 | 2017-03-20 16:05:48 -0700 | [diff] [blame] | 1252 | final String intentLaunchToken = intent.getLaunchToken(); |
| 1253 | if (aInfo.launchToken == null && intentLaunchToken != null) { |
| 1254 | aInfo.launchToken = intentLaunchToken; |
| 1255 | } |
Craig Mautner | 23ac33b | 2013-04-01 16:26:35 -0700 | [diff] [blame] | 1256 | } |
| 1257 | return aInfo; |
| 1258 | } |
| 1259 | |
Todd Kennedy | 7440f17 | 2015-12-09 14:31:22 -0800 | [diff] [blame] | 1260 | ResolveInfo resolveIntent(Intent intent, String resolvedType, int userId) { |
Kenny Guy | b1b3026 | 2016-02-09 16:02:35 +0000 | [diff] [blame] | 1261 | return resolveIntent(intent, resolvedType, userId, 0); |
| 1262 | } |
| 1263 | |
| 1264 | ResolveInfo resolveIntent(Intent intent, String resolvedType, int userId, int flags) { |
Todd Kennedy | 4d1de7d | 2017-02-23 10:32:18 -0800 | [diff] [blame] | 1265 | synchronized (mService) { |
Jorim Jaggi | ffe128d | 2017-11-30 13:54:36 +0100 | [diff] [blame] | 1266 | try { |
| 1267 | Trace.traceBegin(TRACE_TAG_ACTIVITY_MANAGER, "resolveIntent"); |
Patrick Baumann | 577d402 | 2018-01-31 16:55:10 +0000 | [diff] [blame] | 1268 | int modifiedFlags = flags |
| 1269 | | PackageManager.MATCH_DEFAULT_ONLY | ActivityManagerService.STOCK_PM_FLAGS; |
Patrick Baumann | 0da8537 | 2018-02-02 16:07:35 -0800 | [diff] [blame] | 1270 | if (intent.isWebIntent() |
Patrick Baumann | 577d402 | 2018-01-31 16:55:10 +0000 | [diff] [blame] | 1271 | || (intent.getFlags() & Intent.FLAG_ACTIVITY_MATCH_EXTERNAL) != 0) { |
| 1272 | modifiedFlags |= PackageManager.MATCH_INSTANT; |
| 1273 | } |
Jorim Jaggi | ffe128d | 2017-11-30 13:54:36 +0100 | [diff] [blame] | 1274 | return mService.getPackageManagerInternalLocked().resolveIntent( |
Patrick Baumann | 577d402 | 2018-01-31 16:55:10 +0000 | [diff] [blame] | 1275 | intent, resolvedType, modifiedFlags, userId, true); |
Jorim Jaggi | ffe128d | 2017-11-30 13:54:36 +0100 | [diff] [blame] | 1276 | |
| 1277 | } finally { |
| 1278 | Trace.traceEnd(TRACE_TAG_ACTIVITY_MANAGER); |
| 1279 | } |
Todd Kennedy | 7440f17 | 2015-12-09 14:31:22 -0800 | [diff] [blame] | 1280 | } |
Todd Kennedy | 7440f17 | 2015-12-09 14:31:22 -0800 | [diff] [blame] | 1281 | } |
| 1282 | |
| 1283 | ActivityInfo resolveActivity(Intent intent, String resolvedType, int startFlags, |
| 1284 | ProfilerInfo profilerInfo, int userId) { |
| 1285 | final ResolveInfo rInfo = resolveIntent(intent, resolvedType, userId); |
| 1286 | return resolveActivity(intent, rInfo, startFlags, profilerInfo); |
| 1287 | } |
| 1288 | |
Wale Ogunwale | 5658e4b | 2016-02-12 12:22:19 -0800 | [diff] [blame] | 1289 | final boolean realStartActivityLocked(ActivityRecord r, ProcessRecord app, |
| 1290 | boolean andResume, boolean checkConfig) throws RemoteException { |
| 1291 | |
| 1292 | if (!allPausedActivitiesComplete()) { |
| 1293 | // While there are activities pausing we skipping starting any new activities until |
| 1294 | // pauses are complete. NOTE: that we also do this for activities that are starting in |
| 1295 | // the paused state because they will first be resumed then paused on the client side. |
| 1296 | if (DEBUG_SWITCH || DEBUG_PAUSE || DEBUG_STATES) Slog.v(TAG_PAUSE, |
| 1297 | "realStartActivityLocked: Skipping start of r=" + r |
| 1298 | + " some activities pausing..."); |
| 1299 | return false; |
| 1300 | } |
Craig Mautner | 2420ead | 2013-04-01 17:13:20 -0700 | [diff] [blame] | 1301 | |
Bryce Lee | af691c0 | 2017-03-20 14:20:22 -0700 | [diff] [blame] | 1302 | final TaskRecord task = r.getTask(); |
Andrii Kulian | 02b7a83 | 2016-10-06 23:11:56 -0700 | [diff] [blame] | 1303 | final ActivityStack stack = task.getStack(); |
chaviw | 59b9885 | 2017-06-13 12:05:44 -0700 | [diff] [blame] | 1304 | |
| 1305 | beginDeferResume(); |
| 1306 | |
Craig Mautner | 2420ead | 2013-04-01 17:13:20 -0700 | [diff] [blame] | 1307 | try { |
chaviw | 59b9885 | 2017-06-13 12:05:44 -0700 | [diff] [blame] | 1308 | r.startFreezingScreenLocked(app, 0); |
| 1309 | |
| 1310 | // schedule launch ticks to collect information about slow apps. |
| 1311 | r.startLaunchTickingLocked(); |
| 1312 | |
Dianne Hackborn | 68a0633 | 2017-11-15 17:54:18 -0800 | [diff] [blame] | 1313 | r.setProcess(app); |
chaviw | 59b9885 | 2017-06-13 12:05:44 -0700 | [diff] [blame] | 1314 | |
Jorim Jaggi | 838c245 | 2017-08-28 15:44:43 +0200 | [diff] [blame] | 1315 | if (mKeyguardController.isKeyguardLocked()) { |
| 1316 | r.notifyUnknownVisibilityLaunched(); |
| 1317 | } |
| 1318 | |
chaviw | 59b9885 | 2017-06-13 12:05:44 -0700 | [diff] [blame] | 1319 | // Have the window manager re-evaluate the orientation of the screen based on the new |
| 1320 | // activity order. Note that as a result of this, it can call back into the activity |
| 1321 | // manager with a new orientation. We don't care about that, because the activity is |
| 1322 | // not currently running so we are just restarting it anyway. |
| 1323 | if (checkConfig) { |
| 1324 | final int displayId = r.getDisplayId(); |
| 1325 | final Configuration config = mWindowManager.updateOrientationFromAppTokens( |
| 1326 | getDisplayOverrideConfiguration(displayId), |
| 1327 | r.mayFreezeScreenLocked(app) ? r.appToken : null, displayId); |
| 1328 | // Deferring resume here because we're going to launch new activity shortly. |
| 1329 | // We don't want to perform a redundant launch of the same record while ensuring |
| 1330 | // configurations and trying to resume top activity of focused stack. |
| 1331 | mService.updateDisplayOverrideConfigurationLocked(config, r, true /* deferResume */, |
| 1332 | displayId); |
Craig Mautner | 2420ead | 2013-04-01 17:13:20 -0700 | [diff] [blame] | 1333 | } |
chaviw | 59b9885 | 2017-06-13 12:05:44 -0700 | [diff] [blame] | 1334 | |
| 1335 | if (r.getStack().checkKeyguardVisibility(r, true /* shouldBeVisible */, |
| 1336 | true /* isTop */)) { |
| 1337 | // We only set the visibility to true if the activity is allowed to be visible |
| 1338 | // based on |
| 1339 | // keyguard state. This avoids setting this into motion in window manager that is |
| 1340 | // later cancelled due to later calls to ensure visible activities that set |
| 1341 | // visibility back to false. |
| 1342 | r.setVisibility(true); |
Craig Mautner | 2420ead | 2013-04-01 17:13:20 -0700 | [diff] [blame] | 1343 | } |
chaviw | 59b9885 | 2017-06-13 12:05:44 -0700 | [diff] [blame] | 1344 | |
chaviw | 59b9885 | 2017-06-13 12:05:44 -0700 | [diff] [blame] | 1345 | final int applicationInfoUid = |
| 1346 | (r.info.applicationInfo != null) ? r.info.applicationInfo.uid : -1; |
| 1347 | if ((r.userId != app.userId) || (r.appInfo.uid != applicationInfoUid)) { |
| 1348 | Slog.wtf(TAG, |
| 1349 | "User ID for activity changing for " + r |
| 1350 | + " appInfo.uid=" + r.appInfo.uid |
| 1351 | + " info.ai.uid=" + applicationInfoUid |
| 1352 | + " old=" + r.app + " new=" + app); |
| 1353 | } |
| 1354 | |
| 1355 | app.waitingToKill = null; |
| 1356 | r.launchCount++; |
| 1357 | r.lastLaunchTime = SystemClock.uptimeMillis(); |
| 1358 | |
| 1359 | if (DEBUG_ALL) Slog.v(TAG, "Launching: " + r); |
| 1360 | |
| 1361 | int idx = app.activities.indexOf(r); |
| 1362 | if (idx < 0) { |
| 1363 | app.activities.add(r); |
| 1364 | } |
| 1365 | mService.updateLruProcessLocked(app, true, null); |
| 1366 | mService.updateOomAdjLocked(); |
| 1367 | |
Charles He | ff9b4dff | 2017-09-22 10:18:37 +0100 | [diff] [blame] | 1368 | if (task.mLockTaskAuth == LOCK_TASK_AUTH_LAUNCHABLE |
| 1369 | || task.mLockTaskAuth == LOCK_TASK_AUTH_LAUNCHABLE_PRIV |
| 1370 | || (task.mLockTaskAuth == LOCK_TASK_AUTH_WHITELISTED |
| 1371 | && mService.mLockTaskController.getLockTaskModeState() |
| 1372 | == LOCK_TASK_MODE_LOCKED)) { |
Benjamin Franz | a83859f | 2017-07-03 16:34:14 +0100 | [diff] [blame] | 1373 | mService.mLockTaskController.startLockTaskMode(task, false, 0 /* blank UID */); |
chaviw | 59b9885 | 2017-06-13 12:05:44 -0700 | [diff] [blame] | 1374 | } |
| 1375 | |
| 1376 | try { |
| 1377 | if (app.thread == null) { |
| 1378 | throw new RemoteException(); |
| 1379 | } |
| 1380 | List<ResultInfo> results = null; |
| 1381 | List<ReferrerIntent> newIntents = null; |
| 1382 | if (andResume) { |
| 1383 | // We don't need to deliver new intents and/or set results if activity is going |
| 1384 | // to pause immediately after launch. |
| 1385 | results = r.results; |
| 1386 | newIntents = r.newIntents; |
| 1387 | } |
| 1388 | if (DEBUG_SWITCH) Slog.v(TAG_SWITCH, |
| 1389 | "Launching: " + r + " icicle=" + r.icicle + " with results=" + results |
| 1390 | + " newIntents=" + newIntents + " andResume=" + andResume); |
| 1391 | EventLog.writeEvent(EventLogTags.AM_RESTART_ACTIVITY, r.userId, |
| 1392 | System.identityHashCode(r), task.taskId, r.shortComponentName); |
Wale Ogunwale | 6fbde9f | 2017-08-24 07:24:12 -0700 | [diff] [blame] | 1393 | if (r.isActivityTypeHome()) { |
chaviw | 59b9885 | 2017-06-13 12:05:44 -0700 | [diff] [blame] | 1394 | // Home process is the root process of the task. |
| 1395 | mService.mHomeProcess = task.mActivities.get(0).app; |
| 1396 | } |
| 1397 | mService.notifyPackageUse(r.intent.getComponent().getPackageName(), |
| 1398 | PackageManager.NOTIFY_PACKAGE_USE_ACTIVITY); |
| 1399 | r.sleeping = false; |
| 1400 | r.forceNewConfig = false; |
Alan Viverette | b6a2573 | 2017-11-21 14:49:24 -0500 | [diff] [blame] | 1401 | mService.getAppWarningsLocked().onStartActivity(r); |
chaviw | 59b9885 | 2017-06-13 12:05:44 -0700 | [diff] [blame] | 1402 | mService.showAskCompatModeDialogLocked(r); |
| 1403 | r.compat = mService.compatibilityInfoForPackageLocked(r.info.applicationInfo); |
| 1404 | ProfilerInfo profilerInfo = null; |
| 1405 | if (mService.mProfileApp != null && mService.mProfileApp.equals(app.processName)) { |
| 1406 | if (mService.mProfileProc == null || mService.mProfileProc == app) { |
| 1407 | mService.mProfileProc = app; |
Andreas Gampe | 2b073a0 | 2017-06-22 17:28:57 -0700 | [diff] [blame] | 1408 | ProfilerInfo profilerInfoSvc = mService.mProfilerInfo; |
| 1409 | if (profilerInfoSvc != null && profilerInfoSvc.profileFile != null) { |
| 1410 | if (profilerInfoSvc.profileFd != null) { |
chaviw | 59b9885 | 2017-06-13 12:05:44 -0700 | [diff] [blame] | 1411 | try { |
Andreas Gampe | 2b073a0 | 2017-06-22 17:28:57 -0700 | [diff] [blame] | 1412 | profilerInfoSvc.profileFd = profilerInfoSvc.profileFd.dup(); |
chaviw | 59b9885 | 2017-06-13 12:05:44 -0700 | [diff] [blame] | 1413 | } catch (IOException e) { |
Andreas Gampe | 2b073a0 | 2017-06-22 17:28:57 -0700 | [diff] [blame] | 1414 | profilerInfoSvc.closeFd(); |
Craig Mautner | 2568c3a | 2015-03-26 14:22:34 -0700 | [diff] [blame] | 1415 | } |
| 1416 | } |
chaviw | 59b9885 | 2017-06-13 12:05:44 -0700 | [diff] [blame] | 1417 | |
Andreas Gampe | 2b073a0 | 2017-06-22 17:28:57 -0700 | [diff] [blame] | 1418 | profilerInfo = new ProfilerInfo(profilerInfoSvc); |
Craig Mautner | 2420ead | 2013-04-01 17:13:20 -0700 | [diff] [blame] | 1419 | } |
Craig Mautner | 2420ead | 2013-04-01 17:13:20 -0700 | [diff] [blame] | 1420 | } |
| 1421 | } |
Adam Powell | cfbe9be | 2013-11-06 14:58:58 -0800 | [diff] [blame] | 1422 | |
chaviw | 59b9885 | 2017-06-13 12:05:44 -0700 | [diff] [blame] | 1423 | app.hasShownUi = true; |
| 1424 | app.pendingUiClean = true; |
| 1425 | app.forceProcessStateUpTo(mService.mTopProcessState); |
| 1426 | // Because we could be starting an Activity in the system process this may not go |
| 1427 | // across a Binder interface which would create a new Configuration. Consequently |
| 1428 | // we have to always create a new Configuration here. |
Bryce Lee | a163b76 | 2017-01-24 11:05:01 -0800 | [diff] [blame] | 1429 | |
chaviw | 59b9885 | 2017-06-13 12:05:44 -0700 | [diff] [blame] | 1430 | final MergedConfiguration mergedConfiguration = new MergedConfiguration( |
| 1431 | mService.getGlobalConfiguration(), r.getMergedOverrideConfiguration()); |
| 1432 | r.setLastReportedConfiguration(mergedConfiguration); |
Bryce Lee | a163b76 | 2017-01-24 11:05:01 -0800 | [diff] [blame] | 1433 | |
chaviw | 59b9885 | 2017-06-13 12:05:44 -0700 | [diff] [blame] | 1434 | logIfTransactionTooLarge(r.intent, r.icicle); |
Andrii Kulian | 88e05cb | 2017-12-05 17:21:10 -0800 | [diff] [blame] | 1435 | |
| 1436 | |
| 1437 | // Create activity launch transaction. |
Andrii Kulian | 9c5ea9c | 2017-12-07 09:31:01 -0800 | [diff] [blame] | 1438 | final ClientTransaction clientTransaction = ClientTransaction.obtain(app.thread, |
Andrii Kulian | 88e05cb | 2017-12-05 17:21:10 -0800 | [diff] [blame] | 1439 | r.appToken); |
Andrii Kulian | 9c5ea9c | 2017-12-07 09:31:01 -0800 | [diff] [blame] | 1440 | clientTransaction.addCallback(LaunchActivityItem.obtain(new Intent(r.intent), |
chaviw | 59b9885 | 2017-06-13 12:05:44 -0700 | [diff] [blame] | 1441 | System.identityHashCode(r), r.info, |
| 1442 | // TODO: Have this take the merged configuration instead of separate global |
| 1443 | // and override configs. |
| 1444 | mergedConfiguration.getGlobalConfiguration(), |
| 1445 | mergedConfiguration.getOverrideConfiguration(), r.compat, |
| 1446 | r.launchedFromPackage, task.voiceInteractor, app.repProcState, r.icicle, |
Andrii Kulian | 88e05cb | 2017-12-05 17:21:10 -0800 | [diff] [blame] | 1447 | r.persistentState, results, newIntents, mService.isNextTransitionForward(), |
| 1448 | profilerInfo)); |
| 1449 | |
| 1450 | // Set desired final state. |
| 1451 | final ActivityLifecycleItem lifecycleItem; |
| 1452 | if (andResume) { |
Bryce Lee | d946f86 | 2018-01-16 15:59:47 -0800 | [diff] [blame] | 1453 | lifecycleItem = ResumeActivityItem.obtain(mService.isNextTransitionForward()) |
| 1454 | .setDescription(r.getLifecycleDescription("realStartActivityLocked")); |
Andrii Kulian | 88e05cb | 2017-12-05 17:21:10 -0800 | [diff] [blame] | 1455 | } else { |
Andrii Kulian | 9c5ea9c | 2017-12-07 09:31:01 -0800 | [diff] [blame] | 1456 | lifecycleItem = PauseActivityItem.obtain(); |
Andrii Kulian | 88e05cb | 2017-12-05 17:21:10 -0800 | [diff] [blame] | 1457 | } |
| 1458 | clientTransaction.setLifecycleStateRequest(lifecycleItem); |
| 1459 | |
| 1460 | // Schedule transaction. |
| 1461 | mService.mLifecycleManager.scheduleTransaction(clientTransaction); |
| 1462 | |
Craig Mautner | 2420ead | 2013-04-01 17:13:20 -0700 | [diff] [blame] | 1463 | |
chaviw | 59b9885 | 2017-06-13 12:05:44 -0700 | [diff] [blame] | 1464 | if ((app.info.privateFlags & ApplicationInfo.PRIVATE_FLAG_CANT_SAVE_STATE) != 0) { |
| 1465 | // This may be a heavy-weight process! Note that the package |
| 1466 | // manager will ensure that only activity can run in the main |
| 1467 | // process of the .apk, which is the only thing that will be |
| 1468 | // considered heavy-weight. |
| 1469 | if (app.processName.equals(app.info.packageName)) { |
| 1470 | if (mService.mHeavyWeightProcess != null |
| 1471 | && mService.mHeavyWeightProcess != app) { |
| 1472 | Slog.w(TAG, "Starting new heavy weight process " + app |
| 1473 | + " when already running " |
| 1474 | + mService.mHeavyWeightProcess); |
| 1475 | } |
| 1476 | mService.mHeavyWeightProcess = app; |
| 1477 | Message msg = mService.mHandler.obtainMessage( |
| 1478 | ActivityManagerService.POST_HEAVY_NOTIFICATION_MSG); |
| 1479 | msg.obj = r; |
| 1480 | mService.mHandler.sendMessage(msg); |
Craig Mautner | 2420ead | 2013-04-01 17:13:20 -0700 | [diff] [blame] | 1481 | } |
Craig Mautner | 2420ead | 2013-04-01 17:13:20 -0700 | [diff] [blame] | 1482 | } |
Craig Mautner | 2420ead | 2013-04-01 17:13:20 -0700 | [diff] [blame] | 1483 | |
chaviw | 59b9885 | 2017-06-13 12:05:44 -0700 | [diff] [blame] | 1484 | } catch (RemoteException e) { |
| 1485 | if (r.launchFailed) { |
| 1486 | // This is the second time we failed -- finish activity |
| 1487 | // and give up. |
| 1488 | Slog.e(TAG, "Second failure launching " |
| 1489 | + r.intent.getComponent().flattenToShortString() |
| 1490 | + ", giving up", e); |
| 1491 | mService.appDiedLocked(app); |
| 1492 | stack.requestFinishActivityLocked(r.appToken, Activity.RESULT_CANCELED, null, |
| 1493 | "2nd-crash", false); |
| 1494 | return false; |
| 1495 | } |
Craig Mautner | 2420ead | 2013-04-01 17:13:20 -0700 | [diff] [blame] | 1496 | |
chaviw | 59b9885 | 2017-06-13 12:05:44 -0700 | [diff] [blame] | 1497 | // This is the first time we failed -- restart process and |
| 1498 | // retry. |
| 1499 | r.launchFailed = true; |
| 1500 | app.activities.remove(r); |
| 1501 | throw e; |
| 1502 | } |
| 1503 | } finally { |
| 1504 | endDeferResume(); |
Craig Mautner | 2420ead | 2013-04-01 17:13:20 -0700 | [diff] [blame] | 1505 | } |
| 1506 | |
| 1507 | r.launchFailed = false; |
| 1508 | if (stack.updateLRUListLocked(r)) { |
Filip Gruszczynski | 49b80af | 2015-09-24 09:04:26 -0700 | [diff] [blame] | 1509 | Slog.w(TAG, "Activity " + r + " being launched, but already in LRU list"); |
Craig Mautner | 2420ead | 2013-04-01 17:13:20 -0700 | [diff] [blame] | 1510 | } |
| 1511 | |
Andrii Kulian | b372da6 | 2018-01-18 10:46:24 -0800 | [diff] [blame] | 1512 | // TODO(lifecycler): Resume or pause requests are done as part of launch transaction, |
| 1513 | // so updating the state should be done accordingly. |
chaviw | 59b9885 | 2017-06-13 12:05:44 -0700 | [diff] [blame] | 1514 | if (andResume && readyToResume()) { |
Craig Mautner | 2420ead | 2013-04-01 17:13:20 -0700 | [diff] [blame] | 1515 | // As part of the process of launching, ActivityThread also performs |
| 1516 | // a resume. |
| 1517 | stack.minimalResumeActivityLocked(r); |
| 1518 | } else { |
Wale Ogunwale | d046a01 | 2015-12-24 13:05:59 -0800 | [diff] [blame] | 1519 | // 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] | 1520 | // 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] | 1521 | // current icicle and other state. |
Wale Ogunwale | 0fc365c | 2015-05-25 19:35:42 -0700 | [diff] [blame] | 1522 | if (DEBUG_STATES) Slog.v(TAG_STATES, |
Wale Ogunwale | d046a01 | 2015-12-24 13:05:59 -0800 | [diff] [blame] | 1523 | "Moving to PAUSED: " + r + " (starting in paused state)"); |
| 1524 | r.state = PAUSED; |
Craig Mautner | 2420ead | 2013-04-01 17:13:20 -0700 | [diff] [blame] | 1525 | } |
| 1526 | |
| 1527 | // Launch the new version setup screen if needed. We do this -after- |
| 1528 | // launching the initial activity (that is, home), so that it can have |
| 1529 | // a chance to initialize itself while in the background, making the |
| 1530 | // switch back to it faster and look better. |
Wale Ogunwale | 1e60e0c | 2015-10-28 13:36:10 -0700 | [diff] [blame] | 1531 | if (isFocusedStack(stack)) { |
Bryce Lee | d3624e1 | 2017-11-30 08:51:45 -0800 | [diff] [blame] | 1532 | mService.getActivityStartController().startSetupActivity(); |
Craig Mautner | 2420ead | 2013-04-01 17:13:20 -0700 | [diff] [blame] | 1533 | } |
| 1534 | |
Dianne Hackborn | 465fa39 | 2014-09-14 14:21:18 -0700 | [diff] [blame] | 1535 | // Update any services we are bound to that might care about whether |
| 1536 | // their client may have activities. |
Wale Ogunwale | d6ac762 | 2016-05-26 09:02:25 -0700 | [diff] [blame] | 1537 | if (r.app != null) { |
| 1538 | mService.mServices.updateServiceConnectionActivitiesLocked(r.app); |
| 1539 | } |
Dianne Hackborn | 465fa39 | 2014-09-14 14:21:18 -0700 | [diff] [blame] | 1540 | |
Craig Mautner | 2420ead | 2013-04-01 17:13:20 -0700 | [diff] [blame] | 1541 | return true; |
| 1542 | } |
| 1543 | |
Sudheer Shanka | fab200f | 2017-05-17 20:41:53 -0700 | [diff] [blame] | 1544 | private void logIfTransactionTooLarge(Intent intent, Bundle icicle) { |
| 1545 | int extrasSize = 0; |
| 1546 | if (intent != null) { |
| 1547 | final Bundle extras = intent.getExtras(); |
| 1548 | if (extras != null) { |
| 1549 | extrasSize = extras.getSize(); |
| 1550 | } |
| 1551 | } |
| 1552 | int icicleSize = (icicle == null ? 0 : icicle.getSize()); |
| 1553 | if (extrasSize + icicleSize > 200000) { |
| 1554 | Slog.e(TAG, "Transaction too large, intent: " + intent + ", extras size: " + extrasSize |
| 1555 | + ", icicle size: " + icicleSize); |
| 1556 | } |
| 1557 | } |
| 1558 | |
Craig Mautner | e79d4268 | 2013-04-01 19:01:53 -0700 | [diff] [blame] | 1559 | void startSpecificActivityLocked(ActivityRecord r, |
George Mount | 2c92c97 | 2014-03-20 09:38:23 -0700 | [diff] [blame] | 1560 | boolean andResume, boolean checkConfig) { |
Craig Mautner | e79d4268 | 2013-04-01 19:01:53 -0700 | [diff] [blame] | 1561 | // Is this activity's application already running? |
| 1562 | ProcessRecord app = mService.getProcessRecordLocked(r.processName, |
Dianne Hackborn | 3bc8f78d | 2013-09-19 13:34:35 -0700 | [diff] [blame] | 1563 | r.info.applicationInfo.uid, true); |
Craig Mautner | e79d4268 | 2013-04-01 19:01:53 -0700 | [diff] [blame] | 1564 | |
Andrii Kulian | 02b7a83 | 2016-10-06 23:11:56 -0700 | [diff] [blame] | 1565 | r.getStack().setLaunchTime(r); |
Craig Mautner | e79d4268 | 2013-04-01 19:01:53 -0700 | [diff] [blame] | 1566 | |
| 1567 | if (app != null && app.thread != null) { |
| 1568 | try { |
Dianne Hackborn | 237cefb | 2013-10-22 18:45:27 -0700 | [diff] [blame] | 1569 | if ((r.info.flags&ActivityInfo.FLAG_MULTIPROCESS) == 0 |
| 1570 | || !"android".equals(r.info.packageName)) { |
| 1571 | // Don't add this if it is a platform component that is marked |
| 1572 | // to run in multiple processes, because this is actually |
| 1573 | // part of the framework so doesn't make sense to track as a |
| 1574 | // separate apk in the process. |
Dianne Hackborn | f7097a5 | 2014-05-13 09:56:14 -0700 | [diff] [blame] | 1575 | app.addPackage(r.info.packageName, r.info.applicationInfo.versionCode, |
| 1576 | mService.mProcessStats); |
Dianne Hackborn | 237cefb | 2013-10-22 18:45:27 -0700 | [diff] [blame] | 1577 | } |
George Mount | 2c92c97 | 2014-03-20 09:38:23 -0700 | [diff] [blame] | 1578 | realStartActivityLocked(r, app, andResume, checkConfig); |
Craig Mautner | e79d4268 | 2013-04-01 19:01:53 -0700 | [diff] [blame] | 1579 | return; |
| 1580 | } catch (RemoteException e) { |
| 1581 | Slog.w(TAG, "Exception when starting activity " |
| 1582 | + r.intent.getComponent().flattenToShortString(), e); |
| 1583 | } |
| 1584 | |
| 1585 | // If a dead object exception was thrown -- fall through to |
| 1586 | // restart the application. |
| 1587 | } |
| 1588 | |
| 1589 | mService.startProcessLocked(r.processName, r.info.applicationInfo, true, 0, |
Dianne Hackborn | 3bc8f78d | 2013-09-19 13:34:35 -0700 | [diff] [blame] | 1590 | "activity", r.intent.getComponent(), false, false, true); |
Craig Mautner | e79d4268 | 2013-04-01 19:01:53 -0700 | [diff] [blame] | 1591 | } |
| 1592 | |
Bryce Lee | d3624e1 | 2017-11-30 08:51:45 -0800 | [diff] [blame] | 1593 | void sendPowerHintForLaunchStartIfNeeded(boolean forceSend, ActivityRecord targetActivity) { |
| 1594 | boolean sendHint = forceSend; |
| 1595 | |
| 1596 | if (!sendHint) { |
| 1597 | // If not forced, send power hint when the activity's process is different than the |
| 1598 | // current resumed activity. |
| 1599 | final ActivityRecord resumedActivity = getResumedActivityLocked(); |
| 1600 | sendHint = resumedActivity == null |
| 1601 | || resumedActivity.app == null |
| 1602 | || !resumedActivity.app.equals(targetActivity.app); |
| 1603 | } |
| 1604 | |
| 1605 | if (sendHint && mService.mLocalPowerManager != null) { |
| 1606 | mService.mLocalPowerManager.powerHint(PowerHint.LAUNCH, 1); |
| 1607 | mPowerHintSent = true; |
| 1608 | } |
| 1609 | } |
| 1610 | |
| 1611 | void sendPowerHintForLaunchEndIfNeeded() { |
| 1612 | // Trigger launch power hint if activity is launched |
| 1613 | if (mPowerHintSent && mService.mLocalPowerManager != null) { |
| 1614 | mService.mLocalPowerManager.powerHint(PowerHint.LAUNCH, 0); |
| 1615 | mPowerHintSent = false; |
| 1616 | } |
| 1617 | } |
| 1618 | |
Filip Gruszczynski | 07a0e49 | 2015-12-17 14:16:38 -0800 | [diff] [blame] | 1619 | boolean checkStartAnyActivityPermission(Intent intent, ActivityInfo aInfo, |
Filip Gruszczynski | dc39490 | 2015-12-14 10:20:22 -0800 | [diff] [blame] | 1620 | String resultWho, int requestCode, int callingPid, int callingUid, |
| 1621 | String callingPackage, boolean ignoreTargetSecurity, ProcessRecord callerApp, |
Jorim Jaggi | 4d8d32c | 2018-01-19 15:57:41 +0100 | [diff] [blame] | 1622 | ActivityRecord resultRecord, ActivityStack resultStack) { |
Filip Gruszczynski | dc39490 | 2015-12-14 10:20:22 -0800 | [diff] [blame] | 1623 | final int startAnyPerm = mService.checkPermission(START_ANY_ACTIVITY, callingPid, |
| 1624 | callingUid); |
Andrii Kulian | fb1bf69 | 2017-01-17 11:17:34 -0800 | [diff] [blame] | 1625 | if (startAnyPerm == PERMISSION_GRANTED) { |
Filip Gruszczynski | dc39490 | 2015-12-14 10:20:22 -0800 | [diff] [blame] | 1626 | return true; |
| 1627 | } |
| 1628 | final int componentRestriction = getComponentRestrictionForCallingPackage( |
| 1629 | aInfo, callingPackage, callingPid, callingUid, ignoreTargetSecurity); |
| 1630 | final int actionRestriction = getActionRestrictionForCallingPackage( |
| 1631 | intent.getAction(), callingPackage, callingPid, callingUid); |
| 1632 | if (componentRestriction == ACTIVITY_RESTRICTION_PERMISSION |
| 1633 | || actionRestriction == ACTIVITY_RESTRICTION_PERMISSION) { |
| 1634 | if (resultRecord != null) { |
| 1635 | resultStack.sendActivityResultLocked(-1, |
| 1636 | resultRecord, resultWho, requestCode, |
| 1637 | Activity.RESULT_CANCELED, null); |
| 1638 | } |
| 1639 | final String msg; |
| 1640 | if (actionRestriction == ACTIVITY_RESTRICTION_PERMISSION) { |
| 1641 | msg = "Permission Denial: starting " + intent.toString() |
| 1642 | + " from " + callerApp + " (pid=" + callingPid |
| 1643 | + ", uid=" + callingUid + ")" + " with revoked permission " |
| 1644 | + ACTION_TO_RUNTIME_PERMISSION.get(intent.getAction()); |
| 1645 | } else if (!aInfo.exported) { |
| 1646 | msg = "Permission Denial: starting " + intent.toString() |
| 1647 | + " from " + callerApp + " (pid=" + callingPid |
| 1648 | + ", uid=" + callingUid + ")" |
| 1649 | + " not exported from uid " + aInfo.applicationInfo.uid; |
| 1650 | } else { |
| 1651 | msg = "Permission Denial: starting " + intent.toString() |
| 1652 | + " from " + callerApp + " (pid=" + callingPid |
| 1653 | + ", uid=" + callingUid + ")" |
| 1654 | + " requires " + aInfo.permission; |
| 1655 | } |
| 1656 | Slog.w(TAG, msg); |
| 1657 | throw new SecurityException(msg); |
| 1658 | } |
| 1659 | |
| 1660 | if (actionRestriction == ACTIVITY_RESTRICTION_APPOP) { |
| 1661 | final String message = "Appop Denial: starting " + intent.toString() |
| 1662 | + " from " + callerApp + " (pid=" + callingPid |
| 1663 | + ", uid=" + callingUid + ")" |
| 1664 | + " requires " + AppOpsManager.permissionToOp( |
| 1665 | ACTION_TO_RUNTIME_PERMISSION.get(intent.getAction())); |
| 1666 | Slog.w(TAG, message); |
| 1667 | return false; |
| 1668 | } else if (componentRestriction == ACTIVITY_RESTRICTION_APPOP) { |
| 1669 | final String message = "Appop Denial: starting " + intent.toString() |
| 1670 | + " from " + callerApp + " (pid=" + callingPid |
| 1671 | + ", uid=" + callingUid + ")" |
| 1672 | + " requires appop " + AppOpsManager.permissionToOp(aInfo.permission); |
| 1673 | Slog.w(TAG, message); |
| 1674 | return false; |
| 1675 | } |
Jorim Jaggi | 2adba07 | 2016-03-03 13:43:39 +0100 | [diff] [blame] | 1676 | |
Filip Gruszczynski | dc39490 | 2015-12-14 10:20:22 -0800 | [diff] [blame] | 1677 | return true; |
| 1678 | } |
| 1679 | |
Andrii Kulian | fb1bf69 | 2017-01-17 11:17:34 -0800 | [diff] [blame] | 1680 | /** Check if caller is allowed to launch activities on specified display. */ |
Andrii Kulian | 02689a7 | 2017-07-06 14:28:59 -0700 | [diff] [blame] | 1681 | boolean isCallerAllowedToLaunchOnDisplay(int callingPid, int callingUid, int launchDisplayId, |
| 1682 | ActivityInfo aInfo) { |
Andrii Kulian | fb1bf69 | 2017-01-17 11:17:34 -0800 | [diff] [blame] | 1683 | if (DEBUG_TASKS) Slog.d(TAG, "Launch on display check: displayId=" + launchDisplayId |
| 1684 | + " callingPid=" + callingPid + " callingUid=" + callingUid); |
| 1685 | |
Andrii Kulian | 02689a7 | 2017-07-06 14:28:59 -0700 | [diff] [blame] | 1686 | if (callingPid == -1 && callingUid == -1) { |
| 1687 | if (DEBUG_TASKS) Slog.d(TAG, "Launch on display check: no caller info, skip check"); |
| 1688 | return true; |
| 1689 | } |
| 1690 | |
Andrii Kulian | 62e6f25 | 2017-05-30 22:46:53 -0700 | [diff] [blame] | 1691 | final ActivityDisplay activityDisplay = getActivityDisplayOrCreateLocked(launchDisplayId); |
Andrii Kulian | fb1bf69 | 2017-01-17 11:17:34 -0800 | [diff] [blame] | 1692 | if (activityDisplay == null) { |
| 1693 | Slog.w(TAG, "Launch on display check: display not found"); |
| 1694 | return false; |
| 1695 | } |
| 1696 | |
Andrii Kulian | 02689a7 | 2017-07-06 14:28:59 -0700 | [diff] [blame] | 1697 | // Check if the caller has enough privileges to embed activities and launch to private |
| 1698 | // displays. |
Andrii Kulian | 3a95edc | 2017-06-28 16:21:07 -0700 | [diff] [blame] | 1699 | final int startAnyPerm = mService.checkPermission(INTERNAL_SYSTEM_WINDOW, callingPid, |
Andrii Kulian | 1cba31c | 2017-06-28 09:42:48 -0700 | [diff] [blame] | 1700 | callingUid); |
| 1701 | if (startAnyPerm == PERMISSION_GRANTED) { |
| 1702 | if (DEBUG_TASKS) Slog.d(TAG, "Launch on display check:" |
| 1703 | + " allow launch any on display"); |
| 1704 | return true; |
| 1705 | } |
| 1706 | |
Andrii Kulian | 8f07029 | 2017-09-12 22:56:49 -0700 | [diff] [blame] | 1707 | // Check if caller is already present on display |
| 1708 | final boolean uidPresentOnDisplay = activityDisplay.isUidPresent(callingUid); |
| 1709 | |
Andrii Kulian | 3c9ad07 | 2017-08-01 11:45:22 -0700 | [diff] [blame] | 1710 | final int displayOwnerUid = activityDisplay.mDisplay.getOwnerUid(); |
| 1711 | if (activityDisplay.mDisplay.getType() == TYPE_VIRTUAL && displayOwnerUid != SYSTEM_UID |
| 1712 | && displayOwnerUid != aInfo.applicationInfo.uid) { |
Andrii Kulian | 1cba31c | 2017-06-28 09:42:48 -0700 | [diff] [blame] | 1713 | // Limit launching on virtual displays, because their contents can be read from Surface |
| 1714 | // by apps that created them. |
Andrii Kulian | 02689a7 | 2017-07-06 14:28:59 -0700 | [diff] [blame] | 1715 | if ((aInfo.flags & ActivityInfo.FLAG_ALLOW_EMBEDDED) == 0) { |
| 1716 | if (DEBUG_TASKS) Slog.d(TAG, "Launch on display check:" |
| 1717 | + " disallow launch on virtual display for not-embedded activity."); |
| 1718 | return false; |
| 1719 | } |
Andrii Kulian | 3c9ad07 | 2017-08-01 11:45:22 -0700 | [diff] [blame] | 1720 | // Check if the caller is allowed to embed activities from other apps. |
| 1721 | if (mService.checkPermission(ACTIVITY_EMBEDDING, callingPid, callingUid) |
Andrii Kulian | 8f07029 | 2017-09-12 22:56:49 -0700 | [diff] [blame] | 1722 | == PERMISSION_DENIED && !uidPresentOnDisplay) { |
Andrii Kulian | 3c9ad07 | 2017-08-01 11:45:22 -0700 | [diff] [blame] | 1723 | if (DEBUG_TASKS) Slog.d(TAG, "Launch on display check:" |
| 1724 | + " disallow activity embedding without permission."); |
| 1725 | return false; |
| 1726 | } |
Andrii Kulian | 1cba31c | 2017-06-28 09:42:48 -0700 | [diff] [blame] | 1727 | } |
| 1728 | |
Andrii Kulian | fb1bf69 | 2017-01-17 11:17:34 -0800 | [diff] [blame] | 1729 | if (!activityDisplay.isPrivate()) { |
| 1730 | // Anyone can launch on a public display. |
| 1731 | if (DEBUG_TASKS) Slog.d(TAG, "Launch on display check:" |
| 1732 | + " allow launch on public display"); |
| 1733 | return true; |
| 1734 | } |
| 1735 | |
| 1736 | // Check if the caller is the owner of the display. |
Andrii Kulian | 3c9ad07 | 2017-08-01 11:45:22 -0700 | [diff] [blame] | 1737 | if (displayOwnerUid == callingUid) { |
Andrii Kulian | fb1bf69 | 2017-01-17 11:17:34 -0800 | [diff] [blame] | 1738 | if (DEBUG_TASKS) Slog.d(TAG, "Launch on display check:" |
| 1739 | + " allow launch for owner of the display"); |
| 1740 | return true; |
| 1741 | } |
| 1742 | |
Andrii Kulian | 8f07029 | 2017-09-12 22:56:49 -0700 | [diff] [blame] | 1743 | if (uidPresentOnDisplay) { |
Andrii Kulian | fb1bf69 | 2017-01-17 11:17:34 -0800 | [diff] [blame] | 1744 | if (DEBUG_TASKS) Slog.d(TAG, "Launch on display check:" |
| 1745 | + " allow launch for caller present on the display"); |
| 1746 | return true; |
| 1747 | } |
| 1748 | |
Andrii Kulian | fb1bf69 | 2017-01-17 11:17:34 -0800 | [diff] [blame] | 1749 | Slog.w(TAG, "Launch on display check: denied"); |
| 1750 | return false; |
| 1751 | } |
| 1752 | |
| 1753 | /** Update lists of UIDs that are present on displays and have access to them. */ |
| 1754 | void updateUIDsPresentOnDisplay() { |
| 1755 | mDisplayAccessUIDs.clear(); |
| 1756 | for (int displayNdx = mActivityDisplays.size() - 1; displayNdx >= 0; --displayNdx) { |
| 1757 | final ActivityDisplay activityDisplay = mActivityDisplays.valueAt(displayNdx); |
David Stevens | 82ea6cb | 2017-03-03 16:18:50 -0800 | [diff] [blame] | 1758 | // Only bother calculating the whitelist for private displays |
| 1759 | if (activityDisplay.isPrivate()) { |
| 1760 | mDisplayAccessUIDs.append( |
| 1761 | activityDisplay.mDisplayId, activityDisplay.getPresentUIDs()); |
| 1762 | } |
Andrii Kulian | fb1bf69 | 2017-01-17 11:17:34 -0800 | [diff] [blame] | 1763 | } |
| 1764 | // Store updated lists in DisplayManager. Callers from outside of AM should get them there. |
| 1765 | mDisplayManagerInternal.setDisplayAccessUIDs(mDisplayAccessUIDs); |
| 1766 | } |
| 1767 | |
Filip Gruszczynski | 07a0e49 | 2015-12-17 14:16:38 -0800 | [diff] [blame] | 1768 | UserInfo getUserInfo(int userId) { |
Clara Bayarri | f7fea16 | 2015-10-22 16:09:52 +0100 | [diff] [blame] | 1769 | final long identity = Binder.clearCallingIdentity(); |
| 1770 | try { |
| 1771 | return UserManager.get(mService.mContext).getUserInfo(userId); |
| 1772 | } finally { |
| 1773 | Binder.restoreCallingIdentity(identity); |
| 1774 | } |
| 1775 | } |
| 1776 | |
Svet Ganov | 99b6043 | 2015-06-27 13:15:22 -0700 | [diff] [blame] | 1777 | private int getComponentRestrictionForCallingPackage(ActivityInfo activityInfo, |
Dianne Hackborn | a7cfbe0 | 2015-07-16 10:52:52 -0700 | [diff] [blame] | 1778 | String callingPackage, int callingPid, int callingUid, boolean ignoreTargetSecurity) { |
Dianne Hackborn | a7cfbe0 | 2015-07-16 10:52:52 -0700 | [diff] [blame] | 1779 | if (!ignoreTargetSecurity && mService.checkComponentPermission(activityInfo.permission, |
| 1780 | callingPid, callingUid, activityInfo.applicationInfo.uid, activityInfo.exported) |
Andrii Kulian | 3c9ad07 | 2017-08-01 11:45:22 -0700 | [diff] [blame] | 1781 | == PERMISSION_DENIED) { |
Svet Ganov | 99b6043 | 2015-06-27 13:15:22 -0700 | [diff] [blame] | 1782 | return ACTIVITY_RESTRICTION_PERMISSION; |
| 1783 | } |
| 1784 | |
Christopher Tate | ff7add0 | 2015-08-17 10:23:22 -0700 | [diff] [blame] | 1785 | if (activityInfo.permission == null) { |
| 1786 | return ACTIVITY_RESTRICTION_NONE; |
| 1787 | } |
| 1788 | |
Svet Ganov | 99b6043 | 2015-06-27 13:15:22 -0700 | [diff] [blame] | 1789 | final int opCode = AppOpsManager.permissionToOpCode(activityInfo.permission); |
| 1790 | if (opCode == AppOpsManager.OP_NONE) { |
| 1791 | return ACTIVITY_RESTRICTION_NONE; |
| 1792 | } |
| 1793 | |
| 1794 | if (mService.mAppOpsService.noteOperation(opCode, callingUid, |
| 1795 | callingPackage) != AppOpsManager.MODE_ALLOWED) { |
Dianne Hackborn | a7cfbe0 | 2015-07-16 10:52:52 -0700 | [diff] [blame] | 1796 | if (!ignoreTargetSecurity) { |
| 1797 | return ACTIVITY_RESTRICTION_APPOP; |
| 1798 | } |
Svet Ganov | 99b6043 | 2015-06-27 13:15:22 -0700 | [diff] [blame] | 1799 | } |
| 1800 | |
| 1801 | return ACTIVITY_RESTRICTION_NONE; |
| 1802 | } |
| 1803 | |
Svetoslav | 7008b51 | 2015-06-24 18:47:07 -0700 | [diff] [blame] | 1804 | private int getActionRestrictionForCallingPackage(String action, |
| 1805 | String callingPackage, int callingPid, int callingUid) { |
| 1806 | if (action == null) { |
Svet Ganov | 99b6043 | 2015-06-27 13:15:22 -0700 | [diff] [blame] | 1807 | return ACTIVITY_RESTRICTION_NONE; |
Svetoslav | 7008b51 | 2015-06-24 18:47:07 -0700 | [diff] [blame] | 1808 | } |
| 1809 | |
| 1810 | String permission = ACTION_TO_RUNTIME_PERMISSION.get(action); |
| 1811 | if (permission == null) { |
Svet Ganov | 99b6043 | 2015-06-27 13:15:22 -0700 | [diff] [blame] | 1812 | return ACTIVITY_RESTRICTION_NONE; |
Svetoslav | 7008b51 | 2015-06-24 18:47:07 -0700 | [diff] [blame] | 1813 | } |
| 1814 | |
| 1815 | final PackageInfo packageInfo; |
| 1816 | try { |
| 1817 | packageInfo = mService.mContext.getPackageManager() |
| 1818 | .getPackageInfo(callingPackage, PackageManager.GET_PERMISSIONS); |
| 1819 | } catch (PackageManager.NameNotFoundException e) { |
| 1820 | Slog.i(TAG, "Cannot find package info for " + callingPackage); |
Svet Ganov | 99b6043 | 2015-06-27 13:15:22 -0700 | [diff] [blame] | 1821 | return ACTIVITY_RESTRICTION_NONE; |
Svetoslav | 7008b51 | 2015-06-24 18:47:07 -0700 | [diff] [blame] | 1822 | } |
| 1823 | |
| 1824 | if (!ArrayUtils.contains(packageInfo.requestedPermissions, permission)) { |
Svet Ganov | 99b6043 | 2015-06-27 13:15:22 -0700 | [diff] [blame] | 1825 | return ACTIVITY_RESTRICTION_NONE; |
Svetoslav | 7008b51 | 2015-06-24 18:47:07 -0700 | [diff] [blame] | 1826 | } |
| 1827 | |
Andrii Kulian | 3c9ad07 | 2017-08-01 11:45:22 -0700 | [diff] [blame] | 1828 | if (mService.checkPermission(permission, callingPid, callingUid) == PERMISSION_DENIED) { |
Svet Ganov | 99b6043 | 2015-06-27 13:15:22 -0700 | [diff] [blame] | 1829 | return ACTIVITY_RESTRICTION_PERMISSION; |
Svetoslav | 7008b51 | 2015-06-24 18:47:07 -0700 | [diff] [blame] | 1830 | } |
| 1831 | |
| 1832 | final int opCode = AppOpsManager.permissionToOpCode(permission); |
| 1833 | if (opCode == AppOpsManager.OP_NONE) { |
Svet Ganov | 99b6043 | 2015-06-27 13:15:22 -0700 | [diff] [blame] | 1834 | return ACTIVITY_RESTRICTION_NONE; |
Svetoslav | 7008b51 | 2015-06-24 18:47:07 -0700 | [diff] [blame] | 1835 | } |
| 1836 | |
| 1837 | if (mService.mAppOpsService.noteOperation(opCode, callingUid, |
| 1838 | callingPackage) != AppOpsManager.MODE_ALLOWED) { |
Svet Ganov | 99b6043 | 2015-06-27 13:15:22 -0700 | [diff] [blame] | 1839 | return ACTIVITY_RESTRICTION_APPOP; |
Svetoslav | 7008b51 | 2015-06-24 18:47:07 -0700 | [diff] [blame] | 1840 | } |
| 1841 | |
Svet Ganov | 99b6043 | 2015-06-27 13:15:22 -0700 | [diff] [blame] | 1842 | return ACTIVITY_RESTRICTION_NONE; |
Svetoslav | 7008b51 | 2015-06-24 18:47:07 -0700 | [diff] [blame] | 1843 | } |
| 1844 | |
Dianne Hackborn | 3d07c94 | 2015-03-13 18:02:54 -0700 | [diff] [blame] | 1845 | void setLaunchSource(int uid) { |
| 1846 | mLaunchingActivity.setWorkSource(new WorkSource(uid)); |
| 1847 | } |
| 1848 | |
Craig Mautner | 7ea5bd4 | 2013-07-05 15:27:08 -0700 | [diff] [blame] | 1849 | void acquireLaunchWakelock() { |
| 1850 | if (VALIDATE_WAKE_LOCK_CALLER && Binder.getCallingUid() != Process.myUid()) { |
| 1851 | throw new IllegalStateException("Calling must be system uid"); |
| 1852 | } |
| 1853 | mLaunchingActivity.acquire(); |
| 1854 | if (!mHandler.hasMessages(LAUNCH_TIMEOUT_MSG)) { |
| 1855 | // To be safe, don't allow the wake lock to be held for too long. |
| 1856 | mHandler.sendEmptyMessageDelayed(LAUNCH_TIMEOUT_MSG, LAUNCH_TIMEOUT); |
| 1857 | } |
| 1858 | } |
| 1859 | |
Craig Mautner | f3ea23a | 2015-01-13 09:37:08 -0800 | [diff] [blame] | 1860 | /** |
| 1861 | * Called when the frontmost task is idle. |
| 1862 | * @return the state of mService.mBooting before this was called. |
| 1863 | */ |
Andreas Gampe | a36dc62 | 2018-02-05 17:19:22 -0800 | [diff] [blame] | 1864 | @GuardedBy("mService") |
Craig Mautner | f3ea23a | 2015-01-13 09:37:08 -0800 | [diff] [blame] | 1865 | private boolean checkFinishBootingLocked() { |
| 1866 | final boolean booting = mService.mBooting; |
| 1867 | boolean enableScreen = false; |
| 1868 | mService.mBooting = false; |
| 1869 | if (!mService.mBooted) { |
| 1870 | mService.mBooted = true; |
| 1871 | enableScreen = true; |
| 1872 | } |
| 1873 | if (booting || enableScreen) { |
| 1874 | mService.postFinishBooting(booting, enableScreen); |
| 1875 | } |
| 1876 | return booting; |
| 1877 | } |
| 1878 | |
Craig Mautner | f333327 | 2013-04-22 10:55:53 -0700 | [diff] [blame] | 1879 | // Checked. |
Andreas Gampe | a36dc62 | 2018-02-05 17:19:22 -0800 | [diff] [blame] | 1880 | @GuardedBy("mService") |
Craig Mautner | f333327 | 2013-04-22 10:55:53 -0700 | [diff] [blame] | 1881 | final ActivityRecord activityIdleInternalLocked(final IBinder token, boolean fromTimeout, |
Winson Chung | 4dabf23 | 2017-01-25 13:25:22 -0800 | [diff] [blame] | 1882 | boolean processPausingActivities, Configuration config) { |
Wale Ogunwale | e23149f | 2015-03-06 15:39:44 -0800 | [diff] [blame] | 1883 | if (DEBUG_ALL) Slog.v(TAG, "Activity idle: " + token); |
Craig Mautner | f333327 | 2013-04-22 10:55:53 -0700 | [diff] [blame] | 1884 | |
Craig Mautner | f333327 | 2013-04-22 10:55:53 -0700 | [diff] [blame] | 1885 | ArrayList<ActivityRecord> finishes = null; |
Amith Yamasani | 37a40c2 | 2015-06-17 13:25:42 -0700 | [diff] [blame] | 1886 | ArrayList<UserState> startingUsers = null; |
Craig Mautner | f333327 | 2013-04-22 10:55:53 -0700 | [diff] [blame] | 1887 | int NS = 0; |
| 1888 | int NF = 0; |
Craig Mautner | f333327 | 2013-04-22 10:55:53 -0700 | [diff] [blame] | 1889 | boolean booting = false; |
Craig Mautner | f333327 | 2013-04-22 10:55:53 -0700 | [diff] [blame] | 1890 | boolean activityRemoved = false; |
| 1891 | |
Wale Ogunwale | 7d70117 | 2015-03-11 15:36:30 -0700 | [diff] [blame] | 1892 | ActivityRecord r = ActivityRecord.forTokenLocked(token); |
Craig Mautner | f333327 | 2013-04-22 10:55:53 -0700 | [diff] [blame] | 1893 | if (r != null) { |
Wale Ogunwale | 0fc365c | 2015-05-25 19:35:42 -0700 | [diff] [blame] | 1894 | if (DEBUG_IDLE) Slog.d(TAG_IDLE, "activityIdleInternalLocked: Callers=" |
| 1895 | + Debug.getCallers(4)); |
Craig Mautner | f333327 | 2013-04-22 10:55:53 -0700 | [diff] [blame] | 1896 | mHandler.removeMessages(IDLE_TIMEOUT_MSG, r); |
| 1897 | r.finishLaunchTickingLocked(); |
Craig Mautner | 7ea5bd4 | 2013-07-05 15:27:08 -0700 | [diff] [blame] | 1898 | if (fromTimeout) { |
| 1899 | reportActivityLaunchedLocked(fromTimeout, r, -1, -1); |
Craig Mautner | f333327 | 2013-04-22 10:55:53 -0700 | [diff] [blame] | 1900 | } |
Craig Mautner | 7ea5bd4 | 2013-07-05 15:27:08 -0700 | [diff] [blame] | 1901 | |
| 1902 | // This is a hack to semi-deal with a race condition |
| 1903 | // in the client where it can be constructed with a |
| 1904 | // newer configuration from when we asked it to launch. |
| 1905 | // We'll update with whatever configuration it now says |
| 1906 | // it used to launch. |
| 1907 | if (config != null) { |
Bryce Lee | a163b76 | 2017-01-24 11:05:01 -0800 | [diff] [blame] | 1908 | r.setLastReportedGlobalConfiguration(config); |
Craig Mautner | 7ea5bd4 | 2013-07-05 15:27:08 -0700 | [diff] [blame] | 1909 | } |
| 1910 | |
| 1911 | // We are now idle. If someone is waiting for a thumbnail from |
| 1912 | // us, we can now deliver. |
| 1913 | r.idle = true; |
| 1914 | |
Craig Mautner | 7ea5bd4 | 2013-07-05 15:27:08 -0700 | [diff] [blame] | 1915 | //Slog.i(TAG, "IDLE: mBooted=" + mBooted + ", fromTimeout=" + fromTimeout); |
Andrii Kulian | 02b7a83 | 2016-10-06 23:11:56 -0700 | [diff] [blame] | 1916 | if (isFocusedStack(r.getStack()) || fromTimeout) { |
Craig Mautner | f3ea23a | 2015-01-13 09:37:08 -0800 | [diff] [blame] | 1917 | booting = checkFinishBootingLocked(); |
Craig Mautner | 7ea5bd4 | 2013-07-05 15:27:08 -0700 | [diff] [blame] | 1918 | } |
| 1919 | } |
| 1920 | |
| 1921 | if (allResumedActivitiesIdle()) { |
| 1922 | if (r != null) { |
| 1923 | mService.scheduleAppGcsLocked(); |
Craig Mautner | 7ea5bd4 | 2013-07-05 15:27:08 -0700 | [diff] [blame] | 1924 | } |
| 1925 | |
| 1926 | if (mLaunchingActivity.isHeld()) { |
| 1927 | mHandler.removeMessages(LAUNCH_TIMEOUT_MSG); |
| 1928 | if (VALIDATE_WAKE_LOCK_CALLER && |
| 1929 | Binder.getCallingUid() != Process.myUid()) { |
| 1930 | throw new IllegalStateException("Calling must be system uid"); |
| 1931 | } |
| 1932 | mLaunchingActivity.release(); |
| 1933 | } |
Filip Gruszczynski | bc5a6c5 | 2015-09-22 13:13:24 -0700 | [diff] [blame] | 1934 | ensureActivitiesVisibleLocked(null, 0, !PRESERVE_WINDOWS); |
Craig Mautner | f333327 | 2013-04-22 10:55:53 -0700 | [diff] [blame] | 1935 | } |
| 1936 | |
| 1937 | // Atomically retrieve all of the other things to do. |
Winson Chung | 4dabf23 | 2017-01-25 13:25:22 -0800 | [diff] [blame] | 1938 | final ArrayList<ActivityRecord> stops = processStoppingActivitiesLocked(r, |
| 1939 | true /* remove */, processPausingActivities); |
Craig Mautner | f333327 | 2013-04-22 10:55:53 -0700 | [diff] [blame] | 1940 | NS = stops != null ? stops.size() : 0; |
Wale Ogunwale | 7d70117 | 2015-03-11 15:36:30 -0700 | [diff] [blame] | 1941 | if ((NF = mFinishingActivities.size()) > 0) { |
| 1942 | finishes = new ArrayList<>(mFinishingActivities); |
Craig Mautner | f333327 | 2013-04-22 10:55:53 -0700 | [diff] [blame] | 1943 | mFinishingActivities.clear(); |
| 1944 | } |
| 1945 | |
Craig Mautner | f333327 | 2013-04-22 10:55:53 -0700 | [diff] [blame] | 1946 | if (mStartingUsers.size() > 0) { |
Wale Ogunwale | 7d70117 | 2015-03-11 15:36:30 -0700 | [diff] [blame] | 1947 | startingUsers = new ArrayList<>(mStartingUsers); |
Craig Mautner | f333327 | 2013-04-22 10:55:53 -0700 | [diff] [blame] | 1948 | mStartingUsers.clear(); |
| 1949 | } |
| 1950 | |
Craig Mautner | f333327 | 2013-04-22 10:55:53 -0700 | [diff] [blame] | 1951 | // Stop any activities that are scheduled to do so but have been |
| 1952 | // waiting for the next one to start. |
| 1953 | for (int i = 0; i < NS; i++) { |
| 1954 | r = stops.get(i); |
Andrii Kulian | 02b7a83 | 2016-10-06 23:11:56 -0700 | [diff] [blame] | 1955 | final ActivityStack stack = r.getStack(); |
Wale Ogunwale | 7d70117 | 2015-03-11 15:36:30 -0700 | [diff] [blame] | 1956 | if (stack != null) { |
| 1957 | if (r.finishing) { |
| 1958 | stack.finishCurrentActivityLocked(r, ActivityStack.FINISH_IMMEDIATELY, false); |
| 1959 | } else { |
| 1960 | stack.stopActivityLocked(r); |
| 1961 | } |
Craig Mautner | f333327 | 2013-04-22 10:55:53 -0700 | [diff] [blame] | 1962 | } |
| 1963 | } |
| 1964 | |
| 1965 | // Finish any activities that are scheduled to do so but have been |
| 1966 | // waiting for the next one to start. |
| 1967 | for (int i = 0; i < NF; i++) { |
| 1968 | r = finishes.get(i); |
Andrii Kulian | 02b7a83 | 2016-10-06 23:11:56 -0700 | [diff] [blame] | 1969 | final ActivityStack stack = r.getStack(); |
Wale Ogunwale | 7d70117 | 2015-03-11 15:36:30 -0700 | [diff] [blame] | 1970 | if (stack != null) { |
| 1971 | activityRemoved |= stack.destroyActivityLocked(r, true, "finish-idle"); |
| 1972 | } |
Craig Mautner | f333327 | 2013-04-22 10:55:53 -0700 | [diff] [blame] | 1973 | } |
| 1974 | |
Dianne Hackborn | 7622a0f | 2014-09-30 14:31:42 -0700 | [diff] [blame] | 1975 | if (!booting) { |
Amith Yamasani | 1a7eaaa5 | 2014-05-07 10:22:15 -0700 | [diff] [blame] | 1976 | // Complete user switch |
| 1977 | if (startingUsers != null) { |
| 1978 | for (int i = 0; i < startingUsers.size(); i++) { |
Fyodor Kupolov | 610acda | 2015-10-19 18:44:07 -0700 | [diff] [blame] | 1979 | mService.mUserController.finishUserSwitch(startingUsers.get(i)); |
Amith Yamasani | 1a7eaaa5 | 2014-05-07 10:22:15 -0700 | [diff] [blame] | 1980 | } |
| 1981 | } |
Craig Mautner | f333327 | 2013-04-22 10:55:53 -0700 | [diff] [blame] | 1982 | } |
| 1983 | |
| 1984 | mService.trimApplications(); |
| 1985 | //dump(); |
| 1986 | //mWindowManager.dump(); |
| 1987 | |
Craig Mautner | f333327 | 2013-04-22 10:55:53 -0700 | [diff] [blame] | 1988 | if (activityRemoved) { |
Wale Ogunwale | d046a01 | 2015-12-24 13:05:59 -0800 | [diff] [blame] | 1989 | resumeFocusedStackTopActivityLocked(); |
Craig Mautner | f333327 | 2013-04-22 10:55:53 -0700 | [diff] [blame] | 1990 | } |
| 1991 | |
Craig Mautner | 7ea5bd4 | 2013-07-05 15:27:08 -0700 | [diff] [blame] | 1992 | return r; |
Craig Mautner | f333327 | 2013-04-22 10:55:53 -0700 | [diff] [blame] | 1993 | } |
| 1994 | |
Craig Mautner | 8e56957 | 2013-10-11 17:36:59 -0700 | [diff] [blame] | 1995 | boolean handleAppDiedLocked(ProcessRecord app) { |
Craig Mautner | 1909125 | 2013-10-05 00:03:53 -0700 | [diff] [blame] | 1996 | boolean hasVisibleActivities = false; |
Craig Mautner | e0a3884 | 2013-12-16 16:14:02 -0800 | [diff] [blame] | 1997 | for (int displayNdx = mActivityDisplays.size() - 1; displayNdx >= 0; --displayNdx) { |
Wale Ogunwale | a0f5b5e | 2017-10-11 09:37:23 -0700 | [diff] [blame] | 1998 | final ActivityDisplay display = mActivityDisplays.valueAt(displayNdx); |
| 1999 | for (int stackNdx = display.getChildCount() - 1; stackNdx >= 0; --stackNdx) { |
| 2000 | final ActivityStack stack = display.getChildAt(stackNdx); |
| 2001 | hasVisibleActivities |= stack.handleAppDiedLocked(app); |
Craig Mautner | 4a1cb22 | 2013-12-04 16:14:06 -0800 | [diff] [blame] | 2002 | } |
Craig Mautner | 6b74cb5 | 2013-09-27 17:02:21 -0700 | [diff] [blame] | 2003 | } |
Craig Mautner | 1909125 | 2013-10-05 00:03:53 -0700 | [diff] [blame] | 2004 | return hasVisibleActivities; |
Craig Mautner | 8d341ef | 2013-03-26 09:03:27 -0700 | [diff] [blame] | 2005 | } |
| 2006 | |
| 2007 | void closeSystemDialogsLocked() { |
Craig Mautner | e0a3884 | 2013-12-16 16:14:02 -0800 | [diff] [blame] | 2008 | for (int displayNdx = mActivityDisplays.size() - 1; displayNdx >= 0; --displayNdx) { |
Wale Ogunwale | a0f5b5e | 2017-10-11 09:37:23 -0700 | [diff] [blame] | 2009 | final ActivityDisplay display = mActivityDisplays.valueAt(displayNdx); |
| 2010 | for (int stackNdx = display.getChildCount() - 1; stackNdx >= 0; --stackNdx) { |
| 2011 | final ActivityStack stack = display.getChildAt(stackNdx); |
| 2012 | stack.closeSystemDialogsLocked(); |
Craig Mautner | 4a1cb22 | 2013-12-04 16:14:06 -0800 | [diff] [blame] | 2013 | } |
Craig Mautner | 8d341ef | 2013-03-26 09:03:27 -0700 | [diff] [blame] | 2014 | } |
| 2015 | } |
| 2016 | |
Craig Mautner | 93529a4 | 2013-10-04 15:03:13 -0700 | [diff] [blame] | 2017 | void removeUserLocked(int userId) { |
Craig Mautner | 4f1df4f | 2013-10-15 15:44:14 -0700 | [diff] [blame] | 2018 | mUserStackInFront.delete(userId); |
Craig Mautner | 93529a4 | 2013-10-04 15:03:13 -0700 | [diff] [blame] | 2019 | } |
| 2020 | |
Craig Mautner | 8d341ef | 2013-03-26 09:03:27 -0700 | [diff] [blame] | 2021 | /** |
Chong Zhang | 45c25ce | 2015-08-10 22:18:26 -0700 | [diff] [blame] | 2022 | * Update the last used stack id for non-current user (current user's last |
| 2023 | * used stack is the focused stack) |
| 2024 | */ |
| 2025 | void updateUserStackLocked(int userId, ActivityStack stack) { |
| 2026 | if (userId != mCurrentUser) { |
Wale Ogunwale | 6827856 | 2017-09-23 17:13:55 -0700 | [diff] [blame] | 2027 | mUserStackInFront.put(userId, stack != null ? stack.getStackId() : mHomeStack.mStackId); |
Chong Zhang | 45c25ce | 2015-08-10 22:18:26 -0700 | [diff] [blame] | 2028 | } |
| 2029 | } |
| 2030 | |
| 2031 | /** |
Craig Mautner | 8d341ef | 2013-03-26 09:03:27 -0700 | [diff] [blame] | 2032 | * @return true if some activity was finished (or would have finished if doit were true). |
| 2033 | */ |
Wale Ogunwale | 540e123 | 2015-05-01 15:35:39 -0700 | [diff] [blame] | 2034 | boolean finishDisabledPackageActivitiesLocked(String packageName, Set<String> filterByClasses, |
| 2035 | boolean doit, boolean evenPersistent, int userId) { |
Craig Mautner | 8d341ef | 2013-03-26 09:03:27 -0700 | [diff] [blame] | 2036 | boolean didSomething = false; |
Craig Mautner | e0a3884 | 2013-12-16 16:14:02 -0800 | [diff] [blame] | 2037 | for (int displayNdx = mActivityDisplays.size() - 1; displayNdx >= 0; --displayNdx) { |
Wale Ogunwale | a0f5b5e | 2017-10-11 09:37:23 -0700 | [diff] [blame] | 2038 | final ActivityDisplay display = mActivityDisplays.valueAt(displayNdx); |
| 2039 | for (int stackNdx = display.getChildCount() - 1; stackNdx >= 0; --stackNdx) { |
| 2040 | final ActivityStack stack = display.getChildAt(stackNdx); |
Wale Ogunwale | 540e123 | 2015-05-01 15:35:39 -0700 | [diff] [blame] | 2041 | if (stack.finishDisabledPackageActivitiesLocked( |
| 2042 | packageName, filterByClasses, doit, evenPersistent, userId)) { |
Craig Mautner | 4a1cb22 | 2013-12-04 16:14:06 -0800 | [diff] [blame] | 2043 | didSomething = true; |
| 2044 | } |
Craig Mautner | 8d341ef | 2013-03-26 09:03:27 -0700 | [diff] [blame] | 2045 | } |
| 2046 | } |
| 2047 | return didSomething; |
| 2048 | } |
| 2049 | |
Dianne Hackborn | a413dc0 | 2013-07-12 12:02:55 -0700 | [diff] [blame] | 2050 | void updatePreviousProcessLocked(ActivityRecord r) { |
| 2051 | // Now that this process has stopped, we may want to consider |
| 2052 | // it to be the previous app to try to keep around in case |
| 2053 | // the user wants to return to it. |
| 2054 | |
| 2055 | // First, found out what is currently the foreground app, so that |
| 2056 | // we don't blow away the previous app if this activity is being |
| 2057 | // hosted by the process that is actually still the foreground. |
| 2058 | ProcessRecord fgApp = null; |
Craig Mautner | e0a3884 | 2013-12-16 16:14:02 -0800 | [diff] [blame] | 2059 | for (int displayNdx = mActivityDisplays.size() - 1; displayNdx >= 0; --displayNdx) { |
Wale Ogunwale | a0f5b5e | 2017-10-11 09:37:23 -0700 | [diff] [blame] | 2060 | final ActivityDisplay display = mActivityDisplays.valueAt(displayNdx); |
| 2061 | for (int stackNdx = display.getChildCount() - 1; stackNdx >= 0; --stackNdx) { |
| 2062 | final ActivityStack stack = display.getChildAt(stackNdx); |
Wale Ogunwale | 1e60e0c | 2015-10-28 13:36:10 -0700 | [diff] [blame] | 2063 | if (isFocusedStack(stack)) { |
Craig Mautner | 4a1cb22 | 2013-12-04 16:14:06 -0800 | [diff] [blame] | 2064 | if (stack.mResumedActivity != null) { |
| 2065 | fgApp = stack.mResumedActivity.app; |
| 2066 | } else if (stack.mPausingActivity != null) { |
| 2067 | fgApp = stack.mPausingActivity.app; |
| 2068 | } |
| 2069 | break; |
Dianne Hackborn | a413dc0 | 2013-07-12 12:02:55 -0700 | [diff] [blame] | 2070 | } |
Dianne Hackborn | a413dc0 | 2013-07-12 12:02:55 -0700 | [diff] [blame] | 2071 | } |
| 2072 | } |
| 2073 | |
| 2074 | // Now set this one as the previous process, only if that really |
| 2075 | // makes sense to. |
| 2076 | if (r.app != null && fgApp != null && r.app != fgApp |
| 2077 | && r.lastVisibleTime > mService.mPreviousProcessVisibleTime |
Craig Mautner | 4ef2693 | 2013-09-18 15:15:52 -0700 | [diff] [blame] | 2078 | && r.app != mService.mHomeProcess) { |
Dianne Hackborn | a413dc0 | 2013-07-12 12:02:55 -0700 | [diff] [blame] | 2079 | mService.mPreviousProcess = r.app; |
| 2080 | mService.mPreviousProcessVisibleTime = r.lastVisibleTime; |
| 2081 | } |
| 2082 | } |
| 2083 | |
Wale Ogunwale | d046a01 | 2015-12-24 13:05:59 -0800 | [diff] [blame] | 2084 | boolean resumeFocusedStackTopActivityLocked() { |
| 2085 | return resumeFocusedStackTopActivityLocked(null, null, null); |
Craig Mautner | 05d2903 | 2013-05-03 13:40:13 -0700 | [diff] [blame] | 2086 | } |
| 2087 | |
Wale Ogunwale | d046a01 | 2015-12-24 13:05:59 -0800 | [diff] [blame] | 2088 | boolean resumeFocusedStackTopActivityLocked( |
Chong Zhang | 280d332 | 2015-11-03 17:27:26 -0800 | [diff] [blame] | 2089 | ActivityStack targetStack, ActivityRecord target, ActivityOptions targetOptions) { |
chaviw | 59b9885 | 2017-06-13 12:05:44 -0700 | [diff] [blame] | 2090 | |
| 2091 | if (!readyToResume()) { |
| 2092 | return false; |
| 2093 | } |
| 2094 | |
Wale Ogunwale | d046a01 | 2015-12-24 13:05:59 -0800 | [diff] [blame] | 2095 | if (targetStack != null && isFocusedStack(targetStack)) { |
| 2096 | return targetStack.resumeTopActivityUncheckedLocked(target, targetOptions); |
Craig Mautner | 05d2903 | 2013-05-03 13:40:13 -0700 | [diff] [blame] | 2097 | } |
chaviw | 59b9885 | 2017-06-13 12:05:44 -0700 | [diff] [blame] | 2098 | |
Wale Ogunwale | 06579d6 | 2016-04-30 15:29:06 -0700 | [diff] [blame] | 2099 | final ActivityRecord r = mFocusedStack.topRunningActivityLocked(); |
| 2100 | if (r == null || r.state != RESUMED) { |
| 2101 | mFocusedStack.resumeTopActivityUncheckedLocked(null, null); |
skuhne@google.com | 1b974dc | 2016-12-09 13:41:29 -0800 | [diff] [blame] | 2102 | } else if (r.state == RESUMED) { |
| 2103 | // Kick off any lingering app transitions form the MoveTaskToFront operation. |
| 2104 | mFocusedStack.executeAppTransition(targetOptions); |
Wale Ogunwale | 06579d6 | 2016-04-30 15:29:06 -0700 | [diff] [blame] | 2105 | } |
chaviw | 59b9885 | 2017-06-13 12:05:44 -0700 | [diff] [blame] | 2106 | |
Wale Ogunwale | d046a01 | 2015-12-24 13:05:59 -0800 | [diff] [blame] | 2107 | return false; |
Craig Mautner | 8d341ef | 2013-03-26 09:03:27 -0700 | [diff] [blame] | 2108 | } |
| 2109 | |
Todd Kennedy | 39bfee5 | 2016-02-24 10:28:21 -0800 | [diff] [blame] | 2110 | void updateActivityApplicationInfoLocked(ApplicationInfo aInfo) { |
| 2111 | for (int displayNdx = mActivityDisplays.size() - 1; displayNdx >= 0; --displayNdx) { |
Wale Ogunwale | a0f5b5e | 2017-10-11 09:37:23 -0700 | [diff] [blame] | 2112 | final ActivityDisplay display = mActivityDisplays.valueAt(displayNdx); |
| 2113 | for (int stackNdx = display.getChildCount() - 1; stackNdx >= 0; --stackNdx) { |
| 2114 | final ActivityStack stack = display.getChildAt(stackNdx); |
| 2115 | stack.updateActivityApplicationInfoLocked(aInfo); |
Todd Kennedy | 39bfee5 | 2016-02-24 10:28:21 -0800 | [diff] [blame] | 2116 | } |
| 2117 | } |
| 2118 | } |
| 2119 | |
Adrian Roos | 20d7df3 | 2016-01-12 18:59:43 +0100 | [diff] [blame] | 2120 | TaskRecord finishTopRunningActivityLocked(ProcessRecord app, String reason) { |
| 2121 | TaskRecord finishedTask = null; |
| 2122 | ActivityStack focusedStack = getFocusedStack(); |
Craig Mautner | e0a3884 | 2013-12-16 16:14:02 -0800 | [diff] [blame] | 2123 | for (int displayNdx = mActivityDisplays.size() - 1; displayNdx >= 0; --displayNdx) { |
Wale Ogunwale | a0f5b5e | 2017-10-11 09:37:23 -0700 | [diff] [blame] | 2124 | final ActivityDisplay display = mActivityDisplays.valueAt(displayNdx); |
| 2125 | final int numStacks = display.getChildCount(); |
Craig Mautner | 4a1cb22 | 2013-12-04 16:14:06 -0800 | [diff] [blame] | 2126 | for (int stackNdx = 0; stackNdx < numStacks; ++stackNdx) { |
Wale Ogunwale | a0f5b5e | 2017-10-11 09:37:23 -0700 | [diff] [blame] | 2127 | final ActivityStack stack = display.getChildAt(stackNdx); |
Adrian Roos | 20d7df3 | 2016-01-12 18:59:43 +0100 | [diff] [blame] | 2128 | TaskRecord t = stack.finishTopRunningActivityLocked(app, reason); |
| 2129 | if (stack == focusedStack || finishedTask == null) { |
| 2130 | finishedTask = t; |
| 2131 | } |
Craig Mautner | 4a1cb22 | 2013-12-04 16:14:06 -0800 | [diff] [blame] | 2132 | } |
Craig Mautner | 8d341ef | 2013-03-26 09:03:27 -0700 | [diff] [blame] | 2133 | } |
Adrian Roos | 20d7df3 | 2016-01-12 18:59:43 +0100 | [diff] [blame] | 2134 | return finishedTask; |
Craig Mautner | 8d341ef | 2013-03-26 09:03:27 -0700 | [diff] [blame] | 2135 | } |
| 2136 | |
Dianne Hackborn | 6ea0d0a | 2014-07-02 16:23:21 -0700 | [diff] [blame] | 2137 | void finishVoiceTask(IVoiceInteractionSession session) { |
| 2138 | for (int displayNdx = mActivityDisplays.size() - 1; displayNdx >= 0; --displayNdx) { |
Wale Ogunwale | a0f5b5e | 2017-10-11 09:37:23 -0700 | [diff] [blame] | 2139 | final ActivityDisplay display = mActivityDisplays.valueAt(displayNdx); |
| 2140 | final int numStacks = display.getChildCount(); |
Dianne Hackborn | 6ea0d0a | 2014-07-02 16:23:21 -0700 | [diff] [blame] | 2141 | for (int stackNdx = 0; stackNdx < numStacks; ++stackNdx) { |
Wale Ogunwale | a0f5b5e | 2017-10-11 09:37:23 -0700 | [diff] [blame] | 2142 | final ActivityStack stack = display.getChildAt(stackNdx); |
Dianne Hackborn | 6ea0d0a | 2014-07-02 16:23:21 -0700 | [diff] [blame] | 2143 | stack.finishVoiceTask(session); |
| 2144 | } |
| 2145 | } |
| 2146 | } |
| 2147 | |
Jorim Jaggi | 4d8d32c | 2018-01-19 15:57:41 +0100 | [diff] [blame] | 2148 | void findTaskToMoveToFront(TaskRecord task, int flags, ActivityOptions options, String reason, |
| 2149 | boolean forceNonResizeable) { |
Wale Ogunwale | 66e1685 | 2017-10-19 13:35:52 -0700 | [diff] [blame] | 2150 | final ActivityStack currentStack = task.getStack(); |
| 2151 | if (currentStack == null) { |
| 2152 | Slog.e(TAG, "findTaskToMoveToFront: can't move task=" |
| 2153 | + task + " to front. Stack is null"); |
| 2154 | return; |
| 2155 | } |
| 2156 | |
Craig Mautner | aea74a5 | 2014-03-08 14:23:10 -0800 | [diff] [blame] | 2157 | if ((flags & ActivityManager.MOVE_TASK_NO_USER_ACTION) == 0) { |
| 2158 | mUserLeaving = true; |
Craig Mautner | 8d341ef | 2013-03-26 09:03:27 -0700 | [diff] [blame] | 2159 | } |
Wale Ogunwale | 66e1685 | 2017-10-19 13:35:52 -0700 | [diff] [blame] | 2160 | |
| 2161 | final ActivityRecord prev = topRunningActivityLocked(); |
| 2162 | |
| 2163 | if ((flags & ActivityManager.MOVE_TASK_WITH_HOME) != 0 |
| 2164 | || (prev != null && prev.isActivityTypeRecents())) { |
| 2165 | // Caller wants the home activity moved with it or the previous task is recents in which |
| 2166 | // case we always return home from the task we are moving to the front. |
| 2167 | moveHomeStackToFront("findTaskToMoveToFront"); |
Wale Ogunwale | 7d70117 | 2015-03-11 15:36:30 -0700 | [diff] [blame] | 2168 | } |
Chong Zhang | 0fa656b | 2015-08-31 15:17:21 -0700 | [diff] [blame] | 2169 | |
Wale Ogunwale | 0568aed | 2017-09-08 13:29:37 -0700 | [diff] [blame] | 2170 | if (task.isResizeable() && canUseActivityOptionsLaunchBounds(options)) { |
Bryce Lee | f3c6a47 | 2017-11-14 14:53:06 -0800 | [diff] [blame] | 2171 | final Rect bounds = options.getLaunchBounds(); |
Wale Ogunwale | 0568aed | 2017-09-08 13:29:37 -0700 | [diff] [blame] | 2172 | task.updateOverrideConfiguration(bounds); |
| 2173 | |
Wale Ogunwale | 04a05ac | 2017-09-17 21:35:02 -0700 | [diff] [blame] | 2174 | ActivityStack stack = getLaunchStack(null, options, task, ON_TOP); |
Wale Ogunwale | 0568aed | 2017-09-08 13:29:37 -0700 | [diff] [blame] | 2175 | |
Wale Ogunwale | 04a05ac | 2017-09-17 21:35:02 -0700 | [diff] [blame] | 2176 | if (stack != currentStack) { |
| 2177 | task.reparent(stack, ON_TOP, REPARENT_KEEP_STACK_AT_FRONT, !ANIMATE, DEFER_RESUME, |
Wale Ogunwale | 66e1685 | 2017-10-19 13:35:52 -0700 | [diff] [blame] | 2178 | "findTaskToMoveToFront"); |
Wale Ogunwale | 04a05ac | 2017-09-17 21:35:02 -0700 | [diff] [blame] | 2179 | stack = currentStack; |
Wale Ogunwale | 0568aed | 2017-09-08 13:29:37 -0700 | [diff] [blame] | 2180 | // moveTaskToStackUncheckedLocked() should already placed the task on top, |
| 2181 | // still need moveTaskToFrontLocked() below for any transition settings. |
| 2182 | } |
Wale Ogunwale | 44f036f | 2017-09-29 05:09:09 -0700 | [diff] [blame] | 2183 | if (stack.resizeStackWithLaunchBounds()) { |
| 2184 | resizeStackLocked(stack, bounds, null /* tempTaskBounds */, |
Wale Ogunwale | 04a05ac | 2017-09-17 21:35:02 -0700 | [diff] [blame] | 2185 | null /* tempTaskInsetBounds */, !PRESERVE_WINDOWS, |
| 2186 | true /* allowResizeInDockedMode */, !DEFER_RESUME); |
Wale Ogunwale | 0568aed | 2017-09-08 13:29:37 -0700 | [diff] [blame] | 2187 | } else { |
| 2188 | // WM resizeTask must be done after the task is moved to the correct stack, |
| 2189 | // because Task's setBounds() also updates dim layer's bounds, but that has |
| 2190 | // dependency on the stack. |
| 2191 | task.resizeWindowContainer(); |
Chong Zhang | 0fa656b | 2015-08-31 15:17:21 -0700 | [diff] [blame] | 2192 | } |
| 2193 | } |
| 2194 | |
Chong Zhang | db20b5f | 2015-10-23 14:01:43 -0700 | [diff] [blame] | 2195 | final ActivityRecord r = task.getTopActivity(); |
Andrii Kulian | 02b7a83 | 2016-10-06 23:11:56 -0700 | [diff] [blame] | 2196 | currentStack.moveTaskToFrontLocked(task, false /* noAnimation */, options, |
Chong Zhang | db20b5f | 2015-10-23 14:01:43 -0700 | [diff] [blame] | 2197 | r == null ? null : r.appTimeTracker, reason); |
| 2198 | |
Wale Ogunwale | ee006da | 2015-03-30 14:49:25 -0700 | [diff] [blame] | 2199 | if (DEBUG_STACK) Slog.d(TAG_STACK, |
Andrii Kulian | 02b7a83 | 2016-10-06 23:11:56 -0700 | [diff] [blame] | 2200 | "findTaskToMoveToFront: moved to front of stack=" + currentStack); |
Jorim Jaggi | 2adba07 | 2016-03-03 13:43:39 +0100 | [diff] [blame] | 2201 | |
Wale Ogunwale | 0568aed | 2017-09-08 13:29:37 -0700 | [diff] [blame] | 2202 | handleNonResizableTaskIfNeeded(task, WINDOWING_MODE_UNDEFINED, DEFAULT_DISPLAY, |
Wale Ogunwale | a0f5b5e | 2017-10-11 09:37:23 -0700 | [diff] [blame] | 2203 | currentStack, forceNonResizeable); |
Craig Mautner | 8d341ef | 2013-03-26 09:03:27 -0700 | [diff] [blame] | 2204 | } |
| 2205 | |
Wale Ogunwale | 0568aed | 2017-09-08 13:29:37 -0700 | [diff] [blame] | 2206 | boolean canUseActivityOptionsLaunchBounds(ActivityOptions options) { |
Wale Ogunwale | 7a8fa60 | 2015-11-18 15:56:57 -0800 | [diff] [blame] | 2207 | // 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] | 2208 | // window management or is launching into the pinned stack. |
Wale Ogunwale | 0568aed | 2017-09-08 13:29:37 -0700 | [diff] [blame] | 2209 | if (options == null || options.getLaunchBounds() == null) { |
Wale Ogunwale | 854809c | 2015-12-27 16:18:19 -0800 | [diff] [blame] | 2210 | return false; |
| 2211 | } |
Wale Ogunwale | 0568aed | 2017-09-08 13:29:37 -0700 | [diff] [blame] | 2212 | return (mService.mSupportsPictureInPicture |
| 2213 | && options.getLaunchWindowingMode() == WINDOWING_MODE_PINNED) |
Wale Ogunwale | 854809c | 2015-12-27 16:18:19 -0800 | [diff] [blame] | 2214 | || mService.mSupportsFreeformWindowManagement; |
Wale Ogunwale | 7a8fa60 | 2015-11-18 15:56:57 -0800 | [diff] [blame] | 2215 | } |
| 2216 | |
Bryce Lee | ec55eb0 | 2017-12-05 20:51:27 -0800 | [diff] [blame] | 2217 | LaunchParamsController getLaunchParamsController() { |
| 2218 | return mLaunchParamsController; |
Bryce Lee | 9ad3eb3 | 2017-10-10 10:10:31 -0700 | [diff] [blame] | 2219 | } |
| 2220 | |
Winson Chung | 5589333 | 2017-02-17 17:13:10 -0800 | [diff] [blame] | 2221 | protected <T extends ActivityStack> T getStack(int stackId) { |
Wale Ogunwale | 9dcf946 | 2017-09-19 15:13:01 -0700 | [diff] [blame] | 2222 | for (int i = mActivityDisplays.size() - 1; i >= 0; --i) { |
| 2223 | final T stack = mActivityDisplays.valueAt(i).getStack(stackId); |
| 2224 | if (stack != null) { |
| 2225 | return stack; |
| 2226 | } |
| 2227 | } |
| 2228 | return null; |
Wale Ogunwale | ddc1cb2 | 2015-07-25 19:23:04 -0700 | [diff] [blame] | 2229 | } |
| 2230 | |
Wale Ogunwale | 6827856 | 2017-09-23 17:13:55 -0700 | [diff] [blame] | 2231 | /** @see ActivityDisplay#getStack(int, int) */ |
| 2232 | private <T extends ActivityStack> T getStack(int windowingMode, int activityType) { |
| 2233 | for (int i = mActivityDisplays.size() - 1; i >= 0; --i) { |
| 2234 | final T stack = mActivityDisplays.valueAt(i).getStack(windowingMode, activityType); |
| 2235 | if (stack != null) { |
| 2236 | return stack; |
| 2237 | } |
| 2238 | } |
| 2239 | return null; |
| 2240 | } |
| 2241 | |
Wale Ogunwale | 04a05ac | 2017-09-17 21:35:02 -0700 | [diff] [blame] | 2242 | int resolveActivityType(@Nullable ActivityRecord r, @Nullable ActivityOptions options, |
Wale Ogunwale | 0568aed | 2017-09-08 13:29:37 -0700 | [diff] [blame] | 2243 | @Nullable TaskRecord task) { |
Wale Ogunwale | 04a05ac | 2017-09-17 21:35:02 -0700 | [diff] [blame] | 2244 | // Preference is given to the activity type for the activity then the task since the type |
| 2245 | // once set shouldn't change. |
| 2246 | int activityType = r != null ? r.getActivityType() : ACTIVITY_TYPE_UNDEFINED; |
| 2247 | if (activityType == ACTIVITY_TYPE_UNDEFINED && task != null) { |
| 2248 | activityType = task.getActivityType(); |
| 2249 | } |
Wale Ogunwale | 0568aed | 2017-09-08 13:29:37 -0700 | [diff] [blame] | 2250 | if (activityType != ACTIVITY_TYPE_UNDEFINED) { |
| 2251 | return activityType; |
| 2252 | } |
Wale Ogunwale | ab5de37 | 2017-10-18 06:46:31 -0700 | [diff] [blame] | 2253 | if (options != null) { |
| 2254 | activityType = options.getLaunchActivityType(); |
| 2255 | } |
| 2256 | return activityType != ACTIVITY_TYPE_UNDEFINED ? activityType : ACTIVITY_TYPE_STANDARD; |
Wale Ogunwale | 0568aed | 2017-09-08 13:29:37 -0700 | [diff] [blame] | 2257 | } |
| 2258 | |
Wale Ogunwale | 04a05ac | 2017-09-17 21:35:02 -0700 | [diff] [blame] | 2259 | <T extends ActivityStack> T getLaunchStack(@Nullable ActivityRecord r, |
| 2260 | @Nullable ActivityOptions options, @Nullable TaskRecord candidateTask, boolean onTop) { |
| 2261 | return getLaunchStack(r, options, candidateTask, onTop, INVALID_DISPLAY); |
Wale Ogunwale | 0568aed | 2017-09-08 13:29:37 -0700 | [diff] [blame] | 2262 | } |
| 2263 | |
| 2264 | /** |
| 2265 | * Returns the right stack to use for launching factoring in all the input parameters. |
| 2266 | * |
| 2267 | * @param r The activity we are trying to launch. Can be null. |
| 2268 | * @param options The activity options used to the launch. Can be null. |
| 2269 | * @param candidateTask The possible task the activity might be launched in. Can be null. |
| 2270 | * |
| 2271 | * @return The stack to use for the launch or INVALID_STACK_ID. |
| 2272 | */ |
Wale Ogunwale | 04a05ac | 2017-09-17 21:35:02 -0700 | [diff] [blame] | 2273 | <T extends ActivityStack> T getLaunchStack(@Nullable ActivityRecord r, |
| 2274 | @Nullable ActivityOptions options, @Nullable TaskRecord candidateTask, boolean onTop, |
| 2275 | int candidateDisplayId) { |
Wale Ogunwale | 0568aed | 2017-09-08 13:29:37 -0700 | [diff] [blame] | 2276 | int taskId = INVALID_TASK_ID; |
| 2277 | int displayId = INVALID_DISPLAY; |
| 2278 | //Rect bounds = null; |
| 2279 | |
| 2280 | // We give preference to the launch preference in activity options. |
| 2281 | if (options != null) { |
| 2282 | taskId = options.getLaunchTaskId(); |
| 2283 | displayId = options.getLaunchDisplayId(); |
| 2284 | // TODO: Need to work this into the equation... |
| 2285 | //bounds = options.getLaunchBounds(); |
| 2286 | } |
| 2287 | |
| 2288 | // First preference for stack goes to the task Id set in the activity options. Use the stack |
| 2289 | // associated with that if possible. |
| 2290 | if (taskId != INVALID_TASK_ID) { |
| 2291 | // Temporarily set the task id to invalid in case in re-entry. |
| 2292 | options.setLaunchTaskId(INVALID_TASK_ID); |
| 2293 | final TaskRecord task = anyTaskForIdLocked(taskId, |
Wale Ogunwale | ab5de37 | 2017-10-18 06:46:31 -0700 | [diff] [blame] | 2294 | MATCH_TASK_IN_STACKS_OR_RECENT_TASKS_AND_RESTORE, options, onTop); |
Wale Ogunwale | 0568aed | 2017-09-08 13:29:37 -0700 | [diff] [blame] | 2295 | options.setLaunchTaskId(taskId); |
| 2296 | if (task != null) { |
Wale Ogunwale | 04a05ac | 2017-09-17 21:35:02 -0700 | [diff] [blame] | 2297 | return task.getStack(); |
Wale Ogunwale | 0568aed | 2017-09-08 13:29:37 -0700 | [diff] [blame] | 2298 | } |
| 2299 | } |
| 2300 | |
Wale Ogunwale | 0568aed | 2017-09-08 13:29:37 -0700 | [diff] [blame] | 2301 | final int activityType = resolveActivityType(r, options, candidateTask); |
Wale Ogunwale | 04a05ac | 2017-09-17 21:35:02 -0700 | [diff] [blame] | 2302 | T stack = null; |
Wale Ogunwale | 0568aed | 2017-09-08 13:29:37 -0700 | [diff] [blame] | 2303 | |
| 2304 | // Next preference for stack goes to the display Id set in the activity options or the |
| 2305 | // candidate display. |
| 2306 | if (displayId == INVALID_DISPLAY) { |
| 2307 | displayId = candidateDisplayId; |
| 2308 | } |
Andrii Kulian | b850ea5 | 2017-12-12 23:49:10 -0800 | [diff] [blame] | 2309 | if (displayId != INVALID_DISPLAY && canLaunchOnDisplay(r, displayId)) { |
Wale Ogunwale | 0568aed | 2017-09-08 13:29:37 -0700 | [diff] [blame] | 2310 | if (r != null) { |
| 2311 | // TODO: This should also take in the windowing mode and activity type into account. |
Wale Ogunwale | 04a05ac | 2017-09-17 21:35:02 -0700 | [diff] [blame] | 2312 | stack = (T) getValidLaunchStackOnDisplay(displayId, r); |
Wale Ogunwale | 0568aed | 2017-09-08 13:29:37 -0700 | [diff] [blame] | 2313 | if (stack != null) { |
Wale Ogunwale | 04a05ac | 2017-09-17 21:35:02 -0700 | [diff] [blame] | 2314 | return stack; |
Wale Ogunwale | 0568aed | 2017-09-08 13:29:37 -0700 | [diff] [blame] | 2315 | } |
| 2316 | } |
| 2317 | final ActivityDisplay display = getActivityDisplayOrCreateLocked(displayId); |
| 2318 | if (display != null) { |
Wale Ogunwale | 7e1f5f5 | 2017-10-18 15:19:59 -0700 | [diff] [blame] | 2319 | stack = display.getOrCreateStack(r, options, candidateTask, activityType, onTop); |
Wale Ogunwale | ab5de37 | 2017-10-18 06:46:31 -0700 | [diff] [blame] | 2320 | if (stack != null) { |
| 2321 | return stack; |
Wale Ogunwale | 0568aed | 2017-09-08 13:29:37 -0700 | [diff] [blame] | 2322 | } |
Wale Ogunwale | 0568aed | 2017-09-08 13:29:37 -0700 | [diff] [blame] | 2323 | } |
| 2324 | } |
| 2325 | |
| 2326 | // Give preference to the stack and display of the input task and activity if they match the |
| 2327 | // mode we want to launch into. |
Wale Ogunwale | 04a05ac | 2017-09-17 21:35:02 -0700 | [diff] [blame] | 2328 | stack = null; |
| 2329 | ActivityDisplay display = null; |
Wale Ogunwale | 0568aed | 2017-09-08 13:29:37 -0700 | [diff] [blame] | 2330 | if (candidateTask != null) { |
| 2331 | stack = candidateTask.getStack(); |
| 2332 | } |
| 2333 | if (stack == null && r != null) { |
| 2334 | stack = r.getStack(); |
| 2335 | } |
| 2336 | if (stack != null) { |
Wale Ogunwale | 04a05ac | 2017-09-17 21:35:02 -0700 | [diff] [blame] | 2337 | display = stack.getDisplay(); |
Andrii Kulian | b850ea5 | 2017-12-12 23:49:10 -0800 | [diff] [blame] | 2338 | if (display != null && canLaunchOnDisplay(r, display.mDisplayId)) { |
Wale Ogunwale | 7e1f5f5 | 2017-10-18 15:19:59 -0700 | [diff] [blame] | 2339 | final int windowingMode = |
| 2340 | display.resolveWindowingMode(r, options, candidateTask, activityType); |
| 2341 | if (stack.isCompatible(windowingMode, activityType)) { |
| 2342 | return stack; |
| 2343 | } |
| 2344 | } |
Wale Ogunwale | 0568aed | 2017-09-08 13:29:37 -0700 | [diff] [blame] | 2345 | } |
| 2346 | |
Wale Ogunwale | 04a05ac | 2017-09-17 21:35:02 -0700 | [diff] [blame] | 2347 | if (display == null |
Andrii Kulian | b850ea5 | 2017-12-12 23:49:10 -0800 | [diff] [blame] | 2348 | || !canLaunchOnDisplay(r, display.mDisplayId) |
Wale Ogunwale | 04a05ac | 2017-09-17 21:35:02 -0700 | [diff] [blame] | 2349 | // TODO: Can be removed once we figure-out how non-standard types should launch |
| 2350 | // outside the default display. |
| 2351 | || (activityType != ACTIVITY_TYPE_STANDARD |
| 2352 | && activityType != ACTIVITY_TYPE_UNDEFINED)) { |
| 2353 | display = getDefaultDisplay(); |
Wale Ogunwale | 0568aed | 2017-09-08 13:29:37 -0700 | [diff] [blame] | 2354 | } |
Wale Ogunwale | 04a05ac | 2017-09-17 21:35:02 -0700 | [diff] [blame] | 2355 | |
Wale Ogunwale | 7e1f5f5 | 2017-10-18 15:19:59 -0700 | [diff] [blame] | 2356 | return display.getOrCreateStack(r, options, candidateTask, activityType, onTop); |
Wale Ogunwale | 0568aed | 2017-09-08 13:29:37 -0700 | [diff] [blame] | 2357 | } |
| 2358 | |
Andrii Kulian | b850ea5 | 2017-12-12 23:49:10 -0800 | [diff] [blame] | 2359 | /** @return true if activity record is null or can be launched on provided display. */ |
| 2360 | private boolean canLaunchOnDisplay(ActivityRecord r, int displayId) { |
| 2361 | if (r == null) { |
| 2362 | return true; |
| 2363 | } |
| 2364 | return r.canBeLaunchedOnDisplay(displayId); |
| 2365 | } |
| 2366 | |
Andrii Kulian | 16802aa | 2016-11-02 12:21:33 -0700 | [diff] [blame] | 2367 | /** |
| 2368 | * Get a topmost stack on the display, that is a valid launch stack for specified activity. |
| 2369 | * If there is no such stack, new dynamic stack can be created. |
| 2370 | * @param displayId Target display. |
| 2371 | * @param r Activity that should be launched there. |
| 2372 | * @return Existing stack if there is a valid one, new dynamic stack if it is valid or null. |
| 2373 | */ |
| 2374 | ActivityStack getValidLaunchStackOnDisplay(int displayId, @NonNull ActivityRecord r) { |
Andrii Kulian | 62e6f25 | 2017-05-30 22:46:53 -0700 | [diff] [blame] | 2375 | final ActivityDisplay activityDisplay = getActivityDisplayOrCreateLocked(displayId); |
Andrii Kulian | 16802aa | 2016-11-02 12:21:33 -0700 | [diff] [blame] | 2376 | if (activityDisplay == null) { |
| 2377 | throw new IllegalArgumentException( |
| 2378 | "Display with displayId=" + displayId + " not found."); |
| 2379 | } |
| 2380 | |
Wale Ogunwale | 04a05ac | 2017-09-17 21:35:02 -0700 | [diff] [blame] | 2381 | if (!r.canBeLaunchedOnDisplay(displayId)) { |
| 2382 | return null; |
| 2383 | } |
| 2384 | |
Andrii Kulian | 16802aa | 2016-11-02 12:21:33 -0700 | [diff] [blame] | 2385 | // Return the topmost valid stack on the display. |
Wale Ogunwale | a0f5b5e | 2017-10-11 09:37:23 -0700 | [diff] [blame] | 2386 | for (int i = activityDisplay.getChildCount() - 1; i >= 0; --i) { |
| 2387 | final ActivityStack stack = activityDisplay.getChildAt(i); |
Wale Ogunwale | 6827856 | 2017-09-23 17:13:55 -0700 | [diff] [blame] | 2388 | if (isValidLaunchStack(stack, displayId, r)) { |
Andrii Kulian | 16802aa | 2016-11-02 12:21:33 -0700 | [diff] [blame] | 2389 | return stack; |
| 2390 | } |
| 2391 | } |
| 2392 | |
| 2393 | // 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] | 2394 | if (displayId != DEFAULT_DISPLAY) { |
| 2395 | return activityDisplay.createStack( |
| 2396 | r.getWindowingMode(), r.getActivityType(), true /*onTop*/); |
Andrii Kulian | 16802aa | 2016-11-02 12:21:33 -0700 | [diff] [blame] | 2397 | } |
| 2398 | |
| 2399 | Slog.w(TAG, "getValidLaunchStackOnDisplay: can't launch on displayId " + displayId); |
| 2400 | return null; |
| 2401 | } |
| 2402 | |
Wale Ogunwale | 6827856 | 2017-09-23 17:13:55 -0700 | [diff] [blame] | 2403 | // TODO: Can probably be consolidated into getLaunchStack()... |
| 2404 | private boolean isValidLaunchStack(ActivityStack stack, int displayId, ActivityRecord r) { |
| 2405 | switch (stack.getActivityType()) { |
| 2406 | case ACTIVITY_TYPE_HOME: return r.isActivityTypeHome(); |
| 2407 | case ACTIVITY_TYPE_RECENTS: return r.isActivityTypeRecents(); |
| 2408 | case ACTIVITY_TYPE_ASSISTANT: return r.isActivityTypeAssistant(); |
Wale Ogunwale | 0568aed | 2017-09-08 13:29:37 -0700 | [diff] [blame] | 2409 | } |
Wale Ogunwale | 6827856 | 2017-09-23 17:13:55 -0700 | [diff] [blame] | 2410 | switch (stack.getWindowingMode()) { |
| 2411 | case WINDOWING_MODE_FULLSCREEN: return true; |
| 2412 | case WINDOWING_MODE_FREEFORM: return r.supportsFreeform(); |
| 2413 | case WINDOWING_MODE_PINNED: return r.supportsPictureInPicture(); |
| 2414 | case WINDOWING_MODE_SPLIT_SCREEN_PRIMARY: return r.supportsSplitScreenWindowingMode(); |
| 2415 | case WINDOWING_MODE_SPLIT_SCREEN_SECONDARY: return r.supportsSplitScreenWindowingMode(); |
| 2416 | } |
| 2417 | |
Wale Ogunwale | 44f036f | 2017-09-29 05:09:09 -0700 | [diff] [blame] | 2418 | if (!stack.isOnHomeDisplay()) { |
Wale Ogunwale | 6827856 | 2017-09-23 17:13:55 -0700 | [diff] [blame] | 2419 | return r.canBeLaunchedOnDisplay(displayId); |
| 2420 | } |
| 2421 | Slog.e(TAG, "isValidLaunchStack: Unexpected stack=" + stack); |
| 2422 | return false; |
Wale Ogunwale | 0568aed | 2017-09-08 13:29:37 -0700 | [diff] [blame] | 2423 | } |
| 2424 | |
Andrii Kulian | 7fc2281 | 2016-12-28 13:04:11 -0800 | [diff] [blame] | 2425 | /** |
| 2426 | * Get next focusable stack in the system. This will search across displays and stacks |
| 2427 | * in last-focused order for a focusable and visible stack, different from the target stack. |
| 2428 | * |
| 2429 | * @param currentFocus The stack that previously had focus and thus needs to be ignored when |
| 2430 | * searching for next candidate. |
| 2431 | * @return Next focusable {@link ActivityStack}, null if not found. |
| 2432 | */ |
| 2433 | ActivityStack getNextFocusableStackLocked(ActivityStack currentFocus) { |
| 2434 | mWindowManager.getDisplaysInFocusOrder(mTmpOrderedDisplayIds); |
| 2435 | |
| 2436 | for (int i = mTmpOrderedDisplayIds.size() - 1; i >= 0; --i) { |
| 2437 | final int displayId = mTmpOrderedDisplayIds.get(i); |
Andrii Kulian | 62e6f25 | 2017-05-30 22:46:53 -0700 | [diff] [blame] | 2438 | // If a display is registered in WM, it must also be available in AM. |
Wale Ogunwale | a0f5b5e | 2017-10-11 09:37:23 -0700 | [diff] [blame] | 2439 | final ActivityDisplay display = getActivityDisplayOrCreateLocked(displayId); |
| 2440 | for (int j = display.getChildCount() - 1; j >= 0; --j) { |
| 2441 | final ActivityStack stack = display.getChildAt(j); |
Wale Ogunwale | 04a05ac | 2017-09-17 21:35:02 -0700 | [diff] [blame] | 2442 | if (stack != currentFocus && stack.isFocusable() |
| 2443 | && stack.shouldBeVisible(null)) { |
Andrii Kulian | 7fc2281 | 2016-12-28 13:04:11 -0800 | [diff] [blame] | 2444 | return stack; |
| 2445 | } |
| 2446 | } |
| 2447 | } |
| 2448 | |
| 2449 | return null; |
| 2450 | } |
| 2451 | |
Andrii Kulian | a8fe3df | 2017-06-16 15:29:26 -0700 | [diff] [blame] | 2452 | /** |
| 2453 | * Get next valid stack for launching provided activity in the system. This will search across |
| 2454 | * displays and stacks in last-focused order for a focusable and visible stack, except those |
| 2455 | * that are on a currently focused display. |
| 2456 | * |
| 2457 | * @param r The activity that is being launched. |
| 2458 | * @param currentFocus The display that previously had focus and thus needs to be ignored when |
| 2459 | * searching for the next candidate. |
| 2460 | * @return Next valid {@link ActivityStack}, null if not found. |
| 2461 | */ |
| 2462 | ActivityStack getNextValidLaunchStackLocked(@NonNull ActivityRecord r, int currentFocus) { |
| 2463 | mWindowManager.getDisplaysInFocusOrder(mTmpOrderedDisplayIds); |
| 2464 | for (int i = mTmpOrderedDisplayIds.size() - 1; i >= 0; --i) { |
| 2465 | final int displayId = mTmpOrderedDisplayIds.get(i); |
| 2466 | if (displayId == currentFocus) { |
| 2467 | continue; |
| 2468 | } |
| 2469 | final ActivityStack stack = getValidLaunchStackOnDisplay(displayId, r); |
| 2470 | if (stack != null) { |
| 2471 | return stack; |
| 2472 | } |
| 2473 | } |
| 2474 | return null; |
| 2475 | } |
| 2476 | |
Craig Mautner | ee2e45a | 2014-06-27 12:10:03 -0700 | [diff] [blame] | 2477 | ActivityRecord getHomeActivity() { |
Craig Mautner | db49fec | 2015-05-21 15:33:30 -0700 | [diff] [blame] | 2478 | return getHomeActivityForUser(mCurrentUser); |
Fyodor Kupolov | b501330 | 2015-04-17 17:59:14 -0700 | [diff] [blame] | 2479 | } |
| 2480 | |
| 2481 | ActivityRecord getHomeActivityForUser(int userId) { |
Craig Mautner | 4a1cb22 | 2013-12-04 16:14:06 -0800 | [diff] [blame] | 2482 | final ArrayList<TaskRecord> tasks = mHomeStack.getAllTasks(); |
| 2483 | for (int taskNdx = tasks.size() - 1; taskNdx >= 0; --taskNdx) { |
| 2484 | final TaskRecord task = tasks.get(taskNdx); |
Wale Ogunwale | 6fbde9f | 2017-08-24 07:24:12 -0700 | [diff] [blame] | 2485 | if (task.isActivityTypeHome()) { |
Craig Mautner | 4a1cb22 | 2013-12-04 16:14:06 -0800 | [diff] [blame] | 2486 | final ArrayList<ActivityRecord> activities = task.mActivities; |
| 2487 | for (int activityNdx = activities.size() - 1; activityNdx >= 0; --activityNdx) { |
| 2488 | final ActivityRecord r = activities.get(activityNdx); |
Wale Ogunwale | 6fbde9f | 2017-08-24 07:24:12 -0700 | [diff] [blame] | 2489 | if (r.isActivityTypeHome() |
Fyodor Kupolov | b501330 | 2015-04-17 17:59:14 -0700 | [diff] [blame] | 2490 | && ((userId == UserHandle.USER_ALL) || (r.userId == userId))) { |
Craig Mautner | ee2e45a | 2014-06-27 12:10:03 -0700 | [diff] [blame] | 2491 | return r; |
Craig Mautner | 4a1cb22 | 2013-12-04 16:14:06 -0800 | [diff] [blame] | 2492 | } |
| 2493 | } |
| 2494 | } |
| 2495 | } |
| 2496 | return null; |
| 2497 | } |
| 2498 | |
Wale Ogunwale | 44f036f | 2017-09-29 05:09:09 -0700 | [diff] [blame] | 2499 | void resizeStackLocked(ActivityStack stack, Rect bounds, Rect tempTaskBounds, |
| 2500 | Rect tempTaskInsetBounds, boolean preserveWindows, boolean allowResizeInDockedMode, |
| 2501 | boolean deferResume) { |
| 2502 | |
| 2503 | if (stack.inSplitScreenPrimaryWindowingMode()) { |
Jorim Jaggi | dc249c4 | 2015-12-15 14:57:31 -0800 | [diff] [blame] | 2504 | resizeDockedStackLocked(bounds, tempTaskBounds, tempTaskInsetBounds, null, null, |
Andrii Kulian | db3e4ec | 2016-07-12 17:11:35 -0700 | [diff] [blame] | 2505 | preserveWindows, deferResume); |
Jorim Jaggi | dc249c4 | 2015-12-15 14:57:31 -0800 | [diff] [blame] | 2506 | return; |
| 2507 | } |
Wale Ogunwale | 9d3de4c | 2015-02-01 16:49:44 -0800 | [diff] [blame] | 2508 | |
Wale Ogunwale | a0f5b5e | 2017-10-11 09:37:23 -0700 | [diff] [blame] | 2509 | final boolean splitScreenActive = getDefaultDisplay().hasSplitScreenPrimaryStack(); |
Wale Ogunwale | 3382ab1 | 2017-07-27 08:55:03 -0700 | [diff] [blame] | 2510 | if (!allowResizeInDockedMode |
Wale Ogunwale | 926aade | 2017-08-29 11:24:37 -0700 | [diff] [blame] | 2511 | && !stack.getWindowConfiguration().tasksAreFloating() && splitScreenActive) { |
Winson Chung | a2249ac | 2017-03-30 18:15:30 -0700 | [diff] [blame] | 2512 | // If the docked stack exists, don't resize non-floating stacks independently of the |
| 2513 | // 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] | 2514 | return; |
| 2515 | } |
| 2516 | |
Wale Ogunwale | 44f036f | 2017-09-29 05:09:09 -0700 | [diff] [blame] | 2517 | Trace.traceBegin(TRACE_TAG_ACTIVITY_MANAGER, "am.resizeStack_" + stack.mStackId); |
Jorim Jaggi | c402520 | 2015-10-22 16:43:34 +0200 | [diff] [blame] | 2518 | mWindowManager.deferSurfaceLayout(); |
| 2519 | try { |
Wale Ogunwale | 2b07da8 | 2017-11-08 14:52:40 -0800 | [diff] [blame] | 2520 | if (stack.affectedBySplitScreenResize()) { |
Wale Ogunwale | 926aade | 2017-08-29 11:24:37 -0700 | [diff] [blame] | 2521 | if (bounds == null && stack.inSplitScreenWindowingMode()) { |
| 2522 | // null bounds = fullscreen windowing mode...at least for now. |
| 2523 | stack.setWindowingMode(WINDOWING_MODE_FULLSCREEN); |
| 2524 | } else if (splitScreenActive) { |
| 2525 | // If we are in split-screen mode and this stack support split-screen, then |
| 2526 | // it should be split-screen secondary mode. i.e. adjacent to the docked stack. |
| 2527 | stack.setWindowingMode(WINDOWING_MODE_SPLIT_SCREEN_SECONDARY); |
| 2528 | } |
| 2529 | } |
Wale Ogunwale | 1666e31 | 2016-12-16 11:27:18 -0800 | [diff] [blame] | 2530 | stack.resize(bounds, tempTaskBounds, tempTaskInsetBounds); |
Wale Ogunwale | c8da41e | 2016-04-16 13:27:23 -0700 | [diff] [blame] | 2531 | if (!deferResume) { |
Wale Ogunwale | db0fa12 | 2016-05-16 15:12:03 -0700 | [diff] [blame] | 2532 | stack.ensureVisibleActivitiesConfigurationLocked( |
| 2533 | stack.topRunningActivityLocked(), preserveWindows); |
Wale Ogunwale | c8da41e | 2016-04-16 13:27:23 -0700 | [diff] [blame] | 2534 | } |
Jorim Jaggi | c402520 | 2015-10-22 16:43:34 +0200 | [diff] [blame] | 2535 | } finally { |
| 2536 | mWindowManager.continueSurfaceLayout(); |
| 2537 | Trace.traceEnd(TRACE_TAG_ACTIVITY_MANAGER); |
Wale Ogunwale | e4a0c57 | 2015-06-30 08:40:31 -0700 | [diff] [blame] | 2538 | } |
| 2539 | } |
| 2540 | |
Bryce Lee | d3624e1 | 2017-11-30 08:51:45 -0800 | [diff] [blame] | 2541 | void deferUpdateBounds(int activityType) { |
Wale Ogunwale | 6827856 | 2017-09-23 17:13:55 -0700 | [diff] [blame] | 2542 | final ActivityStack stack = getStack(WINDOWING_MODE_UNDEFINED, activityType); |
Jorim Jaggi | 192086e | 2016-03-11 17:17:03 +0100 | [diff] [blame] | 2543 | if (stack != null) { |
| 2544 | stack.deferUpdateBounds(); |
| 2545 | } |
| 2546 | } |
| 2547 | |
Bryce Lee | d3624e1 | 2017-11-30 08:51:45 -0800 | [diff] [blame] | 2548 | void continueUpdateBounds(int activityType) { |
Wale Ogunwale | 6827856 | 2017-09-23 17:13:55 -0700 | [diff] [blame] | 2549 | final ActivityStack stack = getStack(WINDOWING_MODE_UNDEFINED, activityType); |
Jorim Jaggi | 192086e | 2016-03-11 17:17:03 +0100 | [diff] [blame] | 2550 | if (stack != null) { |
| 2551 | stack.continueUpdateBounds(); |
| 2552 | } |
| 2553 | } |
| 2554 | |
Jorim Jaggi | 0b46f3c | 2016-03-14 12:21:37 +0100 | [diff] [blame] | 2555 | void notifyAppTransitionDone() { |
Wale Ogunwale | 6827856 | 2017-09-23 17:13:55 -0700 | [diff] [blame] | 2556 | continueUpdateBounds(ACTIVITY_TYPE_RECENTS); |
Jorim Jaggi | 0b46f3c | 2016-03-14 12:21:37 +0100 | [diff] [blame] | 2557 | for (int i = mResizingTasksDuringAnimation.size() - 1; i >= 0; i--) { |
| 2558 | final int taskId = mResizingTasksDuringAnimation.valueAt(i); |
Wale Ogunwale | 0568aed | 2017-09-08 13:29:37 -0700 | [diff] [blame] | 2559 | final TaskRecord task = anyTaskForIdLocked(taskId, MATCH_TASK_IN_STACKS_ONLY); |
Wale Ogunwale | e1fe7fa2 | 2016-12-15 18:27:00 -0800 | [diff] [blame] | 2560 | if (task != null) { |
| 2561 | task.setTaskDockedResizing(false); |
Jorim Jaggi | 0b46f3c | 2016-03-14 12:21:37 +0100 | [diff] [blame] | 2562 | } |
| 2563 | } |
| 2564 | mResizingTasksDuringAnimation.clear(); |
| 2565 | } |
| 2566 | |
Wale Ogunwale | 04a05ac | 2017-09-17 21:35:02 -0700 | [diff] [blame] | 2567 | /** |
| 2568 | * 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] | 2569 | * Can do that once we are no longer using static stack ids. |
Wale Ogunwale | 04a05ac | 2017-09-17 21:35:02 -0700 | [diff] [blame] | 2570 | */ |
Wale Ogunwale | 9dcf946 | 2017-09-19 15:13:01 -0700 | [diff] [blame] | 2571 | private void moveTasksToFullscreenStackInSurfaceTransaction(ActivityStack fromStack, |
Wale Ogunwale | 04a05ac | 2017-09-17 21:35:02 -0700 | [diff] [blame] | 2572 | int toDisplayId, boolean onTop) { |
Robert Carr | 6914f08 | 2017-03-20 19:04:30 -0700 | [diff] [blame] | 2573 | |
Wale Ogunwale | c8da41e | 2016-04-16 13:27:23 -0700 | [diff] [blame] | 2574 | mWindowManager.deferSurfaceLayout(); |
| 2575 | try { |
Wale Ogunwale | 04a05ac | 2017-09-17 21:35:02 -0700 | [diff] [blame] | 2576 | final int windowingMode = fromStack.getWindowingMode(); |
| 2577 | final boolean inPinnedWindowingMode = windowingMode == WINDOWING_MODE_PINNED; |
| 2578 | final ActivityDisplay toDisplay = getActivityDisplay(toDisplayId); |
| 2579 | |
| 2580 | if (windowingMode == WINDOWING_MODE_SPLIT_SCREEN_PRIMARY) { |
Wale Ogunwale | 7e1f5f5 | 2017-10-18 15:19:59 -0700 | [diff] [blame] | 2581 | // Tell the display we are exiting split-screen mode. |
| 2582 | toDisplay.onExitingSplitScreenMode(); |
Wale Ogunwale | c8da41e | 2016-04-16 13:27:23 -0700 | [diff] [blame] | 2583 | // We are moving all tasks from the docked stack to the fullscreen stack, |
| 2584 | // which is dismissing the docked stack, so resize all other stacks to |
| 2585 | // fullscreen here already so we don't end up with resize trashing. |
Wale Ogunwale | a0f5b5e | 2017-10-11 09:37:23 -0700 | [diff] [blame] | 2586 | for (int i = toDisplay.getChildCount() - 1; i >= 0; --i) { |
| 2587 | final ActivityStack otherStack = toDisplay.getChildAt(i); |
Wale Ogunwale | 926aade | 2017-08-29 11:24:37 -0700 | [diff] [blame] | 2588 | if (!otherStack.inSplitScreenSecondaryWindowingMode()) { |
| 2589 | continue; |
| 2590 | } |
Wale Ogunwale | 44f036f | 2017-09-29 05:09:09 -0700 | [diff] [blame] | 2591 | resizeStackLocked(otherStack, null, null, null, PRESERVE_WINDOWS, |
Wale Ogunwale | 926aade | 2017-08-29 11:24:37 -0700 | [diff] [blame] | 2592 | true /* allowResizeInDockedMode */, DEFER_RESUME); |
Wale Ogunwale | c8da41e | 2016-04-16 13:27:23 -0700 | [diff] [blame] | 2593 | } |
| 2594 | |
| 2595 | // Also disable docked stack resizing since we have manually adjusted the |
| 2596 | // size of other stacks above and we don't want to trigger a docked stack |
| 2597 | // resize when we remove task from it below and it is detached from the |
| 2598 | // display because it no longer contains any tasks. |
| 2599 | mAllowDockedStackResize = false; |
Wale Ogunwale | 04a05ac | 2017-09-17 21:35:02 -0700 | [diff] [blame] | 2600 | } else if (inPinnedWindowingMode && onTop) { |
| 2601 | // Log if we are expanding the PiP to fullscreen |
Chenjie Yu | 52cacc6 | 2017-12-08 18:11:45 -0800 | [diff] [blame] | 2602 | MetricsLoggerWrapper.logPictureInPictureFullScreen(mService.mContext); |
Wale Ogunwale | c8da41e | 2016-04-16 13:27:23 -0700 | [diff] [blame] | 2603 | } |
Wale Ogunwale | 04a05ac | 2017-09-17 21:35:02 -0700 | [diff] [blame] | 2604 | |
Winson Chung | 5af42fc | 2017-03-24 17:11:33 -0700 | [diff] [blame] | 2605 | // If we are moving from the pinned stack, then the animation takes care of updating |
| 2606 | // the picture-in-picture mode. |
Wale Ogunwale | 04a05ac | 2017-09-17 21:35:02 -0700 | [diff] [blame] | 2607 | final boolean schedulePictureInPictureModeChange = inPinnedWindowingMode; |
Wale Ogunwale | 9dcf946 | 2017-09-19 15:13:01 -0700 | [diff] [blame] | 2608 | final ArrayList<TaskRecord> tasks = fromStack.getAllTasks(); |
Wale Ogunwale | 04a05ac | 2017-09-17 21:35:02 -0700 | [diff] [blame] | 2609 | |
Wale Ogunwale | 388945c | 2017-10-04 12:13:46 -0700 | [diff] [blame] | 2610 | if (!tasks.isEmpty()) { |
Wale Ogunwale | 7e1f5f5 | 2017-10-18 15:19:59 -0700 | [diff] [blame] | 2611 | mTmpOptions.setLaunchWindowingMode(WINDOWING_MODE_FULLSCREEN); |
Wale Ogunwale | 388945c | 2017-10-04 12:13:46 -0700 | [diff] [blame] | 2612 | final int size = tasks.size(); |
Wale Ogunwale | 7e1f5f5 | 2017-10-18 15:19:59 -0700 | [diff] [blame] | 2613 | for (int i = 0; i < size; ++i) { |
| 2614 | final TaskRecord task = tasks.get(i); |
| 2615 | final ActivityStack toStack = toDisplay.getOrCreateStack( |
| 2616 | null, mTmpOptions, task, task.getActivityType(), onTop); |
Wale Ogunwale | 388945c | 2017-10-04 12:13:46 -0700 | [diff] [blame] | 2617 | |
Wale Ogunwale | 7e1f5f5 | 2017-10-18 15:19:59 -0700 | [diff] [blame] | 2618 | if (onTop) { |
Wale Ogunwale | 388945c | 2017-10-04 12:13:46 -0700 | [diff] [blame] | 2619 | final boolean isTopTask = i == (size - 1); |
Wale Ogunwale | 388945c | 2017-10-04 12:13:46 -0700 | [diff] [blame] | 2620 | // 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] | 2621 | task.reparent(toStack, ON_TOP, REPARENT_MOVE_STACK_TO_FRONT, |
Wale Ogunwale | 388945c | 2017-10-04 12:13:46 -0700 | [diff] [blame] | 2622 | isTopTask /* animate */, DEFER_RESUME, |
| 2623 | schedulePictureInPictureModeChange, |
| 2624 | "moveTasksToFullscreenStack - onTop"); |
Wale Ogunwale | 7e1f5f5 | 2017-10-18 15:19:59 -0700 | [diff] [blame] | 2625 | } else { |
Wale Ogunwale | 388945c | 2017-10-04 12:13:46 -0700 | [diff] [blame] | 2626 | // Position the tasks in the fullscreen stack in order at the bottom of the |
| 2627 | // stack. Also defer resume until all the tasks have been moved to the |
| 2628 | // fullscreen stack. |
Wale Ogunwale | 7e1f5f5 | 2017-10-18 15:19:59 -0700 | [diff] [blame] | 2629 | task.reparent(toStack, ON_TOP, |
Wale Ogunwale | 388945c | 2017-10-04 12:13:46 -0700 | [diff] [blame] | 2630 | REPARENT_LEAVE_STACK_IN_PLACE, !ANIMATE, DEFER_RESUME, |
| 2631 | schedulePictureInPictureModeChange, |
| 2632 | "moveTasksToFullscreenStack - NOT_onTop"); |
| 2633 | } |
Wale Ogunwale | c8da41e | 2016-04-16 13:27:23 -0700 | [diff] [blame] | 2634 | } |
| 2635 | } |
Winson Chung | 7466610 | 2017-02-22 17:49:24 -0800 | [diff] [blame] | 2636 | |
| 2637 | ensureActivitiesVisibleLocked(null, 0, PRESERVE_WINDOWS); |
| 2638 | resumeFocusedStackTopActivityLocked(); |
Wale Ogunwale | c8da41e | 2016-04-16 13:27:23 -0700 | [diff] [blame] | 2639 | } finally { |
| 2640 | mAllowDockedStackResize = true; |
| 2641 | mWindowManager.continueSurfaceLayout(); |
| 2642 | } |
| 2643 | } |
| 2644 | |
Wale Ogunwale | 9dcf946 | 2017-09-19 15:13:01 -0700 | [diff] [blame] | 2645 | void moveTasksToFullscreenStackLocked(ActivityStack fromStack, boolean onTop) { |
Wale Ogunwale | 04a05ac | 2017-09-17 21:35:02 -0700 | [diff] [blame] | 2646 | moveTasksToFullscreenStackLocked(fromStack, DEFAULT_DISPLAY, onTop); |
| 2647 | } |
| 2648 | |
| 2649 | void moveTasksToFullscreenStackLocked(ActivityStack fromStack, int toDisplayId, boolean onTop) { |
| 2650 | mWindowManager.inSurfaceTransaction(() -> |
| 2651 | moveTasksToFullscreenStackInSurfaceTransaction(fromStack, toDisplayId, onTop)); |
Robert Carr | 6914f08 | 2017-03-20 19:04:30 -0700 | [diff] [blame] | 2652 | } |
| 2653 | |
Jorim Jaggi | dc249c4 | 2015-12-15 14:57:31 -0800 | [diff] [blame] | 2654 | void resizeDockedStackLocked(Rect dockedBounds, Rect tempDockedTaskBounds, |
Andrii Kulian | db3e4ec | 2016-07-12 17:11:35 -0700 | [diff] [blame] | 2655 | Rect tempDockedTaskInsetBounds, Rect tempOtherTaskBounds, Rect tempOtherTaskInsetBounds, |
| 2656 | boolean preserveWindows) { |
| 2657 | resizeDockedStackLocked(dockedBounds, tempDockedTaskBounds, tempDockedTaskInsetBounds, |
| 2658 | tempOtherTaskBounds, tempOtherTaskInsetBounds, preserveWindows, |
| 2659 | false /* deferResume */); |
| 2660 | } |
| 2661 | |
Wale Ogunwale | 04a05ac | 2017-09-17 21:35:02 -0700 | [diff] [blame] | 2662 | private void resizeDockedStackLocked(Rect dockedBounds, Rect tempDockedTaskBounds, |
Andrii Kulian | db3e4ec | 2016-07-12 17:11:35 -0700 | [diff] [blame] | 2663 | Rect tempDockedTaskInsetBounds, Rect tempOtherTaskBounds, Rect tempOtherTaskInsetBounds, |
| 2664 | boolean preserveWindows, boolean deferResume) { |
Wale Ogunwale | c8da41e | 2016-04-16 13:27:23 -0700 | [diff] [blame] | 2665 | |
| 2666 | if (!mAllowDockedStackResize) { |
| 2667 | // Docked stack resize currently disabled. |
| 2668 | return; |
| 2669 | } |
| 2670 | |
Wale Ogunwale | a0f5b5e | 2017-10-11 09:37:23 -0700 | [diff] [blame] | 2671 | final ActivityStack stack = getDefaultDisplay().getSplitScreenPrimaryStack(); |
Jorim Jaggi | dc249c4 | 2015-12-15 14:57:31 -0800 | [diff] [blame] | 2672 | if (stack == null) { |
| 2673 | Slog.w(TAG, "resizeDockedStackLocked: docked stack not found"); |
| 2674 | return; |
| 2675 | } |
| 2676 | |
| 2677 | Trace.traceBegin(TRACE_TAG_ACTIVITY_MANAGER, "am.resizeDockedStack"); |
| 2678 | mWindowManager.deferSurfaceLayout(); |
| 2679 | try { |
Wale Ogunwale | c8da41e | 2016-04-16 13:27:23 -0700 | [diff] [blame] | 2680 | // Don't allow re-entry while resizing. E.g. due to docked stack detaching. |
| 2681 | mAllowDockedStackResize = false; |
Jorim Jaggi | dc249c4 | 2015-12-15 14:57:31 -0800 | [diff] [blame] | 2682 | ActivityRecord r = stack.topRunningActivityLocked(); |
Wale Ogunwale | 1666e31 | 2016-12-16 11:27:18 -0800 | [diff] [blame] | 2683 | stack.resize(dockedBounds, tempDockedTaskBounds, tempDockedTaskInsetBounds); |
Jorim Jaggi | dc249c4 | 2015-12-15 14:57:31 -0800 | [diff] [blame] | 2684 | |
Andrii Kulian | 69fb5e4 | 2016-04-05 16:47:29 -0700 | [diff] [blame] | 2685 | // TODO: Checking for isAttached might not be needed as if the user passes in null |
| 2686 | // dockedBounds then they want the docked stack to be dismissed. |
Bryce Lee | f3c6a47 | 2017-11-14 14:53:06 -0800 | [diff] [blame] | 2687 | if (stack.getWindowingMode() == WINDOWING_MODE_FULLSCREEN |
| 2688 | || (dockedBounds == null && !stack.isAttached())) { |
Andrii Kulian | 69fb5e4 | 2016-04-05 16:47:29 -0700 | [diff] [blame] | 2689 | // 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] | 2690 | // In this case we make all other static stacks fullscreen and move all |
| 2691 | // docked stack tasks to the fullscreen stack. |
Wale Ogunwale | 9dcf946 | 2017-09-19 15:13:01 -0700 | [diff] [blame] | 2692 | moveTasksToFullscreenStackLocked(stack, ON_TOP); |
Jorim Jaggi | dc249c4 | 2015-12-15 14:57:31 -0800 | [diff] [blame] | 2693 | |
| 2694 | // stack shouldn't contain anymore activities, so nothing to resume. |
| 2695 | r = null; |
| 2696 | } else { |
| 2697 | // Docked stacks occupy a dedicated region on screen so the size of all other |
| 2698 | // static stacks need to be adjusted so they don't overlap with the docked stack. |
| 2699 | // We get the bounds to use from window manager which has been adjusted for any |
| 2700 | // screen controls and is also the same for all stacks. |
Wale Ogunwale | a0f5b5e | 2017-10-11 09:37:23 -0700 | [diff] [blame] | 2701 | final ActivityDisplay display = getDefaultDisplay(); |
Matthew Ng | aa2b620 | 2017-02-10 14:48:21 -0800 | [diff] [blame] | 2702 | final Rect otherTaskRect = new Rect(); |
Wale Ogunwale | a0f5b5e | 2017-10-11 09:37:23 -0700 | [diff] [blame] | 2703 | for (int i = display.getChildCount() - 1; i >= 0; --i) { |
| 2704 | final ActivityStack current = display.getChildAt(i); |
Wale Ogunwale | 04a05ac | 2017-09-17 21:35:02 -0700 | [diff] [blame] | 2705 | if (current.getWindowingMode() == WINDOWING_MODE_SPLIT_SCREEN_PRIMARY) { |
Wale Ogunwale | 926aade | 2017-08-29 11:24:37 -0700 | [diff] [blame] | 2706 | continue; |
Jorim Jaggi | dc249c4 | 2015-12-15 14:57:31 -0800 | [diff] [blame] | 2707 | } |
Wale Ogunwale | 2b07da8 | 2017-11-08 14:52:40 -0800 | [diff] [blame] | 2708 | if (!current.affectedBySplitScreenResize()) { |
Wale Ogunwale | 926aade | 2017-08-29 11:24:37 -0700 | [diff] [blame] | 2709 | continue; |
| 2710 | } |
| 2711 | // Need to set windowing mode here before we try to get the dock bounds. |
| 2712 | current.setWindowingMode(WINDOWING_MODE_SPLIT_SCREEN_SECONDARY); |
| 2713 | current.getStackDockedModeBounds( |
| 2714 | tempOtherTaskBounds /* currentTempTaskBounds */, |
| 2715 | tempRect /* outStackBounds */, |
| 2716 | otherTaskRect /* outTempTaskBounds */, true /* ignoreVisibility */); |
| 2717 | |
Wale Ogunwale | 44f036f | 2017-09-29 05:09:09 -0700 | [diff] [blame] | 2718 | resizeStackLocked(current, !tempRect.isEmpty() ? tempRect : null, |
Wale Ogunwale | 926aade | 2017-08-29 11:24:37 -0700 | [diff] [blame] | 2719 | !otherTaskRect.isEmpty() ? otherTaskRect : tempOtherTaskBounds, |
| 2720 | tempOtherTaskInsetBounds, preserveWindows, |
| 2721 | true /* allowResizeInDockedMode */, deferResume); |
Jorim Jaggi | dc249c4 | 2015-12-15 14:57:31 -0800 | [diff] [blame] | 2722 | } |
| 2723 | } |
Andrii Kulian | db3e4ec | 2016-07-12 17:11:35 -0700 | [diff] [blame] | 2724 | if (!deferResume) { |
| 2725 | stack.ensureVisibleActivitiesConfigurationLocked(r, preserveWindows); |
| 2726 | } |
Jorim Jaggi | dc249c4 | 2015-12-15 14:57:31 -0800 | [diff] [blame] | 2727 | } finally { |
Wale Ogunwale | c8da41e | 2016-04-16 13:27:23 -0700 | [diff] [blame] | 2728 | mAllowDockedStackResize = true; |
Jorim Jaggi | dc249c4 | 2015-12-15 14:57:31 -0800 | [diff] [blame] | 2729 | mWindowManager.continueSurfaceLayout(); |
| 2730 | Trace.traceEnd(TRACE_TAG_ACTIVITY_MANAGER); |
| 2731 | } |
Jorim Jaggi | dc249c4 | 2015-12-15 14:57:31 -0800 | [diff] [blame] | 2732 | } |
| 2733 | |
Robert Carr | 0d00c2e | 2016-02-29 17:45:02 -0800 | [diff] [blame] | 2734 | void resizePinnedStackLocked(Rect pinnedBounds, Rect tempPinnedTaskBounds) { |
Wale Ogunwale | 04a05ac | 2017-09-17 21:35:02 -0700 | [diff] [blame] | 2735 | // TODO(multi-display): Pinned stack display should be passed in. |
Wale Ogunwale | a0f5b5e | 2017-10-11 09:37:23 -0700 | [diff] [blame] | 2736 | final PinnedActivityStack stack = getDefaultDisplay().getPinnedStack(); |
Robert Carr | 0d00c2e | 2016-02-29 17:45:02 -0800 | [diff] [blame] | 2737 | if (stack == null) { |
| 2738 | Slog.w(TAG, "resizePinnedStackLocked: pinned stack not found"); |
| 2739 | return; |
| 2740 | } |
Winson Chung | 19953ca | 2017-04-11 11:19:23 -0700 | [diff] [blame] | 2741 | |
| 2742 | // It is possible for the bounds animation from the WM to call this but be delayed by |
| 2743 | // another AM call that is holding the AMS lock. In such a case, the pinnedBounds may be |
| 2744 | // incorrect if AMS.resizeStackWithBoundsFromWindowManager() is already called while waiting |
| 2745 | // for the AMS lock to be freed. So check and make sure these bounds are still good. |
| 2746 | final PinnedStackWindowController stackController = stack.getWindowContainerController(); |
Winson Chung | 8bca9e4 | 2017-04-16 15:59:43 -0700 | [diff] [blame] | 2747 | if (stackController.pinnedStackResizeDisallowed()) { |
Winson Chung | 19953ca | 2017-04-11 11:19:23 -0700 | [diff] [blame] | 2748 | return; |
| 2749 | } |
| 2750 | |
Robert Carr | 0d00c2e | 2016-02-29 17:45:02 -0800 | [diff] [blame] | 2751 | Trace.traceBegin(TRACE_TAG_ACTIVITY_MANAGER, "am.resizePinnedStack"); |
| 2752 | mWindowManager.deferSurfaceLayout(); |
| 2753 | try { |
| 2754 | ActivityRecord r = stack.topRunningActivityLocked(); |
Robert Carr | 7e4c90e | 2017-02-15 19:52:38 -0800 | [diff] [blame] | 2755 | Rect insetBounds = null; |
| 2756 | if (tempPinnedTaskBounds != null) { |
| 2757 | // We always use 0,0 as the position for the inset rect because |
| 2758 | // if we are getting insets at all in the pinned stack it must mean |
| 2759 | // we are headed for fullscreen. |
| 2760 | insetBounds = tempRect; |
| 2761 | insetBounds.top = 0; |
| 2762 | insetBounds.left = 0; |
| 2763 | insetBounds.right = tempPinnedTaskBounds.width(); |
| 2764 | insetBounds.bottom = tempPinnedTaskBounds.height(); |
| 2765 | } |
| 2766 | stack.resize(pinnedBounds, tempPinnedTaskBounds, insetBounds); |
Wale Ogunwale | db0fa12 | 2016-05-16 15:12:03 -0700 | [diff] [blame] | 2767 | stack.ensureVisibleActivitiesConfigurationLocked(r, false); |
Robert Carr | 0d00c2e | 2016-02-29 17:45:02 -0800 | [diff] [blame] | 2768 | } finally { |
| 2769 | mWindowManager.continueSurfaceLayout(); |
| 2770 | Trace.traceEnd(TRACE_TAG_ACTIVITY_MANAGER); |
| 2771 | } |
| 2772 | } |
| 2773 | |
Wale Ogunwale | a0f5b5e | 2017-10-11 09:37:23 -0700 | [diff] [blame] | 2774 | private void removeStackInSurfaceTransaction(ActivityStack stack) { |
Winson Chung | 010927a | 2016-12-15 16:12:35 -0800 | [diff] [blame] | 2775 | final ArrayList<TaskRecord> tasks = stack.getAllTasks(); |
Wale Ogunwale | 04a05ac | 2017-09-17 21:35:02 -0700 | [diff] [blame] | 2776 | if (stack.getWindowingMode() == WINDOWING_MODE_PINNED) { |
Winson Chung | 4790065 | 2017-04-06 18:44:25 -0700 | [diff] [blame] | 2777 | /** |
| 2778 | * Workaround: Force-stop all the activities in the pinned stack before we reparent them |
| 2779 | * to the fullscreen stack. This is to guarantee that when we are removing a stack, |
| 2780 | * that the client receives onStop() before it is reparented. We do this by detaching |
| 2781 | * the stack from the display so that it will be considered invisible when |
| 2782 | * ensureActivitiesVisibleLocked() is called, and all of its activitys will be marked |
| 2783 | * invisible as well and added to the stopping list. After which we process the |
| 2784 | * stopping list by handling the idle. |
| 2785 | */ |
| 2786 | final PinnedActivityStack pinnedStack = (PinnedActivityStack) stack; |
| 2787 | pinnedStack.mForceHidden = true; |
| 2788 | pinnedStack.ensureActivitiesVisibleLocked(null, 0, PRESERVE_WINDOWS); |
| 2789 | pinnedStack.mForceHidden = false; |
| 2790 | activityIdleInternalLocked(null, false /* fromTimeout */, |
| 2791 | true /* processPausingActivites */, null /* configuration */); |
| 2792 | |
| 2793 | // Move all the tasks to the bottom of the fullscreen stack |
Wale Ogunwale | 9dcf946 | 2017-09-19 15:13:01 -0700 | [diff] [blame] | 2794 | moveTasksToFullscreenStackLocked(pinnedStack, !ON_TOP); |
Winson Chung | 010927a | 2016-12-15 16:12:35 -0800 | [diff] [blame] | 2795 | } else { |
| 2796 | for (int i = tasks.size() - 1; i >= 0; i--) { |
| 2797 | removeTaskByIdLocked(tasks.get(i).taskId, true /* killProcess */, |
Winson Chung | 0ec2a35 | 2017-10-26 11:38:30 -0700 | [diff] [blame] | 2798 | REMOVE_FROM_RECENTS, "remove-stack"); |
Winson Chung | 010927a | 2016-12-15 16:12:35 -0800 | [diff] [blame] | 2799 | } |
| 2800 | } |
| 2801 | } |
| 2802 | |
| 2803 | /** |
Wale Ogunwale | a0f5b5e | 2017-10-11 09:37:23 -0700 | [diff] [blame] | 2804 | * 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] | 2805 | * pinned stack, then its tasks are not explicitly removed when the stack is destroyed, but |
| 2806 | * instead moved back onto the fullscreen stack. |
| 2807 | */ |
Wale Ogunwale | a0f5b5e | 2017-10-11 09:37:23 -0700 | [diff] [blame] | 2808 | void removeStack(ActivityStack stack) { |
| 2809 | mWindowManager.inSurfaceTransaction(() -> removeStackInSurfaceTransaction(stack)); |
Wale Ogunwale | 04a05ac | 2017-09-17 21:35:02 -0700 | [diff] [blame] | 2810 | } |
| 2811 | |
Wale Ogunwale | 6827856 | 2017-09-23 17:13:55 -0700 | [diff] [blame] | 2812 | /** |
| 2813 | * Removes stacks in the input windowing modes from the system if they are of activity type |
| 2814 | * ACTIVITY_TYPE_STANDARD or ACTIVITY_TYPE_UNDEFINED |
| 2815 | */ |
| 2816 | void removeStacksInWindowingModes(int... windowingModes) { |
Wale Ogunwale | 04a05ac | 2017-09-17 21:35:02 -0700 | [diff] [blame] | 2817 | for (int i = mActivityDisplays.size() - 1; i >= 0; --i) { |
Wale Ogunwale | 6827856 | 2017-09-23 17:13:55 -0700 | [diff] [blame] | 2818 | mActivityDisplays.valueAt(i).removeStacksInWindowingModes(windowingModes); |
| 2819 | } |
| 2820 | } |
| 2821 | |
| 2822 | void removeStacksWithActivityTypes(int... activityTypes) { |
| 2823 | for (int i = mActivityDisplays.size() - 1; i >= 0; --i) { |
| 2824 | mActivityDisplays.valueAt(i).removeStacksWithActivityTypes(activityTypes); |
Wale Ogunwale | 04a05ac | 2017-09-17 21:35:02 -0700 | [diff] [blame] | 2825 | } |
Robert Carr | 6914f08 | 2017-03-20 19:04:30 -0700 | [diff] [blame] | 2826 | } |
| 2827 | |
| 2828 | /** |
Winson Chung | 6954fc9 | 2017-03-24 16:22:12 -0700 | [diff] [blame] | 2829 | * See {@link #removeTaskByIdLocked(int, boolean, boolean, boolean)} |
| 2830 | */ |
Winson Chung | 0ec2a35 | 2017-10-26 11:38:30 -0700 | [diff] [blame] | 2831 | boolean removeTaskByIdLocked(int taskId, boolean killProcess, boolean removeFromRecents, |
| 2832 | String reason) { |
| 2833 | return removeTaskByIdLocked(taskId, killProcess, removeFromRecents, !PAUSE_IMMEDIATELY, |
| 2834 | reason); |
Winson Chung | 6954fc9 | 2017-03-24 16:22:12 -0700 | [diff] [blame] | 2835 | } |
| 2836 | |
| 2837 | /** |
Winson Chung | 010927a | 2016-12-15 16:12:35 -0800 | [diff] [blame] | 2838 | * Removes the task with the specified task id. |
| 2839 | * |
| 2840 | * @param taskId Identifier of the task to be removed. |
| 2841 | * @param killProcess Kill any process associated with the task if possible. |
| 2842 | * @param removeFromRecents Whether to also remove the task from recents. |
Winson Chung | 6954fc9 | 2017-03-24 16:22:12 -0700 | [diff] [blame] | 2843 | * @param pauseImmediately Pauses all task activities immediately without waiting for the |
| 2844 | * pause-complete callback from the activity. |
Winson Chung | 010927a | 2016-12-15 16:12:35 -0800 | [diff] [blame] | 2845 | * @return Returns true if the given task was found and removed. |
| 2846 | */ |
Winson Chung | 6954fc9 | 2017-03-24 16:22:12 -0700 | [diff] [blame] | 2847 | boolean removeTaskByIdLocked(int taskId, boolean killProcess, boolean removeFromRecents, |
Winson Chung | 0ec2a35 | 2017-10-26 11:38:30 -0700 | [diff] [blame] | 2848 | boolean pauseImmediately, String reason) { |
Wale Ogunwale | 0568aed | 2017-09-08 13:29:37 -0700 | [diff] [blame] | 2849 | final TaskRecord tr = anyTaskForIdLocked(taskId, MATCH_TASK_IN_STACKS_OR_RECENT_TASKS); |
Winson Chung | 010927a | 2016-12-15 16:12:35 -0800 | [diff] [blame] | 2850 | if (tr != null) { |
Winson Chung | 0ec2a35 | 2017-10-26 11:38:30 -0700 | [diff] [blame] | 2851 | tr.removeTaskActivitiesLocked(pauseImmediately, reason); |
Winson Chung | 010927a | 2016-12-15 16:12:35 -0800 | [diff] [blame] | 2852 | cleanUpRemovedTaskLocked(tr, killProcess, removeFromRecents); |
Charles He | ff9b4dff | 2017-09-22 10:18:37 +0100 | [diff] [blame] | 2853 | mService.mLockTaskController.clearLockedTask(tr); |
Winson Chung | 010927a | 2016-12-15 16:12:35 -0800 | [diff] [blame] | 2854 | if (tr.isPersistable) { |
| 2855 | mService.notifyTaskPersisterLocked(null, true); |
| 2856 | } |
| 2857 | return true; |
| 2858 | } |
| 2859 | Slog.w(TAG, "Request to remove task ignored for non-existent task " + taskId); |
| 2860 | return false; |
| 2861 | } |
| 2862 | |
| 2863 | void cleanUpRemovedTaskLocked(TaskRecord tr, boolean killProcess, boolean removeFromRecents) { |
| 2864 | if (removeFromRecents) { |
Winson Chung | 1dbc811 | 2017-09-28 18:05:31 -0700 | [diff] [blame] | 2865 | mRecentTasks.remove(tr); |
Winson Chung | 010927a | 2016-12-15 16:12:35 -0800 | [diff] [blame] | 2866 | } |
| 2867 | ComponentName component = tr.getBaseIntent().getComponent(); |
| 2868 | if (component == null) { |
| 2869 | Slog.w(TAG, "No component for base intent of task: " + tr); |
| 2870 | return; |
| 2871 | } |
| 2872 | |
| 2873 | // Find any running services associated with this app and stop if needed. |
| 2874 | mService.mServices.cleanUpRemovedTaskLocked(tr, component, new Intent(tr.getBaseIntent())); |
| 2875 | |
| 2876 | if (!killProcess) { |
| 2877 | return; |
| 2878 | } |
| 2879 | |
| 2880 | // Determine if the process(es) for this task should be killed. |
| 2881 | final String pkg = component.getPackageName(); |
| 2882 | ArrayList<ProcessRecord> procsToKill = new ArrayList<>(); |
| 2883 | ArrayMap<String, SparseArray<ProcessRecord>> pmap = mService.mProcessNames.getMap(); |
| 2884 | for (int i = 0; i < pmap.size(); i++) { |
| 2885 | |
| 2886 | SparseArray<ProcessRecord> uids = pmap.valueAt(i); |
| 2887 | for (int j = 0; j < uids.size(); j++) { |
| 2888 | ProcessRecord proc = uids.valueAt(j); |
| 2889 | if (proc.userId != tr.userId) { |
| 2890 | // Don't kill process for a different user. |
| 2891 | continue; |
| 2892 | } |
| 2893 | if (proc == mService.mHomeProcess) { |
| 2894 | // Don't kill the home process along with tasks from the same package. |
| 2895 | continue; |
| 2896 | } |
| 2897 | if (!proc.pkgList.containsKey(pkg)) { |
| 2898 | // Don't kill process that is not associated with this task. |
| 2899 | continue; |
| 2900 | } |
| 2901 | |
| 2902 | for (int k = 0; k < proc.activities.size(); k++) { |
Bryce Lee | af691c0 | 2017-03-20 14:20:22 -0700 | [diff] [blame] | 2903 | TaskRecord otherTask = proc.activities.get(k).getTask(); |
Winson Chung | 010927a | 2016-12-15 16:12:35 -0800 | [diff] [blame] | 2904 | if (tr.taskId != otherTask.taskId && otherTask.inRecents) { |
| 2905 | // Don't kill process(es) that has an activity in a different task that is |
| 2906 | // also in recents. |
| 2907 | return; |
| 2908 | } |
| 2909 | } |
| 2910 | |
| 2911 | if (proc.foregroundServices) { |
| 2912 | // Don't kill process(es) with foreground service. |
| 2913 | return; |
| 2914 | } |
| 2915 | |
| 2916 | // Add process to kill list. |
| 2917 | procsToKill.add(proc); |
| 2918 | } |
| 2919 | } |
| 2920 | |
| 2921 | // Kill the running processes. |
| 2922 | for (int i = 0; i < procsToKill.size(); i++) { |
| 2923 | ProcessRecord pr = procsToKill.get(i); |
| 2924 | if (pr.setSchedGroup == ProcessList.SCHED_GROUP_BACKGROUND |
| 2925 | && pr.curReceivers.isEmpty()) { |
| 2926 | pr.kill("remove task", true); |
| 2927 | } else { |
| 2928 | // We delay killing processes that are not in the background or running a receiver. |
| 2929 | pr.waitingToKill = "remove task"; |
| 2930 | } |
| 2931 | } |
| 2932 | } |
| 2933 | |
Chong Zhang | 5dcb275 | 2015-08-18 13:50:26 -0700 | [diff] [blame] | 2934 | /** |
Winson Chung | 1dbc811 | 2017-09-28 18:05:31 -0700 | [diff] [blame] | 2935 | * Called to restore the state of the task into the stack that it's supposed to go into. |
| 2936 | * |
Chong Zhang | 5dcb275 | 2015-08-18 13:50:26 -0700 | [diff] [blame] | 2937 | * @param task The recent task to be restored. |
Wale Ogunwale | 0568aed | 2017-09-08 13:29:37 -0700 | [diff] [blame] | 2938 | * @param aOptions The activity options to use for restoration. |
Wale Ogunwale | ab5de37 | 2017-10-18 06:46:31 -0700 | [diff] [blame] | 2939 | * @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] | 2940 | * @return true if the task has been restored successfully. |
| 2941 | */ |
Wale Ogunwale | ab5de37 | 2017-10-18 06:46:31 -0700 | [diff] [blame] | 2942 | boolean restoreRecentTaskLocked(TaskRecord task, ActivityOptions aOptions, boolean onTop) { |
| 2943 | final ActivityStack stack = getLaunchStack(null, aOptions, task, onTop); |
Andrii Kulian | 02b7a83 | 2016-10-06 23:11:56 -0700 | [diff] [blame] | 2944 | final ActivityStack currentStack = task.getStack(); |
| 2945 | if (currentStack != null) { |
Wale Ogunwale | 706ed79 | 2015-08-02 10:29:44 -0700 | [diff] [blame] | 2946 | // 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] | 2947 | if (currentStack == stack) { |
Wale Ogunwale | 706ed79 | 2015-08-02 10:29:44 -0700 | [diff] [blame] | 2948 | // Nothing else to do since it is already restored in the right stack. |
| 2949 | return true; |
| 2950 | } |
| 2951 | // Remove current stack association, so we can re-associate the task with the |
| 2952 | // right stack below. |
Andrii Kulian | 02b7a83 | 2016-10-06 23:11:56 -0700 | [diff] [blame] | 2953 | currentStack.removeTask(task, "restoreRecentTaskLocked", REMOVE_TASK_MODE_MOVING); |
Wale Ogunwale | 706ed79 | 2015-08-02 10:29:44 -0700 | [diff] [blame] | 2954 | } |
| 2955 | |
Wale Ogunwale | ab5de37 | 2017-10-18 06:46:31 -0700 | [diff] [blame] | 2956 | stack.addTask(task, onTop, "restoreRecentTask"); |
Wale Ogunwale | e1fe7fa2 | 2016-12-15 18:27:00 -0800 | [diff] [blame] | 2957 | // TODO: move call for creation here and other place into Stack.addTask() |
Wale Ogunwale | ab5de37 | 2017-10-18 06:46:31 -0700 | [diff] [blame] | 2958 | task.createWindowContainer(onTop, true /* showForAllUsers */); |
Wale Ogunwale | ee006da | 2015-03-30 14:49:25 -0700 | [diff] [blame] | 2959 | if (DEBUG_RECENTS) Slog.v(TAG_RECENTS, |
| 2960 | "Added restored task=" + task + " to stack=" + stack); |
Wale Ogunwale | 7de0535 | 2014-12-12 15:21:33 -0800 | [diff] [blame] | 2961 | final ArrayList<ActivityRecord> activities = task.mActivities; |
| 2962 | for (int activityNdx = activities.size() - 1; activityNdx >= 0; --activityNdx) { |
Wale Ogunwale | 26c0dfe | 2016-12-14 14:42:30 -0800 | [diff] [blame] | 2963 | activities.get(activityNdx).createWindowContainer(); |
Wale Ogunwale | 7de0535 | 2014-12-12 15:21:33 -0800 | [diff] [blame] | 2964 | } |
| 2965 | return true; |
Craig Mautner | ef73ee1 | 2014-04-23 11:45:37 -0700 | [diff] [blame] | 2966 | } |
| 2967 | |
Winson Chung | 1dbc811 | 2017-09-28 18:05:31 -0700 | [diff] [blame] | 2968 | @Override |
| 2969 | public void onRecentTaskAdded(TaskRecord task) { |
| 2970 | task.touchActiveTime(); |
| 2971 | } |
| 2972 | |
| 2973 | @Override |
Winson Chung | d6aa3db | 2017-10-05 17:18:43 -0700 | [diff] [blame] | 2974 | public void onRecentTaskRemoved(TaskRecord task, boolean wasTrimmed) { |
Winson Chung | 0ec2a35 | 2017-10-26 11:38:30 -0700 | [diff] [blame] | 2975 | if (wasTrimmed) { |
| 2976 | // Task was trimmed from the recent tasks list -- remove the active task record as well |
| 2977 | // since the user won't really be able to go back to it |
| 2978 | removeTaskByIdLocked(task.taskId, false /* killProcess */, |
| 2979 | false /* removeFromRecents */, !PAUSE_IMMEDIATELY, "recent-task-trimmed"); |
| 2980 | } |
Winson Chung | 1dbc811 | 2017-09-28 18:05:31 -0700 | [diff] [blame] | 2981 | task.removedFromRecents(); |
| 2982 | } |
| 2983 | |
Wale Ogunwale | 040b470 | 2015-08-06 18:10:50 -0700 | [diff] [blame] | 2984 | /** |
Andrii Kulian | 839def9 | 2016-11-02 10:58:58 -0700 | [diff] [blame] | 2985 | * Move stack with all its existing content to specified display. |
| 2986 | * @param stackId Id of stack to move. |
| 2987 | * @param displayId Id of display to move stack to. |
Andrii Kulian | 250d653 | 2017-02-08 23:30:45 -0800 | [diff] [blame] | 2988 | * @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] | 2989 | */ |
Andrii Kulian | 250d653 | 2017-02-08 23:30:45 -0800 | [diff] [blame] | 2990 | void moveStackToDisplayLocked(int stackId, int displayId, boolean onTop) { |
Andrii Kulian | 62e6f25 | 2017-05-30 22:46:53 -0700 | [diff] [blame] | 2991 | final ActivityDisplay activityDisplay = getActivityDisplayOrCreateLocked(displayId); |
Andrii Kulian | 839def9 | 2016-11-02 10:58:58 -0700 | [diff] [blame] | 2992 | if (activityDisplay == null) { |
| 2993 | throw new IllegalArgumentException("moveStackToDisplayLocked: Unknown displayId=" |
| 2994 | + displayId); |
| 2995 | } |
Wale Ogunwale | 9dcf946 | 2017-09-19 15:13:01 -0700 | [diff] [blame] | 2996 | final ActivityStack stack = getStack(stackId); |
Andrii Kulian | 94e82d9b0 | 2017-07-13 15:33:06 -0700 | [diff] [blame] | 2997 | if (stack == null) { |
Andrii Kulian | 839def9 | 2016-11-02 10:58:58 -0700 | [diff] [blame] | 2998 | throw new IllegalArgumentException("moveStackToDisplayLocked: Unknown stackId=" |
| 2999 | + stackId); |
| 3000 | } |
Andrii Kulian | 94e82d9b0 | 2017-07-13 15:33:06 -0700 | [diff] [blame] | 3001 | |
| 3002 | final ActivityDisplay currentDisplay = stack.getDisplay(); |
| 3003 | if (currentDisplay == null) { |
| 3004 | throw new IllegalStateException("moveStackToDisplayLocked: Stack with stack=" + stack |
| 3005 | + " is not attached to any display."); |
| 3006 | } |
| 3007 | |
| 3008 | if (currentDisplay.mDisplayId == displayId) { |
| 3009 | throw new IllegalArgumentException("Trying to move stack=" + stack |
| 3010 | + " to its current displayId=" + displayId); |
| 3011 | } |
| 3012 | |
| 3013 | stack.reparent(activityDisplay, onTop); |
Andrii Kulian | 839def9 | 2016-11-02 10:58:58 -0700 | [diff] [blame] | 3014 | // TODO(multi-display): resize stacks properly if moved from split-screen. |
| 3015 | } |
| 3016 | |
| 3017 | /** |
Winson Chung | 7466610 | 2017-02-22 17:49:24 -0800 | [diff] [blame] | 3018 | * Returns the reparent target stack, creating the stack if necessary. This call also enforces |
| 3019 | * 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] | 3020 | */ |
Wale Ogunwale | 30e441d | 2017-11-09 08:28:45 -0800 | [diff] [blame] | 3021 | // TODO: Look into changing users to this method to ActivityDisplay.resolveWindowingMode() |
Wale Ogunwale | 04a05ac | 2017-09-17 21:35:02 -0700 | [diff] [blame] | 3022 | ActivityStack getReparentTargetStack(TaskRecord task, ActivityStack stack, boolean toTop) { |
Andrii Kulian | 02b7a83 | 2016-10-06 23:11:56 -0700 | [diff] [blame] | 3023 | final ActivityStack prevStack = task.getStack(); |
Wale Ogunwale | 04a05ac | 2017-09-17 21:35:02 -0700 | [diff] [blame] | 3024 | final int stackId = stack.mStackId; |
| 3025 | final boolean inMultiWindowMode = stack.inMultiWindowMode(); |
Chong Zhang | 0289835 | 2015-08-21 17:27:14 -0700 | [diff] [blame] | 3026 | |
Winson Chung | 7466610 | 2017-02-22 17:49:24 -0800 | [diff] [blame] | 3027 | // Check that we aren't reparenting to the same stack that the task is already in |
| 3028 | if (prevStack != null && prevStack.mStackId == stackId) { |
| 3029 | Slog.w(TAG, "Can not reparent to same stack, task=" + task |
| 3030 | + " already in stackId=" + stackId); |
| 3031 | return prevStack; |
Wale Ogunwale | 513346d | 2016-01-27 10:55:01 -0800 | [diff] [blame] | 3032 | } |
| 3033 | |
Winson Chung | 7466610 | 2017-02-22 17:49:24 -0800 | [diff] [blame] | 3034 | // Ensure that we aren't trying to move into a multi-window stack without multi-window |
| 3035 | // support |
Wale Ogunwale | 04a05ac | 2017-09-17 21:35:02 -0700 | [diff] [blame] | 3036 | if (inMultiWindowMode && !mService.mSupportsMultiWindow) { |
Winson Chung | 7466610 | 2017-02-22 17:49:24 -0800 | [diff] [blame] | 3037 | throw new IllegalArgumentException("Device doesn't support multi-window, can not" |
Wale Ogunwale | 04a05ac | 2017-09-17 21:35:02 -0700 | [diff] [blame] | 3038 | + " reparent task=" + task + " to stack=" + stack); |
Winson Chung | c2baac0 | 2017-01-11 13:34:47 -0800 | [diff] [blame] | 3039 | } |
| 3040 | |
Andrii Kulian | eafd9db | 2017-04-05 22:01:35 -0700 | [diff] [blame] | 3041 | // Ensure that we're not moving a task to a dynamic stack if device doesn't support |
| 3042 | // multi-display. |
Wale Ogunwale | 04a05ac | 2017-09-17 21:35:02 -0700 | [diff] [blame] | 3043 | if (stack.mDisplayId != DEFAULT_DISPLAY && !mService.mSupportsMultiDisplay) { |
Andrii Kulian | eafd9db | 2017-04-05 22:01:35 -0700 | [diff] [blame] | 3044 | throw new IllegalArgumentException("Device doesn't support multi-display, can not" |
| 3045 | + " reparent task=" + task + " to stackId=" + stackId); |
| 3046 | } |
| 3047 | |
Wale Ogunwale | 30e441d | 2017-11-09 08:28:45 -0800 | [diff] [blame] | 3048 | // 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] | 3049 | if (stack.getWindowingMode() == WINDOWING_MODE_FREEFORM |
| 3050 | && !mService.mSupportsFreeformWindowManagement) { |
Winson Chung | 7466610 | 2017-02-22 17:49:24 -0800 | [diff] [blame] | 3051 | throw new IllegalArgumentException("Device doesn't support freeform, can not reparent" |
| 3052 | + " task=" + task); |
Wale Ogunwale | 08559dc | 2016-02-23 12:20:08 -0800 | [diff] [blame] | 3053 | } |
| 3054 | |
Wale Ogunwale | 7e1f5f5 | 2017-10-18 15:19:59 -0700 | [diff] [blame] | 3055 | // Leave the task in its current stack or a fullscreen stack if it isn't resizeable and the |
| 3056 | // preferred stack is in multi-window mode. |
Wale Ogunwale | 04a05ac | 2017-09-17 21:35:02 -0700 | [diff] [blame] | 3057 | if (inMultiWindowMode && !task.isResizeable()) { |
Wale Ogunwale | 7e1f5f5 | 2017-10-18 15:19:59 -0700 | [diff] [blame] | 3058 | Slog.w(TAG, "Can not move unresizeable task=" + task + " to multi-window stack=" + stack |
| 3059 | + " Moving to a fullscreen stack instead."); |
| 3060 | if (prevStack != null) { |
| 3061 | return prevStack; |
Wale Ogunwale | 04a05ac | 2017-09-17 21:35:02 -0700 | [diff] [blame] | 3062 | } |
Wale Ogunwale | 7e1f5f5 | 2017-10-18 15:19:59 -0700 | [diff] [blame] | 3063 | stack = stack.getDisplay().createStack( |
| 3064 | WINDOWING_MODE_FULLSCREEN, stack.getActivityType(), toTop); |
Filip Gruszczynski | 49b80af | 2015-09-24 09:04:26 -0700 | [diff] [blame] | 3065 | } |
Wale Ogunwale | 04a05ac | 2017-09-17 21:35:02 -0700 | [diff] [blame] | 3066 | return stack; |
Craig Mautner | 8d341ef | 2013-03-26 09:03:27 -0700 | [diff] [blame] | 3067 | } |
| 3068 | |
Winson Chung | 08f8189 | 2017-03-02 15:40:51 -0800 | [diff] [blame] | 3069 | boolean moveTopStackActivityToPinnedStackLocked(int stackId, Rect destBounds) { |
Wale Ogunwale | 04a05ac | 2017-09-17 21:35:02 -0700 | [diff] [blame] | 3070 | final ActivityStack stack = getStack(stackId); |
Wale Ogunwale | 079a004 | 2015-10-24 11:44:07 -0700 | [diff] [blame] | 3071 | if (stack == null) { |
| 3072 | throw new IllegalArgumentException( |
| 3073 | "moveTopStackActivityToPinnedStackLocked: Unknown stackId=" + stackId); |
| 3074 | } |
| 3075 | |
| 3076 | final ActivityRecord r = stack.topRunningActivityLocked(); |
| 3077 | if (r == null) { |
| 3078 | Slog.w(TAG, "moveTopStackActivityToPinnedStackLocked: No top running activity" |
| 3079 | + " in stack=" + stack); |
| 3080 | return false; |
| 3081 | } |
| 3082 | |
Wale Ogunwale | 6cae765 | 2015-12-26 07:36:26 -0800 | [diff] [blame] | 3083 | if (!mService.mForceResizableActivities && !r.supportsPictureInPicture()) { |
Wale Ogunwale | b60692e | 2015-10-24 12:35:56 -0700 | [diff] [blame] | 3084 | Slog.w(TAG, |
| 3085 | "moveTopStackActivityToPinnedStackLocked: Picture-In-Picture not supported for " |
Filip Gruszczynski | 77d9448 | 2015-12-11 13:59:52 -0800 | [diff] [blame] | 3086 | + " r=" + r); |
Wale Ogunwale | 079a004 | 2015-10-24 11:44:07 -0700 | [diff] [blame] | 3087 | return false; |
| 3088 | } |
| 3089 | |
Winson Chung | 3a68287 | 2017-04-10 14:38:05 -0700 | [diff] [blame] | 3090 | moveActivityToPinnedStackLocked(r, null /* sourceBounds */, 0f /* aspectRatio */, |
Wale Ogunwale | 66e1685 | 2017-10-19 13:35:52 -0700 | [diff] [blame] | 3091 | "moveTopActivityToPinnedStack"); |
Wale Ogunwale | 9c604c7 | 2015-12-06 18:42:57 -0800 | [diff] [blame] | 3092 | return true; |
| 3093 | } |
| 3094 | |
Winson Chung | 8bca9e4 | 2017-04-16 15:59:43 -0700 | [diff] [blame] | 3095 | void moveActivityToPinnedStackLocked(ActivityRecord r, Rect sourceHintBounds, float aspectRatio, |
Wale Ogunwale | 66e1685 | 2017-10-19 13:35:52 -0700 | [diff] [blame] | 3096 | String reason) { |
Winson Chung | 08f8189 | 2017-03-02 15:40:51 -0800 | [diff] [blame] | 3097 | |
Wale Ogunwale | 480dca0 | 2016-02-06 13:58:29 -0800 | [diff] [blame] | 3098 | mWindowManager.deferSurfaceLayout(); |
Winson Chung | 7466610 | 2017-02-22 17:49:24 -0800 | [diff] [blame] | 3099 | |
Wale Ogunwale | 04a05ac | 2017-09-17 21:35:02 -0700 | [diff] [blame] | 3100 | final ActivityDisplay display = r.getStack().getDisplay(); |
| 3101 | PinnedActivityStack stack = display.getPinnedStack(); |
Wale Ogunwale | 9dcf946 | 2017-09-19 15:13:01 -0700 | [diff] [blame] | 3102 | |
Bryce Lee | 04ab346 | 2017-04-10 15:06:33 -0700 | [diff] [blame] | 3103 | // This will clear the pinned stack by moving an existing task to the full screen stack, |
| 3104 | // ensuring only one task is present. |
Wale Ogunwale | 9dcf946 | 2017-09-19 15:13:01 -0700 | [diff] [blame] | 3105 | if (stack != null) { |
| 3106 | moveTasksToFullscreenStackLocked(stack, !ON_TOP); |
| 3107 | } |
Bryce Lee | 04ab346 | 2017-04-10 15:06:33 -0700 | [diff] [blame] | 3108 | |
Wale Ogunwale | 1666e31 | 2016-12-16 11:27:18 -0800 | [diff] [blame] | 3109 | // 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] | 3110 | stack = display.getOrCreateStack(WINDOWING_MODE_PINNED, r.getActivityType(), ON_TOP); |
Wale Ogunwale | 1666e31 | 2016-12-16 11:27:18 -0800 | [diff] [blame] | 3111 | |
Winson Chung | e55c019 | 2017-08-24 14:50:48 -0700 | [diff] [blame] | 3112 | // Calculate the target bounds here before the task is reparented back into pinned windowing |
| 3113 | // mode (which will reset the saved bounds) |
| 3114 | final Rect destBounds = stack.getDefaultPictureInPictureBounds(aspectRatio); |
| 3115 | |
Wale Ogunwale | 480dca0 | 2016-02-06 13:58:29 -0800 | [diff] [blame] | 3116 | try { |
Bryce Lee | af691c0 | 2017-03-20 14:20:22 -0700 | [diff] [blame] | 3117 | final TaskRecord task = r.getTask(); |
Wale Ogunwale | 480dca0 | 2016-02-06 13:58:29 -0800 | [diff] [blame] | 3118 | // Resize the pinned stack to match the current size of the task the activity we are |
| 3119 | // going to be moving is currently contained in. We do this to have the right starting |
| 3120 | // 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] | 3121 | resizeStackLocked(stack, task.getOverrideBounds(), null /* tempTaskBounds */, |
Wale Ogunwale | 480dca0 | 2016-02-06 13:58:29 -0800 | [diff] [blame] | 3122 | null /* tempTaskInsetBounds */, !PRESERVE_WINDOWS, |
Wale Ogunwale | c8da41e | 2016-04-16 13:27:23 -0700 | [diff] [blame] | 3123 | true /* allowResizeInDockedMode */, !DEFER_RESUME); |
Wale Ogunwale | 480dca0 | 2016-02-06 13:58:29 -0800 | [diff] [blame] | 3124 | |
| 3125 | if (task.mActivities.size() == 1) { |
Winson Chung | 5af42fc | 2017-03-24 17:11:33 -0700 | [diff] [blame] | 3126 | // 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] | 3127 | task.reparent(stack, ON_TOP, REPARENT_MOVE_STACK_TO_FRONT, !ANIMATE, DEFER_RESUME, |
| 3128 | false /* schedulePictureInPictureModeChange */, reason); |
Wale Ogunwale | 480dca0 | 2016-02-06 13:58:29 -0800 | [diff] [blame] | 3129 | } else { |
Winson Chung | b5c41b7 | 2016-12-07 15:00:47 -0800 | [diff] [blame] | 3130 | // 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] | 3131 | // reveal/leave the other activities in their original task. |
| 3132 | |
| 3133 | // Currently, we don't support reparenting activities across tasks in two different |
| 3134 | // stacks, so instead, just create a new task in the same stack, reparent the |
| 3135 | // activity into that task, and then reparent the whole task to the new stack. This |
| 3136 | // ensures that all the necessary work to migrate states in the old and new stacks |
| 3137 | // is also done. |
| 3138 | final TaskRecord newTask = task.getStack().createTaskRecord( |
Wale Ogunwale | 6fbde9f | 2017-08-24 07:24:12 -0700 | [diff] [blame] | 3139 | getNextTaskIdForUserLocked(r.userId), r.info, r.intent, null, null, true); |
Winson Chung | 7466610 | 2017-02-22 17:49:24 -0800 | [diff] [blame] | 3140 | r.reparent(newTask, MAX_VALUE, "moveActivityToStack"); |
| 3141 | |
Winson Chung | 5af42fc | 2017-03-24 17:11:33 -0700 | [diff] [blame] | 3142 | // 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] | 3143 | newTask.reparent(stack, ON_TOP, REPARENT_MOVE_STACK_TO_FRONT, !ANIMATE, |
Winson Chung | 5af42fc | 2017-03-24 17:11:33 -0700 | [diff] [blame] | 3144 | DEFER_RESUME, false /* schedulePictureInPictureModeChange */, reason); |
Wale Ogunwale | 480dca0 | 2016-02-06 13:58:29 -0800 | [diff] [blame] | 3145 | } |
Winson Chung | c2baac0 | 2017-01-11 13:34:47 -0800 | [diff] [blame] | 3146 | |
| 3147 | // Reset the state that indicates it can enter PiP while pausing after we've moved it |
| 3148 | // to the pinned stack |
Winson Chung | f7e03e1 | 2017-08-22 11:32:16 -0700 | [diff] [blame] | 3149 | r.supportsEnterPipOnTaskSwitch = false; |
Wale Ogunwale | 480dca0 | 2016-02-06 13:58:29 -0800 | [diff] [blame] | 3150 | } finally { |
| 3151 | mWindowManager.continueSurfaceLayout(); |
Wale Ogunwale | 079a004 | 2015-10-24 11:44:07 -0700 | [diff] [blame] | 3152 | } |
| 3153 | |
Winson Chung | e7ba686 | 2017-05-24 12:13:33 -0700 | [diff] [blame] | 3154 | stack.animateResizePinnedStack(sourceHintBounds, destBounds, -1 /* animationDuration */, |
| 3155 | true /* fromFullscreen */); |
| 3156 | |
| 3157 | // Update the visibility of all activities after the they have been reparented to the new |
| 3158 | // stack. This MUST run after the animation above is scheduled to ensure that the windows |
| 3159 | // drawn signal is scheduled after the bounds animation start call on the bounds animator |
| 3160 | // thread. |
Wale Ogunwale | 079a004 | 2015-10-24 11:44:07 -0700 | [diff] [blame] | 3161 | ensureActivitiesVisibleLocked(null, 0, !PRESERVE_WINDOWS); |
Wale Ogunwale | d046a01 | 2015-12-24 13:05:59 -0800 | [diff] [blame] | 3162 | resumeFocusedStackTopActivityLocked(); |
Wale Ogunwale | 03ce863 | 2015-12-29 16:15:22 -0800 | [diff] [blame] | 3163 | |
Wale Ogunwale | 89be576 | 2017-10-04 13:27:49 -0700 | [diff] [blame] | 3164 | mService.mTaskChangeNotificationController.notifyActivityPinned(r); |
Wale Ogunwale | 079a004 | 2015-10-24 11:44:07 -0700 | [diff] [blame] | 3165 | } |
| 3166 | |
Andrii Kulian | 0864bbb | 2017-02-16 15:45:58 -0800 | [diff] [blame] | 3167 | /** Move activity with its stack to front and make the stack focused. */ |
Chong Zhang | 6cda19c | 2016-06-14 19:07:56 -0700 | [diff] [blame] | 3168 | boolean moveFocusableActivityStackToFrontLocked(ActivityRecord r, String reason) { |
| 3169 | if (r == null || !r.isFocusable()) { |
| 3170 | if (DEBUG_FOCUS) Slog.d(TAG_FOCUS, |
| 3171 | "moveActivityStackToFront: unfocusable r=" + r); |
| 3172 | return false; |
| 3173 | } |
| 3174 | |
Bryce Lee | af691c0 | 2017-03-20 14:20:22 -0700 | [diff] [blame] | 3175 | final TaskRecord task = r.getTask(); |
Andrii Kulian | 02b7a83 | 2016-10-06 23:11:56 -0700 | [diff] [blame] | 3176 | final ActivityStack stack = r.getStack(); |
| 3177 | if (stack == null) { |
Chong Zhang | 6cda19c | 2016-06-14 19:07:56 -0700 | [diff] [blame] | 3178 | Slog.w(TAG, "moveActivityStackToFront: invalid task or stack: r=" |
| 3179 | + r + " task=" + task); |
| 3180 | return false; |
| 3181 | } |
| 3182 | |
Chong Zhang | 6cda19c | 2016-06-14 19:07:56 -0700 | [diff] [blame] | 3183 | if (stack == mFocusedStack && stack.topRunningActivityLocked() == r) { |
| 3184 | if (DEBUG_FOCUS) Slog.d(TAG_FOCUS, |
| 3185 | "moveActivityStackToFront: already on top, r=" + r); |
| 3186 | return false; |
| 3187 | } |
| 3188 | |
| 3189 | if (DEBUG_FOCUS) Slog.d(TAG_FOCUS, |
| 3190 | "moveActivityStackToFront: r=" + r); |
| 3191 | |
| 3192 | stack.moveToFront(reason, task); |
| 3193 | return true; |
| 3194 | } |
| 3195 | |
David Stevens | c6b91c6 | 2017-02-08 14:23:58 -0800 | [diff] [blame] | 3196 | ActivityRecord findTaskLocked(ActivityRecord r, int displayId) { |
Wale Ogunwale | 3938197 | 2015-12-17 17:15:29 -0800 | [diff] [blame] | 3197 | mTmpFindTaskResult.r = null; |
| 3198 | mTmpFindTaskResult.matchedByRootAffinity = false; |
David Stevens | c6b91c6 | 2017-02-08 14:23:58 -0800 | [diff] [blame] | 3199 | ActivityRecord affinityMatch = null; |
Wale Ogunwale | ee006da | 2015-03-30 14:49:25 -0700 | [diff] [blame] | 3200 | if (DEBUG_TASKS) Slog.d(TAG_TASKS, "Looking for task of " + r); |
Craig Mautner | e0a3884 | 2013-12-16 16:14:02 -0800 | [diff] [blame] | 3201 | for (int displayNdx = mActivityDisplays.size() - 1; displayNdx >= 0; --displayNdx) { |
Wale Ogunwale | a0f5b5e | 2017-10-11 09:37:23 -0700 | [diff] [blame] | 3202 | final ActivityDisplay display = mActivityDisplays.valueAt(displayNdx); |
| 3203 | for (int stackNdx = display.getChildCount() - 1; stackNdx >= 0; --stackNdx) { |
| 3204 | final ActivityStack stack = display.getChildAt(stackNdx); |
Wale Ogunwale | 6fbde9f | 2017-08-24 07:24:12 -0700 | [diff] [blame] | 3205 | if (!r.hasCompatibleActivityType(stack)) { |
Winson Chung | 91e5c88 | 2017-04-21 14:44:38 -0700 | [diff] [blame] | 3206 | if (DEBUG_TASKS) Slog.d(TAG_TASKS, "Skipping stack: (mismatch activity/stack) " |
| 3207 | + stack); |
Craig Mautner | 1b4bf85 | 2014-05-26 15:06:32 -0700 | [diff] [blame] | 3208 | continue; |
| 3209 | } |
Wale Ogunwale | 3938197 | 2015-12-17 17:15:29 -0800 | [diff] [blame] | 3210 | stack.findTaskLocked(r, mTmpFindTaskResult); |
David Stevens | c6b91c6 | 2017-02-08 14:23:58 -0800 | [diff] [blame] | 3211 | // It is possible to have tasks in multiple stacks with the same root affinity, so |
| 3212 | // we should keep looking after finding an affinity match to see if there is a |
| 3213 | // better match in another stack. Also, task affinity isn't a good enough reason |
| 3214 | // to target a display which isn't the source of the intent, so skip any affinity |
| 3215 | // matches not on the specified display. |
| 3216 | if (mTmpFindTaskResult.r != null) { |
| 3217 | if (!mTmpFindTaskResult.matchedByRootAffinity) { |
| 3218 | return mTmpFindTaskResult.r; |
| 3219 | } else if (mTmpFindTaskResult.r.getDisplayId() == displayId) { |
Winson Chung | 5b895b7 | 2017-05-01 13:46:25 -0700 | [diff] [blame] | 3220 | // Note: since the traversing through the stacks is top down, the floating |
| 3221 | // tasks should always have lower priority than any affinity-matching tasks |
| 3222 | // in the fullscreen stacks |
David Stevens | c6b91c6 | 2017-02-08 14:23:58 -0800 | [diff] [blame] | 3223 | affinityMatch = mTmpFindTaskResult.r; |
David Stevens | e5a7b64 | 2017-05-22 13:18:23 -0700 | [diff] [blame] | 3224 | } else if (DEBUG_TASKS && mTmpFindTaskResult.matchedByRootAffinity) { |
| 3225 | Slog.d(TAG_TASKS, "Skipping match on different display " |
| 3226 | + mTmpFindTaskResult.r.getDisplayId() + " " + displayId); |
David Stevens | c6b91c6 | 2017-02-08 14:23:58 -0800 | [diff] [blame] | 3227 | } |
Craig Mautner | 4a1cb22 | 2013-12-04 16:14:06 -0800 | [diff] [blame] | 3228 | } |
Craig Mautner | 8849a5e | 2013-04-02 16:41:03 -0700 | [diff] [blame] | 3229 | } |
| 3230 | } |
Winson Chung | 5b895b7 | 2017-05-01 13:46:25 -0700 | [diff] [blame] | 3231 | |
David Stevens | c6b91c6 | 2017-02-08 14:23:58 -0800 | [diff] [blame] | 3232 | if (DEBUG_TASKS && affinityMatch == null) Slog.d(TAG_TASKS, "No task found"); |
| 3233 | return affinityMatch; |
Craig Mautner | 8849a5e | 2013-04-02 16:41:03 -0700 | [diff] [blame] | 3234 | } |
| 3235 | |
Andrii Kulian | d3bbb13 | 2016-06-16 16:00:20 -0700 | [diff] [blame] | 3236 | ActivityRecord findActivityLocked(Intent intent, ActivityInfo info, |
Wale Ogunwale | a0f5b5e | 2017-10-11 09:37:23 -0700 | [diff] [blame] | 3237 | boolean compareIntentFilters) { |
Craig Mautner | e0a3884 | 2013-12-16 16:14:02 -0800 | [diff] [blame] | 3238 | for (int displayNdx = mActivityDisplays.size() - 1; displayNdx >= 0; --displayNdx) { |
Wale Ogunwale | a0f5b5e | 2017-10-11 09:37:23 -0700 | [diff] [blame] | 3239 | final ActivityDisplay display = mActivityDisplays.valueAt(displayNdx); |
| 3240 | for (int stackNdx = display.getChildCount() - 1; stackNdx >= 0; --stackNdx) { |
| 3241 | final ActivityStack stack = display.getChildAt(stackNdx); |
| 3242 | final ActivityRecord ar = stack.findActivityLocked( |
| 3243 | intent, info, compareIntentFilters); |
Craig Mautner | 4a1cb22 | 2013-12-04 16:14:06 -0800 | [diff] [blame] | 3244 | if (ar != null) { |
| 3245 | return ar; |
| 3246 | } |
Craig Mautner | 8849a5e | 2013-04-02 16:41:03 -0700 | [diff] [blame] | 3247 | } |
| 3248 | } |
| 3249 | return null; |
| 3250 | } |
| 3251 | |
David Stevens | 9440dc8 | 2017-03-16 19:00:20 -0700 | [diff] [blame] | 3252 | boolean hasAwakeDisplay() { |
| 3253 | for (int displayNdx = mActivityDisplays.size() - 1; displayNdx >= 0; --displayNdx) { |
| 3254 | final ActivityDisplay display = mActivityDisplays.valueAt(displayNdx); |
| 3255 | if (!display.shouldSleep()) { |
| 3256 | return true; |
| 3257 | } |
| 3258 | } |
| 3259 | return false; |
| 3260 | } |
| 3261 | |
Craig Mautner | 8d341ef | 2013-03-26 09:03:27 -0700 | [diff] [blame] | 3262 | void goingToSleepLocked() { |
Craig Mautner | 0eea92c | 2013-05-16 13:35:39 -0700 | [diff] [blame] | 3263 | scheduleSleepTimeout(); |
| 3264 | if (!mGoingToSleep.isHeld()) { |
| 3265 | mGoingToSleep.acquire(); |
Craig Mautner | 7ea5bd4 | 2013-07-05 15:27:08 -0700 | [diff] [blame] | 3266 | if (mLaunchingActivity.isHeld()) { |
| 3267 | if (VALIDATE_WAKE_LOCK_CALLER && Binder.getCallingUid() != Process.myUid()) { |
| 3268 | throw new IllegalStateException("Calling must be system uid"); |
Craig Mautner | 0eea92c | 2013-05-16 13:35:39 -0700 | [diff] [blame] | 3269 | } |
Craig Mautner | 7ea5bd4 | 2013-07-05 15:27:08 -0700 | [diff] [blame] | 3270 | mLaunchingActivity.release(); |
| 3271 | mService.mHandler.removeMessages(LAUNCH_TIMEOUT_MSG); |
Craig Mautner | 0eea92c | 2013-05-16 13:35:39 -0700 | [diff] [blame] | 3272 | } |
Craig Mautner | 8d341ef | 2013-03-26 09:03:27 -0700 | [diff] [blame] | 3273 | } |
David Stevens | 9440dc8 | 2017-03-16 19:00:20 -0700 | [diff] [blame] | 3274 | |
| 3275 | applySleepTokensLocked(false /* applyToStacks */); |
| 3276 | |
| 3277 | checkReadyForSleepLocked(true /* allowDelay */); |
| 3278 | } |
| 3279 | |
| 3280 | void prepareForShutdownLocked() { |
| 3281 | for (int i = 0; i < mActivityDisplays.size(); i++) { |
| 3282 | createSleepTokenLocked("shutdown", mActivityDisplays.keyAt(i)); |
| 3283 | } |
Craig Mautner | 8d341ef | 2013-03-26 09:03:27 -0700 | [diff] [blame] | 3284 | } |
| 3285 | |
| 3286 | boolean shutdownLocked(int timeout) { |
Craig Mautner | 0eea92c | 2013-05-16 13:35:39 -0700 | [diff] [blame] | 3287 | goingToSleepLocked(); |
Craig Mautner | 0eea92c | 2013-05-16 13:35:39 -0700 | [diff] [blame] | 3288 | |
Craig Mautner | f4c909b | 2014-04-17 18:39:38 -0700 | [diff] [blame] | 3289 | boolean timedout = false; |
Craig Mautner | 0eea92c | 2013-05-16 13:35:39 -0700 | [diff] [blame] | 3290 | final long endTime = System.currentTimeMillis() + timeout; |
| 3291 | while (true) { |
David Stevens | 18abd0e | 2017-08-17 14:55:47 -0700 | [diff] [blame] | 3292 | if (!putStacksToSleepLocked(true /* allowDelay */, true /* shuttingDown */)) { |
Craig Mautner | 0eea92c | 2013-05-16 13:35:39 -0700 | [diff] [blame] | 3293 | long timeRemaining = endTime - System.currentTimeMillis(); |
| 3294 | if (timeRemaining > 0) { |
Craig Mautner | 8d341ef | 2013-03-26 09:03:27 -0700 | [diff] [blame] | 3295 | try { |
Craig Mautner | 0eea92c | 2013-05-16 13:35:39 -0700 | [diff] [blame] | 3296 | mService.wait(timeRemaining); |
Craig Mautner | 8d341ef | 2013-03-26 09:03:27 -0700 | [diff] [blame] | 3297 | } catch (InterruptedException e) { |
| 3298 | } |
Craig Mautner | 0eea92c | 2013-05-16 13:35:39 -0700 | [diff] [blame] | 3299 | } else { |
| 3300 | Slog.w(TAG, "Activity manager shutdown timed out"); |
| 3301 | timedout = true; |
| 3302 | break; |
Craig Mautner | 8d341ef | 2013-03-26 09:03:27 -0700 | [diff] [blame] | 3303 | } |
Craig Mautner | 0eea92c | 2013-05-16 13:35:39 -0700 | [diff] [blame] | 3304 | } else { |
| 3305 | break; |
Craig Mautner | 8d341ef | 2013-03-26 09:03:27 -0700 | [diff] [blame] | 3306 | } |
| 3307 | } |
Craig Mautner | 0eea92c | 2013-05-16 13:35:39 -0700 | [diff] [blame] | 3308 | |
| 3309 | // Force checkReadyForSleep to complete. |
David Stevens | 9440dc8 | 2017-03-16 19:00:20 -0700 | [diff] [blame] | 3310 | checkReadyForSleepLocked(false /* allowDelay */); |
Craig Mautner | 0eea92c | 2013-05-16 13:35:39 -0700 | [diff] [blame] | 3311 | |
Craig Mautner | 8d341ef | 2013-03-26 09:03:27 -0700 | [diff] [blame] | 3312 | return timedout; |
| 3313 | } |
| 3314 | |
| 3315 | void comeOutOfSleepIfNeededLocked() { |
Craig Mautner | 0eea92c | 2013-05-16 13:35:39 -0700 | [diff] [blame] | 3316 | removeSleepTimeouts(); |
| 3317 | if (mGoingToSleep.isHeld()) { |
| 3318 | mGoingToSleep.release(); |
| 3319 | } |
David Stevens | 9440dc8 | 2017-03-16 19:00:20 -0700 | [diff] [blame] | 3320 | } |
| 3321 | |
| 3322 | void applySleepTokensLocked(boolean applyToStacks) { |
Craig Mautner | e0a3884 | 2013-12-16 16:14:02 -0800 | [diff] [blame] | 3323 | for (int displayNdx = mActivityDisplays.size() - 1; displayNdx >= 0; --displayNdx) { |
David Stevens | 9440dc8 | 2017-03-16 19:00:20 -0700 | [diff] [blame] | 3324 | // Set the sleeping state of the display. |
| 3325 | final ActivityDisplay display = mActivityDisplays.valueAt(displayNdx); |
| 3326 | final boolean displayShouldSleep = display.shouldSleep(); |
| 3327 | if (displayShouldSleep == display.isSleeping()) { |
| 3328 | continue; |
| 3329 | } |
| 3330 | display.setIsSleeping(displayShouldSleep); |
| 3331 | |
| 3332 | if (!applyToStacks) { |
| 3333 | continue; |
| 3334 | } |
| 3335 | |
| 3336 | // Set the sleeping state of the stacks on the display. |
Wale Ogunwale | a0f5b5e | 2017-10-11 09:37:23 -0700 | [diff] [blame] | 3337 | for (int stackNdx = display.getChildCount() - 1; stackNdx >= 0; --stackNdx) { |
| 3338 | final ActivityStack stack = display.getChildAt(stackNdx); |
David Stevens | 9440dc8 | 2017-03-16 19:00:20 -0700 | [diff] [blame] | 3339 | if (displayShouldSleep) { |
| 3340 | stack.goToSleepIfPossible(false /* shuttingDown */); |
| 3341 | } else { |
| 3342 | stack.awakeFromSleepingLocked(); |
| 3343 | if (isFocusedStack(stack)) { |
| 3344 | resumeFocusedStackTopActivityLocked(); |
| 3345 | } |
| 3346 | } |
| 3347 | } |
| 3348 | |
| 3349 | if (displayShouldSleep || mGoingToSleepActivities.isEmpty()) { |
| 3350 | continue; |
| 3351 | } |
| 3352 | // The display is awake now, so clean up the going to sleep list. |
| 3353 | for (Iterator<ActivityRecord> it = mGoingToSleepActivities.iterator(); it.hasNext(); ) { |
| 3354 | final ActivityRecord r = it.next(); |
| 3355 | if (r.getDisplayId() == display.mDisplayId) { |
| 3356 | it.remove(); |
Craig Mautner | 4a1cb22 | 2013-12-04 16:14:06 -0800 | [diff] [blame] | 3357 | } |
Craig Mautner | 5314a40 | 2013-09-26 12:40:16 -0700 | [diff] [blame] | 3358 | } |
Craig Mautner | 8d341ef | 2013-03-26 09:03:27 -0700 | [diff] [blame] | 3359 | } |
Craig Mautner | 0eea92c | 2013-05-16 13:35:39 -0700 | [diff] [blame] | 3360 | } |
| 3361 | |
| 3362 | void activitySleptLocked(ActivityRecord r) { |
| 3363 | mGoingToSleepActivities.remove(r); |
David Stevens | 9440dc8 | 2017-03-16 19:00:20 -0700 | [diff] [blame] | 3364 | final ActivityStack s = r.getStack(); |
| 3365 | if (s != null) { |
| 3366 | s.checkReadyForSleep(); |
| 3367 | } else { |
| 3368 | checkReadyForSleepLocked(true); |
| 3369 | } |
Craig Mautner | 0eea92c | 2013-05-16 13:35:39 -0700 | [diff] [blame] | 3370 | } |
| 3371 | |
David Stevens | 9440dc8 | 2017-03-16 19:00:20 -0700 | [diff] [blame] | 3372 | void checkReadyForSleepLocked(boolean allowDelay) { |
Fyodor Kupolov | 9b80b94 | 2016-06-16 16:29:05 -0700 | [diff] [blame] | 3373 | if (!mService.isSleepingOrShuttingDownLocked()) { |
Craig Mautner | 0eea92c | 2013-05-16 13:35:39 -0700 | [diff] [blame] | 3374 | // Do not care. |
| 3375 | return; |
| 3376 | } |
| 3377 | |
David Stevens | 18abd0e | 2017-08-17 14:55:47 -0700 | [diff] [blame] | 3378 | if (!putStacksToSleepLocked(allowDelay, false /* shuttingDown */)) { |
| 3379 | return; |
Craig Mautner | 0eea92c | 2013-05-16 13:35:39 -0700 | [diff] [blame] | 3380 | } |
| 3381 | |
Wei Wang | 65c7a15 | 2016-06-02 18:51:22 -0700 | [diff] [blame] | 3382 | // Send launch end powerhint before going sleep |
Bryce Lee | d3624e1 | 2017-11-30 08:51:45 -0800 | [diff] [blame] | 3383 | sendPowerHintForLaunchEndIfNeeded(); |
Wei Wang | 65c7a15 | 2016-06-02 18:51:22 -0700 | [diff] [blame] | 3384 | |
Craig Mautner | 0eea92c | 2013-05-16 13:35:39 -0700 | [diff] [blame] | 3385 | removeSleepTimeouts(); |
| 3386 | |
| 3387 | if (mGoingToSleep.isHeld()) { |
| 3388 | mGoingToSleep.release(); |
| 3389 | } |
| 3390 | if (mService.mShuttingDown) { |
| 3391 | mService.notifyAll(); |
| 3392 | } |
Craig Mautner | 8d341ef | 2013-03-26 09:03:27 -0700 | [diff] [blame] | 3393 | } |
| 3394 | |
David Stevens | 18abd0e | 2017-08-17 14:55:47 -0700 | [diff] [blame] | 3395 | // Tries to put all activity stacks to sleep. Returns true if all stacks were |
| 3396 | // successfully put to sleep. |
| 3397 | private boolean putStacksToSleepLocked(boolean allowDelay, boolean shuttingDown) { |
| 3398 | boolean allSleep = true; |
| 3399 | for (int displayNdx = mActivityDisplays.size() - 1; displayNdx >= 0; --displayNdx) { |
Wale Ogunwale | a0f5b5e | 2017-10-11 09:37:23 -0700 | [diff] [blame] | 3400 | final ActivityDisplay display = mActivityDisplays.valueAt(displayNdx); |
| 3401 | for (int stackNdx = display.getChildCount() - 1; stackNdx >= 0; --stackNdx) { |
| 3402 | final ActivityStack stack = display.getChildAt(stackNdx); |
David Stevens | 18abd0e | 2017-08-17 14:55:47 -0700 | [diff] [blame] | 3403 | if (allowDelay) { |
Wale Ogunwale | a0f5b5e | 2017-10-11 09:37:23 -0700 | [diff] [blame] | 3404 | allSleep &= stack.goToSleepIfPossible(shuttingDown); |
David Stevens | 18abd0e | 2017-08-17 14:55:47 -0700 | [diff] [blame] | 3405 | } else { |
Wale Ogunwale | a0f5b5e | 2017-10-11 09:37:23 -0700 | [diff] [blame] | 3406 | stack.goToSleep(); |
David Stevens | 18abd0e | 2017-08-17 14:55:47 -0700 | [diff] [blame] | 3407 | } |
| 3408 | } |
| 3409 | } |
| 3410 | return allSleep; |
| 3411 | } |
| 3412 | |
Craig Mautner | ce5f3cb | 2013-04-22 08:58:54 -0700 | [diff] [blame] | 3413 | boolean reportResumedActivityLocked(ActivityRecord r) { |
Bryce Lee | 29a649d | 2017-08-18 13:52:31 -0700 | [diff] [blame] | 3414 | // A resumed activity cannot be stopping. remove from list |
| 3415 | mStoppingActivities.remove(r); |
| 3416 | |
Andrii Kulian | 02b7a83 | 2016-10-06 23:11:56 -0700 | [diff] [blame] | 3417 | final ActivityStack stack = r.getStack(); |
Wale Ogunwale | 1e60e0c | 2015-10-28 13:36:10 -0700 | [diff] [blame] | 3418 | if (isFocusedStack(stack)) { |
Jeff Sharkey | 5782da7 | 2013-04-25 14:32:30 -0700 | [diff] [blame] | 3419 | mService.updateUsageStats(r, true); |
Craig Mautner | ce5f3cb | 2013-04-22 08:58:54 -0700 | [diff] [blame] | 3420 | } |
| 3421 | if (allResumedActivitiesComplete()) { |
Filip Gruszczynski | bc5a6c5 | 2015-09-22 13:13:24 -0700 | [diff] [blame] | 3422 | ensureActivitiesVisibleLocked(null, 0, !PRESERVE_WINDOWS); |
Craig Mautner | ce5f3cb | 2013-04-22 08:58:54 -0700 | [diff] [blame] | 3423 | mWindowManager.executeAppTransition(); |
| 3424 | return true; |
| 3425 | } |
| 3426 | return false; |
| 3427 | } |
| 3428 | |
Craig Mautner | 8d341ef | 2013-03-26 09:03:27 -0700 | [diff] [blame] | 3429 | void handleAppCrashLocked(ProcessRecord app) { |
Craig Mautner | e0a3884 | 2013-12-16 16:14:02 -0800 | [diff] [blame] | 3430 | for (int displayNdx = mActivityDisplays.size() - 1; displayNdx >= 0; --displayNdx) { |
Wale Ogunwale | a0f5b5e | 2017-10-11 09:37:23 -0700 | [diff] [blame] | 3431 | final ActivityDisplay display = mActivityDisplays.valueAt(displayNdx); |
| 3432 | for (int stackNdx = display.getChildCount() - 1; stackNdx >= 0; --stackNdx) { |
| 3433 | final ActivityStack stack = display.getChildAt(stackNdx); |
| 3434 | stack.handleAppCrashLocked(app); |
Craig Mautner | 4a1cb22 | 2013-12-04 16:14:06 -0800 | [diff] [blame] | 3435 | } |
Craig Mautner | 8d341ef | 2013-03-26 09:03:27 -0700 | [diff] [blame] | 3436 | } |
| 3437 | } |
| 3438 | |
Craig Mautner | bb74246 | 2014-07-07 15:28:55 -0700 | [diff] [blame] | 3439 | // Called when WindowManager has finished animating the launchingBehind activity to the back. |
Andrii Kulian | 21713ac | 2016-10-12 22:05:05 -0700 | [diff] [blame] | 3440 | private void handleLaunchTaskBehindCompleteLocked(ActivityRecord r) { |
Bryce Lee | af691c0 | 2017-03-20 14:20:22 -0700 | [diff] [blame] | 3441 | final TaskRecord task = r.getTask(); |
Andrii Kulian | 02b7a83 | 2016-10-06 23:11:56 -0700 | [diff] [blame] | 3442 | final ActivityStack stack = task.getStack(); |
Winson | 730bf06 | 2016-03-31 18:04:56 -0700 | [diff] [blame] | 3443 | |
| 3444 | r.mLaunchTaskBehind = false; |
Winson Chung | 1dbc811 | 2017-09-28 18:05:31 -0700 | [diff] [blame] | 3445 | mRecentTasks.add(task); |
Yorke Lee | bd54c2a | 2016-10-25 13:49:23 -0700 | [diff] [blame] | 3446 | mService.mTaskChangeNotificationController.notifyTaskStackChanged(); |
Wale Ogunwale | 26c0dfe | 2016-12-14 14:42:30 -0800 | [diff] [blame] | 3447 | r.setVisibility(false); |
Winson | 730bf06 | 2016-03-31 18:04:56 -0700 | [diff] [blame] | 3448 | |
| 3449 | // When launching tasks behind, update the last active time of the top task after the new |
| 3450 | // task has been shown briefly |
Wale Ogunwale | 30e441d | 2017-11-09 08:28:45 -0800 | [diff] [blame] | 3451 | final ActivityRecord top = stack.getTopActivity(); |
Winson | 730bf06 | 2016-03-31 18:04:56 -0700 | [diff] [blame] | 3452 | if (top != null) { |
Bryce Lee | af691c0 | 2017-03-20 14:20:22 -0700 | [diff] [blame] | 3453 | top.getTask().touchActiveTime(); |
Winson | 730bf06 | 2016-03-31 18:04:56 -0700 | [diff] [blame] | 3454 | } |
Craig Mautner | bb74246 | 2014-07-07 15:28:55 -0700 | [diff] [blame] | 3455 | } |
| 3456 | |
| 3457 | void scheduleLaunchTaskBehindComplete(IBinder token) { |
| 3458 | mHandler.obtainMessage(LAUNCH_TASK_BEHIND_COMPLETE, token).sendToTarget(); |
| 3459 | } |
| 3460 | |
Filip Gruszczynski | bc5a6c5 | 2015-09-22 13:13:24 -0700 | [diff] [blame] | 3461 | void ensureActivitiesVisibleLocked(ActivityRecord starting, int configChanges, |
| 3462 | boolean preserveWindows) { |
Jorim Jaggi | fe76234 | 2016-10-13 14:33:27 +0200 | [diff] [blame] | 3463 | mKeyguardController.beginActivityVisibilityUpdate(); |
| 3464 | try { |
| 3465 | // First the front stacks. In case any are not fullscreen and are in front of home. |
| 3466 | for (int displayNdx = mActivityDisplays.size() - 1; displayNdx >= 0; --displayNdx) { |
Wale Ogunwale | a0f5b5e | 2017-10-11 09:37:23 -0700 | [diff] [blame] | 3467 | final ActivityDisplay display = mActivityDisplays.valueAt(displayNdx); |
| 3468 | for (int stackNdx = display.getChildCount() - 1; stackNdx >= 0; --stackNdx) { |
| 3469 | final ActivityStack stack = display.getChildAt(stackNdx); |
Jorim Jaggi | fe76234 | 2016-10-13 14:33:27 +0200 | [diff] [blame] | 3470 | stack.ensureActivitiesVisibleLocked(starting, configChanges, preserveWindows); |
| 3471 | } |
Craig Mautner | 580ea81 | 2013-04-25 12:58:38 -0700 | [diff] [blame] | 3472 | } |
Jorim Jaggi | fe76234 | 2016-10-13 14:33:27 +0200 | [diff] [blame] | 3473 | } finally { |
| 3474 | mKeyguardController.endActivityVisibilityUpdate(); |
Craig Mautner | 8d341ef | 2013-03-26 09:03:27 -0700 | [diff] [blame] | 3475 | } |
Craig Mautner | 8d341ef | 2013-03-26 09:03:27 -0700 | [diff] [blame] | 3476 | } |
| 3477 | |
Jorim Jaggi | 8b702ed | 2017-01-20 16:59:03 +0100 | [diff] [blame] | 3478 | void addStartingWindowsForVisibleActivities(boolean taskSwitch) { |
| 3479 | for (int displayNdx = mActivityDisplays.size() - 1; displayNdx >= 0; --displayNdx) { |
Wale Ogunwale | a0f5b5e | 2017-10-11 09:37:23 -0700 | [diff] [blame] | 3480 | final ActivityDisplay display = mActivityDisplays.valueAt(displayNdx); |
| 3481 | for (int stackNdx = display.getChildCount() - 1; stackNdx >= 0; --stackNdx) { |
| 3482 | final ActivityStack stack = display.getChildAt(stackNdx); |
Jorim Jaggi | 8b702ed | 2017-01-20 16:59:03 +0100 | [diff] [blame] | 3483 | stack.addStartingWindowsForVisibleActivities(taskSwitch); |
| 3484 | } |
| 3485 | } |
| 3486 | } |
| 3487 | |
Chong Zhang | fdcc4d4 | 2015-10-14 16:50:12 -0700 | [diff] [blame] | 3488 | void invalidateTaskLayers() { |
| 3489 | mTaskLayersChanged = true; |
| 3490 | } |
| 3491 | |
| 3492 | void rankTaskLayersIfNeeded() { |
| 3493 | if (!mTaskLayersChanged) { |
| 3494 | return; |
| 3495 | } |
| 3496 | mTaskLayersChanged = false; |
| 3497 | for (int displayNdx = 0; displayNdx < mActivityDisplays.size(); displayNdx++) { |
Wale Ogunwale | a0f5b5e | 2017-10-11 09:37:23 -0700 | [diff] [blame] | 3498 | final ActivityDisplay display = mActivityDisplays.valueAt(displayNdx); |
Chong Zhang | fdcc4d4 | 2015-10-14 16:50:12 -0700 | [diff] [blame] | 3499 | int baseLayer = 0; |
Wale Ogunwale | a0f5b5e | 2017-10-11 09:37:23 -0700 | [diff] [blame] | 3500 | for (int stackNdx = display.getChildCount() - 1; stackNdx >= 0; --stackNdx) { |
| 3501 | final ActivityStack stack = display.getChildAt(stackNdx); |
| 3502 | baseLayer += stack.rankTaskLayers(baseLayer); |
Chong Zhang | fdcc4d4 | 2015-10-14 16:50:12 -0700 | [diff] [blame] | 3503 | } |
| 3504 | } |
| 3505 | } |
| 3506 | |
Dianne Hackborn | b5a380d | 2015-05-20 18:18:46 -0700 | [diff] [blame] | 3507 | void clearOtherAppTimeTrackers(AppTimeTracker except) { |
| 3508 | for (int displayNdx = mActivityDisplays.size() - 1; displayNdx >= 0; --displayNdx) { |
Wale Ogunwale | a0f5b5e | 2017-10-11 09:37:23 -0700 | [diff] [blame] | 3509 | final ActivityDisplay display = mActivityDisplays.valueAt(displayNdx); |
| 3510 | for (int stackNdx = display.getChildCount() - 1; stackNdx >= 0; --stackNdx) { |
| 3511 | final ActivityStack stack = display.getChildAt(stackNdx); |
Dianne Hackborn | b5a380d | 2015-05-20 18:18:46 -0700 | [diff] [blame] | 3512 | stack.clearOtherAppTimeTrackers(except); |
| 3513 | } |
| 3514 | } |
| 3515 | } |
| 3516 | |
Craig Mautner | 8d341ef | 2013-03-26 09:03:27 -0700 | [diff] [blame] | 3517 | void scheduleDestroyAllActivities(ProcessRecord app, String reason) { |
Craig Mautner | e0a3884 | 2013-12-16 16:14:02 -0800 | [diff] [blame] | 3518 | for (int displayNdx = mActivityDisplays.size() - 1; displayNdx >= 0; --displayNdx) { |
Wale Ogunwale | a0f5b5e | 2017-10-11 09:37:23 -0700 | [diff] [blame] | 3519 | final ActivityDisplay display = mActivityDisplays.valueAt(displayNdx); |
| 3520 | for (int stackNdx = display.getChildCount() - 1; stackNdx >= 0; --stackNdx) { |
| 3521 | final ActivityStack stack = display.getChildAt(stackNdx); |
Craig Mautner | ee2e45a | 2014-06-27 12:10:03 -0700 | [diff] [blame] | 3522 | stack.scheduleDestroyActivities(app, reason); |
Craig Mautner | 4a1cb22 | 2013-12-04 16:14:06 -0800 | [diff] [blame] | 3523 | } |
Craig Mautner | 8d341ef | 2013-03-26 09:03:27 -0700 | [diff] [blame] | 3524 | } |
| 3525 | } |
| 3526 | |
Dianne Hackborn | 89ad456 | 2014-08-24 16:45:38 -0700 | [diff] [blame] | 3527 | void releaseSomeActivitiesLocked(ProcessRecord app, String reason) { |
| 3528 | // Examine all activities currently running in the process. |
| 3529 | TaskRecord firstTask = null; |
| 3530 | // Tasks is non-null only if two or more tasks are found. |
| 3531 | ArraySet<TaskRecord> tasks = null; |
Wale Ogunwale | 0fc365c | 2015-05-25 19:35:42 -0700 | [diff] [blame] | 3532 | if (DEBUG_RELEASE) Slog.d(TAG_RELEASE, "Trying to release some activities in " + app); |
| 3533 | for (int i = 0; i < app.activities.size(); i++) { |
Dianne Hackborn | 89ad456 | 2014-08-24 16:45:38 -0700 | [diff] [blame] | 3534 | ActivityRecord r = app.activities.get(i); |
| 3535 | // First, if we find an activity that is in the process of being destroyed, |
| 3536 | // then we just aren't going to do anything for now; we want things to settle |
| 3537 | // down before we try to prune more activities. |
Wale Ogunwale | ee006da | 2015-03-30 14:49:25 -0700 | [diff] [blame] | 3538 | if (r.finishing || r.state == DESTROYING || r.state == DESTROYED) { |
Wale Ogunwale | 0fc365c | 2015-05-25 19:35:42 -0700 | [diff] [blame] | 3539 | if (DEBUG_RELEASE) Slog.d(TAG_RELEASE, "Abort release; already destroying: " + r); |
Dianne Hackborn | 89ad456 | 2014-08-24 16:45:38 -0700 | [diff] [blame] | 3540 | return; |
| 3541 | } |
| 3542 | // Don't consider any activies that are currently not in a state where they |
| 3543 | // can be destroyed. |
Wale Ogunwale | ee006da | 2015-03-30 14:49:25 -0700 | [diff] [blame] | 3544 | if (r.visible || !r.stopped || !r.haveState || r.state == RESUMED || r.state == PAUSING |
| 3545 | || r.state == PAUSED || r.state == STOPPING) { |
Wale Ogunwale | 0fc365c | 2015-05-25 19:35:42 -0700 | [diff] [blame] | 3546 | if (DEBUG_RELEASE) Slog.d(TAG_RELEASE, "Not releasing in-use activity: " + r); |
Dianne Hackborn | 89ad456 | 2014-08-24 16:45:38 -0700 | [diff] [blame] | 3547 | continue; |
| 3548 | } |
Bryce Lee | af691c0 | 2017-03-20 14:20:22 -0700 | [diff] [blame] | 3549 | |
| 3550 | final TaskRecord task = r.getTask(); |
| 3551 | if (task != null) { |
| 3552 | if (DEBUG_RELEASE) Slog.d(TAG_RELEASE, "Collecting release task " + task |
Dianne Hackborn | 89ad456 | 2014-08-24 16:45:38 -0700 | [diff] [blame] | 3553 | + " from " + r); |
| 3554 | if (firstTask == null) { |
Bryce Lee | af691c0 | 2017-03-20 14:20:22 -0700 | [diff] [blame] | 3555 | firstTask = task; |
| 3556 | } else if (firstTask != task) { |
Dianne Hackborn | 89ad456 | 2014-08-24 16:45:38 -0700 | [diff] [blame] | 3557 | if (tasks == null) { |
| 3558 | tasks = new ArraySet<>(); |
| 3559 | tasks.add(firstTask); |
| 3560 | } |
Bryce Lee | af691c0 | 2017-03-20 14:20:22 -0700 | [diff] [blame] | 3561 | tasks.add(task); |
Dianne Hackborn | 89ad456 | 2014-08-24 16:45:38 -0700 | [diff] [blame] | 3562 | } |
| 3563 | } |
| 3564 | } |
| 3565 | if (tasks == null) { |
Wale Ogunwale | 0fc365c | 2015-05-25 19:35:42 -0700 | [diff] [blame] | 3566 | 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] | 3567 | return; |
| 3568 | } |
| 3569 | // If we have activities in multiple tasks that are in a position to be destroyed, |
| 3570 | // let's iterate through the tasks and release the oldest one. |
| 3571 | final int numDisplays = mActivityDisplays.size(); |
| 3572 | for (int displayNdx = 0; displayNdx < numDisplays; ++displayNdx) { |
Wale Ogunwale | a0f5b5e | 2017-10-11 09:37:23 -0700 | [diff] [blame] | 3573 | final ActivityDisplay display = mActivityDisplays.valueAt(displayNdx); |
| 3574 | final int stackCount = display.getChildCount(); |
Dianne Hackborn | 89ad456 | 2014-08-24 16:45:38 -0700 | [diff] [blame] | 3575 | // 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] | 3576 | for (int stackNdx = 0; stackNdx < stackCount; stackNdx++) { |
| 3577 | final ActivityStack stack = display.getChildAt(stackNdx); |
Dianne Hackborn | 89ad456 | 2014-08-24 16:45:38 -0700 | [diff] [blame] | 3578 | // Try to release activities in this stack; if we manage to, we are done. |
| 3579 | if (stack.releaseSomeActivitiesLocked(app, tasks, reason) > 0) { |
| 3580 | return; |
| 3581 | } |
| 3582 | } |
| 3583 | } |
| 3584 | } |
| 3585 | |
Amith Yamasani | 37a40c2 | 2015-06-17 13:25:42 -0700 | [diff] [blame] | 3586 | boolean switchUserLocked(int userId, UserState uss) { |
Wale Ogunwale | 9a98c52 | 2016-04-27 09:23:55 -0700 | [diff] [blame] | 3587 | final int focusStackId = mFocusedStack.getStackId(); |
| 3588 | // We dismiss the docked stack whenever we switch users. |
Wale Ogunwale | a0f5b5e | 2017-10-11 09:37:23 -0700 | [diff] [blame] | 3589 | final ActivityStack dockedStack = getDefaultDisplay().getSplitScreenPrimaryStack(); |
Wale Ogunwale | 9dcf946 | 2017-09-19 15:13:01 -0700 | [diff] [blame] | 3590 | if (dockedStack != null) { |
| 3591 | moveTasksToFullscreenStackLocked(dockedStack, mFocusedStack == dockedStack); |
| 3592 | } |
Winson Chung | c2b23a5 | 2017-01-09 15:44:55 -0800 | [diff] [blame] | 3593 | // Also dismiss the pinned stack whenever we switch users. Removing the pinned stack will |
| 3594 | // also cause all tasks to be moved to the fullscreen stack at a position that is |
| 3595 | // appropriate. |
Wale Ogunwale | 44f036f | 2017-09-29 05:09:09 -0700 | [diff] [blame] | 3596 | removeStacksInWindowingModes(WINDOWING_MODE_PINNED); |
Wale Ogunwale | 9a98c52 | 2016-04-27 09:23:55 -0700 | [diff] [blame] | 3597 | |
| 3598 | mUserStackInFront.put(mCurrentUser, focusStackId); |
Wale Ogunwale | 6827856 | 2017-09-23 17:13:55 -0700 | [diff] [blame] | 3599 | final int restoreStackId = mUserStackInFront.get(userId, mHomeStack.mStackId); |
Craig Mautner | 2420ead | 2013-04-01 17:13:20 -0700 | [diff] [blame] | 3600 | mCurrentUser = userId; |
Craig Mautner | ac6f843 | 2013-07-17 13:24:59 -0700 | [diff] [blame] | 3601 | |
Craig Mautner | 858d8a6 | 2013-04-23 17:08:34 -0700 | [diff] [blame] | 3602 | mStartingUsers.add(uss); |
Craig Mautner | e0a3884 | 2013-12-16 16:14:02 -0800 | [diff] [blame] | 3603 | for (int displayNdx = mActivityDisplays.size() - 1; displayNdx >= 0; --displayNdx) { |
Wale Ogunwale | a0f5b5e | 2017-10-11 09:37:23 -0700 | [diff] [blame] | 3604 | final ActivityDisplay display = mActivityDisplays.valueAt(displayNdx); |
| 3605 | for (int stackNdx = display.getChildCount() - 1; stackNdx >= 0; --stackNdx) { |
| 3606 | final ActivityStack stack = display.getChildAt(stackNdx); |
Craig Mautner | e0a3884 | 2013-12-16 16:14:02 -0800 | [diff] [blame] | 3607 | stack.switchUserLocked(userId); |
Alexandra Gherghina | dae57a1 | 2014-03-12 19:15:26 +0000 | [diff] [blame] | 3608 | TaskRecord task = stack.topTask(); |
| 3609 | if (task != null) { |
Wale Ogunwale | 1666e31 | 2016-12-16 11:27:18 -0800 | [diff] [blame] | 3610 | stack.positionChildWindowContainerAtTop(task); |
Alexandra Gherghina | dae57a1 | 2014-03-12 19:15:26 +0000 | [diff] [blame] | 3611 | } |
Craig Mautner | 4a1cb22 | 2013-12-04 16:14:06 -0800 | [diff] [blame] | 3612 | } |
Craig Mautner | ac6f843 | 2013-07-17 13:24:59 -0700 | [diff] [blame] | 3613 | } |
Craig Mautner | 858d8a6 | 2013-04-23 17:08:34 -0700 | [diff] [blame] | 3614 | |
Craig Mautner | 4f1df4f | 2013-10-15 15:44:14 -0700 | [diff] [blame] | 3615 | ActivityStack stack = getStack(restoreStackId); |
| 3616 | if (stack == null) { |
| 3617 | stack = mHomeStack; |
| 3618 | } |
Wale Ogunwale | 6fbde9f | 2017-08-24 07:24:12 -0700 | [diff] [blame] | 3619 | final boolean homeInFront = stack.isActivityTypeHome(); |
Craig Mautner | e0a3884 | 2013-12-16 16:14:02 -0800 | [diff] [blame] | 3620 | if (stack.isOnHomeDisplay()) { |
Wale Ogunwale | 925d0d1 | 2015-09-23 15:40:07 -0700 | [diff] [blame] | 3621 | stack.moveToFront("switchUserOnHomeDisplay"); |
Craig Mautner | e0a3884 | 2013-12-16 16:14:02 -0800 | [diff] [blame] | 3622 | } else { |
| 3623 | // Stack was moved to another display while user was swapped out. |
Matthew Ng | ae1ff4f | 2016-11-10 15:49:14 -0800 | [diff] [blame] | 3624 | resumeHomeStackTask(null, "switchUserOnOtherDisplay"); |
Craig Mautner | e0a3884 | 2013-12-16 16:14:02 -0800 | [diff] [blame] | 3625 | } |
Craig Mautner | 93529a4 | 2013-10-04 15:03:13 -0700 | [diff] [blame] | 3626 | return homeInFront; |
Craig Mautner | 2219a1b | 2013-03-25 09:44:30 -0700 | [diff] [blame] | 3627 | } |
| 3628 | |
Wale Ogunwale | 0bd2aa7 | 2015-04-16 13:50:44 -0700 | [diff] [blame] | 3629 | /** Checks whether the userid is a profile of the current user. */ |
| 3630 | boolean isCurrentProfileLocked(int userId) { |
| 3631 | if (userId == mCurrentUser) return true; |
Fyodor Kupolov | 1b3edac | 2017-09-19 15:48:06 -0700 | [diff] [blame] | 3632 | return mService.mUserController.isCurrentProfile(userId); |
Wale Ogunwale | 0bd2aa7 | 2015-04-16 13:50:44 -0700 | [diff] [blame] | 3633 | } |
| 3634 | |
Bryce Lee | b7c9b80 | 2017-05-02 14:20:24 -0700 | [diff] [blame] | 3635 | /** |
| 3636 | * Returns whether a stopping activity is present that should be stopped after visible, rather |
| 3637 | * than idle. |
| 3638 | * @return {@code true} if such activity is present. {@code false} otherwise. |
| 3639 | */ |
| 3640 | boolean isStoppingNoHistoryActivity() { |
| 3641 | // Activities that are marked as nohistory should be stopped immediately after the resumed |
| 3642 | // activity has become visible. |
| 3643 | for (ActivityRecord record : mStoppingActivities) { |
| 3644 | if (record.isNoHistory()) { |
| 3645 | return true; |
| 3646 | } |
| 3647 | } |
| 3648 | |
| 3649 | return false; |
| 3650 | } |
| 3651 | |
Winson Chung | 4dabf23 | 2017-01-25 13:25:22 -0800 | [diff] [blame] | 3652 | final ArrayList<ActivityRecord> processStoppingActivitiesLocked(ActivityRecord idleActivity, |
| 3653 | boolean remove, boolean processPausingActivities) { |
Craig Mautner | de4ef02 | 2013-04-07 19:01:33 -0700 | [diff] [blame] | 3654 | ArrayList<ActivityRecord> stops = null; |
| 3655 | |
| 3656 | final boolean nowVisible = allResumedActivitiesVisible(); |
Craig Mautner | 8c14c15 | 2015-01-15 17:32:07 -0800 | [diff] [blame] | 3657 | for (int activityNdx = mStoppingActivities.size() - 1; activityNdx >= 0; --activityNdx) { |
| 3658 | ActivityRecord s = mStoppingActivities.get(activityNdx); |
Bryce Lee | 4a19438 | 2017-04-04 14:32:48 -0700 | [diff] [blame] | 3659 | boolean waitingVisible = mActivitiesWaitingForVisibleActivity.contains(s); |
Wale Ogunwale | f81c1d1 | 2016-01-12 12:20:18 -0800 | [diff] [blame] | 3660 | if (DEBUG_STATES) Slog.v(TAG, "Stopping " + s + ": nowVisible=" + nowVisible |
Craig Mautner | 8c14c15 | 2015-01-15 17:32:07 -0800 | [diff] [blame] | 3661 | + " waitingVisible=" + waitingVisible + " finishing=" + s.finishing); |
| 3662 | if (waitingVisible && nowVisible) { |
Bryce Lee | 4a19438 | 2017-04-04 14:32:48 -0700 | [diff] [blame] | 3663 | mActivitiesWaitingForVisibleActivity.remove(s); |
Andrii Kulian | ee05681 | 2016-09-21 15:34:45 -0700 | [diff] [blame] | 3664 | waitingVisible = false; |
Craig Mautner | de4ef02 | 2013-04-07 19:01:33 -0700 | [diff] [blame] | 3665 | if (s.finishing) { |
| 3666 | // If this activity is finishing, it is sitting on top of |
| 3667 | // everyone else but we now know it is no longer needed... |
| 3668 | // so get rid of it. Otherwise, we need to go through the |
| 3669 | // normal flow and hide it once we determine that it is |
| 3670 | // hidden by the activities in front of it. |
Wale Ogunwale | f81c1d1 | 2016-01-12 12:20:18 -0800 | [diff] [blame] | 3671 | if (DEBUG_STATES) Slog.v(TAG, "Before stopping, can hide: " + s); |
Wale Ogunwale | 26c0dfe | 2016-12-14 14:42:30 -0800 | [diff] [blame] | 3672 | s.setVisibility(false); |
Craig Mautner | de4ef02 | 2013-04-07 19:01:33 -0700 | [diff] [blame] | 3673 | } |
| 3674 | } |
David Stevens | 9440dc8 | 2017-03-16 19:00:20 -0700 | [diff] [blame] | 3675 | if (remove) { |
| 3676 | final ActivityStack stack = s.getStack(); |
| 3677 | final boolean shouldSleepOrShutDown = stack != null |
| 3678 | ? stack.shouldSleepOrShutDownActivities() |
| 3679 | : mService.isSleepingOrShuttingDownLocked(); |
| 3680 | if (!waitingVisible || shouldSleepOrShutDown) { |
| 3681 | if (!processPausingActivities && s.state == PAUSING) { |
| 3682 | // Defer processing pausing activities in this iteration and reschedule |
| 3683 | // a delayed idle to reprocess it again |
| 3684 | removeTimeoutsForActivityLocked(idleActivity); |
| 3685 | scheduleIdleTimeoutLocked(idleActivity); |
| 3686 | continue; |
| 3687 | } |
Winson Chung | 4dabf23 | 2017-01-25 13:25:22 -0800 | [diff] [blame] | 3688 | |
David Stevens | 9440dc8 | 2017-03-16 19:00:20 -0700 | [diff] [blame] | 3689 | if (DEBUG_STATES) Slog.v(TAG, "Ready to stop: " + s); |
| 3690 | if (stops == null) { |
| 3691 | stops = new ArrayList<>(); |
| 3692 | } |
| 3693 | stops.add(s); |
| 3694 | mStoppingActivities.remove(activityNdx); |
Craig Mautner | de4ef02 | 2013-04-07 19:01:33 -0700 | [diff] [blame] | 3695 | } |
Craig Mautner | de4ef02 | 2013-04-07 19:01:33 -0700 | [diff] [blame] | 3696 | } |
| 3697 | } |
| 3698 | |
| 3699 | return stops; |
| 3700 | } |
| 3701 | |
Craig Mautner | cf910b0 | 2013-04-23 11:23:27 -0700 | [diff] [blame] | 3702 | void validateTopActivitiesLocked() { |
Wale Ogunwale | ee006da | 2015-03-30 14:49:25 -0700 | [diff] [blame] | 3703 | for (int displayNdx = mActivityDisplays.size() - 1; displayNdx >= 0; --displayNdx) { |
Wale Ogunwale | a0f5b5e | 2017-10-11 09:37:23 -0700 | [diff] [blame] | 3704 | final ActivityDisplay display = mActivityDisplays.valueAt(displayNdx); |
| 3705 | for (int stackNdx = display.getChildCount() - 1; stackNdx >= 0; --stackNdx) { |
| 3706 | final ActivityStack stack = display.getChildAt(stackNdx); |
Filip Gruszczynski | 3e85ba2 | 2015-10-05 22:48:30 -0700 | [diff] [blame] | 3707 | final ActivityRecord r = stack.topRunningActivityLocked(); |
Wale Ogunwale | ee006da | 2015-03-30 14:49:25 -0700 | [diff] [blame] | 3708 | final ActivityState state = r == null ? DESTROYED : r.state; |
Wale Ogunwale | 1e60e0c | 2015-10-28 13:36:10 -0700 | [diff] [blame] | 3709 | if (isFocusedStack(stack)) { |
Wale Ogunwale | ee006da | 2015-03-30 14:49:25 -0700 | [diff] [blame] | 3710 | if (r == null) Slog.e(TAG, |
| 3711 | "validateTop...: null top activity, stack=" + stack); |
| 3712 | else { |
| 3713 | final ActivityRecord pausing = stack.mPausingActivity; |
| 3714 | if (pausing != null && pausing == r) Slog.e(TAG, |
| 3715 | "validateTop...: top stack has pausing activity r=" + r |
| 3716 | + " state=" + state); |
| 3717 | if (state != INITIALIZING && state != RESUMED) Slog.e(TAG, |
| 3718 | "validateTop...: activity in front not resumed r=" + r |
| 3719 | + " state=" + state); |
| 3720 | } |
Craig Mautner | cf910b0 | 2013-04-23 11:23:27 -0700 | [diff] [blame] | 3721 | } else { |
Wale Ogunwale | ee006da | 2015-03-30 14:49:25 -0700 | [diff] [blame] | 3722 | final ActivityRecord resumed = stack.mResumedActivity; |
| 3723 | if (resumed != null && resumed == r) Slog.e(TAG, |
| 3724 | "validateTop...: back stack has resumed activity r=" + r |
| 3725 | + " state=" + state); |
| 3726 | if (r != null && (state == INITIALIZING || state == RESUMED)) Slog.e(TAG, |
| 3727 | "validateTop...: activity in back resumed r=" + r + " state=" + state); |
Craig Mautner | cf910b0 | 2013-04-23 11:23:27 -0700 | [diff] [blame] | 3728 | } |
| 3729 | } |
| 3730 | } |
Craig Mautner | 76ea224 | 2013-05-15 11:40:05 -0700 | [diff] [blame] | 3731 | } |
| 3732 | |
Bryce Lee | 77a7dd6 | 2018-01-22 15:47:09 -0800 | [diff] [blame] | 3733 | public void dumpDisplays(PrintWriter pw) { |
| 3734 | for (int i = mActivityDisplays.size() - 1; i >= 0; --i) { |
| 3735 | final ActivityDisplay display = mActivityDisplays.valueAt(i); |
| 3736 | pw.print("[id:" + display.mDisplayId + " stacks:"); |
| 3737 | display.dumpStacks(pw); |
| 3738 | pw.print("]"); |
| 3739 | } |
| 3740 | } |
| 3741 | |
Craig Mautner | 2708430 | 2013-03-25 08:05:25 -0700 | [diff] [blame] | 3742 | public void dump(PrintWriter pw, String prefix) { |
Craig Mautner | d1bbdb462 | 2013-10-22 09:53:20 -0700 | [diff] [blame] | 3743 | pw.print(prefix); pw.print("mFocusedStack=" + mFocusedStack); |
Craig Mautner | 4a1cb22 | 2013-12-04 16:14:06 -0800 | [diff] [blame] | 3744 | pw.print(" mLastFocusedStack="); pw.println(mLastFocusedStack); |
Suprabh Shukla | 09a88f5 | 2015-12-02 14:36:31 -0800 | [diff] [blame] | 3745 | pw.print(prefix); |
| 3746 | pw.println("mCurTaskIdForUser=" + mCurTaskIdForUser); |
Craig Mautner | d1bbdb462 | 2013-10-22 09:53:20 -0700 | [diff] [blame] | 3747 | pw.print(prefix); pw.println("mUserStackInFront=" + mUserStackInFront); |
Wale Ogunwale | 9dcf946 | 2017-09-19 15:13:01 -0700 | [diff] [blame] | 3748 | for (int i = mActivityDisplays.size() - 1; i >= 0; --i) { |
| 3749 | final ActivityDisplay display = mActivityDisplays.valueAt(i); |
Wale Ogunwale | a0f5b5e | 2017-10-11 09:37:23 -0700 | [diff] [blame] | 3750 | display.dump(pw, prefix); |
Wale Ogunwale | 9dcf946 | 2017-09-19 15:13:01 -0700 | [diff] [blame] | 3751 | } |
Bryce Lee | 4a19438 | 2017-04-04 14:32:48 -0700 | [diff] [blame] | 3752 | if (!mWaitingForActivityVisible.isEmpty()) { |
| 3753 | pw.print(prefix); pw.println("mWaitingForActivityVisible="); |
| 3754 | for (int i = 0; i < mWaitingForActivityVisible.size(); ++i) { |
| 3755 | pw.print(prefix); pw.print(prefix); mWaitingForActivityVisible.get(i).dump(pw, prefix); |
| 3756 | } |
| 3757 | } |
| 3758 | |
Jorim Jaggi | 8d78693 | 2016-10-26 19:08:36 -0700 | [diff] [blame] | 3759 | mKeyguardController.dump(pw, prefix); |
Benjamin Franz | a83859f | 2017-07-03 16:34:14 +0100 | [diff] [blame] | 3760 | mService.mLockTaskController.dump(pw, prefix); |
Craig Mautner | 2708430 | 2013-03-25 08:05:25 -0700 | [diff] [blame] | 3761 | } |
Craig Mautner | 8d341ef | 2013-03-26 09:03:27 -0700 | [diff] [blame] | 3762 | |
Yi Jin | 129fc6c | 2017-09-28 15:48:38 -0700 | [diff] [blame] | 3763 | public void writeToProto(ProtoOutputStream proto) { |
Adrian Roos | 4921ccf | 2017-09-28 16:54:06 +0200 | [diff] [blame] | 3764 | super.writeToProto(proto, CONFIGURATION_CONTAINER, false /* trim */); |
Steven Timotius | 4346f0a | 2017-09-12 11:07:21 -0700 | [diff] [blame] | 3765 | for (int displayNdx = 0; displayNdx < mActivityDisplays.size(); ++displayNdx) { |
| 3766 | ActivityDisplay activityDisplay = mActivityDisplays.valueAt(displayNdx); |
| 3767 | activityDisplay.writeToProto(proto, DISPLAYS); |
| 3768 | } |
| 3769 | mKeyguardController.writeToProto(proto, KEYGUARD_CONTROLLER); |
| 3770 | if (mFocusedStack != null) { |
| 3771 | proto.write(FOCUSED_STACK_ID, mFocusedStack.mStackId); |
| 3772 | ActivityRecord focusedActivity = getResumedActivityLocked(); |
| 3773 | if (focusedActivity != null) { |
| 3774 | focusedActivity.writeIdentifierToProto(proto, RESUMED_ACTIVITY); |
| 3775 | } |
| 3776 | } else { |
| 3777 | proto.write(FOCUSED_STACK_ID, INVALID_STACK_ID); |
| 3778 | } |
Steven Timotius | 4346f0a | 2017-09-12 11:07:21 -0700 | [diff] [blame] | 3779 | } |
| 3780 | |
Winson | 43d1f26 | 2016-06-14 16:05:55 -0700 | [diff] [blame] | 3781 | /** |
Andrii Kulian | 5406e7a | 2016-10-21 11:55:23 -0700 | [diff] [blame] | 3782 | * Dump all connected displays' configurations. |
| 3783 | * @param prefix Prefix to apply to each line of the dump. |
| 3784 | */ |
| 3785 | void dumpDisplayConfigs(PrintWriter pw, String prefix) { |
| 3786 | pw.print(prefix); pw.println("Display override configurations:"); |
| 3787 | final int displayCount = mActivityDisplays.size(); |
| 3788 | for (int i = 0; i < displayCount; i++) { |
| 3789 | final ActivityDisplay activityDisplay = mActivityDisplays.valueAt(i); |
| 3790 | pw.print(prefix); pw.print(" "); pw.print(activityDisplay.mDisplayId); pw.print(": "); |
| 3791 | pw.println(activityDisplay.getOverrideConfiguration()); |
| 3792 | } |
| 3793 | } |
| 3794 | |
| 3795 | /** |
Winson | 43d1f26 | 2016-06-14 16:05:55 -0700 | [diff] [blame] | 3796 | * Dumps the activities matching the given {@param name} in the either the focused stack |
| 3797 | * or all visible stacks if {@param dumpVisibleStacks} is true. |
| 3798 | */ |
Winson Chung | 6998bc4 | 2017-02-28 17:07:05 -0800 | [diff] [blame] | 3799 | ArrayList<ActivityRecord> getDumpActivitiesLocked(String name, boolean dumpVisibleStacksOnly, |
| 3800 | boolean dumpFocusedStackOnly) { |
| 3801 | if (dumpFocusedStackOnly) { |
| 3802 | return mFocusedStack.getDumpActivitiesLocked(name); |
| 3803 | } else { |
Winson | 43d1f26 | 2016-06-14 16:05:55 -0700 | [diff] [blame] | 3804 | ArrayList<ActivityRecord> activities = new ArrayList<>(); |
| 3805 | int numDisplays = mActivityDisplays.size(); |
| 3806 | for (int displayNdx = 0; displayNdx < numDisplays; ++displayNdx) { |
Wale Ogunwale | a0f5b5e | 2017-10-11 09:37:23 -0700 | [diff] [blame] | 3807 | final ActivityDisplay display = mActivityDisplays.valueAt(displayNdx); |
| 3808 | for (int stackNdx = display.getChildCount() - 1; stackNdx >= 0; --stackNdx) { |
| 3809 | final ActivityStack stack = display.getChildAt(stackNdx); |
Wale Ogunwale | 9dcf946 | 2017-09-19 15:13:01 -0700 | [diff] [blame] | 3810 | if (!dumpVisibleStacksOnly || stack.shouldBeVisible(null)) { |
Winson | 43d1f26 | 2016-06-14 16:05:55 -0700 | [diff] [blame] | 3811 | activities.addAll(stack.getDumpActivitiesLocked(name)); |
| 3812 | } |
| 3813 | } |
| 3814 | } |
| 3815 | return activities; |
Winson | 43d1f26 | 2016-06-14 16:05:55 -0700 | [diff] [blame] | 3816 | } |
Craig Mautner | 20e7227 | 2013-04-01 13:45:53 -0700 | [diff] [blame] | 3817 | } |
| 3818 | |
Dianne Hackborn | 390517b | 2013-05-30 15:03:32 -0700 | [diff] [blame] | 3819 | static boolean printThisActivity(PrintWriter pw, ActivityRecord activity, String dumpPackage, |
| 3820 | boolean needSep, String prefix) { |
| 3821 | if (activity != null) { |
| 3822 | if (dumpPackage == null || dumpPackage.equals(activity.packageName)) { |
| 3823 | if (needSep) { |
| 3824 | pw.println(); |
Dianne Hackborn | 390517b | 2013-05-30 15:03:32 -0700 | [diff] [blame] | 3825 | } |
| 3826 | pw.print(prefix); |
| 3827 | pw.println(activity); |
Dianne Hackborn | 7ad34e5 | 2013-06-05 18:41:45 -0700 | [diff] [blame] | 3828 | return true; |
Dianne Hackborn | 390517b | 2013-05-30 15:03:32 -0700 | [diff] [blame] | 3829 | } |
| 3830 | } |
Dianne Hackborn | 7ad34e5 | 2013-06-05 18:41:45 -0700 | [diff] [blame] | 3831 | return false; |
Dianne Hackborn | 390517b | 2013-05-30 15:03:32 -0700 | [diff] [blame] | 3832 | } |
| 3833 | |
Craig Mautner | 8d341ef | 2013-03-26 09:03:27 -0700 | [diff] [blame] | 3834 | boolean dumpActivitiesLocked(FileDescriptor fd, PrintWriter pw, boolean dumpAll, |
| 3835 | boolean dumpClient, String dumpPackage) { |
Dianne Hackborn | 7ad34e5 | 2013-06-05 18:41:45 -0700 | [diff] [blame] | 3836 | boolean printed = false; |
| 3837 | boolean needSep = false; |
Craig Mautner | e0a3884 | 2013-12-16 16:14:02 -0800 | [diff] [blame] | 3838 | for (int displayNdx = 0; displayNdx < mActivityDisplays.size(); ++displayNdx) { |
| 3839 | ActivityDisplay activityDisplay = mActivityDisplays.valueAt(displayNdx); |
Craig Mautner | ee2e45a | 2014-06-27 12:10:03 -0700 | [diff] [blame] | 3840 | pw.print("Display #"); pw.print(activityDisplay.mDisplayId); |
Craig Mautner | 737fae2 | 2014-10-15 12:52:10 -0700 | [diff] [blame] | 3841 | pw.println(" (activities from top to bottom):"); |
Wale Ogunwale | a0f5b5e | 2017-10-11 09:37:23 -0700 | [diff] [blame] | 3842 | final ActivityDisplay display = mActivityDisplays.valueAt(displayNdx); |
| 3843 | for (int stackNdx = display.getChildCount() - 1; stackNdx >= 0; --stackNdx) { |
| 3844 | final ActivityStack stack = display.getChildAt(stackNdx); |
Wale Ogunwale | 34a5b57 | 2017-08-31 08:29:41 -0700 | [diff] [blame] | 3845 | pw.println(); |
Wale Ogunwale | 44f036f | 2017-09-29 05:09:09 -0700 | [diff] [blame] | 3846 | pw.println(" Stack #" + stack.mStackId |
Wale Ogunwale | 6191149 | 2017-10-11 08:50:50 -0700 | [diff] [blame] | 3847 | + ": type=" + activityTypeToString(stack.getActivityType()) |
| 3848 | + " mode=" + windowingModeToString(stack.getWindowingMode())); |
Wale Ogunwale | 34a5b57 | 2017-08-31 08:29:41 -0700 | [diff] [blame] | 3849 | pw.println(" isSleeping=" + stack.shouldSleepActivities()); |
Bryce Lee | f3c6a47 | 2017-11-14 14:53:06 -0800 | [diff] [blame] | 3850 | pw.println(" mBounds=" + stack.getOverrideBounds()); |
Winson Chung | abb433b | 2017-03-24 09:35:42 -0700 | [diff] [blame] | 3851 | |
Wale Ogunwale | 34a5b57 | 2017-08-31 08:29:41 -0700 | [diff] [blame] | 3852 | printed |= stack.dumpActivitiesLocked(fd, pw, dumpAll, dumpClient, dumpPackage, |
| 3853 | needSep); |
Winson Chung | abb433b | 2017-03-24 09:35:42 -0700 | [diff] [blame] | 3854 | |
Craig Mautner | 4a1cb22 | 2013-12-04 16:14:06 -0800 | [diff] [blame] | 3855 | printed |= dumpHistoryList(fd, pw, stack.mLRUActivities, " ", "Run", false, |
| 3856 | !dumpAll, false, dumpPackage, true, |
| 3857 | " Running activities (most recent first):", null); |
Craig Mautner | 8d341ef | 2013-03-26 09:03:27 -0700 | [diff] [blame] | 3858 | |
Craig Mautner | 4a1cb22 | 2013-12-04 16:14:06 -0800 | [diff] [blame] | 3859 | needSep = printed; |
| 3860 | boolean pr = printThisActivity(pw, stack.mPausingActivity, dumpPackage, needSep, |
| 3861 | " mPausingActivity: "); |
Dianne Hackborn | 7ad34e5 | 2013-06-05 18:41:45 -0700 | [diff] [blame] | 3862 | if (pr) { |
| 3863 | printed = true; |
Craig Mautner | 4a1cb22 | 2013-12-04 16:14:06 -0800 | [diff] [blame] | 3864 | needSep = false; |
Dianne Hackborn | 7ad34e5 | 2013-06-05 18:41:45 -0700 | [diff] [blame] | 3865 | } |
Craig Mautner | 4a1cb22 | 2013-12-04 16:14:06 -0800 | [diff] [blame] | 3866 | pr = printThisActivity(pw, stack.mResumedActivity, dumpPackage, needSep, |
| 3867 | " mResumedActivity: "); |
| 3868 | if (pr) { |
| 3869 | printed = true; |
| 3870 | needSep = false; |
| 3871 | } |
| 3872 | if (dumpAll) { |
| 3873 | pr = printThisActivity(pw, stack.mLastPausedActivity, dumpPackage, needSep, |
| 3874 | " mLastPausedActivity: "); |
| 3875 | if (pr) { |
| 3876 | printed = true; |
| 3877 | needSep = true; |
| 3878 | } |
| 3879 | printed |= printThisActivity(pw, stack.mLastNoHistoryActivity, dumpPackage, |
| 3880 | needSep, " mLastNoHistoryActivity: "); |
| 3881 | } |
| 3882 | needSep = printed; |
Craig Mautner | 8d341ef | 2013-03-26 09:03:27 -0700 | [diff] [blame] | 3883 | } |
| 3884 | } |
| 3885 | |
Dianne Hackborn | 7ad34e5 | 2013-06-05 18:41:45 -0700 | [diff] [blame] | 3886 | printed |= dumpHistoryList(fd, pw, mFinishingActivities, " ", "Fin", false, !dumpAll, |
| 3887 | false, dumpPackage, true, " Activities waiting to finish:", null); |
| 3888 | printed |= dumpHistoryList(fd, pw, mStoppingActivities, " ", "Stop", false, !dumpAll, |
| 3889 | false, dumpPackage, true, " Activities waiting to stop:", null); |
Bryce Lee | 4a19438 | 2017-04-04 14:32:48 -0700 | [diff] [blame] | 3890 | printed |= dumpHistoryList(fd, pw, mActivitiesWaitingForVisibleActivity, " ", "Wait", |
| 3891 | false, !dumpAll, false, dumpPackage, true, |
| 3892 | " Activities waiting for another to become visible:", null); |
Dianne Hackborn | 7ad34e5 | 2013-06-05 18:41:45 -0700 | [diff] [blame] | 3893 | printed |= dumpHistoryList(fd, pw, mGoingToSleepActivities, " ", "Sleep", false, !dumpAll, |
| 3894 | false, dumpPackage, true, " Activities waiting to sleep:", null); |
Craig Mautner | f333327 | 2013-04-22 10:55:53 -0700 | [diff] [blame] | 3895 | |
Dianne Hackborn | 7ad34e5 | 2013-06-05 18:41:45 -0700 | [diff] [blame] | 3896 | return printed; |
Craig Mautner | 8d341ef | 2013-03-26 09:03:27 -0700 | [diff] [blame] | 3897 | } |
| 3898 | |
Dianne Hackborn | 390517b | 2013-05-30 15:03:32 -0700 | [diff] [blame] | 3899 | static boolean dumpHistoryList(FileDescriptor fd, PrintWriter pw, List<ActivityRecord> list, |
Craig Mautner | 8d341ef | 2013-03-26 09:03:27 -0700 | [diff] [blame] | 3900 | String prefix, String label, boolean complete, boolean brief, boolean client, |
Wale Ogunwale | 34a5b57 | 2017-08-31 08:29:41 -0700 | [diff] [blame] | 3901 | String dumpPackage, boolean needNL, String header, TaskRecord lastTask) { |
Dianne Hackborn | 390517b | 2013-05-30 15:03:32 -0700 | [diff] [blame] | 3902 | String innerPrefix = null; |
| 3903 | String[] args = null; |
| 3904 | boolean printed = false; |
Craig Mautner | 8d341ef | 2013-03-26 09:03:27 -0700 | [diff] [blame] | 3905 | for (int i=list.size()-1; i>=0; i--) { |
| 3906 | final ActivityRecord r = list.get(i); |
| 3907 | if (dumpPackage != null && !dumpPackage.equals(r.packageName)) { |
| 3908 | continue; |
| 3909 | } |
Dianne Hackborn | 390517b | 2013-05-30 15:03:32 -0700 | [diff] [blame] | 3910 | if (innerPrefix == null) { |
| 3911 | innerPrefix = prefix + " "; |
| 3912 | args = new String[0]; |
| 3913 | } |
| 3914 | printed = true; |
Craig Mautner | 8d341ef | 2013-03-26 09:03:27 -0700 | [diff] [blame] | 3915 | final boolean full = !brief && (complete || !r.isInHistory()); |
| 3916 | if (needNL) { |
Dianne Hackborn | 390517b | 2013-05-30 15:03:32 -0700 | [diff] [blame] | 3917 | pw.println(""); |
Craig Mautner | 8d341ef | 2013-03-26 09:03:27 -0700 | [diff] [blame] | 3918 | needNL = false; |
| 3919 | } |
Wale Ogunwale | 34a5b57 | 2017-08-31 08:29:41 -0700 | [diff] [blame] | 3920 | if (header != null) { |
| 3921 | pw.println(header); |
| 3922 | header = null; |
Dianne Hackborn | 390517b | 2013-05-30 15:03:32 -0700 | [diff] [blame] | 3923 | } |
Bryce Lee | af691c0 | 2017-03-20 14:20:22 -0700 | [diff] [blame] | 3924 | if (lastTask != r.getTask()) { |
| 3925 | lastTask = r.getTask(); |
Craig Mautner | 8d341ef | 2013-03-26 09:03:27 -0700 | [diff] [blame] | 3926 | pw.print(prefix); |
| 3927 | pw.print(full ? "* " : " "); |
| 3928 | pw.println(lastTask); |
| 3929 | if (full) { |
| 3930 | lastTask.dump(pw, prefix + " "); |
| 3931 | } else if (complete) { |
| 3932 | // Complete + brief == give a summary. Isn't that obvious?!? |
| 3933 | if (lastTask.intent != null) { |
| 3934 | pw.print(prefix); pw.print(" "); |
| 3935 | pw.println(lastTask.intent.toInsecureStringWithClip()); |
| 3936 | } |
| 3937 | } |
| 3938 | } |
| 3939 | pw.print(prefix); pw.print(full ? " * " : " "); pw.print(label); |
| 3940 | pw.print(" #"); pw.print(i); pw.print(": "); |
| 3941 | pw.println(r); |
| 3942 | if (full) { |
| 3943 | r.dump(pw, innerPrefix); |
| 3944 | } else if (complete) { |
| 3945 | // Complete + brief == give a summary. Isn't that obvious?!? |
| 3946 | pw.print(innerPrefix); pw.println(r.intent.toInsecureString()); |
| 3947 | if (r.app != null) { |
| 3948 | pw.print(innerPrefix); pw.println(r.app); |
| 3949 | } |
| 3950 | } |
| 3951 | if (client && r.app != null && r.app.thread != null) { |
| 3952 | // flush anything that is already in the PrintWriter since the thread is going |
| 3953 | // to write to the file descriptor directly |
| 3954 | pw.flush(); |
| 3955 | try { |
| 3956 | TransferPipe tp = new TransferPipe(); |
| 3957 | try { |
Sudheer Shanka | cc6418f | 2016-10-13 12:03:44 -0700 | [diff] [blame] | 3958 | r.app.thread.dumpActivity(tp.getWriteFd(), r.appToken, innerPrefix, args); |
Craig Mautner | 8d341ef | 2013-03-26 09:03:27 -0700 | [diff] [blame] | 3959 | // Short timeout, since blocking here can |
| 3960 | // deadlock with the application. |
| 3961 | tp.go(fd, 2000); |
| 3962 | } finally { |
| 3963 | tp.kill(); |
| 3964 | } |
| 3965 | } catch (IOException e) { |
| 3966 | pw.println(innerPrefix + "Failure while dumping the activity: " + e); |
| 3967 | } catch (RemoteException e) { |
| 3968 | pw.println(innerPrefix + "Got a RemoteException while dumping the activity"); |
| 3969 | } |
| 3970 | needNL = true; |
| 3971 | } |
| 3972 | } |
Dianne Hackborn | 390517b | 2013-05-30 15:03:32 -0700 | [diff] [blame] | 3973 | return printed; |
Craig Mautner | 8d341ef | 2013-03-26 09:03:27 -0700 | [diff] [blame] | 3974 | } |
Craig Mautner | ce5f3cb | 2013-04-22 08:58:54 -0700 | [diff] [blame] | 3975 | |
Craig Mautner | f333327 | 2013-04-22 10:55:53 -0700 | [diff] [blame] | 3976 | void scheduleIdleTimeoutLocked(ActivityRecord next) { |
Wale Ogunwale | 0fc365c | 2015-05-25 19:35:42 -0700 | [diff] [blame] | 3977 | if (DEBUG_IDLE) Slog.d(TAG_IDLE, |
| 3978 | "scheduleIdleTimeoutLocked: Callers=" + Debug.getCallers(4)); |
Craig Mautner | c64f73e | 2013-04-24 16:44:56 -0700 | [diff] [blame] | 3979 | Message msg = mHandler.obtainMessage(IDLE_TIMEOUT_MSG, next); |
| 3980 | mHandler.sendMessageDelayed(msg, IDLE_TIMEOUT); |
Craig Mautner | f333327 | 2013-04-22 10:55:53 -0700 | [diff] [blame] | 3981 | } |
| 3982 | |
| 3983 | final void scheduleIdleLocked() { |
Craig Mautner | 05d2903 | 2013-05-03 13:40:13 -0700 | [diff] [blame] | 3984 | mHandler.sendEmptyMessage(IDLE_NOW_MSG); |
Craig Mautner | f333327 | 2013-04-22 10:55:53 -0700 | [diff] [blame] | 3985 | } |
| 3986 | |
| 3987 | void removeTimeoutsForActivityLocked(ActivityRecord r) { |
Wale Ogunwale | 0fc365c | 2015-05-25 19:35:42 -0700 | [diff] [blame] | 3988 | if (DEBUG_IDLE) Slog.d(TAG_IDLE, "removeTimeoutsForActivity: Callers=" |
| 3989 | + Debug.getCallers(4)); |
Craig Mautner | f333327 | 2013-04-22 10:55:53 -0700 | [diff] [blame] | 3990 | mHandler.removeMessages(IDLE_TIMEOUT_MSG, r); |
| 3991 | } |
| 3992 | |
Craig Mautner | 05d2903 | 2013-05-03 13:40:13 -0700 | [diff] [blame] | 3993 | final void scheduleResumeTopActivities() { |
Craig Mautner | 34b73df | 2014-01-12 21:11:08 -0800 | [diff] [blame] | 3994 | if (!mHandler.hasMessages(RESUME_TOP_ACTIVITY_MSG)) { |
| 3995 | mHandler.sendEmptyMessage(RESUME_TOP_ACTIVITY_MSG); |
| 3996 | } |
Craig Mautner | 05d2903 | 2013-05-03 13:40:13 -0700 | [diff] [blame] | 3997 | } |
| 3998 | |
Craig Mautner | 0eea92c | 2013-05-16 13:35:39 -0700 | [diff] [blame] | 3999 | void removeSleepTimeouts() { |
Craig Mautner | 0eea92c | 2013-05-16 13:35:39 -0700 | [diff] [blame] | 4000 | mHandler.removeMessages(SLEEP_TIMEOUT_MSG); |
| 4001 | } |
| 4002 | |
| 4003 | final void scheduleSleepTimeout() { |
| 4004 | removeSleepTimeouts(); |
| 4005 | mHandler.sendEmptyMessageDelayed(SLEEP_TIMEOUT_MSG, SLEEP_TIMEOUT); |
| 4006 | } |
| 4007 | |
Craig Mautner | 4a1cb22 | 2013-12-04 16:14:06 -0800 | [diff] [blame] | 4008 | @Override |
| 4009 | public void onDisplayAdded(int displayId) { |
Dianne Hackborn | fb81d09 | 2015-08-03 17:14:46 -0700 | [diff] [blame] | 4010 | if (DEBUG_STACK) Slog.v(TAG, "Display added displayId=" + displayId); |
Craig Mautner | 4a1cb22 | 2013-12-04 16:14:06 -0800 | [diff] [blame] | 4011 | mHandler.sendMessage(mHandler.obtainMessage(HANDLE_DISPLAY_ADDED, displayId, 0)); |
| 4012 | } |
| 4013 | |
| 4014 | @Override |
| 4015 | public void onDisplayRemoved(int displayId) { |
Dianne Hackborn | fb81d09 | 2015-08-03 17:14:46 -0700 | [diff] [blame] | 4016 | if (DEBUG_STACK) Slog.v(TAG, "Display removed displayId=" + displayId); |
Craig Mautner | 4a1cb22 | 2013-12-04 16:14:06 -0800 | [diff] [blame] | 4017 | mHandler.sendMessage(mHandler.obtainMessage(HANDLE_DISPLAY_REMOVED, displayId, 0)); |
| 4018 | } |
| 4019 | |
| 4020 | @Override |
| 4021 | public void onDisplayChanged(int displayId) { |
Dianne Hackborn | fb81d09 | 2015-08-03 17:14:46 -0700 | [diff] [blame] | 4022 | if (DEBUG_STACK) Slog.v(TAG, "Display changed displayId=" + displayId); |
Craig Mautner | 4a1cb22 | 2013-12-04 16:14:06 -0800 | [diff] [blame] | 4023 | mHandler.sendMessage(mHandler.obtainMessage(HANDLE_DISPLAY_CHANGED, displayId, 0)); |
| 4024 | } |
| 4025 | |
Wale Ogunwale | f16a281 | 2015-04-01 11:23:15 -0700 | [diff] [blame] | 4026 | private void handleDisplayAdded(int displayId) { |
Craig Mautner | 4a1cb22 | 2013-12-04 16:14:06 -0800 | [diff] [blame] | 4027 | synchronized (mService) { |
Andrii Kulian | 62e6f25 | 2017-05-30 22:46:53 -0700 | [diff] [blame] | 4028 | getActivityDisplayOrCreateLocked(displayId); |
Craig Mautner | 4a1cb22 | 2013-12-04 16:14:06 -0800 | [diff] [blame] | 4029 | } |
Craig Mautner | 4a1cb22 | 2013-12-04 16:14:06 -0800 | [diff] [blame] | 4030 | } |
| 4031 | |
Andrii Kulian | ca007a6 | 2016-11-22 16:33:28 -0800 | [diff] [blame] | 4032 | /** Check if display with specified id is added to the list. */ |
| 4033 | boolean isDisplayAdded(int displayId) { |
Andrii Kulian | 62e6f25 | 2017-05-30 22:46:53 -0700 | [diff] [blame] | 4034 | return getActivityDisplayOrCreateLocked(displayId) != null; |
| 4035 | } |
| 4036 | |
Wale Ogunwale | 04a05ac | 2017-09-17 21:35:02 -0700 | [diff] [blame] | 4037 | // TODO: Look into consolidating with getActivityDisplayOrCreateLocked() |
Andrii Kulian | 94e82d9b0 | 2017-07-13 15:33:06 -0700 | [diff] [blame] | 4038 | ActivityDisplay getActivityDisplay(int displayId) { |
| 4039 | return mActivityDisplays.get(displayId); |
| 4040 | } |
| 4041 | |
Wale Ogunwale | 04a05ac | 2017-09-17 21:35:02 -0700 | [diff] [blame] | 4042 | // TODO(multi-display): Look at all callpoints to make sure they make sense in multi-display. |
| 4043 | ActivityDisplay getDefaultDisplay() { |
| 4044 | return mActivityDisplays.get(DEFAULT_DISPLAY); |
| 4045 | } |
| 4046 | |
Andrii Kulian | 62e6f25 | 2017-05-30 22:46:53 -0700 | [diff] [blame] | 4047 | /** |
| 4048 | * Get an existing instance of {@link ActivityDisplay} or create new if there is a |
| 4049 | * corresponding record in display manager. |
| 4050 | */ |
Wale Ogunwale | 04a05ac | 2017-09-17 21:35:02 -0700 | [diff] [blame] | 4051 | // TODO: Look into consolidating with getActivityDisplay() |
| 4052 | ActivityDisplay getActivityDisplayOrCreateLocked(int displayId) { |
Andrii Kulian | 62e6f25 | 2017-05-30 22:46:53 -0700 | [diff] [blame] | 4053 | ActivityDisplay activityDisplay = mActivityDisplays.get(displayId); |
| 4054 | if (activityDisplay != null) { |
| 4055 | return activityDisplay; |
| 4056 | } |
| 4057 | if (mDisplayManager == null) { |
| 4058 | // The system isn't fully initialized yet. |
| 4059 | return null; |
| 4060 | } |
| 4061 | final Display display = mDisplayManager.getDisplay(displayId); |
| 4062 | if (display == null) { |
| 4063 | // The display is not registered in DisplayManager. |
| 4064 | return null; |
| 4065 | } |
| 4066 | // The display hasn't been added to ActivityManager yet, create a new record now. |
Wale Ogunwale | 9dcf946 | 2017-09-19 15:13:01 -0700 | [diff] [blame] | 4067 | activityDisplay = new ActivityDisplay(this, displayId); |
| 4068 | attachDisplay(activityDisplay); |
Andrii Kulian | 62e6f25 | 2017-05-30 22:46:53 -0700 | [diff] [blame] | 4069 | calculateDefaultMinimalSizeOfResizeableTasks(activityDisplay); |
| 4070 | mWindowManager.onDisplayAdded(displayId); |
| 4071 | return activityDisplay; |
Andrii Kulian | ca007a6 | 2016-11-22 16:33:28 -0800 | [diff] [blame] | 4072 | } |
| 4073 | |
Wale Ogunwale | 9dcf946 | 2017-09-19 15:13:01 -0700 | [diff] [blame] | 4074 | @VisibleForTesting |
| 4075 | void attachDisplay(ActivityDisplay display) { |
| 4076 | mActivityDisplays.put(display.mDisplayId, display); |
| 4077 | } |
| 4078 | |
Filip Gruszczynski | d2f1d94 | 2015-10-14 15:10:12 -0700 | [diff] [blame] | 4079 | private void calculateDefaultMinimalSizeOfResizeableTasks(ActivityDisplay display) { |
Andrii Kulian | f66a83d | 2016-05-17 12:17:44 -0700 | [diff] [blame] | 4080 | mDefaultMinSizeOfResizeableTask = |
Jorim Jaggi | 19cf297 | 2016-04-07 23:26:10 -0700 | [diff] [blame] | 4081 | mService.mContext.getResources().getDimensionPixelSize( |
| 4082 | com.android.internal.R.dimen.default_minimal_size_resizable_task); |
Filip Gruszczynski | d2f1d94 | 2015-10-14 15:10:12 -0700 | [diff] [blame] | 4083 | } |
| 4084 | |
Wale Ogunwale | f16a281 | 2015-04-01 11:23:15 -0700 | [diff] [blame] | 4085 | private void handleDisplayRemoved(int displayId) { |
Andrii Kulian | a33818c | 2017-02-16 16:11:30 -0800 | [diff] [blame] | 4086 | if (displayId == DEFAULT_DISPLAY) { |
| 4087 | throw new IllegalArgumentException("Can't remove the primary display."); |
| 4088 | } |
| 4089 | |
Craig Mautner | 4a1cb22 | 2013-12-04 16:14:06 -0800 | [diff] [blame] | 4090 | synchronized (mService) { |
Wale Ogunwale | a0f5b5e | 2017-10-11 09:37:23 -0700 | [diff] [blame] | 4091 | final ActivityDisplay activityDisplay = mActivityDisplays.get(displayId); |
| 4092 | if (activityDisplay == null) { |
| 4093 | return; |
Craig Mautner | 4a1cb22 | 2013-12-04 16:14:06 -0800 | [diff] [blame] | 4094 | } |
Wale Ogunwale | a0f5b5e | 2017-10-11 09:37:23 -0700 | [diff] [blame] | 4095 | final boolean destroyContentOnRemoval |
| 4096 | = activityDisplay.shouldDestroyContentOnRemove(); |
| 4097 | while (activityDisplay.getChildCount() > 0) { |
| 4098 | final ActivityStack stack = activityDisplay.getChildAt(0); |
| 4099 | if (destroyContentOnRemoval) { |
| 4100 | moveStackToDisplayLocked(stack.mStackId, DEFAULT_DISPLAY, false /* onTop */); |
| 4101 | stack.finishAllActivitiesLocked(true /* immediately */); |
| 4102 | } else { |
| 4103 | // Moving all tasks to fullscreen stack, because it's guaranteed to be |
| 4104 | // a valid launch stack for all activities. This way the task history from |
| 4105 | // external display will be preserved on primary after move. |
| 4106 | moveTasksToFullscreenStackLocked(stack, true /* onTop */); |
| 4107 | } |
| 4108 | } |
| 4109 | |
| 4110 | releaseSleepTokens(activityDisplay); |
| 4111 | |
| 4112 | mActivityDisplays.remove(displayId); |
| 4113 | mWindowManager.onDisplayRemoved(displayId); |
Craig Mautner | 4a1cb22 | 2013-12-04 16:14:06 -0800 | [diff] [blame] | 4114 | } |
Craig Mautner | 4a1cb22 | 2013-12-04 16:14:06 -0800 | [diff] [blame] | 4115 | } |
| 4116 | |
Wale Ogunwale | f16a281 | 2015-04-01 11:23:15 -0700 | [diff] [blame] | 4117 | private void handleDisplayChanged(int displayId) { |
Craig Mautner | 4a1cb22 | 2013-12-04 16:14:06 -0800 | [diff] [blame] | 4118 | synchronized (mService) { |
Craig Mautner | e0a3884 | 2013-12-16 16:14:02 -0800 | [diff] [blame] | 4119 | ActivityDisplay activityDisplay = mActivityDisplays.get(displayId); |
Bryce Lee | f3c6a47 | 2017-11-14 14:53:06 -0800 | [diff] [blame] | 4120 | // TODO: The following code block should be moved into {@link ActivityDisplay}. |
Craig Mautner | e0a3884 | 2013-12-16 16:14:02 -0800 | [diff] [blame] | 4121 | if (activityDisplay != null) { |
David Stevens | 9440dc8 | 2017-03-16 19:00:20 -0700 | [diff] [blame] | 4122 | // The window policy is responsible for stopping activities on the default display |
| 4123 | if (displayId != Display.DEFAULT_DISPLAY) { |
| 4124 | int displayState = activityDisplay.mDisplay.getState(); |
| 4125 | if (displayState == Display.STATE_OFF && activityDisplay.mOffToken == null) { |
| 4126 | activityDisplay.mOffToken = |
| 4127 | mService.acquireSleepToken("Display-off", displayId); |
| 4128 | } else if (displayState == Display.STATE_ON |
| 4129 | && activityDisplay.mOffToken != null) { |
| 4130 | activityDisplay.mOffToken.release(); |
| 4131 | activityDisplay.mOffToken = null; |
| 4132 | } |
| 4133 | } |
Bryce Lee | f3c6a47 | 2017-11-14 14:53:06 -0800 | [diff] [blame] | 4134 | |
| 4135 | activityDisplay.updateBounds(); |
Craig Mautner | 4a1cb22 | 2013-12-04 16:14:06 -0800 | [diff] [blame] | 4136 | } |
Bryce Lee | af3a400 | 2017-03-20 10:37:12 -0700 | [diff] [blame] | 4137 | mWindowManager.onDisplayChanged(displayId); |
Craig Mautner | 4a1cb22 | 2013-12-04 16:14:06 -0800 | [diff] [blame] | 4138 | } |
Craig Mautner | 4a1cb22 | 2013-12-04 16:14:06 -0800 | [diff] [blame] | 4139 | } |
| 4140 | |
David Stevens | 9440dc8 | 2017-03-16 19:00:20 -0700 | [diff] [blame] | 4141 | SleepToken createSleepTokenLocked(String tag, int displayId) { |
| 4142 | ActivityDisplay display = mActivityDisplays.get(displayId); |
| 4143 | if (display == null) { |
| 4144 | throw new IllegalArgumentException("Invalid display: " + displayId); |
| 4145 | } |
| 4146 | |
| 4147 | final SleepTokenImpl token = new SleepTokenImpl(tag, displayId); |
| 4148 | mSleepTokens.add(token); |
| 4149 | display.mAllSleepTokens.add(token); |
| 4150 | return token; |
| 4151 | } |
| 4152 | |
| 4153 | private void removeSleepTokenLocked(SleepTokenImpl token) { |
| 4154 | mSleepTokens.remove(token); |
| 4155 | |
| 4156 | ActivityDisplay display = mActivityDisplays.get(token.mDisplayId); |
| 4157 | if (display != null) { |
| 4158 | display.mAllSleepTokens.remove(token); |
| 4159 | if (display.mAllSleepTokens.isEmpty()) { |
| 4160 | mService.updateSleepIfNeededLocked(); |
| 4161 | } |
| 4162 | } |
| 4163 | } |
| 4164 | |
| 4165 | private void releaseSleepTokens(ActivityDisplay display) { |
| 4166 | if (display.mAllSleepTokens.isEmpty()) { |
| 4167 | return; |
| 4168 | } |
Wale Ogunwale | 9dcf946 | 2017-09-19 15:13:01 -0700 | [diff] [blame] | 4169 | for (SleepToken token : display.mAllSleepTokens) { |
David Stevens | 9440dc8 | 2017-03-16 19:00:20 -0700 | [diff] [blame] | 4170 | mSleepTokens.remove(token); |
| 4171 | } |
| 4172 | display.mAllSleepTokens.clear(); |
| 4173 | |
| 4174 | mService.updateSleepIfNeededLocked(); |
| 4175 | } |
| 4176 | |
Wale Ogunwale | 6827856 | 2017-09-23 17:13:55 -0700 | [diff] [blame] | 4177 | private StackInfo getStackInfo(ActivityStack stack) { |
Andrii Kulian | 7e215d7 | 2017-04-26 18:33:28 -0700 | [diff] [blame] | 4178 | final int displayId = stack.mDisplayId; |
| 4179 | final ActivityDisplay display = mActivityDisplays.get(displayId); |
Craig Mautner | 4a1cb22 | 2013-12-04 16:14:06 -0800 | [diff] [blame] | 4180 | StackInfo info = new StackInfo(); |
Wale Ogunwale | 1666e31 | 2016-12-16 11:27:18 -0800 | [diff] [blame] | 4181 | stack.getWindowContainerBounds(info.bounds); |
Andrii Kulian | 7e215d7 | 2017-04-26 18:33:28 -0700 | [diff] [blame] | 4182 | info.displayId = displayId; |
Craig Mautner | 4a1cb22 | 2013-12-04 16:14:06 -0800 | [diff] [blame] | 4183 | info.stackId = stack.mStackId; |
Filip Gruszczynski | 21199bd | 2015-12-02 12:49:58 -0800 | [diff] [blame] | 4184 | info.userId = stack.mCurrentUser; |
Wale Ogunwale | 9dcf946 | 2017-09-19 15:13:01 -0700 | [diff] [blame] | 4185 | info.visible = stack.shouldBeVisible(null); |
Andrii Kulian | 62e6f25 | 2017-05-30 22:46:53 -0700 | [diff] [blame] | 4186 | // A stack might be not attached to a display. |
Wale Ogunwale | a0f5b5e | 2017-10-11 09:37:23 -0700 | [diff] [blame] | 4187 | info.position = display != null ? display.getIndexOf(stack) : 0; |
Wale Ogunwale | 6827856 | 2017-09-23 17:13:55 -0700 | [diff] [blame] | 4188 | info.configuration.setTo(stack.getConfiguration()); |
Craig Mautner | 4a1cb22 | 2013-12-04 16:14:06 -0800 | [diff] [blame] | 4189 | |
| 4190 | ArrayList<TaskRecord> tasks = stack.getAllTasks(); |
| 4191 | final int numTasks = tasks.size(); |
| 4192 | int[] taskIds = new int[numTasks]; |
| 4193 | String[] taskNames = new String[numTasks]; |
Wale Ogunwale | e4a0c57 | 2015-06-30 08:40:31 -0700 | [diff] [blame] | 4194 | Rect[] taskBounds = new Rect[numTasks]; |
Filip Gruszczynski | 21199bd | 2015-12-02 12:49:58 -0800 | [diff] [blame] | 4195 | int[] taskUserIds = new int[numTasks]; |
Craig Mautner | 4a1cb22 | 2013-12-04 16:14:06 -0800 | [diff] [blame] | 4196 | for (int i = 0; i < numTasks; ++i) { |
| 4197 | final TaskRecord task = tasks.get(i); |
| 4198 | taskIds[i] = task.taskId; |
| 4199 | taskNames[i] = task.origActivity != null ? task.origActivity.flattenToString() |
| 4200 | : task.realActivity != null ? task.realActivity.flattenToString() |
| 4201 | : task.getTopActivity() != null ? task.getTopActivity().packageName |
| 4202 | : "unknown"; |
Wale Ogunwale | e4a0c57 | 2015-06-30 08:40:31 -0700 | [diff] [blame] | 4203 | taskBounds[i] = new Rect(); |
Wale Ogunwale | e1fe7fa2 | 2016-12-15 18:27:00 -0800 | [diff] [blame] | 4204 | task.getWindowContainerBounds(taskBounds[i]); |
Filip Gruszczynski | 21199bd | 2015-12-02 12:49:58 -0800 | [diff] [blame] | 4205 | taskUserIds[i] = task.userId; |
Craig Mautner | 4a1cb22 | 2013-12-04 16:14:06 -0800 | [diff] [blame] | 4206 | } |
| 4207 | info.taskIds = taskIds; |
| 4208 | info.taskNames = taskNames; |
Wale Ogunwale | 868a5e1 | 2015-08-02 16:19:20 -0700 | [diff] [blame] | 4209 | info.taskBounds = taskBounds; |
Filip Gruszczynski | 21199bd | 2015-12-02 12:49:58 -0800 | [diff] [blame] | 4210 | info.taskUserIds = taskUserIds; |
Winson | d46b727 | 2016-04-20 11:54:27 -0700 | [diff] [blame] | 4211 | |
| 4212 | final ActivityRecord top = stack.topRunningActivityLocked(); |
| 4213 | info.topActivity = top != null ? top.intent.getComponent() : null; |
Craig Mautner | 4a1cb22 | 2013-12-04 16:14:06 -0800 | [diff] [blame] | 4214 | return info; |
| 4215 | } |
| 4216 | |
Wale Ogunwale | 6827856 | 2017-09-23 17:13:55 -0700 | [diff] [blame] | 4217 | StackInfo getStackInfo(int stackId) { |
Craig Mautner | 4a1cb22 | 2013-12-04 16:14:06 -0800 | [diff] [blame] | 4218 | ActivityStack stack = getStack(stackId); |
| 4219 | if (stack != null) { |
Wale Ogunwale | 6827856 | 2017-09-23 17:13:55 -0700 | [diff] [blame] | 4220 | return getStackInfo(stack); |
Craig Mautner | 4a1cb22 | 2013-12-04 16:14:06 -0800 | [diff] [blame] | 4221 | } |
| 4222 | return null; |
| 4223 | } |
| 4224 | |
Wale Ogunwale | 6827856 | 2017-09-23 17:13:55 -0700 | [diff] [blame] | 4225 | StackInfo getStackInfo(int windowingMode, int activityType) { |
| 4226 | final ActivityStack stack = getStack(windowingMode, activityType); |
| 4227 | return (stack != null) ? getStackInfo(stack) : null; |
| 4228 | } |
| 4229 | |
Craig Mautner | 4a1cb22 | 2013-12-04 16:14:06 -0800 | [diff] [blame] | 4230 | ArrayList<StackInfo> getAllStackInfosLocked() { |
Wale Ogunwale | e4a0c57 | 2015-06-30 08:40:31 -0700 | [diff] [blame] | 4231 | ArrayList<StackInfo> list = new ArrayList<>(); |
Craig Mautner | e0a3884 | 2013-12-16 16:14:02 -0800 | [diff] [blame] | 4232 | for (int displayNdx = 0; displayNdx < mActivityDisplays.size(); ++displayNdx) { |
Wale Ogunwale | a0f5b5e | 2017-10-11 09:37:23 -0700 | [diff] [blame] | 4233 | final ActivityDisplay display = mActivityDisplays.valueAt(displayNdx); |
| 4234 | for (int stackNdx = display.getChildCount() - 1; stackNdx >= 0; --stackNdx) { |
| 4235 | final ActivityStack stack = display.getChildAt(stackNdx); |
| 4236 | list.add(getStackInfo(stack)); |
Craig Mautner | 4a1cb22 | 2013-12-04 16:14:06 -0800 | [diff] [blame] | 4237 | } |
| 4238 | } |
| 4239 | return list; |
| 4240 | } |
| 4241 | |
Wale Ogunwale | 0568aed | 2017-09-08 13:29:37 -0700 | [diff] [blame] | 4242 | void handleNonResizableTaskIfNeeded(TaskRecord task, int preferredWindowingMode, |
Wale Ogunwale | a0f5b5e | 2017-10-11 09:37:23 -0700 | [diff] [blame] | 4243 | int preferredDisplayId, ActivityStack actualStack) { |
Wale Ogunwale | 0568aed | 2017-09-08 13:29:37 -0700 | [diff] [blame] | 4244 | handleNonResizableTaskIfNeeded(task, preferredWindowingMode, preferredDisplayId, |
Wale Ogunwale | a0f5b5e | 2017-10-11 09:37:23 -0700 | [diff] [blame] | 4245 | actualStack, false /* forceNonResizable */); |
Andrii Kulian | c2791664 | 2016-04-12 17:59:27 -0700 | [diff] [blame] | 4246 | } |
| 4247 | |
Wale Ogunwale | 0568aed | 2017-09-08 13:29:37 -0700 | [diff] [blame] | 4248 | void handleNonResizableTaskIfNeeded(TaskRecord task, int preferredWindowingMode, |
Wale Ogunwale | a0f5b5e | 2017-10-11 09:37:23 -0700 | [diff] [blame] | 4249 | int preferredDisplayId, ActivityStack actualStack, boolean forceNonResizable) { |
Andrii Kulian | 036e3ad | 2017-04-19 10:55:10 -0700 | [diff] [blame] | 4250 | final boolean isSecondaryDisplayPreferred = |
Wale Ogunwale | 0568aed | 2017-09-08 13:29:37 -0700 | [diff] [blame] | 4251 | (preferredDisplayId != DEFAULT_DISPLAY && preferredDisplayId != INVALID_DISPLAY); |
Wale Ogunwale | 926aade | 2017-08-29 11:24:37 -0700 | [diff] [blame] | 4252 | final boolean inSplitScreenMode = actualStack != null |
Wale Ogunwale | 7e1f5f5 | 2017-10-18 15:19:59 -0700 | [diff] [blame] | 4253 | && actualStack.getDisplay().hasSplitScreenPrimaryStack(); |
Wale Ogunwale | 0568aed | 2017-09-08 13:29:37 -0700 | [diff] [blame] | 4254 | if (((!inSplitScreenMode && preferredWindowingMode != WINDOWING_MODE_SPLIT_SCREEN_PRIMARY) |
Wale Ogunwale | 7e1f5f5 | 2017-10-18 15:19:59 -0700 | [diff] [blame] | 4255 | && !isSecondaryDisplayPreferred) || !task.isActivityTypeStandardOrUndefined()) { |
Wale Ogunwale | b9b16a7 | 2016-01-27 12:24:44 -0800 | [diff] [blame] | 4256 | return; |
| 4257 | } |
| 4258 | |
Andrii Kulian | 036e3ad | 2017-04-19 10:55:10 -0700 | [diff] [blame] | 4259 | // Handle incorrect launch/move to secondary display if needed. |
Andrii Kulian | 036e3ad | 2017-04-19 10:55:10 -0700 | [diff] [blame] | 4260 | if (isSecondaryDisplayPreferred) { |
| 4261 | final int actualDisplayId = task.getStack().mDisplayId; |
| 4262 | if (!task.canBeLaunchedOnDisplay(actualDisplayId)) { |
Andrii Kulian | b850ea5 | 2017-12-12 23:49:10 -0800 | [diff] [blame] | 4263 | throw new IllegalStateException("Task resolved to incompatible display"); |
Andrii Kulian | 036e3ad | 2017-04-19 10:55:10 -0700 | [diff] [blame] | 4264 | } |
Andrii Kulian | b850ea5 | 2017-12-12 23:49:10 -0800 | [diff] [blame] | 4265 | // The task might have landed on a display different from requested. |
| 4266 | // TODO(multi-display): Find proper stack for the task on the default display. |
| 4267 | mService.setTaskWindowingMode(task.taskId, |
| 4268 | WINDOWING_MODE_FULLSCREEN_OR_SPLIT_SCREEN_SECONDARY, true /* toTop */); |
| 4269 | if (preferredDisplayId != actualDisplayId) { |
Andrii Kulian | 036e3ad | 2017-04-19 10:55:10 -0700 | [diff] [blame] | 4270 | // Display a warning toast that we tried to put a non-resizeable task on a secondary |
| 4271 | // display with config different from global config. |
| 4272 | mService.mTaskChangeNotificationController |
| 4273 | .notifyActivityLaunchOnSecondaryDisplayFailed(); |
Wale Ogunwale | 2b07da8 | 2017-11-08 14:52:40 -0800 | [diff] [blame] | 4274 | return; |
Andrii Kulian | 036e3ad | 2017-04-19 10:55:10 -0700 | [diff] [blame] | 4275 | } |
Wale Ogunwale | 2b07da8 | 2017-11-08 14:52:40 -0800 | [diff] [blame] | 4276 | } |
| 4277 | |
Wale Ogunwale | 2b07da8 | 2017-11-08 14:52:40 -0800 | [diff] [blame] | 4278 | if (!task.supportsSplitScreenWindowingMode() || forceNonResizable) { |
Wale Ogunwale | 30e441d | 2017-11-09 08:28:45 -0800 | [diff] [blame] | 4279 | // Display a warning toast that we tried to put an app that doesn't support split-screen |
| 4280 | // in split-screen. |
Wale Ogunwale | 2b07da8 | 2017-11-08 14:52:40 -0800 | [diff] [blame] | 4281 | mService.mTaskChangeNotificationController.notifyActivityDismissingDockedStack(); |
Jorim Jaggi | d53f092 | 2016-04-06 22:16:23 -0700 | [diff] [blame] | 4282 | |
Andrii Kulian | c2791664 | 2016-04-12 17:59:27 -0700 | [diff] [blame] | 4283 | // Dismiss docked stack. If task appeared to be in docked stack but is not resizable - |
| 4284 | // 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] | 4285 | |
Wale Ogunwale | 2b07da8 | 2017-11-08 14:52:40 -0800 | [diff] [blame] | 4286 | final ActivityStack dockedStack = |
| 4287 | task.getStack().getDisplay().getSplitScreenPrimaryStack(); |
Wale Ogunwale | 9dcf946 | 2017-09-19 15:13:01 -0700 | [diff] [blame] | 4288 | if (dockedStack != null) { |
Wale Ogunwale | a0f5b5e | 2017-10-11 09:37:23 -0700 | [diff] [blame] | 4289 | moveTasksToFullscreenStackLocked(dockedStack, actualStack == dockedStack); |
Wale Ogunwale | 9dcf946 | 2017-09-19 15:13:01 -0700 | [diff] [blame] | 4290 | } |
Wale Ogunwale | 2b07da8 | 2017-11-08 14:52:40 -0800 | [diff] [blame] | 4291 | return; |
| 4292 | } |
| 4293 | |
Wale Ogunwale | 30e441d | 2017-11-09 08:28:45 -0800 | [diff] [blame] | 4294 | final ActivityRecord topActivity = task.getTopActivity(); |
Wale Ogunwale | 2b07da8 | 2017-11-08 14:52:40 -0800 | [diff] [blame] | 4295 | if (topActivity != null && topActivity.isNonResizableOrForcedResizable() |
| 4296 | && !topActivity.noDisplay) { |
Andrii Kulian | 036e3ad | 2017-04-19 10:55:10 -0700 | [diff] [blame] | 4297 | final String packageName = topActivity.appInfo.packageName; |
| 4298 | final int reason = isSecondaryDisplayPreferred |
| 4299 | ? FORCED_RESIZEABLE_REASON_SECONDARY_DISPLAY |
| 4300 | : FORCED_RESIZEABLE_REASON_SPLIT_SCREEN; |
Yorke Lee | bd54c2a | 2016-10-25 13:49:23 -0700 | [diff] [blame] | 4301 | mService.mTaskChangeNotificationController.notifyActivityForcedResizable( |
Andrii Kulian | 036e3ad | 2017-04-19 10:55:10 -0700 | [diff] [blame] | 4302 | task.taskId, reason, packageName); |
Wale Ogunwale | b9b16a7 | 2016-01-27 12:24:44 -0800 | [diff] [blame] | 4303 | } |
Chong Zhang | b15758a | 2015-11-17 12:12:03 -0800 | [diff] [blame] | 4304 | } |
| 4305 | |
Jorim Jaggi | fe89d12 | 2015-12-22 16:28:44 +0100 | [diff] [blame] | 4306 | void activityRelaunchedLocked(IBinder token) { |
| 4307 | mWindowManager.notifyAppRelaunchingFinished(token); |
David Stevens | 9440dc8 | 2017-03-16 19:00:20 -0700 | [diff] [blame] | 4308 | final ActivityRecord r = ActivityRecord.isInStackLocked(token); |
| 4309 | if (r != null) { |
| 4310 | if (r.getStack().shouldSleepOrShutDownActivities()) { |
Wale Ogunwale | 3e99736 | 2016-09-06 10:37:56 -0700 | [diff] [blame] | 4311 | r.setSleeping(true, true); |
| 4312 | } |
| 4313 | } |
Jorim Jaggi | fe89d12 | 2015-12-22 16:28:44 +0100 | [diff] [blame] | 4314 | } |
| 4315 | |
| 4316 | void activityRelaunchingLocked(ActivityRecord r) { |
| 4317 | mWindowManager.notifyAppRelaunching(r.appToken); |
| 4318 | } |
| 4319 | |
Filip Gruszczynski | 77d9448 | 2015-12-11 13:59:52 -0800 | [diff] [blame] | 4320 | void logStackState() { |
| 4321 | mActivityMetricsLogger.logWindowState(); |
| 4322 | } |
| 4323 | |
Winson Chung | 5af42fc | 2017-03-24 17:11:33 -0700 | [diff] [blame] | 4324 | void scheduleUpdateMultiWindowMode(TaskRecord task) { |
Winson Chung | 8bca9e4 | 2017-04-16 15:59:43 -0700 | [diff] [blame] | 4325 | // If the stack is animating in a way where we will be forcing a multi-mode change at the |
| 4326 | // end, then ensure that we defer all in between multi-window mode changes |
| 4327 | if (task.getStack().deferScheduleMultiWindowModeChanged()) { |
| 4328 | return; |
| 4329 | } |
| 4330 | |
Wale Ogunwale | 22e2526 | 2016-02-01 10:32:02 -0800 | [diff] [blame] | 4331 | for (int i = task.mActivities.size() - 1; i >= 0; i--) { |
| 4332 | final ActivityRecord r = task.mActivities.get(i); |
| 4333 | if (r.app != null && r.app.thread != null) { |
| 4334 | mMultiWindowModeChangedActivities.add(r); |
| 4335 | } |
| 4336 | } |
| 4337 | |
| 4338 | if (!mHandler.hasMessages(REPORT_MULTI_WINDOW_MODE_CHANGED_MSG)) { |
| 4339 | mHandler.sendEmptyMessage(REPORT_MULTI_WINDOW_MODE_CHANGED_MSG); |
| 4340 | } |
| 4341 | } |
| 4342 | |
Winson Chung | 5af42fc | 2017-03-24 17:11:33 -0700 | [diff] [blame] | 4343 | void scheduleUpdatePictureInPictureModeIfNeeded(TaskRecord task, ActivityStack prevStack) { |
Andrii Kulian | 02b7a83 | 2016-10-06 23:11:56 -0700 | [diff] [blame] | 4344 | final ActivityStack stack = task.getStack(); |
Wale Ogunwale | 22e2526 | 2016-02-01 10:32:02 -0800 | [diff] [blame] | 4345 | if (prevStack == null || prevStack == stack |
Wale Ogunwale | 44f036f | 2017-09-29 05:09:09 -0700 | [diff] [blame] | 4346 | || (!prevStack.inPinnedWindowingMode() && !stack.inPinnedWindowingMode())) { |
Wale Ogunwale | 22e2526 | 2016-02-01 10:32:02 -0800 | [diff] [blame] | 4347 | return; |
| 4348 | } |
| 4349 | |
Bryce Lee | f3c6a47 | 2017-11-14 14:53:06 -0800 | [diff] [blame] | 4350 | scheduleUpdatePictureInPictureModeIfNeeded(task, stack.getOverrideBounds()); |
Winson Chung | 5af42fc | 2017-03-24 17:11:33 -0700 | [diff] [blame] | 4351 | } |
Wale Ogunwale | 22e2526 | 2016-02-01 10:32:02 -0800 | [diff] [blame] | 4352 | |
Winson Chung | ab76bbc | 2017-08-14 13:33:51 -0700 | [diff] [blame] | 4353 | void scheduleUpdatePictureInPictureModeIfNeeded(TaskRecord task, Rect targetStackBounds) { |
| 4354 | for (int i = task.mActivities.size() - 1; i >= 0; i--) { |
| 4355 | final ActivityRecord r = task.mActivities.get(i); |
| 4356 | if (r.app != null && r.app.thread != null) { |
| 4357 | mPipModeChangedActivities.add(r); |
Wale Ogunwale | eb76b76 | 2017-11-17 10:08:04 -0800 | [diff] [blame] | 4358 | // If we are scheduling pip change, then remove this activity from multi-window |
| 4359 | // change list as the processing of pip change will make sure multi-window changed |
| 4360 | // message is processed in the right order relative to pip changed. |
| 4361 | mMultiWindowModeChangedActivities.remove(r); |
Winson Chung | 5af42fc | 2017-03-24 17:11:33 -0700 | [diff] [blame] | 4362 | } |
Winson Chung | ab76bbc | 2017-08-14 13:33:51 -0700 | [diff] [blame] | 4363 | } |
| 4364 | mPipModeChangedTargetStackBounds = targetStackBounds; |
Winson Chung | 5af42fc | 2017-03-24 17:11:33 -0700 | [diff] [blame] | 4365 | |
Winson Chung | ab76bbc | 2017-08-14 13:33:51 -0700 | [diff] [blame] | 4366 | if (!mHandler.hasMessages(REPORT_PIP_MODE_CHANGED_MSG)) { |
| 4367 | mHandler.sendEmptyMessage(REPORT_PIP_MODE_CHANGED_MSG); |
| 4368 | } |
| 4369 | } |
| 4370 | |
| 4371 | void updatePictureInPictureMode(TaskRecord task, Rect targetStackBounds, boolean forceUpdate) { |
| 4372 | mHandler.removeMessages(REPORT_PIP_MODE_CHANGED_MSG); |
| 4373 | for (int i = task.mActivities.size() - 1; i >= 0; i--) { |
| 4374 | final ActivityRecord r = task.mActivities.get(i); |
| 4375 | if (r.app != null && r.app.thread != null) { |
| 4376 | r.updatePictureInPictureMode(targetStackBounds, forceUpdate); |
Winson Chung | 5af42fc | 2017-03-24 17:11:33 -0700 | [diff] [blame] | 4377 | } |
Wale Ogunwale | 22e2526 | 2016-02-01 10:32:02 -0800 | [diff] [blame] | 4378 | } |
| 4379 | } |
| 4380 | |
Tony Mak | 853304c | 2016-04-18 15:17:41 +0100 | [diff] [blame] | 4381 | void setDockedStackMinimized(boolean minimized) { |
| 4382 | mIsDockMinimized = minimized; |
Tony Mak | 853304c | 2016-04-18 15:17:41 +0100 | [diff] [blame] | 4383 | } |
| 4384 | |
chaviw | 59b9885 | 2017-06-13 12:05:44 -0700 | [diff] [blame] | 4385 | void wakeUp(String reason) { |
| 4386 | mPowerManager.wakeUp(SystemClock.uptimeMillis(), "android.server.am:TURN_ON:" + reason); |
| 4387 | } |
| 4388 | |
| 4389 | /** |
| 4390 | * Begin deferring resume to avoid duplicate resumes in one pass. |
| 4391 | */ |
| 4392 | private void beginDeferResume() { |
| 4393 | mDeferResumeCount++; |
| 4394 | } |
| 4395 | |
| 4396 | /** |
| 4397 | * End deferring resume and determine if resume can be called. |
| 4398 | */ |
| 4399 | private void endDeferResume() { |
| 4400 | mDeferResumeCount--; |
| 4401 | } |
| 4402 | |
| 4403 | /** |
| 4404 | * @return True if resume can be called. |
| 4405 | */ |
| 4406 | private boolean readyToResume() { |
| 4407 | return mDeferResumeCount == 0; |
| 4408 | } |
| 4409 | |
Craig Mautner | ce5f3cb | 2013-04-22 08:58:54 -0700 | [diff] [blame] | 4410 | private final class ActivityStackSupervisorHandler extends Handler { |
Craig Mautner | f333327 | 2013-04-22 10:55:53 -0700 | [diff] [blame] | 4411 | |
Craig Mautner | ce5f3cb | 2013-04-22 08:58:54 -0700 | [diff] [blame] | 4412 | public ActivityStackSupervisorHandler(Looper looper) { |
| 4413 | super(looper); |
| 4414 | } |
| 4415 | |
Winson Chung | 4dabf23 | 2017-01-25 13:25:22 -0800 | [diff] [blame] | 4416 | void activityIdleInternal(ActivityRecord r, boolean processPausingActivities) { |
Craig Mautner | f333327 | 2013-04-22 10:55:53 -0700 | [diff] [blame] | 4417 | synchronized (mService) { |
Winson Chung | 4dabf23 | 2017-01-25 13:25:22 -0800 | [diff] [blame] | 4418 | activityIdleInternalLocked(r != null ? r.appToken : null, true /* fromTimeout */, |
| 4419 | processPausingActivities, null); |
Craig Mautner | f333327 | 2013-04-22 10:55:53 -0700 | [diff] [blame] | 4420 | } |
Craig Mautner | 7ea5bd4 | 2013-07-05 15:27:08 -0700 | [diff] [blame] | 4421 | } |
| 4422 | |
Craig Mautner | ce5f3cb | 2013-04-22 08:58:54 -0700 | [diff] [blame] | 4423 | @Override |
| 4424 | public void handleMessage(Message msg) { |
| 4425 | switch (msg.what) { |
Wale Ogunwale | 22e2526 | 2016-02-01 10:32:02 -0800 | [diff] [blame] | 4426 | case REPORT_MULTI_WINDOW_MODE_CHANGED_MSG: { |
| 4427 | synchronized (mService) { |
| 4428 | for (int i = mMultiWindowModeChangedActivities.size() - 1; i >= 0; i--) { |
| 4429 | final ActivityRecord r = mMultiWindowModeChangedActivities.remove(i); |
Winson Chung | 5af42fc | 2017-03-24 17:11:33 -0700 | [diff] [blame] | 4430 | r.updateMultiWindowMode(); |
Wale Ogunwale | 22e2526 | 2016-02-01 10:32:02 -0800 | [diff] [blame] | 4431 | } |
| 4432 | } |
| 4433 | } break; |
| 4434 | case REPORT_PIP_MODE_CHANGED_MSG: { |
| 4435 | synchronized (mService) { |
| 4436 | for (int i = mPipModeChangedActivities.size() - 1; i >= 0; i--) { |
| 4437 | final ActivityRecord r = mPipModeChangedActivities.remove(i); |
Winson Chung | ab76bbc | 2017-08-14 13:33:51 -0700 | [diff] [blame] | 4438 | r.updatePictureInPictureMode(mPipModeChangedTargetStackBounds, |
| 4439 | false /* forceUpdate */); |
Wale Ogunwale | 22e2526 | 2016-02-01 10:32:02 -0800 | [diff] [blame] | 4440 | } |
| 4441 | } |
| 4442 | } break; |
Craig Mautner | f333327 | 2013-04-22 10:55:53 -0700 | [diff] [blame] | 4443 | case IDLE_TIMEOUT_MSG: { |
Wale Ogunwale | 0fc365c | 2015-05-25 19:35:42 -0700 | [diff] [blame] | 4444 | if (DEBUG_IDLE) Slog.d(TAG_IDLE, |
| 4445 | "handleMessage: IDLE_TIMEOUT_MSG: r=" + msg.obj); |
Craig Mautner | f333327 | 2013-04-22 10:55:53 -0700 | [diff] [blame] | 4446 | // We don't at this point know if the activity is fullscreen, |
| 4447 | // so we need to be conservative and assume it isn't. |
Winson Chung | 4dabf23 | 2017-01-25 13:25:22 -0800 | [diff] [blame] | 4448 | activityIdleInternal((ActivityRecord) msg.obj, |
| 4449 | true /* processPausingActivities */); |
Craig Mautner | f333327 | 2013-04-22 10:55:53 -0700 | [diff] [blame] | 4450 | } break; |
| 4451 | case IDLE_NOW_MSG: { |
Wale Ogunwale | 0fc365c | 2015-05-25 19:35:42 -0700 | [diff] [blame] | 4452 | 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] | 4453 | activityIdleInternal((ActivityRecord) msg.obj, |
| 4454 | false /* processPausingActivities */); |
Craig Mautner | f333327 | 2013-04-22 10:55:53 -0700 | [diff] [blame] | 4455 | } break; |
Craig Mautner | 05d2903 | 2013-05-03 13:40:13 -0700 | [diff] [blame] | 4456 | case RESUME_TOP_ACTIVITY_MSG: { |
| 4457 | synchronized (mService) { |
Wale Ogunwale | d046a01 | 2015-12-24 13:05:59 -0800 | [diff] [blame] | 4458 | resumeFocusedStackTopActivityLocked(); |
Craig Mautner | 05d2903 | 2013-05-03 13:40:13 -0700 | [diff] [blame] | 4459 | } |
| 4460 | } break; |
Craig Mautner | 0eea92c | 2013-05-16 13:35:39 -0700 | [diff] [blame] | 4461 | case SLEEP_TIMEOUT_MSG: { |
| 4462 | synchronized (mService) { |
Fyodor Kupolov | 9b80b94 | 2016-06-16 16:29:05 -0700 | [diff] [blame] | 4463 | if (mService.isSleepingOrShuttingDownLocked()) { |
Craig Mautner | 0eea92c | 2013-05-16 13:35:39 -0700 | [diff] [blame] | 4464 | Slog.w(TAG, "Sleep timeout! Sleeping now."); |
David Stevens | 9440dc8 | 2017-03-16 19:00:20 -0700 | [diff] [blame] | 4465 | checkReadyForSleepLocked(false /* allowDelay */); |
Craig Mautner | 0eea92c | 2013-05-16 13:35:39 -0700 | [diff] [blame] | 4466 | } |
| 4467 | } |
| 4468 | } break; |
Craig Mautner | 7ea5bd4 | 2013-07-05 15:27:08 -0700 | [diff] [blame] | 4469 | case LAUNCH_TIMEOUT_MSG: { |
Craig Mautner | 7ea5bd4 | 2013-07-05 15:27:08 -0700 | [diff] [blame] | 4470 | synchronized (mService) { |
| 4471 | if (mLaunchingActivity.isHeld()) { |
| 4472 | Slog.w(TAG, "Launch timeout has expired, giving up wake lock!"); |
| 4473 | if (VALIDATE_WAKE_LOCK_CALLER |
| 4474 | && Binder.getCallingUid() != Process.myUid()) { |
| 4475 | throw new IllegalStateException("Calling must be system uid"); |
| 4476 | } |
| 4477 | mLaunchingActivity.release(); |
| 4478 | } |
| 4479 | } |
| 4480 | } break; |
Craig Mautner | 4a1cb22 | 2013-12-04 16:14:06 -0800 | [diff] [blame] | 4481 | case HANDLE_DISPLAY_ADDED: { |
Wale Ogunwale | f16a281 | 2015-04-01 11:23:15 -0700 | [diff] [blame] | 4482 | handleDisplayAdded(msg.arg1); |
Craig Mautner | 4a1cb22 | 2013-12-04 16:14:06 -0800 | [diff] [blame] | 4483 | } break; |
| 4484 | case HANDLE_DISPLAY_CHANGED: { |
Wale Ogunwale | f16a281 | 2015-04-01 11:23:15 -0700 | [diff] [blame] | 4485 | handleDisplayChanged(msg.arg1); |
Craig Mautner | 4a1cb22 | 2013-12-04 16:14:06 -0800 | [diff] [blame] | 4486 | } break; |
| 4487 | case HANDLE_DISPLAY_REMOVED: { |
Wale Ogunwale | f16a281 | 2015-04-01 11:23:15 -0700 | [diff] [blame] | 4488 | handleDisplayRemoved(msg.arg1); |
Craig Mautner | 4a1cb22 | 2013-12-04 16:14:06 -0800 | [diff] [blame] | 4489 | } break; |
Craig Mautner | bb74246 | 2014-07-07 15:28:55 -0700 | [diff] [blame] | 4490 | case LAUNCH_TASK_BEHIND_COMPLETE: { |
| 4491 | synchronized (mService) { |
Wale Ogunwale | 7d70117 | 2015-03-11 15:36:30 -0700 | [diff] [blame] | 4492 | ActivityRecord r = ActivityRecord.forTokenLocked((IBinder) msg.obj); |
Craig Mautner | bb74246 | 2014-07-07 15:28:55 -0700 | [diff] [blame] | 4493 | if (r != null) { |
| 4494 | handleLaunchTaskBehindCompleteLocked(r); |
| 4495 | } |
| 4496 | } |
| 4497 | } break; |
Chong Zhang | c806d90 | 2015-11-30 09:44:27 -0800 | [diff] [blame] | 4498 | |
Craig Mautner | ce5f3cb | 2013-04-22 08:58:54 -0700 | [diff] [blame] | 4499 | } |
| 4500 | } |
| 4501 | } |
Craig Mautner | ed6649f | 2013-12-02 14:08:25 -0800 | [diff] [blame] | 4502 | |
Filip Gruszczynski | caae14e | 2015-12-16 14:40:04 -0800 | [diff] [blame] | 4503 | ActivityStack findStackBehind(ActivityStack stack) { |
| 4504 | // TODO(multi-display): We are only looking for stacks on the default display. |
Jorim Jaggi | fe76234 | 2016-10-13 14:33:27 +0200 | [diff] [blame] | 4505 | final ActivityDisplay display = mActivityDisplays.get(DEFAULT_DISPLAY); |
Filip Gruszczynski | caae14e | 2015-12-16 14:40:04 -0800 | [diff] [blame] | 4506 | if (display == null) { |
| 4507 | return null; |
| 4508 | } |
Wale Ogunwale | a0f5b5e | 2017-10-11 09:37:23 -0700 | [diff] [blame] | 4509 | for (int i = display.getChildCount() - 1; i >= 0; i--) { |
| 4510 | if (display.getChildAt(i) == stack && i > 0) { |
| 4511 | return display.getChildAt(i - 1); |
Filip Gruszczynski | caae14e | 2015-12-16 14:40:04 -0800 | [diff] [blame] | 4512 | } |
| 4513 | } |
| 4514 | throw new IllegalStateException("Failed to find a stack behind stack=" + stack |
Wale Ogunwale | a0f5b5e | 2017-10-11 09:37:23 -0700 | [diff] [blame] | 4515 | + " in=" + display); |
Filip Gruszczynski | caae14e | 2015-12-16 14:40:04 -0800 | [diff] [blame] | 4516 | } |
Jorim Jaggi | 0b46f3c | 2016-03-14 12:21:37 +0100 | [diff] [blame] | 4517 | |
Jorim Jaggi | c69bd22 | 2016-03-15 14:38:37 +0100 | [diff] [blame] | 4518 | /** |
| 4519 | * Puts a task into resizing mode during the next app transition. |
| 4520 | * |
Wale Ogunwale | e1fe7fa2 | 2016-12-15 18:27:00 -0800 | [diff] [blame] | 4521 | * @param task The task to put into resizing mode |
Jorim Jaggi | c69bd22 | 2016-03-15 14:38:37 +0100 | [diff] [blame] | 4522 | */ |
Bryce Lee | d3624e1 | 2017-11-30 08:51:45 -0800 | [diff] [blame] | 4523 | void setResizingDuringAnimation(TaskRecord task) { |
Wale Ogunwale | e1fe7fa2 | 2016-12-15 18:27:00 -0800 | [diff] [blame] | 4524 | mResizingTasksDuringAnimation.add(task.taskId); |
| 4525 | task.setTaskDockedResizing(true); |
Jorim Jaggi | c69bd22 | 2016-03-15 14:38:37 +0100 | [diff] [blame] | 4526 | } |
| 4527 | |
Jorim Jaggi | 4d8d32c | 2018-01-19 15:57:41 +0100 | [diff] [blame] | 4528 | int startActivityFromRecents(int callingPid, int callingUid, int taskId, |
| 4529 | SafeActivityOptions options) { |
Jorim Jaggi | 0b46f3c | 2016-03-14 12:21:37 +0100 | [diff] [blame] | 4530 | final TaskRecord task; |
Jorim Jaggi | 0b46f3c | 2016-03-14 12:21:37 +0100 | [diff] [blame] | 4531 | final String callingPackage; |
| 4532 | final Intent intent; |
| 4533 | final int userId; |
Wale Ogunwale | 0568aed | 2017-09-08 13:29:37 -0700 | [diff] [blame] | 4534 | int activityType = ACTIVITY_TYPE_UNDEFINED; |
| 4535 | int windowingMode = WINDOWING_MODE_UNDEFINED; |
Jorim Jaggi | 4d8d32c | 2018-01-19 15:57:41 +0100 | [diff] [blame] | 4536 | final ActivityOptions activityOptions = options != null |
| 4537 | ? options.getOptions(this) |
| 4538 | : null; |
Wale Ogunwale | 0568aed | 2017-09-08 13:29:37 -0700 | [diff] [blame] | 4539 | if (activityOptions != null) { |
| 4540 | activityType = activityOptions.getLaunchActivityType(); |
| 4541 | windowingMode = activityOptions.getLaunchWindowingMode(); |
| 4542 | } |
| 4543 | if (activityType == ACTIVITY_TYPE_HOME || activityType == ACTIVITY_TYPE_RECENTS) { |
Wale Ogunwale | ab5de37 | 2017-10-18 06:46:31 -0700 | [diff] [blame] | 4544 | throw new IllegalArgumentException("startActivityFromRecents: Task " |
Matthew Ng | ae1ff4f | 2016-11-10 15:49:14 -0800 | [diff] [blame] | 4545 | + taskId + " can't be launch in the home/recents stack."); |
Jorim Jaggi | 0b46f3c | 2016-03-14 12:21:37 +0100 | [diff] [blame] | 4546 | } |
Jorim Jaggi | 3c800a4 | 2016-04-15 19:44:50 -0700 | [diff] [blame] | 4547 | |
Matthew Ng | 606dd80 | 2017-06-05 14:06:32 -0700 | [diff] [blame] | 4548 | mWindowManager.deferSurfaceLayout(); |
| 4549 | try { |
Wale Ogunwale | 0568aed | 2017-09-08 13:29:37 -0700 | [diff] [blame] | 4550 | if (windowingMode == WINDOWING_MODE_SPLIT_SCREEN_PRIMARY) { |
Matthew Ng | 606dd80 | 2017-06-05 14:06:32 -0700 | [diff] [blame] | 4551 | mWindowManager.setDockedStackCreateState( |
Matthew Ng | bf15587 | 2017-10-27 15:24:39 -0700 | [diff] [blame] | 4552 | activityOptions.getSplitScreenCreateMode(), null /* initialBounds */); |
Jorim Jaggi | 3c800a4 | 2016-04-15 19:44:50 -0700 | [diff] [blame] | 4553 | |
Matthew Ng | 606dd80 | 2017-06-05 14:06:32 -0700 | [diff] [blame] | 4554 | // Defer updating the stack in which recents is until the app transition is done, to |
| 4555 | // not run into issues where we still need to draw the task in recents but the |
| 4556 | // docked stack is already created. |
Wale Ogunwale | 6827856 | 2017-09-23 17:13:55 -0700 | [diff] [blame] | 4557 | deferUpdateBounds(ACTIVITY_TYPE_RECENTS); |
Matthew Ng | 606dd80 | 2017-06-05 14:06:32 -0700 | [diff] [blame] | 4558 | mWindowManager.prepareAppTransition(TRANSIT_DOCK_TASK_FROM_RECENTS, false); |
Jorim Jaggi | 0b46f3c | 2016-03-14 12:21:37 +0100 | [diff] [blame] | 4559 | } |
Jorim Jaggi | 0b46f3c | 2016-03-14 12:21:37 +0100 | [diff] [blame] | 4560 | |
Matthew Ng | 606dd80 | 2017-06-05 14:06:32 -0700 | [diff] [blame] | 4561 | task = anyTaskForIdLocked(taskId, MATCH_TASK_IN_STACKS_OR_RECENT_TASKS_AND_RESTORE, |
Wale Ogunwale | ab5de37 | 2017-10-18 06:46:31 -0700 | [diff] [blame] | 4562 | activityOptions, ON_TOP); |
Matthew Ng | 606dd80 | 2017-06-05 14:06:32 -0700 | [diff] [blame] | 4563 | if (task == null) { |
Wale Ogunwale | 6827856 | 2017-09-23 17:13:55 -0700 | [diff] [blame] | 4564 | continueUpdateBounds(ACTIVITY_TYPE_RECENTS); |
Matthew Ng | 606dd80 | 2017-06-05 14:06:32 -0700 | [diff] [blame] | 4565 | mWindowManager.executeAppTransition(); |
| 4566 | throw new IllegalArgumentException( |
Wale Ogunwale | ab5de37 | 2017-10-18 06:46:31 -0700 | [diff] [blame] | 4567 | "startActivityFromRecents: Task " + taskId + " not found."); |
Matthew Ng | 606dd80 | 2017-06-05 14:06:32 -0700 | [diff] [blame] | 4568 | } |
| 4569 | |
Wale Ogunwale | abc44d0 | 2017-11-08 08:58:03 -0800 | [diff] [blame] | 4570 | if (windowingMode != WINDOWING_MODE_SPLIT_SCREEN_PRIMARY) { |
| 4571 | // We always want to return to the home activity instead of the recents activity |
| 4572 | // from whatever is started from the recents activity, so move the home stack |
| 4573 | // forward. |
| 4574 | moveHomeStackToFront("startActivityFromRecents"); |
| 4575 | } |
Wale Ogunwale | 66e1685 | 2017-10-19 13:35:52 -0700 | [diff] [blame] | 4576 | |
Matthew Ng | 606dd80 | 2017-06-05 14:06:32 -0700 | [diff] [blame] | 4577 | // If the user must confirm credentials (e.g. when first launching a work app and the |
| 4578 | // Work Challenge is present) let startActivityInPackage handle the intercepting. |
| 4579 | if (!mService.mUserController.shouldConfirmCredentials(task.userId) |
| 4580 | && task.getRootActivity() != null) { |
Bryce Lee | 28d8042 | 2017-07-21 13:25:13 -0700 | [diff] [blame] | 4581 | final ActivityRecord targetActivity = task.getTopActivity(); |
| 4582 | |
Bryce Lee | d3624e1 | 2017-11-30 08:51:45 -0800 | [diff] [blame] | 4583 | sendPowerHintForLaunchStartIfNeeded(true /* forceSend */, targetActivity); |
Matthew Ng | 606dd80 | 2017-06-05 14:06:32 -0700 | [diff] [blame] | 4584 | mActivityMetricsLogger.notifyActivityLaunching(); |
Jorim Jaggi | 172e99f | 2017-10-20 14:33:18 +0200 | [diff] [blame] | 4585 | try { |
Jorim Jaggi | 4d8d32c | 2018-01-19 15:57:41 +0100 | [diff] [blame] | 4586 | mService.moveTaskToFrontLocked(task.taskId, 0, options, |
Jorim Jaggi | 172e99f | 2017-10-20 14:33:18 +0200 | [diff] [blame] | 4587 | true /* fromRecents */); |
| 4588 | } finally { |
| 4589 | mActivityMetricsLogger.notifyActivityLaunched(START_TASK_TO_FRONT, |
| 4590 | targetActivity); |
| 4591 | } |
Matthew Ng | 606dd80 | 2017-06-05 14:06:32 -0700 | [diff] [blame] | 4592 | |
| 4593 | // If we are launching the task in the docked stack, put it into resizing mode so |
| 4594 | // the window renders full-screen with the background filling the void. Also only |
| 4595 | // call this at the end to make sure that tasks exists on the window manager side. |
Wale Ogunwale | 0568aed | 2017-09-08 13:29:37 -0700 | [diff] [blame] | 4596 | if (windowingMode == WINDOWING_MODE_SPLIT_SCREEN_PRIMARY) { |
Matthew Ng | 606dd80 | 2017-06-05 14:06:32 -0700 | [diff] [blame] | 4597 | setResizingDuringAnimation(task); |
| 4598 | } |
| 4599 | |
Bryce Lee | d3624e1 | 2017-11-30 08:51:45 -0800 | [diff] [blame] | 4600 | mService.getActivityStartController().postStartActivityProcessingForLastStarter( |
| 4601 | task.getTopActivity(), ActivityManager.START_TASK_TO_FRONT, |
| 4602 | task.getStack()); |
Matthew Ng | 606dd80 | 2017-06-05 14:06:32 -0700 | [diff] [blame] | 4603 | return ActivityManager.START_TASK_TO_FRONT; |
| 4604 | } |
Matthew Ng | 606dd80 | 2017-06-05 14:06:32 -0700 | [diff] [blame] | 4605 | callingPackage = task.mCallingPackage; |
| 4606 | intent = task.intent; |
| 4607 | intent.addFlags(Intent.FLAG_ACTIVITY_LAUNCHED_FROM_HISTORY); |
| 4608 | userId = task.userId; |
Jorim Jaggi | 4d8d32c | 2018-01-19 15:57:41 +0100 | [diff] [blame] | 4609 | int result = mService.getActivityStartController().startActivityInPackage( |
| 4610 | task.mCallingUid, callingPid, callingUid, callingPackage, intent, null, null, |
| 4611 | null, 0, 0, options, userId, task, |
Bryce Lee | d3624e1 | 2017-11-30 08:51:45 -0800 | [diff] [blame] | 4612 | "startActivityFromRecents"); |
Wale Ogunwale | 0568aed | 2017-09-08 13:29:37 -0700 | [diff] [blame] | 4613 | if (windowingMode == WINDOWING_MODE_SPLIT_SCREEN_PRIMARY) { |
Wale Ogunwale | e1fe7fa2 | 2016-12-15 18:27:00 -0800 | [diff] [blame] | 4614 | setResizingDuringAnimation(task); |
Jorim Jaggi | 0b46f3c | 2016-03-14 12:21:37 +0100 | [diff] [blame] | 4615 | } |
Matthew Ng | 606dd80 | 2017-06-05 14:06:32 -0700 | [diff] [blame] | 4616 | return result; |
| 4617 | } finally { |
| 4618 | mWindowManager.continueSurfaceLayout(); |
Jorim Jaggi | 0b46f3c | 2016-03-14 12:21:37 +0100 | [diff] [blame] | 4619 | } |
Jorim Jaggi | 0b46f3c | 2016-03-14 12:21:37 +0100 | [diff] [blame] | 4620 | } |
Amith Yamasani | e8222e5 | 2016-04-08 15:28:47 -0700 | [diff] [blame] | 4621 | |
| 4622 | /** |
| 4623 | * @return a list of activities which are the top ones in each visible stack. The first |
| 4624 | * entry will be the focused activity. |
| 4625 | */ |
Andrii Kulian | 0864bbb | 2017-02-16 15:45:58 -0800 | [diff] [blame] | 4626 | List<IBinder> getTopVisibleActivities() { |
| 4627 | final ArrayList<IBinder> topActivityTokens = new ArrayList<>(); |
| 4628 | // Traverse all displays. |
Robert Carr | 22374c0 | 2017-02-21 13:01:47 -0800 | [diff] [blame] | 4629 | for (int i = mActivityDisplays.size() - 1; i >= 0; i--) { |
Andrii Kulian | 0864bbb | 2017-02-16 15:45:58 -0800 | [diff] [blame] | 4630 | final ActivityDisplay display = mActivityDisplays.valueAt(i); |
| 4631 | // Traverse all stacks on a display. |
Wale Ogunwale | a0f5b5e | 2017-10-11 09:37:23 -0700 | [diff] [blame] | 4632 | for (int j = display.getChildCount() - 1; j >= 0; --j) { |
| 4633 | final ActivityStack stack = display.getChildAt(j); |
Andrii Kulian | 0864bbb | 2017-02-16 15:45:58 -0800 | [diff] [blame] | 4634 | // 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] | 4635 | if (stack.shouldBeVisible(null /* starting */)) { |
Wale Ogunwale | 30e441d | 2017-11-09 08:28:45 -0800 | [diff] [blame] | 4636 | final ActivityRecord top = stack.getTopActivity(); |
Andrii Kulian | 0864bbb | 2017-02-16 15:45:58 -0800 | [diff] [blame] | 4637 | if (top != null) { |
| 4638 | if (stack == mFocusedStack) { |
| 4639 | topActivityTokens.add(0, top.appToken); |
| 4640 | } else { |
| 4641 | topActivityTokens.add(top.appToken); |
| 4642 | } |
Amith Yamasani | e8222e5 | 2016-04-08 15:28:47 -0700 | [diff] [blame] | 4643 | } |
| 4644 | } |
| 4645 | } |
| 4646 | } |
| 4647 | return topActivityTokens; |
| 4648 | } |
Bryce Lee | 4a19438 | 2017-04-04 14:32:48 -0700 | [diff] [blame] | 4649 | |
| 4650 | /** |
| 4651 | * Internal container to store a match qualifier alongside a WaitResult. |
| 4652 | */ |
| 4653 | static class WaitInfo { |
| 4654 | private final ComponentName mTargetComponent; |
| 4655 | private final WaitResult mResult; |
| 4656 | |
| 4657 | public WaitInfo(ComponentName targetComponent, WaitResult result) { |
| 4658 | this.mTargetComponent = targetComponent; |
| 4659 | this.mResult = result; |
| 4660 | } |
| 4661 | |
Wale Ogunwale | 3270f17 | 2017-04-26 07:29:42 -0700 | [diff] [blame] | 4662 | public boolean matches(ComponentName targetComponent) { |
| 4663 | return mTargetComponent == null || mTargetComponent.equals(targetComponent); |
Bryce Lee | 4a19438 | 2017-04-04 14:32:48 -0700 | [diff] [blame] | 4664 | } |
| 4665 | |
| 4666 | public WaitResult getResult() { |
| 4667 | return mResult; |
| 4668 | } |
| 4669 | |
| 4670 | public ComponentName getComponent() { |
| 4671 | return mTargetComponent; |
| 4672 | } |
| 4673 | |
| 4674 | public void dump(PrintWriter pw, String prefix) { |
| 4675 | pw.println(prefix + "WaitInfo:"); |
| 4676 | pw.println(prefix + " mTargetComponent=" + mTargetComponent); |
| 4677 | pw.println(prefix + " mResult="); |
| 4678 | mResult.dump(pw, prefix); |
| 4679 | } |
| 4680 | } |
David Stevens | 9440dc8 | 2017-03-16 19:00:20 -0700 | [diff] [blame] | 4681 | |
| 4682 | private final class SleepTokenImpl extends SleepToken { |
| 4683 | private final String mTag; |
| 4684 | private final long mAcquireTime; |
| 4685 | private final int mDisplayId; |
| 4686 | |
| 4687 | public SleepTokenImpl(String tag, int displayId) { |
| 4688 | mTag = tag; |
| 4689 | mDisplayId = displayId; |
| 4690 | mAcquireTime = SystemClock.uptimeMillis(); |
| 4691 | } |
| 4692 | |
| 4693 | @Override |
| 4694 | public void release() { |
| 4695 | synchronized (mService) { |
| 4696 | removeSleepTokenLocked(this); |
| 4697 | } |
| 4698 | } |
| 4699 | |
| 4700 | @Override |
| 4701 | public String toString() { |
| 4702 | return "{\"" + mTag + "\", display " + mDisplayId |
| 4703 | + ", acquire at " + TimeUtils.formatUptime(mAcquireTime) + "}"; |
| 4704 | } |
| 4705 | } |
| 4706 | |
Craig Mautner | 2708430 | 2013-03-25 08:05:25 -0700 | [diff] [blame] | 4707 | } |