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