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 { |
Bryce Lee | f52974c | 2018-02-14 15:12:01 -0800 | [diff] [blame] | 1456 | lifecycleItem = PauseActivityItem.obtain() |
| 1457 | .setDescription(r.getLifecycleDescription("realStartActivityLocked")); |
Andrii Kulian | 88e05cb | 2017-12-05 17:21:10 -0800 | [diff] [blame] | 1458 | } |
| 1459 | clientTransaction.setLifecycleStateRequest(lifecycleItem); |
| 1460 | |
| 1461 | // Schedule transaction. |
| 1462 | mService.mLifecycleManager.scheduleTransaction(clientTransaction); |
| 1463 | |
Craig Mautner | 2420ead | 2013-04-01 17:13:20 -0700 | [diff] [blame] | 1464 | |
chaviw | 59b9885 | 2017-06-13 12:05:44 -0700 | [diff] [blame] | 1465 | if ((app.info.privateFlags & ApplicationInfo.PRIVATE_FLAG_CANT_SAVE_STATE) != 0) { |
| 1466 | // This may be a heavy-weight process! Note that the package |
| 1467 | // manager will ensure that only activity can run in the main |
| 1468 | // process of the .apk, which is the only thing that will be |
| 1469 | // considered heavy-weight. |
| 1470 | if (app.processName.equals(app.info.packageName)) { |
| 1471 | if (mService.mHeavyWeightProcess != null |
| 1472 | && mService.mHeavyWeightProcess != app) { |
| 1473 | Slog.w(TAG, "Starting new heavy weight process " + app |
| 1474 | + " when already running " |
| 1475 | + mService.mHeavyWeightProcess); |
| 1476 | } |
| 1477 | mService.mHeavyWeightProcess = app; |
| 1478 | Message msg = mService.mHandler.obtainMessage( |
| 1479 | ActivityManagerService.POST_HEAVY_NOTIFICATION_MSG); |
| 1480 | msg.obj = r; |
| 1481 | mService.mHandler.sendMessage(msg); |
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 | } |
Craig Mautner | 2420ead | 2013-04-01 17:13:20 -0700 | [diff] [blame] | 1484 | |
chaviw | 59b9885 | 2017-06-13 12:05:44 -0700 | [diff] [blame] | 1485 | } catch (RemoteException e) { |
| 1486 | if (r.launchFailed) { |
| 1487 | // This is the second time we failed -- finish activity |
| 1488 | // and give up. |
| 1489 | Slog.e(TAG, "Second failure launching " |
| 1490 | + r.intent.getComponent().flattenToShortString() |
| 1491 | + ", giving up", e); |
| 1492 | mService.appDiedLocked(app); |
| 1493 | stack.requestFinishActivityLocked(r.appToken, Activity.RESULT_CANCELED, null, |
| 1494 | "2nd-crash", false); |
| 1495 | return false; |
| 1496 | } |
Craig Mautner | 2420ead | 2013-04-01 17:13:20 -0700 | [diff] [blame] | 1497 | |
chaviw | 59b9885 | 2017-06-13 12:05:44 -0700 | [diff] [blame] | 1498 | // This is the first time we failed -- restart process and |
| 1499 | // retry. |
| 1500 | r.launchFailed = true; |
| 1501 | app.activities.remove(r); |
| 1502 | throw e; |
| 1503 | } |
| 1504 | } finally { |
| 1505 | endDeferResume(); |
Craig Mautner | 2420ead | 2013-04-01 17:13:20 -0700 | [diff] [blame] | 1506 | } |
| 1507 | |
| 1508 | r.launchFailed = false; |
| 1509 | if (stack.updateLRUListLocked(r)) { |
Filip Gruszczynski | 49b80af | 2015-09-24 09:04:26 -0700 | [diff] [blame] | 1510 | Slog.w(TAG, "Activity " + r + " being launched, but already in LRU list"); |
Craig Mautner | 2420ead | 2013-04-01 17:13:20 -0700 | [diff] [blame] | 1511 | } |
| 1512 | |
Andrii Kulian | b372da6 | 2018-01-18 10:46:24 -0800 | [diff] [blame] | 1513 | // TODO(lifecycler): Resume or pause requests are done as part of launch transaction, |
| 1514 | // so updating the state should be done accordingly. |
chaviw | 59b9885 | 2017-06-13 12:05:44 -0700 | [diff] [blame] | 1515 | if (andResume && readyToResume()) { |
Craig Mautner | 2420ead | 2013-04-01 17:13:20 -0700 | [diff] [blame] | 1516 | // As part of the process of launching, ActivityThread also performs |
| 1517 | // a resume. |
| 1518 | stack.minimalResumeActivityLocked(r); |
| 1519 | } else { |
Wale Ogunwale | d046a01 | 2015-12-24 13:05:59 -0800 | [diff] [blame] | 1520 | // 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] | 1521 | // 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] | 1522 | // current icicle and other state. |
Wale Ogunwale | 0fc365c | 2015-05-25 19:35:42 -0700 | [diff] [blame] | 1523 | if (DEBUG_STATES) Slog.v(TAG_STATES, |
Wale Ogunwale | d046a01 | 2015-12-24 13:05:59 -0800 | [diff] [blame] | 1524 | "Moving to PAUSED: " + r + " (starting in paused state)"); |
| 1525 | r.state = PAUSED; |
Craig Mautner | 2420ead | 2013-04-01 17:13:20 -0700 | [diff] [blame] | 1526 | } |
| 1527 | |
| 1528 | // Launch the new version setup screen if needed. We do this -after- |
| 1529 | // launching the initial activity (that is, home), so that it can have |
| 1530 | // a chance to initialize itself while in the background, making the |
| 1531 | // switch back to it faster and look better. |
Wale Ogunwale | 1e60e0c | 2015-10-28 13:36:10 -0700 | [diff] [blame] | 1532 | if (isFocusedStack(stack)) { |
Bryce Lee | d3624e1 | 2017-11-30 08:51:45 -0800 | [diff] [blame] | 1533 | mService.getActivityStartController().startSetupActivity(); |
Craig Mautner | 2420ead | 2013-04-01 17:13:20 -0700 | [diff] [blame] | 1534 | } |
| 1535 | |
Dianne Hackborn | 465fa39 | 2014-09-14 14:21:18 -0700 | [diff] [blame] | 1536 | // Update any services we are bound to that might care about whether |
| 1537 | // their client may have activities. |
Wale Ogunwale | d6ac762 | 2016-05-26 09:02:25 -0700 | [diff] [blame] | 1538 | if (r.app != null) { |
| 1539 | mService.mServices.updateServiceConnectionActivitiesLocked(r.app); |
| 1540 | } |
Dianne Hackborn | 465fa39 | 2014-09-14 14:21:18 -0700 | [diff] [blame] | 1541 | |
Craig Mautner | 2420ead | 2013-04-01 17:13:20 -0700 | [diff] [blame] | 1542 | return true; |
| 1543 | } |
| 1544 | |
Sudheer Shanka | fab200f | 2017-05-17 20:41:53 -0700 | [diff] [blame] | 1545 | private void logIfTransactionTooLarge(Intent intent, Bundle icicle) { |
| 1546 | int extrasSize = 0; |
| 1547 | if (intent != null) { |
| 1548 | final Bundle extras = intent.getExtras(); |
| 1549 | if (extras != null) { |
| 1550 | extrasSize = extras.getSize(); |
| 1551 | } |
| 1552 | } |
| 1553 | int icicleSize = (icicle == null ? 0 : icicle.getSize()); |
| 1554 | if (extrasSize + icicleSize > 200000) { |
| 1555 | Slog.e(TAG, "Transaction too large, intent: " + intent + ", extras size: " + extrasSize |
| 1556 | + ", icicle size: " + icicleSize); |
| 1557 | } |
| 1558 | } |
| 1559 | |
Craig Mautner | e79d4268 | 2013-04-01 19:01:53 -0700 | [diff] [blame] | 1560 | void startSpecificActivityLocked(ActivityRecord r, |
George Mount | 2c92c97 | 2014-03-20 09:38:23 -0700 | [diff] [blame] | 1561 | boolean andResume, boolean checkConfig) { |
Craig Mautner | e79d4268 | 2013-04-01 19:01:53 -0700 | [diff] [blame] | 1562 | // Is this activity's application already running? |
| 1563 | ProcessRecord app = mService.getProcessRecordLocked(r.processName, |
Dianne Hackborn | 3bc8f78d | 2013-09-19 13:34:35 -0700 | [diff] [blame] | 1564 | r.info.applicationInfo.uid, true); |
Craig Mautner | e79d4268 | 2013-04-01 19:01:53 -0700 | [diff] [blame] | 1565 | |
Andrii Kulian | 02b7a83 | 2016-10-06 23:11:56 -0700 | [diff] [blame] | 1566 | r.getStack().setLaunchTime(r); |
Craig Mautner | e79d4268 | 2013-04-01 19:01:53 -0700 | [diff] [blame] | 1567 | |
| 1568 | if (app != null && app.thread != null) { |
| 1569 | try { |
Dianne Hackborn | 237cefb | 2013-10-22 18:45:27 -0700 | [diff] [blame] | 1570 | if ((r.info.flags&ActivityInfo.FLAG_MULTIPROCESS) == 0 |
| 1571 | || !"android".equals(r.info.packageName)) { |
| 1572 | // Don't add this if it is a platform component that is marked |
| 1573 | // to run in multiple processes, because this is actually |
| 1574 | // part of the framework so doesn't make sense to track as a |
| 1575 | // separate apk in the process. |
Dianne Hackborn | f7097a5 | 2014-05-13 09:56:14 -0700 | [diff] [blame] | 1576 | app.addPackage(r.info.packageName, r.info.applicationInfo.versionCode, |
| 1577 | mService.mProcessStats); |
Dianne Hackborn | 237cefb | 2013-10-22 18:45:27 -0700 | [diff] [blame] | 1578 | } |
George Mount | 2c92c97 | 2014-03-20 09:38:23 -0700 | [diff] [blame] | 1579 | realStartActivityLocked(r, app, andResume, checkConfig); |
Craig Mautner | e79d4268 | 2013-04-01 19:01:53 -0700 | [diff] [blame] | 1580 | return; |
| 1581 | } catch (RemoteException e) { |
| 1582 | Slog.w(TAG, "Exception when starting activity " |
| 1583 | + r.intent.getComponent().flattenToShortString(), e); |
| 1584 | } |
| 1585 | |
| 1586 | // If a dead object exception was thrown -- fall through to |
| 1587 | // restart the application. |
| 1588 | } |
| 1589 | |
| 1590 | mService.startProcessLocked(r.processName, r.info.applicationInfo, true, 0, |
Dianne Hackborn | 3bc8f78d | 2013-09-19 13:34:35 -0700 | [diff] [blame] | 1591 | "activity", r.intent.getComponent(), false, false, true); |
Craig Mautner | e79d4268 | 2013-04-01 19:01:53 -0700 | [diff] [blame] | 1592 | } |
| 1593 | |
Bryce Lee | d3624e1 | 2017-11-30 08:51:45 -0800 | [diff] [blame] | 1594 | void sendPowerHintForLaunchStartIfNeeded(boolean forceSend, ActivityRecord targetActivity) { |
| 1595 | boolean sendHint = forceSend; |
| 1596 | |
| 1597 | if (!sendHint) { |
| 1598 | // If not forced, send power hint when the activity's process is different than the |
| 1599 | // current resumed activity. |
| 1600 | final ActivityRecord resumedActivity = getResumedActivityLocked(); |
| 1601 | sendHint = resumedActivity == null |
| 1602 | || resumedActivity.app == null |
| 1603 | || !resumedActivity.app.equals(targetActivity.app); |
| 1604 | } |
| 1605 | |
| 1606 | if (sendHint && mService.mLocalPowerManager != null) { |
| 1607 | mService.mLocalPowerManager.powerHint(PowerHint.LAUNCH, 1); |
| 1608 | mPowerHintSent = true; |
| 1609 | } |
| 1610 | } |
| 1611 | |
| 1612 | void sendPowerHintForLaunchEndIfNeeded() { |
| 1613 | // Trigger launch power hint if activity is launched |
| 1614 | if (mPowerHintSent && mService.mLocalPowerManager != null) { |
| 1615 | mService.mLocalPowerManager.powerHint(PowerHint.LAUNCH, 0); |
| 1616 | mPowerHintSent = false; |
| 1617 | } |
| 1618 | } |
| 1619 | |
Filip Gruszczynski | 07a0e49 | 2015-12-17 14:16:38 -0800 | [diff] [blame] | 1620 | boolean checkStartAnyActivityPermission(Intent intent, ActivityInfo aInfo, |
Filip Gruszczynski | dc39490 | 2015-12-14 10:20:22 -0800 | [diff] [blame] | 1621 | String resultWho, int requestCode, int callingPid, int callingUid, |
| 1622 | String callingPackage, boolean ignoreTargetSecurity, ProcessRecord callerApp, |
Jorim Jaggi | 4d8d32c | 2018-01-19 15:57:41 +0100 | [diff] [blame] | 1623 | ActivityRecord resultRecord, ActivityStack resultStack) { |
Filip Gruszczynski | dc39490 | 2015-12-14 10:20:22 -0800 | [diff] [blame] | 1624 | final int startAnyPerm = mService.checkPermission(START_ANY_ACTIVITY, callingPid, |
| 1625 | callingUid); |
Andrii Kulian | fb1bf69 | 2017-01-17 11:17:34 -0800 | [diff] [blame] | 1626 | if (startAnyPerm == PERMISSION_GRANTED) { |
Filip Gruszczynski | dc39490 | 2015-12-14 10:20:22 -0800 | [diff] [blame] | 1627 | return true; |
| 1628 | } |
| 1629 | final int componentRestriction = getComponentRestrictionForCallingPackage( |
| 1630 | aInfo, callingPackage, callingPid, callingUid, ignoreTargetSecurity); |
| 1631 | final int actionRestriction = getActionRestrictionForCallingPackage( |
| 1632 | intent.getAction(), callingPackage, callingPid, callingUid); |
| 1633 | if (componentRestriction == ACTIVITY_RESTRICTION_PERMISSION |
| 1634 | || actionRestriction == ACTIVITY_RESTRICTION_PERMISSION) { |
| 1635 | if (resultRecord != null) { |
| 1636 | resultStack.sendActivityResultLocked(-1, |
| 1637 | resultRecord, resultWho, requestCode, |
| 1638 | Activity.RESULT_CANCELED, null); |
| 1639 | } |
| 1640 | final String msg; |
| 1641 | if (actionRestriction == ACTIVITY_RESTRICTION_PERMISSION) { |
| 1642 | msg = "Permission Denial: starting " + intent.toString() |
| 1643 | + " from " + callerApp + " (pid=" + callingPid |
| 1644 | + ", uid=" + callingUid + ")" + " with revoked permission " |
| 1645 | + ACTION_TO_RUNTIME_PERMISSION.get(intent.getAction()); |
| 1646 | } else if (!aInfo.exported) { |
| 1647 | msg = "Permission Denial: starting " + intent.toString() |
| 1648 | + " from " + callerApp + " (pid=" + callingPid |
| 1649 | + ", uid=" + callingUid + ")" |
| 1650 | + " not exported from uid " + aInfo.applicationInfo.uid; |
| 1651 | } else { |
| 1652 | msg = "Permission Denial: starting " + intent.toString() |
| 1653 | + " from " + callerApp + " (pid=" + callingPid |
| 1654 | + ", uid=" + callingUid + ")" |
| 1655 | + " requires " + aInfo.permission; |
| 1656 | } |
| 1657 | Slog.w(TAG, msg); |
| 1658 | throw new SecurityException(msg); |
| 1659 | } |
| 1660 | |
| 1661 | if (actionRestriction == ACTIVITY_RESTRICTION_APPOP) { |
| 1662 | final String message = "Appop Denial: starting " + intent.toString() |
| 1663 | + " from " + callerApp + " (pid=" + callingPid |
| 1664 | + ", uid=" + callingUid + ")" |
| 1665 | + " requires " + AppOpsManager.permissionToOp( |
| 1666 | ACTION_TO_RUNTIME_PERMISSION.get(intent.getAction())); |
| 1667 | Slog.w(TAG, message); |
| 1668 | return false; |
| 1669 | } else if (componentRestriction == ACTIVITY_RESTRICTION_APPOP) { |
| 1670 | final String message = "Appop Denial: starting " + intent.toString() |
| 1671 | + " from " + callerApp + " (pid=" + callingPid |
| 1672 | + ", uid=" + callingUid + ")" |
| 1673 | + " requires appop " + AppOpsManager.permissionToOp(aInfo.permission); |
| 1674 | Slog.w(TAG, message); |
| 1675 | return false; |
| 1676 | } |
Jorim Jaggi | 2adba07 | 2016-03-03 13:43:39 +0100 | [diff] [blame] | 1677 | |
Filip Gruszczynski | dc39490 | 2015-12-14 10:20:22 -0800 | [diff] [blame] | 1678 | return true; |
| 1679 | } |
| 1680 | |
Andrii Kulian | fb1bf69 | 2017-01-17 11:17:34 -0800 | [diff] [blame] | 1681 | /** Check if caller is allowed to launch activities on specified display. */ |
Andrii Kulian | 02689a7 | 2017-07-06 14:28:59 -0700 | [diff] [blame] | 1682 | boolean isCallerAllowedToLaunchOnDisplay(int callingPid, int callingUid, int launchDisplayId, |
| 1683 | ActivityInfo aInfo) { |
Andrii Kulian | fb1bf69 | 2017-01-17 11:17:34 -0800 | [diff] [blame] | 1684 | if (DEBUG_TASKS) Slog.d(TAG, "Launch on display check: displayId=" + launchDisplayId |
| 1685 | + " callingPid=" + callingPid + " callingUid=" + callingUid); |
| 1686 | |
Andrii Kulian | 02689a7 | 2017-07-06 14:28:59 -0700 | [diff] [blame] | 1687 | if (callingPid == -1 && callingUid == -1) { |
| 1688 | if (DEBUG_TASKS) Slog.d(TAG, "Launch on display check: no caller info, skip check"); |
| 1689 | return true; |
| 1690 | } |
| 1691 | |
Andrii Kulian | 62e6f25 | 2017-05-30 22:46:53 -0700 | [diff] [blame] | 1692 | final ActivityDisplay activityDisplay = getActivityDisplayOrCreateLocked(launchDisplayId); |
Andrii Kulian | fb1bf69 | 2017-01-17 11:17:34 -0800 | [diff] [blame] | 1693 | if (activityDisplay == null) { |
| 1694 | Slog.w(TAG, "Launch on display check: display not found"); |
| 1695 | return false; |
| 1696 | } |
| 1697 | |
Andrii Kulian | 02689a7 | 2017-07-06 14:28:59 -0700 | [diff] [blame] | 1698 | // Check if the caller has enough privileges to embed activities and launch to private |
| 1699 | // displays. |
Andrii Kulian | 3a95edc | 2017-06-28 16:21:07 -0700 | [diff] [blame] | 1700 | final int startAnyPerm = mService.checkPermission(INTERNAL_SYSTEM_WINDOW, callingPid, |
Andrii Kulian | 1cba31c | 2017-06-28 09:42:48 -0700 | [diff] [blame] | 1701 | callingUid); |
| 1702 | if (startAnyPerm == PERMISSION_GRANTED) { |
| 1703 | if (DEBUG_TASKS) Slog.d(TAG, "Launch on display check:" |
| 1704 | + " allow launch any on display"); |
| 1705 | return true; |
| 1706 | } |
| 1707 | |
Andrii Kulian | 8f07029 | 2017-09-12 22:56:49 -0700 | [diff] [blame] | 1708 | // Check if caller is already present on display |
| 1709 | final boolean uidPresentOnDisplay = activityDisplay.isUidPresent(callingUid); |
| 1710 | |
Andrii Kulian | 3c9ad07 | 2017-08-01 11:45:22 -0700 | [diff] [blame] | 1711 | final int displayOwnerUid = activityDisplay.mDisplay.getOwnerUid(); |
| 1712 | if (activityDisplay.mDisplay.getType() == TYPE_VIRTUAL && displayOwnerUid != SYSTEM_UID |
| 1713 | && displayOwnerUid != aInfo.applicationInfo.uid) { |
Andrii Kulian | 1cba31c | 2017-06-28 09:42:48 -0700 | [diff] [blame] | 1714 | // Limit launching on virtual displays, because their contents can be read from Surface |
| 1715 | // by apps that created them. |
Andrii Kulian | 02689a7 | 2017-07-06 14:28:59 -0700 | [diff] [blame] | 1716 | if ((aInfo.flags & ActivityInfo.FLAG_ALLOW_EMBEDDED) == 0) { |
| 1717 | if (DEBUG_TASKS) Slog.d(TAG, "Launch on display check:" |
| 1718 | + " disallow launch on virtual display for not-embedded activity."); |
| 1719 | return false; |
| 1720 | } |
Andrii Kulian | 3c9ad07 | 2017-08-01 11:45:22 -0700 | [diff] [blame] | 1721 | // Check if the caller is allowed to embed activities from other apps. |
| 1722 | if (mService.checkPermission(ACTIVITY_EMBEDDING, callingPid, callingUid) |
Andrii Kulian | 8f07029 | 2017-09-12 22:56:49 -0700 | [diff] [blame] | 1723 | == PERMISSION_DENIED && !uidPresentOnDisplay) { |
Andrii Kulian | 3c9ad07 | 2017-08-01 11:45:22 -0700 | [diff] [blame] | 1724 | if (DEBUG_TASKS) Slog.d(TAG, "Launch on display check:" |
| 1725 | + " disallow activity embedding without permission."); |
| 1726 | return false; |
| 1727 | } |
Andrii Kulian | 1cba31c | 2017-06-28 09:42:48 -0700 | [diff] [blame] | 1728 | } |
| 1729 | |
Andrii Kulian | fb1bf69 | 2017-01-17 11:17:34 -0800 | [diff] [blame] | 1730 | if (!activityDisplay.isPrivate()) { |
| 1731 | // Anyone can launch on a public display. |
| 1732 | if (DEBUG_TASKS) Slog.d(TAG, "Launch on display check:" |
| 1733 | + " allow launch on public display"); |
| 1734 | return true; |
| 1735 | } |
| 1736 | |
| 1737 | // Check if the caller is the owner of the display. |
Andrii Kulian | 3c9ad07 | 2017-08-01 11:45:22 -0700 | [diff] [blame] | 1738 | if (displayOwnerUid == callingUid) { |
Andrii Kulian | fb1bf69 | 2017-01-17 11:17:34 -0800 | [diff] [blame] | 1739 | if (DEBUG_TASKS) Slog.d(TAG, "Launch on display check:" |
| 1740 | + " allow launch for owner of the display"); |
| 1741 | return true; |
| 1742 | } |
| 1743 | |
Andrii Kulian | 8f07029 | 2017-09-12 22:56:49 -0700 | [diff] [blame] | 1744 | if (uidPresentOnDisplay) { |
Andrii Kulian | fb1bf69 | 2017-01-17 11:17:34 -0800 | [diff] [blame] | 1745 | if (DEBUG_TASKS) Slog.d(TAG, "Launch on display check:" |
| 1746 | + " allow launch for caller present on the display"); |
| 1747 | return true; |
| 1748 | } |
| 1749 | |
Andrii Kulian | fb1bf69 | 2017-01-17 11:17:34 -0800 | [diff] [blame] | 1750 | Slog.w(TAG, "Launch on display check: denied"); |
| 1751 | return false; |
| 1752 | } |
| 1753 | |
| 1754 | /** Update lists of UIDs that are present on displays and have access to them. */ |
| 1755 | void updateUIDsPresentOnDisplay() { |
| 1756 | mDisplayAccessUIDs.clear(); |
| 1757 | for (int displayNdx = mActivityDisplays.size() - 1; displayNdx >= 0; --displayNdx) { |
| 1758 | final ActivityDisplay activityDisplay = mActivityDisplays.valueAt(displayNdx); |
David Stevens | 82ea6cb | 2017-03-03 16:18:50 -0800 | [diff] [blame] | 1759 | // Only bother calculating the whitelist for private displays |
| 1760 | if (activityDisplay.isPrivate()) { |
| 1761 | mDisplayAccessUIDs.append( |
| 1762 | activityDisplay.mDisplayId, activityDisplay.getPresentUIDs()); |
| 1763 | } |
Andrii Kulian | fb1bf69 | 2017-01-17 11:17:34 -0800 | [diff] [blame] | 1764 | } |
| 1765 | // Store updated lists in DisplayManager. Callers from outside of AM should get them there. |
| 1766 | mDisplayManagerInternal.setDisplayAccessUIDs(mDisplayAccessUIDs); |
| 1767 | } |
| 1768 | |
Filip Gruszczynski | 07a0e49 | 2015-12-17 14:16:38 -0800 | [diff] [blame] | 1769 | UserInfo getUserInfo(int userId) { |
Clara Bayarri | f7fea16 | 2015-10-22 16:09:52 +0100 | [diff] [blame] | 1770 | final long identity = Binder.clearCallingIdentity(); |
| 1771 | try { |
| 1772 | return UserManager.get(mService.mContext).getUserInfo(userId); |
| 1773 | } finally { |
| 1774 | Binder.restoreCallingIdentity(identity); |
| 1775 | } |
| 1776 | } |
| 1777 | |
Svet Ganov | 99b6043 | 2015-06-27 13:15:22 -0700 | [diff] [blame] | 1778 | private int getComponentRestrictionForCallingPackage(ActivityInfo activityInfo, |
Dianne Hackborn | a7cfbe0 | 2015-07-16 10:52:52 -0700 | [diff] [blame] | 1779 | String callingPackage, int callingPid, int callingUid, boolean ignoreTargetSecurity) { |
Dianne Hackborn | a7cfbe0 | 2015-07-16 10:52:52 -0700 | [diff] [blame] | 1780 | if (!ignoreTargetSecurity && mService.checkComponentPermission(activityInfo.permission, |
| 1781 | callingPid, callingUid, activityInfo.applicationInfo.uid, activityInfo.exported) |
Andrii Kulian | 3c9ad07 | 2017-08-01 11:45:22 -0700 | [diff] [blame] | 1782 | == PERMISSION_DENIED) { |
Svet Ganov | 99b6043 | 2015-06-27 13:15:22 -0700 | [diff] [blame] | 1783 | return ACTIVITY_RESTRICTION_PERMISSION; |
| 1784 | } |
| 1785 | |
Christopher Tate | ff7add0 | 2015-08-17 10:23:22 -0700 | [diff] [blame] | 1786 | if (activityInfo.permission == null) { |
| 1787 | return ACTIVITY_RESTRICTION_NONE; |
| 1788 | } |
| 1789 | |
Svet Ganov | 99b6043 | 2015-06-27 13:15:22 -0700 | [diff] [blame] | 1790 | final int opCode = AppOpsManager.permissionToOpCode(activityInfo.permission); |
| 1791 | if (opCode == AppOpsManager.OP_NONE) { |
| 1792 | return ACTIVITY_RESTRICTION_NONE; |
| 1793 | } |
| 1794 | |
| 1795 | if (mService.mAppOpsService.noteOperation(opCode, callingUid, |
| 1796 | callingPackage) != AppOpsManager.MODE_ALLOWED) { |
Dianne Hackborn | a7cfbe0 | 2015-07-16 10:52:52 -0700 | [diff] [blame] | 1797 | if (!ignoreTargetSecurity) { |
| 1798 | return ACTIVITY_RESTRICTION_APPOP; |
| 1799 | } |
Svet Ganov | 99b6043 | 2015-06-27 13:15:22 -0700 | [diff] [blame] | 1800 | } |
| 1801 | |
| 1802 | return ACTIVITY_RESTRICTION_NONE; |
| 1803 | } |
| 1804 | |
Svetoslav | 7008b51 | 2015-06-24 18:47:07 -0700 | [diff] [blame] | 1805 | private int getActionRestrictionForCallingPackage(String action, |
| 1806 | String callingPackage, int callingPid, int callingUid) { |
| 1807 | if (action == null) { |
Svet Ganov | 99b6043 | 2015-06-27 13:15:22 -0700 | [diff] [blame] | 1808 | return ACTIVITY_RESTRICTION_NONE; |
Svetoslav | 7008b51 | 2015-06-24 18:47:07 -0700 | [diff] [blame] | 1809 | } |
| 1810 | |
| 1811 | String permission = ACTION_TO_RUNTIME_PERMISSION.get(action); |
| 1812 | if (permission == null) { |
Svet Ganov | 99b6043 | 2015-06-27 13:15:22 -0700 | [diff] [blame] | 1813 | return ACTIVITY_RESTRICTION_NONE; |
Svetoslav | 7008b51 | 2015-06-24 18:47:07 -0700 | [diff] [blame] | 1814 | } |
| 1815 | |
| 1816 | final PackageInfo packageInfo; |
| 1817 | try { |
| 1818 | packageInfo = mService.mContext.getPackageManager() |
| 1819 | .getPackageInfo(callingPackage, PackageManager.GET_PERMISSIONS); |
| 1820 | } catch (PackageManager.NameNotFoundException e) { |
| 1821 | Slog.i(TAG, "Cannot find package info for " + callingPackage); |
Svet Ganov | 99b6043 | 2015-06-27 13:15:22 -0700 | [diff] [blame] | 1822 | return ACTIVITY_RESTRICTION_NONE; |
Svetoslav | 7008b51 | 2015-06-24 18:47:07 -0700 | [diff] [blame] | 1823 | } |
| 1824 | |
| 1825 | if (!ArrayUtils.contains(packageInfo.requestedPermissions, permission)) { |
Svet Ganov | 99b6043 | 2015-06-27 13:15:22 -0700 | [diff] [blame] | 1826 | return ACTIVITY_RESTRICTION_NONE; |
Svetoslav | 7008b51 | 2015-06-24 18:47:07 -0700 | [diff] [blame] | 1827 | } |
| 1828 | |
Andrii Kulian | 3c9ad07 | 2017-08-01 11:45:22 -0700 | [diff] [blame] | 1829 | if (mService.checkPermission(permission, callingPid, callingUid) == PERMISSION_DENIED) { |
Svet Ganov | 99b6043 | 2015-06-27 13:15:22 -0700 | [diff] [blame] | 1830 | return ACTIVITY_RESTRICTION_PERMISSION; |
Svetoslav | 7008b51 | 2015-06-24 18:47:07 -0700 | [diff] [blame] | 1831 | } |
| 1832 | |
| 1833 | final int opCode = AppOpsManager.permissionToOpCode(permission); |
| 1834 | if (opCode == AppOpsManager.OP_NONE) { |
Svet Ganov | 99b6043 | 2015-06-27 13:15:22 -0700 | [diff] [blame] | 1835 | return ACTIVITY_RESTRICTION_NONE; |
Svetoslav | 7008b51 | 2015-06-24 18:47:07 -0700 | [diff] [blame] | 1836 | } |
| 1837 | |
| 1838 | if (mService.mAppOpsService.noteOperation(opCode, callingUid, |
| 1839 | callingPackage) != AppOpsManager.MODE_ALLOWED) { |
Svet Ganov | 99b6043 | 2015-06-27 13:15:22 -0700 | [diff] [blame] | 1840 | return ACTIVITY_RESTRICTION_APPOP; |
Svetoslav | 7008b51 | 2015-06-24 18:47:07 -0700 | [diff] [blame] | 1841 | } |
| 1842 | |
Svet Ganov | 99b6043 | 2015-06-27 13:15:22 -0700 | [diff] [blame] | 1843 | return ACTIVITY_RESTRICTION_NONE; |
Svetoslav | 7008b51 | 2015-06-24 18:47:07 -0700 | [diff] [blame] | 1844 | } |
| 1845 | |
Dianne Hackborn | 3d07c94 | 2015-03-13 18:02:54 -0700 | [diff] [blame] | 1846 | void setLaunchSource(int uid) { |
| 1847 | mLaunchingActivity.setWorkSource(new WorkSource(uid)); |
| 1848 | } |
| 1849 | |
Craig Mautner | 7ea5bd4 | 2013-07-05 15:27:08 -0700 | [diff] [blame] | 1850 | void acquireLaunchWakelock() { |
| 1851 | if (VALIDATE_WAKE_LOCK_CALLER && Binder.getCallingUid() != Process.myUid()) { |
| 1852 | throw new IllegalStateException("Calling must be system uid"); |
| 1853 | } |
| 1854 | mLaunchingActivity.acquire(); |
| 1855 | if (!mHandler.hasMessages(LAUNCH_TIMEOUT_MSG)) { |
| 1856 | // To be safe, don't allow the wake lock to be held for too long. |
| 1857 | mHandler.sendEmptyMessageDelayed(LAUNCH_TIMEOUT_MSG, LAUNCH_TIMEOUT); |
| 1858 | } |
| 1859 | } |
| 1860 | |
Craig Mautner | f3ea23a | 2015-01-13 09:37:08 -0800 | [diff] [blame] | 1861 | /** |
| 1862 | * Called when the frontmost task is idle. |
| 1863 | * @return the state of mService.mBooting before this was called. |
| 1864 | */ |
Andreas Gampe | a36dc62 | 2018-02-05 17:19:22 -0800 | [diff] [blame] | 1865 | @GuardedBy("mService") |
Craig Mautner | f3ea23a | 2015-01-13 09:37:08 -0800 | [diff] [blame] | 1866 | private boolean checkFinishBootingLocked() { |
| 1867 | final boolean booting = mService.mBooting; |
| 1868 | boolean enableScreen = false; |
| 1869 | mService.mBooting = false; |
| 1870 | if (!mService.mBooted) { |
| 1871 | mService.mBooted = true; |
| 1872 | enableScreen = true; |
| 1873 | } |
| 1874 | if (booting || enableScreen) { |
| 1875 | mService.postFinishBooting(booting, enableScreen); |
| 1876 | } |
| 1877 | return booting; |
| 1878 | } |
| 1879 | |
Craig Mautner | f333327 | 2013-04-22 10:55:53 -0700 | [diff] [blame] | 1880 | // Checked. |
Andreas Gampe | a36dc62 | 2018-02-05 17:19:22 -0800 | [diff] [blame] | 1881 | @GuardedBy("mService") |
Craig Mautner | f333327 | 2013-04-22 10:55:53 -0700 | [diff] [blame] | 1882 | final ActivityRecord activityIdleInternalLocked(final IBinder token, boolean fromTimeout, |
Winson Chung | 4dabf23 | 2017-01-25 13:25:22 -0800 | [diff] [blame] | 1883 | boolean processPausingActivities, Configuration config) { |
Wale Ogunwale | e23149f | 2015-03-06 15:39:44 -0800 | [diff] [blame] | 1884 | if (DEBUG_ALL) Slog.v(TAG, "Activity idle: " + token); |
Craig Mautner | f333327 | 2013-04-22 10:55:53 -0700 | [diff] [blame] | 1885 | |
Craig Mautner | f333327 | 2013-04-22 10:55:53 -0700 | [diff] [blame] | 1886 | ArrayList<ActivityRecord> finishes = null; |
Amith Yamasani | 37a40c2 | 2015-06-17 13:25:42 -0700 | [diff] [blame] | 1887 | ArrayList<UserState> startingUsers = null; |
Craig Mautner | f333327 | 2013-04-22 10:55:53 -0700 | [diff] [blame] | 1888 | int NS = 0; |
| 1889 | int NF = 0; |
Craig Mautner | f333327 | 2013-04-22 10:55:53 -0700 | [diff] [blame] | 1890 | boolean booting = false; |
Craig Mautner | f333327 | 2013-04-22 10:55:53 -0700 | [diff] [blame] | 1891 | boolean activityRemoved = false; |
| 1892 | |
Wale Ogunwale | 7d70117 | 2015-03-11 15:36:30 -0700 | [diff] [blame] | 1893 | ActivityRecord r = ActivityRecord.forTokenLocked(token); |
Craig Mautner | f333327 | 2013-04-22 10:55:53 -0700 | [diff] [blame] | 1894 | if (r != null) { |
Wale Ogunwale | 0fc365c | 2015-05-25 19:35:42 -0700 | [diff] [blame] | 1895 | if (DEBUG_IDLE) Slog.d(TAG_IDLE, "activityIdleInternalLocked: Callers=" |
| 1896 | + Debug.getCallers(4)); |
Craig Mautner | f333327 | 2013-04-22 10:55:53 -0700 | [diff] [blame] | 1897 | mHandler.removeMessages(IDLE_TIMEOUT_MSG, r); |
| 1898 | r.finishLaunchTickingLocked(); |
Craig Mautner | 7ea5bd4 | 2013-07-05 15:27:08 -0700 | [diff] [blame] | 1899 | if (fromTimeout) { |
| 1900 | reportActivityLaunchedLocked(fromTimeout, r, -1, -1); |
Craig Mautner | f333327 | 2013-04-22 10:55:53 -0700 | [diff] [blame] | 1901 | } |
Craig Mautner | 7ea5bd4 | 2013-07-05 15:27:08 -0700 | [diff] [blame] | 1902 | |
| 1903 | // This is a hack to semi-deal with a race condition |
| 1904 | // in the client where it can be constructed with a |
| 1905 | // newer configuration from when we asked it to launch. |
| 1906 | // We'll update with whatever configuration it now says |
| 1907 | // it used to launch. |
| 1908 | if (config != null) { |
Bryce Lee | a163b76 | 2017-01-24 11:05:01 -0800 | [diff] [blame] | 1909 | r.setLastReportedGlobalConfiguration(config); |
Craig Mautner | 7ea5bd4 | 2013-07-05 15:27:08 -0700 | [diff] [blame] | 1910 | } |
| 1911 | |
| 1912 | // We are now idle. If someone is waiting for a thumbnail from |
| 1913 | // us, we can now deliver. |
| 1914 | r.idle = true; |
| 1915 | |
Craig Mautner | 7ea5bd4 | 2013-07-05 15:27:08 -0700 | [diff] [blame] | 1916 | //Slog.i(TAG, "IDLE: mBooted=" + mBooted + ", fromTimeout=" + fromTimeout); |
Andrii Kulian | 02b7a83 | 2016-10-06 23:11:56 -0700 | [diff] [blame] | 1917 | if (isFocusedStack(r.getStack()) || fromTimeout) { |
Craig Mautner | f3ea23a | 2015-01-13 09:37:08 -0800 | [diff] [blame] | 1918 | booting = checkFinishBootingLocked(); |
Craig Mautner | 7ea5bd4 | 2013-07-05 15:27:08 -0700 | [diff] [blame] | 1919 | } |
| 1920 | } |
| 1921 | |
| 1922 | if (allResumedActivitiesIdle()) { |
| 1923 | if (r != null) { |
| 1924 | mService.scheduleAppGcsLocked(); |
Craig Mautner | 7ea5bd4 | 2013-07-05 15:27:08 -0700 | [diff] [blame] | 1925 | } |
| 1926 | |
| 1927 | if (mLaunchingActivity.isHeld()) { |
| 1928 | mHandler.removeMessages(LAUNCH_TIMEOUT_MSG); |
| 1929 | if (VALIDATE_WAKE_LOCK_CALLER && |
| 1930 | Binder.getCallingUid() != Process.myUid()) { |
| 1931 | throw new IllegalStateException("Calling must be system uid"); |
| 1932 | } |
| 1933 | mLaunchingActivity.release(); |
| 1934 | } |
Filip Gruszczynski | bc5a6c5 | 2015-09-22 13:13:24 -0700 | [diff] [blame] | 1935 | ensureActivitiesVisibleLocked(null, 0, !PRESERVE_WINDOWS); |
Craig Mautner | f333327 | 2013-04-22 10:55:53 -0700 | [diff] [blame] | 1936 | } |
| 1937 | |
| 1938 | // Atomically retrieve all of the other things to do. |
Winson Chung | 4dabf23 | 2017-01-25 13:25:22 -0800 | [diff] [blame] | 1939 | final ArrayList<ActivityRecord> stops = processStoppingActivitiesLocked(r, |
| 1940 | true /* remove */, processPausingActivities); |
Craig Mautner | f333327 | 2013-04-22 10:55:53 -0700 | [diff] [blame] | 1941 | NS = stops != null ? stops.size() : 0; |
Wale Ogunwale | 7d70117 | 2015-03-11 15:36:30 -0700 | [diff] [blame] | 1942 | if ((NF = mFinishingActivities.size()) > 0) { |
| 1943 | finishes = new ArrayList<>(mFinishingActivities); |
Craig Mautner | f333327 | 2013-04-22 10:55:53 -0700 | [diff] [blame] | 1944 | mFinishingActivities.clear(); |
| 1945 | } |
| 1946 | |
Craig Mautner | f333327 | 2013-04-22 10:55:53 -0700 | [diff] [blame] | 1947 | if (mStartingUsers.size() > 0) { |
Wale Ogunwale | 7d70117 | 2015-03-11 15:36:30 -0700 | [diff] [blame] | 1948 | startingUsers = new ArrayList<>(mStartingUsers); |
Craig Mautner | f333327 | 2013-04-22 10:55:53 -0700 | [diff] [blame] | 1949 | mStartingUsers.clear(); |
| 1950 | } |
| 1951 | |
Craig Mautner | f333327 | 2013-04-22 10:55:53 -0700 | [diff] [blame] | 1952 | // Stop any activities that are scheduled to do so but have been |
| 1953 | // waiting for the next one to start. |
| 1954 | for (int i = 0; i < NS; i++) { |
| 1955 | r = stops.get(i); |
Andrii Kulian | 02b7a83 | 2016-10-06 23:11:56 -0700 | [diff] [blame] | 1956 | final ActivityStack stack = r.getStack(); |
Wale Ogunwale | 7d70117 | 2015-03-11 15:36:30 -0700 | [diff] [blame] | 1957 | if (stack != null) { |
| 1958 | if (r.finishing) { |
Bryce Lee | f52974c | 2018-02-14 15:12:01 -0800 | [diff] [blame] | 1959 | stack.finishCurrentActivityLocked(r, ActivityStack.FINISH_IMMEDIATELY, false, |
| 1960 | "activityIdleInternalLocked"); |
Wale Ogunwale | 7d70117 | 2015-03-11 15:36:30 -0700 | [diff] [blame] | 1961 | } else { |
| 1962 | stack.stopActivityLocked(r); |
| 1963 | } |
Craig Mautner | f333327 | 2013-04-22 10:55:53 -0700 | [diff] [blame] | 1964 | } |
| 1965 | } |
| 1966 | |
| 1967 | // Finish any activities that are scheduled to do so but have been |
| 1968 | // waiting for the next one to start. |
| 1969 | for (int i = 0; i < NF; i++) { |
| 1970 | r = finishes.get(i); |
Andrii Kulian | 02b7a83 | 2016-10-06 23:11:56 -0700 | [diff] [blame] | 1971 | final ActivityStack stack = r.getStack(); |
Wale Ogunwale | 7d70117 | 2015-03-11 15:36:30 -0700 | [diff] [blame] | 1972 | if (stack != null) { |
| 1973 | activityRemoved |= stack.destroyActivityLocked(r, true, "finish-idle"); |
| 1974 | } |
Craig Mautner | f333327 | 2013-04-22 10:55:53 -0700 | [diff] [blame] | 1975 | } |
| 1976 | |
Dianne Hackborn | 7622a0f | 2014-09-30 14:31:42 -0700 | [diff] [blame] | 1977 | if (!booting) { |
Amith Yamasani | 1a7eaaa5 | 2014-05-07 10:22:15 -0700 | [diff] [blame] | 1978 | // Complete user switch |
| 1979 | if (startingUsers != null) { |
| 1980 | for (int i = 0; i < startingUsers.size(); i++) { |
Fyodor Kupolov | 610acda | 2015-10-19 18:44:07 -0700 | [diff] [blame] | 1981 | mService.mUserController.finishUserSwitch(startingUsers.get(i)); |
Amith Yamasani | 1a7eaaa5 | 2014-05-07 10:22:15 -0700 | [diff] [blame] | 1982 | } |
| 1983 | } |
Craig Mautner | f333327 | 2013-04-22 10:55:53 -0700 | [diff] [blame] | 1984 | } |
| 1985 | |
| 1986 | mService.trimApplications(); |
| 1987 | //dump(); |
| 1988 | //mWindowManager.dump(); |
| 1989 | |
Craig Mautner | f333327 | 2013-04-22 10:55:53 -0700 | [diff] [blame] | 1990 | if (activityRemoved) { |
Wale Ogunwale | d046a01 | 2015-12-24 13:05:59 -0800 | [diff] [blame] | 1991 | resumeFocusedStackTopActivityLocked(); |
Craig Mautner | f333327 | 2013-04-22 10:55:53 -0700 | [diff] [blame] | 1992 | } |
| 1993 | |
Craig Mautner | 7ea5bd4 | 2013-07-05 15:27:08 -0700 | [diff] [blame] | 1994 | return r; |
Craig Mautner | f333327 | 2013-04-22 10:55:53 -0700 | [diff] [blame] | 1995 | } |
| 1996 | |
Craig Mautner | 8e56957 | 2013-10-11 17:36:59 -0700 | [diff] [blame] | 1997 | boolean handleAppDiedLocked(ProcessRecord app) { |
Craig Mautner | 1909125 | 2013-10-05 00:03:53 -0700 | [diff] [blame] | 1998 | boolean hasVisibleActivities = false; |
Craig Mautner | e0a3884 | 2013-12-16 16:14:02 -0800 | [diff] [blame] | 1999 | for (int displayNdx = mActivityDisplays.size() - 1; displayNdx >= 0; --displayNdx) { |
Wale Ogunwale | a0f5b5e | 2017-10-11 09:37:23 -0700 | [diff] [blame] | 2000 | final ActivityDisplay display = mActivityDisplays.valueAt(displayNdx); |
| 2001 | for (int stackNdx = display.getChildCount() - 1; stackNdx >= 0; --stackNdx) { |
| 2002 | final ActivityStack stack = display.getChildAt(stackNdx); |
| 2003 | hasVisibleActivities |= stack.handleAppDiedLocked(app); |
Craig Mautner | 4a1cb22 | 2013-12-04 16:14:06 -0800 | [diff] [blame] | 2004 | } |
Craig Mautner | 6b74cb5 | 2013-09-27 17:02:21 -0700 | [diff] [blame] | 2005 | } |
Craig Mautner | 1909125 | 2013-10-05 00:03:53 -0700 | [diff] [blame] | 2006 | return hasVisibleActivities; |
Craig Mautner | 8d341ef | 2013-03-26 09:03:27 -0700 | [diff] [blame] | 2007 | } |
| 2008 | |
| 2009 | void closeSystemDialogsLocked() { |
Craig Mautner | e0a3884 | 2013-12-16 16:14:02 -0800 | [diff] [blame] | 2010 | for (int displayNdx = mActivityDisplays.size() - 1; displayNdx >= 0; --displayNdx) { |
Wale Ogunwale | a0f5b5e | 2017-10-11 09:37:23 -0700 | [diff] [blame] | 2011 | final ActivityDisplay display = mActivityDisplays.valueAt(displayNdx); |
| 2012 | for (int stackNdx = display.getChildCount() - 1; stackNdx >= 0; --stackNdx) { |
| 2013 | final ActivityStack stack = display.getChildAt(stackNdx); |
| 2014 | stack.closeSystemDialogsLocked(); |
Craig Mautner | 4a1cb22 | 2013-12-04 16:14:06 -0800 | [diff] [blame] | 2015 | } |
Craig Mautner | 8d341ef | 2013-03-26 09:03:27 -0700 | [diff] [blame] | 2016 | } |
| 2017 | } |
| 2018 | |
Craig Mautner | 93529a4 | 2013-10-04 15:03:13 -0700 | [diff] [blame] | 2019 | void removeUserLocked(int userId) { |
Craig Mautner | 4f1df4f | 2013-10-15 15:44:14 -0700 | [diff] [blame] | 2020 | mUserStackInFront.delete(userId); |
Craig Mautner | 93529a4 | 2013-10-04 15:03:13 -0700 | [diff] [blame] | 2021 | } |
| 2022 | |
Craig Mautner | 8d341ef | 2013-03-26 09:03:27 -0700 | [diff] [blame] | 2023 | /** |
Chong Zhang | 45c25ce | 2015-08-10 22:18:26 -0700 | [diff] [blame] | 2024 | * Update the last used stack id for non-current user (current user's last |
| 2025 | * used stack is the focused stack) |
| 2026 | */ |
| 2027 | void updateUserStackLocked(int userId, ActivityStack stack) { |
| 2028 | if (userId != mCurrentUser) { |
Wale Ogunwale | 6827856 | 2017-09-23 17:13:55 -0700 | [diff] [blame] | 2029 | mUserStackInFront.put(userId, stack != null ? stack.getStackId() : mHomeStack.mStackId); |
Chong Zhang | 45c25ce | 2015-08-10 22:18:26 -0700 | [diff] [blame] | 2030 | } |
| 2031 | } |
| 2032 | |
| 2033 | /** |
Craig Mautner | 8d341ef | 2013-03-26 09:03:27 -0700 | [diff] [blame] | 2034 | * @return true if some activity was finished (or would have finished if doit were true). |
| 2035 | */ |
Wale Ogunwale | 540e123 | 2015-05-01 15:35:39 -0700 | [diff] [blame] | 2036 | boolean finishDisabledPackageActivitiesLocked(String packageName, Set<String> filterByClasses, |
| 2037 | boolean doit, boolean evenPersistent, int userId) { |
Craig Mautner | 8d341ef | 2013-03-26 09:03:27 -0700 | [diff] [blame] | 2038 | boolean didSomething = false; |
Craig Mautner | e0a3884 | 2013-12-16 16:14:02 -0800 | [diff] [blame] | 2039 | for (int displayNdx = mActivityDisplays.size() - 1; displayNdx >= 0; --displayNdx) { |
Wale Ogunwale | a0f5b5e | 2017-10-11 09:37:23 -0700 | [diff] [blame] | 2040 | final ActivityDisplay display = mActivityDisplays.valueAt(displayNdx); |
| 2041 | for (int stackNdx = display.getChildCount() - 1; stackNdx >= 0; --stackNdx) { |
| 2042 | final ActivityStack stack = display.getChildAt(stackNdx); |
Wale Ogunwale | 540e123 | 2015-05-01 15:35:39 -0700 | [diff] [blame] | 2043 | if (stack.finishDisabledPackageActivitiesLocked( |
| 2044 | packageName, filterByClasses, doit, evenPersistent, userId)) { |
Craig Mautner | 4a1cb22 | 2013-12-04 16:14:06 -0800 | [diff] [blame] | 2045 | didSomething = true; |
| 2046 | } |
Craig Mautner | 8d341ef | 2013-03-26 09:03:27 -0700 | [diff] [blame] | 2047 | } |
| 2048 | } |
| 2049 | return didSomething; |
| 2050 | } |
| 2051 | |
Dianne Hackborn | a413dc0 | 2013-07-12 12:02:55 -0700 | [diff] [blame] | 2052 | void updatePreviousProcessLocked(ActivityRecord r) { |
| 2053 | // Now that this process has stopped, we may want to consider |
| 2054 | // it to be the previous app to try to keep around in case |
| 2055 | // the user wants to return to it. |
| 2056 | |
| 2057 | // First, found out what is currently the foreground app, so that |
| 2058 | // we don't blow away the previous app if this activity is being |
| 2059 | // hosted by the process that is actually still the foreground. |
| 2060 | ProcessRecord fgApp = null; |
Craig Mautner | e0a3884 | 2013-12-16 16:14:02 -0800 | [diff] [blame] | 2061 | for (int displayNdx = mActivityDisplays.size() - 1; displayNdx >= 0; --displayNdx) { |
Wale Ogunwale | a0f5b5e | 2017-10-11 09:37:23 -0700 | [diff] [blame] | 2062 | final ActivityDisplay display = mActivityDisplays.valueAt(displayNdx); |
| 2063 | for (int stackNdx = display.getChildCount() - 1; stackNdx >= 0; --stackNdx) { |
| 2064 | final ActivityStack stack = display.getChildAt(stackNdx); |
Wale Ogunwale | 1e60e0c | 2015-10-28 13:36:10 -0700 | [diff] [blame] | 2065 | if (isFocusedStack(stack)) { |
Craig Mautner | 4a1cb22 | 2013-12-04 16:14:06 -0800 | [diff] [blame] | 2066 | if (stack.mResumedActivity != null) { |
| 2067 | fgApp = stack.mResumedActivity.app; |
| 2068 | } else if (stack.mPausingActivity != null) { |
| 2069 | fgApp = stack.mPausingActivity.app; |
| 2070 | } |
| 2071 | break; |
Dianne Hackborn | a413dc0 | 2013-07-12 12:02:55 -0700 | [diff] [blame] | 2072 | } |
Dianne Hackborn | a413dc0 | 2013-07-12 12:02:55 -0700 | [diff] [blame] | 2073 | } |
| 2074 | } |
| 2075 | |
| 2076 | // Now set this one as the previous process, only if that really |
| 2077 | // makes sense to. |
| 2078 | if (r.app != null && fgApp != null && r.app != fgApp |
| 2079 | && r.lastVisibleTime > mService.mPreviousProcessVisibleTime |
Craig Mautner | 4ef2693 | 2013-09-18 15:15:52 -0700 | [diff] [blame] | 2080 | && r.app != mService.mHomeProcess) { |
Dianne Hackborn | a413dc0 | 2013-07-12 12:02:55 -0700 | [diff] [blame] | 2081 | mService.mPreviousProcess = r.app; |
| 2082 | mService.mPreviousProcessVisibleTime = r.lastVisibleTime; |
| 2083 | } |
| 2084 | } |
| 2085 | |
Wale Ogunwale | d046a01 | 2015-12-24 13:05:59 -0800 | [diff] [blame] | 2086 | boolean resumeFocusedStackTopActivityLocked() { |
| 2087 | return resumeFocusedStackTopActivityLocked(null, null, null); |
Craig Mautner | 05d2903 | 2013-05-03 13:40:13 -0700 | [diff] [blame] | 2088 | } |
| 2089 | |
Wale Ogunwale | d046a01 | 2015-12-24 13:05:59 -0800 | [diff] [blame] | 2090 | boolean resumeFocusedStackTopActivityLocked( |
Chong Zhang | 280d332 | 2015-11-03 17:27:26 -0800 | [diff] [blame] | 2091 | ActivityStack targetStack, ActivityRecord target, ActivityOptions targetOptions) { |
chaviw | 59b9885 | 2017-06-13 12:05:44 -0700 | [diff] [blame] | 2092 | |
| 2093 | if (!readyToResume()) { |
| 2094 | return false; |
| 2095 | } |
| 2096 | |
Wale Ogunwale | d046a01 | 2015-12-24 13:05:59 -0800 | [diff] [blame] | 2097 | if (targetStack != null && isFocusedStack(targetStack)) { |
| 2098 | return targetStack.resumeTopActivityUncheckedLocked(target, targetOptions); |
Craig Mautner | 05d2903 | 2013-05-03 13:40:13 -0700 | [diff] [blame] | 2099 | } |
chaviw | 59b9885 | 2017-06-13 12:05:44 -0700 | [diff] [blame] | 2100 | |
Wale Ogunwale | 06579d6 | 2016-04-30 15:29:06 -0700 | [diff] [blame] | 2101 | final ActivityRecord r = mFocusedStack.topRunningActivityLocked(); |
| 2102 | if (r == null || r.state != RESUMED) { |
| 2103 | mFocusedStack.resumeTopActivityUncheckedLocked(null, null); |
skuhne@google.com | 1b974dc | 2016-12-09 13:41:29 -0800 | [diff] [blame] | 2104 | } else if (r.state == RESUMED) { |
| 2105 | // Kick off any lingering app transitions form the MoveTaskToFront operation. |
| 2106 | mFocusedStack.executeAppTransition(targetOptions); |
Wale Ogunwale | 06579d6 | 2016-04-30 15:29:06 -0700 | [diff] [blame] | 2107 | } |
chaviw | 59b9885 | 2017-06-13 12:05:44 -0700 | [diff] [blame] | 2108 | |
Wale Ogunwale | d046a01 | 2015-12-24 13:05:59 -0800 | [diff] [blame] | 2109 | return false; |
Craig Mautner | 8d341ef | 2013-03-26 09:03:27 -0700 | [diff] [blame] | 2110 | } |
| 2111 | |
Todd Kennedy | 39bfee5 | 2016-02-24 10:28:21 -0800 | [diff] [blame] | 2112 | void updateActivityApplicationInfoLocked(ApplicationInfo aInfo) { |
| 2113 | for (int displayNdx = mActivityDisplays.size() - 1; displayNdx >= 0; --displayNdx) { |
Wale Ogunwale | a0f5b5e | 2017-10-11 09:37:23 -0700 | [diff] [blame] | 2114 | final ActivityDisplay display = mActivityDisplays.valueAt(displayNdx); |
| 2115 | for (int stackNdx = display.getChildCount() - 1; stackNdx >= 0; --stackNdx) { |
| 2116 | final ActivityStack stack = display.getChildAt(stackNdx); |
| 2117 | stack.updateActivityApplicationInfoLocked(aInfo); |
Todd Kennedy | 39bfee5 | 2016-02-24 10:28:21 -0800 | [diff] [blame] | 2118 | } |
| 2119 | } |
| 2120 | } |
| 2121 | |
Adrian Roos | 20d7df3 | 2016-01-12 18:59:43 +0100 | [diff] [blame] | 2122 | TaskRecord finishTopRunningActivityLocked(ProcessRecord app, String reason) { |
| 2123 | TaskRecord finishedTask = null; |
| 2124 | ActivityStack focusedStack = getFocusedStack(); |
Craig Mautner | e0a3884 | 2013-12-16 16:14:02 -0800 | [diff] [blame] | 2125 | for (int displayNdx = mActivityDisplays.size() - 1; displayNdx >= 0; --displayNdx) { |
Wale Ogunwale | a0f5b5e | 2017-10-11 09:37:23 -0700 | [diff] [blame] | 2126 | final ActivityDisplay display = mActivityDisplays.valueAt(displayNdx); |
| 2127 | final int numStacks = display.getChildCount(); |
Craig Mautner | 4a1cb22 | 2013-12-04 16:14:06 -0800 | [diff] [blame] | 2128 | for (int stackNdx = 0; stackNdx < numStacks; ++stackNdx) { |
Wale Ogunwale | a0f5b5e | 2017-10-11 09:37:23 -0700 | [diff] [blame] | 2129 | final ActivityStack stack = display.getChildAt(stackNdx); |
Adrian Roos | 20d7df3 | 2016-01-12 18:59:43 +0100 | [diff] [blame] | 2130 | TaskRecord t = stack.finishTopRunningActivityLocked(app, reason); |
| 2131 | if (stack == focusedStack || finishedTask == null) { |
| 2132 | finishedTask = t; |
| 2133 | } |
Craig Mautner | 4a1cb22 | 2013-12-04 16:14:06 -0800 | [diff] [blame] | 2134 | } |
Craig Mautner | 8d341ef | 2013-03-26 09:03:27 -0700 | [diff] [blame] | 2135 | } |
Adrian Roos | 20d7df3 | 2016-01-12 18:59:43 +0100 | [diff] [blame] | 2136 | return finishedTask; |
Craig Mautner | 8d341ef | 2013-03-26 09:03:27 -0700 | [diff] [blame] | 2137 | } |
| 2138 | |
Dianne Hackborn | 6ea0d0a | 2014-07-02 16:23:21 -0700 | [diff] [blame] | 2139 | void finishVoiceTask(IVoiceInteractionSession session) { |
| 2140 | for (int displayNdx = mActivityDisplays.size() - 1; displayNdx >= 0; --displayNdx) { |
Wale Ogunwale | a0f5b5e | 2017-10-11 09:37:23 -0700 | [diff] [blame] | 2141 | final ActivityDisplay display = mActivityDisplays.valueAt(displayNdx); |
| 2142 | final int numStacks = display.getChildCount(); |
Dianne Hackborn | 6ea0d0a | 2014-07-02 16:23:21 -0700 | [diff] [blame] | 2143 | for (int stackNdx = 0; stackNdx < numStacks; ++stackNdx) { |
Wale Ogunwale | a0f5b5e | 2017-10-11 09:37:23 -0700 | [diff] [blame] | 2144 | final ActivityStack stack = display.getChildAt(stackNdx); |
Dianne Hackborn | 6ea0d0a | 2014-07-02 16:23:21 -0700 | [diff] [blame] | 2145 | stack.finishVoiceTask(session); |
| 2146 | } |
| 2147 | } |
| 2148 | } |
| 2149 | |
Jorim Jaggi | 4d8d32c | 2018-01-19 15:57:41 +0100 | [diff] [blame] | 2150 | void findTaskToMoveToFront(TaskRecord task, int flags, ActivityOptions options, String reason, |
| 2151 | boolean forceNonResizeable) { |
Wale Ogunwale | 66e1685 | 2017-10-19 13:35:52 -0700 | [diff] [blame] | 2152 | final ActivityStack currentStack = task.getStack(); |
| 2153 | if (currentStack == null) { |
| 2154 | Slog.e(TAG, "findTaskToMoveToFront: can't move task=" |
| 2155 | + task + " to front. Stack is null"); |
| 2156 | return; |
| 2157 | } |
| 2158 | |
Craig Mautner | aea74a5 | 2014-03-08 14:23:10 -0800 | [diff] [blame] | 2159 | if ((flags & ActivityManager.MOVE_TASK_NO_USER_ACTION) == 0) { |
| 2160 | mUserLeaving = true; |
Craig Mautner | 8d341ef | 2013-03-26 09:03:27 -0700 | [diff] [blame] | 2161 | } |
Wale Ogunwale | 66e1685 | 2017-10-19 13:35:52 -0700 | [diff] [blame] | 2162 | |
| 2163 | final ActivityRecord prev = topRunningActivityLocked(); |
| 2164 | |
| 2165 | if ((flags & ActivityManager.MOVE_TASK_WITH_HOME) != 0 |
| 2166 | || (prev != null && prev.isActivityTypeRecents())) { |
| 2167 | // Caller wants the home activity moved with it or the previous task is recents in which |
| 2168 | // case we always return home from the task we are moving to the front. |
| 2169 | moveHomeStackToFront("findTaskToMoveToFront"); |
Wale Ogunwale | 7d70117 | 2015-03-11 15:36:30 -0700 | [diff] [blame] | 2170 | } |
Chong Zhang | 0fa656b | 2015-08-31 15:17:21 -0700 | [diff] [blame] | 2171 | |
Wale Ogunwale | 0568aed | 2017-09-08 13:29:37 -0700 | [diff] [blame] | 2172 | if (task.isResizeable() && canUseActivityOptionsLaunchBounds(options)) { |
Bryce Lee | f3c6a47 | 2017-11-14 14:53:06 -0800 | [diff] [blame] | 2173 | final Rect bounds = options.getLaunchBounds(); |
Wale Ogunwale | 0568aed | 2017-09-08 13:29:37 -0700 | [diff] [blame] | 2174 | task.updateOverrideConfiguration(bounds); |
| 2175 | |
Wale Ogunwale | 04a05ac | 2017-09-17 21:35:02 -0700 | [diff] [blame] | 2176 | ActivityStack stack = getLaunchStack(null, options, task, ON_TOP); |
Wale Ogunwale | 0568aed | 2017-09-08 13:29:37 -0700 | [diff] [blame] | 2177 | |
Wale Ogunwale | 04a05ac | 2017-09-17 21:35:02 -0700 | [diff] [blame] | 2178 | if (stack != currentStack) { |
| 2179 | 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] | 2180 | "findTaskToMoveToFront"); |
Wale Ogunwale | 04a05ac | 2017-09-17 21:35:02 -0700 | [diff] [blame] | 2181 | stack = currentStack; |
Wale Ogunwale | 0568aed | 2017-09-08 13:29:37 -0700 | [diff] [blame] | 2182 | // moveTaskToStackUncheckedLocked() should already placed the task on top, |
| 2183 | // still need moveTaskToFrontLocked() below for any transition settings. |
| 2184 | } |
Wale Ogunwale | 44f036f | 2017-09-29 05:09:09 -0700 | [diff] [blame] | 2185 | if (stack.resizeStackWithLaunchBounds()) { |
| 2186 | resizeStackLocked(stack, bounds, null /* tempTaskBounds */, |
Wale Ogunwale | 04a05ac | 2017-09-17 21:35:02 -0700 | [diff] [blame] | 2187 | null /* tempTaskInsetBounds */, !PRESERVE_WINDOWS, |
| 2188 | true /* allowResizeInDockedMode */, !DEFER_RESUME); |
Wale Ogunwale | 0568aed | 2017-09-08 13:29:37 -0700 | [diff] [blame] | 2189 | } else { |
| 2190 | // WM resizeTask must be done after the task is moved to the correct stack, |
| 2191 | // because Task's setBounds() also updates dim layer's bounds, but that has |
| 2192 | // dependency on the stack. |
| 2193 | task.resizeWindowContainer(); |
Chong Zhang | 0fa656b | 2015-08-31 15:17:21 -0700 | [diff] [blame] | 2194 | } |
| 2195 | } |
| 2196 | |
Chong Zhang | db20b5f | 2015-10-23 14:01:43 -0700 | [diff] [blame] | 2197 | final ActivityRecord r = task.getTopActivity(); |
Andrii Kulian | 02b7a83 | 2016-10-06 23:11:56 -0700 | [diff] [blame] | 2198 | currentStack.moveTaskToFrontLocked(task, false /* noAnimation */, options, |
Chong Zhang | db20b5f | 2015-10-23 14:01:43 -0700 | [diff] [blame] | 2199 | r == null ? null : r.appTimeTracker, reason); |
| 2200 | |
Wale Ogunwale | ee006da | 2015-03-30 14:49:25 -0700 | [diff] [blame] | 2201 | if (DEBUG_STACK) Slog.d(TAG_STACK, |
Andrii Kulian | 02b7a83 | 2016-10-06 23:11:56 -0700 | [diff] [blame] | 2202 | "findTaskToMoveToFront: moved to front of stack=" + currentStack); |
Jorim Jaggi | 2adba07 | 2016-03-03 13:43:39 +0100 | [diff] [blame] | 2203 | |
Wale Ogunwale | 0568aed | 2017-09-08 13:29:37 -0700 | [diff] [blame] | 2204 | handleNonResizableTaskIfNeeded(task, WINDOWING_MODE_UNDEFINED, DEFAULT_DISPLAY, |
Wale Ogunwale | a0f5b5e | 2017-10-11 09:37:23 -0700 | [diff] [blame] | 2205 | currentStack, forceNonResizeable); |
Craig Mautner | 8d341ef | 2013-03-26 09:03:27 -0700 | [diff] [blame] | 2206 | } |
| 2207 | |
Wale Ogunwale | 0568aed | 2017-09-08 13:29:37 -0700 | [diff] [blame] | 2208 | boolean canUseActivityOptionsLaunchBounds(ActivityOptions options) { |
Wale Ogunwale | 7a8fa60 | 2015-11-18 15:56:57 -0800 | [diff] [blame] | 2209 | // 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] | 2210 | // window management or is launching into the pinned stack. |
Wale Ogunwale | 0568aed | 2017-09-08 13:29:37 -0700 | [diff] [blame] | 2211 | if (options == null || options.getLaunchBounds() == null) { |
Wale Ogunwale | 854809c | 2015-12-27 16:18:19 -0800 | [diff] [blame] | 2212 | return false; |
| 2213 | } |
Wale Ogunwale | 0568aed | 2017-09-08 13:29:37 -0700 | [diff] [blame] | 2214 | return (mService.mSupportsPictureInPicture |
| 2215 | && options.getLaunchWindowingMode() == WINDOWING_MODE_PINNED) |
Wale Ogunwale | 854809c | 2015-12-27 16:18:19 -0800 | [diff] [blame] | 2216 | || mService.mSupportsFreeformWindowManagement; |
Wale Ogunwale | 7a8fa60 | 2015-11-18 15:56:57 -0800 | [diff] [blame] | 2217 | } |
| 2218 | |
Bryce Lee | ec55eb0 | 2017-12-05 20:51:27 -0800 | [diff] [blame] | 2219 | LaunchParamsController getLaunchParamsController() { |
| 2220 | return mLaunchParamsController; |
Bryce Lee | 9ad3eb3 | 2017-10-10 10:10:31 -0700 | [diff] [blame] | 2221 | } |
| 2222 | |
Winson Chung | 5589333 | 2017-02-17 17:13:10 -0800 | [diff] [blame] | 2223 | protected <T extends ActivityStack> T getStack(int stackId) { |
Wale Ogunwale | 9dcf946 | 2017-09-19 15:13:01 -0700 | [diff] [blame] | 2224 | for (int i = mActivityDisplays.size() - 1; i >= 0; --i) { |
| 2225 | final T stack = mActivityDisplays.valueAt(i).getStack(stackId); |
| 2226 | if (stack != null) { |
| 2227 | return stack; |
| 2228 | } |
| 2229 | } |
| 2230 | return null; |
Wale Ogunwale | ddc1cb2 | 2015-07-25 19:23:04 -0700 | [diff] [blame] | 2231 | } |
| 2232 | |
Wale Ogunwale | 6827856 | 2017-09-23 17:13:55 -0700 | [diff] [blame] | 2233 | /** @see ActivityDisplay#getStack(int, int) */ |
| 2234 | private <T extends ActivityStack> T getStack(int windowingMode, int activityType) { |
| 2235 | for (int i = mActivityDisplays.size() - 1; i >= 0; --i) { |
| 2236 | final T stack = mActivityDisplays.valueAt(i).getStack(windowingMode, activityType); |
| 2237 | if (stack != null) { |
| 2238 | return stack; |
| 2239 | } |
| 2240 | } |
| 2241 | return null; |
| 2242 | } |
| 2243 | |
Wale Ogunwale | 04a05ac | 2017-09-17 21:35:02 -0700 | [diff] [blame] | 2244 | int resolveActivityType(@Nullable ActivityRecord r, @Nullable ActivityOptions options, |
Wale Ogunwale | 0568aed | 2017-09-08 13:29:37 -0700 | [diff] [blame] | 2245 | @Nullable TaskRecord task) { |
Wale Ogunwale | 04a05ac | 2017-09-17 21:35:02 -0700 | [diff] [blame] | 2246 | // Preference is given to the activity type for the activity then the task since the type |
| 2247 | // once set shouldn't change. |
| 2248 | int activityType = r != null ? r.getActivityType() : ACTIVITY_TYPE_UNDEFINED; |
| 2249 | if (activityType == ACTIVITY_TYPE_UNDEFINED && task != null) { |
| 2250 | activityType = task.getActivityType(); |
| 2251 | } |
Wale Ogunwale | 0568aed | 2017-09-08 13:29:37 -0700 | [diff] [blame] | 2252 | if (activityType != ACTIVITY_TYPE_UNDEFINED) { |
| 2253 | return activityType; |
| 2254 | } |
Wale Ogunwale | ab5de37 | 2017-10-18 06:46:31 -0700 | [diff] [blame] | 2255 | if (options != null) { |
| 2256 | activityType = options.getLaunchActivityType(); |
| 2257 | } |
| 2258 | return activityType != ACTIVITY_TYPE_UNDEFINED ? activityType : ACTIVITY_TYPE_STANDARD; |
Wale Ogunwale | 0568aed | 2017-09-08 13:29:37 -0700 | [diff] [blame] | 2259 | } |
| 2260 | |
Wale Ogunwale | 04a05ac | 2017-09-17 21:35:02 -0700 | [diff] [blame] | 2261 | <T extends ActivityStack> T getLaunchStack(@Nullable ActivityRecord r, |
| 2262 | @Nullable ActivityOptions options, @Nullable TaskRecord candidateTask, boolean onTop) { |
| 2263 | return getLaunchStack(r, options, candidateTask, onTop, INVALID_DISPLAY); |
Wale Ogunwale | 0568aed | 2017-09-08 13:29:37 -0700 | [diff] [blame] | 2264 | } |
| 2265 | |
| 2266 | /** |
| 2267 | * Returns the right stack to use for launching factoring in all the input parameters. |
| 2268 | * |
| 2269 | * @param r The activity we are trying to launch. Can be null. |
| 2270 | * @param options The activity options used to the launch. Can be null. |
| 2271 | * @param candidateTask The possible task the activity might be launched in. Can be null. |
| 2272 | * |
| 2273 | * @return The stack to use for the launch or INVALID_STACK_ID. |
| 2274 | */ |
Wale Ogunwale | 04a05ac | 2017-09-17 21:35:02 -0700 | [diff] [blame] | 2275 | <T extends ActivityStack> T getLaunchStack(@Nullable ActivityRecord r, |
| 2276 | @Nullable ActivityOptions options, @Nullable TaskRecord candidateTask, boolean onTop, |
| 2277 | int candidateDisplayId) { |
Wale Ogunwale | 0568aed | 2017-09-08 13:29:37 -0700 | [diff] [blame] | 2278 | int taskId = INVALID_TASK_ID; |
| 2279 | int displayId = INVALID_DISPLAY; |
| 2280 | //Rect bounds = null; |
| 2281 | |
| 2282 | // We give preference to the launch preference in activity options. |
| 2283 | if (options != null) { |
| 2284 | taskId = options.getLaunchTaskId(); |
| 2285 | displayId = options.getLaunchDisplayId(); |
| 2286 | // TODO: Need to work this into the equation... |
| 2287 | //bounds = options.getLaunchBounds(); |
| 2288 | } |
| 2289 | |
| 2290 | // First preference for stack goes to the task Id set in the activity options. Use the stack |
| 2291 | // associated with that if possible. |
| 2292 | if (taskId != INVALID_TASK_ID) { |
| 2293 | // Temporarily set the task id to invalid in case in re-entry. |
| 2294 | options.setLaunchTaskId(INVALID_TASK_ID); |
| 2295 | final TaskRecord task = anyTaskForIdLocked(taskId, |
Wale Ogunwale | ab5de37 | 2017-10-18 06:46:31 -0700 | [diff] [blame] | 2296 | MATCH_TASK_IN_STACKS_OR_RECENT_TASKS_AND_RESTORE, options, onTop); |
Wale Ogunwale | 0568aed | 2017-09-08 13:29:37 -0700 | [diff] [blame] | 2297 | options.setLaunchTaskId(taskId); |
| 2298 | if (task != null) { |
Wale Ogunwale | 04a05ac | 2017-09-17 21:35:02 -0700 | [diff] [blame] | 2299 | return task.getStack(); |
Wale Ogunwale | 0568aed | 2017-09-08 13:29:37 -0700 | [diff] [blame] | 2300 | } |
| 2301 | } |
| 2302 | |
Wale Ogunwale | 0568aed | 2017-09-08 13:29:37 -0700 | [diff] [blame] | 2303 | final int activityType = resolveActivityType(r, options, candidateTask); |
Wale Ogunwale | 04a05ac | 2017-09-17 21:35:02 -0700 | [diff] [blame] | 2304 | T stack = null; |
Wale Ogunwale | 0568aed | 2017-09-08 13:29:37 -0700 | [diff] [blame] | 2305 | |
| 2306 | // Next preference for stack goes to the display Id set in the activity options or the |
| 2307 | // candidate display. |
| 2308 | if (displayId == INVALID_DISPLAY) { |
| 2309 | displayId = candidateDisplayId; |
| 2310 | } |
Andrii Kulian | b850ea5 | 2017-12-12 23:49:10 -0800 | [diff] [blame] | 2311 | if (displayId != INVALID_DISPLAY && canLaunchOnDisplay(r, displayId)) { |
Wale Ogunwale | 0568aed | 2017-09-08 13:29:37 -0700 | [diff] [blame] | 2312 | if (r != null) { |
| 2313 | // 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] | 2314 | stack = (T) getValidLaunchStackOnDisplay(displayId, r); |
Wale Ogunwale | 0568aed | 2017-09-08 13:29:37 -0700 | [diff] [blame] | 2315 | if (stack != null) { |
Wale Ogunwale | 04a05ac | 2017-09-17 21:35:02 -0700 | [diff] [blame] | 2316 | return stack; |
Wale Ogunwale | 0568aed | 2017-09-08 13:29:37 -0700 | [diff] [blame] | 2317 | } |
| 2318 | } |
| 2319 | final ActivityDisplay display = getActivityDisplayOrCreateLocked(displayId); |
| 2320 | if (display != null) { |
Wale Ogunwale | 7e1f5f5 | 2017-10-18 15:19:59 -0700 | [diff] [blame] | 2321 | stack = display.getOrCreateStack(r, options, candidateTask, activityType, onTop); |
Wale Ogunwale | ab5de37 | 2017-10-18 06:46:31 -0700 | [diff] [blame] | 2322 | if (stack != null) { |
| 2323 | return stack; |
Wale Ogunwale | 0568aed | 2017-09-08 13:29:37 -0700 | [diff] [blame] | 2324 | } |
Wale Ogunwale | 0568aed | 2017-09-08 13:29:37 -0700 | [diff] [blame] | 2325 | } |
| 2326 | } |
| 2327 | |
| 2328 | // Give preference to the stack and display of the input task and activity if they match the |
| 2329 | // mode we want to launch into. |
Wale Ogunwale | 04a05ac | 2017-09-17 21:35:02 -0700 | [diff] [blame] | 2330 | stack = null; |
| 2331 | ActivityDisplay display = null; |
Wale Ogunwale | 0568aed | 2017-09-08 13:29:37 -0700 | [diff] [blame] | 2332 | if (candidateTask != null) { |
| 2333 | stack = candidateTask.getStack(); |
| 2334 | } |
| 2335 | if (stack == null && r != null) { |
| 2336 | stack = r.getStack(); |
| 2337 | } |
| 2338 | if (stack != null) { |
Wale Ogunwale | 04a05ac | 2017-09-17 21:35:02 -0700 | [diff] [blame] | 2339 | display = stack.getDisplay(); |
Andrii Kulian | b850ea5 | 2017-12-12 23:49:10 -0800 | [diff] [blame] | 2340 | if (display != null && canLaunchOnDisplay(r, display.mDisplayId)) { |
Wale Ogunwale | 7e1f5f5 | 2017-10-18 15:19:59 -0700 | [diff] [blame] | 2341 | final int windowingMode = |
| 2342 | display.resolveWindowingMode(r, options, candidateTask, activityType); |
| 2343 | if (stack.isCompatible(windowingMode, activityType)) { |
| 2344 | return stack; |
| 2345 | } |
| 2346 | } |
Wale Ogunwale | 0568aed | 2017-09-08 13:29:37 -0700 | [diff] [blame] | 2347 | } |
| 2348 | |
Wale Ogunwale | 04a05ac | 2017-09-17 21:35:02 -0700 | [diff] [blame] | 2349 | if (display == null |
Andrii Kulian | b850ea5 | 2017-12-12 23:49:10 -0800 | [diff] [blame] | 2350 | || !canLaunchOnDisplay(r, display.mDisplayId) |
Wale Ogunwale | 04a05ac | 2017-09-17 21:35:02 -0700 | [diff] [blame] | 2351 | // TODO: Can be removed once we figure-out how non-standard types should launch |
| 2352 | // outside the default display. |
| 2353 | || (activityType != ACTIVITY_TYPE_STANDARD |
| 2354 | && activityType != ACTIVITY_TYPE_UNDEFINED)) { |
| 2355 | display = getDefaultDisplay(); |
Wale Ogunwale | 0568aed | 2017-09-08 13:29:37 -0700 | [diff] [blame] | 2356 | } |
Wale Ogunwale | 04a05ac | 2017-09-17 21:35:02 -0700 | [diff] [blame] | 2357 | |
Wale Ogunwale | 7e1f5f5 | 2017-10-18 15:19:59 -0700 | [diff] [blame] | 2358 | return display.getOrCreateStack(r, options, candidateTask, activityType, onTop); |
Wale Ogunwale | 0568aed | 2017-09-08 13:29:37 -0700 | [diff] [blame] | 2359 | } |
| 2360 | |
Andrii Kulian | b850ea5 | 2017-12-12 23:49:10 -0800 | [diff] [blame] | 2361 | /** @return true if activity record is null or can be launched on provided display. */ |
| 2362 | private boolean canLaunchOnDisplay(ActivityRecord r, int displayId) { |
| 2363 | if (r == null) { |
| 2364 | return true; |
| 2365 | } |
| 2366 | return r.canBeLaunchedOnDisplay(displayId); |
| 2367 | } |
| 2368 | |
Andrii Kulian | 16802aa | 2016-11-02 12:21:33 -0700 | [diff] [blame] | 2369 | /** |
| 2370 | * Get a topmost stack on the display, that is a valid launch stack for specified activity. |
| 2371 | * If there is no such stack, new dynamic stack can be created. |
| 2372 | * @param displayId Target display. |
| 2373 | * @param r Activity that should be launched there. |
| 2374 | * @return Existing stack if there is a valid one, new dynamic stack if it is valid or null. |
| 2375 | */ |
| 2376 | ActivityStack getValidLaunchStackOnDisplay(int displayId, @NonNull ActivityRecord r) { |
Andrii Kulian | 62e6f25 | 2017-05-30 22:46:53 -0700 | [diff] [blame] | 2377 | final ActivityDisplay activityDisplay = getActivityDisplayOrCreateLocked(displayId); |
Andrii Kulian | 16802aa | 2016-11-02 12:21:33 -0700 | [diff] [blame] | 2378 | if (activityDisplay == null) { |
| 2379 | throw new IllegalArgumentException( |
| 2380 | "Display with displayId=" + displayId + " not found."); |
| 2381 | } |
| 2382 | |
Wale Ogunwale | 04a05ac | 2017-09-17 21:35:02 -0700 | [diff] [blame] | 2383 | if (!r.canBeLaunchedOnDisplay(displayId)) { |
| 2384 | return null; |
| 2385 | } |
| 2386 | |
Andrii Kulian | 16802aa | 2016-11-02 12:21:33 -0700 | [diff] [blame] | 2387 | // Return the topmost valid stack on the display. |
Wale Ogunwale | a0f5b5e | 2017-10-11 09:37:23 -0700 | [diff] [blame] | 2388 | for (int i = activityDisplay.getChildCount() - 1; i >= 0; --i) { |
| 2389 | final ActivityStack stack = activityDisplay.getChildAt(i); |
Wale Ogunwale | 6827856 | 2017-09-23 17:13:55 -0700 | [diff] [blame] | 2390 | if (isValidLaunchStack(stack, displayId, r)) { |
Andrii Kulian | 16802aa | 2016-11-02 12:21:33 -0700 | [diff] [blame] | 2391 | return stack; |
| 2392 | } |
| 2393 | } |
| 2394 | |
| 2395 | // 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] | 2396 | if (displayId != DEFAULT_DISPLAY) { |
| 2397 | return activityDisplay.createStack( |
| 2398 | r.getWindowingMode(), r.getActivityType(), true /*onTop*/); |
Andrii Kulian | 16802aa | 2016-11-02 12:21:33 -0700 | [diff] [blame] | 2399 | } |
| 2400 | |
| 2401 | Slog.w(TAG, "getValidLaunchStackOnDisplay: can't launch on displayId " + displayId); |
| 2402 | return null; |
| 2403 | } |
| 2404 | |
Wale Ogunwale | 6827856 | 2017-09-23 17:13:55 -0700 | [diff] [blame] | 2405 | // TODO: Can probably be consolidated into getLaunchStack()... |
| 2406 | private boolean isValidLaunchStack(ActivityStack stack, int displayId, ActivityRecord r) { |
| 2407 | switch (stack.getActivityType()) { |
| 2408 | case ACTIVITY_TYPE_HOME: return r.isActivityTypeHome(); |
| 2409 | case ACTIVITY_TYPE_RECENTS: return r.isActivityTypeRecents(); |
| 2410 | case ACTIVITY_TYPE_ASSISTANT: return r.isActivityTypeAssistant(); |
Wale Ogunwale | 0568aed | 2017-09-08 13:29:37 -0700 | [diff] [blame] | 2411 | } |
Wale Ogunwale | 6827856 | 2017-09-23 17:13:55 -0700 | [diff] [blame] | 2412 | switch (stack.getWindowingMode()) { |
| 2413 | case WINDOWING_MODE_FULLSCREEN: return true; |
| 2414 | case WINDOWING_MODE_FREEFORM: return r.supportsFreeform(); |
| 2415 | case WINDOWING_MODE_PINNED: return r.supportsPictureInPicture(); |
| 2416 | case WINDOWING_MODE_SPLIT_SCREEN_PRIMARY: return r.supportsSplitScreenWindowingMode(); |
| 2417 | case WINDOWING_MODE_SPLIT_SCREEN_SECONDARY: return r.supportsSplitScreenWindowingMode(); |
| 2418 | } |
| 2419 | |
Wale Ogunwale | 44f036f | 2017-09-29 05:09:09 -0700 | [diff] [blame] | 2420 | if (!stack.isOnHomeDisplay()) { |
Wale Ogunwale | 6827856 | 2017-09-23 17:13:55 -0700 | [diff] [blame] | 2421 | return r.canBeLaunchedOnDisplay(displayId); |
| 2422 | } |
| 2423 | Slog.e(TAG, "isValidLaunchStack: Unexpected stack=" + stack); |
| 2424 | return false; |
Wale Ogunwale | 0568aed | 2017-09-08 13:29:37 -0700 | [diff] [blame] | 2425 | } |
| 2426 | |
Andrii Kulian | 7fc2281 | 2016-12-28 13:04:11 -0800 | [diff] [blame] | 2427 | /** |
| 2428 | * Get next focusable stack in the system. This will search across displays and stacks |
| 2429 | * in last-focused order for a focusable and visible stack, different from the target stack. |
| 2430 | * |
| 2431 | * @param currentFocus The stack that previously had focus and thus needs to be ignored when |
| 2432 | * searching for next candidate. |
| 2433 | * @return Next focusable {@link ActivityStack}, null if not found. |
| 2434 | */ |
| 2435 | ActivityStack getNextFocusableStackLocked(ActivityStack currentFocus) { |
| 2436 | mWindowManager.getDisplaysInFocusOrder(mTmpOrderedDisplayIds); |
| 2437 | |
| 2438 | for (int i = mTmpOrderedDisplayIds.size() - 1; i >= 0; --i) { |
| 2439 | final int displayId = mTmpOrderedDisplayIds.get(i); |
Andrii Kulian | 62e6f25 | 2017-05-30 22:46:53 -0700 | [diff] [blame] | 2440 | // 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] | 2441 | final ActivityDisplay display = getActivityDisplayOrCreateLocked(displayId); |
| 2442 | for (int j = display.getChildCount() - 1; j >= 0; --j) { |
| 2443 | final ActivityStack stack = display.getChildAt(j); |
Wale Ogunwale | 04a05ac | 2017-09-17 21:35:02 -0700 | [diff] [blame] | 2444 | if (stack != currentFocus && stack.isFocusable() |
| 2445 | && stack.shouldBeVisible(null)) { |
Andrii Kulian | 7fc2281 | 2016-12-28 13:04:11 -0800 | [diff] [blame] | 2446 | return stack; |
| 2447 | } |
| 2448 | } |
| 2449 | } |
| 2450 | |
| 2451 | return null; |
| 2452 | } |
| 2453 | |
Andrii Kulian | a8fe3df | 2017-06-16 15:29:26 -0700 | [diff] [blame] | 2454 | /** |
| 2455 | * Get next valid stack for launching provided activity in the system. This will search across |
| 2456 | * displays and stacks in last-focused order for a focusable and visible stack, except those |
| 2457 | * that are on a currently focused display. |
| 2458 | * |
| 2459 | * @param r The activity that is being launched. |
| 2460 | * @param currentFocus The display that previously had focus and thus needs to be ignored when |
| 2461 | * searching for the next candidate. |
| 2462 | * @return Next valid {@link ActivityStack}, null if not found. |
| 2463 | */ |
| 2464 | ActivityStack getNextValidLaunchStackLocked(@NonNull ActivityRecord r, int currentFocus) { |
| 2465 | mWindowManager.getDisplaysInFocusOrder(mTmpOrderedDisplayIds); |
| 2466 | for (int i = mTmpOrderedDisplayIds.size() - 1; i >= 0; --i) { |
| 2467 | final int displayId = mTmpOrderedDisplayIds.get(i); |
| 2468 | if (displayId == currentFocus) { |
| 2469 | continue; |
| 2470 | } |
| 2471 | final ActivityStack stack = getValidLaunchStackOnDisplay(displayId, r); |
| 2472 | if (stack != null) { |
| 2473 | return stack; |
| 2474 | } |
| 2475 | } |
| 2476 | return null; |
| 2477 | } |
| 2478 | |
Craig Mautner | ee2e45a | 2014-06-27 12:10:03 -0700 | [diff] [blame] | 2479 | ActivityRecord getHomeActivity() { |
Craig Mautner | db49fec | 2015-05-21 15:33:30 -0700 | [diff] [blame] | 2480 | return getHomeActivityForUser(mCurrentUser); |
Fyodor Kupolov | b501330 | 2015-04-17 17:59:14 -0700 | [diff] [blame] | 2481 | } |
| 2482 | |
| 2483 | ActivityRecord getHomeActivityForUser(int userId) { |
Craig Mautner | 4a1cb22 | 2013-12-04 16:14:06 -0800 | [diff] [blame] | 2484 | final ArrayList<TaskRecord> tasks = mHomeStack.getAllTasks(); |
| 2485 | for (int taskNdx = tasks.size() - 1; taskNdx >= 0; --taskNdx) { |
| 2486 | final TaskRecord task = tasks.get(taskNdx); |
Wale Ogunwale | 6fbde9f | 2017-08-24 07:24:12 -0700 | [diff] [blame] | 2487 | if (task.isActivityTypeHome()) { |
Craig Mautner | 4a1cb22 | 2013-12-04 16:14:06 -0800 | [diff] [blame] | 2488 | final ArrayList<ActivityRecord> activities = task.mActivities; |
| 2489 | for (int activityNdx = activities.size() - 1; activityNdx >= 0; --activityNdx) { |
| 2490 | final ActivityRecord r = activities.get(activityNdx); |
Wale Ogunwale | 6fbde9f | 2017-08-24 07:24:12 -0700 | [diff] [blame] | 2491 | if (r.isActivityTypeHome() |
Fyodor Kupolov | b501330 | 2015-04-17 17:59:14 -0700 | [diff] [blame] | 2492 | && ((userId == UserHandle.USER_ALL) || (r.userId == userId))) { |
Craig Mautner | ee2e45a | 2014-06-27 12:10:03 -0700 | [diff] [blame] | 2493 | return r; |
Craig Mautner | 4a1cb22 | 2013-12-04 16:14:06 -0800 | [diff] [blame] | 2494 | } |
| 2495 | } |
| 2496 | } |
| 2497 | } |
| 2498 | return null; |
| 2499 | } |
| 2500 | |
Wale Ogunwale | 44f036f | 2017-09-29 05:09:09 -0700 | [diff] [blame] | 2501 | void resizeStackLocked(ActivityStack stack, Rect bounds, Rect tempTaskBounds, |
| 2502 | Rect tempTaskInsetBounds, boolean preserveWindows, boolean allowResizeInDockedMode, |
| 2503 | boolean deferResume) { |
| 2504 | |
| 2505 | if (stack.inSplitScreenPrimaryWindowingMode()) { |
Jorim Jaggi | dc249c4 | 2015-12-15 14:57:31 -0800 | [diff] [blame] | 2506 | resizeDockedStackLocked(bounds, tempTaskBounds, tempTaskInsetBounds, null, null, |
Andrii Kulian | db3e4ec | 2016-07-12 17:11:35 -0700 | [diff] [blame] | 2507 | preserveWindows, deferResume); |
Jorim Jaggi | dc249c4 | 2015-12-15 14:57:31 -0800 | [diff] [blame] | 2508 | return; |
| 2509 | } |
Wale Ogunwale | 9d3de4c | 2015-02-01 16:49:44 -0800 | [diff] [blame] | 2510 | |
Wale Ogunwale | a0f5b5e | 2017-10-11 09:37:23 -0700 | [diff] [blame] | 2511 | final boolean splitScreenActive = getDefaultDisplay().hasSplitScreenPrimaryStack(); |
Wale Ogunwale | 3382ab1 | 2017-07-27 08:55:03 -0700 | [diff] [blame] | 2512 | if (!allowResizeInDockedMode |
Wale Ogunwale | 926aade | 2017-08-29 11:24:37 -0700 | [diff] [blame] | 2513 | && !stack.getWindowConfiguration().tasksAreFloating() && splitScreenActive) { |
Winson Chung | a2249ac | 2017-03-30 18:15:30 -0700 | [diff] [blame] | 2514 | // If the docked stack exists, don't resize non-floating stacks independently of the |
| 2515 | // 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] | 2516 | return; |
| 2517 | } |
| 2518 | |
Wale Ogunwale | 44f036f | 2017-09-29 05:09:09 -0700 | [diff] [blame] | 2519 | Trace.traceBegin(TRACE_TAG_ACTIVITY_MANAGER, "am.resizeStack_" + stack.mStackId); |
Jorim Jaggi | c402520 | 2015-10-22 16:43:34 +0200 | [diff] [blame] | 2520 | mWindowManager.deferSurfaceLayout(); |
| 2521 | try { |
Wale Ogunwale | 2b07da8 | 2017-11-08 14:52:40 -0800 | [diff] [blame] | 2522 | if (stack.affectedBySplitScreenResize()) { |
Wale Ogunwale | 926aade | 2017-08-29 11:24:37 -0700 | [diff] [blame] | 2523 | if (bounds == null && stack.inSplitScreenWindowingMode()) { |
| 2524 | // null bounds = fullscreen windowing mode...at least for now. |
| 2525 | stack.setWindowingMode(WINDOWING_MODE_FULLSCREEN); |
| 2526 | } else if (splitScreenActive) { |
| 2527 | // If we are in split-screen mode and this stack support split-screen, then |
| 2528 | // it should be split-screen secondary mode. i.e. adjacent to the docked stack. |
| 2529 | stack.setWindowingMode(WINDOWING_MODE_SPLIT_SCREEN_SECONDARY); |
| 2530 | } |
| 2531 | } |
Wale Ogunwale | 1666e31 | 2016-12-16 11:27:18 -0800 | [diff] [blame] | 2532 | stack.resize(bounds, tempTaskBounds, tempTaskInsetBounds); |
Wale Ogunwale | c8da41e | 2016-04-16 13:27:23 -0700 | [diff] [blame] | 2533 | if (!deferResume) { |
Wale Ogunwale | db0fa12 | 2016-05-16 15:12:03 -0700 | [diff] [blame] | 2534 | stack.ensureVisibleActivitiesConfigurationLocked( |
| 2535 | stack.topRunningActivityLocked(), preserveWindows); |
Wale Ogunwale | c8da41e | 2016-04-16 13:27:23 -0700 | [diff] [blame] | 2536 | } |
Jorim Jaggi | c402520 | 2015-10-22 16:43:34 +0200 | [diff] [blame] | 2537 | } finally { |
| 2538 | mWindowManager.continueSurfaceLayout(); |
| 2539 | Trace.traceEnd(TRACE_TAG_ACTIVITY_MANAGER); |
Wale Ogunwale | e4a0c57 | 2015-06-30 08:40:31 -0700 | [diff] [blame] | 2540 | } |
| 2541 | } |
| 2542 | |
Bryce Lee | d3624e1 | 2017-11-30 08:51:45 -0800 | [diff] [blame] | 2543 | void deferUpdateBounds(int activityType) { |
Wale Ogunwale | 6827856 | 2017-09-23 17:13:55 -0700 | [diff] [blame] | 2544 | final ActivityStack stack = getStack(WINDOWING_MODE_UNDEFINED, activityType); |
Jorim Jaggi | 192086e | 2016-03-11 17:17:03 +0100 | [diff] [blame] | 2545 | if (stack != null) { |
| 2546 | stack.deferUpdateBounds(); |
| 2547 | } |
| 2548 | } |
| 2549 | |
Bryce Lee | d3624e1 | 2017-11-30 08:51:45 -0800 | [diff] [blame] | 2550 | void continueUpdateBounds(int activityType) { |
Wale Ogunwale | 6827856 | 2017-09-23 17:13:55 -0700 | [diff] [blame] | 2551 | final ActivityStack stack = getStack(WINDOWING_MODE_UNDEFINED, activityType); |
Jorim Jaggi | 192086e | 2016-03-11 17:17:03 +0100 | [diff] [blame] | 2552 | if (stack != null) { |
| 2553 | stack.continueUpdateBounds(); |
| 2554 | } |
| 2555 | } |
| 2556 | |
Jorim Jaggi | 0b46f3c | 2016-03-14 12:21:37 +0100 | [diff] [blame] | 2557 | void notifyAppTransitionDone() { |
Wale Ogunwale | 6827856 | 2017-09-23 17:13:55 -0700 | [diff] [blame] | 2558 | continueUpdateBounds(ACTIVITY_TYPE_RECENTS); |
Jorim Jaggi | 0b46f3c | 2016-03-14 12:21:37 +0100 | [diff] [blame] | 2559 | for (int i = mResizingTasksDuringAnimation.size() - 1; i >= 0; i--) { |
| 2560 | final int taskId = mResizingTasksDuringAnimation.valueAt(i); |
Wale Ogunwale | 0568aed | 2017-09-08 13:29:37 -0700 | [diff] [blame] | 2561 | final TaskRecord task = anyTaskForIdLocked(taskId, MATCH_TASK_IN_STACKS_ONLY); |
Wale Ogunwale | e1fe7fa2 | 2016-12-15 18:27:00 -0800 | [diff] [blame] | 2562 | if (task != null) { |
| 2563 | task.setTaskDockedResizing(false); |
Jorim Jaggi | 0b46f3c | 2016-03-14 12:21:37 +0100 | [diff] [blame] | 2564 | } |
| 2565 | } |
| 2566 | mResizingTasksDuringAnimation.clear(); |
| 2567 | } |
| 2568 | |
Wale Ogunwale | 04a05ac | 2017-09-17 21:35:02 -0700 | [diff] [blame] | 2569 | /** |
| 2570 | * 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] | 2571 | * Can do that once we are no longer using static stack ids. |
Wale Ogunwale | 04a05ac | 2017-09-17 21:35:02 -0700 | [diff] [blame] | 2572 | */ |
Wale Ogunwale | 9dcf946 | 2017-09-19 15:13:01 -0700 | [diff] [blame] | 2573 | private void moveTasksToFullscreenStackInSurfaceTransaction(ActivityStack fromStack, |
Wale Ogunwale | 04a05ac | 2017-09-17 21:35:02 -0700 | [diff] [blame] | 2574 | int toDisplayId, boolean onTop) { |
Robert Carr | 6914f08 | 2017-03-20 19:04:30 -0700 | [diff] [blame] | 2575 | |
Wale Ogunwale | c8da41e | 2016-04-16 13:27:23 -0700 | [diff] [blame] | 2576 | mWindowManager.deferSurfaceLayout(); |
| 2577 | try { |
Wale Ogunwale | 04a05ac | 2017-09-17 21:35:02 -0700 | [diff] [blame] | 2578 | final int windowingMode = fromStack.getWindowingMode(); |
| 2579 | final boolean inPinnedWindowingMode = windowingMode == WINDOWING_MODE_PINNED; |
| 2580 | final ActivityDisplay toDisplay = getActivityDisplay(toDisplayId); |
| 2581 | |
| 2582 | if (windowingMode == WINDOWING_MODE_SPLIT_SCREEN_PRIMARY) { |
Wale Ogunwale | 7e1f5f5 | 2017-10-18 15:19:59 -0700 | [diff] [blame] | 2583 | // Tell the display we are exiting split-screen mode. |
| 2584 | toDisplay.onExitingSplitScreenMode(); |
Wale Ogunwale | c8da41e | 2016-04-16 13:27:23 -0700 | [diff] [blame] | 2585 | // We are moving all tasks from the docked stack to the fullscreen stack, |
| 2586 | // which is dismissing the docked stack, so resize all other stacks to |
| 2587 | // fullscreen here already so we don't end up with resize trashing. |
Wale Ogunwale | a0f5b5e | 2017-10-11 09:37:23 -0700 | [diff] [blame] | 2588 | for (int i = toDisplay.getChildCount() - 1; i >= 0; --i) { |
| 2589 | final ActivityStack otherStack = toDisplay.getChildAt(i); |
Wale Ogunwale | 926aade | 2017-08-29 11:24:37 -0700 | [diff] [blame] | 2590 | if (!otherStack.inSplitScreenSecondaryWindowingMode()) { |
| 2591 | continue; |
| 2592 | } |
Wale Ogunwale | 44f036f | 2017-09-29 05:09:09 -0700 | [diff] [blame] | 2593 | resizeStackLocked(otherStack, null, null, null, PRESERVE_WINDOWS, |
Wale Ogunwale | 926aade | 2017-08-29 11:24:37 -0700 | [diff] [blame] | 2594 | true /* allowResizeInDockedMode */, DEFER_RESUME); |
Wale Ogunwale | c8da41e | 2016-04-16 13:27:23 -0700 | [diff] [blame] | 2595 | } |
| 2596 | |
| 2597 | // Also disable docked stack resizing since we have manually adjusted the |
| 2598 | // size of other stacks above and we don't want to trigger a docked stack |
| 2599 | // resize when we remove task from it below and it is detached from the |
| 2600 | // display because it no longer contains any tasks. |
| 2601 | mAllowDockedStackResize = false; |
| 2602 | } |
Wale Ogunwale | 04a05ac | 2017-09-17 21:35:02 -0700 | [diff] [blame] | 2603 | |
Winson Chung | 5af42fc | 2017-03-24 17:11:33 -0700 | [diff] [blame] | 2604 | // If we are moving from the pinned stack, then the animation takes care of updating |
| 2605 | // the picture-in-picture mode. |
Wale Ogunwale | 04a05ac | 2017-09-17 21:35:02 -0700 | [diff] [blame] | 2606 | final boolean schedulePictureInPictureModeChange = inPinnedWindowingMode; |
Wale Ogunwale | 9dcf946 | 2017-09-19 15:13:01 -0700 | [diff] [blame] | 2607 | final ArrayList<TaskRecord> tasks = fromStack.getAllTasks(); |
Wale Ogunwale | 04a05ac | 2017-09-17 21:35:02 -0700 | [diff] [blame] | 2608 | |
Wale Ogunwale | 388945c | 2017-10-04 12:13:46 -0700 | [diff] [blame] | 2609 | if (!tasks.isEmpty()) { |
Wale Ogunwale | 7e1f5f5 | 2017-10-18 15:19:59 -0700 | [diff] [blame] | 2610 | mTmpOptions.setLaunchWindowingMode(WINDOWING_MODE_FULLSCREEN); |
Wale Ogunwale | 388945c | 2017-10-04 12:13:46 -0700 | [diff] [blame] | 2611 | final int size = tasks.size(); |
Wale Ogunwale | 7e1f5f5 | 2017-10-18 15:19:59 -0700 | [diff] [blame] | 2612 | for (int i = 0; i < size; ++i) { |
| 2613 | final TaskRecord task = tasks.get(i); |
| 2614 | final ActivityStack toStack = toDisplay.getOrCreateStack( |
| 2615 | null, mTmpOptions, task, task.getActivityType(), onTop); |
Wale Ogunwale | 388945c | 2017-10-04 12:13:46 -0700 | [diff] [blame] | 2616 | |
Wale Ogunwale | 7e1f5f5 | 2017-10-18 15:19:59 -0700 | [diff] [blame] | 2617 | if (onTop) { |
Wale Ogunwale | 388945c | 2017-10-04 12:13:46 -0700 | [diff] [blame] | 2618 | final boolean isTopTask = i == (size - 1); |
Wale Ogunwale | 388945c | 2017-10-04 12:13:46 -0700 | [diff] [blame] | 2619 | // 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] | 2620 | task.reparent(toStack, ON_TOP, REPARENT_MOVE_STACK_TO_FRONT, |
Wale Ogunwale | 388945c | 2017-10-04 12:13:46 -0700 | [diff] [blame] | 2621 | isTopTask /* animate */, DEFER_RESUME, |
| 2622 | schedulePictureInPictureModeChange, |
| 2623 | "moveTasksToFullscreenStack - onTop"); |
Chenjie Yu | ae9fdf04 | 2018-02-15 10:19:32 -0800 | [diff] [blame] | 2624 | MetricsLoggerWrapper.logPictureInPictureFullScreen(mService.mContext, |
| 2625 | task.effectiveUid, task.realActivity.flattenToString()); |
Wale Ogunwale | 7e1f5f5 | 2017-10-18 15:19:59 -0700 | [diff] [blame] | 2626 | } else { |
Wale Ogunwale | 388945c | 2017-10-04 12:13:46 -0700 | [diff] [blame] | 2627 | // Position the tasks in the fullscreen stack in order at the bottom of the |
| 2628 | // stack. Also defer resume until all the tasks have been moved to the |
| 2629 | // fullscreen stack. |
Wale Ogunwale | 7e1f5f5 | 2017-10-18 15:19:59 -0700 | [diff] [blame] | 2630 | task.reparent(toStack, ON_TOP, |
Wale Ogunwale | 388945c | 2017-10-04 12:13:46 -0700 | [diff] [blame] | 2631 | REPARENT_LEAVE_STACK_IN_PLACE, !ANIMATE, DEFER_RESUME, |
| 2632 | schedulePictureInPictureModeChange, |
| 2633 | "moveTasksToFullscreenStack - NOT_onTop"); |
| 2634 | } |
Wale Ogunwale | c8da41e | 2016-04-16 13:27:23 -0700 | [diff] [blame] | 2635 | } |
| 2636 | } |
Winson Chung | 7466610 | 2017-02-22 17:49:24 -0800 | [diff] [blame] | 2637 | |
| 2638 | ensureActivitiesVisibleLocked(null, 0, PRESERVE_WINDOWS); |
| 2639 | resumeFocusedStackTopActivityLocked(); |
Wale Ogunwale | c8da41e | 2016-04-16 13:27:23 -0700 | [diff] [blame] | 2640 | } finally { |
| 2641 | mAllowDockedStackResize = true; |
| 2642 | mWindowManager.continueSurfaceLayout(); |
| 2643 | } |
| 2644 | } |
| 2645 | |
Wale Ogunwale | 9dcf946 | 2017-09-19 15:13:01 -0700 | [diff] [blame] | 2646 | void moveTasksToFullscreenStackLocked(ActivityStack fromStack, boolean onTop) { |
Wale Ogunwale | 04a05ac | 2017-09-17 21:35:02 -0700 | [diff] [blame] | 2647 | moveTasksToFullscreenStackLocked(fromStack, DEFAULT_DISPLAY, onTop); |
| 2648 | } |
| 2649 | |
| 2650 | void moveTasksToFullscreenStackLocked(ActivityStack fromStack, int toDisplayId, boolean onTop) { |
| 2651 | mWindowManager.inSurfaceTransaction(() -> |
| 2652 | moveTasksToFullscreenStackInSurfaceTransaction(fromStack, toDisplayId, onTop)); |
Robert Carr | 6914f08 | 2017-03-20 19:04:30 -0700 | [diff] [blame] | 2653 | } |
| 2654 | |
Jorim Jaggi | dc249c4 | 2015-12-15 14:57:31 -0800 | [diff] [blame] | 2655 | void resizeDockedStackLocked(Rect dockedBounds, Rect tempDockedTaskBounds, |
Andrii Kulian | db3e4ec | 2016-07-12 17:11:35 -0700 | [diff] [blame] | 2656 | Rect tempDockedTaskInsetBounds, Rect tempOtherTaskBounds, Rect tempOtherTaskInsetBounds, |
| 2657 | boolean preserveWindows) { |
| 2658 | resizeDockedStackLocked(dockedBounds, tempDockedTaskBounds, tempDockedTaskInsetBounds, |
| 2659 | tempOtherTaskBounds, tempOtherTaskInsetBounds, preserveWindows, |
| 2660 | false /* deferResume */); |
| 2661 | } |
| 2662 | |
Wale Ogunwale | 04a05ac | 2017-09-17 21:35:02 -0700 | [diff] [blame] | 2663 | private void resizeDockedStackLocked(Rect dockedBounds, Rect tempDockedTaskBounds, |
Andrii Kulian | db3e4ec | 2016-07-12 17:11:35 -0700 | [diff] [blame] | 2664 | Rect tempDockedTaskInsetBounds, Rect tempOtherTaskBounds, Rect tempOtherTaskInsetBounds, |
| 2665 | boolean preserveWindows, boolean deferResume) { |
Wale Ogunwale | c8da41e | 2016-04-16 13:27:23 -0700 | [diff] [blame] | 2666 | |
| 2667 | if (!mAllowDockedStackResize) { |
| 2668 | // Docked stack resize currently disabled. |
| 2669 | return; |
| 2670 | } |
| 2671 | |
Wale Ogunwale | a0f5b5e | 2017-10-11 09:37:23 -0700 | [diff] [blame] | 2672 | final ActivityStack stack = getDefaultDisplay().getSplitScreenPrimaryStack(); |
Jorim Jaggi | dc249c4 | 2015-12-15 14:57:31 -0800 | [diff] [blame] | 2673 | if (stack == null) { |
| 2674 | Slog.w(TAG, "resizeDockedStackLocked: docked stack not found"); |
| 2675 | return; |
| 2676 | } |
| 2677 | |
| 2678 | Trace.traceBegin(TRACE_TAG_ACTIVITY_MANAGER, "am.resizeDockedStack"); |
| 2679 | mWindowManager.deferSurfaceLayout(); |
| 2680 | try { |
Wale Ogunwale | c8da41e | 2016-04-16 13:27:23 -0700 | [diff] [blame] | 2681 | // Don't allow re-entry while resizing. E.g. due to docked stack detaching. |
| 2682 | mAllowDockedStackResize = false; |
Jorim Jaggi | dc249c4 | 2015-12-15 14:57:31 -0800 | [diff] [blame] | 2683 | ActivityRecord r = stack.topRunningActivityLocked(); |
Wale Ogunwale | 1666e31 | 2016-12-16 11:27:18 -0800 | [diff] [blame] | 2684 | stack.resize(dockedBounds, tempDockedTaskBounds, tempDockedTaskInsetBounds); |
Jorim Jaggi | dc249c4 | 2015-12-15 14:57:31 -0800 | [diff] [blame] | 2685 | |
Andrii Kulian | 69fb5e4 | 2016-04-05 16:47:29 -0700 | [diff] [blame] | 2686 | // TODO: Checking for isAttached might not be needed as if the user passes in null |
| 2687 | // dockedBounds then they want the docked stack to be dismissed. |
Bryce Lee | f3c6a47 | 2017-11-14 14:53:06 -0800 | [diff] [blame] | 2688 | if (stack.getWindowingMode() == WINDOWING_MODE_FULLSCREEN |
| 2689 | || (dockedBounds == null && !stack.isAttached())) { |
Andrii Kulian | 69fb5e4 | 2016-04-05 16:47:29 -0700 | [diff] [blame] | 2690 | // 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] | 2691 | // In this case we make all other static stacks fullscreen and move all |
| 2692 | // docked stack tasks to the fullscreen stack. |
Wale Ogunwale | 9dcf946 | 2017-09-19 15:13:01 -0700 | [diff] [blame] | 2693 | moveTasksToFullscreenStackLocked(stack, ON_TOP); |
Jorim Jaggi | dc249c4 | 2015-12-15 14:57:31 -0800 | [diff] [blame] | 2694 | |
| 2695 | // stack shouldn't contain anymore activities, so nothing to resume. |
| 2696 | r = null; |
| 2697 | } else { |
| 2698 | // Docked stacks occupy a dedicated region on screen so the size of all other |
| 2699 | // static stacks need to be adjusted so they don't overlap with the docked stack. |
| 2700 | // We get the bounds to use from window manager which has been adjusted for any |
| 2701 | // screen controls and is also the same for all stacks. |
Wale Ogunwale | a0f5b5e | 2017-10-11 09:37:23 -0700 | [diff] [blame] | 2702 | final ActivityDisplay display = getDefaultDisplay(); |
Matthew Ng | aa2b620 | 2017-02-10 14:48:21 -0800 | [diff] [blame] | 2703 | final Rect otherTaskRect = new Rect(); |
Wale Ogunwale | a0f5b5e | 2017-10-11 09:37:23 -0700 | [diff] [blame] | 2704 | for (int i = display.getChildCount() - 1; i >= 0; --i) { |
| 2705 | final ActivityStack current = display.getChildAt(i); |
Wale Ogunwale | 04a05ac | 2017-09-17 21:35:02 -0700 | [diff] [blame] | 2706 | if (current.getWindowingMode() == WINDOWING_MODE_SPLIT_SCREEN_PRIMARY) { |
Wale Ogunwale | 926aade | 2017-08-29 11:24:37 -0700 | [diff] [blame] | 2707 | continue; |
Jorim Jaggi | dc249c4 | 2015-12-15 14:57:31 -0800 | [diff] [blame] | 2708 | } |
Wale Ogunwale | 2b07da8 | 2017-11-08 14:52:40 -0800 | [diff] [blame] | 2709 | if (!current.affectedBySplitScreenResize()) { |
Wale Ogunwale | 926aade | 2017-08-29 11:24:37 -0700 | [diff] [blame] | 2710 | continue; |
| 2711 | } |
| 2712 | // Need to set windowing mode here before we try to get the dock bounds. |
| 2713 | current.setWindowingMode(WINDOWING_MODE_SPLIT_SCREEN_SECONDARY); |
| 2714 | current.getStackDockedModeBounds( |
| 2715 | tempOtherTaskBounds /* currentTempTaskBounds */, |
| 2716 | tempRect /* outStackBounds */, |
| 2717 | otherTaskRect /* outTempTaskBounds */, true /* ignoreVisibility */); |
| 2718 | |
Wale Ogunwale | 44f036f | 2017-09-29 05:09:09 -0700 | [diff] [blame] | 2719 | resizeStackLocked(current, !tempRect.isEmpty() ? tempRect : null, |
Wale Ogunwale | 926aade | 2017-08-29 11:24:37 -0700 | [diff] [blame] | 2720 | !otherTaskRect.isEmpty() ? otherTaskRect : tempOtherTaskBounds, |
| 2721 | tempOtherTaskInsetBounds, preserveWindows, |
| 2722 | true /* allowResizeInDockedMode */, deferResume); |
Jorim Jaggi | dc249c4 | 2015-12-15 14:57:31 -0800 | [diff] [blame] | 2723 | } |
| 2724 | } |
Andrii Kulian | db3e4ec | 2016-07-12 17:11:35 -0700 | [diff] [blame] | 2725 | if (!deferResume) { |
| 2726 | stack.ensureVisibleActivitiesConfigurationLocked(r, preserveWindows); |
| 2727 | } |
Jorim Jaggi | dc249c4 | 2015-12-15 14:57:31 -0800 | [diff] [blame] | 2728 | } finally { |
Wale Ogunwale | c8da41e | 2016-04-16 13:27:23 -0700 | [diff] [blame] | 2729 | mAllowDockedStackResize = true; |
Jorim Jaggi | dc249c4 | 2015-12-15 14:57:31 -0800 | [diff] [blame] | 2730 | mWindowManager.continueSurfaceLayout(); |
| 2731 | Trace.traceEnd(TRACE_TAG_ACTIVITY_MANAGER); |
| 2732 | } |
Jorim Jaggi | dc249c4 | 2015-12-15 14:57:31 -0800 | [diff] [blame] | 2733 | } |
| 2734 | |
Robert Carr | 0d00c2e | 2016-02-29 17:45:02 -0800 | [diff] [blame] | 2735 | void resizePinnedStackLocked(Rect pinnedBounds, Rect tempPinnedTaskBounds) { |
Wale Ogunwale | 04a05ac | 2017-09-17 21:35:02 -0700 | [diff] [blame] | 2736 | // TODO(multi-display): Pinned stack display should be passed in. |
Wale Ogunwale | a0f5b5e | 2017-10-11 09:37:23 -0700 | [diff] [blame] | 2737 | final PinnedActivityStack stack = getDefaultDisplay().getPinnedStack(); |
Robert Carr | 0d00c2e | 2016-02-29 17:45:02 -0800 | [diff] [blame] | 2738 | if (stack == null) { |
| 2739 | Slog.w(TAG, "resizePinnedStackLocked: pinned stack not found"); |
| 2740 | return; |
| 2741 | } |
Winson Chung | 19953ca | 2017-04-11 11:19:23 -0700 | [diff] [blame] | 2742 | |
| 2743 | // It is possible for the bounds animation from the WM to call this but be delayed by |
| 2744 | // another AM call that is holding the AMS lock. In such a case, the pinnedBounds may be |
| 2745 | // incorrect if AMS.resizeStackWithBoundsFromWindowManager() is already called while waiting |
| 2746 | // for the AMS lock to be freed. So check and make sure these bounds are still good. |
| 2747 | final PinnedStackWindowController stackController = stack.getWindowContainerController(); |
Winson Chung | 8bca9e4 | 2017-04-16 15:59:43 -0700 | [diff] [blame] | 2748 | if (stackController.pinnedStackResizeDisallowed()) { |
Winson Chung | 19953ca | 2017-04-11 11:19:23 -0700 | [diff] [blame] | 2749 | return; |
| 2750 | } |
| 2751 | |
Robert Carr | 0d00c2e | 2016-02-29 17:45:02 -0800 | [diff] [blame] | 2752 | Trace.traceBegin(TRACE_TAG_ACTIVITY_MANAGER, "am.resizePinnedStack"); |
| 2753 | mWindowManager.deferSurfaceLayout(); |
| 2754 | try { |
| 2755 | ActivityRecord r = stack.topRunningActivityLocked(); |
Robert Carr | 7e4c90e | 2017-02-15 19:52:38 -0800 | [diff] [blame] | 2756 | Rect insetBounds = null; |
| 2757 | if (tempPinnedTaskBounds != null) { |
| 2758 | // We always use 0,0 as the position for the inset rect because |
| 2759 | // if we are getting insets at all in the pinned stack it must mean |
| 2760 | // we are headed for fullscreen. |
| 2761 | insetBounds = tempRect; |
| 2762 | insetBounds.top = 0; |
| 2763 | insetBounds.left = 0; |
| 2764 | insetBounds.right = tempPinnedTaskBounds.width(); |
| 2765 | insetBounds.bottom = tempPinnedTaskBounds.height(); |
| 2766 | } |
| 2767 | stack.resize(pinnedBounds, tempPinnedTaskBounds, insetBounds); |
Wale Ogunwale | db0fa12 | 2016-05-16 15:12:03 -0700 | [diff] [blame] | 2768 | stack.ensureVisibleActivitiesConfigurationLocked(r, false); |
Robert Carr | 0d00c2e | 2016-02-29 17:45:02 -0800 | [diff] [blame] | 2769 | } finally { |
| 2770 | mWindowManager.continueSurfaceLayout(); |
| 2771 | Trace.traceEnd(TRACE_TAG_ACTIVITY_MANAGER); |
| 2772 | } |
| 2773 | } |
| 2774 | |
Wale Ogunwale | a0f5b5e | 2017-10-11 09:37:23 -0700 | [diff] [blame] | 2775 | private void removeStackInSurfaceTransaction(ActivityStack stack) { |
Winson Chung | 010927a | 2016-12-15 16:12:35 -0800 | [diff] [blame] | 2776 | final ArrayList<TaskRecord> tasks = stack.getAllTasks(); |
Wale Ogunwale | 04a05ac | 2017-09-17 21:35:02 -0700 | [diff] [blame] | 2777 | if (stack.getWindowingMode() == WINDOWING_MODE_PINNED) { |
Winson Chung | 4790065 | 2017-04-06 18:44:25 -0700 | [diff] [blame] | 2778 | /** |
| 2779 | * Workaround: Force-stop all the activities in the pinned stack before we reparent them |
| 2780 | * to the fullscreen stack. This is to guarantee that when we are removing a stack, |
| 2781 | * that the client receives onStop() before it is reparented. We do this by detaching |
| 2782 | * the stack from the display so that it will be considered invisible when |
| 2783 | * ensureActivitiesVisibleLocked() is called, and all of its activitys will be marked |
| 2784 | * invisible as well and added to the stopping list. After which we process the |
| 2785 | * stopping list by handling the idle. |
| 2786 | */ |
| 2787 | final PinnedActivityStack pinnedStack = (PinnedActivityStack) stack; |
| 2788 | pinnedStack.mForceHidden = true; |
| 2789 | pinnedStack.ensureActivitiesVisibleLocked(null, 0, PRESERVE_WINDOWS); |
| 2790 | pinnedStack.mForceHidden = false; |
| 2791 | activityIdleInternalLocked(null, false /* fromTimeout */, |
| 2792 | true /* processPausingActivites */, null /* configuration */); |
| 2793 | |
| 2794 | // Move all the tasks to the bottom of the fullscreen stack |
Wale Ogunwale | 9dcf946 | 2017-09-19 15:13:01 -0700 | [diff] [blame] | 2795 | moveTasksToFullscreenStackLocked(pinnedStack, !ON_TOP); |
Winson Chung | 010927a | 2016-12-15 16:12:35 -0800 | [diff] [blame] | 2796 | } else { |
| 2797 | for (int i = tasks.size() - 1; i >= 0; i--) { |
| 2798 | removeTaskByIdLocked(tasks.get(i).taskId, true /* killProcess */, |
Winson Chung | 0ec2a35 | 2017-10-26 11:38:30 -0700 | [diff] [blame] | 2799 | REMOVE_FROM_RECENTS, "remove-stack"); |
Winson Chung | 010927a | 2016-12-15 16:12:35 -0800 | [diff] [blame] | 2800 | } |
| 2801 | } |
| 2802 | } |
| 2803 | |
| 2804 | /** |
Wale Ogunwale | a0f5b5e | 2017-10-11 09:37:23 -0700 | [diff] [blame] | 2805 | * 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] | 2806 | * pinned stack, then its tasks are not explicitly removed when the stack is destroyed, but |
| 2807 | * instead moved back onto the fullscreen stack. |
| 2808 | */ |
Wale Ogunwale | a0f5b5e | 2017-10-11 09:37:23 -0700 | [diff] [blame] | 2809 | void removeStack(ActivityStack stack) { |
| 2810 | mWindowManager.inSurfaceTransaction(() -> removeStackInSurfaceTransaction(stack)); |
Wale Ogunwale | 04a05ac | 2017-09-17 21:35:02 -0700 | [diff] [blame] | 2811 | } |
| 2812 | |
Wale Ogunwale | 6827856 | 2017-09-23 17:13:55 -0700 | [diff] [blame] | 2813 | /** |
| 2814 | * Removes stacks in the input windowing modes from the system if they are of activity type |
| 2815 | * ACTIVITY_TYPE_STANDARD or ACTIVITY_TYPE_UNDEFINED |
| 2816 | */ |
| 2817 | void removeStacksInWindowingModes(int... windowingModes) { |
Wale Ogunwale | 04a05ac | 2017-09-17 21:35:02 -0700 | [diff] [blame] | 2818 | for (int i = mActivityDisplays.size() - 1; i >= 0; --i) { |
Wale Ogunwale | 6827856 | 2017-09-23 17:13:55 -0700 | [diff] [blame] | 2819 | mActivityDisplays.valueAt(i).removeStacksInWindowingModes(windowingModes); |
| 2820 | } |
| 2821 | } |
| 2822 | |
| 2823 | void removeStacksWithActivityTypes(int... activityTypes) { |
| 2824 | for (int i = mActivityDisplays.size() - 1; i >= 0; --i) { |
| 2825 | mActivityDisplays.valueAt(i).removeStacksWithActivityTypes(activityTypes); |
Wale Ogunwale | 04a05ac | 2017-09-17 21:35:02 -0700 | [diff] [blame] | 2826 | } |
Robert Carr | 6914f08 | 2017-03-20 19:04:30 -0700 | [diff] [blame] | 2827 | } |
| 2828 | |
| 2829 | /** |
Winson Chung | 6954fc9 | 2017-03-24 16:22:12 -0700 | [diff] [blame] | 2830 | * See {@link #removeTaskByIdLocked(int, boolean, boolean, boolean)} |
| 2831 | */ |
Winson Chung | 0ec2a35 | 2017-10-26 11:38:30 -0700 | [diff] [blame] | 2832 | boolean removeTaskByIdLocked(int taskId, boolean killProcess, boolean removeFromRecents, |
| 2833 | String reason) { |
| 2834 | return removeTaskByIdLocked(taskId, killProcess, removeFromRecents, !PAUSE_IMMEDIATELY, |
| 2835 | reason); |
Winson Chung | 6954fc9 | 2017-03-24 16:22:12 -0700 | [diff] [blame] | 2836 | } |
| 2837 | |
| 2838 | /** |
Winson Chung | 010927a | 2016-12-15 16:12:35 -0800 | [diff] [blame] | 2839 | * Removes the task with the specified task id. |
| 2840 | * |
| 2841 | * @param taskId Identifier of the task to be removed. |
| 2842 | * @param killProcess Kill any process associated with the task if possible. |
| 2843 | * @param removeFromRecents Whether to also remove the task from recents. |
Winson Chung | 6954fc9 | 2017-03-24 16:22:12 -0700 | [diff] [blame] | 2844 | * @param pauseImmediately Pauses all task activities immediately without waiting for the |
| 2845 | * pause-complete callback from the activity. |
Winson Chung | 010927a | 2016-12-15 16:12:35 -0800 | [diff] [blame] | 2846 | * @return Returns true if the given task was found and removed. |
| 2847 | */ |
Winson Chung | 6954fc9 | 2017-03-24 16:22:12 -0700 | [diff] [blame] | 2848 | boolean removeTaskByIdLocked(int taskId, boolean killProcess, boolean removeFromRecents, |
Winson Chung | 0ec2a35 | 2017-10-26 11:38:30 -0700 | [diff] [blame] | 2849 | boolean pauseImmediately, String reason) { |
Wale Ogunwale | 0568aed | 2017-09-08 13:29:37 -0700 | [diff] [blame] | 2850 | final TaskRecord tr = anyTaskForIdLocked(taskId, MATCH_TASK_IN_STACKS_OR_RECENT_TASKS); |
Winson Chung | 010927a | 2016-12-15 16:12:35 -0800 | [diff] [blame] | 2851 | if (tr != null) { |
Winson Chung | 0ec2a35 | 2017-10-26 11:38:30 -0700 | [diff] [blame] | 2852 | tr.removeTaskActivitiesLocked(pauseImmediately, reason); |
Winson Chung | 010927a | 2016-12-15 16:12:35 -0800 | [diff] [blame] | 2853 | cleanUpRemovedTaskLocked(tr, killProcess, removeFromRecents); |
Charles He | ff9b4dff | 2017-09-22 10:18:37 +0100 | [diff] [blame] | 2854 | mService.mLockTaskController.clearLockedTask(tr); |
Winson Chung | 010927a | 2016-12-15 16:12:35 -0800 | [diff] [blame] | 2855 | if (tr.isPersistable) { |
| 2856 | mService.notifyTaskPersisterLocked(null, true); |
| 2857 | } |
| 2858 | return true; |
| 2859 | } |
| 2860 | Slog.w(TAG, "Request to remove task ignored for non-existent task " + taskId); |
| 2861 | return false; |
| 2862 | } |
| 2863 | |
| 2864 | void cleanUpRemovedTaskLocked(TaskRecord tr, boolean killProcess, boolean removeFromRecents) { |
| 2865 | if (removeFromRecents) { |
Winson Chung | 1dbc811 | 2017-09-28 18:05:31 -0700 | [diff] [blame] | 2866 | mRecentTasks.remove(tr); |
Winson Chung | 010927a | 2016-12-15 16:12:35 -0800 | [diff] [blame] | 2867 | } |
| 2868 | ComponentName component = tr.getBaseIntent().getComponent(); |
| 2869 | if (component == null) { |
| 2870 | Slog.w(TAG, "No component for base intent of task: " + tr); |
| 2871 | return; |
| 2872 | } |
| 2873 | |
| 2874 | // Find any running services associated with this app and stop if needed. |
| 2875 | mService.mServices.cleanUpRemovedTaskLocked(tr, component, new Intent(tr.getBaseIntent())); |
| 2876 | |
| 2877 | if (!killProcess) { |
| 2878 | return; |
| 2879 | } |
| 2880 | |
| 2881 | // Determine if the process(es) for this task should be killed. |
| 2882 | final String pkg = component.getPackageName(); |
| 2883 | ArrayList<ProcessRecord> procsToKill = new ArrayList<>(); |
| 2884 | ArrayMap<String, SparseArray<ProcessRecord>> pmap = mService.mProcessNames.getMap(); |
| 2885 | for (int i = 0; i < pmap.size(); i++) { |
| 2886 | |
| 2887 | SparseArray<ProcessRecord> uids = pmap.valueAt(i); |
| 2888 | for (int j = 0; j < uids.size(); j++) { |
| 2889 | ProcessRecord proc = uids.valueAt(j); |
| 2890 | if (proc.userId != tr.userId) { |
| 2891 | // Don't kill process for a different user. |
| 2892 | continue; |
| 2893 | } |
| 2894 | if (proc == mService.mHomeProcess) { |
| 2895 | // Don't kill the home process along with tasks from the same package. |
| 2896 | continue; |
| 2897 | } |
| 2898 | if (!proc.pkgList.containsKey(pkg)) { |
| 2899 | // Don't kill process that is not associated with this task. |
| 2900 | continue; |
| 2901 | } |
| 2902 | |
| 2903 | for (int k = 0; k < proc.activities.size(); k++) { |
Bryce Lee | af691c0 | 2017-03-20 14:20:22 -0700 | [diff] [blame] | 2904 | TaskRecord otherTask = proc.activities.get(k).getTask(); |
Winson Chung | 010927a | 2016-12-15 16:12:35 -0800 | [diff] [blame] | 2905 | if (tr.taskId != otherTask.taskId && otherTask.inRecents) { |
| 2906 | // Don't kill process(es) that has an activity in a different task that is |
| 2907 | // also in recents. |
| 2908 | return; |
| 2909 | } |
| 2910 | } |
| 2911 | |
| 2912 | if (proc.foregroundServices) { |
| 2913 | // Don't kill process(es) with foreground service. |
| 2914 | return; |
| 2915 | } |
| 2916 | |
| 2917 | // Add process to kill list. |
| 2918 | procsToKill.add(proc); |
| 2919 | } |
| 2920 | } |
| 2921 | |
| 2922 | // Kill the running processes. |
| 2923 | for (int i = 0; i < procsToKill.size(); i++) { |
| 2924 | ProcessRecord pr = procsToKill.get(i); |
| 2925 | if (pr.setSchedGroup == ProcessList.SCHED_GROUP_BACKGROUND |
| 2926 | && pr.curReceivers.isEmpty()) { |
| 2927 | pr.kill("remove task", true); |
| 2928 | } else { |
| 2929 | // We delay killing processes that are not in the background or running a receiver. |
| 2930 | pr.waitingToKill = "remove task"; |
| 2931 | } |
| 2932 | } |
| 2933 | } |
| 2934 | |
Chong Zhang | 5dcb275 | 2015-08-18 13:50:26 -0700 | [diff] [blame] | 2935 | /** |
Winson Chung | 1dbc811 | 2017-09-28 18:05:31 -0700 | [diff] [blame] | 2936 | * Called to restore the state of the task into the stack that it's supposed to go into. |
| 2937 | * |
Chong Zhang | 5dcb275 | 2015-08-18 13:50:26 -0700 | [diff] [blame] | 2938 | * @param task The recent task to be restored. |
Wale Ogunwale | 0568aed | 2017-09-08 13:29:37 -0700 | [diff] [blame] | 2939 | * @param aOptions The activity options to use for restoration. |
Wale Ogunwale | ab5de37 | 2017-10-18 06:46:31 -0700 | [diff] [blame] | 2940 | * @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] | 2941 | * @return true if the task has been restored successfully. |
| 2942 | */ |
Wale Ogunwale | ab5de37 | 2017-10-18 06:46:31 -0700 | [diff] [blame] | 2943 | boolean restoreRecentTaskLocked(TaskRecord task, ActivityOptions aOptions, boolean onTop) { |
| 2944 | final ActivityStack stack = getLaunchStack(null, aOptions, task, onTop); |
Andrii Kulian | 02b7a83 | 2016-10-06 23:11:56 -0700 | [diff] [blame] | 2945 | final ActivityStack currentStack = task.getStack(); |
| 2946 | if (currentStack != null) { |
Wale Ogunwale | 706ed79 | 2015-08-02 10:29:44 -0700 | [diff] [blame] | 2947 | // 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] | 2948 | if (currentStack == stack) { |
Wale Ogunwale | 706ed79 | 2015-08-02 10:29:44 -0700 | [diff] [blame] | 2949 | // Nothing else to do since it is already restored in the right stack. |
| 2950 | return true; |
| 2951 | } |
| 2952 | // Remove current stack association, so we can re-associate the task with the |
| 2953 | // right stack below. |
Andrii Kulian | 02b7a83 | 2016-10-06 23:11:56 -0700 | [diff] [blame] | 2954 | currentStack.removeTask(task, "restoreRecentTaskLocked", REMOVE_TASK_MODE_MOVING); |
Wale Ogunwale | 706ed79 | 2015-08-02 10:29:44 -0700 | [diff] [blame] | 2955 | } |
| 2956 | |
Wale Ogunwale | ab5de37 | 2017-10-18 06:46:31 -0700 | [diff] [blame] | 2957 | stack.addTask(task, onTop, "restoreRecentTask"); |
Wale Ogunwale | e1fe7fa2 | 2016-12-15 18:27:00 -0800 | [diff] [blame] | 2958 | // TODO: move call for creation here and other place into Stack.addTask() |
Wale Ogunwale | ab5de37 | 2017-10-18 06:46:31 -0700 | [diff] [blame] | 2959 | task.createWindowContainer(onTop, true /* showForAllUsers */); |
Wale Ogunwale | ee006da | 2015-03-30 14:49:25 -0700 | [diff] [blame] | 2960 | if (DEBUG_RECENTS) Slog.v(TAG_RECENTS, |
| 2961 | "Added restored task=" + task + " to stack=" + stack); |
Wale Ogunwale | 7de0535 | 2014-12-12 15:21:33 -0800 | [diff] [blame] | 2962 | final ArrayList<ActivityRecord> activities = task.mActivities; |
| 2963 | for (int activityNdx = activities.size() - 1; activityNdx >= 0; --activityNdx) { |
Wale Ogunwale | 26c0dfe | 2016-12-14 14:42:30 -0800 | [diff] [blame] | 2964 | activities.get(activityNdx).createWindowContainer(); |
Wale Ogunwale | 7de0535 | 2014-12-12 15:21:33 -0800 | [diff] [blame] | 2965 | } |
| 2966 | return true; |
Craig Mautner | ef73ee1 | 2014-04-23 11:45:37 -0700 | [diff] [blame] | 2967 | } |
| 2968 | |
Winson Chung | 1dbc811 | 2017-09-28 18:05:31 -0700 | [diff] [blame] | 2969 | @Override |
| 2970 | public void onRecentTaskAdded(TaskRecord task) { |
| 2971 | task.touchActiveTime(); |
| 2972 | } |
| 2973 | |
| 2974 | @Override |
Winson Chung | d6aa3db | 2017-10-05 17:18:43 -0700 | [diff] [blame] | 2975 | public void onRecentTaskRemoved(TaskRecord task, boolean wasTrimmed) { |
Winson Chung | 0ec2a35 | 2017-10-26 11:38:30 -0700 | [diff] [blame] | 2976 | if (wasTrimmed) { |
| 2977 | // Task was trimmed from the recent tasks list -- remove the active task record as well |
| 2978 | // since the user won't really be able to go back to it |
| 2979 | removeTaskByIdLocked(task.taskId, false /* killProcess */, |
| 2980 | false /* removeFromRecents */, !PAUSE_IMMEDIATELY, "recent-task-trimmed"); |
| 2981 | } |
Winson Chung | 1dbc811 | 2017-09-28 18:05:31 -0700 | [diff] [blame] | 2982 | task.removedFromRecents(); |
| 2983 | } |
| 2984 | |
Wale Ogunwale | 040b470 | 2015-08-06 18:10:50 -0700 | [diff] [blame] | 2985 | /** |
Andrii Kulian | 839def9 | 2016-11-02 10:58:58 -0700 | [diff] [blame] | 2986 | * Move stack with all its existing content to specified display. |
| 2987 | * @param stackId Id of stack to move. |
| 2988 | * @param displayId Id of display to move stack to. |
Andrii Kulian | 250d653 | 2017-02-08 23:30:45 -0800 | [diff] [blame] | 2989 | * @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] | 2990 | */ |
Andrii Kulian | 250d653 | 2017-02-08 23:30:45 -0800 | [diff] [blame] | 2991 | void moveStackToDisplayLocked(int stackId, int displayId, boolean onTop) { |
Andrii Kulian | 62e6f25 | 2017-05-30 22:46:53 -0700 | [diff] [blame] | 2992 | final ActivityDisplay activityDisplay = getActivityDisplayOrCreateLocked(displayId); |
Andrii Kulian | 839def9 | 2016-11-02 10:58:58 -0700 | [diff] [blame] | 2993 | if (activityDisplay == null) { |
| 2994 | throw new IllegalArgumentException("moveStackToDisplayLocked: Unknown displayId=" |
| 2995 | + displayId); |
| 2996 | } |
Wale Ogunwale | 9dcf946 | 2017-09-19 15:13:01 -0700 | [diff] [blame] | 2997 | final ActivityStack stack = getStack(stackId); |
Andrii Kulian | 94e82d9b0 | 2017-07-13 15:33:06 -0700 | [diff] [blame] | 2998 | if (stack == null) { |
Andrii Kulian | 839def9 | 2016-11-02 10:58:58 -0700 | [diff] [blame] | 2999 | throw new IllegalArgumentException("moveStackToDisplayLocked: Unknown stackId=" |
| 3000 | + stackId); |
| 3001 | } |
Andrii Kulian | 94e82d9b0 | 2017-07-13 15:33:06 -0700 | [diff] [blame] | 3002 | |
| 3003 | final ActivityDisplay currentDisplay = stack.getDisplay(); |
| 3004 | if (currentDisplay == null) { |
| 3005 | throw new IllegalStateException("moveStackToDisplayLocked: Stack with stack=" + stack |
| 3006 | + " is not attached to any display."); |
| 3007 | } |
| 3008 | |
| 3009 | if (currentDisplay.mDisplayId == displayId) { |
| 3010 | throw new IllegalArgumentException("Trying to move stack=" + stack |
| 3011 | + " to its current displayId=" + displayId); |
| 3012 | } |
| 3013 | |
| 3014 | stack.reparent(activityDisplay, onTop); |
Andrii Kulian | 839def9 | 2016-11-02 10:58:58 -0700 | [diff] [blame] | 3015 | // TODO(multi-display): resize stacks properly if moved from split-screen. |
| 3016 | } |
| 3017 | |
| 3018 | /** |
Winson Chung | 7466610 | 2017-02-22 17:49:24 -0800 | [diff] [blame] | 3019 | * Returns the reparent target stack, creating the stack if necessary. This call also enforces |
| 3020 | * 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] | 3021 | */ |
Wale Ogunwale | 30e441d | 2017-11-09 08:28:45 -0800 | [diff] [blame] | 3022 | // TODO: Look into changing users to this method to ActivityDisplay.resolveWindowingMode() |
Wale Ogunwale | 04a05ac | 2017-09-17 21:35:02 -0700 | [diff] [blame] | 3023 | ActivityStack getReparentTargetStack(TaskRecord task, ActivityStack stack, boolean toTop) { |
Andrii Kulian | 02b7a83 | 2016-10-06 23:11:56 -0700 | [diff] [blame] | 3024 | final ActivityStack prevStack = task.getStack(); |
Wale Ogunwale | 04a05ac | 2017-09-17 21:35:02 -0700 | [diff] [blame] | 3025 | final int stackId = stack.mStackId; |
| 3026 | final boolean inMultiWindowMode = stack.inMultiWindowMode(); |
Chong Zhang | 0289835 | 2015-08-21 17:27:14 -0700 | [diff] [blame] | 3027 | |
Winson Chung | 7466610 | 2017-02-22 17:49:24 -0800 | [diff] [blame] | 3028 | // Check that we aren't reparenting to the same stack that the task is already in |
| 3029 | if (prevStack != null && prevStack.mStackId == stackId) { |
| 3030 | Slog.w(TAG, "Can not reparent to same stack, task=" + task |
| 3031 | + " already in stackId=" + stackId); |
| 3032 | return prevStack; |
Wale Ogunwale | 513346d | 2016-01-27 10:55:01 -0800 | [diff] [blame] | 3033 | } |
| 3034 | |
Winson Chung | 7466610 | 2017-02-22 17:49:24 -0800 | [diff] [blame] | 3035 | // Ensure that we aren't trying to move into a multi-window stack without multi-window |
| 3036 | // support |
Wale Ogunwale | 04a05ac | 2017-09-17 21:35:02 -0700 | [diff] [blame] | 3037 | if (inMultiWindowMode && !mService.mSupportsMultiWindow) { |
Winson Chung | 7466610 | 2017-02-22 17:49:24 -0800 | [diff] [blame] | 3038 | throw new IllegalArgumentException("Device doesn't support multi-window, can not" |
Wale Ogunwale | 04a05ac | 2017-09-17 21:35:02 -0700 | [diff] [blame] | 3039 | + " reparent task=" + task + " to stack=" + stack); |
Winson Chung | c2baac0 | 2017-01-11 13:34:47 -0800 | [diff] [blame] | 3040 | } |
| 3041 | |
Andrii Kulian | eafd9db | 2017-04-05 22:01:35 -0700 | [diff] [blame] | 3042 | // Ensure that we're not moving a task to a dynamic stack if device doesn't support |
| 3043 | // multi-display. |
Wale Ogunwale | 04a05ac | 2017-09-17 21:35:02 -0700 | [diff] [blame] | 3044 | if (stack.mDisplayId != DEFAULT_DISPLAY && !mService.mSupportsMultiDisplay) { |
Andrii Kulian | eafd9db | 2017-04-05 22:01:35 -0700 | [diff] [blame] | 3045 | throw new IllegalArgumentException("Device doesn't support multi-display, can not" |
| 3046 | + " reparent task=" + task + " to stackId=" + stackId); |
| 3047 | } |
| 3048 | |
Wale Ogunwale | 30e441d | 2017-11-09 08:28:45 -0800 | [diff] [blame] | 3049 | // 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] | 3050 | if (stack.getWindowingMode() == WINDOWING_MODE_FREEFORM |
| 3051 | && !mService.mSupportsFreeformWindowManagement) { |
Winson Chung | 7466610 | 2017-02-22 17:49:24 -0800 | [diff] [blame] | 3052 | throw new IllegalArgumentException("Device doesn't support freeform, can not reparent" |
| 3053 | + " task=" + task); |
Wale Ogunwale | 08559dc | 2016-02-23 12:20:08 -0800 | [diff] [blame] | 3054 | } |
| 3055 | |
Wale Ogunwale | 7e1f5f5 | 2017-10-18 15:19:59 -0700 | [diff] [blame] | 3056 | // Leave the task in its current stack or a fullscreen stack if it isn't resizeable and the |
| 3057 | // preferred stack is in multi-window mode. |
Wale Ogunwale | 04a05ac | 2017-09-17 21:35:02 -0700 | [diff] [blame] | 3058 | if (inMultiWindowMode && !task.isResizeable()) { |
Wale Ogunwale | 7e1f5f5 | 2017-10-18 15:19:59 -0700 | [diff] [blame] | 3059 | Slog.w(TAG, "Can not move unresizeable task=" + task + " to multi-window stack=" + stack |
| 3060 | + " Moving to a fullscreen stack instead."); |
| 3061 | if (prevStack != null) { |
| 3062 | return prevStack; |
Wale Ogunwale | 04a05ac | 2017-09-17 21:35:02 -0700 | [diff] [blame] | 3063 | } |
Wale Ogunwale | 7e1f5f5 | 2017-10-18 15:19:59 -0700 | [diff] [blame] | 3064 | stack = stack.getDisplay().createStack( |
| 3065 | WINDOWING_MODE_FULLSCREEN, stack.getActivityType(), toTop); |
Filip Gruszczynski | 49b80af | 2015-09-24 09:04:26 -0700 | [diff] [blame] | 3066 | } |
Wale Ogunwale | 04a05ac | 2017-09-17 21:35:02 -0700 | [diff] [blame] | 3067 | return stack; |
Craig Mautner | 8d341ef | 2013-03-26 09:03:27 -0700 | [diff] [blame] | 3068 | } |
| 3069 | |
Winson Chung | 08f8189 | 2017-03-02 15:40:51 -0800 | [diff] [blame] | 3070 | boolean moveTopStackActivityToPinnedStackLocked(int stackId, Rect destBounds) { |
Wale Ogunwale | 04a05ac | 2017-09-17 21:35:02 -0700 | [diff] [blame] | 3071 | final ActivityStack stack = getStack(stackId); |
Wale Ogunwale | 079a004 | 2015-10-24 11:44:07 -0700 | [diff] [blame] | 3072 | if (stack == null) { |
| 3073 | throw new IllegalArgumentException( |
| 3074 | "moveTopStackActivityToPinnedStackLocked: Unknown stackId=" + stackId); |
| 3075 | } |
| 3076 | |
| 3077 | final ActivityRecord r = stack.topRunningActivityLocked(); |
| 3078 | if (r == null) { |
| 3079 | Slog.w(TAG, "moveTopStackActivityToPinnedStackLocked: No top running activity" |
| 3080 | + " in stack=" + stack); |
| 3081 | return false; |
| 3082 | } |
| 3083 | |
Wale Ogunwale | 6cae765 | 2015-12-26 07:36:26 -0800 | [diff] [blame] | 3084 | if (!mService.mForceResizableActivities && !r.supportsPictureInPicture()) { |
Wale Ogunwale | b60692e | 2015-10-24 12:35:56 -0700 | [diff] [blame] | 3085 | Slog.w(TAG, |
| 3086 | "moveTopStackActivityToPinnedStackLocked: Picture-In-Picture not supported for " |
Filip Gruszczynski | 77d9448 | 2015-12-11 13:59:52 -0800 | [diff] [blame] | 3087 | + " r=" + r); |
Wale Ogunwale | 079a004 | 2015-10-24 11:44:07 -0700 | [diff] [blame] | 3088 | return false; |
| 3089 | } |
| 3090 | |
Winson Chung | 3a68287 | 2017-04-10 14:38:05 -0700 | [diff] [blame] | 3091 | moveActivityToPinnedStackLocked(r, null /* sourceBounds */, 0f /* aspectRatio */, |
Wale Ogunwale | 66e1685 | 2017-10-19 13:35:52 -0700 | [diff] [blame] | 3092 | "moveTopActivityToPinnedStack"); |
Wale Ogunwale | 9c604c7 | 2015-12-06 18:42:57 -0800 | [diff] [blame] | 3093 | return true; |
| 3094 | } |
| 3095 | |
Winson Chung | 8bca9e4 | 2017-04-16 15:59:43 -0700 | [diff] [blame] | 3096 | void moveActivityToPinnedStackLocked(ActivityRecord r, Rect sourceHintBounds, float aspectRatio, |
Wale Ogunwale | 66e1685 | 2017-10-19 13:35:52 -0700 | [diff] [blame] | 3097 | String reason) { |
Winson Chung | 08f8189 | 2017-03-02 15:40:51 -0800 | [diff] [blame] | 3098 | |
Wale Ogunwale | 480dca0 | 2016-02-06 13:58:29 -0800 | [diff] [blame] | 3099 | mWindowManager.deferSurfaceLayout(); |
Winson Chung | 7466610 | 2017-02-22 17:49:24 -0800 | [diff] [blame] | 3100 | |
Wale Ogunwale | 04a05ac | 2017-09-17 21:35:02 -0700 | [diff] [blame] | 3101 | final ActivityDisplay display = r.getStack().getDisplay(); |
| 3102 | PinnedActivityStack stack = display.getPinnedStack(); |
Wale Ogunwale | 9dcf946 | 2017-09-19 15:13:01 -0700 | [diff] [blame] | 3103 | |
Bryce Lee | 04ab346 | 2017-04-10 15:06:33 -0700 | [diff] [blame] | 3104 | // This will clear the pinned stack by moving an existing task to the full screen stack, |
| 3105 | // ensuring only one task is present. |
Wale Ogunwale | 9dcf946 | 2017-09-19 15:13:01 -0700 | [diff] [blame] | 3106 | if (stack != null) { |
| 3107 | moveTasksToFullscreenStackLocked(stack, !ON_TOP); |
| 3108 | } |
Bryce Lee | 04ab346 | 2017-04-10 15:06:33 -0700 | [diff] [blame] | 3109 | |
Wale Ogunwale | 1666e31 | 2016-12-16 11:27:18 -0800 | [diff] [blame] | 3110 | // 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] | 3111 | stack = display.getOrCreateStack(WINDOWING_MODE_PINNED, r.getActivityType(), ON_TOP); |
Wale Ogunwale | 1666e31 | 2016-12-16 11:27:18 -0800 | [diff] [blame] | 3112 | |
Winson Chung | e55c019 | 2017-08-24 14:50:48 -0700 | [diff] [blame] | 3113 | // Calculate the target bounds here before the task is reparented back into pinned windowing |
| 3114 | // mode (which will reset the saved bounds) |
| 3115 | final Rect destBounds = stack.getDefaultPictureInPictureBounds(aspectRatio); |
| 3116 | |
Wale Ogunwale | 480dca0 | 2016-02-06 13:58:29 -0800 | [diff] [blame] | 3117 | try { |
Bryce Lee | af691c0 | 2017-03-20 14:20:22 -0700 | [diff] [blame] | 3118 | final TaskRecord task = r.getTask(); |
Wale Ogunwale | 480dca0 | 2016-02-06 13:58:29 -0800 | [diff] [blame] | 3119 | // Resize the pinned stack to match the current size of the task the activity we are |
| 3120 | // going to be moving is currently contained in. We do this to have the right starting |
| 3121 | // 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] | 3122 | resizeStackLocked(stack, task.getOverrideBounds(), null /* tempTaskBounds */, |
Wale Ogunwale | 480dca0 | 2016-02-06 13:58:29 -0800 | [diff] [blame] | 3123 | null /* tempTaskInsetBounds */, !PRESERVE_WINDOWS, |
Wale Ogunwale | c8da41e | 2016-04-16 13:27:23 -0700 | [diff] [blame] | 3124 | true /* allowResizeInDockedMode */, !DEFER_RESUME); |
Wale Ogunwale | 480dca0 | 2016-02-06 13:58:29 -0800 | [diff] [blame] | 3125 | |
| 3126 | if (task.mActivities.size() == 1) { |
Winson Chung | 5af42fc | 2017-03-24 17:11:33 -0700 | [diff] [blame] | 3127 | // 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] | 3128 | task.reparent(stack, ON_TOP, REPARENT_MOVE_STACK_TO_FRONT, !ANIMATE, DEFER_RESUME, |
| 3129 | false /* schedulePictureInPictureModeChange */, reason); |
Wale Ogunwale | 480dca0 | 2016-02-06 13:58:29 -0800 | [diff] [blame] | 3130 | } else { |
Winson Chung | b5c41b7 | 2016-12-07 15:00:47 -0800 | [diff] [blame] | 3131 | // 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] | 3132 | // reveal/leave the other activities in their original task. |
| 3133 | |
| 3134 | // Currently, we don't support reparenting activities across tasks in two different |
| 3135 | // stacks, so instead, just create a new task in the same stack, reparent the |
| 3136 | // activity into that task, and then reparent the whole task to the new stack. This |
| 3137 | // ensures that all the necessary work to migrate states in the old and new stacks |
| 3138 | // is also done. |
| 3139 | final TaskRecord newTask = task.getStack().createTaskRecord( |
Wale Ogunwale | 6fbde9f | 2017-08-24 07:24:12 -0700 | [diff] [blame] | 3140 | getNextTaskIdForUserLocked(r.userId), r.info, r.intent, null, null, true); |
Winson Chung | 7466610 | 2017-02-22 17:49:24 -0800 | [diff] [blame] | 3141 | r.reparent(newTask, MAX_VALUE, "moveActivityToStack"); |
| 3142 | |
Winson Chung | 5af42fc | 2017-03-24 17:11:33 -0700 | [diff] [blame] | 3143 | // 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] | 3144 | newTask.reparent(stack, ON_TOP, REPARENT_MOVE_STACK_TO_FRONT, !ANIMATE, |
Winson Chung | 5af42fc | 2017-03-24 17:11:33 -0700 | [diff] [blame] | 3145 | DEFER_RESUME, false /* schedulePictureInPictureModeChange */, reason); |
Wale Ogunwale | 480dca0 | 2016-02-06 13:58:29 -0800 | [diff] [blame] | 3146 | } |
Winson Chung | c2baac0 | 2017-01-11 13:34:47 -0800 | [diff] [blame] | 3147 | |
| 3148 | // Reset the state that indicates it can enter PiP while pausing after we've moved it |
| 3149 | // to the pinned stack |
Winson Chung | f7e03e1 | 2017-08-22 11:32:16 -0700 | [diff] [blame] | 3150 | r.supportsEnterPipOnTaskSwitch = false; |
Wale Ogunwale | 480dca0 | 2016-02-06 13:58:29 -0800 | [diff] [blame] | 3151 | } finally { |
| 3152 | mWindowManager.continueSurfaceLayout(); |
Wale Ogunwale | 079a004 | 2015-10-24 11:44:07 -0700 | [diff] [blame] | 3153 | } |
| 3154 | |
Winson Chung | e7ba686 | 2017-05-24 12:13:33 -0700 | [diff] [blame] | 3155 | stack.animateResizePinnedStack(sourceHintBounds, destBounds, -1 /* animationDuration */, |
| 3156 | true /* fromFullscreen */); |
| 3157 | |
| 3158 | // Update the visibility of all activities after the they have been reparented to the new |
| 3159 | // stack. This MUST run after the animation above is scheduled to ensure that the windows |
| 3160 | // drawn signal is scheduled after the bounds animation start call on the bounds animator |
| 3161 | // thread. |
Wale Ogunwale | 079a004 | 2015-10-24 11:44:07 -0700 | [diff] [blame] | 3162 | ensureActivitiesVisibleLocked(null, 0, !PRESERVE_WINDOWS); |
Wale Ogunwale | d046a01 | 2015-12-24 13:05:59 -0800 | [diff] [blame] | 3163 | resumeFocusedStackTopActivityLocked(); |
Wale Ogunwale | 03ce863 | 2015-12-29 16:15:22 -0800 | [diff] [blame] | 3164 | |
Wale Ogunwale | 89be576 | 2017-10-04 13:27:49 -0700 | [diff] [blame] | 3165 | mService.mTaskChangeNotificationController.notifyActivityPinned(r); |
Wale Ogunwale | 079a004 | 2015-10-24 11:44:07 -0700 | [diff] [blame] | 3166 | } |
| 3167 | |
Andrii Kulian | 0864bbb | 2017-02-16 15:45:58 -0800 | [diff] [blame] | 3168 | /** Move activity with its stack to front and make the stack focused. */ |
Chong Zhang | 6cda19c | 2016-06-14 19:07:56 -0700 | [diff] [blame] | 3169 | boolean moveFocusableActivityStackToFrontLocked(ActivityRecord r, String reason) { |
| 3170 | if (r == null || !r.isFocusable()) { |
| 3171 | if (DEBUG_FOCUS) Slog.d(TAG_FOCUS, |
| 3172 | "moveActivityStackToFront: unfocusable r=" + r); |
| 3173 | return false; |
| 3174 | } |
| 3175 | |
Bryce Lee | af691c0 | 2017-03-20 14:20:22 -0700 | [diff] [blame] | 3176 | final TaskRecord task = r.getTask(); |
Andrii Kulian | 02b7a83 | 2016-10-06 23:11:56 -0700 | [diff] [blame] | 3177 | final ActivityStack stack = r.getStack(); |
| 3178 | if (stack == null) { |
Chong Zhang | 6cda19c | 2016-06-14 19:07:56 -0700 | [diff] [blame] | 3179 | Slog.w(TAG, "moveActivityStackToFront: invalid task or stack: r=" |
| 3180 | + r + " task=" + task); |
| 3181 | return false; |
| 3182 | } |
| 3183 | |
Chong Zhang | 6cda19c | 2016-06-14 19:07:56 -0700 | [diff] [blame] | 3184 | if (stack == mFocusedStack && stack.topRunningActivityLocked() == r) { |
| 3185 | if (DEBUG_FOCUS) Slog.d(TAG_FOCUS, |
| 3186 | "moveActivityStackToFront: already on top, r=" + r); |
| 3187 | return false; |
| 3188 | } |
| 3189 | |
| 3190 | if (DEBUG_FOCUS) Slog.d(TAG_FOCUS, |
| 3191 | "moveActivityStackToFront: r=" + r); |
| 3192 | |
| 3193 | stack.moveToFront(reason, task); |
| 3194 | return true; |
| 3195 | } |
| 3196 | |
David Stevens | c6b91c6 | 2017-02-08 14:23:58 -0800 | [diff] [blame] | 3197 | ActivityRecord findTaskLocked(ActivityRecord r, int displayId) { |
Wale Ogunwale | 3938197 | 2015-12-17 17:15:29 -0800 | [diff] [blame] | 3198 | mTmpFindTaskResult.r = null; |
| 3199 | mTmpFindTaskResult.matchedByRootAffinity = false; |
David Stevens | c6b91c6 | 2017-02-08 14:23:58 -0800 | [diff] [blame] | 3200 | ActivityRecord affinityMatch = null; |
Wale Ogunwale | ee006da | 2015-03-30 14:49:25 -0700 | [diff] [blame] | 3201 | if (DEBUG_TASKS) Slog.d(TAG_TASKS, "Looking for task of " + r); |
Craig Mautner | e0a3884 | 2013-12-16 16:14:02 -0800 | [diff] [blame] | 3202 | for (int displayNdx = mActivityDisplays.size() - 1; displayNdx >= 0; --displayNdx) { |
Wale Ogunwale | a0f5b5e | 2017-10-11 09:37:23 -0700 | [diff] [blame] | 3203 | final ActivityDisplay display = mActivityDisplays.valueAt(displayNdx); |
| 3204 | for (int stackNdx = display.getChildCount() - 1; stackNdx >= 0; --stackNdx) { |
| 3205 | final ActivityStack stack = display.getChildAt(stackNdx); |
Wale Ogunwale | 6fbde9f | 2017-08-24 07:24:12 -0700 | [diff] [blame] | 3206 | if (!r.hasCompatibleActivityType(stack)) { |
Winson Chung | 91e5c88 | 2017-04-21 14:44:38 -0700 | [diff] [blame] | 3207 | if (DEBUG_TASKS) Slog.d(TAG_TASKS, "Skipping stack: (mismatch activity/stack) " |
| 3208 | + stack); |
Craig Mautner | 1b4bf85 | 2014-05-26 15:06:32 -0700 | [diff] [blame] | 3209 | continue; |
| 3210 | } |
Wale Ogunwale | 3938197 | 2015-12-17 17:15:29 -0800 | [diff] [blame] | 3211 | stack.findTaskLocked(r, mTmpFindTaskResult); |
David Stevens | c6b91c6 | 2017-02-08 14:23:58 -0800 | [diff] [blame] | 3212 | // It is possible to have tasks in multiple stacks with the same root affinity, so |
| 3213 | // we should keep looking after finding an affinity match to see if there is a |
| 3214 | // better match in another stack. Also, task affinity isn't a good enough reason |
| 3215 | // to target a display which isn't the source of the intent, so skip any affinity |
| 3216 | // matches not on the specified display. |
| 3217 | if (mTmpFindTaskResult.r != null) { |
| 3218 | if (!mTmpFindTaskResult.matchedByRootAffinity) { |
| 3219 | return mTmpFindTaskResult.r; |
| 3220 | } else if (mTmpFindTaskResult.r.getDisplayId() == displayId) { |
Winson Chung | 5b895b7 | 2017-05-01 13:46:25 -0700 | [diff] [blame] | 3221 | // Note: since the traversing through the stacks is top down, the floating |
| 3222 | // tasks should always have lower priority than any affinity-matching tasks |
| 3223 | // in the fullscreen stacks |
David Stevens | c6b91c6 | 2017-02-08 14:23:58 -0800 | [diff] [blame] | 3224 | affinityMatch = mTmpFindTaskResult.r; |
David Stevens | e5a7b64 | 2017-05-22 13:18:23 -0700 | [diff] [blame] | 3225 | } else if (DEBUG_TASKS && mTmpFindTaskResult.matchedByRootAffinity) { |
| 3226 | Slog.d(TAG_TASKS, "Skipping match on different display " |
| 3227 | + mTmpFindTaskResult.r.getDisplayId() + " " + displayId); |
David Stevens | c6b91c6 | 2017-02-08 14:23:58 -0800 | [diff] [blame] | 3228 | } |
Craig Mautner | 4a1cb22 | 2013-12-04 16:14:06 -0800 | [diff] [blame] | 3229 | } |
Craig Mautner | 8849a5e | 2013-04-02 16:41:03 -0700 | [diff] [blame] | 3230 | } |
| 3231 | } |
Winson Chung | 5b895b7 | 2017-05-01 13:46:25 -0700 | [diff] [blame] | 3232 | |
David Stevens | c6b91c6 | 2017-02-08 14:23:58 -0800 | [diff] [blame] | 3233 | if (DEBUG_TASKS && affinityMatch == null) Slog.d(TAG_TASKS, "No task found"); |
| 3234 | return affinityMatch; |
Craig Mautner | 8849a5e | 2013-04-02 16:41:03 -0700 | [diff] [blame] | 3235 | } |
| 3236 | |
Andrii Kulian | d3bbb13 | 2016-06-16 16:00:20 -0700 | [diff] [blame] | 3237 | ActivityRecord findActivityLocked(Intent intent, ActivityInfo info, |
Wale Ogunwale | a0f5b5e | 2017-10-11 09:37:23 -0700 | [diff] [blame] | 3238 | boolean compareIntentFilters) { |
Craig Mautner | e0a3884 | 2013-12-16 16:14:02 -0800 | [diff] [blame] | 3239 | for (int displayNdx = mActivityDisplays.size() - 1; displayNdx >= 0; --displayNdx) { |
Wale Ogunwale | a0f5b5e | 2017-10-11 09:37:23 -0700 | [diff] [blame] | 3240 | final ActivityDisplay display = mActivityDisplays.valueAt(displayNdx); |
| 3241 | for (int stackNdx = display.getChildCount() - 1; stackNdx >= 0; --stackNdx) { |
| 3242 | final ActivityStack stack = display.getChildAt(stackNdx); |
| 3243 | final ActivityRecord ar = stack.findActivityLocked( |
| 3244 | intent, info, compareIntentFilters); |
Craig Mautner | 4a1cb22 | 2013-12-04 16:14:06 -0800 | [diff] [blame] | 3245 | if (ar != null) { |
| 3246 | return ar; |
| 3247 | } |
Craig Mautner | 8849a5e | 2013-04-02 16:41:03 -0700 | [diff] [blame] | 3248 | } |
| 3249 | } |
| 3250 | return null; |
| 3251 | } |
| 3252 | |
David Stevens | 9440dc8 | 2017-03-16 19:00:20 -0700 | [diff] [blame] | 3253 | boolean hasAwakeDisplay() { |
| 3254 | for (int displayNdx = mActivityDisplays.size() - 1; displayNdx >= 0; --displayNdx) { |
| 3255 | final ActivityDisplay display = mActivityDisplays.valueAt(displayNdx); |
| 3256 | if (!display.shouldSleep()) { |
| 3257 | return true; |
| 3258 | } |
| 3259 | } |
| 3260 | return false; |
| 3261 | } |
| 3262 | |
Craig Mautner | 8d341ef | 2013-03-26 09:03:27 -0700 | [diff] [blame] | 3263 | void goingToSleepLocked() { |
Craig Mautner | 0eea92c | 2013-05-16 13:35:39 -0700 | [diff] [blame] | 3264 | scheduleSleepTimeout(); |
| 3265 | if (!mGoingToSleep.isHeld()) { |
| 3266 | mGoingToSleep.acquire(); |
Craig Mautner | 7ea5bd4 | 2013-07-05 15:27:08 -0700 | [diff] [blame] | 3267 | if (mLaunchingActivity.isHeld()) { |
| 3268 | if (VALIDATE_WAKE_LOCK_CALLER && Binder.getCallingUid() != Process.myUid()) { |
| 3269 | throw new IllegalStateException("Calling must be system uid"); |
Craig Mautner | 0eea92c | 2013-05-16 13:35:39 -0700 | [diff] [blame] | 3270 | } |
Craig Mautner | 7ea5bd4 | 2013-07-05 15:27:08 -0700 | [diff] [blame] | 3271 | mLaunchingActivity.release(); |
| 3272 | mService.mHandler.removeMessages(LAUNCH_TIMEOUT_MSG); |
Craig Mautner | 0eea92c | 2013-05-16 13:35:39 -0700 | [diff] [blame] | 3273 | } |
Craig Mautner | 8d341ef | 2013-03-26 09:03:27 -0700 | [diff] [blame] | 3274 | } |
David Stevens | 9440dc8 | 2017-03-16 19:00:20 -0700 | [diff] [blame] | 3275 | |
| 3276 | applySleepTokensLocked(false /* applyToStacks */); |
| 3277 | |
| 3278 | checkReadyForSleepLocked(true /* allowDelay */); |
| 3279 | } |
| 3280 | |
| 3281 | void prepareForShutdownLocked() { |
| 3282 | for (int i = 0; i < mActivityDisplays.size(); i++) { |
| 3283 | createSleepTokenLocked("shutdown", mActivityDisplays.keyAt(i)); |
| 3284 | } |
Craig Mautner | 8d341ef | 2013-03-26 09:03:27 -0700 | [diff] [blame] | 3285 | } |
| 3286 | |
| 3287 | boolean shutdownLocked(int timeout) { |
Craig Mautner | 0eea92c | 2013-05-16 13:35:39 -0700 | [diff] [blame] | 3288 | goingToSleepLocked(); |
Craig Mautner | 0eea92c | 2013-05-16 13:35:39 -0700 | [diff] [blame] | 3289 | |
Craig Mautner | f4c909b | 2014-04-17 18:39:38 -0700 | [diff] [blame] | 3290 | boolean timedout = false; |
Craig Mautner | 0eea92c | 2013-05-16 13:35:39 -0700 | [diff] [blame] | 3291 | final long endTime = System.currentTimeMillis() + timeout; |
| 3292 | while (true) { |
David Stevens | 18abd0e | 2017-08-17 14:55:47 -0700 | [diff] [blame] | 3293 | if (!putStacksToSleepLocked(true /* allowDelay */, true /* shuttingDown */)) { |
Craig Mautner | 0eea92c | 2013-05-16 13:35:39 -0700 | [diff] [blame] | 3294 | long timeRemaining = endTime - System.currentTimeMillis(); |
| 3295 | if (timeRemaining > 0) { |
Craig Mautner | 8d341ef | 2013-03-26 09:03:27 -0700 | [diff] [blame] | 3296 | try { |
Craig Mautner | 0eea92c | 2013-05-16 13:35:39 -0700 | [diff] [blame] | 3297 | mService.wait(timeRemaining); |
Craig Mautner | 8d341ef | 2013-03-26 09:03:27 -0700 | [diff] [blame] | 3298 | } catch (InterruptedException e) { |
| 3299 | } |
Craig Mautner | 0eea92c | 2013-05-16 13:35:39 -0700 | [diff] [blame] | 3300 | } else { |
| 3301 | Slog.w(TAG, "Activity manager shutdown timed out"); |
| 3302 | timedout = true; |
| 3303 | break; |
Craig Mautner | 8d341ef | 2013-03-26 09:03:27 -0700 | [diff] [blame] | 3304 | } |
Craig Mautner | 0eea92c | 2013-05-16 13:35:39 -0700 | [diff] [blame] | 3305 | } else { |
| 3306 | break; |
Craig Mautner | 8d341ef | 2013-03-26 09:03:27 -0700 | [diff] [blame] | 3307 | } |
| 3308 | } |
Craig Mautner | 0eea92c | 2013-05-16 13:35:39 -0700 | [diff] [blame] | 3309 | |
| 3310 | // Force checkReadyForSleep to complete. |
David Stevens | 9440dc8 | 2017-03-16 19:00:20 -0700 | [diff] [blame] | 3311 | checkReadyForSleepLocked(false /* allowDelay */); |
Craig Mautner | 0eea92c | 2013-05-16 13:35:39 -0700 | [diff] [blame] | 3312 | |
Craig Mautner | 8d341ef | 2013-03-26 09:03:27 -0700 | [diff] [blame] | 3313 | return timedout; |
| 3314 | } |
| 3315 | |
| 3316 | void comeOutOfSleepIfNeededLocked() { |
Craig Mautner | 0eea92c | 2013-05-16 13:35:39 -0700 | [diff] [blame] | 3317 | removeSleepTimeouts(); |
| 3318 | if (mGoingToSleep.isHeld()) { |
| 3319 | mGoingToSleep.release(); |
| 3320 | } |
David Stevens | 9440dc8 | 2017-03-16 19:00:20 -0700 | [diff] [blame] | 3321 | } |
| 3322 | |
| 3323 | void applySleepTokensLocked(boolean applyToStacks) { |
Craig Mautner | e0a3884 | 2013-12-16 16:14:02 -0800 | [diff] [blame] | 3324 | for (int displayNdx = mActivityDisplays.size() - 1; displayNdx >= 0; --displayNdx) { |
David Stevens | 9440dc8 | 2017-03-16 19:00:20 -0700 | [diff] [blame] | 3325 | // Set the sleeping state of the display. |
| 3326 | final ActivityDisplay display = mActivityDisplays.valueAt(displayNdx); |
| 3327 | final boolean displayShouldSleep = display.shouldSleep(); |
| 3328 | if (displayShouldSleep == display.isSleeping()) { |
| 3329 | continue; |
| 3330 | } |
| 3331 | display.setIsSleeping(displayShouldSleep); |
| 3332 | |
| 3333 | if (!applyToStacks) { |
| 3334 | continue; |
| 3335 | } |
| 3336 | |
| 3337 | // Set the sleeping state of the stacks on the display. |
Wale Ogunwale | a0f5b5e | 2017-10-11 09:37:23 -0700 | [diff] [blame] | 3338 | for (int stackNdx = display.getChildCount() - 1; stackNdx >= 0; --stackNdx) { |
| 3339 | final ActivityStack stack = display.getChildAt(stackNdx); |
David Stevens | 9440dc8 | 2017-03-16 19:00:20 -0700 | [diff] [blame] | 3340 | if (displayShouldSleep) { |
| 3341 | stack.goToSleepIfPossible(false /* shuttingDown */); |
| 3342 | } else { |
| 3343 | stack.awakeFromSleepingLocked(); |
| 3344 | if (isFocusedStack(stack)) { |
| 3345 | resumeFocusedStackTopActivityLocked(); |
| 3346 | } |
| 3347 | } |
| 3348 | } |
| 3349 | |
| 3350 | if (displayShouldSleep || mGoingToSleepActivities.isEmpty()) { |
| 3351 | continue; |
| 3352 | } |
| 3353 | // The display is awake now, so clean up the going to sleep list. |
| 3354 | for (Iterator<ActivityRecord> it = mGoingToSleepActivities.iterator(); it.hasNext(); ) { |
| 3355 | final ActivityRecord r = it.next(); |
| 3356 | if (r.getDisplayId() == display.mDisplayId) { |
| 3357 | it.remove(); |
Craig Mautner | 4a1cb22 | 2013-12-04 16:14:06 -0800 | [diff] [blame] | 3358 | } |
Craig Mautner | 5314a40 | 2013-09-26 12:40:16 -0700 | [diff] [blame] | 3359 | } |
Craig Mautner | 8d341ef | 2013-03-26 09:03:27 -0700 | [diff] [blame] | 3360 | } |
Craig Mautner | 0eea92c | 2013-05-16 13:35:39 -0700 | [diff] [blame] | 3361 | } |
| 3362 | |
| 3363 | void activitySleptLocked(ActivityRecord r) { |
| 3364 | mGoingToSleepActivities.remove(r); |
David Stevens | 9440dc8 | 2017-03-16 19:00:20 -0700 | [diff] [blame] | 3365 | final ActivityStack s = r.getStack(); |
| 3366 | if (s != null) { |
| 3367 | s.checkReadyForSleep(); |
| 3368 | } else { |
| 3369 | checkReadyForSleepLocked(true); |
| 3370 | } |
Craig Mautner | 0eea92c | 2013-05-16 13:35:39 -0700 | [diff] [blame] | 3371 | } |
| 3372 | |
David Stevens | 9440dc8 | 2017-03-16 19:00:20 -0700 | [diff] [blame] | 3373 | void checkReadyForSleepLocked(boolean allowDelay) { |
Fyodor Kupolov | 9b80b94 | 2016-06-16 16:29:05 -0700 | [diff] [blame] | 3374 | if (!mService.isSleepingOrShuttingDownLocked()) { |
Craig Mautner | 0eea92c | 2013-05-16 13:35:39 -0700 | [diff] [blame] | 3375 | // Do not care. |
| 3376 | return; |
| 3377 | } |
| 3378 | |
David Stevens | 18abd0e | 2017-08-17 14:55:47 -0700 | [diff] [blame] | 3379 | if (!putStacksToSleepLocked(allowDelay, false /* shuttingDown */)) { |
| 3380 | return; |
Craig Mautner | 0eea92c | 2013-05-16 13:35:39 -0700 | [diff] [blame] | 3381 | } |
| 3382 | |
Wei Wang | 65c7a15 | 2016-06-02 18:51:22 -0700 | [diff] [blame] | 3383 | // Send launch end powerhint before going sleep |
Bryce Lee | d3624e1 | 2017-11-30 08:51:45 -0800 | [diff] [blame] | 3384 | sendPowerHintForLaunchEndIfNeeded(); |
Wei Wang | 65c7a15 | 2016-06-02 18:51:22 -0700 | [diff] [blame] | 3385 | |
Craig Mautner | 0eea92c | 2013-05-16 13:35:39 -0700 | [diff] [blame] | 3386 | removeSleepTimeouts(); |
| 3387 | |
| 3388 | if (mGoingToSleep.isHeld()) { |
| 3389 | mGoingToSleep.release(); |
| 3390 | } |
| 3391 | if (mService.mShuttingDown) { |
| 3392 | mService.notifyAll(); |
| 3393 | } |
Craig Mautner | 8d341ef | 2013-03-26 09:03:27 -0700 | [diff] [blame] | 3394 | } |
| 3395 | |
David Stevens | 18abd0e | 2017-08-17 14:55:47 -0700 | [diff] [blame] | 3396 | // Tries to put all activity stacks to sleep. Returns true if all stacks were |
| 3397 | // successfully put to sleep. |
| 3398 | private boolean putStacksToSleepLocked(boolean allowDelay, boolean shuttingDown) { |
| 3399 | boolean allSleep = true; |
| 3400 | for (int displayNdx = mActivityDisplays.size() - 1; displayNdx >= 0; --displayNdx) { |
Wale Ogunwale | a0f5b5e | 2017-10-11 09:37:23 -0700 | [diff] [blame] | 3401 | final ActivityDisplay display = mActivityDisplays.valueAt(displayNdx); |
| 3402 | for (int stackNdx = display.getChildCount() - 1; stackNdx >= 0; --stackNdx) { |
| 3403 | final ActivityStack stack = display.getChildAt(stackNdx); |
David Stevens | 18abd0e | 2017-08-17 14:55:47 -0700 | [diff] [blame] | 3404 | if (allowDelay) { |
Wale Ogunwale | a0f5b5e | 2017-10-11 09:37:23 -0700 | [diff] [blame] | 3405 | allSleep &= stack.goToSleepIfPossible(shuttingDown); |
David Stevens | 18abd0e | 2017-08-17 14:55:47 -0700 | [diff] [blame] | 3406 | } else { |
Wale Ogunwale | a0f5b5e | 2017-10-11 09:37:23 -0700 | [diff] [blame] | 3407 | stack.goToSleep(); |
David Stevens | 18abd0e | 2017-08-17 14:55:47 -0700 | [diff] [blame] | 3408 | } |
| 3409 | } |
| 3410 | } |
| 3411 | return allSleep; |
| 3412 | } |
| 3413 | |
Craig Mautner | ce5f3cb | 2013-04-22 08:58:54 -0700 | [diff] [blame] | 3414 | boolean reportResumedActivityLocked(ActivityRecord r) { |
Bryce Lee | 29a649d | 2017-08-18 13:52:31 -0700 | [diff] [blame] | 3415 | // A resumed activity cannot be stopping. remove from list |
| 3416 | mStoppingActivities.remove(r); |
| 3417 | |
Andrii Kulian | 02b7a83 | 2016-10-06 23:11:56 -0700 | [diff] [blame] | 3418 | final ActivityStack stack = r.getStack(); |
Wale Ogunwale | 1e60e0c | 2015-10-28 13:36:10 -0700 | [diff] [blame] | 3419 | if (isFocusedStack(stack)) { |
Jeff Sharkey | 5782da7 | 2013-04-25 14:32:30 -0700 | [diff] [blame] | 3420 | mService.updateUsageStats(r, true); |
Craig Mautner | ce5f3cb | 2013-04-22 08:58:54 -0700 | [diff] [blame] | 3421 | } |
| 3422 | if (allResumedActivitiesComplete()) { |
Filip Gruszczynski | bc5a6c5 | 2015-09-22 13:13:24 -0700 | [diff] [blame] | 3423 | ensureActivitiesVisibleLocked(null, 0, !PRESERVE_WINDOWS); |
Craig Mautner | ce5f3cb | 2013-04-22 08:58:54 -0700 | [diff] [blame] | 3424 | mWindowManager.executeAppTransition(); |
| 3425 | return true; |
| 3426 | } |
| 3427 | return false; |
| 3428 | } |
| 3429 | |
Craig Mautner | 8d341ef | 2013-03-26 09:03:27 -0700 | [diff] [blame] | 3430 | void handleAppCrashLocked(ProcessRecord app) { |
Craig Mautner | e0a3884 | 2013-12-16 16:14:02 -0800 | [diff] [blame] | 3431 | for (int displayNdx = mActivityDisplays.size() - 1; displayNdx >= 0; --displayNdx) { |
Wale Ogunwale | a0f5b5e | 2017-10-11 09:37:23 -0700 | [diff] [blame] | 3432 | final ActivityDisplay display = mActivityDisplays.valueAt(displayNdx); |
| 3433 | for (int stackNdx = display.getChildCount() - 1; stackNdx >= 0; --stackNdx) { |
| 3434 | final ActivityStack stack = display.getChildAt(stackNdx); |
| 3435 | stack.handleAppCrashLocked(app); |
Craig Mautner | 4a1cb22 | 2013-12-04 16:14:06 -0800 | [diff] [blame] | 3436 | } |
Craig Mautner | 8d341ef | 2013-03-26 09:03:27 -0700 | [diff] [blame] | 3437 | } |
| 3438 | } |
| 3439 | |
Craig Mautner | bb74246 | 2014-07-07 15:28:55 -0700 | [diff] [blame] | 3440 | // Called when WindowManager has finished animating the launchingBehind activity to the back. |
Andrii Kulian | 21713ac | 2016-10-12 22:05:05 -0700 | [diff] [blame] | 3441 | private void handleLaunchTaskBehindCompleteLocked(ActivityRecord r) { |
Bryce Lee | af691c0 | 2017-03-20 14:20:22 -0700 | [diff] [blame] | 3442 | final TaskRecord task = r.getTask(); |
Andrii Kulian | 02b7a83 | 2016-10-06 23:11:56 -0700 | [diff] [blame] | 3443 | final ActivityStack stack = task.getStack(); |
Winson | 730bf06 | 2016-03-31 18:04:56 -0700 | [diff] [blame] | 3444 | |
| 3445 | r.mLaunchTaskBehind = false; |
Winson Chung | 1dbc811 | 2017-09-28 18:05:31 -0700 | [diff] [blame] | 3446 | mRecentTasks.add(task); |
Yorke Lee | bd54c2a | 2016-10-25 13:49:23 -0700 | [diff] [blame] | 3447 | mService.mTaskChangeNotificationController.notifyTaskStackChanged(); |
Wale Ogunwale | 26c0dfe | 2016-12-14 14:42:30 -0800 | [diff] [blame] | 3448 | r.setVisibility(false); |
Winson | 730bf06 | 2016-03-31 18:04:56 -0700 | [diff] [blame] | 3449 | |
| 3450 | // When launching tasks behind, update the last active time of the top task after the new |
| 3451 | // task has been shown briefly |
Wale Ogunwale | 30e441d | 2017-11-09 08:28:45 -0800 | [diff] [blame] | 3452 | final ActivityRecord top = stack.getTopActivity(); |
Winson | 730bf06 | 2016-03-31 18:04:56 -0700 | [diff] [blame] | 3453 | if (top != null) { |
Bryce Lee | af691c0 | 2017-03-20 14:20:22 -0700 | [diff] [blame] | 3454 | top.getTask().touchActiveTime(); |
Winson | 730bf06 | 2016-03-31 18:04:56 -0700 | [diff] [blame] | 3455 | } |
Craig Mautner | bb74246 | 2014-07-07 15:28:55 -0700 | [diff] [blame] | 3456 | } |
| 3457 | |
| 3458 | void scheduleLaunchTaskBehindComplete(IBinder token) { |
| 3459 | mHandler.obtainMessage(LAUNCH_TASK_BEHIND_COMPLETE, token).sendToTarget(); |
| 3460 | } |
| 3461 | |
Filip Gruszczynski | bc5a6c5 | 2015-09-22 13:13:24 -0700 | [diff] [blame] | 3462 | void ensureActivitiesVisibleLocked(ActivityRecord starting, int configChanges, |
| 3463 | boolean preserveWindows) { |
Jorim Jaggi | fe76234 | 2016-10-13 14:33:27 +0200 | [diff] [blame] | 3464 | mKeyguardController.beginActivityVisibilityUpdate(); |
| 3465 | try { |
| 3466 | // First the front stacks. In case any are not fullscreen and are in front of home. |
| 3467 | for (int displayNdx = mActivityDisplays.size() - 1; displayNdx >= 0; --displayNdx) { |
Wale Ogunwale | a0f5b5e | 2017-10-11 09:37:23 -0700 | [diff] [blame] | 3468 | final ActivityDisplay display = mActivityDisplays.valueAt(displayNdx); |
| 3469 | for (int stackNdx = display.getChildCount() - 1; stackNdx >= 0; --stackNdx) { |
| 3470 | final ActivityStack stack = display.getChildAt(stackNdx); |
Jorim Jaggi | fe76234 | 2016-10-13 14:33:27 +0200 | [diff] [blame] | 3471 | stack.ensureActivitiesVisibleLocked(starting, configChanges, preserveWindows); |
| 3472 | } |
Craig Mautner | 580ea81 | 2013-04-25 12:58:38 -0700 | [diff] [blame] | 3473 | } |
Jorim Jaggi | fe76234 | 2016-10-13 14:33:27 +0200 | [diff] [blame] | 3474 | } finally { |
| 3475 | mKeyguardController.endActivityVisibilityUpdate(); |
Craig Mautner | 8d341ef | 2013-03-26 09:03:27 -0700 | [diff] [blame] | 3476 | } |
Craig Mautner | 8d341ef | 2013-03-26 09:03:27 -0700 | [diff] [blame] | 3477 | } |
| 3478 | |
Jorim Jaggi | 8b702ed | 2017-01-20 16:59:03 +0100 | [diff] [blame] | 3479 | void addStartingWindowsForVisibleActivities(boolean taskSwitch) { |
| 3480 | for (int displayNdx = mActivityDisplays.size() - 1; displayNdx >= 0; --displayNdx) { |
Wale Ogunwale | a0f5b5e | 2017-10-11 09:37:23 -0700 | [diff] [blame] | 3481 | final ActivityDisplay display = mActivityDisplays.valueAt(displayNdx); |
| 3482 | for (int stackNdx = display.getChildCount() - 1; stackNdx >= 0; --stackNdx) { |
| 3483 | final ActivityStack stack = display.getChildAt(stackNdx); |
Jorim Jaggi | 8b702ed | 2017-01-20 16:59:03 +0100 | [diff] [blame] | 3484 | stack.addStartingWindowsForVisibleActivities(taskSwitch); |
| 3485 | } |
| 3486 | } |
| 3487 | } |
| 3488 | |
Chong Zhang | fdcc4d4 | 2015-10-14 16:50:12 -0700 | [diff] [blame] | 3489 | void invalidateTaskLayers() { |
| 3490 | mTaskLayersChanged = true; |
| 3491 | } |
| 3492 | |
| 3493 | void rankTaskLayersIfNeeded() { |
| 3494 | if (!mTaskLayersChanged) { |
| 3495 | return; |
| 3496 | } |
| 3497 | mTaskLayersChanged = false; |
| 3498 | for (int displayNdx = 0; displayNdx < mActivityDisplays.size(); displayNdx++) { |
Wale Ogunwale | a0f5b5e | 2017-10-11 09:37:23 -0700 | [diff] [blame] | 3499 | final ActivityDisplay display = mActivityDisplays.valueAt(displayNdx); |
Chong Zhang | fdcc4d4 | 2015-10-14 16:50:12 -0700 | [diff] [blame] | 3500 | int baseLayer = 0; |
Wale Ogunwale | a0f5b5e | 2017-10-11 09:37:23 -0700 | [diff] [blame] | 3501 | for (int stackNdx = display.getChildCount() - 1; stackNdx >= 0; --stackNdx) { |
| 3502 | final ActivityStack stack = display.getChildAt(stackNdx); |
| 3503 | baseLayer += stack.rankTaskLayers(baseLayer); |
Chong Zhang | fdcc4d4 | 2015-10-14 16:50:12 -0700 | [diff] [blame] | 3504 | } |
| 3505 | } |
| 3506 | } |
| 3507 | |
Dianne Hackborn | b5a380d | 2015-05-20 18:18:46 -0700 | [diff] [blame] | 3508 | void clearOtherAppTimeTrackers(AppTimeTracker except) { |
| 3509 | for (int displayNdx = mActivityDisplays.size() - 1; displayNdx >= 0; --displayNdx) { |
Wale Ogunwale | a0f5b5e | 2017-10-11 09:37:23 -0700 | [diff] [blame] | 3510 | final ActivityDisplay display = mActivityDisplays.valueAt(displayNdx); |
| 3511 | for (int stackNdx = display.getChildCount() - 1; stackNdx >= 0; --stackNdx) { |
| 3512 | final ActivityStack stack = display.getChildAt(stackNdx); |
Dianne Hackborn | b5a380d | 2015-05-20 18:18:46 -0700 | [diff] [blame] | 3513 | stack.clearOtherAppTimeTrackers(except); |
| 3514 | } |
| 3515 | } |
| 3516 | } |
| 3517 | |
Craig Mautner | 8d341ef | 2013-03-26 09:03:27 -0700 | [diff] [blame] | 3518 | void scheduleDestroyAllActivities(ProcessRecord app, String reason) { |
Craig Mautner | e0a3884 | 2013-12-16 16:14:02 -0800 | [diff] [blame] | 3519 | for (int displayNdx = mActivityDisplays.size() - 1; displayNdx >= 0; --displayNdx) { |
Wale Ogunwale | a0f5b5e | 2017-10-11 09:37:23 -0700 | [diff] [blame] | 3520 | final ActivityDisplay display = mActivityDisplays.valueAt(displayNdx); |
| 3521 | for (int stackNdx = display.getChildCount() - 1; stackNdx >= 0; --stackNdx) { |
| 3522 | final ActivityStack stack = display.getChildAt(stackNdx); |
Craig Mautner | ee2e45a | 2014-06-27 12:10:03 -0700 | [diff] [blame] | 3523 | stack.scheduleDestroyActivities(app, reason); |
Craig Mautner | 4a1cb22 | 2013-12-04 16:14:06 -0800 | [diff] [blame] | 3524 | } |
Craig Mautner | 8d341ef | 2013-03-26 09:03:27 -0700 | [diff] [blame] | 3525 | } |
| 3526 | } |
| 3527 | |
Dianne Hackborn | 89ad456 | 2014-08-24 16:45:38 -0700 | [diff] [blame] | 3528 | void releaseSomeActivitiesLocked(ProcessRecord app, String reason) { |
| 3529 | // Examine all activities currently running in the process. |
| 3530 | TaskRecord firstTask = null; |
| 3531 | // Tasks is non-null only if two or more tasks are found. |
| 3532 | ArraySet<TaskRecord> tasks = null; |
Wale Ogunwale | 0fc365c | 2015-05-25 19:35:42 -0700 | [diff] [blame] | 3533 | if (DEBUG_RELEASE) Slog.d(TAG_RELEASE, "Trying to release some activities in " + app); |
| 3534 | for (int i = 0; i < app.activities.size(); i++) { |
Dianne Hackborn | 89ad456 | 2014-08-24 16:45:38 -0700 | [diff] [blame] | 3535 | ActivityRecord r = app.activities.get(i); |
| 3536 | // First, if we find an activity that is in the process of being destroyed, |
| 3537 | // then we just aren't going to do anything for now; we want things to settle |
| 3538 | // down before we try to prune more activities. |
Wale Ogunwale | ee006da | 2015-03-30 14:49:25 -0700 | [diff] [blame] | 3539 | if (r.finishing || r.state == DESTROYING || r.state == DESTROYED) { |
Wale Ogunwale | 0fc365c | 2015-05-25 19:35:42 -0700 | [diff] [blame] | 3540 | if (DEBUG_RELEASE) Slog.d(TAG_RELEASE, "Abort release; already destroying: " + r); |
Dianne Hackborn | 89ad456 | 2014-08-24 16:45:38 -0700 | [diff] [blame] | 3541 | return; |
| 3542 | } |
| 3543 | // Don't consider any activies that are currently not in a state where they |
| 3544 | // can be destroyed. |
Wale Ogunwale | ee006da | 2015-03-30 14:49:25 -0700 | [diff] [blame] | 3545 | if (r.visible || !r.stopped || !r.haveState || r.state == RESUMED || r.state == PAUSING |
| 3546 | || r.state == PAUSED || r.state == STOPPING) { |
Wale Ogunwale | 0fc365c | 2015-05-25 19:35:42 -0700 | [diff] [blame] | 3547 | 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] | 3548 | continue; |
| 3549 | } |
Bryce Lee | af691c0 | 2017-03-20 14:20:22 -0700 | [diff] [blame] | 3550 | |
| 3551 | final TaskRecord task = r.getTask(); |
| 3552 | if (task != null) { |
| 3553 | if (DEBUG_RELEASE) Slog.d(TAG_RELEASE, "Collecting release task " + task |
Dianne Hackborn | 89ad456 | 2014-08-24 16:45:38 -0700 | [diff] [blame] | 3554 | + " from " + r); |
| 3555 | if (firstTask == null) { |
Bryce Lee | af691c0 | 2017-03-20 14:20:22 -0700 | [diff] [blame] | 3556 | firstTask = task; |
| 3557 | } else if (firstTask != task) { |
Dianne Hackborn | 89ad456 | 2014-08-24 16:45:38 -0700 | [diff] [blame] | 3558 | if (tasks == null) { |
| 3559 | tasks = new ArraySet<>(); |
| 3560 | tasks.add(firstTask); |
| 3561 | } |
Bryce Lee | af691c0 | 2017-03-20 14:20:22 -0700 | [diff] [blame] | 3562 | tasks.add(task); |
Dianne Hackborn | 89ad456 | 2014-08-24 16:45:38 -0700 | [diff] [blame] | 3563 | } |
| 3564 | } |
| 3565 | } |
| 3566 | if (tasks == null) { |
Wale Ogunwale | 0fc365c | 2015-05-25 19:35:42 -0700 | [diff] [blame] | 3567 | 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] | 3568 | return; |
| 3569 | } |
| 3570 | // If we have activities in multiple tasks that are in a position to be destroyed, |
| 3571 | // let's iterate through the tasks and release the oldest one. |
| 3572 | final int numDisplays = mActivityDisplays.size(); |
| 3573 | for (int displayNdx = 0; displayNdx < numDisplays; ++displayNdx) { |
Wale Ogunwale | a0f5b5e | 2017-10-11 09:37:23 -0700 | [diff] [blame] | 3574 | final ActivityDisplay display = mActivityDisplays.valueAt(displayNdx); |
| 3575 | final int stackCount = display.getChildCount(); |
Dianne Hackborn | 89ad456 | 2014-08-24 16:45:38 -0700 | [diff] [blame] | 3576 | // 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] | 3577 | for (int stackNdx = 0; stackNdx < stackCount; stackNdx++) { |
| 3578 | final ActivityStack stack = display.getChildAt(stackNdx); |
Dianne Hackborn | 89ad456 | 2014-08-24 16:45:38 -0700 | [diff] [blame] | 3579 | // Try to release activities in this stack; if we manage to, we are done. |
| 3580 | if (stack.releaseSomeActivitiesLocked(app, tasks, reason) > 0) { |
| 3581 | return; |
| 3582 | } |
| 3583 | } |
| 3584 | } |
| 3585 | } |
| 3586 | |
Amith Yamasani | 37a40c2 | 2015-06-17 13:25:42 -0700 | [diff] [blame] | 3587 | boolean switchUserLocked(int userId, UserState uss) { |
Wale Ogunwale | 9a98c52 | 2016-04-27 09:23:55 -0700 | [diff] [blame] | 3588 | final int focusStackId = mFocusedStack.getStackId(); |
| 3589 | // We dismiss the docked stack whenever we switch users. |
Wale Ogunwale | a0f5b5e | 2017-10-11 09:37:23 -0700 | [diff] [blame] | 3590 | final ActivityStack dockedStack = getDefaultDisplay().getSplitScreenPrimaryStack(); |
Wale Ogunwale | 9dcf946 | 2017-09-19 15:13:01 -0700 | [diff] [blame] | 3591 | if (dockedStack != null) { |
| 3592 | moveTasksToFullscreenStackLocked(dockedStack, mFocusedStack == dockedStack); |
| 3593 | } |
Winson Chung | c2b23a5 | 2017-01-09 15:44:55 -0800 | [diff] [blame] | 3594 | // Also dismiss the pinned stack whenever we switch users. Removing the pinned stack will |
| 3595 | // also cause all tasks to be moved to the fullscreen stack at a position that is |
| 3596 | // appropriate. |
Wale Ogunwale | 44f036f | 2017-09-29 05:09:09 -0700 | [diff] [blame] | 3597 | removeStacksInWindowingModes(WINDOWING_MODE_PINNED); |
Wale Ogunwale | 9a98c52 | 2016-04-27 09:23:55 -0700 | [diff] [blame] | 3598 | |
| 3599 | mUserStackInFront.put(mCurrentUser, focusStackId); |
Wale Ogunwale | 6827856 | 2017-09-23 17:13:55 -0700 | [diff] [blame] | 3600 | final int restoreStackId = mUserStackInFront.get(userId, mHomeStack.mStackId); |
Craig Mautner | 2420ead | 2013-04-01 17:13:20 -0700 | [diff] [blame] | 3601 | mCurrentUser = userId; |
Craig Mautner | ac6f843 | 2013-07-17 13:24:59 -0700 | [diff] [blame] | 3602 | |
Craig Mautner | 858d8a6 | 2013-04-23 17:08:34 -0700 | [diff] [blame] | 3603 | mStartingUsers.add(uss); |
Craig Mautner | e0a3884 | 2013-12-16 16:14:02 -0800 | [diff] [blame] | 3604 | for (int displayNdx = mActivityDisplays.size() - 1; displayNdx >= 0; --displayNdx) { |
Wale Ogunwale | a0f5b5e | 2017-10-11 09:37:23 -0700 | [diff] [blame] | 3605 | final ActivityDisplay display = mActivityDisplays.valueAt(displayNdx); |
| 3606 | for (int stackNdx = display.getChildCount() - 1; stackNdx >= 0; --stackNdx) { |
| 3607 | final ActivityStack stack = display.getChildAt(stackNdx); |
Craig Mautner | e0a3884 | 2013-12-16 16:14:02 -0800 | [diff] [blame] | 3608 | stack.switchUserLocked(userId); |
Alexandra Gherghina | dae57a1 | 2014-03-12 19:15:26 +0000 | [diff] [blame] | 3609 | TaskRecord task = stack.topTask(); |
| 3610 | if (task != null) { |
Wale Ogunwale | 1666e31 | 2016-12-16 11:27:18 -0800 | [diff] [blame] | 3611 | stack.positionChildWindowContainerAtTop(task); |
Alexandra Gherghina | dae57a1 | 2014-03-12 19:15:26 +0000 | [diff] [blame] | 3612 | } |
Craig Mautner | 4a1cb22 | 2013-12-04 16:14:06 -0800 | [diff] [blame] | 3613 | } |
Craig Mautner | ac6f843 | 2013-07-17 13:24:59 -0700 | [diff] [blame] | 3614 | } |
Craig Mautner | 858d8a6 | 2013-04-23 17:08:34 -0700 | [diff] [blame] | 3615 | |
Craig Mautner | 4f1df4f | 2013-10-15 15:44:14 -0700 | [diff] [blame] | 3616 | ActivityStack stack = getStack(restoreStackId); |
| 3617 | if (stack == null) { |
| 3618 | stack = mHomeStack; |
| 3619 | } |
Wale Ogunwale | 6fbde9f | 2017-08-24 07:24:12 -0700 | [diff] [blame] | 3620 | final boolean homeInFront = stack.isActivityTypeHome(); |
Craig Mautner | e0a3884 | 2013-12-16 16:14:02 -0800 | [diff] [blame] | 3621 | if (stack.isOnHomeDisplay()) { |
Wale Ogunwale | 925d0d1 | 2015-09-23 15:40:07 -0700 | [diff] [blame] | 3622 | stack.moveToFront("switchUserOnHomeDisplay"); |
Craig Mautner | e0a3884 | 2013-12-16 16:14:02 -0800 | [diff] [blame] | 3623 | } else { |
| 3624 | // Stack was moved to another display while user was swapped out. |
Matthew Ng | ae1ff4f | 2016-11-10 15:49:14 -0800 | [diff] [blame] | 3625 | resumeHomeStackTask(null, "switchUserOnOtherDisplay"); |
Craig Mautner | e0a3884 | 2013-12-16 16:14:02 -0800 | [diff] [blame] | 3626 | } |
Craig Mautner | 93529a4 | 2013-10-04 15:03:13 -0700 | [diff] [blame] | 3627 | return homeInFront; |
Craig Mautner | 2219a1b | 2013-03-25 09:44:30 -0700 | [diff] [blame] | 3628 | } |
| 3629 | |
Wale Ogunwale | 0bd2aa7 | 2015-04-16 13:50:44 -0700 | [diff] [blame] | 3630 | /** Checks whether the userid is a profile of the current user. */ |
| 3631 | boolean isCurrentProfileLocked(int userId) { |
| 3632 | if (userId == mCurrentUser) return true; |
Fyodor Kupolov | 1b3edac | 2017-09-19 15:48:06 -0700 | [diff] [blame] | 3633 | return mService.mUserController.isCurrentProfile(userId); |
Wale Ogunwale | 0bd2aa7 | 2015-04-16 13:50:44 -0700 | [diff] [blame] | 3634 | } |
| 3635 | |
Bryce Lee | b7c9b80 | 2017-05-02 14:20:24 -0700 | [diff] [blame] | 3636 | /** |
| 3637 | * Returns whether a stopping activity is present that should be stopped after visible, rather |
| 3638 | * than idle. |
| 3639 | * @return {@code true} if such activity is present. {@code false} otherwise. |
| 3640 | */ |
| 3641 | boolean isStoppingNoHistoryActivity() { |
| 3642 | // Activities that are marked as nohistory should be stopped immediately after the resumed |
| 3643 | // activity has become visible. |
| 3644 | for (ActivityRecord record : mStoppingActivities) { |
| 3645 | if (record.isNoHistory()) { |
| 3646 | return true; |
| 3647 | } |
| 3648 | } |
| 3649 | |
| 3650 | return false; |
| 3651 | } |
| 3652 | |
Winson Chung | 4dabf23 | 2017-01-25 13:25:22 -0800 | [diff] [blame] | 3653 | final ArrayList<ActivityRecord> processStoppingActivitiesLocked(ActivityRecord idleActivity, |
| 3654 | boolean remove, boolean processPausingActivities) { |
Craig Mautner | de4ef02 | 2013-04-07 19:01:33 -0700 | [diff] [blame] | 3655 | ArrayList<ActivityRecord> stops = null; |
| 3656 | |
| 3657 | final boolean nowVisible = allResumedActivitiesVisible(); |
Craig Mautner | 8c14c15 | 2015-01-15 17:32:07 -0800 | [diff] [blame] | 3658 | for (int activityNdx = mStoppingActivities.size() - 1; activityNdx >= 0; --activityNdx) { |
| 3659 | ActivityRecord s = mStoppingActivities.get(activityNdx); |
Bryce Lee | 4a19438 | 2017-04-04 14:32:48 -0700 | [diff] [blame] | 3660 | boolean waitingVisible = mActivitiesWaitingForVisibleActivity.contains(s); |
Wale Ogunwale | f81c1d1 | 2016-01-12 12:20:18 -0800 | [diff] [blame] | 3661 | if (DEBUG_STATES) Slog.v(TAG, "Stopping " + s + ": nowVisible=" + nowVisible |
Craig Mautner | 8c14c15 | 2015-01-15 17:32:07 -0800 | [diff] [blame] | 3662 | + " waitingVisible=" + waitingVisible + " finishing=" + s.finishing); |
| 3663 | if (waitingVisible && nowVisible) { |
Bryce Lee | 4a19438 | 2017-04-04 14:32:48 -0700 | [diff] [blame] | 3664 | mActivitiesWaitingForVisibleActivity.remove(s); |
Andrii Kulian | ee05681 | 2016-09-21 15:34:45 -0700 | [diff] [blame] | 3665 | waitingVisible = false; |
Craig Mautner | de4ef02 | 2013-04-07 19:01:33 -0700 | [diff] [blame] | 3666 | if (s.finishing) { |
| 3667 | // If this activity is finishing, it is sitting on top of |
| 3668 | // everyone else but we now know it is no longer needed... |
| 3669 | // so get rid of it. Otherwise, we need to go through the |
| 3670 | // normal flow and hide it once we determine that it is |
| 3671 | // hidden by the activities in front of it. |
Wale Ogunwale | f81c1d1 | 2016-01-12 12:20:18 -0800 | [diff] [blame] | 3672 | if (DEBUG_STATES) Slog.v(TAG, "Before stopping, can hide: " + s); |
Wale Ogunwale | 26c0dfe | 2016-12-14 14:42:30 -0800 | [diff] [blame] | 3673 | s.setVisibility(false); |
Craig Mautner | de4ef02 | 2013-04-07 19:01:33 -0700 | [diff] [blame] | 3674 | } |
| 3675 | } |
David Stevens | 9440dc8 | 2017-03-16 19:00:20 -0700 | [diff] [blame] | 3676 | if (remove) { |
| 3677 | final ActivityStack stack = s.getStack(); |
| 3678 | final boolean shouldSleepOrShutDown = stack != null |
| 3679 | ? stack.shouldSleepOrShutDownActivities() |
| 3680 | : mService.isSleepingOrShuttingDownLocked(); |
| 3681 | if (!waitingVisible || shouldSleepOrShutDown) { |
| 3682 | if (!processPausingActivities && s.state == PAUSING) { |
| 3683 | // Defer processing pausing activities in this iteration and reschedule |
| 3684 | // a delayed idle to reprocess it again |
| 3685 | removeTimeoutsForActivityLocked(idleActivity); |
| 3686 | scheduleIdleTimeoutLocked(idleActivity); |
| 3687 | continue; |
| 3688 | } |
Winson Chung | 4dabf23 | 2017-01-25 13:25:22 -0800 | [diff] [blame] | 3689 | |
David Stevens | 9440dc8 | 2017-03-16 19:00:20 -0700 | [diff] [blame] | 3690 | if (DEBUG_STATES) Slog.v(TAG, "Ready to stop: " + s); |
| 3691 | if (stops == null) { |
| 3692 | stops = new ArrayList<>(); |
| 3693 | } |
| 3694 | stops.add(s); |
| 3695 | mStoppingActivities.remove(activityNdx); |
Craig Mautner | de4ef02 | 2013-04-07 19:01:33 -0700 | [diff] [blame] | 3696 | } |
Craig Mautner | de4ef02 | 2013-04-07 19:01:33 -0700 | [diff] [blame] | 3697 | } |
| 3698 | } |
| 3699 | |
| 3700 | return stops; |
| 3701 | } |
| 3702 | |
Craig Mautner | cf910b0 | 2013-04-23 11:23:27 -0700 | [diff] [blame] | 3703 | void validateTopActivitiesLocked() { |
Wale Ogunwale | ee006da | 2015-03-30 14:49:25 -0700 | [diff] [blame] | 3704 | for (int displayNdx = mActivityDisplays.size() - 1; displayNdx >= 0; --displayNdx) { |
Wale Ogunwale | a0f5b5e | 2017-10-11 09:37:23 -0700 | [diff] [blame] | 3705 | final ActivityDisplay display = mActivityDisplays.valueAt(displayNdx); |
| 3706 | for (int stackNdx = display.getChildCount() - 1; stackNdx >= 0; --stackNdx) { |
| 3707 | final ActivityStack stack = display.getChildAt(stackNdx); |
Filip Gruszczynski | 3e85ba2 | 2015-10-05 22:48:30 -0700 | [diff] [blame] | 3708 | final ActivityRecord r = stack.topRunningActivityLocked(); |
Wale Ogunwale | ee006da | 2015-03-30 14:49:25 -0700 | [diff] [blame] | 3709 | final ActivityState state = r == null ? DESTROYED : r.state; |
Wale Ogunwale | 1e60e0c | 2015-10-28 13:36:10 -0700 | [diff] [blame] | 3710 | if (isFocusedStack(stack)) { |
Wale Ogunwale | ee006da | 2015-03-30 14:49:25 -0700 | [diff] [blame] | 3711 | if (r == null) Slog.e(TAG, |
| 3712 | "validateTop...: null top activity, stack=" + stack); |
| 3713 | else { |
| 3714 | final ActivityRecord pausing = stack.mPausingActivity; |
| 3715 | if (pausing != null && pausing == r) Slog.e(TAG, |
| 3716 | "validateTop...: top stack has pausing activity r=" + r |
| 3717 | + " state=" + state); |
| 3718 | if (state != INITIALIZING && state != RESUMED) Slog.e(TAG, |
| 3719 | "validateTop...: activity in front not resumed r=" + r |
| 3720 | + " state=" + state); |
| 3721 | } |
Craig Mautner | cf910b0 | 2013-04-23 11:23:27 -0700 | [diff] [blame] | 3722 | } else { |
Wale Ogunwale | ee006da | 2015-03-30 14:49:25 -0700 | [diff] [blame] | 3723 | final ActivityRecord resumed = stack.mResumedActivity; |
| 3724 | if (resumed != null && resumed == r) Slog.e(TAG, |
| 3725 | "validateTop...: back stack has resumed activity r=" + r |
| 3726 | + " state=" + state); |
| 3727 | if (r != null && (state == INITIALIZING || state == RESUMED)) Slog.e(TAG, |
| 3728 | "validateTop...: activity in back resumed r=" + r + " state=" + state); |
Craig Mautner | cf910b0 | 2013-04-23 11:23:27 -0700 | [diff] [blame] | 3729 | } |
| 3730 | } |
| 3731 | } |
Craig Mautner | 76ea224 | 2013-05-15 11:40:05 -0700 | [diff] [blame] | 3732 | } |
| 3733 | |
Bryce Lee | 77a7dd6 | 2018-01-22 15:47:09 -0800 | [diff] [blame] | 3734 | public void dumpDisplays(PrintWriter pw) { |
| 3735 | for (int i = mActivityDisplays.size() - 1; i >= 0; --i) { |
| 3736 | final ActivityDisplay display = mActivityDisplays.valueAt(i); |
| 3737 | pw.print("[id:" + display.mDisplayId + " stacks:"); |
| 3738 | display.dumpStacks(pw); |
| 3739 | pw.print("]"); |
| 3740 | } |
| 3741 | } |
| 3742 | |
Craig Mautner | 2708430 | 2013-03-25 08:05:25 -0700 | [diff] [blame] | 3743 | public void dump(PrintWriter pw, String prefix) { |
Craig Mautner | d1bbdb462 | 2013-10-22 09:53:20 -0700 | [diff] [blame] | 3744 | pw.print(prefix); pw.print("mFocusedStack=" + mFocusedStack); |
Craig Mautner | 4a1cb22 | 2013-12-04 16:14:06 -0800 | [diff] [blame] | 3745 | pw.print(" mLastFocusedStack="); pw.println(mLastFocusedStack); |
Suprabh Shukla | 09a88f5 | 2015-12-02 14:36:31 -0800 | [diff] [blame] | 3746 | pw.print(prefix); |
| 3747 | pw.println("mCurTaskIdForUser=" + mCurTaskIdForUser); |
Craig Mautner | d1bbdb462 | 2013-10-22 09:53:20 -0700 | [diff] [blame] | 3748 | pw.print(prefix); pw.println("mUserStackInFront=" + mUserStackInFront); |
Wale Ogunwale | 9dcf946 | 2017-09-19 15:13:01 -0700 | [diff] [blame] | 3749 | for (int i = mActivityDisplays.size() - 1; i >= 0; --i) { |
| 3750 | final ActivityDisplay display = mActivityDisplays.valueAt(i); |
Wale Ogunwale | a0f5b5e | 2017-10-11 09:37:23 -0700 | [diff] [blame] | 3751 | display.dump(pw, prefix); |
Wale Ogunwale | 9dcf946 | 2017-09-19 15:13:01 -0700 | [diff] [blame] | 3752 | } |
Bryce Lee | 4a19438 | 2017-04-04 14:32:48 -0700 | [diff] [blame] | 3753 | if (!mWaitingForActivityVisible.isEmpty()) { |
| 3754 | pw.print(prefix); pw.println("mWaitingForActivityVisible="); |
| 3755 | for (int i = 0; i < mWaitingForActivityVisible.size(); ++i) { |
| 3756 | pw.print(prefix); pw.print(prefix); mWaitingForActivityVisible.get(i).dump(pw, prefix); |
| 3757 | } |
| 3758 | } |
| 3759 | |
Jorim Jaggi | 8d78693 | 2016-10-26 19:08:36 -0700 | [diff] [blame] | 3760 | mKeyguardController.dump(pw, prefix); |
Benjamin Franz | a83859f | 2017-07-03 16:34:14 +0100 | [diff] [blame] | 3761 | mService.mLockTaskController.dump(pw, prefix); |
Craig Mautner | 2708430 | 2013-03-25 08:05:25 -0700 | [diff] [blame] | 3762 | } |
Craig Mautner | 8d341ef | 2013-03-26 09:03:27 -0700 | [diff] [blame] | 3763 | |
Yi Jin | 129fc6c | 2017-09-28 15:48:38 -0700 | [diff] [blame] | 3764 | public void writeToProto(ProtoOutputStream proto) { |
Adrian Roos | 4921ccf | 2017-09-28 16:54:06 +0200 | [diff] [blame] | 3765 | super.writeToProto(proto, CONFIGURATION_CONTAINER, false /* trim */); |
Steven Timotius | 4346f0a | 2017-09-12 11:07:21 -0700 | [diff] [blame] | 3766 | for (int displayNdx = 0; displayNdx < mActivityDisplays.size(); ++displayNdx) { |
| 3767 | ActivityDisplay activityDisplay = mActivityDisplays.valueAt(displayNdx); |
| 3768 | activityDisplay.writeToProto(proto, DISPLAYS); |
| 3769 | } |
| 3770 | mKeyguardController.writeToProto(proto, KEYGUARD_CONTROLLER); |
| 3771 | if (mFocusedStack != null) { |
| 3772 | proto.write(FOCUSED_STACK_ID, mFocusedStack.mStackId); |
| 3773 | ActivityRecord focusedActivity = getResumedActivityLocked(); |
| 3774 | if (focusedActivity != null) { |
| 3775 | focusedActivity.writeIdentifierToProto(proto, RESUMED_ACTIVITY); |
| 3776 | } |
| 3777 | } else { |
| 3778 | proto.write(FOCUSED_STACK_ID, INVALID_STACK_ID); |
| 3779 | } |
Steven Timotius | 4346f0a | 2017-09-12 11:07:21 -0700 | [diff] [blame] | 3780 | } |
| 3781 | |
Winson | 43d1f26 | 2016-06-14 16:05:55 -0700 | [diff] [blame] | 3782 | /** |
Andrii Kulian | 5406e7a | 2016-10-21 11:55:23 -0700 | [diff] [blame] | 3783 | * Dump all connected displays' configurations. |
| 3784 | * @param prefix Prefix to apply to each line of the dump. |
| 3785 | */ |
| 3786 | void dumpDisplayConfigs(PrintWriter pw, String prefix) { |
| 3787 | pw.print(prefix); pw.println("Display override configurations:"); |
| 3788 | final int displayCount = mActivityDisplays.size(); |
| 3789 | for (int i = 0; i < displayCount; i++) { |
| 3790 | final ActivityDisplay activityDisplay = mActivityDisplays.valueAt(i); |
| 3791 | pw.print(prefix); pw.print(" "); pw.print(activityDisplay.mDisplayId); pw.print(": "); |
| 3792 | pw.println(activityDisplay.getOverrideConfiguration()); |
| 3793 | } |
| 3794 | } |
| 3795 | |
| 3796 | /** |
Winson | 43d1f26 | 2016-06-14 16:05:55 -0700 | [diff] [blame] | 3797 | * Dumps the activities matching the given {@param name} in the either the focused stack |
| 3798 | * or all visible stacks if {@param dumpVisibleStacks} is true. |
| 3799 | */ |
Winson Chung | 6998bc4 | 2017-02-28 17:07:05 -0800 | [diff] [blame] | 3800 | ArrayList<ActivityRecord> getDumpActivitiesLocked(String name, boolean dumpVisibleStacksOnly, |
| 3801 | boolean dumpFocusedStackOnly) { |
| 3802 | if (dumpFocusedStackOnly) { |
| 3803 | return mFocusedStack.getDumpActivitiesLocked(name); |
| 3804 | } else { |
Winson | 43d1f26 | 2016-06-14 16:05:55 -0700 | [diff] [blame] | 3805 | ArrayList<ActivityRecord> activities = new ArrayList<>(); |
| 3806 | int numDisplays = mActivityDisplays.size(); |
| 3807 | for (int displayNdx = 0; displayNdx < numDisplays; ++displayNdx) { |
Wale Ogunwale | a0f5b5e | 2017-10-11 09:37:23 -0700 | [diff] [blame] | 3808 | final ActivityDisplay display = mActivityDisplays.valueAt(displayNdx); |
| 3809 | for (int stackNdx = display.getChildCount() - 1; stackNdx >= 0; --stackNdx) { |
| 3810 | final ActivityStack stack = display.getChildAt(stackNdx); |
Wale Ogunwale | 9dcf946 | 2017-09-19 15:13:01 -0700 | [diff] [blame] | 3811 | if (!dumpVisibleStacksOnly || stack.shouldBeVisible(null)) { |
Winson | 43d1f26 | 2016-06-14 16:05:55 -0700 | [diff] [blame] | 3812 | activities.addAll(stack.getDumpActivitiesLocked(name)); |
| 3813 | } |
| 3814 | } |
| 3815 | } |
| 3816 | return activities; |
Winson | 43d1f26 | 2016-06-14 16:05:55 -0700 | [diff] [blame] | 3817 | } |
Craig Mautner | 20e7227 | 2013-04-01 13:45:53 -0700 | [diff] [blame] | 3818 | } |
| 3819 | |
Dianne Hackborn | 390517b | 2013-05-30 15:03:32 -0700 | [diff] [blame] | 3820 | static boolean printThisActivity(PrintWriter pw, ActivityRecord activity, String dumpPackage, |
| 3821 | boolean needSep, String prefix) { |
| 3822 | if (activity != null) { |
| 3823 | if (dumpPackage == null || dumpPackage.equals(activity.packageName)) { |
| 3824 | if (needSep) { |
| 3825 | pw.println(); |
Dianne Hackborn | 390517b | 2013-05-30 15:03:32 -0700 | [diff] [blame] | 3826 | } |
| 3827 | pw.print(prefix); |
| 3828 | pw.println(activity); |
Dianne Hackborn | 7ad34e5 | 2013-06-05 18:41:45 -0700 | [diff] [blame] | 3829 | return true; |
Dianne Hackborn | 390517b | 2013-05-30 15:03:32 -0700 | [diff] [blame] | 3830 | } |
| 3831 | } |
Dianne Hackborn | 7ad34e5 | 2013-06-05 18:41:45 -0700 | [diff] [blame] | 3832 | return false; |
Dianne Hackborn | 390517b | 2013-05-30 15:03:32 -0700 | [diff] [blame] | 3833 | } |
| 3834 | |
Craig Mautner | 8d341ef | 2013-03-26 09:03:27 -0700 | [diff] [blame] | 3835 | boolean dumpActivitiesLocked(FileDescriptor fd, PrintWriter pw, boolean dumpAll, |
| 3836 | boolean dumpClient, String dumpPackage) { |
Dianne Hackborn | 7ad34e5 | 2013-06-05 18:41:45 -0700 | [diff] [blame] | 3837 | boolean printed = false; |
| 3838 | boolean needSep = false; |
Craig Mautner | e0a3884 | 2013-12-16 16:14:02 -0800 | [diff] [blame] | 3839 | for (int displayNdx = 0; displayNdx < mActivityDisplays.size(); ++displayNdx) { |
| 3840 | ActivityDisplay activityDisplay = mActivityDisplays.valueAt(displayNdx); |
Craig Mautner | ee2e45a | 2014-06-27 12:10:03 -0700 | [diff] [blame] | 3841 | pw.print("Display #"); pw.print(activityDisplay.mDisplayId); |
Craig Mautner | 737fae2 | 2014-10-15 12:52:10 -0700 | [diff] [blame] | 3842 | pw.println(" (activities from top to bottom):"); |
Wale Ogunwale | a0f5b5e | 2017-10-11 09:37:23 -0700 | [diff] [blame] | 3843 | final ActivityDisplay display = mActivityDisplays.valueAt(displayNdx); |
| 3844 | for (int stackNdx = display.getChildCount() - 1; stackNdx >= 0; --stackNdx) { |
| 3845 | final ActivityStack stack = display.getChildAt(stackNdx); |
Wale Ogunwale | 34a5b57 | 2017-08-31 08:29:41 -0700 | [diff] [blame] | 3846 | pw.println(); |
Wale Ogunwale | 44f036f | 2017-09-29 05:09:09 -0700 | [diff] [blame] | 3847 | pw.println(" Stack #" + stack.mStackId |
Wale Ogunwale | 6191149 | 2017-10-11 08:50:50 -0700 | [diff] [blame] | 3848 | + ": type=" + activityTypeToString(stack.getActivityType()) |
| 3849 | + " mode=" + windowingModeToString(stack.getWindowingMode())); |
Wale Ogunwale | 34a5b57 | 2017-08-31 08:29:41 -0700 | [diff] [blame] | 3850 | pw.println(" isSleeping=" + stack.shouldSleepActivities()); |
Bryce Lee | f3c6a47 | 2017-11-14 14:53:06 -0800 | [diff] [blame] | 3851 | pw.println(" mBounds=" + stack.getOverrideBounds()); |
Winson Chung | abb433b | 2017-03-24 09:35:42 -0700 | [diff] [blame] | 3852 | |
Wale Ogunwale | 34a5b57 | 2017-08-31 08:29:41 -0700 | [diff] [blame] | 3853 | printed |= stack.dumpActivitiesLocked(fd, pw, dumpAll, dumpClient, dumpPackage, |
| 3854 | needSep); |
Winson Chung | abb433b | 2017-03-24 09:35:42 -0700 | [diff] [blame] | 3855 | |
Craig Mautner | 4a1cb22 | 2013-12-04 16:14:06 -0800 | [diff] [blame] | 3856 | printed |= dumpHistoryList(fd, pw, stack.mLRUActivities, " ", "Run", false, |
| 3857 | !dumpAll, false, dumpPackage, true, |
| 3858 | " Running activities (most recent first):", null); |
Craig Mautner | 8d341ef | 2013-03-26 09:03:27 -0700 | [diff] [blame] | 3859 | |
Craig Mautner | 4a1cb22 | 2013-12-04 16:14:06 -0800 | [diff] [blame] | 3860 | needSep = printed; |
| 3861 | boolean pr = printThisActivity(pw, stack.mPausingActivity, dumpPackage, needSep, |
| 3862 | " mPausingActivity: "); |
Dianne Hackborn | 7ad34e5 | 2013-06-05 18:41:45 -0700 | [diff] [blame] | 3863 | if (pr) { |
| 3864 | printed = true; |
Craig Mautner | 4a1cb22 | 2013-12-04 16:14:06 -0800 | [diff] [blame] | 3865 | needSep = false; |
Dianne Hackborn | 7ad34e5 | 2013-06-05 18:41:45 -0700 | [diff] [blame] | 3866 | } |
Craig Mautner | 4a1cb22 | 2013-12-04 16:14:06 -0800 | [diff] [blame] | 3867 | pr = printThisActivity(pw, stack.mResumedActivity, dumpPackage, needSep, |
| 3868 | " mResumedActivity: "); |
| 3869 | if (pr) { |
| 3870 | printed = true; |
| 3871 | needSep = false; |
| 3872 | } |
| 3873 | if (dumpAll) { |
| 3874 | pr = printThisActivity(pw, stack.mLastPausedActivity, dumpPackage, needSep, |
| 3875 | " mLastPausedActivity: "); |
| 3876 | if (pr) { |
| 3877 | printed = true; |
| 3878 | needSep = true; |
| 3879 | } |
| 3880 | printed |= printThisActivity(pw, stack.mLastNoHistoryActivity, dumpPackage, |
| 3881 | needSep, " mLastNoHistoryActivity: "); |
| 3882 | } |
| 3883 | needSep = printed; |
Craig Mautner | 8d341ef | 2013-03-26 09:03:27 -0700 | [diff] [blame] | 3884 | } |
| 3885 | } |
| 3886 | |
Dianne Hackborn | 7ad34e5 | 2013-06-05 18:41:45 -0700 | [diff] [blame] | 3887 | printed |= dumpHistoryList(fd, pw, mFinishingActivities, " ", "Fin", false, !dumpAll, |
| 3888 | false, dumpPackage, true, " Activities waiting to finish:", null); |
| 3889 | printed |= dumpHistoryList(fd, pw, mStoppingActivities, " ", "Stop", false, !dumpAll, |
| 3890 | false, dumpPackage, true, " Activities waiting to stop:", null); |
Bryce Lee | 4a19438 | 2017-04-04 14:32:48 -0700 | [diff] [blame] | 3891 | printed |= dumpHistoryList(fd, pw, mActivitiesWaitingForVisibleActivity, " ", "Wait", |
| 3892 | false, !dumpAll, false, dumpPackage, true, |
| 3893 | " Activities waiting for another to become visible:", null); |
Dianne Hackborn | 7ad34e5 | 2013-06-05 18:41:45 -0700 | [diff] [blame] | 3894 | printed |= dumpHistoryList(fd, pw, mGoingToSleepActivities, " ", "Sleep", false, !dumpAll, |
| 3895 | false, dumpPackage, true, " Activities waiting to sleep:", null); |
Craig Mautner | f333327 | 2013-04-22 10:55:53 -0700 | [diff] [blame] | 3896 | |
Dianne Hackborn | 7ad34e5 | 2013-06-05 18:41:45 -0700 | [diff] [blame] | 3897 | return printed; |
Craig Mautner | 8d341ef | 2013-03-26 09:03:27 -0700 | [diff] [blame] | 3898 | } |
| 3899 | |
Dianne Hackborn | 390517b | 2013-05-30 15:03:32 -0700 | [diff] [blame] | 3900 | static boolean dumpHistoryList(FileDescriptor fd, PrintWriter pw, List<ActivityRecord> list, |
Craig Mautner | 8d341ef | 2013-03-26 09:03:27 -0700 | [diff] [blame] | 3901 | String prefix, String label, boolean complete, boolean brief, boolean client, |
Wale Ogunwale | 34a5b57 | 2017-08-31 08:29:41 -0700 | [diff] [blame] | 3902 | String dumpPackage, boolean needNL, String header, TaskRecord lastTask) { |
Dianne Hackborn | 390517b | 2013-05-30 15:03:32 -0700 | [diff] [blame] | 3903 | String innerPrefix = null; |
| 3904 | String[] args = null; |
| 3905 | boolean printed = false; |
Craig Mautner | 8d341ef | 2013-03-26 09:03:27 -0700 | [diff] [blame] | 3906 | for (int i=list.size()-1; i>=0; i--) { |
| 3907 | final ActivityRecord r = list.get(i); |
| 3908 | if (dumpPackage != null && !dumpPackage.equals(r.packageName)) { |
| 3909 | continue; |
| 3910 | } |
Dianne Hackborn | 390517b | 2013-05-30 15:03:32 -0700 | [diff] [blame] | 3911 | if (innerPrefix == null) { |
| 3912 | innerPrefix = prefix + " "; |
| 3913 | args = new String[0]; |
| 3914 | } |
| 3915 | printed = true; |
Craig Mautner | 8d341ef | 2013-03-26 09:03:27 -0700 | [diff] [blame] | 3916 | final boolean full = !brief && (complete || !r.isInHistory()); |
| 3917 | if (needNL) { |
Dianne Hackborn | 390517b | 2013-05-30 15:03:32 -0700 | [diff] [blame] | 3918 | pw.println(""); |
Craig Mautner | 8d341ef | 2013-03-26 09:03:27 -0700 | [diff] [blame] | 3919 | needNL = false; |
| 3920 | } |
Wale Ogunwale | 34a5b57 | 2017-08-31 08:29:41 -0700 | [diff] [blame] | 3921 | if (header != null) { |
| 3922 | pw.println(header); |
| 3923 | header = null; |
Dianne Hackborn | 390517b | 2013-05-30 15:03:32 -0700 | [diff] [blame] | 3924 | } |
Bryce Lee | af691c0 | 2017-03-20 14:20:22 -0700 | [diff] [blame] | 3925 | if (lastTask != r.getTask()) { |
| 3926 | lastTask = r.getTask(); |
Craig Mautner | 8d341ef | 2013-03-26 09:03:27 -0700 | [diff] [blame] | 3927 | pw.print(prefix); |
| 3928 | pw.print(full ? "* " : " "); |
| 3929 | pw.println(lastTask); |
| 3930 | if (full) { |
| 3931 | lastTask.dump(pw, prefix + " "); |
| 3932 | } else if (complete) { |
| 3933 | // Complete + brief == give a summary. Isn't that obvious?!? |
| 3934 | if (lastTask.intent != null) { |
| 3935 | pw.print(prefix); pw.print(" "); |
| 3936 | pw.println(lastTask.intent.toInsecureStringWithClip()); |
| 3937 | } |
| 3938 | } |
| 3939 | } |
| 3940 | pw.print(prefix); pw.print(full ? " * " : " "); pw.print(label); |
| 3941 | pw.print(" #"); pw.print(i); pw.print(": "); |
| 3942 | pw.println(r); |
| 3943 | if (full) { |
| 3944 | r.dump(pw, innerPrefix); |
| 3945 | } else if (complete) { |
| 3946 | // Complete + brief == give a summary. Isn't that obvious?!? |
| 3947 | pw.print(innerPrefix); pw.println(r.intent.toInsecureString()); |
| 3948 | if (r.app != null) { |
| 3949 | pw.print(innerPrefix); pw.println(r.app); |
| 3950 | } |
| 3951 | } |
| 3952 | if (client && r.app != null && r.app.thread != null) { |
| 3953 | // flush anything that is already in the PrintWriter since the thread is going |
| 3954 | // to write to the file descriptor directly |
| 3955 | pw.flush(); |
| 3956 | try { |
| 3957 | TransferPipe tp = new TransferPipe(); |
| 3958 | try { |
Sudheer Shanka | cc6418f | 2016-10-13 12:03:44 -0700 | [diff] [blame] | 3959 | r.app.thread.dumpActivity(tp.getWriteFd(), r.appToken, innerPrefix, args); |
Craig Mautner | 8d341ef | 2013-03-26 09:03:27 -0700 | [diff] [blame] | 3960 | // Short timeout, since blocking here can |
| 3961 | // deadlock with the application. |
| 3962 | tp.go(fd, 2000); |
| 3963 | } finally { |
| 3964 | tp.kill(); |
| 3965 | } |
| 3966 | } catch (IOException e) { |
| 3967 | pw.println(innerPrefix + "Failure while dumping the activity: " + e); |
| 3968 | } catch (RemoteException e) { |
| 3969 | pw.println(innerPrefix + "Got a RemoteException while dumping the activity"); |
| 3970 | } |
| 3971 | needNL = true; |
| 3972 | } |
| 3973 | } |
Dianne Hackborn | 390517b | 2013-05-30 15:03:32 -0700 | [diff] [blame] | 3974 | return printed; |
Craig Mautner | 8d341ef | 2013-03-26 09:03:27 -0700 | [diff] [blame] | 3975 | } |
Craig Mautner | ce5f3cb | 2013-04-22 08:58:54 -0700 | [diff] [blame] | 3976 | |
Craig Mautner | f333327 | 2013-04-22 10:55:53 -0700 | [diff] [blame] | 3977 | void scheduleIdleTimeoutLocked(ActivityRecord next) { |
Wale Ogunwale | 0fc365c | 2015-05-25 19:35:42 -0700 | [diff] [blame] | 3978 | if (DEBUG_IDLE) Slog.d(TAG_IDLE, |
| 3979 | "scheduleIdleTimeoutLocked: Callers=" + Debug.getCallers(4)); |
Craig Mautner | c64f73e | 2013-04-24 16:44:56 -0700 | [diff] [blame] | 3980 | Message msg = mHandler.obtainMessage(IDLE_TIMEOUT_MSG, next); |
| 3981 | mHandler.sendMessageDelayed(msg, IDLE_TIMEOUT); |
Craig Mautner | f333327 | 2013-04-22 10:55:53 -0700 | [diff] [blame] | 3982 | } |
| 3983 | |
| 3984 | final void scheduleIdleLocked() { |
Craig Mautner | 05d2903 | 2013-05-03 13:40:13 -0700 | [diff] [blame] | 3985 | mHandler.sendEmptyMessage(IDLE_NOW_MSG); |
Craig Mautner | f333327 | 2013-04-22 10:55:53 -0700 | [diff] [blame] | 3986 | } |
| 3987 | |
| 3988 | void removeTimeoutsForActivityLocked(ActivityRecord r) { |
Wale Ogunwale | 0fc365c | 2015-05-25 19:35:42 -0700 | [diff] [blame] | 3989 | if (DEBUG_IDLE) Slog.d(TAG_IDLE, "removeTimeoutsForActivity: Callers=" |
| 3990 | + Debug.getCallers(4)); |
Craig Mautner | f333327 | 2013-04-22 10:55:53 -0700 | [diff] [blame] | 3991 | mHandler.removeMessages(IDLE_TIMEOUT_MSG, r); |
| 3992 | } |
| 3993 | |
Craig Mautner | 05d2903 | 2013-05-03 13:40:13 -0700 | [diff] [blame] | 3994 | final void scheduleResumeTopActivities() { |
Craig Mautner | 34b73df | 2014-01-12 21:11:08 -0800 | [diff] [blame] | 3995 | if (!mHandler.hasMessages(RESUME_TOP_ACTIVITY_MSG)) { |
| 3996 | mHandler.sendEmptyMessage(RESUME_TOP_ACTIVITY_MSG); |
| 3997 | } |
Craig Mautner | 05d2903 | 2013-05-03 13:40:13 -0700 | [diff] [blame] | 3998 | } |
| 3999 | |
Craig Mautner | 0eea92c | 2013-05-16 13:35:39 -0700 | [diff] [blame] | 4000 | void removeSleepTimeouts() { |
Craig Mautner | 0eea92c | 2013-05-16 13:35:39 -0700 | [diff] [blame] | 4001 | mHandler.removeMessages(SLEEP_TIMEOUT_MSG); |
| 4002 | } |
| 4003 | |
| 4004 | final void scheduleSleepTimeout() { |
| 4005 | removeSleepTimeouts(); |
| 4006 | mHandler.sendEmptyMessageDelayed(SLEEP_TIMEOUT_MSG, SLEEP_TIMEOUT); |
| 4007 | } |
| 4008 | |
Craig Mautner | 4a1cb22 | 2013-12-04 16:14:06 -0800 | [diff] [blame] | 4009 | @Override |
| 4010 | public void onDisplayAdded(int displayId) { |
Dianne Hackborn | fb81d09 | 2015-08-03 17:14:46 -0700 | [diff] [blame] | 4011 | if (DEBUG_STACK) Slog.v(TAG, "Display added displayId=" + displayId); |
Craig Mautner | 4a1cb22 | 2013-12-04 16:14:06 -0800 | [diff] [blame] | 4012 | mHandler.sendMessage(mHandler.obtainMessage(HANDLE_DISPLAY_ADDED, displayId, 0)); |
| 4013 | } |
| 4014 | |
| 4015 | @Override |
| 4016 | public void onDisplayRemoved(int displayId) { |
Dianne Hackborn | fb81d09 | 2015-08-03 17:14:46 -0700 | [diff] [blame] | 4017 | if (DEBUG_STACK) Slog.v(TAG, "Display removed displayId=" + displayId); |
Craig Mautner | 4a1cb22 | 2013-12-04 16:14:06 -0800 | [diff] [blame] | 4018 | mHandler.sendMessage(mHandler.obtainMessage(HANDLE_DISPLAY_REMOVED, displayId, 0)); |
| 4019 | } |
| 4020 | |
| 4021 | @Override |
| 4022 | public void onDisplayChanged(int displayId) { |
Dianne Hackborn | fb81d09 | 2015-08-03 17:14:46 -0700 | [diff] [blame] | 4023 | if (DEBUG_STACK) Slog.v(TAG, "Display changed displayId=" + displayId); |
Craig Mautner | 4a1cb22 | 2013-12-04 16:14:06 -0800 | [diff] [blame] | 4024 | mHandler.sendMessage(mHandler.obtainMessage(HANDLE_DISPLAY_CHANGED, displayId, 0)); |
| 4025 | } |
| 4026 | |
Wale Ogunwale | f16a281 | 2015-04-01 11:23:15 -0700 | [diff] [blame] | 4027 | private void handleDisplayAdded(int displayId) { |
Craig Mautner | 4a1cb22 | 2013-12-04 16:14:06 -0800 | [diff] [blame] | 4028 | synchronized (mService) { |
Andrii Kulian | 62e6f25 | 2017-05-30 22:46:53 -0700 | [diff] [blame] | 4029 | getActivityDisplayOrCreateLocked(displayId); |
Craig Mautner | 4a1cb22 | 2013-12-04 16:14:06 -0800 | [diff] [blame] | 4030 | } |
Craig Mautner | 4a1cb22 | 2013-12-04 16:14:06 -0800 | [diff] [blame] | 4031 | } |
| 4032 | |
Andrii Kulian | ca007a6 | 2016-11-22 16:33:28 -0800 | [diff] [blame] | 4033 | /** Check if display with specified id is added to the list. */ |
| 4034 | boolean isDisplayAdded(int displayId) { |
Andrii Kulian | 62e6f25 | 2017-05-30 22:46:53 -0700 | [diff] [blame] | 4035 | return getActivityDisplayOrCreateLocked(displayId) != null; |
| 4036 | } |
| 4037 | |
Wale Ogunwale | 04a05ac | 2017-09-17 21:35:02 -0700 | [diff] [blame] | 4038 | // TODO: Look into consolidating with getActivityDisplayOrCreateLocked() |
Andrii Kulian | 94e82d9b0 | 2017-07-13 15:33:06 -0700 | [diff] [blame] | 4039 | ActivityDisplay getActivityDisplay(int displayId) { |
| 4040 | return mActivityDisplays.get(displayId); |
| 4041 | } |
| 4042 | |
Wale Ogunwale | 04a05ac | 2017-09-17 21:35:02 -0700 | [diff] [blame] | 4043 | // TODO(multi-display): Look at all callpoints to make sure they make sense in multi-display. |
| 4044 | ActivityDisplay getDefaultDisplay() { |
| 4045 | return mActivityDisplays.get(DEFAULT_DISPLAY); |
| 4046 | } |
| 4047 | |
Andrii Kulian | 62e6f25 | 2017-05-30 22:46:53 -0700 | [diff] [blame] | 4048 | /** |
| 4049 | * Get an existing instance of {@link ActivityDisplay} or create new if there is a |
| 4050 | * corresponding record in display manager. |
| 4051 | */ |
Wale Ogunwale | 04a05ac | 2017-09-17 21:35:02 -0700 | [diff] [blame] | 4052 | // TODO: Look into consolidating with getActivityDisplay() |
| 4053 | ActivityDisplay getActivityDisplayOrCreateLocked(int displayId) { |
Andrii Kulian | 62e6f25 | 2017-05-30 22:46:53 -0700 | [diff] [blame] | 4054 | ActivityDisplay activityDisplay = mActivityDisplays.get(displayId); |
| 4055 | if (activityDisplay != null) { |
| 4056 | return activityDisplay; |
| 4057 | } |
| 4058 | if (mDisplayManager == null) { |
| 4059 | // The system isn't fully initialized yet. |
| 4060 | return null; |
| 4061 | } |
| 4062 | final Display display = mDisplayManager.getDisplay(displayId); |
| 4063 | if (display == null) { |
| 4064 | // The display is not registered in DisplayManager. |
| 4065 | return null; |
| 4066 | } |
| 4067 | // 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] | 4068 | activityDisplay = new ActivityDisplay(this, displayId); |
| 4069 | attachDisplay(activityDisplay); |
Andrii Kulian | 62e6f25 | 2017-05-30 22:46:53 -0700 | [diff] [blame] | 4070 | calculateDefaultMinimalSizeOfResizeableTasks(activityDisplay); |
| 4071 | mWindowManager.onDisplayAdded(displayId); |
| 4072 | return activityDisplay; |
Andrii Kulian | ca007a6 | 2016-11-22 16:33:28 -0800 | [diff] [blame] | 4073 | } |
| 4074 | |
Wale Ogunwale | 9dcf946 | 2017-09-19 15:13:01 -0700 | [diff] [blame] | 4075 | @VisibleForTesting |
| 4076 | void attachDisplay(ActivityDisplay display) { |
| 4077 | mActivityDisplays.put(display.mDisplayId, display); |
| 4078 | } |
| 4079 | |
Filip Gruszczynski | d2f1d94 | 2015-10-14 15:10:12 -0700 | [diff] [blame] | 4080 | private void calculateDefaultMinimalSizeOfResizeableTasks(ActivityDisplay display) { |
Andrii Kulian | f66a83d | 2016-05-17 12:17:44 -0700 | [diff] [blame] | 4081 | mDefaultMinSizeOfResizeableTask = |
Jorim Jaggi | 19cf297 | 2016-04-07 23:26:10 -0700 | [diff] [blame] | 4082 | mService.mContext.getResources().getDimensionPixelSize( |
| 4083 | com.android.internal.R.dimen.default_minimal_size_resizable_task); |
Filip Gruszczynski | d2f1d94 | 2015-10-14 15:10:12 -0700 | [diff] [blame] | 4084 | } |
| 4085 | |
Wale Ogunwale | f16a281 | 2015-04-01 11:23:15 -0700 | [diff] [blame] | 4086 | private void handleDisplayRemoved(int displayId) { |
Andrii Kulian | a33818c | 2017-02-16 16:11:30 -0800 | [diff] [blame] | 4087 | if (displayId == DEFAULT_DISPLAY) { |
| 4088 | throw new IllegalArgumentException("Can't remove the primary display."); |
| 4089 | } |
| 4090 | |
Craig Mautner | 4a1cb22 | 2013-12-04 16:14:06 -0800 | [diff] [blame] | 4091 | synchronized (mService) { |
Wale Ogunwale | a0f5b5e | 2017-10-11 09:37:23 -0700 | [diff] [blame] | 4092 | final ActivityDisplay activityDisplay = mActivityDisplays.get(displayId); |
| 4093 | if (activityDisplay == null) { |
| 4094 | return; |
Craig Mautner | 4a1cb22 | 2013-12-04 16:14:06 -0800 | [diff] [blame] | 4095 | } |
Bryce Lee | f19cbe2 | 2018-02-02 15:09:21 -0800 | [diff] [blame] | 4096 | |
| 4097 | activityDisplay.remove(); |
Wale Ogunwale | a0f5b5e | 2017-10-11 09:37:23 -0700 | [diff] [blame] | 4098 | |
| 4099 | releaseSleepTokens(activityDisplay); |
| 4100 | |
| 4101 | mActivityDisplays.remove(displayId); |
Craig Mautner | 4a1cb22 | 2013-12-04 16:14:06 -0800 | [diff] [blame] | 4102 | } |
Craig Mautner | 4a1cb22 | 2013-12-04 16:14:06 -0800 | [diff] [blame] | 4103 | } |
| 4104 | |
Wale Ogunwale | f16a281 | 2015-04-01 11:23:15 -0700 | [diff] [blame] | 4105 | private void handleDisplayChanged(int displayId) { |
Craig Mautner | 4a1cb22 | 2013-12-04 16:14:06 -0800 | [diff] [blame] | 4106 | synchronized (mService) { |
Craig Mautner | e0a3884 | 2013-12-16 16:14:02 -0800 | [diff] [blame] | 4107 | ActivityDisplay activityDisplay = mActivityDisplays.get(displayId); |
Bryce Lee | f3c6a47 | 2017-11-14 14:53:06 -0800 | [diff] [blame] | 4108 | // TODO: The following code block should be moved into {@link ActivityDisplay}. |
Craig Mautner | e0a3884 | 2013-12-16 16:14:02 -0800 | [diff] [blame] | 4109 | if (activityDisplay != null) { |
David Stevens | 9440dc8 | 2017-03-16 19:00:20 -0700 | [diff] [blame] | 4110 | // The window policy is responsible for stopping activities on the default display |
| 4111 | if (displayId != Display.DEFAULT_DISPLAY) { |
| 4112 | int displayState = activityDisplay.mDisplay.getState(); |
| 4113 | if (displayState == Display.STATE_OFF && activityDisplay.mOffToken == null) { |
| 4114 | activityDisplay.mOffToken = |
| 4115 | mService.acquireSleepToken("Display-off", displayId); |
| 4116 | } else if (displayState == Display.STATE_ON |
| 4117 | && activityDisplay.mOffToken != null) { |
| 4118 | activityDisplay.mOffToken.release(); |
| 4119 | activityDisplay.mOffToken = null; |
| 4120 | } |
| 4121 | } |
Bryce Lee | f3c6a47 | 2017-11-14 14:53:06 -0800 | [diff] [blame] | 4122 | |
| 4123 | activityDisplay.updateBounds(); |
Craig Mautner | 4a1cb22 | 2013-12-04 16:14:06 -0800 | [diff] [blame] | 4124 | } |
Bryce Lee | af3a400 | 2017-03-20 10:37:12 -0700 | [diff] [blame] | 4125 | mWindowManager.onDisplayChanged(displayId); |
Craig Mautner | 4a1cb22 | 2013-12-04 16:14:06 -0800 | [diff] [blame] | 4126 | } |
Craig Mautner | 4a1cb22 | 2013-12-04 16:14:06 -0800 | [diff] [blame] | 4127 | } |
| 4128 | |
David Stevens | 9440dc8 | 2017-03-16 19:00:20 -0700 | [diff] [blame] | 4129 | SleepToken createSleepTokenLocked(String tag, int displayId) { |
| 4130 | ActivityDisplay display = mActivityDisplays.get(displayId); |
| 4131 | if (display == null) { |
| 4132 | throw new IllegalArgumentException("Invalid display: " + displayId); |
| 4133 | } |
| 4134 | |
| 4135 | final SleepTokenImpl token = new SleepTokenImpl(tag, displayId); |
| 4136 | mSleepTokens.add(token); |
| 4137 | display.mAllSleepTokens.add(token); |
| 4138 | return token; |
| 4139 | } |
| 4140 | |
| 4141 | private void removeSleepTokenLocked(SleepTokenImpl token) { |
| 4142 | mSleepTokens.remove(token); |
| 4143 | |
| 4144 | ActivityDisplay display = mActivityDisplays.get(token.mDisplayId); |
| 4145 | if (display != null) { |
| 4146 | display.mAllSleepTokens.remove(token); |
| 4147 | if (display.mAllSleepTokens.isEmpty()) { |
| 4148 | mService.updateSleepIfNeededLocked(); |
| 4149 | } |
| 4150 | } |
| 4151 | } |
| 4152 | |
| 4153 | private void releaseSleepTokens(ActivityDisplay display) { |
| 4154 | if (display.mAllSleepTokens.isEmpty()) { |
| 4155 | return; |
| 4156 | } |
Wale Ogunwale | 9dcf946 | 2017-09-19 15:13:01 -0700 | [diff] [blame] | 4157 | for (SleepToken token : display.mAllSleepTokens) { |
David Stevens | 9440dc8 | 2017-03-16 19:00:20 -0700 | [diff] [blame] | 4158 | mSleepTokens.remove(token); |
| 4159 | } |
| 4160 | display.mAllSleepTokens.clear(); |
| 4161 | |
| 4162 | mService.updateSleepIfNeededLocked(); |
| 4163 | } |
| 4164 | |
Wale Ogunwale | 6827856 | 2017-09-23 17:13:55 -0700 | [diff] [blame] | 4165 | private StackInfo getStackInfo(ActivityStack stack) { |
Andrii Kulian | 7e215d7 | 2017-04-26 18:33:28 -0700 | [diff] [blame] | 4166 | final int displayId = stack.mDisplayId; |
| 4167 | final ActivityDisplay display = mActivityDisplays.get(displayId); |
Craig Mautner | 4a1cb22 | 2013-12-04 16:14:06 -0800 | [diff] [blame] | 4168 | StackInfo info = new StackInfo(); |
Wale Ogunwale | 1666e31 | 2016-12-16 11:27:18 -0800 | [diff] [blame] | 4169 | stack.getWindowContainerBounds(info.bounds); |
Andrii Kulian | 7e215d7 | 2017-04-26 18:33:28 -0700 | [diff] [blame] | 4170 | info.displayId = displayId; |
Craig Mautner | 4a1cb22 | 2013-12-04 16:14:06 -0800 | [diff] [blame] | 4171 | info.stackId = stack.mStackId; |
Filip Gruszczynski | 21199bd | 2015-12-02 12:49:58 -0800 | [diff] [blame] | 4172 | info.userId = stack.mCurrentUser; |
Wale Ogunwale | 9dcf946 | 2017-09-19 15:13:01 -0700 | [diff] [blame] | 4173 | info.visible = stack.shouldBeVisible(null); |
Andrii Kulian | 62e6f25 | 2017-05-30 22:46:53 -0700 | [diff] [blame] | 4174 | // A stack might be not attached to a display. |
Wale Ogunwale | a0f5b5e | 2017-10-11 09:37:23 -0700 | [diff] [blame] | 4175 | info.position = display != null ? display.getIndexOf(stack) : 0; |
Wale Ogunwale | 6827856 | 2017-09-23 17:13:55 -0700 | [diff] [blame] | 4176 | info.configuration.setTo(stack.getConfiguration()); |
Craig Mautner | 4a1cb22 | 2013-12-04 16:14:06 -0800 | [diff] [blame] | 4177 | |
| 4178 | ArrayList<TaskRecord> tasks = stack.getAllTasks(); |
| 4179 | final int numTasks = tasks.size(); |
| 4180 | int[] taskIds = new int[numTasks]; |
| 4181 | String[] taskNames = new String[numTasks]; |
Wale Ogunwale | e4a0c57 | 2015-06-30 08:40:31 -0700 | [diff] [blame] | 4182 | Rect[] taskBounds = new Rect[numTasks]; |
Filip Gruszczynski | 21199bd | 2015-12-02 12:49:58 -0800 | [diff] [blame] | 4183 | int[] taskUserIds = new int[numTasks]; |
Craig Mautner | 4a1cb22 | 2013-12-04 16:14:06 -0800 | [diff] [blame] | 4184 | for (int i = 0; i < numTasks; ++i) { |
| 4185 | final TaskRecord task = tasks.get(i); |
| 4186 | taskIds[i] = task.taskId; |
| 4187 | taskNames[i] = task.origActivity != null ? task.origActivity.flattenToString() |
| 4188 | : task.realActivity != null ? task.realActivity.flattenToString() |
| 4189 | : task.getTopActivity() != null ? task.getTopActivity().packageName |
| 4190 | : "unknown"; |
Wale Ogunwale | e4a0c57 | 2015-06-30 08:40:31 -0700 | [diff] [blame] | 4191 | taskBounds[i] = new Rect(); |
Wale Ogunwale | e1fe7fa2 | 2016-12-15 18:27:00 -0800 | [diff] [blame] | 4192 | task.getWindowContainerBounds(taskBounds[i]); |
Filip Gruszczynski | 21199bd | 2015-12-02 12:49:58 -0800 | [diff] [blame] | 4193 | taskUserIds[i] = task.userId; |
Craig Mautner | 4a1cb22 | 2013-12-04 16:14:06 -0800 | [diff] [blame] | 4194 | } |
| 4195 | info.taskIds = taskIds; |
| 4196 | info.taskNames = taskNames; |
Wale Ogunwale | 868a5e1 | 2015-08-02 16:19:20 -0700 | [diff] [blame] | 4197 | info.taskBounds = taskBounds; |
Filip Gruszczynski | 21199bd | 2015-12-02 12:49:58 -0800 | [diff] [blame] | 4198 | info.taskUserIds = taskUserIds; |
Winson | d46b727 | 2016-04-20 11:54:27 -0700 | [diff] [blame] | 4199 | |
| 4200 | final ActivityRecord top = stack.topRunningActivityLocked(); |
| 4201 | info.topActivity = top != null ? top.intent.getComponent() : null; |
Craig Mautner | 4a1cb22 | 2013-12-04 16:14:06 -0800 | [diff] [blame] | 4202 | return info; |
| 4203 | } |
| 4204 | |
Wale Ogunwale | 6827856 | 2017-09-23 17:13:55 -0700 | [diff] [blame] | 4205 | StackInfo getStackInfo(int stackId) { |
Craig Mautner | 4a1cb22 | 2013-12-04 16:14:06 -0800 | [diff] [blame] | 4206 | ActivityStack stack = getStack(stackId); |
| 4207 | if (stack != null) { |
Wale Ogunwale | 6827856 | 2017-09-23 17:13:55 -0700 | [diff] [blame] | 4208 | return getStackInfo(stack); |
Craig Mautner | 4a1cb22 | 2013-12-04 16:14:06 -0800 | [diff] [blame] | 4209 | } |
| 4210 | return null; |
| 4211 | } |
| 4212 | |
Wale Ogunwale | 6827856 | 2017-09-23 17:13:55 -0700 | [diff] [blame] | 4213 | StackInfo getStackInfo(int windowingMode, int activityType) { |
| 4214 | final ActivityStack stack = getStack(windowingMode, activityType); |
| 4215 | return (stack != null) ? getStackInfo(stack) : null; |
| 4216 | } |
| 4217 | |
Craig Mautner | 4a1cb22 | 2013-12-04 16:14:06 -0800 | [diff] [blame] | 4218 | ArrayList<StackInfo> getAllStackInfosLocked() { |
Wale Ogunwale | e4a0c57 | 2015-06-30 08:40:31 -0700 | [diff] [blame] | 4219 | ArrayList<StackInfo> list = new ArrayList<>(); |
Craig Mautner | e0a3884 | 2013-12-16 16:14:02 -0800 | [diff] [blame] | 4220 | for (int displayNdx = 0; displayNdx < mActivityDisplays.size(); ++displayNdx) { |
Wale Ogunwale | a0f5b5e | 2017-10-11 09:37:23 -0700 | [diff] [blame] | 4221 | final ActivityDisplay display = mActivityDisplays.valueAt(displayNdx); |
| 4222 | for (int stackNdx = display.getChildCount() - 1; stackNdx >= 0; --stackNdx) { |
| 4223 | final ActivityStack stack = display.getChildAt(stackNdx); |
| 4224 | list.add(getStackInfo(stack)); |
Craig Mautner | 4a1cb22 | 2013-12-04 16:14:06 -0800 | [diff] [blame] | 4225 | } |
| 4226 | } |
| 4227 | return list; |
| 4228 | } |
| 4229 | |
Wale Ogunwale | 0568aed | 2017-09-08 13:29:37 -0700 | [diff] [blame] | 4230 | void handleNonResizableTaskIfNeeded(TaskRecord task, int preferredWindowingMode, |
Wale Ogunwale | a0f5b5e | 2017-10-11 09:37:23 -0700 | [diff] [blame] | 4231 | int preferredDisplayId, ActivityStack actualStack) { |
Wale Ogunwale | 0568aed | 2017-09-08 13:29:37 -0700 | [diff] [blame] | 4232 | handleNonResizableTaskIfNeeded(task, preferredWindowingMode, preferredDisplayId, |
Wale Ogunwale | a0f5b5e | 2017-10-11 09:37:23 -0700 | [diff] [blame] | 4233 | actualStack, false /* forceNonResizable */); |
Andrii Kulian | c2791664 | 2016-04-12 17:59:27 -0700 | [diff] [blame] | 4234 | } |
| 4235 | |
Wale Ogunwale | 0568aed | 2017-09-08 13:29:37 -0700 | [diff] [blame] | 4236 | void handleNonResizableTaskIfNeeded(TaskRecord task, int preferredWindowingMode, |
Wale Ogunwale | a0f5b5e | 2017-10-11 09:37:23 -0700 | [diff] [blame] | 4237 | int preferredDisplayId, ActivityStack actualStack, boolean forceNonResizable) { |
Andrii Kulian | 036e3ad | 2017-04-19 10:55:10 -0700 | [diff] [blame] | 4238 | final boolean isSecondaryDisplayPreferred = |
Wale Ogunwale | 0568aed | 2017-09-08 13:29:37 -0700 | [diff] [blame] | 4239 | (preferredDisplayId != DEFAULT_DISPLAY && preferredDisplayId != INVALID_DISPLAY); |
Wale Ogunwale | 926aade | 2017-08-29 11:24:37 -0700 | [diff] [blame] | 4240 | final boolean inSplitScreenMode = actualStack != null |
Wale Ogunwale | 7e1f5f5 | 2017-10-18 15:19:59 -0700 | [diff] [blame] | 4241 | && actualStack.getDisplay().hasSplitScreenPrimaryStack(); |
Wale Ogunwale | 0568aed | 2017-09-08 13:29:37 -0700 | [diff] [blame] | 4242 | if (((!inSplitScreenMode && preferredWindowingMode != WINDOWING_MODE_SPLIT_SCREEN_PRIMARY) |
Wale Ogunwale | 7e1f5f5 | 2017-10-18 15:19:59 -0700 | [diff] [blame] | 4243 | && !isSecondaryDisplayPreferred) || !task.isActivityTypeStandardOrUndefined()) { |
Wale Ogunwale | b9b16a7 | 2016-01-27 12:24:44 -0800 | [diff] [blame] | 4244 | return; |
| 4245 | } |
| 4246 | |
Andrii Kulian | 036e3ad | 2017-04-19 10:55:10 -0700 | [diff] [blame] | 4247 | // Handle incorrect launch/move to secondary display if needed. |
Andrii Kulian | 036e3ad | 2017-04-19 10:55:10 -0700 | [diff] [blame] | 4248 | if (isSecondaryDisplayPreferred) { |
| 4249 | final int actualDisplayId = task.getStack().mDisplayId; |
| 4250 | if (!task.canBeLaunchedOnDisplay(actualDisplayId)) { |
Andrii Kulian | b850ea5 | 2017-12-12 23:49:10 -0800 | [diff] [blame] | 4251 | throw new IllegalStateException("Task resolved to incompatible display"); |
Andrii Kulian | 036e3ad | 2017-04-19 10:55:10 -0700 | [diff] [blame] | 4252 | } |
Andrii Kulian | b850ea5 | 2017-12-12 23:49:10 -0800 | [diff] [blame] | 4253 | // The task might have landed on a display different from requested. |
| 4254 | // TODO(multi-display): Find proper stack for the task on the default display. |
| 4255 | mService.setTaskWindowingMode(task.taskId, |
| 4256 | WINDOWING_MODE_FULLSCREEN_OR_SPLIT_SCREEN_SECONDARY, true /* toTop */); |
| 4257 | if (preferredDisplayId != actualDisplayId) { |
Andrii Kulian | 036e3ad | 2017-04-19 10:55:10 -0700 | [diff] [blame] | 4258 | // Display a warning toast that we tried to put a non-resizeable task on a secondary |
| 4259 | // display with config different from global config. |
| 4260 | mService.mTaskChangeNotificationController |
| 4261 | .notifyActivityLaunchOnSecondaryDisplayFailed(); |
Wale Ogunwale | 2b07da8 | 2017-11-08 14:52:40 -0800 | [diff] [blame] | 4262 | return; |
Andrii Kulian | 036e3ad | 2017-04-19 10:55:10 -0700 | [diff] [blame] | 4263 | } |
Wale Ogunwale | 2b07da8 | 2017-11-08 14:52:40 -0800 | [diff] [blame] | 4264 | } |
| 4265 | |
Wale Ogunwale | 2b07da8 | 2017-11-08 14:52:40 -0800 | [diff] [blame] | 4266 | if (!task.supportsSplitScreenWindowingMode() || forceNonResizable) { |
Wale Ogunwale | 30e441d | 2017-11-09 08:28:45 -0800 | [diff] [blame] | 4267 | // Display a warning toast that we tried to put an app that doesn't support split-screen |
| 4268 | // in split-screen. |
Wale Ogunwale | 2b07da8 | 2017-11-08 14:52:40 -0800 | [diff] [blame] | 4269 | mService.mTaskChangeNotificationController.notifyActivityDismissingDockedStack(); |
Jorim Jaggi | d53f092 | 2016-04-06 22:16:23 -0700 | [diff] [blame] | 4270 | |
Andrii Kulian | c2791664 | 2016-04-12 17:59:27 -0700 | [diff] [blame] | 4271 | // Dismiss docked stack. If task appeared to be in docked stack but is not resizable - |
| 4272 | // 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] | 4273 | |
Wale Ogunwale | 2b07da8 | 2017-11-08 14:52:40 -0800 | [diff] [blame] | 4274 | final ActivityStack dockedStack = |
| 4275 | task.getStack().getDisplay().getSplitScreenPrimaryStack(); |
Wale Ogunwale | 9dcf946 | 2017-09-19 15:13:01 -0700 | [diff] [blame] | 4276 | if (dockedStack != null) { |
Wale Ogunwale | a0f5b5e | 2017-10-11 09:37:23 -0700 | [diff] [blame] | 4277 | moveTasksToFullscreenStackLocked(dockedStack, actualStack == dockedStack); |
Wale Ogunwale | 9dcf946 | 2017-09-19 15:13:01 -0700 | [diff] [blame] | 4278 | } |
Wale Ogunwale | 2b07da8 | 2017-11-08 14:52:40 -0800 | [diff] [blame] | 4279 | return; |
| 4280 | } |
| 4281 | |
Wale Ogunwale | 30e441d | 2017-11-09 08:28:45 -0800 | [diff] [blame] | 4282 | final ActivityRecord topActivity = task.getTopActivity(); |
Wale Ogunwale | 2b07da8 | 2017-11-08 14:52:40 -0800 | [diff] [blame] | 4283 | if (topActivity != null && topActivity.isNonResizableOrForcedResizable() |
| 4284 | && !topActivity.noDisplay) { |
Andrii Kulian | 036e3ad | 2017-04-19 10:55:10 -0700 | [diff] [blame] | 4285 | final String packageName = topActivity.appInfo.packageName; |
| 4286 | final int reason = isSecondaryDisplayPreferred |
| 4287 | ? FORCED_RESIZEABLE_REASON_SECONDARY_DISPLAY |
| 4288 | : FORCED_RESIZEABLE_REASON_SPLIT_SCREEN; |
Yorke Lee | bd54c2a | 2016-10-25 13:49:23 -0700 | [diff] [blame] | 4289 | mService.mTaskChangeNotificationController.notifyActivityForcedResizable( |
Andrii Kulian | 036e3ad | 2017-04-19 10:55:10 -0700 | [diff] [blame] | 4290 | task.taskId, reason, packageName); |
Wale Ogunwale | b9b16a7 | 2016-01-27 12:24:44 -0800 | [diff] [blame] | 4291 | } |
Chong Zhang | b15758a | 2015-11-17 12:12:03 -0800 | [diff] [blame] | 4292 | } |
| 4293 | |
Jorim Jaggi | fe89d12 | 2015-12-22 16:28:44 +0100 | [diff] [blame] | 4294 | void activityRelaunchedLocked(IBinder token) { |
| 4295 | mWindowManager.notifyAppRelaunchingFinished(token); |
David Stevens | 9440dc8 | 2017-03-16 19:00:20 -0700 | [diff] [blame] | 4296 | final ActivityRecord r = ActivityRecord.isInStackLocked(token); |
| 4297 | if (r != null) { |
| 4298 | if (r.getStack().shouldSleepOrShutDownActivities()) { |
Wale Ogunwale | 3e99736 | 2016-09-06 10:37:56 -0700 | [diff] [blame] | 4299 | r.setSleeping(true, true); |
| 4300 | } |
| 4301 | } |
Jorim Jaggi | fe89d12 | 2015-12-22 16:28:44 +0100 | [diff] [blame] | 4302 | } |
| 4303 | |
| 4304 | void activityRelaunchingLocked(ActivityRecord r) { |
| 4305 | mWindowManager.notifyAppRelaunching(r.appToken); |
| 4306 | } |
| 4307 | |
Filip Gruszczynski | 77d9448 | 2015-12-11 13:59:52 -0800 | [diff] [blame] | 4308 | void logStackState() { |
| 4309 | mActivityMetricsLogger.logWindowState(); |
| 4310 | } |
| 4311 | |
Winson Chung | 5af42fc | 2017-03-24 17:11:33 -0700 | [diff] [blame] | 4312 | void scheduleUpdateMultiWindowMode(TaskRecord task) { |
Winson Chung | 8bca9e4 | 2017-04-16 15:59:43 -0700 | [diff] [blame] | 4313 | // If the stack is animating in a way where we will be forcing a multi-mode change at the |
| 4314 | // end, then ensure that we defer all in between multi-window mode changes |
| 4315 | if (task.getStack().deferScheduleMultiWindowModeChanged()) { |
| 4316 | return; |
| 4317 | } |
| 4318 | |
Wale Ogunwale | 22e2526 | 2016-02-01 10:32:02 -0800 | [diff] [blame] | 4319 | for (int i = task.mActivities.size() - 1; i >= 0; i--) { |
| 4320 | final ActivityRecord r = task.mActivities.get(i); |
| 4321 | if (r.app != null && r.app.thread != null) { |
| 4322 | mMultiWindowModeChangedActivities.add(r); |
| 4323 | } |
| 4324 | } |
| 4325 | |
| 4326 | if (!mHandler.hasMessages(REPORT_MULTI_WINDOW_MODE_CHANGED_MSG)) { |
| 4327 | mHandler.sendEmptyMessage(REPORT_MULTI_WINDOW_MODE_CHANGED_MSG); |
| 4328 | } |
| 4329 | } |
| 4330 | |
Winson Chung | 5af42fc | 2017-03-24 17:11:33 -0700 | [diff] [blame] | 4331 | void scheduleUpdatePictureInPictureModeIfNeeded(TaskRecord task, ActivityStack prevStack) { |
Andrii Kulian | 02b7a83 | 2016-10-06 23:11:56 -0700 | [diff] [blame] | 4332 | final ActivityStack stack = task.getStack(); |
Wale Ogunwale | 22e2526 | 2016-02-01 10:32:02 -0800 | [diff] [blame] | 4333 | if (prevStack == null || prevStack == stack |
Wale Ogunwale | 44f036f | 2017-09-29 05:09:09 -0700 | [diff] [blame] | 4334 | || (!prevStack.inPinnedWindowingMode() && !stack.inPinnedWindowingMode())) { |
Wale Ogunwale | 22e2526 | 2016-02-01 10:32:02 -0800 | [diff] [blame] | 4335 | return; |
| 4336 | } |
| 4337 | |
Bryce Lee | f3c6a47 | 2017-11-14 14:53:06 -0800 | [diff] [blame] | 4338 | scheduleUpdatePictureInPictureModeIfNeeded(task, stack.getOverrideBounds()); |
Winson Chung | 5af42fc | 2017-03-24 17:11:33 -0700 | [diff] [blame] | 4339 | } |
Wale Ogunwale | 22e2526 | 2016-02-01 10:32:02 -0800 | [diff] [blame] | 4340 | |
Winson Chung | ab76bbc | 2017-08-14 13:33:51 -0700 | [diff] [blame] | 4341 | void scheduleUpdatePictureInPictureModeIfNeeded(TaskRecord task, Rect targetStackBounds) { |
| 4342 | for (int i = task.mActivities.size() - 1; i >= 0; i--) { |
| 4343 | final ActivityRecord r = task.mActivities.get(i); |
| 4344 | if (r.app != null && r.app.thread != null) { |
| 4345 | mPipModeChangedActivities.add(r); |
Wale Ogunwale | eb76b76 | 2017-11-17 10:08:04 -0800 | [diff] [blame] | 4346 | // If we are scheduling pip change, then remove this activity from multi-window |
| 4347 | // change list as the processing of pip change will make sure multi-window changed |
| 4348 | // message is processed in the right order relative to pip changed. |
| 4349 | mMultiWindowModeChangedActivities.remove(r); |
Winson Chung | 5af42fc | 2017-03-24 17:11:33 -0700 | [diff] [blame] | 4350 | } |
Winson Chung | ab76bbc | 2017-08-14 13:33:51 -0700 | [diff] [blame] | 4351 | } |
| 4352 | mPipModeChangedTargetStackBounds = targetStackBounds; |
Winson Chung | 5af42fc | 2017-03-24 17:11:33 -0700 | [diff] [blame] | 4353 | |
Winson Chung | ab76bbc | 2017-08-14 13:33:51 -0700 | [diff] [blame] | 4354 | if (!mHandler.hasMessages(REPORT_PIP_MODE_CHANGED_MSG)) { |
| 4355 | mHandler.sendEmptyMessage(REPORT_PIP_MODE_CHANGED_MSG); |
| 4356 | } |
| 4357 | } |
| 4358 | |
| 4359 | void updatePictureInPictureMode(TaskRecord task, Rect targetStackBounds, boolean forceUpdate) { |
| 4360 | mHandler.removeMessages(REPORT_PIP_MODE_CHANGED_MSG); |
| 4361 | for (int i = task.mActivities.size() - 1; i >= 0; i--) { |
| 4362 | final ActivityRecord r = task.mActivities.get(i); |
| 4363 | if (r.app != null && r.app.thread != null) { |
| 4364 | r.updatePictureInPictureMode(targetStackBounds, forceUpdate); |
Winson Chung | 5af42fc | 2017-03-24 17:11:33 -0700 | [diff] [blame] | 4365 | } |
Wale Ogunwale | 22e2526 | 2016-02-01 10:32:02 -0800 | [diff] [blame] | 4366 | } |
| 4367 | } |
| 4368 | |
Tony Mak | 853304c | 2016-04-18 15:17:41 +0100 | [diff] [blame] | 4369 | void setDockedStackMinimized(boolean minimized) { |
| 4370 | mIsDockMinimized = minimized; |
Tony Mak | 853304c | 2016-04-18 15:17:41 +0100 | [diff] [blame] | 4371 | } |
| 4372 | |
chaviw | 59b9885 | 2017-06-13 12:05:44 -0700 | [diff] [blame] | 4373 | void wakeUp(String reason) { |
| 4374 | mPowerManager.wakeUp(SystemClock.uptimeMillis(), "android.server.am:TURN_ON:" + reason); |
| 4375 | } |
| 4376 | |
| 4377 | /** |
| 4378 | * Begin deferring resume to avoid duplicate resumes in one pass. |
| 4379 | */ |
| 4380 | private void beginDeferResume() { |
| 4381 | mDeferResumeCount++; |
| 4382 | } |
| 4383 | |
| 4384 | /** |
| 4385 | * End deferring resume and determine if resume can be called. |
| 4386 | */ |
| 4387 | private void endDeferResume() { |
| 4388 | mDeferResumeCount--; |
| 4389 | } |
| 4390 | |
| 4391 | /** |
| 4392 | * @return True if resume can be called. |
| 4393 | */ |
| 4394 | private boolean readyToResume() { |
| 4395 | return mDeferResumeCount == 0; |
| 4396 | } |
| 4397 | |
Craig Mautner | ce5f3cb | 2013-04-22 08:58:54 -0700 | [diff] [blame] | 4398 | private final class ActivityStackSupervisorHandler extends Handler { |
Craig Mautner | f333327 | 2013-04-22 10:55:53 -0700 | [diff] [blame] | 4399 | |
Craig Mautner | ce5f3cb | 2013-04-22 08:58:54 -0700 | [diff] [blame] | 4400 | public ActivityStackSupervisorHandler(Looper looper) { |
| 4401 | super(looper); |
| 4402 | } |
| 4403 | |
Winson Chung | 4dabf23 | 2017-01-25 13:25:22 -0800 | [diff] [blame] | 4404 | void activityIdleInternal(ActivityRecord r, boolean processPausingActivities) { |
Craig Mautner | f333327 | 2013-04-22 10:55:53 -0700 | [diff] [blame] | 4405 | synchronized (mService) { |
Winson Chung | 4dabf23 | 2017-01-25 13:25:22 -0800 | [diff] [blame] | 4406 | activityIdleInternalLocked(r != null ? r.appToken : null, true /* fromTimeout */, |
| 4407 | processPausingActivities, null); |
Craig Mautner | f333327 | 2013-04-22 10:55:53 -0700 | [diff] [blame] | 4408 | } |
Craig Mautner | 7ea5bd4 | 2013-07-05 15:27:08 -0700 | [diff] [blame] | 4409 | } |
| 4410 | |
Craig Mautner | ce5f3cb | 2013-04-22 08:58:54 -0700 | [diff] [blame] | 4411 | @Override |
| 4412 | public void handleMessage(Message msg) { |
| 4413 | switch (msg.what) { |
Wale Ogunwale | 22e2526 | 2016-02-01 10:32:02 -0800 | [diff] [blame] | 4414 | case REPORT_MULTI_WINDOW_MODE_CHANGED_MSG: { |
| 4415 | synchronized (mService) { |
| 4416 | for (int i = mMultiWindowModeChangedActivities.size() - 1; i >= 0; i--) { |
| 4417 | final ActivityRecord r = mMultiWindowModeChangedActivities.remove(i); |
Winson Chung | 5af42fc | 2017-03-24 17:11:33 -0700 | [diff] [blame] | 4418 | r.updateMultiWindowMode(); |
Wale Ogunwale | 22e2526 | 2016-02-01 10:32:02 -0800 | [diff] [blame] | 4419 | } |
| 4420 | } |
| 4421 | } break; |
| 4422 | case REPORT_PIP_MODE_CHANGED_MSG: { |
| 4423 | synchronized (mService) { |
| 4424 | for (int i = mPipModeChangedActivities.size() - 1; i >= 0; i--) { |
| 4425 | final ActivityRecord r = mPipModeChangedActivities.remove(i); |
Winson Chung | ab76bbc | 2017-08-14 13:33:51 -0700 | [diff] [blame] | 4426 | r.updatePictureInPictureMode(mPipModeChangedTargetStackBounds, |
| 4427 | false /* forceUpdate */); |
Wale Ogunwale | 22e2526 | 2016-02-01 10:32:02 -0800 | [diff] [blame] | 4428 | } |
| 4429 | } |
| 4430 | } break; |
Craig Mautner | f333327 | 2013-04-22 10:55:53 -0700 | [diff] [blame] | 4431 | case IDLE_TIMEOUT_MSG: { |
Wale Ogunwale | 0fc365c | 2015-05-25 19:35:42 -0700 | [diff] [blame] | 4432 | if (DEBUG_IDLE) Slog.d(TAG_IDLE, |
| 4433 | "handleMessage: IDLE_TIMEOUT_MSG: r=" + msg.obj); |
Craig Mautner | f333327 | 2013-04-22 10:55:53 -0700 | [diff] [blame] | 4434 | // We don't at this point know if the activity is fullscreen, |
| 4435 | // so we need to be conservative and assume it isn't. |
Winson Chung | 4dabf23 | 2017-01-25 13:25:22 -0800 | [diff] [blame] | 4436 | activityIdleInternal((ActivityRecord) msg.obj, |
| 4437 | true /* processPausingActivities */); |
Craig Mautner | f333327 | 2013-04-22 10:55:53 -0700 | [diff] [blame] | 4438 | } break; |
| 4439 | case IDLE_NOW_MSG: { |
Wale Ogunwale | 0fc365c | 2015-05-25 19:35:42 -0700 | [diff] [blame] | 4440 | 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] | 4441 | activityIdleInternal((ActivityRecord) msg.obj, |
| 4442 | false /* processPausingActivities */); |
Craig Mautner | f333327 | 2013-04-22 10:55:53 -0700 | [diff] [blame] | 4443 | } break; |
Craig Mautner | 05d2903 | 2013-05-03 13:40:13 -0700 | [diff] [blame] | 4444 | case RESUME_TOP_ACTIVITY_MSG: { |
| 4445 | synchronized (mService) { |
Wale Ogunwale | d046a01 | 2015-12-24 13:05:59 -0800 | [diff] [blame] | 4446 | resumeFocusedStackTopActivityLocked(); |
Craig Mautner | 05d2903 | 2013-05-03 13:40:13 -0700 | [diff] [blame] | 4447 | } |
| 4448 | } break; |
Craig Mautner | 0eea92c | 2013-05-16 13:35:39 -0700 | [diff] [blame] | 4449 | case SLEEP_TIMEOUT_MSG: { |
| 4450 | synchronized (mService) { |
Fyodor Kupolov | 9b80b94 | 2016-06-16 16:29:05 -0700 | [diff] [blame] | 4451 | if (mService.isSleepingOrShuttingDownLocked()) { |
Craig Mautner | 0eea92c | 2013-05-16 13:35:39 -0700 | [diff] [blame] | 4452 | Slog.w(TAG, "Sleep timeout! Sleeping now."); |
David Stevens | 9440dc8 | 2017-03-16 19:00:20 -0700 | [diff] [blame] | 4453 | checkReadyForSleepLocked(false /* allowDelay */); |
Craig Mautner | 0eea92c | 2013-05-16 13:35:39 -0700 | [diff] [blame] | 4454 | } |
| 4455 | } |
| 4456 | } break; |
Craig Mautner | 7ea5bd4 | 2013-07-05 15:27:08 -0700 | [diff] [blame] | 4457 | case LAUNCH_TIMEOUT_MSG: { |
Craig Mautner | 7ea5bd4 | 2013-07-05 15:27:08 -0700 | [diff] [blame] | 4458 | synchronized (mService) { |
| 4459 | if (mLaunchingActivity.isHeld()) { |
| 4460 | Slog.w(TAG, "Launch timeout has expired, giving up wake lock!"); |
| 4461 | if (VALIDATE_WAKE_LOCK_CALLER |
| 4462 | && Binder.getCallingUid() != Process.myUid()) { |
| 4463 | throw new IllegalStateException("Calling must be system uid"); |
| 4464 | } |
| 4465 | mLaunchingActivity.release(); |
| 4466 | } |
| 4467 | } |
| 4468 | } break; |
Craig Mautner | 4a1cb22 | 2013-12-04 16:14:06 -0800 | [diff] [blame] | 4469 | case HANDLE_DISPLAY_ADDED: { |
Wale Ogunwale | f16a281 | 2015-04-01 11:23:15 -0700 | [diff] [blame] | 4470 | handleDisplayAdded(msg.arg1); |
Craig Mautner | 4a1cb22 | 2013-12-04 16:14:06 -0800 | [diff] [blame] | 4471 | } break; |
| 4472 | case HANDLE_DISPLAY_CHANGED: { |
Wale Ogunwale | f16a281 | 2015-04-01 11:23:15 -0700 | [diff] [blame] | 4473 | handleDisplayChanged(msg.arg1); |
Craig Mautner | 4a1cb22 | 2013-12-04 16:14:06 -0800 | [diff] [blame] | 4474 | } break; |
| 4475 | case HANDLE_DISPLAY_REMOVED: { |
Wale Ogunwale | f16a281 | 2015-04-01 11:23:15 -0700 | [diff] [blame] | 4476 | handleDisplayRemoved(msg.arg1); |
Craig Mautner | 4a1cb22 | 2013-12-04 16:14:06 -0800 | [diff] [blame] | 4477 | } break; |
Craig Mautner | bb74246 | 2014-07-07 15:28:55 -0700 | [diff] [blame] | 4478 | case LAUNCH_TASK_BEHIND_COMPLETE: { |
| 4479 | synchronized (mService) { |
Wale Ogunwale | 7d70117 | 2015-03-11 15:36:30 -0700 | [diff] [blame] | 4480 | ActivityRecord r = ActivityRecord.forTokenLocked((IBinder) msg.obj); |
Craig Mautner | bb74246 | 2014-07-07 15:28:55 -0700 | [diff] [blame] | 4481 | if (r != null) { |
| 4482 | handleLaunchTaskBehindCompleteLocked(r); |
| 4483 | } |
| 4484 | } |
| 4485 | } break; |
Chong Zhang | c806d90 | 2015-11-30 09:44:27 -0800 | [diff] [blame] | 4486 | |
Craig Mautner | ce5f3cb | 2013-04-22 08:58:54 -0700 | [diff] [blame] | 4487 | } |
| 4488 | } |
| 4489 | } |
Craig Mautner | ed6649f | 2013-12-02 14:08:25 -0800 | [diff] [blame] | 4490 | |
Filip Gruszczynski | caae14e | 2015-12-16 14:40:04 -0800 | [diff] [blame] | 4491 | ActivityStack findStackBehind(ActivityStack stack) { |
| 4492 | // 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] | 4493 | final ActivityDisplay display = mActivityDisplays.get(DEFAULT_DISPLAY); |
Filip Gruszczynski | caae14e | 2015-12-16 14:40:04 -0800 | [diff] [blame] | 4494 | if (display == null) { |
| 4495 | return null; |
| 4496 | } |
Wale Ogunwale | a0f5b5e | 2017-10-11 09:37:23 -0700 | [diff] [blame] | 4497 | for (int i = display.getChildCount() - 1; i >= 0; i--) { |
| 4498 | if (display.getChildAt(i) == stack && i > 0) { |
| 4499 | return display.getChildAt(i - 1); |
Filip Gruszczynski | caae14e | 2015-12-16 14:40:04 -0800 | [diff] [blame] | 4500 | } |
| 4501 | } |
| 4502 | throw new IllegalStateException("Failed to find a stack behind stack=" + stack |
Wale Ogunwale | a0f5b5e | 2017-10-11 09:37:23 -0700 | [diff] [blame] | 4503 | + " in=" + display); |
Filip Gruszczynski | caae14e | 2015-12-16 14:40:04 -0800 | [diff] [blame] | 4504 | } |
Jorim Jaggi | 0b46f3c | 2016-03-14 12:21:37 +0100 | [diff] [blame] | 4505 | |
Jorim Jaggi | c69bd22 | 2016-03-15 14:38:37 +0100 | [diff] [blame] | 4506 | /** |
| 4507 | * Puts a task into resizing mode during the next app transition. |
| 4508 | * |
Wale Ogunwale | e1fe7fa2 | 2016-12-15 18:27:00 -0800 | [diff] [blame] | 4509 | * @param task The task to put into resizing mode |
Jorim Jaggi | c69bd22 | 2016-03-15 14:38:37 +0100 | [diff] [blame] | 4510 | */ |
Bryce Lee | d3624e1 | 2017-11-30 08:51:45 -0800 | [diff] [blame] | 4511 | void setResizingDuringAnimation(TaskRecord task) { |
Wale Ogunwale | e1fe7fa2 | 2016-12-15 18:27:00 -0800 | [diff] [blame] | 4512 | mResizingTasksDuringAnimation.add(task.taskId); |
| 4513 | task.setTaskDockedResizing(true); |
Jorim Jaggi | c69bd22 | 2016-03-15 14:38:37 +0100 | [diff] [blame] | 4514 | } |
| 4515 | |
Jorim Jaggi | 4d8d32c | 2018-01-19 15:57:41 +0100 | [diff] [blame] | 4516 | int startActivityFromRecents(int callingPid, int callingUid, int taskId, |
| 4517 | SafeActivityOptions options) { |
Wale Ogunwale | dd2ae3d | 2018-02-15 13:58:46 -0800 | [diff] [blame] | 4518 | TaskRecord task = null; |
Jorim Jaggi | 0b46f3c | 2016-03-14 12:21:37 +0100 | [diff] [blame] | 4519 | final String callingPackage; |
| 4520 | final Intent intent; |
| 4521 | final int userId; |
Wale Ogunwale | 0568aed | 2017-09-08 13:29:37 -0700 | [diff] [blame] | 4522 | int activityType = ACTIVITY_TYPE_UNDEFINED; |
| 4523 | int windowingMode = WINDOWING_MODE_UNDEFINED; |
Jorim Jaggi | 4d8d32c | 2018-01-19 15:57:41 +0100 | [diff] [blame] | 4524 | final ActivityOptions activityOptions = options != null |
| 4525 | ? options.getOptions(this) |
| 4526 | : null; |
Wale Ogunwale | 0568aed | 2017-09-08 13:29:37 -0700 | [diff] [blame] | 4527 | if (activityOptions != null) { |
| 4528 | activityType = activityOptions.getLaunchActivityType(); |
| 4529 | windowingMode = activityOptions.getLaunchWindowingMode(); |
| 4530 | } |
| 4531 | if (activityType == ACTIVITY_TYPE_HOME || activityType == ACTIVITY_TYPE_RECENTS) { |
Wale Ogunwale | ab5de37 | 2017-10-18 06:46:31 -0700 | [diff] [blame] | 4532 | throw new IllegalArgumentException("startActivityFromRecents: Task " |
Matthew Ng | ae1ff4f | 2016-11-10 15:49:14 -0800 | [diff] [blame] | 4533 | + taskId + " can't be launch in the home/recents stack."); |
Jorim Jaggi | 0b46f3c | 2016-03-14 12:21:37 +0100 | [diff] [blame] | 4534 | } |
Jorim Jaggi | 3c800a4 | 2016-04-15 19:44:50 -0700 | [diff] [blame] | 4535 | |
Matthew Ng | 606dd80 | 2017-06-05 14:06:32 -0700 | [diff] [blame] | 4536 | mWindowManager.deferSurfaceLayout(); |
| 4537 | try { |
Wale Ogunwale | 0568aed | 2017-09-08 13:29:37 -0700 | [diff] [blame] | 4538 | if (windowingMode == WINDOWING_MODE_SPLIT_SCREEN_PRIMARY) { |
Matthew Ng | 606dd80 | 2017-06-05 14:06:32 -0700 | [diff] [blame] | 4539 | mWindowManager.setDockedStackCreateState( |
Matthew Ng | bf15587 | 2017-10-27 15:24:39 -0700 | [diff] [blame] | 4540 | activityOptions.getSplitScreenCreateMode(), null /* initialBounds */); |
Jorim Jaggi | 3c800a4 | 2016-04-15 19:44:50 -0700 | [diff] [blame] | 4541 | |
Matthew Ng | 606dd80 | 2017-06-05 14:06:32 -0700 | [diff] [blame] | 4542 | // Defer updating the stack in which recents is until the app transition is done, to |
| 4543 | // not run into issues where we still need to draw the task in recents but the |
| 4544 | // docked stack is already created. |
Wale Ogunwale | 6827856 | 2017-09-23 17:13:55 -0700 | [diff] [blame] | 4545 | deferUpdateBounds(ACTIVITY_TYPE_RECENTS); |
Matthew Ng | 606dd80 | 2017-06-05 14:06:32 -0700 | [diff] [blame] | 4546 | mWindowManager.prepareAppTransition(TRANSIT_DOCK_TASK_FROM_RECENTS, false); |
Jorim Jaggi | 0b46f3c | 2016-03-14 12:21:37 +0100 | [diff] [blame] | 4547 | } |
Jorim Jaggi | 0b46f3c | 2016-03-14 12:21:37 +0100 | [diff] [blame] | 4548 | |
Matthew Ng | 606dd80 | 2017-06-05 14:06:32 -0700 | [diff] [blame] | 4549 | task = anyTaskForIdLocked(taskId, MATCH_TASK_IN_STACKS_OR_RECENT_TASKS_AND_RESTORE, |
Wale Ogunwale | ab5de37 | 2017-10-18 06:46:31 -0700 | [diff] [blame] | 4550 | activityOptions, ON_TOP); |
Matthew Ng | 606dd80 | 2017-06-05 14:06:32 -0700 | [diff] [blame] | 4551 | if (task == null) { |
Wale Ogunwale | 6827856 | 2017-09-23 17:13:55 -0700 | [diff] [blame] | 4552 | continueUpdateBounds(ACTIVITY_TYPE_RECENTS); |
Matthew Ng | 606dd80 | 2017-06-05 14:06:32 -0700 | [diff] [blame] | 4553 | mWindowManager.executeAppTransition(); |
| 4554 | throw new IllegalArgumentException( |
Wale Ogunwale | ab5de37 | 2017-10-18 06:46:31 -0700 | [diff] [blame] | 4555 | "startActivityFromRecents: Task " + taskId + " not found."); |
Matthew Ng | 606dd80 | 2017-06-05 14:06:32 -0700 | [diff] [blame] | 4556 | } |
| 4557 | |
Wale Ogunwale | abc44d0 | 2017-11-08 08:58:03 -0800 | [diff] [blame] | 4558 | if (windowingMode != WINDOWING_MODE_SPLIT_SCREEN_PRIMARY) { |
| 4559 | // We always want to return to the home activity instead of the recents activity |
| 4560 | // from whatever is started from the recents activity, so move the home stack |
| 4561 | // forward. |
| 4562 | moveHomeStackToFront("startActivityFromRecents"); |
| 4563 | } |
Wale Ogunwale | 66e1685 | 2017-10-19 13:35:52 -0700 | [diff] [blame] | 4564 | |
Matthew Ng | 606dd80 | 2017-06-05 14:06:32 -0700 | [diff] [blame] | 4565 | // If the user must confirm credentials (e.g. when first launching a work app and the |
| 4566 | // Work Challenge is present) let startActivityInPackage handle the intercepting. |
| 4567 | if (!mService.mUserController.shouldConfirmCredentials(task.userId) |
| 4568 | && task.getRootActivity() != null) { |
Bryce Lee | 28d8042 | 2017-07-21 13:25:13 -0700 | [diff] [blame] | 4569 | final ActivityRecord targetActivity = task.getTopActivity(); |
| 4570 | |
Bryce Lee | d3624e1 | 2017-11-30 08:51:45 -0800 | [diff] [blame] | 4571 | sendPowerHintForLaunchStartIfNeeded(true /* forceSend */, targetActivity); |
Matthew Ng | 606dd80 | 2017-06-05 14:06:32 -0700 | [diff] [blame] | 4572 | mActivityMetricsLogger.notifyActivityLaunching(); |
Jorim Jaggi | 172e99f | 2017-10-20 14:33:18 +0200 | [diff] [blame] | 4573 | try { |
Jorim Jaggi | 4d8d32c | 2018-01-19 15:57:41 +0100 | [diff] [blame] | 4574 | mService.moveTaskToFrontLocked(task.taskId, 0, options, |
Jorim Jaggi | 172e99f | 2017-10-20 14:33:18 +0200 | [diff] [blame] | 4575 | true /* fromRecents */); |
| 4576 | } finally { |
| 4577 | mActivityMetricsLogger.notifyActivityLaunched(START_TASK_TO_FRONT, |
| 4578 | targetActivity); |
| 4579 | } |
Matthew Ng | 606dd80 | 2017-06-05 14:06:32 -0700 | [diff] [blame] | 4580 | |
Bryce Lee | d3624e1 | 2017-11-30 08:51:45 -0800 | [diff] [blame] | 4581 | mService.getActivityStartController().postStartActivityProcessingForLastStarter( |
| 4582 | task.getTopActivity(), ActivityManager.START_TASK_TO_FRONT, |
| 4583 | task.getStack()); |
Matthew Ng | 606dd80 | 2017-06-05 14:06:32 -0700 | [diff] [blame] | 4584 | return ActivityManager.START_TASK_TO_FRONT; |
| 4585 | } |
Matthew Ng | 606dd80 | 2017-06-05 14:06:32 -0700 | [diff] [blame] | 4586 | callingPackage = task.mCallingPackage; |
| 4587 | intent = task.intent; |
| 4588 | intent.addFlags(Intent.FLAG_ACTIVITY_LAUNCHED_FROM_HISTORY); |
| 4589 | userId = task.userId; |
Wale Ogunwale | dd2ae3d | 2018-02-15 13:58:46 -0800 | [diff] [blame] | 4590 | return mService.getActivityStartController().startActivityInPackage( |
Jorim Jaggi | 4d8d32c | 2018-01-19 15:57:41 +0100 | [diff] [blame] | 4591 | task.mCallingUid, callingPid, callingUid, callingPackage, intent, null, null, |
Wale Ogunwale | dd2ae3d | 2018-02-15 13:58:46 -0800 | [diff] [blame] | 4592 | null, 0, 0, options, userId, task, "startActivityFromRecents"); |
Matthew Ng | 606dd80 | 2017-06-05 14:06:32 -0700 | [diff] [blame] | 4593 | } finally { |
Wale Ogunwale | dd2ae3d | 2018-02-15 13:58:46 -0800 | [diff] [blame] | 4594 | if (windowingMode == WINDOWING_MODE_SPLIT_SCREEN_PRIMARY && task != null) { |
| 4595 | // If we are launching the task in the docked stack, put it into resizing mode so |
| 4596 | // the window renders full-screen with the background filling the void. Also only |
| 4597 | // call this at the end to make sure that tasks exists on the window manager side. |
| 4598 | setResizingDuringAnimation(task); |
| 4599 | |
| 4600 | final ActivityDisplay display = task.getStack().getDisplay(); |
| 4601 | final ActivityStack topSecondaryStack = |
| 4602 | display.getTopStackInWindowingMode(WINDOWING_MODE_SPLIT_SCREEN_SECONDARY); |
| 4603 | if (topSecondaryStack.isActivityTypeHome()) { |
| 4604 | // If the home activity if the top split-screen secondary stack, then the |
| 4605 | // primary split-screen stack is in the minimized mode which means it can't |
| 4606 | // receive input keys, so we should move the focused app to the home app so that |
| 4607 | // window manager can correctly calculate the focus window that can receive |
| 4608 | // input keys. |
| 4609 | moveHomeStackToFront("startActivityFromRecents: homeVisibleInSplitScreen"); |
| 4610 | } |
| 4611 | } |
Matthew Ng | 606dd80 | 2017-06-05 14:06:32 -0700 | [diff] [blame] | 4612 | mWindowManager.continueSurfaceLayout(); |
Jorim Jaggi | 0b46f3c | 2016-03-14 12:21:37 +0100 | [diff] [blame] | 4613 | } |
Jorim Jaggi | 0b46f3c | 2016-03-14 12:21:37 +0100 | [diff] [blame] | 4614 | } |
Amith Yamasani | e8222e5 | 2016-04-08 15:28:47 -0700 | [diff] [blame] | 4615 | |
| 4616 | /** |
| 4617 | * @return a list of activities which are the top ones in each visible stack. The first |
| 4618 | * entry will be the focused activity. |
| 4619 | */ |
Andrii Kulian | 0864bbb | 2017-02-16 15:45:58 -0800 | [diff] [blame] | 4620 | List<IBinder> getTopVisibleActivities() { |
| 4621 | final ArrayList<IBinder> topActivityTokens = new ArrayList<>(); |
| 4622 | // Traverse all displays. |
Robert Carr | 22374c0 | 2017-02-21 13:01:47 -0800 | [diff] [blame] | 4623 | for (int i = mActivityDisplays.size() - 1; i >= 0; i--) { |
Andrii Kulian | 0864bbb | 2017-02-16 15:45:58 -0800 | [diff] [blame] | 4624 | final ActivityDisplay display = mActivityDisplays.valueAt(i); |
| 4625 | // Traverse all stacks on a display. |
Wale Ogunwale | a0f5b5e | 2017-10-11 09:37:23 -0700 | [diff] [blame] | 4626 | for (int j = display.getChildCount() - 1; j >= 0; --j) { |
| 4627 | final ActivityStack stack = display.getChildAt(j); |
Andrii Kulian | 0864bbb | 2017-02-16 15:45:58 -0800 | [diff] [blame] | 4628 | // 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] | 4629 | if (stack.shouldBeVisible(null /* starting */)) { |
Wale Ogunwale | 30e441d | 2017-11-09 08:28:45 -0800 | [diff] [blame] | 4630 | final ActivityRecord top = stack.getTopActivity(); |
Andrii Kulian | 0864bbb | 2017-02-16 15:45:58 -0800 | [diff] [blame] | 4631 | if (top != null) { |
| 4632 | if (stack == mFocusedStack) { |
| 4633 | topActivityTokens.add(0, top.appToken); |
| 4634 | } else { |
| 4635 | topActivityTokens.add(top.appToken); |
| 4636 | } |
Amith Yamasani | e8222e5 | 2016-04-08 15:28:47 -0700 | [diff] [blame] | 4637 | } |
| 4638 | } |
| 4639 | } |
| 4640 | } |
| 4641 | return topActivityTokens; |
| 4642 | } |
Bryce Lee | 4a19438 | 2017-04-04 14:32:48 -0700 | [diff] [blame] | 4643 | |
| 4644 | /** |
| 4645 | * Internal container to store a match qualifier alongside a WaitResult. |
| 4646 | */ |
| 4647 | static class WaitInfo { |
| 4648 | private final ComponentName mTargetComponent; |
| 4649 | private final WaitResult mResult; |
| 4650 | |
| 4651 | public WaitInfo(ComponentName targetComponent, WaitResult result) { |
| 4652 | this.mTargetComponent = targetComponent; |
| 4653 | this.mResult = result; |
| 4654 | } |
| 4655 | |
Wale Ogunwale | 3270f17 | 2017-04-26 07:29:42 -0700 | [diff] [blame] | 4656 | public boolean matches(ComponentName targetComponent) { |
| 4657 | return mTargetComponent == null || mTargetComponent.equals(targetComponent); |
Bryce Lee | 4a19438 | 2017-04-04 14:32:48 -0700 | [diff] [blame] | 4658 | } |
| 4659 | |
| 4660 | public WaitResult getResult() { |
| 4661 | return mResult; |
| 4662 | } |
| 4663 | |
| 4664 | public ComponentName getComponent() { |
| 4665 | return mTargetComponent; |
| 4666 | } |
| 4667 | |
| 4668 | public void dump(PrintWriter pw, String prefix) { |
| 4669 | pw.println(prefix + "WaitInfo:"); |
| 4670 | pw.println(prefix + " mTargetComponent=" + mTargetComponent); |
| 4671 | pw.println(prefix + " mResult="); |
| 4672 | mResult.dump(pw, prefix); |
| 4673 | } |
| 4674 | } |
David Stevens | 9440dc8 | 2017-03-16 19:00:20 -0700 | [diff] [blame] | 4675 | |
| 4676 | private final class SleepTokenImpl extends SleepToken { |
| 4677 | private final String mTag; |
| 4678 | private final long mAcquireTime; |
| 4679 | private final int mDisplayId; |
| 4680 | |
| 4681 | public SleepTokenImpl(String tag, int displayId) { |
| 4682 | mTag = tag; |
| 4683 | mDisplayId = displayId; |
| 4684 | mAcquireTime = SystemClock.uptimeMillis(); |
| 4685 | } |
| 4686 | |
| 4687 | @Override |
| 4688 | public void release() { |
| 4689 | synchronized (mService) { |
| 4690 | removeSleepTokenLocked(this); |
| 4691 | } |
| 4692 | } |
| 4693 | |
| 4694 | @Override |
| 4695 | public String toString() { |
| 4696 | return "{\"" + mTag + "\", display " + mDisplayId |
| 4697 | + ", acquire at " + TimeUtils.formatUptime(mAcquireTime) + "}"; |
| 4698 | } |
| 4699 | } |
| 4700 | |
Craig Mautner | 2708430 | 2013-03-25 08:05:25 -0700 | [diff] [blame] | 4701 | } |