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; |
Adrian Roos | a6d6aab | 2018-04-19 18:58:22 +0200 | [diff] [blame] | 46 | import static android.graphics.Rect.copyOrNull; |
chaviw | 59b9885 | 2017-06-13 12:05:44 -0700 | [diff] [blame] | 47 | import static android.os.PowerManager.PARTIAL_WAKE_LOCK; |
Benjamin Franz | a83859f | 2017-07-03 16:34:14 +0100 | [diff] [blame] | 48 | import static android.os.Process.SYSTEM_UID; |
Jorim Jaggi | fe76234 | 2016-10-13 14:33:27 +0200 | [diff] [blame] | 49 | import static android.os.Trace.TRACE_TAG_ACTIVITY_MANAGER; |
| 50 | import static android.view.Display.DEFAULT_DISPLAY; |
Andrii Kulian | 16802aa | 2016-11-02 12:21:33 -0700 | [diff] [blame] | 51 | import static android.view.Display.INVALID_DISPLAY; |
Andrii Kulian | 1cba31c | 2017-06-28 09:42:48 -0700 | [diff] [blame] | 52 | import static android.view.Display.TYPE_VIRTUAL; |
Winson Chung | 1dbc811 | 2017-09-28 18:05:31 -0700 | [diff] [blame] | 53 | |
Winson Chung | 4790065 | 2017-04-06 18:44:25 -0700 | [diff] [blame] | 54 | 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] | 55 | import static com.android.server.am.ActivityManagerDebugConfig.DEBUG_ALL; |
Jorim Jaggi | fe76234 | 2016-10-13 14:33:27 +0200 | [diff] [blame] | 56 | import static com.android.server.am.ActivityManagerDebugConfig.DEBUG_FOCUS; |
| 57 | import static com.android.server.am.ActivityManagerDebugConfig.DEBUG_IDLE; |
Jorim Jaggi | fe76234 | 2016-10-13 14:33:27 +0200 | [diff] [blame] | 58 | import static com.android.server.am.ActivityManagerDebugConfig.DEBUG_PAUSE; |
| 59 | import static com.android.server.am.ActivityManagerDebugConfig.DEBUG_RECENTS; |
| 60 | import static com.android.server.am.ActivityManagerDebugConfig.DEBUG_RELEASE; |
| 61 | import static com.android.server.am.ActivityManagerDebugConfig.DEBUG_STACK; |
| 62 | import static com.android.server.am.ActivityManagerDebugConfig.DEBUG_STATES; |
| 63 | import static com.android.server.am.ActivityManagerDebugConfig.DEBUG_SWITCH; |
| 64 | import static com.android.server.am.ActivityManagerDebugConfig.DEBUG_TASKS; |
Jorim Jaggi | fe76234 | 2016-10-13 14:33:27 +0200 | [diff] [blame] | 65 | import static com.android.server.am.ActivityManagerDebugConfig.POSTFIX_FOCUS; |
| 66 | import static com.android.server.am.ActivityManagerDebugConfig.POSTFIX_IDLE; |
Jorim Jaggi | fe76234 | 2016-10-13 14:33:27 +0200 | [diff] [blame] | 67 | import static com.android.server.am.ActivityManagerDebugConfig.POSTFIX_PAUSE; |
| 68 | import static com.android.server.am.ActivityManagerDebugConfig.POSTFIX_RECENTS; |
| 69 | import static com.android.server.am.ActivityManagerDebugConfig.POSTFIX_RELEASE; |
| 70 | import static com.android.server.am.ActivityManagerDebugConfig.POSTFIX_STACK; |
| 71 | import static com.android.server.am.ActivityManagerDebugConfig.POSTFIX_STATES; |
| 72 | import static com.android.server.am.ActivityManagerDebugConfig.POSTFIX_SWITCH; |
| 73 | import static com.android.server.am.ActivityManagerDebugConfig.POSTFIX_TASKS; |
Jorim Jaggi | fe76234 | 2016-10-13 14:33:27 +0200 | [diff] [blame] | 74 | import static com.android.server.am.ActivityManagerDebugConfig.TAG_AM; |
| 75 | import static com.android.server.am.ActivityManagerDebugConfig.TAG_WITH_CLASS_NAME; |
| 76 | import static com.android.server.am.ActivityManagerService.ANIMATE; |
| 77 | import static com.android.server.am.ActivityManagerService.FIRST_SUPERVISOR_STACK_MSG; |
Jorim Jaggi | fe76234 | 2016-10-13 14:33:27 +0200 | [diff] [blame] | 78 | import static com.android.server.am.ActivityStack.ActivityState.DESTROYED; |
| 79 | import static com.android.server.am.ActivityStack.ActivityState.DESTROYING; |
| 80 | import static com.android.server.am.ActivityStack.ActivityState.INITIALIZING; |
| 81 | import static com.android.server.am.ActivityStack.ActivityState.PAUSED; |
| 82 | import static com.android.server.am.ActivityStack.ActivityState.PAUSING; |
| 83 | import static com.android.server.am.ActivityStack.ActivityState.RESUMED; |
| 84 | import static com.android.server.am.ActivityStack.ActivityState.STOPPED; |
| 85 | import static com.android.server.am.ActivityStack.ActivityState.STOPPING; |
| 86 | import static com.android.server.am.ActivityStack.REMOVE_TASK_MODE_MOVING; |
Wale Ogunwale | 0568aed | 2017-09-08 13:29:37 -0700 | [diff] [blame] | 87 | import static com.android.server.am.TaskRecord.INVALID_TASK_ID; |
Jorim Jaggi | fe76234 | 2016-10-13 14:33:27 +0200 | [diff] [blame] | 88 | import static com.android.server.am.TaskRecord.LOCK_TASK_AUTH_LAUNCHABLE; |
| 89 | import static com.android.server.am.TaskRecord.LOCK_TASK_AUTH_LAUNCHABLE_PRIV; |
Charles He | ff9b4dff | 2017-09-22 10:18:37 +0100 | [diff] [blame] | 90 | import static com.android.server.am.TaskRecord.LOCK_TASK_AUTH_WHITELISTED; |
Winson Chung | 7466610 | 2017-02-22 17:49:24 -0800 | [diff] [blame] | 91 | import static com.android.server.am.TaskRecord.REPARENT_KEEP_STACK_AT_FRONT; |
| 92 | import static com.android.server.am.TaskRecord.REPARENT_LEAVE_STACK_IN_PLACE; |
| 93 | import static com.android.server.am.TaskRecord.REPARENT_MOVE_STACK_TO_FRONT; |
Yi Jin | 6c6e9ca | 2018-03-20 16:53:35 -0700 | [diff] [blame] | 94 | import static com.android.server.am.ActivityStackSupervisorProto.CONFIGURATION_CONTAINER; |
| 95 | import static com.android.server.am.ActivityStackSupervisorProto.DISPLAYS; |
| 96 | import static com.android.server.am.ActivityStackSupervisorProto.FOCUSED_STACK_ID; |
| 97 | import static com.android.server.am.ActivityStackSupervisorProto.IS_HOME_RECENTS_COMPONENT; |
| 98 | import static com.android.server.am.ActivityStackSupervisorProto.KEYGUARD_CONTROLLER; |
| 99 | import static com.android.server.am.ActivityStackSupervisorProto.RESUMED_ACTIVITY; |
Jorim Jaggi | f84e2f6 | 2018-01-16 14:17:59 +0100 | [diff] [blame] | 100 | import static android.view.WindowManager.TRANSIT_DOCK_TASK_FROM_RECENTS; |
Winson Chung | 1dbc811 | 2017-09-28 18:05:31 -0700 | [diff] [blame] | 101 | |
Wale Ogunwale | e1fe7fa2 | 2016-12-15 18:27:00 -0800 | [diff] [blame] | 102 | import static java.lang.Integer.MAX_VALUE; |
Jorim Jaggi | fe76234 | 2016-10-13 14:33:27 +0200 | [diff] [blame] | 103 | |
Svetoslav | 7008b51 | 2015-06-24 18:47:07 -0700 | [diff] [blame] | 104 | import android.Manifest; |
Winson Chung | 7900bee | 2017-03-10 08:59:25 -0800 | [diff] [blame] | 105 | import android.annotation.IntDef; |
Andrii Kulian | 16802aa | 2016-11-02 12:21:33 -0700 | [diff] [blame] | 106 | import android.annotation.NonNull; |
Wale Ogunwale | 0568aed | 2017-09-08 13:29:37 -0700 | [diff] [blame] | 107 | import android.annotation.Nullable; |
Tony Mak | 853304c | 2016-04-18 15:17:41 +0100 | [diff] [blame] | 108 | import android.annotation.UserIdInt; |
Craig Mautner | 2420ead | 2013-04-01 17:13:20 -0700 | [diff] [blame] | 109 | import android.app.Activity; |
Craig Mautner | 23ac33b | 2013-04-01 16:26:35 -0700 | [diff] [blame] | 110 | import android.app.ActivityManager; |
Filip Gruszczynski | 80e29f1 | 2015-12-14 14:58:30 -0800 | [diff] [blame] | 111 | import android.app.ActivityManager.RunningTaskInfo; |
Craig Mautner | ed6649f | 2013-12-02 14:08:25 -0800 | [diff] [blame] | 112 | import android.app.ActivityManager.StackInfo; |
David Stevens | 9440dc8 | 2017-03-16 19:00:20 -0700 | [diff] [blame] | 113 | import android.app.ActivityManagerInternal.SleepToken; |
Craig Mautner | 23ac33b | 2013-04-01 16:26:35 -0700 | [diff] [blame] | 114 | import android.app.ActivityOptions; |
Svetoslav | 7008b51 | 2015-06-24 18:47:07 -0700 | [diff] [blame] | 115 | import android.app.AppOpsManager; |
Jeff Hao | 1b012d3 | 2014-08-20 10:35:34 -0700 | [diff] [blame] | 116 | import android.app.ProfilerInfo; |
Craig Mautner | 2420ead | 2013-04-01 17:13:20 -0700 | [diff] [blame] | 117 | import android.app.ResultInfo; |
Sudheer Shanka | fc46e9b | 2016-10-21 17:55:27 -0700 | [diff] [blame] | 118 | import android.app.WaitResult; |
Winson Chung | 61c9e5a | 2017-10-11 10:39:32 -0700 | [diff] [blame] | 119 | import android.app.WindowConfiguration.ActivityType; |
| 120 | import android.app.WindowConfiguration.WindowingMode; |
Andrii Kulian | 88e05cb | 2017-12-05 17:21:10 -0800 | [diff] [blame] | 121 | import android.app.servertransaction.ActivityLifecycleItem; |
| 122 | import android.app.servertransaction.ClientTransaction; |
Andrii Kulian | 446e824 | 2017-10-26 15:17:29 -0700 | [diff] [blame] | 123 | import android.app.servertransaction.LaunchActivityItem; |
Andrii Kulian | 88e05cb | 2017-12-05 17:21:10 -0800 | [diff] [blame] | 124 | import android.app.servertransaction.PauseActivityItem; |
| 125 | import android.app.servertransaction.ResumeActivityItem; |
Craig Mautner | 23ac33b | 2013-04-01 16:26:35 -0700 | [diff] [blame] | 126 | import android.content.ComponentName; |
Craig Mautner | 2219a1b | 2013-03-25 09:44:30 -0700 | [diff] [blame] | 127 | import android.content.Context; |
| 128 | import android.content.Intent; |
| 129 | import android.content.pm.ActivityInfo; |
Craig Mautner | 23ac33b | 2013-04-01 16:26:35 -0700 | [diff] [blame] | 130 | import android.content.pm.ApplicationInfo; |
Svetoslav | 7008b51 | 2015-06-24 18:47:07 -0700 | [diff] [blame] | 131 | import android.content.pm.PackageInfo; |
Craig Mautner | 23ac33b | 2013-04-01 16:26:35 -0700 | [diff] [blame] | 132 | import android.content.pm.PackageManager; |
| 133 | import android.content.pm.ResolveInfo; |
Clara Bayarri | f7fea16 | 2015-10-22 16:09:52 +0100 | [diff] [blame] | 134 | import android.content.pm.UserInfo; |
Craig Mautner | 23ac33b | 2013-04-01 16:26:35 -0700 | [diff] [blame] | 135 | import android.content.res.Configuration; |
Wale Ogunwale | 60454db | 2015-01-23 16:05:07 -0800 | [diff] [blame] | 136 | import android.graphics.Rect; |
Craig Mautner | 4a1cb22 | 2013-12-04 16:14:06 -0800 | [diff] [blame] | 137 | import android.hardware.display.DisplayManager; |
| 138 | import android.hardware.display.DisplayManager.DisplayListener; |
Andrii Kulian | fb1bf69 | 2017-01-17 11:17:34 -0800 | [diff] [blame] | 139 | import android.hardware.display.DisplayManagerInternal; |
Bryce Lee | d3624e1 | 2017-11-30 08:51:45 -0800 | [diff] [blame] | 140 | import android.hardware.power.V1_0.PowerHint; |
Craig Mautner | 23ac33b | 2013-04-01 16:26:35 -0700 | [diff] [blame] | 141 | import android.os.Binder; |
Jorim Jaggi | 0b46f3c | 2016-03-14 12:21:37 +0100 | [diff] [blame] | 142 | import android.os.Bundle; |
Craig Mautner | b59dcfd | 2013-05-06 13:12:58 -0700 | [diff] [blame] | 143 | import android.os.Debug; |
Craig Mautner | ce5f3cb | 2013-04-22 08:58:54 -0700 | [diff] [blame] | 144 | import android.os.Handler; |
Craig Mautner | 23ac33b | 2013-04-01 16:26:35 -0700 | [diff] [blame] | 145 | import android.os.IBinder; |
Craig Mautner | 2219a1b | 2013-03-25 09:44:30 -0700 | [diff] [blame] | 146 | import android.os.Looper; |
Craig Mautner | 2420ead | 2013-04-01 17:13:20 -0700 | [diff] [blame] | 147 | import android.os.Message; |
Craig Mautner | 0eea92c | 2013-05-16 13:35:39 -0700 | [diff] [blame] | 148 | import android.os.PowerManager; |
Craig Mautner | 7ea5bd4 | 2013-07-05 15:27:08 -0700 | [diff] [blame] | 149 | import android.os.Process; |
Craig Mautner | 8d341ef | 2013-03-26 09:03:27 -0700 | [diff] [blame] | 150 | import android.os.RemoteException; |
Craig Mautner | 23ac33b | 2013-04-01 16:26:35 -0700 | [diff] [blame] | 151 | import android.os.SystemClock; |
Wale Ogunwale | cad05a0 | 2015-09-25 10:41:44 -0700 | [diff] [blame] | 152 | import android.os.Trace; |
Craig Mautner | 6170f73 | 2013-04-02 13:05:23 -0700 | [diff] [blame] | 153 | import android.os.UserHandle; |
Clara Bayarri | f7fea16 | 2015-10-22 16:09:52 +0100 | [diff] [blame] | 154 | import android.os.UserManager; |
Dianne Hackborn | 3d07c94 | 2015-03-13 18:02:54 -0700 | [diff] [blame] | 155 | import android.os.WorkSource; |
Svetoslav | 7008b51 | 2015-06-24 18:47:07 -0700 | [diff] [blame] | 156 | import android.provider.MediaStore; |
Dianne Hackborn | 91097de | 2014-04-04 18:02:06 -0700 | [diff] [blame] | 157 | import android.service.voice.IVoiceInteractionSession; |
Svetoslav | 7008b51 | 2015-06-24 18:47:07 -0700 | [diff] [blame] | 158 | import android.util.ArrayMap; |
Dianne Hackborn | 89ad456 | 2014-08-24 16:45:38 -0700 | [diff] [blame] | 159 | import android.util.ArraySet; |
Craig Mautner | 2420ead | 2013-04-01 17:13:20 -0700 | [diff] [blame] | 160 | import android.util.EventLog; |
Andrii Kulian | fb1bf69 | 2017-01-17 11:17:34 -0800 | [diff] [blame] | 161 | import android.util.IntArray; |
Wale Ogunwale | e610d3d | 2017-04-25 10:23:48 -0700 | [diff] [blame] | 162 | import android.util.MergedConfiguration; |
Craig Mautner | 8d341ef | 2013-03-26 09:03:27 -0700 | [diff] [blame] | 163 | import android.util.Slog; |
Craig Mautner | 4a1cb22 | 2013-12-04 16:14:06 -0800 | [diff] [blame] | 164 | import android.util.SparseArray; |
Craig Mautner | 4a1cb22 | 2013-12-04 16:14:06 -0800 | [diff] [blame] | 165 | import android.util.SparseIntArray; |
David Stevens | 9440dc8 | 2017-03-16 19:00:20 -0700 | [diff] [blame] | 166 | import android.util.TimeUtils; |
Steven Timotius | 4346f0a | 2017-09-12 11:07:21 -0700 | [diff] [blame] | 167 | import android.util.proto.ProtoOutputStream; |
Craig Mautner | ed6649f | 2013-12-02 14:08:25 -0800 | [diff] [blame] | 168 | import android.view.Display; |
Chong Zhang | b15758a | 2015-11-17 12:12:03 -0800 | [diff] [blame] | 169 | |
Andreas Gampe | a36dc62 | 2018-02-05 17:19:22 -0800 | [diff] [blame] | 170 | import com.android.internal.annotations.GuardedBy; |
Andrii Kulian | 94e82d9b0 | 2017-07-13 15:33:06 -0700 | [diff] [blame] | 171 | import com.android.internal.annotations.VisibleForTesting; |
Dianne Hackborn | 85d558c | 2014-11-04 10:31:54 -0800 | [diff] [blame] | 172 | import com.android.internal.content.ReferrerIntent; |
Chenjie Yu | 52cacc6 | 2017-12-08 18:11:45 -0800 | [diff] [blame] | 173 | import com.android.internal.os.logging.MetricsLoggerWrapper; |
Dianne Hackborn | cbfd23e | 2013-06-11 14:26:53 -0700 | [diff] [blame] | 174 | import com.android.internal.os.TransferPipe; |
Svetoslav | 7008b51 | 2015-06-24 18:47:07 -0700 | [diff] [blame] | 175 | import com.android.internal.util.ArrayUtils; |
Jeff Brown | ca9bc70 | 2014-02-11 14:32:56 -0800 | [diff] [blame] | 176 | import com.android.server.LocalServices; |
Craig Mautner | 2420ead | 2013-04-01 17:13:20 -0700 | [diff] [blame] | 177 | import com.android.server.am.ActivityStack.ActivityState; |
Wale Ogunwale | 98d6231 | 2017-07-12 09:24:56 -0700 | [diff] [blame] | 178 | import com.android.server.wm.ConfigurationContainer; |
Winson Chung | 19953ca | 2017-04-11 11:19:23 -0700 | [diff] [blame] | 179 | import com.android.server.wm.PinnedStackWindowController; |
Craig Mautner | ce5f3cb | 2013-04-22 08:58:54 -0700 | [diff] [blame] | 180 | import com.android.server.wm.WindowManagerService; |
Craig Mautner | 23ac33b | 2013-04-01 16:26:35 -0700 | [diff] [blame] | 181 | |
Craig Mautner | 8d341ef | 2013-03-26 09:03:27 -0700 | [diff] [blame] | 182 | import java.io.FileDescriptor; |
| 183 | import java.io.IOException; |
Craig Mautner | 2708430 | 2013-03-25 08:05:25 -0700 | [diff] [blame] | 184 | import java.io.PrintWriter; |
Winson Chung | 7900bee | 2017-03-10 08:59:25 -0800 | [diff] [blame] | 185 | import java.lang.annotation.Retention; |
| 186 | import java.lang.annotation.RetentionPolicy; |
Craig Mautner | 2219a1b | 2013-03-25 09:44:30 -0700 | [diff] [blame] | 187 | import java.util.ArrayList; |
David Stevens | 9440dc8 | 2017-03-16 19:00:20 -0700 | [diff] [blame] | 188 | import java.util.Iterator; |
Craig Mautner | 8d341ef | 2013-03-26 09:03:27 -0700 | [diff] [blame] | 189 | import java.util.List; |
Wale Ogunwale | 540e123 | 2015-05-01 15:35:39 -0700 | [diff] [blame] | 190 | import java.util.Set; |
Craig Mautner | 2708430 | 2013-03-25 08:05:25 -0700 | [diff] [blame] | 191 | |
Winson Chung | 1dbc811 | 2017-09-28 18:05:31 -0700 | [diff] [blame] | 192 | public class ActivityStackSupervisor extends ConfigurationContainer implements DisplayListener, |
| 193 | RecentTasks.Callbacks { |
Wale Ogunwale | e23149f | 2015-03-06 15:39:44 -0800 | [diff] [blame] | 194 | private static final String TAG = TAG_WITH_CLASS_NAME ? "ActivityStackSupervisor" : TAG_AM; |
Chong Zhang | 6cda19c | 2016-06-14 19:07:56 -0700 | [diff] [blame] | 195 | private static final String TAG_FOCUS = TAG + POSTFIX_FOCUS; |
Wale Ogunwale | 0fc365c | 2015-05-25 19:35:42 -0700 | [diff] [blame] | 196 | private static final String TAG_IDLE = TAG + POSTFIX_IDLE; |
Wale Ogunwale | ee006da | 2015-03-30 14:49:25 -0700 | [diff] [blame] | 197 | private static final String TAG_PAUSE = TAG + POSTFIX_PAUSE; |
Wale Ogunwale | ee006da | 2015-03-30 14:49:25 -0700 | [diff] [blame] | 198 | private static final String TAG_RECENTS = TAG + POSTFIX_RECENTS; |
Wale Ogunwale | 0fc365c | 2015-05-25 19:35:42 -0700 | [diff] [blame] | 199 | private static final String TAG_RELEASE = TAG + POSTFIX_RELEASE; |
Wale Ogunwale | ee006da | 2015-03-30 14:49:25 -0700 | [diff] [blame] | 200 | private static final String TAG_STACK = TAG + POSTFIX_STACK; |
Wale Ogunwale | 0fc365c | 2015-05-25 19:35:42 -0700 | [diff] [blame] | 201 | private static final String TAG_STATES = TAG + POSTFIX_STATES; |
Wale Ogunwale | ee006da | 2015-03-30 14:49:25 -0700 | [diff] [blame] | 202 | private static final String TAG_SWITCH = TAG + POSTFIX_SWITCH; |
Filip Gruszczynski | 07a0e49 | 2015-12-17 14:16:38 -0800 | [diff] [blame] | 203 | static final String TAG_TASKS = TAG + POSTFIX_TASKS; |
Wale Ogunwale | e23149f | 2015-03-06 15:39:44 -0800 | [diff] [blame] | 204 | |
Craig Mautner | f333327 | 2013-04-22 10:55:53 -0700 | [diff] [blame] | 205 | /** 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] | 206 | static final int IDLE_TIMEOUT = 10 * 1000; |
Craig Mautner | f333327 | 2013-04-22 10:55:53 -0700 | [diff] [blame] | 207 | |
Craig Mautner | 0eea92c | 2013-05-16 13:35:39 -0700 | [diff] [blame] | 208 | /** How long we can hold the sleep wake lock before giving up. */ |
Wale Ogunwale | 0fc365c | 2015-05-25 19:35:42 -0700 | [diff] [blame] | 209 | static final int SLEEP_TIMEOUT = 5 * 1000; |
Craig Mautner | 0eea92c | 2013-05-16 13:35:39 -0700 | [diff] [blame] | 210 | |
Craig Mautner | 7ea5bd4 | 2013-07-05 15:27:08 -0700 | [diff] [blame] | 211 | // How long we can hold the launch wake lock before giving up. |
Wale Ogunwale | 0fc365c | 2015-05-25 19:35:42 -0700 | [diff] [blame] | 212 | static final int LAUNCH_TIMEOUT = 10 * 1000; |
Craig Mautner | 7ea5bd4 | 2013-07-05 15:27:08 -0700 | [diff] [blame] | 213 | |
Craig Mautner | 05d2903 | 2013-05-03 13:40:13 -0700 | [diff] [blame] | 214 | static final int IDLE_TIMEOUT_MSG = FIRST_SUPERVISOR_STACK_MSG; |
| 215 | static final int IDLE_NOW_MSG = FIRST_SUPERVISOR_STACK_MSG + 1; |
| 216 | static final int RESUME_TOP_ACTIVITY_MSG = FIRST_SUPERVISOR_STACK_MSG + 2; |
Craig Mautner | 0eea92c | 2013-05-16 13:35:39 -0700 | [diff] [blame] | 217 | static final int SLEEP_TIMEOUT_MSG = FIRST_SUPERVISOR_STACK_MSG + 3; |
Craig Mautner | 7ea5bd4 | 2013-07-05 15:27:08 -0700 | [diff] [blame] | 218 | static final int LAUNCH_TIMEOUT_MSG = FIRST_SUPERVISOR_STACK_MSG + 4; |
Craig Mautner | 4a1cb22 | 2013-12-04 16:14:06 -0800 | [diff] [blame] | 219 | static final int HANDLE_DISPLAY_ADDED = FIRST_SUPERVISOR_STACK_MSG + 5; |
| 220 | static final int HANDLE_DISPLAY_CHANGED = FIRST_SUPERVISOR_STACK_MSG + 6; |
| 221 | static final int HANDLE_DISPLAY_REMOVED = FIRST_SUPERVISOR_STACK_MSG + 7; |
Wale Ogunwale | 73eba74 | 2015-04-07 14:23:14 -0700 | [diff] [blame] | 222 | static final int LAUNCH_TASK_BEHIND_COMPLETE = FIRST_SUPERVISOR_STACK_MSG + 12; |
Wale Ogunwale | 22e2526 | 2016-02-01 10:32:02 -0800 | [diff] [blame] | 223 | static final int REPORT_MULTI_WINDOW_MODE_CHANGED_MSG = FIRST_SUPERVISOR_STACK_MSG + 14; |
| 224 | 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] | 225 | |
Wale Ogunwale | 040b470 | 2015-08-06 18:10:50 -0700 | [diff] [blame] | 226 | private static final String VIRTUAL_DISPLAY_BASE_NAME = "ActivityViewVirtualDisplay"; |
Craig Mautner | 7ea5bd4 | 2013-07-05 15:27:08 -0700 | [diff] [blame] | 227 | |
Wale Ogunwale | 040b470 | 2015-08-06 18:10:50 -0700 | [diff] [blame] | 228 | // Used to indicate if an object (e.g. stack) that we are trying to get |
| 229 | // should be created if it doesn't exist already. |
Filip Gruszczynski | 07a0e49 | 2015-12-17 14:16:38 -0800 | [diff] [blame] | 230 | static final boolean CREATE_IF_NEEDED = true; |
Wale Ogunwale | 040b470 | 2015-08-06 18:10:50 -0700 | [diff] [blame] | 231 | |
Filip Gruszczynski | bc5a6c5 | 2015-09-22 13:13:24 -0700 | [diff] [blame] | 232 | // Used to indicate that windows of activities should be preserved during the resize. |
| 233 | static final boolean PRESERVE_WINDOWS = true; |
| 234 | |
Wale Ogunwale | 040b470 | 2015-08-06 18:10:50 -0700 | [diff] [blame] | 235 | // Used to indicate if an object (e.g. task) should be moved/created |
| 236 | // at the top of its container (e.g. stack). |
Wale Ogunwale | b30daaa | 2015-08-07 21:50:49 -0700 | [diff] [blame] | 237 | static final boolean ON_TOP = true; |
Wale Ogunwale | 040b470 | 2015-08-06 18:10:50 -0700 | [diff] [blame] | 238 | |
Wale Ogunwale | c8da41e | 2016-04-16 13:27:23 -0700 | [diff] [blame] | 239 | // Don't execute any calls to resume. |
| 240 | static final boolean DEFER_RESUME = true; |
| 241 | |
Winson Chung | 010927a | 2016-12-15 16:12:35 -0800 | [diff] [blame] | 242 | // Used to indicate that a task is removed it should also be removed from recents. |
| 243 | static final boolean REMOVE_FROM_RECENTS = true; |
| 244 | |
Winson Chung | 6954fc9 | 2017-03-24 16:22:12 -0700 | [diff] [blame] | 245 | // Used to indicate that pausing an activity should occur immediately without waiting for |
| 246 | // the activity callback indicating that it has completed pausing |
| 247 | static final boolean PAUSE_IMMEDIATELY = true; |
| 248 | |
Adrian Roos | a6d6aab | 2018-04-19 18:58:22 +0200 | [diff] [blame] | 249 | /** True if the docked stack is currently being resized. */ |
| 250 | private boolean mDockedStackResizing; |
| 251 | |
| 252 | /** |
| 253 | * True if there are pending docked bounds that need to be applied after |
| 254 | * {@link #mDockedStackResizing} is reset to false. |
| 255 | */ |
| 256 | private boolean mHasPendingDockedBounds; |
| 257 | private Rect mPendingDockedBounds; |
| 258 | private Rect mPendingTempDockedTaskBounds; |
| 259 | private Rect mPendingTempDockedTaskInsetBounds; |
| 260 | private Rect mPendingTempOtherTaskBounds; |
| 261 | private Rect mPendingTempOtherTaskInsetBounds; |
| 262 | |
Winson Chung | 7900bee | 2017-03-10 08:59:25 -0800 | [diff] [blame] | 263 | /** |
| 264 | * The modes which affect which tasks are returned when calling |
| 265 | * {@link ActivityStackSupervisor#anyTaskForIdLocked(int)}. |
| 266 | */ |
| 267 | @Retention(RetentionPolicy.SOURCE) |
| 268 | @IntDef({ |
| 269 | MATCH_TASK_IN_STACKS_ONLY, |
| 270 | MATCH_TASK_IN_STACKS_OR_RECENT_TASKS, |
| 271 | MATCH_TASK_IN_STACKS_OR_RECENT_TASKS_AND_RESTORE |
| 272 | }) |
| 273 | public @interface AnyTaskForIdMatchTaskMode {} |
| 274 | // Match only tasks in the current stacks |
| 275 | static final int MATCH_TASK_IN_STACKS_ONLY = 0; |
| 276 | // Match either tasks in the current stacks, or in the recent tasks if not found in the stacks |
| 277 | static final int MATCH_TASK_IN_STACKS_OR_RECENT_TASKS = 1; |
| 278 | // Match either tasks in the current stacks, or in the recent tasks, restoring it to the |
| 279 | // provided stack id |
| 280 | static final int MATCH_TASK_IN_STACKS_OR_RECENT_TASKS_AND_RESTORE = 2; |
| 281 | |
Svetoslav | 7008b51 | 2015-06-24 18:47:07 -0700 | [diff] [blame] | 282 | // Activity actions an app cannot start if it uses a permission which is not granted. |
| 283 | private static final ArrayMap<String, String> ACTION_TO_RUNTIME_PERMISSION = |
| 284 | new ArrayMap<>(); |
Filip Gruszczynski | bc5a6c5 | 2015-09-22 13:13:24 -0700 | [diff] [blame] | 285 | |
Svetoslav | 7008b51 | 2015-06-24 18:47:07 -0700 | [diff] [blame] | 286 | static { |
| 287 | ACTION_TO_RUNTIME_PERMISSION.put(MediaStore.ACTION_IMAGE_CAPTURE, |
| 288 | Manifest.permission.CAMERA); |
| 289 | ACTION_TO_RUNTIME_PERMISSION.put(MediaStore.ACTION_VIDEO_CAPTURE, |
| 290 | Manifest.permission.CAMERA); |
| 291 | ACTION_TO_RUNTIME_PERMISSION.put(Intent.ACTION_CALL, |
| 292 | Manifest.permission.CALL_PHONE); |
| 293 | } |
| 294 | |
Svet Ganov | 99b6043 | 2015-06-27 13:15:22 -0700 | [diff] [blame] | 295 | /** Action restriction: launching the activity is not restricted. */ |
| 296 | private static final int ACTIVITY_RESTRICTION_NONE = 0; |
| 297 | /** Action restriction: launching the activity is restricted by a permission. */ |
| 298 | private static final int ACTIVITY_RESTRICTION_PERMISSION = 1; |
| 299 | /** Action restriction: launching the activity is restricted by an app op. */ |
| 300 | private static final int ACTIVITY_RESTRICTION_APPOP = 2; |
Svetoslav | 7008b51 | 2015-06-24 18:47:07 -0700 | [diff] [blame] | 301 | |
Craig Mautner | 7ea5bd4 | 2013-07-05 15:27:08 -0700 | [diff] [blame] | 302 | // For debugging to make sure the caller when acquiring/releasing our |
| 303 | // wake lock is the system process. |
| 304 | static final boolean VALIDATE_WAKE_LOCK_CALLER = false; |
Suprabh Shukla | 09a88f5 | 2015-12-02 14:36:31 -0800 | [diff] [blame] | 305 | /** The number of distinct task ids that can be assigned to the tasks of a single user */ |
| 306 | 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] | 307 | |
Craig Mautner | 2708430 | 2013-03-25 08:05:25 -0700 | [diff] [blame] | 308 | final ActivityManagerService mService; |
| 309 | |
Winson Chung | 61c9e5a | 2017-10-11 10:39:32 -0700 | [diff] [blame] | 310 | /** The historial list of recent tasks including inactive tasks */ |
Winson Chung | 1dbc811 | 2017-09-28 18:05:31 -0700 | [diff] [blame] | 311 | RecentTasks mRecentTasks; |
Wale Ogunwale | c82f2f5 | 2014-12-09 09:32:50 -0800 | [diff] [blame] | 312 | |
Winson Chung | 61c9e5a | 2017-10-11 10:39:32 -0700 | [diff] [blame] | 313 | /** 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] | 314 | private RunningTasks mRunningTasks; |
Winson Chung | 61c9e5a | 2017-10-11 10:39:32 -0700 | [diff] [blame] | 315 | |
Craig Mautner | ce5f3cb | 2013-04-22 08:58:54 -0700 | [diff] [blame] | 316 | final ActivityStackSupervisorHandler mHandler; |
Winson Chung | e2d7217 | 2018-01-25 17:46:20 +0000 | [diff] [blame] | 317 | final Looper mLooper; |
Craig Mautner | ce5f3cb | 2013-04-22 08:58:54 -0700 | [diff] [blame] | 318 | |
| 319 | /** Short cut */ |
| 320 | WindowManagerService mWindowManager; |
Craig Mautner | 4a1cb22 | 2013-12-04 16:14:06 -0800 | [diff] [blame] | 321 | DisplayManager mDisplayManager; |
Craig Mautner | ce5f3cb | 2013-04-22 08:58:54 -0700 | [diff] [blame] | 322 | |
Bryce Lee | ec55eb0 | 2017-12-05 20:51:27 -0800 | [diff] [blame] | 323 | private LaunchParamsController mLaunchParamsController; |
Bryce Lee | 9ad3eb3 | 2017-10-10 10:10:31 -0700 | [diff] [blame] | 324 | |
Suprabh Shukla | 09a88f5 | 2015-12-02 14:36:31 -0800 | [diff] [blame] | 325 | /** |
| 326 | * Maps the task identifier that activities are currently being started in to the userId of the |
| 327 | * task. Each time a new task is created, the entry for the userId of the task is incremented |
| 328 | */ |
| 329 | private final SparseIntArray mCurTaskIdForUser = new SparseIntArray(20); |
Craig Mautner | 8d341ef | 2013-03-26 09:03:27 -0700 | [diff] [blame] | 330 | |
Craig Mautner | 2420ead | 2013-04-01 17:13:20 -0700 | [diff] [blame] | 331 | /** The current user */ |
Filip Gruszczynski | 07a0e49 | 2015-12-17 14:16:38 -0800 | [diff] [blame] | 332 | int mCurrentUser; |
Craig Mautner | 2420ead | 2013-04-01 17:13:20 -0700 | [diff] [blame] | 333 | |
Craig Mautner | e0a3884 | 2013-12-16 16:14:02 -0800 | [diff] [blame] | 334 | /** The stack containing the launcher app. Assumed to always be attached to |
| 335 | * Display.DEFAULT_DISPLAY. */ |
Filip Gruszczynski | 07a0e49 | 2015-12-17 14:16:38 -0800 | [diff] [blame] | 336 | ActivityStack mHomeStack; |
Craig Mautner | 20e7227 | 2013-04-01 13:45:53 -0700 | [diff] [blame] | 337 | |
Craig Mautner | e0a3884 | 2013-12-16 16:14:02 -0800 | [diff] [blame] | 338 | /** The stack currently receiving input or launching the next activity. */ |
Filip Gruszczynski | 07a0e49 | 2015-12-17 14:16:38 -0800 | [diff] [blame] | 339 | ActivityStack mFocusedStack; |
Craig Mautner | 8d341ef | 2013-03-26 09:03:27 -0700 | [diff] [blame] | 340 | |
Craig Mautner | 4a1cb22 | 2013-12-04 16:14:06 -0800 | [diff] [blame] | 341 | /** If this is the same as mFocusedStack then the activity on the top of the focused stack has |
| 342 | * 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] | 343 | * stack becomes resumed after which it will be set to mFocusedStack. */ |
Craig Mautner | 4a1cb22 | 2013-12-04 16:14:06 -0800 | [diff] [blame] | 344 | private ActivityStack mLastFocusedStack; |
Craig Mautner | de4ef02 | 2013-04-07 19:01:33 -0700 | [diff] [blame] | 345 | |
| 346 | /** List of activities that are waiting for a new activity to become visible before completing |
| 347 | * whatever operation they are supposed to do. */ |
Bryce Lee | 4a19438 | 2017-04-04 14:32:48 -0700 | [diff] [blame] | 348 | // TODO: Remove mActivitiesWaitingForVisibleActivity list and just remove activity from |
| 349 | // mStoppingActivities when something else comes up. |
| 350 | final ArrayList<ActivityRecord> mActivitiesWaitingForVisibleActivity = new ArrayList<>(); |
Craig Mautner | de4ef02 | 2013-04-07 19:01:33 -0700 | [diff] [blame] | 351 | |
Bryce Lee | 4a19438 | 2017-04-04 14:32:48 -0700 | [diff] [blame] | 352 | /** List of processes waiting to find out when a specific activity becomes visible. */ |
| 353 | private final ArrayList<WaitInfo> mWaitingForActivityVisible = new ArrayList<>(); |
Craig Mautner | ce5f3cb | 2013-04-22 08:58:54 -0700 | [diff] [blame] | 354 | |
| 355 | /** List of processes waiting to find out about the next launched activity. */ |
Sudheer Shanka | fc46e9b | 2016-10-21 17:55:27 -0700 | [diff] [blame] | 356 | final ArrayList<WaitResult> mWaitingActivityLaunched = new ArrayList<>(); |
Craig Mautner | ce5f3cb | 2013-04-22 08:58:54 -0700 | [diff] [blame] | 357 | |
Craig Mautner | de4ef02 | 2013-04-07 19:01:33 -0700 | [diff] [blame] | 358 | /** List of activities that are ready to be stopped, but waiting for the next activity to |
| 359 | * settle down before doing so. */ |
Craig Mautner | 8c14c15 | 2015-01-15 17:32:07 -0800 | [diff] [blame] | 360 | final ArrayList<ActivityRecord> mStoppingActivities = new ArrayList<>(); |
Craig Mautner | de4ef02 | 2013-04-07 19:01:33 -0700 | [diff] [blame] | 361 | |
Craig Mautner | f333327 | 2013-04-22 10:55:53 -0700 | [diff] [blame] | 362 | /** List of activities that are ready to be finished, but waiting for the previous activity to |
| 363 | * settle down before doing so. It contains ActivityRecord objects. */ |
Craig Mautner | 8c14c15 | 2015-01-15 17:32:07 -0800 | [diff] [blame] | 364 | final ArrayList<ActivityRecord> mFinishingActivities = new ArrayList<>(); |
Craig Mautner | f333327 | 2013-04-22 10:55:53 -0700 | [diff] [blame] | 365 | |
Craig Mautner | 0eea92c | 2013-05-16 13:35:39 -0700 | [diff] [blame] | 366 | /** List of activities that are in the process of going to sleep. */ |
Craig Mautner | 8c14c15 | 2015-01-15 17:32:07 -0800 | [diff] [blame] | 367 | final ArrayList<ActivityRecord> mGoingToSleepActivities = new ArrayList<>(); |
Craig Mautner | 0eea92c | 2013-05-16 13:35:39 -0700 | [diff] [blame] | 368 | |
Wale Ogunwale | 22e2526 | 2016-02-01 10:32:02 -0800 | [diff] [blame] | 369 | /** List of activities whose multi-window mode changed that we need to report to the |
| 370 | * application */ |
| 371 | final ArrayList<ActivityRecord> mMultiWindowModeChangedActivities = new ArrayList<>(); |
| 372 | |
| 373 | /** List of activities whose picture-in-picture mode changed that we need to report to the |
| 374 | * application */ |
| 375 | final ArrayList<ActivityRecord> mPipModeChangedActivities = new ArrayList<>(); |
| 376 | |
Jorim Jaggi | fa9ed96 | 2018-01-25 00:16:49 +0100 | [diff] [blame] | 377 | /** |
| 378 | * Animations that for the current transition have requested not to |
| 379 | * be considered for the transition animation. |
| 380 | */ |
| 381 | final ArrayList<ActivityRecord> mNoAnimActivities = new ArrayList<>(); |
| 382 | |
Winson Chung | 5af42fc | 2017-03-24 17:11:33 -0700 | [diff] [blame] | 383 | /** The target stack bounds for the picture-in-picture mode changed that we need to report to |
| 384 | * the application */ |
| 385 | Rect mPipModeChangedTargetStackBounds; |
| 386 | |
Craig Mautner | f333327 | 2013-04-22 10:55:53 -0700 | [diff] [blame] | 387 | /** Used on user changes */ |
Amith Yamasani | 37a40c2 | 2015-06-17 13:25:42 -0700 | [diff] [blame] | 388 | final ArrayList<UserState> mStartingUsers = new ArrayList<>(); |
Craig Mautner | f333327 | 2013-04-22 10:55:53 -0700 | [diff] [blame] | 389 | |
Craig Mautner | de4ef02 | 2013-04-07 19:01:33 -0700 | [diff] [blame] | 390 | /** Set to indicate whether to issue an onUserLeaving callback when a newly launched activity |
| 391 | * is being brought in front of us. */ |
| 392 | boolean mUserLeaving = false; |
| 393 | |
Bryce Lee | d3624e1 | 2017-11-30 08:51:45 -0800 | [diff] [blame] | 394 | /** Set when a power hint has started, but not ended. */ |
| 395 | private boolean mPowerHintSent; |
| 396 | |
Craig Mautner | 0eea92c | 2013-05-16 13:35:39 -0700 | [diff] [blame] | 397 | /** |
Craig Mautner | 7ea5bd4 | 2013-07-05 15:27:08 -0700 | [diff] [blame] | 398 | * We don't want to allow the device to go to sleep while in the process |
| 399 | * of launching an activity. This is primarily to allow alarm intent |
| 400 | * receivers to launch an activity and get that to run before the device |
| 401 | * goes back to sleep. |
| 402 | */ |
Jeff Brown | 2c43c33 | 2014-06-12 22:38:59 -0700 | [diff] [blame] | 403 | PowerManager.WakeLock mLaunchingActivity; |
Craig Mautner | 7ea5bd4 | 2013-07-05 15:27:08 -0700 | [diff] [blame] | 404 | |
| 405 | /** |
Craig Mautner | 0eea92c | 2013-05-16 13:35:39 -0700 | [diff] [blame] | 406 | * Set when the system is going to sleep, until we have |
| 407 | * successfully paused the current activity and released our wake lock. |
| 408 | * At that point the system is allowed to actually sleep. |
| 409 | */ |
Jeff Brown | 2c43c33 | 2014-06-12 22:38:59 -0700 | [diff] [blame] | 410 | PowerManager.WakeLock mGoingToSleep; |
Craig Mautner | 0eea92c | 2013-05-16 13:35:39 -0700 | [diff] [blame] | 411 | |
David Stevens | 9440dc8 | 2017-03-16 19:00:20 -0700 | [diff] [blame] | 412 | /** |
| 413 | * A list of tokens that cause the top activity to be put to sleep. |
| 414 | * They are used by components that may hide and block interaction with underlying |
| 415 | * activities. |
| 416 | */ |
Wale Ogunwale | 9dcf946 | 2017-09-19 15:13:01 -0700 | [diff] [blame] | 417 | final ArrayList<SleepToken> mSleepTokens = new ArrayList<>(); |
David Stevens | 9440dc8 | 2017-03-16 19:00:20 -0700 | [diff] [blame] | 418 | |
Craig Mautner | 4f1df4f | 2013-10-15 15:44:14 -0700 | [diff] [blame] | 419 | /** Stack id of the front stack when user switched, indexed by userId. */ |
| 420 | SparseIntArray mUserStackInFront = new SparseIntArray(2); |
Craig Mautner | 93529a4 | 2013-10-04 15:03:13 -0700 | [diff] [blame] | 421 | |
Bryce Lee | af3a400 | 2017-03-20 10:37:12 -0700 | [diff] [blame] | 422 | // TODO: There should be an ActivityDisplayController coordinating am/wm interaction. |
Craig Mautner | 4a1cb22 | 2013-12-04 16:14:06 -0800 | [diff] [blame] | 423 | /** Mapping from displayId to display current state */ |
Craig Mautner | 15df08a | 2015-04-01 12:17:18 -0700 | [diff] [blame] | 424 | private final SparseArray<ActivityDisplay> mActivityDisplays = new SparseArray<>(); |
Craig Mautner | 4a1cb22 | 2013-12-04 16:14:06 -0800 | [diff] [blame] | 425 | |
Andrii Kulian | fb1bf69 | 2017-01-17 11:17:34 -0800 | [diff] [blame] | 426 | private final SparseArray<IntArray> mDisplayAccessUIDs = new SparseArray<>(); |
| 427 | |
| 428 | private DisplayManagerInternal mDisplayManagerInternal; |
Jeff Brown | ca9bc70 | 2014-02-11 14:32:56 -0800 | [diff] [blame] | 429 | |
Wale Ogunwale | d046a01 | 2015-12-24 13:05:59 -0800 | [diff] [blame] | 430 | /** Used to keep resumeTopActivityUncheckedLocked() from being entered recursively */ |
Craig Mautner | 42d04db | 2014-11-06 12:13:23 -0800 | [diff] [blame] | 431 | boolean inResumeTopActivity; |
| 432 | |
Andrii Kulian | 1e32e02 | 2016-09-16 15:29:34 -0700 | [diff] [blame] | 433 | /** |
| 434 | * Temporary rect used during docked stack resize calculation so we don't need to create a new |
| 435 | * object each time. |
| 436 | */ |
Wale Ogunwale | b34a7ad | 2015-08-14 11:05:30 -0700 | [diff] [blame] | 437 | private final Rect tempRect = new Rect(); |
Wale Ogunwale | 7e1f5f5 | 2017-10-18 15:19:59 -0700 | [diff] [blame] | 438 | private final ActivityOptions mTmpOptions = ActivityOptions.makeBasic(); |
Filip Gruszczynski | ebcc875 | 2015-08-25 16:51:05 -0700 | [diff] [blame] | 439 | |
Filip Gruszczynski | d2f1d94 | 2015-10-14 15:10:12 -0700 | [diff] [blame] | 440 | // The default minimal size that will be used if the activity doesn't specify its minimal size. |
| 441 | // It will be calculated when the default display gets added. |
Andrii Kulian | f66a83d | 2016-05-17 12:17:44 -0700 | [diff] [blame] | 442 | int mDefaultMinSizeOfResizeableTask = -1; |
Filip Gruszczynski | d2f1d94 | 2015-10-14 15:10:12 -0700 | [diff] [blame] | 443 | |
Chong Zhang | fdcc4d4 | 2015-10-14 16:50:12 -0700 | [diff] [blame] | 444 | // Whether tasks have moved and we need to rank the tasks before next OOM scoring |
| 445 | private boolean mTaskLayersChanged = true; |
| 446 | |
Bryce Lee | 2a3cc46 | 2017-10-27 10:57:35 -0700 | [diff] [blame] | 447 | private ActivityMetricsLogger mActivityMetricsLogger; |
Jorim Jaggi | de8305a | 2018-05-15 12:06:35 -0700 | [diff] [blame] | 448 | private LaunchTimeTracker mLaunchTimeTracker = new LaunchTimeTracker(); |
Filip Gruszczynski | 77d9448 | 2015-12-11 13:59:52 -0800 | [diff] [blame] | 449 | |
Jorim Jaggi | ea039a8 | 2017-08-02 14:37:49 +0200 | [diff] [blame] | 450 | private final ArrayList<ActivityRecord> mTmpActivityList = new ArrayList<>(); |
| 451 | |
Andrii Kulian | 1779e61 | 2016-10-12 21:58:25 -0700 | [diff] [blame] | 452 | @Override |
| 453 | protected int getChildCount() { |
| 454 | return mActivityDisplays.size(); |
| 455 | } |
| 456 | |
| 457 | @Override |
Andrii Kulian | 5406e7a | 2016-10-21 11:55:23 -0700 | [diff] [blame] | 458 | protected ActivityDisplay getChildAt(int index) { |
Andrii Kulian | 1779e61 | 2016-10-12 21:58:25 -0700 | [diff] [blame] | 459 | return mActivityDisplays.valueAt(index); |
| 460 | } |
| 461 | |
| 462 | @Override |
| 463 | protected ConfigurationContainer getParent() { |
| 464 | return null; |
| 465 | } |
| 466 | |
Andrii Kulian | 5406e7a | 2016-10-21 11:55:23 -0700 | [diff] [blame] | 467 | Configuration getDisplayOverrideConfiguration(int displayId) { |
Andrii Kulian | 62e6f25 | 2017-05-30 22:46:53 -0700 | [diff] [blame] | 468 | final ActivityDisplay activityDisplay = getActivityDisplayOrCreateLocked(displayId); |
Andrii Kulian | 5406e7a | 2016-10-21 11:55:23 -0700 | [diff] [blame] | 469 | if (activityDisplay == null) { |
| 470 | throw new IllegalArgumentException("No display found with id: " + displayId); |
| 471 | } |
| 472 | |
| 473 | return activityDisplay.getOverrideConfiguration(); |
| 474 | } |
| 475 | |
| 476 | void setDisplayOverrideConfiguration(Configuration overrideConfiguration, int displayId) { |
Andrii Kulian | 62e6f25 | 2017-05-30 22:46:53 -0700 | [diff] [blame] | 477 | final ActivityDisplay activityDisplay = getActivityDisplayOrCreateLocked(displayId); |
Andrii Kulian | 5406e7a | 2016-10-21 11:55:23 -0700 | [diff] [blame] | 478 | if (activityDisplay == null) { |
| 479 | throw new IllegalArgumentException("No display found with id: " + displayId); |
| 480 | } |
| 481 | |
| 482 | activityDisplay.onOverrideConfigurationChanged(overrideConfiguration); |
| 483 | } |
| 484 | |
Andrii Kulian | 036e3ad | 2017-04-19 10:55:10 -0700 | [diff] [blame] | 485 | /** Check if placing task or activity on specified display is allowed. */ |
Andrii Kulian | 02689a7 | 2017-07-06 14:28:59 -0700 | [diff] [blame] | 486 | boolean canPlaceEntityOnDisplay(int displayId, boolean resizeable, int callingPid, |
| 487 | int callingUid, ActivityInfo activityInfo) { |
| 488 | if (displayId == DEFAULT_DISPLAY) { |
| 489 | // No restrictions for the default display. |
| 490 | return true; |
| 491 | } |
| 492 | if (!mService.mSupportsMultiDisplay) { |
| 493 | // Can't launch on secondary displays if feature is not supported. |
| 494 | return false; |
| 495 | } |
| 496 | if (!resizeable && !displayConfigMatchesGlobal(displayId)) { |
| 497 | // Can't apply wrong configuration to non-resizeable activities. |
| 498 | return false; |
| 499 | } |
| 500 | if (!isCallerAllowedToLaunchOnDisplay(callingPid, callingUid, displayId, activityInfo)) { |
| 501 | // Can't place activities to a display that has restricted launch rules. |
| 502 | // In this case the request should be made by explicitly adding target display id and |
| 503 | // by caller with corresponding permissions. See #isCallerAllowedToLaunchOnDisplay(). |
| 504 | return false; |
| 505 | } |
| 506 | return true; |
Andrii Kulian | 036e3ad | 2017-04-19 10:55:10 -0700 | [diff] [blame] | 507 | } |
| 508 | |
| 509 | /** |
| 510 | * Check if configuration of specified display matches current global config. |
| 511 | * Used to check if we can put a non-resizeable activity on a secondary display and it will get |
| 512 | * the same config as on the default display. |
| 513 | * @param displayId Id of the display to check. |
| 514 | * @return {@code true} if configuration matches. |
| 515 | */ |
| 516 | private boolean displayConfigMatchesGlobal(int displayId) { |
| 517 | if (displayId == DEFAULT_DISPLAY) { |
| 518 | return true; |
| 519 | } |
| 520 | if (displayId == INVALID_DISPLAY) { |
| 521 | return false; |
| 522 | } |
Andrii Kulian | 62e6f25 | 2017-05-30 22:46:53 -0700 | [diff] [blame] | 523 | final ActivityDisplay targetDisplay = getActivityDisplayOrCreateLocked(displayId); |
Andrii Kulian | 036e3ad | 2017-04-19 10:55:10 -0700 | [diff] [blame] | 524 | if (targetDisplay == null) { |
| 525 | throw new IllegalArgumentException("No display found with id: " + displayId); |
| 526 | } |
| 527 | return getConfiguration().equals(targetDisplay.getConfiguration()); |
| 528 | } |
| 529 | |
Wale Ogunwale | 3938197 | 2015-12-17 17:15:29 -0800 | [diff] [blame] | 530 | static class FindTaskResult { |
| 531 | ActivityRecord r; |
| 532 | boolean matchedByRootAffinity; |
| 533 | } |
| 534 | private final FindTaskResult mTmpFindTaskResult = new FindTaskResult(); |
| 535 | |
Craig Mautner | ee36c77 | 2014-07-16 14:56:05 -0700 | [diff] [blame] | 536 | /** |
Andrii Kulian | 7fc2281 | 2016-12-28 13:04:11 -0800 | [diff] [blame] | 537 | * Temp storage for display ids sorted in focus order. |
| 538 | * Maps position to id. Using {@link SparseIntArray} instead of {@link ArrayList} because |
| 539 | * it's more efficient, as the number of displays is usually small. |
| 540 | */ |
| 541 | private SparseIntArray mTmpOrderedDisplayIds = new SparseIntArray(); |
| 542 | |
| 543 | /** |
Jorim Jaggi | a0fdeec | 2016-01-07 14:42:28 +0100 | [diff] [blame] | 544 | * Used to keep track whether app visibilities got changed since the last pause. Useful to |
| 545 | * determine whether to invoke the task stack change listener after pausing. |
| 546 | */ |
| 547 | boolean mAppVisibilitiesChangedSinceLastPause; |
| 548 | |
| 549 | /** |
Jorim Jaggi | 0b46f3c | 2016-03-14 12:21:37 +0100 | [diff] [blame] | 550 | * Set of tasks that are in resizing mode during an app transition to fill the "void". |
| 551 | */ |
| 552 | private final ArraySet<Integer> mResizingTasksDuringAnimation = new ArraySet<>(); |
| 553 | |
Wale Ogunwale | c8da41e | 2016-04-16 13:27:23 -0700 | [diff] [blame] | 554 | |
| 555 | /** |
| 556 | * If set to {@code false} all calls to resize the docked stack {@link #resizeDockedStackLocked} |
| 557 | * will be ignored. Useful for the case where the caller is handling resizing of other stack and |
| 558 | * moving tasks around and doesn't want dock stack to be resized due to an automatic trigger |
| 559 | * like the docked stack going empty. |
| 560 | */ |
| 561 | private boolean mAllowDockedStackResize = true; |
| 562 | |
Jorim Jaggi | 0b46f3c | 2016-03-14 12:21:37 +0100 | [diff] [blame] | 563 | /** |
Tony Mak | 853304c | 2016-04-18 15:17:41 +0100 | [diff] [blame] | 564 | * Is dock currently minimized. |
| 565 | */ |
| 566 | boolean mIsDockMinimized; |
| 567 | |
Bryce Lee | 2a3cc46 | 2017-10-27 10:57:35 -0700 | [diff] [blame] | 568 | private KeyguardController mKeyguardController; |
Jorim Jaggi | fe76234 | 2016-10-13 14:33:27 +0200 | [diff] [blame] | 569 | |
chaviw | 59b9885 | 2017-06-13 12:05:44 -0700 | [diff] [blame] | 570 | private PowerManager mPowerManager; |
| 571 | private int mDeferResumeCount; |
| 572 | |
Bryce Lee | 2a3cc46 | 2017-10-27 10:57:35 -0700 | [diff] [blame] | 573 | private boolean mInitialized; |
| 574 | |
Tony Mak | 853304c | 2016-04-18 15:17:41 +0100 | [diff] [blame] | 575 | /** |
Craig Mautner | ee36c77 | 2014-07-16 14:56:05 -0700 | [diff] [blame] | 576 | * Description of a request to start a new activity, which has been held |
| 577 | * due to app switches being disabled. |
| 578 | */ |
| 579 | static class PendingActivityLaunch { |
| 580 | final ActivityRecord r; |
| 581 | final ActivityRecord sourceRecord; |
| 582 | final int startFlags; |
| 583 | final ActivityStack stack; |
Robert Carr | 13997f5 | 2015-10-23 13:13:39 -0700 | [diff] [blame] | 584 | final ProcessRecord callerApp; |
Craig Mautner | ee36c77 | 2014-07-16 14:56:05 -0700 | [diff] [blame] | 585 | |
| 586 | PendingActivityLaunch(ActivityRecord _r, ActivityRecord _sourceRecord, |
Robert Carr | 13997f5 | 2015-10-23 13:13:39 -0700 | [diff] [blame] | 587 | int _startFlags, ActivityStack _stack, ProcessRecord _callerApp) { |
Craig Mautner | ee36c77 | 2014-07-16 14:56:05 -0700 | [diff] [blame] | 588 | r = _r; |
| 589 | sourceRecord = _sourceRecord; |
| 590 | startFlags = _startFlags; |
| 591 | stack = _stack; |
Robert Carr | 13997f5 | 2015-10-23 13:13:39 -0700 | [diff] [blame] | 592 | callerApp = _callerApp; |
| 593 | } |
| 594 | |
| 595 | void sendErrorResult(String message) { |
| 596 | try { |
| 597 | if (callerApp.thread != null) { |
| 598 | callerApp.thread.scheduleCrash(message); |
| 599 | } |
| 600 | } catch (RemoteException e) { |
| 601 | Slog.e(TAG, "Exception scheduling crash of failed " |
| 602 | + "activity launcher sourceRecord=" + sourceRecord, e); |
| 603 | } |
Craig Mautner | ee36c77 | 2014-07-16 14:56:05 -0700 | [diff] [blame] | 604 | } |
| 605 | } |
| 606 | |
Bryce Lee | af691c0 | 2017-03-20 14:20:22 -0700 | [diff] [blame] | 607 | public ActivityStackSupervisor(ActivityManagerService service, Looper looper) { |
Craig Mautner | 2708430 | 2013-03-25 08:05:25 -0700 | [diff] [blame] | 608 | mService = service; |
Winson Chung | e2d7217 | 2018-01-25 17:46:20 +0000 | [diff] [blame] | 609 | mLooper = looper; |
Bryce Lee | af691c0 | 2017-03-20 14:20:22 -0700 | [diff] [blame] | 610 | mHandler = new ActivityStackSupervisorHandler(looper); |
Bryce Lee | 2a3cc46 | 2017-10-27 10:57:35 -0700 | [diff] [blame] | 611 | } |
| 612 | |
| 613 | public void initialize() { |
| 614 | if (mInitialized) { |
| 615 | return; |
| 616 | } |
| 617 | |
| 618 | mInitialized = true; |
Winson Chung | 3f0e59a | 2017-10-25 10:19:05 -0700 | [diff] [blame] | 619 | mRunningTasks = createRunningTasks(); |
Bryce Lee | 2a3cc46 | 2017-10-27 10:57:35 -0700 | [diff] [blame] | 620 | mActivityMetricsLogger = new ActivityMetricsLogger(this, mService.mContext, |
| 621 | mHandler.getLooper()); |
| 622 | mKeyguardController = new KeyguardController(mService, this); |
Bryce Lee | dacefc4 | 2017-10-10 12:56:02 -0700 | [diff] [blame] | 623 | |
Bryce Lee | ec55eb0 | 2017-12-05 20:51:27 -0800 | [diff] [blame] | 624 | mLaunchParamsController = new LaunchParamsController(mService); |
| 625 | mLaunchParamsController.registerDefaultModifiers(this); |
Jeff Brown | 2c43c33 | 2014-06-12 22:38:59 -0700 | [diff] [blame] | 626 | } |
| 627 | |
Bryce Lee | 2a3cc46 | 2017-10-27 10:57:35 -0700 | [diff] [blame] | 628 | |
| 629 | public ActivityMetricsLogger getActivityMetricsLogger() { |
| 630 | return mActivityMetricsLogger; |
| 631 | } |
| 632 | |
Jorim Jaggi | de8305a | 2018-05-15 12:06:35 -0700 | [diff] [blame] | 633 | LaunchTimeTracker getLaunchTimeTracker() { |
| 634 | return mLaunchTimeTracker; |
| 635 | } |
| 636 | |
Bryce Lee | 2a3cc46 | 2017-10-27 10:57:35 -0700 | [diff] [blame] | 637 | public KeyguardController getKeyguardController() { |
| 638 | return mKeyguardController; |
| 639 | } |
| 640 | |
Suprabh Shukla | 09a88f5 | 2015-12-02 14:36:31 -0800 | [diff] [blame] | 641 | void setRecentTasks(RecentTasks recentTasks) { |
| 642 | mRecentTasks = recentTasks; |
Winson Chung | 1dbc811 | 2017-09-28 18:05:31 -0700 | [diff] [blame] | 643 | mRecentTasks.registerCallback(this); |
Suprabh Shukla | 09a88f5 | 2015-12-02 14:36:31 -0800 | [diff] [blame] | 644 | } |
| 645 | |
Winson Chung | 3f0e59a | 2017-10-25 10:19:05 -0700 | [diff] [blame] | 646 | @VisibleForTesting |
| 647 | RunningTasks createRunningTasks() { |
| 648 | return new RunningTasks(); |
| 649 | } |
| 650 | |
Jeff Brown | 2c43c33 | 2014-06-12 22:38:59 -0700 | [diff] [blame] | 651 | /** |
| 652 | * At the time when the constructor runs, the power manager has not yet been |
| 653 | * initialized. So we initialize our wakelocks afterwards. |
| 654 | */ |
| 655 | void initPowerManagement() { |
chaviw | 59b9885 | 2017-06-13 12:05:44 -0700 | [diff] [blame] | 656 | mPowerManager = (PowerManager)mService.mContext.getSystemService(Context.POWER_SERVICE); |
| 657 | mGoingToSleep = mPowerManager |
| 658 | .newWakeLock(PARTIAL_WAKE_LOCK, "ActivityManager-Sleep"); |
| 659 | mLaunchingActivity = mPowerManager.newWakeLock(PARTIAL_WAKE_LOCK, "*launch*"); |
Craig Mautner | 7ea5bd4 | 2013-07-05 15:27:08 -0700 | [diff] [blame] | 660 | mLaunchingActivity.setReferenceCounted(false); |
Craig Mautner | 2219a1b | 2013-03-25 09:44:30 -0700 | [diff] [blame] | 661 | } |
| 662 | |
Craig Mautner | ce5f3cb | 2013-04-22 08:58:54 -0700 | [diff] [blame] | 663 | void setWindowManager(WindowManagerService wm) { |
Craig Mautner | 4a1cb22 | 2013-12-04 16:14:06 -0800 | [diff] [blame] | 664 | synchronized (mService) { |
| 665 | mWindowManager = wm; |
Bryce Lee | 459c062 | 2018-03-19 11:04:01 -0700 | [diff] [blame] | 666 | getKeyguardController().setWindowManager(wm); |
Craig Mautner | 4a1cb22 | 2013-12-04 16:14:06 -0800 | [diff] [blame] | 667 | |
| 668 | mDisplayManager = |
| 669 | (DisplayManager)mService.mContext.getSystemService(Context.DISPLAY_SERVICE); |
| 670 | mDisplayManager.registerDisplayListener(this, null); |
Andrii Kulian | fb1bf69 | 2017-01-17 11:17:34 -0800 | [diff] [blame] | 671 | mDisplayManagerInternal = LocalServices.getService(DisplayManagerInternal.class); |
Craig Mautner | 4a1cb22 | 2013-12-04 16:14:06 -0800 | [diff] [blame] | 672 | |
| 673 | Display[] displays = mDisplayManager.getDisplays(); |
| 674 | for (int displayNdx = displays.length - 1; displayNdx >= 0; --displayNdx) { |
Wale Ogunwale | 45477b5 | 2018-03-06 12:24:19 -0800 | [diff] [blame] | 675 | final Display display = displays[displayNdx]; |
| 676 | ActivityDisplay activityDisplay = new ActivityDisplay(this, display); |
| 677 | mActivityDisplays.put(display.getDisplayId(), activityDisplay); |
Filip Gruszczynski | 7be9a8c | 2015-10-15 18:20:30 -0700 | [diff] [blame] | 678 | calculateDefaultMinimalSizeOfResizeableTasks(activityDisplay); |
Craig Mautner | 4a1cb22 | 2013-12-04 16:14:06 -0800 | [diff] [blame] | 679 | } |
| 680 | |
Wale Ogunwale | 04a05ac | 2017-09-17 21:35:02 -0700 | [diff] [blame] | 681 | mHomeStack = mFocusedStack = mLastFocusedStack = getDefaultDisplay().getOrCreateStack( |
| 682 | WINDOWING_MODE_FULLSCREEN, ACTIVITY_TYPE_HOME, ON_TOP); |
Craig Mautner | 4a1cb22 | 2013-12-04 16:14:06 -0800 | [diff] [blame] | 683 | } |
Craig Mautner | 2708430 | 2013-03-25 08:05:25 -0700 | [diff] [blame] | 684 | } |
| 685 | |
Craig Mautner | ce5f3cb | 2013-04-22 08:58:54 -0700 | [diff] [blame] | 686 | ActivityStack getFocusedStack() { |
Craig Mautner | 4a1cb22 | 2013-12-04 16:14:06 -0800 | [diff] [blame] | 687 | return mFocusedStack; |
Craig Mautner | 20e7227 | 2013-04-01 13:45:53 -0700 | [diff] [blame] | 688 | } |
| 689 | |
Bryce Lee | 7b851cc | 2018-04-10 14:53:13 -0700 | [diff] [blame] | 690 | boolean isFocusable(ConfigurationContainer container, boolean alwaysFocusable) { |
| 691 | if (container.inSplitScreenPrimaryWindowingMode() && mIsDockMinimized) { |
| 692 | return false; |
| 693 | } |
| 694 | |
| 695 | return container.getWindowConfiguration().canReceiveKeys() || alwaysFocusable; |
| 696 | } |
| 697 | |
Craig Mautner | de4ef02 | 2013-04-07 19:01:33 -0700 | [diff] [blame] | 698 | ActivityStack getLastStack() { |
Craig Mautner | 4a1cb22 | 2013-12-04 16:14:06 -0800 | [diff] [blame] | 699 | return mLastFocusedStack; |
Craig Mautner | 2219a1b | 2013-03-25 09:44:30 -0700 | [diff] [blame] | 700 | } |
| 701 | |
Wale Ogunwale | 1e60e0c | 2015-10-28 13:36:10 -0700 | [diff] [blame] | 702 | boolean isFocusedStack(ActivityStack stack) { |
Andrii Kulian | 94e82d9b0 | 2017-07-13 15:33:06 -0700 | [diff] [blame] | 703 | return stack != null && stack == mFocusedStack; |
Craig Mautner | 20e7227 | 2013-04-01 13:45:53 -0700 | [diff] [blame] | 704 | } |
| 705 | |
Wale Ogunwale | d046a01 | 2015-12-24 13:05:59 -0800 | [diff] [blame] | 706 | /** NOTE: Should only be called from {@link ActivityStack#moveToFront} */ |
Wale Ogunwale | 4cea0f5 | 2015-12-25 06:30:31 -0800 | [diff] [blame] | 707 | void setFocusStackUnchecked(String reason, ActivityStack focusCandidate) { |
| 708 | if (!focusCandidate.isFocusable()) { |
| 709 | // The focus candidate isn't focusable. Move focus to the top stack that is focusable. |
Wale Ogunwale | e1f68ce | 2018-03-09 08:58:54 -0800 | [diff] [blame] | 710 | focusCandidate = getNextFocusableStackLocked(focusCandidate, false /* ignoreCurrent */); |
Wale Ogunwale | 4cea0f5 | 2015-12-25 06:30:31 -0800 | [diff] [blame] | 711 | } |
| 712 | |
| 713 | if (focusCandidate != mFocusedStack) { |
Wale Ogunwale | d046a01 | 2015-12-24 13:05:59 -0800 | [diff] [blame] | 714 | mLastFocusedStack = mFocusedStack; |
Wale Ogunwale | 4cea0f5 | 2015-12-25 06:30:31 -0800 | [diff] [blame] | 715 | mFocusedStack = focusCandidate; |
Wale Ogunwale | cb82f30 | 2015-02-25 07:53:40 -0800 | [diff] [blame] | 716 | |
Wale Ogunwale | d046a01 | 2015-12-24 13:05:59 -0800 | [diff] [blame] | 717 | EventLogTags.writeAmFocusedStack( |
| 718 | mCurrentUser, mFocusedStack == null ? -1 : mFocusedStack.getStackId(), |
| 719 | mLastFocusedStack == null ? -1 : mLastFocusedStack.getStackId(), reason); |
| 720 | } |
| 721 | |
| 722 | final ActivityRecord r = topRunningActivityLocked(); |
Craig Mautner | f3ea23a | 2015-01-13 09:37:08 -0800 | [diff] [blame] | 723 | if (mService.mBooting || !mService.mBooted) { |
Craig Mautner | f3ea23a | 2015-01-13 09:37:08 -0800 | [diff] [blame] | 724 | if (r != null && r.idle) { |
| 725 | checkFinishBootingLocked(); |
| 726 | } |
| 727 | } |
Craig Mautner | de4ef02 | 2013-04-07 19:01:33 -0700 | [diff] [blame] | 728 | } |
| 729 | |
Wale Ogunwale | 925d0d1 | 2015-09-23 15:40:07 -0700 | [diff] [blame] | 730 | void moveHomeStackToFront(String reason) { |
| 731 | mHomeStack.moveToFront(reason); |
| 732 | } |
| 733 | |
Matthew Ng | 330757d | 2017-02-28 14:19:17 -0800 | [diff] [blame] | 734 | void moveRecentsStackToFront(String reason) { |
Wale Ogunwale | 04a05ac | 2017-09-17 21:35:02 -0700 | [diff] [blame] | 735 | final ActivityStack recentsStack = getDefaultDisplay().getStack( |
| 736 | WINDOWING_MODE_UNDEFINED, ACTIVITY_TYPE_RECENTS); |
Matthew Ng | 330757d | 2017-02-28 14:19:17 -0800 | [diff] [blame] | 737 | if (recentsStack != null) { |
| 738 | recentsStack.moveToFront(reason); |
| 739 | } |
| 740 | } |
| 741 | |
Wale Ogunwale | d80c263 | 2015-03-13 10:26:26 -0700 | [diff] [blame] | 742 | /** 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] | 743 | boolean moveHomeStackTaskToTop(String reason) { |
| 744 | mHomeStack.moveHomeStackTaskToTop(); |
Wale Ogunwale | d80c263 | 2015-03-13 10:26:26 -0700 | [diff] [blame] | 745 | |
Wale Ogunwale | 2d0f39b | 2015-04-17 15:35:39 -0700 | [diff] [blame] | 746 | final ActivityRecord top = getHomeActivity(); |
Wale Ogunwale | d80c263 | 2015-03-13 10:26:26 -0700 | [diff] [blame] | 747 | if (top == null) { |
| 748 | return false; |
| 749 | } |
Chong Zhang | 6cda19c | 2016-06-14 19:07:56 -0700 | [diff] [blame] | 750 | moveFocusableActivityStackToFrontLocked(top, reason); |
Wale Ogunwale | d80c263 | 2015-03-13 10:26:26 -0700 | [diff] [blame] | 751 | return true; |
Craig Mautner | 8e56957 | 2013-10-11 17:36:59 -0700 | [diff] [blame] | 752 | } |
| 753 | |
Matthew Ng | ae1ff4f | 2016-11-10 15:49:14 -0800 | [diff] [blame] | 754 | boolean resumeHomeStackTask(ActivityRecord prev, String reason) { |
Dianne Hackborn | 7622a0f | 2014-09-30 14:31:42 -0700 | [diff] [blame] | 755 | if (!mService.mBooting && !mService.mBooted) { |
| 756 | // Not ready yet! |
| 757 | return false; |
| 758 | } |
| 759 | |
Matthew Ng | ae1ff4f | 2016-11-10 15:49:14 -0800 | [diff] [blame] | 760 | mHomeStack.moveHomeStackTaskToTop(); |
Wale Ogunwale | 2d0f39b | 2015-04-17 15:35:39 -0700 | [diff] [blame] | 761 | ActivityRecord r = getHomeActivity(); |
Wale Ogunwale | d046a01 | 2015-12-24 13:05:59 -0800 | [diff] [blame] | 762 | final String myReason = reason + " resumeHomeStackTask"; |
| 763 | |
Mark Lu | a56ea12 | 2015-10-08 13:31:01 +0800 | [diff] [blame] | 764 | // Only resume home activity if isn't finishing. |
| 765 | if (r != null && !r.finishing) { |
Chong Zhang | 6cda19c | 2016-06-14 19:07:56 -0700 | [diff] [blame] | 766 | moveFocusableActivityStackToFrontLocked(r, myReason); |
Wale Ogunwale | d046a01 | 2015-12-24 13:05:59 -0800 | [diff] [blame] | 767 | return resumeFocusedStackTopActivityLocked(mHomeStack, prev, null); |
Craig Mautner | 69ada55 | 2013-04-18 13:51:51 -0700 | [diff] [blame] | 768 | } |
Wale Ogunwale | d046a01 | 2015-12-24 13:05:59 -0800 | [diff] [blame] | 769 | return mService.startHomeActivityLocked(mCurrentUser, myReason); |
Craig Mautner | 69ada55 | 2013-04-18 13:51:51 -0700 | [diff] [blame] | 770 | } |
| 771 | |
Craig Mautner | 8d341ef | 2013-03-26 09:03:27 -0700 | [diff] [blame] | 772 | TaskRecord anyTaskForIdLocked(int id) { |
Wale Ogunwale | 0568aed | 2017-09-08 13:29:37 -0700 | [diff] [blame] | 773 | return anyTaskForIdLocked(id, MATCH_TASK_IN_STACKS_OR_RECENT_TASKS_AND_RESTORE); |
| 774 | } |
| 775 | |
| 776 | TaskRecord anyTaskForIdLocked(int id, @AnyTaskForIdMatchTaskMode int matchMode) { |
Wale Ogunwale | ab5de37 | 2017-10-18 06:46:31 -0700 | [diff] [blame] | 777 | return anyTaskForIdLocked(id, matchMode, null, !ON_TOP); |
Wale Ogunwale | 04f4d6b | 2015-03-11 09:23:25 -0700 | [diff] [blame] | 778 | } |
| 779 | |
| 780 | /** |
Bryce Lee | 92b7b65 | 2017-04-03 08:33:11 -0700 | [diff] [blame] | 781 | * 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] | 782 | * @param id Id of the task we would like returned. |
Winson Chung | 7900bee | 2017-03-10 08:59:25 -0800 | [diff] [blame] | 783 | * @param matchMode The mode to match the given task id in. |
Wale Ogunwale | 0568aed | 2017-09-08 13:29:37 -0700 | [diff] [blame] | 784 | * @param aOptions The activity options to use for restoration. Can be null. |
Wale Ogunwale | ab5de37 | 2017-10-18 06:46:31 -0700 | [diff] [blame] | 785 | * @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] | 786 | */ |
Wale Ogunwale | 0568aed | 2017-09-08 13:29:37 -0700 | [diff] [blame] | 787 | TaskRecord anyTaskForIdLocked(int id, @AnyTaskForIdMatchTaskMode int matchMode, |
Wale Ogunwale | ab5de37 | 2017-10-18 06:46:31 -0700 | [diff] [blame] | 788 | @Nullable ActivityOptions aOptions, boolean onTop) { |
| 789 | // 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] | 790 | if (matchMode != MATCH_TASK_IN_STACKS_OR_RECENT_TASKS_AND_RESTORE && aOptions != null) { |
| 791 | throw new IllegalArgumentException("Should not specify activity options for non-restore" |
| 792 | + " lookup"); |
Winson Chung | 7900bee | 2017-03-10 08:59:25 -0800 | [diff] [blame] | 793 | } |
| 794 | |
Craig Mautner | e0a3884 | 2013-12-16 16:14:02 -0800 | [diff] [blame] | 795 | int numDisplays = mActivityDisplays.size(); |
Craig Mautner | 4a1cb22 | 2013-12-04 16:14:06 -0800 | [diff] [blame] | 796 | for (int displayNdx = 0; displayNdx < numDisplays; ++displayNdx) { |
Wale Ogunwale | a0f5b5e | 2017-10-11 09:37:23 -0700 | [diff] [blame] | 797 | final ActivityDisplay display = mActivityDisplays.valueAt(displayNdx); |
| 798 | for (int stackNdx = display.getChildCount() - 1; stackNdx >= 0; --stackNdx) { |
| 799 | final ActivityStack stack = display.getChildAt(stackNdx); |
Bryce Lee | 92b7b65 | 2017-04-03 08:33:11 -0700 | [diff] [blame] | 800 | final TaskRecord task = stack.taskForIdLocked(id); |
Wale Ogunwale | ab5de37 | 2017-10-18 06:46:31 -0700 | [diff] [blame] | 801 | if (task == null) { |
| 802 | continue; |
Craig Mautner | 4a1cb22 | 2013-12-04 16:14:06 -0800 | [diff] [blame] | 803 | } |
Wale Ogunwale | ab5de37 | 2017-10-18 06:46:31 -0700 | [diff] [blame] | 804 | if (aOptions != null) { |
| 805 | // Resolve the stack the task should be placed in now based on options |
| 806 | // and reparent if needed. |
| 807 | final ActivityStack launchStack = getLaunchStack(null, aOptions, task, onTop); |
| 808 | if (launchStack != null && stack != launchStack) { |
| 809 | final int reparentMode = onTop |
| 810 | ? REPARENT_MOVE_STACK_TO_FRONT : REPARENT_LEAVE_STACK_IN_PLACE; |
| 811 | task.reparent(launchStack, onTop, reparentMode, ANIMATE, DEFER_RESUME, |
| 812 | "anyTaskForIdLocked"); |
| 813 | } |
| 814 | } |
| 815 | return task; |
Craig Mautner | 8d341ef | 2013-03-26 09:03:27 -0700 | [diff] [blame] | 816 | } |
| 817 | } |
Wale Ogunwale | 7de0535 | 2014-12-12 15:21:33 -0800 | [diff] [blame] | 818 | |
Winson Chung | 7900bee | 2017-03-10 08:59:25 -0800 | [diff] [blame] | 819 | // If we are matching stack tasks only, return now |
| 820 | if (matchMode == MATCH_TASK_IN_STACKS_ONLY) { |
Wale Ogunwale | 7de0535 | 2014-12-12 15:21:33 -0800 | [diff] [blame] | 821 | return null; |
| 822 | } |
| 823 | |
Winson Chung | 7900bee | 2017-03-10 08:59:25 -0800 | [diff] [blame] | 824 | // Otherwise, check the recent tasks and return if we find it there and we are not restoring |
| 825 | // the task from recents |
| 826 | 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] | 827 | final TaskRecord task = mRecentTasks.getTask(id); |
Bryce Lee | 92b7b65 | 2017-04-03 08:33:11 -0700 | [diff] [blame] | 828 | |
| 829 | if (task == null) { |
| 830 | if (DEBUG_RECENTS) { |
Winson Chung | 7900bee | 2017-03-10 08:59:25 -0800 | [diff] [blame] | 831 | Slog.d(TAG_RECENTS, "\tDidn't find task id=" + id + " in recents"); |
| 832 | } |
Bryce Lee | 92b7b65 | 2017-04-03 08:33:11 -0700 | [diff] [blame] | 833 | |
| 834 | return null; |
| 835 | } |
| 836 | |
| 837 | if (matchMode == MATCH_TASK_IN_STACKS_OR_RECENT_TASKS) { |
Wale Ogunwale | 04f4d6b | 2015-03-11 09:23:25 -0700 | [diff] [blame] | 838 | return task; |
| 839 | } |
| 840 | |
Winson Chung | 7900bee | 2017-03-10 08:59:25 -0800 | [diff] [blame] | 841 | // 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] | 842 | if (!restoreRecentTaskLocked(task, aOptions, onTop)) { |
Wale Ogunwale | ee006da | 2015-03-30 14:49:25 -0700 | [diff] [blame] | 843 | if (DEBUG_RECENTS) Slog.w(TAG_RECENTS, |
| 844 | "Couldn't restore task id=" + id + " found in recents"); |
Wale Ogunwale | 7de0535 | 2014-12-12 15:21:33 -0800 | [diff] [blame] | 845 | return null; |
| 846 | } |
Wale Ogunwale | ee006da | 2015-03-30 14:49:25 -0700 | [diff] [blame] | 847 | 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] | 848 | return task; |
Craig Mautner | 8d341ef | 2013-03-26 09:03:27 -0700 | [diff] [blame] | 849 | } |
| 850 | |
Craig Mautner | 6170f73 | 2013-04-02 13:05:23 -0700 | [diff] [blame] | 851 | ActivityRecord isInAnyStackLocked(IBinder token) { |
Craig Mautner | e0a3884 | 2013-12-16 16:14:02 -0800 | [diff] [blame] | 852 | int numDisplays = mActivityDisplays.size(); |
Craig Mautner | 4a1cb22 | 2013-12-04 16:14:06 -0800 | [diff] [blame] | 853 | for (int displayNdx = 0; displayNdx < numDisplays; ++displayNdx) { |
Wale Ogunwale | a0f5b5e | 2017-10-11 09:37:23 -0700 | [diff] [blame] | 854 | final ActivityDisplay display = mActivityDisplays.valueAt(displayNdx); |
| 855 | for (int stackNdx = display.getChildCount() - 1; stackNdx >= 0; --stackNdx) { |
| 856 | final ActivityStack stack = display.getChildAt(stackNdx); |
| 857 | final ActivityRecord r = stack.isInStackLocked(token); |
Craig Mautner | 4a1cb22 | 2013-12-04 16:14:06 -0800 | [diff] [blame] | 858 | if (r != null) { |
| 859 | return r; |
| 860 | } |
Craig Mautner | 6170f73 | 2013-04-02 13:05:23 -0700 | [diff] [blame] | 861 | } |
| 862 | } |
| 863 | return null; |
| 864 | } |
| 865 | |
Tony Mak | 853304c | 2016-04-18 15:17:41 +0100 | [diff] [blame] | 866 | /** |
Robin Lee | 3fef1f2 | 2016-12-20 14:50:13 +0000 | [diff] [blame] | 867 | * Detects whether we should show a lock screen in front of this task for a locked user. |
| 868 | * <p> |
| 869 | * We'll do this if either of the following holds: |
| 870 | * <ul> |
| 871 | * <li>The top activity explicitly belongs to {@param userId}.</li> |
| 872 | * <li>The top activity returns a result to an activity belonging to {@param userId}.</li> |
| 873 | * </ul> |
| 874 | * |
| 875 | * @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] | 876 | */ |
Robin Lee | 3fef1f2 | 2016-12-20 14:50:13 +0000 | [diff] [blame] | 877 | private boolean taskTopActivityIsUser(TaskRecord task, @UserIdInt int userId) { |
| 878 | // To handle the case that work app is in the task but just is not the top one. |
| 879 | final ActivityRecord activityRecord = task.getTopActivity(); |
| 880 | final ActivityRecord resultTo = (activityRecord != null ? activityRecord.resultTo : null); |
| 881 | |
| 882 | return (activityRecord != null && activityRecord.userId == userId) |
| 883 | || (resultTo != null && resultTo.userId == userId); |
| 884 | } |
| 885 | |
| 886 | /** |
| 887 | * Find all visible task stacks containing {@param userId} and intercept them with an activity |
| 888 | * to block out the contents and possibly start a credential-confirming intent. |
| 889 | * |
| 890 | * @param userId user handle for the locked managed profile. |
| 891 | */ |
| 892 | void lockAllProfileTasks(@UserIdInt int userId) { |
| 893 | mWindowManager.deferSurfaceLayout(); |
| 894 | try { |
Wale Ogunwale | a0f5b5e | 2017-10-11 09:37:23 -0700 | [diff] [blame] | 895 | for (int displayNdx = mActivityDisplays.size() - 1; displayNdx >= 0; --displayNdx) { |
| 896 | final ActivityDisplay display = mActivityDisplays.valueAt(displayNdx); |
| 897 | for (int stackNdx = display.getChildCount() - 1; stackNdx >= 0; --stackNdx) { |
| 898 | final ActivityStack stack = display.getChildAt(stackNdx); |
| 899 | final List<TaskRecord> tasks = stack.getAllTasks(); |
| 900 | for (int taskNdx = tasks.size() - 1; taskNdx >= 0; taskNdx--) { |
| 901 | final TaskRecord task = tasks.get(taskNdx); |
Robin Lee | 3fef1f2 | 2016-12-20 14:50:13 +0000 | [diff] [blame] | 902 | |
Wale Ogunwale | a0f5b5e | 2017-10-11 09:37:23 -0700 | [diff] [blame] | 903 | // Check the task for a top activity belonging to userId, or returning a |
| 904 | // result to an activity belonging to userId. Example case: a document |
| 905 | // picker for personal files, opened by a work app, should still get locked. |
| 906 | if (taskTopActivityIsUser(task, userId)) { |
| 907 | mService.mTaskChangeNotificationController.notifyTaskProfileLocked( |
| 908 | task.taskId, userId); |
| 909 | } |
Robin Lee | 3fef1f2 | 2016-12-20 14:50:13 +0000 | [diff] [blame] | 910 | } |
Tony Mak | 853304c | 2016-04-18 15:17:41 +0100 | [diff] [blame] | 911 | } |
| 912 | } |
Robin Lee | 3fef1f2 | 2016-12-20 14:50:13 +0000 | [diff] [blame] | 913 | } finally { |
| 914 | mWindowManager.continueSurfaceLayout(); |
Tony Mak | 853304c | 2016-04-18 15:17:41 +0100 | [diff] [blame] | 915 | } |
Clara Bayarri | f0649ce | 2016-01-14 12:30:42 +0000 | [diff] [blame] | 916 | } |
| 917 | |
Suprabh Shukla | 09a88f5 | 2015-12-02 14:36:31 -0800 | [diff] [blame] | 918 | void setNextTaskIdForUserLocked(int taskId, int userId) { |
| 919 | final int currentTaskId = mCurTaskIdForUser.get(userId, -1); |
| 920 | if (taskId > currentTaskId) { |
| 921 | mCurTaskIdForUser.put(userId, taskId); |
Craig Mautner | ef73ee1 | 2014-04-23 11:45:37 -0700 | [diff] [blame] | 922 | } |
| 923 | } |
| 924 | |
Chong Zhang | d9d35bd | 2016-08-04 17:55:21 -0700 | [diff] [blame] | 925 | static int nextTaskIdForUser(int taskId, int userId) { |
| 926 | int nextTaskId = taskId + 1; |
| 927 | if (nextTaskId == (userId + 1) * MAX_TASK_IDS_PER_USER) { |
| 928 | // Wrap around as there will be smaller task ids that are available now. |
| 929 | nextTaskId -= MAX_TASK_IDS_PER_USER; |
| 930 | } |
| 931 | return nextTaskId; |
| 932 | } |
| 933 | |
Suprabh Shukla | 09a88f5 | 2015-12-02 14:36:31 -0800 | [diff] [blame] | 934 | int getNextTaskIdForUserLocked(int userId) { |
Suprabh Shukla | 09a88f5 | 2015-12-02 14:36:31 -0800 | [diff] [blame] | 935 | final int currentTaskId = mCurTaskIdForUser.get(userId, userId * MAX_TASK_IDS_PER_USER); |
| 936 | // for a userId u, a taskId can only be in the range |
| 937 | // [u*MAX_TASK_IDS_PER_USER, (u+1)*MAX_TASK_IDS_PER_USER-1], so if MAX_TASK_IDS_PER_USER |
| 938 | // 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] | 939 | int candidateTaskId = nextTaskIdForUser(currentTaskId, userId); |
Winson Chung | 1dbc811 | 2017-09-28 18:05:31 -0700 | [diff] [blame] | 940 | while (mRecentTasks.containsTaskId(candidateTaskId, userId) |
Wale Ogunwale | 0568aed | 2017-09-08 13:29:37 -0700 | [diff] [blame] | 941 | || anyTaskForIdLocked( |
| 942 | candidateTaskId, MATCH_TASK_IN_STACKS_OR_RECENT_TASKS) != null) { |
Chong Zhang | d9d35bd | 2016-08-04 17:55:21 -0700 | [diff] [blame] | 943 | candidateTaskId = nextTaskIdForUser(candidateTaskId, userId); |
Suprabh Shukla | 09a88f5 | 2015-12-02 14:36:31 -0800 | [diff] [blame] | 944 | if (candidateTaskId == currentTaskId) { |
| 945 | // Something wrong! |
| 946 | // All MAX_TASK_IDS_PER_USER task ids are taken up by running tasks for this user |
| 947 | throw new IllegalStateException("Cannot get an available task id." |
| 948 | + " Reached limit of " + MAX_TASK_IDS_PER_USER |
| 949 | + " running tasks per user."); |
| 950 | } |
| 951 | } |
| 952 | mCurTaskIdForUser.put(userId, candidateTaskId); |
| 953 | return candidateTaskId; |
Craig Mautner | 8d341ef | 2013-03-26 09:03:27 -0700 | [diff] [blame] | 954 | } |
| 955 | |
Chong Zhang | 6cda19c | 2016-06-14 19:07:56 -0700 | [diff] [blame] | 956 | ActivityRecord getResumedActivityLocked() { |
Wale Ogunwale | d697cea | 2015-02-20 17:19:49 -0800 | [diff] [blame] | 957 | ActivityStack stack = mFocusedStack; |
Craig Mautner | ce5f3cb | 2013-04-22 08:58:54 -0700 | [diff] [blame] | 958 | if (stack == null) { |
| 959 | return null; |
| 960 | } |
Bryce Lee | c4ab62a | 2018-03-05 14:19:26 -0800 | [diff] [blame] | 961 | ActivityRecord resumedActivity = stack.getResumedActivity(); |
Craig Mautner | de4ef02 | 2013-04-07 19:01:33 -0700 | [diff] [blame] | 962 | if (resumedActivity == null || resumedActivity.app == null) { |
| 963 | resumedActivity = stack.mPausingActivity; |
| 964 | if (resumedActivity == null || resumedActivity.app == null) { |
Filip Gruszczynski | 3e85ba2 | 2015-10-05 22:48:30 -0700 | [diff] [blame] | 965 | resumedActivity = stack.topRunningActivityLocked(); |
Craig Mautner | de4ef02 | 2013-04-07 19:01:33 -0700 | [diff] [blame] | 966 | } |
| 967 | } |
| 968 | return resumedActivity; |
| 969 | } |
| 970 | |
Dianne Hackborn | ff07272 | 2014-09-24 10:56:28 -0700 | [diff] [blame] | 971 | boolean attachApplicationLocked(ProcessRecord app) throws RemoteException { |
Craig Mautner | 20e7227 | 2013-04-01 13:45:53 -0700 | [diff] [blame] | 972 | final String processName = app.processName; |
Craig Mautner | 4a1cb22 | 2013-12-04 16:14:06 -0800 | [diff] [blame] | 973 | boolean didSomething = false; |
Craig Mautner | e0a3884 | 2013-12-16 16:14:02 -0800 | [diff] [blame] | 974 | for (int displayNdx = mActivityDisplays.size() - 1; displayNdx >= 0; --displayNdx) { |
Wale Ogunwale | a0f5b5e | 2017-10-11 09:37:23 -0700 | [diff] [blame] | 975 | final ActivityDisplay display = mActivityDisplays.valueAt(displayNdx); |
| 976 | for (int stackNdx = display.getChildCount() - 1; stackNdx >= 0; --stackNdx) { |
| 977 | final ActivityStack stack = display.getChildAt(stackNdx); |
Wale Ogunwale | 1e60e0c | 2015-10-28 13:36:10 -0700 | [diff] [blame] | 978 | if (!isFocusedStack(stack)) { |
Craig Mautner | 4a1cb22 | 2013-12-04 16:14:06 -0800 | [diff] [blame] | 979 | continue; |
| 980 | } |
Jorim Jaggi | ea039a8 | 2017-08-02 14:37:49 +0200 | [diff] [blame] | 981 | stack.getAllRunningVisibleActivitiesLocked(mTmpActivityList); |
| 982 | final ActivityRecord top = stack.topRunningActivityLocked(); |
| 983 | final int size = mTmpActivityList.size(); |
| 984 | for (int i = 0; i < size; i++) { |
| 985 | final ActivityRecord activity = mTmpActivityList.get(i); |
| 986 | if (activity.app == null && app.uid == activity.info.applicationInfo.uid |
| 987 | && processName.equals(activity.processName)) { |
Craig Mautner | 4a1cb22 | 2013-12-04 16:14:06 -0800 | [diff] [blame] | 988 | try { |
Jorim Jaggi | ea039a8 | 2017-08-02 14:37:49 +0200 | [diff] [blame] | 989 | if (realStartActivityLocked(activity, app, |
| 990 | top == activity /* andResume */, true /* checkConfig */)) { |
Craig Mautner | 4a1cb22 | 2013-12-04 16:14:06 -0800 | [diff] [blame] | 991 | didSomething = true; |
| 992 | } |
Dianne Hackborn | ff07272 | 2014-09-24 10:56:28 -0700 | [diff] [blame] | 993 | } catch (RemoteException e) { |
Craig Mautner | 4a1cb22 | 2013-12-04 16:14:06 -0800 | [diff] [blame] | 994 | Slog.w(TAG, "Exception in new application when starting activity " |
Jorim Jaggi | ea039a8 | 2017-08-02 14:37:49 +0200 | [diff] [blame] | 995 | + top.intent.getComponent().flattenToShortString(), e); |
Craig Mautner | 4a1cb22 | 2013-12-04 16:14:06 -0800 | [diff] [blame] | 996 | throw e; |
Craig Mautner | 20e7227 | 2013-04-01 13:45:53 -0700 | [diff] [blame] | 997 | } |
Craig Mautner | 20e7227 | 2013-04-01 13:45:53 -0700 | [diff] [blame] | 998 | } |
Craig Mautner | 20e7227 | 2013-04-01 13:45:53 -0700 | [diff] [blame] | 999 | } |
| 1000 | } |
| 1001 | } |
Craig Mautner | b59dcfd | 2013-05-06 13:12:58 -0700 | [diff] [blame] | 1002 | if (!didSomething) { |
Filip Gruszczynski | bc5a6c5 | 2015-09-22 13:13:24 -0700 | [diff] [blame] | 1003 | ensureActivitiesVisibleLocked(null, 0, !PRESERVE_WINDOWS); |
Craig Mautner | b59dcfd | 2013-05-06 13:12:58 -0700 | [diff] [blame] | 1004 | } |
Craig Mautner | 20e7227 | 2013-04-01 13:45:53 -0700 | [diff] [blame] | 1005 | return didSomething; |
| 1006 | } |
| 1007 | |
| 1008 | boolean allResumedActivitiesIdle() { |
Craig Mautner | e0a3884 | 2013-12-16 16:14:02 -0800 | [diff] [blame] | 1009 | for (int displayNdx = mActivityDisplays.size() - 1; displayNdx >= 0; --displayNdx) { |
Wale Ogunwale | a0f5b5e | 2017-10-11 09:37:23 -0700 | [diff] [blame] | 1010 | final ActivityDisplay display = mActivityDisplays.valueAt(displayNdx); |
| 1011 | for (int stackNdx = display.getChildCount() - 1; stackNdx >= 0; --stackNdx) { |
| 1012 | final ActivityStack stack = display.getChildAt(stackNdx); |
Wale Ogunwale | 1e60e0c | 2015-10-28 13:36:10 -0700 | [diff] [blame] | 1013 | if (!isFocusedStack(stack) || stack.numActivities() == 0) { |
Craig Mautner | 4a1cb22 | 2013-12-04 16:14:06 -0800 | [diff] [blame] | 1014 | continue; |
| 1015 | } |
Bryce Lee | c4ab62a | 2018-03-05 14:19:26 -0800 | [diff] [blame] | 1016 | final ActivityRecord resumedActivity = stack.getResumedActivity(); |
Craig Mautner | 4a1cb22 | 2013-12-04 16:14:06 -0800 | [diff] [blame] | 1017 | if (resumedActivity == null || !resumedActivity.idle) { |
Wale Ogunwale | 0fc365c | 2015-05-25 19:35:42 -0700 | [diff] [blame] | 1018 | if (DEBUG_STATES) Slog.d(TAG_STATES, "allResumedActivitiesIdle: stack=" |
Craig Mautner | 34b73df | 2014-01-12 21:11:08 -0800 | [diff] [blame] | 1019 | + stack.mStackId + " " + resumedActivity + " not idle"); |
Craig Mautner | 4a1cb22 | 2013-12-04 16:14:06 -0800 | [diff] [blame] | 1020 | return false; |
| 1021 | } |
Craig Mautner | 20e7227 | 2013-04-01 13:45:53 -0700 | [diff] [blame] | 1022 | } |
| 1023 | } |
Wei Wang | 65c7a15 | 2016-06-02 18:51:22 -0700 | [diff] [blame] | 1024 | // Send launch end powerhint when idle |
Bryce Lee | d3624e1 | 2017-11-30 08:51:45 -0800 | [diff] [blame] | 1025 | sendPowerHintForLaunchEndIfNeeded(); |
Craig Mautner | 20e7227 | 2013-04-01 13:45:53 -0700 | [diff] [blame] | 1026 | return true; |
| 1027 | } |
| 1028 | |
Craig Mautner | de4ef02 | 2013-04-07 19:01:33 -0700 | [diff] [blame] | 1029 | boolean allResumedActivitiesComplete() { |
Craig Mautner | e0a3884 | 2013-12-16 16:14:02 -0800 | [diff] [blame] | 1030 | for (int displayNdx = mActivityDisplays.size() - 1; displayNdx >= 0; --displayNdx) { |
Wale Ogunwale | a0f5b5e | 2017-10-11 09:37:23 -0700 | [diff] [blame] | 1031 | final ActivityDisplay display = mActivityDisplays.valueAt(displayNdx); |
| 1032 | for (int stackNdx = display.getChildCount() - 1; stackNdx >= 0; --stackNdx) { |
| 1033 | final ActivityStack stack = display.getChildAt(stackNdx); |
Wale Ogunwale | 1e60e0c | 2015-10-28 13:36:10 -0700 | [diff] [blame] | 1034 | if (isFocusedStack(stack)) { |
Bryce Lee | c4ab62a | 2018-03-05 14:19:26 -0800 | [diff] [blame] | 1035 | final ActivityRecord r = stack.getResumedActivity(); |
Bryce Lee | 7ace395 | 2018-02-16 14:34:32 -0800 | [diff] [blame] | 1036 | if (r != null && !r.isState(RESUMED)) { |
Craig Mautner | 4a1cb22 | 2013-12-04 16:14:06 -0800 | [diff] [blame] | 1037 | return false; |
| 1038 | } |
Craig Mautner | de4ef02 | 2013-04-07 19:01:33 -0700 | [diff] [blame] | 1039 | } |
| 1040 | } |
| 1041 | } |
| 1042 | // 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] | 1043 | if (DEBUG_STACK) Slog.d(TAG_STACK, |
Craig Mautner | 4a1cb22 | 2013-12-04 16:14:06 -0800 | [diff] [blame] | 1044 | "allResumedActivitiesComplete: mLastFocusedStack changing from=" + |
| 1045 | mLastFocusedStack + " to=" + mFocusedStack); |
| 1046 | mLastFocusedStack = mFocusedStack; |
Craig Mautner | de4ef02 | 2013-04-07 19:01:33 -0700 | [diff] [blame] | 1047 | return true; |
| 1048 | } |
| 1049 | |
Wale Ogunwale | a0f5b5e | 2017-10-11 09:37:23 -0700 | [diff] [blame] | 1050 | private boolean allResumedActivitiesVisible() { |
riddle_hsu | db46d6b | 2015-04-01 18:58:07 +0800 | [diff] [blame] | 1051 | boolean foundResumed = false; |
Craig Mautner | e0a3884 | 2013-12-16 16:14:02 -0800 | [diff] [blame] | 1052 | for (int displayNdx = mActivityDisplays.size() - 1; displayNdx >= 0; --displayNdx) { |
Wale Ogunwale | a0f5b5e | 2017-10-11 09:37:23 -0700 | [diff] [blame] | 1053 | final ActivityDisplay display = mActivityDisplays.valueAt(displayNdx); |
| 1054 | for (int stackNdx = display.getChildCount() - 1; stackNdx >= 0; --stackNdx) { |
| 1055 | final ActivityStack stack = display.getChildAt(stackNdx); |
Bryce Lee | c4ab62a | 2018-03-05 14:19:26 -0800 | [diff] [blame] | 1056 | final ActivityRecord r = stack.getResumedActivity(); |
riddle_hsu | db46d6b | 2015-04-01 18:58:07 +0800 | [diff] [blame] | 1057 | if (r != null) { |
Bryce Lee | 4a19438 | 2017-04-04 14:32:48 -0700 | [diff] [blame] | 1058 | if (!r.nowVisible || mActivitiesWaitingForVisibleActivity.contains(r)) { |
riddle_hsu | db46d6b | 2015-04-01 18:58:07 +0800 | [diff] [blame] | 1059 | return false; |
| 1060 | } |
| 1061 | foundResumed = true; |
Craig Mautner | 4a1cb22 | 2013-12-04 16:14:06 -0800 | [diff] [blame] | 1062 | } |
Craig Mautner | de4ef02 | 2013-04-07 19:01:33 -0700 | [diff] [blame] | 1063 | } |
| 1064 | } |
riddle_hsu | db46d6b | 2015-04-01 18:58:07 +0800 | [diff] [blame] | 1065 | return foundResumed; |
Craig Mautner | de4ef02 | 2013-04-07 19:01:33 -0700 | [diff] [blame] | 1066 | } |
| 1067 | |
Craig Mautner | 2acc389 | 2013-09-23 10:28:14 -0700 | [diff] [blame] | 1068 | /** |
| 1069 | * Pause all activities in either all of the stacks or just the back stacks. |
| 1070 | * @param userLeaving Passed to pauseActivity() to indicate whether to call onUserLeaving(). |
Wale Ogunwale | 950faff | 2016-08-08 09:51:04 -0700 | [diff] [blame] | 1071 | * @param resuming The resuming activity. |
| 1072 | * @param dontWait The resuming activity isn't going to wait for all activities to be paused |
| 1073 | * before resuming. |
Craig Mautner | 2acc389 | 2013-09-23 10:28:14 -0700 | [diff] [blame] | 1074 | * @return true if any activity was paused as a result of this call. |
| 1075 | */ |
Wale Ogunwale | 950faff | 2016-08-08 09:51:04 -0700 | [diff] [blame] | 1076 | boolean pauseBackStacks(boolean userLeaving, ActivityRecord resuming, boolean dontWait) { |
Craig Mautner | cf910b0 | 2013-04-23 11:23:27 -0700 | [diff] [blame] | 1077 | boolean someActivityPaused = false; |
Craig Mautner | e0a3884 | 2013-12-16 16:14:02 -0800 | [diff] [blame] | 1078 | for (int displayNdx = mActivityDisplays.size() - 1; displayNdx >= 0; --displayNdx) { |
Wale Ogunwale | a0f5b5e | 2017-10-11 09:37:23 -0700 | [diff] [blame] | 1079 | final ActivityDisplay display = mActivityDisplays.valueAt(displayNdx); |
| 1080 | for (int stackNdx = display.getChildCount() - 1; stackNdx >= 0; --stackNdx) { |
| 1081 | final ActivityStack stack = display.getChildAt(stackNdx); |
Bryce Lee | c4ab62a | 2018-03-05 14:19:26 -0800 | [diff] [blame] | 1082 | if (!isFocusedStack(stack) && stack.getResumedActivity() != null) { |
Wale Ogunwale | 0fc365c | 2015-05-25 19:35:42 -0700 | [diff] [blame] | 1083 | if (DEBUG_STATES) Slog.d(TAG_STATES, "pauseBackStacks: stack=" + stack + |
Bryce Lee | c4ab62a | 2018-03-05 14:19:26 -0800 | [diff] [blame] | 1084 | " mResumedActivity=" + stack.getResumedActivity()); |
Dianne Hackborn | a4e102e | 2014-09-04 22:52:27 -0700 | [diff] [blame] | 1085 | someActivityPaused |= stack.startPausingLocked(userLeaving, false, resuming, |
| 1086 | dontWait); |
Craig Mautner | 4a1cb22 | 2013-12-04 16:14:06 -0800 | [diff] [blame] | 1087 | } |
Craig Mautner | cf910b0 | 2013-04-23 11:23:27 -0700 | [diff] [blame] | 1088 | } |
| 1089 | } |
| 1090 | return someActivityPaused; |
| 1091 | } |
| 1092 | |
Craig Mautner | de4ef02 | 2013-04-07 19:01:33 -0700 | [diff] [blame] | 1093 | boolean allPausedActivitiesComplete() { |
Craig Mautner | ac6f843 | 2013-07-17 13:24:59 -0700 | [diff] [blame] | 1094 | boolean pausing = true; |
Craig Mautner | e0a3884 | 2013-12-16 16:14:02 -0800 | [diff] [blame] | 1095 | for (int displayNdx = mActivityDisplays.size() - 1; displayNdx >= 0; --displayNdx) { |
Wale Ogunwale | a0f5b5e | 2017-10-11 09:37:23 -0700 | [diff] [blame] | 1096 | final ActivityDisplay display = mActivityDisplays.valueAt(displayNdx); |
| 1097 | for (int stackNdx = display.getChildCount() - 1; stackNdx >= 0; --stackNdx) { |
| 1098 | final ActivityStack stack = display.getChildAt(stackNdx); |
Craig Mautner | 4a1cb22 | 2013-12-04 16:14:06 -0800 | [diff] [blame] | 1099 | final ActivityRecord r = stack.mPausingActivity; |
Bryce Lee | 7ace395 | 2018-02-16 14:34:32 -0800 | [diff] [blame] | 1100 | if (r != null && !r.isState(PAUSED, STOPPED, STOPPING)) { |
Craig Mautner | 4a1cb22 | 2013-12-04 16:14:06 -0800 | [diff] [blame] | 1101 | if (DEBUG_STATES) { |
Wale Ogunwale | 0fc365c | 2015-05-25 19:35:42 -0700 | [diff] [blame] | 1102 | Slog.d(TAG_STATES, |
Bryce Lee | 7ace395 | 2018-02-16 14:34:32 -0800 | [diff] [blame] | 1103 | "allPausedActivitiesComplete: r=" + r + " state=" + r.getState()); |
Craig Mautner | 4a1cb22 | 2013-12-04 16:14:06 -0800 | [diff] [blame] | 1104 | pausing = false; |
| 1105 | } else { |
| 1106 | return false; |
| 1107 | } |
Craig Mautner | ac6f843 | 2013-07-17 13:24:59 -0700 | [diff] [blame] | 1108 | } |
Craig Mautner | de4ef02 | 2013-04-07 19:01:33 -0700 | [diff] [blame] | 1109 | } |
| 1110 | } |
Craig Mautner | ac6f843 | 2013-07-17 13:24:59 -0700 | [diff] [blame] | 1111 | return pausing; |
Craig Mautner | de4ef02 | 2013-04-07 19:01:33 -0700 | [diff] [blame] | 1112 | } |
| 1113 | |
Wale Ogunwale | 2be760d | 2016-02-17 11:16:10 -0800 | [diff] [blame] | 1114 | void cancelInitializingActivities() { |
| 1115 | for (int displayNdx = mActivityDisplays.size() - 1; displayNdx >= 0; --displayNdx) { |
Wale Ogunwale | a0f5b5e | 2017-10-11 09:37:23 -0700 | [diff] [blame] | 1116 | final ActivityDisplay display = mActivityDisplays.valueAt(displayNdx); |
| 1117 | for (int stackNdx = display.getChildCount() - 1; stackNdx >= 0; --stackNdx) { |
| 1118 | final ActivityStack stack = display.getChildAt(stackNdx); |
| 1119 | stack.cancelInitializingActivities(); |
Wale Ogunwale | 2be760d | 2016-02-17 11:16:10 -0800 | [diff] [blame] | 1120 | } |
| 1121 | } |
| 1122 | } |
| 1123 | |
Bryce Lee | 4a19438 | 2017-04-04 14:32:48 -0700 | [diff] [blame] | 1124 | void waitActivityVisible(ComponentName name, WaitResult result) { |
| 1125 | final WaitInfo waitInfo = new WaitInfo(name, result); |
| 1126 | mWaitingForActivityVisible.add(waitInfo); |
| 1127 | } |
| 1128 | |
| 1129 | void cleanupActivity(ActivityRecord r) { |
| 1130 | // Make sure this record is no longer in the pending finishes list. |
| 1131 | // This could happen, for example, if we are trimming activities |
| 1132 | // down to the max limit while they are still waiting to finish. |
| 1133 | mFinishingActivities.remove(r); |
| 1134 | mActivitiesWaitingForVisibleActivity.remove(r); |
| 1135 | |
| 1136 | for (int i = mWaitingForActivityVisible.size() - 1; i >= 0; --i) { |
Wale Ogunwale | 3270f17 | 2017-04-26 07:29:42 -0700 | [diff] [blame] | 1137 | if (mWaitingForActivityVisible.get(i).matches(r.realActivity)) { |
Bryce Lee | 4a19438 | 2017-04-04 14:32:48 -0700 | [diff] [blame] | 1138 | mWaitingForActivityVisible.remove(i); |
| 1139 | } |
| 1140 | } |
| 1141 | } |
| 1142 | |
Craig Mautner | ce5f3cb | 2013-04-22 08:58:54 -0700 | [diff] [blame] | 1143 | void reportActivityVisibleLocked(ActivityRecord r) { |
Dianne Hackborn | 6cfbb71 | 2014-09-17 12:47:35 -0700 | [diff] [blame] | 1144 | sendWaitingVisibleReportLocked(r); |
Dianne Hackborn | 6cfbb71 | 2014-09-17 12:47:35 -0700 | [diff] [blame] | 1145 | } |
| 1146 | |
| 1147 | void sendWaitingVisibleReportLocked(ActivityRecord r) { |
| 1148 | boolean changed = false; |
Bryce Lee | 4a19438 | 2017-04-04 14:32:48 -0700 | [diff] [blame] | 1149 | for (int i = mWaitingForActivityVisible.size() - 1; i >= 0; --i) { |
| 1150 | final WaitInfo w = mWaitingForActivityVisible.get(i); |
Wale Ogunwale | 3270f17 | 2017-04-26 07:29:42 -0700 | [diff] [blame] | 1151 | if (w.matches(r.realActivity)) { |
Bryce Lee | 4a19438 | 2017-04-04 14:32:48 -0700 | [diff] [blame] | 1152 | final WaitResult result = w.getResult(); |
Dianne Hackborn | 6cfbb71 | 2014-09-17 12:47:35 -0700 | [diff] [blame] | 1153 | changed = true; |
Bryce Lee | 4a19438 | 2017-04-04 14:32:48 -0700 | [diff] [blame] | 1154 | result.timeout = false; |
| 1155 | result.who = w.getComponent(); |
| 1156 | result.totalTime = SystemClock.uptimeMillis() - result.thisTime; |
| 1157 | result.thisTime = result.totalTime; |
| 1158 | mWaitingForActivityVisible.remove(w); |
Craig Mautner | ce5f3cb | 2013-04-22 08:58:54 -0700 | [diff] [blame] | 1159 | } |
Craig Mautner | ce5f3cb | 2013-04-22 08:58:54 -0700 | [diff] [blame] | 1160 | } |
Dianne Hackborn | 6cfbb71 | 2014-09-17 12:47:35 -0700 | [diff] [blame] | 1161 | if (changed) { |
| 1162 | mService.notifyAll(); |
| 1163 | } |
Craig Mautner | ce5f3cb | 2013-04-22 08:58:54 -0700 | [diff] [blame] | 1164 | } |
| 1165 | |
Bryce Lee | 5f0e28f | 2018-01-30 16:00:03 -0800 | [diff] [blame] | 1166 | void reportWaitingActivityLaunchedIfNeeded(ActivityRecord r, int result) { |
| 1167 | if (mWaitingActivityLaunched.isEmpty()) { |
| 1168 | return; |
| 1169 | } |
| 1170 | |
| 1171 | if (result != START_DELIVERED_TO_TOP && result != START_TASK_TO_FRONT) { |
| 1172 | return; |
| 1173 | } |
| 1174 | |
Chong Zhang | 5022da3 | 2016-06-21 16:31:37 -0700 | [diff] [blame] | 1175 | boolean changed = false; |
Bryce Lee | 5f0e28f | 2018-01-30 16:00:03 -0800 | [diff] [blame] | 1176 | |
Chong Zhang | 5022da3 | 2016-06-21 16:31:37 -0700 | [diff] [blame] | 1177 | for (int i = mWaitingActivityLaunched.size() - 1; i >= 0; i--) { |
| 1178 | WaitResult w = mWaitingActivityLaunched.remove(i); |
| 1179 | if (w.who == null) { |
| 1180 | changed = true; |
Bryce Lee | 5f0e28f | 2018-01-30 16:00:03 -0800 | [diff] [blame] | 1181 | w.result = result; |
| 1182 | |
| 1183 | // Unlike START_TASK_TO_FRONT, When an intent is delivered to top, there |
| 1184 | // will be no followup launch signals. Assign the result and launched component. |
| 1185 | if (result == START_DELIVERED_TO_TOP) { |
| 1186 | w.who = r.realActivity; |
| 1187 | } |
Chong Zhang | 5022da3 | 2016-06-21 16:31:37 -0700 | [diff] [blame] | 1188 | } |
| 1189 | } |
Bryce Lee | 5f0e28f | 2018-01-30 16:00:03 -0800 | [diff] [blame] | 1190 | |
Chong Zhang | 5022da3 | 2016-06-21 16:31:37 -0700 | [diff] [blame] | 1191 | if (changed) { |
| 1192 | mService.notifyAll(); |
| 1193 | } |
| 1194 | } |
| 1195 | |
Craig Mautner | ce5f3cb | 2013-04-22 08:58:54 -0700 | [diff] [blame] | 1196 | void reportActivityLaunchedLocked(boolean timeout, ActivityRecord r, |
| 1197 | long thisTime, long totalTime) { |
Dianne Hackborn | 6cfbb71 | 2014-09-17 12:47:35 -0700 | [diff] [blame] | 1198 | boolean changed = false; |
Craig Mautner | ce5f3cb | 2013-04-22 08:58:54 -0700 | [diff] [blame] | 1199 | for (int i = mWaitingActivityLaunched.size() - 1; i >= 0; i--) { |
Craig Mautner | c64f73e | 2013-04-24 16:44:56 -0700 | [diff] [blame] | 1200 | WaitResult w = mWaitingActivityLaunched.remove(i); |
Dianne Hackborn | 6cfbb71 | 2014-09-17 12:47:35 -0700 | [diff] [blame] | 1201 | if (w.who == null) { |
| 1202 | changed = true; |
| 1203 | w.timeout = timeout; |
| 1204 | if (r != null) { |
| 1205 | w.who = new ComponentName(r.info.packageName, r.info.name); |
| 1206 | } |
| 1207 | w.thisTime = thisTime; |
| 1208 | w.totalTime = totalTime; |
Chong Zhang | 5022da3 | 2016-06-21 16:31:37 -0700 | [diff] [blame] | 1209 | // Do not modify w.result. |
Craig Mautner | ce5f3cb | 2013-04-22 08:58:54 -0700 | [diff] [blame] | 1210 | } |
Craig Mautner | ce5f3cb | 2013-04-22 08:58:54 -0700 | [diff] [blame] | 1211 | } |
Dianne Hackborn | 6cfbb71 | 2014-09-17 12:47:35 -0700 | [diff] [blame] | 1212 | if (changed) { |
| 1213 | mService.notifyAll(); |
| 1214 | } |
Craig Mautner | ce5f3cb | 2013-04-22 08:58:54 -0700 | [diff] [blame] | 1215 | } |
| 1216 | |
Craig Mautner | 29219d9 | 2013-04-16 20:19:12 -0700 | [diff] [blame] | 1217 | ActivityRecord topRunningActivityLocked() { |
Bryce Lee | c961e0a | 2018-04-13 17:58:02 -0700 | [diff] [blame] | 1218 | return topRunningActivityLocked(false /* considerKeyguardState */); |
| 1219 | } |
| 1220 | |
| 1221 | /** |
| 1222 | * Returns the top running activity in the focused stack. In the case the focused stack has no |
| 1223 | * such activity, the next focusable stack on top of a display is returned. |
| 1224 | * @param considerKeyguardState Indicates whether the locked state should be considered. if |
| 1225 | * {@code true} and the keyguard is locked, only activities that |
| 1226 | * can be shown on top of the keyguard will be considered. |
| 1227 | * @return The top running activity. {@code null} if none is available. |
| 1228 | */ |
| 1229 | ActivityRecord topRunningActivityLocked(boolean considerKeyguardState) { |
Wale Ogunwale | d697cea | 2015-02-20 17:19:49 -0800 | [diff] [blame] | 1230 | final ActivityStack focusedStack = mFocusedStack; |
Filip Gruszczynski | 3e85ba2 | 2015-10-05 22:48:30 -0700 | [diff] [blame] | 1231 | ActivityRecord r = focusedStack.topRunningActivityLocked(); |
Bryce Lee | 8691896 | 2018-04-26 15:28:12 -0700 | [diff] [blame] | 1232 | if (r != null && isValidTopRunningActivity(r, considerKeyguardState)) { |
Craig Mautner | 1602ec2 | 2013-05-12 10:24:27 -0700 | [diff] [blame] | 1233 | return r; |
Craig Mautner | 29219d9 | 2013-04-16 20:19:12 -0700 | [diff] [blame] | 1234 | } |
Craig Mautner | 1602ec2 | 2013-05-12 10:24:27 -0700 | [diff] [blame] | 1235 | |
Andrii Kulian | 7318d63 | 2016-07-20 18:59:28 -0700 | [diff] [blame] | 1236 | // Look in other non-focused and non-home stacks. |
Andrii Kulian | 7d95df4 | 2017-02-15 10:11:48 -0800 | [diff] [blame] | 1237 | mWindowManager.getDisplaysInFocusOrder(mTmpOrderedDisplayIds); |
| 1238 | |
| 1239 | for (int i = mTmpOrderedDisplayIds.size() - 1; i >= 0; --i) { |
| 1240 | final int displayId = mTmpOrderedDisplayIds.get(i); |
Wale Ogunwale | a0f5b5e | 2017-10-11 09:37:23 -0700 | [diff] [blame] | 1241 | final ActivityDisplay display = mActivityDisplays.get(displayId); |
Bryce Lee | 4bc5ba3 | 2018-03-20 13:58:53 -0700 | [diff] [blame] | 1242 | |
| 1243 | // If WindowManagerService has encountered the display before we have, ignore as there |
| 1244 | // will be no stacks present and therefore no activities. |
| 1245 | if (display == null) { |
| 1246 | continue; |
| 1247 | } |
Bryce Lee | c961e0a | 2018-04-13 17:58:02 -0700 | [diff] [blame] | 1248 | |
| 1249 | // TODO: We probably want to consider the top fullscreen stack as we could have a pinned |
| 1250 | // stack on top. |
| 1251 | final ActivityStack topStack = display.getTopStack(); |
| 1252 | |
| 1253 | // Only consider focusable top stacks other than the current focused one. |
| 1254 | if (topStack == null || !topStack.isFocusable() || topStack == focusedStack) { |
| 1255 | continue; |
| 1256 | } |
| 1257 | |
| 1258 | final ActivityRecord topActivity = topStack.topRunningActivityLocked(); |
| 1259 | |
| 1260 | // Skip if no top activity. |
| 1261 | if (topActivity == null) { |
| 1262 | continue; |
| 1263 | } |
| 1264 | |
Bryce Lee | c961e0a | 2018-04-13 17:58:02 -0700 | [diff] [blame] | 1265 | |
| 1266 | // This activity can be considered the top running activity if we are not |
| 1267 | // considering the locked state, the keyguard isn't locked, or we can show when |
| 1268 | // locked. |
Bryce Lee | 8691896 | 2018-04-26 15:28:12 -0700 | [diff] [blame] | 1269 | if (isValidTopRunningActivity(topActivity, considerKeyguardState)) { |
Bryce Lee | c961e0a | 2018-04-13 17:58:02 -0700 | [diff] [blame] | 1270 | return topActivity; |
Craig Mautner | 29219d9 | 2013-04-16 20:19:12 -0700 | [diff] [blame] | 1271 | } |
| 1272 | } |
Bryce Lee | c961e0a | 2018-04-13 17:58:02 -0700 | [diff] [blame] | 1273 | |
Craig Mautner | 29219d9 | 2013-04-16 20:19:12 -0700 | [diff] [blame] | 1274 | return null; |
| 1275 | } |
| 1276 | |
Bryce Lee | 8691896 | 2018-04-26 15:28:12 -0700 | [diff] [blame] | 1277 | /** |
| 1278 | * Verifies an {@link ActivityRecord} can be the top activity based on keyguard state and |
| 1279 | * whether we are considering it. |
| 1280 | */ |
| 1281 | private boolean isValidTopRunningActivity(ActivityRecord record, |
| 1282 | boolean considerKeyguardState) { |
| 1283 | if (!considerKeyguardState) { |
| 1284 | return true; |
| 1285 | } |
| 1286 | |
| 1287 | final boolean keyguardLocked = getKeyguardController().isKeyguardLocked(); |
| 1288 | |
| 1289 | if (!keyguardLocked) { |
| 1290 | return true; |
| 1291 | } |
| 1292 | |
| 1293 | return record.canShowWhenLocked(); |
| 1294 | } |
| 1295 | |
Winson Chung | 61c9e5a | 2017-10-11 10:39:32 -0700 | [diff] [blame] | 1296 | @VisibleForTesting |
| 1297 | void getRunningTasks(int maxNum, List<RunningTaskInfo> list, |
| 1298 | @ActivityType int ignoreActivityType, @WindowingMode int ignoreWindowingMode, |
| 1299 | int callingUid, boolean allowed) { |
| 1300 | mRunningTasks.getTasks(maxNum, list, ignoreActivityType, ignoreWindowingMode, |
| 1301 | mActivityDisplays, callingUid, allowed); |
Craig Mautner | 20e7227 | 2013-04-01 13:45:53 -0700 | [diff] [blame] | 1302 | } |
| 1303 | |
Todd Kennedy | 7440f17 | 2015-12-09 14:31:22 -0800 | [diff] [blame] | 1304 | ActivityInfo resolveActivity(Intent intent, ResolveInfo rInfo, int startFlags, |
| 1305 | ProfilerInfo profilerInfo) { |
| 1306 | final ActivityInfo aInfo = rInfo != null ? rInfo.activityInfo : null; |
Craig Mautner | 23ac33b | 2013-04-01 16:26:35 -0700 | [diff] [blame] | 1307 | if (aInfo != null) { |
| 1308 | // Store the found target back into the intent, because now that |
| 1309 | // we have it we never want to do this again. For example, if the |
| 1310 | // user navigates back to this point in the history, we should |
| 1311 | // always restart the exact same activity. |
| 1312 | intent.setComponent(new ComponentName( |
| 1313 | aInfo.applicationInfo.packageName, aInfo.name)); |
| 1314 | |
| 1315 | // Don't debug things in the system process |
Man Cao | cfa78b2 | 2015-06-11 20:14:34 -0700 | [diff] [blame] | 1316 | if (!aInfo.processName.equals("system")) { |
| 1317 | if ((startFlags & ActivityManager.START_FLAG_DEBUG) != 0) { |
Chong Zhang | d25944e | 2016-06-09 16:15:27 -0700 | [diff] [blame] | 1318 | mService.setDebugApp(aInfo.processName, true, false); |
Craig Mautner | 23ac33b | 2013-04-01 16:26:35 -0700 | [diff] [blame] | 1319 | } |
Craig Mautner | 23ac33b | 2013-04-01 16:26:35 -0700 | [diff] [blame] | 1320 | |
Tamas Berghammer | df6cb28 | 2016-01-29 12:07:00 +0000 | [diff] [blame] | 1321 | if ((startFlags & ActivityManager.START_FLAG_NATIVE_DEBUGGING) != 0) { |
| 1322 | mService.setNativeDebuggingAppLocked(aInfo.applicationInfo, aInfo.processName); |
| 1323 | } |
| 1324 | |
Man Cao | cfa78b2 | 2015-06-11 20:14:34 -0700 | [diff] [blame] | 1325 | if ((startFlags & ActivityManager.START_FLAG_TRACK_ALLOCATION) != 0) { |
| 1326 | mService.setTrackAllocationApp(aInfo.applicationInfo, aInfo.processName); |
| 1327 | } |
| 1328 | |
| 1329 | if (profilerInfo != null) { |
Jeff Hao | 1b012d3 | 2014-08-20 10:35:34 -0700 | [diff] [blame] | 1330 | mService.setProfileApp(aInfo.applicationInfo, aInfo.processName, profilerInfo); |
Craig Mautner | 23ac33b | 2013-04-01 16:26:35 -0700 | [diff] [blame] | 1331 | } |
| 1332 | } |
Todd Kennedy | b3b43130 | 2017-03-20 16:05:48 -0700 | [diff] [blame] | 1333 | final String intentLaunchToken = intent.getLaunchToken(); |
| 1334 | if (aInfo.launchToken == null && intentLaunchToken != null) { |
| 1335 | aInfo.launchToken = intentLaunchToken; |
| 1336 | } |
Craig Mautner | 23ac33b | 2013-04-01 16:26:35 -0700 | [diff] [blame] | 1337 | } |
| 1338 | return aInfo; |
| 1339 | } |
| 1340 | |
Patrick Baumann | 7838027 | 2018-04-04 10:41:01 -0700 | [diff] [blame] | 1341 | ResolveInfo resolveIntent(Intent intent, String resolvedType, int userId, int flags, |
| 1342 | int filterCallingUid) { |
Todd Kennedy | 4d1de7d | 2017-02-23 10:32:18 -0800 | [diff] [blame] | 1343 | synchronized (mService) { |
Jorim Jaggi | ffe128d | 2017-11-30 13:54:36 +0100 | [diff] [blame] | 1344 | try { |
| 1345 | Trace.traceBegin(TRACE_TAG_ACTIVITY_MANAGER, "resolveIntent"); |
Patrick Baumann | 577d402 | 2018-01-31 16:55:10 +0000 | [diff] [blame] | 1346 | int modifiedFlags = flags |
| 1347 | | PackageManager.MATCH_DEFAULT_ONLY | ActivityManagerService.STOCK_PM_FLAGS; |
Patrick Baumann | 0da8537 | 2018-02-02 16:07:35 -0800 | [diff] [blame] | 1348 | if (intent.isWebIntent() |
Patrick Baumann | 577d402 | 2018-01-31 16:55:10 +0000 | [diff] [blame] | 1349 | || (intent.getFlags() & Intent.FLAG_ACTIVITY_MATCH_EXTERNAL) != 0) { |
| 1350 | modifiedFlags |= PackageManager.MATCH_INSTANT; |
| 1351 | } |
Jorim Jaggi | ffe128d | 2017-11-30 13:54:36 +0100 | [diff] [blame] | 1352 | |
Makoto Onuki | 1a34274 | 2018-04-26 14:56:59 -0700 | [diff] [blame] | 1353 | // In order to allow cross-profile lookup, we clear the calling identity here. |
| 1354 | // Note the binder identity won't affect the result, but filterCallingUid will. |
| 1355 | |
| 1356 | // Cross-user/profile call check are done at the entry points |
| 1357 | // (e.g. AMS.startActivityAsUser). |
| 1358 | final long token = Binder.clearCallingIdentity(); |
| 1359 | try { |
| 1360 | return mService.getPackageManagerInternalLocked().resolveIntent( |
| 1361 | intent, resolvedType, modifiedFlags, userId, true, filterCallingUid); |
| 1362 | } finally { |
| 1363 | Binder.restoreCallingIdentity(token); |
| 1364 | } |
Jorim Jaggi | ffe128d | 2017-11-30 13:54:36 +0100 | [diff] [blame] | 1365 | } finally { |
| 1366 | Trace.traceEnd(TRACE_TAG_ACTIVITY_MANAGER); |
| 1367 | } |
Todd Kennedy | 7440f17 | 2015-12-09 14:31:22 -0800 | [diff] [blame] | 1368 | } |
Todd Kennedy | 7440f17 | 2015-12-09 14:31:22 -0800 | [diff] [blame] | 1369 | } |
| 1370 | |
| 1371 | ActivityInfo resolveActivity(Intent intent, String resolvedType, int startFlags, |
Patrick Baumann | 7838027 | 2018-04-04 10:41:01 -0700 | [diff] [blame] | 1372 | ProfilerInfo profilerInfo, int userId, int filterCallingUid) { |
| 1373 | final ResolveInfo rInfo = resolveIntent(intent, resolvedType, userId, 0, filterCallingUid); |
Todd Kennedy | 7440f17 | 2015-12-09 14:31:22 -0800 | [diff] [blame] | 1374 | return resolveActivity(intent, rInfo, startFlags, profilerInfo); |
| 1375 | } |
| 1376 | |
Wale Ogunwale | 5658e4b | 2016-02-12 12:22:19 -0800 | [diff] [blame] | 1377 | final boolean realStartActivityLocked(ActivityRecord r, ProcessRecord app, |
| 1378 | boolean andResume, boolean checkConfig) throws RemoteException { |
| 1379 | |
| 1380 | if (!allPausedActivitiesComplete()) { |
| 1381 | // While there are activities pausing we skipping starting any new activities until |
| 1382 | // pauses are complete. NOTE: that we also do this for activities that are starting in |
| 1383 | // the paused state because they will first be resumed then paused on the client side. |
| 1384 | if (DEBUG_SWITCH || DEBUG_PAUSE || DEBUG_STATES) Slog.v(TAG_PAUSE, |
| 1385 | "realStartActivityLocked: Skipping start of r=" + r |
| 1386 | + " some activities pausing..."); |
| 1387 | return false; |
| 1388 | } |
Craig Mautner | 2420ead | 2013-04-01 17:13:20 -0700 | [diff] [blame] | 1389 | |
Bryce Lee | af691c0 | 2017-03-20 14:20:22 -0700 | [diff] [blame] | 1390 | final TaskRecord task = r.getTask(); |
Andrii Kulian | 02b7a83 | 2016-10-06 23:11:56 -0700 | [diff] [blame] | 1391 | final ActivityStack stack = task.getStack(); |
chaviw | 59b9885 | 2017-06-13 12:05:44 -0700 | [diff] [blame] | 1392 | |
| 1393 | beginDeferResume(); |
| 1394 | |
Craig Mautner | 2420ead | 2013-04-01 17:13:20 -0700 | [diff] [blame] | 1395 | try { |
chaviw | 59b9885 | 2017-06-13 12:05:44 -0700 | [diff] [blame] | 1396 | r.startFreezingScreenLocked(app, 0); |
| 1397 | |
| 1398 | // schedule launch ticks to collect information about slow apps. |
| 1399 | r.startLaunchTickingLocked(); |
| 1400 | |
Dianne Hackborn | 68a0633 | 2017-11-15 17:54:18 -0800 | [diff] [blame] | 1401 | r.setProcess(app); |
chaviw | 59b9885 | 2017-06-13 12:05:44 -0700 | [diff] [blame] | 1402 | |
Bryce Lee | 459c062 | 2018-03-19 11:04:01 -0700 | [diff] [blame] | 1403 | if (getKeyguardController().isKeyguardLocked()) { |
Jorim Jaggi | 838c245 | 2017-08-28 15:44:43 +0200 | [diff] [blame] | 1404 | r.notifyUnknownVisibilityLaunched(); |
| 1405 | } |
| 1406 | |
chaviw | 59b9885 | 2017-06-13 12:05:44 -0700 | [diff] [blame] | 1407 | // Have the window manager re-evaluate the orientation of the screen based on the new |
| 1408 | // activity order. Note that as a result of this, it can call back into the activity |
| 1409 | // manager with a new orientation. We don't care about that, because the activity is |
| 1410 | // not currently running so we are just restarting it anyway. |
| 1411 | if (checkConfig) { |
chaviw | 59b9885 | 2017-06-13 12:05:44 -0700 | [diff] [blame] | 1412 | // Deferring resume here because we're going to launch new activity shortly. |
| 1413 | // We don't want to perform a redundant launch of the same record while ensuring |
| 1414 | // configurations and trying to resume top activity of focused stack. |
Andrii Kulian | f4479ee | 2018-05-23 17:52:48 -0700 | [diff] [blame] | 1415 | ensureVisibilityAndConfig(r, r.getDisplayId(), |
| 1416 | false /* markFrozenIfConfigChanged */, true /* deferResume */); |
Craig Mautner | 2420ead | 2013-04-01 17:13:20 -0700 | [diff] [blame] | 1417 | } |
chaviw | 59b9885 | 2017-06-13 12:05:44 -0700 | [diff] [blame] | 1418 | |
| 1419 | if (r.getStack().checkKeyguardVisibility(r, true /* shouldBeVisible */, |
| 1420 | true /* isTop */)) { |
| 1421 | // We only set the visibility to true if the activity is allowed to be visible |
| 1422 | // based on |
| 1423 | // keyguard state. This avoids setting this into motion in window manager that is |
| 1424 | // later cancelled due to later calls to ensure visible activities that set |
| 1425 | // visibility back to false. |
| 1426 | r.setVisibility(true); |
Craig Mautner | 2420ead | 2013-04-01 17:13:20 -0700 | [diff] [blame] | 1427 | } |
chaviw | 59b9885 | 2017-06-13 12:05:44 -0700 | [diff] [blame] | 1428 | |
chaviw | 59b9885 | 2017-06-13 12:05:44 -0700 | [diff] [blame] | 1429 | final int applicationInfoUid = |
| 1430 | (r.info.applicationInfo != null) ? r.info.applicationInfo.uid : -1; |
| 1431 | if ((r.userId != app.userId) || (r.appInfo.uid != applicationInfoUid)) { |
| 1432 | Slog.wtf(TAG, |
| 1433 | "User ID for activity changing for " + r |
| 1434 | + " appInfo.uid=" + r.appInfo.uid |
| 1435 | + " info.ai.uid=" + applicationInfoUid |
| 1436 | + " old=" + r.app + " new=" + app); |
| 1437 | } |
| 1438 | |
| 1439 | app.waitingToKill = null; |
| 1440 | r.launchCount++; |
| 1441 | r.lastLaunchTime = SystemClock.uptimeMillis(); |
| 1442 | |
| 1443 | if (DEBUG_ALL) Slog.v(TAG, "Launching: " + r); |
| 1444 | |
| 1445 | int idx = app.activities.indexOf(r); |
| 1446 | if (idx < 0) { |
| 1447 | app.activities.add(r); |
| 1448 | } |
| 1449 | mService.updateLruProcessLocked(app, true, null); |
| 1450 | mService.updateOomAdjLocked(); |
| 1451 | |
Bryce Lee | 2b8e037 | 2018-04-05 17:01:37 -0700 | [diff] [blame] | 1452 | final LockTaskController lockTaskController = mService.getLockTaskController(); |
Charles He | ff9b4dff | 2017-09-22 10:18:37 +0100 | [diff] [blame] | 1453 | if (task.mLockTaskAuth == LOCK_TASK_AUTH_LAUNCHABLE |
| 1454 | || task.mLockTaskAuth == LOCK_TASK_AUTH_LAUNCHABLE_PRIV |
| 1455 | || (task.mLockTaskAuth == LOCK_TASK_AUTH_WHITELISTED |
Bryce Lee | 2b8e037 | 2018-04-05 17:01:37 -0700 | [diff] [blame] | 1456 | && lockTaskController.getLockTaskModeState() |
| 1457 | == LOCK_TASK_MODE_LOCKED)) { |
| 1458 | lockTaskController.startLockTaskMode(task, false, 0 /* blank UID */); |
chaviw | 59b9885 | 2017-06-13 12:05:44 -0700 | [diff] [blame] | 1459 | } |
| 1460 | |
| 1461 | try { |
| 1462 | if (app.thread == null) { |
| 1463 | throw new RemoteException(); |
| 1464 | } |
| 1465 | List<ResultInfo> results = null; |
| 1466 | List<ReferrerIntent> newIntents = null; |
| 1467 | if (andResume) { |
| 1468 | // We don't need to deliver new intents and/or set results if activity is going |
| 1469 | // to pause immediately after launch. |
| 1470 | results = r.results; |
| 1471 | newIntents = r.newIntents; |
| 1472 | } |
| 1473 | if (DEBUG_SWITCH) Slog.v(TAG_SWITCH, |
| 1474 | "Launching: " + r + " icicle=" + r.icicle + " with results=" + results |
| 1475 | + " newIntents=" + newIntents + " andResume=" + andResume); |
| 1476 | EventLog.writeEvent(EventLogTags.AM_RESTART_ACTIVITY, r.userId, |
| 1477 | System.identityHashCode(r), task.taskId, r.shortComponentName); |
Wale Ogunwale | 6fbde9f | 2017-08-24 07:24:12 -0700 | [diff] [blame] | 1478 | if (r.isActivityTypeHome()) { |
chaviw | 59b9885 | 2017-06-13 12:05:44 -0700 | [diff] [blame] | 1479 | // Home process is the root process of the task. |
| 1480 | mService.mHomeProcess = task.mActivities.get(0).app; |
| 1481 | } |
| 1482 | mService.notifyPackageUse(r.intent.getComponent().getPackageName(), |
| 1483 | PackageManager.NOTIFY_PACKAGE_USE_ACTIVITY); |
| 1484 | r.sleeping = false; |
| 1485 | r.forceNewConfig = false; |
Alan Viverette | b6a2573 | 2017-11-21 14:49:24 -0500 | [diff] [blame] | 1486 | mService.getAppWarningsLocked().onStartActivity(r); |
chaviw | 59b9885 | 2017-06-13 12:05:44 -0700 | [diff] [blame] | 1487 | mService.showAskCompatModeDialogLocked(r); |
| 1488 | r.compat = mService.compatibilityInfoForPackageLocked(r.info.applicationInfo); |
| 1489 | ProfilerInfo profilerInfo = null; |
| 1490 | if (mService.mProfileApp != null && mService.mProfileApp.equals(app.processName)) { |
| 1491 | if (mService.mProfileProc == null || mService.mProfileProc == app) { |
| 1492 | mService.mProfileProc = app; |
Andreas Gampe | 2b073a0 | 2017-06-22 17:28:57 -0700 | [diff] [blame] | 1493 | ProfilerInfo profilerInfoSvc = mService.mProfilerInfo; |
| 1494 | if (profilerInfoSvc != null && profilerInfoSvc.profileFile != null) { |
| 1495 | if (profilerInfoSvc.profileFd != null) { |
chaviw | 59b9885 | 2017-06-13 12:05:44 -0700 | [diff] [blame] | 1496 | try { |
Andreas Gampe | 2b073a0 | 2017-06-22 17:28:57 -0700 | [diff] [blame] | 1497 | profilerInfoSvc.profileFd = profilerInfoSvc.profileFd.dup(); |
chaviw | 59b9885 | 2017-06-13 12:05:44 -0700 | [diff] [blame] | 1498 | } catch (IOException e) { |
Andreas Gampe | 2b073a0 | 2017-06-22 17:28:57 -0700 | [diff] [blame] | 1499 | profilerInfoSvc.closeFd(); |
Craig Mautner | 2568c3a | 2015-03-26 14:22:34 -0700 | [diff] [blame] | 1500 | } |
| 1501 | } |
chaviw | 59b9885 | 2017-06-13 12:05:44 -0700 | [diff] [blame] | 1502 | |
Andreas Gampe | 2b073a0 | 2017-06-22 17:28:57 -0700 | [diff] [blame] | 1503 | profilerInfo = new ProfilerInfo(profilerInfoSvc); |
Craig Mautner | 2420ead | 2013-04-01 17:13:20 -0700 | [diff] [blame] | 1504 | } |
Craig Mautner | 2420ead | 2013-04-01 17:13:20 -0700 | [diff] [blame] | 1505 | } |
| 1506 | } |
Adam Powell | cfbe9be | 2013-11-06 14:58:58 -0800 | [diff] [blame] | 1507 | |
chaviw | 59b9885 | 2017-06-13 12:05:44 -0700 | [diff] [blame] | 1508 | app.hasShownUi = true; |
| 1509 | app.pendingUiClean = true; |
| 1510 | app.forceProcessStateUpTo(mService.mTopProcessState); |
| 1511 | // Because we could be starting an Activity in the system process this may not go |
| 1512 | // across a Binder interface which would create a new Configuration. Consequently |
| 1513 | // we have to always create a new Configuration here. |
Bryce Lee | a163b76 | 2017-01-24 11:05:01 -0800 | [diff] [blame] | 1514 | |
chaviw | 59b9885 | 2017-06-13 12:05:44 -0700 | [diff] [blame] | 1515 | final MergedConfiguration mergedConfiguration = new MergedConfiguration( |
| 1516 | mService.getGlobalConfiguration(), r.getMergedOverrideConfiguration()); |
| 1517 | r.setLastReportedConfiguration(mergedConfiguration); |
Bryce Lee | a163b76 | 2017-01-24 11:05:01 -0800 | [diff] [blame] | 1518 | |
chaviw | 59b9885 | 2017-06-13 12:05:44 -0700 | [diff] [blame] | 1519 | logIfTransactionTooLarge(r.intent, r.icicle); |
Andrii Kulian | 88e05cb | 2017-12-05 17:21:10 -0800 | [diff] [blame] | 1520 | |
| 1521 | |
| 1522 | // Create activity launch transaction. |
Andrii Kulian | 9c5ea9c | 2017-12-07 09:31:01 -0800 | [diff] [blame] | 1523 | final ClientTransaction clientTransaction = ClientTransaction.obtain(app.thread, |
Andrii Kulian | 88e05cb | 2017-12-05 17:21:10 -0800 | [diff] [blame] | 1524 | r.appToken); |
Andrii Kulian | 9c5ea9c | 2017-12-07 09:31:01 -0800 | [diff] [blame] | 1525 | clientTransaction.addCallback(LaunchActivityItem.obtain(new Intent(r.intent), |
chaviw | 59b9885 | 2017-06-13 12:05:44 -0700 | [diff] [blame] | 1526 | System.identityHashCode(r), r.info, |
| 1527 | // TODO: Have this take the merged configuration instead of separate global |
| 1528 | // and override configs. |
| 1529 | mergedConfiguration.getGlobalConfiguration(), |
| 1530 | mergedConfiguration.getOverrideConfiguration(), r.compat, |
| 1531 | r.launchedFromPackage, task.voiceInteractor, app.repProcState, r.icicle, |
Andrii Kulian | 88e05cb | 2017-12-05 17:21:10 -0800 | [diff] [blame] | 1532 | r.persistentState, results, newIntents, mService.isNextTransitionForward(), |
| 1533 | profilerInfo)); |
| 1534 | |
| 1535 | // Set desired final state. |
| 1536 | final ActivityLifecycleItem lifecycleItem; |
| 1537 | if (andResume) { |
Bryce Lee | 1d0d514 | 2018-04-12 10:35:07 -0700 | [diff] [blame] | 1538 | lifecycleItem = ResumeActivityItem.obtain(mService.isNextTransitionForward()); |
Andrii Kulian | 88e05cb | 2017-12-05 17:21:10 -0800 | [diff] [blame] | 1539 | } else { |
Bryce Lee | 1d0d514 | 2018-04-12 10:35:07 -0700 | [diff] [blame] | 1540 | lifecycleItem = PauseActivityItem.obtain(); |
Andrii Kulian | 88e05cb | 2017-12-05 17:21:10 -0800 | [diff] [blame] | 1541 | } |
| 1542 | clientTransaction.setLifecycleStateRequest(lifecycleItem); |
| 1543 | |
| 1544 | // Schedule transaction. |
Bryce Lee | b0f993f | 2018-03-02 15:38:01 -0800 | [diff] [blame] | 1545 | mService.getLifecycleManager().scheduleTransaction(clientTransaction); |
Andrii Kulian | 88e05cb | 2017-12-05 17:21:10 -0800 | [diff] [blame] | 1546 | |
Craig Mautner | 2420ead | 2013-04-01 17:13:20 -0700 | [diff] [blame] | 1547 | |
Dianne Hackborn | c8e4fad | 2018-05-04 11:31:09 -0700 | [diff] [blame] | 1548 | if ((app.info.privateFlags & ApplicationInfo.PRIVATE_FLAG_CANT_SAVE_STATE) != 0 |
| 1549 | && mService.mHasHeavyWeightFeature) { |
chaviw | 59b9885 | 2017-06-13 12:05:44 -0700 | [diff] [blame] | 1550 | // This may be a heavy-weight process! Note that the package |
| 1551 | // manager will ensure that only activity can run in the main |
| 1552 | // process of the .apk, which is the only thing that will be |
| 1553 | // considered heavy-weight. |
| 1554 | if (app.processName.equals(app.info.packageName)) { |
| 1555 | if (mService.mHeavyWeightProcess != null |
| 1556 | && mService.mHeavyWeightProcess != app) { |
| 1557 | Slog.w(TAG, "Starting new heavy weight process " + app |
| 1558 | + " when already running " |
| 1559 | + mService.mHeavyWeightProcess); |
| 1560 | } |
| 1561 | mService.mHeavyWeightProcess = app; |
| 1562 | Message msg = mService.mHandler.obtainMessage( |
| 1563 | ActivityManagerService.POST_HEAVY_NOTIFICATION_MSG); |
| 1564 | msg.obj = r; |
| 1565 | mService.mHandler.sendMessage(msg); |
Craig Mautner | 2420ead | 2013-04-01 17:13:20 -0700 | [diff] [blame] | 1566 | } |
Craig Mautner | 2420ead | 2013-04-01 17:13:20 -0700 | [diff] [blame] | 1567 | } |
Craig Mautner | 2420ead | 2013-04-01 17:13:20 -0700 | [diff] [blame] | 1568 | |
chaviw | 59b9885 | 2017-06-13 12:05:44 -0700 | [diff] [blame] | 1569 | } catch (RemoteException e) { |
| 1570 | if (r.launchFailed) { |
| 1571 | // This is the second time we failed -- finish activity |
| 1572 | // and give up. |
| 1573 | Slog.e(TAG, "Second failure launching " |
| 1574 | + r.intent.getComponent().flattenToShortString() |
| 1575 | + ", giving up", e); |
| 1576 | mService.appDiedLocked(app); |
| 1577 | stack.requestFinishActivityLocked(r.appToken, Activity.RESULT_CANCELED, null, |
| 1578 | "2nd-crash", false); |
| 1579 | return false; |
| 1580 | } |
Craig Mautner | 2420ead | 2013-04-01 17:13:20 -0700 | [diff] [blame] | 1581 | |
chaviw | 59b9885 | 2017-06-13 12:05:44 -0700 | [diff] [blame] | 1582 | // This is the first time we failed -- restart process and |
| 1583 | // retry. |
| 1584 | r.launchFailed = true; |
| 1585 | app.activities.remove(r); |
| 1586 | throw e; |
| 1587 | } |
| 1588 | } finally { |
| 1589 | endDeferResume(); |
Craig Mautner | 2420ead | 2013-04-01 17:13:20 -0700 | [diff] [blame] | 1590 | } |
| 1591 | |
| 1592 | r.launchFailed = false; |
| 1593 | if (stack.updateLRUListLocked(r)) { |
Filip Gruszczynski | 49b80af | 2015-09-24 09:04:26 -0700 | [diff] [blame] | 1594 | Slog.w(TAG, "Activity " + r + " being launched, but already in LRU list"); |
Craig Mautner | 2420ead | 2013-04-01 17:13:20 -0700 | [diff] [blame] | 1595 | } |
| 1596 | |
Andrii Kulian | b372da6 | 2018-01-18 10:46:24 -0800 | [diff] [blame] | 1597 | // TODO(lifecycler): Resume or pause requests are done as part of launch transaction, |
| 1598 | // so updating the state should be done accordingly. |
chaviw | 59b9885 | 2017-06-13 12:05:44 -0700 | [diff] [blame] | 1599 | if (andResume && readyToResume()) { |
Craig Mautner | 2420ead | 2013-04-01 17:13:20 -0700 | [diff] [blame] | 1600 | // As part of the process of launching, ActivityThread also performs |
| 1601 | // a resume. |
| 1602 | stack.minimalResumeActivityLocked(r); |
| 1603 | } else { |
Wale Ogunwale | d046a01 | 2015-12-24 13:05:59 -0800 | [diff] [blame] | 1604 | // 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] | 1605 | // 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] | 1606 | // current icicle and other state. |
Wale Ogunwale | 0fc365c | 2015-05-25 19:35:42 -0700 | [diff] [blame] | 1607 | if (DEBUG_STATES) Slog.v(TAG_STATES, |
Wale Ogunwale | d046a01 | 2015-12-24 13:05:59 -0800 | [diff] [blame] | 1608 | "Moving to PAUSED: " + r + " (starting in paused state)"); |
Bryce Lee | 7ace395 | 2018-02-16 14:34:32 -0800 | [diff] [blame] | 1609 | r.setState(PAUSED, "realStartActivityLocked"); |
Craig Mautner | 2420ead | 2013-04-01 17:13:20 -0700 | [diff] [blame] | 1610 | } |
| 1611 | |
| 1612 | // Launch the new version setup screen if needed. We do this -after- |
| 1613 | // launching the initial activity (that is, home), so that it can have |
| 1614 | // a chance to initialize itself while in the background, making the |
| 1615 | // switch back to it faster and look better. |
Wale Ogunwale | 1e60e0c | 2015-10-28 13:36:10 -0700 | [diff] [blame] | 1616 | if (isFocusedStack(stack)) { |
Bryce Lee | d3624e1 | 2017-11-30 08:51:45 -0800 | [diff] [blame] | 1617 | mService.getActivityStartController().startSetupActivity(); |
Craig Mautner | 2420ead | 2013-04-01 17:13:20 -0700 | [diff] [blame] | 1618 | } |
| 1619 | |
Dianne Hackborn | 465fa39 | 2014-09-14 14:21:18 -0700 | [diff] [blame] | 1620 | // Update any services we are bound to that might care about whether |
| 1621 | // their client may have activities. |
Wale Ogunwale | d6ac762 | 2016-05-26 09:02:25 -0700 | [diff] [blame] | 1622 | if (r.app != null) { |
| 1623 | mService.mServices.updateServiceConnectionActivitiesLocked(r.app); |
| 1624 | } |
Dianne Hackborn | 465fa39 | 2014-09-14 14:21:18 -0700 | [diff] [blame] | 1625 | |
Craig Mautner | 2420ead | 2013-04-01 17:13:20 -0700 | [diff] [blame] | 1626 | return true; |
| 1627 | } |
| 1628 | |
Andrii Kulian | f4479ee | 2018-05-23 17:52:48 -0700 | [diff] [blame] | 1629 | /** |
| 1630 | * Ensure all activities visibility, update orientation and configuration. |
Andrii Kulian | a39ae3e | 2018-05-31 12:43:54 -0700 | [diff] [blame] | 1631 | * |
| 1632 | * @param starting The currently starting activity or {@code null} if there is none. |
| 1633 | * @param displayId The id of the display where operation is executed. |
| 1634 | * @param markFrozenIfConfigChanged Whether to set {@link ActivityRecord#frozenBeforeDestroy} to |
| 1635 | * {@code true} if config changed. |
| 1636 | * @param deferResume Whether to defer resume while updating config. |
Andrii Kulian | 2f0d73c | 2018-06-15 14:32:04 -0700 | [diff] [blame] | 1637 | * @return 'true' if starting activity was kept or wasn't provided, 'false' if it was relaunched |
| 1638 | * because of configuration update. |
Andrii Kulian | f4479ee | 2018-05-23 17:52:48 -0700 | [diff] [blame] | 1639 | */ |
Andrii Kulian | a39ae3e | 2018-05-31 12:43:54 -0700 | [diff] [blame] | 1640 | boolean ensureVisibilityAndConfig(ActivityRecord starting, int displayId, |
Andrii Kulian | f4479ee | 2018-05-23 17:52:48 -0700 | [diff] [blame] | 1641 | boolean markFrozenIfConfigChanged, boolean deferResume) { |
| 1642 | // First ensure visibility without updating the config just yet. We need this to know what |
| 1643 | // activities are affecting configuration now. |
Andrii Kulian | a39ae3e | 2018-05-31 12:43:54 -0700 | [diff] [blame] | 1644 | // Passing null here for 'starting' param value, so that visibility of actual starting |
| 1645 | // activity will be properly updated. |
Andrii Kulian | f4479ee | 2018-05-23 17:52:48 -0700 | [diff] [blame] | 1646 | ensureActivitiesVisibleLocked(null /* starting */, 0 /* configChanges */, |
Andrii Kulian | a39ae3e | 2018-05-31 12:43:54 -0700 | [diff] [blame] | 1647 | false /* preserveWindows */, false /* notifyClients */); |
Andrii Kulian | f4479ee | 2018-05-23 17:52:48 -0700 | [diff] [blame] | 1648 | |
Andrii Kulian | 2f0d73c | 2018-06-15 14:32:04 -0700 | [diff] [blame] | 1649 | if (displayId == INVALID_DISPLAY) { |
| 1650 | // The caller didn't provide a valid display id, skip updating config. |
| 1651 | return true; |
| 1652 | } |
| 1653 | |
Andrii Kulian | f4479ee | 2018-05-23 17:52:48 -0700 | [diff] [blame] | 1654 | // Force-update the orientation from the WindowManager, since we need the true configuration |
| 1655 | // to send to the client now. |
| 1656 | final Configuration config = mWindowManager.updateOrientationFromAppTokens( |
| 1657 | getDisplayOverrideConfiguration(displayId), |
Andrii Kulian | a39ae3e | 2018-05-31 12:43:54 -0700 | [diff] [blame] | 1658 | starting != null && starting.mayFreezeScreenLocked(starting.app) |
| 1659 | ? starting.appToken : null, |
Andrii Kulian | 6cdcfe4 | 2018-05-23 17:59:43 -0700 | [diff] [blame] | 1660 | displayId, true /* forceUpdate */); |
Andrii Kulian | a39ae3e | 2018-05-31 12:43:54 -0700 | [diff] [blame] | 1661 | if (starting != null && markFrozenIfConfigChanged && config != null) { |
| 1662 | starting.frozenBeforeDestroy = true; |
Andrii Kulian | f4479ee | 2018-05-23 17:52:48 -0700 | [diff] [blame] | 1663 | } |
| 1664 | |
| 1665 | // Update the configuration of the activities on the display. |
Andrii Kulian | a39ae3e | 2018-05-31 12:43:54 -0700 | [diff] [blame] | 1666 | return mService.updateDisplayOverrideConfigurationLocked(config, starting, deferResume, |
| 1667 | displayId); |
Andrii Kulian | f4479ee | 2018-05-23 17:52:48 -0700 | [diff] [blame] | 1668 | } |
| 1669 | |
Sudheer Shanka | fab200f | 2017-05-17 20:41:53 -0700 | [diff] [blame] | 1670 | private void logIfTransactionTooLarge(Intent intent, Bundle icicle) { |
| 1671 | int extrasSize = 0; |
| 1672 | if (intent != null) { |
| 1673 | final Bundle extras = intent.getExtras(); |
| 1674 | if (extras != null) { |
| 1675 | extrasSize = extras.getSize(); |
| 1676 | } |
| 1677 | } |
| 1678 | int icicleSize = (icicle == null ? 0 : icicle.getSize()); |
| 1679 | if (extrasSize + icicleSize > 200000) { |
| 1680 | Slog.e(TAG, "Transaction too large, intent: " + intent + ", extras size: " + extrasSize |
| 1681 | + ", icicle size: " + icicleSize); |
| 1682 | } |
| 1683 | } |
| 1684 | |
Craig Mautner | e79d4268 | 2013-04-01 19:01:53 -0700 | [diff] [blame] | 1685 | void startSpecificActivityLocked(ActivityRecord r, |
George Mount | 2c92c97 | 2014-03-20 09:38:23 -0700 | [diff] [blame] | 1686 | boolean andResume, boolean checkConfig) { |
Craig Mautner | e79d4268 | 2013-04-01 19:01:53 -0700 | [diff] [blame] | 1687 | // Is this activity's application already running? |
| 1688 | ProcessRecord app = mService.getProcessRecordLocked(r.processName, |
Dianne Hackborn | 3bc8f78d | 2013-09-19 13:34:35 -0700 | [diff] [blame] | 1689 | r.info.applicationInfo.uid, true); |
Craig Mautner | e79d4268 | 2013-04-01 19:01:53 -0700 | [diff] [blame] | 1690 | |
Jorim Jaggi | de8305a | 2018-05-15 12:06:35 -0700 | [diff] [blame] | 1691 | getLaunchTimeTracker().setLaunchTime(r); |
Craig Mautner | e79d4268 | 2013-04-01 19:01:53 -0700 | [diff] [blame] | 1692 | |
| 1693 | if (app != null && app.thread != null) { |
| 1694 | try { |
Dianne Hackborn | 237cefb | 2013-10-22 18:45:27 -0700 | [diff] [blame] | 1695 | if ((r.info.flags&ActivityInfo.FLAG_MULTIPROCESS) == 0 |
| 1696 | || !"android".equals(r.info.packageName)) { |
| 1697 | // Don't add this if it is a platform component that is marked |
| 1698 | // to run in multiple processes, because this is actually |
| 1699 | // part of the framework so doesn't make sense to track as a |
| 1700 | // separate apk in the process. |
Patrick Baumann | c2def58 | 2018-04-04 12:14:15 -0700 | [diff] [blame] | 1701 | app.addPackage(r.info.packageName, r.info.applicationInfo.longVersionCode, |
Dianne Hackborn | f7097a5 | 2014-05-13 09:56:14 -0700 | [diff] [blame] | 1702 | mService.mProcessStats); |
Dianne Hackborn | 237cefb | 2013-10-22 18:45:27 -0700 | [diff] [blame] | 1703 | } |
George Mount | 2c92c97 | 2014-03-20 09:38:23 -0700 | [diff] [blame] | 1704 | realStartActivityLocked(r, app, andResume, checkConfig); |
Craig Mautner | e79d4268 | 2013-04-01 19:01:53 -0700 | [diff] [blame] | 1705 | return; |
| 1706 | } catch (RemoteException e) { |
| 1707 | Slog.w(TAG, "Exception when starting activity " |
| 1708 | + r.intent.getComponent().flattenToShortString(), e); |
| 1709 | } |
| 1710 | |
| 1711 | // If a dead object exception was thrown -- fall through to |
| 1712 | // restart the application. |
| 1713 | } |
| 1714 | |
| 1715 | mService.startProcessLocked(r.processName, r.info.applicationInfo, true, 0, |
Dianne Hackborn | 3bc8f78d | 2013-09-19 13:34:35 -0700 | [diff] [blame] | 1716 | "activity", r.intent.getComponent(), false, false, true); |
Craig Mautner | e79d4268 | 2013-04-01 19:01:53 -0700 | [diff] [blame] | 1717 | } |
| 1718 | |
Bryce Lee | d3624e1 | 2017-11-30 08:51:45 -0800 | [diff] [blame] | 1719 | void sendPowerHintForLaunchStartIfNeeded(boolean forceSend, ActivityRecord targetActivity) { |
| 1720 | boolean sendHint = forceSend; |
| 1721 | |
| 1722 | if (!sendHint) { |
| 1723 | // If not forced, send power hint when the activity's process is different than the |
| 1724 | // current resumed activity. |
| 1725 | final ActivityRecord resumedActivity = getResumedActivityLocked(); |
| 1726 | sendHint = resumedActivity == null |
| 1727 | || resumedActivity.app == null |
| 1728 | || !resumedActivity.app.equals(targetActivity.app); |
| 1729 | } |
| 1730 | |
| 1731 | if (sendHint && mService.mLocalPowerManager != null) { |
| 1732 | mService.mLocalPowerManager.powerHint(PowerHint.LAUNCH, 1); |
| 1733 | mPowerHintSent = true; |
| 1734 | } |
| 1735 | } |
| 1736 | |
| 1737 | void sendPowerHintForLaunchEndIfNeeded() { |
| 1738 | // Trigger launch power hint if activity is launched |
| 1739 | if (mPowerHintSent && mService.mLocalPowerManager != null) { |
| 1740 | mService.mLocalPowerManager.powerHint(PowerHint.LAUNCH, 0); |
| 1741 | mPowerHintSent = false; |
| 1742 | } |
| 1743 | } |
| 1744 | |
Filip Gruszczynski | 07a0e49 | 2015-12-17 14:16:38 -0800 | [diff] [blame] | 1745 | boolean checkStartAnyActivityPermission(Intent intent, ActivityInfo aInfo, |
Filip Gruszczynski | dc39490 | 2015-12-14 10:20:22 -0800 | [diff] [blame] | 1746 | String resultWho, int requestCode, int callingPid, int callingUid, |
Winson Chung | c9804e7 | 2018-05-15 11:01:44 -0700 | [diff] [blame] | 1747 | String callingPackage, boolean ignoreTargetSecurity, boolean launchingInTask, |
| 1748 | ProcessRecord callerApp, ActivityRecord resultRecord, ActivityStack resultStack) { |
| 1749 | final boolean isCallerRecents = mService.getRecentTasks() != null && |
| 1750 | mService.getRecentTasks().isCallerRecents(callingUid); |
Filip Gruszczynski | dc39490 | 2015-12-14 10:20:22 -0800 | [diff] [blame] | 1751 | final int startAnyPerm = mService.checkPermission(START_ANY_ACTIVITY, callingPid, |
| 1752 | callingUid); |
Winson Chung | c9804e7 | 2018-05-15 11:01:44 -0700 | [diff] [blame] | 1753 | if (startAnyPerm == PERMISSION_GRANTED || (isCallerRecents && launchingInTask)) { |
| 1754 | // If the caller has START_ANY_ACTIVITY, ignore all checks below. In addition, if the |
| 1755 | // caller is the recents component and we are specifically starting an activity in an |
| 1756 | // existing task, then also allow the activity to be fully relaunched. |
Filip Gruszczynski | dc39490 | 2015-12-14 10:20:22 -0800 | [diff] [blame] | 1757 | return true; |
| 1758 | } |
| 1759 | final int componentRestriction = getComponentRestrictionForCallingPackage( |
| 1760 | aInfo, callingPackage, callingPid, callingUid, ignoreTargetSecurity); |
| 1761 | final int actionRestriction = getActionRestrictionForCallingPackage( |
| 1762 | intent.getAction(), callingPackage, callingPid, callingUid); |
| 1763 | if (componentRestriction == ACTIVITY_RESTRICTION_PERMISSION |
| 1764 | || actionRestriction == ACTIVITY_RESTRICTION_PERMISSION) { |
| 1765 | if (resultRecord != null) { |
| 1766 | resultStack.sendActivityResultLocked(-1, |
| 1767 | resultRecord, resultWho, requestCode, |
| 1768 | Activity.RESULT_CANCELED, null); |
| 1769 | } |
| 1770 | final String msg; |
| 1771 | if (actionRestriction == ACTIVITY_RESTRICTION_PERMISSION) { |
| 1772 | msg = "Permission Denial: starting " + intent.toString() |
| 1773 | + " from " + callerApp + " (pid=" + callingPid |
| 1774 | + ", uid=" + callingUid + ")" + " with revoked permission " |
| 1775 | + ACTION_TO_RUNTIME_PERMISSION.get(intent.getAction()); |
| 1776 | } else if (!aInfo.exported) { |
| 1777 | msg = "Permission Denial: starting " + intent.toString() |
| 1778 | + " from " + callerApp + " (pid=" + callingPid |
| 1779 | + ", uid=" + callingUid + ")" |
| 1780 | + " not exported from uid " + aInfo.applicationInfo.uid; |
| 1781 | } else { |
| 1782 | msg = "Permission Denial: starting " + intent.toString() |
| 1783 | + " from " + callerApp + " (pid=" + callingPid |
| 1784 | + ", uid=" + callingUid + ")" |
| 1785 | + " requires " + aInfo.permission; |
| 1786 | } |
| 1787 | Slog.w(TAG, msg); |
| 1788 | throw new SecurityException(msg); |
| 1789 | } |
| 1790 | |
| 1791 | if (actionRestriction == ACTIVITY_RESTRICTION_APPOP) { |
| 1792 | final String message = "Appop Denial: starting " + intent.toString() |
| 1793 | + " from " + callerApp + " (pid=" + callingPid |
| 1794 | + ", uid=" + callingUid + ")" |
| 1795 | + " requires " + AppOpsManager.permissionToOp( |
| 1796 | ACTION_TO_RUNTIME_PERMISSION.get(intent.getAction())); |
| 1797 | Slog.w(TAG, message); |
| 1798 | return false; |
| 1799 | } else if (componentRestriction == ACTIVITY_RESTRICTION_APPOP) { |
| 1800 | final String message = "Appop Denial: starting " + intent.toString() |
| 1801 | + " from " + callerApp + " (pid=" + callingPid |
| 1802 | + ", uid=" + callingUid + ")" |
| 1803 | + " requires appop " + AppOpsManager.permissionToOp(aInfo.permission); |
| 1804 | Slog.w(TAG, message); |
| 1805 | return false; |
| 1806 | } |
Jorim Jaggi | 2adba07 | 2016-03-03 13:43:39 +0100 | [diff] [blame] | 1807 | |
Filip Gruszczynski | dc39490 | 2015-12-14 10:20:22 -0800 | [diff] [blame] | 1808 | return true; |
| 1809 | } |
| 1810 | |
Andrii Kulian | fb1bf69 | 2017-01-17 11:17:34 -0800 | [diff] [blame] | 1811 | /** Check if caller is allowed to launch activities on specified display. */ |
Andrii Kulian | 02689a7 | 2017-07-06 14:28:59 -0700 | [diff] [blame] | 1812 | boolean isCallerAllowedToLaunchOnDisplay(int callingPid, int callingUid, int launchDisplayId, |
| 1813 | ActivityInfo aInfo) { |
Andrii Kulian | fb1bf69 | 2017-01-17 11:17:34 -0800 | [diff] [blame] | 1814 | if (DEBUG_TASKS) Slog.d(TAG, "Launch on display check: displayId=" + launchDisplayId |
| 1815 | + " callingPid=" + callingPid + " callingUid=" + callingUid); |
| 1816 | |
Andrii Kulian | 02689a7 | 2017-07-06 14:28:59 -0700 | [diff] [blame] | 1817 | if (callingPid == -1 && callingUid == -1) { |
| 1818 | if (DEBUG_TASKS) Slog.d(TAG, "Launch on display check: no caller info, skip check"); |
| 1819 | return true; |
| 1820 | } |
| 1821 | |
Andrii Kulian | 62e6f25 | 2017-05-30 22:46:53 -0700 | [diff] [blame] | 1822 | final ActivityDisplay activityDisplay = getActivityDisplayOrCreateLocked(launchDisplayId); |
Andrii Kulian | fb1bf69 | 2017-01-17 11:17:34 -0800 | [diff] [blame] | 1823 | if (activityDisplay == null) { |
| 1824 | Slog.w(TAG, "Launch on display check: display not found"); |
| 1825 | return false; |
| 1826 | } |
| 1827 | |
Andrii Kulian | 02689a7 | 2017-07-06 14:28:59 -0700 | [diff] [blame] | 1828 | // Check if the caller has enough privileges to embed activities and launch to private |
| 1829 | // displays. |
Andrii Kulian | 3a95edc | 2017-06-28 16:21:07 -0700 | [diff] [blame] | 1830 | final int startAnyPerm = mService.checkPermission(INTERNAL_SYSTEM_WINDOW, callingPid, |
Andrii Kulian | 1cba31c | 2017-06-28 09:42:48 -0700 | [diff] [blame] | 1831 | callingUid); |
| 1832 | if (startAnyPerm == PERMISSION_GRANTED) { |
| 1833 | if (DEBUG_TASKS) Slog.d(TAG, "Launch on display check:" |
| 1834 | + " allow launch any on display"); |
| 1835 | return true; |
| 1836 | } |
| 1837 | |
Andrii Kulian | 8f07029 | 2017-09-12 22:56:49 -0700 | [diff] [blame] | 1838 | // Check if caller is already present on display |
| 1839 | final boolean uidPresentOnDisplay = activityDisplay.isUidPresent(callingUid); |
| 1840 | |
Andrii Kulian | 3c9ad07 | 2017-08-01 11:45:22 -0700 | [diff] [blame] | 1841 | final int displayOwnerUid = activityDisplay.mDisplay.getOwnerUid(); |
| 1842 | if (activityDisplay.mDisplay.getType() == TYPE_VIRTUAL && displayOwnerUid != SYSTEM_UID |
| 1843 | && displayOwnerUid != aInfo.applicationInfo.uid) { |
Andrii Kulian | 1cba31c | 2017-06-28 09:42:48 -0700 | [diff] [blame] | 1844 | // Limit launching on virtual displays, because their contents can be read from Surface |
| 1845 | // by apps that created them. |
Andrii Kulian | 02689a7 | 2017-07-06 14:28:59 -0700 | [diff] [blame] | 1846 | if ((aInfo.flags & ActivityInfo.FLAG_ALLOW_EMBEDDED) == 0) { |
| 1847 | if (DEBUG_TASKS) Slog.d(TAG, "Launch on display check:" |
| 1848 | + " disallow launch on virtual display for not-embedded activity."); |
| 1849 | return false; |
| 1850 | } |
Andrii Kulian | 3c9ad07 | 2017-08-01 11:45:22 -0700 | [diff] [blame] | 1851 | // Check if the caller is allowed to embed activities from other apps. |
| 1852 | if (mService.checkPermission(ACTIVITY_EMBEDDING, callingPid, callingUid) |
Andrii Kulian | 8f07029 | 2017-09-12 22:56:49 -0700 | [diff] [blame] | 1853 | == PERMISSION_DENIED && !uidPresentOnDisplay) { |
Andrii Kulian | 3c9ad07 | 2017-08-01 11:45:22 -0700 | [diff] [blame] | 1854 | if (DEBUG_TASKS) Slog.d(TAG, "Launch on display check:" |
| 1855 | + " disallow activity embedding without permission."); |
| 1856 | return false; |
| 1857 | } |
Andrii Kulian | 1cba31c | 2017-06-28 09:42:48 -0700 | [diff] [blame] | 1858 | } |
| 1859 | |
Andrii Kulian | fb1bf69 | 2017-01-17 11:17:34 -0800 | [diff] [blame] | 1860 | if (!activityDisplay.isPrivate()) { |
| 1861 | // Anyone can launch on a public display. |
| 1862 | if (DEBUG_TASKS) Slog.d(TAG, "Launch on display check:" |
| 1863 | + " allow launch on public display"); |
| 1864 | return true; |
| 1865 | } |
| 1866 | |
| 1867 | // Check if the caller is the owner of the display. |
Andrii Kulian | 3c9ad07 | 2017-08-01 11:45:22 -0700 | [diff] [blame] | 1868 | if (displayOwnerUid == callingUid) { |
Andrii Kulian | fb1bf69 | 2017-01-17 11:17:34 -0800 | [diff] [blame] | 1869 | if (DEBUG_TASKS) Slog.d(TAG, "Launch on display check:" |
| 1870 | + " allow launch for owner of the display"); |
| 1871 | return true; |
| 1872 | } |
| 1873 | |
Andrii Kulian | 8f07029 | 2017-09-12 22:56:49 -0700 | [diff] [blame] | 1874 | if (uidPresentOnDisplay) { |
Andrii Kulian | fb1bf69 | 2017-01-17 11:17:34 -0800 | [diff] [blame] | 1875 | if (DEBUG_TASKS) Slog.d(TAG, "Launch on display check:" |
| 1876 | + " allow launch for caller present on the display"); |
| 1877 | return true; |
| 1878 | } |
| 1879 | |
Andrii Kulian | fb1bf69 | 2017-01-17 11:17:34 -0800 | [diff] [blame] | 1880 | Slog.w(TAG, "Launch on display check: denied"); |
| 1881 | return false; |
| 1882 | } |
| 1883 | |
| 1884 | /** Update lists of UIDs that are present on displays and have access to them. */ |
| 1885 | void updateUIDsPresentOnDisplay() { |
| 1886 | mDisplayAccessUIDs.clear(); |
| 1887 | for (int displayNdx = mActivityDisplays.size() - 1; displayNdx >= 0; --displayNdx) { |
| 1888 | final ActivityDisplay activityDisplay = mActivityDisplays.valueAt(displayNdx); |
David Stevens | 82ea6cb | 2017-03-03 16:18:50 -0800 | [diff] [blame] | 1889 | // Only bother calculating the whitelist for private displays |
| 1890 | if (activityDisplay.isPrivate()) { |
| 1891 | mDisplayAccessUIDs.append( |
| 1892 | activityDisplay.mDisplayId, activityDisplay.getPresentUIDs()); |
| 1893 | } |
Andrii Kulian | fb1bf69 | 2017-01-17 11:17:34 -0800 | [diff] [blame] | 1894 | } |
| 1895 | // Store updated lists in DisplayManager. Callers from outside of AM should get them there. |
| 1896 | mDisplayManagerInternal.setDisplayAccessUIDs(mDisplayAccessUIDs); |
| 1897 | } |
| 1898 | |
Filip Gruszczynski | 07a0e49 | 2015-12-17 14:16:38 -0800 | [diff] [blame] | 1899 | UserInfo getUserInfo(int userId) { |
Clara Bayarri | f7fea16 | 2015-10-22 16:09:52 +0100 | [diff] [blame] | 1900 | final long identity = Binder.clearCallingIdentity(); |
| 1901 | try { |
| 1902 | return UserManager.get(mService.mContext).getUserInfo(userId); |
| 1903 | } finally { |
| 1904 | Binder.restoreCallingIdentity(identity); |
| 1905 | } |
| 1906 | } |
| 1907 | |
Svet Ganov | 99b6043 | 2015-06-27 13:15:22 -0700 | [diff] [blame] | 1908 | private int getComponentRestrictionForCallingPackage(ActivityInfo activityInfo, |
Dianne Hackborn | a7cfbe0 | 2015-07-16 10:52:52 -0700 | [diff] [blame] | 1909 | String callingPackage, int callingPid, int callingUid, boolean ignoreTargetSecurity) { |
Dianne Hackborn | a7cfbe0 | 2015-07-16 10:52:52 -0700 | [diff] [blame] | 1910 | if (!ignoreTargetSecurity && mService.checkComponentPermission(activityInfo.permission, |
| 1911 | callingPid, callingUid, activityInfo.applicationInfo.uid, activityInfo.exported) |
Andrii Kulian | 3c9ad07 | 2017-08-01 11:45:22 -0700 | [diff] [blame] | 1912 | == PERMISSION_DENIED) { |
Svet Ganov | 99b6043 | 2015-06-27 13:15:22 -0700 | [diff] [blame] | 1913 | return ACTIVITY_RESTRICTION_PERMISSION; |
| 1914 | } |
| 1915 | |
Christopher Tate | ff7add0 | 2015-08-17 10:23:22 -0700 | [diff] [blame] | 1916 | if (activityInfo.permission == null) { |
| 1917 | return ACTIVITY_RESTRICTION_NONE; |
| 1918 | } |
| 1919 | |
Svet Ganov | 99b6043 | 2015-06-27 13:15:22 -0700 | [diff] [blame] | 1920 | final int opCode = AppOpsManager.permissionToOpCode(activityInfo.permission); |
| 1921 | if (opCode == AppOpsManager.OP_NONE) { |
| 1922 | return ACTIVITY_RESTRICTION_NONE; |
| 1923 | } |
| 1924 | |
| 1925 | if (mService.mAppOpsService.noteOperation(opCode, callingUid, |
| 1926 | callingPackage) != AppOpsManager.MODE_ALLOWED) { |
Dianne Hackborn | a7cfbe0 | 2015-07-16 10:52:52 -0700 | [diff] [blame] | 1927 | if (!ignoreTargetSecurity) { |
| 1928 | return ACTIVITY_RESTRICTION_APPOP; |
| 1929 | } |
Svet Ganov | 99b6043 | 2015-06-27 13:15:22 -0700 | [diff] [blame] | 1930 | } |
| 1931 | |
| 1932 | return ACTIVITY_RESTRICTION_NONE; |
| 1933 | } |
| 1934 | |
Svetoslav | 7008b51 | 2015-06-24 18:47:07 -0700 | [diff] [blame] | 1935 | private int getActionRestrictionForCallingPackage(String action, |
| 1936 | String callingPackage, int callingPid, int callingUid) { |
| 1937 | if (action == null) { |
Svet Ganov | 99b6043 | 2015-06-27 13:15:22 -0700 | [diff] [blame] | 1938 | return ACTIVITY_RESTRICTION_NONE; |
Svetoslav | 7008b51 | 2015-06-24 18:47:07 -0700 | [diff] [blame] | 1939 | } |
| 1940 | |
| 1941 | String permission = ACTION_TO_RUNTIME_PERMISSION.get(action); |
| 1942 | if (permission == null) { |
Svet Ganov | 99b6043 | 2015-06-27 13:15:22 -0700 | [diff] [blame] | 1943 | return ACTIVITY_RESTRICTION_NONE; |
Svetoslav | 7008b51 | 2015-06-24 18:47:07 -0700 | [diff] [blame] | 1944 | } |
| 1945 | |
| 1946 | final PackageInfo packageInfo; |
| 1947 | try { |
| 1948 | packageInfo = mService.mContext.getPackageManager() |
| 1949 | .getPackageInfo(callingPackage, PackageManager.GET_PERMISSIONS); |
| 1950 | } catch (PackageManager.NameNotFoundException e) { |
| 1951 | Slog.i(TAG, "Cannot find package info for " + callingPackage); |
Svet Ganov | 99b6043 | 2015-06-27 13:15:22 -0700 | [diff] [blame] | 1952 | return ACTIVITY_RESTRICTION_NONE; |
Svetoslav | 7008b51 | 2015-06-24 18:47:07 -0700 | [diff] [blame] | 1953 | } |
| 1954 | |
| 1955 | if (!ArrayUtils.contains(packageInfo.requestedPermissions, permission)) { |
Svet Ganov | 99b6043 | 2015-06-27 13:15:22 -0700 | [diff] [blame] | 1956 | return ACTIVITY_RESTRICTION_NONE; |
Svetoslav | 7008b51 | 2015-06-24 18:47:07 -0700 | [diff] [blame] | 1957 | } |
| 1958 | |
Andrii Kulian | 3c9ad07 | 2017-08-01 11:45:22 -0700 | [diff] [blame] | 1959 | if (mService.checkPermission(permission, callingPid, callingUid) == PERMISSION_DENIED) { |
Svet Ganov | 99b6043 | 2015-06-27 13:15:22 -0700 | [diff] [blame] | 1960 | return ACTIVITY_RESTRICTION_PERMISSION; |
Svetoslav | 7008b51 | 2015-06-24 18:47:07 -0700 | [diff] [blame] | 1961 | } |
| 1962 | |
| 1963 | final int opCode = AppOpsManager.permissionToOpCode(permission); |
| 1964 | if (opCode == AppOpsManager.OP_NONE) { |
Svet Ganov | 99b6043 | 2015-06-27 13:15:22 -0700 | [diff] [blame] | 1965 | return ACTIVITY_RESTRICTION_NONE; |
Svetoslav | 7008b51 | 2015-06-24 18:47:07 -0700 | [diff] [blame] | 1966 | } |
| 1967 | |
| 1968 | if (mService.mAppOpsService.noteOperation(opCode, callingUid, |
| 1969 | callingPackage) != AppOpsManager.MODE_ALLOWED) { |
Svet Ganov | 99b6043 | 2015-06-27 13:15:22 -0700 | [diff] [blame] | 1970 | return ACTIVITY_RESTRICTION_APPOP; |
Svetoslav | 7008b51 | 2015-06-24 18:47:07 -0700 | [diff] [blame] | 1971 | } |
| 1972 | |
Svet Ganov | 99b6043 | 2015-06-27 13:15:22 -0700 | [diff] [blame] | 1973 | return ACTIVITY_RESTRICTION_NONE; |
Svetoslav | 7008b51 | 2015-06-24 18:47:07 -0700 | [diff] [blame] | 1974 | } |
| 1975 | |
Dianne Hackborn | 3d07c94 | 2015-03-13 18:02:54 -0700 | [diff] [blame] | 1976 | void setLaunchSource(int uid) { |
| 1977 | mLaunchingActivity.setWorkSource(new WorkSource(uid)); |
| 1978 | } |
| 1979 | |
Craig Mautner | 7ea5bd4 | 2013-07-05 15:27:08 -0700 | [diff] [blame] | 1980 | void acquireLaunchWakelock() { |
| 1981 | if (VALIDATE_WAKE_LOCK_CALLER && Binder.getCallingUid() != Process.myUid()) { |
| 1982 | throw new IllegalStateException("Calling must be system uid"); |
| 1983 | } |
| 1984 | mLaunchingActivity.acquire(); |
| 1985 | if (!mHandler.hasMessages(LAUNCH_TIMEOUT_MSG)) { |
| 1986 | // To be safe, don't allow the wake lock to be held for too long. |
| 1987 | mHandler.sendEmptyMessageDelayed(LAUNCH_TIMEOUT_MSG, LAUNCH_TIMEOUT); |
| 1988 | } |
| 1989 | } |
| 1990 | |
Craig Mautner | f3ea23a | 2015-01-13 09:37:08 -0800 | [diff] [blame] | 1991 | /** |
| 1992 | * Called when the frontmost task is idle. |
| 1993 | * @return the state of mService.mBooting before this was called. |
| 1994 | */ |
Andreas Gampe | a36dc62 | 2018-02-05 17:19:22 -0800 | [diff] [blame] | 1995 | @GuardedBy("mService") |
Craig Mautner | f3ea23a | 2015-01-13 09:37:08 -0800 | [diff] [blame] | 1996 | private boolean checkFinishBootingLocked() { |
| 1997 | final boolean booting = mService.mBooting; |
| 1998 | boolean enableScreen = false; |
| 1999 | mService.mBooting = false; |
| 2000 | if (!mService.mBooted) { |
| 2001 | mService.mBooted = true; |
| 2002 | enableScreen = true; |
| 2003 | } |
| 2004 | if (booting || enableScreen) { |
| 2005 | mService.postFinishBooting(booting, enableScreen); |
| 2006 | } |
| 2007 | return booting; |
| 2008 | } |
| 2009 | |
Craig Mautner | f333327 | 2013-04-22 10:55:53 -0700 | [diff] [blame] | 2010 | // Checked. |
Andreas Gampe | a36dc62 | 2018-02-05 17:19:22 -0800 | [diff] [blame] | 2011 | @GuardedBy("mService") |
Craig Mautner | f333327 | 2013-04-22 10:55:53 -0700 | [diff] [blame] | 2012 | final ActivityRecord activityIdleInternalLocked(final IBinder token, boolean fromTimeout, |
Winson Chung | 4dabf23 | 2017-01-25 13:25:22 -0800 | [diff] [blame] | 2013 | boolean processPausingActivities, Configuration config) { |
Wale Ogunwale | e23149f | 2015-03-06 15:39:44 -0800 | [diff] [blame] | 2014 | if (DEBUG_ALL) Slog.v(TAG, "Activity idle: " + token); |
Craig Mautner | f333327 | 2013-04-22 10:55:53 -0700 | [diff] [blame] | 2015 | |
Craig Mautner | f333327 | 2013-04-22 10:55:53 -0700 | [diff] [blame] | 2016 | ArrayList<ActivityRecord> finishes = null; |
Amith Yamasani | 37a40c2 | 2015-06-17 13:25:42 -0700 | [diff] [blame] | 2017 | ArrayList<UserState> startingUsers = null; |
Craig Mautner | f333327 | 2013-04-22 10:55:53 -0700 | [diff] [blame] | 2018 | int NS = 0; |
| 2019 | int NF = 0; |
Craig Mautner | f333327 | 2013-04-22 10:55:53 -0700 | [diff] [blame] | 2020 | boolean booting = false; |
Craig Mautner | f333327 | 2013-04-22 10:55:53 -0700 | [diff] [blame] | 2021 | boolean activityRemoved = false; |
| 2022 | |
Wale Ogunwale | 7d70117 | 2015-03-11 15:36:30 -0700 | [diff] [blame] | 2023 | ActivityRecord r = ActivityRecord.forTokenLocked(token); |
Craig Mautner | f333327 | 2013-04-22 10:55:53 -0700 | [diff] [blame] | 2024 | if (r != null) { |
Wale Ogunwale | 0fc365c | 2015-05-25 19:35:42 -0700 | [diff] [blame] | 2025 | if (DEBUG_IDLE) Slog.d(TAG_IDLE, "activityIdleInternalLocked: Callers=" |
| 2026 | + Debug.getCallers(4)); |
Craig Mautner | f333327 | 2013-04-22 10:55:53 -0700 | [diff] [blame] | 2027 | mHandler.removeMessages(IDLE_TIMEOUT_MSG, r); |
| 2028 | r.finishLaunchTickingLocked(); |
Craig Mautner | 7ea5bd4 | 2013-07-05 15:27:08 -0700 | [diff] [blame] | 2029 | if (fromTimeout) { |
| 2030 | reportActivityLaunchedLocked(fromTimeout, r, -1, -1); |
Craig Mautner | f333327 | 2013-04-22 10:55:53 -0700 | [diff] [blame] | 2031 | } |
Craig Mautner | 7ea5bd4 | 2013-07-05 15:27:08 -0700 | [diff] [blame] | 2032 | |
| 2033 | // This is a hack to semi-deal with a race condition |
| 2034 | // in the client where it can be constructed with a |
| 2035 | // newer configuration from when we asked it to launch. |
| 2036 | // We'll update with whatever configuration it now says |
| 2037 | // it used to launch. |
| 2038 | if (config != null) { |
Bryce Lee | a163b76 | 2017-01-24 11:05:01 -0800 | [diff] [blame] | 2039 | r.setLastReportedGlobalConfiguration(config); |
Craig Mautner | 7ea5bd4 | 2013-07-05 15:27:08 -0700 | [diff] [blame] | 2040 | } |
| 2041 | |
| 2042 | // We are now idle. If someone is waiting for a thumbnail from |
| 2043 | // us, we can now deliver. |
| 2044 | r.idle = true; |
| 2045 | |
Craig Mautner | 7ea5bd4 | 2013-07-05 15:27:08 -0700 | [diff] [blame] | 2046 | //Slog.i(TAG, "IDLE: mBooted=" + mBooted + ", fromTimeout=" + fromTimeout); |
Andrii Kulian | 02b7a83 | 2016-10-06 23:11:56 -0700 | [diff] [blame] | 2047 | if (isFocusedStack(r.getStack()) || fromTimeout) { |
Craig Mautner | f3ea23a | 2015-01-13 09:37:08 -0800 | [diff] [blame] | 2048 | booting = checkFinishBootingLocked(); |
Craig Mautner | 7ea5bd4 | 2013-07-05 15:27:08 -0700 | [diff] [blame] | 2049 | } |
| 2050 | } |
| 2051 | |
| 2052 | if (allResumedActivitiesIdle()) { |
| 2053 | if (r != null) { |
| 2054 | mService.scheduleAppGcsLocked(); |
Craig Mautner | 7ea5bd4 | 2013-07-05 15:27:08 -0700 | [diff] [blame] | 2055 | } |
| 2056 | |
| 2057 | if (mLaunchingActivity.isHeld()) { |
| 2058 | mHandler.removeMessages(LAUNCH_TIMEOUT_MSG); |
| 2059 | if (VALIDATE_WAKE_LOCK_CALLER && |
| 2060 | Binder.getCallingUid() != Process.myUid()) { |
| 2061 | throw new IllegalStateException("Calling must be system uid"); |
| 2062 | } |
| 2063 | mLaunchingActivity.release(); |
| 2064 | } |
Filip Gruszczynski | bc5a6c5 | 2015-09-22 13:13:24 -0700 | [diff] [blame] | 2065 | ensureActivitiesVisibleLocked(null, 0, !PRESERVE_WINDOWS); |
Craig Mautner | f333327 | 2013-04-22 10:55:53 -0700 | [diff] [blame] | 2066 | } |
| 2067 | |
| 2068 | // Atomically retrieve all of the other things to do. |
Winson Chung | 4dabf23 | 2017-01-25 13:25:22 -0800 | [diff] [blame] | 2069 | final ArrayList<ActivityRecord> stops = processStoppingActivitiesLocked(r, |
| 2070 | true /* remove */, processPausingActivities); |
Craig Mautner | f333327 | 2013-04-22 10:55:53 -0700 | [diff] [blame] | 2071 | NS = stops != null ? stops.size() : 0; |
Wale Ogunwale | 7d70117 | 2015-03-11 15:36:30 -0700 | [diff] [blame] | 2072 | if ((NF = mFinishingActivities.size()) > 0) { |
| 2073 | finishes = new ArrayList<>(mFinishingActivities); |
Craig Mautner | f333327 | 2013-04-22 10:55:53 -0700 | [diff] [blame] | 2074 | mFinishingActivities.clear(); |
| 2075 | } |
| 2076 | |
Craig Mautner | f333327 | 2013-04-22 10:55:53 -0700 | [diff] [blame] | 2077 | if (mStartingUsers.size() > 0) { |
Wale Ogunwale | 7d70117 | 2015-03-11 15:36:30 -0700 | [diff] [blame] | 2078 | startingUsers = new ArrayList<>(mStartingUsers); |
Craig Mautner | f333327 | 2013-04-22 10:55:53 -0700 | [diff] [blame] | 2079 | mStartingUsers.clear(); |
| 2080 | } |
| 2081 | |
Craig Mautner | f333327 | 2013-04-22 10:55:53 -0700 | [diff] [blame] | 2082 | // Stop any activities that are scheduled to do so but have been |
| 2083 | // waiting for the next one to start. |
| 2084 | for (int i = 0; i < NS; i++) { |
| 2085 | r = stops.get(i); |
Andrii Kulian | 02b7a83 | 2016-10-06 23:11:56 -0700 | [diff] [blame] | 2086 | final ActivityStack stack = r.getStack(); |
Wale Ogunwale | 7d70117 | 2015-03-11 15:36:30 -0700 | [diff] [blame] | 2087 | if (stack != null) { |
| 2088 | if (r.finishing) { |
Bryce Lee | f52974c | 2018-02-14 15:12:01 -0800 | [diff] [blame] | 2089 | stack.finishCurrentActivityLocked(r, ActivityStack.FINISH_IMMEDIATELY, false, |
| 2090 | "activityIdleInternalLocked"); |
Wale Ogunwale | 7d70117 | 2015-03-11 15:36:30 -0700 | [diff] [blame] | 2091 | } else { |
| 2092 | stack.stopActivityLocked(r); |
| 2093 | } |
Craig Mautner | f333327 | 2013-04-22 10:55:53 -0700 | [diff] [blame] | 2094 | } |
| 2095 | } |
| 2096 | |
| 2097 | // Finish any activities that are scheduled to do so but have been |
| 2098 | // waiting for the next one to start. |
| 2099 | for (int i = 0; i < NF; i++) { |
| 2100 | r = finishes.get(i); |
Andrii Kulian | 02b7a83 | 2016-10-06 23:11:56 -0700 | [diff] [blame] | 2101 | final ActivityStack stack = r.getStack(); |
Wale Ogunwale | 7d70117 | 2015-03-11 15:36:30 -0700 | [diff] [blame] | 2102 | if (stack != null) { |
| 2103 | activityRemoved |= stack.destroyActivityLocked(r, true, "finish-idle"); |
| 2104 | } |
Craig Mautner | f333327 | 2013-04-22 10:55:53 -0700 | [diff] [blame] | 2105 | } |
| 2106 | |
Dianne Hackborn | 7622a0f | 2014-09-30 14:31:42 -0700 | [diff] [blame] | 2107 | if (!booting) { |
Amith Yamasani | 1a7eaaa5 | 2014-05-07 10:22:15 -0700 | [diff] [blame] | 2108 | // Complete user switch |
| 2109 | if (startingUsers != null) { |
| 2110 | for (int i = 0; i < startingUsers.size(); i++) { |
Fyodor Kupolov | 610acda | 2015-10-19 18:44:07 -0700 | [diff] [blame] | 2111 | mService.mUserController.finishUserSwitch(startingUsers.get(i)); |
Amith Yamasani | 1a7eaaa5 | 2014-05-07 10:22:15 -0700 | [diff] [blame] | 2112 | } |
| 2113 | } |
Craig Mautner | f333327 | 2013-04-22 10:55:53 -0700 | [diff] [blame] | 2114 | } |
| 2115 | |
| 2116 | mService.trimApplications(); |
| 2117 | //dump(); |
| 2118 | //mWindowManager.dump(); |
| 2119 | |
Craig Mautner | f333327 | 2013-04-22 10:55:53 -0700 | [diff] [blame] | 2120 | if (activityRemoved) { |
Wale Ogunwale | d046a01 | 2015-12-24 13:05:59 -0800 | [diff] [blame] | 2121 | resumeFocusedStackTopActivityLocked(); |
Craig Mautner | f333327 | 2013-04-22 10:55:53 -0700 | [diff] [blame] | 2122 | } |
| 2123 | |
Craig Mautner | 7ea5bd4 | 2013-07-05 15:27:08 -0700 | [diff] [blame] | 2124 | return r; |
Craig Mautner | f333327 | 2013-04-22 10:55:53 -0700 | [diff] [blame] | 2125 | } |
| 2126 | |
Craig Mautner | 8e56957 | 2013-10-11 17:36:59 -0700 | [diff] [blame] | 2127 | boolean handleAppDiedLocked(ProcessRecord app) { |
Craig Mautner | 1909125 | 2013-10-05 00:03:53 -0700 | [diff] [blame] | 2128 | boolean hasVisibleActivities = false; |
Craig Mautner | e0a3884 | 2013-12-16 16:14:02 -0800 | [diff] [blame] | 2129 | for (int displayNdx = mActivityDisplays.size() - 1; displayNdx >= 0; --displayNdx) { |
Wale Ogunwale | a0f5b5e | 2017-10-11 09:37:23 -0700 | [diff] [blame] | 2130 | final ActivityDisplay display = mActivityDisplays.valueAt(displayNdx); |
| 2131 | for (int stackNdx = display.getChildCount() - 1; stackNdx >= 0; --stackNdx) { |
| 2132 | final ActivityStack stack = display.getChildAt(stackNdx); |
| 2133 | hasVisibleActivities |= stack.handleAppDiedLocked(app); |
Craig Mautner | 4a1cb22 | 2013-12-04 16:14:06 -0800 | [diff] [blame] | 2134 | } |
Craig Mautner | 6b74cb5 | 2013-09-27 17:02:21 -0700 | [diff] [blame] | 2135 | } |
Craig Mautner | 1909125 | 2013-10-05 00:03:53 -0700 | [diff] [blame] | 2136 | return hasVisibleActivities; |
Craig Mautner | 8d341ef | 2013-03-26 09:03:27 -0700 | [diff] [blame] | 2137 | } |
| 2138 | |
| 2139 | void closeSystemDialogsLocked() { |
Craig Mautner | e0a3884 | 2013-12-16 16:14:02 -0800 | [diff] [blame] | 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 | for (int stackNdx = display.getChildCount() - 1; stackNdx >= 0; --stackNdx) { |
| 2143 | final ActivityStack stack = display.getChildAt(stackNdx); |
| 2144 | stack.closeSystemDialogsLocked(); |
Craig Mautner | 4a1cb22 | 2013-12-04 16:14:06 -0800 | [diff] [blame] | 2145 | } |
Craig Mautner | 8d341ef | 2013-03-26 09:03:27 -0700 | [diff] [blame] | 2146 | } |
| 2147 | } |
| 2148 | |
Craig Mautner | 93529a4 | 2013-10-04 15:03:13 -0700 | [diff] [blame] | 2149 | void removeUserLocked(int userId) { |
Craig Mautner | 4f1df4f | 2013-10-15 15:44:14 -0700 | [diff] [blame] | 2150 | mUserStackInFront.delete(userId); |
Craig Mautner | 93529a4 | 2013-10-04 15:03:13 -0700 | [diff] [blame] | 2151 | } |
| 2152 | |
Craig Mautner | 8d341ef | 2013-03-26 09:03:27 -0700 | [diff] [blame] | 2153 | /** |
Chong Zhang | 45c25ce | 2015-08-10 22:18:26 -0700 | [diff] [blame] | 2154 | * Update the last used stack id for non-current user (current user's last |
| 2155 | * used stack is the focused stack) |
| 2156 | */ |
| 2157 | void updateUserStackLocked(int userId, ActivityStack stack) { |
| 2158 | if (userId != mCurrentUser) { |
Wale Ogunwale | 6827856 | 2017-09-23 17:13:55 -0700 | [diff] [blame] | 2159 | mUserStackInFront.put(userId, stack != null ? stack.getStackId() : mHomeStack.mStackId); |
Chong Zhang | 45c25ce | 2015-08-10 22:18:26 -0700 | [diff] [blame] | 2160 | } |
| 2161 | } |
| 2162 | |
| 2163 | /** |
Craig Mautner | 8d341ef | 2013-03-26 09:03:27 -0700 | [diff] [blame] | 2164 | * @return true if some activity was finished (or would have finished if doit were true). |
| 2165 | */ |
Wale Ogunwale | 540e123 | 2015-05-01 15:35:39 -0700 | [diff] [blame] | 2166 | boolean finishDisabledPackageActivitiesLocked(String packageName, Set<String> filterByClasses, |
| 2167 | boolean doit, boolean evenPersistent, int userId) { |
Craig Mautner | 8d341ef | 2013-03-26 09:03:27 -0700 | [diff] [blame] | 2168 | boolean didSomething = false; |
Craig Mautner | e0a3884 | 2013-12-16 16:14:02 -0800 | [diff] [blame] | 2169 | for (int displayNdx = mActivityDisplays.size() - 1; displayNdx >= 0; --displayNdx) { |
Wale Ogunwale | a0f5b5e | 2017-10-11 09:37:23 -0700 | [diff] [blame] | 2170 | final ActivityDisplay display = mActivityDisplays.valueAt(displayNdx); |
| 2171 | for (int stackNdx = display.getChildCount() - 1; stackNdx >= 0; --stackNdx) { |
| 2172 | final ActivityStack stack = display.getChildAt(stackNdx); |
Wale Ogunwale | 540e123 | 2015-05-01 15:35:39 -0700 | [diff] [blame] | 2173 | if (stack.finishDisabledPackageActivitiesLocked( |
| 2174 | packageName, filterByClasses, doit, evenPersistent, userId)) { |
Craig Mautner | 4a1cb22 | 2013-12-04 16:14:06 -0800 | [diff] [blame] | 2175 | didSomething = true; |
| 2176 | } |
Craig Mautner | 8d341ef | 2013-03-26 09:03:27 -0700 | [diff] [blame] | 2177 | } |
| 2178 | } |
| 2179 | return didSomething; |
| 2180 | } |
| 2181 | |
Dianne Hackborn | a413dc0 | 2013-07-12 12:02:55 -0700 | [diff] [blame] | 2182 | void updatePreviousProcessLocked(ActivityRecord r) { |
| 2183 | // Now that this process has stopped, we may want to consider |
| 2184 | // it to be the previous app to try to keep around in case |
| 2185 | // the user wants to return to it. |
| 2186 | |
| 2187 | // First, found out what is currently the foreground app, so that |
| 2188 | // we don't blow away the previous app if this activity is being |
| 2189 | // hosted by the process that is actually still the foreground. |
| 2190 | ProcessRecord fgApp = null; |
Craig Mautner | e0a3884 | 2013-12-16 16:14:02 -0800 | [diff] [blame] | 2191 | for (int displayNdx = mActivityDisplays.size() - 1; displayNdx >= 0; --displayNdx) { |
Wale Ogunwale | a0f5b5e | 2017-10-11 09:37:23 -0700 | [diff] [blame] | 2192 | final ActivityDisplay display = mActivityDisplays.valueAt(displayNdx); |
| 2193 | for (int stackNdx = display.getChildCount() - 1; stackNdx >= 0; --stackNdx) { |
| 2194 | final ActivityStack stack = display.getChildAt(stackNdx); |
Wale Ogunwale | 1e60e0c | 2015-10-28 13:36:10 -0700 | [diff] [blame] | 2195 | if (isFocusedStack(stack)) { |
Bryce Lee | c4ab62a | 2018-03-05 14:19:26 -0800 | [diff] [blame] | 2196 | final ActivityRecord resumedActivity = stack.getResumedActivity(); |
| 2197 | if (resumedActivity != null) { |
| 2198 | fgApp = resumedActivity.app; |
Craig Mautner | 4a1cb22 | 2013-12-04 16:14:06 -0800 | [diff] [blame] | 2199 | } else if (stack.mPausingActivity != null) { |
| 2200 | fgApp = stack.mPausingActivity.app; |
| 2201 | } |
| 2202 | break; |
Dianne Hackborn | a413dc0 | 2013-07-12 12:02:55 -0700 | [diff] [blame] | 2203 | } |
Dianne Hackborn | a413dc0 | 2013-07-12 12:02:55 -0700 | [diff] [blame] | 2204 | } |
| 2205 | } |
| 2206 | |
| 2207 | // Now set this one as the previous process, only if that really |
| 2208 | // makes sense to. |
| 2209 | if (r.app != null && fgApp != null && r.app != fgApp |
| 2210 | && r.lastVisibleTime > mService.mPreviousProcessVisibleTime |
Craig Mautner | 4ef2693 | 2013-09-18 15:15:52 -0700 | [diff] [blame] | 2211 | && r.app != mService.mHomeProcess) { |
Dianne Hackborn | a413dc0 | 2013-07-12 12:02:55 -0700 | [diff] [blame] | 2212 | mService.mPreviousProcess = r.app; |
| 2213 | mService.mPreviousProcessVisibleTime = r.lastVisibleTime; |
| 2214 | } |
| 2215 | } |
| 2216 | |
Wale Ogunwale | d046a01 | 2015-12-24 13:05:59 -0800 | [diff] [blame] | 2217 | boolean resumeFocusedStackTopActivityLocked() { |
| 2218 | return resumeFocusedStackTopActivityLocked(null, null, null); |
Craig Mautner | 05d2903 | 2013-05-03 13:40:13 -0700 | [diff] [blame] | 2219 | } |
| 2220 | |
Wale Ogunwale | d046a01 | 2015-12-24 13:05:59 -0800 | [diff] [blame] | 2221 | boolean resumeFocusedStackTopActivityLocked( |
Chong Zhang | 280d332 | 2015-11-03 17:27:26 -0800 | [diff] [blame] | 2222 | ActivityStack targetStack, ActivityRecord target, ActivityOptions targetOptions) { |
chaviw | 59b9885 | 2017-06-13 12:05:44 -0700 | [diff] [blame] | 2223 | |
| 2224 | if (!readyToResume()) { |
| 2225 | return false; |
| 2226 | } |
| 2227 | |
Wale Ogunwale | d046a01 | 2015-12-24 13:05:59 -0800 | [diff] [blame] | 2228 | if (targetStack != null && isFocusedStack(targetStack)) { |
| 2229 | return targetStack.resumeTopActivityUncheckedLocked(target, targetOptions); |
Craig Mautner | 05d2903 | 2013-05-03 13:40:13 -0700 | [diff] [blame] | 2230 | } |
chaviw | 59b9885 | 2017-06-13 12:05:44 -0700 | [diff] [blame] | 2231 | |
Wale Ogunwale | 06579d6 | 2016-04-30 15:29:06 -0700 | [diff] [blame] | 2232 | final ActivityRecord r = mFocusedStack.topRunningActivityLocked(); |
Bryce Lee | 7ace395 | 2018-02-16 14:34:32 -0800 | [diff] [blame] | 2233 | if (r == null || !r.isState(RESUMED)) { |
Wale Ogunwale | 06579d6 | 2016-04-30 15:29:06 -0700 | [diff] [blame] | 2234 | mFocusedStack.resumeTopActivityUncheckedLocked(null, null); |
Bryce Lee | 7ace395 | 2018-02-16 14:34:32 -0800 | [diff] [blame] | 2235 | } else if (r.isState(RESUMED)) { |
skuhne@google.com | 1b974dc | 2016-12-09 13:41:29 -0800 | [diff] [blame] | 2236 | // Kick off any lingering app transitions form the MoveTaskToFront operation. |
| 2237 | mFocusedStack.executeAppTransition(targetOptions); |
Wale Ogunwale | 06579d6 | 2016-04-30 15:29:06 -0700 | [diff] [blame] | 2238 | } |
chaviw | 59b9885 | 2017-06-13 12:05:44 -0700 | [diff] [blame] | 2239 | |
Wale Ogunwale | d046a01 | 2015-12-24 13:05:59 -0800 | [diff] [blame] | 2240 | return false; |
Craig Mautner | 8d341ef | 2013-03-26 09:03:27 -0700 | [diff] [blame] | 2241 | } |
| 2242 | |
Todd Kennedy | 39bfee5 | 2016-02-24 10:28:21 -0800 | [diff] [blame] | 2243 | void updateActivityApplicationInfoLocked(ApplicationInfo aInfo) { |
| 2244 | for (int displayNdx = mActivityDisplays.size() - 1; displayNdx >= 0; --displayNdx) { |
Wale Ogunwale | a0f5b5e | 2017-10-11 09:37:23 -0700 | [diff] [blame] | 2245 | final ActivityDisplay display = mActivityDisplays.valueAt(displayNdx); |
| 2246 | for (int stackNdx = display.getChildCount() - 1; stackNdx >= 0; --stackNdx) { |
| 2247 | final ActivityStack stack = display.getChildAt(stackNdx); |
| 2248 | stack.updateActivityApplicationInfoLocked(aInfo); |
Todd Kennedy | 39bfee5 | 2016-02-24 10:28:21 -0800 | [diff] [blame] | 2249 | } |
| 2250 | } |
| 2251 | } |
| 2252 | |
Andrii Kulian | 8cc92ac6 | 2018-04-02 23:14:18 -0700 | [diff] [blame] | 2253 | /** |
| 2254 | * Finish the topmost activities in all stacks that belong to the crashed app. |
| 2255 | * @param app The app that crashed. |
| 2256 | * @param reason Reason to perform this action. |
| 2257 | * @return The task that was finished in this stack, {@code null} if haven't found any. |
| 2258 | */ |
| 2259 | TaskRecord finishTopCrashedActivitiesLocked(ProcessRecord app, String reason) { |
Adrian Roos | 20d7df3 | 2016-01-12 18:59:43 +0100 | [diff] [blame] | 2260 | TaskRecord finishedTask = null; |
| 2261 | ActivityStack focusedStack = getFocusedStack(); |
Craig Mautner | e0a3884 | 2013-12-16 16:14:02 -0800 | [diff] [blame] | 2262 | for (int displayNdx = mActivityDisplays.size() - 1; displayNdx >= 0; --displayNdx) { |
Wale Ogunwale | a0f5b5e | 2017-10-11 09:37:23 -0700 | [diff] [blame] | 2263 | final ActivityDisplay display = mActivityDisplays.valueAt(displayNdx); |
Andrii Kulian | 8cc92ac6 | 2018-04-02 23:14:18 -0700 | [diff] [blame] | 2264 | // It is possible that request to finish activity might also remove its task and stack, |
| 2265 | // so we need to be careful with indexes in the loop and check child count every time. |
| 2266 | for (int stackNdx = 0; stackNdx < display.getChildCount(); ++stackNdx) { |
Wale Ogunwale | a0f5b5e | 2017-10-11 09:37:23 -0700 | [diff] [blame] | 2267 | final ActivityStack stack = display.getChildAt(stackNdx); |
Andrii Kulian | 8cc92ac6 | 2018-04-02 23:14:18 -0700 | [diff] [blame] | 2268 | final TaskRecord t = stack.finishTopCrashedActivityLocked(app, reason); |
Adrian Roos | 20d7df3 | 2016-01-12 18:59:43 +0100 | [diff] [blame] | 2269 | if (stack == focusedStack || finishedTask == null) { |
| 2270 | finishedTask = t; |
| 2271 | } |
Craig Mautner | 4a1cb22 | 2013-12-04 16:14:06 -0800 | [diff] [blame] | 2272 | } |
Craig Mautner | 8d341ef | 2013-03-26 09:03:27 -0700 | [diff] [blame] | 2273 | } |
Adrian Roos | 20d7df3 | 2016-01-12 18:59:43 +0100 | [diff] [blame] | 2274 | return finishedTask; |
Craig Mautner | 8d341ef | 2013-03-26 09:03:27 -0700 | [diff] [blame] | 2275 | } |
| 2276 | |
Dianne Hackborn | 6ea0d0a | 2014-07-02 16:23:21 -0700 | [diff] [blame] | 2277 | void finishVoiceTask(IVoiceInteractionSession session) { |
| 2278 | for (int displayNdx = mActivityDisplays.size() - 1; displayNdx >= 0; --displayNdx) { |
Wale Ogunwale | a0f5b5e | 2017-10-11 09:37:23 -0700 | [diff] [blame] | 2279 | final ActivityDisplay display = mActivityDisplays.valueAt(displayNdx); |
| 2280 | final int numStacks = display.getChildCount(); |
Dianne Hackborn | 6ea0d0a | 2014-07-02 16:23:21 -0700 | [diff] [blame] | 2281 | for (int stackNdx = 0; stackNdx < numStacks; ++stackNdx) { |
Wale Ogunwale | a0f5b5e | 2017-10-11 09:37:23 -0700 | [diff] [blame] | 2282 | final ActivityStack stack = display.getChildAt(stackNdx); |
Dianne Hackborn | 6ea0d0a | 2014-07-02 16:23:21 -0700 | [diff] [blame] | 2283 | stack.finishVoiceTask(session); |
| 2284 | } |
| 2285 | } |
| 2286 | } |
| 2287 | |
Jorim Jaggi | 4d8d32c | 2018-01-19 15:57:41 +0100 | [diff] [blame] | 2288 | void findTaskToMoveToFront(TaskRecord task, int flags, ActivityOptions options, String reason, |
| 2289 | boolean forceNonResizeable) { |
Wale Ogunwale | 66e1685 | 2017-10-19 13:35:52 -0700 | [diff] [blame] | 2290 | final ActivityStack currentStack = task.getStack(); |
| 2291 | if (currentStack == null) { |
| 2292 | Slog.e(TAG, "findTaskToMoveToFront: can't move task=" |
| 2293 | + task + " to front. Stack is null"); |
| 2294 | return; |
| 2295 | } |
| 2296 | |
Craig Mautner | aea74a5 | 2014-03-08 14:23:10 -0800 | [diff] [blame] | 2297 | if ((flags & ActivityManager.MOVE_TASK_NO_USER_ACTION) == 0) { |
| 2298 | mUserLeaving = true; |
Craig Mautner | 8d341ef | 2013-03-26 09:03:27 -0700 | [diff] [blame] | 2299 | } |
Wale Ogunwale | 66e1685 | 2017-10-19 13:35:52 -0700 | [diff] [blame] | 2300 | |
| 2301 | final ActivityRecord prev = topRunningActivityLocked(); |
| 2302 | |
| 2303 | if ((flags & ActivityManager.MOVE_TASK_WITH_HOME) != 0 |
| 2304 | || (prev != null && prev.isActivityTypeRecents())) { |
| 2305 | // Caller wants the home activity moved with it or the previous task is recents in which |
| 2306 | // case we always return home from the task we are moving to the front. |
| 2307 | moveHomeStackToFront("findTaskToMoveToFront"); |
Wale Ogunwale | 7d70117 | 2015-03-11 15:36:30 -0700 | [diff] [blame] | 2308 | } |
Chong Zhang | 0fa656b | 2015-08-31 15:17:21 -0700 | [diff] [blame] | 2309 | |
Wale Ogunwale | 0568aed | 2017-09-08 13:29:37 -0700 | [diff] [blame] | 2310 | if (task.isResizeable() && canUseActivityOptionsLaunchBounds(options)) { |
Bryce Lee | f3c6a47 | 2017-11-14 14:53:06 -0800 | [diff] [blame] | 2311 | final Rect bounds = options.getLaunchBounds(); |
Wale Ogunwale | 0568aed | 2017-09-08 13:29:37 -0700 | [diff] [blame] | 2312 | task.updateOverrideConfiguration(bounds); |
| 2313 | |
Wale Ogunwale | 04a05ac | 2017-09-17 21:35:02 -0700 | [diff] [blame] | 2314 | ActivityStack stack = getLaunchStack(null, options, task, ON_TOP); |
Wale Ogunwale | 0568aed | 2017-09-08 13:29:37 -0700 | [diff] [blame] | 2315 | |
Wale Ogunwale | 04a05ac | 2017-09-17 21:35:02 -0700 | [diff] [blame] | 2316 | if (stack != currentStack) { |
| 2317 | 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] | 2318 | "findTaskToMoveToFront"); |
Wale Ogunwale | 04a05ac | 2017-09-17 21:35:02 -0700 | [diff] [blame] | 2319 | stack = currentStack; |
Wale Ogunwale | 0568aed | 2017-09-08 13:29:37 -0700 | [diff] [blame] | 2320 | // moveTaskToStackUncheckedLocked() should already placed the task on top, |
| 2321 | // still need moveTaskToFrontLocked() below for any transition settings. |
| 2322 | } |
Wale Ogunwale | 44f036f | 2017-09-29 05:09:09 -0700 | [diff] [blame] | 2323 | if (stack.resizeStackWithLaunchBounds()) { |
| 2324 | resizeStackLocked(stack, bounds, null /* tempTaskBounds */, |
Wale Ogunwale | 04a05ac | 2017-09-17 21:35:02 -0700 | [diff] [blame] | 2325 | null /* tempTaskInsetBounds */, !PRESERVE_WINDOWS, |
| 2326 | true /* allowResizeInDockedMode */, !DEFER_RESUME); |
Wale Ogunwale | 0568aed | 2017-09-08 13:29:37 -0700 | [diff] [blame] | 2327 | } else { |
| 2328 | // WM resizeTask must be done after the task is moved to the correct stack, |
| 2329 | // because Task's setBounds() also updates dim layer's bounds, but that has |
| 2330 | // dependency on the stack. |
| 2331 | task.resizeWindowContainer(); |
Chong Zhang | 0fa656b | 2015-08-31 15:17:21 -0700 | [diff] [blame] | 2332 | } |
| 2333 | } |
| 2334 | |
Chong Zhang | db20b5f | 2015-10-23 14:01:43 -0700 | [diff] [blame] | 2335 | final ActivityRecord r = task.getTopActivity(); |
chaviw | 0d562bf | 2018-03-15 14:24:14 -0700 | [diff] [blame] | 2336 | currentStack.moveTaskToFrontLocked(task, false /* noAnimation */, options, |
Chong Zhang | db20b5f | 2015-10-23 14:01:43 -0700 | [diff] [blame] | 2337 | r == null ? null : r.appTimeTracker, reason); |
| 2338 | |
Wale Ogunwale | ee006da | 2015-03-30 14:49:25 -0700 | [diff] [blame] | 2339 | if (DEBUG_STACK) Slog.d(TAG_STACK, |
Andrii Kulian | 02b7a83 | 2016-10-06 23:11:56 -0700 | [diff] [blame] | 2340 | "findTaskToMoveToFront: moved to front of stack=" + currentStack); |
Jorim Jaggi | 2adba07 | 2016-03-03 13:43:39 +0100 | [diff] [blame] | 2341 | |
Wale Ogunwale | 0568aed | 2017-09-08 13:29:37 -0700 | [diff] [blame] | 2342 | handleNonResizableTaskIfNeeded(task, WINDOWING_MODE_UNDEFINED, DEFAULT_DISPLAY, |
Wale Ogunwale | a0f5b5e | 2017-10-11 09:37:23 -0700 | [diff] [blame] | 2343 | currentStack, forceNonResizeable); |
Craig Mautner | 8d341ef | 2013-03-26 09:03:27 -0700 | [diff] [blame] | 2344 | } |
| 2345 | |
Wale Ogunwale | 0568aed | 2017-09-08 13:29:37 -0700 | [diff] [blame] | 2346 | boolean canUseActivityOptionsLaunchBounds(ActivityOptions options) { |
Wale Ogunwale | 7a8fa60 | 2015-11-18 15:56:57 -0800 | [diff] [blame] | 2347 | // 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] | 2348 | // window management or is launching into the pinned stack. |
Wale Ogunwale | 0568aed | 2017-09-08 13:29:37 -0700 | [diff] [blame] | 2349 | if (options == null || options.getLaunchBounds() == null) { |
Wale Ogunwale | 854809c | 2015-12-27 16:18:19 -0800 | [diff] [blame] | 2350 | return false; |
| 2351 | } |
Wale Ogunwale | 0568aed | 2017-09-08 13:29:37 -0700 | [diff] [blame] | 2352 | return (mService.mSupportsPictureInPicture |
| 2353 | && options.getLaunchWindowingMode() == WINDOWING_MODE_PINNED) |
Wale Ogunwale | 854809c | 2015-12-27 16:18:19 -0800 | [diff] [blame] | 2354 | || mService.mSupportsFreeformWindowManagement; |
Wale Ogunwale | 7a8fa60 | 2015-11-18 15:56:57 -0800 | [diff] [blame] | 2355 | } |
| 2356 | |
Bryce Lee | ec55eb0 | 2017-12-05 20:51:27 -0800 | [diff] [blame] | 2357 | LaunchParamsController getLaunchParamsController() { |
| 2358 | return mLaunchParamsController; |
Bryce Lee | 9ad3eb3 | 2017-10-10 10:10:31 -0700 | [diff] [blame] | 2359 | } |
| 2360 | |
Winson Chung | 5589333 | 2017-02-17 17:13:10 -0800 | [diff] [blame] | 2361 | protected <T extends ActivityStack> T getStack(int stackId) { |
Wale Ogunwale | 9dcf946 | 2017-09-19 15:13:01 -0700 | [diff] [blame] | 2362 | for (int i = mActivityDisplays.size() - 1; i >= 0; --i) { |
| 2363 | final T stack = mActivityDisplays.valueAt(i).getStack(stackId); |
| 2364 | if (stack != null) { |
| 2365 | return stack; |
| 2366 | } |
| 2367 | } |
| 2368 | return null; |
Wale Ogunwale | ddc1cb2 | 2015-07-25 19:23:04 -0700 | [diff] [blame] | 2369 | } |
| 2370 | |
Wale Ogunwale | 6827856 | 2017-09-23 17:13:55 -0700 | [diff] [blame] | 2371 | /** @see ActivityDisplay#getStack(int, int) */ |
| 2372 | private <T extends ActivityStack> T getStack(int windowingMode, int activityType) { |
| 2373 | for (int i = mActivityDisplays.size() - 1; i >= 0; --i) { |
| 2374 | final T stack = mActivityDisplays.valueAt(i).getStack(windowingMode, activityType); |
| 2375 | if (stack != null) { |
| 2376 | return stack; |
| 2377 | } |
| 2378 | } |
| 2379 | return null; |
| 2380 | } |
| 2381 | |
Wale Ogunwale | 04a05ac | 2017-09-17 21:35:02 -0700 | [diff] [blame] | 2382 | int resolveActivityType(@Nullable ActivityRecord r, @Nullable ActivityOptions options, |
Wale Ogunwale | 0568aed | 2017-09-08 13:29:37 -0700 | [diff] [blame] | 2383 | @Nullable TaskRecord task) { |
Wale Ogunwale | 04a05ac | 2017-09-17 21:35:02 -0700 | [diff] [blame] | 2384 | // Preference is given to the activity type for the activity then the task since the type |
| 2385 | // once set shouldn't change. |
| 2386 | int activityType = r != null ? r.getActivityType() : ACTIVITY_TYPE_UNDEFINED; |
| 2387 | if (activityType == ACTIVITY_TYPE_UNDEFINED && task != null) { |
| 2388 | activityType = task.getActivityType(); |
| 2389 | } |
Wale Ogunwale | 0568aed | 2017-09-08 13:29:37 -0700 | [diff] [blame] | 2390 | if (activityType != ACTIVITY_TYPE_UNDEFINED) { |
| 2391 | return activityType; |
| 2392 | } |
Wale Ogunwale | ab5de37 | 2017-10-18 06:46:31 -0700 | [diff] [blame] | 2393 | if (options != null) { |
| 2394 | activityType = options.getLaunchActivityType(); |
| 2395 | } |
| 2396 | return activityType != ACTIVITY_TYPE_UNDEFINED ? activityType : ACTIVITY_TYPE_STANDARD; |
Wale Ogunwale | 0568aed | 2017-09-08 13:29:37 -0700 | [diff] [blame] | 2397 | } |
| 2398 | |
Wale Ogunwale | 04a05ac | 2017-09-17 21:35:02 -0700 | [diff] [blame] | 2399 | <T extends ActivityStack> T getLaunchStack(@Nullable ActivityRecord r, |
| 2400 | @Nullable ActivityOptions options, @Nullable TaskRecord candidateTask, boolean onTop) { |
| 2401 | return getLaunchStack(r, options, candidateTask, onTop, INVALID_DISPLAY); |
Wale Ogunwale | 0568aed | 2017-09-08 13:29:37 -0700 | [diff] [blame] | 2402 | } |
| 2403 | |
| 2404 | /** |
| 2405 | * Returns the right stack to use for launching factoring in all the input parameters. |
| 2406 | * |
| 2407 | * @param r The activity we are trying to launch. Can be null. |
| 2408 | * @param options The activity options used to the launch. Can be null. |
| 2409 | * @param candidateTask The possible task the activity might be launched in. Can be null. |
| 2410 | * |
| 2411 | * @return The stack to use for the launch or INVALID_STACK_ID. |
| 2412 | */ |
Wale Ogunwale | 04a05ac | 2017-09-17 21:35:02 -0700 | [diff] [blame] | 2413 | <T extends ActivityStack> T getLaunchStack(@Nullable ActivityRecord r, |
| 2414 | @Nullable ActivityOptions options, @Nullable TaskRecord candidateTask, boolean onTop, |
| 2415 | int candidateDisplayId) { |
Wale Ogunwale | 0568aed | 2017-09-08 13:29:37 -0700 | [diff] [blame] | 2416 | int taskId = INVALID_TASK_ID; |
| 2417 | int displayId = INVALID_DISPLAY; |
| 2418 | //Rect bounds = null; |
| 2419 | |
| 2420 | // We give preference to the launch preference in activity options. |
| 2421 | if (options != null) { |
| 2422 | taskId = options.getLaunchTaskId(); |
| 2423 | displayId = options.getLaunchDisplayId(); |
| 2424 | // TODO: Need to work this into the equation... |
| 2425 | //bounds = options.getLaunchBounds(); |
| 2426 | } |
| 2427 | |
| 2428 | // First preference for stack goes to the task Id set in the activity options. Use the stack |
| 2429 | // associated with that if possible. |
| 2430 | if (taskId != INVALID_TASK_ID) { |
| 2431 | // Temporarily set the task id to invalid in case in re-entry. |
| 2432 | options.setLaunchTaskId(INVALID_TASK_ID); |
| 2433 | final TaskRecord task = anyTaskForIdLocked(taskId, |
Wale Ogunwale | ab5de37 | 2017-10-18 06:46:31 -0700 | [diff] [blame] | 2434 | MATCH_TASK_IN_STACKS_OR_RECENT_TASKS_AND_RESTORE, options, onTop); |
Wale Ogunwale | 0568aed | 2017-09-08 13:29:37 -0700 | [diff] [blame] | 2435 | options.setLaunchTaskId(taskId); |
| 2436 | if (task != null) { |
Wale Ogunwale | 04a05ac | 2017-09-17 21:35:02 -0700 | [diff] [blame] | 2437 | return task.getStack(); |
Wale Ogunwale | 0568aed | 2017-09-08 13:29:37 -0700 | [diff] [blame] | 2438 | } |
| 2439 | } |
| 2440 | |
Wale Ogunwale | 0568aed | 2017-09-08 13:29:37 -0700 | [diff] [blame] | 2441 | final int activityType = resolveActivityType(r, options, candidateTask); |
Wale Ogunwale | 04a05ac | 2017-09-17 21:35:02 -0700 | [diff] [blame] | 2442 | T stack = null; |
Wale Ogunwale | 0568aed | 2017-09-08 13:29:37 -0700 | [diff] [blame] | 2443 | |
| 2444 | // Next preference for stack goes to the display Id set in the activity options or the |
| 2445 | // candidate display. |
| 2446 | if (displayId == INVALID_DISPLAY) { |
| 2447 | displayId = candidateDisplayId; |
| 2448 | } |
Andrii Kulian | b850ea5 | 2017-12-12 23:49:10 -0800 | [diff] [blame] | 2449 | if (displayId != INVALID_DISPLAY && canLaunchOnDisplay(r, displayId)) { |
Wale Ogunwale | 0568aed | 2017-09-08 13:29:37 -0700 | [diff] [blame] | 2450 | if (r != null) { |
| 2451 | // 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] | 2452 | stack = (T) getValidLaunchStackOnDisplay(displayId, r); |
Wale Ogunwale | 0568aed | 2017-09-08 13:29:37 -0700 | [diff] [blame] | 2453 | if (stack != null) { |
Wale Ogunwale | 04a05ac | 2017-09-17 21:35:02 -0700 | [diff] [blame] | 2454 | return stack; |
Wale Ogunwale | 0568aed | 2017-09-08 13:29:37 -0700 | [diff] [blame] | 2455 | } |
| 2456 | } |
| 2457 | final ActivityDisplay display = getActivityDisplayOrCreateLocked(displayId); |
| 2458 | if (display != null) { |
Wale Ogunwale | 7e1f5f5 | 2017-10-18 15:19:59 -0700 | [diff] [blame] | 2459 | stack = display.getOrCreateStack(r, options, candidateTask, activityType, onTop); |
Wale Ogunwale | ab5de37 | 2017-10-18 06:46:31 -0700 | [diff] [blame] | 2460 | if (stack != null) { |
| 2461 | return stack; |
Wale Ogunwale | 0568aed | 2017-09-08 13:29:37 -0700 | [diff] [blame] | 2462 | } |
Wale Ogunwale | 0568aed | 2017-09-08 13:29:37 -0700 | [diff] [blame] | 2463 | } |
| 2464 | } |
| 2465 | |
| 2466 | // Give preference to the stack and display of the input task and activity if they match the |
| 2467 | // mode we want to launch into. |
Wale Ogunwale | 04a05ac | 2017-09-17 21:35:02 -0700 | [diff] [blame] | 2468 | stack = null; |
| 2469 | ActivityDisplay display = null; |
Wale Ogunwale | 0568aed | 2017-09-08 13:29:37 -0700 | [diff] [blame] | 2470 | if (candidateTask != null) { |
| 2471 | stack = candidateTask.getStack(); |
| 2472 | } |
| 2473 | if (stack == null && r != null) { |
| 2474 | stack = r.getStack(); |
| 2475 | } |
| 2476 | if (stack != null) { |
Wale Ogunwale | 04a05ac | 2017-09-17 21:35:02 -0700 | [diff] [blame] | 2477 | display = stack.getDisplay(); |
Andrii Kulian | b850ea5 | 2017-12-12 23:49:10 -0800 | [diff] [blame] | 2478 | if (display != null && canLaunchOnDisplay(r, display.mDisplayId)) { |
Wale Ogunwale | 7e1f5f5 | 2017-10-18 15:19:59 -0700 | [diff] [blame] | 2479 | final int windowingMode = |
| 2480 | display.resolveWindowingMode(r, options, candidateTask, activityType); |
| 2481 | if (stack.isCompatible(windowingMode, activityType)) { |
| 2482 | return stack; |
| 2483 | } |
Andrii Kulian | ec7d4c4 | 2018-04-26 18:31:58 -0700 | [diff] [blame] | 2484 | if (windowingMode == WINDOWING_MODE_FULLSCREEN_OR_SPLIT_SCREEN_SECONDARY |
| 2485 | && display.getSplitScreenPrimaryStack() == stack |
| 2486 | && candidateTask == stack.topTask()) { |
| 2487 | // This is a special case when we try to launch an activity that is currently on |
| 2488 | // top of split-screen primary stack, but is targeting split-screen secondary. |
| 2489 | // In this case we don't want to move it to another stack. |
| 2490 | // TODO(b/78788972): Remove after differentiating between preferred and required |
| 2491 | // launch options. |
| 2492 | return stack; |
| 2493 | } |
Wale Ogunwale | 7e1f5f5 | 2017-10-18 15:19:59 -0700 | [diff] [blame] | 2494 | } |
Wale Ogunwale | 0568aed | 2017-09-08 13:29:37 -0700 | [diff] [blame] | 2495 | } |
| 2496 | |
Wale Ogunwale | 04a05ac | 2017-09-17 21:35:02 -0700 | [diff] [blame] | 2497 | if (display == null |
Andrii Kulian | b850ea5 | 2017-12-12 23:49:10 -0800 | [diff] [blame] | 2498 | || !canLaunchOnDisplay(r, display.mDisplayId) |
Wale Ogunwale | 04a05ac | 2017-09-17 21:35:02 -0700 | [diff] [blame] | 2499 | // TODO: Can be removed once we figure-out how non-standard types should launch |
| 2500 | // outside the default display. |
| 2501 | || (activityType != ACTIVITY_TYPE_STANDARD |
| 2502 | && activityType != ACTIVITY_TYPE_UNDEFINED)) { |
| 2503 | display = getDefaultDisplay(); |
Wale Ogunwale | 0568aed | 2017-09-08 13:29:37 -0700 | [diff] [blame] | 2504 | } |
Wale Ogunwale | 04a05ac | 2017-09-17 21:35:02 -0700 | [diff] [blame] | 2505 | |
Wale Ogunwale | 7e1f5f5 | 2017-10-18 15:19:59 -0700 | [diff] [blame] | 2506 | return display.getOrCreateStack(r, options, candidateTask, activityType, onTop); |
Wale Ogunwale | 0568aed | 2017-09-08 13:29:37 -0700 | [diff] [blame] | 2507 | } |
| 2508 | |
Andrii Kulian | b850ea5 | 2017-12-12 23:49:10 -0800 | [diff] [blame] | 2509 | /** @return true if activity record is null or can be launched on provided display. */ |
| 2510 | private boolean canLaunchOnDisplay(ActivityRecord r, int displayId) { |
| 2511 | if (r == null) { |
| 2512 | return true; |
| 2513 | } |
| 2514 | return r.canBeLaunchedOnDisplay(displayId); |
| 2515 | } |
| 2516 | |
Andrii Kulian | 16802aa | 2016-11-02 12:21:33 -0700 | [diff] [blame] | 2517 | /** |
| 2518 | * Get a topmost stack on the display, that is a valid launch stack for specified activity. |
| 2519 | * If there is no such stack, new dynamic stack can be created. |
| 2520 | * @param displayId Target display. |
| 2521 | * @param r Activity that should be launched there. |
| 2522 | * @return Existing stack if there is a valid one, new dynamic stack if it is valid or null. |
| 2523 | */ |
| 2524 | ActivityStack getValidLaunchStackOnDisplay(int displayId, @NonNull ActivityRecord r) { |
Andrii Kulian | 62e6f25 | 2017-05-30 22:46:53 -0700 | [diff] [blame] | 2525 | final ActivityDisplay activityDisplay = getActivityDisplayOrCreateLocked(displayId); |
Andrii Kulian | 16802aa | 2016-11-02 12:21:33 -0700 | [diff] [blame] | 2526 | if (activityDisplay == null) { |
| 2527 | throw new IllegalArgumentException( |
| 2528 | "Display with displayId=" + displayId + " not found."); |
| 2529 | } |
| 2530 | |
Wale Ogunwale | 04a05ac | 2017-09-17 21:35:02 -0700 | [diff] [blame] | 2531 | if (!r.canBeLaunchedOnDisplay(displayId)) { |
| 2532 | return null; |
| 2533 | } |
| 2534 | |
Andrii Kulian | 16802aa | 2016-11-02 12:21:33 -0700 | [diff] [blame] | 2535 | // Return the topmost valid stack on the display. |
Wale Ogunwale | a0f5b5e | 2017-10-11 09:37:23 -0700 | [diff] [blame] | 2536 | for (int i = activityDisplay.getChildCount() - 1; i >= 0; --i) { |
| 2537 | final ActivityStack stack = activityDisplay.getChildAt(i); |
Wale Ogunwale | 6827856 | 2017-09-23 17:13:55 -0700 | [diff] [blame] | 2538 | if (isValidLaunchStack(stack, displayId, r)) { |
Andrii Kulian | 16802aa | 2016-11-02 12:21:33 -0700 | [diff] [blame] | 2539 | return stack; |
| 2540 | } |
| 2541 | } |
| 2542 | |
| 2543 | // 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] | 2544 | if (displayId != DEFAULT_DISPLAY) { |
| 2545 | return activityDisplay.createStack( |
| 2546 | r.getWindowingMode(), r.getActivityType(), true /*onTop*/); |
Andrii Kulian | 16802aa | 2016-11-02 12:21:33 -0700 | [diff] [blame] | 2547 | } |
| 2548 | |
| 2549 | Slog.w(TAG, "getValidLaunchStackOnDisplay: can't launch on displayId " + displayId); |
| 2550 | return null; |
| 2551 | } |
| 2552 | |
Wale Ogunwale | 6827856 | 2017-09-23 17:13:55 -0700 | [diff] [blame] | 2553 | // TODO: Can probably be consolidated into getLaunchStack()... |
| 2554 | private boolean isValidLaunchStack(ActivityStack stack, int displayId, ActivityRecord r) { |
| 2555 | switch (stack.getActivityType()) { |
| 2556 | case ACTIVITY_TYPE_HOME: return r.isActivityTypeHome(); |
| 2557 | case ACTIVITY_TYPE_RECENTS: return r.isActivityTypeRecents(); |
| 2558 | case ACTIVITY_TYPE_ASSISTANT: return r.isActivityTypeAssistant(); |
Wale Ogunwale | 0568aed | 2017-09-08 13:29:37 -0700 | [diff] [blame] | 2559 | } |
Wale Ogunwale | 6827856 | 2017-09-23 17:13:55 -0700 | [diff] [blame] | 2560 | switch (stack.getWindowingMode()) { |
| 2561 | case WINDOWING_MODE_FULLSCREEN: return true; |
| 2562 | case WINDOWING_MODE_FREEFORM: return r.supportsFreeform(); |
| 2563 | case WINDOWING_MODE_PINNED: return r.supportsPictureInPicture(); |
| 2564 | case WINDOWING_MODE_SPLIT_SCREEN_PRIMARY: return r.supportsSplitScreenWindowingMode(); |
| 2565 | case WINDOWING_MODE_SPLIT_SCREEN_SECONDARY: return r.supportsSplitScreenWindowingMode(); |
| 2566 | } |
| 2567 | |
Wale Ogunwale | 44f036f | 2017-09-29 05:09:09 -0700 | [diff] [blame] | 2568 | if (!stack.isOnHomeDisplay()) { |
Wale Ogunwale | 6827856 | 2017-09-23 17:13:55 -0700 | [diff] [blame] | 2569 | return r.canBeLaunchedOnDisplay(displayId); |
| 2570 | } |
| 2571 | Slog.e(TAG, "isValidLaunchStack: Unexpected stack=" + stack); |
| 2572 | return false; |
Wale Ogunwale | 0568aed | 2017-09-08 13:29:37 -0700 | [diff] [blame] | 2573 | } |
| 2574 | |
Andrii Kulian | 7fc2281 | 2016-12-28 13:04:11 -0800 | [diff] [blame] | 2575 | /** |
| 2576 | * Get next focusable stack in the system. This will search across displays and stacks |
| 2577 | * in last-focused order for a focusable and visible stack, different from the target stack. |
| 2578 | * |
Wale Ogunwale | e1f68ce | 2018-03-09 08:58:54 -0800 | [diff] [blame] | 2579 | * @param currentFocus The stack that previously had focus. |
| 2580 | * @param ignoreCurrent If we should ignore {@param currentFocus} when searching for next |
| 2581 | * candidate. |
Andrii Kulian | 7fc2281 | 2016-12-28 13:04:11 -0800 | [diff] [blame] | 2582 | * @return Next focusable {@link ActivityStack}, null if not found. |
| 2583 | */ |
Wale Ogunwale | e1f68ce | 2018-03-09 08:58:54 -0800 | [diff] [blame] | 2584 | ActivityStack getNextFocusableStackLocked(ActivityStack currentFocus, boolean ignoreCurrent) { |
Andrii Kulian | 7fc2281 | 2016-12-28 13:04:11 -0800 | [diff] [blame] | 2585 | mWindowManager.getDisplaysInFocusOrder(mTmpOrderedDisplayIds); |
| 2586 | |
Wale Ogunwale | e1f68ce | 2018-03-09 08:58:54 -0800 | [diff] [blame] | 2587 | final int currentWindowingMode = currentFocus != null |
| 2588 | ? currentFocus.getWindowingMode() : WINDOWING_MODE_UNDEFINED; |
| 2589 | ActivityStack candidate = null; |
Andrii Kulian | 7fc2281 | 2016-12-28 13:04:11 -0800 | [diff] [blame] | 2590 | for (int i = mTmpOrderedDisplayIds.size() - 1; i >= 0; --i) { |
| 2591 | final int displayId = mTmpOrderedDisplayIds.get(i); |
Andrii Kulian | 62e6f25 | 2017-05-30 22:46:53 -0700 | [diff] [blame] | 2592 | // 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] | 2593 | final ActivityDisplay display = getActivityDisplayOrCreateLocked(displayId); |
Wale Ogunwale | c2ea364 | 2018-05-24 00:32:23 -0700 | [diff] [blame] | 2594 | if (display == null) { |
| 2595 | // Looks like the display no longer exists in the system... |
| 2596 | continue; |
| 2597 | } |
Wale Ogunwale | a0f5b5e | 2017-10-11 09:37:23 -0700 | [diff] [blame] | 2598 | for (int j = display.getChildCount() - 1; j >= 0; --j) { |
| 2599 | final ActivityStack stack = display.getChildAt(j); |
Wale Ogunwale | e1f68ce | 2018-03-09 08:58:54 -0800 | [diff] [blame] | 2600 | if (ignoreCurrent && stack == currentFocus) { |
| 2601 | continue; |
Andrii Kulian | 7fc2281 | 2016-12-28 13:04:11 -0800 | [diff] [blame] | 2602 | } |
Wale Ogunwale | e1f68ce | 2018-03-09 08:58:54 -0800 | [diff] [blame] | 2603 | if (!stack.isFocusable() || !stack.shouldBeVisible(null)) { |
| 2604 | continue; |
| 2605 | } |
| 2606 | |
| 2607 | if (currentWindowingMode == WINDOWING_MODE_SPLIT_SCREEN_SECONDARY |
| 2608 | && candidate == null && stack.inSplitScreenPrimaryWindowingMode()) { |
Wale Ogunwale | 17696de | 2018-03-15 16:41:05 -0700 | [diff] [blame] | 2609 | // If the currently focused stack is in split-screen secondary we save off the |
| 2610 | // top primary split-screen stack as a candidate for focus because we might |
| 2611 | // prefer focus to move to an other stack to avoid primary split-screen stack |
| 2612 | // overlapping with a fullscreen stack when a fullscreen stack is higher in z |
| 2613 | // than the next split-screen stack. Assistant stack, I am looking at you... |
Wale Ogunwale | e1f68ce | 2018-03-09 08:58:54 -0800 | [diff] [blame] | 2614 | // We only move the focus to the primary-split screen stack if there isn't a |
| 2615 | // better alternative. |
| 2616 | candidate = stack; |
| 2617 | continue; |
| 2618 | } |
Wale Ogunwale | 17696de | 2018-03-15 16:41:05 -0700 | [diff] [blame] | 2619 | if (candidate != null && stack.inSplitScreenSecondaryWindowingMode()) { |
| 2620 | // Use the candidate stack since we are now at the secondary split-screen. |
| 2621 | return candidate; |
| 2622 | } |
Wale Ogunwale | e1f68ce | 2018-03-09 08:58:54 -0800 | [diff] [blame] | 2623 | return stack; |
Andrii Kulian | 7fc2281 | 2016-12-28 13:04:11 -0800 | [diff] [blame] | 2624 | } |
| 2625 | } |
| 2626 | |
Wale Ogunwale | e1f68ce | 2018-03-09 08:58:54 -0800 | [diff] [blame] | 2627 | return candidate; |
Andrii Kulian | 7fc2281 | 2016-12-28 13:04:11 -0800 | [diff] [blame] | 2628 | } |
| 2629 | |
Andrii Kulian | a8fe3df | 2017-06-16 15:29:26 -0700 | [diff] [blame] | 2630 | /** |
| 2631 | * Get next valid stack for launching provided activity in the system. This will search across |
| 2632 | * displays and stacks in last-focused order for a focusable and visible stack, except those |
| 2633 | * that are on a currently focused display. |
| 2634 | * |
| 2635 | * @param r The activity that is being launched. |
| 2636 | * @param currentFocus The display that previously had focus and thus needs to be ignored when |
| 2637 | * searching for the next candidate. |
| 2638 | * @return Next valid {@link ActivityStack}, null if not found. |
| 2639 | */ |
| 2640 | ActivityStack getNextValidLaunchStackLocked(@NonNull ActivityRecord r, int currentFocus) { |
| 2641 | mWindowManager.getDisplaysInFocusOrder(mTmpOrderedDisplayIds); |
| 2642 | for (int i = mTmpOrderedDisplayIds.size() - 1; i >= 0; --i) { |
| 2643 | final int displayId = mTmpOrderedDisplayIds.get(i); |
| 2644 | if (displayId == currentFocus) { |
| 2645 | continue; |
| 2646 | } |
| 2647 | final ActivityStack stack = getValidLaunchStackOnDisplay(displayId, r); |
| 2648 | if (stack != null) { |
| 2649 | return stack; |
| 2650 | } |
| 2651 | } |
| 2652 | return null; |
| 2653 | } |
| 2654 | |
Craig Mautner | ee2e45a | 2014-06-27 12:10:03 -0700 | [diff] [blame] | 2655 | ActivityRecord getHomeActivity() { |
Craig Mautner | db49fec | 2015-05-21 15:33:30 -0700 | [diff] [blame] | 2656 | return getHomeActivityForUser(mCurrentUser); |
Fyodor Kupolov | b501330 | 2015-04-17 17:59:14 -0700 | [diff] [blame] | 2657 | } |
| 2658 | |
| 2659 | ActivityRecord getHomeActivityForUser(int userId) { |
Craig Mautner | 4a1cb22 | 2013-12-04 16:14:06 -0800 | [diff] [blame] | 2660 | final ArrayList<TaskRecord> tasks = mHomeStack.getAllTasks(); |
| 2661 | for (int taskNdx = tasks.size() - 1; taskNdx >= 0; --taskNdx) { |
| 2662 | final TaskRecord task = tasks.get(taskNdx); |
Wale Ogunwale | 6fbde9f | 2017-08-24 07:24:12 -0700 | [diff] [blame] | 2663 | if (task.isActivityTypeHome()) { |
Craig Mautner | 4a1cb22 | 2013-12-04 16:14:06 -0800 | [diff] [blame] | 2664 | final ArrayList<ActivityRecord> activities = task.mActivities; |
| 2665 | for (int activityNdx = activities.size() - 1; activityNdx >= 0; --activityNdx) { |
| 2666 | final ActivityRecord r = activities.get(activityNdx); |
Wale Ogunwale | 6fbde9f | 2017-08-24 07:24:12 -0700 | [diff] [blame] | 2667 | if (r.isActivityTypeHome() |
Fyodor Kupolov | b501330 | 2015-04-17 17:59:14 -0700 | [diff] [blame] | 2668 | && ((userId == UserHandle.USER_ALL) || (r.userId == userId))) { |
Craig Mautner | ee2e45a | 2014-06-27 12:10:03 -0700 | [diff] [blame] | 2669 | return r; |
Craig Mautner | 4a1cb22 | 2013-12-04 16:14:06 -0800 | [diff] [blame] | 2670 | } |
| 2671 | } |
| 2672 | } |
| 2673 | } |
| 2674 | return null; |
| 2675 | } |
| 2676 | |
Wale Ogunwale | 44f036f | 2017-09-29 05:09:09 -0700 | [diff] [blame] | 2677 | void resizeStackLocked(ActivityStack stack, Rect bounds, Rect tempTaskBounds, |
| 2678 | Rect tempTaskInsetBounds, boolean preserveWindows, boolean allowResizeInDockedMode, |
| 2679 | boolean deferResume) { |
| 2680 | |
| 2681 | if (stack.inSplitScreenPrimaryWindowingMode()) { |
Jorim Jaggi | dc249c4 | 2015-12-15 14:57:31 -0800 | [diff] [blame] | 2682 | resizeDockedStackLocked(bounds, tempTaskBounds, tempTaskInsetBounds, null, null, |
Andrii Kulian | db3e4ec | 2016-07-12 17:11:35 -0700 | [diff] [blame] | 2683 | preserveWindows, deferResume); |
Jorim Jaggi | dc249c4 | 2015-12-15 14:57:31 -0800 | [diff] [blame] | 2684 | return; |
| 2685 | } |
Wale Ogunwale | 9d3de4c | 2015-02-01 16:49:44 -0800 | [diff] [blame] | 2686 | |
Wale Ogunwale | a0f5b5e | 2017-10-11 09:37:23 -0700 | [diff] [blame] | 2687 | final boolean splitScreenActive = getDefaultDisplay().hasSplitScreenPrimaryStack(); |
Wale Ogunwale | 3382ab1 | 2017-07-27 08:55:03 -0700 | [diff] [blame] | 2688 | if (!allowResizeInDockedMode |
Wale Ogunwale | 926aade | 2017-08-29 11:24:37 -0700 | [diff] [blame] | 2689 | && !stack.getWindowConfiguration().tasksAreFloating() && splitScreenActive) { |
Winson Chung | a2249ac | 2017-03-30 18:15:30 -0700 | [diff] [blame] | 2690 | // If the docked stack exists, don't resize non-floating stacks independently of the |
| 2691 | // 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] | 2692 | return; |
| 2693 | } |
| 2694 | |
Wale Ogunwale | 44f036f | 2017-09-29 05:09:09 -0700 | [diff] [blame] | 2695 | Trace.traceBegin(TRACE_TAG_ACTIVITY_MANAGER, "am.resizeStack_" + stack.mStackId); |
Jorim Jaggi | c402520 | 2015-10-22 16:43:34 +0200 | [diff] [blame] | 2696 | mWindowManager.deferSurfaceLayout(); |
| 2697 | try { |
Wale Ogunwale | 2b07da8 | 2017-11-08 14:52:40 -0800 | [diff] [blame] | 2698 | if (stack.affectedBySplitScreenResize()) { |
Wale Ogunwale | 926aade | 2017-08-29 11:24:37 -0700 | [diff] [blame] | 2699 | if (bounds == null && stack.inSplitScreenWindowingMode()) { |
| 2700 | // null bounds = fullscreen windowing mode...at least for now. |
| 2701 | stack.setWindowingMode(WINDOWING_MODE_FULLSCREEN); |
| 2702 | } else if (splitScreenActive) { |
| 2703 | // If we are in split-screen mode and this stack support split-screen, then |
| 2704 | // it should be split-screen secondary mode. i.e. adjacent to the docked stack. |
| 2705 | stack.setWindowingMode(WINDOWING_MODE_SPLIT_SCREEN_SECONDARY); |
| 2706 | } |
| 2707 | } |
Wale Ogunwale | 1666e31 | 2016-12-16 11:27:18 -0800 | [diff] [blame] | 2708 | stack.resize(bounds, tempTaskBounds, tempTaskInsetBounds); |
Wale Ogunwale | c8da41e | 2016-04-16 13:27:23 -0700 | [diff] [blame] | 2709 | if (!deferResume) { |
Wale Ogunwale | db0fa12 | 2016-05-16 15:12:03 -0700 | [diff] [blame] | 2710 | stack.ensureVisibleActivitiesConfigurationLocked( |
| 2711 | stack.topRunningActivityLocked(), preserveWindows); |
Wale Ogunwale | c8da41e | 2016-04-16 13:27:23 -0700 | [diff] [blame] | 2712 | } |
Jorim Jaggi | c402520 | 2015-10-22 16:43:34 +0200 | [diff] [blame] | 2713 | } finally { |
| 2714 | mWindowManager.continueSurfaceLayout(); |
| 2715 | Trace.traceEnd(TRACE_TAG_ACTIVITY_MANAGER); |
Wale Ogunwale | e4a0c57 | 2015-06-30 08:40:31 -0700 | [diff] [blame] | 2716 | } |
| 2717 | } |
| 2718 | |
Winson Chung | c167427 | 2018-02-21 10:15:17 -0800 | [diff] [blame] | 2719 | void deferUpdateRecentsHomeStackBounds() { |
| 2720 | deferUpdateBounds(ACTIVITY_TYPE_RECENTS); |
| 2721 | deferUpdateBounds(ACTIVITY_TYPE_HOME); |
| 2722 | } |
| 2723 | |
Bryce Lee | d3624e1 | 2017-11-30 08:51:45 -0800 | [diff] [blame] | 2724 | void deferUpdateBounds(int activityType) { |
Wale Ogunwale | 6827856 | 2017-09-23 17:13:55 -0700 | [diff] [blame] | 2725 | final ActivityStack stack = getStack(WINDOWING_MODE_UNDEFINED, activityType); |
Jorim Jaggi | 192086e | 2016-03-11 17:17:03 +0100 | [diff] [blame] | 2726 | if (stack != null) { |
| 2727 | stack.deferUpdateBounds(); |
| 2728 | } |
| 2729 | } |
| 2730 | |
Winson Chung | c167427 | 2018-02-21 10:15:17 -0800 | [diff] [blame] | 2731 | void continueUpdateRecentsHomeStackBounds() { |
| 2732 | continueUpdateBounds(ACTIVITY_TYPE_RECENTS); |
| 2733 | continueUpdateBounds(ACTIVITY_TYPE_HOME); |
| 2734 | } |
| 2735 | |
Bryce Lee | d3624e1 | 2017-11-30 08:51:45 -0800 | [diff] [blame] | 2736 | void continueUpdateBounds(int activityType) { |
Wale Ogunwale | 6827856 | 2017-09-23 17:13:55 -0700 | [diff] [blame] | 2737 | final ActivityStack stack = getStack(WINDOWING_MODE_UNDEFINED, activityType); |
Jorim Jaggi | 192086e | 2016-03-11 17:17:03 +0100 | [diff] [blame] | 2738 | if (stack != null) { |
| 2739 | stack.continueUpdateBounds(); |
| 2740 | } |
| 2741 | } |
| 2742 | |
Jorim Jaggi | 0b46f3c | 2016-03-14 12:21:37 +0100 | [diff] [blame] | 2743 | void notifyAppTransitionDone() { |
Winson Chung | c167427 | 2018-02-21 10:15:17 -0800 | [diff] [blame] | 2744 | continueUpdateRecentsHomeStackBounds(); |
Jorim Jaggi | 0b46f3c | 2016-03-14 12:21:37 +0100 | [diff] [blame] | 2745 | for (int i = mResizingTasksDuringAnimation.size() - 1; i >= 0; i--) { |
| 2746 | final int taskId = mResizingTasksDuringAnimation.valueAt(i); |
Wale Ogunwale | 0568aed | 2017-09-08 13:29:37 -0700 | [diff] [blame] | 2747 | final TaskRecord task = anyTaskForIdLocked(taskId, MATCH_TASK_IN_STACKS_ONLY); |
Wale Ogunwale | e1fe7fa2 | 2016-12-15 18:27:00 -0800 | [diff] [blame] | 2748 | if (task != null) { |
| 2749 | task.setTaskDockedResizing(false); |
Jorim Jaggi | 0b46f3c | 2016-03-14 12:21:37 +0100 | [diff] [blame] | 2750 | } |
| 2751 | } |
| 2752 | mResizingTasksDuringAnimation.clear(); |
| 2753 | } |
| 2754 | |
Wale Ogunwale | 04a05ac | 2017-09-17 21:35:02 -0700 | [diff] [blame] | 2755 | /** |
| 2756 | * 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] | 2757 | * Can do that once we are no longer using static stack ids. |
Wale Ogunwale | 04a05ac | 2017-09-17 21:35:02 -0700 | [diff] [blame] | 2758 | */ |
Wale Ogunwale | 9dcf946 | 2017-09-19 15:13:01 -0700 | [diff] [blame] | 2759 | private void moveTasksToFullscreenStackInSurfaceTransaction(ActivityStack fromStack, |
Wale Ogunwale | 04a05ac | 2017-09-17 21:35:02 -0700 | [diff] [blame] | 2760 | int toDisplayId, boolean onTop) { |
Robert Carr | 6914f08 | 2017-03-20 19:04:30 -0700 | [diff] [blame] | 2761 | |
Wale Ogunwale | c8da41e | 2016-04-16 13:27:23 -0700 | [diff] [blame] | 2762 | mWindowManager.deferSurfaceLayout(); |
| 2763 | try { |
Wale Ogunwale | 04a05ac | 2017-09-17 21:35:02 -0700 | [diff] [blame] | 2764 | final int windowingMode = fromStack.getWindowingMode(); |
| 2765 | final boolean inPinnedWindowingMode = windowingMode == WINDOWING_MODE_PINNED; |
| 2766 | final ActivityDisplay toDisplay = getActivityDisplay(toDisplayId); |
| 2767 | |
| 2768 | if (windowingMode == WINDOWING_MODE_SPLIT_SCREEN_PRIMARY) { |
Wale Ogunwale | 7e1f5f5 | 2017-10-18 15:19:59 -0700 | [diff] [blame] | 2769 | // Tell the display we are exiting split-screen mode. |
| 2770 | toDisplay.onExitingSplitScreenMode(); |
Wale Ogunwale | c8da41e | 2016-04-16 13:27:23 -0700 | [diff] [blame] | 2771 | // We are moving all tasks from the docked stack to the fullscreen stack, |
| 2772 | // which is dismissing the docked stack, so resize all other stacks to |
| 2773 | // fullscreen here already so we don't end up with resize trashing. |
Wale Ogunwale | a0f5b5e | 2017-10-11 09:37:23 -0700 | [diff] [blame] | 2774 | for (int i = toDisplay.getChildCount() - 1; i >= 0; --i) { |
| 2775 | final ActivityStack otherStack = toDisplay.getChildAt(i); |
Wale Ogunwale | 926aade | 2017-08-29 11:24:37 -0700 | [diff] [blame] | 2776 | if (!otherStack.inSplitScreenSecondaryWindowingMode()) { |
| 2777 | continue; |
| 2778 | } |
Wale Ogunwale | 44f036f | 2017-09-29 05:09:09 -0700 | [diff] [blame] | 2779 | resizeStackLocked(otherStack, null, null, null, PRESERVE_WINDOWS, |
Wale Ogunwale | 926aade | 2017-08-29 11:24:37 -0700 | [diff] [blame] | 2780 | true /* allowResizeInDockedMode */, DEFER_RESUME); |
Wale Ogunwale | c8da41e | 2016-04-16 13:27:23 -0700 | [diff] [blame] | 2781 | } |
| 2782 | |
| 2783 | // Also disable docked stack resizing since we have manually adjusted the |
| 2784 | // size of other stacks above and we don't want to trigger a docked stack |
| 2785 | // resize when we remove task from it below and it is detached from the |
| 2786 | // display because it no longer contains any tasks. |
| 2787 | mAllowDockedStackResize = false; |
| 2788 | } |
Wale Ogunwale | 04a05ac | 2017-09-17 21:35:02 -0700 | [diff] [blame] | 2789 | |
Winson Chung | 5af42fc | 2017-03-24 17:11:33 -0700 | [diff] [blame] | 2790 | // If we are moving from the pinned stack, then the animation takes care of updating |
| 2791 | // the picture-in-picture mode. |
Wale Ogunwale | 04a05ac | 2017-09-17 21:35:02 -0700 | [diff] [blame] | 2792 | final boolean schedulePictureInPictureModeChange = inPinnedWindowingMode; |
Wale Ogunwale | 9dcf946 | 2017-09-19 15:13:01 -0700 | [diff] [blame] | 2793 | final ArrayList<TaskRecord> tasks = fromStack.getAllTasks(); |
Wale Ogunwale | 04a05ac | 2017-09-17 21:35:02 -0700 | [diff] [blame] | 2794 | |
Wale Ogunwale | 388945c | 2017-10-04 12:13:46 -0700 | [diff] [blame] | 2795 | if (!tasks.isEmpty()) { |
Wale Ogunwale | 7e1f5f5 | 2017-10-18 15:19:59 -0700 | [diff] [blame] | 2796 | mTmpOptions.setLaunchWindowingMode(WINDOWING_MODE_FULLSCREEN); |
Wale Ogunwale | 388945c | 2017-10-04 12:13:46 -0700 | [diff] [blame] | 2797 | final int size = tasks.size(); |
Wale Ogunwale | 7e1f5f5 | 2017-10-18 15:19:59 -0700 | [diff] [blame] | 2798 | for (int i = 0; i < size; ++i) { |
| 2799 | final TaskRecord task = tasks.get(i); |
| 2800 | final ActivityStack toStack = toDisplay.getOrCreateStack( |
| 2801 | null, mTmpOptions, task, task.getActivityType(), onTop); |
Wale Ogunwale | 388945c | 2017-10-04 12:13:46 -0700 | [diff] [blame] | 2802 | |
Wale Ogunwale | 7e1f5f5 | 2017-10-18 15:19:59 -0700 | [diff] [blame] | 2803 | if (onTop) { |
Wale Ogunwale | 388945c | 2017-10-04 12:13:46 -0700 | [diff] [blame] | 2804 | final boolean isTopTask = i == (size - 1); |
Wale Ogunwale | 388945c | 2017-10-04 12:13:46 -0700 | [diff] [blame] | 2805 | // 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] | 2806 | task.reparent(toStack, ON_TOP, REPARENT_MOVE_STACK_TO_FRONT, |
Wale Ogunwale | 388945c | 2017-10-04 12:13:46 -0700 | [diff] [blame] | 2807 | isTopTask /* animate */, DEFER_RESUME, |
| 2808 | schedulePictureInPictureModeChange, |
| 2809 | "moveTasksToFullscreenStack - onTop"); |
Chenjie Yu | ae9fdf04 | 2018-02-15 10:19:32 -0800 | [diff] [blame] | 2810 | MetricsLoggerWrapper.logPictureInPictureFullScreen(mService.mContext, |
| 2811 | task.effectiveUid, task.realActivity.flattenToString()); |
Wale Ogunwale | 7e1f5f5 | 2017-10-18 15:19:59 -0700 | [diff] [blame] | 2812 | } else { |
Wale Ogunwale | 388945c | 2017-10-04 12:13:46 -0700 | [diff] [blame] | 2813 | // Position the tasks in the fullscreen stack in order at the bottom of the |
| 2814 | // stack. Also defer resume until all the tasks have been moved to the |
| 2815 | // fullscreen stack. |
Wale Ogunwale | 7e1f5f5 | 2017-10-18 15:19:59 -0700 | [diff] [blame] | 2816 | task.reparent(toStack, ON_TOP, |
Wale Ogunwale | 388945c | 2017-10-04 12:13:46 -0700 | [diff] [blame] | 2817 | REPARENT_LEAVE_STACK_IN_PLACE, !ANIMATE, DEFER_RESUME, |
| 2818 | schedulePictureInPictureModeChange, |
| 2819 | "moveTasksToFullscreenStack - NOT_onTop"); |
| 2820 | } |
Wale Ogunwale | c8da41e | 2016-04-16 13:27:23 -0700 | [diff] [blame] | 2821 | } |
| 2822 | } |
Winson Chung | 7466610 | 2017-02-22 17:49:24 -0800 | [diff] [blame] | 2823 | |
| 2824 | ensureActivitiesVisibleLocked(null, 0, PRESERVE_WINDOWS); |
| 2825 | resumeFocusedStackTopActivityLocked(); |
Wale Ogunwale | c8da41e | 2016-04-16 13:27:23 -0700 | [diff] [blame] | 2826 | } finally { |
| 2827 | mAllowDockedStackResize = true; |
| 2828 | mWindowManager.continueSurfaceLayout(); |
| 2829 | } |
| 2830 | } |
| 2831 | |
Wale Ogunwale | 9dcf946 | 2017-09-19 15:13:01 -0700 | [diff] [blame] | 2832 | void moveTasksToFullscreenStackLocked(ActivityStack fromStack, boolean onTop) { |
Wale Ogunwale | 04a05ac | 2017-09-17 21:35:02 -0700 | [diff] [blame] | 2833 | moveTasksToFullscreenStackLocked(fromStack, DEFAULT_DISPLAY, onTop); |
| 2834 | } |
| 2835 | |
| 2836 | void moveTasksToFullscreenStackLocked(ActivityStack fromStack, int toDisplayId, boolean onTop) { |
| 2837 | mWindowManager.inSurfaceTransaction(() -> |
| 2838 | moveTasksToFullscreenStackInSurfaceTransaction(fromStack, toDisplayId, onTop)); |
Robert Carr | 6914f08 | 2017-03-20 19:04:30 -0700 | [diff] [blame] | 2839 | } |
| 2840 | |
Adrian Roos | a6d6aab | 2018-04-19 18:58:22 +0200 | [diff] [blame] | 2841 | void setSplitScreenResizing(boolean resizing) { |
| 2842 | if (resizing == mDockedStackResizing) { |
| 2843 | return; |
| 2844 | } |
| 2845 | |
| 2846 | mDockedStackResizing = resizing; |
| 2847 | mWindowManager.setDockedStackResizing(resizing); |
| 2848 | |
| 2849 | if (!resizing && mHasPendingDockedBounds) { |
| 2850 | resizeDockedStackLocked(mPendingDockedBounds, mPendingTempDockedTaskBounds, |
| 2851 | mPendingTempDockedTaskInsetBounds, mPendingTempOtherTaskBounds, |
| 2852 | mPendingTempOtherTaskInsetBounds, PRESERVE_WINDOWS); |
| 2853 | |
| 2854 | mHasPendingDockedBounds = false; |
| 2855 | mPendingDockedBounds = null; |
| 2856 | mPendingTempDockedTaskBounds = null; |
| 2857 | mPendingTempDockedTaskInsetBounds = null; |
| 2858 | mPendingTempOtherTaskBounds = null; |
| 2859 | mPendingTempOtherTaskInsetBounds = null; |
| 2860 | } |
| 2861 | } |
| 2862 | |
Jorim Jaggi | dc249c4 | 2015-12-15 14:57:31 -0800 | [diff] [blame] | 2863 | void resizeDockedStackLocked(Rect dockedBounds, Rect tempDockedTaskBounds, |
Andrii Kulian | db3e4ec | 2016-07-12 17:11:35 -0700 | [diff] [blame] | 2864 | Rect tempDockedTaskInsetBounds, Rect tempOtherTaskBounds, Rect tempOtherTaskInsetBounds, |
| 2865 | boolean preserveWindows) { |
| 2866 | resizeDockedStackLocked(dockedBounds, tempDockedTaskBounds, tempDockedTaskInsetBounds, |
| 2867 | tempOtherTaskBounds, tempOtherTaskInsetBounds, preserveWindows, |
| 2868 | false /* deferResume */); |
| 2869 | } |
| 2870 | |
Wale Ogunwale | 04a05ac | 2017-09-17 21:35:02 -0700 | [diff] [blame] | 2871 | private void resizeDockedStackLocked(Rect dockedBounds, Rect tempDockedTaskBounds, |
Andrii Kulian | db3e4ec | 2016-07-12 17:11:35 -0700 | [diff] [blame] | 2872 | Rect tempDockedTaskInsetBounds, Rect tempOtherTaskBounds, Rect tempOtherTaskInsetBounds, |
| 2873 | boolean preserveWindows, boolean deferResume) { |
Wale Ogunwale | c8da41e | 2016-04-16 13:27:23 -0700 | [diff] [blame] | 2874 | |
| 2875 | if (!mAllowDockedStackResize) { |
| 2876 | // Docked stack resize currently disabled. |
| 2877 | return; |
| 2878 | } |
| 2879 | |
Wale Ogunwale | a0f5b5e | 2017-10-11 09:37:23 -0700 | [diff] [blame] | 2880 | final ActivityStack stack = getDefaultDisplay().getSplitScreenPrimaryStack(); |
Jorim Jaggi | dc249c4 | 2015-12-15 14:57:31 -0800 | [diff] [blame] | 2881 | if (stack == null) { |
| 2882 | Slog.w(TAG, "resizeDockedStackLocked: docked stack not found"); |
| 2883 | return; |
| 2884 | } |
| 2885 | |
Adrian Roos | a6d6aab | 2018-04-19 18:58:22 +0200 | [diff] [blame] | 2886 | if (mDockedStackResizing) { |
| 2887 | mHasPendingDockedBounds = true; |
| 2888 | mPendingDockedBounds = copyOrNull(dockedBounds); |
| 2889 | mPendingTempDockedTaskBounds = copyOrNull(tempDockedTaskBounds); |
| 2890 | mPendingTempDockedTaskInsetBounds = copyOrNull(tempDockedTaskInsetBounds); |
| 2891 | mPendingTempOtherTaskBounds = copyOrNull(tempOtherTaskBounds); |
| 2892 | mPendingTempOtherTaskInsetBounds = copyOrNull(tempOtherTaskInsetBounds); |
| 2893 | } |
| 2894 | |
Jorim Jaggi | dc249c4 | 2015-12-15 14:57:31 -0800 | [diff] [blame] | 2895 | Trace.traceBegin(TRACE_TAG_ACTIVITY_MANAGER, "am.resizeDockedStack"); |
| 2896 | mWindowManager.deferSurfaceLayout(); |
| 2897 | try { |
Wale Ogunwale | c8da41e | 2016-04-16 13:27:23 -0700 | [diff] [blame] | 2898 | // Don't allow re-entry while resizing. E.g. due to docked stack detaching. |
| 2899 | mAllowDockedStackResize = false; |
Jorim Jaggi | dc249c4 | 2015-12-15 14:57:31 -0800 | [diff] [blame] | 2900 | ActivityRecord r = stack.topRunningActivityLocked(); |
Wale Ogunwale | 1666e31 | 2016-12-16 11:27:18 -0800 | [diff] [blame] | 2901 | stack.resize(dockedBounds, tempDockedTaskBounds, tempDockedTaskInsetBounds); |
Jorim Jaggi | dc249c4 | 2015-12-15 14:57:31 -0800 | [diff] [blame] | 2902 | |
Andrii Kulian | 69fb5e4 | 2016-04-05 16:47:29 -0700 | [diff] [blame] | 2903 | // TODO: Checking for isAttached might not be needed as if the user passes in null |
| 2904 | // dockedBounds then they want the docked stack to be dismissed. |
Bryce Lee | f3c6a47 | 2017-11-14 14:53:06 -0800 | [diff] [blame] | 2905 | if (stack.getWindowingMode() == WINDOWING_MODE_FULLSCREEN |
| 2906 | || (dockedBounds == null && !stack.isAttached())) { |
Andrii Kulian | 69fb5e4 | 2016-04-05 16:47:29 -0700 | [diff] [blame] | 2907 | // 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] | 2908 | // In this case we make all other static stacks fullscreen and move all |
| 2909 | // docked stack tasks to the fullscreen stack. |
Wale Ogunwale | 9dcf946 | 2017-09-19 15:13:01 -0700 | [diff] [blame] | 2910 | moveTasksToFullscreenStackLocked(stack, ON_TOP); |
Jorim Jaggi | dc249c4 | 2015-12-15 14:57:31 -0800 | [diff] [blame] | 2911 | |
| 2912 | // stack shouldn't contain anymore activities, so nothing to resume. |
| 2913 | r = null; |
| 2914 | } else { |
| 2915 | // Docked stacks occupy a dedicated region on screen so the size of all other |
| 2916 | // static stacks need to be adjusted so they don't overlap with the docked stack. |
| 2917 | // We get the bounds to use from window manager which has been adjusted for any |
| 2918 | // screen controls and is also the same for all stacks. |
Wale Ogunwale | a0f5b5e | 2017-10-11 09:37:23 -0700 | [diff] [blame] | 2919 | final ActivityDisplay display = getDefaultDisplay(); |
Matthew Ng | aa2b620 | 2017-02-10 14:48:21 -0800 | [diff] [blame] | 2920 | final Rect otherTaskRect = new Rect(); |
Wale Ogunwale | a0f5b5e | 2017-10-11 09:37:23 -0700 | [diff] [blame] | 2921 | for (int i = display.getChildCount() - 1; i >= 0; --i) { |
| 2922 | final ActivityStack current = display.getChildAt(i); |
Wale Ogunwale | 04a05ac | 2017-09-17 21:35:02 -0700 | [diff] [blame] | 2923 | if (current.getWindowingMode() == WINDOWING_MODE_SPLIT_SCREEN_PRIMARY) { |
Wale Ogunwale | 926aade | 2017-08-29 11:24:37 -0700 | [diff] [blame] | 2924 | continue; |
Jorim Jaggi | dc249c4 | 2015-12-15 14:57:31 -0800 | [diff] [blame] | 2925 | } |
Wale Ogunwale | 2b07da8 | 2017-11-08 14:52:40 -0800 | [diff] [blame] | 2926 | if (!current.affectedBySplitScreenResize()) { |
Wale Ogunwale | 926aade | 2017-08-29 11:24:37 -0700 | [diff] [blame] | 2927 | continue; |
| 2928 | } |
Adrian Roos | a6d6aab | 2018-04-19 18:58:22 +0200 | [diff] [blame] | 2929 | if (mDockedStackResizing && !current.isTopActivityVisible()) { |
| 2930 | // Non-visible stacks get resized once we're done with the resize |
| 2931 | // interaction. |
| 2932 | continue; |
| 2933 | } |
Wale Ogunwale | 926aade | 2017-08-29 11:24:37 -0700 | [diff] [blame] | 2934 | // Need to set windowing mode here before we try to get the dock bounds. |
| 2935 | current.setWindowingMode(WINDOWING_MODE_SPLIT_SCREEN_SECONDARY); |
| 2936 | current.getStackDockedModeBounds( |
| 2937 | tempOtherTaskBounds /* currentTempTaskBounds */, |
| 2938 | tempRect /* outStackBounds */, |
| 2939 | otherTaskRect /* outTempTaskBounds */, true /* ignoreVisibility */); |
| 2940 | |
Wale Ogunwale | 44f036f | 2017-09-29 05:09:09 -0700 | [diff] [blame] | 2941 | resizeStackLocked(current, !tempRect.isEmpty() ? tempRect : null, |
Wale Ogunwale | 926aade | 2017-08-29 11:24:37 -0700 | [diff] [blame] | 2942 | !otherTaskRect.isEmpty() ? otherTaskRect : tempOtherTaskBounds, |
| 2943 | tempOtherTaskInsetBounds, preserveWindows, |
| 2944 | true /* allowResizeInDockedMode */, deferResume); |
Jorim Jaggi | dc249c4 | 2015-12-15 14:57:31 -0800 | [diff] [blame] | 2945 | } |
| 2946 | } |
Andrii Kulian | db3e4ec | 2016-07-12 17:11:35 -0700 | [diff] [blame] | 2947 | if (!deferResume) { |
| 2948 | stack.ensureVisibleActivitiesConfigurationLocked(r, preserveWindows); |
| 2949 | } |
Jorim Jaggi | dc249c4 | 2015-12-15 14:57:31 -0800 | [diff] [blame] | 2950 | } finally { |
Wale Ogunwale | c8da41e | 2016-04-16 13:27:23 -0700 | [diff] [blame] | 2951 | mAllowDockedStackResize = true; |
Jorim Jaggi | dc249c4 | 2015-12-15 14:57:31 -0800 | [diff] [blame] | 2952 | mWindowManager.continueSurfaceLayout(); |
| 2953 | Trace.traceEnd(TRACE_TAG_ACTIVITY_MANAGER); |
| 2954 | } |
Jorim Jaggi | dc249c4 | 2015-12-15 14:57:31 -0800 | [diff] [blame] | 2955 | } |
| 2956 | |
Robert Carr | 0d00c2e | 2016-02-29 17:45:02 -0800 | [diff] [blame] | 2957 | void resizePinnedStackLocked(Rect pinnedBounds, Rect tempPinnedTaskBounds) { |
Wale Ogunwale | 04a05ac | 2017-09-17 21:35:02 -0700 | [diff] [blame] | 2958 | // TODO(multi-display): Pinned stack display should be passed in. |
Wale Ogunwale | a0f5b5e | 2017-10-11 09:37:23 -0700 | [diff] [blame] | 2959 | final PinnedActivityStack stack = getDefaultDisplay().getPinnedStack(); |
Robert Carr | 0d00c2e | 2016-02-29 17:45:02 -0800 | [diff] [blame] | 2960 | if (stack == null) { |
| 2961 | Slog.w(TAG, "resizePinnedStackLocked: pinned stack not found"); |
| 2962 | return; |
| 2963 | } |
Winson Chung | 19953ca | 2017-04-11 11:19:23 -0700 | [diff] [blame] | 2964 | |
| 2965 | // It is possible for the bounds animation from the WM to call this but be delayed by |
| 2966 | // another AM call that is holding the AMS lock. In such a case, the pinnedBounds may be |
| 2967 | // incorrect if AMS.resizeStackWithBoundsFromWindowManager() is already called while waiting |
| 2968 | // for the AMS lock to be freed. So check and make sure these bounds are still good. |
| 2969 | final PinnedStackWindowController stackController = stack.getWindowContainerController(); |
Winson Chung | 8bca9e4 | 2017-04-16 15:59:43 -0700 | [diff] [blame] | 2970 | if (stackController.pinnedStackResizeDisallowed()) { |
Winson Chung | 19953ca | 2017-04-11 11:19:23 -0700 | [diff] [blame] | 2971 | return; |
| 2972 | } |
| 2973 | |
Robert Carr | 0d00c2e | 2016-02-29 17:45:02 -0800 | [diff] [blame] | 2974 | Trace.traceBegin(TRACE_TAG_ACTIVITY_MANAGER, "am.resizePinnedStack"); |
| 2975 | mWindowManager.deferSurfaceLayout(); |
| 2976 | try { |
| 2977 | ActivityRecord r = stack.topRunningActivityLocked(); |
Robert Carr | 7e4c90e | 2017-02-15 19:52:38 -0800 | [diff] [blame] | 2978 | Rect insetBounds = null; |
Adrian Roos | 3e80b60 | 2018-04-30 12:42:36 +0200 | [diff] [blame] | 2979 | if (tempPinnedTaskBounds != null && stack.isAnimatingBoundsToFullscreen()) { |
| 2980 | // Use 0,0 as the position for the inset rect because we are headed for fullscreen. |
Robert Carr | 7e4c90e | 2017-02-15 19:52:38 -0800 | [diff] [blame] | 2981 | insetBounds = tempRect; |
| 2982 | insetBounds.top = 0; |
| 2983 | insetBounds.left = 0; |
| 2984 | insetBounds.right = tempPinnedTaskBounds.width(); |
| 2985 | insetBounds.bottom = tempPinnedTaskBounds.height(); |
| 2986 | } |
Winson Chung | 15036ca | 2018-05-31 15:51:47 -0700 | [diff] [blame] | 2987 | if (pinnedBounds != null && tempPinnedTaskBounds == null) { |
| 2988 | // We have finished the animation into PiP, and are resizing the tasks to match the |
| 2989 | // stack bounds, while layouts are deferred, update any task state as a part of |
| 2990 | // transitioning it from fullscreen into a floating state. |
| 2991 | stack.onPipAnimationEndResize(); |
| 2992 | } |
Robert Carr | 7e4c90e | 2017-02-15 19:52:38 -0800 | [diff] [blame] | 2993 | stack.resize(pinnedBounds, tempPinnedTaskBounds, insetBounds); |
Wale Ogunwale | db0fa12 | 2016-05-16 15:12:03 -0700 | [diff] [blame] | 2994 | stack.ensureVisibleActivitiesConfigurationLocked(r, false); |
Robert Carr | 0d00c2e | 2016-02-29 17:45:02 -0800 | [diff] [blame] | 2995 | } finally { |
| 2996 | mWindowManager.continueSurfaceLayout(); |
| 2997 | Trace.traceEnd(TRACE_TAG_ACTIVITY_MANAGER); |
| 2998 | } |
| 2999 | } |
| 3000 | |
Wale Ogunwale | a0f5b5e | 2017-10-11 09:37:23 -0700 | [diff] [blame] | 3001 | private void removeStackInSurfaceTransaction(ActivityStack stack) { |
Winson Chung | 010927a | 2016-12-15 16:12:35 -0800 | [diff] [blame] | 3002 | final ArrayList<TaskRecord> tasks = stack.getAllTasks(); |
Wale Ogunwale | 04a05ac | 2017-09-17 21:35:02 -0700 | [diff] [blame] | 3003 | if (stack.getWindowingMode() == WINDOWING_MODE_PINNED) { |
Winson Chung | 4790065 | 2017-04-06 18:44:25 -0700 | [diff] [blame] | 3004 | /** |
| 3005 | * Workaround: Force-stop all the activities in the pinned stack before we reparent them |
| 3006 | * to the fullscreen stack. This is to guarantee that when we are removing a stack, |
| 3007 | * that the client receives onStop() before it is reparented. We do this by detaching |
| 3008 | * the stack from the display so that it will be considered invisible when |
| 3009 | * ensureActivitiesVisibleLocked() is called, and all of its activitys will be marked |
| 3010 | * invisible as well and added to the stopping list. After which we process the |
| 3011 | * stopping list by handling the idle. |
| 3012 | */ |
| 3013 | final PinnedActivityStack pinnedStack = (PinnedActivityStack) stack; |
| 3014 | pinnedStack.mForceHidden = true; |
| 3015 | pinnedStack.ensureActivitiesVisibleLocked(null, 0, PRESERVE_WINDOWS); |
| 3016 | pinnedStack.mForceHidden = false; |
| 3017 | activityIdleInternalLocked(null, false /* fromTimeout */, |
| 3018 | true /* processPausingActivites */, null /* configuration */); |
| 3019 | |
| 3020 | // Move all the tasks to the bottom of the fullscreen stack |
Wale Ogunwale | 9dcf946 | 2017-09-19 15:13:01 -0700 | [diff] [blame] | 3021 | moveTasksToFullscreenStackLocked(pinnedStack, !ON_TOP); |
Winson Chung | 010927a | 2016-12-15 16:12:35 -0800 | [diff] [blame] | 3022 | } else { |
| 3023 | for (int i = tasks.size() - 1; i >= 0; i--) { |
| 3024 | removeTaskByIdLocked(tasks.get(i).taskId, true /* killProcess */, |
Winson Chung | 0ec2a35 | 2017-10-26 11:38:30 -0700 | [diff] [blame] | 3025 | REMOVE_FROM_RECENTS, "remove-stack"); |
Winson Chung | 010927a | 2016-12-15 16:12:35 -0800 | [diff] [blame] | 3026 | } |
| 3027 | } |
| 3028 | } |
| 3029 | |
| 3030 | /** |
Wale Ogunwale | a0f5b5e | 2017-10-11 09:37:23 -0700 | [diff] [blame] | 3031 | * 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] | 3032 | * pinned stack, then its tasks are not explicitly removed when the stack is destroyed, but |
| 3033 | * instead moved back onto the fullscreen stack. |
| 3034 | */ |
Wale Ogunwale | a0f5b5e | 2017-10-11 09:37:23 -0700 | [diff] [blame] | 3035 | void removeStack(ActivityStack stack) { |
| 3036 | mWindowManager.inSurfaceTransaction(() -> removeStackInSurfaceTransaction(stack)); |
Wale Ogunwale | 04a05ac | 2017-09-17 21:35:02 -0700 | [diff] [blame] | 3037 | } |
| 3038 | |
Wale Ogunwale | 6827856 | 2017-09-23 17:13:55 -0700 | [diff] [blame] | 3039 | /** |
| 3040 | * Removes stacks in the input windowing modes from the system if they are of activity type |
| 3041 | * ACTIVITY_TYPE_STANDARD or ACTIVITY_TYPE_UNDEFINED |
| 3042 | */ |
| 3043 | void removeStacksInWindowingModes(int... windowingModes) { |
Wale Ogunwale | 04a05ac | 2017-09-17 21:35:02 -0700 | [diff] [blame] | 3044 | for (int i = mActivityDisplays.size() - 1; i >= 0; --i) { |
Wale Ogunwale | 6827856 | 2017-09-23 17:13:55 -0700 | [diff] [blame] | 3045 | mActivityDisplays.valueAt(i).removeStacksInWindowingModes(windowingModes); |
| 3046 | } |
| 3047 | } |
| 3048 | |
| 3049 | void removeStacksWithActivityTypes(int... activityTypes) { |
| 3050 | for (int i = mActivityDisplays.size() - 1; i >= 0; --i) { |
| 3051 | mActivityDisplays.valueAt(i).removeStacksWithActivityTypes(activityTypes); |
Wale Ogunwale | 04a05ac | 2017-09-17 21:35:02 -0700 | [diff] [blame] | 3052 | } |
Robert Carr | 6914f08 | 2017-03-20 19:04:30 -0700 | [diff] [blame] | 3053 | } |
| 3054 | |
| 3055 | /** |
Winson Chung | 6954fc9 | 2017-03-24 16:22:12 -0700 | [diff] [blame] | 3056 | * See {@link #removeTaskByIdLocked(int, boolean, boolean, boolean)} |
| 3057 | */ |
Winson Chung | 0ec2a35 | 2017-10-26 11:38:30 -0700 | [diff] [blame] | 3058 | boolean removeTaskByIdLocked(int taskId, boolean killProcess, boolean removeFromRecents, |
| 3059 | String reason) { |
| 3060 | return removeTaskByIdLocked(taskId, killProcess, removeFromRecents, !PAUSE_IMMEDIATELY, |
| 3061 | reason); |
Winson Chung | 6954fc9 | 2017-03-24 16:22:12 -0700 | [diff] [blame] | 3062 | } |
| 3063 | |
| 3064 | /** |
Winson Chung | 010927a | 2016-12-15 16:12:35 -0800 | [diff] [blame] | 3065 | * Removes the task with the specified task id. |
| 3066 | * |
| 3067 | * @param taskId Identifier of the task to be removed. |
| 3068 | * @param killProcess Kill any process associated with the task if possible. |
| 3069 | * @param removeFromRecents Whether to also remove the task from recents. |
Winson Chung | 6954fc9 | 2017-03-24 16:22:12 -0700 | [diff] [blame] | 3070 | * @param pauseImmediately Pauses all task activities immediately without waiting for the |
| 3071 | * pause-complete callback from the activity. |
Winson Chung | 010927a | 2016-12-15 16:12:35 -0800 | [diff] [blame] | 3072 | * @return Returns true if the given task was found and removed. |
| 3073 | */ |
Winson Chung | 6954fc9 | 2017-03-24 16:22:12 -0700 | [diff] [blame] | 3074 | boolean removeTaskByIdLocked(int taskId, boolean killProcess, boolean removeFromRecents, |
Winson Chung | 0ec2a35 | 2017-10-26 11:38:30 -0700 | [diff] [blame] | 3075 | boolean pauseImmediately, String reason) { |
Wale Ogunwale | 0568aed | 2017-09-08 13:29:37 -0700 | [diff] [blame] | 3076 | final TaskRecord tr = anyTaskForIdLocked(taskId, MATCH_TASK_IN_STACKS_OR_RECENT_TASKS); |
Winson Chung | 010927a | 2016-12-15 16:12:35 -0800 | [diff] [blame] | 3077 | if (tr != null) { |
Winson Chung | 0ec2a35 | 2017-10-26 11:38:30 -0700 | [diff] [blame] | 3078 | tr.removeTaskActivitiesLocked(pauseImmediately, reason); |
Winson Chung | 010927a | 2016-12-15 16:12:35 -0800 | [diff] [blame] | 3079 | cleanUpRemovedTaskLocked(tr, killProcess, removeFromRecents); |
Bryce Lee | 2b8e037 | 2018-04-05 17:01:37 -0700 | [diff] [blame] | 3080 | mService.getLockTaskController().clearLockedTask(tr); |
Winson Chung | 010927a | 2016-12-15 16:12:35 -0800 | [diff] [blame] | 3081 | if (tr.isPersistable) { |
| 3082 | mService.notifyTaskPersisterLocked(null, true); |
| 3083 | } |
| 3084 | return true; |
| 3085 | } |
| 3086 | Slog.w(TAG, "Request to remove task ignored for non-existent task " + taskId); |
| 3087 | return false; |
| 3088 | } |
| 3089 | |
| 3090 | void cleanUpRemovedTaskLocked(TaskRecord tr, boolean killProcess, boolean removeFromRecents) { |
| 3091 | if (removeFromRecents) { |
Winson Chung | 1dbc811 | 2017-09-28 18:05:31 -0700 | [diff] [blame] | 3092 | mRecentTasks.remove(tr); |
Winson Chung | 010927a | 2016-12-15 16:12:35 -0800 | [diff] [blame] | 3093 | } |
| 3094 | ComponentName component = tr.getBaseIntent().getComponent(); |
| 3095 | if (component == null) { |
| 3096 | Slog.w(TAG, "No component for base intent of task: " + tr); |
| 3097 | return; |
| 3098 | } |
| 3099 | |
| 3100 | // Find any running services associated with this app and stop if needed. |
| 3101 | mService.mServices.cleanUpRemovedTaskLocked(tr, component, new Intent(tr.getBaseIntent())); |
| 3102 | |
| 3103 | if (!killProcess) { |
| 3104 | return; |
| 3105 | } |
| 3106 | |
| 3107 | // Determine if the process(es) for this task should be killed. |
| 3108 | final String pkg = component.getPackageName(); |
| 3109 | ArrayList<ProcessRecord> procsToKill = new ArrayList<>(); |
| 3110 | ArrayMap<String, SparseArray<ProcessRecord>> pmap = mService.mProcessNames.getMap(); |
| 3111 | for (int i = 0; i < pmap.size(); i++) { |
| 3112 | |
| 3113 | SparseArray<ProcessRecord> uids = pmap.valueAt(i); |
| 3114 | for (int j = 0; j < uids.size(); j++) { |
| 3115 | ProcessRecord proc = uids.valueAt(j); |
| 3116 | if (proc.userId != tr.userId) { |
| 3117 | // Don't kill process for a different user. |
| 3118 | continue; |
| 3119 | } |
| 3120 | if (proc == mService.mHomeProcess) { |
| 3121 | // Don't kill the home process along with tasks from the same package. |
| 3122 | continue; |
| 3123 | } |
| 3124 | if (!proc.pkgList.containsKey(pkg)) { |
| 3125 | // Don't kill process that is not associated with this task. |
| 3126 | continue; |
| 3127 | } |
| 3128 | |
| 3129 | for (int k = 0; k < proc.activities.size(); k++) { |
Bryce Lee | af691c0 | 2017-03-20 14:20:22 -0700 | [diff] [blame] | 3130 | TaskRecord otherTask = proc.activities.get(k).getTask(); |
Winson Chung | 010927a | 2016-12-15 16:12:35 -0800 | [diff] [blame] | 3131 | if (tr.taskId != otherTask.taskId && otherTask.inRecents) { |
| 3132 | // Don't kill process(es) that has an activity in a different task that is |
| 3133 | // also in recents. |
| 3134 | return; |
| 3135 | } |
| 3136 | } |
| 3137 | |
| 3138 | if (proc.foregroundServices) { |
| 3139 | // Don't kill process(es) with foreground service. |
| 3140 | return; |
| 3141 | } |
| 3142 | |
| 3143 | // Add process to kill list. |
| 3144 | procsToKill.add(proc); |
| 3145 | } |
| 3146 | } |
| 3147 | |
| 3148 | // Kill the running processes. |
| 3149 | for (int i = 0; i < procsToKill.size(); i++) { |
| 3150 | ProcessRecord pr = procsToKill.get(i); |
| 3151 | if (pr.setSchedGroup == ProcessList.SCHED_GROUP_BACKGROUND |
| 3152 | && pr.curReceivers.isEmpty()) { |
| 3153 | pr.kill("remove task", true); |
| 3154 | } else { |
| 3155 | // We delay killing processes that are not in the background or running a receiver. |
| 3156 | pr.waitingToKill = "remove task"; |
| 3157 | } |
| 3158 | } |
| 3159 | } |
| 3160 | |
Chong Zhang | 5dcb275 | 2015-08-18 13:50:26 -0700 | [diff] [blame] | 3161 | /** |
Winson Chung | 1dbc811 | 2017-09-28 18:05:31 -0700 | [diff] [blame] | 3162 | * Called to restore the state of the task into the stack that it's supposed to go into. |
| 3163 | * |
Chong Zhang | 5dcb275 | 2015-08-18 13:50:26 -0700 | [diff] [blame] | 3164 | * @param task The recent task to be restored. |
Wale Ogunwale | 0568aed | 2017-09-08 13:29:37 -0700 | [diff] [blame] | 3165 | * @param aOptions The activity options to use for restoration. |
Wale Ogunwale | ab5de37 | 2017-10-18 06:46:31 -0700 | [diff] [blame] | 3166 | * @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] | 3167 | * @return true if the task has been restored successfully. |
| 3168 | */ |
Wale Ogunwale | ab5de37 | 2017-10-18 06:46:31 -0700 | [diff] [blame] | 3169 | boolean restoreRecentTaskLocked(TaskRecord task, ActivityOptions aOptions, boolean onTop) { |
| 3170 | final ActivityStack stack = getLaunchStack(null, aOptions, task, onTop); |
Andrii Kulian | 02b7a83 | 2016-10-06 23:11:56 -0700 | [diff] [blame] | 3171 | final ActivityStack currentStack = task.getStack(); |
| 3172 | if (currentStack != null) { |
Wale Ogunwale | 706ed79 | 2015-08-02 10:29:44 -0700 | [diff] [blame] | 3173 | // 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] | 3174 | if (currentStack == stack) { |
Wale Ogunwale | 706ed79 | 2015-08-02 10:29:44 -0700 | [diff] [blame] | 3175 | // Nothing else to do since it is already restored in the right stack. |
| 3176 | return true; |
| 3177 | } |
| 3178 | // Remove current stack association, so we can re-associate the task with the |
| 3179 | // right stack below. |
Andrii Kulian | 02b7a83 | 2016-10-06 23:11:56 -0700 | [diff] [blame] | 3180 | currentStack.removeTask(task, "restoreRecentTaskLocked", REMOVE_TASK_MODE_MOVING); |
Wale Ogunwale | 706ed79 | 2015-08-02 10:29:44 -0700 | [diff] [blame] | 3181 | } |
| 3182 | |
Wale Ogunwale | ab5de37 | 2017-10-18 06:46:31 -0700 | [diff] [blame] | 3183 | stack.addTask(task, onTop, "restoreRecentTask"); |
Wale Ogunwale | e1fe7fa2 | 2016-12-15 18:27:00 -0800 | [diff] [blame] | 3184 | // TODO: move call for creation here and other place into Stack.addTask() |
Wale Ogunwale | ab5de37 | 2017-10-18 06:46:31 -0700 | [diff] [blame] | 3185 | task.createWindowContainer(onTop, true /* showForAllUsers */); |
Wale Ogunwale | ee006da | 2015-03-30 14:49:25 -0700 | [diff] [blame] | 3186 | if (DEBUG_RECENTS) Slog.v(TAG_RECENTS, |
| 3187 | "Added restored task=" + task + " to stack=" + stack); |
Wale Ogunwale | 7de0535 | 2014-12-12 15:21:33 -0800 | [diff] [blame] | 3188 | final ArrayList<ActivityRecord> activities = task.mActivities; |
| 3189 | for (int activityNdx = activities.size() - 1; activityNdx >= 0; --activityNdx) { |
Wale Ogunwale | 26c0dfe | 2016-12-14 14:42:30 -0800 | [diff] [blame] | 3190 | activities.get(activityNdx).createWindowContainer(); |
Wale Ogunwale | 7de0535 | 2014-12-12 15:21:33 -0800 | [diff] [blame] | 3191 | } |
| 3192 | return true; |
Craig Mautner | ef73ee1 | 2014-04-23 11:45:37 -0700 | [diff] [blame] | 3193 | } |
| 3194 | |
Winson Chung | 1dbc811 | 2017-09-28 18:05:31 -0700 | [diff] [blame] | 3195 | @Override |
| 3196 | public void onRecentTaskAdded(TaskRecord task) { |
| 3197 | task.touchActiveTime(); |
| 3198 | } |
| 3199 | |
| 3200 | @Override |
Winson Chung | d6aa3db | 2017-10-05 17:18:43 -0700 | [diff] [blame] | 3201 | public void onRecentTaskRemoved(TaskRecord task, boolean wasTrimmed) { |
Winson Chung | 0ec2a35 | 2017-10-26 11:38:30 -0700 | [diff] [blame] | 3202 | if (wasTrimmed) { |
| 3203 | // Task was trimmed from the recent tasks list -- remove the active task record as well |
| 3204 | // since the user won't really be able to go back to it |
| 3205 | removeTaskByIdLocked(task.taskId, false /* killProcess */, |
| 3206 | false /* removeFromRecents */, !PAUSE_IMMEDIATELY, "recent-task-trimmed"); |
| 3207 | } |
Winson Chung | 1dbc811 | 2017-09-28 18:05:31 -0700 | [diff] [blame] | 3208 | task.removedFromRecents(); |
| 3209 | } |
| 3210 | |
Wale Ogunwale | 040b470 | 2015-08-06 18:10:50 -0700 | [diff] [blame] | 3211 | /** |
Andrii Kulian | 839def9 | 2016-11-02 10:58:58 -0700 | [diff] [blame] | 3212 | * Move stack with all its existing content to specified display. |
| 3213 | * @param stackId Id of stack to move. |
| 3214 | * @param displayId Id of display to move stack to. |
Andrii Kulian | 250d653 | 2017-02-08 23:30:45 -0800 | [diff] [blame] | 3215 | * @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] | 3216 | */ |
Andrii Kulian | 250d653 | 2017-02-08 23:30:45 -0800 | [diff] [blame] | 3217 | void moveStackToDisplayLocked(int stackId, int displayId, boolean onTop) { |
Andrii Kulian | 62e6f25 | 2017-05-30 22:46:53 -0700 | [diff] [blame] | 3218 | final ActivityDisplay activityDisplay = getActivityDisplayOrCreateLocked(displayId); |
Andrii Kulian | 839def9 | 2016-11-02 10:58:58 -0700 | [diff] [blame] | 3219 | if (activityDisplay == null) { |
| 3220 | throw new IllegalArgumentException("moveStackToDisplayLocked: Unknown displayId=" |
| 3221 | + displayId); |
| 3222 | } |
Wale Ogunwale | 9dcf946 | 2017-09-19 15:13:01 -0700 | [diff] [blame] | 3223 | final ActivityStack stack = getStack(stackId); |
Andrii Kulian | 94e82d9b0 | 2017-07-13 15:33:06 -0700 | [diff] [blame] | 3224 | if (stack == null) { |
Andrii Kulian | 839def9 | 2016-11-02 10:58:58 -0700 | [diff] [blame] | 3225 | throw new IllegalArgumentException("moveStackToDisplayLocked: Unknown stackId=" |
| 3226 | + stackId); |
| 3227 | } |
Andrii Kulian | 94e82d9b0 | 2017-07-13 15:33:06 -0700 | [diff] [blame] | 3228 | |
| 3229 | final ActivityDisplay currentDisplay = stack.getDisplay(); |
| 3230 | if (currentDisplay == null) { |
| 3231 | throw new IllegalStateException("moveStackToDisplayLocked: Stack with stack=" + stack |
| 3232 | + " is not attached to any display."); |
| 3233 | } |
| 3234 | |
| 3235 | if (currentDisplay.mDisplayId == displayId) { |
| 3236 | throw new IllegalArgumentException("Trying to move stack=" + stack |
| 3237 | + " to its current displayId=" + displayId); |
| 3238 | } |
| 3239 | |
| 3240 | stack.reparent(activityDisplay, onTop); |
Andrii Kulian | 839def9 | 2016-11-02 10:58:58 -0700 | [diff] [blame] | 3241 | // TODO(multi-display): resize stacks properly if moved from split-screen. |
| 3242 | } |
| 3243 | |
| 3244 | /** |
Winson Chung | 7466610 | 2017-02-22 17:49:24 -0800 | [diff] [blame] | 3245 | * Returns the reparent target stack, creating the stack if necessary. This call also enforces |
| 3246 | * 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] | 3247 | */ |
Wale Ogunwale | 30e441d | 2017-11-09 08:28:45 -0800 | [diff] [blame] | 3248 | // TODO: Look into changing users to this method to ActivityDisplay.resolveWindowingMode() |
Wale Ogunwale | 04a05ac | 2017-09-17 21:35:02 -0700 | [diff] [blame] | 3249 | ActivityStack getReparentTargetStack(TaskRecord task, ActivityStack stack, boolean toTop) { |
Andrii Kulian | 02b7a83 | 2016-10-06 23:11:56 -0700 | [diff] [blame] | 3250 | final ActivityStack prevStack = task.getStack(); |
Wale Ogunwale | 04a05ac | 2017-09-17 21:35:02 -0700 | [diff] [blame] | 3251 | final int stackId = stack.mStackId; |
| 3252 | final boolean inMultiWindowMode = stack.inMultiWindowMode(); |
Chong Zhang | 0289835 | 2015-08-21 17:27:14 -0700 | [diff] [blame] | 3253 | |
Winson Chung | 7466610 | 2017-02-22 17:49:24 -0800 | [diff] [blame] | 3254 | // Check that we aren't reparenting to the same stack that the task is already in |
| 3255 | if (prevStack != null && prevStack.mStackId == stackId) { |
| 3256 | Slog.w(TAG, "Can not reparent to same stack, task=" + task |
| 3257 | + " already in stackId=" + stackId); |
| 3258 | return prevStack; |
Wale Ogunwale | 513346d | 2016-01-27 10:55:01 -0800 | [diff] [blame] | 3259 | } |
| 3260 | |
Winson Chung | 7466610 | 2017-02-22 17:49:24 -0800 | [diff] [blame] | 3261 | // Ensure that we aren't trying to move into a multi-window stack without multi-window |
| 3262 | // support |
Wale Ogunwale | 04a05ac | 2017-09-17 21:35:02 -0700 | [diff] [blame] | 3263 | if (inMultiWindowMode && !mService.mSupportsMultiWindow) { |
Winson Chung | 7466610 | 2017-02-22 17:49:24 -0800 | [diff] [blame] | 3264 | throw new IllegalArgumentException("Device doesn't support multi-window, can not" |
Wale Ogunwale | 04a05ac | 2017-09-17 21:35:02 -0700 | [diff] [blame] | 3265 | + " reparent task=" + task + " to stack=" + stack); |
Winson Chung | c2baac0 | 2017-01-11 13:34:47 -0800 | [diff] [blame] | 3266 | } |
| 3267 | |
Andrii Kulian | eafd9db | 2017-04-05 22:01:35 -0700 | [diff] [blame] | 3268 | // Ensure that we're not moving a task to a dynamic stack if device doesn't support |
| 3269 | // multi-display. |
Wale Ogunwale | 04a05ac | 2017-09-17 21:35:02 -0700 | [diff] [blame] | 3270 | if (stack.mDisplayId != DEFAULT_DISPLAY && !mService.mSupportsMultiDisplay) { |
Andrii Kulian | eafd9db | 2017-04-05 22:01:35 -0700 | [diff] [blame] | 3271 | throw new IllegalArgumentException("Device doesn't support multi-display, can not" |
| 3272 | + " reparent task=" + task + " to stackId=" + stackId); |
| 3273 | } |
| 3274 | |
Wale Ogunwale | 30e441d | 2017-11-09 08:28:45 -0800 | [diff] [blame] | 3275 | // 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] | 3276 | if (stack.getWindowingMode() == WINDOWING_MODE_FREEFORM |
| 3277 | && !mService.mSupportsFreeformWindowManagement) { |
Winson Chung | 7466610 | 2017-02-22 17:49:24 -0800 | [diff] [blame] | 3278 | throw new IllegalArgumentException("Device doesn't support freeform, can not reparent" |
| 3279 | + " task=" + task); |
Wale Ogunwale | 08559dc | 2016-02-23 12:20:08 -0800 | [diff] [blame] | 3280 | } |
| 3281 | |
Wale Ogunwale | 7e1f5f5 | 2017-10-18 15:19:59 -0700 | [diff] [blame] | 3282 | // Leave the task in its current stack or a fullscreen stack if it isn't resizeable and the |
| 3283 | // preferred stack is in multi-window mode. |
Wale Ogunwale | 04a05ac | 2017-09-17 21:35:02 -0700 | [diff] [blame] | 3284 | if (inMultiWindowMode && !task.isResizeable()) { |
Wale Ogunwale | 7e1f5f5 | 2017-10-18 15:19:59 -0700 | [diff] [blame] | 3285 | Slog.w(TAG, "Can not move unresizeable task=" + task + " to multi-window stack=" + stack |
| 3286 | + " Moving to a fullscreen stack instead."); |
| 3287 | if (prevStack != null) { |
| 3288 | return prevStack; |
Wale Ogunwale | 04a05ac | 2017-09-17 21:35:02 -0700 | [diff] [blame] | 3289 | } |
Wale Ogunwale | 7e1f5f5 | 2017-10-18 15:19:59 -0700 | [diff] [blame] | 3290 | stack = stack.getDisplay().createStack( |
| 3291 | WINDOWING_MODE_FULLSCREEN, stack.getActivityType(), toTop); |
Filip Gruszczynski | 49b80af | 2015-09-24 09:04:26 -0700 | [diff] [blame] | 3292 | } |
Wale Ogunwale | 04a05ac | 2017-09-17 21:35:02 -0700 | [diff] [blame] | 3293 | return stack; |
Craig Mautner | 8d341ef | 2013-03-26 09:03:27 -0700 | [diff] [blame] | 3294 | } |
| 3295 | |
Winson Chung | 08f8189 | 2017-03-02 15:40:51 -0800 | [diff] [blame] | 3296 | boolean moveTopStackActivityToPinnedStackLocked(int stackId, Rect destBounds) { |
Wale Ogunwale | 04a05ac | 2017-09-17 21:35:02 -0700 | [diff] [blame] | 3297 | final ActivityStack stack = getStack(stackId); |
Wale Ogunwale | 079a004 | 2015-10-24 11:44:07 -0700 | [diff] [blame] | 3298 | if (stack == null) { |
| 3299 | throw new IllegalArgumentException( |
| 3300 | "moveTopStackActivityToPinnedStackLocked: Unknown stackId=" + stackId); |
| 3301 | } |
| 3302 | |
| 3303 | final ActivityRecord r = stack.topRunningActivityLocked(); |
| 3304 | if (r == null) { |
| 3305 | Slog.w(TAG, "moveTopStackActivityToPinnedStackLocked: No top running activity" |
| 3306 | + " in stack=" + stack); |
| 3307 | return false; |
| 3308 | } |
| 3309 | |
Wale Ogunwale | 6cae765 | 2015-12-26 07:36:26 -0800 | [diff] [blame] | 3310 | if (!mService.mForceResizableActivities && !r.supportsPictureInPicture()) { |
Wale Ogunwale | b60692e | 2015-10-24 12:35:56 -0700 | [diff] [blame] | 3311 | Slog.w(TAG, |
| 3312 | "moveTopStackActivityToPinnedStackLocked: Picture-In-Picture not supported for " |
Filip Gruszczynski | 77d9448 | 2015-12-11 13:59:52 -0800 | [diff] [blame] | 3313 | + " r=" + r); |
Wale Ogunwale | 079a004 | 2015-10-24 11:44:07 -0700 | [diff] [blame] | 3314 | return false; |
| 3315 | } |
| 3316 | |
Winson Chung | 3a68287 | 2017-04-10 14:38:05 -0700 | [diff] [blame] | 3317 | moveActivityToPinnedStackLocked(r, null /* sourceBounds */, 0f /* aspectRatio */, |
Wale Ogunwale | 66e1685 | 2017-10-19 13:35:52 -0700 | [diff] [blame] | 3318 | "moveTopActivityToPinnedStack"); |
Wale Ogunwale | 9c604c7 | 2015-12-06 18:42:57 -0800 | [diff] [blame] | 3319 | return true; |
| 3320 | } |
| 3321 | |
Winson Chung | 8bca9e4 | 2017-04-16 15:59:43 -0700 | [diff] [blame] | 3322 | void moveActivityToPinnedStackLocked(ActivityRecord r, Rect sourceHintBounds, float aspectRatio, |
Wale Ogunwale | 66e1685 | 2017-10-19 13:35:52 -0700 | [diff] [blame] | 3323 | String reason) { |
Winson Chung | 08f8189 | 2017-03-02 15:40:51 -0800 | [diff] [blame] | 3324 | |
Wale Ogunwale | 480dca0 | 2016-02-06 13:58:29 -0800 | [diff] [blame] | 3325 | mWindowManager.deferSurfaceLayout(); |
Winson Chung | 7466610 | 2017-02-22 17:49:24 -0800 | [diff] [blame] | 3326 | |
Wale Ogunwale | 04a05ac | 2017-09-17 21:35:02 -0700 | [diff] [blame] | 3327 | final ActivityDisplay display = r.getStack().getDisplay(); |
| 3328 | PinnedActivityStack stack = display.getPinnedStack(); |
Wale Ogunwale | 9dcf946 | 2017-09-19 15:13:01 -0700 | [diff] [blame] | 3329 | |
Bryce Lee | 04ab346 | 2017-04-10 15:06:33 -0700 | [diff] [blame] | 3330 | // This will clear the pinned stack by moving an existing task to the full screen stack, |
| 3331 | // ensuring only one task is present. |
Wale Ogunwale | 9dcf946 | 2017-09-19 15:13:01 -0700 | [diff] [blame] | 3332 | if (stack != null) { |
| 3333 | moveTasksToFullscreenStackLocked(stack, !ON_TOP); |
| 3334 | } |
Bryce Lee | 04ab346 | 2017-04-10 15:06:33 -0700 | [diff] [blame] | 3335 | |
Wale Ogunwale | 1666e31 | 2016-12-16 11:27:18 -0800 | [diff] [blame] | 3336 | // 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] | 3337 | stack = display.getOrCreateStack(WINDOWING_MODE_PINNED, r.getActivityType(), ON_TOP); |
Wale Ogunwale | 1666e31 | 2016-12-16 11:27:18 -0800 | [diff] [blame] | 3338 | |
Winson Chung | e55c019 | 2017-08-24 14:50:48 -0700 | [diff] [blame] | 3339 | // Calculate the target bounds here before the task is reparented back into pinned windowing |
| 3340 | // mode (which will reset the saved bounds) |
| 3341 | final Rect destBounds = stack.getDefaultPictureInPictureBounds(aspectRatio); |
| 3342 | |
Wale Ogunwale | 480dca0 | 2016-02-06 13:58:29 -0800 | [diff] [blame] | 3343 | try { |
Bryce Lee | af691c0 | 2017-03-20 14:20:22 -0700 | [diff] [blame] | 3344 | final TaskRecord task = r.getTask(); |
Wale Ogunwale | 480dca0 | 2016-02-06 13:58:29 -0800 | [diff] [blame] | 3345 | // Resize the pinned stack to match the current size of the task the activity we are |
| 3346 | // going to be moving is currently contained in. We do this to have the right starting |
| 3347 | // 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] | 3348 | resizeStackLocked(stack, task.getOverrideBounds(), null /* tempTaskBounds */, |
Wale Ogunwale | 480dca0 | 2016-02-06 13:58:29 -0800 | [diff] [blame] | 3349 | null /* tempTaskInsetBounds */, !PRESERVE_WINDOWS, |
Wale Ogunwale | c8da41e | 2016-04-16 13:27:23 -0700 | [diff] [blame] | 3350 | true /* allowResizeInDockedMode */, !DEFER_RESUME); |
Wale Ogunwale | 480dca0 | 2016-02-06 13:58:29 -0800 | [diff] [blame] | 3351 | |
| 3352 | if (task.mActivities.size() == 1) { |
Winson Chung | 5af42fc | 2017-03-24 17:11:33 -0700 | [diff] [blame] | 3353 | // 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] | 3354 | task.reparent(stack, ON_TOP, REPARENT_MOVE_STACK_TO_FRONT, !ANIMATE, DEFER_RESUME, |
| 3355 | false /* schedulePictureInPictureModeChange */, reason); |
Wale Ogunwale | 480dca0 | 2016-02-06 13:58:29 -0800 | [diff] [blame] | 3356 | } else { |
Winson Chung | b5c41b7 | 2016-12-07 15:00:47 -0800 | [diff] [blame] | 3357 | // 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] | 3358 | // reveal/leave the other activities in their original task. |
| 3359 | |
| 3360 | // Currently, we don't support reparenting activities across tasks in two different |
| 3361 | // stacks, so instead, just create a new task in the same stack, reparent the |
| 3362 | // activity into that task, and then reparent the whole task to the new stack. This |
| 3363 | // ensures that all the necessary work to migrate states in the old and new stacks |
| 3364 | // is also done. |
| 3365 | final TaskRecord newTask = task.getStack().createTaskRecord( |
Wale Ogunwale | 6fbde9f | 2017-08-24 07:24:12 -0700 | [diff] [blame] | 3366 | getNextTaskIdForUserLocked(r.userId), r.info, r.intent, null, null, true); |
Winson Chung | 7466610 | 2017-02-22 17:49:24 -0800 | [diff] [blame] | 3367 | r.reparent(newTask, MAX_VALUE, "moveActivityToStack"); |
| 3368 | |
Winson Chung | 5af42fc | 2017-03-24 17:11:33 -0700 | [diff] [blame] | 3369 | // 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] | 3370 | newTask.reparent(stack, ON_TOP, REPARENT_MOVE_STACK_TO_FRONT, !ANIMATE, |
Winson Chung | 5af42fc | 2017-03-24 17:11:33 -0700 | [diff] [blame] | 3371 | DEFER_RESUME, false /* schedulePictureInPictureModeChange */, reason); |
Wale Ogunwale | 480dca0 | 2016-02-06 13:58:29 -0800 | [diff] [blame] | 3372 | } |
Winson Chung | c2baac0 | 2017-01-11 13:34:47 -0800 | [diff] [blame] | 3373 | |
| 3374 | // Reset the state that indicates it can enter PiP while pausing after we've moved it |
| 3375 | // to the pinned stack |
Winson Chung | f7e03e1 | 2017-08-22 11:32:16 -0700 | [diff] [blame] | 3376 | r.supportsEnterPipOnTaskSwitch = false; |
Wale Ogunwale | 480dca0 | 2016-02-06 13:58:29 -0800 | [diff] [blame] | 3377 | } finally { |
| 3378 | mWindowManager.continueSurfaceLayout(); |
Wale Ogunwale | 079a004 | 2015-10-24 11:44:07 -0700 | [diff] [blame] | 3379 | } |
| 3380 | |
Winson Chung | e7ba686 | 2017-05-24 12:13:33 -0700 | [diff] [blame] | 3381 | stack.animateResizePinnedStack(sourceHintBounds, destBounds, -1 /* animationDuration */, |
| 3382 | true /* fromFullscreen */); |
| 3383 | |
| 3384 | // Update the visibility of all activities after the they have been reparented to the new |
| 3385 | // stack. This MUST run after the animation above is scheduled to ensure that the windows |
| 3386 | // drawn signal is scheduled after the bounds animation start call on the bounds animator |
| 3387 | // thread. |
Wale Ogunwale | 079a004 | 2015-10-24 11:44:07 -0700 | [diff] [blame] | 3388 | ensureActivitiesVisibleLocked(null, 0, !PRESERVE_WINDOWS); |
Wale Ogunwale | d046a01 | 2015-12-24 13:05:59 -0800 | [diff] [blame] | 3389 | resumeFocusedStackTopActivityLocked(); |
Wale Ogunwale | 03ce863 | 2015-12-29 16:15:22 -0800 | [diff] [blame] | 3390 | |
Wale Ogunwale | 89be576 | 2017-10-04 13:27:49 -0700 | [diff] [blame] | 3391 | mService.mTaskChangeNotificationController.notifyActivityPinned(r); |
Wale Ogunwale | 079a004 | 2015-10-24 11:44:07 -0700 | [diff] [blame] | 3392 | } |
| 3393 | |
Andrii Kulian | 0864bbb | 2017-02-16 15:45:58 -0800 | [diff] [blame] | 3394 | /** Move activity with its stack to front and make the stack focused. */ |
Chong Zhang | 6cda19c | 2016-06-14 19:07:56 -0700 | [diff] [blame] | 3395 | boolean moveFocusableActivityStackToFrontLocked(ActivityRecord r, String reason) { |
| 3396 | if (r == null || !r.isFocusable()) { |
| 3397 | if (DEBUG_FOCUS) Slog.d(TAG_FOCUS, |
| 3398 | "moveActivityStackToFront: unfocusable r=" + r); |
| 3399 | return false; |
| 3400 | } |
| 3401 | |
Bryce Lee | af691c0 | 2017-03-20 14:20:22 -0700 | [diff] [blame] | 3402 | final TaskRecord task = r.getTask(); |
Andrii Kulian | 02b7a83 | 2016-10-06 23:11:56 -0700 | [diff] [blame] | 3403 | final ActivityStack stack = r.getStack(); |
| 3404 | if (stack == null) { |
Chong Zhang | 6cda19c | 2016-06-14 19:07:56 -0700 | [diff] [blame] | 3405 | Slog.w(TAG, "moveActivityStackToFront: invalid task or stack: r=" |
| 3406 | + r + " task=" + task); |
| 3407 | return false; |
| 3408 | } |
| 3409 | |
Chong Zhang | 6cda19c | 2016-06-14 19:07:56 -0700 | [diff] [blame] | 3410 | if (stack == mFocusedStack && stack.topRunningActivityLocked() == r) { |
| 3411 | if (DEBUG_FOCUS) Slog.d(TAG_FOCUS, |
| 3412 | "moveActivityStackToFront: already on top, r=" + r); |
| 3413 | return false; |
| 3414 | } |
| 3415 | |
| 3416 | if (DEBUG_FOCUS) Slog.d(TAG_FOCUS, |
| 3417 | "moveActivityStackToFront: r=" + r); |
| 3418 | |
| 3419 | stack.moveToFront(reason, task); |
| 3420 | return true; |
| 3421 | } |
| 3422 | |
David Stevens | c6b91c6 | 2017-02-08 14:23:58 -0800 | [diff] [blame] | 3423 | ActivityRecord findTaskLocked(ActivityRecord r, int displayId) { |
Wale Ogunwale | 3938197 | 2015-12-17 17:15:29 -0800 | [diff] [blame] | 3424 | mTmpFindTaskResult.r = null; |
| 3425 | mTmpFindTaskResult.matchedByRootAffinity = false; |
David Stevens | c6b91c6 | 2017-02-08 14:23:58 -0800 | [diff] [blame] | 3426 | ActivityRecord affinityMatch = null; |
Wale Ogunwale | ee006da | 2015-03-30 14:49:25 -0700 | [diff] [blame] | 3427 | if (DEBUG_TASKS) Slog.d(TAG_TASKS, "Looking for task of " + r); |
Craig Mautner | e0a3884 | 2013-12-16 16:14:02 -0800 | [diff] [blame] | 3428 | for (int displayNdx = mActivityDisplays.size() - 1; displayNdx >= 0; --displayNdx) { |
Wale Ogunwale | a0f5b5e | 2017-10-11 09:37:23 -0700 | [diff] [blame] | 3429 | final ActivityDisplay display = mActivityDisplays.valueAt(displayNdx); |
| 3430 | for (int stackNdx = display.getChildCount() - 1; stackNdx >= 0; --stackNdx) { |
| 3431 | final ActivityStack stack = display.getChildAt(stackNdx); |
Wale Ogunwale | 6fbde9f | 2017-08-24 07:24:12 -0700 | [diff] [blame] | 3432 | if (!r.hasCompatibleActivityType(stack)) { |
Winson Chung | 91e5c88 | 2017-04-21 14:44:38 -0700 | [diff] [blame] | 3433 | if (DEBUG_TASKS) Slog.d(TAG_TASKS, "Skipping stack: (mismatch activity/stack) " |
| 3434 | + stack); |
Craig Mautner | 1b4bf85 | 2014-05-26 15:06:32 -0700 | [diff] [blame] | 3435 | continue; |
| 3436 | } |
Wale Ogunwale | 3938197 | 2015-12-17 17:15:29 -0800 | [diff] [blame] | 3437 | stack.findTaskLocked(r, mTmpFindTaskResult); |
David Stevens | c6b91c6 | 2017-02-08 14:23:58 -0800 | [diff] [blame] | 3438 | // It is possible to have tasks in multiple stacks with the same root affinity, so |
| 3439 | // we should keep looking after finding an affinity match to see if there is a |
| 3440 | // better match in another stack. Also, task affinity isn't a good enough reason |
| 3441 | // to target a display which isn't the source of the intent, so skip any affinity |
| 3442 | // matches not on the specified display. |
| 3443 | if (mTmpFindTaskResult.r != null) { |
| 3444 | if (!mTmpFindTaskResult.matchedByRootAffinity) { |
| 3445 | return mTmpFindTaskResult.r; |
| 3446 | } else if (mTmpFindTaskResult.r.getDisplayId() == displayId) { |
Winson Chung | 5b895b7 | 2017-05-01 13:46:25 -0700 | [diff] [blame] | 3447 | // Note: since the traversing through the stacks is top down, the floating |
| 3448 | // tasks should always have lower priority than any affinity-matching tasks |
| 3449 | // in the fullscreen stacks |
David Stevens | c6b91c6 | 2017-02-08 14:23:58 -0800 | [diff] [blame] | 3450 | affinityMatch = mTmpFindTaskResult.r; |
David Stevens | e5a7b64 | 2017-05-22 13:18:23 -0700 | [diff] [blame] | 3451 | } else if (DEBUG_TASKS && mTmpFindTaskResult.matchedByRootAffinity) { |
| 3452 | Slog.d(TAG_TASKS, "Skipping match on different display " |
| 3453 | + mTmpFindTaskResult.r.getDisplayId() + " " + displayId); |
David Stevens | c6b91c6 | 2017-02-08 14:23:58 -0800 | [diff] [blame] | 3454 | } |
Craig Mautner | 4a1cb22 | 2013-12-04 16:14:06 -0800 | [diff] [blame] | 3455 | } |
Craig Mautner | 8849a5e | 2013-04-02 16:41:03 -0700 | [diff] [blame] | 3456 | } |
| 3457 | } |
Winson Chung | 5b895b7 | 2017-05-01 13:46:25 -0700 | [diff] [blame] | 3458 | |
David Stevens | c6b91c6 | 2017-02-08 14:23:58 -0800 | [diff] [blame] | 3459 | if (DEBUG_TASKS && affinityMatch == null) Slog.d(TAG_TASKS, "No task found"); |
| 3460 | return affinityMatch; |
Craig Mautner | 8849a5e | 2013-04-02 16:41:03 -0700 | [diff] [blame] | 3461 | } |
| 3462 | |
Andrii Kulian | d3bbb13 | 2016-06-16 16:00:20 -0700 | [diff] [blame] | 3463 | ActivityRecord findActivityLocked(Intent intent, ActivityInfo info, |
Wale Ogunwale | a0f5b5e | 2017-10-11 09:37:23 -0700 | [diff] [blame] | 3464 | boolean compareIntentFilters) { |
Craig Mautner | e0a3884 | 2013-12-16 16:14:02 -0800 | [diff] [blame] | 3465 | for (int displayNdx = mActivityDisplays.size() - 1; displayNdx >= 0; --displayNdx) { |
Wale Ogunwale | a0f5b5e | 2017-10-11 09:37:23 -0700 | [diff] [blame] | 3466 | final ActivityDisplay display = mActivityDisplays.valueAt(displayNdx); |
| 3467 | for (int stackNdx = display.getChildCount() - 1; stackNdx >= 0; --stackNdx) { |
| 3468 | final ActivityStack stack = display.getChildAt(stackNdx); |
| 3469 | final ActivityRecord ar = stack.findActivityLocked( |
| 3470 | intent, info, compareIntentFilters); |
Craig Mautner | 4a1cb22 | 2013-12-04 16:14:06 -0800 | [diff] [blame] | 3471 | if (ar != null) { |
| 3472 | return ar; |
| 3473 | } |
Craig Mautner | 8849a5e | 2013-04-02 16:41:03 -0700 | [diff] [blame] | 3474 | } |
| 3475 | } |
| 3476 | return null; |
| 3477 | } |
| 3478 | |
David Stevens | 9440dc8 | 2017-03-16 19:00:20 -0700 | [diff] [blame] | 3479 | boolean hasAwakeDisplay() { |
| 3480 | for (int displayNdx = mActivityDisplays.size() - 1; displayNdx >= 0; --displayNdx) { |
| 3481 | final ActivityDisplay display = mActivityDisplays.valueAt(displayNdx); |
| 3482 | if (!display.shouldSleep()) { |
| 3483 | return true; |
| 3484 | } |
| 3485 | } |
| 3486 | return false; |
| 3487 | } |
| 3488 | |
Craig Mautner | 8d341ef | 2013-03-26 09:03:27 -0700 | [diff] [blame] | 3489 | void goingToSleepLocked() { |
Craig Mautner | 0eea92c | 2013-05-16 13:35:39 -0700 | [diff] [blame] | 3490 | scheduleSleepTimeout(); |
| 3491 | if (!mGoingToSleep.isHeld()) { |
| 3492 | mGoingToSleep.acquire(); |
Craig Mautner | 7ea5bd4 | 2013-07-05 15:27:08 -0700 | [diff] [blame] | 3493 | if (mLaunchingActivity.isHeld()) { |
| 3494 | if (VALIDATE_WAKE_LOCK_CALLER && Binder.getCallingUid() != Process.myUid()) { |
| 3495 | throw new IllegalStateException("Calling must be system uid"); |
Craig Mautner | 0eea92c | 2013-05-16 13:35:39 -0700 | [diff] [blame] | 3496 | } |
Craig Mautner | 7ea5bd4 | 2013-07-05 15:27:08 -0700 | [diff] [blame] | 3497 | mLaunchingActivity.release(); |
| 3498 | mService.mHandler.removeMessages(LAUNCH_TIMEOUT_MSG); |
Craig Mautner | 0eea92c | 2013-05-16 13:35:39 -0700 | [diff] [blame] | 3499 | } |
Craig Mautner | 8d341ef | 2013-03-26 09:03:27 -0700 | [diff] [blame] | 3500 | } |
David Stevens | 9440dc8 | 2017-03-16 19:00:20 -0700 | [diff] [blame] | 3501 | |
| 3502 | applySleepTokensLocked(false /* applyToStacks */); |
| 3503 | |
| 3504 | checkReadyForSleepLocked(true /* allowDelay */); |
| 3505 | } |
| 3506 | |
| 3507 | void prepareForShutdownLocked() { |
| 3508 | for (int i = 0; i < mActivityDisplays.size(); i++) { |
| 3509 | createSleepTokenLocked("shutdown", mActivityDisplays.keyAt(i)); |
| 3510 | } |
Craig Mautner | 8d341ef | 2013-03-26 09:03:27 -0700 | [diff] [blame] | 3511 | } |
| 3512 | |
| 3513 | boolean shutdownLocked(int timeout) { |
Craig Mautner | 0eea92c | 2013-05-16 13:35:39 -0700 | [diff] [blame] | 3514 | goingToSleepLocked(); |
Craig Mautner | 0eea92c | 2013-05-16 13:35:39 -0700 | [diff] [blame] | 3515 | |
Craig Mautner | f4c909b | 2014-04-17 18:39:38 -0700 | [diff] [blame] | 3516 | boolean timedout = false; |
Craig Mautner | 0eea92c | 2013-05-16 13:35:39 -0700 | [diff] [blame] | 3517 | final long endTime = System.currentTimeMillis() + timeout; |
| 3518 | while (true) { |
David Stevens | 18abd0e | 2017-08-17 14:55:47 -0700 | [diff] [blame] | 3519 | if (!putStacksToSleepLocked(true /* allowDelay */, true /* shuttingDown */)) { |
Craig Mautner | 0eea92c | 2013-05-16 13:35:39 -0700 | [diff] [blame] | 3520 | long timeRemaining = endTime - System.currentTimeMillis(); |
| 3521 | if (timeRemaining > 0) { |
Craig Mautner | 8d341ef | 2013-03-26 09:03:27 -0700 | [diff] [blame] | 3522 | try { |
Craig Mautner | 0eea92c | 2013-05-16 13:35:39 -0700 | [diff] [blame] | 3523 | mService.wait(timeRemaining); |
Craig Mautner | 8d341ef | 2013-03-26 09:03:27 -0700 | [diff] [blame] | 3524 | } catch (InterruptedException e) { |
| 3525 | } |
Craig Mautner | 0eea92c | 2013-05-16 13:35:39 -0700 | [diff] [blame] | 3526 | } else { |
| 3527 | Slog.w(TAG, "Activity manager shutdown timed out"); |
| 3528 | timedout = true; |
| 3529 | break; |
Craig Mautner | 8d341ef | 2013-03-26 09:03:27 -0700 | [diff] [blame] | 3530 | } |
Craig Mautner | 0eea92c | 2013-05-16 13:35:39 -0700 | [diff] [blame] | 3531 | } else { |
| 3532 | break; |
Craig Mautner | 8d341ef | 2013-03-26 09:03:27 -0700 | [diff] [blame] | 3533 | } |
| 3534 | } |
Craig Mautner | 0eea92c | 2013-05-16 13:35:39 -0700 | [diff] [blame] | 3535 | |
| 3536 | // Force checkReadyForSleep to complete. |
David Stevens | 9440dc8 | 2017-03-16 19:00:20 -0700 | [diff] [blame] | 3537 | checkReadyForSleepLocked(false /* allowDelay */); |
Craig Mautner | 0eea92c | 2013-05-16 13:35:39 -0700 | [diff] [blame] | 3538 | |
Craig Mautner | 8d341ef | 2013-03-26 09:03:27 -0700 | [diff] [blame] | 3539 | return timedout; |
| 3540 | } |
| 3541 | |
| 3542 | void comeOutOfSleepIfNeededLocked() { |
Craig Mautner | 0eea92c | 2013-05-16 13:35:39 -0700 | [diff] [blame] | 3543 | removeSleepTimeouts(); |
| 3544 | if (mGoingToSleep.isHeld()) { |
| 3545 | mGoingToSleep.release(); |
| 3546 | } |
David Stevens | 9440dc8 | 2017-03-16 19:00:20 -0700 | [diff] [blame] | 3547 | } |
| 3548 | |
| 3549 | void applySleepTokensLocked(boolean applyToStacks) { |
Craig Mautner | e0a3884 | 2013-12-16 16:14:02 -0800 | [diff] [blame] | 3550 | for (int displayNdx = mActivityDisplays.size() - 1; displayNdx >= 0; --displayNdx) { |
David Stevens | 9440dc8 | 2017-03-16 19:00:20 -0700 | [diff] [blame] | 3551 | // Set the sleeping state of the display. |
| 3552 | final ActivityDisplay display = mActivityDisplays.valueAt(displayNdx); |
| 3553 | final boolean displayShouldSleep = display.shouldSleep(); |
| 3554 | if (displayShouldSleep == display.isSleeping()) { |
| 3555 | continue; |
| 3556 | } |
| 3557 | display.setIsSleeping(displayShouldSleep); |
| 3558 | |
| 3559 | if (!applyToStacks) { |
| 3560 | continue; |
| 3561 | } |
| 3562 | |
| 3563 | // Set the sleeping state of the stacks on the display. |
Wale Ogunwale | a0f5b5e | 2017-10-11 09:37:23 -0700 | [diff] [blame] | 3564 | for (int stackNdx = display.getChildCount() - 1; stackNdx >= 0; --stackNdx) { |
| 3565 | final ActivityStack stack = display.getChildAt(stackNdx); |
David Stevens | 9440dc8 | 2017-03-16 19:00:20 -0700 | [diff] [blame] | 3566 | if (displayShouldSleep) { |
| 3567 | stack.goToSleepIfPossible(false /* shuttingDown */); |
| 3568 | } else { |
| 3569 | stack.awakeFromSleepingLocked(); |
Lucas Dupin | 47a65c7 | 2018-02-15 14:16:18 -0800 | [diff] [blame] | 3570 | if (isFocusedStack(stack) && !getKeyguardController().isKeyguardOrAodShowing( |
| 3571 | display.mDisplayId)) { |
Bryce Lee | d939cf0 | 2018-03-12 09:04:44 -0700 | [diff] [blame] | 3572 | // If the keyguard is unlocked - resume immediately. |
| 3573 | // It is possible that the display will not be awake at the time we |
| 3574 | // process the keyguard going away, which can happen before the sleep token |
| 3575 | // is released. As a result, it is important we resume the activity here. |
David Stevens | 9440dc8 | 2017-03-16 19:00:20 -0700 | [diff] [blame] | 3576 | resumeFocusedStackTopActivityLocked(); |
| 3577 | } |
| 3578 | } |
| 3579 | } |
| 3580 | |
| 3581 | if (displayShouldSleep || mGoingToSleepActivities.isEmpty()) { |
| 3582 | continue; |
| 3583 | } |
| 3584 | // The display is awake now, so clean up the going to sleep list. |
| 3585 | for (Iterator<ActivityRecord> it = mGoingToSleepActivities.iterator(); it.hasNext(); ) { |
| 3586 | final ActivityRecord r = it.next(); |
| 3587 | if (r.getDisplayId() == display.mDisplayId) { |
| 3588 | it.remove(); |
Craig Mautner | 4a1cb22 | 2013-12-04 16:14:06 -0800 | [diff] [blame] | 3589 | } |
Craig Mautner | 5314a40 | 2013-09-26 12:40:16 -0700 | [diff] [blame] | 3590 | } |
Craig Mautner | 8d341ef | 2013-03-26 09:03:27 -0700 | [diff] [blame] | 3591 | } |
Craig Mautner | 0eea92c | 2013-05-16 13:35:39 -0700 | [diff] [blame] | 3592 | } |
| 3593 | |
| 3594 | void activitySleptLocked(ActivityRecord r) { |
| 3595 | mGoingToSleepActivities.remove(r); |
David Stevens | 9440dc8 | 2017-03-16 19:00:20 -0700 | [diff] [blame] | 3596 | final ActivityStack s = r.getStack(); |
| 3597 | if (s != null) { |
| 3598 | s.checkReadyForSleep(); |
| 3599 | } else { |
| 3600 | checkReadyForSleepLocked(true); |
| 3601 | } |
Craig Mautner | 0eea92c | 2013-05-16 13:35:39 -0700 | [diff] [blame] | 3602 | } |
| 3603 | |
David Stevens | 9440dc8 | 2017-03-16 19:00:20 -0700 | [diff] [blame] | 3604 | void checkReadyForSleepLocked(boolean allowDelay) { |
Fyodor Kupolov | 9b80b94 | 2016-06-16 16:29:05 -0700 | [diff] [blame] | 3605 | if (!mService.isSleepingOrShuttingDownLocked()) { |
Craig Mautner | 0eea92c | 2013-05-16 13:35:39 -0700 | [diff] [blame] | 3606 | // Do not care. |
| 3607 | return; |
| 3608 | } |
| 3609 | |
David Stevens | 18abd0e | 2017-08-17 14:55:47 -0700 | [diff] [blame] | 3610 | if (!putStacksToSleepLocked(allowDelay, false /* shuttingDown */)) { |
| 3611 | return; |
Craig Mautner | 0eea92c | 2013-05-16 13:35:39 -0700 | [diff] [blame] | 3612 | } |
| 3613 | |
Wei Wang | 65c7a15 | 2016-06-02 18:51:22 -0700 | [diff] [blame] | 3614 | // Send launch end powerhint before going sleep |
Bryce Lee | d3624e1 | 2017-11-30 08:51:45 -0800 | [diff] [blame] | 3615 | sendPowerHintForLaunchEndIfNeeded(); |
Wei Wang | 65c7a15 | 2016-06-02 18:51:22 -0700 | [diff] [blame] | 3616 | |
Craig Mautner | 0eea92c | 2013-05-16 13:35:39 -0700 | [diff] [blame] | 3617 | removeSleepTimeouts(); |
| 3618 | |
| 3619 | if (mGoingToSleep.isHeld()) { |
| 3620 | mGoingToSleep.release(); |
| 3621 | } |
| 3622 | if (mService.mShuttingDown) { |
| 3623 | mService.notifyAll(); |
| 3624 | } |
Craig Mautner | 8d341ef | 2013-03-26 09:03:27 -0700 | [diff] [blame] | 3625 | } |
| 3626 | |
David Stevens | 18abd0e | 2017-08-17 14:55:47 -0700 | [diff] [blame] | 3627 | // Tries to put all activity stacks to sleep. Returns true if all stacks were |
| 3628 | // successfully put to sleep. |
| 3629 | private boolean putStacksToSleepLocked(boolean allowDelay, boolean shuttingDown) { |
| 3630 | boolean allSleep = true; |
| 3631 | for (int displayNdx = mActivityDisplays.size() - 1; displayNdx >= 0; --displayNdx) { |
Wale Ogunwale | a0f5b5e | 2017-10-11 09:37:23 -0700 | [diff] [blame] | 3632 | final ActivityDisplay display = mActivityDisplays.valueAt(displayNdx); |
| 3633 | for (int stackNdx = display.getChildCount() - 1; stackNdx >= 0; --stackNdx) { |
| 3634 | final ActivityStack stack = display.getChildAt(stackNdx); |
David Stevens | 18abd0e | 2017-08-17 14:55:47 -0700 | [diff] [blame] | 3635 | if (allowDelay) { |
Wale Ogunwale | a0f5b5e | 2017-10-11 09:37:23 -0700 | [diff] [blame] | 3636 | allSleep &= stack.goToSleepIfPossible(shuttingDown); |
David Stevens | 18abd0e | 2017-08-17 14:55:47 -0700 | [diff] [blame] | 3637 | } else { |
Wale Ogunwale | a0f5b5e | 2017-10-11 09:37:23 -0700 | [diff] [blame] | 3638 | stack.goToSleep(); |
David Stevens | 18abd0e | 2017-08-17 14:55:47 -0700 | [diff] [blame] | 3639 | } |
| 3640 | } |
| 3641 | } |
| 3642 | return allSleep; |
| 3643 | } |
| 3644 | |
Craig Mautner | ce5f3cb | 2013-04-22 08:58:54 -0700 | [diff] [blame] | 3645 | boolean reportResumedActivityLocked(ActivityRecord r) { |
Bryce Lee | 29a649d | 2017-08-18 13:52:31 -0700 | [diff] [blame] | 3646 | // A resumed activity cannot be stopping. remove from list |
| 3647 | mStoppingActivities.remove(r); |
| 3648 | |
Andrii Kulian | 02b7a83 | 2016-10-06 23:11:56 -0700 | [diff] [blame] | 3649 | final ActivityStack stack = r.getStack(); |
Wale Ogunwale | 1e60e0c | 2015-10-28 13:36:10 -0700 | [diff] [blame] | 3650 | if (isFocusedStack(stack)) { |
Jeff Sharkey | 5782da7 | 2013-04-25 14:32:30 -0700 | [diff] [blame] | 3651 | mService.updateUsageStats(r, true); |
Craig Mautner | ce5f3cb | 2013-04-22 08:58:54 -0700 | [diff] [blame] | 3652 | } |
| 3653 | if (allResumedActivitiesComplete()) { |
Filip Gruszczynski | bc5a6c5 | 2015-09-22 13:13:24 -0700 | [diff] [blame] | 3654 | ensureActivitiesVisibleLocked(null, 0, !PRESERVE_WINDOWS); |
Craig Mautner | ce5f3cb | 2013-04-22 08:58:54 -0700 | [diff] [blame] | 3655 | mWindowManager.executeAppTransition(); |
| 3656 | return true; |
| 3657 | } |
| 3658 | return false; |
| 3659 | } |
| 3660 | |
Craig Mautner | 8d341ef | 2013-03-26 09:03:27 -0700 | [diff] [blame] | 3661 | void handleAppCrashLocked(ProcessRecord app) { |
Craig Mautner | e0a3884 | 2013-12-16 16:14:02 -0800 | [diff] [blame] | 3662 | for (int displayNdx = mActivityDisplays.size() - 1; displayNdx >= 0; --displayNdx) { |
Wale Ogunwale | a0f5b5e | 2017-10-11 09:37:23 -0700 | [diff] [blame] | 3663 | final ActivityDisplay display = mActivityDisplays.valueAt(displayNdx); |
| 3664 | for (int stackNdx = display.getChildCount() - 1; stackNdx >= 0; --stackNdx) { |
| 3665 | final ActivityStack stack = display.getChildAt(stackNdx); |
| 3666 | stack.handleAppCrashLocked(app); |
Craig Mautner | 4a1cb22 | 2013-12-04 16:14:06 -0800 | [diff] [blame] | 3667 | } |
Craig Mautner | 8d341ef | 2013-03-26 09:03:27 -0700 | [diff] [blame] | 3668 | } |
| 3669 | } |
| 3670 | |
Craig Mautner | bb74246 | 2014-07-07 15:28:55 -0700 | [diff] [blame] | 3671 | // Called when WindowManager has finished animating the launchingBehind activity to the back. |
Andrii Kulian | 21713ac | 2016-10-12 22:05:05 -0700 | [diff] [blame] | 3672 | private void handleLaunchTaskBehindCompleteLocked(ActivityRecord r) { |
Bryce Lee | af691c0 | 2017-03-20 14:20:22 -0700 | [diff] [blame] | 3673 | final TaskRecord task = r.getTask(); |
Andrii Kulian | 02b7a83 | 2016-10-06 23:11:56 -0700 | [diff] [blame] | 3674 | final ActivityStack stack = task.getStack(); |
Winson | 730bf06 | 2016-03-31 18:04:56 -0700 | [diff] [blame] | 3675 | |
| 3676 | r.mLaunchTaskBehind = false; |
Winson Chung | 1dbc811 | 2017-09-28 18:05:31 -0700 | [diff] [blame] | 3677 | mRecentTasks.add(task); |
Yorke Lee | bd54c2a | 2016-10-25 13:49:23 -0700 | [diff] [blame] | 3678 | mService.mTaskChangeNotificationController.notifyTaskStackChanged(); |
Wale Ogunwale | 26c0dfe | 2016-12-14 14:42:30 -0800 | [diff] [blame] | 3679 | r.setVisibility(false); |
Winson | 730bf06 | 2016-03-31 18:04:56 -0700 | [diff] [blame] | 3680 | |
| 3681 | // When launching tasks behind, update the last active time of the top task after the new |
| 3682 | // task has been shown briefly |
Wale Ogunwale | 30e441d | 2017-11-09 08:28:45 -0800 | [diff] [blame] | 3683 | final ActivityRecord top = stack.getTopActivity(); |
Winson | 730bf06 | 2016-03-31 18:04:56 -0700 | [diff] [blame] | 3684 | if (top != null) { |
Bryce Lee | af691c0 | 2017-03-20 14:20:22 -0700 | [diff] [blame] | 3685 | top.getTask().touchActiveTime(); |
Winson | 730bf06 | 2016-03-31 18:04:56 -0700 | [diff] [blame] | 3686 | } |
Craig Mautner | bb74246 | 2014-07-07 15:28:55 -0700 | [diff] [blame] | 3687 | } |
| 3688 | |
| 3689 | void scheduleLaunchTaskBehindComplete(IBinder token) { |
| 3690 | mHandler.obtainMessage(LAUNCH_TASK_BEHIND_COMPLETE, token).sendToTarget(); |
| 3691 | } |
| 3692 | |
Andrii Kulian | f4479ee | 2018-05-23 17:52:48 -0700 | [diff] [blame] | 3693 | /** |
| 3694 | * Make sure that all activities that need to be visible in the system actually are and update |
| 3695 | * their configuration. |
| 3696 | */ |
Filip Gruszczynski | bc5a6c5 | 2015-09-22 13:13:24 -0700 | [diff] [blame] | 3697 | void ensureActivitiesVisibleLocked(ActivityRecord starting, int configChanges, |
| 3698 | boolean preserveWindows) { |
Andrii Kulian | f4479ee | 2018-05-23 17:52:48 -0700 | [diff] [blame] | 3699 | ensureActivitiesVisibleLocked(starting, configChanges, preserveWindows, |
Andrii Kulian | a39ae3e | 2018-05-31 12:43:54 -0700 | [diff] [blame] | 3700 | true /* notifyClients */); |
Andrii Kulian | f4479ee | 2018-05-23 17:52:48 -0700 | [diff] [blame] | 3701 | } |
| 3702 | |
| 3703 | /** |
| 3704 | * @see #ensureActivitiesVisibleLocked(ActivityRecord, int, boolean) |
| 3705 | */ |
| 3706 | void ensureActivitiesVisibleLocked(ActivityRecord starting, int configChanges, |
Andrii Kulian | a39ae3e | 2018-05-31 12:43:54 -0700 | [diff] [blame] | 3707 | boolean preserveWindows, boolean notifyClients) { |
Bryce Lee | 459c062 | 2018-03-19 11:04:01 -0700 | [diff] [blame] | 3708 | getKeyguardController().beginActivityVisibilityUpdate(); |
Jorim Jaggi | fe76234 | 2016-10-13 14:33:27 +0200 | [diff] [blame] | 3709 | try { |
| 3710 | // First the front stacks. In case any are not fullscreen and are in front of home. |
| 3711 | for (int displayNdx = mActivityDisplays.size() - 1; displayNdx >= 0; --displayNdx) { |
Wale Ogunwale | a0f5b5e | 2017-10-11 09:37:23 -0700 | [diff] [blame] | 3712 | final ActivityDisplay display = mActivityDisplays.valueAt(displayNdx); |
| 3713 | for (int stackNdx = display.getChildCount() - 1; stackNdx >= 0; --stackNdx) { |
| 3714 | final ActivityStack stack = display.getChildAt(stackNdx); |
Andrii Kulian | f4479ee | 2018-05-23 17:52:48 -0700 | [diff] [blame] | 3715 | stack.ensureActivitiesVisibleLocked(starting, configChanges, preserveWindows, |
Andrii Kulian | a39ae3e | 2018-05-31 12:43:54 -0700 | [diff] [blame] | 3716 | notifyClients); |
Jorim Jaggi | fe76234 | 2016-10-13 14:33:27 +0200 | [diff] [blame] | 3717 | } |
Craig Mautner | 580ea81 | 2013-04-25 12:58:38 -0700 | [diff] [blame] | 3718 | } |
Jorim Jaggi | fe76234 | 2016-10-13 14:33:27 +0200 | [diff] [blame] | 3719 | } finally { |
Bryce Lee | 459c062 | 2018-03-19 11:04:01 -0700 | [diff] [blame] | 3720 | getKeyguardController().endActivityVisibilityUpdate(); |
Craig Mautner | 8d341ef | 2013-03-26 09:03:27 -0700 | [diff] [blame] | 3721 | } |
Craig Mautner | 8d341ef | 2013-03-26 09:03:27 -0700 | [diff] [blame] | 3722 | } |
| 3723 | |
Jorim Jaggi | 8b702ed | 2017-01-20 16:59:03 +0100 | [diff] [blame] | 3724 | void addStartingWindowsForVisibleActivities(boolean taskSwitch) { |
| 3725 | for (int displayNdx = mActivityDisplays.size() - 1; displayNdx >= 0; --displayNdx) { |
Wale Ogunwale | a0f5b5e | 2017-10-11 09:37:23 -0700 | [diff] [blame] | 3726 | final ActivityDisplay display = mActivityDisplays.valueAt(displayNdx); |
| 3727 | for (int stackNdx = display.getChildCount() - 1; stackNdx >= 0; --stackNdx) { |
| 3728 | final ActivityStack stack = display.getChildAt(stackNdx); |
Jorim Jaggi | 8b702ed | 2017-01-20 16:59:03 +0100 | [diff] [blame] | 3729 | stack.addStartingWindowsForVisibleActivities(taskSwitch); |
| 3730 | } |
| 3731 | } |
| 3732 | } |
| 3733 | |
Chong Zhang | fdcc4d4 | 2015-10-14 16:50:12 -0700 | [diff] [blame] | 3734 | void invalidateTaskLayers() { |
| 3735 | mTaskLayersChanged = true; |
| 3736 | } |
| 3737 | |
| 3738 | void rankTaskLayersIfNeeded() { |
| 3739 | if (!mTaskLayersChanged) { |
| 3740 | return; |
| 3741 | } |
| 3742 | mTaskLayersChanged = false; |
| 3743 | for (int displayNdx = 0; displayNdx < mActivityDisplays.size(); displayNdx++) { |
Wale Ogunwale | a0f5b5e | 2017-10-11 09:37:23 -0700 | [diff] [blame] | 3744 | final ActivityDisplay display = mActivityDisplays.valueAt(displayNdx); |
Chong Zhang | fdcc4d4 | 2015-10-14 16:50:12 -0700 | [diff] [blame] | 3745 | int baseLayer = 0; |
Wale Ogunwale | a0f5b5e | 2017-10-11 09:37:23 -0700 | [diff] [blame] | 3746 | for (int stackNdx = display.getChildCount() - 1; stackNdx >= 0; --stackNdx) { |
| 3747 | final ActivityStack stack = display.getChildAt(stackNdx); |
| 3748 | baseLayer += stack.rankTaskLayers(baseLayer); |
Chong Zhang | fdcc4d4 | 2015-10-14 16:50:12 -0700 | [diff] [blame] | 3749 | } |
| 3750 | } |
| 3751 | } |
| 3752 | |
Dianne Hackborn | b5a380d | 2015-05-20 18:18:46 -0700 | [diff] [blame] | 3753 | void clearOtherAppTimeTrackers(AppTimeTracker except) { |
| 3754 | for (int displayNdx = mActivityDisplays.size() - 1; displayNdx >= 0; --displayNdx) { |
Wale Ogunwale | a0f5b5e | 2017-10-11 09:37:23 -0700 | [diff] [blame] | 3755 | final ActivityDisplay display = mActivityDisplays.valueAt(displayNdx); |
| 3756 | for (int stackNdx = display.getChildCount() - 1; stackNdx >= 0; --stackNdx) { |
| 3757 | final ActivityStack stack = display.getChildAt(stackNdx); |
Dianne Hackborn | b5a380d | 2015-05-20 18:18:46 -0700 | [diff] [blame] | 3758 | stack.clearOtherAppTimeTrackers(except); |
| 3759 | } |
| 3760 | } |
| 3761 | } |
| 3762 | |
Craig Mautner | 8d341ef | 2013-03-26 09:03:27 -0700 | [diff] [blame] | 3763 | void scheduleDestroyAllActivities(ProcessRecord app, String reason) { |
Craig Mautner | e0a3884 | 2013-12-16 16:14:02 -0800 | [diff] [blame] | 3764 | for (int displayNdx = mActivityDisplays.size() - 1; displayNdx >= 0; --displayNdx) { |
Wale Ogunwale | a0f5b5e | 2017-10-11 09:37:23 -0700 | [diff] [blame] | 3765 | final ActivityDisplay display = mActivityDisplays.valueAt(displayNdx); |
| 3766 | for (int stackNdx = display.getChildCount() - 1; stackNdx >= 0; --stackNdx) { |
| 3767 | final ActivityStack stack = display.getChildAt(stackNdx); |
Craig Mautner | ee2e45a | 2014-06-27 12:10:03 -0700 | [diff] [blame] | 3768 | stack.scheduleDestroyActivities(app, reason); |
Craig Mautner | 4a1cb22 | 2013-12-04 16:14:06 -0800 | [diff] [blame] | 3769 | } |
Craig Mautner | 8d341ef | 2013-03-26 09:03:27 -0700 | [diff] [blame] | 3770 | } |
| 3771 | } |
| 3772 | |
Dianne Hackborn | 89ad456 | 2014-08-24 16:45:38 -0700 | [diff] [blame] | 3773 | void releaseSomeActivitiesLocked(ProcessRecord app, String reason) { |
| 3774 | // Examine all activities currently running in the process. |
| 3775 | TaskRecord firstTask = null; |
| 3776 | // Tasks is non-null only if two or more tasks are found. |
| 3777 | ArraySet<TaskRecord> tasks = null; |
Wale Ogunwale | 0fc365c | 2015-05-25 19:35:42 -0700 | [diff] [blame] | 3778 | if (DEBUG_RELEASE) Slog.d(TAG_RELEASE, "Trying to release some activities in " + app); |
| 3779 | for (int i = 0; i < app.activities.size(); i++) { |
Dianne Hackborn | 89ad456 | 2014-08-24 16:45:38 -0700 | [diff] [blame] | 3780 | ActivityRecord r = app.activities.get(i); |
| 3781 | // First, if we find an activity that is in the process of being destroyed, |
| 3782 | // then we just aren't going to do anything for now; we want things to settle |
| 3783 | // down before we try to prune more activities. |
Bryce Lee | 7ace395 | 2018-02-16 14:34:32 -0800 | [diff] [blame] | 3784 | if (r.finishing || r.isState(DESTROYING, DESTROYED)) { |
Wale Ogunwale | 0fc365c | 2015-05-25 19:35:42 -0700 | [diff] [blame] | 3785 | if (DEBUG_RELEASE) Slog.d(TAG_RELEASE, "Abort release; already destroying: " + r); |
Dianne Hackborn | 89ad456 | 2014-08-24 16:45:38 -0700 | [diff] [blame] | 3786 | return; |
| 3787 | } |
| 3788 | // Don't consider any activies that are currently not in a state where they |
| 3789 | // can be destroyed. |
Bryce Lee | 7ace395 | 2018-02-16 14:34:32 -0800 | [diff] [blame] | 3790 | if (r.visible || !r.stopped || !r.haveState |
| 3791 | || r.isState(RESUMED, PAUSING, PAUSED, STOPPING)) { |
Wale Ogunwale | 0fc365c | 2015-05-25 19:35:42 -0700 | [diff] [blame] | 3792 | 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] | 3793 | continue; |
| 3794 | } |
Bryce Lee | af691c0 | 2017-03-20 14:20:22 -0700 | [diff] [blame] | 3795 | |
| 3796 | final TaskRecord task = r.getTask(); |
| 3797 | if (task != null) { |
| 3798 | if (DEBUG_RELEASE) Slog.d(TAG_RELEASE, "Collecting release task " + task |
Dianne Hackborn | 89ad456 | 2014-08-24 16:45:38 -0700 | [diff] [blame] | 3799 | + " from " + r); |
| 3800 | if (firstTask == null) { |
Bryce Lee | af691c0 | 2017-03-20 14:20:22 -0700 | [diff] [blame] | 3801 | firstTask = task; |
| 3802 | } else if (firstTask != task) { |
Dianne Hackborn | 89ad456 | 2014-08-24 16:45:38 -0700 | [diff] [blame] | 3803 | if (tasks == null) { |
| 3804 | tasks = new ArraySet<>(); |
| 3805 | tasks.add(firstTask); |
| 3806 | } |
Bryce Lee | af691c0 | 2017-03-20 14:20:22 -0700 | [diff] [blame] | 3807 | tasks.add(task); |
Dianne Hackborn | 89ad456 | 2014-08-24 16:45:38 -0700 | [diff] [blame] | 3808 | } |
| 3809 | } |
| 3810 | } |
| 3811 | if (tasks == null) { |
Wale Ogunwale | 0fc365c | 2015-05-25 19:35:42 -0700 | [diff] [blame] | 3812 | 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] | 3813 | return; |
| 3814 | } |
| 3815 | // If we have activities in multiple tasks that are in a position to be destroyed, |
| 3816 | // let's iterate through the tasks and release the oldest one. |
| 3817 | final int numDisplays = mActivityDisplays.size(); |
| 3818 | for (int displayNdx = 0; displayNdx < numDisplays; ++displayNdx) { |
Wale Ogunwale | a0f5b5e | 2017-10-11 09:37:23 -0700 | [diff] [blame] | 3819 | final ActivityDisplay display = mActivityDisplays.valueAt(displayNdx); |
| 3820 | final int stackCount = display.getChildCount(); |
Dianne Hackborn | 89ad456 | 2014-08-24 16:45:38 -0700 | [diff] [blame] | 3821 | // 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] | 3822 | for (int stackNdx = 0; stackNdx < stackCount; stackNdx++) { |
| 3823 | final ActivityStack stack = display.getChildAt(stackNdx); |
Dianne Hackborn | 89ad456 | 2014-08-24 16:45:38 -0700 | [diff] [blame] | 3824 | // Try to release activities in this stack; if we manage to, we are done. |
| 3825 | if (stack.releaseSomeActivitiesLocked(app, tasks, reason) > 0) { |
| 3826 | return; |
| 3827 | } |
| 3828 | } |
| 3829 | } |
| 3830 | } |
| 3831 | |
Amith Yamasani | 37a40c2 | 2015-06-17 13:25:42 -0700 | [diff] [blame] | 3832 | boolean switchUserLocked(int userId, UserState uss) { |
Wale Ogunwale | 9a98c52 | 2016-04-27 09:23:55 -0700 | [diff] [blame] | 3833 | final int focusStackId = mFocusedStack.getStackId(); |
| 3834 | // We dismiss the docked stack whenever we switch users. |
Wale Ogunwale | a0f5b5e | 2017-10-11 09:37:23 -0700 | [diff] [blame] | 3835 | final ActivityStack dockedStack = getDefaultDisplay().getSplitScreenPrimaryStack(); |
Wale Ogunwale | 9dcf946 | 2017-09-19 15:13:01 -0700 | [diff] [blame] | 3836 | if (dockedStack != null) { |
| 3837 | moveTasksToFullscreenStackLocked(dockedStack, mFocusedStack == dockedStack); |
| 3838 | } |
Winson Chung | c2b23a5 | 2017-01-09 15:44:55 -0800 | [diff] [blame] | 3839 | // Also dismiss the pinned stack whenever we switch users. Removing the pinned stack will |
| 3840 | // also cause all tasks to be moved to the fullscreen stack at a position that is |
| 3841 | // appropriate. |
Wale Ogunwale | 44f036f | 2017-09-29 05:09:09 -0700 | [diff] [blame] | 3842 | removeStacksInWindowingModes(WINDOWING_MODE_PINNED); |
Wale Ogunwale | 9a98c52 | 2016-04-27 09:23:55 -0700 | [diff] [blame] | 3843 | |
| 3844 | mUserStackInFront.put(mCurrentUser, focusStackId); |
Wale Ogunwale | 6827856 | 2017-09-23 17:13:55 -0700 | [diff] [blame] | 3845 | final int restoreStackId = mUserStackInFront.get(userId, mHomeStack.mStackId); |
Craig Mautner | 2420ead | 2013-04-01 17:13:20 -0700 | [diff] [blame] | 3846 | mCurrentUser = userId; |
Craig Mautner | ac6f843 | 2013-07-17 13:24:59 -0700 | [diff] [blame] | 3847 | |
Craig Mautner | 858d8a6 | 2013-04-23 17:08:34 -0700 | [diff] [blame] | 3848 | mStartingUsers.add(uss); |
Craig Mautner | e0a3884 | 2013-12-16 16:14:02 -0800 | [diff] [blame] | 3849 | for (int displayNdx = mActivityDisplays.size() - 1; displayNdx >= 0; --displayNdx) { |
Wale Ogunwale | a0f5b5e | 2017-10-11 09:37:23 -0700 | [diff] [blame] | 3850 | final ActivityDisplay display = mActivityDisplays.valueAt(displayNdx); |
| 3851 | for (int stackNdx = display.getChildCount() - 1; stackNdx >= 0; --stackNdx) { |
| 3852 | final ActivityStack stack = display.getChildAt(stackNdx); |
Craig Mautner | e0a3884 | 2013-12-16 16:14:02 -0800 | [diff] [blame] | 3853 | stack.switchUserLocked(userId); |
Alexandra Gherghina | dae57a1 | 2014-03-12 19:15:26 +0000 | [diff] [blame] | 3854 | TaskRecord task = stack.topTask(); |
| 3855 | if (task != null) { |
Wale Ogunwale | 1666e31 | 2016-12-16 11:27:18 -0800 | [diff] [blame] | 3856 | stack.positionChildWindowContainerAtTop(task); |
Alexandra Gherghina | dae57a1 | 2014-03-12 19:15:26 +0000 | [diff] [blame] | 3857 | } |
Craig Mautner | 4a1cb22 | 2013-12-04 16:14:06 -0800 | [diff] [blame] | 3858 | } |
Craig Mautner | ac6f843 | 2013-07-17 13:24:59 -0700 | [diff] [blame] | 3859 | } |
Craig Mautner | 858d8a6 | 2013-04-23 17:08:34 -0700 | [diff] [blame] | 3860 | |
Craig Mautner | 4f1df4f | 2013-10-15 15:44:14 -0700 | [diff] [blame] | 3861 | ActivityStack stack = getStack(restoreStackId); |
| 3862 | if (stack == null) { |
| 3863 | stack = mHomeStack; |
| 3864 | } |
Wale Ogunwale | 6fbde9f | 2017-08-24 07:24:12 -0700 | [diff] [blame] | 3865 | final boolean homeInFront = stack.isActivityTypeHome(); |
Craig Mautner | e0a3884 | 2013-12-16 16:14:02 -0800 | [diff] [blame] | 3866 | if (stack.isOnHomeDisplay()) { |
Wale Ogunwale | 925d0d1 | 2015-09-23 15:40:07 -0700 | [diff] [blame] | 3867 | stack.moveToFront("switchUserOnHomeDisplay"); |
Craig Mautner | e0a3884 | 2013-12-16 16:14:02 -0800 | [diff] [blame] | 3868 | } else { |
| 3869 | // Stack was moved to another display while user was swapped out. |
Matthew Ng | ae1ff4f | 2016-11-10 15:49:14 -0800 | [diff] [blame] | 3870 | resumeHomeStackTask(null, "switchUserOnOtherDisplay"); |
Craig Mautner | e0a3884 | 2013-12-16 16:14:02 -0800 | [diff] [blame] | 3871 | } |
Craig Mautner | 93529a4 | 2013-10-04 15:03:13 -0700 | [diff] [blame] | 3872 | return homeInFront; |
Craig Mautner | 2219a1b | 2013-03-25 09:44:30 -0700 | [diff] [blame] | 3873 | } |
| 3874 | |
Wale Ogunwale | 0bd2aa7 | 2015-04-16 13:50:44 -0700 | [diff] [blame] | 3875 | /** Checks whether the userid is a profile of the current user. */ |
| 3876 | boolean isCurrentProfileLocked(int userId) { |
| 3877 | if (userId == mCurrentUser) return true; |
Fyodor Kupolov | 1b3edac | 2017-09-19 15:48:06 -0700 | [diff] [blame] | 3878 | return mService.mUserController.isCurrentProfile(userId); |
Wale Ogunwale | 0bd2aa7 | 2015-04-16 13:50:44 -0700 | [diff] [blame] | 3879 | } |
| 3880 | |
Bryce Lee | b7c9b80 | 2017-05-02 14:20:24 -0700 | [diff] [blame] | 3881 | /** |
| 3882 | * Returns whether a stopping activity is present that should be stopped after visible, rather |
| 3883 | * than idle. |
| 3884 | * @return {@code true} if such activity is present. {@code false} otherwise. |
| 3885 | */ |
| 3886 | boolean isStoppingNoHistoryActivity() { |
| 3887 | // Activities that are marked as nohistory should be stopped immediately after the resumed |
| 3888 | // activity has become visible. |
| 3889 | for (ActivityRecord record : mStoppingActivities) { |
| 3890 | if (record.isNoHistory()) { |
| 3891 | return true; |
| 3892 | } |
| 3893 | } |
| 3894 | |
| 3895 | return false; |
| 3896 | } |
| 3897 | |
Winson Chung | 4dabf23 | 2017-01-25 13:25:22 -0800 | [diff] [blame] | 3898 | final ArrayList<ActivityRecord> processStoppingActivitiesLocked(ActivityRecord idleActivity, |
| 3899 | boolean remove, boolean processPausingActivities) { |
Craig Mautner | de4ef02 | 2013-04-07 19:01:33 -0700 | [diff] [blame] | 3900 | ArrayList<ActivityRecord> stops = null; |
| 3901 | |
| 3902 | final boolean nowVisible = allResumedActivitiesVisible(); |
Craig Mautner | 8c14c15 | 2015-01-15 17:32:07 -0800 | [diff] [blame] | 3903 | for (int activityNdx = mStoppingActivities.size() - 1; activityNdx >= 0; --activityNdx) { |
| 3904 | ActivityRecord s = mStoppingActivities.get(activityNdx); |
Bryce Lee | 4a19438 | 2017-04-04 14:32:48 -0700 | [diff] [blame] | 3905 | boolean waitingVisible = mActivitiesWaitingForVisibleActivity.contains(s); |
Wale Ogunwale | f81c1d1 | 2016-01-12 12:20:18 -0800 | [diff] [blame] | 3906 | if (DEBUG_STATES) Slog.v(TAG, "Stopping " + s + ": nowVisible=" + nowVisible |
Craig Mautner | 8c14c15 | 2015-01-15 17:32:07 -0800 | [diff] [blame] | 3907 | + " waitingVisible=" + waitingVisible + " finishing=" + s.finishing); |
| 3908 | if (waitingVisible && nowVisible) { |
Bryce Lee | 4a19438 | 2017-04-04 14:32:48 -0700 | [diff] [blame] | 3909 | mActivitiesWaitingForVisibleActivity.remove(s); |
Andrii Kulian | ee05681 | 2016-09-21 15:34:45 -0700 | [diff] [blame] | 3910 | waitingVisible = false; |
Craig Mautner | de4ef02 | 2013-04-07 19:01:33 -0700 | [diff] [blame] | 3911 | if (s.finishing) { |
| 3912 | // If this activity is finishing, it is sitting on top of |
| 3913 | // everyone else but we now know it is no longer needed... |
| 3914 | // so get rid of it. Otherwise, we need to go through the |
| 3915 | // normal flow and hide it once we determine that it is |
| 3916 | // hidden by the activities in front of it. |
Wale Ogunwale | f81c1d1 | 2016-01-12 12:20:18 -0800 | [diff] [blame] | 3917 | if (DEBUG_STATES) Slog.v(TAG, "Before stopping, can hide: " + s); |
Wale Ogunwale | 26c0dfe | 2016-12-14 14:42:30 -0800 | [diff] [blame] | 3918 | s.setVisibility(false); |
Craig Mautner | de4ef02 | 2013-04-07 19:01:33 -0700 | [diff] [blame] | 3919 | } |
| 3920 | } |
David Stevens | 9440dc8 | 2017-03-16 19:00:20 -0700 | [diff] [blame] | 3921 | if (remove) { |
| 3922 | final ActivityStack stack = s.getStack(); |
| 3923 | final boolean shouldSleepOrShutDown = stack != null |
| 3924 | ? stack.shouldSleepOrShutDownActivities() |
| 3925 | : mService.isSleepingOrShuttingDownLocked(); |
| 3926 | if (!waitingVisible || shouldSleepOrShutDown) { |
Bryce Lee | 7ace395 | 2018-02-16 14:34:32 -0800 | [diff] [blame] | 3927 | if (!processPausingActivities && s.isState(PAUSING)) { |
David Stevens | 9440dc8 | 2017-03-16 19:00:20 -0700 | [diff] [blame] | 3928 | // Defer processing pausing activities in this iteration and reschedule |
| 3929 | // a delayed idle to reprocess it again |
| 3930 | removeTimeoutsForActivityLocked(idleActivity); |
| 3931 | scheduleIdleTimeoutLocked(idleActivity); |
| 3932 | continue; |
| 3933 | } |
Winson Chung | 4dabf23 | 2017-01-25 13:25:22 -0800 | [diff] [blame] | 3934 | |
David Stevens | 9440dc8 | 2017-03-16 19:00:20 -0700 | [diff] [blame] | 3935 | if (DEBUG_STATES) Slog.v(TAG, "Ready to stop: " + s); |
| 3936 | if (stops == null) { |
| 3937 | stops = new ArrayList<>(); |
| 3938 | } |
| 3939 | stops.add(s); |
Jorim Jaggi | 5db9ae4 | 2018-06-25 16:14:50 +0200 | [diff] [blame] | 3940 | |
| 3941 | // Make sure to remove it in all cases in case we entered this block with |
| 3942 | // shouldSleepOrShutDown |
| 3943 | mActivitiesWaitingForVisibleActivity.remove(s); |
David Stevens | 9440dc8 | 2017-03-16 19:00:20 -0700 | [diff] [blame] | 3944 | mStoppingActivities.remove(activityNdx); |
Craig Mautner | de4ef02 | 2013-04-07 19:01:33 -0700 | [diff] [blame] | 3945 | } |
Craig Mautner | de4ef02 | 2013-04-07 19:01:33 -0700 | [diff] [blame] | 3946 | } |
| 3947 | } |
| 3948 | |
| 3949 | return stops; |
| 3950 | } |
| 3951 | |
Craig Mautner | cf910b0 | 2013-04-23 11:23:27 -0700 | [diff] [blame] | 3952 | void validateTopActivitiesLocked() { |
Wale Ogunwale | ee006da | 2015-03-30 14:49:25 -0700 | [diff] [blame] | 3953 | for (int displayNdx = mActivityDisplays.size() - 1; displayNdx >= 0; --displayNdx) { |
Wale Ogunwale | a0f5b5e | 2017-10-11 09:37:23 -0700 | [diff] [blame] | 3954 | final ActivityDisplay display = mActivityDisplays.valueAt(displayNdx); |
| 3955 | for (int stackNdx = display.getChildCount() - 1; stackNdx >= 0; --stackNdx) { |
| 3956 | final ActivityStack stack = display.getChildAt(stackNdx); |
Filip Gruszczynski | 3e85ba2 | 2015-10-05 22:48:30 -0700 | [diff] [blame] | 3957 | final ActivityRecord r = stack.topRunningActivityLocked(); |
Bryce Lee | 7ace395 | 2018-02-16 14:34:32 -0800 | [diff] [blame] | 3958 | final ActivityState state = r == null ? DESTROYED : r.getState(); |
Wale Ogunwale | 1e60e0c | 2015-10-28 13:36:10 -0700 | [diff] [blame] | 3959 | if (isFocusedStack(stack)) { |
Wale Ogunwale | ee006da | 2015-03-30 14:49:25 -0700 | [diff] [blame] | 3960 | if (r == null) Slog.e(TAG, |
| 3961 | "validateTop...: null top activity, stack=" + stack); |
| 3962 | else { |
| 3963 | final ActivityRecord pausing = stack.mPausingActivity; |
| 3964 | if (pausing != null && pausing == r) Slog.e(TAG, |
| 3965 | "validateTop...: top stack has pausing activity r=" + r |
| 3966 | + " state=" + state); |
| 3967 | if (state != INITIALIZING && state != RESUMED) Slog.e(TAG, |
| 3968 | "validateTop...: activity in front not resumed r=" + r |
| 3969 | + " state=" + state); |
| 3970 | } |
Craig Mautner | cf910b0 | 2013-04-23 11:23:27 -0700 | [diff] [blame] | 3971 | } else { |
Bryce Lee | c4ab62a | 2018-03-05 14:19:26 -0800 | [diff] [blame] | 3972 | final ActivityRecord resumed = stack.getResumedActivity(); |
Wale Ogunwale | ee006da | 2015-03-30 14:49:25 -0700 | [diff] [blame] | 3973 | if (resumed != null && resumed == r) Slog.e(TAG, |
| 3974 | "validateTop...: back stack has resumed activity r=" + r |
| 3975 | + " state=" + state); |
| 3976 | if (r != null && (state == INITIALIZING || state == RESUMED)) Slog.e(TAG, |
| 3977 | "validateTop...: activity in back resumed r=" + r + " state=" + state); |
Craig Mautner | cf910b0 | 2013-04-23 11:23:27 -0700 | [diff] [blame] | 3978 | } |
| 3979 | } |
| 3980 | } |
Craig Mautner | 76ea224 | 2013-05-15 11:40:05 -0700 | [diff] [blame] | 3981 | } |
| 3982 | |
Bryce Lee | 77a7dd6 | 2018-01-22 15:47:09 -0800 | [diff] [blame] | 3983 | public void dumpDisplays(PrintWriter pw) { |
| 3984 | for (int i = mActivityDisplays.size() - 1; i >= 0; --i) { |
| 3985 | final ActivityDisplay display = mActivityDisplays.valueAt(i); |
| 3986 | pw.print("[id:" + display.mDisplayId + " stacks:"); |
| 3987 | display.dumpStacks(pw); |
| 3988 | pw.print("]"); |
| 3989 | } |
| 3990 | } |
| 3991 | |
Craig Mautner | 2708430 | 2013-03-25 08:05:25 -0700 | [diff] [blame] | 3992 | public void dump(PrintWriter pw, String prefix) { |
Craig Mautner | d1bbdb462 | 2013-10-22 09:53:20 -0700 | [diff] [blame] | 3993 | pw.print(prefix); pw.print("mFocusedStack=" + mFocusedStack); |
Craig Mautner | 4a1cb22 | 2013-12-04 16:14:06 -0800 | [diff] [blame] | 3994 | pw.print(" mLastFocusedStack="); pw.println(mLastFocusedStack); |
Suprabh Shukla | 09a88f5 | 2015-12-02 14:36:31 -0800 | [diff] [blame] | 3995 | pw.print(prefix); |
| 3996 | pw.println("mCurTaskIdForUser=" + mCurTaskIdForUser); |
Craig Mautner | d1bbdb462 | 2013-10-22 09:53:20 -0700 | [diff] [blame] | 3997 | pw.print(prefix); pw.println("mUserStackInFront=" + mUserStackInFront); |
Wale Ogunwale | 9dcf946 | 2017-09-19 15:13:01 -0700 | [diff] [blame] | 3998 | for (int i = mActivityDisplays.size() - 1; i >= 0; --i) { |
| 3999 | final ActivityDisplay display = mActivityDisplays.valueAt(i); |
Wale Ogunwale | a0f5b5e | 2017-10-11 09:37:23 -0700 | [diff] [blame] | 4000 | display.dump(pw, prefix); |
Wale Ogunwale | 9dcf946 | 2017-09-19 15:13:01 -0700 | [diff] [blame] | 4001 | } |
Bryce Lee | 4a19438 | 2017-04-04 14:32:48 -0700 | [diff] [blame] | 4002 | if (!mWaitingForActivityVisible.isEmpty()) { |
| 4003 | pw.print(prefix); pw.println("mWaitingForActivityVisible="); |
| 4004 | for (int i = 0; i < mWaitingForActivityVisible.size(); ++i) { |
| 4005 | pw.print(prefix); pw.print(prefix); mWaitingForActivityVisible.get(i).dump(pw, prefix); |
| 4006 | } |
| 4007 | } |
Winson Chung | c167427 | 2018-02-21 10:15:17 -0800 | [diff] [blame] | 4008 | pw.print(prefix); pw.print("isHomeRecentsComponent="); |
| 4009 | pw.print(mRecentTasks.isRecentsComponentHomeActivity(mCurrentUser)); |
Bryce Lee | 4a19438 | 2017-04-04 14:32:48 -0700 | [diff] [blame] | 4010 | |
Bryce Lee | 459c062 | 2018-03-19 11:04:01 -0700 | [diff] [blame] | 4011 | getKeyguardController().dump(pw, prefix); |
Bryce Lee | 2b8e037 | 2018-04-05 17:01:37 -0700 | [diff] [blame] | 4012 | mService.getLockTaskController().dump(pw, prefix); |
Craig Mautner | 2708430 | 2013-03-25 08:05:25 -0700 | [diff] [blame] | 4013 | } |
Craig Mautner | 8d341ef | 2013-03-26 09:03:27 -0700 | [diff] [blame] | 4014 | |
Yi Jin | 2b30f32 | 2018-02-20 15:41:47 -0800 | [diff] [blame] | 4015 | public void writeToProto(ProtoOutputStream proto, long fieldId) { |
| 4016 | final long token = proto.start(fieldId); |
Adrian Roos | 4921ccf | 2017-09-28 16:54:06 +0200 | [diff] [blame] | 4017 | super.writeToProto(proto, CONFIGURATION_CONTAINER, false /* trim */); |
Steven Timotius | 4346f0a | 2017-09-12 11:07:21 -0700 | [diff] [blame] | 4018 | for (int displayNdx = 0; displayNdx < mActivityDisplays.size(); ++displayNdx) { |
| 4019 | ActivityDisplay activityDisplay = mActivityDisplays.valueAt(displayNdx); |
| 4020 | activityDisplay.writeToProto(proto, DISPLAYS); |
| 4021 | } |
Bryce Lee | 459c062 | 2018-03-19 11:04:01 -0700 | [diff] [blame] | 4022 | getKeyguardController().writeToProto(proto, KEYGUARD_CONTROLLER); |
Steven Timotius | 4346f0a | 2017-09-12 11:07:21 -0700 | [diff] [blame] | 4023 | if (mFocusedStack != null) { |
| 4024 | proto.write(FOCUSED_STACK_ID, mFocusedStack.mStackId); |
| 4025 | ActivityRecord focusedActivity = getResumedActivityLocked(); |
| 4026 | if (focusedActivity != null) { |
| 4027 | focusedActivity.writeIdentifierToProto(proto, RESUMED_ACTIVITY); |
| 4028 | } |
| 4029 | } else { |
| 4030 | proto.write(FOCUSED_STACK_ID, INVALID_STACK_ID); |
| 4031 | } |
Winson Chung | c167427 | 2018-02-21 10:15:17 -0800 | [diff] [blame] | 4032 | proto.write(IS_HOME_RECENTS_COMPONENT, |
| 4033 | mRecentTasks.isRecentsComponentHomeActivity(mCurrentUser)); |
Yi Jin | 2b30f32 | 2018-02-20 15:41:47 -0800 | [diff] [blame] | 4034 | proto.end(token); |
Steven Timotius | 4346f0a | 2017-09-12 11:07:21 -0700 | [diff] [blame] | 4035 | } |
| 4036 | |
Winson | 43d1f26 | 2016-06-14 16:05:55 -0700 | [diff] [blame] | 4037 | /** |
Andrii Kulian | 5406e7a | 2016-10-21 11:55:23 -0700 | [diff] [blame] | 4038 | * Dump all connected displays' configurations. |
| 4039 | * @param prefix Prefix to apply to each line of the dump. |
| 4040 | */ |
| 4041 | void dumpDisplayConfigs(PrintWriter pw, String prefix) { |
| 4042 | pw.print(prefix); pw.println("Display override configurations:"); |
| 4043 | final int displayCount = mActivityDisplays.size(); |
| 4044 | for (int i = 0; i < displayCount; i++) { |
| 4045 | final ActivityDisplay activityDisplay = mActivityDisplays.valueAt(i); |
| 4046 | pw.print(prefix); pw.print(" "); pw.print(activityDisplay.mDisplayId); pw.print(": "); |
| 4047 | pw.println(activityDisplay.getOverrideConfiguration()); |
| 4048 | } |
| 4049 | } |
| 4050 | |
| 4051 | /** |
Winson | 43d1f26 | 2016-06-14 16:05:55 -0700 | [diff] [blame] | 4052 | * Dumps the activities matching the given {@param name} in the either the focused stack |
| 4053 | * or all visible stacks if {@param dumpVisibleStacks} is true. |
| 4054 | */ |
Winson Chung | 6998bc4 | 2017-02-28 17:07:05 -0800 | [diff] [blame] | 4055 | ArrayList<ActivityRecord> getDumpActivitiesLocked(String name, boolean dumpVisibleStacksOnly, |
| 4056 | boolean dumpFocusedStackOnly) { |
| 4057 | if (dumpFocusedStackOnly) { |
| 4058 | return mFocusedStack.getDumpActivitiesLocked(name); |
| 4059 | } else { |
Winson | 43d1f26 | 2016-06-14 16:05:55 -0700 | [diff] [blame] | 4060 | ArrayList<ActivityRecord> activities = new ArrayList<>(); |
| 4061 | int numDisplays = mActivityDisplays.size(); |
| 4062 | for (int displayNdx = 0; displayNdx < numDisplays; ++displayNdx) { |
Wale Ogunwale | a0f5b5e | 2017-10-11 09:37:23 -0700 | [diff] [blame] | 4063 | final ActivityDisplay display = mActivityDisplays.valueAt(displayNdx); |
| 4064 | for (int stackNdx = display.getChildCount() - 1; stackNdx >= 0; --stackNdx) { |
| 4065 | final ActivityStack stack = display.getChildAt(stackNdx); |
Wale Ogunwale | 9dcf946 | 2017-09-19 15:13:01 -0700 | [diff] [blame] | 4066 | if (!dumpVisibleStacksOnly || stack.shouldBeVisible(null)) { |
Winson | 43d1f26 | 2016-06-14 16:05:55 -0700 | [diff] [blame] | 4067 | activities.addAll(stack.getDumpActivitiesLocked(name)); |
| 4068 | } |
| 4069 | } |
| 4070 | } |
| 4071 | return activities; |
Winson | 43d1f26 | 2016-06-14 16:05:55 -0700 | [diff] [blame] | 4072 | } |
Craig Mautner | 20e7227 | 2013-04-01 13:45:53 -0700 | [diff] [blame] | 4073 | } |
| 4074 | |
Dianne Hackborn | 390517b | 2013-05-30 15:03:32 -0700 | [diff] [blame] | 4075 | static boolean printThisActivity(PrintWriter pw, ActivityRecord activity, String dumpPackage, |
| 4076 | boolean needSep, String prefix) { |
| 4077 | if (activity != null) { |
| 4078 | if (dumpPackage == null || dumpPackage.equals(activity.packageName)) { |
| 4079 | if (needSep) { |
| 4080 | pw.println(); |
Dianne Hackborn | 390517b | 2013-05-30 15:03:32 -0700 | [diff] [blame] | 4081 | } |
| 4082 | pw.print(prefix); |
| 4083 | pw.println(activity); |
Dianne Hackborn | 7ad34e5 | 2013-06-05 18:41:45 -0700 | [diff] [blame] | 4084 | return true; |
Dianne Hackborn | 390517b | 2013-05-30 15:03:32 -0700 | [diff] [blame] | 4085 | } |
| 4086 | } |
Dianne Hackborn | 7ad34e5 | 2013-06-05 18:41:45 -0700 | [diff] [blame] | 4087 | return false; |
Dianne Hackborn | 390517b | 2013-05-30 15:03:32 -0700 | [diff] [blame] | 4088 | } |
| 4089 | |
Craig Mautner | 8d341ef | 2013-03-26 09:03:27 -0700 | [diff] [blame] | 4090 | boolean dumpActivitiesLocked(FileDescriptor fd, PrintWriter pw, boolean dumpAll, |
| 4091 | boolean dumpClient, String dumpPackage) { |
Dianne Hackborn | 7ad34e5 | 2013-06-05 18:41:45 -0700 | [diff] [blame] | 4092 | boolean printed = false; |
| 4093 | boolean needSep = false; |
Craig Mautner | e0a3884 | 2013-12-16 16:14:02 -0800 | [diff] [blame] | 4094 | for (int displayNdx = 0; displayNdx < mActivityDisplays.size(); ++displayNdx) { |
| 4095 | ActivityDisplay activityDisplay = mActivityDisplays.valueAt(displayNdx); |
Craig Mautner | ee2e45a | 2014-06-27 12:10:03 -0700 | [diff] [blame] | 4096 | pw.print("Display #"); pw.print(activityDisplay.mDisplayId); |
Craig Mautner | 737fae2 | 2014-10-15 12:52:10 -0700 | [diff] [blame] | 4097 | pw.println(" (activities from top to bottom):"); |
Wale Ogunwale | a0f5b5e | 2017-10-11 09:37:23 -0700 | [diff] [blame] | 4098 | final ActivityDisplay display = mActivityDisplays.valueAt(displayNdx); |
| 4099 | for (int stackNdx = display.getChildCount() - 1; stackNdx >= 0; --stackNdx) { |
| 4100 | final ActivityStack stack = display.getChildAt(stackNdx); |
Wale Ogunwale | 34a5b57 | 2017-08-31 08:29:41 -0700 | [diff] [blame] | 4101 | pw.println(); |
Wale Ogunwale | 44f036f | 2017-09-29 05:09:09 -0700 | [diff] [blame] | 4102 | pw.println(" Stack #" + stack.mStackId |
Wale Ogunwale | 6191149 | 2017-10-11 08:50:50 -0700 | [diff] [blame] | 4103 | + ": type=" + activityTypeToString(stack.getActivityType()) |
| 4104 | + " mode=" + windowingModeToString(stack.getWindowingMode())); |
Wale Ogunwale | 34a5b57 | 2017-08-31 08:29:41 -0700 | [diff] [blame] | 4105 | pw.println(" isSleeping=" + stack.shouldSleepActivities()); |
Bryce Lee | f3c6a47 | 2017-11-14 14:53:06 -0800 | [diff] [blame] | 4106 | pw.println(" mBounds=" + stack.getOverrideBounds()); |
Winson Chung | abb433b | 2017-03-24 09:35:42 -0700 | [diff] [blame] | 4107 | |
Wale Ogunwale | 34a5b57 | 2017-08-31 08:29:41 -0700 | [diff] [blame] | 4108 | printed |= stack.dumpActivitiesLocked(fd, pw, dumpAll, dumpClient, dumpPackage, |
| 4109 | needSep); |
Winson Chung | abb433b | 2017-03-24 09:35:42 -0700 | [diff] [blame] | 4110 | |
Craig Mautner | 4a1cb22 | 2013-12-04 16:14:06 -0800 | [diff] [blame] | 4111 | printed |= dumpHistoryList(fd, pw, stack.mLRUActivities, " ", "Run", false, |
| 4112 | !dumpAll, false, dumpPackage, true, |
| 4113 | " Running activities (most recent first):", null); |
Craig Mautner | 8d341ef | 2013-03-26 09:03:27 -0700 | [diff] [blame] | 4114 | |
Craig Mautner | 4a1cb22 | 2013-12-04 16:14:06 -0800 | [diff] [blame] | 4115 | needSep = printed; |
| 4116 | boolean pr = printThisActivity(pw, stack.mPausingActivity, dumpPackage, needSep, |
| 4117 | " mPausingActivity: "); |
Dianne Hackborn | 7ad34e5 | 2013-06-05 18:41:45 -0700 | [diff] [blame] | 4118 | if (pr) { |
| 4119 | printed = true; |
Craig Mautner | 4a1cb22 | 2013-12-04 16:14:06 -0800 | [diff] [blame] | 4120 | needSep = false; |
Dianne Hackborn | 7ad34e5 | 2013-06-05 18:41:45 -0700 | [diff] [blame] | 4121 | } |
Bryce Lee | c4ab62a | 2018-03-05 14:19:26 -0800 | [diff] [blame] | 4122 | pr = printThisActivity(pw, stack.getResumedActivity(), dumpPackage, needSep, |
Craig Mautner | 4a1cb22 | 2013-12-04 16:14:06 -0800 | [diff] [blame] | 4123 | " mResumedActivity: "); |
| 4124 | if (pr) { |
| 4125 | printed = true; |
| 4126 | needSep = false; |
| 4127 | } |
| 4128 | if (dumpAll) { |
| 4129 | pr = printThisActivity(pw, stack.mLastPausedActivity, dumpPackage, needSep, |
| 4130 | " mLastPausedActivity: "); |
| 4131 | if (pr) { |
| 4132 | printed = true; |
| 4133 | needSep = true; |
| 4134 | } |
| 4135 | printed |= printThisActivity(pw, stack.mLastNoHistoryActivity, dumpPackage, |
| 4136 | needSep, " mLastNoHistoryActivity: "); |
| 4137 | } |
| 4138 | needSep = printed; |
Craig Mautner | 8d341ef | 2013-03-26 09:03:27 -0700 | [diff] [blame] | 4139 | } |
| 4140 | } |
| 4141 | |
Dianne Hackborn | 7ad34e5 | 2013-06-05 18:41:45 -0700 | [diff] [blame] | 4142 | printed |= dumpHistoryList(fd, pw, mFinishingActivities, " ", "Fin", false, !dumpAll, |
| 4143 | false, dumpPackage, true, " Activities waiting to finish:", null); |
| 4144 | printed |= dumpHistoryList(fd, pw, mStoppingActivities, " ", "Stop", false, !dumpAll, |
| 4145 | false, dumpPackage, true, " Activities waiting to stop:", null); |
Bryce Lee | 4a19438 | 2017-04-04 14:32:48 -0700 | [diff] [blame] | 4146 | printed |= dumpHistoryList(fd, pw, mActivitiesWaitingForVisibleActivity, " ", "Wait", |
| 4147 | false, !dumpAll, false, dumpPackage, true, |
| 4148 | " Activities waiting for another to become visible:", null); |
Dianne Hackborn | 7ad34e5 | 2013-06-05 18:41:45 -0700 | [diff] [blame] | 4149 | printed |= dumpHistoryList(fd, pw, mGoingToSleepActivities, " ", "Sleep", false, !dumpAll, |
| 4150 | false, dumpPackage, true, " Activities waiting to sleep:", null); |
Craig Mautner | f333327 | 2013-04-22 10:55:53 -0700 | [diff] [blame] | 4151 | |
Dianne Hackborn | 7ad34e5 | 2013-06-05 18:41:45 -0700 | [diff] [blame] | 4152 | return printed; |
Craig Mautner | 8d341ef | 2013-03-26 09:03:27 -0700 | [diff] [blame] | 4153 | } |
| 4154 | |
Dianne Hackborn | 390517b | 2013-05-30 15:03:32 -0700 | [diff] [blame] | 4155 | static boolean dumpHistoryList(FileDescriptor fd, PrintWriter pw, List<ActivityRecord> list, |
Craig Mautner | 8d341ef | 2013-03-26 09:03:27 -0700 | [diff] [blame] | 4156 | String prefix, String label, boolean complete, boolean brief, boolean client, |
Wale Ogunwale | 34a5b57 | 2017-08-31 08:29:41 -0700 | [diff] [blame] | 4157 | String dumpPackage, boolean needNL, String header, TaskRecord lastTask) { |
Dianne Hackborn | 390517b | 2013-05-30 15:03:32 -0700 | [diff] [blame] | 4158 | String innerPrefix = null; |
| 4159 | String[] args = null; |
| 4160 | boolean printed = false; |
Craig Mautner | 8d341ef | 2013-03-26 09:03:27 -0700 | [diff] [blame] | 4161 | for (int i=list.size()-1; i>=0; i--) { |
| 4162 | final ActivityRecord r = list.get(i); |
| 4163 | if (dumpPackage != null && !dumpPackage.equals(r.packageName)) { |
| 4164 | continue; |
| 4165 | } |
Dianne Hackborn | 390517b | 2013-05-30 15:03:32 -0700 | [diff] [blame] | 4166 | if (innerPrefix == null) { |
| 4167 | innerPrefix = prefix + " "; |
| 4168 | args = new String[0]; |
| 4169 | } |
| 4170 | printed = true; |
Craig Mautner | 8d341ef | 2013-03-26 09:03:27 -0700 | [diff] [blame] | 4171 | final boolean full = !brief && (complete || !r.isInHistory()); |
| 4172 | if (needNL) { |
Dianne Hackborn | 390517b | 2013-05-30 15:03:32 -0700 | [diff] [blame] | 4173 | pw.println(""); |
Craig Mautner | 8d341ef | 2013-03-26 09:03:27 -0700 | [diff] [blame] | 4174 | needNL = false; |
| 4175 | } |
Wale Ogunwale | 34a5b57 | 2017-08-31 08:29:41 -0700 | [diff] [blame] | 4176 | if (header != null) { |
| 4177 | pw.println(header); |
| 4178 | header = null; |
Dianne Hackborn | 390517b | 2013-05-30 15:03:32 -0700 | [diff] [blame] | 4179 | } |
Bryce Lee | af691c0 | 2017-03-20 14:20:22 -0700 | [diff] [blame] | 4180 | if (lastTask != r.getTask()) { |
| 4181 | lastTask = r.getTask(); |
Craig Mautner | 8d341ef | 2013-03-26 09:03:27 -0700 | [diff] [blame] | 4182 | pw.print(prefix); |
| 4183 | pw.print(full ? "* " : " "); |
| 4184 | pw.println(lastTask); |
| 4185 | if (full) { |
| 4186 | lastTask.dump(pw, prefix + " "); |
| 4187 | } else if (complete) { |
| 4188 | // Complete + brief == give a summary. Isn't that obvious?!? |
| 4189 | if (lastTask.intent != null) { |
| 4190 | pw.print(prefix); pw.print(" "); |
| 4191 | pw.println(lastTask.intent.toInsecureStringWithClip()); |
| 4192 | } |
| 4193 | } |
| 4194 | } |
| 4195 | pw.print(prefix); pw.print(full ? " * " : " "); pw.print(label); |
| 4196 | pw.print(" #"); pw.print(i); pw.print(": "); |
| 4197 | pw.println(r); |
| 4198 | if (full) { |
| 4199 | r.dump(pw, innerPrefix); |
| 4200 | } else if (complete) { |
| 4201 | // Complete + brief == give a summary. Isn't that obvious?!? |
| 4202 | pw.print(innerPrefix); pw.println(r.intent.toInsecureString()); |
| 4203 | if (r.app != null) { |
| 4204 | pw.print(innerPrefix); pw.println(r.app); |
| 4205 | } |
| 4206 | } |
| 4207 | if (client && r.app != null && r.app.thread != null) { |
| 4208 | // flush anything that is already in the PrintWriter since the thread is going |
| 4209 | // to write to the file descriptor directly |
| 4210 | pw.flush(); |
| 4211 | try { |
| 4212 | TransferPipe tp = new TransferPipe(); |
| 4213 | try { |
Sudheer Shanka | cc6418f | 2016-10-13 12:03:44 -0700 | [diff] [blame] | 4214 | r.app.thread.dumpActivity(tp.getWriteFd(), r.appToken, innerPrefix, args); |
Craig Mautner | 8d341ef | 2013-03-26 09:03:27 -0700 | [diff] [blame] | 4215 | // Short timeout, since blocking here can |
| 4216 | // deadlock with the application. |
| 4217 | tp.go(fd, 2000); |
| 4218 | } finally { |
| 4219 | tp.kill(); |
| 4220 | } |
| 4221 | } catch (IOException e) { |
| 4222 | pw.println(innerPrefix + "Failure while dumping the activity: " + e); |
| 4223 | } catch (RemoteException e) { |
| 4224 | pw.println(innerPrefix + "Got a RemoteException while dumping the activity"); |
| 4225 | } |
| 4226 | needNL = true; |
| 4227 | } |
| 4228 | } |
Dianne Hackborn | 390517b | 2013-05-30 15:03:32 -0700 | [diff] [blame] | 4229 | return printed; |
Craig Mautner | 8d341ef | 2013-03-26 09:03:27 -0700 | [diff] [blame] | 4230 | } |
Craig Mautner | ce5f3cb | 2013-04-22 08:58:54 -0700 | [diff] [blame] | 4231 | |
Craig Mautner | f333327 | 2013-04-22 10:55:53 -0700 | [diff] [blame] | 4232 | void scheduleIdleTimeoutLocked(ActivityRecord next) { |
Wale Ogunwale | 0fc365c | 2015-05-25 19:35:42 -0700 | [diff] [blame] | 4233 | if (DEBUG_IDLE) Slog.d(TAG_IDLE, |
| 4234 | "scheduleIdleTimeoutLocked: Callers=" + Debug.getCallers(4)); |
Craig Mautner | c64f73e | 2013-04-24 16:44:56 -0700 | [diff] [blame] | 4235 | Message msg = mHandler.obtainMessage(IDLE_TIMEOUT_MSG, next); |
| 4236 | mHandler.sendMessageDelayed(msg, IDLE_TIMEOUT); |
Craig Mautner | f333327 | 2013-04-22 10:55:53 -0700 | [diff] [blame] | 4237 | } |
| 4238 | |
| 4239 | final void scheduleIdleLocked() { |
Craig Mautner | 05d2903 | 2013-05-03 13:40:13 -0700 | [diff] [blame] | 4240 | mHandler.sendEmptyMessage(IDLE_NOW_MSG); |
Craig Mautner | f333327 | 2013-04-22 10:55:53 -0700 | [diff] [blame] | 4241 | } |
| 4242 | |
| 4243 | void removeTimeoutsForActivityLocked(ActivityRecord r) { |
Wale Ogunwale | 0fc365c | 2015-05-25 19:35:42 -0700 | [diff] [blame] | 4244 | if (DEBUG_IDLE) Slog.d(TAG_IDLE, "removeTimeoutsForActivity: Callers=" |
| 4245 | + Debug.getCallers(4)); |
Craig Mautner | f333327 | 2013-04-22 10:55:53 -0700 | [diff] [blame] | 4246 | mHandler.removeMessages(IDLE_TIMEOUT_MSG, r); |
| 4247 | } |
| 4248 | |
Craig Mautner | 05d2903 | 2013-05-03 13:40:13 -0700 | [diff] [blame] | 4249 | final void scheduleResumeTopActivities() { |
Craig Mautner | 34b73df | 2014-01-12 21:11:08 -0800 | [diff] [blame] | 4250 | if (!mHandler.hasMessages(RESUME_TOP_ACTIVITY_MSG)) { |
| 4251 | mHandler.sendEmptyMessage(RESUME_TOP_ACTIVITY_MSG); |
| 4252 | } |
Craig Mautner | 05d2903 | 2013-05-03 13:40:13 -0700 | [diff] [blame] | 4253 | } |
| 4254 | |
Craig Mautner | 0eea92c | 2013-05-16 13:35:39 -0700 | [diff] [blame] | 4255 | void removeSleepTimeouts() { |
Craig Mautner | 0eea92c | 2013-05-16 13:35:39 -0700 | [diff] [blame] | 4256 | mHandler.removeMessages(SLEEP_TIMEOUT_MSG); |
| 4257 | } |
| 4258 | |
| 4259 | final void scheduleSleepTimeout() { |
| 4260 | removeSleepTimeouts(); |
| 4261 | mHandler.sendEmptyMessageDelayed(SLEEP_TIMEOUT_MSG, SLEEP_TIMEOUT); |
| 4262 | } |
| 4263 | |
Craig Mautner | 4a1cb22 | 2013-12-04 16:14:06 -0800 | [diff] [blame] | 4264 | @Override |
| 4265 | public void onDisplayAdded(int displayId) { |
Dianne Hackborn | fb81d09 | 2015-08-03 17:14:46 -0700 | [diff] [blame] | 4266 | if (DEBUG_STACK) Slog.v(TAG, "Display added displayId=" + displayId); |
Craig Mautner | 4a1cb22 | 2013-12-04 16:14:06 -0800 | [diff] [blame] | 4267 | mHandler.sendMessage(mHandler.obtainMessage(HANDLE_DISPLAY_ADDED, displayId, 0)); |
| 4268 | } |
| 4269 | |
| 4270 | @Override |
| 4271 | public void onDisplayRemoved(int displayId) { |
Dianne Hackborn | fb81d09 | 2015-08-03 17:14:46 -0700 | [diff] [blame] | 4272 | if (DEBUG_STACK) Slog.v(TAG, "Display removed displayId=" + displayId); |
Craig Mautner | 4a1cb22 | 2013-12-04 16:14:06 -0800 | [diff] [blame] | 4273 | mHandler.sendMessage(mHandler.obtainMessage(HANDLE_DISPLAY_REMOVED, displayId, 0)); |
| 4274 | } |
| 4275 | |
| 4276 | @Override |
| 4277 | public void onDisplayChanged(int displayId) { |
Dianne Hackborn | fb81d09 | 2015-08-03 17:14:46 -0700 | [diff] [blame] | 4278 | if (DEBUG_STACK) Slog.v(TAG, "Display changed displayId=" + displayId); |
Craig Mautner | 4a1cb22 | 2013-12-04 16:14:06 -0800 | [diff] [blame] | 4279 | mHandler.sendMessage(mHandler.obtainMessage(HANDLE_DISPLAY_CHANGED, displayId, 0)); |
| 4280 | } |
| 4281 | |
Wale Ogunwale | f16a281 | 2015-04-01 11:23:15 -0700 | [diff] [blame] | 4282 | private void handleDisplayAdded(int displayId) { |
Craig Mautner | 4a1cb22 | 2013-12-04 16:14:06 -0800 | [diff] [blame] | 4283 | synchronized (mService) { |
Andrii Kulian | 62e6f25 | 2017-05-30 22:46:53 -0700 | [diff] [blame] | 4284 | getActivityDisplayOrCreateLocked(displayId); |
Craig Mautner | 4a1cb22 | 2013-12-04 16:14:06 -0800 | [diff] [blame] | 4285 | } |
Craig Mautner | 4a1cb22 | 2013-12-04 16:14:06 -0800 | [diff] [blame] | 4286 | } |
| 4287 | |
Andrii Kulian | ca007a6 | 2016-11-22 16:33:28 -0800 | [diff] [blame] | 4288 | /** Check if display with specified id is added to the list. */ |
| 4289 | boolean isDisplayAdded(int displayId) { |
Andrii Kulian | 62e6f25 | 2017-05-30 22:46:53 -0700 | [diff] [blame] | 4290 | return getActivityDisplayOrCreateLocked(displayId) != null; |
| 4291 | } |
| 4292 | |
Wale Ogunwale | 04a05ac | 2017-09-17 21:35:02 -0700 | [diff] [blame] | 4293 | // TODO: Look into consolidating with getActivityDisplayOrCreateLocked() |
Andrii Kulian | 94e82d9b0 | 2017-07-13 15:33:06 -0700 | [diff] [blame] | 4294 | ActivityDisplay getActivityDisplay(int displayId) { |
| 4295 | return mActivityDisplays.get(displayId); |
| 4296 | } |
| 4297 | |
Wale Ogunwale | 04a05ac | 2017-09-17 21:35:02 -0700 | [diff] [blame] | 4298 | // TODO(multi-display): Look at all callpoints to make sure they make sense in multi-display. |
| 4299 | ActivityDisplay getDefaultDisplay() { |
| 4300 | return mActivityDisplays.get(DEFAULT_DISPLAY); |
| 4301 | } |
| 4302 | |
Andrii Kulian | 62e6f25 | 2017-05-30 22:46:53 -0700 | [diff] [blame] | 4303 | /** |
| 4304 | * Get an existing instance of {@link ActivityDisplay} or create new if there is a |
| 4305 | * corresponding record in display manager. |
| 4306 | */ |
Wale Ogunwale | 04a05ac | 2017-09-17 21:35:02 -0700 | [diff] [blame] | 4307 | // TODO: Look into consolidating with getActivityDisplay() |
| 4308 | ActivityDisplay getActivityDisplayOrCreateLocked(int displayId) { |
Andrii Kulian | 62e6f25 | 2017-05-30 22:46:53 -0700 | [diff] [blame] | 4309 | ActivityDisplay activityDisplay = mActivityDisplays.get(displayId); |
| 4310 | if (activityDisplay != null) { |
| 4311 | return activityDisplay; |
| 4312 | } |
| 4313 | if (mDisplayManager == null) { |
| 4314 | // The system isn't fully initialized yet. |
| 4315 | return null; |
| 4316 | } |
| 4317 | final Display display = mDisplayManager.getDisplay(displayId); |
| 4318 | if (display == null) { |
| 4319 | // The display is not registered in DisplayManager. |
| 4320 | return null; |
| 4321 | } |
| 4322 | // The display hasn't been added to ActivityManager yet, create a new record now. |
Wale Ogunwale | 45477b5 | 2018-03-06 12:24:19 -0800 | [diff] [blame] | 4323 | activityDisplay = new ActivityDisplay(this, display); |
Wale Ogunwale | 9dcf946 | 2017-09-19 15:13:01 -0700 | [diff] [blame] | 4324 | attachDisplay(activityDisplay); |
Andrii Kulian | 62e6f25 | 2017-05-30 22:46:53 -0700 | [diff] [blame] | 4325 | calculateDefaultMinimalSizeOfResizeableTasks(activityDisplay); |
| 4326 | mWindowManager.onDisplayAdded(displayId); |
| 4327 | return activityDisplay; |
Andrii Kulian | ca007a6 | 2016-11-22 16:33:28 -0800 | [diff] [blame] | 4328 | } |
| 4329 | |
Wale Ogunwale | 9dcf946 | 2017-09-19 15:13:01 -0700 | [diff] [blame] | 4330 | @VisibleForTesting |
| 4331 | void attachDisplay(ActivityDisplay display) { |
| 4332 | mActivityDisplays.put(display.mDisplayId, display); |
| 4333 | } |
| 4334 | |
Filip Gruszczynski | d2f1d94 | 2015-10-14 15:10:12 -0700 | [diff] [blame] | 4335 | private void calculateDefaultMinimalSizeOfResizeableTasks(ActivityDisplay display) { |
Andrii Kulian | f66a83d | 2016-05-17 12:17:44 -0700 | [diff] [blame] | 4336 | mDefaultMinSizeOfResizeableTask = |
Jorim Jaggi | 19cf297 | 2016-04-07 23:26:10 -0700 | [diff] [blame] | 4337 | mService.mContext.getResources().getDimensionPixelSize( |
| 4338 | com.android.internal.R.dimen.default_minimal_size_resizable_task); |
Filip Gruszczynski | d2f1d94 | 2015-10-14 15:10:12 -0700 | [diff] [blame] | 4339 | } |
| 4340 | |
Wale Ogunwale | f16a281 | 2015-04-01 11:23:15 -0700 | [diff] [blame] | 4341 | private void handleDisplayRemoved(int displayId) { |
Andrii Kulian | a33818c | 2017-02-16 16:11:30 -0800 | [diff] [blame] | 4342 | if (displayId == DEFAULT_DISPLAY) { |
| 4343 | throw new IllegalArgumentException("Can't remove the primary display."); |
| 4344 | } |
| 4345 | |
Craig Mautner | 4a1cb22 | 2013-12-04 16:14:06 -0800 | [diff] [blame] | 4346 | synchronized (mService) { |
Wale Ogunwale | a0f5b5e | 2017-10-11 09:37:23 -0700 | [diff] [blame] | 4347 | final ActivityDisplay activityDisplay = mActivityDisplays.get(displayId); |
| 4348 | if (activityDisplay == null) { |
| 4349 | return; |
Craig Mautner | 4a1cb22 | 2013-12-04 16:14:06 -0800 | [diff] [blame] | 4350 | } |
Bryce Lee | f19cbe2 | 2018-02-02 15:09:21 -0800 | [diff] [blame] | 4351 | |
| 4352 | activityDisplay.remove(); |
Wale Ogunwale | a0f5b5e | 2017-10-11 09:37:23 -0700 | [diff] [blame] | 4353 | |
| 4354 | releaseSleepTokens(activityDisplay); |
| 4355 | |
| 4356 | mActivityDisplays.remove(displayId); |
Craig Mautner | 4a1cb22 | 2013-12-04 16:14:06 -0800 | [diff] [blame] | 4357 | } |
Craig Mautner | 4a1cb22 | 2013-12-04 16:14:06 -0800 | [diff] [blame] | 4358 | } |
| 4359 | |
Wale Ogunwale | f16a281 | 2015-04-01 11:23:15 -0700 | [diff] [blame] | 4360 | private void handleDisplayChanged(int displayId) { |
Craig Mautner | 4a1cb22 | 2013-12-04 16:14:06 -0800 | [diff] [blame] | 4361 | synchronized (mService) { |
Craig Mautner | e0a3884 | 2013-12-16 16:14:02 -0800 | [diff] [blame] | 4362 | ActivityDisplay activityDisplay = mActivityDisplays.get(displayId); |
Bryce Lee | f3c6a47 | 2017-11-14 14:53:06 -0800 | [diff] [blame] | 4363 | // TODO: The following code block should be moved into {@link ActivityDisplay}. |
Craig Mautner | e0a3884 | 2013-12-16 16:14:02 -0800 | [diff] [blame] | 4364 | if (activityDisplay != null) { |
David Stevens | 9440dc8 | 2017-03-16 19:00:20 -0700 | [diff] [blame] | 4365 | // The window policy is responsible for stopping activities on the default display |
| 4366 | if (displayId != Display.DEFAULT_DISPLAY) { |
| 4367 | int displayState = activityDisplay.mDisplay.getState(); |
| 4368 | if (displayState == Display.STATE_OFF && activityDisplay.mOffToken == null) { |
| 4369 | activityDisplay.mOffToken = |
| 4370 | mService.acquireSleepToken("Display-off", displayId); |
| 4371 | } else if (displayState == Display.STATE_ON |
| 4372 | && activityDisplay.mOffToken != null) { |
| 4373 | activityDisplay.mOffToken.release(); |
| 4374 | activityDisplay.mOffToken = null; |
| 4375 | } |
| 4376 | } |
Bryce Lee | f3c6a47 | 2017-11-14 14:53:06 -0800 | [diff] [blame] | 4377 | |
| 4378 | activityDisplay.updateBounds(); |
Craig Mautner | 4a1cb22 | 2013-12-04 16:14:06 -0800 | [diff] [blame] | 4379 | } |
Bryce Lee | af3a400 | 2017-03-20 10:37:12 -0700 | [diff] [blame] | 4380 | mWindowManager.onDisplayChanged(displayId); |
Craig Mautner | 4a1cb22 | 2013-12-04 16:14:06 -0800 | [diff] [blame] | 4381 | } |
Craig Mautner | 4a1cb22 | 2013-12-04 16:14:06 -0800 | [diff] [blame] | 4382 | } |
| 4383 | |
David Stevens | 9440dc8 | 2017-03-16 19:00:20 -0700 | [diff] [blame] | 4384 | SleepToken createSleepTokenLocked(String tag, int displayId) { |
| 4385 | ActivityDisplay display = mActivityDisplays.get(displayId); |
| 4386 | if (display == null) { |
| 4387 | throw new IllegalArgumentException("Invalid display: " + displayId); |
| 4388 | } |
| 4389 | |
| 4390 | final SleepTokenImpl token = new SleepTokenImpl(tag, displayId); |
| 4391 | mSleepTokens.add(token); |
| 4392 | display.mAllSleepTokens.add(token); |
| 4393 | return token; |
| 4394 | } |
| 4395 | |
| 4396 | private void removeSleepTokenLocked(SleepTokenImpl token) { |
| 4397 | mSleepTokens.remove(token); |
| 4398 | |
| 4399 | ActivityDisplay display = mActivityDisplays.get(token.mDisplayId); |
| 4400 | if (display != null) { |
| 4401 | display.mAllSleepTokens.remove(token); |
| 4402 | if (display.mAllSleepTokens.isEmpty()) { |
| 4403 | mService.updateSleepIfNeededLocked(); |
| 4404 | } |
| 4405 | } |
| 4406 | } |
| 4407 | |
| 4408 | private void releaseSleepTokens(ActivityDisplay display) { |
| 4409 | if (display.mAllSleepTokens.isEmpty()) { |
| 4410 | return; |
| 4411 | } |
Wale Ogunwale | 9dcf946 | 2017-09-19 15:13:01 -0700 | [diff] [blame] | 4412 | for (SleepToken token : display.mAllSleepTokens) { |
David Stevens | 9440dc8 | 2017-03-16 19:00:20 -0700 | [diff] [blame] | 4413 | mSleepTokens.remove(token); |
| 4414 | } |
| 4415 | display.mAllSleepTokens.clear(); |
| 4416 | |
| 4417 | mService.updateSleepIfNeededLocked(); |
| 4418 | } |
| 4419 | |
Wale Ogunwale | 6827856 | 2017-09-23 17:13:55 -0700 | [diff] [blame] | 4420 | private StackInfo getStackInfo(ActivityStack stack) { |
Andrii Kulian | 7e215d7 | 2017-04-26 18:33:28 -0700 | [diff] [blame] | 4421 | final int displayId = stack.mDisplayId; |
| 4422 | final ActivityDisplay display = mActivityDisplays.get(displayId); |
Craig Mautner | 4a1cb22 | 2013-12-04 16:14:06 -0800 | [diff] [blame] | 4423 | StackInfo info = new StackInfo(); |
Wale Ogunwale | 1666e31 | 2016-12-16 11:27:18 -0800 | [diff] [blame] | 4424 | stack.getWindowContainerBounds(info.bounds); |
Andrii Kulian | 7e215d7 | 2017-04-26 18:33:28 -0700 | [diff] [blame] | 4425 | info.displayId = displayId; |
Craig Mautner | 4a1cb22 | 2013-12-04 16:14:06 -0800 | [diff] [blame] | 4426 | info.stackId = stack.mStackId; |
Filip Gruszczynski | 21199bd | 2015-12-02 12:49:58 -0800 | [diff] [blame] | 4427 | info.userId = stack.mCurrentUser; |
Wale Ogunwale | 9dcf946 | 2017-09-19 15:13:01 -0700 | [diff] [blame] | 4428 | info.visible = stack.shouldBeVisible(null); |
Andrii Kulian | 62e6f25 | 2017-05-30 22:46:53 -0700 | [diff] [blame] | 4429 | // A stack might be not attached to a display. |
Wale Ogunwale | a0f5b5e | 2017-10-11 09:37:23 -0700 | [diff] [blame] | 4430 | info.position = display != null ? display.getIndexOf(stack) : 0; |
Wale Ogunwale | 6827856 | 2017-09-23 17:13:55 -0700 | [diff] [blame] | 4431 | info.configuration.setTo(stack.getConfiguration()); |
Craig Mautner | 4a1cb22 | 2013-12-04 16:14:06 -0800 | [diff] [blame] | 4432 | |
| 4433 | ArrayList<TaskRecord> tasks = stack.getAllTasks(); |
| 4434 | final int numTasks = tasks.size(); |
| 4435 | int[] taskIds = new int[numTasks]; |
| 4436 | String[] taskNames = new String[numTasks]; |
Wale Ogunwale | e4a0c57 | 2015-06-30 08:40:31 -0700 | [diff] [blame] | 4437 | Rect[] taskBounds = new Rect[numTasks]; |
Filip Gruszczynski | 21199bd | 2015-12-02 12:49:58 -0800 | [diff] [blame] | 4438 | int[] taskUserIds = new int[numTasks]; |
Craig Mautner | 4a1cb22 | 2013-12-04 16:14:06 -0800 | [diff] [blame] | 4439 | for (int i = 0; i < numTasks; ++i) { |
| 4440 | final TaskRecord task = tasks.get(i); |
| 4441 | taskIds[i] = task.taskId; |
| 4442 | taskNames[i] = task.origActivity != null ? task.origActivity.flattenToString() |
| 4443 | : task.realActivity != null ? task.realActivity.flattenToString() |
| 4444 | : task.getTopActivity() != null ? task.getTopActivity().packageName |
| 4445 | : "unknown"; |
Wale Ogunwale | e4a0c57 | 2015-06-30 08:40:31 -0700 | [diff] [blame] | 4446 | taskBounds[i] = new Rect(); |
Wale Ogunwale | e1fe7fa2 | 2016-12-15 18:27:00 -0800 | [diff] [blame] | 4447 | task.getWindowContainerBounds(taskBounds[i]); |
Filip Gruszczynski | 21199bd | 2015-12-02 12:49:58 -0800 | [diff] [blame] | 4448 | taskUserIds[i] = task.userId; |
Craig Mautner | 4a1cb22 | 2013-12-04 16:14:06 -0800 | [diff] [blame] | 4449 | } |
| 4450 | info.taskIds = taskIds; |
| 4451 | info.taskNames = taskNames; |
Wale Ogunwale | 868a5e1 | 2015-08-02 16:19:20 -0700 | [diff] [blame] | 4452 | info.taskBounds = taskBounds; |
Filip Gruszczynski | 21199bd | 2015-12-02 12:49:58 -0800 | [diff] [blame] | 4453 | info.taskUserIds = taskUserIds; |
Winson | d46b727 | 2016-04-20 11:54:27 -0700 | [diff] [blame] | 4454 | |
| 4455 | final ActivityRecord top = stack.topRunningActivityLocked(); |
| 4456 | info.topActivity = top != null ? top.intent.getComponent() : null; |
Craig Mautner | 4a1cb22 | 2013-12-04 16:14:06 -0800 | [diff] [blame] | 4457 | return info; |
| 4458 | } |
| 4459 | |
Wale Ogunwale | 6827856 | 2017-09-23 17:13:55 -0700 | [diff] [blame] | 4460 | StackInfo getStackInfo(int stackId) { |
Craig Mautner | 4a1cb22 | 2013-12-04 16:14:06 -0800 | [diff] [blame] | 4461 | ActivityStack stack = getStack(stackId); |
| 4462 | if (stack != null) { |
Wale Ogunwale | 6827856 | 2017-09-23 17:13:55 -0700 | [diff] [blame] | 4463 | return getStackInfo(stack); |
Craig Mautner | 4a1cb22 | 2013-12-04 16:14:06 -0800 | [diff] [blame] | 4464 | } |
| 4465 | return null; |
| 4466 | } |
| 4467 | |
Wale Ogunwale | 6827856 | 2017-09-23 17:13:55 -0700 | [diff] [blame] | 4468 | StackInfo getStackInfo(int windowingMode, int activityType) { |
| 4469 | final ActivityStack stack = getStack(windowingMode, activityType); |
| 4470 | return (stack != null) ? getStackInfo(stack) : null; |
| 4471 | } |
| 4472 | |
Craig Mautner | 4a1cb22 | 2013-12-04 16:14:06 -0800 | [diff] [blame] | 4473 | ArrayList<StackInfo> getAllStackInfosLocked() { |
Wale Ogunwale | e4a0c57 | 2015-06-30 08:40:31 -0700 | [diff] [blame] | 4474 | ArrayList<StackInfo> list = new ArrayList<>(); |
Craig Mautner | e0a3884 | 2013-12-16 16:14:02 -0800 | [diff] [blame] | 4475 | for (int displayNdx = 0; displayNdx < mActivityDisplays.size(); ++displayNdx) { |
Wale Ogunwale | a0f5b5e | 2017-10-11 09:37:23 -0700 | [diff] [blame] | 4476 | final ActivityDisplay display = mActivityDisplays.valueAt(displayNdx); |
| 4477 | for (int stackNdx = display.getChildCount() - 1; stackNdx >= 0; --stackNdx) { |
| 4478 | final ActivityStack stack = display.getChildAt(stackNdx); |
| 4479 | list.add(getStackInfo(stack)); |
Craig Mautner | 4a1cb22 | 2013-12-04 16:14:06 -0800 | [diff] [blame] | 4480 | } |
| 4481 | } |
| 4482 | return list; |
| 4483 | } |
| 4484 | |
Wale Ogunwale | 0568aed | 2017-09-08 13:29:37 -0700 | [diff] [blame] | 4485 | void handleNonResizableTaskIfNeeded(TaskRecord task, int preferredWindowingMode, |
Wale Ogunwale | a0f5b5e | 2017-10-11 09:37:23 -0700 | [diff] [blame] | 4486 | int preferredDisplayId, ActivityStack actualStack) { |
Wale Ogunwale | 0568aed | 2017-09-08 13:29:37 -0700 | [diff] [blame] | 4487 | handleNonResizableTaskIfNeeded(task, preferredWindowingMode, preferredDisplayId, |
Wale Ogunwale | a0f5b5e | 2017-10-11 09:37:23 -0700 | [diff] [blame] | 4488 | actualStack, false /* forceNonResizable */); |
Andrii Kulian | c2791664 | 2016-04-12 17:59:27 -0700 | [diff] [blame] | 4489 | } |
| 4490 | |
Wale Ogunwale | 0568aed | 2017-09-08 13:29:37 -0700 | [diff] [blame] | 4491 | void handleNonResizableTaskIfNeeded(TaskRecord task, int preferredWindowingMode, |
Wale Ogunwale | a0f5b5e | 2017-10-11 09:37:23 -0700 | [diff] [blame] | 4492 | int preferredDisplayId, ActivityStack actualStack, boolean forceNonResizable) { |
Andrii Kulian | 036e3ad | 2017-04-19 10:55:10 -0700 | [diff] [blame] | 4493 | final boolean isSecondaryDisplayPreferred = |
Wale Ogunwale | 0568aed | 2017-09-08 13:29:37 -0700 | [diff] [blame] | 4494 | (preferredDisplayId != DEFAULT_DISPLAY && preferredDisplayId != INVALID_DISPLAY); |
Wale Ogunwale | 926aade | 2017-08-29 11:24:37 -0700 | [diff] [blame] | 4495 | final boolean inSplitScreenMode = actualStack != null |
Wale Ogunwale | 7e1f5f5 | 2017-10-18 15:19:59 -0700 | [diff] [blame] | 4496 | && actualStack.getDisplay().hasSplitScreenPrimaryStack(); |
Wale Ogunwale | 0568aed | 2017-09-08 13:29:37 -0700 | [diff] [blame] | 4497 | if (((!inSplitScreenMode && preferredWindowingMode != WINDOWING_MODE_SPLIT_SCREEN_PRIMARY) |
Wale Ogunwale | 7e1f5f5 | 2017-10-18 15:19:59 -0700 | [diff] [blame] | 4498 | && !isSecondaryDisplayPreferred) || !task.isActivityTypeStandardOrUndefined()) { |
Wale Ogunwale | b9b16a7 | 2016-01-27 12:24:44 -0800 | [diff] [blame] | 4499 | return; |
| 4500 | } |
| 4501 | |
Andrii Kulian | 036e3ad | 2017-04-19 10:55:10 -0700 | [diff] [blame] | 4502 | // Handle incorrect launch/move to secondary display if needed. |
Andrii Kulian | 036e3ad | 2017-04-19 10:55:10 -0700 | [diff] [blame] | 4503 | if (isSecondaryDisplayPreferred) { |
| 4504 | final int actualDisplayId = task.getStack().mDisplayId; |
| 4505 | if (!task.canBeLaunchedOnDisplay(actualDisplayId)) { |
Andrii Kulian | b850ea5 | 2017-12-12 23:49:10 -0800 | [diff] [blame] | 4506 | throw new IllegalStateException("Task resolved to incompatible display"); |
Andrii Kulian | 036e3ad | 2017-04-19 10:55:10 -0700 | [diff] [blame] | 4507 | } |
Andrii Kulian | b850ea5 | 2017-12-12 23:49:10 -0800 | [diff] [blame] | 4508 | // The task might have landed on a display different from requested. |
| 4509 | // TODO(multi-display): Find proper stack for the task on the default display. |
| 4510 | mService.setTaskWindowingMode(task.taskId, |
| 4511 | WINDOWING_MODE_FULLSCREEN_OR_SPLIT_SCREEN_SECONDARY, true /* toTop */); |
| 4512 | if (preferredDisplayId != actualDisplayId) { |
Andrii Kulian | 036e3ad | 2017-04-19 10:55:10 -0700 | [diff] [blame] | 4513 | // Display a warning toast that we tried to put a non-resizeable task on a secondary |
| 4514 | // display with config different from global config. |
| 4515 | mService.mTaskChangeNotificationController |
| 4516 | .notifyActivityLaunchOnSecondaryDisplayFailed(); |
Wale Ogunwale | 2b07da8 | 2017-11-08 14:52:40 -0800 | [diff] [blame] | 4517 | return; |
Andrii Kulian | 036e3ad | 2017-04-19 10:55:10 -0700 | [diff] [blame] | 4518 | } |
Wale Ogunwale | 2b07da8 | 2017-11-08 14:52:40 -0800 | [diff] [blame] | 4519 | } |
| 4520 | |
Wale Ogunwale | 2b07da8 | 2017-11-08 14:52:40 -0800 | [diff] [blame] | 4521 | if (!task.supportsSplitScreenWindowingMode() || forceNonResizable) { |
Wale Ogunwale | 30e441d | 2017-11-09 08:28:45 -0800 | [diff] [blame] | 4522 | // Display a warning toast that we tried to put an app that doesn't support split-screen |
| 4523 | // in split-screen. |
Wale Ogunwale | 2b07da8 | 2017-11-08 14:52:40 -0800 | [diff] [blame] | 4524 | mService.mTaskChangeNotificationController.notifyActivityDismissingDockedStack(); |
Jorim Jaggi | d53f092 | 2016-04-06 22:16:23 -0700 | [diff] [blame] | 4525 | |
Andrii Kulian | c2791664 | 2016-04-12 17:59:27 -0700 | [diff] [blame] | 4526 | // Dismiss docked stack. If task appeared to be in docked stack but is not resizable - |
| 4527 | // 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] | 4528 | |
Wale Ogunwale | 2b07da8 | 2017-11-08 14:52:40 -0800 | [diff] [blame] | 4529 | final ActivityStack dockedStack = |
| 4530 | task.getStack().getDisplay().getSplitScreenPrimaryStack(); |
Wale Ogunwale | 9dcf946 | 2017-09-19 15:13:01 -0700 | [diff] [blame] | 4531 | if (dockedStack != null) { |
Wale Ogunwale | a0f5b5e | 2017-10-11 09:37:23 -0700 | [diff] [blame] | 4532 | moveTasksToFullscreenStackLocked(dockedStack, actualStack == dockedStack); |
Wale Ogunwale | 9dcf946 | 2017-09-19 15:13:01 -0700 | [diff] [blame] | 4533 | } |
Wale Ogunwale | 2b07da8 | 2017-11-08 14:52:40 -0800 | [diff] [blame] | 4534 | return; |
| 4535 | } |
| 4536 | |
Wale Ogunwale | 30e441d | 2017-11-09 08:28:45 -0800 | [diff] [blame] | 4537 | final ActivityRecord topActivity = task.getTopActivity(); |
Wale Ogunwale | 2b07da8 | 2017-11-08 14:52:40 -0800 | [diff] [blame] | 4538 | if (topActivity != null && topActivity.isNonResizableOrForcedResizable() |
| 4539 | && !topActivity.noDisplay) { |
Andrii Kulian | 036e3ad | 2017-04-19 10:55:10 -0700 | [diff] [blame] | 4540 | final String packageName = topActivity.appInfo.packageName; |
| 4541 | final int reason = isSecondaryDisplayPreferred |
| 4542 | ? FORCED_RESIZEABLE_REASON_SECONDARY_DISPLAY |
| 4543 | : FORCED_RESIZEABLE_REASON_SPLIT_SCREEN; |
Yorke Lee | bd54c2a | 2016-10-25 13:49:23 -0700 | [diff] [blame] | 4544 | mService.mTaskChangeNotificationController.notifyActivityForcedResizable( |
Andrii Kulian | 036e3ad | 2017-04-19 10:55:10 -0700 | [diff] [blame] | 4545 | task.taskId, reason, packageName); |
Wale Ogunwale | b9b16a7 | 2016-01-27 12:24:44 -0800 | [diff] [blame] | 4546 | } |
Chong Zhang | b15758a | 2015-11-17 12:12:03 -0800 | [diff] [blame] | 4547 | } |
| 4548 | |
Jorim Jaggi | fe89d12 | 2015-12-22 16:28:44 +0100 | [diff] [blame] | 4549 | void activityRelaunchedLocked(IBinder token) { |
| 4550 | mWindowManager.notifyAppRelaunchingFinished(token); |
David Stevens | 9440dc8 | 2017-03-16 19:00:20 -0700 | [diff] [blame] | 4551 | final ActivityRecord r = ActivityRecord.isInStackLocked(token); |
| 4552 | if (r != null) { |
| 4553 | if (r.getStack().shouldSleepOrShutDownActivities()) { |
Wale Ogunwale | 3e99736 | 2016-09-06 10:37:56 -0700 | [diff] [blame] | 4554 | r.setSleeping(true, true); |
| 4555 | } |
| 4556 | } |
Jorim Jaggi | fe89d12 | 2015-12-22 16:28:44 +0100 | [diff] [blame] | 4557 | } |
| 4558 | |
| 4559 | void activityRelaunchingLocked(ActivityRecord r) { |
| 4560 | mWindowManager.notifyAppRelaunching(r.appToken); |
| 4561 | } |
| 4562 | |
Filip Gruszczynski | 77d9448 | 2015-12-11 13:59:52 -0800 | [diff] [blame] | 4563 | void logStackState() { |
| 4564 | mActivityMetricsLogger.logWindowState(); |
| 4565 | } |
| 4566 | |
Winson Chung | 5af42fc | 2017-03-24 17:11:33 -0700 | [diff] [blame] | 4567 | void scheduleUpdateMultiWindowMode(TaskRecord task) { |
Winson Chung | 8bca9e4 | 2017-04-16 15:59:43 -0700 | [diff] [blame] | 4568 | // If the stack is animating in a way where we will be forcing a multi-mode change at the |
| 4569 | // end, then ensure that we defer all in between multi-window mode changes |
| 4570 | if (task.getStack().deferScheduleMultiWindowModeChanged()) { |
| 4571 | return; |
| 4572 | } |
| 4573 | |
Wale Ogunwale | 22e2526 | 2016-02-01 10:32:02 -0800 | [diff] [blame] | 4574 | for (int i = task.mActivities.size() - 1; i >= 0; i--) { |
| 4575 | final ActivityRecord r = task.mActivities.get(i); |
| 4576 | if (r.app != null && r.app.thread != null) { |
| 4577 | mMultiWindowModeChangedActivities.add(r); |
| 4578 | } |
| 4579 | } |
| 4580 | |
| 4581 | if (!mHandler.hasMessages(REPORT_MULTI_WINDOW_MODE_CHANGED_MSG)) { |
| 4582 | mHandler.sendEmptyMessage(REPORT_MULTI_WINDOW_MODE_CHANGED_MSG); |
| 4583 | } |
| 4584 | } |
| 4585 | |
Winson Chung | 5af42fc | 2017-03-24 17:11:33 -0700 | [diff] [blame] | 4586 | void scheduleUpdatePictureInPictureModeIfNeeded(TaskRecord task, ActivityStack prevStack) { |
Andrii Kulian | 02b7a83 | 2016-10-06 23:11:56 -0700 | [diff] [blame] | 4587 | final ActivityStack stack = task.getStack(); |
Wale Ogunwale | 22e2526 | 2016-02-01 10:32:02 -0800 | [diff] [blame] | 4588 | if (prevStack == null || prevStack == stack |
Wale Ogunwale | 44f036f | 2017-09-29 05:09:09 -0700 | [diff] [blame] | 4589 | || (!prevStack.inPinnedWindowingMode() && !stack.inPinnedWindowingMode())) { |
Wale Ogunwale | 22e2526 | 2016-02-01 10:32:02 -0800 | [diff] [blame] | 4590 | return; |
| 4591 | } |
| 4592 | |
Bryce Lee | f3c6a47 | 2017-11-14 14:53:06 -0800 | [diff] [blame] | 4593 | scheduleUpdatePictureInPictureModeIfNeeded(task, stack.getOverrideBounds()); |
Winson Chung | 5af42fc | 2017-03-24 17:11:33 -0700 | [diff] [blame] | 4594 | } |
Wale Ogunwale | 22e2526 | 2016-02-01 10:32:02 -0800 | [diff] [blame] | 4595 | |
Winson Chung | ab76bbc | 2017-08-14 13:33:51 -0700 | [diff] [blame] | 4596 | void scheduleUpdatePictureInPictureModeIfNeeded(TaskRecord task, Rect targetStackBounds) { |
| 4597 | for (int i = task.mActivities.size() - 1; i >= 0; i--) { |
| 4598 | final ActivityRecord r = task.mActivities.get(i); |
| 4599 | if (r.app != null && r.app.thread != null) { |
| 4600 | mPipModeChangedActivities.add(r); |
Wale Ogunwale | eb76b76 | 2017-11-17 10:08:04 -0800 | [diff] [blame] | 4601 | // If we are scheduling pip change, then remove this activity from multi-window |
| 4602 | // change list as the processing of pip change will make sure multi-window changed |
| 4603 | // message is processed in the right order relative to pip changed. |
| 4604 | mMultiWindowModeChangedActivities.remove(r); |
Winson Chung | 5af42fc | 2017-03-24 17:11:33 -0700 | [diff] [blame] | 4605 | } |
Winson Chung | ab76bbc | 2017-08-14 13:33:51 -0700 | [diff] [blame] | 4606 | } |
| 4607 | mPipModeChangedTargetStackBounds = targetStackBounds; |
Winson Chung | 5af42fc | 2017-03-24 17:11:33 -0700 | [diff] [blame] | 4608 | |
Winson Chung | ab76bbc | 2017-08-14 13:33:51 -0700 | [diff] [blame] | 4609 | if (!mHandler.hasMessages(REPORT_PIP_MODE_CHANGED_MSG)) { |
| 4610 | mHandler.sendEmptyMessage(REPORT_PIP_MODE_CHANGED_MSG); |
| 4611 | } |
| 4612 | } |
| 4613 | |
| 4614 | void updatePictureInPictureMode(TaskRecord task, Rect targetStackBounds, boolean forceUpdate) { |
| 4615 | mHandler.removeMessages(REPORT_PIP_MODE_CHANGED_MSG); |
| 4616 | for (int i = task.mActivities.size() - 1; i >= 0; i--) { |
| 4617 | final ActivityRecord r = task.mActivities.get(i); |
| 4618 | if (r.app != null && r.app.thread != null) { |
| 4619 | r.updatePictureInPictureMode(targetStackBounds, forceUpdate); |
Winson Chung | 5af42fc | 2017-03-24 17:11:33 -0700 | [diff] [blame] | 4620 | } |
Wale Ogunwale | 22e2526 | 2016-02-01 10:32:02 -0800 | [diff] [blame] | 4621 | } |
| 4622 | } |
| 4623 | |
Tony Mak | 853304c | 2016-04-18 15:17:41 +0100 | [diff] [blame] | 4624 | void setDockedStackMinimized(boolean minimized) { |
| 4625 | mIsDockMinimized = minimized; |
Wale Ogunwale | 17696de | 2018-03-15 16:41:05 -0700 | [diff] [blame] | 4626 | if (mIsDockMinimized) { |
| 4627 | final ActivityStack current = getFocusedStack(); |
| 4628 | if (current.inSplitScreenPrimaryWindowingMode()) { |
| 4629 | // The primary split-screen stack can't be focused while it is minimize, so move |
| 4630 | // focus to something else. |
| 4631 | current.adjustFocusToNextFocusableStack("setDockedStackMinimized"); |
| 4632 | } |
| 4633 | } |
Tony Mak | 853304c | 2016-04-18 15:17:41 +0100 | [diff] [blame] | 4634 | } |
| 4635 | |
chaviw | 59b9885 | 2017-06-13 12:05:44 -0700 | [diff] [blame] | 4636 | void wakeUp(String reason) { |
| 4637 | mPowerManager.wakeUp(SystemClock.uptimeMillis(), "android.server.am:TURN_ON:" + reason); |
| 4638 | } |
| 4639 | |
| 4640 | /** |
| 4641 | * Begin deferring resume to avoid duplicate resumes in one pass. |
| 4642 | */ |
| 4643 | private void beginDeferResume() { |
| 4644 | mDeferResumeCount++; |
| 4645 | } |
| 4646 | |
| 4647 | /** |
| 4648 | * End deferring resume and determine if resume can be called. |
| 4649 | */ |
| 4650 | private void endDeferResume() { |
| 4651 | mDeferResumeCount--; |
| 4652 | } |
| 4653 | |
| 4654 | /** |
| 4655 | * @return True if resume can be called. |
| 4656 | */ |
| 4657 | private boolean readyToResume() { |
| 4658 | return mDeferResumeCount == 0; |
| 4659 | } |
| 4660 | |
Craig Mautner | ce5f3cb | 2013-04-22 08:58:54 -0700 | [diff] [blame] | 4661 | private final class ActivityStackSupervisorHandler extends Handler { |
Craig Mautner | f333327 | 2013-04-22 10:55:53 -0700 | [diff] [blame] | 4662 | |
Craig Mautner | ce5f3cb | 2013-04-22 08:58:54 -0700 | [diff] [blame] | 4663 | public ActivityStackSupervisorHandler(Looper looper) { |
| 4664 | super(looper); |
| 4665 | } |
| 4666 | |
Winson Chung | 4dabf23 | 2017-01-25 13:25:22 -0800 | [diff] [blame] | 4667 | void activityIdleInternal(ActivityRecord r, boolean processPausingActivities) { |
Craig Mautner | f333327 | 2013-04-22 10:55:53 -0700 | [diff] [blame] | 4668 | synchronized (mService) { |
Winson Chung | 4dabf23 | 2017-01-25 13:25:22 -0800 | [diff] [blame] | 4669 | activityIdleInternalLocked(r != null ? r.appToken : null, true /* fromTimeout */, |
| 4670 | processPausingActivities, null); |
Craig Mautner | f333327 | 2013-04-22 10:55:53 -0700 | [diff] [blame] | 4671 | } |
Craig Mautner | 7ea5bd4 | 2013-07-05 15:27:08 -0700 | [diff] [blame] | 4672 | } |
| 4673 | |
Craig Mautner | ce5f3cb | 2013-04-22 08:58:54 -0700 | [diff] [blame] | 4674 | @Override |
| 4675 | public void handleMessage(Message msg) { |
| 4676 | switch (msg.what) { |
Wale Ogunwale | 22e2526 | 2016-02-01 10:32:02 -0800 | [diff] [blame] | 4677 | case REPORT_MULTI_WINDOW_MODE_CHANGED_MSG: { |
| 4678 | synchronized (mService) { |
| 4679 | for (int i = mMultiWindowModeChangedActivities.size() - 1; i >= 0; i--) { |
| 4680 | final ActivityRecord r = mMultiWindowModeChangedActivities.remove(i); |
Winson Chung | 5af42fc | 2017-03-24 17:11:33 -0700 | [diff] [blame] | 4681 | r.updateMultiWindowMode(); |
Wale Ogunwale | 22e2526 | 2016-02-01 10:32:02 -0800 | [diff] [blame] | 4682 | } |
| 4683 | } |
| 4684 | } break; |
| 4685 | case REPORT_PIP_MODE_CHANGED_MSG: { |
| 4686 | synchronized (mService) { |
| 4687 | for (int i = mPipModeChangedActivities.size() - 1; i >= 0; i--) { |
| 4688 | final ActivityRecord r = mPipModeChangedActivities.remove(i); |
Winson Chung | ab76bbc | 2017-08-14 13:33:51 -0700 | [diff] [blame] | 4689 | r.updatePictureInPictureMode(mPipModeChangedTargetStackBounds, |
| 4690 | false /* forceUpdate */); |
Wale Ogunwale | 22e2526 | 2016-02-01 10:32:02 -0800 | [diff] [blame] | 4691 | } |
| 4692 | } |
| 4693 | } break; |
Craig Mautner | f333327 | 2013-04-22 10:55:53 -0700 | [diff] [blame] | 4694 | case IDLE_TIMEOUT_MSG: { |
Wale Ogunwale | 0fc365c | 2015-05-25 19:35:42 -0700 | [diff] [blame] | 4695 | if (DEBUG_IDLE) Slog.d(TAG_IDLE, |
| 4696 | "handleMessage: IDLE_TIMEOUT_MSG: r=" + msg.obj); |
Craig Mautner | f333327 | 2013-04-22 10:55:53 -0700 | [diff] [blame] | 4697 | // We don't at this point know if the activity is fullscreen, |
| 4698 | // so we need to be conservative and assume it isn't. |
Winson Chung | 4dabf23 | 2017-01-25 13:25:22 -0800 | [diff] [blame] | 4699 | activityIdleInternal((ActivityRecord) msg.obj, |
| 4700 | true /* processPausingActivities */); |
Craig Mautner | f333327 | 2013-04-22 10:55:53 -0700 | [diff] [blame] | 4701 | } break; |
| 4702 | case IDLE_NOW_MSG: { |
Wale Ogunwale | 0fc365c | 2015-05-25 19:35:42 -0700 | [diff] [blame] | 4703 | 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] | 4704 | activityIdleInternal((ActivityRecord) msg.obj, |
| 4705 | false /* processPausingActivities */); |
Craig Mautner | f333327 | 2013-04-22 10:55:53 -0700 | [diff] [blame] | 4706 | } break; |
Craig Mautner | 05d2903 | 2013-05-03 13:40:13 -0700 | [diff] [blame] | 4707 | case RESUME_TOP_ACTIVITY_MSG: { |
| 4708 | synchronized (mService) { |
Wale Ogunwale | d046a01 | 2015-12-24 13:05:59 -0800 | [diff] [blame] | 4709 | resumeFocusedStackTopActivityLocked(); |
Craig Mautner | 05d2903 | 2013-05-03 13:40:13 -0700 | [diff] [blame] | 4710 | } |
| 4711 | } break; |
Craig Mautner | 0eea92c | 2013-05-16 13:35:39 -0700 | [diff] [blame] | 4712 | case SLEEP_TIMEOUT_MSG: { |
| 4713 | synchronized (mService) { |
Fyodor Kupolov | 9b80b94 | 2016-06-16 16:29:05 -0700 | [diff] [blame] | 4714 | if (mService.isSleepingOrShuttingDownLocked()) { |
Craig Mautner | 0eea92c | 2013-05-16 13:35:39 -0700 | [diff] [blame] | 4715 | Slog.w(TAG, "Sleep timeout! Sleeping now."); |
David Stevens | 9440dc8 | 2017-03-16 19:00:20 -0700 | [diff] [blame] | 4716 | checkReadyForSleepLocked(false /* allowDelay */); |
Craig Mautner | 0eea92c | 2013-05-16 13:35:39 -0700 | [diff] [blame] | 4717 | } |
| 4718 | } |
| 4719 | } break; |
Craig Mautner | 7ea5bd4 | 2013-07-05 15:27:08 -0700 | [diff] [blame] | 4720 | case LAUNCH_TIMEOUT_MSG: { |
Craig Mautner | 7ea5bd4 | 2013-07-05 15:27:08 -0700 | [diff] [blame] | 4721 | synchronized (mService) { |
| 4722 | if (mLaunchingActivity.isHeld()) { |
| 4723 | Slog.w(TAG, "Launch timeout has expired, giving up wake lock!"); |
| 4724 | if (VALIDATE_WAKE_LOCK_CALLER |
| 4725 | && Binder.getCallingUid() != Process.myUid()) { |
| 4726 | throw new IllegalStateException("Calling must be system uid"); |
| 4727 | } |
| 4728 | mLaunchingActivity.release(); |
| 4729 | } |
| 4730 | } |
| 4731 | } break; |
Craig Mautner | 4a1cb22 | 2013-12-04 16:14:06 -0800 | [diff] [blame] | 4732 | case HANDLE_DISPLAY_ADDED: { |
Wale Ogunwale | f16a281 | 2015-04-01 11:23:15 -0700 | [diff] [blame] | 4733 | handleDisplayAdded(msg.arg1); |
Craig Mautner | 4a1cb22 | 2013-12-04 16:14:06 -0800 | [diff] [blame] | 4734 | } break; |
| 4735 | case HANDLE_DISPLAY_CHANGED: { |
Wale Ogunwale | f16a281 | 2015-04-01 11:23:15 -0700 | [diff] [blame] | 4736 | handleDisplayChanged(msg.arg1); |
Craig Mautner | 4a1cb22 | 2013-12-04 16:14:06 -0800 | [diff] [blame] | 4737 | } break; |
| 4738 | case HANDLE_DISPLAY_REMOVED: { |
Wale Ogunwale | f16a281 | 2015-04-01 11:23:15 -0700 | [diff] [blame] | 4739 | handleDisplayRemoved(msg.arg1); |
Craig Mautner | 4a1cb22 | 2013-12-04 16:14:06 -0800 | [diff] [blame] | 4740 | } break; |
Craig Mautner | bb74246 | 2014-07-07 15:28:55 -0700 | [diff] [blame] | 4741 | case LAUNCH_TASK_BEHIND_COMPLETE: { |
| 4742 | synchronized (mService) { |
Wale Ogunwale | 7d70117 | 2015-03-11 15:36:30 -0700 | [diff] [blame] | 4743 | ActivityRecord r = ActivityRecord.forTokenLocked((IBinder) msg.obj); |
Craig Mautner | bb74246 | 2014-07-07 15:28:55 -0700 | [diff] [blame] | 4744 | if (r != null) { |
| 4745 | handleLaunchTaskBehindCompleteLocked(r); |
| 4746 | } |
| 4747 | } |
| 4748 | } break; |
Chong Zhang | c806d90 | 2015-11-30 09:44:27 -0800 | [diff] [blame] | 4749 | |
Craig Mautner | ce5f3cb | 2013-04-22 08:58:54 -0700 | [diff] [blame] | 4750 | } |
| 4751 | } |
| 4752 | } |
Craig Mautner | ed6649f | 2013-12-02 14:08:25 -0800 | [diff] [blame] | 4753 | |
Filip Gruszczynski | caae14e | 2015-12-16 14:40:04 -0800 | [diff] [blame] | 4754 | ActivityStack findStackBehind(ActivityStack stack) { |
| 4755 | // 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] | 4756 | final ActivityDisplay display = mActivityDisplays.get(DEFAULT_DISPLAY); |
Filip Gruszczynski | caae14e | 2015-12-16 14:40:04 -0800 | [diff] [blame] | 4757 | if (display == null) { |
| 4758 | return null; |
| 4759 | } |
Wale Ogunwale | a0f5b5e | 2017-10-11 09:37:23 -0700 | [diff] [blame] | 4760 | for (int i = display.getChildCount() - 1; i >= 0; i--) { |
| 4761 | if (display.getChildAt(i) == stack && i > 0) { |
| 4762 | return display.getChildAt(i - 1); |
Filip Gruszczynski | caae14e | 2015-12-16 14:40:04 -0800 | [diff] [blame] | 4763 | } |
| 4764 | } |
| 4765 | throw new IllegalStateException("Failed to find a stack behind stack=" + stack |
Wale Ogunwale | a0f5b5e | 2017-10-11 09:37:23 -0700 | [diff] [blame] | 4766 | + " in=" + display); |
Filip Gruszczynski | caae14e | 2015-12-16 14:40:04 -0800 | [diff] [blame] | 4767 | } |
Jorim Jaggi | 0b46f3c | 2016-03-14 12:21:37 +0100 | [diff] [blame] | 4768 | |
Jorim Jaggi | c69bd22 | 2016-03-15 14:38:37 +0100 | [diff] [blame] | 4769 | /** |
| 4770 | * Puts a task into resizing mode during the next app transition. |
| 4771 | * |
Wale Ogunwale | e1fe7fa2 | 2016-12-15 18:27:00 -0800 | [diff] [blame] | 4772 | * @param task The task to put into resizing mode |
Jorim Jaggi | c69bd22 | 2016-03-15 14:38:37 +0100 | [diff] [blame] | 4773 | */ |
Bryce Lee | d3624e1 | 2017-11-30 08:51:45 -0800 | [diff] [blame] | 4774 | void setResizingDuringAnimation(TaskRecord task) { |
Wale Ogunwale | e1fe7fa2 | 2016-12-15 18:27:00 -0800 | [diff] [blame] | 4775 | mResizingTasksDuringAnimation.add(task.taskId); |
| 4776 | task.setTaskDockedResizing(true); |
Jorim Jaggi | c69bd22 | 2016-03-15 14:38:37 +0100 | [diff] [blame] | 4777 | } |
| 4778 | |
Jorim Jaggi | 4d8d32c | 2018-01-19 15:57:41 +0100 | [diff] [blame] | 4779 | int startActivityFromRecents(int callingPid, int callingUid, int taskId, |
| 4780 | SafeActivityOptions options) { |
Wale Ogunwale | dd2ae3d | 2018-02-15 13:58:46 -0800 | [diff] [blame] | 4781 | TaskRecord task = null; |
Jorim Jaggi | 0b46f3c | 2016-03-14 12:21:37 +0100 | [diff] [blame] | 4782 | final String callingPackage; |
| 4783 | final Intent intent; |
| 4784 | final int userId; |
Wale Ogunwale | 0568aed | 2017-09-08 13:29:37 -0700 | [diff] [blame] | 4785 | int activityType = ACTIVITY_TYPE_UNDEFINED; |
| 4786 | int windowingMode = WINDOWING_MODE_UNDEFINED; |
Jorim Jaggi | 4d8d32c | 2018-01-19 15:57:41 +0100 | [diff] [blame] | 4787 | final ActivityOptions activityOptions = options != null |
| 4788 | ? options.getOptions(this) |
| 4789 | : null; |
Wale Ogunwale | 0568aed | 2017-09-08 13:29:37 -0700 | [diff] [blame] | 4790 | if (activityOptions != null) { |
| 4791 | activityType = activityOptions.getLaunchActivityType(); |
| 4792 | windowingMode = activityOptions.getLaunchWindowingMode(); |
| 4793 | } |
| 4794 | if (activityType == ACTIVITY_TYPE_HOME || activityType == ACTIVITY_TYPE_RECENTS) { |
Wale Ogunwale | ab5de37 | 2017-10-18 06:46:31 -0700 | [diff] [blame] | 4795 | throw new IllegalArgumentException("startActivityFromRecents: Task " |
Matthew Ng | ae1ff4f | 2016-11-10 15:49:14 -0800 | [diff] [blame] | 4796 | + taskId + " can't be launch in the home/recents stack."); |
Jorim Jaggi | 0b46f3c | 2016-03-14 12:21:37 +0100 | [diff] [blame] | 4797 | } |
Jorim Jaggi | 3c800a4 | 2016-04-15 19:44:50 -0700 | [diff] [blame] | 4798 | |
Matthew Ng | 606dd80 | 2017-06-05 14:06:32 -0700 | [diff] [blame] | 4799 | mWindowManager.deferSurfaceLayout(); |
| 4800 | try { |
Wale Ogunwale | 0568aed | 2017-09-08 13:29:37 -0700 | [diff] [blame] | 4801 | if (windowingMode == WINDOWING_MODE_SPLIT_SCREEN_PRIMARY) { |
Matthew Ng | 606dd80 | 2017-06-05 14:06:32 -0700 | [diff] [blame] | 4802 | mWindowManager.setDockedStackCreateState( |
Matthew Ng | bf15587 | 2017-10-27 15:24:39 -0700 | [diff] [blame] | 4803 | activityOptions.getSplitScreenCreateMode(), null /* initialBounds */); |
Jorim Jaggi | 3c800a4 | 2016-04-15 19:44:50 -0700 | [diff] [blame] | 4804 | |
Matthew Ng | 606dd80 | 2017-06-05 14:06:32 -0700 | [diff] [blame] | 4805 | // Defer updating the stack in which recents is until the app transition is done, to |
| 4806 | // not run into issues where we still need to draw the task in recents but the |
| 4807 | // docked stack is already created. |
Winson Chung | c167427 | 2018-02-21 10:15:17 -0800 | [diff] [blame] | 4808 | deferUpdateRecentsHomeStackBounds(); |
Matthew Ng | 606dd80 | 2017-06-05 14:06:32 -0700 | [diff] [blame] | 4809 | mWindowManager.prepareAppTransition(TRANSIT_DOCK_TASK_FROM_RECENTS, false); |
Jorim Jaggi | 0b46f3c | 2016-03-14 12:21:37 +0100 | [diff] [blame] | 4810 | } |
Jorim Jaggi | 0b46f3c | 2016-03-14 12:21:37 +0100 | [diff] [blame] | 4811 | |
Matthew Ng | 606dd80 | 2017-06-05 14:06:32 -0700 | [diff] [blame] | 4812 | task = anyTaskForIdLocked(taskId, MATCH_TASK_IN_STACKS_OR_RECENT_TASKS_AND_RESTORE, |
Wale Ogunwale | ab5de37 | 2017-10-18 06:46:31 -0700 | [diff] [blame] | 4813 | activityOptions, ON_TOP); |
Matthew Ng | 606dd80 | 2017-06-05 14:06:32 -0700 | [diff] [blame] | 4814 | if (task == null) { |
Winson Chung | c167427 | 2018-02-21 10:15:17 -0800 | [diff] [blame] | 4815 | continueUpdateRecentsHomeStackBounds(); |
Matthew Ng | 606dd80 | 2017-06-05 14:06:32 -0700 | [diff] [blame] | 4816 | mWindowManager.executeAppTransition(); |
| 4817 | throw new IllegalArgumentException( |
Wale Ogunwale | ab5de37 | 2017-10-18 06:46:31 -0700 | [diff] [blame] | 4818 | "startActivityFromRecents: Task " + taskId + " not found."); |
Matthew Ng | 606dd80 | 2017-06-05 14:06:32 -0700 | [diff] [blame] | 4819 | } |
| 4820 | |
Wale Ogunwale | abc44d0 | 2017-11-08 08:58:03 -0800 | [diff] [blame] | 4821 | if (windowingMode != WINDOWING_MODE_SPLIT_SCREEN_PRIMARY) { |
| 4822 | // We always want to return to the home activity instead of the recents activity |
| 4823 | // from whatever is started from the recents activity, so move the home stack |
| 4824 | // forward. |
| 4825 | moveHomeStackToFront("startActivityFromRecents"); |
| 4826 | } |
Wale Ogunwale | 66e1685 | 2017-10-19 13:35:52 -0700 | [diff] [blame] | 4827 | |
Matthew Ng | 606dd80 | 2017-06-05 14:06:32 -0700 | [diff] [blame] | 4828 | // If the user must confirm credentials (e.g. when first launching a work app and the |
| 4829 | // Work Challenge is present) let startActivityInPackage handle the intercepting. |
| 4830 | if (!mService.mUserController.shouldConfirmCredentials(task.userId) |
| 4831 | && task.getRootActivity() != null) { |
Bryce Lee | 28d8042 | 2017-07-21 13:25:13 -0700 | [diff] [blame] | 4832 | final ActivityRecord targetActivity = task.getTopActivity(); |
| 4833 | |
Bryce Lee | d3624e1 | 2017-11-30 08:51:45 -0800 | [diff] [blame] | 4834 | sendPowerHintForLaunchStartIfNeeded(true /* forceSend */, targetActivity); |
Matthew Ng | 606dd80 | 2017-06-05 14:06:32 -0700 | [diff] [blame] | 4835 | mActivityMetricsLogger.notifyActivityLaunching(); |
Jorim Jaggi | 172e99f | 2017-10-20 14:33:18 +0200 | [diff] [blame] | 4836 | try { |
Jorim Jaggi | 4d8d32c | 2018-01-19 15:57:41 +0100 | [diff] [blame] | 4837 | mService.moveTaskToFrontLocked(task.taskId, 0, options, |
Jorim Jaggi | 172e99f | 2017-10-20 14:33:18 +0200 | [diff] [blame] | 4838 | true /* fromRecents */); |
| 4839 | } finally { |
| 4840 | mActivityMetricsLogger.notifyActivityLaunched(START_TASK_TO_FRONT, |
| 4841 | targetActivity); |
| 4842 | } |
Matthew Ng | 606dd80 | 2017-06-05 14:06:32 -0700 | [diff] [blame] | 4843 | |
Bryce Lee | d3624e1 | 2017-11-30 08:51:45 -0800 | [diff] [blame] | 4844 | mService.getActivityStartController().postStartActivityProcessingForLastStarter( |
| 4845 | task.getTopActivity(), ActivityManager.START_TASK_TO_FRONT, |
| 4846 | task.getStack()); |
Matthew Ng | 606dd80 | 2017-06-05 14:06:32 -0700 | [diff] [blame] | 4847 | return ActivityManager.START_TASK_TO_FRONT; |
| 4848 | } |
Matthew Ng | 606dd80 | 2017-06-05 14:06:32 -0700 | [diff] [blame] | 4849 | callingPackage = task.mCallingPackage; |
| 4850 | intent = task.intent; |
| 4851 | intent.addFlags(Intent.FLAG_ACTIVITY_LAUNCHED_FROM_HISTORY); |
| 4852 | userId = task.userId; |
Wale Ogunwale | dd2ae3d | 2018-02-15 13:58:46 -0800 | [diff] [blame] | 4853 | return mService.getActivityStartController().startActivityInPackage( |
Jorim Jaggi | 4d8d32c | 2018-01-19 15:57:41 +0100 | [diff] [blame] | 4854 | task.mCallingUid, callingPid, callingUid, callingPackage, intent, null, null, |
Makoto Onuki | c00ea71 | 2018-04-13 12:06:39 -0700 | [diff] [blame] | 4855 | null, 0, 0, options, userId, task, "startActivityFromRecents", |
Michal Karpinski | 3eab951 | 2018-07-20 15:32:00 +0100 | [diff] [blame] | 4856 | false /* validateIncomingUser */, null /* originatingPendingIntent */); |
Matthew Ng | 606dd80 | 2017-06-05 14:06:32 -0700 | [diff] [blame] | 4857 | } finally { |
Wale Ogunwale | dd2ae3d | 2018-02-15 13:58:46 -0800 | [diff] [blame] | 4858 | if (windowingMode == WINDOWING_MODE_SPLIT_SCREEN_PRIMARY && task != null) { |
| 4859 | // If we are launching the task in the docked stack, put it into resizing mode so |
| 4860 | // the window renders full-screen with the background filling the void. Also only |
| 4861 | // call this at the end to make sure that tasks exists on the window manager side. |
| 4862 | setResizingDuringAnimation(task); |
| 4863 | |
| 4864 | final ActivityDisplay display = task.getStack().getDisplay(); |
| 4865 | final ActivityStack topSecondaryStack = |
| 4866 | display.getTopStackInWindowingMode(WINDOWING_MODE_SPLIT_SCREEN_SECONDARY); |
| 4867 | if (topSecondaryStack.isActivityTypeHome()) { |
| 4868 | // If the home activity if the top split-screen secondary stack, then the |
| 4869 | // primary split-screen stack is in the minimized mode which means it can't |
| 4870 | // receive input keys, so we should move the focused app to the home app so that |
| 4871 | // window manager can correctly calculate the focus window that can receive |
| 4872 | // input keys. |
| 4873 | moveHomeStackToFront("startActivityFromRecents: homeVisibleInSplitScreen"); |
Winson Chung | c167427 | 2018-02-21 10:15:17 -0800 | [diff] [blame] | 4874 | |
| 4875 | // Immediately update the minimized docked stack mode, the upcoming animation |
| 4876 | // for the docked activity (WMS.overridePendingAppTransitionMultiThumbFuture) |
| 4877 | // will do the animation to the target bounds |
| 4878 | mWindowManager.checkSplitScreenMinimizedChanged(false /* animate */); |
Wale Ogunwale | dd2ae3d | 2018-02-15 13:58:46 -0800 | [diff] [blame] | 4879 | } |
| 4880 | } |
Matthew Ng | 606dd80 | 2017-06-05 14:06:32 -0700 | [diff] [blame] | 4881 | mWindowManager.continueSurfaceLayout(); |
Jorim Jaggi | 0b46f3c | 2016-03-14 12:21:37 +0100 | [diff] [blame] | 4882 | } |
Jorim Jaggi | 0b46f3c | 2016-03-14 12:21:37 +0100 | [diff] [blame] | 4883 | } |
Amith Yamasani | e8222e5 | 2016-04-08 15:28:47 -0700 | [diff] [blame] | 4884 | |
| 4885 | /** |
| 4886 | * @return a list of activities which are the top ones in each visible stack. The first |
| 4887 | * entry will be the focused activity. |
| 4888 | */ |
Andrii Kulian | 0864bbb | 2017-02-16 15:45:58 -0800 | [diff] [blame] | 4889 | List<IBinder> getTopVisibleActivities() { |
| 4890 | final ArrayList<IBinder> topActivityTokens = new ArrayList<>(); |
| 4891 | // Traverse all displays. |
Robert Carr | 22374c0 | 2017-02-21 13:01:47 -0800 | [diff] [blame] | 4892 | for (int i = mActivityDisplays.size() - 1; i >= 0; i--) { |
Andrii Kulian | 0864bbb | 2017-02-16 15:45:58 -0800 | [diff] [blame] | 4893 | final ActivityDisplay display = mActivityDisplays.valueAt(i); |
| 4894 | // Traverse all stacks on a display. |
Wale Ogunwale | a0f5b5e | 2017-10-11 09:37:23 -0700 | [diff] [blame] | 4895 | for (int j = display.getChildCount() - 1; j >= 0; --j) { |
| 4896 | final ActivityStack stack = display.getChildAt(j); |
Andrii Kulian | 0864bbb | 2017-02-16 15:45:58 -0800 | [diff] [blame] | 4897 | // 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] | 4898 | if (stack.shouldBeVisible(null /* starting */)) { |
Wale Ogunwale | 30e441d | 2017-11-09 08:28:45 -0800 | [diff] [blame] | 4899 | final ActivityRecord top = stack.getTopActivity(); |
Andrii Kulian | 0864bbb | 2017-02-16 15:45:58 -0800 | [diff] [blame] | 4900 | if (top != null) { |
| 4901 | if (stack == mFocusedStack) { |
| 4902 | topActivityTokens.add(0, top.appToken); |
| 4903 | } else { |
| 4904 | topActivityTokens.add(top.appToken); |
| 4905 | } |
Amith Yamasani | e8222e5 | 2016-04-08 15:28:47 -0700 | [diff] [blame] | 4906 | } |
| 4907 | } |
| 4908 | } |
| 4909 | } |
| 4910 | return topActivityTokens; |
| 4911 | } |
Bryce Lee | 4a19438 | 2017-04-04 14:32:48 -0700 | [diff] [blame] | 4912 | |
| 4913 | /** |
| 4914 | * Internal container to store a match qualifier alongside a WaitResult. |
| 4915 | */ |
| 4916 | static class WaitInfo { |
| 4917 | private final ComponentName mTargetComponent; |
| 4918 | private final WaitResult mResult; |
| 4919 | |
| 4920 | public WaitInfo(ComponentName targetComponent, WaitResult result) { |
| 4921 | this.mTargetComponent = targetComponent; |
| 4922 | this.mResult = result; |
| 4923 | } |
| 4924 | |
Wale Ogunwale | 3270f17 | 2017-04-26 07:29:42 -0700 | [diff] [blame] | 4925 | public boolean matches(ComponentName targetComponent) { |
| 4926 | return mTargetComponent == null || mTargetComponent.equals(targetComponent); |
Bryce Lee | 4a19438 | 2017-04-04 14:32:48 -0700 | [diff] [blame] | 4927 | } |
| 4928 | |
| 4929 | public WaitResult getResult() { |
| 4930 | return mResult; |
| 4931 | } |
| 4932 | |
| 4933 | public ComponentName getComponent() { |
| 4934 | return mTargetComponent; |
| 4935 | } |
| 4936 | |
| 4937 | public void dump(PrintWriter pw, String prefix) { |
| 4938 | pw.println(prefix + "WaitInfo:"); |
| 4939 | pw.println(prefix + " mTargetComponent=" + mTargetComponent); |
| 4940 | pw.println(prefix + " mResult="); |
| 4941 | mResult.dump(pw, prefix); |
| 4942 | } |
| 4943 | } |
David Stevens | 9440dc8 | 2017-03-16 19:00:20 -0700 | [diff] [blame] | 4944 | |
| 4945 | private final class SleepTokenImpl extends SleepToken { |
| 4946 | private final String mTag; |
| 4947 | private final long mAcquireTime; |
| 4948 | private final int mDisplayId; |
| 4949 | |
| 4950 | public SleepTokenImpl(String tag, int displayId) { |
| 4951 | mTag = tag; |
| 4952 | mDisplayId = displayId; |
| 4953 | mAcquireTime = SystemClock.uptimeMillis(); |
| 4954 | } |
| 4955 | |
| 4956 | @Override |
| 4957 | public void release() { |
| 4958 | synchronized (mService) { |
| 4959 | removeSleepTokenLocked(this); |
| 4960 | } |
| 4961 | } |
| 4962 | |
| 4963 | @Override |
| 4964 | public String toString() { |
| 4965 | return "{\"" + mTag + "\", display " + mDisplayId |
| 4966 | + ", acquire at " + TimeUtils.formatUptime(mAcquireTime) + "}"; |
| 4967 | } |
| 4968 | } |
| 4969 | |
Craig Mautner | 2708430 | 2013-03-25 08:05:25 -0700 | [diff] [blame] | 4970 | } |