Craig Mautner | 2708430 | 2013-03-25 08:05:25 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2013 The Android Open Source Project |
| 3 | * |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | * you may not use this file except in compliance with the License. |
| 6 | * You may obtain a copy of the License at |
| 7 | * |
| 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | * |
| 10 | * Unless required by applicable law or agreed to in writing, software |
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | * See the License for the specific language governing permissions and |
| 14 | * limitations under the License. |
| 15 | */ |
| 16 | |
| 17 | package com.android.server.am; |
| 18 | |
Andrii Kulian | 3c9ad07 | 2017-08-01 11:45:22 -0700 | [diff] [blame] | 19 | import static android.Manifest.permission.ACTIVITY_EMBEDDING; |
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; |
| 22 | import static android.Manifest.permission.START_TASKS_FROM_RECENTS; |
Charles He | ff9b4dff | 2017-09-22 10:18:37 +0100 | [diff] [blame] | 23 | import static android.app.ActivityManager.LOCK_TASK_MODE_LOCKED; |
Jorim Jaggi | fe76234 | 2016-10-13 14:33:27 +0200 | [diff] [blame] | 24 | import static android.app.ActivityManager.START_TASK_TO_FRONT; |
Jorim Jaggi | fe76234 | 2016-10-13 14:33:27 +0200 | [diff] [blame] | 25 | import static android.app.ActivityManager.StackId.INVALID_STACK_ID; |
Andrii Kulian | 036e3ad | 2017-04-19 10:55:10 -0700 | [diff] [blame] | 26 | import static android.app.ITaskStackListener.FORCED_RESIZEABLE_REASON_SECONDARY_DISPLAY; |
| 27 | import static android.app.ITaskStackListener.FORCED_RESIZEABLE_REASON_SPLIT_SCREEN; |
Wale Ogunwale | 6827856 | 2017-09-23 17:13:55 -0700 | [diff] [blame] | 28 | import static android.app.WindowConfiguration.ACTIVITY_TYPE_ASSISTANT; |
Wale Ogunwale | 6fbde9f | 2017-08-24 07:24:12 -0700 | [diff] [blame] | 29 | import static android.app.WindowConfiguration.ACTIVITY_TYPE_HOME; |
Wale Ogunwale | 0568aed | 2017-09-08 13:29:37 -0700 | [diff] [blame] | 30 | import static android.app.WindowConfiguration.ACTIVITY_TYPE_RECENTS; |
Wale Ogunwale | 6fbde9f | 2017-08-24 07:24:12 -0700 | [diff] [blame] | 31 | import static android.app.WindowConfiguration.ACTIVITY_TYPE_STANDARD; |
| 32 | import static android.app.WindowConfiguration.ACTIVITY_TYPE_UNDEFINED; |
Wale Ogunwale | 0568aed | 2017-09-08 13:29:37 -0700 | [diff] [blame] | 33 | import static android.app.WindowConfiguration.WINDOWING_MODE_FREEFORM; |
Wale Ogunwale | 926aade | 2017-08-29 11:24:37 -0700 | [diff] [blame] | 34 | import static android.app.WindowConfiguration.WINDOWING_MODE_FULLSCREEN; |
Wale Ogunwale | 44f036f | 2017-09-29 05:09:09 -0700 | [diff] [blame] | 35 | import static android.app.WindowConfiguration.WINDOWING_MODE_FULLSCREEN_OR_SPLIT_SCREEN_SECONDARY; |
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 | 44f036f | 2017-09-29 05:09:09 -0700 | [diff] [blame] | 40 | import static android.app.WindowConfiguration.activityTypeToString; |
| 41 | import static android.app.WindowConfiguration.windowingModeToString; |
Andrii Kulian | 3c9ad07 | 2017-08-01 11:45:22 -0700 | [diff] [blame] | 42 | import static android.content.pm.PackageManager.PERMISSION_DENIED; |
Jorim Jaggi | fe76234 | 2016-10-13 14:33:27 +0200 | [diff] [blame] | 43 | import static android.content.pm.PackageManager.PERMISSION_GRANTED; |
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; |
Winson Chung | 1dbc811 | 2017-09-28 18:05:31 -0700 | [diff] [blame] | 50 | |
Winson Chung | 4790065 | 2017-04-06 18:44:25 -0700 | [diff] [blame] | 51 | import static com.android.internal.logging.nano.MetricsProto.MetricsEvent.ACTION_PICTURE_IN_PICTURE_EXPANDED_TO_FULLSCREEN; |
Jorim Jaggi | fe76234 | 2016-10-13 14:33:27 +0200 | [diff] [blame] | 52 | import static com.android.server.am.ActivityManagerDebugConfig.DEBUG_ALL; |
Jorim Jaggi | fe76234 | 2016-10-13 14:33:27 +0200 | [diff] [blame] | 53 | import static com.android.server.am.ActivityManagerDebugConfig.DEBUG_FOCUS; |
| 54 | import static com.android.server.am.ActivityManagerDebugConfig.DEBUG_IDLE; |
Jorim Jaggi | fe76234 | 2016-10-13 14:33:27 +0200 | [diff] [blame] | 55 | import static com.android.server.am.ActivityManagerDebugConfig.DEBUG_PAUSE; |
| 56 | import static com.android.server.am.ActivityManagerDebugConfig.DEBUG_RECENTS; |
| 57 | import static com.android.server.am.ActivityManagerDebugConfig.DEBUG_RELEASE; |
| 58 | import static com.android.server.am.ActivityManagerDebugConfig.DEBUG_STACK; |
| 59 | import static com.android.server.am.ActivityManagerDebugConfig.DEBUG_STATES; |
| 60 | import static com.android.server.am.ActivityManagerDebugConfig.DEBUG_SWITCH; |
| 61 | import static com.android.server.am.ActivityManagerDebugConfig.DEBUG_TASKS; |
Jorim Jaggi | fe76234 | 2016-10-13 14:33:27 +0200 | [diff] [blame] | 62 | import static com.android.server.am.ActivityManagerDebugConfig.POSTFIX_FOCUS; |
| 63 | import static com.android.server.am.ActivityManagerDebugConfig.POSTFIX_IDLE; |
Jorim Jaggi | fe76234 | 2016-10-13 14:33:27 +0200 | [diff] [blame] | 64 | import static com.android.server.am.ActivityManagerDebugConfig.POSTFIX_PAUSE; |
| 65 | import static com.android.server.am.ActivityManagerDebugConfig.POSTFIX_RECENTS; |
| 66 | import static com.android.server.am.ActivityManagerDebugConfig.POSTFIX_RELEASE; |
| 67 | import static com.android.server.am.ActivityManagerDebugConfig.POSTFIX_STACK; |
| 68 | import static com.android.server.am.ActivityManagerDebugConfig.POSTFIX_STATES; |
| 69 | import static com.android.server.am.ActivityManagerDebugConfig.POSTFIX_SWITCH; |
| 70 | import static com.android.server.am.ActivityManagerDebugConfig.POSTFIX_TASKS; |
Jorim Jaggi | fe76234 | 2016-10-13 14:33:27 +0200 | [diff] [blame] | 71 | import static com.android.server.am.ActivityManagerDebugConfig.TAG_AM; |
| 72 | import static com.android.server.am.ActivityManagerDebugConfig.TAG_WITH_CLASS_NAME; |
| 73 | import static com.android.server.am.ActivityManagerService.ANIMATE; |
| 74 | import static com.android.server.am.ActivityManagerService.FIRST_SUPERVISOR_STACK_MSG; |
Jorim Jaggi | fe76234 | 2016-10-13 14:33:27 +0200 | [diff] [blame] | 75 | import static com.android.server.am.ActivityStack.ActivityState.DESTROYED; |
| 76 | import static com.android.server.am.ActivityStack.ActivityState.DESTROYING; |
| 77 | import static com.android.server.am.ActivityStack.ActivityState.INITIALIZING; |
| 78 | import static com.android.server.am.ActivityStack.ActivityState.PAUSED; |
| 79 | import static com.android.server.am.ActivityStack.ActivityState.PAUSING; |
| 80 | import static com.android.server.am.ActivityStack.ActivityState.RESUMED; |
| 81 | import static com.android.server.am.ActivityStack.ActivityState.STOPPED; |
| 82 | import static com.android.server.am.ActivityStack.ActivityState.STOPPING; |
| 83 | import static com.android.server.am.ActivityStack.REMOVE_TASK_MODE_MOVING; |
Wale Ogunwale | 0568aed | 2017-09-08 13:29:37 -0700 | [diff] [blame] | 84 | import static com.android.server.am.TaskRecord.INVALID_TASK_ID; |
Jorim Jaggi | fe76234 | 2016-10-13 14:33:27 +0200 | [diff] [blame] | 85 | import static com.android.server.am.TaskRecord.LOCK_TASK_AUTH_LAUNCHABLE; |
| 86 | import static com.android.server.am.TaskRecord.LOCK_TASK_AUTH_LAUNCHABLE_PRIV; |
Charles He | ff9b4dff | 2017-09-22 10:18:37 +0100 | [diff] [blame] | 87 | import static com.android.server.am.TaskRecord.LOCK_TASK_AUTH_WHITELISTED; |
Winson Chung | 7466610 | 2017-02-22 17:49:24 -0800 | [diff] [blame] | 88 | import static com.android.server.am.TaskRecord.REPARENT_KEEP_STACK_AT_FRONT; |
| 89 | import static com.android.server.am.TaskRecord.REPARENT_LEAVE_STACK_IN_PLACE; |
| 90 | import static com.android.server.am.TaskRecord.REPARENT_MOVE_STACK_TO_FRONT; |
Winson Chung | 1dbc811 | 2017-09-28 18:05:31 -0700 | [diff] [blame] | 91 | import static com.android.server.am.proto.ActivityStackSupervisorProto.CONFIGURATION_CONTAINER; |
Steven Timotius | 4346f0a | 2017-09-12 11:07:21 -0700 | [diff] [blame] | 92 | import static com.android.server.am.proto.ActivityStackSupervisorProto.DISPLAYS; |
| 93 | import static com.android.server.am.proto.ActivityStackSupervisorProto.FOCUSED_STACK_ID; |
| 94 | import static com.android.server.am.proto.ActivityStackSupervisorProto.KEYGUARD_CONTROLLER; |
| 95 | import static com.android.server.am.proto.ActivityStackSupervisorProto.RESUMED_ACTIVITY; |
Jorim Jaggi | fe76234 | 2016-10-13 14:33:27 +0200 | [diff] [blame] | 96 | import static com.android.server.wm.AppTransition.TRANSIT_DOCK_TASK_FROM_RECENTS; |
Winson Chung | 1dbc811 | 2017-09-28 18:05:31 -0700 | [diff] [blame] | 97 | |
Wale Ogunwale | e1fe7fa2 | 2016-12-15 18:27:00 -0800 | [diff] [blame] | 98 | import static java.lang.Integer.MAX_VALUE; |
Jorim Jaggi | fe76234 | 2016-10-13 14:33:27 +0200 | [diff] [blame] | 99 | |
Svetoslav | 7008b51 | 2015-06-24 18:47:07 -0700 | [diff] [blame] | 100 | import android.Manifest; |
Winson Chung | 7900bee | 2017-03-10 08:59:25 -0800 | [diff] [blame] | 101 | import android.annotation.IntDef; |
Andrii Kulian | 16802aa | 2016-11-02 12:21:33 -0700 | [diff] [blame] | 102 | import android.annotation.NonNull; |
Wale Ogunwale | 0568aed | 2017-09-08 13:29:37 -0700 | [diff] [blame] | 103 | import android.annotation.Nullable; |
Tony Mak | 853304c | 2016-04-18 15:17:41 +0100 | [diff] [blame] | 104 | import android.annotation.UserIdInt; |
Craig Mautner | 2420ead | 2013-04-01 17:13:20 -0700 | [diff] [blame] | 105 | import android.app.Activity; |
Craig Mautner | 23ac33b | 2013-04-01 16:26:35 -0700 | [diff] [blame] | 106 | import android.app.ActivityManager; |
Filip Gruszczynski | 80e29f1 | 2015-12-14 14:58:30 -0800 | [diff] [blame] | 107 | import android.app.ActivityManager.RunningTaskInfo; |
Craig Mautner | ed6649f | 2013-12-02 14:08:25 -0800 | [diff] [blame] | 108 | import android.app.ActivityManager.StackInfo; |
David Stevens | 9440dc8 | 2017-03-16 19:00:20 -0700 | [diff] [blame] | 109 | import android.app.ActivityManagerInternal.SleepToken; |
Craig Mautner | 23ac33b | 2013-04-01 16:26:35 -0700 | [diff] [blame] | 110 | import android.app.ActivityOptions; |
Svetoslav | 7008b51 | 2015-06-24 18:47:07 -0700 | [diff] [blame] | 111 | import android.app.AppOpsManager; |
Jeff Hao | 1b012d3 | 2014-08-20 10:35:34 -0700 | [diff] [blame] | 112 | import android.app.ProfilerInfo; |
Craig Mautner | 2420ead | 2013-04-01 17:13:20 -0700 | [diff] [blame] | 113 | import android.app.ResultInfo; |
Sudheer Shanka | fc46e9b | 2016-10-21 17:55:27 -0700 | [diff] [blame] | 114 | import android.app.WaitResult; |
Winson Chung | 61c9e5a | 2017-10-11 10:39:32 -0700 | [diff] [blame] | 115 | import android.app.WindowConfiguration.ActivityType; |
| 116 | import android.app.WindowConfiguration.WindowingMode; |
Craig Mautner | 23ac33b | 2013-04-01 16:26:35 -0700 | [diff] [blame] | 117 | import android.content.ComponentName; |
Craig Mautner | 2219a1b | 2013-03-25 09:44:30 -0700 | [diff] [blame] | 118 | import android.content.Context; |
| 119 | import android.content.Intent; |
| 120 | import android.content.pm.ActivityInfo; |
Craig Mautner | 23ac33b | 2013-04-01 16:26:35 -0700 | [diff] [blame] | 121 | import android.content.pm.ApplicationInfo; |
Svetoslav | 7008b51 | 2015-06-24 18:47:07 -0700 | [diff] [blame] | 122 | import android.content.pm.PackageInfo; |
Craig Mautner | 23ac33b | 2013-04-01 16:26:35 -0700 | [diff] [blame] | 123 | import android.content.pm.PackageManager; |
| 124 | import android.content.pm.ResolveInfo; |
Clara Bayarri | f7fea16 | 2015-10-22 16:09:52 +0100 | [diff] [blame] | 125 | import android.content.pm.UserInfo; |
Craig Mautner | 23ac33b | 2013-04-01 16:26:35 -0700 | [diff] [blame] | 126 | import android.content.res.Configuration; |
Wale Ogunwale | 60454db | 2015-01-23 16:05:07 -0800 | [diff] [blame] | 127 | import android.graphics.Rect; |
Craig Mautner | 4a1cb22 | 2013-12-04 16:14:06 -0800 | [diff] [blame] | 128 | import android.hardware.display.DisplayManager; |
| 129 | import android.hardware.display.DisplayManager.DisplayListener; |
Andrii Kulian | fb1bf69 | 2017-01-17 11:17:34 -0800 | [diff] [blame] | 130 | import android.hardware.display.DisplayManagerInternal; |
Jeff Brown | ca9bc70 | 2014-02-11 14:32:56 -0800 | [diff] [blame] | 131 | import android.hardware.input.InputManagerInternal; |
Craig Mautner | 23ac33b | 2013-04-01 16:26:35 -0700 | [diff] [blame] | 132 | import android.os.Binder; |
Jorim Jaggi | 0b46f3c | 2016-03-14 12:21:37 +0100 | [diff] [blame] | 133 | import android.os.Bundle; |
Craig Mautner | b59dcfd | 2013-05-06 13:12:58 -0700 | [diff] [blame] | 134 | import android.os.Debug; |
Craig Mautner | ce5f3cb | 2013-04-22 08:58:54 -0700 | [diff] [blame] | 135 | import android.os.Handler; |
Craig Mautner | 23ac33b | 2013-04-01 16:26:35 -0700 | [diff] [blame] | 136 | import android.os.IBinder; |
Craig Mautner | 2219a1b | 2013-03-25 09:44:30 -0700 | [diff] [blame] | 137 | import android.os.Looper; |
Craig Mautner | 2420ead | 2013-04-01 17:13:20 -0700 | [diff] [blame] | 138 | import android.os.Message; |
Craig Mautner | 0eea92c | 2013-05-16 13:35:39 -0700 | [diff] [blame] | 139 | import android.os.PowerManager; |
Craig Mautner | 7ea5bd4 | 2013-07-05 15:27:08 -0700 | [diff] [blame] | 140 | import android.os.Process; |
Craig Mautner | 8d341ef | 2013-03-26 09:03:27 -0700 | [diff] [blame] | 141 | import android.os.RemoteException; |
Craig Mautner | 23ac33b | 2013-04-01 16:26:35 -0700 | [diff] [blame] | 142 | import android.os.SystemClock; |
Wale Ogunwale | cad05a0 | 2015-09-25 10:41:44 -0700 | [diff] [blame] | 143 | import android.os.Trace; |
Craig Mautner | 6170f73 | 2013-04-02 13:05:23 -0700 | [diff] [blame] | 144 | import android.os.UserHandle; |
Clara Bayarri | f7fea16 | 2015-10-22 16:09:52 +0100 | [diff] [blame] | 145 | import android.os.UserManager; |
Dianne Hackborn | 3d07c94 | 2015-03-13 18:02:54 -0700 | [diff] [blame] | 146 | import android.os.WorkSource; |
Svetoslav | 7008b51 | 2015-06-24 18:47:07 -0700 | [diff] [blame] | 147 | import android.provider.MediaStore; |
Dianne Hackborn | 91097de | 2014-04-04 18:02:06 -0700 | [diff] [blame] | 148 | import android.service.voice.IVoiceInteractionSession; |
Svetoslav | 7008b51 | 2015-06-24 18:47:07 -0700 | [diff] [blame] | 149 | import android.util.ArrayMap; |
Dianne Hackborn | 89ad456 | 2014-08-24 16:45:38 -0700 | [diff] [blame] | 150 | import android.util.ArraySet; |
Craig Mautner | 2420ead | 2013-04-01 17:13:20 -0700 | [diff] [blame] | 151 | import android.util.EventLog; |
Andrii Kulian | fb1bf69 | 2017-01-17 11:17:34 -0800 | [diff] [blame] | 152 | import android.util.IntArray; |
Wale Ogunwale | e610d3d | 2017-04-25 10:23:48 -0700 | [diff] [blame] | 153 | import android.util.MergedConfiguration; |
Craig Mautner | 8d341ef | 2013-03-26 09:03:27 -0700 | [diff] [blame] | 154 | import android.util.Slog; |
Craig Mautner | 4a1cb22 | 2013-12-04 16:14:06 -0800 | [diff] [blame] | 155 | import android.util.SparseArray; |
Craig Mautner | 4a1cb22 | 2013-12-04 16:14:06 -0800 | [diff] [blame] | 156 | import android.util.SparseIntArray; |
David Stevens | 9440dc8 | 2017-03-16 19:00:20 -0700 | [diff] [blame] | 157 | import android.util.TimeUtils; |
Steven Timotius | 4346f0a | 2017-09-12 11:07:21 -0700 | [diff] [blame] | 158 | import android.util.proto.ProtoOutputStream; |
Craig Mautner | ed6649f | 2013-12-02 14:08:25 -0800 | [diff] [blame] | 159 | import android.view.Display; |
Chong Zhang | b15758a | 2015-11-17 12:12:03 -0800 | [diff] [blame] | 160 | |
Andrii Kulian | 94e82d9b0 | 2017-07-13 15:33:06 -0700 | [diff] [blame] | 161 | import com.android.internal.annotations.VisibleForTesting; |
Dianne Hackborn | 85d558c | 2014-11-04 10:31:54 -0800 | [diff] [blame] | 162 | import com.android.internal.content.ReferrerIntent; |
Winson Chung | 14fbe14 | 2016-12-19 16:18:24 -0800 | [diff] [blame] | 163 | import com.android.internal.logging.MetricsLogger; |
Dianne Hackborn | cbfd23e | 2013-06-11 14:26:53 -0700 | [diff] [blame] | 164 | import com.android.internal.os.TransferPipe; |
Svetoslav | 7008b51 | 2015-06-24 18:47:07 -0700 | [diff] [blame] | 165 | import com.android.internal.util.ArrayUtils; |
Jeff Brown | ca9bc70 | 2014-02-11 14:32:56 -0800 | [diff] [blame] | 166 | import com.android.server.LocalServices; |
Craig Mautner | 2420ead | 2013-04-01 17:13:20 -0700 | [diff] [blame] | 167 | import com.android.server.am.ActivityStack.ActivityState; |
Wale Ogunwale | 98d6231 | 2017-07-12 09:24:56 -0700 | [diff] [blame] | 168 | import com.android.server.wm.ConfigurationContainer; |
Winson Chung | 19953ca | 2017-04-11 11:19:23 -0700 | [diff] [blame] | 169 | import com.android.server.wm.PinnedStackWindowController; |
Craig Mautner | ce5f3cb | 2013-04-22 08:58:54 -0700 | [diff] [blame] | 170 | import com.android.server.wm.WindowManagerService; |
Craig Mautner | 23ac33b | 2013-04-01 16:26:35 -0700 | [diff] [blame] | 171 | |
Craig Mautner | 8d341ef | 2013-03-26 09:03:27 -0700 | [diff] [blame] | 172 | import java.io.FileDescriptor; |
| 173 | import java.io.IOException; |
Craig Mautner | 2708430 | 2013-03-25 08:05:25 -0700 | [diff] [blame] | 174 | import java.io.PrintWriter; |
Winson Chung | 7900bee | 2017-03-10 08:59:25 -0800 | [diff] [blame] | 175 | import java.lang.annotation.Retention; |
| 176 | import java.lang.annotation.RetentionPolicy; |
Craig Mautner | 2219a1b | 2013-03-25 09:44:30 -0700 | [diff] [blame] | 177 | import java.util.ArrayList; |
David Stevens | 9440dc8 | 2017-03-16 19:00:20 -0700 | [diff] [blame] | 178 | import java.util.Iterator; |
Craig Mautner | 8d341ef | 2013-03-26 09:03:27 -0700 | [diff] [blame] | 179 | import java.util.List; |
Wale Ogunwale | 540e123 | 2015-05-01 15:35:39 -0700 | [diff] [blame] | 180 | import java.util.Set; |
Craig Mautner | 2708430 | 2013-03-25 08:05:25 -0700 | [diff] [blame] | 181 | |
Winson Chung | 1dbc811 | 2017-09-28 18:05:31 -0700 | [diff] [blame] | 182 | public class ActivityStackSupervisor extends ConfigurationContainer implements DisplayListener, |
| 183 | RecentTasks.Callbacks { |
Wale Ogunwale | e23149f | 2015-03-06 15:39:44 -0800 | [diff] [blame] | 184 | private static final String TAG = TAG_WITH_CLASS_NAME ? "ActivityStackSupervisor" : TAG_AM; |
Chong Zhang | 6cda19c | 2016-06-14 19:07:56 -0700 | [diff] [blame] | 185 | private static final String TAG_FOCUS = TAG + POSTFIX_FOCUS; |
Wale Ogunwale | 0fc365c | 2015-05-25 19:35:42 -0700 | [diff] [blame] | 186 | private static final String TAG_IDLE = TAG + POSTFIX_IDLE; |
Wale Ogunwale | ee006da | 2015-03-30 14:49:25 -0700 | [diff] [blame] | 187 | private static final String TAG_PAUSE = TAG + POSTFIX_PAUSE; |
Wale Ogunwale | ee006da | 2015-03-30 14:49:25 -0700 | [diff] [blame] | 188 | private static final String TAG_RECENTS = TAG + POSTFIX_RECENTS; |
Wale Ogunwale | 0fc365c | 2015-05-25 19:35:42 -0700 | [diff] [blame] | 189 | private static final String TAG_RELEASE = TAG + POSTFIX_RELEASE; |
Wale Ogunwale | ee006da | 2015-03-30 14:49:25 -0700 | [diff] [blame] | 190 | private static final String TAG_STACK = TAG + POSTFIX_STACK; |
Wale Ogunwale | 0fc365c | 2015-05-25 19:35:42 -0700 | [diff] [blame] | 191 | private static final String TAG_STATES = TAG + POSTFIX_STATES; |
Wale Ogunwale | ee006da | 2015-03-30 14:49:25 -0700 | [diff] [blame] | 192 | private static final String TAG_SWITCH = TAG + POSTFIX_SWITCH; |
Filip Gruszczynski | 07a0e49 | 2015-12-17 14:16:38 -0800 | [diff] [blame] | 193 | static final String TAG_TASKS = TAG + POSTFIX_TASKS; |
Wale Ogunwale | e23149f | 2015-03-06 15:39:44 -0800 | [diff] [blame] | 194 | |
Craig Mautner | f333327 | 2013-04-22 10:55:53 -0700 | [diff] [blame] | 195 | /** 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] | 196 | static final int IDLE_TIMEOUT = 10 * 1000; |
Craig Mautner | f333327 | 2013-04-22 10:55:53 -0700 | [diff] [blame] | 197 | |
Craig Mautner | 0eea92c | 2013-05-16 13:35:39 -0700 | [diff] [blame] | 198 | /** How long we can hold the sleep wake lock before giving up. */ |
Wale Ogunwale | 0fc365c | 2015-05-25 19:35:42 -0700 | [diff] [blame] | 199 | static final int SLEEP_TIMEOUT = 5 * 1000; |
Craig Mautner | 0eea92c | 2013-05-16 13:35:39 -0700 | [diff] [blame] | 200 | |
Craig Mautner | 7ea5bd4 | 2013-07-05 15:27:08 -0700 | [diff] [blame] | 201 | // How long we can hold the launch wake lock before giving up. |
Wale Ogunwale | 0fc365c | 2015-05-25 19:35:42 -0700 | [diff] [blame] | 202 | static final int LAUNCH_TIMEOUT = 10 * 1000; |
Craig Mautner | 7ea5bd4 | 2013-07-05 15:27:08 -0700 | [diff] [blame] | 203 | |
Craig Mautner | 05d2903 | 2013-05-03 13:40:13 -0700 | [diff] [blame] | 204 | static final int IDLE_TIMEOUT_MSG = FIRST_SUPERVISOR_STACK_MSG; |
| 205 | static final int IDLE_NOW_MSG = FIRST_SUPERVISOR_STACK_MSG + 1; |
| 206 | static final int RESUME_TOP_ACTIVITY_MSG = FIRST_SUPERVISOR_STACK_MSG + 2; |
Craig Mautner | 0eea92c | 2013-05-16 13:35:39 -0700 | [diff] [blame] | 207 | static final int SLEEP_TIMEOUT_MSG = FIRST_SUPERVISOR_STACK_MSG + 3; |
Craig Mautner | 7ea5bd4 | 2013-07-05 15:27:08 -0700 | [diff] [blame] | 208 | static final int LAUNCH_TIMEOUT_MSG = FIRST_SUPERVISOR_STACK_MSG + 4; |
Craig Mautner | 4a1cb22 | 2013-12-04 16:14:06 -0800 | [diff] [blame] | 209 | static final int HANDLE_DISPLAY_ADDED = FIRST_SUPERVISOR_STACK_MSG + 5; |
| 210 | static final int HANDLE_DISPLAY_CHANGED = FIRST_SUPERVISOR_STACK_MSG + 6; |
| 211 | static final int HANDLE_DISPLAY_REMOVED = FIRST_SUPERVISOR_STACK_MSG + 7; |
Wale Ogunwale | 73eba74 | 2015-04-07 14:23:14 -0700 | [diff] [blame] | 212 | static final int LAUNCH_TASK_BEHIND_COMPLETE = FIRST_SUPERVISOR_STACK_MSG + 12; |
Wale Ogunwale | 22e2526 | 2016-02-01 10:32:02 -0800 | [diff] [blame] | 213 | static final int REPORT_MULTI_WINDOW_MODE_CHANGED_MSG = FIRST_SUPERVISOR_STACK_MSG + 14; |
| 214 | static final int REPORT_PIP_MODE_CHANGED_MSG = FIRST_SUPERVISOR_STACK_MSG + 15; |
Craig Mautner | 4a1cb22 | 2013-12-04 16:14:06 -0800 | [diff] [blame] | 215 | |
Wale Ogunwale | 040b470 | 2015-08-06 18:10:50 -0700 | [diff] [blame] | 216 | private static final String VIRTUAL_DISPLAY_BASE_NAME = "ActivityViewVirtualDisplay"; |
Craig Mautner | 7ea5bd4 | 2013-07-05 15:27:08 -0700 | [diff] [blame] | 217 | |
Wale Ogunwale | 040b470 | 2015-08-06 18:10:50 -0700 | [diff] [blame] | 218 | // Used to indicate if an object (e.g. stack) that we are trying to get |
| 219 | // should be created if it doesn't exist already. |
Filip Gruszczynski | 07a0e49 | 2015-12-17 14:16:38 -0800 | [diff] [blame] | 220 | static final boolean CREATE_IF_NEEDED = true; |
Wale Ogunwale | 040b470 | 2015-08-06 18:10:50 -0700 | [diff] [blame] | 221 | |
Filip Gruszczynski | bc5a6c5 | 2015-09-22 13:13:24 -0700 | [diff] [blame] | 222 | // Used to indicate that windows of activities should be preserved during the resize. |
| 223 | static final boolean PRESERVE_WINDOWS = true; |
| 224 | |
Wale Ogunwale | 040b470 | 2015-08-06 18:10:50 -0700 | [diff] [blame] | 225 | // Used to indicate if an object (e.g. task) should be moved/created |
| 226 | // at the top of its container (e.g. stack). |
Wale Ogunwale | b30daaa | 2015-08-07 21:50:49 -0700 | [diff] [blame] | 227 | static final boolean ON_TOP = true; |
Wale Ogunwale | 040b470 | 2015-08-06 18:10:50 -0700 | [diff] [blame] | 228 | |
Wale Ogunwale | c8da41e | 2016-04-16 13:27:23 -0700 | [diff] [blame] | 229 | // Don't execute any calls to resume. |
| 230 | static final boolean DEFER_RESUME = true; |
| 231 | |
Winson Chung | 010927a | 2016-12-15 16:12:35 -0800 | [diff] [blame] | 232 | // Used to indicate that a task is removed it should also be removed from recents. |
| 233 | static final boolean REMOVE_FROM_RECENTS = true; |
| 234 | |
Winson Chung | 6954fc9 | 2017-03-24 16:22:12 -0700 | [diff] [blame] | 235 | // Used to indicate that pausing an activity should occur immediately without waiting for |
| 236 | // the activity callback indicating that it has completed pausing |
| 237 | static final boolean PAUSE_IMMEDIATELY = true; |
| 238 | |
Winson Chung | 7900bee | 2017-03-10 08:59:25 -0800 | [diff] [blame] | 239 | /** |
| 240 | * The modes which affect which tasks are returned when calling |
| 241 | * {@link ActivityStackSupervisor#anyTaskForIdLocked(int)}. |
| 242 | */ |
| 243 | @Retention(RetentionPolicy.SOURCE) |
| 244 | @IntDef({ |
| 245 | MATCH_TASK_IN_STACKS_ONLY, |
| 246 | MATCH_TASK_IN_STACKS_OR_RECENT_TASKS, |
| 247 | MATCH_TASK_IN_STACKS_OR_RECENT_TASKS_AND_RESTORE |
| 248 | }) |
| 249 | public @interface AnyTaskForIdMatchTaskMode {} |
| 250 | // Match only tasks in the current stacks |
| 251 | static final int MATCH_TASK_IN_STACKS_ONLY = 0; |
| 252 | // Match either tasks in the current stacks, or in the recent tasks if not found in the stacks |
| 253 | static final int MATCH_TASK_IN_STACKS_OR_RECENT_TASKS = 1; |
| 254 | // Match either tasks in the current stacks, or in the recent tasks, restoring it to the |
| 255 | // provided stack id |
| 256 | static final int MATCH_TASK_IN_STACKS_OR_RECENT_TASKS_AND_RESTORE = 2; |
| 257 | |
Svetoslav | 7008b51 | 2015-06-24 18:47:07 -0700 | [diff] [blame] | 258 | // Activity actions an app cannot start if it uses a permission which is not granted. |
| 259 | private static final ArrayMap<String, String> ACTION_TO_RUNTIME_PERMISSION = |
| 260 | new ArrayMap<>(); |
Filip Gruszczynski | bc5a6c5 | 2015-09-22 13:13:24 -0700 | [diff] [blame] | 261 | |
Svetoslav | 7008b51 | 2015-06-24 18:47:07 -0700 | [diff] [blame] | 262 | static { |
| 263 | ACTION_TO_RUNTIME_PERMISSION.put(MediaStore.ACTION_IMAGE_CAPTURE, |
| 264 | Manifest.permission.CAMERA); |
| 265 | ACTION_TO_RUNTIME_PERMISSION.put(MediaStore.ACTION_VIDEO_CAPTURE, |
| 266 | Manifest.permission.CAMERA); |
| 267 | ACTION_TO_RUNTIME_PERMISSION.put(Intent.ACTION_CALL, |
| 268 | Manifest.permission.CALL_PHONE); |
| 269 | } |
| 270 | |
Svet Ganov | 99b6043 | 2015-06-27 13:15:22 -0700 | [diff] [blame] | 271 | /** Action restriction: launching the activity is not restricted. */ |
| 272 | private static final int ACTIVITY_RESTRICTION_NONE = 0; |
| 273 | /** Action restriction: launching the activity is restricted by a permission. */ |
| 274 | private static final int ACTIVITY_RESTRICTION_PERMISSION = 1; |
| 275 | /** Action restriction: launching the activity is restricted by an app op. */ |
| 276 | private static final int ACTIVITY_RESTRICTION_APPOP = 2; |
Svetoslav | 7008b51 | 2015-06-24 18:47:07 -0700 | [diff] [blame] | 277 | |
Craig Mautner | 7ea5bd4 | 2013-07-05 15:27:08 -0700 | [diff] [blame] | 278 | // For debugging to make sure the caller when acquiring/releasing our |
| 279 | // wake lock is the system process. |
| 280 | static final boolean VALIDATE_WAKE_LOCK_CALLER = false; |
Suprabh Shukla | 09a88f5 | 2015-12-02 14:36:31 -0800 | [diff] [blame] | 281 | /** The number of distinct task ids that can be assigned to the tasks of a single user */ |
| 282 | 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] | 283 | |
Craig Mautner | 2708430 | 2013-03-25 08:05:25 -0700 | [diff] [blame] | 284 | final ActivityManagerService mService; |
| 285 | |
Winson Chung | 61c9e5a | 2017-10-11 10:39:32 -0700 | [diff] [blame] | 286 | /** The historial list of recent tasks including inactive tasks */ |
Winson Chung | 1dbc811 | 2017-09-28 18:05:31 -0700 | [diff] [blame] | 287 | RecentTasks mRecentTasks; |
Wale Ogunwale | c82f2f5 | 2014-12-09 09:32:50 -0800 | [diff] [blame] | 288 | |
Winson Chung | 61c9e5a | 2017-10-11 10:39:32 -0700 | [diff] [blame] | 289 | /** Helper class to abstract out logic for fetching the set of currently running tasks */ |
Winson Chung | 3f0e59a | 2017-10-25 10:19:05 -0700 | [diff] [blame] | 290 | private RunningTasks mRunningTasks; |
Winson Chung | 61c9e5a | 2017-10-11 10:39:32 -0700 | [diff] [blame] | 291 | |
Craig Mautner | ce5f3cb | 2013-04-22 08:58:54 -0700 | [diff] [blame] | 292 | final ActivityStackSupervisorHandler mHandler; |
| 293 | |
| 294 | /** Short cut */ |
| 295 | WindowManagerService mWindowManager; |
Craig Mautner | 4a1cb22 | 2013-12-04 16:14:06 -0800 | [diff] [blame] | 296 | DisplayManager mDisplayManager; |
Craig Mautner | ce5f3cb | 2013-04-22 08:58:54 -0700 | [diff] [blame] | 297 | |
Bryce Lee | 2a3cc46 | 2017-10-27 10:57:35 -0700 | [diff] [blame] | 298 | private LaunchingBoundsController mLaunchingBoundsController; |
Bryce Lee | 9ad3eb3 | 2017-10-10 10:10:31 -0700 | [diff] [blame] | 299 | |
Wale Ogunwale | ddc1cb2 | 2015-07-25 19:23:04 -0700 | [diff] [blame] | 300 | /** Counter for next free stack ID to use for dynamic activity stacks. */ |
Wale Ogunwale | 44f036f | 2017-09-29 05:09:09 -0700 | [diff] [blame] | 301 | private int mNextFreeStackId = 0; |
Craig Mautner | 8d341ef | 2013-03-26 09:03:27 -0700 | [diff] [blame] | 302 | |
Suprabh Shukla | 09a88f5 | 2015-12-02 14:36:31 -0800 | [diff] [blame] | 303 | /** |
| 304 | * Maps the task identifier that activities are currently being started in to the userId of the |
| 305 | * task. Each time a new task is created, the entry for the userId of the task is incremented |
| 306 | */ |
| 307 | private final SparseIntArray mCurTaskIdForUser = new SparseIntArray(20); |
Craig Mautner | 8d341ef | 2013-03-26 09:03:27 -0700 | [diff] [blame] | 308 | |
Craig Mautner | 2420ead | 2013-04-01 17:13:20 -0700 | [diff] [blame] | 309 | /** The current user */ |
Filip Gruszczynski | 07a0e49 | 2015-12-17 14:16:38 -0800 | [diff] [blame] | 310 | int mCurrentUser; |
Craig Mautner | 2420ead | 2013-04-01 17:13:20 -0700 | [diff] [blame] | 311 | |
Craig Mautner | e0a3884 | 2013-12-16 16:14:02 -0800 | [diff] [blame] | 312 | /** The stack containing the launcher app. Assumed to always be attached to |
| 313 | * Display.DEFAULT_DISPLAY. */ |
Filip Gruszczynski | 07a0e49 | 2015-12-17 14:16:38 -0800 | [diff] [blame] | 314 | ActivityStack mHomeStack; |
Craig Mautner | 20e7227 | 2013-04-01 13:45:53 -0700 | [diff] [blame] | 315 | |
Craig Mautner | e0a3884 | 2013-12-16 16:14:02 -0800 | [diff] [blame] | 316 | /** The stack currently receiving input or launching the next activity. */ |
Filip Gruszczynski | 07a0e49 | 2015-12-17 14:16:38 -0800 | [diff] [blame] | 317 | ActivityStack mFocusedStack; |
Craig Mautner | 8d341ef | 2013-03-26 09:03:27 -0700 | [diff] [blame] | 318 | |
Craig Mautner | 4a1cb22 | 2013-12-04 16:14:06 -0800 | [diff] [blame] | 319 | /** If this is the same as mFocusedStack then the activity on the top of the focused stack has |
| 320 | * been resumed. If stacks are changing position this will hold the old stack until the new |
Craig Mautner | e0a3884 | 2013-12-16 16:14:02 -0800 | [diff] [blame] | 321 | * stack becomes resumed after which it will be set to mFocusedStack. */ |
Craig Mautner | 4a1cb22 | 2013-12-04 16:14:06 -0800 | [diff] [blame] | 322 | private ActivityStack mLastFocusedStack; |
Craig Mautner | de4ef02 | 2013-04-07 19:01:33 -0700 | [diff] [blame] | 323 | |
| 324 | /** List of activities that are waiting for a new activity to become visible before completing |
| 325 | * whatever operation they are supposed to do. */ |
Bryce Lee | 4a19438 | 2017-04-04 14:32:48 -0700 | [diff] [blame] | 326 | // TODO: Remove mActivitiesWaitingForVisibleActivity list and just remove activity from |
| 327 | // mStoppingActivities when something else comes up. |
| 328 | final ArrayList<ActivityRecord> mActivitiesWaitingForVisibleActivity = new ArrayList<>(); |
Craig Mautner | de4ef02 | 2013-04-07 19:01:33 -0700 | [diff] [blame] | 329 | |
Bryce Lee | 4a19438 | 2017-04-04 14:32:48 -0700 | [diff] [blame] | 330 | /** List of processes waiting to find out when a specific activity becomes visible. */ |
| 331 | private final ArrayList<WaitInfo> mWaitingForActivityVisible = new ArrayList<>(); |
Craig Mautner | ce5f3cb | 2013-04-22 08:58:54 -0700 | [diff] [blame] | 332 | |
| 333 | /** List of processes waiting to find out about the next launched activity. */ |
Sudheer Shanka | fc46e9b | 2016-10-21 17:55:27 -0700 | [diff] [blame] | 334 | final ArrayList<WaitResult> mWaitingActivityLaunched = new ArrayList<>(); |
Craig Mautner | ce5f3cb | 2013-04-22 08:58:54 -0700 | [diff] [blame] | 335 | |
Craig Mautner | de4ef02 | 2013-04-07 19:01:33 -0700 | [diff] [blame] | 336 | /** List of activities that are ready to be stopped, but waiting for the next activity to |
| 337 | * settle down before doing so. */ |
Craig Mautner | 8c14c15 | 2015-01-15 17:32:07 -0800 | [diff] [blame] | 338 | final ArrayList<ActivityRecord> mStoppingActivities = new ArrayList<>(); |
Craig Mautner | de4ef02 | 2013-04-07 19:01:33 -0700 | [diff] [blame] | 339 | |
Craig Mautner | f333327 | 2013-04-22 10:55:53 -0700 | [diff] [blame] | 340 | /** List of activities that are ready to be finished, but waiting for the previous activity to |
| 341 | * settle down before doing so. It contains ActivityRecord objects. */ |
Craig Mautner | 8c14c15 | 2015-01-15 17:32:07 -0800 | [diff] [blame] | 342 | final ArrayList<ActivityRecord> mFinishingActivities = new ArrayList<>(); |
Craig Mautner | f333327 | 2013-04-22 10:55:53 -0700 | [diff] [blame] | 343 | |
Craig Mautner | 0eea92c | 2013-05-16 13:35:39 -0700 | [diff] [blame] | 344 | /** List of activities that are in the process of going to sleep. */ |
Craig Mautner | 8c14c15 | 2015-01-15 17:32:07 -0800 | [diff] [blame] | 345 | final ArrayList<ActivityRecord> mGoingToSleepActivities = new ArrayList<>(); |
Craig Mautner | 0eea92c | 2013-05-16 13:35:39 -0700 | [diff] [blame] | 346 | |
Wale Ogunwale | 22e2526 | 2016-02-01 10:32:02 -0800 | [diff] [blame] | 347 | /** List of activities whose multi-window mode changed that we need to report to the |
| 348 | * application */ |
| 349 | final ArrayList<ActivityRecord> mMultiWindowModeChangedActivities = new ArrayList<>(); |
| 350 | |
| 351 | /** List of activities whose picture-in-picture mode changed that we need to report to the |
| 352 | * application */ |
| 353 | final ArrayList<ActivityRecord> mPipModeChangedActivities = new ArrayList<>(); |
| 354 | |
Winson Chung | 5af42fc | 2017-03-24 17:11:33 -0700 | [diff] [blame] | 355 | /** The target stack bounds for the picture-in-picture mode changed that we need to report to |
| 356 | * the application */ |
| 357 | Rect mPipModeChangedTargetStackBounds; |
| 358 | |
Craig Mautner | f333327 | 2013-04-22 10:55:53 -0700 | [diff] [blame] | 359 | /** Used on user changes */ |
Amith Yamasani | 37a40c2 | 2015-06-17 13:25:42 -0700 | [diff] [blame] | 360 | final ArrayList<UserState> mStartingUsers = new ArrayList<>(); |
Craig Mautner | f333327 | 2013-04-22 10:55:53 -0700 | [diff] [blame] | 361 | |
Craig Mautner | de4ef02 | 2013-04-07 19:01:33 -0700 | [diff] [blame] | 362 | /** Set to indicate whether to issue an onUserLeaving callback when a newly launched activity |
| 363 | * is being brought in front of us. */ |
| 364 | boolean mUserLeaving = false; |
| 365 | |
Craig Mautner | 0eea92c | 2013-05-16 13:35:39 -0700 | [diff] [blame] | 366 | /** |
Craig Mautner | 7ea5bd4 | 2013-07-05 15:27:08 -0700 | [diff] [blame] | 367 | * We don't want to allow the device to go to sleep while in the process |
| 368 | * of launching an activity. This is primarily to allow alarm intent |
| 369 | * receivers to launch an activity and get that to run before the device |
| 370 | * goes back to sleep. |
| 371 | */ |
Jeff Brown | 2c43c33 | 2014-06-12 22:38:59 -0700 | [diff] [blame] | 372 | PowerManager.WakeLock mLaunchingActivity; |
Craig Mautner | 7ea5bd4 | 2013-07-05 15:27:08 -0700 | [diff] [blame] | 373 | |
| 374 | /** |
Craig Mautner | 0eea92c | 2013-05-16 13:35:39 -0700 | [diff] [blame] | 375 | * Set when the system is going to sleep, until we have |
| 376 | * successfully paused the current activity and released our wake lock. |
| 377 | * At that point the system is allowed to actually sleep. |
| 378 | */ |
Jeff Brown | 2c43c33 | 2014-06-12 22:38:59 -0700 | [diff] [blame] | 379 | PowerManager.WakeLock mGoingToSleep; |
Craig Mautner | 0eea92c | 2013-05-16 13:35:39 -0700 | [diff] [blame] | 380 | |
David Stevens | 9440dc8 | 2017-03-16 19:00:20 -0700 | [diff] [blame] | 381 | /** |
| 382 | * A list of tokens that cause the top activity to be put to sleep. |
| 383 | * They are used by components that may hide and block interaction with underlying |
| 384 | * activities. |
| 385 | */ |
Wale Ogunwale | 9dcf946 | 2017-09-19 15:13:01 -0700 | [diff] [blame] | 386 | final ArrayList<SleepToken> mSleepTokens = new ArrayList<>(); |
David Stevens | 9440dc8 | 2017-03-16 19:00:20 -0700 | [diff] [blame] | 387 | |
Craig Mautner | 4f1df4f | 2013-10-15 15:44:14 -0700 | [diff] [blame] | 388 | /** Stack id of the front stack when user switched, indexed by userId. */ |
| 389 | SparseIntArray mUserStackInFront = new SparseIntArray(2); |
Craig Mautner | 93529a4 | 2013-10-04 15:03:13 -0700 | [diff] [blame] | 390 | |
Bryce Lee | af3a400 | 2017-03-20 10:37:12 -0700 | [diff] [blame] | 391 | // TODO: There should be an ActivityDisplayController coordinating am/wm interaction. |
Craig Mautner | 4a1cb22 | 2013-12-04 16:14:06 -0800 | [diff] [blame] | 392 | /** Mapping from displayId to display current state */ |
Craig Mautner | 15df08a | 2015-04-01 12:17:18 -0700 | [diff] [blame] | 393 | private final SparseArray<ActivityDisplay> mActivityDisplays = new SparseArray<>(); |
Craig Mautner | 4a1cb22 | 2013-12-04 16:14:06 -0800 | [diff] [blame] | 394 | |
Andrii Kulian | fb1bf69 | 2017-01-17 11:17:34 -0800 | [diff] [blame] | 395 | private final SparseArray<IntArray> mDisplayAccessUIDs = new SparseArray<>(); |
| 396 | |
| 397 | private DisplayManagerInternal mDisplayManagerInternal; |
Jeff Brown | ca9bc70 | 2014-02-11 14:32:56 -0800 | [diff] [blame] | 398 | |
Wale Ogunwale | d046a01 | 2015-12-24 13:05:59 -0800 | [diff] [blame] | 399 | /** Used to keep resumeTopActivityUncheckedLocked() from being entered recursively */ |
Craig Mautner | 42d04db | 2014-11-06 12:13:23 -0800 | [diff] [blame] | 400 | boolean inResumeTopActivity; |
| 401 | |
Andrii Kulian | 1e32e02 | 2016-09-16 15:29:34 -0700 | [diff] [blame] | 402 | /** |
| 403 | * Temporary rect used during docked stack resize calculation so we don't need to create a new |
| 404 | * object each time. |
| 405 | */ |
Wale Ogunwale | b34a7ad | 2015-08-14 11:05:30 -0700 | [diff] [blame] | 406 | private final Rect tempRect = new Rect(); |
Wale Ogunwale | 7e1f5f5 | 2017-10-18 15:19:59 -0700 | [diff] [blame] | 407 | private final ActivityOptions mTmpOptions = ActivityOptions.makeBasic(); |
Filip Gruszczynski | ebcc875 | 2015-08-25 16:51:05 -0700 | [diff] [blame] | 408 | |
Filip Gruszczynski | d2f1d94 | 2015-10-14 15:10:12 -0700 | [diff] [blame] | 409 | // The default minimal size that will be used if the activity doesn't specify its minimal size. |
| 410 | // It will be calculated when the default display gets added. |
Andrii Kulian | f66a83d | 2016-05-17 12:17:44 -0700 | [diff] [blame] | 411 | int mDefaultMinSizeOfResizeableTask = -1; |
Filip Gruszczynski | d2f1d94 | 2015-10-14 15:10:12 -0700 | [diff] [blame] | 412 | |
Chong Zhang | fdcc4d4 | 2015-10-14 16:50:12 -0700 | [diff] [blame] | 413 | // Whether tasks have moved and we need to rank the tasks before next OOM scoring |
| 414 | private boolean mTaskLayersChanged = true; |
| 415 | |
Bryce Lee | 2a3cc46 | 2017-10-27 10:57:35 -0700 | [diff] [blame] | 416 | private ActivityMetricsLogger mActivityMetricsLogger; |
Filip Gruszczynski | 77d9448 | 2015-12-11 13:59:52 -0800 | [diff] [blame] | 417 | |
Jorim Jaggi | ea039a8 | 2017-08-02 14:37:49 +0200 | [diff] [blame] | 418 | private final ArrayList<ActivityRecord> mTmpActivityList = new ArrayList<>(); |
| 419 | |
Andrii Kulian | 1779e61 | 2016-10-12 21:58:25 -0700 | [diff] [blame] | 420 | @Override |
| 421 | protected int getChildCount() { |
| 422 | return mActivityDisplays.size(); |
| 423 | } |
| 424 | |
| 425 | @Override |
Andrii Kulian | 5406e7a | 2016-10-21 11:55:23 -0700 | [diff] [blame] | 426 | protected ActivityDisplay getChildAt(int index) { |
Andrii Kulian | 1779e61 | 2016-10-12 21:58:25 -0700 | [diff] [blame] | 427 | return mActivityDisplays.valueAt(index); |
| 428 | } |
| 429 | |
| 430 | @Override |
| 431 | protected ConfigurationContainer getParent() { |
| 432 | return null; |
| 433 | } |
| 434 | |
Andrii Kulian | 5406e7a | 2016-10-21 11:55:23 -0700 | [diff] [blame] | 435 | Configuration getDisplayOverrideConfiguration(int displayId) { |
Andrii Kulian | 62e6f25 | 2017-05-30 22:46:53 -0700 | [diff] [blame] | 436 | final ActivityDisplay activityDisplay = getActivityDisplayOrCreateLocked(displayId); |
Andrii Kulian | 5406e7a | 2016-10-21 11:55:23 -0700 | [diff] [blame] | 437 | if (activityDisplay == null) { |
| 438 | throw new IllegalArgumentException("No display found with id: " + displayId); |
| 439 | } |
| 440 | |
| 441 | return activityDisplay.getOverrideConfiguration(); |
| 442 | } |
| 443 | |
| 444 | void setDisplayOverrideConfiguration(Configuration overrideConfiguration, int displayId) { |
Andrii Kulian | 62e6f25 | 2017-05-30 22:46:53 -0700 | [diff] [blame] | 445 | final ActivityDisplay activityDisplay = getActivityDisplayOrCreateLocked(displayId); |
Andrii Kulian | 5406e7a | 2016-10-21 11:55:23 -0700 | [diff] [blame] | 446 | if (activityDisplay == null) { |
| 447 | throw new IllegalArgumentException("No display found with id: " + displayId); |
| 448 | } |
| 449 | |
| 450 | activityDisplay.onOverrideConfigurationChanged(overrideConfiguration); |
| 451 | } |
| 452 | |
Andrii Kulian | 036e3ad | 2017-04-19 10:55:10 -0700 | [diff] [blame] | 453 | /** Check if placing task or activity on specified display is allowed. */ |
Andrii Kulian | 02689a7 | 2017-07-06 14:28:59 -0700 | [diff] [blame] | 454 | boolean canPlaceEntityOnDisplay(int displayId, boolean resizeable, int callingPid, |
| 455 | int callingUid, ActivityInfo activityInfo) { |
| 456 | if (displayId == DEFAULT_DISPLAY) { |
| 457 | // No restrictions for the default display. |
| 458 | return true; |
| 459 | } |
| 460 | if (!mService.mSupportsMultiDisplay) { |
| 461 | // Can't launch on secondary displays if feature is not supported. |
| 462 | return false; |
| 463 | } |
| 464 | if (!resizeable && !displayConfigMatchesGlobal(displayId)) { |
| 465 | // Can't apply wrong configuration to non-resizeable activities. |
| 466 | return false; |
| 467 | } |
| 468 | if (!isCallerAllowedToLaunchOnDisplay(callingPid, callingUid, displayId, activityInfo)) { |
| 469 | // Can't place activities to a display that has restricted launch rules. |
| 470 | // In this case the request should be made by explicitly adding target display id and |
| 471 | // by caller with corresponding permissions. See #isCallerAllowedToLaunchOnDisplay(). |
| 472 | return false; |
| 473 | } |
| 474 | return true; |
Andrii Kulian | 036e3ad | 2017-04-19 10:55:10 -0700 | [diff] [blame] | 475 | } |
| 476 | |
| 477 | /** |
| 478 | * Check if configuration of specified display matches current global config. |
| 479 | * Used to check if we can put a non-resizeable activity on a secondary display and it will get |
| 480 | * the same config as on the default display. |
| 481 | * @param displayId Id of the display to check. |
| 482 | * @return {@code true} if configuration matches. |
| 483 | */ |
| 484 | private boolean displayConfigMatchesGlobal(int displayId) { |
| 485 | if (displayId == DEFAULT_DISPLAY) { |
| 486 | return true; |
| 487 | } |
| 488 | if (displayId == INVALID_DISPLAY) { |
| 489 | return false; |
| 490 | } |
Andrii Kulian | 62e6f25 | 2017-05-30 22:46:53 -0700 | [diff] [blame] | 491 | final ActivityDisplay targetDisplay = getActivityDisplayOrCreateLocked(displayId); |
Andrii Kulian | 036e3ad | 2017-04-19 10:55:10 -0700 | [diff] [blame] | 492 | if (targetDisplay == null) { |
| 493 | throw new IllegalArgumentException("No display found with id: " + displayId); |
| 494 | } |
| 495 | return getConfiguration().equals(targetDisplay.getConfiguration()); |
| 496 | } |
| 497 | |
Wale Ogunwale | 3938197 | 2015-12-17 17:15:29 -0800 | [diff] [blame] | 498 | static class FindTaskResult { |
| 499 | ActivityRecord r; |
| 500 | boolean matchedByRootAffinity; |
| 501 | } |
| 502 | private final FindTaskResult mTmpFindTaskResult = new FindTaskResult(); |
| 503 | |
Craig Mautner | ee36c77 | 2014-07-16 14:56:05 -0700 | [diff] [blame] | 504 | /** |
Andrii Kulian | 7fc2281 | 2016-12-28 13:04:11 -0800 | [diff] [blame] | 505 | * Temp storage for display ids sorted in focus order. |
| 506 | * Maps position to id. Using {@link SparseIntArray} instead of {@link ArrayList} because |
| 507 | * it's more efficient, as the number of displays is usually small. |
| 508 | */ |
| 509 | private SparseIntArray mTmpOrderedDisplayIds = new SparseIntArray(); |
| 510 | |
| 511 | /** |
Jorim Jaggi | a0fdeec | 2016-01-07 14:42:28 +0100 | [diff] [blame] | 512 | * Used to keep track whether app visibilities got changed since the last pause. Useful to |
| 513 | * determine whether to invoke the task stack change listener after pausing. |
| 514 | */ |
| 515 | boolean mAppVisibilitiesChangedSinceLastPause; |
| 516 | |
| 517 | /** |
Jorim Jaggi | 0b46f3c | 2016-03-14 12:21:37 +0100 | [diff] [blame] | 518 | * Set of tasks that are in resizing mode during an app transition to fill the "void". |
| 519 | */ |
| 520 | private final ArraySet<Integer> mResizingTasksDuringAnimation = new ArraySet<>(); |
| 521 | |
Wale Ogunwale | c8da41e | 2016-04-16 13:27:23 -0700 | [diff] [blame] | 522 | |
| 523 | /** |
| 524 | * If set to {@code false} all calls to resize the docked stack {@link #resizeDockedStackLocked} |
| 525 | * will be ignored. Useful for the case where the caller is handling resizing of other stack and |
| 526 | * moving tasks around and doesn't want dock stack to be resized due to an automatic trigger |
| 527 | * like the docked stack going empty. |
| 528 | */ |
| 529 | private boolean mAllowDockedStackResize = true; |
| 530 | |
Jorim Jaggi | 0b46f3c | 2016-03-14 12:21:37 +0100 | [diff] [blame] | 531 | /** |
Tony Mak | 853304c | 2016-04-18 15:17:41 +0100 | [diff] [blame] | 532 | * Is dock currently minimized. |
| 533 | */ |
| 534 | boolean mIsDockMinimized; |
| 535 | |
Bryce Lee | 2a3cc46 | 2017-10-27 10:57:35 -0700 | [diff] [blame] | 536 | private KeyguardController mKeyguardController; |
Jorim Jaggi | fe76234 | 2016-10-13 14:33:27 +0200 | [diff] [blame] | 537 | |
chaviw | 59b9885 | 2017-06-13 12:05:44 -0700 | [diff] [blame] | 538 | private PowerManager mPowerManager; |
| 539 | private int mDeferResumeCount; |
| 540 | |
Bryce Lee | 2a3cc46 | 2017-10-27 10:57:35 -0700 | [diff] [blame] | 541 | private boolean mInitialized; |
| 542 | |
Tony Mak | 853304c | 2016-04-18 15:17:41 +0100 | [diff] [blame] | 543 | /** |
Craig Mautner | ee36c77 | 2014-07-16 14:56:05 -0700 | [diff] [blame] | 544 | * Description of a request to start a new activity, which has been held |
| 545 | * due to app switches being disabled. |
| 546 | */ |
| 547 | static class PendingActivityLaunch { |
| 548 | final ActivityRecord r; |
| 549 | final ActivityRecord sourceRecord; |
| 550 | final int startFlags; |
| 551 | final ActivityStack stack; |
Robert Carr | 13997f5 | 2015-10-23 13:13:39 -0700 | [diff] [blame] | 552 | final ProcessRecord callerApp; |
Craig Mautner | ee36c77 | 2014-07-16 14:56:05 -0700 | [diff] [blame] | 553 | |
| 554 | PendingActivityLaunch(ActivityRecord _r, ActivityRecord _sourceRecord, |
Robert Carr | 13997f5 | 2015-10-23 13:13:39 -0700 | [diff] [blame] | 555 | int _startFlags, ActivityStack _stack, ProcessRecord _callerApp) { |
Craig Mautner | ee36c77 | 2014-07-16 14:56:05 -0700 | [diff] [blame] | 556 | r = _r; |
| 557 | sourceRecord = _sourceRecord; |
| 558 | startFlags = _startFlags; |
| 559 | stack = _stack; |
Robert Carr | 13997f5 | 2015-10-23 13:13:39 -0700 | [diff] [blame] | 560 | callerApp = _callerApp; |
| 561 | } |
| 562 | |
| 563 | void sendErrorResult(String message) { |
| 564 | try { |
| 565 | if (callerApp.thread != null) { |
| 566 | callerApp.thread.scheduleCrash(message); |
| 567 | } |
| 568 | } catch (RemoteException e) { |
| 569 | Slog.e(TAG, "Exception scheduling crash of failed " |
| 570 | + "activity launcher sourceRecord=" + sourceRecord, e); |
| 571 | } |
Craig Mautner | ee36c77 | 2014-07-16 14:56:05 -0700 | [diff] [blame] | 572 | } |
| 573 | } |
| 574 | |
Bryce Lee | af691c0 | 2017-03-20 14:20:22 -0700 | [diff] [blame] | 575 | public ActivityStackSupervisor(ActivityManagerService service, Looper looper) { |
Craig Mautner | 2708430 | 2013-03-25 08:05:25 -0700 | [diff] [blame] | 576 | mService = service; |
Bryce Lee | af691c0 | 2017-03-20 14:20:22 -0700 | [diff] [blame] | 577 | mHandler = new ActivityStackSupervisorHandler(looper); |
Bryce Lee | 2a3cc46 | 2017-10-27 10:57:35 -0700 | [diff] [blame] | 578 | } |
| 579 | |
| 580 | public void initialize() { |
| 581 | if (mInitialized) { |
| 582 | return; |
| 583 | } |
| 584 | |
| 585 | mInitialized = true; |
Winson Chung | 3f0e59a | 2017-10-25 10:19:05 -0700 | [diff] [blame] | 586 | mRunningTasks = createRunningTasks(); |
Bryce Lee | 2a3cc46 | 2017-10-27 10:57:35 -0700 | [diff] [blame] | 587 | mActivityMetricsLogger = new ActivityMetricsLogger(this, mService.mContext, |
| 588 | mHandler.getLooper()); |
| 589 | mKeyguardController = new KeyguardController(mService, this); |
Bryce Lee | dacefc4 | 2017-10-10 12:56:02 -0700 | [diff] [blame] | 590 | |
| 591 | mLaunchingBoundsController = new LaunchingBoundsController(); |
| 592 | mLaunchingBoundsController.registerDefaultPositioners(this); |
Jeff Brown | 2c43c33 | 2014-06-12 22:38:59 -0700 | [diff] [blame] | 593 | } |
| 594 | |
Bryce Lee | 2a3cc46 | 2017-10-27 10:57:35 -0700 | [diff] [blame] | 595 | |
| 596 | public ActivityMetricsLogger getActivityMetricsLogger() { |
| 597 | return mActivityMetricsLogger; |
| 598 | } |
| 599 | |
| 600 | public KeyguardController getKeyguardController() { |
| 601 | return mKeyguardController; |
| 602 | } |
| 603 | |
Suprabh Shukla | 09a88f5 | 2015-12-02 14:36:31 -0800 | [diff] [blame] | 604 | void setRecentTasks(RecentTasks recentTasks) { |
| 605 | mRecentTasks = recentTasks; |
Winson Chung | 1dbc811 | 2017-09-28 18:05:31 -0700 | [diff] [blame] | 606 | mRecentTasks.registerCallback(this); |
Suprabh Shukla | 09a88f5 | 2015-12-02 14:36:31 -0800 | [diff] [blame] | 607 | } |
| 608 | |
Winson Chung | 3f0e59a | 2017-10-25 10:19:05 -0700 | [diff] [blame] | 609 | @VisibleForTesting |
| 610 | RunningTasks createRunningTasks() { |
| 611 | return new RunningTasks(); |
| 612 | } |
| 613 | |
Jeff Brown | 2c43c33 | 2014-06-12 22:38:59 -0700 | [diff] [blame] | 614 | /** |
| 615 | * At the time when the constructor runs, the power manager has not yet been |
| 616 | * initialized. So we initialize our wakelocks afterwards. |
| 617 | */ |
| 618 | void initPowerManagement() { |
chaviw | 59b9885 | 2017-06-13 12:05:44 -0700 | [diff] [blame] | 619 | mPowerManager = (PowerManager)mService.mContext.getSystemService(Context.POWER_SERVICE); |
| 620 | mGoingToSleep = mPowerManager |
| 621 | .newWakeLock(PARTIAL_WAKE_LOCK, "ActivityManager-Sleep"); |
| 622 | mLaunchingActivity = mPowerManager.newWakeLock(PARTIAL_WAKE_LOCK, "*launch*"); |
Craig Mautner | 7ea5bd4 | 2013-07-05 15:27:08 -0700 | [diff] [blame] | 623 | mLaunchingActivity.setReferenceCounted(false); |
Craig Mautner | 2219a1b | 2013-03-25 09:44:30 -0700 | [diff] [blame] | 624 | } |
| 625 | |
Craig Mautner | ce5f3cb | 2013-04-22 08:58:54 -0700 | [diff] [blame] | 626 | void setWindowManager(WindowManagerService wm) { |
Craig Mautner | 4a1cb22 | 2013-12-04 16:14:06 -0800 | [diff] [blame] | 627 | synchronized (mService) { |
| 628 | mWindowManager = wm; |
Jorim Jaggi | fe76234 | 2016-10-13 14:33:27 +0200 | [diff] [blame] | 629 | mKeyguardController.setWindowManager(wm); |
Craig Mautner | 4a1cb22 | 2013-12-04 16:14:06 -0800 | [diff] [blame] | 630 | |
| 631 | mDisplayManager = |
| 632 | (DisplayManager)mService.mContext.getSystemService(Context.DISPLAY_SERVICE); |
| 633 | mDisplayManager.registerDisplayListener(this, null); |
Andrii Kulian | fb1bf69 | 2017-01-17 11:17:34 -0800 | [diff] [blame] | 634 | mDisplayManagerInternal = LocalServices.getService(DisplayManagerInternal.class); |
Craig Mautner | 4a1cb22 | 2013-12-04 16:14:06 -0800 | [diff] [blame] | 635 | |
| 636 | Display[] displays = mDisplayManager.getDisplays(); |
| 637 | for (int displayNdx = displays.length - 1; displayNdx >= 0; --displayNdx) { |
| 638 | final int displayId = displays[displayNdx].getDisplayId(); |
Wale Ogunwale | 9dcf946 | 2017-09-19 15:13:01 -0700 | [diff] [blame] | 639 | ActivityDisplay activityDisplay = new ActivityDisplay(this, displayId); |
Craig Mautner | e0a3884 | 2013-12-16 16:14:02 -0800 | [diff] [blame] | 640 | mActivityDisplays.put(displayId, activityDisplay); |
Filip Gruszczynski | 7be9a8c | 2015-10-15 18:20:30 -0700 | [diff] [blame] | 641 | calculateDefaultMinimalSizeOfResizeableTasks(activityDisplay); |
Craig Mautner | 4a1cb22 | 2013-12-04 16:14:06 -0800 | [diff] [blame] | 642 | } |
| 643 | |
Wale Ogunwale | 04a05ac | 2017-09-17 21:35:02 -0700 | [diff] [blame] | 644 | mHomeStack = mFocusedStack = mLastFocusedStack = getDefaultDisplay().getOrCreateStack( |
| 645 | WINDOWING_MODE_FULLSCREEN, ACTIVITY_TYPE_HOME, ON_TOP); |
Craig Mautner | 4a1cb22 | 2013-12-04 16:14:06 -0800 | [diff] [blame] | 646 | } |
Craig Mautner | 2708430 | 2013-03-25 08:05:25 -0700 | [diff] [blame] | 647 | } |
| 648 | |
Craig Mautner | ce5f3cb | 2013-04-22 08:58:54 -0700 | [diff] [blame] | 649 | ActivityStack getFocusedStack() { |
Craig Mautner | 4a1cb22 | 2013-12-04 16:14:06 -0800 | [diff] [blame] | 650 | return mFocusedStack; |
Craig Mautner | 20e7227 | 2013-04-01 13:45:53 -0700 | [diff] [blame] | 651 | } |
| 652 | |
Craig Mautner | de4ef02 | 2013-04-07 19:01:33 -0700 | [diff] [blame] | 653 | ActivityStack getLastStack() { |
Craig Mautner | 4a1cb22 | 2013-12-04 16:14:06 -0800 | [diff] [blame] | 654 | return mLastFocusedStack; |
Craig Mautner | 2219a1b | 2013-03-25 09:44:30 -0700 | [diff] [blame] | 655 | } |
| 656 | |
Wale Ogunwale | 1e60e0c | 2015-10-28 13:36:10 -0700 | [diff] [blame] | 657 | boolean isFocusedStack(ActivityStack stack) { |
Andrii Kulian | 94e82d9b0 | 2017-07-13 15:33:06 -0700 | [diff] [blame] | 658 | return stack != null && stack == mFocusedStack; |
Craig Mautner | 20e7227 | 2013-04-01 13:45:53 -0700 | [diff] [blame] | 659 | } |
| 660 | |
Wale Ogunwale | d046a01 | 2015-12-24 13:05:59 -0800 | [diff] [blame] | 661 | /** NOTE: Should only be called from {@link ActivityStack#moveToFront} */ |
Wale Ogunwale | 4cea0f5 | 2015-12-25 06:30:31 -0800 | [diff] [blame] | 662 | void setFocusStackUnchecked(String reason, ActivityStack focusCandidate) { |
| 663 | if (!focusCandidate.isFocusable()) { |
| 664 | // The focus candidate isn't focusable. Move focus to the top stack that is focusable. |
Andrii Kulian | 7fc2281 | 2016-12-28 13:04:11 -0800 | [diff] [blame] | 665 | focusCandidate = getNextFocusableStackLocked(focusCandidate); |
Wale Ogunwale | 4cea0f5 | 2015-12-25 06:30:31 -0800 | [diff] [blame] | 666 | } |
| 667 | |
| 668 | if (focusCandidate != mFocusedStack) { |
Wale Ogunwale | d046a01 | 2015-12-24 13:05:59 -0800 | [diff] [blame] | 669 | mLastFocusedStack = mFocusedStack; |
Wale Ogunwale | 4cea0f5 | 2015-12-25 06:30:31 -0800 | [diff] [blame] | 670 | mFocusedStack = focusCandidate; |
Wale Ogunwale | cb82f30 | 2015-02-25 07:53:40 -0800 | [diff] [blame] | 671 | |
Wale Ogunwale | d046a01 | 2015-12-24 13:05:59 -0800 | [diff] [blame] | 672 | EventLogTags.writeAmFocusedStack( |
| 673 | mCurrentUser, mFocusedStack == null ? -1 : mFocusedStack.getStackId(), |
| 674 | mLastFocusedStack == null ? -1 : mLastFocusedStack.getStackId(), reason); |
| 675 | } |
| 676 | |
| 677 | final ActivityRecord r = topRunningActivityLocked(); |
Craig Mautner | f3ea23a | 2015-01-13 09:37:08 -0800 | [diff] [blame] | 678 | if (mService.mBooting || !mService.mBooted) { |
Craig Mautner | f3ea23a | 2015-01-13 09:37:08 -0800 | [diff] [blame] | 679 | if (r != null && r.idle) { |
| 680 | checkFinishBootingLocked(); |
| 681 | } |
| 682 | } |
Craig Mautner | de4ef02 | 2013-04-07 19:01:33 -0700 | [diff] [blame] | 683 | } |
| 684 | |
Wale Ogunwale | 925d0d1 | 2015-09-23 15:40:07 -0700 | [diff] [blame] | 685 | void moveHomeStackToFront(String reason) { |
| 686 | mHomeStack.moveToFront(reason); |
| 687 | } |
| 688 | |
Matthew Ng | 330757d | 2017-02-28 14:19:17 -0800 | [diff] [blame] | 689 | void moveRecentsStackToFront(String reason) { |
Wale Ogunwale | 04a05ac | 2017-09-17 21:35:02 -0700 | [diff] [blame] | 690 | final ActivityStack recentsStack = getDefaultDisplay().getStack( |
| 691 | WINDOWING_MODE_UNDEFINED, ACTIVITY_TYPE_RECENTS); |
Matthew Ng | 330757d | 2017-02-28 14:19:17 -0800 | [diff] [blame] | 692 | if (recentsStack != null) { |
| 693 | recentsStack.moveToFront(reason); |
| 694 | } |
| 695 | } |
| 696 | |
Wale Ogunwale | d80c263 | 2015-03-13 10:26:26 -0700 | [diff] [blame] | 697 | /** Returns true if the focus activity was adjusted to the home stack top activity. */ |
Matthew Ng | ae1ff4f | 2016-11-10 15:49:14 -0800 | [diff] [blame] | 698 | boolean moveHomeStackTaskToTop(String reason) { |
| 699 | mHomeStack.moveHomeStackTaskToTop(); |
Wale Ogunwale | d80c263 | 2015-03-13 10:26:26 -0700 | [diff] [blame] | 700 | |
Wale Ogunwale | 2d0f39b | 2015-04-17 15:35:39 -0700 | [diff] [blame] | 701 | final ActivityRecord top = getHomeActivity(); |
Wale Ogunwale | d80c263 | 2015-03-13 10:26:26 -0700 | [diff] [blame] | 702 | if (top == null) { |
| 703 | return false; |
| 704 | } |
Chong Zhang | 6cda19c | 2016-06-14 19:07:56 -0700 | [diff] [blame] | 705 | moveFocusableActivityStackToFrontLocked(top, reason); |
Wale Ogunwale | d80c263 | 2015-03-13 10:26:26 -0700 | [diff] [blame] | 706 | return true; |
Craig Mautner | 8e56957 | 2013-10-11 17:36:59 -0700 | [diff] [blame] | 707 | } |
| 708 | |
Matthew Ng | ae1ff4f | 2016-11-10 15:49:14 -0800 | [diff] [blame] | 709 | boolean resumeHomeStackTask(ActivityRecord prev, String reason) { |
Dianne Hackborn | 7622a0f | 2014-09-30 14:31:42 -0700 | [diff] [blame] | 710 | if (!mService.mBooting && !mService.mBooted) { |
| 711 | // Not ready yet! |
| 712 | return false; |
| 713 | } |
| 714 | |
Matthew Ng | ae1ff4f | 2016-11-10 15:49:14 -0800 | [diff] [blame] | 715 | mHomeStack.moveHomeStackTaskToTop(); |
Wale Ogunwale | 2d0f39b | 2015-04-17 15:35:39 -0700 | [diff] [blame] | 716 | ActivityRecord r = getHomeActivity(); |
Wale Ogunwale | d046a01 | 2015-12-24 13:05:59 -0800 | [diff] [blame] | 717 | final String myReason = reason + " resumeHomeStackTask"; |
| 718 | |
Mark Lu | a56ea12 | 2015-10-08 13:31:01 +0800 | [diff] [blame] | 719 | // Only resume home activity if isn't finishing. |
| 720 | if (r != null && !r.finishing) { |
Chong Zhang | 6cda19c | 2016-06-14 19:07:56 -0700 | [diff] [blame] | 721 | moveFocusableActivityStackToFrontLocked(r, myReason); |
Wale Ogunwale | d046a01 | 2015-12-24 13:05:59 -0800 | [diff] [blame] | 722 | return resumeFocusedStackTopActivityLocked(mHomeStack, prev, null); |
Craig Mautner | 69ada55 | 2013-04-18 13:51:51 -0700 | [diff] [blame] | 723 | } |
Wale Ogunwale | d046a01 | 2015-12-24 13:05:59 -0800 | [diff] [blame] | 724 | return mService.startHomeActivityLocked(mCurrentUser, myReason); |
Craig Mautner | 69ada55 | 2013-04-18 13:51:51 -0700 | [diff] [blame] | 725 | } |
| 726 | |
Craig Mautner | 8d341ef | 2013-03-26 09:03:27 -0700 | [diff] [blame] | 727 | TaskRecord anyTaskForIdLocked(int id) { |
Wale Ogunwale | 0568aed | 2017-09-08 13:29:37 -0700 | [diff] [blame] | 728 | return anyTaskForIdLocked(id, MATCH_TASK_IN_STACKS_OR_RECENT_TASKS_AND_RESTORE); |
| 729 | } |
| 730 | |
| 731 | TaskRecord anyTaskForIdLocked(int id, @AnyTaskForIdMatchTaskMode int matchMode) { |
Wale Ogunwale | ab5de37 | 2017-10-18 06:46:31 -0700 | [diff] [blame] | 732 | return anyTaskForIdLocked(id, matchMode, null, !ON_TOP); |
Wale Ogunwale | 04f4d6b | 2015-03-11 09:23:25 -0700 | [diff] [blame] | 733 | } |
| 734 | |
| 735 | /** |
Bryce Lee | 92b7b65 | 2017-04-03 08:33:11 -0700 | [diff] [blame] | 736 | * Returns a {@link TaskRecord} for the input id if available. {@code null} otherwise. |
Wale Ogunwale | 04f4d6b | 2015-03-11 09:23:25 -0700 | [diff] [blame] | 737 | * @param id Id of the task we would like returned. |
Winson Chung | 7900bee | 2017-03-10 08:59:25 -0800 | [diff] [blame] | 738 | * @param matchMode The mode to match the given task id in. |
Wale Ogunwale | 0568aed | 2017-09-08 13:29:37 -0700 | [diff] [blame] | 739 | * @param aOptions The activity options to use for restoration. Can be null. |
Wale Ogunwale | ab5de37 | 2017-10-18 06:46:31 -0700 | [diff] [blame] | 740 | * @param onTop If the stack for the task should be the topmost on the display. |
Wale Ogunwale | 04f4d6b | 2015-03-11 09:23:25 -0700 | [diff] [blame] | 741 | */ |
Wale Ogunwale | 0568aed | 2017-09-08 13:29:37 -0700 | [diff] [blame] | 742 | TaskRecord anyTaskForIdLocked(int id, @AnyTaskForIdMatchTaskMode int matchMode, |
Wale Ogunwale | ab5de37 | 2017-10-18 06:46:31 -0700 | [diff] [blame] | 743 | @Nullable ActivityOptions aOptions, boolean onTop) { |
| 744 | // If options are set, ensure that we are attempting to actually restore a task |
Wale Ogunwale | 0568aed | 2017-09-08 13:29:37 -0700 | [diff] [blame] | 745 | if (matchMode != MATCH_TASK_IN_STACKS_OR_RECENT_TASKS_AND_RESTORE && aOptions != null) { |
| 746 | throw new IllegalArgumentException("Should not specify activity options for non-restore" |
| 747 | + " lookup"); |
Winson Chung | 7900bee | 2017-03-10 08:59:25 -0800 | [diff] [blame] | 748 | } |
| 749 | |
Craig Mautner | e0a3884 | 2013-12-16 16:14:02 -0800 | [diff] [blame] | 750 | int numDisplays = mActivityDisplays.size(); |
Craig Mautner | 4a1cb22 | 2013-12-04 16:14:06 -0800 | [diff] [blame] | 751 | for (int displayNdx = 0; displayNdx < numDisplays; ++displayNdx) { |
Wale Ogunwale | a0f5b5e | 2017-10-11 09:37:23 -0700 | [diff] [blame] | 752 | final ActivityDisplay display = mActivityDisplays.valueAt(displayNdx); |
| 753 | for (int stackNdx = display.getChildCount() - 1; stackNdx >= 0; --stackNdx) { |
| 754 | final ActivityStack stack = display.getChildAt(stackNdx); |
Bryce Lee | 92b7b65 | 2017-04-03 08:33:11 -0700 | [diff] [blame] | 755 | final TaskRecord task = stack.taskForIdLocked(id); |
Wale Ogunwale | ab5de37 | 2017-10-18 06:46:31 -0700 | [diff] [blame] | 756 | if (task == null) { |
| 757 | continue; |
Craig Mautner | 4a1cb22 | 2013-12-04 16:14:06 -0800 | [diff] [blame] | 758 | } |
Wale Ogunwale | ab5de37 | 2017-10-18 06:46:31 -0700 | [diff] [blame] | 759 | if (aOptions != null) { |
| 760 | // Resolve the stack the task should be placed in now based on options |
| 761 | // and reparent if needed. |
| 762 | final ActivityStack launchStack = getLaunchStack(null, aOptions, task, onTop); |
| 763 | if (launchStack != null && stack != launchStack) { |
| 764 | final int reparentMode = onTop |
| 765 | ? REPARENT_MOVE_STACK_TO_FRONT : REPARENT_LEAVE_STACK_IN_PLACE; |
| 766 | task.reparent(launchStack, onTop, reparentMode, ANIMATE, DEFER_RESUME, |
| 767 | "anyTaskForIdLocked"); |
| 768 | } |
| 769 | } |
| 770 | return task; |
Craig Mautner | 8d341ef | 2013-03-26 09:03:27 -0700 | [diff] [blame] | 771 | } |
| 772 | } |
Wale Ogunwale | 7de0535 | 2014-12-12 15:21:33 -0800 | [diff] [blame] | 773 | |
Winson Chung | 7900bee | 2017-03-10 08:59:25 -0800 | [diff] [blame] | 774 | // If we are matching stack tasks only, return now |
| 775 | if (matchMode == MATCH_TASK_IN_STACKS_ONLY) { |
Wale Ogunwale | 7de0535 | 2014-12-12 15:21:33 -0800 | [diff] [blame] | 776 | return null; |
| 777 | } |
| 778 | |
Winson Chung | 7900bee | 2017-03-10 08:59:25 -0800 | [diff] [blame] | 779 | // Otherwise, check the recent tasks and return if we find it there and we are not restoring |
| 780 | // the task from recents |
| 781 | if (DEBUG_RECENTS) Slog.v(TAG_RECENTS, "Looking for task id=" + id + " in recents"); |
Winson Chung | 1dbc811 | 2017-09-28 18:05:31 -0700 | [diff] [blame] | 782 | final TaskRecord task = mRecentTasks.getTask(id); |
Bryce Lee | 92b7b65 | 2017-04-03 08:33:11 -0700 | [diff] [blame] | 783 | |
| 784 | if (task == null) { |
| 785 | if (DEBUG_RECENTS) { |
Winson Chung | 7900bee | 2017-03-10 08:59:25 -0800 | [diff] [blame] | 786 | Slog.d(TAG_RECENTS, "\tDidn't find task id=" + id + " in recents"); |
| 787 | } |
Bryce Lee | 92b7b65 | 2017-04-03 08:33:11 -0700 | [diff] [blame] | 788 | |
| 789 | return null; |
| 790 | } |
| 791 | |
| 792 | if (matchMode == MATCH_TASK_IN_STACKS_OR_RECENT_TASKS) { |
Wale Ogunwale | 04f4d6b | 2015-03-11 09:23:25 -0700 | [diff] [blame] | 793 | return task; |
| 794 | } |
| 795 | |
Winson Chung | 7900bee | 2017-03-10 08:59:25 -0800 | [diff] [blame] | 796 | // Implicitly, this case is MATCH_TASK_IN_STACKS_OR_RECENT_TASKS_AND_RESTORE |
Wale Ogunwale | ab5de37 | 2017-10-18 06:46:31 -0700 | [diff] [blame] | 797 | if (!restoreRecentTaskLocked(task, aOptions, onTop)) { |
Wale Ogunwale | ee006da | 2015-03-30 14:49:25 -0700 | [diff] [blame] | 798 | if (DEBUG_RECENTS) Slog.w(TAG_RECENTS, |
| 799 | "Couldn't restore task id=" + id + " found in recents"); |
Wale Ogunwale | 7de0535 | 2014-12-12 15:21:33 -0800 | [diff] [blame] | 800 | return null; |
| 801 | } |
Wale Ogunwale | ee006da | 2015-03-30 14:49:25 -0700 | [diff] [blame] | 802 | if (DEBUG_RECENTS) Slog.w(TAG_RECENTS, "Restored task id=" + id + " from in recents"); |
Wale Ogunwale | 7de0535 | 2014-12-12 15:21:33 -0800 | [diff] [blame] | 803 | return task; |
Craig Mautner | 8d341ef | 2013-03-26 09:03:27 -0700 | [diff] [blame] | 804 | } |
| 805 | |
Craig Mautner | 6170f73 | 2013-04-02 13:05:23 -0700 | [diff] [blame] | 806 | ActivityRecord isInAnyStackLocked(IBinder token) { |
Craig Mautner | e0a3884 | 2013-12-16 16:14:02 -0800 | [diff] [blame] | 807 | int numDisplays = mActivityDisplays.size(); |
Craig Mautner | 4a1cb22 | 2013-12-04 16:14:06 -0800 | [diff] [blame] | 808 | for (int displayNdx = 0; displayNdx < numDisplays; ++displayNdx) { |
Wale Ogunwale | a0f5b5e | 2017-10-11 09:37:23 -0700 | [diff] [blame] | 809 | final ActivityDisplay display = mActivityDisplays.valueAt(displayNdx); |
| 810 | for (int stackNdx = display.getChildCount() - 1; stackNdx >= 0; --stackNdx) { |
| 811 | final ActivityStack stack = display.getChildAt(stackNdx); |
| 812 | final ActivityRecord r = stack.isInStackLocked(token); |
Craig Mautner | 4a1cb22 | 2013-12-04 16:14:06 -0800 | [diff] [blame] | 813 | if (r != null) { |
| 814 | return r; |
| 815 | } |
Craig Mautner | 6170f73 | 2013-04-02 13:05:23 -0700 | [diff] [blame] | 816 | } |
| 817 | } |
| 818 | return null; |
| 819 | } |
| 820 | |
Tony Mak | 853304c | 2016-04-18 15:17:41 +0100 | [diff] [blame] | 821 | /** |
Robin Lee | 3fef1f2 | 2016-12-20 14:50:13 +0000 | [diff] [blame] | 822 | * Detects whether we should show a lock screen in front of this task for a locked user. |
| 823 | * <p> |
| 824 | * We'll do this if either of the following holds: |
| 825 | * <ul> |
| 826 | * <li>The top activity explicitly belongs to {@param userId}.</li> |
| 827 | * <li>The top activity returns a result to an activity belonging to {@param userId}.</li> |
| 828 | * </ul> |
| 829 | * |
| 830 | * @return {@code true} if the top activity looks like it belongs to {@param userId}. |
Tony Mak | 853304c | 2016-04-18 15:17:41 +0100 | [diff] [blame] | 831 | */ |
Robin Lee | 3fef1f2 | 2016-12-20 14:50:13 +0000 | [diff] [blame] | 832 | private boolean taskTopActivityIsUser(TaskRecord task, @UserIdInt int userId) { |
| 833 | // To handle the case that work app is in the task but just is not the top one. |
| 834 | final ActivityRecord activityRecord = task.getTopActivity(); |
| 835 | final ActivityRecord resultTo = (activityRecord != null ? activityRecord.resultTo : null); |
| 836 | |
| 837 | return (activityRecord != null && activityRecord.userId == userId) |
| 838 | || (resultTo != null && resultTo.userId == userId); |
| 839 | } |
| 840 | |
| 841 | /** |
| 842 | * Find all visible task stacks containing {@param userId} and intercept them with an activity |
| 843 | * to block out the contents and possibly start a credential-confirming intent. |
| 844 | * |
| 845 | * @param userId user handle for the locked managed profile. |
| 846 | */ |
| 847 | void lockAllProfileTasks(@UserIdInt int userId) { |
| 848 | mWindowManager.deferSurfaceLayout(); |
| 849 | try { |
Wale Ogunwale | a0f5b5e | 2017-10-11 09:37:23 -0700 | [diff] [blame] | 850 | for (int displayNdx = mActivityDisplays.size() - 1; displayNdx >= 0; --displayNdx) { |
| 851 | final ActivityDisplay display = mActivityDisplays.valueAt(displayNdx); |
| 852 | for (int stackNdx = display.getChildCount() - 1; stackNdx >= 0; --stackNdx) { |
| 853 | final ActivityStack stack = display.getChildAt(stackNdx); |
| 854 | final List<TaskRecord> tasks = stack.getAllTasks(); |
| 855 | for (int taskNdx = tasks.size() - 1; taskNdx >= 0; taskNdx--) { |
| 856 | final TaskRecord task = tasks.get(taskNdx); |
Robin Lee | 3fef1f2 | 2016-12-20 14:50:13 +0000 | [diff] [blame] | 857 | |
Wale Ogunwale | a0f5b5e | 2017-10-11 09:37:23 -0700 | [diff] [blame] | 858 | // Check the task for a top activity belonging to userId, or returning a |
| 859 | // result to an activity belonging to userId. Example case: a document |
| 860 | // picker for personal files, opened by a work app, should still get locked. |
| 861 | if (taskTopActivityIsUser(task, userId)) { |
| 862 | mService.mTaskChangeNotificationController.notifyTaskProfileLocked( |
| 863 | task.taskId, userId); |
| 864 | } |
Robin Lee | 3fef1f2 | 2016-12-20 14:50:13 +0000 | [diff] [blame] | 865 | } |
Tony Mak | 853304c | 2016-04-18 15:17:41 +0100 | [diff] [blame] | 866 | } |
| 867 | } |
Robin Lee | 3fef1f2 | 2016-12-20 14:50:13 +0000 | [diff] [blame] | 868 | } finally { |
| 869 | mWindowManager.continueSurfaceLayout(); |
Tony Mak | 853304c | 2016-04-18 15:17:41 +0100 | [diff] [blame] | 870 | } |
Clara Bayarri | f0649ce | 2016-01-14 12:30:42 +0000 | [diff] [blame] | 871 | } |
| 872 | |
Suprabh Shukla | 09a88f5 | 2015-12-02 14:36:31 -0800 | [diff] [blame] | 873 | void setNextTaskIdForUserLocked(int taskId, int userId) { |
| 874 | final int currentTaskId = mCurTaskIdForUser.get(userId, -1); |
| 875 | if (taskId > currentTaskId) { |
| 876 | mCurTaskIdForUser.put(userId, taskId); |
Craig Mautner | ef73ee1 | 2014-04-23 11:45:37 -0700 | [diff] [blame] | 877 | } |
| 878 | } |
| 879 | |
Chong Zhang | d9d35bd | 2016-08-04 17:55:21 -0700 | [diff] [blame] | 880 | static int nextTaskIdForUser(int taskId, int userId) { |
| 881 | int nextTaskId = taskId + 1; |
| 882 | if (nextTaskId == (userId + 1) * MAX_TASK_IDS_PER_USER) { |
| 883 | // Wrap around as there will be smaller task ids that are available now. |
| 884 | nextTaskId -= MAX_TASK_IDS_PER_USER; |
| 885 | } |
| 886 | return nextTaskId; |
| 887 | } |
| 888 | |
Suprabh Shukla | 09a88f5 | 2015-12-02 14:36:31 -0800 | [diff] [blame] | 889 | int getNextTaskIdForUserLocked(int userId) { |
Suprabh Shukla | 09a88f5 | 2015-12-02 14:36:31 -0800 | [diff] [blame] | 890 | final int currentTaskId = mCurTaskIdForUser.get(userId, userId * MAX_TASK_IDS_PER_USER); |
| 891 | // for a userId u, a taskId can only be in the range |
| 892 | // [u*MAX_TASK_IDS_PER_USER, (u+1)*MAX_TASK_IDS_PER_USER-1], so if MAX_TASK_IDS_PER_USER |
| 893 | // 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] | 894 | int candidateTaskId = nextTaskIdForUser(currentTaskId, userId); |
Winson Chung | 1dbc811 | 2017-09-28 18:05:31 -0700 | [diff] [blame] | 895 | while (mRecentTasks.containsTaskId(candidateTaskId, userId) |
Wale Ogunwale | 0568aed | 2017-09-08 13:29:37 -0700 | [diff] [blame] | 896 | || anyTaskForIdLocked( |
| 897 | candidateTaskId, MATCH_TASK_IN_STACKS_OR_RECENT_TASKS) != null) { |
Chong Zhang | d9d35bd | 2016-08-04 17:55:21 -0700 | [diff] [blame] | 898 | candidateTaskId = nextTaskIdForUser(candidateTaskId, userId); |
Suprabh Shukla | 09a88f5 | 2015-12-02 14:36:31 -0800 | [diff] [blame] | 899 | if (candidateTaskId == currentTaskId) { |
| 900 | // Something wrong! |
| 901 | // All MAX_TASK_IDS_PER_USER task ids are taken up by running tasks for this user |
| 902 | throw new IllegalStateException("Cannot get an available task id." |
| 903 | + " Reached limit of " + MAX_TASK_IDS_PER_USER |
| 904 | + " running tasks per user."); |
| 905 | } |
| 906 | } |
| 907 | mCurTaskIdForUser.put(userId, candidateTaskId); |
| 908 | return candidateTaskId; |
Craig Mautner | 8d341ef | 2013-03-26 09:03:27 -0700 | [diff] [blame] | 909 | } |
| 910 | |
Chong Zhang | 6cda19c | 2016-06-14 19:07:56 -0700 | [diff] [blame] | 911 | ActivityRecord getResumedActivityLocked() { |
Wale Ogunwale | d697cea | 2015-02-20 17:19:49 -0800 | [diff] [blame] | 912 | ActivityStack stack = mFocusedStack; |
Craig Mautner | ce5f3cb | 2013-04-22 08:58:54 -0700 | [diff] [blame] | 913 | if (stack == null) { |
| 914 | return null; |
| 915 | } |
Craig Mautner | de4ef02 | 2013-04-07 19:01:33 -0700 | [diff] [blame] | 916 | ActivityRecord resumedActivity = stack.mResumedActivity; |
| 917 | if (resumedActivity == null || resumedActivity.app == null) { |
| 918 | resumedActivity = stack.mPausingActivity; |
| 919 | if (resumedActivity == null || resumedActivity.app == null) { |
Filip Gruszczynski | 3e85ba2 | 2015-10-05 22:48:30 -0700 | [diff] [blame] | 920 | resumedActivity = stack.topRunningActivityLocked(); |
Craig Mautner | de4ef02 | 2013-04-07 19:01:33 -0700 | [diff] [blame] | 921 | } |
| 922 | } |
| 923 | return resumedActivity; |
| 924 | } |
| 925 | |
Dianne Hackborn | ff07272 | 2014-09-24 10:56:28 -0700 | [diff] [blame] | 926 | boolean attachApplicationLocked(ProcessRecord app) throws RemoteException { |
Craig Mautner | 20e7227 | 2013-04-01 13:45:53 -0700 | [diff] [blame] | 927 | final String processName = app.processName; |
Craig Mautner | 4a1cb22 | 2013-12-04 16:14:06 -0800 | [diff] [blame] | 928 | boolean didSomething = false; |
Craig Mautner | e0a3884 | 2013-12-16 16:14:02 -0800 | [diff] [blame] | 929 | for (int displayNdx = mActivityDisplays.size() - 1; displayNdx >= 0; --displayNdx) { |
Wale Ogunwale | a0f5b5e | 2017-10-11 09:37:23 -0700 | [diff] [blame] | 930 | final ActivityDisplay display = mActivityDisplays.valueAt(displayNdx); |
| 931 | for (int stackNdx = display.getChildCount() - 1; stackNdx >= 0; --stackNdx) { |
| 932 | final ActivityStack stack = display.getChildAt(stackNdx); |
Wale Ogunwale | 1e60e0c | 2015-10-28 13:36:10 -0700 | [diff] [blame] | 933 | if (!isFocusedStack(stack)) { |
Craig Mautner | 4a1cb22 | 2013-12-04 16:14:06 -0800 | [diff] [blame] | 934 | continue; |
| 935 | } |
Jorim Jaggi | ea039a8 | 2017-08-02 14:37:49 +0200 | [diff] [blame] | 936 | stack.getAllRunningVisibleActivitiesLocked(mTmpActivityList); |
| 937 | final ActivityRecord top = stack.topRunningActivityLocked(); |
| 938 | final int size = mTmpActivityList.size(); |
| 939 | for (int i = 0; i < size; i++) { |
| 940 | final ActivityRecord activity = mTmpActivityList.get(i); |
| 941 | if (activity.app == null && app.uid == activity.info.applicationInfo.uid |
| 942 | && processName.equals(activity.processName)) { |
Craig Mautner | 4a1cb22 | 2013-12-04 16:14:06 -0800 | [diff] [blame] | 943 | try { |
Jorim Jaggi | ea039a8 | 2017-08-02 14:37:49 +0200 | [diff] [blame] | 944 | if (realStartActivityLocked(activity, app, |
| 945 | top == activity /* andResume */, true /* checkConfig */)) { |
Craig Mautner | 4a1cb22 | 2013-12-04 16:14:06 -0800 | [diff] [blame] | 946 | didSomething = true; |
| 947 | } |
Dianne Hackborn | ff07272 | 2014-09-24 10:56:28 -0700 | [diff] [blame] | 948 | } catch (RemoteException e) { |
Craig Mautner | 4a1cb22 | 2013-12-04 16:14:06 -0800 | [diff] [blame] | 949 | Slog.w(TAG, "Exception in new application when starting activity " |
Jorim Jaggi | ea039a8 | 2017-08-02 14:37:49 +0200 | [diff] [blame] | 950 | + top.intent.getComponent().flattenToShortString(), e); |
Craig Mautner | 4a1cb22 | 2013-12-04 16:14:06 -0800 | [diff] [blame] | 951 | throw e; |
Craig Mautner | 20e7227 | 2013-04-01 13:45:53 -0700 | [diff] [blame] | 952 | } |
Craig Mautner | 20e7227 | 2013-04-01 13:45:53 -0700 | [diff] [blame] | 953 | } |
Craig Mautner | 20e7227 | 2013-04-01 13:45:53 -0700 | [diff] [blame] | 954 | } |
| 955 | } |
| 956 | } |
Craig Mautner | b59dcfd | 2013-05-06 13:12:58 -0700 | [diff] [blame] | 957 | if (!didSomething) { |
Filip Gruszczynski | bc5a6c5 | 2015-09-22 13:13:24 -0700 | [diff] [blame] | 958 | ensureActivitiesVisibleLocked(null, 0, !PRESERVE_WINDOWS); |
Craig Mautner | b59dcfd | 2013-05-06 13:12:58 -0700 | [diff] [blame] | 959 | } |
Craig Mautner | 20e7227 | 2013-04-01 13:45:53 -0700 | [diff] [blame] | 960 | return didSomething; |
| 961 | } |
| 962 | |
| 963 | boolean allResumedActivitiesIdle() { |
Craig Mautner | e0a3884 | 2013-12-16 16:14:02 -0800 | [diff] [blame] | 964 | for (int displayNdx = mActivityDisplays.size() - 1; displayNdx >= 0; --displayNdx) { |
Wale Ogunwale | a0f5b5e | 2017-10-11 09:37:23 -0700 | [diff] [blame] | 965 | final ActivityDisplay display = mActivityDisplays.valueAt(displayNdx); |
| 966 | for (int stackNdx = display.getChildCount() - 1; stackNdx >= 0; --stackNdx) { |
| 967 | final ActivityStack stack = display.getChildAt(stackNdx); |
Wale Ogunwale | 1e60e0c | 2015-10-28 13:36:10 -0700 | [diff] [blame] | 968 | if (!isFocusedStack(stack) || stack.numActivities() == 0) { |
Craig Mautner | 4a1cb22 | 2013-12-04 16:14:06 -0800 | [diff] [blame] | 969 | continue; |
| 970 | } |
| 971 | final ActivityRecord resumedActivity = stack.mResumedActivity; |
| 972 | if (resumedActivity == null || !resumedActivity.idle) { |
Wale Ogunwale | 0fc365c | 2015-05-25 19:35:42 -0700 | [diff] [blame] | 973 | if (DEBUG_STATES) Slog.d(TAG_STATES, "allResumedActivitiesIdle: stack=" |
Craig Mautner | 34b73df | 2014-01-12 21:11:08 -0800 | [diff] [blame] | 974 | + stack.mStackId + " " + resumedActivity + " not idle"); |
Craig Mautner | 4a1cb22 | 2013-12-04 16:14:06 -0800 | [diff] [blame] | 975 | return false; |
| 976 | } |
Craig Mautner | 20e7227 | 2013-04-01 13:45:53 -0700 | [diff] [blame] | 977 | } |
| 978 | } |
Wei Wang | 65c7a15 | 2016-06-02 18:51:22 -0700 | [diff] [blame] | 979 | // Send launch end powerhint when idle |
| 980 | mService.mActivityStarter.sendPowerHintForLaunchEndIfNeeded(); |
Craig Mautner | 20e7227 | 2013-04-01 13:45:53 -0700 | [diff] [blame] | 981 | return true; |
| 982 | } |
| 983 | |
Craig Mautner | de4ef02 | 2013-04-07 19:01:33 -0700 | [diff] [blame] | 984 | boolean allResumedActivitiesComplete() { |
Craig Mautner | e0a3884 | 2013-12-16 16:14:02 -0800 | [diff] [blame] | 985 | for (int displayNdx = mActivityDisplays.size() - 1; displayNdx >= 0; --displayNdx) { |
Wale Ogunwale | a0f5b5e | 2017-10-11 09:37:23 -0700 | [diff] [blame] | 986 | final ActivityDisplay display = mActivityDisplays.valueAt(displayNdx); |
| 987 | for (int stackNdx = display.getChildCount() - 1; stackNdx >= 0; --stackNdx) { |
| 988 | final ActivityStack stack = display.getChildAt(stackNdx); |
Wale Ogunwale | 1e60e0c | 2015-10-28 13:36:10 -0700 | [diff] [blame] | 989 | if (isFocusedStack(stack)) { |
Craig Mautner | 4a1cb22 | 2013-12-04 16:14:06 -0800 | [diff] [blame] | 990 | final ActivityRecord r = stack.mResumedActivity; |
Wale Ogunwale | ee006da | 2015-03-30 14:49:25 -0700 | [diff] [blame] | 991 | if (r != null && r.state != RESUMED) { |
Craig Mautner | 4a1cb22 | 2013-12-04 16:14:06 -0800 | [diff] [blame] | 992 | return false; |
| 993 | } |
Craig Mautner | de4ef02 | 2013-04-07 19:01:33 -0700 | [diff] [blame] | 994 | } |
| 995 | } |
| 996 | } |
| 997 | // TODO: Not sure if this should check if all Paused are complete too. |
Wale Ogunwale | ee006da | 2015-03-30 14:49:25 -0700 | [diff] [blame] | 998 | if (DEBUG_STACK) Slog.d(TAG_STACK, |
Craig Mautner | 4a1cb22 | 2013-12-04 16:14:06 -0800 | [diff] [blame] | 999 | "allResumedActivitiesComplete: mLastFocusedStack changing from=" + |
| 1000 | mLastFocusedStack + " to=" + mFocusedStack); |
| 1001 | mLastFocusedStack = mFocusedStack; |
Craig Mautner | de4ef02 | 2013-04-07 19:01:33 -0700 | [diff] [blame] | 1002 | return true; |
| 1003 | } |
| 1004 | |
Wale Ogunwale | a0f5b5e | 2017-10-11 09:37:23 -0700 | [diff] [blame] | 1005 | private boolean allResumedActivitiesVisible() { |
riddle_hsu | db46d6b | 2015-04-01 18:58:07 +0800 | [diff] [blame] | 1006 | boolean foundResumed = false; |
Craig Mautner | e0a3884 | 2013-12-16 16:14:02 -0800 | [diff] [blame] | 1007 | for (int displayNdx = mActivityDisplays.size() - 1; displayNdx >= 0; --displayNdx) { |
Wale Ogunwale | a0f5b5e | 2017-10-11 09:37:23 -0700 | [diff] [blame] | 1008 | final ActivityDisplay display = mActivityDisplays.valueAt(displayNdx); |
| 1009 | for (int stackNdx = display.getChildCount() - 1; stackNdx >= 0; --stackNdx) { |
| 1010 | final ActivityStack stack = display.getChildAt(stackNdx); |
Craig Mautner | 4a1cb22 | 2013-12-04 16:14:06 -0800 | [diff] [blame] | 1011 | final ActivityRecord r = stack.mResumedActivity; |
riddle_hsu | db46d6b | 2015-04-01 18:58:07 +0800 | [diff] [blame] | 1012 | if (r != null) { |
Bryce Lee | 4a19438 | 2017-04-04 14:32:48 -0700 | [diff] [blame] | 1013 | if (!r.nowVisible || mActivitiesWaitingForVisibleActivity.contains(r)) { |
riddle_hsu | db46d6b | 2015-04-01 18:58:07 +0800 | [diff] [blame] | 1014 | return false; |
| 1015 | } |
| 1016 | foundResumed = true; |
Craig Mautner | 4a1cb22 | 2013-12-04 16:14:06 -0800 | [diff] [blame] | 1017 | } |
Craig Mautner | de4ef02 | 2013-04-07 19:01:33 -0700 | [diff] [blame] | 1018 | } |
| 1019 | } |
riddle_hsu | db46d6b | 2015-04-01 18:58:07 +0800 | [diff] [blame] | 1020 | return foundResumed; |
Craig Mautner | de4ef02 | 2013-04-07 19:01:33 -0700 | [diff] [blame] | 1021 | } |
| 1022 | |
Craig Mautner | 2acc389 | 2013-09-23 10:28:14 -0700 | [diff] [blame] | 1023 | /** |
| 1024 | * Pause all activities in either all of the stacks or just the back stacks. |
| 1025 | * @param userLeaving Passed to pauseActivity() to indicate whether to call onUserLeaving(). |
Wale Ogunwale | 950faff | 2016-08-08 09:51:04 -0700 | [diff] [blame] | 1026 | * @param resuming The resuming activity. |
| 1027 | * @param dontWait The resuming activity isn't going to wait for all activities to be paused |
| 1028 | * before resuming. |
Craig Mautner | 2acc389 | 2013-09-23 10:28:14 -0700 | [diff] [blame] | 1029 | * @return true if any activity was paused as a result of this call. |
| 1030 | */ |
Wale Ogunwale | 950faff | 2016-08-08 09:51:04 -0700 | [diff] [blame] | 1031 | boolean pauseBackStacks(boolean userLeaving, ActivityRecord resuming, boolean dontWait) { |
Craig Mautner | cf910b0 | 2013-04-23 11:23:27 -0700 | [diff] [blame] | 1032 | boolean someActivityPaused = false; |
Craig Mautner | e0a3884 | 2013-12-16 16:14:02 -0800 | [diff] [blame] | 1033 | for (int displayNdx = mActivityDisplays.size() - 1; displayNdx >= 0; --displayNdx) { |
Wale Ogunwale | a0f5b5e | 2017-10-11 09:37:23 -0700 | [diff] [blame] | 1034 | final ActivityDisplay display = mActivityDisplays.valueAt(displayNdx); |
| 1035 | for (int stackNdx = display.getChildCount() - 1; stackNdx >= 0; --stackNdx) { |
| 1036 | final ActivityStack stack = display.getChildAt(stackNdx); |
Wale Ogunwale | 1e60e0c | 2015-10-28 13:36:10 -0700 | [diff] [blame] | 1037 | if (!isFocusedStack(stack) && stack.mResumedActivity != null) { |
Wale Ogunwale | 0fc365c | 2015-05-25 19:35:42 -0700 | [diff] [blame] | 1038 | if (DEBUG_STATES) Slog.d(TAG_STATES, "pauseBackStacks: stack=" + stack + |
Craig Mautner | 4a1cb22 | 2013-12-04 16:14:06 -0800 | [diff] [blame] | 1039 | " mResumedActivity=" + stack.mResumedActivity); |
Dianne Hackborn | a4e102e | 2014-09-04 22:52:27 -0700 | [diff] [blame] | 1040 | someActivityPaused |= stack.startPausingLocked(userLeaving, false, resuming, |
| 1041 | dontWait); |
Craig Mautner | 4a1cb22 | 2013-12-04 16:14:06 -0800 | [diff] [blame] | 1042 | } |
Craig Mautner | cf910b0 | 2013-04-23 11:23:27 -0700 | [diff] [blame] | 1043 | } |
| 1044 | } |
| 1045 | return someActivityPaused; |
| 1046 | } |
| 1047 | |
Craig Mautner | de4ef02 | 2013-04-07 19:01:33 -0700 | [diff] [blame] | 1048 | boolean allPausedActivitiesComplete() { |
Craig Mautner | ac6f843 | 2013-07-17 13:24:59 -0700 | [diff] [blame] | 1049 | boolean pausing = true; |
Craig Mautner | e0a3884 | 2013-12-16 16:14:02 -0800 | [diff] [blame] | 1050 | for (int displayNdx = mActivityDisplays.size() - 1; displayNdx >= 0; --displayNdx) { |
Wale Ogunwale | a0f5b5e | 2017-10-11 09:37:23 -0700 | [diff] [blame] | 1051 | final ActivityDisplay display = mActivityDisplays.valueAt(displayNdx); |
| 1052 | for (int stackNdx = display.getChildCount() - 1; stackNdx >= 0; --stackNdx) { |
| 1053 | final ActivityStack stack = display.getChildAt(stackNdx); |
Craig Mautner | 4a1cb22 | 2013-12-04 16:14:06 -0800 | [diff] [blame] | 1054 | final ActivityRecord r = stack.mPausingActivity; |
Wale Ogunwale | ee006da | 2015-03-30 14:49:25 -0700 | [diff] [blame] | 1055 | if (r != null && r.state != PAUSED && r.state != STOPPED && r.state != STOPPING) { |
Craig Mautner | 4a1cb22 | 2013-12-04 16:14:06 -0800 | [diff] [blame] | 1056 | if (DEBUG_STATES) { |
Wale Ogunwale | 0fc365c | 2015-05-25 19:35:42 -0700 | [diff] [blame] | 1057 | Slog.d(TAG_STATES, |
| 1058 | "allPausedActivitiesComplete: r=" + r + " state=" + r.state); |
Craig Mautner | 4a1cb22 | 2013-12-04 16:14:06 -0800 | [diff] [blame] | 1059 | pausing = false; |
| 1060 | } else { |
| 1061 | return false; |
| 1062 | } |
Craig Mautner | ac6f843 | 2013-07-17 13:24:59 -0700 | [diff] [blame] | 1063 | } |
Craig Mautner | de4ef02 | 2013-04-07 19:01:33 -0700 | [diff] [blame] | 1064 | } |
| 1065 | } |
Craig Mautner | ac6f843 | 2013-07-17 13:24:59 -0700 | [diff] [blame] | 1066 | return pausing; |
Craig Mautner | de4ef02 | 2013-04-07 19:01:33 -0700 | [diff] [blame] | 1067 | } |
| 1068 | |
Wale Ogunwale | 2be760d | 2016-02-17 11:16:10 -0800 | [diff] [blame] | 1069 | void cancelInitializingActivities() { |
| 1070 | for (int displayNdx = mActivityDisplays.size() - 1; displayNdx >= 0; --displayNdx) { |
Wale Ogunwale | a0f5b5e | 2017-10-11 09:37:23 -0700 | [diff] [blame] | 1071 | final ActivityDisplay display = mActivityDisplays.valueAt(displayNdx); |
| 1072 | for (int stackNdx = display.getChildCount() - 1; stackNdx >= 0; --stackNdx) { |
| 1073 | final ActivityStack stack = display.getChildAt(stackNdx); |
| 1074 | stack.cancelInitializingActivities(); |
Wale Ogunwale | 2be760d | 2016-02-17 11:16:10 -0800 | [diff] [blame] | 1075 | } |
| 1076 | } |
| 1077 | } |
| 1078 | |
Bryce Lee | 4a19438 | 2017-04-04 14:32:48 -0700 | [diff] [blame] | 1079 | void waitActivityVisible(ComponentName name, WaitResult result) { |
| 1080 | final WaitInfo waitInfo = new WaitInfo(name, result); |
| 1081 | mWaitingForActivityVisible.add(waitInfo); |
| 1082 | } |
| 1083 | |
| 1084 | void cleanupActivity(ActivityRecord r) { |
| 1085 | // Make sure this record is no longer in the pending finishes list. |
| 1086 | // This could happen, for example, if we are trimming activities |
| 1087 | // down to the max limit while they are still waiting to finish. |
| 1088 | mFinishingActivities.remove(r); |
| 1089 | mActivitiesWaitingForVisibleActivity.remove(r); |
| 1090 | |
| 1091 | for (int i = mWaitingForActivityVisible.size() - 1; i >= 0; --i) { |
Wale Ogunwale | 3270f17 | 2017-04-26 07:29:42 -0700 | [diff] [blame] | 1092 | if (mWaitingForActivityVisible.get(i).matches(r.realActivity)) { |
Bryce Lee | 4a19438 | 2017-04-04 14:32:48 -0700 | [diff] [blame] | 1093 | mWaitingForActivityVisible.remove(i); |
| 1094 | } |
| 1095 | } |
| 1096 | } |
| 1097 | |
Craig Mautner | ce5f3cb | 2013-04-22 08:58:54 -0700 | [diff] [blame] | 1098 | void reportActivityVisibleLocked(ActivityRecord r) { |
Dianne Hackborn | 6cfbb71 | 2014-09-17 12:47:35 -0700 | [diff] [blame] | 1099 | sendWaitingVisibleReportLocked(r); |
Dianne Hackborn | 6cfbb71 | 2014-09-17 12:47:35 -0700 | [diff] [blame] | 1100 | } |
| 1101 | |
| 1102 | void sendWaitingVisibleReportLocked(ActivityRecord r) { |
| 1103 | boolean changed = false; |
Bryce Lee | 4a19438 | 2017-04-04 14:32:48 -0700 | [diff] [blame] | 1104 | for (int i = mWaitingForActivityVisible.size() - 1; i >= 0; --i) { |
| 1105 | final WaitInfo w = mWaitingForActivityVisible.get(i); |
Wale Ogunwale | 3270f17 | 2017-04-26 07:29:42 -0700 | [diff] [blame] | 1106 | if (w.matches(r.realActivity)) { |
Bryce Lee | 4a19438 | 2017-04-04 14:32:48 -0700 | [diff] [blame] | 1107 | final WaitResult result = w.getResult(); |
Dianne Hackborn | 6cfbb71 | 2014-09-17 12:47:35 -0700 | [diff] [blame] | 1108 | changed = true; |
Bryce Lee | 4a19438 | 2017-04-04 14:32:48 -0700 | [diff] [blame] | 1109 | result.timeout = false; |
| 1110 | result.who = w.getComponent(); |
| 1111 | result.totalTime = SystemClock.uptimeMillis() - result.thisTime; |
| 1112 | result.thisTime = result.totalTime; |
| 1113 | mWaitingForActivityVisible.remove(w); |
Craig Mautner | ce5f3cb | 2013-04-22 08:58:54 -0700 | [diff] [blame] | 1114 | } |
Craig Mautner | ce5f3cb | 2013-04-22 08:58:54 -0700 | [diff] [blame] | 1115 | } |
Dianne Hackborn | 6cfbb71 | 2014-09-17 12:47:35 -0700 | [diff] [blame] | 1116 | if (changed) { |
| 1117 | mService.notifyAll(); |
| 1118 | } |
Craig Mautner | ce5f3cb | 2013-04-22 08:58:54 -0700 | [diff] [blame] | 1119 | } |
| 1120 | |
Chong Zhang | 5022da3 | 2016-06-21 16:31:37 -0700 | [diff] [blame] | 1121 | void reportTaskToFrontNoLaunch(ActivityRecord r) { |
| 1122 | boolean changed = false; |
| 1123 | for (int i = mWaitingActivityLaunched.size() - 1; i >= 0; i--) { |
| 1124 | WaitResult w = mWaitingActivityLaunched.remove(i); |
| 1125 | if (w.who == null) { |
| 1126 | changed = true; |
| 1127 | // Set result to START_TASK_TO_FRONT so that startActivityMayWait() knows that |
| 1128 | // the starting activity ends up moving another activity to front, and it should |
| 1129 | // wait for this new activity to become visible instead. |
| 1130 | // Do not modify other fields. |
| 1131 | w.result = START_TASK_TO_FRONT; |
| 1132 | } |
| 1133 | } |
| 1134 | if (changed) { |
| 1135 | mService.notifyAll(); |
| 1136 | } |
| 1137 | } |
| 1138 | |
Craig Mautner | ce5f3cb | 2013-04-22 08:58:54 -0700 | [diff] [blame] | 1139 | void reportActivityLaunchedLocked(boolean timeout, ActivityRecord r, |
| 1140 | long thisTime, long totalTime) { |
Dianne Hackborn | 6cfbb71 | 2014-09-17 12:47:35 -0700 | [diff] [blame] | 1141 | boolean changed = false; |
Craig Mautner | ce5f3cb | 2013-04-22 08:58:54 -0700 | [diff] [blame] | 1142 | for (int i = mWaitingActivityLaunched.size() - 1; i >= 0; i--) { |
Craig Mautner | c64f73e | 2013-04-24 16:44:56 -0700 | [diff] [blame] | 1143 | WaitResult w = mWaitingActivityLaunched.remove(i); |
Dianne Hackborn | 6cfbb71 | 2014-09-17 12:47:35 -0700 | [diff] [blame] | 1144 | if (w.who == null) { |
| 1145 | changed = true; |
| 1146 | w.timeout = timeout; |
| 1147 | if (r != null) { |
| 1148 | w.who = new ComponentName(r.info.packageName, r.info.name); |
| 1149 | } |
| 1150 | w.thisTime = thisTime; |
| 1151 | w.totalTime = totalTime; |
Chong Zhang | 5022da3 | 2016-06-21 16:31:37 -0700 | [diff] [blame] | 1152 | // Do not modify w.result. |
Craig Mautner | ce5f3cb | 2013-04-22 08:58:54 -0700 | [diff] [blame] | 1153 | } |
Craig Mautner | ce5f3cb | 2013-04-22 08:58:54 -0700 | [diff] [blame] | 1154 | } |
Dianne Hackborn | 6cfbb71 | 2014-09-17 12:47:35 -0700 | [diff] [blame] | 1155 | if (changed) { |
| 1156 | mService.notifyAll(); |
| 1157 | } |
Craig Mautner | ce5f3cb | 2013-04-22 08:58:54 -0700 | [diff] [blame] | 1158 | } |
| 1159 | |
Craig Mautner | 29219d9 | 2013-04-16 20:19:12 -0700 | [diff] [blame] | 1160 | ActivityRecord topRunningActivityLocked() { |
Wale Ogunwale | d697cea | 2015-02-20 17:19:49 -0800 | [diff] [blame] | 1161 | final ActivityStack focusedStack = mFocusedStack; |
Filip Gruszczynski | 3e85ba2 | 2015-10-05 22:48:30 -0700 | [diff] [blame] | 1162 | ActivityRecord r = focusedStack.topRunningActivityLocked(); |
Craig Mautner | 1602ec2 | 2013-05-12 10:24:27 -0700 | [diff] [blame] | 1163 | if (r != null) { |
| 1164 | return r; |
Craig Mautner | 29219d9 | 2013-04-16 20:19:12 -0700 | [diff] [blame] | 1165 | } |
Craig Mautner | 1602ec2 | 2013-05-12 10:24:27 -0700 | [diff] [blame] | 1166 | |
Andrii Kulian | 7318d63 | 2016-07-20 18:59:28 -0700 | [diff] [blame] | 1167 | // Look in other non-focused and non-home stacks. |
Andrii Kulian | 7d95df4 | 2017-02-15 10:11:48 -0800 | [diff] [blame] | 1168 | mWindowManager.getDisplaysInFocusOrder(mTmpOrderedDisplayIds); |
| 1169 | |
| 1170 | for (int i = mTmpOrderedDisplayIds.size() - 1; i >= 0; --i) { |
| 1171 | final int displayId = mTmpOrderedDisplayIds.get(i); |
Wale Ogunwale | a0f5b5e | 2017-10-11 09:37:23 -0700 | [diff] [blame] | 1172 | final ActivityDisplay display = mActivityDisplays.get(displayId); |
| 1173 | for (int j = display.getChildCount() - 1; j >= 0; --j) { |
| 1174 | final ActivityStack stack = display.getChildAt(j); |
| 1175 | if (stack != focusedStack && stack.isTopStackOnDisplay() && stack.isFocusable()) { |
Andrii Kulian | 7d95df4 | 2017-02-15 10:11:48 -0800 | [diff] [blame] | 1176 | r = stack.topRunningActivityLocked(); |
| 1177 | if (r != null) { |
| 1178 | return r; |
| 1179 | } |
Craig Mautner | 29219d9 | 2013-04-16 20:19:12 -0700 | [diff] [blame] | 1180 | } |
| 1181 | } |
| 1182 | } |
| 1183 | return null; |
| 1184 | } |
| 1185 | |
Winson Chung | 61c9e5a | 2017-10-11 10:39:32 -0700 | [diff] [blame] | 1186 | @VisibleForTesting |
| 1187 | void getRunningTasks(int maxNum, List<RunningTaskInfo> list, |
| 1188 | @ActivityType int ignoreActivityType, @WindowingMode int ignoreWindowingMode, |
| 1189 | int callingUid, boolean allowed) { |
| 1190 | mRunningTasks.getTasks(maxNum, list, ignoreActivityType, ignoreWindowingMode, |
| 1191 | mActivityDisplays, callingUid, allowed); |
Craig Mautner | 20e7227 | 2013-04-01 13:45:53 -0700 | [diff] [blame] | 1192 | } |
| 1193 | |
Todd Kennedy | 7440f17 | 2015-12-09 14:31:22 -0800 | [diff] [blame] | 1194 | ActivityInfo resolveActivity(Intent intent, ResolveInfo rInfo, int startFlags, |
| 1195 | ProfilerInfo profilerInfo) { |
| 1196 | final ActivityInfo aInfo = rInfo != null ? rInfo.activityInfo : null; |
Craig Mautner | 23ac33b | 2013-04-01 16:26:35 -0700 | [diff] [blame] | 1197 | if (aInfo != null) { |
| 1198 | // Store the found target back into the intent, because now that |
| 1199 | // we have it we never want to do this again. For example, if the |
| 1200 | // user navigates back to this point in the history, we should |
| 1201 | // always restart the exact same activity. |
| 1202 | intent.setComponent(new ComponentName( |
| 1203 | aInfo.applicationInfo.packageName, aInfo.name)); |
| 1204 | |
| 1205 | // Don't debug things in the system process |
Man Cao | cfa78b2 | 2015-06-11 20:14:34 -0700 | [diff] [blame] | 1206 | if (!aInfo.processName.equals("system")) { |
| 1207 | if ((startFlags & ActivityManager.START_FLAG_DEBUG) != 0) { |
Chong Zhang | d25944e | 2016-06-09 16:15:27 -0700 | [diff] [blame] | 1208 | mService.setDebugApp(aInfo.processName, true, false); |
Craig Mautner | 23ac33b | 2013-04-01 16:26:35 -0700 | [diff] [blame] | 1209 | } |
Craig Mautner | 23ac33b | 2013-04-01 16:26:35 -0700 | [diff] [blame] | 1210 | |
Tamas Berghammer | df6cb28 | 2016-01-29 12:07:00 +0000 | [diff] [blame] | 1211 | if ((startFlags & ActivityManager.START_FLAG_NATIVE_DEBUGGING) != 0) { |
| 1212 | mService.setNativeDebuggingAppLocked(aInfo.applicationInfo, aInfo.processName); |
| 1213 | } |
| 1214 | |
Man Cao | cfa78b2 | 2015-06-11 20:14:34 -0700 | [diff] [blame] | 1215 | if ((startFlags & ActivityManager.START_FLAG_TRACK_ALLOCATION) != 0) { |
| 1216 | mService.setTrackAllocationApp(aInfo.applicationInfo, aInfo.processName); |
| 1217 | } |
| 1218 | |
| 1219 | if (profilerInfo != null) { |
Jeff Hao | 1b012d3 | 2014-08-20 10:35:34 -0700 | [diff] [blame] | 1220 | mService.setProfileApp(aInfo.applicationInfo, aInfo.processName, profilerInfo); |
Craig Mautner | 23ac33b | 2013-04-01 16:26:35 -0700 | [diff] [blame] | 1221 | } |
| 1222 | } |
Todd Kennedy | b3b43130 | 2017-03-20 16:05:48 -0700 | [diff] [blame] | 1223 | final String intentLaunchToken = intent.getLaunchToken(); |
| 1224 | if (aInfo.launchToken == null && intentLaunchToken != null) { |
| 1225 | aInfo.launchToken = intentLaunchToken; |
| 1226 | } |
Craig Mautner | 23ac33b | 2013-04-01 16:26:35 -0700 | [diff] [blame] | 1227 | } |
| 1228 | return aInfo; |
| 1229 | } |
| 1230 | |
Todd Kennedy | 7440f17 | 2015-12-09 14:31:22 -0800 | [diff] [blame] | 1231 | ResolveInfo resolveIntent(Intent intent, String resolvedType, int userId) { |
Kenny Guy | b1b3026 | 2016-02-09 16:02:35 +0000 | [diff] [blame] | 1232 | return resolveIntent(intent, resolvedType, userId, 0); |
| 1233 | } |
| 1234 | |
| 1235 | ResolveInfo resolveIntent(Intent intent, String resolvedType, int userId, int flags) { |
Todd Kennedy | 4d1de7d | 2017-02-23 10:32:18 -0800 | [diff] [blame] | 1236 | synchronized (mService) { |
| 1237 | return mService.getPackageManagerInternalLocked().resolveIntent(intent, resolvedType, |
Todd Kennedy | be0b889 | 2017-02-15 14:13:52 -0800 | [diff] [blame] | 1238 | PackageManager.MATCH_INSTANT | PackageManager.MATCH_DEFAULT_ONLY | flags |
Todd Kennedy | 82b0842 | 2017-09-28 13:32:05 -0700 | [diff] [blame] | 1239 | | ActivityManagerService.STOCK_PM_FLAGS, userId, true); |
Todd Kennedy | 7440f17 | 2015-12-09 14:31:22 -0800 | [diff] [blame] | 1240 | } |
Todd Kennedy | 7440f17 | 2015-12-09 14:31:22 -0800 | [diff] [blame] | 1241 | } |
| 1242 | |
| 1243 | ActivityInfo resolveActivity(Intent intent, String resolvedType, int startFlags, |
| 1244 | ProfilerInfo profilerInfo, int userId) { |
| 1245 | final ResolveInfo rInfo = resolveIntent(intent, resolvedType, userId); |
| 1246 | return resolveActivity(intent, rInfo, startFlags, profilerInfo); |
| 1247 | } |
| 1248 | |
Wale Ogunwale | 5658e4b | 2016-02-12 12:22:19 -0800 | [diff] [blame] | 1249 | final boolean realStartActivityLocked(ActivityRecord r, ProcessRecord app, |
| 1250 | boolean andResume, boolean checkConfig) throws RemoteException { |
| 1251 | |
| 1252 | if (!allPausedActivitiesComplete()) { |
| 1253 | // While there are activities pausing we skipping starting any new activities until |
| 1254 | // pauses are complete. NOTE: that we also do this for activities that are starting in |
| 1255 | // the paused state because they will first be resumed then paused on the client side. |
| 1256 | if (DEBUG_SWITCH || DEBUG_PAUSE || DEBUG_STATES) Slog.v(TAG_PAUSE, |
| 1257 | "realStartActivityLocked: Skipping start of r=" + r |
| 1258 | + " some activities pausing..."); |
| 1259 | return false; |
| 1260 | } |
Craig Mautner | 2420ead | 2013-04-01 17:13:20 -0700 | [diff] [blame] | 1261 | |
Bryce Lee | af691c0 | 2017-03-20 14:20:22 -0700 | [diff] [blame] | 1262 | final TaskRecord task = r.getTask(); |
Andrii Kulian | 02b7a83 | 2016-10-06 23:11:56 -0700 | [diff] [blame] | 1263 | final ActivityStack stack = task.getStack(); |
chaviw | 59b9885 | 2017-06-13 12:05:44 -0700 | [diff] [blame] | 1264 | |
| 1265 | beginDeferResume(); |
| 1266 | |
Craig Mautner | 2420ead | 2013-04-01 17:13:20 -0700 | [diff] [blame] | 1267 | try { |
chaviw | 59b9885 | 2017-06-13 12:05:44 -0700 | [diff] [blame] | 1268 | r.startFreezingScreenLocked(app, 0); |
| 1269 | |
| 1270 | // schedule launch ticks to collect information about slow apps. |
| 1271 | r.startLaunchTickingLocked(); |
| 1272 | |
Dianne Hackborn | 68a0633 | 2017-11-15 17:54:18 -0800 | [diff] [blame] | 1273 | r.setProcess(app); |
chaviw | 59b9885 | 2017-06-13 12:05:44 -0700 | [diff] [blame] | 1274 | |
Jorim Jaggi | 838c245 | 2017-08-28 15:44:43 +0200 | [diff] [blame] | 1275 | if (mKeyguardController.isKeyguardLocked()) { |
| 1276 | r.notifyUnknownVisibilityLaunched(); |
| 1277 | } |
| 1278 | |
chaviw | 59b9885 | 2017-06-13 12:05:44 -0700 | [diff] [blame] | 1279 | // Have the window manager re-evaluate the orientation of the screen based on the new |
| 1280 | // activity order. Note that as a result of this, it can call back into the activity |
| 1281 | // manager with a new orientation. We don't care about that, because the activity is |
| 1282 | // not currently running so we are just restarting it anyway. |
| 1283 | if (checkConfig) { |
| 1284 | final int displayId = r.getDisplayId(); |
| 1285 | final Configuration config = mWindowManager.updateOrientationFromAppTokens( |
| 1286 | getDisplayOverrideConfiguration(displayId), |
| 1287 | r.mayFreezeScreenLocked(app) ? r.appToken : null, displayId); |
| 1288 | // Deferring resume here because we're going to launch new activity shortly. |
| 1289 | // We don't want to perform a redundant launch of the same record while ensuring |
| 1290 | // configurations and trying to resume top activity of focused stack. |
| 1291 | mService.updateDisplayOverrideConfigurationLocked(config, r, true /* deferResume */, |
| 1292 | displayId); |
Craig Mautner | 2420ead | 2013-04-01 17:13:20 -0700 | [diff] [blame] | 1293 | } |
chaviw | 59b9885 | 2017-06-13 12:05:44 -0700 | [diff] [blame] | 1294 | |
| 1295 | if (r.getStack().checkKeyguardVisibility(r, true /* shouldBeVisible */, |
| 1296 | true /* isTop */)) { |
| 1297 | // We only set the visibility to true if the activity is allowed to be visible |
| 1298 | // based on |
| 1299 | // keyguard state. This avoids setting this into motion in window manager that is |
| 1300 | // later cancelled due to later calls to ensure visible activities that set |
| 1301 | // visibility back to false. |
| 1302 | r.setVisibility(true); |
Craig Mautner | 2420ead | 2013-04-01 17:13:20 -0700 | [diff] [blame] | 1303 | } |
chaviw | 59b9885 | 2017-06-13 12:05:44 -0700 | [diff] [blame] | 1304 | |
chaviw | 59b9885 | 2017-06-13 12:05:44 -0700 | [diff] [blame] | 1305 | final int applicationInfoUid = |
| 1306 | (r.info.applicationInfo != null) ? r.info.applicationInfo.uid : -1; |
| 1307 | if ((r.userId != app.userId) || (r.appInfo.uid != applicationInfoUid)) { |
| 1308 | Slog.wtf(TAG, |
| 1309 | "User ID for activity changing for " + r |
| 1310 | + " appInfo.uid=" + r.appInfo.uid |
| 1311 | + " info.ai.uid=" + applicationInfoUid |
| 1312 | + " old=" + r.app + " new=" + app); |
| 1313 | } |
| 1314 | |
| 1315 | app.waitingToKill = null; |
| 1316 | r.launchCount++; |
| 1317 | r.lastLaunchTime = SystemClock.uptimeMillis(); |
| 1318 | |
| 1319 | if (DEBUG_ALL) Slog.v(TAG, "Launching: " + r); |
| 1320 | |
| 1321 | int idx = app.activities.indexOf(r); |
| 1322 | if (idx < 0) { |
| 1323 | app.activities.add(r); |
| 1324 | } |
| 1325 | mService.updateLruProcessLocked(app, true, null); |
| 1326 | mService.updateOomAdjLocked(); |
| 1327 | |
Charles He | ff9b4dff | 2017-09-22 10:18:37 +0100 | [diff] [blame] | 1328 | if (task.mLockTaskAuth == LOCK_TASK_AUTH_LAUNCHABLE |
| 1329 | || task.mLockTaskAuth == LOCK_TASK_AUTH_LAUNCHABLE_PRIV |
| 1330 | || (task.mLockTaskAuth == LOCK_TASK_AUTH_WHITELISTED |
| 1331 | && mService.mLockTaskController.getLockTaskModeState() |
| 1332 | == LOCK_TASK_MODE_LOCKED)) { |
Benjamin Franz | a83859f | 2017-07-03 16:34:14 +0100 | [diff] [blame] | 1333 | mService.mLockTaskController.startLockTaskMode(task, false, 0 /* blank UID */); |
chaviw | 59b9885 | 2017-06-13 12:05:44 -0700 | [diff] [blame] | 1334 | } |
| 1335 | |
| 1336 | try { |
| 1337 | if (app.thread == null) { |
| 1338 | throw new RemoteException(); |
| 1339 | } |
| 1340 | List<ResultInfo> results = null; |
| 1341 | List<ReferrerIntent> newIntents = null; |
| 1342 | if (andResume) { |
| 1343 | // We don't need to deliver new intents and/or set results if activity is going |
| 1344 | // to pause immediately after launch. |
| 1345 | results = r.results; |
| 1346 | newIntents = r.newIntents; |
| 1347 | } |
| 1348 | if (DEBUG_SWITCH) Slog.v(TAG_SWITCH, |
| 1349 | "Launching: " + r + " icicle=" + r.icicle + " with results=" + results |
| 1350 | + " newIntents=" + newIntents + " andResume=" + andResume); |
| 1351 | EventLog.writeEvent(EventLogTags.AM_RESTART_ACTIVITY, r.userId, |
| 1352 | System.identityHashCode(r), task.taskId, r.shortComponentName); |
Wale Ogunwale | 6fbde9f | 2017-08-24 07:24:12 -0700 | [diff] [blame] | 1353 | if (r.isActivityTypeHome()) { |
chaviw | 59b9885 | 2017-06-13 12:05:44 -0700 | [diff] [blame] | 1354 | // Home process is the root process of the task. |
| 1355 | mService.mHomeProcess = task.mActivities.get(0).app; |
| 1356 | } |
| 1357 | mService.notifyPackageUse(r.intent.getComponent().getPackageName(), |
| 1358 | PackageManager.NOTIFY_PACKAGE_USE_ACTIVITY); |
| 1359 | r.sleeping = false; |
| 1360 | r.forceNewConfig = false; |
Alan Viverette | b6a2573 | 2017-11-21 14:49:24 -0500 | [diff] [blame] | 1361 | mService.getAppWarningsLocked().onStartActivity(r); |
chaviw | 59b9885 | 2017-06-13 12:05:44 -0700 | [diff] [blame] | 1362 | mService.showAskCompatModeDialogLocked(r); |
| 1363 | r.compat = mService.compatibilityInfoForPackageLocked(r.info.applicationInfo); |
| 1364 | ProfilerInfo profilerInfo = null; |
| 1365 | if (mService.mProfileApp != null && mService.mProfileApp.equals(app.processName)) { |
| 1366 | if (mService.mProfileProc == null || mService.mProfileProc == app) { |
| 1367 | mService.mProfileProc = app; |
Andreas Gampe | 2b073a0 | 2017-06-22 17:28:57 -0700 | [diff] [blame] | 1368 | ProfilerInfo profilerInfoSvc = mService.mProfilerInfo; |
| 1369 | if (profilerInfoSvc != null && profilerInfoSvc.profileFile != null) { |
| 1370 | if (profilerInfoSvc.profileFd != null) { |
chaviw | 59b9885 | 2017-06-13 12:05:44 -0700 | [diff] [blame] | 1371 | try { |
Andreas Gampe | 2b073a0 | 2017-06-22 17:28:57 -0700 | [diff] [blame] | 1372 | profilerInfoSvc.profileFd = profilerInfoSvc.profileFd.dup(); |
chaviw | 59b9885 | 2017-06-13 12:05:44 -0700 | [diff] [blame] | 1373 | } catch (IOException e) { |
Andreas Gampe | 2b073a0 | 2017-06-22 17:28:57 -0700 | [diff] [blame] | 1374 | profilerInfoSvc.closeFd(); |
Craig Mautner | 2568c3a | 2015-03-26 14:22:34 -0700 | [diff] [blame] | 1375 | } |
| 1376 | } |
chaviw | 59b9885 | 2017-06-13 12:05:44 -0700 | [diff] [blame] | 1377 | |
Andreas Gampe | 2b073a0 | 2017-06-22 17:28:57 -0700 | [diff] [blame] | 1378 | profilerInfo = new ProfilerInfo(profilerInfoSvc); |
Craig Mautner | 2420ead | 2013-04-01 17:13:20 -0700 | [diff] [blame] | 1379 | } |
Craig Mautner | 2420ead | 2013-04-01 17:13:20 -0700 | [diff] [blame] | 1380 | } |
| 1381 | } |
Adam Powell | cfbe9be | 2013-11-06 14:58:58 -0800 | [diff] [blame] | 1382 | |
chaviw | 59b9885 | 2017-06-13 12:05:44 -0700 | [diff] [blame] | 1383 | app.hasShownUi = true; |
| 1384 | app.pendingUiClean = true; |
| 1385 | app.forceProcessStateUpTo(mService.mTopProcessState); |
| 1386 | // Because we could be starting an Activity in the system process this may not go |
| 1387 | // across a Binder interface which would create a new Configuration. Consequently |
| 1388 | // we have to always create a new Configuration here. |
Bryce Lee | a163b76 | 2017-01-24 11:05:01 -0800 | [diff] [blame] | 1389 | |
chaviw | 59b9885 | 2017-06-13 12:05:44 -0700 | [diff] [blame] | 1390 | final MergedConfiguration mergedConfiguration = new MergedConfiguration( |
| 1391 | mService.getGlobalConfiguration(), r.getMergedOverrideConfiguration()); |
| 1392 | r.setLastReportedConfiguration(mergedConfiguration); |
Bryce Lee | a163b76 | 2017-01-24 11:05:01 -0800 | [diff] [blame] | 1393 | |
chaviw | 59b9885 | 2017-06-13 12:05:44 -0700 | [diff] [blame] | 1394 | logIfTransactionTooLarge(r.intent, r.icicle); |
| 1395 | app.thread.scheduleLaunchActivity(new Intent(r.intent), r.appToken, |
| 1396 | System.identityHashCode(r), r.info, |
| 1397 | // TODO: Have this take the merged configuration instead of separate global |
| 1398 | // and override configs. |
| 1399 | mergedConfiguration.getGlobalConfiguration(), |
| 1400 | mergedConfiguration.getOverrideConfiguration(), r.compat, |
| 1401 | r.launchedFromPackage, task.voiceInteractor, app.repProcState, r.icicle, |
| 1402 | r.persistentState, results, newIntents, !andResume, |
| 1403 | mService.isNextTransitionForward(), profilerInfo); |
Craig Mautner | 2420ead | 2013-04-01 17:13:20 -0700 | [diff] [blame] | 1404 | |
chaviw | 59b9885 | 2017-06-13 12:05:44 -0700 | [diff] [blame] | 1405 | if ((app.info.privateFlags & ApplicationInfo.PRIVATE_FLAG_CANT_SAVE_STATE) != 0) { |
| 1406 | // This may be a heavy-weight process! Note that the package |
| 1407 | // manager will ensure that only activity can run in the main |
| 1408 | // process of the .apk, which is the only thing that will be |
| 1409 | // considered heavy-weight. |
| 1410 | if (app.processName.equals(app.info.packageName)) { |
| 1411 | if (mService.mHeavyWeightProcess != null |
| 1412 | && mService.mHeavyWeightProcess != app) { |
| 1413 | Slog.w(TAG, "Starting new heavy weight process " + app |
| 1414 | + " when already running " |
| 1415 | + mService.mHeavyWeightProcess); |
| 1416 | } |
| 1417 | mService.mHeavyWeightProcess = app; |
| 1418 | Message msg = mService.mHandler.obtainMessage( |
| 1419 | ActivityManagerService.POST_HEAVY_NOTIFICATION_MSG); |
| 1420 | msg.obj = r; |
| 1421 | mService.mHandler.sendMessage(msg); |
Craig Mautner | 2420ead | 2013-04-01 17:13:20 -0700 | [diff] [blame] | 1422 | } |
Craig Mautner | 2420ead | 2013-04-01 17:13:20 -0700 | [diff] [blame] | 1423 | } |
Craig Mautner | 2420ead | 2013-04-01 17:13:20 -0700 | [diff] [blame] | 1424 | |
chaviw | 59b9885 | 2017-06-13 12:05:44 -0700 | [diff] [blame] | 1425 | } catch (RemoteException e) { |
| 1426 | if (r.launchFailed) { |
| 1427 | // This is the second time we failed -- finish activity |
| 1428 | // and give up. |
| 1429 | Slog.e(TAG, "Second failure launching " |
| 1430 | + r.intent.getComponent().flattenToShortString() |
| 1431 | + ", giving up", e); |
| 1432 | mService.appDiedLocked(app); |
| 1433 | stack.requestFinishActivityLocked(r.appToken, Activity.RESULT_CANCELED, null, |
| 1434 | "2nd-crash", false); |
| 1435 | return false; |
| 1436 | } |
Craig Mautner | 2420ead | 2013-04-01 17:13:20 -0700 | [diff] [blame] | 1437 | |
chaviw | 59b9885 | 2017-06-13 12:05:44 -0700 | [diff] [blame] | 1438 | // This is the first time we failed -- restart process and |
| 1439 | // retry. |
| 1440 | r.launchFailed = true; |
| 1441 | app.activities.remove(r); |
| 1442 | throw e; |
| 1443 | } |
| 1444 | } finally { |
| 1445 | endDeferResume(); |
Craig Mautner | 2420ead | 2013-04-01 17:13:20 -0700 | [diff] [blame] | 1446 | } |
| 1447 | |
| 1448 | r.launchFailed = false; |
| 1449 | if (stack.updateLRUListLocked(r)) { |
Filip Gruszczynski | 49b80af | 2015-09-24 09:04:26 -0700 | [diff] [blame] | 1450 | Slog.w(TAG, "Activity " + r + " being launched, but already in LRU list"); |
Craig Mautner | 2420ead | 2013-04-01 17:13:20 -0700 | [diff] [blame] | 1451 | } |
| 1452 | |
chaviw | 59b9885 | 2017-06-13 12:05:44 -0700 | [diff] [blame] | 1453 | if (andResume && readyToResume()) { |
Craig Mautner | 2420ead | 2013-04-01 17:13:20 -0700 | [diff] [blame] | 1454 | // As part of the process of launching, ActivityThread also performs |
| 1455 | // a resume. |
| 1456 | stack.minimalResumeActivityLocked(r); |
| 1457 | } else { |
Wale Ogunwale | d046a01 | 2015-12-24 13:05:59 -0800 | [diff] [blame] | 1458 | // 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] | 1459 | // 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] | 1460 | // current icicle and other state. |
Wale Ogunwale | 0fc365c | 2015-05-25 19:35:42 -0700 | [diff] [blame] | 1461 | if (DEBUG_STATES) Slog.v(TAG_STATES, |
Wale Ogunwale | d046a01 | 2015-12-24 13:05:59 -0800 | [diff] [blame] | 1462 | "Moving to PAUSED: " + r + " (starting in paused state)"); |
| 1463 | r.state = PAUSED; |
Craig Mautner | 2420ead | 2013-04-01 17:13:20 -0700 | [diff] [blame] | 1464 | } |
| 1465 | |
| 1466 | // Launch the new version setup screen if needed. We do this -after- |
| 1467 | // launching the initial activity (that is, home), so that it can have |
| 1468 | // a chance to initialize itself while in the background, making the |
| 1469 | // switch back to it faster and look better. |
Wale Ogunwale | 1e60e0c | 2015-10-28 13:36:10 -0700 | [diff] [blame] | 1470 | if (isFocusedStack(stack)) { |
Craig Mautner | 2420ead | 2013-04-01 17:13:20 -0700 | [diff] [blame] | 1471 | mService.startSetupActivityLocked(); |
| 1472 | } |
| 1473 | |
Dianne Hackborn | 465fa39 | 2014-09-14 14:21:18 -0700 | [diff] [blame] | 1474 | // Update any services we are bound to that might care about whether |
| 1475 | // their client may have activities. |
Wale Ogunwale | d6ac762 | 2016-05-26 09:02:25 -0700 | [diff] [blame] | 1476 | if (r.app != null) { |
| 1477 | mService.mServices.updateServiceConnectionActivitiesLocked(r.app); |
| 1478 | } |
Dianne Hackborn | 465fa39 | 2014-09-14 14:21:18 -0700 | [diff] [blame] | 1479 | |
Craig Mautner | 2420ead | 2013-04-01 17:13:20 -0700 | [diff] [blame] | 1480 | return true; |
| 1481 | } |
| 1482 | |
Sudheer Shanka | fab200f | 2017-05-17 20:41:53 -0700 | [diff] [blame] | 1483 | private void logIfTransactionTooLarge(Intent intent, Bundle icicle) { |
| 1484 | int extrasSize = 0; |
| 1485 | if (intent != null) { |
| 1486 | final Bundle extras = intent.getExtras(); |
| 1487 | if (extras != null) { |
| 1488 | extrasSize = extras.getSize(); |
| 1489 | } |
| 1490 | } |
| 1491 | int icicleSize = (icicle == null ? 0 : icicle.getSize()); |
| 1492 | if (extrasSize + icicleSize > 200000) { |
| 1493 | Slog.e(TAG, "Transaction too large, intent: " + intent + ", extras size: " + extrasSize |
| 1494 | + ", icicle size: " + icicleSize); |
| 1495 | } |
| 1496 | } |
| 1497 | |
Craig Mautner | e79d4268 | 2013-04-01 19:01:53 -0700 | [diff] [blame] | 1498 | void startSpecificActivityLocked(ActivityRecord r, |
George Mount | 2c92c97 | 2014-03-20 09:38:23 -0700 | [diff] [blame] | 1499 | boolean andResume, boolean checkConfig) { |
Craig Mautner | e79d4268 | 2013-04-01 19:01:53 -0700 | [diff] [blame] | 1500 | // Is this activity's application already running? |
| 1501 | ProcessRecord app = mService.getProcessRecordLocked(r.processName, |
Dianne Hackborn | 3bc8f78d | 2013-09-19 13:34:35 -0700 | [diff] [blame] | 1502 | r.info.applicationInfo.uid, true); |
Craig Mautner | e79d4268 | 2013-04-01 19:01:53 -0700 | [diff] [blame] | 1503 | |
Andrii Kulian | 02b7a83 | 2016-10-06 23:11:56 -0700 | [diff] [blame] | 1504 | r.getStack().setLaunchTime(r); |
Craig Mautner | e79d4268 | 2013-04-01 19:01:53 -0700 | [diff] [blame] | 1505 | |
| 1506 | if (app != null && app.thread != null) { |
| 1507 | try { |
Dianne Hackborn | 237cefb | 2013-10-22 18:45:27 -0700 | [diff] [blame] | 1508 | if ((r.info.flags&ActivityInfo.FLAG_MULTIPROCESS) == 0 |
| 1509 | || !"android".equals(r.info.packageName)) { |
| 1510 | // Don't add this if it is a platform component that is marked |
| 1511 | // to run in multiple processes, because this is actually |
| 1512 | // part of the framework so doesn't make sense to track as a |
| 1513 | // separate apk in the process. |
Dianne Hackborn | f7097a5 | 2014-05-13 09:56:14 -0700 | [diff] [blame] | 1514 | app.addPackage(r.info.packageName, r.info.applicationInfo.versionCode, |
| 1515 | mService.mProcessStats); |
Dianne Hackborn | 237cefb | 2013-10-22 18:45:27 -0700 | [diff] [blame] | 1516 | } |
George Mount | 2c92c97 | 2014-03-20 09:38:23 -0700 | [diff] [blame] | 1517 | realStartActivityLocked(r, app, andResume, checkConfig); |
Craig Mautner | e79d4268 | 2013-04-01 19:01:53 -0700 | [diff] [blame] | 1518 | return; |
| 1519 | } catch (RemoteException e) { |
| 1520 | Slog.w(TAG, "Exception when starting activity " |
| 1521 | + r.intent.getComponent().flattenToShortString(), e); |
| 1522 | } |
| 1523 | |
| 1524 | // If a dead object exception was thrown -- fall through to |
| 1525 | // restart the application. |
| 1526 | } |
| 1527 | |
| 1528 | mService.startProcessLocked(r.processName, r.info.applicationInfo, true, 0, |
Dianne Hackborn | 3bc8f78d | 2013-09-19 13:34:35 -0700 | [diff] [blame] | 1529 | "activity", r.intent.getComponent(), false, false, true); |
Craig Mautner | e79d4268 | 2013-04-01 19:01:53 -0700 | [diff] [blame] | 1530 | } |
| 1531 | |
Filip Gruszczynski | 07a0e49 | 2015-12-17 14:16:38 -0800 | [diff] [blame] | 1532 | boolean checkStartAnyActivityPermission(Intent intent, ActivityInfo aInfo, |
Filip Gruszczynski | dc39490 | 2015-12-14 10:20:22 -0800 | [diff] [blame] | 1533 | String resultWho, int requestCode, int callingPid, int callingUid, |
| 1534 | String callingPackage, boolean ignoreTargetSecurity, ProcessRecord callerApp, |
Jorim Jaggi | 2adba07 | 2016-03-03 13:43:39 +0100 | [diff] [blame] | 1535 | ActivityRecord resultRecord, ActivityStack resultStack, ActivityOptions options) { |
Filip Gruszczynski | dc39490 | 2015-12-14 10:20:22 -0800 | [diff] [blame] | 1536 | final int startAnyPerm = mService.checkPermission(START_ANY_ACTIVITY, callingPid, |
| 1537 | callingUid); |
Andrii Kulian | fb1bf69 | 2017-01-17 11:17:34 -0800 | [diff] [blame] | 1538 | if (startAnyPerm == PERMISSION_GRANTED) { |
Filip Gruszczynski | dc39490 | 2015-12-14 10:20:22 -0800 | [diff] [blame] | 1539 | return true; |
| 1540 | } |
| 1541 | final int componentRestriction = getComponentRestrictionForCallingPackage( |
| 1542 | aInfo, callingPackage, callingPid, callingUid, ignoreTargetSecurity); |
| 1543 | final int actionRestriction = getActionRestrictionForCallingPackage( |
| 1544 | intent.getAction(), callingPackage, callingPid, callingUid); |
| 1545 | if (componentRestriction == ACTIVITY_RESTRICTION_PERMISSION |
| 1546 | || actionRestriction == ACTIVITY_RESTRICTION_PERMISSION) { |
| 1547 | if (resultRecord != null) { |
| 1548 | resultStack.sendActivityResultLocked(-1, |
| 1549 | resultRecord, resultWho, requestCode, |
| 1550 | Activity.RESULT_CANCELED, null); |
| 1551 | } |
| 1552 | final String msg; |
| 1553 | if (actionRestriction == ACTIVITY_RESTRICTION_PERMISSION) { |
| 1554 | msg = "Permission Denial: starting " + intent.toString() |
| 1555 | + " from " + callerApp + " (pid=" + callingPid |
| 1556 | + ", uid=" + callingUid + ")" + " with revoked permission " |
| 1557 | + ACTION_TO_RUNTIME_PERMISSION.get(intent.getAction()); |
| 1558 | } else if (!aInfo.exported) { |
| 1559 | msg = "Permission Denial: starting " + intent.toString() |
| 1560 | + " from " + callerApp + " (pid=" + callingPid |
| 1561 | + ", uid=" + callingUid + ")" |
| 1562 | + " not exported from uid " + aInfo.applicationInfo.uid; |
| 1563 | } else { |
| 1564 | msg = "Permission Denial: starting " + intent.toString() |
| 1565 | + " from " + callerApp + " (pid=" + callingPid |
| 1566 | + ", uid=" + callingUid + ")" |
| 1567 | + " requires " + aInfo.permission; |
| 1568 | } |
| 1569 | Slog.w(TAG, msg); |
| 1570 | throw new SecurityException(msg); |
| 1571 | } |
| 1572 | |
| 1573 | if (actionRestriction == ACTIVITY_RESTRICTION_APPOP) { |
| 1574 | final String message = "Appop Denial: starting " + intent.toString() |
| 1575 | + " from " + callerApp + " (pid=" + callingPid |
| 1576 | + ", uid=" + callingUid + ")" |
| 1577 | + " requires " + AppOpsManager.permissionToOp( |
| 1578 | ACTION_TO_RUNTIME_PERMISSION.get(intent.getAction())); |
| 1579 | Slog.w(TAG, message); |
| 1580 | return false; |
| 1581 | } else if (componentRestriction == ACTIVITY_RESTRICTION_APPOP) { |
| 1582 | final String message = "Appop Denial: starting " + intent.toString() |
| 1583 | + " from " + callerApp + " (pid=" + callingPid |
| 1584 | + ", uid=" + callingUid + ")" |
| 1585 | + " requires appop " + AppOpsManager.permissionToOp(aInfo.permission); |
| 1586 | Slog.w(TAG, message); |
| 1587 | return false; |
| 1588 | } |
Andrii Kulian | 16802aa | 2016-11-02 12:21:33 -0700 | [diff] [blame] | 1589 | if (options != null) { |
Winson Chung | 3f0e59a | 2017-10-25 10:19:05 -0700 | [diff] [blame] | 1590 | // If a launch task id is specified, then ensure that the caller is the recents |
| 1591 | // component or has the START_TASKS_FROM_RECENTS permission |
| 1592 | if (options.getLaunchTaskId() != INVALID_TASK_ID |
| 1593 | && !mRecentTasks.isCallerRecents(callingUid)) { |
Andrii Kulian | 16802aa | 2016-11-02 12:21:33 -0700 | [diff] [blame] | 1594 | final int startInTaskPerm = mService.checkPermission(START_TASKS_FROM_RECENTS, |
| 1595 | callingPid, callingUid); |
Andrii Kulian | 3c9ad07 | 2017-08-01 11:45:22 -0700 | [diff] [blame] | 1596 | if (startInTaskPerm == PERMISSION_DENIED) { |
Andrii Kulian | 16802aa | 2016-11-02 12:21:33 -0700 | [diff] [blame] | 1597 | final String msg = "Permission Denial: starting " + intent.toString() |
| 1598 | + " from " + callerApp + " (pid=" + callingPid |
| 1599 | + ", uid=" + callingUid + ") with launchTaskId=" |
| 1600 | + options.getLaunchTaskId(); |
| 1601 | Slog.w(TAG, msg); |
| 1602 | throw new SecurityException(msg); |
| 1603 | } |
| 1604 | } |
| 1605 | // Check if someone tries to launch an activity on a private display with a different |
| 1606 | // owner. |
| 1607 | final int launchDisplayId = options.getLaunchDisplayId(); |
Andrii Kulian | 02689a7 | 2017-07-06 14:28:59 -0700 | [diff] [blame] | 1608 | if (launchDisplayId != INVALID_DISPLAY && !isCallerAllowedToLaunchOnDisplay(callingPid, |
| 1609 | callingUid, launchDisplayId, aInfo)) { |
Andrii Kulian | fb1bf69 | 2017-01-17 11:17:34 -0800 | [diff] [blame] | 1610 | final String msg = "Permission Denial: starting " + intent.toString() |
| 1611 | + " from " + callerApp + " (pid=" + callingPid |
| 1612 | + ", uid=" + callingUid + ") with launchDisplayId=" |
| 1613 | + launchDisplayId; |
| 1614 | Slog.w(TAG, msg); |
| 1615 | throw new SecurityException(msg); |
Jorim Jaggi | 2adba07 | 2016-03-03 13:43:39 +0100 | [diff] [blame] | 1616 | } |
Charles He | 2bf2832 | 2017-10-12 22:24:49 +0100 | [diff] [blame] | 1617 | // Check if someone tries to launch an unwhitelisted activity into LockTask mode. |
| 1618 | final boolean lockTaskMode = options.getLockTaskMode(); |
| 1619 | if (lockTaskMode && !mService.mLockTaskController.isPackageWhitelisted( |
| 1620 | UserHandle.getUserId(callingUid), aInfo.packageName)) { |
| 1621 | final String msg = "Permission Denial: starting " + intent.toString() |
| 1622 | + " from " + callerApp + " (pid=" + callingPid |
| 1623 | + ", uid=" + callingUid + ") with lockTaskMode=true"; |
| 1624 | Slog.w(TAG, msg); |
| 1625 | throw new SecurityException(msg); |
| 1626 | } |
Jorim Jaggi | 2adba07 | 2016-03-03 13:43:39 +0100 | [diff] [blame] | 1627 | } |
| 1628 | |
Filip Gruszczynski | dc39490 | 2015-12-14 10:20:22 -0800 | [diff] [blame] | 1629 | return true; |
| 1630 | } |
| 1631 | |
Andrii Kulian | fb1bf69 | 2017-01-17 11:17:34 -0800 | [diff] [blame] | 1632 | /** Check if caller is allowed to launch activities on specified display. */ |
Andrii Kulian | 02689a7 | 2017-07-06 14:28:59 -0700 | [diff] [blame] | 1633 | boolean isCallerAllowedToLaunchOnDisplay(int callingPid, int callingUid, int launchDisplayId, |
| 1634 | ActivityInfo aInfo) { |
Andrii Kulian | fb1bf69 | 2017-01-17 11:17:34 -0800 | [diff] [blame] | 1635 | if (DEBUG_TASKS) Slog.d(TAG, "Launch on display check: displayId=" + launchDisplayId |
| 1636 | + " callingPid=" + callingPid + " callingUid=" + callingUid); |
| 1637 | |
Andrii Kulian | 02689a7 | 2017-07-06 14:28:59 -0700 | [diff] [blame] | 1638 | if (callingPid == -1 && callingUid == -1) { |
| 1639 | if (DEBUG_TASKS) Slog.d(TAG, "Launch on display check: no caller info, skip check"); |
| 1640 | return true; |
| 1641 | } |
| 1642 | |
Andrii Kulian | 62e6f25 | 2017-05-30 22:46:53 -0700 | [diff] [blame] | 1643 | final ActivityDisplay activityDisplay = getActivityDisplayOrCreateLocked(launchDisplayId); |
Andrii Kulian | fb1bf69 | 2017-01-17 11:17:34 -0800 | [diff] [blame] | 1644 | if (activityDisplay == null) { |
| 1645 | Slog.w(TAG, "Launch on display check: display not found"); |
| 1646 | return false; |
| 1647 | } |
| 1648 | |
Andrii Kulian | 02689a7 | 2017-07-06 14:28:59 -0700 | [diff] [blame] | 1649 | // Check if the caller has enough privileges to embed activities and launch to private |
| 1650 | // displays. |
Andrii Kulian | 3a95edc | 2017-06-28 16:21:07 -0700 | [diff] [blame] | 1651 | final int startAnyPerm = mService.checkPermission(INTERNAL_SYSTEM_WINDOW, callingPid, |
Andrii Kulian | 1cba31c | 2017-06-28 09:42:48 -0700 | [diff] [blame] | 1652 | callingUid); |
| 1653 | if (startAnyPerm == PERMISSION_GRANTED) { |
| 1654 | if (DEBUG_TASKS) Slog.d(TAG, "Launch on display check:" |
| 1655 | + " allow launch any on display"); |
| 1656 | return true; |
| 1657 | } |
| 1658 | |
Andrii Kulian | 8f07029 | 2017-09-12 22:56:49 -0700 | [diff] [blame] | 1659 | // Check if caller is already present on display |
| 1660 | final boolean uidPresentOnDisplay = activityDisplay.isUidPresent(callingUid); |
| 1661 | |
Andrii Kulian | 3c9ad07 | 2017-08-01 11:45:22 -0700 | [diff] [blame] | 1662 | final int displayOwnerUid = activityDisplay.mDisplay.getOwnerUid(); |
| 1663 | if (activityDisplay.mDisplay.getType() == TYPE_VIRTUAL && displayOwnerUid != SYSTEM_UID |
| 1664 | && displayOwnerUid != aInfo.applicationInfo.uid) { |
Andrii Kulian | 1cba31c | 2017-06-28 09:42:48 -0700 | [diff] [blame] | 1665 | // Limit launching on virtual displays, because their contents can be read from Surface |
| 1666 | // by apps that created them. |
Andrii Kulian | 02689a7 | 2017-07-06 14:28:59 -0700 | [diff] [blame] | 1667 | if ((aInfo.flags & ActivityInfo.FLAG_ALLOW_EMBEDDED) == 0) { |
| 1668 | if (DEBUG_TASKS) Slog.d(TAG, "Launch on display check:" |
| 1669 | + " disallow launch on virtual display for not-embedded activity."); |
| 1670 | return false; |
| 1671 | } |
Andrii Kulian | 3c9ad07 | 2017-08-01 11:45:22 -0700 | [diff] [blame] | 1672 | // Check if the caller is allowed to embed activities from other apps. |
| 1673 | if (mService.checkPermission(ACTIVITY_EMBEDDING, callingPid, callingUid) |
Andrii Kulian | 8f07029 | 2017-09-12 22:56:49 -0700 | [diff] [blame] | 1674 | == PERMISSION_DENIED && !uidPresentOnDisplay) { |
Andrii Kulian | 3c9ad07 | 2017-08-01 11:45:22 -0700 | [diff] [blame] | 1675 | if (DEBUG_TASKS) Slog.d(TAG, "Launch on display check:" |
| 1676 | + " disallow activity embedding without permission."); |
| 1677 | return false; |
| 1678 | } |
Andrii Kulian | 1cba31c | 2017-06-28 09:42:48 -0700 | [diff] [blame] | 1679 | } |
| 1680 | |
Andrii Kulian | fb1bf69 | 2017-01-17 11:17:34 -0800 | [diff] [blame] | 1681 | if (!activityDisplay.isPrivate()) { |
| 1682 | // Anyone can launch on a public display. |
| 1683 | if (DEBUG_TASKS) Slog.d(TAG, "Launch on display check:" |
| 1684 | + " allow launch on public display"); |
| 1685 | return true; |
| 1686 | } |
| 1687 | |
| 1688 | // Check if the caller is the owner of the display. |
Andrii Kulian | 3c9ad07 | 2017-08-01 11:45:22 -0700 | [diff] [blame] | 1689 | if (displayOwnerUid == callingUid) { |
Andrii Kulian | fb1bf69 | 2017-01-17 11:17:34 -0800 | [diff] [blame] | 1690 | if (DEBUG_TASKS) Slog.d(TAG, "Launch on display check:" |
| 1691 | + " allow launch for owner of the display"); |
| 1692 | return true; |
| 1693 | } |
| 1694 | |
Andrii Kulian | 8f07029 | 2017-09-12 22:56:49 -0700 | [diff] [blame] | 1695 | if (uidPresentOnDisplay) { |
Andrii Kulian | fb1bf69 | 2017-01-17 11:17:34 -0800 | [diff] [blame] | 1696 | if (DEBUG_TASKS) Slog.d(TAG, "Launch on display check:" |
| 1697 | + " allow launch for caller present on the display"); |
| 1698 | return true; |
| 1699 | } |
| 1700 | |
Andrii Kulian | fb1bf69 | 2017-01-17 11:17:34 -0800 | [diff] [blame] | 1701 | Slog.w(TAG, "Launch on display check: denied"); |
| 1702 | return false; |
| 1703 | } |
| 1704 | |
| 1705 | /** Update lists of UIDs that are present on displays and have access to them. */ |
| 1706 | void updateUIDsPresentOnDisplay() { |
| 1707 | mDisplayAccessUIDs.clear(); |
| 1708 | for (int displayNdx = mActivityDisplays.size() - 1; displayNdx >= 0; --displayNdx) { |
| 1709 | final ActivityDisplay activityDisplay = mActivityDisplays.valueAt(displayNdx); |
David Stevens | 82ea6cb | 2017-03-03 16:18:50 -0800 | [diff] [blame] | 1710 | // Only bother calculating the whitelist for private displays |
| 1711 | if (activityDisplay.isPrivate()) { |
| 1712 | mDisplayAccessUIDs.append( |
| 1713 | activityDisplay.mDisplayId, activityDisplay.getPresentUIDs()); |
| 1714 | } |
Andrii Kulian | fb1bf69 | 2017-01-17 11:17:34 -0800 | [diff] [blame] | 1715 | } |
| 1716 | // Store updated lists in DisplayManager. Callers from outside of AM should get them there. |
| 1717 | mDisplayManagerInternal.setDisplayAccessUIDs(mDisplayAccessUIDs); |
| 1718 | } |
| 1719 | |
Filip Gruszczynski | 07a0e49 | 2015-12-17 14:16:38 -0800 | [diff] [blame] | 1720 | UserInfo getUserInfo(int userId) { |
Clara Bayarri | f7fea16 | 2015-10-22 16:09:52 +0100 | [diff] [blame] | 1721 | final long identity = Binder.clearCallingIdentity(); |
| 1722 | try { |
| 1723 | return UserManager.get(mService.mContext).getUserInfo(userId); |
| 1724 | } finally { |
| 1725 | Binder.restoreCallingIdentity(identity); |
| 1726 | } |
| 1727 | } |
| 1728 | |
Svet Ganov | 99b6043 | 2015-06-27 13:15:22 -0700 | [diff] [blame] | 1729 | private int getComponentRestrictionForCallingPackage(ActivityInfo activityInfo, |
Dianne Hackborn | a7cfbe0 | 2015-07-16 10:52:52 -0700 | [diff] [blame] | 1730 | String callingPackage, int callingPid, int callingUid, boolean ignoreTargetSecurity) { |
Dianne Hackborn | a7cfbe0 | 2015-07-16 10:52:52 -0700 | [diff] [blame] | 1731 | if (!ignoreTargetSecurity && mService.checkComponentPermission(activityInfo.permission, |
| 1732 | callingPid, callingUid, activityInfo.applicationInfo.uid, activityInfo.exported) |
Andrii Kulian | 3c9ad07 | 2017-08-01 11:45:22 -0700 | [diff] [blame] | 1733 | == PERMISSION_DENIED) { |
Svet Ganov | 99b6043 | 2015-06-27 13:15:22 -0700 | [diff] [blame] | 1734 | return ACTIVITY_RESTRICTION_PERMISSION; |
| 1735 | } |
| 1736 | |
Christopher Tate | ff7add0 | 2015-08-17 10:23:22 -0700 | [diff] [blame] | 1737 | if (activityInfo.permission == null) { |
| 1738 | return ACTIVITY_RESTRICTION_NONE; |
| 1739 | } |
| 1740 | |
Svet Ganov | 99b6043 | 2015-06-27 13:15:22 -0700 | [diff] [blame] | 1741 | final int opCode = AppOpsManager.permissionToOpCode(activityInfo.permission); |
| 1742 | if (opCode == AppOpsManager.OP_NONE) { |
| 1743 | return ACTIVITY_RESTRICTION_NONE; |
| 1744 | } |
| 1745 | |
| 1746 | if (mService.mAppOpsService.noteOperation(opCode, callingUid, |
| 1747 | callingPackage) != AppOpsManager.MODE_ALLOWED) { |
Dianne Hackborn | a7cfbe0 | 2015-07-16 10:52:52 -0700 | [diff] [blame] | 1748 | if (!ignoreTargetSecurity) { |
| 1749 | return ACTIVITY_RESTRICTION_APPOP; |
| 1750 | } |
Svet Ganov | 99b6043 | 2015-06-27 13:15:22 -0700 | [diff] [blame] | 1751 | } |
| 1752 | |
| 1753 | return ACTIVITY_RESTRICTION_NONE; |
| 1754 | } |
| 1755 | |
Svetoslav | 7008b51 | 2015-06-24 18:47:07 -0700 | [diff] [blame] | 1756 | private int getActionRestrictionForCallingPackage(String action, |
| 1757 | String callingPackage, int callingPid, int callingUid) { |
| 1758 | if (action == null) { |
Svet Ganov | 99b6043 | 2015-06-27 13:15:22 -0700 | [diff] [blame] | 1759 | return ACTIVITY_RESTRICTION_NONE; |
Svetoslav | 7008b51 | 2015-06-24 18:47:07 -0700 | [diff] [blame] | 1760 | } |
| 1761 | |
| 1762 | String permission = ACTION_TO_RUNTIME_PERMISSION.get(action); |
| 1763 | if (permission == null) { |
Svet Ganov | 99b6043 | 2015-06-27 13:15:22 -0700 | [diff] [blame] | 1764 | return ACTIVITY_RESTRICTION_NONE; |
Svetoslav | 7008b51 | 2015-06-24 18:47:07 -0700 | [diff] [blame] | 1765 | } |
| 1766 | |
| 1767 | final PackageInfo packageInfo; |
| 1768 | try { |
| 1769 | packageInfo = mService.mContext.getPackageManager() |
| 1770 | .getPackageInfo(callingPackage, PackageManager.GET_PERMISSIONS); |
| 1771 | } catch (PackageManager.NameNotFoundException e) { |
| 1772 | Slog.i(TAG, "Cannot find package info for " + callingPackage); |
Svet Ganov | 99b6043 | 2015-06-27 13:15:22 -0700 | [diff] [blame] | 1773 | return ACTIVITY_RESTRICTION_NONE; |
Svetoslav | 7008b51 | 2015-06-24 18:47:07 -0700 | [diff] [blame] | 1774 | } |
| 1775 | |
| 1776 | if (!ArrayUtils.contains(packageInfo.requestedPermissions, permission)) { |
Svet Ganov | 99b6043 | 2015-06-27 13:15:22 -0700 | [diff] [blame] | 1777 | return ACTIVITY_RESTRICTION_NONE; |
Svetoslav | 7008b51 | 2015-06-24 18:47:07 -0700 | [diff] [blame] | 1778 | } |
| 1779 | |
Andrii Kulian | 3c9ad07 | 2017-08-01 11:45:22 -0700 | [diff] [blame] | 1780 | if (mService.checkPermission(permission, callingPid, callingUid) == PERMISSION_DENIED) { |
Svet Ganov | 99b6043 | 2015-06-27 13:15:22 -0700 | [diff] [blame] | 1781 | return ACTIVITY_RESTRICTION_PERMISSION; |
Svetoslav | 7008b51 | 2015-06-24 18:47:07 -0700 | [diff] [blame] | 1782 | } |
| 1783 | |
| 1784 | final int opCode = AppOpsManager.permissionToOpCode(permission); |
| 1785 | if (opCode == AppOpsManager.OP_NONE) { |
Svet Ganov | 99b6043 | 2015-06-27 13:15:22 -0700 | [diff] [blame] | 1786 | return ACTIVITY_RESTRICTION_NONE; |
Svetoslav | 7008b51 | 2015-06-24 18:47:07 -0700 | [diff] [blame] | 1787 | } |
| 1788 | |
| 1789 | if (mService.mAppOpsService.noteOperation(opCode, callingUid, |
| 1790 | callingPackage) != AppOpsManager.MODE_ALLOWED) { |
Svet Ganov | 99b6043 | 2015-06-27 13:15:22 -0700 | [diff] [blame] | 1791 | return ACTIVITY_RESTRICTION_APPOP; |
Svetoslav | 7008b51 | 2015-06-24 18:47:07 -0700 | [diff] [blame] | 1792 | } |
| 1793 | |
Svet Ganov | 99b6043 | 2015-06-27 13:15:22 -0700 | [diff] [blame] | 1794 | return ACTIVITY_RESTRICTION_NONE; |
Svetoslav | 7008b51 | 2015-06-24 18:47:07 -0700 | [diff] [blame] | 1795 | } |
| 1796 | |
Dianne Hackborn | 3d07c94 | 2015-03-13 18:02:54 -0700 | [diff] [blame] | 1797 | void setLaunchSource(int uid) { |
| 1798 | mLaunchingActivity.setWorkSource(new WorkSource(uid)); |
| 1799 | } |
| 1800 | |
Craig Mautner | 7ea5bd4 | 2013-07-05 15:27:08 -0700 | [diff] [blame] | 1801 | void acquireLaunchWakelock() { |
| 1802 | if (VALIDATE_WAKE_LOCK_CALLER && Binder.getCallingUid() != Process.myUid()) { |
| 1803 | throw new IllegalStateException("Calling must be system uid"); |
| 1804 | } |
| 1805 | mLaunchingActivity.acquire(); |
| 1806 | if (!mHandler.hasMessages(LAUNCH_TIMEOUT_MSG)) { |
| 1807 | // To be safe, don't allow the wake lock to be held for too long. |
| 1808 | mHandler.sendEmptyMessageDelayed(LAUNCH_TIMEOUT_MSG, LAUNCH_TIMEOUT); |
| 1809 | } |
| 1810 | } |
| 1811 | |
Craig Mautner | f3ea23a | 2015-01-13 09:37:08 -0800 | [diff] [blame] | 1812 | /** |
| 1813 | * Called when the frontmost task is idle. |
| 1814 | * @return the state of mService.mBooting before this was called. |
| 1815 | */ |
| 1816 | private boolean checkFinishBootingLocked() { |
| 1817 | final boolean booting = mService.mBooting; |
| 1818 | boolean enableScreen = false; |
| 1819 | mService.mBooting = false; |
| 1820 | if (!mService.mBooted) { |
| 1821 | mService.mBooted = true; |
| 1822 | enableScreen = true; |
| 1823 | } |
| 1824 | if (booting || enableScreen) { |
| 1825 | mService.postFinishBooting(booting, enableScreen); |
| 1826 | } |
| 1827 | return booting; |
| 1828 | } |
| 1829 | |
Craig Mautner | f333327 | 2013-04-22 10:55:53 -0700 | [diff] [blame] | 1830 | // Checked. |
| 1831 | final ActivityRecord activityIdleInternalLocked(final IBinder token, boolean fromTimeout, |
Winson Chung | 4dabf23 | 2017-01-25 13:25:22 -0800 | [diff] [blame] | 1832 | boolean processPausingActivities, Configuration config) { |
Wale Ogunwale | e23149f | 2015-03-06 15:39:44 -0800 | [diff] [blame] | 1833 | if (DEBUG_ALL) Slog.v(TAG, "Activity idle: " + token); |
Craig Mautner | f333327 | 2013-04-22 10:55:53 -0700 | [diff] [blame] | 1834 | |
Craig Mautner | f333327 | 2013-04-22 10:55:53 -0700 | [diff] [blame] | 1835 | ArrayList<ActivityRecord> finishes = null; |
Amith Yamasani | 37a40c2 | 2015-06-17 13:25:42 -0700 | [diff] [blame] | 1836 | ArrayList<UserState> startingUsers = null; |
Craig Mautner | f333327 | 2013-04-22 10:55:53 -0700 | [diff] [blame] | 1837 | int NS = 0; |
| 1838 | int NF = 0; |
Craig Mautner | f333327 | 2013-04-22 10:55:53 -0700 | [diff] [blame] | 1839 | boolean booting = false; |
Craig Mautner | f333327 | 2013-04-22 10:55:53 -0700 | [diff] [blame] | 1840 | boolean activityRemoved = false; |
| 1841 | |
Wale Ogunwale | 7d70117 | 2015-03-11 15:36:30 -0700 | [diff] [blame] | 1842 | ActivityRecord r = ActivityRecord.forTokenLocked(token); |
Craig Mautner | f333327 | 2013-04-22 10:55:53 -0700 | [diff] [blame] | 1843 | if (r != null) { |
Wale Ogunwale | 0fc365c | 2015-05-25 19:35:42 -0700 | [diff] [blame] | 1844 | if (DEBUG_IDLE) Slog.d(TAG_IDLE, "activityIdleInternalLocked: Callers=" |
| 1845 | + Debug.getCallers(4)); |
Craig Mautner | f333327 | 2013-04-22 10:55:53 -0700 | [diff] [blame] | 1846 | mHandler.removeMessages(IDLE_TIMEOUT_MSG, r); |
| 1847 | r.finishLaunchTickingLocked(); |
Craig Mautner | 7ea5bd4 | 2013-07-05 15:27:08 -0700 | [diff] [blame] | 1848 | if (fromTimeout) { |
| 1849 | reportActivityLaunchedLocked(fromTimeout, r, -1, -1); |
Craig Mautner | f333327 | 2013-04-22 10:55:53 -0700 | [diff] [blame] | 1850 | } |
Craig Mautner | 7ea5bd4 | 2013-07-05 15:27:08 -0700 | [diff] [blame] | 1851 | |
| 1852 | // This is a hack to semi-deal with a race condition |
| 1853 | // in the client where it can be constructed with a |
| 1854 | // newer configuration from when we asked it to launch. |
| 1855 | // We'll update with whatever configuration it now says |
| 1856 | // it used to launch. |
| 1857 | if (config != null) { |
Bryce Lee | a163b76 | 2017-01-24 11:05:01 -0800 | [diff] [blame] | 1858 | r.setLastReportedGlobalConfiguration(config); |
Craig Mautner | 7ea5bd4 | 2013-07-05 15:27:08 -0700 | [diff] [blame] | 1859 | } |
| 1860 | |
| 1861 | // We are now idle. If someone is waiting for a thumbnail from |
| 1862 | // us, we can now deliver. |
| 1863 | r.idle = true; |
| 1864 | |
Craig Mautner | 7ea5bd4 | 2013-07-05 15:27:08 -0700 | [diff] [blame] | 1865 | //Slog.i(TAG, "IDLE: mBooted=" + mBooted + ", fromTimeout=" + fromTimeout); |
Andrii Kulian | 02b7a83 | 2016-10-06 23:11:56 -0700 | [diff] [blame] | 1866 | if (isFocusedStack(r.getStack()) || fromTimeout) { |
Craig Mautner | f3ea23a | 2015-01-13 09:37:08 -0800 | [diff] [blame] | 1867 | booting = checkFinishBootingLocked(); |
Craig Mautner | 7ea5bd4 | 2013-07-05 15:27:08 -0700 | [diff] [blame] | 1868 | } |
| 1869 | } |
| 1870 | |
| 1871 | if (allResumedActivitiesIdle()) { |
| 1872 | if (r != null) { |
| 1873 | mService.scheduleAppGcsLocked(); |
Craig Mautner | 7ea5bd4 | 2013-07-05 15:27:08 -0700 | [diff] [blame] | 1874 | } |
| 1875 | |
| 1876 | if (mLaunchingActivity.isHeld()) { |
| 1877 | mHandler.removeMessages(LAUNCH_TIMEOUT_MSG); |
| 1878 | if (VALIDATE_WAKE_LOCK_CALLER && |
| 1879 | Binder.getCallingUid() != Process.myUid()) { |
| 1880 | throw new IllegalStateException("Calling must be system uid"); |
| 1881 | } |
| 1882 | mLaunchingActivity.release(); |
| 1883 | } |
Filip Gruszczynski | bc5a6c5 | 2015-09-22 13:13:24 -0700 | [diff] [blame] | 1884 | ensureActivitiesVisibleLocked(null, 0, !PRESERVE_WINDOWS); |
Craig Mautner | f333327 | 2013-04-22 10:55:53 -0700 | [diff] [blame] | 1885 | } |
| 1886 | |
| 1887 | // Atomically retrieve all of the other things to do. |
Winson Chung | 4dabf23 | 2017-01-25 13:25:22 -0800 | [diff] [blame] | 1888 | final ArrayList<ActivityRecord> stops = processStoppingActivitiesLocked(r, |
| 1889 | true /* remove */, processPausingActivities); |
Craig Mautner | f333327 | 2013-04-22 10:55:53 -0700 | [diff] [blame] | 1890 | NS = stops != null ? stops.size() : 0; |
Wale Ogunwale | 7d70117 | 2015-03-11 15:36:30 -0700 | [diff] [blame] | 1891 | if ((NF = mFinishingActivities.size()) > 0) { |
| 1892 | finishes = new ArrayList<>(mFinishingActivities); |
Craig Mautner | f333327 | 2013-04-22 10:55:53 -0700 | [diff] [blame] | 1893 | mFinishingActivities.clear(); |
| 1894 | } |
| 1895 | |
Craig Mautner | f333327 | 2013-04-22 10:55:53 -0700 | [diff] [blame] | 1896 | if (mStartingUsers.size() > 0) { |
Wale Ogunwale | 7d70117 | 2015-03-11 15:36:30 -0700 | [diff] [blame] | 1897 | startingUsers = new ArrayList<>(mStartingUsers); |
Craig Mautner | f333327 | 2013-04-22 10:55:53 -0700 | [diff] [blame] | 1898 | mStartingUsers.clear(); |
| 1899 | } |
| 1900 | |
Craig Mautner | f333327 | 2013-04-22 10:55:53 -0700 | [diff] [blame] | 1901 | // Stop any activities that are scheduled to do so but have been |
| 1902 | // waiting for the next one to start. |
| 1903 | for (int i = 0; i < NS; i++) { |
| 1904 | r = stops.get(i); |
Andrii Kulian | 02b7a83 | 2016-10-06 23:11:56 -0700 | [diff] [blame] | 1905 | final ActivityStack stack = r.getStack(); |
Wale Ogunwale | 7d70117 | 2015-03-11 15:36:30 -0700 | [diff] [blame] | 1906 | if (stack != null) { |
| 1907 | if (r.finishing) { |
| 1908 | stack.finishCurrentActivityLocked(r, ActivityStack.FINISH_IMMEDIATELY, false); |
| 1909 | } else { |
| 1910 | stack.stopActivityLocked(r); |
| 1911 | } |
Craig Mautner | f333327 | 2013-04-22 10:55:53 -0700 | [diff] [blame] | 1912 | } |
| 1913 | } |
| 1914 | |
| 1915 | // Finish any activities that are scheduled to do so but have been |
| 1916 | // waiting for the next one to start. |
| 1917 | for (int i = 0; i < NF; i++) { |
| 1918 | r = finishes.get(i); |
Andrii Kulian | 02b7a83 | 2016-10-06 23:11:56 -0700 | [diff] [blame] | 1919 | final ActivityStack stack = r.getStack(); |
Wale Ogunwale | 7d70117 | 2015-03-11 15:36:30 -0700 | [diff] [blame] | 1920 | if (stack != null) { |
| 1921 | activityRemoved |= stack.destroyActivityLocked(r, true, "finish-idle"); |
| 1922 | } |
Craig Mautner | f333327 | 2013-04-22 10:55:53 -0700 | [diff] [blame] | 1923 | } |
| 1924 | |
Dianne Hackborn | 7622a0f | 2014-09-30 14:31:42 -0700 | [diff] [blame] | 1925 | if (!booting) { |
Amith Yamasani | 1a7eaaa5 | 2014-05-07 10:22:15 -0700 | [diff] [blame] | 1926 | // Complete user switch |
| 1927 | if (startingUsers != null) { |
| 1928 | for (int i = 0; i < startingUsers.size(); i++) { |
Fyodor Kupolov | 610acda | 2015-10-19 18:44:07 -0700 | [diff] [blame] | 1929 | mService.mUserController.finishUserSwitch(startingUsers.get(i)); |
Amith Yamasani | 1a7eaaa5 | 2014-05-07 10:22:15 -0700 | [diff] [blame] | 1930 | } |
| 1931 | } |
Craig Mautner | f333327 | 2013-04-22 10:55:53 -0700 | [diff] [blame] | 1932 | } |
| 1933 | |
| 1934 | mService.trimApplications(); |
| 1935 | //dump(); |
| 1936 | //mWindowManager.dump(); |
| 1937 | |
Craig Mautner | f333327 | 2013-04-22 10:55:53 -0700 | [diff] [blame] | 1938 | if (activityRemoved) { |
Wale Ogunwale | d046a01 | 2015-12-24 13:05:59 -0800 | [diff] [blame] | 1939 | resumeFocusedStackTopActivityLocked(); |
Craig Mautner | f333327 | 2013-04-22 10:55:53 -0700 | [diff] [blame] | 1940 | } |
| 1941 | |
Craig Mautner | 7ea5bd4 | 2013-07-05 15:27:08 -0700 | [diff] [blame] | 1942 | return r; |
Craig Mautner | f333327 | 2013-04-22 10:55:53 -0700 | [diff] [blame] | 1943 | } |
| 1944 | |
Craig Mautner | 8e56957 | 2013-10-11 17:36:59 -0700 | [diff] [blame] | 1945 | boolean handleAppDiedLocked(ProcessRecord app) { |
Craig Mautner | 1909125 | 2013-10-05 00:03:53 -0700 | [diff] [blame] | 1946 | boolean hasVisibleActivities = false; |
Craig Mautner | e0a3884 | 2013-12-16 16:14:02 -0800 | [diff] [blame] | 1947 | for (int displayNdx = mActivityDisplays.size() - 1; displayNdx >= 0; --displayNdx) { |
Wale Ogunwale | a0f5b5e | 2017-10-11 09:37:23 -0700 | [diff] [blame] | 1948 | final ActivityDisplay display = mActivityDisplays.valueAt(displayNdx); |
| 1949 | for (int stackNdx = display.getChildCount() - 1; stackNdx >= 0; --stackNdx) { |
| 1950 | final ActivityStack stack = display.getChildAt(stackNdx); |
| 1951 | hasVisibleActivities |= stack.handleAppDiedLocked(app); |
Craig Mautner | 4a1cb22 | 2013-12-04 16:14:06 -0800 | [diff] [blame] | 1952 | } |
Craig Mautner | 6b74cb5 | 2013-09-27 17:02:21 -0700 | [diff] [blame] | 1953 | } |
Craig Mautner | 1909125 | 2013-10-05 00:03:53 -0700 | [diff] [blame] | 1954 | return hasVisibleActivities; |
Craig Mautner | 8d341ef | 2013-03-26 09:03:27 -0700 | [diff] [blame] | 1955 | } |
| 1956 | |
| 1957 | void closeSystemDialogsLocked() { |
Craig Mautner | e0a3884 | 2013-12-16 16:14:02 -0800 | [diff] [blame] | 1958 | for (int displayNdx = mActivityDisplays.size() - 1; displayNdx >= 0; --displayNdx) { |
Wale Ogunwale | a0f5b5e | 2017-10-11 09:37:23 -0700 | [diff] [blame] | 1959 | final ActivityDisplay display = mActivityDisplays.valueAt(displayNdx); |
| 1960 | for (int stackNdx = display.getChildCount() - 1; stackNdx >= 0; --stackNdx) { |
| 1961 | final ActivityStack stack = display.getChildAt(stackNdx); |
| 1962 | stack.closeSystemDialogsLocked(); |
Craig Mautner | 4a1cb22 | 2013-12-04 16:14:06 -0800 | [diff] [blame] | 1963 | } |
Craig Mautner | 8d341ef | 2013-03-26 09:03:27 -0700 | [diff] [blame] | 1964 | } |
| 1965 | } |
| 1966 | |
Craig Mautner | 93529a4 | 2013-10-04 15:03:13 -0700 | [diff] [blame] | 1967 | void removeUserLocked(int userId) { |
Craig Mautner | 4f1df4f | 2013-10-15 15:44:14 -0700 | [diff] [blame] | 1968 | mUserStackInFront.delete(userId); |
Craig Mautner | 93529a4 | 2013-10-04 15:03:13 -0700 | [diff] [blame] | 1969 | } |
| 1970 | |
Craig Mautner | 8d341ef | 2013-03-26 09:03:27 -0700 | [diff] [blame] | 1971 | /** |
Chong Zhang | 45c25ce | 2015-08-10 22:18:26 -0700 | [diff] [blame] | 1972 | * Update the last used stack id for non-current user (current user's last |
| 1973 | * used stack is the focused stack) |
| 1974 | */ |
| 1975 | void updateUserStackLocked(int userId, ActivityStack stack) { |
| 1976 | if (userId != mCurrentUser) { |
Wale Ogunwale | 6827856 | 2017-09-23 17:13:55 -0700 | [diff] [blame] | 1977 | mUserStackInFront.put(userId, stack != null ? stack.getStackId() : mHomeStack.mStackId); |
Chong Zhang | 45c25ce | 2015-08-10 22:18:26 -0700 | [diff] [blame] | 1978 | } |
| 1979 | } |
| 1980 | |
| 1981 | /** |
Craig Mautner | 8d341ef | 2013-03-26 09:03:27 -0700 | [diff] [blame] | 1982 | * @return true if some activity was finished (or would have finished if doit were true). |
| 1983 | */ |
Wale Ogunwale | 540e123 | 2015-05-01 15:35:39 -0700 | [diff] [blame] | 1984 | boolean finishDisabledPackageActivitiesLocked(String packageName, Set<String> filterByClasses, |
| 1985 | boolean doit, boolean evenPersistent, int userId) { |
Craig Mautner | 8d341ef | 2013-03-26 09:03:27 -0700 | [diff] [blame] | 1986 | boolean didSomething = false; |
Craig Mautner | e0a3884 | 2013-12-16 16:14:02 -0800 | [diff] [blame] | 1987 | for (int displayNdx = mActivityDisplays.size() - 1; displayNdx >= 0; --displayNdx) { |
Wale Ogunwale | a0f5b5e | 2017-10-11 09:37:23 -0700 | [diff] [blame] | 1988 | final ActivityDisplay display = mActivityDisplays.valueAt(displayNdx); |
| 1989 | for (int stackNdx = display.getChildCount() - 1; stackNdx >= 0; --stackNdx) { |
| 1990 | final ActivityStack stack = display.getChildAt(stackNdx); |
Wale Ogunwale | 540e123 | 2015-05-01 15:35:39 -0700 | [diff] [blame] | 1991 | if (stack.finishDisabledPackageActivitiesLocked( |
| 1992 | packageName, filterByClasses, doit, evenPersistent, userId)) { |
Craig Mautner | 4a1cb22 | 2013-12-04 16:14:06 -0800 | [diff] [blame] | 1993 | didSomething = true; |
| 1994 | } |
Craig Mautner | 8d341ef | 2013-03-26 09:03:27 -0700 | [diff] [blame] | 1995 | } |
| 1996 | } |
| 1997 | return didSomething; |
| 1998 | } |
| 1999 | |
Dianne Hackborn | a413dc0 | 2013-07-12 12:02:55 -0700 | [diff] [blame] | 2000 | void updatePreviousProcessLocked(ActivityRecord r) { |
| 2001 | // Now that this process has stopped, we may want to consider |
| 2002 | // it to be the previous app to try to keep around in case |
| 2003 | // the user wants to return to it. |
| 2004 | |
| 2005 | // First, found out what is currently the foreground app, so that |
| 2006 | // we don't blow away the previous app if this activity is being |
| 2007 | // hosted by the process that is actually still the foreground. |
| 2008 | ProcessRecord fgApp = null; |
Craig Mautner | e0a3884 | 2013-12-16 16:14:02 -0800 | [diff] [blame] | 2009 | for (int displayNdx = mActivityDisplays.size() - 1; displayNdx >= 0; --displayNdx) { |
Wale Ogunwale | a0f5b5e | 2017-10-11 09:37:23 -0700 | [diff] [blame] | 2010 | final ActivityDisplay display = mActivityDisplays.valueAt(displayNdx); |
| 2011 | for (int stackNdx = display.getChildCount() - 1; stackNdx >= 0; --stackNdx) { |
| 2012 | final ActivityStack stack = display.getChildAt(stackNdx); |
Wale Ogunwale | 1e60e0c | 2015-10-28 13:36:10 -0700 | [diff] [blame] | 2013 | if (isFocusedStack(stack)) { |
Craig Mautner | 4a1cb22 | 2013-12-04 16:14:06 -0800 | [diff] [blame] | 2014 | if (stack.mResumedActivity != null) { |
| 2015 | fgApp = stack.mResumedActivity.app; |
| 2016 | } else if (stack.mPausingActivity != null) { |
| 2017 | fgApp = stack.mPausingActivity.app; |
| 2018 | } |
| 2019 | break; |
Dianne Hackborn | a413dc0 | 2013-07-12 12:02:55 -0700 | [diff] [blame] | 2020 | } |
Dianne Hackborn | a413dc0 | 2013-07-12 12:02:55 -0700 | [diff] [blame] | 2021 | } |
| 2022 | } |
| 2023 | |
| 2024 | // Now set this one as the previous process, only if that really |
| 2025 | // makes sense to. |
| 2026 | if (r.app != null && fgApp != null && r.app != fgApp |
| 2027 | && r.lastVisibleTime > mService.mPreviousProcessVisibleTime |
Craig Mautner | 4ef2693 | 2013-09-18 15:15:52 -0700 | [diff] [blame] | 2028 | && r.app != mService.mHomeProcess) { |
Dianne Hackborn | a413dc0 | 2013-07-12 12:02:55 -0700 | [diff] [blame] | 2029 | mService.mPreviousProcess = r.app; |
| 2030 | mService.mPreviousProcessVisibleTime = r.lastVisibleTime; |
| 2031 | } |
| 2032 | } |
| 2033 | |
Wale Ogunwale | d046a01 | 2015-12-24 13:05:59 -0800 | [diff] [blame] | 2034 | boolean resumeFocusedStackTopActivityLocked() { |
| 2035 | return resumeFocusedStackTopActivityLocked(null, null, null); |
Craig Mautner | 05d2903 | 2013-05-03 13:40:13 -0700 | [diff] [blame] | 2036 | } |
| 2037 | |
Wale Ogunwale | d046a01 | 2015-12-24 13:05:59 -0800 | [diff] [blame] | 2038 | boolean resumeFocusedStackTopActivityLocked( |
Chong Zhang | 280d332 | 2015-11-03 17:27:26 -0800 | [diff] [blame] | 2039 | ActivityStack targetStack, ActivityRecord target, ActivityOptions targetOptions) { |
chaviw | 59b9885 | 2017-06-13 12:05:44 -0700 | [diff] [blame] | 2040 | |
| 2041 | if (!readyToResume()) { |
| 2042 | return false; |
| 2043 | } |
| 2044 | |
Wale Ogunwale | d046a01 | 2015-12-24 13:05:59 -0800 | [diff] [blame] | 2045 | if (targetStack != null && isFocusedStack(targetStack)) { |
| 2046 | return targetStack.resumeTopActivityUncheckedLocked(target, targetOptions); |
Craig Mautner | 05d2903 | 2013-05-03 13:40:13 -0700 | [diff] [blame] | 2047 | } |
chaviw | 59b9885 | 2017-06-13 12:05:44 -0700 | [diff] [blame] | 2048 | |
Wale Ogunwale | 06579d6 | 2016-04-30 15:29:06 -0700 | [diff] [blame] | 2049 | final ActivityRecord r = mFocusedStack.topRunningActivityLocked(); |
| 2050 | if (r == null || r.state != RESUMED) { |
| 2051 | mFocusedStack.resumeTopActivityUncheckedLocked(null, null); |
skuhne@google.com | 1b974dc | 2016-12-09 13:41:29 -0800 | [diff] [blame] | 2052 | } else if (r.state == RESUMED) { |
| 2053 | // Kick off any lingering app transitions form the MoveTaskToFront operation. |
| 2054 | mFocusedStack.executeAppTransition(targetOptions); |
Wale Ogunwale | 06579d6 | 2016-04-30 15:29:06 -0700 | [diff] [blame] | 2055 | } |
chaviw | 59b9885 | 2017-06-13 12:05:44 -0700 | [diff] [blame] | 2056 | |
Wale Ogunwale | d046a01 | 2015-12-24 13:05:59 -0800 | [diff] [blame] | 2057 | return false; |
Craig Mautner | 8d341ef | 2013-03-26 09:03:27 -0700 | [diff] [blame] | 2058 | } |
| 2059 | |
Todd Kennedy | 39bfee5 | 2016-02-24 10:28:21 -0800 | [diff] [blame] | 2060 | void updateActivityApplicationInfoLocked(ApplicationInfo aInfo) { |
| 2061 | for (int displayNdx = mActivityDisplays.size() - 1; displayNdx >= 0; --displayNdx) { |
Wale Ogunwale | a0f5b5e | 2017-10-11 09:37:23 -0700 | [diff] [blame] | 2062 | final ActivityDisplay display = mActivityDisplays.valueAt(displayNdx); |
| 2063 | for (int stackNdx = display.getChildCount() - 1; stackNdx >= 0; --stackNdx) { |
| 2064 | final ActivityStack stack = display.getChildAt(stackNdx); |
| 2065 | stack.updateActivityApplicationInfoLocked(aInfo); |
Todd Kennedy | 39bfee5 | 2016-02-24 10:28:21 -0800 | [diff] [blame] | 2066 | } |
| 2067 | } |
| 2068 | } |
| 2069 | |
Adrian Roos | 20d7df3 | 2016-01-12 18:59:43 +0100 | [diff] [blame] | 2070 | TaskRecord finishTopRunningActivityLocked(ProcessRecord app, String reason) { |
| 2071 | TaskRecord finishedTask = null; |
| 2072 | ActivityStack focusedStack = getFocusedStack(); |
Craig Mautner | e0a3884 | 2013-12-16 16:14:02 -0800 | [diff] [blame] | 2073 | for (int displayNdx = mActivityDisplays.size() - 1; displayNdx >= 0; --displayNdx) { |
Wale Ogunwale | a0f5b5e | 2017-10-11 09:37:23 -0700 | [diff] [blame] | 2074 | final ActivityDisplay display = mActivityDisplays.valueAt(displayNdx); |
| 2075 | final int numStacks = display.getChildCount(); |
Craig Mautner | 4a1cb22 | 2013-12-04 16:14:06 -0800 | [diff] [blame] | 2076 | for (int stackNdx = 0; stackNdx < numStacks; ++stackNdx) { |
Wale Ogunwale | a0f5b5e | 2017-10-11 09:37:23 -0700 | [diff] [blame] | 2077 | final ActivityStack stack = display.getChildAt(stackNdx); |
Adrian Roos | 20d7df3 | 2016-01-12 18:59:43 +0100 | [diff] [blame] | 2078 | TaskRecord t = stack.finishTopRunningActivityLocked(app, reason); |
| 2079 | if (stack == focusedStack || finishedTask == null) { |
| 2080 | finishedTask = t; |
| 2081 | } |
Craig Mautner | 4a1cb22 | 2013-12-04 16:14:06 -0800 | [diff] [blame] | 2082 | } |
Craig Mautner | 8d341ef | 2013-03-26 09:03:27 -0700 | [diff] [blame] | 2083 | } |
Adrian Roos | 20d7df3 | 2016-01-12 18:59:43 +0100 | [diff] [blame] | 2084 | return finishedTask; |
Craig Mautner | 8d341ef | 2013-03-26 09:03:27 -0700 | [diff] [blame] | 2085 | } |
| 2086 | |
Dianne Hackborn | 6ea0d0a | 2014-07-02 16:23:21 -0700 | [diff] [blame] | 2087 | void finishVoiceTask(IVoiceInteractionSession session) { |
| 2088 | for (int displayNdx = mActivityDisplays.size() - 1; displayNdx >= 0; --displayNdx) { |
Wale Ogunwale | a0f5b5e | 2017-10-11 09:37:23 -0700 | [diff] [blame] | 2089 | final ActivityDisplay display = mActivityDisplays.valueAt(displayNdx); |
| 2090 | final int numStacks = display.getChildCount(); |
Dianne Hackborn | 6ea0d0a | 2014-07-02 16:23:21 -0700 | [diff] [blame] | 2091 | for (int stackNdx = 0; stackNdx < numStacks; ++stackNdx) { |
Wale Ogunwale | a0f5b5e | 2017-10-11 09:37:23 -0700 | [diff] [blame] | 2092 | final ActivityStack stack = display.getChildAt(stackNdx); |
Dianne Hackborn | 6ea0d0a | 2014-07-02 16:23:21 -0700 | [diff] [blame] | 2093 | stack.finishVoiceTask(session); |
| 2094 | } |
| 2095 | } |
| 2096 | } |
| 2097 | |
Wale Ogunwale | 66e1685 | 2017-10-19 13:35:52 -0700 | [diff] [blame] | 2098 | void findTaskToMoveToFront(TaskRecord task, int flags, ActivityOptions options, |
Andrii Kulian | c2791664 | 2016-04-12 17:59:27 -0700 | [diff] [blame] | 2099 | String reason, boolean forceNonResizeable) { |
Wale Ogunwale | 66e1685 | 2017-10-19 13:35:52 -0700 | [diff] [blame] | 2100 | final ActivityStack currentStack = task.getStack(); |
| 2101 | if (currentStack == null) { |
| 2102 | Slog.e(TAG, "findTaskToMoveToFront: can't move task=" |
| 2103 | + task + " to front. Stack is null"); |
| 2104 | return; |
| 2105 | } |
| 2106 | |
Craig Mautner | aea74a5 | 2014-03-08 14:23:10 -0800 | [diff] [blame] | 2107 | if ((flags & ActivityManager.MOVE_TASK_NO_USER_ACTION) == 0) { |
| 2108 | mUserLeaving = true; |
Craig Mautner | 8d341ef | 2013-03-26 09:03:27 -0700 | [diff] [blame] | 2109 | } |
Wale Ogunwale | 66e1685 | 2017-10-19 13:35:52 -0700 | [diff] [blame] | 2110 | |
| 2111 | final ActivityRecord prev = topRunningActivityLocked(); |
| 2112 | |
| 2113 | if ((flags & ActivityManager.MOVE_TASK_WITH_HOME) != 0 |
| 2114 | || (prev != null && prev.isActivityTypeRecents())) { |
| 2115 | // Caller wants the home activity moved with it or the previous task is recents in which |
| 2116 | // case we always return home from the task we are moving to the front. |
| 2117 | moveHomeStackToFront("findTaskToMoveToFront"); |
Wale Ogunwale | 7d70117 | 2015-03-11 15:36:30 -0700 | [diff] [blame] | 2118 | } |
Chong Zhang | 0fa656b | 2015-08-31 15:17:21 -0700 | [diff] [blame] | 2119 | |
Wale Ogunwale | 0568aed | 2017-09-08 13:29:37 -0700 | [diff] [blame] | 2120 | if (task.isResizeable() && canUseActivityOptionsLaunchBounds(options)) { |
Bryce Lee | f3c6a47 | 2017-11-14 14:53:06 -0800 | [diff] [blame] | 2121 | final Rect bounds = options.getLaunchBounds(); |
Wale Ogunwale | 0568aed | 2017-09-08 13:29:37 -0700 | [diff] [blame] | 2122 | task.updateOverrideConfiguration(bounds); |
| 2123 | |
Wale Ogunwale | 04a05ac | 2017-09-17 21:35:02 -0700 | [diff] [blame] | 2124 | ActivityStack stack = getLaunchStack(null, options, task, ON_TOP); |
Wale Ogunwale | 0568aed | 2017-09-08 13:29:37 -0700 | [diff] [blame] | 2125 | |
Wale Ogunwale | 04a05ac | 2017-09-17 21:35:02 -0700 | [diff] [blame] | 2126 | if (stack != currentStack) { |
| 2127 | task.reparent(stack, ON_TOP, REPARENT_KEEP_STACK_AT_FRONT, !ANIMATE, DEFER_RESUME, |
Wale Ogunwale | 66e1685 | 2017-10-19 13:35:52 -0700 | [diff] [blame] | 2128 | "findTaskToMoveToFront"); |
Wale Ogunwale | 04a05ac | 2017-09-17 21:35:02 -0700 | [diff] [blame] | 2129 | stack = currentStack; |
Wale Ogunwale | 0568aed | 2017-09-08 13:29:37 -0700 | [diff] [blame] | 2130 | // moveTaskToStackUncheckedLocked() should already placed the task on top, |
| 2131 | // still need moveTaskToFrontLocked() below for any transition settings. |
| 2132 | } |
Wale Ogunwale | 44f036f | 2017-09-29 05:09:09 -0700 | [diff] [blame] | 2133 | if (stack.resizeStackWithLaunchBounds()) { |
| 2134 | resizeStackLocked(stack, bounds, null /* tempTaskBounds */, |
Wale Ogunwale | 04a05ac | 2017-09-17 21:35:02 -0700 | [diff] [blame] | 2135 | null /* tempTaskInsetBounds */, !PRESERVE_WINDOWS, |
| 2136 | true /* allowResizeInDockedMode */, !DEFER_RESUME); |
Wale Ogunwale | 0568aed | 2017-09-08 13:29:37 -0700 | [diff] [blame] | 2137 | } else { |
| 2138 | // WM resizeTask must be done after the task is moved to the correct stack, |
| 2139 | // because Task's setBounds() also updates dim layer's bounds, but that has |
| 2140 | // dependency on the stack. |
| 2141 | task.resizeWindowContainer(); |
Chong Zhang | 0fa656b | 2015-08-31 15:17:21 -0700 | [diff] [blame] | 2142 | } |
| 2143 | } |
| 2144 | |
Chong Zhang | db20b5f | 2015-10-23 14:01:43 -0700 | [diff] [blame] | 2145 | final ActivityRecord r = task.getTopActivity(); |
Andrii Kulian | 02b7a83 | 2016-10-06 23:11:56 -0700 | [diff] [blame] | 2146 | currentStack.moveTaskToFrontLocked(task, false /* noAnimation */, options, |
Chong Zhang | db20b5f | 2015-10-23 14:01:43 -0700 | [diff] [blame] | 2147 | r == null ? null : r.appTimeTracker, reason); |
| 2148 | |
Wale Ogunwale | ee006da | 2015-03-30 14:49:25 -0700 | [diff] [blame] | 2149 | if (DEBUG_STACK) Slog.d(TAG_STACK, |
Andrii Kulian | 02b7a83 | 2016-10-06 23:11:56 -0700 | [diff] [blame] | 2150 | "findTaskToMoveToFront: moved to front of stack=" + currentStack); |
Jorim Jaggi | 2adba07 | 2016-03-03 13:43:39 +0100 | [diff] [blame] | 2151 | |
Wale Ogunwale | 0568aed | 2017-09-08 13:29:37 -0700 | [diff] [blame] | 2152 | handleNonResizableTaskIfNeeded(task, WINDOWING_MODE_UNDEFINED, DEFAULT_DISPLAY, |
Wale Ogunwale | a0f5b5e | 2017-10-11 09:37:23 -0700 | [diff] [blame] | 2153 | currentStack, forceNonResizeable); |
Craig Mautner | 8d341ef | 2013-03-26 09:03:27 -0700 | [diff] [blame] | 2154 | } |
| 2155 | |
Wale Ogunwale | 0568aed | 2017-09-08 13:29:37 -0700 | [diff] [blame] | 2156 | boolean canUseActivityOptionsLaunchBounds(ActivityOptions options) { |
Wale Ogunwale | 7a8fa60 | 2015-11-18 15:56:57 -0800 | [diff] [blame] | 2157 | // 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] | 2158 | // window management or is launching into the pinned stack. |
Wale Ogunwale | 0568aed | 2017-09-08 13:29:37 -0700 | [diff] [blame] | 2159 | if (options == null || options.getLaunchBounds() == null) { |
Wale Ogunwale | 854809c | 2015-12-27 16:18:19 -0800 | [diff] [blame] | 2160 | return false; |
| 2161 | } |
Wale Ogunwale | 0568aed | 2017-09-08 13:29:37 -0700 | [diff] [blame] | 2162 | return (mService.mSupportsPictureInPicture |
| 2163 | && options.getLaunchWindowingMode() == WINDOWING_MODE_PINNED) |
Wale Ogunwale | 854809c | 2015-12-27 16:18:19 -0800 | [diff] [blame] | 2164 | || mService.mSupportsFreeformWindowManagement; |
Wale Ogunwale | 7a8fa60 | 2015-11-18 15:56:57 -0800 | [diff] [blame] | 2165 | } |
| 2166 | |
Bryce Lee | dacefc4 | 2017-10-10 12:56:02 -0700 | [diff] [blame] | 2167 | LaunchingBoundsController getLaunchingBoundsController() { |
| 2168 | return mLaunchingBoundsController; |
Bryce Lee | 9ad3eb3 | 2017-10-10 10:10:31 -0700 | [diff] [blame] | 2169 | } |
| 2170 | |
Winson Chung | 5589333 | 2017-02-17 17:13:10 -0800 | [diff] [blame] | 2171 | protected <T extends ActivityStack> T getStack(int stackId) { |
Wale Ogunwale | 9dcf946 | 2017-09-19 15:13:01 -0700 | [diff] [blame] | 2172 | for (int i = mActivityDisplays.size() - 1; i >= 0; --i) { |
| 2173 | final T stack = mActivityDisplays.valueAt(i).getStack(stackId); |
| 2174 | if (stack != null) { |
| 2175 | return stack; |
| 2176 | } |
| 2177 | } |
| 2178 | return null; |
Wale Ogunwale | ddc1cb2 | 2015-07-25 19:23:04 -0700 | [diff] [blame] | 2179 | } |
| 2180 | |
Wale Ogunwale | 6827856 | 2017-09-23 17:13:55 -0700 | [diff] [blame] | 2181 | /** @see ActivityDisplay#getStack(int, int) */ |
| 2182 | private <T extends ActivityStack> T getStack(int windowingMode, int activityType) { |
| 2183 | for (int i = mActivityDisplays.size() - 1; i >= 0; --i) { |
| 2184 | final T stack = mActivityDisplays.valueAt(i).getStack(windowingMode, activityType); |
| 2185 | if (stack != null) { |
| 2186 | return stack; |
| 2187 | } |
| 2188 | } |
| 2189 | return null; |
| 2190 | } |
| 2191 | |
Wale Ogunwale | 04a05ac | 2017-09-17 21:35:02 -0700 | [diff] [blame] | 2192 | int resolveActivityType(@Nullable ActivityRecord r, @Nullable ActivityOptions options, |
Wale Ogunwale | 0568aed | 2017-09-08 13:29:37 -0700 | [diff] [blame] | 2193 | @Nullable TaskRecord task) { |
Wale Ogunwale | 04a05ac | 2017-09-17 21:35:02 -0700 | [diff] [blame] | 2194 | // Preference is given to the activity type for the activity then the task since the type |
| 2195 | // once set shouldn't change. |
| 2196 | int activityType = r != null ? r.getActivityType() : ACTIVITY_TYPE_UNDEFINED; |
| 2197 | if (activityType == ACTIVITY_TYPE_UNDEFINED && task != null) { |
| 2198 | activityType = task.getActivityType(); |
| 2199 | } |
Wale Ogunwale | 0568aed | 2017-09-08 13:29:37 -0700 | [diff] [blame] | 2200 | if (activityType != ACTIVITY_TYPE_UNDEFINED) { |
| 2201 | return activityType; |
| 2202 | } |
Wale Ogunwale | ab5de37 | 2017-10-18 06:46:31 -0700 | [diff] [blame] | 2203 | if (options != null) { |
| 2204 | activityType = options.getLaunchActivityType(); |
| 2205 | } |
| 2206 | return activityType != ACTIVITY_TYPE_UNDEFINED ? activityType : ACTIVITY_TYPE_STANDARD; |
Wale Ogunwale | 0568aed | 2017-09-08 13:29:37 -0700 | [diff] [blame] | 2207 | } |
| 2208 | |
Wale Ogunwale | 04a05ac | 2017-09-17 21:35:02 -0700 | [diff] [blame] | 2209 | <T extends ActivityStack> T getLaunchStack(@Nullable ActivityRecord r, |
| 2210 | @Nullable ActivityOptions options, @Nullable TaskRecord candidateTask, boolean onTop) { |
| 2211 | return getLaunchStack(r, options, candidateTask, onTop, INVALID_DISPLAY); |
Wale Ogunwale | 0568aed | 2017-09-08 13:29:37 -0700 | [diff] [blame] | 2212 | } |
| 2213 | |
| 2214 | /** |
| 2215 | * Returns the right stack to use for launching factoring in all the input parameters. |
| 2216 | * |
| 2217 | * @param r The activity we are trying to launch. Can be null. |
| 2218 | * @param options The activity options used to the launch. Can be null. |
| 2219 | * @param candidateTask The possible task the activity might be launched in. Can be null. |
| 2220 | * |
| 2221 | * @return The stack to use for the launch or INVALID_STACK_ID. |
| 2222 | */ |
Wale Ogunwale | 04a05ac | 2017-09-17 21:35:02 -0700 | [diff] [blame] | 2223 | <T extends ActivityStack> T getLaunchStack(@Nullable ActivityRecord r, |
| 2224 | @Nullable ActivityOptions options, @Nullable TaskRecord candidateTask, boolean onTop, |
| 2225 | int candidateDisplayId) { |
Wale Ogunwale | 0568aed | 2017-09-08 13:29:37 -0700 | [diff] [blame] | 2226 | int taskId = INVALID_TASK_ID; |
| 2227 | int displayId = INVALID_DISPLAY; |
| 2228 | //Rect bounds = null; |
| 2229 | |
| 2230 | // We give preference to the launch preference in activity options. |
| 2231 | if (options != null) { |
| 2232 | taskId = options.getLaunchTaskId(); |
| 2233 | displayId = options.getLaunchDisplayId(); |
| 2234 | // TODO: Need to work this into the equation... |
| 2235 | //bounds = options.getLaunchBounds(); |
| 2236 | } |
| 2237 | |
| 2238 | // First preference for stack goes to the task Id set in the activity options. Use the stack |
| 2239 | // associated with that if possible. |
| 2240 | if (taskId != INVALID_TASK_ID) { |
| 2241 | // Temporarily set the task id to invalid in case in re-entry. |
| 2242 | options.setLaunchTaskId(INVALID_TASK_ID); |
| 2243 | final TaskRecord task = anyTaskForIdLocked(taskId, |
Wale Ogunwale | ab5de37 | 2017-10-18 06:46:31 -0700 | [diff] [blame] | 2244 | MATCH_TASK_IN_STACKS_OR_RECENT_TASKS_AND_RESTORE, options, onTop); |
Wale Ogunwale | 0568aed | 2017-09-08 13:29:37 -0700 | [diff] [blame] | 2245 | options.setLaunchTaskId(taskId); |
| 2246 | if (task != null) { |
Wale Ogunwale | 04a05ac | 2017-09-17 21:35:02 -0700 | [diff] [blame] | 2247 | return task.getStack(); |
Wale Ogunwale | 0568aed | 2017-09-08 13:29:37 -0700 | [diff] [blame] | 2248 | } |
| 2249 | } |
| 2250 | |
Wale Ogunwale | 0568aed | 2017-09-08 13:29:37 -0700 | [diff] [blame] | 2251 | final int activityType = resolveActivityType(r, options, candidateTask); |
Wale Ogunwale | 04a05ac | 2017-09-17 21:35:02 -0700 | [diff] [blame] | 2252 | T stack = null; |
Wale Ogunwale | 0568aed | 2017-09-08 13:29:37 -0700 | [diff] [blame] | 2253 | |
| 2254 | // Next preference for stack goes to the display Id set in the activity options or the |
| 2255 | // candidate display. |
| 2256 | if (displayId == INVALID_DISPLAY) { |
| 2257 | displayId = candidateDisplayId; |
| 2258 | } |
| 2259 | if (displayId != INVALID_DISPLAY) { |
| 2260 | if (r != null) { |
| 2261 | // TODO: This should also take in the windowing mode and activity type into account. |
Wale Ogunwale | 04a05ac | 2017-09-17 21:35:02 -0700 | [diff] [blame] | 2262 | stack = (T) getValidLaunchStackOnDisplay(displayId, r); |
Wale Ogunwale | 0568aed | 2017-09-08 13:29:37 -0700 | [diff] [blame] | 2263 | if (stack != null) { |
Wale Ogunwale | 04a05ac | 2017-09-17 21:35:02 -0700 | [diff] [blame] | 2264 | return stack; |
Wale Ogunwale | 0568aed | 2017-09-08 13:29:37 -0700 | [diff] [blame] | 2265 | } |
| 2266 | } |
| 2267 | final ActivityDisplay display = getActivityDisplayOrCreateLocked(displayId); |
| 2268 | if (display != null) { |
Wale Ogunwale | 7e1f5f5 | 2017-10-18 15:19:59 -0700 | [diff] [blame] | 2269 | stack = display.getOrCreateStack(r, options, candidateTask, activityType, onTop); |
Wale Ogunwale | ab5de37 | 2017-10-18 06:46:31 -0700 | [diff] [blame] | 2270 | if (stack != null) { |
| 2271 | return stack; |
Wale Ogunwale | 0568aed | 2017-09-08 13:29:37 -0700 | [diff] [blame] | 2272 | } |
Wale Ogunwale | 0568aed | 2017-09-08 13:29:37 -0700 | [diff] [blame] | 2273 | } |
| 2274 | } |
| 2275 | |
| 2276 | // Give preference to the stack and display of the input task and activity if they match the |
| 2277 | // mode we want to launch into. |
Wale Ogunwale | 04a05ac | 2017-09-17 21:35:02 -0700 | [diff] [blame] | 2278 | stack = null; |
| 2279 | ActivityDisplay display = null; |
Wale Ogunwale | 0568aed | 2017-09-08 13:29:37 -0700 | [diff] [blame] | 2280 | if (candidateTask != null) { |
| 2281 | stack = candidateTask.getStack(); |
| 2282 | } |
| 2283 | if (stack == null && r != null) { |
| 2284 | stack = r.getStack(); |
| 2285 | } |
| 2286 | if (stack != null) { |
Wale Ogunwale | 04a05ac | 2017-09-17 21:35:02 -0700 | [diff] [blame] | 2287 | display = stack.getDisplay(); |
Wale Ogunwale | 7e1f5f5 | 2017-10-18 15:19:59 -0700 | [diff] [blame] | 2288 | if (display != null) { |
| 2289 | final int windowingMode = |
| 2290 | display.resolveWindowingMode(r, options, candidateTask, activityType); |
| 2291 | if (stack.isCompatible(windowingMode, activityType)) { |
| 2292 | return stack; |
| 2293 | } |
| 2294 | } |
Wale Ogunwale | 0568aed | 2017-09-08 13:29:37 -0700 | [diff] [blame] | 2295 | } |
| 2296 | |
Wale Ogunwale | 04a05ac | 2017-09-17 21:35:02 -0700 | [diff] [blame] | 2297 | if (display == null |
| 2298 | // TODO: Can be removed once we figure-out how non-standard types should launch |
| 2299 | // outside the default display. |
| 2300 | || (activityType != ACTIVITY_TYPE_STANDARD |
| 2301 | && activityType != ACTIVITY_TYPE_UNDEFINED)) { |
| 2302 | display = getDefaultDisplay(); |
Wale Ogunwale | 0568aed | 2017-09-08 13:29:37 -0700 | [diff] [blame] | 2303 | } |
Wale Ogunwale | 04a05ac | 2017-09-17 21:35:02 -0700 | [diff] [blame] | 2304 | |
Wale Ogunwale | 7e1f5f5 | 2017-10-18 15:19:59 -0700 | [diff] [blame] | 2305 | return display.getOrCreateStack(r, options, candidateTask, activityType, onTop); |
Wale Ogunwale | 0568aed | 2017-09-08 13:29:37 -0700 | [diff] [blame] | 2306 | } |
| 2307 | |
Andrii Kulian | 16802aa | 2016-11-02 12:21:33 -0700 | [diff] [blame] | 2308 | /** |
| 2309 | * Get a topmost stack on the display, that is a valid launch stack for specified activity. |
| 2310 | * If there is no such stack, new dynamic stack can be created. |
| 2311 | * @param displayId Target display. |
| 2312 | * @param r Activity that should be launched there. |
| 2313 | * @return Existing stack if there is a valid one, new dynamic stack if it is valid or null. |
| 2314 | */ |
| 2315 | ActivityStack getValidLaunchStackOnDisplay(int displayId, @NonNull ActivityRecord r) { |
Andrii Kulian | 62e6f25 | 2017-05-30 22:46:53 -0700 | [diff] [blame] | 2316 | final ActivityDisplay activityDisplay = getActivityDisplayOrCreateLocked(displayId); |
Andrii Kulian | 16802aa | 2016-11-02 12:21:33 -0700 | [diff] [blame] | 2317 | if (activityDisplay == null) { |
| 2318 | throw new IllegalArgumentException( |
| 2319 | "Display with displayId=" + displayId + " not found."); |
| 2320 | } |
| 2321 | |
Wale Ogunwale | 04a05ac | 2017-09-17 21:35:02 -0700 | [diff] [blame] | 2322 | if (!r.canBeLaunchedOnDisplay(displayId)) { |
| 2323 | return null; |
| 2324 | } |
| 2325 | |
Andrii Kulian | 16802aa | 2016-11-02 12:21:33 -0700 | [diff] [blame] | 2326 | // Return the topmost valid stack on the display. |
Wale Ogunwale | a0f5b5e | 2017-10-11 09:37:23 -0700 | [diff] [blame] | 2327 | for (int i = activityDisplay.getChildCount() - 1; i >= 0; --i) { |
| 2328 | final ActivityStack stack = activityDisplay.getChildAt(i); |
Wale Ogunwale | 6827856 | 2017-09-23 17:13:55 -0700 | [diff] [blame] | 2329 | if (isValidLaunchStack(stack, displayId, r)) { |
Andrii Kulian | 16802aa | 2016-11-02 12:21:33 -0700 | [diff] [blame] | 2330 | return stack; |
| 2331 | } |
| 2332 | } |
| 2333 | |
| 2334 | // If there is no valid stack on the external display - check if new dynamic stack will do. |
Wale Ogunwale | 04a05ac | 2017-09-17 21:35:02 -0700 | [diff] [blame] | 2335 | if (displayId != DEFAULT_DISPLAY) { |
| 2336 | return activityDisplay.createStack( |
| 2337 | r.getWindowingMode(), r.getActivityType(), true /*onTop*/); |
Andrii Kulian | 16802aa | 2016-11-02 12:21:33 -0700 | [diff] [blame] | 2338 | } |
| 2339 | |
| 2340 | Slog.w(TAG, "getValidLaunchStackOnDisplay: can't launch on displayId " + displayId); |
| 2341 | return null; |
| 2342 | } |
| 2343 | |
Wale Ogunwale | 6827856 | 2017-09-23 17:13:55 -0700 | [diff] [blame] | 2344 | // TODO: Can probably be consolidated into getLaunchStack()... |
| 2345 | private boolean isValidLaunchStack(ActivityStack stack, int displayId, ActivityRecord r) { |
| 2346 | switch (stack.getActivityType()) { |
| 2347 | case ACTIVITY_TYPE_HOME: return r.isActivityTypeHome(); |
| 2348 | case ACTIVITY_TYPE_RECENTS: return r.isActivityTypeRecents(); |
| 2349 | case ACTIVITY_TYPE_ASSISTANT: return r.isActivityTypeAssistant(); |
Wale Ogunwale | 0568aed | 2017-09-08 13:29:37 -0700 | [diff] [blame] | 2350 | } |
Wale Ogunwale | 6827856 | 2017-09-23 17:13:55 -0700 | [diff] [blame] | 2351 | switch (stack.getWindowingMode()) { |
| 2352 | case WINDOWING_MODE_FULLSCREEN: return true; |
| 2353 | case WINDOWING_MODE_FREEFORM: return r.supportsFreeform(); |
| 2354 | case WINDOWING_MODE_PINNED: return r.supportsPictureInPicture(); |
| 2355 | case WINDOWING_MODE_SPLIT_SCREEN_PRIMARY: return r.supportsSplitScreenWindowingMode(); |
| 2356 | case WINDOWING_MODE_SPLIT_SCREEN_SECONDARY: return r.supportsSplitScreenWindowingMode(); |
| 2357 | } |
| 2358 | |
Wale Ogunwale | 44f036f | 2017-09-29 05:09:09 -0700 | [diff] [blame] | 2359 | if (!stack.isOnHomeDisplay()) { |
Wale Ogunwale | 6827856 | 2017-09-23 17:13:55 -0700 | [diff] [blame] | 2360 | return r.canBeLaunchedOnDisplay(displayId); |
| 2361 | } |
| 2362 | Slog.e(TAG, "isValidLaunchStack: Unexpected stack=" + stack); |
| 2363 | return false; |
Wale Ogunwale | 0568aed | 2017-09-08 13:29:37 -0700 | [diff] [blame] | 2364 | } |
| 2365 | |
Andrii Kulian | 7fc2281 | 2016-12-28 13:04:11 -0800 | [diff] [blame] | 2366 | /** |
| 2367 | * Get next focusable stack in the system. This will search across displays and stacks |
| 2368 | * in last-focused order for a focusable and visible stack, different from the target stack. |
| 2369 | * |
| 2370 | * @param currentFocus The stack that previously had focus and thus needs to be ignored when |
| 2371 | * searching for next candidate. |
| 2372 | * @return Next focusable {@link ActivityStack}, null if not found. |
| 2373 | */ |
| 2374 | ActivityStack getNextFocusableStackLocked(ActivityStack currentFocus) { |
| 2375 | mWindowManager.getDisplaysInFocusOrder(mTmpOrderedDisplayIds); |
| 2376 | |
| 2377 | for (int i = mTmpOrderedDisplayIds.size() - 1; i >= 0; --i) { |
| 2378 | final int displayId = mTmpOrderedDisplayIds.get(i); |
Andrii Kulian | 62e6f25 | 2017-05-30 22:46:53 -0700 | [diff] [blame] | 2379 | // If a display is registered in WM, it must also be available in AM. |
Wale Ogunwale | a0f5b5e | 2017-10-11 09:37:23 -0700 | [diff] [blame] | 2380 | final ActivityDisplay display = getActivityDisplayOrCreateLocked(displayId); |
| 2381 | for (int j = display.getChildCount() - 1; j >= 0; --j) { |
| 2382 | final ActivityStack stack = display.getChildAt(j); |
Wale Ogunwale | 04a05ac | 2017-09-17 21:35:02 -0700 | [diff] [blame] | 2383 | if (stack != currentFocus && stack.isFocusable() |
| 2384 | && stack.shouldBeVisible(null)) { |
Andrii Kulian | 7fc2281 | 2016-12-28 13:04:11 -0800 | [diff] [blame] | 2385 | return stack; |
| 2386 | } |
| 2387 | } |
| 2388 | } |
| 2389 | |
| 2390 | return null; |
| 2391 | } |
| 2392 | |
Andrii Kulian | a8fe3df | 2017-06-16 15:29:26 -0700 | [diff] [blame] | 2393 | /** |
| 2394 | * Get next valid stack for launching provided activity in the system. This will search across |
| 2395 | * displays and stacks in last-focused order for a focusable and visible stack, except those |
| 2396 | * that are on a currently focused display. |
| 2397 | * |
| 2398 | * @param r The activity that is being launched. |
| 2399 | * @param currentFocus The display that previously had focus and thus needs to be ignored when |
| 2400 | * searching for the next candidate. |
| 2401 | * @return Next valid {@link ActivityStack}, null if not found. |
| 2402 | */ |
| 2403 | ActivityStack getNextValidLaunchStackLocked(@NonNull ActivityRecord r, int currentFocus) { |
| 2404 | mWindowManager.getDisplaysInFocusOrder(mTmpOrderedDisplayIds); |
| 2405 | for (int i = mTmpOrderedDisplayIds.size() - 1; i >= 0; --i) { |
| 2406 | final int displayId = mTmpOrderedDisplayIds.get(i); |
| 2407 | if (displayId == currentFocus) { |
| 2408 | continue; |
| 2409 | } |
| 2410 | final ActivityStack stack = getValidLaunchStackOnDisplay(displayId, r); |
| 2411 | if (stack != null) { |
| 2412 | return stack; |
| 2413 | } |
| 2414 | } |
| 2415 | return null; |
| 2416 | } |
| 2417 | |
Craig Mautner | ee2e45a | 2014-06-27 12:10:03 -0700 | [diff] [blame] | 2418 | ActivityRecord getHomeActivity() { |
Craig Mautner | db49fec | 2015-05-21 15:33:30 -0700 | [diff] [blame] | 2419 | return getHomeActivityForUser(mCurrentUser); |
Fyodor Kupolov | b501330 | 2015-04-17 17:59:14 -0700 | [diff] [blame] | 2420 | } |
| 2421 | |
| 2422 | ActivityRecord getHomeActivityForUser(int userId) { |
Craig Mautner | 4a1cb22 | 2013-12-04 16:14:06 -0800 | [diff] [blame] | 2423 | final ArrayList<TaskRecord> tasks = mHomeStack.getAllTasks(); |
| 2424 | for (int taskNdx = tasks.size() - 1; taskNdx >= 0; --taskNdx) { |
| 2425 | final TaskRecord task = tasks.get(taskNdx); |
Wale Ogunwale | 6fbde9f | 2017-08-24 07:24:12 -0700 | [diff] [blame] | 2426 | if (task.isActivityTypeHome()) { |
Craig Mautner | 4a1cb22 | 2013-12-04 16:14:06 -0800 | [diff] [blame] | 2427 | final ArrayList<ActivityRecord> activities = task.mActivities; |
| 2428 | for (int activityNdx = activities.size() - 1; activityNdx >= 0; --activityNdx) { |
| 2429 | final ActivityRecord r = activities.get(activityNdx); |
Wale Ogunwale | 6fbde9f | 2017-08-24 07:24:12 -0700 | [diff] [blame] | 2430 | if (r.isActivityTypeHome() |
Fyodor Kupolov | b501330 | 2015-04-17 17:59:14 -0700 | [diff] [blame] | 2431 | && ((userId == UserHandle.USER_ALL) || (r.userId == userId))) { |
Craig Mautner | ee2e45a | 2014-06-27 12:10:03 -0700 | [diff] [blame] | 2432 | return r; |
Craig Mautner | 4a1cb22 | 2013-12-04 16:14:06 -0800 | [diff] [blame] | 2433 | } |
| 2434 | } |
| 2435 | } |
| 2436 | } |
| 2437 | return null; |
| 2438 | } |
| 2439 | |
Wale Ogunwale | 44f036f | 2017-09-29 05:09:09 -0700 | [diff] [blame] | 2440 | void resizeStackLocked(ActivityStack stack, Rect bounds, Rect tempTaskBounds, |
| 2441 | Rect tempTaskInsetBounds, boolean preserveWindows, boolean allowResizeInDockedMode, |
| 2442 | boolean deferResume) { |
| 2443 | |
| 2444 | if (stack.inSplitScreenPrimaryWindowingMode()) { |
Jorim Jaggi | dc249c4 | 2015-12-15 14:57:31 -0800 | [diff] [blame] | 2445 | resizeDockedStackLocked(bounds, tempTaskBounds, tempTaskInsetBounds, null, null, |
Andrii Kulian | db3e4ec | 2016-07-12 17:11:35 -0700 | [diff] [blame] | 2446 | preserveWindows, deferResume); |
Jorim Jaggi | dc249c4 | 2015-12-15 14:57:31 -0800 | [diff] [blame] | 2447 | return; |
| 2448 | } |
Wale Ogunwale | 9d3de4c | 2015-02-01 16:49:44 -0800 | [diff] [blame] | 2449 | |
Wale Ogunwale | a0f5b5e | 2017-10-11 09:37:23 -0700 | [diff] [blame] | 2450 | final boolean splitScreenActive = getDefaultDisplay().hasSplitScreenPrimaryStack(); |
Wale Ogunwale | 3382ab1 | 2017-07-27 08:55:03 -0700 | [diff] [blame] | 2451 | if (!allowResizeInDockedMode |
Wale Ogunwale | 926aade | 2017-08-29 11:24:37 -0700 | [diff] [blame] | 2452 | && !stack.getWindowConfiguration().tasksAreFloating() && splitScreenActive) { |
Winson Chung | a2249ac | 2017-03-30 18:15:30 -0700 | [diff] [blame] | 2453 | // If the docked stack exists, don't resize non-floating stacks independently of the |
| 2454 | // size computed from the docked stack size (otherwise they will be out of sync) |
Wale Ogunwale | ffc11bb | 2015-10-10 13:05:45 -0700 | [diff] [blame] | 2455 | return; |
| 2456 | } |
| 2457 | |
Wale Ogunwale | 44f036f | 2017-09-29 05:09:09 -0700 | [diff] [blame] | 2458 | Trace.traceBegin(TRACE_TAG_ACTIVITY_MANAGER, "am.resizeStack_" + stack.mStackId); |
Jorim Jaggi | c402520 | 2015-10-22 16:43:34 +0200 | [diff] [blame] | 2459 | mWindowManager.deferSurfaceLayout(); |
| 2460 | try { |
Wale Ogunwale | 2b07da8 | 2017-11-08 14:52:40 -0800 | [diff] [blame] | 2461 | if (stack.affectedBySplitScreenResize()) { |
Wale Ogunwale | 926aade | 2017-08-29 11:24:37 -0700 | [diff] [blame] | 2462 | if (bounds == null && stack.inSplitScreenWindowingMode()) { |
| 2463 | // null bounds = fullscreen windowing mode...at least for now. |
| 2464 | stack.setWindowingMode(WINDOWING_MODE_FULLSCREEN); |
| 2465 | } else if (splitScreenActive) { |
| 2466 | // If we are in split-screen mode and this stack support split-screen, then |
| 2467 | // it should be split-screen secondary mode. i.e. adjacent to the docked stack. |
| 2468 | stack.setWindowingMode(WINDOWING_MODE_SPLIT_SCREEN_SECONDARY); |
| 2469 | } |
| 2470 | } |
Wale Ogunwale | 1666e31 | 2016-12-16 11:27:18 -0800 | [diff] [blame] | 2471 | stack.resize(bounds, tempTaskBounds, tempTaskInsetBounds); |
Wale Ogunwale | c8da41e | 2016-04-16 13:27:23 -0700 | [diff] [blame] | 2472 | if (!deferResume) { |
Wale Ogunwale | db0fa12 | 2016-05-16 15:12:03 -0700 | [diff] [blame] | 2473 | stack.ensureVisibleActivitiesConfigurationLocked( |
| 2474 | stack.topRunningActivityLocked(), preserveWindows); |
Wale Ogunwale | c8da41e | 2016-04-16 13:27:23 -0700 | [diff] [blame] | 2475 | } |
Jorim Jaggi | c402520 | 2015-10-22 16:43:34 +0200 | [diff] [blame] | 2476 | } finally { |
| 2477 | mWindowManager.continueSurfaceLayout(); |
| 2478 | Trace.traceEnd(TRACE_TAG_ACTIVITY_MANAGER); |
Wale Ogunwale | e4a0c57 | 2015-06-30 08:40:31 -0700 | [diff] [blame] | 2479 | } |
| 2480 | } |
| 2481 | |
Wale Ogunwale | 6827856 | 2017-09-23 17:13:55 -0700 | [diff] [blame] | 2482 | private void deferUpdateBounds(int activityType) { |
| 2483 | final ActivityStack stack = getStack(WINDOWING_MODE_UNDEFINED, activityType); |
Jorim Jaggi | 192086e | 2016-03-11 17:17:03 +0100 | [diff] [blame] | 2484 | if (stack != null) { |
| 2485 | stack.deferUpdateBounds(); |
| 2486 | } |
| 2487 | } |
| 2488 | |
Wale Ogunwale | 6827856 | 2017-09-23 17:13:55 -0700 | [diff] [blame] | 2489 | private void continueUpdateBounds(int activityType) { |
| 2490 | final ActivityStack stack = getStack(WINDOWING_MODE_UNDEFINED, activityType); |
Jorim Jaggi | 192086e | 2016-03-11 17:17:03 +0100 | [diff] [blame] | 2491 | if (stack != null) { |
| 2492 | stack.continueUpdateBounds(); |
| 2493 | } |
| 2494 | } |
| 2495 | |
Jorim Jaggi | 0b46f3c | 2016-03-14 12:21:37 +0100 | [diff] [blame] | 2496 | void notifyAppTransitionDone() { |
Wale Ogunwale | 6827856 | 2017-09-23 17:13:55 -0700 | [diff] [blame] | 2497 | continueUpdateBounds(ACTIVITY_TYPE_RECENTS); |
Jorim Jaggi | 0b46f3c | 2016-03-14 12:21:37 +0100 | [diff] [blame] | 2498 | for (int i = mResizingTasksDuringAnimation.size() - 1; i >= 0; i--) { |
| 2499 | final int taskId = mResizingTasksDuringAnimation.valueAt(i); |
Wale Ogunwale | 0568aed | 2017-09-08 13:29:37 -0700 | [diff] [blame] | 2500 | final TaskRecord task = anyTaskForIdLocked(taskId, MATCH_TASK_IN_STACKS_ONLY); |
Wale Ogunwale | e1fe7fa2 | 2016-12-15 18:27:00 -0800 | [diff] [blame] | 2501 | if (task != null) { |
| 2502 | task.setTaskDockedResizing(false); |
Jorim Jaggi | 0b46f3c | 2016-03-14 12:21:37 +0100 | [diff] [blame] | 2503 | } |
| 2504 | } |
| 2505 | mResizingTasksDuringAnimation.clear(); |
| 2506 | } |
| 2507 | |
Wale Ogunwale | 04a05ac | 2017-09-17 21:35:02 -0700 | [diff] [blame] | 2508 | /** |
| 2509 | * 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] | 2510 | * Can do that once we are no longer using static stack ids. |
Wale Ogunwale | 04a05ac | 2017-09-17 21:35:02 -0700 | [diff] [blame] | 2511 | */ |
Wale Ogunwale | 9dcf946 | 2017-09-19 15:13:01 -0700 | [diff] [blame] | 2512 | private void moveTasksToFullscreenStackInSurfaceTransaction(ActivityStack fromStack, |
Wale Ogunwale | 04a05ac | 2017-09-17 21:35:02 -0700 | [diff] [blame] | 2513 | int toDisplayId, boolean onTop) { |
Robert Carr | 6914f08 | 2017-03-20 19:04:30 -0700 | [diff] [blame] | 2514 | |
Wale Ogunwale | c8da41e | 2016-04-16 13:27:23 -0700 | [diff] [blame] | 2515 | mWindowManager.deferSurfaceLayout(); |
| 2516 | try { |
Wale Ogunwale | 04a05ac | 2017-09-17 21:35:02 -0700 | [diff] [blame] | 2517 | final int windowingMode = fromStack.getWindowingMode(); |
| 2518 | final boolean inPinnedWindowingMode = windowingMode == WINDOWING_MODE_PINNED; |
| 2519 | final ActivityDisplay toDisplay = getActivityDisplay(toDisplayId); |
| 2520 | |
| 2521 | if (windowingMode == WINDOWING_MODE_SPLIT_SCREEN_PRIMARY) { |
Wale Ogunwale | 7e1f5f5 | 2017-10-18 15:19:59 -0700 | [diff] [blame] | 2522 | // Tell the display we are exiting split-screen mode. |
| 2523 | toDisplay.onExitingSplitScreenMode(); |
Wale Ogunwale | c8da41e | 2016-04-16 13:27:23 -0700 | [diff] [blame] | 2524 | // We are moving all tasks from the docked stack to the fullscreen stack, |
| 2525 | // which is dismissing the docked stack, so resize all other stacks to |
| 2526 | // fullscreen here already so we don't end up with resize trashing. |
Wale Ogunwale | a0f5b5e | 2017-10-11 09:37:23 -0700 | [diff] [blame] | 2527 | for (int i = toDisplay.getChildCount() - 1; i >= 0; --i) { |
| 2528 | final ActivityStack otherStack = toDisplay.getChildAt(i); |
Wale Ogunwale | 926aade | 2017-08-29 11:24:37 -0700 | [diff] [blame] | 2529 | if (!otherStack.inSplitScreenSecondaryWindowingMode()) { |
| 2530 | continue; |
| 2531 | } |
Wale Ogunwale | 44f036f | 2017-09-29 05:09:09 -0700 | [diff] [blame] | 2532 | resizeStackLocked(otherStack, null, null, null, PRESERVE_WINDOWS, |
Wale Ogunwale | 926aade | 2017-08-29 11:24:37 -0700 | [diff] [blame] | 2533 | true /* allowResizeInDockedMode */, DEFER_RESUME); |
Wale Ogunwale | c8da41e | 2016-04-16 13:27:23 -0700 | [diff] [blame] | 2534 | } |
| 2535 | |
| 2536 | // Also disable docked stack resizing since we have manually adjusted the |
| 2537 | // size of other stacks above and we don't want to trigger a docked stack |
| 2538 | // resize when we remove task from it below and it is detached from the |
| 2539 | // display because it no longer contains any tasks. |
| 2540 | mAllowDockedStackResize = false; |
Wale Ogunwale | 04a05ac | 2017-09-17 21:35:02 -0700 | [diff] [blame] | 2541 | } else if (inPinnedWindowingMode && onTop) { |
| 2542 | // Log if we are expanding the PiP to fullscreen |
| 2543 | MetricsLogger.action(mService.mContext, |
| 2544 | ACTION_PICTURE_IN_PICTURE_EXPANDED_TO_FULLSCREEN); |
Wale Ogunwale | c8da41e | 2016-04-16 13:27:23 -0700 | [diff] [blame] | 2545 | } |
Wale Ogunwale | 04a05ac | 2017-09-17 21:35:02 -0700 | [diff] [blame] | 2546 | |
Winson Chung | 5af42fc | 2017-03-24 17:11:33 -0700 | [diff] [blame] | 2547 | // If we are moving from the pinned stack, then the animation takes care of updating |
| 2548 | // the picture-in-picture mode. |
Wale Ogunwale | 04a05ac | 2017-09-17 21:35:02 -0700 | [diff] [blame] | 2549 | final boolean schedulePictureInPictureModeChange = inPinnedWindowingMode; |
Wale Ogunwale | 9dcf946 | 2017-09-19 15:13:01 -0700 | [diff] [blame] | 2550 | final ArrayList<TaskRecord> tasks = fromStack.getAllTasks(); |
Wale Ogunwale | 04a05ac | 2017-09-17 21:35:02 -0700 | [diff] [blame] | 2551 | |
Wale Ogunwale | 388945c | 2017-10-04 12:13:46 -0700 | [diff] [blame] | 2552 | if (!tasks.isEmpty()) { |
Wale Ogunwale | 7e1f5f5 | 2017-10-18 15:19:59 -0700 | [diff] [blame] | 2553 | mTmpOptions.setLaunchWindowingMode(WINDOWING_MODE_FULLSCREEN); |
Wale Ogunwale | 388945c | 2017-10-04 12:13:46 -0700 | [diff] [blame] | 2554 | final int size = tasks.size(); |
Wale Ogunwale | 7e1f5f5 | 2017-10-18 15:19:59 -0700 | [diff] [blame] | 2555 | for (int i = 0; i < size; ++i) { |
| 2556 | final TaskRecord task = tasks.get(i); |
| 2557 | final ActivityStack toStack = toDisplay.getOrCreateStack( |
| 2558 | null, mTmpOptions, task, task.getActivityType(), onTop); |
Wale Ogunwale | 388945c | 2017-10-04 12:13:46 -0700 | [diff] [blame] | 2559 | |
Wale Ogunwale | 7e1f5f5 | 2017-10-18 15:19:59 -0700 | [diff] [blame] | 2560 | if (onTop) { |
Wale Ogunwale | 388945c | 2017-10-04 12:13:46 -0700 | [diff] [blame] | 2561 | final boolean isTopTask = i == (size - 1); |
Wale Ogunwale | 388945c | 2017-10-04 12:13:46 -0700 | [diff] [blame] | 2562 | // 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] | 2563 | task.reparent(toStack, ON_TOP, REPARENT_MOVE_STACK_TO_FRONT, |
Wale Ogunwale | 388945c | 2017-10-04 12:13:46 -0700 | [diff] [blame] | 2564 | isTopTask /* animate */, DEFER_RESUME, |
| 2565 | schedulePictureInPictureModeChange, |
| 2566 | "moveTasksToFullscreenStack - onTop"); |
Wale Ogunwale | 7e1f5f5 | 2017-10-18 15:19:59 -0700 | [diff] [blame] | 2567 | } else { |
Wale Ogunwale | 388945c | 2017-10-04 12:13:46 -0700 | [diff] [blame] | 2568 | // Position the tasks in the fullscreen stack in order at the bottom of the |
| 2569 | // stack. Also defer resume until all the tasks have been moved to the |
| 2570 | // fullscreen stack. |
Wale Ogunwale | 7e1f5f5 | 2017-10-18 15:19:59 -0700 | [diff] [blame] | 2571 | task.reparent(toStack, ON_TOP, |
Wale Ogunwale | 388945c | 2017-10-04 12:13:46 -0700 | [diff] [blame] | 2572 | REPARENT_LEAVE_STACK_IN_PLACE, !ANIMATE, DEFER_RESUME, |
| 2573 | schedulePictureInPictureModeChange, |
| 2574 | "moveTasksToFullscreenStack - NOT_onTop"); |
| 2575 | } |
Wale Ogunwale | c8da41e | 2016-04-16 13:27:23 -0700 | [diff] [blame] | 2576 | } |
| 2577 | } |
Winson Chung | 7466610 | 2017-02-22 17:49:24 -0800 | [diff] [blame] | 2578 | |
| 2579 | ensureActivitiesVisibleLocked(null, 0, PRESERVE_WINDOWS); |
| 2580 | resumeFocusedStackTopActivityLocked(); |
Wale Ogunwale | c8da41e | 2016-04-16 13:27:23 -0700 | [diff] [blame] | 2581 | } finally { |
| 2582 | mAllowDockedStackResize = true; |
| 2583 | mWindowManager.continueSurfaceLayout(); |
| 2584 | } |
| 2585 | } |
| 2586 | |
Wale Ogunwale | 9dcf946 | 2017-09-19 15:13:01 -0700 | [diff] [blame] | 2587 | void moveTasksToFullscreenStackLocked(ActivityStack fromStack, boolean onTop) { |
Wale Ogunwale | 04a05ac | 2017-09-17 21:35:02 -0700 | [diff] [blame] | 2588 | moveTasksToFullscreenStackLocked(fromStack, DEFAULT_DISPLAY, onTop); |
| 2589 | } |
| 2590 | |
| 2591 | void moveTasksToFullscreenStackLocked(ActivityStack fromStack, int toDisplayId, boolean onTop) { |
| 2592 | mWindowManager.inSurfaceTransaction(() -> |
| 2593 | moveTasksToFullscreenStackInSurfaceTransaction(fromStack, toDisplayId, onTop)); |
Robert Carr | 6914f08 | 2017-03-20 19:04:30 -0700 | [diff] [blame] | 2594 | } |
| 2595 | |
Jorim Jaggi | dc249c4 | 2015-12-15 14:57:31 -0800 | [diff] [blame] | 2596 | void resizeDockedStackLocked(Rect dockedBounds, Rect tempDockedTaskBounds, |
Andrii Kulian | db3e4ec | 2016-07-12 17:11:35 -0700 | [diff] [blame] | 2597 | Rect tempDockedTaskInsetBounds, Rect tempOtherTaskBounds, Rect tempOtherTaskInsetBounds, |
| 2598 | boolean preserveWindows) { |
| 2599 | resizeDockedStackLocked(dockedBounds, tempDockedTaskBounds, tempDockedTaskInsetBounds, |
| 2600 | tempOtherTaskBounds, tempOtherTaskInsetBounds, preserveWindows, |
| 2601 | false /* deferResume */); |
| 2602 | } |
| 2603 | |
Wale Ogunwale | 04a05ac | 2017-09-17 21:35:02 -0700 | [diff] [blame] | 2604 | private void resizeDockedStackLocked(Rect dockedBounds, Rect tempDockedTaskBounds, |
Andrii Kulian | db3e4ec | 2016-07-12 17:11:35 -0700 | [diff] [blame] | 2605 | Rect tempDockedTaskInsetBounds, Rect tempOtherTaskBounds, Rect tempOtherTaskInsetBounds, |
| 2606 | boolean preserveWindows, boolean deferResume) { |
Wale Ogunwale | c8da41e | 2016-04-16 13:27:23 -0700 | [diff] [blame] | 2607 | |
| 2608 | if (!mAllowDockedStackResize) { |
| 2609 | // Docked stack resize currently disabled. |
| 2610 | return; |
| 2611 | } |
| 2612 | |
Wale Ogunwale | a0f5b5e | 2017-10-11 09:37:23 -0700 | [diff] [blame] | 2613 | final ActivityStack stack = getDefaultDisplay().getSplitScreenPrimaryStack(); |
Jorim Jaggi | dc249c4 | 2015-12-15 14:57:31 -0800 | [diff] [blame] | 2614 | if (stack == null) { |
| 2615 | Slog.w(TAG, "resizeDockedStackLocked: docked stack not found"); |
| 2616 | return; |
| 2617 | } |
| 2618 | |
| 2619 | Trace.traceBegin(TRACE_TAG_ACTIVITY_MANAGER, "am.resizeDockedStack"); |
| 2620 | mWindowManager.deferSurfaceLayout(); |
| 2621 | try { |
Wale Ogunwale | c8da41e | 2016-04-16 13:27:23 -0700 | [diff] [blame] | 2622 | // Don't allow re-entry while resizing. E.g. due to docked stack detaching. |
| 2623 | mAllowDockedStackResize = false; |
Jorim Jaggi | dc249c4 | 2015-12-15 14:57:31 -0800 | [diff] [blame] | 2624 | ActivityRecord r = stack.topRunningActivityLocked(); |
Wale Ogunwale | 1666e31 | 2016-12-16 11:27:18 -0800 | [diff] [blame] | 2625 | stack.resize(dockedBounds, tempDockedTaskBounds, tempDockedTaskInsetBounds); |
Jorim Jaggi | dc249c4 | 2015-12-15 14:57:31 -0800 | [diff] [blame] | 2626 | |
Andrii Kulian | 69fb5e4 | 2016-04-05 16:47:29 -0700 | [diff] [blame] | 2627 | // TODO: Checking for isAttached might not be needed as if the user passes in null |
| 2628 | // dockedBounds then they want the docked stack to be dismissed. |
Bryce Lee | f3c6a47 | 2017-11-14 14:53:06 -0800 | [diff] [blame] | 2629 | if (stack.getWindowingMode() == WINDOWING_MODE_FULLSCREEN |
| 2630 | || (dockedBounds == null && !stack.isAttached())) { |
Andrii Kulian | 69fb5e4 | 2016-04-05 16:47:29 -0700 | [diff] [blame] | 2631 | // 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] | 2632 | // In this case we make all other static stacks fullscreen and move all |
| 2633 | // docked stack tasks to the fullscreen stack. |
Wale Ogunwale | 9dcf946 | 2017-09-19 15:13:01 -0700 | [diff] [blame] | 2634 | moveTasksToFullscreenStackLocked(stack, ON_TOP); |
Jorim Jaggi | dc249c4 | 2015-12-15 14:57:31 -0800 | [diff] [blame] | 2635 | |
| 2636 | // stack shouldn't contain anymore activities, so nothing to resume. |
| 2637 | r = null; |
| 2638 | } else { |
| 2639 | // Docked stacks occupy a dedicated region on screen so the size of all other |
| 2640 | // static stacks need to be adjusted so they don't overlap with the docked stack. |
| 2641 | // We get the bounds to use from window manager which has been adjusted for any |
| 2642 | // screen controls and is also the same for all stacks. |
Wale Ogunwale | a0f5b5e | 2017-10-11 09:37:23 -0700 | [diff] [blame] | 2643 | final ActivityDisplay display = getDefaultDisplay(); |
Matthew Ng | aa2b620 | 2017-02-10 14:48:21 -0800 | [diff] [blame] | 2644 | final Rect otherTaskRect = new Rect(); |
Wale Ogunwale | a0f5b5e | 2017-10-11 09:37:23 -0700 | [diff] [blame] | 2645 | for (int i = display.getChildCount() - 1; i >= 0; --i) { |
| 2646 | final ActivityStack current = display.getChildAt(i); |
Wale Ogunwale | 04a05ac | 2017-09-17 21:35:02 -0700 | [diff] [blame] | 2647 | if (current.getWindowingMode() == WINDOWING_MODE_SPLIT_SCREEN_PRIMARY) { |
Wale Ogunwale | 926aade | 2017-08-29 11:24:37 -0700 | [diff] [blame] | 2648 | continue; |
Jorim Jaggi | dc249c4 | 2015-12-15 14:57:31 -0800 | [diff] [blame] | 2649 | } |
Wale Ogunwale | 2b07da8 | 2017-11-08 14:52:40 -0800 | [diff] [blame] | 2650 | if (!current.affectedBySplitScreenResize()) { |
Wale Ogunwale | 926aade | 2017-08-29 11:24:37 -0700 | [diff] [blame] | 2651 | continue; |
| 2652 | } |
| 2653 | // Need to set windowing mode here before we try to get the dock bounds. |
| 2654 | current.setWindowingMode(WINDOWING_MODE_SPLIT_SCREEN_SECONDARY); |
| 2655 | current.getStackDockedModeBounds( |
| 2656 | tempOtherTaskBounds /* currentTempTaskBounds */, |
| 2657 | tempRect /* outStackBounds */, |
| 2658 | otherTaskRect /* outTempTaskBounds */, true /* ignoreVisibility */); |
| 2659 | |
Wale Ogunwale | 44f036f | 2017-09-29 05:09:09 -0700 | [diff] [blame] | 2660 | resizeStackLocked(current, !tempRect.isEmpty() ? tempRect : null, |
Wale Ogunwale | 926aade | 2017-08-29 11:24:37 -0700 | [diff] [blame] | 2661 | !otherTaskRect.isEmpty() ? otherTaskRect : tempOtherTaskBounds, |
| 2662 | tempOtherTaskInsetBounds, preserveWindows, |
| 2663 | true /* allowResizeInDockedMode */, deferResume); |
Jorim Jaggi | dc249c4 | 2015-12-15 14:57:31 -0800 | [diff] [blame] | 2664 | } |
| 2665 | } |
Andrii Kulian | db3e4ec | 2016-07-12 17:11:35 -0700 | [diff] [blame] | 2666 | if (!deferResume) { |
| 2667 | stack.ensureVisibleActivitiesConfigurationLocked(r, preserveWindows); |
| 2668 | } |
Jorim Jaggi | dc249c4 | 2015-12-15 14:57:31 -0800 | [diff] [blame] | 2669 | } finally { |
Wale Ogunwale | c8da41e | 2016-04-16 13:27:23 -0700 | [diff] [blame] | 2670 | mAllowDockedStackResize = true; |
Jorim Jaggi | dc249c4 | 2015-12-15 14:57:31 -0800 | [diff] [blame] | 2671 | mWindowManager.continueSurfaceLayout(); |
| 2672 | Trace.traceEnd(TRACE_TAG_ACTIVITY_MANAGER); |
| 2673 | } |
Jorim Jaggi | dc249c4 | 2015-12-15 14:57:31 -0800 | [diff] [blame] | 2674 | } |
| 2675 | |
Robert Carr | 0d00c2e | 2016-02-29 17:45:02 -0800 | [diff] [blame] | 2676 | void resizePinnedStackLocked(Rect pinnedBounds, Rect tempPinnedTaskBounds) { |
Wale Ogunwale | 04a05ac | 2017-09-17 21:35:02 -0700 | [diff] [blame] | 2677 | // TODO(multi-display): Pinned stack display should be passed in. |
Wale Ogunwale | a0f5b5e | 2017-10-11 09:37:23 -0700 | [diff] [blame] | 2678 | final PinnedActivityStack stack = getDefaultDisplay().getPinnedStack(); |
Robert Carr | 0d00c2e | 2016-02-29 17:45:02 -0800 | [diff] [blame] | 2679 | if (stack == null) { |
| 2680 | Slog.w(TAG, "resizePinnedStackLocked: pinned stack not found"); |
| 2681 | return; |
| 2682 | } |
Winson Chung | 19953ca | 2017-04-11 11:19:23 -0700 | [diff] [blame] | 2683 | |
| 2684 | // It is possible for the bounds animation from the WM to call this but be delayed by |
| 2685 | // another AM call that is holding the AMS lock. In such a case, the pinnedBounds may be |
| 2686 | // incorrect if AMS.resizeStackWithBoundsFromWindowManager() is already called while waiting |
| 2687 | // for the AMS lock to be freed. So check and make sure these bounds are still good. |
| 2688 | final PinnedStackWindowController stackController = stack.getWindowContainerController(); |
Winson Chung | 8bca9e4 | 2017-04-16 15:59:43 -0700 | [diff] [blame] | 2689 | if (stackController.pinnedStackResizeDisallowed()) { |
Winson Chung | 19953ca | 2017-04-11 11:19:23 -0700 | [diff] [blame] | 2690 | return; |
| 2691 | } |
| 2692 | |
Robert Carr | 0d00c2e | 2016-02-29 17:45:02 -0800 | [diff] [blame] | 2693 | Trace.traceBegin(TRACE_TAG_ACTIVITY_MANAGER, "am.resizePinnedStack"); |
| 2694 | mWindowManager.deferSurfaceLayout(); |
| 2695 | try { |
| 2696 | ActivityRecord r = stack.topRunningActivityLocked(); |
Robert Carr | 7e4c90e | 2017-02-15 19:52:38 -0800 | [diff] [blame] | 2697 | Rect insetBounds = null; |
| 2698 | if (tempPinnedTaskBounds != null) { |
| 2699 | // We always use 0,0 as the position for the inset rect because |
| 2700 | // if we are getting insets at all in the pinned stack it must mean |
| 2701 | // we are headed for fullscreen. |
| 2702 | insetBounds = tempRect; |
| 2703 | insetBounds.top = 0; |
| 2704 | insetBounds.left = 0; |
| 2705 | insetBounds.right = tempPinnedTaskBounds.width(); |
| 2706 | insetBounds.bottom = tempPinnedTaskBounds.height(); |
| 2707 | } |
| 2708 | stack.resize(pinnedBounds, tempPinnedTaskBounds, insetBounds); |
Wale Ogunwale | db0fa12 | 2016-05-16 15:12:03 -0700 | [diff] [blame] | 2709 | stack.ensureVisibleActivitiesConfigurationLocked(r, false); |
Robert Carr | 0d00c2e | 2016-02-29 17:45:02 -0800 | [diff] [blame] | 2710 | } finally { |
| 2711 | mWindowManager.continueSurfaceLayout(); |
| 2712 | Trace.traceEnd(TRACE_TAG_ACTIVITY_MANAGER); |
| 2713 | } |
| 2714 | } |
| 2715 | |
Wale Ogunwale | a0f5b5e | 2017-10-11 09:37:23 -0700 | [diff] [blame] | 2716 | private void removeStackInSurfaceTransaction(ActivityStack stack) { |
Winson Chung | 010927a | 2016-12-15 16:12:35 -0800 | [diff] [blame] | 2717 | final ArrayList<TaskRecord> tasks = stack.getAllTasks(); |
Wale Ogunwale | 04a05ac | 2017-09-17 21:35:02 -0700 | [diff] [blame] | 2718 | if (stack.getWindowingMode() == WINDOWING_MODE_PINNED) { |
Winson Chung | 4790065 | 2017-04-06 18:44:25 -0700 | [diff] [blame] | 2719 | /** |
| 2720 | * Workaround: Force-stop all the activities in the pinned stack before we reparent them |
| 2721 | * to the fullscreen stack. This is to guarantee that when we are removing a stack, |
| 2722 | * that the client receives onStop() before it is reparented. We do this by detaching |
| 2723 | * the stack from the display so that it will be considered invisible when |
| 2724 | * ensureActivitiesVisibleLocked() is called, and all of its activitys will be marked |
| 2725 | * invisible as well and added to the stopping list. After which we process the |
| 2726 | * stopping list by handling the idle. |
| 2727 | */ |
| 2728 | final PinnedActivityStack pinnedStack = (PinnedActivityStack) stack; |
| 2729 | pinnedStack.mForceHidden = true; |
| 2730 | pinnedStack.ensureActivitiesVisibleLocked(null, 0, PRESERVE_WINDOWS); |
| 2731 | pinnedStack.mForceHidden = false; |
| 2732 | activityIdleInternalLocked(null, false /* fromTimeout */, |
| 2733 | true /* processPausingActivites */, null /* configuration */); |
| 2734 | |
| 2735 | // Move all the tasks to the bottom of the fullscreen stack |
Wale Ogunwale | 9dcf946 | 2017-09-19 15:13:01 -0700 | [diff] [blame] | 2736 | moveTasksToFullscreenStackLocked(pinnedStack, !ON_TOP); |
Winson Chung | 010927a | 2016-12-15 16:12:35 -0800 | [diff] [blame] | 2737 | } else { |
| 2738 | for (int i = tasks.size() - 1; i >= 0; i--) { |
| 2739 | removeTaskByIdLocked(tasks.get(i).taskId, true /* killProcess */, |
| 2740 | REMOVE_FROM_RECENTS); |
| 2741 | } |
| 2742 | } |
| 2743 | } |
| 2744 | |
| 2745 | /** |
Wale Ogunwale | a0f5b5e | 2017-10-11 09:37:23 -0700 | [diff] [blame] | 2746 | * 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] | 2747 | * pinned stack, then its tasks are not explicitly removed when the stack is destroyed, but |
| 2748 | * instead moved back onto the fullscreen stack. |
| 2749 | */ |
Wale Ogunwale | a0f5b5e | 2017-10-11 09:37:23 -0700 | [diff] [blame] | 2750 | void removeStack(ActivityStack stack) { |
| 2751 | mWindowManager.inSurfaceTransaction(() -> removeStackInSurfaceTransaction(stack)); |
Wale Ogunwale | 04a05ac | 2017-09-17 21:35:02 -0700 | [diff] [blame] | 2752 | } |
| 2753 | |
Wale Ogunwale | 6827856 | 2017-09-23 17:13:55 -0700 | [diff] [blame] | 2754 | /** |
| 2755 | * Removes stacks in the input windowing modes from the system if they are of activity type |
| 2756 | * ACTIVITY_TYPE_STANDARD or ACTIVITY_TYPE_UNDEFINED |
| 2757 | */ |
| 2758 | void removeStacksInWindowingModes(int... windowingModes) { |
Wale Ogunwale | 04a05ac | 2017-09-17 21:35:02 -0700 | [diff] [blame] | 2759 | for (int i = mActivityDisplays.size() - 1; i >= 0; --i) { |
Wale Ogunwale | 6827856 | 2017-09-23 17:13:55 -0700 | [diff] [blame] | 2760 | mActivityDisplays.valueAt(i).removeStacksInWindowingModes(windowingModes); |
| 2761 | } |
| 2762 | } |
| 2763 | |
| 2764 | void removeStacksWithActivityTypes(int... activityTypes) { |
| 2765 | for (int i = mActivityDisplays.size() - 1; i >= 0; --i) { |
| 2766 | mActivityDisplays.valueAt(i).removeStacksWithActivityTypes(activityTypes); |
Wale Ogunwale | 04a05ac | 2017-09-17 21:35:02 -0700 | [diff] [blame] | 2767 | } |
Robert Carr | 6914f08 | 2017-03-20 19:04:30 -0700 | [diff] [blame] | 2768 | } |
| 2769 | |
| 2770 | /** |
Winson Chung | 6954fc9 | 2017-03-24 16:22:12 -0700 | [diff] [blame] | 2771 | * See {@link #removeTaskByIdLocked(int, boolean, boolean, boolean)} |
| 2772 | */ |
| 2773 | boolean removeTaskByIdLocked(int taskId, boolean killProcess, boolean removeFromRecents) { |
| 2774 | return removeTaskByIdLocked(taskId, killProcess, removeFromRecents, !PAUSE_IMMEDIATELY); |
| 2775 | } |
| 2776 | |
| 2777 | /** |
Winson Chung | 010927a | 2016-12-15 16:12:35 -0800 | [diff] [blame] | 2778 | * Removes the task with the specified task id. |
| 2779 | * |
| 2780 | * @param taskId Identifier of the task to be removed. |
| 2781 | * @param killProcess Kill any process associated with the task if possible. |
| 2782 | * @param removeFromRecents Whether to also remove the task from recents. |
Winson Chung | 6954fc9 | 2017-03-24 16:22:12 -0700 | [diff] [blame] | 2783 | * @param pauseImmediately Pauses all task activities immediately without waiting for the |
| 2784 | * pause-complete callback from the activity. |
Winson Chung | 010927a | 2016-12-15 16:12:35 -0800 | [diff] [blame] | 2785 | * @return Returns true if the given task was found and removed. |
| 2786 | */ |
Winson Chung | 6954fc9 | 2017-03-24 16:22:12 -0700 | [diff] [blame] | 2787 | boolean removeTaskByIdLocked(int taskId, boolean killProcess, boolean removeFromRecents, |
| 2788 | boolean pauseImmediately) { |
Wale Ogunwale | 0568aed | 2017-09-08 13:29:37 -0700 | [diff] [blame] | 2789 | final TaskRecord tr = anyTaskForIdLocked(taskId, MATCH_TASK_IN_STACKS_OR_RECENT_TASKS); |
Winson Chung | 010927a | 2016-12-15 16:12:35 -0800 | [diff] [blame] | 2790 | if (tr != null) { |
Winson Chung | 6954fc9 | 2017-03-24 16:22:12 -0700 | [diff] [blame] | 2791 | tr.removeTaskActivitiesLocked(pauseImmediately); |
Winson Chung | 010927a | 2016-12-15 16:12:35 -0800 | [diff] [blame] | 2792 | cleanUpRemovedTaskLocked(tr, killProcess, removeFromRecents); |
Charles He | ff9b4dff | 2017-09-22 10:18:37 +0100 | [diff] [blame] | 2793 | mService.mLockTaskController.clearLockedTask(tr); |
Winson Chung | 010927a | 2016-12-15 16:12:35 -0800 | [diff] [blame] | 2794 | if (tr.isPersistable) { |
| 2795 | mService.notifyTaskPersisterLocked(null, true); |
| 2796 | } |
| 2797 | return true; |
| 2798 | } |
| 2799 | Slog.w(TAG, "Request to remove task ignored for non-existent task " + taskId); |
| 2800 | return false; |
| 2801 | } |
| 2802 | |
| 2803 | void cleanUpRemovedTaskLocked(TaskRecord tr, boolean killProcess, boolean removeFromRecents) { |
| 2804 | if (removeFromRecents) { |
Winson Chung | 1dbc811 | 2017-09-28 18:05:31 -0700 | [diff] [blame] | 2805 | mRecentTasks.remove(tr); |
Winson Chung | 010927a | 2016-12-15 16:12:35 -0800 | [diff] [blame] | 2806 | } |
| 2807 | ComponentName component = tr.getBaseIntent().getComponent(); |
| 2808 | if (component == null) { |
| 2809 | Slog.w(TAG, "No component for base intent of task: " + tr); |
| 2810 | return; |
| 2811 | } |
| 2812 | |
| 2813 | // Find any running services associated with this app and stop if needed. |
| 2814 | mService.mServices.cleanUpRemovedTaskLocked(tr, component, new Intent(tr.getBaseIntent())); |
| 2815 | |
| 2816 | if (!killProcess) { |
| 2817 | return; |
| 2818 | } |
| 2819 | |
| 2820 | // Determine if the process(es) for this task should be killed. |
| 2821 | final String pkg = component.getPackageName(); |
| 2822 | ArrayList<ProcessRecord> procsToKill = new ArrayList<>(); |
| 2823 | ArrayMap<String, SparseArray<ProcessRecord>> pmap = mService.mProcessNames.getMap(); |
| 2824 | for (int i = 0; i < pmap.size(); i++) { |
| 2825 | |
| 2826 | SparseArray<ProcessRecord> uids = pmap.valueAt(i); |
| 2827 | for (int j = 0; j < uids.size(); j++) { |
| 2828 | ProcessRecord proc = uids.valueAt(j); |
| 2829 | if (proc.userId != tr.userId) { |
| 2830 | // Don't kill process for a different user. |
| 2831 | continue; |
| 2832 | } |
| 2833 | if (proc == mService.mHomeProcess) { |
| 2834 | // Don't kill the home process along with tasks from the same package. |
| 2835 | continue; |
| 2836 | } |
| 2837 | if (!proc.pkgList.containsKey(pkg)) { |
| 2838 | // Don't kill process that is not associated with this task. |
| 2839 | continue; |
| 2840 | } |
| 2841 | |
| 2842 | for (int k = 0; k < proc.activities.size(); k++) { |
Bryce Lee | af691c0 | 2017-03-20 14:20:22 -0700 | [diff] [blame] | 2843 | TaskRecord otherTask = proc.activities.get(k).getTask(); |
Winson Chung | 010927a | 2016-12-15 16:12:35 -0800 | [diff] [blame] | 2844 | if (tr.taskId != otherTask.taskId && otherTask.inRecents) { |
| 2845 | // Don't kill process(es) that has an activity in a different task that is |
| 2846 | // also in recents. |
| 2847 | return; |
| 2848 | } |
| 2849 | } |
| 2850 | |
| 2851 | if (proc.foregroundServices) { |
| 2852 | // Don't kill process(es) with foreground service. |
| 2853 | return; |
| 2854 | } |
| 2855 | |
| 2856 | // Add process to kill list. |
| 2857 | procsToKill.add(proc); |
| 2858 | } |
| 2859 | } |
| 2860 | |
| 2861 | // Kill the running processes. |
| 2862 | for (int i = 0; i < procsToKill.size(); i++) { |
| 2863 | ProcessRecord pr = procsToKill.get(i); |
| 2864 | if (pr.setSchedGroup == ProcessList.SCHED_GROUP_BACKGROUND |
| 2865 | && pr.curReceivers.isEmpty()) { |
| 2866 | pr.kill("remove task", true); |
| 2867 | } else { |
| 2868 | // We delay killing processes that are not in the background or running a receiver. |
| 2869 | pr.waitingToKill = "remove task"; |
| 2870 | } |
| 2871 | } |
| 2872 | } |
| 2873 | |
Craig Mautner | 4a1cb22 | 2013-12-04 16:14:06 -0800 | [diff] [blame] | 2874 | int getNextStackId() { |
Craig Mautner | 858d8a6 | 2013-04-23 17:08:34 -0700 | [diff] [blame] | 2875 | while (true) { |
Wale Ogunwale | 44f036f | 2017-09-29 05:09:09 -0700 | [diff] [blame] | 2876 | if (getStack(mNextFreeStackId) == null) { |
Craig Mautner | 858d8a6 | 2013-04-23 17:08:34 -0700 | [diff] [blame] | 2877 | break; |
| 2878 | } |
Wale Ogunwale | ddc1cb2 | 2015-07-25 19:23:04 -0700 | [diff] [blame] | 2879 | mNextFreeStackId++; |
Craig Mautner | 8d341ef | 2013-03-26 09:03:27 -0700 | [diff] [blame] | 2880 | } |
Wale Ogunwale | ddc1cb2 | 2015-07-25 19:23:04 -0700 | [diff] [blame] | 2881 | return mNextFreeStackId; |
Craig Mautner | 8d341ef | 2013-03-26 09:03:27 -0700 | [diff] [blame] | 2882 | } |
| 2883 | |
Chong Zhang | 5dcb275 | 2015-08-18 13:50:26 -0700 | [diff] [blame] | 2884 | /** |
Winson Chung | 1dbc811 | 2017-09-28 18:05:31 -0700 | [diff] [blame] | 2885 | * Called to restore the state of the task into the stack that it's supposed to go into. |
| 2886 | * |
Chong Zhang | 5dcb275 | 2015-08-18 13:50:26 -0700 | [diff] [blame] | 2887 | * @param task The recent task to be restored. |
Wale Ogunwale | 0568aed | 2017-09-08 13:29:37 -0700 | [diff] [blame] | 2888 | * @param aOptions The activity options to use for restoration. |
Wale Ogunwale | ab5de37 | 2017-10-18 06:46:31 -0700 | [diff] [blame] | 2889 | * @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] | 2890 | * @return true if the task has been restored successfully. |
| 2891 | */ |
Wale Ogunwale | ab5de37 | 2017-10-18 06:46:31 -0700 | [diff] [blame] | 2892 | boolean restoreRecentTaskLocked(TaskRecord task, ActivityOptions aOptions, boolean onTop) { |
| 2893 | final ActivityStack stack = getLaunchStack(null, aOptions, task, onTop); |
Andrii Kulian | 02b7a83 | 2016-10-06 23:11:56 -0700 | [diff] [blame] | 2894 | final ActivityStack currentStack = task.getStack(); |
| 2895 | if (currentStack != null) { |
Wale Ogunwale | 706ed79 | 2015-08-02 10:29:44 -0700 | [diff] [blame] | 2896 | // 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] | 2897 | if (currentStack == stack) { |
Wale Ogunwale | 706ed79 | 2015-08-02 10:29:44 -0700 | [diff] [blame] | 2898 | // Nothing else to do since it is already restored in the right stack. |
| 2899 | return true; |
| 2900 | } |
| 2901 | // Remove current stack association, so we can re-associate the task with the |
| 2902 | // right stack below. |
Andrii Kulian | 02b7a83 | 2016-10-06 23:11:56 -0700 | [diff] [blame] | 2903 | currentStack.removeTask(task, "restoreRecentTaskLocked", REMOVE_TASK_MODE_MOVING); |
Wale Ogunwale | 706ed79 | 2015-08-02 10:29:44 -0700 | [diff] [blame] | 2904 | } |
| 2905 | |
Wale Ogunwale | ab5de37 | 2017-10-18 06:46:31 -0700 | [diff] [blame] | 2906 | stack.addTask(task, onTop, "restoreRecentTask"); |
Wale Ogunwale | e1fe7fa2 | 2016-12-15 18:27:00 -0800 | [diff] [blame] | 2907 | // TODO: move call for creation here and other place into Stack.addTask() |
Wale Ogunwale | ab5de37 | 2017-10-18 06:46:31 -0700 | [diff] [blame] | 2908 | task.createWindowContainer(onTop, true /* showForAllUsers */); |
Wale Ogunwale | ee006da | 2015-03-30 14:49:25 -0700 | [diff] [blame] | 2909 | if (DEBUG_RECENTS) Slog.v(TAG_RECENTS, |
| 2910 | "Added restored task=" + task + " to stack=" + stack); |
Wale Ogunwale | 7de0535 | 2014-12-12 15:21:33 -0800 | [diff] [blame] | 2911 | final ArrayList<ActivityRecord> activities = task.mActivities; |
| 2912 | for (int activityNdx = activities.size() - 1; activityNdx >= 0; --activityNdx) { |
Wale Ogunwale | 26c0dfe | 2016-12-14 14:42:30 -0800 | [diff] [blame] | 2913 | activities.get(activityNdx).createWindowContainer(); |
Wale Ogunwale | 7de0535 | 2014-12-12 15:21:33 -0800 | [diff] [blame] | 2914 | } |
| 2915 | return true; |
Craig Mautner | ef73ee1 | 2014-04-23 11:45:37 -0700 | [diff] [blame] | 2916 | } |
| 2917 | |
Winson Chung | 1dbc811 | 2017-09-28 18:05:31 -0700 | [diff] [blame] | 2918 | @Override |
| 2919 | public void onRecentTaskAdded(TaskRecord task) { |
| 2920 | task.touchActiveTime(); |
| 2921 | } |
| 2922 | |
| 2923 | @Override |
Winson Chung | d6aa3db | 2017-10-05 17:18:43 -0700 | [diff] [blame] | 2924 | public void onRecentTaskRemoved(TaskRecord task, boolean wasTrimmed) { |
Winson Chung | 14cfbb4 | 2017-10-20 13:54:39 -0700 | [diff] [blame] | 2925 | // TODO: Trim active task once b/68045330 is fixed |
Winson Chung | 1dbc811 | 2017-09-28 18:05:31 -0700 | [diff] [blame] | 2926 | task.removedFromRecents(); |
| 2927 | } |
| 2928 | |
Wale Ogunwale | 040b470 | 2015-08-06 18:10:50 -0700 | [diff] [blame] | 2929 | /** |
Andrii Kulian | 839def9 | 2016-11-02 10:58:58 -0700 | [diff] [blame] | 2930 | * Move stack with all its existing content to specified display. |
| 2931 | * @param stackId Id of stack to move. |
| 2932 | * @param displayId Id of display to move stack to. |
Andrii Kulian | 250d653 | 2017-02-08 23:30:45 -0800 | [diff] [blame] | 2933 | * @param onTop Indicates whether container should be place on top or on bottom. |
Andrii Kulian | 839def9 | 2016-11-02 10:58:58 -0700 | [diff] [blame] | 2934 | */ |
Andrii Kulian | 250d653 | 2017-02-08 23:30:45 -0800 | [diff] [blame] | 2935 | void moveStackToDisplayLocked(int stackId, int displayId, boolean onTop) { |
Andrii Kulian | 62e6f25 | 2017-05-30 22:46:53 -0700 | [diff] [blame] | 2936 | final ActivityDisplay activityDisplay = getActivityDisplayOrCreateLocked(displayId); |
Andrii Kulian | 839def9 | 2016-11-02 10:58:58 -0700 | [diff] [blame] | 2937 | if (activityDisplay == null) { |
| 2938 | throw new IllegalArgumentException("moveStackToDisplayLocked: Unknown displayId=" |
| 2939 | + displayId); |
| 2940 | } |
Wale Ogunwale | 9dcf946 | 2017-09-19 15:13:01 -0700 | [diff] [blame] | 2941 | final ActivityStack stack = getStack(stackId); |
Andrii Kulian | 94e82d9b0 | 2017-07-13 15:33:06 -0700 | [diff] [blame] | 2942 | if (stack == null) { |
Andrii Kulian | 839def9 | 2016-11-02 10:58:58 -0700 | [diff] [blame] | 2943 | throw new IllegalArgumentException("moveStackToDisplayLocked: Unknown stackId=" |
| 2944 | + stackId); |
| 2945 | } |
Andrii Kulian | 94e82d9b0 | 2017-07-13 15:33:06 -0700 | [diff] [blame] | 2946 | |
| 2947 | final ActivityDisplay currentDisplay = stack.getDisplay(); |
| 2948 | if (currentDisplay == null) { |
| 2949 | throw new IllegalStateException("moveStackToDisplayLocked: Stack with stack=" + stack |
| 2950 | + " is not attached to any display."); |
| 2951 | } |
| 2952 | |
| 2953 | if (currentDisplay.mDisplayId == displayId) { |
| 2954 | throw new IllegalArgumentException("Trying to move stack=" + stack |
| 2955 | + " to its current displayId=" + displayId); |
| 2956 | } |
| 2957 | |
| 2958 | stack.reparent(activityDisplay, onTop); |
Andrii Kulian | 839def9 | 2016-11-02 10:58:58 -0700 | [diff] [blame] | 2959 | // TODO(multi-display): resize stacks properly if moved from split-screen. |
| 2960 | } |
| 2961 | |
| 2962 | /** |
Winson Chung | 7466610 | 2017-02-22 17:49:24 -0800 | [diff] [blame] | 2963 | * Returns the reparent target stack, creating the stack if necessary. This call also enforces |
| 2964 | * 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] | 2965 | */ |
Wale Ogunwale | 30e441d | 2017-11-09 08:28:45 -0800 | [diff] [blame] | 2966 | // TODO: Look into changing users to this method to ActivityDisplay.resolveWindowingMode() |
Wale Ogunwale | 04a05ac | 2017-09-17 21:35:02 -0700 | [diff] [blame] | 2967 | ActivityStack getReparentTargetStack(TaskRecord task, ActivityStack stack, boolean toTop) { |
Andrii Kulian | 02b7a83 | 2016-10-06 23:11:56 -0700 | [diff] [blame] | 2968 | final ActivityStack prevStack = task.getStack(); |
Wale Ogunwale | 04a05ac | 2017-09-17 21:35:02 -0700 | [diff] [blame] | 2969 | final int stackId = stack.mStackId; |
| 2970 | final boolean inMultiWindowMode = stack.inMultiWindowMode(); |
Chong Zhang | 0289835 | 2015-08-21 17:27:14 -0700 | [diff] [blame] | 2971 | |
Winson Chung | 7466610 | 2017-02-22 17:49:24 -0800 | [diff] [blame] | 2972 | // Check that we aren't reparenting to the same stack that the task is already in |
| 2973 | if (prevStack != null && prevStack.mStackId == stackId) { |
| 2974 | Slog.w(TAG, "Can not reparent to same stack, task=" + task |
| 2975 | + " already in stackId=" + stackId); |
| 2976 | return prevStack; |
Wale Ogunwale | 513346d | 2016-01-27 10:55:01 -0800 | [diff] [blame] | 2977 | } |
| 2978 | |
Winson Chung | 7466610 | 2017-02-22 17:49:24 -0800 | [diff] [blame] | 2979 | // Ensure that we aren't trying to move into a multi-window stack without multi-window |
| 2980 | // support |
Wale Ogunwale | 04a05ac | 2017-09-17 21:35:02 -0700 | [diff] [blame] | 2981 | if (inMultiWindowMode && !mService.mSupportsMultiWindow) { |
Winson Chung | 7466610 | 2017-02-22 17:49:24 -0800 | [diff] [blame] | 2982 | throw new IllegalArgumentException("Device doesn't support multi-window, can not" |
Wale Ogunwale | 04a05ac | 2017-09-17 21:35:02 -0700 | [diff] [blame] | 2983 | + " reparent task=" + task + " to stack=" + stack); |
Winson Chung | c2baac0 | 2017-01-11 13:34:47 -0800 | [diff] [blame] | 2984 | } |
| 2985 | |
Andrii Kulian | eafd9db | 2017-04-05 22:01:35 -0700 | [diff] [blame] | 2986 | // Ensure that we're not moving a task to a dynamic stack if device doesn't support |
| 2987 | // multi-display. |
Wale Ogunwale | 04a05ac | 2017-09-17 21:35:02 -0700 | [diff] [blame] | 2988 | if (stack.mDisplayId != DEFAULT_DISPLAY && !mService.mSupportsMultiDisplay) { |
Andrii Kulian | eafd9db | 2017-04-05 22:01:35 -0700 | [diff] [blame] | 2989 | throw new IllegalArgumentException("Device doesn't support multi-display, can not" |
| 2990 | + " reparent task=" + task + " to stackId=" + stackId); |
| 2991 | } |
| 2992 | |
Wale Ogunwale | 30e441d | 2017-11-09 08:28:45 -0800 | [diff] [blame] | 2993 | // 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] | 2994 | if (stack.getWindowingMode() == WINDOWING_MODE_FREEFORM |
| 2995 | && !mService.mSupportsFreeformWindowManagement) { |
Winson Chung | 7466610 | 2017-02-22 17:49:24 -0800 | [diff] [blame] | 2996 | throw new IllegalArgumentException("Device doesn't support freeform, can not reparent" |
| 2997 | + " task=" + task); |
Wale Ogunwale | 08559dc | 2016-02-23 12:20:08 -0800 | [diff] [blame] | 2998 | } |
| 2999 | |
Wale Ogunwale | 7e1f5f5 | 2017-10-18 15:19:59 -0700 | [diff] [blame] | 3000 | // Leave the task in its current stack or a fullscreen stack if it isn't resizeable and the |
| 3001 | // preferred stack is in multi-window mode. |
Wale Ogunwale | 04a05ac | 2017-09-17 21:35:02 -0700 | [diff] [blame] | 3002 | if (inMultiWindowMode && !task.isResizeable()) { |
Wale Ogunwale | 7e1f5f5 | 2017-10-18 15:19:59 -0700 | [diff] [blame] | 3003 | Slog.w(TAG, "Can not move unresizeable task=" + task + " to multi-window stack=" + stack |
| 3004 | + " Moving to a fullscreen stack instead."); |
| 3005 | if (prevStack != null) { |
| 3006 | return prevStack; |
Wale Ogunwale | 04a05ac | 2017-09-17 21:35:02 -0700 | [diff] [blame] | 3007 | } |
Wale Ogunwale | 7e1f5f5 | 2017-10-18 15:19:59 -0700 | [diff] [blame] | 3008 | stack = stack.getDisplay().createStack( |
| 3009 | WINDOWING_MODE_FULLSCREEN, stack.getActivityType(), toTop); |
Filip Gruszczynski | 49b80af | 2015-09-24 09:04:26 -0700 | [diff] [blame] | 3010 | } |
Wale Ogunwale | 04a05ac | 2017-09-17 21:35:02 -0700 | [diff] [blame] | 3011 | return stack; |
Craig Mautner | 8d341ef | 2013-03-26 09:03:27 -0700 | [diff] [blame] | 3012 | } |
| 3013 | |
Winson Chung | 08f8189 | 2017-03-02 15:40:51 -0800 | [diff] [blame] | 3014 | boolean moveTopStackActivityToPinnedStackLocked(int stackId, Rect destBounds) { |
Wale Ogunwale | 04a05ac | 2017-09-17 21:35:02 -0700 | [diff] [blame] | 3015 | final ActivityStack stack = getStack(stackId); |
Wale Ogunwale | 079a004 | 2015-10-24 11:44:07 -0700 | [diff] [blame] | 3016 | if (stack == null) { |
| 3017 | throw new IllegalArgumentException( |
| 3018 | "moveTopStackActivityToPinnedStackLocked: Unknown stackId=" + stackId); |
| 3019 | } |
| 3020 | |
| 3021 | final ActivityRecord r = stack.topRunningActivityLocked(); |
| 3022 | if (r == null) { |
| 3023 | Slog.w(TAG, "moveTopStackActivityToPinnedStackLocked: No top running activity" |
| 3024 | + " in stack=" + stack); |
| 3025 | return false; |
| 3026 | } |
| 3027 | |
Wale Ogunwale | 6cae765 | 2015-12-26 07:36:26 -0800 | [diff] [blame] | 3028 | if (!mService.mForceResizableActivities && !r.supportsPictureInPicture()) { |
Wale Ogunwale | b60692e | 2015-10-24 12:35:56 -0700 | [diff] [blame] | 3029 | Slog.w(TAG, |
| 3030 | "moveTopStackActivityToPinnedStackLocked: Picture-In-Picture not supported for " |
Filip Gruszczynski | 77d9448 | 2015-12-11 13:59:52 -0800 | [diff] [blame] | 3031 | + " r=" + r); |
Wale Ogunwale | 079a004 | 2015-10-24 11:44:07 -0700 | [diff] [blame] | 3032 | return false; |
| 3033 | } |
| 3034 | |
Winson Chung | 3a68287 | 2017-04-10 14:38:05 -0700 | [diff] [blame] | 3035 | moveActivityToPinnedStackLocked(r, null /* sourceBounds */, 0f /* aspectRatio */, |
Wale Ogunwale | 66e1685 | 2017-10-19 13:35:52 -0700 | [diff] [blame] | 3036 | "moveTopActivityToPinnedStack"); |
Wale Ogunwale | 9c604c7 | 2015-12-06 18:42:57 -0800 | [diff] [blame] | 3037 | return true; |
| 3038 | } |
| 3039 | |
Winson Chung | 8bca9e4 | 2017-04-16 15:59:43 -0700 | [diff] [blame] | 3040 | void moveActivityToPinnedStackLocked(ActivityRecord r, Rect sourceHintBounds, float aspectRatio, |
Wale Ogunwale | 66e1685 | 2017-10-19 13:35:52 -0700 | [diff] [blame] | 3041 | String reason) { |
Winson Chung | 08f8189 | 2017-03-02 15:40:51 -0800 | [diff] [blame] | 3042 | |
Wale Ogunwale | 480dca0 | 2016-02-06 13:58:29 -0800 | [diff] [blame] | 3043 | mWindowManager.deferSurfaceLayout(); |
Winson Chung | 7466610 | 2017-02-22 17:49:24 -0800 | [diff] [blame] | 3044 | |
Wale Ogunwale | 04a05ac | 2017-09-17 21:35:02 -0700 | [diff] [blame] | 3045 | final ActivityDisplay display = r.getStack().getDisplay(); |
| 3046 | PinnedActivityStack stack = display.getPinnedStack(); |
Wale Ogunwale | 9dcf946 | 2017-09-19 15:13:01 -0700 | [diff] [blame] | 3047 | |
Bryce Lee | 04ab346 | 2017-04-10 15:06:33 -0700 | [diff] [blame] | 3048 | // This will clear the pinned stack by moving an existing task to the full screen stack, |
| 3049 | // ensuring only one task is present. |
Wale Ogunwale | 9dcf946 | 2017-09-19 15:13:01 -0700 | [diff] [blame] | 3050 | if (stack != null) { |
| 3051 | moveTasksToFullscreenStackLocked(stack, !ON_TOP); |
| 3052 | } |
Bryce Lee | 04ab346 | 2017-04-10 15:06:33 -0700 | [diff] [blame] | 3053 | |
Wale Ogunwale | 1666e31 | 2016-12-16 11:27:18 -0800 | [diff] [blame] | 3054 | // Need to make sure the pinned stack exist so we can resize it below... |
Wale Ogunwale | 04a05ac | 2017-09-17 21:35:02 -0700 | [diff] [blame] | 3055 | stack = display.getOrCreateStack(WINDOWING_MODE_PINNED, r.getActivityType(), ON_TOP); |
Wale Ogunwale | 1666e31 | 2016-12-16 11:27:18 -0800 | [diff] [blame] | 3056 | |
Wale Ogunwale | 480dca0 | 2016-02-06 13:58:29 -0800 | [diff] [blame] | 3057 | try { |
Bryce Lee | af691c0 | 2017-03-20 14:20:22 -0700 | [diff] [blame] | 3058 | final TaskRecord task = r.getTask(); |
Wale Ogunwale | 480dca0 | 2016-02-06 13:58:29 -0800 | [diff] [blame] | 3059 | // Resize the pinned stack to match the current size of the task the activity we are |
| 3060 | // going to be moving is currently contained in. We do this to have the right starting |
| 3061 | // animation bounds for the pinned stack to the desired bounds the caller wants. |
Bryce Lee | f3c6a47 | 2017-11-14 14:53:06 -0800 | [diff] [blame] | 3062 | resizeStackLocked(stack, task.getOverrideBounds(), null /* tempTaskBounds */, |
Wale Ogunwale | 480dca0 | 2016-02-06 13:58:29 -0800 | [diff] [blame] | 3063 | null /* tempTaskInsetBounds */, !PRESERVE_WINDOWS, |
Wale Ogunwale | c8da41e | 2016-04-16 13:27:23 -0700 | [diff] [blame] | 3064 | true /* allowResizeInDockedMode */, !DEFER_RESUME); |
Wale Ogunwale | 480dca0 | 2016-02-06 13:58:29 -0800 | [diff] [blame] | 3065 | |
| 3066 | if (task.mActivities.size() == 1) { |
Winson Chung | 5af42fc | 2017-03-24 17:11:33 -0700 | [diff] [blame] | 3067 | // Defer resume until below, and do not schedule PiP changes until we animate below |
Wale Ogunwale | 04a05ac | 2017-09-17 21:35:02 -0700 | [diff] [blame] | 3068 | task.reparent(stack, ON_TOP, REPARENT_MOVE_STACK_TO_FRONT, !ANIMATE, DEFER_RESUME, |
| 3069 | false /* schedulePictureInPictureModeChange */, reason); |
Wale Ogunwale | 480dca0 | 2016-02-06 13:58:29 -0800 | [diff] [blame] | 3070 | } else { |
Winson Chung | b5c41b7 | 2016-12-07 15:00:47 -0800 | [diff] [blame] | 3071 | // There are multiple activities in the task and moving the top activity should |
Winson Chung | 7466610 | 2017-02-22 17:49:24 -0800 | [diff] [blame] | 3072 | // reveal/leave the other activities in their original task. |
| 3073 | |
| 3074 | // Currently, we don't support reparenting activities across tasks in two different |
| 3075 | // stacks, so instead, just create a new task in the same stack, reparent the |
| 3076 | // activity into that task, and then reparent the whole task to the new stack. This |
| 3077 | // ensures that all the necessary work to migrate states in the old and new stacks |
| 3078 | // is also done. |
| 3079 | final TaskRecord newTask = task.getStack().createTaskRecord( |
Wale Ogunwale | 6fbde9f | 2017-08-24 07:24:12 -0700 | [diff] [blame] | 3080 | getNextTaskIdForUserLocked(r.userId), r.info, r.intent, null, null, true); |
Winson Chung | 7466610 | 2017-02-22 17:49:24 -0800 | [diff] [blame] | 3081 | r.reparent(newTask, MAX_VALUE, "moveActivityToStack"); |
| 3082 | |
Winson Chung | 5af42fc | 2017-03-24 17:11:33 -0700 | [diff] [blame] | 3083 | // Defer resume until below, and do not schedule PiP changes until we animate below |
Wale Ogunwale | 04a05ac | 2017-09-17 21:35:02 -0700 | [diff] [blame] | 3084 | newTask.reparent(stack, ON_TOP, REPARENT_MOVE_STACK_TO_FRONT, !ANIMATE, |
Winson Chung | 5af42fc | 2017-03-24 17:11:33 -0700 | [diff] [blame] | 3085 | DEFER_RESUME, false /* schedulePictureInPictureModeChange */, reason); |
Wale Ogunwale | 480dca0 | 2016-02-06 13:58:29 -0800 | [diff] [blame] | 3086 | } |
Winson Chung | c2baac0 | 2017-01-11 13:34:47 -0800 | [diff] [blame] | 3087 | |
| 3088 | // Reset the state that indicates it can enter PiP while pausing after we've moved it |
| 3089 | // to the pinned stack |
Winson Chung | f7e03e1 | 2017-08-22 11:32:16 -0700 | [diff] [blame] | 3090 | r.supportsEnterPipOnTaskSwitch = false; |
Wale Ogunwale | 480dca0 | 2016-02-06 13:58:29 -0800 | [diff] [blame] | 3091 | } finally { |
| 3092 | mWindowManager.continueSurfaceLayout(); |
Wale Ogunwale | 079a004 | 2015-10-24 11:44:07 -0700 | [diff] [blame] | 3093 | } |
| 3094 | |
Winson Chung | e7ba686 | 2017-05-24 12:13:33 -0700 | [diff] [blame] | 3095 | // Calculate the default bounds (don't use existing stack bounds as we may have just created |
| 3096 | // the stack, and schedule the start of the animation into PiP (the bounds animator that |
| 3097 | // is triggered by this is posted on another thread) |
Winson Chung | a71febe | 2017-05-22 11:14:22 -0700 | [diff] [blame] | 3098 | final Rect destBounds = stack.getDefaultPictureInPictureBounds(aspectRatio); |
| 3099 | |
Winson Chung | e7ba686 | 2017-05-24 12:13:33 -0700 | [diff] [blame] | 3100 | stack.animateResizePinnedStack(sourceHintBounds, destBounds, -1 /* animationDuration */, |
| 3101 | true /* fromFullscreen */); |
| 3102 | |
| 3103 | // Update the visibility of all activities after the they have been reparented to the new |
| 3104 | // stack. This MUST run after the animation above is scheduled to ensure that the windows |
| 3105 | // drawn signal is scheduled after the bounds animation start call on the bounds animator |
| 3106 | // thread. |
Wale Ogunwale | 079a004 | 2015-10-24 11:44:07 -0700 | [diff] [blame] | 3107 | ensureActivitiesVisibleLocked(null, 0, !PRESERVE_WINDOWS); |
Wale Ogunwale | d046a01 | 2015-12-24 13:05:59 -0800 | [diff] [blame] | 3108 | resumeFocusedStackTopActivityLocked(); |
Wale Ogunwale | 03ce863 | 2015-12-29 16:15:22 -0800 | [diff] [blame] | 3109 | |
Wale Ogunwale | 89be576 | 2017-10-04 13:27:49 -0700 | [diff] [blame] | 3110 | mService.mTaskChangeNotificationController.notifyActivityPinned(r); |
Wale Ogunwale | 079a004 | 2015-10-24 11:44:07 -0700 | [diff] [blame] | 3111 | } |
| 3112 | |
Andrii Kulian | 0864bbb | 2017-02-16 15:45:58 -0800 | [diff] [blame] | 3113 | /** Move activity with its stack to front and make the stack focused. */ |
Chong Zhang | 6cda19c | 2016-06-14 19:07:56 -0700 | [diff] [blame] | 3114 | boolean moveFocusableActivityStackToFrontLocked(ActivityRecord r, String reason) { |
| 3115 | if (r == null || !r.isFocusable()) { |
| 3116 | if (DEBUG_FOCUS) Slog.d(TAG_FOCUS, |
| 3117 | "moveActivityStackToFront: unfocusable r=" + r); |
| 3118 | return false; |
| 3119 | } |
| 3120 | |
Bryce Lee | af691c0 | 2017-03-20 14:20:22 -0700 | [diff] [blame] | 3121 | final TaskRecord task = r.getTask(); |
Andrii Kulian | 02b7a83 | 2016-10-06 23:11:56 -0700 | [diff] [blame] | 3122 | final ActivityStack stack = r.getStack(); |
| 3123 | if (stack == null) { |
Chong Zhang | 6cda19c | 2016-06-14 19:07:56 -0700 | [diff] [blame] | 3124 | Slog.w(TAG, "moveActivityStackToFront: invalid task or stack: r=" |
| 3125 | + r + " task=" + task); |
| 3126 | return false; |
| 3127 | } |
| 3128 | |
Chong Zhang | 6cda19c | 2016-06-14 19:07:56 -0700 | [diff] [blame] | 3129 | if (stack == mFocusedStack && stack.topRunningActivityLocked() == r) { |
| 3130 | if (DEBUG_FOCUS) Slog.d(TAG_FOCUS, |
| 3131 | "moveActivityStackToFront: already on top, r=" + r); |
| 3132 | return false; |
| 3133 | } |
| 3134 | |
| 3135 | if (DEBUG_FOCUS) Slog.d(TAG_FOCUS, |
| 3136 | "moveActivityStackToFront: r=" + r); |
| 3137 | |
| 3138 | stack.moveToFront(reason, task); |
| 3139 | return true; |
| 3140 | } |
| 3141 | |
David Stevens | c6b91c6 | 2017-02-08 14:23:58 -0800 | [diff] [blame] | 3142 | ActivityRecord findTaskLocked(ActivityRecord r, int displayId) { |
Wale Ogunwale | 3938197 | 2015-12-17 17:15:29 -0800 | [diff] [blame] | 3143 | mTmpFindTaskResult.r = null; |
| 3144 | mTmpFindTaskResult.matchedByRootAffinity = false; |
David Stevens | c6b91c6 | 2017-02-08 14:23:58 -0800 | [diff] [blame] | 3145 | ActivityRecord affinityMatch = null; |
Wale Ogunwale | ee006da | 2015-03-30 14:49:25 -0700 | [diff] [blame] | 3146 | if (DEBUG_TASKS) Slog.d(TAG_TASKS, "Looking for task of " + r); |
Craig Mautner | e0a3884 | 2013-12-16 16:14:02 -0800 | [diff] [blame] | 3147 | for (int displayNdx = mActivityDisplays.size() - 1; displayNdx >= 0; --displayNdx) { |
Wale Ogunwale | a0f5b5e | 2017-10-11 09:37:23 -0700 | [diff] [blame] | 3148 | final ActivityDisplay display = mActivityDisplays.valueAt(displayNdx); |
| 3149 | for (int stackNdx = display.getChildCount() - 1; stackNdx >= 0; --stackNdx) { |
| 3150 | final ActivityStack stack = display.getChildAt(stackNdx); |
Wale Ogunwale | 6fbde9f | 2017-08-24 07:24:12 -0700 | [diff] [blame] | 3151 | if (!r.hasCompatibleActivityType(stack)) { |
Winson Chung | 91e5c88 | 2017-04-21 14:44:38 -0700 | [diff] [blame] | 3152 | if (DEBUG_TASKS) Slog.d(TAG_TASKS, "Skipping stack: (mismatch activity/stack) " |
| 3153 | + stack); |
Craig Mautner | 1b4bf85 | 2014-05-26 15:06:32 -0700 | [diff] [blame] | 3154 | continue; |
| 3155 | } |
Wale Ogunwale | 3938197 | 2015-12-17 17:15:29 -0800 | [diff] [blame] | 3156 | stack.findTaskLocked(r, mTmpFindTaskResult); |
David Stevens | c6b91c6 | 2017-02-08 14:23:58 -0800 | [diff] [blame] | 3157 | // It is possible to have tasks in multiple stacks with the same root affinity, so |
| 3158 | // we should keep looking after finding an affinity match to see if there is a |
| 3159 | // better match in another stack. Also, task affinity isn't a good enough reason |
| 3160 | // to target a display which isn't the source of the intent, so skip any affinity |
| 3161 | // matches not on the specified display. |
| 3162 | if (mTmpFindTaskResult.r != null) { |
| 3163 | if (!mTmpFindTaskResult.matchedByRootAffinity) { |
| 3164 | return mTmpFindTaskResult.r; |
| 3165 | } else if (mTmpFindTaskResult.r.getDisplayId() == displayId) { |
Winson Chung | 5b895b7 | 2017-05-01 13:46:25 -0700 | [diff] [blame] | 3166 | // Note: since the traversing through the stacks is top down, the floating |
| 3167 | // tasks should always have lower priority than any affinity-matching tasks |
| 3168 | // in the fullscreen stacks |
David Stevens | c6b91c6 | 2017-02-08 14:23:58 -0800 | [diff] [blame] | 3169 | affinityMatch = mTmpFindTaskResult.r; |
David Stevens | e5a7b64 | 2017-05-22 13:18:23 -0700 | [diff] [blame] | 3170 | } else if (DEBUG_TASKS && mTmpFindTaskResult.matchedByRootAffinity) { |
| 3171 | Slog.d(TAG_TASKS, "Skipping match on different display " |
| 3172 | + mTmpFindTaskResult.r.getDisplayId() + " " + displayId); |
David Stevens | c6b91c6 | 2017-02-08 14:23:58 -0800 | [diff] [blame] | 3173 | } |
Craig Mautner | 4a1cb22 | 2013-12-04 16:14:06 -0800 | [diff] [blame] | 3174 | } |
Craig Mautner | 8849a5e | 2013-04-02 16:41:03 -0700 | [diff] [blame] | 3175 | } |
| 3176 | } |
Winson Chung | 5b895b7 | 2017-05-01 13:46:25 -0700 | [diff] [blame] | 3177 | |
David Stevens | c6b91c6 | 2017-02-08 14:23:58 -0800 | [diff] [blame] | 3178 | if (DEBUG_TASKS && affinityMatch == null) Slog.d(TAG_TASKS, "No task found"); |
| 3179 | return affinityMatch; |
Craig Mautner | 8849a5e | 2013-04-02 16:41:03 -0700 | [diff] [blame] | 3180 | } |
| 3181 | |
Andrii Kulian | d3bbb13 | 2016-06-16 16:00:20 -0700 | [diff] [blame] | 3182 | ActivityRecord findActivityLocked(Intent intent, ActivityInfo info, |
Wale Ogunwale | a0f5b5e | 2017-10-11 09:37:23 -0700 | [diff] [blame] | 3183 | boolean compareIntentFilters) { |
Craig Mautner | e0a3884 | 2013-12-16 16:14:02 -0800 | [diff] [blame] | 3184 | for (int displayNdx = mActivityDisplays.size() - 1; displayNdx >= 0; --displayNdx) { |
Wale Ogunwale | a0f5b5e | 2017-10-11 09:37:23 -0700 | [diff] [blame] | 3185 | final ActivityDisplay display = mActivityDisplays.valueAt(displayNdx); |
| 3186 | for (int stackNdx = display.getChildCount() - 1; stackNdx >= 0; --stackNdx) { |
| 3187 | final ActivityStack stack = display.getChildAt(stackNdx); |
| 3188 | final ActivityRecord ar = stack.findActivityLocked( |
| 3189 | intent, info, compareIntentFilters); |
Craig Mautner | 4a1cb22 | 2013-12-04 16:14:06 -0800 | [diff] [blame] | 3190 | if (ar != null) { |
| 3191 | return ar; |
| 3192 | } |
Craig Mautner | 8849a5e | 2013-04-02 16:41:03 -0700 | [diff] [blame] | 3193 | } |
| 3194 | } |
| 3195 | return null; |
| 3196 | } |
| 3197 | |
David Stevens | 9440dc8 | 2017-03-16 19:00:20 -0700 | [diff] [blame] | 3198 | boolean hasAwakeDisplay() { |
| 3199 | for (int displayNdx = mActivityDisplays.size() - 1; displayNdx >= 0; --displayNdx) { |
| 3200 | final ActivityDisplay display = mActivityDisplays.valueAt(displayNdx); |
| 3201 | if (!display.shouldSleep()) { |
| 3202 | return true; |
| 3203 | } |
| 3204 | } |
| 3205 | return false; |
| 3206 | } |
| 3207 | |
Craig Mautner | 8d341ef | 2013-03-26 09:03:27 -0700 | [diff] [blame] | 3208 | void goingToSleepLocked() { |
Craig Mautner | 0eea92c | 2013-05-16 13:35:39 -0700 | [diff] [blame] | 3209 | scheduleSleepTimeout(); |
| 3210 | if (!mGoingToSleep.isHeld()) { |
| 3211 | mGoingToSleep.acquire(); |
Craig Mautner | 7ea5bd4 | 2013-07-05 15:27:08 -0700 | [diff] [blame] | 3212 | if (mLaunchingActivity.isHeld()) { |
| 3213 | if (VALIDATE_WAKE_LOCK_CALLER && Binder.getCallingUid() != Process.myUid()) { |
| 3214 | throw new IllegalStateException("Calling must be system uid"); |
Craig Mautner | 0eea92c | 2013-05-16 13:35:39 -0700 | [diff] [blame] | 3215 | } |
Craig Mautner | 7ea5bd4 | 2013-07-05 15:27:08 -0700 | [diff] [blame] | 3216 | mLaunchingActivity.release(); |
| 3217 | mService.mHandler.removeMessages(LAUNCH_TIMEOUT_MSG); |
Craig Mautner | 0eea92c | 2013-05-16 13:35:39 -0700 | [diff] [blame] | 3218 | } |
Craig Mautner | 8d341ef | 2013-03-26 09:03:27 -0700 | [diff] [blame] | 3219 | } |
David Stevens | 9440dc8 | 2017-03-16 19:00:20 -0700 | [diff] [blame] | 3220 | |
| 3221 | applySleepTokensLocked(false /* applyToStacks */); |
| 3222 | |
| 3223 | checkReadyForSleepLocked(true /* allowDelay */); |
| 3224 | } |
| 3225 | |
| 3226 | void prepareForShutdownLocked() { |
| 3227 | for (int i = 0; i < mActivityDisplays.size(); i++) { |
| 3228 | createSleepTokenLocked("shutdown", mActivityDisplays.keyAt(i)); |
| 3229 | } |
Craig Mautner | 8d341ef | 2013-03-26 09:03:27 -0700 | [diff] [blame] | 3230 | } |
| 3231 | |
| 3232 | boolean shutdownLocked(int timeout) { |
Craig Mautner | 0eea92c | 2013-05-16 13:35:39 -0700 | [diff] [blame] | 3233 | goingToSleepLocked(); |
Craig Mautner | 0eea92c | 2013-05-16 13:35:39 -0700 | [diff] [blame] | 3234 | |
Craig Mautner | f4c909b | 2014-04-17 18:39:38 -0700 | [diff] [blame] | 3235 | boolean timedout = false; |
Craig Mautner | 0eea92c | 2013-05-16 13:35:39 -0700 | [diff] [blame] | 3236 | final long endTime = System.currentTimeMillis() + timeout; |
| 3237 | while (true) { |
David Stevens | 18abd0e | 2017-08-17 14:55:47 -0700 | [diff] [blame] | 3238 | if (!putStacksToSleepLocked(true /* allowDelay */, true /* shuttingDown */)) { |
Craig Mautner | 0eea92c | 2013-05-16 13:35:39 -0700 | [diff] [blame] | 3239 | long timeRemaining = endTime - System.currentTimeMillis(); |
| 3240 | if (timeRemaining > 0) { |
Craig Mautner | 8d341ef | 2013-03-26 09:03:27 -0700 | [diff] [blame] | 3241 | try { |
Craig Mautner | 0eea92c | 2013-05-16 13:35:39 -0700 | [diff] [blame] | 3242 | mService.wait(timeRemaining); |
Craig Mautner | 8d341ef | 2013-03-26 09:03:27 -0700 | [diff] [blame] | 3243 | } catch (InterruptedException e) { |
| 3244 | } |
Craig Mautner | 0eea92c | 2013-05-16 13:35:39 -0700 | [diff] [blame] | 3245 | } else { |
| 3246 | Slog.w(TAG, "Activity manager shutdown timed out"); |
| 3247 | timedout = true; |
| 3248 | break; |
Craig Mautner | 8d341ef | 2013-03-26 09:03:27 -0700 | [diff] [blame] | 3249 | } |
Craig Mautner | 0eea92c | 2013-05-16 13:35:39 -0700 | [diff] [blame] | 3250 | } else { |
| 3251 | break; |
Craig Mautner | 8d341ef | 2013-03-26 09:03:27 -0700 | [diff] [blame] | 3252 | } |
| 3253 | } |
Craig Mautner | 0eea92c | 2013-05-16 13:35:39 -0700 | [diff] [blame] | 3254 | |
| 3255 | // Force checkReadyForSleep to complete. |
David Stevens | 9440dc8 | 2017-03-16 19:00:20 -0700 | [diff] [blame] | 3256 | checkReadyForSleepLocked(false /* allowDelay */); |
Craig Mautner | 0eea92c | 2013-05-16 13:35:39 -0700 | [diff] [blame] | 3257 | |
Craig Mautner | 8d341ef | 2013-03-26 09:03:27 -0700 | [diff] [blame] | 3258 | return timedout; |
| 3259 | } |
| 3260 | |
| 3261 | void comeOutOfSleepIfNeededLocked() { |
Craig Mautner | 0eea92c | 2013-05-16 13:35:39 -0700 | [diff] [blame] | 3262 | removeSleepTimeouts(); |
| 3263 | if (mGoingToSleep.isHeld()) { |
| 3264 | mGoingToSleep.release(); |
| 3265 | } |
David Stevens | 9440dc8 | 2017-03-16 19:00:20 -0700 | [diff] [blame] | 3266 | } |
| 3267 | |
| 3268 | void applySleepTokensLocked(boolean applyToStacks) { |
Craig Mautner | e0a3884 | 2013-12-16 16:14:02 -0800 | [diff] [blame] | 3269 | for (int displayNdx = mActivityDisplays.size() - 1; displayNdx >= 0; --displayNdx) { |
David Stevens | 9440dc8 | 2017-03-16 19:00:20 -0700 | [diff] [blame] | 3270 | // Set the sleeping state of the display. |
| 3271 | final ActivityDisplay display = mActivityDisplays.valueAt(displayNdx); |
| 3272 | final boolean displayShouldSleep = display.shouldSleep(); |
| 3273 | if (displayShouldSleep == display.isSleeping()) { |
| 3274 | continue; |
| 3275 | } |
| 3276 | display.setIsSleeping(displayShouldSleep); |
| 3277 | |
| 3278 | if (!applyToStacks) { |
| 3279 | continue; |
| 3280 | } |
| 3281 | |
| 3282 | // Set the sleeping state of the stacks on the display. |
Wale Ogunwale | a0f5b5e | 2017-10-11 09:37:23 -0700 | [diff] [blame] | 3283 | for (int stackNdx = display.getChildCount() - 1; stackNdx >= 0; --stackNdx) { |
| 3284 | final ActivityStack stack = display.getChildAt(stackNdx); |
David Stevens | 9440dc8 | 2017-03-16 19:00:20 -0700 | [diff] [blame] | 3285 | if (displayShouldSleep) { |
| 3286 | stack.goToSleepIfPossible(false /* shuttingDown */); |
| 3287 | } else { |
| 3288 | stack.awakeFromSleepingLocked(); |
| 3289 | if (isFocusedStack(stack)) { |
| 3290 | resumeFocusedStackTopActivityLocked(); |
| 3291 | } |
| 3292 | } |
| 3293 | } |
| 3294 | |
| 3295 | if (displayShouldSleep || mGoingToSleepActivities.isEmpty()) { |
| 3296 | continue; |
| 3297 | } |
| 3298 | // The display is awake now, so clean up the going to sleep list. |
| 3299 | for (Iterator<ActivityRecord> it = mGoingToSleepActivities.iterator(); it.hasNext(); ) { |
| 3300 | final ActivityRecord r = it.next(); |
| 3301 | if (r.getDisplayId() == display.mDisplayId) { |
| 3302 | it.remove(); |
Craig Mautner | 4a1cb22 | 2013-12-04 16:14:06 -0800 | [diff] [blame] | 3303 | } |
Craig Mautner | 5314a40 | 2013-09-26 12:40:16 -0700 | [diff] [blame] | 3304 | } |
Craig Mautner | 8d341ef | 2013-03-26 09:03:27 -0700 | [diff] [blame] | 3305 | } |
Craig Mautner | 0eea92c | 2013-05-16 13:35:39 -0700 | [diff] [blame] | 3306 | } |
| 3307 | |
| 3308 | void activitySleptLocked(ActivityRecord r) { |
| 3309 | mGoingToSleepActivities.remove(r); |
David Stevens | 9440dc8 | 2017-03-16 19:00:20 -0700 | [diff] [blame] | 3310 | final ActivityStack s = r.getStack(); |
| 3311 | if (s != null) { |
| 3312 | s.checkReadyForSleep(); |
| 3313 | } else { |
| 3314 | checkReadyForSleepLocked(true); |
| 3315 | } |
Craig Mautner | 0eea92c | 2013-05-16 13:35:39 -0700 | [diff] [blame] | 3316 | } |
| 3317 | |
David Stevens | 9440dc8 | 2017-03-16 19:00:20 -0700 | [diff] [blame] | 3318 | void checkReadyForSleepLocked(boolean allowDelay) { |
Fyodor Kupolov | 9b80b94 | 2016-06-16 16:29:05 -0700 | [diff] [blame] | 3319 | if (!mService.isSleepingOrShuttingDownLocked()) { |
Craig Mautner | 0eea92c | 2013-05-16 13:35:39 -0700 | [diff] [blame] | 3320 | // Do not care. |
| 3321 | return; |
| 3322 | } |
| 3323 | |
David Stevens | 18abd0e | 2017-08-17 14:55:47 -0700 | [diff] [blame] | 3324 | if (!putStacksToSleepLocked(allowDelay, false /* shuttingDown */)) { |
| 3325 | return; |
Craig Mautner | 0eea92c | 2013-05-16 13:35:39 -0700 | [diff] [blame] | 3326 | } |
| 3327 | |
Wei Wang | 65c7a15 | 2016-06-02 18:51:22 -0700 | [diff] [blame] | 3328 | // Send launch end powerhint before going sleep |
| 3329 | mService.mActivityStarter.sendPowerHintForLaunchEndIfNeeded(); |
| 3330 | |
Craig Mautner | 0eea92c | 2013-05-16 13:35:39 -0700 | [diff] [blame] | 3331 | removeSleepTimeouts(); |
| 3332 | |
| 3333 | if (mGoingToSleep.isHeld()) { |
| 3334 | mGoingToSleep.release(); |
| 3335 | } |
| 3336 | if (mService.mShuttingDown) { |
| 3337 | mService.notifyAll(); |
| 3338 | } |
Craig Mautner | 8d341ef | 2013-03-26 09:03:27 -0700 | [diff] [blame] | 3339 | } |
| 3340 | |
David Stevens | 18abd0e | 2017-08-17 14:55:47 -0700 | [diff] [blame] | 3341 | // Tries to put all activity stacks to sleep. Returns true if all stacks were |
| 3342 | // successfully put to sleep. |
| 3343 | private boolean putStacksToSleepLocked(boolean allowDelay, boolean shuttingDown) { |
| 3344 | boolean allSleep = true; |
| 3345 | for (int displayNdx = mActivityDisplays.size() - 1; displayNdx >= 0; --displayNdx) { |
Wale Ogunwale | a0f5b5e | 2017-10-11 09:37:23 -0700 | [diff] [blame] | 3346 | final ActivityDisplay display = mActivityDisplays.valueAt(displayNdx); |
| 3347 | for (int stackNdx = display.getChildCount() - 1; stackNdx >= 0; --stackNdx) { |
| 3348 | final ActivityStack stack = display.getChildAt(stackNdx); |
David Stevens | 18abd0e | 2017-08-17 14:55:47 -0700 | [diff] [blame] | 3349 | if (allowDelay) { |
Wale Ogunwale | a0f5b5e | 2017-10-11 09:37:23 -0700 | [diff] [blame] | 3350 | allSleep &= stack.goToSleepIfPossible(shuttingDown); |
David Stevens | 18abd0e | 2017-08-17 14:55:47 -0700 | [diff] [blame] | 3351 | } else { |
Wale Ogunwale | a0f5b5e | 2017-10-11 09:37:23 -0700 | [diff] [blame] | 3352 | stack.goToSleep(); |
David Stevens | 18abd0e | 2017-08-17 14:55:47 -0700 | [diff] [blame] | 3353 | } |
| 3354 | } |
| 3355 | } |
| 3356 | return allSleep; |
| 3357 | } |
| 3358 | |
Craig Mautner | ce5f3cb | 2013-04-22 08:58:54 -0700 | [diff] [blame] | 3359 | boolean reportResumedActivityLocked(ActivityRecord r) { |
Bryce Lee | 29a649d | 2017-08-18 13:52:31 -0700 | [diff] [blame] | 3360 | // A resumed activity cannot be stopping. remove from list |
| 3361 | mStoppingActivities.remove(r); |
| 3362 | |
Andrii Kulian | 02b7a83 | 2016-10-06 23:11:56 -0700 | [diff] [blame] | 3363 | final ActivityStack stack = r.getStack(); |
Wale Ogunwale | 1e60e0c | 2015-10-28 13:36:10 -0700 | [diff] [blame] | 3364 | if (isFocusedStack(stack)) { |
Jeff Sharkey | 5782da7 | 2013-04-25 14:32:30 -0700 | [diff] [blame] | 3365 | mService.updateUsageStats(r, true); |
Craig Mautner | ce5f3cb | 2013-04-22 08:58:54 -0700 | [diff] [blame] | 3366 | } |
| 3367 | if (allResumedActivitiesComplete()) { |
Filip Gruszczynski | bc5a6c5 | 2015-09-22 13:13:24 -0700 | [diff] [blame] | 3368 | ensureActivitiesVisibleLocked(null, 0, !PRESERVE_WINDOWS); |
Craig Mautner | ce5f3cb | 2013-04-22 08:58:54 -0700 | [diff] [blame] | 3369 | mWindowManager.executeAppTransition(); |
| 3370 | return true; |
| 3371 | } |
| 3372 | return false; |
| 3373 | } |
| 3374 | |
Craig Mautner | 8d341ef | 2013-03-26 09:03:27 -0700 | [diff] [blame] | 3375 | void handleAppCrashLocked(ProcessRecord app) { |
Craig Mautner | e0a3884 | 2013-12-16 16:14:02 -0800 | [diff] [blame] | 3376 | for (int displayNdx = mActivityDisplays.size() - 1; displayNdx >= 0; --displayNdx) { |
Wale Ogunwale | a0f5b5e | 2017-10-11 09:37:23 -0700 | [diff] [blame] | 3377 | final ActivityDisplay display = mActivityDisplays.valueAt(displayNdx); |
| 3378 | for (int stackNdx = display.getChildCount() - 1; stackNdx >= 0; --stackNdx) { |
| 3379 | final ActivityStack stack = display.getChildAt(stackNdx); |
| 3380 | stack.handleAppCrashLocked(app); |
Craig Mautner | 4a1cb22 | 2013-12-04 16:14:06 -0800 | [diff] [blame] | 3381 | } |
Craig Mautner | 8d341ef | 2013-03-26 09:03:27 -0700 | [diff] [blame] | 3382 | } |
| 3383 | } |
| 3384 | |
Craig Mautner | bb74246 | 2014-07-07 15:28:55 -0700 | [diff] [blame] | 3385 | // Called when WindowManager has finished animating the launchingBehind activity to the back. |
Andrii Kulian | 21713ac | 2016-10-12 22:05:05 -0700 | [diff] [blame] | 3386 | private void handleLaunchTaskBehindCompleteLocked(ActivityRecord r) { |
Bryce Lee | af691c0 | 2017-03-20 14:20:22 -0700 | [diff] [blame] | 3387 | final TaskRecord task = r.getTask(); |
Andrii Kulian | 02b7a83 | 2016-10-06 23:11:56 -0700 | [diff] [blame] | 3388 | final ActivityStack stack = task.getStack(); |
Winson | 730bf06 | 2016-03-31 18:04:56 -0700 | [diff] [blame] | 3389 | |
| 3390 | r.mLaunchTaskBehind = false; |
Winson Chung | 1dbc811 | 2017-09-28 18:05:31 -0700 | [diff] [blame] | 3391 | mRecentTasks.add(task); |
Yorke Lee | bd54c2a | 2016-10-25 13:49:23 -0700 | [diff] [blame] | 3392 | mService.mTaskChangeNotificationController.notifyTaskStackChanged(); |
Wale Ogunwale | 26c0dfe | 2016-12-14 14:42:30 -0800 | [diff] [blame] | 3393 | r.setVisibility(false); |
Winson | 730bf06 | 2016-03-31 18:04:56 -0700 | [diff] [blame] | 3394 | |
| 3395 | // When launching tasks behind, update the last active time of the top task after the new |
| 3396 | // task has been shown briefly |
Wale Ogunwale | 30e441d | 2017-11-09 08:28:45 -0800 | [diff] [blame] | 3397 | final ActivityRecord top = stack.getTopActivity(); |
Winson | 730bf06 | 2016-03-31 18:04:56 -0700 | [diff] [blame] | 3398 | if (top != null) { |
Bryce Lee | af691c0 | 2017-03-20 14:20:22 -0700 | [diff] [blame] | 3399 | top.getTask().touchActiveTime(); |
Winson | 730bf06 | 2016-03-31 18:04:56 -0700 | [diff] [blame] | 3400 | } |
Craig Mautner | bb74246 | 2014-07-07 15:28:55 -0700 | [diff] [blame] | 3401 | } |
| 3402 | |
| 3403 | void scheduleLaunchTaskBehindComplete(IBinder token) { |
| 3404 | mHandler.obtainMessage(LAUNCH_TASK_BEHIND_COMPLETE, token).sendToTarget(); |
| 3405 | } |
| 3406 | |
Filip Gruszczynski | bc5a6c5 | 2015-09-22 13:13:24 -0700 | [diff] [blame] | 3407 | void ensureActivitiesVisibleLocked(ActivityRecord starting, int configChanges, |
| 3408 | boolean preserveWindows) { |
Jorim Jaggi | fe76234 | 2016-10-13 14:33:27 +0200 | [diff] [blame] | 3409 | mKeyguardController.beginActivityVisibilityUpdate(); |
| 3410 | try { |
| 3411 | // First the front stacks. In case any are not fullscreen and are in front of home. |
| 3412 | for (int displayNdx = mActivityDisplays.size() - 1; displayNdx >= 0; --displayNdx) { |
Wale Ogunwale | a0f5b5e | 2017-10-11 09:37:23 -0700 | [diff] [blame] | 3413 | final ActivityDisplay display = mActivityDisplays.valueAt(displayNdx); |
| 3414 | for (int stackNdx = display.getChildCount() - 1; stackNdx >= 0; --stackNdx) { |
| 3415 | final ActivityStack stack = display.getChildAt(stackNdx); |
Jorim Jaggi | fe76234 | 2016-10-13 14:33:27 +0200 | [diff] [blame] | 3416 | stack.ensureActivitiesVisibleLocked(starting, configChanges, preserveWindows); |
| 3417 | } |
Craig Mautner | 580ea81 | 2013-04-25 12:58:38 -0700 | [diff] [blame] | 3418 | } |
Jorim Jaggi | fe76234 | 2016-10-13 14:33:27 +0200 | [diff] [blame] | 3419 | } finally { |
| 3420 | mKeyguardController.endActivityVisibilityUpdate(); |
Craig Mautner | 8d341ef | 2013-03-26 09:03:27 -0700 | [diff] [blame] | 3421 | } |
Craig Mautner | 8d341ef | 2013-03-26 09:03:27 -0700 | [diff] [blame] | 3422 | } |
| 3423 | |
Jorim Jaggi | 8b702ed | 2017-01-20 16:59:03 +0100 | [diff] [blame] | 3424 | void addStartingWindowsForVisibleActivities(boolean taskSwitch) { |
| 3425 | for (int displayNdx = mActivityDisplays.size() - 1; displayNdx >= 0; --displayNdx) { |
Wale Ogunwale | a0f5b5e | 2017-10-11 09:37:23 -0700 | [diff] [blame] | 3426 | final ActivityDisplay display = mActivityDisplays.valueAt(displayNdx); |
| 3427 | for (int stackNdx = display.getChildCount() - 1; stackNdx >= 0; --stackNdx) { |
| 3428 | final ActivityStack stack = display.getChildAt(stackNdx); |
Jorim Jaggi | 8b702ed | 2017-01-20 16:59:03 +0100 | [diff] [blame] | 3429 | stack.addStartingWindowsForVisibleActivities(taskSwitch); |
| 3430 | } |
| 3431 | } |
| 3432 | } |
| 3433 | |
Chong Zhang | fdcc4d4 | 2015-10-14 16:50:12 -0700 | [diff] [blame] | 3434 | void invalidateTaskLayers() { |
| 3435 | mTaskLayersChanged = true; |
| 3436 | } |
| 3437 | |
| 3438 | void rankTaskLayersIfNeeded() { |
| 3439 | if (!mTaskLayersChanged) { |
| 3440 | return; |
| 3441 | } |
| 3442 | mTaskLayersChanged = false; |
| 3443 | for (int displayNdx = 0; displayNdx < mActivityDisplays.size(); displayNdx++) { |
Wale Ogunwale | a0f5b5e | 2017-10-11 09:37:23 -0700 | [diff] [blame] | 3444 | final ActivityDisplay display = mActivityDisplays.valueAt(displayNdx); |
Chong Zhang | fdcc4d4 | 2015-10-14 16:50:12 -0700 | [diff] [blame] | 3445 | int baseLayer = 0; |
Wale Ogunwale | a0f5b5e | 2017-10-11 09:37:23 -0700 | [diff] [blame] | 3446 | for (int stackNdx = display.getChildCount() - 1; stackNdx >= 0; --stackNdx) { |
| 3447 | final ActivityStack stack = display.getChildAt(stackNdx); |
| 3448 | baseLayer += stack.rankTaskLayers(baseLayer); |
Chong Zhang | fdcc4d4 | 2015-10-14 16:50:12 -0700 | [diff] [blame] | 3449 | } |
| 3450 | } |
| 3451 | } |
| 3452 | |
Dianne Hackborn | b5a380d | 2015-05-20 18:18:46 -0700 | [diff] [blame] | 3453 | void clearOtherAppTimeTrackers(AppTimeTracker except) { |
| 3454 | for (int displayNdx = mActivityDisplays.size() - 1; displayNdx >= 0; --displayNdx) { |
Wale Ogunwale | a0f5b5e | 2017-10-11 09:37:23 -0700 | [diff] [blame] | 3455 | final ActivityDisplay display = mActivityDisplays.valueAt(displayNdx); |
| 3456 | for (int stackNdx = display.getChildCount() - 1; stackNdx >= 0; --stackNdx) { |
| 3457 | final ActivityStack stack = display.getChildAt(stackNdx); |
Dianne Hackborn | b5a380d | 2015-05-20 18:18:46 -0700 | [diff] [blame] | 3458 | stack.clearOtherAppTimeTrackers(except); |
| 3459 | } |
| 3460 | } |
| 3461 | } |
| 3462 | |
Craig Mautner | 8d341ef | 2013-03-26 09:03:27 -0700 | [diff] [blame] | 3463 | void scheduleDestroyAllActivities(ProcessRecord app, String reason) { |
Craig Mautner | e0a3884 | 2013-12-16 16:14:02 -0800 | [diff] [blame] | 3464 | for (int displayNdx = mActivityDisplays.size() - 1; displayNdx >= 0; --displayNdx) { |
Wale Ogunwale | a0f5b5e | 2017-10-11 09:37:23 -0700 | [diff] [blame] | 3465 | final ActivityDisplay display = mActivityDisplays.valueAt(displayNdx); |
| 3466 | for (int stackNdx = display.getChildCount() - 1; stackNdx >= 0; --stackNdx) { |
| 3467 | final ActivityStack stack = display.getChildAt(stackNdx); |
Craig Mautner | ee2e45a | 2014-06-27 12:10:03 -0700 | [diff] [blame] | 3468 | stack.scheduleDestroyActivities(app, reason); |
Craig Mautner | 4a1cb22 | 2013-12-04 16:14:06 -0800 | [diff] [blame] | 3469 | } |
Craig Mautner | 8d341ef | 2013-03-26 09:03:27 -0700 | [diff] [blame] | 3470 | } |
| 3471 | } |
| 3472 | |
Dianne Hackborn | 89ad456 | 2014-08-24 16:45:38 -0700 | [diff] [blame] | 3473 | void releaseSomeActivitiesLocked(ProcessRecord app, String reason) { |
| 3474 | // Examine all activities currently running in the process. |
| 3475 | TaskRecord firstTask = null; |
| 3476 | // Tasks is non-null only if two or more tasks are found. |
| 3477 | ArraySet<TaskRecord> tasks = null; |
Wale Ogunwale | 0fc365c | 2015-05-25 19:35:42 -0700 | [diff] [blame] | 3478 | if (DEBUG_RELEASE) Slog.d(TAG_RELEASE, "Trying to release some activities in " + app); |
| 3479 | for (int i = 0; i < app.activities.size(); i++) { |
Dianne Hackborn | 89ad456 | 2014-08-24 16:45:38 -0700 | [diff] [blame] | 3480 | ActivityRecord r = app.activities.get(i); |
| 3481 | // First, if we find an activity that is in the process of being destroyed, |
| 3482 | // then we just aren't going to do anything for now; we want things to settle |
| 3483 | // down before we try to prune more activities. |
Wale Ogunwale | ee006da | 2015-03-30 14:49:25 -0700 | [diff] [blame] | 3484 | if (r.finishing || r.state == DESTROYING || r.state == DESTROYED) { |
Wale Ogunwale | 0fc365c | 2015-05-25 19:35:42 -0700 | [diff] [blame] | 3485 | if (DEBUG_RELEASE) Slog.d(TAG_RELEASE, "Abort release; already destroying: " + r); |
Dianne Hackborn | 89ad456 | 2014-08-24 16:45:38 -0700 | [diff] [blame] | 3486 | return; |
| 3487 | } |
| 3488 | // Don't consider any activies that are currently not in a state where they |
| 3489 | // can be destroyed. |
Wale Ogunwale | ee006da | 2015-03-30 14:49:25 -0700 | [diff] [blame] | 3490 | if (r.visible || !r.stopped || !r.haveState || r.state == RESUMED || r.state == PAUSING |
| 3491 | || r.state == PAUSED || r.state == STOPPING) { |
Wale Ogunwale | 0fc365c | 2015-05-25 19:35:42 -0700 | [diff] [blame] | 3492 | if (DEBUG_RELEASE) Slog.d(TAG_RELEASE, "Not releasing in-use activity: " + r); |
Dianne Hackborn | 89ad456 | 2014-08-24 16:45:38 -0700 | [diff] [blame] | 3493 | continue; |
| 3494 | } |
Bryce Lee | af691c0 | 2017-03-20 14:20:22 -0700 | [diff] [blame] | 3495 | |
| 3496 | final TaskRecord task = r.getTask(); |
| 3497 | if (task != null) { |
| 3498 | if (DEBUG_RELEASE) Slog.d(TAG_RELEASE, "Collecting release task " + task |
Dianne Hackborn | 89ad456 | 2014-08-24 16:45:38 -0700 | [diff] [blame] | 3499 | + " from " + r); |
| 3500 | if (firstTask == null) { |
Bryce Lee | af691c0 | 2017-03-20 14:20:22 -0700 | [diff] [blame] | 3501 | firstTask = task; |
| 3502 | } else if (firstTask != task) { |
Dianne Hackborn | 89ad456 | 2014-08-24 16:45:38 -0700 | [diff] [blame] | 3503 | if (tasks == null) { |
| 3504 | tasks = new ArraySet<>(); |
| 3505 | tasks.add(firstTask); |
| 3506 | } |
Bryce Lee | af691c0 | 2017-03-20 14:20:22 -0700 | [diff] [blame] | 3507 | tasks.add(task); |
Dianne Hackborn | 89ad456 | 2014-08-24 16:45:38 -0700 | [diff] [blame] | 3508 | } |
| 3509 | } |
| 3510 | } |
| 3511 | if (tasks == null) { |
Wale Ogunwale | 0fc365c | 2015-05-25 19:35:42 -0700 | [diff] [blame] | 3512 | if (DEBUG_RELEASE) Slog.d(TAG_RELEASE, "Didn't find two or more tasks to release"); |
Dianne Hackborn | 89ad456 | 2014-08-24 16:45:38 -0700 | [diff] [blame] | 3513 | return; |
| 3514 | } |
| 3515 | // If we have activities in multiple tasks that are in a position to be destroyed, |
| 3516 | // let's iterate through the tasks and release the oldest one. |
| 3517 | final int numDisplays = mActivityDisplays.size(); |
| 3518 | for (int displayNdx = 0; displayNdx < numDisplays; ++displayNdx) { |
Wale Ogunwale | a0f5b5e | 2017-10-11 09:37:23 -0700 | [diff] [blame] | 3519 | final ActivityDisplay display = mActivityDisplays.valueAt(displayNdx); |
| 3520 | final int stackCount = display.getChildCount(); |
Dianne Hackborn | 89ad456 | 2014-08-24 16:45:38 -0700 | [diff] [blame] | 3521 | // Step through all stacks starting from behind, to hit the oldest things first. |
Wale Ogunwale | a0f5b5e | 2017-10-11 09:37:23 -0700 | [diff] [blame] | 3522 | for (int stackNdx = 0; stackNdx < stackCount; stackNdx++) { |
| 3523 | final ActivityStack stack = display.getChildAt(stackNdx); |
Dianne Hackborn | 89ad456 | 2014-08-24 16:45:38 -0700 | [diff] [blame] | 3524 | // Try to release activities in this stack; if we manage to, we are done. |
| 3525 | if (stack.releaseSomeActivitiesLocked(app, tasks, reason) > 0) { |
| 3526 | return; |
| 3527 | } |
| 3528 | } |
| 3529 | } |
| 3530 | } |
| 3531 | |
Amith Yamasani | 37a40c2 | 2015-06-17 13:25:42 -0700 | [diff] [blame] | 3532 | boolean switchUserLocked(int userId, UserState uss) { |
Wale Ogunwale | 9a98c52 | 2016-04-27 09:23:55 -0700 | [diff] [blame] | 3533 | final int focusStackId = mFocusedStack.getStackId(); |
| 3534 | // We dismiss the docked stack whenever we switch users. |
Wale Ogunwale | a0f5b5e | 2017-10-11 09:37:23 -0700 | [diff] [blame] | 3535 | final ActivityStack dockedStack = getDefaultDisplay().getSplitScreenPrimaryStack(); |
Wale Ogunwale | 9dcf946 | 2017-09-19 15:13:01 -0700 | [diff] [blame] | 3536 | if (dockedStack != null) { |
| 3537 | moveTasksToFullscreenStackLocked(dockedStack, mFocusedStack == dockedStack); |
| 3538 | } |
Winson Chung | c2b23a5 | 2017-01-09 15:44:55 -0800 | [diff] [blame] | 3539 | // Also dismiss the pinned stack whenever we switch users. Removing the pinned stack will |
| 3540 | // also cause all tasks to be moved to the fullscreen stack at a position that is |
| 3541 | // appropriate. |
Wale Ogunwale | 44f036f | 2017-09-29 05:09:09 -0700 | [diff] [blame] | 3542 | removeStacksInWindowingModes(WINDOWING_MODE_PINNED); |
Wale Ogunwale | 9a98c52 | 2016-04-27 09:23:55 -0700 | [diff] [blame] | 3543 | |
| 3544 | mUserStackInFront.put(mCurrentUser, focusStackId); |
Wale Ogunwale | 6827856 | 2017-09-23 17:13:55 -0700 | [diff] [blame] | 3545 | final int restoreStackId = mUserStackInFront.get(userId, mHomeStack.mStackId); |
Craig Mautner | 2420ead | 2013-04-01 17:13:20 -0700 | [diff] [blame] | 3546 | mCurrentUser = userId; |
Craig Mautner | ac6f843 | 2013-07-17 13:24:59 -0700 | [diff] [blame] | 3547 | |
Craig Mautner | 858d8a6 | 2013-04-23 17:08:34 -0700 | [diff] [blame] | 3548 | mStartingUsers.add(uss); |
Craig Mautner | e0a3884 | 2013-12-16 16:14:02 -0800 | [diff] [blame] | 3549 | for (int displayNdx = mActivityDisplays.size() - 1; displayNdx >= 0; --displayNdx) { |
Wale Ogunwale | a0f5b5e | 2017-10-11 09:37:23 -0700 | [diff] [blame] | 3550 | final ActivityDisplay display = mActivityDisplays.valueAt(displayNdx); |
| 3551 | for (int stackNdx = display.getChildCount() - 1; stackNdx >= 0; --stackNdx) { |
| 3552 | final ActivityStack stack = display.getChildAt(stackNdx); |
Craig Mautner | e0a3884 | 2013-12-16 16:14:02 -0800 | [diff] [blame] | 3553 | stack.switchUserLocked(userId); |
Alexandra Gherghina | dae57a1 | 2014-03-12 19:15:26 +0000 | [diff] [blame] | 3554 | TaskRecord task = stack.topTask(); |
| 3555 | if (task != null) { |
Wale Ogunwale | 1666e31 | 2016-12-16 11:27:18 -0800 | [diff] [blame] | 3556 | stack.positionChildWindowContainerAtTop(task); |
Alexandra Gherghina | dae57a1 | 2014-03-12 19:15:26 +0000 | [diff] [blame] | 3557 | } |
Craig Mautner | 4a1cb22 | 2013-12-04 16:14:06 -0800 | [diff] [blame] | 3558 | } |
Craig Mautner | ac6f843 | 2013-07-17 13:24:59 -0700 | [diff] [blame] | 3559 | } |
Craig Mautner | 858d8a6 | 2013-04-23 17:08:34 -0700 | [diff] [blame] | 3560 | |
Craig Mautner | 4f1df4f | 2013-10-15 15:44:14 -0700 | [diff] [blame] | 3561 | ActivityStack stack = getStack(restoreStackId); |
| 3562 | if (stack == null) { |
| 3563 | stack = mHomeStack; |
| 3564 | } |
Wale Ogunwale | 6fbde9f | 2017-08-24 07:24:12 -0700 | [diff] [blame] | 3565 | final boolean homeInFront = stack.isActivityTypeHome(); |
Craig Mautner | e0a3884 | 2013-12-16 16:14:02 -0800 | [diff] [blame] | 3566 | if (stack.isOnHomeDisplay()) { |
Wale Ogunwale | 925d0d1 | 2015-09-23 15:40:07 -0700 | [diff] [blame] | 3567 | stack.moveToFront("switchUserOnHomeDisplay"); |
Craig Mautner | e0a3884 | 2013-12-16 16:14:02 -0800 | [diff] [blame] | 3568 | } else { |
| 3569 | // Stack was moved to another display while user was swapped out. |
Matthew Ng | ae1ff4f | 2016-11-10 15:49:14 -0800 | [diff] [blame] | 3570 | resumeHomeStackTask(null, "switchUserOnOtherDisplay"); |
Craig Mautner | e0a3884 | 2013-12-16 16:14:02 -0800 | [diff] [blame] | 3571 | } |
Craig Mautner | 93529a4 | 2013-10-04 15:03:13 -0700 | [diff] [blame] | 3572 | return homeInFront; |
Craig Mautner | 2219a1b | 2013-03-25 09:44:30 -0700 | [diff] [blame] | 3573 | } |
| 3574 | |
Wale Ogunwale | 0bd2aa7 | 2015-04-16 13:50:44 -0700 | [diff] [blame] | 3575 | /** Checks whether the userid is a profile of the current user. */ |
| 3576 | boolean isCurrentProfileLocked(int userId) { |
| 3577 | if (userId == mCurrentUser) return true; |
Fyodor Kupolov | 1b3edac | 2017-09-19 15:48:06 -0700 | [diff] [blame] | 3578 | return mService.mUserController.isCurrentProfile(userId); |
Wale Ogunwale | 0bd2aa7 | 2015-04-16 13:50:44 -0700 | [diff] [blame] | 3579 | } |
| 3580 | |
Bryce Lee | b7c9b80 | 2017-05-02 14:20:24 -0700 | [diff] [blame] | 3581 | /** |
| 3582 | * Returns whether a stopping activity is present that should be stopped after visible, rather |
| 3583 | * than idle. |
| 3584 | * @return {@code true} if such activity is present. {@code false} otherwise. |
| 3585 | */ |
| 3586 | boolean isStoppingNoHistoryActivity() { |
| 3587 | // Activities that are marked as nohistory should be stopped immediately after the resumed |
| 3588 | // activity has become visible. |
| 3589 | for (ActivityRecord record : mStoppingActivities) { |
| 3590 | if (record.isNoHistory()) { |
| 3591 | return true; |
| 3592 | } |
| 3593 | } |
| 3594 | |
| 3595 | return false; |
| 3596 | } |
| 3597 | |
Winson Chung | 4dabf23 | 2017-01-25 13:25:22 -0800 | [diff] [blame] | 3598 | final ArrayList<ActivityRecord> processStoppingActivitiesLocked(ActivityRecord idleActivity, |
| 3599 | boolean remove, boolean processPausingActivities) { |
Craig Mautner | de4ef02 | 2013-04-07 19:01:33 -0700 | [diff] [blame] | 3600 | ArrayList<ActivityRecord> stops = null; |
| 3601 | |
| 3602 | final boolean nowVisible = allResumedActivitiesVisible(); |
Craig Mautner | 8c14c15 | 2015-01-15 17:32:07 -0800 | [diff] [blame] | 3603 | for (int activityNdx = mStoppingActivities.size() - 1; activityNdx >= 0; --activityNdx) { |
| 3604 | ActivityRecord s = mStoppingActivities.get(activityNdx); |
Bryce Lee | 4a19438 | 2017-04-04 14:32:48 -0700 | [diff] [blame] | 3605 | boolean waitingVisible = mActivitiesWaitingForVisibleActivity.contains(s); |
Wale Ogunwale | f81c1d1 | 2016-01-12 12:20:18 -0800 | [diff] [blame] | 3606 | if (DEBUG_STATES) Slog.v(TAG, "Stopping " + s + ": nowVisible=" + nowVisible |
Craig Mautner | 8c14c15 | 2015-01-15 17:32:07 -0800 | [diff] [blame] | 3607 | + " waitingVisible=" + waitingVisible + " finishing=" + s.finishing); |
| 3608 | if (waitingVisible && nowVisible) { |
Bryce Lee | 4a19438 | 2017-04-04 14:32:48 -0700 | [diff] [blame] | 3609 | mActivitiesWaitingForVisibleActivity.remove(s); |
Andrii Kulian | ee05681 | 2016-09-21 15:34:45 -0700 | [diff] [blame] | 3610 | waitingVisible = false; |
Craig Mautner | de4ef02 | 2013-04-07 19:01:33 -0700 | [diff] [blame] | 3611 | if (s.finishing) { |
| 3612 | // If this activity is finishing, it is sitting on top of |
| 3613 | // everyone else but we now know it is no longer needed... |
| 3614 | // so get rid of it. Otherwise, we need to go through the |
| 3615 | // normal flow and hide it once we determine that it is |
| 3616 | // hidden by the activities in front of it. |
Wale Ogunwale | f81c1d1 | 2016-01-12 12:20:18 -0800 | [diff] [blame] | 3617 | if (DEBUG_STATES) Slog.v(TAG, "Before stopping, can hide: " + s); |
Wale Ogunwale | 26c0dfe | 2016-12-14 14:42:30 -0800 | [diff] [blame] | 3618 | s.setVisibility(false); |
Craig Mautner | de4ef02 | 2013-04-07 19:01:33 -0700 | [diff] [blame] | 3619 | } |
| 3620 | } |
David Stevens | 9440dc8 | 2017-03-16 19:00:20 -0700 | [diff] [blame] | 3621 | if (remove) { |
| 3622 | final ActivityStack stack = s.getStack(); |
| 3623 | final boolean shouldSleepOrShutDown = stack != null |
| 3624 | ? stack.shouldSleepOrShutDownActivities() |
| 3625 | : mService.isSleepingOrShuttingDownLocked(); |
| 3626 | if (!waitingVisible || shouldSleepOrShutDown) { |
| 3627 | if (!processPausingActivities && s.state == PAUSING) { |
| 3628 | // Defer processing pausing activities in this iteration and reschedule |
| 3629 | // a delayed idle to reprocess it again |
| 3630 | removeTimeoutsForActivityLocked(idleActivity); |
| 3631 | scheduleIdleTimeoutLocked(idleActivity); |
| 3632 | continue; |
| 3633 | } |
Winson Chung | 4dabf23 | 2017-01-25 13:25:22 -0800 | [diff] [blame] | 3634 | |
David Stevens | 9440dc8 | 2017-03-16 19:00:20 -0700 | [diff] [blame] | 3635 | if (DEBUG_STATES) Slog.v(TAG, "Ready to stop: " + s); |
| 3636 | if (stops == null) { |
| 3637 | stops = new ArrayList<>(); |
| 3638 | } |
| 3639 | stops.add(s); |
| 3640 | mStoppingActivities.remove(activityNdx); |
Craig Mautner | de4ef02 | 2013-04-07 19:01:33 -0700 | [diff] [blame] | 3641 | } |
Craig Mautner | de4ef02 | 2013-04-07 19:01:33 -0700 | [diff] [blame] | 3642 | } |
| 3643 | } |
| 3644 | |
| 3645 | return stops; |
| 3646 | } |
| 3647 | |
Craig Mautner | cf910b0 | 2013-04-23 11:23:27 -0700 | [diff] [blame] | 3648 | void validateTopActivitiesLocked() { |
Wale Ogunwale | ee006da | 2015-03-30 14:49:25 -0700 | [diff] [blame] | 3649 | for (int displayNdx = mActivityDisplays.size() - 1; displayNdx >= 0; --displayNdx) { |
Wale Ogunwale | a0f5b5e | 2017-10-11 09:37:23 -0700 | [diff] [blame] | 3650 | final ActivityDisplay display = mActivityDisplays.valueAt(displayNdx); |
| 3651 | for (int stackNdx = display.getChildCount() - 1; stackNdx >= 0; --stackNdx) { |
| 3652 | final ActivityStack stack = display.getChildAt(stackNdx); |
Filip Gruszczynski | 3e85ba2 | 2015-10-05 22:48:30 -0700 | [diff] [blame] | 3653 | final ActivityRecord r = stack.topRunningActivityLocked(); |
Wale Ogunwale | ee006da | 2015-03-30 14:49:25 -0700 | [diff] [blame] | 3654 | final ActivityState state = r == null ? DESTROYED : r.state; |
Wale Ogunwale | 1e60e0c | 2015-10-28 13:36:10 -0700 | [diff] [blame] | 3655 | if (isFocusedStack(stack)) { |
Wale Ogunwale | ee006da | 2015-03-30 14:49:25 -0700 | [diff] [blame] | 3656 | if (r == null) Slog.e(TAG, |
| 3657 | "validateTop...: null top activity, stack=" + stack); |
| 3658 | else { |
| 3659 | final ActivityRecord pausing = stack.mPausingActivity; |
| 3660 | if (pausing != null && pausing == r) Slog.e(TAG, |
| 3661 | "validateTop...: top stack has pausing activity r=" + r |
| 3662 | + " state=" + state); |
| 3663 | if (state != INITIALIZING && state != RESUMED) Slog.e(TAG, |
| 3664 | "validateTop...: activity in front not resumed r=" + r |
| 3665 | + " state=" + state); |
| 3666 | } |
Craig Mautner | cf910b0 | 2013-04-23 11:23:27 -0700 | [diff] [blame] | 3667 | } else { |
Wale Ogunwale | ee006da | 2015-03-30 14:49:25 -0700 | [diff] [blame] | 3668 | final ActivityRecord resumed = stack.mResumedActivity; |
| 3669 | if (resumed != null && resumed == r) Slog.e(TAG, |
| 3670 | "validateTop...: back stack has resumed activity r=" + r |
| 3671 | + " state=" + state); |
| 3672 | if (r != null && (state == INITIALIZING || state == RESUMED)) Slog.e(TAG, |
| 3673 | "validateTop...: activity in back resumed r=" + r + " state=" + state); |
Craig Mautner | cf910b0 | 2013-04-23 11:23:27 -0700 | [diff] [blame] | 3674 | } |
| 3675 | } |
| 3676 | } |
Craig Mautner | 76ea224 | 2013-05-15 11:40:05 -0700 | [diff] [blame] | 3677 | } |
| 3678 | |
Craig Mautner | 2708430 | 2013-03-25 08:05:25 -0700 | [diff] [blame] | 3679 | public void dump(PrintWriter pw, String prefix) { |
Craig Mautner | d1bbdb462 | 2013-10-22 09:53:20 -0700 | [diff] [blame] | 3680 | pw.print(prefix); pw.print("mFocusedStack=" + mFocusedStack); |
Craig Mautner | 4a1cb22 | 2013-12-04 16:14:06 -0800 | [diff] [blame] | 3681 | pw.print(" mLastFocusedStack="); pw.println(mLastFocusedStack); |
Suprabh Shukla | 09a88f5 | 2015-12-02 14:36:31 -0800 | [diff] [blame] | 3682 | pw.print(prefix); |
| 3683 | pw.println("mCurTaskIdForUser=" + mCurTaskIdForUser); |
Craig Mautner | d1bbdb462 | 2013-10-22 09:53:20 -0700 | [diff] [blame] | 3684 | pw.print(prefix); pw.println("mUserStackInFront=" + mUserStackInFront); |
Wale Ogunwale | 9dcf946 | 2017-09-19 15:13:01 -0700 | [diff] [blame] | 3685 | for (int i = mActivityDisplays.size() - 1; i >= 0; --i) { |
| 3686 | final ActivityDisplay display = mActivityDisplays.valueAt(i); |
Wale Ogunwale | a0f5b5e | 2017-10-11 09:37:23 -0700 | [diff] [blame] | 3687 | display.dump(pw, prefix); |
Wale Ogunwale | 9dcf946 | 2017-09-19 15:13:01 -0700 | [diff] [blame] | 3688 | } |
Bryce Lee | 4a19438 | 2017-04-04 14:32:48 -0700 | [diff] [blame] | 3689 | if (!mWaitingForActivityVisible.isEmpty()) { |
| 3690 | pw.print(prefix); pw.println("mWaitingForActivityVisible="); |
| 3691 | for (int i = 0; i < mWaitingForActivityVisible.size(); ++i) { |
| 3692 | pw.print(prefix); pw.print(prefix); mWaitingForActivityVisible.get(i).dump(pw, prefix); |
| 3693 | } |
| 3694 | } |
| 3695 | |
Jorim Jaggi | 8d78693 | 2016-10-26 19:08:36 -0700 | [diff] [blame] | 3696 | mKeyguardController.dump(pw, prefix); |
Benjamin Franz | a83859f | 2017-07-03 16:34:14 +0100 | [diff] [blame] | 3697 | mService.mLockTaskController.dump(pw, prefix); |
Craig Mautner | 2708430 | 2013-03-25 08:05:25 -0700 | [diff] [blame] | 3698 | } |
Craig Mautner | 8d341ef | 2013-03-26 09:03:27 -0700 | [diff] [blame] | 3699 | |
Yi Jin | 129fc6c | 2017-09-28 15:48:38 -0700 | [diff] [blame] | 3700 | public void writeToProto(ProtoOutputStream proto) { |
Adrian Roos | 4921ccf | 2017-09-28 16:54:06 +0200 | [diff] [blame] | 3701 | super.writeToProto(proto, CONFIGURATION_CONTAINER, false /* trim */); |
Steven Timotius | 4346f0a | 2017-09-12 11:07:21 -0700 | [diff] [blame] | 3702 | for (int displayNdx = 0; displayNdx < mActivityDisplays.size(); ++displayNdx) { |
| 3703 | ActivityDisplay activityDisplay = mActivityDisplays.valueAt(displayNdx); |
| 3704 | activityDisplay.writeToProto(proto, DISPLAYS); |
| 3705 | } |
| 3706 | mKeyguardController.writeToProto(proto, KEYGUARD_CONTROLLER); |
| 3707 | if (mFocusedStack != null) { |
| 3708 | proto.write(FOCUSED_STACK_ID, mFocusedStack.mStackId); |
| 3709 | ActivityRecord focusedActivity = getResumedActivityLocked(); |
| 3710 | if (focusedActivity != null) { |
| 3711 | focusedActivity.writeIdentifierToProto(proto, RESUMED_ACTIVITY); |
| 3712 | } |
| 3713 | } else { |
| 3714 | proto.write(FOCUSED_STACK_ID, INVALID_STACK_ID); |
| 3715 | } |
Steven Timotius | 4346f0a | 2017-09-12 11:07:21 -0700 | [diff] [blame] | 3716 | } |
| 3717 | |
Winson | 43d1f26 | 2016-06-14 16:05:55 -0700 | [diff] [blame] | 3718 | /** |
Andrii Kulian | 5406e7a | 2016-10-21 11:55:23 -0700 | [diff] [blame] | 3719 | * Dump all connected displays' configurations. |
| 3720 | * @param prefix Prefix to apply to each line of the dump. |
| 3721 | */ |
| 3722 | void dumpDisplayConfigs(PrintWriter pw, String prefix) { |
| 3723 | pw.print(prefix); pw.println("Display override configurations:"); |
| 3724 | final int displayCount = mActivityDisplays.size(); |
| 3725 | for (int i = 0; i < displayCount; i++) { |
| 3726 | final ActivityDisplay activityDisplay = mActivityDisplays.valueAt(i); |
| 3727 | pw.print(prefix); pw.print(" "); pw.print(activityDisplay.mDisplayId); pw.print(": "); |
| 3728 | pw.println(activityDisplay.getOverrideConfiguration()); |
| 3729 | } |
| 3730 | } |
| 3731 | |
| 3732 | /** |
Winson | 43d1f26 | 2016-06-14 16:05:55 -0700 | [diff] [blame] | 3733 | * Dumps the activities matching the given {@param name} in the either the focused stack |
| 3734 | * or all visible stacks if {@param dumpVisibleStacks} is true. |
| 3735 | */ |
Winson Chung | 6998bc4 | 2017-02-28 17:07:05 -0800 | [diff] [blame] | 3736 | ArrayList<ActivityRecord> getDumpActivitiesLocked(String name, boolean dumpVisibleStacksOnly, |
| 3737 | boolean dumpFocusedStackOnly) { |
| 3738 | if (dumpFocusedStackOnly) { |
| 3739 | return mFocusedStack.getDumpActivitiesLocked(name); |
| 3740 | } else { |
Winson | 43d1f26 | 2016-06-14 16:05:55 -0700 | [diff] [blame] | 3741 | ArrayList<ActivityRecord> activities = new ArrayList<>(); |
| 3742 | int numDisplays = mActivityDisplays.size(); |
| 3743 | for (int displayNdx = 0; displayNdx < numDisplays; ++displayNdx) { |
Wale Ogunwale | a0f5b5e | 2017-10-11 09:37:23 -0700 | [diff] [blame] | 3744 | final ActivityDisplay display = mActivityDisplays.valueAt(displayNdx); |
| 3745 | for (int stackNdx = display.getChildCount() - 1; stackNdx >= 0; --stackNdx) { |
| 3746 | final ActivityStack stack = display.getChildAt(stackNdx); |
Wale Ogunwale | 9dcf946 | 2017-09-19 15:13:01 -0700 | [diff] [blame] | 3747 | if (!dumpVisibleStacksOnly || stack.shouldBeVisible(null)) { |
Winson | 43d1f26 | 2016-06-14 16:05:55 -0700 | [diff] [blame] | 3748 | activities.addAll(stack.getDumpActivitiesLocked(name)); |
| 3749 | } |
| 3750 | } |
| 3751 | } |
| 3752 | return activities; |
Winson | 43d1f26 | 2016-06-14 16:05:55 -0700 | [diff] [blame] | 3753 | } |
Craig Mautner | 20e7227 | 2013-04-01 13:45:53 -0700 | [diff] [blame] | 3754 | } |
| 3755 | |
Dianne Hackborn | 390517b | 2013-05-30 15:03:32 -0700 | [diff] [blame] | 3756 | static boolean printThisActivity(PrintWriter pw, ActivityRecord activity, String dumpPackage, |
| 3757 | boolean needSep, String prefix) { |
| 3758 | if (activity != null) { |
| 3759 | if (dumpPackage == null || dumpPackage.equals(activity.packageName)) { |
| 3760 | if (needSep) { |
| 3761 | pw.println(); |
Dianne Hackborn | 390517b | 2013-05-30 15:03:32 -0700 | [diff] [blame] | 3762 | } |
| 3763 | pw.print(prefix); |
| 3764 | pw.println(activity); |
Dianne Hackborn | 7ad34e5 | 2013-06-05 18:41:45 -0700 | [diff] [blame] | 3765 | return true; |
Dianne Hackborn | 390517b | 2013-05-30 15:03:32 -0700 | [diff] [blame] | 3766 | } |
| 3767 | } |
Dianne Hackborn | 7ad34e5 | 2013-06-05 18:41:45 -0700 | [diff] [blame] | 3768 | return false; |
Dianne Hackborn | 390517b | 2013-05-30 15:03:32 -0700 | [diff] [blame] | 3769 | } |
| 3770 | |
Craig Mautner | 8d341ef | 2013-03-26 09:03:27 -0700 | [diff] [blame] | 3771 | boolean dumpActivitiesLocked(FileDescriptor fd, PrintWriter pw, boolean dumpAll, |
| 3772 | boolean dumpClient, String dumpPackage) { |
Dianne Hackborn | 7ad34e5 | 2013-06-05 18:41:45 -0700 | [diff] [blame] | 3773 | boolean printed = false; |
| 3774 | boolean needSep = false; |
Craig Mautner | e0a3884 | 2013-12-16 16:14:02 -0800 | [diff] [blame] | 3775 | for (int displayNdx = 0; displayNdx < mActivityDisplays.size(); ++displayNdx) { |
| 3776 | ActivityDisplay activityDisplay = mActivityDisplays.valueAt(displayNdx); |
Craig Mautner | ee2e45a | 2014-06-27 12:10:03 -0700 | [diff] [blame] | 3777 | pw.print("Display #"); pw.print(activityDisplay.mDisplayId); |
Craig Mautner | 737fae2 | 2014-10-15 12:52:10 -0700 | [diff] [blame] | 3778 | pw.println(" (activities from top to bottom):"); |
Wale Ogunwale | a0f5b5e | 2017-10-11 09:37:23 -0700 | [diff] [blame] | 3779 | final ActivityDisplay display = mActivityDisplays.valueAt(displayNdx); |
| 3780 | for (int stackNdx = display.getChildCount() - 1; stackNdx >= 0; --stackNdx) { |
| 3781 | final ActivityStack stack = display.getChildAt(stackNdx); |
Wale Ogunwale | 34a5b57 | 2017-08-31 08:29:41 -0700 | [diff] [blame] | 3782 | pw.println(); |
Wale Ogunwale | 44f036f | 2017-09-29 05:09:09 -0700 | [diff] [blame] | 3783 | pw.println(" Stack #" + stack.mStackId |
Wale Ogunwale | 6191149 | 2017-10-11 08:50:50 -0700 | [diff] [blame] | 3784 | + ": type=" + activityTypeToString(stack.getActivityType()) |
| 3785 | + " mode=" + windowingModeToString(stack.getWindowingMode())); |
Wale Ogunwale | 34a5b57 | 2017-08-31 08:29:41 -0700 | [diff] [blame] | 3786 | pw.println(" isSleeping=" + stack.shouldSleepActivities()); |
Bryce Lee | f3c6a47 | 2017-11-14 14:53:06 -0800 | [diff] [blame] | 3787 | pw.println(" mBounds=" + stack.getOverrideBounds()); |
Winson Chung | abb433b | 2017-03-24 09:35:42 -0700 | [diff] [blame] | 3788 | |
Wale Ogunwale | 34a5b57 | 2017-08-31 08:29:41 -0700 | [diff] [blame] | 3789 | printed |= stack.dumpActivitiesLocked(fd, pw, dumpAll, dumpClient, dumpPackage, |
| 3790 | needSep); |
Winson Chung | abb433b | 2017-03-24 09:35:42 -0700 | [diff] [blame] | 3791 | |
Craig Mautner | 4a1cb22 | 2013-12-04 16:14:06 -0800 | [diff] [blame] | 3792 | printed |= dumpHistoryList(fd, pw, stack.mLRUActivities, " ", "Run", false, |
| 3793 | !dumpAll, false, dumpPackage, true, |
| 3794 | " Running activities (most recent first):", null); |
Craig Mautner | 8d341ef | 2013-03-26 09:03:27 -0700 | [diff] [blame] | 3795 | |
Craig Mautner | 4a1cb22 | 2013-12-04 16:14:06 -0800 | [diff] [blame] | 3796 | needSep = printed; |
| 3797 | boolean pr = printThisActivity(pw, stack.mPausingActivity, dumpPackage, needSep, |
| 3798 | " mPausingActivity: "); |
Dianne Hackborn | 7ad34e5 | 2013-06-05 18:41:45 -0700 | [diff] [blame] | 3799 | if (pr) { |
| 3800 | printed = true; |
Craig Mautner | 4a1cb22 | 2013-12-04 16:14:06 -0800 | [diff] [blame] | 3801 | needSep = false; |
Dianne Hackborn | 7ad34e5 | 2013-06-05 18:41:45 -0700 | [diff] [blame] | 3802 | } |
Craig Mautner | 4a1cb22 | 2013-12-04 16:14:06 -0800 | [diff] [blame] | 3803 | pr = printThisActivity(pw, stack.mResumedActivity, dumpPackage, needSep, |
| 3804 | " mResumedActivity: "); |
| 3805 | if (pr) { |
| 3806 | printed = true; |
| 3807 | needSep = false; |
| 3808 | } |
| 3809 | if (dumpAll) { |
| 3810 | pr = printThisActivity(pw, stack.mLastPausedActivity, dumpPackage, needSep, |
| 3811 | " mLastPausedActivity: "); |
| 3812 | if (pr) { |
| 3813 | printed = true; |
| 3814 | needSep = true; |
| 3815 | } |
| 3816 | printed |= printThisActivity(pw, stack.mLastNoHistoryActivity, dumpPackage, |
| 3817 | needSep, " mLastNoHistoryActivity: "); |
| 3818 | } |
| 3819 | needSep = printed; |
Craig Mautner | 8d341ef | 2013-03-26 09:03:27 -0700 | [diff] [blame] | 3820 | } |
| 3821 | } |
| 3822 | |
Dianne Hackborn | 7ad34e5 | 2013-06-05 18:41:45 -0700 | [diff] [blame] | 3823 | printed |= dumpHistoryList(fd, pw, mFinishingActivities, " ", "Fin", false, !dumpAll, |
| 3824 | false, dumpPackage, true, " Activities waiting to finish:", null); |
| 3825 | printed |= dumpHistoryList(fd, pw, mStoppingActivities, " ", "Stop", false, !dumpAll, |
| 3826 | false, dumpPackage, true, " Activities waiting to stop:", null); |
Bryce Lee | 4a19438 | 2017-04-04 14:32:48 -0700 | [diff] [blame] | 3827 | printed |= dumpHistoryList(fd, pw, mActivitiesWaitingForVisibleActivity, " ", "Wait", |
| 3828 | false, !dumpAll, false, dumpPackage, true, |
| 3829 | " Activities waiting for another to become visible:", null); |
Dianne Hackborn | 7ad34e5 | 2013-06-05 18:41:45 -0700 | [diff] [blame] | 3830 | printed |= dumpHistoryList(fd, pw, mGoingToSleepActivities, " ", "Sleep", false, !dumpAll, |
| 3831 | false, dumpPackage, true, " Activities waiting to sleep:", null); |
Craig Mautner | f333327 | 2013-04-22 10:55:53 -0700 | [diff] [blame] | 3832 | |
Dianne Hackborn | 7ad34e5 | 2013-06-05 18:41:45 -0700 | [diff] [blame] | 3833 | return printed; |
Craig Mautner | 8d341ef | 2013-03-26 09:03:27 -0700 | [diff] [blame] | 3834 | } |
| 3835 | |
Dianne Hackborn | 390517b | 2013-05-30 15:03:32 -0700 | [diff] [blame] | 3836 | static boolean dumpHistoryList(FileDescriptor fd, PrintWriter pw, List<ActivityRecord> list, |
Craig Mautner | 8d341ef | 2013-03-26 09:03:27 -0700 | [diff] [blame] | 3837 | String prefix, String label, boolean complete, boolean brief, boolean client, |
Wale Ogunwale | 34a5b57 | 2017-08-31 08:29:41 -0700 | [diff] [blame] | 3838 | String dumpPackage, boolean needNL, String header, TaskRecord lastTask) { |
Dianne Hackborn | 390517b | 2013-05-30 15:03:32 -0700 | [diff] [blame] | 3839 | String innerPrefix = null; |
| 3840 | String[] args = null; |
| 3841 | boolean printed = false; |
Craig Mautner | 8d341ef | 2013-03-26 09:03:27 -0700 | [diff] [blame] | 3842 | for (int i=list.size()-1; i>=0; i--) { |
| 3843 | final ActivityRecord r = list.get(i); |
| 3844 | if (dumpPackage != null && !dumpPackage.equals(r.packageName)) { |
| 3845 | continue; |
| 3846 | } |
Dianne Hackborn | 390517b | 2013-05-30 15:03:32 -0700 | [diff] [blame] | 3847 | if (innerPrefix == null) { |
| 3848 | innerPrefix = prefix + " "; |
| 3849 | args = new String[0]; |
| 3850 | } |
| 3851 | printed = true; |
Craig Mautner | 8d341ef | 2013-03-26 09:03:27 -0700 | [diff] [blame] | 3852 | final boolean full = !brief && (complete || !r.isInHistory()); |
| 3853 | if (needNL) { |
Dianne Hackborn | 390517b | 2013-05-30 15:03:32 -0700 | [diff] [blame] | 3854 | pw.println(""); |
Craig Mautner | 8d341ef | 2013-03-26 09:03:27 -0700 | [diff] [blame] | 3855 | needNL = false; |
| 3856 | } |
Wale Ogunwale | 34a5b57 | 2017-08-31 08:29:41 -0700 | [diff] [blame] | 3857 | if (header != null) { |
| 3858 | pw.println(header); |
| 3859 | header = null; |
Dianne Hackborn | 390517b | 2013-05-30 15:03:32 -0700 | [diff] [blame] | 3860 | } |
Bryce Lee | af691c0 | 2017-03-20 14:20:22 -0700 | [diff] [blame] | 3861 | if (lastTask != r.getTask()) { |
| 3862 | lastTask = r.getTask(); |
Craig Mautner | 8d341ef | 2013-03-26 09:03:27 -0700 | [diff] [blame] | 3863 | pw.print(prefix); |
| 3864 | pw.print(full ? "* " : " "); |
| 3865 | pw.println(lastTask); |
| 3866 | if (full) { |
| 3867 | lastTask.dump(pw, prefix + " "); |
| 3868 | } else if (complete) { |
| 3869 | // Complete + brief == give a summary. Isn't that obvious?!? |
| 3870 | if (lastTask.intent != null) { |
| 3871 | pw.print(prefix); pw.print(" "); |
| 3872 | pw.println(lastTask.intent.toInsecureStringWithClip()); |
| 3873 | } |
| 3874 | } |
| 3875 | } |
| 3876 | pw.print(prefix); pw.print(full ? " * " : " "); pw.print(label); |
| 3877 | pw.print(" #"); pw.print(i); pw.print(": "); |
| 3878 | pw.println(r); |
| 3879 | if (full) { |
| 3880 | r.dump(pw, innerPrefix); |
| 3881 | } else if (complete) { |
| 3882 | // Complete + brief == give a summary. Isn't that obvious?!? |
| 3883 | pw.print(innerPrefix); pw.println(r.intent.toInsecureString()); |
| 3884 | if (r.app != null) { |
| 3885 | pw.print(innerPrefix); pw.println(r.app); |
| 3886 | } |
| 3887 | } |
| 3888 | if (client && r.app != null && r.app.thread != null) { |
| 3889 | // flush anything that is already in the PrintWriter since the thread is going |
| 3890 | // to write to the file descriptor directly |
| 3891 | pw.flush(); |
| 3892 | try { |
| 3893 | TransferPipe tp = new TransferPipe(); |
| 3894 | try { |
Sudheer Shanka | cc6418f | 2016-10-13 12:03:44 -0700 | [diff] [blame] | 3895 | r.app.thread.dumpActivity(tp.getWriteFd(), r.appToken, innerPrefix, args); |
Craig Mautner | 8d341ef | 2013-03-26 09:03:27 -0700 | [diff] [blame] | 3896 | // Short timeout, since blocking here can |
| 3897 | // deadlock with the application. |
| 3898 | tp.go(fd, 2000); |
| 3899 | } finally { |
| 3900 | tp.kill(); |
| 3901 | } |
| 3902 | } catch (IOException e) { |
| 3903 | pw.println(innerPrefix + "Failure while dumping the activity: " + e); |
| 3904 | } catch (RemoteException e) { |
| 3905 | pw.println(innerPrefix + "Got a RemoteException while dumping the activity"); |
| 3906 | } |
| 3907 | needNL = true; |
| 3908 | } |
| 3909 | } |
Dianne Hackborn | 390517b | 2013-05-30 15:03:32 -0700 | [diff] [blame] | 3910 | return printed; |
Craig Mautner | 8d341ef | 2013-03-26 09:03:27 -0700 | [diff] [blame] | 3911 | } |
Craig Mautner | ce5f3cb | 2013-04-22 08:58:54 -0700 | [diff] [blame] | 3912 | |
Craig Mautner | f333327 | 2013-04-22 10:55:53 -0700 | [diff] [blame] | 3913 | void scheduleIdleTimeoutLocked(ActivityRecord next) { |
Wale Ogunwale | 0fc365c | 2015-05-25 19:35:42 -0700 | [diff] [blame] | 3914 | if (DEBUG_IDLE) Slog.d(TAG_IDLE, |
| 3915 | "scheduleIdleTimeoutLocked: Callers=" + Debug.getCallers(4)); |
Craig Mautner | c64f73e | 2013-04-24 16:44:56 -0700 | [diff] [blame] | 3916 | Message msg = mHandler.obtainMessage(IDLE_TIMEOUT_MSG, next); |
| 3917 | mHandler.sendMessageDelayed(msg, IDLE_TIMEOUT); |
Craig Mautner | f333327 | 2013-04-22 10:55:53 -0700 | [diff] [blame] | 3918 | } |
| 3919 | |
| 3920 | final void scheduleIdleLocked() { |
Craig Mautner | 05d2903 | 2013-05-03 13:40:13 -0700 | [diff] [blame] | 3921 | mHandler.sendEmptyMessage(IDLE_NOW_MSG); |
Craig Mautner | f333327 | 2013-04-22 10:55:53 -0700 | [diff] [blame] | 3922 | } |
| 3923 | |
| 3924 | void removeTimeoutsForActivityLocked(ActivityRecord r) { |
Wale Ogunwale | 0fc365c | 2015-05-25 19:35:42 -0700 | [diff] [blame] | 3925 | if (DEBUG_IDLE) Slog.d(TAG_IDLE, "removeTimeoutsForActivity: Callers=" |
| 3926 | + Debug.getCallers(4)); |
Craig Mautner | f333327 | 2013-04-22 10:55:53 -0700 | [diff] [blame] | 3927 | mHandler.removeMessages(IDLE_TIMEOUT_MSG, r); |
| 3928 | } |
| 3929 | |
Craig Mautner | 05d2903 | 2013-05-03 13:40:13 -0700 | [diff] [blame] | 3930 | final void scheduleResumeTopActivities() { |
Craig Mautner | 34b73df | 2014-01-12 21:11:08 -0800 | [diff] [blame] | 3931 | if (!mHandler.hasMessages(RESUME_TOP_ACTIVITY_MSG)) { |
| 3932 | mHandler.sendEmptyMessage(RESUME_TOP_ACTIVITY_MSG); |
| 3933 | } |
Craig Mautner | 05d2903 | 2013-05-03 13:40:13 -0700 | [diff] [blame] | 3934 | } |
| 3935 | |
Craig Mautner | 0eea92c | 2013-05-16 13:35:39 -0700 | [diff] [blame] | 3936 | void removeSleepTimeouts() { |
Craig Mautner | 0eea92c | 2013-05-16 13:35:39 -0700 | [diff] [blame] | 3937 | mHandler.removeMessages(SLEEP_TIMEOUT_MSG); |
| 3938 | } |
| 3939 | |
| 3940 | final void scheduleSleepTimeout() { |
| 3941 | removeSleepTimeouts(); |
| 3942 | mHandler.sendEmptyMessageDelayed(SLEEP_TIMEOUT_MSG, SLEEP_TIMEOUT); |
| 3943 | } |
| 3944 | |
Craig Mautner | 4a1cb22 | 2013-12-04 16:14:06 -0800 | [diff] [blame] | 3945 | @Override |
| 3946 | public void onDisplayAdded(int displayId) { |
Dianne Hackborn | fb81d09 | 2015-08-03 17:14:46 -0700 | [diff] [blame] | 3947 | if (DEBUG_STACK) Slog.v(TAG, "Display added displayId=" + displayId); |
Craig Mautner | 4a1cb22 | 2013-12-04 16:14:06 -0800 | [diff] [blame] | 3948 | mHandler.sendMessage(mHandler.obtainMessage(HANDLE_DISPLAY_ADDED, displayId, 0)); |
| 3949 | } |
| 3950 | |
| 3951 | @Override |
| 3952 | public void onDisplayRemoved(int displayId) { |
Dianne Hackborn | fb81d09 | 2015-08-03 17:14:46 -0700 | [diff] [blame] | 3953 | if (DEBUG_STACK) Slog.v(TAG, "Display removed displayId=" + displayId); |
Craig Mautner | 4a1cb22 | 2013-12-04 16:14:06 -0800 | [diff] [blame] | 3954 | mHandler.sendMessage(mHandler.obtainMessage(HANDLE_DISPLAY_REMOVED, displayId, 0)); |
| 3955 | } |
| 3956 | |
| 3957 | @Override |
| 3958 | public void onDisplayChanged(int displayId) { |
Dianne Hackborn | fb81d09 | 2015-08-03 17:14:46 -0700 | [diff] [blame] | 3959 | if (DEBUG_STACK) Slog.v(TAG, "Display changed displayId=" + displayId); |
Craig Mautner | 4a1cb22 | 2013-12-04 16:14:06 -0800 | [diff] [blame] | 3960 | mHandler.sendMessage(mHandler.obtainMessage(HANDLE_DISPLAY_CHANGED, displayId, 0)); |
| 3961 | } |
| 3962 | |
Wale Ogunwale | f16a281 | 2015-04-01 11:23:15 -0700 | [diff] [blame] | 3963 | private void handleDisplayAdded(int displayId) { |
Craig Mautner | 4a1cb22 | 2013-12-04 16:14:06 -0800 | [diff] [blame] | 3964 | synchronized (mService) { |
Andrii Kulian | 62e6f25 | 2017-05-30 22:46:53 -0700 | [diff] [blame] | 3965 | getActivityDisplayOrCreateLocked(displayId); |
Craig Mautner | 4a1cb22 | 2013-12-04 16:14:06 -0800 | [diff] [blame] | 3966 | } |
Craig Mautner | 4a1cb22 | 2013-12-04 16:14:06 -0800 | [diff] [blame] | 3967 | } |
| 3968 | |
Andrii Kulian | ca007a6 | 2016-11-22 16:33:28 -0800 | [diff] [blame] | 3969 | /** Check if display with specified id is added to the list. */ |
| 3970 | boolean isDisplayAdded(int displayId) { |
Andrii Kulian | 62e6f25 | 2017-05-30 22:46:53 -0700 | [diff] [blame] | 3971 | return getActivityDisplayOrCreateLocked(displayId) != null; |
| 3972 | } |
| 3973 | |
Wale Ogunwale | 04a05ac | 2017-09-17 21:35:02 -0700 | [diff] [blame] | 3974 | // TODO: Look into consolidating with getActivityDisplayOrCreateLocked() |
Andrii Kulian | 94e82d9b0 | 2017-07-13 15:33:06 -0700 | [diff] [blame] | 3975 | ActivityDisplay getActivityDisplay(int displayId) { |
| 3976 | return mActivityDisplays.get(displayId); |
| 3977 | } |
| 3978 | |
Wale Ogunwale | 04a05ac | 2017-09-17 21:35:02 -0700 | [diff] [blame] | 3979 | // TODO(multi-display): Look at all callpoints to make sure they make sense in multi-display. |
| 3980 | ActivityDisplay getDefaultDisplay() { |
| 3981 | return mActivityDisplays.get(DEFAULT_DISPLAY); |
| 3982 | } |
| 3983 | |
Andrii Kulian | 62e6f25 | 2017-05-30 22:46:53 -0700 | [diff] [blame] | 3984 | /** |
| 3985 | * Get an existing instance of {@link ActivityDisplay} or create new if there is a |
| 3986 | * corresponding record in display manager. |
| 3987 | */ |
Wale Ogunwale | 04a05ac | 2017-09-17 21:35:02 -0700 | [diff] [blame] | 3988 | // TODO: Look into consolidating with getActivityDisplay() |
| 3989 | ActivityDisplay getActivityDisplayOrCreateLocked(int displayId) { |
Andrii Kulian | 62e6f25 | 2017-05-30 22:46:53 -0700 | [diff] [blame] | 3990 | ActivityDisplay activityDisplay = mActivityDisplays.get(displayId); |
| 3991 | if (activityDisplay != null) { |
| 3992 | return activityDisplay; |
| 3993 | } |
| 3994 | if (mDisplayManager == null) { |
| 3995 | // The system isn't fully initialized yet. |
| 3996 | return null; |
| 3997 | } |
| 3998 | final Display display = mDisplayManager.getDisplay(displayId); |
| 3999 | if (display == null) { |
| 4000 | // The display is not registered in DisplayManager. |
| 4001 | return null; |
| 4002 | } |
| 4003 | // The display hasn't been added to ActivityManager yet, create a new record now. |
Wale Ogunwale | 9dcf946 | 2017-09-19 15:13:01 -0700 | [diff] [blame] | 4004 | activityDisplay = new ActivityDisplay(this, displayId); |
| 4005 | attachDisplay(activityDisplay); |
Andrii Kulian | 62e6f25 | 2017-05-30 22:46:53 -0700 | [diff] [blame] | 4006 | calculateDefaultMinimalSizeOfResizeableTasks(activityDisplay); |
| 4007 | mWindowManager.onDisplayAdded(displayId); |
| 4008 | return activityDisplay; |
Andrii Kulian | ca007a6 | 2016-11-22 16:33:28 -0800 | [diff] [blame] | 4009 | } |
| 4010 | |
Wale Ogunwale | 9dcf946 | 2017-09-19 15:13:01 -0700 | [diff] [blame] | 4011 | @VisibleForTesting |
| 4012 | void attachDisplay(ActivityDisplay display) { |
| 4013 | mActivityDisplays.put(display.mDisplayId, display); |
| 4014 | } |
| 4015 | |
Filip Gruszczynski | d2f1d94 | 2015-10-14 15:10:12 -0700 | [diff] [blame] | 4016 | private void calculateDefaultMinimalSizeOfResizeableTasks(ActivityDisplay display) { |
Andrii Kulian | f66a83d | 2016-05-17 12:17:44 -0700 | [diff] [blame] | 4017 | mDefaultMinSizeOfResizeableTask = |
Jorim Jaggi | 19cf297 | 2016-04-07 23:26:10 -0700 | [diff] [blame] | 4018 | mService.mContext.getResources().getDimensionPixelSize( |
| 4019 | com.android.internal.R.dimen.default_minimal_size_resizable_task); |
Filip Gruszczynski | d2f1d94 | 2015-10-14 15:10:12 -0700 | [diff] [blame] | 4020 | } |
| 4021 | |
Wale Ogunwale | f16a281 | 2015-04-01 11:23:15 -0700 | [diff] [blame] | 4022 | private void handleDisplayRemoved(int displayId) { |
Andrii Kulian | a33818c | 2017-02-16 16:11:30 -0800 | [diff] [blame] | 4023 | if (displayId == DEFAULT_DISPLAY) { |
| 4024 | throw new IllegalArgumentException("Can't remove the primary display."); |
| 4025 | } |
| 4026 | |
Craig Mautner | 4a1cb22 | 2013-12-04 16:14:06 -0800 | [diff] [blame] | 4027 | synchronized (mService) { |
Wale Ogunwale | a0f5b5e | 2017-10-11 09:37:23 -0700 | [diff] [blame] | 4028 | final ActivityDisplay activityDisplay = mActivityDisplays.get(displayId); |
| 4029 | if (activityDisplay == null) { |
| 4030 | return; |
Craig Mautner | 4a1cb22 | 2013-12-04 16:14:06 -0800 | [diff] [blame] | 4031 | } |
Wale Ogunwale | a0f5b5e | 2017-10-11 09:37:23 -0700 | [diff] [blame] | 4032 | final boolean destroyContentOnRemoval |
| 4033 | = activityDisplay.shouldDestroyContentOnRemove(); |
| 4034 | while (activityDisplay.getChildCount() > 0) { |
| 4035 | final ActivityStack stack = activityDisplay.getChildAt(0); |
| 4036 | if (destroyContentOnRemoval) { |
| 4037 | moveStackToDisplayLocked(stack.mStackId, DEFAULT_DISPLAY, false /* onTop */); |
| 4038 | stack.finishAllActivitiesLocked(true /* immediately */); |
| 4039 | } else { |
| 4040 | // Moving all tasks to fullscreen stack, because it's guaranteed to be |
| 4041 | // a valid launch stack for all activities. This way the task history from |
| 4042 | // external display will be preserved on primary after move. |
| 4043 | moveTasksToFullscreenStackLocked(stack, true /* onTop */); |
| 4044 | } |
| 4045 | } |
| 4046 | |
| 4047 | releaseSleepTokens(activityDisplay); |
| 4048 | |
| 4049 | mActivityDisplays.remove(displayId); |
| 4050 | mWindowManager.onDisplayRemoved(displayId); |
Craig Mautner | 4a1cb22 | 2013-12-04 16:14:06 -0800 | [diff] [blame] | 4051 | } |
Craig Mautner | 4a1cb22 | 2013-12-04 16:14:06 -0800 | [diff] [blame] | 4052 | } |
| 4053 | |
Wale Ogunwale | f16a281 | 2015-04-01 11:23:15 -0700 | [diff] [blame] | 4054 | private void handleDisplayChanged(int displayId) { |
Craig Mautner | 4a1cb22 | 2013-12-04 16:14:06 -0800 | [diff] [blame] | 4055 | synchronized (mService) { |
Craig Mautner | e0a3884 | 2013-12-16 16:14:02 -0800 | [diff] [blame] | 4056 | ActivityDisplay activityDisplay = mActivityDisplays.get(displayId); |
Bryce Lee | f3c6a47 | 2017-11-14 14:53:06 -0800 | [diff] [blame] | 4057 | // TODO: The following code block should be moved into {@link ActivityDisplay}. |
Craig Mautner | e0a3884 | 2013-12-16 16:14:02 -0800 | [diff] [blame] | 4058 | if (activityDisplay != null) { |
David Stevens | 9440dc8 | 2017-03-16 19:00:20 -0700 | [diff] [blame] | 4059 | // The window policy is responsible for stopping activities on the default display |
| 4060 | if (displayId != Display.DEFAULT_DISPLAY) { |
| 4061 | int displayState = activityDisplay.mDisplay.getState(); |
| 4062 | if (displayState == Display.STATE_OFF && activityDisplay.mOffToken == null) { |
| 4063 | activityDisplay.mOffToken = |
| 4064 | mService.acquireSleepToken("Display-off", displayId); |
| 4065 | } else if (displayState == Display.STATE_ON |
| 4066 | && activityDisplay.mOffToken != null) { |
| 4067 | activityDisplay.mOffToken.release(); |
| 4068 | activityDisplay.mOffToken = null; |
| 4069 | } |
| 4070 | } |
Bryce Lee | f3c6a47 | 2017-11-14 14:53:06 -0800 | [diff] [blame] | 4071 | |
| 4072 | activityDisplay.updateBounds(); |
Craig Mautner | 4a1cb22 | 2013-12-04 16:14:06 -0800 | [diff] [blame] | 4073 | } |
Bryce Lee | af3a400 | 2017-03-20 10:37:12 -0700 | [diff] [blame] | 4074 | mWindowManager.onDisplayChanged(displayId); |
Craig Mautner | 4a1cb22 | 2013-12-04 16:14:06 -0800 | [diff] [blame] | 4075 | } |
Craig Mautner | 4a1cb22 | 2013-12-04 16:14:06 -0800 | [diff] [blame] | 4076 | } |
| 4077 | |
David Stevens | 9440dc8 | 2017-03-16 19:00:20 -0700 | [diff] [blame] | 4078 | SleepToken createSleepTokenLocked(String tag, int displayId) { |
| 4079 | ActivityDisplay display = mActivityDisplays.get(displayId); |
| 4080 | if (display == null) { |
| 4081 | throw new IllegalArgumentException("Invalid display: " + displayId); |
| 4082 | } |
| 4083 | |
| 4084 | final SleepTokenImpl token = new SleepTokenImpl(tag, displayId); |
| 4085 | mSleepTokens.add(token); |
| 4086 | display.mAllSleepTokens.add(token); |
| 4087 | return token; |
| 4088 | } |
| 4089 | |
| 4090 | private void removeSleepTokenLocked(SleepTokenImpl token) { |
| 4091 | mSleepTokens.remove(token); |
| 4092 | |
| 4093 | ActivityDisplay display = mActivityDisplays.get(token.mDisplayId); |
| 4094 | if (display != null) { |
| 4095 | display.mAllSleepTokens.remove(token); |
| 4096 | if (display.mAllSleepTokens.isEmpty()) { |
| 4097 | mService.updateSleepIfNeededLocked(); |
| 4098 | } |
| 4099 | } |
| 4100 | } |
| 4101 | |
| 4102 | private void releaseSleepTokens(ActivityDisplay display) { |
| 4103 | if (display.mAllSleepTokens.isEmpty()) { |
| 4104 | return; |
| 4105 | } |
Wale Ogunwale | 9dcf946 | 2017-09-19 15:13:01 -0700 | [diff] [blame] | 4106 | for (SleepToken token : display.mAllSleepTokens) { |
David Stevens | 9440dc8 | 2017-03-16 19:00:20 -0700 | [diff] [blame] | 4107 | mSleepTokens.remove(token); |
| 4108 | } |
| 4109 | display.mAllSleepTokens.clear(); |
| 4110 | |
| 4111 | mService.updateSleepIfNeededLocked(); |
| 4112 | } |
| 4113 | |
Wale Ogunwale | 6827856 | 2017-09-23 17:13:55 -0700 | [diff] [blame] | 4114 | private StackInfo getStackInfo(ActivityStack stack) { |
Andrii Kulian | 7e215d7 | 2017-04-26 18:33:28 -0700 | [diff] [blame] | 4115 | final int displayId = stack.mDisplayId; |
| 4116 | final ActivityDisplay display = mActivityDisplays.get(displayId); |
Craig Mautner | 4a1cb22 | 2013-12-04 16:14:06 -0800 | [diff] [blame] | 4117 | StackInfo info = new StackInfo(); |
Wale Ogunwale | 1666e31 | 2016-12-16 11:27:18 -0800 | [diff] [blame] | 4118 | stack.getWindowContainerBounds(info.bounds); |
Andrii Kulian | 7e215d7 | 2017-04-26 18:33:28 -0700 | [diff] [blame] | 4119 | info.displayId = displayId; |
Craig Mautner | 4a1cb22 | 2013-12-04 16:14:06 -0800 | [diff] [blame] | 4120 | info.stackId = stack.mStackId; |
Filip Gruszczynski | 21199bd | 2015-12-02 12:49:58 -0800 | [diff] [blame] | 4121 | info.userId = stack.mCurrentUser; |
Wale Ogunwale | 9dcf946 | 2017-09-19 15:13:01 -0700 | [diff] [blame] | 4122 | info.visible = stack.shouldBeVisible(null); |
Andrii Kulian | 62e6f25 | 2017-05-30 22:46:53 -0700 | [diff] [blame] | 4123 | // A stack might be not attached to a display. |
Wale Ogunwale | a0f5b5e | 2017-10-11 09:37:23 -0700 | [diff] [blame] | 4124 | info.position = display != null ? display.getIndexOf(stack) : 0; |
Wale Ogunwale | 6827856 | 2017-09-23 17:13:55 -0700 | [diff] [blame] | 4125 | info.configuration.setTo(stack.getConfiguration()); |
Craig Mautner | 4a1cb22 | 2013-12-04 16:14:06 -0800 | [diff] [blame] | 4126 | |
| 4127 | ArrayList<TaskRecord> tasks = stack.getAllTasks(); |
| 4128 | final int numTasks = tasks.size(); |
| 4129 | int[] taskIds = new int[numTasks]; |
| 4130 | String[] taskNames = new String[numTasks]; |
Wale Ogunwale | e4a0c57 | 2015-06-30 08:40:31 -0700 | [diff] [blame] | 4131 | Rect[] taskBounds = new Rect[numTasks]; |
Filip Gruszczynski | 21199bd | 2015-12-02 12:49:58 -0800 | [diff] [blame] | 4132 | int[] taskUserIds = new int[numTasks]; |
Craig Mautner | 4a1cb22 | 2013-12-04 16:14:06 -0800 | [diff] [blame] | 4133 | for (int i = 0; i < numTasks; ++i) { |
| 4134 | final TaskRecord task = tasks.get(i); |
| 4135 | taskIds[i] = task.taskId; |
| 4136 | taskNames[i] = task.origActivity != null ? task.origActivity.flattenToString() |
| 4137 | : task.realActivity != null ? task.realActivity.flattenToString() |
| 4138 | : task.getTopActivity() != null ? task.getTopActivity().packageName |
| 4139 | : "unknown"; |
Wale Ogunwale | e4a0c57 | 2015-06-30 08:40:31 -0700 | [diff] [blame] | 4140 | taskBounds[i] = new Rect(); |
Wale Ogunwale | e1fe7fa2 | 2016-12-15 18:27:00 -0800 | [diff] [blame] | 4141 | task.getWindowContainerBounds(taskBounds[i]); |
Filip Gruszczynski | 21199bd | 2015-12-02 12:49:58 -0800 | [diff] [blame] | 4142 | taskUserIds[i] = task.userId; |
Craig Mautner | 4a1cb22 | 2013-12-04 16:14:06 -0800 | [diff] [blame] | 4143 | } |
| 4144 | info.taskIds = taskIds; |
| 4145 | info.taskNames = taskNames; |
Wale Ogunwale | 868a5e1 | 2015-08-02 16:19:20 -0700 | [diff] [blame] | 4146 | info.taskBounds = taskBounds; |
Filip Gruszczynski | 21199bd | 2015-12-02 12:49:58 -0800 | [diff] [blame] | 4147 | info.taskUserIds = taskUserIds; |
Winson | d46b727 | 2016-04-20 11:54:27 -0700 | [diff] [blame] | 4148 | |
| 4149 | final ActivityRecord top = stack.topRunningActivityLocked(); |
| 4150 | info.topActivity = top != null ? top.intent.getComponent() : null; |
Craig Mautner | 4a1cb22 | 2013-12-04 16:14:06 -0800 | [diff] [blame] | 4151 | return info; |
| 4152 | } |
| 4153 | |
Wale Ogunwale | 6827856 | 2017-09-23 17:13:55 -0700 | [diff] [blame] | 4154 | StackInfo getStackInfo(int stackId) { |
Craig Mautner | 4a1cb22 | 2013-12-04 16:14:06 -0800 | [diff] [blame] | 4155 | ActivityStack stack = getStack(stackId); |
| 4156 | if (stack != null) { |
Wale Ogunwale | 6827856 | 2017-09-23 17:13:55 -0700 | [diff] [blame] | 4157 | return getStackInfo(stack); |
Craig Mautner | 4a1cb22 | 2013-12-04 16:14:06 -0800 | [diff] [blame] | 4158 | } |
| 4159 | return null; |
| 4160 | } |
| 4161 | |
Wale Ogunwale | 6827856 | 2017-09-23 17:13:55 -0700 | [diff] [blame] | 4162 | StackInfo getStackInfo(int windowingMode, int activityType) { |
| 4163 | final ActivityStack stack = getStack(windowingMode, activityType); |
| 4164 | return (stack != null) ? getStackInfo(stack) : null; |
| 4165 | } |
| 4166 | |
Craig Mautner | 4a1cb22 | 2013-12-04 16:14:06 -0800 | [diff] [blame] | 4167 | ArrayList<StackInfo> getAllStackInfosLocked() { |
Wale Ogunwale | e4a0c57 | 2015-06-30 08:40:31 -0700 | [diff] [blame] | 4168 | ArrayList<StackInfo> list = new ArrayList<>(); |
Craig Mautner | e0a3884 | 2013-12-16 16:14:02 -0800 | [diff] [blame] | 4169 | for (int displayNdx = 0; displayNdx < mActivityDisplays.size(); ++displayNdx) { |
Wale Ogunwale | a0f5b5e | 2017-10-11 09:37:23 -0700 | [diff] [blame] | 4170 | final ActivityDisplay display = mActivityDisplays.valueAt(displayNdx); |
| 4171 | for (int stackNdx = display.getChildCount() - 1; stackNdx >= 0; --stackNdx) { |
| 4172 | final ActivityStack stack = display.getChildAt(stackNdx); |
| 4173 | list.add(getStackInfo(stack)); |
Craig Mautner | 4a1cb22 | 2013-12-04 16:14:06 -0800 | [diff] [blame] | 4174 | } |
| 4175 | } |
| 4176 | return list; |
| 4177 | } |
| 4178 | |
Wale Ogunwale | 0568aed | 2017-09-08 13:29:37 -0700 | [diff] [blame] | 4179 | void handleNonResizableTaskIfNeeded(TaskRecord task, int preferredWindowingMode, |
Wale Ogunwale | a0f5b5e | 2017-10-11 09:37:23 -0700 | [diff] [blame] | 4180 | int preferredDisplayId, ActivityStack actualStack) { |
Wale Ogunwale | 0568aed | 2017-09-08 13:29:37 -0700 | [diff] [blame] | 4181 | handleNonResizableTaskIfNeeded(task, preferredWindowingMode, preferredDisplayId, |
Wale Ogunwale | a0f5b5e | 2017-10-11 09:37:23 -0700 | [diff] [blame] | 4182 | actualStack, false /* forceNonResizable */); |
Andrii Kulian | c2791664 | 2016-04-12 17:59:27 -0700 | [diff] [blame] | 4183 | } |
| 4184 | |
Wale Ogunwale | 0568aed | 2017-09-08 13:29:37 -0700 | [diff] [blame] | 4185 | void handleNonResizableTaskIfNeeded(TaskRecord task, int preferredWindowingMode, |
Wale Ogunwale | a0f5b5e | 2017-10-11 09:37:23 -0700 | [diff] [blame] | 4186 | int preferredDisplayId, ActivityStack actualStack, boolean forceNonResizable) { |
Andrii Kulian | 036e3ad | 2017-04-19 10:55:10 -0700 | [diff] [blame] | 4187 | final boolean isSecondaryDisplayPreferred = |
Wale Ogunwale | 0568aed | 2017-09-08 13:29:37 -0700 | [diff] [blame] | 4188 | (preferredDisplayId != DEFAULT_DISPLAY && preferredDisplayId != INVALID_DISPLAY); |
Wale Ogunwale | 926aade | 2017-08-29 11:24:37 -0700 | [diff] [blame] | 4189 | final boolean inSplitScreenMode = actualStack != null |
Wale Ogunwale | 7e1f5f5 | 2017-10-18 15:19:59 -0700 | [diff] [blame] | 4190 | && actualStack.getDisplay().hasSplitScreenPrimaryStack(); |
Wale Ogunwale | 0568aed | 2017-09-08 13:29:37 -0700 | [diff] [blame] | 4191 | if (((!inSplitScreenMode && preferredWindowingMode != WINDOWING_MODE_SPLIT_SCREEN_PRIMARY) |
Wale Ogunwale | 7e1f5f5 | 2017-10-18 15:19:59 -0700 | [diff] [blame] | 4192 | && !isSecondaryDisplayPreferred) || !task.isActivityTypeStandardOrUndefined()) { |
Wale Ogunwale | b9b16a7 | 2016-01-27 12:24:44 -0800 | [diff] [blame] | 4193 | return; |
| 4194 | } |
| 4195 | |
Andrii Kulian | 036e3ad | 2017-04-19 10:55:10 -0700 | [diff] [blame] | 4196 | // Handle incorrect launch/move to secondary display if needed. |
Andrii Kulian | 036e3ad | 2017-04-19 10:55:10 -0700 | [diff] [blame] | 4197 | if (isSecondaryDisplayPreferred) { |
Wale Ogunwale | 2b07da8 | 2017-11-08 14:52:40 -0800 | [diff] [blame] | 4198 | final boolean launchOnSecondaryDisplayFailed; |
Andrii Kulian | 036e3ad | 2017-04-19 10:55:10 -0700 | [diff] [blame] | 4199 | final int actualDisplayId = task.getStack().mDisplayId; |
| 4200 | if (!task.canBeLaunchedOnDisplay(actualDisplayId)) { |
| 4201 | // The task landed on an inappropriate display somehow, move it to the default |
| 4202 | // display. |
| 4203 | // TODO(multi-display): Find proper stack for the task on the default display. |
Wale Ogunwale | 44f036f | 2017-09-29 05:09:09 -0700 | [diff] [blame] | 4204 | mService.setTaskWindowingMode(task.taskId, |
| 4205 | WINDOWING_MODE_FULLSCREEN_OR_SPLIT_SCREEN_SECONDARY, true /* toTop */); |
Andrii Kulian | 036e3ad | 2017-04-19 10:55:10 -0700 | [diff] [blame] | 4206 | launchOnSecondaryDisplayFailed = true; |
| 4207 | } else { |
| 4208 | // The task might have landed on a display different from requested. |
| 4209 | launchOnSecondaryDisplayFailed = actualDisplayId == DEFAULT_DISPLAY |
| 4210 | || (preferredDisplayId != INVALID_DISPLAY |
| 4211 | && preferredDisplayId != actualDisplayId); |
| 4212 | } |
Andrii Kulian | 036e3ad | 2017-04-19 10:55:10 -0700 | [diff] [blame] | 4213 | if (launchOnSecondaryDisplayFailed) { |
| 4214 | // Display a warning toast that we tried to put a non-resizeable task on a secondary |
| 4215 | // display with config different from global config. |
| 4216 | mService.mTaskChangeNotificationController |
| 4217 | .notifyActivityLaunchOnSecondaryDisplayFailed(); |
Wale Ogunwale | 2b07da8 | 2017-11-08 14:52:40 -0800 | [diff] [blame] | 4218 | return; |
Andrii Kulian | 036e3ad | 2017-04-19 10:55:10 -0700 | [diff] [blame] | 4219 | } |
Wale Ogunwale | 2b07da8 | 2017-11-08 14:52:40 -0800 | [diff] [blame] | 4220 | } |
| 4221 | |
Wale Ogunwale | 2b07da8 | 2017-11-08 14:52:40 -0800 | [diff] [blame] | 4222 | if (!task.supportsSplitScreenWindowingMode() || forceNonResizable) { |
Wale Ogunwale | 30e441d | 2017-11-09 08:28:45 -0800 | [diff] [blame] | 4223 | // Display a warning toast that we tried to put an app that doesn't support split-screen |
| 4224 | // in split-screen. |
Wale Ogunwale | 2b07da8 | 2017-11-08 14:52:40 -0800 | [diff] [blame] | 4225 | mService.mTaskChangeNotificationController.notifyActivityDismissingDockedStack(); |
Jorim Jaggi | d53f092 | 2016-04-06 22:16:23 -0700 | [diff] [blame] | 4226 | |
Andrii Kulian | c2791664 | 2016-04-12 17:59:27 -0700 | [diff] [blame] | 4227 | // Dismiss docked stack. If task appeared to be in docked stack but is not resizable - |
| 4228 | // 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] | 4229 | |
Wale Ogunwale | 2b07da8 | 2017-11-08 14:52:40 -0800 | [diff] [blame] | 4230 | final ActivityStack dockedStack = |
| 4231 | task.getStack().getDisplay().getSplitScreenPrimaryStack(); |
Wale Ogunwale | 9dcf946 | 2017-09-19 15:13:01 -0700 | [diff] [blame] | 4232 | if (dockedStack != null) { |
Wale Ogunwale | a0f5b5e | 2017-10-11 09:37:23 -0700 | [diff] [blame] | 4233 | moveTasksToFullscreenStackLocked(dockedStack, actualStack == dockedStack); |
Wale Ogunwale | 9dcf946 | 2017-09-19 15:13:01 -0700 | [diff] [blame] | 4234 | } |
Wale Ogunwale | 2b07da8 | 2017-11-08 14:52:40 -0800 | [diff] [blame] | 4235 | return; |
| 4236 | } |
| 4237 | |
Wale Ogunwale | 30e441d | 2017-11-09 08:28:45 -0800 | [diff] [blame] | 4238 | final ActivityRecord topActivity = task.getTopActivity(); |
Wale Ogunwale | 2b07da8 | 2017-11-08 14:52:40 -0800 | [diff] [blame] | 4239 | if (topActivity != null && topActivity.isNonResizableOrForcedResizable() |
| 4240 | && !topActivity.noDisplay) { |
Andrii Kulian | 036e3ad | 2017-04-19 10:55:10 -0700 | [diff] [blame] | 4241 | final String packageName = topActivity.appInfo.packageName; |
| 4242 | final int reason = isSecondaryDisplayPreferred |
| 4243 | ? FORCED_RESIZEABLE_REASON_SECONDARY_DISPLAY |
| 4244 | : FORCED_RESIZEABLE_REASON_SPLIT_SCREEN; |
Yorke Lee | bd54c2a | 2016-10-25 13:49:23 -0700 | [diff] [blame] | 4245 | mService.mTaskChangeNotificationController.notifyActivityForcedResizable( |
Andrii Kulian | 036e3ad | 2017-04-19 10:55:10 -0700 | [diff] [blame] | 4246 | task.taskId, reason, packageName); |
Wale Ogunwale | b9b16a7 | 2016-01-27 12:24:44 -0800 | [diff] [blame] | 4247 | } |
Chong Zhang | b15758a | 2015-11-17 12:12:03 -0800 | [diff] [blame] | 4248 | } |
| 4249 | |
Jorim Jaggi | fe89d12 | 2015-12-22 16:28:44 +0100 | [diff] [blame] | 4250 | void activityRelaunchedLocked(IBinder token) { |
| 4251 | mWindowManager.notifyAppRelaunchingFinished(token); |
David Stevens | 9440dc8 | 2017-03-16 19:00:20 -0700 | [diff] [blame] | 4252 | final ActivityRecord r = ActivityRecord.isInStackLocked(token); |
| 4253 | if (r != null) { |
| 4254 | if (r.getStack().shouldSleepOrShutDownActivities()) { |
Wale Ogunwale | 3e99736 | 2016-09-06 10:37:56 -0700 | [diff] [blame] | 4255 | r.setSleeping(true, true); |
| 4256 | } |
| 4257 | } |
Jorim Jaggi | fe89d12 | 2015-12-22 16:28:44 +0100 | [diff] [blame] | 4258 | } |
| 4259 | |
| 4260 | void activityRelaunchingLocked(ActivityRecord r) { |
| 4261 | mWindowManager.notifyAppRelaunching(r.appToken); |
| 4262 | } |
| 4263 | |
Filip Gruszczynski | 77d9448 | 2015-12-11 13:59:52 -0800 | [diff] [blame] | 4264 | void logStackState() { |
| 4265 | mActivityMetricsLogger.logWindowState(); |
| 4266 | } |
| 4267 | |
Winson Chung | 5af42fc | 2017-03-24 17:11:33 -0700 | [diff] [blame] | 4268 | void scheduleUpdateMultiWindowMode(TaskRecord task) { |
Winson Chung | 8bca9e4 | 2017-04-16 15:59:43 -0700 | [diff] [blame] | 4269 | // If the stack is animating in a way where we will be forcing a multi-mode change at the |
| 4270 | // end, then ensure that we defer all in between multi-window mode changes |
| 4271 | if (task.getStack().deferScheduleMultiWindowModeChanged()) { |
| 4272 | return; |
| 4273 | } |
| 4274 | |
Wale Ogunwale | 22e2526 | 2016-02-01 10:32:02 -0800 | [diff] [blame] | 4275 | for (int i = task.mActivities.size() - 1; i >= 0; i--) { |
| 4276 | final ActivityRecord r = task.mActivities.get(i); |
| 4277 | if (r.app != null && r.app.thread != null) { |
| 4278 | mMultiWindowModeChangedActivities.add(r); |
| 4279 | } |
| 4280 | } |
| 4281 | |
| 4282 | if (!mHandler.hasMessages(REPORT_MULTI_WINDOW_MODE_CHANGED_MSG)) { |
| 4283 | mHandler.sendEmptyMessage(REPORT_MULTI_WINDOW_MODE_CHANGED_MSG); |
| 4284 | } |
| 4285 | } |
| 4286 | |
Winson Chung | 5af42fc | 2017-03-24 17:11:33 -0700 | [diff] [blame] | 4287 | void scheduleUpdatePictureInPictureModeIfNeeded(TaskRecord task, ActivityStack prevStack) { |
Andrii Kulian | 02b7a83 | 2016-10-06 23:11:56 -0700 | [diff] [blame] | 4288 | final ActivityStack stack = task.getStack(); |
Wale Ogunwale | 22e2526 | 2016-02-01 10:32:02 -0800 | [diff] [blame] | 4289 | if (prevStack == null || prevStack == stack |
Wale Ogunwale | 44f036f | 2017-09-29 05:09:09 -0700 | [diff] [blame] | 4290 | || (!prevStack.inPinnedWindowingMode() && !stack.inPinnedWindowingMode())) { |
Wale Ogunwale | 22e2526 | 2016-02-01 10:32:02 -0800 | [diff] [blame] | 4291 | return; |
| 4292 | } |
| 4293 | |
Bryce Lee | f3c6a47 | 2017-11-14 14:53:06 -0800 | [diff] [blame] | 4294 | scheduleUpdatePictureInPictureModeIfNeeded(task, stack.getOverrideBounds()); |
Winson Chung | 5af42fc | 2017-03-24 17:11:33 -0700 | [diff] [blame] | 4295 | } |
Wale Ogunwale | 22e2526 | 2016-02-01 10:32:02 -0800 | [diff] [blame] | 4296 | |
Winson Chung | ab76bbc | 2017-08-14 13:33:51 -0700 | [diff] [blame] | 4297 | void scheduleUpdatePictureInPictureModeIfNeeded(TaskRecord task, Rect targetStackBounds) { |
| 4298 | for (int i = task.mActivities.size() - 1; i >= 0; i--) { |
| 4299 | final ActivityRecord r = task.mActivities.get(i); |
| 4300 | if (r.app != null && r.app.thread != null) { |
| 4301 | mPipModeChangedActivities.add(r); |
Winson Chung | 5af42fc | 2017-03-24 17:11:33 -0700 | [diff] [blame] | 4302 | } |
Winson Chung | ab76bbc | 2017-08-14 13:33:51 -0700 | [diff] [blame] | 4303 | } |
| 4304 | mPipModeChangedTargetStackBounds = targetStackBounds; |
Winson Chung | 5af42fc | 2017-03-24 17:11:33 -0700 | [diff] [blame] | 4305 | |
Winson Chung | ab76bbc | 2017-08-14 13:33:51 -0700 | [diff] [blame] | 4306 | if (!mHandler.hasMessages(REPORT_PIP_MODE_CHANGED_MSG)) { |
| 4307 | mHandler.sendEmptyMessage(REPORT_PIP_MODE_CHANGED_MSG); |
| 4308 | } |
| 4309 | } |
| 4310 | |
| 4311 | void updatePictureInPictureMode(TaskRecord task, Rect targetStackBounds, boolean forceUpdate) { |
| 4312 | mHandler.removeMessages(REPORT_PIP_MODE_CHANGED_MSG); |
| 4313 | for (int i = task.mActivities.size() - 1; i >= 0; i--) { |
| 4314 | final ActivityRecord r = task.mActivities.get(i); |
| 4315 | if (r.app != null && r.app.thread != null) { |
| 4316 | r.updatePictureInPictureMode(targetStackBounds, forceUpdate); |
Winson Chung | 5af42fc | 2017-03-24 17:11:33 -0700 | [diff] [blame] | 4317 | } |
Wale Ogunwale | 22e2526 | 2016-02-01 10:32:02 -0800 | [diff] [blame] | 4318 | } |
| 4319 | } |
| 4320 | |
Tony Mak | 853304c | 2016-04-18 15:17:41 +0100 | [diff] [blame] | 4321 | void setDockedStackMinimized(boolean minimized) { |
| 4322 | mIsDockMinimized = minimized; |
Tony Mak | 853304c | 2016-04-18 15:17:41 +0100 | [diff] [blame] | 4323 | } |
| 4324 | |
chaviw | 59b9885 | 2017-06-13 12:05:44 -0700 | [diff] [blame] | 4325 | void wakeUp(String reason) { |
| 4326 | mPowerManager.wakeUp(SystemClock.uptimeMillis(), "android.server.am:TURN_ON:" + reason); |
| 4327 | } |
| 4328 | |
| 4329 | /** |
| 4330 | * Begin deferring resume to avoid duplicate resumes in one pass. |
| 4331 | */ |
| 4332 | private void beginDeferResume() { |
| 4333 | mDeferResumeCount++; |
| 4334 | } |
| 4335 | |
| 4336 | /** |
| 4337 | * End deferring resume and determine if resume can be called. |
| 4338 | */ |
| 4339 | private void endDeferResume() { |
| 4340 | mDeferResumeCount--; |
| 4341 | } |
| 4342 | |
| 4343 | /** |
| 4344 | * @return True if resume can be called. |
| 4345 | */ |
| 4346 | private boolean readyToResume() { |
| 4347 | return mDeferResumeCount == 0; |
| 4348 | } |
| 4349 | |
Craig Mautner | ce5f3cb | 2013-04-22 08:58:54 -0700 | [diff] [blame] | 4350 | private final class ActivityStackSupervisorHandler extends Handler { |
Craig Mautner | f333327 | 2013-04-22 10:55:53 -0700 | [diff] [blame] | 4351 | |
Craig Mautner | ce5f3cb | 2013-04-22 08:58:54 -0700 | [diff] [blame] | 4352 | public ActivityStackSupervisorHandler(Looper looper) { |
| 4353 | super(looper); |
| 4354 | } |
| 4355 | |
Winson Chung | 4dabf23 | 2017-01-25 13:25:22 -0800 | [diff] [blame] | 4356 | void activityIdleInternal(ActivityRecord r, boolean processPausingActivities) { |
Craig Mautner | f333327 | 2013-04-22 10:55:53 -0700 | [diff] [blame] | 4357 | synchronized (mService) { |
Winson Chung | 4dabf23 | 2017-01-25 13:25:22 -0800 | [diff] [blame] | 4358 | activityIdleInternalLocked(r != null ? r.appToken : null, true /* fromTimeout */, |
| 4359 | processPausingActivities, null); |
Craig Mautner | f333327 | 2013-04-22 10:55:53 -0700 | [diff] [blame] | 4360 | } |
Craig Mautner | 7ea5bd4 | 2013-07-05 15:27:08 -0700 | [diff] [blame] | 4361 | } |
| 4362 | |
Craig Mautner | ce5f3cb | 2013-04-22 08:58:54 -0700 | [diff] [blame] | 4363 | @Override |
| 4364 | public void handleMessage(Message msg) { |
| 4365 | switch (msg.what) { |
Wale Ogunwale | 22e2526 | 2016-02-01 10:32:02 -0800 | [diff] [blame] | 4366 | case REPORT_MULTI_WINDOW_MODE_CHANGED_MSG: { |
| 4367 | synchronized (mService) { |
| 4368 | for (int i = mMultiWindowModeChangedActivities.size() - 1; i >= 0; i--) { |
| 4369 | final ActivityRecord r = mMultiWindowModeChangedActivities.remove(i); |
Winson Chung | 5af42fc | 2017-03-24 17:11:33 -0700 | [diff] [blame] | 4370 | r.updateMultiWindowMode(); |
Wale Ogunwale | 22e2526 | 2016-02-01 10:32:02 -0800 | [diff] [blame] | 4371 | } |
| 4372 | } |
| 4373 | } break; |
| 4374 | case REPORT_PIP_MODE_CHANGED_MSG: { |
| 4375 | synchronized (mService) { |
| 4376 | for (int i = mPipModeChangedActivities.size() - 1; i >= 0; i--) { |
| 4377 | final ActivityRecord r = mPipModeChangedActivities.remove(i); |
Winson Chung | ab76bbc | 2017-08-14 13:33:51 -0700 | [diff] [blame] | 4378 | r.updatePictureInPictureMode(mPipModeChangedTargetStackBounds, |
| 4379 | false /* forceUpdate */); |
Wale Ogunwale | 22e2526 | 2016-02-01 10:32:02 -0800 | [diff] [blame] | 4380 | } |
| 4381 | } |
| 4382 | } break; |
Craig Mautner | f333327 | 2013-04-22 10:55:53 -0700 | [diff] [blame] | 4383 | case IDLE_TIMEOUT_MSG: { |
Wale Ogunwale | 0fc365c | 2015-05-25 19:35:42 -0700 | [diff] [blame] | 4384 | if (DEBUG_IDLE) Slog.d(TAG_IDLE, |
| 4385 | "handleMessage: IDLE_TIMEOUT_MSG: r=" + msg.obj); |
Craig Mautner | f333327 | 2013-04-22 10:55:53 -0700 | [diff] [blame] | 4386 | // We don't at this point know if the activity is fullscreen, |
| 4387 | // so we need to be conservative and assume it isn't. |
Winson Chung | 4dabf23 | 2017-01-25 13:25:22 -0800 | [diff] [blame] | 4388 | activityIdleInternal((ActivityRecord) msg.obj, |
| 4389 | true /* processPausingActivities */); |
Craig Mautner | f333327 | 2013-04-22 10:55:53 -0700 | [diff] [blame] | 4390 | } break; |
| 4391 | case IDLE_NOW_MSG: { |
Wale Ogunwale | 0fc365c | 2015-05-25 19:35:42 -0700 | [diff] [blame] | 4392 | 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] | 4393 | activityIdleInternal((ActivityRecord) msg.obj, |
| 4394 | false /* processPausingActivities */); |
Craig Mautner | f333327 | 2013-04-22 10:55:53 -0700 | [diff] [blame] | 4395 | } break; |
Craig Mautner | 05d2903 | 2013-05-03 13:40:13 -0700 | [diff] [blame] | 4396 | case RESUME_TOP_ACTIVITY_MSG: { |
| 4397 | synchronized (mService) { |
Wale Ogunwale | d046a01 | 2015-12-24 13:05:59 -0800 | [diff] [blame] | 4398 | resumeFocusedStackTopActivityLocked(); |
Craig Mautner | 05d2903 | 2013-05-03 13:40:13 -0700 | [diff] [blame] | 4399 | } |
| 4400 | } break; |
Craig Mautner | 0eea92c | 2013-05-16 13:35:39 -0700 | [diff] [blame] | 4401 | case SLEEP_TIMEOUT_MSG: { |
| 4402 | synchronized (mService) { |
Fyodor Kupolov | 9b80b94 | 2016-06-16 16:29:05 -0700 | [diff] [blame] | 4403 | if (mService.isSleepingOrShuttingDownLocked()) { |
Craig Mautner | 0eea92c | 2013-05-16 13:35:39 -0700 | [diff] [blame] | 4404 | Slog.w(TAG, "Sleep timeout! Sleeping now."); |
David Stevens | 9440dc8 | 2017-03-16 19:00:20 -0700 | [diff] [blame] | 4405 | checkReadyForSleepLocked(false /* allowDelay */); |
Craig Mautner | 0eea92c | 2013-05-16 13:35:39 -0700 | [diff] [blame] | 4406 | } |
| 4407 | } |
| 4408 | } break; |
Craig Mautner | 7ea5bd4 | 2013-07-05 15:27:08 -0700 | [diff] [blame] | 4409 | case LAUNCH_TIMEOUT_MSG: { |
Craig Mautner | 7ea5bd4 | 2013-07-05 15:27:08 -0700 | [diff] [blame] | 4410 | synchronized (mService) { |
| 4411 | if (mLaunchingActivity.isHeld()) { |
| 4412 | Slog.w(TAG, "Launch timeout has expired, giving up wake lock!"); |
| 4413 | if (VALIDATE_WAKE_LOCK_CALLER |
| 4414 | && Binder.getCallingUid() != Process.myUid()) { |
| 4415 | throw new IllegalStateException("Calling must be system uid"); |
| 4416 | } |
| 4417 | mLaunchingActivity.release(); |
| 4418 | } |
| 4419 | } |
| 4420 | } break; |
Craig Mautner | 4a1cb22 | 2013-12-04 16:14:06 -0800 | [diff] [blame] | 4421 | case HANDLE_DISPLAY_ADDED: { |
Wale Ogunwale | f16a281 | 2015-04-01 11:23:15 -0700 | [diff] [blame] | 4422 | handleDisplayAdded(msg.arg1); |
Craig Mautner | 4a1cb22 | 2013-12-04 16:14:06 -0800 | [diff] [blame] | 4423 | } break; |
| 4424 | case HANDLE_DISPLAY_CHANGED: { |
Wale Ogunwale | f16a281 | 2015-04-01 11:23:15 -0700 | [diff] [blame] | 4425 | handleDisplayChanged(msg.arg1); |
Craig Mautner | 4a1cb22 | 2013-12-04 16:14:06 -0800 | [diff] [blame] | 4426 | } break; |
| 4427 | case HANDLE_DISPLAY_REMOVED: { |
Wale Ogunwale | f16a281 | 2015-04-01 11:23:15 -0700 | [diff] [blame] | 4428 | handleDisplayRemoved(msg.arg1); |
Craig Mautner | 4a1cb22 | 2013-12-04 16:14:06 -0800 | [diff] [blame] | 4429 | } break; |
Craig Mautner | bb74246 | 2014-07-07 15:28:55 -0700 | [diff] [blame] | 4430 | case LAUNCH_TASK_BEHIND_COMPLETE: { |
| 4431 | synchronized (mService) { |
Wale Ogunwale | 7d70117 | 2015-03-11 15:36:30 -0700 | [diff] [blame] | 4432 | ActivityRecord r = ActivityRecord.forTokenLocked((IBinder) msg.obj); |
Craig Mautner | bb74246 | 2014-07-07 15:28:55 -0700 | [diff] [blame] | 4433 | if (r != null) { |
| 4434 | handleLaunchTaskBehindCompleteLocked(r); |
| 4435 | } |
| 4436 | } |
| 4437 | } break; |
Chong Zhang | c806d90 | 2015-11-30 09:44:27 -0800 | [diff] [blame] | 4438 | |
Craig Mautner | ce5f3cb | 2013-04-22 08:58:54 -0700 | [diff] [blame] | 4439 | } |
| 4440 | } |
| 4441 | } |
Craig Mautner | ed6649f | 2013-12-02 14:08:25 -0800 | [diff] [blame] | 4442 | |
Filip Gruszczynski | caae14e | 2015-12-16 14:40:04 -0800 | [diff] [blame] | 4443 | ActivityStack findStackBehind(ActivityStack stack) { |
| 4444 | // TODO(multi-display): We are only looking for stacks on the default display. |
Jorim Jaggi | fe76234 | 2016-10-13 14:33:27 +0200 | [diff] [blame] | 4445 | final ActivityDisplay display = mActivityDisplays.get(DEFAULT_DISPLAY); |
Filip Gruszczynski | caae14e | 2015-12-16 14:40:04 -0800 | [diff] [blame] | 4446 | if (display == null) { |
| 4447 | return null; |
| 4448 | } |
Wale Ogunwale | a0f5b5e | 2017-10-11 09:37:23 -0700 | [diff] [blame] | 4449 | for (int i = display.getChildCount() - 1; i >= 0; i--) { |
| 4450 | if (display.getChildAt(i) == stack && i > 0) { |
| 4451 | return display.getChildAt(i - 1); |
Filip Gruszczynski | caae14e | 2015-12-16 14:40:04 -0800 | [diff] [blame] | 4452 | } |
| 4453 | } |
| 4454 | throw new IllegalStateException("Failed to find a stack behind stack=" + stack |
Wale Ogunwale | a0f5b5e | 2017-10-11 09:37:23 -0700 | [diff] [blame] | 4455 | + " in=" + display); |
Filip Gruszczynski | caae14e | 2015-12-16 14:40:04 -0800 | [diff] [blame] | 4456 | } |
Jorim Jaggi | 0b46f3c | 2016-03-14 12:21:37 +0100 | [diff] [blame] | 4457 | |
Jorim Jaggi | c69bd22 | 2016-03-15 14:38:37 +0100 | [diff] [blame] | 4458 | /** |
| 4459 | * Puts a task into resizing mode during the next app transition. |
| 4460 | * |
Wale Ogunwale | e1fe7fa2 | 2016-12-15 18:27:00 -0800 | [diff] [blame] | 4461 | * @param task The task to put into resizing mode |
Jorim Jaggi | c69bd22 | 2016-03-15 14:38:37 +0100 | [diff] [blame] | 4462 | */ |
Wale Ogunwale | e1fe7fa2 | 2016-12-15 18:27:00 -0800 | [diff] [blame] | 4463 | private void setResizingDuringAnimation(TaskRecord task) { |
| 4464 | mResizingTasksDuringAnimation.add(task.taskId); |
| 4465 | task.setTaskDockedResizing(true); |
Jorim Jaggi | c69bd22 | 2016-03-15 14:38:37 +0100 | [diff] [blame] | 4466 | } |
| 4467 | |
Wale Ogunwale | ab5de37 | 2017-10-18 06:46:31 -0700 | [diff] [blame] | 4468 | int startActivityFromRecents(int taskId, Bundle bOptions) { |
Jorim Jaggi | 0b46f3c | 2016-03-14 12:21:37 +0100 | [diff] [blame] | 4469 | final TaskRecord task; |
| 4470 | final int callingUid; |
| 4471 | final String callingPackage; |
| 4472 | final Intent intent; |
| 4473 | final int userId; |
Wale Ogunwale | 0568aed | 2017-09-08 13:29:37 -0700 | [diff] [blame] | 4474 | int activityType = ACTIVITY_TYPE_UNDEFINED; |
| 4475 | int windowingMode = WINDOWING_MODE_UNDEFINED; |
Jorim Jaggi | 0b46f3c | 2016-03-14 12:21:37 +0100 | [diff] [blame] | 4476 | final ActivityOptions activityOptions = (bOptions != null) |
| 4477 | ? new ActivityOptions(bOptions) : null; |
Wale Ogunwale | 0568aed | 2017-09-08 13:29:37 -0700 | [diff] [blame] | 4478 | if (activityOptions != null) { |
| 4479 | activityType = activityOptions.getLaunchActivityType(); |
| 4480 | windowingMode = activityOptions.getLaunchWindowingMode(); |
| 4481 | } |
| 4482 | if (activityType == ACTIVITY_TYPE_HOME || activityType == ACTIVITY_TYPE_RECENTS) { |
Wale Ogunwale | ab5de37 | 2017-10-18 06:46:31 -0700 | [diff] [blame] | 4483 | throw new IllegalArgumentException("startActivityFromRecents: Task " |
Matthew Ng | ae1ff4f | 2016-11-10 15:49:14 -0800 | [diff] [blame] | 4484 | + taskId + " can't be launch in the home/recents stack."); |
Jorim Jaggi | 0b46f3c | 2016-03-14 12:21:37 +0100 | [diff] [blame] | 4485 | } |
Jorim Jaggi | 3c800a4 | 2016-04-15 19:44:50 -0700 | [diff] [blame] | 4486 | |
Matthew Ng | 606dd80 | 2017-06-05 14:06:32 -0700 | [diff] [blame] | 4487 | mWindowManager.deferSurfaceLayout(); |
| 4488 | try { |
Wale Ogunwale | 0568aed | 2017-09-08 13:29:37 -0700 | [diff] [blame] | 4489 | if (windowingMode == WINDOWING_MODE_SPLIT_SCREEN_PRIMARY) { |
Matthew Ng | 606dd80 | 2017-06-05 14:06:32 -0700 | [diff] [blame] | 4490 | mWindowManager.setDockedStackCreateState( |
Matthew Ng | bf15587 | 2017-10-27 15:24:39 -0700 | [diff] [blame] | 4491 | activityOptions.getSplitScreenCreateMode(), null /* initialBounds */); |
Jorim Jaggi | 3c800a4 | 2016-04-15 19:44:50 -0700 | [diff] [blame] | 4492 | |
Matthew Ng | 606dd80 | 2017-06-05 14:06:32 -0700 | [diff] [blame] | 4493 | // Defer updating the stack in which recents is until the app transition is done, to |
| 4494 | // not run into issues where we still need to draw the task in recents but the |
| 4495 | // docked stack is already created. |
Wale Ogunwale | 6827856 | 2017-09-23 17:13:55 -0700 | [diff] [blame] | 4496 | deferUpdateBounds(ACTIVITY_TYPE_RECENTS); |
Matthew Ng | 606dd80 | 2017-06-05 14:06:32 -0700 | [diff] [blame] | 4497 | mWindowManager.prepareAppTransition(TRANSIT_DOCK_TASK_FROM_RECENTS, false); |
Jorim Jaggi | 0b46f3c | 2016-03-14 12:21:37 +0100 | [diff] [blame] | 4498 | } |
Jorim Jaggi | 0b46f3c | 2016-03-14 12:21:37 +0100 | [diff] [blame] | 4499 | |
Matthew Ng | 606dd80 | 2017-06-05 14:06:32 -0700 | [diff] [blame] | 4500 | task = anyTaskForIdLocked(taskId, MATCH_TASK_IN_STACKS_OR_RECENT_TASKS_AND_RESTORE, |
Wale Ogunwale | ab5de37 | 2017-10-18 06:46:31 -0700 | [diff] [blame] | 4501 | activityOptions, ON_TOP); |
Matthew Ng | 606dd80 | 2017-06-05 14:06:32 -0700 | [diff] [blame] | 4502 | if (task == null) { |
Wale Ogunwale | 6827856 | 2017-09-23 17:13:55 -0700 | [diff] [blame] | 4503 | continueUpdateBounds(ACTIVITY_TYPE_RECENTS); |
Matthew Ng | 606dd80 | 2017-06-05 14:06:32 -0700 | [diff] [blame] | 4504 | mWindowManager.executeAppTransition(); |
| 4505 | throw new IllegalArgumentException( |
Wale Ogunwale | ab5de37 | 2017-10-18 06:46:31 -0700 | [diff] [blame] | 4506 | "startActivityFromRecents: Task " + taskId + " not found."); |
Matthew Ng | 606dd80 | 2017-06-05 14:06:32 -0700 | [diff] [blame] | 4507 | } |
| 4508 | |
Wale Ogunwale | abc44d0 | 2017-11-08 08:58:03 -0800 | [diff] [blame] | 4509 | if (windowingMode != WINDOWING_MODE_SPLIT_SCREEN_PRIMARY) { |
| 4510 | // We always want to return to the home activity instead of the recents activity |
| 4511 | // from whatever is started from the recents activity, so move the home stack |
| 4512 | // forward. |
| 4513 | moveHomeStackToFront("startActivityFromRecents"); |
| 4514 | } |
Wale Ogunwale | 66e1685 | 2017-10-19 13:35:52 -0700 | [diff] [blame] | 4515 | |
Matthew Ng | 606dd80 | 2017-06-05 14:06:32 -0700 | [diff] [blame] | 4516 | // If the user must confirm credentials (e.g. when first launching a work app and the |
| 4517 | // Work Challenge is present) let startActivityInPackage handle the intercepting. |
| 4518 | if (!mService.mUserController.shouldConfirmCredentials(task.userId) |
| 4519 | && task.getRootActivity() != null) { |
Bryce Lee | 28d8042 | 2017-07-21 13:25:13 -0700 | [diff] [blame] | 4520 | final ActivityRecord targetActivity = task.getTopActivity(); |
| 4521 | |
| 4522 | mService.mActivityStarter.sendPowerHintForLaunchStartIfNeeded(true /* forceSend */, |
| 4523 | targetActivity); |
Matthew Ng | 606dd80 | 2017-06-05 14:06:32 -0700 | [diff] [blame] | 4524 | mActivityMetricsLogger.notifyActivityLaunching(); |
Jorim Jaggi | 172e99f | 2017-10-20 14:33:18 +0200 | [diff] [blame] | 4525 | try { |
| 4526 | mService.moveTaskToFrontLocked(task.taskId, 0, bOptions, |
| 4527 | true /* fromRecents */); |
| 4528 | } finally { |
| 4529 | mActivityMetricsLogger.notifyActivityLaunched(START_TASK_TO_FRONT, |
| 4530 | targetActivity); |
| 4531 | } |
Matthew Ng | 606dd80 | 2017-06-05 14:06:32 -0700 | [diff] [blame] | 4532 | |
| 4533 | // If we are launching the task in the docked stack, put it into resizing mode so |
| 4534 | // the window renders full-screen with the background filling the void. Also only |
| 4535 | // call this at the end to make sure that tasks exists on the window manager side. |
Wale Ogunwale | 0568aed | 2017-09-08 13:29:37 -0700 | [diff] [blame] | 4536 | if (windowingMode == WINDOWING_MODE_SPLIT_SCREEN_PRIMARY) { |
Matthew Ng | 606dd80 | 2017-06-05 14:06:32 -0700 | [diff] [blame] | 4537 | setResizingDuringAnimation(task); |
| 4538 | } |
| 4539 | |
| 4540 | mService.mActivityStarter.postStartActivityProcessing(task.getTopActivity(), |
Wale Ogunwale | 04a05ac | 2017-09-17 21:35:02 -0700 | [diff] [blame] | 4541 | ActivityManager.START_TASK_TO_FRONT, task.getStack()); |
Matthew Ng | 606dd80 | 2017-06-05 14:06:32 -0700 | [diff] [blame] | 4542 | return ActivityManager.START_TASK_TO_FRONT; |
| 4543 | } |
| 4544 | callingUid = task.mCallingUid; |
| 4545 | callingPackage = task.mCallingPackage; |
| 4546 | intent = task.intent; |
| 4547 | intent.addFlags(Intent.FLAG_ACTIVITY_LAUNCHED_FROM_HISTORY); |
| 4548 | userId = task.userId; |
| 4549 | int result = mService.startActivityInPackage(callingUid, callingPackage, intent, null, |
Andrii Kulian | 94e82d9b0 | 2017-07-13 15:33:06 -0700 | [diff] [blame] | 4550 | null, null, 0, 0, bOptions, userId, task, "startActivityFromRecents"); |
Wale Ogunwale | 0568aed | 2017-09-08 13:29:37 -0700 | [diff] [blame] | 4551 | if (windowingMode == WINDOWING_MODE_SPLIT_SCREEN_PRIMARY) { |
Wale Ogunwale | e1fe7fa2 | 2016-12-15 18:27:00 -0800 | [diff] [blame] | 4552 | setResizingDuringAnimation(task); |
Jorim Jaggi | 0b46f3c | 2016-03-14 12:21:37 +0100 | [diff] [blame] | 4553 | } |
Matthew Ng | 606dd80 | 2017-06-05 14:06:32 -0700 | [diff] [blame] | 4554 | return result; |
| 4555 | } finally { |
| 4556 | mWindowManager.continueSurfaceLayout(); |
Jorim Jaggi | 0b46f3c | 2016-03-14 12:21:37 +0100 | [diff] [blame] | 4557 | } |
Jorim Jaggi | 0b46f3c | 2016-03-14 12:21:37 +0100 | [diff] [blame] | 4558 | } |
Amith Yamasani | e8222e5 | 2016-04-08 15:28:47 -0700 | [diff] [blame] | 4559 | |
| 4560 | /** |
| 4561 | * @return a list of activities which are the top ones in each visible stack. The first |
| 4562 | * entry will be the focused activity. |
| 4563 | */ |
Andrii Kulian | 0864bbb | 2017-02-16 15:45:58 -0800 | [diff] [blame] | 4564 | List<IBinder> getTopVisibleActivities() { |
| 4565 | final ArrayList<IBinder> topActivityTokens = new ArrayList<>(); |
| 4566 | // Traverse all displays. |
Robert Carr | 22374c0 | 2017-02-21 13:01:47 -0800 | [diff] [blame] | 4567 | for (int i = mActivityDisplays.size() - 1; i >= 0; i--) { |
Andrii Kulian | 0864bbb | 2017-02-16 15:45:58 -0800 | [diff] [blame] | 4568 | final ActivityDisplay display = mActivityDisplays.valueAt(i); |
| 4569 | // Traverse all stacks on a display. |
Wale Ogunwale | a0f5b5e | 2017-10-11 09:37:23 -0700 | [diff] [blame] | 4570 | for (int j = display.getChildCount() - 1; j >= 0; --j) { |
| 4571 | final ActivityStack stack = display.getChildAt(j); |
Andrii Kulian | 0864bbb | 2017-02-16 15:45:58 -0800 | [diff] [blame] | 4572 | // Get top activity from a visible stack and add it to the list. |
Wale Ogunwale | 9dcf946 | 2017-09-19 15:13:01 -0700 | [diff] [blame] | 4573 | if (stack.shouldBeVisible(null /* starting */)) { |
Wale Ogunwale | 30e441d | 2017-11-09 08:28:45 -0800 | [diff] [blame] | 4574 | final ActivityRecord top = stack.getTopActivity(); |
Andrii Kulian | 0864bbb | 2017-02-16 15:45:58 -0800 | [diff] [blame] | 4575 | if (top != null) { |
| 4576 | if (stack == mFocusedStack) { |
| 4577 | topActivityTokens.add(0, top.appToken); |
| 4578 | } else { |
| 4579 | topActivityTokens.add(top.appToken); |
| 4580 | } |
Amith Yamasani | e8222e5 | 2016-04-08 15:28:47 -0700 | [diff] [blame] | 4581 | } |
| 4582 | } |
| 4583 | } |
| 4584 | } |
| 4585 | return topActivityTokens; |
| 4586 | } |
Bryce Lee | 4a19438 | 2017-04-04 14:32:48 -0700 | [diff] [blame] | 4587 | |
| 4588 | /** |
| 4589 | * Internal container to store a match qualifier alongside a WaitResult. |
| 4590 | */ |
| 4591 | static class WaitInfo { |
| 4592 | private final ComponentName mTargetComponent; |
| 4593 | private final WaitResult mResult; |
| 4594 | |
| 4595 | public WaitInfo(ComponentName targetComponent, WaitResult result) { |
| 4596 | this.mTargetComponent = targetComponent; |
| 4597 | this.mResult = result; |
| 4598 | } |
| 4599 | |
Wale Ogunwale | 3270f17 | 2017-04-26 07:29:42 -0700 | [diff] [blame] | 4600 | public boolean matches(ComponentName targetComponent) { |
| 4601 | return mTargetComponent == null || mTargetComponent.equals(targetComponent); |
Bryce Lee | 4a19438 | 2017-04-04 14:32:48 -0700 | [diff] [blame] | 4602 | } |
| 4603 | |
| 4604 | public WaitResult getResult() { |
| 4605 | return mResult; |
| 4606 | } |
| 4607 | |
| 4608 | public ComponentName getComponent() { |
| 4609 | return mTargetComponent; |
| 4610 | } |
| 4611 | |
| 4612 | public void dump(PrintWriter pw, String prefix) { |
| 4613 | pw.println(prefix + "WaitInfo:"); |
| 4614 | pw.println(prefix + " mTargetComponent=" + mTargetComponent); |
| 4615 | pw.println(prefix + " mResult="); |
| 4616 | mResult.dump(pw, prefix); |
| 4617 | } |
| 4618 | } |
David Stevens | 9440dc8 | 2017-03-16 19:00:20 -0700 | [diff] [blame] | 4619 | |
| 4620 | private final class SleepTokenImpl extends SleepToken { |
| 4621 | private final String mTag; |
| 4622 | private final long mAcquireTime; |
| 4623 | private final int mDisplayId; |
| 4624 | |
| 4625 | public SleepTokenImpl(String tag, int displayId) { |
| 4626 | mTag = tag; |
| 4627 | mDisplayId = displayId; |
| 4628 | mAcquireTime = SystemClock.uptimeMillis(); |
| 4629 | } |
| 4630 | |
| 4631 | @Override |
| 4632 | public void release() { |
| 4633 | synchronized (mService) { |
| 4634 | removeSleepTokenLocked(this); |
| 4635 | } |
| 4636 | } |
| 4637 | |
| 4638 | @Override |
| 4639 | public String toString() { |
| 4640 | return "{\"" + mTag + "\", display " + mDisplayId |
| 4641 | + ", acquire at " + TimeUtils.formatUptime(mAcquireTime) + "}"; |
| 4642 | } |
| 4643 | } |
| 4644 | |
Craig Mautner | 2708430 | 2013-03-25 08:05:25 -0700 | [diff] [blame] | 4645 | } |