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