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; |
Vishnu Nair | cf23504 | 2018-11-02 13:27:00 -0700 | [diff] [blame] | 30 | import static android.app.WaitResult.INVALID_DELAY; |
Wale Ogunwale | 6827856 | 2017-09-23 17:13:55 -0700 | [diff] [blame] | 31 | import static android.app.WindowConfiguration.ACTIVITY_TYPE_ASSISTANT; |
Wale Ogunwale | 6fbde9f | 2017-08-24 07:24:12 -0700 | [diff] [blame] | 32 | import static android.app.WindowConfiguration.ACTIVITY_TYPE_HOME; |
Wale Ogunwale | 0568aed | 2017-09-08 13:29:37 -0700 | [diff] [blame] | 33 | import static android.app.WindowConfiguration.ACTIVITY_TYPE_RECENTS; |
Wale Ogunwale | 6fbde9f | 2017-08-24 07:24:12 -0700 | [diff] [blame] | 34 | import static android.app.WindowConfiguration.ACTIVITY_TYPE_STANDARD; |
| 35 | import static android.app.WindowConfiguration.ACTIVITY_TYPE_UNDEFINED; |
Wale Ogunwale | 0568aed | 2017-09-08 13:29:37 -0700 | [diff] [blame] | 36 | import static android.app.WindowConfiguration.WINDOWING_MODE_FREEFORM; |
Wale Ogunwale | 926aade | 2017-08-29 11:24:37 -0700 | [diff] [blame] | 37 | import static android.app.WindowConfiguration.WINDOWING_MODE_FULLSCREEN; |
Wale Ogunwale | 44f036f | 2017-09-29 05:09:09 -0700 | [diff] [blame] | 38 | import static android.app.WindowConfiguration.WINDOWING_MODE_FULLSCREEN_OR_SPLIT_SCREEN_SECONDARY; |
Wale Ogunwale | 0568aed | 2017-09-08 13:29:37 -0700 | [diff] [blame] | 39 | import static android.app.WindowConfiguration.WINDOWING_MODE_PINNED; |
| 40 | import static android.app.WindowConfiguration.WINDOWING_MODE_SPLIT_SCREEN_PRIMARY; |
Wale Ogunwale | 926aade | 2017-08-29 11:24:37 -0700 | [diff] [blame] | 41 | import static android.app.WindowConfiguration.WINDOWING_MODE_SPLIT_SCREEN_SECONDARY; |
Wale Ogunwale | 0568aed | 2017-09-08 13:29:37 -0700 | [diff] [blame] | 42 | import static android.app.WindowConfiguration.WINDOWING_MODE_UNDEFINED; |
Wale Ogunwale | 44f036f | 2017-09-29 05:09:09 -0700 | [diff] [blame] | 43 | import static android.app.WindowConfiguration.activityTypeToString; |
| 44 | import static android.app.WindowConfiguration.windowingModeToString; |
Andrii Kulian | 3c9ad07 | 2017-08-01 11:45:22 -0700 | [diff] [blame] | 45 | import static android.content.pm.PackageManager.PERMISSION_DENIED; |
Jorim Jaggi | fe76234 | 2016-10-13 14:33:27 +0200 | [diff] [blame] | 46 | import static android.content.pm.PackageManager.PERMISSION_GRANTED; |
Adrian Roos | a6d6aab | 2018-04-19 18:58:22 +0200 | [diff] [blame] | 47 | import static android.graphics.Rect.copyOrNull; |
chaviw | 59b9885 | 2017-06-13 12:05:44 -0700 | [diff] [blame] | 48 | import static android.os.PowerManager.PARTIAL_WAKE_LOCK; |
Benjamin Franz | a83859f | 2017-07-03 16:34:14 +0100 | [diff] [blame] | 49 | import static android.os.Process.SYSTEM_UID; |
Jorim Jaggi | fe76234 | 2016-10-13 14:33:27 +0200 | [diff] [blame] | 50 | import static android.os.Trace.TRACE_TAG_ACTIVITY_MANAGER; |
| 51 | import static android.view.Display.DEFAULT_DISPLAY; |
Andrii Kulian | 16802aa | 2016-11-02 12:21:33 -0700 | [diff] [blame] | 52 | import static android.view.Display.INVALID_DISPLAY; |
Andrii Kulian | 1cba31c | 2017-06-28 09:42:48 -0700 | [diff] [blame] | 53 | import static android.view.Display.TYPE_VIRTUAL; |
Winson Chung | 1dbc811 | 2017-09-28 18:05:31 -0700 | [diff] [blame] | 54 | |
Winson Chung | 4790065 | 2017-04-06 18:44:25 -0700 | [diff] [blame] | 55 | 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] | 56 | import static com.android.server.am.ActivityManagerDebugConfig.DEBUG_ALL; |
Jorim Jaggi | fe76234 | 2016-10-13 14:33:27 +0200 | [diff] [blame] | 57 | import static com.android.server.am.ActivityManagerDebugConfig.DEBUG_FOCUS; |
| 58 | import static com.android.server.am.ActivityManagerDebugConfig.DEBUG_IDLE; |
Jorim Jaggi | fe76234 | 2016-10-13 14:33:27 +0200 | [diff] [blame] | 59 | import static com.android.server.am.ActivityManagerDebugConfig.DEBUG_PAUSE; |
| 60 | import static com.android.server.am.ActivityManagerDebugConfig.DEBUG_RECENTS; |
| 61 | import static com.android.server.am.ActivityManagerDebugConfig.DEBUG_RELEASE; |
| 62 | import static com.android.server.am.ActivityManagerDebugConfig.DEBUG_STACK; |
| 63 | import static com.android.server.am.ActivityManagerDebugConfig.DEBUG_STATES; |
| 64 | import static com.android.server.am.ActivityManagerDebugConfig.DEBUG_SWITCH; |
| 65 | import static com.android.server.am.ActivityManagerDebugConfig.DEBUG_TASKS; |
Jorim Jaggi | fe76234 | 2016-10-13 14:33:27 +0200 | [diff] [blame] | 66 | import static com.android.server.am.ActivityManagerDebugConfig.POSTFIX_FOCUS; |
| 67 | import static com.android.server.am.ActivityManagerDebugConfig.POSTFIX_IDLE; |
Jorim Jaggi | fe76234 | 2016-10-13 14:33:27 +0200 | [diff] [blame] | 68 | import static com.android.server.am.ActivityManagerDebugConfig.POSTFIX_PAUSE; |
| 69 | import static com.android.server.am.ActivityManagerDebugConfig.POSTFIX_RECENTS; |
| 70 | import static com.android.server.am.ActivityManagerDebugConfig.POSTFIX_RELEASE; |
| 71 | import static com.android.server.am.ActivityManagerDebugConfig.POSTFIX_STACK; |
| 72 | import static com.android.server.am.ActivityManagerDebugConfig.POSTFIX_STATES; |
| 73 | import static com.android.server.am.ActivityManagerDebugConfig.POSTFIX_SWITCH; |
| 74 | import static com.android.server.am.ActivityManagerDebugConfig.POSTFIX_TASKS; |
Jorim Jaggi | fe76234 | 2016-10-13 14:33:27 +0200 | [diff] [blame] | 75 | import static com.android.server.am.ActivityManagerDebugConfig.TAG_AM; |
| 76 | import static com.android.server.am.ActivityManagerDebugConfig.TAG_WITH_CLASS_NAME; |
| 77 | import static com.android.server.am.ActivityManagerService.ANIMATE; |
| 78 | import static com.android.server.am.ActivityManagerService.FIRST_SUPERVISOR_STACK_MSG; |
Jorim Jaggi | fe76234 | 2016-10-13 14:33:27 +0200 | [diff] [blame] | 79 | import static com.android.server.am.ActivityStack.ActivityState.DESTROYED; |
| 80 | import static com.android.server.am.ActivityStack.ActivityState.DESTROYING; |
| 81 | import static com.android.server.am.ActivityStack.ActivityState.INITIALIZING; |
| 82 | import static com.android.server.am.ActivityStack.ActivityState.PAUSED; |
| 83 | import static com.android.server.am.ActivityStack.ActivityState.PAUSING; |
| 84 | import static com.android.server.am.ActivityStack.ActivityState.RESUMED; |
| 85 | import static com.android.server.am.ActivityStack.ActivityState.STOPPED; |
| 86 | import static com.android.server.am.ActivityStack.ActivityState.STOPPING; |
| 87 | import static com.android.server.am.ActivityStack.REMOVE_TASK_MODE_MOVING; |
Wale Ogunwale | 0568aed | 2017-09-08 13:29:37 -0700 | [diff] [blame] | 88 | import static com.android.server.am.TaskRecord.INVALID_TASK_ID; |
Jorim Jaggi | fe76234 | 2016-10-13 14:33:27 +0200 | [diff] [blame] | 89 | import static com.android.server.am.TaskRecord.LOCK_TASK_AUTH_LAUNCHABLE; |
| 90 | import static com.android.server.am.TaskRecord.LOCK_TASK_AUTH_LAUNCHABLE_PRIV; |
Charles He | ff9b4dff | 2017-09-22 10:18:37 +0100 | [diff] [blame] | 91 | import static com.android.server.am.TaskRecord.LOCK_TASK_AUTH_WHITELISTED; |
Winson Chung | 7466610 | 2017-02-22 17:49:24 -0800 | [diff] [blame] | 92 | import static com.android.server.am.TaskRecord.REPARENT_KEEP_STACK_AT_FRONT; |
| 93 | import static com.android.server.am.TaskRecord.REPARENT_LEAVE_STACK_IN_PLACE; |
| 94 | import static com.android.server.am.TaskRecord.REPARENT_MOVE_STACK_TO_FRONT; |
Yi Jin | 6c6e9ca | 2018-03-20 16:53:35 -0700 | [diff] [blame] | 95 | import static com.android.server.am.ActivityStackSupervisorProto.CONFIGURATION_CONTAINER; |
| 96 | import static com.android.server.am.ActivityStackSupervisorProto.DISPLAYS; |
| 97 | import static com.android.server.am.ActivityStackSupervisorProto.FOCUSED_STACK_ID; |
| 98 | import static com.android.server.am.ActivityStackSupervisorProto.IS_HOME_RECENTS_COMPONENT; |
| 99 | import static com.android.server.am.ActivityStackSupervisorProto.KEYGUARD_CONTROLLER; |
| 100 | import static com.android.server.am.ActivityStackSupervisorProto.RESUMED_ACTIVITY; |
Jorim Jaggi | f84e2f6 | 2018-01-16 14:17:59 +0100 | [diff] [blame] | 101 | import static android.view.WindowManager.TRANSIT_DOCK_TASK_FROM_RECENTS; |
Winson Chung | 1dbc811 | 2017-09-28 18:05:31 -0700 | [diff] [blame] | 102 | |
Wale Ogunwale | e1fe7fa2 | 2016-12-15 18:27:00 -0800 | [diff] [blame] | 103 | import static java.lang.Integer.MAX_VALUE; |
Jorim Jaggi | fe76234 | 2016-10-13 14:33:27 +0200 | [diff] [blame] | 104 | |
Svetoslav | 7008b51 | 2015-06-24 18:47:07 -0700 | [diff] [blame] | 105 | import android.Manifest; |
Winson Chung | 7900bee | 2017-03-10 08:59:25 -0800 | [diff] [blame] | 106 | import android.annotation.IntDef; |
Andrii Kulian | 16802aa | 2016-11-02 12:21:33 -0700 | [diff] [blame] | 107 | import android.annotation.NonNull; |
Wale Ogunwale | 0568aed | 2017-09-08 13:29:37 -0700 | [diff] [blame] | 108 | import android.annotation.Nullable; |
Tony Mak | 853304c | 2016-04-18 15:17:41 +0100 | [diff] [blame] | 109 | import android.annotation.UserIdInt; |
Craig Mautner | 2420ead | 2013-04-01 17:13:20 -0700 | [diff] [blame] | 110 | import android.app.Activity; |
Craig Mautner | 23ac33b | 2013-04-01 16:26:35 -0700 | [diff] [blame] | 111 | import android.app.ActivityManager; |
Filip Gruszczynski | 80e29f1 | 2015-12-14 14:58:30 -0800 | [diff] [blame] | 112 | import android.app.ActivityManager.RunningTaskInfo; |
Craig Mautner | ed6649f | 2013-12-02 14:08:25 -0800 | [diff] [blame] | 113 | import android.app.ActivityManager.StackInfo; |
David Stevens | 9440dc8 | 2017-03-16 19:00:20 -0700 | [diff] [blame] | 114 | import android.app.ActivityManagerInternal.SleepToken; |
Craig Mautner | 23ac33b | 2013-04-01 16:26:35 -0700 | [diff] [blame] | 115 | import android.app.ActivityOptions; |
Svetoslav | 7008b51 | 2015-06-24 18:47:07 -0700 | [diff] [blame] | 116 | import android.app.AppOpsManager; |
Jeff Hao | 1b012d3 | 2014-08-20 10:35:34 -0700 | [diff] [blame] | 117 | import android.app.ProfilerInfo; |
Craig Mautner | 2420ead | 2013-04-01 17:13:20 -0700 | [diff] [blame] | 118 | import android.app.ResultInfo; |
Sudheer Shanka | fc46e9b | 2016-10-21 17:55:27 -0700 | [diff] [blame] | 119 | import android.app.WaitResult; |
Winson Chung | 61c9e5a | 2017-10-11 10:39:32 -0700 | [diff] [blame] | 120 | import android.app.WindowConfiguration.ActivityType; |
| 121 | import android.app.WindowConfiguration.WindowingMode; |
Andrii Kulian | 88e05cb | 2017-12-05 17:21:10 -0800 | [diff] [blame] | 122 | import android.app.servertransaction.ActivityLifecycleItem; |
| 123 | import android.app.servertransaction.ClientTransaction; |
Andrii Kulian | 446e824 | 2017-10-26 15:17:29 -0700 | [diff] [blame] | 124 | import android.app.servertransaction.LaunchActivityItem; |
Andrii Kulian | 88e05cb | 2017-12-05 17:21:10 -0800 | [diff] [blame] | 125 | import android.app.servertransaction.PauseActivityItem; |
| 126 | import android.app.servertransaction.ResumeActivityItem; |
Craig Mautner | 23ac33b | 2013-04-01 16:26:35 -0700 | [diff] [blame] | 127 | import android.content.ComponentName; |
Craig Mautner | 2219a1b | 2013-03-25 09:44:30 -0700 | [diff] [blame] | 128 | import android.content.Context; |
| 129 | import android.content.Intent; |
| 130 | import android.content.pm.ActivityInfo; |
Craig Mautner | 23ac33b | 2013-04-01 16:26:35 -0700 | [diff] [blame] | 131 | import android.content.pm.ApplicationInfo; |
Svetoslav | 7008b51 | 2015-06-24 18:47:07 -0700 | [diff] [blame] | 132 | import android.content.pm.PackageInfo; |
Craig Mautner | 23ac33b | 2013-04-01 16:26:35 -0700 | [diff] [blame] | 133 | import android.content.pm.PackageManager; |
| 134 | import android.content.pm.ResolveInfo; |
Clara Bayarri | f7fea16 | 2015-10-22 16:09:52 +0100 | [diff] [blame] | 135 | import android.content.pm.UserInfo; |
Craig Mautner | 23ac33b | 2013-04-01 16:26:35 -0700 | [diff] [blame] | 136 | import android.content.res.Configuration; |
Wale Ogunwale | 60454db | 2015-01-23 16:05:07 -0800 | [diff] [blame] | 137 | import android.graphics.Rect; |
Craig Mautner | 4a1cb22 | 2013-12-04 16:14:06 -0800 | [diff] [blame] | 138 | import android.hardware.display.DisplayManager; |
| 139 | import android.hardware.display.DisplayManager.DisplayListener; |
Andrii Kulian | fb1bf69 | 2017-01-17 11:17:34 -0800 | [diff] [blame] | 140 | import android.hardware.display.DisplayManagerInternal; |
Bryce Lee | d3624e1 | 2017-11-30 08:51:45 -0800 | [diff] [blame] | 141 | import android.hardware.power.V1_0.PowerHint; |
Craig Mautner | 23ac33b | 2013-04-01 16:26:35 -0700 | [diff] [blame] | 142 | import android.os.Binder; |
Jorim Jaggi | 0b46f3c | 2016-03-14 12:21:37 +0100 | [diff] [blame] | 143 | import android.os.Bundle; |
Craig Mautner | b59dcfd | 2013-05-06 13:12:58 -0700 | [diff] [blame] | 144 | import android.os.Debug; |
Craig Mautner | ce5f3cb | 2013-04-22 08:58:54 -0700 | [diff] [blame] | 145 | import android.os.Handler; |
Craig Mautner | 23ac33b | 2013-04-01 16:26:35 -0700 | [diff] [blame] | 146 | import android.os.IBinder; |
Craig Mautner | 2219a1b | 2013-03-25 09:44:30 -0700 | [diff] [blame] | 147 | import android.os.Looper; |
Craig Mautner | 2420ead | 2013-04-01 17:13:20 -0700 | [diff] [blame] | 148 | import android.os.Message; |
Craig Mautner | 0eea92c | 2013-05-16 13:35:39 -0700 | [diff] [blame] | 149 | import android.os.PowerManager; |
Craig Mautner | 7ea5bd4 | 2013-07-05 15:27:08 -0700 | [diff] [blame] | 150 | import android.os.Process; |
Craig Mautner | 8d341ef | 2013-03-26 09:03:27 -0700 | [diff] [blame] | 151 | import android.os.RemoteException; |
Craig Mautner | 23ac33b | 2013-04-01 16:26:35 -0700 | [diff] [blame] | 152 | import android.os.SystemClock; |
Wale Ogunwale | cad05a0 | 2015-09-25 10:41:44 -0700 | [diff] [blame] | 153 | import android.os.Trace; |
Craig Mautner | 6170f73 | 2013-04-02 13:05:23 -0700 | [diff] [blame] | 154 | import android.os.UserHandle; |
Clara Bayarri | f7fea16 | 2015-10-22 16:09:52 +0100 | [diff] [blame] | 155 | import android.os.UserManager; |
Dianne Hackborn | 3d07c94 | 2015-03-13 18:02:54 -0700 | [diff] [blame] | 156 | import android.os.WorkSource; |
Svetoslav | 7008b51 | 2015-06-24 18:47:07 -0700 | [diff] [blame] | 157 | import android.provider.MediaStore; |
Dianne Hackborn | 91097de | 2014-04-04 18:02:06 -0700 | [diff] [blame] | 158 | import android.service.voice.IVoiceInteractionSession; |
Svetoslav | 7008b51 | 2015-06-24 18:47:07 -0700 | [diff] [blame] | 159 | import android.util.ArrayMap; |
Dianne Hackborn | 89ad456 | 2014-08-24 16:45:38 -0700 | [diff] [blame] | 160 | import android.util.ArraySet; |
Craig Mautner | 2420ead | 2013-04-01 17:13:20 -0700 | [diff] [blame] | 161 | import android.util.EventLog; |
Andrii Kulian | fb1bf69 | 2017-01-17 11:17:34 -0800 | [diff] [blame] | 162 | import android.util.IntArray; |
Wale Ogunwale | e610d3d | 2017-04-25 10:23:48 -0700 | [diff] [blame] | 163 | import android.util.MergedConfiguration; |
Craig Mautner | 8d341ef | 2013-03-26 09:03:27 -0700 | [diff] [blame] | 164 | import android.util.Slog; |
Craig Mautner | 4a1cb22 | 2013-12-04 16:14:06 -0800 | [diff] [blame] | 165 | import android.util.SparseArray; |
Craig Mautner | 4a1cb22 | 2013-12-04 16:14:06 -0800 | [diff] [blame] | 166 | import android.util.SparseIntArray; |
David Stevens | 9440dc8 | 2017-03-16 19:00:20 -0700 | [diff] [blame] | 167 | import android.util.TimeUtils; |
Steven Timotius | 4346f0a | 2017-09-12 11:07:21 -0700 | [diff] [blame] | 168 | import android.util.proto.ProtoOutputStream; |
Craig Mautner | ed6649f | 2013-12-02 14:08:25 -0800 | [diff] [blame] | 169 | import android.view.Display; |
Chong Zhang | b15758a | 2015-11-17 12:12:03 -0800 | [diff] [blame] | 170 | |
Andreas Gampe | a36dc62 | 2018-02-05 17:19:22 -0800 | [diff] [blame] | 171 | import com.android.internal.annotations.GuardedBy; |
Andrii Kulian | 94e82d9b0 | 2017-07-13 15:33:06 -0700 | [diff] [blame] | 172 | import com.android.internal.annotations.VisibleForTesting; |
Dianne Hackborn | 85d558c | 2014-11-04 10:31:54 -0800 | [diff] [blame] | 173 | import com.android.internal.content.ReferrerIntent; |
Chenjie Yu | 52cacc6 | 2017-12-08 18:11:45 -0800 | [diff] [blame] | 174 | import com.android.internal.os.logging.MetricsLoggerWrapper; |
Dianne Hackborn | cbfd23e | 2013-06-11 14:26:53 -0700 | [diff] [blame] | 175 | import com.android.internal.os.TransferPipe; |
Svetoslav | 7008b51 | 2015-06-24 18:47:07 -0700 | [diff] [blame] | 176 | import com.android.internal.util.ArrayUtils; |
Jeff Brown | ca9bc70 | 2014-02-11 14:32:56 -0800 | [diff] [blame] | 177 | import com.android.server.LocalServices; |
Craig Mautner | 2420ead | 2013-04-01 17:13:20 -0700 | [diff] [blame] | 178 | import com.android.server.am.ActivityStack.ActivityState; |
Wale Ogunwale | 98d6231 | 2017-07-12 09:24:56 -0700 | [diff] [blame] | 179 | import com.android.server.wm.ConfigurationContainer; |
Winson Chung | 19953ca | 2017-04-11 11:19:23 -0700 | [diff] [blame] | 180 | import com.android.server.wm.PinnedStackWindowController; |
Craig Mautner | ce5f3cb | 2013-04-22 08:58:54 -0700 | [diff] [blame] | 181 | import com.android.server.wm.WindowManagerService; |
Craig Mautner | 23ac33b | 2013-04-01 16:26:35 -0700 | [diff] [blame] | 182 | |
Craig Mautner | 8d341ef | 2013-03-26 09:03:27 -0700 | [diff] [blame] | 183 | import java.io.FileDescriptor; |
| 184 | import java.io.IOException; |
Craig Mautner | 2708430 | 2013-03-25 08:05:25 -0700 | [diff] [blame] | 185 | import java.io.PrintWriter; |
Winson Chung | 7900bee | 2017-03-10 08:59:25 -0800 | [diff] [blame] | 186 | import java.lang.annotation.Retention; |
| 187 | import java.lang.annotation.RetentionPolicy; |
Craig Mautner | 2219a1b | 2013-03-25 09:44:30 -0700 | [diff] [blame] | 188 | import java.util.ArrayList; |
David Stevens | 9440dc8 | 2017-03-16 19:00:20 -0700 | [diff] [blame] | 189 | import java.util.Iterator; |
Craig Mautner | 8d341ef | 2013-03-26 09:03:27 -0700 | [diff] [blame] | 190 | import java.util.List; |
Wale Ogunwale | 540e123 | 2015-05-01 15:35:39 -0700 | [diff] [blame] | 191 | import java.util.Set; |
Craig Mautner | 2708430 | 2013-03-25 08:05:25 -0700 | [diff] [blame] | 192 | |
Winson Chung | 1dbc811 | 2017-09-28 18:05:31 -0700 | [diff] [blame] | 193 | public class ActivityStackSupervisor extends ConfigurationContainer implements DisplayListener, |
| 194 | RecentTasks.Callbacks { |
Wale Ogunwale | e23149f | 2015-03-06 15:39:44 -0800 | [diff] [blame] | 195 | private static final String TAG = TAG_WITH_CLASS_NAME ? "ActivityStackSupervisor" : TAG_AM; |
Chong Zhang | 6cda19c | 2016-06-14 19:07:56 -0700 | [diff] [blame] | 196 | private static final String TAG_FOCUS = TAG + POSTFIX_FOCUS; |
Wale Ogunwale | 0fc365c | 2015-05-25 19:35:42 -0700 | [diff] [blame] | 197 | private static final String TAG_IDLE = TAG + POSTFIX_IDLE; |
Wale Ogunwale | ee006da | 2015-03-30 14:49:25 -0700 | [diff] [blame] | 198 | private static final String TAG_PAUSE = TAG + POSTFIX_PAUSE; |
Wale Ogunwale | ee006da | 2015-03-30 14:49:25 -0700 | [diff] [blame] | 199 | private static final String TAG_RECENTS = TAG + POSTFIX_RECENTS; |
Wale Ogunwale | 0fc365c | 2015-05-25 19:35:42 -0700 | [diff] [blame] | 200 | private static final String TAG_RELEASE = TAG + POSTFIX_RELEASE; |
Wale Ogunwale | ee006da | 2015-03-30 14:49:25 -0700 | [diff] [blame] | 201 | private static final String TAG_STACK = TAG + POSTFIX_STACK; |
Wale Ogunwale | 0fc365c | 2015-05-25 19:35:42 -0700 | [diff] [blame] | 202 | private static final String TAG_STATES = TAG + POSTFIX_STATES; |
Wale Ogunwale | ee006da | 2015-03-30 14:49:25 -0700 | [diff] [blame] | 203 | private static final String TAG_SWITCH = TAG + POSTFIX_SWITCH; |
Filip Gruszczynski | 07a0e49 | 2015-12-17 14:16:38 -0800 | [diff] [blame] | 204 | static final String TAG_TASKS = TAG + POSTFIX_TASKS; |
Wale Ogunwale | e23149f | 2015-03-06 15:39:44 -0800 | [diff] [blame] | 205 | |
Craig Mautner | f333327 | 2013-04-22 10:55:53 -0700 | [diff] [blame] | 206 | /** 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] | 207 | static final int IDLE_TIMEOUT = 10 * 1000; |
Craig Mautner | f333327 | 2013-04-22 10:55:53 -0700 | [diff] [blame] | 208 | |
Craig Mautner | 0eea92c | 2013-05-16 13:35:39 -0700 | [diff] [blame] | 209 | /** How long we can hold the sleep wake lock before giving up. */ |
Wale Ogunwale | 0fc365c | 2015-05-25 19:35:42 -0700 | [diff] [blame] | 210 | static final int SLEEP_TIMEOUT = 5 * 1000; |
Craig Mautner | 0eea92c | 2013-05-16 13:35:39 -0700 | [diff] [blame] | 211 | |
Craig Mautner | 7ea5bd4 | 2013-07-05 15:27:08 -0700 | [diff] [blame] | 212 | // How long we can hold the launch wake lock before giving up. |
Wale Ogunwale | 0fc365c | 2015-05-25 19:35:42 -0700 | [diff] [blame] | 213 | static final int LAUNCH_TIMEOUT = 10 * 1000; |
Craig Mautner | 7ea5bd4 | 2013-07-05 15:27:08 -0700 | [diff] [blame] | 214 | |
Craig Mautner | 05d2903 | 2013-05-03 13:40:13 -0700 | [diff] [blame] | 215 | static final int IDLE_TIMEOUT_MSG = FIRST_SUPERVISOR_STACK_MSG; |
| 216 | static final int IDLE_NOW_MSG = FIRST_SUPERVISOR_STACK_MSG + 1; |
| 217 | static final int RESUME_TOP_ACTIVITY_MSG = FIRST_SUPERVISOR_STACK_MSG + 2; |
Craig Mautner | 0eea92c | 2013-05-16 13:35:39 -0700 | [diff] [blame] | 218 | static final int SLEEP_TIMEOUT_MSG = FIRST_SUPERVISOR_STACK_MSG + 3; |
Craig Mautner | 7ea5bd4 | 2013-07-05 15:27:08 -0700 | [diff] [blame] | 219 | static final int LAUNCH_TIMEOUT_MSG = FIRST_SUPERVISOR_STACK_MSG + 4; |
Craig Mautner | 4a1cb22 | 2013-12-04 16:14:06 -0800 | [diff] [blame] | 220 | static final int HANDLE_DISPLAY_ADDED = FIRST_SUPERVISOR_STACK_MSG + 5; |
| 221 | static final int HANDLE_DISPLAY_CHANGED = FIRST_SUPERVISOR_STACK_MSG + 6; |
| 222 | static final int HANDLE_DISPLAY_REMOVED = FIRST_SUPERVISOR_STACK_MSG + 7; |
Wale Ogunwale | 73eba74 | 2015-04-07 14:23:14 -0700 | [diff] [blame] | 223 | static final int LAUNCH_TASK_BEHIND_COMPLETE = FIRST_SUPERVISOR_STACK_MSG + 12; |
Wale Ogunwale | 22e2526 | 2016-02-01 10:32:02 -0800 | [diff] [blame] | 224 | static final int REPORT_MULTI_WINDOW_MODE_CHANGED_MSG = FIRST_SUPERVISOR_STACK_MSG + 14; |
| 225 | 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] | 226 | |
Wale Ogunwale | 040b470 | 2015-08-06 18:10:50 -0700 | [diff] [blame] | 227 | private static final String VIRTUAL_DISPLAY_BASE_NAME = "ActivityViewVirtualDisplay"; |
Craig Mautner | 7ea5bd4 | 2013-07-05 15:27:08 -0700 | [diff] [blame] | 228 | |
Wale Ogunwale | 040b470 | 2015-08-06 18:10:50 -0700 | [diff] [blame] | 229 | // Used to indicate if an object (e.g. stack) that we are trying to get |
| 230 | // should be created if it doesn't exist already. |
Filip Gruszczynski | 07a0e49 | 2015-12-17 14:16:38 -0800 | [diff] [blame] | 231 | static final boolean CREATE_IF_NEEDED = true; |
Wale Ogunwale | 040b470 | 2015-08-06 18:10:50 -0700 | [diff] [blame] | 232 | |
Filip Gruszczynski | bc5a6c5 | 2015-09-22 13:13:24 -0700 | [diff] [blame] | 233 | // Used to indicate that windows of activities should be preserved during the resize. |
| 234 | static final boolean PRESERVE_WINDOWS = true; |
| 235 | |
Wale Ogunwale | 040b470 | 2015-08-06 18:10:50 -0700 | [diff] [blame] | 236 | // Used to indicate if an object (e.g. task) should be moved/created |
| 237 | // at the top of its container (e.g. stack). |
Wale Ogunwale | b30daaa | 2015-08-07 21:50:49 -0700 | [diff] [blame] | 238 | static final boolean ON_TOP = true; |
Wale Ogunwale | 040b470 | 2015-08-06 18:10:50 -0700 | [diff] [blame] | 239 | |
Wale Ogunwale | c8da41e | 2016-04-16 13:27:23 -0700 | [diff] [blame] | 240 | // Don't execute any calls to resume. |
| 241 | static final boolean DEFER_RESUME = true; |
| 242 | |
Winson Chung | 010927a | 2016-12-15 16:12:35 -0800 | [diff] [blame] | 243 | // Used to indicate that a task is removed it should also be removed from recents. |
| 244 | static final boolean REMOVE_FROM_RECENTS = true; |
| 245 | |
Winson Chung | 6954fc9 | 2017-03-24 16:22:12 -0700 | [diff] [blame] | 246 | // Used to indicate that pausing an activity should occur immediately without waiting for |
| 247 | // the activity callback indicating that it has completed pausing |
| 248 | static final boolean PAUSE_IMMEDIATELY = true; |
| 249 | |
Adrian Roos | a6d6aab | 2018-04-19 18:58:22 +0200 | [diff] [blame] | 250 | /** True if the docked stack is currently being resized. */ |
| 251 | private boolean mDockedStackResizing; |
| 252 | |
| 253 | /** |
| 254 | * True if there are pending docked bounds that need to be applied after |
| 255 | * {@link #mDockedStackResizing} is reset to false. |
| 256 | */ |
| 257 | private boolean mHasPendingDockedBounds; |
| 258 | private Rect mPendingDockedBounds; |
| 259 | private Rect mPendingTempDockedTaskBounds; |
| 260 | private Rect mPendingTempDockedTaskInsetBounds; |
| 261 | private Rect mPendingTempOtherTaskBounds; |
| 262 | private Rect mPendingTempOtherTaskInsetBounds; |
| 263 | |
Winson Chung | 7900bee | 2017-03-10 08:59:25 -0800 | [diff] [blame] | 264 | /** |
| 265 | * The modes which affect which tasks are returned when calling |
| 266 | * {@link ActivityStackSupervisor#anyTaskForIdLocked(int)}. |
| 267 | */ |
| 268 | @Retention(RetentionPolicy.SOURCE) |
| 269 | @IntDef({ |
| 270 | MATCH_TASK_IN_STACKS_ONLY, |
| 271 | MATCH_TASK_IN_STACKS_OR_RECENT_TASKS, |
| 272 | MATCH_TASK_IN_STACKS_OR_RECENT_TASKS_AND_RESTORE |
| 273 | }) |
| 274 | public @interface AnyTaskForIdMatchTaskMode {} |
| 275 | // Match only tasks in the current stacks |
| 276 | static final int MATCH_TASK_IN_STACKS_ONLY = 0; |
| 277 | // Match either tasks in the current stacks, or in the recent tasks if not found in the stacks |
| 278 | static final int MATCH_TASK_IN_STACKS_OR_RECENT_TASKS = 1; |
| 279 | // Match either tasks in the current stacks, or in the recent tasks, restoring it to the |
| 280 | // provided stack id |
| 281 | static final int MATCH_TASK_IN_STACKS_OR_RECENT_TASKS_AND_RESTORE = 2; |
| 282 | |
Svetoslav | 7008b51 | 2015-06-24 18:47:07 -0700 | [diff] [blame] | 283 | // Activity actions an app cannot start if it uses a permission which is not granted. |
| 284 | private static final ArrayMap<String, String> ACTION_TO_RUNTIME_PERMISSION = |
| 285 | new ArrayMap<>(); |
Filip Gruszczynski | bc5a6c5 | 2015-09-22 13:13:24 -0700 | [diff] [blame] | 286 | |
Svetoslav | 7008b51 | 2015-06-24 18:47:07 -0700 | [diff] [blame] | 287 | static { |
| 288 | ACTION_TO_RUNTIME_PERMISSION.put(MediaStore.ACTION_IMAGE_CAPTURE, |
| 289 | Manifest.permission.CAMERA); |
| 290 | ACTION_TO_RUNTIME_PERMISSION.put(MediaStore.ACTION_VIDEO_CAPTURE, |
| 291 | Manifest.permission.CAMERA); |
| 292 | ACTION_TO_RUNTIME_PERMISSION.put(Intent.ACTION_CALL, |
| 293 | Manifest.permission.CALL_PHONE); |
| 294 | } |
| 295 | |
Svet Ganov | 99b6043 | 2015-06-27 13:15:22 -0700 | [diff] [blame] | 296 | /** Action restriction: launching the activity is not restricted. */ |
| 297 | private static final int ACTIVITY_RESTRICTION_NONE = 0; |
| 298 | /** Action restriction: launching the activity is restricted by a permission. */ |
| 299 | private static final int ACTIVITY_RESTRICTION_PERMISSION = 1; |
| 300 | /** Action restriction: launching the activity is restricted by an app op. */ |
| 301 | private static final int ACTIVITY_RESTRICTION_APPOP = 2; |
Svetoslav | 7008b51 | 2015-06-24 18:47:07 -0700 | [diff] [blame] | 302 | |
Craig Mautner | 7ea5bd4 | 2013-07-05 15:27:08 -0700 | [diff] [blame] | 303 | // For debugging to make sure the caller when acquiring/releasing our |
| 304 | // wake lock is the system process. |
| 305 | static final boolean VALIDATE_WAKE_LOCK_CALLER = false; |
Suprabh Shukla | 09a88f5 | 2015-12-02 14:36:31 -0800 | [diff] [blame] | 306 | /** The number of distinct task ids that can be assigned to the tasks of a single user */ |
| 307 | 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] | 308 | |
Craig Mautner | 2708430 | 2013-03-25 08:05:25 -0700 | [diff] [blame] | 309 | final ActivityManagerService mService; |
| 310 | |
Winson Chung | 61c9e5a | 2017-10-11 10:39:32 -0700 | [diff] [blame] | 311 | /** The historial list of recent tasks including inactive tasks */ |
Winson Chung | 1dbc811 | 2017-09-28 18:05:31 -0700 | [diff] [blame] | 312 | RecentTasks mRecentTasks; |
Wale Ogunwale | c82f2f5 | 2014-12-09 09:32:50 -0800 | [diff] [blame] | 313 | |
Winson Chung | 61c9e5a | 2017-10-11 10:39:32 -0700 | [diff] [blame] | 314 | /** 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] | 315 | private RunningTasks mRunningTasks; |
Winson Chung | 61c9e5a | 2017-10-11 10:39:32 -0700 | [diff] [blame] | 316 | |
Craig Mautner | ce5f3cb | 2013-04-22 08:58:54 -0700 | [diff] [blame] | 317 | final ActivityStackSupervisorHandler mHandler; |
Winson Chung | e2d7217 | 2018-01-25 17:46:20 +0000 | [diff] [blame] | 318 | final Looper mLooper; |
Craig Mautner | ce5f3cb | 2013-04-22 08:58:54 -0700 | [diff] [blame] | 319 | |
| 320 | /** Short cut */ |
| 321 | WindowManagerService mWindowManager; |
Craig Mautner | 4a1cb22 | 2013-12-04 16:14:06 -0800 | [diff] [blame] | 322 | DisplayManager mDisplayManager; |
Craig Mautner | ce5f3cb | 2013-04-22 08:58:54 -0700 | [diff] [blame] | 323 | |
Bryce Lee | ec55eb0 | 2017-12-05 20:51:27 -0800 | [diff] [blame] | 324 | private LaunchParamsController mLaunchParamsController; |
Bryce Lee | 9ad3eb3 | 2017-10-10 10:10:31 -0700 | [diff] [blame] | 325 | |
Suprabh Shukla | 09a88f5 | 2015-12-02 14:36:31 -0800 | [diff] [blame] | 326 | /** |
| 327 | * Maps the task identifier that activities are currently being started in to the userId of the |
| 328 | * task. Each time a new task is created, the entry for the userId of the task is incremented |
| 329 | */ |
| 330 | private final SparseIntArray mCurTaskIdForUser = new SparseIntArray(20); |
Craig Mautner | 8d341ef | 2013-03-26 09:03:27 -0700 | [diff] [blame] | 331 | |
Craig Mautner | 2420ead | 2013-04-01 17:13:20 -0700 | [diff] [blame] | 332 | /** The current user */ |
Filip Gruszczynski | 07a0e49 | 2015-12-17 14:16:38 -0800 | [diff] [blame] | 333 | int mCurrentUser; |
Craig Mautner | 2420ead | 2013-04-01 17:13:20 -0700 | [diff] [blame] | 334 | |
Craig Mautner | e0a3884 | 2013-12-16 16:14:02 -0800 | [diff] [blame] | 335 | /** The stack containing the launcher app. Assumed to always be attached to |
| 336 | * Display.DEFAULT_DISPLAY. */ |
Filip Gruszczynski | 07a0e49 | 2015-12-17 14:16:38 -0800 | [diff] [blame] | 337 | ActivityStack mHomeStack; |
Craig Mautner | 20e7227 | 2013-04-01 13:45:53 -0700 | [diff] [blame] | 338 | |
Craig Mautner | e0a3884 | 2013-12-16 16:14:02 -0800 | [diff] [blame] | 339 | /** The stack currently receiving input or launching the next activity. */ |
Filip Gruszczynski | 07a0e49 | 2015-12-17 14:16:38 -0800 | [diff] [blame] | 340 | ActivityStack mFocusedStack; |
Craig Mautner | 8d341ef | 2013-03-26 09:03:27 -0700 | [diff] [blame] | 341 | |
Craig Mautner | 4a1cb22 | 2013-12-04 16:14:06 -0800 | [diff] [blame] | 342 | /** If this is the same as mFocusedStack then the activity on the top of the focused stack has |
| 343 | * 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] | 344 | * stack becomes resumed after which it will be set to mFocusedStack. */ |
Craig Mautner | 4a1cb22 | 2013-12-04 16:14:06 -0800 | [diff] [blame] | 345 | private ActivityStack mLastFocusedStack; |
Craig Mautner | de4ef02 | 2013-04-07 19:01:33 -0700 | [diff] [blame] | 346 | |
| 347 | /** List of activities that are waiting for a new activity to become visible before completing |
| 348 | * whatever operation they are supposed to do. */ |
Bryce Lee | 4a19438 | 2017-04-04 14:32:48 -0700 | [diff] [blame] | 349 | // TODO: Remove mActivitiesWaitingForVisibleActivity list and just remove activity from |
| 350 | // mStoppingActivities when something else comes up. |
| 351 | final ArrayList<ActivityRecord> mActivitiesWaitingForVisibleActivity = new ArrayList<>(); |
Craig Mautner | de4ef02 | 2013-04-07 19:01:33 -0700 | [diff] [blame] | 352 | |
Bryce Lee | 4a19438 | 2017-04-04 14:32:48 -0700 | [diff] [blame] | 353 | /** List of processes waiting to find out when a specific activity becomes visible. */ |
| 354 | private final ArrayList<WaitInfo> mWaitingForActivityVisible = new ArrayList<>(); |
Craig Mautner | ce5f3cb | 2013-04-22 08:58:54 -0700 | [diff] [blame] | 355 | |
| 356 | /** List of processes waiting to find out about the next launched activity. */ |
Sudheer Shanka | fc46e9b | 2016-10-21 17:55:27 -0700 | [diff] [blame] | 357 | final ArrayList<WaitResult> mWaitingActivityLaunched = new ArrayList<>(); |
Craig Mautner | ce5f3cb | 2013-04-22 08:58:54 -0700 | [diff] [blame] | 358 | |
Craig Mautner | de4ef02 | 2013-04-07 19:01:33 -0700 | [diff] [blame] | 359 | /** List of activities that are ready to be stopped, but waiting for the next activity to |
| 360 | * settle down before doing so. */ |
Craig Mautner | 8c14c15 | 2015-01-15 17:32:07 -0800 | [diff] [blame] | 361 | final ArrayList<ActivityRecord> mStoppingActivities = new ArrayList<>(); |
Craig Mautner | de4ef02 | 2013-04-07 19:01:33 -0700 | [diff] [blame] | 362 | |
Craig Mautner | f333327 | 2013-04-22 10:55:53 -0700 | [diff] [blame] | 363 | /** List of activities that are ready to be finished, but waiting for the previous activity to |
| 364 | * settle down before doing so. It contains ActivityRecord objects. */ |
Craig Mautner | 8c14c15 | 2015-01-15 17:32:07 -0800 | [diff] [blame] | 365 | final ArrayList<ActivityRecord> mFinishingActivities = new ArrayList<>(); |
Craig Mautner | f333327 | 2013-04-22 10:55:53 -0700 | [diff] [blame] | 366 | |
Craig Mautner | 0eea92c | 2013-05-16 13:35:39 -0700 | [diff] [blame] | 367 | /** List of activities that are in the process of going to sleep. */ |
Craig Mautner | 8c14c15 | 2015-01-15 17:32:07 -0800 | [diff] [blame] | 368 | final ArrayList<ActivityRecord> mGoingToSleepActivities = new ArrayList<>(); |
Craig Mautner | 0eea92c | 2013-05-16 13:35:39 -0700 | [diff] [blame] | 369 | |
Wale Ogunwale | 22e2526 | 2016-02-01 10:32:02 -0800 | [diff] [blame] | 370 | /** List of activities whose multi-window mode changed that we need to report to the |
| 371 | * application */ |
| 372 | final ArrayList<ActivityRecord> mMultiWindowModeChangedActivities = new ArrayList<>(); |
| 373 | |
| 374 | /** List of activities whose picture-in-picture mode changed that we need to report to the |
| 375 | * application */ |
| 376 | final ArrayList<ActivityRecord> mPipModeChangedActivities = new ArrayList<>(); |
| 377 | |
Jorim Jaggi | fa9ed96 | 2018-01-25 00:16:49 +0100 | [diff] [blame] | 378 | /** |
| 379 | * Animations that for the current transition have requested not to |
| 380 | * be considered for the transition animation. |
| 381 | */ |
| 382 | final ArrayList<ActivityRecord> mNoAnimActivities = new ArrayList<>(); |
| 383 | |
Winson Chung | 5af42fc | 2017-03-24 17:11:33 -0700 | [diff] [blame] | 384 | /** The target stack bounds for the picture-in-picture mode changed that we need to report to |
| 385 | * the application */ |
| 386 | Rect mPipModeChangedTargetStackBounds; |
| 387 | |
Craig Mautner | f333327 | 2013-04-22 10:55:53 -0700 | [diff] [blame] | 388 | /** Used on user changes */ |
Amith Yamasani | 37a40c2 | 2015-06-17 13:25:42 -0700 | [diff] [blame] | 389 | final ArrayList<UserState> mStartingUsers = new ArrayList<>(); |
Craig Mautner | f333327 | 2013-04-22 10:55:53 -0700 | [diff] [blame] | 390 | |
Craig Mautner | de4ef02 | 2013-04-07 19:01:33 -0700 | [diff] [blame] | 391 | /** Set to indicate whether to issue an onUserLeaving callback when a newly launched activity |
| 392 | * is being brought in front of us. */ |
| 393 | boolean mUserLeaving = false; |
| 394 | |
Bryce Lee | d3624e1 | 2017-11-30 08:51:45 -0800 | [diff] [blame] | 395 | /** Set when a power hint has started, but not ended. */ |
| 396 | private boolean mPowerHintSent; |
| 397 | |
Craig Mautner | 0eea92c | 2013-05-16 13:35:39 -0700 | [diff] [blame] | 398 | /** |
Craig Mautner | 7ea5bd4 | 2013-07-05 15:27:08 -0700 | [diff] [blame] | 399 | * We don't want to allow the device to go to sleep while in the process |
| 400 | * of launching an activity. This is primarily to allow alarm intent |
| 401 | * receivers to launch an activity and get that to run before the device |
| 402 | * goes back to sleep. |
| 403 | */ |
Jeff Brown | 2c43c33 | 2014-06-12 22:38:59 -0700 | [diff] [blame] | 404 | PowerManager.WakeLock mLaunchingActivity; |
Craig Mautner | 7ea5bd4 | 2013-07-05 15:27:08 -0700 | [diff] [blame] | 405 | |
| 406 | /** |
Craig Mautner | 0eea92c | 2013-05-16 13:35:39 -0700 | [diff] [blame] | 407 | * Set when the system is going to sleep, until we have |
| 408 | * successfully paused the current activity and released our wake lock. |
| 409 | * At that point the system is allowed to actually sleep. |
| 410 | */ |
Jeff Brown | 2c43c33 | 2014-06-12 22:38:59 -0700 | [diff] [blame] | 411 | PowerManager.WakeLock mGoingToSleep; |
Craig Mautner | 0eea92c | 2013-05-16 13:35:39 -0700 | [diff] [blame] | 412 | |
David Stevens | 9440dc8 | 2017-03-16 19:00:20 -0700 | [diff] [blame] | 413 | /** |
| 414 | * A list of tokens that cause the top activity to be put to sleep. |
| 415 | * They are used by components that may hide and block interaction with underlying |
| 416 | * activities. |
| 417 | */ |
Wale Ogunwale | 9dcf946 | 2017-09-19 15:13:01 -0700 | [diff] [blame] | 418 | final ArrayList<SleepToken> mSleepTokens = new ArrayList<>(); |
David Stevens | 9440dc8 | 2017-03-16 19:00:20 -0700 | [diff] [blame] | 419 | |
Craig Mautner | 4f1df4f | 2013-10-15 15:44:14 -0700 | [diff] [blame] | 420 | /** Stack id of the front stack when user switched, indexed by userId. */ |
| 421 | SparseIntArray mUserStackInFront = new SparseIntArray(2); |
Craig Mautner | 93529a4 | 2013-10-04 15:03:13 -0700 | [diff] [blame] | 422 | |
Bryce Lee | af3a400 | 2017-03-20 10:37:12 -0700 | [diff] [blame] | 423 | // TODO: There should be an ActivityDisplayController coordinating am/wm interaction. |
Craig Mautner | 4a1cb22 | 2013-12-04 16:14:06 -0800 | [diff] [blame] | 424 | /** Mapping from displayId to display current state */ |
Craig Mautner | 15df08a | 2015-04-01 12:17:18 -0700 | [diff] [blame] | 425 | private final SparseArray<ActivityDisplay> mActivityDisplays = new SparseArray<>(); |
Craig Mautner | 4a1cb22 | 2013-12-04 16:14:06 -0800 | [diff] [blame] | 426 | |
Andrii Kulian | fb1bf69 | 2017-01-17 11:17:34 -0800 | [diff] [blame] | 427 | private final SparseArray<IntArray> mDisplayAccessUIDs = new SparseArray<>(); |
| 428 | |
| 429 | private DisplayManagerInternal mDisplayManagerInternal; |
Jeff Brown | ca9bc70 | 2014-02-11 14:32:56 -0800 | [diff] [blame] | 430 | |
Wale Ogunwale | d046a01 | 2015-12-24 13:05:59 -0800 | [diff] [blame] | 431 | /** Used to keep resumeTopActivityUncheckedLocked() from being entered recursively */ |
Craig Mautner | 42d04db | 2014-11-06 12:13:23 -0800 | [diff] [blame] | 432 | boolean inResumeTopActivity; |
| 433 | |
Andrii Kulian | 1e32e02 | 2016-09-16 15:29:34 -0700 | [diff] [blame] | 434 | /** |
| 435 | * Temporary rect used during docked stack resize calculation so we don't need to create a new |
| 436 | * object each time. |
| 437 | */ |
Wale Ogunwale | b34a7ad | 2015-08-14 11:05:30 -0700 | [diff] [blame] | 438 | private final Rect tempRect = new Rect(); |
Wale Ogunwale | 7e1f5f5 | 2017-10-18 15:19:59 -0700 | [diff] [blame] | 439 | private final ActivityOptions mTmpOptions = ActivityOptions.makeBasic(); |
Filip Gruszczynski | ebcc875 | 2015-08-25 16:51:05 -0700 | [diff] [blame] | 440 | |
Filip Gruszczynski | d2f1d94 | 2015-10-14 15:10:12 -0700 | [diff] [blame] | 441 | // The default minimal size that will be used if the activity doesn't specify its minimal size. |
| 442 | // It will be calculated when the default display gets added. |
Andrii Kulian | f66a83d | 2016-05-17 12:17:44 -0700 | [diff] [blame] | 443 | int mDefaultMinSizeOfResizeableTask = -1; |
Filip Gruszczynski | d2f1d94 | 2015-10-14 15:10:12 -0700 | [diff] [blame] | 444 | |
Chong Zhang | fdcc4d4 | 2015-10-14 16:50:12 -0700 | [diff] [blame] | 445 | // Whether tasks have moved and we need to rank the tasks before next OOM scoring |
| 446 | private boolean mTaskLayersChanged = true; |
| 447 | |
Bryce Lee | 2a3cc46 | 2017-10-27 10:57:35 -0700 | [diff] [blame] | 448 | private ActivityMetricsLogger mActivityMetricsLogger; |
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 | |
| 633 | public KeyguardController getKeyguardController() { |
| 634 | return mKeyguardController; |
| 635 | } |
| 636 | |
Suprabh Shukla | 09a88f5 | 2015-12-02 14:36:31 -0800 | [diff] [blame] | 637 | void setRecentTasks(RecentTasks recentTasks) { |
| 638 | mRecentTasks = recentTasks; |
Winson Chung | 1dbc811 | 2017-09-28 18:05:31 -0700 | [diff] [blame] | 639 | mRecentTasks.registerCallback(this); |
Suprabh Shukla | 09a88f5 | 2015-12-02 14:36:31 -0800 | [diff] [blame] | 640 | } |
| 641 | |
Winson Chung | 3f0e59a | 2017-10-25 10:19:05 -0700 | [diff] [blame] | 642 | @VisibleForTesting |
| 643 | RunningTasks createRunningTasks() { |
| 644 | return new RunningTasks(); |
| 645 | } |
| 646 | |
Jeff Brown | 2c43c33 | 2014-06-12 22:38:59 -0700 | [diff] [blame] | 647 | /** |
| 648 | * At the time when the constructor runs, the power manager has not yet been |
| 649 | * initialized. So we initialize our wakelocks afterwards. |
| 650 | */ |
| 651 | void initPowerManagement() { |
chaviw | 59b9885 | 2017-06-13 12:05:44 -0700 | [diff] [blame] | 652 | mPowerManager = (PowerManager)mService.mContext.getSystemService(Context.POWER_SERVICE); |
| 653 | mGoingToSleep = mPowerManager |
| 654 | .newWakeLock(PARTIAL_WAKE_LOCK, "ActivityManager-Sleep"); |
| 655 | mLaunchingActivity = mPowerManager.newWakeLock(PARTIAL_WAKE_LOCK, "*launch*"); |
Craig Mautner | 7ea5bd4 | 2013-07-05 15:27:08 -0700 | [diff] [blame] | 656 | mLaunchingActivity.setReferenceCounted(false); |
Craig Mautner | 2219a1b | 2013-03-25 09:44:30 -0700 | [diff] [blame] | 657 | } |
| 658 | |
Craig Mautner | ce5f3cb | 2013-04-22 08:58:54 -0700 | [diff] [blame] | 659 | void setWindowManager(WindowManagerService wm) { |
Craig Mautner | 4a1cb22 | 2013-12-04 16:14:06 -0800 | [diff] [blame] | 660 | synchronized (mService) { |
| 661 | mWindowManager = wm; |
Bryce Lee | 459c062 | 2018-03-19 11:04:01 -0700 | [diff] [blame] | 662 | getKeyguardController().setWindowManager(wm); |
Craig Mautner | 4a1cb22 | 2013-12-04 16:14:06 -0800 | [diff] [blame] | 663 | |
| 664 | mDisplayManager = |
| 665 | (DisplayManager)mService.mContext.getSystemService(Context.DISPLAY_SERVICE); |
| 666 | mDisplayManager.registerDisplayListener(this, null); |
Andrii Kulian | fb1bf69 | 2017-01-17 11:17:34 -0800 | [diff] [blame] | 667 | mDisplayManagerInternal = LocalServices.getService(DisplayManagerInternal.class); |
Craig Mautner | 4a1cb22 | 2013-12-04 16:14:06 -0800 | [diff] [blame] | 668 | |
| 669 | Display[] displays = mDisplayManager.getDisplays(); |
| 670 | for (int displayNdx = displays.length - 1; displayNdx >= 0; --displayNdx) { |
Wale Ogunwale | 45477b5 | 2018-03-06 12:24:19 -0800 | [diff] [blame] | 671 | final Display display = displays[displayNdx]; |
| 672 | ActivityDisplay activityDisplay = new ActivityDisplay(this, display); |
| 673 | mActivityDisplays.put(display.getDisplayId(), activityDisplay); |
Filip Gruszczynski | 7be9a8c | 2015-10-15 18:20:30 -0700 | [diff] [blame] | 674 | calculateDefaultMinimalSizeOfResizeableTasks(activityDisplay); |
Craig Mautner | 4a1cb22 | 2013-12-04 16:14:06 -0800 | [diff] [blame] | 675 | } |
| 676 | |
Wale Ogunwale | 04a05ac | 2017-09-17 21:35:02 -0700 | [diff] [blame] | 677 | mHomeStack = mFocusedStack = mLastFocusedStack = getDefaultDisplay().getOrCreateStack( |
| 678 | WINDOWING_MODE_FULLSCREEN, ACTIVITY_TYPE_HOME, ON_TOP); |
Craig Mautner | 4a1cb22 | 2013-12-04 16:14:06 -0800 | [diff] [blame] | 679 | } |
Craig Mautner | 2708430 | 2013-03-25 08:05:25 -0700 | [diff] [blame] | 680 | } |
| 681 | |
Craig Mautner | ce5f3cb | 2013-04-22 08:58:54 -0700 | [diff] [blame] | 682 | ActivityStack getFocusedStack() { |
Craig Mautner | 4a1cb22 | 2013-12-04 16:14:06 -0800 | [diff] [blame] | 683 | return mFocusedStack; |
Craig Mautner | 20e7227 | 2013-04-01 13:45:53 -0700 | [diff] [blame] | 684 | } |
| 685 | |
Bryce Lee | 7b851cc | 2018-04-10 14:53:13 -0700 | [diff] [blame] | 686 | boolean isFocusable(ConfigurationContainer container, boolean alwaysFocusable) { |
| 687 | if (container.inSplitScreenPrimaryWindowingMode() && mIsDockMinimized) { |
| 688 | return false; |
| 689 | } |
| 690 | |
| 691 | return container.getWindowConfiguration().canReceiveKeys() || alwaysFocusable; |
| 692 | } |
| 693 | |
Craig Mautner | de4ef02 | 2013-04-07 19:01:33 -0700 | [diff] [blame] | 694 | ActivityStack getLastStack() { |
Craig Mautner | 4a1cb22 | 2013-12-04 16:14:06 -0800 | [diff] [blame] | 695 | return mLastFocusedStack; |
Craig Mautner | 2219a1b | 2013-03-25 09:44:30 -0700 | [diff] [blame] | 696 | } |
| 697 | |
Wale Ogunwale | 1e60e0c | 2015-10-28 13:36:10 -0700 | [diff] [blame] | 698 | boolean isFocusedStack(ActivityStack stack) { |
Andrii Kulian | 94e82d9b0 | 2017-07-13 15:33:06 -0700 | [diff] [blame] | 699 | return stack != null && stack == mFocusedStack; |
Craig Mautner | 20e7227 | 2013-04-01 13:45:53 -0700 | [diff] [blame] | 700 | } |
| 701 | |
Wale Ogunwale | d046a01 | 2015-12-24 13:05:59 -0800 | [diff] [blame] | 702 | /** NOTE: Should only be called from {@link ActivityStack#moveToFront} */ |
Wale Ogunwale | 4cea0f5 | 2015-12-25 06:30:31 -0800 | [diff] [blame] | 703 | void setFocusStackUnchecked(String reason, ActivityStack focusCandidate) { |
| 704 | if (!focusCandidate.isFocusable()) { |
| 705 | // 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] | 706 | focusCandidate = getNextFocusableStackLocked(focusCandidate, false /* ignoreCurrent */); |
Wale Ogunwale | 4cea0f5 | 2015-12-25 06:30:31 -0800 | [diff] [blame] | 707 | } |
| 708 | |
| 709 | if (focusCandidate != mFocusedStack) { |
Wale Ogunwale | d046a01 | 2015-12-24 13:05:59 -0800 | [diff] [blame] | 710 | mLastFocusedStack = mFocusedStack; |
Wale Ogunwale | 4cea0f5 | 2015-12-25 06:30:31 -0800 | [diff] [blame] | 711 | mFocusedStack = focusCandidate; |
Wale Ogunwale | cb82f30 | 2015-02-25 07:53:40 -0800 | [diff] [blame] | 712 | |
Wale Ogunwale | d046a01 | 2015-12-24 13:05:59 -0800 | [diff] [blame] | 713 | EventLogTags.writeAmFocusedStack( |
| 714 | mCurrentUser, mFocusedStack == null ? -1 : mFocusedStack.getStackId(), |
| 715 | mLastFocusedStack == null ? -1 : mLastFocusedStack.getStackId(), reason); |
| 716 | } |
| 717 | |
| 718 | final ActivityRecord r = topRunningActivityLocked(); |
Craig Mautner | f3ea23a | 2015-01-13 09:37:08 -0800 | [diff] [blame] | 719 | if (mService.mBooting || !mService.mBooted) { |
Craig Mautner | f3ea23a | 2015-01-13 09:37:08 -0800 | [diff] [blame] | 720 | if (r != null && r.idle) { |
| 721 | checkFinishBootingLocked(); |
| 722 | } |
| 723 | } |
Craig Mautner | de4ef02 | 2013-04-07 19:01:33 -0700 | [diff] [blame] | 724 | } |
| 725 | |
Wale Ogunwale | 925d0d1 | 2015-09-23 15:40:07 -0700 | [diff] [blame] | 726 | void moveHomeStackToFront(String reason) { |
| 727 | mHomeStack.moveToFront(reason); |
| 728 | } |
| 729 | |
Matthew Ng | 330757d | 2017-02-28 14:19:17 -0800 | [diff] [blame] | 730 | void moveRecentsStackToFront(String reason) { |
Wale Ogunwale | 04a05ac | 2017-09-17 21:35:02 -0700 | [diff] [blame] | 731 | final ActivityStack recentsStack = getDefaultDisplay().getStack( |
| 732 | WINDOWING_MODE_UNDEFINED, ACTIVITY_TYPE_RECENTS); |
Matthew Ng | 330757d | 2017-02-28 14:19:17 -0800 | [diff] [blame] | 733 | if (recentsStack != null) { |
| 734 | recentsStack.moveToFront(reason); |
| 735 | } |
| 736 | } |
| 737 | |
Wale Ogunwale | d80c263 | 2015-03-13 10:26:26 -0700 | [diff] [blame] | 738 | /** 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] | 739 | boolean moveHomeStackTaskToTop(String reason) { |
| 740 | mHomeStack.moveHomeStackTaskToTop(); |
Wale Ogunwale | d80c263 | 2015-03-13 10:26:26 -0700 | [diff] [blame] | 741 | |
Wale Ogunwale | 2d0f39b | 2015-04-17 15:35:39 -0700 | [diff] [blame] | 742 | final ActivityRecord top = getHomeActivity(); |
Wale Ogunwale | d80c263 | 2015-03-13 10:26:26 -0700 | [diff] [blame] | 743 | if (top == null) { |
| 744 | return false; |
| 745 | } |
Chong Zhang | 6cda19c | 2016-06-14 19:07:56 -0700 | [diff] [blame] | 746 | moveFocusableActivityStackToFrontLocked(top, reason); |
Wale Ogunwale | d80c263 | 2015-03-13 10:26:26 -0700 | [diff] [blame] | 747 | return true; |
Craig Mautner | 8e56957 | 2013-10-11 17:36:59 -0700 | [diff] [blame] | 748 | } |
| 749 | |
Matthew Ng | ae1ff4f | 2016-11-10 15:49:14 -0800 | [diff] [blame] | 750 | boolean resumeHomeStackTask(ActivityRecord prev, String reason) { |
Dianne Hackborn | 7622a0f | 2014-09-30 14:31:42 -0700 | [diff] [blame] | 751 | if (!mService.mBooting && !mService.mBooted) { |
| 752 | // Not ready yet! |
| 753 | return false; |
| 754 | } |
| 755 | |
Matthew Ng | ae1ff4f | 2016-11-10 15:49:14 -0800 | [diff] [blame] | 756 | mHomeStack.moveHomeStackTaskToTop(); |
Wale Ogunwale | 2d0f39b | 2015-04-17 15:35:39 -0700 | [diff] [blame] | 757 | ActivityRecord r = getHomeActivity(); |
Wale Ogunwale | d046a01 | 2015-12-24 13:05:59 -0800 | [diff] [blame] | 758 | final String myReason = reason + " resumeHomeStackTask"; |
| 759 | |
Mark Lu | a56ea12 | 2015-10-08 13:31:01 +0800 | [diff] [blame] | 760 | // Only resume home activity if isn't finishing. |
| 761 | if (r != null && !r.finishing) { |
Chong Zhang | 6cda19c | 2016-06-14 19:07:56 -0700 | [diff] [blame] | 762 | moveFocusableActivityStackToFrontLocked(r, myReason); |
Wale Ogunwale | d046a01 | 2015-12-24 13:05:59 -0800 | [diff] [blame] | 763 | return resumeFocusedStackTopActivityLocked(mHomeStack, prev, null); |
Craig Mautner | 69ada55 | 2013-04-18 13:51:51 -0700 | [diff] [blame] | 764 | } |
Wale Ogunwale | d046a01 | 2015-12-24 13:05:59 -0800 | [diff] [blame] | 765 | return mService.startHomeActivityLocked(mCurrentUser, myReason); |
Craig Mautner | 69ada55 | 2013-04-18 13:51:51 -0700 | [diff] [blame] | 766 | } |
| 767 | |
Craig Mautner | 8d341ef | 2013-03-26 09:03:27 -0700 | [diff] [blame] | 768 | TaskRecord anyTaskForIdLocked(int id) { |
Wale Ogunwale | 0568aed | 2017-09-08 13:29:37 -0700 | [diff] [blame] | 769 | return anyTaskForIdLocked(id, MATCH_TASK_IN_STACKS_OR_RECENT_TASKS_AND_RESTORE); |
| 770 | } |
| 771 | |
| 772 | TaskRecord anyTaskForIdLocked(int id, @AnyTaskForIdMatchTaskMode int matchMode) { |
Wale Ogunwale | ab5de37 | 2017-10-18 06:46:31 -0700 | [diff] [blame] | 773 | return anyTaskForIdLocked(id, matchMode, null, !ON_TOP); |
Wale Ogunwale | 04f4d6b | 2015-03-11 09:23:25 -0700 | [diff] [blame] | 774 | } |
| 775 | |
| 776 | /** |
Bryce Lee | 92b7b65 | 2017-04-03 08:33:11 -0700 | [diff] [blame] | 777 | * 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] | 778 | * @param id Id of the task we would like returned. |
Winson Chung | 7900bee | 2017-03-10 08:59:25 -0800 | [diff] [blame] | 779 | * @param matchMode The mode to match the given task id in. |
Wale Ogunwale | 0568aed | 2017-09-08 13:29:37 -0700 | [diff] [blame] | 780 | * @param aOptions The activity options to use for restoration. Can be null. |
Wale Ogunwale | ab5de37 | 2017-10-18 06:46:31 -0700 | [diff] [blame] | 781 | * @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] | 782 | */ |
Wale Ogunwale | 0568aed | 2017-09-08 13:29:37 -0700 | [diff] [blame] | 783 | TaskRecord anyTaskForIdLocked(int id, @AnyTaskForIdMatchTaskMode int matchMode, |
Wale Ogunwale | ab5de37 | 2017-10-18 06:46:31 -0700 | [diff] [blame] | 784 | @Nullable ActivityOptions aOptions, boolean onTop) { |
| 785 | // 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] | 786 | if (matchMode != MATCH_TASK_IN_STACKS_OR_RECENT_TASKS_AND_RESTORE && aOptions != null) { |
| 787 | throw new IllegalArgumentException("Should not specify activity options for non-restore" |
| 788 | + " lookup"); |
Winson Chung | 7900bee | 2017-03-10 08:59:25 -0800 | [diff] [blame] | 789 | } |
| 790 | |
Craig Mautner | e0a3884 | 2013-12-16 16:14:02 -0800 | [diff] [blame] | 791 | int numDisplays = mActivityDisplays.size(); |
Craig Mautner | 4a1cb22 | 2013-12-04 16:14:06 -0800 | [diff] [blame] | 792 | for (int displayNdx = 0; displayNdx < numDisplays; ++displayNdx) { |
Wale Ogunwale | a0f5b5e | 2017-10-11 09:37:23 -0700 | [diff] [blame] | 793 | final ActivityDisplay display = mActivityDisplays.valueAt(displayNdx); |
| 794 | for (int stackNdx = display.getChildCount() - 1; stackNdx >= 0; --stackNdx) { |
| 795 | final ActivityStack stack = display.getChildAt(stackNdx); |
Bryce Lee | 92b7b65 | 2017-04-03 08:33:11 -0700 | [diff] [blame] | 796 | final TaskRecord task = stack.taskForIdLocked(id); |
Wale Ogunwale | ab5de37 | 2017-10-18 06:46:31 -0700 | [diff] [blame] | 797 | if (task == null) { |
| 798 | continue; |
Craig Mautner | 4a1cb22 | 2013-12-04 16:14:06 -0800 | [diff] [blame] | 799 | } |
Wale Ogunwale | ab5de37 | 2017-10-18 06:46:31 -0700 | [diff] [blame] | 800 | if (aOptions != null) { |
| 801 | // Resolve the stack the task should be placed in now based on options |
| 802 | // and reparent if needed. |
| 803 | final ActivityStack launchStack = getLaunchStack(null, aOptions, task, onTop); |
| 804 | if (launchStack != null && stack != launchStack) { |
| 805 | final int reparentMode = onTop |
| 806 | ? REPARENT_MOVE_STACK_TO_FRONT : REPARENT_LEAVE_STACK_IN_PLACE; |
| 807 | task.reparent(launchStack, onTop, reparentMode, ANIMATE, DEFER_RESUME, |
| 808 | "anyTaskForIdLocked"); |
| 809 | } |
| 810 | } |
| 811 | return task; |
Craig Mautner | 8d341ef | 2013-03-26 09:03:27 -0700 | [diff] [blame] | 812 | } |
| 813 | } |
Wale Ogunwale | 7de0535 | 2014-12-12 15:21:33 -0800 | [diff] [blame] | 814 | |
Winson Chung | 7900bee | 2017-03-10 08:59:25 -0800 | [diff] [blame] | 815 | // If we are matching stack tasks only, return now |
| 816 | if (matchMode == MATCH_TASK_IN_STACKS_ONLY) { |
Wale Ogunwale | 7de0535 | 2014-12-12 15:21:33 -0800 | [diff] [blame] | 817 | return null; |
| 818 | } |
| 819 | |
Winson Chung | 7900bee | 2017-03-10 08:59:25 -0800 | [diff] [blame] | 820 | // Otherwise, check the recent tasks and return if we find it there and we are not restoring |
| 821 | // the task from recents |
| 822 | 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] | 823 | final TaskRecord task = mRecentTasks.getTask(id); |
Bryce Lee | 92b7b65 | 2017-04-03 08:33:11 -0700 | [diff] [blame] | 824 | |
| 825 | if (task == null) { |
| 826 | if (DEBUG_RECENTS) { |
Winson Chung | 7900bee | 2017-03-10 08:59:25 -0800 | [diff] [blame] | 827 | Slog.d(TAG_RECENTS, "\tDidn't find task id=" + id + " in recents"); |
| 828 | } |
Bryce Lee | 92b7b65 | 2017-04-03 08:33:11 -0700 | [diff] [blame] | 829 | |
| 830 | return null; |
| 831 | } |
| 832 | |
| 833 | if (matchMode == MATCH_TASK_IN_STACKS_OR_RECENT_TASKS) { |
Wale Ogunwale | 04f4d6b | 2015-03-11 09:23:25 -0700 | [diff] [blame] | 834 | return task; |
| 835 | } |
| 836 | |
Winson Chung | 7900bee | 2017-03-10 08:59:25 -0800 | [diff] [blame] | 837 | // 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] | 838 | if (!restoreRecentTaskLocked(task, aOptions, onTop)) { |
Wale Ogunwale | ee006da | 2015-03-30 14:49:25 -0700 | [diff] [blame] | 839 | if (DEBUG_RECENTS) Slog.w(TAG_RECENTS, |
| 840 | "Couldn't restore task id=" + id + " found in recents"); |
Wale Ogunwale | 7de0535 | 2014-12-12 15:21:33 -0800 | [diff] [blame] | 841 | return null; |
| 842 | } |
Wale Ogunwale | ee006da | 2015-03-30 14:49:25 -0700 | [diff] [blame] | 843 | 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] | 844 | return task; |
Craig Mautner | 8d341ef | 2013-03-26 09:03:27 -0700 | [diff] [blame] | 845 | } |
| 846 | |
Craig Mautner | 6170f73 | 2013-04-02 13:05:23 -0700 | [diff] [blame] | 847 | ActivityRecord isInAnyStackLocked(IBinder token) { |
Craig Mautner | e0a3884 | 2013-12-16 16:14:02 -0800 | [diff] [blame] | 848 | int numDisplays = mActivityDisplays.size(); |
Craig Mautner | 4a1cb22 | 2013-12-04 16:14:06 -0800 | [diff] [blame] | 849 | for (int displayNdx = 0; displayNdx < numDisplays; ++displayNdx) { |
Wale Ogunwale | a0f5b5e | 2017-10-11 09:37:23 -0700 | [diff] [blame] | 850 | final ActivityDisplay display = mActivityDisplays.valueAt(displayNdx); |
| 851 | for (int stackNdx = display.getChildCount() - 1; stackNdx >= 0; --stackNdx) { |
| 852 | final ActivityStack stack = display.getChildAt(stackNdx); |
| 853 | final ActivityRecord r = stack.isInStackLocked(token); |
Craig Mautner | 4a1cb22 | 2013-12-04 16:14:06 -0800 | [diff] [blame] | 854 | if (r != null) { |
| 855 | return r; |
| 856 | } |
Craig Mautner | 6170f73 | 2013-04-02 13:05:23 -0700 | [diff] [blame] | 857 | } |
| 858 | } |
| 859 | return null; |
| 860 | } |
| 861 | |
Tony Mak | 853304c | 2016-04-18 15:17:41 +0100 | [diff] [blame] | 862 | /** |
Robin Lee | 3fef1f2 | 2016-12-20 14:50:13 +0000 | [diff] [blame] | 863 | * Detects whether we should show a lock screen in front of this task for a locked user. |
| 864 | * <p> |
| 865 | * We'll do this if either of the following holds: |
| 866 | * <ul> |
| 867 | * <li>The top activity explicitly belongs to {@param userId}.</li> |
| 868 | * <li>The top activity returns a result to an activity belonging to {@param userId}.</li> |
| 869 | * </ul> |
| 870 | * |
| 871 | * @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] | 872 | */ |
Robin Lee | 3fef1f2 | 2016-12-20 14:50:13 +0000 | [diff] [blame] | 873 | private boolean taskTopActivityIsUser(TaskRecord task, @UserIdInt int userId) { |
| 874 | // To handle the case that work app is in the task but just is not the top one. |
| 875 | final ActivityRecord activityRecord = task.getTopActivity(); |
| 876 | final ActivityRecord resultTo = (activityRecord != null ? activityRecord.resultTo : null); |
| 877 | |
| 878 | return (activityRecord != null && activityRecord.userId == userId) |
| 879 | || (resultTo != null && resultTo.userId == userId); |
| 880 | } |
| 881 | |
| 882 | /** |
| 883 | * Find all visible task stacks containing {@param userId} and intercept them with an activity |
| 884 | * to block out the contents and possibly start a credential-confirming intent. |
| 885 | * |
| 886 | * @param userId user handle for the locked managed profile. |
| 887 | */ |
| 888 | void lockAllProfileTasks(@UserIdInt int userId) { |
| 889 | mWindowManager.deferSurfaceLayout(); |
| 890 | try { |
Wale Ogunwale | a0f5b5e | 2017-10-11 09:37:23 -0700 | [diff] [blame] | 891 | for (int displayNdx = mActivityDisplays.size() - 1; displayNdx >= 0; --displayNdx) { |
| 892 | final ActivityDisplay display = mActivityDisplays.valueAt(displayNdx); |
| 893 | for (int stackNdx = display.getChildCount() - 1; stackNdx >= 0; --stackNdx) { |
| 894 | final ActivityStack stack = display.getChildAt(stackNdx); |
| 895 | final List<TaskRecord> tasks = stack.getAllTasks(); |
| 896 | for (int taskNdx = tasks.size() - 1; taskNdx >= 0; taskNdx--) { |
| 897 | final TaskRecord task = tasks.get(taskNdx); |
Robin Lee | 3fef1f2 | 2016-12-20 14:50:13 +0000 | [diff] [blame] | 898 | |
Wale Ogunwale | a0f5b5e | 2017-10-11 09:37:23 -0700 | [diff] [blame] | 899 | // Check the task for a top activity belonging to userId, or returning a |
| 900 | // result to an activity belonging to userId. Example case: a document |
| 901 | // picker for personal files, opened by a work app, should still get locked. |
| 902 | if (taskTopActivityIsUser(task, userId)) { |
| 903 | mService.mTaskChangeNotificationController.notifyTaskProfileLocked( |
| 904 | task.taskId, userId); |
| 905 | } |
Robin Lee | 3fef1f2 | 2016-12-20 14:50:13 +0000 | [diff] [blame] | 906 | } |
Tony Mak | 853304c | 2016-04-18 15:17:41 +0100 | [diff] [blame] | 907 | } |
| 908 | } |
Robin Lee | 3fef1f2 | 2016-12-20 14:50:13 +0000 | [diff] [blame] | 909 | } finally { |
| 910 | mWindowManager.continueSurfaceLayout(); |
Tony Mak | 853304c | 2016-04-18 15:17:41 +0100 | [diff] [blame] | 911 | } |
Clara Bayarri | f0649ce | 2016-01-14 12:30:42 +0000 | [diff] [blame] | 912 | } |
| 913 | |
Suprabh Shukla | 09a88f5 | 2015-12-02 14:36:31 -0800 | [diff] [blame] | 914 | void setNextTaskIdForUserLocked(int taskId, int userId) { |
| 915 | final int currentTaskId = mCurTaskIdForUser.get(userId, -1); |
| 916 | if (taskId > currentTaskId) { |
| 917 | mCurTaskIdForUser.put(userId, taskId); |
Craig Mautner | ef73ee1 | 2014-04-23 11:45:37 -0700 | [diff] [blame] | 918 | } |
| 919 | } |
| 920 | |
Chong Zhang | d9d35bd | 2016-08-04 17:55:21 -0700 | [diff] [blame] | 921 | static int nextTaskIdForUser(int taskId, int userId) { |
| 922 | int nextTaskId = taskId + 1; |
| 923 | if (nextTaskId == (userId + 1) * MAX_TASK_IDS_PER_USER) { |
| 924 | // Wrap around as there will be smaller task ids that are available now. |
| 925 | nextTaskId -= MAX_TASK_IDS_PER_USER; |
| 926 | } |
| 927 | return nextTaskId; |
| 928 | } |
| 929 | |
Suprabh Shukla | 09a88f5 | 2015-12-02 14:36:31 -0800 | [diff] [blame] | 930 | int getNextTaskIdForUserLocked(int userId) { |
Suprabh Shukla | 09a88f5 | 2015-12-02 14:36:31 -0800 | [diff] [blame] | 931 | final int currentTaskId = mCurTaskIdForUser.get(userId, userId * MAX_TASK_IDS_PER_USER); |
| 932 | // for a userId u, a taskId can only be in the range |
| 933 | // [u*MAX_TASK_IDS_PER_USER, (u+1)*MAX_TASK_IDS_PER_USER-1], so if MAX_TASK_IDS_PER_USER |
| 934 | // 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] | 935 | int candidateTaskId = nextTaskIdForUser(currentTaskId, userId); |
Winson Chung | 1dbc811 | 2017-09-28 18:05:31 -0700 | [diff] [blame] | 936 | while (mRecentTasks.containsTaskId(candidateTaskId, userId) |
Wale Ogunwale | 0568aed | 2017-09-08 13:29:37 -0700 | [diff] [blame] | 937 | || anyTaskForIdLocked( |
| 938 | candidateTaskId, MATCH_TASK_IN_STACKS_OR_RECENT_TASKS) != null) { |
Chong Zhang | d9d35bd | 2016-08-04 17:55:21 -0700 | [diff] [blame] | 939 | candidateTaskId = nextTaskIdForUser(candidateTaskId, userId); |
Suprabh Shukla | 09a88f5 | 2015-12-02 14:36:31 -0800 | [diff] [blame] | 940 | if (candidateTaskId == currentTaskId) { |
| 941 | // Something wrong! |
| 942 | // All MAX_TASK_IDS_PER_USER task ids are taken up by running tasks for this user |
| 943 | throw new IllegalStateException("Cannot get an available task id." |
| 944 | + " Reached limit of " + MAX_TASK_IDS_PER_USER |
| 945 | + " running tasks per user."); |
| 946 | } |
| 947 | } |
| 948 | mCurTaskIdForUser.put(userId, candidateTaskId); |
| 949 | return candidateTaskId; |
Craig Mautner | 8d341ef | 2013-03-26 09:03:27 -0700 | [diff] [blame] | 950 | } |
| 951 | |
Chong Zhang | 6cda19c | 2016-06-14 19:07:56 -0700 | [diff] [blame] | 952 | ActivityRecord getResumedActivityLocked() { |
Wale Ogunwale | d697cea | 2015-02-20 17:19:49 -0800 | [diff] [blame] | 953 | ActivityStack stack = mFocusedStack; |
Craig Mautner | ce5f3cb | 2013-04-22 08:58:54 -0700 | [diff] [blame] | 954 | if (stack == null) { |
| 955 | return null; |
| 956 | } |
Bryce Lee | c4ab62a | 2018-03-05 14:19:26 -0800 | [diff] [blame] | 957 | ActivityRecord resumedActivity = stack.getResumedActivity(); |
Craig Mautner | de4ef02 | 2013-04-07 19:01:33 -0700 | [diff] [blame] | 958 | if (resumedActivity == null || resumedActivity.app == null) { |
| 959 | resumedActivity = stack.mPausingActivity; |
| 960 | if (resumedActivity == null || resumedActivity.app == null) { |
Filip Gruszczynski | 3e85ba2 | 2015-10-05 22:48:30 -0700 | [diff] [blame] | 961 | resumedActivity = stack.topRunningActivityLocked(); |
Craig Mautner | de4ef02 | 2013-04-07 19:01:33 -0700 | [diff] [blame] | 962 | } |
| 963 | } |
| 964 | return resumedActivity; |
| 965 | } |
| 966 | |
Dianne Hackborn | ff07272 | 2014-09-24 10:56:28 -0700 | [diff] [blame] | 967 | boolean attachApplicationLocked(ProcessRecord app) throws RemoteException { |
Craig Mautner | 20e7227 | 2013-04-01 13:45:53 -0700 | [diff] [blame] | 968 | final String processName = app.processName; |
Craig Mautner | 4a1cb22 | 2013-12-04 16:14:06 -0800 | [diff] [blame] | 969 | boolean didSomething = false; |
Craig Mautner | e0a3884 | 2013-12-16 16:14:02 -0800 | [diff] [blame] | 970 | for (int displayNdx = mActivityDisplays.size() - 1; displayNdx >= 0; --displayNdx) { |
Wale Ogunwale | a0f5b5e | 2017-10-11 09:37:23 -0700 | [diff] [blame] | 971 | final ActivityDisplay display = mActivityDisplays.valueAt(displayNdx); |
| 972 | for (int stackNdx = display.getChildCount() - 1; stackNdx >= 0; --stackNdx) { |
| 973 | final ActivityStack stack = display.getChildAt(stackNdx); |
Wale Ogunwale | 1e60e0c | 2015-10-28 13:36:10 -0700 | [diff] [blame] | 974 | if (!isFocusedStack(stack)) { |
Craig Mautner | 4a1cb22 | 2013-12-04 16:14:06 -0800 | [diff] [blame] | 975 | continue; |
| 976 | } |
Jorim Jaggi | ea039a8 | 2017-08-02 14:37:49 +0200 | [diff] [blame] | 977 | stack.getAllRunningVisibleActivitiesLocked(mTmpActivityList); |
| 978 | final ActivityRecord top = stack.topRunningActivityLocked(); |
| 979 | final int size = mTmpActivityList.size(); |
| 980 | for (int i = 0; i < size; i++) { |
| 981 | final ActivityRecord activity = mTmpActivityList.get(i); |
| 982 | if (activity.app == null && app.uid == activity.info.applicationInfo.uid |
| 983 | && processName.equals(activity.processName)) { |
Craig Mautner | 4a1cb22 | 2013-12-04 16:14:06 -0800 | [diff] [blame] | 984 | try { |
Jorim Jaggi | ea039a8 | 2017-08-02 14:37:49 +0200 | [diff] [blame] | 985 | if (realStartActivityLocked(activity, app, |
| 986 | top == activity /* andResume */, true /* checkConfig */)) { |
Craig Mautner | 4a1cb22 | 2013-12-04 16:14:06 -0800 | [diff] [blame] | 987 | didSomething = true; |
| 988 | } |
Dianne Hackborn | ff07272 | 2014-09-24 10:56:28 -0700 | [diff] [blame] | 989 | } catch (RemoteException e) { |
Craig Mautner | 4a1cb22 | 2013-12-04 16:14:06 -0800 | [diff] [blame] | 990 | Slog.w(TAG, "Exception in new application when starting activity " |
Jorim Jaggi | ea039a8 | 2017-08-02 14:37:49 +0200 | [diff] [blame] | 991 | + top.intent.getComponent().flattenToShortString(), e); |
Craig Mautner | 4a1cb22 | 2013-12-04 16:14:06 -0800 | [diff] [blame] | 992 | throw e; |
Craig Mautner | 20e7227 | 2013-04-01 13:45:53 -0700 | [diff] [blame] | 993 | } |
Craig Mautner | 20e7227 | 2013-04-01 13:45:53 -0700 | [diff] [blame] | 994 | } |
Craig Mautner | 20e7227 | 2013-04-01 13:45:53 -0700 | [diff] [blame] | 995 | } |
| 996 | } |
| 997 | } |
Craig Mautner | b59dcfd | 2013-05-06 13:12:58 -0700 | [diff] [blame] | 998 | if (!didSomething) { |
Filip Gruszczynski | bc5a6c5 | 2015-09-22 13:13:24 -0700 | [diff] [blame] | 999 | ensureActivitiesVisibleLocked(null, 0, !PRESERVE_WINDOWS); |
Craig Mautner | b59dcfd | 2013-05-06 13:12:58 -0700 | [diff] [blame] | 1000 | } |
Craig Mautner | 20e7227 | 2013-04-01 13:45:53 -0700 | [diff] [blame] | 1001 | return didSomething; |
| 1002 | } |
| 1003 | |
| 1004 | boolean allResumedActivitiesIdle() { |
Craig Mautner | e0a3884 | 2013-12-16 16:14:02 -0800 | [diff] [blame] | 1005 | for (int displayNdx = mActivityDisplays.size() - 1; displayNdx >= 0; --displayNdx) { |
Wale Ogunwale | a0f5b5e | 2017-10-11 09:37:23 -0700 | [diff] [blame] | 1006 | final ActivityDisplay display = mActivityDisplays.valueAt(displayNdx); |
| 1007 | for (int stackNdx = display.getChildCount() - 1; stackNdx >= 0; --stackNdx) { |
| 1008 | final ActivityStack stack = display.getChildAt(stackNdx); |
Wale Ogunwale | 1e60e0c | 2015-10-28 13:36:10 -0700 | [diff] [blame] | 1009 | if (!isFocusedStack(stack) || stack.numActivities() == 0) { |
Craig Mautner | 4a1cb22 | 2013-12-04 16:14:06 -0800 | [diff] [blame] | 1010 | continue; |
| 1011 | } |
Bryce Lee | c4ab62a | 2018-03-05 14:19:26 -0800 | [diff] [blame] | 1012 | final ActivityRecord resumedActivity = stack.getResumedActivity(); |
Craig Mautner | 4a1cb22 | 2013-12-04 16:14:06 -0800 | [diff] [blame] | 1013 | if (resumedActivity == null || !resumedActivity.idle) { |
Wale Ogunwale | 0fc365c | 2015-05-25 19:35:42 -0700 | [diff] [blame] | 1014 | if (DEBUG_STATES) Slog.d(TAG_STATES, "allResumedActivitiesIdle: stack=" |
Craig Mautner | 34b73df | 2014-01-12 21:11:08 -0800 | [diff] [blame] | 1015 | + stack.mStackId + " " + resumedActivity + " not idle"); |
Craig Mautner | 4a1cb22 | 2013-12-04 16:14:06 -0800 | [diff] [blame] | 1016 | return false; |
| 1017 | } |
Craig Mautner | 20e7227 | 2013-04-01 13:45:53 -0700 | [diff] [blame] | 1018 | } |
| 1019 | } |
Wei Wang | 65c7a15 | 2016-06-02 18:51:22 -0700 | [diff] [blame] | 1020 | // Send launch end powerhint when idle |
Bryce Lee | d3624e1 | 2017-11-30 08:51:45 -0800 | [diff] [blame] | 1021 | sendPowerHintForLaunchEndIfNeeded(); |
Craig Mautner | 20e7227 | 2013-04-01 13:45:53 -0700 | [diff] [blame] | 1022 | return true; |
| 1023 | } |
| 1024 | |
Craig Mautner | de4ef02 | 2013-04-07 19:01:33 -0700 | [diff] [blame] | 1025 | boolean allResumedActivitiesComplete() { |
Craig Mautner | e0a3884 | 2013-12-16 16:14:02 -0800 | [diff] [blame] | 1026 | for (int displayNdx = mActivityDisplays.size() - 1; displayNdx >= 0; --displayNdx) { |
Wale Ogunwale | a0f5b5e | 2017-10-11 09:37:23 -0700 | [diff] [blame] | 1027 | final ActivityDisplay display = mActivityDisplays.valueAt(displayNdx); |
| 1028 | for (int stackNdx = display.getChildCount() - 1; stackNdx >= 0; --stackNdx) { |
| 1029 | final ActivityStack stack = display.getChildAt(stackNdx); |
Wale Ogunwale | 1e60e0c | 2015-10-28 13:36:10 -0700 | [diff] [blame] | 1030 | if (isFocusedStack(stack)) { |
Bryce Lee | c4ab62a | 2018-03-05 14:19:26 -0800 | [diff] [blame] | 1031 | final ActivityRecord r = stack.getResumedActivity(); |
Bryce Lee | 7ace395 | 2018-02-16 14:34:32 -0800 | [diff] [blame] | 1032 | if (r != null && !r.isState(RESUMED)) { |
Craig Mautner | 4a1cb22 | 2013-12-04 16:14:06 -0800 | [diff] [blame] | 1033 | return false; |
| 1034 | } |
Craig Mautner | de4ef02 | 2013-04-07 19:01:33 -0700 | [diff] [blame] | 1035 | } |
| 1036 | } |
| 1037 | } |
| 1038 | // 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] | 1039 | if (DEBUG_STACK) Slog.d(TAG_STACK, |
Craig Mautner | 4a1cb22 | 2013-12-04 16:14:06 -0800 | [diff] [blame] | 1040 | "allResumedActivitiesComplete: mLastFocusedStack changing from=" + |
| 1041 | mLastFocusedStack + " to=" + mFocusedStack); |
| 1042 | mLastFocusedStack = mFocusedStack; |
Craig Mautner | de4ef02 | 2013-04-07 19:01:33 -0700 | [diff] [blame] | 1043 | return true; |
| 1044 | } |
| 1045 | |
Wale Ogunwale | a0f5b5e | 2017-10-11 09:37:23 -0700 | [diff] [blame] | 1046 | private boolean allResumedActivitiesVisible() { |
riddle_hsu | db46d6b | 2015-04-01 18:58:07 +0800 | [diff] [blame] | 1047 | boolean foundResumed = false; |
Craig Mautner | e0a3884 | 2013-12-16 16:14:02 -0800 | [diff] [blame] | 1048 | for (int displayNdx = mActivityDisplays.size() - 1; displayNdx >= 0; --displayNdx) { |
Wale Ogunwale | a0f5b5e | 2017-10-11 09:37:23 -0700 | [diff] [blame] | 1049 | final ActivityDisplay display = mActivityDisplays.valueAt(displayNdx); |
| 1050 | for (int stackNdx = display.getChildCount() - 1; stackNdx >= 0; --stackNdx) { |
| 1051 | final ActivityStack stack = display.getChildAt(stackNdx); |
Bryce Lee | c4ab62a | 2018-03-05 14:19:26 -0800 | [diff] [blame] | 1052 | final ActivityRecord r = stack.getResumedActivity(); |
riddle_hsu | db46d6b | 2015-04-01 18:58:07 +0800 | [diff] [blame] | 1053 | if (r != null) { |
Bryce Lee | 4a19438 | 2017-04-04 14:32:48 -0700 | [diff] [blame] | 1054 | if (!r.nowVisible || mActivitiesWaitingForVisibleActivity.contains(r)) { |
riddle_hsu | db46d6b | 2015-04-01 18:58:07 +0800 | [diff] [blame] | 1055 | return false; |
| 1056 | } |
| 1057 | foundResumed = true; |
Craig Mautner | 4a1cb22 | 2013-12-04 16:14:06 -0800 | [diff] [blame] | 1058 | } |
Craig Mautner | de4ef02 | 2013-04-07 19:01:33 -0700 | [diff] [blame] | 1059 | } |
| 1060 | } |
riddle_hsu | db46d6b | 2015-04-01 18:58:07 +0800 | [diff] [blame] | 1061 | return foundResumed; |
Craig Mautner | de4ef02 | 2013-04-07 19:01:33 -0700 | [diff] [blame] | 1062 | } |
| 1063 | |
Craig Mautner | 2acc389 | 2013-09-23 10:28:14 -0700 | [diff] [blame] | 1064 | /** |
| 1065 | * Pause all activities in either all of the stacks or just the back stacks. |
| 1066 | * @param userLeaving Passed to pauseActivity() to indicate whether to call onUserLeaving(). |
Wale Ogunwale | 950faff | 2016-08-08 09:51:04 -0700 | [diff] [blame] | 1067 | * @param resuming The resuming activity. |
| 1068 | * @param dontWait The resuming activity isn't going to wait for all activities to be paused |
| 1069 | * before resuming. |
Craig Mautner | 2acc389 | 2013-09-23 10:28:14 -0700 | [diff] [blame] | 1070 | * @return true if any activity was paused as a result of this call. |
| 1071 | */ |
Wale Ogunwale | 950faff | 2016-08-08 09:51:04 -0700 | [diff] [blame] | 1072 | boolean pauseBackStacks(boolean userLeaving, ActivityRecord resuming, boolean dontWait) { |
Craig Mautner | cf910b0 | 2013-04-23 11:23:27 -0700 | [diff] [blame] | 1073 | boolean someActivityPaused = false; |
Craig Mautner | e0a3884 | 2013-12-16 16:14:02 -0800 | [diff] [blame] | 1074 | for (int displayNdx = mActivityDisplays.size() - 1; displayNdx >= 0; --displayNdx) { |
Wale Ogunwale | a0f5b5e | 2017-10-11 09:37:23 -0700 | [diff] [blame] | 1075 | final ActivityDisplay display = mActivityDisplays.valueAt(displayNdx); |
| 1076 | for (int stackNdx = display.getChildCount() - 1; stackNdx >= 0; --stackNdx) { |
| 1077 | final ActivityStack stack = display.getChildAt(stackNdx); |
Bryce Lee | c4ab62a | 2018-03-05 14:19:26 -0800 | [diff] [blame] | 1078 | if (!isFocusedStack(stack) && stack.getResumedActivity() != null) { |
Wale Ogunwale | 0fc365c | 2015-05-25 19:35:42 -0700 | [diff] [blame] | 1079 | if (DEBUG_STATES) Slog.d(TAG_STATES, "pauseBackStacks: stack=" + stack + |
Bryce Lee | c4ab62a | 2018-03-05 14:19:26 -0800 | [diff] [blame] | 1080 | " mResumedActivity=" + stack.getResumedActivity()); |
Dianne Hackborn | a4e102e | 2014-09-04 22:52:27 -0700 | [diff] [blame] | 1081 | someActivityPaused |= stack.startPausingLocked(userLeaving, false, resuming, |
| 1082 | dontWait); |
Craig Mautner | 4a1cb22 | 2013-12-04 16:14:06 -0800 | [diff] [blame] | 1083 | } |
Craig Mautner | cf910b0 | 2013-04-23 11:23:27 -0700 | [diff] [blame] | 1084 | } |
| 1085 | } |
| 1086 | return someActivityPaused; |
| 1087 | } |
| 1088 | |
Craig Mautner | de4ef02 | 2013-04-07 19:01:33 -0700 | [diff] [blame] | 1089 | boolean allPausedActivitiesComplete() { |
Craig Mautner | ac6f843 | 2013-07-17 13:24:59 -0700 | [diff] [blame] | 1090 | boolean pausing = true; |
Craig Mautner | e0a3884 | 2013-12-16 16:14:02 -0800 | [diff] [blame] | 1091 | for (int displayNdx = mActivityDisplays.size() - 1; displayNdx >= 0; --displayNdx) { |
Wale Ogunwale | a0f5b5e | 2017-10-11 09:37:23 -0700 | [diff] [blame] | 1092 | final ActivityDisplay display = mActivityDisplays.valueAt(displayNdx); |
| 1093 | for (int stackNdx = display.getChildCount() - 1; stackNdx >= 0; --stackNdx) { |
| 1094 | final ActivityStack stack = display.getChildAt(stackNdx); |
Craig Mautner | 4a1cb22 | 2013-12-04 16:14:06 -0800 | [diff] [blame] | 1095 | final ActivityRecord r = stack.mPausingActivity; |
Bryce Lee | 7ace395 | 2018-02-16 14:34:32 -0800 | [diff] [blame] | 1096 | if (r != null && !r.isState(PAUSED, STOPPED, STOPPING)) { |
Craig Mautner | 4a1cb22 | 2013-12-04 16:14:06 -0800 | [diff] [blame] | 1097 | if (DEBUG_STATES) { |
Wale Ogunwale | 0fc365c | 2015-05-25 19:35:42 -0700 | [diff] [blame] | 1098 | Slog.d(TAG_STATES, |
Bryce Lee | 7ace395 | 2018-02-16 14:34:32 -0800 | [diff] [blame] | 1099 | "allPausedActivitiesComplete: r=" + r + " state=" + r.getState()); |
Craig Mautner | 4a1cb22 | 2013-12-04 16:14:06 -0800 | [diff] [blame] | 1100 | pausing = false; |
| 1101 | } else { |
| 1102 | return false; |
| 1103 | } |
Craig Mautner | ac6f843 | 2013-07-17 13:24:59 -0700 | [diff] [blame] | 1104 | } |
Craig Mautner | de4ef02 | 2013-04-07 19:01:33 -0700 | [diff] [blame] | 1105 | } |
| 1106 | } |
Craig Mautner | ac6f843 | 2013-07-17 13:24:59 -0700 | [diff] [blame] | 1107 | return pausing; |
Craig Mautner | de4ef02 | 2013-04-07 19:01:33 -0700 | [diff] [blame] | 1108 | } |
| 1109 | |
Wale Ogunwale | 2be760d | 2016-02-17 11:16:10 -0800 | [diff] [blame] | 1110 | void cancelInitializingActivities() { |
| 1111 | for (int displayNdx = mActivityDisplays.size() - 1; displayNdx >= 0; --displayNdx) { |
Wale Ogunwale | a0f5b5e | 2017-10-11 09:37:23 -0700 | [diff] [blame] | 1112 | final ActivityDisplay display = mActivityDisplays.valueAt(displayNdx); |
| 1113 | for (int stackNdx = display.getChildCount() - 1; stackNdx >= 0; --stackNdx) { |
| 1114 | final ActivityStack stack = display.getChildAt(stackNdx); |
| 1115 | stack.cancelInitializingActivities(); |
Wale Ogunwale | 2be760d | 2016-02-17 11:16:10 -0800 | [diff] [blame] | 1116 | } |
| 1117 | } |
| 1118 | } |
| 1119 | |
Vishnu Nair | cf23504 | 2018-11-02 13:27:00 -0700 | [diff] [blame] | 1120 | void waitActivityVisible(ComponentName name, WaitResult result, long startTimeMs) { |
| 1121 | final WaitInfo waitInfo = new WaitInfo(name, result, startTimeMs); |
Bryce Lee | 4a19438 | 2017-04-04 14:32:48 -0700 | [diff] [blame] | 1122 | mWaitingForActivityVisible.add(waitInfo); |
| 1123 | } |
| 1124 | |
| 1125 | void cleanupActivity(ActivityRecord r) { |
| 1126 | // Make sure this record is no longer in the pending finishes list. |
| 1127 | // This could happen, for example, if we are trimming activities |
| 1128 | // down to the max limit while they are still waiting to finish. |
| 1129 | mFinishingActivities.remove(r); |
| 1130 | mActivitiesWaitingForVisibleActivity.remove(r); |
| 1131 | |
| 1132 | for (int i = mWaitingForActivityVisible.size() - 1; i >= 0; --i) { |
Wale Ogunwale | 3270f17 | 2017-04-26 07:29:42 -0700 | [diff] [blame] | 1133 | if (mWaitingForActivityVisible.get(i).matches(r.realActivity)) { |
Bryce Lee | 4a19438 | 2017-04-04 14:32:48 -0700 | [diff] [blame] | 1134 | mWaitingForActivityVisible.remove(i); |
| 1135 | } |
| 1136 | } |
| 1137 | } |
| 1138 | |
Craig Mautner | ce5f3cb | 2013-04-22 08:58:54 -0700 | [diff] [blame] | 1139 | void reportActivityVisibleLocked(ActivityRecord r) { |
Dianne Hackborn | 6cfbb71 | 2014-09-17 12:47:35 -0700 | [diff] [blame] | 1140 | sendWaitingVisibleReportLocked(r); |
Dianne Hackborn | 6cfbb71 | 2014-09-17 12:47:35 -0700 | [diff] [blame] | 1141 | } |
| 1142 | |
| 1143 | void sendWaitingVisibleReportLocked(ActivityRecord r) { |
| 1144 | boolean changed = false; |
Bryce Lee | 4a19438 | 2017-04-04 14:32:48 -0700 | [diff] [blame] | 1145 | for (int i = mWaitingForActivityVisible.size() - 1; i >= 0; --i) { |
| 1146 | final WaitInfo w = mWaitingForActivityVisible.get(i); |
Wale Ogunwale | 3270f17 | 2017-04-26 07:29:42 -0700 | [diff] [blame] | 1147 | if (w.matches(r.realActivity)) { |
Bryce Lee | 4a19438 | 2017-04-04 14:32:48 -0700 | [diff] [blame] | 1148 | final WaitResult result = w.getResult(); |
Dianne Hackborn | 6cfbb71 | 2014-09-17 12:47:35 -0700 | [diff] [blame] | 1149 | changed = true; |
Bryce Lee | 4a19438 | 2017-04-04 14:32:48 -0700 | [diff] [blame] | 1150 | result.timeout = false; |
| 1151 | result.who = w.getComponent(); |
Vishnu Nair | cf23504 | 2018-11-02 13:27:00 -0700 | [diff] [blame] | 1152 | result.totalTime = SystemClock.uptimeMillis() - w.getStartTime(); |
Bryce Lee | 4a19438 | 2017-04-04 14:32:48 -0700 | [diff] [blame] | 1153 | mWaitingForActivityVisible.remove(w); |
Craig Mautner | ce5f3cb | 2013-04-22 08:58:54 -0700 | [diff] [blame] | 1154 | } |
Craig Mautner | ce5f3cb | 2013-04-22 08:58:54 -0700 | [diff] [blame] | 1155 | } |
Dianne Hackborn | 6cfbb71 | 2014-09-17 12:47:35 -0700 | [diff] [blame] | 1156 | if (changed) { |
| 1157 | mService.notifyAll(); |
| 1158 | } |
Craig Mautner | ce5f3cb | 2013-04-22 08:58:54 -0700 | [diff] [blame] | 1159 | } |
| 1160 | |
Bryce Lee | 5f0e28f | 2018-01-30 16:00:03 -0800 | [diff] [blame] | 1161 | void reportWaitingActivityLaunchedIfNeeded(ActivityRecord r, int result) { |
| 1162 | if (mWaitingActivityLaunched.isEmpty()) { |
| 1163 | return; |
| 1164 | } |
| 1165 | |
| 1166 | if (result != START_DELIVERED_TO_TOP && result != START_TASK_TO_FRONT) { |
| 1167 | return; |
| 1168 | } |
| 1169 | |
Chong Zhang | 5022da3 | 2016-06-21 16:31:37 -0700 | [diff] [blame] | 1170 | boolean changed = false; |
Bryce Lee | 5f0e28f | 2018-01-30 16:00:03 -0800 | [diff] [blame] | 1171 | |
Chong Zhang | 5022da3 | 2016-06-21 16:31:37 -0700 | [diff] [blame] | 1172 | for (int i = mWaitingActivityLaunched.size() - 1; i >= 0; i--) { |
| 1173 | WaitResult w = mWaitingActivityLaunched.remove(i); |
| 1174 | if (w.who == null) { |
| 1175 | changed = true; |
Bryce Lee | 5f0e28f | 2018-01-30 16:00:03 -0800 | [diff] [blame] | 1176 | w.result = result; |
| 1177 | |
| 1178 | // Unlike START_TASK_TO_FRONT, When an intent is delivered to top, there |
| 1179 | // will be no followup launch signals. Assign the result and launched component. |
| 1180 | if (result == START_DELIVERED_TO_TOP) { |
| 1181 | w.who = r.realActivity; |
| 1182 | } |
Chong Zhang | 5022da3 | 2016-06-21 16:31:37 -0700 | [diff] [blame] | 1183 | } |
| 1184 | } |
Bryce Lee | 5f0e28f | 2018-01-30 16:00:03 -0800 | [diff] [blame] | 1185 | |
Chong Zhang | 5022da3 | 2016-06-21 16:31:37 -0700 | [diff] [blame] | 1186 | if (changed) { |
| 1187 | mService.notifyAll(); |
| 1188 | } |
| 1189 | } |
| 1190 | |
Vishnu Nair | cf23504 | 2018-11-02 13:27:00 -0700 | [diff] [blame] | 1191 | void reportActivityLaunchedLocked(boolean timeout, ActivityRecord r, long totalTime) { |
Dianne Hackborn | 6cfbb71 | 2014-09-17 12:47:35 -0700 | [diff] [blame] | 1192 | boolean changed = false; |
Craig Mautner | ce5f3cb | 2013-04-22 08:58:54 -0700 | [diff] [blame] | 1193 | for (int i = mWaitingActivityLaunched.size() - 1; i >= 0; i--) { |
Craig Mautner | c64f73e | 2013-04-24 16:44:56 -0700 | [diff] [blame] | 1194 | WaitResult w = mWaitingActivityLaunched.remove(i); |
Dianne Hackborn | 6cfbb71 | 2014-09-17 12:47:35 -0700 | [diff] [blame] | 1195 | if (w.who == null) { |
| 1196 | changed = true; |
| 1197 | w.timeout = timeout; |
| 1198 | if (r != null) { |
| 1199 | w.who = new ComponentName(r.info.packageName, r.info.name); |
| 1200 | } |
Dianne Hackborn | 6cfbb71 | 2014-09-17 12:47:35 -0700 | [diff] [blame] | 1201 | w.totalTime = totalTime; |
Chong Zhang | 5022da3 | 2016-06-21 16:31:37 -0700 | [diff] [blame] | 1202 | // Do not modify w.result. |
Craig Mautner | ce5f3cb | 2013-04-22 08:58:54 -0700 | [diff] [blame] | 1203 | } |
Craig Mautner | ce5f3cb | 2013-04-22 08:58:54 -0700 | [diff] [blame] | 1204 | } |
Dianne Hackborn | 6cfbb71 | 2014-09-17 12:47:35 -0700 | [diff] [blame] | 1205 | if (changed) { |
| 1206 | mService.notifyAll(); |
| 1207 | } |
Craig Mautner | ce5f3cb | 2013-04-22 08:58:54 -0700 | [diff] [blame] | 1208 | } |
| 1209 | |
Craig Mautner | 29219d9 | 2013-04-16 20:19:12 -0700 | [diff] [blame] | 1210 | ActivityRecord topRunningActivityLocked() { |
Bryce Lee | c961e0a | 2018-04-13 17:58:02 -0700 | [diff] [blame] | 1211 | return topRunningActivityLocked(false /* considerKeyguardState */); |
| 1212 | } |
| 1213 | |
| 1214 | /** |
| 1215 | * Returns the top running activity in the focused stack. In the case the focused stack has no |
| 1216 | * such activity, the next focusable stack on top of a display is returned. |
| 1217 | * @param considerKeyguardState Indicates whether the locked state should be considered. if |
| 1218 | * {@code true} and the keyguard is locked, only activities that |
| 1219 | * can be shown on top of the keyguard will be considered. |
| 1220 | * @return The top running activity. {@code null} if none is available. |
| 1221 | */ |
| 1222 | ActivityRecord topRunningActivityLocked(boolean considerKeyguardState) { |
Wale Ogunwale | d697cea | 2015-02-20 17:19:49 -0800 | [diff] [blame] | 1223 | final ActivityStack focusedStack = mFocusedStack; |
Filip Gruszczynski | 3e85ba2 | 2015-10-05 22:48:30 -0700 | [diff] [blame] | 1224 | ActivityRecord r = focusedStack.topRunningActivityLocked(); |
Bryce Lee | 8691896 | 2018-04-26 15:28:12 -0700 | [diff] [blame] | 1225 | if (r != null && isValidTopRunningActivity(r, considerKeyguardState)) { |
Craig Mautner | 1602ec2 | 2013-05-12 10:24:27 -0700 | [diff] [blame] | 1226 | return r; |
Craig Mautner | 29219d9 | 2013-04-16 20:19:12 -0700 | [diff] [blame] | 1227 | } |
Craig Mautner | 1602ec2 | 2013-05-12 10:24:27 -0700 | [diff] [blame] | 1228 | |
Andrii Kulian | 7318d63 | 2016-07-20 18:59:28 -0700 | [diff] [blame] | 1229 | // Look in other non-focused and non-home stacks. |
Andrii Kulian | 7d95df4 | 2017-02-15 10:11:48 -0800 | [diff] [blame] | 1230 | mWindowManager.getDisplaysInFocusOrder(mTmpOrderedDisplayIds); |
| 1231 | |
| 1232 | for (int i = mTmpOrderedDisplayIds.size() - 1; i >= 0; --i) { |
| 1233 | final int displayId = mTmpOrderedDisplayIds.get(i); |
Wale Ogunwale | a0f5b5e | 2017-10-11 09:37:23 -0700 | [diff] [blame] | 1234 | final ActivityDisplay display = mActivityDisplays.get(displayId); |
Bryce Lee | 4bc5ba3 | 2018-03-20 13:58:53 -0700 | [diff] [blame] | 1235 | |
| 1236 | // If WindowManagerService has encountered the display before we have, ignore as there |
| 1237 | // will be no stacks present and therefore no activities. |
| 1238 | if (display == null) { |
| 1239 | continue; |
| 1240 | } |
Bryce Lee | c961e0a | 2018-04-13 17:58:02 -0700 | [diff] [blame] | 1241 | |
| 1242 | // TODO: We probably want to consider the top fullscreen stack as we could have a pinned |
| 1243 | // stack on top. |
| 1244 | final ActivityStack topStack = display.getTopStack(); |
| 1245 | |
| 1246 | // Only consider focusable top stacks other than the current focused one. |
| 1247 | if (topStack == null || !topStack.isFocusable() || topStack == focusedStack) { |
| 1248 | continue; |
| 1249 | } |
| 1250 | |
| 1251 | final ActivityRecord topActivity = topStack.topRunningActivityLocked(); |
| 1252 | |
| 1253 | // Skip if no top activity. |
| 1254 | if (topActivity == null) { |
| 1255 | continue; |
| 1256 | } |
| 1257 | |
Bryce Lee | c961e0a | 2018-04-13 17:58:02 -0700 | [diff] [blame] | 1258 | |
| 1259 | // This activity can be considered the top running activity if we are not |
| 1260 | // considering the locked state, the keyguard isn't locked, or we can show when |
| 1261 | // locked. |
Bryce Lee | 8691896 | 2018-04-26 15:28:12 -0700 | [diff] [blame] | 1262 | if (isValidTopRunningActivity(topActivity, considerKeyguardState)) { |
Bryce Lee | c961e0a | 2018-04-13 17:58:02 -0700 | [diff] [blame] | 1263 | return topActivity; |
Craig Mautner | 29219d9 | 2013-04-16 20:19:12 -0700 | [diff] [blame] | 1264 | } |
| 1265 | } |
Bryce Lee | c961e0a | 2018-04-13 17:58:02 -0700 | [diff] [blame] | 1266 | |
Craig Mautner | 29219d9 | 2013-04-16 20:19:12 -0700 | [diff] [blame] | 1267 | return null; |
| 1268 | } |
| 1269 | |
Bryce Lee | 8691896 | 2018-04-26 15:28:12 -0700 | [diff] [blame] | 1270 | /** |
| 1271 | * Verifies an {@link ActivityRecord} can be the top activity based on keyguard state and |
| 1272 | * whether we are considering it. |
| 1273 | */ |
| 1274 | private boolean isValidTopRunningActivity(ActivityRecord record, |
| 1275 | boolean considerKeyguardState) { |
| 1276 | if (!considerKeyguardState) { |
| 1277 | return true; |
| 1278 | } |
| 1279 | |
| 1280 | final boolean keyguardLocked = getKeyguardController().isKeyguardLocked(); |
| 1281 | |
| 1282 | if (!keyguardLocked) { |
| 1283 | return true; |
| 1284 | } |
| 1285 | |
| 1286 | return record.canShowWhenLocked(); |
| 1287 | } |
| 1288 | |
Winson Chung | 61c9e5a | 2017-10-11 10:39:32 -0700 | [diff] [blame] | 1289 | @VisibleForTesting |
| 1290 | void getRunningTasks(int maxNum, List<RunningTaskInfo> list, |
| 1291 | @ActivityType int ignoreActivityType, @WindowingMode int ignoreWindowingMode, |
| 1292 | int callingUid, boolean allowed) { |
| 1293 | mRunningTasks.getTasks(maxNum, list, ignoreActivityType, ignoreWindowingMode, |
| 1294 | mActivityDisplays, callingUid, allowed); |
Craig Mautner | 20e7227 | 2013-04-01 13:45:53 -0700 | [diff] [blame] | 1295 | } |
| 1296 | |
Todd Kennedy | 7440f17 | 2015-12-09 14:31:22 -0800 | [diff] [blame] | 1297 | ActivityInfo resolveActivity(Intent intent, ResolveInfo rInfo, int startFlags, |
| 1298 | ProfilerInfo profilerInfo) { |
| 1299 | final ActivityInfo aInfo = rInfo != null ? rInfo.activityInfo : null; |
Craig Mautner | 23ac33b | 2013-04-01 16:26:35 -0700 | [diff] [blame] | 1300 | if (aInfo != null) { |
| 1301 | // Store the found target back into the intent, because now that |
| 1302 | // we have it we never want to do this again. For example, if the |
| 1303 | // user navigates back to this point in the history, we should |
| 1304 | // always restart the exact same activity. |
| 1305 | intent.setComponent(new ComponentName( |
| 1306 | aInfo.applicationInfo.packageName, aInfo.name)); |
| 1307 | |
| 1308 | // Don't debug things in the system process |
Man Cao | cfa78b2 | 2015-06-11 20:14:34 -0700 | [diff] [blame] | 1309 | if (!aInfo.processName.equals("system")) { |
| 1310 | if ((startFlags & ActivityManager.START_FLAG_DEBUG) != 0) { |
Chong Zhang | d25944e | 2016-06-09 16:15:27 -0700 | [diff] [blame] | 1311 | mService.setDebugApp(aInfo.processName, true, false); |
Craig Mautner | 23ac33b | 2013-04-01 16:26:35 -0700 | [diff] [blame] | 1312 | } |
Craig Mautner | 23ac33b | 2013-04-01 16:26:35 -0700 | [diff] [blame] | 1313 | |
Tamas Berghammer | df6cb28 | 2016-01-29 12:07:00 +0000 | [diff] [blame] | 1314 | if ((startFlags & ActivityManager.START_FLAG_NATIVE_DEBUGGING) != 0) { |
| 1315 | mService.setNativeDebuggingAppLocked(aInfo.applicationInfo, aInfo.processName); |
| 1316 | } |
| 1317 | |
Man Cao | cfa78b2 | 2015-06-11 20:14:34 -0700 | [diff] [blame] | 1318 | if ((startFlags & ActivityManager.START_FLAG_TRACK_ALLOCATION) != 0) { |
| 1319 | mService.setTrackAllocationApp(aInfo.applicationInfo, aInfo.processName); |
| 1320 | } |
| 1321 | |
| 1322 | if (profilerInfo != null) { |
Jeff Hao | 1b012d3 | 2014-08-20 10:35:34 -0700 | [diff] [blame] | 1323 | mService.setProfileApp(aInfo.applicationInfo, aInfo.processName, profilerInfo); |
Craig Mautner | 23ac33b | 2013-04-01 16:26:35 -0700 | [diff] [blame] | 1324 | } |
| 1325 | } |
Todd Kennedy | b3b43130 | 2017-03-20 16:05:48 -0700 | [diff] [blame] | 1326 | final String intentLaunchToken = intent.getLaunchToken(); |
| 1327 | if (aInfo.launchToken == null && intentLaunchToken != null) { |
| 1328 | aInfo.launchToken = intentLaunchToken; |
| 1329 | } |
Craig Mautner | 23ac33b | 2013-04-01 16:26:35 -0700 | [diff] [blame] | 1330 | } |
| 1331 | return aInfo; |
| 1332 | } |
| 1333 | |
Patrick Baumann | 7838027 | 2018-04-04 10:41:01 -0700 | [diff] [blame] | 1334 | ResolveInfo resolveIntent(Intent intent, String resolvedType, int userId, int flags, |
| 1335 | int filterCallingUid) { |
Todd Kennedy | 4d1de7d | 2017-02-23 10:32:18 -0800 | [diff] [blame] | 1336 | synchronized (mService) { |
Jorim Jaggi | ffe128d | 2017-11-30 13:54:36 +0100 | [diff] [blame] | 1337 | try { |
| 1338 | Trace.traceBegin(TRACE_TAG_ACTIVITY_MANAGER, "resolveIntent"); |
Patrick Baumann | 577d402 | 2018-01-31 16:55:10 +0000 | [diff] [blame] | 1339 | int modifiedFlags = flags |
| 1340 | | PackageManager.MATCH_DEFAULT_ONLY | ActivityManagerService.STOCK_PM_FLAGS; |
Patrick Baumann | 0da8537 | 2018-02-02 16:07:35 -0800 | [diff] [blame] | 1341 | if (intent.isWebIntent() |
Patrick Baumann | 577d402 | 2018-01-31 16:55:10 +0000 | [diff] [blame] | 1342 | || (intent.getFlags() & Intent.FLAG_ACTIVITY_MATCH_EXTERNAL) != 0) { |
| 1343 | modifiedFlags |= PackageManager.MATCH_INSTANT; |
| 1344 | } |
Jorim Jaggi | ffe128d | 2017-11-30 13:54:36 +0100 | [diff] [blame] | 1345 | |
Makoto Onuki | 1a34274 | 2018-04-26 14:56:59 -0700 | [diff] [blame] | 1346 | // In order to allow cross-profile lookup, we clear the calling identity here. |
| 1347 | // Note the binder identity won't affect the result, but filterCallingUid will. |
| 1348 | |
| 1349 | // Cross-user/profile call check are done at the entry points |
| 1350 | // (e.g. AMS.startActivityAsUser). |
| 1351 | final long token = Binder.clearCallingIdentity(); |
| 1352 | try { |
| 1353 | return mService.getPackageManagerInternalLocked().resolveIntent( |
| 1354 | intent, resolvedType, modifiedFlags, userId, true, filterCallingUid); |
| 1355 | } finally { |
| 1356 | Binder.restoreCallingIdentity(token); |
| 1357 | } |
Jorim Jaggi | ffe128d | 2017-11-30 13:54:36 +0100 | [diff] [blame] | 1358 | } finally { |
| 1359 | Trace.traceEnd(TRACE_TAG_ACTIVITY_MANAGER); |
| 1360 | } |
Todd Kennedy | 7440f17 | 2015-12-09 14:31:22 -0800 | [diff] [blame] | 1361 | } |
Todd Kennedy | 7440f17 | 2015-12-09 14:31:22 -0800 | [diff] [blame] | 1362 | } |
| 1363 | |
| 1364 | ActivityInfo resolveActivity(Intent intent, String resolvedType, int startFlags, |
Patrick Baumann | 7838027 | 2018-04-04 10:41:01 -0700 | [diff] [blame] | 1365 | ProfilerInfo profilerInfo, int userId, int filterCallingUid) { |
| 1366 | final ResolveInfo rInfo = resolveIntent(intent, resolvedType, userId, 0, filterCallingUid); |
Todd Kennedy | 7440f17 | 2015-12-09 14:31:22 -0800 | [diff] [blame] | 1367 | return resolveActivity(intent, rInfo, startFlags, profilerInfo); |
| 1368 | } |
| 1369 | |
Wale Ogunwale | 5658e4b | 2016-02-12 12:22:19 -0800 | [diff] [blame] | 1370 | final boolean realStartActivityLocked(ActivityRecord r, ProcessRecord app, |
| 1371 | boolean andResume, boolean checkConfig) throws RemoteException { |
| 1372 | |
| 1373 | if (!allPausedActivitiesComplete()) { |
| 1374 | // While there are activities pausing we skipping starting any new activities until |
| 1375 | // pauses are complete. NOTE: that we also do this for activities that are starting in |
| 1376 | // the paused state because they will first be resumed then paused on the client side. |
| 1377 | if (DEBUG_SWITCH || DEBUG_PAUSE || DEBUG_STATES) Slog.v(TAG_PAUSE, |
| 1378 | "realStartActivityLocked: Skipping start of r=" + r |
| 1379 | + " some activities pausing..."); |
| 1380 | return false; |
| 1381 | } |
Craig Mautner | 2420ead | 2013-04-01 17:13:20 -0700 | [diff] [blame] | 1382 | |
Bryce Lee | af691c0 | 2017-03-20 14:20:22 -0700 | [diff] [blame] | 1383 | final TaskRecord task = r.getTask(); |
Andrii Kulian | 02b7a83 | 2016-10-06 23:11:56 -0700 | [diff] [blame] | 1384 | final ActivityStack stack = task.getStack(); |
chaviw | 59b9885 | 2017-06-13 12:05:44 -0700 | [diff] [blame] | 1385 | |
| 1386 | beginDeferResume(); |
| 1387 | |
Craig Mautner | 2420ead | 2013-04-01 17:13:20 -0700 | [diff] [blame] | 1388 | try { |
chaviw | 59b9885 | 2017-06-13 12:05:44 -0700 | [diff] [blame] | 1389 | r.startFreezingScreenLocked(app, 0); |
| 1390 | |
| 1391 | // schedule launch ticks to collect information about slow apps. |
| 1392 | r.startLaunchTickingLocked(); |
| 1393 | |
Dianne Hackborn | 68a0633 | 2017-11-15 17:54:18 -0800 | [diff] [blame] | 1394 | r.setProcess(app); |
chaviw | 59b9885 | 2017-06-13 12:05:44 -0700 | [diff] [blame] | 1395 | |
Bryce Lee | 459c062 | 2018-03-19 11:04:01 -0700 | [diff] [blame] | 1396 | if (getKeyguardController().isKeyguardLocked()) { |
Jorim Jaggi | 838c245 | 2017-08-28 15:44:43 +0200 | [diff] [blame] | 1397 | r.notifyUnknownVisibilityLaunched(); |
| 1398 | } |
| 1399 | |
chaviw | 59b9885 | 2017-06-13 12:05:44 -0700 | [diff] [blame] | 1400 | // Have the window manager re-evaluate the orientation of the screen based on the new |
| 1401 | // activity order. Note that as a result of this, it can call back into the activity |
| 1402 | // manager with a new orientation. We don't care about that, because the activity is |
| 1403 | // not currently running so we are just restarting it anyway. |
| 1404 | if (checkConfig) { |
chaviw | 59b9885 | 2017-06-13 12:05:44 -0700 | [diff] [blame] | 1405 | // Deferring resume here because we're going to launch new activity shortly. |
| 1406 | // We don't want to perform a redundant launch of the same record while ensuring |
| 1407 | // configurations and trying to resume top activity of focused stack. |
Andrii Kulian | f4479ee | 2018-05-23 17:52:48 -0700 | [diff] [blame] | 1408 | ensureVisibilityAndConfig(r, r.getDisplayId(), |
| 1409 | false /* markFrozenIfConfigChanged */, true /* deferResume */); |
Craig Mautner | 2420ead | 2013-04-01 17:13:20 -0700 | [diff] [blame] | 1410 | } |
chaviw | 59b9885 | 2017-06-13 12:05:44 -0700 | [diff] [blame] | 1411 | |
| 1412 | if (r.getStack().checkKeyguardVisibility(r, true /* shouldBeVisible */, |
| 1413 | true /* isTop */)) { |
| 1414 | // We only set the visibility to true if the activity is allowed to be visible |
| 1415 | // based on |
| 1416 | // keyguard state. This avoids setting this into motion in window manager that is |
| 1417 | // later cancelled due to later calls to ensure visible activities that set |
| 1418 | // visibility back to false. |
| 1419 | r.setVisibility(true); |
Craig Mautner | 2420ead | 2013-04-01 17:13:20 -0700 | [diff] [blame] | 1420 | } |
chaviw | 59b9885 | 2017-06-13 12:05:44 -0700 | [diff] [blame] | 1421 | |
chaviw | 59b9885 | 2017-06-13 12:05:44 -0700 | [diff] [blame] | 1422 | final int applicationInfoUid = |
| 1423 | (r.info.applicationInfo != null) ? r.info.applicationInfo.uid : -1; |
| 1424 | if ((r.userId != app.userId) || (r.appInfo.uid != applicationInfoUid)) { |
| 1425 | Slog.wtf(TAG, |
| 1426 | "User ID for activity changing for " + r |
| 1427 | + " appInfo.uid=" + r.appInfo.uid |
| 1428 | + " info.ai.uid=" + applicationInfoUid |
| 1429 | + " old=" + r.app + " new=" + app); |
| 1430 | } |
| 1431 | |
| 1432 | app.waitingToKill = null; |
| 1433 | r.launchCount++; |
| 1434 | r.lastLaunchTime = SystemClock.uptimeMillis(); |
| 1435 | |
| 1436 | if (DEBUG_ALL) Slog.v(TAG, "Launching: " + r); |
| 1437 | |
| 1438 | int idx = app.activities.indexOf(r); |
| 1439 | if (idx < 0) { |
| 1440 | app.activities.add(r); |
| 1441 | } |
| 1442 | mService.updateLruProcessLocked(app, true, null); |
| 1443 | mService.updateOomAdjLocked(); |
| 1444 | |
Bryce Lee | 2b8e037 | 2018-04-05 17:01:37 -0700 | [diff] [blame] | 1445 | final LockTaskController lockTaskController = mService.getLockTaskController(); |
Charles He | ff9b4dff | 2017-09-22 10:18:37 +0100 | [diff] [blame] | 1446 | if (task.mLockTaskAuth == LOCK_TASK_AUTH_LAUNCHABLE |
| 1447 | || task.mLockTaskAuth == LOCK_TASK_AUTH_LAUNCHABLE_PRIV |
| 1448 | || (task.mLockTaskAuth == LOCK_TASK_AUTH_WHITELISTED |
Bryce Lee | 2b8e037 | 2018-04-05 17:01:37 -0700 | [diff] [blame] | 1449 | && lockTaskController.getLockTaskModeState() |
| 1450 | == LOCK_TASK_MODE_LOCKED)) { |
| 1451 | lockTaskController.startLockTaskMode(task, false, 0 /* blank UID */); |
chaviw | 59b9885 | 2017-06-13 12:05:44 -0700 | [diff] [blame] | 1452 | } |
| 1453 | |
| 1454 | try { |
| 1455 | if (app.thread == null) { |
| 1456 | throw new RemoteException(); |
| 1457 | } |
| 1458 | List<ResultInfo> results = null; |
| 1459 | List<ReferrerIntent> newIntents = null; |
| 1460 | if (andResume) { |
| 1461 | // We don't need to deliver new intents and/or set results if activity is going |
| 1462 | // to pause immediately after launch. |
| 1463 | results = r.results; |
| 1464 | newIntents = r.newIntents; |
| 1465 | } |
| 1466 | if (DEBUG_SWITCH) Slog.v(TAG_SWITCH, |
| 1467 | "Launching: " + r + " icicle=" + r.icicle + " with results=" + results |
| 1468 | + " newIntents=" + newIntents + " andResume=" + andResume); |
| 1469 | EventLog.writeEvent(EventLogTags.AM_RESTART_ACTIVITY, r.userId, |
| 1470 | System.identityHashCode(r), task.taskId, r.shortComponentName); |
Wale Ogunwale | 6fbde9f | 2017-08-24 07:24:12 -0700 | [diff] [blame] | 1471 | if (r.isActivityTypeHome()) { |
chaviw | 59b9885 | 2017-06-13 12:05:44 -0700 | [diff] [blame] | 1472 | // Home process is the root process of the task. |
| 1473 | mService.mHomeProcess = task.mActivities.get(0).app; |
| 1474 | } |
| 1475 | mService.notifyPackageUse(r.intent.getComponent().getPackageName(), |
| 1476 | PackageManager.NOTIFY_PACKAGE_USE_ACTIVITY); |
| 1477 | r.sleeping = false; |
| 1478 | r.forceNewConfig = false; |
Alan Viverette | b6a2573 | 2017-11-21 14:49:24 -0500 | [diff] [blame] | 1479 | mService.getAppWarningsLocked().onStartActivity(r); |
chaviw | 59b9885 | 2017-06-13 12:05:44 -0700 | [diff] [blame] | 1480 | mService.showAskCompatModeDialogLocked(r); |
| 1481 | r.compat = mService.compatibilityInfoForPackageLocked(r.info.applicationInfo); |
| 1482 | ProfilerInfo profilerInfo = null; |
| 1483 | if (mService.mProfileApp != null && mService.mProfileApp.equals(app.processName)) { |
| 1484 | if (mService.mProfileProc == null || mService.mProfileProc == app) { |
| 1485 | mService.mProfileProc = app; |
Andreas Gampe | 2b073a0 | 2017-06-22 17:28:57 -0700 | [diff] [blame] | 1486 | ProfilerInfo profilerInfoSvc = mService.mProfilerInfo; |
| 1487 | if (profilerInfoSvc != null && profilerInfoSvc.profileFile != null) { |
| 1488 | if (profilerInfoSvc.profileFd != null) { |
chaviw | 59b9885 | 2017-06-13 12:05:44 -0700 | [diff] [blame] | 1489 | try { |
Andreas Gampe | 2b073a0 | 2017-06-22 17:28:57 -0700 | [diff] [blame] | 1490 | profilerInfoSvc.profileFd = profilerInfoSvc.profileFd.dup(); |
chaviw | 59b9885 | 2017-06-13 12:05:44 -0700 | [diff] [blame] | 1491 | } catch (IOException e) { |
Andreas Gampe | 2b073a0 | 2017-06-22 17:28:57 -0700 | [diff] [blame] | 1492 | profilerInfoSvc.closeFd(); |
Craig Mautner | 2568c3a | 2015-03-26 14:22:34 -0700 | [diff] [blame] | 1493 | } |
| 1494 | } |
chaviw | 59b9885 | 2017-06-13 12:05:44 -0700 | [diff] [blame] | 1495 | |
Andreas Gampe | 2b073a0 | 2017-06-22 17:28:57 -0700 | [diff] [blame] | 1496 | profilerInfo = new ProfilerInfo(profilerInfoSvc); |
Craig Mautner | 2420ead | 2013-04-01 17:13:20 -0700 | [diff] [blame] | 1497 | } |
Craig Mautner | 2420ead | 2013-04-01 17:13:20 -0700 | [diff] [blame] | 1498 | } |
| 1499 | } |
Adam Powell | cfbe9be | 2013-11-06 14:58:58 -0800 | [diff] [blame] | 1500 | |
chaviw | 59b9885 | 2017-06-13 12:05:44 -0700 | [diff] [blame] | 1501 | app.hasShownUi = true; |
| 1502 | app.pendingUiClean = true; |
| 1503 | app.forceProcessStateUpTo(mService.mTopProcessState); |
| 1504 | // Because we could be starting an Activity in the system process this may not go |
| 1505 | // across a Binder interface which would create a new Configuration. Consequently |
| 1506 | // we have to always create a new Configuration here. |
Bryce Lee | a163b76 | 2017-01-24 11:05:01 -0800 | [diff] [blame] | 1507 | |
chaviw | 59b9885 | 2017-06-13 12:05:44 -0700 | [diff] [blame] | 1508 | final MergedConfiguration mergedConfiguration = new MergedConfiguration( |
| 1509 | mService.getGlobalConfiguration(), r.getMergedOverrideConfiguration()); |
| 1510 | r.setLastReportedConfiguration(mergedConfiguration); |
Bryce Lee | a163b76 | 2017-01-24 11:05:01 -0800 | [diff] [blame] | 1511 | |
chaviw | 59b9885 | 2017-06-13 12:05:44 -0700 | [diff] [blame] | 1512 | logIfTransactionTooLarge(r.intent, r.icicle); |
Andrii Kulian | 88e05cb | 2017-12-05 17:21:10 -0800 | [diff] [blame] | 1513 | |
| 1514 | |
| 1515 | // Create activity launch transaction. |
Andrii Kulian | 9c5ea9c | 2017-12-07 09:31:01 -0800 | [diff] [blame] | 1516 | final ClientTransaction clientTransaction = ClientTransaction.obtain(app.thread, |
Andrii Kulian | 88e05cb | 2017-12-05 17:21:10 -0800 | [diff] [blame] | 1517 | r.appToken); |
Andrii Kulian | 9c5ea9c | 2017-12-07 09:31:01 -0800 | [diff] [blame] | 1518 | clientTransaction.addCallback(LaunchActivityItem.obtain(new Intent(r.intent), |
chaviw | 59b9885 | 2017-06-13 12:05:44 -0700 | [diff] [blame] | 1519 | System.identityHashCode(r), r.info, |
| 1520 | // TODO: Have this take the merged configuration instead of separate global |
| 1521 | // and override configs. |
| 1522 | mergedConfiguration.getGlobalConfiguration(), |
| 1523 | mergedConfiguration.getOverrideConfiguration(), r.compat, |
| 1524 | r.launchedFromPackage, task.voiceInteractor, app.repProcState, r.icicle, |
Andrii Kulian | 88e05cb | 2017-12-05 17:21:10 -0800 | [diff] [blame] | 1525 | r.persistentState, results, newIntents, mService.isNextTransitionForward(), |
| 1526 | profilerInfo)); |
| 1527 | |
| 1528 | // Set desired final state. |
| 1529 | final ActivityLifecycleItem lifecycleItem; |
| 1530 | if (andResume) { |
Bryce Lee | 1d0d514 | 2018-04-12 10:35:07 -0700 | [diff] [blame] | 1531 | lifecycleItem = ResumeActivityItem.obtain(mService.isNextTransitionForward()); |
Andrii Kulian | 88e05cb | 2017-12-05 17:21:10 -0800 | [diff] [blame] | 1532 | } else { |
Bryce Lee | 1d0d514 | 2018-04-12 10:35:07 -0700 | [diff] [blame] | 1533 | lifecycleItem = PauseActivityItem.obtain(); |
Andrii Kulian | 88e05cb | 2017-12-05 17:21:10 -0800 | [diff] [blame] | 1534 | } |
| 1535 | clientTransaction.setLifecycleStateRequest(lifecycleItem); |
| 1536 | |
| 1537 | // Schedule transaction. |
Bryce Lee | b0f993f | 2018-03-02 15:38:01 -0800 | [diff] [blame] | 1538 | mService.getLifecycleManager().scheduleTransaction(clientTransaction); |
Andrii Kulian | 88e05cb | 2017-12-05 17:21:10 -0800 | [diff] [blame] | 1539 | |
Craig Mautner | 2420ead | 2013-04-01 17:13:20 -0700 | [diff] [blame] | 1540 | |
Dianne Hackborn | c8e4fad | 2018-05-04 11:31:09 -0700 | [diff] [blame] | 1541 | if ((app.info.privateFlags & ApplicationInfo.PRIVATE_FLAG_CANT_SAVE_STATE) != 0 |
| 1542 | && mService.mHasHeavyWeightFeature) { |
chaviw | 59b9885 | 2017-06-13 12:05:44 -0700 | [diff] [blame] | 1543 | // This may be a heavy-weight process! Note that the package |
| 1544 | // manager will ensure that only activity can run in the main |
| 1545 | // process of the .apk, which is the only thing that will be |
| 1546 | // considered heavy-weight. |
| 1547 | if (app.processName.equals(app.info.packageName)) { |
| 1548 | if (mService.mHeavyWeightProcess != null |
| 1549 | && mService.mHeavyWeightProcess != app) { |
| 1550 | Slog.w(TAG, "Starting new heavy weight process " + app |
| 1551 | + " when already running " |
| 1552 | + mService.mHeavyWeightProcess); |
| 1553 | } |
| 1554 | mService.mHeavyWeightProcess = app; |
| 1555 | Message msg = mService.mHandler.obtainMessage( |
| 1556 | ActivityManagerService.POST_HEAVY_NOTIFICATION_MSG); |
| 1557 | msg.obj = r; |
| 1558 | mService.mHandler.sendMessage(msg); |
Craig Mautner | 2420ead | 2013-04-01 17:13:20 -0700 | [diff] [blame] | 1559 | } |
Craig Mautner | 2420ead | 2013-04-01 17:13:20 -0700 | [diff] [blame] | 1560 | } |
Craig Mautner | 2420ead | 2013-04-01 17:13:20 -0700 | [diff] [blame] | 1561 | |
chaviw | 59b9885 | 2017-06-13 12:05:44 -0700 | [diff] [blame] | 1562 | } catch (RemoteException e) { |
| 1563 | if (r.launchFailed) { |
| 1564 | // This is the second time we failed -- finish activity |
| 1565 | // and give up. |
| 1566 | Slog.e(TAG, "Second failure launching " |
| 1567 | + r.intent.getComponent().flattenToShortString() |
| 1568 | + ", giving up", e); |
| 1569 | mService.appDiedLocked(app); |
| 1570 | stack.requestFinishActivityLocked(r.appToken, Activity.RESULT_CANCELED, null, |
| 1571 | "2nd-crash", false); |
| 1572 | return false; |
| 1573 | } |
Craig Mautner | 2420ead | 2013-04-01 17:13:20 -0700 | [diff] [blame] | 1574 | |
chaviw | 59b9885 | 2017-06-13 12:05:44 -0700 | [diff] [blame] | 1575 | // This is the first time we failed -- restart process and |
| 1576 | // retry. |
| 1577 | r.launchFailed = true; |
| 1578 | app.activities.remove(r); |
| 1579 | throw e; |
| 1580 | } |
| 1581 | } finally { |
| 1582 | endDeferResume(); |
Craig Mautner | 2420ead | 2013-04-01 17:13:20 -0700 | [diff] [blame] | 1583 | } |
| 1584 | |
| 1585 | r.launchFailed = false; |
| 1586 | if (stack.updateLRUListLocked(r)) { |
Filip Gruszczynski | 49b80af | 2015-09-24 09:04:26 -0700 | [diff] [blame] | 1587 | Slog.w(TAG, "Activity " + r + " being launched, but already in LRU list"); |
Craig Mautner | 2420ead | 2013-04-01 17:13:20 -0700 | [diff] [blame] | 1588 | } |
| 1589 | |
Andrii Kulian | b372da6 | 2018-01-18 10:46:24 -0800 | [diff] [blame] | 1590 | // TODO(lifecycler): Resume or pause requests are done as part of launch transaction, |
| 1591 | // so updating the state should be done accordingly. |
chaviw | 59b9885 | 2017-06-13 12:05:44 -0700 | [diff] [blame] | 1592 | if (andResume && readyToResume()) { |
Craig Mautner | 2420ead | 2013-04-01 17:13:20 -0700 | [diff] [blame] | 1593 | // As part of the process of launching, ActivityThread also performs |
| 1594 | // a resume. |
| 1595 | stack.minimalResumeActivityLocked(r); |
| 1596 | } else { |
Wale Ogunwale | d046a01 | 2015-12-24 13:05:59 -0800 | [diff] [blame] | 1597 | // 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] | 1598 | // 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] | 1599 | // current icicle and other state. |
Wale Ogunwale | 0fc365c | 2015-05-25 19:35:42 -0700 | [diff] [blame] | 1600 | if (DEBUG_STATES) Slog.v(TAG_STATES, |
Wale Ogunwale | d046a01 | 2015-12-24 13:05:59 -0800 | [diff] [blame] | 1601 | "Moving to PAUSED: " + r + " (starting in paused state)"); |
Bryce Lee | 7ace395 | 2018-02-16 14:34:32 -0800 | [diff] [blame] | 1602 | r.setState(PAUSED, "realStartActivityLocked"); |
Craig Mautner | 2420ead | 2013-04-01 17:13:20 -0700 | [diff] [blame] | 1603 | } |
| 1604 | |
| 1605 | // Launch the new version setup screen if needed. We do this -after- |
| 1606 | // launching the initial activity (that is, home), so that it can have |
| 1607 | // a chance to initialize itself while in the background, making the |
| 1608 | // switch back to it faster and look better. |
Wale Ogunwale | 1e60e0c | 2015-10-28 13:36:10 -0700 | [diff] [blame] | 1609 | if (isFocusedStack(stack)) { |
Bryce Lee | d3624e1 | 2017-11-30 08:51:45 -0800 | [diff] [blame] | 1610 | mService.getActivityStartController().startSetupActivity(); |
Craig Mautner | 2420ead | 2013-04-01 17:13:20 -0700 | [diff] [blame] | 1611 | } |
| 1612 | |
Dianne Hackborn | 465fa39 | 2014-09-14 14:21:18 -0700 | [diff] [blame] | 1613 | // Update any services we are bound to that might care about whether |
| 1614 | // their client may have activities. |
Wale Ogunwale | d6ac762 | 2016-05-26 09:02:25 -0700 | [diff] [blame] | 1615 | if (r.app != null) { |
| 1616 | mService.mServices.updateServiceConnectionActivitiesLocked(r.app); |
| 1617 | } |
Dianne Hackborn | 465fa39 | 2014-09-14 14:21:18 -0700 | [diff] [blame] | 1618 | |
Craig Mautner | 2420ead | 2013-04-01 17:13:20 -0700 | [diff] [blame] | 1619 | return true; |
| 1620 | } |
| 1621 | |
Andrii Kulian | f4479ee | 2018-05-23 17:52:48 -0700 | [diff] [blame] | 1622 | /** |
| 1623 | * Ensure all activities visibility, update orientation and configuration. |
Andrii Kulian | a39ae3e | 2018-05-31 12:43:54 -0700 | [diff] [blame] | 1624 | * |
| 1625 | * @param starting The currently starting activity or {@code null} if there is none. |
| 1626 | * @param displayId The id of the display where operation is executed. |
| 1627 | * @param markFrozenIfConfigChanged Whether to set {@link ActivityRecord#frozenBeforeDestroy} to |
| 1628 | * {@code true} if config changed. |
| 1629 | * @param deferResume Whether to defer resume while updating config. |
Andrii Kulian | 2f0d73c | 2018-06-15 14:32:04 -0700 | [diff] [blame] | 1630 | * @return 'true' if starting activity was kept or wasn't provided, 'false' if it was relaunched |
| 1631 | * because of configuration update. |
Andrii Kulian | f4479ee | 2018-05-23 17:52:48 -0700 | [diff] [blame] | 1632 | */ |
Andrii Kulian | a39ae3e | 2018-05-31 12:43:54 -0700 | [diff] [blame] | 1633 | boolean ensureVisibilityAndConfig(ActivityRecord starting, int displayId, |
Andrii Kulian | f4479ee | 2018-05-23 17:52:48 -0700 | [diff] [blame] | 1634 | boolean markFrozenIfConfigChanged, boolean deferResume) { |
| 1635 | // First ensure visibility without updating the config just yet. We need this to know what |
| 1636 | // activities are affecting configuration now. |
Andrii Kulian | a39ae3e | 2018-05-31 12:43:54 -0700 | [diff] [blame] | 1637 | // Passing null here for 'starting' param value, so that visibility of actual starting |
| 1638 | // activity will be properly updated. |
Andrii Kulian | f4479ee | 2018-05-23 17:52:48 -0700 | [diff] [blame] | 1639 | ensureActivitiesVisibleLocked(null /* starting */, 0 /* configChanges */, |
Andrii Kulian | a39ae3e | 2018-05-31 12:43:54 -0700 | [diff] [blame] | 1640 | false /* preserveWindows */, false /* notifyClients */); |
Andrii Kulian | f4479ee | 2018-05-23 17:52:48 -0700 | [diff] [blame] | 1641 | |
Andrii Kulian | 2f0d73c | 2018-06-15 14:32:04 -0700 | [diff] [blame] | 1642 | if (displayId == INVALID_DISPLAY) { |
| 1643 | // The caller didn't provide a valid display id, skip updating config. |
| 1644 | return true; |
| 1645 | } |
| 1646 | |
Andrii Kulian | f4479ee | 2018-05-23 17:52:48 -0700 | [diff] [blame] | 1647 | // Force-update the orientation from the WindowManager, since we need the true configuration |
| 1648 | // to send to the client now. |
| 1649 | final Configuration config = mWindowManager.updateOrientationFromAppTokens( |
| 1650 | getDisplayOverrideConfiguration(displayId), |
Andrii Kulian | a39ae3e | 2018-05-31 12:43:54 -0700 | [diff] [blame] | 1651 | starting != null && starting.mayFreezeScreenLocked(starting.app) |
| 1652 | ? starting.appToken : null, |
Andrii Kulian | 6cdcfe4 | 2018-05-23 17:59:43 -0700 | [diff] [blame] | 1653 | displayId, true /* forceUpdate */); |
Andrii Kulian | a39ae3e | 2018-05-31 12:43:54 -0700 | [diff] [blame] | 1654 | if (starting != null && markFrozenIfConfigChanged && config != null) { |
| 1655 | starting.frozenBeforeDestroy = true; |
Andrii Kulian | f4479ee | 2018-05-23 17:52:48 -0700 | [diff] [blame] | 1656 | } |
| 1657 | |
| 1658 | // Update the configuration of the activities on the display. |
Andrii Kulian | a39ae3e | 2018-05-31 12:43:54 -0700 | [diff] [blame] | 1659 | return mService.updateDisplayOverrideConfigurationLocked(config, starting, deferResume, |
| 1660 | displayId); |
Andrii Kulian | f4479ee | 2018-05-23 17:52:48 -0700 | [diff] [blame] | 1661 | } |
| 1662 | |
Sudheer Shanka | fab200f | 2017-05-17 20:41:53 -0700 | [diff] [blame] | 1663 | private void logIfTransactionTooLarge(Intent intent, Bundle icicle) { |
| 1664 | int extrasSize = 0; |
| 1665 | if (intent != null) { |
| 1666 | final Bundle extras = intent.getExtras(); |
| 1667 | if (extras != null) { |
| 1668 | extrasSize = extras.getSize(); |
| 1669 | } |
| 1670 | } |
| 1671 | int icicleSize = (icicle == null ? 0 : icicle.getSize()); |
| 1672 | if (extrasSize + icicleSize > 200000) { |
| 1673 | Slog.e(TAG, "Transaction too large, intent: " + intent + ", extras size: " + extrasSize |
| 1674 | + ", icicle size: " + icicleSize); |
| 1675 | } |
| 1676 | } |
| 1677 | |
Craig Mautner | e79d4268 | 2013-04-01 19:01:53 -0700 | [diff] [blame] | 1678 | void startSpecificActivityLocked(ActivityRecord r, |
George Mount | 2c92c97 | 2014-03-20 09:38:23 -0700 | [diff] [blame] | 1679 | boolean andResume, boolean checkConfig) { |
Craig Mautner | e79d4268 | 2013-04-01 19:01:53 -0700 | [diff] [blame] | 1680 | // Is this activity's application already running? |
| 1681 | ProcessRecord app = mService.getProcessRecordLocked(r.processName, |
Dianne Hackborn | 3bc8f78d | 2013-09-19 13:34:35 -0700 | [diff] [blame] | 1682 | r.info.applicationInfo.uid, true); |
Craig Mautner | e79d4268 | 2013-04-01 19:01:53 -0700 | [diff] [blame] | 1683 | |
Craig Mautner | e79d4268 | 2013-04-01 19:01:53 -0700 | [diff] [blame] | 1684 | if (app != null && app.thread != null) { |
| 1685 | try { |
Dianne Hackborn | 237cefb | 2013-10-22 18:45:27 -0700 | [diff] [blame] | 1686 | if ((r.info.flags&ActivityInfo.FLAG_MULTIPROCESS) == 0 |
| 1687 | || !"android".equals(r.info.packageName)) { |
| 1688 | // Don't add this if it is a platform component that is marked |
| 1689 | // to run in multiple processes, because this is actually |
| 1690 | // part of the framework so doesn't make sense to track as a |
| 1691 | // separate apk in the process. |
Patrick Baumann | c2def58 | 2018-04-04 12:14:15 -0700 | [diff] [blame] | 1692 | app.addPackage(r.info.packageName, r.info.applicationInfo.longVersionCode, |
Dianne Hackborn | f7097a5 | 2014-05-13 09:56:14 -0700 | [diff] [blame] | 1693 | mService.mProcessStats); |
Dianne Hackborn | 237cefb | 2013-10-22 18:45:27 -0700 | [diff] [blame] | 1694 | } |
George Mount | 2c92c97 | 2014-03-20 09:38:23 -0700 | [diff] [blame] | 1695 | realStartActivityLocked(r, app, andResume, checkConfig); |
Craig Mautner | e79d4268 | 2013-04-01 19:01:53 -0700 | [diff] [blame] | 1696 | return; |
| 1697 | } catch (RemoteException e) { |
| 1698 | Slog.w(TAG, "Exception when starting activity " |
| 1699 | + r.intent.getComponent().flattenToShortString(), e); |
| 1700 | } |
| 1701 | |
| 1702 | // If a dead object exception was thrown -- fall through to |
| 1703 | // restart the application. |
| 1704 | } |
| 1705 | |
| 1706 | mService.startProcessLocked(r.processName, r.info.applicationInfo, true, 0, |
Dianne Hackborn | 3bc8f78d | 2013-09-19 13:34:35 -0700 | [diff] [blame] | 1707 | "activity", r.intent.getComponent(), false, false, true); |
Craig Mautner | e79d4268 | 2013-04-01 19:01:53 -0700 | [diff] [blame] | 1708 | } |
| 1709 | |
Bryce Lee | d3624e1 | 2017-11-30 08:51:45 -0800 | [diff] [blame] | 1710 | void sendPowerHintForLaunchStartIfNeeded(boolean forceSend, ActivityRecord targetActivity) { |
| 1711 | boolean sendHint = forceSend; |
| 1712 | |
| 1713 | if (!sendHint) { |
| 1714 | // If not forced, send power hint when the activity's process is different than the |
| 1715 | // current resumed activity. |
| 1716 | final ActivityRecord resumedActivity = getResumedActivityLocked(); |
| 1717 | sendHint = resumedActivity == null |
| 1718 | || resumedActivity.app == null |
| 1719 | || !resumedActivity.app.equals(targetActivity.app); |
| 1720 | } |
| 1721 | |
| 1722 | if (sendHint && mService.mLocalPowerManager != null) { |
| 1723 | mService.mLocalPowerManager.powerHint(PowerHint.LAUNCH, 1); |
| 1724 | mPowerHintSent = true; |
| 1725 | } |
| 1726 | } |
| 1727 | |
| 1728 | void sendPowerHintForLaunchEndIfNeeded() { |
| 1729 | // Trigger launch power hint if activity is launched |
| 1730 | if (mPowerHintSent && mService.mLocalPowerManager != null) { |
| 1731 | mService.mLocalPowerManager.powerHint(PowerHint.LAUNCH, 0); |
| 1732 | mPowerHintSent = false; |
| 1733 | } |
| 1734 | } |
| 1735 | |
Filip Gruszczynski | 07a0e49 | 2015-12-17 14:16:38 -0800 | [diff] [blame] | 1736 | boolean checkStartAnyActivityPermission(Intent intent, ActivityInfo aInfo, |
Filip Gruszczynski | dc39490 | 2015-12-14 10:20:22 -0800 | [diff] [blame] | 1737 | String resultWho, int requestCode, int callingPid, int callingUid, |
Winson Chung | c9804e7 | 2018-05-15 11:01:44 -0700 | [diff] [blame] | 1738 | String callingPackage, boolean ignoreTargetSecurity, boolean launchingInTask, |
| 1739 | ProcessRecord callerApp, ActivityRecord resultRecord, ActivityStack resultStack) { |
| 1740 | final boolean isCallerRecents = mService.getRecentTasks() != null && |
| 1741 | mService.getRecentTasks().isCallerRecents(callingUid); |
Filip Gruszczynski | dc39490 | 2015-12-14 10:20:22 -0800 | [diff] [blame] | 1742 | final int startAnyPerm = mService.checkPermission(START_ANY_ACTIVITY, callingPid, |
| 1743 | callingUid); |
Winson Chung | c9804e7 | 2018-05-15 11:01:44 -0700 | [diff] [blame] | 1744 | if (startAnyPerm == PERMISSION_GRANTED || (isCallerRecents && launchingInTask)) { |
| 1745 | // If the caller has START_ANY_ACTIVITY, ignore all checks below. In addition, if the |
| 1746 | // caller is the recents component and we are specifically starting an activity in an |
| 1747 | // existing task, then also allow the activity to be fully relaunched. |
Filip Gruszczynski | dc39490 | 2015-12-14 10:20:22 -0800 | [diff] [blame] | 1748 | return true; |
| 1749 | } |
| 1750 | final int componentRestriction = getComponentRestrictionForCallingPackage( |
| 1751 | aInfo, callingPackage, callingPid, callingUid, ignoreTargetSecurity); |
| 1752 | final int actionRestriction = getActionRestrictionForCallingPackage( |
| 1753 | intent.getAction(), callingPackage, callingPid, callingUid); |
| 1754 | if (componentRestriction == ACTIVITY_RESTRICTION_PERMISSION |
| 1755 | || actionRestriction == ACTIVITY_RESTRICTION_PERMISSION) { |
| 1756 | if (resultRecord != null) { |
| 1757 | resultStack.sendActivityResultLocked(-1, |
| 1758 | resultRecord, resultWho, requestCode, |
| 1759 | Activity.RESULT_CANCELED, null); |
| 1760 | } |
| 1761 | final String msg; |
| 1762 | if (actionRestriction == ACTIVITY_RESTRICTION_PERMISSION) { |
| 1763 | msg = "Permission Denial: starting " + intent.toString() |
| 1764 | + " from " + callerApp + " (pid=" + callingPid |
| 1765 | + ", uid=" + callingUid + ")" + " with revoked permission " |
| 1766 | + ACTION_TO_RUNTIME_PERMISSION.get(intent.getAction()); |
| 1767 | } else if (!aInfo.exported) { |
| 1768 | msg = "Permission Denial: starting " + intent.toString() |
| 1769 | + " from " + callerApp + " (pid=" + callingPid |
| 1770 | + ", uid=" + callingUid + ")" |
| 1771 | + " not exported from uid " + aInfo.applicationInfo.uid; |
| 1772 | } else { |
| 1773 | msg = "Permission Denial: starting " + intent.toString() |
| 1774 | + " from " + callerApp + " (pid=" + callingPid |
| 1775 | + ", uid=" + callingUid + ")" |
| 1776 | + " requires " + aInfo.permission; |
| 1777 | } |
| 1778 | Slog.w(TAG, msg); |
| 1779 | throw new SecurityException(msg); |
| 1780 | } |
| 1781 | |
| 1782 | if (actionRestriction == ACTIVITY_RESTRICTION_APPOP) { |
| 1783 | final String message = "Appop Denial: starting " + intent.toString() |
| 1784 | + " from " + callerApp + " (pid=" + callingPid |
| 1785 | + ", uid=" + callingUid + ")" |
| 1786 | + " requires " + AppOpsManager.permissionToOp( |
| 1787 | ACTION_TO_RUNTIME_PERMISSION.get(intent.getAction())); |
| 1788 | Slog.w(TAG, message); |
| 1789 | return false; |
| 1790 | } else if (componentRestriction == ACTIVITY_RESTRICTION_APPOP) { |
| 1791 | final String message = "Appop Denial: starting " + intent.toString() |
| 1792 | + " from " + callerApp + " (pid=" + callingPid |
| 1793 | + ", uid=" + callingUid + ")" |
| 1794 | + " requires appop " + AppOpsManager.permissionToOp(aInfo.permission); |
| 1795 | Slog.w(TAG, message); |
| 1796 | return false; |
| 1797 | } |
Jorim Jaggi | 2adba07 | 2016-03-03 13:43:39 +0100 | [diff] [blame] | 1798 | |
Filip Gruszczynski | dc39490 | 2015-12-14 10:20:22 -0800 | [diff] [blame] | 1799 | return true; |
| 1800 | } |
| 1801 | |
Andrii Kulian | fb1bf69 | 2017-01-17 11:17:34 -0800 | [diff] [blame] | 1802 | /** Check if caller is allowed to launch activities on specified display. */ |
Andrii Kulian | 02689a7 | 2017-07-06 14:28:59 -0700 | [diff] [blame] | 1803 | boolean isCallerAllowedToLaunchOnDisplay(int callingPid, int callingUid, int launchDisplayId, |
| 1804 | ActivityInfo aInfo) { |
Andrii Kulian | fb1bf69 | 2017-01-17 11:17:34 -0800 | [diff] [blame] | 1805 | if (DEBUG_TASKS) Slog.d(TAG, "Launch on display check: displayId=" + launchDisplayId |
| 1806 | + " callingPid=" + callingPid + " callingUid=" + callingUid); |
| 1807 | |
Andrii Kulian | 02689a7 | 2017-07-06 14:28:59 -0700 | [diff] [blame] | 1808 | if (callingPid == -1 && callingUid == -1) { |
| 1809 | if (DEBUG_TASKS) Slog.d(TAG, "Launch on display check: no caller info, skip check"); |
| 1810 | return true; |
| 1811 | } |
| 1812 | |
Andrii Kulian | 62e6f25 | 2017-05-30 22:46:53 -0700 | [diff] [blame] | 1813 | final ActivityDisplay activityDisplay = getActivityDisplayOrCreateLocked(launchDisplayId); |
Andrii Kulian | fb1bf69 | 2017-01-17 11:17:34 -0800 | [diff] [blame] | 1814 | if (activityDisplay == null) { |
| 1815 | Slog.w(TAG, "Launch on display check: display not found"); |
| 1816 | return false; |
| 1817 | } |
| 1818 | |
Andrii Kulian | 02689a7 | 2017-07-06 14:28:59 -0700 | [diff] [blame] | 1819 | // Check if the caller has enough privileges to embed activities and launch to private |
| 1820 | // displays. |
Andrii Kulian | 3a95edc | 2017-06-28 16:21:07 -0700 | [diff] [blame] | 1821 | final int startAnyPerm = mService.checkPermission(INTERNAL_SYSTEM_WINDOW, callingPid, |
Andrii Kulian | 1cba31c | 2017-06-28 09:42:48 -0700 | [diff] [blame] | 1822 | callingUid); |
| 1823 | if (startAnyPerm == PERMISSION_GRANTED) { |
| 1824 | if (DEBUG_TASKS) Slog.d(TAG, "Launch on display check:" |
| 1825 | + " allow launch any on display"); |
| 1826 | return true; |
| 1827 | } |
| 1828 | |
Andrii Kulian | 8f07029 | 2017-09-12 22:56:49 -0700 | [diff] [blame] | 1829 | // Check if caller is already present on display |
| 1830 | final boolean uidPresentOnDisplay = activityDisplay.isUidPresent(callingUid); |
| 1831 | |
Andrii Kulian | 3c9ad07 | 2017-08-01 11:45:22 -0700 | [diff] [blame] | 1832 | final int displayOwnerUid = activityDisplay.mDisplay.getOwnerUid(); |
| 1833 | if (activityDisplay.mDisplay.getType() == TYPE_VIRTUAL && displayOwnerUid != SYSTEM_UID |
| 1834 | && displayOwnerUid != aInfo.applicationInfo.uid) { |
Andrii Kulian | 1cba31c | 2017-06-28 09:42:48 -0700 | [diff] [blame] | 1835 | // Limit launching on virtual displays, because their contents can be read from Surface |
| 1836 | // by apps that created them. |
Andrii Kulian | 02689a7 | 2017-07-06 14:28:59 -0700 | [diff] [blame] | 1837 | if ((aInfo.flags & ActivityInfo.FLAG_ALLOW_EMBEDDED) == 0) { |
| 1838 | if (DEBUG_TASKS) Slog.d(TAG, "Launch on display check:" |
| 1839 | + " disallow launch on virtual display for not-embedded activity."); |
| 1840 | return false; |
| 1841 | } |
Andrii Kulian | 3c9ad07 | 2017-08-01 11:45:22 -0700 | [diff] [blame] | 1842 | // Check if the caller is allowed to embed activities from other apps. |
| 1843 | if (mService.checkPermission(ACTIVITY_EMBEDDING, callingPid, callingUid) |
Andrii Kulian | 8f07029 | 2017-09-12 22:56:49 -0700 | [diff] [blame] | 1844 | == PERMISSION_DENIED && !uidPresentOnDisplay) { |
Andrii Kulian | 3c9ad07 | 2017-08-01 11:45:22 -0700 | [diff] [blame] | 1845 | if (DEBUG_TASKS) Slog.d(TAG, "Launch on display check:" |
| 1846 | + " disallow activity embedding without permission."); |
| 1847 | return false; |
| 1848 | } |
Andrii Kulian | 1cba31c | 2017-06-28 09:42:48 -0700 | [diff] [blame] | 1849 | } |
| 1850 | |
Andrii Kulian | fb1bf69 | 2017-01-17 11:17:34 -0800 | [diff] [blame] | 1851 | if (!activityDisplay.isPrivate()) { |
| 1852 | // Anyone can launch on a public display. |
| 1853 | if (DEBUG_TASKS) Slog.d(TAG, "Launch on display check:" |
| 1854 | + " allow launch on public display"); |
| 1855 | return true; |
| 1856 | } |
| 1857 | |
| 1858 | // Check if the caller is the owner of the display. |
Andrii Kulian | 3c9ad07 | 2017-08-01 11:45:22 -0700 | [diff] [blame] | 1859 | if (displayOwnerUid == callingUid) { |
Andrii Kulian | fb1bf69 | 2017-01-17 11:17:34 -0800 | [diff] [blame] | 1860 | if (DEBUG_TASKS) Slog.d(TAG, "Launch on display check:" |
| 1861 | + " allow launch for owner of the display"); |
| 1862 | return true; |
| 1863 | } |
| 1864 | |
Andrii Kulian | 8f07029 | 2017-09-12 22:56:49 -0700 | [diff] [blame] | 1865 | if (uidPresentOnDisplay) { |
Andrii Kulian | fb1bf69 | 2017-01-17 11:17:34 -0800 | [diff] [blame] | 1866 | if (DEBUG_TASKS) Slog.d(TAG, "Launch on display check:" |
| 1867 | + " allow launch for caller present on the display"); |
| 1868 | return true; |
| 1869 | } |
| 1870 | |
Andrii Kulian | fb1bf69 | 2017-01-17 11:17:34 -0800 | [diff] [blame] | 1871 | Slog.w(TAG, "Launch on display check: denied"); |
| 1872 | return false; |
| 1873 | } |
| 1874 | |
| 1875 | /** Update lists of UIDs that are present on displays and have access to them. */ |
| 1876 | void updateUIDsPresentOnDisplay() { |
| 1877 | mDisplayAccessUIDs.clear(); |
| 1878 | for (int displayNdx = mActivityDisplays.size() - 1; displayNdx >= 0; --displayNdx) { |
| 1879 | final ActivityDisplay activityDisplay = mActivityDisplays.valueAt(displayNdx); |
David Stevens | 82ea6cb | 2017-03-03 16:18:50 -0800 | [diff] [blame] | 1880 | // Only bother calculating the whitelist for private displays |
| 1881 | if (activityDisplay.isPrivate()) { |
| 1882 | mDisplayAccessUIDs.append( |
| 1883 | activityDisplay.mDisplayId, activityDisplay.getPresentUIDs()); |
| 1884 | } |
Andrii Kulian | fb1bf69 | 2017-01-17 11:17:34 -0800 | [diff] [blame] | 1885 | } |
| 1886 | // Store updated lists in DisplayManager. Callers from outside of AM should get them there. |
| 1887 | mDisplayManagerInternal.setDisplayAccessUIDs(mDisplayAccessUIDs); |
| 1888 | } |
| 1889 | |
Filip Gruszczynski | 07a0e49 | 2015-12-17 14:16:38 -0800 | [diff] [blame] | 1890 | UserInfo getUserInfo(int userId) { |
Clara Bayarri | f7fea16 | 2015-10-22 16:09:52 +0100 | [diff] [blame] | 1891 | final long identity = Binder.clearCallingIdentity(); |
| 1892 | try { |
| 1893 | return UserManager.get(mService.mContext).getUserInfo(userId); |
| 1894 | } finally { |
| 1895 | Binder.restoreCallingIdentity(identity); |
| 1896 | } |
| 1897 | } |
| 1898 | |
Svet Ganov | 99b6043 | 2015-06-27 13:15:22 -0700 | [diff] [blame] | 1899 | private int getComponentRestrictionForCallingPackage(ActivityInfo activityInfo, |
Dianne Hackborn | a7cfbe0 | 2015-07-16 10:52:52 -0700 | [diff] [blame] | 1900 | String callingPackage, int callingPid, int callingUid, boolean ignoreTargetSecurity) { |
Dianne Hackborn | a7cfbe0 | 2015-07-16 10:52:52 -0700 | [diff] [blame] | 1901 | if (!ignoreTargetSecurity && mService.checkComponentPermission(activityInfo.permission, |
| 1902 | callingPid, callingUid, activityInfo.applicationInfo.uid, activityInfo.exported) |
Andrii Kulian | 3c9ad07 | 2017-08-01 11:45:22 -0700 | [diff] [blame] | 1903 | == PERMISSION_DENIED) { |
Svet Ganov | 99b6043 | 2015-06-27 13:15:22 -0700 | [diff] [blame] | 1904 | return ACTIVITY_RESTRICTION_PERMISSION; |
| 1905 | } |
| 1906 | |
Christopher Tate | ff7add0 | 2015-08-17 10:23:22 -0700 | [diff] [blame] | 1907 | if (activityInfo.permission == null) { |
| 1908 | return ACTIVITY_RESTRICTION_NONE; |
| 1909 | } |
| 1910 | |
Svet Ganov | 99b6043 | 2015-06-27 13:15:22 -0700 | [diff] [blame] | 1911 | final int opCode = AppOpsManager.permissionToOpCode(activityInfo.permission); |
| 1912 | if (opCode == AppOpsManager.OP_NONE) { |
| 1913 | return ACTIVITY_RESTRICTION_NONE; |
| 1914 | } |
| 1915 | |
| 1916 | if (mService.mAppOpsService.noteOperation(opCode, callingUid, |
| 1917 | callingPackage) != AppOpsManager.MODE_ALLOWED) { |
Dianne Hackborn | a7cfbe0 | 2015-07-16 10:52:52 -0700 | [diff] [blame] | 1918 | if (!ignoreTargetSecurity) { |
| 1919 | return ACTIVITY_RESTRICTION_APPOP; |
| 1920 | } |
Svet Ganov | 99b6043 | 2015-06-27 13:15:22 -0700 | [diff] [blame] | 1921 | } |
| 1922 | |
| 1923 | return ACTIVITY_RESTRICTION_NONE; |
| 1924 | } |
| 1925 | |
Svetoslav | 7008b51 | 2015-06-24 18:47:07 -0700 | [diff] [blame] | 1926 | private int getActionRestrictionForCallingPackage(String action, |
| 1927 | String callingPackage, int callingPid, int callingUid) { |
| 1928 | if (action == null) { |
Svet Ganov | 99b6043 | 2015-06-27 13:15:22 -0700 | [diff] [blame] | 1929 | return ACTIVITY_RESTRICTION_NONE; |
Svetoslav | 7008b51 | 2015-06-24 18:47:07 -0700 | [diff] [blame] | 1930 | } |
| 1931 | |
| 1932 | String permission = ACTION_TO_RUNTIME_PERMISSION.get(action); |
| 1933 | if (permission == null) { |
Svet Ganov | 99b6043 | 2015-06-27 13:15:22 -0700 | [diff] [blame] | 1934 | return ACTIVITY_RESTRICTION_NONE; |
Svetoslav | 7008b51 | 2015-06-24 18:47:07 -0700 | [diff] [blame] | 1935 | } |
| 1936 | |
| 1937 | final PackageInfo packageInfo; |
| 1938 | try { |
| 1939 | packageInfo = mService.mContext.getPackageManager() |
| 1940 | .getPackageInfo(callingPackage, PackageManager.GET_PERMISSIONS); |
| 1941 | } catch (PackageManager.NameNotFoundException e) { |
| 1942 | Slog.i(TAG, "Cannot find package info for " + callingPackage); |
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 | if (!ArrayUtils.contains(packageInfo.requestedPermissions, permission)) { |
Svet Ganov | 99b6043 | 2015-06-27 13:15:22 -0700 | [diff] [blame] | 1947 | return ACTIVITY_RESTRICTION_NONE; |
Svetoslav | 7008b51 | 2015-06-24 18:47:07 -0700 | [diff] [blame] | 1948 | } |
| 1949 | |
Andrii Kulian | 3c9ad07 | 2017-08-01 11:45:22 -0700 | [diff] [blame] | 1950 | if (mService.checkPermission(permission, callingPid, callingUid) == PERMISSION_DENIED) { |
Svet Ganov | 99b6043 | 2015-06-27 13:15:22 -0700 | [diff] [blame] | 1951 | return ACTIVITY_RESTRICTION_PERMISSION; |
Svetoslav | 7008b51 | 2015-06-24 18:47:07 -0700 | [diff] [blame] | 1952 | } |
| 1953 | |
| 1954 | final int opCode = AppOpsManager.permissionToOpCode(permission); |
| 1955 | if (opCode == AppOpsManager.OP_NONE) { |
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 | |
| 1959 | if (mService.mAppOpsService.noteOperation(opCode, callingUid, |
| 1960 | callingPackage) != AppOpsManager.MODE_ALLOWED) { |
Svet Ganov | 99b6043 | 2015-06-27 13:15:22 -0700 | [diff] [blame] | 1961 | return ACTIVITY_RESTRICTION_APPOP; |
Svetoslav | 7008b51 | 2015-06-24 18:47:07 -0700 | [diff] [blame] | 1962 | } |
| 1963 | |
Svet Ganov | 99b6043 | 2015-06-27 13:15:22 -0700 | [diff] [blame] | 1964 | return ACTIVITY_RESTRICTION_NONE; |
Svetoslav | 7008b51 | 2015-06-24 18:47:07 -0700 | [diff] [blame] | 1965 | } |
| 1966 | |
Dianne Hackborn | 3d07c94 | 2015-03-13 18:02:54 -0700 | [diff] [blame] | 1967 | void setLaunchSource(int uid) { |
| 1968 | mLaunchingActivity.setWorkSource(new WorkSource(uid)); |
| 1969 | } |
| 1970 | |
Craig Mautner | 7ea5bd4 | 2013-07-05 15:27:08 -0700 | [diff] [blame] | 1971 | void acquireLaunchWakelock() { |
| 1972 | if (VALIDATE_WAKE_LOCK_CALLER && Binder.getCallingUid() != Process.myUid()) { |
| 1973 | throw new IllegalStateException("Calling must be system uid"); |
| 1974 | } |
| 1975 | mLaunchingActivity.acquire(); |
| 1976 | if (!mHandler.hasMessages(LAUNCH_TIMEOUT_MSG)) { |
| 1977 | // To be safe, don't allow the wake lock to be held for too long. |
| 1978 | mHandler.sendEmptyMessageDelayed(LAUNCH_TIMEOUT_MSG, LAUNCH_TIMEOUT); |
| 1979 | } |
| 1980 | } |
| 1981 | |
Craig Mautner | f3ea23a | 2015-01-13 09:37:08 -0800 | [diff] [blame] | 1982 | /** |
| 1983 | * Called when the frontmost task is idle. |
| 1984 | * @return the state of mService.mBooting before this was called. |
| 1985 | */ |
Andreas Gampe | a36dc62 | 2018-02-05 17:19:22 -0800 | [diff] [blame] | 1986 | @GuardedBy("mService") |
Craig Mautner | f3ea23a | 2015-01-13 09:37:08 -0800 | [diff] [blame] | 1987 | private boolean checkFinishBootingLocked() { |
| 1988 | final boolean booting = mService.mBooting; |
| 1989 | boolean enableScreen = false; |
| 1990 | mService.mBooting = false; |
| 1991 | if (!mService.mBooted) { |
| 1992 | mService.mBooted = true; |
| 1993 | enableScreen = true; |
| 1994 | } |
| 1995 | if (booting || enableScreen) { |
| 1996 | mService.postFinishBooting(booting, enableScreen); |
| 1997 | } |
| 1998 | return booting; |
| 1999 | } |
| 2000 | |
Craig Mautner | f333327 | 2013-04-22 10:55:53 -0700 | [diff] [blame] | 2001 | // Checked. |
Andreas Gampe | a36dc62 | 2018-02-05 17:19:22 -0800 | [diff] [blame] | 2002 | @GuardedBy("mService") |
Craig Mautner | f333327 | 2013-04-22 10:55:53 -0700 | [diff] [blame] | 2003 | final ActivityRecord activityIdleInternalLocked(final IBinder token, boolean fromTimeout, |
Winson Chung | 4dabf23 | 2017-01-25 13:25:22 -0800 | [diff] [blame] | 2004 | boolean processPausingActivities, Configuration config) { |
Wale Ogunwale | e23149f | 2015-03-06 15:39:44 -0800 | [diff] [blame] | 2005 | if (DEBUG_ALL) Slog.v(TAG, "Activity idle: " + token); |
Craig Mautner | f333327 | 2013-04-22 10:55:53 -0700 | [diff] [blame] | 2006 | |
Craig Mautner | f333327 | 2013-04-22 10:55:53 -0700 | [diff] [blame] | 2007 | ArrayList<ActivityRecord> finishes = null; |
Amith Yamasani | 37a40c2 | 2015-06-17 13:25:42 -0700 | [diff] [blame] | 2008 | ArrayList<UserState> startingUsers = null; |
Craig Mautner | f333327 | 2013-04-22 10:55:53 -0700 | [diff] [blame] | 2009 | int NS = 0; |
| 2010 | int NF = 0; |
Craig Mautner | f333327 | 2013-04-22 10:55:53 -0700 | [diff] [blame] | 2011 | boolean booting = false; |
Craig Mautner | f333327 | 2013-04-22 10:55:53 -0700 | [diff] [blame] | 2012 | boolean activityRemoved = false; |
| 2013 | |
Wale Ogunwale | 7d70117 | 2015-03-11 15:36:30 -0700 | [diff] [blame] | 2014 | ActivityRecord r = ActivityRecord.forTokenLocked(token); |
Craig Mautner | f333327 | 2013-04-22 10:55:53 -0700 | [diff] [blame] | 2015 | if (r != null) { |
Wale Ogunwale | 0fc365c | 2015-05-25 19:35:42 -0700 | [diff] [blame] | 2016 | if (DEBUG_IDLE) Slog.d(TAG_IDLE, "activityIdleInternalLocked: Callers=" |
| 2017 | + Debug.getCallers(4)); |
Craig Mautner | f333327 | 2013-04-22 10:55:53 -0700 | [diff] [blame] | 2018 | mHandler.removeMessages(IDLE_TIMEOUT_MSG, r); |
| 2019 | r.finishLaunchTickingLocked(); |
Craig Mautner | 7ea5bd4 | 2013-07-05 15:27:08 -0700 | [diff] [blame] | 2020 | if (fromTimeout) { |
Vishnu Nair | cf23504 | 2018-11-02 13:27:00 -0700 | [diff] [blame] | 2021 | reportActivityLaunchedLocked(fromTimeout, r, INVALID_DELAY); |
Craig Mautner | f333327 | 2013-04-22 10:55:53 -0700 | [diff] [blame] | 2022 | } |
Craig Mautner | 7ea5bd4 | 2013-07-05 15:27:08 -0700 | [diff] [blame] | 2023 | |
| 2024 | // This is a hack to semi-deal with a race condition |
| 2025 | // in the client where it can be constructed with a |
| 2026 | // newer configuration from when we asked it to launch. |
| 2027 | // We'll update with whatever configuration it now says |
| 2028 | // it used to launch. |
| 2029 | if (config != null) { |
Bryce Lee | a163b76 | 2017-01-24 11:05:01 -0800 | [diff] [blame] | 2030 | r.setLastReportedGlobalConfiguration(config); |
Craig Mautner | 7ea5bd4 | 2013-07-05 15:27:08 -0700 | [diff] [blame] | 2031 | } |
| 2032 | |
| 2033 | // We are now idle. If someone is waiting for a thumbnail from |
| 2034 | // us, we can now deliver. |
| 2035 | r.idle = true; |
| 2036 | |
Craig Mautner | 7ea5bd4 | 2013-07-05 15:27:08 -0700 | [diff] [blame] | 2037 | //Slog.i(TAG, "IDLE: mBooted=" + mBooted + ", fromTimeout=" + fromTimeout); |
Andrii Kulian | 02b7a83 | 2016-10-06 23:11:56 -0700 | [diff] [blame] | 2038 | if (isFocusedStack(r.getStack()) || fromTimeout) { |
Craig Mautner | f3ea23a | 2015-01-13 09:37:08 -0800 | [diff] [blame] | 2039 | booting = checkFinishBootingLocked(); |
Craig Mautner | 7ea5bd4 | 2013-07-05 15:27:08 -0700 | [diff] [blame] | 2040 | } |
| 2041 | } |
| 2042 | |
| 2043 | if (allResumedActivitiesIdle()) { |
| 2044 | if (r != null) { |
| 2045 | mService.scheduleAppGcsLocked(); |
Craig Mautner | 7ea5bd4 | 2013-07-05 15:27:08 -0700 | [diff] [blame] | 2046 | } |
| 2047 | |
| 2048 | if (mLaunchingActivity.isHeld()) { |
| 2049 | mHandler.removeMessages(LAUNCH_TIMEOUT_MSG); |
| 2050 | if (VALIDATE_WAKE_LOCK_CALLER && |
| 2051 | Binder.getCallingUid() != Process.myUid()) { |
| 2052 | throw new IllegalStateException("Calling must be system uid"); |
| 2053 | } |
| 2054 | mLaunchingActivity.release(); |
| 2055 | } |
Filip Gruszczynski | bc5a6c5 | 2015-09-22 13:13:24 -0700 | [diff] [blame] | 2056 | ensureActivitiesVisibleLocked(null, 0, !PRESERVE_WINDOWS); |
Craig Mautner | f333327 | 2013-04-22 10:55:53 -0700 | [diff] [blame] | 2057 | } |
| 2058 | |
| 2059 | // Atomically retrieve all of the other things to do. |
Winson Chung | 4dabf23 | 2017-01-25 13:25:22 -0800 | [diff] [blame] | 2060 | final ArrayList<ActivityRecord> stops = processStoppingActivitiesLocked(r, |
| 2061 | true /* remove */, processPausingActivities); |
Craig Mautner | f333327 | 2013-04-22 10:55:53 -0700 | [diff] [blame] | 2062 | NS = stops != null ? stops.size() : 0; |
Wale Ogunwale | 7d70117 | 2015-03-11 15:36:30 -0700 | [diff] [blame] | 2063 | if ((NF = mFinishingActivities.size()) > 0) { |
| 2064 | finishes = new ArrayList<>(mFinishingActivities); |
Craig Mautner | f333327 | 2013-04-22 10:55:53 -0700 | [diff] [blame] | 2065 | mFinishingActivities.clear(); |
| 2066 | } |
| 2067 | |
Craig Mautner | f333327 | 2013-04-22 10:55:53 -0700 | [diff] [blame] | 2068 | if (mStartingUsers.size() > 0) { |
Wale Ogunwale | 7d70117 | 2015-03-11 15:36:30 -0700 | [diff] [blame] | 2069 | startingUsers = new ArrayList<>(mStartingUsers); |
Craig Mautner | f333327 | 2013-04-22 10:55:53 -0700 | [diff] [blame] | 2070 | mStartingUsers.clear(); |
| 2071 | } |
| 2072 | |
Craig Mautner | f333327 | 2013-04-22 10:55:53 -0700 | [diff] [blame] | 2073 | // Stop any activities that are scheduled to do so but have been |
| 2074 | // waiting for the next one to start. |
| 2075 | for (int i = 0; i < NS; i++) { |
| 2076 | r = stops.get(i); |
Andrii Kulian | 02b7a83 | 2016-10-06 23:11:56 -0700 | [diff] [blame] | 2077 | final ActivityStack stack = r.getStack(); |
Wale Ogunwale | 7d70117 | 2015-03-11 15:36:30 -0700 | [diff] [blame] | 2078 | if (stack != null) { |
| 2079 | if (r.finishing) { |
Bryce Lee | f52974c | 2018-02-14 15:12:01 -0800 | [diff] [blame] | 2080 | stack.finishCurrentActivityLocked(r, ActivityStack.FINISH_IMMEDIATELY, false, |
| 2081 | "activityIdleInternalLocked"); |
Wale Ogunwale | 7d70117 | 2015-03-11 15:36:30 -0700 | [diff] [blame] | 2082 | } else { |
| 2083 | stack.stopActivityLocked(r); |
| 2084 | } |
Craig Mautner | f333327 | 2013-04-22 10:55:53 -0700 | [diff] [blame] | 2085 | } |
| 2086 | } |
| 2087 | |
| 2088 | // Finish any activities that are scheduled to do so but have been |
| 2089 | // waiting for the next one to start. |
| 2090 | for (int i = 0; i < NF; i++) { |
| 2091 | r = finishes.get(i); |
Andrii Kulian | 02b7a83 | 2016-10-06 23:11:56 -0700 | [diff] [blame] | 2092 | final ActivityStack stack = r.getStack(); |
Wale Ogunwale | 7d70117 | 2015-03-11 15:36:30 -0700 | [diff] [blame] | 2093 | if (stack != null) { |
| 2094 | activityRemoved |= stack.destroyActivityLocked(r, true, "finish-idle"); |
| 2095 | } |
Craig Mautner | f333327 | 2013-04-22 10:55:53 -0700 | [diff] [blame] | 2096 | } |
| 2097 | |
Dianne Hackborn | 7622a0f | 2014-09-30 14:31:42 -0700 | [diff] [blame] | 2098 | if (!booting) { |
Amith Yamasani | 1a7eaaa5 | 2014-05-07 10:22:15 -0700 | [diff] [blame] | 2099 | // Complete user switch |
| 2100 | if (startingUsers != null) { |
| 2101 | for (int i = 0; i < startingUsers.size(); i++) { |
Fyodor Kupolov | 610acda | 2015-10-19 18:44:07 -0700 | [diff] [blame] | 2102 | mService.mUserController.finishUserSwitch(startingUsers.get(i)); |
Amith Yamasani | 1a7eaaa5 | 2014-05-07 10:22:15 -0700 | [diff] [blame] | 2103 | } |
| 2104 | } |
Craig Mautner | f333327 | 2013-04-22 10:55:53 -0700 | [diff] [blame] | 2105 | } |
| 2106 | |
| 2107 | mService.trimApplications(); |
| 2108 | //dump(); |
| 2109 | //mWindowManager.dump(); |
| 2110 | |
Craig Mautner | f333327 | 2013-04-22 10:55:53 -0700 | [diff] [blame] | 2111 | if (activityRemoved) { |
Wale Ogunwale | d046a01 | 2015-12-24 13:05:59 -0800 | [diff] [blame] | 2112 | resumeFocusedStackTopActivityLocked(); |
Craig Mautner | f333327 | 2013-04-22 10:55:53 -0700 | [diff] [blame] | 2113 | } |
| 2114 | |
Craig Mautner | 7ea5bd4 | 2013-07-05 15:27:08 -0700 | [diff] [blame] | 2115 | return r; |
Craig Mautner | f333327 | 2013-04-22 10:55:53 -0700 | [diff] [blame] | 2116 | } |
| 2117 | |
Craig Mautner | 8e56957 | 2013-10-11 17:36:59 -0700 | [diff] [blame] | 2118 | boolean handleAppDiedLocked(ProcessRecord app) { |
Craig Mautner | 1909125 | 2013-10-05 00:03:53 -0700 | [diff] [blame] | 2119 | boolean hasVisibleActivities = false; |
Craig Mautner | e0a3884 | 2013-12-16 16:14:02 -0800 | [diff] [blame] | 2120 | for (int displayNdx = mActivityDisplays.size() - 1; displayNdx >= 0; --displayNdx) { |
Wale Ogunwale | a0f5b5e | 2017-10-11 09:37:23 -0700 | [diff] [blame] | 2121 | final ActivityDisplay display = mActivityDisplays.valueAt(displayNdx); |
| 2122 | for (int stackNdx = display.getChildCount() - 1; stackNdx >= 0; --stackNdx) { |
| 2123 | final ActivityStack stack = display.getChildAt(stackNdx); |
| 2124 | hasVisibleActivities |= stack.handleAppDiedLocked(app); |
Craig Mautner | 4a1cb22 | 2013-12-04 16:14:06 -0800 | [diff] [blame] | 2125 | } |
Craig Mautner | 6b74cb5 | 2013-09-27 17:02:21 -0700 | [diff] [blame] | 2126 | } |
Craig Mautner | 1909125 | 2013-10-05 00:03:53 -0700 | [diff] [blame] | 2127 | return hasVisibleActivities; |
Craig Mautner | 8d341ef | 2013-03-26 09:03:27 -0700 | [diff] [blame] | 2128 | } |
| 2129 | |
| 2130 | void closeSystemDialogsLocked() { |
Craig Mautner | e0a3884 | 2013-12-16 16:14:02 -0800 | [diff] [blame] | 2131 | for (int displayNdx = mActivityDisplays.size() - 1; displayNdx >= 0; --displayNdx) { |
Wale Ogunwale | a0f5b5e | 2017-10-11 09:37:23 -0700 | [diff] [blame] | 2132 | final ActivityDisplay display = mActivityDisplays.valueAt(displayNdx); |
| 2133 | for (int stackNdx = display.getChildCount() - 1; stackNdx >= 0; --stackNdx) { |
| 2134 | final ActivityStack stack = display.getChildAt(stackNdx); |
| 2135 | stack.closeSystemDialogsLocked(); |
Craig Mautner | 4a1cb22 | 2013-12-04 16:14:06 -0800 | [diff] [blame] | 2136 | } |
Craig Mautner | 8d341ef | 2013-03-26 09:03:27 -0700 | [diff] [blame] | 2137 | } |
| 2138 | } |
| 2139 | |
Craig Mautner | 93529a4 | 2013-10-04 15:03:13 -0700 | [diff] [blame] | 2140 | void removeUserLocked(int userId) { |
Craig Mautner | 4f1df4f | 2013-10-15 15:44:14 -0700 | [diff] [blame] | 2141 | mUserStackInFront.delete(userId); |
Craig Mautner | 93529a4 | 2013-10-04 15:03:13 -0700 | [diff] [blame] | 2142 | } |
| 2143 | |
Craig Mautner | 8d341ef | 2013-03-26 09:03:27 -0700 | [diff] [blame] | 2144 | /** |
Chong Zhang | 45c25ce | 2015-08-10 22:18:26 -0700 | [diff] [blame] | 2145 | * Update the last used stack id for non-current user (current user's last |
| 2146 | * used stack is the focused stack) |
| 2147 | */ |
| 2148 | void updateUserStackLocked(int userId, ActivityStack stack) { |
| 2149 | if (userId != mCurrentUser) { |
Wale Ogunwale | 6827856 | 2017-09-23 17:13:55 -0700 | [diff] [blame] | 2150 | mUserStackInFront.put(userId, stack != null ? stack.getStackId() : mHomeStack.mStackId); |
Chong Zhang | 45c25ce | 2015-08-10 22:18:26 -0700 | [diff] [blame] | 2151 | } |
| 2152 | } |
| 2153 | |
| 2154 | /** |
Craig Mautner | 8d341ef | 2013-03-26 09:03:27 -0700 | [diff] [blame] | 2155 | * @return true if some activity was finished (or would have finished if doit were true). |
| 2156 | */ |
Wale Ogunwale | 540e123 | 2015-05-01 15:35:39 -0700 | [diff] [blame] | 2157 | boolean finishDisabledPackageActivitiesLocked(String packageName, Set<String> filterByClasses, |
| 2158 | boolean doit, boolean evenPersistent, int userId) { |
Craig Mautner | 8d341ef | 2013-03-26 09:03:27 -0700 | [diff] [blame] | 2159 | boolean didSomething = false; |
Craig Mautner | e0a3884 | 2013-12-16 16:14:02 -0800 | [diff] [blame] | 2160 | for (int displayNdx = mActivityDisplays.size() - 1; displayNdx >= 0; --displayNdx) { |
Wale Ogunwale | a0f5b5e | 2017-10-11 09:37:23 -0700 | [diff] [blame] | 2161 | final ActivityDisplay display = mActivityDisplays.valueAt(displayNdx); |
| 2162 | for (int stackNdx = display.getChildCount() - 1; stackNdx >= 0; --stackNdx) { |
| 2163 | final ActivityStack stack = display.getChildAt(stackNdx); |
Wale Ogunwale | 540e123 | 2015-05-01 15:35:39 -0700 | [diff] [blame] | 2164 | if (stack.finishDisabledPackageActivitiesLocked( |
| 2165 | packageName, filterByClasses, doit, evenPersistent, userId)) { |
Craig Mautner | 4a1cb22 | 2013-12-04 16:14:06 -0800 | [diff] [blame] | 2166 | didSomething = true; |
| 2167 | } |
Craig Mautner | 8d341ef | 2013-03-26 09:03:27 -0700 | [diff] [blame] | 2168 | } |
| 2169 | } |
| 2170 | return didSomething; |
| 2171 | } |
| 2172 | |
Dianne Hackborn | a413dc0 | 2013-07-12 12:02:55 -0700 | [diff] [blame] | 2173 | void updatePreviousProcessLocked(ActivityRecord r) { |
| 2174 | // Now that this process has stopped, we may want to consider |
| 2175 | // it to be the previous app to try to keep around in case |
| 2176 | // the user wants to return to it. |
| 2177 | |
| 2178 | // First, found out what is currently the foreground app, so that |
| 2179 | // we don't blow away the previous app if this activity is being |
| 2180 | // hosted by the process that is actually still the foreground. |
| 2181 | ProcessRecord fgApp = null; |
Craig Mautner | e0a3884 | 2013-12-16 16:14:02 -0800 | [diff] [blame] | 2182 | for (int displayNdx = mActivityDisplays.size() - 1; displayNdx >= 0; --displayNdx) { |
Wale Ogunwale | a0f5b5e | 2017-10-11 09:37:23 -0700 | [diff] [blame] | 2183 | final ActivityDisplay display = mActivityDisplays.valueAt(displayNdx); |
| 2184 | for (int stackNdx = display.getChildCount() - 1; stackNdx >= 0; --stackNdx) { |
| 2185 | final ActivityStack stack = display.getChildAt(stackNdx); |
Wale Ogunwale | 1e60e0c | 2015-10-28 13:36:10 -0700 | [diff] [blame] | 2186 | if (isFocusedStack(stack)) { |
Bryce Lee | c4ab62a | 2018-03-05 14:19:26 -0800 | [diff] [blame] | 2187 | final ActivityRecord resumedActivity = stack.getResumedActivity(); |
| 2188 | if (resumedActivity != null) { |
| 2189 | fgApp = resumedActivity.app; |
Craig Mautner | 4a1cb22 | 2013-12-04 16:14:06 -0800 | [diff] [blame] | 2190 | } else if (stack.mPausingActivity != null) { |
| 2191 | fgApp = stack.mPausingActivity.app; |
| 2192 | } |
| 2193 | break; |
Dianne Hackborn | a413dc0 | 2013-07-12 12:02:55 -0700 | [diff] [blame] | 2194 | } |
Dianne Hackborn | a413dc0 | 2013-07-12 12:02:55 -0700 | [diff] [blame] | 2195 | } |
| 2196 | } |
| 2197 | |
| 2198 | // Now set this one as the previous process, only if that really |
| 2199 | // makes sense to. |
| 2200 | if (r.app != null && fgApp != null && r.app != fgApp |
| 2201 | && r.lastVisibleTime > mService.mPreviousProcessVisibleTime |
Craig Mautner | 4ef2693 | 2013-09-18 15:15:52 -0700 | [diff] [blame] | 2202 | && r.app != mService.mHomeProcess) { |
Dianne Hackborn | a413dc0 | 2013-07-12 12:02:55 -0700 | [diff] [blame] | 2203 | mService.mPreviousProcess = r.app; |
| 2204 | mService.mPreviousProcessVisibleTime = r.lastVisibleTime; |
| 2205 | } |
| 2206 | } |
| 2207 | |
Wale Ogunwale | d046a01 | 2015-12-24 13:05:59 -0800 | [diff] [blame] | 2208 | boolean resumeFocusedStackTopActivityLocked() { |
| 2209 | return resumeFocusedStackTopActivityLocked(null, null, null); |
Craig Mautner | 05d2903 | 2013-05-03 13:40:13 -0700 | [diff] [blame] | 2210 | } |
| 2211 | |
Wale Ogunwale | d046a01 | 2015-12-24 13:05:59 -0800 | [diff] [blame] | 2212 | boolean resumeFocusedStackTopActivityLocked( |
Chong Zhang | 280d332 | 2015-11-03 17:27:26 -0800 | [diff] [blame] | 2213 | ActivityStack targetStack, ActivityRecord target, ActivityOptions targetOptions) { |
chaviw | 59b9885 | 2017-06-13 12:05:44 -0700 | [diff] [blame] | 2214 | |
| 2215 | if (!readyToResume()) { |
| 2216 | return false; |
| 2217 | } |
| 2218 | |
Wale Ogunwale | d046a01 | 2015-12-24 13:05:59 -0800 | [diff] [blame] | 2219 | if (targetStack != null && isFocusedStack(targetStack)) { |
| 2220 | return targetStack.resumeTopActivityUncheckedLocked(target, targetOptions); |
Craig Mautner | 05d2903 | 2013-05-03 13:40:13 -0700 | [diff] [blame] | 2221 | } |
chaviw | 59b9885 | 2017-06-13 12:05:44 -0700 | [diff] [blame] | 2222 | |
Wale Ogunwale | 06579d6 | 2016-04-30 15:29:06 -0700 | [diff] [blame] | 2223 | final ActivityRecord r = mFocusedStack.topRunningActivityLocked(); |
Bryce Lee | 7ace395 | 2018-02-16 14:34:32 -0800 | [diff] [blame] | 2224 | if (r == null || !r.isState(RESUMED)) { |
Wale Ogunwale | 06579d6 | 2016-04-30 15:29:06 -0700 | [diff] [blame] | 2225 | mFocusedStack.resumeTopActivityUncheckedLocked(null, null); |
Bryce Lee | 7ace395 | 2018-02-16 14:34:32 -0800 | [diff] [blame] | 2226 | } else if (r.isState(RESUMED)) { |
skuhne@google.com | 1b974dc | 2016-12-09 13:41:29 -0800 | [diff] [blame] | 2227 | // Kick off any lingering app transitions form the MoveTaskToFront operation. |
| 2228 | mFocusedStack.executeAppTransition(targetOptions); |
Wale Ogunwale | 06579d6 | 2016-04-30 15:29:06 -0700 | [diff] [blame] | 2229 | } |
chaviw | 59b9885 | 2017-06-13 12:05:44 -0700 | [diff] [blame] | 2230 | |
Wale Ogunwale | d046a01 | 2015-12-24 13:05:59 -0800 | [diff] [blame] | 2231 | return false; |
Craig Mautner | 8d341ef | 2013-03-26 09:03:27 -0700 | [diff] [blame] | 2232 | } |
| 2233 | |
Todd Kennedy | 39bfee5 | 2016-02-24 10:28:21 -0800 | [diff] [blame] | 2234 | void updateActivityApplicationInfoLocked(ApplicationInfo aInfo) { |
| 2235 | for (int displayNdx = mActivityDisplays.size() - 1; displayNdx >= 0; --displayNdx) { |
Wale Ogunwale | a0f5b5e | 2017-10-11 09:37:23 -0700 | [diff] [blame] | 2236 | final ActivityDisplay display = mActivityDisplays.valueAt(displayNdx); |
| 2237 | for (int stackNdx = display.getChildCount() - 1; stackNdx >= 0; --stackNdx) { |
| 2238 | final ActivityStack stack = display.getChildAt(stackNdx); |
| 2239 | stack.updateActivityApplicationInfoLocked(aInfo); |
Todd Kennedy | 39bfee5 | 2016-02-24 10:28:21 -0800 | [diff] [blame] | 2240 | } |
| 2241 | } |
| 2242 | } |
| 2243 | |
Andrii Kulian | 8cc92ac6 | 2018-04-02 23:14:18 -0700 | [diff] [blame] | 2244 | /** |
| 2245 | * Finish the topmost activities in all stacks that belong to the crashed app. |
| 2246 | * @param app The app that crashed. |
| 2247 | * @param reason Reason to perform this action. |
| 2248 | * @return The task that was finished in this stack, {@code null} if haven't found any. |
| 2249 | */ |
| 2250 | TaskRecord finishTopCrashedActivitiesLocked(ProcessRecord app, String reason) { |
Adrian Roos | 20d7df3 | 2016-01-12 18:59:43 +0100 | [diff] [blame] | 2251 | TaskRecord finishedTask = null; |
| 2252 | ActivityStack focusedStack = getFocusedStack(); |
Craig Mautner | e0a3884 | 2013-12-16 16:14:02 -0800 | [diff] [blame] | 2253 | for (int displayNdx = mActivityDisplays.size() - 1; displayNdx >= 0; --displayNdx) { |
Wale Ogunwale | a0f5b5e | 2017-10-11 09:37:23 -0700 | [diff] [blame] | 2254 | final ActivityDisplay display = mActivityDisplays.valueAt(displayNdx); |
Andrii Kulian | 8cc92ac6 | 2018-04-02 23:14:18 -0700 | [diff] [blame] | 2255 | // It is possible that request to finish activity might also remove its task and stack, |
| 2256 | // so we need to be careful with indexes in the loop and check child count every time. |
| 2257 | for (int stackNdx = 0; stackNdx < display.getChildCount(); ++stackNdx) { |
Wale Ogunwale | a0f5b5e | 2017-10-11 09:37:23 -0700 | [diff] [blame] | 2258 | final ActivityStack stack = display.getChildAt(stackNdx); |
Andrii Kulian | 8cc92ac6 | 2018-04-02 23:14:18 -0700 | [diff] [blame] | 2259 | final TaskRecord t = stack.finishTopCrashedActivityLocked(app, reason); |
Adrian Roos | 20d7df3 | 2016-01-12 18:59:43 +0100 | [diff] [blame] | 2260 | if (stack == focusedStack || finishedTask == null) { |
| 2261 | finishedTask = t; |
| 2262 | } |
Craig Mautner | 4a1cb22 | 2013-12-04 16:14:06 -0800 | [diff] [blame] | 2263 | } |
Craig Mautner | 8d341ef | 2013-03-26 09:03:27 -0700 | [diff] [blame] | 2264 | } |
Adrian Roos | 20d7df3 | 2016-01-12 18:59:43 +0100 | [diff] [blame] | 2265 | return finishedTask; |
Craig Mautner | 8d341ef | 2013-03-26 09:03:27 -0700 | [diff] [blame] | 2266 | } |
| 2267 | |
Dianne Hackborn | 6ea0d0a | 2014-07-02 16:23:21 -0700 | [diff] [blame] | 2268 | void finishVoiceTask(IVoiceInteractionSession session) { |
| 2269 | for (int displayNdx = mActivityDisplays.size() - 1; displayNdx >= 0; --displayNdx) { |
Wale Ogunwale | a0f5b5e | 2017-10-11 09:37:23 -0700 | [diff] [blame] | 2270 | final ActivityDisplay display = mActivityDisplays.valueAt(displayNdx); |
| 2271 | final int numStacks = display.getChildCount(); |
Dianne Hackborn | 6ea0d0a | 2014-07-02 16:23:21 -0700 | [diff] [blame] | 2272 | for (int stackNdx = 0; stackNdx < numStacks; ++stackNdx) { |
Wale Ogunwale | a0f5b5e | 2017-10-11 09:37:23 -0700 | [diff] [blame] | 2273 | final ActivityStack stack = display.getChildAt(stackNdx); |
Dianne Hackborn | 6ea0d0a | 2014-07-02 16:23:21 -0700 | [diff] [blame] | 2274 | stack.finishVoiceTask(session); |
| 2275 | } |
| 2276 | } |
| 2277 | } |
| 2278 | |
Jorim Jaggi | 4d8d32c | 2018-01-19 15:57:41 +0100 | [diff] [blame] | 2279 | void findTaskToMoveToFront(TaskRecord task, int flags, ActivityOptions options, String reason, |
| 2280 | boolean forceNonResizeable) { |
Wale Ogunwale | 66e1685 | 2017-10-19 13:35:52 -0700 | [diff] [blame] | 2281 | final ActivityStack currentStack = task.getStack(); |
| 2282 | if (currentStack == null) { |
| 2283 | Slog.e(TAG, "findTaskToMoveToFront: can't move task=" |
| 2284 | + task + " to front. Stack is null"); |
| 2285 | return; |
| 2286 | } |
| 2287 | |
Craig Mautner | aea74a5 | 2014-03-08 14:23:10 -0800 | [diff] [blame] | 2288 | if ((flags & ActivityManager.MOVE_TASK_NO_USER_ACTION) == 0) { |
| 2289 | mUserLeaving = true; |
Craig Mautner | 8d341ef | 2013-03-26 09:03:27 -0700 | [diff] [blame] | 2290 | } |
Wale Ogunwale | 66e1685 | 2017-10-19 13:35:52 -0700 | [diff] [blame] | 2291 | |
| 2292 | final ActivityRecord prev = topRunningActivityLocked(); |
| 2293 | |
| 2294 | if ((flags & ActivityManager.MOVE_TASK_WITH_HOME) != 0 |
| 2295 | || (prev != null && prev.isActivityTypeRecents())) { |
| 2296 | // Caller wants the home activity moved with it or the previous task is recents in which |
| 2297 | // case we always return home from the task we are moving to the front. |
| 2298 | moveHomeStackToFront("findTaskToMoveToFront"); |
Wale Ogunwale | 7d70117 | 2015-03-11 15:36:30 -0700 | [diff] [blame] | 2299 | } |
Chong Zhang | 0fa656b | 2015-08-31 15:17:21 -0700 | [diff] [blame] | 2300 | |
Wale Ogunwale | 0568aed | 2017-09-08 13:29:37 -0700 | [diff] [blame] | 2301 | if (task.isResizeable() && canUseActivityOptionsLaunchBounds(options)) { |
Bryce Lee | f3c6a47 | 2017-11-14 14:53:06 -0800 | [diff] [blame] | 2302 | final Rect bounds = options.getLaunchBounds(); |
Wale Ogunwale | 0568aed | 2017-09-08 13:29:37 -0700 | [diff] [blame] | 2303 | task.updateOverrideConfiguration(bounds); |
| 2304 | |
Wale Ogunwale | 04a05ac | 2017-09-17 21:35:02 -0700 | [diff] [blame] | 2305 | ActivityStack stack = getLaunchStack(null, options, task, ON_TOP); |
Wale Ogunwale | 0568aed | 2017-09-08 13:29:37 -0700 | [diff] [blame] | 2306 | |
Wale Ogunwale | 04a05ac | 2017-09-17 21:35:02 -0700 | [diff] [blame] | 2307 | if (stack != currentStack) { |
| 2308 | 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] | 2309 | "findTaskToMoveToFront"); |
Wale Ogunwale | 04a05ac | 2017-09-17 21:35:02 -0700 | [diff] [blame] | 2310 | stack = currentStack; |
Wale Ogunwale | 0568aed | 2017-09-08 13:29:37 -0700 | [diff] [blame] | 2311 | // moveTaskToStackUncheckedLocked() should already placed the task on top, |
| 2312 | // still need moveTaskToFrontLocked() below for any transition settings. |
| 2313 | } |
Wale Ogunwale | 44f036f | 2017-09-29 05:09:09 -0700 | [diff] [blame] | 2314 | if (stack.resizeStackWithLaunchBounds()) { |
| 2315 | resizeStackLocked(stack, bounds, null /* tempTaskBounds */, |
Wale Ogunwale | 04a05ac | 2017-09-17 21:35:02 -0700 | [diff] [blame] | 2316 | null /* tempTaskInsetBounds */, !PRESERVE_WINDOWS, |
| 2317 | true /* allowResizeInDockedMode */, !DEFER_RESUME); |
Wale Ogunwale | 0568aed | 2017-09-08 13:29:37 -0700 | [diff] [blame] | 2318 | } else { |
| 2319 | // WM resizeTask must be done after the task is moved to the correct stack, |
| 2320 | // because Task's setBounds() also updates dim layer's bounds, but that has |
| 2321 | // dependency on the stack. |
| 2322 | task.resizeWindowContainer(); |
Chong Zhang | 0fa656b | 2015-08-31 15:17:21 -0700 | [diff] [blame] | 2323 | } |
| 2324 | } |
| 2325 | |
Chong Zhang | db20b5f | 2015-10-23 14:01:43 -0700 | [diff] [blame] | 2326 | final ActivityRecord r = task.getTopActivity(); |
chaviw | 0d562bf | 2018-03-15 14:24:14 -0700 | [diff] [blame] | 2327 | currentStack.moveTaskToFrontLocked(task, false /* noAnimation */, options, |
Chong Zhang | db20b5f | 2015-10-23 14:01:43 -0700 | [diff] [blame] | 2328 | r == null ? null : r.appTimeTracker, reason); |
| 2329 | |
Wale Ogunwale | ee006da | 2015-03-30 14:49:25 -0700 | [diff] [blame] | 2330 | if (DEBUG_STACK) Slog.d(TAG_STACK, |
Andrii Kulian | 02b7a83 | 2016-10-06 23:11:56 -0700 | [diff] [blame] | 2331 | "findTaskToMoveToFront: moved to front of stack=" + currentStack); |
Jorim Jaggi | 2adba07 | 2016-03-03 13:43:39 +0100 | [diff] [blame] | 2332 | |
Wale Ogunwale | 0568aed | 2017-09-08 13:29:37 -0700 | [diff] [blame] | 2333 | handleNonResizableTaskIfNeeded(task, WINDOWING_MODE_UNDEFINED, DEFAULT_DISPLAY, |
Wale Ogunwale | a0f5b5e | 2017-10-11 09:37:23 -0700 | [diff] [blame] | 2334 | currentStack, forceNonResizeable); |
Craig Mautner | 8d341ef | 2013-03-26 09:03:27 -0700 | [diff] [blame] | 2335 | } |
| 2336 | |
Wale Ogunwale | 0568aed | 2017-09-08 13:29:37 -0700 | [diff] [blame] | 2337 | boolean canUseActivityOptionsLaunchBounds(ActivityOptions options) { |
Wale Ogunwale | 7a8fa60 | 2015-11-18 15:56:57 -0800 | [diff] [blame] | 2338 | // 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] | 2339 | // window management or is launching into the pinned stack. |
Wale Ogunwale | 0568aed | 2017-09-08 13:29:37 -0700 | [diff] [blame] | 2340 | if (options == null || options.getLaunchBounds() == null) { |
Wale Ogunwale | 854809c | 2015-12-27 16:18:19 -0800 | [diff] [blame] | 2341 | return false; |
| 2342 | } |
Wale Ogunwale | 0568aed | 2017-09-08 13:29:37 -0700 | [diff] [blame] | 2343 | return (mService.mSupportsPictureInPicture |
| 2344 | && options.getLaunchWindowingMode() == WINDOWING_MODE_PINNED) |
Wale Ogunwale | 854809c | 2015-12-27 16:18:19 -0800 | [diff] [blame] | 2345 | || mService.mSupportsFreeformWindowManagement; |
Wale Ogunwale | 7a8fa60 | 2015-11-18 15:56:57 -0800 | [diff] [blame] | 2346 | } |
| 2347 | |
Bryce Lee | ec55eb0 | 2017-12-05 20:51:27 -0800 | [diff] [blame] | 2348 | LaunchParamsController getLaunchParamsController() { |
| 2349 | return mLaunchParamsController; |
Bryce Lee | 9ad3eb3 | 2017-10-10 10:10:31 -0700 | [diff] [blame] | 2350 | } |
| 2351 | |
Winson Chung | 5589333 | 2017-02-17 17:13:10 -0800 | [diff] [blame] | 2352 | protected <T extends ActivityStack> T getStack(int stackId) { |
Wale Ogunwale | 9dcf946 | 2017-09-19 15:13:01 -0700 | [diff] [blame] | 2353 | for (int i = mActivityDisplays.size() - 1; i >= 0; --i) { |
| 2354 | final T stack = mActivityDisplays.valueAt(i).getStack(stackId); |
| 2355 | if (stack != null) { |
| 2356 | return stack; |
| 2357 | } |
| 2358 | } |
| 2359 | return null; |
Wale Ogunwale | ddc1cb2 | 2015-07-25 19:23:04 -0700 | [diff] [blame] | 2360 | } |
| 2361 | |
Wale Ogunwale | 6827856 | 2017-09-23 17:13:55 -0700 | [diff] [blame] | 2362 | /** @see ActivityDisplay#getStack(int, int) */ |
| 2363 | private <T extends ActivityStack> T getStack(int windowingMode, int activityType) { |
| 2364 | for (int i = mActivityDisplays.size() - 1; i >= 0; --i) { |
| 2365 | final T stack = mActivityDisplays.valueAt(i).getStack(windowingMode, activityType); |
| 2366 | if (stack != null) { |
| 2367 | return stack; |
| 2368 | } |
| 2369 | } |
| 2370 | return null; |
| 2371 | } |
| 2372 | |
Wale Ogunwale | 04a05ac | 2017-09-17 21:35:02 -0700 | [diff] [blame] | 2373 | int resolveActivityType(@Nullable ActivityRecord r, @Nullable ActivityOptions options, |
Wale Ogunwale | 0568aed | 2017-09-08 13:29:37 -0700 | [diff] [blame] | 2374 | @Nullable TaskRecord task) { |
Wale Ogunwale | 04a05ac | 2017-09-17 21:35:02 -0700 | [diff] [blame] | 2375 | // Preference is given to the activity type for the activity then the task since the type |
| 2376 | // once set shouldn't change. |
| 2377 | int activityType = r != null ? r.getActivityType() : ACTIVITY_TYPE_UNDEFINED; |
| 2378 | if (activityType == ACTIVITY_TYPE_UNDEFINED && task != null) { |
| 2379 | activityType = task.getActivityType(); |
| 2380 | } |
Wale Ogunwale | 0568aed | 2017-09-08 13:29:37 -0700 | [diff] [blame] | 2381 | if (activityType != ACTIVITY_TYPE_UNDEFINED) { |
| 2382 | return activityType; |
| 2383 | } |
Wale Ogunwale | ab5de37 | 2017-10-18 06:46:31 -0700 | [diff] [blame] | 2384 | if (options != null) { |
| 2385 | activityType = options.getLaunchActivityType(); |
| 2386 | } |
| 2387 | return activityType != ACTIVITY_TYPE_UNDEFINED ? activityType : ACTIVITY_TYPE_STANDARD; |
Wale Ogunwale | 0568aed | 2017-09-08 13:29:37 -0700 | [diff] [blame] | 2388 | } |
| 2389 | |
Wale Ogunwale | 04a05ac | 2017-09-17 21:35:02 -0700 | [diff] [blame] | 2390 | <T extends ActivityStack> T getLaunchStack(@Nullable ActivityRecord r, |
| 2391 | @Nullable ActivityOptions options, @Nullable TaskRecord candidateTask, boolean onTop) { |
| 2392 | return getLaunchStack(r, options, candidateTask, onTop, INVALID_DISPLAY); |
Wale Ogunwale | 0568aed | 2017-09-08 13:29:37 -0700 | [diff] [blame] | 2393 | } |
| 2394 | |
| 2395 | /** |
| 2396 | * Returns the right stack to use for launching factoring in all the input parameters. |
| 2397 | * |
| 2398 | * @param r The activity we are trying to launch. Can be null. |
| 2399 | * @param options The activity options used to the launch. Can be null. |
| 2400 | * @param candidateTask The possible task the activity might be launched in. Can be null. |
| 2401 | * |
| 2402 | * @return The stack to use for the launch or INVALID_STACK_ID. |
| 2403 | */ |
Wale Ogunwale | 04a05ac | 2017-09-17 21:35:02 -0700 | [diff] [blame] | 2404 | <T extends ActivityStack> T getLaunchStack(@Nullable ActivityRecord r, |
| 2405 | @Nullable ActivityOptions options, @Nullable TaskRecord candidateTask, boolean onTop, |
| 2406 | int candidateDisplayId) { |
Wale Ogunwale | 0568aed | 2017-09-08 13:29:37 -0700 | [diff] [blame] | 2407 | int taskId = INVALID_TASK_ID; |
| 2408 | int displayId = INVALID_DISPLAY; |
| 2409 | //Rect bounds = null; |
| 2410 | |
| 2411 | // We give preference to the launch preference in activity options. |
| 2412 | if (options != null) { |
| 2413 | taskId = options.getLaunchTaskId(); |
| 2414 | displayId = options.getLaunchDisplayId(); |
| 2415 | // TODO: Need to work this into the equation... |
| 2416 | //bounds = options.getLaunchBounds(); |
| 2417 | } |
| 2418 | |
| 2419 | // First preference for stack goes to the task Id set in the activity options. Use the stack |
| 2420 | // associated with that if possible. |
| 2421 | if (taskId != INVALID_TASK_ID) { |
| 2422 | // Temporarily set the task id to invalid in case in re-entry. |
| 2423 | options.setLaunchTaskId(INVALID_TASK_ID); |
| 2424 | final TaskRecord task = anyTaskForIdLocked(taskId, |
Wale Ogunwale | ab5de37 | 2017-10-18 06:46:31 -0700 | [diff] [blame] | 2425 | MATCH_TASK_IN_STACKS_OR_RECENT_TASKS_AND_RESTORE, options, onTop); |
Wale Ogunwale | 0568aed | 2017-09-08 13:29:37 -0700 | [diff] [blame] | 2426 | options.setLaunchTaskId(taskId); |
| 2427 | if (task != null) { |
Wale Ogunwale | 04a05ac | 2017-09-17 21:35:02 -0700 | [diff] [blame] | 2428 | return task.getStack(); |
Wale Ogunwale | 0568aed | 2017-09-08 13:29:37 -0700 | [diff] [blame] | 2429 | } |
| 2430 | } |
| 2431 | |
Wale Ogunwale | 0568aed | 2017-09-08 13:29:37 -0700 | [diff] [blame] | 2432 | final int activityType = resolveActivityType(r, options, candidateTask); |
Wale Ogunwale | 04a05ac | 2017-09-17 21:35:02 -0700 | [diff] [blame] | 2433 | T stack = null; |
Wale Ogunwale | 0568aed | 2017-09-08 13:29:37 -0700 | [diff] [blame] | 2434 | |
| 2435 | // Next preference for stack goes to the display Id set in the activity options or the |
| 2436 | // candidate display. |
| 2437 | if (displayId == INVALID_DISPLAY) { |
| 2438 | displayId = candidateDisplayId; |
| 2439 | } |
Andrii Kulian | b850ea5 | 2017-12-12 23:49:10 -0800 | [diff] [blame] | 2440 | if (displayId != INVALID_DISPLAY && canLaunchOnDisplay(r, displayId)) { |
Wale Ogunwale | 0568aed | 2017-09-08 13:29:37 -0700 | [diff] [blame] | 2441 | if (r != null) { |
| 2442 | // 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] | 2443 | stack = (T) getValidLaunchStackOnDisplay(displayId, r); |
Wale Ogunwale | 0568aed | 2017-09-08 13:29:37 -0700 | [diff] [blame] | 2444 | if (stack != null) { |
Wale Ogunwale | 04a05ac | 2017-09-17 21:35:02 -0700 | [diff] [blame] | 2445 | return stack; |
Wale Ogunwale | 0568aed | 2017-09-08 13:29:37 -0700 | [diff] [blame] | 2446 | } |
| 2447 | } |
| 2448 | final ActivityDisplay display = getActivityDisplayOrCreateLocked(displayId); |
| 2449 | if (display != null) { |
Wale Ogunwale | 7e1f5f5 | 2017-10-18 15:19:59 -0700 | [diff] [blame] | 2450 | stack = display.getOrCreateStack(r, options, candidateTask, activityType, onTop); |
Wale Ogunwale | ab5de37 | 2017-10-18 06:46:31 -0700 | [diff] [blame] | 2451 | if (stack != null) { |
| 2452 | return stack; |
Wale Ogunwale | 0568aed | 2017-09-08 13:29:37 -0700 | [diff] [blame] | 2453 | } |
Wale Ogunwale | 0568aed | 2017-09-08 13:29:37 -0700 | [diff] [blame] | 2454 | } |
| 2455 | } |
| 2456 | |
| 2457 | // Give preference to the stack and display of the input task and activity if they match the |
| 2458 | // mode we want to launch into. |
Wale Ogunwale | 04a05ac | 2017-09-17 21:35:02 -0700 | [diff] [blame] | 2459 | stack = null; |
| 2460 | ActivityDisplay display = null; |
Wale Ogunwale | 0568aed | 2017-09-08 13:29:37 -0700 | [diff] [blame] | 2461 | if (candidateTask != null) { |
| 2462 | stack = candidateTask.getStack(); |
| 2463 | } |
| 2464 | if (stack == null && r != null) { |
| 2465 | stack = r.getStack(); |
| 2466 | } |
| 2467 | if (stack != null) { |
Wale Ogunwale | 04a05ac | 2017-09-17 21:35:02 -0700 | [diff] [blame] | 2468 | display = stack.getDisplay(); |
Andrii Kulian | b850ea5 | 2017-12-12 23:49:10 -0800 | [diff] [blame] | 2469 | if (display != null && canLaunchOnDisplay(r, display.mDisplayId)) { |
Wale Ogunwale | 7e1f5f5 | 2017-10-18 15:19:59 -0700 | [diff] [blame] | 2470 | final int windowingMode = |
| 2471 | display.resolveWindowingMode(r, options, candidateTask, activityType); |
| 2472 | if (stack.isCompatible(windowingMode, activityType)) { |
| 2473 | return stack; |
| 2474 | } |
Andrii Kulian | ec7d4c4 | 2018-04-26 18:31:58 -0700 | [diff] [blame] | 2475 | if (windowingMode == WINDOWING_MODE_FULLSCREEN_OR_SPLIT_SCREEN_SECONDARY |
| 2476 | && display.getSplitScreenPrimaryStack() == stack |
| 2477 | && candidateTask == stack.topTask()) { |
| 2478 | // This is a special case when we try to launch an activity that is currently on |
| 2479 | // top of split-screen primary stack, but is targeting split-screen secondary. |
| 2480 | // In this case we don't want to move it to another stack. |
| 2481 | // TODO(b/78788972): Remove after differentiating between preferred and required |
| 2482 | // launch options. |
| 2483 | return stack; |
| 2484 | } |
Wale Ogunwale | 7e1f5f5 | 2017-10-18 15:19:59 -0700 | [diff] [blame] | 2485 | } |
Wale Ogunwale | 0568aed | 2017-09-08 13:29:37 -0700 | [diff] [blame] | 2486 | } |
| 2487 | |
Wale Ogunwale | 04a05ac | 2017-09-17 21:35:02 -0700 | [diff] [blame] | 2488 | if (display == null |
Andrii Kulian | b850ea5 | 2017-12-12 23:49:10 -0800 | [diff] [blame] | 2489 | || !canLaunchOnDisplay(r, display.mDisplayId) |
Wale Ogunwale | 04a05ac | 2017-09-17 21:35:02 -0700 | [diff] [blame] | 2490 | // TODO: Can be removed once we figure-out how non-standard types should launch |
| 2491 | // outside the default display. |
| 2492 | || (activityType != ACTIVITY_TYPE_STANDARD |
| 2493 | && activityType != ACTIVITY_TYPE_UNDEFINED)) { |
| 2494 | display = getDefaultDisplay(); |
Wale Ogunwale | 0568aed | 2017-09-08 13:29:37 -0700 | [diff] [blame] | 2495 | } |
Wale Ogunwale | 04a05ac | 2017-09-17 21:35:02 -0700 | [diff] [blame] | 2496 | |
Wale Ogunwale | 7e1f5f5 | 2017-10-18 15:19:59 -0700 | [diff] [blame] | 2497 | return display.getOrCreateStack(r, options, candidateTask, activityType, onTop); |
Wale Ogunwale | 0568aed | 2017-09-08 13:29:37 -0700 | [diff] [blame] | 2498 | } |
| 2499 | |
Andrii Kulian | b850ea5 | 2017-12-12 23:49:10 -0800 | [diff] [blame] | 2500 | /** @return true if activity record is null or can be launched on provided display. */ |
| 2501 | private boolean canLaunchOnDisplay(ActivityRecord r, int displayId) { |
| 2502 | if (r == null) { |
| 2503 | return true; |
| 2504 | } |
| 2505 | return r.canBeLaunchedOnDisplay(displayId); |
| 2506 | } |
| 2507 | |
Andrii Kulian | 16802aa | 2016-11-02 12:21:33 -0700 | [diff] [blame] | 2508 | /** |
| 2509 | * Get a topmost stack on the display, that is a valid launch stack for specified activity. |
| 2510 | * If there is no such stack, new dynamic stack can be created. |
| 2511 | * @param displayId Target display. |
| 2512 | * @param r Activity that should be launched there. |
| 2513 | * @return Existing stack if there is a valid one, new dynamic stack if it is valid or null. |
| 2514 | */ |
| 2515 | ActivityStack getValidLaunchStackOnDisplay(int displayId, @NonNull ActivityRecord r) { |
Andrii Kulian | 62e6f25 | 2017-05-30 22:46:53 -0700 | [diff] [blame] | 2516 | final ActivityDisplay activityDisplay = getActivityDisplayOrCreateLocked(displayId); |
Andrii Kulian | 16802aa | 2016-11-02 12:21:33 -0700 | [diff] [blame] | 2517 | if (activityDisplay == null) { |
| 2518 | throw new IllegalArgumentException( |
| 2519 | "Display with displayId=" + displayId + " not found."); |
| 2520 | } |
| 2521 | |
Wale Ogunwale | 04a05ac | 2017-09-17 21:35:02 -0700 | [diff] [blame] | 2522 | if (!r.canBeLaunchedOnDisplay(displayId)) { |
| 2523 | return null; |
| 2524 | } |
| 2525 | |
Andrii Kulian | 16802aa | 2016-11-02 12:21:33 -0700 | [diff] [blame] | 2526 | // Return the topmost valid stack on the display. |
Wale Ogunwale | a0f5b5e | 2017-10-11 09:37:23 -0700 | [diff] [blame] | 2527 | for (int i = activityDisplay.getChildCount() - 1; i >= 0; --i) { |
| 2528 | final ActivityStack stack = activityDisplay.getChildAt(i); |
Wale Ogunwale | 6827856 | 2017-09-23 17:13:55 -0700 | [diff] [blame] | 2529 | if (isValidLaunchStack(stack, displayId, r)) { |
Andrii Kulian | 16802aa | 2016-11-02 12:21:33 -0700 | [diff] [blame] | 2530 | return stack; |
| 2531 | } |
| 2532 | } |
| 2533 | |
| 2534 | // 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] | 2535 | if (displayId != DEFAULT_DISPLAY) { |
| 2536 | return activityDisplay.createStack( |
| 2537 | r.getWindowingMode(), r.getActivityType(), true /*onTop*/); |
Andrii Kulian | 16802aa | 2016-11-02 12:21:33 -0700 | [diff] [blame] | 2538 | } |
| 2539 | |
| 2540 | Slog.w(TAG, "getValidLaunchStackOnDisplay: can't launch on displayId " + displayId); |
| 2541 | return null; |
| 2542 | } |
| 2543 | |
Wale Ogunwale | 6827856 | 2017-09-23 17:13:55 -0700 | [diff] [blame] | 2544 | // TODO: Can probably be consolidated into getLaunchStack()... |
| 2545 | private boolean isValidLaunchStack(ActivityStack stack, int displayId, ActivityRecord r) { |
| 2546 | switch (stack.getActivityType()) { |
| 2547 | case ACTIVITY_TYPE_HOME: return r.isActivityTypeHome(); |
| 2548 | case ACTIVITY_TYPE_RECENTS: return r.isActivityTypeRecents(); |
| 2549 | case ACTIVITY_TYPE_ASSISTANT: return r.isActivityTypeAssistant(); |
Wale Ogunwale | 0568aed | 2017-09-08 13:29:37 -0700 | [diff] [blame] | 2550 | } |
Wale Ogunwale | 6827856 | 2017-09-23 17:13:55 -0700 | [diff] [blame] | 2551 | switch (stack.getWindowingMode()) { |
| 2552 | case WINDOWING_MODE_FULLSCREEN: return true; |
| 2553 | case WINDOWING_MODE_FREEFORM: return r.supportsFreeform(); |
| 2554 | case WINDOWING_MODE_PINNED: return r.supportsPictureInPicture(); |
| 2555 | case WINDOWING_MODE_SPLIT_SCREEN_PRIMARY: return r.supportsSplitScreenWindowingMode(); |
| 2556 | case WINDOWING_MODE_SPLIT_SCREEN_SECONDARY: return r.supportsSplitScreenWindowingMode(); |
| 2557 | } |
| 2558 | |
Wale Ogunwale | 44f036f | 2017-09-29 05:09:09 -0700 | [diff] [blame] | 2559 | if (!stack.isOnHomeDisplay()) { |
Wale Ogunwale | 6827856 | 2017-09-23 17:13:55 -0700 | [diff] [blame] | 2560 | return r.canBeLaunchedOnDisplay(displayId); |
| 2561 | } |
| 2562 | Slog.e(TAG, "isValidLaunchStack: Unexpected stack=" + stack); |
| 2563 | return false; |
Wale Ogunwale | 0568aed | 2017-09-08 13:29:37 -0700 | [diff] [blame] | 2564 | } |
| 2565 | |
Andrii Kulian | 7fc2281 | 2016-12-28 13:04:11 -0800 | [diff] [blame] | 2566 | /** |
| 2567 | * Get next focusable stack in the system. This will search across displays and stacks |
| 2568 | * in last-focused order for a focusable and visible stack, different from the target stack. |
| 2569 | * |
Wale Ogunwale | e1f68ce | 2018-03-09 08:58:54 -0800 | [diff] [blame] | 2570 | * @param currentFocus The stack that previously had focus. |
| 2571 | * @param ignoreCurrent If we should ignore {@param currentFocus} when searching for next |
| 2572 | * candidate. |
Andrii Kulian | 7fc2281 | 2016-12-28 13:04:11 -0800 | [diff] [blame] | 2573 | * @return Next focusable {@link ActivityStack}, null if not found. |
| 2574 | */ |
Wale Ogunwale | e1f68ce | 2018-03-09 08:58:54 -0800 | [diff] [blame] | 2575 | ActivityStack getNextFocusableStackLocked(ActivityStack currentFocus, boolean ignoreCurrent) { |
Andrii Kulian | 7fc2281 | 2016-12-28 13:04:11 -0800 | [diff] [blame] | 2576 | mWindowManager.getDisplaysInFocusOrder(mTmpOrderedDisplayIds); |
| 2577 | |
Wale Ogunwale | e1f68ce | 2018-03-09 08:58:54 -0800 | [diff] [blame] | 2578 | final int currentWindowingMode = currentFocus != null |
| 2579 | ? currentFocus.getWindowingMode() : WINDOWING_MODE_UNDEFINED; |
| 2580 | ActivityStack candidate = null; |
Andrii Kulian | 7fc2281 | 2016-12-28 13:04:11 -0800 | [diff] [blame] | 2581 | for (int i = mTmpOrderedDisplayIds.size() - 1; i >= 0; --i) { |
| 2582 | final int displayId = mTmpOrderedDisplayIds.get(i); |
Andrii Kulian | 62e6f25 | 2017-05-30 22:46:53 -0700 | [diff] [blame] | 2583 | // 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] | 2584 | final ActivityDisplay display = getActivityDisplayOrCreateLocked(displayId); |
Wale Ogunwale | c2ea364 | 2018-05-24 00:32:23 -0700 | [diff] [blame] | 2585 | if (display == null) { |
| 2586 | // Looks like the display no longer exists in the system... |
| 2587 | continue; |
| 2588 | } |
Wale Ogunwale | a0f5b5e | 2017-10-11 09:37:23 -0700 | [diff] [blame] | 2589 | for (int j = display.getChildCount() - 1; j >= 0; --j) { |
| 2590 | final ActivityStack stack = display.getChildAt(j); |
Wale Ogunwale | e1f68ce | 2018-03-09 08:58:54 -0800 | [diff] [blame] | 2591 | if (ignoreCurrent && stack == currentFocus) { |
| 2592 | continue; |
Andrii Kulian | 7fc2281 | 2016-12-28 13:04:11 -0800 | [diff] [blame] | 2593 | } |
Wale Ogunwale | e1f68ce | 2018-03-09 08:58:54 -0800 | [diff] [blame] | 2594 | if (!stack.isFocusable() || !stack.shouldBeVisible(null)) { |
| 2595 | continue; |
| 2596 | } |
| 2597 | |
| 2598 | if (currentWindowingMode == WINDOWING_MODE_SPLIT_SCREEN_SECONDARY |
| 2599 | && candidate == null && stack.inSplitScreenPrimaryWindowingMode()) { |
Wale Ogunwale | 17696de | 2018-03-15 16:41:05 -0700 | [diff] [blame] | 2600 | // If the currently focused stack is in split-screen secondary we save off the |
| 2601 | // top primary split-screen stack as a candidate for focus because we might |
| 2602 | // prefer focus to move to an other stack to avoid primary split-screen stack |
| 2603 | // overlapping with a fullscreen stack when a fullscreen stack is higher in z |
| 2604 | // 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] | 2605 | // We only move the focus to the primary-split screen stack if there isn't a |
| 2606 | // better alternative. |
| 2607 | candidate = stack; |
| 2608 | continue; |
| 2609 | } |
Wale Ogunwale | 17696de | 2018-03-15 16:41:05 -0700 | [diff] [blame] | 2610 | if (candidate != null && stack.inSplitScreenSecondaryWindowingMode()) { |
| 2611 | // Use the candidate stack since we are now at the secondary split-screen. |
| 2612 | return candidate; |
| 2613 | } |
Wale Ogunwale | e1f68ce | 2018-03-09 08:58:54 -0800 | [diff] [blame] | 2614 | return stack; |
Andrii Kulian | 7fc2281 | 2016-12-28 13:04:11 -0800 | [diff] [blame] | 2615 | } |
| 2616 | } |
| 2617 | |
Wale Ogunwale | e1f68ce | 2018-03-09 08:58:54 -0800 | [diff] [blame] | 2618 | return candidate; |
Andrii Kulian | 7fc2281 | 2016-12-28 13:04:11 -0800 | [diff] [blame] | 2619 | } |
| 2620 | |
Andrii Kulian | a8fe3df | 2017-06-16 15:29:26 -0700 | [diff] [blame] | 2621 | /** |
| 2622 | * Get next valid stack for launching provided activity in the system. This will search across |
| 2623 | * displays and stacks in last-focused order for a focusable and visible stack, except those |
| 2624 | * that are on a currently focused display. |
| 2625 | * |
| 2626 | * @param r The activity that is being launched. |
| 2627 | * @param currentFocus The display that previously had focus and thus needs to be ignored when |
| 2628 | * searching for the next candidate. |
| 2629 | * @return Next valid {@link ActivityStack}, null if not found. |
| 2630 | */ |
| 2631 | ActivityStack getNextValidLaunchStackLocked(@NonNull ActivityRecord r, int currentFocus) { |
| 2632 | mWindowManager.getDisplaysInFocusOrder(mTmpOrderedDisplayIds); |
| 2633 | for (int i = mTmpOrderedDisplayIds.size() - 1; i >= 0; --i) { |
| 2634 | final int displayId = mTmpOrderedDisplayIds.get(i); |
| 2635 | if (displayId == currentFocus) { |
| 2636 | continue; |
| 2637 | } |
| 2638 | final ActivityStack stack = getValidLaunchStackOnDisplay(displayId, r); |
| 2639 | if (stack != null) { |
| 2640 | return stack; |
| 2641 | } |
| 2642 | } |
| 2643 | return null; |
| 2644 | } |
| 2645 | |
Craig Mautner | ee2e45a | 2014-06-27 12:10:03 -0700 | [diff] [blame] | 2646 | ActivityRecord getHomeActivity() { |
Craig Mautner | db49fec | 2015-05-21 15:33:30 -0700 | [diff] [blame] | 2647 | return getHomeActivityForUser(mCurrentUser); |
Fyodor Kupolov | b501330 | 2015-04-17 17:59:14 -0700 | [diff] [blame] | 2648 | } |
| 2649 | |
| 2650 | ActivityRecord getHomeActivityForUser(int userId) { |
Craig Mautner | 4a1cb22 | 2013-12-04 16:14:06 -0800 | [diff] [blame] | 2651 | final ArrayList<TaskRecord> tasks = mHomeStack.getAllTasks(); |
| 2652 | for (int taskNdx = tasks.size() - 1; taskNdx >= 0; --taskNdx) { |
| 2653 | final TaskRecord task = tasks.get(taskNdx); |
Wale Ogunwale | 6fbde9f | 2017-08-24 07:24:12 -0700 | [diff] [blame] | 2654 | if (task.isActivityTypeHome()) { |
Craig Mautner | 4a1cb22 | 2013-12-04 16:14:06 -0800 | [diff] [blame] | 2655 | final ArrayList<ActivityRecord> activities = task.mActivities; |
| 2656 | for (int activityNdx = activities.size() - 1; activityNdx >= 0; --activityNdx) { |
| 2657 | final ActivityRecord r = activities.get(activityNdx); |
Wale Ogunwale | 6fbde9f | 2017-08-24 07:24:12 -0700 | [diff] [blame] | 2658 | if (r.isActivityTypeHome() |
Fyodor Kupolov | b501330 | 2015-04-17 17:59:14 -0700 | [diff] [blame] | 2659 | && ((userId == UserHandle.USER_ALL) || (r.userId == userId))) { |
Craig Mautner | ee2e45a | 2014-06-27 12:10:03 -0700 | [diff] [blame] | 2660 | return r; |
Craig Mautner | 4a1cb22 | 2013-12-04 16:14:06 -0800 | [diff] [blame] | 2661 | } |
| 2662 | } |
| 2663 | } |
| 2664 | } |
| 2665 | return null; |
| 2666 | } |
| 2667 | |
Wale Ogunwale | 44f036f | 2017-09-29 05:09:09 -0700 | [diff] [blame] | 2668 | void resizeStackLocked(ActivityStack stack, Rect bounds, Rect tempTaskBounds, |
| 2669 | Rect tempTaskInsetBounds, boolean preserveWindows, boolean allowResizeInDockedMode, |
| 2670 | boolean deferResume) { |
| 2671 | |
| 2672 | if (stack.inSplitScreenPrimaryWindowingMode()) { |
Jorim Jaggi | dc249c4 | 2015-12-15 14:57:31 -0800 | [diff] [blame] | 2673 | resizeDockedStackLocked(bounds, tempTaskBounds, tempTaskInsetBounds, null, null, |
Andrii Kulian | db3e4ec | 2016-07-12 17:11:35 -0700 | [diff] [blame] | 2674 | preserveWindows, deferResume); |
Jorim Jaggi | dc249c4 | 2015-12-15 14:57:31 -0800 | [diff] [blame] | 2675 | return; |
| 2676 | } |
Wale Ogunwale | 9d3de4c | 2015-02-01 16:49:44 -0800 | [diff] [blame] | 2677 | |
Wale Ogunwale | a0f5b5e | 2017-10-11 09:37:23 -0700 | [diff] [blame] | 2678 | final boolean splitScreenActive = getDefaultDisplay().hasSplitScreenPrimaryStack(); |
Wale Ogunwale | 3382ab1 | 2017-07-27 08:55:03 -0700 | [diff] [blame] | 2679 | if (!allowResizeInDockedMode |
Wale Ogunwale | 926aade | 2017-08-29 11:24:37 -0700 | [diff] [blame] | 2680 | && !stack.getWindowConfiguration().tasksAreFloating() && splitScreenActive) { |
Winson Chung | a2249ac | 2017-03-30 18:15:30 -0700 | [diff] [blame] | 2681 | // If the docked stack exists, don't resize non-floating stacks independently of the |
| 2682 | // 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] | 2683 | return; |
| 2684 | } |
| 2685 | |
Wale Ogunwale | 44f036f | 2017-09-29 05:09:09 -0700 | [diff] [blame] | 2686 | Trace.traceBegin(TRACE_TAG_ACTIVITY_MANAGER, "am.resizeStack_" + stack.mStackId); |
Jorim Jaggi | c402520 | 2015-10-22 16:43:34 +0200 | [diff] [blame] | 2687 | mWindowManager.deferSurfaceLayout(); |
| 2688 | try { |
Wale Ogunwale | 2b07da8 | 2017-11-08 14:52:40 -0800 | [diff] [blame] | 2689 | if (stack.affectedBySplitScreenResize()) { |
Wale Ogunwale | 926aade | 2017-08-29 11:24:37 -0700 | [diff] [blame] | 2690 | if (bounds == null && stack.inSplitScreenWindowingMode()) { |
| 2691 | // null bounds = fullscreen windowing mode...at least for now. |
| 2692 | stack.setWindowingMode(WINDOWING_MODE_FULLSCREEN); |
| 2693 | } else if (splitScreenActive) { |
| 2694 | // If we are in split-screen mode and this stack support split-screen, then |
| 2695 | // it should be split-screen secondary mode. i.e. adjacent to the docked stack. |
| 2696 | stack.setWindowingMode(WINDOWING_MODE_SPLIT_SCREEN_SECONDARY); |
| 2697 | } |
| 2698 | } |
Wale Ogunwale | 1666e31 | 2016-12-16 11:27:18 -0800 | [diff] [blame] | 2699 | stack.resize(bounds, tempTaskBounds, tempTaskInsetBounds); |
Wale Ogunwale | c8da41e | 2016-04-16 13:27:23 -0700 | [diff] [blame] | 2700 | if (!deferResume) { |
Wale Ogunwale | db0fa12 | 2016-05-16 15:12:03 -0700 | [diff] [blame] | 2701 | stack.ensureVisibleActivitiesConfigurationLocked( |
| 2702 | stack.topRunningActivityLocked(), preserveWindows); |
Wale Ogunwale | c8da41e | 2016-04-16 13:27:23 -0700 | [diff] [blame] | 2703 | } |
Jorim Jaggi | c402520 | 2015-10-22 16:43:34 +0200 | [diff] [blame] | 2704 | } finally { |
| 2705 | mWindowManager.continueSurfaceLayout(); |
| 2706 | Trace.traceEnd(TRACE_TAG_ACTIVITY_MANAGER); |
Wale Ogunwale | e4a0c57 | 2015-06-30 08:40:31 -0700 | [diff] [blame] | 2707 | } |
| 2708 | } |
| 2709 | |
Winson Chung | c167427 | 2018-02-21 10:15:17 -0800 | [diff] [blame] | 2710 | void deferUpdateRecentsHomeStackBounds() { |
| 2711 | deferUpdateBounds(ACTIVITY_TYPE_RECENTS); |
| 2712 | deferUpdateBounds(ACTIVITY_TYPE_HOME); |
| 2713 | } |
| 2714 | |
Bryce Lee | d3624e1 | 2017-11-30 08:51:45 -0800 | [diff] [blame] | 2715 | void deferUpdateBounds(int activityType) { |
Wale Ogunwale | 6827856 | 2017-09-23 17:13:55 -0700 | [diff] [blame] | 2716 | final ActivityStack stack = getStack(WINDOWING_MODE_UNDEFINED, activityType); |
Jorim Jaggi | 192086e | 2016-03-11 17:17:03 +0100 | [diff] [blame] | 2717 | if (stack != null) { |
| 2718 | stack.deferUpdateBounds(); |
| 2719 | } |
| 2720 | } |
| 2721 | |
Winson Chung | c167427 | 2018-02-21 10:15:17 -0800 | [diff] [blame] | 2722 | void continueUpdateRecentsHomeStackBounds() { |
| 2723 | continueUpdateBounds(ACTIVITY_TYPE_RECENTS); |
| 2724 | continueUpdateBounds(ACTIVITY_TYPE_HOME); |
| 2725 | } |
| 2726 | |
Bryce Lee | d3624e1 | 2017-11-30 08:51:45 -0800 | [diff] [blame] | 2727 | void continueUpdateBounds(int activityType) { |
Wale Ogunwale | 6827856 | 2017-09-23 17:13:55 -0700 | [diff] [blame] | 2728 | final ActivityStack stack = getStack(WINDOWING_MODE_UNDEFINED, activityType); |
Jorim Jaggi | 192086e | 2016-03-11 17:17:03 +0100 | [diff] [blame] | 2729 | if (stack != null) { |
| 2730 | stack.continueUpdateBounds(); |
| 2731 | } |
| 2732 | } |
| 2733 | |
Jorim Jaggi | 0b46f3c | 2016-03-14 12:21:37 +0100 | [diff] [blame] | 2734 | void notifyAppTransitionDone() { |
Winson Chung | c167427 | 2018-02-21 10:15:17 -0800 | [diff] [blame] | 2735 | continueUpdateRecentsHomeStackBounds(); |
Jorim Jaggi | 0b46f3c | 2016-03-14 12:21:37 +0100 | [diff] [blame] | 2736 | for (int i = mResizingTasksDuringAnimation.size() - 1; i >= 0; i--) { |
| 2737 | final int taskId = mResizingTasksDuringAnimation.valueAt(i); |
Wale Ogunwale | 0568aed | 2017-09-08 13:29:37 -0700 | [diff] [blame] | 2738 | final TaskRecord task = anyTaskForIdLocked(taskId, MATCH_TASK_IN_STACKS_ONLY); |
Wale Ogunwale | e1fe7fa2 | 2016-12-15 18:27:00 -0800 | [diff] [blame] | 2739 | if (task != null) { |
| 2740 | task.setTaskDockedResizing(false); |
Jorim Jaggi | 0b46f3c | 2016-03-14 12:21:37 +0100 | [diff] [blame] | 2741 | } |
| 2742 | } |
| 2743 | mResizingTasksDuringAnimation.clear(); |
| 2744 | } |
| 2745 | |
Wale Ogunwale | 04a05ac | 2017-09-17 21:35:02 -0700 | [diff] [blame] | 2746 | /** |
| 2747 | * 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] | 2748 | * Can do that once we are no longer using static stack ids. |
Wale Ogunwale | 04a05ac | 2017-09-17 21:35:02 -0700 | [diff] [blame] | 2749 | */ |
Wale Ogunwale | 9dcf946 | 2017-09-19 15:13:01 -0700 | [diff] [blame] | 2750 | private void moveTasksToFullscreenStackInSurfaceTransaction(ActivityStack fromStack, |
Wale Ogunwale | 04a05ac | 2017-09-17 21:35:02 -0700 | [diff] [blame] | 2751 | int toDisplayId, boolean onTop) { |
Robert Carr | 6914f08 | 2017-03-20 19:04:30 -0700 | [diff] [blame] | 2752 | |
Wale Ogunwale | c8da41e | 2016-04-16 13:27:23 -0700 | [diff] [blame] | 2753 | mWindowManager.deferSurfaceLayout(); |
| 2754 | try { |
Wale Ogunwale | 04a05ac | 2017-09-17 21:35:02 -0700 | [diff] [blame] | 2755 | final int windowingMode = fromStack.getWindowingMode(); |
| 2756 | final boolean inPinnedWindowingMode = windowingMode == WINDOWING_MODE_PINNED; |
| 2757 | final ActivityDisplay toDisplay = getActivityDisplay(toDisplayId); |
| 2758 | |
| 2759 | if (windowingMode == WINDOWING_MODE_SPLIT_SCREEN_PRIMARY) { |
Wale Ogunwale | 7e1f5f5 | 2017-10-18 15:19:59 -0700 | [diff] [blame] | 2760 | // Tell the display we are exiting split-screen mode. |
| 2761 | toDisplay.onExitingSplitScreenMode(); |
Wale Ogunwale | c8da41e | 2016-04-16 13:27:23 -0700 | [diff] [blame] | 2762 | // We are moving all tasks from the docked stack to the fullscreen stack, |
| 2763 | // which is dismissing the docked stack, so resize all other stacks to |
| 2764 | // fullscreen here already so we don't end up with resize trashing. |
Wale Ogunwale | a0f5b5e | 2017-10-11 09:37:23 -0700 | [diff] [blame] | 2765 | for (int i = toDisplay.getChildCount() - 1; i >= 0; --i) { |
| 2766 | final ActivityStack otherStack = toDisplay.getChildAt(i); |
Wale Ogunwale | 926aade | 2017-08-29 11:24:37 -0700 | [diff] [blame] | 2767 | if (!otherStack.inSplitScreenSecondaryWindowingMode()) { |
| 2768 | continue; |
| 2769 | } |
Wale Ogunwale | 44f036f | 2017-09-29 05:09:09 -0700 | [diff] [blame] | 2770 | resizeStackLocked(otherStack, null, null, null, PRESERVE_WINDOWS, |
Wale Ogunwale | 926aade | 2017-08-29 11:24:37 -0700 | [diff] [blame] | 2771 | true /* allowResizeInDockedMode */, DEFER_RESUME); |
Wale Ogunwale | c8da41e | 2016-04-16 13:27:23 -0700 | [diff] [blame] | 2772 | } |
| 2773 | |
| 2774 | // Also disable docked stack resizing since we have manually adjusted the |
| 2775 | // size of other stacks above and we don't want to trigger a docked stack |
| 2776 | // resize when we remove task from it below and it is detached from the |
| 2777 | // display because it no longer contains any tasks. |
| 2778 | mAllowDockedStackResize = false; |
| 2779 | } |
Wale Ogunwale | 04a05ac | 2017-09-17 21:35:02 -0700 | [diff] [blame] | 2780 | |
Winson Chung | 5af42fc | 2017-03-24 17:11:33 -0700 | [diff] [blame] | 2781 | // If we are moving from the pinned stack, then the animation takes care of updating |
| 2782 | // the picture-in-picture mode. |
Wale Ogunwale | 04a05ac | 2017-09-17 21:35:02 -0700 | [diff] [blame] | 2783 | final boolean schedulePictureInPictureModeChange = inPinnedWindowingMode; |
Wale Ogunwale | 9dcf946 | 2017-09-19 15:13:01 -0700 | [diff] [blame] | 2784 | final ArrayList<TaskRecord> tasks = fromStack.getAllTasks(); |
Wale Ogunwale | 04a05ac | 2017-09-17 21:35:02 -0700 | [diff] [blame] | 2785 | |
Wale Ogunwale | 388945c | 2017-10-04 12:13:46 -0700 | [diff] [blame] | 2786 | if (!tasks.isEmpty()) { |
Wale Ogunwale | 7e1f5f5 | 2017-10-18 15:19:59 -0700 | [diff] [blame] | 2787 | mTmpOptions.setLaunchWindowingMode(WINDOWING_MODE_FULLSCREEN); |
Wale Ogunwale | 388945c | 2017-10-04 12:13:46 -0700 | [diff] [blame] | 2788 | final int size = tasks.size(); |
Wale Ogunwale | 7e1f5f5 | 2017-10-18 15:19:59 -0700 | [diff] [blame] | 2789 | for (int i = 0; i < size; ++i) { |
| 2790 | final TaskRecord task = tasks.get(i); |
| 2791 | final ActivityStack toStack = toDisplay.getOrCreateStack( |
| 2792 | null, mTmpOptions, task, task.getActivityType(), onTop); |
Wale Ogunwale | 388945c | 2017-10-04 12:13:46 -0700 | [diff] [blame] | 2793 | |
Wale Ogunwale | 7e1f5f5 | 2017-10-18 15:19:59 -0700 | [diff] [blame] | 2794 | if (onTop) { |
Wale Ogunwale | 388945c | 2017-10-04 12:13:46 -0700 | [diff] [blame] | 2795 | final boolean isTopTask = i == (size - 1); |
Wale Ogunwale | 388945c | 2017-10-04 12:13:46 -0700 | [diff] [blame] | 2796 | // 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] | 2797 | task.reparent(toStack, ON_TOP, REPARENT_MOVE_STACK_TO_FRONT, |
Wale Ogunwale | 388945c | 2017-10-04 12:13:46 -0700 | [diff] [blame] | 2798 | isTopTask /* animate */, DEFER_RESUME, |
| 2799 | schedulePictureInPictureModeChange, |
| 2800 | "moveTasksToFullscreenStack - onTop"); |
Chenjie Yu | ae9fdf04 | 2018-02-15 10:19:32 -0800 | [diff] [blame] | 2801 | MetricsLoggerWrapper.logPictureInPictureFullScreen(mService.mContext, |
| 2802 | task.effectiveUid, task.realActivity.flattenToString()); |
Wale Ogunwale | 7e1f5f5 | 2017-10-18 15:19:59 -0700 | [diff] [blame] | 2803 | } else { |
Wale Ogunwale | 388945c | 2017-10-04 12:13:46 -0700 | [diff] [blame] | 2804 | // Position the tasks in the fullscreen stack in order at the bottom of the |
| 2805 | // stack. Also defer resume until all the tasks have been moved to the |
| 2806 | // fullscreen stack. |
Wale Ogunwale | 7e1f5f5 | 2017-10-18 15:19:59 -0700 | [diff] [blame] | 2807 | task.reparent(toStack, ON_TOP, |
Wale Ogunwale | 388945c | 2017-10-04 12:13:46 -0700 | [diff] [blame] | 2808 | REPARENT_LEAVE_STACK_IN_PLACE, !ANIMATE, DEFER_RESUME, |
| 2809 | schedulePictureInPictureModeChange, |
| 2810 | "moveTasksToFullscreenStack - NOT_onTop"); |
| 2811 | } |
Wale Ogunwale | c8da41e | 2016-04-16 13:27:23 -0700 | [diff] [blame] | 2812 | } |
| 2813 | } |
Winson Chung | 7466610 | 2017-02-22 17:49:24 -0800 | [diff] [blame] | 2814 | |
| 2815 | ensureActivitiesVisibleLocked(null, 0, PRESERVE_WINDOWS); |
| 2816 | resumeFocusedStackTopActivityLocked(); |
Wale Ogunwale | c8da41e | 2016-04-16 13:27:23 -0700 | [diff] [blame] | 2817 | } finally { |
| 2818 | mAllowDockedStackResize = true; |
| 2819 | mWindowManager.continueSurfaceLayout(); |
| 2820 | } |
| 2821 | } |
| 2822 | |
Wale Ogunwale | 9dcf946 | 2017-09-19 15:13:01 -0700 | [diff] [blame] | 2823 | void moveTasksToFullscreenStackLocked(ActivityStack fromStack, boolean onTop) { |
Wale Ogunwale | 04a05ac | 2017-09-17 21:35:02 -0700 | [diff] [blame] | 2824 | moveTasksToFullscreenStackLocked(fromStack, DEFAULT_DISPLAY, onTop); |
| 2825 | } |
| 2826 | |
| 2827 | void moveTasksToFullscreenStackLocked(ActivityStack fromStack, int toDisplayId, boolean onTop) { |
| 2828 | mWindowManager.inSurfaceTransaction(() -> |
| 2829 | moveTasksToFullscreenStackInSurfaceTransaction(fromStack, toDisplayId, onTop)); |
Robert Carr | 6914f08 | 2017-03-20 19:04:30 -0700 | [diff] [blame] | 2830 | } |
| 2831 | |
Adrian Roos | a6d6aab | 2018-04-19 18:58:22 +0200 | [diff] [blame] | 2832 | void setSplitScreenResizing(boolean resizing) { |
| 2833 | if (resizing == mDockedStackResizing) { |
| 2834 | return; |
| 2835 | } |
| 2836 | |
| 2837 | mDockedStackResizing = resizing; |
| 2838 | mWindowManager.setDockedStackResizing(resizing); |
| 2839 | |
| 2840 | if (!resizing && mHasPendingDockedBounds) { |
| 2841 | resizeDockedStackLocked(mPendingDockedBounds, mPendingTempDockedTaskBounds, |
| 2842 | mPendingTempDockedTaskInsetBounds, mPendingTempOtherTaskBounds, |
| 2843 | mPendingTempOtherTaskInsetBounds, PRESERVE_WINDOWS); |
| 2844 | |
| 2845 | mHasPendingDockedBounds = false; |
| 2846 | mPendingDockedBounds = null; |
| 2847 | mPendingTempDockedTaskBounds = null; |
| 2848 | mPendingTempDockedTaskInsetBounds = null; |
| 2849 | mPendingTempOtherTaskBounds = null; |
| 2850 | mPendingTempOtherTaskInsetBounds = null; |
| 2851 | } |
| 2852 | } |
| 2853 | |
Jorim Jaggi | dc249c4 | 2015-12-15 14:57:31 -0800 | [diff] [blame] | 2854 | void resizeDockedStackLocked(Rect dockedBounds, Rect tempDockedTaskBounds, |
Andrii Kulian | db3e4ec | 2016-07-12 17:11:35 -0700 | [diff] [blame] | 2855 | Rect tempDockedTaskInsetBounds, Rect tempOtherTaskBounds, Rect tempOtherTaskInsetBounds, |
| 2856 | boolean preserveWindows) { |
| 2857 | resizeDockedStackLocked(dockedBounds, tempDockedTaskBounds, tempDockedTaskInsetBounds, |
| 2858 | tempOtherTaskBounds, tempOtherTaskInsetBounds, preserveWindows, |
| 2859 | false /* deferResume */); |
| 2860 | } |
| 2861 | |
Wale Ogunwale | 04a05ac | 2017-09-17 21:35:02 -0700 | [diff] [blame] | 2862 | private void resizeDockedStackLocked(Rect dockedBounds, Rect tempDockedTaskBounds, |
Andrii Kulian | db3e4ec | 2016-07-12 17:11:35 -0700 | [diff] [blame] | 2863 | Rect tempDockedTaskInsetBounds, Rect tempOtherTaskBounds, Rect tempOtherTaskInsetBounds, |
| 2864 | boolean preserveWindows, boolean deferResume) { |
Wale Ogunwale | c8da41e | 2016-04-16 13:27:23 -0700 | [diff] [blame] | 2865 | |
| 2866 | if (!mAllowDockedStackResize) { |
| 2867 | // Docked stack resize currently disabled. |
| 2868 | return; |
| 2869 | } |
| 2870 | |
Wale Ogunwale | a0f5b5e | 2017-10-11 09:37:23 -0700 | [diff] [blame] | 2871 | final ActivityStack stack = getDefaultDisplay().getSplitScreenPrimaryStack(); |
Jorim Jaggi | dc249c4 | 2015-12-15 14:57:31 -0800 | [diff] [blame] | 2872 | if (stack == null) { |
| 2873 | Slog.w(TAG, "resizeDockedStackLocked: docked stack not found"); |
| 2874 | return; |
| 2875 | } |
| 2876 | |
Adrian Roos | a6d6aab | 2018-04-19 18:58:22 +0200 | [diff] [blame] | 2877 | if (mDockedStackResizing) { |
| 2878 | mHasPendingDockedBounds = true; |
| 2879 | mPendingDockedBounds = copyOrNull(dockedBounds); |
| 2880 | mPendingTempDockedTaskBounds = copyOrNull(tempDockedTaskBounds); |
| 2881 | mPendingTempDockedTaskInsetBounds = copyOrNull(tempDockedTaskInsetBounds); |
| 2882 | mPendingTempOtherTaskBounds = copyOrNull(tempOtherTaskBounds); |
| 2883 | mPendingTempOtherTaskInsetBounds = copyOrNull(tempOtherTaskInsetBounds); |
| 2884 | } |
| 2885 | |
Jorim Jaggi | dc249c4 | 2015-12-15 14:57:31 -0800 | [diff] [blame] | 2886 | Trace.traceBegin(TRACE_TAG_ACTIVITY_MANAGER, "am.resizeDockedStack"); |
| 2887 | mWindowManager.deferSurfaceLayout(); |
| 2888 | try { |
Wale Ogunwale | c8da41e | 2016-04-16 13:27:23 -0700 | [diff] [blame] | 2889 | // Don't allow re-entry while resizing. E.g. due to docked stack detaching. |
| 2890 | mAllowDockedStackResize = false; |
Jorim Jaggi | dc249c4 | 2015-12-15 14:57:31 -0800 | [diff] [blame] | 2891 | ActivityRecord r = stack.topRunningActivityLocked(); |
Wale Ogunwale | 1666e31 | 2016-12-16 11:27:18 -0800 | [diff] [blame] | 2892 | stack.resize(dockedBounds, tempDockedTaskBounds, tempDockedTaskInsetBounds); |
Jorim Jaggi | dc249c4 | 2015-12-15 14:57:31 -0800 | [diff] [blame] | 2893 | |
Andrii Kulian | 69fb5e4 | 2016-04-05 16:47:29 -0700 | [diff] [blame] | 2894 | // TODO: Checking for isAttached might not be needed as if the user passes in null |
| 2895 | // dockedBounds then they want the docked stack to be dismissed. |
Bryce Lee | f3c6a47 | 2017-11-14 14:53:06 -0800 | [diff] [blame] | 2896 | if (stack.getWindowingMode() == WINDOWING_MODE_FULLSCREEN |
| 2897 | || (dockedBounds == null && !stack.isAttached())) { |
Andrii Kulian | 69fb5e4 | 2016-04-05 16:47:29 -0700 | [diff] [blame] | 2898 | // 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] | 2899 | // In this case we make all other static stacks fullscreen and move all |
| 2900 | // docked stack tasks to the fullscreen stack. |
Wale Ogunwale | 9dcf946 | 2017-09-19 15:13:01 -0700 | [diff] [blame] | 2901 | moveTasksToFullscreenStackLocked(stack, ON_TOP); |
Jorim Jaggi | dc249c4 | 2015-12-15 14:57:31 -0800 | [diff] [blame] | 2902 | |
| 2903 | // stack shouldn't contain anymore activities, so nothing to resume. |
| 2904 | r = null; |
| 2905 | } else { |
| 2906 | // Docked stacks occupy a dedicated region on screen so the size of all other |
| 2907 | // static stacks need to be adjusted so they don't overlap with the docked stack. |
| 2908 | // We get the bounds to use from window manager which has been adjusted for any |
| 2909 | // screen controls and is also the same for all stacks. |
Wale Ogunwale | a0f5b5e | 2017-10-11 09:37:23 -0700 | [diff] [blame] | 2910 | final ActivityDisplay display = getDefaultDisplay(); |
Matthew Ng | aa2b620 | 2017-02-10 14:48:21 -0800 | [diff] [blame] | 2911 | final Rect otherTaskRect = new Rect(); |
Wale Ogunwale | a0f5b5e | 2017-10-11 09:37:23 -0700 | [diff] [blame] | 2912 | for (int i = display.getChildCount() - 1; i >= 0; --i) { |
| 2913 | final ActivityStack current = display.getChildAt(i); |
Wale Ogunwale | 04a05ac | 2017-09-17 21:35:02 -0700 | [diff] [blame] | 2914 | if (current.getWindowingMode() == WINDOWING_MODE_SPLIT_SCREEN_PRIMARY) { |
Wale Ogunwale | 926aade | 2017-08-29 11:24:37 -0700 | [diff] [blame] | 2915 | continue; |
Jorim Jaggi | dc249c4 | 2015-12-15 14:57:31 -0800 | [diff] [blame] | 2916 | } |
Wale Ogunwale | 2b07da8 | 2017-11-08 14:52:40 -0800 | [diff] [blame] | 2917 | if (!current.affectedBySplitScreenResize()) { |
Wale Ogunwale | 926aade | 2017-08-29 11:24:37 -0700 | [diff] [blame] | 2918 | continue; |
| 2919 | } |
Adrian Roos | a6d6aab | 2018-04-19 18:58:22 +0200 | [diff] [blame] | 2920 | if (mDockedStackResizing && !current.isTopActivityVisible()) { |
| 2921 | // Non-visible stacks get resized once we're done with the resize |
| 2922 | // interaction. |
| 2923 | continue; |
| 2924 | } |
Wale Ogunwale | 926aade | 2017-08-29 11:24:37 -0700 | [diff] [blame] | 2925 | // Need to set windowing mode here before we try to get the dock bounds. |
| 2926 | current.setWindowingMode(WINDOWING_MODE_SPLIT_SCREEN_SECONDARY); |
| 2927 | current.getStackDockedModeBounds( |
| 2928 | tempOtherTaskBounds /* currentTempTaskBounds */, |
| 2929 | tempRect /* outStackBounds */, |
| 2930 | otherTaskRect /* outTempTaskBounds */, true /* ignoreVisibility */); |
| 2931 | |
Wale Ogunwale | 44f036f | 2017-09-29 05:09:09 -0700 | [diff] [blame] | 2932 | resizeStackLocked(current, !tempRect.isEmpty() ? tempRect : null, |
Wale Ogunwale | 926aade | 2017-08-29 11:24:37 -0700 | [diff] [blame] | 2933 | !otherTaskRect.isEmpty() ? otherTaskRect : tempOtherTaskBounds, |
| 2934 | tempOtherTaskInsetBounds, preserveWindows, |
| 2935 | true /* allowResizeInDockedMode */, deferResume); |
Jorim Jaggi | dc249c4 | 2015-12-15 14:57:31 -0800 | [diff] [blame] | 2936 | } |
| 2937 | } |
Andrii Kulian | db3e4ec | 2016-07-12 17:11:35 -0700 | [diff] [blame] | 2938 | if (!deferResume) { |
| 2939 | stack.ensureVisibleActivitiesConfigurationLocked(r, preserveWindows); |
| 2940 | } |
Jorim Jaggi | dc249c4 | 2015-12-15 14:57:31 -0800 | [diff] [blame] | 2941 | } finally { |
Wale Ogunwale | c8da41e | 2016-04-16 13:27:23 -0700 | [diff] [blame] | 2942 | mAllowDockedStackResize = true; |
Jorim Jaggi | dc249c4 | 2015-12-15 14:57:31 -0800 | [diff] [blame] | 2943 | mWindowManager.continueSurfaceLayout(); |
| 2944 | Trace.traceEnd(TRACE_TAG_ACTIVITY_MANAGER); |
| 2945 | } |
Jorim Jaggi | dc249c4 | 2015-12-15 14:57:31 -0800 | [diff] [blame] | 2946 | } |
| 2947 | |
Robert Carr | 0d00c2e | 2016-02-29 17:45:02 -0800 | [diff] [blame] | 2948 | void resizePinnedStackLocked(Rect pinnedBounds, Rect tempPinnedTaskBounds) { |
Wale Ogunwale | 04a05ac | 2017-09-17 21:35:02 -0700 | [diff] [blame] | 2949 | // TODO(multi-display): Pinned stack display should be passed in. |
Wale Ogunwale | a0f5b5e | 2017-10-11 09:37:23 -0700 | [diff] [blame] | 2950 | final PinnedActivityStack stack = getDefaultDisplay().getPinnedStack(); |
Robert Carr | 0d00c2e | 2016-02-29 17:45:02 -0800 | [diff] [blame] | 2951 | if (stack == null) { |
| 2952 | Slog.w(TAG, "resizePinnedStackLocked: pinned stack not found"); |
| 2953 | return; |
| 2954 | } |
Winson Chung | 19953ca | 2017-04-11 11:19:23 -0700 | [diff] [blame] | 2955 | |
| 2956 | // It is possible for the bounds animation from the WM to call this but be delayed by |
| 2957 | // another AM call that is holding the AMS lock. In such a case, the pinnedBounds may be |
| 2958 | // incorrect if AMS.resizeStackWithBoundsFromWindowManager() is already called while waiting |
| 2959 | // for the AMS lock to be freed. So check and make sure these bounds are still good. |
| 2960 | final PinnedStackWindowController stackController = stack.getWindowContainerController(); |
Winson Chung | 8bca9e4 | 2017-04-16 15:59:43 -0700 | [diff] [blame] | 2961 | if (stackController.pinnedStackResizeDisallowed()) { |
Winson Chung | 19953ca | 2017-04-11 11:19:23 -0700 | [diff] [blame] | 2962 | return; |
| 2963 | } |
| 2964 | |
Robert Carr | 0d00c2e | 2016-02-29 17:45:02 -0800 | [diff] [blame] | 2965 | Trace.traceBegin(TRACE_TAG_ACTIVITY_MANAGER, "am.resizePinnedStack"); |
| 2966 | mWindowManager.deferSurfaceLayout(); |
| 2967 | try { |
| 2968 | ActivityRecord r = stack.topRunningActivityLocked(); |
Robert Carr | 7e4c90e | 2017-02-15 19:52:38 -0800 | [diff] [blame] | 2969 | Rect insetBounds = null; |
Adrian Roos | 3e80b60 | 2018-04-30 12:42:36 +0200 | [diff] [blame] | 2970 | if (tempPinnedTaskBounds != null && stack.isAnimatingBoundsToFullscreen()) { |
| 2971 | // 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] | 2972 | insetBounds = tempRect; |
| 2973 | insetBounds.top = 0; |
| 2974 | insetBounds.left = 0; |
| 2975 | insetBounds.right = tempPinnedTaskBounds.width(); |
| 2976 | insetBounds.bottom = tempPinnedTaskBounds.height(); |
| 2977 | } |
Winson Chung | 15036ca | 2018-05-31 15:51:47 -0700 | [diff] [blame] | 2978 | if (pinnedBounds != null && tempPinnedTaskBounds == null) { |
| 2979 | // We have finished the animation into PiP, and are resizing the tasks to match the |
| 2980 | // stack bounds, while layouts are deferred, update any task state as a part of |
| 2981 | // transitioning it from fullscreen into a floating state. |
| 2982 | stack.onPipAnimationEndResize(); |
| 2983 | } |
Robert Carr | 7e4c90e | 2017-02-15 19:52:38 -0800 | [diff] [blame] | 2984 | stack.resize(pinnedBounds, tempPinnedTaskBounds, insetBounds); |
Wale Ogunwale | db0fa12 | 2016-05-16 15:12:03 -0700 | [diff] [blame] | 2985 | stack.ensureVisibleActivitiesConfigurationLocked(r, false); |
Robert Carr | 0d00c2e | 2016-02-29 17:45:02 -0800 | [diff] [blame] | 2986 | } finally { |
| 2987 | mWindowManager.continueSurfaceLayout(); |
| 2988 | Trace.traceEnd(TRACE_TAG_ACTIVITY_MANAGER); |
| 2989 | } |
| 2990 | } |
| 2991 | |
Wale Ogunwale | a0f5b5e | 2017-10-11 09:37:23 -0700 | [diff] [blame] | 2992 | private void removeStackInSurfaceTransaction(ActivityStack stack) { |
Winson Chung | 010927a | 2016-12-15 16:12:35 -0800 | [diff] [blame] | 2993 | final ArrayList<TaskRecord> tasks = stack.getAllTasks(); |
Wale Ogunwale | 04a05ac | 2017-09-17 21:35:02 -0700 | [diff] [blame] | 2994 | if (stack.getWindowingMode() == WINDOWING_MODE_PINNED) { |
Winson Chung | 4790065 | 2017-04-06 18:44:25 -0700 | [diff] [blame] | 2995 | /** |
| 2996 | * Workaround: Force-stop all the activities in the pinned stack before we reparent them |
| 2997 | * to the fullscreen stack. This is to guarantee that when we are removing a stack, |
| 2998 | * that the client receives onStop() before it is reparented. We do this by detaching |
| 2999 | * the stack from the display so that it will be considered invisible when |
| 3000 | * ensureActivitiesVisibleLocked() is called, and all of its activitys will be marked |
| 3001 | * invisible as well and added to the stopping list. After which we process the |
| 3002 | * stopping list by handling the idle. |
| 3003 | */ |
| 3004 | final PinnedActivityStack pinnedStack = (PinnedActivityStack) stack; |
| 3005 | pinnedStack.mForceHidden = true; |
| 3006 | pinnedStack.ensureActivitiesVisibleLocked(null, 0, PRESERVE_WINDOWS); |
| 3007 | pinnedStack.mForceHidden = false; |
| 3008 | activityIdleInternalLocked(null, false /* fromTimeout */, |
| 3009 | true /* processPausingActivites */, null /* configuration */); |
| 3010 | |
| 3011 | // Move all the tasks to the bottom of the fullscreen stack |
Wale Ogunwale | 9dcf946 | 2017-09-19 15:13:01 -0700 | [diff] [blame] | 3012 | moveTasksToFullscreenStackLocked(pinnedStack, !ON_TOP); |
Winson Chung | 010927a | 2016-12-15 16:12:35 -0800 | [diff] [blame] | 3013 | } else { |
| 3014 | for (int i = tasks.size() - 1; i >= 0; i--) { |
| 3015 | removeTaskByIdLocked(tasks.get(i).taskId, true /* killProcess */, |
Winson Chung | 0ec2a35 | 2017-10-26 11:38:30 -0700 | [diff] [blame] | 3016 | REMOVE_FROM_RECENTS, "remove-stack"); |
Winson Chung | 010927a | 2016-12-15 16:12:35 -0800 | [diff] [blame] | 3017 | } |
| 3018 | } |
| 3019 | } |
| 3020 | |
| 3021 | /** |
Wale Ogunwale | a0f5b5e | 2017-10-11 09:37:23 -0700 | [diff] [blame] | 3022 | * 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] | 3023 | * pinned stack, then its tasks are not explicitly removed when the stack is destroyed, but |
| 3024 | * instead moved back onto the fullscreen stack. |
| 3025 | */ |
Wale Ogunwale | a0f5b5e | 2017-10-11 09:37:23 -0700 | [diff] [blame] | 3026 | void removeStack(ActivityStack stack) { |
| 3027 | mWindowManager.inSurfaceTransaction(() -> removeStackInSurfaceTransaction(stack)); |
Wale Ogunwale | 04a05ac | 2017-09-17 21:35:02 -0700 | [diff] [blame] | 3028 | } |
| 3029 | |
Wale Ogunwale | 6827856 | 2017-09-23 17:13:55 -0700 | [diff] [blame] | 3030 | /** |
| 3031 | * Removes stacks in the input windowing modes from the system if they are of activity type |
| 3032 | * ACTIVITY_TYPE_STANDARD or ACTIVITY_TYPE_UNDEFINED |
| 3033 | */ |
| 3034 | void removeStacksInWindowingModes(int... windowingModes) { |
Wale Ogunwale | 04a05ac | 2017-09-17 21:35:02 -0700 | [diff] [blame] | 3035 | for (int i = mActivityDisplays.size() - 1; i >= 0; --i) { |
Wale Ogunwale | 6827856 | 2017-09-23 17:13:55 -0700 | [diff] [blame] | 3036 | mActivityDisplays.valueAt(i).removeStacksInWindowingModes(windowingModes); |
| 3037 | } |
| 3038 | } |
| 3039 | |
| 3040 | void removeStacksWithActivityTypes(int... activityTypes) { |
| 3041 | for (int i = mActivityDisplays.size() - 1; i >= 0; --i) { |
| 3042 | mActivityDisplays.valueAt(i).removeStacksWithActivityTypes(activityTypes); |
Wale Ogunwale | 04a05ac | 2017-09-17 21:35:02 -0700 | [diff] [blame] | 3043 | } |
Robert Carr | 6914f08 | 2017-03-20 19:04:30 -0700 | [diff] [blame] | 3044 | } |
| 3045 | |
| 3046 | /** |
Winson Chung | 6954fc9 | 2017-03-24 16:22:12 -0700 | [diff] [blame] | 3047 | * See {@link #removeTaskByIdLocked(int, boolean, boolean, boolean)} |
| 3048 | */ |
Winson Chung | 0ec2a35 | 2017-10-26 11:38:30 -0700 | [diff] [blame] | 3049 | boolean removeTaskByIdLocked(int taskId, boolean killProcess, boolean removeFromRecents, |
| 3050 | String reason) { |
| 3051 | return removeTaskByIdLocked(taskId, killProcess, removeFromRecents, !PAUSE_IMMEDIATELY, |
| 3052 | reason); |
Winson Chung | 6954fc9 | 2017-03-24 16:22:12 -0700 | [diff] [blame] | 3053 | } |
| 3054 | |
| 3055 | /** |
Winson Chung | 010927a | 2016-12-15 16:12:35 -0800 | [diff] [blame] | 3056 | * Removes the task with the specified task id. |
| 3057 | * |
| 3058 | * @param taskId Identifier of the task to be removed. |
| 3059 | * @param killProcess Kill any process associated with the task if possible. |
| 3060 | * @param removeFromRecents Whether to also remove the task from recents. |
Winson Chung | 6954fc9 | 2017-03-24 16:22:12 -0700 | [diff] [blame] | 3061 | * @param pauseImmediately Pauses all task activities immediately without waiting for the |
| 3062 | * pause-complete callback from the activity. |
Winson Chung | 010927a | 2016-12-15 16:12:35 -0800 | [diff] [blame] | 3063 | * @return Returns true if the given task was found and removed. |
| 3064 | */ |
Winson Chung | 6954fc9 | 2017-03-24 16:22:12 -0700 | [diff] [blame] | 3065 | boolean removeTaskByIdLocked(int taskId, boolean killProcess, boolean removeFromRecents, |
Winson Chung | 0ec2a35 | 2017-10-26 11:38:30 -0700 | [diff] [blame] | 3066 | boolean pauseImmediately, String reason) { |
Wale Ogunwale | 0568aed | 2017-09-08 13:29:37 -0700 | [diff] [blame] | 3067 | final TaskRecord tr = anyTaskForIdLocked(taskId, MATCH_TASK_IN_STACKS_OR_RECENT_TASKS); |
Winson Chung | 010927a | 2016-12-15 16:12:35 -0800 | [diff] [blame] | 3068 | if (tr != null) { |
Winson Chung | 0ec2a35 | 2017-10-26 11:38:30 -0700 | [diff] [blame] | 3069 | tr.removeTaskActivitiesLocked(pauseImmediately, reason); |
Winson Chung | 010927a | 2016-12-15 16:12:35 -0800 | [diff] [blame] | 3070 | cleanUpRemovedTaskLocked(tr, killProcess, removeFromRecents); |
Bryce Lee | 2b8e037 | 2018-04-05 17:01:37 -0700 | [diff] [blame] | 3071 | mService.getLockTaskController().clearLockedTask(tr); |
Winson Chung | 010927a | 2016-12-15 16:12:35 -0800 | [diff] [blame] | 3072 | if (tr.isPersistable) { |
| 3073 | mService.notifyTaskPersisterLocked(null, true); |
| 3074 | } |
| 3075 | return true; |
| 3076 | } |
| 3077 | Slog.w(TAG, "Request to remove task ignored for non-existent task " + taskId); |
| 3078 | return false; |
| 3079 | } |
| 3080 | |
| 3081 | void cleanUpRemovedTaskLocked(TaskRecord tr, boolean killProcess, boolean removeFromRecents) { |
| 3082 | if (removeFromRecents) { |
Winson Chung | 1dbc811 | 2017-09-28 18:05:31 -0700 | [diff] [blame] | 3083 | mRecentTasks.remove(tr); |
Winson Chung | 010927a | 2016-12-15 16:12:35 -0800 | [diff] [blame] | 3084 | } |
| 3085 | ComponentName component = tr.getBaseIntent().getComponent(); |
| 3086 | if (component == null) { |
| 3087 | Slog.w(TAG, "No component for base intent of task: " + tr); |
| 3088 | return; |
| 3089 | } |
| 3090 | |
| 3091 | // Find any running services associated with this app and stop if needed. |
| 3092 | mService.mServices.cleanUpRemovedTaskLocked(tr, component, new Intent(tr.getBaseIntent())); |
| 3093 | |
| 3094 | if (!killProcess) { |
| 3095 | return; |
| 3096 | } |
| 3097 | |
| 3098 | // Determine if the process(es) for this task should be killed. |
| 3099 | final String pkg = component.getPackageName(); |
| 3100 | ArrayList<ProcessRecord> procsToKill = new ArrayList<>(); |
| 3101 | ArrayMap<String, SparseArray<ProcessRecord>> pmap = mService.mProcessNames.getMap(); |
| 3102 | for (int i = 0; i < pmap.size(); i++) { |
| 3103 | |
| 3104 | SparseArray<ProcessRecord> uids = pmap.valueAt(i); |
| 3105 | for (int j = 0; j < uids.size(); j++) { |
| 3106 | ProcessRecord proc = uids.valueAt(j); |
| 3107 | if (proc.userId != tr.userId) { |
| 3108 | // Don't kill process for a different user. |
| 3109 | continue; |
| 3110 | } |
| 3111 | if (proc == mService.mHomeProcess) { |
| 3112 | // Don't kill the home process along with tasks from the same package. |
| 3113 | continue; |
| 3114 | } |
| 3115 | if (!proc.pkgList.containsKey(pkg)) { |
| 3116 | // Don't kill process that is not associated with this task. |
| 3117 | continue; |
| 3118 | } |
| 3119 | |
| 3120 | for (int k = 0; k < proc.activities.size(); k++) { |
Bryce Lee | af691c0 | 2017-03-20 14:20:22 -0700 | [diff] [blame] | 3121 | TaskRecord otherTask = proc.activities.get(k).getTask(); |
Winson Chung | 010927a | 2016-12-15 16:12:35 -0800 | [diff] [blame] | 3122 | if (tr.taskId != otherTask.taskId && otherTask.inRecents) { |
| 3123 | // Don't kill process(es) that has an activity in a different task that is |
| 3124 | // also in recents. |
| 3125 | return; |
| 3126 | } |
| 3127 | } |
| 3128 | |
| 3129 | if (proc.foregroundServices) { |
| 3130 | // Don't kill process(es) with foreground service. |
| 3131 | return; |
| 3132 | } |
| 3133 | |
| 3134 | // Add process to kill list. |
| 3135 | procsToKill.add(proc); |
| 3136 | } |
| 3137 | } |
| 3138 | |
| 3139 | // Kill the running processes. |
| 3140 | for (int i = 0; i < procsToKill.size(); i++) { |
| 3141 | ProcessRecord pr = procsToKill.get(i); |
| 3142 | if (pr.setSchedGroup == ProcessList.SCHED_GROUP_BACKGROUND |
| 3143 | && pr.curReceivers.isEmpty()) { |
| 3144 | pr.kill("remove task", true); |
| 3145 | } else { |
| 3146 | // We delay killing processes that are not in the background or running a receiver. |
| 3147 | pr.waitingToKill = "remove task"; |
| 3148 | } |
| 3149 | } |
| 3150 | } |
| 3151 | |
Chong Zhang | 5dcb275 | 2015-08-18 13:50:26 -0700 | [diff] [blame] | 3152 | /** |
Winson Chung | 1dbc811 | 2017-09-28 18:05:31 -0700 | [diff] [blame] | 3153 | * Called to restore the state of the task into the stack that it's supposed to go into. |
| 3154 | * |
Chong Zhang | 5dcb275 | 2015-08-18 13:50:26 -0700 | [diff] [blame] | 3155 | * @param task The recent task to be restored. |
Wale Ogunwale | 0568aed | 2017-09-08 13:29:37 -0700 | [diff] [blame] | 3156 | * @param aOptions The activity options to use for restoration. |
Wale Ogunwale | ab5de37 | 2017-10-18 06:46:31 -0700 | [diff] [blame] | 3157 | * @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] | 3158 | * @return true if the task has been restored successfully. |
| 3159 | */ |
Wale Ogunwale | ab5de37 | 2017-10-18 06:46:31 -0700 | [diff] [blame] | 3160 | boolean restoreRecentTaskLocked(TaskRecord task, ActivityOptions aOptions, boolean onTop) { |
| 3161 | final ActivityStack stack = getLaunchStack(null, aOptions, task, onTop); |
Andrii Kulian | 02b7a83 | 2016-10-06 23:11:56 -0700 | [diff] [blame] | 3162 | final ActivityStack currentStack = task.getStack(); |
| 3163 | if (currentStack != null) { |
Wale Ogunwale | 706ed79 | 2015-08-02 10:29:44 -0700 | [diff] [blame] | 3164 | // 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] | 3165 | if (currentStack == stack) { |
Wale Ogunwale | 706ed79 | 2015-08-02 10:29:44 -0700 | [diff] [blame] | 3166 | // Nothing else to do since it is already restored in the right stack. |
| 3167 | return true; |
| 3168 | } |
| 3169 | // Remove current stack association, so we can re-associate the task with the |
| 3170 | // right stack below. |
Andrii Kulian | 02b7a83 | 2016-10-06 23:11:56 -0700 | [diff] [blame] | 3171 | currentStack.removeTask(task, "restoreRecentTaskLocked", REMOVE_TASK_MODE_MOVING); |
Wale Ogunwale | 706ed79 | 2015-08-02 10:29:44 -0700 | [diff] [blame] | 3172 | } |
| 3173 | |
Wale Ogunwale | ab5de37 | 2017-10-18 06:46:31 -0700 | [diff] [blame] | 3174 | stack.addTask(task, onTop, "restoreRecentTask"); |
Wale Ogunwale | e1fe7fa2 | 2016-12-15 18:27:00 -0800 | [diff] [blame] | 3175 | // TODO: move call for creation here and other place into Stack.addTask() |
Wale Ogunwale | ab5de37 | 2017-10-18 06:46:31 -0700 | [diff] [blame] | 3176 | task.createWindowContainer(onTop, true /* showForAllUsers */); |
Wale Ogunwale | ee006da | 2015-03-30 14:49:25 -0700 | [diff] [blame] | 3177 | if (DEBUG_RECENTS) Slog.v(TAG_RECENTS, |
| 3178 | "Added restored task=" + task + " to stack=" + stack); |
Wale Ogunwale | 7de0535 | 2014-12-12 15:21:33 -0800 | [diff] [blame] | 3179 | final ArrayList<ActivityRecord> activities = task.mActivities; |
| 3180 | for (int activityNdx = activities.size() - 1; activityNdx >= 0; --activityNdx) { |
Wale Ogunwale | 26c0dfe | 2016-12-14 14:42:30 -0800 | [diff] [blame] | 3181 | activities.get(activityNdx).createWindowContainer(); |
Wale Ogunwale | 7de0535 | 2014-12-12 15:21:33 -0800 | [diff] [blame] | 3182 | } |
| 3183 | return true; |
Craig Mautner | ef73ee1 | 2014-04-23 11:45:37 -0700 | [diff] [blame] | 3184 | } |
| 3185 | |
Winson Chung | 1dbc811 | 2017-09-28 18:05:31 -0700 | [diff] [blame] | 3186 | @Override |
| 3187 | public void onRecentTaskAdded(TaskRecord task) { |
| 3188 | task.touchActiveTime(); |
| 3189 | } |
| 3190 | |
| 3191 | @Override |
Winson Chung | d6aa3db | 2017-10-05 17:18:43 -0700 | [diff] [blame] | 3192 | public void onRecentTaskRemoved(TaskRecord task, boolean wasTrimmed) { |
Winson Chung | 0ec2a35 | 2017-10-26 11:38:30 -0700 | [diff] [blame] | 3193 | if (wasTrimmed) { |
| 3194 | // Task was trimmed from the recent tasks list -- remove the active task record as well |
| 3195 | // since the user won't really be able to go back to it |
| 3196 | removeTaskByIdLocked(task.taskId, false /* killProcess */, |
| 3197 | false /* removeFromRecents */, !PAUSE_IMMEDIATELY, "recent-task-trimmed"); |
| 3198 | } |
Winson Chung | 1dbc811 | 2017-09-28 18:05:31 -0700 | [diff] [blame] | 3199 | task.removedFromRecents(); |
| 3200 | } |
| 3201 | |
Wale Ogunwale | 040b470 | 2015-08-06 18:10:50 -0700 | [diff] [blame] | 3202 | /** |
Andrii Kulian | 839def9 | 2016-11-02 10:58:58 -0700 | [diff] [blame] | 3203 | * Move stack with all its existing content to specified display. |
| 3204 | * @param stackId Id of stack to move. |
| 3205 | * @param displayId Id of display to move stack to. |
Andrii Kulian | 250d653 | 2017-02-08 23:30:45 -0800 | [diff] [blame] | 3206 | * @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] | 3207 | */ |
Andrii Kulian | 250d653 | 2017-02-08 23:30:45 -0800 | [diff] [blame] | 3208 | void moveStackToDisplayLocked(int stackId, int displayId, boolean onTop) { |
Andrii Kulian | 62e6f25 | 2017-05-30 22:46:53 -0700 | [diff] [blame] | 3209 | final ActivityDisplay activityDisplay = getActivityDisplayOrCreateLocked(displayId); |
Andrii Kulian | 839def9 | 2016-11-02 10:58:58 -0700 | [diff] [blame] | 3210 | if (activityDisplay == null) { |
| 3211 | throw new IllegalArgumentException("moveStackToDisplayLocked: Unknown displayId=" |
| 3212 | + displayId); |
| 3213 | } |
Wale Ogunwale | 9dcf946 | 2017-09-19 15:13:01 -0700 | [diff] [blame] | 3214 | final ActivityStack stack = getStack(stackId); |
Andrii Kulian | 94e82d9b0 | 2017-07-13 15:33:06 -0700 | [diff] [blame] | 3215 | if (stack == null) { |
Andrii Kulian | 839def9 | 2016-11-02 10:58:58 -0700 | [diff] [blame] | 3216 | throw new IllegalArgumentException("moveStackToDisplayLocked: Unknown stackId=" |
| 3217 | + stackId); |
| 3218 | } |
Andrii Kulian | 94e82d9b0 | 2017-07-13 15:33:06 -0700 | [diff] [blame] | 3219 | |
| 3220 | final ActivityDisplay currentDisplay = stack.getDisplay(); |
| 3221 | if (currentDisplay == null) { |
| 3222 | throw new IllegalStateException("moveStackToDisplayLocked: Stack with stack=" + stack |
| 3223 | + " is not attached to any display."); |
| 3224 | } |
| 3225 | |
| 3226 | if (currentDisplay.mDisplayId == displayId) { |
| 3227 | throw new IllegalArgumentException("Trying to move stack=" + stack |
| 3228 | + " to its current displayId=" + displayId); |
| 3229 | } |
| 3230 | |
| 3231 | stack.reparent(activityDisplay, onTop); |
Andrii Kulian | 839def9 | 2016-11-02 10:58:58 -0700 | [diff] [blame] | 3232 | // TODO(multi-display): resize stacks properly if moved from split-screen. |
| 3233 | } |
| 3234 | |
| 3235 | /** |
Winson Chung | 7466610 | 2017-02-22 17:49:24 -0800 | [diff] [blame] | 3236 | * Returns the reparent target stack, creating the stack if necessary. This call also enforces |
| 3237 | * 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] | 3238 | */ |
Wale Ogunwale | 30e441d | 2017-11-09 08:28:45 -0800 | [diff] [blame] | 3239 | // TODO: Look into changing users to this method to ActivityDisplay.resolveWindowingMode() |
Wale Ogunwale | 04a05ac | 2017-09-17 21:35:02 -0700 | [diff] [blame] | 3240 | ActivityStack getReparentTargetStack(TaskRecord task, ActivityStack stack, boolean toTop) { |
Andrii Kulian | 02b7a83 | 2016-10-06 23:11:56 -0700 | [diff] [blame] | 3241 | final ActivityStack prevStack = task.getStack(); |
Wale Ogunwale | 04a05ac | 2017-09-17 21:35:02 -0700 | [diff] [blame] | 3242 | final int stackId = stack.mStackId; |
| 3243 | final boolean inMultiWindowMode = stack.inMultiWindowMode(); |
Chong Zhang | 0289835 | 2015-08-21 17:27:14 -0700 | [diff] [blame] | 3244 | |
Winson Chung | 7466610 | 2017-02-22 17:49:24 -0800 | [diff] [blame] | 3245 | // Check that we aren't reparenting to the same stack that the task is already in |
| 3246 | if (prevStack != null && prevStack.mStackId == stackId) { |
| 3247 | Slog.w(TAG, "Can not reparent to same stack, task=" + task |
| 3248 | + " already in stackId=" + stackId); |
| 3249 | return prevStack; |
Wale Ogunwale | 513346d | 2016-01-27 10:55:01 -0800 | [diff] [blame] | 3250 | } |
| 3251 | |
Winson Chung | 7466610 | 2017-02-22 17:49:24 -0800 | [diff] [blame] | 3252 | // Ensure that we aren't trying to move into a multi-window stack without multi-window |
| 3253 | // support |
Wale Ogunwale | 04a05ac | 2017-09-17 21:35:02 -0700 | [diff] [blame] | 3254 | if (inMultiWindowMode && !mService.mSupportsMultiWindow) { |
Winson Chung | 7466610 | 2017-02-22 17:49:24 -0800 | [diff] [blame] | 3255 | throw new IllegalArgumentException("Device doesn't support multi-window, can not" |
Wale Ogunwale | 04a05ac | 2017-09-17 21:35:02 -0700 | [diff] [blame] | 3256 | + " reparent task=" + task + " to stack=" + stack); |
Winson Chung | c2baac0 | 2017-01-11 13:34:47 -0800 | [diff] [blame] | 3257 | } |
| 3258 | |
Andrii Kulian | eafd9db | 2017-04-05 22:01:35 -0700 | [diff] [blame] | 3259 | // Ensure that we're not moving a task to a dynamic stack if device doesn't support |
| 3260 | // multi-display. |
Wale Ogunwale | 04a05ac | 2017-09-17 21:35:02 -0700 | [diff] [blame] | 3261 | if (stack.mDisplayId != DEFAULT_DISPLAY && !mService.mSupportsMultiDisplay) { |
Andrii Kulian | eafd9db | 2017-04-05 22:01:35 -0700 | [diff] [blame] | 3262 | throw new IllegalArgumentException("Device doesn't support multi-display, can not" |
| 3263 | + " reparent task=" + task + " to stackId=" + stackId); |
| 3264 | } |
| 3265 | |
Wale Ogunwale | 30e441d | 2017-11-09 08:28:45 -0800 | [diff] [blame] | 3266 | // 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] | 3267 | if (stack.getWindowingMode() == WINDOWING_MODE_FREEFORM |
| 3268 | && !mService.mSupportsFreeformWindowManagement) { |
Winson Chung | 7466610 | 2017-02-22 17:49:24 -0800 | [diff] [blame] | 3269 | throw new IllegalArgumentException("Device doesn't support freeform, can not reparent" |
| 3270 | + " task=" + task); |
Wale Ogunwale | 08559dc | 2016-02-23 12:20:08 -0800 | [diff] [blame] | 3271 | } |
| 3272 | |
Wale Ogunwale | 7e1f5f5 | 2017-10-18 15:19:59 -0700 | [diff] [blame] | 3273 | // Leave the task in its current stack or a fullscreen stack if it isn't resizeable and the |
| 3274 | // preferred stack is in multi-window mode. |
Wale Ogunwale | 04a05ac | 2017-09-17 21:35:02 -0700 | [diff] [blame] | 3275 | if (inMultiWindowMode && !task.isResizeable()) { |
Wale Ogunwale | 7e1f5f5 | 2017-10-18 15:19:59 -0700 | [diff] [blame] | 3276 | Slog.w(TAG, "Can not move unresizeable task=" + task + " to multi-window stack=" + stack |
| 3277 | + " Moving to a fullscreen stack instead."); |
| 3278 | if (prevStack != null) { |
| 3279 | return prevStack; |
Wale Ogunwale | 04a05ac | 2017-09-17 21:35:02 -0700 | [diff] [blame] | 3280 | } |
Wale Ogunwale | 7e1f5f5 | 2017-10-18 15:19:59 -0700 | [diff] [blame] | 3281 | stack = stack.getDisplay().createStack( |
| 3282 | WINDOWING_MODE_FULLSCREEN, stack.getActivityType(), toTop); |
Filip Gruszczynski | 49b80af | 2015-09-24 09:04:26 -0700 | [diff] [blame] | 3283 | } |
Wale Ogunwale | 04a05ac | 2017-09-17 21:35:02 -0700 | [diff] [blame] | 3284 | return stack; |
Craig Mautner | 8d341ef | 2013-03-26 09:03:27 -0700 | [diff] [blame] | 3285 | } |
| 3286 | |
Winson Chung | 08f8189 | 2017-03-02 15:40:51 -0800 | [diff] [blame] | 3287 | boolean moveTopStackActivityToPinnedStackLocked(int stackId, Rect destBounds) { |
Wale Ogunwale | 04a05ac | 2017-09-17 21:35:02 -0700 | [diff] [blame] | 3288 | final ActivityStack stack = getStack(stackId); |
Wale Ogunwale | 079a004 | 2015-10-24 11:44:07 -0700 | [diff] [blame] | 3289 | if (stack == null) { |
| 3290 | throw new IllegalArgumentException( |
| 3291 | "moveTopStackActivityToPinnedStackLocked: Unknown stackId=" + stackId); |
| 3292 | } |
| 3293 | |
| 3294 | final ActivityRecord r = stack.topRunningActivityLocked(); |
| 3295 | if (r == null) { |
| 3296 | Slog.w(TAG, "moveTopStackActivityToPinnedStackLocked: No top running activity" |
| 3297 | + " in stack=" + stack); |
| 3298 | return false; |
| 3299 | } |
| 3300 | |
Wale Ogunwale | 6cae765 | 2015-12-26 07:36:26 -0800 | [diff] [blame] | 3301 | if (!mService.mForceResizableActivities && !r.supportsPictureInPicture()) { |
Wale Ogunwale | b60692e | 2015-10-24 12:35:56 -0700 | [diff] [blame] | 3302 | Slog.w(TAG, |
| 3303 | "moveTopStackActivityToPinnedStackLocked: Picture-In-Picture not supported for " |
Filip Gruszczynski | 77d9448 | 2015-12-11 13:59:52 -0800 | [diff] [blame] | 3304 | + " r=" + r); |
Wale Ogunwale | 079a004 | 2015-10-24 11:44:07 -0700 | [diff] [blame] | 3305 | return false; |
| 3306 | } |
| 3307 | |
Winson Chung | 3a68287 | 2017-04-10 14:38:05 -0700 | [diff] [blame] | 3308 | moveActivityToPinnedStackLocked(r, null /* sourceBounds */, 0f /* aspectRatio */, |
Wale Ogunwale | 66e1685 | 2017-10-19 13:35:52 -0700 | [diff] [blame] | 3309 | "moveTopActivityToPinnedStack"); |
Wale Ogunwale | 9c604c7 | 2015-12-06 18:42:57 -0800 | [diff] [blame] | 3310 | return true; |
| 3311 | } |
| 3312 | |
Winson Chung | 8bca9e4 | 2017-04-16 15:59:43 -0700 | [diff] [blame] | 3313 | void moveActivityToPinnedStackLocked(ActivityRecord r, Rect sourceHintBounds, float aspectRatio, |
Wale Ogunwale | 66e1685 | 2017-10-19 13:35:52 -0700 | [diff] [blame] | 3314 | String reason) { |
Winson Chung | 08f8189 | 2017-03-02 15:40:51 -0800 | [diff] [blame] | 3315 | |
Wale Ogunwale | 480dca0 | 2016-02-06 13:58:29 -0800 | [diff] [blame] | 3316 | mWindowManager.deferSurfaceLayout(); |
Winson Chung | 7466610 | 2017-02-22 17:49:24 -0800 | [diff] [blame] | 3317 | |
Wale Ogunwale | 04a05ac | 2017-09-17 21:35:02 -0700 | [diff] [blame] | 3318 | final ActivityDisplay display = r.getStack().getDisplay(); |
| 3319 | PinnedActivityStack stack = display.getPinnedStack(); |
Wale Ogunwale | 9dcf946 | 2017-09-19 15:13:01 -0700 | [diff] [blame] | 3320 | |
Bryce Lee | 04ab346 | 2017-04-10 15:06:33 -0700 | [diff] [blame] | 3321 | // This will clear the pinned stack by moving an existing task to the full screen stack, |
| 3322 | // ensuring only one task is present. |
Wale Ogunwale | 9dcf946 | 2017-09-19 15:13:01 -0700 | [diff] [blame] | 3323 | if (stack != null) { |
| 3324 | moveTasksToFullscreenStackLocked(stack, !ON_TOP); |
| 3325 | } |
Bryce Lee | 04ab346 | 2017-04-10 15:06:33 -0700 | [diff] [blame] | 3326 | |
Wale Ogunwale | 1666e31 | 2016-12-16 11:27:18 -0800 | [diff] [blame] | 3327 | // 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] | 3328 | stack = display.getOrCreateStack(WINDOWING_MODE_PINNED, r.getActivityType(), ON_TOP); |
Wale Ogunwale | 1666e31 | 2016-12-16 11:27:18 -0800 | [diff] [blame] | 3329 | |
Winson Chung | e55c019 | 2017-08-24 14:50:48 -0700 | [diff] [blame] | 3330 | // Calculate the target bounds here before the task is reparented back into pinned windowing |
| 3331 | // mode (which will reset the saved bounds) |
| 3332 | final Rect destBounds = stack.getDefaultPictureInPictureBounds(aspectRatio); |
| 3333 | |
Wale Ogunwale | 480dca0 | 2016-02-06 13:58:29 -0800 | [diff] [blame] | 3334 | try { |
Bryce Lee | af691c0 | 2017-03-20 14:20:22 -0700 | [diff] [blame] | 3335 | final TaskRecord task = r.getTask(); |
Wale Ogunwale | 480dca0 | 2016-02-06 13:58:29 -0800 | [diff] [blame] | 3336 | // Resize the pinned stack to match the current size of the task the activity we are |
| 3337 | // going to be moving is currently contained in. We do this to have the right starting |
| 3338 | // 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] | 3339 | resizeStackLocked(stack, task.getOverrideBounds(), null /* tempTaskBounds */, |
Wale Ogunwale | 480dca0 | 2016-02-06 13:58:29 -0800 | [diff] [blame] | 3340 | null /* tempTaskInsetBounds */, !PRESERVE_WINDOWS, |
Wale Ogunwale | c8da41e | 2016-04-16 13:27:23 -0700 | [diff] [blame] | 3341 | true /* allowResizeInDockedMode */, !DEFER_RESUME); |
Wale Ogunwale | 480dca0 | 2016-02-06 13:58:29 -0800 | [diff] [blame] | 3342 | |
| 3343 | if (task.mActivities.size() == 1) { |
Winson Chung | 5af42fc | 2017-03-24 17:11:33 -0700 | [diff] [blame] | 3344 | // 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] | 3345 | task.reparent(stack, ON_TOP, REPARENT_MOVE_STACK_TO_FRONT, !ANIMATE, DEFER_RESUME, |
| 3346 | false /* schedulePictureInPictureModeChange */, reason); |
Wale Ogunwale | 480dca0 | 2016-02-06 13:58:29 -0800 | [diff] [blame] | 3347 | } else { |
Winson Chung | b5c41b7 | 2016-12-07 15:00:47 -0800 | [diff] [blame] | 3348 | // 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] | 3349 | // reveal/leave the other activities in their original task. |
| 3350 | |
| 3351 | // Currently, we don't support reparenting activities across tasks in two different |
| 3352 | // stacks, so instead, just create a new task in the same stack, reparent the |
| 3353 | // activity into that task, and then reparent the whole task to the new stack. This |
| 3354 | // ensures that all the necessary work to migrate states in the old and new stacks |
| 3355 | // is also done. |
| 3356 | final TaskRecord newTask = task.getStack().createTaskRecord( |
Wale Ogunwale | 6fbde9f | 2017-08-24 07:24:12 -0700 | [diff] [blame] | 3357 | getNextTaskIdForUserLocked(r.userId), r.info, r.intent, null, null, true); |
Winson Chung | 7466610 | 2017-02-22 17:49:24 -0800 | [diff] [blame] | 3358 | r.reparent(newTask, MAX_VALUE, "moveActivityToStack"); |
| 3359 | |
Winson Chung | 5af42fc | 2017-03-24 17:11:33 -0700 | [diff] [blame] | 3360 | // 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] | 3361 | newTask.reparent(stack, ON_TOP, REPARENT_MOVE_STACK_TO_FRONT, !ANIMATE, |
Winson Chung | 5af42fc | 2017-03-24 17:11:33 -0700 | [diff] [blame] | 3362 | DEFER_RESUME, false /* schedulePictureInPictureModeChange */, reason); |
Wale Ogunwale | 480dca0 | 2016-02-06 13:58:29 -0800 | [diff] [blame] | 3363 | } |
Winson Chung | c2baac0 | 2017-01-11 13:34:47 -0800 | [diff] [blame] | 3364 | |
| 3365 | // Reset the state that indicates it can enter PiP while pausing after we've moved it |
| 3366 | // to the pinned stack |
Winson Chung | f7e03e1 | 2017-08-22 11:32:16 -0700 | [diff] [blame] | 3367 | r.supportsEnterPipOnTaskSwitch = false; |
Wale Ogunwale | 480dca0 | 2016-02-06 13:58:29 -0800 | [diff] [blame] | 3368 | } finally { |
| 3369 | mWindowManager.continueSurfaceLayout(); |
Wale Ogunwale | 079a004 | 2015-10-24 11:44:07 -0700 | [diff] [blame] | 3370 | } |
| 3371 | |
Winson Chung | e7ba686 | 2017-05-24 12:13:33 -0700 | [diff] [blame] | 3372 | stack.animateResizePinnedStack(sourceHintBounds, destBounds, -1 /* animationDuration */, |
| 3373 | true /* fromFullscreen */); |
| 3374 | |
| 3375 | // Update the visibility of all activities after the they have been reparented to the new |
| 3376 | // stack. This MUST run after the animation above is scheduled to ensure that the windows |
| 3377 | // drawn signal is scheduled after the bounds animation start call on the bounds animator |
| 3378 | // thread. |
Wale Ogunwale | 079a004 | 2015-10-24 11:44:07 -0700 | [diff] [blame] | 3379 | ensureActivitiesVisibleLocked(null, 0, !PRESERVE_WINDOWS); |
Wale Ogunwale | d046a01 | 2015-12-24 13:05:59 -0800 | [diff] [blame] | 3380 | resumeFocusedStackTopActivityLocked(); |
Wale Ogunwale | 03ce863 | 2015-12-29 16:15:22 -0800 | [diff] [blame] | 3381 | |
Wale Ogunwale | 89be576 | 2017-10-04 13:27:49 -0700 | [diff] [blame] | 3382 | mService.mTaskChangeNotificationController.notifyActivityPinned(r); |
Wale Ogunwale | 079a004 | 2015-10-24 11:44:07 -0700 | [diff] [blame] | 3383 | } |
| 3384 | |
Andrii Kulian | 0864bbb | 2017-02-16 15:45:58 -0800 | [diff] [blame] | 3385 | /** Move activity with its stack to front and make the stack focused. */ |
Chong Zhang | 6cda19c | 2016-06-14 19:07:56 -0700 | [diff] [blame] | 3386 | boolean moveFocusableActivityStackToFrontLocked(ActivityRecord r, String reason) { |
| 3387 | if (r == null || !r.isFocusable()) { |
| 3388 | if (DEBUG_FOCUS) Slog.d(TAG_FOCUS, |
| 3389 | "moveActivityStackToFront: unfocusable r=" + r); |
| 3390 | return false; |
| 3391 | } |
| 3392 | |
Bryce Lee | af691c0 | 2017-03-20 14:20:22 -0700 | [diff] [blame] | 3393 | final TaskRecord task = r.getTask(); |
Andrii Kulian | 02b7a83 | 2016-10-06 23:11:56 -0700 | [diff] [blame] | 3394 | final ActivityStack stack = r.getStack(); |
| 3395 | if (stack == null) { |
Chong Zhang | 6cda19c | 2016-06-14 19:07:56 -0700 | [diff] [blame] | 3396 | Slog.w(TAG, "moveActivityStackToFront: invalid task or stack: r=" |
| 3397 | + r + " task=" + task); |
| 3398 | return false; |
| 3399 | } |
| 3400 | |
Chong Zhang | 6cda19c | 2016-06-14 19:07:56 -0700 | [diff] [blame] | 3401 | if (stack == mFocusedStack && stack.topRunningActivityLocked() == r) { |
| 3402 | if (DEBUG_FOCUS) Slog.d(TAG_FOCUS, |
| 3403 | "moveActivityStackToFront: already on top, r=" + r); |
| 3404 | return false; |
| 3405 | } |
| 3406 | |
| 3407 | if (DEBUG_FOCUS) Slog.d(TAG_FOCUS, |
| 3408 | "moveActivityStackToFront: r=" + r); |
| 3409 | |
| 3410 | stack.moveToFront(reason, task); |
| 3411 | return true; |
| 3412 | } |
| 3413 | |
David Stevens | c6b91c6 | 2017-02-08 14:23:58 -0800 | [diff] [blame] | 3414 | ActivityRecord findTaskLocked(ActivityRecord r, int displayId) { |
Wale Ogunwale | 3938197 | 2015-12-17 17:15:29 -0800 | [diff] [blame] | 3415 | mTmpFindTaskResult.r = null; |
| 3416 | mTmpFindTaskResult.matchedByRootAffinity = false; |
David Stevens | c6b91c6 | 2017-02-08 14:23:58 -0800 | [diff] [blame] | 3417 | ActivityRecord affinityMatch = null; |
Wale Ogunwale | ee006da | 2015-03-30 14:49:25 -0700 | [diff] [blame] | 3418 | if (DEBUG_TASKS) Slog.d(TAG_TASKS, "Looking for task of " + r); |
Craig Mautner | e0a3884 | 2013-12-16 16:14:02 -0800 | [diff] [blame] | 3419 | for (int displayNdx = mActivityDisplays.size() - 1; displayNdx >= 0; --displayNdx) { |
Wale Ogunwale | a0f5b5e | 2017-10-11 09:37:23 -0700 | [diff] [blame] | 3420 | final ActivityDisplay display = mActivityDisplays.valueAt(displayNdx); |
| 3421 | for (int stackNdx = display.getChildCount() - 1; stackNdx >= 0; --stackNdx) { |
| 3422 | final ActivityStack stack = display.getChildAt(stackNdx); |
Wale Ogunwale | 6fbde9f | 2017-08-24 07:24:12 -0700 | [diff] [blame] | 3423 | if (!r.hasCompatibleActivityType(stack)) { |
Winson Chung | 91e5c88 | 2017-04-21 14:44:38 -0700 | [diff] [blame] | 3424 | if (DEBUG_TASKS) Slog.d(TAG_TASKS, "Skipping stack: (mismatch activity/stack) " |
| 3425 | + stack); |
Craig Mautner | 1b4bf85 | 2014-05-26 15:06:32 -0700 | [diff] [blame] | 3426 | continue; |
| 3427 | } |
Wale Ogunwale | 3938197 | 2015-12-17 17:15:29 -0800 | [diff] [blame] | 3428 | stack.findTaskLocked(r, mTmpFindTaskResult); |
David Stevens | c6b91c6 | 2017-02-08 14:23:58 -0800 | [diff] [blame] | 3429 | // It is possible to have tasks in multiple stacks with the same root affinity, so |
| 3430 | // we should keep looking after finding an affinity match to see if there is a |
| 3431 | // better match in another stack. Also, task affinity isn't a good enough reason |
| 3432 | // to target a display which isn't the source of the intent, so skip any affinity |
| 3433 | // matches not on the specified display. |
| 3434 | if (mTmpFindTaskResult.r != null) { |
| 3435 | if (!mTmpFindTaskResult.matchedByRootAffinity) { |
| 3436 | return mTmpFindTaskResult.r; |
| 3437 | } else if (mTmpFindTaskResult.r.getDisplayId() == displayId) { |
Winson Chung | 5b895b7 | 2017-05-01 13:46:25 -0700 | [diff] [blame] | 3438 | // Note: since the traversing through the stacks is top down, the floating |
| 3439 | // tasks should always have lower priority than any affinity-matching tasks |
| 3440 | // in the fullscreen stacks |
David Stevens | c6b91c6 | 2017-02-08 14:23:58 -0800 | [diff] [blame] | 3441 | affinityMatch = mTmpFindTaskResult.r; |
David Stevens | e5a7b64 | 2017-05-22 13:18:23 -0700 | [diff] [blame] | 3442 | } else if (DEBUG_TASKS && mTmpFindTaskResult.matchedByRootAffinity) { |
| 3443 | Slog.d(TAG_TASKS, "Skipping match on different display " |
| 3444 | + mTmpFindTaskResult.r.getDisplayId() + " " + displayId); |
David Stevens | c6b91c6 | 2017-02-08 14:23:58 -0800 | [diff] [blame] | 3445 | } |
Craig Mautner | 4a1cb22 | 2013-12-04 16:14:06 -0800 | [diff] [blame] | 3446 | } |
Craig Mautner | 8849a5e | 2013-04-02 16:41:03 -0700 | [diff] [blame] | 3447 | } |
| 3448 | } |
Winson Chung | 5b895b7 | 2017-05-01 13:46:25 -0700 | [diff] [blame] | 3449 | |
David Stevens | c6b91c6 | 2017-02-08 14:23:58 -0800 | [diff] [blame] | 3450 | if (DEBUG_TASKS && affinityMatch == null) Slog.d(TAG_TASKS, "No task found"); |
| 3451 | return affinityMatch; |
Craig Mautner | 8849a5e | 2013-04-02 16:41:03 -0700 | [diff] [blame] | 3452 | } |
| 3453 | |
Andrii Kulian | d3bbb13 | 2016-06-16 16:00:20 -0700 | [diff] [blame] | 3454 | ActivityRecord findActivityLocked(Intent intent, ActivityInfo info, |
Wale Ogunwale | a0f5b5e | 2017-10-11 09:37:23 -0700 | [diff] [blame] | 3455 | boolean compareIntentFilters) { |
Craig Mautner | e0a3884 | 2013-12-16 16:14:02 -0800 | [diff] [blame] | 3456 | for (int displayNdx = mActivityDisplays.size() - 1; displayNdx >= 0; --displayNdx) { |
Wale Ogunwale | a0f5b5e | 2017-10-11 09:37:23 -0700 | [diff] [blame] | 3457 | final ActivityDisplay display = mActivityDisplays.valueAt(displayNdx); |
| 3458 | for (int stackNdx = display.getChildCount() - 1; stackNdx >= 0; --stackNdx) { |
| 3459 | final ActivityStack stack = display.getChildAt(stackNdx); |
| 3460 | final ActivityRecord ar = stack.findActivityLocked( |
| 3461 | intent, info, compareIntentFilters); |
Craig Mautner | 4a1cb22 | 2013-12-04 16:14:06 -0800 | [diff] [blame] | 3462 | if (ar != null) { |
| 3463 | return ar; |
| 3464 | } |
Craig Mautner | 8849a5e | 2013-04-02 16:41:03 -0700 | [diff] [blame] | 3465 | } |
| 3466 | } |
| 3467 | return null; |
| 3468 | } |
| 3469 | |
David Stevens | 9440dc8 | 2017-03-16 19:00:20 -0700 | [diff] [blame] | 3470 | boolean hasAwakeDisplay() { |
| 3471 | for (int displayNdx = mActivityDisplays.size() - 1; displayNdx >= 0; --displayNdx) { |
| 3472 | final ActivityDisplay display = mActivityDisplays.valueAt(displayNdx); |
| 3473 | if (!display.shouldSleep()) { |
| 3474 | return true; |
| 3475 | } |
| 3476 | } |
| 3477 | return false; |
| 3478 | } |
| 3479 | |
Craig Mautner | 8d341ef | 2013-03-26 09:03:27 -0700 | [diff] [blame] | 3480 | void goingToSleepLocked() { |
Craig Mautner | 0eea92c | 2013-05-16 13:35:39 -0700 | [diff] [blame] | 3481 | scheduleSleepTimeout(); |
| 3482 | if (!mGoingToSleep.isHeld()) { |
| 3483 | mGoingToSleep.acquire(); |
Craig Mautner | 7ea5bd4 | 2013-07-05 15:27:08 -0700 | [diff] [blame] | 3484 | if (mLaunchingActivity.isHeld()) { |
| 3485 | if (VALIDATE_WAKE_LOCK_CALLER && Binder.getCallingUid() != Process.myUid()) { |
| 3486 | throw new IllegalStateException("Calling must be system uid"); |
Craig Mautner | 0eea92c | 2013-05-16 13:35:39 -0700 | [diff] [blame] | 3487 | } |
Craig Mautner | 7ea5bd4 | 2013-07-05 15:27:08 -0700 | [diff] [blame] | 3488 | mLaunchingActivity.release(); |
| 3489 | mService.mHandler.removeMessages(LAUNCH_TIMEOUT_MSG); |
Craig Mautner | 0eea92c | 2013-05-16 13:35:39 -0700 | [diff] [blame] | 3490 | } |
Craig Mautner | 8d341ef | 2013-03-26 09:03:27 -0700 | [diff] [blame] | 3491 | } |
David Stevens | 9440dc8 | 2017-03-16 19:00:20 -0700 | [diff] [blame] | 3492 | |
| 3493 | applySleepTokensLocked(false /* applyToStacks */); |
| 3494 | |
| 3495 | checkReadyForSleepLocked(true /* allowDelay */); |
| 3496 | } |
| 3497 | |
| 3498 | void prepareForShutdownLocked() { |
| 3499 | for (int i = 0; i < mActivityDisplays.size(); i++) { |
| 3500 | createSleepTokenLocked("shutdown", mActivityDisplays.keyAt(i)); |
| 3501 | } |
Craig Mautner | 8d341ef | 2013-03-26 09:03:27 -0700 | [diff] [blame] | 3502 | } |
| 3503 | |
| 3504 | boolean shutdownLocked(int timeout) { |
Craig Mautner | 0eea92c | 2013-05-16 13:35:39 -0700 | [diff] [blame] | 3505 | goingToSleepLocked(); |
Craig Mautner | 0eea92c | 2013-05-16 13:35:39 -0700 | [diff] [blame] | 3506 | |
Craig Mautner | f4c909b | 2014-04-17 18:39:38 -0700 | [diff] [blame] | 3507 | boolean timedout = false; |
Craig Mautner | 0eea92c | 2013-05-16 13:35:39 -0700 | [diff] [blame] | 3508 | final long endTime = System.currentTimeMillis() + timeout; |
| 3509 | while (true) { |
David Stevens | 18abd0e | 2017-08-17 14:55:47 -0700 | [diff] [blame] | 3510 | if (!putStacksToSleepLocked(true /* allowDelay */, true /* shuttingDown */)) { |
Craig Mautner | 0eea92c | 2013-05-16 13:35:39 -0700 | [diff] [blame] | 3511 | long timeRemaining = endTime - System.currentTimeMillis(); |
| 3512 | if (timeRemaining > 0) { |
Craig Mautner | 8d341ef | 2013-03-26 09:03:27 -0700 | [diff] [blame] | 3513 | try { |
Craig Mautner | 0eea92c | 2013-05-16 13:35:39 -0700 | [diff] [blame] | 3514 | mService.wait(timeRemaining); |
Craig Mautner | 8d341ef | 2013-03-26 09:03:27 -0700 | [diff] [blame] | 3515 | } catch (InterruptedException e) { |
| 3516 | } |
Craig Mautner | 0eea92c | 2013-05-16 13:35:39 -0700 | [diff] [blame] | 3517 | } else { |
| 3518 | Slog.w(TAG, "Activity manager shutdown timed out"); |
| 3519 | timedout = true; |
| 3520 | break; |
Craig Mautner | 8d341ef | 2013-03-26 09:03:27 -0700 | [diff] [blame] | 3521 | } |
Craig Mautner | 0eea92c | 2013-05-16 13:35:39 -0700 | [diff] [blame] | 3522 | } else { |
| 3523 | break; |
Craig Mautner | 8d341ef | 2013-03-26 09:03:27 -0700 | [diff] [blame] | 3524 | } |
| 3525 | } |
Craig Mautner | 0eea92c | 2013-05-16 13:35:39 -0700 | [diff] [blame] | 3526 | |
| 3527 | // Force checkReadyForSleep to complete. |
David Stevens | 9440dc8 | 2017-03-16 19:00:20 -0700 | [diff] [blame] | 3528 | checkReadyForSleepLocked(false /* allowDelay */); |
Craig Mautner | 0eea92c | 2013-05-16 13:35:39 -0700 | [diff] [blame] | 3529 | |
Craig Mautner | 8d341ef | 2013-03-26 09:03:27 -0700 | [diff] [blame] | 3530 | return timedout; |
| 3531 | } |
| 3532 | |
| 3533 | void comeOutOfSleepIfNeededLocked() { |
Craig Mautner | 0eea92c | 2013-05-16 13:35:39 -0700 | [diff] [blame] | 3534 | removeSleepTimeouts(); |
| 3535 | if (mGoingToSleep.isHeld()) { |
| 3536 | mGoingToSleep.release(); |
| 3537 | } |
David Stevens | 9440dc8 | 2017-03-16 19:00:20 -0700 | [diff] [blame] | 3538 | } |
| 3539 | |
| 3540 | void applySleepTokensLocked(boolean applyToStacks) { |
Craig Mautner | e0a3884 | 2013-12-16 16:14:02 -0800 | [diff] [blame] | 3541 | for (int displayNdx = mActivityDisplays.size() - 1; displayNdx >= 0; --displayNdx) { |
David Stevens | 9440dc8 | 2017-03-16 19:00:20 -0700 | [diff] [blame] | 3542 | // Set the sleeping state of the display. |
| 3543 | final ActivityDisplay display = mActivityDisplays.valueAt(displayNdx); |
| 3544 | final boolean displayShouldSleep = display.shouldSleep(); |
| 3545 | if (displayShouldSleep == display.isSleeping()) { |
| 3546 | continue; |
| 3547 | } |
| 3548 | display.setIsSleeping(displayShouldSleep); |
| 3549 | |
| 3550 | if (!applyToStacks) { |
| 3551 | continue; |
| 3552 | } |
| 3553 | |
| 3554 | // Set the sleeping state of the stacks on the display. |
Wale Ogunwale | a0f5b5e | 2017-10-11 09:37:23 -0700 | [diff] [blame] | 3555 | for (int stackNdx = display.getChildCount() - 1; stackNdx >= 0; --stackNdx) { |
| 3556 | final ActivityStack stack = display.getChildAt(stackNdx); |
David Stevens | 9440dc8 | 2017-03-16 19:00:20 -0700 | [diff] [blame] | 3557 | if (displayShouldSleep) { |
| 3558 | stack.goToSleepIfPossible(false /* shuttingDown */); |
| 3559 | } else { |
| 3560 | stack.awakeFromSleepingLocked(); |
Lucas Dupin | 47a65c7 | 2018-02-15 14:16:18 -0800 | [diff] [blame] | 3561 | if (isFocusedStack(stack) && !getKeyguardController().isKeyguardOrAodShowing( |
| 3562 | display.mDisplayId)) { |
Bryce Lee | d939cf0 | 2018-03-12 09:04:44 -0700 | [diff] [blame] | 3563 | // If the keyguard is unlocked - resume immediately. |
| 3564 | // It is possible that the display will not be awake at the time we |
| 3565 | // process the keyguard going away, which can happen before the sleep token |
| 3566 | // 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] | 3567 | resumeFocusedStackTopActivityLocked(); |
| 3568 | } |
| 3569 | } |
| 3570 | } |
| 3571 | |
| 3572 | if (displayShouldSleep || mGoingToSleepActivities.isEmpty()) { |
| 3573 | continue; |
| 3574 | } |
| 3575 | // The display is awake now, so clean up the going to sleep list. |
| 3576 | for (Iterator<ActivityRecord> it = mGoingToSleepActivities.iterator(); it.hasNext(); ) { |
| 3577 | final ActivityRecord r = it.next(); |
| 3578 | if (r.getDisplayId() == display.mDisplayId) { |
| 3579 | it.remove(); |
Craig Mautner | 4a1cb22 | 2013-12-04 16:14:06 -0800 | [diff] [blame] | 3580 | } |
Craig Mautner | 5314a40 | 2013-09-26 12:40:16 -0700 | [diff] [blame] | 3581 | } |
Craig Mautner | 8d341ef | 2013-03-26 09:03:27 -0700 | [diff] [blame] | 3582 | } |
Craig Mautner | 0eea92c | 2013-05-16 13:35:39 -0700 | [diff] [blame] | 3583 | } |
| 3584 | |
| 3585 | void activitySleptLocked(ActivityRecord r) { |
| 3586 | mGoingToSleepActivities.remove(r); |
David Stevens | 9440dc8 | 2017-03-16 19:00:20 -0700 | [diff] [blame] | 3587 | final ActivityStack s = r.getStack(); |
| 3588 | if (s != null) { |
| 3589 | s.checkReadyForSleep(); |
| 3590 | } else { |
| 3591 | checkReadyForSleepLocked(true); |
| 3592 | } |
Craig Mautner | 0eea92c | 2013-05-16 13:35:39 -0700 | [diff] [blame] | 3593 | } |
| 3594 | |
David Stevens | 9440dc8 | 2017-03-16 19:00:20 -0700 | [diff] [blame] | 3595 | void checkReadyForSleepLocked(boolean allowDelay) { |
Fyodor Kupolov | 9b80b94 | 2016-06-16 16:29:05 -0700 | [diff] [blame] | 3596 | if (!mService.isSleepingOrShuttingDownLocked()) { |
Craig Mautner | 0eea92c | 2013-05-16 13:35:39 -0700 | [diff] [blame] | 3597 | // Do not care. |
| 3598 | return; |
| 3599 | } |
| 3600 | |
David Stevens | 18abd0e | 2017-08-17 14:55:47 -0700 | [diff] [blame] | 3601 | if (!putStacksToSleepLocked(allowDelay, false /* shuttingDown */)) { |
| 3602 | return; |
Craig Mautner | 0eea92c | 2013-05-16 13:35:39 -0700 | [diff] [blame] | 3603 | } |
| 3604 | |
Wei Wang | 65c7a15 | 2016-06-02 18:51:22 -0700 | [diff] [blame] | 3605 | // Send launch end powerhint before going sleep |
Bryce Lee | d3624e1 | 2017-11-30 08:51:45 -0800 | [diff] [blame] | 3606 | sendPowerHintForLaunchEndIfNeeded(); |
Wei Wang | 65c7a15 | 2016-06-02 18:51:22 -0700 | [diff] [blame] | 3607 | |
Craig Mautner | 0eea92c | 2013-05-16 13:35:39 -0700 | [diff] [blame] | 3608 | removeSleepTimeouts(); |
| 3609 | |
| 3610 | if (mGoingToSleep.isHeld()) { |
| 3611 | mGoingToSleep.release(); |
| 3612 | } |
| 3613 | if (mService.mShuttingDown) { |
| 3614 | mService.notifyAll(); |
| 3615 | } |
Craig Mautner | 8d341ef | 2013-03-26 09:03:27 -0700 | [diff] [blame] | 3616 | } |
| 3617 | |
David Stevens | 18abd0e | 2017-08-17 14:55:47 -0700 | [diff] [blame] | 3618 | // Tries to put all activity stacks to sleep. Returns true if all stacks were |
| 3619 | // successfully put to sleep. |
| 3620 | private boolean putStacksToSleepLocked(boolean allowDelay, boolean shuttingDown) { |
| 3621 | boolean allSleep = true; |
| 3622 | for (int displayNdx = mActivityDisplays.size() - 1; displayNdx >= 0; --displayNdx) { |
Wale Ogunwale | a0f5b5e | 2017-10-11 09:37:23 -0700 | [diff] [blame] | 3623 | final ActivityDisplay display = mActivityDisplays.valueAt(displayNdx); |
| 3624 | for (int stackNdx = display.getChildCount() - 1; stackNdx >= 0; --stackNdx) { |
| 3625 | final ActivityStack stack = display.getChildAt(stackNdx); |
David Stevens | 18abd0e | 2017-08-17 14:55:47 -0700 | [diff] [blame] | 3626 | if (allowDelay) { |
Wale Ogunwale | a0f5b5e | 2017-10-11 09:37:23 -0700 | [diff] [blame] | 3627 | allSleep &= stack.goToSleepIfPossible(shuttingDown); |
David Stevens | 18abd0e | 2017-08-17 14:55:47 -0700 | [diff] [blame] | 3628 | } else { |
Wale Ogunwale | a0f5b5e | 2017-10-11 09:37:23 -0700 | [diff] [blame] | 3629 | stack.goToSleep(); |
David Stevens | 18abd0e | 2017-08-17 14:55:47 -0700 | [diff] [blame] | 3630 | } |
| 3631 | } |
| 3632 | } |
| 3633 | return allSleep; |
| 3634 | } |
| 3635 | |
Craig Mautner | ce5f3cb | 2013-04-22 08:58:54 -0700 | [diff] [blame] | 3636 | boolean reportResumedActivityLocked(ActivityRecord r) { |
Bryce Lee | 29a649d | 2017-08-18 13:52:31 -0700 | [diff] [blame] | 3637 | // A resumed activity cannot be stopping. remove from list |
| 3638 | mStoppingActivities.remove(r); |
| 3639 | |
Andrii Kulian | 02b7a83 | 2016-10-06 23:11:56 -0700 | [diff] [blame] | 3640 | final ActivityStack stack = r.getStack(); |
Wale Ogunwale | 1e60e0c | 2015-10-28 13:36:10 -0700 | [diff] [blame] | 3641 | if (isFocusedStack(stack)) { |
Jeff Sharkey | 5782da7 | 2013-04-25 14:32:30 -0700 | [diff] [blame] | 3642 | mService.updateUsageStats(r, true); |
Craig Mautner | ce5f3cb | 2013-04-22 08:58:54 -0700 | [diff] [blame] | 3643 | } |
| 3644 | if (allResumedActivitiesComplete()) { |
Filip Gruszczynski | bc5a6c5 | 2015-09-22 13:13:24 -0700 | [diff] [blame] | 3645 | ensureActivitiesVisibleLocked(null, 0, !PRESERVE_WINDOWS); |
Craig Mautner | ce5f3cb | 2013-04-22 08:58:54 -0700 | [diff] [blame] | 3646 | mWindowManager.executeAppTransition(); |
| 3647 | return true; |
| 3648 | } |
| 3649 | return false; |
| 3650 | } |
| 3651 | |
Craig Mautner | 8d341ef | 2013-03-26 09:03:27 -0700 | [diff] [blame] | 3652 | void handleAppCrashLocked(ProcessRecord app) { |
Craig Mautner | e0a3884 | 2013-12-16 16:14:02 -0800 | [diff] [blame] | 3653 | for (int displayNdx = mActivityDisplays.size() - 1; displayNdx >= 0; --displayNdx) { |
Wale Ogunwale | a0f5b5e | 2017-10-11 09:37:23 -0700 | [diff] [blame] | 3654 | final ActivityDisplay display = mActivityDisplays.valueAt(displayNdx); |
| 3655 | for (int stackNdx = display.getChildCount() - 1; stackNdx >= 0; --stackNdx) { |
| 3656 | final ActivityStack stack = display.getChildAt(stackNdx); |
| 3657 | stack.handleAppCrashLocked(app); |
Craig Mautner | 4a1cb22 | 2013-12-04 16:14:06 -0800 | [diff] [blame] | 3658 | } |
Craig Mautner | 8d341ef | 2013-03-26 09:03:27 -0700 | [diff] [blame] | 3659 | } |
| 3660 | } |
| 3661 | |
Craig Mautner | bb74246 | 2014-07-07 15:28:55 -0700 | [diff] [blame] | 3662 | // Called when WindowManager has finished animating the launchingBehind activity to the back. |
Andrii Kulian | 21713ac | 2016-10-12 22:05:05 -0700 | [diff] [blame] | 3663 | private void handleLaunchTaskBehindCompleteLocked(ActivityRecord r) { |
Bryce Lee | af691c0 | 2017-03-20 14:20:22 -0700 | [diff] [blame] | 3664 | final TaskRecord task = r.getTask(); |
Andrii Kulian | 02b7a83 | 2016-10-06 23:11:56 -0700 | [diff] [blame] | 3665 | final ActivityStack stack = task.getStack(); |
Winson | 730bf06 | 2016-03-31 18:04:56 -0700 | [diff] [blame] | 3666 | |
| 3667 | r.mLaunchTaskBehind = false; |
Winson Chung | 1dbc811 | 2017-09-28 18:05:31 -0700 | [diff] [blame] | 3668 | mRecentTasks.add(task); |
Yorke Lee | bd54c2a | 2016-10-25 13:49:23 -0700 | [diff] [blame] | 3669 | mService.mTaskChangeNotificationController.notifyTaskStackChanged(); |
Wale Ogunwale | 26c0dfe | 2016-12-14 14:42:30 -0800 | [diff] [blame] | 3670 | r.setVisibility(false); |
Winson | 730bf06 | 2016-03-31 18:04:56 -0700 | [diff] [blame] | 3671 | |
| 3672 | // When launching tasks behind, update the last active time of the top task after the new |
| 3673 | // task has been shown briefly |
Wale Ogunwale | 30e441d | 2017-11-09 08:28:45 -0800 | [diff] [blame] | 3674 | final ActivityRecord top = stack.getTopActivity(); |
Winson | 730bf06 | 2016-03-31 18:04:56 -0700 | [diff] [blame] | 3675 | if (top != null) { |
Bryce Lee | af691c0 | 2017-03-20 14:20:22 -0700 | [diff] [blame] | 3676 | top.getTask().touchActiveTime(); |
Winson | 730bf06 | 2016-03-31 18:04:56 -0700 | [diff] [blame] | 3677 | } |
Craig Mautner | bb74246 | 2014-07-07 15:28:55 -0700 | [diff] [blame] | 3678 | } |
| 3679 | |
| 3680 | void scheduleLaunchTaskBehindComplete(IBinder token) { |
| 3681 | mHandler.obtainMessage(LAUNCH_TASK_BEHIND_COMPLETE, token).sendToTarget(); |
| 3682 | } |
| 3683 | |
Andrii Kulian | f4479ee | 2018-05-23 17:52:48 -0700 | [diff] [blame] | 3684 | /** |
| 3685 | * Make sure that all activities that need to be visible in the system actually are and update |
| 3686 | * their configuration. |
| 3687 | */ |
Filip Gruszczynski | bc5a6c5 | 2015-09-22 13:13:24 -0700 | [diff] [blame] | 3688 | void ensureActivitiesVisibleLocked(ActivityRecord starting, int configChanges, |
| 3689 | boolean preserveWindows) { |
Andrii Kulian | f4479ee | 2018-05-23 17:52:48 -0700 | [diff] [blame] | 3690 | ensureActivitiesVisibleLocked(starting, configChanges, preserveWindows, |
Andrii Kulian | a39ae3e | 2018-05-31 12:43:54 -0700 | [diff] [blame] | 3691 | true /* notifyClients */); |
Andrii Kulian | f4479ee | 2018-05-23 17:52:48 -0700 | [diff] [blame] | 3692 | } |
| 3693 | |
| 3694 | /** |
| 3695 | * @see #ensureActivitiesVisibleLocked(ActivityRecord, int, boolean) |
| 3696 | */ |
| 3697 | void ensureActivitiesVisibleLocked(ActivityRecord starting, int configChanges, |
Andrii Kulian | a39ae3e | 2018-05-31 12:43:54 -0700 | [diff] [blame] | 3698 | boolean preserveWindows, boolean notifyClients) { |
Bryce Lee | 459c062 | 2018-03-19 11:04:01 -0700 | [diff] [blame] | 3699 | getKeyguardController().beginActivityVisibilityUpdate(); |
Jorim Jaggi | fe76234 | 2016-10-13 14:33:27 +0200 | [diff] [blame] | 3700 | try { |
| 3701 | // First the front stacks. In case any are not fullscreen and are in front of home. |
| 3702 | for (int displayNdx = mActivityDisplays.size() - 1; displayNdx >= 0; --displayNdx) { |
Wale Ogunwale | a0f5b5e | 2017-10-11 09:37:23 -0700 | [diff] [blame] | 3703 | final ActivityDisplay display = mActivityDisplays.valueAt(displayNdx); |
| 3704 | for (int stackNdx = display.getChildCount() - 1; stackNdx >= 0; --stackNdx) { |
| 3705 | final ActivityStack stack = display.getChildAt(stackNdx); |
Andrii Kulian | f4479ee | 2018-05-23 17:52:48 -0700 | [diff] [blame] | 3706 | stack.ensureActivitiesVisibleLocked(starting, configChanges, preserveWindows, |
Andrii Kulian | a39ae3e | 2018-05-31 12:43:54 -0700 | [diff] [blame] | 3707 | notifyClients); |
Jorim Jaggi | fe76234 | 2016-10-13 14:33:27 +0200 | [diff] [blame] | 3708 | } |
Craig Mautner | 580ea81 | 2013-04-25 12:58:38 -0700 | [diff] [blame] | 3709 | } |
Jorim Jaggi | fe76234 | 2016-10-13 14:33:27 +0200 | [diff] [blame] | 3710 | } finally { |
Bryce Lee | 459c062 | 2018-03-19 11:04:01 -0700 | [diff] [blame] | 3711 | getKeyguardController().endActivityVisibilityUpdate(); |
Craig Mautner | 8d341ef | 2013-03-26 09:03:27 -0700 | [diff] [blame] | 3712 | } |
Craig Mautner | 8d341ef | 2013-03-26 09:03:27 -0700 | [diff] [blame] | 3713 | } |
| 3714 | |
Jorim Jaggi | 8b702ed | 2017-01-20 16:59:03 +0100 | [diff] [blame] | 3715 | void addStartingWindowsForVisibleActivities(boolean taskSwitch) { |
| 3716 | for (int displayNdx = mActivityDisplays.size() - 1; displayNdx >= 0; --displayNdx) { |
Wale Ogunwale | a0f5b5e | 2017-10-11 09:37:23 -0700 | [diff] [blame] | 3717 | final ActivityDisplay display = mActivityDisplays.valueAt(displayNdx); |
| 3718 | for (int stackNdx = display.getChildCount() - 1; stackNdx >= 0; --stackNdx) { |
| 3719 | final ActivityStack stack = display.getChildAt(stackNdx); |
Jorim Jaggi | 8b702ed | 2017-01-20 16:59:03 +0100 | [diff] [blame] | 3720 | stack.addStartingWindowsForVisibleActivities(taskSwitch); |
| 3721 | } |
| 3722 | } |
| 3723 | } |
| 3724 | |
Chong Zhang | fdcc4d4 | 2015-10-14 16:50:12 -0700 | [diff] [blame] | 3725 | void invalidateTaskLayers() { |
| 3726 | mTaskLayersChanged = true; |
| 3727 | } |
| 3728 | |
| 3729 | void rankTaskLayersIfNeeded() { |
| 3730 | if (!mTaskLayersChanged) { |
| 3731 | return; |
| 3732 | } |
| 3733 | mTaskLayersChanged = false; |
| 3734 | for (int displayNdx = 0; displayNdx < mActivityDisplays.size(); displayNdx++) { |
Wale Ogunwale | a0f5b5e | 2017-10-11 09:37:23 -0700 | [diff] [blame] | 3735 | final ActivityDisplay display = mActivityDisplays.valueAt(displayNdx); |
Chong Zhang | fdcc4d4 | 2015-10-14 16:50:12 -0700 | [diff] [blame] | 3736 | int baseLayer = 0; |
Wale Ogunwale | a0f5b5e | 2017-10-11 09:37:23 -0700 | [diff] [blame] | 3737 | for (int stackNdx = display.getChildCount() - 1; stackNdx >= 0; --stackNdx) { |
| 3738 | final ActivityStack stack = display.getChildAt(stackNdx); |
| 3739 | baseLayer += stack.rankTaskLayers(baseLayer); |
Chong Zhang | fdcc4d4 | 2015-10-14 16:50:12 -0700 | [diff] [blame] | 3740 | } |
| 3741 | } |
| 3742 | } |
| 3743 | |
Dianne Hackborn | b5a380d | 2015-05-20 18:18:46 -0700 | [diff] [blame] | 3744 | void clearOtherAppTimeTrackers(AppTimeTracker except) { |
| 3745 | for (int displayNdx = mActivityDisplays.size() - 1; displayNdx >= 0; --displayNdx) { |
Wale Ogunwale | a0f5b5e | 2017-10-11 09:37:23 -0700 | [diff] [blame] | 3746 | final ActivityDisplay display = mActivityDisplays.valueAt(displayNdx); |
| 3747 | for (int stackNdx = display.getChildCount() - 1; stackNdx >= 0; --stackNdx) { |
| 3748 | final ActivityStack stack = display.getChildAt(stackNdx); |
Dianne Hackborn | b5a380d | 2015-05-20 18:18:46 -0700 | [diff] [blame] | 3749 | stack.clearOtherAppTimeTrackers(except); |
| 3750 | } |
| 3751 | } |
| 3752 | } |
| 3753 | |
Craig Mautner | 8d341ef | 2013-03-26 09:03:27 -0700 | [diff] [blame] | 3754 | void scheduleDestroyAllActivities(ProcessRecord app, String reason) { |
Craig Mautner | e0a3884 | 2013-12-16 16:14:02 -0800 | [diff] [blame] | 3755 | for (int displayNdx = mActivityDisplays.size() - 1; displayNdx >= 0; --displayNdx) { |
Wale Ogunwale | a0f5b5e | 2017-10-11 09:37:23 -0700 | [diff] [blame] | 3756 | final ActivityDisplay display = mActivityDisplays.valueAt(displayNdx); |
| 3757 | for (int stackNdx = display.getChildCount() - 1; stackNdx >= 0; --stackNdx) { |
| 3758 | final ActivityStack stack = display.getChildAt(stackNdx); |
Craig Mautner | ee2e45a | 2014-06-27 12:10:03 -0700 | [diff] [blame] | 3759 | stack.scheduleDestroyActivities(app, reason); |
Craig Mautner | 4a1cb22 | 2013-12-04 16:14:06 -0800 | [diff] [blame] | 3760 | } |
Craig Mautner | 8d341ef | 2013-03-26 09:03:27 -0700 | [diff] [blame] | 3761 | } |
| 3762 | } |
| 3763 | |
Dianne Hackborn | 89ad456 | 2014-08-24 16:45:38 -0700 | [diff] [blame] | 3764 | void releaseSomeActivitiesLocked(ProcessRecord app, String reason) { |
| 3765 | // Examine all activities currently running in the process. |
| 3766 | TaskRecord firstTask = null; |
| 3767 | // Tasks is non-null only if two or more tasks are found. |
| 3768 | ArraySet<TaskRecord> tasks = null; |
Wale Ogunwale | 0fc365c | 2015-05-25 19:35:42 -0700 | [diff] [blame] | 3769 | if (DEBUG_RELEASE) Slog.d(TAG_RELEASE, "Trying to release some activities in " + app); |
| 3770 | for (int i = 0; i < app.activities.size(); i++) { |
Dianne Hackborn | 89ad456 | 2014-08-24 16:45:38 -0700 | [diff] [blame] | 3771 | ActivityRecord r = app.activities.get(i); |
| 3772 | // First, if we find an activity that is in the process of being destroyed, |
| 3773 | // then we just aren't going to do anything for now; we want things to settle |
| 3774 | // down before we try to prune more activities. |
Bryce Lee | 7ace395 | 2018-02-16 14:34:32 -0800 | [diff] [blame] | 3775 | if (r.finishing || r.isState(DESTROYING, DESTROYED)) { |
Wale Ogunwale | 0fc365c | 2015-05-25 19:35:42 -0700 | [diff] [blame] | 3776 | if (DEBUG_RELEASE) Slog.d(TAG_RELEASE, "Abort release; already destroying: " + r); |
Dianne Hackborn | 89ad456 | 2014-08-24 16:45:38 -0700 | [diff] [blame] | 3777 | return; |
| 3778 | } |
| 3779 | // Don't consider any activies that are currently not in a state where they |
| 3780 | // can be destroyed. |
Bryce Lee | 7ace395 | 2018-02-16 14:34:32 -0800 | [diff] [blame] | 3781 | if (r.visible || !r.stopped || !r.haveState |
| 3782 | || r.isState(RESUMED, PAUSING, PAUSED, STOPPING)) { |
Wale Ogunwale | 0fc365c | 2015-05-25 19:35:42 -0700 | [diff] [blame] | 3783 | 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] | 3784 | continue; |
| 3785 | } |
Bryce Lee | af691c0 | 2017-03-20 14:20:22 -0700 | [diff] [blame] | 3786 | |
| 3787 | final TaskRecord task = r.getTask(); |
| 3788 | if (task != null) { |
| 3789 | if (DEBUG_RELEASE) Slog.d(TAG_RELEASE, "Collecting release task " + task |
Dianne Hackborn | 89ad456 | 2014-08-24 16:45:38 -0700 | [diff] [blame] | 3790 | + " from " + r); |
| 3791 | if (firstTask == null) { |
Bryce Lee | af691c0 | 2017-03-20 14:20:22 -0700 | [diff] [blame] | 3792 | firstTask = task; |
| 3793 | } else if (firstTask != task) { |
Dianne Hackborn | 89ad456 | 2014-08-24 16:45:38 -0700 | [diff] [blame] | 3794 | if (tasks == null) { |
| 3795 | tasks = new ArraySet<>(); |
| 3796 | tasks.add(firstTask); |
| 3797 | } |
Bryce Lee | af691c0 | 2017-03-20 14:20:22 -0700 | [diff] [blame] | 3798 | tasks.add(task); |
Dianne Hackborn | 89ad456 | 2014-08-24 16:45:38 -0700 | [diff] [blame] | 3799 | } |
| 3800 | } |
| 3801 | } |
| 3802 | if (tasks == null) { |
Wale Ogunwale | 0fc365c | 2015-05-25 19:35:42 -0700 | [diff] [blame] | 3803 | 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] | 3804 | return; |
| 3805 | } |
| 3806 | // If we have activities in multiple tasks that are in a position to be destroyed, |
| 3807 | // let's iterate through the tasks and release the oldest one. |
| 3808 | final int numDisplays = mActivityDisplays.size(); |
| 3809 | for (int displayNdx = 0; displayNdx < numDisplays; ++displayNdx) { |
Wale Ogunwale | a0f5b5e | 2017-10-11 09:37:23 -0700 | [diff] [blame] | 3810 | final ActivityDisplay display = mActivityDisplays.valueAt(displayNdx); |
| 3811 | final int stackCount = display.getChildCount(); |
Dianne Hackborn | 89ad456 | 2014-08-24 16:45:38 -0700 | [diff] [blame] | 3812 | // 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] | 3813 | for (int stackNdx = 0; stackNdx < stackCount; stackNdx++) { |
| 3814 | final ActivityStack stack = display.getChildAt(stackNdx); |
Dianne Hackborn | 89ad456 | 2014-08-24 16:45:38 -0700 | [diff] [blame] | 3815 | // Try to release activities in this stack; if we manage to, we are done. |
| 3816 | if (stack.releaseSomeActivitiesLocked(app, tasks, reason) > 0) { |
| 3817 | return; |
| 3818 | } |
| 3819 | } |
| 3820 | } |
| 3821 | } |
| 3822 | |
Amith Yamasani | 37a40c2 | 2015-06-17 13:25:42 -0700 | [diff] [blame] | 3823 | boolean switchUserLocked(int userId, UserState uss) { |
Wale Ogunwale | 9a98c52 | 2016-04-27 09:23:55 -0700 | [diff] [blame] | 3824 | final int focusStackId = mFocusedStack.getStackId(); |
| 3825 | // We dismiss the docked stack whenever we switch users. |
Wale Ogunwale | a0f5b5e | 2017-10-11 09:37:23 -0700 | [diff] [blame] | 3826 | final ActivityStack dockedStack = getDefaultDisplay().getSplitScreenPrimaryStack(); |
Wale Ogunwale | 9dcf946 | 2017-09-19 15:13:01 -0700 | [diff] [blame] | 3827 | if (dockedStack != null) { |
| 3828 | moveTasksToFullscreenStackLocked(dockedStack, mFocusedStack == dockedStack); |
| 3829 | } |
Winson Chung | c2b23a5 | 2017-01-09 15:44:55 -0800 | [diff] [blame] | 3830 | // Also dismiss the pinned stack whenever we switch users. Removing the pinned stack will |
| 3831 | // also cause all tasks to be moved to the fullscreen stack at a position that is |
| 3832 | // appropriate. |
Wale Ogunwale | 44f036f | 2017-09-29 05:09:09 -0700 | [diff] [blame] | 3833 | removeStacksInWindowingModes(WINDOWING_MODE_PINNED); |
Wale Ogunwale | 9a98c52 | 2016-04-27 09:23:55 -0700 | [diff] [blame] | 3834 | |
| 3835 | mUserStackInFront.put(mCurrentUser, focusStackId); |
Wale Ogunwale | 6827856 | 2017-09-23 17:13:55 -0700 | [diff] [blame] | 3836 | final int restoreStackId = mUserStackInFront.get(userId, mHomeStack.mStackId); |
Craig Mautner | 2420ead | 2013-04-01 17:13:20 -0700 | [diff] [blame] | 3837 | mCurrentUser = userId; |
Craig Mautner | ac6f843 | 2013-07-17 13:24:59 -0700 | [diff] [blame] | 3838 | |
Craig Mautner | 858d8a6 | 2013-04-23 17:08:34 -0700 | [diff] [blame] | 3839 | mStartingUsers.add(uss); |
Craig Mautner | e0a3884 | 2013-12-16 16:14:02 -0800 | [diff] [blame] | 3840 | for (int displayNdx = mActivityDisplays.size() - 1; displayNdx >= 0; --displayNdx) { |
Wale Ogunwale | a0f5b5e | 2017-10-11 09:37:23 -0700 | [diff] [blame] | 3841 | final ActivityDisplay display = mActivityDisplays.valueAt(displayNdx); |
| 3842 | for (int stackNdx = display.getChildCount() - 1; stackNdx >= 0; --stackNdx) { |
| 3843 | final ActivityStack stack = display.getChildAt(stackNdx); |
Craig Mautner | e0a3884 | 2013-12-16 16:14:02 -0800 | [diff] [blame] | 3844 | stack.switchUserLocked(userId); |
Alexandra Gherghina | dae57a1 | 2014-03-12 19:15:26 +0000 | [diff] [blame] | 3845 | TaskRecord task = stack.topTask(); |
| 3846 | if (task != null) { |
Wale Ogunwale | 1666e31 | 2016-12-16 11:27:18 -0800 | [diff] [blame] | 3847 | stack.positionChildWindowContainerAtTop(task); |
Alexandra Gherghina | dae57a1 | 2014-03-12 19:15:26 +0000 | [diff] [blame] | 3848 | } |
Craig Mautner | 4a1cb22 | 2013-12-04 16:14:06 -0800 | [diff] [blame] | 3849 | } |
Craig Mautner | ac6f843 | 2013-07-17 13:24:59 -0700 | [diff] [blame] | 3850 | } |
Craig Mautner | 858d8a6 | 2013-04-23 17:08:34 -0700 | [diff] [blame] | 3851 | |
Craig Mautner | 4f1df4f | 2013-10-15 15:44:14 -0700 | [diff] [blame] | 3852 | ActivityStack stack = getStack(restoreStackId); |
| 3853 | if (stack == null) { |
| 3854 | stack = mHomeStack; |
| 3855 | } |
Wale Ogunwale | 6fbde9f | 2017-08-24 07:24:12 -0700 | [diff] [blame] | 3856 | final boolean homeInFront = stack.isActivityTypeHome(); |
Craig Mautner | e0a3884 | 2013-12-16 16:14:02 -0800 | [diff] [blame] | 3857 | if (stack.isOnHomeDisplay()) { |
Wale Ogunwale | 925d0d1 | 2015-09-23 15:40:07 -0700 | [diff] [blame] | 3858 | stack.moveToFront("switchUserOnHomeDisplay"); |
Craig Mautner | e0a3884 | 2013-12-16 16:14:02 -0800 | [diff] [blame] | 3859 | } else { |
| 3860 | // Stack was moved to another display while user was swapped out. |
Matthew Ng | ae1ff4f | 2016-11-10 15:49:14 -0800 | [diff] [blame] | 3861 | resumeHomeStackTask(null, "switchUserOnOtherDisplay"); |
Craig Mautner | e0a3884 | 2013-12-16 16:14:02 -0800 | [diff] [blame] | 3862 | } |
Craig Mautner | 93529a4 | 2013-10-04 15:03:13 -0700 | [diff] [blame] | 3863 | return homeInFront; |
Craig Mautner | 2219a1b | 2013-03-25 09:44:30 -0700 | [diff] [blame] | 3864 | } |
| 3865 | |
Wale Ogunwale | 0bd2aa7 | 2015-04-16 13:50:44 -0700 | [diff] [blame] | 3866 | /** Checks whether the userid is a profile of the current user. */ |
| 3867 | boolean isCurrentProfileLocked(int userId) { |
| 3868 | if (userId == mCurrentUser) return true; |
Fyodor Kupolov | 1b3edac | 2017-09-19 15:48:06 -0700 | [diff] [blame] | 3869 | return mService.mUserController.isCurrentProfile(userId); |
Wale Ogunwale | 0bd2aa7 | 2015-04-16 13:50:44 -0700 | [diff] [blame] | 3870 | } |
| 3871 | |
Bryce Lee | b7c9b80 | 2017-05-02 14:20:24 -0700 | [diff] [blame] | 3872 | /** |
| 3873 | * Returns whether a stopping activity is present that should be stopped after visible, rather |
| 3874 | * than idle. |
| 3875 | * @return {@code true} if such activity is present. {@code false} otherwise. |
| 3876 | */ |
| 3877 | boolean isStoppingNoHistoryActivity() { |
| 3878 | // Activities that are marked as nohistory should be stopped immediately after the resumed |
| 3879 | // activity has become visible. |
| 3880 | for (ActivityRecord record : mStoppingActivities) { |
| 3881 | if (record.isNoHistory()) { |
| 3882 | return true; |
| 3883 | } |
| 3884 | } |
| 3885 | |
| 3886 | return false; |
| 3887 | } |
| 3888 | |
Winson Chung | 4dabf23 | 2017-01-25 13:25:22 -0800 | [diff] [blame] | 3889 | final ArrayList<ActivityRecord> processStoppingActivitiesLocked(ActivityRecord idleActivity, |
| 3890 | boolean remove, boolean processPausingActivities) { |
Craig Mautner | de4ef02 | 2013-04-07 19:01:33 -0700 | [diff] [blame] | 3891 | ArrayList<ActivityRecord> stops = null; |
| 3892 | |
| 3893 | final boolean nowVisible = allResumedActivitiesVisible(); |
Craig Mautner | 8c14c15 | 2015-01-15 17:32:07 -0800 | [diff] [blame] | 3894 | for (int activityNdx = mStoppingActivities.size() - 1; activityNdx >= 0; --activityNdx) { |
| 3895 | ActivityRecord s = mStoppingActivities.get(activityNdx); |
Bryce Lee | 4a19438 | 2017-04-04 14:32:48 -0700 | [diff] [blame] | 3896 | boolean waitingVisible = mActivitiesWaitingForVisibleActivity.contains(s); |
Wale Ogunwale | f81c1d1 | 2016-01-12 12:20:18 -0800 | [diff] [blame] | 3897 | if (DEBUG_STATES) Slog.v(TAG, "Stopping " + s + ": nowVisible=" + nowVisible |
Craig Mautner | 8c14c15 | 2015-01-15 17:32:07 -0800 | [diff] [blame] | 3898 | + " waitingVisible=" + waitingVisible + " finishing=" + s.finishing); |
| 3899 | if (waitingVisible && nowVisible) { |
Bryce Lee | 4a19438 | 2017-04-04 14:32:48 -0700 | [diff] [blame] | 3900 | mActivitiesWaitingForVisibleActivity.remove(s); |
Andrii Kulian | ee05681 | 2016-09-21 15:34:45 -0700 | [diff] [blame] | 3901 | waitingVisible = false; |
Craig Mautner | de4ef02 | 2013-04-07 19:01:33 -0700 | [diff] [blame] | 3902 | if (s.finishing) { |
| 3903 | // If this activity is finishing, it is sitting on top of |
| 3904 | // everyone else but we now know it is no longer needed... |
| 3905 | // so get rid of it. Otherwise, we need to go through the |
| 3906 | // normal flow and hide it once we determine that it is |
| 3907 | // hidden by the activities in front of it. |
Wale Ogunwale | f81c1d1 | 2016-01-12 12:20:18 -0800 | [diff] [blame] | 3908 | if (DEBUG_STATES) Slog.v(TAG, "Before stopping, can hide: " + s); |
Wale Ogunwale | 26c0dfe | 2016-12-14 14:42:30 -0800 | [diff] [blame] | 3909 | s.setVisibility(false); |
Craig Mautner | de4ef02 | 2013-04-07 19:01:33 -0700 | [diff] [blame] | 3910 | } |
| 3911 | } |
David Stevens | 9440dc8 | 2017-03-16 19:00:20 -0700 | [diff] [blame] | 3912 | if (remove) { |
| 3913 | final ActivityStack stack = s.getStack(); |
| 3914 | final boolean shouldSleepOrShutDown = stack != null |
| 3915 | ? stack.shouldSleepOrShutDownActivities() |
| 3916 | : mService.isSleepingOrShuttingDownLocked(); |
| 3917 | if (!waitingVisible || shouldSleepOrShutDown) { |
Bryce Lee | 7ace395 | 2018-02-16 14:34:32 -0800 | [diff] [blame] | 3918 | if (!processPausingActivities && s.isState(PAUSING)) { |
David Stevens | 9440dc8 | 2017-03-16 19:00:20 -0700 | [diff] [blame] | 3919 | // Defer processing pausing activities in this iteration and reschedule |
| 3920 | // a delayed idle to reprocess it again |
| 3921 | removeTimeoutsForActivityLocked(idleActivity); |
| 3922 | scheduleIdleTimeoutLocked(idleActivity); |
| 3923 | continue; |
| 3924 | } |
Winson Chung | 4dabf23 | 2017-01-25 13:25:22 -0800 | [diff] [blame] | 3925 | |
David Stevens | 9440dc8 | 2017-03-16 19:00:20 -0700 | [diff] [blame] | 3926 | if (DEBUG_STATES) Slog.v(TAG, "Ready to stop: " + s); |
| 3927 | if (stops == null) { |
| 3928 | stops = new ArrayList<>(); |
| 3929 | } |
| 3930 | stops.add(s); |
Jorim Jaggi | 5db9ae4 | 2018-06-25 16:14:50 +0200 | [diff] [blame] | 3931 | |
| 3932 | // Make sure to remove it in all cases in case we entered this block with |
| 3933 | // shouldSleepOrShutDown |
| 3934 | mActivitiesWaitingForVisibleActivity.remove(s); |
David Stevens | 9440dc8 | 2017-03-16 19:00:20 -0700 | [diff] [blame] | 3935 | mStoppingActivities.remove(activityNdx); |
Craig Mautner | de4ef02 | 2013-04-07 19:01:33 -0700 | [diff] [blame] | 3936 | } |
Craig Mautner | de4ef02 | 2013-04-07 19:01:33 -0700 | [diff] [blame] | 3937 | } |
| 3938 | } |
| 3939 | |
| 3940 | return stops; |
| 3941 | } |
| 3942 | |
Craig Mautner | cf910b0 | 2013-04-23 11:23:27 -0700 | [diff] [blame] | 3943 | void validateTopActivitiesLocked() { |
Wale Ogunwale | ee006da | 2015-03-30 14:49:25 -0700 | [diff] [blame] | 3944 | for (int displayNdx = mActivityDisplays.size() - 1; displayNdx >= 0; --displayNdx) { |
Wale Ogunwale | a0f5b5e | 2017-10-11 09:37:23 -0700 | [diff] [blame] | 3945 | final ActivityDisplay display = mActivityDisplays.valueAt(displayNdx); |
| 3946 | for (int stackNdx = display.getChildCount() - 1; stackNdx >= 0; --stackNdx) { |
| 3947 | final ActivityStack stack = display.getChildAt(stackNdx); |
Filip Gruszczynski | 3e85ba2 | 2015-10-05 22:48:30 -0700 | [diff] [blame] | 3948 | final ActivityRecord r = stack.topRunningActivityLocked(); |
Bryce Lee | 7ace395 | 2018-02-16 14:34:32 -0800 | [diff] [blame] | 3949 | final ActivityState state = r == null ? DESTROYED : r.getState(); |
Wale Ogunwale | 1e60e0c | 2015-10-28 13:36:10 -0700 | [diff] [blame] | 3950 | if (isFocusedStack(stack)) { |
Wale Ogunwale | ee006da | 2015-03-30 14:49:25 -0700 | [diff] [blame] | 3951 | if (r == null) Slog.e(TAG, |
| 3952 | "validateTop...: null top activity, stack=" + stack); |
| 3953 | else { |
| 3954 | final ActivityRecord pausing = stack.mPausingActivity; |
| 3955 | if (pausing != null && pausing == r) Slog.e(TAG, |
| 3956 | "validateTop...: top stack has pausing activity r=" + r |
| 3957 | + " state=" + state); |
| 3958 | if (state != INITIALIZING && state != RESUMED) Slog.e(TAG, |
| 3959 | "validateTop...: activity in front not resumed r=" + r |
| 3960 | + " state=" + state); |
| 3961 | } |
Craig Mautner | cf910b0 | 2013-04-23 11:23:27 -0700 | [diff] [blame] | 3962 | } else { |
Bryce Lee | c4ab62a | 2018-03-05 14:19:26 -0800 | [diff] [blame] | 3963 | final ActivityRecord resumed = stack.getResumedActivity(); |
Wale Ogunwale | ee006da | 2015-03-30 14:49:25 -0700 | [diff] [blame] | 3964 | if (resumed != null && resumed == r) Slog.e(TAG, |
| 3965 | "validateTop...: back stack has resumed activity r=" + r |
| 3966 | + " state=" + state); |
| 3967 | if (r != null && (state == INITIALIZING || state == RESUMED)) Slog.e(TAG, |
| 3968 | "validateTop...: activity in back resumed r=" + r + " state=" + state); |
Craig Mautner | cf910b0 | 2013-04-23 11:23:27 -0700 | [diff] [blame] | 3969 | } |
| 3970 | } |
| 3971 | } |
Craig Mautner | 76ea224 | 2013-05-15 11:40:05 -0700 | [diff] [blame] | 3972 | } |
| 3973 | |
Bryce Lee | 77a7dd6 | 2018-01-22 15:47:09 -0800 | [diff] [blame] | 3974 | public void dumpDisplays(PrintWriter pw) { |
| 3975 | for (int i = mActivityDisplays.size() - 1; i >= 0; --i) { |
| 3976 | final ActivityDisplay display = mActivityDisplays.valueAt(i); |
| 3977 | pw.print("[id:" + display.mDisplayId + " stacks:"); |
| 3978 | display.dumpStacks(pw); |
| 3979 | pw.print("]"); |
| 3980 | } |
| 3981 | } |
| 3982 | |
Craig Mautner | 2708430 | 2013-03-25 08:05:25 -0700 | [diff] [blame] | 3983 | public void dump(PrintWriter pw, String prefix) { |
Craig Mautner | d1bbdb462 | 2013-10-22 09:53:20 -0700 | [diff] [blame] | 3984 | pw.print(prefix); pw.print("mFocusedStack=" + mFocusedStack); |
Craig Mautner | 4a1cb22 | 2013-12-04 16:14:06 -0800 | [diff] [blame] | 3985 | pw.print(" mLastFocusedStack="); pw.println(mLastFocusedStack); |
Suprabh Shukla | 09a88f5 | 2015-12-02 14:36:31 -0800 | [diff] [blame] | 3986 | pw.print(prefix); |
| 3987 | pw.println("mCurTaskIdForUser=" + mCurTaskIdForUser); |
Craig Mautner | d1bbdb462 | 2013-10-22 09:53:20 -0700 | [diff] [blame] | 3988 | pw.print(prefix); pw.println("mUserStackInFront=" + mUserStackInFront); |
Wale Ogunwale | 9dcf946 | 2017-09-19 15:13:01 -0700 | [diff] [blame] | 3989 | for (int i = mActivityDisplays.size() - 1; i >= 0; --i) { |
| 3990 | final ActivityDisplay display = mActivityDisplays.valueAt(i); |
Wale Ogunwale | a0f5b5e | 2017-10-11 09:37:23 -0700 | [diff] [blame] | 3991 | display.dump(pw, prefix); |
Wale Ogunwale | 9dcf946 | 2017-09-19 15:13:01 -0700 | [diff] [blame] | 3992 | } |
Bryce Lee | 4a19438 | 2017-04-04 14:32:48 -0700 | [diff] [blame] | 3993 | if (!mWaitingForActivityVisible.isEmpty()) { |
| 3994 | pw.print(prefix); pw.println("mWaitingForActivityVisible="); |
| 3995 | for (int i = 0; i < mWaitingForActivityVisible.size(); ++i) { |
| 3996 | pw.print(prefix); pw.print(prefix); mWaitingForActivityVisible.get(i).dump(pw, prefix); |
| 3997 | } |
| 3998 | } |
Winson Chung | c167427 | 2018-02-21 10:15:17 -0800 | [diff] [blame] | 3999 | pw.print(prefix); pw.print("isHomeRecentsComponent="); |
| 4000 | pw.print(mRecentTasks.isRecentsComponentHomeActivity(mCurrentUser)); |
Bryce Lee | 4a19438 | 2017-04-04 14:32:48 -0700 | [diff] [blame] | 4001 | |
Bryce Lee | 459c062 | 2018-03-19 11:04:01 -0700 | [diff] [blame] | 4002 | getKeyguardController().dump(pw, prefix); |
Bryce Lee | 2b8e037 | 2018-04-05 17:01:37 -0700 | [diff] [blame] | 4003 | mService.getLockTaskController().dump(pw, prefix); |
Craig Mautner | 2708430 | 2013-03-25 08:05:25 -0700 | [diff] [blame] | 4004 | } |
Craig Mautner | 8d341ef | 2013-03-26 09:03:27 -0700 | [diff] [blame] | 4005 | |
Yi Jin | 2b30f32 | 2018-02-20 15:41:47 -0800 | [diff] [blame] | 4006 | public void writeToProto(ProtoOutputStream proto, long fieldId) { |
| 4007 | final long token = proto.start(fieldId); |
Adrian Roos | 4921ccf | 2017-09-28 16:54:06 +0200 | [diff] [blame] | 4008 | super.writeToProto(proto, CONFIGURATION_CONTAINER, false /* trim */); |
Steven Timotius | 4346f0a | 2017-09-12 11:07:21 -0700 | [diff] [blame] | 4009 | for (int displayNdx = 0; displayNdx < mActivityDisplays.size(); ++displayNdx) { |
| 4010 | ActivityDisplay activityDisplay = mActivityDisplays.valueAt(displayNdx); |
| 4011 | activityDisplay.writeToProto(proto, DISPLAYS); |
| 4012 | } |
Bryce Lee | 459c062 | 2018-03-19 11:04:01 -0700 | [diff] [blame] | 4013 | getKeyguardController().writeToProto(proto, KEYGUARD_CONTROLLER); |
Steven Timotius | 4346f0a | 2017-09-12 11:07:21 -0700 | [diff] [blame] | 4014 | if (mFocusedStack != null) { |
| 4015 | proto.write(FOCUSED_STACK_ID, mFocusedStack.mStackId); |
| 4016 | ActivityRecord focusedActivity = getResumedActivityLocked(); |
| 4017 | if (focusedActivity != null) { |
| 4018 | focusedActivity.writeIdentifierToProto(proto, RESUMED_ACTIVITY); |
| 4019 | } |
| 4020 | } else { |
| 4021 | proto.write(FOCUSED_STACK_ID, INVALID_STACK_ID); |
| 4022 | } |
Winson Chung | c167427 | 2018-02-21 10:15:17 -0800 | [diff] [blame] | 4023 | proto.write(IS_HOME_RECENTS_COMPONENT, |
| 4024 | mRecentTasks.isRecentsComponentHomeActivity(mCurrentUser)); |
Yi Jin | 2b30f32 | 2018-02-20 15:41:47 -0800 | [diff] [blame] | 4025 | proto.end(token); |
Steven Timotius | 4346f0a | 2017-09-12 11:07:21 -0700 | [diff] [blame] | 4026 | } |
| 4027 | |
Winson | 43d1f26 | 2016-06-14 16:05:55 -0700 | [diff] [blame] | 4028 | /** |
Andrii Kulian | 5406e7a | 2016-10-21 11:55:23 -0700 | [diff] [blame] | 4029 | * Dump all connected displays' configurations. |
| 4030 | * @param prefix Prefix to apply to each line of the dump. |
| 4031 | */ |
| 4032 | void dumpDisplayConfigs(PrintWriter pw, String prefix) { |
| 4033 | pw.print(prefix); pw.println("Display override configurations:"); |
| 4034 | final int displayCount = mActivityDisplays.size(); |
| 4035 | for (int i = 0; i < displayCount; i++) { |
| 4036 | final ActivityDisplay activityDisplay = mActivityDisplays.valueAt(i); |
| 4037 | pw.print(prefix); pw.print(" "); pw.print(activityDisplay.mDisplayId); pw.print(": "); |
| 4038 | pw.println(activityDisplay.getOverrideConfiguration()); |
| 4039 | } |
| 4040 | } |
| 4041 | |
| 4042 | /** |
Winson | 43d1f26 | 2016-06-14 16:05:55 -0700 | [diff] [blame] | 4043 | * Dumps the activities matching the given {@param name} in the either the focused stack |
| 4044 | * or all visible stacks if {@param dumpVisibleStacks} is true. |
| 4045 | */ |
Winson Chung | 6998bc4 | 2017-02-28 17:07:05 -0800 | [diff] [blame] | 4046 | ArrayList<ActivityRecord> getDumpActivitiesLocked(String name, boolean dumpVisibleStacksOnly, |
| 4047 | boolean dumpFocusedStackOnly) { |
| 4048 | if (dumpFocusedStackOnly) { |
| 4049 | return mFocusedStack.getDumpActivitiesLocked(name); |
| 4050 | } else { |
Winson | 43d1f26 | 2016-06-14 16:05:55 -0700 | [diff] [blame] | 4051 | ArrayList<ActivityRecord> activities = new ArrayList<>(); |
| 4052 | int numDisplays = mActivityDisplays.size(); |
| 4053 | for (int displayNdx = 0; displayNdx < numDisplays; ++displayNdx) { |
Wale Ogunwale | a0f5b5e | 2017-10-11 09:37:23 -0700 | [diff] [blame] | 4054 | final ActivityDisplay display = mActivityDisplays.valueAt(displayNdx); |
| 4055 | for (int stackNdx = display.getChildCount() - 1; stackNdx >= 0; --stackNdx) { |
| 4056 | final ActivityStack stack = display.getChildAt(stackNdx); |
Wale Ogunwale | 9dcf946 | 2017-09-19 15:13:01 -0700 | [diff] [blame] | 4057 | if (!dumpVisibleStacksOnly || stack.shouldBeVisible(null)) { |
Winson | 43d1f26 | 2016-06-14 16:05:55 -0700 | [diff] [blame] | 4058 | activities.addAll(stack.getDumpActivitiesLocked(name)); |
| 4059 | } |
| 4060 | } |
| 4061 | } |
| 4062 | return activities; |
Winson | 43d1f26 | 2016-06-14 16:05:55 -0700 | [diff] [blame] | 4063 | } |
Craig Mautner | 20e7227 | 2013-04-01 13:45:53 -0700 | [diff] [blame] | 4064 | } |
| 4065 | |
Dianne Hackborn | 390517b | 2013-05-30 15:03:32 -0700 | [diff] [blame] | 4066 | static boolean printThisActivity(PrintWriter pw, ActivityRecord activity, String dumpPackage, |
| 4067 | boolean needSep, String prefix) { |
| 4068 | if (activity != null) { |
| 4069 | if (dumpPackage == null || dumpPackage.equals(activity.packageName)) { |
| 4070 | if (needSep) { |
| 4071 | pw.println(); |
Dianne Hackborn | 390517b | 2013-05-30 15:03:32 -0700 | [diff] [blame] | 4072 | } |
| 4073 | pw.print(prefix); |
| 4074 | pw.println(activity); |
Dianne Hackborn | 7ad34e5 | 2013-06-05 18:41:45 -0700 | [diff] [blame] | 4075 | return true; |
Dianne Hackborn | 390517b | 2013-05-30 15:03:32 -0700 | [diff] [blame] | 4076 | } |
| 4077 | } |
Dianne Hackborn | 7ad34e5 | 2013-06-05 18:41:45 -0700 | [diff] [blame] | 4078 | return false; |
Dianne Hackborn | 390517b | 2013-05-30 15:03:32 -0700 | [diff] [blame] | 4079 | } |
| 4080 | |
Craig Mautner | 8d341ef | 2013-03-26 09:03:27 -0700 | [diff] [blame] | 4081 | boolean dumpActivitiesLocked(FileDescriptor fd, PrintWriter pw, boolean dumpAll, |
| 4082 | boolean dumpClient, String dumpPackage) { |
Dianne Hackborn | 7ad34e5 | 2013-06-05 18:41:45 -0700 | [diff] [blame] | 4083 | boolean printed = false; |
| 4084 | boolean needSep = false; |
Craig Mautner | e0a3884 | 2013-12-16 16:14:02 -0800 | [diff] [blame] | 4085 | for (int displayNdx = 0; displayNdx < mActivityDisplays.size(); ++displayNdx) { |
| 4086 | ActivityDisplay activityDisplay = mActivityDisplays.valueAt(displayNdx); |
Craig Mautner | ee2e45a | 2014-06-27 12:10:03 -0700 | [diff] [blame] | 4087 | pw.print("Display #"); pw.print(activityDisplay.mDisplayId); |
Craig Mautner | 737fae2 | 2014-10-15 12:52:10 -0700 | [diff] [blame] | 4088 | pw.println(" (activities from top to bottom):"); |
Wale Ogunwale | a0f5b5e | 2017-10-11 09:37:23 -0700 | [diff] [blame] | 4089 | final ActivityDisplay display = mActivityDisplays.valueAt(displayNdx); |
| 4090 | for (int stackNdx = display.getChildCount() - 1; stackNdx >= 0; --stackNdx) { |
| 4091 | final ActivityStack stack = display.getChildAt(stackNdx); |
Wale Ogunwale | 34a5b57 | 2017-08-31 08:29:41 -0700 | [diff] [blame] | 4092 | pw.println(); |
Wale Ogunwale | 44f036f | 2017-09-29 05:09:09 -0700 | [diff] [blame] | 4093 | pw.println(" Stack #" + stack.mStackId |
Wale Ogunwale | 6191149 | 2017-10-11 08:50:50 -0700 | [diff] [blame] | 4094 | + ": type=" + activityTypeToString(stack.getActivityType()) |
| 4095 | + " mode=" + windowingModeToString(stack.getWindowingMode())); |
Wale Ogunwale | 34a5b57 | 2017-08-31 08:29:41 -0700 | [diff] [blame] | 4096 | pw.println(" isSleeping=" + stack.shouldSleepActivities()); |
Bryce Lee | f3c6a47 | 2017-11-14 14:53:06 -0800 | [diff] [blame] | 4097 | pw.println(" mBounds=" + stack.getOverrideBounds()); |
Winson Chung | abb433b | 2017-03-24 09:35:42 -0700 | [diff] [blame] | 4098 | |
Wale Ogunwale | 34a5b57 | 2017-08-31 08:29:41 -0700 | [diff] [blame] | 4099 | printed |= stack.dumpActivitiesLocked(fd, pw, dumpAll, dumpClient, dumpPackage, |
| 4100 | needSep); |
Winson Chung | abb433b | 2017-03-24 09:35:42 -0700 | [diff] [blame] | 4101 | |
Craig Mautner | 4a1cb22 | 2013-12-04 16:14:06 -0800 | [diff] [blame] | 4102 | printed |= dumpHistoryList(fd, pw, stack.mLRUActivities, " ", "Run", false, |
| 4103 | !dumpAll, false, dumpPackage, true, |
| 4104 | " Running activities (most recent first):", null); |
Craig Mautner | 8d341ef | 2013-03-26 09:03:27 -0700 | [diff] [blame] | 4105 | |
Craig Mautner | 4a1cb22 | 2013-12-04 16:14:06 -0800 | [diff] [blame] | 4106 | needSep = printed; |
| 4107 | boolean pr = printThisActivity(pw, stack.mPausingActivity, dumpPackage, needSep, |
| 4108 | " mPausingActivity: "); |
Dianne Hackborn | 7ad34e5 | 2013-06-05 18:41:45 -0700 | [diff] [blame] | 4109 | if (pr) { |
| 4110 | printed = true; |
Craig Mautner | 4a1cb22 | 2013-12-04 16:14:06 -0800 | [diff] [blame] | 4111 | needSep = false; |
Dianne Hackborn | 7ad34e5 | 2013-06-05 18:41:45 -0700 | [diff] [blame] | 4112 | } |
Bryce Lee | c4ab62a | 2018-03-05 14:19:26 -0800 | [diff] [blame] | 4113 | pr = printThisActivity(pw, stack.getResumedActivity(), dumpPackage, needSep, |
Craig Mautner | 4a1cb22 | 2013-12-04 16:14:06 -0800 | [diff] [blame] | 4114 | " mResumedActivity: "); |
| 4115 | if (pr) { |
| 4116 | printed = true; |
| 4117 | needSep = false; |
| 4118 | } |
| 4119 | if (dumpAll) { |
| 4120 | pr = printThisActivity(pw, stack.mLastPausedActivity, dumpPackage, needSep, |
| 4121 | " mLastPausedActivity: "); |
| 4122 | if (pr) { |
| 4123 | printed = true; |
| 4124 | needSep = true; |
| 4125 | } |
| 4126 | printed |= printThisActivity(pw, stack.mLastNoHistoryActivity, dumpPackage, |
| 4127 | needSep, " mLastNoHistoryActivity: "); |
| 4128 | } |
| 4129 | needSep = printed; |
Craig Mautner | 8d341ef | 2013-03-26 09:03:27 -0700 | [diff] [blame] | 4130 | } |
| 4131 | } |
| 4132 | |
Dianne Hackborn | 7ad34e5 | 2013-06-05 18:41:45 -0700 | [diff] [blame] | 4133 | printed |= dumpHistoryList(fd, pw, mFinishingActivities, " ", "Fin", false, !dumpAll, |
| 4134 | false, dumpPackage, true, " Activities waiting to finish:", null); |
| 4135 | printed |= dumpHistoryList(fd, pw, mStoppingActivities, " ", "Stop", false, !dumpAll, |
| 4136 | false, dumpPackage, true, " Activities waiting to stop:", null); |
Bryce Lee | 4a19438 | 2017-04-04 14:32:48 -0700 | [diff] [blame] | 4137 | printed |= dumpHistoryList(fd, pw, mActivitiesWaitingForVisibleActivity, " ", "Wait", |
| 4138 | false, !dumpAll, false, dumpPackage, true, |
| 4139 | " Activities waiting for another to become visible:", null); |
Dianne Hackborn | 7ad34e5 | 2013-06-05 18:41:45 -0700 | [diff] [blame] | 4140 | printed |= dumpHistoryList(fd, pw, mGoingToSleepActivities, " ", "Sleep", false, !dumpAll, |
| 4141 | false, dumpPackage, true, " Activities waiting to sleep:", null); |
Craig Mautner | f333327 | 2013-04-22 10:55:53 -0700 | [diff] [blame] | 4142 | |
Dianne Hackborn | 7ad34e5 | 2013-06-05 18:41:45 -0700 | [diff] [blame] | 4143 | return printed; |
Craig Mautner | 8d341ef | 2013-03-26 09:03:27 -0700 | [diff] [blame] | 4144 | } |
| 4145 | |
Dianne Hackborn | 390517b | 2013-05-30 15:03:32 -0700 | [diff] [blame] | 4146 | static boolean dumpHistoryList(FileDescriptor fd, PrintWriter pw, List<ActivityRecord> list, |
Craig Mautner | 8d341ef | 2013-03-26 09:03:27 -0700 | [diff] [blame] | 4147 | String prefix, String label, boolean complete, boolean brief, boolean client, |
Wale Ogunwale | 34a5b57 | 2017-08-31 08:29:41 -0700 | [diff] [blame] | 4148 | String dumpPackage, boolean needNL, String header, TaskRecord lastTask) { |
Dianne Hackborn | 390517b | 2013-05-30 15:03:32 -0700 | [diff] [blame] | 4149 | String innerPrefix = null; |
| 4150 | String[] args = null; |
| 4151 | boolean printed = false; |
Craig Mautner | 8d341ef | 2013-03-26 09:03:27 -0700 | [diff] [blame] | 4152 | for (int i=list.size()-1; i>=0; i--) { |
| 4153 | final ActivityRecord r = list.get(i); |
| 4154 | if (dumpPackage != null && !dumpPackage.equals(r.packageName)) { |
| 4155 | continue; |
| 4156 | } |
Dianne Hackborn | 390517b | 2013-05-30 15:03:32 -0700 | [diff] [blame] | 4157 | if (innerPrefix == null) { |
| 4158 | innerPrefix = prefix + " "; |
| 4159 | args = new String[0]; |
| 4160 | } |
| 4161 | printed = true; |
Craig Mautner | 8d341ef | 2013-03-26 09:03:27 -0700 | [diff] [blame] | 4162 | final boolean full = !brief && (complete || !r.isInHistory()); |
| 4163 | if (needNL) { |
Dianne Hackborn | 390517b | 2013-05-30 15:03:32 -0700 | [diff] [blame] | 4164 | pw.println(""); |
Craig Mautner | 8d341ef | 2013-03-26 09:03:27 -0700 | [diff] [blame] | 4165 | needNL = false; |
| 4166 | } |
Wale Ogunwale | 34a5b57 | 2017-08-31 08:29:41 -0700 | [diff] [blame] | 4167 | if (header != null) { |
| 4168 | pw.println(header); |
| 4169 | header = null; |
Dianne Hackborn | 390517b | 2013-05-30 15:03:32 -0700 | [diff] [blame] | 4170 | } |
Bryce Lee | af691c0 | 2017-03-20 14:20:22 -0700 | [diff] [blame] | 4171 | if (lastTask != r.getTask()) { |
| 4172 | lastTask = r.getTask(); |
Craig Mautner | 8d341ef | 2013-03-26 09:03:27 -0700 | [diff] [blame] | 4173 | pw.print(prefix); |
| 4174 | pw.print(full ? "* " : " "); |
| 4175 | pw.println(lastTask); |
| 4176 | if (full) { |
| 4177 | lastTask.dump(pw, prefix + " "); |
| 4178 | } else if (complete) { |
| 4179 | // Complete + brief == give a summary. Isn't that obvious?!? |
| 4180 | if (lastTask.intent != null) { |
| 4181 | pw.print(prefix); pw.print(" "); |
| 4182 | pw.println(lastTask.intent.toInsecureStringWithClip()); |
| 4183 | } |
| 4184 | } |
| 4185 | } |
| 4186 | pw.print(prefix); pw.print(full ? " * " : " "); pw.print(label); |
| 4187 | pw.print(" #"); pw.print(i); pw.print(": "); |
| 4188 | pw.println(r); |
| 4189 | if (full) { |
| 4190 | r.dump(pw, innerPrefix); |
| 4191 | } else if (complete) { |
| 4192 | // Complete + brief == give a summary. Isn't that obvious?!? |
| 4193 | pw.print(innerPrefix); pw.println(r.intent.toInsecureString()); |
| 4194 | if (r.app != null) { |
| 4195 | pw.print(innerPrefix); pw.println(r.app); |
| 4196 | } |
| 4197 | } |
| 4198 | if (client && r.app != null && r.app.thread != null) { |
| 4199 | // flush anything that is already in the PrintWriter since the thread is going |
| 4200 | // to write to the file descriptor directly |
| 4201 | pw.flush(); |
| 4202 | try { |
| 4203 | TransferPipe tp = new TransferPipe(); |
| 4204 | try { |
Sudheer Shanka | cc6418f | 2016-10-13 12:03:44 -0700 | [diff] [blame] | 4205 | r.app.thread.dumpActivity(tp.getWriteFd(), r.appToken, innerPrefix, args); |
Craig Mautner | 8d341ef | 2013-03-26 09:03:27 -0700 | [diff] [blame] | 4206 | // Short timeout, since blocking here can |
| 4207 | // deadlock with the application. |
| 4208 | tp.go(fd, 2000); |
| 4209 | } finally { |
| 4210 | tp.kill(); |
| 4211 | } |
| 4212 | } catch (IOException e) { |
| 4213 | pw.println(innerPrefix + "Failure while dumping the activity: " + e); |
| 4214 | } catch (RemoteException e) { |
| 4215 | pw.println(innerPrefix + "Got a RemoteException while dumping the activity"); |
| 4216 | } |
| 4217 | needNL = true; |
| 4218 | } |
| 4219 | } |
Dianne Hackborn | 390517b | 2013-05-30 15:03:32 -0700 | [diff] [blame] | 4220 | return printed; |
Craig Mautner | 8d341ef | 2013-03-26 09:03:27 -0700 | [diff] [blame] | 4221 | } |
Craig Mautner | ce5f3cb | 2013-04-22 08:58:54 -0700 | [diff] [blame] | 4222 | |
Craig Mautner | f333327 | 2013-04-22 10:55:53 -0700 | [diff] [blame] | 4223 | void scheduleIdleTimeoutLocked(ActivityRecord next) { |
Wale Ogunwale | 0fc365c | 2015-05-25 19:35:42 -0700 | [diff] [blame] | 4224 | if (DEBUG_IDLE) Slog.d(TAG_IDLE, |
| 4225 | "scheduleIdleTimeoutLocked: Callers=" + Debug.getCallers(4)); |
Craig Mautner | c64f73e | 2013-04-24 16:44:56 -0700 | [diff] [blame] | 4226 | Message msg = mHandler.obtainMessage(IDLE_TIMEOUT_MSG, next); |
| 4227 | mHandler.sendMessageDelayed(msg, IDLE_TIMEOUT); |
Craig Mautner | f333327 | 2013-04-22 10:55:53 -0700 | [diff] [blame] | 4228 | } |
| 4229 | |
| 4230 | final void scheduleIdleLocked() { |
Craig Mautner | 05d2903 | 2013-05-03 13:40:13 -0700 | [diff] [blame] | 4231 | mHandler.sendEmptyMessage(IDLE_NOW_MSG); |
Craig Mautner | f333327 | 2013-04-22 10:55:53 -0700 | [diff] [blame] | 4232 | } |
| 4233 | |
| 4234 | void removeTimeoutsForActivityLocked(ActivityRecord r) { |
Wale Ogunwale | 0fc365c | 2015-05-25 19:35:42 -0700 | [diff] [blame] | 4235 | if (DEBUG_IDLE) Slog.d(TAG_IDLE, "removeTimeoutsForActivity: Callers=" |
| 4236 | + Debug.getCallers(4)); |
Craig Mautner | f333327 | 2013-04-22 10:55:53 -0700 | [diff] [blame] | 4237 | mHandler.removeMessages(IDLE_TIMEOUT_MSG, r); |
| 4238 | } |
| 4239 | |
Craig Mautner | 05d2903 | 2013-05-03 13:40:13 -0700 | [diff] [blame] | 4240 | final void scheduleResumeTopActivities() { |
Craig Mautner | 34b73df | 2014-01-12 21:11:08 -0800 | [diff] [blame] | 4241 | if (!mHandler.hasMessages(RESUME_TOP_ACTIVITY_MSG)) { |
| 4242 | mHandler.sendEmptyMessage(RESUME_TOP_ACTIVITY_MSG); |
| 4243 | } |
Craig Mautner | 05d2903 | 2013-05-03 13:40:13 -0700 | [diff] [blame] | 4244 | } |
| 4245 | |
Craig Mautner | 0eea92c | 2013-05-16 13:35:39 -0700 | [diff] [blame] | 4246 | void removeSleepTimeouts() { |
Craig Mautner | 0eea92c | 2013-05-16 13:35:39 -0700 | [diff] [blame] | 4247 | mHandler.removeMessages(SLEEP_TIMEOUT_MSG); |
| 4248 | } |
| 4249 | |
| 4250 | final void scheduleSleepTimeout() { |
| 4251 | removeSleepTimeouts(); |
| 4252 | mHandler.sendEmptyMessageDelayed(SLEEP_TIMEOUT_MSG, SLEEP_TIMEOUT); |
| 4253 | } |
| 4254 | |
Craig Mautner | 4a1cb22 | 2013-12-04 16:14:06 -0800 | [diff] [blame] | 4255 | @Override |
| 4256 | public void onDisplayAdded(int displayId) { |
Dianne Hackborn | fb81d09 | 2015-08-03 17:14:46 -0700 | [diff] [blame] | 4257 | if (DEBUG_STACK) Slog.v(TAG, "Display added displayId=" + displayId); |
Craig Mautner | 4a1cb22 | 2013-12-04 16:14:06 -0800 | [diff] [blame] | 4258 | mHandler.sendMessage(mHandler.obtainMessage(HANDLE_DISPLAY_ADDED, displayId, 0)); |
| 4259 | } |
| 4260 | |
| 4261 | @Override |
| 4262 | public void onDisplayRemoved(int displayId) { |
Dianne Hackborn | fb81d09 | 2015-08-03 17:14:46 -0700 | [diff] [blame] | 4263 | if (DEBUG_STACK) Slog.v(TAG, "Display removed displayId=" + displayId); |
Craig Mautner | 4a1cb22 | 2013-12-04 16:14:06 -0800 | [diff] [blame] | 4264 | mHandler.sendMessage(mHandler.obtainMessage(HANDLE_DISPLAY_REMOVED, displayId, 0)); |
| 4265 | } |
| 4266 | |
| 4267 | @Override |
| 4268 | public void onDisplayChanged(int displayId) { |
Dianne Hackborn | fb81d09 | 2015-08-03 17:14:46 -0700 | [diff] [blame] | 4269 | if (DEBUG_STACK) Slog.v(TAG, "Display changed displayId=" + displayId); |
Craig Mautner | 4a1cb22 | 2013-12-04 16:14:06 -0800 | [diff] [blame] | 4270 | mHandler.sendMessage(mHandler.obtainMessage(HANDLE_DISPLAY_CHANGED, displayId, 0)); |
| 4271 | } |
| 4272 | |
Wale Ogunwale | f16a281 | 2015-04-01 11:23:15 -0700 | [diff] [blame] | 4273 | private void handleDisplayAdded(int displayId) { |
Craig Mautner | 4a1cb22 | 2013-12-04 16:14:06 -0800 | [diff] [blame] | 4274 | synchronized (mService) { |
Andrii Kulian | 62e6f25 | 2017-05-30 22:46:53 -0700 | [diff] [blame] | 4275 | getActivityDisplayOrCreateLocked(displayId); |
Craig Mautner | 4a1cb22 | 2013-12-04 16:14:06 -0800 | [diff] [blame] | 4276 | } |
Craig Mautner | 4a1cb22 | 2013-12-04 16:14:06 -0800 | [diff] [blame] | 4277 | } |
| 4278 | |
Andrii Kulian | ca007a6 | 2016-11-22 16:33:28 -0800 | [diff] [blame] | 4279 | /** Check if display with specified id is added to the list. */ |
| 4280 | boolean isDisplayAdded(int displayId) { |
Andrii Kulian | 62e6f25 | 2017-05-30 22:46:53 -0700 | [diff] [blame] | 4281 | return getActivityDisplayOrCreateLocked(displayId) != null; |
| 4282 | } |
| 4283 | |
Wale Ogunwale | 04a05ac | 2017-09-17 21:35:02 -0700 | [diff] [blame] | 4284 | // TODO: Look into consolidating with getActivityDisplayOrCreateLocked() |
Andrii Kulian | 94e82d9b0 | 2017-07-13 15:33:06 -0700 | [diff] [blame] | 4285 | ActivityDisplay getActivityDisplay(int displayId) { |
| 4286 | return mActivityDisplays.get(displayId); |
| 4287 | } |
| 4288 | |
Wale Ogunwale | 04a05ac | 2017-09-17 21:35:02 -0700 | [diff] [blame] | 4289 | // TODO(multi-display): Look at all callpoints to make sure they make sense in multi-display. |
| 4290 | ActivityDisplay getDefaultDisplay() { |
| 4291 | return mActivityDisplays.get(DEFAULT_DISPLAY); |
| 4292 | } |
| 4293 | |
Andrii Kulian | 62e6f25 | 2017-05-30 22:46:53 -0700 | [diff] [blame] | 4294 | /** |
| 4295 | * Get an existing instance of {@link ActivityDisplay} or create new if there is a |
| 4296 | * corresponding record in display manager. |
| 4297 | */ |
Wale Ogunwale | 04a05ac | 2017-09-17 21:35:02 -0700 | [diff] [blame] | 4298 | // TODO: Look into consolidating with getActivityDisplay() |
| 4299 | ActivityDisplay getActivityDisplayOrCreateLocked(int displayId) { |
Andrii Kulian | 62e6f25 | 2017-05-30 22:46:53 -0700 | [diff] [blame] | 4300 | ActivityDisplay activityDisplay = mActivityDisplays.get(displayId); |
| 4301 | if (activityDisplay != null) { |
| 4302 | return activityDisplay; |
| 4303 | } |
| 4304 | if (mDisplayManager == null) { |
| 4305 | // The system isn't fully initialized yet. |
| 4306 | return null; |
| 4307 | } |
| 4308 | final Display display = mDisplayManager.getDisplay(displayId); |
| 4309 | if (display == null) { |
| 4310 | // The display is not registered in DisplayManager. |
| 4311 | return null; |
| 4312 | } |
| 4313 | // 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] | 4314 | activityDisplay = new ActivityDisplay(this, display); |
Wale Ogunwale | 9dcf946 | 2017-09-19 15:13:01 -0700 | [diff] [blame] | 4315 | attachDisplay(activityDisplay); |
Andrii Kulian | 62e6f25 | 2017-05-30 22:46:53 -0700 | [diff] [blame] | 4316 | calculateDefaultMinimalSizeOfResizeableTasks(activityDisplay); |
| 4317 | mWindowManager.onDisplayAdded(displayId); |
| 4318 | return activityDisplay; |
Andrii Kulian | ca007a6 | 2016-11-22 16:33:28 -0800 | [diff] [blame] | 4319 | } |
| 4320 | |
Wale Ogunwale | 9dcf946 | 2017-09-19 15:13:01 -0700 | [diff] [blame] | 4321 | @VisibleForTesting |
| 4322 | void attachDisplay(ActivityDisplay display) { |
| 4323 | mActivityDisplays.put(display.mDisplayId, display); |
| 4324 | } |
| 4325 | |
Filip Gruszczynski | d2f1d94 | 2015-10-14 15:10:12 -0700 | [diff] [blame] | 4326 | private void calculateDefaultMinimalSizeOfResizeableTasks(ActivityDisplay display) { |
Andrii Kulian | f66a83d | 2016-05-17 12:17:44 -0700 | [diff] [blame] | 4327 | mDefaultMinSizeOfResizeableTask = |
Jorim Jaggi | 19cf297 | 2016-04-07 23:26:10 -0700 | [diff] [blame] | 4328 | mService.mContext.getResources().getDimensionPixelSize( |
| 4329 | com.android.internal.R.dimen.default_minimal_size_resizable_task); |
Filip Gruszczynski | d2f1d94 | 2015-10-14 15:10:12 -0700 | [diff] [blame] | 4330 | } |
| 4331 | |
Wale Ogunwale | f16a281 | 2015-04-01 11:23:15 -0700 | [diff] [blame] | 4332 | private void handleDisplayRemoved(int displayId) { |
Andrii Kulian | a33818c | 2017-02-16 16:11:30 -0800 | [diff] [blame] | 4333 | if (displayId == DEFAULT_DISPLAY) { |
| 4334 | throw new IllegalArgumentException("Can't remove the primary display."); |
| 4335 | } |
| 4336 | |
Craig Mautner | 4a1cb22 | 2013-12-04 16:14:06 -0800 | [diff] [blame] | 4337 | synchronized (mService) { |
Wale Ogunwale | a0f5b5e | 2017-10-11 09:37:23 -0700 | [diff] [blame] | 4338 | final ActivityDisplay activityDisplay = mActivityDisplays.get(displayId); |
| 4339 | if (activityDisplay == null) { |
| 4340 | return; |
Craig Mautner | 4a1cb22 | 2013-12-04 16:14:06 -0800 | [diff] [blame] | 4341 | } |
Bryce Lee | f19cbe2 | 2018-02-02 15:09:21 -0800 | [diff] [blame] | 4342 | |
| 4343 | activityDisplay.remove(); |
Wale Ogunwale | a0f5b5e | 2017-10-11 09:37:23 -0700 | [diff] [blame] | 4344 | |
| 4345 | releaseSleepTokens(activityDisplay); |
| 4346 | |
| 4347 | mActivityDisplays.remove(displayId); |
Craig Mautner | 4a1cb22 | 2013-12-04 16:14:06 -0800 | [diff] [blame] | 4348 | } |
Craig Mautner | 4a1cb22 | 2013-12-04 16:14:06 -0800 | [diff] [blame] | 4349 | } |
| 4350 | |
Wale Ogunwale | f16a281 | 2015-04-01 11:23:15 -0700 | [diff] [blame] | 4351 | private void handleDisplayChanged(int displayId) { |
Craig Mautner | 4a1cb22 | 2013-12-04 16:14:06 -0800 | [diff] [blame] | 4352 | synchronized (mService) { |
Craig Mautner | e0a3884 | 2013-12-16 16:14:02 -0800 | [diff] [blame] | 4353 | ActivityDisplay activityDisplay = mActivityDisplays.get(displayId); |
Bryce Lee | f3c6a47 | 2017-11-14 14:53:06 -0800 | [diff] [blame] | 4354 | // TODO: The following code block should be moved into {@link ActivityDisplay}. |
Craig Mautner | e0a3884 | 2013-12-16 16:14:02 -0800 | [diff] [blame] | 4355 | if (activityDisplay != null) { |
David Stevens | 9440dc8 | 2017-03-16 19:00:20 -0700 | [diff] [blame] | 4356 | // The window policy is responsible for stopping activities on the default display |
| 4357 | if (displayId != Display.DEFAULT_DISPLAY) { |
| 4358 | int displayState = activityDisplay.mDisplay.getState(); |
| 4359 | if (displayState == Display.STATE_OFF && activityDisplay.mOffToken == null) { |
| 4360 | activityDisplay.mOffToken = |
| 4361 | mService.acquireSleepToken("Display-off", displayId); |
| 4362 | } else if (displayState == Display.STATE_ON |
| 4363 | && activityDisplay.mOffToken != null) { |
| 4364 | activityDisplay.mOffToken.release(); |
| 4365 | activityDisplay.mOffToken = null; |
| 4366 | } |
| 4367 | } |
Bryce Lee | f3c6a47 | 2017-11-14 14:53:06 -0800 | [diff] [blame] | 4368 | |
| 4369 | activityDisplay.updateBounds(); |
Craig Mautner | 4a1cb22 | 2013-12-04 16:14:06 -0800 | [diff] [blame] | 4370 | } |
Bryce Lee | af3a400 | 2017-03-20 10:37:12 -0700 | [diff] [blame] | 4371 | mWindowManager.onDisplayChanged(displayId); |
Craig Mautner | 4a1cb22 | 2013-12-04 16:14:06 -0800 | [diff] [blame] | 4372 | } |
Craig Mautner | 4a1cb22 | 2013-12-04 16:14:06 -0800 | [diff] [blame] | 4373 | } |
| 4374 | |
David Stevens | 9440dc8 | 2017-03-16 19:00:20 -0700 | [diff] [blame] | 4375 | SleepToken createSleepTokenLocked(String tag, int displayId) { |
| 4376 | ActivityDisplay display = mActivityDisplays.get(displayId); |
| 4377 | if (display == null) { |
| 4378 | throw new IllegalArgumentException("Invalid display: " + displayId); |
| 4379 | } |
| 4380 | |
| 4381 | final SleepTokenImpl token = new SleepTokenImpl(tag, displayId); |
| 4382 | mSleepTokens.add(token); |
| 4383 | display.mAllSleepTokens.add(token); |
| 4384 | return token; |
| 4385 | } |
| 4386 | |
| 4387 | private void removeSleepTokenLocked(SleepTokenImpl token) { |
| 4388 | mSleepTokens.remove(token); |
| 4389 | |
| 4390 | ActivityDisplay display = mActivityDisplays.get(token.mDisplayId); |
| 4391 | if (display != null) { |
| 4392 | display.mAllSleepTokens.remove(token); |
| 4393 | if (display.mAllSleepTokens.isEmpty()) { |
| 4394 | mService.updateSleepIfNeededLocked(); |
| 4395 | } |
| 4396 | } |
| 4397 | } |
| 4398 | |
| 4399 | private void releaseSleepTokens(ActivityDisplay display) { |
| 4400 | if (display.mAllSleepTokens.isEmpty()) { |
| 4401 | return; |
| 4402 | } |
Wale Ogunwale | 9dcf946 | 2017-09-19 15:13:01 -0700 | [diff] [blame] | 4403 | for (SleepToken token : display.mAllSleepTokens) { |
David Stevens | 9440dc8 | 2017-03-16 19:00:20 -0700 | [diff] [blame] | 4404 | mSleepTokens.remove(token); |
| 4405 | } |
| 4406 | display.mAllSleepTokens.clear(); |
| 4407 | |
| 4408 | mService.updateSleepIfNeededLocked(); |
| 4409 | } |
| 4410 | |
Wale Ogunwale | 6827856 | 2017-09-23 17:13:55 -0700 | [diff] [blame] | 4411 | private StackInfo getStackInfo(ActivityStack stack) { |
Andrii Kulian | 7e215d7 | 2017-04-26 18:33:28 -0700 | [diff] [blame] | 4412 | final int displayId = stack.mDisplayId; |
| 4413 | final ActivityDisplay display = mActivityDisplays.get(displayId); |
Craig Mautner | 4a1cb22 | 2013-12-04 16:14:06 -0800 | [diff] [blame] | 4414 | StackInfo info = new StackInfo(); |
Wale Ogunwale | 1666e31 | 2016-12-16 11:27:18 -0800 | [diff] [blame] | 4415 | stack.getWindowContainerBounds(info.bounds); |
Andrii Kulian | 7e215d7 | 2017-04-26 18:33:28 -0700 | [diff] [blame] | 4416 | info.displayId = displayId; |
Craig Mautner | 4a1cb22 | 2013-12-04 16:14:06 -0800 | [diff] [blame] | 4417 | info.stackId = stack.mStackId; |
Filip Gruszczynski | 21199bd | 2015-12-02 12:49:58 -0800 | [diff] [blame] | 4418 | info.userId = stack.mCurrentUser; |
Wale Ogunwale | 9dcf946 | 2017-09-19 15:13:01 -0700 | [diff] [blame] | 4419 | info.visible = stack.shouldBeVisible(null); |
Andrii Kulian | 62e6f25 | 2017-05-30 22:46:53 -0700 | [diff] [blame] | 4420 | // A stack might be not attached to a display. |
Wale Ogunwale | a0f5b5e | 2017-10-11 09:37:23 -0700 | [diff] [blame] | 4421 | info.position = display != null ? display.getIndexOf(stack) : 0; |
Wale Ogunwale | 6827856 | 2017-09-23 17:13:55 -0700 | [diff] [blame] | 4422 | info.configuration.setTo(stack.getConfiguration()); |
Craig Mautner | 4a1cb22 | 2013-12-04 16:14:06 -0800 | [diff] [blame] | 4423 | |
| 4424 | ArrayList<TaskRecord> tasks = stack.getAllTasks(); |
| 4425 | final int numTasks = tasks.size(); |
| 4426 | int[] taskIds = new int[numTasks]; |
| 4427 | String[] taskNames = new String[numTasks]; |
Wale Ogunwale | e4a0c57 | 2015-06-30 08:40:31 -0700 | [diff] [blame] | 4428 | Rect[] taskBounds = new Rect[numTasks]; |
Filip Gruszczynski | 21199bd | 2015-12-02 12:49:58 -0800 | [diff] [blame] | 4429 | int[] taskUserIds = new int[numTasks]; |
Craig Mautner | 4a1cb22 | 2013-12-04 16:14:06 -0800 | [diff] [blame] | 4430 | for (int i = 0; i < numTasks; ++i) { |
| 4431 | final TaskRecord task = tasks.get(i); |
| 4432 | taskIds[i] = task.taskId; |
| 4433 | taskNames[i] = task.origActivity != null ? task.origActivity.flattenToString() |
| 4434 | : task.realActivity != null ? task.realActivity.flattenToString() |
| 4435 | : task.getTopActivity() != null ? task.getTopActivity().packageName |
| 4436 | : "unknown"; |
Wale Ogunwale | e4a0c57 | 2015-06-30 08:40:31 -0700 | [diff] [blame] | 4437 | taskBounds[i] = new Rect(); |
Wale Ogunwale | e1fe7fa2 | 2016-12-15 18:27:00 -0800 | [diff] [blame] | 4438 | task.getWindowContainerBounds(taskBounds[i]); |
Filip Gruszczynski | 21199bd | 2015-12-02 12:49:58 -0800 | [diff] [blame] | 4439 | taskUserIds[i] = task.userId; |
Craig Mautner | 4a1cb22 | 2013-12-04 16:14:06 -0800 | [diff] [blame] | 4440 | } |
| 4441 | info.taskIds = taskIds; |
| 4442 | info.taskNames = taskNames; |
Wale Ogunwale | 868a5e1 | 2015-08-02 16:19:20 -0700 | [diff] [blame] | 4443 | info.taskBounds = taskBounds; |
Filip Gruszczynski | 21199bd | 2015-12-02 12:49:58 -0800 | [diff] [blame] | 4444 | info.taskUserIds = taskUserIds; |
Winson | d46b727 | 2016-04-20 11:54:27 -0700 | [diff] [blame] | 4445 | |
| 4446 | final ActivityRecord top = stack.topRunningActivityLocked(); |
| 4447 | info.topActivity = top != null ? top.intent.getComponent() : null; |
Craig Mautner | 4a1cb22 | 2013-12-04 16:14:06 -0800 | [diff] [blame] | 4448 | return info; |
| 4449 | } |
| 4450 | |
Wale Ogunwale | 6827856 | 2017-09-23 17:13:55 -0700 | [diff] [blame] | 4451 | StackInfo getStackInfo(int stackId) { |
Craig Mautner | 4a1cb22 | 2013-12-04 16:14:06 -0800 | [diff] [blame] | 4452 | ActivityStack stack = getStack(stackId); |
| 4453 | if (stack != null) { |
Wale Ogunwale | 6827856 | 2017-09-23 17:13:55 -0700 | [diff] [blame] | 4454 | return getStackInfo(stack); |
Craig Mautner | 4a1cb22 | 2013-12-04 16:14:06 -0800 | [diff] [blame] | 4455 | } |
| 4456 | return null; |
| 4457 | } |
| 4458 | |
Wale Ogunwale | 6827856 | 2017-09-23 17:13:55 -0700 | [diff] [blame] | 4459 | StackInfo getStackInfo(int windowingMode, int activityType) { |
| 4460 | final ActivityStack stack = getStack(windowingMode, activityType); |
| 4461 | return (stack != null) ? getStackInfo(stack) : null; |
| 4462 | } |
| 4463 | |
Craig Mautner | 4a1cb22 | 2013-12-04 16:14:06 -0800 | [diff] [blame] | 4464 | ArrayList<StackInfo> getAllStackInfosLocked() { |
Wale Ogunwale | e4a0c57 | 2015-06-30 08:40:31 -0700 | [diff] [blame] | 4465 | ArrayList<StackInfo> list = new ArrayList<>(); |
Craig Mautner | e0a3884 | 2013-12-16 16:14:02 -0800 | [diff] [blame] | 4466 | for (int displayNdx = 0; displayNdx < mActivityDisplays.size(); ++displayNdx) { |
Wale Ogunwale | a0f5b5e | 2017-10-11 09:37:23 -0700 | [diff] [blame] | 4467 | final ActivityDisplay display = mActivityDisplays.valueAt(displayNdx); |
| 4468 | for (int stackNdx = display.getChildCount() - 1; stackNdx >= 0; --stackNdx) { |
| 4469 | final ActivityStack stack = display.getChildAt(stackNdx); |
| 4470 | list.add(getStackInfo(stack)); |
Craig Mautner | 4a1cb22 | 2013-12-04 16:14:06 -0800 | [diff] [blame] | 4471 | } |
| 4472 | } |
| 4473 | return list; |
| 4474 | } |
| 4475 | |
Wale Ogunwale | 0568aed | 2017-09-08 13:29:37 -0700 | [diff] [blame] | 4476 | void handleNonResizableTaskIfNeeded(TaskRecord task, int preferredWindowingMode, |
Wale Ogunwale | a0f5b5e | 2017-10-11 09:37:23 -0700 | [diff] [blame] | 4477 | int preferredDisplayId, ActivityStack actualStack) { |
Wale Ogunwale | 0568aed | 2017-09-08 13:29:37 -0700 | [diff] [blame] | 4478 | handleNonResizableTaskIfNeeded(task, preferredWindowingMode, preferredDisplayId, |
Wale Ogunwale | a0f5b5e | 2017-10-11 09:37:23 -0700 | [diff] [blame] | 4479 | actualStack, false /* forceNonResizable */); |
Andrii Kulian | c2791664 | 2016-04-12 17:59:27 -0700 | [diff] [blame] | 4480 | } |
| 4481 | |
Wale Ogunwale | 0568aed | 2017-09-08 13:29:37 -0700 | [diff] [blame] | 4482 | void handleNonResizableTaskIfNeeded(TaskRecord task, int preferredWindowingMode, |
Wale Ogunwale | a0f5b5e | 2017-10-11 09:37:23 -0700 | [diff] [blame] | 4483 | int preferredDisplayId, ActivityStack actualStack, boolean forceNonResizable) { |
Andrii Kulian | 036e3ad | 2017-04-19 10:55:10 -0700 | [diff] [blame] | 4484 | final boolean isSecondaryDisplayPreferred = |
Wale Ogunwale | 0568aed | 2017-09-08 13:29:37 -0700 | [diff] [blame] | 4485 | (preferredDisplayId != DEFAULT_DISPLAY && preferredDisplayId != INVALID_DISPLAY); |
Wale Ogunwale | 926aade | 2017-08-29 11:24:37 -0700 | [diff] [blame] | 4486 | final boolean inSplitScreenMode = actualStack != null |
Wale Ogunwale | 7e1f5f5 | 2017-10-18 15:19:59 -0700 | [diff] [blame] | 4487 | && actualStack.getDisplay().hasSplitScreenPrimaryStack(); |
Wale Ogunwale | 0568aed | 2017-09-08 13:29:37 -0700 | [diff] [blame] | 4488 | if (((!inSplitScreenMode && preferredWindowingMode != WINDOWING_MODE_SPLIT_SCREEN_PRIMARY) |
Wale Ogunwale | 7e1f5f5 | 2017-10-18 15:19:59 -0700 | [diff] [blame] | 4489 | && !isSecondaryDisplayPreferred) || !task.isActivityTypeStandardOrUndefined()) { |
Wale Ogunwale | b9b16a7 | 2016-01-27 12:24:44 -0800 | [diff] [blame] | 4490 | return; |
| 4491 | } |
| 4492 | |
Andrii Kulian | 036e3ad | 2017-04-19 10:55:10 -0700 | [diff] [blame] | 4493 | // Handle incorrect launch/move to secondary display if needed. |
Andrii Kulian | 036e3ad | 2017-04-19 10:55:10 -0700 | [diff] [blame] | 4494 | if (isSecondaryDisplayPreferred) { |
| 4495 | final int actualDisplayId = task.getStack().mDisplayId; |
| 4496 | if (!task.canBeLaunchedOnDisplay(actualDisplayId)) { |
Andrii Kulian | b850ea5 | 2017-12-12 23:49:10 -0800 | [diff] [blame] | 4497 | throw new IllegalStateException("Task resolved to incompatible display"); |
Andrii Kulian | 036e3ad | 2017-04-19 10:55:10 -0700 | [diff] [blame] | 4498 | } |
Andrii Kulian | b850ea5 | 2017-12-12 23:49:10 -0800 | [diff] [blame] | 4499 | // The task might have landed on a display different from requested. |
| 4500 | // TODO(multi-display): Find proper stack for the task on the default display. |
| 4501 | mService.setTaskWindowingMode(task.taskId, |
| 4502 | WINDOWING_MODE_FULLSCREEN_OR_SPLIT_SCREEN_SECONDARY, true /* toTop */); |
| 4503 | if (preferredDisplayId != actualDisplayId) { |
Andrii Kulian | 036e3ad | 2017-04-19 10:55:10 -0700 | [diff] [blame] | 4504 | // Display a warning toast that we tried to put a non-resizeable task on a secondary |
| 4505 | // display with config different from global config. |
| 4506 | mService.mTaskChangeNotificationController |
| 4507 | .notifyActivityLaunchOnSecondaryDisplayFailed(); |
Wale Ogunwale | 2b07da8 | 2017-11-08 14:52:40 -0800 | [diff] [blame] | 4508 | return; |
Andrii Kulian | 036e3ad | 2017-04-19 10:55:10 -0700 | [diff] [blame] | 4509 | } |
Wale Ogunwale | 2b07da8 | 2017-11-08 14:52:40 -0800 | [diff] [blame] | 4510 | } |
| 4511 | |
Wale Ogunwale | 2b07da8 | 2017-11-08 14:52:40 -0800 | [diff] [blame] | 4512 | if (!task.supportsSplitScreenWindowingMode() || forceNonResizable) { |
Wale Ogunwale | 30e441d | 2017-11-09 08:28:45 -0800 | [diff] [blame] | 4513 | // Display a warning toast that we tried to put an app that doesn't support split-screen |
| 4514 | // in split-screen. |
Wale Ogunwale | 2b07da8 | 2017-11-08 14:52:40 -0800 | [diff] [blame] | 4515 | mService.mTaskChangeNotificationController.notifyActivityDismissingDockedStack(); |
Jorim Jaggi | d53f092 | 2016-04-06 22:16:23 -0700 | [diff] [blame] | 4516 | |
Andrii Kulian | c2791664 | 2016-04-12 17:59:27 -0700 | [diff] [blame] | 4517 | // Dismiss docked stack. If task appeared to be in docked stack but is not resizable - |
| 4518 | // 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] | 4519 | |
Wale Ogunwale | 2b07da8 | 2017-11-08 14:52:40 -0800 | [diff] [blame] | 4520 | final ActivityStack dockedStack = |
| 4521 | task.getStack().getDisplay().getSplitScreenPrimaryStack(); |
Wale Ogunwale | 9dcf946 | 2017-09-19 15:13:01 -0700 | [diff] [blame] | 4522 | if (dockedStack != null) { |
Wale Ogunwale | a0f5b5e | 2017-10-11 09:37:23 -0700 | [diff] [blame] | 4523 | moveTasksToFullscreenStackLocked(dockedStack, actualStack == dockedStack); |
Wale Ogunwale | 9dcf946 | 2017-09-19 15:13:01 -0700 | [diff] [blame] | 4524 | } |
Wale Ogunwale | 2b07da8 | 2017-11-08 14:52:40 -0800 | [diff] [blame] | 4525 | return; |
| 4526 | } |
| 4527 | |
Wale Ogunwale | 30e441d | 2017-11-09 08:28:45 -0800 | [diff] [blame] | 4528 | final ActivityRecord topActivity = task.getTopActivity(); |
Wale Ogunwale | 2b07da8 | 2017-11-08 14:52:40 -0800 | [diff] [blame] | 4529 | if (topActivity != null && topActivity.isNonResizableOrForcedResizable() |
| 4530 | && !topActivity.noDisplay) { |
Andrii Kulian | 036e3ad | 2017-04-19 10:55:10 -0700 | [diff] [blame] | 4531 | final String packageName = topActivity.appInfo.packageName; |
| 4532 | final int reason = isSecondaryDisplayPreferred |
| 4533 | ? FORCED_RESIZEABLE_REASON_SECONDARY_DISPLAY |
| 4534 | : FORCED_RESIZEABLE_REASON_SPLIT_SCREEN; |
Yorke Lee | bd54c2a | 2016-10-25 13:49:23 -0700 | [diff] [blame] | 4535 | mService.mTaskChangeNotificationController.notifyActivityForcedResizable( |
Andrii Kulian | 036e3ad | 2017-04-19 10:55:10 -0700 | [diff] [blame] | 4536 | task.taskId, reason, packageName); |
Wale Ogunwale | b9b16a7 | 2016-01-27 12:24:44 -0800 | [diff] [blame] | 4537 | } |
Chong Zhang | b15758a | 2015-11-17 12:12:03 -0800 | [diff] [blame] | 4538 | } |
| 4539 | |
Jorim Jaggi | fe89d12 | 2015-12-22 16:28:44 +0100 | [diff] [blame] | 4540 | void activityRelaunchedLocked(IBinder token) { |
| 4541 | mWindowManager.notifyAppRelaunchingFinished(token); |
David Stevens | 9440dc8 | 2017-03-16 19:00:20 -0700 | [diff] [blame] | 4542 | final ActivityRecord r = ActivityRecord.isInStackLocked(token); |
| 4543 | if (r != null) { |
| 4544 | if (r.getStack().shouldSleepOrShutDownActivities()) { |
Wale Ogunwale | 3e99736 | 2016-09-06 10:37:56 -0700 | [diff] [blame] | 4545 | r.setSleeping(true, true); |
| 4546 | } |
| 4547 | } |
Jorim Jaggi | fe89d12 | 2015-12-22 16:28:44 +0100 | [diff] [blame] | 4548 | } |
| 4549 | |
| 4550 | void activityRelaunchingLocked(ActivityRecord r) { |
| 4551 | mWindowManager.notifyAppRelaunching(r.appToken); |
| 4552 | } |
| 4553 | |
Filip Gruszczynski | 77d9448 | 2015-12-11 13:59:52 -0800 | [diff] [blame] | 4554 | void logStackState() { |
| 4555 | mActivityMetricsLogger.logWindowState(); |
| 4556 | } |
| 4557 | |
Winson Chung | 5af42fc | 2017-03-24 17:11:33 -0700 | [diff] [blame] | 4558 | void scheduleUpdateMultiWindowMode(TaskRecord task) { |
Winson Chung | 8bca9e4 | 2017-04-16 15:59:43 -0700 | [diff] [blame] | 4559 | // If the stack is animating in a way where we will be forcing a multi-mode change at the |
| 4560 | // end, then ensure that we defer all in between multi-window mode changes |
| 4561 | if (task.getStack().deferScheduleMultiWindowModeChanged()) { |
| 4562 | return; |
| 4563 | } |
| 4564 | |
Wale Ogunwale | 22e2526 | 2016-02-01 10:32:02 -0800 | [diff] [blame] | 4565 | for (int i = task.mActivities.size() - 1; i >= 0; i--) { |
| 4566 | final ActivityRecord r = task.mActivities.get(i); |
| 4567 | if (r.app != null && r.app.thread != null) { |
| 4568 | mMultiWindowModeChangedActivities.add(r); |
| 4569 | } |
| 4570 | } |
| 4571 | |
| 4572 | if (!mHandler.hasMessages(REPORT_MULTI_WINDOW_MODE_CHANGED_MSG)) { |
| 4573 | mHandler.sendEmptyMessage(REPORT_MULTI_WINDOW_MODE_CHANGED_MSG); |
| 4574 | } |
| 4575 | } |
| 4576 | |
Winson Chung | 5af42fc | 2017-03-24 17:11:33 -0700 | [diff] [blame] | 4577 | void scheduleUpdatePictureInPictureModeIfNeeded(TaskRecord task, ActivityStack prevStack) { |
Andrii Kulian | 02b7a83 | 2016-10-06 23:11:56 -0700 | [diff] [blame] | 4578 | final ActivityStack stack = task.getStack(); |
Wale Ogunwale | 22e2526 | 2016-02-01 10:32:02 -0800 | [diff] [blame] | 4579 | if (prevStack == null || prevStack == stack |
Wale Ogunwale | 44f036f | 2017-09-29 05:09:09 -0700 | [diff] [blame] | 4580 | || (!prevStack.inPinnedWindowingMode() && !stack.inPinnedWindowingMode())) { |
Wale Ogunwale | 22e2526 | 2016-02-01 10:32:02 -0800 | [diff] [blame] | 4581 | return; |
| 4582 | } |
| 4583 | |
Bryce Lee | f3c6a47 | 2017-11-14 14:53:06 -0800 | [diff] [blame] | 4584 | scheduleUpdatePictureInPictureModeIfNeeded(task, stack.getOverrideBounds()); |
Winson Chung | 5af42fc | 2017-03-24 17:11:33 -0700 | [diff] [blame] | 4585 | } |
Wale Ogunwale | 22e2526 | 2016-02-01 10:32:02 -0800 | [diff] [blame] | 4586 | |
Winson Chung | ab76bbc | 2017-08-14 13:33:51 -0700 | [diff] [blame] | 4587 | void scheduleUpdatePictureInPictureModeIfNeeded(TaskRecord task, Rect targetStackBounds) { |
| 4588 | for (int i = task.mActivities.size() - 1; i >= 0; i--) { |
| 4589 | final ActivityRecord r = task.mActivities.get(i); |
| 4590 | if (r.app != null && r.app.thread != null) { |
| 4591 | mPipModeChangedActivities.add(r); |
Wale Ogunwale | eb76b76 | 2017-11-17 10:08:04 -0800 | [diff] [blame] | 4592 | // If we are scheduling pip change, then remove this activity from multi-window |
| 4593 | // change list as the processing of pip change will make sure multi-window changed |
| 4594 | // message is processed in the right order relative to pip changed. |
| 4595 | mMultiWindowModeChangedActivities.remove(r); |
Winson Chung | 5af42fc | 2017-03-24 17:11:33 -0700 | [diff] [blame] | 4596 | } |
Winson Chung | ab76bbc | 2017-08-14 13:33:51 -0700 | [diff] [blame] | 4597 | } |
| 4598 | mPipModeChangedTargetStackBounds = targetStackBounds; |
Winson Chung | 5af42fc | 2017-03-24 17:11:33 -0700 | [diff] [blame] | 4599 | |
Winson Chung | ab76bbc | 2017-08-14 13:33:51 -0700 | [diff] [blame] | 4600 | if (!mHandler.hasMessages(REPORT_PIP_MODE_CHANGED_MSG)) { |
| 4601 | mHandler.sendEmptyMessage(REPORT_PIP_MODE_CHANGED_MSG); |
| 4602 | } |
| 4603 | } |
| 4604 | |
| 4605 | void updatePictureInPictureMode(TaskRecord task, Rect targetStackBounds, boolean forceUpdate) { |
| 4606 | mHandler.removeMessages(REPORT_PIP_MODE_CHANGED_MSG); |
| 4607 | for (int i = task.mActivities.size() - 1; i >= 0; i--) { |
| 4608 | final ActivityRecord r = task.mActivities.get(i); |
| 4609 | if (r.app != null && r.app.thread != null) { |
| 4610 | r.updatePictureInPictureMode(targetStackBounds, forceUpdate); |
Winson Chung | 5af42fc | 2017-03-24 17:11:33 -0700 | [diff] [blame] | 4611 | } |
Wale Ogunwale | 22e2526 | 2016-02-01 10:32:02 -0800 | [diff] [blame] | 4612 | } |
| 4613 | } |
| 4614 | |
Tony Mak | 853304c | 2016-04-18 15:17:41 +0100 | [diff] [blame] | 4615 | void setDockedStackMinimized(boolean minimized) { |
| 4616 | mIsDockMinimized = minimized; |
Wale Ogunwale | 17696de | 2018-03-15 16:41:05 -0700 | [diff] [blame] | 4617 | if (mIsDockMinimized) { |
| 4618 | final ActivityStack current = getFocusedStack(); |
| 4619 | if (current.inSplitScreenPrimaryWindowingMode()) { |
| 4620 | // The primary split-screen stack can't be focused while it is minimize, so move |
| 4621 | // focus to something else. |
| 4622 | current.adjustFocusToNextFocusableStack("setDockedStackMinimized"); |
| 4623 | } |
| 4624 | } |
Tony Mak | 853304c | 2016-04-18 15:17:41 +0100 | [diff] [blame] | 4625 | } |
| 4626 | |
chaviw | 59b9885 | 2017-06-13 12:05:44 -0700 | [diff] [blame] | 4627 | void wakeUp(String reason) { |
| 4628 | mPowerManager.wakeUp(SystemClock.uptimeMillis(), "android.server.am:TURN_ON:" + reason); |
| 4629 | } |
| 4630 | |
| 4631 | /** |
| 4632 | * Begin deferring resume to avoid duplicate resumes in one pass. |
| 4633 | */ |
| 4634 | private void beginDeferResume() { |
| 4635 | mDeferResumeCount++; |
| 4636 | } |
| 4637 | |
| 4638 | /** |
| 4639 | * End deferring resume and determine if resume can be called. |
| 4640 | */ |
| 4641 | private void endDeferResume() { |
| 4642 | mDeferResumeCount--; |
| 4643 | } |
| 4644 | |
| 4645 | /** |
| 4646 | * @return True if resume can be called. |
| 4647 | */ |
| 4648 | private boolean readyToResume() { |
| 4649 | return mDeferResumeCount == 0; |
| 4650 | } |
| 4651 | |
Craig Mautner | ce5f3cb | 2013-04-22 08:58:54 -0700 | [diff] [blame] | 4652 | private final class ActivityStackSupervisorHandler extends Handler { |
Craig Mautner | f333327 | 2013-04-22 10:55:53 -0700 | [diff] [blame] | 4653 | |
Craig Mautner | ce5f3cb | 2013-04-22 08:58:54 -0700 | [diff] [blame] | 4654 | public ActivityStackSupervisorHandler(Looper looper) { |
| 4655 | super(looper); |
| 4656 | } |
| 4657 | |
Winson Chung | 4dabf23 | 2017-01-25 13:25:22 -0800 | [diff] [blame] | 4658 | void activityIdleInternal(ActivityRecord r, boolean processPausingActivities) { |
Craig Mautner | f333327 | 2013-04-22 10:55:53 -0700 | [diff] [blame] | 4659 | synchronized (mService) { |
Winson Chung | 4dabf23 | 2017-01-25 13:25:22 -0800 | [diff] [blame] | 4660 | activityIdleInternalLocked(r != null ? r.appToken : null, true /* fromTimeout */, |
| 4661 | processPausingActivities, null); |
Craig Mautner | f333327 | 2013-04-22 10:55:53 -0700 | [diff] [blame] | 4662 | } |
Craig Mautner | 7ea5bd4 | 2013-07-05 15:27:08 -0700 | [diff] [blame] | 4663 | } |
| 4664 | |
Craig Mautner | ce5f3cb | 2013-04-22 08:58:54 -0700 | [diff] [blame] | 4665 | @Override |
| 4666 | public void handleMessage(Message msg) { |
| 4667 | switch (msg.what) { |
Wale Ogunwale | 22e2526 | 2016-02-01 10:32:02 -0800 | [diff] [blame] | 4668 | case REPORT_MULTI_WINDOW_MODE_CHANGED_MSG: { |
| 4669 | synchronized (mService) { |
| 4670 | for (int i = mMultiWindowModeChangedActivities.size() - 1; i >= 0; i--) { |
| 4671 | final ActivityRecord r = mMultiWindowModeChangedActivities.remove(i); |
Winson Chung | 5af42fc | 2017-03-24 17:11:33 -0700 | [diff] [blame] | 4672 | r.updateMultiWindowMode(); |
Wale Ogunwale | 22e2526 | 2016-02-01 10:32:02 -0800 | [diff] [blame] | 4673 | } |
| 4674 | } |
| 4675 | } break; |
| 4676 | case REPORT_PIP_MODE_CHANGED_MSG: { |
| 4677 | synchronized (mService) { |
| 4678 | for (int i = mPipModeChangedActivities.size() - 1; i >= 0; i--) { |
| 4679 | final ActivityRecord r = mPipModeChangedActivities.remove(i); |
Winson Chung | ab76bbc | 2017-08-14 13:33:51 -0700 | [diff] [blame] | 4680 | r.updatePictureInPictureMode(mPipModeChangedTargetStackBounds, |
| 4681 | false /* forceUpdate */); |
Wale Ogunwale | 22e2526 | 2016-02-01 10:32:02 -0800 | [diff] [blame] | 4682 | } |
| 4683 | } |
| 4684 | } break; |
Craig Mautner | f333327 | 2013-04-22 10:55:53 -0700 | [diff] [blame] | 4685 | case IDLE_TIMEOUT_MSG: { |
Wale Ogunwale | 0fc365c | 2015-05-25 19:35:42 -0700 | [diff] [blame] | 4686 | if (DEBUG_IDLE) Slog.d(TAG_IDLE, |
| 4687 | "handleMessage: IDLE_TIMEOUT_MSG: r=" + msg.obj); |
Craig Mautner | f333327 | 2013-04-22 10:55:53 -0700 | [diff] [blame] | 4688 | // We don't at this point know if the activity is fullscreen, |
| 4689 | // so we need to be conservative and assume it isn't. |
Winson Chung | 4dabf23 | 2017-01-25 13:25:22 -0800 | [diff] [blame] | 4690 | activityIdleInternal((ActivityRecord) msg.obj, |
| 4691 | true /* processPausingActivities */); |
Craig Mautner | f333327 | 2013-04-22 10:55:53 -0700 | [diff] [blame] | 4692 | } break; |
| 4693 | case IDLE_NOW_MSG: { |
Wale Ogunwale | 0fc365c | 2015-05-25 19:35:42 -0700 | [diff] [blame] | 4694 | 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] | 4695 | activityIdleInternal((ActivityRecord) msg.obj, |
| 4696 | false /* processPausingActivities */); |
Craig Mautner | f333327 | 2013-04-22 10:55:53 -0700 | [diff] [blame] | 4697 | } break; |
Craig Mautner | 05d2903 | 2013-05-03 13:40:13 -0700 | [diff] [blame] | 4698 | case RESUME_TOP_ACTIVITY_MSG: { |
| 4699 | synchronized (mService) { |
Wale Ogunwale | d046a01 | 2015-12-24 13:05:59 -0800 | [diff] [blame] | 4700 | resumeFocusedStackTopActivityLocked(); |
Craig Mautner | 05d2903 | 2013-05-03 13:40:13 -0700 | [diff] [blame] | 4701 | } |
| 4702 | } break; |
Craig Mautner | 0eea92c | 2013-05-16 13:35:39 -0700 | [diff] [blame] | 4703 | case SLEEP_TIMEOUT_MSG: { |
| 4704 | synchronized (mService) { |
Fyodor Kupolov | 9b80b94 | 2016-06-16 16:29:05 -0700 | [diff] [blame] | 4705 | if (mService.isSleepingOrShuttingDownLocked()) { |
Craig Mautner | 0eea92c | 2013-05-16 13:35:39 -0700 | [diff] [blame] | 4706 | Slog.w(TAG, "Sleep timeout! Sleeping now."); |
David Stevens | 9440dc8 | 2017-03-16 19:00:20 -0700 | [diff] [blame] | 4707 | checkReadyForSleepLocked(false /* allowDelay */); |
Craig Mautner | 0eea92c | 2013-05-16 13:35:39 -0700 | [diff] [blame] | 4708 | } |
| 4709 | } |
| 4710 | } break; |
Craig Mautner | 7ea5bd4 | 2013-07-05 15:27:08 -0700 | [diff] [blame] | 4711 | case LAUNCH_TIMEOUT_MSG: { |
Craig Mautner | 7ea5bd4 | 2013-07-05 15:27:08 -0700 | [diff] [blame] | 4712 | synchronized (mService) { |
| 4713 | if (mLaunchingActivity.isHeld()) { |
| 4714 | Slog.w(TAG, "Launch timeout has expired, giving up wake lock!"); |
| 4715 | if (VALIDATE_WAKE_LOCK_CALLER |
| 4716 | && Binder.getCallingUid() != Process.myUid()) { |
| 4717 | throw new IllegalStateException("Calling must be system uid"); |
| 4718 | } |
| 4719 | mLaunchingActivity.release(); |
| 4720 | } |
| 4721 | } |
| 4722 | } break; |
Craig Mautner | 4a1cb22 | 2013-12-04 16:14:06 -0800 | [diff] [blame] | 4723 | case HANDLE_DISPLAY_ADDED: { |
Wale Ogunwale | f16a281 | 2015-04-01 11:23:15 -0700 | [diff] [blame] | 4724 | handleDisplayAdded(msg.arg1); |
Craig Mautner | 4a1cb22 | 2013-12-04 16:14:06 -0800 | [diff] [blame] | 4725 | } break; |
| 4726 | case HANDLE_DISPLAY_CHANGED: { |
Wale Ogunwale | f16a281 | 2015-04-01 11:23:15 -0700 | [diff] [blame] | 4727 | handleDisplayChanged(msg.arg1); |
Craig Mautner | 4a1cb22 | 2013-12-04 16:14:06 -0800 | [diff] [blame] | 4728 | } break; |
| 4729 | case HANDLE_DISPLAY_REMOVED: { |
Wale Ogunwale | f16a281 | 2015-04-01 11:23:15 -0700 | [diff] [blame] | 4730 | handleDisplayRemoved(msg.arg1); |
Craig Mautner | 4a1cb22 | 2013-12-04 16:14:06 -0800 | [diff] [blame] | 4731 | } break; |
Craig Mautner | bb74246 | 2014-07-07 15:28:55 -0700 | [diff] [blame] | 4732 | case LAUNCH_TASK_BEHIND_COMPLETE: { |
| 4733 | synchronized (mService) { |
Wale Ogunwale | 7d70117 | 2015-03-11 15:36:30 -0700 | [diff] [blame] | 4734 | ActivityRecord r = ActivityRecord.forTokenLocked((IBinder) msg.obj); |
Craig Mautner | bb74246 | 2014-07-07 15:28:55 -0700 | [diff] [blame] | 4735 | if (r != null) { |
| 4736 | handleLaunchTaskBehindCompleteLocked(r); |
| 4737 | } |
| 4738 | } |
| 4739 | } break; |
Chong Zhang | c806d90 | 2015-11-30 09:44:27 -0800 | [diff] [blame] | 4740 | |
Craig Mautner | ce5f3cb | 2013-04-22 08:58:54 -0700 | [diff] [blame] | 4741 | } |
| 4742 | } |
| 4743 | } |
Craig Mautner | ed6649f | 2013-12-02 14:08:25 -0800 | [diff] [blame] | 4744 | |
Filip Gruszczynski | caae14e | 2015-12-16 14:40:04 -0800 | [diff] [blame] | 4745 | ActivityStack findStackBehind(ActivityStack stack) { |
| 4746 | // 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] | 4747 | final ActivityDisplay display = mActivityDisplays.get(DEFAULT_DISPLAY); |
Filip Gruszczynski | caae14e | 2015-12-16 14:40:04 -0800 | [diff] [blame] | 4748 | if (display == null) { |
| 4749 | return null; |
| 4750 | } |
Wale Ogunwale | a0f5b5e | 2017-10-11 09:37:23 -0700 | [diff] [blame] | 4751 | for (int i = display.getChildCount() - 1; i >= 0; i--) { |
| 4752 | if (display.getChildAt(i) == stack && i > 0) { |
| 4753 | return display.getChildAt(i - 1); |
Filip Gruszczynski | caae14e | 2015-12-16 14:40:04 -0800 | [diff] [blame] | 4754 | } |
| 4755 | } |
| 4756 | throw new IllegalStateException("Failed to find a stack behind stack=" + stack |
Wale Ogunwale | a0f5b5e | 2017-10-11 09:37:23 -0700 | [diff] [blame] | 4757 | + " in=" + display); |
Filip Gruszczynski | caae14e | 2015-12-16 14:40:04 -0800 | [diff] [blame] | 4758 | } |
Jorim Jaggi | 0b46f3c | 2016-03-14 12:21:37 +0100 | [diff] [blame] | 4759 | |
Jorim Jaggi | c69bd22 | 2016-03-15 14:38:37 +0100 | [diff] [blame] | 4760 | /** |
| 4761 | * Puts a task into resizing mode during the next app transition. |
| 4762 | * |
Wale Ogunwale | e1fe7fa2 | 2016-12-15 18:27:00 -0800 | [diff] [blame] | 4763 | * @param task The task to put into resizing mode |
Jorim Jaggi | c69bd22 | 2016-03-15 14:38:37 +0100 | [diff] [blame] | 4764 | */ |
Bryce Lee | d3624e1 | 2017-11-30 08:51:45 -0800 | [diff] [blame] | 4765 | void setResizingDuringAnimation(TaskRecord task) { |
Wale Ogunwale | e1fe7fa2 | 2016-12-15 18:27:00 -0800 | [diff] [blame] | 4766 | mResizingTasksDuringAnimation.add(task.taskId); |
| 4767 | task.setTaskDockedResizing(true); |
Jorim Jaggi | c69bd22 | 2016-03-15 14:38:37 +0100 | [diff] [blame] | 4768 | } |
| 4769 | |
Jorim Jaggi | 4d8d32c | 2018-01-19 15:57:41 +0100 | [diff] [blame] | 4770 | int startActivityFromRecents(int callingPid, int callingUid, int taskId, |
| 4771 | SafeActivityOptions options) { |
Wale Ogunwale | dd2ae3d | 2018-02-15 13:58:46 -0800 | [diff] [blame] | 4772 | TaskRecord task = null; |
Jorim Jaggi | 0b46f3c | 2016-03-14 12:21:37 +0100 | [diff] [blame] | 4773 | final String callingPackage; |
| 4774 | final Intent intent; |
| 4775 | final int userId; |
Wale Ogunwale | 0568aed | 2017-09-08 13:29:37 -0700 | [diff] [blame] | 4776 | int activityType = ACTIVITY_TYPE_UNDEFINED; |
| 4777 | int windowingMode = WINDOWING_MODE_UNDEFINED; |
Jorim Jaggi | 4d8d32c | 2018-01-19 15:57:41 +0100 | [diff] [blame] | 4778 | final ActivityOptions activityOptions = options != null |
| 4779 | ? options.getOptions(this) |
| 4780 | : null; |
Wale Ogunwale | 0568aed | 2017-09-08 13:29:37 -0700 | [diff] [blame] | 4781 | if (activityOptions != null) { |
| 4782 | activityType = activityOptions.getLaunchActivityType(); |
| 4783 | windowingMode = activityOptions.getLaunchWindowingMode(); |
| 4784 | } |
| 4785 | if (activityType == ACTIVITY_TYPE_HOME || activityType == ACTIVITY_TYPE_RECENTS) { |
Wale Ogunwale | ab5de37 | 2017-10-18 06:46:31 -0700 | [diff] [blame] | 4786 | throw new IllegalArgumentException("startActivityFromRecents: Task " |
Matthew Ng | ae1ff4f | 2016-11-10 15:49:14 -0800 | [diff] [blame] | 4787 | + taskId + " can't be launch in the home/recents stack."); |
Jorim Jaggi | 0b46f3c | 2016-03-14 12:21:37 +0100 | [diff] [blame] | 4788 | } |
Jorim Jaggi | 3c800a4 | 2016-04-15 19:44:50 -0700 | [diff] [blame] | 4789 | |
Matthew Ng | 606dd80 | 2017-06-05 14:06:32 -0700 | [diff] [blame] | 4790 | mWindowManager.deferSurfaceLayout(); |
| 4791 | try { |
Wale Ogunwale | 0568aed | 2017-09-08 13:29:37 -0700 | [diff] [blame] | 4792 | if (windowingMode == WINDOWING_MODE_SPLIT_SCREEN_PRIMARY) { |
Matthew Ng | 606dd80 | 2017-06-05 14:06:32 -0700 | [diff] [blame] | 4793 | mWindowManager.setDockedStackCreateState( |
Matthew Ng | bf15587 | 2017-10-27 15:24:39 -0700 | [diff] [blame] | 4794 | activityOptions.getSplitScreenCreateMode(), null /* initialBounds */); |
Jorim Jaggi | 3c800a4 | 2016-04-15 19:44:50 -0700 | [diff] [blame] | 4795 | |
Matthew Ng | 606dd80 | 2017-06-05 14:06:32 -0700 | [diff] [blame] | 4796 | // Defer updating the stack in which recents is until the app transition is done, to |
| 4797 | // not run into issues where we still need to draw the task in recents but the |
| 4798 | // docked stack is already created. |
Winson Chung | c167427 | 2018-02-21 10:15:17 -0800 | [diff] [blame] | 4799 | deferUpdateRecentsHomeStackBounds(); |
Matthew Ng | 606dd80 | 2017-06-05 14:06:32 -0700 | [diff] [blame] | 4800 | mWindowManager.prepareAppTransition(TRANSIT_DOCK_TASK_FROM_RECENTS, false); |
Jorim Jaggi | 0b46f3c | 2016-03-14 12:21:37 +0100 | [diff] [blame] | 4801 | } |
Jorim Jaggi | 0b46f3c | 2016-03-14 12:21:37 +0100 | [diff] [blame] | 4802 | |
Matthew Ng | 606dd80 | 2017-06-05 14:06:32 -0700 | [diff] [blame] | 4803 | task = anyTaskForIdLocked(taskId, MATCH_TASK_IN_STACKS_OR_RECENT_TASKS_AND_RESTORE, |
Wale Ogunwale | ab5de37 | 2017-10-18 06:46:31 -0700 | [diff] [blame] | 4804 | activityOptions, ON_TOP); |
Matthew Ng | 606dd80 | 2017-06-05 14:06:32 -0700 | [diff] [blame] | 4805 | if (task == null) { |
Winson Chung | c167427 | 2018-02-21 10:15:17 -0800 | [diff] [blame] | 4806 | continueUpdateRecentsHomeStackBounds(); |
Matthew Ng | 606dd80 | 2017-06-05 14:06:32 -0700 | [diff] [blame] | 4807 | mWindowManager.executeAppTransition(); |
| 4808 | throw new IllegalArgumentException( |
Wale Ogunwale | ab5de37 | 2017-10-18 06:46:31 -0700 | [diff] [blame] | 4809 | "startActivityFromRecents: Task " + taskId + " not found."); |
Matthew Ng | 606dd80 | 2017-06-05 14:06:32 -0700 | [diff] [blame] | 4810 | } |
| 4811 | |
Wale Ogunwale | abc44d0 | 2017-11-08 08:58:03 -0800 | [diff] [blame] | 4812 | if (windowingMode != WINDOWING_MODE_SPLIT_SCREEN_PRIMARY) { |
| 4813 | // We always want to return to the home activity instead of the recents activity |
| 4814 | // from whatever is started from the recents activity, so move the home stack |
| 4815 | // forward. |
| 4816 | moveHomeStackToFront("startActivityFromRecents"); |
| 4817 | } |
Wale Ogunwale | 66e1685 | 2017-10-19 13:35:52 -0700 | [diff] [blame] | 4818 | |
Matthew Ng | 606dd80 | 2017-06-05 14:06:32 -0700 | [diff] [blame] | 4819 | // If the user must confirm credentials (e.g. when first launching a work app and the |
| 4820 | // Work Challenge is present) let startActivityInPackage handle the intercepting. |
| 4821 | if (!mService.mUserController.shouldConfirmCredentials(task.userId) |
| 4822 | && task.getRootActivity() != null) { |
Bryce Lee | 28d8042 | 2017-07-21 13:25:13 -0700 | [diff] [blame] | 4823 | final ActivityRecord targetActivity = task.getTopActivity(); |
| 4824 | |
Bryce Lee | d3624e1 | 2017-11-30 08:51:45 -0800 | [diff] [blame] | 4825 | sendPowerHintForLaunchStartIfNeeded(true /* forceSend */, targetActivity); |
Matthew Ng | 606dd80 | 2017-06-05 14:06:32 -0700 | [diff] [blame] | 4826 | mActivityMetricsLogger.notifyActivityLaunching(); |
Jorim Jaggi | 172e99f | 2017-10-20 14:33:18 +0200 | [diff] [blame] | 4827 | try { |
Jorim Jaggi | 4d8d32c | 2018-01-19 15:57:41 +0100 | [diff] [blame] | 4828 | mService.moveTaskToFrontLocked(task.taskId, 0, options, |
Jorim Jaggi | 172e99f | 2017-10-20 14:33:18 +0200 | [diff] [blame] | 4829 | true /* fromRecents */); |
| 4830 | } finally { |
| 4831 | mActivityMetricsLogger.notifyActivityLaunched(START_TASK_TO_FRONT, |
| 4832 | targetActivity); |
| 4833 | } |
Matthew Ng | 606dd80 | 2017-06-05 14:06:32 -0700 | [diff] [blame] | 4834 | |
Bryce Lee | d3624e1 | 2017-11-30 08:51:45 -0800 | [diff] [blame] | 4835 | mService.getActivityStartController().postStartActivityProcessingForLastStarter( |
| 4836 | task.getTopActivity(), ActivityManager.START_TASK_TO_FRONT, |
| 4837 | task.getStack()); |
Matthew Ng | 606dd80 | 2017-06-05 14:06:32 -0700 | [diff] [blame] | 4838 | return ActivityManager.START_TASK_TO_FRONT; |
| 4839 | } |
Matthew Ng | 606dd80 | 2017-06-05 14:06:32 -0700 | [diff] [blame] | 4840 | callingPackage = task.mCallingPackage; |
| 4841 | intent = task.intent; |
| 4842 | intent.addFlags(Intent.FLAG_ACTIVITY_LAUNCHED_FROM_HISTORY); |
| 4843 | userId = task.userId; |
Wale Ogunwale | dd2ae3d | 2018-02-15 13:58:46 -0800 | [diff] [blame] | 4844 | return mService.getActivityStartController().startActivityInPackage( |
Jorim Jaggi | 4d8d32c | 2018-01-19 15:57:41 +0100 | [diff] [blame] | 4845 | task.mCallingUid, callingPid, callingUid, callingPackage, intent, null, null, |
Makoto Onuki | c00ea71 | 2018-04-13 12:06:39 -0700 | [diff] [blame] | 4846 | null, 0, 0, options, userId, task, "startActivityFromRecents", |
Michal Karpinski | 3eab951 | 2018-07-20 15:32:00 +0100 | [diff] [blame] | 4847 | false /* validateIncomingUser */, null /* originatingPendingIntent */); |
Matthew Ng | 606dd80 | 2017-06-05 14:06:32 -0700 | [diff] [blame] | 4848 | } finally { |
Wale Ogunwale | dd2ae3d | 2018-02-15 13:58:46 -0800 | [diff] [blame] | 4849 | if (windowingMode == WINDOWING_MODE_SPLIT_SCREEN_PRIMARY && task != null) { |
| 4850 | // If we are launching the task in the docked stack, put it into resizing mode so |
| 4851 | // the window renders full-screen with the background filling the void. Also only |
| 4852 | // call this at the end to make sure that tasks exists on the window manager side. |
| 4853 | setResizingDuringAnimation(task); |
| 4854 | |
| 4855 | final ActivityDisplay display = task.getStack().getDisplay(); |
| 4856 | final ActivityStack topSecondaryStack = |
| 4857 | display.getTopStackInWindowingMode(WINDOWING_MODE_SPLIT_SCREEN_SECONDARY); |
| 4858 | if (topSecondaryStack.isActivityTypeHome()) { |
| 4859 | // If the home activity if the top split-screen secondary stack, then the |
| 4860 | // primary split-screen stack is in the minimized mode which means it can't |
| 4861 | // receive input keys, so we should move the focused app to the home app so that |
| 4862 | // window manager can correctly calculate the focus window that can receive |
| 4863 | // input keys. |
| 4864 | moveHomeStackToFront("startActivityFromRecents: homeVisibleInSplitScreen"); |
Winson Chung | c167427 | 2018-02-21 10:15:17 -0800 | [diff] [blame] | 4865 | |
| 4866 | // Immediately update the minimized docked stack mode, the upcoming animation |
| 4867 | // for the docked activity (WMS.overridePendingAppTransitionMultiThumbFuture) |
| 4868 | // will do the animation to the target bounds |
| 4869 | mWindowManager.checkSplitScreenMinimizedChanged(false /* animate */); |
Wale Ogunwale | dd2ae3d | 2018-02-15 13:58:46 -0800 | [diff] [blame] | 4870 | } |
| 4871 | } |
Matthew Ng | 606dd80 | 2017-06-05 14:06:32 -0700 | [diff] [blame] | 4872 | mWindowManager.continueSurfaceLayout(); |
Jorim Jaggi | 0b46f3c | 2016-03-14 12:21:37 +0100 | [diff] [blame] | 4873 | } |
Jorim Jaggi | 0b46f3c | 2016-03-14 12:21:37 +0100 | [diff] [blame] | 4874 | } |
Amith Yamasani | e8222e5 | 2016-04-08 15:28:47 -0700 | [diff] [blame] | 4875 | |
| 4876 | /** |
| 4877 | * @return a list of activities which are the top ones in each visible stack. The first |
| 4878 | * entry will be the focused activity. |
| 4879 | */ |
Andrii Kulian | 0864bbb | 2017-02-16 15:45:58 -0800 | [diff] [blame] | 4880 | List<IBinder> getTopVisibleActivities() { |
| 4881 | final ArrayList<IBinder> topActivityTokens = new ArrayList<>(); |
| 4882 | // Traverse all displays. |
Robert Carr | 22374c0 | 2017-02-21 13:01:47 -0800 | [diff] [blame] | 4883 | for (int i = mActivityDisplays.size() - 1; i >= 0; i--) { |
Andrii Kulian | 0864bbb | 2017-02-16 15:45:58 -0800 | [diff] [blame] | 4884 | final ActivityDisplay display = mActivityDisplays.valueAt(i); |
| 4885 | // Traverse all stacks on a display. |
Wale Ogunwale | a0f5b5e | 2017-10-11 09:37:23 -0700 | [diff] [blame] | 4886 | for (int j = display.getChildCount() - 1; j >= 0; --j) { |
| 4887 | final ActivityStack stack = display.getChildAt(j); |
Andrii Kulian | 0864bbb | 2017-02-16 15:45:58 -0800 | [diff] [blame] | 4888 | // 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] | 4889 | if (stack.shouldBeVisible(null /* starting */)) { |
Wale Ogunwale | 30e441d | 2017-11-09 08:28:45 -0800 | [diff] [blame] | 4890 | final ActivityRecord top = stack.getTopActivity(); |
Andrii Kulian | 0864bbb | 2017-02-16 15:45:58 -0800 | [diff] [blame] | 4891 | if (top != null) { |
| 4892 | if (stack == mFocusedStack) { |
| 4893 | topActivityTokens.add(0, top.appToken); |
| 4894 | } else { |
| 4895 | topActivityTokens.add(top.appToken); |
| 4896 | } |
Amith Yamasani | e8222e5 | 2016-04-08 15:28:47 -0700 | [diff] [blame] | 4897 | } |
| 4898 | } |
| 4899 | } |
| 4900 | } |
| 4901 | return topActivityTokens; |
| 4902 | } |
Bryce Lee | 4a19438 | 2017-04-04 14:32:48 -0700 | [diff] [blame] | 4903 | |
| 4904 | /** |
| 4905 | * Internal container to store a match qualifier alongside a WaitResult. |
| 4906 | */ |
| 4907 | static class WaitInfo { |
| 4908 | private final ComponentName mTargetComponent; |
| 4909 | private final WaitResult mResult; |
Vishnu Nair | cf23504 | 2018-11-02 13:27:00 -0700 | [diff] [blame] | 4910 | /** Time stamp when we started to wait for {@link WaitResult}. */ |
| 4911 | private final long mStartTimeMs; |
Bryce Lee | 4a19438 | 2017-04-04 14:32:48 -0700 | [diff] [blame] | 4912 | |
Vishnu Nair | cf23504 | 2018-11-02 13:27:00 -0700 | [diff] [blame] | 4913 | WaitInfo(ComponentName targetComponent, WaitResult result, long startTimeMs) { |
Bryce Lee | 4a19438 | 2017-04-04 14:32:48 -0700 | [diff] [blame] | 4914 | this.mTargetComponent = targetComponent; |
| 4915 | this.mResult = result; |
Vishnu Nair | cf23504 | 2018-11-02 13:27:00 -0700 | [diff] [blame] | 4916 | this.mStartTimeMs = startTimeMs; |
Bryce Lee | 4a19438 | 2017-04-04 14:32:48 -0700 | [diff] [blame] | 4917 | } |
| 4918 | |
Wale Ogunwale | 3270f17 | 2017-04-26 07:29:42 -0700 | [diff] [blame] | 4919 | public boolean matches(ComponentName targetComponent) { |
| 4920 | return mTargetComponent == null || mTargetComponent.equals(targetComponent); |
Bryce Lee | 4a19438 | 2017-04-04 14:32:48 -0700 | [diff] [blame] | 4921 | } |
| 4922 | |
| 4923 | public WaitResult getResult() { |
| 4924 | return mResult; |
| 4925 | } |
| 4926 | |
Vishnu Nair | cf23504 | 2018-11-02 13:27:00 -0700 | [diff] [blame] | 4927 | public long getStartTime() { |
| 4928 | return mStartTimeMs; |
| 4929 | } |
| 4930 | |
Bryce Lee | 4a19438 | 2017-04-04 14:32:48 -0700 | [diff] [blame] | 4931 | public ComponentName getComponent() { |
| 4932 | return mTargetComponent; |
| 4933 | } |
| 4934 | |
| 4935 | public void dump(PrintWriter pw, String prefix) { |
| 4936 | pw.println(prefix + "WaitInfo:"); |
| 4937 | pw.println(prefix + " mTargetComponent=" + mTargetComponent); |
| 4938 | pw.println(prefix + " mResult="); |
| 4939 | mResult.dump(pw, prefix); |
| 4940 | } |
| 4941 | } |
David Stevens | 9440dc8 | 2017-03-16 19:00:20 -0700 | [diff] [blame] | 4942 | |
| 4943 | private final class SleepTokenImpl extends SleepToken { |
| 4944 | private final String mTag; |
| 4945 | private final long mAcquireTime; |
| 4946 | private final int mDisplayId; |
| 4947 | |
| 4948 | public SleepTokenImpl(String tag, int displayId) { |
| 4949 | mTag = tag; |
| 4950 | mDisplayId = displayId; |
| 4951 | mAcquireTime = SystemClock.uptimeMillis(); |
| 4952 | } |
| 4953 | |
| 4954 | @Override |
| 4955 | public void release() { |
| 4956 | synchronized (mService) { |
| 4957 | removeSleepTokenLocked(this); |
| 4958 | } |
| 4959 | } |
| 4960 | |
| 4961 | @Override |
| 4962 | public String toString() { |
| 4963 | return "{\"" + mTag + "\", display " + mDisplayId |
| 4964 | + ", acquire at " + TimeUtils.formatUptime(mAcquireTime) + "}"; |
| 4965 | } |
| 4966 | } |
| 4967 | |
Craig Mautner | 2708430 | 2013-03-25 08:05:25 -0700 | [diff] [blame] | 4968 | } |