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 | e6ac20e | 2017-03-17 10:30:50 -0700 | [diff] [blame] | 19 | import static android.Manifest.permission.MANAGE_ACTIVITY_STACKS; |
Jorim Jaggi | fe76234 | 2016-10-13 14:33:27 +0200 | [diff] [blame] | 20 | import static android.Manifest.permission.START_ANY_ACTIVITY; |
| 21 | import static android.Manifest.permission.START_TASKS_FROM_RECENTS; |
| 22 | import static android.app.ActivityManager.LOCK_TASK_MODE_LOCKED; |
| 23 | import static android.app.ActivityManager.LOCK_TASK_MODE_NONE; |
| 24 | import static android.app.ActivityManager.LOCK_TASK_MODE_PINNED; |
Jorim Jaggi | fe76234 | 2016-10-13 14:33:27 +0200 | [diff] [blame] | 25 | import static android.app.ActivityManager.START_TASK_TO_FRONT; |
| 26 | import static android.app.ActivityManager.StackId.DOCKED_STACK_ID; |
| 27 | import static android.app.ActivityManager.StackId.FIRST_DYNAMIC_STACK_ID; |
| 28 | import static android.app.ActivityManager.StackId.FIRST_STATIC_STACK_ID; |
| 29 | import static android.app.ActivityManager.StackId.FREEFORM_WORKSPACE_STACK_ID; |
| 30 | import static android.app.ActivityManager.StackId.FULLSCREEN_WORKSPACE_STACK_ID; |
| 31 | import static android.app.ActivityManager.StackId.HOME_STACK_ID; |
| 32 | import static android.app.ActivityManager.StackId.INVALID_STACK_ID; |
| 33 | import static android.app.ActivityManager.StackId.LAST_STATIC_STACK_ID; |
| 34 | import static android.app.ActivityManager.StackId.PINNED_STACK_ID; |
Matthew Ng | 330757d | 2017-02-28 14:19:17 -0800 | [diff] [blame] | 35 | import static android.app.ActivityManager.StackId.RECENTS_STACK_ID; |
Andrii Kulian | 036e3ad | 2017-04-19 10:55:10 -0700 | [diff] [blame] | 36 | import static android.app.ITaskStackListener.FORCED_RESIZEABLE_REASON_SECONDARY_DISPLAY; |
| 37 | import static android.app.ITaskStackListener.FORCED_RESIZEABLE_REASON_SPLIT_SCREEN; |
Jorim Jaggi | fe76234 | 2016-10-13 14:33:27 +0200 | [diff] [blame] | 38 | import static android.content.Intent.FLAG_ACTIVITY_MULTIPLE_TASK; |
| 39 | import static android.content.Intent.FLAG_ACTIVITY_NEW_TASK; |
| 40 | import static android.content.pm.PackageManager.PERMISSION_GRANTED; |
Andrii Kulian | 1cba31c | 2017-06-28 09:42:48 -0700 | [diff] [blame] | 41 | import static android.os.Process.SYSTEM_UID; |
Jorim Jaggi | fe76234 | 2016-10-13 14:33:27 +0200 | [diff] [blame] | 42 | import static android.os.Trace.TRACE_TAG_ACTIVITY_MANAGER; |
| 43 | import static android.view.Display.DEFAULT_DISPLAY; |
Andrii Kulian | 16802aa | 2016-11-02 12:21:33 -0700 | [diff] [blame] | 44 | import static android.view.Display.FLAG_PRIVATE; |
| 45 | import static android.view.Display.INVALID_DISPLAY; |
Andrii Kulian | 250d653 | 2017-02-08 23:30:45 -0800 | [diff] [blame] | 46 | import static android.view.Display.REMOVE_MODE_DESTROY_CONTENT; |
Andrii Kulian | 1cba31c | 2017-06-28 09:42:48 -0700 | [diff] [blame] | 47 | import static android.view.Display.TYPE_VIRTUAL; |
Jorim Jaggi | fe76234 | 2016-10-13 14:33:27 +0200 | [diff] [blame] | 48 | |
Winson Chung | 4790065 | 2017-04-06 18:44:25 -0700 | [diff] [blame] | 49 | 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] | 50 | import static com.android.server.am.ActivityManagerDebugConfig.DEBUG_ALL; |
| 51 | import static com.android.server.am.ActivityManagerDebugConfig.DEBUG_CONTAINERS; |
| 52 | import static com.android.server.am.ActivityManagerDebugConfig.DEBUG_FOCUS; |
| 53 | import static com.android.server.am.ActivityManagerDebugConfig.DEBUG_IDLE; |
| 54 | import static com.android.server.am.ActivityManagerDebugConfig.DEBUG_LOCKTASK; |
| 55 | import static com.android.server.am.ActivityManagerDebugConfig.DEBUG_PAUSE; |
| 56 | import static com.android.server.am.ActivityManagerDebugConfig.DEBUG_RECENTS; |
| 57 | import static com.android.server.am.ActivityManagerDebugConfig.DEBUG_RELEASE; |
| 58 | import static com.android.server.am.ActivityManagerDebugConfig.DEBUG_STACK; |
| 59 | import static com.android.server.am.ActivityManagerDebugConfig.DEBUG_STATES; |
| 60 | import static com.android.server.am.ActivityManagerDebugConfig.DEBUG_SWITCH; |
| 61 | import static com.android.server.am.ActivityManagerDebugConfig.DEBUG_TASKS; |
| 62 | import static com.android.server.am.ActivityManagerDebugConfig.DEBUG_VISIBLE_BEHIND; |
| 63 | import static com.android.server.am.ActivityManagerDebugConfig.POSTFIX_CONTAINERS; |
| 64 | import static com.android.server.am.ActivityManagerDebugConfig.POSTFIX_FOCUS; |
| 65 | import static com.android.server.am.ActivityManagerDebugConfig.POSTFIX_IDLE; |
| 66 | import static com.android.server.am.ActivityManagerDebugConfig.POSTFIX_LOCKTASK; |
| 67 | import static com.android.server.am.ActivityManagerDebugConfig.POSTFIX_PAUSE; |
| 68 | import static com.android.server.am.ActivityManagerDebugConfig.POSTFIX_RECENTS; |
| 69 | import static com.android.server.am.ActivityManagerDebugConfig.POSTFIX_RELEASE; |
| 70 | import static com.android.server.am.ActivityManagerDebugConfig.POSTFIX_STACK; |
| 71 | import static com.android.server.am.ActivityManagerDebugConfig.POSTFIX_STATES; |
| 72 | import static com.android.server.am.ActivityManagerDebugConfig.POSTFIX_SWITCH; |
| 73 | import static com.android.server.am.ActivityManagerDebugConfig.POSTFIX_TASKS; |
| 74 | import static com.android.server.am.ActivityManagerDebugConfig.POSTFIX_VISIBLE_BEHIND; |
| 75 | import static com.android.server.am.ActivityManagerDebugConfig.TAG_AM; |
| 76 | import static com.android.server.am.ActivityManagerDebugConfig.TAG_WITH_CLASS_NAME; |
| 77 | import static com.android.server.am.ActivityManagerService.ANIMATE; |
| 78 | import static com.android.server.am.ActivityManagerService.FIRST_SUPERVISOR_STACK_MSG; |
| 79 | import static com.android.server.am.ActivityRecord.APPLICATION_ACTIVITY_TYPE; |
| 80 | import static com.android.server.am.ActivityRecord.HOME_ACTIVITY_TYPE; |
Jorim Jaggi | fe76234 | 2016-10-13 14:33:27 +0200 | [diff] [blame] | 81 | import static com.android.server.am.ActivityStack.ActivityState.DESTROYED; |
| 82 | import static com.android.server.am.ActivityStack.ActivityState.DESTROYING; |
| 83 | import static com.android.server.am.ActivityStack.ActivityState.INITIALIZING; |
| 84 | import static com.android.server.am.ActivityStack.ActivityState.PAUSED; |
| 85 | import static com.android.server.am.ActivityStack.ActivityState.PAUSING; |
| 86 | import static com.android.server.am.ActivityStack.ActivityState.RESUMED; |
| 87 | import static com.android.server.am.ActivityStack.ActivityState.STOPPED; |
| 88 | import static com.android.server.am.ActivityStack.ActivityState.STOPPING; |
| 89 | import static com.android.server.am.ActivityStack.REMOVE_TASK_MODE_MOVING; |
| 90 | import static com.android.server.am.ActivityStack.STACK_INVISIBLE; |
| 91 | import static com.android.server.am.ActivityStack.STACK_VISIBLE; |
| 92 | import static com.android.server.am.TaskRecord.LOCK_TASK_AUTH_DONT_LOCK; |
| 93 | import static com.android.server.am.TaskRecord.LOCK_TASK_AUTH_LAUNCHABLE; |
| 94 | import static com.android.server.am.TaskRecord.LOCK_TASK_AUTH_LAUNCHABLE_PRIV; |
| 95 | import static com.android.server.am.TaskRecord.LOCK_TASK_AUTH_PINNABLE; |
| 96 | import static com.android.server.am.TaskRecord.LOCK_TASK_AUTH_WHITELISTED; |
Winson Chung | 7466610 | 2017-02-22 17:49:24 -0800 | [diff] [blame] | 97 | import static com.android.server.am.TaskRecord.REPARENT_KEEP_STACK_AT_FRONT; |
| 98 | import static com.android.server.am.TaskRecord.REPARENT_LEAVE_STACK_IN_PLACE; |
| 99 | import static com.android.server.am.TaskRecord.REPARENT_MOVE_STACK_TO_FRONT; |
Jorim Jaggi | fe76234 | 2016-10-13 14:33:27 +0200 | [diff] [blame] | 100 | import static com.android.server.wm.AppTransition.TRANSIT_DOCK_TASK_FROM_RECENTS; |
Wale Ogunwale | e1fe7fa2 | 2016-12-15 18:27:00 -0800 | [diff] [blame] | 101 | import static java.lang.Integer.MAX_VALUE; |
Jorim Jaggi | fe76234 | 2016-10-13 14:33:27 +0200 | [diff] [blame] | 102 | |
Svetoslav | 7008b51 | 2015-06-24 18:47:07 -0700 | [diff] [blame] | 103 | import android.Manifest; |
Winson Chung | 7900bee | 2017-03-10 08:59:25 -0800 | [diff] [blame] | 104 | import android.annotation.IntDef; |
Andrii Kulian | 16802aa | 2016-11-02 12:21:33 -0700 | [diff] [blame] | 105 | import android.annotation.NonNull; |
Tony Mak | 853304c | 2016-04-18 15:17:41 +0100 | [diff] [blame] | 106 | import android.annotation.UserIdInt; |
Craig Mautner | 2420ead | 2013-04-01 17:13:20 -0700 | [diff] [blame] | 107 | import android.app.Activity; |
Craig Mautner | 23ac33b | 2013-04-01 16:26:35 -0700 | [diff] [blame] | 108 | import android.app.ActivityManager; |
Filip Gruszczynski | 80e29f1 | 2015-12-14 14:58:30 -0800 | [diff] [blame] | 109 | import android.app.ActivityManager.RunningTaskInfo; |
Wale Ogunwale | 3797c22 | 2015-10-27 14:21:58 -0700 | [diff] [blame] | 110 | import android.app.ActivityManager.StackId; |
Craig Mautner | ed6649f | 2013-12-02 14:08:25 -0800 | [diff] [blame] | 111 | import android.app.ActivityManager.StackInfo; |
Craig Mautner | 23ac33b | 2013-04-01 16:26:35 -0700 | [diff] [blame] | 112 | import android.app.ActivityOptions; |
Svetoslav | 7008b51 | 2015-06-24 18:47:07 -0700 | [diff] [blame] | 113 | import android.app.AppOpsManager; |
Craig Mautner | 4a1cb22 | 2013-12-04 16:14:06 -0800 | [diff] [blame] | 114 | import android.app.IActivityContainerCallback; |
Jeff Hao | 1b012d3 | 2014-08-20 10:35:34 -0700 | [diff] [blame] | 115 | import android.app.ProfilerInfo; |
Craig Mautner | 2420ead | 2013-04-01 17:13:20 -0700 | [diff] [blame] | 116 | import android.app.ResultInfo; |
justinzhang | 5286d3f | 2014-05-12 17:06:01 -0400 | [diff] [blame] | 117 | import android.app.StatusBarManager; |
Sudheer Shanka | fc46e9b | 2016-10-21 17:55:27 -0700 | [diff] [blame] | 118 | import android.app.WaitResult; |
Jason Monk | 35c62a4 | 2014-06-17 10:24:47 -0400 | [diff] [blame] | 119 | import android.app.admin.IDevicePolicyManager; |
Craig Mautner | 23ac33b | 2013-04-01 16:26:35 -0700 | [diff] [blame] | 120 | import android.content.ComponentName; |
Craig Mautner | 2219a1b | 2013-03-25 09:44:30 -0700 | [diff] [blame] | 121 | import android.content.Context; |
Craig Mautner | 23ac33b | 2013-04-01 16:26:35 -0700 | [diff] [blame] | 122 | import android.content.IIntentSender; |
Craig Mautner | 2219a1b | 2013-03-25 09:44:30 -0700 | [diff] [blame] | 123 | import android.content.Intent; |
| 124 | import android.content.pm.ActivityInfo; |
Craig Mautner | 23ac33b | 2013-04-01 16:26:35 -0700 | [diff] [blame] | 125 | import android.content.pm.ApplicationInfo; |
Svetoslav | 7008b51 | 2015-06-24 18:47:07 -0700 | [diff] [blame] | 126 | import android.content.pm.PackageInfo; |
Craig Mautner | 23ac33b | 2013-04-01 16:26:35 -0700 | [diff] [blame] | 127 | import android.content.pm.PackageManager; |
| 128 | import android.content.pm.ResolveInfo; |
Clara Bayarri | f7fea16 | 2015-10-22 16:09:52 +0100 | [diff] [blame] | 129 | import android.content.pm.UserInfo; |
Craig Mautner | 23ac33b | 2013-04-01 16:26:35 -0700 | [diff] [blame] | 130 | import android.content.res.Configuration; |
Wale Ogunwale | 60454db | 2015-01-23 16:05:07 -0800 | [diff] [blame] | 131 | import android.graphics.Rect; |
Craig Mautner | 4a1cb22 | 2013-12-04 16:14:06 -0800 | [diff] [blame] | 132 | import android.hardware.display.DisplayManager; |
| 133 | import android.hardware.display.DisplayManager.DisplayListener; |
Craig Mautner | 4504de5 | 2013-12-20 09:06:56 -0800 | [diff] [blame] | 134 | import android.hardware.display.DisplayManagerGlobal; |
Andrii Kulian | fb1bf69 | 2017-01-17 11:17:34 -0800 | [diff] [blame] | 135 | import android.hardware.display.DisplayManagerInternal; |
Craig Mautner | 4504de5 | 2013-12-20 09:06:56 -0800 | [diff] [blame] | 136 | import android.hardware.display.VirtualDisplay; |
Jeff Brown | ca9bc70 | 2014-02-11 14:32:56 -0800 | [diff] [blame] | 137 | import android.hardware.input.InputManager; |
| 138 | import android.hardware.input.InputManagerInternal; |
Craig Mautner | 23ac33b | 2013-04-01 16:26:35 -0700 | [diff] [blame] | 139 | import android.os.Binder; |
Jorim Jaggi | 0b46f3c | 2016-03-14 12:21:37 +0100 | [diff] [blame] | 140 | import android.os.Bundle; |
Craig Mautner | b59dcfd | 2013-05-06 13:12:58 -0700 | [diff] [blame] | 141 | import android.os.Debug; |
Craig Mautner | ce5f3cb | 2013-04-22 08:58:54 -0700 | [diff] [blame] | 142 | import android.os.Handler; |
Craig Mautner | 23ac33b | 2013-04-01 16:26:35 -0700 | [diff] [blame] | 143 | import android.os.IBinder; |
Craig Mautner | 2219a1b | 2013-03-25 09:44:30 -0700 | [diff] [blame] | 144 | import android.os.Looper; |
Craig Mautner | 2420ead | 2013-04-01 17:13:20 -0700 | [diff] [blame] | 145 | import android.os.Message; |
Craig Mautner | 23ac33b | 2013-04-01 16:26:35 -0700 | [diff] [blame] | 146 | import android.os.ParcelFileDescriptor; |
Craig Mautner | 0eea92c | 2013-05-16 13:35:39 -0700 | [diff] [blame] | 147 | import android.os.PowerManager; |
Craig Mautner | 7ea5bd4 | 2013-07-05 15:27:08 -0700 | [diff] [blame] | 148 | import android.os.Process; |
Craig Mautner | 8d341ef | 2013-03-26 09:03:27 -0700 | [diff] [blame] | 149 | import android.os.RemoteException; |
justinzhang | 5286d3f | 2014-05-12 17:06:01 -0400 | [diff] [blame] | 150 | import android.os.ServiceManager; |
Craig Mautner | 23ac33b | 2013-04-01 16:26:35 -0700 | [diff] [blame] | 151 | import android.os.SystemClock; |
Wale Ogunwale | cad05a0 | 2015-09-25 10:41:44 -0700 | [diff] [blame] | 152 | import android.os.Trace; |
Craig Mautner | 5f2bb4c | 2015-03-12 16:10:27 -0700 | [diff] [blame] | 153 | import android.os.TransactionTooLargeException; |
Craig Mautner | 6170f73 | 2013-04-02 13:05:23 -0700 | [diff] [blame] | 154 | import android.os.UserHandle; |
Clara Bayarri | f7fea16 | 2015-10-22 16:09:52 +0100 | [diff] [blame] | 155 | import android.os.UserManager; |
Dianne Hackborn | 3d07c94 | 2015-03-13 18:02:54 -0700 | [diff] [blame] | 156 | import android.os.WorkSource; |
Svetoslav | 7008b51 | 2015-06-24 18:47:07 -0700 | [diff] [blame] | 157 | import android.provider.MediaStore; |
Jason Monk | 62515be | 2014-05-21 16:06:19 -0400 | [diff] [blame] | 158 | import android.provider.Settings; |
| 159 | import android.provider.Settings.SettingNotFoundException; |
Dianne Hackborn | 91097de | 2014-04-04 18:02:06 -0700 | [diff] [blame] | 160 | import android.service.voice.IVoiceInteractionSession; |
Svetoslav | 7008b51 | 2015-06-24 18:47:07 -0700 | [diff] [blame] | 161 | import android.util.ArrayMap; |
Dianne Hackborn | 89ad456 | 2014-08-24 16:45:38 -0700 | [diff] [blame] | 162 | import android.util.ArraySet; |
Craig Mautner | 2420ead | 2013-04-01 17:13:20 -0700 | [diff] [blame] | 163 | import android.util.EventLog; |
Andrii Kulian | fb1bf69 | 2017-01-17 11:17:34 -0800 | [diff] [blame] | 164 | import android.util.IntArray; |
Wale Ogunwale | e610d3d | 2017-04-25 10:23:48 -0700 | [diff] [blame] | 165 | import android.util.MergedConfiguration; |
Craig Mautner | 8d341ef | 2013-03-26 09:03:27 -0700 | [diff] [blame] | 166 | import android.util.Slog; |
Craig Mautner | 4a1cb22 | 2013-12-04 16:14:06 -0800 | [diff] [blame] | 167 | import android.util.SparseArray; |
Craig Mautner | 4a1cb22 | 2013-12-04 16:14:06 -0800 | [diff] [blame] | 168 | import android.util.SparseIntArray; |
Craig Mautner | ed6649f | 2013-12-02 14:08:25 -0800 | [diff] [blame] | 169 | import android.view.Display; |
Jeff Brown | ca9bc70 | 2014-02-11 14:32:56 -0800 | [diff] [blame] | 170 | import android.view.InputEvent; |
Craig Mautner | 4504de5 | 2013-12-20 09:06:56 -0800 | [diff] [blame] | 171 | import android.view.Surface; |
Chong Zhang | b15758a | 2015-11-17 12:12:03 -0800 | [diff] [blame] | 172 | |
Dianne Hackborn | 85d558c | 2014-11-04 10:31:54 -0800 | [diff] [blame] | 173 | import com.android.internal.content.ReferrerIntent; |
Winson Chung | 14fbe14 | 2016-12-19 16:18:24 -0800 | [diff] [blame] | 174 | import com.android.internal.logging.MetricsLogger; |
Dianne Hackborn | cbfd23e | 2013-06-11 14:26:53 -0700 | [diff] [blame] | 175 | import com.android.internal.os.TransferPipe; |
justinzhang | 5286d3f | 2014-05-12 17:06:01 -0400 | [diff] [blame] | 176 | import com.android.internal.statusbar.IStatusBarService; |
Svetoslav | 7008b51 | 2015-06-24 18:47:07 -0700 | [diff] [blame] | 177 | import com.android.internal.util.ArrayUtils; |
Jason Monk | e069779 | 2014-08-04 16:28:09 -0400 | [diff] [blame] | 178 | import com.android.internal.widget.LockPatternUtils; |
Jeff Brown | ca9bc70 | 2014-02-11 14:32:56 -0800 | [diff] [blame] | 179 | import com.android.server.LocalServices; |
Craig Mautner | 2420ead | 2013-04-01 17:13:20 -0700 | [diff] [blame] | 180 | import com.android.server.am.ActivityStack.ActivityState; |
Winson Chung | 19953ca | 2017-04-11 11:19:23 -0700 | [diff] [blame] | 181 | import com.android.server.wm.PinnedStackWindowController; |
Craig Mautner | ce5f3cb | 2013-04-22 08:58:54 -0700 | [diff] [blame] | 182 | import com.android.server.wm.WindowManagerService; |
Craig Mautner | 23ac33b | 2013-04-01 16:26:35 -0700 | [diff] [blame] | 183 | |
Craig Mautner | 8d341ef | 2013-03-26 09:03:27 -0700 | [diff] [blame] | 184 | import java.io.FileDescriptor; |
| 185 | import java.io.IOException; |
Craig Mautner | 2708430 | 2013-03-25 08:05:25 -0700 | [diff] [blame] | 186 | import java.io.PrintWriter; |
Winson Chung | 7900bee | 2017-03-10 08:59:25 -0800 | [diff] [blame] | 187 | import java.lang.annotation.Retention; |
| 188 | import java.lang.annotation.RetentionPolicy; |
Craig Mautner | 2219a1b | 2013-03-25 09:44:30 -0700 | [diff] [blame] | 189 | import java.util.ArrayList; |
Craig Mautner | e057020 | 2015-05-13 13:06:11 -0700 | [diff] [blame] | 190 | import java.util.Arrays; |
Craig Mautner | 8d341ef | 2013-03-26 09:03:27 -0700 | [diff] [blame] | 191 | import java.util.List; |
Wale Ogunwale | 540e123 | 2015-05-01 15:35:39 -0700 | [diff] [blame] | 192 | import java.util.Set; |
Craig Mautner | 2708430 | 2013-03-25 08:05:25 -0700 | [diff] [blame] | 193 | |
Wale Ogunwale | 26c0dfe | 2016-12-14 14:42:30 -0800 | [diff] [blame] | 194 | public class ActivityStackSupervisor extends ConfigurationContainer implements DisplayListener { |
Wale Ogunwale | e23149f | 2015-03-06 15:39:44 -0800 | [diff] [blame] | 195 | private static final String TAG = TAG_WITH_CLASS_NAME ? "ActivityStackSupervisor" : TAG_AM; |
Wale Ogunwale | 0fc365c | 2015-05-25 19:35:42 -0700 | [diff] [blame] | 196 | private static final String TAG_CONTAINERS = TAG + POSTFIX_CONTAINERS; |
Chong Zhang | 6cda19c | 2016-06-14 19:07:56 -0700 | [diff] [blame] | 197 | private static final String TAG_FOCUS = TAG + POSTFIX_FOCUS; |
Wale Ogunwale | 0fc365c | 2015-05-25 19:35:42 -0700 | [diff] [blame] | 198 | private static final String TAG_IDLE = TAG + POSTFIX_IDLE; |
Craig Mautner | e057020 | 2015-05-13 13:06:11 -0700 | [diff] [blame] | 199 | private static final String TAG_LOCKTASK = TAG + POSTFIX_LOCKTASK; |
Wale Ogunwale | ee006da | 2015-03-30 14:49:25 -0700 | [diff] [blame] | 200 | private static final String TAG_PAUSE = TAG + POSTFIX_PAUSE; |
Wale Ogunwale | ee006da | 2015-03-30 14:49:25 -0700 | [diff] [blame] | 201 | private static final String TAG_RECENTS = TAG + POSTFIX_RECENTS; |
Wale Ogunwale | 0fc365c | 2015-05-25 19:35:42 -0700 | [diff] [blame] | 202 | private static final String TAG_RELEASE = TAG + POSTFIX_RELEASE; |
Wale Ogunwale | ee006da | 2015-03-30 14:49:25 -0700 | [diff] [blame] | 203 | private static final String TAG_STACK = TAG + POSTFIX_STACK; |
Wale Ogunwale | 0fc365c | 2015-05-25 19:35:42 -0700 | [diff] [blame] | 204 | private static final String TAG_STATES = TAG + POSTFIX_STATES; |
Wale Ogunwale | ee006da | 2015-03-30 14:49:25 -0700 | [diff] [blame] | 205 | private static final String TAG_SWITCH = TAG + POSTFIX_SWITCH; |
Filip Gruszczynski | 07a0e49 | 2015-12-17 14:16:38 -0800 | [diff] [blame] | 206 | static final String TAG_TASKS = TAG + POSTFIX_TASKS; |
Wale Ogunwale | 0fc365c | 2015-05-25 19:35:42 -0700 | [diff] [blame] | 207 | private static final String TAG_VISIBLE_BEHIND = TAG + POSTFIX_VISIBLE_BEHIND; |
Wale Ogunwale | e23149f | 2015-03-06 15:39:44 -0800 | [diff] [blame] | 208 | |
Craig Mautner | f333327 | 2013-04-22 10:55:53 -0700 | [diff] [blame] | 209 | /** 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] | 210 | static final int IDLE_TIMEOUT = 10 * 1000; |
Craig Mautner | f333327 | 2013-04-22 10:55:53 -0700 | [diff] [blame] | 211 | |
Craig Mautner | 0eea92c | 2013-05-16 13:35:39 -0700 | [diff] [blame] | 212 | /** How long we can hold the sleep wake lock before giving up. */ |
Wale Ogunwale | 0fc365c | 2015-05-25 19:35:42 -0700 | [diff] [blame] | 213 | static final int SLEEP_TIMEOUT = 5 * 1000; |
Craig Mautner | 0eea92c | 2013-05-16 13:35:39 -0700 | [diff] [blame] | 214 | |
Craig Mautner | 7ea5bd4 | 2013-07-05 15:27:08 -0700 | [diff] [blame] | 215 | // How long we can hold the launch wake lock before giving up. |
Wale Ogunwale | 0fc365c | 2015-05-25 19:35:42 -0700 | [diff] [blame] | 216 | static final int LAUNCH_TIMEOUT = 10 * 1000; |
Craig Mautner | 7ea5bd4 | 2013-07-05 15:27:08 -0700 | [diff] [blame] | 217 | |
Craig Mautner | 05d2903 | 2013-05-03 13:40:13 -0700 | [diff] [blame] | 218 | static final int IDLE_TIMEOUT_MSG = FIRST_SUPERVISOR_STACK_MSG; |
| 219 | static final int IDLE_NOW_MSG = FIRST_SUPERVISOR_STACK_MSG + 1; |
| 220 | static final int RESUME_TOP_ACTIVITY_MSG = FIRST_SUPERVISOR_STACK_MSG + 2; |
Craig Mautner | 0eea92c | 2013-05-16 13:35:39 -0700 | [diff] [blame] | 221 | static final int SLEEP_TIMEOUT_MSG = FIRST_SUPERVISOR_STACK_MSG + 3; |
Craig Mautner | 7ea5bd4 | 2013-07-05 15:27:08 -0700 | [diff] [blame] | 222 | static final int LAUNCH_TIMEOUT_MSG = FIRST_SUPERVISOR_STACK_MSG + 4; |
Craig Mautner | 4a1cb22 | 2013-12-04 16:14:06 -0800 | [diff] [blame] | 223 | static final int HANDLE_DISPLAY_ADDED = FIRST_SUPERVISOR_STACK_MSG + 5; |
| 224 | static final int HANDLE_DISPLAY_CHANGED = FIRST_SUPERVISOR_STACK_MSG + 6; |
| 225 | static final int HANDLE_DISPLAY_REMOVED = FIRST_SUPERVISOR_STACK_MSG + 7; |
Craig Mautner | e3a00d7 | 2014-04-16 08:31:19 -0700 | [diff] [blame] | 226 | static final int CONTAINER_CALLBACK_VISIBILITY = FIRST_SUPERVISOR_STACK_MSG + 8; |
justinzhang | 5286d3f | 2014-05-12 17:06:01 -0400 | [diff] [blame] | 227 | static final int LOCK_TASK_START_MSG = FIRST_SUPERVISOR_STACK_MSG + 9; |
| 228 | static final int LOCK_TASK_END_MSG = FIRST_SUPERVISOR_STACK_MSG + 10; |
Craig Mautner | 6cd6cec | 2015-04-01 00:02:12 -0700 | [diff] [blame] | 229 | static final int CONTAINER_CALLBACK_TASK_LIST_EMPTY = FIRST_SUPERVISOR_STACK_MSG + 11; |
Wale Ogunwale | 73eba74 | 2015-04-07 14:23:14 -0700 | [diff] [blame] | 230 | static final int LAUNCH_TASK_BEHIND_COMPLETE = FIRST_SUPERVISOR_STACK_MSG + 12; |
Craig Mautner | c21ae9e | 2015-04-15 09:45:42 -0700 | [diff] [blame] | 231 | static final int SHOW_LOCK_TASK_ESCAPE_MESSAGE_MSG = FIRST_SUPERVISOR_STACK_MSG + 13; |
Wale Ogunwale | 22e2526 | 2016-02-01 10:32:02 -0800 | [diff] [blame] | 232 | static final int REPORT_MULTI_WINDOW_MODE_CHANGED_MSG = FIRST_SUPERVISOR_STACK_MSG + 14; |
| 233 | 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] | 234 | |
Wale Ogunwale | 040b470 | 2015-08-06 18:10:50 -0700 | [diff] [blame] | 235 | private static final String VIRTUAL_DISPLAY_BASE_NAME = "ActivityViewVirtualDisplay"; |
Craig Mautner | 7ea5bd4 | 2013-07-05 15:27:08 -0700 | [diff] [blame] | 236 | |
Jason Monk | 62515be | 2014-05-21 16:06:19 -0400 | [diff] [blame] | 237 | private static final String LOCK_TASK_TAG = "Lock-to-App"; |
| 238 | |
Wale Ogunwale | 040b470 | 2015-08-06 18:10:50 -0700 | [diff] [blame] | 239 | // Used to indicate if an object (e.g. stack) that we are trying to get |
| 240 | // should be created if it doesn't exist already. |
Filip Gruszczynski | 07a0e49 | 2015-12-17 14:16:38 -0800 | [diff] [blame] | 241 | static final boolean CREATE_IF_NEEDED = true; |
Wale Ogunwale | 040b470 | 2015-08-06 18:10:50 -0700 | [diff] [blame] | 242 | |
Filip Gruszczynski | bc5a6c5 | 2015-09-22 13:13:24 -0700 | [diff] [blame] | 243 | // Used to indicate that windows of activities should be preserved during the resize. |
| 244 | static final boolean PRESERVE_WINDOWS = true; |
| 245 | |
Wale Ogunwale | 040b470 | 2015-08-06 18:10:50 -0700 | [diff] [blame] | 246 | // Used to indicate if an object (e.g. task) should be moved/created |
| 247 | // at the top of its container (e.g. stack). |
Wale Ogunwale | b30daaa | 2015-08-07 21:50:49 -0700 | [diff] [blame] | 248 | static final boolean ON_TOP = true; |
Wale Ogunwale | 040b470 | 2015-08-06 18:10:50 -0700 | [diff] [blame] | 249 | |
| 250 | // Used to indicate that an objects (e.g. task) removal from its container |
| 251 | // (e.g. stack) is due to it moving to another container. |
| 252 | static final boolean MOVING = true; |
| 253 | |
Wale Ogunwale | b34a7ad | 2015-08-14 11:05:30 -0700 | [diff] [blame] | 254 | // Force the focus to change to the stack we are moving a task to.. |
| 255 | static final boolean FORCE_FOCUS = true; |
| 256 | |
Wale Ogunwale | c8da41e | 2016-04-16 13:27:23 -0700 | [diff] [blame] | 257 | // Don't execute any calls to resume. |
| 258 | static final boolean DEFER_RESUME = true; |
| 259 | |
Winson Chung | 010927a | 2016-12-15 16:12:35 -0800 | [diff] [blame] | 260 | // Used to indicate that a task is removed it should also be removed from recents. |
| 261 | static final boolean REMOVE_FROM_RECENTS = true; |
| 262 | |
Winson Chung | 6954fc9 | 2017-03-24 16:22:12 -0700 | [diff] [blame] | 263 | // Used to indicate that pausing an activity should occur immediately without waiting for |
| 264 | // the activity callback indicating that it has completed pausing |
| 265 | static final boolean PAUSE_IMMEDIATELY = true; |
| 266 | |
Winson Chung | 7900bee | 2017-03-10 08:59:25 -0800 | [diff] [blame] | 267 | /** |
| 268 | * The modes which affect which tasks are returned when calling |
| 269 | * {@link ActivityStackSupervisor#anyTaskForIdLocked(int)}. |
| 270 | */ |
| 271 | @Retention(RetentionPolicy.SOURCE) |
| 272 | @IntDef({ |
| 273 | MATCH_TASK_IN_STACKS_ONLY, |
| 274 | MATCH_TASK_IN_STACKS_OR_RECENT_TASKS, |
| 275 | MATCH_TASK_IN_STACKS_OR_RECENT_TASKS_AND_RESTORE |
| 276 | }) |
| 277 | public @interface AnyTaskForIdMatchTaskMode {} |
| 278 | // Match only tasks in the current stacks |
| 279 | static final int MATCH_TASK_IN_STACKS_ONLY = 0; |
| 280 | // Match either tasks in the current stacks, or in the recent tasks if not found in the stacks |
| 281 | static final int MATCH_TASK_IN_STACKS_OR_RECENT_TASKS = 1; |
| 282 | // Match either tasks in the current stacks, or in the recent tasks, restoring it to the |
| 283 | // provided stack id |
| 284 | static final int MATCH_TASK_IN_STACKS_OR_RECENT_TASKS_AND_RESTORE = 2; |
| 285 | |
Svetoslav | 7008b51 | 2015-06-24 18:47:07 -0700 | [diff] [blame] | 286 | // Activity actions an app cannot start if it uses a permission which is not granted. |
| 287 | private static final ArrayMap<String, String> ACTION_TO_RUNTIME_PERMISSION = |
| 288 | new ArrayMap<>(); |
Filip Gruszczynski | bc5a6c5 | 2015-09-22 13:13:24 -0700 | [diff] [blame] | 289 | |
Svetoslav | 7008b51 | 2015-06-24 18:47:07 -0700 | [diff] [blame] | 290 | static { |
| 291 | ACTION_TO_RUNTIME_PERMISSION.put(MediaStore.ACTION_IMAGE_CAPTURE, |
| 292 | Manifest.permission.CAMERA); |
| 293 | ACTION_TO_RUNTIME_PERMISSION.put(MediaStore.ACTION_VIDEO_CAPTURE, |
| 294 | Manifest.permission.CAMERA); |
| 295 | ACTION_TO_RUNTIME_PERMISSION.put(Intent.ACTION_CALL, |
| 296 | Manifest.permission.CALL_PHONE); |
| 297 | } |
| 298 | |
Svet Ganov | 99b6043 | 2015-06-27 13:15:22 -0700 | [diff] [blame] | 299 | /** Action restriction: launching the activity is not restricted. */ |
| 300 | private static final int ACTIVITY_RESTRICTION_NONE = 0; |
| 301 | /** Action restriction: launching the activity is restricted by a permission. */ |
| 302 | private static final int ACTIVITY_RESTRICTION_PERMISSION = 1; |
| 303 | /** Action restriction: launching the activity is restricted by an app op. */ |
| 304 | private static final int ACTIVITY_RESTRICTION_APPOP = 2; |
Svetoslav | 7008b51 | 2015-06-24 18:47:07 -0700 | [diff] [blame] | 305 | |
justinzhang | 5286d3f | 2014-05-12 17:06:01 -0400 | [diff] [blame] | 306 | /** Status Bar Service **/ |
| 307 | private IBinder mToken = new Binder(); |
| 308 | private IStatusBarService mStatusBarService; |
Jason Monk | 35c62a4 | 2014-06-17 10:24:47 -0400 | [diff] [blame] | 309 | private IDevicePolicyManager mDevicePolicyManager; |
justinzhang | 5286d3f | 2014-05-12 17:06:01 -0400 | [diff] [blame] | 310 | |
Craig Mautner | 7ea5bd4 | 2013-07-05 15:27:08 -0700 | [diff] [blame] | 311 | // For debugging to make sure the caller when acquiring/releasing our |
| 312 | // wake lock is the system process. |
| 313 | static final boolean VALIDATE_WAKE_LOCK_CALLER = false; |
Suprabh Shukla | 09a88f5 | 2015-12-02 14:36:31 -0800 | [diff] [blame] | 314 | /** The number of distinct task ids that can be assigned to the tasks of a single user */ |
| 315 | 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] | 316 | |
Craig Mautner | 2708430 | 2013-03-25 08:05:25 -0700 | [diff] [blame] | 317 | final ActivityManagerService mService; |
| 318 | |
Suprabh Shukla | 09a88f5 | 2015-12-02 14:36:31 -0800 | [diff] [blame] | 319 | private RecentTasks mRecentTasks; |
Wale Ogunwale | c82f2f5 | 2014-12-09 09:32:50 -0800 | [diff] [blame] | 320 | |
Craig Mautner | ce5f3cb | 2013-04-22 08:58:54 -0700 | [diff] [blame] | 321 | final ActivityStackSupervisorHandler mHandler; |
| 322 | |
| 323 | /** Short cut */ |
| 324 | WindowManagerService mWindowManager; |
Craig Mautner | 4a1cb22 | 2013-12-04 16:14:06 -0800 | [diff] [blame] | 325 | DisplayManager mDisplayManager; |
Craig Mautner | ce5f3cb | 2013-04-22 08:58:54 -0700 | [diff] [blame] | 326 | |
Wale Ogunwale | ddc1cb2 | 2015-07-25 19:23:04 -0700 | [diff] [blame] | 327 | /** Counter for next free stack ID to use for dynamic activity stacks. */ |
| 328 | private int mNextFreeStackId = FIRST_DYNAMIC_STACK_ID; |
Craig Mautner | 8d341ef | 2013-03-26 09:03:27 -0700 | [diff] [blame] | 329 | |
Suprabh Shukla | 09a88f5 | 2015-12-02 14:36:31 -0800 | [diff] [blame] | 330 | /** |
| 331 | * Maps the task identifier that activities are currently being started in to the userId of the |
| 332 | * task. Each time a new task is created, the entry for the userId of the task is incremented |
| 333 | */ |
| 334 | private final SparseIntArray mCurTaskIdForUser = new SparseIntArray(20); |
Craig Mautner | 8d341ef | 2013-03-26 09:03:27 -0700 | [diff] [blame] | 335 | |
Craig Mautner | 2420ead | 2013-04-01 17:13:20 -0700 | [diff] [blame] | 336 | /** The current user */ |
Filip Gruszczynski | 07a0e49 | 2015-12-17 14:16:38 -0800 | [diff] [blame] | 337 | int mCurrentUser; |
Craig Mautner | 2420ead | 2013-04-01 17:13:20 -0700 | [diff] [blame] | 338 | |
Craig Mautner | e0a3884 | 2013-12-16 16:14:02 -0800 | [diff] [blame] | 339 | /** The stack containing the launcher app. Assumed to always be attached to |
| 340 | * Display.DEFAULT_DISPLAY. */ |
Filip Gruszczynski | 07a0e49 | 2015-12-17 14:16:38 -0800 | [diff] [blame] | 341 | ActivityStack mHomeStack; |
Craig Mautner | 20e7227 | 2013-04-01 13:45:53 -0700 | [diff] [blame] | 342 | |
Craig Mautner | e0a3884 | 2013-12-16 16:14:02 -0800 | [diff] [blame] | 343 | /** The stack currently receiving input or launching the next activity. */ |
Filip Gruszczynski | 07a0e49 | 2015-12-17 14:16:38 -0800 | [diff] [blame] | 344 | ActivityStack mFocusedStack; |
Craig Mautner | 8d341ef | 2013-03-26 09:03:27 -0700 | [diff] [blame] | 345 | |
Craig Mautner | 4a1cb22 | 2013-12-04 16:14:06 -0800 | [diff] [blame] | 346 | /** If this is the same as mFocusedStack then the activity on the top of the focused stack has |
| 347 | * 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] | 348 | * stack becomes resumed after which it will be set to mFocusedStack. */ |
Craig Mautner | 4a1cb22 | 2013-12-04 16:14:06 -0800 | [diff] [blame] | 349 | private ActivityStack mLastFocusedStack; |
Craig Mautner | de4ef02 | 2013-04-07 19:01:33 -0700 | [diff] [blame] | 350 | |
| 351 | /** List of activities that are waiting for a new activity to become visible before completing |
| 352 | * whatever operation they are supposed to do. */ |
Bryce Lee | 4a19438 | 2017-04-04 14:32:48 -0700 | [diff] [blame] | 353 | // TODO: Remove mActivitiesWaitingForVisibleActivity list and just remove activity from |
| 354 | // mStoppingActivities when something else comes up. |
| 355 | final ArrayList<ActivityRecord> mActivitiesWaitingForVisibleActivity = new ArrayList<>(); |
Craig Mautner | de4ef02 | 2013-04-07 19:01:33 -0700 | [diff] [blame] | 356 | |
Bryce Lee | 4a19438 | 2017-04-04 14:32:48 -0700 | [diff] [blame] | 357 | /** List of processes waiting to find out when a specific activity becomes visible. */ |
| 358 | private final ArrayList<WaitInfo> mWaitingForActivityVisible = new ArrayList<>(); |
Craig Mautner | ce5f3cb | 2013-04-22 08:58:54 -0700 | [diff] [blame] | 359 | |
| 360 | /** List of processes waiting to find out about the next launched activity. */ |
Sudheer Shanka | fc46e9b | 2016-10-21 17:55:27 -0700 | [diff] [blame] | 361 | final ArrayList<WaitResult> mWaitingActivityLaunched = new ArrayList<>(); |
Craig Mautner | ce5f3cb | 2013-04-22 08:58:54 -0700 | [diff] [blame] | 362 | |
Craig Mautner | de4ef02 | 2013-04-07 19:01:33 -0700 | [diff] [blame] | 363 | /** List of activities that are ready to be stopped, but waiting for the next activity to |
| 364 | * settle down before doing so. */ |
Craig Mautner | 8c14c15 | 2015-01-15 17:32:07 -0800 | [diff] [blame] | 365 | final ArrayList<ActivityRecord> mStoppingActivities = new ArrayList<>(); |
Craig Mautner | de4ef02 | 2013-04-07 19:01:33 -0700 | [diff] [blame] | 366 | |
Craig Mautner | f333327 | 2013-04-22 10:55:53 -0700 | [diff] [blame] | 367 | /** List of activities that are ready to be finished, but waiting for the previous activity to |
| 368 | * settle down before doing so. It contains ActivityRecord objects. */ |
Craig Mautner | 8c14c15 | 2015-01-15 17:32:07 -0800 | [diff] [blame] | 369 | final ArrayList<ActivityRecord> mFinishingActivities = new ArrayList<>(); |
Craig Mautner | f333327 | 2013-04-22 10:55:53 -0700 | [diff] [blame] | 370 | |
Craig Mautner | 0eea92c | 2013-05-16 13:35:39 -0700 | [diff] [blame] | 371 | /** List of activities that are in the process of going to sleep. */ |
Craig Mautner | 8c14c15 | 2015-01-15 17:32:07 -0800 | [diff] [blame] | 372 | final ArrayList<ActivityRecord> mGoingToSleepActivities = new ArrayList<>(); |
Craig Mautner | 0eea92c | 2013-05-16 13:35:39 -0700 | [diff] [blame] | 373 | |
Wale Ogunwale | 22e2526 | 2016-02-01 10:32:02 -0800 | [diff] [blame] | 374 | /** List of activities whose multi-window mode changed that we need to report to the |
| 375 | * application */ |
| 376 | final ArrayList<ActivityRecord> mMultiWindowModeChangedActivities = new ArrayList<>(); |
| 377 | |
| 378 | /** List of activities whose picture-in-picture mode changed that we need to report to the |
| 379 | * application */ |
| 380 | final ArrayList<ActivityRecord> mPipModeChangedActivities = new ArrayList<>(); |
| 381 | |
Winson Chung | 5af42fc | 2017-03-24 17:11:33 -0700 | [diff] [blame] | 382 | /** The target stack bounds for the picture-in-picture mode changed that we need to report to |
| 383 | * the application */ |
| 384 | Rect mPipModeChangedTargetStackBounds; |
| 385 | |
Craig Mautner | f333327 | 2013-04-22 10:55:53 -0700 | [diff] [blame] | 386 | /** Used on user changes */ |
Amith Yamasani | 37a40c2 | 2015-06-17 13:25:42 -0700 | [diff] [blame] | 387 | final ArrayList<UserState> mStartingUsers = new ArrayList<>(); |
Craig Mautner | f333327 | 2013-04-22 10:55:53 -0700 | [diff] [blame] | 388 | |
Craig Mautner | de4ef02 | 2013-04-07 19:01:33 -0700 | [diff] [blame] | 389 | /** Set to indicate whether to issue an onUserLeaving callback when a newly launched activity |
| 390 | * is being brought in front of us. */ |
| 391 | boolean mUserLeaving = false; |
| 392 | |
Craig Mautner | 0eea92c | 2013-05-16 13:35:39 -0700 | [diff] [blame] | 393 | /** Set when we have taken too long waiting to go to sleep. */ |
| 394 | boolean mSleepTimeout = false; |
| 395 | |
| 396 | /** |
Craig Mautner | 7ea5bd4 | 2013-07-05 15:27:08 -0700 | [diff] [blame] | 397 | * We don't want to allow the device to go to sleep while in the process |
| 398 | * of launching an activity. This is primarily to allow alarm intent |
| 399 | * receivers to launch an activity and get that to run before the device |
| 400 | * goes back to sleep. |
| 401 | */ |
Jeff Brown | 2c43c33 | 2014-06-12 22:38:59 -0700 | [diff] [blame] | 402 | PowerManager.WakeLock mLaunchingActivity; |
Craig Mautner | 7ea5bd4 | 2013-07-05 15:27:08 -0700 | [diff] [blame] | 403 | |
| 404 | /** |
Craig Mautner | 0eea92c | 2013-05-16 13:35:39 -0700 | [diff] [blame] | 405 | * Set when the system is going to sleep, until we have |
| 406 | * successfully paused the current activity and released our wake lock. |
| 407 | * At that point the system is allowed to actually sleep. |
| 408 | */ |
Jeff Brown | 2c43c33 | 2014-06-12 22:38:59 -0700 | [diff] [blame] | 409 | PowerManager.WakeLock mGoingToSleep; |
Craig Mautner | 0eea92c | 2013-05-16 13:35:39 -0700 | [diff] [blame] | 410 | |
Craig Mautner | 4f1df4f | 2013-10-15 15:44:14 -0700 | [diff] [blame] | 411 | /** Stack id of the front stack when user switched, indexed by userId. */ |
| 412 | SparseIntArray mUserStackInFront = new SparseIntArray(2); |
Craig Mautner | 93529a4 | 2013-10-04 15:03:13 -0700 | [diff] [blame] | 413 | |
Craig Mautner | 4504de5 | 2013-12-20 09:06:56 -0800 | [diff] [blame] | 414 | // TODO: Add listener for removal of references. |
Craig Mautner | 4a1cb22 | 2013-12-04 16:14:06 -0800 | [diff] [blame] | 415 | /** Mapping from (ActivityStack/TaskStack).mStackId to their current state */ |
Wale Ogunwale | 1666e31 | 2016-12-16 11:27:18 -0800 | [diff] [blame] | 416 | SparseArray<ActivityContainer> mActivityContainers = new SparseArray<>(); |
Craig Mautner | 4a1cb22 | 2013-12-04 16:14:06 -0800 | [diff] [blame] | 417 | |
Bryce Lee | af3a400 | 2017-03-20 10:37:12 -0700 | [diff] [blame] | 418 | // TODO: There should be an ActivityDisplayController coordinating am/wm interaction. |
Craig Mautner | 4a1cb22 | 2013-12-04 16:14:06 -0800 | [diff] [blame] | 419 | /** Mapping from displayId to display current state */ |
Craig Mautner | 15df08a | 2015-04-01 12:17:18 -0700 | [diff] [blame] | 420 | private final SparseArray<ActivityDisplay> mActivityDisplays = new SparseArray<>(); |
Craig Mautner | 4a1cb22 | 2013-12-04 16:14:06 -0800 | [diff] [blame] | 421 | |
Andrii Kulian | fb1bf69 | 2017-01-17 11:17:34 -0800 | [diff] [blame] | 422 | private final SparseArray<IntArray> mDisplayAccessUIDs = new SparseArray<>(); |
| 423 | |
| 424 | private DisplayManagerInternal mDisplayManagerInternal; |
| 425 | private InputManagerInternal mInputManagerInternal; |
Jeff Brown | ca9bc70 | 2014-02-11 14:32:56 -0800 | [diff] [blame] | 426 | |
Craig Mautner | 15df08a | 2015-04-01 12:17:18 -0700 | [diff] [blame] | 427 | /** The chain of tasks in lockTask mode. The current frontmost task is at the top, and tasks |
| 428 | * may be finished until there is only one entry left. If this is empty the system is not |
| 429 | * in lockTask mode. */ |
| 430 | ArrayList<TaskRecord> mLockTaskModeTasks = new ArrayList<>(); |
Benjamin Franz | 4326114 | 2015-02-11 15:59:44 +0000 | [diff] [blame] | 431 | /** Store the current lock task mode. Possible values: |
Craig Mautner | 2568c3a | 2015-03-26 14:22:34 -0700 | [diff] [blame] | 432 | * {@link ActivityManager#LOCK_TASK_MODE_NONE}, {@link ActivityManager#LOCK_TASK_MODE_LOCKED}, |
| 433 | * {@link ActivityManager#LOCK_TASK_MODE_PINNED} |
Benjamin Franz | 4326114 | 2015-02-11 15:59:44 +0000 | [diff] [blame] | 434 | */ |
| 435 | private int mLockTaskModeState; |
Jason Monk | 62515be | 2014-05-21 16:06:19 -0400 | [diff] [blame] | 436 | /** |
| 437 | * Notifies the user when entering/exiting lock-task. |
| 438 | */ |
| 439 | private LockTaskNotify mLockTaskNotify; |
Craig Mautner | aea74a5 | 2014-03-08 14:23:10 -0800 | [diff] [blame] | 440 | |
Wale Ogunwale | d046a01 | 2015-12-24 13:05:59 -0800 | [diff] [blame] | 441 | /** Used to keep resumeTopActivityUncheckedLocked() from being entered recursively */ |
Craig Mautner | 42d04db | 2014-11-06 12:13:23 -0800 | [diff] [blame] | 442 | boolean inResumeTopActivity; |
| 443 | |
Andrii Kulian | 1e32e02 | 2016-09-16 15:29:34 -0700 | [diff] [blame] | 444 | /** |
| 445 | * Temporary rect used during docked stack resize calculation so we don't need to create a new |
| 446 | * object each time. |
| 447 | */ |
Wale Ogunwale | b34a7ad | 2015-08-14 11:05:30 -0700 | [diff] [blame] | 448 | private final Rect tempRect = new Rect(); |
Filip Gruszczynski | ebcc875 | 2015-08-25 16:51:05 -0700 | [diff] [blame] | 449 | |
Filip Gruszczynski | d2f1d94 | 2015-10-14 15:10:12 -0700 | [diff] [blame] | 450 | // The default minimal size that will be used if the activity doesn't specify its minimal size. |
| 451 | // It will be calculated when the default display gets added. |
Andrii Kulian | f66a83d | 2016-05-17 12:17:44 -0700 | [diff] [blame] | 452 | int mDefaultMinSizeOfResizeableTask = -1; |
Filip Gruszczynski | d2f1d94 | 2015-10-14 15:10:12 -0700 | [diff] [blame] | 453 | |
Chong Zhang | fdcc4d4 | 2015-10-14 16:50:12 -0700 | [diff] [blame] | 454 | // Whether tasks have moved and we need to rank the tasks before next OOM scoring |
| 455 | private boolean mTaskLayersChanged = true; |
| 456 | |
Jorim Jaggi | 275561a | 2016-02-23 10:11:02 -0500 | [diff] [blame] | 457 | final ActivityMetricsLogger mActivityMetricsLogger; |
Filip Gruszczynski | 77d9448 | 2015-12-11 13:59:52 -0800 | [diff] [blame] | 458 | |
Andrii Kulian | 1779e61 | 2016-10-12 21:58:25 -0700 | [diff] [blame] | 459 | @Override |
| 460 | protected int getChildCount() { |
| 461 | return mActivityDisplays.size(); |
| 462 | } |
| 463 | |
| 464 | @Override |
Andrii Kulian | 5406e7a | 2016-10-21 11:55:23 -0700 | [diff] [blame] | 465 | protected ActivityDisplay getChildAt(int index) { |
Andrii Kulian | 1779e61 | 2016-10-12 21:58:25 -0700 | [diff] [blame] | 466 | return mActivityDisplays.valueAt(index); |
| 467 | } |
| 468 | |
| 469 | @Override |
| 470 | protected ConfigurationContainer getParent() { |
| 471 | return null; |
| 472 | } |
| 473 | |
Andrii Kulian | 5406e7a | 2016-10-21 11:55:23 -0700 | [diff] [blame] | 474 | Configuration getDisplayOverrideConfiguration(int displayId) { |
Andrii Kulian | 62e6f25 | 2017-05-30 22:46:53 -0700 | [diff] [blame] | 475 | final ActivityDisplay activityDisplay = getActivityDisplayOrCreateLocked(displayId); |
Andrii Kulian | 5406e7a | 2016-10-21 11:55:23 -0700 | [diff] [blame] | 476 | if (activityDisplay == null) { |
| 477 | throw new IllegalArgumentException("No display found with id: " + displayId); |
| 478 | } |
| 479 | |
| 480 | return activityDisplay.getOverrideConfiguration(); |
| 481 | } |
| 482 | |
| 483 | void setDisplayOverrideConfiguration(Configuration overrideConfiguration, int displayId) { |
Andrii Kulian | 62e6f25 | 2017-05-30 22:46:53 -0700 | [diff] [blame] | 484 | final ActivityDisplay activityDisplay = getActivityDisplayOrCreateLocked(displayId); |
Andrii Kulian | 5406e7a | 2016-10-21 11:55:23 -0700 | [diff] [blame] | 485 | if (activityDisplay == null) { |
| 486 | throw new IllegalArgumentException("No display found with id: " + displayId); |
| 487 | } |
| 488 | |
| 489 | activityDisplay.onOverrideConfigurationChanged(overrideConfiguration); |
| 490 | } |
| 491 | |
Andrii Kulian | 036e3ad | 2017-04-19 10:55:10 -0700 | [diff] [blame] | 492 | /** Check if placing task or activity on specified display is allowed. */ |
| 493 | boolean canPlaceEntityOnDisplay(int displayId, boolean resizeable) { |
| 494 | return displayId == DEFAULT_DISPLAY || (mService.mSupportsMultiDisplay |
| 495 | && (resizeable || displayConfigMatchesGlobal(displayId))); |
| 496 | } |
| 497 | |
| 498 | /** |
| 499 | * Check if configuration of specified display matches current global config. |
| 500 | * Used to check if we can put a non-resizeable activity on a secondary display and it will get |
| 501 | * the same config as on the default display. |
| 502 | * @param displayId Id of the display to check. |
| 503 | * @return {@code true} if configuration matches. |
| 504 | */ |
| 505 | private boolean displayConfigMatchesGlobal(int displayId) { |
| 506 | if (displayId == DEFAULT_DISPLAY) { |
| 507 | return true; |
| 508 | } |
| 509 | if (displayId == INVALID_DISPLAY) { |
| 510 | return false; |
| 511 | } |
Andrii Kulian | 62e6f25 | 2017-05-30 22:46:53 -0700 | [diff] [blame] | 512 | final ActivityDisplay targetDisplay = getActivityDisplayOrCreateLocked(displayId); |
Andrii Kulian | 036e3ad | 2017-04-19 10:55:10 -0700 | [diff] [blame] | 513 | if (targetDisplay == null) { |
| 514 | throw new IllegalArgumentException("No display found with id: " + displayId); |
| 515 | } |
| 516 | return getConfiguration().equals(targetDisplay.getConfiguration()); |
| 517 | } |
| 518 | |
Wale Ogunwale | 3938197 | 2015-12-17 17:15:29 -0800 | [diff] [blame] | 519 | static class FindTaskResult { |
| 520 | ActivityRecord r; |
| 521 | boolean matchedByRootAffinity; |
| 522 | } |
| 523 | private final FindTaskResult mTmpFindTaskResult = new FindTaskResult(); |
| 524 | |
Craig Mautner | ee36c77 | 2014-07-16 14:56:05 -0700 | [diff] [blame] | 525 | /** |
Andrii Kulian | 7fc2281 | 2016-12-28 13:04:11 -0800 | [diff] [blame] | 526 | * Temp storage for display ids sorted in focus order. |
| 527 | * Maps position to id. Using {@link SparseIntArray} instead of {@link ArrayList} because |
| 528 | * it's more efficient, as the number of displays is usually small. |
| 529 | */ |
| 530 | private SparseIntArray mTmpOrderedDisplayIds = new SparseIntArray(); |
| 531 | |
| 532 | /** |
Jorim Jaggi | a0fdeec | 2016-01-07 14:42:28 +0100 | [diff] [blame] | 533 | * Used to keep track whether app visibilities got changed since the last pause. Useful to |
| 534 | * determine whether to invoke the task stack change listener after pausing. |
| 535 | */ |
| 536 | boolean mAppVisibilitiesChangedSinceLastPause; |
| 537 | |
| 538 | /** |
Jorim Jaggi | 0b46f3c | 2016-03-14 12:21:37 +0100 | [diff] [blame] | 539 | * Set of tasks that are in resizing mode during an app transition to fill the "void". |
| 540 | */ |
| 541 | private final ArraySet<Integer> mResizingTasksDuringAnimation = new ArraySet<>(); |
| 542 | |
Wale Ogunwale | c8da41e | 2016-04-16 13:27:23 -0700 | [diff] [blame] | 543 | |
| 544 | /** |
| 545 | * If set to {@code false} all calls to resize the docked stack {@link #resizeDockedStackLocked} |
| 546 | * will be ignored. Useful for the case where the caller is handling resizing of other stack and |
| 547 | * moving tasks around and doesn't want dock stack to be resized due to an automatic trigger |
| 548 | * like the docked stack going empty. |
| 549 | */ |
| 550 | private boolean mAllowDockedStackResize = true; |
| 551 | |
Jorim Jaggi | 0b46f3c | 2016-03-14 12:21:37 +0100 | [diff] [blame] | 552 | /** |
Tony Mak | 853304c | 2016-04-18 15:17:41 +0100 | [diff] [blame] | 553 | * Is dock currently minimized. |
| 554 | */ |
| 555 | boolean mIsDockMinimized; |
| 556 | |
Jorim Jaggi | fe76234 | 2016-10-13 14:33:27 +0200 | [diff] [blame] | 557 | final KeyguardController mKeyguardController; |
| 558 | |
Tony Mak | 853304c | 2016-04-18 15:17:41 +0100 | [diff] [blame] | 559 | /** |
Craig Mautner | ee36c77 | 2014-07-16 14:56:05 -0700 | [diff] [blame] | 560 | * Description of a request to start a new activity, which has been held |
| 561 | * due to app switches being disabled. |
| 562 | */ |
| 563 | static class PendingActivityLaunch { |
| 564 | final ActivityRecord r; |
| 565 | final ActivityRecord sourceRecord; |
| 566 | final int startFlags; |
| 567 | final ActivityStack stack; |
Robert Carr | 13997f5 | 2015-10-23 13:13:39 -0700 | [diff] [blame] | 568 | final ProcessRecord callerApp; |
Craig Mautner | ee36c77 | 2014-07-16 14:56:05 -0700 | [diff] [blame] | 569 | |
| 570 | PendingActivityLaunch(ActivityRecord _r, ActivityRecord _sourceRecord, |
Robert Carr | 13997f5 | 2015-10-23 13:13:39 -0700 | [diff] [blame] | 571 | int _startFlags, ActivityStack _stack, ProcessRecord _callerApp) { |
Craig Mautner | ee36c77 | 2014-07-16 14:56:05 -0700 | [diff] [blame] | 572 | r = _r; |
| 573 | sourceRecord = _sourceRecord; |
| 574 | startFlags = _startFlags; |
| 575 | stack = _stack; |
Robert Carr | 13997f5 | 2015-10-23 13:13:39 -0700 | [diff] [blame] | 576 | callerApp = _callerApp; |
| 577 | } |
| 578 | |
| 579 | void sendErrorResult(String message) { |
| 580 | try { |
| 581 | if (callerApp.thread != null) { |
| 582 | callerApp.thread.scheduleCrash(message); |
| 583 | } |
| 584 | } catch (RemoteException e) { |
| 585 | Slog.e(TAG, "Exception scheduling crash of failed " |
| 586 | + "activity launcher sourceRecord=" + sourceRecord, e); |
| 587 | } |
Craig Mautner | ee36c77 | 2014-07-16 14:56:05 -0700 | [diff] [blame] | 588 | } |
| 589 | } |
| 590 | |
Bryce Lee | af691c0 | 2017-03-20 14:20:22 -0700 | [diff] [blame] | 591 | public ActivityStackSupervisor(ActivityManagerService service, Looper looper) { |
Craig Mautner | 2708430 | 2013-03-25 08:05:25 -0700 | [diff] [blame] | 592 | mService = service; |
Bryce Lee | af691c0 | 2017-03-20 14:20:22 -0700 | [diff] [blame] | 593 | mHandler = new ActivityStackSupervisorHandler(looper); |
Filip Gruszczynski | 77d9448 | 2015-12-11 13:59:52 -0800 | [diff] [blame] | 594 | mActivityMetricsLogger = new ActivityMetricsLogger(this, mService.mContext); |
Jorim Jaggi | fe76234 | 2016-10-13 14:33:27 +0200 | [diff] [blame] | 595 | mKeyguardController = new KeyguardController(service, this); |
Jeff Brown | 2c43c33 | 2014-06-12 22:38:59 -0700 | [diff] [blame] | 596 | } |
| 597 | |
Suprabh Shukla | 09a88f5 | 2015-12-02 14:36:31 -0800 | [diff] [blame] | 598 | void setRecentTasks(RecentTasks recentTasks) { |
| 599 | mRecentTasks = recentTasks; |
| 600 | } |
| 601 | |
Jeff Brown | 2c43c33 | 2014-06-12 22:38:59 -0700 | [diff] [blame] | 602 | /** |
| 603 | * At the time when the constructor runs, the power manager has not yet been |
| 604 | * initialized. So we initialize our wakelocks afterwards. |
| 605 | */ |
| 606 | void initPowerManagement() { |
Craig Mautner | 4a1cb22 | 2013-12-04 16:14:06 -0800 | [diff] [blame] | 607 | PowerManager pm = (PowerManager)mService.mContext.getSystemService(Context.POWER_SERVICE); |
Craig Mautner | 0eea92c | 2013-05-16 13:35:39 -0700 | [diff] [blame] | 608 | mGoingToSleep = pm.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, "ActivityManager-Sleep"); |
Dianne Hackborn | 3d07c94 | 2015-03-13 18:02:54 -0700 | [diff] [blame] | 609 | mLaunchingActivity = pm.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, "*launch*"); |
Craig Mautner | 7ea5bd4 | 2013-07-05 15:27:08 -0700 | [diff] [blame] | 610 | mLaunchingActivity.setReferenceCounted(false); |
Craig Mautner | 2219a1b | 2013-03-25 09:44:30 -0700 | [diff] [blame] | 611 | } |
| 612 | |
justinzhang | 5286d3f | 2014-05-12 17:06:01 -0400 | [diff] [blame] | 613 | // This function returns a IStatusBarService. The value is from ServiceManager. |
| 614 | // getService and is cached. |
| 615 | private IStatusBarService getStatusBarService() { |
| 616 | synchronized (mService) { |
| 617 | if (mStatusBarService == null) { |
| 618 | mStatusBarService = IStatusBarService.Stub.asInterface( |
| 619 | ServiceManager.checkService(Context.STATUS_BAR_SERVICE)); |
| 620 | if (mStatusBarService == null) { |
| 621 | Slog.w("StatusBarManager", "warning: no STATUS_BAR_SERVICE"); |
| 622 | } |
| 623 | } |
| 624 | return mStatusBarService; |
| 625 | } |
| 626 | } |
| 627 | |
Jason Monk | 35c62a4 | 2014-06-17 10:24:47 -0400 | [diff] [blame] | 628 | private IDevicePolicyManager getDevicePolicyManager() { |
| 629 | synchronized (mService) { |
| 630 | if (mDevicePolicyManager == null) { |
| 631 | mDevicePolicyManager = IDevicePolicyManager.Stub.asInterface( |
| 632 | ServiceManager.checkService(Context.DEVICE_POLICY_SERVICE)); |
| 633 | if (mDevicePolicyManager == null) { |
| 634 | Slog.w(TAG, "warning: no DEVICE_POLICY_SERVICE"); |
| 635 | } |
| 636 | } |
| 637 | return mDevicePolicyManager; |
| 638 | } |
| 639 | } |
| 640 | |
Craig Mautner | ce5f3cb | 2013-04-22 08:58:54 -0700 | [diff] [blame] | 641 | void setWindowManager(WindowManagerService wm) { |
Craig Mautner | 4a1cb22 | 2013-12-04 16:14:06 -0800 | [diff] [blame] | 642 | synchronized (mService) { |
| 643 | mWindowManager = wm; |
Jorim Jaggi | fe76234 | 2016-10-13 14:33:27 +0200 | [diff] [blame] | 644 | mKeyguardController.setWindowManager(wm); |
Craig Mautner | 4a1cb22 | 2013-12-04 16:14:06 -0800 | [diff] [blame] | 645 | |
| 646 | mDisplayManager = |
| 647 | (DisplayManager)mService.mContext.getSystemService(Context.DISPLAY_SERVICE); |
| 648 | mDisplayManager.registerDisplayListener(this, null); |
Andrii Kulian | fb1bf69 | 2017-01-17 11:17:34 -0800 | [diff] [blame] | 649 | mDisplayManagerInternal = LocalServices.getService(DisplayManagerInternal.class); |
Craig Mautner | 4a1cb22 | 2013-12-04 16:14:06 -0800 | [diff] [blame] | 650 | |
| 651 | Display[] displays = mDisplayManager.getDisplays(); |
| 652 | for (int displayNdx = displays.length - 1; displayNdx >= 0; --displayNdx) { |
| 653 | final int displayId = displays[displayNdx].getDisplayId(); |
Craig Mautner | e0a3884 | 2013-12-16 16:14:02 -0800 | [diff] [blame] | 654 | ActivityDisplay activityDisplay = new ActivityDisplay(displayId); |
Craig Mautner | 1a70a16 | 2014-09-13 12:09:31 -0700 | [diff] [blame] | 655 | if (activityDisplay.mDisplay == null) { |
| 656 | throw new IllegalStateException("Default Display does not exist"); |
| 657 | } |
Craig Mautner | e0a3884 | 2013-12-16 16:14:02 -0800 | [diff] [blame] | 658 | mActivityDisplays.put(displayId, activityDisplay); |
Filip Gruszczynski | 7be9a8c | 2015-10-15 18:20:30 -0700 | [diff] [blame] | 659 | calculateDefaultMinimalSizeOfResizeableTasks(activityDisplay); |
Craig Mautner | 4a1cb22 | 2013-12-04 16:14:06 -0800 | [diff] [blame] | 660 | } |
| 661 | |
Wale Ogunwale | 4cea0f5 | 2015-12-25 06:30:31 -0800 | [diff] [blame] | 662 | mHomeStack = mFocusedStack = mLastFocusedStack = |
| 663 | getStack(HOME_STACK_ID, CREATE_IF_NEEDED, ON_TOP); |
Jeff Brown | ca9bc70 | 2014-02-11 14:32:56 -0800 | [diff] [blame] | 664 | |
| 665 | mInputManagerInternal = LocalServices.getService(InputManagerInternal.class); |
Craig Mautner | 4a1cb22 | 2013-12-04 16:14:06 -0800 | [diff] [blame] | 666 | } |
Craig Mautner | 2708430 | 2013-03-25 08:05:25 -0700 | [diff] [blame] | 667 | } |
| 668 | |
Craig Mautner | ce5f3cb | 2013-04-22 08:58:54 -0700 | [diff] [blame] | 669 | ActivityStack getFocusedStack() { |
Craig Mautner | 4a1cb22 | 2013-12-04 16:14:06 -0800 | [diff] [blame] | 670 | return mFocusedStack; |
Craig Mautner | 20e7227 | 2013-04-01 13:45:53 -0700 | [diff] [blame] | 671 | } |
| 672 | |
Craig Mautner | de4ef02 | 2013-04-07 19:01:33 -0700 | [diff] [blame] | 673 | ActivityStack getLastStack() { |
Craig Mautner | 4a1cb22 | 2013-12-04 16:14:06 -0800 | [diff] [blame] | 674 | return mLastFocusedStack; |
Craig Mautner | 2219a1b | 2013-03-25 09:44:30 -0700 | [diff] [blame] | 675 | } |
| 676 | |
Wale Ogunwale | 1e60e0c | 2015-10-28 13:36:10 -0700 | [diff] [blame] | 677 | boolean isFocusedStack(ActivityStack stack) { |
Wale Ogunwale | 7d70117 | 2015-03-11 15:36:30 -0700 | [diff] [blame] | 678 | if (stack == null) { |
| 679 | return false; |
| 680 | } |
| 681 | |
Craig Mautner | df88d73 | 2014-01-27 09:21:32 -0800 | [diff] [blame] | 682 | final ActivityRecord parent = stack.mActivityContainer.mParentActivity; |
| 683 | if (parent != null) { |
Andrii Kulian | 02b7a83 | 2016-10-06 23:11:56 -0700 | [diff] [blame] | 684 | stack = parent.getStack(); |
Craig Mautner | df88d73 | 2014-01-27 09:21:32 -0800 | [diff] [blame] | 685 | } |
Wale Ogunwale | cb82f30 | 2015-02-25 07:53:40 -0800 | [diff] [blame] | 686 | return stack == mFocusedStack; |
Craig Mautner | 20e7227 | 2013-04-01 13:45:53 -0700 | [diff] [blame] | 687 | } |
| 688 | |
Andrii Kulian | e8d928a | 2016-11-14 18:38:14 -0800 | [diff] [blame] | 689 | /** The top most stack on its display. */ |
| 690 | boolean isFrontStackOnDisplay(ActivityStack stack) { |
| 691 | return isFrontOfStackList(stack, stack.mActivityContainer.mActivityDisplay.mStacks); |
| 692 | } |
| 693 | |
| 694 | private boolean isFrontOfStackList(ActivityStack stack, List<ActivityStack> stackList) { |
Wale Ogunwale | 1e60e0c | 2015-10-28 13:36:10 -0700 | [diff] [blame] | 695 | if (stack == null) { |
| 696 | return false; |
Craig Mautner | 4a1cb22 | 2013-12-04 16:14:06 -0800 | [diff] [blame] | 697 | } |
Wale Ogunwale | 92acaf2 | 2015-03-18 14:43:41 -0700 | [diff] [blame] | 698 | |
Wale Ogunwale | 1e60e0c | 2015-10-28 13:36:10 -0700 | [diff] [blame] | 699 | final ActivityRecord parent = stack.mActivityContainer.mParentActivity; |
| 700 | if (parent != null) { |
Andrii Kulian | 02b7a83 | 2016-10-06 23:11:56 -0700 | [diff] [blame] | 701 | stack = parent.getStack(); |
Wale Ogunwale | cb82f30 | 2015-02-25 07:53:40 -0800 | [diff] [blame] | 702 | } |
Andrii Kulian | e8d928a | 2016-11-14 18:38:14 -0800 | [diff] [blame] | 703 | return stack == stackList.get((stackList.size() - 1)); |
Wale Ogunwale | 1e60e0c | 2015-10-28 13:36:10 -0700 | [diff] [blame] | 704 | } |
| 705 | |
Wale Ogunwale | d046a01 | 2015-12-24 13:05:59 -0800 | [diff] [blame] | 706 | /** NOTE: Should only be called from {@link ActivityStack#moveToFront} */ |
Wale Ogunwale | 4cea0f5 | 2015-12-25 06:30:31 -0800 | [diff] [blame] | 707 | void setFocusStackUnchecked(String reason, ActivityStack focusCandidate) { |
| 708 | if (!focusCandidate.isFocusable()) { |
| 709 | // 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] | 710 | focusCandidate = getNextFocusableStackLocked(focusCandidate); |
Wale Ogunwale | 4cea0f5 | 2015-12-25 06:30:31 -0800 | [diff] [blame] | 711 | } |
| 712 | |
| 713 | if (focusCandidate != mFocusedStack) { |
Wale Ogunwale | d046a01 | 2015-12-24 13:05:59 -0800 | [diff] [blame] | 714 | mLastFocusedStack = mFocusedStack; |
Wale Ogunwale | 4cea0f5 | 2015-12-25 06:30:31 -0800 | [diff] [blame] | 715 | mFocusedStack = focusCandidate; |
Wale Ogunwale | cb82f30 | 2015-02-25 07:53:40 -0800 | [diff] [blame] | 716 | |
Wale Ogunwale | d046a01 | 2015-12-24 13:05:59 -0800 | [diff] [blame] | 717 | EventLogTags.writeAmFocusedStack( |
| 718 | mCurrentUser, mFocusedStack == null ? -1 : mFocusedStack.getStackId(), |
| 719 | mLastFocusedStack == null ? -1 : mLastFocusedStack.getStackId(), reason); |
| 720 | } |
| 721 | |
| 722 | final ActivityRecord r = topRunningActivityLocked(); |
Craig Mautner | f3ea23a | 2015-01-13 09:37:08 -0800 | [diff] [blame] | 723 | if (mService.mBooting || !mService.mBooted) { |
Craig Mautner | f3ea23a | 2015-01-13 09:37:08 -0800 | [diff] [blame] | 724 | if (r != null && r.idle) { |
| 725 | checkFinishBootingLocked(); |
| 726 | } |
| 727 | } |
Craig Mautner | de4ef02 | 2013-04-07 19:01:33 -0700 | [diff] [blame] | 728 | } |
| 729 | |
Wale Ogunwale | 925d0d1 | 2015-09-23 15:40:07 -0700 | [diff] [blame] | 730 | void moveHomeStackToFront(String reason) { |
| 731 | mHomeStack.moveToFront(reason); |
| 732 | } |
| 733 | |
Matthew Ng | 330757d | 2017-02-28 14:19:17 -0800 | [diff] [blame] | 734 | void moveRecentsStackToFront(String reason) { |
| 735 | final ActivityStack recentsStack = getStack(RECENTS_STACK_ID); |
| 736 | if (recentsStack != null) { |
| 737 | recentsStack.moveToFront(reason); |
| 738 | } |
| 739 | } |
| 740 | |
Wale Ogunwale | d80c263 | 2015-03-13 10:26:26 -0700 | [diff] [blame] | 741 | /** 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] | 742 | boolean moveHomeStackTaskToTop(String reason) { |
| 743 | mHomeStack.moveHomeStackTaskToTop(); |
Wale Ogunwale | d80c263 | 2015-03-13 10:26:26 -0700 | [diff] [blame] | 744 | |
Wale Ogunwale | 2d0f39b | 2015-04-17 15:35:39 -0700 | [diff] [blame] | 745 | final ActivityRecord top = getHomeActivity(); |
Wale Ogunwale | d80c263 | 2015-03-13 10:26:26 -0700 | [diff] [blame] | 746 | if (top == null) { |
| 747 | return false; |
| 748 | } |
Chong Zhang | 6cda19c | 2016-06-14 19:07:56 -0700 | [diff] [blame] | 749 | moveFocusableActivityStackToFrontLocked(top, reason); |
Wale Ogunwale | d80c263 | 2015-03-13 10:26:26 -0700 | [diff] [blame] | 750 | return true; |
Craig Mautner | 8e56957 | 2013-10-11 17:36:59 -0700 | [diff] [blame] | 751 | } |
| 752 | |
Matthew Ng | ae1ff4f | 2016-11-10 15:49:14 -0800 | [diff] [blame] | 753 | boolean resumeHomeStackTask(ActivityRecord prev, String reason) { |
Dianne Hackborn | 7622a0f | 2014-09-30 14:31:42 -0700 | [diff] [blame] | 754 | if (!mService.mBooting && !mService.mBooted) { |
| 755 | // Not ready yet! |
| 756 | return false; |
| 757 | } |
| 758 | |
Craig Mautner | 84984fa | 2014-06-19 11:19:20 -0700 | [diff] [blame] | 759 | if (prev != null) { |
Bryce Lee | af691c0 | 2017-03-20 14:20:22 -0700 | [diff] [blame] | 760 | prev.getTask().setTaskToReturnTo(APPLICATION_ACTIVITY_TYPE); |
Craig Mautner | 84984fa | 2014-06-19 11:19:20 -0700 | [diff] [blame] | 761 | } |
| 762 | |
Matthew Ng | ae1ff4f | 2016-11-10 15:49:14 -0800 | [diff] [blame] | 763 | mHomeStack.moveHomeStackTaskToTop(); |
Wale Ogunwale | 2d0f39b | 2015-04-17 15:35:39 -0700 | [diff] [blame] | 764 | ActivityRecord r = getHomeActivity(); |
Wale Ogunwale | d046a01 | 2015-12-24 13:05:59 -0800 | [diff] [blame] | 765 | final String myReason = reason + " resumeHomeStackTask"; |
| 766 | |
Mark Lu | a56ea12 | 2015-10-08 13:31:01 +0800 | [diff] [blame] | 767 | // Only resume home activity if isn't finishing. |
| 768 | if (r != null && !r.finishing) { |
Chong Zhang | 6cda19c | 2016-06-14 19:07:56 -0700 | [diff] [blame] | 769 | moveFocusableActivityStackToFrontLocked(r, myReason); |
Wale Ogunwale | d046a01 | 2015-12-24 13:05:59 -0800 | [diff] [blame] | 770 | return resumeFocusedStackTopActivityLocked(mHomeStack, prev, null); |
Craig Mautner | 69ada55 | 2013-04-18 13:51:51 -0700 | [diff] [blame] | 771 | } |
Wale Ogunwale | d046a01 | 2015-12-24 13:05:59 -0800 | [diff] [blame] | 772 | return mService.startHomeActivityLocked(mCurrentUser, myReason); |
Craig Mautner | 69ada55 | 2013-04-18 13:51:51 -0700 | [diff] [blame] | 773 | } |
| 774 | |
Craig Mautner | 8d341ef | 2013-03-26 09:03:27 -0700 | [diff] [blame] | 775 | TaskRecord anyTaskForIdLocked(int id) { |
Winson Chung | 7900bee | 2017-03-10 08:59:25 -0800 | [diff] [blame] | 776 | return anyTaskForIdLocked(id, MATCH_TASK_IN_STACKS_OR_RECENT_TASKS_AND_RESTORE, |
| 777 | INVALID_STACK_ID); |
Wale Ogunwale | 04f4d6b | 2015-03-11 09:23:25 -0700 | [diff] [blame] | 778 | } |
| 779 | |
| 780 | /** |
Bryce Lee | 92b7b65 | 2017-04-03 08:33:11 -0700 | [diff] [blame] | 781 | * 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] | 782 | * @param id Id of the task we would like returned. |
Winson Chung | 7900bee | 2017-03-10 08:59:25 -0800 | [diff] [blame] | 783 | * @param matchMode The mode to match the given task id in. |
Wale Ogunwale | 3797c22 | 2015-10-27 14:21:58 -0700 | [diff] [blame] | 784 | * @param stackId The stack to restore the task to (default launch stack will be used if |
Winson Chung | 7900bee | 2017-03-10 08:59:25 -0800 | [diff] [blame] | 785 | * stackId is {@link android.app.ActivityManager.StackId#INVALID_STACK_ID}). Only |
| 786 | * valid if the matchMode is |
| 787 | * {@link #MATCH_TASK_IN_STACKS_OR_RECENT_TASKS_AND_RESTORE}. |
Wale Ogunwale | 04f4d6b | 2015-03-11 09:23:25 -0700 | [diff] [blame] | 788 | */ |
Winson Chung | 7900bee | 2017-03-10 08:59:25 -0800 | [diff] [blame] | 789 | TaskRecord anyTaskForIdLocked(int id, @AnyTaskForIdMatchTaskMode int matchMode, int stackId) { |
| 790 | // If there is a stack id set, ensure that we are attempting to actually restore a task |
| 791 | if (matchMode != MATCH_TASK_IN_STACKS_OR_RECENT_TASKS_AND_RESTORE && |
| 792 | stackId != INVALID_STACK_ID) { |
| 793 | throw new IllegalArgumentException("Should not specify stackId for non-restore lookup"); |
| 794 | } |
| 795 | |
Craig Mautner | e0a3884 | 2013-12-16 16:14:02 -0800 | [diff] [blame] | 796 | int numDisplays = mActivityDisplays.size(); |
Craig Mautner | 4a1cb22 | 2013-12-04 16:14:06 -0800 | [diff] [blame] | 797 | for (int displayNdx = 0; displayNdx < numDisplays; ++displayNdx) { |
Craig Mautner | e0a3884 | 2013-12-16 16:14:02 -0800 | [diff] [blame] | 798 | ArrayList<ActivityStack> stacks = mActivityDisplays.valueAt(displayNdx).mStacks; |
Craig Mautner | 4a1cb22 | 2013-12-04 16:14:06 -0800 | [diff] [blame] | 799 | for (int stackNdx = stacks.size() - 1; stackNdx >= 0; --stackNdx) { |
| 800 | ActivityStack stack = stacks.get(stackNdx); |
Bryce Lee | 92b7b65 | 2017-04-03 08:33:11 -0700 | [diff] [blame] | 801 | final TaskRecord task = stack.taskForIdLocked(id); |
Craig Mautner | 4a1cb22 | 2013-12-04 16:14:06 -0800 | [diff] [blame] | 802 | if (task != null) { |
| 803 | return task; |
| 804 | } |
Craig Mautner | 8d341ef | 2013-03-26 09:03:27 -0700 | [diff] [blame] | 805 | } |
| 806 | } |
Wale Ogunwale | 7de0535 | 2014-12-12 15:21:33 -0800 | [diff] [blame] | 807 | |
Winson Chung | 7900bee | 2017-03-10 08:59:25 -0800 | [diff] [blame] | 808 | // If we are matching stack tasks only, return now |
| 809 | if (matchMode == MATCH_TASK_IN_STACKS_ONLY) { |
Wale Ogunwale | 7de0535 | 2014-12-12 15:21:33 -0800 | [diff] [blame] | 810 | return null; |
| 811 | } |
| 812 | |
Winson Chung | 7900bee | 2017-03-10 08:59:25 -0800 | [diff] [blame] | 813 | // Otherwise, check the recent tasks and return if we find it there and we are not restoring |
| 814 | // the task from recents |
| 815 | 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] | 816 | final TaskRecord task = mRecentTasks.taskForIdLocked(id); |
| 817 | |
| 818 | if (task == null) { |
| 819 | if (DEBUG_RECENTS) { |
Winson Chung | 7900bee | 2017-03-10 08:59:25 -0800 | [diff] [blame] | 820 | Slog.d(TAG_RECENTS, "\tDidn't find task id=" + id + " in recents"); |
| 821 | } |
Bryce Lee | 92b7b65 | 2017-04-03 08:33:11 -0700 | [diff] [blame] | 822 | |
| 823 | return null; |
| 824 | } |
| 825 | |
| 826 | if (matchMode == MATCH_TASK_IN_STACKS_OR_RECENT_TASKS) { |
Wale Ogunwale | 04f4d6b | 2015-03-11 09:23:25 -0700 | [diff] [blame] | 827 | return task; |
| 828 | } |
| 829 | |
Winson Chung | 7900bee | 2017-03-10 08:59:25 -0800 | [diff] [blame] | 830 | // Implicitly, this case is MATCH_TASK_IN_STACKS_OR_RECENT_TASKS_AND_RESTORE |
Wale Ogunwale | 7e8184b | 2015-10-05 14:37:03 -0700 | [diff] [blame] | 831 | if (!restoreRecentTaskLocked(task, stackId)) { |
Wale Ogunwale | ee006da | 2015-03-30 14:49:25 -0700 | [diff] [blame] | 832 | if (DEBUG_RECENTS) Slog.w(TAG_RECENTS, |
| 833 | "Couldn't restore task id=" + id + " found in recents"); |
Wale Ogunwale | 7de0535 | 2014-12-12 15:21:33 -0800 | [diff] [blame] | 834 | return null; |
| 835 | } |
Wale Ogunwale | ee006da | 2015-03-30 14:49:25 -0700 | [diff] [blame] | 836 | 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] | 837 | return task; |
Craig Mautner | 8d341ef | 2013-03-26 09:03:27 -0700 | [diff] [blame] | 838 | } |
| 839 | |
Craig Mautner | 6170f73 | 2013-04-02 13:05:23 -0700 | [diff] [blame] | 840 | ActivityRecord isInAnyStackLocked(IBinder token) { |
Craig Mautner | e0a3884 | 2013-12-16 16:14:02 -0800 | [diff] [blame] | 841 | int numDisplays = mActivityDisplays.size(); |
Craig Mautner | 4a1cb22 | 2013-12-04 16:14:06 -0800 | [diff] [blame] | 842 | for (int displayNdx = 0; displayNdx < numDisplays; ++displayNdx) { |
Craig Mautner | e0a3884 | 2013-12-16 16:14:02 -0800 | [diff] [blame] | 843 | ArrayList<ActivityStack> stacks = mActivityDisplays.valueAt(displayNdx).mStacks; |
Craig Mautner | 4a1cb22 | 2013-12-04 16:14:06 -0800 | [diff] [blame] | 844 | for (int stackNdx = stacks.size() - 1; stackNdx >= 0; --stackNdx) { |
| 845 | final ActivityRecord r = stacks.get(stackNdx).isInStackLocked(token); |
| 846 | if (r != null) { |
| 847 | return r; |
| 848 | } |
Craig Mautner | 6170f73 | 2013-04-02 13:05:23 -0700 | [diff] [blame] | 849 | } |
| 850 | } |
| 851 | return null; |
| 852 | } |
| 853 | |
Tony Mak | 853304c | 2016-04-18 15:17:41 +0100 | [diff] [blame] | 854 | /** |
Robin Lee | 3fef1f2 | 2016-12-20 14:50:13 +0000 | [diff] [blame] | 855 | * Detects whether we should show a lock screen in front of this task for a locked user. |
| 856 | * <p> |
| 857 | * We'll do this if either of the following holds: |
| 858 | * <ul> |
| 859 | * <li>The top activity explicitly belongs to {@param userId}.</li> |
| 860 | * <li>The top activity returns a result to an activity belonging to {@param userId}.</li> |
| 861 | * </ul> |
| 862 | * |
| 863 | * @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] | 864 | */ |
Robin Lee | 3fef1f2 | 2016-12-20 14:50:13 +0000 | [diff] [blame] | 865 | private boolean taskTopActivityIsUser(TaskRecord task, @UserIdInt int userId) { |
| 866 | // To handle the case that work app is in the task but just is not the top one. |
| 867 | final ActivityRecord activityRecord = task.getTopActivity(); |
| 868 | final ActivityRecord resultTo = (activityRecord != null ? activityRecord.resultTo : null); |
| 869 | |
| 870 | return (activityRecord != null && activityRecord.userId == userId) |
| 871 | || (resultTo != null && resultTo.userId == userId); |
| 872 | } |
| 873 | |
| 874 | /** |
| 875 | * Find all visible task stacks containing {@param userId} and intercept them with an activity |
| 876 | * to block out the contents and possibly start a credential-confirming intent. |
| 877 | * |
| 878 | * @param userId user handle for the locked managed profile. |
| 879 | */ |
| 880 | void lockAllProfileTasks(@UserIdInt int userId) { |
| 881 | mWindowManager.deferSurfaceLayout(); |
| 882 | try { |
| 883 | final List<ActivityStack> stacks = getStacks(); |
| 884 | for (int stackNdx = stacks.size() - 1; stackNdx >= 0; stackNdx--) { |
| 885 | final List<TaskRecord> tasks = stacks.get(stackNdx).getAllTasks(); |
| 886 | for (int taskNdx = tasks.size() - 1; taskNdx >= 0; taskNdx--) { |
| 887 | final TaskRecord task = tasks.get(taskNdx); |
| 888 | |
| 889 | // Check the task for a top activity belonging to userId, or returning a result |
| 890 | // to an activity belonging to userId. Example case: a document picker for |
| 891 | // personal files, opened by a work app, should still get locked. |
| 892 | if (taskTopActivityIsUser(task, userId)) { |
Robin Lee | c41f6ec | 2017-01-10 17:02:34 +0000 | [diff] [blame] | 893 | mService.mTaskChangeNotificationController.notifyTaskProfileLocked( |
| 894 | task.taskId, userId); |
Robin Lee | 3fef1f2 | 2016-12-20 14:50:13 +0000 | [diff] [blame] | 895 | } |
Tony Mak | 853304c | 2016-04-18 15:17:41 +0100 | [diff] [blame] | 896 | } |
| 897 | } |
Robin Lee | 3fef1f2 | 2016-12-20 14:50:13 +0000 | [diff] [blame] | 898 | } finally { |
| 899 | mWindowManager.continueSurfaceLayout(); |
Tony Mak | 853304c | 2016-04-18 15:17:41 +0100 | [diff] [blame] | 900 | } |
Clara Bayarri | f0649ce | 2016-01-14 12:30:42 +0000 | [diff] [blame] | 901 | } |
| 902 | |
Suprabh Shukla | 09a88f5 | 2015-12-02 14:36:31 -0800 | [diff] [blame] | 903 | void setNextTaskIdForUserLocked(int taskId, int userId) { |
| 904 | final int currentTaskId = mCurTaskIdForUser.get(userId, -1); |
| 905 | if (taskId > currentTaskId) { |
| 906 | mCurTaskIdForUser.put(userId, taskId); |
Craig Mautner | ef73ee1 | 2014-04-23 11:45:37 -0700 | [diff] [blame] | 907 | } |
| 908 | } |
| 909 | |
Chong Zhang | d9d35bd | 2016-08-04 17:55:21 -0700 | [diff] [blame] | 910 | static int nextTaskIdForUser(int taskId, int userId) { |
| 911 | int nextTaskId = taskId + 1; |
| 912 | if (nextTaskId == (userId + 1) * MAX_TASK_IDS_PER_USER) { |
| 913 | // Wrap around as there will be smaller task ids that are available now. |
| 914 | nextTaskId -= MAX_TASK_IDS_PER_USER; |
| 915 | } |
| 916 | return nextTaskId; |
| 917 | } |
| 918 | |
Suprabh Shukla | 09a88f5 | 2015-12-02 14:36:31 -0800 | [diff] [blame] | 919 | int getNextTaskIdForUserLocked(int userId) { |
Suprabh Shukla | 09a88f5 | 2015-12-02 14:36:31 -0800 | [diff] [blame] | 920 | final int currentTaskId = mCurTaskIdForUser.get(userId, userId * MAX_TASK_IDS_PER_USER); |
| 921 | // for a userId u, a taskId can only be in the range |
| 922 | // [u*MAX_TASK_IDS_PER_USER, (u+1)*MAX_TASK_IDS_PER_USER-1], so if MAX_TASK_IDS_PER_USER |
| 923 | // 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] | 924 | int candidateTaskId = nextTaskIdForUser(currentTaskId, userId); |
Suprabh Shukla | 4bccb46 | 2016-02-10 18:45:12 -0800 | [diff] [blame] | 925 | while (mRecentTasks.taskIdTakenForUserLocked(candidateTaskId, userId) |
Winson Chung | 7900bee | 2017-03-10 08:59:25 -0800 | [diff] [blame] | 926 | || anyTaskForIdLocked(candidateTaskId, MATCH_TASK_IN_STACKS_OR_RECENT_TASKS, |
Suprabh Shukla | 4bccb46 | 2016-02-10 18:45:12 -0800 | [diff] [blame] | 927 | INVALID_STACK_ID) != null) { |
Chong Zhang | d9d35bd | 2016-08-04 17:55:21 -0700 | [diff] [blame] | 928 | candidateTaskId = nextTaskIdForUser(candidateTaskId, userId); |
Suprabh Shukla | 09a88f5 | 2015-12-02 14:36:31 -0800 | [diff] [blame] | 929 | if (candidateTaskId == currentTaskId) { |
| 930 | // Something wrong! |
| 931 | // All MAX_TASK_IDS_PER_USER task ids are taken up by running tasks for this user |
| 932 | throw new IllegalStateException("Cannot get an available task id." |
| 933 | + " Reached limit of " + MAX_TASK_IDS_PER_USER |
| 934 | + " running tasks per user."); |
| 935 | } |
| 936 | } |
| 937 | mCurTaskIdForUser.put(userId, candidateTaskId); |
| 938 | return candidateTaskId; |
Craig Mautner | 8d341ef | 2013-03-26 09:03:27 -0700 | [diff] [blame] | 939 | } |
| 940 | |
Chong Zhang | 6cda19c | 2016-06-14 19:07:56 -0700 | [diff] [blame] | 941 | ActivityRecord getResumedActivityLocked() { |
Wale Ogunwale | d697cea | 2015-02-20 17:19:49 -0800 | [diff] [blame] | 942 | ActivityStack stack = mFocusedStack; |
Craig Mautner | ce5f3cb | 2013-04-22 08:58:54 -0700 | [diff] [blame] | 943 | if (stack == null) { |
| 944 | return null; |
| 945 | } |
Craig Mautner | de4ef02 | 2013-04-07 19:01:33 -0700 | [diff] [blame] | 946 | ActivityRecord resumedActivity = stack.mResumedActivity; |
| 947 | if (resumedActivity == null || resumedActivity.app == null) { |
| 948 | resumedActivity = stack.mPausingActivity; |
| 949 | if (resumedActivity == null || resumedActivity.app == null) { |
Filip Gruszczynski | 3e85ba2 | 2015-10-05 22:48:30 -0700 | [diff] [blame] | 950 | resumedActivity = stack.topRunningActivityLocked(); |
Craig Mautner | de4ef02 | 2013-04-07 19:01:33 -0700 | [diff] [blame] | 951 | } |
| 952 | } |
| 953 | return resumedActivity; |
| 954 | } |
| 955 | |
Dianne Hackborn | ff07272 | 2014-09-24 10:56:28 -0700 | [diff] [blame] | 956 | boolean attachApplicationLocked(ProcessRecord app) throws RemoteException { |
Craig Mautner | 20e7227 | 2013-04-01 13:45:53 -0700 | [diff] [blame] | 957 | final String processName = app.processName; |
Craig Mautner | 4a1cb22 | 2013-12-04 16:14:06 -0800 | [diff] [blame] | 958 | boolean didSomething = false; |
Craig Mautner | e0a3884 | 2013-12-16 16:14:02 -0800 | [diff] [blame] | 959 | for (int displayNdx = mActivityDisplays.size() - 1; displayNdx >= 0; --displayNdx) { |
| 960 | ArrayList<ActivityStack> stacks = mActivityDisplays.valueAt(displayNdx).mStacks; |
Craig Mautner | 4a1cb22 | 2013-12-04 16:14:06 -0800 | [diff] [blame] | 961 | for (int stackNdx = stacks.size() - 1; stackNdx >= 0; --stackNdx) { |
| 962 | final ActivityStack stack = stacks.get(stackNdx); |
Wale Ogunwale | 1e60e0c | 2015-10-28 13:36:10 -0700 | [diff] [blame] | 963 | if (!isFocusedStack(stack)) { |
Craig Mautner | 4a1cb22 | 2013-12-04 16:14:06 -0800 | [diff] [blame] | 964 | continue; |
| 965 | } |
Filip Gruszczynski | 3e85ba2 | 2015-10-05 22:48:30 -0700 | [diff] [blame] | 966 | ActivityRecord hr = stack.topRunningActivityLocked(); |
Craig Mautner | 4a1cb22 | 2013-12-04 16:14:06 -0800 | [diff] [blame] | 967 | if (hr != null) { |
| 968 | if (hr.app == null && app.uid == hr.info.applicationInfo.uid |
| 969 | && processName.equals(hr.processName)) { |
| 970 | try { |
George Mount | 2c92c97 | 2014-03-20 09:38:23 -0700 | [diff] [blame] | 971 | if (realStartActivityLocked(hr, app, true, true)) { |
Craig Mautner | 4a1cb22 | 2013-12-04 16:14:06 -0800 | [diff] [blame] | 972 | didSomething = true; |
| 973 | } |
Dianne Hackborn | ff07272 | 2014-09-24 10:56:28 -0700 | [diff] [blame] | 974 | } catch (RemoteException e) { |
Craig Mautner | 4a1cb22 | 2013-12-04 16:14:06 -0800 | [diff] [blame] | 975 | Slog.w(TAG, "Exception in new application when starting activity " |
| 976 | + hr.intent.getComponent().flattenToShortString(), e); |
| 977 | throw e; |
Craig Mautner | 20e7227 | 2013-04-01 13:45:53 -0700 | [diff] [blame] | 978 | } |
Craig Mautner | 20e7227 | 2013-04-01 13:45:53 -0700 | [diff] [blame] | 979 | } |
Craig Mautner | 20e7227 | 2013-04-01 13:45:53 -0700 | [diff] [blame] | 980 | } |
| 981 | } |
| 982 | } |
Craig Mautner | b59dcfd | 2013-05-06 13:12:58 -0700 | [diff] [blame] | 983 | if (!didSomething) { |
Filip Gruszczynski | bc5a6c5 | 2015-09-22 13:13:24 -0700 | [diff] [blame] | 984 | ensureActivitiesVisibleLocked(null, 0, !PRESERVE_WINDOWS); |
Craig Mautner | b59dcfd | 2013-05-06 13:12:58 -0700 | [diff] [blame] | 985 | } |
Craig Mautner | 20e7227 | 2013-04-01 13:45:53 -0700 | [diff] [blame] | 986 | return didSomething; |
| 987 | } |
| 988 | |
| 989 | boolean allResumedActivitiesIdle() { |
Craig Mautner | e0a3884 | 2013-12-16 16:14:02 -0800 | [diff] [blame] | 990 | for (int displayNdx = mActivityDisplays.size() - 1; displayNdx >= 0; --displayNdx) { |
| 991 | ArrayList<ActivityStack> stacks = mActivityDisplays.valueAt(displayNdx).mStacks; |
Craig Mautner | 4a1cb22 | 2013-12-04 16:14:06 -0800 | [diff] [blame] | 992 | for (int stackNdx = stacks.size() - 1; stackNdx >= 0; --stackNdx) { |
| 993 | final ActivityStack stack = stacks.get(stackNdx); |
Wale Ogunwale | 1e60e0c | 2015-10-28 13:36:10 -0700 | [diff] [blame] | 994 | if (!isFocusedStack(stack) || stack.numActivities() == 0) { |
Craig Mautner | 4a1cb22 | 2013-12-04 16:14:06 -0800 | [diff] [blame] | 995 | continue; |
| 996 | } |
| 997 | final ActivityRecord resumedActivity = stack.mResumedActivity; |
| 998 | if (resumedActivity == null || !resumedActivity.idle) { |
Wale Ogunwale | 0fc365c | 2015-05-25 19:35:42 -0700 | [diff] [blame] | 999 | if (DEBUG_STATES) Slog.d(TAG_STATES, "allResumedActivitiesIdle: stack=" |
Craig Mautner | 34b73df | 2014-01-12 21:11:08 -0800 | [diff] [blame] | 1000 | + stack.mStackId + " " + resumedActivity + " not idle"); |
Craig Mautner | 4a1cb22 | 2013-12-04 16:14:06 -0800 | [diff] [blame] | 1001 | return false; |
| 1002 | } |
Craig Mautner | 20e7227 | 2013-04-01 13:45:53 -0700 | [diff] [blame] | 1003 | } |
| 1004 | } |
Wei Wang | 65c7a15 | 2016-06-02 18:51:22 -0700 | [diff] [blame] | 1005 | // Send launch end powerhint when idle |
| 1006 | mService.mActivityStarter.sendPowerHintForLaunchEndIfNeeded(); |
Craig Mautner | 20e7227 | 2013-04-01 13:45:53 -0700 | [diff] [blame] | 1007 | return true; |
| 1008 | } |
| 1009 | |
Craig Mautner | de4ef02 | 2013-04-07 19:01:33 -0700 | [diff] [blame] | 1010 | boolean allResumedActivitiesComplete() { |
Craig Mautner | e0a3884 | 2013-12-16 16:14:02 -0800 | [diff] [blame] | 1011 | for (int displayNdx = mActivityDisplays.size() - 1; displayNdx >= 0; --displayNdx) { |
| 1012 | ArrayList<ActivityStack> stacks = mActivityDisplays.valueAt(displayNdx).mStacks; |
Craig Mautner | 4a1cb22 | 2013-12-04 16:14:06 -0800 | [diff] [blame] | 1013 | for (int stackNdx = stacks.size() - 1; stackNdx >= 0; --stackNdx) { |
| 1014 | final ActivityStack stack = stacks.get(stackNdx); |
Wale Ogunwale | 1e60e0c | 2015-10-28 13:36:10 -0700 | [diff] [blame] | 1015 | if (isFocusedStack(stack)) { |
Craig Mautner | 4a1cb22 | 2013-12-04 16:14:06 -0800 | [diff] [blame] | 1016 | final ActivityRecord r = stack.mResumedActivity; |
Wale Ogunwale | ee006da | 2015-03-30 14:49:25 -0700 | [diff] [blame] | 1017 | if (r != null && r.state != RESUMED) { |
Craig Mautner | 4a1cb22 | 2013-12-04 16:14:06 -0800 | [diff] [blame] | 1018 | return false; |
| 1019 | } |
Craig Mautner | de4ef02 | 2013-04-07 19:01:33 -0700 | [diff] [blame] | 1020 | } |
| 1021 | } |
| 1022 | } |
| 1023 | // 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] | 1024 | if (DEBUG_STACK) Slog.d(TAG_STACK, |
Craig Mautner | 4a1cb22 | 2013-12-04 16:14:06 -0800 | [diff] [blame] | 1025 | "allResumedActivitiesComplete: mLastFocusedStack changing from=" + |
| 1026 | mLastFocusedStack + " to=" + mFocusedStack); |
| 1027 | mLastFocusedStack = mFocusedStack; |
Craig Mautner | de4ef02 | 2013-04-07 19:01:33 -0700 | [diff] [blame] | 1028 | return true; |
| 1029 | } |
| 1030 | |
| 1031 | boolean allResumedActivitiesVisible() { |
riddle_hsu | db46d6b | 2015-04-01 18:58:07 +0800 | [diff] [blame] | 1032 | boolean foundResumed = false; |
Craig Mautner | e0a3884 | 2013-12-16 16:14:02 -0800 | [diff] [blame] | 1033 | for (int displayNdx = mActivityDisplays.size() - 1; displayNdx >= 0; --displayNdx) { |
| 1034 | ArrayList<ActivityStack> stacks = mActivityDisplays.valueAt(displayNdx).mStacks; |
Craig Mautner | 4a1cb22 | 2013-12-04 16:14:06 -0800 | [diff] [blame] | 1035 | for (int stackNdx = stacks.size() - 1; stackNdx >= 0; --stackNdx) { |
| 1036 | final ActivityStack stack = stacks.get(stackNdx); |
| 1037 | final ActivityRecord r = stack.mResumedActivity; |
riddle_hsu | db46d6b | 2015-04-01 18:58:07 +0800 | [diff] [blame] | 1038 | if (r != null) { |
Bryce Lee | 4a19438 | 2017-04-04 14:32:48 -0700 | [diff] [blame] | 1039 | if (!r.nowVisible || mActivitiesWaitingForVisibleActivity.contains(r)) { |
riddle_hsu | db46d6b | 2015-04-01 18:58:07 +0800 | [diff] [blame] | 1040 | return false; |
| 1041 | } |
| 1042 | foundResumed = true; |
Craig Mautner | 4a1cb22 | 2013-12-04 16:14:06 -0800 | [diff] [blame] | 1043 | } |
Craig Mautner | de4ef02 | 2013-04-07 19:01:33 -0700 | [diff] [blame] | 1044 | } |
| 1045 | } |
riddle_hsu | db46d6b | 2015-04-01 18:58:07 +0800 | [diff] [blame] | 1046 | return foundResumed; |
Craig Mautner | de4ef02 | 2013-04-07 19:01:33 -0700 | [diff] [blame] | 1047 | } |
| 1048 | |
Craig Mautner | 2acc389 | 2013-09-23 10:28:14 -0700 | [diff] [blame] | 1049 | /** |
| 1050 | * Pause all activities in either all of the stacks or just the back stacks. |
| 1051 | * @param userLeaving Passed to pauseActivity() to indicate whether to call onUserLeaving(). |
Wale Ogunwale | 950faff | 2016-08-08 09:51:04 -0700 | [diff] [blame] | 1052 | * @param resuming The resuming activity. |
| 1053 | * @param dontWait The resuming activity isn't going to wait for all activities to be paused |
| 1054 | * before resuming. |
Craig Mautner | 2acc389 | 2013-09-23 10:28:14 -0700 | [diff] [blame] | 1055 | * @return true if any activity was paused as a result of this call. |
| 1056 | */ |
Wale Ogunwale | 950faff | 2016-08-08 09:51:04 -0700 | [diff] [blame] | 1057 | boolean pauseBackStacks(boolean userLeaving, ActivityRecord resuming, boolean dontWait) { |
Craig Mautner | cf910b0 | 2013-04-23 11:23:27 -0700 | [diff] [blame] | 1058 | boolean someActivityPaused = false; |
Craig Mautner | e0a3884 | 2013-12-16 16:14:02 -0800 | [diff] [blame] | 1059 | for (int displayNdx = mActivityDisplays.size() - 1; displayNdx >= 0; --displayNdx) { |
| 1060 | ArrayList<ActivityStack> stacks = mActivityDisplays.valueAt(displayNdx).mStacks; |
Craig Mautner | 4a1cb22 | 2013-12-04 16:14:06 -0800 | [diff] [blame] | 1061 | for (int stackNdx = stacks.size() - 1; stackNdx >= 0; --stackNdx) { |
| 1062 | final ActivityStack stack = stacks.get(stackNdx); |
Wale Ogunwale | 1e60e0c | 2015-10-28 13:36:10 -0700 | [diff] [blame] | 1063 | if (!isFocusedStack(stack) && stack.mResumedActivity != null) { |
Wale Ogunwale | 0fc365c | 2015-05-25 19:35:42 -0700 | [diff] [blame] | 1064 | if (DEBUG_STATES) Slog.d(TAG_STATES, "pauseBackStacks: stack=" + stack + |
Craig Mautner | 4a1cb22 | 2013-12-04 16:14:06 -0800 | [diff] [blame] | 1065 | " mResumedActivity=" + stack.mResumedActivity); |
Dianne Hackborn | a4e102e | 2014-09-04 22:52:27 -0700 | [diff] [blame] | 1066 | someActivityPaused |= stack.startPausingLocked(userLeaving, false, resuming, |
| 1067 | dontWait); |
Craig Mautner | 4a1cb22 | 2013-12-04 16:14:06 -0800 | [diff] [blame] | 1068 | } |
Craig Mautner | cf910b0 | 2013-04-23 11:23:27 -0700 | [diff] [blame] | 1069 | } |
| 1070 | } |
| 1071 | return someActivityPaused; |
| 1072 | } |
| 1073 | |
Craig Mautner | de4ef02 | 2013-04-07 19:01:33 -0700 | [diff] [blame] | 1074 | boolean allPausedActivitiesComplete() { |
Craig Mautner | ac6f843 | 2013-07-17 13:24:59 -0700 | [diff] [blame] | 1075 | boolean pausing = true; |
Craig Mautner | e0a3884 | 2013-12-16 16:14:02 -0800 | [diff] [blame] | 1076 | for (int displayNdx = mActivityDisplays.size() - 1; displayNdx >= 0; --displayNdx) { |
| 1077 | ArrayList<ActivityStack> stacks = mActivityDisplays.valueAt(displayNdx).mStacks; |
Craig Mautner | 4a1cb22 | 2013-12-04 16:14:06 -0800 | [diff] [blame] | 1078 | for (int stackNdx = stacks.size() - 1; stackNdx >= 0; --stackNdx) { |
| 1079 | final ActivityStack stack = stacks.get(stackNdx); |
| 1080 | final ActivityRecord r = stack.mPausingActivity; |
Wale Ogunwale | ee006da | 2015-03-30 14:49:25 -0700 | [diff] [blame] | 1081 | if (r != null && r.state != PAUSED && r.state != STOPPED && r.state != STOPPING) { |
Craig Mautner | 4a1cb22 | 2013-12-04 16:14:06 -0800 | [diff] [blame] | 1082 | if (DEBUG_STATES) { |
Wale Ogunwale | 0fc365c | 2015-05-25 19:35:42 -0700 | [diff] [blame] | 1083 | Slog.d(TAG_STATES, |
| 1084 | "allPausedActivitiesComplete: r=" + r + " state=" + r.state); |
Craig Mautner | 4a1cb22 | 2013-12-04 16:14:06 -0800 | [diff] [blame] | 1085 | pausing = false; |
| 1086 | } else { |
| 1087 | return false; |
| 1088 | } |
Craig Mautner | ac6f843 | 2013-07-17 13:24:59 -0700 | [diff] [blame] | 1089 | } |
Craig Mautner | de4ef02 | 2013-04-07 19:01:33 -0700 | [diff] [blame] | 1090 | } |
| 1091 | } |
Craig Mautner | ac6f843 | 2013-07-17 13:24:59 -0700 | [diff] [blame] | 1092 | return pausing; |
Craig Mautner | de4ef02 | 2013-04-07 19:01:33 -0700 | [diff] [blame] | 1093 | } |
| 1094 | |
Dianne Hackborn | a4e102e | 2014-09-04 22:52:27 -0700 | [diff] [blame] | 1095 | void pauseChildStacks(ActivityRecord parent, boolean userLeaving, boolean uiSleeping, |
Wale Ogunwale | 950faff | 2016-08-08 09:51:04 -0700 | [diff] [blame] | 1096 | ActivityRecord resuming, boolean dontWait) { |
John Spurlock | 8a985d2 | 2014-02-25 09:40:05 -0500 | [diff] [blame] | 1097 | // TODO: Put all stacks in supervisor and iterate through them instead. |
Craig Mautner | df88d73 | 2014-01-27 09:21:32 -0800 | [diff] [blame] | 1098 | for (int displayNdx = mActivityDisplays.size() - 1; displayNdx >= 0; --displayNdx) { |
| 1099 | ArrayList<ActivityStack> stacks = mActivityDisplays.valueAt(displayNdx).mStacks; |
| 1100 | for (int stackNdx = stacks.size() - 1; stackNdx >= 0; --stackNdx) { |
| 1101 | final ActivityStack stack = stacks.get(stackNdx); |
| 1102 | if (stack.mResumedActivity != null && |
| 1103 | stack.mActivityContainer.mParentActivity == parent) { |
Dianne Hackborn | a4e102e | 2014-09-04 22:52:27 -0700 | [diff] [blame] | 1104 | stack.startPausingLocked(userLeaving, uiSleeping, resuming, dontWait); |
Craig Mautner | df88d73 | 2014-01-27 09:21:32 -0800 | [diff] [blame] | 1105 | } |
| 1106 | } |
| 1107 | } |
| 1108 | } |
| 1109 | |
Wale Ogunwale | 2be760d | 2016-02-17 11:16:10 -0800 | [diff] [blame] | 1110 | void cancelInitializingActivities() { |
| 1111 | for (int displayNdx = mActivityDisplays.size() - 1; displayNdx >= 0; --displayNdx) { |
| 1112 | ArrayList<ActivityStack> stacks = mActivityDisplays.valueAt(displayNdx).mStacks; |
| 1113 | for (int stackNdx = stacks.size() - 1; stackNdx >= 0; --stackNdx) { |
| 1114 | stacks.get(stackNdx).cancelInitializingActivities(); |
| 1115 | } |
| 1116 | } |
| 1117 | } |
| 1118 | |
Bryce Lee | 4a19438 | 2017-04-04 14:32:48 -0700 | [diff] [blame] | 1119 | void waitActivityVisible(ComponentName name, WaitResult result) { |
| 1120 | final WaitInfo waitInfo = new WaitInfo(name, result); |
| 1121 | mWaitingForActivityVisible.add(waitInfo); |
| 1122 | } |
| 1123 | |
| 1124 | void cleanupActivity(ActivityRecord r) { |
| 1125 | // Make sure this record is no longer in the pending finishes list. |
| 1126 | // This could happen, for example, if we are trimming activities |
| 1127 | // down to the max limit while they are still waiting to finish. |
| 1128 | mFinishingActivities.remove(r); |
| 1129 | mActivitiesWaitingForVisibleActivity.remove(r); |
| 1130 | |
| 1131 | for (int i = mWaitingForActivityVisible.size() - 1; i >= 0; --i) { |
Wale Ogunwale | 3270f17 | 2017-04-26 07:29:42 -0700 | [diff] [blame] | 1132 | if (mWaitingForActivityVisible.get(i).matches(r.realActivity)) { |
Bryce Lee | 4a19438 | 2017-04-04 14:32:48 -0700 | [diff] [blame] | 1133 | mWaitingForActivityVisible.remove(i); |
| 1134 | } |
| 1135 | } |
| 1136 | } |
| 1137 | |
Craig Mautner | ce5f3cb | 2013-04-22 08:58:54 -0700 | [diff] [blame] | 1138 | void reportActivityVisibleLocked(ActivityRecord r) { |
Dianne Hackborn | 6cfbb71 | 2014-09-17 12:47:35 -0700 | [diff] [blame] | 1139 | sendWaitingVisibleReportLocked(r); |
Dianne Hackborn | 6cfbb71 | 2014-09-17 12:47:35 -0700 | [diff] [blame] | 1140 | } |
| 1141 | |
| 1142 | void sendWaitingVisibleReportLocked(ActivityRecord r) { |
| 1143 | boolean changed = false; |
Bryce Lee | 4a19438 | 2017-04-04 14:32:48 -0700 | [diff] [blame] | 1144 | for (int i = mWaitingForActivityVisible.size() - 1; i >= 0; --i) { |
| 1145 | final WaitInfo w = mWaitingForActivityVisible.get(i); |
Wale Ogunwale | 3270f17 | 2017-04-26 07:29:42 -0700 | [diff] [blame] | 1146 | if (w.matches(r.realActivity)) { |
Bryce Lee | 4a19438 | 2017-04-04 14:32:48 -0700 | [diff] [blame] | 1147 | final WaitResult result = w.getResult(); |
Dianne Hackborn | 6cfbb71 | 2014-09-17 12:47:35 -0700 | [diff] [blame] | 1148 | changed = true; |
Bryce Lee | 4a19438 | 2017-04-04 14:32:48 -0700 | [diff] [blame] | 1149 | result.timeout = false; |
| 1150 | result.who = w.getComponent(); |
| 1151 | result.totalTime = SystemClock.uptimeMillis() - result.thisTime; |
| 1152 | result.thisTime = result.totalTime; |
| 1153 | mWaitingForActivityVisible.remove(w); |
Craig Mautner | ce5f3cb | 2013-04-22 08:58:54 -0700 | [diff] [blame] | 1154 | } |
Craig Mautner | ce5f3cb | 2013-04-22 08:58:54 -0700 | [diff] [blame] | 1155 | } |
Dianne Hackborn | 6cfbb71 | 2014-09-17 12:47:35 -0700 | [diff] [blame] | 1156 | if (changed) { |
| 1157 | mService.notifyAll(); |
| 1158 | } |
Craig Mautner | ce5f3cb | 2013-04-22 08:58:54 -0700 | [diff] [blame] | 1159 | } |
| 1160 | |
Chong Zhang | 5022da3 | 2016-06-21 16:31:37 -0700 | [diff] [blame] | 1161 | void reportTaskToFrontNoLaunch(ActivityRecord r) { |
| 1162 | boolean changed = false; |
| 1163 | for (int i = mWaitingActivityLaunched.size() - 1; i >= 0; i--) { |
| 1164 | WaitResult w = mWaitingActivityLaunched.remove(i); |
| 1165 | if (w.who == null) { |
| 1166 | changed = true; |
| 1167 | // Set result to START_TASK_TO_FRONT so that startActivityMayWait() knows that |
| 1168 | // the starting activity ends up moving another activity to front, and it should |
| 1169 | // wait for this new activity to become visible instead. |
| 1170 | // Do not modify other fields. |
| 1171 | w.result = START_TASK_TO_FRONT; |
| 1172 | } |
| 1173 | } |
| 1174 | if (changed) { |
| 1175 | mService.notifyAll(); |
| 1176 | } |
| 1177 | } |
| 1178 | |
Craig Mautner | ce5f3cb | 2013-04-22 08:58:54 -0700 | [diff] [blame] | 1179 | void reportActivityLaunchedLocked(boolean timeout, ActivityRecord r, |
| 1180 | long thisTime, long totalTime) { |
Dianne Hackborn | 6cfbb71 | 2014-09-17 12:47:35 -0700 | [diff] [blame] | 1181 | boolean changed = false; |
Craig Mautner | ce5f3cb | 2013-04-22 08:58:54 -0700 | [diff] [blame] | 1182 | for (int i = mWaitingActivityLaunched.size() - 1; i >= 0; i--) { |
Craig Mautner | c64f73e | 2013-04-24 16:44:56 -0700 | [diff] [blame] | 1183 | WaitResult w = mWaitingActivityLaunched.remove(i); |
Dianne Hackborn | 6cfbb71 | 2014-09-17 12:47:35 -0700 | [diff] [blame] | 1184 | if (w.who == null) { |
| 1185 | changed = true; |
| 1186 | w.timeout = timeout; |
| 1187 | if (r != null) { |
| 1188 | w.who = new ComponentName(r.info.packageName, r.info.name); |
| 1189 | } |
| 1190 | w.thisTime = thisTime; |
| 1191 | w.totalTime = totalTime; |
Chong Zhang | 5022da3 | 2016-06-21 16:31:37 -0700 | [diff] [blame] | 1192 | // Do not modify w.result. |
Craig Mautner | ce5f3cb | 2013-04-22 08:58:54 -0700 | [diff] [blame] | 1193 | } |
Craig Mautner | ce5f3cb | 2013-04-22 08:58:54 -0700 | [diff] [blame] | 1194 | } |
Dianne Hackborn | 6cfbb71 | 2014-09-17 12:47:35 -0700 | [diff] [blame] | 1195 | if (changed) { |
| 1196 | mService.notifyAll(); |
| 1197 | } |
Craig Mautner | ce5f3cb | 2013-04-22 08:58:54 -0700 | [diff] [blame] | 1198 | } |
| 1199 | |
Craig Mautner | 29219d9 | 2013-04-16 20:19:12 -0700 | [diff] [blame] | 1200 | ActivityRecord topRunningActivityLocked() { |
Wale Ogunwale | d697cea | 2015-02-20 17:19:49 -0800 | [diff] [blame] | 1201 | final ActivityStack focusedStack = mFocusedStack; |
Filip Gruszczynski | 3e85ba2 | 2015-10-05 22:48:30 -0700 | [diff] [blame] | 1202 | ActivityRecord r = focusedStack.topRunningActivityLocked(); |
Craig Mautner | 1602ec2 | 2013-05-12 10:24:27 -0700 | [diff] [blame] | 1203 | if (r != null) { |
| 1204 | return r; |
Craig Mautner | 29219d9 | 2013-04-16 20:19:12 -0700 | [diff] [blame] | 1205 | } |
Craig Mautner | 1602ec2 | 2013-05-12 10:24:27 -0700 | [diff] [blame] | 1206 | |
Andrii Kulian | 7318d63 | 2016-07-20 18:59:28 -0700 | [diff] [blame] | 1207 | // Look in other non-focused and non-home stacks. |
Andrii Kulian | 7d95df4 | 2017-02-15 10:11:48 -0800 | [diff] [blame] | 1208 | mWindowManager.getDisplaysInFocusOrder(mTmpOrderedDisplayIds); |
| 1209 | |
| 1210 | for (int i = mTmpOrderedDisplayIds.size() - 1; i >= 0; --i) { |
| 1211 | final int displayId = mTmpOrderedDisplayIds.get(i); |
| 1212 | final List<ActivityStack> stacks = mActivityDisplays.get(displayId).mStacks; |
| 1213 | if (stacks == null) { |
| 1214 | continue; |
| 1215 | } |
| 1216 | for (int j = stacks.size() - 1; j >= 0; --j) { |
| 1217 | final ActivityStack stack = stacks.get(j); |
| 1218 | if (stack != focusedStack && isFrontStackOnDisplay(stack) && stack.isFocusable()) { |
| 1219 | r = stack.topRunningActivityLocked(); |
| 1220 | if (r != null) { |
| 1221 | return r; |
| 1222 | } |
Craig Mautner | 29219d9 | 2013-04-16 20:19:12 -0700 | [diff] [blame] | 1223 | } |
| 1224 | } |
| 1225 | } |
| 1226 | return null; |
| 1227 | } |
| 1228 | |
Dianne Hackborn | 0923328 | 2014-04-30 11:33:59 -0700 | [diff] [blame] | 1229 | void getTasksLocked(int maxNum, List<RunningTaskInfo> list, int callingUid, boolean allowed) { |
Craig Mautner | c0fd805 | 2013-09-19 11:20:17 -0700 | [diff] [blame] | 1230 | // Gather all of the running tasks for each stack into runningTaskLists. |
Craig Mautner | 4a1cb22 | 2013-12-04 16:14:06 -0800 | [diff] [blame] | 1231 | ArrayList<ArrayList<RunningTaskInfo>> runningTaskLists = |
| 1232 | new ArrayList<ArrayList<RunningTaskInfo>>(); |
Craig Mautner | e0a3884 | 2013-12-16 16:14:02 -0800 | [diff] [blame] | 1233 | final int numDisplays = mActivityDisplays.size(); |
Craig Mautner | 4a1cb22 | 2013-12-04 16:14:06 -0800 | [diff] [blame] | 1234 | for (int displayNdx = 0; displayNdx < numDisplays; ++displayNdx) { |
Craig Mautner | e0a3884 | 2013-12-16 16:14:02 -0800 | [diff] [blame] | 1235 | ArrayList<ActivityStack> stacks = mActivityDisplays.valueAt(displayNdx).mStacks; |
Craig Mautner | 4a1cb22 | 2013-12-04 16:14:06 -0800 | [diff] [blame] | 1236 | for (int stackNdx = stacks.size() - 1; stackNdx >= 0; --stackNdx) { |
| 1237 | final ActivityStack stack = stacks.get(stackNdx); |
Craig Mautner | 15df08a | 2015-04-01 12:17:18 -0700 | [diff] [blame] | 1238 | ArrayList<RunningTaskInfo> stackTaskList = new ArrayList<>(); |
Craig Mautner | 4a1cb22 | 2013-12-04 16:14:06 -0800 | [diff] [blame] | 1239 | runningTaskLists.add(stackTaskList); |
Dianne Hackborn | 0923328 | 2014-04-30 11:33:59 -0700 | [diff] [blame] | 1240 | stack.getTasksLocked(stackTaskList, callingUid, allowed); |
Craig Mautner | 20e7227 | 2013-04-01 13:45:53 -0700 | [diff] [blame] | 1241 | } |
| 1242 | } |
Craig Mautner | c0fd805 | 2013-09-19 11:20:17 -0700 | [diff] [blame] | 1243 | |
| 1244 | // The lists are already sorted from most recent to oldest. Just pull the most recent off |
| 1245 | // each list and add it to list. Stop when all lists are empty or maxNum reached. |
| 1246 | while (maxNum > 0) { |
| 1247 | long mostRecentActiveTime = Long.MIN_VALUE; |
| 1248 | ArrayList<RunningTaskInfo> selectedStackList = null; |
Craig Mautner | 4a1cb22 | 2013-12-04 16:14:06 -0800 | [diff] [blame] | 1249 | final int numTaskLists = runningTaskLists.size(); |
| 1250 | for (int stackNdx = 0; stackNdx < numTaskLists; ++stackNdx) { |
| 1251 | ArrayList<RunningTaskInfo> stackTaskList = runningTaskLists.get(stackNdx); |
Craig Mautner | c0fd805 | 2013-09-19 11:20:17 -0700 | [diff] [blame] | 1252 | if (!stackTaskList.isEmpty()) { |
| 1253 | final long lastActiveTime = stackTaskList.get(0).lastActiveTime; |
| 1254 | if (lastActiveTime > mostRecentActiveTime) { |
| 1255 | mostRecentActiveTime = lastActiveTime; |
| 1256 | selectedStackList = stackTaskList; |
| 1257 | } |
| 1258 | } |
| 1259 | } |
| 1260 | if (selectedStackList != null) { |
| 1261 | list.add(selectedStackList.remove(0)); |
| 1262 | --maxNum; |
| 1263 | } else { |
| 1264 | break; |
| 1265 | } |
| 1266 | } |
Craig Mautner | 20e7227 | 2013-04-01 13:45:53 -0700 | [diff] [blame] | 1267 | } |
| 1268 | |
Todd Kennedy | 7440f17 | 2015-12-09 14:31:22 -0800 | [diff] [blame] | 1269 | ActivityInfo resolveActivity(Intent intent, ResolveInfo rInfo, int startFlags, |
| 1270 | ProfilerInfo profilerInfo) { |
| 1271 | final ActivityInfo aInfo = rInfo != null ? rInfo.activityInfo : null; |
Craig Mautner | 23ac33b | 2013-04-01 16:26:35 -0700 | [diff] [blame] | 1272 | if (aInfo != null) { |
| 1273 | // Store the found target back into the intent, because now that |
| 1274 | // we have it we never want to do this again. For example, if the |
| 1275 | // user navigates back to this point in the history, we should |
| 1276 | // always restart the exact same activity. |
| 1277 | intent.setComponent(new ComponentName( |
| 1278 | aInfo.applicationInfo.packageName, aInfo.name)); |
| 1279 | |
| 1280 | // Don't debug things in the system process |
Man Cao | cfa78b2 | 2015-06-11 20:14:34 -0700 | [diff] [blame] | 1281 | if (!aInfo.processName.equals("system")) { |
| 1282 | if ((startFlags & ActivityManager.START_FLAG_DEBUG) != 0) { |
Chong Zhang | d25944e | 2016-06-09 16:15:27 -0700 | [diff] [blame] | 1283 | mService.setDebugApp(aInfo.processName, true, false); |
Craig Mautner | 23ac33b | 2013-04-01 16:26:35 -0700 | [diff] [blame] | 1284 | } |
Craig Mautner | 23ac33b | 2013-04-01 16:26:35 -0700 | [diff] [blame] | 1285 | |
Tamas Berghammer | df6cb28 | 2016-01-29 12:07:00 +0000 | [diff] [blame] | 1286 | if ((startFlags & ActivityManager.START_FLAG_NATIVE_DEBUGGING) != 0) { |
| 1287 | mService.setNativeDebuggingAppLocked(aInfo.applicationInfo, aInfo.processName); |
| 1288 | } |
| 1289 | |
Man Cao | cfa78b2 | 2015-06-11 20:14:34 -0700 | [diff] [blame] | 1290 | if ((startFlags & ActivityManager.START_FLAG_TRACK_ALLOCATION) != 0) { |
| 1291 | mService.setTrackAllocationApp(aInfo.applicationInfo, aInfo.processName); |
| 1292 | } |
| 1293 | |
| 1294 | if (profilerInfo != null) { |
Jeff Hao | 1b012d3 | 2014-08-20 10:35:34 -0700 | [diff] [blame] | 1295 | mService.setProfileApp(aInfo.applicationInfo, aInfo.processName, profilerInfo); |
Craig Mautner | 23ac33b | 2013-04-01 16:26:35 -0700 | [diff] [blame] | 1296 | } |
| 1297 | } |
Todd Kennedy | b3b43130 | 2017-03-20 16:05:48 -0700 | [diff] [blame] | 1298 | final String intentLaunchToken = intent.getLaunchToken(); |
| 1299 | if (aInfo.launchToken == null && intentLaunchToken != null) { |
| 1300 | aInfo.launchToken = intentLaunchToken; |
| 1301 | } |
Craig Mautner | 23ac33b | 2013-04-01 16:26:35 -0700 | [diff] [blame] | 1302 | } |
| 1303 | return aInfo; |
| 1304 | } |
| 1305 | |
Todd Kennedy | 7440f17 | 2015-12-09 14:31:22 -0800 | [diff] [blame] | 1306 | ResolveInfo resolveIntent(Intent intent, String resolvedType, int userId) { |
Kenny Guy | b1b3026 | 2016-02-09 16:02:35 +0000 | [diff] [blame] | 1307 | return resolveIntent(intent, resolvedType, userId, 0); |
| 1308 | } |
| 1309 | |
| 1310 | ResolveInfo resolveIntent(Intent intent, String resolvedType, int userId, int flags) { |
Todd Kennedy | 4d1de7d | 2017-02-23 10:32:18 -0800 | [diff] [blame] | 1311 | synchronized (mService) { |
| 1312 | return mService.getPackageManagerInternalLocked().resolveIntent(intent, resolvedType, |
Todd Kennedy | be0b889 | 2017-02-15 14:13:52 -0800 | [diff] [blame] | 1313 | PackageManager.MATCH_INSTANT | PackageManager.MATCH_DEFAULT_ONLY | flags |
Kenny Guy | b1b3026 | 2016-02-09 16:02:35 +0000 | [diff] [blame] | 1314 | | ActivityManagerService.STOCK_PM_FLAGS, userId); |
Todd Kennedy | 7440f17 | 2015-12-09 14:31:22 -0800 | [diff] [blame] | 1315 | } |
Todd Kennedy | 7440f17 | 2015-12-09 14:31:22 -0800 | [diff] [blame] | 1316 | } |
| 1317 | |
| 1318 | ActivityInfo resolveActivity(Intent intent, String resolvedType, int startFlags, |
| 1319 | ProfilerInfo profilerInfo, int userId) { |
| 1320 | final ResolveInfo rInfo = resolveIntent(intent, resolvedType, userId); |
| 1321 | return resolveActivity(intent, rInfo, startFlags, profilerInfo); |
| 1322 | } |
| 1323 | |
Wale Ogunwale | 5658e4b | 2016-02-12 12:22:19 -0800 | [diff] [blame] | 1324 | final boolean realStartActivityLocked(ActivityRecord r, ProcessRecord app, |
| 1325 | boolean andResume, boolean checkConfig) throws RemoteException { |
| 1326 | |
| 1327 | if (!allPausedActivitiesComplete()) { |
| 1328 | // While there are activities pausing we skipping starting any new activities until |
| 1329 | // pauses are complete. NOTE: that we also do this for activities that are starting in |
| 1330 | // the paused state because they will first be resumed then paused on the client side. |
| 1331 | if (DEBUG_SWITCH || DEBUG_PAUSE || DEBUG_STATES) Slog.v(TAG_PAUSE, |
| 1332 | "realStartActivityLocked: Skipping start of r=" + r |
| 1333 | + " some activities pausing..."); |
| 1334 | return false; |
| 1335 | } |
Craig Mautner | 2420ead | 2013-04-01 17:13:20 -0700 | [diff] [blame] | 1336 | |
Andrii Kulian | ada1029 | 2017-02-09 23:19:29 -0800 | [diff] [blame] | 1337 | r.startFreezingScreenLocked(app, 0); |
Wale Ogunwale | d334a05 | 2017-05-12 07:17:36 -0700 | [diff] [blame] | 1338 | if (r.getStack().checkKeyguardVisibility(r, true /* shouldBeVisible */, true /* isTop */)) { |
| 1339 | // We only set the visibility to true if the activity is allowed to be visible based on |
| 1340 | // keyguard state. This avoids setting this into motion in window manager that is later |
| 1341 | // cancelled due to later calls to ensure visible activities that set visibility back to |
| 1342 | // false. |
| 1343 | r.setVisibility(true); |
| 1344 | } |
Craig Mautner | 2420ead | 2013-04-01 17:13:20 -0700 | [diff] [blame] | 1345 | |
Andrii Kulian | ada1029 | 2017-02-09 23:19:29 -0800 | [diff] [blame] | 1346 | // schedule launch ticks to collect information about slow apps. |
| 1347 | r.startLaunchTickingLocked(); |
Craig Mautner | 2420ead | 2013-04-01 17:13:20 -0700 | [diff] [blame] | 1348 | |
Andrii Kulian | 5406e7a | 2016-10-21 11:55:23 -0700 | [diff] [blame] | 1349 | // Have the window manager re-evaluate the orientation of the screen based on the new |
| 1350 | // activity order. Note that as a result of this, it can call back into the activity |
| 1351 | // manager with a new orientation. We don't care about that, because the activity is not |
| 1352 | // currently running so we are just restarting it anyway. |
Craig Mautner | 2420ead | 2013-04-01 17:13:20 -0700 | [diff] [blame] | 1353 | if (checkConfig) { |
Andrii Kulian | 5406e7a | 2016-10-21 11:55:23 -0700 | [diff] [blame] | 1354 | final int displayId = r.getDisplayId(); |
| 1355 | final Configuration config = mWindowManager.updateOrientationFromAppTokens( |
| 1356 | getDisplayOverrideConfiguration(displayId), |
| 1357 | r.mayFreezeScreenLocked(app) ? r.appToken : null, displayId); |
Andrii Kulian | db3e4ec | 2016-07-12 17:11:35 -0700 | [diff] [blame] | 1358 | // Deferring resume here because we're going to launch new activity shortly. |
| 1359 | // We don't want to perform a redundant launch of the same record while ensuring |
| 1360 | // configurations and trying to resume top activity of focused stack. |
Andrii Kulian | 5406e7a | 2016-10-21 11:55:23 -0700 | [diff] [blame] | 1361 | mService.updateDisplayOverrideConfigurationLocked(config, r, true /* deferResume */, |
| 1362 | displayId); |
Craig Mautner | 2420ead | 2013-04-01 17:13:20 -0700 | [diff] [blame] | 1363 | } |
| 1364 | |
Jorim Jaggi | 5a108c2 | 2016-10-13 14:33:27 +0200 | [diff] [blame] | 1365 | if (mKeyguardController.isKeyguardLocked()) { |
Wale Ogunwale | 26c0dfe | 2016-12-14 14:42:30 -0800 | [diff] [blame] | 1366 | r.notifyUnknownVisibilityLaunched(); |
Jorim Jaggi | 5a108c2 | 2016-10-13 14:33:27 +0200 | [diff] [blame] | 1367 | } |
Makoto Onuki | 7a62278 | 2017-05-10 16:32:39 -0700 | [diff] [blame] | 1368 | final int applicationInfoUid = |
| 1369 | (r.info.applicationInfo != null) ? r.info.applicationInfo.uid : -1; |
| 1370 | if ((r.userId != app.userId) || (r.appInfo.uid != applicationInfoUid)) { |
| 1371 | Slog.wtf(TAG, |
| 1372 | "User ID for activity changing for " + r |
| 1373 | + " appInfo.uid=" + r.appInfo.uid |
| 1374 | + " info.ai.uid=" + applicationInfoUid |
| 1375 | + " old=" + r.app + " new=" + app); |
| 1376 | } |
Jorim Jaggi | 5a108c2 | 2016-10-13 14:33:27 +0200 | [diff] [blame] | 1377 | |
Craig Mautner | 2420ead | 2013-04-01 17:13:20 -0700 | [diff] [blame] | 1378 | r.app = app; |
| 1379 | app.waitingToKill = null; |
| 1380 | r.launchCount++; |
| 1381 | r.lastLaunchTime = SystemClock.uptimeMillis(); |
| 1382 | |
Wale Ogunwale | e23149f | 2015-03-06 15:39:44 -0800 | [diff] [blame] | 1383 | if (DEBUG_ALL) Slog.v(TAG, "Launching: " + r); |
Craig Mautner | 2420ead | 2013-04-01 17:13:20 -0700 | [diff] [blame] | 1384 | |
| 1385 | int idx = app.activities.indexOf(r); |
| 1386 | if (idx < 0) { |
| 1387 | app.activities.add(r); |
| 1388 | } |
Dianne Hackborn | db92608 | 2013-10-31 16:32:44 -0700 | [diff] [blame] | 1389 | mService.updateLruProcessLocked(app, true, null); |
| 1390 | mService.updateOomAdjLocked(); |
Craig Mautner | 2420ead | 2013-04-01 17:13:20 -0700 | [diff] [blame] | 1391 | |
Bryce Lee | af691c0 | 2017-03-20 14:20:22 -0700 | [diff] [blame] | 1392 | final TaskRecord task = r.getTask(); |
Benjamin Franz | 469dd58 | 2015-06-09 14:24:36 +0100 | [diff] [blame] | 1393 | if (task.mLockTaskAuth == LOCK_TASK_AUTH_LAUNCHABLE || |
| 1394 | task.mLockTaskAuth == LOCK_TASK_AUTH_LAUNCHABLE_PRIV) { |
Craig Mautner | 432f64e | 2015-05-20 14:59:57 -0700 | [diff] [blame] | 1395 | setLockTaskModeLocked(task, LOCK_TASK_MODE_LOCKED, "mLockTaskAuth==LAUNCHABLE", false); |
Craig Mautner | 15df08a | 2015-04-01 12:17:18 -0700 | [diff] [blame] | 1396 | } |
| 1397 | |
Andrii Kulian | 02b7a83 | 2016-10-06 23:11:56 -0700 | [diff] [blame] | 1398 | final ActivityStack stack = task.getStack(); |
Craig Mautner | 2420ead | 2013-04-01 17:13:20 -0700 | [diff] [blame] | 1399 | try { |
| 1400 | if (app.thread == null) { |
| 1401 | throw new RemoteException(); |
| 1402 | } |
| 1403 | List<ResultInfo> results = null; |
Dianne Hackborn | 85d558c | 2014-11-04 10:31:54 -0800 | [diff] [blame] | 1404 | List<ReferrerIntent> newIntents = null; |
Craig Mautner | 2420ead | 2013-04-01 17:13:20 -0700 | [diff] [blame] | 1405 | if (andResume) { |
Andrii Kulian | ada1029 | 2017-02-09 23:19:29 -0800 | [diff] [blame] | 1406 | // We don't need to deliver new intents and/or set results if activity is going |
| 1407 | // to pause immediately after launch. |
Craig Mautner | 2420ead | 2013-04-01 17:13:20 -0700 | [diff] [blame] | 1408 | results = r.results; |
| 1409 | newIntents = r.newIntents; |
| 1410 | } |
Wale Ogunwale | ee006da | 2015-03-30 14:49:25 -0700 | [diff] [blame] | 1411 | if (DEBUG_SWITCH) Slog.v(TAG_SWITCH, |
| 1412 | "Launching: " + r + " icicle=" + r.icicle + " with results=" + results |
| 1413 | + " newIntents=" + newIntents + " andResume=" + andResume); |
Andrii Kulian | ada1029 | 2017-02-09 23:19:29 -0800 | [diff] [blame] | 1414 | EventLog.writeEvent(EventLogTags.AM_RESTART_ACTIVITY, r.userId, |
| 1415 | System.identityHashCode(r), task.taskId, r.shortComponentName); |
Chong Zhang | 85ee654 | 2015-10-02 13:36:38 -0700 | [diff] [blame] | 1416 | if (r.isHomeActivity()) { |
Craig Mautner | 4ef2693 | 2013-09-18 15:15:52 -0700 | [diff] [blame] | 1417 | // Home process is the root process of the task. |
Craig Mautner | 15df08a | 2015-04-01 12:17:18 -0700 | [diff] [blame] | 1418 | mService.mHomeProcess = task.mActivities.get(0).app; |
Craig Mautner | 2420ead | 2013-04-01 17:13:20 -0700 | [diff] [blame] | 1419 | } |
Brian Carlstrom | ca82e61 | 2016-04-19 23:16:08 -0700 | [diff] [blame] | 1420 | mService.notifyPackageUse(r.intent.getComponent().getPackageName(), |
| 1421 | PackageManager.NOTIFY_PACKAGE_USE_ACTIVITY); |
Craig Mautner | 2420ead | 2013-04-01 17:13:20 -0700 | [diff] [blame] | 1422 | r.sleeping = false; |
| 1423 | r.forceNewConfig = false; |
Alan Viverette | 7df9b45 | 2016-06-16 12:47:58 -0400 | [diff] [blame] | 1424 | mService.showUnsupportedZoomDialogIfNeededLocked(r); |
Craig Mautner | 2420ead | 2013-04-01 17:13:20 -0700 | [diff] [blame] | 1425 | mService.showAskCompatModeDialogLocked(r); |
| 1426 | r.compat = mService.compatibilityInfoForPackageLocked(r.info.applicationInfo); |
Craig Mautner | 2568c3a | 2015-03-26 14:22:34 -0700 | [diff] [blame] | 1427 | ProfilerInfo profilerInfo = null; |
Craig Mautner | 2420ead | 2013-04-01 17:13:20 -0700 | [diff] [blame] | 1428 | if (mService.mProfileApp != null && mService.mProfileApp.equals(app.processName)) { |
| 1429 | if (mService.mProfileProc == null || mService.mProfileProc == app) { |
| 1430 | mService.mProfileProc = app; |
Craig Mautner | 2568c3a | 2015-03-26 14:22:34 -0700 | [diff] [blame] | 1431 | final String profileFile = mService.mProfileFile; |
| 1432 | if (profileFile != null) { |
| 1433 | ParcelFileDescriptor profileFd = mService.mProfileFd; |
| 1434 | if (profileFd != null) { |
| 1435 | try { |
| 1436 | profileFd = profileFd.dup(); |
| 1437 | } catch (IOException e) { |
| 1438 | if (profileFd != null) { |
| 1439 | try { |
| 1440 | profileFd.close(); |
| 1441 | } catch (IOException o) { |
| 1442 | } |
| 1443 | profileFd = null; |
| 1444 | } |
| 1445 | } |
Craig Mautner | 2420ead | 2013-04-01 17:13:20 -0700 | [diff] [blame] | 1446 | } |
Craig Mautner | 2568c3a | 2015-03-26 14:22:34 -0700 | [diff] [blame] | 1447 | |
| 1448 | profilerInfo = new ProfilerInfo(profileFile, profileFd, |
Shukang Zhou | 6ffd4f9 | 2017-01-25 16:07:57 -0800 | [diff] [blame] | 1449 | mService.mSamplingInterval, mService.mAutoStopProfiler, |
| 1450 | mService.mStreamingOutput); |
Craig Mautner | 2420ead | 2013-04-01 17:13:20 -0700 | [diff] [blame] | 1451 | } |
| 1452 | } |
| 1453 | } |
Adam Powell | cfbe9be | 2013-11-06 14:58:58 -0800 | [diff] [blame] | 1454 | |
Andrii Kulian | ada1029 | 2017-02-09 23:19:29 -0800 | [diff] [blame] | 1455 | app.hasShownUi = true; |
| 1456 | app.pendingUiClean = true; |
Dianne Hackborn | 4870e9d | 2015-04-08 16:55:47 -0700 | [diff] [blame] | 1457 | app.forceProcessStateUpTo(mService.mTopProcessState); |
Andrii Kulian | 1779e61 | 2016-10-12 21:58:25 -0700 | [diff] [blame] | 1458 | // Because we could be starting an Activity in the system process this may not go across |
| 1459 | // a Binder interface which would create a new Configuration. Consequently we have to |
| 1460 | // always create a new Configuration here. |
Bryce Lee | a163b76 | 2017-01-24 11:05:01 -0800 | [diff] [blame] | 1461 | |
Wale Ogunwale | e610d3d | 2017-04-25 10:23:48 -0700 | [diff] [blame] | 1462 | final MergedConfiguration mergedConfiguration = new MergedConfiguration( |
| 1463 | mService.getGlobalConfiguration(), r.getMergedOverrideConfiguration()); |
| 1464 | r.setLastReportedConfiguration(mergedConfiguration); |
Bryce Lee | a163b76 | 2017-01-24 11:05:01 -0800 | [diff] [blame] | 1465 | |
Craig Mautner | 2420ead | 2013-04-01 17:13:20 -0700 | [diff] [blame] | 1466 | app.thread.scheduleLaunchActivity(new Intent(r.intent), r.appToken, |
Andrii Kulian | 8072d11 | 2016-09-16 11:11:01 -0700 | [diff] [blame] | 1467 | System.identityHashCode(r), r.info, |
Wale Ogunwale | e610d3d | 2017-04-25 10:23:48 -0700 | [diff] [blame] | 1468 | // TODO: Have this take the merged configuration instead of separate global and |
| 1469 | // override configs. |
| 1470 | mergedConfiguration.getGlobalConfiguration(), |
| 1471 | mergedConfiguration.getOverrideConfiguration(), r.compat, |
Andrii Kulian | 1779e61 | 2016-10-12 21:58:25 -0700 | [diff] [blame] | 1472 | r.launchedFromPackage, task.voiceInteractor, app.repProcState, r.icicle, |
| 1473 | r.persistentState, results, newIntents, !andResume, |
| 1474 | mService.isNextTransitionForward(), profilerInfo); |
Craig Mautner | 2420ead | 2013-04-01 17:13:20 -0700 | [diff] [blame] | 1475 | |
Alex Klyubin | b9f8a52 | 2015-02-03 11:12:59 -0800 | [diff] [blame] | 1476 | if ((app.info.privateFlags&ApplicationInfo.PRIVATE_FLAG_CANT_SAVE_STATE) != 0) { |
Craig Mautner | 2420ead | 2013-04-01 17:13:20 -0700 | [diff] [blame] | 1477 | // This may be a heavy-weight process! Note that the package |
| 1478 | // manager will ensure that only activity can run in the main |
| 1479 | // process of the .apk, which is the only thing that will be |
| 1480 | // considered heavy-weight. |
| 1481 | if (app.processName.equals(app.info.packageName)) { |
| 1482 | if (mService.mHeavyWeightProcess != null |
| 1483 | && mService.mHeavyWeightProcess != app) { |
| 1484 | Slog.w(TAG, "Starting new heavy weight process " + app |
| 1485 | + " when already running " |
| 1486 | + mService.mHeavyWeightProcess); |
| 1487 | } |
| 1488 | mService.mHeavyWeightProcess = app; |
| 1489 | Message msg = mService.mHandler.obtainMessage( |
| 1490 | ActivityManagerService.POST_HEAVY_NOTIFICATION_MSG); |
| 1491 | msg.obj = r; |
| 1492 | mService.mHandler.sendMessage(msg); |
| 1493 | } |
| 1494 | } |
| 1495 | |
| 1496 | } catch (RemoteException e) { |
| 1497 | if (r.launchFailed) { |
| 1498 | // This is the second time we failed -- finish activity |
| 1499 | // and give up. |
| 1500 | Slog.e(TAG, "Second failure launching " |
| 1501 | + r.intent.getComponent().flattenToShortString() |
| 1502 | + ", giving up", e); |
Craig Mautner | 4a8dddbf | 2014-08-13 10:49:26 -0700 | [diff] [blame] | 1503 | mService.appDiedLocked(app); |
Craig Mautner | 2420ead | 2013-04-01 17:13:20 -0700 | [diff] [blame] | 1504 | stack.requestFinishActivityLocked(r.appToken, Activity.RESULT_CANCELED, null, |
| 1505 | "2nd-crash", false); |
| 1506 | return false; |
| 1507 | } |
| 1508 | |
| 1509 | // This is the first time we failed -- restart process and |
| 1510 | // retry. |
Sudheer Shanka | e49e7b8 | 2017-05-05 16:39:32 -0700 | [diff] [blame] | 1511 | r.launchFailed = true; |
Craig Mautner | 2420ead | 2013-04-01 17:13:20 -0700 | [diff] [blame] | 1512 | app.activities.remove(r); |
| 1513 | throw e; |
| 1514 | } |
| 1515 | |
| 1516 | r.launchFailed = false; |
| 1517 | if (stack.updateLRUListLocked(r)) { |
Filip Gruszczynski | 49b80af | 2015-09-24 09:04:26 -0700 | [diff] [blame] | 1518 | Slog.w(TAG, "Activity " + r + " being launched, but already in LRU list"); |
Craig Mautner | 2420ead | 2013-04-01 17:13:20 -0700 | [diff] [blame] | 1519 | } |
| 1520 | |
| 1521 | if (andResume) { |
| 1522 | // As part of the process of launching, ActivityThread also performs |
| 1523 | // a resume. |
| 1524 | stack.minimalResumeActivityLocked(r); |
| 1525 | } else { |
Wale Ogunwale | d046a01 | 2015-12-24 13:05:59 -0800 | [diff] [blame] | 1526 | // 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] | 1527 | // 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] | 1528 | // current icicle and other state. |
Wale Ogunwale | 0fc365c | 2015-05-25 19:35:42 -0700 | [diff] [blame] | 1529 | if (DEBUG_STATES) Slog.v(TAG_STATES, |
Wale Ogunwale | d046a01 | 2015-12-24 13:05:59 -0800 | [diff] [blame] | 1530 | "Moving to PAUSED: " + r + " (starting in paused state)"); |
| 1531 | r.state = PAUSED; |
Craig Mautner | 2420ead | 2013-04-01 17:13:20 -0700 | [diff] [blame] | 1532 | } |
| 1533 | |
| 1534 | // Launch the new version setup screen if needed. We do this -after- |
| 1535 | // launching the initial activity (that is, home), so that it can have |
| 1536 | // a chance to initialize itself while in the background, making the |
| 1537 | // switch back to it faster and look better. |
Wale Ogunwale | 1e60e0c | 2015-10-28 13:36:10 -0700 | [diff] [blame] | 1538 | if (isFocusedStack(stack)) { |
Craig Mautner | 2420ead | 2013-04-01 17:13:20 -0700 | [diff] [blame] | 1539 | mService.startSetupActivityLocked(); |
| 1540 | } |
| 1541 | |
Dianne Hackborn | 465fa39 | 2014-09-14 14:21:18 -0700 | [diff] [blame] | 1542 | // Update any services we are bound to that might care about whether |
| 1543 | // their client may have activities. |
Wale Ogunwale | d6ac762 | 2016-05-26 09:02:25 -0700 | [diff] [blame] | 1544 | if (r.app != null) { |
| 1545 | mService.mServices.updateServiceConnectionActivitiesLocked(r.app); |
| 1546 | } |
Dianne Hackborn | 465fa39 | 2014-09-14 14:21:18 -0700 | [diff] [blame] | 1547 | |
Craig Mautner | 2420ead | 2013-04-01 17:13:20 -0700 | [diff] [blame] | 1548 | return true; |
| 1549 | } |
| 1550 | |
Craig Mautner | e79d4268 | 2013-04-01 19:01:53 -0700 | [diff] [blame] | 1551 | void startSpecificActivityLocked(ActivityRecord r, |
George Mount | 2c92c97 | 2014-03-20 09:38:23 -0700 | [diff] [blame] | 1552 | boolean andResume, boolean checkConfig) { |
Craig Mautner | e79d4268 | 2013-04-01 19:01:53 -0700 | [diff] [blame] | 1553 | // Is this activity's application already running? |
| 1554 | ProcessRecord app = mService.getProcessRecordLocked(r.processName, |
Dianne Hackborn | 3bc8f78d | 2013-09-19 13:34:35 -0700 | [diff] [blame] | 1555 | r.info.applicationInfo.uid, true); |
Craig Mautner | e79d4268 | 2013-04-01 19:01:53 -0700 | [diff] [blame] | 1556 | |
Andrii Kulian | 02b7a83 | 2016-10-06 23:11:56 -0700 | [diff] [blame] | 1557 | r.getStack().setLaunchTime(r); |
Craig Mautner | e79d4268 | 2013-04-01 19:01:53 -0700 | [diff] [blame] | 1558 | |
| 1559 | if (app != null && app.thread != null) { |
| 1560 | try { |
Dianne Hackborn | 237cefb | 2013-10-22 18:45:27 -0700 | [diff] [blame] | 1561 | if ((r.info.flags&ActivityInfo.FLAG_MULTIPROCESS) == 0 |
| 1562 | || !"android".equals(r.info.packageName)) { |
| 1563 | // Don't add this if it is a platform component that is marked |
| 1564 | // to run in multiple processes, because this is actually |
| 1565 | // part of the framework so doesn't make sense to track as a |
| 1566 | // separate apk in the process. |
Dianne Hackborn | f7097a5 | 2014-05-13 09:56:14 -0700 | [diff] [blame] | 1567 | app.addPackage(r.info.packageName, r.info.applicationInfo.versionCode, |
| 1568 | mService.mProcessStats); |
Dianne Hackborn | 237cefb | 2013-10-22 18:45:27 -0700 | [diff] [blame] | 1569 | } |
George Mount | 2c92c97 | 2014-03-20 09:38:23 -0700 | [diff] [blame] | 1570 | realStartActivityLocked(r, app, andResume, checkConfig); |
Craig Mautner | e79d4268 | 2013-04-01 19:01:53 -0700 | [diff] [blame] | 1571 | return; |
| 1572 | } catch (RemoteException e) { |
| 1573 | Slog.w(TAG, "Exception when starting activity " |
| 1574 | + r.intent.getComponent().flattenToShortString(), e); |
| 1575 | } |
| 1576 | |
| 1577 | // If a dead object exception was thrown -- fall through to |
| 1578 | // restart the application. |
| 1579 | } |
| 1580 | |
| 1581 | mService.startProcessLocked(r.processName, r.info.applicationInfo, true, 0, |
Dianne Hackborn | 3bc8f78d | 2013-09-19 13:34:35 -0700 | [diff] [blame] | 1582 | "activity", r.intent.getComponent(), false, false, true); |
Craig Mautner | e79d4268 | 2013-04-01 19:01:53 -0700 | [diff] [blame] | 1583 | } |
| 1584 | |
Filip Gruszczynski | 07a0e49 | 2015-12-17 14:16:38 -0800 | [diff] [blame] | 1585 | boolean checkStartAnyActivityPermission(Intent intent, ActivityInfo aInfo, |
Filip Gruszczynski | dc39490 | 2015-12-14 10:20:22 -0800 | [diff] [blame] | 1586 | String resultWho, int requestCode, int callingPid, int callingUid, |
| 1587 | String callingPackage, boolean ignoreTargetSecurity, ProcessRecord callerApp, |
Jorim Jaggi | 2adba07 | 2016-03-03 13:43:39 +0100 | [diff] [blame] | 1588 | ActivityRecord resultRecord, ActivityStack resultStack, ActivityOptions options) { |
Filip Gruszczynski | dc39490 | 2015-12-14 10:20:22 -0800 | [diff] [blame] | 1589 | final int startAnyPerm = mService.checkPermission(START_ANY_ACTIVITY, callingPid, |
| 1590 | callingUid); |
Andrii Kulian | fb1bf69 | 2017-01-17 11:17:34 -0800 | [diff] [blame] | 1591 | if (startAnyPerm == PERMISSION_GRANTED) { |
Filip Gruszczynski | dc39490 | 2015-12-14 10:20:22 -0800 | [diff] [blame] | 1592 | return true; |
| 1593 | } |
| 1594 | final int componentRestriction = getComponentRestrictionForCallingPackage( |
| 1595 | aInfo, callingPackage, callingPid, callingUid, ignoreTargetSecurity); |
| 1596 | final int actionRestriction = getActionRestrictionForCallingPackage( |
| 1597 | intent.getAction(), callingPackage, callingPid, callingUid); |
| 1598 | if (componentRestriction == ACTIVITY_RESTRICTION_PERMISSION |
| 1599 | || actionRestriction == ACTIVITY_RESTRICTION_PERMISSION) { |
| 1600 | if (resultRecord != null) { |
| 1601 | resultStack.sendActivityResultLocked(-1, |
| 1602 | resultRecord, resultWho, requestCode, |
| 1603 | Activity.RESULT_CANCELED, null); |
| 1604 | } |
| 1605 | final String msg; |
| 1606 | if (actionRestriction == ACTIVITY_RESTRICTION_PERMISSION) { |
| 1607 | msg = "Permission Denial: starting " + intent.toString() |
| 1608 | + " from " + callerApp + " (pid=" + callingPid |
| 1609 | + ", uid=" + callingUid + ")" + " with revoked permission " |
| 1610 | + ACTION_TO_RUNTIME_PERMISSION.get(intent.getAction()); |
| 1611 | } else if (!aInfo.exported) { |
| 1612 | msg = "Permission Denial: starting " + intent.toString() |
| 1613 | + " from " + callerApp + " (pid=" + callingPid |
| 1614 | + ", uid=" + callingUid + ")" |
| 1615 | + " not exported from uid " + aInfo.applicationInfo.uid; |
| 1616 | } else { |
| 1617 | msg = "Permission Denial: starting " + intent.toString() |
| 1618 | + " from " + callerApp + " (pid=" + callingPid |
| 1619 | + ", uid=" + callingUid + ")" |
| 1620 | + " requires " + aInfo.permission; |
| 1621 | } |
| 1622 | Slog.w(TAG, msg); |
| 1623 | throw new SecurityException(msg); |
| 1624 | } |
| 1625 | |
| 1626 | if (actionRestriction == ACTIVITY_RESTRICTION_APPOP) { |
| 1627 | final String message = "Appop Denial: starting " + intent.toString() |
| 1628 | + " from " + callerApp + " (pid=" + callingPid |
| 1629 | + ", uid=" + callingUid + ")" |
| 1630 | + " requires " + AppOpsManager.permissionToOp( |
| 1631 | ACTION_TO_RUNTIME_PERMISSION.get(intent.getAction())); |
| 1632 | Slog.w(TAG, message); |
| 1633 | return false; |
| 1634 | } else if (componentRestriction == ACTIVITY_RESTRICTION_APPOP) { |
| 1635 | final String message = "Appop Denial: starting " + intent.toString() |
| 1636 | + " from " + callerApp + " (pid=" + callingPid |
| 1637 | + ", uid=" + callingUid + ")" |
| 1638 | + " requires appop " + AppOpsManager.permissionToOp(aInfo.permission); |
| 1639 | Slog.w(TAG, message); |
| 1640 | return false; |
| 1641 | } |
Andrii Kulian | 16802aa | 2016-11-02 12:21:33 -0700 | [diff] [blame] | 1642 | if (options != null) { |
| 1643 | if (options.getLaunchTaskId() != INVALID_STACK_ID) { |
| 1644 | final int startInTaskPerm = mService.checkPermission(START_TASKS_FROM_RECENTS, |
| 1645 | callingPid, callingUid); |
| 1646 | if (startInTaskPerm != PERMISSION_GRANTED) { |
| 1647 | final String msg = "Permission Denial: starting " + intent.toString() |
| 1648 | + " from " + callerApp + " (pid=" + callingPid |
| 1649 | + ", uid=" + callingUid + ") with launchTaskId=" |
| 1650 | + options.getLaunchTaskId(); |
| 1651 | Slog.w(TAG, msg); |
| 1652 | throw new SecurityException(msg); |
| 1653 | } |
| 1654 | } |
| 1655 | // Check if someone tries to launch an activity on a private display with a different |
| 1656 | // owner. |
| 1657 | final int launchDisplayId = options.getLaunchDisplayId(); |
Andrii Kulian | fb1bf69 | 2017-01-17 11:17:34 -0800 | [diff] [blame] | 1658 | if (launchDisplayId != INVALID_DISPLAY |
Andrii Kulian | 1cba31c | 2017-06-28 09:42:48 -0700 | [diff] [blame] | 1659 | && !isCallerAllowedToLaunchOnDisplay(callingPid, callingUid, launchDisplayId, |
| 1660 | aInfo)) { |
Andrii Kulian | fb1bf69 | 2017-01-17 11:17:34 -0800 | [diff] [blame] | 1661 | final String msg = "Permission Denial: starting " + intent.toString() |
| 1662 | + " from " + callerApp + " (pid=" + callingPid |
| 1663 | + ", uid=" + callingUid + ") with launchDisplayId=" |
| 1664 | + launchDisplayId; |
| 1665 | Slog.w(TAG, msg); |
| 1666 | throw new SecurityException(msg); |
Jorim Jaggi | 2adba07 | 2016-03-03 13:43:39 +0100 | [diff] [blame] | 1667 | } |
| 1668 | } |
| 1669 | |
Filip Gruszczynski | dc39490 | 2015-12-14 10:20:22 -0800 | [diff] [blame] | 1670 | return true; |
| 1671 | } |
| 1672 | |
Andrii Kulian | fb1bf69 | 2017-01-17 11:17:34 -0800 | [diff] [blame] | 1673 | /** Check if caller is allowed to launch activities on specified display. */ |
Andrii Kulian | 1cba31c | 2017-06-28 09:42:48 -0700 | [diff] [blame] | 1674 | boolean isCallerAllowedToLaunchOnDisplay(int callingPid, int callingUid, int launchDisplayId, |
| 1675 | ActivityInfo aInfo) { |
Andrii Kulian | fb1bf69 | 2017-01-17 11:17:34 -0800 | [diff] [blame] | 1676 | if (DEBUG_TASKS) Slog.d(TAG, "Launch on display check: displayId=" + launchDisplayId |
| 1677 | + " callingPid=" + callingPid + " callingUid=" + callingUid); |
| 1678 | |
Andrii Kulian | 62e6f25 | 2017-05-30 22:46:53 -0700 | [diff] [blame] | 1679 | final ActivityDisplay activityDisplay = getActivityDisplayOrCreateLocked(launchDisplayId); |
Andrii Kulian | fb1bf69 | 2017-01-17 11:17:34 -0800 | [diff] [blame] | 1680 | if (activityDisplay == null) { |
| 1681 | Slog.w(TAG, "Launch on display check: display not found"); |
| 1682 | return false; |
| 1683 | } |
| 1684 | |
Andrii Kulian | 1cba31c | 2017-06-28 09:42:48 -0700 | [diff] [blame] | 1685 | // Check if the caller can manage activity stacks. |
| 1686 | final int startAnyPerm = mService.checkPermission(MANAGE_ACTIVITY_STACKS, callingPid, |
| 1687 | callingUid); |
| 1688 | if (startAnyPerm == PERMISSION_GRANTED) { |
| 1689 | if (DEBUG_TASKS) Slog.d(TAG, "Launch on display check:" |
| 1690 | + " allow launch any on display"); |
| 1691 | return true; |
| 1692 | } |
| 1693 | |
| 1694 | if (activityDisplay.mDisplay.getType() == TYPE_VIRTUAL |
| 1695 | && activityDisplay.mDisplay.getOwnerUid() != SYSTEM_UID |
| 1696 | && (aInfo.flags & ActivityInfo.FLAG_ALLOW_EMBEDDED) == 0) { |
| 1697 | // Limit launching on virtual displays, because their contents can be read from Surface |
| 1698 | // by apps that created them. |
| 1699 | if (DEBUG_TASKS) Slog.d(TAG, "Launch on display check:" |
| 1700 | + " disallow launch on virtual display for not-embedded activity"); |
| 1701 | return false; |
| 1702 | } |
| 1703 | |
Andrii Kulian | fb1bf69 | 2017-01-17 11:17:34 -0800 | [diff] [blame] | 1704 | if (!activityDisplay.isPrivate()) { |
| 1705 | // Anyone can launch on a public display. |
| 1706 | if (DEBUG_TASKS) Slog.d(TAG, "Launch on display check:" |
| 1707 | + " allow launch on public display"); |
| 1708 | return true; |
| 1709 | } |
| 1710 | |
| 1711 | // Check if the caller is the owner of the display. |
| 1712 | if (activityDisplay.mDisplay.getOwnerUid() == callingUid) { |
| 1713 | if (DEBUG_TASKS) Slog.d(TAG, "Launch on display check:" |
| 1714 | + " allow launch for owner of the display"); |
| 1715 | return true; |
| 1716 | } |
| 1717 | |
| 1718 | // Check if caller is present on display |
| 1719 | if (activityDisplay.isUidPresent(callingUid)) { |
| 1720 | if (DEBUG_TASKS) Slog.d(TAG, "Launch on display check:" |
| 1721 | + " allow launch for caller present on the display"); |
| 1722 | return true; |
| 1723 | } |
| 1724 | |
Andrii Kulian | fb1bf69 | 2017-01-17 11:17:34 -0800 | [diff] [blame] | 1725 | Slog.w(TAG, "Launch on display check: denied"); |
| 1726 | return false; |
| 1727 | } |
| 1728 | |
| 1729 | /** Update lists of UIDs that are present on displays and have access to them. */ |
| 1730 | void updateUIDsPresentOnDisplay() { |
| 1731 | mDisplayAccessUIDs.clear(); |
| 1732 | for (int displayNdx = mActivityDisplays.size() - 1; displayNdx >= 0; --displayNdx) { |
| 1733 | final ActivityDisplay activityDisplay = mActivityDisplays.valueAt(displayNdx); |
David Stevens | 82ea6cb | 2017-03-03 16:18:50 -0800 | [diff] [blame] | 1734 | // Only bother calculating the whitelist for private displays |
| 1735 | if (activityDisplay.isPrivate()) { |
| 1736 | mDisplayAccessUIDs.append( |
| 1737 | activityDisplay.mDisplayId, activityDisplay.getPresentUIDs()); |
| 1738 | } |
Andrii Kulian | fb1bf69 | 2017-01-17 11:17:34 -0800 | [diff] [blame] | 1739 | } |
| 1740 | // Store updated lists in DisplayManager. Callers from outside of AM should get them there. |
| 1741 | mDisplayManagerInternal.setDisplayAccessUIDs(mDisplayAccessUIDs); |
| 1742 | } |
| 1743 | |
Filip Gruszczynski | 07a0e49 | 2015-12-17 14:16:38 -0800 | [diff] [blame] | 1744 | UserInfo getUserInfo(int userId) { |
Clara Bayarri | f7fea16 | 2015-10-22 16:09:52 +0100 | [diff] [blame] | 1745 | final long identity = Binder.clearCallingIdentity(); |
| 1746 | try { |
| 1747 | return UserManager.get(mService.mContext).getUserInfo(userId); |
| 1748 | } finally { |
| 1749 | Binder.restoreCallingIdentity(identity); |
| 1750 | } |
| 1751 | } |
| 1752 | |
Svet Ganov | 99b6043 | 2015-06-27 13:15:22 -0700 | [diff] [blame] | 1753 | private int getComponentRestrictionForCallingPackage(ActivityInfo activityInfo, |
Dianne Hackborn | a7cfbe0 | 2015-07-16 10:52:52 -0700 | [diff] [blame] | 1754 | String callingPackage, int callingPid, int callingUid, boolean ignoreTargetSecurity) { |
Dianne Hackborn | a7cfbe0 | 2015-07-16 10:52:52 -0700 | [diff] [blame] | 1755 | if (!ignoreTargetSecurity && mService.checkComponentPermission(activityInfo.permission, |
| 1756 | callingPid, callingUid, activityInfo.applicationInfo.uid, activityInfo.exported) |
Svet Ganov | 99b6043 | 2015-06-27 13:15:22 -0700 | [diff] [blame] | 1757 | == PackageManager.PERMISSION_DENIED) { |
| 1758 | return ACTIVITY_RESTRICTION_PERMISSION; |
| 1759 | } |
| 1760 | |
Christopher Tate | ff7add0 | 2015-08-17 10:23:22 -0700 | [diff] [blame] | 1761 | if (activityInfo.permission == null) { |
| 1762 | return ACTIVITY_RESTRICTION_NONE; |
| 1763 | } |
| 1764 | |
Svet Ganov | 99b6043 | 2015-06-27 13:15:22 -0700 | [diff] [blame] | 1765 | final int opCode = AppOpsManager.permissionToOpCode(activityInfo.permission); |
| 1766 | if (opCode == AppOpsManager.OP_NONE) { |
| 1767 | return ACTIVITY_RESTRICTION_NONE; |
| 1768 | } |
| 1769 | |
| 1770 | if (mService.mAppOpsService.noteOperation(opCode, callingUid, |
| 1771 | callingPackage) != AppOpsManager.MODE_ALLOWED) { |
Dianne Hackborn | a7cfbe0 | 2015-07-16 10:52:52 -0700 | [diff] [blame] | 1772 | if (!ignoreTargetSecurity) { |
| 1773 | return ACTIVITY_RESTRICTION_APPOP; |
| 1774 | } |
Svet Ganov | 99b6043 | 2015-06-27 13:15:22 -0700 | [diff] [blame] | 1775 | } |
| 1776 | |
| 1777 | return ACTIVITY_RESTRICTION_NONE; |
| 1778 | } |
| 1779 | |
Svetoslav | 7008b51 | 2015-06-24 18:47:07 -0700 | [diff] [blame] | 1780 | private int getActionRestrictionForCallingPackage(String action, |
| 1781 | String callingPackage, int callingPid, int callingUid) { |
| 1782 | if (action == null) { |
Svet Ganov | 99b6043 | 2015-06-27 13:15:22 -0700 | [diff] [blame] | 1783 | return ACTIVITY_RESTRICTION_NONE; |
Svetoslav | 7008b51 | 2015-06-24 18:47:07 -0700 | [diff] [blame] | 1784 | } |
| 1785 | |
| 1786 | String permission = ACTION_TO_RUNTIME_PERMISSION.get(action); |
| 1787 | if (permission == null) { |
Svet Ganov | 99b6043 | 2015-06-27 13:15:22 -0700 | [diff] [blame] | 1788 | return ACTIVITY_RESTRICTION_NONE; |
Svetoslav | 7008b51 | 2015-06-24 18:47:07 -0700 | [diff] [blame] | 1789 | } |
| 1790 | |
| 1791 | final PackageInfo packageInfo; |
| 1792 | try { |
| 1793 | packageInfo = mService.mContext.getPackageManager() |
| 1794 | .getPackageInfo(callingPackage, PackageManager.GET_PERMISSIONS); |
| 1795 | } catch (PackageManager.NameNotFoundException e) { |
| 1796 | Slog.i(TAG, "Cannot find package info for " + callingPackage); |
Svet Ganov | 99b6043 | 2015-06-27 13:15:22 -0700 | [diff] [blame] | 1797 | return ACTIVITY_RESTRICTION_NONE; |
Svetoslav | 7008b51 | 2015-06-24 18:47:07 -0700 | [diff] [blame] | 1798 | } |
| 1799 | |
| 1800 | if (!ArrayUtils.contains(packageInfo.requestedPermissions, permission)) { |
Svet Ganov | 99b6043 | 2015-06-27 13:15:22 -0700 | [diff] [blame] | 1801 | return ACTIVITY_RESTRICTION_NONE; |
Svetoslav | 7008b51 | 2015-06-24 18:47:07 -0700 | [diff] [blame] | 1802 | } |
| 1803 | |
| 1804 | if (mService.checkPermission(permission, callingPid, callingUid) == |
| 1805 | PackageManager.PERMISSION_DENIED) { |
Svet Ganov | 99b6043 | 2015-06-27 13:15:22 -0700 | [diff] [blame] | 1806 | return ACTIVITY_RESTRICTION_PERMISSION; |
Svetoslav | 7008b51 | 2015-06-24 18:47:07 -0700 | [diff] [blame] | 1807 | } |
| 1808 | |
| 1809 | final int opCode = AppOpsManager.permissionToOpCode(permission); |
| 1810 | if (opCode == AppOpsManager.OP_NONE) { |
Svet Ganov | 99b6043 | 2015-06-27 13:15:22 -0700 | [diff] [blame] | 1811 | return ACTIVITY_RESTRICTION_NONE; |
Svetoslav | 7008b51 | 2015-06-24 18:47:07 -0700 | [diff] [blame] | 1812 | } |
| 1813 | |
| 1814 | if (mService.mAppOpsService.noteOperation(opCode, callingUid, |
| 1815 | callingPackage) != AppOpsManager.MODE_ALLOWED) { |
Svet Ganov | 99b6043 | 2015-06-27 13:15:22 -0700 | [diff] [blame] | 1816 | return ACTIVITY_RESTRICTION_APPOP; |
Svetoslav | 7008b51 | 2015-06-24 18:47:07 -0700 | [diff] [blame] | 1817 | } |
| 1818 | |
Svet Ganov | 99b6043 | 2015-06-27 13:15:22 -0700 | [diff] [blame] | 1819 | return ACTIVITY_RESTRICTION_NONE; |
Svetoslav | 7008b51 | 2015-06-24 18:47:07 -0700 | [diff] [blame] | 1820 | } |
| 1821 | |
Dianne Hackborn | 3d07c94 | 2015-03-13 18:02:54 -0700 | [diff] [blame] | 1822 | void setLaunchSource(int uid) { |
| 1823 | mLaunchingActivity.setWorkSource(new WorkSource(uid)); |
| 1824 | } |
| 1825 | |
Craig Mautner | 7ea5bd4 | 2013-07-05 15:27:08 -0700 | [diff] [blame] | 1826 | void acquireLaunchWakelock() { |
| 1827 | if (VALIDATE_WAKE_LOCK_CALLER && Binder.getCallingUid() != Process.myUid()) { |
| 1828 | throw new IllegalStateException("Calling must be system uid"); |
| 1829 | } |
| 1830 | mLaunchingActivity.acquire(); |
| 1831 | if (!mHandler.hasMessages(LAUNCH_TIMEOUT_MSG)) { |
| 1832 | // To be safe, don't allow the wake lock to be held for too long. |
| 1833 | mHandler.sendEmptyMessageDelayed(LAUNCH_TIMEOUT_MSG, LAUNCH_TIMEOUT); |
| 1834 | } |
| 1835 | } |
| 1836 | |
Craig Mautner | f3ea23a | 2015-01-13 09:37:08 -0800 | [diff] [blame] | 1837 | /** |
| 1838 | * Called when the frontmost task is idle. |
| 1839 | * @return the state of mService.mBooting before this was called. |
| 1840 | */ |
| 1841 | private boolean checkFinishBootingLocked() { |
| 1842 | final boolean booting = mService.mBooting; |
| 1843 | boolean enableScreen = false; |
| 1844 | mService.mBooting = false; |
| 1845 | if (!mService.mBooted) { |
| 1846 | mService.mBooted = true; |
| 1847 | enableScreen = true; |
| 1848 | } |
| 1849 | if (booting || enableScreen) { |
| 1850 | mService.postFinishBooting(booting, enableScreen); |
| 1851 | } |
| 1852 | return booting; |
| 1853 | } |
| 1854 | |
Craig Mautner | f333327 | 2013-04-22 10:55:53 -0700 | [diff] [blame] | 1855 | // Checked. |
| 1856 | final ActivityRecord activityIdleInternalLocked(final IBinder token, boolean fromTimeout, |
Winson Chung | 4dabf23 | 2017-01-25 13:25:22 -0800 | [diff] [blame] | 1857 | boolean processPausingActivities, Configuration config) { |
Wale Ogunwale | e23149f | 2015-03-06 15:39:44 -0800 | [diff] [blame] | 1858 | if (DEBUG_ALL) Slog.v(TAG, "Activity idle: " + token); |
Craig Mautner | f333327 | 2013-04-22 10:55:53 -0700 | [diff] [blame] | 1859 | |
Craig Mautner | f333327 | 2013-04-22 10:55:53 -0700 | [diff] [blame] | 1860 | ArrayList<ActivityRecord> finishes = null; |
Amith Yamasani | 37a40c2 | 2015-06-17 13:25:42 -0700 | [diff] [blame] | 1861 | ArrayList<UserState> startingUsers = null; |
Craig Mautner | f333327 | 2013-04-22 10:55:53 -0700 | [diff] [blame] | 1862 | int NS = 0; |
| 1863 | int NF = 0; |
Craig Mautner | f333327 | 2013-04-22 10:55:53 -0700 | [diff] [blame] | 1864 | boolean booting = false; |
Craig Mautner | f333327 | 2013-04-22 10:55:53 -0700 | [diff] [blame] | 1865 | boolean activityRemoved = false; |
| 1866 | |
Wale Ogunwale | 7d70117 | 2015-03-11 15:36:30 -0700 | [diff] [blame] | 1867 | ActivityRecord r = ActivityRecord.forTokenLocked(token); |
Craig Mautner | f333327 | 2013-04-22 10:55:53 -0700 | [diff] [blame] | 1868 | if (r != null) { |
Wale Ogunwale | 0fc365c | 2015-05-25 19:35:42 -0700 | [diff] [blame] | 1869 | if (DEBUG_IDLE) Slog.d(TAG_IDLE, "activityIdleInternalLocked: Callers=" |
| 1870 | + Debug.getCallers(4)); |
Craig Mautner | f333327 | 2013-04-22 10:55:53 -0700 | [diff] [blame] | 1871 | mHandler.removeMessages(IDLE_TIMEOUT_MSG, r); |
| 1872 | r.finishLaunchTickingLocked(); |
Craig Mautner | 7ea5bd4 | 2013-07-05 15:27:08 -0700 | [diff] [blame] | 1873 | if (fromTimeout) { |
| 1874 | reportActivityLaunchedLocked(fromTimeout, r, -1, -1); |
Craig Mautner | f333327 | 2013-04-22 10:55:53 -0700 | [diff] [blame] | 1875 | } |
Craig Mautner | 7ea5bd4 | 2013-07-05 15:27:08 -0700 | [diff] [blame] | 1876 | |
| 1877 | // This is a hack to semi-deal with a race condition |
| 1878 | // in the client where it can be constructed with a |
| 1879 | // newer configuration from when we asked it to launch. |
| 1880 | // We'll update with whatever configuration it now says |
| 1881 | // it used to launch. |
| 1882 | if (config != null) { |
Bryce Lee | a163b76 | 2017-01-24 11:05:01 -0800 | [diff] [blame] | 1883 | r.setLastReportedGlobalConfiguration(config); |
Craig Mautner | 7ea5bd4 | 2013-07-05 15:27:08 -0700 | [diff] [blame] | 1884 | } |
| 1885 | |
| 1886 | // We are now idle. If someone is waiting for a thumbnail from |
| 1887 | // us, we can now deliver. |
| 1888 | r.idle = true; |
| 1889 | |
Craig Mautner | 7ea5bd4 | 2013-07-05 15:27:08 -0700 | [diff] [blame] | 1890 | //Slog.i(TAG, "IDLE: mBooted=" + mBooted + ", fromTimeout=" + fromTimeout); |
Andrii Kulian | 02b7a83 | 2016-10-06 23:11:56 -0700 | [diff] [blame] | 1891 | if (isFocusedStack(r.getStack()) || fromTimeout) { |
Craig Mautner | f3ea23a | 2015-01-13 09:37:08 -0800 | [diff] [blame] | 1892 | booting = checkFinishBootingLocked(); |
Craig Mautner | 7ea5bd4 | 2013-07-05 15:27:08 -0700 | [diff] [blame] | 1893 | } |
| 1894 | } |
| 1895 | |
| 1896 | if (allResumedActivitiesIdle()) { |
| 1897 | if (r != null) { |
| 1898 | mService.scheduleAppGcsLocked(); |
Craig Mautner | 7ea5bd4 | 2013-07-05 15:27:08 -0700 | [diff] [blame] | 1899 | } |
| 1900 | |
| 1901 | if (mLaunchingActivity.isHeld()) { |
| 1902 | mHandler.removeMessages(LAUNCH_TIMEOUT_MSG); |
| 1903 | if (VALIDATE_WAKE_LOCK_CALLER && |
| 1904 | Binder.getCallingUid() != Process.myUid()) { |
| 1905 | throw new IllegalStateException("Calling must be system uid"); |
| 1906 | } |
| 1907 | mLaunchingActivity.release(); |
| 1908 | } |
Filip Gruszczynski | bc5a6c5 | 2015-09-22 13:13:24 -0700 | [diff] [blame] | 1909 | ensureActivitiesVisibleLocked(null, 0, !PRESERVE_WINDOWS); |
Craig Mautner | f333327 | 2013-04-22 10:55:53 -0700 | [diff] [blame] | 1910 | } |
| 1911 | |
| 1912 | // Atomically retrieve all of the other things to do. |
Winson Chung | 4dabf23 | 2017-01-25 13:25:22 -0800 | [diff] [blame] | 1913 | final ArrayList<ActivityRecord> stops = processStoppingActivitiesLocked(r, |
| 1914 | true /* remove */, processPausingActivities); |
Craig Mautner | f333327 | 2013-04-22 10:55:53 -0700 | [diff] [blame] | 1915 | NS = stops != null ? stops.size() : 0; |
Wale Ogunwale | 7d70117 | 2015-03-11 15:36:30 -0700 | [diff] [blame] | 1916 | if ((NF = mFinishingActivities.size()) > 0) { |
| 1917 | finishes = new ArrayList<>(mFinishingActivities); |
Craig Mautner | f333327 | 2013-04-22 10:55:53 -0700 | [diff] [blame] | 1918 | mFinishingActivities.clear(); |
| 1919 | } |
| 1920 | |
Craig Mautner | f333327 | 2013-04-22 10:55:53 -0700 | [diff] [blame] | 1921 | if (mStartingUsers.size() > 0) { |
Wale Ogunwale | 7d70117 | 2015-03-11 15:36:30 -0700 | [diff] [blame] | 1922 | startingUsers = new ArrayList<>(mStartingUsers); |
Craig Mautner | f333327 | 2013-04-22 10:55:53 -0700 | [diff] [blame] | 1923 | mStartingUsers.clear(); |
| 1924 | } |
| 1925 | |
Craig Mautner | f333327 | 2013-04-22 10:55:53 -0700 | [diff] [blame] | 1926 | // Stop any activities that are scheduled to do so but have been |
| 1927 | // waiting for the next one to start. |
| 1928 | for (int i = 0; i < NS; i++) { |
| 1929 | r = stops.get(i); |
Andrii Kulian | 02b7a83 | 2016-10-06 23:11:56 -0700 | [diff] [blame] | 1930 | final ActivityStack stack = r.getStack(); |
Wale Ogunwale | 7d70117 | 2015-03-11 15:36:30 -0700 | [diff] [blame] | 1931 | if (stack != null) { |
| 1932 | if (r.finishing) { |
| 1933 | stack.finishCurrentActivityLocked(r, ActivityStack.FINISH_IMMEDIATELY, false); |
| 1934 | } else { |
| 1935 | stack.stopActivityLocked(r); |
| 1936 | } |
Craig Mautner | f333327 | 2013-04-22 10:55:53 -0700 | [diff] [blame] | 1937 | } |
| 1938 | } |
| 1939 | |
| 1940 | // Finish any activities that are scheduled to do so but have been |
| 1941 | // waiting for the next one to start. |
| 1942 | for (int i = 0; i < NF; i++) { |
| 1943 | r = finishes.get(i); |
Andrii Kulian | 02b7a83 | 2016-10-06 23:11:56 -0700 | [diff] [blame] | 1944 | final ActivityStack stack = r.getStack(); |
Wale Ogunwale | 7d70117 | 2015-03-11 15:36:30 -0700 | [diff] [blame] | 1945 | if (stack != null) { |
| 1946 | activityRemoved |= stack.destroyActivityLocked(r, true, "finish-idle"); |
| 1947 | } |
Craig Mautner | f333327 | 2013-04-22 10:55:53 -0700 | [diff] [blame] | 1948 | } |
| 1949 | |
Dianne Hackborn | 7622a0f | 2014-09-30 14:31:42 -0700 | [diff] [blame] | 1950 | if (!booting) { |
Amith Yamasani | 1a7eaaa5 | 2014-05-07 10:22:15 -0700 | [diff] [blame] | 1951 | // Complete user switch |
| 1952 | if (startingUsers != null) { |
| 1953 | for (int i = 0; i < startingUsers.size(); i++) { |
Fyodor Kupolov | 610acda | 2015-10-19 18:44:07 -0700 | [diff] [blame] | 1954 | mService.mUserController.finishUserSwitch(startingUsers.get(i)); |
Amith Yamasani | 1a7eaaa5 | 2014-05-07 10:22:15 -0700 | [diff] [blame] | 1955 | } |
| 1956 | } |
Craig Mautner | f333327 | 2013-04-22 10:55:53 -0700 | [diff] [blame] | 1957 | } |
| 1958 | |
| 1959 | mService.trimApplications(); |
| 1960 | //dump(); |
| 1961 | //mWindowManager.dump(); |
| 1962 | |
Craig Mautner | f333327 | 2013-04-22 10:55:53 -0700 | [diff] [blame] | 1963 | if (activityRemoved) { |
Wale Ogunwale | d046a01 | 2015-12-24 13:05:59 -0800 | [diff] [blame] | 1964 | resumeFocusedStackTopActivityLocked(); |
Craig Mautner | f333327 | 2013-04-22 10:55:53 -0700 | [diff] [blame] | 1965 | } |
| 1966 | |
Craig Mautner | 7ea5bd4 | 2013-07-05 15:27:08 -0700 | [diff] [blame] | 1967 | return r; |
Craig Mautner | f333327 | 2013-04-22 10:55:53 -0700 | [diff] [blame] | 1968 | } |
| 1969 | |
Craig Mautner | 8e56957 | 2013-10-11 17:36:59 -0700 | [diff] [blame] | 1970 | boolean handleAppDiedLocked(ProcessRecord app) { |
Craig Mautner | 1909125 | 2013-10-05 00:03:53 -0700 | [diff] [blame] | 1971 | boolean hasVisibleActivities = false; |
Craig Mautner | e0a3884 | 2013-12-16 16:14:02 -0800 | [diff] [blame] | 1972 | for (int displayNdx = mActivityDisplays.size() - 1; displayNdx >= 0; --displayNdx) { |
| 1973 | final ArrayList<ActivityStack> stacks = mActivityDisplays.valueAt(displayNdx).mStacks; |
Craig Mautner | 4a1cb22 | 2013-12-04 16:14:06 -0800 | [diff] [blame] | 1974 | for (int stackNdx = stacks.size() - 1; stackNdx >= 0; --stackNdx) { |
| 1975 | hasVisibleActivities |= stacks.get(stackNdx).handleAppDiedLocked(app); |
| 1976 | } |
Craig Mautner | 6b74cb5 | 2013-09-27 17:02:21 -0700 | [diff] [blame] | 1977 | } |
Craig Mautner | 1909125 | 2013-10-05 00:03:53 -0700 | [diff] [blame] | 1978 | return hasVisibleActivities; |
Craig Mautner | 8d341ef | 2013-03-26 09:03:27 -0700 | [diff] [blame] | 1979 | } |
| 1980 | |
| 1981 | void closeSystemDialogsLocked() { |
Craig Mautner | e0a3884 | 2013-12-16 16:14:02 -0800 | [diff] [blame] | 1982 | for (int displayNdx = mActivityDisplays.size() - 1; displayNdx >= 0; --displayNdx) { |
| 1983 | final ArrayList<ActivityStack> stacks = mActivityDisplays.valueAt(displayNdx).mStacks; |
Craig Mautner | 4a1cb22 | 2013-12-04 16:14:06 -0800 | [diff] [blame] | 1984 | for (int stackNdx = stacks.size() - 1; stackNdx >= 0; --stackNdx) { |
| 1985 | stacks.get(stackNdx).closeSystemDialogsLocked(); |
| 1986 | } |
Craig Mautner | 8d341ef | 2013-03-26 09:03:27 -0700 | [diff] [blame] | 1987 | } |
| 1988 | } |
| 1989 | |
Craig Mautner | 93529a4 | 2013-10-04 15:03:13 -0700 | [diff] [blame] | 1990 | void removeUserLocked(int userId) { |
Craig Mautner | 4f1df4f | 2013-10-15 15:44:14 -0700 | [diff] [blame] | 1991 | mUserStackInFront.delete(userId); |
Craig Mautner | 93529a4 | 2013-10-04 15:03:13 -0700 | [diff] [blame] | 1992 | } |
| 1993 | |
Craig Mautner | 8d341ef | 2013-03-26 09:03:27 -0700 | [diff] [blame] | 1994 | /** |
Chong Zhang | 45c25ce | 2015-08-10 22:18:26 -0700 | [diff] [blame] | 1995 | * Update the last used stack id for non-current user (current user's last |
| 1996 | * used stack is the focused stack) |
| 1997 | */ |
| 1998 | void updateUserStackLocked(int userId, ActivityStack stack) { |
| 1999 | if (userId != mCurrentUser) { |
| 2000 | mUserStackInFront.put(userId, stack != null ? stack.getStackId() : HOME_STACK_ID); |
| 2001 | } |
| 2002 | } |
| 2003 | |
| 2004 | /** |
Craig Mautner | 8d341ef | 2013-03-26 09:03:27 -0700 | [diff] [blame] | 2005 | * @return true if some activity was finished (or would have finished if doit were true). |
| 2006 | */ |
Wale Ogunwale | 540e123 | 2015-05-01 15:35:39 -0700 | [diff] [blame] | 2007 | boolean finishDisabledPackageActivitiesLocked(String packageName, Set<String> filterByClasses, |
| 2008 | boolean doit, boolean evenPersistent, int userId) { |
Craig Mautner | 8d341ef | 2013-03-26 09:03:27 -0700 | [diff] [blame] | 2009 | boolean didSomething = false; |
Craig Mautner | e0a3884 | 2013-12-16 16:14:02 -0800 | [diff] [blame] | 2010 | for (int displayNdx = mActivityDisplays.size() - 1; displayNdx >= 0; --displayNdx) { |
| 2011 | final ArrayList<ActivityStack> stacks = mActivityDisplays.valueAt(displayNdx).mStacks; |
louis_chang | 8f0555a | 2015-10-27 10:45:53 +0800 | [diff] [blame] | 2012 | for (int stackNdx = stacks.size() - 1; stackNdx >= 0; --stackNdx) { |
Craig Mautner | 4a1cb22 | 2013-12-04 16:14:06 -0800 | [diff] [blame] | 2013 | final ActivityStack stack = stacks.get(stackNdx); |
Wale Ogunwale | 540e123 | 2015-05-01 15:35:39 -0700 | [diff] [blame] | 2014 | if (stack.finishDisabledPackageActivitiesLocked( |
| 2015 | packageName, filterByClasses, doit, evenPersistent, userId)) { |
Craig Mautner | 4a1cb22 | 2013-12-04 16:14:06 -0800 | [diff] [blame] | 2016 | didSomething = true; |
| 2017 | } |
Craig Mautner | 8d341ef | 2013-03-26 09:03:27 -0700 | [diff] [blame] | 2018 | } |
| 2019 | } |
| 2020 | return didSomething; |
| 2021 | } |
| 2022 | |
Dianne Hackborn | a413dc0 | 2013-07-12 12:02:55 -0700 | [diff] [blame] | 2023 | void updatePreviousProcessLocked(ActivityRecord r) { |
| 2024 | // Now that this process has stopped, we may want to consider |
| 2025 | // it to be the previous app to try to keep around in case |
| 2026 | // the user wants to return to it. |
| 2027 | |
| 2028 | // First, found out what is currently the foreground app, so that |
| 2029 | // we don't blow away the previous app if this activity is being |
| 2030 | // hosted by the process that is actually still the foreground. |
| 2031 | ProcessRecord fgApp = null; |
Craig Mautner | e0a3884 | 2013-12-16 16:14:02 -0800 | [diff] [blame] | 2032 | for (int displayNdx = mActivityDisplays.size() - 1; displayNdx >= 0; --displayNdx) { |
| 2033 | final ArrayList<ActivityStack> stacks = mActivityDisplays.valueAt(displayNdx).mStacks; |
Craig Mautner | 4a1cb22 | 2013-12-04 16:14:06 -0800 | [diff] [blame] | 2034 | for (int stackNdx = stacks.size() - 1; stackNdx >= 0; --stackNdx) { |
| 2035 | final ActivityStack stack = stacks.get(stackNdx); |
Wale Ogunwale | 1e60e0c | 2015-10-28 13:36:10 -0700 | [diff] [blame] | 2036 | if (isFocusedStack(stack)) { |
Craig Mautner | 4a1cb22 | 2013-12-04 16:14:06 -0800 | [diff] [blame] | 2037 | if (stack.mResumedActivity != null) { |
| 2038 | fgApp = stack.mResumedActivity.app; |
| 2039 | } else if (stack.mPausingActivity != null) { |
| 2040 | fgApp = stack.mPausingActivity.app; |
| 2041 | } |
| 2042 | break; |
Dianne Hackborn | a413dc0 | 2013-07-12 12:02:55 -0700 | [diff] [blame] | 2043 | } |
Dianne Hackborn | a413dc0 | 2013-07-12 12:02:55 -0700 | [diff] [blame] | 2044 | } |
| 2045 | } |
| 2046 | |
| 2047 | // Now set this one as the previous process, only if that really |
| 2048 | // makes sense to. |
| 2049 | if (r.app != null && fgApp != null && r.app != fgApp |
| 2050 | && r.lastVisibleTime > mService.mPreviousProcessVisibleTime |
Craig Mautner | 4ef2693 | 2013-09-18 15:15:52 -0700 | [diff] [blame] | 2051 | && r.app != mService.mHomeProcess) { |
Dianne Hackborn | a413dc0 | 2013-07-12 12:02:55 -0700 | [diff] [blame] | 2052 | mService.mPreviousProcess = r.app; |
| 2053 | mService.mPreviousProcessVisibleTime = r.lastVisibleTime; |
| 2054 | } |
| 2055 | } |
| 2056 | |
Wale Ogunwale | d046a01 | 2015-12-24 13:05:59 -0800 | [diff] [blame] | 2057 | boolean resumeFocusedStackTopActivityLocked() { |
| 2058 | return resumeFocusedStackTopActivityLocked(null, null, null); |
Craig Mautner | 05d2903 | 2013-05-03 13:40:13 -0700 | [diff] [blame] | 2059 | } |
| 2060 | |
Wale Ogunwale | d046a01 | 2015-12-24 13:05:59 -0800 | [diff] [blame] | 2061 | boolean resumeFocusedStackTopActivityLocked( |
Chong Zhang | 280d332 | 2015-11-03 17:27:26 -0800 | [diff] [blame] | 2062 | ActivityStack targetStack, ActivityRecord target, ActivityOptions targetOptions) { |
Wale Ogunwale | d046a01 | 2015-12-24 13:05:59 -0800 | [diff] [blame] | 2063 | if (targetStack != null && isFocusedStack(targetStack)) { |
| 2064 | return targetStack.resumeTopActivityUncheckedLocked(target, targetOptions); |
Craig Mautner | 05d2903 | 2013-05-03 13:40:13 -0700 | [diff] [blame] | 2065 | } |
Wale Ogunwale | 06579d6 | 2016-04-30 15:29:06 -0700 | [diff] [blame] | 2066 | final ActivityRecord r = mFocusedStack.topRunningActivityLocked(); |
| 2067 | if (r == null || r.state != RESUMED) { |
| 2068 | mFocusedStack.resumeTopActivityUncheckedLocked(null, null); |
skuhne@google.com | 1b974dc | 2016-12-09 13:41:29 -0800 | [diff] [blame] | 2069 | } else if (r.state == RESUMED) { |
| 2070 | // Kick off any lingering app transitions form the MoveTaskToFront operation. |
| 2071 | mFocusedStack.executeAppTransition(targetOptions); |
Wale Ogunwale | 06579d6 | 2016-04-30 15:29:06 -0700 | [diff] [blame] | 2072 | } |
Wale Ogunwale | d046a01 | 2015-12-24 13:05:59 -0800 | [diff] [blame] | 2073 | return false; |
Craig Mautner | 8d341ef | 2013-03-26 09:03:27 -0700 | [diff] [blame] | 2074 | } |
| 2075 | |
Todd Kennedy | 39bfee5 | 2016-02-24 10:28:21 -0800 | [diff] [blame] | 2076 | void updateActivityApplicationInfoLocked(ApplicationInfo aInfo) { |
| 2077 | for (int displayNdx = mActivityDisplays.size() - 1; displayNdx >= 0; --displayNdx) { |
| 2078 | final ArrayList<ActivityStack> stacks = mActivityDisplays.valueAt(displayNdx).mStacks; |
| 2079 | for (int stackNdx = stacks.size() - 1; stackNdx >= 0; --stackNdx) { |
| 2080 | stacks.get(stackNdx).updateActivityApplicationInfoLocked(aInfo); |
| 2081 | } |
| 2082 | } |
| 2083 | } |
| 2084 | |
Adrian Roos | 20d7df3 | 2016-01-12 18:59:43 +0100 | [diff] [blame] | 2085 | TaskRecord finishTopRunningActivityLocked(ProcessRecord app, String reason) { |
| 2086 | TaskRecord finishedTask = null; |
| 2087 | ActivityStack focusedStack = getFocusedStack(); |
Craig Mautner | e0a3884 | 2013-12-16 16:14:02 -0800 | [diff] [blame] | 2088 | for (int displayNdx = mActivityDisplays.size() - 1; displayNdx >= 0; --displayNdx) { |
| 2089 | final ArrayList<ActivityStack> stacks = mActivityDisplays.valueAt(displayNdx).mStacks; |
Craig Mautner | 4a1cb22 | 2013-12-04 16:14:06 -0800 | [diff] [blame] | 2090 | final int numStacks = stacks.size(); |
| 2091 | for (int stackNdx = 0; stackNdx < numStacks; ++stackNdx) { |
| 2092 | final ActivityStack stack = stacks.get(stackNdx); |
Adrian Roos | 20d7df3 | 2016-01-12 18:59:43 +0100 | [diff] [blame] | 2093 | TaskRecord t = stack.finishTopRunningActivityLocked(app, reason); |
| 2094 | if (stack == focusedStack || finishedTask == null) { |
| 2095 | finishedTask = t; |
| 2096 | } |
Craig Mautner | 4a1cb22 | 2013-12-04 16:14:06 -0800 | [diff] [blame] | 2097 | } |
Craig Mautner | 8d341ef | 2013-03-26 09:03:27 -0700 | [diff] [blame] | 2098 | } |
Adrian Roos | 20d7df3 | 2016-01-12 18:59:43 +0100 | [diff] [blame] | 2099 | return finishedTask; |
Craig Mautner | 8d341ef | 2013-03-26 09:03:27 -0700 | [diff] [blame] | 2100 | } |
| 2101 | |
Dianne Hackborn | 6ea0d0a | 2014-07-02 16:23:21 -0700 | [diff] [blame] | 2102 | void finishVoiceTask(IVoiceInteractionSession session) { |
| 2103 | for (int displayNdx = mActivityDisplays.size() - 1; displayNdx >= 0; --displayNdx) { |
| 2104 | final ArrayList<ActivityStack> stacks = mActivityDisplays.valueAt(displayNdx).mStacks; |
| 2105 | final int numStacks = stacks.size(); |
| 2106 | for (int stackNdx = 0; stackNdx < numStacks; ++stackNdx) { |
| 2107 | final ActivityStack stack = stacks.get(stackNdx); |
| 2108 | stack.finishVoiceTask(session); |
| 2109 | } |
| 2110 | } |
| 2111 | } |
| 2112 | |
Andrii Kulian | c2791664 | 2016-04-12 17:59:27 -0700 | [diff] [blame] | 2113 | void findTaskToMoveToFrontLocked(TaskRecord task, int flags, ActivityOptions options, |
| 2114 | String reason, boolean forceNonResizeable) { |
Craig Mautner | aea74a5 | 2014-03-08 14:23:10 -0800 | [diff] [blame] | 2115 | if ((flags & ActivityManager.MOVE_TASK_NO_USER_ACTION) == 0) { |
| 2116 | mUserLeaving = true; |
Craig Mautner | 8d341ef | 2013-03-26 09:03:27 -0700 | [diff] [blame] | 2117 | } |
Craig Mautner | aea74a5 | 2014-03-08 14:23:10 -0800 | [diff] [blame] | 2118 | if ((flags & ActivityManager.MOVE_TASK_WITH_HOME) != 0) { |
| 2119 | // Caller wants the home activity moved with it. To accomplish this, |
| 2120 | // we'll just indicate that this task returns to the home task. |
Craig Mautner | 84984fa | 2014-06-19 11:19:20 -0700 | [diff] [blame] | 2121 | task.setTaskToReturnTo(HOME_ACTIVITY_TYPE); |
Craig Mautner | aea74a5 | 2014-03-08 14:23:10 -0800 | [diff] [blame] | 2122 | } |
Andrii Kulian | 02b7a83 | 2016-10-06 23:11:56 -0700 | [diff] [blame] | 2123 | ActivityStack currentStack = task.getStack(); |
| 2124 | if (currentStack == null) { |
Wale Ogunwale | 7d70117 | 2015-03-11 15:36:30 -0700 | [diff] [blame] | 2125 | Slog.e(TAG, "findTaskToMoveToFrontLocked: can't move task=" |
| 2126 | + task + " to front. Stack is null"); |
| 2127 | return; |
| 2128 | } |
Chong Zhang | 0fa656b | 2015-08-31 15:17:21 -0700 | [diff] [blame] | 2129 | |
Wale Ogunwale | b1faf60 | 2016-01-27 09:12:31 -0800 | [diff] [blame] | 2130 | if (task.isResizeable() && options != null) { |
Wale Ogunwale | 854809c | 2015-12-27 16:18:19 -0800 | [diff] [blame] | 2131 | int stackId = options.getLaunchStackId(); |
| 2132 | if (canUseActivityOptionsLaunchBounds(options, stackId)) { |
Filip Gruszczynski | dce2d16 | 2016-01-12 15:40:13 -0800 | [diff] [blame] | 2133 | final Rect bounds = TaskRecord.validateBounds(options.getLaunchBounds()); |
Chong Zhang | 0fa656b | 2015-08-31 15:17:21 -0700 | [diff] [blame] | 2134 | task.updateOverrideConfiguration(bounds); |
Wale Ogunwale | 854809c | 2015-12-27 16:18:19 -0800 | [diff] [blame] | 2135 | if (stackId == INVALID_STACK_ID) { |
| 2136 | stackId = task.getLaunchStackId(); |
| 2137 | } |
Andrii Kulian | 02b7a83 | 2016-10-06 23:11:56 -0700 | [diff] [blame] | 2138 | if (stackId != currentStack.mStackId) { |
Winson Chung | 7466610 | 2017-02-22 17:49:24 -0800 | [diff] [blame] | 2139 | task.reparent(stackId, ON_TOP, REPARENT_KEEP_STACK_AT_FRONT, !ANIMATE, |
| 2140 | DEFER_RESUME, "findTaskToMoveToFrontLocked"); |
Andrii Kulian | 02b7a83 | 2016-10-06 23:11:56 -0700 | [diff] [blame] | 2141 | stackId = currentStack.mStackId; |
Chong Zhang | 112eb8c | 2015-11-02 11:17:00 -0800 | [diff] [blame] | 2142 | // moveTaskToStackUncheckedLocked() should already placed the task on top, |
| 2143 | // still need moveTaskToFrontLocked() below for any transition settings. |
| 2144 | } |
Wale Ogunwale | cacfaa2 | 2016-01-15 11:26:08 -0800 | [diff] [blame] | 2145 | if (StackId.resizeStackWithLaunchBounds(stackId)) { |
| 2146 | resizeStackLocked(stackId, bounds, |
| 2147 | null /* tempTaskBounds */, null /* tempTaskInsetBounds */, |
Wale Ogunwale | c8da41e | 2016-04-16 13:27:23 -0700 | [diff] [blame] | 2148 | !PRESERVE_WINDOWS, true /* allowResizeInDockedMode */, !DEFER_RESUME); |
Wale Ogunwale | cacfaa2 | 2016-01-15 11:26:08 -0800 | [diff] [blame] | 2149 | } else { |
| 2150 | // WM resizeTask must be done after the task is moved to the correct stack, |
| 2151 | // because Task's setBounds() also updates dim layer's bounds, but that has |
| 2152 | // dependency on the stack. |
Wale Ogunwale | e1fe7fa2 | 2016-12-15 18:27:00 -0800 | [diff] [blame] | 2153 | task.resizeWindowContainer(); |
Wale Ogunwale | cacfaa2 | 2016-01-15 11:26:08 -0800 | [diff] [blame] | 2154 | } |
Chong Zhang | 0fa656b | 2015-08-31 15:17:21 -0700 | [diff] [blame] | 2155 | } |
| 2156 | } |
| 2157 | |
Chong Zhang | db20b5f | 2015-10-23 14:01:43 -0700 | [diff] [blame] | 2158 | final ActivityRecord r = task.getTopActivity(); |
Andrii Kulian | 02b7a83 | 2016-10-06 23:11:56 -0700 | [diff] [blame] | 2159 | currentStack.moveTaskToFrontLocked(task, false /* noAnimation */, options, |
Chong Zhang | db20b5f | 2015-10-23 14:01:43 -0700 | [diff] [blame] | 2160 | r == null ? null : r.appTimeTracker, reason); |
| 2161 | |
Wale Ogunwale | ee006da | 2015-03-30 14:49:25 -0700 | [diff] [blame] | 2162 | if (DEBUG_STACK) Slog.d(TAG_STACK, |
Andrii Kulian | 02b7a83 | 2016-10-06 23:11:56 -0700 | [diff] [blame] | 2163 | "findTaskToMoveToFront: moved to front of stack=" + currentStack); |
Jorim Jaggi | 2adba07 | 2016-03-03 13:43:39 +0100 | [diff] [blame] | 2164 | |
Andrii Kulian | 036e3ad | 2017-04-19 10:55:10 -0700 | [diff] [blame] | 2165 | handleNonResizableTaskIfNeeded(task, INVALID_STACK_ID, DEFAULT_DISPLAY, |
| 2166 | currentStack.mStackId, forceNonResizeable); |
Craig Mautner | 8d341ef | 2013-03-26 09:03:27 -0700 | [diff] [blame] | 2167 | } |
| 2168 | |
Wale Ogunwale | 854809c | 2015-12-27 16:18:19 -0800 | [diff] [blame] | 2169 | boolean canUseActivityOptionsLaunchBounds(ActivityOptions options, int launchStackId) { |
Wale Ogunwale | 7a8fa60 | 2015-11-18 15:56:57 -0800 | [diff] [blame] | 2170 | // 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] | 2171 | // window management or is launching into the pinned stack. |
Wale Ogunwale | 5122df0 | 2016-01-29 22:33:38 -0800 | [diff] [blame] | 2172 | if (options.getLaunchBounds() == null) { |
Wale Ogunwale | 854809c | 2015-12-27 16:18:19 -0800 | [diff] [blame] | 2173 | return false; |
| 2174 | } |
| 2175 | return (mService.mSupportsPictureInPicture && launchStackId == PINNED_STACK_ID) |
| 2176 | || mService.mSupportsFreeformWindowManagement; |
Wale Ogunwale | 7a8fa60 | 2015-11-18 15:56:57 -0800 | [diff] [blame] | 2177 | } |
| 2178 | |
Winson Chung | 5589333 | 2017-02-17 17:13:10 -0800 | [diff] [blame] | 2179 | protected <T extends ActivityStack> T getStack(int stackId) { |
Wale Ogunwale | 040b470 | 2015-08-06 18:10:50 -0700 | [diff] [blame] | 2180 | return getStack(stackId, !CREATE_IF_NEEDED, !ON_TOP); |
Wale Ogunwale | ddc1cb2 | 2015-07-25 19:23:04 -0700 | [diff] [blame] | 2181 | } |
| 2182 | |
Winson Chung | 5589333 | 2017-02-17 17:13:10 -0800 | [diff] [blame] | 2183 | protected <T extends ActivityStack> T getStack(int stackId, boolean createStaticStackIfNeeded, |
| 2184 | boolean createOnTop) { |
Andrii Kulian | 16802aa | 2016-11-02 12:21:33 -0700 | [diff] [blame] | 2185 | final ActivityContainer activityContainer = mActivityContainers.get(stackId); |
Craig Mautner | f4c909b | 2014-04-17 18:39:38 -0700 | [diff] [blame] | 2186 | if (activityContainer != null) { |
Winson Chung | 5589333 | 2017-02-17 17:13:10 -0800 | [diff] [blame] | 2187 | return (T) activityContainer.mStack; |
Craig Mautner | 8d341ef | 2013-03-26 09:03:27 -0700 | [diff] [blame] | 2188 | } |
Wale Ogunwale | 3797c22 | 2015-10-27 14:21:58 -0700 | [diff] [blame] | 2189 | if (!createStaticStackIfNeeded || !StackId.isStaticStack(stackId)) { |
Wale Ogunwale | ddc1cb2 | 2015-07-25 19:23:04 -0700 | [diff] [blame] | 2190 | return null; |
| 2191 | } |
Matthew Ng | 330757d | 2017-02-28 14:19:17 -0800 | [diff] [blame] | 2192 | if (stackId == DOCKED_STACK_ID) { |
| 2193 | // Make sure recents stack exist when creating a dock stack as it normally need to be on |
| 2194 | // the other side of the docked stack and we make visibility decisions based on that. |
| 2195 | getStack(RECENTS_STACK_ID, CREATE_IF_NEEDED, createOnTop); |
| 2196 | } |
Winson Chung | 5589333 | 2017-02-17 17:13:10 -0800 | [diff] [blame] | 2197 | return (T) createStackOnDisplay(stackId, DEFAULT_DISPLAY, createOnTop); |
Craig Mautner | 8d341ef | 2013-03-26 09:03:27 -0700 | [diff] [blame] | 2198 | } |
| 2199 | |
Andrii Kulian | 16802aa | 2016-11-02 12:21:33 -0700 | [diff] [blame] | 2200 | /** |
| 2201 | * Get a topmost stack on the display, that is a valid launch stack for specified activity. |
| 2202 | * If there is no such stack, new dynamic stack can be created. |
| 2203 | * @param displayId Target display. |
| 2204 | * @param r Activity that should be launched there. |
| 2205 | * @return Existing stack if there is a valid one, new dynamic stack if it is valid or null. |
| 2206 | */ |
| 2207 | ActivityStack getValidLaunchStackOnDisplay(int displayId, @NonNull ActivityRecord r) { |
Andrii Kulian | 62e6f25 | 2017-05-30 22:46:53 -0700 | [diff] [blame] | 2208 | final ActivityDisplay activityDisplay = getActivityDisplayOrCreateLocked(displayId); |
Andrii Kulian | 16802aa | 2016-11-02 12:21:33 -0700 | [diff] [blame] | 2209 | if (activityDisplay == null) { |
| 2210 | throw new IllegalArgumentException( |
| 2211 | "Display with displayId=" + displayId + " not found."); |
| 2212 | } |
| 2213 | |
| 2214 | // Return the topmost valid stack on the display. |
| 2215 | for (int i = activityDisplay.mStacks.size() - 1; i >= 0; --i) { |
| 2216 | final ActivityStack stack = activityDisplay.mStacks.get(i); |
Andrii Kulian | 036e3ad | 2017-04-19 10:55:10 -0700 | [diff] [blame] | 2217 | if (mService.mActivityStarter.isValidLaunchStackId(stack.mStackId, displayId, r)) { |
Andrii Kulian | 16802aa | 2016-11-02 12:21:33 -0700 | [diff] [blame] | 2218 | return stack; |
| 2219 | } |
| 2220 | } |
| 2221 | |
| 2222 | // If there is no valid stack on the external display - check if new dynamic stack will do. |
| 2223 | if (displayId != Display.DEFAULT_DISPLAY) { |
| 2224 | final int newDynamicStackId = getNextStackId(); |
Andrii Kulian | 036e3ad | 2017-04-19 10:55:10 -0700 | [diff] [blame] | 2225 | if (mService.mActivityStarter.isValidLaunchStackId(newDynamicStackId, displayId, r)) { |
Andrii Kulian | 16802aa | 2016-11-02 12:21:33 -0700 | [diff] [blame] | 2226 | return createStackOnDisplay(newDynamicStackId, displayId, true /*onTop*/); |
| 2227 | } |
| 2228 | } |
| 2229 | |
| 2230 | Slog.w(TAG, "getValidLaunchStackOnDisplay: can't launch on displayId " + displayId); |
| 2231 | return null; |
| 2232 | } |
| 2233 | |
Craig Mautner | 967212c | 2013-04-13 21:10:58 -0700 | [diff] [blame] | 2234 | ArrayList<ActivityStack> getStacks() { |
Wale Ogunwale | 3797c22 | 2015-10-27 14:21:58 -0700 | [diff] [blame] | 2235 | ArrayList<ActivityStack> allStacks = new ArrayList<>(); |
Craig Mautner | e0a3884 | 2013-12-16 16:14:02 -0800 | [diff] [blame] | 2236 | for (int displayNdx = mActivityDisplays.size() - 1; displayNdx >= 0; --displayNdx) { |
| 2237 | allStacks.addAll(mActivityDisplays.valueAt(displayNdx).mStacks); |
Craig Mautner | 4a1cb22 | 2013-12-04 16:14:06 -0800 | [diff] [blame] | 2238 | } |
| 2239 | return allStacks; |
Craig Mautner | 967212c | 2013-04-13 21:10:58 -0700 | [diff] [blame] | 2240 | } |
| 2241 | |
Jorim Jaggi | fe76234 | 2016-10-13 14:33:27 +0200 | [diff] [blame] | 2242 | ArrayList<ActivityStack> getStacksOnDefaultDisplay() { |
| 2243 | return mActivityDisplays.valueAt(DEFAULT_DISPLAY).mStacks; |
| 2244 | } |
| 2245 | |
Andrii Kulian | 7fc2281 | 2016-12-28 13:04:11 -0800 | [diff] [blame] | 2246 | /** |
| 2247 | * Get next focusable stack in the system. This will search across displays and stacks |
| 2248 | * in last-focused order for a focusable and visible stack, different from the target stack. |
| 2249 | * |
| 2250 | * @param currentFocus The stack that previously had focus and thus needs to be ignored when |
| 2251 | * searching for next candidate. |
| 2252 | * @return Next focusable {@link ActivityStack}, null if not found. |
| 2253 | */ |
| 2254 | ActivityStack getNextFocusableStackLocked(ActivityStack currentFocus) { |
| 2255 | mWindowManager.getDisplaysInFocusOrder(mTmpOrderedDisplayIds); |
| 2256 | |
| 2257 | for (int i = mTmpOrderedDisplayIds.size() - 1; i >= 0; --i) { |
| 2258 | final int displayId = mTmpOrderedDisplayIds.get(i); |
Andrii Kulian | 62e6f25 | 2017-05-30 22:46:53 -0700 | [diff] [blame] | 2259 | // If a display is registered in WM, it must also be available in AM. |
| 2260 | @SuppressWarnings("ConstantConditions") |
| 2261 | final List<ActivityStack> stacks = getActivityDisplayOrCreateLocked(displayId).mStacks; |
Andrii Kulian | 7fc2281 | 2016-12-28 13:04:11 -0800 | [diff] [blame] | 2262 | for (int j = stacks.size() - 1; j >= 0; --j) { |
| 2263 | final ActivityStack stack = stacks.get(j); |
| 2264 | if (stack != currentFocus && stack.isFocusable() |
Wale Ogunwale | cd501ec | 2017-04-07 08:53:41 -0700 | [diff] [blame] | 2265 | && stack.shouldBeVisible(null) != STACK_INVISIBLE) { |
Andrii Kulian | 7fc2281 | 2016-12-28 13:04:11 -0800 | [diff] [blame] | 2266 | return stack; |
| 2267 | } |
| 2268 | } |
| 2269 | } |
| 2270 | |
| 2271 | return null; |
| 2272 | } |
| 2273 | |
Andrii Kulian | a8fe3df | 2017-06-16 15:29:26 -0700 | [diff] [blame] | 2274 | /** |
| 2275 | * Get next valid stack for launching provided activity in the system. This will search across |
| 2276 | * displays and stacks in last-focused order for a focusable and visible stack, except those |
| 2277 | * that are on a currently focused display. |
| 2278 | * |
| 2279 | * @param r The activity that is being launched. |
| 2280 | * @param currentFocus The display that previously had focus and thus needs to be ignored when |
| 2281 | * searching for the next candidate. |
| 2282 | * @return Next valid {@link ActivityStack}, null if not found. |
| 2283 | */ |
| 2284 | ActivityStack getNextValidLaunchStackLocked(@NonNull ActivityRecord r, int currentFocus) { |
| 2285 | mWindowManager.getDisplaysInFocusOrder(mTmpOrderedDisplayIds); |
| 2286 | for (int i = mTmpOrderedDisplayIds.size() - 1; i >= 0; --i) { |
| 2287 | final int displayId = mTmpOrderedDisplayIds.get(i); |
| 2288 | if (displayId == currentFocus) { |
| 2289 | continue; |
| 2290 | } |
| 2291 | final ActivityStack stack = getValidLaunchStackOnDisplay(displayId, r); |
| 2292 | if (stack != null) { |
| 2293 | return stack; |
| 2294 | } |
| 2295 | } |
| 2296 | return null; |
| 2297 | } |
| 2298 | |
Craig Mautner | ee2e45a | 2014-06-27 12:10:03 -0700 | [diff] [blame] | 2299 | ActivityRecord getHomeActivity() { |
Craig Mautner | db49fec | 2015-05-21 15:33:30 -0700 | [diff] [blame] | 2300 | return getHomeActivityForUser(mCurrentUser); |
Fyodor Kupolov | b501330 | 2015-04-17 17:59:14 -0700 | [diff] [blame] | 2301 | } |
| 2302 | |
| 2303 | ActivityRecord getHomeActivityForUser(int userId) { |
Craig Mautner | 4a1cb22 | 2013-12-04 16:14:06 -0800 | [diff] [blame] | 2304 | final ArrayList<TaskRecord> tasks = mHomeStack.getAllTasks(); |
| 2305 | for (int taskNdx = tasks.size() - 1; taskNdx >= 0; --taskNdx) { |
| 2306 | final TaskRecord task = tasks.get(taskNdx); |
| 2307 | if (task.isHomeTask()) { |
| 2308 | final ArrayList<ActivityRecord> activities = task.mActivities; |
| 2309 | for (int activityNdx = activities.size() - 1; activityNdx >= 0; --activityNdx) { |
| 2310 | final ActivityRecord r = activities.get(activityNdx); |
Fyodor Kupolov | b501330 | 2015-04-17 17:59:14 -0700 | [diff] [blame] | 2311 | if (r.isHomeActivity() |
| 2312 | && ((userId == UserHandle.USER_ALL) || (r.userId == userId))) { |
Craig Mautner | ee2e45a | 2014-06-27 12:10:03 -0700 | [diff] [blame] | 2313 | return r; |
Craig Mautner | 4a1cb22 | 2013-12-04 16:14:06 -0800 | [diff] [blame] | 2314 | } |
| 2315 | } |
| 2316 | } |
| 2317 | } |
| 2318 | return null; |
| 2319 | } |
| 2320 | |
Chong Zhang | b15758a | 2015-11-17 12:12:03 -0800 | [diff] [blame] | 2321 | /** |
| 2322 | * Returns if a stack should be treated as if it's docked. Returns true if the stack is |
| 2323 | * the docked stack itself, or if it's side-by-side to the docked stack. |
| 2324 | */ |
| 2325 | boolean isStackDockedInEffect(int stackId) { |
| 2326 | return stackId == DOCKED_STACK_ID || |
| 2327 | (StackId.isResizeableByDockedStack(stackId) && getStack(DOCKED_STACK_ID) != null); |
| 2328 | } |
| 2329 | |
Todd Kennedy | ca4d842 | 2015-01-15 15:19:22 -0800 | [diff] [blame] | 2330 | ActivityContainer createVirtualActivityContainer(ActivityRecord parentActivity, |
Craig Mautner | 4a1cb22 | 2013-12-04 16:14:06 -0800 | [diff] [blame] | 2331 | IActivityContainerCallback callback) { |
Craig Mautner | d163e75 | 2014-06-13 17:18:47 -0700 | [diff] [blame] | 2332 | ActivityContainer activityContainer = |
| 2333 | new VirtualActivityContainer(parentActivity, callback); |
Craig Mautner | f4c909b | 2014-04-17 18:39:38 -0700 | [diff] [blame] | 2334 | mActivityContainers.put(activityContainer.mStackId, activityContainer); |
Wale Ogunwale | 0fc365c | 2015-05-25 19:35:42 -0700 | [diff] [blame] | 2335 | if (DEBUG_CONTAINERS) Slog.d(TAG_CONTAINERS, |
| 2336 | "createActivityContainer: " + activityContainer); |
Craig Mautner | f4c909b | 2014-04-17 18:39:38 -0700 | [diff] [blame] | 2337 | parentActivity.mChildContainers.add(activityContainer); |
Craig Mautner | 4a1cb22 | 2013-12-04 16:14:06 -0800 | [diff] [blame] | 2338 | return activityContainer; |
| 2339 | } |
| 2340 | |
Craig Mautner | 34b73df | 2014-01-12 21:11:08 -0800 | [diff] [blame] | 2341 | void removeChildActivityContainers(ActivityRecord parentActivity) { |
Craig Mautner | f4c909b | 2014-04-17 18:39:38 -0700 | [diff] [blame] | 2342 | final ArrayList<ActivityContainer> childStacks = parentActivity.mChildContainers; |
| 2343 | for (int containerNdx = childStacks.size() - 1; containerNdx >= 0; --containerNdx) { |
| 2344 | ActivityContainer container = childStacks.remove(containerNdx); |
Wale Ogunwale | 0fc365c | 2015-05-25 19:35:42 -0700 | [diff] [blame] | 2345 | if (DEBUG_CONTAINERS) Slog.d(TAG_CONTAINERS, "removeChildActivityContainers: removing " |
| 2346 | + container); |
Craig Mautner | f4c909b | 2014-04-17 18:39:38 -0700 | [diff] [blame] | 2347 | container.release(); |
Craig Mautner | 34b73df | 2014-01-12 21:11:08 -0800 | [diff] [blame] | 2348 | } |
| 2349 | } |
| 2350 | |
Andrii Kulian | 6d6fb40 | 2016-10-26 16:15:25 -0700 | [diff] [blame] | 2351 | void deleteActivityContainerRecord(int stackId) { |
| 2352 | if (DEBUG_CONTAINERS) Slog.d(TAG_CONTAINERS, |
| 2353 | "deleteActivityContainerRecord: callers=" + Debug.getCallers(4)); |
| 2354 | mActivityContainers.remove(stackId); |
Craig Mautner | 95da108 | 2014-02-24 17:54:35 -0800 | [diff] [blame] | 2355 | } |
| 2356 | |
Jorim Jaggi | dc249c4 | 2015-12-15 14:57:31 -0800 | [diff] [blame] | 2357 | void resizeStackLocked(int stackId, Rect bounds, Rect tempTaskBounds, Rect tempTaskInsetBounds, |
Wale Ogunwale | c8da41e | 2016-04-16 13:27:23 -0700 | [diff] [blame] | 2358 | boolean preserveWindows, boolean allowResizeInDockedMode, boolean deferResume) { |
Jorim Jaggi | dc249c4 | 2015-12-15 14:57:31 -0800 | [diff] [blame] | 2359 | if (stackId == DOCKED_STACK_ID) { |
| 2360 | resizeDockedStackLocked(bounds, tempTaskBounds, tempTaskInsetBounds, null, null, |
Andrii Kulian | db3e4ec | 2016-07-12 17:11:35 -0700 | [diff] [blame] | 2361 | preserveWindows, deferResume); |
Jorim Jaggi | dc249c4 | 2015-12-15 14:57:31 -0800 | [diff] [blame] | 2362 | return; |
| 2363 | } |
Wale Ogunwale | 60454db | 2015-01-23 16:05:07 -0800 | [diff] [blame] | 2364 | final ActivityStack stack = getStack(stackId); |
| 2365 | if (stack == null) { |
| 2366 | Slog.w(TAG, "resizeStack: stackId " + stackId + " not found."); |
| 2367 | return; |
| 2368 | } |
Wale Ogunwale | 9d3de4c | 2015-02-01 16:49:44 -0800 | [diff] [blame] | 2369 | |
Winson Chung | a2249ac | 2017-03-30 18:15:30 -0700 | [diff] [blame] | 2370 | if (!allowResizeInDockedMode && !StackId.tasksAreFloating(stackId) && |
| 2371 | getStack(DOCKED_STACK_ID) != null) { |
| 2372 | // If the docked stack exists, don't resize non-floating stacks independently of the |
| 2373 | // 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] | 2374 | return; |
| 2375 | } |
| 2376 | |
Wale Ogunwale | cad05a0 | 2015-09-25 10:41:44 -0700 | [diff] [blame] | 2377 | Trace.traceBegin(TRACE_TAG_ACTIVITY_MANAGER, "am.resizeStack_" + stackId); |
Jorim Jaggi | c402520 | 2015-10-22 16:43:34 +0200 | [diff] [blame] | 2378 | mWindowManager.deferSurfaceLayout(); |
| 2379 | try { |
Wale Ogunwale | 1666e31 | 2016-12-16 11:27:18 -0800 | [diff] [blame] | 2380 | stack.resize(bounds, tempTaskBounds, tempTaskInsetBounds); |
Wale Ogunwale | c8da41e | 2016-04-16 13:27:23 -0700 | [diff] [blame] | 2381 | if (!deferResume) { |
Wale Ogunwale | db0fa12 | 2016-05-16 15:12:03 -0700 | [diff] [blame] | 2382 | stack.ensureVisibleActivitiesConfigurationLocked( |
| 2383 | stack.topRunningActivityLocked(), preserveWindows); |
Wale Ogunwale | c8da41e | 2016-04-16 13:27:23 -0700 | [diff] [blame] | 2384 | } |
Jorim Jaggi | c402520 | 2015-10-22 16:43:34 +0200 | [diff] [blame] | 2385 | } finally { |
| 2386 | mWindowManager.continueSurfaceLayout(); |
| 2387 | Trace.traceEnd(TRACE_TAG_ACTIVITY_MANAGER); |
Wale Ogunwale | e4a0c57 | 2015-06-30 08:40:31 -0700 | [diff] [blame] | 2388 | } |
| 2389 | } |
| 2390 | |
Jorim Jaggi | 192086e | 2016-03-11 17:17:03 +0100 | [diff] [blame] | 2391 | void deferUpdateBounds(int stackId) { |
| 2392 | final ActivityStack stack = getStack(stackId); |
| 2393 | if (stack != null) { |
| 2394 | stack.deferUpdateBounds(); |
| 2395 | } |
| 2396 | } |
| 2397 | |
| 2398 | void continueUpdateBounds(int stackId) { |
| 2399 | final ActivityStack stack = getStack(stackId); |
| 2400 | if (stack != null) { |
| 2401 | stack.continueUpdateBounds(); |
| 2402 | } |
| 2403 | } |
| 2404 | |
Jorim Jaggi | 0b46f3c | 2016-03-14 12:21:37 +0100 | [diff] [blame] | 2405 | void notifyAppTransitionDone() { |
Matthew Ng | 606dd80 | 2017-06-05 14:06:32 -0700 | [diff] [blame] | 2406 | continueUpdateBounds(RECENTS_STACK_ID); |
Jorim Jaggi | 0b46f3c | 2016-03-14 12:21:37 +0100 | [diff] [blame] | 2407 | for (int i = mResizingTasksDuringAnimation.size() - 1; i >= 0; i--) { |
| 2408 | final int taskId = mResizingTasksDuringAnimation.valueAt(i); |
Wale Ogunwale | e1fe7fa2 | 2016-12-15 18:27:00 -0800 | [diff] [blame] | 2409 | final TaskRecord task = |
Winson Chung | 7900bee | 2017-03-10 08:59:25 -0800 | [diff] [blame] | 2410 | anyTaskForIdLocked(taskId, MATCH_TASK_IN_STACKS_ONLY, INVALID_STACK_ID); |
Wale Ogunwale | e1fe7fa2 | 2016-12-15 18:27:00 -0800 | [diff] [blame] | 2411 | if (task != null) { |
| 2412 | task.setTaskDockedResizing(false); |
Jorim Jaggi | 0b46f3c | 2016-03-14 12:21:37 +0100 | [diff] [blame] | 2413 | } |
| 2414 | } |
| 2415 | mResizingTasksDuringAnimation.clear(); |
| 2416 | } |
| 2417 | |
Robert Carr | e7cc44d | 2017-03-20 19:04:30 -0700 | [diff] [blame] | 2418 | private void moveTasksToFullscreenStackInSurfaceTransaction(int fromStackId, |
| 2419 | boolean onTop) { |
Robert Carr | 6914f08 | 2017-03-20 19:04:30 -0700 | [diff] [blame] | 2420 | |
Wale Ogunwale | c8da41e | 2016-04-16 13:27:23 -0700 | [diff] [blame] | 2421 | final ActivityStack stack = getStack(fromStackId); |
| 2422 | if (stack == null) { |
| 2423 | return; |
| 2424 | } |
| 2425 | |
| 2426 | mWindowManager.deferSurfaceLayout(); |
| 2427 | try { |
| 2428 | if (fromStackId == DOCKED_STACK_ID) { |
Wale Ogunwale | c8da41e | 2016-04-16 13:27:23 -0700 | [diff] [blame] | 2429 | // We are moving all tasks from the docked stack to the fullscreen stack, |
| 2430 | // which is dismissing the docked stack, so resize all other stacks to |
| 2431 | // fullscreen here already so we don't end up with resize trashing. |
| 2432 | for (int i = FIRST_STATIC_STACK_ID; i <= LAST_STATIC_STACK_ID; i++) { |
| 2433 | if (StackId.isResizeableByDockedStack(i)) { |
| 2434 | ActivityStack otherStack = getStack(i); |
| 2435 | if (otherStack != null) { |
| 2436 | resizeStackLocked(i, null, null, null, PRESERVE_WINDOWS, |
| 2437 | true /* allowResizeInDockedMode */, DEFER_RESUME); |
| 2438 | } |
| 2439 | } |
| 2440 | } |
| 2441 | |
| 2442 | // Also disable docked stack resizing since we have manually adjusted the |
| 2443 | // size of other stacks above and we don't want to trigger a docked stack |
| 2444 | // resize when we remove task from it below and it is detached from the |
| 2445 | // display because it no longer contains any tasks. |
| 2446 | mAllowDockedStackResize = false; |
Winson Chung | 4790065 | 2017-04-06 18:44:25 -0700 | [diff] [blame] | 2447 | } else if (fromStackId == PINNED_STACK_ID) { |
| 2448 | if (onTop) { |
| 2449 | // Log if we are expanding the PiP to fullscreen |
| 2450 | MetricsLogger.action(mService.mContext, |
| 2451 | ACTION_PICTURE_IN_PICTURE_EXPANDED_TO_FULLSCREEN); |
| 2452 | } |
Wale Ogunwale | c8da41e | 2016-04-16 13:27:23 -0700 | [diff] [blame] | 2453 | } |
Wale Ogunwale | e1fe7fa2 | 2016-12-15 18:27:00 -0800 | [diff] [blame] | 2454 | ActivityStack fullscreenStack = getStack(FULLSCREEN_WORKSPACE_STACK_ID); |
Winson Chung | c85d9ce | 2017-01-03 11:59:52 -0800 | [diff] [blame] | 2455 | final boolean isFullscreenStackVisible = fullscreenStack != null && |
Wale Ogunwale | cd501ec | 2017-04-07 08:53:41 -0700 | [diff] [blame] | 2456 | fullscreenStack.shouldBeVisible(null) == STACK_VISIBLE; |
Winson Chung | 5af42fc | 2017-03-24 17:11:33 -0700 | [diff] [blame] | 2457 | // If we are moving from the pinned stack, then the animation takes care of updating |
| 2458 | // the picture-in-picture mode. |
Winson Chung | 4790065 | 2017-04-06 18:44:25 -0700 | [diff] [blame] | 2459 | final boolean schedulePictureInPictureModeChange = (fromStackId == PINNED_STACK_ID); |
Wale Ogunwale | c8da41e | 2016-04-16 13:27:23 -0700 | [diff] [blame] | 2460 | final ArrayList<TaskRecord> tasks = stack.getAllTasks(); |
| 2461 | final int size = tasks.size(); |
| 2462 | if (onTop) { |
| 2463 | for (int i = 0; i < size; i++) { |
Winson Chung | 0c1ca09 | 2016-11-10 17:40:34 -0800 | [diff] [blame] | 2464 | final TaskRecord task = tasks.get(i); |
Winson Chung | 7466610 | 2017-02-22 17:49:24 -0800 | [diff] [blame] | 2465 | final boolean isTopTask = i == (size - 1); |
Winson Chung | 0c1ca09 | 2016-11-10 17:40:34 -0800 | [diff] [blame] | 2466 | if (fromStackId == PINNED_STACK_ID) { |
| 2467 | // Update the return-to to reflect where the pinned stack task was moved |
| 2468 | // from so that we retain the stack that was previously visible if the |
| 2469 | // pinned stack is recreated. See moveActivityToPinnedStackLocked(). |
Winson Chung | c85d9ce | 2017-01-03 11:59:52 -0800 | [diff] [blame] | 2470 | task.setTaskToReturnTo(isFullscreenStackVisible && onTop ? |
| 2471 | APPLICATION_ACTIVITY_TYPE : HOME_ACTIVITY_TYPE); |
Winson Chung | 0c1ca09 | 2016-11-10 17:40:34 -0800 | [diff] [blame] | 2472 | } |
Winson Chung | 7466610 | 2017-02-22 17:49:24 -0800 | [diff] [blame] | 2473 | // Defer resume until all the tasks have been moved to the fullscreen stack |
| 2474 | task.reparent(FULLSCREEN_WORKSPACE_STACK_ID, ON_TOP, |
| 2475 | REPARENT_MOVE_STACK_TO_FRONT, isTopTask /* animate */, DEFER_RESUME, |
Winson Chung | 5af42fc | 2017-03-24 17:11:33 -0700 | [diff] [blame] | 2476 | schedulePictureInPictureModeChange, |
Winson Chung | 7466610 | 2017-02-22 17:49:24 -0800 | [diff] [blame] | 2477 | "moveTasksToFullscreenStack - onTop"); |
Wale Ogunwale | c8da41e | 2016-04-16 13:27:23 -0700 | [diff] [blame] | 2478 | } |
| 2479 | } else { |
Wale Ogunwale | e1fe7fa2 | 2016-12-15 18:27:00 -0800 | [diff] [blame] | 2480 | for (int i = 0; i < size; i++) { |
Wale Ogunwale | c5cc301 | 2017-01-13 13:26:16 -0800 | [diff] [blame] | 2481 | final TaskRecord task = tasks.get(i); |
Winson Chung | 3a64998 | 2017-04-19 10:16:17 -0700 | [diff] [blame] | 2482 | // Position the tasks in the fullscreen stack in order at the bottom of the |
| 2483 | // stack. Also defer resume until all the tasks have been moved to the |
| 2484 | // fullscreen stack. |
| 2485 | task.reparent(FULLSCREEN_WORKSPACE_STACK_ID, i /* position */, |
Winson Chung | 5af42fc | 2017-03-24 17:11:33 -0700 | [diff] [blame] | 2486 | REPARENT_LEAVE_STACK_IN_PLACE, !ANIMATE, DEFER_RESUME, |
| 2487 | schedulePictureInPictureModeChange, |
| 2488 | "moveTasksToFullscreenStack - NOT_onTop"); |
Wale Ogunwale | c8da41e | 2016-04-16 13:27:23 -0700 | [diff] [blame] | 2489 | } |
| 2490 | } |
Winson Chung | 7466610 | 2017-02-22 17:49:24 -0800 | [diff] [blame] | 2491 | |
| 2492 | ensureActivitiesVisibleLocked(null, 0, PRESERVE_WINDOWS); |
| 2493 | resumeFocusedStackTopActivityLocked(); |
Wale Ogunwale | c8da41e | 2016-04-16 13:27:23 -0700 | [diff] [blame] | 2494 | } finally { |
| 2495 | mAllowDockedStackResize = true; |
| 2496 | mWindowManager.continueSurfaceLayout(); |
| 2497 | } |
| 2498 | } |
| 2499 | |
Robert Carr | 6914f08 | 2017-03-20 19:04:30 -0700 | [diff] [blame] | 2500 | void moveTasksToFullscreenStackLocked(int fromStackId, boolean onTop) { |
Robert Carr | e7cc44d | 2017-03-20 19:04:30 -0700 | [diff] [blame] | 2501 | mWindowManager.inSurfaceTransaction( |
| 2502 | () -> moveTasksToFullscreenStackInSurfaceTransaction(fromStackId, onTop)); |
Robert Carr | 6914f08 | 2017-03-20 19:04:30 -0700 | [diff] [blame] | 2503 | } |
| 2504 | |
Jorim Jaggi | dc249c4 | 2015-12-15 14:57:31 -0800 | [diff] [blame] | 2505 | void resizeDockedStackLocked(Rect dockedBounds, Rect tempDockedTaskBounds, |
Andrii Kulian | db3e4ec | 2016-07-12 17:11:35 -0700 | [diff] [blame] | 2506 | Rect tempDockedTaskInsetBounds, Rect tempOtherTaskBounds, Rect tempOtherTaskInsetBounds, |
| 2507 | boolean preserveWindows) { |
| 2508 | resizeDockedStackLocked(dockedBounds, tempDockedTaskBounds, tempDockedTaskInsetBounds, |
| 2509 | tempOtherTaskBounds, tempOtherTaskInsetBounds, preserveWindows, |
| 2510 | false /* deferResume */); |
| 2511 | } |
| 2512 | |
| 2513 | void resizeDockedStackLocked(Rect dockedBounds, Rect tempDockedTaskBounds, |
| 2514 | Rect tempDockedTaskInsetBounds, Rect tempOtherTaskBounds, Rect tempOtherTaskInsetBounds, |
| 2515 | boolean preserveWindows, boolean deferResume) { |
Wale Ogunwale | c8da41e | 2016-04-16 13:27:23 -0700 | [diff] [blame] | 2516 | |
| 2517 | if (!mAllowDockedStackResize) { |
| 2518 | // Docked stack resize currently disabled. |
| 2519 | return; |
| 2520 | } |
| 2521 | |
Jorim Jaggi | dc249c4 | 2015-12-15 14:57:31 -0800 | [diff] [blame] | 2522 | final ActivityStack stack = getStack(DOCKED_STACK_ID); |
| 2523 | if (stack == null) { |
| 2524 | Slog.w(TAG, "resizeDockedStackLocked: docked stack not found"); |
| 2525 | return; |
| 2526 | } |
| 2527 | |
| 2528 | Trace.traceBegin(TRACE_TAG_ACTIVITY_MANAGER, "am.resizeDockedStack"); |
| 2529 | mWindowManager.deferSurfaceLayout(); |
| 2530 | try { |
Wale Ogunwale | c8da41e | 2016-04-16 13:27:23 -0700 | [diff] [blame] | 2531 | // Don't allow re-entry while resizing. E.g. due to docked stack detaching. |
| 2532 | mAllowDockedStackResize = false; |
Jorim Jaggi | dc249c4 | 2015-12-15 14:57:31 -0800 | [diff] [blame] | 2533 | ActivityRecord r = stack.topRunningActivityLocked(); |
Wale Ogunwale | 1666e31 | 2016-12-16 11:27:18 -0800 | [diff] [blame] | 2534 | stack.resize(dockedBounds, tempDockedTaskBounds, tempDockedTaskInsetBounds); |
Jorim Jaggi | dc249c4 | 2015-12-15 14:57:31 -0800 | [diff] [blame] | 2535 | |
Andrii Kulian | 69fb5e4 | 2016-04-05 16:47:29 -0700 | [diff] [blame] | 2536 | // TODO: Checking for isAttached might not be needed as if the user passes in null |
| 2537 | // dockedBounds then they want the docked stack to be dismissed. |
| 2538 | if (stack.mFullscreen || (dockedBounds == null && !stack.isAttached())) { |
| 2539 | // 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] | 2540 | // In this case we make all other static stacks fullscreen and move all |
| 2541 | // docked stack tasks to the fullscreen stack. |
Wale Ogunwale | c8da41e | 2016-04-16 13:27:23 -0700 | [diff] [blame] | 2542 | moveTasksToFullscreenStackLocked(DOCKED_STACK_ID, ON_TOP); |
Jorim Jaggi | dc249c4 | 2015-12-15 14:57:31 -0800 | [diff] [blame] | 2543 | |
| 2544 | // stack shouldn't contain anymore activities, so nothing to resume. |
| 2545 | r = null; |
| 2546 | } else { |
| 2547 | // Docked stacks occupy a dedicated region on screen so the size of all other |
| 2548 | // static stacks need to be adjusted so they don't overlap with the docked stack. |
| 2549 | // We get the bounds to use from window manager which has been adjusted for any |
| 2550 | // screen controls and is also the same for all stacks. |
Matthew Ng | aa2b620 | 2017-02-10 14:48:21 -0800 | [diff] [blame] | 2551 | final Rect otherTaskRect = new Rect(); |
Jorim Jaggi | dc249c4 | 2015-12-15 14:57:31 -0800 | [diff] [blame] | 2552 | for (int i = FIRST_STATIC_STACK_ID; i <= LAST_STATIC_STACK_ID; i++) { |
Wale Ogunwale | 1666e31 | 2016-12-16 11:27:18 -0800 | [diff] [blame] | 2553 | final ActivityStack current = getStack(i); |
| 2554 | if (current != null && StackId.isResizeableByDockedStack(i)) { |
Matthew Ng | aa2b620 | 2017-02-10 14:48:21 -0800 | [diff] [blame] | 2555 | current.getStackDockedModeBounds( |
| 2556 | tempOtherTaskBounds /* currentTempTaskBounds */, |
| 2557 | tempRect /* outStackBounds */, |
| 2558 | otherTaskRect /* outTempTaskBounds */, true /* ignoreVisibility */); |
| 2559 | |
Andrii Kulian | e48b7d8 | 2017-04-28 14:51:05 -0700 | [diff] [blame] | 2560 | resizeStackLocked(i, !tempRect.isEmpty() ? tempRect : null, |
Matthew Ng | aa2b620 | 2017-02-10 14:48:21 -0800 | [diff] [blame] | 2561 | !otherTaskRect.isEmpty() ? otherTaskRect : tempOtherTaskBounds, |
| 2562 | tempOtherTaskInsetBounds, preserveWindows, |
| 2563 | true /* allowResizeInDockedMode */, deferResume); |
Jorim Jaggi | dc249c4 | 2015-12-15 14:57:31 -0800 | [diff] [blame] | 2564 | } |
| 2565 | } |
| 2566 | } |
Andrii Kulian | db3e4ec | 2016-07-12 17:11:35 -0700 | [diff] [blame] | 2567 | if (!deferResume) { |
| 2568 | stack.ensureVisibleActivitiesConfigurationLocked(r, preserveWindows); |
| 2569 | } |
Jorim Jaggi | dc249c4 | 2015-12-15 14:57:31 -0800 | [diff] [blame] | 2570 | } finally { |
Wale Ogunwale | c8da41e | 2016-04-16 13:27:23 -0700 | [diff] [blame] | 2571 | mAllowDockedStackResize = true; |
Jorim Jaggi | dc249c4 | 2015-12-15 14:57:31 -0800 | [diff] [blame] | 2572 | mWindowManager.continueSurfaceLayout(); |
| 2573 | Trace.traceEnd(TRACE_TAG_ACTIVITY_MANAGER); |
| 2574 | } |
Jorim Jaggi | dc249c4 | 2015-12-15 14:57:31 -0800 | [diff] [blame] | 2575 | } |
| 2576 | |
Robert Carr | 0d00c2e | 2016-02-29 17:45:02 -0800 | [diff] [blame] | 2577 | void resizePinnedStackLocked(Rect pinnedBounds, Rect tempPinnedTaskBounds) { |
Winson Chung | 19953ca | 2017-04-11 11:19:23 -0700 | [diff] [blame] | 2578 | final PinnedActivityStack stack = getStack(PINNED_STACK_ID); |
Robert Carr | 0d00c2e | 2016-02-29 17:45:02 -0800 | [diff] [blame] | 2579 | if (stack == null) { |
| 2580 | Slog.w(TAG, "resizePinnedStackLocked: pinned stack not found"); |
| 2581 | return; |
| 2582 | } |
Winson Chung | 19953ca | 2017-04-11 11:19:23 -0700 | [diff] [blame] | 2583 | |
| 2584 | // It is possible for the bounds animation from the WM to call this but be delayed by |
| 2585 | // another AM call that is holding the AMS lock. In such a case, the pinnedBounds may be |
| 2586 | // incorrect if AMS.resizeStackWithBoundsFromWindowManager() is already called while waiting |
| 2587 | // for the AMS lock to be freed. So check and make sure these bounds are still good. |
| 2588 | final PinnedStackWindowController stackController = stack.getWindowContainerController(); |
Winson Chung | 8bca9e4 | 2017-04-16 15:59:43 -0700 | [diff] [blame] | 2589 | if (stackController.pinnedStackResizeDisallowed()) { |
Winson Chung | 19953ca | 2017-04-11 11:19:23 -0700 | [diff] [blame] | 2590 | return; |
| 2591 | } |
| 2592 | |
Robert Carr | 0d00c2e | 2016-02-29 17:45:02 -0800 | [diff] [blame] | 2593 | Trace.traceBegin(TRACE_TAG_ACTIVITY_MANAGER, "am.resizePinnedStack"); |
| 2594 | mWindowManager.deferSurfaceLayout(); |
| 2595 | try { |
| 2596 | ActivityRecord r = stack.topRunningActivityLocked(); |
Robert Carr | 7e4c90e | 2017-02-15 19:52:38 -0800 | [diff] [blame] | 2597 | Rect insetBounds = null; |
| 2598 | if (tempPinnedTaskBounds != null) { |
| 2599 | // We always use 0,0 as the position for the inset rect because |
| 2600 | // if we are getting insets at all in the pinned stack it must mean |
| 2601 | // we are headed for fullscreen. |
| 2602 | insetBounds = tempRect; |
| 2603 | insetBounds.top = 0; |
| 2604 | insetBounds.left = 0; |
| 2605 | insetBounds.right = tempPinnedTaskBounds.width(); |
| 2606 | insetBounds.bottom = tempPinnedTaskBounds.height(); |
| 2607 | } |
| 2608 | stack.resize(pinnedBounds, tempPinnedTaskBounds, insetBounds); |
Wale Ogunwale | db0fa12 | 2016-05-16 15:12:03 -0700 | [diff] [blame] | 2609 | stack.ensureVisibleActivitiesConfigurationLocked(r, false); |
Robert Carr | 0d00c2e | 2016-02-29 17:45:02 -0800 | [diff] [blame] | 2610 | } finally { |
| 2611 | mWindowManager.continueSurfaceLayout(); |
| 2612 | Trace.traceEnd(TRACE_TAG_ACTIVITY_MANAGER); |
| 2613 | } |
| 2614 | } |
| 2615 | |
Wale Ogunwale | ddc1cb2 | 2015-07-25 19:23:04 -0700 | [diff] [blame] | 2616 | ActivityStack createStackOnDisplay(int stackId, int displayId, boolean onTop) { |
Andrii Kulian | 62e6f25 | 2017-05-30 22:46:53 -0700 | [diff] [blame] | 2617 | final ActivityDisplay activityDisplay = getActivityDisplayOrCreateLocked(displayId); |
Craig Mautner | e0a3884 | 2013-12-16 16:14:02 -0800 | [diff] [blame] | 2618 | if (activityDisplay == null) { |
Todd Kennedy | 4900bf9 | 2015-01-16 16:05:14 -0800 | [diff] [blame] | 2619 | return null; |
Craig Mautner | 4a1cb22 | 2013-12-04 16:14:06 -0800 | [diff] [blame] | 2620 | } |
| 2621 | |
Wale Ogunwale | 1666e31 | 2016-12-16 11:27:18 -0800 | [diff] [blame] | 2622 | final ActivityContainer activityContainer = |
| 2623 | new ActivityContainer(stackId, activityDisplay, onTop); |
Todd Kennedy | 4900bf9 | 2015-01-16 16:05:14 -0800 | [diff] [blame] | 2624 | return activityContainer.mStack; |
Craig Mautner | 4a1cb22 | 2013-12-04 16:14:06 -0800 | [diff] [blame] | 2625 | } |
| 2626 | |
Robert Carr | 6914f08 | 2017-03-20 19:04:30 -0700 | [diff] [blame] | 2627 | |
Robert Carr | e7cc44d | 2017-03-20 19:04:30 -0700 | [diff] [blame] | 2628 | void removeStackInSurfaceTransaction(int stackId) { |
Winson Chung | 010927a | 2016-12-15 16:12:35 -0800 | [diff] [blame] | 2629 | final ActivityStack stack = getStack(stackId); |
| 2630 | if (stack == null) { |
| 2631 | return; |
| 2632 | } |
| 2633 | |
| 2634 | final ArrayList<TaskRecord> tasks = stack.getAllTasks(); |
| 2635 | if (stack.getStackId() == PINNED_STACK_ID) { |
Winson Chung | 4790065 | 2017-04-06 18:44:25 -0700 | [diff] [blame] | 2636 | /** |
| 2637 | * Workaround: Force-stop all the activities in the pinned stack before we reparent them |
| 2638 | * to the fullscreen stack. This is to guarantee that when we are removing a stack, |
| 2639 | * that the client receives onStop() before it is reparented. We do this by detaching |
| 2640 | * the stack from the display so that it will be considered invisible when |
| 2641 | * ensureActivitiesVisibleLocked() is called, and all of its activitys will be marked |
| 2642 | * invisible as well and added to the stopping list. After which we process the |
| 2643 | * stopping list by handling the idle. |
| 2644 | */ |
| 2645 | final PinnedActivityStack pinnedStack = (PinnedActivityStack) stack; |
| 2646 | pinnedStack.mForceHidden = true; |
| 2647 | pinnedStack.ensureActivitiesVisibleLocked(null, 0, PRESERVE_WINDOWS); |
| 2648 | pinnedStack.mForceHidden = false; |
| 2649 | activityIdleInternalLocked(null, false /* fromTimeout */, |
| 2650 | true /* processPausingActivites */, null /* configuration */); |
| 2651 | |
| 2652 | // Move all the tasks to the bottom of the fullscreen stack |
| 2653 | moveTasksToFullscreenStackLocked(PINNED_STACK_ID, !ON_TOP); |
Winson Chung | 010927a | 2016-12-15 16:12:35 -0800 | [diff] [blame] | 2654 | } else { |
| 2655 | for (int i = tasks.size() - 1; i >= 0; i--) { |
| 2656 | removeTaskByIdLocked(tasks.get(i).taskId, true /* killProcess */, |
| 2657 | REMOVE_FROM_RECENTS); |
| 2658 | } |
| 2659 | } |
| 2660 | } |
| 2661 | |
| 2662 | /** |
Robert Carr | 6914f08 | 2017-03-20 19:04:30 -0700 | [diff] [blame] | 2663 | * Removes the stack associated with the given {@param stackId}. If the {@param stackId} is the |
| 2664 | * pinned stack, then its tasks are not explicitly removed when the stack is destroyed, but |
| 2665 | * instead moved back onto the fullscreen stack. |
| 2666 | */ |
| 2667 | void removeStackLocked(int stackId) { |
Robert Carr | e7cc44d | 2017-03-20 19:04:30 -0700 | [diff] [blame] | 2668 | mWindowManager.inSurfaceTransaction( |
| 2669 | () -> removeStackInSurfaceTransaction(stackId)); |
Robert Carr | 6914f08 | 2017-03-20 19:04:30 -0700 | [diff] [blame] | 2670 | } |
| 2671 | |
| 2672 | /** |
Winson Chung | 6954fc9 | 2017-03-24 16:22:12 -0700 | [diff] [blame] | 2673 | * See {@link #removeTaskByIdLocked(int, boolean, boolean, boolean)} |
| 2674 | */ |
| 2675 | boolean removeTaskByIdLocked(int taskId, boolean killProcess, boolean removeFromRecents) { |
| 2676 | return removeTaskByIdLocked(taskId, killProcess, removeFromRecents, !PAUSE_IMMEDIATELY); |
| 2677 | } |
| 2678 | |
| 2679 | /** |
Winson Chung | 010927a | 2016-12-15 16:12:35 -0800 | [diff] [blame] | 2680 | * Removes the task with the specified task id. |
| 2681 | * |
| 2682 | * @param taskId Identifier of the task to be removed. |
| 2683 | * @param killProcess Kill any process associated with the task if possible. |
| 2684 | * @param removeFromRecents Whether to also remove the task from recents. |
Winson Chung | 6954fc9 | 2017-03-24 16:22:12 -0700 | [diff] [blame] | 2685 | * @param pauseImmediately Pauses all task activities immediately without waiting for the |
| 2686 | * pause-complete callback from the activity. |
Winson Chung | 010927a | 2016-12-15 16:12:35 -0800 | [diff] [blame] | 2687 | * @return Returns true if the given task was found and removed. |
| 2688 | */ |
Winson Chung | 6954fc9 | 2017-03-24 16:22:12 -0700 | [diff] [blame] | 2689 | boolean removeTaskByIdLocked(int taskId, boolean killProcess, boolean removeFromRecents, |
| 2690 | boolean pauseImmediately) { |
Winson Chung | 7900bee | 2017-03-10 08:59:25 -0800 | [diff] [blame] | 2691 | final TaskRecord tr = anyTaskForIdLocked(taskId, MATCH_TASK_IN_STACKS_OR_RECENT_TASKS, |
| 2692 | INVALID_STACK_ID); |
Winson Chung | 010927a | 2016-12-15 16:12:35 -0800 | [diff] [blame] | 2693 | if (tr != null) { |
Winson Chung | 6954fc9 | 2017-03-24 16:22:12 -0700 | [diff] [blame] | 2694 | tr.removeTaskActivitiesLocked(pauseImmediately); |
Winson Chung | 010927a | 2016-12-15 16:12:35 -0800 | [diff] [blame] | 2695 | cleanUpRemovedTaskLocked(tr, killProcess, removeFromRecents); |
| 2696 | if (tr.isPersistable) { |
| 2697 | mService.notifyTaskPersisterLocked(null, true); |
| 2698 | } |
| 2699 | return true; |
| 2700 | } |
| 2701 | Slog.w(TAG, "Request to remove task ignored for non-existent task " + taskId); |
| 2702 | return false; |
| 2703 | } |
| 2704 | |
| 2705 | void cleanUpRemovedTaskLocked(TaskRecord tr, boolean killProcess, boolean removeFromRecents) { |
| 2706 | if (removeFromRecents) { |
| 2707 | mRecentTasks.remove(tr); |
| 2708 | tr.removedFromRecents(); |
| 2709 | } |
| 2710 | ComponentName component = tr.getBaseIntent().getComponent(); |
| 2711 | if (component == null) { |
| 2712 | Slog.w(TAG, "No component for base intent of task: " + tr); |
| 2713 | return; |
| 2714 | } |
| 2715 | |
| 2716 | // Find any running services associated with this app and stop if needed. |
| 2717 | mService.mServices.cleanUpRemovedTaskLocked(tr, component, new Intent(tr.getBaseIntent())); |
| 2718 | |
| 2719 | if (!killProcess) { |
| 2720 | return; |
| 2721 | } |
| 2722 | |
| 2723 | // Determine if the process(es) for this task should be killed. |
| 2724 | final String pkg = component.getPackageName(); |
| 2725 | ArrayList<ProcessRecord> procsToKill = new ArrayList<>(); |
| 2726 | ArrayMap<String, SparseArray<ProcessRecord>> pmap = mService.mProcessNames.getMap(); |
| 2727 | for (int i = 0; i < pmap.size(); i++) { |
| 2728 | |
| 2729 | SparseArray<ProcessRecord> uids = pmap.valueAt(i); |
| 2730 | for (int j = 0; j < uids.size(); j++) { |
| 2731 | ProcessRecord proc = uids.valueAt(j); |
| 2732 | if (proc.userId != tr.userId) { |
| 2733 | // Don't kill process for a different user. |
| 2734 | continue; |
| 2735 | } |
| 2736 | if (proc == mService.mHomeProcess) { |
| 2737 | // Don't kill the home process along with tasks from the same package. |
| 2738 | continue; |
| 2739 | } |
| 2740 | if (!proc.pkgList.containsKey(pkg)) { |
| 2741 | // Don't kill process that is not associated with this task. |
| 2742 | continue; |
| 2743 | } |
| 2744 | |
| 2745 | for (int k = 0; k < proc.activities.size(); k++) { |
Bryce Lee | af691c0 | 2017-03-20 14:20:22 -0700 | [diff] [blame] | 2746 | TaskRecord otherTask = proc.activities.get(k).getTask(); |
Winson Chung | 010927a | 2016-12-15 16:12:35 -0800 | [diff] [blame] | 2747 | if (tr.taskId != otherTask.taskId && otherTask.inRecents) { |
| 2748 | // Don't kill process(es) that has an activity in a different task that is |
| 2749 | // also in recents. |
| 2750 | return; |
| 2751 | } |
| 2752 | } |
| 2753 | |
| 2754 | if (proc.foregroundServices) { |
| 2755 | // Don't kill process(es) with foreground service. |
| 2756 | return; |
| 2757 | } |
| 2758 | |
| 2759 | // Add process to kill list. |
| 2760 | procsToKill.add(proc); |
| 2761 | } |
| 2762 | } |
| 2763 | |
| 2764 | // Kill the running processes. |
| 2765 | for (int i = 0; i < procsToKill.size(); i++) { |
| 2766 | ProcessRecord pr = procsToKill.get(i); |
| 2767 | if (pr.setSchedGroup == ProcessList.SCHED_GROUP_BACKGROUND |
| 2768 | && pr.curReceivers.isEmpty()) { |
| 2769 | pr.kill("remove task", true); |
| 2770 | } else { |
| 2771 | // We delay killing processes that are not in the background or running a receiver. |
| 2772 | pr.waitingToKill = "remove task"; |
| 2773 | } |
| 2774 | } |
| 2775 | } |
| 2776 | |
Craig Mautner | 4a1cb22 | 2013-12-04 16:14:06 -0800 | [diff] [blame] | 2777 | int getNextStackId() { |
Craig Mautner | 858d8a6 | 2013-04-23 17:08:34 -0700 | [diff] [blame] | 2778 | while (true) { |
Wale Ogunwale | ddc1cb2 | 2015-07-25 19:23:04 -0700 | [diff] [blame] | 2779 | if (mNextFreeStackId >= FIRST_DYNAMIC_STACK_ID |
| 2780 | && getStack(mNextFreeStackId) == null) { |
Craig Mautner | 858d8a6 | 2013-04-23 17:08:34 -0700 | [diff] [blame] | 2781 | break; |
| 2782 | } |
Wale Ogunwale | ddc1cb2 | 2015-07-25 19:23:04 -0700 | [diff] [blame] | 2783 | mNextFreeStackId++; |
Craig Mautner | 8d341ef | 2013-03-26 09:03:27 -0700 | [diff] [blame] | 2784 | } |
Wale Ogunwale | ddc1cb2 | 2015-07-25 19:23:04 -0700 | [diff] [blame] | 2785 | return mNextFreeStackId; |
Craig Mautner | 8d341ef | 2013-03-26 09:03:27 -0700 | [diff] [blame] | 2786 | } |
| 2787 | |
Chong Zhang | 5dcb275 | 2015-08-18 13:50:26 -0700 | [diff] [blame] | 2788 | /** |
| 2789 | * Restores a recent task to a stack |
| 2790 | * @param task The recent task to be restored. |
| 2791 | * @param stackId The stack to restore the task to (default launch stack will be used |
Andrii Kulian | 16802aa | 2016-11-02 12:21:33 -0700 | [diff] [blame] | 2792 | * if stackId is {@link android.app.ActivityManager.StackId#INVALID_STACK_ID} |
| 2793 | * or is not a static stack). |
Chong Zhang | 5dcb275 | 2015-08-18 13:50:26 -0700 | [diff] [blame] | 2794 | * @return true if the task has been restored successfully. |
| 2795 | */ |
Wale Ogunwale | e1fe7fa2 | 2016-12-15 18:27:00 -0800 | [diff] [blame] | 2796 | boolean restoreRecentTaskLocked(TaskRecord task, int stackId) { |
Andrii Kulian | 16802aa | 2016-11-02 12:21:33 -0700 | [diff] [blame] | 2797 | if (!StackId.isStaticStack(stackId)) { |
| 2798 | // If stack is not static (or stack id is invalid) - use the default one. |
| 2799 | // This means that tasks that were on external displays will be restored on the |
| 2800 | // primary display. |
Wale Ogunwale | 8b06a58 | 2015-10-22 14:38:21 -0700 | [diff] [blame] | 2801 | stackId = task.getLaunchStackId(); |
Winson Chung | d339538 | 2016-12-13 11:49:09 -0800 | [diff] [blame] | 2802 | } else if (stackId == DOCKED_STACK_ID && !task.supportsSplitScreen()) { |
Wale Ogunwale | 513346d | 2016-01-27 10:55:01 -0800 | [diff] [blame] | 2803 | // Preferred stack is the docked stack, but the task can't go in the docked stack. |
| 2804 | // Put it in the fullscreen stack. |
| 2805 | stackId = FULLSCREEN_WORKSPACE_STACK_ID; |
Chong Zhang | 5dcb275 | 2015-08-18 13:50:26 -0700 | [diff] [blame] | 2806 | } |
Wale Ogunwale | 513346d | 2016-01-27 10:55:01 -0800 | [diff] [blame] | 2807 | |
Andrii Kulian | 02b7a83 | 2016-10-06 23:11:56 -0700 | [diff] [blame] | 2808 | final ActivityStack currentStack = task.getStack(); |
| 2809 | if (currentStack != null) { |
Wale Ogunwale | 706ed79 | 2015-08-02 10:29:44 -0700 | [diff] [blame] | 2810 | // Task has already been restored once. See if we need to do anything more |
Andrii Kulian | 02b7a83 | 2016-10-06 23:11:56 -0700 | [diff] [blame] | 2811 | if (currentStack.mStackId == stackId) { |
Wale Ogunwale | 706ed79 | 2015-08-02 10:29:44 -0700 | [diff] [blame] | 2812 | // Nothing else to do since it is already restored in the right stack. |
| 2813 | return true; |
| 2814 | } |
| 2815 | // Remove current stack association, so we can re-associate the task with the |
| 2816 | // right stack below. |
Andrii Kulian | 02b7a83 | 2016-10-06 23:11:56 -0700 | [diff] [blame] | 2817 | currentStack.removeTask(task, "restoreRecentTaskLocked", REMOVE_TASK_MODE_MOVING); |
Wale Ogunwale | 706ed79 | 2015-08-02 10:29:44 -0700 | [diff] [blame] | 2818 | } |
| 2819 | |
Wale Ogunwale | 6c5eb1c | 2015-11-10 07:52:22 -0800 | [diff] [blame] | 2820 | final ActivityStack stack = |
Wale Ogunwale | 040b470 | 2015-08-06 18:10:50 -0700 | [diff] [blame] | 2821 | getStack(stackId, CREATE_IF_NEEDED, !ON_TOP); |
Wale Ogunwale | 7de0535 | 2014-12-12 15:21:33 -0800 | [diff] [blame] | 2822 | |
| 2823 | if (stack == null) { |
| 2824 | // What does this mean??? Not sure how we would get here... |
Wale Ogunwale | ee006da | 2015-03-30 14:49:25 -0700 | [diff] [blame] | 2825 | if (DEBUG_RECENTS) Slog.v(TAG_RECENTS, |
| 2826 | "Unable to find/create stack to restore recent task=" + task); |
Wale Ogunwale | 7de0535 | 2014-12-12 15:21:33 -0800 | [diff] [blame] | 2827 | return false; |
| 2828 | } |
| 2829 | |
Wale Ogunwale | 72919d2 | 2016-12-08 18:58:50 -0800 | [diff] [blame] | 2830 | stack.addTask(task, false /* toTop */, "restoreRecentTask"); |
Wale Ogunwale | e1fe7fa2 | 2016-12-15 18:27:00 -0800 | [diff] [blame] | 2831 | // TODO: move call for creation here and other place into Stack.addTask() |
| 2832 | task.createWindowContainer(false /* toTop */, true /* showForAllUsers */); |
Wale Ogunwale | ee006da | 2015-03-30 14:49:25 -0700 | [diff] [blame] | 2833 | if (DEBUG_RECENTS) Slog.v(TAG_RECENTS, |
| 2834 | "Added restored task=" + task + " to stack=" + stack); |
Wale Ogunwale | 7de0535 | 2014-12-12 15:21:33 -0800 | [diff] [blame] | 2835 | final ArrayList<ActivityRecord> activities = task.mActivities; |
| 2836 | for (int activityNdx = activities.size() - 1; activityNdx >= 0; --activityNdx) { |
Wale Ogunwale | 26c0dfe | 2016-12-14 14:42:30 -0800 | [diff] [blame] | 2837 | activities.get(activityNdx).createWindowContainer(); |
Wale Ogunwale | 7de0535 | 2014-12-12 15:21:33 -0800 | [diff] [blame] | 2838 | } |
| 2839 | return true; |
Craig Mautner | ef73ee1 | 2014-04-23 11:45:37 -0700 | [diff] [blame] | 2840 | } |
| 2841 | |
Wale Ogunwale | 040b470 | 2015-08-06 18:10:50 -0700 | [diff] [blame] | 2842 | /** |
Andrii Kulian | 839def9 | 2016-11-02 10:58:58 -0700 | [diff] [blame] | 2843 | * Move stack with all its existing content to specified display. |
| 2844 | * @param stackId Id of stack to move. |
| 2845 | * @param displayId Id of display to move stack to. |
Andrii Kulian | 250d653 | 2017-02-08 23:30:45 -0800 | [diff] [blame] | 2846 | * @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] | 2847 | */ |
Andrii Kulian | 250d653 | 2017-02-08 23:30:45 -0800 | [diff] [blame] | 2848 | void moveStackToDisplayLocked(int stackId, int displayId, boolean onTop) { |
Andrii Kulian | 62e6f25 | 2017-05-30 22:46:53 -0700 | [diff] [blame] | 2849 | final ActivityDisplay activityDisplay = getActivityDisplayOrCreateLocked(displayId); |
Andrii Kulian | 839def9 | 2016-11-02 10:58:58 -0700 | [diff] [blame] | 2850 | if (activityDisplay == null) { |
| 2851 | throw new IllegalArgumentException("moveStackToDisplayLocked: Unknown displayId=" |
| 2852 | + displayId); |
| 2853 | } |
| 2854 | final ActivityContainer activityContainer = mActivityContainers.get(stackId); |
| 2855 | if (activityContainer != null) { |
| 2856 | if (activityContainer.isAttachedLocked()) { |
| 2857 | if (activityContainer.getDisplayId() == displayId) { |
| 2858 | throw new IllegalArgumentException("Trying to move stackId=" + stackId |
| 2859 | + " to its current displayId=" + displayId); |
| 2860 | } |
| 2861 | |
Andrii Kulian | 250d653 | 2017-02-08 23:30:45 -0800 | [diff] [blame] | 2862 | activityContainer.moveToDisplayLocked(activityDisplay, onTop); |
Andrii Kulian | 839def9 | 2016-11-02 10:58:58 -0700 | [diff] [blame] | 2863 | } else { |
| 2864 | throw new IllegalStateException("moveStackToDisplayLocked: Stack with stackId=" |
| 2865 | + stackId + " is not attached to any display."); |
| 2866 | } |
| 2867 | } else { |
| 2868 | throw new IllegalArgumentException("moveStackToDisplayLocked: Unknown stackId=" |
| 2869 | + stackId); |
| 2870 | } |
Andrii Kulian | 839def9 | 2016-11-02 10:58:58 -0700 | [diff] [blame] | 2871 | // TODO(multi-display): resize stacks properly if moved from split-screen. |
| 2872 | } |
| 2873 | |
| 2874 | /** |
Winson Chung | 7466610 | 2017-02-22 17:49:24 -0800 | [diff] [blame] | 2875 | * Returns the reparent target stack, creating the stack if necessary. This call also enforces |
| 2876 | * 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] | 2877 | */ |
Winson Chung | 7466610 | 2017-02-22 17:49:24 -0800 | [diff] [blame] | 2878 | ActivityStack getReparentTargetStack(TaskRecord task, int stackId, boolean toTop) { |
Andrii Kulian | 02b7a83 | 2016-10-06 23:11:56 -0700 | [diff] [blame] | 2879 | final ActivityStack prevStack = task.getStack(); |
Chong Zhang | 0289835 | 2015-08-21 17:27:14 -0700 | [diff] [blame] | 2880 | |
Winson Chung | 7466610 | 2017-02-22 17:49:24 -0800 | [diff] [blame] | 2881 | // Check that we aren't reparenting to the same stack that the task is already in |
| 2882 | if (prevStack != null && prevStack.mStackId == stackId) { |
| 2883 | Slog.w(TAG, "Can not reparent to same stack, task=" + task |
| 2884 | + " already in stackId=" + stackId); |
| 2885 | return prevStack; |
Wale Ogunwale | 513346d | 2016-01-27 10:55:01 -0800 | [diff] [blame] | 2886 | } |
| 2887 | |
Winson Chung | 7466610 | 2017-02-22 17:49:24 -0800 | [diff] [blame] | 2888 | // Ensure that we aren't trying to move into a multi-window stack without multi-window |
| 2889 | // support |
| 2890 | if (StackId.isMultiWindowStack(stackId) && !mService.mSupportsMultiWindow) { |
| 2891 | throw new IllegalArgumentException("Device doesn't support multi-window, can not" |
| 2892 | + " reparent task=" + task + " to stackId=" + stackId); |
Winson Chung | c2baac0 | 2017-01-11 13:34:47 -0800 | [diff] [blame] | 2893 | } |
| 2894 | |
Andrii Kulian | eafd9db | 2017-04-05 22:01:35 -0700 | [diff] [blame] | 2895 | // Ensure that we're not moving a task to a dynamic stack if device doesn't support |
| 2896 | // multi-display. |
| 2897 | // TODO(multi-display): Support non-dynamic stacks on secondary displays. |
| 2898 | // TODO: Check ActivityView after fixing b/35349678. |
| 2899 | if (StackId.isDynamicStack(stackId) && !mService.mSupportsMultiDisplay) { |
| 2900 | throw new IllegalArgumentException("Device doesn't support multi-display, can not" |
| 2901 | + " reparent task=" + task + " to stackId=" + stackId); |
| 2902 | } |
| 2903 | |
Winson Chung | 7466610 | 2017-02-22 17:49:24 -0800 | [diff] [blame] | 2904 | // Ensure that we aren't trying to move into a freeform stack without freeform |
| 2905 | // support |
Wale Ogunwale | 08559dc | 2016-02-23 12:20:08 -0800 | [diff] [blame] | 2906 | if (stackId == FREEFORM_WORKSPACE_STACK_ID && !mService.mSupportsFreeformWindowManagement) { |
Winson Chung | 7466610 | 2017-02-22 17:49:24 -0800 | [diff] [blame] | 2907 | throw new IllegalArgumentException("Device doesn't support freeform, can not reparent" |
| 2908 | + " task=" + task); |
Wale Ogunwale | 08559dc | 2016-02-23 12:20:08 -0800 | [diff] [blame] | 2909 | } |
| 2910 | |
Winson Chung | 7466610 | 2017-02-22 17:49:24 -0800 | [diff] [blame] | 2911 | // We don't allow moving a unresizeable task to the docked stack since the docked stack is |
| 2912 | // used for split-screen mode and will cause things like the docked divider to show up. We |
| 2913 | // instead leave the task in its current stack or move it to the fullscreen stack if it |
| 2914 | // isn't currently in a stack. |
| 2915 | if (stackId == DOCKED_STACK_ID && !task.isResizeable()) { |
| 2916 | stackId = (prevStack != null) ? prevStack.mStackId : FULLSCREEN_WORKSPACE_STACK_ID; |
| 2917 | Slog.w(TAG, "Can not move unresizeable task=" + task + " to docked stack." |
| 2918 | + " Moving to stackId=" + stackId + " instead."); |
Filip Gruszczynski | 49b80af | 2015-09-24 09:04:26 -0700 | [diff] [blame] | 2919 | } |
Wale Ogunwale | 961f485 | 2016-02-01 20:25:54 -0800 | [diff] [blame] | 2920 | |
Winson Chung | 7466610 | 2017-02-22 17:49:24 -0800 | [diff] [blame] | 2921 | // Temporarily disable resizeablility of the task as we don't want it to be resized if, for |
| 2922 | // example, a docked stack is created which will lead to the stack we are moving from being |
| 2923 | // resized and and its resizeable tasks being resized. |
Wale Ogunwale | 961f485 | 2016-02-01 20:25:54 -0800 | [diff] [blame] | 2924 | try { |
Winson Chung | 7466610 | 2017-02-22 17:49:24 -0800 | [diff] [blame] | 2925 | task.mTemporarilyUnresizable = true; |
| 2926 | return getStack(stackId, CREATE_IF_NEEDED, toTop); |
Wale Ogunwale | 961f485 | 2016-02-01 20:25:54 -0800 | [diff] [blame] | 2927 | } finally { |
Winson Chung | 7466610 | 2017-02-22 17:49:24 -0800 | [diff] [blame] | 2928 | task.mTemporarilyUnresizable = false; |
Chong Zhang | f596cd5 | 2016-01-05 13:42:44 -0800 | [diff] [blame] | 2929 | } |
Craig Mautner | 8d341ef | 2013-03-26 09:03:27 -0700 | [diff] [blame] | 2930 | } |
| 2931 | |
Winson Chung | 08f8189 | 2017-03-02 15:40:51 -0800 | [diff] [blame] | 2932 | boolean moveTopStackActivityToPinnedStackLocked(int stackId, Rect destBounds) { |
Wale Ogunwale | 079a004 | 2015-10-24 11:44:07 -0700 | [diff] [blame] | 2933 | final ActivityStack stack = getStack(stackId, !CREATE_IF_NEEDED, !ON_TOP); |
| 2934 | if (stack == null) { |
| 2935 | throw new IllegalArgumentException( |
| 2936 | "moveTopStackActivityToPinnedStackLocked: Unknown stackId=" + stackId); |
| 2937 | } |
| 2938 | |
| 2939 | final ActivityRecord r = stack.topRunningActivityLocked(); |
| 2940 | if (r == null) { |
| 2941 | Slog.w(TAG, "moveTopStackActivityToPinnedStackLocked: No top running activity" |
| 2942 | + " in stack=" + stack); |
| 2943 | return false; |
| 2944 | } |
| 2945 | |
Wale Ogunwale | 6cae765 | 2015-12-26 07:36:26 -0800 | [diff] [blame] | 2946 | if (!mService.mForceResizableActivities && !r.supportsPictureInPicture()) { |
Wale Ogunwale | b60692e | 2015-10-24 12:35:56 -0700 | [diff] [blame] | 2947 | Slog.w(TAG, |
| 2948 | "moveTopStackActivityToPinnedStackLocked: Picture-In-Picture not supported for " |
Filip Gruszczynski | 77d9448 | 2015-12-11 13:59:52 -0800 | [diff] [blame] | 2949 | + " r=" + r); |
Wale Ogunwale | 079a004 | 2015-10-24 11:44:07 -0700 | [diff] [blame] | 2950 | return false; |
| 2951 | } |
| 2952 | |
Winson Chung | 3a68287 | 2017-04-10 14:38:05 -0700 | [diff] [blame] | 2953 | moveActivityToPinnedStackLocked(r, null /* sourceBounds */, 0f /* aspectRatio */, |
Winson Chung | 08f8189 | 2017-03-02 15:40:51 -0800 | [diff] [blame] | 2954 | true /* moveHomeStackToFront */, "moveTopActivityToPinnedStack"); |
Wale Ogunwale | 9c604c7 | 2015-12-06 18:42:57 -0800 | [diff] [blame] | 2955 | return true; |
| 2956 | } |
| 2957 | |
Winson Chung | 8bca9e4 | 2017-04-16 15:59:43 -0700 | [diff] [blame] | 2958 | void moveActivityToPinnedStackLocked(ActivityRecord r, Rect sourceHintBounds, float aspectRatio, |
Winson Chung | 08f8189 | 2017-03-02 15:40:51 -0800 | [diff] [blame] | 2959 | boolean moveHomeStackToFront, String reason) { |
| 2960 | |
Wale Ogunwale | 480dca0 | 2016-02-06 13:58:29 -0800 | [diff] [blame] | 2961 | mWindowManager.deferSurfaceLayout(); |
Winson Chung | 7466610 | 2017-02-22 17:49:24 -0800 | [diff] [blame] | 2962 | |
Bryce Lee | 04ab346 | 2017-04-10 15:06:33 -0700 | [diff] [blame] | 2963 | // This will clear the pinned stack by moving an existing task to the full screen stack, |
| 2964 | // ensuring only one task is present. |
| 2965 | moveTasksToFullscreenStackLocked(PINNED_STACK_ID, !ON_TOP); |
| 2966 | |
Wale Ogunwale | 1666e31 | 2016-12-16 11:27:18 -0800 | [diff] [blame] | 2967 | // Need to make sure the pinned stack exist so we can resize it below... |
Winson Chung | 5589333 | 2017-02-17 17:13:10 -0800 | [diff] [blame] | 2968 | final PinnedActivityStack stack = getStack(PINNED_STACK_ID, CREATE_IF_NEEDED, ON_TOP); |
Wale Ogunwale | 1666e31 | 2016-12-16 11:27:18 -0800 | [diff] [blame] | 2969 | |
Wale Ogunwale | 480dca0 | 2016-02-06 13:58:29 -0800 | [diff] [blame] | 2970 | try { |
Bryce Lee | af691c0 | 2017-03-20 14:20:22 -0700 | [diff] [blame] | 2971 | final TaskRecord task = r.getTask(); |
Wale Ogunwale | 480dca0 | 2016-02-06 13:58:29 -0800 | [diff] [blame] | 2972 | |
Andrii Kulian | 02b7a83 | 2016-10-06 23:11:56 -0700 | [diff] [blame] | 2973 | if (r == task.getStack().getVisibleBehindActivity()) { |
Wale Ogunwale | 43896cf | 2016-04-16 10:54:30 -0700 | [diff] [blame] | 2974 | // An activity can't be pinned and visible behind at the same time. Go ahead and |
| 2975 | // release it from been visible behind before pinning. |
| 2976 | requestVisibleBehindLocked(r, false); |
| 2977 | } |
| 2978 | |
Wale Ogunwale | 480dca0 | 2016-02-06 13:58:29 -0800 | [diff] [blame] | 2979 | // Resize the pinned stack to match the current size of the task the activity we are |
| 2980 | // going to be moving is currently contained in. We do this to have the right starting |
| 2981 | // animation bounds for the pinned stack to the desired bounds the caller wants. |
| 2982 | resizeStackLocked(PINNED_STACK_ID, task.mBounds, null /* tempTaskBounds */, |
| 2983 | null /* tempTaskInsetBounds */, !PRESERVE_WINDOWS, |
Wale Ogunwale | c8da41e | 2016-04-16 13:27:23 -0700 | [diff] [blame] | 2984 | true /* allowResizeInDockedMode */, !DEFER_RESUME); |
Wale Ogunwale | 480dca0 | 2016-02-06 13:58:29 -0800 | [diff] [blame] | 2985 | |
| 2986 | if (task.mActivities.size() == 1) { |
| 2987 | // 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] | 2988 | // the stack without re-parenting the activity in a different task. We don't |
| 2989 | // move the home stack forward if we are currently entering picture-in-picture |
| 2990 | // while pausing because that changes the focused stack and may prevent the new |
| 2991 | // starting activity from resuming. |
| 2992 | if (moveHomeStackToFront && task.getTaskToReturnTo() == HOME_ACTIVITY_TYPE |
Winson Chung | 105ae5f | 2017-03-06 15:06:28 -0800 | [diff] [blame] | 2993 | && (r.state == RESUMED || !r.supportsPictureInPictureWhilePausing)) { |
Wale Ogunwale | da4ba96 | 2016-03-11 09:33:17 -0800 | [diff] [blame] | 2994 | // Move the home stack forward if the task we just moved to the pinned stack |
| 2995 | // was launched from home so home should be visible behind it. |
| 2996 | moveHomeStackToFront(reason); |
| 2997 | } |
Winson Chung | 5af42fc | 2017-03-24 17:11:33 -0700 | [diff] [blame] | 2998 | // Defer resume until below, and do not schedule PiP changes until we animate below |
Winson Chung | 7466610 | 2017-02-22 17:49:24 -0800 | [diff] [blame] | 2999 | task.reparent(PINNED_STACK_ID, ON_TOP, REPARENT_MOVE_STACK_TO_FRONT, !ANIMATE, |
Winson Chung | 5af42fc | 2017-03-24 17:11:33 -0700 | [diff] [blame] | 3000 | DEFER_RESUME, false /* schedulePictureInPictureModeChange */, reason); |
Wale Ogunwale | 480dca0 | 2016-02-06 13:58:29 -0800 | [diff] [blame] | 3001 | } else { |
Winson Chung | b5c41b7 | 2016-12-07 15:00:47 -0800 | [diff] [blame] | 3002 | // 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] | 3003 | // reveal/leave the other activities in their original task. |
| 3004 | |
| 3005 | // Currently, we don't support reparenting activities across tasks in two different |
| 3006 | // stacks, so instead, just create a new task in the same stack, reparent the |
| 3007 | // activity into that task, and then reparent the whole task to the new stack. This |
| 3008 | // ensures that all the necessary work to migrate states in the old and new stacks |
| 3009 | // is also done. |
| 3010 | final TaskRecord newTask = task.getStack().createTaskRecord( |
| 3011 | getNextTaskIdForUserLocked(r.userId), r.info, r.intent, null, null, true, |
| 3012 | r.mActivityType); |
| 3013 | r.reparent(newTask, MAX_VALUE, "moveActivityToStack"); |
| 3014 | |
Winson Chung | 5af42fc | 2017-03-24 17:11:33 -0700 | [diff] [blame] | 3015 | // Defer resume until below, and do not schedule PiP changes until we animate below |
Winson Chung | 7466610 | 2017-02-22 17:49:24 -0800 | [diff] [blame] | 3016 | newTask.reparent(PINNED_STACK_ID, ON_TOP, REPARENT_MOVE_STACK_TO_FRONT, !ANIMATE, |
Winson Chung | 5af42fc | 2017-03-24 17:11:33 -0700 | [diff] [blame] | 3017 | DEFER_RESUME, false /* schedulePictureInPictureModeChange */, reason); |
Wale Ogunwale | 480dca0 | 2016-02-06 13:58:29 -0800 | [diff] [blame] | 3018 | } |
Winson Chung | c2baac0 | 2017-01-11 13:34:47 -0800 | [diff] [blame] | 3019 | |
| 3020 | // Reset the state that indicates it can enter PiP while pausing after we've moved it |
| 3021 | // to the pinned stack |
| 3022 | r.supportsPictureInPictureWhilePausing = false; |
Wale Ogunwale | 480dca0 | 2016-02-06 13:58:29 -0800 | [diff] [blame] | 3023 | } finally { |
| 3024 | mWindowManager.continueSurfaceLayout(); |
Wale Ogunwale | 079a004 | 2015-10-24 11:44:07 -0700 | [diff] [blame] | 3025 | } |
| 3026 | |
Winson Chung | e7ba686 | 2017-05-24 12:13:33 -0700 | [diff] [blame] | 3027 | // Calculate the default bounds (don't use existing stack bounds as we may have just created |
| 3028 | // the stack, and schedule the start of the animation into PiP (the bounds animator that |
| 3029 | // is triggered by this is posted on another thread) |
Winson Chung | a71febe | 2017-05-22 11:14:22 -0700 | [diff] [blame] | 3030 | final Rect destBounds = stack.getDefaultPictureInPictureBounds(aspectRatio); |
| 3031 | |
Winson Chung | e7ba686 | 2017-05-24 12:13:33 -0700 | [diff] [blame] | 3032 | stack.animateResizePinnedStack(sourceHintBounds, destBounds, -1 /* animationDuration */, |
| 3033 | true /* fromFullscreen */); |
| 3034 | |
| 3035 | // Update the visibility of all activities after the they have been reparented to the new |
| 3036 | // stack. This MUST run after the animation above is scheduled to ensure that the windows |
| 3037 | // drawn signal is scheduled after the bounds animation start call on the bounds animator |
| 3038 | // thread. |
Wale Ogunwale | 079a004 | 2015-10-24 11:44:07 -0700 | [diff] [blame] | 3039 | ensureActivitiesVisibleLocked(null, 0, !PRESERVE_WINDOWS); |
Wale Ogunwale | d046a01 | 2015-12-24 13:05:59 -0800 | [diff] [blame] | 3040 | resumeFocusedStackTopActivityLocked(); |
Wale Ogunwale | 03ce863 | 2015-12-29 16:15:22 -0800 | [diff] [blame] | 3041 | |
Winson Chung | b502690 | 2017-05-03 12:45:13 -0700 | [diff] [blame] | 3042 | mService.mTaskChangeNotificationController.notifyActivityPinned(r.packageName, |
| 3043 | r.getTask().taskId); |
Wale Ogunwale | 079a004 | 2015-10-24 11:44:07 -0700 | [diff] [blame] | 3044 | } |
| 3045 | |
Andrii Kulian | 0864bbb | 2017-02-16 15:45:58 -0800 | [diff] [blame] | 3046 | /** Move activity with its stack to front and make the stack focused. */ |
Chong Zhang | 6cda19c | 2016-06-14 19:07:56 -0700 | [diff] [blame] | 3047 | boolean moveFocusableActivityStackToFrontLocked(ActivityRecord r, String reason) { |
| 3048 | if (r == null || !r.isFocusable()) { |
| 3049 | if (DEBUG_FOCUS) Slog.d(TAG_FOCUS, |
| 3050 | "moveActivityStackToFront: unfocusable r=" + r); |
| 3051 | return false; |
| 3052 | } |
| 3053 | |
Bryce Lee | af691c0 | 2017-03-20 14:20:22 -0700 | [diff] [blame] | 3054 | final TaskRecord task = r.getTask(); |
Andrii Kulian | 02b7a83 | 2016-10-06 23:11:56 -0700 | [diff] [blame] | 3055 | final ActivityStack stack = r.getStack(); |
| 3056 | if (stack == null) { |
Chong Zhang | 6cda19c | 2016-06-14 19:07:56 -0700 | [diff] [blame] | 3057 | Slog.w(TAG, "moveActivityStackToFront: invalid task or stack: r=" |
| 3058 | + r + " task=" + task); |
| 3059 | return false; |
| 3060 | } |
| 3061 | |
Chong Zhang | 6cda19c | 2016-06-14 19:07:56 -0700 | [diff] [blame] | 3062 | if (stack == mFocusedStack && stack.topRunningActivityLocked() == r) { |
| 3063 | if (DEBUG_FOCUS) Slog.d(TAG_FOCUS, |
| 3064 | "moveActivityStackToFront: already on top, r=" + r); |
| 3065 | return false; |
| 3066 | } |
| 3067 | |
| 3068 | if (DEBUG_FOCUS) Slog.d(TAG_FOCUS, |
| 3069 | "moveActivityStackToFront: r=" + r); |
| 3070 | |
| 3071 | stack.moveToFront(reason, task); |
| 3072 | return true; |
| 3073 | } |
| 3074 | |
David Stevens | c6b91c6 | 2017-02-08 14:23:58 -0800 | [diff] [blame] | 3075 | ActivityRecord findTaskLocked(ActivityRecord r, int displayId) { |
Wale Ogunwale | 3938197 | 2015-12-17 17:15:29 -0800 | [diff] [blame] | 3076 | mTmpFindTaskResult.r = null; |
| 3077 | mTmpFindTaskResult.matchedByRootAffinity = false; |
David Stevens | c6b91c6 | 2017-02-08 14:23:58 -0800 | [diff] [blame] | 3078 | ActivityRecord affinityMatch = null; |
Wale Ogunwale | ee006da | 2015-03-30 14:49:25 -0700 | [diff] [blame] | 3079 | if (DEBUG_TASKS) Slog.d(TAG_TASKS, "Looking for task of " + r); |
Craig Mautner | e0a3884 | 2013-12-16 16:14:02 -0800 | [diff] [blame] | 3080 | for (int displayNdx = mActivityDisplays.size() - 1; displayNdx >= 0; --displayNdx) { |
| 3081 | final ArrayList<ActivityStack> stacks = mActivityDisplays.valueAt(displayNdx).mStacks; |
Craig Mautner | 4a1cb22 | 2013-12-04 16:14:06 -0800 | [diff] [blame] | 3082 | for (int stackNdx = stacks.size() - 1; stackNdx >= 0; --stackNdx) { |
| 3083 | final ActivityStack stack = stacks.get(stackNdx); |
Winson Chung | 91e5c88 | 2017-04-21 14:44:38 -0700 | [diff] [blame] | 3084 | if (!checkActivityBelongsInStack(r, stack)) { |
| 3085 | if (DEBUG_TASKS) Slog.d(TAG_TASKS, "Skipping stack: (mismatch activity/stack) " |
| 3086 | + stack); |
Craig Mautner | 1b4bf85 | 2014-05-26 15:06:32 -0700 | [diff] [blame] | 3087 | continue; |
| 3088 | } |
| 3089 | if (!stack.mActivityContainer.isEligibleForNewTasks()) { |
Wale Ogunwale | ee006da | 2015-03-30 14:49:25 -0700 | [diff] [blame] | 3090 | if (DEBUG_TASKS) Slog.d(TAG_TASKS, |
| 3091 | "Skipping stack: (new task not allowed) " + stack); |
Craig Mautner | 4a1cb22 | 2013-12-04 16:14:06 -0800 | [diff] [blame] | 3092 | continue; |
| 3093 | } |
Wale Ogunwale | 3938197 | 2015-12-17 17:15:29 -0800 | [diff] [blame] | 3094 | stack.findTaskLocked(r, mTmpFindTaskResult); |
David Stevens | c6b91c6 | 2017-02-08 14:23:58 -0800 | [diff] [blame] | 3095 | // It is possible to have tasks in multiple stacks with the same root affinity, so |
| 3096 | // we should keep looking after finding an affinity match to see if there is a |
| 3097 | // better match in another stack. Also, task affinity isn't a good enough reason |
| 3098 | // to target a display which isn't the source of the intent, so skip any affinity |
| 3099 | // matches not on the specified display. |
| 3100 | if (mTmpFindTaskResult.r != null) { |
| 3101 | if (!mTmpFindTaskResult.matchedByRootAffinity) { |
| 3102 | return mTmpFindTaskResult.r; |
| 3103 | } else if (mTmpFindTaskResult.r.getDisplayId() == displayId) { |
Winson Chung | 5b895b7 | 2017-05-01 13:46:25 -0700 | [diff] [blame] | 3104 | // Note: since the traversing through the stacks is top down, the floating |
| 3105 | // tasks should always have lower priority than any affinity-matching tasks |
| 3106 | // in the fullscreen stacks |
David Stevens | c6b91c6 | 2017-02-08 14:23:58 -0800 | [diff] [blame] | 3107 | affinityMatch = mTmpFindTaskResult.r; |
| 3108 | } |
Craig Mautner | 4a1cb22 | 2013-12-04 16:14:06 -0800 | [diff] [blame] | 3109 | } |
Craig Mautner | 8849a5e | 2013-04-02 16:41:03 -0700 | [diff] [blame] | 3110 | } |
| 3111 | } |
Winson Chung | 5b895b7 | 2017-05-01 13:46:25 -0700 | [diff] [blame] | 3112 | |
David Stevens | c6b91c6 | 2017-02-08 14:23:58 -0800 | [diff] [blame] | 3113 | if (DEBUG_TASKS && affinityMatch == null) Slog.d(TAG_TASKS, "No task found"); |
| 3114 | return affinityMatch; |
Craig Mautner | 8849a5e | 2013-04-02 16:41:03 -0700 | [diff] [blame] | 3115 | } |
| 3116 | |
Winson Chung | 91e5c88 | 2017-04-21 14:44:38 -0700 | [diff] [blame] | 3117 | /** |
| 3118 | * Checks that for the given activity {@param r}, its activity type matches the {@param stack} |
| 3119 | * type. |
| 3120 | */ |
| 3121 | private boolean checkActivityBelongsInStack(ActivityRecord r, ActivityStack stack) { |
| 3122 | if (r.isHomeActivity()) { |
| 3123 | return stack.isHomeStack(); |
| 3124 | } else if (r.isRecentsActivity()) { |
| 3125 | return stack.isRecentsStack(); |
| 3126 | } else if (r.isAssistantActivity()) { |
| 3127 | return stack.isAssistantStack(); |
| 3128 | } |
| 3129 | return true; |
| 3130 | } |
| 3131 | |
Andrii Kulian | d3bbb13 | 2016-06-16 16:00:20 -0700 | [diff] [blame] | 3132 | ActivityRecord findActivityLocked(Intent intent, ActivityInfo info, |
| 3133 | boolean compareIntentFilters) { |
Craig Mautner | e0a3884 | 2013-12-16 16:14:02 -0800 | [diff] [blame] | 3134 | for (int displayNdx = mActivityDisplays.size() - 1; displayNdx >= 0; --displayNdx) { |
| 3135 | final ArrayList<ActivityStack> stacks = mActivityDisplays.valueAt(displayNdx).mStacks; |
Craig Mautner | 4a1cb22 | 2013-12-04 16:14:06 -0800 | [diff] [blame] | 3136 | for (int stackNdx = stacks.size() - 1; stackNdx >= 0; --stackNdx) { |
Andrii Kulian | d3bbb13 | 2016-06-16 16:00:20 -0700 | [diff] [blame] | 3137 | final ActivityRecord ar = stacks.get(stackNdx) |
| 3138 | .findActivityLocked(intent, info, compareIntentFilters); |
Craig Mautner | 4a1cb22 | 2013-12-04 16:14:06 -0800 | [diff] [blame] | 3139 | if (ar != null) { |
| 3140 | return ar; |
| 3141 | } |
Craig Mautner | 8849a5e | 2013-04-02 16:41:03 -0700 | [diff] [blame] | 3142 | } |
| 3143 | } |
| 3144 | return null; |
| 3145 | } |
| 3146 | |
Craig Mautner | 8d341ef | 2013-03-26 09:03:27 -0700 | [diff] [blame] | 3147 | void goingToSleepLocked() { |
Craig Mautner | 0eea92c | 2013-05-16 13:35:39 -0700 | [diff] [blame] | 3148 | scheduleSleepTimeout(); |
| 3149 | if (!mGoingToSleep.isHeld()) { |
| 3150 | mGoingToSleep.acquire(); |
Craig Mautner | 7ea5bd4 | 2013-07-05 15:27:08 -0700 | [diff] [blame] | 3151 | if (mLaunchingActivity.isHeld()) { |
| 3152 | if (VALIDATE_WAKE_LOCK_CALLER && Binder.getCallingUid() != Process.myUid()) { |
| 3153 | throw new IllegalStateException("Calling must be system uid"); |
Craig Mautner | 0eea92c | 2013-05-16 13:35:39 -0700 | [diff] [blame] | 3154 | } |
Craig Mautner | 7ea5bd4 | 2013-07-05 15:27:08 -0700 | [diff] [blame] | 3155 | mLaunchingActivity.release(); |
| 3156 | mService.mHandler.removeMessages(LAUNCH_TIMEOUT_MSG); |
Craig Mautner | 0eea92c | 2013-05-16 13:35:39 -0700 | [diff] [blame] | 3157 | } |
Craig Mautner | 8d341ef | 2013-03-26 09:03:27 -0700 | [diff] [blame] | 3158 | } |
Amith Yamasani | ce15e15 | 2013-09-19 12:30:32 -0700 | [diff] [blame] | 3159 | checkReadyForSleepLocked(); |
Craig Mautner | 8d341ef | 2013-03-26 09:03:27 -0700 | [diff] [blame] | 3160 | } |
| 3161 | |
| 3162 | boolean shutdownLocked(int timeout) { |
Craig Mautner | 0eea92c | 2013-05-16 13:35:39 -0700 | [diff] [blame] | 3163 | goingToSleepLocked(); |
Craig Mautner | 0eea92c | 2013-05-16 13:35:39 -0700 | [diff] [blame] | 3164 | |
Craig Mautner | f4c909b | 2014-04-17 18:39:38 -0700 | [diff] [blame] | 3165 | boolean timedout = false; |
Craig Mautner | 0eea92c | 2013-05-16 13:35:39 -0700 | [diff] [blame] | 3166 | final long endTime = System.currentTimeMillis() + timeout; |
| 3167 | while (true) { |
| 3168 | boolean cantShutdown = false; |
Craig Mautner | e0a3884 | 2013-12-16 16:14:02 -0800 | [diff] [blame] | 3169 | for (int displayNdx = mActivityDisplays.size() - 1; displayNdx >= 0; --displayNdx) { |
| 3170 | final ArrayList<ActivityStack> stacks = mActivityDisplays.valueAt(displayNdx).mStacks; |
Craig Mautner | 4a1cb22 | 2013-12-04 16:14:06 -0800 | [diff] [blame] | 3171 | for (int stackNdx = stacks.size() - 1; stackNdx >= 0; --stackNdx) { |
| 3172 | cantShutdown |= stacks.get(stackNdx).checkReadyForSleepLocked(); |
| 3173 | } |
Craig Mautner | 0eea92c | 2013-05-16 13:35:39 -0700 | [diff] [blame] | 3174 | } |
| 3175 | if (cantShutdown) { |
| 3176 | long timeRemaining = endTime - System.currentTimeMillis(); |
| 3177 | if (timeRemaining > 0) { |
Craig Mautner | 8d341ef | 2013-03-26 09:03:27 -0700 | [diff] [blame] | 3178 | try { |
Craig Mautner | 0eea92c | 2013-05-16 13:35:39 -0700 | [diff] [blame] | 3179 | mService.wait(timeRemaining); |
Craig Mautner | 8d341ef | 2013-03-26 09:03:27 -0700 | [diff] [blame] | 3180 | } catch (InterruptedException e) { |
| 3181 | } |
Craig Mautner | 0eea92c | 2013-05-16 13:35:39 -0700 | [diff] [blame] | 3182 | } else { |
| 3183 | Slog.w(TAG, "Activity manager shutdown timed out"); |
| 3184 | timedout = true; |
| 3185 | break; |
Craig Mautner | 8d341ef | 2013-03-26 09:03:27 -0700 | [diff] [blame] | 3186 | } |
Craig Mautner | 0eea92c | 2013-05-16 13:35:39 -0700 | [diff] [blame] | 3187 | } else { |
| 3188 | break; |
Craig Mautner | 8d341ef | 2013-03-26 09:03:27 -0700 | [diff] [blame] | 3189 | } |
| 3190 | } |
Craig Mautner | 0eea92c | 2013-05-16 13:35:39 -0700 | [diff] [blame] | 3191 | |
| 3192 | // Force checkReadyForSleep to complete. |
| 3193 | mSleepTimeout = true; |
| 3194 | checkReadyForSleepLocked(); |
| 3195 | |
Craig Mautner | 8d341ef | 2013-03-26 09:03:27 -0700 | [diff] [blame] | 3196 | return timedout; |
| 3197 | } |
| 3198 | |
| 3199 | void comeOutOfSleepIfNeededLocked() { |
Craig Mautner | 0eea92c | 2013-05-16 13:35:39 -0700 | [diff] [blame] | 3200 | removeSleepTimeouts(); |
| 3201 | if (mGoingToSleep.isHeld()) { |
| 3202 | mGoingToSleep.release(); |
| 3203 | } |
Craig Mautner | e0a3884 | 2013-12-16 16:14:02 -0800 | [diff] [blame] | 3204 | for (int displayNdx = mActivityDisplays.size() - 1; displayNdx >= 0; --displayNdx) { |
| 3205 | final ArrayList<ActivityStack> stacks = mActivityDisplays.valueAt(displayNdx).mStacks; |
Craig Mautner | 4a1cb22 | 2013-12-04 16:14:06 -0800 | [diff] [blame] | 3206 | for (int stackNdx = stacks.size() - 1; stackNdx >= 0; --stackNdx) { |
| 3207 | final ActivityStack stack = stacks.get(stackNdx); |
| 3208 | stack.awakeFromSleepingLocked(); |
Wale Ogunwale | 1e60e0c | 2015-10-28 13:36:10 -0700 | [diff] [blame] | 3209 | if (isFocusedStack(stack)) { |
Wale Ogunwale | d046a01 | 2015-12-24 13:05:59 -0800 | [diff] [blame] | 3210 | resumeFocusedStackTopActivityLocked(); |
Craig Mautner | 4a1cb22 | 2013-12-04 16:14:06 -0800 | [diff] [blame] | 3211 | } |
Craig Mautner | 5314a40 | 2013-09-26 12:40:16 -0700 | [diff] [blame] | 3212 | } |
Craig Mautner | 8d341ef | 2013-03-26 09:03:27 -0700 | [diff] [blame] | 3213 | } |
Craig Mautner | 0eea92c | 2013-05-16 13:35:39 -0700 | [diff] [blame] | 3214 | mGoingToSleepActivities.clear(); |
| 3215 | } |
| 3216 | |
| 3217 | void activitySleptLocked(ActivityRecord r) { |
| 3218 | mGoingToSleepActivities.remove(r); |
| 3219 | checkReadyForSleepLocked(); |
| 3220 | } |
| 3221 | |
| 3222 | void checkReadyForSleepLocked() { |
Fyodor Kupolov | 9b80b94 | 2016-06-16 16:29:05 -0700 | [diff] [blame] | 3223 | if (!mService.isSleepingOrShuttingDownLocked()) { |
Craig Mautner | 0eea92c | 2013-05-16 13:35:39 -0700 | [diff] [blame] | 3224 | // Do not care. |
| 3225 | return; |
| 3226 | } |
| 3227 | |
| 3228 | if (!mSleepTimeout) { |
| 3229 | boolean dontSleep = false; |
Craig Mautner | e0a3884 | 2013-12-16 16:14:02 -0800 | [diff] [blame] | 3230 | for (int displayNdx = mActivityDisplays.size() - 1; displayNdx >= 0; --displayNdx) { |
| 3231 | final ArrayList<ActivityStack> stacks = mActivityDisplays.valueAt(displayNdx).mStacks; |
Craig Mautner | 4a1cb22 | 2013-12-04 16:14:06 -0800 | [diff] [blame] | 3232 | for (int stackNdx = stacks.size() - 1; stackNdx >= 0; --stackNdx) { |
| 3233 | dontSleep |= stacks.get(stackNdx).checkReadyForSleepLocked(); |
| 3234 | } |
Craig Mautner | 0eea92c | 2013-05-16 13:35:39 -0700 | [diff] [blame] | 3235 | } |
| 3236 | |
| 3237 | if (mStoppingActivities.size() > 0) { |
| 3238 | // Still need to tell some activities to stop; can't sleep yet. |
Wale Ogunwale | ee006da | 2015-03-30 14:49:25 -0700 | [diff] [blame] | 3239 | if (DEBUG_PAUSE) Slog.v(TAG_PAUSE, "Sleep still need to stop " |
Craig Mautner | 0eea92c | 2013-05-16 13:35:39 -0700 | [diff] [blame] | 3240 | + mStoppingActivities.size() + " activities"); |
| 3241 | scheduleIdleLocked(); |
| 3242 | dontSleep = true; |
| 3243 | } |
| 3244 | |
| 3245 | if (mGoingToSleepActivities.size() > 0) { |
| 3246 | // Still need to tell some activities to sleep; can't sleep yet. |
Wale Ogunwale | ee006da | 2015-03-30 14:49:25 -0700 | [diff] [blame] | 3247 | if (DEBUG_PAUSE) Slog.v(TAG_PAUSE, "Sleep still need to sleep " |
Craig Mautner | 0eea92c | 2013-05-16 13:35:39 -0700 | [diff] [blame] | 3248 | + mGoingToSleepActivities.size() + " activities"); |
| 3249 | dontSleep = true; |
| 3250 | } |
| 3251 | |
| 3252 | if (dontSleep) { |
| 3253 | return; |
| 3254 | } |
| 3255 | } |
| 3256 | |
Wei Wang | 65c7a15 | 2016-06-02 18:51:22 -0700 | [diff] [blame] | 3257 | // Send launch end powerhint before going sleep |
| 3258 | mService.mActivityStarter.sendPowerHintForLaunchEndIfNeeded(); |
| 3259 | |
Craig Mautner | e0a3884 | 2013-12-16 16:14:02 -0800 | [diff] [blame] | 3260 | for (int displayNdx = mActivityDisplays.size() - 1; displayNdx >= 0; --displayNdx) { |
| 3261 | final ArrayList<ActivityStack> stacks = mActivityDisplays.valueAt(displayNdx).mStacks; |
Craig Mautner | 4a1cb22 | 2013-12-04 16:14:06 -0800 | [diff] [blame] | 3262 | for (int stackNdx = stacks.size() - 1; stackNdx >= 0; --stackNdx) { |
| 3263 | stacks.get(stackNdx).goToSleep(); |
| 3264 | } |
Craig Mautner | 0eea92c | 2013-05-16 13:35:39 -0700 | [diff] [blame] | 3265 | } |
| 3266 | |
| 3267 | removeSleepTimeouts(); |
| 3268 | |
| 3269 | if (mGoingToSleep.isHeld()) { |
| 3270 | mGoingToSleep.release(); |
| 3271 | } |
| 3272 | if (mService.mShuttingDown) { |
| 3273 | mService.notifyAll(); |
| 3274 | } |
Craig Mautner | 8d341ef | 2013-03-26 09:03:27 -0700 | [diff] [blame] | 3275 | } |
| 3276 | |
Craig Mautner | ce5f3cb | 2013-04-22 08:58:54 -0700 | [diff] [blame] | 3277 | boolean reportResumedActivityLocked(ActivityRecord r) { |
Andrii Kulian | 02b7a83 | 2016-10-06 23:11:56 -0700 | [diff] [blame] | 3278 | final ActivityStack stack = r.getStack(); |
Wale Ogunwale | 1e60e0c | 2015-10-28 13:36:10 -0700 | [diff] [blame] | 3279 | if (isFocusedStack(stack)) { |
Jeff Sharkey | 5782da7 | 2013-04-25 14:32:30 -0700 | [diff] [blame] | 3280 | mService.updateUsageStats(r, true); |
Craig Mautner | ce5f3cb | 2013-04-22 08:58:54 -0700 | [diff] [blame] | 3281 | } |
| 3282 | if (allResumedActivitiesComplete()) { |
Filip Gruszczynski | bc5a6c5 | 2015-09-22 13:13:24 -0700 | [diff] [blame] | 3283 | ensureActivitiesVisibleLocked(null, 0, !PRESERVE_WINDOWS); |
Craig Mautner | ce5f3cb | 2013-04-22 08:58:54 -0700 | [diff] [blame] | 3284 | mWindowManager.executeAppTransition(); |
| 3285 | return true; |
| 3286 | } |
| 3287 | return false; |
| 3288 | } |
| 3289 | |
Craig Mautner | 8d341ef | 2013-03-26 09:03:27 -0700 | [diff] [blame] | 3290 | void handleAppCrashLocked(ProcessRecord app) { |
Craig Mautner | e0a3884 | 2013-12-16 16:14:02 -0800 | [diff] [blame] | 3291 | for (int displayNdx = mActivityDisplays.size() - 1; displayNdx >= 0; --displayNdx) { |
| 3292 | final ArrayList<ActivityStack> stacks = mActivityDisplays.valueAt(displayNdx).mStacks; |
Wale Ogunwale | 28b2397 | 2015-07-29 16:01:50 -0700 | [diff] [blame] | 3293 | int stackNdx = stacks.size() - 1; |
| 3294 | while (stackNdx >= 0) { |
| 3295 | stacks.get(stackNdx).handleAppCrashLocked(app); |
| 3296 | stackNdx--; |
Craig Mautner | 4a1cb22 | 2013-12-04 16:14:06 -0800 | [diff] [blame] | 3297 | } |
Craig Mautner | 8d341ef | 2013-03-26 09:03:27 -0700 | [diff] [blame] | 3298 | } |
| 3299 | } |
| 3300 | |
Jose Lima | 4b6c669 | 2014-08-12 17:41:12 -0700 | [diff] [blame] | 3301 | boolean requestVisibleBehindLocked(ActivityRecord r, boolean visible) { |
Andrii Kulian | 02b7a83 | 2016-10-06 23:11:56 -0700 | [diff] [blame] | 3302 | final ActivityStack stack = r.getStack(); |
Craig Mautner | ee2e45a | 2014-06-27 12:10:03 -0700 | [diff] [blame] | 3303 | if (stack == null) { |
Wale Ogunwale | 0fc365c | 2015-05-25 19:35:42 -0700 | [diff] [blame] | 3304 | if (DEBUG_VISIBLE_BEHIND) Slog.d(TAG_VISIBLE_BEHIND, |
| 3305 | "requestVisibleBehind: r=" + r + " visible=" + visible + " stack is null"); |
Craig Mautner | ee2e45a | 2014-06-27 12:10:03 -0700 | [diff] [blame] | 3306 | return false; |
| 3307 | } |
Wale Ogunwale | 43896cf | 2016-04-16 10:54:30 -0700 | [diff] [blame] | 3308 | |
| 3309 | if (visible && !StackId.activitiesCanRequestVisibleBehind(stack.mStackId)) { |
| 3310 | if (DEBUG_VISIBLE_BEHIND) Slog.d(TAG_VISIBLE_BEHIND, "requestVisibleBehind: r=" + r |
| 3311 | + " visible=" + visible + " stackId=" + stack.mStackId |
| 3312 | + " can't contain visible behind activities"); |
| 3313 | return false; |
| 3314 | } |
| 3315 | |
Jose Lima | 4b6c669 | 2014-08-12 17:41:12 -0700 | [diff] [blame] | 3316 | final boolean isVisible = stack.hasVisibleBehindActivity(); |
Wale Ogunwale | 0fc365c | 2015-05-25 19:35:42 -0700 | [diff] [blame] | 3317 | if (DEBUG_VISIBLE_BEHIND) Slog.d(TAG_VISIBLE_BEHIND, |
| 3318 | "requestVisibleBehind r=" + r + " visible=" + visible + " isVisible=" + isVisible); |
Craig Mautner | ee2e45a | 2014-06-27 12:10:03 -0700 | [diff] [blame] | 3319 | |
| 3320 | final ActivityRecord top = topRunningActivityLocked(); |
Jose Lima | 4b6c669 | 2014-08-12 17:41:12 -0700 | [diff] [blame] | 3321 | if (top == null || top == r || (visible == isVisible)) { |
Wale Ogunwale | 0fc365c | 2015-05-25 19:35:42 -0700 | [diff] [blame] | 3322 | if (DEBUG_VISIBLE_BEHIND) Slog.d(TAG_VISIBLE_BEHIND, "requestVisibleBehind: quick return"); |
Jose Lima | 4b6c669 | 2014-08-12 17:41:12 -0700 | [diff] [blame] | 3323 | stack.setVisibleBehindActivity(visible ? r : null); |
Craig Mautner | ee2e45a | 2014-06-27 12:10:03 -0700 | [diff] [blame] | 3324 | return true; |
| 3325 | } |
| 3326 | |
| 3327 | // A non-top activity is reporting a visibility change. |
Craig Mautner | aea5ced | 2014-09-07 17:08:39 -0700 | [diff] [blame] | 3328 | if (visible && top.fullscreen) { |
| 3329 | // Let the caller know that it can't be seen. |
Wale Ogunwale | 0fc365c | 2015-05-25 19:35:42 -0700 | [diff] [blame] | 3330 | if (DEBUG_VISIBLE_BEHIND) Slog.d(TAG_VISIBLE_BEHIND, |
| 3331 | "requestVisibleBehind: returning top.fullscreen=" + top.fullscreen |
| 3332 | + " top.state=" + top.state + " top.app=" + top.app + " top.app.thread=" |
| 3333 | + top.app.thread); |
Craig Mautner | ee2e45a | 2014-06-27 12:10:03 -0700 | [diff] [blame] | 3334 | return false; |
Jose Lima | 34ff492 | 2014-08-18 15:19:41 -0700 | [diff] [blame] | 3335 | } else if (!visible && stack.getVisibleBehindActivity() != r) { |
| 3336 | // Only the activity set as currently visible behind should actively reset its |
| 3337 | // visible behind state. |
Wale Ogunwale | 0fc365c | 2015-05-25 19:35:42 -0700 | [diff] [blame] | 3338 | if (DEBUG_VISIBLE_BEHIND) Slog.d(TAG_VISIBLE_BEHIND, |
| 3339 | "requestVisibleBehind: returning visible=" + visible |
| 3340 | + " stack.getVisibleBehindActivity()=" + stack.getVisibleBehindActivity() |
| 3341 | + " r=" + r); |
Jose Lima | 34ff492 | 2014-08-18 15:19:41 -0700 | [diff] [blame] | 3342 | return false; |
Craig Mautner | ee2e45a | 2014-06-27 12:10:03 -0700 | [diff] [blame] | 3343 | } |
| 3344 | |
Jose Lima | 4b6c669 | 2014-08-12 17:41:12 -0700 | [diff] [blame] | 3345 | stack.setVisibleBehindActivity(visible ? r : null); |
| 3346 | if (!visible) { |
Filip Gruszczynski | 62c5e9d | 2016-02-04 11:06:54 -0800 | [diff] [blame] | 3347 | // If there is a translucent home activity, we need to force it stop being translucent, |
| 3348 | // because we can't depend on the application to necessarily perform that operation. |
| 3349 | // Check out b/14469711 for details. |
Craig Mautner | fa387ad | 2014-08-05 11:16:41 -0700 | [diff] [blame] | 3350 | final ActivityRecord next = stack.findNextTranslucentActivity(r); |
Filip Gruszczynski | 62c5e9d | 2016-02-04 11:06:54 -0800 | [diff] [blame] | 3351 | if (next != null && next.isHomeActivity()) { |
Craig Mautner | fa387ad | 2014-08-05 11:16:41 -0700 | [diff] [blame] | 3352 | mService.convertFromTranslucent(next.appToken); |
| 3353 | } |
| 3354 | } |
Craig Mautner | aea5ced | 2014-09-07 17:08:39 -0700 | [diff] [blame] | 3355 | if (top.app != null && top.app.thread != null) { |
| 3356 | // Notify the top app of the change. |
| 3357 | try { |
| 3358 | top.app.thread.scheduleBackgroundVisibleBehindChanged(top.appToken, visible); |
| 3359 | } catch (RemoteException e) { |
| 3360 | } |
Craig Mautner | ee2e45a | 2014-06-27 12:10:03 -0700 | [diff] [blame] | 3361 | } |
| 3362 | return true; |
| 3363 | } |
| 3364 | |
Craig Mautner | bb74246 | 2014-07-07 15:28:55 -0700 | [diff] [blame] | 3365 | // Called when WindowManager has finished animating the launchingBehind activity to the back. |
Andrii Kulian | 21713ac | 2016-10-12 22:05:05 -0700 | [diff] [blame] | 3366 | private void handleLaunchTaskBehindCompleteLocked(ActivityRecord r) { |
Bryce Lee | af691c0 | 2017-03-20 14:20:22 -0700 | [diff] [blame] | 3367 | final TaskRecord task = r.getTask(); |
Andrii Kulian | 02b7a83 | 2016-10-06 23:11:56 -0700 | [diff] [blame] | 3368 | final ActivityStack stack = task.getStack(); |
Winson | 730bf06 | 2016-03-31 18:04:56 -0700 | [diff] [blame] | 3369 | |
| 3370 | r.mLaunchTaskBehind = false; |
Andrii Kulian | 21713ac | 2016-10-12 22:05:05 -0700 | [diff] [blame] | 3371 | task.setLastThumbnailLocked(r.screenshotActivityLocked()); |
Wale Ogunwale | c82f2f5 | 2014-12-09 09:32:50 -0800 | [diff] [blame] | 3372 | mRecentTasks.addLocked(task); |
Yorke Lee | bd54c2a | 2016-10-25 13:49:23 -0700 | [diff] [blame] | 3373 | mService.mTaskChangeNotificationController.notifyTaskStackChanged(); |
Wale Ogunwale | 26c0dfe | 2016-12-14 14:42:30 -0800 | [diff] [blame] | 3374 | r.setVisibility(false); |
Winson | 730bf06 | 2016-03-31 18:04:56 -0700 | [diff] [blame] | 3375 | |
| 3376 | // When launching tasks behind, update the last active time of the top task after the new |
| 3377 | // task has been shown briefly |
| 3378 | final ActivityRecord top = stack.topActivity(); |
| 3379 | if (top != null) { |
Bryce Lee | af691c0 | 2017-03-20 14:20:22 -0700 | [diff] [blame] | 3380 | top.getTask().touchActiveTime(); |
Winson | 730bf06 | 2016-03-31 18:04:56 -0700 | [diff] [blame] | 3381 | } |
Craig Mautner | bb74246 | 2014-07-07 15:28:55 -0700 | [diff] [blame] | 3382 | } |
| 3383 | |
| 3384 | void scheduleLaunchTaskBehindComplete(IBinder token) { |
| 3385 | mHandler.obtainMessage(LAUNCH_TASK_BEHIND_COMPLETE, token).sendToTarget(); |
| 3386 | } |
| 3387 | |
Filip Gruszczynski | bc5a6c5 | 2015-09-22 13:13:24 -0700 | [diff] [blame] | 3388 | void ensureActivitiesVisibleLocked(ActivityRecord starting, int configChanges, |
| 3389 | boolean preserveWindows) { |
Jorim Jaggi | fe76234 | 2016-10-13 14:33:27 +0200 | [diff] [blame] | 3390 | mKeyguardController.beginActivityVisibilityUpdate(); |
| 3391 | try { |
| 3392 | // First the front stacks. In case any are not fullscreen and are in front of home. |
| 3393 | for (int displayNdx = mActivityDisplays.size() - 1; displayNdx >= 0; --displayNdx) { |
| 3394 | final ArrayList<ActivityStack> stacks = mActivityDisplays.valueAt(displayNdx).mStacks; |
| 3395 | final int topStackNdx = stacks.size() - 1; |
| 3396 | for (int stackNdx = topStackNdx; stackNdx >= 0; --stackNdx) { |
| 3397 | final ActivityStack stack = stacks.get(stackNdx); |
| 3398 | stack.ensureActivitiesVisibleLocked(starting, configChanges, preserveWindows); |
| 3399 | } |
Craig Mautner | 580ea81 | 2013-04-25 12:58:38 -0700 | [diff] [blame] | 3400 | } |
Jorim Jaggi | fe76234 | 2016-10-13 14:33:27 +0200 | [diff] [blame] | 3401 | } finally { |
| 3402 | mKeyguardController.endActivityVisibilityUpdate(); |
Craig Mautner | 8d341ef | 2013-03-26 09:03:27 -0700 | [diff] [blame] | 3403 | } |
Craig Mautner | 8d341ef | 2013-03-26 09:03:27 -0700 | [diff] [blame] | 3404 | } |
| 3405 | |
Jorim Jaggi | 8b702ed | 2017-01-20 16:59:03 +0100 | [diff] [blame] | 3406 | void addStartingWindowsForVisibleActivities(boolean taskSwitch) { |
| 3407 | for (int displayNdx = mActivityDisplays.size() - 1; displayNdx >= 0; --displayNdx) { |
| 3408 | final ArrayList<ActivityStack> stacks = mActivityDisplays.valueAt(displayNdx).mStacks; |
| 3409 | final int topStackNdx = stacks.size() - 1; |
| 3410 | for (int stackNdx = topStackNdx; stackNdx >= 0; --stackNdx) { |
| 3411 | final ActivityStack stack = stacks.get(stackNdx); |
| 3412 | stack.addStartingWindowsForVisibleActivities(taskSwitch); |
| 3413 | } |
| 3414 | } |
| 3415 | } |
| 3416 | |
Chong Zhang | fdcc4d4 | 2015-10-14 16:50:12 -0700 | [diff] [blame] | 3417 | void invalidateTaskLayers() { |
| 3418 | mTaskLayersChanged = true; |
| 3419 | } |
| 3420 | |
| 3421 | void rankTaskLayersIfNeeded() { |
| 3422 | if (!mTaskLayersChanged) { |
| 3423 | return; |
| 3424 | } |
| 3425 | mTaskLayersChanged = false; |
| 3426 | for (int displayNdx = 0; displayNdx < mActivityDisplays.size(); displayNdx++) { |
| 3427 | final ArrayList<ActivityStack> stacks = mActivityDisplays.valueAt(displayNdx).mStacks; |
| 3428 | int baseLayer = 0; |
| 3429 | for (int stackNdx = stacks.size() - 1; stackNdx >= 0; --stackNdx) { |
| 3430 | baseLayer += stacks.get(stackNdx).rankTaskLayers(baseLayer); |
| 3431 | } |
| 3432 | } |
| 3433 | } |
| 3434 | |
Dianne Hackborn | b5a380d | 2015-05-20 18:18:46 -0700 | [diff] [blame] | 3435 | void clearOtherAppTimeTrackers(AppTimeTracker except) { |
| 3436 | for (int displayNdx = mActivityDisplays.size() - 1; displayNdx >= 0; --displayNdx) { |
| 3437 | final ArrayList<ActivityStack> stacks = mActivityDisplays.valueAt(displayNdx).mStacks; |
| 3438 | final int topStackNdx = stacks.size() - 1; |
| 3439 | for (int stackNdx = topStackNdx; stackNdx >= 0; --stackNdx) { |
| 3440 | final ActivityStack stack = stacks.get(stackNdx); |
| 3441 | stack.clearOtherAppTimeTrackers(except); |
| 3442 | } |
| 3443 | } |
| 3444 | } |
| 3445 | |
Craig Mautner | 8d341ef | 2013-03-26 09:03:27 -0700 | [diff] [blame] | 3446 | void scheduleDestroyAllActivities(ProcessRecord app, String reason) { |
Craig Mautner | e0a3884 | 2013-12-16 16:14:02 -0800 | [diff] [blame] | 3447 | for (int displayNdx = mActivityDisplays.size() - 1; displayNdx >= 0; --displayNdx) { |
| 3448 | final ArrayList<ActivityStack> stacks = mActivityDisplays.valueAt(displayNdx).mStacks; |
Craig Mautner | 4a1cb22 | 2013-12-04 16:14:06 -0800 | [diff] [blame] | 3449 | final int numStacks = stacks.size(); |
| 3450 | for (int stackNdx = 0; stackNdx < numStacks; ++stackNdx) { |
| 3451 | final ActivityStack stack = stacks.get(stackNdx); |
Craig Mautner | ee2e45a | 2014-06-27 12:10:03 -0700 | [diff] [blame] | 3452 | stack.scheduleDestroyActivities(app, reason); |
Craig Mautner | 4a1cb22 | 2013-12-04 16:14:06 -0800 | [diff] [blame] | 3453 | } |
Craig Mautner | 8d341ef | 2013-03-26 09:03:27 -0700 | [diff] [blame] | 3454 | } |
| 3455 | } |
| 3456 | |
Dianne Hackborn | 89ad456 | 2014-08-24 16:45:38 -0700 | [diff] [blame] | 3457 | void releaseSomeActivitiesLocked(ProcessRecord app, String reason) { |
| 3458 | // Examine all activities currently running in the process. |
| 3459 | TaskRecord firstTask = null; |
| 3460 | // Tasks is non-null only if two or more tasks are found. |
| 3461 | ArraySet<TaskRecord> tasks = null; |
Wale Ogunwale | 0fc365c | 2015-05-25 19:35:42 -0700 | [diff] [blame] | 3462 | if (DEBUG_RELEASE) Slog.d(TAG_RELEASE, "Trying to release some activities in " + app); |
| 3463 | for (int i = 0; i < app.activities.size(); i++) { |
Dianne Hackborn | 89ad456 | 2014-08-24 16:45:38 -0700 | [diff] [blame] | 3464 | ActivityRecord r = app.activities.get(i); |
| 3465 | // First, if we find an activity that is in the process of being destroyed, |
| 3466 | // then we just aren't going to do anything for now; we want things to settle |
| 3467 | // down before we try to prune more activities. |
Wale Ogunwale | ee006da | 2015-03-30 14:49:25 -0700 | [diff] [blame] | 3468 | if (r.finishing || r.state == DESTROYING || r.state == DESTROYED) { |
Wale Ogunwale | 0fc365c | 2015-05-25 19:35:42 -0700 | [diff] [blame] | 3469 | if (DEBUG_RELEASE) Slog.d(TAG_RELEASE, "Abort release; already destroying: " + r); |
Dianne Hackborn | 89ad456 | 2014-08-24 16:45:38 -0700 | [diff] [blame] | 3470 | return; |
| 3471 | } |
| 3472 | // Don't consider any activies that are currently not in a state where they |
| 3473 | // can be destroyed. |
Wale Ogunwale | ee006da | 2015-03-30 14:49:25 -0700 | [diff] [blame] | 3474 | if (r.visible || !r.stopped || !r.haveState || r.state == RESUMED || r.state == PAUSING |
| 3475 | || r.state == PAUSED || r.state == STOPPING) { |
Wale Ogunwale | 0fc365c | 2015-05-25 19:35:42 -0700 | [diff] [blame] | 3476 | 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] | 3477 | continue; |
| 3478 | } |
Bryce Lee | af691c0 | 2017-03-20 14:20:22 -0700 | [diff] [blame] | 3479 | |
| 3480 | final TaskRecord task = r.getTask(); |
| 3481 | if (task != null) { |
| 3482 | if (DEBUG_RELEASE) Slog.d(TAG_RELEASE, "Collecting release task " + task |
Dianne Hackborn | 89ad456 | 2014-08-24 16:45:38 -0700 | [diff] [blame] | 3483 | + " from " + r); |
| 3484 | if (firstTask == null) { |
Bryce Lee | af691c0 | 2017-03-20 14:20:22 -0700 | [diff] [blame] | 3485 | firstTask = task; |
| 3486 | } else if (firstTask != task) { |
Dianne Hackborn | 89ad456 | 2014-08-24 16:45:38 -0700 | [diff] [blame] | 3487 | if (tasks == null) { |
| 3488 | tasks = new ArraySet<>(); |
| 3489 | tasks.add(firstTask); |
| 3490 | } |
Bryce Lee | af691c0 | 2017-03-20 14:20:22 -0700 | [diff] [blame] | 3491 | tasks.add(task); |
Dianne Hackborn | 89ad456 | 2014-08-24 16:45:38 -0700 | [diff] [blame] | 3492 | } |
| 3493 | } |
| 3494 | } |
| 3495 | if (tasks == null) { |
Wale Ogunwale | 0fc365c | 2015-05-25 19:35:42 -0700 | [diff] [blame] | 3496 | 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] | 3497 | return; |
| 3498 | } |
| 3499 | // If we have activities in multiple tasks that are in a position to be destroyed, |
| 3500 | // let's iterate through the tasks and release the oldest one. |
| 3501 | final int numDisplays = mActivityDisplays.size(); |
| 3502 | for (int displayNdx = 0; displayNdx < numDisplays; ++displayNdx) { |
| 3503 | final ArrayList<ActivityStack> stacks = mActivityDisplays.valueAt(displayNdx).mStacks; |
| 3504 | // Step through all stacks starting from behind, to hit the oldest things first. |
| 3505 | for (int stackNdx = 0; stackNdx < stacks.size(); stackNdx++) { |
| 3506 | final ActivityStack stack = stacks.get(stackNdx); |
| 3507 | // Try to release activities in this stack; if we manage to, we are done. |
| 3508 | if (stack.releaseSomeActivitiesLocked(app, tasks, reason) > 0) { |
| 3509 | return; |
| 3510 | } |
| 3511 | } |
| 3512 | } |
| 3513 | } |
| 3514 | |
Amith Yamasani | 37a40c2 | 2015-06-17 13:25:42 -0700 | [diff] [blame] | 3515 | boolean switchUserLocked(int userId, UserState uss) { |
Wale Ogunwale | 9a98c52 | 2016-04-27 09:23:55 -0700 | [diff] [blame] | 3516 | final int focusStackId = mFocusedStack.getStackId(); |
| 3517 | // We dismiss the docked stack whenever we switch users. |
| 3518 | moveTasksToFullscreenStackLocked(DOCKED_STACK_ID, focusStackId == DOCKED_STACK_ID); |
Winson Chung | c2b23a5 | 2017-01-09 15:44:55 -0800 | [diff] [blame] | 3519 | // Also dismiss the pinned stack whenever we switch users. Removing the pinned stack will |
| 3520 | // also cause all tasks to be moved to the fullscreen stack at a position that is |
| 3521 | // appropriate. |
| 3522 | removeStackLocked(PINNED_STACK_ID); |
Wale Ogunwale | 9a98c52 | 2016-04-27 09:23:55 -0700 | [diff] [blame] | 3523 | |
| 3524 | mUserStackInFront.put(mCurrentUser, focusStackId); |
Craig Mautner | 4f1df4f | 2013-10-15 15:44:14 -0700 | [diff] [blame] | 3525 | final int restoreStackId = mUserStackInFront.get(userId, HOME_STACK_ID); |
Craig Mautner | 2420ead | 2013-04-01 17:13:20 -0700 | [diff] [blame] | 3526 | mCurrentUser = userId; |
Craig Mautner | ac6f843 | 2013-07-17 13:24:59 -0700 | [diff] [blame] | 3527 | |
Craig Mautner | 858d8a6 | 2013-04-23 17:08:34 -0700 | [diff] [blame] | 3528 | mStartingUsers.add(uss); |
Craig Mautner | e0a3884 | 2013-12-16 16:14:02 -0800 | [diff] [blame] | 3529 | for (int displayNdx = mActivityDisplays.size() - 1; displayNdx >= 0; --displayNdx) { |
| 3530 | final ArrayList<ActivityStack> stacks = mActivityDisplays.valueAt(displayNdx).mStacks; |
Craig Mautner | 4a1cb22 | 2013-12-04 16:14:06 -0800 | [diff] [blame] | 3531 | for (int stackNdx = stacks.size() - 1; stackNdx >= 0; --stackNdx) { |
Craig Mautner | e0a3884 | 2013-12-16 16:14:02 -0800 | [diff] [blame] | 3532 | final ActivityStack stack = stacks.get(stackNdx); |
| 3533 | stack.switchUserLocked(userId); |
Alexandra Gherghina | dae57a1 | 2014-03-12 19:15:26 +0000 | [diff] [blame] | 3534 | TaskRecord task = stack.topTask(); |
| 3535 | if (task != null) { |
Wale Ogunwale | 1666e31 | 2016-12-16 11:27:18 -0800 | [diff] [blame] | 3536 | stack.positionChildWindowContainerAtTop(task); |
Alexandra Gherghina | dae57a1 | 2014-03-12 19:15:26 +0000 | [diff] [blame] | 3537 | } |
Craig Mautner | 4a1cb22 | 2013-12-04 16:14:06 -0800 | [diff] [blame] | 3538 | } |
Craig Mautner | ac6f843 | 2013-07-17 13:24:59 -0700 | [diff] [blame] | 3539 | } |
Craig Mautner | 858d8a6 | 2013-04-23 17:08:34 -0700 | [diff] [blame] | 3540 | |
Craig Mautner | 4f1df4f | 2013-10-15 15:44:14 -0700 | [diff] [blame] | 3541 | ActivityStack stack = getStack(restoreStackId); |
| 3542 | if (stack == null) { |
| 3543 | stack = mHomeStack; |
| 3544 | } |
| 3545 | final boolean homeInFront = stack.isHomeStack(); |
Craig Mautner | e0a3884 | 2013-12-16 16:14:02 -0800 | [diff] [blame] | 3546 | if (stack.isOnHomeDisplay()) { |
Wale Ogunwale | 925d0d1 | 2015-09-23 15:40:07 -0700 | [diff] [blame] | 3547 | stack.moveToFront("switchUserOnHomeDisplay"); |
Craig Mautner | e0a3884 | 2013-12-16 16:14:02 -0800 | [diff] [blame] | 3548 | } else { |
| 3549 | // Stack was moved to another display while user was swapped out. |
Matthew Ng | ae1ff4f | 2016-11-10 15:49:14 -0800 | [diff] [blame] | 3550 | resumeHomeStackTask(null, "switchUserOnOtherDisplay"); |
Craig Mautner | e0a3884 | 2013-12-16 16:14:02 -0800 | [diff] [blame] | 3551 | } |
Craig Mautner | 93529a4 | 2013-10-04 15:03:13 -0700 | [diff] [blame] | 3552 | return homeInFront; |
Craig Mautner | 2219a1b | 2013-03-25 09:44:30 -0700 | [diff] [blame] | 3553 | } |
| 3554 | |
Wale Ogunwale | 0bd2aa7 | 2015-04-16 13:50:44 -0700 | [diff] [blame] | 3555 | /** Checks whether the userid is a profile of the current user. */ |
| 3556 | boolean isCurrentProfileLocked(int userId) { |
| 3557 | if (userId == mCurrentUser) return true; |
Fyodor Kupolov | 610acda | 2015-10-19 18:44:07 -0700 | [diff] [blame] | 3558 | return mService.mUserController.isCurrentProfileLocked(userId); |
Wale Ogunwale | 0bd2aa7 | 2015-04-16 13:50:44 -0700 | [diff] [blame] | 3559 | } |
| 3560 | |
Bryce Lee | b7c9b80 | 2017-05-02 14:20:24 -0700 | [diff] [blame] | 3561 | /** |
| 3562 | * Returns whether a stopping activity is present that should be stopped after visible, rather |
| 3563 | * than idle. |
| 3564 | * @return {@code true} if such activity is present. {@code false} otherwise. |
| 3565 | */ |
| 3566 | boolean isStoppingNoHistoryActivity() { |
| 3567 | // Activities that are marked as nohistory should be stopped immediately after the resumed |
| 3568 | // activity has become visible. |
| 3569 | for (ActivityRecord record : mStoppingActivities) { |
| 3570 | if (record.isNoHistory()) { |
| 3571 | return true; |
| 3572 | } |
| 3573 | } |
| 3574 | |
| 3575 | return false; |
| 3576 | } |
| 3577 | |
Winson Chung | 4dabf23 | 2017-01-25 13:25:22 -0800 | [diff] [blame] | 3578 | final ArrayList<ActivityRecord> processStoppingActivitiesLocked(ActivityRecord idleActivity, |
| 3579 | boolean remove, boolean processPausingActivities) { |
Craig Mautner | de4ef02 | 2013-04-07 19:01:33 -0700 | [diff] [blame] | 3580 | ArrayList<ActivityRecord> stops = null; |
| 3581 | |
| 3582 | final boolean nowVisible = allResumedActivitiesVisible(); |
Craig Mautner | 8c14c15 | 2015-01-15 17:32:07 -0800 | [diff] [blame] | 3583 | for (int activityNdx = mStoppingActivities.size() - 1; activityNdx >= 0; --activityNdx) { |
| 3584 | ActivityRecord s = mStoppingActivities.get(activityNdx); |
Bryce Lee | 4a19438 | 2017-04-04 14:32:48 -0700 | [diff] [blame] | 3585 | boolean waitingVisible = mActivitiesWaitingForVisibleActivity.contains(s); |
Wale Ogunwale | f81c1d1 | 2016-01-12 12:20:18 -0800 | [diff] [blame] | 3586 | if (DEBUG_STATES) Slog.v(TAG, "Stopping " + s + ": nowVisible=" + nowVisible |
Craig Mautner | 8c14c15 | 2015-01-15 17:32:07 -0800 | [diff] [blame] | 3587 | + " waitingVisible=" + waitingVisible + " finishing=" + s.finishing); |
| 3588 | if (waitingVisible && nowVisible) { |
Bryce Lee | 4a19438 | 2017-04-04 14:32:48 -0700 | [diff] [blame] | 3589 | mActivitiesWaitingForVisibleActivity.remove(s); |
Andrii Kulian | ee05681 | 2016-09-21 15:34:45 -0700 | [diff] [blame] | 3590 | waitingVisible = false; |
Craig Mautner | de4ef02 | 2013-04-07 19:01:33 -0700 | [diff] [blame] | 3591 | if (s.finishing) { |
| 3592 | // If this activity is finishing, it is sitting on top of |
| 3593 | // everyone else but we now know it is no longer needed... |
| 3594 | // so get rid of it. Otherwise, we need to go through the |
| 3595 | // normal flow and hide it once we determine that it is |
| 3596 | // hidden by the activities in front of it. |
Wale Ogunwale | f81c1d1 | 2016-01-12 12:20:18 -0800 | [diff] [blame] | 3597 | if (DEBUG_STATES) Slog.v(TAG, "Before stopping, can hide: " + s); |
Wale Ogunwale | 26c0dfe | 2016-12-14 14:42:30 -0800 | [diff] [blame] | 3598 | s.setVisibility(false); |
Craig Mautner | de4ef02 | 2013-04-07 19:01:33 -0700 | [diff] [blame] | 3599 | } |
| 3600 | } |
Fyodor Kupolov | 9b80b94 | 2016-06-16 16:29:05 -0700 | [diff] [blame] | 3601 | if ((!waitingVisible || mService.isSleepingOrShuttingDownLocked()) && remove) { |
Winson Chung | 4dabf23 | 2017-01-25 13:25:22 -0800 | [diff] [blame] | 3602 | if (!processPausingActivities && s.state == PAUSING) { |
| 3603 | // Defer processing pausing activities in this iteration and reschedule |
| 3604 | // a delayed idle to reprocess it again |
| 3605 | removeTimeoutsForActivityLocked(idleActivity); |
| 3606 | scheduleIdleTimeoutLocked(idleActivity); |
| 3607 | continue; |
| 3608 | } |
| 3609 | |
Wale Ogunwale | f81c1d1 | 2016-01-12 12:20:18 -0800 | [diff] [blame] | 3610 | if (DEBUG_STATES) Slog.v(TAG, "Ready to stop: " + s); |
Craig Mautner | de4ef02 | 2013-04-07 19:01:33 -0700 | [diff] [blame] | 3611 | if (stops == null) { |
Craig Mautner | 8c14c15 | 2015-01-15 17:32:07 -0800 | [diff] [blame] | 3612 | stops = new ArrayList<>(); |
Craig Mautner | de4ef02 | 2013-04-07 19:01:33 -0700 | [diff] [blame] | 3613 | } |
| 3614 | stops.add(s); |
Craig Mautner | 8c14c15 | 2015-01-15 17:32:07 -0800 | [diff] [blame] | 3615 | mStoppingActivities.remove(activityNdx); |
Craig Mautner | de4ef02 | 2013-04-07 19:01:33 -0700 | [diff] [blame] | 3616 | } |
| 3617 | } |
| 3618 | |
| 3619 | return stops; |
| 3620 | } |
| 3621 | |
Craig Mautner | cf910b0 | 2013-04-23 11:23:27 -0700 | [diff] [blame] | 3622 | void validateTopActivitiesLocked() { |
Wale Ogunwale | ee006da | 2015-03-30 14:49:25 -0700 | [diff] [blame] | 3623 | for (int displayNdx = mActivityDisplays.size() - 1; displayNdx >= 0; --displayNdx) { |
| 3624 | final ArrayList<ActivityStack> stacks = mActivityDisplays.valueAt(displayNdx).mStacks; |
| 3625 | for (int stackNdx = stacks.size() - 1; stackNdx >= 0; --stackNdx) { |
| 3626 | final ActivityStack stack = stacks.get(stackNdx); |
Filip Gruszczynski | 3e85ba2 | 2015-10-05 22:48:30 -0700 | [diff] [blame] | 3627 | final ActivityRecord r = stack.topRunningActivityLocked(); |
Wale Ogunwale | ee006da | 2015-03-30 14:49:25 -0700 | [diff] [blame] | 3628 | final ActivityState state = r == null ? DESTROYED : r.state; |
Wale Ogunwale | 1e60e0c | 2015-10-28 13:36:10 -0700 | [diff] [blame] | 3629 | if (isFocusedStack(stack)) { |
Wale Ogunwale | ee006da | 2015-03-30 14:49:25 -0700 | [diff] [blame] | 3630 | if (r == null) Slog.e(TAG, |
| 3631 | "validateTop...: null top activity, stack=" + stack); |
| 3632 | else { |
| 3633 | final ActivityRecord pausing = stack.mPausingActivity; |
| 3634 | if (pausing != null && pausing == r) Slog.e(TAG, |
| 3635 | "validateTop...: top stack has pausing activity r=" + r |
| 3636 | + " state=" + state); |
| 3637 | if (state != INITIALIZING && state != RESUMED) Slog.e(TAG, |
| 3638 | "validateTop...: activity in front not resumed r=" + r |
| 3639 | + " state=" + state); |
| 3640 | } |
Craig Mautner | cf910b0 | 2013-04-23 11:23:27 -0700 | [diff] [blame] | 3641 | } else { |
Wale Ogunwale | ee006da | 2015-03-30 14:49:25 -0700 | [diff] [blame] | 3642 | final ActivityRecord resumed = stack.mResumedActivity; |
| 3643 | if (resumed != null && resumed == r) Slog.e(TAG, |
| 3644 | "validateTop...: back stack has resumed activity r=" + r |
| 3645 | + " state=" + state); |
| 3646 | if (r != null && (state == INITIALIZING || state == RESUMED)) Slog.e(TAG, |
| 3647 | "validateTop...: activity in back resumed r=" + r + " state=" + state); |
Craig Mautner | cf910b0 | 2013-04-23 11:23:27 -0700 | [diff] [blame] | 3648 | } |
| 3649 | } |
| 3650 | } |
Craig Mautner | 76ea224 | 2013-05-15 11:40:05 -0700 | [diff] [blame] | 3651 | } |
| 3652 | |
Craig Mautner | e057020 | 2015-05-13 13:06:11 -0700 | [diff] [blame] | 3653 | private String lockTaskModeToString() { |
| 3654 | switch (mLockTaskModeState) { |
| 3655 | case LOCK_TASK_MODE_LOCKED: |
| 3656 | return "LOCKED"; |
| 3657 | case LOCK_TASK_MODE_PINNED: |
| 3658 | return "PINNED"; |
| 3659 | case LOCK_TASK_MODE_NONE: |
| 3660 | return "NONE"; |
| 3661 | default: return "unknown=" + mLockTaskModeState; |
| 3662 | } |
| 3663 | } |
| 3664 | |
Craig Mautner | 2708430 | 2013-03-25 08:05:25 -0700 | [diff] [blame] | 3665 | public void dump(PrintWriter pw, String prefix) { |
Craig Mautner | d1bbdb462 | 2013-10-22 09:53:20 -0700 | [diff] [blame] | 3666 | pw.print(prefix); pw.print("mFocusedStack=" + mFocusedStack); |
Craig Mautner | 4a1cb22 | 2013-12-04 16:14:06 -0800 | [diff] [blame] | 3667 | pw.print(" mLastFocusedStack="); pw.println(mLastFocusedStack); |
Craig Mautner | d1bbdb462 | 2013-10-22 09:53:20 -0700 | [diff] [blame] | 3668 | pw.print(prefix); pw.println("mSleepTimeout=" + mSleepTimeout); |
Suprabh Shukla | 09a88f5 | 2015-12-02 14:36:31 -0800 | [diff] [blame] | 3669 | pw.print(prefix); |
| 3670 | pw.println("mCurTaskIdForUser=" + mCurTaskIdForUser); |
Craig Mautner | d1bbdb462 | 2013-10-22 09:53:20 -0700 | [diff] [blame] | 3671 | pw.print(prefix); pw.println("mUserStackInFront=" + mUserStackInFront); |
Craig Mautner | 95da108 | 2014-02-24 17:54:35 -0800 | [diff] [blame] | 3672 | pw.print(prefix); pw.println("mActivityContainers=" + mActivityContainers); |
Craig Mautner | e057020 | 2015-05-13 13:06:11 -0700 | [diff] [blame] | 3673 | pw.print(prefix); pw.print("mLockTaskModeState=" + lockTaskModeToString()); |
Jorim Jaggi | 8d78693 | 2016-10-26 19:08:36 -0700 | [diff] [blame] | 3674 | final SparseArray<String[]> packages = mService.mLockTaskPackages; |
| 3675 | if (packages.size() > 0) { |
| 3676 | pw.print(prefix); pw.println("mLockTaskPackages (userId:packages)="); |
| 3677 | for (int i = 0; i < packages.size(); ++i) { |
| 3678 | pw.print(prefix); pw.print(prefix); pw.print(packages.keyAt(i)); |
| 3679 | pw.print(":"); pw.println(Arrays.toString(packages.valueAt(i))); |
| 3680 | } |
| 3681 | } |
Bryce Lee | 4a19438 | 2017-04-04 14:32:48 -0700 | [diff] [blame] | 3682 | if (!mWaitingForActivityVisible.isEmpty()) { |
| 3683 | pw.print(prefix); pw.println("mWaitingForActivityVisible="); |
| 3684 | for (int i = 0; i < mWaitingForActivityVisible.size(); ++i) { |
| 3685 | pw.print(prefix); pw.print(prefix); mWaitingForActivityVisible.get(i).dump(pw, prefix); |
| 3686 | } |
| 3687 | } |
| 3688 | |
Jorim Jaggi | 8d78693 | 2016-10-26 19:08:36 -0700 | [diff] [blame] | 3689 | pw.println(" mLockTaskModeTasks" + mLockTaskModeTasks); |
| 3690 | mKeyguardController.dump(pw, prefix); |
Craig Mautner | 2708430 | 2013-03-25 08:05:25 -0700 | [diff] [blame] | 3691 | } |
Craig Mautner | 8d341ef | 2013-03-26 09:03:27 -0700 | [diff] [blame] | 3692 | |
Winson | 43d1f26 | 2016-06-14 16:05:55 -0700 | [diff] [blame] | 3693 | /** |
Andrii Kulian | 5406e7a | 2016-10-21 11:55:23 -0700 | [diff] [blame] | 3694 | * Dump all connected displays' configurations. |
| 3695 | * @param prefix Prefix to apply to each line of the dump. |
| 3696 | */ |
| 3697 | void dumpDisplayConfigs(PrintWriter pw, String prefix) { |
| 3698 | pw.print(prefix); pw.println("Display override configurations:"); |
| 3699 | final int displayCount = mActivityDisplays.size(); |
| 3700 | for (int i = 0; i < displayCount; i++) { |
| 3701 | final ActivityDisplay activityDisplay = mActivityDisplays.valueAt(i); |
| 3702 | pw.print(prefix); pw.print(" "); pw.print(activityDisplay.mDisplayId); pw.print(": "); |
| 3703 | pw.println(activityDisplay.getOverrideConfiguration()); |
| 3704 | } |
| 3705 | } |
| 3706 | |
| 3707 | /** |
Winson | 43d1f26 | 2016-06-14 16:05:55 -0700 | [diff] [blame] | 3708 | * Dumps the activities matching the given {@param name} in the either the focused stack |
| 3709 | * or all visible stacks if {@param dumpVisibleStacks} is true. |
| 3710 | */ |
Winson Chung | 6998bc4 | 2017-02-28 17:07:05 -0800 | [diff] [blame] | 3711 | ArrayList<ActivityRecord> getDumpActivitiesLocked(String name, boolean dumpVisibleStacksOnly, |
| 3712 | boolean dumpFocusedStackOnly) { |
| 3713 | if (dumpFocusedStackOnly) { |
| 3714 | return mFocusedStack.getDumpActivitiesLocked(name); |
| 3715 | } else { |
Winson | 43d1f26 | 2016-06-14 16:05:55 -0700 | [diff] [blame] | 3716 | ArrayList<ActivityRecord> activities = new ArrayList<>(); |
| 3717 | int numDisplays = mActivityDisplays.size(); |
| 3718 | for (int displayNdx = 0; displayNdx < numDisplays; ++displayNdx) { |
| 3719 | ArrayList<ActivityStack> stacks = mActivityDisplays.valueAt(displayNdx).mStacks; |
| 3720 | for (int stackNdx = stacks.size() - 1; stackNdx >= 0; --stackNdx) { |
| 3721 | ActivityStack stack = stacks.get(stackNdx); |
Winson Chung | 6998bc4 | 2017-02-28 17:07:05 -0800 | [diff] [blame] | 3722 | if (!dumpVisibleStacksOnly || |
Wale Ogunwale | cd501ec | 2017-04-07 08:53:41 -0700 | [diff] [blame] | 3723 | stack.shouldBeVisible(null) == STACK_VISIBLE) { |
Winson | 43d1f26 | 2016-06-14 16:05:55 -0700 | [diff] [blame] | 3724 | activities.addAll(stack.getDumpActivitiesLocked(name)); |
| 3725 | } |
| 3726 | } |
| 3727 | } |
| 3728 | return activities; |
Winson | 43d1f26 | 2016-06-14 16:05:55 -0700 | [diff] [blame] | 3729 | } |
Craig Mautner | 20e7227 | 2013-04-01 13:45:53 -0700 | [diff] [blame] | 3730 | } |
| 3731 | |
Dianne Hackborn | 390517b | 2013-05-30 15:03:32 -0700 | [diff] [blame] | 3732 | static boolean printThisActivity(PrintWriter pw, ActivityRecord activity, String dumpPackage, |
| 3733 | boolean needSep, String prefix) { |
| 3734 | if (activity != null) { |
| 3735 | if (dumpPackage == null || dumpPackage.equals(activity.packageName)) { |
| 3736 | if (needSep) { |
| 3737 | pw.println(); |
Dianne Hackborn | 390517b | 2013-05-30 15:03:32 -0700 | [diff] [blame] | 3738 | } |
| 3739 | pw.print(prefix); |
| 3740 | pw.println(activity); |
Dianne Hackborn | 7ad34e5 | 2013-06-05 18:41:45 -0700 | [diff] [blame] | 3741 | return true; |
Dianne Hackborn | 390517b | 2013-05-30 15:03:32 -0700 | [diff] [blame] | 3742 | } |
| 3743 | } |
Dianne Hackborn | 7ad34e5 | 2013-06-05 18:41:45 -0700 | [diff] [blame] | 3744 | return false; |
Dianne Hackborn | 390517b | 2013-05-30 15:03:32 -0700 | [diff] [blame] | 3745 | } |
| 3746 | |
Craig Mautner | 8d341ef | 2013-03-26 09:03:27 -0700 | [diff] [blame] | 3747 | boolean dumpActivitiesLocked(FileDescriptor fd, PrintWriter pw, boolean dumpAll, |
| 3748 | boolean dumpClient, String dumpPackage) { |
Dianne Hackborn | 7ad34e5 | 2013-06-05 18:41:45 -0700 | [diff] [blame] | 3749 | boolean printed = false; |
| 3750 | boolean needSep = false; |
Craig Mautner | e0a3884 | 2013-12-16 16:14:02 -0800 | [diff] [blame] | 3751 | for (int displayNdx = 0; displayNdx < mActivityDisplays.size(); ++displayNdx) { |
| 3752 | ActivityDisplay activityDisplay = mActivityDisplays.valueAt(displayNdx); |
Craig Mautner | ee2e45a | 2014-06-27 12:10:03 -0700 | [diff] [blame] | 3753 | pw.print("Display #"); pw.print(activityDisplay.mDisplayId); |
Craig Mautner | 737fae2 | 2014-10-15 12:52:10 -0700 | [diff] [blame] | 3754 | pw.println(" (activities from top to bottom):"); |
Craig Mautner | e0a3884 | 2013-12-16 16:14:02 -0800 | [diff] [blame] | 3755 | ArrayList<ActivityStack> stacks = activityDisplay.mStacks; |
Craig Mautner | 737fae2 | 2014-10-15 12:52:10 -0700 | [diff] [blame] | 3756 | for (int stackNdx = stacks.size() - 1; stackNdx >= 0; --stackNdx) { |
Craig Mautner | 4a1cb22 | 2013-12-04 16:14:06 -0800 | [diff] [blame] | 3757 | final ActivityStack stack = stacks.get(stackNdx); |
| 3758 | StringBuilder stackHeader = new StringBuilder(128); |
| 3759 | stackHeader.append(" Stack #"); |
| 3760 | stackHeader.append(stack.mStackId); |
| 3761 | stackHeader.append(":"); |
Wale Ogunwale | b34a7ad | 2015-08-14 11:05:30 -0700 | [diff] [blame] | 3762 | stackHeader.append("\n"); |
| 3763 | stackHeader.append(" mFullscreen=" + stack.mFullscreen); |
| 3764 | stackHeader.append("\n"); |
| 3765 | stackHeader.append(" mBounds=" + stack.mBounds); |
Winson Chung | abb433b | 2017-03-24 09:35:42 -0700 | [diff] [blame] | 3766 | |
| 3767 | final boolean printedStackHeader = stack.dumpActivitiesLocked(fd, pw, dumpAll, |
| 3768 | dumpClient, dumpPackage, needSep, stackHeader.toString()); |
| 3769 | printed |= printedStackHeader; |
| 3770 | if (!printedStackHeader) { |
| 3771 | // Ensure we always dump the stack header even if there are no activities |
| 3772 | pw.println(); |
| 3773 | pw.println(stackHeader); |
| 3774 | } |
| 3775 | |
Craig Mautner | 4a1cb22 | 2013-12-04 16:14:06 -0800 | [diff] [blame] | 3776 | printed |= dumpHistoryList(fd, pw, stack.mLRUActivities, " ", "Run", false, |
| 3777 | !dumpAll, false, dumpPackage, true, |
| 3778 | " Running activities (most recent first):", null); |
Craig Mautner | 8d341ef | 2013-03-26 09:03:27 -0700 | [diff] [blame] | 3779 | |
Craig Mautner | 4a1cb22 | 2013-12-04 16:14:06 -0800 | [diff] [blame] | 3780 | needSep = printed; |
| 3781 | boolean pr = printThisActivity(pw, stack.mPausingActivity, dumpPackage, needSep, |
| 3782 | " mPausingActivity: "); |
Dianne Hackborn | 7ad34e5 | 2013-06-05 18:41:45 -0700 | [diff] [blame] | 3783 | if (pr) { |
| 3784 | printed = true; |
Craig Mautner | 4a1cb22 | 2013-12-04 16:14:06 -0800 | [diff] [blame] | 3785 | needSep = false; |
Dianne Hackborn | 7ad34e5 | 2013-06-05 18:41:45 -0700 | [diff] [blame] | 3786 | } |
Craig Mautner | 4a1cb22 | 2013-12-04 16:14:06 -0800 | [diff] [blame] | 3787 | pr = printThisActivity(pw, stack.mResumedActivity, dumpPackage, needSep, |
| 3788 | " mResumedActivity: "); |
| 3789 | if (pr) { |
| 3790 | printed = true; |
| 3791 | needSep = false; |
| 3792 | } |
| 3793 | if (dumpAll) { |
| 3794 | pr = printThisActivity(pw, stack.mLastPausedActivity, dumpPackage, needSep, |
| 3795 | " mLastPausedActivity: "); |
| 3796 | if (pr) { |
| 3797 | printed = true; |
| 3798 | needSep = true; |
| 3799 | } |
| 3800 | printed |= printThisActivity(pw, stack.mLastNoHistoryActivity, dumpPackage, |
| 3801 | needSep, " mLastNoHistoryActivity: "); |
| 3802 | } |
| 3803 | needSep = printed; |
Craig Mautner | 8d341ef | 2013-03-26 09:03:27 -0700 | [diff] [blame] | 3804 | } |
| 3805 | } |
| 3806 | |
Dianne Hackborn | 7ad34e5 | 2013-06-05 18:41:45 -0700 | [diff] [blame] | 3807 | printed |= dumpHistoryList(fd, pw, mFinishingActivities, " ", "Fin", false, !dumpAll, |
| 3808 | false, dumpPackage, true, " Activities waiting to finish:", null); |
| 3809 | printed |= dumpHistoryList(fd, pw, mStoppingActivities, " ", "Stop", false, !dumpAll, |
| 3810 | false, dumpPackage, true, " Activities waiting to stop:", null); |
Bryce Lee | 4a19438 | 2017-04-04 14:32:48 -0700 | [diff] [blame] | 3811 | printed |= dumpHistoryList(fd, pw, mActivitiesWaitingForVisibleActivity, " ", "Wait", |
| 3812 | false, !dumpAll, false, dumpPackage, true, |
| 3813 | " Activities waiting for another to become visible:", null); |
Dianne Hackborn | 7ad34e5 | 2013-06-05 18:41:45 -0700 | [diff] [blame] | 3814 | printed |= dumpHistoryList(fd, pw, mGoingToSleepActivities, " ", "Sleep", false, !dumpAll, |
| 3815 | false, dumpPackage, true, " Activities waiting to sleep:", null); |
| 3816 | printed |= dumpHistoryList(fd, pw, mGoingToSleepActivities, " ", "Sleep", false, !dumpAll, |
| 3817 | false, dumpPackage, true, " Activities waiting to sleep:", null); |
Craig Mautner | f333327 | 2013-04-22 10:55:53 -0700 | [diff] [blame] | 3818 | |
Dianne Hackborn | 7ad34e5 | 2013-06-05 18:41:45 -0700 | [diff] [blame] | 3819 | return printed; |
Craig Mautner | 8d341ef | 2013-03-26 09:03:27 -0700 | [diff] [blame] | 3820 | } |
| 3821 | |
Dianne Hackborn | 390517b | 2013-05-30 15:03:32 -0700 | [diff] [blame] | 3822 | static boolean dumpHistoryList(FileDescriptor fd, PrintWriter pw, List<ActivityRecord> list, |
Craig Mautner | 8d341ef | 2013-03-26 09:03:27 -0700 | [diff] [blame] | 3823 | String prefix, String label, boolean complete, boolean brief, boolean client, |
Dianne Hackborn | 7ad34e5 | 2013-06-05 18:41:45 -0700 | [diff] [blame] | 3824 | String dumpPackage, boolean needNL, String header1, String header2) { |
Craig Mautner | 8d341ef | 2013-03-26 09:03:27 -0700 | [diff] [blame] | 3825 | TaskRecord lastTask = null; |
Dianne Hackborn | 390517b | 2013-05-30 15:03:32 -0700 | [diff] [blame] | 3826 | String innerPrefix = null; |
| 3827 | String[] args = null; |
| 3828 | boolean printed = false; |
Craig Mautner | 8d341ef | 2013-03-26 09:03:27 -0700 | [diff] [blame] | 3829 | for (int i=list.size()-1; i>=0; i--) { |
| 3830 | final ActivityRecord r = list.get(i); |
| 3831 | if (dumpPackage != null && !dumpPackage.equals(r.packageName)) { |
| 3832 | continue; |
| 3833 | } |
Dianne Hackborn | 390517b | 2013-05-30 15:03:32 -0700 | [diff] [blame] | 3834 | if (innerPrefix == null) { |
| 3835 | innerPrefix = prefix + " "; |
| 3836 | args = new String[0]; |
| 3837 | } |
| 3838 | printed = true; |
Craig Mautner | 8d341ef | 2013-03-26 09:03:27 -0700 | [diff] [blame] | 3839 | final boolean full = !brief && (complete || !r.isInHistory()); |
| 3840 | if (needNL) { |
Dianne Hackborn | 390517b | 2013-05-30 15:03:32 -0700 | [diff] [blame] | 3841 | pw.println(""); |
Craig Mautner | 8d341ef | 2013-03-26 09:03:27 -0700 | [diff] [blame] | 3842 | needNL = false; |
| 3843 | } |
Dianne Hackborn | 7ad34e5 | 2013-06-05 18:41:45 -0700 | [diff] [blame] | 3844 | if (header1 != null) { |
| 3845 | pw.println(header1); |
| 3846 | header1 = null; |
| 3847 | } |
| 3848 | if (header2 != null) { |
| 3849 | pw.println(header2); |
| 3850 | header2 = null; |
Dianne Hackborn | 390517b | 2013-05-30 15:03:32 -0700 | [diff] [blame] | 3851 | } |
Bryce Lee | af691c0 | 2017-03-20 14:20:22 -0700 | [diff] [blame] | 3852 | if (lastTask != r.getTask()) { |
| 3853 | lastTask = r.getTask(); |
Craig Mautner | 8d341ef | 2013-03-26 09:03:27 -0700 | [diff] [blame] | 3854 | pw.print(prefix); |
| 3855 | pw.print(full ? "* " : " "); |
| 3856 | pw.println(lastTask); |
| 3857 | if (full) { |
| 3858 | lastTask.dump(pw, prefix + " "); |
| 3859 | } else if (complete) { |
| 3860 | // Complete + brief == give a summary. Isn't that obvious?!? |
| 3861 | if (lastTask.intent != null) { |
| 3862 | pw.print(prefix); pw.print(" "); |
| 3863 | pw.println(lastTask.intent.toInsecureStringWithClip()); |
| 3864 | } |
| 3865 | } |
| 3866 | } |
| 3867 | pw.print(prefix); pw.print(full ? " * " : " "); pw.print(label); |
| 3868 | pw.print(" #"); pw.print(i); pw.print(": "); |
| 3869 | pw.println(r); |
| 3870 | if (full) { |
| 3871 | r.dump(pw, innerPrefix); |
| 3872 | } else if (complete) { |
| 3873 | // Complete + brief == give a summary. Isn't that obvious?!? |
| 3874 | pw.print(innerPrefix); pw.println(r.intent.toInsecureString()); |
| 3875 | if (r.app != null) { |
| 3876 | pw.print(innerPrefix); pw.println(r.app); |
| 3877 | } |
| 3878 | } |
| 3879 | if (client && r.app != null && r.app.thread != null) { |
| 3880 | // flush anything that is already in the PrintWriter since the thread is going |
| 3881 | // to write to the file descriptor directly |
| 3882 | pw.flush(); |
| 3883 | try { |
| 3884 | TransferPipe tp = new TransferPipe(); |
| 3885 | try { |
Sudheer Shanka | cc6418f | 2016-10-13 12:03:44 -0700 | [diff] [blame] | 3886 | r.app.thread.dumpActivity(tp.getWriteFd(), r.appToken, innerPrefix, args); |
Craig Mautner | 8d341ef | 2013-03-26 09:03:27 -0700 | [diff] [blame] | 3887 | // Short timeout, since blocking here can |
| 3888 | // deadlock with the application. |
| 3889 | tp.go(fd, 2000); |
| 3890 | } finally { |
| 3891 | tp.kill(); |
| 3892 | } |
| 3893 | } catch (IOException e) { |
| 3894 | pw.println(innerPrefix + "Failure while dumping the activity: " + e); |
| 3895 | } catch (RemoteException e) { |
| 3896 | pw.println(innerPrefix + "Got a RemoteException while dumping the activity"); |
| 3897 | } |
| 3898 | needNL = true; |
| 3899 | } |
| 3900 | } |
Dianne Hackborn | 390517b | 2013-05-30 15:03:32 -0700 | [diff] [blame] | 3901 | return printed; |
Craig Mautner | 8d341ef | 2013-03-26 09:03:27 -0700 | [diff] [blame] | 3902 | } |
Craig Mautner | ce5f3cb | 2013-04-22 08:58:54 -0700 | [diff] [blame] | 3903 | |
Craig Mautner | f333327 | 2013-04-22 10:55:53 -0700 | [diff] [blame] | 3904 | void scheduleIdleTimeoutLocked(ActivityRecord next) { |
Wale Ogunwale | 0fc365c | 2015-05-25 19:35:42 -0700 | [diff] [blame] | 3905 | if (DEBUG_IDLE) Slog.d(TAG_IDLE, |
| 3906 | "scheduleIdleTimeoutLocked: Callers=" + Debug.getCallers(4)); |
Craig Mautner | c64f73e | 2013-04-24 16:44:56 -0700 | [diff] [blame] | 3907 | Message msg = mHandler.obtainMessage(IDLE_TIMEOUT_MSG, next); |
| 3908 | mHandler.sendMessageDelayed(msg, IDLE_TIMEOUT); |
Craig Mautner | f333327 | 2013-04-22 10:55:53 -0700 | [diff] [blame] | 3909 | } |
| 3910 | |
| 3911 | final void scheduleIdleLocked() { |
Craig Mautner | 05d2903 | 2013-05-03 13:40:13 -0700 | [diff] [blame] | 3912 | mHandler.sendEmptyMessage(IDLE_NOW_MSG); |
Craig Mautner | f333327 | 2013-04-22 10:55:53 -0700 | [diff] [blame] | 3913 | } |
| 3914 | |
| 3915 | void removeTimeoutsForActivityLocked(ActivityRecord r) { |
Wale Ogunwale | 0fc365c | 2015-05-25 19:35:42 -0700 | [diff] [blame] | 3916 | if (DEBUG_IDLE) Slog.d(TAG_IDLE, "removeTimeoutsForActivity: Callers=" |
| 3917 | + Debug.getCallers(4)); |
Craig Mautner | f333327 | 2013-04-22 10:55:53 -0700 | [diff] [blame] | 3918 | mHandler.removeMessages(IDLE_TIMEOUT_MSG, r); |
| 3919 | } |
| 3920 | |
Craig Mautner | 05d2903 | 2013-05-03 13:40:13 -0700 | [diff] [blame] | 3921 | final void scheduleResumeTopActivities() { |
Craig Mautner | 34b73df | 2014-01-12 21:11:08 -0800 | [diff] [blame] | 3922 | if (!mHandler.hasMessages(RESUME_TOP_ACTIVITY_MSG)) { |
| 3923 | mHandler.sendEmptyMessage(RESUME_TOP_ACTIVITY_MSG); |
| 3924 | } |
Craig Mautner | 05d2903 | 2013-05-03 13:40:13 -0700 | [diff] [blame] | 3925 | } |
| 3926 | |
Craig Mautner | 0eea92c | 2013-05-16 13:35:39 -0700 | [diff] [blame] | 3927 | void removeSleepTimeouts() { |
| 3928 | mSleepTimeout = false; |
| 3929 | mHandler.removeMessages(SLEEP_TIMEOUT_MSG); |
| 3930 | } |
| 3931 | |
| 3932 | final void scheduleSleepTimeout() { |
| 3933 | removeSleepTimeouts(); |
| 3934 | mHandler.sendEmptyMessageDelayed(SLEEP_TIMEOUT_MSG, SLEEP_TIMEOUT); |
| 3935 | } |
| 3936 | |
Craig Mautner | 4a1cb22 | 2013-12-04 16:14:06 -0800 | [diff] [blame] | 3937 | @Override |
| 3938 | public void onDisplayAdded(int displayId) { |
Dianne Hackborn | fb81d09 | 2015-08-03 17:14:46 -0700 | [diff] [blame] | 3939 | if (DEBUG_STACK) Slog.v(TAG, "Display added displayId=" + displayId); |
Craig Mautner | 4a1cb22 | 2013-12-04 16:14:06 -0800 | [diff] [blame] | 3940 | mHandler.sendMessage(mHandler.obtainMessage(HANDLE_DISPLAY_ADDED, displayId, 0)); |
| 3941 | } |
| 3942 | |
| 3943 | @Override |
| 3944 | public void onDisplayRemoved(int displayId) { |
Dianne Hackborn | fb81d09 | 2015-08-03 17:14:46 -0700 | [diff] [blame] | 3945 | if (DEBUG_STACK) Slog.v(TAG, "Display removed displayId=" + displayId); |
Craig Mautner | 4a1cb22 | 2013-12-04 16:14:06 -0800 | [diff] [blame] | 3946 | mHandler.sendMessage(mHandler.obtainMessage(HANDLE_DISPLAY_REMOVED, displayId, 0)); |
| 3947 | } |
| 3948 | |
| 3949 | @Override |
| 3950 | public void onDisplayChanged(int displayId) { |
Dianne Hackborn | fb81d09 | 2015-08-03 17:14:46 -0700 | [diff] [blame] | 3951 | if (DEBUG_STACK) Slog.v(TAG, "Display changed displayId=" + displayId); |
Craig Mautner | 4a1cb22 | 2013-12-04 16:14:06 -0800 | [diff] [blame] | 3952 | mHandler.sendMessage(mHandler.obtainMessage(HANDLE_DISPLAY_CHANGED, displayId, 0)); |
| 3953 | } |
| 3954 | |
Wale Ogunwale | f16a281 | 2015-04-01 11:23:15 -0700 | [diff] [blame] | 3955 | private void handleDisplayAdded(int displayId) { |
Craig Mautner | 4a1cb22 | 2013-12-04 16:14:06 -0800 | [diff] [blame] | 3956 | synchronized (mService) { |
Andrii Kulian | 62e6f25 | 2017-05-30 22:46:53 -0700 | [diff] [blame] | 3957 | getActivityDisplayOrCreateLocked(displayId); |
Craig Mautner | 4a1cb22 | 2013-12-04 16:14:06 -0800 | [diff] [blame] | 3958 | } |
Craig Mautner | 4a1cb22 | 2013-12-04 16:14:06 -0800 | [diff] [blame] | 3959 | } |
| 3960 | |
Andrii Kulian | ca007a6 | 2016-11-22 16:33:28 -0800 | [diff] [blame] | 3961 | /** Check if display with specified id is added to the list. */ |
| 3962 | boolean isDisplayAdded(int displayId) { |
Andrii Kulian | 62e6f25 | 2017-05-30 22:46:53 -0700 | [diff] [blame] | 3963 | return getActivityDisplayOrCreateLocked(displayId) != null; |
| 3964 | } |
| 3965 | |
| 3966 | /** |
| 3967 | * Get an existing instance of {@link ActivityDisplay} or create new if there is a |
| 3968 | * corresponding record in display manager. |
| 3969 | */ |
| 3970 | private ActivityDisplay getActivityDisplayOrCreateLocked(int displayId) { |
| 3971 | ActivityDisplay activityDisplay = mActivityDisplays.get(displayId); |
| 3972 | if (activityDisplay != null) { |
| 3973 | return activityDisplay; |
| 3974 | } |
| 3975 | if (mDisplayManager == null) { |
| 3976 | // The system isn't fully initialized yet. |
| 3977 | return null; |
| 3978 | } |
| 3979 | final Display display = mDisplayManager.getDisplay(displayId); |
| 3980 | if (display == null) { |
| 3981 | // The display is not registered in DisplayManager. |
| 3982 | return null; |
| 3983 | } |
| 3984 | // The display hasn't been added to ActivityManager yet, create a new record now. |
| 3985 | activityDisplay = new ActivityDisplay(displayId); |
| 3986 | if (activityDisplay.mDisplay == null) { |
| 3987 | Slog.w(TAG, "Display " + displayId + " gone before initialization complete"); |
| 3988 | return null; |
| 3989 | } |
| 3990 | mActivityDisplays.put(displayId, activityDisplay); |
| 3991 | calculateDefaultMinimalSizeOfResizeableTasks(activityDisplay); |
| 3992 | mWindowManager.onDisplayAdded(displayId); |
| 3993 | return activityDisplay; |
Andrii Kulian | ca007a6 | 2016-11-22 16:33:28 -0800 | [diff] [blame] | 3994 | } |
| 3995 | |
Filip Gruszczynski | d2f1d94 | 2015-10-14 15:10:12 -0700 | [diff] [blame] | 3996 | private void calculateDefaultMinimalSizeOfResizeableTasks(ActivityDisplay display) { |
Andrii Kulian | f66a83d | 2016-05-17 12:17:44 -0700 | [diff] [blame] | 3997 | mDefaultMinSizeOfResizeableTask = |
Jorim Jaggi | 19cf297 | 2016-04-07 23:26:10 -0700 | [diff] [blame] | 3998 | mService.mContext.getResources().getDimensionPixelSize( |
| 3999 | com.android.internal.R.dimen.default_minimal_size_resizable_task); |
Filip Gruszczynski | d2f1d94 | 2015-10-14 15:10:12 -0700 | [diff] [blame] | 4000 | } |
| 4001 | |
Wale Ogunwale | f16a281 | 2015-04-01 11:23:15 -0700 | [diff] [blame] | 4002 | private void handleDisplayRemoved(int displayId) { |
Andrii Kulian | a33818c | 2017-02-16 16:11:30 -0800 | [diff] [blame] | 4003 | if (displayId == DEFAULT_DISPLAY) { |
| 4004 | throw new IllegalArgumentException("Can't remove the primary display."); |
| 4005 | } |
| 4006 | |
Craig Mautner | 4a1cb22 | 2013-12-04 16:14:06 -0800 | [diff] [blame] | 4007 | synchronized (mService) { |
Craig Mautner | e0a3884 | 2013-12-16 16:14:02 -0800 | [diff] [blame] | 4008 | ActivityDisplay activityDisplay = mActivityDisplays.get(displayId); |
| 4009 | if (activityDisplay != null) { |
Andrii Kulian | 250d653 | 2017-02-08 23:30:45 -0800 | [diff] [blame] | 4010 | final boolean destroyContentOnRemoval |
| 4011 | = activityDisplay.shouldDestroyContentOnRemove(); |
Andrii Kulian | a33818c | 2017-02-16 16:11:30 -0800 | [diff] [blame] | 4012 | final ArrayList<ActivityStack> stacks = activityDisplay.mStacks; |
| 4013 | while (!stacks.isEmpty()) { |
| 4014 | final ActivityStack stack = stacks.get(0); |
Andrii Kulian | 250d653 | 2017-02-08 23:30:45 -0800 | [diff] [blame] | 4015 | if (destroyContentOnRemoval) { |
Andrii Kulian | a33818c | 2017-02-16 16:11:30 -0800 | [diff] [blame] | 4016 | moveStackToDisplayLocked(stack.mStackId, DEFAULT_DISPLAY, |
| 4017 | false /* onTop */); |
Andrii Kulian | 250d653 | 2017-02-08 23:30:45 -0800 | [diff] [blame] | 4018 | stack.finishAllActivitiesLocked(true /* immediately */); |
Andrii Kulian | a33818c | 2017-02-16 16:11:30 -0800 | [diff] [blame] | 4019 | } else { |
| 4020 | // Moving all tasks to fullscreen stack, because it's guaranteed to be |
| 4021 | // a valid launch stack for all activities. This way the task history from |
| 4022 | // external display will be preserved on primary after move. |
| 4023 | moveTasksToFullscreenStackLocked(stack.getStackId(), true /* onTop */); |
Andrii Kulian | 250d653 | 2017-02-08 23:30:45 -0800 | [diff] [blame] | 4024 | } |
Craig Mautner | 4a1cb22 | 2013-12-04 16:14:06 -0800 | [diff] [blame] | 4025 | } |
Craig Mautner | e0a3884 | 2013-12-16 16:14:02 -0800 | [diff] [blame] | 4026 | mActivityDisplays.remove(displayId); |
Bryce Lee | af3a400 | 2017-03-20 10:37:12 -0700 | [diff] [blame] | 4027 | mWindowManager.onDisplayRemoved(displayId); |
Craig Mautner | 4a1cb22 | 2013-12-04 16:14:06 -0800 | [diff] [blame] | 4028 | } |
| 4029 | } |
Craig Mautner | 4a1cb22 | 2013-12-04 16:14:06 -0800 | [diff] [blame] | 4030 | } |
| 4031 | |
Wale Ogunwale | f16a281 | 2015-04-01 11:23:15 -0700 | [diff] [blame] | 4032 | private void handleDisplayChanged(int displayId) { |
Craig Mautner | 4a1cb22 | 2013-12-04 16:14:06 -0800 | [diff] [blame] | 4033 | synchronized (mService) { |
Craig Mautner | e0a3884 | 2013-12-16 16:14:02 -0800 | [diff] [blame] | 4034 | ActivityDisplay activityDisplay = mActivityDisplays.get(displayId); |
| 4035 | if (activityDisplay != null) { |
Craig Mautner | 4a1cb22 | 2013-12-04 16:14:06 -0800 | [diff] [blame] | 4036 | // TODO: Update the bounds. |
| 4037 | } |
Bryce Lee | af3a400 | 2017-03-20 10:37:12 -0700 | [diff] [blame] | 4038 | mWindowManager.onDisplayChanged(displayId); |
Craig Mautner | 4a1cb22 | 2013-12-04 16:14:06 -0800 | [diff] [blame] | 4039 | } |
Craig Mautner | 4a1cb22 | 2013-12-04 16:14:06 -0800 | [diff] [blame] | 4040 | } |
| 4041 | |
Wale Ogunwale | f16a281 | 2015-04-01 11:23:15 -0700 | [diff] [blame] | 4042 | private StackInfo getStackInfoLocked(ActivityStack stack) { |
Andrii Kulian | 7e215d7 | 2017-04-26 18:33:28 -0700 | [diff] [blame] | 4043 | final int displayId = stack.mDisplayId; |
| 4044 | final ActivityDisplay display = mActivityDisplays.get(displayId); |
Craig Mautner | 4a1cb22 | 2013-12-04 16:14:06 -0800 | [diff] [blame] | 4045 | StackInfo info = new StackInfo(); |
Wale Ogunwale | 1666e31 | 2016-12-16 11:27:18 -0800 | [diff] [blame] | 4046 | stack.getWindowContainerBounds(info.bounds); |
Andrii Kulian | 7e215d7 | 2017-04-26 18:33:28 -0700 | [diff] [blame] | 4047 | info.displayId = displayId; |
Craig Mautner | 4a1cb22 | 2013-12-04 16:14:06 -0800 | [diff] [blame] | 4048 | info.stackId = stack.mStackId; |
Filip Gruszczynski | 21199bd | 2015-12-02 12:49:58 -0800 | [diff] [blame] | 4049 | info.userId = stack.mCurrentUser; |
Wale Ogunwale | cd501ec | 2017-04-07 08:53:41 -0700 | [diff] [blame] | 4050 | info.visible = stack.shouldBeVisible(null) == STACK_VISIBLE; |
Andrii Kulian | 62e6f25 | 2017-05-30 22:46:53 -0700 | [diff] [blame] | 4051 | // A stack might be not attached to a display. |
Winson | 529c8e4 | 2016-05-17 11:08:40 -0700 | [diff] [blame] | 4052 | info.position = display != null |
| 4053 | ? display.mStacks.indexOf(stack) |
| 4054 | : 0; |
Craig Mautner | 4a1cb22 | 2013-12-04 16:14:06 -0800 | [diff] [blame] | 4055 | |
| 4056 | ArrayList<TaskRecord> tasks = stack.getAllTasks(); |
| 4057 | final int numTasks = tasks.size(); |
| 4058 | int[] taskIds = new int[numTasks]; |
| 4059 | String[] taskNames = new String[numTasks]; |
Wale Ogunwale | e4a0c57 | 2015-06-30 08:40:31 -0700 | [diff] [blame] | 4060 | Rect[] taskBounds = new Rect[numTasks]; |
Filip Gruszczynski | 21199bd | 2015-12-02 12:49:58 -0800 | [diff] [blame] | 4061 | int[] taskUserIds = new int[numTasks]; |
Craig Mautner | 4a1cb22 | 2013-12-04 16:14:06 -0800 | [diff] [blame] | 4062 | for (int i = 0; i < numTasks; ++i) { |
| 4063 | final TaskRecord task = tasks.get(i); |
| 4064 | taskIds[i] = task.taskId; |
| 4065 | taskNames[i] = task.origActivity != null ? task.origActivity.flattenToString() |
| 4066 | : task.realActivity != null ? task.realActivity.flattenToString() |
| 4067 | : task.getTopActivity() != null ? task.getTopActivity().packageName |
| 4068 | : "unknown"; |
Wale Ogunwale | e4a0c57 | 2015-06-30 08:40:31 -0700 | [diff] [blame] | 4069 | taskBounds[i] = new Rect(); |
Wale Ogunwale | e1fe7fa2 | 2016-12-15 18:27:00 -0800 | [diff] [blame] | 4070 | task.getWindowContainerBounds(taskBounds[i]); |
Filip Gruszczynski | 21199bd | 2015-12-02 12:49:58 -0800 | [diff] [blame] | 4071 | taskUserIds[i] = task.userId; |
Craig Mautner | 4a1cb22 | 2013-12-04 16:14:06 -0800 | [diff] [blame] | 4072 | } |
| 4073 | info.taskIds = taskIds; |
| 4074 | info.taskNames = taskNames; |
Wale Ogunwale | 868a5e1 | 2015-08-02 16:19:20 -0700 | [diff] [blame] | 4075 | info.taskBounds = taskBounds; |
Filip Gruszczynski | 21199bd | 2015-12-02 12:49:58 -0800 | [diff] [blame] | 4076 | info.taskUserIds = taskUserIds; |
Winson | d46b727 | 2016-04-20 11:54:27 -0700 | [diff] [blame] | 4077 | |
| 4078 | final ActivityRecord top = stack.topRunningActivityLocked(); |
| 4079 | info.topActivity = top != null ? top.intent.getComponent() : null; |
Craig Mautner | 4a1cb22 | 2013-12-04 16:14:06 -0800 | [diff] [blame] | 4080 | return info; |
| 4081 | } |
| 4082 | |
| 4083 | StackInfo getStackInfoLocked(int stackId) { |
| 4084 | ActivityStack stack = getStack(stackId); |
| 4085 | if (stack != null) { |
Wale Ogunwale | f16a281 | 2015-04-01 11:23:15 -0700 | [diff] [blame] | 4086 | return getStackInfoLocked(stack); |
Craig Mautner | 4a1cb22 | 2013-12-04 16:14:06 -0800 | [diff] [blame] | 4087 | } |
| 4088 | return null; |
| 4089 | } |
| 4090 | |
| 4091 | ArrayList<StackInfo> getAllStackInfosLocked() { |
Wale Ogunwale | e4a0c57 | 2015-06-30 08:40:31 -0700 | [diff] [blame] | 4092 | ArrayList<StackInfo> list = new ArrayList<>(); |
Craig Mautner | e0a3884 | 2013-12-16 16:14:02 -0800 | [diff] [blame] | 4093 | for (int displayNdx = 0; displayNdx < mActivityDisplays.size(); ++displayNdx) { |
| 4094 | ArrayList<ActivityStack> stacks = mActivityDisplays.valueAt(displayNdx).mStacks; |
Craig Mautner | 4a1cb22 | 2013-12-04 16:14:06 -0800 | [diff] [blame] | 4095 | for (int ndx = stacks.size() - 1; ndx >= 0; --ndx) { |
Wale Ogunwale | f16a281 | 2015-04-01 11:23:15 -0700 | [diff] [blame] | 4096 | list.add(getStackInfoLocked(stacks.get(ndx))); |
Craig Mautner | 4a1cb22 | 2013-12-04 16:14:06 -0800 | [diff] [blame] | 4097 | } |
| 4098 | } |
| 4099 | return list; |
| 4100 | } |
| 4101 | |
Craig Mautner | 15df08a | 2015-04-01 12:17:18 -0700 | [diff] [blame] | 4102 | TaskRecord getLockedTaskLocked() { |
| 4103 | final int top = mLockTaskModeTasks.size() - 1; |
| 4104 | if (top >= 0) { |
| 4105 | return mLockTaskModeTasks.get(top); |
| 4106 | } |
| 4107 | return null; |
| 4108 | } |
| 4109 | |
| 4110 | boolean isLockedTask(TaskRecord task) { |
| 4111 | return mLockTaskModeTasks.contains(task); |
| 4112 | } |
| 4113 | |
| 4114 | boolean isLastLockedTask(TaskRecord task) { |
| 4115 | return mLockTaskModeTasks.size() == 1 && mLockTaskModeTasks.contains(task); |
| 4116 | } |
| 4117 | |
| 4118 | void removeLockedTaskLocked(final TaskRecord task) { |
Craig Mautner | 432f64e | 2015-05-20 14:59:57 -0700 | [diff] [blame] | 4119 | if (!mLockTaskModeTasks.remove(task)) { |
| 4120 | return; |
| 4121 | } |
| 4122 | if (DEBUG_LOCKTASK) Slog.w(TAG_LOCKTASK, "removeLockedTaskLocked: removed " + task); |
| 4123 | if (mLockTaskModeTasks.isEmpty()) { |
Craig Mautner | 15df08a | 2015-04-01 12:17:18 -0700 | [diff] [blame] | 4124 | // Last one. |
Craig Mautner | e057020 | 2015-05-13 13:06:11 -0700 | [diff] [blame] | 4125 | if (DEBUG_LOCKTASK) Slog.d(TAG_LOCKTASK, "removeLockedTask: task=" + task + |
| 4126 | " last task, reverting locktask mode. Callers=" + Debug.getCallers(3)); |
Craig Mautner | 15df08a | 2015-04-01 12:17:18 -0700 | [diff] [blame] | 4127 | final Message lockTaskMsg = Message.obtain(); |
| 4128 | lockTaskMsg.arg1 = task.userId; |
| 4129 | lockTaskMsg.what = LOCK_TASK_END_MSG; |
| 4130 | mHandler.sendMessage(lockTaskMsg); |
| 4131 | } |
| 4132 | } |
| 4133 | |
Andrii Kulian | 036e3ad | 2017-04-19 10:55:10 -0700 | [diff] [blame] | 4134 | void handleNonResizableTaskIfNeeded(TaskRecord task, int preferredStackId, |
| 4135 | int preferredDisplayId, int actualStackId) { |
| 4136 | handleNonResizableTaskIfNeeded(task, preferredStackId, preferredDisplayId, actualStackId, |
Andrii Kulian | c2791664 | 2016-04-12 17:59:27 -0700 | [diff] [blame] | 4137 | false /* forceNonResizable */); |
| 4138 | } |
| 4139 | |
Andrii Kulian | 036e3ad | 2017-04-19 10:55:10 -0700 | [diff] [blame] | 4140 | private void handleNonResizableTaskIfNeeded(TaskRecord task, int preferredStackId, |
| 4141 | int preferredDisplayId, int actualStackId, boolean forceNonResizable) { |
| 4142 | final boolean isSecondaryDisplayPreferred = |
| 4143 | (preferredDisplayId != DEFAULT_DISPLAY && preferredDisplayId != INVALID_DISPLAY) |
| 4144 | || StackId.isDynamicStack(preferredStackId); |
| 4145 | if (((!isStackDockedInEffect(actualStackId) && preferredStackId != DOCKED_STACK_ID) |
| 4146 | && !isSecondaryDisplayPreferred) || task.isHomeTask()) { |
Wale Ogunwale | b9b16a7 | 2016-01-27 12:24:44 -0800 | [diff] [blame] | 4147 | return; |
| 4148 | } |
| 4149 | |
Andrii Kulian | 036e3ad | 2017-04-19 10:55:10 -0700 | [diff] [blame] | 4150 | // Handle incorrect launch/move to secondary display if needed. |
| 4151 | final boolean launchOnSecondaryDisplayFailed; |
| 4152 | if (isSecondaryDisplayPreferred) { |
| 4153 | final int actualDisplayId = task.getStack().mDisplayId; |
| 4154 | if (!task.canBeLaunchedOnDisplay(actualDisplayId)) { |
| 4155 | // The task landed on an inappropriate display somehow, move it to the default |
| 4156 | // display. |
| 4157 | // TODO(multi-display): Find proper stack for the task on the default display. |
| 4158 | mService.moveTaskToStack(task.taskId, FULLSCREEN_WORKSPACE_STACK_ID, |
| 4159 | true /* toTop */); |
| 4160 | launchOnSecondaryDisplayFailed = true; |
| 4161 | } else { |
| 4162 | // The task might have landed on a display different from requested. |
| 4163 | launchOnSecondaryDisplayFailed = actualDisplayId == DEFAULT_DISPLAY |
| 4164 | || (preferredDisplayId != INVALID_DISPLAY |
| 4165 | && preferredDisplayId != actualDisplayId); |
| 4166 | } |
| 4167 | } else { |
| 4168 | // The task wasn't requested to be on a secondary display. |
| 4169 | launchOnSecondaryDisplayFailed = false; |
| 4170 | } |
| 4171 | |
Jorim Jaggi | cd13d33 | 2016-04-27 15:40:20 -0700 | [diff] [blame] | 4172 | final ActivityRecord topActivity = task.getTopActivity(); |
Andrii Kulian | 036e3ad | 2017-04-19 10:55:10 -0700 | [diff] [blame] | 4173 | if (launchOnSecondaryDisplayFailed || !task.supportsSplitScreen() || forceNonResizable) { |
| 4174 | if (launchOnSecondaryDisplayFailed) { |
| 4175 | // Display a warning toast that we tried to put a non-resizeable task on a secondary |
| 4176 | // display with config different from global config. |
| 4177 | mService.mTaskChangeNotificationController |
| 4178 | .notifyActivityLaunchOnSecondaryDisplayFailed(); |
| 4179 | } else { |
| 4180 | // Display a warning toast that we tried to put a non-dockable task in the docked |
| 4181 | // stack. |
| 4182 | mService.mTaskChangeNotificationController.notifyActivityDismissingDockedStack(); |
| 4183 | } |
Jorim Jaggi | d53f092 | 2016-04-06 22:16:23 -0700 | [diff] [blame] | 4184 | |
Andrii Kulian | c2791664 | 2016-04-12 17:59:27 -0700 | [diff] [blame] | 4185 | // Dismiss docked stack. If task appeared to be in docked stack but is not resizable - |
| 4186 | // we need to move it to top of fullscreen stack, otherwise it will be covered. |
Wale Ogunwale | 9a98c52 | 2016-04-27 09:23:55 -0700 | [diff] [blame] | 4187 | moveTasksToFullscreenStackLocked(DOCKED_STACK_ID, actualStackId == DOCKED_STACK_ID); |
Winson Chung | d339538 | 2016-12-13 11:49:09 -0800 | [diff] [blame] | 4188 | } else if (topActivity != null && topActivity.isNonResizableOrForcedResizable() |
Jorim Jaggi | cd13d33 | 2016-04-27 15:40:20 -0700 | [diff] [blame] | 4189 | && !topActivity.noDisplay) { |
Andrii Kulian | 036e3ad | 2017-04-19 10:55:10 -0700 | [diff] [blame] | 4190 | final String packageName = topActivity.appInfo.packageName; |
| 4191 | final int reason = isSecondaryDisplayPreferred |
| 4192 | ? FORCED_RESIZEABLE_REASON_SECONDARY_DISPLAY |
| 4193 | : FORCED_RESIZEABLE_REASON_SPLIT_SCREEN; |
Yorke Lee | bd54c2a | 2016-10-25 13:49:23 -0700 | [diff] [blame] | 4194 | mService.mTaskChangeNotificationController.notifyActivityForcedResizable( |
Andrii Kulian | 036e3ad | 2017-04-19 10:55:10 -0700 | [diff] [blame] | 4195 | task.taskId, reason, packageName); |
Wale Ogunwale | b9b16a7 | 2016-01-27 12:24:44 -0800 | [diff] [blame] | 4196 | } |
Chong Zhang | b15758a | 2015-11-17 12:12:03 -0800 | [diff] [blame] | 4197 | } |
| 4198 | |
Craig Mautner | 6cd6cec | 2015-04-01 00:02:12 -0700 | [diff] [blame] | 4199 | void showLockTaskToast() { |
Hall Liu | 45784f1 | 2016-05-31 15:50:48 -0700 | [diff] [blame] | 4200 | if (mLockTaskNotify != null) { |
| 4201 | mLockTaskNotify.showToast(mLockTaskModeState); |
| 4202 | } |
Jason Monk | a8f569c | 2014-07-07 12:15:21 -0400 | [diff] [blame] | 4203 | } |
| 4204 | |
Craig Mautner | c21ae9e | 2015-04-15 09:45:42 -0700 | [diff] [blame] | 4205 | void showLockTaskEscapeMessageLocked(TaskRecord task) { |
| 4206 | if (mLockTaskModeTasks.contains(task)) { |
| 4207 | mHandler.sendEmptyMessage(SHOW_LOCK_TASK_ESCAPE_MESSAGE_MSG); |
| 4208 | } |
| 4209 | } |
| 4210 | |
Craig Mautner | 432f64e | 2015-05-20 14:59:57 -0700 | [diff] [blame] | 4211 | void setLockTaskModeLocked(TaskRecord task, int lockTaskModeState, String reason, |
| 4212 | boolean andResume) { |
Craig Mautner | aea74a5 | 2014-03-08 14:23:10 -0800 | [diff] [blame] | 4213 | if (task == null) { |
Christopher Tate | 3bd9061 | 2014-06-18 16:37:52 -0700 | [diff] [blame] | 4214 | // Take out of lock task mode if necessary |
Craig Mautner | 15df08a | 2015-04-01 12:17:18 -0700 | [diff] [blame] | 4215 | final TaskRecord lockedTask = getLockedTaskLocked(); |
| 4216 | if (lockedTask != null) { |
| 4217 | removeLockedTaskLocked(lockedTask); |
| 4218 | if (!mLockTaskModeTasks.isEmpty()) { |
| 4219 | // There are locked tasks remaining, can only finish this task, not unlock it. |
Craig Mautner | e057020 | 2015-05-13 13:06:11 -0700 | [diff] [blame] | 4220 | if (DEBUG_LOCKTASK) Slog.w(TAG_LOCKTASK, |
| 4221 | "setLockTaskModeLocked: Tasks remaining, can't unlock"); |
Craig Mautner | 15df08a | 2015-04-01 12:17:18 -0700 | [diff] [blame] | 4222 | lockedTask.performClearTaskLocked(); |
Wale Ogunwale | d046a01 | 2015-12-24 13:05:59 -0800 | [diff] [blame] | 4223 | resumeFocusedStackTopActivityLocked(); |
Craig Mautner | 15df08a | 2015-04-01 12:17:18 -0700 | [diff] [blame] | 4224 | return; |
| 4225 | } |
Christopher Tate | 3bd9061 | 2014-06-18 16:37:52 -0700 | [diff] [blame] | 4226 | } |
Craig Mautner | e057020 | 2015-05-13 13:06:11 -0700 | [diff] [blame] | 4227 | if (DEBUG_LOCKTASK) Slog.w(TAG_LOCKTASK, |
| 4228 | "setLockTaskModeLocked: No tasks to unlock. Callers=" + Debug.getCallers(4)); |
Craig Mautner | aea74a5 | 2014-03-08 14:23:10 -0800 | [diff] [blame] | 4229 | return; |
| 4230 | } |
Craig Mautner | 15df08a | 2015-04-01 12:17:18 -0700 | [diff] [blame] | 4231 | |
| 4232 | // Should have already been checked, but do it again. |
| 4233 | if (task.mLockTaskAuth == LOCK_TASK_AUTH_DONT_LOCK) { |
Craig Mautner | e057020 | 2015-05-13 13:06:11 -0700 | [diff] [blame] | 4234 | if (DEBUG_LOCKTASK) Slog.w(TAG_LOCKTASK, |
| 4235 | "setLockTaskModeLocked: Can't lock due to auth"); |
Craig Mautner | aea74a5 | 2014-03-08 14:23:10 -0800 | [diff] [blame] | 4236 | return; |
| 4237 | } |
Craig Mautner | 15df08a | 2015-04-01 12:17:18 -0700 | [diff] [blame] | 4238 | if (isLockTaskModeViolation(task)) { |
Craig Mautner | e057020 | 2015-05-13 13:06:11 -0700 | [diff] [blame] | 4239 | Slog.e(TAG_LOCKTASK, "setLockTaskMode: Attempt to start an unauthorized lock task."); |
Craig Mautner | 15df08a | 2015-04-01 12:17:18 -0700 | [diff] [blame] | 4240 | return; |
| 4241 | } |
| 4242 | |
| 4243 | if (mLockTaskModeTasks.isEmpty()) { |
| 4244 | // First locktask. |
| 4245 | final Message lockTaskMsg = Message.obtain(); |
| 4246 | lockTaskMsg.obj = task.intent.getComponent().getPackageName(); |
| 4247 | lockTaskMsg.arg1 = task.userId; |
| 4248 | lockTaskMsg.what = LOCK_TASK_START_MSG; |
| 4249 | lockTaskMsg.arg2 = lockTaskModeState; |
| 4250 | mHandler.sendMessage(lockTaskMsg); |
| 4251 | } |
| 4252 | // Add it or move it to the top. |
Craig Mautner | e057020 | 2015-05-13 13:06:11 -0700 | [diff] [blame] | 4253 | if (DEBUG_LOCKTASK) Slog.w(TAG_LOCKTASK, "setLockTaskModeLocked: Locking to " + task + |
| 4254 | " Callers=" + Debug.getCallers(4)); |
Craig Mautner | 15df08a | 2015-04-01 12:17:18 -0700 | [diff] [blame] | 4255 | mLockTaskModeTasks.remove(task); |
| 4256 | mLockTaskModeTasks.add(task); |
| 4257 | |
| 4258 | if (task.mLockTaskUid == -1) { |
Wale Ogunwale | 5c18d05 | 2015-10-12 10:34:14 -0700 | [diff] [blame] | 4259 | task.mLockTaskUid = task.effectiveUid; |
Craig Mautner | 15df08a | 2015-04-01 12:17:18 -0700 | [diff] [blame] | 4260 | } |
Craig Mautner | 432f64e | 2015-05-20 14:59:57 -0700 | [diff] [blame] | 4261 | |
| 4262 | if (andResume) { |
Andrii Kulian | c2791664 | 2016-04-12 17:59:27 -0700 | [diff] [blame] | 4263 | findTaskToMoveToFrontLocked(task, 0, null, reason, |
| 4264 | lockTaskModeState != LOCK_TASK_MODE_NONE); |
Wale Ogunwale | d046a01 | 2015-12-24 13:05:59 -0800 | [diff] [blame] | 4265 | resumeFocusedStackTopActivityLocked(); |
Jorim Jaggi | a42938e | 2016-11-22 14:31:38 +0100 | [diff] [blame] | 4266 | mWindowManager.executeAppTransition(); |
Andrii Kulian | c2791664 | 2016-04-12 17:59:27 -0700 | [diff] [blame] | 4267 | } else if (lockTaskModeState != LOCK_TASK_MODE_NONE) { |
Andrii Kulian | 036e3ad | 2017-04-19 10:55:10 -0700 | [diff] [blame] | 4268 | handleNonResizableTaskIfNeeded(task, INVALID_STACK_ID, DEFAULT_DISPLAY, |
| 4269 | task.getStackId(), true /* forceNonResizable */); |
Craig Mautner | 432f64e | 2015-05-20 14:59:57 -0700 | [diff] [blame] | 4270 | } |
Craig Mautner | aea74a5 | 2014-03-08 14:23:10 -0800 | [diff] [blame] | 4271 | } |
| 4272 | |
| 4273 | boolean isLockTaskModeViolation(TaskRecord task) { |
Jason Monk | 25d237b | 2015-06-19 10:39:39 -0400 | [diff] [blame] | 4274 | return isLockTaskModeViolation(task, false); |
| 4275 | } |
| 4276 | |
| 4277 | boolean isLockTaskModeViolation(TaskRecord task, boolean isNewClearTask) { |
| 4278 | if (getLockedTaskLocked() == task && !isNewClearTask) { |
Craig Mautner | 15df08a | 2015-04-01 12:17:18 -0700 | [diff] [blame] | 4279 | return false; |
| 4280 | } |
| 4281 | final int lockTaskAuth = task.mLockTaskAuth; |
| 4282 | switch (lockTaskAuth) { |
| 4283 | case LOCK_TASK_AUTH_DONT_LOCK: |
| 4284 | return !mLockTaskModeTasks.isEmpty(); |
Benjamin Franz | 469dd58 | 2015-06-09 14:24:36 +0100 | [diff] [blame] | 4285 | case LOCK_TASK_AUTH_LAUNCHABLE_PRIV: |
Craig Mautner | 15df08a | 2015-04-01 12:17:18 -0700 | [diff] [blame] | 4286 | case LOCK_TASK_AUTH_LAUNCHABLE: |
| 4287 | case LOCK_TASK_AUTH_WHITELISTED: |
| 4288 | return false; |
| 4289 | case LOCK_TASK_AUTH_PINNABLE: |
| 4290 | // Pinnable tasks can't be launched on top of locktask tasks. |
| 4291 | return !mLockTaskModeTasks.isEmpty(); |
| 4292 | default: |
| 4293 | Slog.w(TAG, "isLockTaskModeViolation: invalid lockTaskAuth value=" + lockTaskAuth); |
| 4294 | return true; |
| 4295 | } |
Craig Mautner | aea74a5 | 2014-03-08 14:23:10 -0800 | [diff] [blame] | 4296 | } |
| 4297 | |
Craig Mautner | 15df08a | 2015-04-01 12:17:18 -0700 | [diff] [blame] | 4298 | void onLockTaskPackagesUpdatedLocked() { |
| 4299 | boolean didSomething = false; |
| 4300 | for (int taskNdx = mLockTaskModeTasks.size() - 1; taskNdx >= 0; --taskNdx) { |
| 4301 | final TaskRecord lockedTask = mLockTaskModeTasks.get(taskNdx); |
Benjamin Franz | 469dd58 | 2015-06-09 14:24:36 +0100 | [diff] [blame] | 4302 | final boolean wasWhitelisted = |
| 4303 | (lockedTask.mLockTaskAuth == LOCK_TASK_AUTH_LAUNCHABLE) || |
| 4304 | (lockedTask.mLockTaskAuth == LOCK_TASK_AUTH_WHITELISTED); |
Craig Mautner | 15df08a | 2015-04-01 12:17:18 -0700 | [diff] [blame] | 4305 | lockedTask.setLockTaskAuth(); |
Benjamin Franz | 469dd58 | 2015-06-09 14:24:36 +0100 | [diff] [blame] | 4306 | final boolean isWhitelisted = |
| 4307 | (lockedTask.mLockTaskAuth == LOCK_TASK_AUTH_LAUNCHABLE) || |
| 4308 | (lockedTask.mLockTaskAuth == LOCK_TASK_AUTH_WHITELISTED); |
| 4309 | if (wasWhitelisted && !isWhitelisted) { |
Craig Mautner | 15df08a | 2015-04-01 12:17:18 -0700 | [diff] [blame] | 4310 | // Lost whitelisting authorization. End it now. |
Craig Mautner | 432f64e | 2015-05-20 14:59:57 -0700 | [diff] [blame] | 4311 | if (DEBUG_LOCKTASK) Slog.d(TAG_LOCKTASK, "onLockTaskPackagesUpdated: removing " + |
| 4312 | lockedTask + " mLockTaskAuth=" + lockedTask.lockTaskAuthToString()); |
Craig Mautner | 15df08a | 2015-04-01 12:17:18 -0700 | [diff] [blame] | 4313 | removeLockedTaskLocked(lockedTask); |
| 4314 | lockedTask.performClearTaskLocked(); |
| 4315 | didSomething = true; |
| 4316 | } |
| 4317 | } |
| 4318 | for (int displayNdx = mActivityDisplays.size() - 1; displayNdx >= 0; --displayNdx) { |
| 4319 | ArrayList<ActivityStack> stacks = mActivityDisplays.valueAt(displayNdx).mStacks; |
| 4320 | for (int stackNdx = stacks.size() - 1; stackNdx >= 0; --stackNdx) { |
| 4321 | final ActivityStack stack = stacks.get(stackNdx); |
| 4322 | stack.onLockTaskPackagesUpdatedLocked(); |
| 4323 | } |
| 4324 | } |
Craig Mautner | e057020 | 2015-05-13 13:06:11 -0700 | [diff] [blame] | 4325 | final ActivityRecord r = topRunningActivityLocked(); |
Bryce Lee | af691c0 | 2017-03-20 14:20:22 -0700 | [diff] [blame] | 4326 | final TaskRecord task = r != null ? r.getTask() : null; |
Craig Mautner | e057020 | 2015-05-13 13:06:11 -0700 | [diff] [blame] | 4327 | if (mLockTaskModeTasks.isEmpty() && task != null |
| 4328 | && task.mLockTaskAuth == LOCK_TASK_AUTH_LAUNCHABLE) { |
| 4329 | // This task must have just been authorized. |
Craig Mautner | 432f64e | 2015-05-20 14:59:57 -0700 | [diff] [blame] | 4330 | if (DEBUG_LOCKTASK) Slog.d(TAG_LOCKTASK, |
| 4331 | "onLockTaskPackagesUpdated: starting new locktask task=" + task); |
| 4332 | setLockTaskModeLocked(task, ActivityManager.LOCK_TASK_MODE_LOCKED, "package updated", |
| 4333 | false); |
| 4334 | didSomething = true; |
Craig Mautner | e057020 | 2015-05-13 13:06:11 -0700 | [diff] [blame] | 4335 | } |
Craig Mautner | 15df08a | 2015-04-01 12:17:18 -0700 | [diff] [blame] | 4336 | if (didSomething) { |
Wale Ogunwale | d046a01 | 2015-12-24 13:05:59 -0800 | [diff] [blame] | 4337 | resumeFocusedStackTopActivityLocked(); |
Craig Mautner | aea74a5 | 2014-03-08 14:23:10 -0800 | [diff] [blame] | 4338 | } |
| 4339 | } |
| 4340 | |
Benjamin Franz | 4326114 | 2015-02-11 15:59:44 +0000 | [diff] [blame] | 4341 | int getLockTaskModeState() { |
| 4342 | return mLockTaskModeState; |
Craig Mautner | aea74a5 | 2014-03-08 14:23:10 -0800 | [diff] [blame] | 4343 | } |
| 4344 | |
Jorim Jaggi | fe89d12 | 2015-12-22 16:28:44 +0100 | [diff] [blame] | 4345 | void activityRelaunchedLocked(IBinder token) { |
| 4346 | mWindowManager.notifyAppRelaunchingFinished(token); |
Wale Ogunwale | 3e99736 | 2016-09-06 10:37:56 -0700 | [diff] [blame] | 4347 | if (mService.isSleepingOrShuttingDownLocked()) { |
| 4348 | final ActivityRecord r = ActivityRecord.isInStackLocked(token); |
| 4349 | if (r != null) { |
| 4350 | r.setSleeping(true, true); |
| 4351 | } |
| 4352 | } |
Jorim Jaggi | fe89d12 | 2015-12-22 16:28:44 +0100 | [diff] [blame] | 4353 | } |
| 4354 | |
| 4355 | void activityRelaunchingLocked(ActivityRecord r) { |
| 4356 | mWindowManager.notifyAppRelaunching(r.appToken); |
| 4357 | } |
| 4358 | |
Filip Gruszczynski | 77d9448 | 2015-12-11 13:59:52 -0800 | [diff] [blame] | 4359 | void logStackState() { |
| 4360 | mActivityMetricsLogger.logWindowState(); |
| 4361 | } |
| 4362 | |
Winson Chung | 5af42fc | 2017-03-24 17:11:33 -0700 | [diff] [blame] | 4363 | void scheduleUpdateMultiWindowMode(TaskRecord task) { |
Winson Chung | 8bca9e4 | 2017-04-16 15:59:43 -0700 | [diff] [blame] | 4364 | // If the stack is animating in a way where we will be forcing a multi-mode change at the |
| 4365 | // end, then ensure that we defer all in between multi-window mode changes |
| 4366 | if (task.getStack().deferScheduleMultiWindowModeChanged()) { |
| 4367 | return; |
| 4368 | } |
| 4369 | |
Wale Ogunwale | 22e2526 | 2016-02-01 10:32:02 -0800 | [diff] [blame] | 4370 | for (int i = task.mActivities.size() - 1; i >= 0; i--) { |
| 4371 | final ActivityRecord r = task.mActivities.get(i); |
| 4372 | if (r.app != null && r.app.thread != null) { |
| 4373 | mMultiWindowModeChangedActivities.add(r); |
| 4374 | } |
| 4375 | } |
| 4376 | |
| 4377 | if (!mHandler.hasMessages(REPORT_MULTI_WINDOW_MODE_CHANGED_MSG)) { |
| 4378 | mHandler.sendEmptyMessage(REPORT_MULTI_WINDOW_MODE_CHANGED_MSG); |
| 4379 | } |
| 4380 | } |
| 4381 | |
Winson Chung | 5af42fc | 2017-03-24 17:11:33 -0700 | [diff] [blame] | 4382 | void scheduleUpdatePictureInPictureModeIfNeeded(TaskRecord task, ActivityStack prevStack) { |
Andrii Kulian | 02b7a83 | 2016-10-06 23:11:56 -0700 | [diff] [blame] | 4383 | final ActivityStack stack = task.getStack(); |
Wale Ogunwale | 22e2526 | 2016-02-01 10:32:02 -0800 | [diff] [blame] | 4384 | if (prevStack == null || prevStack == stack |
| 4385 | || (prevStack.mStackId != PINNED_STACK_ID && stack.mStackId != PINNED_STACK_ID)) { |
| 4386 | return; |
| 4387 | } |
| 4388 | |
Winson Chung | 5af42fc | 2017-03-24 17:11:33 -0700 | [diff] [blame] | 4389 | scheduleUpdatePictureInPictureModeIfNeeded(task, stack.mBounds, false /* immediate */); |
| 4390 | } |
Wale Ogunwale | 22e2526 | 2016-02-01 10:32:02 -0800 | [diff] [blame] | 4391 | |
Winson Chung | 5af42fc | 2017-03-24 17:11:33 -0700 | [diff] [blame] | 4392 | void scheduleUpdatePictureInPictureModeIfNeeded(TaskRecord task, Rect targetStackBounds, |
| 4393 | boolean immediate) { |
| 4394 | |
| 4395 | if (immediate) { |
| 4396 | mHandler.removeMessages(REPORT_PIP_MODE_CHANGED_MSG); |
| 4397 | for (int i = task.mActivities.size() - 1; i >= 0; i--) { |
| 4398 | final ActivityRecord r = task.mActivities.get(i); |
| 4399 | if (r.app != null && r.app.thread != null) { |
| 4400 | r.updatePictureInPictureMode(targetStackBounds); |
| 4401 | } |
| 4402 | } |
| 4403 | } else { |
| 4404 | for (int i = task.mActivities.size() - 1; i >= 0; i--) { |
| 4405 | final ActivityRecord r = task.mActivities.get(i); |
| 4406 | if (r.app != null && r.app.thread != null) { |
| 4407 | mPipModeChangedActivities.add(r); |
| 4408 | } |
| 4409 | } |
| 4410 | mPipModeChangedTargetStackBounds = targetStackBounds; |
| 4411 | |
| 4412 | if (!mHandler.hasMessages(REPORT_PIP_MODE_CHANGED_MSG)) { |
| 4413 | mHandler.sendEmptyMessage(REPORT_PIP_MODE_CHANGED_MSG); |
| 4414 | } |
Wale Ogunwale | 22e2526 | 2016-02-01 10:32:02 -0800 | [diff] [blame] | 4415 | } |
| 4416 | } |
| 4417 | |
Tony Mak | 853304c | 2016-04-18 15:17:41 +0100 | [diff] [blame] | 4418 | void setDockedStackMinimized(boolean minimized) { |
| 4419 | mIsDockMinimized = minimized; |
Tony Mak | 853304c | 2016-04-18 15:17:41 +0100 | [diff] [blame] | 4420 | } |
| 4421 | |
Craig Mautner | ce5f3cb | 2013-04-22 08:58:54 -0700 | [diff] [blame] | 4422 | private final class ActivityStackSupervisorHandler extends Handler { |
Craig Mautner | f333327 | 2013-04-22 10:55:53 -0700 | [diff] [blame] | 4423 | |
Craig Mautner | ce5f3cb | 2013-04-22 08:58:54 -0700 | [diff] [blame] | 4424 | public ActivityStackSupervisorHandler(Looper looper) { |
| 4425 | super(looper); |
| 4426 | } |
| 4427 | |
Winson Chung | 4dabf23 | 2017-01-25 13:25:22 -0800 | [diff] [blame] | 4428 | void activityIdleInternal(ActivityRecord r, boolean processPausingActivities) { |
Craig Mautner | f333327 | 2013-04-22 10:55:53 -0700 | [diff] [blame] | 4429 | synchronized (mService) { |
Winson Chung | 4dabf23 | 2017-01-25 13:25:22 -0800 | [diff] [blame] | 4430 | activityIdleInternalLocked(r != null ? r.appToken : null, true /* fromTimeout */, |
| 4431 | processPausingActivities, null); |
Craig Mautner | f333327 | 2013-04-22 10:55:53 -0700 | [diff] [blame] | 4432 | } |
Craig Mautner | 7ea5bd4 | 2013-07-05 15:27:08 -0700 | [diff] [blame] | 4433 | } |
| 4434 | |
Craig Mautner | ce5f3cb | 2013-04-22 08:58:54 -0700 | [diff] [blame] | 4435 | @Override |
| 4436 | public void handleMessage(Message msg) { |
| 4437 | switch (msg.what) { |
Wale Ogunwale | 22e2526 | 2016-02-01 10:32:02 -0800 | [diff] [blame] | 4438 | case REPORT_MULTI_WINDOW_MODE_CHANGED_MSG: { |
| 4439 | synchronized (mService) { |
| 4440 | for (int i = mMultiWindowModeChangedActivities.size() - 1; i >= 0; i--) { |
| 4441 | final ActivityRecord r = mMultiWindowModeChangedActivities.remove(i); |
Winson Chung | 5af42fc | 2017-03-24 17:11:33 -0700 | [diff] [blame] | 4442 | r.updateMultiWindowMode(); |
Wale Ogunwale | 22e2526 | 2016-02-01 10:32:02 -0800 | [diff] [blame] | 4443 | } |
| 4444 | } |
| 4445 | } break; |
| 4446 | case REPORT_PIP_MODE_CHANGED_MSG: { |
| 4447 | synchronized (mService) { |
| 4448 | for (int i = mPipModeChangedActivities.size() - 1; i >= 0; i--) { |
| 4449 | final ActivityRecord r = mPipModeChangedActivities.remove(i); |
Winson Chung | 5af42fc | 2017-03-24 17:11:33 -0700 | [diff] [blame] | 4450 | r.updatePictureInPictureMode(mPipModeChangedTargetStackBounds); |
Wale Ogunwale | 22e2526 | 2016-02-01 10:32:02 -0800 | [diff] [blame] | 4451 | } |
| 4452 | } |
| 4453 | } break; |
Craig Mautner | f333327 | 2013-04-22 10:55:53 -0700 | [diff] [blame] | 4454 | case IDLE_TIMEOUT_MSG: { |
Wale Ogunwale | 0fc365c | 2015-05-25 19:35:42 -0700 | [diff] [blame] | 4455 | if (DEBUG_IDLE) Slog.d(TAG_IDLE, |
| 4456 | "handleMessage: IDLE_TIMEOUT_MSG: r=" + msg.obj); |
Craig Mautner | f333327 | 2013-04-22 10:55:53 -0700 | [diff] [blame] | 4457 | if (mService.mDidDexOpt) { |
| 4458 | mService.mDidDexOpt = false; |
| 4459 | Message nmsg = mHandler.obtainMessage(IDLE_TIMEOUT_MSG); |
| 4460 | nmsg.obj = msg.obj; |
| 4461 | mHandler.sendMessageDelayed(nmsg, IDLE_TIMEOUT); |
| 4462 | return; |
| 4463 | } |
| 4464 | // We don't at this point know if the activity is fullscreen, |
| 4465 | // so we need to be conservative and assume it isn't. |
Winson Chung | 4dabf23 | 2017-01-25 13:25:22 -0800 | [diff] [blame] | 4466 | activityIdleInternal((ActivityRecord) msg.obj, |
| 4467 | true /* processPausingActivities */); |
Craig Mautner | f333327 | 2013-04-22 10:55:53 -0700 | [diff] [blame] | 4468 | } break; |
| 4469 | case IDLE_NOW_MSG: { |
Wale Ogunwale | 0fc365c | 2015-05-25 19:35:42 -0700 | [diff] [blame] | 4470 | 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] | 4471 | activityIdleInternal((ActivityRecord) msg.obj, |
| 4472 | false /* processPausingActivities */); |
Craig Mautner | f333327 | 2013-04-22 10:55:53 -0700 | [diff] [blame] | 4473 | } break; |
Craig Mautner | 05d2903 | 2013-05-03 13:40:13 -0700 | [diff] [blame] | 4474 | case RESUME_TOP_ACTIVITY_MSG: { |
| 4475 | synchronized (mService) { |
Wale Ogunwale | d046a01 | 2015-12-24 13:05:59 -0800 | [diff] [blame] | 4476 | resumeFocusedStackTopActivityLocked(); |
Craig Mautner | 05d2903 | 2013-05-03 13:40:13 -0700 | [diff] [blame] | 4477 | } |
| 4478 | } break; |
Craig Mautner | 0eea92c | 2013-05-16 13:35:39 -0700 | [diff] [blame] | 4479 | case SLEEP_TIMEOUT_MSG: { |
| 4480 | synchronized (mService) { |
Fyodor Kupolov | 9b80b94 | 2016-06-16 16:29:05 -0700 | [diff] [blame] | 4481 | if (mService.isSleepingOrShuttingDownLocked()) { |
Craig Mautner | 0eea92c | 2013-05-16 13:35:39 -0700 | [diff] [blame] | 4482 | Slog.w(TAG, "Sleep timeout! Sleeping now."); |
| 4483 | mSleepTimeout = true; |
| 4484 | checkReadyForSleepLocked(); |
| 4485 | } |
| 4486 | } |
| 4487 | } break; |
Craig Mautner | 7ea5bd4 | 2013-07-05 15:27:08 -0700 | [diff] [blame] | 4488 | case LAUNCH_TIMEOUT_MSG: { |
| 4489 | if (mService.mDidDexOpt) { |
| 4490 | mService.mDidDexOpt = false; |
| 4491 | mHandler.sendEmptyMessageDelayed(LAUNCH_TIMEOUT_MSG, LAUNCH_TIMEOUT); |
| 4492 | return; |
| 4493 | } |
| 4494 | synchronized (mService) { |
| 4495 | if (mLaunchingActivity.isHeld()) { |
| 4496 | Slog.w(TAG, "Launch timeout has expired, giving up wake lock!"); |
| 4497 | if (VALIDATE_WAKE_LOCK_CALLER |
| 4498 | && Binder.getCallingUid() != Process.myUid()) { |
| 4499 | throw new IllegalStateException("Calling must be system uid"); |
| 4500 | } |
| 4501 | mLaunchingActivity.release(); |
| 4502 | } |
| 4503 | } |
| 4504 | } break; |
Craig Mautner | 4a1cb22 | 2013-12-04 16:14:06 -0800 | [diff] [blame] | 4505 | case HANDLE_DISPLAY_ADDED: { |
Wale Ogunwale | f16a281 | 2015-04-01 11:23:15 -0700 | [diff] [blame] | 4506 | handleDisplayAdded(msg.arg1); |
Craig Mautner | 4a1cb22 | 2013-12-04 16:14:06 -0800 | [diff] [blame] | 4507 | } break; |
| 4508 | case HANDLE_DISPLAY_CHANGED: { |
Wale Ogunwale | f16a281 | 2015-04-01 11:23:15 -0700 | [diff] [blame] | 4509 | handleDisplayChanged(msg.arg1); |
Craig Mautner | 4a1cb22 | 2013-12-04 16:14:06 -0800 | [diff] [blame] | 4510 | } break; |
| 4511 | case HANDLE_DISPLAY_REMOVED: { |
Wale Ogunwale | f16a281 | 2015-04-01 11:23:15 -0700 | [diff] [blame] | 4512 | handleDisplayRemoved(msg.arg1); |
Craig Mautner | 4a1cb22 | 2013-12-04 16:14:06 -0800 | [diff] [blame] | 4513 | } break; |
Craig Mautner | e3a00d7 | 2014-04-16 08:31:19 -0700 | [diff] [blame] | 4514 | case CONTAINER_CALLBACK_VISIBILITY: { |
| 4515 | final ActivityContainer container = (ActivityContainer) msg.obj; |
Craig Mautner | d94b47f | 2014-06-02 15:06:40 -0700 | [diff] [blame] | 4516 | final IActivityContainerCallback callback = container.mCallback; |
| 4517 | if (callback != null) { |
| 4518 | try { |
| 4519 | callback.setVisible(container.asBinder(), msg.arg1 == 1); |
| 4520 | } catch (RemoteException e) { |
| 4521 | } |
Craig Mautner | e3a00d7 | 2014-04-16 08:31:19 -0700 | [diff] [blame] | 4522 | } |
Craig Mautner | d94b47f | 2014-06-02 15:06:40 -0700 | [diff] [blame] | 4523 | } break; |
justinzhang | 5286d3f | 2014-05-12 17:06:01 -0400 | [diff] [blame] | 4524 | case LOCK_TASK_START_MSG: { |
| 4525 | // When lock task starts, we disable the status bars. |
| 4526 | try { |
Jason Monk | 62515be | 2014-05-21 16:06:19 -0400 | [diff] [blame] | 4527 | if (mLockTaskNotify == null) { |
| 4528 | mLockTaskNotify = new LockTaskNotify(mService.mContext); |
justinzhang | 5286d3f | 2014-05-12 17:06:01 -0400 | [diff] [blame] | 4529 | } |
Jason Monk | 62515be | 2014-05-21 16:06:19 -0400 | [diff] [blame] | 4530 | mLockTaskNotify.show(true); |
Benjamin Franz | 4326114 | 2015-02-11 15:59:44 +0000 | [diff] [blame] | 4531 | mLockTaskModeState = msg.arg2; |
Jason Monk | 62515be | 2014-05-21 16:06:19 -0400 | [diff] [blame] | 4532 | if (getStatusBarService() != null) { |
Benjamin Franz | 4326114 | 2015-02-11 15:59:44 +0000 | [diff] [blame] | 4533 | int flags = 0; |
Craig Mautner | 15df08a | 2015-04-01 12:17:18 -0700 | [diff] [blame] | 4534 | if (mLockTaskModeState == LOCK_TASK_MODE_LOCKED) { |
Benjamin Franz | 4326114 | 2015-02-11 15:59:44 +0000 | [diff] [blame] | 4535 | flags = StatusBarManager.DISABLE_MASK |
| 4536 | & (~StatusBarManager.DISABLE_BACK); |
Craig Mautner | 15df08a | 2015-04-01 12:17:18 -0700 | [diff] [blame] | 4537 | } else if (mLockTaskModeState == LOCK_TASK_MODE_PINNED) { |
Benjamin Franz | 4326114 | 2015-02-11 15:59:44 +0000 | [diff] [blame] | 4538 | flags = StatusBarManager.DISABLE_MASK |
| 4539 | & (~StatusBarManager.DISABLE_BACK) |
| 4540 | & (~StatusBarManager.DISABLE_HOME) |
| 4541 | & (~StatusBarManager.DISABLE_RECENT); |
Jason Monk | 62515be | 2014-05-21 16:06:19 -0400 | [diff] [blame] | 4542 | } |
| 4543 | getStatusBarService().disable(flags, mToken, |
| 4544 | mService.mContext.getPackageName()); |
| 4545 | } |
| 4546 | mWindowManager.disableKeyguard(mToken, LOCK_TASK_TAG); |
Jason Monk | 35c62a4 | 2014-06-17 10:24:47 -0400 | [diff] [blame] | 4547 | if (getDevicePolicyManager() != null) { |
| 4548 | getDevicePolicyManager().notifyLockTaskModeChanged(true, |
Jason Monk | 62515be | 2014-05-21 16:06:19 -0400 | [diff] [blame] | 4549 | (String)msg.obj, msg.arg1); |
Jason Monk | 35c62a4 | 2014-06-17 10:24:47 -0400 | [diff] [blame] | 4550 | } |
justinzhang | 5286d3f | 2014-05-12 17:06:01 -0400 | [diff] [blame] | 4551 | } catch (RemoteException ex) { |
| 4552 | throw new RuntimeException(ex); |
| 4553 | } |
Craig Mautner | b6011c1 | 2014-06-04 20:59:13 -0700 | [diff] [blame] | 4554 | } break; |
justinzhang | 5286d3f | 2014-05-12 17:06:01 -0400 | [diff] [blame] | 4555 | case LOCK_TASK_END_MSG: { |
| 4556 | // When lock task ends, we enable the status bars. |
| 4557 | try { |
Jason Monk | 62515be | 2014-05-21 16:06:19 -0400 | [diff] [blame] | 4558 | if (getStatusBarService() != null) { |
| 4559 | getStatusBarService().disable(StatusBarManager.DISABLE_NONE, mToken, |
| 4560 | mService.mContext.getPackageName()); |
| 4561 | } |
| 4562 | mWindowManager.reenableKeyguard(mToken); |
Jason Monk | 35c62a4 | 2014-06-17 10:24:47 -0400 | [diff] [blame] | 4563 | if (getDevicePolicyManager() != null) { |
| 4564 | getDevicePolicyManager().notifyLockTaskModeChanged(false, null, |
| 4565 | msg.arg1); |
| 4566 | } |
Jason Monk | 62515be | 2014-05-21 16:06:19 -0400 | [diff] [blame] | 4567 | if (mLockTaskNotify == null) { |
| 4568 | mLockTaskNotify = new LockTaskNotify(mService.mContext); |
| 4569 | } |
| 4570 | mLockTaskNotify.show(false); |
| 4571 | try { |
Jason Monk | 94cfd9d | 2014-10-31 13:18:21 -0400 | [diff] [blame] | 4572 | boolean shouldLockKeyguard = Settings.Secure.getInt( |
Jason Monk | 62515be | 2014-05-21 16:06:19 -0400 | [diff] [blame] | 4573 | mService.mContext.getContentResolver(), |
Jason Monk | 94cfd9d | 2014-10-31 13:18:21 -0400 | [diff] [blame] | 4574 | Settings.Secure.LOCK_TO_APP_EXIT_LOCKED) != 0; |
Craig Mautner | 15df08a | 2015-04-01 12:17:18 -0700 | [diff] [blame] | 4575 | if (mLockTaskModeState == LOCK_TASK_MODE_PINNED && shouldLockKeyguard) { |
Jason Monk | 62515be | 2014-05-21 16:06:19 -0400 | [diff] [blame] | 4576 | mWindowManager.lockNow(null); |
Jorim Jaggi | 241ae10 | 2016-11-02 21:57:33 -0700 | [diff] [blame] | 4577 | mWindowManager.dismissKeyguard(null /* callback */); |
Jason Monk | e069779 | 2014-08-04 16:28:09 -0400 | [diff] [blame] | 4578 | new LockPatternUtils(mService.mContext) |
| 4579 | .requireCredentialEntry(UserHandle.USER_ALL); |
Jason Monk | 62515be | 2014-05-21 16:06:19 -0400 | [diff] [blame] | 4580 | } |
| 4581 | } catch (SettingNotFoundException e) { |
| 4582 | // No setting, don't lock. |
| 4583 | } |
justinzhang | 5286d3f | 2014-05-12 17:06:01 -0400 | [diff] [blame] | 4584 | } catch (RemoteException ex) { |
| 4585 | throw new RuntimeException(ex); |
Benjamin Franz | 4326114 | 2015-02-11 15:59:44 +0000 | [diff] [blame] | 4586 | } finally { |
Craig Mautner | 15df08a | 2015-04-01 12:17:18 -0700 | [diff] [blame] | 4587 | mLockTaskModeState = LOCK_TASK_MODE_NONE; |
justinzhang | 5286d3f | 2014-05-12 17:06:01 -0400 | [diff] [blame] | 4588 | } |
Craig Mautner | b6011c1 | 2014-06-04 20:59:13 -0700 | [diff] [blame] | 4589 | } break; |
Craig Mautner | c21ae9e | 2015-04-15 09:45:42 -0700 | [diff] [blame] | 4590 | case SHOW_LOCK_TASK_ESCAPE_MESSAGE_MSG: { |
| 4591 | if (mLockTaskNotify == null) { |
| 4592 | mLockTaskNotify = new LockTaskNotify(mService.mContext); |
| 4593 | } |
| 4594 | mLockTaskNotify.showToast(LOCK_TASK_MODE_PINNED); |
| 4595 | } break; |
Craig Mautner | d94b47f | 2014-06-02 15:06:40 -0700 | [diff] [blame] | 4596 | case CONTAINER_CALLBACK_TASK_LIST_EMPTY: { |
| 4597 | final ActivityContainer container = (ActivityContainer) msg.obj; |
| 4598 | final IActivityContainerCallback callback = container.mCallback; |
| 4599 | if (callback != null) { |
| 4600 | try { |
| 4601 | callback.onAllActivitiesComplete(container.asBinder()); |
| 4602 | } catch (RemoteException e) { |
| 4603 | } |
| 4604 | } |
| 4605 | } break; |
Craig Mautner | bb74246 | 2014-07-07 15:28:55 -0700 | [diff] [blame] | 4606 | case LAUNCH_TASK_BEHIND_COMPLETE: { |
| 4607 | synchronized (mService) { |
Wale Ogunwale | 7d70117 | 2015-03-11 15:36:30 -0700 | [diff] [blame] | 4608 | ActivityRecord r = ActivityRecord.forTokenLocked((IBinder) msg.obj); |
Craig Mautner | bb74246 | 2014-07-07 15:28:55 -0700 | [diff] [blame] | 4609 | if (r != null) { |
| 4610 | handleLaunchTaskBehindCompleteLocked(r); |
| 4611 | } |
| 4612 | } |
| 4613 | } break; |
Chong Zhang | c806d90 | 2015-11-30 09:44:27 -0800 | [diff] [blame] | 4614 | |
Craig Mautner | ce5f3cb | 2013-04-22 08:58:54 -0700 | [diff] [blame] | 4615 | } |
| 4616 | } |
| 4617 | } |
Craig Mautner | ed6649f | 2013-12-02 14:08:25 -0800 | [diff] [blame] | 4618 | |
Ying Wang | b081a59 | 2014-04-22 15:20:16 -0700 | [diff] [blame] | 4619 | class ActivityContainer extends android.app.IActivityContainer.Stub { |
Filip Gruszczynski | dc39490 | 2015-12-14 10:20:22 -0800 | [diff] [blame] | 4620 | final static int FORCE_NEW_TASK_FLAGS = FLAG_ACTIVITY_NEW_TASK | |
| 4621 | FLAG_ACTIVITY_MULTIPLE_TASK | Intent.FLAG_ACTIVITY_NO_ANIMATION; |
Craig Mautner | 4a1cb22 | 2013-12-04 16:14:06 -0800 | [diff] [blame] | 4622 | final int mStackId; |
Craig Mautner | f4c909b | 2014-04-17 18:39:38 -0700 | [diff] [blame] | 4623 | IActivityContainerCallback mCallback = null; |
Wale Ogunwale | 1666e31 | 2016-12-16 11:27:18 -0800 | [diff] [blame] | 4624 | ActivityStack mStack; |
Craig Mautner | f4c909b | 2014-04-17 18:39:38 -0700 | [diff] [blame] | 4625 | ActivityRecord mParentActivity = null; |
| 4626 | String mIdString; |
Craig Mautner | ed6649f | 2013-12-02 14:08:25 -0800 | [diff] [blame] | 4627 | |
Craig Mautner | e3a00d7 | 2014-04-16 08:31:19 -0700 | [diff] [blame] | 4628 | boolean mVisible = true; |
| 4629 | |
Craig Mautner | 4a1cb22 | 2013-12-04 16:14:06 -0800 | [diff] [blame] | 4630 | /** Display this ActivityStack is currently on. Null if not attached to a Display. */ |
Craig Mautner | e0a3884 | 2013-12-16 16:14:02 -0800 | [diff] [blame] | 4631 | ActivityDisplay mActivityDisplay; |
Craig Mautner | 4a1cb22 | 2013-12-04 16:14:06 -0800 | [diff] [blame] | 4632 | |
Craig Mautner | f4c909b | 2014-04-17 18:39:38 -0700 | [diff] [blame] | 4633 | final static int CONTAINER_STATE_HAS_SURFACE = 0; |
| 4634 | final static int CONTAINER_STATE_NO_SURFACE = 1; |
| 4635 | final static int CONTAINER_STATE_FINISHING = 2; |
| 4636 | int mContainerState = CONTAINER_STATE_HAS_SURFACE; |
| 4637 | |
Wale Ogunwale | 1666e31 | 2016-12-16 11:27:18 -0800 | [diff] [blame] | 4638 | ActivityContainer(int stackId, ActivityDisplay activityDisplay, boolean onTop) { |
Craig Mautner | 4a1cb22 | 2013-12-04 16:14:06 -0800 | [diff] [blame] | 4639 | synchronized (mService) { |
| 4640 | mStackId = stackId; |
Wale Ogunwale | 1666e31 | 2016-12-16 11:27:18 -0800 | [diff] [blame] | 4641 | mActivityDisplay = activityDisplay; |
Craig Mautner | f4c909b | 2014-04-17 18:39:38 -0700 | [diff] [blame] | 4642 | mIdString = "ActivtyContainer{" + mStackId + "}"; |
Bryce Lee | af691c0 | 2017-03-20 14:20:22 -0700 | [diff] [blame] | 4643 | |
| 4644 | createStack(stackId, onTop); |
Wale Ogunwale | ee006da | 2015-03-30 14:49:25 -0700 | [diff] [blame] | 4645 | if (DEBUG_STACK) Slog.d(TAG_STACK, "Creating " + this); |
Craig Mautner | 4a1cb22 | 2013-12-04 16:14:06 -0800 | [diff] [blame] | 4646 | } |
Craig Mautner | ed6649f | 2013-12-02 14:08:25 -0800 | [diff] [blame] | 4647 | } |
Craig Mautner | 4a1cb22 | 2013-12-04 16:14:06 -0800 | [diff] [blame] | 4648 | |
Bryce Lee | af691c0 | 2017-03-20 14:20:22 -0700 | [diff] [blame] | 4649 | protected void createStack(int stackId, boolean onTop) { |
| 4650 | switch (stackId) { |
| 4651 | case PINNED_STACK_ID: |
| 4652 | new PinnedActivityStack(this, mRecentTasks, onTop); |
| 4653 | break; |
| 4654 | default: |
| 4655 | new ActivityStack(this, mRecentTasks, onTop); |
| 4656 | break; |
| 4657 | } |
| 4658 | } |
| 4659 | |
Andrii Kulian | 839def9 | 2016-11-02 10:58:58 -0700 | [diff] [blame] | 4660 | /** |
| 4661 | * Adds the stack to specified display. Also calls WindowManager to do the same from |
Wale Ogunwale | 1666e31 | 2016-12-16 11:27:18 -0800 | [diff] [blame] | 4662 | * {@link ActivityStack#reparent(ActivityDisplay, boolean)}. |
Andrii Kulian | 839def9 | 2016-11-02 10:58:58 -0700 | [diff] [blame] | 4663 | * @param activityDisplay The display to add the stack to. |
Andrii Kulian | 839def9 | 2016-11-02 10:58:58 -0700 | [diff] [blame] | 4664 | */ |
Wale Ogunwale | 1666e31 | 2016-12-16 11:27:18 -0800 | [diff] [blame] | 4665 | void addToDisplayLocked(ActivityDisplay activityDisplay) { |
Andrii Kulian | 839def9 | 2016-11-02 10:58:58 -0700 | [diff] [blame] | 4666 | if (DEBUG_STACK) Slog.d(TAG_STACK, "addToDisplayLocked: " + this |
Wale Ogunwale | 1666e31 | 2016-12-16 11:27:18 -0800 | [diff] [blame] | 4667 | + " to display=" + activityDisplay); |
Andrii Kulian | 839def9 | 2016-11-02 10:58:58 -0700 | [diff] [blame] | 4668 | if (mActivityDisplay != null) { |
| 4669 | throw new IllegalStateException("ActivityContainer is already attached, " + |
| 4670 | "displayId=" + mActivityDisplay.mDisplayId); |
| 4671 | } |
Craig Mautner | e0a3884 | 2013-12-16 16:14:02 -0800 | [diff] [blame] | 4672 | mActivityDisplay = activityDisplay; |
Wale Ogunwale | 1666e31 | 2016-12-16 11:27:18 -0800 | [diff] [blame] | 4673 | mStack.reparent(activityDisplay, true /* onTop */); |
Craig Mautner | 4a1cb22 | 2013-12-04 16:14:06 -0800 | [diff] [blame] | 4674 | } |
| 4675 | |
| 4676 | @Override |
Andrii Kulian | 839def9 | 2016-11-02 10:58:58 -0700 | [diff] [blame] | 4677 | public void addToDisplay(int displayId) { |
Craig Mautner | 4a1cb22 | 2013-12-04 16:14:06 -0800 | [diff] [blame] | 4678 | synchronized (mService) { |
Andrii Kulian | 62e6f25 | 2017-05-30 22:46:53 -0700 | [diff] [blame] | 4679 | final ActivityDisplay activityDisplay = getActivityDisplayOrCreateLocked(displayId); |
Craig Mautner | e0a3884 | 2013-12-16 16:14:02 -0800 | [diff] [blame] | 4680 | if (activityDisplay == null) { |
Craig Mautner | 4a1cb22 | 2013-12-04 16:14:06 -0800 | [diff] [blame] | 4681 | return; |
| 4682 | } |
Wale Ogunwale | 1666e31 | 2016-12-16 11:27:18 -0800 | [diff] [blame] | 4683 | addToDisplayLocked(activityDisplay); |
Craig Mautner | 4a1cb22 | 2013-12-04 16:14:06 -0800 | [diff] [blame] | 4684 | } |
| 4685 | } |
| 4686 | |
| 4687 | @Override |
Jeff Brown | ca9bc70 | 2014-02-11 14:32:56 -0800 | [diff] [blame] | 4688 | public int getDisplayId() { |
Craig Mautner | d163e75 | 2014-06-13 17:18:47 -0700 | [diff] [blame] | 4689 | synchronized (mService) { |
| 4690 | if (mActivityDisplay != null) { |
| 4691 | return mActivityDisplay.mDisplayId; |
| 4692 | } |
Craig Mautner | e0a3884 | 2013-12-16 16:14:02 -0800 | [diff] [blame] | 4693 | } |
| 4694 | return -1; |
Craig Mautner | 4a1cb22 | 2013-12-04 16:14:06 -0800 | [diff] [blame] | 4695 | } |
| 4696 | |
Jeff Brown | ca9bc70 | 2014-02-11 14:32:56 -0800 | [diff] [blame] | 4697 | @Override |
Winson Chung | d16c565 | 2015-01-26 16:11:07 -0800 | [diff] [blame] | 4698 | public int getStackId() { |
| 4699 | synchronized (mService) { |
| 4700 | return mStackId; |
| 4701 | } |
| 4702 | } |
| 4703 | |
| 4704 | @Override |
Jeff Brown | ca9bc70 | 2014-02-11 14:32:56 -0800 | [diff] [blame] | 4705 | public boolean injectEvent(InputEvent event) { |
| 4706 | final long origId = Binder.clearCallingIdentity(); |
| 4707 | try { |
Craig Mautner | d163e75 | 2014-06-13 17:18:47 -0700 | [diff] [blame] | 4708 | synchronized (mService) { |
| 4709 | if (mActivityDisplay != null) { |
| 4710 | return mInputManagerInternal.injectInputEvent(event, |
| 4711 | mActivityDisplay.mDisplayId, |
| 4712 | InputManager.INJECT_INPUT_EVENT_MODE_ASYNC); |
| 4713 | } |
Jeff Brown | ca9bc70 | 2014-02-11 14:32:56 -0800 | [diff] [blame] | 4714 | } |
| 4715 | return false; |
| 4716 | } finally { |
| 4717 | Binder.restoreCallingIdentity(origId); |
| 4718 | } |
| 4719 | } |
| 4720 | |
Craig Mautner | f4c909b | 2014-04-17 18:39:38 -0700 | [diff] [blame] | 4721 | @Override |
| 4722 | public void release() { |
Craig Mautner | d163e75 | 2014-06-13 17:18:47 -0700 | [diff] [blame] | 4723 | synchronized (mService) { |
| 4724 | if (mContainerState == CONTAINER_STATE_FINISHING) { |
| 4725 | return; |
| 4726 | } |
| 4727 | mContainerState = CONTAINER_STATE_FINISHING; |
| 4728 | |
Craig Mautner | d163e75 | 2014-06-13 17:18:47 -0700 | [diff] [blame] | 4729 | long origId = Binder.clearCallingIdentity(); |
| 4730 | try { |
Craig Mautner | ee36c77 | 2014-07-16 14:56:05 -0700 | [diff] [blame] | 4731 | mStack.finishAllActivitiesLocked(false); |
Filip Gruszczynski | 07a0e49 | 2015-12-17 14:16:38 -0800 | [diff] [blame] | 4732 | mService.mActivityStarter.removePendingActivityLaunchesLocked(mStack); |
Craig Mautner | d163e75 | 2014-06-13 17:18:47 -0700 | [diff] [blame] | 4733 | } finally { |
| 4734 | Binder.restoreCallingIdentity(origId); |
| 4735 | } |
| 4736 | } |
Craig Mautner | f4c909b | 2014-04-17 18:39:38 -0700 | [diff] [blame] | 4737 | } |
| 4738 | |
Andrii Kulian | 03c403d | 2016-11-11 11:14:12 -0800 | [diff] [blame] | 4739 | /** |
| 4740 | * Remove the stack completely. Must be called only when there are no tasks left in it, |
| 4741 | * as this method does not finish running activities. |
| 4742 | */ |
Andrii Kulian | 6d6fb40 | 2016-10-26 16:15:25 -0700 | [diff] [blame] | 4743 | void removeLocked() { |
| 4744 | if (DEBUG_STACK) Slog.d(TAG_STACK, "removeLocked: " + this + " from display=" |
Craig Mautner | 34b73df | 2014-01-12 21:11:08 -0800 | [diff] [blame] | 4745 | + mActivityDisplay + " Callers=" + Debug.getCallers(2)); |
Craig Mautner | e0a3884 | 2013-12-16 16:14:02 -0800 | [diff] [blame] | 4746 | if (mActivityDisplay != null) { |
Andrii Kulian | 839def9 | 2016-11-02 10:58:58 -0700 | [diff] [blame] | 4747 | removeFromDisplayLocked(); |
Craig Mautner | 4a1cb22 | 2013-12-04 16:14:06 -0800 | [diff] [blame] | 4748 | } |
Andrii Kulian | 6d6fb40 | 2016-10-26 16:15:25 -0700 | [diff] [blame] | 4749 | mStack.remove(); |
Craig Mautner | 4a1cb22 | 2013-12-04 16:14:06 -0800 | [diff] [blame] | 4750 | } |
| 4751 | |
Andrii Kulian | 839def9 | 2016-11-02 10:58:58 -0700 | [diff] [blame] | 4752 | /** |
| 4753 | * Remove the stack from its current {@link ActivityDisplay}, so it can be either destroyed |
| 4754 | * completely or re-parented. |
| 4755 | */ |
| 4756 | private void removeFromDisplayLocked() { |
| 4757 | if (DEBUG_STACK) Slog.d(TAG_STACK, "removeFromDisplayLocked: " + this |
| 4758 | + " current displayId=" + mActivityDisplay.mDisplayId); |
| 4759 | |
Wale Ogunwale | 1666e31 | 2016-12-16 11:27:18 -0800 | [diff] [blame] | 4760 | mActivityDisplay.detachStack(mStack); |
Andrii Kulian | 839def9 | 2016-11-02 10:58:58 -0700 | [diff] [blame] | 4761 | mActivityDisplay = null; |
| 4762 | } |
| 4763 | |
| 4764 | /** |
| 4765 | * Move the stack to specified display. |
| 4766 | * @param activityDisplay Target display to move the stack to. |
Andrii Kulian | 250d653 | 2017-02-08 23:30:45 -0800 | [diff] [blame] | 4767 | * @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] | 4768 | */ |
Andrii Kulian | 250d653 | 2017-02-08 23:30:45 -0800 | [diff] [blame] | 4769 | void moveToDisplayLocked(ActivityDisplay activityDisplay, boolean onTop) { |
Andrii Kulian | 839def9 | 2016-11-02 10:58:58 -0700 | [diff] [blame] | 4770 | if (DEBUG_STACK) Slog.d(TAG_STACK, "moveToDisplayLocked: " + this + " from display=" |
| 4771 | + mActivityDisplay + " to display=" + activityDisplay |
| 4772 | + " Callers=" + Debug.getCallers(2)); |
| 4773 | |
| 4774 | removeFromDisplayLocked(); |
| 4775 | |
| 4776 | mActivityDisplay = activityDisplay; |
Andrii Kulian | 250d653 | 2017-02-08 23:30:45 -0800 | [diff] [blame] | 4777 | mStack.reparent(activityDisplay, onTop); |
Andrii Kulian | 839def9 | 2016-11-02 10:58:58 -0700 | [diff] [blame] | 4778 | } |
| 4779 | |
Craig Mautner | 4a1cb22 | 2013-12-04 16:14:06 -0800 | [diff] [blame] | 4780 | @Override |
Craig Mautner | e0a3884 | 2013-12-16 16:14:02 -0800 | [diff] [blame] | 4781 | public final int startActivity(Intent intent) { |
Filip Gruszczynski | 07a0e49 | 2015-12-17 14:16:38 -0800 | [diff] [blame] | 4782 | return mService.startActivity(intent, this); |
Craig Mautner | 4a1cb22 | 2013-12-04 16:14:06 -0800 | [diff] [blame] | 4783 | } |
| 4784 | |
| 4785 | @Override |
Craig Mautner | 5f2bb4c | 2015-03-12 16:10:27 -0700 | [diff] [blame] | 4786 | public final int startActivityIntentSender(IIntentSender intentSender) |
| 4787 | throws TransactionTooLargeException { |
Craig Mautner | df88d73 | 2014-01-27 09:21:32 -0800 | [diff] [blame] | 4788 | mService.enforceNotIsolatedCaller("ActivityContainer.startActivityIntentSender"); |
| 4789 | |
| 4790 | if (!(intentSender instanceof PendingIntentRecord)) { |
| 4791 | throw new IllegalArgumentException("Bad PendingIntent object"); |
| 4792 | } |
| 4793 | |
Fyodor Kupolov | f63b89c | 2015-10-27 18:08:56 -0700 | [diff] [blame] | 4794 | final int userId = mService.mUserController.handleIncomingUser(Binder.getCallingPid(), |
Dianne Hackborn | 409297d | 2014-07-10 17:39:20 -0700 | [diff] [blame] | 4795 | Binder.getCallingUid(), mCurrentUser, false, |
| 4796 | ActivityManagerService.ALLOW_FULL_ONLY, "ActivityContainer", null); |
Craig Mautner | b916836 | 2015-02-26 20:40:19 -0800 | [diff] [blame] | 4797 | |
| 4798 | final PendingIntentRecord pendingIntent = (PendingIntentRecord) intentSender; |
| 4799 | checkEmbeddedAllowedInner(userId, pendingIntent.key.requestIntent, |
| 4800 | pendingIntent.key.requestResolvedType); |
| 4801 | |
Dianne Hackborn | 9830552 | 2017-05-05 17:53:53 -0700 | [diff] [blame] | 4802 | return pendingIntent.sendInner(0, null, null, null, null, null, null, null, 0, |
Craig Mautner | b916836 | 2015-02-26 20:40:19 -0800 | [diff] [blame] | 4803 | FORCE_NEW_TASK_FLAGS, FORCE_NEW_TASK_FLAGS, null, this); |
| 4804 | } |
| 4805 | |
Filip Gruszczynski | 07a0e49 | 2015-12-17 14:16:38 -0800 | [diff] [blame] | 4806 | void checkEmbeddedAllowedInner(int userId, Intent intent, String resolvedType) { |
Jeff Hao | 1b012d3 | 2014-08-20 10:35:34 -0700 | [diff] [blame] | 4807 | ActivityInfo aInfo = resolveActivity(intent, resolvedType, 0, null, userId); |
Craig Mautner | 05678d5 | 2014-05-05 12:32:40 -0700 | [diff] [blame] | 4808 | if (aInfo != null && (aInfo.flags & ActivityInfo.FLAG_ALLOW_EMBEDDED) == 0) { |
Craig Mautner | 247ab65 | 2014-04-25 10:09:00 -0700 | [diff] [blame] | 4809 | throw new SecurityException( |
| 4810 | "Attempt to embed activity that has not set allowEmbedded=\"true\""); |
| 4811 | } |
| 4812 | } |
| 4813 | |
Craig Mautner | df88d73 | 2014-01-27 09:21:32 -0800 | [diff] [blame] | 4814 | @Override |
Craig Mautner | 4a1cb22 | 2013-12-04 16:14:06 -0800 | [diff] [blame] | 4815 | public IBinder asBinder() { |
| 4816 | return this; |
| 4817 | } |
| 4818 | |
Craig Mautner | 4504de5 | 2013-12-20 09:06:56 -0800 | [diff] [blame] | 4819 | @Override |
Craig Mautner | f4c909b | 2014-04-17 18:39:38 -0700 | [diff] [blame] | 4820 | public void setSurface(Surface surface, int width, int height, int density) { |
Craig Mautner | df88d73 | 2014-01-27 09:21:32 -0800 | [diff] [blame] | 4821 | mService.enforceNotIsolatedCaller("ActivityContainer.attachToSurface"); |
Craig Mautner | 4504de5 | 2013-12-20 09:06:56 -0800 | [diff] [blame] | 4822 | } |
| 4823 | |
Craig Mautner | 4a1cb22 | 2013-12-04 16:14:06 -0800 | [diff] [blame] | 4824 | ActivityStackSupervisor getOuter() { |
| 4825 | return ActivityStackSupervisor.this; |
| 4826 | } |
| 4827 | |
Craig Mautner | d163e75 | 2014-06-13 17:18:47 -0700 | [diff] [blame] | 4828 | boolean isAttachedLocked() { |
Craig Mautner | e0a3884 | 2013-12-16 16:14:02 -0800 | [diff] [blame] | 4829 | return mActivityDisplay != null; |
Craig Mautner | 4a1cb22 | 2013-12-04 16:14:06 -0800 | [diff] [blame] | 4830 | } |
| 4831 | |
Craig Mautner | 6985bad | 2014-04-21 15:22:06 -0700 | [diff] [blame] | 4832 | // TODO: Make sure every change to ActivityRecord.visible results in a call to this. |
Craig Mautner | e3a00d7 | 2014-04-16 08:31:19 -0700 | [diff] [blame] | 4833 | void setVisible(boolean visible) { |
| 4834 | if (mVisible != visible) { |
| 4835 | mVisible = visible; |
| 4836 | if (mCallback != null) { |
| 4837 | mHandler.obtainMessage(CONTAINER_CALLBACK_VISIBILITY, visible ? 1 : 0, |
| 4838 | 0 /* unused */, this).sendToTarget(); |
| 4839 | } |
| 4840 | } |
| 4841 | } |
| 4842 | |
Craig Mautner | 6985bad | 2014-04-21 15:22:06 -0700 | [diff] [blame] | 4843 | void setDrawn() { |
| 4844 | } |
| 4845 | |
Craig Mautner | 1b4bf85 | 2014-05-26 15:06:32 -0700 | [diff] [blame] | 4846 | // You can always start a new task on a regular ActivityStack. |
| 4847 | boolean isEligibleForNewTasks() { |
| 4848 | return true; |
| 4849 | } |
| 4850 | |
Craig Mautner | d163e75 | 2014-06-13 17:18:47 -0700 | [diff] [blame] | 4851 | void onTaskListEmptyLocked() { |
Andrii Kulian | 6d6fb40 | 2016-10-26 16:15:25 -0700 | [diff] [blame] | 4852 | removeLocked(); |
Wale Ogunwale | 04f4d6b | 2015-03-11 09:23:25 -0700 | [diff] [blame] | 4853 | mHandler.obtainMessage(CONTAINER_CALLBACK_TASK_LIST_EMPTY, this).sendToTarget(); |
Craig Mautner | d94b47f | 2014-06-02 15:06:40 -0700 | [diff] [blame] | 4854 | } |
| 4855 | |
Craig Mautner | 34b73df | 2014-01-12 21:11:08 -0800 | [diff] [blame] | 4856 | @Override |
| 4857 | public String toString() { |
| 4858 | return mIdString + (mActivityDisplay == null ? "N" : "A"); |
| 4859 | } |
Craig Mautner | ed6649f | 2013-12-02 14:08:25 -0800 | [diff] [blame] | 4860 | } |
| 4861 | |
Craig Mautner | f4c909b | 2014-04-17 18:39:38 -0700 | [diff] [blame] | 4862 | private class VirtualActivityContainer extends ActivityContainer { |
| 4863 | Surface mSurface; |
Craig Mautner | 6985bad | 2014-04-21 15:22:06 -0700 | [diff] [blame] | 4864 | boolean mDrawn = false; |
Craig Mautner | f4c909b | 2014-04-17 18:39:38 -0700 | [diff] [blame] | 4865 | |
| 4866 | VirtualActivityContainer(ActivityRecord parent, IActivityContainerCallback callback) { |
Wale Ogunwale | 1666e31 | 2016-12-16 11:27:18 -0800 | [diff] [blame] | 4867 | super(getNextStackId(), parent.getStack().mActivityContainer.mActivityDisplay, |
| 4868 | true /* onTop */); |
Craig Mautner | f4c909b | 2014-04-17 18:39:38 -0700 | [diff] [blame] | 4869 | mParentActivity = parent; |
| 4870 | mCallback = callback; |
| 4871 | mContainerState = CONTAINER_STATE_NO_SURFACE; |
Craig Mautner | d163e75 | 2014-06-13 17:18:47 -0700 | [diff] [blame] | 4872 | mIdString = "VirtualActivityContainer{" + mStackId + ", parent=" + mParentActivity + "}"; |
Craig Mautner | f4c909b | 2014-04-17 18:39:38 -0700 | [diff] [blame] | 4873 | } |
| 4874 | |
| 4875 | @Override |
| 4876 | public void setSurface(Surface surface, int width, int height, int density) { |
| 4877 | super.setSurface(surface, width, height, density); |
| 4878 | |
| 4879 | synchronized (mService) { |
| 4880 | final long origId = Binder.clearCallingIdentity(); |
| 4881 | try { |
| 4882 | setSurfaceLocked(surface, width, height, density); |
| 4883 | } finally { |
| 4884 | Binder.restoreCallingIdentity(origId); |
| 4885 | } |
| 4886 | } |
| 4887 | } |
| 4888 | |
| 4889 | private void setSurfaceLocked(Surface surface, int width, int height, int density) { |
| 4890 | if (mContainerState == CONTAINER_STATE_FINISHING) { |
| 4891 | return; |
| 4892 | } |
| 4893 | VirtualActivityDisplay virtualActivityDisplay = |
| 4894 | (VirtualActivityDisplay) mActivityDisplay; |
| 4895 | if (virtualActivityDisplay == null) { |
| 4896 | virtualActivityDisplay = |
Craig Mautner | 6985bad | 2014-04-21 15:22:06 -0700 | [diff] [blame] | 4897 | new VirtualActivityDisplay(width, height, density); |
Craig Mautner | f4c909b | 2014-04-17 18:39:38 -0700 | [diff] [blame] | 4898 | mActivityDisplay = virtualActivityDisplay; |
| 4899 | mActivityDisplays.put(virtualActivityDisplay.mDisplayId, virtualActivityDisplay); |
Wale Ogunwale | 1666e31 | 2016-12-16 11:27:18 -0800 | [diff] [blame] | 4900 | addToDisplayLocked(virtualActivityDisplay); |
Craig Mautner | f4c909b | 2014-04-17 18:39:38 -0700 | [diff] [blame] | 4901 | } |
| 4902 | |
| 4903 | if (mSurface != null) { |
| 4904 | mSurface.release(); |
Craig Mautner | f4c909b | 2014-04-17 18:39:38 -0700 | [diff] [blame] | 4905 | } |
| 4906 | |
Craig Mautner | 6985bad | 2014-04-21 15:22:06 -0700 | [diff] [blame] | 4907 | mSurface = surface; |
Craig Mautner | f4c909b | 2014-04-17 18:39:38 -0700 | [diff] [blame] | 4908 | if (surface != null) { |
Wale Ogunwale | d046a01 | 2015-12-24 13:05:59 -0800 | [diff] [blame] | 4909 | resumeFocusedStackTopActivityLocked(); |
Craig Mautner | f4c909b | 2014-04-17 18:39:38 -0700 | [diff] [blame] | 4910 | } else { |
| 4911 | mContainerState = CONTAINER_STATE_NO_SURFACE; |
Craig Mautner | 6985bad | 2014-04-21 15:22:06 -0700 | [diff] [blame] | 4912 | ((VirtualActivityDisplay) mActivityDisplay).setSurface(null); |
Craig Mautner | d13a558 | 2014-05-05 12:07:40 -0700 | [diff] [blame] | 4913 | if (mStack.mPausingActivity == null && mStack.mResumedActivity != null) { |
Wale Ogunwale | 950faff | 2016-08-08 09:51:04 -0700 | [diff] [blame] | 4914 | mStack.startPausingLocked(false, true, null, false); |
Craig Mautner | d13a558 | 2014-05-05 12:07:40 -0700 | [diff] [blame] | 4915 | } |
Craig Mautner | f4c909b | 2014-04-17 18:39:38 -0700 | [diff] [blame] | 4916 | } |
Craig Mautner | 6985bad | 2014-04-21 15:22:06 -0700 | [diff] [blame] | 4917 | |
Craig Mautner | d163e75 | 2014-06-13 17:18:47 -0700 | [diff] [blame] | 4918 | setSurfaceIfReadyLocked(); |
Craig Mautner | 6985bad | 2014-04-21 15:22:06 -0700 | [diff] [blame] | 4919 | |
Wale Ogunwale | ee006da | 2015-03-30 14:49:25 -0700 | [diff] [blame] | 4920 | if (DEBUG_STACK) Slog.d(TAG_STACK, |
| 4921 | "setSurface: " + this + " to display=" + virtualActivityDisplay); |
Craig Mautner | 6985bad | 2014-04-21 15:22:06 -0700 | [diff] [blame] | 4922 | } |
Craig Mautner | f4c909b | 2014-04-17 18:39:38 -0700 | [diff] [blame] | 4923 | |
Craig Mautner | 6985bad | 2014-04-21 15:22:06 -0700 | [diff] [blame] | 4924 | @Override |
Craig Mautner | d163e75 | 2014-06-13 17:18:47 -0700 | [diff] [blame] | 4925 | boolean isAttachedLocked() { |
| 4926 | return mSurface != null && super.isAttachedLocked(); |
Craig Mautner | d13a558 | 2014-05-05 12:07:40 -0700 | [diff] [blame] | 4927 | } |
| 4928 | |
| 4929 | @Override |
Craig Mautner | 6985bad | 2014-04-21 15:22:06 -0700 | [diff] [blame] | 4930 | void setDrawn() { |
| 4931 | synchronized (mService) { |
| 4932 | mDrawn = true; |
Craig Mautner | d163e75 | 2014-06-13 17:18:47 -0700 | [diff] [blame] | 4933 | setSurfaceIfReadyLocked(); |
Craig Mautner | 6985bad | 2014-04-21 15:22:06 -0700 | [diff] [blame] | 4934 | } |
| 4935 | } |
| 4936 | |
Craig Mautner | 1b4bf85 | 2014-05-26 15:06:32 -0700 | [diff] [blame] | 4937 | // Never start a new task on an ActivityView if it isn't explicitly specified. |
| 4938 | @Override |
| 4939 | boolean isEligibleForNewTasks() { |
| 4940 | return false; |
| 4941 | } |
| 4942 | |
Craig Mautner | d163e75 | 2014-06-13 17:18:47 -0700 | [diff] [blame] | 4943 | private void setSurfaceIfReadyLocked() { |
Wale Ogunwale | ee006da | 2015-03-30 14:49:25 -0700 | [diff] [blame] | 4944 | if (DEBUG_STACK) Slog.v(TAG_STACK, "setSurfaceIfReadyLocked: mDrawn=" + mDrawn + |
Craig Mautner | 6985bad | 2014-04-21 15:22:06 -0700 | [diff] [blame] | 4945 | " mContainerState=" + mContainerState + " mSurface=" + mSurface); |
| 4946 | if (mDrawn && mSurface != null && mContainerState == CONTAINER_STATE_NO_SURFACE) { |
| 4947 | ((VirtualActivityDisplay) mActivityDisplay).setSurface(mSurface); |
| 4948 | mContainerState = CONTAINER_STATE_HAS_SURFACE; |
| 4949 | } |
Craig Mautner | f4c909b | 2014-04-17 18:39:38 -0700 | [diff] [blame] | 4950 | } |
| 4951 | } |
| 4952 | |
Craig Mautner | 4a1cb22 | 2013-12-04 16:14:06 -0800 | [diff] [blame] | 4953 | /** Exactly one of these classes per Display in the system. Capable of holding zero or more |
| 4954 | * attached {@link ActivityStack}s */ |
Andrii Kulian | 1779e61 | 2016-10-12 21:58:25 -0700 | [diff] [blame] | 4955 | class ActivityDisplay extends ConfigurationContainer { |
Craig Mautner | 4a1cb22 | 2013-12-04 16:14:06 -0800 | [diff] [blame] | 4956 | /** Actual Display this object tracks. */ |
Craig Mautner | 34b73df | 2014-01-12 21:11:08 -0800 | [diff] [blame] | 4957 | int mDisplayId; |
| 4958 | Display mDisplay; |
Craig Mautner | ed6649f | 2013-12-02 14:08:25 -0800 | [diff] [blame] | 4959 | |
Craig Mautner | 4a1cb22 | 2013-12-04 16:14:06 -0800 | [diff] [blame] | 4960 | /** All of the stacks on this display. Order matters, topmost stack is in front of all other |
| 4961 | * stacks, bottommost behind. Accessed directly by ActivityManager package classes */ |
Wale Ogunwale | 1f544be | 2015-12-17 10:27:23 -0800 | [diff] [blame] | 4962 | final ArrayList<ActivityStack> mStacks = new ArrayList<>(); |
Craig Mautner | 4a1cb22 | 2013-12-04 16:14:06 -0800 | [diff] [blame] | 4963 | |
Jose Lima | 4b6c669 | 2014-08-12 17:41:12 -0700 | [diff] [blame] | 4964 | ActivityRecord mVisibleBehindActivity; |
Craig Mautner | ee2e45a | 2014-06-27 12:10:03 -0700 | [diff] [blame] | 4965 | |
Andrii Kulian | fb1bf69 | 2017-01-17 11:17:34 -0800 | [diff] [blame] | 4966 | /** Array of all UIDs that are present on the display. */ |
| 4967 | private IntArray mDisplayAccessUIDs = new IntArray(); |
| 4968 | |
Craig Mautner | f4c909b | 2014-04-17 18:39:38 -0700 | [diff] [blame] | 4969 | ActivityDisplay() { |
| 4970 | } |
Craig Mautner | 4504de5 | 2013-12-20 09:06:56 -0800 | [diff] [blame] | 4971 | |
Craig Mautner | 1a70a16 | 2014-09-13 12:09:31 -0700 | [diff] [blame] | 4972 | // After instantiation, check that mDisplay is not null before using this. The alternative |
| 4973 | // is for this to throw an exception if mDisplayManager.getDisplay() returns null. |
Craig Mautner | e0a3884 | 2013-12-16 16:14:02 -0800 | [diff] [blame] | 4974 | ActivityDisplay(int displayId) { |
Craig Mautner | 1a70a16 | 2014-09-13 12:09:31 -0700 | [diff] [blame] | 4975 | final Display display = mDisplayManager.getDisplay(displayId); |
| 4976 | if (display == null) { |
| 4977 | return; |
| 4978 | } |
| 4979 | init(display); |
Craig Mautner | 4504de5 | 2013-12-20 09:06:56 -0800 | [diff] [blame] | 4980 | } |
| 4981 | |
Craig Mautner | f4c909b | 2014-04-17 18:39:38 -0700 | [diff] [blame] | 4982 | void init(Display display) { |
Craig Mautner | 4504de5 | 2013-12-20 09:06:56 -0800 | [diff] [blame] | 4983 | mDisplay = display; |
| 4984 | mDisplayId = display.getDisplayId(); |
Craig Mautner | ed6649f | 2013-12-02 14:08:25 -0800 | [diff] [blame] | 4985 | } |
Craig Mautner | 4a1cb22 | 2013-12-04 16:14:06 -0800 | [diff] [blame] | 4986 | |
Winson Chung | 7c3ede3 | 2017-03-14 14:18:34 -0700 | [diff] [blame] | 4987 | void attachStack(ActivityStack stack, int position) { |
Wale Ogunwale | 1666e31 | 2016-12-16 11:27:18 -0800 | [diff] [blame] | 4988 | if (DEBUG_STACK) Slog.v(TAG_STACK, "attachStack: attaching " + stack |
Winson Chung | 7c3ede3 | 2017-03-14 14:18:34 -0700 | [diff] [blame] | 4989 | + " to displayId=" + mDisplayId + " position=" + position); |
| 4990 | mStacks.add(position, stack); |
Craig Mautner | 4a1cb22 | 2013-12-04 16:14:06 -0800 | [diff] [blame] | 4991 | } |
| 4992 | |
Wale Ogunwale | 1666e31 | 2016-12-16 11:27:18 -0800 | [diff] [blame] | 4993 | void detachStack(ActivityStack stack) { |
| 4994 | if (DEBUG_STACK) Slog.v(TAG_STACK, "detachStack: detaching " + stack |
Craig Mautner | e0a3884 | 2013-12-16 16:14:02 -0800 | [diff] [blame] | 4995 | + " from displayId=" + mDisplayId); |
| 4996 | mStacks.remove(stack); |
Craig Mautner | 4a1cb22 | 2013-12-04 16:14:06 -0800 | [diff] [blame] | 4997 | } |
| 4998 | |
Jose Lima | 4b6c669 | 2014-08-12 17:41:12 -0700 | [diff] [blame] | 4999 | void setVisibleBehindActivity(ActivityRecord r) { |
| 5000 | mVisibleBehindActivity = r; |
Craig Mautner | ee2e45a | 2014-06-27 12:10:03 -0700 | [diff] [blame] | 5001 | } |
| 5002 | |
Jose Lima | 4b6c669 | 2014-08-12 17:41:12 -0700 | [diff] [blame] | 5003 | boolean hasVisibleBehindActivity() { |
| 5004 | return mVisibleBehindActivity != null; |
Craig Mautner | ee2e45a | 2014-06-27 12:10:03 -0700 | [diff] [blame] | 5005 | } |
| 5006 | |
Craig Mautner | 34b73df | 2014-01-12 21:11:08 -0800 | [diff] [blame] | 5007 | @Override |
| 5008 | public String toString() { |
Craig Mautner | f4c909b | 2014-04-17 18:39:38 -0700 | [diff] [blame] | 5009 | return "ActivityDisplay={" + mDisplayId + " numStacks=" + mStacks.size() + "}"; |
| 5010 | } |
Andrii Kulian | 1779e61 | 2016-10-12 21:58:25 -0700 | [diff] [blame] | 5011 | |
| 5012 | @Override |
| 5013 | protected int getChildCount() { |
| 5014 | return mStacks.size(); |
| 5015 | } |
| 5016 | |
| 5017 | @Override |
| 5018 | protected ConfigurationContainer getChildAt(int index) { |
| 5019 | return mStacks.get(index); |
| 5020 | } |
| 5021 | |
| 5022 | @Override |
| 5023 | protected ConfigurationContainer getParent() { |
| 5024 | return ActivityStackSupervisor.this; |
| 5025 | } |
Andrii Kulian | fb1bf69 | 2017-01-17 11:17:34 -0800 | [diff] [blame] | 5026 | |
| 5027 | boolean isPrivate() { |
| 5028 | return (mDisplay.getFlags() & FLAG_PRIVATE) != 0; |
| 5029 | } |
| 5030 | |
| 5031 | boolean isUidPresent(int uid) { |
| 5032 | for (ActivityStack stack : mStacks) { |
| 5033 | if (stack.isUidPresent(uid)) { |
| 5034 | return true; |
| 5035 | } |
| 5036 | } |
| 5037 | return false; |
| 5038 | } |
| 5039 | |
| 5040 | /** Update and get all UIDs that are present on the display and have access to it. */ |
| 5041 | private IntArray getPresentUIDs() { |
| 5042 | mDisplayAccessUIDs.clear(); |
| 5043 | for (ActivityStack stack : mStacks) { |
| 5044 | stack.getPresentUIDs(mDisplayAccessUIDs); |
| 5045 | } |
| 5046 | return mDisplayAccessUIDs; |
| 5047 | } |
Andrii Kulian | 250d653 | 2017-02-08 23:30:45 -0800 | [diff] [blame] | 5048 | |
| 5049 | boolean shouldDestroyContentOnRemove() { |
| 5050 | return mDisplay.getRemoveMode() == REMOVE_MODE_DESTROY_CONTENT; |
| 5051 | } |
Craig Mautner | f4c909b | 2014-04-17 18:39:38 -0700 | [diff] [blame] | 5052 | } |
| 5053 | |
| 5054 | class VirtualActivityDisplay extends ActivityDisplay { |
| 5055 | VirtualDisplay mVirtualDisplay; |
| 5056 | |
Craig Mautner | 6985bad | 2014-04-21 15:22:06 -0700 | [diff] [blame] | 5057 | VirtualActivityDisplay(int width, int height, int density) { |
Craig Mautner | f4c909b | 2014-04-17 18:39:38 -0700 | [diff] [blame] | 5058 | DisplayManagerGlobal dm = DisplayManagerGlobal.getInstance(); |
Santos Cordon | b060863 | 2017-04-05 10:31:15 -0700 | [diff] [blame] | 5059 | mVirtualDisplay = dm.createVirtualDisplay(mService.mContext, null /* projection */, |
| 5060 | VIRTUAL_DISPLAY_BASE_NAME, width, height, density, null /* surface */, |
Michael Wright | c39d47a | 2014-07-08 18:07:36 -0700 | [diff] [blame] | 5061 | DisplayManager.VIRTUAL_DISPLAY_FLAG_PUBLIC | |
Santos Cordon | b060863 | 2017-04-05 10:31:15 -0700 | [diff] [blame] | 5062 | DisplayManager.VIRTUAL_DISPLAY_FLAG_OWN_CONTENT_ONLY, null /* callback */, |
| 5063 | null /* handler */, null /* uniqueId */); |
Craig Mautner | f4c909b | 2014-04-17 18:39:38 -0700 | [diff] [blame] | 5064 | |
| 5065 | init(mVirtualDisplay.getDisplay()); |
| 5066 | |
Bryce Lee | af3a400 | 2017-03-20 10:37:12 -0700 | [diff] [blame] | 5067 | mWindowManager.onDisplayAdded(mDisplayId); |
Craig Mautner | f4c909b | 2014-04-17 18:39:38 -0700 | [diff] [blame] | 5068 | } |
| 5069 | |
| 5070 | void setSurface(Surface surface) { |
| 5071 | if (mVirtualDisplay != null) { |
| 5072 | mVirtualDisplay.setSurface(surface); |
| 5073 | } |
| 5074 | } |
| 5075 | |
| 5076 | @Override |
Wale Ogunwale | 1666e31 | 2016-12-16 11:27:18 -0800 | [diff] [blame] | 5077 | void detachStack(ActivityStack stack) { |
| 5078 | super.detachStack(stack); |
Craig Mautner | f4c909b | 2014-04-17 18:39:38 -0700 | [diff] [blame] | 5079 | if (mVirtualDisplay != null) { |
| 5080 | mVirtualDisplay.release(); |
| 5081 | mVirtualDisplay = null; |
| 5082 | } |
| 5083 | } |
| 5084 | |
| 5085 | @Override |
| 5086 | public String toString() { |
| 5087 | return "VirtualActivityDisplay={" + mDisplayId + "}"; |
Craig Mautner | 34b73df | 2014-01-12 21:11:08 -0800 | [diff] [blame] | 5088 | } |
Craig Mautner | ed6649f | 2013-12-02 14:08:25 -0800 | [diff] [blame] | 5089 | } |
Jose Lima | 58e66d6 | 2014-05-27 20:00:27 -0700 | [diff] [blame] | 5090 | |
Filip Gruszczynski | caae14e | 2015-12-16 14:40:04 -0800 | [diff] [blame] | 5091 | ActivityStack findStackBehind(ActivityStack stack) { |
| 5092 | // 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] | 5093 | final ActivityDisplay display = mActivityDisplays.get(DEFAULT_DISPLAY); |
Filip Gruszczynski | caae14e | 2015-12-16 14:40:04 -0800 | [diff] [blame] | 5094 | if (display == null) { |
| 5095 | return null; |
| 5096 | } |
| 5097 | final ArrayList<ActivityStack> stacks = display.mStacks; |
| 5098 | for (int i = stacks.size() - 1; i >= 0; i--) { |
| 5099 | if (stacks.get(i) == stack && i > 0) { |
| 5100 | return stacks.get(i - 1); |
| 5101 | } |
| 5102 | } |
| 5103 | throw new IllegalStateException("Failed to find a stack behind stack=" + stack |
| 5104 | + " in=" + stacks); |
| 5105 | } |
Jorim Jaggi | 0b46f3c | 2016-03-14 12:21:37 +0100 | [diff] [blame] | 5106 | |
Jorim Jaggi | c69bd22 | 2016-03-15 14:38:37 +0100 | [diff] [blame] | 5107 | /** |
| 5108 | * Puts a task into resizing mode during the next app transition. |
| 5109 | * |
Wale Ogunwale | e1fe7fa2 | 2016-12-15 18:27:00 -0800 | [diff] [blame] | 5110 | * @param task The task to put into resizing mode |
Jorim Jaggi | c69bd22 | 2016-03-15 14:38:37 +0100 | [diff] [blame] | 5111 | */ |
Wale Ogunwale | e1fe7fa2 | 2016-12-15 18:27:00 -0800 | [diff] [blame] | 5112 | private void setResizingDuringAnimation(TaskRecord task) { |
| 5113 | mResizingTasksDuringAnimation.add(task.taskId); |
| 5114 | task.setTaskDockedResizing(true); |
Jorim Jaggi | c69bd22 | 2016-03-15 14:38:37 +0100 | [diff] [blame] | 5115 | } |
| 5116 | |
Jorim Jaggi | 0b46f3c | 2016-03-14 12:21:37 +0100 | [diff] [blame] | 5117 | final int startActivityFromRecentsInner(int taskId, Bundle bOptions) { |
| 5118 | final TaskRecord task; |
| 5119 | final int callingUid; |
| 5120 | final String callingPackage; |
| 5121 | final Intent intent; |
| 5122 | final int userId; |
| 5123 | final ActivityOptions activityOptions = (bOptions != null) |
| 5124 | ? new ActivityOptions(bOptions) : null; |
| 5125 | final int launchStackId = (activityOptions != null) |
| 5126 | ? activityOptions.getLaunchStackId() : INVALID_STACK_ID; |
Matthew Ng | ae1ff4f | 2016-11-10 15:49:14 -0800 | [diff] [blame] | 5127 | if (StackId.isHomeOrRecentsStack(launchStackId)) { |
Jorim Jaggi | 0b46f3c | 2016-03-14 12:21:37 +0100 | [diff] [blame] | 5128 | throw new IllegalArgumentException("startActivityFromRecentsInner: Task " |
Matthew Ng | ae1ff4f | 2016-11-10 15:49:14 -0800 | [diff] [blame] | 5129 | + taskId + " can't be launch in the home/recents stack."); |
Jorim Jaggi | 0b46f3c | 2016-03-14 12:21:37 +0100 | [diff] [blame] | 5130 | } |
Jorim Jaggi | 3c800a4 | 2016-04-15 19:44:50 -0700 | [diff] [blame] | 5131 | |
Matthew Ng | 606dd80 | 2017-06-05 14:06:32 -0700 | [diff] [blame] | 5132 | mWindowManager.deferSurfaceLayout(); |
| 5133 | try { |
| 5134 | if (launchStackId == DOCKED_STACK_ID) { |
| 5135 | mWindowManager.setDockedStackCreateState( |
| 5136 | activityOptions.getDockCreateMode(), null /* initialBounds */); |
Jorim Jaggi | 3c800a4 | 2016-04-15 19:44:50 -0700 | [diff] [blame] | 5137 | |
Matthew Ng | 606dd80 | 2017-06-05 14:06:32 -0700 | [diff] [blame] | 5138 | // Defer updating the stack in which recents is until the app transition is done, to |
| 5139 | // not run into issues where we still need to draw the task in recents but the |
| 5140 | // docked stack is already created. |
| 5141 | deferUpdateBounds(RECENTS_STACK_ID); |
| 5142 | mWindowManager.prepareAppTransition(TRANSIT_DOCK_TASK_FROM_RECENTS, false); |
Jorim Jaggi | 0b46f3c | 2016-03-14 12:21:37 +0100 | [diff] [blame] | 5143 | } |
Jorim Jaggi | 0b46f3c | 2016-03-14 12:21:37 +0100 | [diff] [blame] | 5144 | |
Matthew Ng | 606dd80 | 2017-06-05 14:06:32 -0700 | [diff] [blame] | 5145 | task = anyTaskForIdLocked(taskId, MATCH_TASK_IN_STACKS_OR_RECENT_TASKS_AND_RESTORE, |
| 5146 | launchStackId); |
| 5147 | if (task == null) { |
| 5148 | continueUpdateBounds(RECENTS_STACK_ID); |
| 5149 | mWindowManager.executeAppTransition(); |
| 5150 | throw new IllegalArgumentException( |
| 5151 | "startActivityFromRecentsInner: Task " + taskId + " not found."); |
| 5152 | } |
Jorim Jaggi | 0b46f3c | 2016-03-14 12:21:37 +0100 | [diff] [blame] | 5153 | |
Matthew Ng | 606dd80 | 2017-06-05 14:06:32 -0700 | [diff] [blame] | 5154 | // Since we don't have an actual source record here, we assume that the currently |
| 5155 | // focused activity was the source. |
| 5156 | final ActivityStack focusedStack = getFocusedStack(); |
| 5157 | final ActivityRecord sourceRecord = |
| 5158 | focusedStack != null ? focusedStack.topActivity() : null; |
| 5159 | |
| 5160 | if (launchStackId != INVALID_STACK_ID) { |
| 5161 | if (task.getStackId() != launchStackId) { |
| 5162 | task.reparent(launchStackId, ON_TOP, REPARENT_MOVE_STACK_TO_FRONT, ANIMATE, |
| 5163 | DEFER_RESUME, "startActivityFromRecents"); |
| 5164 | } |
| 5165 | } |
| 5166 | |
| 5167 | // If the user must confirm credentials (e.g. when first launching a work app and the |
| 5168 | // Work Challenge is present) let startActivityInPackage handle the intercepting. |
| 5169 | if (!mService.mUserController.shouldConfirmCredentials(task.userId) |
| 5170 | && task.getRootActivity() != null) { |
| 5171 | mService.mActivityStarter.sendPowerHintForLaunchStartIfNeeded(true /* forceSend */); |
| 5172 | mActivityMetricsLogger.notifyActivityLaunching(); |
Jorim Jaggi | 42befc6 | 2017-06-13 11:54:04 -0700 | [diff] [blame] | 5173 | mService.moveTaskToFrontLocked(task.taskId, 0, bOptions, true /* fromRecents */); |
Matthew Ng | 606dd80 | 2017-06-05 14:06:32 -0700 | [diff] [blame] | 5174 | mActivityMetricsLogger.notifyActivityLaunched(ActivityManager.START_TASK_TO_FRONT, |
| 5175 | task.getTopActivity()); |
| 5176 | |
| 5177 | // If we are launching the task in the docked stack, put it into resizing mode so |
| 5178 | // the window renders full-screen with the background filling the void. Also only |
| 5179 | // call this at the end to make sure that tasks exists on the window manager side. |
| 5180 | if (launchStackId == DOCKED_STACK_ID) { |
| 5181 | setResizingDuringAnimation(task); |
| 5182 | } |
| 5183 | |
| 5184 | mService.mActivityStarter.postStartActivityProcessing(task.getTopActivity(), |
| 5185 | ActivityManager.START_TASK_TO_FRONT, |
| 5186 | sourceRecord != null |
| 5187 | ? sourceRecord.getTask().getStackId() : INVALID_STACK_ID, |
| 5188 | sourceRecord, task.getStack()); |
| 5189 | return ActivityManager.START_TASK_TO_FRONT; |
| 5190 | } |
| 5191 | callingUid = task.mCallingUid; |
| 5192 | callingPackage = task.mCallingPackage; |
| 5193 | intent = task.intent; |
| 5194 | intent.addFlags(Intent.FLAG_ACTIVITY_LAUNCHED_FROM_HISTORY); |
| 5195 | userId = task.userId; |
| 5196 | int result = mService.startActivityInPackage(callingUid, callingPackage, intent, null, |
Wale Ogunwale | 692dcd6 | 2017-06-20 13:38:14 -0700 | [diff] [blame] | 5197 | null, null, 0, 0, bOptions, userId, null, task, "startActivityFromRecents"); |
Jorim Jaggi | 0b46f3c | 2016-03-14 12:21:37 +0100 | [diff] [blame] | 5198 | if (launchStackId == DOCKED_STACK_ID) { |
Wale Ogunwale | e1fe7fa2 | 2016-12-15 18:27:00 -0800 | [diff] [blame] | 5199 | setResizingDuringAnimation(task); |
Jorim Jaggi | 0b46f3c | 2016-03-14 12:21:37 +0100 | [diff] [blame] | 5200 | } |
Matthew Ng | 606dd80 | 2017-06-05 14:06:32 -0700 | [diff] [blame] | 5201 | return result; |
| 5202 | } finally { |
| 5203 | mWindowManager.continueSurfaceLayout(); |
Jorim Jaggi | 0b46f3c | 2016-03-14 12:21:37 +0100 | [diff] [blame] | 5204 | } |
Jorim Jaggi | 0b46f3c | 2016-03-14 12:21:37 +0100 | [diff] [blame] | 5205 | } |
Amith Yamasani | e8222e5 | 2016-04-08 15:28:47 -0700 | [diff] [blame] | 5206 | |
| 5207 | /** |
| 5208 | * @return a list of activities which are the top ones in each visible stack. The first |
| 5209 | * entry will be the focused activity. |
| 5210 | */ |
Andrii Kulian | 0864bbb | 2017-02-16 15:45:58 -0800 | [diff] [blame] | 5211 | List<IBinder> getTopVisibleActivities() { |
| 5212 | final ArrayList<IBinder> topActivityTokens = new ArrayList<>(); |
| 5213 | // Traverse all displays. |
Robert Carr | 22374c0 | 2017-02-21 13:01:47 -0800 | [diff] [blame] | 5214 | for (int i = mActivityDisplays.size() - 1; i >= 0; i--) { |
Andrii Kulian | 0864bbb | 2017-02-16 15:45:58 -0800 | [diff] [blame] | 5215 | final ActivityDisplay display = mActivityDisplays.valueAt(i); |
| 5216 | // Traverse all stacks on a display. |
| 5217 | for (int j = display.mStacks.size() - 1; j >= 0; j--) { |
| 5218 | final ActivityStack stack = display.mStacks.get(j); |
| 5219 | // Get top activity from a visible stack and add it to the list. |
Wale Ogunwale | cd501ec | 2017-04-07 08:53:41 -0700 | [diff] [blame] | 5220 | if (stack.shouldBeVisible(null /* starting */) |
Andrii Kulian | 0864bbb | 2017-02-16 15:45:58 -0800 | [diff] [blame] | 5221 | == ActivityStack.STACK_VISIBLE) { |
| 5222 | final ActivityRecord top = stack.topActivity(); |
| 5223 | if (top != null) { |
| 5224 | if (stack == mFocusedStack) { |
| 5225 | topActivityTokens.add(0, top.appToken); |
| 5226 | } else { |
| 5227 | topActivityTokens.add(top.appToken); |
| 5228 | } |
Amith Yamasani | e8222e5 | 2016-04-08 15:28:47 -0700 | [diff] [blame] | 5229 | } |
| 5230 | } |
| 5231 | } |
| 5232 | } |
| 5233 | return topActivityTokens; |
| 5234 | } |
Bryce Lee | 4a19438 | 2017-04-04 14:32:48 -0700 | [diff] [blame] | 5235 | |
| 5236 | /** |
| 5237 | * Internal container to store a match qualifier alongside a WaitResult. |
| 5238 | */ |
| 5239 | static class WaitInfo { |
| 5240 | private final ComponentName mTargetComponent; |
| 5241 | private final WaitResult mResult; |
| 5242 | |
| 5243 | public WaitInfo(ComponentName targetComponent, WaitResult result) { |
| 5244 | this.mTargetComponent = targetComponent; |
| 5245 | this.mResult = result; |
| 5246 | } |
| 5247 | |
Wale Ogunwale | 3270f17 | 2017-04-26 07:29:42 -0700 | [diff] [blame] | 5248 | public boolean matches(ComponentName targetComponent) { |
| 5249 | return mTargetComponent == null || mTargetComponent.equals(targetComponent); |
Bryce Lee | 4a19438 | 2017-04-04 14:32:48 -0700 | [diff] [blame] | 5250 | } |
| 5251 | |
| 5252 | public WaitResult getResult() { |
| 5253 | return mResult; |
| 5254 | } |
| 5255 | |
| 5256 | public ComponentName getComponent() { |
| 5257 | return mTargetComponent; |
| 5258 | } |
| 5259 | |
| 5260 | public void dump(PrintWriter pw, String prefix) { |
| 5261 | pw.println(prefix + "WaitInfo:"); |
| 5262 | pw.println(prefix + " mTargetComponent=" + mTargetComponent); |
| 5263 | pw.println(prefix + " mResult="); |
| 5264 | mResult.dump(pw, prefix); |
| 5265 | } |
| 5266 | } |
Craig Mautner | 2708430 | 2013-03-25 08:05:25 -0700 | [diff] [blame] | 5267 | } |