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