Craig Mautner | 2708430 | 2013-03-25 08:05:25 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2013 The Android Open Source Project |
| 3 | * |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | * you may not use this file except in compliance with the License. |
| 6 | * You may obtain a copy of the License at |
| 7 | * |
| 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | * |
| 10 | * Unless required by applicable law or agreed to in writing, software |
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | * See the License for the specific language governing permissions and |
| 14 | * limitations under the License. |
| 15 | */ |
| 16 | |
Wale Ogunwale | 5950709 | 2018-10-29 09:00:30 -0700 | [diff] [blame] | 17 | package com.android.server.wm; |
Craig Mautner | 2708430 | 2013-03-25 08:05:25 -0700 | [diff] [blame] | 18 | |
Andrii Kulian | 3c9ad07 | 2017-08-01 11:45:22 -0700 | [diff] [blame] | 19 | import static android.Manifest.permission.ACTIVITY_EMBEDDING; |
Andrii Kulian | 3a95edc | 2017-06-28 16:21:07 -0700 | [diff] [blame] | 20 | import static android.Manifest.permission.INTERNAL_SYSTEM_WINDOW; |
Jorim Jaggi | fe76234 | 2016-10-13 14:33:27 +0200 | [diff] [blame] | 21 | import static android.Manifest.permission.START_ANY_ACTIVITY; |
Charles He | ff9b4dff | 2017-09-22 10:18:37 +0100 | [diff] [blame] | 22 | import static android.app.ActivityManager.LOCK_TASK_MODE_LOCKED; |
Bryce Lee | 5f0e28f | 2018-01-30 16:00:03 -0800 | [diff] [blame] | 23 | import static android.app.ActivityManager.START_DELIVERED_TO_TOP; |
Wale Ogunwale | 7056a06 | 2018-10-18 15:02:50 -0700 | [diff] [blame] | 24 | import static android.app.ActivityManager.START_FLAG_DEBUG; |
| 25 | import static android.app.ActivityManager.START_FLAG_NATIVE_DEBUGGING; |
| 26 | import static android.app.ActivityManager.START_FLAG_TRACK_ALLOCATION; |
Jorim Jaggi | fe76234 | 2016-10-13 14:33:27 +0200 | [diff] [blame] | 27 | import static android.app.ActivityManager.START_TASK_TO_FRONT; |
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 | 132ee83 | 2018-09-28 15:00:05 -0700 | [diff] [blame] | 30 | import static android.app.WaitResult.INVALID_DELAY; |
Wale Ogunwale | 6fbde9f | 2017-08-24 07:24:12 -0700 | [diff] [blame] | 31 | import static android.app.WindowConfiguration.ACTIVITY_TYPE_HOME; |
Wale Ogunwale | 0568aed | 2017-09-08 13:29:37 -0700 | [diff] [blame] | 32 | import static android.app.WindowConfiguration.ACTIVITY_TYPE_RECENTS; |
Wale Ogunwale | 6fbde9f | 2017-08-24 07:24:12 -0700 | [diff] [blame] | 33 | import static android.app.WindowConfiguration.ACTIVITY_TYPE_UNDEFINED; |
Wale Ogunwale | 0568aed | 2017-09-08 13:29:37 -0700 | [diff] [blame] | 34 | import static android.app.WindowConfiguration.WINDOWING_MODE_FREEFORM; |
Wale Ogunwale | 926aade | 2017-08-29 11:24:37 -0700 | [diff] [blame] | 35 | import static android.app.WindowConfiguration.WINDOWING_MODE_FULLSCREEN; |
Wale Ogunwale | 0568aed | 2017-09-08 13:29:37 -0700 | [diff] [blame] | 36 | import static android.app.WindowConfiguration.WINDOWING_MODE_PINNED; |
| 37 | import static android.app.WindowConfiguration.WINDOWING_MODE_SPLIT_SCREEN_PRIMARY; |
Wale Ogunwale | 926aade | 2017-08-29 11:24:37 -0700 | [diff] [blame] | 38 | import static android.app.WindowConfiguration.WINDOWING_MODE_SPLIT_SCREEN_SECONDARY; |
Wale Ogunwale | 0568aed | 2017-09-08 13:29:37 -0700 | [diff] [blame] | 39 | import static android.app.WindowConfiguration.WINDOWING_MODE_UNDEFINED; |
Wale Ogunwale | 214f348 | 2018-10-04 11:00:47 -0700 | [diff] [blame] | 40 | import static android.content.pm.PackageManager.NOTIFY_PACKAGE_USE_ACTIVITY; |
Andrii Kulian | 3c9ad07 | 2017-08-01 11:45:22 -0700 | [diff] [blame] | 41 | import static android.content.pm.PackageManager.PERMISSION_DENIED; |
Jorim Jaggi | fe76234 | 2016-10-13 14:33:27 +0200 | [diff] [blame] | 42 | import static android.content.pm.PackageManager.PERMISSION_GRANTED; |
Adrian Roos | a6d6aab | 2018-04-19 18:58:22 +0200 | [diff] [blame] | 43 | import static android.graphics.Rect.copyOrNull; |
chaviw | 59b9885 | 2017-06-13 12:05:44 -0700 | [diff] [blame] | 44 | import static android.os.PowerManager.PARTIAL_WAKE_LOCK; |
Andrii Kulian | 79d6798 | 2019-08-19 11:56:16 -0700 | [diff] [blame] | 45 | import static android.os.Process.INVALID_UID; |
Benjamin Franz | a83859f | 2017-07-03 16:34:14 +0100 | [diff] [blame] | 46 | import static android.os.Process.SYSTEM_UID; |
Riddle Hsu | 2ca561b | 2019-10-08 21:58:58 +0800 | [diff] [blame] | 47 | import static android.os.Trace.TRACE_TAG_WINDOW_MANAGER; |
Jorim Jaggi | fe76234 | 2016-10-13 14:33:27 +0200 | [diff] [blame] | 48 | import static android.view.Display.DEFAULT_DISPLAY; |
Andrii Kulian | 16802aa | 2016-11-02 12:21:33 -0700 | [diff] [blame] | 49 | import static android.view.Display.INVALID_DISPLAY; |
Andrii Kulian | 1cba31c | 2017-06-28 09:42:48 -0700 | [diff] [blame] | 50 | import static android.view.Display.TYPE_VIRTUAL; |
Louis Chang | 7d0037c | 2018-08-13 12:42:06 +0800 | [diff] [blame] | 51 | import static android.view.WindowManager.TRANSIT_DOCK_TASK_FROM_RECENTS; |
Louis Chang | ceeb506 | 2018-09-17 18:13:52 +0800 | [diff] [blame] | 52 | |
Wale Ogunwale | 5950709 | 2018-10-29 09:00:30 -0700 | [diff] [blame] | 53 | import static com.android.server.wm.ActivityStack.ActivityState.PAUSED; |
| 54 | import static com.android.server.wm.ActivityStack.ActivityState.PAUSING; |
Wale Ogunwale | 5950709 | 2018-10-29 09:00:30 -0700 | [diff] [blame] | 55 | import static com.android.server.wm.ActivityTaskManagerDebugConfig.DEBUG_ALL; |
| 56 | import static com.android.server.wm.ActivityTaskManagerDebugConfig.DEBUG_IDLE; |
| 57 | import static com.android.server.wm.ActivityTaskManagerDebugConfig.DEBUG_PAUSE; |
| 58 | import static com.android.server.wm.ActivityTaskManagerDebugConfig.DEBUG_RECENTS; |
Wale Ogunwale | 5950709 | 2018-10-29 09:00:30 -0700 | [diff] [blame] | 59 | import static com.android.server.wm.ActivityTaskManagerDebugConfig.DEBUG_STACK; |
| 60 | import static com.android.server.wm.ActivityTaskManagerDebugConfig.DEBUG_STATES; |
| 61 | import static com.android.server.wm.ActivityTaskManagerDebugConfig.DEBUG_SWITCH; |
| 62 | import static com.android.server.wm.ActivityTaskManagerDebugConfig.DEBUG_TASKS; |
| 63 | import static com.android.server.wm.ActivityTaskManagerDebugConfig.POSTFIX_IDLE; |
| 64 | import static com.android.server.wm.ActivityTaskManagerDebugConfig.POSTFIX_PAUSE; |
| 65 | import static com.android.server.wm.ActivityTaskManagerDebugConfig.POSTFIX_RECENTS; |
Wale Ogunwale | 5950709 | 2018-10-29 09:00:30 -0700 | [diff] [blame] | 66 | import static com.android.server.wm.ActivityTaskManagerDebugConfig.POSTFIX_STACK; |
Wale Ogunwale | 5950709 | 2018-10-29 09:00:30 -0700 | [diff] [blame] | 67 | import static com.android.server.wm.ActivityTaskManagerDebugConfig.POSTFIX_SWITCH; |
| 68 | import static com.android.server.wm.ActivityTaskManagerDebugConfig.POSTFIX_TASKS; |
| 69 | import static com.android.server.wm.ActivityTaskManagerDebugConfig.TAG_ATM; |
| 70 | import static com.android.server.wm.ActivityTaskManagerDebugConfig.TAG_WITH_CLASS_NAME; |
| 71 | import static com.android.server.wm.ActivityTaskManagerService.ANIMATE; |
| 72 | import static com.android.server.wm.ActivityTaskManagerService.H.FIRST_SUPERVISOR_STACK_MSG; |
| 73 | import static com.android.server.wm.ActivityTaskManagerService.RELAUNCH_REASON_NONE; |
Wale Ogunwale | d32da47 | 2018-11-16 07:19:28 -0800 | [diff] [blame] | 74 | import static com.android.server.wm.RootActivityContainer.MATCH_TASK_IN_STACKS_ONLY; |
| 75 | import static com.android.server.wm.RootActivityContainer.MATCH_TASK_IN_STACKS_OR_RECENT_TASKS; |
| 76 | import static com.android.server.wm.RootActivityContainer.MATCH_TASK_IN_STACKS_OR_RECENT_TASKS_AND_RESTORE; |
| 77 | import static com.android.server.wm.RootActivityContainer.TAG_STATES; |
Louis Chang | cdec080 | 2019-11-11 11:45:07 +0800 | [diff] [blame] | 78 | import static com.android.server.wm.Task.LOCK_TASK_AUTH_LAUNCHABLE; |
| 79 | import static com.android.server.wm.Task.LOCK_TASK_AUTH_LAUNCHABLE_PRIV; |
| 80 | import static com.android.server.wm.Task.LOCK_TASK_AUTH_WHITELISTED; |
| 81 | import static com.android.server.wm.Task.REPARENT_KEEP_STACK_AT_FRONT; |
| 82 | import static com.android.server.wm.Task.REPARENT_LEAVE_STACK_IN_PLACE; |
| 83 | import static com.android.server.wm.Task.REPARENT_MOVE_STACK_TO_FRONT; |
lumark | 9bca6b4 | 2019-10-17 18:35:22 +0800 | [diff] [blame] | 84 | import static com.android.server.wm.WindowContainer.AnimationFlags.TRANSITION; |
Wale Ogunwale | 2322bed | 2019-10-10 17:24:19 +0200 | [diff] [blame] | 85 | import static com.android.server.wm.WindowContainer.POSITION_TOP; |
Louis Chang | ceeb506 | 2018-09-17 18:13:52 +0800 | [diff] [blame] | 86 | |
Svetoslav | 7008b51 | 2015-06-24 18:47:07 -0700 | [diff] [blame] | 87 | import android.Manifest; |
Craig Mautner | 2420ead | 2013-04-01 17:13:20 -0700 | [diff] [blame] | 88 | import android.app.Activity; |
Craig Mautner | 23ac33b | 2013-04-01 16:26:35 -0700 | [diff] [blame] | 89 | import android.app.ActivityManager; |
Wale Ogunwale | 9e4f3e0 | 2018-05-17 09:35:39 -0700 | [diff] [blame] | 90 | import android.app.ActivityManagerInternal; |
Craig Mautner | 23ac33b | 2013-04-01 16:26:35 -0700 | [diff] [blame] | 91 | import android.app.ActivityOptions; |
Svetoslav | 7008b51 | 2015-06-24 18:47:07 -0700 | [diff] [blame] | 92 | import android.app.AppOpsManager; |
Jeff Hao | 1b012d3 | 2014-08-20 10:35:34 -0700 | [diff] [blame] | 93 | import android.app.ProfilerInfo; |
Craig Mautner | 2420ead | 2013-04-01 17:13:20 -0700 | [diff] [blame] | 94 | import android.app.ResultInfo; |
Sudheer Shanka | fc46e9b | 2016-10-21 17:55:27 -0700 | [diff] [blame] | 95 | import android.app.WaitResult; |
Andrii Kulian | 88e05cb | 2017-12-05 17:21:10 -0800 | [diff] [blame] | 96 | import android.app.servertransaction.ActivityLifecycleItem; |
| 97 | import android.app.servertransaction.ClientTransaction; |
Andrii Kulian | 446e824 | 2017-10-26 15:17:29 -0700 | [diff] [blame] | 98 | import android.app.servertransaction.LaunchActivityItem; |
Andrii Kulian | 88e05cb | 2017-12-05 17:21:10 -0800 | [diff] [blame] | 99 | import android.app.servertransaction.PauseActivityItem; |
| 100 | import android.app.servertransaction.ResumeActivityItem; |
Craig Mautner | 23ac33b | 2013-04-01 16:26:35 -0700 | [diff] [blame] | 101 | import android.content.ComponentName; |
Craig Mautner | 2219a1b | 2013-03-25 09:44:30 -0700 | [diff] [blame] | 102 | import android.content.Intent; |
| 103 | import android.content.pm.ActivityInfo; |
Craig Mautner | 23ac33b | 2013-04-01 16:26:35 -0700 | [diff] [blame] | 104 | import android.content.pm.ApplicationInfo; |
Svetoslav | 7008b51 | 2015-06-24 18:47:07 -0700 | [diff] [blame] | 105 | import android.content.pm.PackageInfo; |
Craig Mautner | 23ac33b | 2013-04-01 16:26:35 -0700 | [diff] [blame] | 106 | import android.content.pm.PackageManager; |
| 107 | import android.content.pm.ResolveInfo; |
Clara Bayarri | f7fea16 | 2015-10-22 16:09:52 +0100 | [diff] [blame] | 108 | import android.content.pm.UserInfo; |
Craig Mautner | 23ac33b | 2013-04-01 16:26:35 -0700 | [diff] [blame] | 109 | import android.content.res.Configuration; |
Wale Ogunwale | 60454db | 2015-01-23 16:05:07 -0800 | [diff] [blame] | 110 | import android.graphics.Rect; |
Craig Mautner | 23ac33b | 2013-04-01 16:26:35 -0700 | [diff] [blame] | 111 | import android.os.Binder; |
Jorim Jaggi | 0b46f3c | 2016-03-14 12:21:37 +0100 | [diff] [blame] | 112 | import android.os.Bundle; |
Craig Mautner | b59dcfd | 2013-05-06 13:12:58 -0700 | [diff] [blame] | 113 | import android.os.Debug; |
Craig Mautner | ce5f3cb | 2013-04-22 08:58:54 -0700 | [diff] [blame] | 114 | import android.os.Handler; |
Craig Mautner | 23ac33b | 2013-04-01 16:26:35 -0700 | [diff] [blame] | 115 | import android.os.IBinder; |
Craig Mautner | 2219a1b | 2013-03-25 09:44:30 -0700 | [diff] [blame] | 116 | import android.os.Looper; |
Craig Mautner | 2420ead | 2013-04-01 17:13:20 -0700 | [diff] [blame] | 117 | import android.os.Message; |
Craig Mautner | 0eea92c | 2013-05-16 13:35:39 -0700 | [diff] [blame] | 118 | import android.os.PowerManager; |
Craig Mautner | 7ea5bd4 | 2013-07-05 15:27:08 -0700 | [diff] [blame] | 119 | import android.os.Process; |
Craig Mautner | 8d341ef | 2013-03-26 09:03:27 -0700 | [diff] [blame] | 120 | import android.os.RemoteException; |
Craig Mautner | 23ac33b | 2013-04-01 16:26:35 -0700 | [diff] [blame] | 121 | import android.os.SystemClock; |
Wale Ogunwale | cad05a0 | 2015-09-25 10:41:44 -0700 | [diff] [blame] | 122 | import android.os.Trace; |
Craig Mautner | 6170f73 | 2013-04-02 13:05:23 -0700 | [diff] [blame] | 123 | import android.os.UserHandle; |
Clara Bayarri | f7fea16 | 2015-10-22 16:09:52 +0100 | [diff] [blame] | 124 | import android.os.UserManager; |
Dianne Hackborn | 3d07c94 | 2015-03-13 18:02:54 -0700 | [diff] [blame] | 125 | import android.os.WorkSource; |
Svetoslav | 7008b51 | 2015-06-24 18:47:07 -0700 | [diff] [blame] | 126 | import android.provider.MediaStore; |
Svetoslav | 7008b51 | 2015-06-24 18:47:07 -0700 | [diff] [blame] | 127 | import android.util.ArrayMap; |
Dianne Hackborn | 89ad456 | 2014-08-24 16:45:38 -0700 | [diff] [blame] | 128 | import android.util.ArraySet; |
Craig Mautner | 2420ead | 2013-04-01 17:13:20 -0700 | [diff] [blame] | 129 | import android.util.EventLog; |
Wale Ogunwale | e610d3d | 2017-04-25 10:23:48 -0700 | [diff] [blame] | 130 | import android.util.MergedConfiguration; |
Craig Mautner | 8d341ef | 2013-03-26 09:03:27 -0700 | [diff] [blame] | 131 | import android.util.Slog; |
Craig Mautner | 4a1cb22 | 2013-12-04 16:14:06 -0800 | [diff] [blame] | 132 | import android.util.SparseArray; |
Craig Mautner | 4a1cb22 | 2013-12-04 16:14:06 -0800 | [diff] [blame] | 133 | import android.util.SparseIntArray; |
Chong Zhang | b15758a | 2015-11-17 12:12:03 -0800 | [diff] [blame] | 134 | |
Louis Chang | 6a9be16 | 2019-07-15 10:41:32 +0800 | [diff] [blame] | 135 | import com.android.internal.R; |
Andreas Gampe | a36dc62 | 2018-02-05 17:19:22 -0800 | [diff] [blame] | 136 | import com.android.internal.annotations.GuardedBy; |
Andrii Kulian | 94e82d9b0 | 2017-07-13 15:33:06 -0700 | [diff] [blame] | 137 | import com.android.internal.annotations.VisibleForTesting; |
Dianne Hackborn | 85d558c | 2014-11-04 10:31:54 -0800 | [diff] [blame] | 138 | import com.android.internal.content.ReferrerIntent; |
Dianne Hackborn | cbfd23e | 2013-06-11 14:26:53 -0700 | [diff] [blame] | 139 | import com.android.internal.os.TransferPipe; |
Louis Chang | 7d0037c | 2018-08-13 12:42:06 +0800 | [diff] [blame] | 140 | import com.android.internal.os.logging.MetricsLoggerWrapper; |
Svetoslav | 7008b51 | 2015-06-24 18:47:07 -0700 | [diff] [blame] | 141 | import com.android.internal.util.ArrayUtils; |
Louis Chang | 7d0037c | 2018-08-13 12:42:06 +0800 | [diff] [blame] | 142 | import com.android.internal.util.function.pooled.PooledLambda; |
Wale Ogunwale | 5950709 | 2018-10-29 09:00:30 -0700 | [diff] [blame] | 143 | import com.android.server.am.ActivityManagerService; |
Wale Ogunwale | 5950709 | 2018-10-29 09:00:30 -0700 | [diff] [blame] | 144 | import com.android.server.am.EventLogTags; |
| 145 | import com.android.server.am.UserState; |
Craig Mautner | 23ac33b | 2013-04-01 16:26:35 -0700 | [diff] [blame] | 146 | |
Craig Mautner | 8d341ef | 2013-03-26 09:03:27 -0700 | [diff] [blame] | 147 | import java.io.FileDescriptor; |
| 148 | import java.io.IOException; |
Craig Mautner | 2708430 | 2013-03-25 08:05:25 -0700 | [diff] [blame] | 149 | import java.io.PrintWriter; |
Craig Mautner | 2219a1b | 2013-03-25 09:44:30 -0700 | [diff] [blame] | 150 | import java.util.ArrayList; |
Craig Mautner | 8d341ef | 2013-03-26 09:03:27 -0700 | [diff] [blame] | 151 | import java.util.List; |
Craig Mautner | 2708430 | 2013-03-25 08:05:25 -0700 | [diff] [blame] | 152 | |
Wale Ogunwale | d32da47 | 2018-11-16 07:19:28 -0800 | [diff] [blame] | 153 | // TODO: This class has become a dumping ground. Let's |
| 154 | // - Move things relating to the hierarchy to RootWindowContainer |
| 155 | // - Move things relating to activity life cycles to maybe a new class called ActivityLifeCycler |
| 156 | // - Move interface things to ActivityTaskManagerService. |
| 157 | // - All other little things to other files. |
| 158 | public class ActivityStackSupervisor implements RecentTasks.Callbacks { |
Wale Ogunwale | 9887561 | 2018-10-12 07:53:02 -0700 | [diff] [blame] | 159 | private static final String TAG = TAG_WITH_CLASS_NAME ? "ActivityStackSupervisor" : TAG_ATM; |
Wale Ogunwale | 0fc365c | 2015-05-25 19:35:42 -0700 | [diff] [blame] | 160 | private static final String TAG_IDLE = TAG + POSTFIX_IDLE; |
Wale Ogunwale | ee006da | 2015-03-30 14:49:25 -0700 | [diff] [blame] | 161 | private static final String TAG_PAUSE = TAG + POSTFIX_PAUSE; |
Wale Ogunwale | ee006da | 2015-03-30 14:49:25 -0700 | [diff] [blame] | 162 | private static final String TAG_RECENTS = TAG + POSTFIX_RECENTS; |
| 163 | private static final String TAG_STACK = TAG + POSTFIX_STACK; |
| 164 | private static final String TAG_SWITCH = TAG + POSTFIX_SWITCH; |
Filip Gruszczynski | 07a0e49 | 2015-12-17 14:16:38 -0800 | [diff] [blame] | 165 | static final String TAG_TASKS = TAG + POSTFIX_TASKS; |
Wale Ogunwale | e23149f | 2015-03-06 15:39:44 -0800 | [diff] [blame] | 166 | |
Craig Mautner | f333327 | 2013-04-22 10:55:53 -0700 | [diff] [blame] | 167 | /** 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] | 168 | static final int IDLE_TIMEOUT = 10 * 1000; |
Craig Mautner | f333327 | 2013-04-22 10:55:53 -0700 | [diff] [blame] | 169 | |
Craig Mautner | 0eea92c | 2013-05-16 13:35:39 -0700 | [diff] [blame] | 170 | /** How long we can hold the sleep wake lock before giving up. */ |
Wale Ogunwale | 0fc365c | 2015-05-25 19:35:42 -0700 | [diff] [blame] | 171 | static final int SLEEP_TIMEOUT = 5 * 1000; |
Craig Mautner | 0eea92c | 2013-05-16 13:35:39 -0700 | [diff] [blame] | 172 | |
Craig Mautner | 7ea5bd4 | 2013-07-05 15:27:08 -0700 | [diff] [blame] | 173 | // How long we can hold the launch wake lock before giving up. |
Wale Ogunwale | 0fc365c | 2015-05-25 19:35:42 -0700 | [diff] [blame] | 174 | static final int LAUNCH_TIMEOUT = 10 * 1000; |
Craig Mautner | 7ea5bd4 | 2013-07-05 15:27:08 -0700 | [diff] [blame] | 175 | |
Andrii Kulian | 86e70fc | 2019-02-12 11:04:10 +0000 | [diff] [blame] | 176 | /** How long we wait until giving up on the activity telling us it released the top state. */ |
| 177 | static final int TOP_RESUMED_STATE_LOSS_TIMEOUT = 500; |
| 178 | |
Craig Mautner | 05d2903 | 2013-05-03 13:40:13 -0700 | [diff] [blame] | 179 | static final int IDLE_TIMEOUT_MSG = FIRST_SUPERVISOR_STACK_MSG; |
| 180 | static final int IDLE_NOW_MSG = FIRST_SUPERVISOR_STACK_MSG + 1; |
| 181 | static final int RESUME_TOP_ACTIVITY_MSG = FIRST_SUPERVISOR_STACK_MSG + 2; |
Craig Mautner | 0eea92c | 2013-05-16 13:35:39 -0700 | [diff] [blame] | 182 | static final int SLEEP_TIMEOUT_MSG = FIRST_SUPERVISOR_STACK_MSG + 3; |
Craig Mautner | 7ea5bd4 | 2013-07-05 15:27:08 -0700 | [diff] [blame] | 183 | static final int LAUNCH_TIMEOUT_MSG = FIRST_SUPERVISOR_STACK_MSG + 4; |
Wale Ogunwale | 73eba74 | 2015-04-07 14:23:14 -0700 | [diff] [blame] | 184 | static final int LAUNCH_TASK_BEHIND_COMPLETE = FIRST_SUPERVISOR_STACK_MSG + 12; |
Riddle Hsu | 7b766fd | 2019-01-28 21:14:59 +0800 | [diff] [blame] | 185 | static final int RESTART_ACTIVITY_PROCESS_TIMEOUT_MSG = FIRST_SUPERVISOR_STACK_MSG + 13; |
Wale Ogunwale | 22e2526 | 2016-02-01 10:32:02 -0800 | [diff] [blame] | 186 | static final int REPORT_MULTI_WINDOW_MODE_CHANGED_MSG = FIRST_SUPERVISOR_STACK_MSG + 14; |
| 187 | static final int REPORT_PIP_MODE_CHANGED_MSG = FIRST_SUPERVISOR_STACK_MSG + 15; |
Louis Chang | dcdde95 | 2018-12-04 15:38:44 +0800 | [diff] [blame] | 188 | static final int REPORT_HOME_CHANGED_MSG = FIRST_SUPERVISOR_STACK_MSG + 16; |
Andrii Kulian | 86e70fc | 2019-02-12 11:04:10 +0000 | [diff] [blame] | 189 | static final int TOP_RESUMED_STATE_LOSS_TIMEOUT_MSG = FIRST_SUPERVISOR_STACK_MSG + 17; |
Craig Mautner | 4a1cb22 | 2013-12-04 16:14:06 -0800 | [diff] [blame] | 190 | |
Filip Gruszczynski | bc5a6c5 | 2015-09-22 13:13:24 -0700 | [diff] [blame] | 191 | // Used to indicate that windows of activities should be preserved during the resize. |
| 192 | static final boolean PRESERVE_WINDOWS = true; |
| 193 | |
Wale Ogunwale | 040b470 | 2015-08-06 18:10:50 -0700 | [diff] [blame] | 194 | // Used to indicate if an object (e.g. task) should be moved/created |
| 195 | // at the top of its container (e.g. stack). |
Wale Ogunwale | b30daaa | 2015-08-07 21:50:49 -0700 | [diff] [blame] | 196 | static final boolean ON_TOP = true; |
Wale Ogunwale | 040b470 | 2015-08-06 18:10:50 -0700 | [diff] [blame] | 197 | |
Wale Ogunwale | c8da41e | 2016-04-16 13:27:23 -0700 | [diff] [blame] | 198 | // Don't execute any calls to resume. |
| 199 | static final boolean DEFER_RESUME = true; |
| 200 | |
Winson Chung | 010927a | 2016-12-15 16:12:35 -0800 | [diff] [blame] | 201 | // Used to indicate that a task is removed it should also be removed from recents. |
| 202 | static final boolean REMOVE_FROM_RECENTS = true; |
| 203 | |
Adrian Roos | a6d6aab | 2018-04-19 18:58:22 +0200 | [diff] [blame] | 204 | /** True if the docked stack is currently being resized. */ |
| 205 | private boolean mDockedStackResizing; |
| 206 | |
| 207 | /** |
| 208 | * True if there are pending docked bounds that need to be applied after |
| 209 | * {@link #mDockedStackResizing} is reset to false. |
| 210 | */ |
| 211 | private boolean mHasPendingDockedBounds; |
| 212 | private Rect mPendingDockedBounds; |
| 213 | private Rect mPendingTempDockedTaskBounds; |
| 214 | private Rect mPendingTempDockedTaskInsetBounds; |
| 215 | private Rect mPendingTempOtherTaskBounds; |
| 216 | private Rect mPendingTempOtherTaskInsetBounds; |
| 217 | |
Svetoslav | 7008b51 | 2015-06-24 18:47:07 -0700 | [diff] [blame] | 218 | // Activity actions an app cannot start if it uses a permission which is not granted. |
| 219 | private static final ArrayMap<String, String> ACTION_TO_RUNTIME_PERMISSION = |
| 220 | new ArrayMap<>(); |
Filip Gruszczynski | bc5a6c5 | 2015-09-22 13:13:24 -0700 | [diff] [blame] | 221 | |
Svetoslav | 7008b51 | 2015-06-24 18:47:07 -0700 | [diff] [blame] | 222 | static { |
| 223 | ACTION_TO_RUNTIME_PERMISSION.put(MediaStore.ACTION_IMAGE_CAPTURE, |
| 224 | Manifest.permission.CAMERA); |
| 225 | ACTION_TO_RUNTIME_PERMISSION.put(MediaStore.ACTION_VIDEO_CAPTURE, |
| 226 | Manifest.permission.CAMERA); |
| 227 | ACTION_TO_RUNTIME_PERMISSION.put(Intent.ACTION_CALL, |
| 228 | Manifest.permission.CALL_PHONE); |
| 229 | } |
| 230 | |
Svet Ganov | 99b6043 | 2015-06-27 13:15:22 -0700 | [diff] [blame] | 231 | /** Action restriction: launching the activity is not restricted. */ |
| 232 | private static final int ACTIVITY_RESTRICTION_NONE = 0; |
| 233 | /** Action restriction: launching the activity is restricted by a permission. */ |
| 234 | private static final int ACTIVITY_RESTRICTION_PERMISSION = 1; |
| 235 | /** Action restriction: launching the activity is restricted by an app op. */ |
| 236 | private static final int ACTIVITY_RESTRICTION_APPOP = 2; |
Svetoslav | 7008b51 | 2015-06-24 18:47:07 -0700 | [diff] [blame] | 237 | |
Craig Mautner | 7ea5bd4 | 2013-07-05 15:27:08 -0700 | [diff] [blame] | 238 | // For debugging to make sure the caller when acquiring/releasing our |
| 239 | // wake lock is the system process. |
| 240 | static final boolean VALIDATE_WAKE_LOCK_CALLER = false; |
Suprabh Shukla | 09a88f5 | 2015-12-02 14:36:31 -0800 | [diff] [blame] | 241 | /** The number of distinct task ids that can be assigned to the tasks of a single user */ |
| 242 | 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] | 243 | |
Wale Ogunwale | b73f396 | 2018-11-20 07:58:22 -0800 | [diff] [blame] | 244 | final ActivityTaskManagerService mService; |
Wale Ogunwale | d32da47 | 2018-11-16 07:19:28 -0800 | [diff] [blame] | 245 | RootActivityContainer mRootActivityContainer; |
Craig Mautner | 2708430 | 2013-03-25 08:05:25 -0700 | [diff] [blame] | 246 | |
Winson Chung | 61c9e5a | 2017-10-11 10:39:32 -0700 | [diff] [blame] | 247 | /** The historial list of recent tasks including inactive tasks */ |
Winson Chung | 1dbc811 | 2017-09-28 18:05:31 -0700 | [diff] [blame] | 248 | RecentTasks mRecentTasks; |
Wale Ogunwale | c82f2f5 | 2014-12-09 09:32:50 -0800 | [diff] [blame] | 249 | |
Winson Chung | 61c9e5a | 2017-10-11 10:39:32 -0700 | [diff] [blame] | 250 | /** Helper class to abstract out logic for fetching the set of currently running tasks */ |
Wale Ogunwale | 8a1860a | 2019-06-05 08:57:19 -0700 | [diff] [blame] | 251 | private RunningTasks mRunningTasks; |
Winson Chung | 61c9e5a | 2017-10-11 10:39:32 -0700 | [diff] [blame] | 252 | |
Craig Mautner | ce5f3cb | 2013-04-22 08:58:54 -0700 | [diff] [blame] | 253 | final ActivityStackSupervisorHandler mHandler; |
Winson Chung | e2d7217 | 2018-01-25 17:46:20 +0000 | [diff] [blame] | 254 | final Looper mLooper; |
Craig Mautner | ce5f3cb | 2013-04-22 08:58:54 -0700 | [diff] [blame] | 255 | |
| 256 | /** Short cut */ |
| 257 | WindowManagerService mWindowManager; |
| 258 | |
Garfield Tan | 891146c | 2018-10-09 12:14:00 -0700 | [diff] [blame] | 259 | /** Common synchronization logic used to save things to disks. */ |
| 260 | PersisterQueue mPersisterQueue; |
| 261 | LaunchParamsPersister mLaunchParamsPersister; |
Bryce Lee | ec55eb0 | 2017-12-05 20:51:27 -0800 | [diff] [blame] | 262 | private LaunchParamsController mLaunchParamsController; |
Bryce Lee | 9ad3eb3 | 2017-10-10 10:10:31 -0700 | [diff] [blame] | 263 | |
Suprabh Shukla | 09a88f5 | 2015-12-02 14:36:31 -0800 | [diff] [blame] | 264 | /** |
| 265 | * Maps the task identifier that activities are currently being started in to the userId of the |
| 266 | * task. Each time a new task is created, the entry for the userId of the task is incremented |
| 267 | */ |
| 268 | private final SparseIntArray mCurTaskIdForUser = new SparseIntArray(20); |
Craig Mautner | 8d341ef | 2013-03-26 09:03:27 -0700 | [diff] [blame] | 269 | |
Bryce Lee | 4a19438 | 2017-04-04 14:32:48 -0700 | [diff] [blame] | 270 | /** List of processes waiting to find out when a specific activity becomes visible. */ |
| 271 | private final ArrayList<WaitInfo> mWaitingForActivityVisible = new ArrayList<>(); |
Craig Mautner | ce5f3cb | 2013-04-22 08:58:54 -0700 | [diff] [blame] | 272 | |
| 273 | /** List of processes waiting to find out about the next launched activity. */ |
Sudheer Shanka | fc46e9b | 2016-10-21 17:55:27 -0700 | [diff] [blame] | 274 | final ArrayList<WaitResult> mWaitingActivityLaunched = new ArrayList<>(); |
Craig Mautner | ce5f3cb | 2013-04-22 08:58:54 -0700 | [diff] [blame] | 275 | |
Craig Mautner | de4ef02 | 2013-04-07 19:01:33 -0700 | [diff] [blame] | 276 | /** List of activities that are ready to be stopped, but waiting for the next activity to |
| 277 | * settle down before doing so. */ |
Craig Mautner | 8c14c15 | 2015-01-15 17:32:07 -0800 | [diff] [blame] | 278 | final ArrayList<ActivityRecord> mStoppingActivities = new ArrayList<>(); |
Craig Mautner | de4ef02 | 2013-04-07 19:01:33 -0700 | [diff] [blame] | 279 | |
Craig Mautner | f333327 | 2013-04-22 10:55:53 -0700 | [diff] [blame] | 280 | /** List of activities that are ready to be finished, but waiting for the previous activity to |
| 281 | * settle down before doing so. It contains ActivityRecord objects. */ |
Craig Mautner | 8c14c15 | 2015-01-15 17:32:07 -0800 | [diff] [blame] | 282 | final ArrayList<ActivityRecord> mFinishingActivities = new ArrayList<>(); |
Craig Mautner | f333327 | 2013-04-22 10:55:53 -0700 | [diff] [blame] | 283 | |
Craig Mautner | 0eea92c | 2013-05-16 13:35:39 -0700 | [diff] [blame] | 284 | /** List of activities that are in the process of going to sleep. */ |
Craig Mautner | 8c14c15 | 2015-01-15 17:32:07 -0800 | [diff] [blame] | 285 | final ArrayList<ActivityRecord> mGoingToSleepActivities = new ArrayList<>(); |
Craig Mautner | 0eea92c | 2013-05-16 13:35:39 -0700 | [diff] [blame] | 286 | |
Wale Ogunwale | 22e2526 | 2016-02-01 10:32:02 -0800 | [diff] [blame] | 287 | /** List of activities whose multi-window mode changed that we need to report to the |
| 288 | * application */ |
| 289 | final ArrayList<ActivityRecord> mMultiWindowModeChangedActivities = new ArrayList<>(); |
| 290 | |
| 291 | /** List of activities whose picture-in-picture mode changed that we need to report to the |
| 292 | * application */ |
| 293 | final ArrayList<ActivityRecord> mPipModeChangedActivities = new ArrayList<>(); |
| 294 | |
Jorim Jaggi | fa9ed96 | 2018-01-25 00:16:49 +0100 | [diff] [blame] | 295 | /** |
| 296 | * Animations that for the current transition have requested not to |
| 297 | * be considered for the transition animation. |
| 298 | */ |
| 299 | final ArrayList<ActivityRecord> mNoAnimActivities = new ArrayList<>(); |
| 300 | |
Andrii Kulian | 86e70fc | 2019-02-12 11:04:10 +0000 | [diff] [blame] | 301 | /** |
| 302 | * Cached value of the topmost resumed activity in the system. Updated when new activity is |
| 303 | * resumed. |
| 304 | */ |
| 305 | private ActivityRecord mTopResumedActivity; |
| 306 | |
| 307 | /** |
| 308 | * Flag indicating whether we're currently waiting for the previous top activity to handle the |
| 309 | * loss of the state and report back before making new activity top resumed. |
| 310 | */ |
| 311 | private boolean mTopResumedActivityWaitingForPrev; |
| 312 | |
Winson Chung | 5af42fc | 2017-03-24 17:11:33 -0700 | [diff] [blame] | 313 | /** The target stack bounds for the picture-in-picture mode changed that we need to report to |
| 314 | * the application */ |
| 315 | Rect mPipModeChangedTargetStackBounds; |
| 316 | |
Craig Mautner | f333327 | 2013-04-22 10:55:53 -0700 | [diff] [blame] | 317 | /** Used on user changes */ |
Amith Yamasani | 37a40c2 | 2015-06-17 13:25:42 -0700 | [diff] [blame] | 318 | final ArrayList<UserState> mStartingUsers = new ArrayList<>(); |
Craig Mautner | f333327 | 2013-04-22 10:55:53 -0700 | [diff] [blame] | 319 | |
Craig Mautner | de4ef02 | 2013-04-07 19:01:33 -0700 | [diff] [blame] | 320 | /** Set to indicate whether to issue an onUserLeaving callback when a newly launched activity |
| 321 | * is being brought in front of us. */ |
| 322 | boolean mUserLeaving = false; |
| 323 | |
Craig Mautner | 0eea92c | 2013-05-16 13:35:39 -0700 | [diff] [blame] | 324 | /** |
Louis Chang | 6a9be16 | 2019-07-15 10:41:32 +0800 | [diff] [blame] | 325 | * The system chooser activity which worked as a delegate of |
| 326 | * {@link com.android.internal.app.ResolverActivity}. |
| 327 | */ |
| 328 | private ComponentName mSystemChooserActivity; |
| 329 | |
| 330 | /** |
Craig Mautner | 7ea5bd4 | 2013-07-05 15:27:08 -0700 | [diff] [blame] | 331 | * We don't want to allow the device to go to sleep while in the process |
| 332 | * of launching an activity. This is primarily to allow alarm intent |
| 333 | * receivers to launch an activity and get that to run before the device |
| 334 | * goes back to sleep. |
| 335 | */ |
Andrii Kulian | c598b2d | 2019-02-07 17:16:38 -0800 | [diff] [blame] | 336 | PowerManager.WakeLock mLaunchingActivityWakeLock; |
Craig Mautner | 7ea5bd4 | 2013-07-05 15:27:08 -0700 | [diff] [blame] | 337 | |
| 338 | /** |
Craig Mautner | 0eea92c | 2013-05-16 13:35:39 -0700 | [diff] [blame] | 339 | * Set when the system is going to sleep, until we have |
| 340 | * successfully paused the current activity and released our wake lock. |
| 341 | * At that point the system is allowed to actually sleep. |
| 342 | */ |
Andrii Kulian | c598b2d | 2019-02-07 17:16:38 -0800 | [diff] [blame] | 343 | PowerManager.WakeLock mGoingToSleepWakeLock; |
Craig Mautner | 0eea92c | 2013-05-16 13:35:39 -0700 | [diff] [blame] | 344 | |
Andrii Kulian | 1e32e02 | 2016-09-16 15:29:34 -0700 | [diff] [blame] | 345 | /** |
| 346 | * Temporary rect used during docked stack resize calculation so we don't need to create a new |
| 347 | * object each time. |
| 348 | */ |
Wale Ogunwale | b34a7ad | 2015-08-14 11:05:30 -0700 | [diff] [blame] | 349 | private final Rect tempRect = new Rect(); |
Wale Ogunwale | 7e1f5f5 | 2017-10-18 15:19:59 -0700 | [diff] [blame] | 350 | private final ActivityOptions mTmpOptions = ActivityOptions.makeBasic(); |
Filip Gruszczynski | ebcc875 | 2015-08-25 16:51:05 -0700 | [diff] [blame] | 351 | |
Bryce Lee | 2a3cc46 | 2017-10-27 10:57:35 -0700 | [diff] [blame] | 352 | private ActivityMetricsLogger mActivityMetricsLogger; |
Filip Gruszczynski | 77d9448 | 2015-12-11 13:59:52 -0800 | [diff] [blame] | 353 | |
Andrii Kulian | 036e3ad | 2017-04-19 10:55:10 -0700 | [diff] [blame] | 354 | /** Check if placing task or activity on specified display is allowed. */ |
Riddle Hsu | 1656713 | 2018-08-16 21:37:47 +0800 | [diff] [blame] | 355 | boolean canPlaceEntityOnDisplay(int displayId, int callingPid, int callingUid, |
| 356 | ActivityInfo activityInfo) { |
Andrii Kulian | 02689a7 | 2017-07-06 14:28:59 -0700 | [diff] [blame] | 357 | if (displayId == DEFAULT_DISPLAY) { |
| 358 | // No restrictions for the default display. |
| 359 | return true; |
| 360 | } |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 361 | if (!mService.mSupportsMultiDisplay) { |
Andrii Kulian | 02689a7 | 2017-07-06 14:28:59 -0700 | [diff] [blame] | 362 | // Can't launch on secondary displays if feature is not supported. |
| 363 | return false; |
| 364 | } |
Andrii Kulian | 02689a7 | 2017-07-06 14:28:59 -0700 | [diff] [blame] | 365 | if (!isCallerAllowedToLaunchOnDisplay(callingPid, callingUid, displayId, activityInfo)) { |
| 366 | // Can't place activities to a display that has restricted launch rules. |
| 367 | // In this case the request should be made by explicitly adding target display id and |
| 368 | // by caller with corresponding permissions. See #isCallerAllowedToLaunchOnDisplay(). |
| 369 | return false; |
| 370 | } |
| 371 | return true; |
Andrii Kulian | 036e3ad | 2017-04-19 10:55:10 -0700 | [diff] [blame] | 372 | } |
| 373 | |
| 374 | /** |
Jorim Jaggi | a0fdeec | 2016-01-07 14:42:28 +0100 | [diff] [blame] | 375 | * Used to keep track whether app visibilities got changed since the last pause. Useful to |
| 376 | * determine whether to invoke the task stack change listener after pausing. |
| 377 | */ |
| 378 | boolean mAppVisibilitiesChangedSinceLastPause; |
| 379 | |
| 380 | /** |
Jorim Jaggi | 0b46f3c | 2016-03-14 12:21:37 +0100 | [diff] [blame] | 381 | * Set of tasks that are in resizing mode during an app transition to fill the "void". |
| 382 | */ |
| 383 | private final ArraySet<Integer> mResizingTasksDuringAnimation = new ArraySet<>(); |
| 384 | |
Wale Ogunwale | c8da41e | 2016-04-16 13:27:23 -0700 | [diff] [blame] | 385 | |
| 386 | /** |
| 387 | * If set to {@code false} all calls to resize the docked stack {@link #resizeDockedStackLocked} |
| 388 | * will be ignored. Useful for the case where the caller is handling resizing of other stack and |
| 389 | * moving tasks around and doesn't want dock stack to be resized due to an automatic trigger |
| 390 | * like the docked stack going empty. |
| 391 | */ |
| 392 | private boolean mAllowDockedStackResize = true; |
| 393 | |
Bryce Lee | 2a3cc46 | 2017-10-27 10:57:35 -0700 | [diff] [blame] | 394 | private KeyguardController mKeyguardController; |
Jorim Jaggi | fe76234 | 2016-10-13 14:33:27 +0200 | [diff] [blame] | 395 | |
chaviw | 59b9885 | 2017-06-13 12:05:44 -0700 | [diff] [blame] | 396 | private PowerManager mPowerManager; |
| 397 | private int mDeferResumeCount; |
| 398 | |
Bryce Lee | 2a3cc46 | 2017-10-27 10:57:35 -0700 | [diff] [blame] | 399 | private boolean mInitialized; |
| 400 | |
Tony Mak | 853304c | 2016-04-18 15:17:41 +0100 | [diff] [blame] | 401 | /** |
Craig Mautner | ee36c77 | 2014-07-16 14:56:05 -0700 | [diff] [blame] | 402 | * Description of a request to start a new activity, which has been held |
| 403 | * due to app switches being disabled. |
| 404 | */ |
| 405 | static class PendingActivityLaunch { |
| 406 | final ActivityRecord r; |
| 407 | final ActivityRecord sourceRecord; |
| 408 | final int startFlags; |
| 409 | final ActivityStack stack; |
Wale Ogunwale | 9e4f3e0 | 2018-05-17 09:35:39 -0700 | [diff] [blame] | 410 | final WindowProcessController callerApp; |
Craig Mautner | ee36c77 | 2014-07-16 14:56:05 -0700 | [diff] [blame] | 411 | |
Wale Ogunwale | 586a8ee | 2019-06-04 13:44:14 +0000 | [diff] [blame] | 412 | PendingActivityLaunch(ActivityRecord _r, ActivityRecord _sourceRecord, |
| 413 | int _startFlags, ActivityStack _stack, WindowProcessController app) { |
| 414 | r = _r; |
| 415 | sourceRecord = _sourceRecord; |
| 416 | startFlags = _startFlags; |
| 417 | stack = _stack; |
| 418 | callerApp = app; |
Robert Carr | 13997f5 | 2015-10-23 13:13:39 -0700 | [diff] [blame] | 419 | } |
| 420 | |
| 421 | void sendErrorResult(String message) { |
| 422 | try { |
wilsonshih | 0c0fb22 | 2019-06-21 16:15:08 +0800 | [diff] [blame] | 423 | if (callerApp != null && callerApp.hasThread()) { |
Wale Ogunwale | 9e4f3e0 | 2018-05-17 09:35:39 -0700 | [diff] [blame] | 424 | callerApp.getThread().scheduleCrash(message); |
Robert Carr | 13997f5 | 2015-10-23 13:13:39 -0700 | [diff] [blame] | 425 | } |
| 426 | } catch (RemoteException e) { |
| 427 | Slog.e(TAG, "Exception scheduling crash of failed " |
| 428 | + "activity launcher sourceRecord=" + sourceRecord, e); |
| 429 | } |
Craig Mautner | ee36c77 | 2014-07-16 14:56:05 -0700 | [diff] [blame] | 430 | } |
| 431 | } |
| 432 | |
Wale Ogunwale | c9e57de | 2018-05-08 14:28:07 -0700 | [diff] [blame] | 433 | public ActivityStackSupervisor(ActivityTaskManagerService service, Looper looper) { |
Craig Mautner | 2708430 | 2013-03-25 08:05:25 -0700 | [diff] [blame] | 434 | mService = service; |
Winson Chung | e2d7217 | 2018-01-25 17:46:20 +0000 | [diff] [blame] | 435 | mLooper = looper; |
Bryce Lee | af691c0 | 2017-03-20 14:20:22 -0700 | [diff] [blame] | 436 | mHandler = new ActivityStackSupervisorHandler(looper); |
Bryce Lee | 2a3cc46 | 2017-10-27 10:57:35 -0700 | [diff] [blame] | 437 | } |
| 438 | |
| 439 | public void initialize() { |
| 440 | if (mInitialized) { |
| 441 | return; |
| 442 | } |
| 443 | |
| 444 | mInitialized = true; |
Wale Ogunwale | 8a1860a | 2019-06-05 08:57:19 -0700 | [diff] [blame] | 445 | setRunningTasks(new RunningTasks()); |
Igor Murashkin | c0b47e4 | 2018-11-07 15:54:18 -0800 | [diff] [blame] | 446 | |
| 447 | mActivityMetricsLogger = new ActivityMetricsLogger(this, mService.mContext, |
| 448 | mHandler.getLooper()); |
Wale Ogunwale | f673393 | 2018-06-27 05:14:34 -0700 | [diff] [blame] | 449 | mKeyguardController = new KeyguardController(mService, this); |
Bryce Lee | dacefc4 | 2017-10-10 12:56:02 -0700 | [diff] [blame] | 450 | |
Garfield Tan | 891146c | 2018-10-09 12:14:00 -0700 | [diff] [blame] | 451 | mPersisterQueue = new PersisterQueue(); |
| 452 | mLaunchParamsPersister = new LaunchParamsPersister(mPersisterQueue, this); |
| 453 | mLaunchParamsController = new LaunchParamsController(mService, mLaunchParamsPersister); |
Bryce Lee | ec55eb0 | 2017-12-05 20:51:27 -0800 | [diff] [blame] | 454 | mLaunchParamsController.registerDefaultModifiers(this); |
Jeff Brown | 2c43c33 | 2014-06-12 22:38:59 -0700 | [diff] [blame] | 455 | } |
| 456 | |
Garfield Tan | 891146c | 2018-10-09 12:14:00 -0700 | [diff] [blame] | 457 | void onSystemReady() { |
Garfield Tan | 891146c | 2018-10-09 12:14:00 -0700 | [diff] [blame] | 458 | mLaunchParamsPersister.onSystemReady(); |
| 459 | } |
Bryce Lee | 2a3cc46 | 2017-10-27 10:57:35 -0700 | [diff] [blame] | 460 | |
Garfield Tan | 0d407f4 | 2019-03-07 11:47:01 -0800 | [diff] [blame] | 461 | void onUserUnlocked(int userId) { |
| 462 | // Only start persisting when the first user is unlocked. The method call is |
| 463 | // idempotent so there is no side effect to call it again when the second user is |
| 464 | // unlocked. |
| 465 | mPersisterQueue.startPersisting(); |
| 466 | mLaunchParamsPersister.onUnlockUser(userId); |
| 467 | } |
| 468 | |
Bryce Lee | 2a3cc46 | 2017-10-27 10:57:35 -0700 | [diff] [blame] | 469 | public ActivityMetricsLogger getActivityMetricsLogger() { |
| 470 | return mActivityMetricsLogger; |
| 471 | } |
| 472 | |
| 473 | public KeyguardController getKeyguardController() { |
| 474 | return mKeyguardController; |
| 475 | } |
| 476 | |
Louis Chang | 6a9be16 | 2019-07-15 10:41:32 +0800 | [diff] [blame] | 477 | ComponentName getSystemChooserActivity() { |
| 478 | if (mSystemChooserActivity == null) { |
| 479 | mSystemChooserActivity = ComponentName.unflattenFromString( |
| 480 | mService.mContext.getResources().getString(R.string.config_chooserActivity)); |
| 481 | } |
| 482 | return mSystemChooserActivity; |
| 483 | } |
| 484 | |
Suprabh Shukla | 09a88f5 | 2015-12-02 14:36:31 -0800 | [diff] [blame] | 485 | void setRecentTasks(RecentTasks recentTasks) { |
Wale Ogunwale | 8a1860a | 2019-06-05 08:57:19 -0700 | [diff] [blame] | 486 | if (mRecentTasks != null) { |
| 487 | mRecentTasks.unregisterCallback(this); |
| 488 | } |
Suprabh Shukla | 09a88f5 | 2015-12-02 14:36:31 -0800 | [diff] [blame] | 489 | mRecentTasks = recentTasks; |
Winson Chung | 1dbc811 | 2017-09-28 18:05:31 -0700 | [diff] [blame] | 490 | mRecentTasks.registerCallback(this); |
Suprabh Shukla | 09a88f5 | 2015-12-02 14:36:31 -0800 | [diff] [blame] | 491 | } |
| 492 | |
Winson Chung | 3f0e59a | 2017-10-25 10:19:05 -0700 | [diff] [blame] | 493 | @VisibleForTesting |
Wale Ogunwale | 8a1860a | 2019-06-05 08:57:19 -0700 | [diff] [blame] | 494 | void setRunningTasks(RunningTasks runningTasks) { |
| 495 | mRunningTasks = runningTasks; |
| 496 | } |
| 497 | |
| 498 | RunningTasks getRunningTasks() { |
| 499 | return mRunningTasks; |
Winson Chung | 3f0e59a | 2017-10-25 10:19:05 -0700 | [diff] [blame] | 500 | } |
| 501 | |
Jeff Brown | 2c43c33 | 2014-06-12 22:38:59 -0700 | [diff] [blame] | 502 | /** |
| 503 | * At the time when the constructor runs, the power manager has not yet been |
| 504 | * initialized. So we initialize our wakelocks afterwards. |
| 505 | */ |
| 506 | void initPowerManagement() { |
Michael Wright | e300104 | 2019-02-05 00:13:14 +0000 | [diff] [blame] | 507 | mPowerManager = mService.mContext.getSystemService(PowerManager.class); |
Andrii Kulian | c598b2d | 2019-02-07 17:16:38 -0800 | [diff] [blame] | 508 | mGoingToSleepWakeLock = mPowerManager |
chaviw | 59b9885 | 2017-06-13 12:05:44 -0700 | [diff] [blame] | 509 | .newWakeLock(PARTIAL_WAKE_LOCK, "ActivityManager-Sleep"); |
Andrii Kulian | c598b2d | 2019-02-07 17:16:38 -0800 | [diff] [blame] | 510 | mLaunchingActivityWakeLock = mPowerManager.newWakeLock(PARTIAL_WAKE_LOCK, "*launch*"); |
| 511 | mLaunchingActivityWakeLock.setReferenceCounted(false); |
Craig Mautner | 2219a1b | 2013-03-25 09:44:30 -0700 | [diff] [blame] | 512 | } |
| 513 | |
Craig Mautner | ce5f3cb | 2013-04-22 08:58:54 -0700 | [diff] [blame] | 514 | void setWindowManager(WindowManagerService wm) { |
Wale Ogunwale | 65ebd95 | 2018-04-25 15:41:44 -0700 | [diff] [blame] | 515 | mWindowManager = wm; |
| 516 | getKeyguardController().setWindowManager(wm); |
Craig Mautner | 20e7227 | 2013-04-01 13:45:53 -0700 | [diff] [blame] | 517 | } |
| 518 | |
Matthew Ng | 330757d | 2017-02-28 14:19:17 -0800 | [diff] [blame] | 519 | void moveRecentsStackToFront(String reason) { |
Wale Ogunwale | d32da47 | 2018-11-16 07:19:28 -0800 | [diff] [blame] | 520 | final ActivityStack recentsStack = mRootActivityContainer.getDefaultDisplay().getStack( |
Wale Ogunwale | 04a05ac | 2017-09-17 21:35:02 -0700 | [diff] [blame] | 521 | WINDOWING_MODE_UNDEFINED, ACTIVITY_TYPE_RECENTS); |
Matthew Ng | 330757d | 2017-02-28 14:19:17 -0800 | [diff] [blame] | 522 | if (recentsStack != null) { |
| 523 | recentsStack.moveToFront(reason); |
| 524 | } |
| 525 | } |
| 526 | |
Suprabh Shukla | 09a88f5 | 2015-12-02 14:36:31 -0800 | [diff] [blame] | 527 | void setNextTaskIdForUserLocked(int taskId, int userId) { |
| 528 | final int currentTaskId = mCurTaskIdForUser.get(userId, -1); |
| 529 | if (taskId > currentTaskId) { |
| 530 | mCurTaskIdForUser.put(userId, taskId); |
Craig Mautner | ef73ee1 | 2014-04-23 11:45:37 -0700 | [diff] [blame] | 531 | } |
| 532 | } |
| 533 | |
Chong Zhang | d9d35bd | 2016-08-04 17:55:21 -0700 | [diff] [blame] | 534 | static int nextTaskIdForUser(int taskId, int userId) { |
| 535 | int nextTaskId = taskId + 1; |
| 536 | if (nextTaskId == (userId + 1) * MAX_TASK_IDS_PER_USER) { |
| 537 | // Wrap around as there will be smaller task ids that are available now. |
| 538 | nextTaskId -= MAX_TASK_IDS_PER_USER; |
| 539 | } |
| 540 | return nextTaskId; |
| 541 | } |
| 542 | |
Suprabh Shukla | 09a88f5 | 2015-12-02 14:36:31 -0800 | [diff] [blame] | 543 | int getNextTaskIdForUserLocked(int userId) { |
Suprabh Shukla | 09a88f5 | 2015-12-02 14:36:31 -0800 | [diff] [blame] | 544 | final int currentTaskId = mCurTaskIdForUser.get(userId, userId * MAX_TASK_IDS_PER_USER); |
| 545 | // for a userId u, a taskId can only be in the range |
| 546 | // [u*MAX_TASK_IDS_PER_USER, (u+1)*MAX_TASK_IDS_PER_USER-1], so if MAX_TASK_IDS_PER_USER |
| 547 | // 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] | 548 | int candidateTaskId = nextTaskIdForUser(currentTaskId, userId); |
Winson Chung | 1dbc811 | 2017-09-28 18:05:31 -0700 | [diff] [blame] | 549 | while (mRecentTasks.containsTaskId(candidateTaskId, userId) |
Wale Ogunwale | d32da47 | 2018-11-16 07:19:28 -0800 | [diff] [blame] | 550 | || mRootActivityContainer.anyTaskForId( |
Wale Ogunwale | 0568aed | 2017-09-08 13:29:37 -0700 | [diff] [blame] | 551 | candidateTaskId, MATCH_TASK_IN_STACKS_OR_RECENT_TASKS) != null) { |
Chong Zhang | d9d35bd | 2016-08-04 17:55:21 -0700 | [diff] [blame] | 552 | candidateTaskId = nextTaskIdForUser(candidateTaskId, userId); |
Suprabh Shukla | 09a88f5 | 2015-12-02 14:36:31 -0800 | [diff] [blame] | 553 | if (candidateTaskId == currentTaskId) { |
| 554 | // Something wrong! |
| 555 | // All MAX_TASK_IDS_PER_USER task ids are taken up by running tasks for this user |
| 556 | throw new IllegalStateException("Cannot get an available task id." |
| 557 | + " Reached limit of " + MAX_TASK_IDS_PER_USER |
| 558 | + " running tasks per user."); |
| 559 | } |
| 560 | } |
| 561 | mCurTaskIdForUser.put(userId, candidateTaskId); |
| 562 | return candidateTaskId; |
Craig Mautner | 8d341ef | 2013-03-26 09:03:27 -0700 | [diff] [blame] | 563 | } |
| 564 | |
Riddle Hsu | c48c891 | 2019-10-31 13:34:27 +0800 | [diff] [blame] | 565 | void waitActivityVisible(ComponentName name, WaitResult result) { |
| 566 | final WaitInfo waitInfo = new WaitInfo(name, result); |
Bryce Lee | 4a19438 | 2017-04-04 14:32:48 -0700 | [diff] [blame] | 567 | mWaitingForActivityVisible.add(waitInfo); |
| 568 | } |
| 569 | |
| 570 | void cleanupActivity(ActivityRecord r) { |
| 571 | // Make sure this record is no longer in the pending finishes list. |
| 572 | // This could happen, for example, if we are trimming activities |
| 573 | // down to the max limit while they are still waiting to finish. |
| 574 | mFinishingActivities.remove(r); |
Bryce Lee | 4a19438 | 2017-04-04 14:32:48 -0700 | [diff] [blame] | 575 | |
Riddle Hsu | c48c891 | 2019-10-31 13:34:27 +0800 | [diff] [blame] | 576 | stopWaitingForActivityVisible(r, WaitResult.INVALID_DELAY); |
Bryce Lee | 4a19438 | 2017-04-04 14:32:48 -0700 | [diff] [blame] | 577 | } |
| 578 | |
Louis Chang | a59937a | 2019-03-20 17:17:22 +0800 | [diff] [blame] | 579 | void stopWaitingForActivityVisible(ActivityRecord r) { |
Riddle Hsu | c48c891 | 2019-10-31 13:34:27 +0800 | [diff] [blame] | 580 | stopWaitingForActivityVisible(r, |
| 581 | getActivityMetricsLogger().getLastDrawnDelayMs(r.getWindowingMode())); |
| 582 | } |
| 583 | |
| 584 | void stopWaitingForActivityVisible(ActivityRecord r, long totalTime) { |
Dianne Hackborn | 6cfbb71 | 2014-09-17 12:47:35 -0700 | [diff] [blame] | 585 | boolean changed = false; |
Bryce Lee | 4a19438 | 2017-04-04 14:32:48 -0700 | [diff] [blame] | 586 | for (int i = mWaitingForActivityVisible.size() - 1; i >= 0; --i) { |
| 587 | final WaitInfo w = mWaitingForActivityVisible.get(i); |
Wale Ogunwale | 8b19de9 | 2018-11-29 19:58:26 -0800 | [diff] [blame] | 588 | if (w.matches(r.mActivityComponent)) { |
Bryce Lee | 4a19438 | 2017-04-04 14:32:48 -0700 | [diff] [blame] | 589 | final WaitResult result = w.getResult(); |
Dianne Hackborn | 6cfbb71 | 2014-09-17 12:47:35 -0700 | [diff] [blame] | 590 | changed = true; |
Bryce Lee | 4a19438 | 2017-04-04 14:32:48 -0700 | [diff] [blame] | 591 | result.timeout = false; |
| 592 | result.who = w.getComponent(); |
Riddle Hsu | c48c891 | 2019-10-31 13:34:27 +0800 | [diff] [blame] | 593 | result.totalTime = totalTime; |
Bryce Lee | 4a19438 | 2017-04-04 14:32:48 -0700 | [diff] [blame] | 594 | mWaitingForActivityVisible.remove(w); |
Craig Mautner | ce5f3cb | 2013-04-22 08:58:54 -0700 | [diff] [blame] | 595 | } |
Craig Mautner | ce5f3cb | 2013-04-22 08:58:54 -0700 | [diff] [blame] | 596 | } |
Dianne Hackborn | 6cfbb71 | 2014-09-17 12:47:35 -0700 | [diff] [blame] | 597 | if (changed) { |
Wale Ogunwale | f673393 | 2018-06-27 05:14:34 -0700 | [diff] [blame] | 598 | mService.mGlobalLock.notifyAll(); |
Dianne Hackborn | 6cfbb71 | 2014-09-17 12:47:35 -0700 | [diff] [blame] | 599 | } |
Craig Mautner | ce5f3cb | 2013-04-22 08:58:54 -0700 | [diff] [blame] | 600 | } |
| 601 | |
Bryce Lee | 5f0e28f | 2018-01-30 16:00:03 -0800 | [diff] [blame] | 602 | void reportWaitingActivityLaunchedIfNeeded(ActivityRecord r, int result) { |
| 603 | if (mWaitingActivityLaunched.isEmpty()) { |
| 604 | return; |
| 605 | } |
| 606 | |
| 607 | if (result != START_DELIVERED_TO_TOP && result != START_TASK_TO_FRONT) { |
| 608 | return; |
| 609 | } |
| 610 | |
Chong Zhang | 5022da3 | 2016-06-21 16:31:37 -0700 | [diff] [blame] | 611 | boolean changed = false; |
Bryce Lee | 5f0e28f | 2018-01-30 16:00:03 -0800 | [diff] [blame] | 612 | |
Chong Zhang | 5022da3 | 2016-06-21 16:31:37 -0700 | [diff] [blame] | 613 | for (int i = mWaitingActivityLaunched.size() - 1; i >= 0; i--) { |
| 614 | WaitResult w = mWaitingActivityLaunched.remove(i); |
| 615 | if (w.who == null) { |
| 616 | changed = true; |
Bryce Lee | 5f0e28f | 2018-01-30 16:00:03 -0800 | [diff] [blame] | 617 | w.result = result; |
| 618 | |
| 619 | // Unlike START_TASK_TO_FRONT, When an intent is delivered to top, there |
| 620 | // will be no followup launch signals. Assign the result and launched component. |
| 621 | if (result == START_DELIVERED_TO_TOP) { |
Wale Ogunwale | 8b19de9 | 2018-11-29 19:58:26 -0800 | [diff] [blame] | 622 | w.who = r.mActivityComponent; |
Bryce Lee | 5f0e28f | 2018-01-30 16:00:03 -0800 | [diff] [blame] | 623 | } |
Chong Zhang | 5022da3 | 2016-06-21 16:31:37 -0700 | [diff] [blame] | 624 | } |
| 625 | } |
Bryce Lee | 5f0e28f | 2018-01-30 16:00:03 -0800 | [diff] [blame] | 626 | |
Chong Zhang | 5022da3 | 2016-06-21 16:31:37 -0700 | [diff] [blame] | 627 | if (changed) { |
Wale Ogunwale | f673393 | 2018-06-27 05:14:34 -0700 | [diff] [blame] | 628 | mService.mGlobalLock.notifyAll(); |
Chong Zhang | 5022da3 | 2016-06-21 16:31:37 -0700 | [diff] [blame] | 629 | } |
| 630 | } |
| 631 | |
Vishnu Nair | bb9ab4b | 2018-12-13 10:29:46 -0800 | [diff] [blame] | 632 | void reportActivityLaunchedLocked(boolean timeout, ActivityRecord r, long totalTime, |
| 633 | @WaitResult.LaunchState int launchState) { |
Dianne Hackborn | 6cfbb71 | 2014-09-17 12:47:35 -0700 | [diff] [blame] | 634 | boolean changed = false; |
Craig Mautner | ce5f3cb | 2013-04-22 08:58:54 -0700 | [diff] [blame] | 635 | for (int i = mWaitingActivityLaunched.size() - 1; i >= 0; i--) { |
Craig Mautner | c64f73e | 2013-04-24 16:44:56 -0700 | [diff] [blame] | 636 | WaitResult w = mWaitingActivityLaunched.remove(i); |
Dianne Hackborn | 6cfbb71 | 2014-09-17 12:47:35 -0700 | [diff] [blame] | 637 | if (w.who == null) { |
| 638 | changed = true; |
| 639 | w.timeout = timeout; |
| 640 | if (r != null) { |
| 641 | w.who = new ComponentName(r.info.packageName, r.info.name); |
| 642 | } |
Dianne Hackborn | 6cfbb71 | 2014-09-17 12:47:35 -0700 | [diff] [blame] | 643 | w.totalTime = totalTime; |
Vishnu Nair | bb9ab4b | 2018-12-13 10:29:46 -0800 | [diff] [blame] | 644 | w.launchState = launchState; |
Chong Zhang | 5022da3 | 2016-06-21 16:31:37 -0700 | [diff] [blame] | 645 | // Do not modify w.result. |
Craig Mautner | ce5f3cb | 2013-04-22 08:58:54 -0700 | [diff] [blame] | 646 | } |
Craig Mautner | ce5f3cb | 2013-04-22 08:58:54 -0700 | [diff] [blame] | 647 | } |
Dianne Hackborn | 6cfbb71 | 2014-09-17 12:47:35 -0700 | [diff] [blame] | 648 | if (changed) { |
Wale Ogunwale | f673393 | 2018-06-27 05:14:34 -0700 | [diff] [blame] | 649 | mService.mGlobalLock.notifyAll(); |
Dianne Hackborn | 6cfbb71 | 2014-09-17 12:47:35 -0700 | [diff] [blame] | 650 | } |
Craig Mautner | ce5f3cb | 2013-04-22 08:58:54 -0700 | [diff] [blame] | 651 | } |
| 652 | |
Todd Kennedy | 7440f17 | 2015-12-09 14:31:22 -0800 | [diff] [blame] | 653 | ActivityInfo resolveActivity(Intent intent, ResolveInfo rInfo, int startFlags, |
| 654 | ProfilerInfo profilerInfo) { |
| 655 | final ActivityInfo aInfo = rInfo != null ? rInfo.activityInfo : null; |
Craig Mautner | 23ac33b | 2013-04-01 16:26:35 -0700 | [diff] [blame] | 656 | if (aInfo != null) { |
| 657 | // Store the found target back into the intent, because now that |
| 658 | // we have it we never want to do this again. For example, if the |
| 659 | // user navigates back to this point in the history, we should |
| 660 | // always restart the exact same activity. |
| 661 | intent.setComponent(new ComponentName( |
| 662 | aInfo.applicationInfo.packageName, aInfo.name)); |
| 663 | |
| 664 | // Don't debug things in the system process |
Man Cao | cfa78b2 | 2015-06-11 20:14:34 -0700 | [diff] [blame] | 665 | if (!aInfo.processName.equals("system")) { |
Wale Ogunwale | 7056a06 | 2018-10-18 15:02:50 -0700 | [diff] [blame] | 666 | if ((startFlags & (START_FLAG_DEBUG | START_FLAG_NATIVE_DEBUGGING |
| 667 | | START_FLAG_TRACK_ALLOCATION)) != 0 || profilerInfo != null) { |
Vishnu Nair | 006ee3f | 2018-11-09 08:36:01 -0800 | [diff] [blame] | 668 | |
| 669 | // Mimic an AMS synchronous call by passing a message to AMS and wait for AMS |
| 670 | // to notify us that the task has completed. |
| 671 | // TODO(b/80414790) look into further untangling for the situation where the |
| 672 | // caller is on the same thread as the handler we are posting to. |
| 673 | synchronized (mService.mGlobalLock) { |
| 674 | // Post message to AMS. |
| 675 | final Message msg = PooledLambda.obtainMessage( |
| 676 | ActivityManagerInternal::setDebugFlagsForStartingActivity, |
| 677 | mService.mAmInternal, aInfo, startFlags, profilerInfo, |
| 678 | mService.mGlobalLock); |
| 679 | mService.mH.sendMessage(msg); |
| 680 | try { |
| 681 | mService.mGlobalLock.wait(); |
| 682 | } catch (InterruptedException ignore) { |
| 683 | |
| 684 | } |
| 685 | } |
Craig Mautner | 23ac33b | 2013-04-01 16:26:35 -0700 | [diff] [blame] | 686 | } |
| 687 | } |
Todd Kennedy | b3b43130 | 2017-03-20 16:05:48 -0700 | [diff] [blame] | 688 | final String intentLaunchToken = intent.getLaunchToken(); |
| 689 | if (aInfo.launchToken == null && intentLaunchToken != null) { |
| 690 | aInfo.launchToken = intentLaunchToken; |
| 691 | } |
Craig Mautner | 23ac33b | 2013-04-01 16:26:35 -0700 | [diff] [blame] | 692 | } |
| 693 | return aInfo; |
| 694 | } |
| 695 | |
Patrick Baumann | 7838027 | 2018-04-04 10:41:01 -0700 | [diff] [blame] | 696 | ResolveInfo resolveIntent(Intent intent, String resolvedType, int userId, int flags, |
| 697 | int filterCallingUid) { |
Wale Ogunwale | 1f57338 | 2018-12-03 06:42:54 -0800 | [diff] [blame] | 698 | try { |
Riddle Hsu | 2ca561b | 2019-10-08 21:58:58 +0800 | [diff] [blame] | 699 | Trace.traceBegin(TRACE_TAG_WINDOW_MANAGER, "resolveIntent"); |
Wale Ogunwale | 1f57338 | 2018-12-03 06:42:54 -0800 | [diff] [blame] | 700 | int modifiedFlags = flags |
| 701 | | PackageManager.MATCH_DEFAULT_ONLY | ActivityManagerService.STOCK_PM_FLAGS; |
| 702 | if (intent.isWebIntent() |
| 703 | || (intent.getFlags() & Intent.FLAG_ACTIVITY_MATCH_EXTERNAL) != 0) { |
| 704 | modifiedFlags |= PackageManager.MATCH_INSTANT; |
Jorim Jaggi | ffe128d | 2017-11-30 13:54:36 +0100 | [diff] [blame] | 705 | } |
Wale Ogunwale | 1f57338 | 2018-12-03 06:42:54 -0800 | [diff] [blame] | 706 | |
| 707 | // In order to allow cross-profile lookup, we clear the calling identity here. |
| 708 | // Note the binder identity won't affect the result, but filterCallingUid will. |
| 709 | |
| 710 | // Cross-user/profile call check are done at the entry points |
| 711 | // (e.g. AMS.startActivityAsUser). |
| 712 | final long token = Binder.clearCallingIdentity(); |
| 713 | try { |
| 714 | return mService.getPackageManagerInternalLocked().resolveIntent( |
| 715 | intent, resolvedType, modifiedFlags, userId, true, filterCallingUid); |
| 716 | } finally { |
| 717 | Binder.restoreCallingIdentity(token); |
| 718 | } |
| 719 | } finally { |
Riddle Hsu | 2ca561b | 2019-10-08 21:58:58 +0800 | [diff] [blame] | 720 | Trace.traceEnd(TRACE_TAG_WINDOW_MANAGER); |
Todd Kennedy | 7440f17 | 2015-12-09 14:31:22 -0800 | [diff] [blame] | 721 | } |
Todd Kennedy | 7440f17 | 2015-12-09 14:31:22 -0800 | [diff] [blame] | 722 | } |
| 723 | |
| 724 | ActivityInfo resolveActivity(Intent intent, String resolvedType, int startFlags, |
Patrick Baumann | 7838027 | 2018-04-04 10:41:01 -0700 | [diff] [blame] | 725 | ProfilerInfo profilerInfo, int userId, int filterCallingUid) { |
| 726 | final ResolveInfo rInfo = resolveIntent(intent, resolvedType, userId, 0, filterCallingUid); |
Todd Kennedy | 7440f17 | 2015-12-09 14:31:22 -0800 | [diff] [blame] | 727 | return resolveActivity(intent, rInfo, startFlags, profilerInfo); |
| 728 | } |
| 729 | |
Wale Ogunwale | d32da47 | 2018-11-16 07:19:28 -0800 | [diff] [blame] | 730 | boolean realStartActivityLocked(ActivityRecord r, WindowProcessController proc, |
Wale Ogunwale | 5658e4b | 2016-02-12 12:22:19 -0800 | [diff] [blame] | 731 | boolean andResume, boolean checkConfig) throws RemoteException { |
| 732 | |
Wale Ogunwale | d32da47 | 2018-11-16 07:19:28 -0800 | [diff] [blame] | 733 | if (!mRootActivityContainer.allPausedActivitiesComplete()) { |
Wale Ogunwale | 5658e4b | 2016-02-12 12:22:19 -0800 | [diff] [blame] | 734 | // While there are activities pausing we skipping starting any new activities until |
| 735 | // pauses are complete. NOTE: that we also do this for activities that are starting in |
| 736 | // the paused state because they will first be resumed then paused on the client side. |
| 737 | if (DEBUG_SWITCH || DEBUG_PAUSE || DEBUG_STATES) Slog.v(TAG_PAUSE, |
| 738 | "realStartActivityLocked: Skipping start of r=" + r |
| 739 | + " some activities pausing..."); |
| 740 | return false; |
| 741 | } |
Craig Mautner | 2420ead | 2013-04-01 17:13:20 -0700 | [diff] [blame] | 742 | |
Louis Chang | cdec080 | 2019-11-11 11:45:07 +0800 | [diff] [blame] | 743 | final Task task = r.getTask(); |
Andrii Kulian | 02b7a83 | 2016-10-06 23:11:56 -0700 | [diff] [blame] | 744 | final ActivityStack stack = task.getStack(); |
chaviw | 59b9885 | 2017-06-13 12:05:44 -0700 | [diff] [blame] | 745 | |
| 746 | beginDeferResume(); |
| 747 | |
Craig Mautner | 2420ead | 2013-04-01 17:13:20 -0700 | [diff] [blame] | 748 | try { |
Wale Ogunwale | 9e4f3e0 | 2018-05-17 09:35:39 -0700 | [diff] [blame] | 749 | r.startFreezingScreenLocked(proc, 0); |
chaviw | 59b9885 | 2017-06-13 12:05:44 -0700 | [diff] [blame] | 750 | |
| 751 | // schedule launch ticks to collect information about slow apps. |
| 752 | r.startLaunchTickingLocked(); |
| 753 | |
Wale Ogunwale | 9e4f3e0 | 2018-05-17 09:35:39 -0700 | [diff] [blame] | 754 | r.setProcess(proc); |
chaviw | 59b9885 | 2017-06-13 12:05:44 -0700 | [diff] [blame] | 755 | |
Louis Chang | 77ce34d | 2019-01-03 15:45:12 +0800 | [diff] [blame] | 756 | // Ensure activity is allowed to be resumed after process has set. |
| 757 | if (andResume && !r.canResumeByCompat()) { |
| 758 | andResume = false; |
| 759 | } |
| 760 | |
Riddle Hsu | 13c27ae | 2019-10-05 23:10:15 +0800 | [diff] [blame] | 761 | r.notifyUnknownVisibilityLaunchedForKeyguardTransition(); |
Jorim Jaggi | 838c245 | 2017-08-28 15:44:43 +0200 | [diff] [blame] | 762 | |
chaviw | 59b9885 | 2017-06-13 12:05:44 -0700 | [diff] [blame] | 763 | // Have the window manager re-evaluate the orientation of the screen based on the new |
| 764 | // activity order. Note that as a result of this, it can call back into the activity |
| 765 | // manager with a new orientation. We don't care about that, because the activity is |
| 766 | // not currently running so we are just restarting it anyway. |
| 767 | if (checkConfig) { |
chaviw | 59b9885 | 2017-06-13 12:05:44 -0700 | [diff] [blame] | 768 | // Deferring resume here because we're going to launch new activity shortly. |
| 769 | // We don't want to perform a redundant launch of the same record while ensuring |
| 770 | // configurations and trying to resume top activity of focused stack. |
Wale Ogunwale | d32da47 | 2018-11-16 07:19:28 -0800 | [diff] [blame] | 771 | mRootActivityContainer.ensureVisibilityAndConfig(r, r.getDisplayId(), |
Andrii Kulian | f4479ee | 2018-05-23 17:52:48 -0700 | [diff] [blame] | 772 | false /* markFrozenIfConfigChanged */, true /* deferResume */); |
Craig Mautner | 2420ead | 2013-04-01 17:13:20 -0700 | [diff] [blame] | 773 | } |
chaviw | 59b9885 | 2017-06-13 12:05:44 -0700 | [diff] [blame] | 774 | |
Wale Ogunwale | 8b19de9 | 2018-11-29 19:58:26 -0800 | [diff] [blame] | 775 | if (r.getActivityStack().checkKeyguardVisibility(r, true /* shouldBeVisible */, |
Issei Suzuki | 430a111 | 2019-11-14 16:20:52 +0100 | [diff] [blame] | 776 | true /* isTop */)) { |
| 777 | // We only set the visibility to true if the activity is allowed to be visible |
| 778 | // based on |
| 779 | // keyguard state. This avoids setting this into motion in window manager that is |
| 780 | // later cancelled due to later calls to ensure visible activities that set |
| 781 | // visibility back to false. |
chaviw | 59b9885 | 2017-06-13 12:05:44 -0700 | [diff] [blame] | 782 | r.setVisibility(true); |
Craig Mautner | 2420ead | 2013-04-01 17:13:20 -0700 | [diff] [blame] | 783 | } |
chaviw | 59b9885 | 2017-06-13 12:05:44 -0700 | [diff] [blame] | 784 | |
chaviw | 59b9885 | 2017-06-13 12:05:44 -0700 | [diff] [blame] | 785 | final int applicationInfoUid = |
| 786 | (r.info.applicationInfo != null) ? r.info.applicationInfo.uid : -1; |
Andrii Kulian | eceebbf | 2019-06-26 17:36:51 -0700 | [diff] [blame] | 787 | if ((r.mUserId != proc.mUserId) || (r.info.applicationInfo.uid != applicationInfoUid)) { |
chaviw | 59b9885 | 2017-06-13 12:05:44 -0700 | [diff] [blame] | 788 | Slog.wtf(TAG, |
| 789 | "User ID for activity changing for " + r |
Andrii Kulian | eceebbf | 2019-06-26 17:36:51 -0700 | [diff] [blame] | 790 | + " appInfo.uid=" + r.info.applicationInfo.uid |
chaviw | 59b9885 | 2017-06-13 12:05:44 -0700 | [diff] [blame] | 791 | + " info.ai.uid=" + applicationInfoUid |
Wale Ogunwale | 9c10302 | 2018-10-18 07:44:54 -0700 | [diff] [blame] | 792 | + " old=" + r.app + " new=" + proc); |
chaviw | 59b9885 | 2017-06-13 12:05:44 -0700 | [diff] [blame] | 793 | } |
| 794 | |
chaviw | 59b9885 | 2017-06-13 12:05:44 -0700 | [diff] [blame] | 795 | r.launchCount++; |
| 796 | r.lastLaunchTime = SystemClock.uptimeMillis(); |
| 797 | |
| 798 | if (DEBUG_ALL) Slog.v(TAG, "Launching: " + r); |
| 799 | |
Wale Ogunwale | 9e4f3e0 | 2018-05-17 09:35:39 -0700 | [diff] [blame] | 800 | proc.addActivityIfNeeded(r); |
chaviw | 59b9885 | 2017-06-13 12:05:44 -0700 | [diff] [blame] | 801 | |
Wale Ogunwale | c9e57de | 2018-05-08 14:28:07 -0700 | [diff] [blame] | 802 | final LockTaskController lockTaskController = mService.getLockTaskController(); |
Charles He | ff9b4dff | 2017-09-22 10:18:37 +0100 | [diff] [blame] | 803 | if (task.mLockTaskAuth == LOCK_TASK_AUTH_LAUNCHABLE |
| 804 | || task.mLockTaskAuth == LOCK_TASK_AUTH_LAUNCHABLE_PRIV |
| 805 | || (task.mLockTaskAuth == LOCK_TASK_AUTH_WHITELISTED |
Bryce Lee | 2b8e037 | 2018-04-05 17:01:37 -0700 | [diff] [blame] | 806 | && lockTaskController.getLockTaskModeState() |
| 807 | == LOCK_TASK_MODE_LOCKED)) { |
| 808 | lockTaskController.startLockTaskMode(task, false, 0 /* blank UID */); |
chaviw | 59b9885 | 2017-06-13 12:05:44 -0700 | [diff] [blame] | 809 | } |
| 810 | |
| 811 | try { |
Wale Ogunwale | 9c10302 | 2018-10-18 07:44:54 -0700 | [diff] [blame] | 812 | if (!proc.hasThread()) { |
chaviw | 59b9885 | 2017-06-13 12:05:44 -0700 | [diff] [blame] | 813 | throw new RemoteException(); |
| 814 | } |
| 815 | List<ResultInfo> results = null; |
| 816 | List<ReferrerIntent> newIntents = null; |
| 817 | if (andResume) { |
| 818 | // We don't need to deliver new intents and/or set results if activity is going |
| 819 | // to pause immediately after launch. |
| 820 | results = r.results; |
| 821 | newIntents = r.newIntents; |
| 822 | } |
| 823 | if (DEBUG_SWITCH) Slog.v(TAG_SWITCH, |
Andrii Kulian | 06b8dcb | 2019-07-10 21:09:38 -0700 | [diff] [blame] | 824 | "Launching: " + r + " savedState=" + r.getSavedState() |
| 825 | + " with results=" + results + " newIntents=" + newIntents |
| 826 | + " andResume=" + andResume); |
Wale Ogunwale | 8b19de9 | 2018-11-29 19:58:26 -0800 | [diff] [blame] | 827 | EventLog.writeEvent(EventLogTags.AM_RESTART_ACTIVITY, r.mUserId, |
Wale Ogunwale | 4e79a1c | 2019-10-05 20:52:40 -0700 | [diff] [blame] | 828 | System.identityHashCode(r), task.mTaskId, r.shortComponentName); |
Wale Ogunwale | 6fbde9f | 2017-08-24 07:24:12 -0700 | [diff] [blame] | 829 | if (r.isActivityTypeHome()) { |
chaviw | 59b9885 | 2017-06-13 12:05:44 -0700 | [diff] [blame] | 830 | // Home process is the root process of the task. |
Wale Ogunwale | 1a06f15 | 2019-10-11 11:26:30 +0200 | [diff] [blame] | 831 | updateHomeProcess(task.getChildAt(0).app); |
chaviw | 59b9885 | 2017-06-13 12:05:44 -0700 | [diff] [blame] | 832 | } |
Wale Ogunwale | 214f348 | 2018-10-04 11:00:47 -0700 | [diff] [blame] | 833 | mService.getPackageManagerInternalLocked().notifyPackageUse( |
| 834 | r.intent.getComponent().getPackageName(), NOTIFY_PACKAGE_USE_ACTIVITY); |
chaviw | 59b9885 | 2017-06-13 12:05:44 -0700 | [diff] [blame] | 835 | r.sleeping = false; |
| 836 | r.forceNewConfig = false; |
Wale Ogunwale | 008163e | 2018-07-23 23:11:08 -0700 | [diff] [blame] | 837 | mService.getAppWarningsLocked().onStartActivity(r); |
Wale Ogunwale | 5378374 | 2018-09-16 10:21:51 -0700 | [diff] [blame] | 838 | r.compat = mService.compatibilityInfoForPackageLocked(r.info.applicationInfo); |
chaviw | 59b9885 | 2017-06-13 12:05:44 -0700 | [diff] [blame] | 839 | |
chaviw | 59b9885 | 2017-06-13 12:05:44 -0700 | [diff] [blame] | 840 | // Because we could be starting an Activity in the system process this may not go |
| 841 | // across a Binder interface which would create a new Configuration. Consequently |
| 842 | // we have to always create a new Configuration here. |
Bryce Lee | a163b76 | 2017-01-24 11:05:01 -0800 | [diff] [blame] | 843 | |
chaviw | 59b9885 | 2017-06-13 12:05:44 -0700 | [diff] [blame] | 844 | final MergedConfiguration mergedConfiguration = new MergedConfiguration( |
Wale Ogunwale | 9c10302 | 2018-10-18 07:44:54 -0700 | [diff] [blame] | 845 | proc.getConfiguration(), r.getMergedOverrideConfiguration()); |
chaviw | 59b9885 | 2017-06-13 12:05:44 -0700 | [diff] [blame] | 846 | r.setLastReportedConfiguration(mergedConfiguration); |
Bryce Lee | a163b76 | 2017-01-24 11:05:01 -0800 | [diff] [blame] | 847 | |
Andrii Kulian | 06b8dcb | 2019-07-10 21:09:38 -0700 | [diff] [blame] | 848 | logIfTransactionTooLarge(r.intent, r.getSavedState()); |
Andrii Kulian | 88e05cb | 2017-12-05 17:21:10 -0800 | [diff] [blame] | 849 | |
| 850 | |
| 851 | // Create activity launch transaction. |
Wale Ogunwale | 9c10302 | 2018-10-18 07:44:54 -0700 | [diff] [blame] | 852 | final ClientTransaction clientTransaction = ClientTransaction.obtain( |
| 853 | proc.getThread(), r.appToken); |
lumark | 588a3e8 | 2018-07-20 18:53:54 +0800 | [diff] [blame] | 854 | |
Wale Ogunwale | 3a256e6 | 2018-12-06 14:41:18 -0800 | [diff] [blame] | 855 | final DisplayContent dc = r.getDisplay().mDisplayContent; |
Andrii Kulian | 9c5ea9c | 2017-12-07 09:31:01 -0800 | [diff] [blame] | 856 | clientTransaction.addCallback(LaunchActivityItem.obtain(new Intent(r.intent), |
chaviw | 59b9885 | 2017-06-13 12:05:44 -0700 | [diff] [blame] | 857 | System.identityHashCode(r), r.info, |
| 858 | // TODO: Have this take the merged configuration instead of separate global |
| 859 | // and override configs. |
| 860 | mergedConfiguration.getGlobalConfiguration(), |
| 861 | mergedConfiguration.getOverrideConfiguration(), r.compat, |
Wale Ogunwale | 9c10302 | 2018-10-18 07:44:54 -0700 | [diff] [blame] | 862 | r.launchedFromPackage, task.voiceInteractor, proc.getReportedProcState(), |
Andrii Kulian | 06b8dcb | 2019-07-10 21:09:38 -0700 | [diff] [blame] | 863 | r.getSavedState(), r.getPersistentSavedState(), results, newIntents, |
Sunny Goyal | d40c345 | 2019-03-20 12:46:55 -0700 | [diff] [blame] | 864 | dc.isNextTransitionForward(), proc.createProfilerInfoIfNeeded(), |
| 865 | r.assistToken)); |
Andrii Kulian | 88e05cb | 2017-12-05 17:21:10 -0800 | [diff] [blame] | 866 | |
| 867 | // Set desired final state. |
| 868 | final ActivityLifecycleItem lifecycleItem; |
| 869 | if (andResume) { |
Wale Ogunwale | 3a256e6 | 2018-12-06 14:41:18 -0800 | [diff] [blame] | 870 | lifecycleItem = ResumeActivityItem.obtain(dc.isNextTransitionForward()); |
Andrii Kulian | 88e05cb | 2017-12-05 17:21:10 -0800 | [diff] [blame] | 871 | } else { |
Bryce Lee | 1d0d514 | 2018-04-12 10:35:07 -0700 | [diff] [blame] | 872 | lifecycleItem = PauseActivityItem.obtain(); |
Andrii Kulian | 88e05cb | 2017-12-05 17:21:10 -0800 | [diff] [blame] | 873 | } |
| 874 | clientTransaction.setLifecycleStateRequest(lifecycleItem); |
| 875 | |
| 876 | // Schedule transaction. |
Wale Ogunwale | c9e57de | 2018-05-08 14:28:07 -0700 | [diff] [blame] | 877 | mService.getLifecycleManager().scheduleTransaction(clientTransaction); |
Craig Mautner | 2420ead | 2013-04-01 17:13:20 -0700 | [diff] [blame] | 878 | |
Wale Ogunwale | 9c10302 | 2018-10-18 07:44:54 -0700 | [diff] [blame] | 879 | if ((proc.mInfo.privateFlags & ApplicationInfo.PRIVATE_FLAG_CANT_SAVE_STATE) != 0 |
Wale Ogunwale | 214f348 | 2018-10-04 11:00:47 -0700 | [diff] [blame] | 880 | && mService.mHasHeavyWeightFeature) { |
Wale Ogunwale | 5378374 | 2018-09-16 10:21:51 -0700 | [diff] [blame] | 881 | // This may be a heavy-weight process! Note that the package manager will ensure |
| 882 | // that only activity can run in the main process of the .apk, which is the only |
| 883 | // thing that will be considered heavy-weight. |
Wale Ogunwale | 9c10302 | 2018-10-18 07:44:54 -0700 | [diff] [blame] | 884 | if (proc.mName.equals(proc.mInfo.packageName)) { |
Wale Ogunwale | 5378374 | 2018-09-16 10:21:51 -0700 | [diff] [blame] | 885 | if (mService.mHeavyWeightProcess != null |
| 886 | && mService.mHeavyWeightProcess != proc) { |
| 887 | Slog.w(TAG, "Starting new heavy weight process " + proc |
chaviw | 59b9885 | 2017-06-13 12:05:44 -0700 | [diff] [blame] | 888 | + " when already running " |
Wale Ogunwale | 5378374 | 2018-09-16 10:21:51 -0700 | [diff] [blame] | 889 | + mService.mHeavyWeightProcess); |
chaviw | 59b9885 | 2017-06-13 12:05:44 -0700 | [diff] [blame] | 890 | } |
Wale Ogunwale | 5378374 | 2018-09-16 10:21:51 -0700 | [diff] [blame] | 891 | mService.setHeavyWeightProcess(r); |
Craig Mautner | 2420ead | 2013-04-01 17:13:20 -0700 | [diff] [blame] | 892 | } |
Craig Mautner | 2420ead | 2013-04-01 17:13:20 -0700 | [diff] [blame] | 893 | } |
Craig Mautner | 2420ead | 2013-04-01 17:13:20 -0700 | [diff] [blame] | 894 | |
chaviw | 59b9885 | 2017-06-13 12:05:44 -0700 | [diff] [blame] | 895 | } catch (RemoteException e) { |
| 896 | if (r.launchFailed) { |
Wale Ogunwale | 9c10302 | 2018-10-18 07:44:54 -0700 | [diff] [blame] | 897 | // This is the second time we failed -- finish activity and give up. |
chaviw | 59b9885 | 2017-06-13 12:05:44 -0700 | [diff] [blame] | 898 | Slog.e(TAG, "Second failure launching " |
Wale Ogunwale | 9c10302 | 2018-10-18 07:44:54 -0700 | [diff] [blame] | 899 | + r.intent.getComponent().flattenToShortString() + ", giving up", e); |
| 900 | proc.appDied(); |
Andrii Kulian | 7dd39bb | 2019-07-22 13:11:10 -0700 | [diff] [blame] | 901 | r.finishIfPossible("2nd-crash", false /* oomAdj */); |
chaviw | 59b9885 | 2017-06-13 12:05:44 -0700 | [diff] [blame] | 902 | return false; |
| 903 | } |
Craig Mautner | 2420ead | 2013-04-01 17:13:20 -0700 | [diff] [blame] | 904 | |
chaviw | 59b9885 | 2017-06-13 12:05:44 -0700 | [diff] [blame] | 905 | // This is the first time we failed -- restart process and |
| 906 | // retry. |
| 907 | r.launchFailed = true; |
Wale Ogunwale | 9e4f3e0 | 2018-05-17 09:35:39 -0700 | [diff] [blame] | 908 | proc.removeActivity(r); |
chaviw | 59b9885 | 2017-06-13 12:05:44 -0700 | [diff] [blame] | 909 | throw e; |
| 910 | } |
| 911 | } finally { |
| 912 | endDeferResume(); |
Craig Mautner | 2420ead | 2013-04-01 17:13:20 -0700 | [diff] [blame] | 913 | } |
| 914 | |
| 915 | r.launchFailed = false; |
Riddle Hsu | 5477b57 | 2019-11-12 16:07:29 +0800 | [diff] [blame] | 916 | if (stack.updateLruList(r)) { |
Filip Gruszczynski | 49b80af | 2015-09-24 09:04:26 -0700 | [diff] [blame] | 917 | Slog.w(TAG, "Activity " + r + " being launched, but already in LRU list"); |
Craig Mautner | 2420ead | 2013-04-01 17:13:20 -0700 | [diff] [blame] | 918 | } |
| 919 | |
Andrii Kulian | b372da6 | 2018-01-18 10:46:24 -0800 | [diff] [blame] | 920 | // TODO(lifecycler): Resume or pause requests are done as part of launch transaction, |
| 921 | // so updating the state should be done accordingly. |
chaviw | 59b9885 | 2017-06-13 12:05:44 -0700 | [diff] [blame] | 922 | if (andResume && readyToResume()) { |
Craig Mautner | 2420ead | 2013-04-01 17:13:20 -0700 | [diff] [blame] | 923 | // As part of the process of launching, ActivityThread also performs |
| 924 | // a resume. |
| 925 | stack.minimalResumeActivityLocked(r); |
| 926 | } else { |
Wale Ogunwale | d046a01 | 2015-12-24 13:05:59 -0800 | [diff] [blame] | 927 | // 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] | 928 | // 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] | 929 | // current icicle and other state. |
Wale Ogunwale | 0fc365c | 2015-05-25 19:35:42 -0700 | [diff] [blame] | 930 | if (DEBUG_STATES) Slog.v(TAG_STATES, |
Wale Ogunwale | d046a01 | 2015-12-24 13:05:59 -0800 | [diff] [blame] | 931 | "Moving to PAUSED: " + r + " (starting in paused state)"); |
Bryce Lee | 7ace395 | 2018-02-16 14:34:32 -0800 | [diff] [blame] | 932 | r.setState(PAUSED, "realStartActivityLocked"); |
Craig Mautner | 2420ead | 2013-04-01 17:13:20 -0700 | [diff] [blame] | 933 | } |
Riddle Hsu | 17e3842 | 2019-04-12 16:55:11 +0800 | [diff] [blame] | 934 | // Perform OOM scoring after the activity state is set, so the process can be updated with |
| 935 | // the latest state. |
| 936 | proc.onStartActivity(mService.mTopProcessState, r.info); |
Craig Mautner | 2420ead | 2013-04-01 17:13:20 -0700 | [diff] [blame] | 937 | |
| 938 | // Launch the new version setup screen if needed. We do this -after- |
| 939 | // launching the initial activity (that is, home), so that it can have |
| 940 | // a chance to initialize itself while in the background, making the |
| 941 | // switch back to it faster and look better. |
Wale Ogunwale | d32da47 | 2018-11-16 07:19:28 -0800 | [diff] [blame] | 942 | if (mRootActivityContainer.isTopDisplayFocusedStack(stack)) { |
Wale Ogunwale | c9e57de | 2018-05-08 14:28:07 -0700 | [diff] [blame] | 943 | mService.getActivityStartController().startSetupActivity(); |
Craig Mautner | 2420ead | 2013-04-01 17:13:20 -0700 | [diff] [blame] | 944 | } |
| 945 | |
Dianne Hackborn | 465fa39 | 2014-09-14 14:21:18 -0700 | [diff] [blame] | 946 | // Update any services we are bound to that might care about whether |
| 947 | // their client may have activities. |
Wale Ogunwale | d6ac762 | 2016-05-26 09:02:25 -0700 | [diff] [blame] | 948 | if (r.app != null) { |
Wale Ogunwale | 9e4f3e0 | 2018-05-17 09:35:39 -0700 | [diff] [blame] | 949 | r.app.updateServiceConnectionActivities(); |
Wale Ogunwale | d6ac762 | 2016-05-26 09:02:25 -0700 | [diff] [blame] | 950 | } |
Dianne Hackborn | 465fa39 | 2014-09-14 14:21:18 -0700 | [diff] [blame] | 951 | |
Craig Mautner | 2420ead | 2013-04-01 17:13:20 -0700 | [diff] [blame] | 952 | return true; |
| 953 | } |
| 954 | |
Louis Chang | dcdde95 | 2018-12-04 15:38:44 +0800 | [diff] [blame] | 955 | void updateHomeProcess(WindowProcessController app) { |
| 956 | if (app != null && mService.mHomeProcess != app) { |
| 957 | if (!mHandler.hasMessages(REPORT_HOME_CHANGED_MSG)) { |
| 958 | mHandler.sendEmptyMessage(REPORT_HOME_CHANGED_MSG); |
| 959 | } |
| 960 | mService.mHomeProcess = app; |
| 961 | } |
| 962 | } |
| 963 | |
Sudheer Shanka | fab200f | 2017-05-17 20:41:53 -0700 | [diff] [blame] | 964 | private void logIfTransactionTooLarge(Intent intent, Bundle icicle) { |
| 965 | int extrasSize = 0; |
| 966 | if (intent != null) { |
| 967 | final Bundle extras = intent.getExtras(); |
| 968 | if (extras != null) { |
| 969 | extrasSize = extras.getSize(); |
| 970 | } |
| 971 | } |
| 972 | int icicleSize = (icicle == null ? 0 : icicle.getSize()); |
| 973 | if (extrasSize + icicleSize > 200000) { |
| 974 | Slog.e(TAG, "Transaction too large, intent: " + intent + ", extras size: " + extrasSize |
| 975 | + ", icicle size: " + icicleSize); |
| 976 | } |
| 977 | } |
| 978 | |
Wale Ogunwale | 9c10302 | 2018-10-18 07:44:54 -0700 | [diff] [blame] | 979 | void startSpecificActivityLocked(ActivityRecord r, boolean andResume, boolean checkConfig) { |
Craig Mautner | e79d4268 | 2013-04-01 19:01:53 -0700 | [diff] [blame] | 980 | // Is this activity's application already running? |
Wale Ogunwale | 9c10302 | 2018-10-18 07:44:54 -0700 | [diff] [blame] | 981 | final WindowProcessController wpc = |
| 982 | mService.getProcessController(r.processName, r.info.applicationInfo.uid); |
Craig Mautner | e79d4268 | 2013-04-01 19:01:53 -0700 | [diff] [blame] | 983 | |
Chilun | 917173f | 2019-01-04 16:47:42 +0800 | [diff] [blame] | 984 | boolean knownToBeDead = false; |
Wale Ogunwale | 9c10302 | 2018-10-18 07:44:54 -0700 | [diff] [blame] | 985 | if (wpc != null && wpc.hasThread()) { |
Craig Mautner | e79d4268 | 2013-04-01 19:01:53 -0700 | [diff] [blame] | 986 | try { |
Wale Ogunwale | 9c10302 | 2018-10-18 07:44:54 -0700 | [diff] [blame] | 987 | realStartActivityLocked(r, wpc, andResume, checkConfig); |
Craig Mautner | e79d4268 | 2013-04-01 19:01:53 -0700 | [diff] [blame] | 988 | return; |
| 989 | } catch (RemoteException e) { |
| 990 | Slog.w(TAG, "Exception when starting activity " |
| 991 | + r.intent.getComponent().flattenToShortString(), e); |
| 992 | } |
| 993 | |
| 994 | // If a dead object exception was thrown -- fall through to |
| 995 | // restart the application. |
Chilun | 917173f | 2019-01-04 16:47:42 +0800 | [diff] [blame] | 996 | knownToBeDead = true; |
Craig Mautner | e79d4268 | 2013-04-01 19:01:53 -0700 | [diff] [blame] | 997 | } |
| 998 | |
Riddle Hsu | 13c27ae | 2019-10-05 23:10:15 +0800 | [diff] [blame] | 999 | r.notifyUnknownVisibilityLaunchedForKeyguardTransition(); |
Issei Suzuki | 5205af7 | 2018-11-09 11:51:59 +0100 | [diff] [blame] | 1000 | |
Riddle Hsu | 32dbdca | 2019-05-17 23:10:16 -0600 | [diff] [blame] | 1001 | final boolean isTop = andResume && r.isTopRunningActivity(); |
| 1002 | mService.startProcessAsync(r, knownToBeDead, isTop, isTop ? "top-activity" : "activity"); |
Craig Mautner | e79d4268 | 2013-04-01 19:01:53 -0700 | [diff] [blame] | 1003 | } |
| 1004 | |
Wale Ogunwale | 342fbe9 | 2018-10-09 08:44:10 -0700 | [diff] [blame] | 1005 | boolean checkStartAnyActivityPermission(Intent intent, ActivityInfo aInfo, String resultWho, |
| 1006 | int requestCode, int callingPid, int callingUid, String callingPackage, |
| 1007 | boolean ignoreTargetSecurity, boolean launchingInTask, |
| 1008 | WindowProcessController callerApp, ActivityRecord resultRecord, |
| 1009 | ActivityStack resultStack) { |
Wale Ogunwale | c9e57de | 2018-05-08 14:28:07 -0700 | [diff] [blame] | 1010 | final boolean isCallerRecents = mService.getRecentTasks() != null |
| 1011 | && mService.getRecentTasks().isCallerRecents(callingUid); |
Wale Ogunwale | f673393 | 2018-06-27 05:14:34 -0700 | [diff] [blame] | 1012 | final int startAnyPerm = mService.checkPermission(START_ANY_ACTIVITY, callingPid, |
Filip Gruszczynski | dc39490 | 2015-12-14 10:20:22 -0800 | [diff] [blame] | 1013 | callingUid); |
Winson Chung | c9804e7 | 2018-05-15 11:01:44 -0700 | [diff] [blame] | 1014 | if (startAnyPerm == PERMISSION_GRANTED || (isCallerRecents && launchingInTask)) { |
| 1015 | // If the caller has START_ANY_ACTIVITY, ignore all checks below. In addition, if the |
| 1016 | // caller is the recents component and we are specifically starting an activity in an |
| 1017 | // existing task, then also allow the activity to be fully relaunched. |
Filip Gruszczynski | dc39490 | 2015-12-14 10:20:22 -0800 | [diff] [blame] | 1018 | return true; |
| 1019 | } |
| 1020 | final int componentRestriction = getComponentRestrictionForCallingPackage( |
| 1021 | aInfo, callingPackage, callingPid, callingUid, ignoreTargetSecurity); |
| 1022 | final int actionRestriction = getActionRestrictionForCallingPackage( |
| 1023 | intent.getAction(), callingPackage, callingPid, callingUid); |
| 1024 | if (componentRestriction == ACTIVITY_RESTRICTION_PERMISSION |
| 1025 | || actionRestriction == ACTIVITY_RESTRICTION_PERMISSION) { |
| 1026 | if (resultRecord != null) { |
Andrii Kulian | 79d6798 | 2019-08-19 11:56:16 -0700 | [diff] [blame] | 1027 | resultRecord.sendResult(INVALID_UID, resultWho, requestCode, |
| 1028 | Activity.RESULT_CANCELED, null /* data */); |
Filip Gruszczynski | dc39490 | 2015-12-14 10:20:22 -0800 | [diff] [blame] | 1029 | } |
| 1030 | final String msg; |
| 1031 | if (actionRestriction == ACTIVITY_RESTRICTION_PERMISSION) { |
| 1032 | msg = "Permission Denial: starting " + intent.toString() |
| 1033 | + " from " + callerApp + " (pid=" + callingPid |
| 1034 | + ", uid=" + callingUid + ")" + " with revoked permission " |
| 1035 | + ACTION_TO_RUNTIME_PERMISSION.get(intent.getAction()); |
| 1036 | } else if (!aInfo.exported) { |
| 1037 | msg = "Permission Denial: starting " + intent.toString() |
| 1038 | + " from " + callerApp + " (pid=" + callingPid |
| 1039 | + ", uid=" + callingUid + ")" |
| 1040 | + " not exported from uid " + aInfo.applicationInfo.uid; |
| 1041 | } else { |
| 1042 | msg = "Permission Denial: starting " + intent.toString() |
| 1043 | + " from " + callerApp + " (pid=" + callingPid |
| 1044 | + ", uid=" + callingUid + ")" |
| 1045 | + " requires " + aInfo.permission; |
| 1046 | } |
| 1047 | Slog.w(TAG, msg); |
| 1048 | throw new SecurityException(msg); |
| 1049 | } |
| 1050 | |
| 1051 | if (actionRestriction == ACTIVITY_RESTRICTION_APPOP) { |
| 1052 | final String message = "Appop Denial: starting " + intent.toString() |
| 1053 | + " from " + callerApp + " (pid=" + callingPid |
| 1054 | + ", uid=" + callingUid + ")" |
| 1055 | + " requires " + AppOpsManager.permissionToOp( |
| 1056 | ACTION_TO_RUNTIME_PERMISSION.get(intent.getAction())); |
| 1057 | Slog.w(TAG, message); |
| 1058 | return false; |
| 1059 | } else if (componentRestriction == ACTIVITY_RESTRICTION_APPOP) { |
| 1060 | final String message = "Appop Denial: starting " + intent.toString() |
| 1061 | + " from " + callerApp + " (pid=" + callingPid |
| 1062 | + ", uid=" + callingUid + ")" |
| 1063 | + " requires appop " + AppOpsManager.permissionToOp(aInfo.permission); |
| 1064 | Slog.w(TAG, message); |
| 1065 | return false; |
| 1066 | } |
Jorim Jaggi | 2adba07 | 2016-03-03 13:43:39 +0100 | [diff] [blame] | 1067 | |
Filip Gruszczynski | dc39490 | 2015-12-14 10:20:22 -0800 | [diff] [blame] | 1068 | return true; |
| 1069 | } |
| 1070 | |
Andrii Kulian | fb1bf69 | 2017-01-17 11:17:34 -0800 | [diff] [blame] | 1071 | /** Check if caller is allowed to launch activities on specified display. */ |
Andrii Kulian | 02689a7 | 2017-07-06 14:28:59 -0700 | [diff] [blame] | 1072 | boolean isCallerAllowedToLaunchOnDisplay(int callingPid, int callingUid, int launchDisplayId, |
| 1073 | ActivityInfo aInfo) { |
Andrii Kulian | fb1bf69 | 2017-01-17 11:17:34 -0800 | [diff] [blame] | 1074 | if (DEBUG_TASKS) Slog.d(TAG, "Launch on display check: displayId=" + launchDisplayId |
| 1075 | + " callingPid=" + callingPid + " callingUid=" + callingUid); |
| 1076 | |
Andrii Kulian | 02689a7 | 2017-07-06 14:28:59 -0700 | [diff] [blame] | 1077 | if (callingPid == -1 && callingUid == -1) { |
| 1078 | if (DEBUG_TASKS) Slog.d(TAG, "Launch on display check: no caller info, skip check"); |
| 1079 | return true; |
| 1080 | } |
| 1081 | |
Wale Ogunwale | d32da47 | 2018-11-16 07:19:28 -0800 | [diff] [blame] | 1082 | final ActivityDisplay activityDisplay = |
| 1083 | mRootActivityContainer.getActivityDisplayOrCreate(launchDisplayId); |
Louis Chang | 7d0037c | 2018-08-13 12:42:06 +0800 | [diff] [blame] | 1084 | if (activityDisplay == null || activityDisplay.isRemoved()) { |
Andrii Kulian | fb1bf69 | 2017-01-17 11:17:34 -0800 | [diff] [blame] | 1085 | Slog.w(TAG, "Launch on display check: display not found"); |
| 1086 | return false; |
| 1087 | } |
| 1088 | |
Andrii Kulian | 02689a7 | 2017-07-06 14:28:59 -0700 | [diff] [blame] | 1089 | // Check if the caller has enough privileges to embed activities and launch to private |
| 1090 | // displays. |
Wale Ogunwale | f673393 | 2018-06-27 05:14:34 -0700 | [diff] [blame] | 1091 | final int startAnyPerm = mService.checkPermission(INTERNAL_SYSTEM_WINDOW, callingPid, |
Andrii Kulian | 1cba31c | 2017-06-28 09:42:48 -0700 | [diff] [blame] | 1092 | callingUid); |
| 1093 | if (startAnyPerm == PERMISSION_GRANTED) { |
| 1094 | if (DEBUG_TASKS) Slog.d(TAG, "Launch on display check:" |
| 1095 | + " allow launch any on display"); |
| 1096 | return true; |
| 1097 | } |
| 1098 | |
Andrii Kulian | 8f07029 | 2017-09-12 22:56:49 -0700 | [diff] [blame] | 1099 | // Check if caller is already present on display |
| 1100 | final boolean uidPresentOnDisplay = activityDisplay.isUidPresent(callingUid); |
| 1101 | |
Andrii Kulian | 3c9ad07 | 2017-08-01 11:45:22 -0700 | [diff] [blame] | 1102 | final int displayOwnerUid = activityDisplay.mDisplay.getOwnerUid(); |
| 1103 | if (activityDisplay.mDisplay.getType() == TYPE_VIRTUAL && displayOwnerUid != SYSTEM_UID |
| 1104 | && displayOwnerUid != aInfo.applicationInfo.uid) { |
Andrii Kulian | 1cba31c | 2017-06-28 09:42:48 -0700 | [diff] [blame] | 1105 | // Limit launching on virtual displays, because their contents can be read from Surface |
| 1106 | // by apps that created them. |
Andrii Kulian | 02689a7 | 2017-07-06 14:28:59 -0700 | [diff] [blame] | 1107 | if ((aInfo.flags & ActivityInfo.FLAG_ALLOW_EMBEDDED) == 0) { |
| 1108 | if (DEBUG_TASKS) Slog.d(TAG, "Launch on display check:" |
| 1109 | + " disallow launch on virtual display for not-embedded activity."); |
| 1110 | return false; |
| 1111 | } |
Andrii Kulian | 3c9ad07 | 2017-08-01 11:45:22 -0700 | [diff] [blame] | 1112 | // Check if the caller is allowed to embed activities from other apps. |
Wale Ogunwale | f673393 | 2018-06-27 05:14:34 -0700 | [diff] [blame] | 1113 | if (mService.checkPermission(ACTIVITY_EMBEDDING, callingPid, callingUid) |
Andrii Kulian | 8f07029 | 2017-09-12 22:56:49 -0700 | [diff] [blame] | 1114 | == PERMISSION_DENIED && !uidPresentOnDisplay) { |
Andrii Kulian | 3c9ad07 | 2017-08-01 11:45:22 -0700 | [diff] [blame] | 1115 | if (DEBUG_TASKS) Slog.d(TAG, "Launch on display check:" |
| 1116 | + " disallow activity embedding without permission."); |
| 1117 | return false; |
| 1118 | } |
Andrii Kulian | 1cba31c | 2017-06-28 09:42:48 -0700 | [diff] [blame] | 1119 | } |
| 1120 | |
Andrii Kulian | fb1bf69 | 2017-01-17 11:17:34 -0800 | [diff] [blame] | 1121 | if (!activityDisplay.isPrivate()) { |
| 1122 | // Anyone can launch on a public display. |
| 1123 | if (DEBUG_TASKS) Slog.d(TAG, "Launch on display check:" |
| 1124 | + " allow launch on public display"); |
| 1125 | return true; |
| 1126 | } |
| 1127 | |
| 1128 | // Check if the caller is the owner of the display. |
Andrii Kulian | 3c9ad07 | 2017-08-01 11:45:22 -0700 | [diff] [blame] | 1129 | if (displayOwnerUid == callingUid) { |
Andrii Kulian | fb1bf69 | 2017-01-17 11:17:34 -0800 | [diff] [blame] | 1130 | if (DEBUG_TASKS) Slog.d(TAG, "Launch on display check:" |
| 1131 | + " allow launch for owner of the display"); |
| 1132 | return true; |
| 1133 | } |
| 1134 | |
Andrii Kulian | 8f07029 | 2017-09-12 22:56:49 -0700 | [diff] [blame] | 1135 | if (uidPresentOnDisplay) { |
Andrii Kulian | fb1bf69 | 2017-01-17 11:17:34 -0800 | [diff] [blame] | 1136 | if (DEBUG_TASKS) Slog.d(TAG, "Launch on display check:" |
| 1137 | + " allow launch for caller present on the display"); |
| 1138 | return true; |
| 1139 | } |
| 1140 | |
Andrii Kulian | fb1bf69 | 2017-01-17 11:17:34 -0800 | [diff] [blame] | 1141 | Slog.w(TAG, "Launch on display check: denied"); |
| 1142 | return false; |
| 1143 | } |
| 1144 | |
Filip Gruszczynski | 07a0e49 | 2015-12-17 14:16:38 -0800 | [diff] [blame] | 1145 | UserInfo getUserInfo(int userId) { |
Clara Bayarri | f7fea16 | 2015-10-22 16:09:52 +0100 | [diff] [blame] | 1146 | final long identity = Binder.clearCallingIdentity(); |
| 1147 | try { |
| 1148 | return UserManager.get(mService.mContext).getUserInfo(userId); |
| 1149 | } finally { |
| 1150 | Binder.restoreCallingIdentity(identity); |
| 1151 | } |
| 1152 | } |
| 1153 | |
Svet Ganov | 99b6043 | 2015-06-27 13:15:22 -0700 | [diff] [blame] | 1154 | private int getComponentRestrictionForCallingPackage(ActivityInfo activityInfo, |
Dianne Hackborn | a7cfbe0 | 2015-07-16 10:52:52 -0700 | [diff] [blame] | 1155 | String callingPackage, int callingPid, int callingUid, boolean ignoreTargetSecurity) { |
Wale Ogunwale | 214f348 | 2018-10-04 11:00:47 -0700 | [diff] [blame] | 1156 | if (!ignoreTargetSecurity && mService.checkComponentPermission(activityInfo.permission, |
Dianne Hackborn | a7cfbe0 | 2015-07-16 10:52:52 -0700 | [diff] [blame] | 1157 | callingPid, callingUid, activityInfo.applicationInfo.uid, activityInfo.exported) |
Andrii Kulian | 3c9ad07 | 2017-08-01 11:45:22 -0700 | [diff] [blame] | 1158 | == PERMISSION_DENIED) { |
Svet Ganov | 99b6043 | 2015-06-27 13:15:22 -0700 | [diff] [blame] | 1159 | return ACTIVITY_RESTRICTION_PERMISSION; |
| 1160 | } |
| 1161 | |
Christopher Tate | ff7add0 | 2015-08-17 10:23:22 -0700 | [diff] [blame] | 1162 | if (activityInfo.permission == null) { |
| 1163 | return ACTIVITY_RESTRICTION_NONE; |
| 1164 | } |
| 1165 | |
Svet Ganov | 99b6043 | 2015-06-27 13:15:22 -0700 | [diff] [blame] | 1166 | final int opCode = AppOpsManager.permissionToOpCode(activityInfo.permission); |
| 1167 | if (opCode == AppOpsManager.OP_NONE) { |
| 1168 | return ACTIVITY_RESTRICTION_NONE; |
| 1169 | } |
| 1170 | |
Philip P. Moltmann | 59076d8 | 2019-08-19 15:00:40 -0700 | [diff] [blame] | 1171 | // TODO moltmann b/136595429: Set featureId from caller |
| 1172 | if (mService.getAppOpsService().noteOperation(opCode, callingUid, callingPackage, /* featureId */ null) |
Wale Ogunwale | f673393 | 2018-06-27 05:14:34 -0700 | [diff] [blame] | 1173 | != AppOpsManager.MODE_ALLOWED) { |
Dianne Hackborn | a7cfbe0 | 2015-07-16 10:52:52 -0700 | [diff] [blame] | 1174 | if (!ignoreTargetSecurity) { |
| 1175 | return ACTIVITY_RESTRICTION_APPOP; |
| 1176 | } |
Svet Ganov | 99b6043 | 2015-06-27 13:15:22 -0700 | [diff] [blame] | 1177 | } |
| 1178 | |
| 1179 | return ACTIVITY_RESTRICTION_NONE; |
| 1180 | } |
| 1181 | |
Svetoslav | 7008b51 | 2015-06-24 18:47:07 -0700 | [diff] [blame] | 1182 | private int getActionRestrictionForCallingPackage(String action, |
| 1183 | String callingPackage, int callingPid, int callingUid) { |
| 1184 | if (action == null) { |
Svet Ganov | 99b6043 | 2015-06-27 13:15:22 -0700 | [diff] [blame] | 1185 | return ACTIVITY_RESTRICTION_NONE; |
Svetoslav | 7008b51 | 2015-06-24 18:47:07 -0700 | [diff] [blame] | 1186 | } |
| 1187 | |
| 1188 | String permission = ACTION_TO_RUNTIME_PERMISSION.get(action); |
| 1189 | if (permission == null) { |
Svet Ganov | 99b6043 | 2015-06-27 13:15:22 -0700 | [diff] [blame] | 1190 | return ACTIVITY_RESTRICTION_NONE; |
Svetoslav | 7008b51 | 2015-06-24 18:47:07 -0700 | [diff] [blame] | 1191 | } |
| 1192 | |
| 1193 | final PackageInfo packageInfo; |
| 1194 | try { |
| 1195 | packageInfo = mService.mContext.getPackageManager() |
Andrii Kulian | a8ccae4 | 2019-07-24 18:35:22 +0000 | [diff] [blame] | 1196 | .getPackageInfo(callingPackage, PackageManager.GET_PERMISSIONS); |
Svetoslav | 7008b51 | 2015-06-24 18:47:07 -0700 | [diff] [blame] | 1197 | } catch (PackageManager.NameNotFoundException e) { |
| 1198 | Slog.i(TAG, "Cannot find package info for " + callingPackage); |
Svet Ganov | 99b6043 | 2015-06-27 13:15:22 -0700 | [diff] [blame] | 1199 | return ACTIVITY_RESTRICTION_NONE; |
Svetoslav | 7008b51 | 2015-06-24 18:47:07 -0700 | [diff] [blame] | 1200 | } |
| 1201 | |
| 1202 | if (!ArrayUtils.contains(packageInfo.requestedPermissions, permission)) { |
Svet Ganov | 99b6043 | 2015-06-27 13:15:22 -0700 | [diff] [blame] | 1203 | return ACTIVITY_RESTRICTION_NONE; |
Svetoslav | 7008b51 | 2015-06-24 18:47:07 -0700 | [diff] [blame] | 1204 | } |
| 1205 | |
Wale Ogunwale | f673393 | 2018-06-27 05:14:34 -0700 | [diff] [blame] | 1206 | if (mService.checkPermission(permission, callingPid, callingUid) == PERMISSION_DENIED) { |
Svet Ganov | 99b6043 | 2015-06-27 13:15:22 -0700 | [diff] [blame] | 1207 | return ACTIVITY_RESTRICTION_PERMISSION; |
Svetoslav | 7008b51 | 2015-06-24 18:47:07 -0700 | [diff] [blame] | 1208 | } |
| 1209 | |
| 1210 | final int opCode = AppOpsManager.permissionToOpCode(permission); |
| 1211 | if (opCode == AppOpsManager.OP_NONE) { |
Svet Ganov | 99b6043 | 2015-06-27 13:15:22 -0700 | [diff] [blame] | 1212 | return ACTIVITY_RESTRICTION_NONE; |
Svetoslav | 7008b51 | 2015-06-24 18:47:07 -0700 | [diff] [blame] | 1213 | } |
| 1214 | |
Philip P. Moltmann | 59076d8 | 2019-08-19 15:00:40 -0700 | [diff] [blame] | 1215 | // TODO moltmann b/136595429: Set componentId from caller |
| 1216 | if (mService.getAppOpsService().noteOperation(opCode, callingUid, callingPackage, /* featureId */ null) |
Wale Ogunwale | f673393 | 2018-06-27 05:14:34 -0700 | [diff] [blame] | 1217 | != AppOpsManager.MODE_ALLOWED) { |
Svet Ganov | 99b6043 | 2015-06-27 13:15:22 -0700 | [diff] [blame] | 1218 | return ACTIVITY_RESTRICTION_APPOP; |
Svetoslav | 7008b51 | 2015-06-24 18:47:07 -0700 | [diff] [blame] | 1219 | } |
| 1220 | |
Svet Ganov | 99b6043 | 2015-06-27 13:15:22 -0700 | [diff] [blame] | 1221 | return ACTIVITY_RESTRICTION_NONE; |
Svetoslav | 7008b51 | 2015-06-24 18:47:07 -0700 | [diff] [blame] | 1222 | } |
| 1223 | |
Dianne Hackborn | 3d07c94 | 2015-03-13 18:02:54 -0700 | [diff] [blame] | 1224 | void setLaunchSource(int uid) { |
Andrii Kulian | c598b2d | 2019-02-07 17:16:38 -0800 | [diff] [blame] | 1225 | mLaunchingActivityWakeLock.setWorkSource(new WorkSource(uid)); |
Dianne Hackborn | 3d07c94 | 2015-03-13 18:02:54 -0700 | [diff] [blame] | 1226 | } |
| 1227 | |
Craig Mautner | 7ea5bd4 | 2013-07-05 15:27:08 -0700 | [diff] [blame] | 1228 | void acquireLaunchWakelock() { |
| 1229 | if (VALIDATE_WAKE_LOCK_CALLER && Binder.getCallingUid() != Process.myUid()) { |
| 1230 | throw new IllegalStateException("Calling must be system uid"); |
| 1231 | } |
Andrii Kulian | c598b2d | 2019-02-07 17:16:38 -0800 | [diff] [blame] | 1232 | mLaunchingActivityWakeLock.acquire(); |
Craig Mautner | 7ea5bd4 | 2013-07-05 15:27:08 -0700 | [diff] [blame] | 1233 | if (!mHandler.hasMessages(LAUNCH_TIMEOUT_MSG)) { |
| 1234 | // To be safe, don't allow the wake lock to be held for too long. |
| 1235 | mHandler.sendEmptyMessageDelayed(LAUNCH_TIMEOUT_MSG, LAUNCH_TIMEOUT); |
| 1236 | } |
| 1237 | } |
| 1238 | |
Craig Mautner | f3ea23a | 2015-01-13 09:37:08 -0800 | [diff] [blame] | 1239 | /** |
Louis Chang | 89f43fc | 2018-10-05 10:59:14 +0800 | [diff] [blame] | 1240 | * Called when all resumed tasks/stacks are idle. |
Wale Ogunwale | c9e57de | 2018-05-08 14:28:07 -0700 | [diff] [blame] | 1241 | * @return the state of mService.mAm.mBooting before this was called. |
Craig Mautner | f3ea23a | 2015-01-13 09:37:08 -0800 | [diff] [blame] | 1242 | */ |
Andreas Gampe | a36dc62 | 2018-02-05 17:19:22 -0800 | [diff] [blame] | 1243 | @GuardedBy("mService") |
Craig Mautner | f3ea23a | 2015-01-13 09:37:08 -0800 | [diff] [blame] | 1244 | private boolean checkFinishBootingLocked() { |
Wale Ogunwale | 5378374 | 2018-09-16 10:21:51 -0700 | [diff] [blame] | 1245 | final boolean booting = mService.isBooting(); |
Craig Mautner | f3ea23a | 2015-01-13 09:37:08 -0800 | [diff] [blame] | 1246 | boolean enableScreen = false; |
Wale Ogunwale | 5378374 | 2018-09-16 10:21:51 -0700 | [diff] [blame] | 1247 | mService.setBooting(false); |
| 1248 | if (!mService.isBooted()) { |
| 1249 | mService.setBooted(true); |
Craig Mautner | f3ea23a | 2015-01-13 09:37:08 -0800 | [diff] [blame] | 1250 | enableScreen = true; |
| 1251 | } |
| 1252 | if (booting || enableScreen) { |
Wale Ogunwale | 5378374 | 2018-09-16 10:21:51 -0700 | [diff] [blame] | 1253 | mService.postFinishBooting(booting, enableScreen); |
Craig Mautner | f3ea23a | 2015-01-13 09:37:08 -0800 | [diff] [blame] | 1254 | } |
| 1255 | return booting; |
| 1256 | } |
| 1257 | |
Craig Mautner | f333327 | 2013-04-22 10:55:53 -0700 | [diff] [blame] | 1258 | // Checked. |
Andreas Gampe | a36dc62 | 2018-02-05 17:19:22 -0800 | [diff] [blame] | 1259 | @GuardedBy("mService") |
Craig Mautner | f333327 | 2013-04-22 10:55:53 -0700 | [diff] [blame] | 1260 | final ActivityRecord activityIdleInternalLocked(final IBinder token, boolean fromTimeout, |
Winson Chung | 4dabf23 | 2017-01-25 13:25:22 -0800 | [diff] [blame] | 1261 | boolean processPausingActivities, Configuration config) { |
Wale Ogunwale | e23149f | 2015-03-06 15:39:44 -0800 | [diff] [blame] | 1262 | if (DEBUG_ALL) Slog.v(TAG, "Activity idle: " + token); |
Craig Mautner | f333327 | 2013-04-22 10:55:53 -0700 | [diff] [blame] | 1263 | |
Craig Mautner | f333327 | 2013-04-22 10:55:53 -0700 | [diff] [blame] | 1264 | ArrayList<ActivityRecord> finishes = null; |
Amith Yamasani | 37a40c2 | 2015-06-17 13:25:42 -0700 | [diff] [blame] | 1265 | ArrayList<UserState> startingUsers = null; |
Craig Mautner | f333327 | 2013-04-22 10:55:53 -0700 | [diff] [blame] | 1266 | int NS = 0; |
| 1267 | int NF = 0; |
Craig Mautner | f333327 | 2013-04-22 10:55:53 -0700 | [diff] [blame] | 1268 | boolean booting = false; |
Craig Mautner | f333327 | 2013-04-22 10:55:53 -0700 | [diff] [blame] | 1269 | boolean activityRemoved = false; |
| 1270 | |
Wale Ogunwale | 7d70117 | 2015-03-11 15:36:30 -0700 | [diff] [blame] | 1271 | ActivityRecord r = ActivityRecord.forTokenLocked(token); |
Craig Mautner | f333327 | 2013-04-22 10:55:53 -0700 | [diff] [blame] | 1272 | if (r != null) { |
Wale Ogunwale | 0fc365c | 2015-05-25 19:35:42 -0700 | [diff] [blame] | 1273 | if (DEBUG_IDLE) Slog.d(TAG_IDLE, "activityIdleInternalLocked: Callers=" |
| 1274 | + Debug.getCallers(4)); |
Craig Mautner | f333327 | 2013-04-22 10:55:53 -0700 | [diff] [blame] | 1275 | mHandler.removeMessages(IDLE_TIMEOUT_MSG, r); |
| 1276 | r.finishLaunchTickingLocked(); |
Craig Mautner | 7ea5bd4 | 2013-07-05 15:27:08 -0700 | [diff] [blame] | 1277 | if (fromTimeout) { |
Vishnu Nair | bb9ab4b | 2018-12-13 10:29:46 -0800 | [diff] [blame] | 1278 | reportActivityLaunchedLocked(fromTimeout, r, INVALID_DELAY, |
| 1279 | -1 /* launchState */); |
Craig Mautner | f333327 | 2013-04-22 10:55:53 -0700 | [diff] [blame] | 1280 | } |
Craig Mautner | 7ea5bd4 | 2013-07-05 15:27:08 -0700 | [diff] [blame] | 1281 | |
| 1282 | // This is a hack to semi-deal with a race condition |
| 1283 | // in the client where it can be constructed with a |
| 1284 | // newer configuration from when we asked it to launch. |
| 1285 | // We'll update with whatever configuration it now says |
| 1286 | // it used to launch. |
| 1287 | if (config != null) { |
Bryce Lee | a163b76 | 2017-01-24 11:05:01 -0800 | [diff] [blame] | 1288 | r.setLastReportedGlobalConfiguration(config); |
Craig Mautner | 7ea5bd4 | 2013-07-05 15:27:08 -0700 | [diff] [blame] | 1289 | } |
| 1290 | |
| 1291 | // We are now idle. If someone is waiting for a thumbnail from |
| 1292 | // us, we can now deliver. |
| 1293 | r.idle = true; |
| 1294 | |
Craig Mautner | 7ea5bd4 | 2013-07-05 15:27:08 -0700 | [diff] [blame] | 1295 | //Slog.i(TAG, "IDLE: mBooted=" + mBooted + ", fromTimeout=" + fromTimeout); |
Louis Chang | 89f43fc | 2018-10-05 10:59:14 +0800 | [diff] [blame] | 1296 | |
Louis Chang | 1eff248 | 2018-11-01 15:46:31 +0800 | [diff] [blame] | 1297 | // Check if able to finish booting when device is booting and all resumed activities |
| 1298 | // are idle. |
Wale Ogunwale | d32da47 | 2018-11-16 07:19:28 -0800 | [diff] [blame] | 1299 | if ((mService.isBooting() && mRootActivityContainer.allResumedActivitiesIdle()) |
| 1300 | || fromTimeout) { |
Craig Mautner | f3ea23a | 2015-01-13 09:37:08 -0800 | [diff] [blame] | 1301 | booting = checkFinishBootingLocked(); |
Craig Mautner | 7ea5bd4 | 2013-07-05 15:27:08 -0700 | [diff] [blame] | 1302 | } |
Garfield Tan | 2746ab5 | 2018-07-25 12:33:01 -0700 | [diff] [blame] | 1303 | |
| 1304 | // When activity is idle, we consider the relaunch must be successful, so let's clear |
| 1305 | // the flag. |
| 1306 | r.mRelaunchReason = RELAUNCH_REASON_NONE; |
Craig Mautner | 7ea5bd4 | 2013-07-05 15:27:08 -0700 | [diff] [blame] | 1307 | } |
| 1308 | |
Wale Ogunwale | d32da47 | 2018-11-16 07:19:28 -0800 | [diff] [blame] | 1309 | if (mRootActivityContainer.allResumedActivitiesIdle()) { |
Craig Mautner | 7ea5bd4 | 2013-07-05 15:27:08 -0700 | [diff] [blame] | 1310 | if (r != null) { |
Wale Ogunwale | 906f9c6 | 2018-07-23 11:23:44 -0700 | [diff] [blame] | 1311 | mService.scheduleAppGcsLocked(); |
Craig Mautner | 7ea5bd4 | 2013-07-05 15:27:08 -0700 | [diff] [blame] | 1312 | } |
| 1313 | |
Andrii Kulian | c598b2d | 2019-02-07 17:16:38 -0800 | [diff] [blame] | 1314 | if (mLaunchingActivityWakeLock.isHeld()) { |
Craig Mautner | 7ea5bd4 | 2013-07-05 15:27:08 -0700 | [diff] [blame] | 1315 | mHandler.removeMessages(LAUNCH_TIMEOUT_MSG); |
| 1316 | if (VALIDATE_WAKE_LOCK_CALLER && |
| 1317 | Binder.getCallingUid() != Process.myUid()) { |
| 1318 | throw new IllegalStateException("Calling must be system uid"); |
| 1319 | } |
Andrii Kulian | c598b2d | 2019-02-07 17:16:38 -0800 | [diff] [blame] | 1320 | mLaunchingActivityWakeLock.release(); |
Craig Mautner | 7ea5bd4 | 2013-07-05 15:27:08 -0700 | [diff] [blame] | 1321 | } |
Wale Ogunwale | d32da47 | 2018-11-16 07:19:28 -0800 | [diff] [blame] | 1322 | mRootActivityContainer.ensureActivitiesVisible(null, 0, !PRESERVE_WINDOWS); |
Craig Mautner | f333327 | 2013-04-22 10:55:53 -0700 | [diff] [blame] | 1323 | } |
| 1324 | |
| 1325 | // Atomically retrieve all of the other things to do. |
Winson Chung | 4dabf23 | 2017-01-25 13:25:22 -0800 | [diff] [blame] | 1326 | final ArrayList<ActivityRecord> stops = processStoppingActivitiesLocked(r, |
| 1327 | true /* remove */, processPausingActivities); |
Craig Mautner | f333327 | 2013-04-22 10:55:53 -0700 | [diff] [blame] | 1328 | NS = stops != null ? stops.size() : 0; |
Wale Ogunwale | 7d70117 | 2015-03-11 15:36:30 -0700 | [diff] [blame] | 1329 | if ((NF = mFinishingActivities.size()) > 0) { |
| 1330 | finishes = new ArrayList<>(mFinishingActivities); |
Craig Mautner | f333327 | 2013-04-22 10:55:53 -0700 | [diff] [blame] | 1331 | mFinishingActivities.clear(); |
| 1332 | } |
| 1333 | |
Craig Mautner | f333327 | 2013-04-22 10:55:53 -0700 | [diff] [blame] | 1334 | if (mStartingUsers.size() > 0) { |
Wale Ogunwale | 7d70117 | 2015-03-11 15:36:30 -0700 | [diff] [blame] | 1335 | startingUsers = new ArrayList<>(mStartingUsers); |
Craig Mautner | f333327 | 2013-04-22 10:55:53 -0700 | [diff] [blame] | 1336 | mStartingUsers.clear(); |
| 1337 | } |
| 1338 | |
Craig Mautner | f333327 | 2013-04-22 10:55:53 -0700 | [diff] [blame] | 1339 | // Stop any activities that are scheduled to do so but have been |
| 1340 | // waiting for the next one to start. |
| 1341 | for (int i = 0; i < NS; i++) { |
| 1342 | r = stops.get(i); |
Wale Ogunwale | 8b19de9 | 2018-11-29 19:58:26 -0800 | [diff] [blame] | 1343 | final ActivityStack stack = r.getActivityStack(); |
Wale Ogunwale | 7d70117 | 2015-03-11 15:36:30 -0700 | [diff] [blame] | 1344 | if (stack != null) { |
| 1345 | if (r.finishing) { |
Andrii Kulian | 7dd39bb | 2019-07-22 13:11:10 -0700 | [diff] [blame] | 1346 | // TODO(b/137329632): Wait for idle of the right activity, not just any. |
| 1347 | r.destroyIfPossible("activityIdleInternalLocked"); |
Wale Ogunwale | 7d70117 | 2015-03-11 15:36:30 -0700 | [diff] [blame] | 1348 | } else { |
Andrii Kulian | 79d6798 | 2019-08-19 11:56:16 -0700 | [diff] [blame] | 1349 | r.stopIfPossible(); |
Wale Ogunwale | 7d70117 | 2015-03-11 15:36:30 -0700 | [diff] [blame] | 1350 | } |
Craig Mautner | f333327 | 2013-04-22 10:55:53 -0700 | [diff] [blame] | 1351 | } |
| 1352 | } |
| 1353 | |
| 1354 | // Finish any activities that are scheduled to do so but have been |
| 1355 | // waiting for the next one to start. |
| 1356 | for (int i = 0; i < NF; i++) { |
| 1357 | r = finishes.get(i); |
Wale Ogunwale | 8b19de9 | 2018-11-29 19:58:26 -0800 | [diff] [blame] | 1358 | final ActivityStack stack = r.getActivityStack(); |
Wale Ogunwale | 7d70117 | 2015-03-11 15:36:30 -0700 | [diff] [blame] | 1359 | if (stack != null) { |
Andrii Kulian | 79d6798 | 2019-08-19 11:56:16 -0700 | [diff] [blame] | 1360 | activityRemoved |= r.destroyImmediately(true /* removeFromApp */, "finish-idle"); |
Wale Ogunwale | 7d70117 | 2015-03-11 15:36:30 -0700 | [diff] [blame] | 1361 | } |
Craig Mautner | f333327 | 2013-04-22 10:55:53 -0700 | [diff] [blame] | 1362 | } |
| 1363 | |
Dianne Hackborn | 7622a0f | 2014-09-30 14:31:42 -0700 | [diff] [blame] | 1364 | if (!booting) { |
Amith Yamasani | 1a7eaaa5 | 2014-05-07 10:22:15 -0700 | [diff] [blame] | 1365 | // Complete user switch |
| 1366 | if (startingUsers != null) { |
| 1367 | for (int i = 0; i < startingUsers.size(); i++) { |
Wale Ogunwale | 86b7446 | 2018-07-02 08:42:43 -0700 | [diff] [blame] | 1368 | mService.mAmInternal.finishUserSwitch(startingUsers.get(i)); |
Amith Yamasani | 1a7eaaa5 | 2014-05-07 10:22:15 -0700 | [diff] [blame] | 1369 | } |
| 1370 | } |
Craig Mautner | f333327 | 2013-04-22 10:55:53 -0700 | [diff] [blame] | 1371 | } |
| 1372 | |
Wale Ogunwale | 1f5e53d | 2018-11-05 05:12:46 -0800 | [diff] [blame] | 1373 | mService.mH.post(() -> mService.mAmInternal.trimApplications()); |
Craig Mautner | f333327 | 2013-04-22 10:55:53 -0700 | [diff] [blame] | 1374 | //dump(); |
| 1375 | //mWindowManager.dump(); |
| 1376 | |
Craig Mautner | f333327 | 2013-04-22 10:55:53 -0700 | [diff] [blame] | 1377 | if (activityRemoved) { |
Wale Ogunwale | d32da47 | 2018-11-16 07:19:28 -0800 | [diff] [blame] | 1378 | mRootActivityContainer.resumeFocusedStacksTopActivities(); |
Craig Mautner | f333327 | 2013-04-22 10:55:53 -0700 | [diff] [blame] | 1379 | } |
| 1380 | |
Craig Mautner | 7ea5bd4 | 2013-07-05 15:27:08 -0700 | [diff] [blame] | 1381 | return r; |
Craig Mautner | f333327 | 2013-04-22 10:55:53 -0700 | [diff] [blame] | 1382 | } |
| 1383 | |
Wale Ogunwale | d32da47 | 2018-11-16 07:19:28 -0800 | [diff] [blame] | 1384 | /** This doesn't just find a task, it also moves the task to front. */ |
Louis Chang | cdec080 | 2019-11-11 11:45:07 +0800 | [diff] [blame] | 1385 | void findTaskToMoveToFront(Task task, int flags, ActivityOptions options, String reason, |
Jorim Jaggi | 4d8d32c | 2018-01-19 15:57:41 +0100 | [diff] [blame] | 1386 | boolean forceNonResizeable) { |
Louis Chang | bd48dca | 2018-08-29 17:44:34 +0800 | [diff] [blame] | 1387 | ActivityStack currentStack = task.getStack(); |
Wale Ogunwale | 66e1685 | 2017-10-19 13:35:52 -0700 | [diff] [blame] | 1388 | if (currentStack == null) { |
| 1389 | Slog.e(TAG, "findTaskToMoveToFront: can't move task=" |
| 1390 | + task + " to front. Stack is null"); |
| 1391 | return; |
| 1392 | } |
| 1393 | |
Craig Mautner | aea74a5 | 2014-03-08 14:23:10 -0800 | [diff] [blame] | 1394 | if ((flags & ActivityManager.MOVE_TASK_NO_USER_ACTION) == 0) { |
| 1395 | mUserLeaving = true; |
Craig Mautner | 8d341ef | 2013-03-26 09:03:27 -0700 | [diff] [blame] | 1396 | } |
Wale Ogunwale | 66e1685 | 2017-10-19 13:35:52 -0700 | [diff] [blame] | 1397 | |
Louis Chang | c8b6411 | 2018-10-11 09:22:14 +0800 | [diff] [blame] | 1398 | reason = reason + " findTaskToMoveToFront"; |
| 1399 | boolean reparented = false; |
Wale Ogunwale | 0568aed | 2017-09-08 13:29:37 -0700 | [diff] [blame] | 1400 | if (task.isResizeable() && canUseActivityOptionsLaunchBounds(options)) { |
Bryce Lee | f3c6a47 | 2017-11-14 14:53:06 -0800 | [diff] [blame] | 1401 | final Rect bounds = options.getLaunchBounds(); |
Evan Rosky | a4cc3a9 | 2019-06-28 13:25:01 -0700 | [diff] [blame] | 1402 | task.setBounds(bounds); |
Wale Ogunwale | 0568aed | 2017-09-08 13:29:37 -0700 | [diff] [blame] | 1403 | |
Wale Ogunwale | d32da47 | 2018-11-16 07:19:28 -0800 | [diff] [blame] | 1404 | ActivityStack stack = |
| 1405 | mRootActivityContainer.getLaunchStack(null, options, task, ON_TOP); |
Wale Ogunwale | 0568aed | 2017-09-08 13:29:37 -0700 | [diff] [blame] | 1406 | |
Wale Ogunwale | 04a05ac | 2017-09-17 21:35:02 -0700 | [diff] [blame] | 1407 | if (stack != currentStack) { |
Louis Chang | c8b6411 | 2018-10-11 09:22:14 +0800 | [diff] [blame] | 1408 | moveHomeStackToFrontIfNeeded(flags, stack.getDisplay(), reason); |
Wale Ogunwale | 04a05ac | 2017-09-17 21:35:02 -0700 | [diff] [blame] | 1409 | task.reparent(stack, ON_TOP, REPARENT_KEEP_STACK_AT_FRONT, !ANIMATE, DEFER_RESUME, |
Louis Chang | c8b6411 | 2018-10-11 09:22:14 +0800 | [diff] [blame] | 1410 | reason); |
Louis Chang | bd48dca | 2018-08-29 17:44:34 +0800 | [diff] [blame] | 1411 | currentStack = stack; |
Louis Chang | c8b6411 | 2018-10-11 09:22:14 +0800 | [diff] [blame] | 1412 | reparented = true; |
| 1413 | // task.reparent() should already placed the task on top, |
Wale Ogunwale | 0568aed | 2017-09-08 13:29:37 -0700 | [diff] [blame] | 1414 | // still need moveTaskToFrontLocked() below for any transition settings. |
| 1415 | } |
Evan Rosky | dbe2ce5 | 2019-07-18 11:13:17 -0700 | [diff] [blame] | 1416 | if (stack.shouldResizeStackWithLaunchBounds()) { |
| 1417 | stack.resize(bounds, null /* tempTaskBounds */, null /* tempTaskInsetBounds */, |
| 1418 | !PRESERVE_WINDOWS, !DEFER_RESUME); |
Wale Ogunwale | 0568aed | 2017-09-08 13:29:37 -0700 | [diff] [blame] | 1419 | } else { |
| 1420 | // WM resizeTask must be done after the task is moved to the correct stack, |
| 1421 | // because Task's setBounds() also updates dim layer's bounds, but that has |
| 1422 | // dependency on the stack. |
Wale Ogunwale | 2322bed | 2019-10-10 17:24:19 +0200 | [diff] [blame] | 1423 | task.resize(false /* relayout */, false /* forced */); |
Chong Zhang | 0fa656b | 2015-08-31 15:17:21 -0700 | [diff] [blame] | 1424 | } |
| 1425 | } |
| 1426 | |
Louis Chang | c8b6411 | 2018-10-11 09:22:14 +0800 | [diff] [blame] | 1427 | if (!reparented) { |
| 1428 | moveHomeStackToFrontIfNeeded(flags, currentStack.getDisplay(), reason); |
| 1429 | } |
| 1430 | |
Wale Ogunwale | 21e0648 | 2019-11-18 05:14:15 -0800 | [diff] [blame] | 1431 | final ActivityRecord r = task.getTopNonFinishingActivity(); |
chaviw | 0d562bf | 2018-03-15 14:24:14 -0700 | [diff] [blame] | 1432 | currentStack.moveTaskToFrontLocked(task, false /* noAnimation */, options, |
Chong Zhang | db20b5f | 2015-10-23 14:01:43 -0700 | [diff] [blame] | 1433 | r == null ? null : r.appTimeTracker, reason); |
| 1434 | |
Wale Ogunwale | ee006da | 2015-03-30 14:49:25 -0700 | [diff] [blame] | 1435 | if (DEBUG_STACK) Slog.d(TAG_STACK, |
Andrii Kulian | 02b7a83 | 2016-10-06 23:11:56 -0700 | [diff] [blame] | 1436 | "findTaskToMoveToFront: moved to front of stack=" + currentStack); |
Jorim Jaggi | 2adba07 | 2016-03-03 13:43:39 +0100 | [diff] [blame] | 1437 | |
Wale Ogunwale | 0568aed | 2017-09-08 13:29:37 -0700 | [diff] [blame] | 1438 | handleNonResizableTaskIfNeeded(task, WINDOWING_MODE_UNDEFINED, DEFAULT_DISPLAY, |
Wale Ogunwale | a0f5b5e | 2017-10-11 09:37:23 -0700 | [diff] [blame] | 1439 | currentStack, forceNonResizeable); |
Craig Mautner | 8d341ef | 2013-03-26 09:03:27 -0700 | [diff] [blame] | 1440 | } |
| 1441 | |
Louis Chang | c8b6411 | 2018-10-11 09:22:14 +0800 | [diff] [blame] | 1442 | private void moveHomeStackToFrontIfNeeded(int flags, ActivityDisplay display, String reason) { |
| 1443 | final ActivityStack focusedStack = display.getFocusedStack(); |
| 1444 | |
| 1445 | if ((display.getWindowingMode() == WINDOWING_MODE_FULLSCREEN |
| 1446 | && (flags & ActivityManager.MOVE_TASK_WITH_HOME) != 0) |
| 1447 | || (focusedStack != null && focusedStack.isActivityTypeRecents())) { |
| 1448 | // We move home stack to front when we are on a fullscreen display and caller has |
| 1449 | // requested the home activity to move with it. Or the previous stack is recents. |
| 1450 | display.moveHomeStackToFront(reason); |
| 1451 | } |
| 1452 | } |
| 1453 | |
Wale Ogunwale | 0568aed | 2017-09-08 13:29:37 -0700 | [diff] [blame] | 1454 | boolean canUseActivityOptionsLaunchBounds(ActivityOptions options) { |
Wale Ogunwale | 7a8fa60 | 2015-11-18 15:56:57 -0800 | [diff] [blame] | 1455 | // 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] | 1456 | // window management or is launching into the pinned stack. |
Wale Ogunwale | 0568aed | 2017-09-08 13:29:37 -0700 | [diff] [blame] | 1457 | if (options == null || options.getLaunchBounds() == null) { |
Wale Ogunwale | 854809c | 2015-12-27 16:18:19 -0800 | [diff] [blame] | 1458 | return false; |
| 1459 | } |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 1460 | return (mService.mSupportsPictureInPicture |
Wale Ogunwale | 0568aed | 2017-09-08 13:29:37 -0700 | [diff] [blame] | 1461 | && options.getLaunchWindowingMode() == WINDOWING_MODE_PINNED) |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 1462 | || mService.mSupportsFreeformWindowManagement; |
Wale Ogunwale | 7a8fa60 | 2015-11-18 15:56:57 -0800 | [diff] [blame] | 1463 | } |
| 1464 | |
Bryce Lee | ec55eb0 | 2017-12-05 20:51:27 -0800 | [diff] [blame] | 1465 | LaunchParamsController getLaunchParamsController() { |
| 1466 | return mLaunchParamsController; |
Bryce Lee | 9ad3eb3 | 2017-10-10 10:10:31 -0700 | [diff] [blame] | 1467 | } |
| 1468 | |
Wale Ogunwale | d32da47 | 2018-11-16 07:19:28 -0800 | [diff] [blame] | 1469 | private void deferUpdateRecentsHomeStackBounds() { |
| 1470 | mRootActivityContainer.deferUpdateBounds(ACTIVITY_TYPE_RECENTS); |
| 1471 | mRootActivityContainer.deferUpdateBounds(ACTIVITY_TYPE_HOME); |
Wale Ogunwale | ddc1cb2 | 2015-07-25 19:23:04 -0700 | [diff] [blame] | 1472 | } |
| 1473 | |
Wale Ogunwale | d32da47 | 2018-11-16 07:19:28 -0800 | [diff] [blame] | 1474 | private void continueUpdateRecentsHomeStackBounds() { |
| 1475 | mRootActivityContainer.continueUpdateBounds(ACTIVITY_TYPE_RECENTS); |
| 1476 | mRootActivityContainer.continueUpdateBounds(ACTIVITY_TYPE_HOME); |
Jorim Jaggi | 192086e | 2016-03-11 17:17:03 +0100 | [diff] [blame] | 1477 | } |
| 1478 | |
Jorim Jaggi | 0b46f3c | 2016-03-14 12:21:37 +0100 | [diff] [blame] | 1479 | void notifyAppTransitionDone() { |
Winson Chung | c167427 | 2018-02-21 10:15:17 -0800 | [diff] [blame] | 1480 | continueUpdateRecentsHomeStackBounds(); |
Jorim Jaggi | 0b46f3c | 2016-03-14 12:21:37 +0100 | [diff] [blame] | 1481 | for (int i = mResizingTasksDuringAnimation.size() - 1; i >= 0; i--) { |
| 1482 | final int taskId = mResizingTasksDuringAnimation.valueAt(i); |
Louis Chang | cdec080 | 2019-11-11 11:45:07 +0800 | [diff] [blame] | 1483 | final Task task = |
Wale Ogunwale | d32da47 | 2018-11-16 07:19:28 -0800 | [diff] [blame] | 1484 | mRootActivityContainer.anyTaskForId(taskId, MATCH_TASK_IN_STACKS_ONLY); |
Wale Ogunwale | e1fe7fa2 | 2016-12-15 18:27:00 -0800 | [diff] [blame] | 1485 | if (task != null) { |
| 1486 | task.setTaskDockedResizing(false); |
Jorim Jaggi | 0b46f3c | 2016-03-14 12:21:37 +0100 | [diff] [blame] | 1487 | } |
| 1488 | } |
| 1489 | mResizingTasksDuringAnimation.clear(); |
| 1490 | } |
| 1491 | |
Wale Ogunwale | 04a05ac | 2017-09-17 21:35:02 -0700 | [diff] [blame] | 1492 | /** |
| 1493 | * 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] | 1494 | * Can do that once we are no longer using static stack ids. |
Wale Ogunwale | 04a05ac | 2017-09-17 21:35:02 -0700 | [diff] [blame] | 1495 | */ |
Wale Ogunwale | 9dcf946 | 2017-09-19 15:13:01 -0700 | [diff] [blame] | 1496 | private void moveTasksToFullscreenStackInSurfaceTransaction(ActivityStack fromStack, |
Wale Ogunwale | 04a05ac | 2017-09-17 21:35:02 -0700 | [diff] [blame] | 1497 | int toDisplayId, boolean onTop) { |
Robert Carr | 6914f08 | 2017-03-20 19:04:30 -0700 | [diff] [blame] | 1498 | |
Riddle Hsu | a0022cd | 2019-09-09 21:12:41 +0800 | [diff] [blame] | 1499 | mService.deferWindowLayout(); |
Wale Ogunwale | c8da41e | 2016-04-16 13:27:23 -0700 | [diff] [blame] | 1500 | try { |
Wale Ogunwale | 04a05ac | 2017-09-17 21:35:02 -0700 | [diff] [blame] | 1501 | final int windowingMode = fromStack.getWindowingMode(); |
Wale Ogunwale | d32da47 | 2018-11-16 07:19:28 -0800 | [diff] [blame] | 1502 | final ActivityDisplay toDisplay = |
| 1503 | mRootActivityContainer.getActivityDisplay(toDisplayId); |
Wale Ogunwale | 04a05ac | 2017-09-17 21:35:02 -0700 | [diff] [blame] | 1504 | |
| 1505 | if (windowingMode == WINDOWING_MODE_SPLIT_SCREEN_PRIMARY) { |
Wale Ogunwale | 7e1f5f5 | 2017-10-18 15:19:59 -0700 | [diff] [blame] | 1506 | // Tell the display we are exiting split-screen mode. |
| 1507 | toDisplay.onExitingSplitScreenMode(); |
Wale Ogunwale | c8da41e | 2016-04-16 13:27:23 -0700 | [diff] [blame] | 1508 | // We are moving all tasks from the docked stack to the fullscreen stack, |
| 1509 | // which is dismissing the docked stack, so resize all other stacks to |
| 1510 | // fullscreen here already so we don't end up with resize trashing. |
Wale Ogunwale | a0f5b5e | 2017-10-11 09:37:23 -0700 | [diff] [blame] | 1511 | for (int i = toDisplay.getChildCount() - 1; i >= 0; --i) { |
| 1512 | final ActivityStack otherStack = toDisplay.getChildAt(i); |
Wale Ogunwale | 926aade | 2017-08-29 11:24:37 -0700 | [diff] [blame] | 1513 | if (!otherStack.inSplitScreenSecondaryWindowingMode()) { |
| 1514 | continue; |
| 1515 | } |
Evan Rosky | 1047574 | 2018-09-05 19:02:48 -0700 | [diff] [blame] | 1516 | otherStack.setWindowingMode(WINDOWING_MODE_UNDEFINED); |
Wale Ogunwale | c8da41e | 2016-04-16 13:27:23 -0700 | [diff] [blame] | 1517 | } |
| 1518 | |
| 1519 | // Also disable docked stack resizing since we have manually adjusted the |
| 1520 | // size of other stacks above and we don't want to trigger a docked stack |
| 1521 | // resize when we remove task from it below and it is detached from the |
| 1522 | // display because it no longer contains any tasks. |
| 1523 | mAllowDockedStackResize = false; |
| 1524 | } |
Wale Ogunwale | 04a05ac | 2017-09-17 21:35:02 -0700 | [diff] [blame] | 1525 | |
Winson Chung | 5af42fc | 2017-03-24 17:11:33 -0700 | [diff] [blame] | 1526 | // If we are moving from the pinned stack, then the animation takes care of updating |
| 1527 | // the picture-in-picture mode. |
Ben Lin | 6db8fb2 | 2019-10-18 16:03:44 -0700 | [diff] [blame] | 1528 | final boolean schedulePictureInPictureModeChange = |
| 1529 | windowingMode == WINDOWING_MODE_PINNED; |
Louis Chang | cdec080 | 2019-11-11 11:45:07 +0800 | [diff] [blame] | 1530 | final ArrayList<Task> tasks = fromStack.getAllTasks(); |
Wale Ogunwale | 04a05ac | 2017-09-17 21:35:02 -0700 | [diff] [blame] | 1531 | |
Wale Ogunwale | 388945c | 2017-10-04 12:13:46 -0700 | [diff] [blame] | 1532 | if (!tasks.isEmpty()) { |
Wale Ogunwale | 7e1f5f5 | 2017-10-18 15:19:59 -0700 | [diff] [blame] | 1533 | mTmpOptions.setLaunchWindowingMode(WINDOWING_MODE_FULLSCREEN); |
Wale Ogunwale | 388945c | 2017-10-04 12:13:46 -0700 | [diff] [blame] | 1534 | final int size = tasks.size(); |
Wale Ogunwale | 7e1f5f5 | 2017-10-18 15:19:59 -0700 | [diff] [blame] | 1535 | for (int i = 0; i < size; ++i) { |
Louis Chang | cdec080 | 2019-11-11 11:45:07 +0800 | [diff] [blame] | 1536 | final Task task = tasks.get(i); |
Wale Ogunwale | 7e1f5f5 | 2017-10-18 15:19:59 -0700 | [diff] [blame] | 1537 | final ActivityStack toStack = toDisplay.getOrCreateStack( |
| 1538 | null, mTmpOptions, task, task.getActivityType(), onTop); |
Wale Ogunwale | 388945c | 2017-10-04 12:13:46 -0700 | [diff] [blame] | 1539 | |
Wale Ogunwale | 7e1f5f5 | 2017-10-18 15:19:59 -0700 | [diff] [blame] | 1540 | if (onTop) { |
Wale Ogunwale | 388945c | 2017-10-04 12:13:46 -0700 | [diff] [blame] | 1541 | final boolean isTopTask = i == (size - 1); |
Wale Ogunwale | 388945c | 2017-10-04 12:13:46 -0700 | [diff] [blame] | 1542 | // 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] | 1543 | task.reparent(toStack, ON_TOP, REPARENT_MOVE_STACK_TO_FRONT, |
Wale Ogunwale | 388945c | 2017-10-04 12:13:46 -0700 | [diff] [blame] | 1544 | isTopTask /* animate */, DEFER_RESUME, |
| 1545 | schedulePictureInPictureModeChange, |
| 1546 | "moveTasksToFullscreenStack - onTop"); |
Chenjie Yu | ae9fdf04 | 2018-02-15 10:19:32 -0800 | [diff] [blame] | 1547 | MetricsLoggerWrapper.logPictureInPictureFullScreen(mService.mContext, |
| 1548 | task.effectiveUid, task.realActivity.flattenToString()); |
Wale Ogunwale | 7e1f5f5 | 2017-10-18 15:19:59 -0700 | [diff] [blame] | 1549 | } else { |
Wale Ogunwale | 388945c | 2017-10-04 12:13:46 -0700 | [diff] [blame] | 1550 | // Position the tasks in the fullscreen stack in order at the bottom of the |
| 1551 | // stack. Also defer resume until all the tasks have been moved to the |
| 1552 | // fullscreen stack. |
Wale Ogunwale | 7e1f5f5 | 2017-10-18 15:19:59 -0700 | [diff] [blame] | 1553 | task.reparent(toStack, ON_TOP, |
Wale Ogunwale | 388945c | 2017-10-04 12:13:46 -0700 | [diff] [blame] | 1554 | REPARENT_LEAVE_STACK_IN_PLACE, !ANIMATE, DEFER_RESUME, |
| 1555 | schedulePictureInPictureModeChange, |
| 1556 | "moveTasksToFullscreenStack - NOT_onTop"); |
| 1557 | } |
Wale Ogunwale | c8da41e | 2016-04-16 13:27:23 -0700 | [diff] [blame] | 1558 | } |
| 1559 | } |
Winson Chung | 7466610 | 2017-02-22 17:49:24 -0800 | [diff] [blame] | 1560 | |
Wale Ogunwale | d32da47 | 2018-11-16 07:19:28 -0800 | [diff] [blame] | 1561 | mRootActivityContainer.ensureActivitiesVisible(null, 0, PRESERVE_WINDOWS); |
| 1562 | mRootActivityContainer.resumeFocusedStacksTopActivities(); |
Wale Ogunwale | c8da41e | 2016-04-16 13:27:23 -0700 | [diff] [blame] | 1563 | } finally { |
| 1564 | mAllowDockedStackResize = true; |
Riddle Hsu | a0022cd | 2019-09-09 21:12:41 +0800 | [diff] [blame] | 1565 | mService.continueWindowLayout(); |
Wale Ogunwale | c8da41e | 2016-04-16 13:27:23 -0700 | [diff] [blame] | 1566 | } |
| 1567 | } |
| 1568 | |
Wale Ogunwale | 9dcf946 | 2017-09-19 15:13:01 -0700 | [diff] [blame] | 1569 | void moveTasksToFullscreenStackLocked(ActivityStack fromStack, boolean onTop) { |
Wale Ogunwale | 04a05ac | 2017-09-17 21:35:02 -0700 | [diff] [blame] | 1570 | moveTasksToFullscreenStackLocked(fromStack, DEFAULT_DISPLAY, onTop); |
| 1571 | } |
| 1572 | |
| 1573 | void moveTasksToFullscreenStackLocked(ActivityStack fromStack, int toDisplayId, boolean onTop) { |
| 1574 | mWindowManager.inSurfaceTransaction(() -> |
| 1575 | moveTasksToFullscreenStackInSurfaceTransaction(fromStack, toDisplayId, onTop)); |
Robert Carr | 6914f08 | 2017-03-20 19:04:30 -0700 | [diff] [blame] | 1576 | } |
| 1577 | |
Adrian Roos | a6d6aab | 2018-04-19 18:58:22 +0200 | [diff] [blame] | 1578 | void setSplitScreenResizing(boolean resizing) { |
| 1579 | if (resizing == mDockedStackResizing) { |
| 1580 | return; |
| 1581 | } |
| 1582 | |
| 1583 | mDockedStackResizing = resizing; |
| 1584 | mWindowManager.setDockedStackResizing(resizing); |
| 1585 | |
| 1586 | if (!resizing && mHasPendingDockedBounds) { |
| 1587 | resizeDockedStackLocked(mPendingDockedBounds, mPendingTempDockedTaskBounds, |
| 1588 | mPendingTempDockedTaskInsetBounds, mPendingTempOtherTaskBounds, |
| 1589 | mPendingTempOtherTaskInsetBounds, PRESERVE_WINDOWS); |
| 1590 | |
| 1591 | mHasPendingDockedBounds = false; |
| 1592 | mPendingDockedBounds = null; |
| 1593 | mPendingTempDockedTaskBounds = null; |
| 1594 | mPendingTempDockedTaskInsetBounds = null; |
| 1595 | mPendingTempOtherTaskBounds = null; |
| 1596 | mPendingTempOtherTaskInsetBounds = null; |
| 1597 | } |
| 1598 | } |
| 1599 | |
Jorim Jaggi | dc249c4 | 2015-12-15 14:57:31 -0800 | [diff] [blame] | 1600 | void resizeDockedStackLocked(Rect dockedBounds, Rect tempDockedTaskBounds, |
Andrii Kulian | db3e4ec | 2016-07-12 17:11:35 -0700 | [diff] [blame] | 1601 | Rect tempDockedTaskInsetBounds, Rect tempOtherTaskBounds, Rect tempOtherTaskInsetBounds, |
| 1602 | boolean preserveWindows) { |
| 1603 | resizeDockedStackLocked(dockedBounds, tempDockedTaskBounds, tempDockedTaskInsetBounds, |
| 1604 | tempOtherTaskBounds, tempOtherTaskInsetBounds, preserveWindows, |
| 1605 | false /* deferResume */); |
| 1606 | } |
| 1607 | |
Wale Ogunwale | d32da47 | 2018-11-16 07:19:28 -0800 | [diff] [blame] | 1608 | void resizeDockedStackLocked(Rect dockedBounds, Rect tempDockedTaskBounds, |
Andrii Kulian | db3e4ec | 2016-07-12 17:11:35 -0700 | [diff] [blame] | 1609 | Rect tempDockedTaskInsetBounds, Rect tempOtherTaskBounds, Rect tempOtherTaskInsetBounds, |
| 1610 | boolean preserveWindows, boolean deferResume) { |
Wale Ogunwale | c8da41e | 2016-04-16 13:27:23 -0700 | [diff] [blame] | 1611 | |
| 1612 | if (!mAllowDockedStackResize) { |
| 1613 | // Docked stack resize currently disabled. |
| 1614 | return; |
| 1615 | } |
| 1616 | |
Wale Ogunwale | d32da47 | 2018-11-16 07:19:28 -0800 | [diff] [blame] | 1617 | final ActivityStack stack = |
| 1618 | mRootActivityContainer.getDefaultDisplay().getSplitScreenPrimaryStack(); |
Jorim Jaggi | dc249c4 | 2015-12-15 14:57:31 -0800 | [diff] [blame] | 1619 | if (stack == null) { |
| 1620 | Slog.w(TAG, "resizeDockedStackLocked: docked stack not found"); |
| 1621 | return; |
| 1622 | } |
| 1623 | |
Adrian Roos | a6d6aab | 2018-04-19 18:58:22 +0200 | [diff] [blame] | 1624 | if (mDockedStackResizing) { |
| 1625 | mHasPendingDockedBounds = true; |
| 1626 | mPendingDockedBounds = copyOrNull(dockedBounds); |
| 1627 | mPendingTempDockedTaskBounds = copyOrNull(tempDockedTaskBounds); |
| 1628 | mPendingTempDockedTaskInsetBounds = copyOrNull(tempDockedTaskInsetBounds); |
| 1629 | mPendingTempOtherTaskBounds = copyOrNull(tempOtherTaskBounds); |
| 1630 | mPendingTempOtherTaskInsetBounds = copyOrNull(tempOtherTaskInsetBounds); |
| 1631 | } |
| 1632 | |
Riddle Hsu | 2ca561b | 2019-10-08 21:58:58 +0800 | [diff] [blame] | 1633 | Trace.traceBegin(TRACE_TAG_WINDOW_MANAGER, "resizeDockedStack"); |
Riddle Hsu | a0022cd | 2019-09-09 21:12:41 +0800 | [diff] [blame] | 1634 | mService.deferWindowLayout(); |
Jorim Jaggi | dc249c4 | 2015-12-15 14:57:31 -0800 | [diff] [blame] | 1635 | try { |
Wale Ogunwale | c8da41e | 2016-04-16 13:27:23 -0700 | [diff] [blame] | 1636 | // Don't allow re-entry while resizing. E.g. due to docked stack detaching. |
| 1637 | mAllowDockedStackResize = false; |
Jorim Jaggi | dc249c4 | 2015-12-15 14:57:31 -0800 | [diff] [blame] | 1638 | ActivityRecord r = stack.topRunningActivityLocked(); |
Evan Rosky | dbe2ce5 | 2019-07-18 11:13:17 -0700 | [diff] [blame] | 1639 | stack.resize(dockedBounds, tempDockedTaskBounds, tempDockedTaskInsetBounds, |
| 1640 | !PRESERVE_WINDOWS, DEFER_RESUME); |
Jorim Jaggi | dc249c4 | 2015-12-15 14:57:31 -0800 | [diff] [blame] | 1641 | |
Andrii Kulian | 69fb5e4 | 2016-04-05 16:47:29 -0700 | [diff] [blame] | 1642 | // TODO: Checking for isAttached might not be needed as if the user passes in null |
| 1643 | // dockedBounds then they want the docked stack to be dismissed. |
Bryce Lee | f3c6a47 | 2017-11-14 14:53:06 -0800 | [diff] [blame] | 1644 | if (stack.getWindowingMode() == WINDOWING_MODE_FULLSCREEN |
| 1645 | || (dockedBounds == null && !stack.isAttached())) { |
Andrii Kulian | 69fb5e4 | 2016-04-05 16:47:29 -0700 | [diff] [blame] | 1646 | // 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] | 1647 | // In this case we make all other static stacks fullscreen and move all |
| 1648 | // docked stack tasks to the fullscreen stack. |
Wale Ogunwale | 9dcf946 | 2017-09-19 15:13:01 -0700 | [diff] [blame] | 1649 | moveTasksToFullscreenStackLocked(stack, ON_TOP); |
Jorim Jaggi | dc249c4 | 2015-12-15 14:57:31 -0800 | [diff] [blame] | 1650 | |
| 1651 | // stack shouldn't contain anymore activities, so nothing to resume. |
| 1652 | r = null; |
| 1653 | } else { |
| 1654 | // Docked stacks occupy a dedicated region on screen so the size of all other |
| 1655 | // static stacks need to be adjusted so they don't overlap with the docked stack. |
| 1656 | // We get the bounds to use from window manager which has been adjusted for any |
| 1657 | // screen controls and is also the same for all stacks. |
Wale Ogunwale | d32da47 | 2018-11-16 07:19:28 -0800 | [diff] [blame] | 1658 | final ActivityDisplay display = mRootActivityContainer.getDefaultDisplay(); |
Matthew Ng | aa2b620 | 2017-02-10 14:48:21 -0800 | [diff] [blame] | 1659 | final Rect otherTaskRect = new Rect(); |
Wale Ogunwale | a0f5b5e | 2017-10-11 09:37:23 -0700 | [diff] [blame] | 1660 | for (int i = display.getChildCount() - 1; i >= 0; --i) { |
| 1661 | final ActivityStack current = display.getChildAt(i); |
Evan Rosky | c5abbd8 | 2018-10-05 16:02:19 -0700 | [diff] [blame] | 1662 | if (!current.inSplitScreenSecondaryWindowingMode()) { |
Wale Ogunwale | 926aade | 2017-08-29 11:24:37 -0700 | [diff] [blame] | 1663 | continue; |
Jorim Jaggi | dc249c4 | 2015-12-15 14:57:31 -0800 | [diff] [blame] | 1664 | } |
Wale Ogunwale | 2b07da8 | 2017-11-08 14:52:40 -0800 | [diff] [blame] | 1665 | if (!current.affectedBySplitScreenResize()) { |
Wale Ogunwale | 926aade | 2017-08-29 11:24:37 -0700 | [diff] [blame] | 1666 | continue; |
| 1667 | } |
Adrian Roos | a6d6aab | 2018-04-19 18:58:22 +0200 | [diff] [blame] | 1668 | if (mDockedStackResizing && !current.isTopActivityVisible()) { |
| 1669 | // Non-visible stacks get resized once we're done with the resize |
| 1670 | // interaction. |
| 1671 | continue; |
| 1672 | } |
Evan Rosky | c5abbd8 | 2018-10-05 16:02:19 -0700 | [diff] [blame] | 1673 | current.getStackDockedModeBounds(dockedBounds, |
Wale Ogunwale | 926aade | 2017-08-29 11:24:37 -0700 | [diff] [blame] | 1674 | tempOtherTaskBounds /* currentTempTaskBounds */, |
| 1675 | tempRect /* outStackBounds */, |
Evan Rosky | c5abbd8 | 2018-10-05 16:02:19 -0700 | [diff] [blame] | 1676 | otherTaskRect /* outTempTaskBounds */); |
Wale Ogunwale | 926aade | 2017-08-29 11:24:37 -0700 | [diff] [blame] | 1677 | |
Evan Rosky | dbe2ce5 | 2019-07-18 11:13:17 -0700 | [diff] [blame] | 1678 | if (tempRect.isEmpty()) { |
| 1679 | // If this scenario is hit, it means something is not working right. |
| 1680 | // Empty/null bounds implies fullscreen. In the event that this stack |
| 1681 | // *should* be fullscreen, its mode should be set explicitly in a form |
| 1682 | // of setWindowingMode so that other parts of the system are updated |
| 1683 | // properly. |
| 1684 | throw new IllegalArgumentException("Trying to set null bounds on a" |
| 1685 | + " non-fullscreen stack"); |
| 1686 | } |
| 1687 | |
| 1688 | current.resize(tempRect, |
Wale Ogunwale | 926aade | 2017-08-29 11:24:37 -0700 | [diff] [blame] | 1689 | !otherTaskRect.isEmpty() ? otherTaskRect : tempOtherTaskBounds, |
Evan Rosky | dbe2ce5 | 2019-07-18 11:13:17 -0700 | [diff] [blame] | 1690 | tempOtherTaskInsetBounds, preserveWindows, deferResume); |
Jorim Jaggi | dc249c4 | 2015-12-15 14:57:31 -0800 | [diff] [blame] | 1691 | } |
| 1692 | } |
Andrii Kulian | db3e4ec | 2016-07-12 17:11:35 -0700 | [diff] [blame] | 1693 | if (!deferResume) { |
| 1694 | stack.ensureVisibleActivitiesConfigurationLocked(r, preserveWindows); |
| 1695 | } |
Jorim Jaggi | dc249c4 | 2015-12-15 14:57:31 -0800 | [diff] [blame] | 1696 | } finally { |
Wale Ogunwale | c8da41e | 2016-04-16 13:27:23 -0700 | [diff] [blame] | 1697 | mAllowDockedStackResize = true; |
Riddle Hsu | a0022cd | 2019-09-09 21:12:41 +0800 | [diff] [blame] | 1698 | mService.continueWindowLayout(); |
Riddle Hsu | 2ca561b | 2019-10-08 21:58:58 +0800 | [diff] [blame] | 1699 | Trace.traceEnd(TRACE_TAG_WINDOW_MANAGER); |
Jorim Jaggi | dc249c4 | 2015-12-15 14:57:31 -0800 | [diff] [blame] | 1700 | } |
Jorim Jaggi | dc249c4 | 2015-12-15 14:57:31 -0800 | [diff] [blame] | 1701 | } |
| 1702 | |
Robert Carr | 0d00c2e | 2016-02-29 17:45:02 -0800 | [diff] [blame] | 1703 | void resizePinnedStackLocked(Rect pinnedBounds, Rect tempPinnedTaskBounds) { |
Yunfan Chen | 279f558 | 2018-12-12 15:24:50 -0800 | [diff] [blame] | 1704 | // TODO(multi-display): The display containing the stack should be passed in. |
| 1705 | final ActivityStack stack = |
Wale Ogunwale | d32da47 | 2018-11-16 07:19:28 -0800 | [diff] [blame] | 1706 | mRootActivityContainer.getDefaultDisplay().getPinnedStack(); |
Robert Carr | 0d00c2e | 2016-02-29 17:45:02 -0800 | [diff] [blame] | 1707 | if (stack == null) { |
| 1708 | Slog.w(TAG, "resizePinnedStackLocked: pinned stack not found"); |
| 1709 | return; |
| 1710 | } |
Winson Chung | 19953ca | 2017-04-11 11:19:23 -0700 | [diff] [blame] | 1711 | |
Riddle Hsu | 2ca561b | 2019-10-08 21:58:58 +0800 | [diff] [blame] | 1712 | Trace.traceBegin(TRACE_TAG_WINDOW_MANAGER, "resizePinnedStack"); |
Riddle Hsu | a0022cd | 2019-09-09 21:12:41 +0800 | [diff] [blame] | 1713 | mService.deferWindowLayout(); |
Robert Carr | 0d00c2e | 2016-02-29 17:45:02 -0800 | [diff] [blame] | 1714 | try { |
Robert Carr | 7e4c90e | 2017-02-15 19:52:38 -0800 | [diff] [blame] | 1715 | Rect insetBounds = null; |
Adrian Roos | 3e80b60 | 2018-04-30 12:42:36 +0200 | [diff] [blame] | 1716 | if (tempPinnedTaskBounds != null && stack.isAnimatingBoundsToFullscreen()) { |
| 1717 | // 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] | 1718 | insetBounds = tempRect; |
| 1719 | insetBounds.top = 0; |
| 1720 | insetBounds.left = 0; |
| 1721 | insetBounds.right = tempPinnedTaskBounds.width(); |
| 1722 | insetBounds.bottom = tempPinnedTaskBounds.height(); |
| 1723 | } |
Winson Chung | 15036ca | 2018-05-31 15:51:47 -0700 | [diff] [blame] | 1724 | if (pinnedBounds != null && tempPinnedTaskBounds == null) { |
| 1725 | // We have finished the animation into PiP, and are resizing the tasks to match the |
| 1726 | // stack bounds, while layouts are deferred, update any task state as a part of |
| 1727 | // transitioning it from fullscreen into a floating state. |
| 1728 | stack.onPipAnimationEndResize(); |
| 1729 | } |
Evan Rosky | dbe2ce5 | 2019-07-18 11:13:17 -0700 | [diff] [blame] | 1730 | stack.resize(pinnedBounds, tempPinnedTaskBounds, insetBounds, !PRESERVE_WINDOWS, |
| 1731 | !DEFER_RESUME); |
Robert Carr | 0d00c2e | 2016-02-29 17:45:02 -0800 | [diff] [blame] | 1732 | } finally { |
Riddle Hsu | a0022cd | 2019-09-09 21:12:41 +0800 | [diff] [blame] | 1733 | mService.continueWindowLayout(); |
Riddle Hsu | 2ca561b | 2019-10-08 21:58:58 +0800 | [diff] [blame] | 1734 | Trace.traceEnd(TRACE_TAG_WINDOW_MANAGER); |
Robert Carr | 0d00c2e | 2016-02-29 17:45:02 -0800 | [diff] [blame] | 1735 | } |
| 1736 | } |
| 1737 | |
Wale Ogunwale | a0f5b5e | 2017-10-11 09:37:23 -0700 | [diff] [blame] | 1738 | private void removeStackInSurfaceTransaction(ActivityStack stack) { |
Louis Chang | cdec080 | 2019-11-11 11:45:07 +0800 | [diff] [blame] | 1739 | final ArrayList<Task> tasks = stack.getAllTasks(); |
Wale Ogunwale | 04a05ac | 2017-09-17 21:35:02 -0700 | [diff] [blame] | 1740 | if (stack.getWindowingMode() == WINDOWING_MODE_PINNED) { |
Winson Chung | 4790065 | 2017-04-06 18:44:25 -0700 | [diff] [blame] | 1741 | /** |
| 1742 | * Workaround: Force-stop all the activities in the pinned stack before we reparent them |
| 1743 | * to the fullscreen stack. This is to guarantee that when we are removing a stack, |
| 1744 | * that the client receives onStop() before it is reparented. We do this by detaching |
| 1745 | * the stack from the display so that it will be considered invisible when |
| 1746 | * ensureActivitiesVisibleLocked() is called, and all of its activitys will be marked |
| 1747 | * invisible as well and added to the stopping list. After which we process the |
| 1748 | * stopping list by handling the idle. |
| 1749 | */ |
Yunfan Chen | 279f558 | 2018-12-12 15:24:50 -0800 | [diff] [blame] | 1750 | stack.mForceHidden = true; |
| 1751 | stack.ensureActivitiesVisibleLocked(null, 0, PRESERVE_WINDOWS); |
| 1752 | stack.mForceHidden = false; |
Winson Chung | 4790065 | 2017-04-06 18:44:25 -0700 | [diff] [blame] | 1753 | activityIdleInternalLocked(null, false /* fromTimeout */, |
| 1754 | true /* processPausingActivites */, null /* configuration */); |
| 1755 | |
| 1756 | // Move all the tasks to the bottom of the fullscreen stack |
Yunfan Chen | 279f558 | 2018-12-12 15:24:50 -0800 | [diff] [blame] | 1757 | moveTasksToFullscreenStackLocked(stack, !ON_TOP); |
Winson Chung | 010927a | 2016-12-15 16:12:35 -0800 | [diff] [blame] | 1758 | } else { |
| 1759 | for (int i = tasks.size() - 1; i >= 0; i--) { |
Wale Ogunwale | 4e79a1c | 2019-10-05 20:52:40 -0700 | [diff] [blame] | 1760 | removeTaskByIdLocked(tasks.get(i).mTaskId, true /* killProcess */, |
Winson Chung | 0ec2a35 | 2017-10-26 11:38:30 -0700 | [diff] [blame] | 1761 | REMOVE_FROM_RECENTS, "remove-stack"); |
Winson Chung | 010927a | 2016-12-15 16:12:35 -0800 | [diff] [blame] | 1762 | } |
| 1763 | } |
| 1764 | } |
| 1765 | |
| 1766 | /** |
Wale Ogunwale | a0f5b5e | 2017-10-11 09:37:23 -0700 | [diff] [blame] | 1767 | * 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] | 1768 | * pinned stack, then its tasks are not explicitly removed when the stack is destroyed, but |
| 1769 | * instead moved back onto the fullscreen stack. |
| 1770 | */ |
Wale Ogunwale | a0f5b5e | 2017-10-11 09:37:23 -0700 | [diff] [blame] | 1771 | void removeStack(ActivityStack stack) { |
| 1772 | mWindowManager.inSurfaceTransaction(() -> removeStackInSurfaceTransaction(stack)); |
Wale Ogunwale | 04a05ac | 2017-09-17 21:35:02 -0700 | [diff] [blame] | 1773 | } |
| 1774 | |
Wale Ogunwale | 6827856 | 2017-09-23 17:13:55 -0700 | [diff] [blame] | 1775 | /** |
Winson Chung | 010927a | 2016-12-15 16:12:35 -0800 | [diff] [blame] | 1776 | * Removes the task with the specified task id. |
| 1777 | * |
| 1778 | * @param taskId Identifier of the task to be removed. |
| 1779 | * @param killProcess Kill any process associated with the task if possible. |
| 1780 | * @param removeFromRecents Whether to also remove the task from recents. |
| 1781 | * @return Returns true if the given task was found and removed. |
| 1782 | */ |
Winson Chung | 6954fc9 | 2017-03-24 16:22:12 -0700 | [diff] [blame] | 1783 | boolean removeTaskByIdLocked(int taskId, boolean killProcess, boolean removeFromRecents, |
Louis Chang | 7b03ad9 | 2019-08-21 12:32:33 +0800 | [diff] [blame] | 1784 | String reason) { |
Louis Chang | cdec080 | 2019-11-11 11:45:07 +0800 | [diff] [blame] | 1785 | final Task task = |
Wale Ogunwale | d32da47 | 2018-11-16 07:19:28 -0800 | [diff] [blame] | 1786 | mRootActivityContainer.anyTaskForId(taskId, MATCH_TASK_IN_STACKS_OR_RECENT_TASKS); |
Louis Chang | cdec080 | 2019-11-11 11:45:07 +0800 | [diff] [blame] | 1787 | if (task != null) { |
| 1788 | task.removeTaskActivitiesLocked(reason); |
| 1789 | cleanUpRemovedTaskLocked(task, killProcess, removeFromRecents); |
| 1790 | mService.getLockTaskController().clearLockedTask(task); |
vincent.cw_lee | f59b813 | 2019-10-15 16:25:41 +0800 | [diff] [blame] | 1791 | mService.getTaskChangeNotificationController().notifyTaskStackChanged(); |
Louis Chang | cdec080 | 2019-11-11 11:45:07 +0800 | [diff] [blame] | 1792 | if (task.isPersistable) { |
Wale Ogunwale | c9e57de | 2018-05-08 14:28:07 -0700 | [diff] [blame] | 1793 | mService.notifyTaskPersisterLocked(null, true); |
Winson Chung | 010927a | 2016-12-15 16:12:35 -0800 | [diff] [blame] | 1794 | } |
| 1795 | return true; |
| 1796 | } |
| 1797 | Slog.w(TAG, "Request to remove task ignored for non-existent task " + taskId); |
| 1798 | return false; |
| 1799 | } |
| 1800 | |
Louis Chang | cdec080 | 2019-11-11 11:45:07 +0800 | [diff] [blame] | 1801 | void cleanUpRemovedTaskLocked(Task task, boolean killProcess, boolean removeFromRecents) { |
Winson Chung | 010927a | 2016-12-15 16:12:35 -0800 | [diff] [blame] | 1802 | if (removeFromRecents) { |
Louis Chang | cdec080 | 2019-11-11 11:45:07 +0800 | [diff] [blame] | 1803 | mRecentTasks.remove(task); |
Winson Chung | 010927a | 2016-12-15 16:12:35 -0800 | [diff] [blame] | 1804 | } |
Louis Chang | cdec080 | 2019-11-11 11:45:07 +0800 | [diff] [blame] | 1805 | ComponentName component = task.getBaseIntent().getComponent(); |
Winson Chung | 010927a | 2016-12-15 16:12:35 -0800 | [diff] [blame] | 1806 | if (component == null) { |
Louis Chang | cdec080 | 2019-11-11 11:45:07 +0800 | [diff] [blame] | 1807 | Slog.w(TAG, "No component for base intent of task: " + task); |
Winson Chung | 010927a | 2016-12-15 16:12:35 -0800 | [diff] [blame] | 1808 | return; |
| 1809 | } |
| 1810 | |
| 1811 | // Find any running services associated with this app and stop if needed. |
Wale Ogunwale | 342fbe9 | 2018-10-09 08:44:10 -0700 | [diff] [blame] | 1812 | final Message msg = PooledLambda.obtainMessage(ActivityManagerInternal::cleanUpServices, |
Louis Chang | cdec080 | 2019-11-11 11:45:07 +0800 | [diff] [blame] | 1813 | mService.mAmInternal, task.mUserId, component, new Intent(task.getBaseIntent())); |
Wale Ogunwale | 342fbe9 | 2018-10-09 08:44:10 -0700 | [diff] [blame] | 1814 | mService.mH.sendMessage(msg); |
Winson Chung | 010927a | 2016-12-15 16:12:35 -0800 | [diff] [blame] | 1815 | |
| 1816 | if (!killProcess) { |
| 1817 | return; |
| 1818 | } |
| 1819 | |
| 1820 | // Determine if the process(es) for this task should be killed. |
| 1821 | final String pkg = component.getPackageName(); |
Wale Ogunwale | 9e4f3e0 | 2018-05-17 09:35:39 -0700 | [diff] [blame] | 1822 | ArrayList<Object> procsToKill = new ArrayList<>(); |
| 1823 | ArrayMap<String, SparseArray<WindowProcessController>> pmap = |
| 1824 | mService.mProcessNames.getMap(); |
Winson Chung | 010927a | 2016-12-15 16:12:35 -0800 | [diff] [blame] | 1825 | for (int i = 0; i < pmap.size(); i++) { |
| 1826 | |
Wale Ogunwale | 9e4f3e0 | 2018-05-17 09:35:39 -0700 | [diff] [blame] | 1827 | SparseArray<WindowProcessController> uids = pmap.valueAt(i); |
Winson Chung | 010927a | 2016-12-15 16:12:35 -0800 | [diff] [blame] | 1828 | for (int j = 0; j < uids.size(); j++) { |
Wale Ogunwale | 9e4f3e0 | 2018-05-17 09:35:39 -0700 | [diff] [blame] | 1829 | WindowProcessController proc = uids.valueAt(j); |
Louis Chang | cdec080 | 2019-11-11 11:45:07 +0800 | [diff] [blame] | 1830 | if (proc.mUserId != task.mUserId) { |
Winson Chung | 010927a | 2016-12-15 16:12:35 -0800 | [diff] [blame] | 1831 | // Don't kill process for a different user. |
| 1832 | continue; |
| 1833 | } |
Wale Ogunwale | 9e4f3e0 | 2018-05-17 09:35:39 -0700 | [diff] [blame] | 1834 | if (proc == mService.mHomeProcess) { |
Winson Chung | 010927a | 2016-12-15 16:12:35 -0800 | [diff] [blame] | 1835 | // Don't kill the home process along with tasks from the same package. |
| 1836 | continue; |
| 1837 | } |
Wale Ogunwale | 9e4f3e0 | 2018-05-17 09:35:39 -0700 | [diff] [blame] | 1838 | if (!proc.mPkgList.contains(pkg)) { |
Winson Chung | 010927a | 2016-12-15 16:12:35 -0800 | [diff] [blame] | 1839 | // Don't kill process that is not associated with this task. |
| 1840 | continue; |
| 1841 | } |
| 1842 | |
Louis Chang | cdec080 | 2019-11-11 11:45:07 +0800 | [diff] [blame] | 1843 | if (!proc.shouldKillProcessForRemovedTask(task)) { |
Wale Ogunwale | 9e4f3e0 | 2018-05-17 09:35:39 -0700 | [diff] [blame] | 1844 | // Don't kill process(es) that has an activity in a different task that is also |
Yunfan Chen | afc1583 | 2018-07-26 16:34:28 +0900 | [diff] [blame] | 1845 | // in recents, or has an activity not stopped. |
Wale Ogunwale | 9e4f3e0 | 2018-05-17 09:35:39 -0700 | [diff] [blame] | 1846 | return; |
Winson Chung | 010927a | 2016-12-15 16:12:35 -0800 | [diff] [blame] | 1847 | } |
| 1848 | |
Wale Ogunwale | 9e4f3e0 | 2018-05-17 09:35:39 -0700 | [diff] [blame] | 1849 | if (proc.hasForegroundServices()) { |
Winson Chung | 010927a | 2016-12-15 16:12:35 -0800 | [diff] [blame] | 1850 | // Don't kill process(es) with foreground service. |
| 1851 | return; |
| 1852 | } |
| 1853 | |
| 1854 | // Add process to kill list. |
| 1855 | procsToKill.add(proc); |
| 1856 | } |
| 1857 | } |
| 1858 | |
Wale Ogunwale | 9e4f3e0 | 2018-05-17 09:35:39 -0700 | [diff] [blame] | 1859 | // Kill the running processes. Post on handle since we don't want to hold the service lock |
| 1860 | // while calling into AM. |
Yohei Yukawa | e2fa39e | 2018-09-22 13:13:10 -0700 | [diff] [blame] | 1861 | final Message m = PooledLambda.obtainMessage( |
Wale Ogunwale | 9e4f3e0 | 2018-05-17 09:35:39 -0700 | [diff] [blame] | 1862 | ActivityManagerInternal::killProcessesForRemovedTask, mService.mAmInternal, |
| 1863 | procsToKill); |
Yohei Yukawa | e2fa39e | 2018-09-22 13:13:10 -0700 | [diff] [blame] | 1864 | mService.mH.sendMessage(m); |
Winson Chung | 010927a | 2016-12-15 16:12:35 -0800 | [diff] [blame] | 1865 | } |
| 1866 | |
Chong Zhang | 5dcb275 | 2015-08-18 13:50:26 -0700 | [diff] [blame] | 1867 | /** |
Winson Chung | 1dbc811 | 2017-09-28 18:05:31 -0700 | [diff] [blame] | 1868 | * Called to restore the state of the task into the stack that it's supposed to go into. |
| 1869 | * |
Chong Zhang | 5dcb275 | 2015-08-18 13:50:26 -0700 | [diff] [blame] | 1870 | * @param task The recent task to be restored. |
Wale Ogunwale | 0568aed | 2017-09-08 13:29:37 -0700 | [diff] [blame] | 1871 | * @param aOptions The activity options to use for restoration. |
Wale Ogunwale | ab5de37 | 2017-10-18 06:46:31 -0700 | [diff] [blame] | 1872 | * @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] | 1873 | * @return true if the task has been restored successfully. |
| 1874 | */ |
Louis Chang | cdec080 | 2019-11-11 11:45:07 +0800 | [diff] [blame] | 1875 | boolean restoreRecentTaskLocked(Task task, ActivityOptions aOptions, boolean onTop) { |
Wale Ogunwale | d32da47 | 2018-11-16 07:19:28 -0800 | [diff] [blame] | 1876 | final ActivityStack stack = |
| 1877 | mRootActivityContainer.getLaunchStack(null, aOptions, task, onTop); |
Andrii Kulian | 02b7a83 | 2016-10-06 23:11:56 -0700 | [diff] [blame] | 1878 | final ActivityStack currentStack = task.getStack(); |
Wale Ogunwale | 2322bed | 2019-10-10 17:24:19 +0200 | [diff] [blame] | 1879 | |
| 1880 | if (currentStack == stack) { |
| 1881 | // Nothing else to do since it is already restored in the right stack. |
| 1882 | return true; |
Wale Ogunwale | 706ed79 | 2015-08-02 10:29:44 -0700 | [diff] [blame] | 1883 | } |
| 1884 | |
Wale Ogunwale | 2322bed | 2019-10-10 17:24:19 +0200 | [diff] [blame] | 1885 | if (currentStack != null) { |
| 1886 | // Task has already been restored once. Just re-parent it to the new stack. |
Wale Ogunwale | bebd8cd | 2019-10-28 15:53:31 -0700 | [diff] [blame] | 1887 | task.reparent(stack, POSITION_TOP, true /*moveParents*/, "restoreRecentTaskLocked"); |
Wale Ogunwale | 2322bed | 2019-10-10 17:24:19 +0200 | [diff] [blame] | 1888 | return true; |
| 1889 | } |
| 1890 | |
| 1891 | stack.addChild(task, onTop, true /* showForAllUsers */); |
Wale Ogunwale | ee006da | 2015-03-30 14:49:25 -0700 | [diff] [blame] | 1892 | if (DEBUG_RECENTS) Slog.v(TAG_RECENTS, |
| 1893 | "Added restored task=" + task + " to stack=" + stack); |
Wale Ogunwale | 7de0535 | 2014-12-12 15:21:33 -0800 | [diff] [blame] | 1894 | return true; |
Craig Mautner | ef73ee1 | 2014-04-23 11:45:37 -0700 | [diff] [blame] | 1895 | } |
| 1896 | |
Winson Chung | 1dbc811 | 2017-09-28 18:05:31 -0700 | [diff] [blame] | 1897 | @Override |
Louis Chang | cdec080 | 2019-11-11 11:45:07 +0800 | [diff] [blame] | 1898 | public void onRecentTaskAdded(Task task) { |
Winson Chung | 1dbc811 | 2017-09-28 18:05:31 -0700 | [diff] [blame] | 1899 | task.touchActiveTime(); |
| 1900 | } |
| 1901 | |
| 1902 | @Override |
Louis Chang | cdec080 | 2019-11-11 11:45:07 +0800 | [diff] [blame] | 1903 | public void onRecentTaskRemoved(Task task, boolean wasTrimmed, boolean killProcess) { |
Winson Chung | 0ec2a35 | 2017-10-26 11:38:30 -0700 | [diff] [blame] | 1904 | if (wasTrimmed) { |
| 1905 | // Task was trimmed from the recent tasks list -- remove the active task record as well |
| 1906 | // since the user won't really be able to go back to it |
Wale Ogunwale | 4e79a1c | 2019-10-05 20:52:40 -0700 | [diff] [blame] | 1907 | removeTaskByIdLocked(task.mTaskId, killProcess, false /* removeFromRecents */, |
Louis Chang | 7b03ad9 | 2019-08-21 12:32:33 +0800 | [diff] [blame] | 1908 | "recent-task-trimmed"); |
Winson Chung | 0ec2a35 | 2017-10-26 11:38:30 -0700 | [diff] [blame] | 1909 | } |
Winson Chung | 1dbc811 | 2017-09-28 18:05:31 -0700 | [diff] [blame] | 1910 | task.removedFromRecents(); |
| 1911 | } |
| 1912 | |
Wale Ogunwale | 040b470 | 2015-08-06 18:10:50 -0700 | [diff] [blame] | 1913 | /** |
Winson Chung | 7466610 | 2017-02-22 17:49:24 -0800 | [diff] [blame] | 1914 | * Returns the reparent target stack, creating the stack if necessary. This call also enforces |
| 1915 | * 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] | 1916 | */ |
Wale Ogunwale | 30e441d | 2017-11-09 08:28:45 -0800 | [diff] [blame] | 1917 | // TODO: Look into changing users to this method to ActivityDisplay.resolveWindowingMode() |
Louis Chang | cdec080 | 2019-11-11 11:45:07 +0800 | [diff] [blame] | 1918 | ActivityStack getReparentTargetStack(Task task, ActivityStack stack, boolean toTop) { |
Andrii Kulian | 02b7a83 | 2016-10-06 23:11:56 -0700 | [diff] [blame] | 1919 | final ActivityStack prevStack = task.getStack(); |
Wale Ogunwale | 04a05ac | 2017-09-17 21:35:02 -0700 | [diff] [blame] | 1920 | final int stackId = stack.mStackId; |
| 1921 | final boolean inMultiWindowMode = stack.inMultiWindowMode(); |
Chong Zhang | 0289835 | 2015-08-21 17:27:14 -0700 | [diff] [blame] | 1922 | |
Winson Chung | 7466610 | 2017-02-22 17:49:24 -0800 | [diff] [blame] | 1923 | // Check that we aren't reparenting to the same stack that the task is already in |
| 1924 | if (prevStack != null && prevStack.mStackId == stackId) { |
| 1925 | Slog.w(TAG, "Can not reparent to same stack, task=" + task |
| 1926 | + " already in stackId=" + stackId); |
| 1927 | return prevStack; |
Wale Ogunwale | 513346d | 2016-01-27 10:55:01 -0800 | [diff] [blame] | 1928 | } |
| 1929 | |
Winson Chung | 7466610 | 2017-02-22 17:49:24 -0800 | [diff] [blame] | 1930 | // Ensure that we aren't trying to move into a multi-window stack without multi-window |
| 1931 | // support |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 1932 | if (inMultiWindowMode && !mService.mSupportsMultiWindow) { |
Winson Chung | 7466610 | 2017-02-22 17:49:24 -0800 | [diff] [blame] | 1933 | throw new IllegalArgumentException("Device doesn't support multi-window, can not" |
Wale Ogunwale | 04a05ac | 2017-09-17 21:35:02 -0700 | [diff] [blame] | 1934 | + " reparent task=" + task + " to stack=" + stack); |
Winson Chung | c2baac0 | 2017-01-11 13:34:47 -0800 | [diff] [blame] | 1935 | } |
| 1936 | |
Andrii Kulian | eafd9db | 2017-04-05 22:01:35 -0700 | [diff] [blame] | 1937 | // Ensure that we're not moving a task to a dynamic stack if device doesn't support |
| 1938 | // multi-display. |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 1939 | if (stack.mDisplayId != DEFAULT_DISPLAY && !mService.mSupportsMultiDisplay) { |
Andrii Kulian | eafd9db | 2017-04-05 22:01:35 -0700 | [diff] [blame] | 1940 | throw new IllegalArgumentException("Device doesn't support multi-display, can not" |
| 1941 | + " reparent task=" + task + " to stackId=" + stackId); |
| 1942 | } |
| 1943 | |
Wale Ogunwale | 30e441d | 2017-11-09 08:28:45 -0800 | [diff] [blame] | 1944 | // 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] | 1945 | if (stack.getWindowingMode() == WINDOWING_MODE_FREEFORM |
Wale Ogunwale | a6191b4 | 2018-05-09 07:41:32 -0700 | [diff] [blame] | 1946 | && !mService.mSupportsFreeformWindowManagement) { |
Winson Chung | 7466610 | 2017-02-22 17:49:24 -0800 | [diff] [blame] | 1947 | throw new IllegalArgumentException("Device doesn't support freeform, can not reparent" |
| 1948 | + " task=" + task); |
Wale Ogunwale | 08559dc | 2016-02-23 12:20:08 -0800 | [diff] [blame] | 1949 | } |
| 1950 | |
Wale Ogunwale | 7e1f5f5 | 2017-10-18 15:19:59 -0700 | [diff] [blame] | 1951 | // Leave the task in its current stack or a fullscreen stack if it isn't resizeable and the |
| 1952 | // preferred stack is in multi-window mode. |
Wale Ogunwale | 04a05ac | 2017-09-17 21:35:02 -0700 | [diff] [blame] | 1953 | if (inMultiWindowMode && !task.isResizeable()) { |
Wale Ogunwale | 7e1f5f5 | 2017-10-18 15:19:59 -0700 | [diff] [blame] | 1954 | Slog.w(TAG, "Can not move unresizeable task=" + task + " to multi-window stack=" + stack |
| 1955 | + " Moving to a fullscreen stack instead."); |
| 1956 | if (prevStack != null) { |
| 1957 | return prevStack; |
Wale Ogunwale | 04a05ac | 2017-09-17 21:35:02 -0700 | [diff] [blame] | 1958 | } |
Wale Ogunwale | 7e1f5f5 | 2017-10-18 15:19:59 -0700 | [diff] [blame] | 1959 | stack = stack.getDisplay().createStack( |
| 1960 | WINDOWING_MODE_FULLSCREEN, stack.getActivityType(), toTop); |
Filip Gruszczynski | 49b80af | 2015-09-24 09:04:26 -0700 | [diff] [blame] | 1961 | } |
Wale Ogunwale | 04a05ac | 2017-09-17 21:35:02 -0700 | [diff] [blame] | 1962 | return stack; |
Craig Mautner | 8d341ef | 2013-03-26 09:03:27 -0700 | [diff] [blame] | 1963 | } |
| 1964 | |
| 1965 | void goingToSleepLocked() { |
Craig Mautner | 0eea92c | 2013-05-16 13:35:39 -0700 | [diff] [blame] | 1966 | scheduleSleepTimeout(); |
Andrii Kulian | c598b2d | 2019-02-07 17:16:38 -0800 | [diff] [blame] | 1967 | if (!mGoingToSleepWakeLock.isHeld()) { |
| 1968 | mGoingToSleepWakeLock.acquire(); |
| 1969 | if (mLaunchingActivityWakeLock.isHeld()) { |
Craig Mautner | 7ea5bd4 | 2013-07-05 15:27:08 -0700 | [diff] [blame] | 1970 | if (VALIDATE_WAKE_LOCK_CALLER && Binder.getCallingUid() != Process.myUid()) { |
| 1971 | throw new IllegalStateException("Calling must be system uid"); |
Craig Mautner | 0eea92c | 2013-05-16 13:35:39 -0700 | [diff] [blame] | 1972 | } |
Andrii Kulian | c598b2d | 2019-02-07 17:16:38 -0800 | [diff] [blame] | 1973 | mLaunchingActivityWakeLock.release(); |
Wale Ogunwale | 342fbe9 | 2018-10-09 08:44:10 -0700 | [diff] [blame] | 1974 | mHandler.removeMessages(LAUNCH_TIMEOUT_MSG); |
Craig Mautner | 0eea92c | 2013-05-16 13:35:39 -0700 | [diff] [blame] | 1975 | } |
Craig Mautner | 8d341ef | 2013-03-26 09:03:27 -0700 | [diff] [blame] | 1976 | } |
David Stevens | 9440dc8 | 2017-03-16 19:00:20 -0700 | [diff] [blame] | 1977 | |
Wale Ogunwale | d32da47 | 2018-11-16 07:19:28 -0800 | [diff] [blame] | 1978 | mRootActivityContainer.applySleepTokens(false /* applyToStacks */); |
David Stevens | 9440dc8 | 2017-03-16 19:00:20 -0700 | [diff] [blame] | 1979 | |
| 1980 | checkReadyForSleepLocked(true /* allowDelay */); |
| 1981 | } |
| 1982 | |
Craig Mautner | 8d341ef | 2013-03-26 09:03:27 -0700 | [diff] [blame] | 1983 | boolean shutdownLocked(int timeout) { |
Craig Mautner | 0eea92c | 2013-05-16 13:35:39 -0700 | [diff] [blame] | 1984 | goingToSleepLocked(); |
Craig Mautner | 0eea92c | 2013-05-16 13:35:39 -0700 | [diff] [blame] | 1985 | |
Craig Mautner | f4c909b | 2014-04-17 18:39:38 -0700 | [diff] [blame] | 1986 | boolean timedout = false; |
Craig Mautner | 0eea92c | 2013-05-16 13:35:39 -0700 | [diff] [blame] | 1987 | final long endTime = System.currentTimeMillis() + timeout; |
| 1988 | while (true) { |
Wale Ogunwale | d32da47 | 2018-11-16 07:19:28 -0800 | [diff] [blame] | 1989 | if (!mRootActivityContainer.putStacksToSleep( |
| 1990 | true /* allowDelay */, true /* shuttingDown */)) { |
Craig Mautner | 0eea92c | 2013-05-16 13:35:39 -0700 | [diff] [blame] | 1991 | long timeRemaining = endTime - System.currentTimeMillis(); |
| 1992 | if (timeRemaining > 0) { |
Craig Mautner | 8d341ef | 2013-03-26 09:03:27 -0700 | [diff] [blame] | 1993 | try { |
Wale Ogunwale | f673393 | 2018-06-27 05:14:34 -0700 | [diff] [blame] | 1994 | mService.mGlobalLock.wait(timeRemaining); |
Craig Mautner | 8d341ef | 2013-03-26 09:03:27 -0700 | [diff] [blame] | 1995 | } catch (InterruptedException e) { |
| 1996 | } |
Craig Mautner | 0eea92c | 2013-05-16 13:35:39 -0700 | [diff] [blame] | 1997 | } else { |
| 1998 | Slog.w(TAG, "Activity manager shutdown timed out"); |
| 1999 | timedout = true; |
| 2000 | break; |
Craig Mautner | 8d341ef | 2013-03-26 09:03:27 -0700 | [diff] [blame] | 2001 | } |
Craig Mautner | 0eea92c | 2013-05-16 13:35:39 -0700 | [diff] [blame] | 2002 | } else { |
| 2003 | break; |
Craig Mautner | 8d341ef | 2013-03-26 09:03:27 -0700 | [diff] [blame] | 2004 | } |
| 2005 | } |
Craig Mautner | 0eea92c | 2013-05-16 13:35:39 -0700 | [diff] [blame] | 2006 | |
| 2007 | // Force checkReadyForSleep to complete. |
David Stevens | 9440dc8 | 2017-03-16 19:00:20 -0700 | [diff] [blame] | 2008 | checkReadyForSleepLocked(false /* allowDelay */); |
Craig Mautner | 0eea92c | 2013-05-16 13:35:39 -0700 | [diff] [blame] | 2009 | |
Craig Mautner | 8d341ef | 2013-03-26 09:03:27 -0700 | [diff] [blame] | 2010 | return timedout; |
| 2011 | } |
| 2012 | |
| 2013 | void comeOutOfSleepIfNeededLocked() { |
Craig Mautner | 0eea92c | 2013-05-16 13:35:39 -0700 | [diff] [blame] | 2014 | removeSleepTimeouts(); |
Andrii Kulian | c598b2d | 2019-02-07 17:16:38 -0800 | [diff] [blame] | 2015 | if (mGoingToSleepWakeLock.isHeld()) { |
| 2016 | mGoingToSleepWakeLock.release(); |
Craig Mautner | 0eea92c | 2013-05-16 13:35:39 -0700 | [diff] [blame] | 2017 | } |
David Stevens | 9440dc8 | 2017-03-16 19:00:20 -0700 | [diff] [blame] | 2018 | } |
| 2019 | |
Craig Mautner | 0eea92c | 2013-05-16 13:35:39 -0700 | [diff] [blame] | 2020 | void activitySleptLocked(ActivityRecord r) { |
| 2021 | mGoingToSleepActivities.remove(r); |
Wale Ogunwale | 8b19de9 | 2018-11-29 19:58:26 -0800 | [diff] [blame] | 2022 | final ActivityStack s = r.getActivityStack(); |
David Stevens | 9440dc8 | 2017-03-16 19:00:20 -0700 | [diff] [blame] | 2023 | if (s != null) { |
| 2024 | s.checkReadyForSleep(); |
| 2025 | } else { |
| 2026 | checkReadyForSleepLocked(true); |
| 2027 | } |
Craig Mautner | 0eea92c | 2013-05-16 13:35:39 -0700 | [diff] [blame] | 2028 | } |
| 2029 | |
David Stevens | 9440dc8 | 2017-03-16 19:00:20 -0700 | [diff] [blame] | 2030 | void checkReadyForSleepLocked(boolean allowDelay) { |
Wale Ogunwale | f673393 | 2018-06-27 05:14:34 -0700 | [diff] [blame] | 2031 | if (!mService.isSleepingOrShuttingDownLocked()) { |
Craig Mautner | 0eea92c | 2013-05-16 13:35:39 -0700 | [diff] [blame] | 2032 | // Do not care. |
| 2033 | return; |
| 2034 | } |
| 2035 | |
Wale Ogunwale | d32da47 | 2018-11-16 07:19:28 -0800 | [diff] [blame] | 2036 | if (!mRootActivityContainer.putStacksToSleep( |
| 2037 | allowDelay, false /* shuttingDown */)) { |
David Stevens | 18abd0e | 2017-08-17 14:55:47 -0700 | [diff] [blame] | 2038 | return; |
Craig Mautner | 0eea92c | 2013-05-16 13:35:39 -0700 | [diff] [blame] | 2039 | } |
| 2040 | |
Wei Wang | 65c7a15 | 2016-06-02 18:51:22 -0700 | [diff] [blame] | 2041 | // Send launch end powerhint before going sleep |
Wale Ogunwale | d32da47 | 2018-11-16 07:19:28 -0800 | [diff] [blame] | 2042 | mRootActivityContainer.sendPowerHintForLaunchEndIfNeeded(); |
Wei Wang | 65c7a15 | 2016-06-02 18:51:22 -0700 | [diff] [blame] | 2043 | |
Craig Mautner | 0eea92c | 2013-05-16 13:35:39 -0700 | [diff] [blame] | 2044 | removeSleepTimeouts(); |
| 2045 | |
Andrii Kulian | c598b2d | 2019-02-07 17:16:38 -0800 | [diff] [blame] | 2046 | if (mGoingToSleepWakeLock.isHeld()) { |
| 2047 | mGoingToSleepWakeLock.release(); |
Craig Mautner | 0eea92c | 2013-05-16 13:35:39 -0700 | [diff] [blame] | 2048 | } |
Wale Ogunwale | f673393 | 2018-06-27 05:14:34 -0700 | [diff] [blame] | 2049 | if (mService.mShuttingDown) { |
| 2050 | mService.mGlobalLock.notifyAll(); |
Craig Mautner | 0eea92c | 2013-05-16 13:35:39 -0700 | [diff] [blame] | 2051 | } |
Craig Mautner | 8d341ef | 2013-03-26 09:03:27 -0700 | [diff] [blame] | 2052 | } |
| 2053 | |
Craig Mautner | ce5f3cb | 2013-04-22 08:58:54 -0700 | [diff] [blame] | 2054 | boolean reportResumedActivityLocked(ActivityRecord r) { |
Bryce Lee | 29a649d | 2017-08-18 13:52:31 -0700 | [diff] [blame] | 2055 | // A resumed activity cannot be stopping. remove from list |
| 2056 | mStoppingActivities.remove(r); |
| 2057 | |
Wale Ogunwale | 8b19de9 | 2018-11-29 19:58:26 -0800 | [diff] [blame] | 2058 | final ActivityStack stack = r.getActivityStack(); |
Riddle Hsu | bbb63c2 | 2018-10-03 12:28:29 +0800 | [diff] [blame] | 2059 | if (stack.getDisplay().allResumedActivitiesComplete()) { |
Wale Ogunwale | d32da47 | 2018-11-16 07:19:28 -0800 | [diff] [blame] | 2060 | mRootActivityContainer.ensureActivitiesVisible(null, 0, !PRESERVE_WINDOWS); |
lumark | 588a3e8 | 2018-07-20 18:53:54 +0800 | [diff] [blame] | 2061 | // Make sure activity & window visibility should be identical |
| 2062 | // for all displays in this stage. |
Wale Ogunwale | d32da47 | 2018-11-16 07:19:28 -0800 | [diff] [blame] | 2063 | mRootActivityContainer.executeAppTransitionForAllDisplay(); |
Craig Mautner | ce5f3cb | 2013-04-22 08:58:54 -0700 | [diff] [blame] | 2064 | return true; |
| 2065 | } |
| 2066 | return false; |
| 2067 | } |
| 2068 | |
Craig Mautner | bb74246 | 2014-07-07 15:28:55 -0700 | [diff] [blame] | 2069 | // Called when WindowManager has finished animating the launchingBehind activity to the back. |
Andrii Kulian | 21713ac | 2016-10-12 22:05:05 -0700 | [diff] [blame] | 2070 | private void handleLaunchTaskBehindCompleteLocked(ActivityRecord r) { |
Louis Chang | cdec080 | 2019-11-11 11:45:07 +0800 | [diff] [blame] | 2071 | final Task task = r.getTask(); |
Andrii Kulian | 02b7a83 | 2016-10-06 23:11:56 -0700 | [diff] [blame] | 2072 | final ActivityStack stack = task.getStack(); |
Winson | 730bf06 | 2016-03-31 18:04:56 -0700 | [diff] [blame] | 2073 | |
Winson Chung | 1dbc811 | 2017-09-28 18:05:31 -0700 | [diff] [blame] | 2074 | mRecentTasks.add(task); |
Wale Ogunwale | c9e57de | 2018-05-08 14:28:07 -0700 | [diff] [blame] | 2075 | mService.getTaskChangeNotificationController().notifyTaskStackChanged(); |
Louis Chang | 3731715 | 2019-05-09 09:53:58 +0800 | [diff] [blame] | 2076 | stack.ensureActivitiesVisibleLocked(null, 0, !PRESERVE_WINDOWS); |
Winson | 730bf06 | 2016-03-31 18:04:56 -0700 | [diff] [blame] | 2077 | |
| 2078 | // When launching tasks behind, update the last active time of the top task after the new |
| 2079 | // task has been shown briefly |
Wale Ogunwale | 21e0648 | 2019-11-18 05:14:15 -0800 | [diff] [blame] | 2080 | final ActivityRecord top = stack.getTopNonFinishingActivity(); |
Winson | 730bf06 | 2016-03-31 18:04:56 -0700 | [diff] [blame] | 2081 | if (top != null) { |
Louis Chang | cdec080 | 2019-11-11 11:45:07 +0800 | [diff] [blame] | 2082 | top.getTask().touchActiveTime(); |
Winson | 730bf06 | 2016-03-31 18:04:56 -0700 | [diff] [blame] | 2083 | } |
Craig Mautner | bb74246 | 2014-07-07 15:28:55 -0700 | [diff] [blame] | 2084 | } |
| 2085 | |
| 2086 | void scheduleLaunchTaskBehindComplete(IBinder token) { |
| 2087 | mHandler.obtainMessage(LAUNCH_TASK_BEHIND_COMPLETE, token).sendToTarget(); |
| 2088 | } |
| 2089 | |
Wale Ogunwale | 0bd2aa7 | 2015-04-16 13:50:44 -0700 | [diff] [blame] | 2090 | /** Checks whether the userid is a profile of the current user. */ |
| 2091 | boolean isCurrentProfileLocked(int userId) { |
Wale Ogunwale | d32da47 | 2018-11-16 07:19:28 -0800 | [diff] [blame] | 2092 | if (userId == mRootActivityContainer.mCurrentUser) return true; |
Wale Ogunwale | 86b7446 | 2018-07-02 08:42:43 -0700 | [diff] [blame] | 2093 | return mService.mAmInternal.isCurrentProfile(userId); |
Wale Ogunwale | 0bd2aa7 | 2015-04-16 13:50:44 -0700 | [diff] [blame] | 2094 | } |
| 2095 | |
Bryce Lee | b7c9b80 | 2017-05-02 14:20:24 -0700 | [diff] [blame] | 2096 | /** |
| 2097 | * Returns whether a stopping activity is present that should be stopped after visible, rather |
| 2098 | * than idle. |
| 2099 | * @return {@code true} if such activity is present. {@code false} otherwise. |
| 2100 | */ |
| 2101 | boolean isStoppingNoHistoryActivity() { |
| 2102 | // Activities that are marked as nohistory should be stopped immediately after the resumed |
| 2103 | // activity has become visible. |
| 2104 | for (ActivityRecord record : mStoppingActivities) { |
| 2105 | if (record.isNoHistory()) { |
| 2106 | return true; |
| 2107 | } |
| 2108 | } |
| 2109 | |
| 2110 | return false; |
| 2111 | } |
| 2112 | |
Wale Ogunwale | da8b827 | 2018-11-29 19:37:37 -0800 | [diff] [blame] | 2113 | // TODO: Change method name to reflect what it actually does. |
Winson Chung | 4dabf23 | 2017-01-25 13:25:22 -0800 | [diff] [blame] | 2114 | final ArrayList<ActivityRecord> processStoppingActivitiesLocked(ActivityRecord idleActivity, |
| 2115 | boolean remove, boolean processPausingActivities) { |
Craig Mautner | de4ef02 | 2013-04-07 19:01:33 -0700 | [diff] [blame] | 2116 | ArrayList<ActivityRecord> stops = null; |
| 2117 | |
Wale Ogunwale | d32da47 | 2018-11-16 07:19:28 -0800 | [diff] [blame] | 2118 | final boolean nowVisible = mRootActivityContainer.allResumedActivitiesVisible(); |
Craig Mautner | 8c14c15 | 2015-01-15 17:32:07 -0800 | [diff] [blame] | 2119 | for (int activityNdx = mStoppingActivities.size() - 1; activityNdx >= 0; --activityNdx) { |
| 2120 | ActivityRecord s = mStoppingActivities.get(activityNdx); |
Jorim Jaggi | 9b5e331 | 2019-03-01 18:08:00 +0100 | [diff] [blame] | 2121 | |
lumark | 9bca6b4 | 2019-10-17 18:35:22 +0800 | [diff] [blame] | 2122 | final boolean animating = s.isAnimating(TRANSITION); |
Jorim Jaggi | 9b5e331 | 2019-03-01 18:08:00 +0100 | [diff] [blame] | 2123 | |
Wale Ogunwale | f81c1d1 | 2016-01-12 12:20:18 -0800 | [diff] [blame] | 2124 | if (DEBUG_STATES) Slog.v(TAG, "Stopping " + s + ": nowVisible=" + nowVisible |
Jorim Jaggi | 9b5e331 | 2019-03-01 18:08:00 +0100 | [diff] [blame] | 2125 | + " animating=" + animating + " finishing=" + s.finishing); |
| 2126 | if (nowVisible && s.finishing) { |
| 2127 | |
| 2128 | // If this activity is finishing, it is sitting on top of |
| 2129 | // everyone else but we now know it is no longer needed... |
| 2130 | // so get rid of it. Otherwise, we need to go through the |
| 2131 | // normal flow and hide it once we determine that it is |
| 2132 | // hidden by the activities in front of it. |
| 2133 | if (DEBUG_STATES) Slog.v(TAG, "Before stopping, can hide: " + s); |
| 2134 | s.setVisibility(false); |
Craig Mautner | de4ef02 | 2013-04-07 19:01:33 -0700 | [diff] [blame] | 2135 | } |
David Stevens | 9440dc8 | 2017-03-16 19:00:20 -0700 | [diff] [blame] | 2136 | if (remove) { |
Wale Ogunwale | 8b19de9 | 2018-11-29 19:58:26 -0800 | [diff] [blame] | 2137 | final ActivityStack stack = s.getActivityStack(); |
David Stevens | 9440dc8 | 2017-03-16 19:00:20 -0700 | [diff] [blame] | 2138 | final boolean shouldSleepOrShutDown = stack != null |
| 2139 | ? stack.shouldSleepOrShutDownActivities() |
Wale Ogunwale | f673393 | 2018-06-27 05:14:34 -0700 | [diff] [blame] | 2140 | : mService.isSleepingOrShuttingDownLocked(); |
Jorim Jaggi | 9b5e331 | 2019-03-01 18:08:00 +0100 | [diff] [blame] | 2141 | if (!animating || shouldSleepOrShutDown) { |
Bryce Lee | 7ace395 | 2018-02-16 14:34:32 -0800 | [diff] [blame] | 2142 | if (!processPausingActivities && s.isState(PAUSING)) { |
David Stevens | 9440dc8 | 2017-03-16 19:00:20 -0700 | [diff] [blame] | 2143 | // Defer processing pausing activities in this iteration and reschedule |
| 2144 | // a delayed idle to reprocess it again |
| 2145 | removeTimeoutsForActivityLocked(idleActivity); |
| 2146 | scheduleIdleTimeoutLocked(idleActivity); |
| 2147 | continue; |
| 2148 | } |
Winson Chung | 4dabf23 | 2017-01-25 13:25:22 -0800 | [diff] [blame] | 2149 | |
David Stevens | 9440dc8 | 2017-03-16 19:00:20 -0700 | [diff] [blame] | 2150 | if (DEBUG_STATES) Slog.v(TAG, "Ready to stop: " + s); |
| 2151 | if (stops == null) { |
| 2152 | stops = new ArrayList<>(); |
| 2153 | } |
| 2154 | stops.add(s); |
Jorim Jaggi | 5db9ae4 | 2018-06-25 16:14:50 +0200 | [diff] [blame] | 2155 | |
David Stevens | 9440dc8 | 2017-03-16 19:00:20 -0700 | [diff] [blame] | 2156 | mStoppingActivities.remove(activityNdx); |
Craig Mautner | de4ef02 | 2013-04-07 19:01:33 -0700 | [diff] [blame] | 2157 | } |
Craig Mautner | de4ef02 | 2013-04-07 19:01:33 -0700 | [diff] [blame] | 2158 | } |
| 2159 | } |
| 2160 | |
| 2161 | return stops; |
| 2162 | } |
| 2163 | |
Craig Mautner | 2708430 | 2013-03-25 08:05:25 -0700 | [diff] [blame] | 2164 | public void dump(PrintWriter pw, String prefix) { |
Riddle Hsu | 7501699 | 2018-09-20 20:37:14 +0800 | [diff] [blame] | 2165 | pw.println(); |
| 2166 | pw.println("ActivityStackSupervisor state:"); |
Wale Ogunwale | d32da47 | 2018-11-16 07:19:28 -0800 | [diff] [blame] | 2167 | mRootActivityContainer.dump(pw, prefix); |
Riddle Hsu | 7501699 | 2018-09-20 20:37:14 +0800 | [diff] [blame] | 2168 | pw.print(prefix); |
Suprabh Shukla | 09a88f5 | 2015-12-02 14:36:31 -0800 | [diff] [blame] | 2169 | pw.println("mCurTaskIdForUser=" + mCurTaskIdForUser); |
Wale Ogunwale | d32da47 | 2018-11-16 07:19:28 -0800 | [diff] [blame] | 2170 | pw.println(prefix + "mUserStackInFront=" + mRootActivityContainer.mUserStackInFront); |
Bryce Lee | 4a19438 | 2017-04-04 14:32:48 -0700 | [diff] [blame] | 2171 | if (!mWaitingForActivityVisible.isEmpty()) { |
Wale Ogunwale | d32da47 | 2018-11-16 07:19:28 -0800 | [diff] [blame] | 2172 | pw.println(prefix + "mWaitingForActivityVisible="); |
Bryce Lee | 4a19438 | 2017-04-04 14:32:48 -0700 | [diff] [blame] | 2173 | for (int i = 0; i < mWaitingForActivityVisible.size(); ++i) { |
Wale Ogunwale | d32da47 | 2018-11-16 07:19:28 -0800 | [diff] [blame] | 2174 | pw.print(prefix + prefix); mWaitingForActivityVisible.get(i).dump(pw, prefix); |
Bryce Lee | 4a19438 | 2017-04-04 14:32:48 -0700 | [diff] [blame] | 2175 | } |
| 2176 | } |
Winson Chung | c167427 | 2018-02-21 10:15:17 -0800 | [diff] [blame] | 2177 | pw.print(prefix); pw.print("isHomeRecentsComponent="); |
Wale Ogunwale | d32da47 | 2018-11-16 07:19:28 -0800 | [diff] [blame] | 2178 | pw.print(mRecentTasks.isRecentsComponentHomeActivity(mRootActivityContainer.mCurrentUser)); |
Bryce Lee | 4a19438 | 2017-04-04 14:32:48 -0700 | [diff] [blame] | 2179 | |
Bryce Lee | 459c062 | 2018-03-19 11:04:01 -0700 | [diff] [blame] | 2180 | getKeyguardController().dump(pw, prefix); |
Wale Ogunwale | c9e57de | 2018-05-08 14:28:07 -0700 | [diff] [blame] | 2181 | mService.getLockTaskController().dump(pw, prefix); |
Craig Mautner | 2708430 | 2013-03-25 08:05:25 -0700 | [diff] [blame] | 2182 | } |
Craig Mautner | 8d341ef | 2013-03-26 09:03:27 -0700 | [diff] [blame] | 2183 | |
Dianne Hackborn | 390517b | 2013-05-30 15:03:32 -0700 | [diff] [blame] | 2184 | static boolean printThisActivity(PrintWriter pw, ActivityRecord activity, String dumpPackage, |
| 2185 | boolean needSep, String prefix) { |
| 2186 | if (activity != null) { |
| 2187 | if (dumpPackage == null || dumpPackage.equals(activity.packageName)) { |
| 2188 | if (needSep) { |
| 2189 | pw.println(); |
Dianne Hackborn | 390517b | 2013-05-30 15:03:32 -0700 | [diff] [blame] | 2190 | } |
| 2191 | pw.print(prefix); |
| 2192 | pw.println(activity); |
Dianne Hackborn | 7ad34e5 | 2013-06-05 18:41:45 -0700 | [diff] [blame] | 2193 | return true; |
Dianne Hackborn | 390517b | 2013-05-30 15:03:32 -0700 | [diff] [blame] | 2194 | } |
| 2195 | } |
Dianne Hackborn | 7ad34e5 | 2013-06-05 18:41:45 -0700 | [diff] [blame] | 2196 | return false; |
Dianne Hackborn | 390517b | 2013-05-30 15:03:32 -0700 | [diff] [blame] | 2197 | } |
| 2198 | |
Dianne Hackborn | 390517b | 2013-05-30 15:03:32 -0700 | [diff] [blame] | 2199 | static boolean dumpHistoryList(FileDescriptor fd, PrintWriter pw, List<ActivityRecord> list, |
Craig Mautner | 8d341ef | 2013-03-26 09:03:27 -0700 | [diff] [blame] | 2200 | String prefix, String label, boolean complete, boolean brief, boolean client, |
Louis Chang | cdec080 | 2019-11-11 11:45:07 +0800 | [diff] [blame] | 2201 | String dumpPackage, boolean needNL, String header, Task lastTask) { |
Dianne Hackborn | 390517b | 2013-05-30 15:03:32 -0700 | [diff] [blame] | 2202 | String innerPrefix = null; |
| 2203 | String[] args = null; |
| 2204 | boolean printed = false; |
Craig Mautner | 8d341ef | 2013-03-26 09:03:27 -0700 | [diff] [blame] | 2205 | for (int i=list.size()-1; i>=0; i--) { |
| 2206 | final ActivityRecord r = list.get(i); |
| 2207 | if (dumpPackage != null && !dumpPackage.equals(r.packageName)) { |
| 2208 | continue; |
| 2209 | } |
Dianne Hackborn | 390517b | 2013-05-30 15:03:32 -0700 | [diff] [blame] | 2210 | if (innerPrefix == null) { |
| 2211 | innerPrefix = prefix + " "; |
| 2212 | args = new String[0]; |
| 2213 | } |
| 2214 | printed = true; |
Craig Mautner | 8d341ef | 2013-03-26 09:03:27 -0700 | [diff] [blame] | 2215 | final boolean full = !brief && (complete || !r.isInHistory()); |
| 2216 | if (needNL) { |
Dianne Hackborn | 390517b | 2013-05-30 15:03:32 -0700 | [diff] [blame] | 2217 | pw.println(""); |
Craig Mautner | 8d341ef | 2013-03-26 09:03:27 -0700 | [diff] [blame] | 2218 | needNL = false; |
| 2219 | } |
Wale Ogunwale | 34a5b57 | 2017-08-31 08:29:41 -0700 | [diff] [blame] | 2220 | if (header != null) { |
| 2221 | pw.println(header); |
| 2222 | header = null; |
Dianne Hackborn | 390517b | 2013-05-30 15:03:32 -0700 | [diff] [blame] | 2223 | } |
Louis Chang | cdec080 | 2019-11-11 11:45:07 +0800 | [diff] [blame] | 2224 | if (lastTask != r.getTask()) { |
| 2225 | lastTask = r.getTask(); |
Craig Mautner | 8d341ef | 2013-03-26 09:03:27 -0700 | [diff] [blame] | 2226 | pw.print(prefix); |
| 2227 | pw.print(full ? "* " : " "); |
| 2228 | pw.println(lastTask); |
| 2229 | if (full) { |
| 2230 | lastTask.dump(pw, prefix + " "); |
| 2231 | } else if (complete) { |
| 2232 | // Complete + brief == give a summary. Isn't that obvious?!? |
| 2233 | if (lastTask.intent != null) { |
| 2234 | pw.print(prefix); pw.print(" "); |
Hui Yu | 6d5c3b9 | 2019-10-22 15:35:53 -0700 | [diff] [blame] | 2235 | pw.println(lastTask.intent.toInsecureString()); |
Craig Mautner | 8d341ef | 2013-03-26 09:03:27 -0700 | [diff] [blame] | 2236 | } |
| 2237 | } |
| 2238 | } |
| 2239 | pw.print(prefix); pw.print(full ? " * " : " "); pw.print(label); |
| 2240 | pw.print(" #"); pw.print(i); pw.print(": "); |
| 2241 | pw.println(r); |
| 2242 | if (full) { |
Garfield Tan | e8d84ab | 2019-10-11 09:49:40 -0700 | [diff] [blame] | 2243 | r.dump(pw, innerPrefix, true /* dumpAll */); |
Craig Mautner | 8d341ef | 2013-03-26 09:03:27 -0700 | [diff] [blame] | 2244 | } else if (complete) { |
| 2245 | // Complete + brief == give a summary. Isn't that obvious?!? |
| 2246 | pw.print(innerPrefix); pw.println(r.intent.toInsecureString()); |
| 2247 | if (r.app != null) { |
| 2248 | pw.print(innerPrefix); pw.println(r.app); |
| 2249 | } |
| 2250 | } |
Wale Ogunwale | 9e4f3e0 | 2018-05-17 09:35:39 -0700 | [diff] [blame] | 2251 | if (client && r.attachedToProcess()) { |
Craig Mautner | 8d341ef | 2013-03-26 09:03:27 -0700 | [diff] [blame] | 2252 | // flush anything that is already in the PrintWriter since the thread is going |
| 2253 | // to write to the file descriptor directly |
| 2254 | pw.flush(); |
| 2255 | try { |
| 2256 | TransferPipe tp = new TransferPipe(); |
| 2257 | try { |
Wale Ogunwale | 9e4f3e0 | 2018-05-17 09:35:39 -0700 | [diff] [blame] | 2258 | r.app.getThread().dumpActivity( |
| 2259 | tp.getWriteFd(), r.appToken, innerPrefix, args); |
| 2260 | // Short timeout, since blocking here can deadlock with the application. |
Craig Mautner | 8d341ef | 2013-03-26 09:03:27 -0700 | [diff] [blame] | 2261 | tp.go(fd, 2000); |
| 2262 | } finally { |
| 2263 | tp.kill(); |
| 2264 | } |
| 2265 | } catch (IOException e) { |
| 2266 | pw.println(innerPrefix + "Failure while dumping the activity: " + e); |
| 2267 | } catch (RemoteException e) { |
| 2268 | pw.println(innerPrefix + "Got a RemoteException while dumping the activity"); |
| 2269 | } |
| 2270 | needNL = true; |
| 2271 | } |
| 2272 | } |
Dianne Hackborn | 390517b | 2013-05-30 15:03:32 -0700 | [diff] [blame] | 2273 | return printed; |
Craig Mautner | 8d341ef | 2013-03-26 09:03:27 -0700 | [diff] [blame] | 2274 | } |
Craig Mautner | ce5f3cb | 2013-04-22 08:58:54 -0700 | [diff] [blame] | 2275 | |
Craig Mautner | f333327 | 2013-04-22 10:55:53 -0700 | [diff] [blame] | 2276 | void scheduleIdleTimeoutLocked(ActivityRecord next) { |
Wale Ogunwale | 0fc365c | 2015-05-25 19:35:42 -0700 | [diff] [blame] | 2277 | if (DEBUG_IDLE) Slog.d(TAG_IDLE, |
| 2278 | "scheduleIdleTimeoutLocked: Callers=" + Debug.getCallers(4)); |
Craig Mautner | c64f73e | 2013-04-24 16:44:56 -0700 | [diff] [blame] | 2279 | Message msg = mHandler.obtainMessage(IDLE_TIMEOUT_MSG, next); |
| 2280 | mHandler.sendMessageDelayed(msg, IDLE_TIMEOUT); |
Craig Mautner | f333327 | 2013-04-22 10:55:53 -0700 | [diff] [blame] | 2281 | } |
| 2282 | |
| 2283 | final void scheduleIdleLocked() { |
Craig Mautner | 05d2903 | 2013-05-03 13:40:13 -0700 | [diff] [blame] | 2284 | mHandler.sendEmptyMessage(IDLE_NOW_MSG); |
Craig Mautner | f333327 | 2013-04-22 10:55:53 -0700 | [diff] [blame] | 2285 | } |
| 2286 | |
Andrii Kulian | 86e70fc | 2019-02-12 11:04:10 +0000 | [diff] [blame] | 2287 | /** |
| 2288 | * Updates the record of top resumed activity when it changes and handles reporting of the |
| 2289 | * state changes to previous and new top activities. It will immediately dispatch top resumed |
| 2290 | * state loss message to previous top activity (if haven't done it already). After the previous |
| 2291 | * activity releases the top state and reports back, message about acquiring top state will be |
| 2292 | * sent to the new top resumed activity. |
| 2293 | */ |
| 2294 | void updateTopResumedActivityIfNeeded() { |
| 2295 | final ActivityRecord prevTopActivity = mTopResumedActivity; |
| 2296 | final ActivityStack topStack = mRootActivityContainer.getTopDisplayFocusedStack(); |
| 2297 | if (topStack == null || topStack.mResumedActivity == prevTopActivity) { |
| 2298 | return; |
| 2299 | } |
| 2300 | |
| 2301 | // Ask previous activity to release the top state. |
| 2302 | final boolean prevActivityReceivedTopState = |
| 2303 | prevTopActivity != null && !mTopResumedActivityWaitingForPrev; |
| 2304 | // mTopResumedActivityWaitingForPrev == true at this point would mean that an activity |
| 2305 | // before the prevTopActivity one hasn't reported back yet. So server never sent the top |
| 2306 | // resumed state change message to prevTopActivity. |
Louis Chang | 3b21bdc | 2019-03-25 15:49:14 +0800 | [diff] [blame] | 2307 | if (prevActivityReceivedTopState |
| 2308 | && prevTopActivity.scheduleTopResumedActivityChanged(false /* onTop */)) { |
Andrii Kulian | 86e70fc | 2019-02-12 11:04:10 +0000 | [diff] [blame] | 2309 | scheduleTopResumedStateLossTimeout(prevTopActivity); |
| 2310 | mTopResumedActivityWaitingForPrev = true; |
| 2311 | } |
| 2312 | |
| 2313 | // Update the current top activity. |
| 2314 | mTopResumedActivity = topStack.mResumedActivity; |
| 2315 | scheduleTopResumedActivityStateIfNeeded(); |
| 2316 | } |
| 2317 | |
| 2318 | /** Schedule top resumed state change if previous top activity already reported back. */ |
| 2319 | private void scheduleTopResumedActivityStateIfNeeded() { |
| 2320 | if (mTopResumedActivity != null && !mTopResumedActivityWaitingForPrev) { |
| 2321 | mTopResumedActivity.scheduleTopResumedActivityChanged(true /* onTop */); |
| 2322 | } |
| 2323 | } |
| 2324 | |
| 2325 | /** |
| 2326 | * Limit the time given to the app to report handling of the state loss. |
| 2327 | */ |
| 2328 | private void scheduleTopResumedStateLossTimeout(ActivityRecord r) { |
| 2329 | final Message msg = mHandler.obtainMessage(TOP_RESUMED_STATE_LOSS_TIMEOUT_MSG); |
| 2330 | msg.obj = r; |
| 2331 | r.topResumedStateLossTime = SystemClock.uptimeMillis(); |
| 2332 | mHandler.sendMessageDelayed(msg, TOP_RESUMED_STATE_LOSS_TIMEOUT); |
| 2333 | if (DEBUG_STATES) Slog.v(TAG_STATES, "Waiting for top state to be released by " + r); |
| 2334 | } |
| 2335 | |
| 2336 | /** |
| 2337 | * Handle a loss of top resumed state by an activity - update internal state and inform next top |
| 2338 | * activity if needed. |
| 2339 | */ |
| 2340 | void handleTopResumedStateReleased(boolean timeout) { |
| 2341 | if (DEBUG_STATES) { |
| 2342 | Slog.v(TAG_STATES, "Top resumed state released " |
| 2343 | + (timeout ? " (due to timeout)" : " (transition complete)")); |
| 2344 | } |
| 2345 | mHandler.removeMessages(TOP_RESUMED_STATE_LOSS_TIMEOUT_MSG); |
| 2346 | if (!mTopResumedActivityWaitingForPrev) { |
| 2347 | // Top resumed activity state loss already handled. |
| 2348 | return; |
| 2349 | } |
| 2350 | mTopResumedActivityWaitingForPrev = false; |
| 2351 | scheduleTopResumedActivityStateIfNeeded(); |
| 2352 | } |
| 2353 | |
Craig Mautner | f333327 | 2013-04-22 10:55:53 -0700 | [diff] [blame] | 2354 | void removeTimeoutsForActivityLocked(ActivityRecord r) { |
Wale Ogunwale | 0fc365c | 2015-05-25 19:35:42 -0700 | [diff] [blame] | 2355 | if (DEBUG_IDLE) Slog.d(TAG_IDLE, "removeTimeoutsForActivity: Callers=" |
| 2356 | + Debug.getCallers(4)); |
Craig Mautner | f333327 | 2013-04-22 10:55:53 -0700 | [diff] [blame] | 2357 | mHandler.removeMessages(IDLE_TIMEOUT_MSG, r); |
| 2358 | } |
| 2359 | |
Craig Mautner | 05d2903 | 2013-05-03 13:40:13 -0700 | [diff] [blame] | 2360 | final void scheduleResumeTopActivities() { |
Craig Mautner | 34b73df | 2014-01-12 21:11:08 -0800 | [diff] [blame] | 2361 | if (!mHandler.hasMessages(RESUME_TOP_ACTIVITY_MSG)) { |
| 2362 | mHandler.sendEmptyMessage(RESUME_TOP_ACTIVITY_MSG); |
| 2363 | } |
Craig Mautner | 05d2903 | 2013-05-03 13:40:13 -0700 | [diff] [blame] | 2364 | } |
| 2365 | |
Craig Mautner | 0eea92c | 2013-05-16 13:35:39 -0700 | [diff] [blame] | 2366 | void removeSleepTimeouts() { |
Craig Mautner | 0eea92c | 2013-05-16 13:35:39 -0700 | [diff] [blame] | 2367 | mHandler.removeMessages(SLEEP_TIMEOUT_MSG); |
| 2368 | } |
| 2369 | |
| 2370 | final void scheduleSleepTimeout() { |
| 2371 | removeSleepTimeouts(); |
| 2372 | mHandler.sendEmptyMessageDelayed(SLEEP_TIMEOUT_MSG, SLEEP_TIMEOUT); |
| 2373 | } |
| 2374 | |
Riddle Hsu | 7b766fd | 2019-01-28 21:14:59 +0800 | [diff] [blame] | 2375 | void removeRestartTimeouts(ActivityRecord r) { |
| 2376 | mHandler.removeMessages(RESTART_ACTIVITY_PROCESS_TIMEOUT_MSG, r); |
| 2377 | } |
| 2378 | |
| 2379 | final void scheduleRestartTimeout(ActivityRecord r) { |
| 2380 | removeRestartTimeouts(r); |
| 2381 | mHandler.sendMessageDelayed(mHandler.obtainMessage(RESTART_ACTIVITY_PROCESS_TIMEOUT_MSG, r), |
| 2382 | WindowManagerService.WINDOW_FREEZE_TIMEOUT_DURATION); |
| 2383 | } |
| 2384 | |
Louis Chang | cdec080 | 2019-11-11 11:45:07 +0800 | [diff] [blame] | 2385 | void handleNonResizableTaskIfNeeded(Task task, int preferredWindowingMode, |
Wale Ogunwale | a0f5b5e | 2017-10-11 09:37:23 -0700 | [diff] [blame] | 2386 | int preferredDisplayId, ActivityStack actualStack) { |
Wale Ogunwale | 0568aed | 2017-09-08 13:29:37 -0700 | [diff] [blame] | 2387 | handleNonResizableTaskIfNeeded(task, preferredWindowingMode, preferredDisplayId, |
Wale Ogunwale | a0f5b5e | 2017-10-11 09:37:23 -0700 | [diff] [blame] | 2388 | actualStack, false /* forceNonResizable */); |
Andrii Kulian | c2791664 | 2016-04-12 17:59:27 -0700 | [diff] [blame] | 2389 | } |
| 2390 | |
Louis Chang | cdec080 | 2019-11-11 11:45:07 +0800 | [diff] [blame] | 2391 | void handleNonResizableTaskIfNeeded(Task task, int preferredWindowingMode, |
Wale Ogunwale | a0f5b5e | 2017-10-11 09:37:23 -0700 | [diff] [blame] | 2392 | int preferredDisplayId, ActivityStack actualStack, boolean forceNonResizable) { |
Andrii Kulian | 036e3ad | 2017-04-19 10:55:10 -0700 | [diff] [blame] | 2393 | final boolean isSecondaryDisplayPreferred = |
Wale Ogunwale | 0568aed | 2017-09-08 13:29:37 -0700 | [diff] [blame] | 2394 | (preferredDisplayId != DEFAULT_DISPLAY && preferredDisplayId != INVALID_DISPLAY); |
Wale Ogunwale | 926aade | 2017-08-29 11:24:37 -0700 | [diff] [blame] | 2395 | final boolean inSplitScreenMode = actualStack != null |
Wale Ogunwale | 7e1f5f5 | 2017-10-18 15:19:59 -0700 | [diff] [blame] | 2396 | && actualStack.getDisplay().hasSplitScreenPrimaryStack(); |
Wale Ogunwale | 0568aed | 2017-09-08 13:29:37 -0700 | [diff] [blame] | 2397 | if (((!inSplitScreenMode && preferredWindowingMode != WINDOWING_MODE_SPLIT_SCREEN_PRIMARY) |
Wale Ogunwale | 7e1f5f5 | 2017-10-18 15:19:59 -0700 | [diff] [blame] | 2398 | && !isSecondaryDisplayPreferred) || !task.isActivityTypeStandardOrUndefined()) { |
Wale Ogunwale | b9b16a7 | 2016-01-27 12:24:44 -0800 | [diff] [blame] | 2399 | return; |
| 2400 | } |
| 2401 | |
Andrii Kulian | 036e3ad | 2017-04-19 10:55:10 -0700 | [diff] [blame] | 2402 | // Handle incorrect launch/move to secondary display if needed. |
Andrii Kulian | 036e3ad | 2017-04-19 10:55:10 -0700 | [diff] [blame] | 2403 | if (isSecondaryDisplayPreferred) { |
| 2404 | final int actualDisplayId = task.getStack().mDisplayId; |
| 2405 | if (!task.canBeLaunchedOnDisplay(actualDisplayId)) { |
Andrii Kulian | b850ea5 | 2017-12-12 23:49:10 -0800 | [diff] [blame] | 2406 | throw new IllegalStateException("Task resolved to incompatible display"); |
Andrii Kulian | 036e3ad | 2017-04-19 10:55:10 -0700 | [diff] [blame] | 2407 | } |
Jeff Chang | 78f5441 | 2019-02-14 20:42:27 +0800 | [diff] [blame] | 2408 | |
| 2409 | final ActivityDisplay preferredDisplay = |
| 2410 | mRootActivityContainer.getActivityDisplay(preferredDisplayId); |
| 2411 | |
| 2412 | final boolean singleTaskInstance = preferredDisplay != null |
| 2413 | && preferredDisplay.isSingleTaskInstance(); |
| 2414 | |
Mark Renouf | 2f9ea1e | 2019-03-05 14:49:06 -0500 | [diff] [blame] | 2415 | if (preferredDisplayId != actualDisplayId) { |
Jeff Chang | 78f5441 | 2019-02-14 20:42:27 +0800 | [diff] [blame] | 2416 | // Suppress the warning toast if the preferredDisplay was set to singleTask. |
| 2417 | // The singleTaskInstance displays will only contain one task and any attempt to |
| 2418 | // launch new task will re-route to the default display. |
Mark Renouf | 2f9ea1e | 2019-03-05 14:49:06 -0500 | [diff] [blame] | 2419 | if (singleTaskInstance) { |
| 2420 | mService.getTaskChangeNotificationController() |
| 2421 | .notifyActivityLaunchOnSecondaryDisplayRerouted(task.getTaskInfo(), |
| 2422 | preferredDisplayId); |
| 2423 | return; |
| 2424 | } |
Jeff Chang | 78f5441 | 2019-02-14 20:42:27 +0800 | [diff] [blame] | 2425 | |
Riddle Hsu | 1656713 | 2018-08-16 21:37:47 +0800 | [diff] [blame] | 2426 | Slog.w(TAG, "Failed to put " + task + " on display " + preferredDisplayId); |
| 2427 | // Display a warning toast that we failed to put a task on a secondary display. |
Wale Ogunwale | c9e57de | 2018-05-08 14:28:07 -0700 | [diff] [blame] | 2428 | mService.getTaskChangeNotificationController() |
Mark Renouf | c808f06 | 2019-02-07 15:20:37 -0500 | [diff] [blame] | 2429 | .notifyActivityLaunchOnSecondaryDisplayFailed(task.getTaskInfo(), |
| 2430 | preferredDisplayId); |
Riddle Hsu | bed3db4 | 2019-03-15 20:26:27 +0800 | [diff] [blame] | 2431 | } else if (!forceNonResizable) { |
| 2432 | handleForcedResizableTaskIfNeeded(task, FORCED_RESIZEABLE_REASON_SECONDARY_DISPLAY); |
Andrii Kulian | 036e3ad | 2017-04-19 10:55:10 -0700 | [diff] [blame] | 2433 | } |
Riddle Hsu | bed3db4 | 2019-03-15 20:26:27 +0800 | [diff] [blame] | 2434 | // The information about not support secondary display should already be notified, we |
| 2435 | // don't want to show another message on default display about split-screen. And it may |
| 2436 | // be the case that a resizable activity is launched on a non-resizable task. |
| 2437 | return; |
Wale Ogunwale | 2b07da8 | 2017-11-08 14:52:40 -0800 | [diff] [blame] | 2438 | } |
| 2439 | |
Wale Ogunwale | 2b07da8 | 2017-11-08 14:52:40 -0800 | [diff] [blame] | 2440 | if (!task.supportsSplitScreenWindowingMode() || forceNonResizable) { |
Andrii Kulian | c2791664 | 2016-04-12 17:59:27 -0700 | [diff] [blame] | 2441 | // Dismiss docked stack. If task appeared to be in docked stack but is not resizable - |
| 2442 | // 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] | 2443 | |
Wale Ogunwale | 2b07da8 | 2017-11-08 14:52:40 -0800 | [diff] [blame] | 2444 | final ActivityStack dockedStack = |
| 2445 | task.getStack().getDisplay().getSplitScreenPrimaryStack(); |
Wale Ogunwale | 9dcf946 | 2017-09-19 15:13:01 -0700 | [diff] [blame] | 2446 | if (dockedStack != null) { |
Riddle Hsu | bed3db4 | 2019-03-15 20:26:27 +0800 | [diff] [blame] | 2447 | // Display a warning toast that we tried to put an app that doesn't support |
| 2448 | // split-screen in split-screen. |
| 2449 | mService.getTaskChangeNotificationController() |
| 2450 | .notifyActivityDismissingDockedStack(); |
Wale Ogunwale | a0f5b5e | 2017-10-11 09:37:23 -0700 | [diff] [blame] | 2451 | moveTasksToFullscreenStackLocked(dockedStack, actualStack == dockedStack); |
Wale Ogunwale | 9dcf946 | 2017-09-19 15:13:01 -0700 | [diff] [blame] | 2452 | } |
Wale Ogunwale | 2b07da8 | 2017-11-08 14:52:40 -0800 | [diff] [blame] | 2453 | return; |
| 2454 | } |
| 2455 | |
Riddle Hsu | bed3db4 | 2019-03-15 20:26:27 +0800 | [diff] [blame] | 2456 | handleForcedResizableTaskIfNeeded(task, FORCED_RESIZEABLE_REASON_SPLIT_SCREEN); |
Riddle Hsu | 1656713 | 2018-08-16 21:37:47 +0800 | [diff] [blame] | 2457 | } |
| 2458 | |
Riddle Hsu | bed3db4 | 2019-03-15 20:26:27 +0800 | [diff] [blame] | 2459 | /** Notifies that the top activity of the task is forced to be resizeable. */ |
Louis Chang | cdec080 | 2019-11-11 11:45:07 +0800 | [diff] [blame] | 2460 | private void handleForcedResizableTaskIfNeeded(Task task, int reason) { |
Wale Ogunwale | 21e0648 | 2019-11-18 05:14:15 -0800 | [diff] [blame] | 2461 | final ActivityRecord topActivity = task.getTopNonFinishingActivity(); |
Riddle Hsu | bed3db4 | 2019-03-15 20:26:27 +0800 | [diff] [blame] | 2462 | if (topActivity == null || topActivity.noDisplay |
Wale Ogunwale | bebd8cd | 2019-10-28 15:53:31 -0700 | [diff] [blame] | 2463 | || !topActivity.isNonResizableOrForcedResizable(task.getWindowingMode())) { |
Riddle Hsu | bed3db4 | 2019-03-15 20:26:27 +0800 | [diff] [blame] | 2464 | return; |
Wale Ogunwale | b9b16a7 | 2016-01-27 12:24:44 -0800 | [diff] [blame] | 2465 | } |
Riddle Hsu | bed3db4 | 2019-03-15 20:26:27 +0800 | [diff] [blame] | 2466 | mService.getTaskChangeNotificationController().notifyActivityForcedResizable( |
Wale Ogunwale | 4e79a1c | 2019-10-05 20:52:40 -0700 | [diff] [blame] | 2467 | task.mTaskId, reason, topActivity.info.applicationInfo.packageName); |
Chong Zhang | b15758a | 2015-11-17 12:12:03 -0800 | [diff] [blame] | 2468 | } |
| 2469 | |
Jorim Jaggi | fe89d12 | 2015-12-22 16:28:44 +0100 | [diff] [blame] | 2470 | void activityRelaunchedLocked(IBinder token) { |
David Stevens | 9440dc8 | 2017-03-16 19:00:20 -0700 | [diff] [blame] | 2471 | final ActivityRecord r = ActivityRecord.isInStackLocked(token); |
| 2472 | if (r != null) { |
Wale Ogunwale | da8b827 | 2018-11-29 19:37:37 -0800 | [diff] [blame] | 2473 | r.finishRelaunching(); |
Wale Ogunwale | 8b19de9 | 2018-11-29 19:58:26 -0800 | [diff] [blame] | 2474 | if (r.getActivityStack().shouldSleepOrShutDownActivities()) { |
Wale Ogunwale | 3e99736 | 2016-09-06 10:37:56 -0700 | [diff] [blame] | 2475 | r.setSleeping(true, true); |
| 2476 | } |
| 2477 | } |
Jorim Jaggi | fe89d12 | 2015-12-22 16:28:44 +0100 | [diff] [blame] | 2478 | } |
| 2479 | |
Filip Gruszczynski | 77d9448 | 2015-12-11 13:59:52 -0800 | [diff] [blame] | 2480 | void logStackState() { |
| 2481 | mActivityMetricsLogger.logWindowState(); |
| 2482 | } |
| 2483 | |
Louis Chang | cdec080 | 2019-11-11 11:45:07 +0800 | [diff] [blame] | 2484 | void scheduleUpdateMultiWindowMode(Task task) { |
Winson Chung | 8bca9e4 | 2017-04-16 15:59:43 -0700 | [diff] [blame] | 2485 | // If the stack is animating in a way where we will be forcing a multi-mode change at the |
| 2486 | // end, then ensure that we defer all in between multi-window mode changes |
| 2487 | if (task.getStack().deferScheduleMultiWindowModeChanged()) { |
| 2488 | return; |
| 2489 | } |
| 2490 | |
Wale Ogunwale | 1a06f15 | 2019-10-11 11:26:30 +0200 | [diff] [blame] | 2491 | for (int i = task.getChildCount() - 1; i >= 0; i--) { |
| 2492 | final ActivityRecord r = task.getChildAt(i); |
Wale Ogunwale | 9e4f3e0 | 2018-05-17 09:35:39 -0700 | [diff] [blame] | 2493 | if (r.attachedToProcess()) { |
Wale Ogunwale | 22e2526 | 2016-02-01 10:32:02 -0800 | [diff] [blame] | 2494 | mMultiWindowModeChangedActivities.add(r); |
| 2495 | } |
| 2496 | } |
| 2497 | |
| 2498 | if (!mHandler.hasMessages(REPORT_MULTI_WINDOW_MODE_CHANGED_MSG)) { |
| 2499 | mHandler.sendEmptyMessage(REPORT_MULTI_WINDOW_MODE_CHANGED_MSG); |
| 2500 | } |
| 2501 | } |
| 2502 | |
Louis Chang | cdec080 | 2019-11-11 11:45:07 +0800 | [diff] [blame] | 2503 | void scheduleUpdatePictureInPictureModeIfNeeded(Task task, ActivityStack prevStack) { |
Andrii Kulian | 02b7a83 | 2016-10-06 23:11:56 -0700 | [diff] [blame] | 2504 | final ActivityStack stack = task.getStack(); |
Wale Ogunwale | 22e2526 | 2016-02-01 10:32:02 -0800 | [diff] [blame] | 2505 | if (prevStack == null || prevStack == stack |
Wale Ogunwale | 44f036f | 2017-09-29 05:09:09 -0700 | [diff] [blame] | 2506 | || (!prevStack.inPinnedWindowingMode() && !stack.inPinnedWindowingMode())) { |
Wale Ogunwale | 22e2526 | 2016-02-01 10:32:02 -0800 | [diff] [blame] | 2507 | return; |
| 2508 | } |
| 2509 | |
Evan Rosky | dfe3da7 | 2018-10-26 17:21:06 -0700 | [diff] [blame] | 2510 | scheduleUpdatePictureInPictureModeIfNeeded(task, stack.getRequestedOverrideBounds()); |
Winson Chung | 5af42fc | 2017-03-24 17:11:33 -0700 | [diff] [blame] | 2511 | } |
Wale Ogunwale | 22e2526 | 2016-02-01 10:32:02 -0800 | [diff] [blame] | 2512 | |
Louis Chang | cdec080 | 2019-11-11 11:45:07 +0800 | [diff] [blame] | 2513 | void scheduleUpdatePictureInPictureModeIfNeeded(Task task, Rect targetStackBounds) { |
Wale Ogunwale | 1a06f15 | 2019-10-11 11:26:30 +0200 | [diff] [blame] | 2514 | for (int i = task.getChildCount() - 1; i >= 0; i--) { |
| 2515 | final ActivityRecord r = task.getChildAt(i); |
Wale Ogunwale | 9e4f3e0 | 2018-05-17 09:35:39 -0700 | [diff] [blame] | 2516 | if (r.attachedToProcess()) { |
Winson Chung | ab76bbc | 2017-08-14 13:33:51 -0700 | [diff] [blame] | 2517 | mPipModeChangedActivities.add(r); |
Wale Ogunwale | eb76b76 | 2017-11-17 10:08:04 -0800 | [diff] [blame] | 2518 | // If we are scheduling pip change, then remove this activity from multi-window |
| 2519 | // change list as the processing of pip change will make sure multi-window changed |
| 2520 | // message is processed in the right order relative to pip changed. |
| 2521 | mMultiWindowModeChangedActivities.remove(r); |
Winson Chung | 5af42fc | 2017-03-24 17:11:33 -0700 | [diff] [blame] | 2522 | } |
Winson Chung | ab76bbc | 2017-08-14 13:33:51 -0700 | [diff] [blame] | 2523 | } |
| 2524 | mPipModeChangedTargetStackBounds = targetStackBounds; |
Winson Chung | 5af42fc | 2017-03-24 17:11:33 -0700 | [diff] [blame] | 2525 | |
Winson Chung | ab76bbc | 2017-08-14 13:33:51 -0700 | [diff] [blame] | 2526 | if (!mHandler.hasMessages(REPORT_PIP_MODE_CHANGED_MSG)) { |
| 2527 | mHandler.sendEmptyMessage(REPORT_PIP_MODE_CHANGED_MSG); |
| 2528 | } |
| 2529 | } |
| 2530 | |
Louis Chang | cdec080 | 2019-11-11 11:45:07 +0800 | [diff] [blame] | 2531 | void updatePictureInPictureMode(Task task, Rect targetStackBounds, boolean forceUpdate) { |
Winson Chung | ab76bbc | 2017-08-14 13:33:51 -0700 | [diff] [blame] | 2532 | mHandler.removeMessages(REPORT_PIP_MODE_CHANGED_MSG); |
Wale Ogunwale | 1a06f15 | 2019-10-11 11:26:30 +0200 | [diff] [blame] | 2533 | for (int i = task.getChildCount() - 1; i >= 0; i--) { |
| 2534 | final ActivityRecord r = task.getChildAt(i); |
Wale Ogunwale | 9e4f3e0 | 2018-05-17 09:35:39 -0700 | [diff] [blame] | 2535 | if (r.attachedToProcess()) { |
Winson Chung | ab76bbc | 2017-08-14 13:33:51 -0700 | [diff] [blame] | 2536 | r.updatePictureInPictureMode(targetStackBounds, forceUpdate); |
Winson Chung | 5af42fc | 2017-03-24 17:11:33 -0700 | [diff] [blame] | 2537 | } |
Wale Ogunwale | 22e2526 | 2016-02-01 10:32:02 -0800 | [diff] [blame] | 2538 | } |
| 2539 | } |
| 2540 | |
chaviw | 59b9885 | 2017-06-13 12:05:44 -0700 | [diff] [blame] | 2541 | void wakeUp(String reason) { |
Michael Wright | e300104 | 2019-02-05 00:13:14 +0000 | [diff] [blame] | 2542 | mPowerManager.wakeUp(SystemClock.uptimeMillis(), PowerManager.WAKE_REASON_APPLICATION, |
| 2543 | "android.server.am:TURN_ON:" + reason); |
chaviw | 59b9885 | 2017-06-13 12:05:44 -0700 | [diff] [blame] | 2544 | } |
| 2545 | |
| 2546 | /** |
| 2547 | * Begin deferring resume to avoid duplicate resumes in one pass. |
| 2548 | */ |
Riddle Hsu | 402b440 | 2018-11-06 17:23:15 +0800 | [diff] [blame] | 2549 | void beginDeferResume() { |
chaviw | 59b9885 | 2017-06-13 12:05:44 -0700 | [diff] [blame] | 2550 | mDeferResumeCount++; |
| 2551 | } |
| 2552 | |
| 2553 | /** |
| 2554 | * End deferring resume and determine if resume can be called. |
| 2555 | */ |
Riddle Hsu | 402b440 | 2018-11-06 17:23:15 +0800 | [diff] [blame] | 2556 | void endDeferResume() { |
chaviw | 59b9885 | 2017-06-13 12:05:44 -0700 | [diff] [blame] | 2557 | mDeferResumeCount--; |
| 2558 | } |
| 2559 | |
Wale Ogunwale | d32da47 | 2018-11-16 07:19:28 -0800 | [diff] [blame] | 2560 | /** @return True if resume can be called. */ |
| 2561 | boolean readyToResume() { |
chaviw | 59b9885 | 2017-06-13 12:05:44 -0700 | [diff] [blame] | 2562 | return mDeferResumeCount == 0; |
| 2563 | } |
| 2564 | |
Craig Mautner | ce5f3cb | 2013-04-22 08:58:54 -0700 | [diff] [blame] | 2565 | private final class ActivityStackSupervisorHandler extends Handler { |
Craig Mautner | f333327 | 2013-04-22 10:55:53 -0700 | [diff] [blame] | 2566 | |
Craig Mautner | ce5f3cb | 2013-04-22 08:58:54 -0700 | [diff] [blame] | 2567 | public ActivityStackSupervisorHandler(Looper looper) { |
| 2568 | super(looper); |
| 2569 | } |
| 2570 | |
Winson Chung | 4dabf23 | 2017-01-25 13:25:22 -0800 | [diff] [blame] | 2571 | void activityIdleInternal(ActivityRecord r, boolean processPausingActivities) { |
Wale Ogunwale | c9e57de | 2018-05-08 14:28:07 -0700 | [diff] [blame] | 2572 | synchronized (mService.mGlobalLock) { |
Winson Chung | 4dabf23 | 2017-01-25 13:25:22 -0800 | [diff] [blame] | 2573 | activityIdleInternalLocked(r != null ? r.appToken : null, true /* fromTimeout */, |
| 2574 | processPausingActivities, null); |
Craig Mautner | f333327 | 2013-04-22 10:55:53 -0700 | [diff] [blame] | 2575 | } |
Craig Mautner | 7ea5bd4 | 2013-07-05 15:27:08 -0700 | [diff] [blame] | 2576 | } |
| 2577 | |
Craig Mautner | ce5f3cb | 2013-04-22 08:58:54 -0700 | [diff] [blame] | 2578 | @Override |
| 2579 | public void handleMessage(Message msg) { |
| 2580 | switch (msg.what) { |
Wale Ogunwale | 22e2526 | 2016-02-01 10:32:02 -0800 | [diff] [blame] | 2581 | case REPORT_MULTI_WINDOW_MODE_CHANGED_MSG: { |
Wale Ogunwale | c9e57de | 2018-05-08 14:28:07 -0700 | [diff] [blame] | 2582 | synchronized (mService.mGlobalLock) { |
Wale Ogunwale | 22e2526 | 2016-02-01 10:32:02 -0800 | [diff] [blame] | 2583 | for (int i = mMultiWindowModeChangedActivities.size() - 1; i >= 0; i--) { |
| 2584 | final ActivityRecord r = mMultiWindowModeChangedActivities.remove(i); |
Winson Chung | 5af42fc | 2017-03-24 17:11:33 -0700 | [diff] [blame] | 2585 | r.updateMultiWindowMode(); |
Wale Ogunwale | 22e2526 | 2016-02-01 10:32:02 -0800 | [diff] [blame] | 2586 | } |
| 2587 | } |
| 2588 | } break; |
| 2589 | case REPORT_PIP_MODE_CHANGED_MSG: { |
Wale Ogunwale | c9e57de | 2018-05-08 14:28:07 -0700 | [diff] [blame] | 2590 | synchronized (mService.mGlobalLock) { |
Wale Ogunwale | 22e2526 | 2016-02-01 10:32:02 -0800 | [diff] [blame] | 2591 | for (int i = mPipModeChangedActivities.size() - 1; i >= 0; i--) { |
| 2592 | final ActivityRecord r = mPipModeChangedActivities.remove(i); |
Winson Chung | ab76bbc | 2017-08-14 13:33:51 -0700 | [diff] [blame] | 2593 | r.updatePictureInPictureMode(mPipModeChangedTargetStackBounds, |
| 2594 | false /* forceUpdate */); |
Wale Ogunwale | 22e2526 | 2016-02-01 10:32:02 -0800 | [diff] [blame] | 2595 | } |
| 2596 | } |
| 2597 | } break; |
Craig Mautner | f333327 | 2013-04-22 10:55:53 -0700 | [diff] [blame] | 2598 | case IDLE_TIMEOUT_MSG: { |
Wale Ogunwale | 0fc365c | 2015-05-25 19:35:42 -0700 | [diff] [blame] | 2599 | if (DEBUG_IDLE) Slog.d(TAG_IDLE, |
| 2600 | "handleMessage: IDLE_TIMEOUT_MSG: r=" + msg.obj); |
Craig Mautner | f333327 | 2013-04-22 10:55:53 -0700 | [diff] [blame] | 2601 | // We don't at this point know if the activity is fullscreen, |
| 2602 | // so we need to be conservative and assume it isn't. |
Winson Chung | 4dabf23 | 2017-01-25 13:25:22 -0800 | [diff] [blame] | 2603 | activityIdleInternal((ActivityRecord) msg.obj, |
| 2604 | true /* processPausingActivities */); |
Craig Mautner | f333327 | 2013-04-22 10:55:53 -0700 | [diff] [blame] | 2605 | } break; |
| 2606 | case IDLE_NOW_MSG: { |
Wale Ogunwale | 0fc365c | 2015-05-25 19:35:42 -0700 | [diff] [blame] | 2607 | 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] | 2608 | activityIdleInternal((ActivityRecord) msg.obj, |
| 2609 | false /* processPausingActivities */); |
Craig Mautner | f333327 | 2013-04-22 10:55:53 -0700 | [diff] [blame] | 2610 | } break; |
Craig Mautner | 05d2903 | 2013-05-03 13:40:13 -0700 | [diff] [blame] | 2611 | case RESUME_TOP_ACTIVITY_MSG: { |
Wale Ogunwale | c9e57de | 2018-05-08 14:28:07 -0700 | [diff] [blame] | 2612 | synchronized (mService.mGlobalLock) { |
Wale Ogunwale | d32da47 | 2018-11-16 07:19:28 -0800 | [diff] [blame] | 2613 | mRootActivityContainer.resumeFocusedStacksTopActivities(); |
Craig Mautner | 05d2903 | 2013-05-03 13:40:13 -0700 | [diff] [blame] | 2614 | } |
| 2615 | } break; |
Craig Mautner | 0eea92c | 2013-05-16 13:35:39 -0700 | [diff] [blame] | 2616 | case SLEEP_TIMEOUT_MSG: { |
Wale Ogunwale | c9e57de | 2018-05-08 14:28:07 -0700 | [diff] [blame] | 2617 | synchronized (mService.mGlobalLock) { |
Wale Ogunwale | f673393 | 2018-06-27 05:14:34 -0700 | [diff] [blame] | 2618 | if (mService.isSleepingOrShuttingDownLocked()) { |
Craig Mautner | 0eea92c | 2013-05-16 13:35:39 -0700 | [diff] [blame] | 2619 | Slog.w(TAG, "Sleep timeout! Sleeping now."); |
David Stevens | 9440dc8 | 2017-03-16 19:00:20 -0700 | [diff] [blame] | 2620 | checkReadyForSleepLocked(false /* allowDelay */); |
Craig Mautner | 0eea92c | 2013-05-16 13:35:39 -0700 | [diff] [blame] | 2621 | } |
| 2622 | } |
| 2623 | } break; |
Craig Mautner | 7ea5bd4 | 2013-07-05 15:27:08 -0700 | [diff] [blame] | 2624 | case LAUNCH_TIMEOUT_MSG: { |
Wale Ogunwale | c9e57de | 2018-05-08 14:28:07 -0700 | [diff] [blame] | 2625 | synchronized (mService.mGlobalLock) { |
Andrii Kulian | c598b2d | 2019-02-07 17:16:38 -0800 | [diff] [blame] | 2626 | if (mLaunchingActivityWakeLock.isHeld()) { |
Craig Mautner | 7ea5bd4 | 2013-07-05 15:27:08 -0700 | [diff] [blame] | 2627 | Slog.w(TAG, "Launch timeout has expired, giving up wake lock!"); |
| 2628 | if (VALIDATE_WAKE_LOCK_CALLER |
| 2629 | && Binder.getCallingUid() != Process.myUid()) { |
| 2630 | throw new IllegalStateException("Calling must be system uid"); |
| 2631 | } |
Andrii Kulian | c598b2d | 2019-02-07 17:16:38 -0800 | [diff] [blame] | 2632 | mLaunchingActivityWakeLock.release(); |
Craig Mautner | 7ea5bd4 | 2013-07-05 15:27:08 -0700 | [diff] [blame] | 2633 | } |
| 2634 | } |
| 2635 | } break; |
Craig Mautner | bb74246 | 2014-07-07 15:28:55 -0700 | [diff] [blame] | 2636 | case LAUNCH_TASK_BEHIND_COMPLETE: { |
Wale Ogunwale | c9e57de | 2018-05-08 14:28:07 -0700 | [diff] [blame] | 2637 | synchronized (mService.mGlobalLock) { |
Wale Ogunwale | 7d70117 | 2015-03-11 15:36:30 -0700 | [diff] [blame] | 2638 | ActivityRecord r = ActivityRecord.forTokenLocked((IBinder) msg.obj); |
Craig Mautner | bb74246 | 2014-07-07 15:28:55 -0700 | [diff] [blame] | 2639 | if (r != null) { |
| 2640 | handleLaunchTaskBehindCompleteLocked(r); |
| 2641 | } |
| 2642 | } |
| 2643 | } break; |
Riddle Hsu | 7b766fd | 2019-01-28 21:14:59 +0800 | [diff] [blame] | 2644 | case RESTART_ACTIVITY_PROCESS_TIMEOUT_MSG: { |
| 2645 | final ActivityRecord r = (ActivityRecord) msg.obj; |
| 2646 | String processName = null; |
| 2647 | int uid = 0; |
| 2648 | synchronized (mService.mGlobalLock) { |
| 2649 | if (r.attachedToProcess() |
| 2650 | && r.isState(ActivityStack.ActivityState.RESTARTING_PROCESS)) { |
| 2651 | processName = r.app.mName; |
| 2652 | uid = r.app.mUid; |
| 2653 | } |
| 2654 | } |
| 2655 | if (processName != null) { |
| 2656 | mService.mAmInternal.killProcess(processName, uid, |
| 2657 | "restartActivityProcessTimeout"); |
| 2658 | } |
| 2659 | } break; |
Louis Chang | dcdde95 | 2018-12-04 15:38:44 +0800 | [diff] [blame] | 2660 | case REPORT_HOME_CHANGED_MSG: { |
| 2661 | synchronized (mService.mGlobalLock) { |
| 2662 | mHandler.removeMessages(REPORT_HOME_CHANGED_MSG); |
Chong Zhang | c806d90 | 2015-11-30 09:44:27 -0800 | [diff] [blame] | 2663 | |
Louis Chang | dcdde95 | 2018-12-04 15:38:44 +0800 | [diff] [blame] | 2664 | // Start home activities on displays with no activities. |
| 2665 | mRootActivityContainer.startHomeOnEmptyDisplays("homeChanged"); |
| 2666 | } |
Andrii Kulian | 86e70fc | 2019-02-12 11:04:10 +0000 | [diff] [blame] | 2667 | } break; |
| 2668 | case TOP_RESUMED_STATE_LOSS_TIMEOUT_MSG: { |
| 2669 | ActivityRecord r = (ActivityRecord) msg.obj; |
| 2670 | Slog.w(TAG, "Activity top resumed state loss timeout for " + r); |
| 2671 | synchronized (mService.mGlobalLock) { |
| 2672 | if (r.hasProcess()) { |
| 2673 | mService.logAppTooSlow(r.app, r.topResumedStateLossTime, |
| 2674 | "top state loss for " + r); |
| 2675 | } |
| 2676 | } |
| 2677 | handleTopResumedStateReleased(true /* timeout */); |
| 2678 | } break; |
Craig Mautner | ce5f3cb | 2013-04-22 08:58:54 -0700 | [diff] [blame] | 2679 | } |
| 2680 | } |
| 2681 | } |
Craig Mautner | ed6649f | 2013-12-02 14:08:25 -0800 | [diff] [blame] | 2682 | |
Jorim Jaggi | c69bd22 | 2016-03-15 14:38:37 +0100 | [diff] [blame] | 2683 | /** |
| 2684 | * Puts a task into resizing mode during the next app transition. |
| 2685 | * |
Wale Ogunwale | e1fe7fa2 | 2016-12-15 18:27:00 -0800 | [diff] [blame] | 2686 | * @param task The task to put into resizing mode |
Jorim Jaggi | c69bd22 | 2016-03-15 14:38:37 +0100 | [diff] [blame] | 2687 | */ |
Louis Chang | cdec080 | 2019-11-11 11:45:07 +0800 | [diff] [blame] | 2688 | void setResizingDuringAnimation(Task task) { |
Wale Ogunwale | 4e79a1c | 2019-10-05 20:52:40 -0700 | [diff] [blame] | 2689 | mResizingTasksDuringAnimation.add(task.mTaskId); |
Wale Ogunwale | e1fe7fa2 | 2016-12-15 18:27:00 -0800 | [diff] [blame] | 2690 | task.setTaskDockedResizing(true); |
Jorim Jaggi | c69bd22 | 2016-03-15 14:38:37 +0100 | [diff] [blame] | 2691 | } |
| 2692 | |
Jorim Jaggi | 4d8d32c | 2018-01-19 15:57:41 +0100 | [diff] [blame] | 2693 | int startActivityFromRecents(int callingPid, int callingUid, int taskId, |
| 2694 | SafeActivityOptions options) { |
Louis Chang | cdec080 | 2019-11-11 11:45:07 +0800 | [diff] [blame] | 2695 | Task task = null; |
Jorim Jaggi | 0b46f3c | 2016-03-14 12:21:37 +0100 | [diff] [blame] | 2696 | final String callingPackage; |
| 2697 | final Intent intent; |
| 2698 | final int userId; |
Wale Ogunwale | 0568aed | 2017-09-08 13:29:37 -0700 | [diff] [blame] | 2699 | int activityType = ACTIVITY_TYPE_UNDEFINED; |
| 2700 | int windowingMode = WINDOWING_MODE_UNDEFINED; |
Jorim Jaggi | 4d8d32c | 2018-01-19 15:57:41 +0100 | [diff] [blame] | 2701 | final ActivityOptions activityOptions = options != null |
| 2702 | ? options.getOptions(this) |
| 2703 | : null; |
Wale Ogunwale | 0568aed | 2017-09-08 13:29:37 -0700 | [diff] [blame] | 2704 | if (activityOptions != null) { |
| 2705 | activityType = activityOptions.getLaunchActivityType(); |
| 2706 | windowingMode = activityOptions.getLaunchWindowingMode(); |
Winson Chung | cdd4c3f | 2019-04-17 15:40:11 -0700 | [diff] [blame] | 2707 | if (activityOptions.freezeRecentTasksReordering() |
| 2708 | && mRecentTasks.isCallerRecents(callingUid)) { |
Winson Chung | c5fe7ff | 2019-02-19 14:49:25 -0800 | [diff] [blame] | 2709 | mRecentTasks.setFreezeTaskListReordering(); |
| 2710 | } |
Wale Ogunwale | 0568aed | 2017-09-08 13:29:37 -0700 | [diff] [blame] | 2711 | } |
| 2712 | if (activityType == ACTIVITY_TYPE_HOME || activityType == ACTIVITY_TYPE_RECENTS) { |
Wale Ogunwale | ab5de37 | 2017-10-18 06:46:31 -0700 | [diff] [blame] | 2713 | throw new IllegalArgumentException("startActivityFromRecents: Task " |
Matthew Ng | ae1ff4f | 2016-11-10 15:49:14 -0800 | [diff] [blame] | 2714 | + taskId + " can't be launch in the home/recents stack."); |
Jorim Jaggi | 0b46f3c | 2016-03-14 12:21:37 +0100 | [diff] [blame] | 2715 | } |
Jorim Jaggi | 3c800a4 | 2016-04-15 19:44:50 -0700 | [diff] [blame] | 2716 | |
Riddle Hsu | a0022cd | 2019-09-09 21:12:41 +0800 | [diff] [blame] | 2717 | mService.deferWindowLayout(); |
Matthew Ng | 606dd80 | 2017-06-05 14:06:32 -0700 | [diff] [blame] | 2718 | try { |
Wale Ogunwale | 0568aed | 2017-09-08 13:29:37 -0700 | [diff] [blame] | 2719 | if (windowingMode == WINDOWING_MODE_SPLIT_SCREEN_PRIMARY) { |
Wale Ogunwale | 83b8a6b | 2019-06-27 20:15:15 -0700 | [diff] [blame] | 2720 | mWindowManager.setDockedStackCreateStateLocked( |
Matthew Ng | bf15587 | 2017-10-27 15:24:39 -0700 | [diff] [blame] | 2721 | activityOptions.getSplitScreenCreateMode(), null /* initialBounds */); |
Jorim Jaggi | 3c800a4 | 2016-04-15 19:44:50 -0700 | [diff] [blame] | 2722 | |
Matthew Ng | 606dd80 | 2017-06-05 14:06:32 -0700 | [diff] [blame] | 2723 | // Defer updating the stack in which recents is until the app transition is done, to |
| 2724 | // not run into issues where we still need to draw the task in recents but the |
| 2725 | // docked stack is already created. |
Winson Chung | c167427 | 2018-02-21 10:15:17 -0800 | [diff] [blame] | 2726 | deferUpdateRecentsHomeStackBounds(); |
lumark | 588a3e8 | 2018-07-20 18:53:54 +0800 | [diff] [blame] | 2727 | // TODO(multi-display): currently recents animation only support default display. |
Matthew Ng | 606dd80 | 2017-06-05 14:06:32 -0700 | [diff] [blame] | 2728 | mWindowManager.prepareAppTransition(TRANSIT_DOCK_TASK_FROM_RECENTS, false); |
Jorim Jaggi | 0b46f3c | 2016-03-14 12:21:37 +0100 | [diff] [blame] | 2729 | } |
Jorim Jaggi | 0b46f3c | 2016-03-14 12:21:37 +0100 | [diff] [blame] | 2730 | |
Wale Ogunwale | d32da47 | 2018-11-16 07:19:28 -0800 | [diff] [blame] | 2731 | task = mRootActivityContainer.anyTaskForId(taskId, |
| 2732 | MATCH_TASK_IN_STACKS_OR_RECENT_TASKS_AND_RESTORE, activityOptions, ON_TOP); |
Matthew Ng | 606dd80 | 2017-06-05 14:06:32 -0700 | [diff] [blame] | 2733 | if (task == null) { |
Winson Chung | c167427 | 2018-02-21 10:15:17 -0800 | [diff] [blame] | 2734 | continueUpdateRecentsHomeStackBounds(); |
Matthew Ng | 606dd80 | 2017-06-05 14:06:32 -0700 | [diff] [blame] | 2735 | mWindowManager.executeAppTransition(); |
| 2736 | throw new IllegalArgumentException( |
Wale Ogunwale | ab5de37 | 2017-10-18 06:46:31 -0700 | [diff] [blame] | 2737 | "startActivityFromRecents: Task " + taskId + " not found."); |
Matthew Ng | 606dd80 | 2017-06-05 14:06:32 -0700 | [diff] [blame] | 2738 | } |
| 2739 | |
Wale Ogunwale | abc44d0 | 2017-11-08 08:58:03 -0800 | [diff] [blame] | 2740 | if (windowingMode != WINDOWING_MODE_SPLIT_SCREEN_PRIMARY) { |
| 2741 | // We always want to return to the home activity instead of the recents activity |
| 2742 | // from whatever is started from the recents activity, so move the home stack |
| 2743 | // forward. |
Louis Chang | bd48dca | 2018-08-29 17:44:34 +0800 | [diff] [blame] | 2744 | // TODO (b/115289124): Multi-display supports for recents. |
Wale Ogunwale | d32da47 | 2018-11-16 07:19:28 -0800 | [diff] [blame] | 2745 | mRootActivityContainer.getDefaultDisplay().moveHomeStackToFront( |
| 2746 | "startActivityFromRecents"); |
Wale Ogunwale | abc44d0 | 2017-11-08 08:58:03 -0800 | [diff] [blame] | 2747 | } |
Wale Ogunwale | 66e1685 | 2017-10-19 13:35:52 -0700 | [diff] [blame] | 2748 | |
Matthew Ng | 606dd80 | 2017-06-05 14:06:32 -0700 | [diff] [blame] | 2749 | // If the user must confirm credentials (e.g. when first launching a work app and the |
| 2750 | // Work Challenge is present) let startActivityInPackage handle the intercepting. |
Wale Ogunwale | 4e79a1c | 2019-10-05 20:52:40 -0700 | [diff] [blame] | 2751 | if (!mService.mAmInternal.shouldConfirmCredentials(task.mUserId) |
Matthew Ng | 606dd80 | 2017-06-05 14:06:32 -0700 | [diff] [blame] | 2752 | && task.getRootActivity() != null) { |
Wale Ogunwale | 21e0648 | 2019-11-18 05:14:15 -0800 | [diff] [blame] | 2753 | final ActivityRecord targetActivity = task.getTopNonFinishingActivity(); |
Bryce Lee | 28d8042 | 2017-07-21 13:25:13 -0700 | [diff] [blame] | 2754 | |
Wale Ogunwale | d32da47 | 2018-11-16 07:19:28 -0800 | [diff] [blame] | 2755 | mRootActivityContainer.sendPowerHintForLaunchStartIfNeeded( |
| 2756 | true /* forceSend */, targetActivity); |
Igor Murashkin | 212d06c | 2018-10-22 16:34:39 -0700 | [diff] [blame] | 2757 | mActivityMetricsLogger.notifyActivityLaunching(task.intent); |
Jorim Jaggi | 172e99f | 2017-10-20 14:33:18 +0200 | [diff] [blame] | 2758 | try { |
Ricky Wai | aca8a77 | 2019-04-04 16:01:06 +0100 | [diff] [blame] | 2759 | mService.moveTaskToFrontLocked(null /* appThread */, null /* callingPackage */, |
Wale Ogunwale | 4e79a1c | 2019-10-05 20:52:40 -0700 | [diff] [blame] | 2760 | task.mTaskId, 0, options, true /* fromRecents */); |
lumark | 5e8aff4 | 2019-01-11 22:22:59 +0800 | [diff] [blame] | 2761 | // Apply options to prevent pendingOptions be taken by client to make sure |
| 2762 | // the override pending app transition will be applied immediately. |
| 2763 | targetActivity.applyOptionsLocked(); |
Jorim Jaggi | 172e99f | 2017-10-20 14:33:18 +0200 | [diff] [blame] | 2764 | } finally { |
| 2765 | mActivityMetricsLogger.notifyActivityLaunched(START_TASK_TO_FRONT, |
| 2766 | targetActivity); |
| 2767 | } |
Matthew Ng | 606dd80 | 2017-06-05 14:06:32 -0700 | [diff] [blame] | 2768 | |
Wale Ogunwale | c9e57de | 2018-05-08 14:28:07 -0700 | [diff] [blame] | 2769 | mService.getActivityStartController().postStartActivityProcessingForLastStarter( |
Wale Ogunwale | 21e0648 | 2019-11-18 05:14:15 -0800 | [diff] [blame] | 2770 | task.getTopNonFinishingActivity(), ActivityManager.START_TASK_TO_FRONT, |
Bryce Lee | d3624e1 | 2017-11-30 08:51:45 -0800 | [diff] [blame] | 2771 | task.getStack()); |
Matthew Ng | 606dd80 | 2017-06-05 14:06:32 -0700 | [diff] [blame] | 2772 | return ActivityManager.START_TASK_TO_FRONT; |
| 2773 | } |
Matthew Ng | 606dd80 | 2017-06-05 14:06:32 -0700 | [diff] [blame] | 2774 | callingPackage = task.mCallingPackage; |
| 2775 | intent = task.intent; |
| 2776 | intent.addFlags(Intent.FLAG_ACTIVITY_LAUNCHED_FROM_HISTORY); |
Wale Ogunwale | 4e79a1c | 2019-10-05 20:52:40 -0700 | [diff] [blame] | 2777 | userId = task.mUserId; |
Wale Ogunwale | c9e57de | 2018-05-08 14:28:07 -0700 | [diff] [blame] | 2778 | return mService.getActivityStartController().startActivityInPackage( |
Jorim Jaggi | 4d8d32c | 2018-01-19 15:57:41 +0100 | [diff] [blame] | 2779 | task.mCallingUid, callingPid, callingUid, callingPackage, intent, null, null, |
Makoto Onuki | c00ea71 | 2018-04-13 12:06:39 -0700 | [diff] [blame] | 2780 | null, 0, 0, options, userId, task, "startActivityFromRecents", |
Michal Karpinski | ac116df | 2018-12-10 17:51:42 +0000 | [diff] [blame] | 2781 | false /* validateIncomingUser */, null /* originatingPendingIntent */, |
| 2782 | false /* allowBackgroundActivityStart */); |
Matthew Ng | 606dd80 | 2017-06-05 14:06:32 -0700 | [diff] [blame] | 2783 | } finally { |
Wale Ogunwale | dd2ae3d | 2018-02-15 13:58:46 -0800 | [diff] [blame] | 2784 | if (windowingMode == WINDOWING_MODE_SPLIT_SCREEN_PRIMARY && task != null) { |
| 2785 | // If we are launching the task in the docked stack, put it into resizing mode so |
| 2786 | // the window renders full-screen with the background filling the void. Also only |
| 2787 | // call this at the end to make sure that tasks exists on the window manager side. |
| 2788 | setResizingDuringAnimation(task); |
| 2789 | |
| 2790 | final ActivityDisplay display = task.getStack().getDisplay(); |
| 2791 | final ActivityStack topSecondaryStack = |
| 2792 | display.getTopStackInWindowingMode(WINDOWING_MODE_SPLIT_SCREEN_SECONDARY); |
| 2793 | if (topSecondaryStack.isActivityTypeHome()) { |
Louis Chang | bd48dca | 2018-08-29 17:44:34 +0800 | [diff] [blame] | 2794 | // If the home activity is the top split-screen secondary stack, then the |
Wale Ogunwale | dd2ae3d | 2018-02-15 13:58:46 -0800 | [diff] [blame] | 2795 | // primary split-screen stack is in the minimized mode which means it can't |
| 2796 | // receive input keys, so we should move the focused app to the home app so that |
| 2797 | // window manager can correctly calculate the focus window that can receive |
| 2798 | // input keys. |
lumark | 95f2063 | 2019-06-19 16:42:35 +0800 | [diff] [blame] | 2799 | display.moveHomeActivityToTop( |
Louis Chang | bd48dca | 2018-08-29 17:44:34 +0800 | [diff] [blame] | 2800 | "startActivityFromRecents: homeVisibleInSplitScreen"); |
Winson Chung | c167427 | 2018-02-21 10:15:17 -0800 | [diff] [blame] | 2801 | |
| 2802 | // Immediately update the minimized docked stack mode, the upcoming animation |
| 2803 | // for the docked activity (WMS.overridePendingAppTransitionMultiThumbFuture) |
| 2804 | // will do the animation to the target bounds |
| 2805 | mWindowManager.checkSplitScreenMinimizedChanged(false /* animate */); |
Wale Ogunwale | dd2ae3d | 2018-02-15 13:58:46 -0800 | [diff] [blame] | 2806 | } |
| 2807 | } |
Riddle Hsu | a0022cd | 2019-09-09 21:12:41 +0800 | [diff] [blame] | 2808 | mService.continueWindowLayout(); |
Jorim Jaggi | 0b46f3c | 2016-03-14 12:21:37 +0100 | [diff] [blame] | 2809 | } |
Jorim Jaggi | 0b46f3c | 2016-03-14 12:21:37 +0100 | [diff] [blame] | 2810 | } |
Amith Yamasani | e8222e5 | 2016-04-08 15:28:47 -0700 | [diff] [blame] | 2811 | |
| 2812 | /** |
Bryce Lee | 4a19438 | 2017-04-04 14:32:48 -0700 | [diff] [blame] | 2813 | * Internal container to store a match qualifier alongside a WaitResult. |
| 2814 | */ |
| 2815 | static class WaitInfo { |
| 2816 | private final ComponentName mTargetComponent; |
| 2817 | private final WaitResult mResult; |
| 2818 | |
Riddle Hsu | c48c891 | 2019-10-31 13:34:27 +0800 | [diff] [blame] | 2819 | WaitInfo(ComponentName targetComponent, WaitResult result) { |
Bryce Lee | 4a19438 | 2017-04-04 14:32:48 -0700 | [diff] [blame] | 2820 | this.mTargetComponent = targetComponent; |
| 2821 | this.mResult = result; |
| 2822 | } |
| 2823 | |
Wale Ogunwale | 3270f17 | 2017-04-26 07:29:42 -0700 | [diff] [blame] | 2824 | public boolean matches(ComponentName targetComponent) { |
| 2825 | return mTargetComponent == null || mTargetComponent.equals(targetComponent); |
Bryce Lee | 4a19438 | 2017-04-04 14:32:48 -0700 | [diff] [blame] | 2826 | } |
| 2827 | |
| 2828 | public WaitResult getResult() { |
| 2829 | return mResult; |
| 2830 | } |
| 2831 | |
| 2832 | public ComponentName getComponent() { |
| 2833 | return mTargetComponent; |
| 2834 | } |
| 2835 | |
| 2836 | public void dump(PrintWriter pw, String prefix) { |
| 2837 | pw.println(prefix + "WaitInfo:"); |
| 2838 | pw.println(prefix + " mTargetComponent=" + mTargetComponent); |
| 2839 | pw.println(prefix + " mResult="); |
| 2840 | mResult.dump(pw, prefix); |
| 2841 | } |
| 2842 | } |
Craig Mautner | 2708430 | 2013-03-25 08:05:25 -0700 | [diff] [blame] | 2843 | } |