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 | |
Svetoslav | 7008b51 | 2015-06-24 18:47:07 -0700 | [diff] [blame] | 19 | import android.Manifest; |
Craig Mautner | 2420ead | 2013-04-01 17:13:20 -0700 | [diff] [blame] | 20 | import android.app.Activity; |
Craig Mautner | 23ac33b | 2013-04-01 16:26:35 -0700 | [diff] [blame] | 21 | import android.app.ActivityManager; |
Filip Gruszczynski | 80e29f1 | 2015-12-14 14:58:30 -0800 | [diff] [blame] | 22 | import android.app.ActivityManager.RunningTaskInfo; |
Wale Ogunwale | 3797c22 | 2015-10-27 14:21:58 -0700 | [diff] [blame] | 23 | import android.app.ActivityManager.StackId; |
Craig Mautner | ed6649f | 2013-12-02 14:08:25 -0800 | [diff] [blame] | 24 | import android.app.ActivityManager.StackInfo; |
Craig Mautner | 23ac33b | 2013-04-01 16:26:35 -0700 | [diff] [blame] | 25 | import android.app.ActivityOptions; |
| 26 | import android.app.AppGlobals; |
Svetoslav | 7008b51 | 2015-06-24 18:47:07 -0700 | [diff] [blame] | 27 | import android.app.AppOpsManager; |
Craig Mautner | 4a1cb22 | 2013-12-04 16:14:06 -0800 | [diff] [blame] | 28 | import android.app.IActivityContainer; |
| 29 | import android.app.IActivityContainerCallback; |
Craig Mautner | ce5f3cb | 2013-04-22 08:58:54 -0700 | [diff] [blame] | 30 | import android.app.IActivityManager; |
Filip Gruszczynski | 80e29f1 | 2015-12-14 14:58:30 -0800 | [diff] [blame] | 31 | import android.app.IActivityManager.WaitResult; |
Jeff Hao | 1b012d3 | 2014-08-20 10:35:34 -0700 | [diff] [blame] | 32 | import android.app.ProfilerInfo; |
Craig Mautner | 2420ead | 2013-04-01 17:13:20 -0700 | [diff] [blame] | 33 | import android.app.ResultInfo; |
justinzhang | 5286d3f | 2014-05-12 17:06:01 -0400 | [diff] [blame] | 34 | import android.app.StatusBarManager; |
Jason Monk | 35c62a4 | 2014-06-17 10:24:47 -0400 | [diff] [blame] | 35 | import android.app.admin.IDevicePolicyManager; |
Craig Mautner | 23ac33b | 2013-04-01 16:26:35 -0700 | [diff] [blame] | 36 | import android.content.ComponentName; |
Craig Mautner | 2219a1b | 2013-03-25 09:44:30 -0700 | [diff] [blame] | 37 | import android.content.Context; |
Craig Mautner | 23ac33b | 2013-04-01 16:26:35 -0700 | [diff] [blame] | 38 | import android.content.IIntentSender; |
Craig Mautner | 2219a1b | 2013-03-25 09:44:30 -0700 | [diff] [blame] | 39 | import android.content.Intent; |
| 40 | import android.content.pm.ActivityInfo; |
Craig Mautner | 23ac33b | 2013-04-01 16:26:35 -0700 | [diff] [blame] | 41 | import android.content.pm.ApplicationInfo; |
Svetoslav | 7008b51 | 2015-06-24 18:47:07 -0700 | [diff] [blame] | 42 | import android.content.pm.PackageInfo; |
Craig Mautner | 23ac33b | 2013-04-01 16:26:35 -0700 | [diff] [blame] | 43 | import android.content.pm.PackageManager; |
| 44 | import android.content.pm.ResolveInfo; |
Clara Bayarri | f7fea16 | 2015-10-22 16:09:52 +0100 | [diff] [blame] | 45 | import android.content.pm.UserInfo; |
Craig Mautner | 23ac33b | 2013-04-01 16:26:35 -0700 | [diff] [blame] | 46 | import android.content.res.Configuration; |
Wale Ogunwale | 60454db | 2015-01-23 16:05:07 -0800 | [diff] [blame] | 47 | import android.graphics.Rect; |
Craig Mautner | 4a1cb22 | 2013-12-04 16:14:06 -0800 | [diff] [blame] | 48 | import android.hardware.display.DisplayManager; |
| 49 | import android.hardware.display.DisplayManager.DisplayListener; |
Craig Mautner | 4504de5 | 2013-12-20 09:06:56 -0800 | [diff] [blame] | 50 | import android.hardware.display.DisplayManagerGlobal; |
| 51 | import android.hardware.display.VirtualDisplay; |
Jeff Brown | ca9bc70 | 2014-02-11 14:32:56 -0800 | [diff] [blame] | 52 | import android.hardware.input.InputManager; |
| 53 | import android.hardware.input.InputManagerInternal; |
Craig Mautner | 23ac33b | 2013-04-01 16:26:35 -0700 | [diff] [blame] | 54 | import android.os.Binder; |
Craig Mautner | b59dcfd | 2013-05-06 13:12:58 -0700 | [diff] [blame] | 55 | import android.os.Debug; |
Craig Mautner | ce5f3cb | 2013-04-22 08:58:54 -0700 | [diff] [blame] | 56 | import android.os.Handler; |
Craig Mautner | 23ac33b | 2013-04-01 16:26:35 -0700 | [diff] [blame] | 57 | import android.os.IBinder; |
Craig Mautner | 2219a1b | 2013-03-25 09:44:30 -0700 | [diff] [blame] | 58 | import android.os.Looper; |
Craig Mautner | 2420ead | 2013-04-01 17:13:20 -0700 | [diff] [blame] | 59 | import android.os.Message; |
Craig Mautner | 23ac33b | 2013-04-01 16:26:35 -0700 | [diff] [blame] | 60 | import android.os.ParcelFileDescriptor; |
Craig Mautner | 0eea92c | 2013-05-16 13:35:39 -0700 | [diff] [blame] | 61 | import android.os.PowerManager; |
Craig Mautner | 7ea5bd4 | 2013-07-05 15:27:08 -0700 | [diff] [blame] | 62 | import android.os.Process; |
Craig Mautner | 8d341ef | 2013-03-26 09:03:27 -0700 | [diff] [blame] | 63 | import android.os.RemoteException; |
justinzhang | 5286d3f | 2014-05-12 17:06:01 -0400 | [diff] [blame] | 64 | import android.os.ServiceManager; |
Craig Mautner | 23ac33b | 2013-04-01 16:26:35 -0700 | [diff] [blame] | 65 | import android.os.SystemClock; |
Wale Ogunwale | cad05a0 | 2015-09-25 10:41:44 -0700 | [diff] [blame] | 66 | import android.os.Trace; |
Craig Mautner | 5f2bb4c | 2015-03-12 16:10:27 -0700 | [diff] [blame] | 67 | import android.os.TransactionTooLargeException; |
Craig Mautner | 6170f73 | 2013-04-02 13:05:23 -0700 | [diff] [blame] | 68 | import android.os.UserHandle; |
Clara Bayarri | f7fea16 | 2015-10-22 16:09:52 +0100 | [diff] [blame] | 69 | import android.os.UserManager; |
Dianne Hackborn | 3d07c94 | 2015-03-13 18:02:54 -0700 | [diff] [blame] | 70 | import android.os.WorkSource; |
Svetoslav | 7008b51 | 2015-06-24 18:47:07 -0700 | [diff] [blame] | 71 | import android.provider.MediaStore; |
Jason Monk | 62515be | 2014-05-21 16:06:19 -0400 | [diff] [blame] | 72 | import android.provider.Settings; |
| 73 | import android.provider.Settings.SettingNotFoundException; |
Dianne Hackborn | 91097de | 2014-04-04 18:02:06 -0700 | [diff] [blame] | 74 | import android.service.voice.IVoiceInteractionSession; |
Svetoslav | 7008b51 | 2015-06-24 18:47:07 -0700 | [diff] [blame] | 75 | import android.util.ArrayMap; |
Dianne Hackborn | 89ad456 | 2014-08-24 16:45:38 -0700 | [diff] [blame] | 76 | import android.util.ArraySet; |
Craig Mautner | 2420ead | 2013-04-01 17:13:20 -0700 | [diff] [blame] | 77 | import android.util.EventLog; |
Craig Mautner | 8d341ef | 2013-03-26 09:03:27 -0700 | [diff] [blame] | 78 | import android.util.Slog; |
Craig Mautner | 4a1cb22 | 2013-12-04 16:14:06 -0800 | [diff] [blame] | 79 | import android.util.SparseArray; |
Craig Mautner | 4a1cb22 | 2013-12-04 16:14:06 -0800 | [diff] [blame] | 80 | import android.util.SparseIntArray; |
Craig Mautner | ed6649f | 2013-12-02 14:08:25 -0800 | [diff] [blame] | 81 | import android.view.Display; |
Craig Mautner | 4a1cb22 | 2013-12-04 16:14:06 -0800 | [diff] [blame] | 82 | import android.view.DisplayInfo; |
Jeff Brown | ca9bc70 | 2014-02-11 14:32:56 -0800 | [diff] [blame] | 83 | import android.view.InputEvent; |
Craig Mautner | 4504de5 | 2013-12-20 09:06:56 -0800 | [diff] [blame] | 84 | import android.view.Surface; |
Chong Zhang | b15758a | 2015-11-17 12:12:03 -0800 | [diff] [blame] | 85 | |
Dianne Hackborn | 85d558c | 2014-11-04 10:31:54 -0800 | [diff] [blame] | 86 | import com.android.internal.content.ReferrerIntent; |
Dianne Hackborn | cbfd23e | 2013-06-11 14:26:53 -0700 | [diff] [blame] | 87 | import com.android.internal.os.TransferPipe; |
justinzhang | 5286d3f | 2014-05-12 17:06:01 -0400 | [diff] [blame] | 88 | import com.android.internal.statusbar.IStatusBarService; |
Svetoslav | 7008b51 | 2015-06-24 18:47:07 -0700 | [diff] [blame] | 89 | import com.android.internal.util.ArrayUtils; |
Jason Monk | e069779 | 2014-08-04 16:28:09 -0400 | [diff] [blame] | 90 | import com.android.internal.widget.LockPatternUtils; |
Jeff Brown | ca9bc70 | 2014-02-11 14:32:56 -0800 | [diff] [blame] | 91 | import com.android.server.LocalServices; |
Craig Mautner | 2420ead | 2013-04-01 17:13:20 -0700 | [diff] [blame] | 92 | import com.android.server.am.ActivityStack.ActivityState; |
Craig Mautner | ce5f3cb | 2013-04-22 08:58:54 -0700 | [diff] [blame] | 93 | import com.android.server.wm.WindowManagerService; |
Craig Mautner | 23ac33b | 2013-04-01 16:26:35 -0700 | [diff] [blame] | 94 | |
Craig Mautner | 8d341ef | 2013-03-26 09:03:27 -0700 | [diff] [blame] | 95 | import java.io.FileDescriptor; |
| 96 | import java.io.IOException; |
Craig Mautner | 2708430 | 2013-03-25 08:05:25 -0700 | [diff] [blame] | 97 | import java.io.PrintWriter; |
Craig Mautner | 2219a1b | 2013-03-25 09:44:30 -0700 | [diff] [blame] | 98 | import java.util.ArrayList; |
Craig Mautner | e057020 | 2015-05-13 13:06:11 -0700 | [diff] [blame] | 99 | import java.util.Arrays; |
Craig Mautner | 8d341ef | 2013-03-26 09:03:27 -0700 | [diff] [blame] | 100 | import java.util.List; |
Filip Gruszczynski | 84fa335 | 2016-01-25 16:28:49 -0800 | [diff] [blame] | 101 | import java.util.Objects; |
Wale Ogunwale | 540e123 | 2015-05-01 15:35:39 -0700 | [diff] [blame] | 102 | import java.util.Set; |
Craig Mautner | 2708430 | 2013-03-25 08:05:25 -0700 | [diff] [blame] | 103 | |
Jorim Jaggi | fe89d12 | 2015-12-22 16:28:44 +0100 | [diff] [blame] | 104 | import static android.Manifest.permission.START_ANY_ACTIVITY; |
| 105 | import static android.app.ActivityManager.LOCK_TASK_MODE_LOCKED; |
| 106 | import static android.app.ActivityManager.LOCK_TASK_MODE_NONE; |
| 107 | import static android.app.ActivityManager.LOCK_TASK_MODE_PINNED; |
| 108 | import static android.app.ActivityManager.RESIZE_MODE_FORCED; |
| 109 | import static android.app.ActivityManager.RESIZE_MODE_SYSTEM; |
| 110 | import static android.app.ActivityManager.StackId.DOCKED_STACK_ID; |
| 111 | import static android.app.ActivityManager.StackId.FIRST_DYNAMIC_STACK_ID; |
| 112 | import static android.app.ActivityManager.StackId.FIRST_STATIC_STACK_ID; |
| 113 | import static android.app.ActivityManager.StackId.FREEFORM_WORKSPACE_STACK_ID; |
| 114 | import static android.app.ActivityManager.StackId.FULLSCREEN_WORKSPACE_STACK_ID; |
| 115 | import static android.app.ActivityManager.StackId.HOME_STACK_ID; |
| 116 | import static android.app.ActivityManager.StackId.INVALID_STACK_ID; |
| 117 | import static android.app.ActivityManager.StackId.LAST_STATIC_STACK_ID; |
| 118 | import static android.app.ActivityManager.StackId.PINNED_STACK_ID; |
| 119 | import static android.content.Intent.FLAG_ACTIVITY_MULTIPLE_TASK; |
| 120 | import static android.content.Intent.FLAG_ACTIVITY_NEW_TASK; |
| 121 | import static android.content.pm.ActivityInfo.FLAG_SHOW_FOR_ALL_USERS; |
Wale Ogunwale | b1faf60 | 2016-01-27 09:12:31 -0800 | [diff] [blame] | 122 | import static android.content.pm.ActivityInfo.RESIZE_MODE_UNRESIZEABLE; |
Jorim Jaggi | fe89d12 | 2015-12-22 16:28:44 +0100 | [diff] [blame] | 123 | import static android.content.pm.PackageManager.PERMISSION_GRANTED; |
| 124 | import static android.os.Trace.TRACE_TAG_ACTIVITY_MANAGER; |
| 125 | import static com.android.server.am.ActivityManagerDebugConfig.DEBUG_ALL; |
| 126 | import static com.android.server.am.ActivityManagerDebugConfig.DEBUG_CONTAINERS; |
| 127 | import static com.android.server.am.ActivityManagerDebugConfig.DEBUG_IDLE; |
| 128 | import static com.android.server.am.ActivityManagerDebugConfig.DEBUG_LOCKSCREEN; |
| 129 | import static com.android.server.am.ActivityManagerDebugConfig.DEBUG_LOCKTASK; |
| 130 | import static com.android.server.am.ActivityManagerDebugConfig.DEBUG_PAUSE; |
| 131 | import static com.android.server.am.ActivityManagerDebugConfig.DEBUG_RECENTS; |
| 132 | import static com.android.server.am.ActivityManagerDebugConfig.DEBUG_RELEASE; |
| 133 | import static com.android.server.am.ActivityManagerDebugConfig.DEBUG_STACK; |
| 134 | import static com.android.server.am.ActivityManagerDebugConfig.DEBUG_STATES; |
| 135 | import static com.android.server.am.ActivityManagerDebugConfig.DEBUG_SWITCH; |
| 136 | import static com.android.server.am.ActivityManagerDebugConfig.DEBUG_TASKS; |
| 137 | import static com.android.server.am.ActivityManagerDebugConfig.DEBUG_VISIBLE_BEHIND; |
| 138 | import static com.android.server.am.ActivityManagerDebugConfig.POSTFIX_CONTAINERS; |
| 139 | import static com.android.server.am.ActivityManagerDebugConfig.POSTFIX_IDLE; |
| 140 | import static com.android.server.am.ActivityManagerDebugConfig.POSTFIX_LOCKTASK; |
| 141 | import static com.android.server.am.ActivityManagerDebugConfig.POSTFIX_PAUSE; |
| 142 | import static com.android.server.am.ActivityManagerDebugConfig.POSTFIX_RECENTS; |
| 143 | import static com.android.server.am.ActivityManagerDebugConfig.POSTFIX_RELEASE; |
| 144 | import static com.android.server.am.ActivityManagerDebugConfig.POSTFIX_STACK; |
| 145 | import static com.android.server.am.ActivityManagerDebugConfig.POSTFIX_STATES; |
| 146 | import static com.android.server.am.ActivityManagerDebugConfig.POSTFIX_SWITCH; |
| 147 | import static com.android.server.am.ActivityManagerDebugConfig.POSTFIX_TASKS; |
| 148 | import static com.android.server.am.ActivityManagerDebugConfig.POSTFIX_VISIBLE_BEHIND; |
| 149 | import static com.android.server.am.ActivityManagerDebugConfig.TAG_AM; |
| 150 | import static com.android.server.am.ActivityManagerDebugConfig.TAG_WITH_CLASS_NAME; |
Wale Ogunwale | 480dca0 | 2016-02-06 13:58:29 -0800 | [diff] [blame] | 151 | import static com.android.server.am.ActivityManagerService.ANIMATE; |
Jorim Jaggi | fe89d12 | 2015-12-22 16:28:44 +0100 | [diff] [blame] | 152 | import static com.android.server.am.ActivityManagerService.FIRST_SUPERVISOR_STACK_MSG; |
| 153 | import static com.android.server.am.ActivityRecord.APPLICATION_ACTIVITY_TYPE; |
| 154 | import static com.android.server.am.ActivityRecord.HOME_ACTIVITY_TYPE; |
| 155 | import static com.android.server.am.ActivityRecord.RECENTS_ACTIVITY_TYPE; |
| 156 | import static com.android.server.am.ActivityStack.ActivityState.DESTROYED; |
| 157 | import static com.android.server.am.ActivityStack.ActivityState.DESTROYING; |
| 158 | import static com.android.server.am.ActivityStack.ActivityState.INITIALIZING; |
| 159 | import static com.android.server.am.ActivityStack.ActivityState.PAUSED; |
| 160 | import static com.android.server.am.ActivityStack.ActivityState.PAUSING; |
| 161 | import static com.android.server.am.ActivityStack.ActivityState.RESUMED; |
| 162 | import static com.android.server.am.ActivityStack.ActivityState.STOPPED; |
| 163 | import static com.android.server.am.ActivityStack.ActivityState.STOPPING; |
| 164 | import static com.android.server.am.TaskRecord.LOCK_TASK_AUTH_DONT_LOCK; |
| 165 | import static com.android.server.am.TaskRecord.LOCK_TASK_AUTH_LAUNCHABLE; |
| 166 | import static com.android.server.am.TaskRecord.LOCK_TASK_AUTH_LAUNCHABLE_PRIV; |
| 167 | import static com.android.server.am.TaskRecord.LOCK_TASK_AUTH_PINNABLE; |
| 168 | import static com.android.server.am.TaskRecord.LOCK_TASK_AUTH_WHITELISTED; |
| 169 | |
Craig Mautner | 4a1cb22 | 2013-12-04 16:14:06 -0800 | [diff] [blame] | 170 | public final class ActivityStackSupervisor implements DisplayListener { |
Wale Ogunwale | e23149f | 2015-03-06 15:39:44 -0800 | [diff] [blame] | 171 | private static final String TAG = TAG_WITH_CLASS_NAME ? "ActivityStackSupervisor" : TAG_AM; |
Wale Ogunwale | 0fc365c | 2015-05-25 19:35:42 -0700 | [diff] [blame] | 172 | private static final String TAG_CONTAINERS = TAG + POSTFIX_CONTAINERS; |
Wale Ogunwale | 0fc365c | 2015-05-25 19:35:42 -0700 | [diff] [blame] | 173 | private static final String TAG_IDLE = TAG + POSTFIX_IDLE; |
Craig Mautner | e057020 | 2015-05-13 13:06:11 -0700 | [diff] [blame] | 174 | private static final String TAG_LOCKTASK = TAG + POSTFIX_LOCKTASK; |
Wale Ogunwale | ee006da | 2015-03-30 14:49:25 -0700 | [diff] [blame] | 175 | private static final String TAG_PAUSE = TAG + POSTFIX_PAUSE; |
Wale Ogunwale | ee006da | 2015-03-30 14:49:25 -0700 | [diff] [blame] | 176 | private static final String TAG_RECENTS = TAG + POSTFIX_RECENTS; |
Wale Ogunwale | 0fc365c | 2015-05-25 19:35:42 -0700 | [diff] [blame] | 177 | private static final String TAG_RELEASE = TAG + POSTFIX_RELEASE; |
Wale Ogunwale | ee006da | 2015-03-30 14:49:25 -0700 | [diff] [blame] | 178 | private static final String TAG_STACK = TAG + POSTFIX_STACK; |
Wale Ogunwale | 0fc365c | 2015-05-25 19:35:42 -0700 | [diff] [blame] | 179 | private static final String TAG_STATES = TAG + POSTFIX_STATES; |
Wale Ogunwale | ee006da | 2015-03-30 14:49:25 -0700 | [diff] [blame] | 180 | private static final String TAG_SWITCH = TAG + POSTFIX_SWITCH; |
Filip Gruszczynski | 07a0e49 | 2015-12-17 14:16:38 -0800 | [diff] [blame] | 181 | static final String TAG_TASKS = TAG + POSTFIX_TASKS; |
Wale Ogunwale | 0fc365c | 2015-05-25 19:35:42 -0700 | [diff] [blame] | 182 | private static final String TAG_VISIBLE_BEHIND = TAG + POSTFIX_VISIBLE_BEHIND; |
Wale Ogunwale | e23149f | 2015-03-06 15:39:44 -0800 | [diff] [blame] | 183 | |
Craig Mautner | f333327 | 2013-04-22 10:55:53 -0700 | [diff] [blame] | 184 | /** 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] | 185 | static final int IDLE_TIMEOUT = 10 * 1000; |
Craig Mautner | f333327 | 2013-04-22 10:55:53 -0700 | [diff] [blame] | 186 | |
Craig Mautner | 0eea92c | 2013-05-16 13:35:39 -0700 | [diff] [blame] | 187 | /** How long we can hold the sleep wake lock before giving up. */ |
Wale Ogunwale | 0fc365c | 2015-05-25 19:35:42 -0700 | [diff] [blame] | 188 | static final int SLEEP_TIMEOUT = 5 * 1000; |
Craig Mautner | 0eea92c | 2013-05-16 13:35:39 -0700 | [diff] [blame] | 189 | |
Craig Mautner | 7ea5bd4 | 2013-07-05 15:27:08 -0700 | [diff] [blame] | 190 | // How long we can hold the launch wake lock before giving up. |
Wale Ogunwale | 0fc365c | 2015-05-25 19:35:42 -0700 | [diff] [blame] | 191 | static final int LAUNCH_TIMEOUT = 10 * 1000; |
Craig Mautner | 7ea5bd4 | 2013-07-05 15:27:08 -0700 | [diff] [blame] | 192 | |
Craig Mautner | 05d2903 | 2013-05-03 13:40:13 -0700 | [diff] [blame] | 193 | static final int IDLE_TIMEOUT_MSG = FIRST_SUPERVISOR_STACK_MSG; |
| 194 | static final int IDLE_NOW_MSG = FIRST_SUPERVISOR_STACK_MSG + 1; |
| 195 | static final int RESUME_TOP_ACTIVITY_MSG = FIRST_SUPERVISOR_STACK_MSG + 2; |
Craig Mautner | 0eea92c | 2013-05-16 13:35:39 -0700 | [diff] [blame] | 196 | static final int SLEEP_TIMEOUT_MSG = FIRST_SUPERVISOR_STACK_MSG + 3; |
Craig Mautner | 7ea5bd4 | 2013-07-05 15:27:08 -0700 | [diff] [blame] | 197 | static final int LAUNCH_TIMEOUT_MSG = FIRST_SUPERVISOR_STACK_MSG + 4; |
Craig Mautner | 4a1cb22 | 2013-12-04 16:14:06 -0800 | [diff] [blame] | 198 | static final int HANDLE_DISPLAY_ADDED = FIRST_SUPERVISOR_STACK_MSG + 5; |
| 199 | static final int HANDLE_DISPLAY_CHANGED = FIRST_SUPERVISOR_STACK_MSG + 6; |
| 200 | static final int HANDLE_DISPLAY_REMOVED = FIRST_SUPERVISOR_STACK_MSG + 7; |
Craig Mautner | e3a00d7 | 2014-04-16 08:31:19 -0700 | [diff] [blame] | 201 | static final int CONTAINER_CALLBACK_VISIBILITY = FIRST_SUPERVISOR_STACK_MSG + 8; |
justinzhang | 5286d3f | 2014-05-12 17:06:01 -0400 | [diff] [blame] | 202 | static final int LOCK_TASK_START_MSG = FIRST_SUPERVISOR_STACK_MSG + 9; |
| 203 | static final int LOCK_TASK_END_MSG = FIRST_SUPERVISOR_STACK_MSG + 10; |
Craig Mautner | 6cd6cec | 2015-04-01 00:02:12 -0700 | [diff] [blame] | 204 | 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] | 205 | static final int LAUNCH_TASK_BEHIND_COMPLETE = FIRST_SUPERVISOR_STACK_MSG + 12; |
Craig Mautner | c21ae9e | 2015-04-15 09:45:42 -0700 | [diff] [blame] | 206 | 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] | 207 | static final int REPORT_MULTI_WINDOW_MODE_CHANGED_MSG = FIRST_SUPERVISOR_STACK_MSG + 14; |
| 208 | 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] | 209 | |
Wale Ogunwale | 040b470 | 2015-08-06 18:10:50 -0700 | [diff] [blame] | 210 | private static final String VIRTUAL_DISPLAY_BASE_NAME = "ActivityViewVirtualDisplay"; |
Craig Mautner | 7ea5bd4 | 2013-07-05 15:27:08 -0700 | [diff] [blame] | 211 | |
Jason Monk | 62515be | 2014-05-21 16:06:19 -0400 | [diff] [blame] | 212 | private static final String LOCK_TASK_TAG = "Lock-to-App"; |
| 213 | |
Wale Ogunwale | 040b470 | 2015-08-06 18:10:50 -0700 | [diff] [blame] | 214 | // Used to indicate if an object (e.g. stack) that we are trying to get |
| 215 | // should be created if it doesn't exist already. |
Filip Gruszczynski | 07a0e49 | 2015-12-17 14:16:38 -0800 | [diff] [blame] | 216 | static final boolean CREATE_IF_NEEDED = true; |
Wale Ogunwale | 040b470 | 2015-08-06 18:10:50 -0700 | [diff] [blame] | 217 | |
Filip Gruszczynski | bc5a6c5 | 2015-09-22 13:13:24 -0700 | [diff] [blame] | 218 | // Used to indicate that windows of activities should be preserved during the resize. |
| 219 | static final boolean PRESERVE_WINDOWS = true; |
| 220 | |
Wale Ogunwale | 040b470 | 2015-08-06 18:10:50 -0700 | [diff] [blame] | 221 | // Used to indicate if an object (e.g. task) should be moved/created |
| 222 | // at the top of its container (e.g. stack). |
Wale Ogunwale | b30daaa | 2015-08-07 21:50:49 -0700 | [diff] [blame] | 223 | static final boolean ON_TOP = true; |
Wale Ogunwale | 040b470 | 2015-08-06 18:10:50 -0700 | [diff] [blame] | 224 | |
| 225 | // Used to indicate that an objects (e.g. task) removal from its container |
| 226 | // (e.g. stack) is due to it moving to another container. |
| 227 | static final boolean MOVING = true; |
| 228 | |
Wale Ogunwale | b34a7ad | 2015-08-14 11:05:30 -0700 | [diff] [blame] | 229 | // Force the focus to change to the stack we are moving a task to.. |
| 230 | static final boolean FORCE_FOCUS = true; |
| 231 | |
Wale Ogunwale | 7e8184b | 2015-10-05 14:37:03 -0700 | [diff] [blame] | 232 | // Restore task from the saved recents if it can't be found in any live stack. |
| 233 | static final boolean RESTORE_FROM_RECENTS = true; |
| 234 | |
Svetoslav | 7008b51 | 2015-06-24 18:47:07 -0700 | [diff] [blame] | 235 | // Activity actions an app cannot start if it uses a permission which is not granted. |
| 236 | private static final ArrayMap<String, String> ACTION_TO_RUNTIME_PERMISSION = |
| 237 | new ArrayMap<>(); |
Filip Gruszczynski | bc5a6c5 | 2015-09-22 13:13:24 -0700 | [diff] [blame] | 238 | |
Svetoslav | 7008b51 | 2015-06-24 18:47:07 -0700 | [diff] [blame] | 239 | static { |
| 240 | ACTION_TO_RUNTIME_PERMISSION.put(MediaStore.ACTION_IMAGE_CAPTURE, |
| 241 | Manifest.permission.CAMERA); |
| 242 | ACTION_TO_RUNTIME_PERMISSION.put(MediaStore.ACTION_VIDEO_CAPTURE, |
| 243 | Manifest.permission.CAMERA); |
| 244 | ACTION_TO_RUNTIME_PERMISSION.put(Intent.ACTION_CALL, |
| 245 | Manifest.permission.CALL_PHONE); |
| 246 | } |
| 247 | |
Svet Ganov | 99b6043 | 2015-06-27 13:15:22 -0700 | [diff] [blame] | 248 | /** Action restriction: launching the activity is not restricted. */ |
| 249 | private static final int ACTIVITY_RESTRICTION_NONE = 0; |
| 250 | /** Action restriction: launching the activity is restricted by a permission. */ |
| 251 | private static final int ACTIVITY_RESTRICTION_PERMISSION = 1; |
| 252 | /** Action restriction: launching the activity is restricted by an app op. */ |
| 253 | private static final int ACTIVITY_RESTRICTION_APPOP = 2; |
Svetoslav | 7008b51 | 2015-06-24 18:47:07 -0700 | [diff] [blame] | 254 | |
Wale Ogunwale | 3e3e66f | 2015-09-10 15:40:19 -0700 | [diff] [blame] | 255 | // The height/width divide used when fitting a task within a bounds with method |
| 256 | // {@link #fitWithinBounds}. |
| 257 | // We always want the task to to be visible in the bounds without affecting its size when |
| 258 | // fitting. To make sure this is the case, we don't adjust the task left or top side pass |
| 259 | // the input bounds right or bottom side minus the width or height divided by this value. |
| 260 | private static final int FIT_WITHIN_BOUNDS_DIVIDER = 3; |
| 261 | |
justinzhang | 5286d3f | 2014-05-12 17:06:01 -0400 | [diff] [blame] | 262 | /** Status Bar Service **/ |
| 263 | private IBinder mToken = new Binder(); |
| 264 | private IStatusBarService mStatusBarService; |
Jason Monk | 35c62a4 | 2014-06-17 10:24:47 -0400 | [diff] [blame] | 265 | private IDevicePolicyManager mDevicePolicyManager; |
justinzhang | 5286d3f | 2014-05-12 17:06:01 -0400 | [diff] [blame] | 266 | |
Craig Mautner | 7ea5bd4 | 2013-07-05 15:27:08 -0700 | [diff] [blame] | 267 | // For debugging to make sure the caller when acquiring/releasing our |
| 268 | // wake lock is the system process. |
| 269 | static final boolean VALIDATE_WAKE_LOCK_CALLER = false; |
Suprabh Shukla | 09a88f5 | 2015-12-02 14:36:31 -0800 | [diff] [blame] | 270 | /** The number of distinct task ids that can be assigned to the tasks of a single user */ |
| 271 | 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] | 272 | |
Craig Mautner | 2708430 | 2013-03-25 08:05:25 -0700 | [diff] [blame] | 273 | final ActivityManagerService mService; |
| 274 | |
Suprabh Shukla | 09a88f5 | 2015-12-02 14:36:31 -0800 | [diff] [blame] | 275 | private RecentTasks mRecentTasks; |
Wale Ogunwale | c82f2f5 | 2014-12-09 09:32:50 -0800 | [diff] [blame] | 276 | |
Craig Mautner | ce5f3cb | 2013-04-22 08:58:54 -0700 | [diff] [blame] | 277 | final ActivityStackSupervisorHandler mHandler; |
| 278 | |
| 279 | /** Short cut */ |
| 280 | WindowManagerService mWindowManager; |
Craig Mautner | 4a1cb22 | 2013-12-04 16:14:06 -0800 | [diff] [blame] | 281 | DisplayManager mDisplayManager; |
Craig Mautner | ce5f3cb | 2013-04-22 08:58:54 -0700 | [diff] [blame] | 282 | |
Wale Ogunwale | ddc1cb2 | 2015-07-25 19:23:04 -0700 | [diff] [blame] | 283 | /** Counter for next free stack ID to use for dynamic activity stacks. */ |
| 284 | private int mNextFreeStackId = FIRST_DYNAMIC_STACK_ID; |
Craig Mautner | 8d341ef | 2013-03-26 09:03:27 -0700 | [diff] [blame] | 285 | |
Suprabh Shukla | 09a88f5 | 2015-12-02 14:36:31 -0800 | [diff] [blame] | 286 | /** |
| 287 | * Maps the task identifier that activities are currently being started in to the userId of the |
| 288 | * task. Each time a new task is created, the entry for the userId of the task is incremented |
| 289 | */ |
| 290 | private final SparseIntArray mCurTaskIdForUser = new SparseIntArray(20); |
Craig Mautner | 8d341ef | 2013-03-26 09:03:27 -0700 | [diff] [blame] | 291 | |
Craig Mautner | 2420ead | 2013-04-01 17:13:20 -0700 | [diff] [blame] | 292 | /** The current user */ |
Filip Gruszczynski | 07a0e49 | 2015-12-17 14:16:38 -0800 | [diff] [blame] | 293 | int mCurrentUser; |
Craig Mautner | 2420ead | 2013-04-01 17:13:20 -0700 | [diff] [blame] | 294 | |
Craig Mautner | e0a3884 | 2013-12-16 16:14:02 -0800 | [diff] [blame] | 295 | /** The stack containing the launcher app. Assumed to always be attached to |
| 296 | * Display.DEFAULT_DISPLAY. */ |
Filip Gruszczynski | 07a0e49 | 2015-12-17 14:16:38 -0800 | [diff] [blame] | 297 | ActivityStack mHomeStack; |
Craig Mautner | 20e7227 | 2013-04-01 13:45:53 -0700 | [diff] [blame] | 298 | |
Craig Mautner | e0a3884 | 2013-12-16 16:14:02 -0800 | [diff] [blame] | 299 | /** The stack currently receiving input or launching the next activity. */ |
Filip Gruszczynski | 07a0e49 | 2015-12-17 14:16:38 -0800 | [diff] [blame] | 300 | ActivityStack mFocusedStack; |
Craig Mautner | 8d341ef | 2013-03-26 09:03:27 -0700 | [diff] [blame] | 301 | |
Craig Mautner | 4a1cb22 | 2013-12-04 16:14:06 -0800 | [diff] [blame] | 302 | /** If this is the same as mFocusedStack then the activity on the top of the focused stack has |
| 303 | * 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] | 304 | * stack becomes resumed after which it will be set to mFocusedStack. */ |
Craig Mautner | 4a1cb22 | 2013-12-04 16:14:06 -0800 | [diff] [blame] | 305 | private ActivityStack mLastFocusedStack; |
Craig Mautner | de4ef02 | 2013-04-07 19:01:33 -0700 | [diff] [blame] | 306 | |
| 307 | /** List of activities that are waiting for a new activity to become visible before completing |
| 308 | * whatever operation they are supposed to do. */ |
Craig Mautner | 8c14c15 | 2015-01-15 17:32:07 -0800 | [diff] [blame] | 309 | final ArrayList<ActivityRecord> mWaitingVisibleActivities = new ArrayList<>(); |
Craig Mautner | de4ef02 | 2013-04-07 19:01:33 -0700 | [diff] [blame] | 310 | |
Craig Mautner | ce5f3cb | 2013-04-22 08:58:54 -0700 | [diff] [blame] | 311 | /** List of processes waiting to find out about the next visible activity. */ |
Craig Mautner | 8c14c15 | 2015-01-15 17:32:07 -0800 | [diff] [blame] | 312 | final ArrayList<IActivityManager.WaitResult> mWaitingActivityVisible = new ArrayList<>(); |
Craig Mautner | ce5f3cb | 2013-04-22 08:58:54 -0700 | [diff] [blame] | 313 | |
| 314 | /** List of processes waiting to find out about the next launched activity. */ |
Craig Mautner | 8c14c15 | 2015-01-15 17:32:07 -0800 | [diff] [blame] | 315 | final ArrayList<IActivityManager.WaitResult> mWaitingActivityLaunched = new ArrayList<>(); |
Craig Mautner | ce5f3cb | 2013-04-22 08:58:54 -0700 | [diff] [blame] | 316 | |
Craig Mautner | de4ef02 | 2013-04-07 19:01:33 -0700 | [diff] [blame] | 317 | /** List of activities that are ready to be stopped, but waiting for the next activity to |
| 318 | * settle down before doing so. */ |
Craig Mautner | 8c14c15 | 2015-01-15 17:32:07 -0800 | [diff] [blame] | 319 | final ArrayList<ActivityRecord> mStoppingActivities = new ArrayList<>(); |
Craig Mautner | de4ef02 | 2013-04-07 19:01:33 -0700 | [diff] [blame] | 320 | |
Craig Mautner | f333327 | 2013-04-22 10:55:53 -0700 | [diff] [blame] | 321 | /** List of activities that are ready to be finished, but waiting for the previous activity to |
| 322 | * settle down before doing so. It contains ActivityRecord objects. */ |
Craig Mautner | 8c14c15 | 2015-01-15 17:32:07 -0800 | [diff] [blame] | 323 | final ArrayList<ActivityRecord> mFinishingActivities = new ArrayList<>(); |
Craig Mautner | f333327 | 2013-04-22 10:55:53 -0700 | [diff] [blame] | 324 | |
Craig Mautner | 0eea92c | 2013-05-16 13:35:39 -0700 | [diff] [blame] | 325 | /** List of activities that are in the process of going to sleep. */ |
Craig Mautner | 8c14c15 | 2015-01-15 17:32:07 -0800 | [diff] [blame] | 326 | final ArrayList<ActivityRecord> mGoingToSleepActivities = new ArrayList<>(); |
Craig Mautner | 0eea92c | 2013-05-16 13:35:39 -0700 | [diff] [blame] | 327 | |
Wale Ogunwale | 22e2526 | 2016-02-01 10:32:02 -0800 | [diff] [blame] | 328 | /** List of activities whose multi-window mode changed that we need to report to the |
| 329 | * application */ |
| 330 | final ArrayList<ActivityRecord> mMultiWindowModeChangedActivities = new ArrayList<>(); |
| 331 | |
| 332 | /** List of activities whose picture-in-picture mode changed that we need to report to the |
| 333 | * application */ |
| 334 | final ArrayList<ActivityRecord> mPipModeChangedActivities = new ArrayList<>(); |
| 335 | |
Craig Mautner | f333327 | 2013-04-22 10:55:53 -0700 | [diff] [blame] | 336 | /** Used on user changes */ |
Amith Yamasani | 37a40c2 | 2015-06-17 13:25:42 -0700 | [diff] [blame] | 337 | final ArrayList<UserState> mStartingUsers = new ArrayList<>(); |
Craig Mautner | f333327 | 2013-04-22 10:55:53 -0700 | [diff] [blame] | 338 | |
Amith Yamasani | 1a7eaaa5 | 2014-05-07 10:22:15 -0700 | [diff] [blame] | 339 | /** Used to queue up any background users being started */ |
Amith Yamasani | 37a40c2 | 2015-06-17 13:25:42 -0700 | [diff] [blame] | 340 | final ArrayList<UserState> mStartingBackgroundUsers = new ArrayList<>(); |
Amith Yamasani | 1a7eaaa5 | 2014-05-07 10:22:15 -0700 | [diff] [blame] | 341 | |
Craig Mautner | de4ef02 | 2013-04-07 19:01:33 -0700 | [diff] [blame] | 342 | /** Set to indicate whether to issue an onUserLeaving callback when a newly launched activity |
| 343 | * is being brought in front of us. */ |
| 344 | boolean mUserLeaving = false; |
| 345 | |
Craig Mautner | 0eea92c | 2013-05-16 13:35:39 -0700 | [diff] [blame] | 346 | /** Set when we have taken too long waiting to go to sleep. */ |
| 347 | boolean mSleepTimeout = false; |
| 348 | |
| 349 | /** |
Craig Mautner | 7ea5bd4 | 2013-07-05 15:27:08 -0700 | [diff] [blame] | 350 | * We don't want to allow the device to go to sleep while in the process |
| 351 | * of launching an activity. This is primarily to allow alarm intent |
| 352 | * receivers to launch an activity and get that to run before the device |
| 353 | * goes back to sleep. |
| 354 | */ |
Jeff Brown | 2c43c33 | 2014-06-12 22:38:59 -0700 | [diff] [blame] | 355 | PowerManager.WakeLock mLaunchingActivity; |
Craig Mautner | 7ea5bd4 | 2013-07-05 15:27:08 -0700 | [diff] [blame] | 356 | |
| 357 | /** |
Craig Mautner | 0eea92c | 2013-05-16 13:35:39 -0700 | [diff] [blame] | 358 | * Set when the system is going to sleep, until we have |
| 359 | * successfully paused the current activity and released our wake lock. |
| 360 | * At that point the system is allowed to actually sleep. |
| 361 | */ |
Jeff Brown | 2c43c33 | 2014-06-12 22:38:59 -0700 | [diff] [blame] | 362 | PowerManager.WakeLock mGoingToSleep; |
Craig Mautner | 0eea92c | 2013-05-16 13:35:39 -0700 | [diff] [blame] | 363 | |
Craig Mautner | 4f1df4f | 2013-10-15 15:44:14 -0700 | [diff] [blame] | 364 | /** Stack id of the front stack when user switched, indexed by userId. */ |
| 365 | SparseIntArray mUserStackInFront = new SparseIntArray(2); |
Craig Mautner | 93529a4 | 2013-10-04 15:03:13 -0700 | [diff] [blame] | 366 | |
Craig Mautner | 4504de5 | 2013-12-20 09:06:56 -0800 | [diff] [blame] | 367 | // TODO: Add listener for removal of references. |
Craig Mautner | 4a1cb22 | 2013-12-04 16:14:06 -0800 | [diff] [blame] | 368 | /** Mapping from (ActivityStack/TaskStack).mStackId to their current state */ |
Craig Mautner | 15df08a | 2015-04-01 12:17:18 -0700 | [diff] [blame] | 369 | private SparseArray<ActivityContainer> mActivityContainers = new SparseArray<>(); |
Craig Mautner | 4a1cb22 | 2013-12-04 16:14:06 -0800 | [diff] [blame] | 370 | |
| 371 | /** Mapping from displayId to display current state */ |
Craig Mautner | 15df08a | 2015-04-01 12:17:18 -0700 | [diff] [blame] | 372 | private final SparseArray<ActivityDisplay> mActivityDisplays = new SparseArray<>(); |
Craig Mautner | 4a1cb22 | 2013-12-04 16:14:06 -0800 | [diff] [blame] | 373 | |
Jeff Brown | ca9bc70 | 2014-02-11 14:32:56 -0800 | [diff] [blame] | 374 | InputManagerInternal mInputManagerInternal; |
| 375 | |
Craig Mautner | 15df08a | 2015-04-01 12:17:18 -0700 | [diff] [blame] | 376 | /** The chain of tasks in lockTask mode. The current frontmost task is at the top, and tasks |
| 377 | * may be finished until there is only one entry left. If this is empty the system is not |
| 378 | * in lockTask mode. */ |
| 379 | ArrayList<TaskRecord> mLockTaskModeTasks = new ArrayList<>(); |
Benjamin Franz | 4326114 | 2015-02-11 15:59:44 +0000 | [diff] [blame] | 380 | /** Store the current lock task mode. Possible values: |
Craig Mautner | 2568c3a | 2015-03-26 14:22:34 -0700 | [diff] [blame] | 381 | * {@link ActivityManager#LOCK_TASK_MODE_NONE}, {@link ActivityManager#LOCK_TASK_MODE_LOCKED}, |
| 382 | * {@link ActivityManager#LOCK_TASK_MODE_PINNED} |
Benjamin Franz | 4326114 | 2015-02-11 15:59:44 +0000 | [diff] [blame] | 383 | */ |
| 384 | private int mLockTaskModeState; |
Jason Monk | 62515be | 2014-05-21 16:06:19 -0400 | [diff] [blame] | 385 | /** |
| 386 | * Notifies the user when entering/exiting lock-task. |
| 387 | */ |
| 388 | private LockTaskNotify mLockTaskNotify; |
Craig Mautner | aea74a5 | 2014-03-08 14:23:10 -0800 | [diff] [blame] | 389 | |
Wale Ogunwale | d046a01 | 2015-12-24 13:05:59 -0800 | [diff] [blame] | 390 | /** Used to keep resumeTopActivityUncheckedLocked() from being entered recursively */ |
Craig Mautner | 42d04db | 2014-11-06 12:13:23 -0800 | [diff] [blame] | 391 | boolean inResumeTopActivity; |
| 392 | |
Wale Ogunwale | 3e3e66f | 2015-09-10 15:40:19 -0700 | [diff] [blame] | 393 | // temp. rects used during resize calculation so we don't need to create a new object each time. |
Wale Ogunwale | b34a7ad | 2015-08-14 11:05:30 -0700 | [diff] [blame] | 394 | private final Rect tempRect = new Rect(); |
Wale Ogunwale | 3e3e66f | 2015-09-10 15:40:19 -0700 | [diff] [blame] | 395 | private final Rect tempRect2 = new Rect(); |
Wale Ogunwale | b34a7ad | 2015-08-14 11:05:30 -0700 | [diff] [blame] | 396 | |
Filip Gruszczynski | ebcc875 | 2015-08-25 16:51:05 -0700 | [diff] [blame] | 397 | private final SparseArray<Configuration> mTmpConfigs = new SparseArray<>(); |
| 398 | private final SparseArray<Rect> mTmpBounds = new SparseArray<>(); |
Jorim Jaggi | dc249c4 | 2015-12-15 14:57:31 -0800 | [diff] [blame] | 399 | private final SparseArray<Rect> mTmpInsetBounds = new SparseArray<>(); |
Filip Gruszczynski | ebcc875 | 2015-08-25 16:51:05 -0700 | [diff] [blame] | 400 | |
Filip Gruszczynski | d2f1d94 | 2015-10-14 15:10:12 -0700 | [diff] [blame] | 401 | // The default minimal size that will be used if the activity doesn't specify its minimal size. |
| 402 | // It will be calculated when the default display gets added. |
Wale Ogunwale | 9a08f82 | 2016-02-17 19:03:58 -0800 | [diff] [blame] | 403 | int mDefaultMinimalSizeOfResizeableTask = -1; |
Filip Gruszczynski | d2f1d94 | 2015-10-14 15:10:12 -0700 | [diff] [blame] | 404 | |
Chong Zhang | fdcc4d4 | 2015-10-14 16:50:12 -0700 | [diff] [blame] | 405 | // Whether tasks have moved and we need to rank the tasks before next OOM scoring |
| 406 | private boolean mTaskLayersChanged = true; |
| 407 | |
Filip Gruszczynski | 77d9448 | 2015-12-11 13:59:52 -0800 | [diff] [blame] | 408 | private final ActivityMetricsLogger mActivityMetricsLogger; |
| 409 | |
Jorim Jaggi | dc249c4 | 2015-12-15 14:57:31 -0800 | [diff] [blame] | 410 | private final ResizeDockedStackTimeout mResizeDockedStackTimeout; |
| 411 | |
Wale Ogunwale | 3938197 | 2015-12-17 17:15:29 -0800 | [diff] [blame] | 412 | static class FindTaskResult { |
| 413 | ActivityRecord r; |
| 414 | boolean matchedByRootAffinity; |
| 415 | } |
| 416 | private final FindTaskResult mTmpFindTaskResult = new FindTaskResult(); |
| 417 | |
Craig Mautner | ee36c77 | 2014-07-16 14:56:05 -0700 | [diff] [blame] | 418 | /** |
Jorim Jaggi | a0fdeec | 2016-01-07 14:42:28 +0100 | [diff] [blame] | 419 | * Used to keep track whether app visibilities got changed since the last pause. Useful to |
| 420 | * determine whether to invoke the task stack change listener after pausing. |
| 421 | */ |
| 422 | boolean mAppVisibilitiesChangedSinceLastPause; |
| 423 | |
| 424 | /** |
Craig Mautner | ee36c77 | 2014-07-16 14:56:05 -0700 | [diff] [blame] | 425 | * Description of a request to start a new activity, which has been held |
| 426 | * due to app switches being disabled. |
| 427 | */ |
| 428 | static class PendingActivityLaunch { |
| 429 | final ActivityRecord r; |
| 430 | final ActivityRecord sourceRecord; |
| 431 | final int startFlags; |
| 432 | final ActivityStack stack; |
Robert Carr | 13997f5 | 2015-10-23 13:13:39 -0700 | [diff] [blame] | 433 | final ProcessRecord callerApp; |
Craig Mautner | ee36c77 | 2014-07-16 14:56:05 -0700 | [diff] [blame] | 434 | |
| 435 | PendingActivityLaunch(ActivityRecord _r, ActivityRecord _sourceRecord, |
Robert Carr | 13997f5 | 2015-10-23 13:13:39 -0700 | [diff] [blame] | 436 | int _startFlags, ActivityStack _stack, ProcessRecord _callerApp) { |
Craig Mautner | ee36c77 | 2014-07-16 14:56:05 -0700 | [diff] [blame] | 437 | r = _r; |
| 438 | sourceRecord = _sourceRecord; |
| 439 | startFlags = _startFlags; |
| 440 | stack = _stack; |
Robert Carr | 13997f5 | 2015-10-23 13:13:39 -0700 | [diff] [blame] | 441 | callerApp = _callerApp; |
| 442 | } |
| 443 | |
| 444 | void sendErrorResult(String message) { |
| 445 | try { |
| 446 | if (callerApp.thread != null) { |
| 447 | callerApp.thread.scheduleCrash(message); |
| 448 | } |
| 449 | } catch (RemoteException e) { |
| 450 | Slog.e(TAG, "Exception scheduling crash of failed " |
| 451 | + "activity launcher sourceRecord=" + sourceRecord, e); |
| 452 | } |
Craig Mautner | ee36c77 | 2014-07-16 14:56:05 -0700 | [diff] [blame] | 453 | } |
| 454 | } |
| 455 | |
Suprabh Shukla | 09a88f5 | 2015-12-02 14:36:31 -0800 | [diff] [blame] | 456 | public ActivityStackSupervisor(ActivityManagerService service) { |
Craig Mautner | 2708430 | 2013-03-25 08:05:25 -0700 | [diff] [blame] | 457 | mService = service; |
Jeff Brown | 2c43c33 | 2014-06-12 22:38:59 -0700 | [diff] [blame] | 458 | mHandler = new ActivityStackSupervisorHandler(mService.mHandler.getLooper()); |
Filip Gruszczynski | 77d9448 | 2015-12-11 13:59:52 -0800 | [diff] [blame] | 459 | mActivityMetricsLogger = new ActivityMetricsLogger(this, mService.mContext); |
Jorim Jaggi | dc249c4 | 2015-12-15 14:57:31 -0800 | [diff] [blame] | 460 | mResizeDockedStackTimeout = new ResizeDockedStackTimeout(service, this, mHandler); |
Jeff Brown | 2c43c33 | 2014-06-12 22:38:59 -0700 | [diff] [blame] | 461 | } |
| 462 | |
Suprabh Shukla | 09a88f5 | 2015-12-02 14:36:31 -0800 | [diff] [blame] | 463 | void setRecentTasks(RecentTasks recentTasks) { |
| 464 | mRecentTasks = recentTasks; |
| 465 | } |
| 466 | |
Jeff Brown | 2c43c33 | 2014-06-12 22:38:59 -0700 | [diff] [blame] | 467 | /** |
| 468 | * At the time when the constructor runs, the power manager has not yet been |
| 469 | * initialized. So we initialize our wakelocks afterwards. |
| 470 | */ |
| 471 | void initPowerManagement() { |
Craig Mautner | 4a1cb22 | 2013-12-04 16:14:06 -0800 | [diff] [blame] | 472 | PowerManager pm = (PowerManager)mService.mContext.getSystemService(Context.POWER_SERVICE); |
Craig Mautner | 0eea92c | 2013-05-16 13:35:39 -0700 | [diff] [blame] | 473 | mGoingToSleep = pm.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, "ActivityManager-Sleep"); |
Dianne Hackborn | 3d07c94 | 2015-03-13 18:02:54 -0700 | [diff] [blame] | 474 | mLaunchingActivity = pm.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, "*launch*"); |
Craig Mautner | 7ea5bd4 | 2013-07-05 15:27:08 -0700 | [diff] [blame] | 475 | mLaunchingActivity.setReferenceCounted(false); |
Craig Mautner | 2219a1b | 2013-03-25 09:44:30 -0700 | [diff] [blame] | 476 | } |
| 477 | |
justinzhang | 5286d3f | 2014-05-12 17:06:01 -0400 | [diff] [blame] | 478 | // This function returns a IStatusBarService. The value is from ServiceManager. |
| 479 | // getService and is cached. |
| 480 | private IStatusBarService getStatusBarService() { |
| 481 | synchronized (mService) { |
| 482 | if (mStatusBarService == null) { |
| 483 | mStatusBarService = IStatusBarService.Stub.asInterface( |
| 484 | ServiceManager.checkService(Context.STATUS_BAR_SERVICE)); |
| 485 | if (mStatusBarService == null) { |
| 486 | Slog.w("StatusBarManager", "warning: no STATUS_BAR_SERVICE"); |
| 487 | } |
| 488 | } |
| 489 | return mStatusBarService; |
| 490 | } |
| 491 | } |
| 492 | |
Jason Monk | 35c62a4 | 2014-06-17 10:24:47 -0400 | [diff] [blame] | 493 | private IDevicePolicyManager getDevicePolicyManager() { |
| 494 | synchronized (mService) { |
| 495 | if (mDevicePolicyManager == null) { |
| 496 | mDevicePolicyManager = IDevicePolicyManager.Stub.asInterface( |
| 497 | ServiceManager.checkService(Context.DEVICE_POLICY_SERVICE)); |
| 498 | if (mDevicePolicyManager == null) { |
| 499 | Slog.w(TAG, "warning: no DEVICE_POLICY_SERVICE"); |
| 500 | } |
| 501 | } |
| 502 | return mDevicePolicyManager; |
| 503 | } |
| 504 | } |
| 505 | |
Craig Mautner | ce5f3cb | 2013-04-22 08:58:54 -0700 | [diff] [blame] | 506 | void setWindowManager(WindowManagerService wm) { |
Craig Mautner | 4a1cb22 | 2013-12-04 16:14:06 -0800 | [diff] [blame] | 507 | synchronized (mService) { |
| 508 | mWindowManager = wm; |
| 509 | |
| 510 | mDisplayManager = |
| 511 | (DisplayManager)mService.mContext.getSystemService(Context.DISPLAY_SERVICE); |
| 512 | mDisplayManager.registerDisplayListener(this, null); |
| 513 | |
| 514 | Display[] displays = mDisplayManager.getDisplays(); |
| 515 | for (int displayNdx = displays.length - 1; displayNdx >= 0; --displayNdx) { |
| 516 | final int displayId = displays[displayNdx].getDisplayId(); |
Craig Mautner | e0a3884 | 2013-12-16 16:14:02 -0800 | [diff] [blame] | 517 | ActivityDisplay activityDisplay = new ActivityDisplay(displayId); |
Craig Mautner | 1a70a16 | 2014-09-13 12:09:31 -0700 | [diff] [blame] | 518 | if (activityDisplay.mDisplay == null) { |
| 519 | throw new IllegalStateException("Default Display does not exist"); |
| 520 | } |
Craig Mautner | e0a3884 | 2013-12-16 16:14:02 -0800 | [diff] [blame] | 521 | mActivityDisplays.put(displayId, activityDisplay); |
Filip Gruszczynski | 7be9a8c | 2015-10-15 18:20:30 -0700 | [diff] [blame] | 522 | calculateDefaultMinimalSizeOfResizeableTasks(activityDisplay); |
Craig Mautner | 4a1cb22 | 2013-12-04 16:14:06 -0800 | [diff] [blame] | 523 | } |
| 524 | |
Wale Ogunwale | 4cea0f5 | 2015-12-25 06:30:31 -0800 | [diff] [blame] | 525 | mHomeStack = mFocusedStack = mLastFocusedStack = |
| 526 | getStack(HOME_STACK_ID, CREATE_IF_NEEDED, ON_TOP); |
Jeff Brown | ca9bc70 | 2014-02-11 14:32:56 -0800 | [diff] [blame] | 527 | |
| 528 | mInputManagerInternal = LocalServices.getService(InputManagerInternal.class); |
Craig Mautner | 4a1cb22 | 2013-12-04 16:14:06 -0800 | [diff] [blame] | 529 | } |
Craig Mautner | 2708430 | 2013-03-25 08:05:25 -0700 | [diff] [blame] | 530 | } |
| 531 | |
Jorim Jaggi | 8de4311c | 2014-08-11 22:36:20 +0200 | [diff] [blame] | 532 | void notifyActivityDrawnForKeyguard() { |
Wale Ogunwale | ee006da | 2015-03-30 14:49:25 -0700 | [diff] [blame] | 533 | if (DEBUG_LOCKSCREEN) mService.logLockScreen(""); |
Jorim Jaggi | 8de4311c | 2014-08-11 22:36:20 +0200 | [diff] [blame] | 534 | mWindowManager.notifyActivityDrawnForKeyguard(); |
Craig Mautner | 2708430 | 2013-03-25 08:05:25 -0700 | [diff] [blame] | 535 | } |
| 536 | |
Craig Mautner | ce5f3cb | 2013-04-22 08:58:54 -0700 | [diff] [blame] | 537 | ActivityStack getFocusedStack() { |
Craig Mautner | 4a1cb22 | 2013-12-04 16:14:06 -0800 | [diff] [blame] | 538 | return mFocusedStack; |
Craig Mautner | 20e7227 | 2013-04-01 13:45:53 -0700 | [diff] [blame] | 539 | } |
| 540 | |
Craig Mautner | de4ef02 | 2013-04-07 19:01:33 -0700 | [diff] [blame] | 541 | ActivityStack getLastStack() { |
Craig Mautner | 4a1cb22 | 2013-12-04 16:14:06 -0800 | [diff] [blame] | 542 | return mLastFocusedStack; |
Craig Mautner | 2219a1b | 2013-03-25 09:44:30 -0700 | [diff] [blame] | 543 | } |
| 544 | |
Wale Ogunwale | 1e60e0c | 2015-10-28 13:36:10 -0700 | [diff] [blame] | 545 | boolean isFocusedStack(ActivityStack stack) { |
Wale Ogunwale | 7d70117 | 2015-03-11 15:36:30 -0700 | [diff] [blame] | 546 | if (stack == null) { |
| 547 | return false; |
| 548 | } |
| 549 | |
Craig Mautner | df88d73 | 2014-01-27 09:21:32 -0800 | [diff] [blame] | 550 | final ActivityRecord parent = stack.mActivityContainer.mParentActivity; |
| 551 | if (parent != null) { |
| 552 | stack = parent.task.stack; |
| 553 | } |
Wale Ogunwale | cb82f30 | 2015-02-25 07:53:40 -0800 | [diff] [blame] | 554 | return stack == mFocusedStack; |
Craig Mautner | 20e7227 | 2013-04-01 13:45:53 -0700 | [diff] [blame] | 555 | } |
| 556 | |
Wale Ogunwale | 1e60e0c | 2015-10-28 13:36:10 -0700 | [diff] [blame] | 557 | /** The top most stack. */ |
| 558 | boolean isFrontStack(ActivityStack stack) { |
| 559 | if (stack == null) { |
| 560 | return false; |
Craig Mautner | 4a1cb22 | 2013-12-04 16:14:06 -0800 | [diff] [blame] | 561 | } |
Wale Ogunwale | 92acaf2 | 2015-03-18 14:43:41 -0700 | [diff] [blame] | 562 | |
Wale Ogunwale | 1e60e0c | 2015-10-28 13:36:10 -0700 | [diff] [blame] | 563 | final ActivityRecord parent = stack.mActivityContainer.mParentActivity; |
| 564 | if (parent != null) { |
| 565 | stack = parent.task.stack; |
Wale Ogunwale | cb82f30 | 2015-02-25 07:53:40 -0800 | [diff] [blame] | 566 | } |
Wale Ogunwale | 1e60e0c | 2015-10-28 13:36:10 -0700 | [diff] [blame] | 567 | return stack == mHomeStack.mStacks.get((mHomeStack.mStacks.size() - 1)); |
| 568 | } |
| 569 | |
Wale Ogunwale | d046a01 | 2015-12-24 13:05:59 -0800 | [diff] [blame] | 570 | /** NOTE: Should only be called from {@link ActivityStack#moveToFront} */ |
Wale Ogunwale | 4cea0f5 | 2015-12-25 06:30:31 -0800 | [diff] [blame] | 571 | void setFocusStackUnchecked(String reason, ActivityStack focusCandidate) { |
| 572 | if (!focusCandidate.isFocusable()) { |
| 573 | // The focus candidate isn't focusable. Move focus to the top stack that is focusable. |
| 574 | focusCandidate = focusCandidate.getNextFocusableStackLocked(); |
| 575 | } |
| 576 | |
| 577 | if (focusCandidate != mFocusedStack) { |
Wale Ogunwale | d046a01 | 2015-12-24 13:05:59 -0800 | [diff] [blame] | 578 | mLastFocusedStack = mFocusedStack; |
Wale Ogunwale | 4cea0f5 | 2015-12-25 06:30:31 -0800 | [diff] [blame] | 579 | mFocusedStack = focusCandidate; |
Wale Ogunwale | cb82f30 | 2015-02-25 07:53:40 -0800 | [diff] [blame] | 580 | |
Wale Ogunwale | d046a01 | 2015-12-24 13:05:59 -0800 | [diff] [blame] | 581 | EventLogTags.writeAmFocusedStack( |
| 582 | mCurrentUser, mFocusedStack == null ? -1 : mFocusedStack.getStackId(), |
| 583 | mLastFocusedStack == null ? -1 : mLastFocusedStack.getStackId(), reason); |
| 584 | } |
| 585 | |
| 586 | final ActivityRecord r = topRunningActivityLocked(); |
Chong Zhang | 3aa28b2 | 2016-02-04 16:38:33 -0800 | [diff] [blame] | 587 | if (!mService.mDoingSetFocusedActivity && mService.mFocusedActivity != r) { |
Wale Ogunwale | d046a01 | 2015-12-24 13:05:59 -0800 | [diff] [blame] | 588 | // The focus activity should always be the top activity in the focused stack. |
| 589 | // There will be chaos and anarchy if it isn't... |
| 590 | mService.setFocusedActivityLocked(r, reason + " setFocusStack"); |
| 591 | } |
Craig Mautner | de31375 | 2015-01-22 14:28:03 -0800 | [diff] [blame] | 592 | |
Craig Mautner | f3ea23a | 2015-01-13 09:37:08 -0800 | [diff] [blame] | 593 | if (mService.mBooting || !mService.mBooted) { |
Craig Mautner | f3ea23a | 2015-01-13 09:37:08 -0800 | [diff] [blame] | 594 | if (r != null && r.idle) { |
| 595 | checkFinishBootingLocked(); |
| 596 | } |
| 597 | } |
Craig Mautner | de4ef02 | 2013-04-07 19:01:33 -0700 | [diff] [blame] | 598 | } |
| 599 | |
Wale Ogunwale | 925d0d1 | 2015-09-23 15:40:07 -0700 | [diff] [blame] | 600 | void moveHomeStackToFront(String reason) { |
| 601 | mHomeStack.moveToFront(reason); |
| 602 | } |
| 603 | |
Wale Ogunwale | d80c263 | 2015-03-13 10:26:26 -0700 | [diff] [blame] | 604 | /** Returns true if the focus activity was adjusted to the home stack top activity. */ |
| 605 | boolean moveHomeStackTaskToTop(int homeStackTaskType, String reason) { |
Craig Mautner | 84984fa | 2014-06-19 11:19:20 -0700 | [diff] [blame] | 606 | if (homeStackTaskType == RECENTS_ACTIVITY_TYPE) { |
| 607 | mWindowManager.showRecentApps(); |
Wale Ogunwale | d80c263 | 2015-03-13 10:26:26 -0700 | [diff] [blame] | 608 | return false; |
Craig Mautner | 84984fa | 2014-06-19 11:19:20 -0700 | [diff] [blame] | 609 | } |
Wale Ogunwale | d80c263 | 2015-03-13 10:26:26 -0700 | [diff] [blame] | 610 | |
Craig Mautner | 84984fa | 2014-06-19 11:19:20 -0700 | [diff] [blame] | 611 | mHomeStack.moveHomeStackTaskToTop(homeStackTaskType); |
Wale Ogunwale | d80c263 | 2015-03-13 10:26:26 -0700 | [diff] [blame] | 612 | |
Wale Ogunwale | 2d0f39b | 2015-04-17 15:35:39 -0700 | [diff] [blame] | 613 | final ActivityRecord top = getHomeActivity(); |
Wale Ogunwale | d80c263 | 2015-03-13 10:26:26 -0700 | [diff] [blame] | 614 | if (top == null) { |
| 615 | return false; |
| 616 | } |
| 617 | mService.setFocusedActivityLocked(top, reason); |
| 618 | return true; |
Craig Mautner | 8e56957 | 2013-10-11 17:36:59 -0700 | [diff] [blame] | 619 | } |
| 620 | |
Craig Mautner | 299f960 | 2015-01-26 09:47:33 -0800 | [diff] [blame] | 621 | boolean resumeHomeStackTask(int homeStackTaskType, ActivityRecord prev, String reason) { |
Dianne Hackborn | 7622a0f | 2014-09-30 14:31:42 -0700 | [diff] [blame] | 622 | if (!mService.mBooting && !mService.mBooted) { |
| 623 | // Not ready yet! |
| 624 | return false; |
| 625 | } |
| 626 | |
Craig Mautner | 84984fa | 2014-06-19 11:19:20 -0700 | [diff] [blame] | 627 | if (homeStackTaskType == RECENTS_ACTIVITY_TYPE) { |
| 628 | mWindowManager.showRecentApps(); |
| 629 | return false; |
Craig Mautner | df6523f | 2014-05-20 19:17:54 -0700 | [diff] [blame] | 630 | } |
Wale Ogunwale | d80c263 | 2015-03-13 10:26:26 -0700 | [diff] [blame] | 631 | |
Craig Mautner | 84984fa | 2014-06-19 11:19:20 -0700 | [diff] [blame] | 632 | if (prev != null) { |
| 633 | prev.task.setTaskToReturnTo(APPLICATION_ACTIVITY_TYPE); |
| 634 | } |
| 635 | |
Wale Ogunwale | 2d0f39b | 2015-04-17 15:35:39 -0700 | [diff] [blame] | 636 | mHomeStack.moveHomeStackTaskToTop(homeStackTaskType); |
| 637 | ActivityRecord r = getHomeActivity(); |
Wale Ogunwale | d046a01 | 2015-12-24 13:05:59 -0800 | [diff] [blame] | 638 | final String myReason = reason + " resumeHomeStackTask"; |
| 639 | |
Mark Lu | a56ea12 | 2015-10-08 13:31:01 +0800 | [diff] [blame] | 640 | // Only resume home activity if isn't finishing. |
| 641 | if (r != null && !r.finishing) { |
Wale Ogunwale | d046a01 | 2015-12-24 13:05:59 -0800 | [diff] [blame] | 642 | mService.setFocusedActivityLocked(r, myReason); |
| 643 | return resumeFocusedStackTopActivityLocked(mHomeStack, prev, null); |
Craig Mautner | 69ada55 | 2013-04-18 13:51:51 -0700 | [diff] [blame] | 644 | } |
Wale Ogunwale | d046a01 | 2015-12-24 13:05:59 -0800 | [diff] [blame] | 645 | return mService.startHomeActivityLocked(mCurrentUser, myReason); |
Craig Mautner | 69ada55 | 2013-04-18 13:51:51 -0700 | [diff] [blame] | 646 | } |
| 647 | |
Craig Mautner | 8d341ef | 2013-03-26 09:03:27 -0700 | [diff] [blame] | 648 | TaskRecord anyTaskForIdLocked(int id) { |
Wale Ogunwale | 7e8184b | 2015-10-05 14:37:03 -0700 | [diff] [blame] | 649 | return anyTaskForIdLocked(id, RESTORE_FROM_RECENTS, INVALID_STACK_ID); |
Wale Ogunwale | 04f4d6b | 2015-03-11 09:23:25 -0700 | [diff] [blame] | 650 | } |
| 651 | |
| 652 | /** |
| 653 | * Returns a {@link TaskRecord} for the input id if available. Null otherwise. |
| 654 | * @param id Id of the task we would like returned. |
| 655 | * @param restoreFromRecents If the id was not in the active list, but was found in recents, |
| 656 | * restore the task from recents to the active list. |
Wale Ogunwale | 3797c22 | 2015-10-27 14:21:58 -0700 | [diff] [blame] | 657 | * @param stackId The stack to restore the task to (default launch stack will be used if |
| 658 | * stackId is {@link android.app.ActivityManager.StackId#INVALID_STACK_ID}). |
Wale Ogunwale | 04f4d6b | 2015-03-11 09:23:25 -0700 | [diff] [blame] | 659 | */ |
Wale Ogunwale | 7e8184b | 2015-10-05 14:37:03 -0700 | [diff] [blame] | 660 | TaskRecord anyTaskForIdLocked(int id, boolean restoreFromRecents, int stackId) { |
Craig Mautner | e0a3884 | 2013-12-16 16:14:02 -0800 | [diff] [blame] | 661 | int numDisplays = mActivityDisplays.size(); |
Craig Mautner | 4a1cb22 | 2013-12-04 16:14:06 -0800 | [diff] [blame] | 662 | for (int displayNdx = 0; displayNdx < numDisplays; ++displayNdx) { |
Craig Mautner | e0a3884 | 2013-12-16 16:14:02 -0800 | [diff] [blame] | 663 | ArrayList<ActivityStack> stacks = mActivityDisplays.valueAt(displayNdx).mStacks; |
Craig Mautner | 4a1cb22 | 2013-12-04 16:14:06 -0800 | [diff] [blame] | 664 | for (int stackNdx = stacks.size() - 1; stackNdx >= 0; --stackNdx) { |
| 665 | ActivityStack stack = stacks.get(stackNdx); |
| 666 | TaskRecord task = stack.taskForIdLocked(id); |
| 667 | if (task != null) { |
| 668 | return task; |
| 669 | } |
Craig Mautner | 8d341ef | 2013-03-26 09:03:27 -0700 | [diff] [blame] | 670 | } |
| 671 | } |
Wale Ogunwale | 7de0535 | 2014-12-12 15:21:33 -0800 | [diff] [blame] | 672 | |
| 673 | // Don't give up! Look in recents. |
Wale Ogunwale | ee006da | 2015-03-30 14:49:25 -0700 | [diff] [blame] | 674 | if (DEBUG_RECENTS) Slog.v(TAG_RECENTS, "Looking for task id=" + id + " in recents"); |
Wale Ogunwale | c82f2f5 | 2014-12-09 09:32:50 -0800 | [diff] [blame] | 675 | TaskRecord task = mRecentTasks.taskForIdLocked(id); |
Wale Ogunwale | 7de0535 | 2014-12-12 15:21:33 -0800 | [diff] [blame] | 676 | if (task == null) { |
Wale Ogunwale | ee006da | 2015-03-30 14:49:25 -0700 | [diff] [blame] | 677 | if (DEBUG_RECENTS) Slog.d(TAG_RECENTS, "\tDidn't find task id=" + id + " in recents"); |
Wale Ogunwale | 7de0535 | 2014-12-12 15:21:33 -0800 | [diff] [blame] | 678 | return null; |
| 679 | } |
| 680 | |
Wale Ogunwale | 04f4d6b | 2015-03-11 09:23:25 -0700 | [diff] [blame] | 681 | if (!restoreFromRecents) { |
| 682 | return task; |
| 683 | } |
| 684 | |
Wale Ogunwale | 7e8184b | 2015-10-05 14:37:03 -0700 | [diff] [blame] | 685 | if (!restoreRecentTaskLocked(task, stackId)) { |
Wale Ogunwale | ee006da | 2015-03-30 14:49:25 -0700 | [diff] [blame] | 686 | if (DEBUG_RECENTS) Slog.w(TAG_RECENTS, |
| 687 | "Couldn't restore task id=" + id + " found in recents"); |
Wale Ogunwale | 7de0535 | 2014-12-12 15:21:33 -0800 | [diff] [blame] | 688 | return null; |
| 689 | } |
Wale Ogunwale | ee006da | 2015-03-30 14:49:25 -0700 | [diff] [blame] | 690 | 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] | 691 | return task; |
Craig Mautner | 8d341ef | 2013-03-26 09:03:27 -0700 | [diff] [blame] | 692 | } |
| 693 | |
Craig Mautner | 6170f73 | 2013-04-02 13:05:23 -0700 | [diff] [blame] | 694 | ActivityRecord isInAnyStackLocked(IBinder token) { |
Craig Mautner | e0a3884 | 2013-12-16 16:14:02 -0800 | [diff] [blame] | 695 | int numDisplays = mActivityDisplays.size(); |
Craig Mautner | 4a1cb22 | 2013-12-04 16:14:06 -0800 | [diff] [blame] | 696 | for (int displayNdx = 0; displayNdx < numDisplays; ++displayNdx) { |
Craig Mautner | e0a3884 | 2013-12-16 16:14:02 -0800 | [diff] [blame] | 697 | ArrayList<ActivityStack> stacks = mActivityDisplays.valueAt(displayNdx).mStacks; |
Craig Mautner | 4a1cb22 | 2013-12-04 16:14:06 -0800 | [diff] [blame] | 698 | for (int stackNdx = stacks.size() - 1; stackNdx >= 0; --stackNdx) { |
| 699 | final ActivityRecord r = stacks.get(stackNdx).isInStackLocked(token); |
| 700 | if (r != null) { |
| 701 | return r; |
| 702 | } |
Craig Mautner | 6170f73 | 2013-04-02 13:05:23 -0700 | [diff] [blame] | 703 | } |
| 704 | } |
| 705 | return null; |
| 706 | } |
| 707 | |
Clara Bayarri | f0649ce | 2016-01-14 12:30:42 +0000 | [diff] [blame] | 708 | boolean isFocusedUserLockedProfile() { |
| 709 | final int userId = mFocusedStack.topRunningActivityLocked().userId; |
| 710 | return userId != UserHandle.myUserId() |
| 711 | && mService.mUserController.shouldConfirmCredentials(userId); |
| 712 | } |
| 713 | |
Suprabh Shukla | 09a88f5 | 2015-12-02 14:36:31 -0800 | [diff] [blame] | 714 | void setNextTaskIdForUserLocked(int taskId, int userId) { |
| 715 | final int currentTaskId = mCurTaskIdForUser.get(userId, -1); |
| 716 | if (taskId > currentTaskId) { |
| 717 | mCurTaskIdForUser.put(userId, taskId); |
Craig Mautner | ef73ee1 | 2014-04-23 11:45:37 -0700 | [diff] [blame] | 718 | } |
| 719 | } |
| 720 | |
Suprabh Shukla | 09a88f5 | 2015-12-02 14:36:31 -0800 | [diff] [blame] | 721 | int getNextTaskIdForUserLocked(int userId) { |
Suprabh Shukla | 09a88f5 | 2015-12-02 14:36:31 -0800 | [diff] [blame] | 722 | final int currentTaskId = mCurTaskIdForUser.get(userId, userId * MAX_TASK_IDS_PER_USER); |
| 723 | // for a userId u, a taskId can only be in the range |
| 724 | // [u*MAX_TASK_IDS_PER_USER, (u+1)*MAX_TASK_IDS_PER_USER-1], so if MAX_TASK_IDS_PER_USER |
| 725 | // was 10, user 0 could only have taskIds 0 to 9, user 1: 10 to 19, user 2: 20 to 29, so on. |
| 726 | int candidateTaskId = currentTaskId; |
Suprabh Shukla | 4bccb46 | 2016-02-10 18:45:12 -0800 | [diff] [blame] | 727 | while (mRecentTasks.taskIdTakenForUserLocked(candidateTaskId, userId) |
| 728 | || anyTaskForIdLocked(candidateTaskId, !RESTORE_FROM_RECENTS, |
| 729 | INVALID_STACK_ID) != null) { |
Suprabh Shukla | 09a88f5 | 2015-12-02 14:36:31 -0800 | [diff] [blame] | 730 | candidateTaskId++; |
| 731 | if (candidateTaskId == (userId + 1) * MAX_TASK_IDS_PER_USER) { |
| 732 | // Wrap around as there will be smaller task ids that are available now. |
| 733 | candidateTaskId -= MAX_TASK_IDS_PER_USER; |
Craig Mautner | 8d341ef | 2013-03-26 09:03:27 -0700 | [diff] [blame] | 734 | } |
Suprabh Shukla | 09a88f5 | 2015-12-02 14:36:31 -0800 | [diff] [blame] | 735 | if (candidateTaskId == currentTaskId) { |
| 736 | // Something wrong! |
| 737 | // All MAX_TASK_IDS_PER_USER task ids are taken up by running tasks for this user |
| 738 | throw new IllegalStateException("Cannot get an available task id." |
| 739 | + " Reached limit of " + MAX_TASK_IDS_PER_USER |
| 740 | + " running tasks per user."); |
| 741 | } |
| 742 | } |
| 743 | mCurTaskIdForUser.put(userId, candidateTaskId); |
| 744 | return candidateTaskId; |
Craig Mautner | 8d341ef | 2013-03-26 09:03:27 -0700 | [diff] [blame] | 745 | } |
| 746 | |
Craig Mautner | de4ef02 | 2013-04-07 19:01:33 -0700 | [diff] [blame] | 747 | ActivityRecord resumedAppLocked() { |
Wale Ogunwale | d697cea | 2015-02-20 17:19:49 -0800 | [diff] [blame] | 748 | ActivityStack stack = mFocusedStack; |
Craig Mautner | ce5f3cb | 2013-04-22 08:58:54 -0700 | [diff] [blame] | 749 | if (stack == null) { |
| 750 | return null; |
| 751 | } |
Craig Mautner | de4ef02 | 2013-04-07 19:01:33 -0700 | [diff] [blame] | 752 | ActivityRecord resumedActivity = stack.mResumedActivity; |
| 753 | if (resumedActivity == null || resumedActivity.app == null) { |
| 754 | resumedActivity = stack.mPausingActivity; |
| 755 | if (resumedActivity == null || resumedActivity.app == null) { |
Filip Gruszczynski | 3e85ba2 | 2015-10-05 22:48:30 -0700 | [diff] [blame] | 756 | resumedActivity = stack.topRunningActivityLocked(); |
Craig Mautner | de4ef02 | 2013-04-07 19:01:33 -0700 | [diff] [blame] | 757 | } |
| 758 | } |
| 759 | return resumedActivity; |
| 760 | } |
| 761 | |
Dianne Hackborn | ff07272 | 2014-09-24 10:56:28 -0700 | [diff] [blame] | 762 | boolean attachApplicationLocked(ProcessRecord app) throws RemoteException { |
Craig Mautner | 20e7227 | 2013-04-01 13:45:53 -0700 | [diff] [blame] | 763 | final String processName = app.processName; |
Craig Mautner | 4a1cb22 | 2013-12-04 16:14:06 -0800 | [diff] [blame] | 764 | boolean didSomething = false; |
Craig Mautner | e0a3884 | 2013-12-16 16:14:02 -0800 | [diff] [blame] | 765 | for (int displayNdx = mActivityDisplays.size() - 1; displayNdx >= 0; --displayNdx) { |
| 766 | ArrayList<ActivityStack> stacks = mActivityDisplays.valueAt(displayNdx).mStacks; |
Craig Mautner | 4a1cb22 | 2013-12-04 16:14:06 -0800 | [diff] [blame] | 767 | for (int stackNdx = stacks.size() - 1; stackNdx >= 0; --stackNdx) { |
| 768 | final ActivityStack stack = stacks.get(stackNdx); |
Wale Ogunwale | 1e60e0c | 2015-10-28 13:36:10 -0700 | [diff] [blame] | 769 | if (!isFocusedStack(stack)) { |
Craig Mautner | 4a1cb22 | 2013-12-04 16:14:06 -0800 | [diff] [blame] | 770 | continue; |
| 771 | } |
Filip Gruszczynski | 3e85ba2 | 2015-10-05 22:48:30 -0700 | [diff] [blame] | 772 | ActivityRecord hr = stack.topRunningActivityLocked(); |
Craig Mautner | 4a1cb22 | 2013-12-04 16:14:06 -0800 | [diff] [blame] | 773 | if (hr != null) { |
| 774 | if (hr.app == null && app.uid == hr.info.applicationInfo.uid |
| 775 | && processName.equals(hr.processName)) { |
| 776 | try { |
George Mount | 2c92c97 | 2014-03-20 09:38:23 -0700 | [diff] [blame] | 777 | if (realStartActivityLocked(hr, app, true, true)) { |
Craig Mautner | 4a1cb22 | 2013-12-04 16:14:06 -0800 | [diff] [blame] | 778 | didSomething = true; |
| 779 | } |
Dianne Hackborn | ff07272 | 2014-09-24 10:56:28 -0700 | [diff] [blame] | 780 | } catch (RemoteException e) { |
Craig Mautner | 4a1cb22 | 2013-12-04 16:14:06 -0800 | [diff] [blame] | 781 | Slog.w(TAG, "Exception in new application when starting activity " |
| 782 | + hr.intent.getComponent().flattenToShortString(), e); |
| 783 | throw e; |
Craig Mautner | 20e7227 | 2013-04-01 13:45:53 -0700 | [diff] [blame] | 784 | } |
Craig Mautner | 20e7227 | 2013-04-01 13:45:53 -0700 | [diff] [blame] | 785 | } |
Craig Mautner | 20e7227 | 2013-04-01 13:45:53 -0700 | [diff] [blame] | 786 | } |
| 787 | } |
| 788 | } |
Craig Mautner | b59dcfd | 2013-05-06 13:12:58 -0700 | [diff] [blame] | 789 | if (!didSomething) { |
Filip Gruszczynski | bc5a6c5 | 2015-09-22 13:13:24 -0700 | [diff] [blame] | 790 | ensureActivitiesVisibleLocked(null, 0, !PRESERVE_WINDOWS); |
Craig Mautner | b59dcfd | 2013-05-06 13:12:58 -0700 | [diff] [blame] | 791 | } |
Craig Mautner | 20e7227 | 2013-04-01 13:45:53 -0700 | [diff] [blame] | 792 | return didSomething; |
| 793 | } |
| 794 | |
| 795 | boolean allResumedActivitiesIdle() { |
Craig Mautner | e0a3884 | 2013-12-16 16:14:02 -0800 | [diff] [blame] | 796 | for (int displayNdx = mActivityDisplays.size() - 1; displayNdx >= 0; --displayNdx) { |
| 797 | ArrayList<ActivityStack> stacks = mActivityDisplays.valueAt(displayNdx).mStacks; |
Craig Mautner | 4a1cb22 | 2013-12-04 16:14:06 -0800 | [diff] [blame] | 798 | for (int stackNdx = stacks.size() - 1; stackNdx >= 0; --stackNdx) { |
| 799 | final ActivityStack stack = stacks.get(stackNdx); |
Wale Ogunwale | 1e60e0c | 2015-10-28 13:36:10 -0700 | [diff] [blame] | 800 | if (!isFocusedStack(stack) || stack.numActivities() == 0) { |
Craig Mautner | 4a1cb22 | 2013-12-04 16:14:06 -0800 | [diff] [blame] | 801 | continue; |
| 802 | } |
| 803 | final ActivityRecord resumedActivity = stack.mResumedActivity; |
| 804 | if (resumedActivity == null || !resumedActivity.idle) { |
Wale Ogunwale | 0fc365c | 2015-05-25 19:35:42 -0700 | [diff] [blame] | 805 | if (DEBUG_STATES) Slog.d(TAG_STATES, "allResumedActivitiesIdle: stack=" |
Craig Mautner | 34b73df | 2014-01-12 21:11:08 -0800 | [diff] [blame] | 806 | + stack.mStackId + " " + resumedActivity + " not idle"); |
Craig Mautner | 4a1cb22 | 2013-12-04 16:14:06 -0800 | [diff] [blame] | 807 | return false; |
| 808 | } |
Craig Mautner | 20e7227 | 2013-04-01 13:45:53 -0700 | [diff] [blame] | 809 | } |
| 810 | } |
| 811 | return true; |
| 812 | } |
| 813 | |
Craig Mautner | de4ef02 | 2013-04-07 19:01:33 -0700 | [diff] [blame] | 814 | boolean allResumedActivitiesComplete() { |
Craig Mautner | e0a3884 | 2013-12-16 16:14:02 -0800 | [diff] [blame] | 815 | for (int displayNdx = mActivityDisplays.size() - 1; displayNdx >= 0; --displayNdx) { |
| 816 | ArrayList<ActivityStack> stacks = mActivityDisplays.valueAt(displayNdx).mStacks; |
Craig Mautner | 4a1cb22 | 2013-12-04 16:14:06 -0800 | [diff] [blame] | 817 | for (int stackNdx = stacks.size() - 1; stackNdx >= 0; --stackNdx) { |
| 818 | final ActivityStack stack = stacks.get(stackNdx); |
Wale Ogunwale | 1e60e0c | 2015-10-28 13:36:10 -0700 | [diff] [blame] | 819 | if (isFocusedStack(stack)) { |
Craig Mautner | 4a1cb22 | 2013-12-04 16:14:06 -0800 | [diff] [blame] | 820 | final ActivityRecord r = stack.mResumedActivity; |
Wale Ogunwale | ee006da | 2015-03-30 14:49:25 -0700 | [diff] [blame] | 821 | if (r != null && r.state != RESUMED) { |
Craig Mautner | 4a1cb22 | 2013-12-04 16:14:06 -0800 | [diff] [blame] | 822 | return false; |
| 823 | } |
Craig Mautner | de4ef02 | 2013-04-07 19:01:33 -0700 | [diff] [blame] | 824 | } |
| 825 | } |
| 826 | } |
| 827 | // 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] | 828 | if (DEBUG_STACK) Slog.d(TAG_STACK, |
Craig Mautner | 4a1cb22 | 2013-12-04 16:14:06 -0800 | [diff] [blame] | 829 | "allResumedActivitiesComplete: mLastFocusedStack changing from=" + |
| 830 | mLastFocusedStack + " to=" + mFocusedStack); |
| 831 | mLastFocusedStack = mFocusedStack; |
Craig Mautner | de4ef02 | 2013-04-07 19:01:33 -0700 | [diff] [blame] | 832 | return true; |
| 833 | } |
| 834 | |
| 835 | boolean allResumedActivitiesVisible() { |
riddle_hsu | db46d6b | 2015-04-01 18:58:07 +0800 | [diff] [blame] | 836 | boolean foundResumed = false; |
Craig Mautner | e0a3884 | 2013-12-16 16:14:02 -0800 | [diff] [blame] | 837 | for (int displayNdx = mActivityDisplays.size() - 1; displayNdx >= 0; --displayNdx) { |
| 838 | ArrayList<ActivityStack> stacks = mActivityDisplays.valueAt(displayNdx).mStacks; |
Craig Mautner | 4a1cb22 | 2013-12-04 16:14:06 -0800 | [diff] [blame] | 839 | for (int stackNdx = stacks.size() - 1; stackNdx >= 0; --stackNdx) { |
| 840 | final ActivityStack stack = stacks.get(stackNdx); |
| 841 | final ActivityRecord r = stack.mResumedActivity; |
riddle_hsu | db46d6b | 2015-04-01 18:58:07 +0800 | [diff] [blame] | 842 | if (r != null) { |
Wale Ogunwale | 356c628 | 2015-04-01 12:32:32 -0700 | [diff] [blame] | 843 | if (!r.nowVisible || mWaitingVisibleActivities.contains(r)) { |
riddle_hsu | db46d6b | 2015-04-01 18:58:07 +0800 | [diff] [blame] | 844 | return false; |
| 845 | } |
| 846 | foundResumed = true; |
Craig Mautner | 4a1cb22 | 2013-12-04 16:14:06 -0800 | [diff] [blame] | 847 | } |
Craig Mautner | de4ef02 | 2013-04-07 19:01:33 -0700 | [diff] [blame] | 848 | } |
| 849 | } |
riddle_hsu | db46d6b | 2015-04-01 18:58:07 +0800 | [diff] [blame] | 850 | return foundResumed; |
Craig Mautner | de4ef02 | 2013-04-07 19:01:33 -0700 | [diff] [blame] | 851 | } |
| 852 | |
Craig Mautner | 2acc389 | 2013-09-23 10:28:14 -0700 | [diff] [blame] | 853 | /** |
| 854 | * Pause all activities in either all of the stacks or just the back stacks. |
| 855 | * @param userLeaving Passed to pauseActivity() to indicate whether to call onUserLeaving(). |
Craig Mautner | 2acc389 | 2013-09-23 10:28:14 -0700 | [diff] [blame] | 856 | * @return true if any activity was paused as a result of this call. |
| 857 | */ |
Dianne Hackborn | a4e102e | 2014-09-04 22:52:27 -0700 | [diff] [blame] | 858 | boolean pauseBackStacks(boolean userLeaving, boolean resuming, boolean dontWait) { |
Craig Mautner | cf910b0 | 2013-04-23 11:23:27 -0700 | [diff] [blame] | 859 | boolean someActivityPaused = false; |
Craig Mautner | e0a3884 | 2013-12-16 16:14:02 -0800 | [diff] [blame] | 860 | for (int displayNdx = mActivityDisplays.size() - 1; displayNdx >= 0; --displayNdx) { |
| 861 | ArrayList<ActivityStack> stacks = mActivityDisplays.valueAt(displayNdx).mStacks; |
Craig Mautner | 4a1cb22 | 2013-12-04 16:14:06 -0800 | [diff] [blame] | 862 | for (int stackNdx = stacks.size() - 1; stackNdx >= 0; --stackNdx) { |
| 863 | final ActivityStack stack = stacks.get(stackNdx); |
Wale Ogunwale | 1e60e0c | 2015-10-28 13:36:10 -0700 | [diff] [blame] | 864 | if (!isFocusedStack(stack) && stack.mResumedActivity != null) { |
Wale Ogunwale | 0fc365c | 2015-05-25 19:35:42 -0700 | [diff] [blame] | 865 | if (DEBUG_STATES) Slog.d(TAG_STATES, "pauseBackStacks: stack=" + stack + |
Craig Mautner | 4a1cb22 | 2013-12-04 16:14:06 -0800 | [diff] [blame] | 866 | " mResumedActivity=" + stack.mResumedActivity); |
Dianne Hackborn | a4e102e | 2014-09-04 22:52:27 -0700 | [diff] [blame] | 867 | someActivityPaused |= stack.startPausingLocked(userLeaving, false, resuming, |
| 868 | dontWait); |
Craig Mautner | 4a1cb22 | 2013-12-04 16:14:06 -0800 | [diff] [blame] | 869 | } |
Craig Mautner | cf910b0 | 2013-04-23 11:23:27 -0700 | [diff] [blame] | 870 | } |
| 871 | } |
| 872 | return someActivityPaused; |
| 873 | } |
| 874 | |
Craig Mautner | de4ef02 | 2013-04-07 19:01:33 -0700 | [diff] [blame] | 875 | boolean allPausedActivitiesComplete() { |
Craig Mautner | ac6f843 | 2013-07-17 13:24:59 -0700 | [diff] [blame] | 876 | boolean pausing = true; |
Craig Mautner | e0a3884 | 2013-12-16 16:14:02 -0800 | [diff] [blame] | 877 | for (int displayNdx = mActivityDisplays.size() - 1; displayNdx >= 0; --displayNdx) { |
| 878 | ArrayList<ActivityStack> stacks = mActivityDisplays.valueAt(displayNdx).mStacks; |
Craig Mautner | 4a1cb22 | 2013-12-04 16:14:06 -0800 | [diff] [blame] | 879 | for (int stackNdx = stacks.size() - 1; stackNdx >= 0; --stackNdx) { |
| 880 | final ActivityStack stack = stacks.get(stackNdx); |
| 881 | final ActivityRecord r = stack.mPausingActivity; |
Wale Ogunwale | ee006da | 2015-03-30 14:49:25 -0700 | [diff] [blame] | 882 | if (r != null && r.state != PAUSED && r.state != STOPPED && r.state != STOPPING) { |
Craig Mautner | 4a1cb22 | 2013-12-04 16:14:06 -0800 | [diff] [blame] | 883 | if (DEBUG_STATES) { |
Wale Ogunwale | 0fc365c | 2015-05-25 19:35:42 -0700 | [diff] [blame] | 884 | Slog.d(TAG_STATES, |
| 885 | "allPausedActivitiesComplete: r=" + r + " state=" + r.state); |
Craig Mautner | 4a1cb22 | 2013-12-04 16:14:06 -0800 | [diff] [blame] | 886 | pausing = false; |
| 887 | } else { |
| 888 | return false; |
| 889 | } |
Craig Mautner | ac6f843 | 2013-07-17 13:24:59 -0700 | [diff] [blame] | 890 | } |
Craig Mautner | de4ef02 | 2013-04-07 19:01:33 -0700 | [diff] [blame] | 891 | } |
| 892 | } |
Craig Mautner | ac6f843 | 2013-07-17 13:24:59 -0700 | [diff] [blame] | 893 | return pausing; |
Craig Mautner | de4ef02 | 2013-04-07 19:01:33 -0700 | [diff] [blame] | 894 | } |
| 895 | |
Dianne Hackborn | a4e102e | 2014-09-04 22:52:27 -0700 | [diff] [blame] | 896 | void pauseChildStacks(ActivityRecord parent, boolean userLeaving, boolean uiSleeping, |
| 897 | boolean resuming, boolean dontWait) { |
John Spurlock | 8a985d2 | 2014-02-25 09:40:05 -0500 | [diff] [blame] | 898 | // TODO: Put all stacks in supervisor and iterate through them instead. |
Craig Mautner | df88d73 | 2014-01-27 09:21:32 -0800 | [diff] [blame] | 899 | for (int displayNdx = mActivityDisplays.size() - 1; displayNdx >= 0; --displayNdx) { |
| 900 | ArrayList<ActivityStack> stacks = mActivityDisplays.valueAt(displayNdx).mStacks; |
| 901 | for (int stackNdx = stacks.size() - 1; stackNdx >= 0; --stackNdx) { |
| 902 | final ActivityStack stack = stacks.get(stackNdx); |
| 903 | if (stack.mResumedActivity != null && |
| 904 | stack.mActivityContainer.mParentActivity == parent) { |
Dianne Hackborn | a4e102e | 2014-09-04 22:52:27 -0700 | [diff] [blame] | 905 | stack.startPausingLocked(userLeaving, uiSleeping, resuming, dontWait); |
Craig Mautner | df88d73 | 2014-01-27 09:21:32 -0800 | [diff] [blame] | 906 | } |
| 907 | } |
| 908 | } |
| 909 | } |
| 910 | |
Wale Ogunwale | 2be760d | 2016-02-17 11:16:10 -0800 | [diff] [blame] | 911 | void cancelInitializingActivities() { |
| 912 | for (int displayNdx = mActivityDisplays.size() - 1; displayNdx >= 0; --displayNdx) { |
| 913 | ArrayList<ActivityStack> stacks = mActivityDisplays.valueAt(displayNdx).mStacks; |
| 914 | for (int stackNdx = stacks.size() - 1; stackNdx >= 0; --stackNdx) { |
| 915 | stacks.get(stackNdx).cancelInitializingActivities(); |
| 916 | } |
| 917 | } |
| 918 | } |
| 919 | |
Craig Mautner | ce5f3cb | 2013-04-22 08:58:54 -0700 | [diff] [blame] | 920 | void reportActivityVisibleLocked(ActivityRecord r) { |
Dianne Hackborn | 6cfbb71 | 2014-09-17 12:47:35 -0700 | [diff] [blame] | 921 | sendWaitingVisibleReportLocked(r); |
Dianne Hackborn | 6cfbb71 | 2014-09-17 12:47:35 -0700 | [diff] [blame] | 922 | } |
| 923 | |
| 924 | void sendWaitingVisibleReportLocked(ActivityRecord r) { |
| 925 | boolean changed = false; |
Craig Mautner | 858d8a6 | 2013-04-23 17:08:34 -0700 | [diff] [blame] | 926 | for (int i = mWaitingActivityVisible.size()-1; i >= 0; i--) { |
Craig Mautner | ce5f3cb | 2013-04-22 08:58:54 -0700 | [diff] [blame] | 927 | WaitResult w = mWaitingActivityVisible.get(i); |
Dianne Hackborn | 6cfbb71 | 2014-09-17 12:47:35 -0700 | [diff] [blame] | 928 | if (w.who == null) { |
| 929 | changed = true; |
| 930 | w.timeout = false; |
| 931 | if (r != null) { |
| 932 | w.who = new ComponentName(r.info.packageName, r.info.name); |
| 933 | } |
| 934 | w.totalTime = SystemClock.uptimeMillis() - w.thisTime; |
| 935 | w.thisTime = w.totalTime; |
Craig Mautner | ce5f3cb | 2013-04-22 08:58:54 -0700 | [diff] [blame] | 936 | } |
Craig Mautner | ce5f3cb | 2013-04-22 08:58:54 -0700 | [diff] [blame] | 937 | } |
Dianne Hackborn | 6cfbb71 | 2014-09-17 12:47:35 -0700 | [diff] [blame] | 938 | if (changed) { |
| 939 | mService.notifyAll(); |
| 940 | } |
Craig Mautner | ce5f3cb | 2013-04-22 08:58:54 -0700 | [diff] [blame] | 941 | } |
| 942 | |
| 943 | void reportActivityLaunchedLocked(boolean timeout, ActivityRecord r, |
| 944 | long thisTime, long totalTime) { |
Dianne Hackborn | 6cfbb71 | 2014-09-17 12:47:35 -0700 | [diff] [blame] | 945 | boolean changed = false; |
Craig Mautner | ce5f3cb | 2013-04-22 08:58:54 -0700 | [diff] [blame] | 946 | for (int i = mWaitingActivityLaunched.size() - 1; i >= 0; i--) { |
Craig Mautner | c64f73e | 2013-04-24 16:44:56 -0700 | [diff] [blame] | 947 | WaitResult w = mWaitingActivityLaunched.remove(i); |
Dianne Hackborn | 6cfbb71 | 2014-09-17 12:47:35 -0700 | [diff] [blame] | 948 | if (w.who == null) { |
| 949 | changed = true; |
| 950 | w.timeout = timeout; |
| 951 | if (r != null) { |
| 952 | w.who = new ComponentName(r.info.packageName, r.info.name); |
| 953 | } |
| 954 | w.thisTime = thisTime; |
| 955 | w.totalTime = totalTime; |
Craig Mautner | ce5f3cb | 2013-04-22 08:58:54 -0700 | [diff] [blame] | 956 | } |
Craig Mautner | ce5f3cb | 2013-04-22 08:58:54 -0700 | [diff] [blame] | 957 | } |
Dianne Hackborn | 6cfbb71 | 2014-09-17 12:47:35 -0700 | [diff] [blame] | 958 | if (changed) { |
| 959 | mService.notifyAll(); |
| 960 | } |
Craig Mautner | ce5f3cb | 2013-04-22 08:58:54 -0700 | [diff] [blame] | 961 | } |
| 962 | |
Craig Mautner | 29219d9 | 2013-04-16 20:19:12 -0700 | [diff] [blame] | 963 | ActivityRecord topRunningActivityLocked() { |
Wale Ogunwale | d697cea | 2015-02-20 17:19:49 -0800 | [diff] [blame] | 964 | final ActivityStack focusedStack = mFocusedStack; |
Filip Gruszczynski | 3e85ba2 | 2015-10-05 22:48:30 -0700 | [diff] [blame] | 965 | ActivityRecord r = focusedStack.topRunningActivityLocked(); |
Craig Mautner | 1602ec2 | 2013-05-12 10:24:27 -0700 | [diff] [blame] | 966 | if (r != null) { |
| 967 | return r; |
Craig Mautner | 29219d9 | 2013-04-16 20:19:12 -0700 | [diff] [blame] | 968 | } |
Craig Mautner | 1602ec2 | 2013-05-12 10:24:27 -0700 | [diff] [blame] | 969 | |
Craig Mautner | 4a1cb22 | 2013-12-04 16:14:06 -0800 | [diff] [blame] | 970 | // Return to the home stack. |
Craig Mautner | e0a3884 | 2013-12-16 16:14:02 -0800 | [diff] [blame] | 971 | final ArrayList<ActivityStack> stacks = mHomeStack.mStacks; |
Craig Mautner | 4a1cb22 | 2013-12-04 16:14:06 -0800 | [diff] [blame] | 972 | for (int stackNdx = stacks.size() - 1; stackNdx >= 0; --stackNdx) { |
| 973 | final ActivityStack stack = stacks.get(stackNdx); |
Wale Ogunwale | 4cea0f5 | 2015-12-25 06:30:31 -0800 | [diff] [blame] | 974 | if (stack != focusedStack && isFrontStack(stack) && stack.isFocusable()) { |
Filip Gruszczynski | 3e85ba2 | 2015-10-05 22:48:30 -0700 | [diff] [blame] | 975 | r = stack.topRunningActivityLocked(); |
Craig Mautner | 29219d9 | 2013-04-16 20:19:12 -0700 | [diff] [blame] | 976 | if (r != null) { |
| 977 | return r; |
| 978 | } |
| 979 | } |
| 980 | } |
| 981 | return null; |
| 982 | } |
| 983 | |
Dianne Hackborn | 0923328 | 2014-04-30 11:33:59 -0700 | [diff] [blame] | 984 | void getTasksLocked(int maxNum, List<RunningTaskInfo> list, int callingUid, boolean allowed) { |
Craig Mautner | c0fd805 | 2013-09-19 11:20:17 -0700 | [diff] [blame] | 985 | // Gather all of the running tasks for each stack into runningTaskLists. |
Craig Mautner | 4a1cb22 | 2013-12-04 16:14:06 -0800 | [diff] [blame] | 986 | ArrayList<ArrayList<RunningTaskInfo>> runningTaskLists = |
| 987 | new ArrayList<ArrayList<RunningTaskInfo>>(); |
Craig Mautner | e0a3884 | 2013-12-16 16:14:02 -0800 | [diff] [blame] | 988 | final int numDisplays = mActivityDisplays.size(); |
Craig Mautner | 4a1cb22 | 2013-12-04 16:14:06 -0800 | [diff] [blame] | 989 | for (int displayNdx = 0; displayNdx < numDisplays; ++displayNdx) { |
Craig Mautner | e0a3884 | 2013-12-16 16:14:02 -0800 | [diff] [blame] | 990 | ArrayList<ActivityStack> stacks = mActivityDisplays.valueAt(displayNdx).mStacks; |
Craig Mautner | 4a1cb22 | 2013-12-04 16:14:06 -0800 | [diff] [blame] | 991 | for (int stackNdx = stacks.size() - 1; stackNdx >= 0; --stackNdx) { |
| 992 | final ActivityStack stack = stacks.get(stackNdx); |
Craig Mautner | 15df08a | 2015-04-01 12:17:18 -0700 | [diff] [blame] | 993 | ArrayList<RunningTaskInfo> stackTaskList = new ArrayList<>(); |
Craig Mautner | 4a1cb22 | 2013-12-04 16:14:06 -0800 | [diff] [blame] | 994 | runningTaskLists.add(stackTaskList); |
Dianne Hackborn | 0923328 | 2014-04-30 11:33:59 -0700 | [diff] [blame] | 995 | stack.getTasksLocked(stackTaskList, callingUid, allowed); |
Craig Mautner | 20e7227 | 2013-04-01 13:45:53 -0700 | [diff] [blame] | 996 | } |
| 997 | } |
Craig Mautner | c0fd805 | 2013-09-19 11:20:17 -0700 | [diff] [blame] | 998 | |
| 999 | // The lists are already sorted from most recent to oldest. Just pull the most recent off |
| 1000 | // each list and add it to list. Stop when all lists are empty or maxNum reached. |
| 1001 | while (maxNum > 0) { |
| 1002 | long mostRecentActiveTime = Long.MIN_VALUE; |
| 1003 | ArrayList<RunningTaskInfo> selectedStackList = null; |
Craig Mautner | 4a1cb22 | 2013-12-04 16:14:06 -0800 | [diff] [blame] | 1004 | final int numTaskLists = runningTaskLists.size(); |
| 1005 | for (int stackNdx = 0; stackNdx < numTaskLists; ++stackNdx) { |
| 1006 | ArrayList<RunningTaskInfo> stackTaskList = runningTaskLists.get(stackNdx); |
Craig Mautner | c0fd805 | 2013-09-19 11:20:17 -0700 | [diff] [blame] | 1007 | if (!stackTaskList.isEmpty()) { |
| 1008 | final long lastActiveTime = stackTaskList.get(0).lastActiveTime; |
| 1009 | if (lastActiveTime > mostRecentActiveTime) { |
| 1010 | mostRecentActiveTime = lastActiveTime; |
| 1011 | selectedStackList = stackTaskList; |
| 1012 | } |
| 1013 | } |
| 1014 | } |
| 1015 | if (selectedStackList != null) { |
| 1016 | list.add(selectedStackList.remove(0)); |
| 1017 | --maxNum; |
| 1018 | } else { |
| 1019 | break; |
| 1020 | } |
| 1021 | } |
Craig Mautner | 20e7227 | 2013-04-01 13:45:53 -0700 | [diff] [blame] | 1022 | } |
| 1023 | |
Todd Kennedy | 7440f17 | 2015-12-09 14:31:22 -0800 | [diff] [blame] | 1024 | ActivityInfo resolveActivity(Intent intent, ResolveInfo rInfo, int startFlags, |
| 1025 | ProfilerInfo profilerInfo) { |
| 1026 | final ActivityInfo aInfo = rInfo != null ? rInfo.activityInfo : null; |
Craig Mautner | 23ac33b | 2013-04-01 16:26:35 -0700 | [diff] [blame] | 1027 | if (aInfo != null) { |
| 1028 | // Store the found target back into the intent, because now that |
| 1029 | // we have it we never want to do this again. For example, if the |
| 1030 | // user navigates back to this point in the history, we should |
| 1031 | // always restart the exact same activity. |
| 1032 | intent.setComponent(new ComponentName( |
| 1033 | aInfo.applicationInfo.packageName, aInfo.name)); |
| 1034 | |
| 1035 | // Don't debug things in the system process |
Man Cao | cfa78b2 | 2015-06-11 20:14:34 -0700 | [diff] [blame] | 1036 | if (!aInfo.processName.equals("system")) { |
| 1037 | if ((startFlags & ActivityManager.START_FLAG_DEBUG) != 0) { |
Craig Mautner | 23ac33b | 2013-04-01 16:26:35 -0700 | [diff] [blame] | 1038 | mService.setDebugApp(aInfo.processName, true, false); |
| 1039 | } |
Craig Mautner | 23ac33b | 2013-04-01 16:26:35 -0700 | [diff] [blame] | 1040 | |
Tamas Berghammer | df6cb28 | 2016-01-29 12:07:00 +0000 | [diff] [blame] | 1041 | if ((startFlags & ActivityManager.START_FLAG_NATIVE_DEBUGGING) != 0) { |
| 1042 | mService.setNativeDebuggingAppLocked(aInfo.applicationInfo, aInfo.processName); |
| 1043 | } |
| 1044 | |
Man Cao | cfa78b2 | 2015-06-11 20:14:34 -0700 | [diff] [blame] | 1045 | if ((startFlags & ActivityManager.START_FLAG_TRACK_ALLOCATION) != 0) { |
| 1046 | mService.setTrackAllocationApp(aInfo.applicationInfo, aInfo.processName); |
| 1047 | } |
| 1048 | |
| 1049 | if (profilerInfo != null) { |
Jeff Hao | 1b012d3 | 2014-08-20 10:35:34 -0700 | [diff] [blame] | 1050 | mService.setProfileApp(aInfo.applicationInfo, aInfo.processName, profilerInfo); |
Craig Mautner | 23ac33b | 2013-04-01 16:26:35 -0700 | [diff] [blame] | 1051 | } |
| 1052 | } |
| 1053 | } |
| 1054 | return aInfo; |
| 1055 | } |
| 1056 | |
Todd Kennedy | 7440f17 | 2015-12-09 14:31:22 -0800 | [diff] [blame] | 1057 | ResolveInfo resolveIntent(Intent intent, String resolvedType, int userId) { |
Kenny Guy | b1b3026 | 2016-02-09 16:02:35 +0000 | [diff] [blame] | 1058 | return resolveIntent(intent, resolvedType, userId, 0); |
| 1059 | } |
| 1060 | |
| 1061 | ResolveInfo resolveIntent(Intent intent, String resolvedType, int userId, int flags) { |
Todd Kennedy | 7440f17 | 2015-12-09 14:31:22 -0800 | [diff] [blame] | 1062 | try { |
| 1063 | return AppGlobals.getPackageManager().resolveIntent(intent, resolvedType, |
Kenny Guy | b1b3026 | 2016-02-09 16:02:35 +0000 | [diff] [blame] | 1064 | PackageManager.MATCH_DEFAULT_ONLY | flags |
| 1065 | | ActivityManagerService.STOCK_PM_FLAGS, userId); |
Todd Kennedy | 7440f17 | 2015-12-09 14:31:22 -0800 | [diff] [blame] | 1066 | } catch (RemoteException e) { |
| 1067 | } |
| 1068 | return null; |
| 1069 | } |
| 1070 | |
| 1071 | ActivityInfo resolveActivity(Intent intent, String resolvedType, int startFlags, |
| 1072 | ProfilerInfo profilerInfo, int userId) { |
| 1073 | final ResolveInfo rInfo = resolveIntent(intent, resolvedType, userId); |
| 1074 | return resolveActivity(intent, rInfo, startFlags, profilerInfo); |
| 1075 | } |
| 1076 | |
Wale Ogunwale | 5658e4b | 2016-02-12 12:22:19 -0800 | [diff] [blame] | 1077 | final boolean realStartActivityLocked(ActivityRecord r, ProcessRecord app, |
| 1078 | boolean andResume, boolean checkConfig) throws RemoteException { |
| 1079 | |
| 1080 | if (!allPausedActivitiesComplete()) { |
| 1081 | // While there are activities pausing we skipping starting any new activities until |
| 1082 | // pauses are complete. NOTE: that we also do this for activities that are starting in |
| 1083 | // the paused state because they will first be resumed then paused on the client side. |
| 1084 | if (DEBUG_SWITCH || DEBUG_PAUSE || DEBUG_STATES) Slog.v(TAG_PAUSE, |
| 1085 | "realStartActivityLocked: Skipping start of r=" + r |
| 1086 | + " some activities pausing..."); |
| 1087 | return false; |
| 1088 | } |
Craig Mautner | 2420ead | 2013-04-01 17:13:20 -0700 | [diff] [blame] | 1089 | |
Craig Mautner | 2568c3a | 2015-03-26 14:22:34 -0700 | [diff] [blame] | 1090 | if (andResume) { |
| 1091 | r.startFreezingScreenLocked(app, 0); |
| 1092 | mWindowManager.setAppVisibility(r.appToken, true); |
Craig Mautner | 2420ead | 2013-04-01 17:13:20 -0700 | [diff] [blame] | 1093 | |
Craig Mautner | 2568c3a | 2015-03-26 14:22:34 -0700 | [diff] [blame] | 1094 | // schedule launch ticks to collect information about slow apps. |
| 1095 | r.startLaunchTickingLocked(); |
| 1096 | } |
Craig Mautner | 2420ead | 2013-04-01 17:13:20 -0700 | [diff] [blame] | 1097 | |
| 1098 | // Have the window manager re-evaluate the orientation of |
| 1099 | // the screen based on the new activity order. Note that |
| 1100 | // as a result of this, it can call back into the activity |
| 1101 | // manager with a new orientation. We don't care about that, |
| 1102 | // because the activity is not currently running so we are |
| 1103 | // just restarting it anyway. |
| 1104 | if (checkConfig) { |
Craig Mautner | ce5f3cb | 2013-04-22 08:58:54 -0700 | [diff] [blame] | 1105 | Configuration config = mWindowManager.updateOrientationFromAppTokens( |
Craig Mautner | 2420ead | 2013-04-01 17:13:20 -0700 | [diff] [blame] | 1106 | mService.mConfiguration, |
| 1107 | r.mayFreezeScreenLocked(app) ? r.appToken : null); |
Maxim Bogatov | 0507530 | 2015-05-19 18:33:08 -0700 | [diff] [blame] | 1108 | mService.updateConfigurationLocked(config, r, false); |
Craig Mautner | 2420ead | 2013-04-01 17:13:20 -0700 | [diff] [blame] | 1109 | } |
| 1110 | |
| 1111 | r.app = app; |
| 1112 | app.waitingToKill = null; |
| 1113 | r.launchCount++; |
| 1114 | r.lastLaunchTime = SystemClock.uptimeMillis(); |
| 1115 | |
Wale Ogunwale | e23149f | 2015-03-06 15:39:44 -0800 | [diff] [blame] | 1116 | if (DEBUG_ALL) Slog.v(TAG, "Launching: " + r); |
Craig Mautner | 2420ead | 2013-04-01 17:13:20 -0700 | [diff] [blame] | 1117 | |
| 1118 | int idx = app.activities.indexOf(r); |
| 1119 | if (idx < 0) { |
| 1120 | app.activities.add(r); |
| 1121 | } |
Dianne Hackborn | db92608 | 2013-10-31 16:32:44 -0700 | [diff] [blame] | 1122 | mService.updateLruProcessLocked(app, true, null); |
| 1123 | mService.updateOomAdjLocked(); |
Craig Mautner | 2420ead | 2013-04-01 17:13:20 -0700 | [diff] [blame] | 1124 | |
Craig Mautner | 15df08a | 2015-04-01 12:17:18 -0700 | [diff] [blame] | 1125 | final TaskRecord task = r.task; |
Benjamin Franz | 469dd58 | 2015-06-09 14:24:36 +0100 | [diff] [blame] | 1126 | if (task.mLockTaskAuth == LOCK_TASK_AUTH_LAUNCHABLE || |
| 1127 | task.mLockTaskAuth == LOCK_TASK_AUTH_LAUNCHABLE_PRIV) { |
Craig Mautner | 432f64e | 2015-05-20 14:59:57 -0700 | [diff] [blame] | 1128 | setLockTaskModeLocked(task, LOCK_TASK_MODE_LOCKED, "mLockTaskAuth==LAUNCHABLE", false); |
Craig Mautner | 15df08a | 2015-04-01 12:17:18 -0700 | [diff] [blame] | 1129 | } |
| 1130 | |
| 1131 | final ActivityStack stack = task.stack; |
Craig Mautner | 2420ead | 2013-04-01 17:13:20 -0700 | [diff] [blame] | 1132 | try { |
| 1133 | if (app.thread == null) { |
| 1134 | throw new RemoteException(); |
| 1135 | } |
| 1136 | List<ResultInfo> results = null; |
Dianne Hackborn | 85d558c | 2014-11-04 10:31:54 -0800 | [diff] [blame] | 1137 | List<ReferrerIntent> newIntents = null; |
Craig Mautner | 2420ead | 2013-04-01 17:13:20 -0700 | [diff] [blame] | 1138 | if (andResume) { |
| 1139 | results = r.results; |
| 1140 | newIntents = r.newIntents; |
| 1141 | } |
Wale Ogunwale | ee006da | 2015-03-30 14:49:25 -0700 | [diff] [blame] | 1142 | if (DEBUG_SWITCH) Slog.v(TAG_SWITCH, |
| 1143 | "Launching: " + r + " icicle=" + r.icicle + " with results=" + results |
| 1144 | + " newIntents=" + newIntents + " andResume=" + andResume); |
Craig Mautner | 2420ead | 2013-04-01 17:13:20 -0700 | [diff] [blame] | 1145 | if (andResume) { |
| 1146 | EventLog.writeEvent(EventLogTags.AM_RESTART_ACTIVITY, |
| 1147 | r.userId, System.identityHashCode(r), |
Craig Mautner | 15df08a | 2015-04-01 12:17:18 -0700 | [diff] [blame] | 1148 | task.taskId, r.shortComponentName); |
Craig Mautner | 2420ead | 2013-04-01 17:13:20 -0700 | [diff] [blame] | 1149 | } |
Chong Zhang | 85ee654 | 2015-10-02 13:36:38 -0700 | [diff] [blame] | 1150 | if (r.isHomeActivity()) { |
Craig Mautner | 4ef2693 | 2013-09-18 15:15:52 -0700 | [diff] [blame] | 1151 | // Home process is the root process of the task. |
Craig Mautner | 15df08a | 2015-04-01 12:17:18 -0700 | [diff] [blame] | 1152 | mService.mHomeProcess = task.mActivities.get(0).app; |
Craig Mautner | 2420ead | 2013-04-01 17:13:20 -0700 | [diff] [blame] | 1153 | } |
Nicolas Geoffray | 27c0737 | 2015-11-05 16:54:09 +0000 | [diff] [blame] | 1154 | mService.notifyPackageUse(r.intent.getComponent().getPackageName()); |
Craig Mautner | 2420ead | 2013-04-01 17:13:20 -0700 | [diff] [blame] | 1155 | r.sleeping = false; |
| 1156 | r.forceNewConfig = false; |
| 1157 | mService.showAskCompatModeDialogLocked(r); |
| 1158 | r.compat = mService.compatibilityInfoForPackageLocked(r.info.applicationInfo); |
Craig Mautner | 2568c3a | 2015-03-26 14:22:34 -0700 | [diff] [blame] | 1159 | ProfilerInfo profilerInfo = null; |
Craig Mautner | 2420ead | 2013-04-01 17:13:20 -0700 | [diff] [blame] | 1160 | if (mService.mProfileApp != null && mService.mProfileApp.equals(app.processName)) { |
| 1161 | if (mService.mProfileProc == null || mService.mProfileProc == app) { |
| 1162 | mService.mProfileProc = app; |
Craig Mautner | 2568c3a | 2015-03-26 14:22:34 -0700 | [diff] [blame] | 1163 | final String profileFile = mService.mProfileFile; |
| 1164 | if (profileFile != null) { |
| 1165 | ParcelFileDescriptor profileFd = mService.mProfileFd; |
| 1166 | if (profileFd != null) { |
| 1167 | try { |
| 1168 | profileFd = profileFd.dup(); |
| 1169 | } catch (IOException e) { |
| 1170 | if (profileFd != null) { |
| 1171 | try { |
| 1172 | profileFd.close(); |
| 1173 | } catch (IOException o) { |
| 1174 | } |
| 1175 | profileFd = null; |
| 1176 | } |
| 1177 | } |
Craig Mautner | 2420ead | 2013-04-01 17:13:20 -0700 | [diff] [blame] | 1178 | } |
Craig Mautner | 2568c3a | 2015-03-26 14:22:34 -0700 | [diff] [blame] | 1179 | |
| 1180 | profilerInfo = new ProfilerInfo(profileFile, profileFd, |
| 1181 | mService.mSamplingInterval, mService.mAutoStopProfiler); |
Craig Mautner | 2420ead | 2013-04-01 17:13:20 -0700 | [diff] [blame] | 1182 | } |
| 1183 | } |
| 1184 | } |
Adam Powell | cfbe9be | 2013-11-06 14:58:58 -0800 | [diff] [blame] | 1185 | |
Craig Mautner | 2568c3a | 2015-03-26 14:22:34 -0700 | [diff] [blame] | 1186 | if (andResume) { |
| 1187 | app.hasShownUi = true; |
| 1188 | app.pendingUiClean = true; |
| 1189 | } |
Dianne Hackborn | 4870e9d | 2015-04-08 16:55:47 -0700 | [diff] [blame] | 1190 | app.forceProcessStateUpTo(mService.mTopProcessState); |
Craig Mautner | 2420ead | 2013-04-01 17:13:20 -0700 | [diff] [blame] | 1191 | app.thread.scheduleLaunchActivity(new Intent(r.intent), r.appToken, |
Jeff Hao | 1b012d3 | 2014-08-20 10:35:34 -0700 | [diff] [blame] | 1192 | System.identityHashCode(r), r.info, new Configuration(mService.mConfiguration), |
Wale Ogunwale | e4a0c57 | 2015-06-30 08:40:31 -0700 | [diff] [blame] | 1193 | new Configuration(task.mOverrideConfig), r.compat, r.launchedFromPackage, |
Craig Mautner | 15df08a | 2015-04-01 12:17:18 -0700 | [diff] [blame] | 1194 | task.voiceInteractor, app.repProcState, r.icicle, r.persistentState, results, |
Wale Ogunwale | 60454db | 2015-01-23 16:05:07 -0800 | [diff] [blame] | 1195 | newIntents, !andResume, mService.isNextTransitionForward(), profilerInfo); |
Craig Mautner | 2420ead | 2013-04-01 17:13:20 -0700 | [diff] [blame] | 1196 | |
Alex Klyubin | b9f8a52 | 2015-02-03 11:12:59 -0800 | [diff] [blame] | 1197 | if ((app.info.privateFlags&ApplicationInfo.PRIVATE_FLAG_CANT_SAVE_STATE) != 0) { |
Craig Mautner | 2420ead | 2013-04-01 17:13:20 -0700 | [diff] [blame] | 1198 | // This may be a heavy-weight process! Note that the package |
| 1199 | // manager will ensure that only activity can run in the main |
| 1200 | // process of the .apk, which is the only thing that will be |
| 1201 | // considered heavy-weight. |
| 1202 | if (app.processName.equals(app.info.packageName)) { |
| 1203 | if (mService.mHeavyWeightProcess != null |
| 1204 | && mService.mHeavyWeightProcess != app) { |
| 1205 | Slog.w(TAG, "Starting new heavy weight process " + app |
| 1206 | + " when already running " |
| 1207 | + mService.mHeavyWeightProcess); |
| 1208 | } |
| 1209 | mService.mHeavyWeightProcess = app; |
| 1210 | Message msg = mService.mHandler.obtainMessage( |
| 1211 | ActivityManagerService.POST_HEAVY_NOTIFICATION_MSG); |
| 1212 | msg.obj = r; |
| 1213 | mService.mHandler.sendMessage(msg); |
| 1214 | } |
| 1215 | } |
| 1216 | |
| 1217 | } catch (RemoteException e) { |
| 1218 | if (r.launchFailed) { |
| 1219 | // This is the second time we failed -- finish activity |
| 1220 | // and give up. |
| 1221 | Slog.e(TAG, "Second failure launching " |
| 1222 | + r.intent.getComponent().flattenToShortString() |
| 1223 | + ", giving up", e); |
Craig Mautner | 4a8dddbf | 2014-08-13 10:49:26 -0700 | [diff] [blame] | 1224 | mService.appDiedLocked(app); |
Craig Mautner | 2420ead | 2013-04-01 17:13:20 -0700 | [diff] [blame] | 1225 | stack.requestFinishActivityLocked(r.appToken, Activity.RESULT_CANCELED, null, |
| 1226 | "2nd-crash", false); |
| 1227 | return false; |
| 1228 | } |
| 1229 | |
| 1230 | // This is the first time we failed -- restart process and |
| 1231 | // retry. |
| 1232 | app.activities.remove(r); |
| 1233 | throw e; |
| 1234 | } |
| 1235 | |
| 1236 | r.launchFailed = false; |
| 1237 | if (stack.updateLRUListLocked(r)) { |
Filip Gruszczynski | 49b80af | 2015-09-24 09:04:26 -0700 | [diff] [blame] | 1238 | Slog.w(TAG, "Activity " + r + " being launched, but already in LRU list"); |
Craig Mautner | 2420ead | 2013-04-01 17:13:20 -0700 | [diff] [blame] | 1239 | } |
| 1240 | |
| 1241 | if (andResume) { |
| 1242 | // As part of the process of launching, ActivityThread also performs |
| 1243 | // a resume. |
| 1244 | stack.minimalResumeActivityLocked(r); |
| 1245 | } else { |
Wale Ogunwale | d046a01 | 2015-12-24 13:05:59 -0800 | [diff] [blame] | 1246 | // This activity is not starting in the resumed state... which should look like we asked |
| 1247 | // it to pause+stop (but remain visible), and it has done so and reported back the |
| 1248 | // current icicle and other state. |
Wale Ogunwale | 0fc365c | 2015-05-25 19:35:42 -0700 | [diff] [blame] | 1249 | if (DEBUG_STATES) Slog.v(TAG_STATES, |
Wale Ogunwale | d046a01 | 2015-12-24 13:05:59 -0800 | [diff] [blame] | 1250 | "Moving to PAUSED: " + r + " (starting in paused state)"); |
| 1251 | r.state = PAUSED; |
Craig Mautner | 2420ead | 2013-04-01 17:13:20 -0700 | [diff] [blame] | 1252 | } |
| 1253 | |
| 1254 | // Launch the new version setup screen if needed. We do this -after- |
| 1255 | // launching the initial activity (that is, home), so that it can have |
| 1256 | // a chance to initialize itself while in the background, making the |
| 1257 | // switch back to it faster and look better. |
Wale Ogunwale | 1e60e0c | 2015-10-28 13:36:10 -0700 | [diff] [blame] | 1258 | if (isFocusedStack(stack)) { |
Craig Mautner | 2420ead | 2013-04-01 17:13:20 -0700 | [diff] [blame] | 1259 | mService.startSetupActivityLocked(); |
| 1260 | } |
| 1261 | |
Dianne Hackborn | 465fa39 | 2014-09-14 14:21:18 -0700 | [diff] [blame] | 1262 | // Update any services we are bound to that might care about whether |
| 1263 | // their client may have activities. |
| 1264 | mService.mServices.updateServiceConnectionActivitiesLocked(r.app); |
| 1265 | |
Craig Mautner | 2420ead | 2013-04-01 17:13:20 -0700 | [diff] [blame] | 1266 | return true; |
| 1267 | } |
| 1268 | |
Craig Mautner | e79d4268 | 2013-04-01 19:01:53 -0700 | [diff] [blame] | 1269 | void startSpecificActivityLocked(ActivityRecord r, |
George Mount | 2c92c97 | 2014-03-20 09:38:23 -0700 | [diff] [blame] | 1270 | boolean andResume, boolean checkConfig) { |
Craig Mautner | e79d4268 | 2013-04-01 19:01:53 -0700 | [diff] [blame] | 1271 | // Is this activity's application already running? |
| 1272 | ProcessRecord app = mService.getProcessRecordLocked(r.processName, |
Dianne Hackborn | 3bc8f78d | 2013-09-19 13:34:35 -0700 | [diff] [blame] | 1273 | r.info.applicationInfo.uid, true); |
Craig Mautner | e79d4268 | 2013-04-01 19:01:53 -0700 | [diff] [blame] | 1274 | |
| 1275 | r.task.stack.setLaunchTime(r); |
| 1276 | |
| 1277 | if (app != null && app.thread != null) { |
| 1278 | try { |
Dianne Hackborn | 237cefb | 2013-10-22 18:45:27 -0700 | [diff] [blame] | 1279 | if ((r.info.flags&ActivityInfo.FLAG_MULTIPROCESS) == 0 |
| 1280 | || !"android".equals(r.info.packageName)) { |
| 1281 | // Don't add this if it is a platform component that is marked |
| 1282 | // to run in multiple processes, because this is actually |
| 1283 | // part of the framework so doesn't make sense to track as a |
| 1284 | // separate apk in the process. |
Dianne Hackborn | f7097a5 | 2014-05-13 09:56:14 -0700 | [diff] [blame] | 1285 | app.addPackage(r.info.packageName, r.info.applicationInfo.versionCode, |
| 1286 | mService.mProcessStats); |
Dianne Hackborn | 237cefb | 2013-10-22 18:45:27 -0700 | [diff] [blame] | 1287 | } |
George Mount | 2c92c97 | 2014-03-20 09:38:23 -0700 | [diff] [blame] | 1288 | realStartActivityLocked(r, app, andResume, checkConfig); |
Craig Mautner | e79d4268 | 2013-04-01 19:01:53 -0700 | [diff] [blame] | 1289 | return; |
| 1290 | } catch (RemoteException e) { |
| 1291 | Slog.w(TAG, "Exception when starting activity " |
| 1292 | + r.intent.getComponent().flattenToShortString(), e); |
| 1293 | } |
| 1294 | |
| 1295 | // If a dead object exception was thrown -- fall through to |
| 1296 | // restart the application. |
| 1297 | } |
| 1298 | |
| 1299 | mService.startProcessLocked(r.processName, r.info.applicationInfo, true, 0, |
Dianne Hackborn | 3bc8f78d | 2013-09-19 13:34:35 -0700 | [diff] [blame] | 1300 | "activity", r.intent.getComponent(), false, false, true); |
Craig Mautner | e79d4268 | 2013-04-01 19:01:53 -0700 | [diff] [blame] | 1301 | } |
| 1302 | |
Filip Gruszczynski | 07a0e49 | 2015-12-17 14:16:38 -0800 | [diff] [blame] | 1303 | boolean checkStartAnyActivityPermission(Intent intent, ActivityInfo aInfo, |
Filip Gruszczynski | dc39490 | 2015-12-14 10:20:22 -0800 | [diff] [blame] | 1304 | String resultWho, int requestCode, int callingPid, int callingUid, |
| 1305 | String callingPackage, boolean ignoreTargetSecurity, ProcessRecord callerApp, |
| 1306 | ActivityRecord resultRecord, ActivityStack resultStack) { |
| 1307 | final int startAnyPerm = mService.checkPermission(START_ANY_ACTIVITY, callingPid, |
| 1308 | callingUid); |
| 1309 | if (startAnyPerm == PERMISSION_GRANTED) { |
| 1310 | return true; |
| 1311 | } |
| 1312 | final int componentRestriction = getComponentRestrictionForCallingPackage( |
| 1313 | aInfo, callingPackage, callingPid, callingUid, ignoreTargetSecurity); |
| 1314 | final int actionRestriction = getActionRestrictionForCallingPackage( |
| 1315 | intent.getAction(), callingPackage, callingPid, callingUid); |
| 1316 | if (componentRestriction == ACTIVITY_RESTRICTION_PERMISSION |
| 1317 | || actionRestriction == ACTIVITY_RESTRICTION_PERMISSION) { |
| 1318 | if (resultRecord != null) { |
| 1319 | resultStack.sendActivityResultLocked(-1, |
| 1320 | resultRecord, resultWho, requestCode, |
| 1321 | Activity.RESULT_CANCELED, null); |
| 1322 | } |
| 1323 | final String msg; |
| 1324 | if (actionRestriction == ACTIVITY_RESTRICTION_PERMISSION) { |
| 1325 | msg = "Permission Denial: starting " + intent.toString() |
| 1326 | + " from " + callerApp + " (pid=" + callingPid |
| 1327 | + ", uid=" + callingUid + ")" + " with revoked permission " |
| 1328 | + ACTION_TO_RUNTIME_PERMISSION.get(intent.getAction()); |
| 1329 | } else if (!aInfo.exported) { |
| 1330 | msg = "Permission Denial: starting " + intent.toString() |
| 1331 | + " from " + callerApp + " (pid=" + callingPid |
| 1332 | + ", uid=" + callingUid + ")" |
| 1333 | + " not exported from uid " + aInfo.applicationInfo.uid; |
| 1334 | } else { |
| 1335 | msg = "Permission Denial: starting " + intent.toString() |
| 1336 | + " from " + callerApp + " (pid=" + callingPid |
| 1337 | + ", uid=" + callingUid + ")" |
| 1338 | + " requires " + aInfo.permission; |
| 1339 | } |
| 1340 | Slog.w(TAG, msg); |
| 1341 | throw new SecurityException(msg); |
| 1342 | } |
| 1343 | |
| 1344 | if (actionRestriction == ACTIVITY_RESTRICTION_APPOP) { |
| 1345 | final String message = "Appop Denial: starting " + intent.toString() |
| 1346 | + " from " + callerApp + " (pid=" + callingPid |
| 1347 | + ", uid=" + callingUid + ")" |
| 1348 | + " requires " + AppOpsManager.permissionToOp( |
| 1349 | ACTION_TO_RUNTIME_PERMISSION.get(intent.getAction())); |
| 1350 | Slog.w(TAG, message); |
| 1351 | return false; |
| 1352 | } else if (componentRestriction == ACTIVITY_RESTRICTION_APPOP) { |
| 1353 | final String message = "Appop Denial: starting " + intent.toString() |
| 1354 | + " from " + callerApp + " (pid=" + callingPid |
| 1355 | + ", uid=" + callingUid + ")" |
| 1356 | + " requires appop " + AppOpsManager.permissionToOp(aInfo.permission); |
| 1357 | Slog.w(TAG, message); |
| 1358 | return false; |
| 1359 | } |
| 1360 | return true; |
| 1361 | } |
| 1362 | |
Filip Gruszczynski | 07a0e49 | 2015-12-17 14:16:38 -0800 | [diff] [blame] | 1363 | UserInfo getUserInfo(int userId) { |
Clara Bayarri | f7fea16 | 2015-10-22 16:09:52 +0100 | [diff] [blame] | 1364 | final long identity = Binder.clearCallingIdentity(); |
| 1365 | try { |
| 1366 | return UserManager.get(mService.mContext).getUserInfo(userId); |
| 1367 | } finally { |
| 1368 | Binder.restoreCallingIdentity(identity); |
| 1369 | } |
| 1370 | } |
| 1371 | |
Svet Ganov | 99b6043 | 2015-06-27 13:15:22 -0700 | [diff] [blame] | 1372 | private int getComponentRestrictionForCallingPackage(ActivityInfo activityInfo, |
Dianne Hackborn | a7cfbe0 | 2015-07-16 10:52:52 -0700 | [diff] [blame] | 1373 | String callingPackage, int callingPid, int callingUid, boolean ignoreTargetSecurity) { |
Dianne Hackborn | a7cfbe0 | 2015-07-16 10:52:52 -0700 | [diff] [blame] | 1374 | if (!ignoreTargetSecurity && mService.checkComponentPermission(activityInfo.permission, |
| 1375 | callingPid, callingUid, activityInfo.applicationInfo.uid, activityInfo.exported) |
Svet Ganov | 99b6043 | 2015-06-27 13:15:22 -0700 | [diff] [blame] | 1376 | == PackageManager.PERMISSION_DENIED) { |
| 1377 | return ACTIVITY_RESTRICTION_PERMISSION; |
| 1378 | } |
| 1379 | |
Christopher Tate | ff7add0 | 2015-08-17 10:23:22 -0700 | [diff] [blame] | 1380 | if (activityInfo.permission == null) { |
| 1381 | return ACTIVITY_RESTRICTION_NONE; |
| 1382 | } |
| 1383 | |
Svet Ganov | 99b6043 | 2015-06-27 13:15:22 -0700 | [diff] [blame] | 1384 | final int opCode = AppOpsManager.permissionToOpCode(activityInfo.permission); |
| 1385 | if (opCode == AppOpsManager.OP_NONE) { |
| 1386 | return ACTIVITY_RESTRICTION_NONE; |
| 1387 | } |
| 1388 | |
| 1389 | if (mService.mAppOpsService.noteOperation(opCode, callingUid, |
| 1390 | callingPackage) != AppOpsManager.MODE_ALLOWED) { |
Dianne Hackborn | a7cfbe0 | 2015-07-16 10:52:52 -0700 | [diff] [blame] | 1391 | if (!ignoreTargetSecurity) { |
| 1392 | return ACTIVITY_RESTRICTION_APPOP; |
| 1393 | } |
Svet Ganov | 99b6043 | 2015-06-27 13:15:22 -0700 | [diff] [blame] | 1394 | } |
| 1395 | |
| 1396 | return ACTIVITY_RESTRICTION_NONE; |
| 1397 | } |
| 1398 | |
Svetoslav | 7008b51 | 2015-06-24 18:47:07 -0700 | [diff] [blame] | 1399 | private int getActionRestrictionForCallingPackage(String action, |
| 1400 | String callingPackage, int callingPid, int callingUid) { |
| 1401 | if (action == null) { |
Svet Ganov | 99b6043 | 2015-06-27 13:15:22 -0700 | [diff] [blame] | 1402 | return ACTIVITY_RESTRICTION_NONE; |
Svetoslav | 7008b51 | 2015-06-24 18:47:07 -0700 | [diff] [blame] | 1403 | } |
| 1404 | |
| 1405 | String permission = ACTION_TO_RUNTIME_PERMISSION.get(action); |
| 1406 | if (permission == null) { |
Svet Ganov | 99b6043 | 2015-06-27 13:15:22 -0700 | [diff] [blame] | 1407 | return ACTIVITY_RESTRICTION_NONE; |
Svetoslav | 7008b51 | 2015-06-24 18:47:07 -0700 | [diff] [blame] | 1408 | } |
| 1409 | |
| 1410 | final PackageInfo packageInfo; |
| 1411 | try { |
| 1412 | packageInfo = mService.mContext.getPackageManager() |
| 1413 | .getPackageInfo(callingPackage, PackageManager.GET_PERMISSIONS); |
| 1414 | } catch (PackageManager.NameNotFoundException e) { |
| 1415 | Slog.i(TAG, "Cannot find package info for " + callingPackage); |
Svet Ganov | 99b6043 | 2015-06-27 13:15:22 -0700 | [diff] [blame] | 1416 | return ACTIVITY_RESTRICTION_NONE; |
Svetoslav | 7008b51 | 2015-06-24 18:47:07 -0700 | [diff] [blame] | 1417 | } |
| 1418 | |
| 1419 | if (!ArrayUtils.contains(packageInfo.requestedPermissions, permission)) { |
Svet Ganov | 99b6043 | 2015-06-27 13:15:22 -0700 | [diff] [blame] | 1420 | return ACTIVITY_RESTRICTION_NONE; |
Svetoslav | 7008b51 | 2015-06-24 18:47:07 -0700 | [diff] [blame] | 1421 | } |
| 1422 | |
| 1423 | if (mService.checkPermission(permission, callingPid, callingUid) == |
| 1424 | PackageManager.PERMISSION_DENIED) { |
Svet Ganov | 99b6043 | 2015-06-27 13:15:22 -0700 | [diff] [blame] | 1425 | return ACTIVITY_RESTRICTION_PERMISSION; |
Svetoslav | 7008b51 | 2015-06-24 18:47:07 -0700 | [diff] [blame] | 1426 | } |
| 1427 | |
| 1428 | final int opCode = AppOpsManager.permissionToOpCode(permission); |
| 1429 | if (opCode == AppOpsManager.OP_NONE) { |
Svet Ganov | 99b6043 | 2015-06-27 13:15:22 -0700 | [diff] [blame] | 1430 | return ACTIVITY_RESTRICTION_NONE; |
Svetoslav | 7008b51 | 2015-06-24 18:47:07 -0700 | [diff] [blame] | 1431 | } |
| 1432 | |
| 1433 | if (mService.mAppOpsService.noteOperation(opCode, callingUid, |
| 1434 | callingPackage) != AppOpsManager.MODE_ALLOWED) { |
Svet Ganov | 99b6043 | 2015-06-27 13:15:22 -0700 | [diff] [blame] | 1435 | return ACTIVITY_RESTRICTION_APPOP; |
Svetoslav | 7008b51 | 2015-06-24 18:47:07 -0700 | [diff] [blame] | 1436 | } |
| 1437 | |
Svet Ganov | 99b6043 | 2015-06-27 13:15:22 -0700 | [diff] [blame] | 1438 | return ACTIVITY_RESTRICTION_NONE; |
Svetoslav | 7008b51 | 2015-06-24 18:47:07 -0700 | [diff] [blame] | 1439 | } |
| 1440 | |
Wale Ogunwale | d046a01 | 2015-12-24 13:05:59 -0800 | [diff] [blame] | 1441 | boolean moveActivityStackToFront(ActivityRecord r, String reason) { |
Wale Ogunwale | cb82f30 | 2015-02-25 07:53:40 -0800 | [diff] [blame] | 1442 | if (r == null) { |
| 1443 | // Not sure what you are trying to do, but it is not going to work... |
| 1444 | return false; |
Craig Mautner | 29219d9 | 2013-04-16 20:19:12 -0700 | [diff] [blame] | 1445 | } |
Wale Ogunwale | cb82f30 | 2015-02-25 07:53:40 -0800 | [diff] [blame] | 1446 | final TaskRecord task = r.task; |
| 1447 | if (task == null || task.stack == null) { |
Wale Ogunwale | d046a01 | 2015-12-24 13:05:59 -0800 | [diff] [blame] | 1448 | Slog.w(TAG, "Can't move stack to front for r=" + r + " task=" + task); |
Wale Ogunwale | cb82f30 | 2015-02-25 07:53:40 -0800 | [diff] [blame] | 1449 | return false; |
| 1450 | } |
Wale Ogunwale | eae451e | 2015-08-04 15:20:50 -0700 | [diff] [blame] | 1451 | task.stack.moveToFront(reason, task); |
Wale Ogunwale | cb82f30 | 2015-02-25 07:53:40 -0800 | [diff] [blame] | 1452 | return true; |
Craig Mautner | 29219d9 | 2013-04-16 20:19:12 -0700 | [diff] [blame] | 1453 | } |
| 1454 | |
Dianne Hackborn | 3d07c94 | 2015-03-13 18:02:54 -0700 | [diff] [blame] | 1455 | void setLaunchSource(int uid) { |
| 1456 | mLaunchingActivity.setWorkSource(new WorkSource(uid)); |
| 1457 | } |
| 1458 | |
Craig Mautner | 7ea5bd4 | 2013-07-05 15:27:08 -0700 | [diff] [blame] | 1459 | void acquireLaunchWakelock() { |
| 1460 | if (VALIDATE_WAKE_LOCK_CALLER && Binder.getCallingUid() != Process.myUid()) { |
| 1461 | throw new IllegalStateException("Calling must be system uid"); |
| 1462 | } |
| 1463 | mLaunchingActivity.acquire(); |
| 1464 | if (!mHandler.hasMessages(LAUNCH_TIMEOUT_MSG)) { |
| 1465 | // To be safe, don't allow the wake lock to be held for too long. |
| 1466 | mHandler.sendEmptyMessageDelayed(LAUNCH_TIMEOUT_MSG, LAUNCH_TIMEOUT); |
| 1467 | } |
| 1468 | } |
| 1469 | |
Craig Mautner | f3ea23a | 2015-01-13 09:37:08 -0800 | [diff] [blame] | 1470 | /** |
| 1471 | * Called when the frontmost task is idle. |
| 1472 | * @return the state of mService.mBooting before this was called. |
| 1473 | */ |
| 1474 | private boolean checkFinishBootingLocked() { |
| 1475 | final boolean booting = mService.mBooting; |
| 1476 | boolean enableScreen = false; |
| 1477 | mService.mBooting = false; |
| 1478 | if (!mService.mBooted) { |
| 1479 | mService.mBooted = true; |
| 1480 | enableScreen = true; |
| 1481 | } |
| 1482 | if (booting || enableScreen) { |
| 1483 | mService.postFinishBooting(booting, enableScreen); |
| 1484 | } |
| 1485 | return booting; |
| 1486 | } |
| 1487 | |
Craig Mautner | f333327 | 2013-04-22 10:55:53 -0700 | [diff] [blame] | 1488 | // Checked. |
| 1489 | final ActivityRecord activityIdleInternalLocked(final IBinder token, boolean fromTimeout, |
| 1490 | Configuration config) { |
Wale Ogunwale | e23149f | 2015-03-06 15:39:44 -0800 | [diff] [blame] | 1491 | if (DEBUG_ALL) Slog.v(TAG, "Activity idle: " + token); |
Craig Mautner | f333327 | 2013-04-22 10:55:53 -0700 | [diff] [blame] | 1492 | |
Craig Mautner | f333327 | 2013-04-22 10:55:53 -0700 | [diff] [blame] | 1493 | ArrayList<ActivityRecord> finishes = null; |
Amith Yamasani | 37a40c2 | 2015-06-17 13:25:42 -0700 | [diff] [blame] | 1494 | ArrayList<UserState> startingUsers = null; |
Craig Mautner | f333327 | 2013-04-22 10:55:53 -0700 | [diff] [blame] | 1495 | int NS = 0; |
| 1496 | int NF = 0; |
Craig Mautner | f333327 | 2013-04-22 10:55:53 -0700 | [diff] [blame] | 1497 | boolean booting = false; |
Craig Mautner | f333327 | 2013-04-22 10:55:53 -0700 | [diff] [blame] | 1498 | boolean activityRemoved = false; |
| 1499 | |
Wale Ogunwale | 7d70117 | 2015-03-11 15:36:30 -0700 | [diff] [blame] | 1500 | ActivityRecord r = ActivityRecord.forTokenLocked(token); |
Craig Mautner | f333327 | 2013-04-22 10:55:53 -0700 | [diff] [blame] | 1501 | if (r != null) { |
Wale Ogunwale | 0fc365c | 2015-05-25 19:35:42 -0700 | [diff] [blame] | 1502 | if (DEBUG_IDLE) Slog.d(TAG_IDLE, "activityIdleInternalLocked: Callers=" |
| 1503 | + Debug.getCallers(4)); |
Craig Mautner | f333327 | 2013-04-22 10:55:53 -0700 | [diff] [blame] | 1504 | mHandler.removeMessages(IDLE_TIMEOUT_MSG, r); |
| 1505 | r.finishLaunchTickingLocked(); |
Craig Mautner | 7ea5bd4 | 2013-07-05 15:27:08 -0700 | [diff] [blame] | 1506 | if (fromTimeout) { |
| 1507 | reportActivityLaunchedLocked(fromTimeout, r, -1, -1); |
Craig Mautner | f333327 | 2013-04-22 10:55:53 -0700 | [diff] [blame] | 1508 | } |
Craig Mautner | 7ea5bd4 | 2013-07-05 15:27:08 -0700 | [diff] [blame] | 1509 | |
| 1510 | // This is a hack to semi-deal with a race condition |
| 1511 | // in the client where it can be constructed with a |
| 1512 | // newer configuration from when we asked it to launch. |
| 1513 | // We'll update with whatever configuration it now says |
| 1514 | // it used to launch. |
| 1515 | if (config != null) { |
| 1516 | r.configuration = config; |
| 1517 | } |
| 1518 | |
| 1519 | // We are now idle. If someone is waiting for a thumbnail from |
| 1520 | // us, we can now deliver. |
| 1521 | r.idle = true; |
| 1522 | |
Craig Mautner | 7ea5bd4 | 2013-07-05 15:27:08 -0700 | [diff] [blame] | 1523 | //Slog.i(TAG, "IDLE: mBooted=" + mBooted + ", fromTimeout=" + fromTimeout); |
Wale Ogunwale | 1e60e0c | 2015-10-28 13:36:10 -0700 | [diff] [blame] | 1524 | if (isFocusedStack(r.task.stack) || fromTimeout) { |
Craig Mautner | f3ea23a | 2015-01-13 09:37:08 -0800 | [diff] [blame] | 1525 | booting = checkFinishBootingLocked(); |
Craig Mautner | 7ea5bd4 | 2013-07-05 15:27:08 -0700 | [diff] [blame] | 1526 | } |
| 1527 | } |
| 1528 | |
| 1529 | if (allResumedActivitiesIdle()) { |
| 1530 | if (r != null) { |
| 1531 | mService.scheduleAppGcsLocked(); |
Craig Mautner | 7ea5bd4 | 2013-07-05 15:27:08 -0700 | [diff] [blame] | 1532 | } |
| 1533 | |
| 1534 | if (mLaunchingActivity.isHeld()) { |
| 1535 | mHandler.removeMessages(LAUNCH_TIMEOUT_MSG); |
| 1536 | if (VALIDATE_WAKE_LOCK_CALLER && |
| 1537 | Binder.getCallingUid() != Process.myUid()) { |
| 1538 | throw new IllegalStateException("Calling must be system uid"); |
| 1539 | } |
| 1540 | mLaunchingActivity.release(); |
| 1541 | } |
Filip Gruszczynski | bc5a6c5 | 2015-09-22 13:13:24 -0700 | [diff] [blame] | 1542 | ensureActivitiesVisibleLocked(null, 0, !PRESERVE_WINDOWS); |
Craig Mautner | f333327 | 2013-04-22 10:55:53 -0700 | [diff] [blame] | 1543 | } |
| 1544 | |
| 1545 | // Atomically retrieve all of the other things to do. |
Filip Gruszczynski | 21199bd | 2015-12-02 12:49:58 -0800 | [diff] [blame] | 1546 | final ArrayList<ActivityRecord> stops = processStoppingActivitiesLocked(true); |
Craig Mautner | f333327 | 2013-04-22 10:55:53 -0700 | [diff] [blame] | 1547 | NS = stops != null ? stops.size() : 0; |
Wale Ogunwale | 7d70117 | 2015-03-11 15:36:30 -0700 | [diff] [blame] | 1548 | if ((NF = mFinishingActivities.size()) > 0) { |
| 1549 | finishes = new ArrayList<>(mFinishingActivities); |
Craig Mautner | f333327 | 2013-04-22 10:55:53 -0700 | [diff] [blame] | 1550 | mFinishingActivities.clear(); |
| 1551 | } |
| 1552 | |
Craig Mautner | f333327 | 2013-04-22 10:55:53 -0700 | [diff] [blame] | 1553 | if (mStartingUsers.size() > 0) { |
Wale Ogunwale | 7d70117 | 2015-03-11 15:36:30 -0700 | [diff] [blame] | 1554 | startingUsers = new ArrayList<>(mStartingUsers); |
Craig Mautner | f333327 | 2013-04-22 10:55:53 -0700 | [diff] [blame] | 1555 | mStartingUsers.clear(); |
| 1556 | } |
| 1557 | |
Craig Mautner | f333327 | 2013-04-22 10:55:53 -0700 | [diff] [blame] | 1558 | // Stop any activities that are scheduled to do so but have been |
| 1559 | // waiting for the next one to start. |
| 1560 | for (int i = 0; i < NS; i++) { |
| 1561 | r = stops.get(i); |
| 1562 | final ActivityStack stack = r.task.stack; |
Wale Ogunwale | 7d70117 | 2015-03-11 15:36:30 -0700 | [diff] [blame] | 1563 | if (stack != null) { |
| 1564 | if (r.finishing) { |
| 1565 | stack.finishCurrentActivityLocked(r, ActivityStack.FINISH_IMMEDIATELY, false); |
| 1566 | } else { |
| 1567 | stack.stopActivityLocked(r); |
| 1568 | } |
Craig Mautner | f333327 | 2013-04-22 10:55:53 -0700 | [diff] [blame] | 1569 | } |
| 1570 | } |
| 1571 | |
| 1572 | // Finish any activities that are scheduled to do so but have been |
| 1573 | // waiting for the next one to start. |
| 1574 | for (int i = 0; i < NF; i++) { |
| 1575 | r = finishes.get(i); |
Wale Ogunwale | 7d70117 | 2015-03-11 15:36:30 -0700 | [diff] [blame] | 1576 | final ActivityStack stack = r.task.stack; |
| 1577 | if (stack != null) { |
| 1578 | activityRemoved |= stack.destroyActivityLocked(r, true, "finish-idle"); |
| 1579 | } |
Craig Mautner | f333327 | 2013-04-22 10:55:53 -0700 | [diff] [blame] | 1580 | } |
| 1581 | |
Dianne Hackborn | 7622a0f | 2014-09-30 14:31:42 -0700 | [diff] [blame] | 1582 | if (!booting) { |
Amith Yamasani | 1a7eaaa5 | 2014-05-07 10:22:15 -0700 | [diff] [blame] | 1583 | // Complete user switch |
| 1584 | if (startingUsers != null) { |
| 1585 | for (int i = 0; i < startingUsers.size(); i++) { |
Fyodor Kupolov | 610acda | 2015-10-19 18:44:07 -0700 | [diff] [blame] | 1586 | mService.mUserController.finishUserSwitch(startingUsers.get(i)); |
Amith Yamasani | 1a7eaaa5 | 2014-05-07 10:22:15 -0700 | [diff] [blame] | 1587 | } |
| 1588 | } |
Craig Mautner | f333327 | 2013-04-22 10:55:53 -0700 | [diff] [blame] | 1589 | } |
| 1590 | |
| 1591 | mService.trimApplications(); |
| 1592 | //dump(); |
| 1593 | //mWindowManager.dump(); |
| 1594 | |
Craig Mautner | f333327 | 2013-04-22 10:55:53 -0700 | [diff] [blame] | 1595 | if (activityRemoved) { |
Wale Ogunwale | d046a01 | 2015-12-24 13:05:59 -0800 | [diff] [blame] | 1596 | resumeFocusedStackTopActivityLocked(); |
Craig Mautner | f333327 | 2013-04-22 10:55:53 -0700 | [diff] [blame] | 1597 | } |
| 1598 | |
Craig Mautner | 7ea5bd4 | 2013-07-05 15:27:08 -0700 | [diff] [blame] | 1599 | return r; |
Craig Mautner | f333327 | 2013-04-22 10:55:53 -0700 | [diff] [blame] | 1600 | } |
| 1601 | |
Craig Mautner | 8e56957 | 2013-10-11 17:36:59 -0700 | [diff] [blame] | 1602 | boolean handleAppDiedLocked(ProcessRecord app) { |
Craig Mautner | 1909125 | 2013-10-05 00:03:53 -0700 | [diff] [blame] | 1603 | boolean hasVisibleActivities = false; |
Craig Mautner | e0a3884 | 2013-12-16 16:14:02 -0800 | [diff] [blame] | 1604 | for (int displayNdx = mActivityDisplays.size() - 1; displayNdx >= 0; --displayNdx) { |
| 1605 | final ArrayList<ActivityStack> stacks = mActivityDisplays.valueAt(displayNdx).mStacks; |
Craig Mautner | 4a1cb22 | 2013-12-04 16:14:06 -0800 | [diff] [blame] | 1606 | for (int stackNdx = stacks.size() - 1; stackNdx >= 0; --stackNdx) { |
| 1607 | hasVisibleActivities |= stacks.get(stackNdx).handleAppDiedLocked(app); |
| 1608 | } |
Craig Mautner | 6b74cb5 | 2013-09-27 17:02:21 -0700 | [diff] [blame] | 1609 | } |
Craig Mautner | 1909125 | 2013-10-05 00:03:53 -0700 | [diff] [blame] | 1610 | return hasVisibleActivities; |
Craig Mautner | 8d341ef | 2013-03-26 09:03:27 -0700 | [diff] [blame] | 1611 | } |
| 1612 | |
| 1613 | void closeSystemDialogsLocked() { |
Craig Mautner | e0a3884 | 2013-12-16 16:14:02 -0800 | [diff] [blame] | 1614 | for (int displayNdx = mActivityDisplays.size() - 1; displayNdx >= 0; --displayNdx) { |
| 1615 | final ArrayList<ActivityStack> stacks = mActivityDisplays.valueAt(displayNdx).mStacks; |
Craig Mautner | 4a1cb22 | 2013-12-04 16:14:06 -0800 | [diff] [blame] | 1616 | for (int stackNdx = stacks.size() - 1; stackNdx >= 0; --stackNdx) { |
| 1617 | stacks.get(stackNdx).closeSystemDialogsLocked(); |
| 1618 | } |
Craig Mautner | 8d341ef | 2013-03-26 09:03:27 -0700 | [diff] [blame] | 1619 | } |
| 1620 | } |
| 1621 | |
Craig Mautner | 93529a4 | 2013-10-04 15:03:13 -0700 | [diff] [blame] | 1622 | void removeUserLocked(int userId) { |
Craig Mautner | 4f1df4f | 2013-10-15 15:44:14 -0700 | [diff] [blame] | 1623 | mUserStackInFront.delete(userId); |
Craig Mautner | 93529a4 | 2013-10-04 15:03:13 -0700 | [diff] [blame] | 1624 | } |
| 1625 | |
Craig Mautner | 8d341ef | 2013-03-26 09:03:27 -0700 | [diff] [blame] | 1626 | /** |
Chong Zhang | 45c25ce | 2015-08-10 22:18:26 -0700 | [diff] [blame] | 1627 | * Update the last used stack id for non-current user (current user's last |
| 1628 | * used stack is the focused stack) |
| 1629 | */ |
| 1630 | void updateUserStackLocked(int userId, ActivityStack stack) { |
| 1631 | if (userId != mCurrentUser) { |
| 1632 | mUserStackInFront.put(userId, stack != null ? stack.getStackId() : HOME_STACK_ID); |
| 1633 | } |
| 1634 | } |
| 1635 | |
| 1636 | /** |
Craig Mautner | 8d341ef | 2013-03-26 09:03:27 -0700 | [diff] [blame] | 1637 | * @return true if some activity was finished (or would have finished if doit were true). |
| 1638 | */ |
Wale Ogunwale | 540e123 | 2015-05-01 15:35:39 -0700 | [diff] [blame] | 1639 | boolean finishDisabledPackageActivitiesLocked(String packageName, Set<String> filterByClasses, |
| 1640 | boolean doit, boolean evenPersistent, int userId) { |
Craig Mautner | 8d341ef | 2013-03-26 09:03:27 -0700 | [diff] [blame] | 1641 | boolean didSomething = false; |
Craig Mautner | e0a3884 | 2013-12-16 16:14:02 -0800 | [diff] [blame] | 1642 | for (int displayNdx = mActivityDisplays.size() - 1; displayNdx >= 0; --displayNdx) { |
| 1643 | final ArrayList<ActivityStack> stacks = mActivityDisplays.valueAt(displayNdx).mStacks; |
louis_chang | 8f0555a | 2015-10-27 10:45:53 +0800 | [diff] [blame] | 1644 | for (int stackNdx = stacks.size() - 1; stackNdx >= 0; --stackNdx) { |
Craig Mautner | 4a1cb22 | 2013-12-04 16:14:06 -0800 | [diff] [blame] | 1645 | final ActivityStack stack = stacks.get(stackNdx); |
Wale Ogunwale | 540e123 | 2015-05-01 15:35:39 -0700 | [diff] [blame] | 1646 | if (stack.finishDisabledPackageActivitiesLocked( |
| 1647 | packageName, filterByClasses, doit, evenPersistent, userId)) { |
Craig Mautner | 4a1cb22 | 2013-12-04 16:14:06 -0800 | [diff] [blame] | 1648 | didSomething = true; |
| 1649 | } |
Craig Mautner | 8d341ef | 2013-03-26 09:03:27 -0700 | [diff] [blame] | 1650 | } |
| 1651 | } |
| 1652 | return didSomething; |
| 1653 | } |
| 1654 | |
Dianne Hackborn | a413dc0 | 2013-07-12 12:02:55 -0700 | [diff] [blame] | 1655 | void updatePreviousProcessLocked(ActivityRecord r) { |
| 1656 | // Now that this process has stopped, we may want to consider |
| 1657 | // it to be the previous app to try to keep around in case |
| 1658 | // the user wants to return to it. |
| 1659 | |
| 1660 | // First, found out what is currently the foreground app, so that |
| 1661 | // we don't blow away the previous app if this activity is being |
| 1662 | // hosted by the process that is actually still the foreground. |
| 1663 | ProcessRecord fgApp = null; |
Craig Mautner | e0a3884 | 2013-12-16 16:14:02 -0800 | [diff] [blame] | 1664 | for (int displayNdx = mActivityDisplays.size() - 1; displayNdx >= 0; --displayNdx) { |
| 1665 | final ArrayList<ActivityStack> stacks = mActivityDisplays.valueAt(displayNdx).mStacks; |
Craig Mautner | 4a1cb22 | 2013-12-04 16:14:06 -0800 | [diff] [blame] | 1666 | for (int stackNdx = stacks.size() - 1; stackNdx >= 0; --stackNdx) { |
| 1667 | final ActivityStack stack = stacks.get(stackNdx); |
Wale Ogunwale | 1e60e0c | 2015-10-28 13:36:10 -0700 | [diff] [blame] | 1668 | if (isFocusedStack(stack)) { |
Craig Mautner | 4a1cb22 | 2013-12-04 16:14:06 -0800 | [diff] [blame] | 1669 | if (stack.mResumedActivity != null) { |
| 1670 | fgApp = stack.mResumedActivity.app; |
| 1671 | } else if (stack.mPausingActivity != null) { |
| 1672 | fgApp = stack.mPausingActivity.app; |
| 1673 | } |
| 1674 | break; |
Dianne Hackborn | a413dc0 | 2013-07-12 12:02:55 -0700 | [diff] [blame] | 1675 | } |
Dianne Hackborn | a413dc0 | 2013-07-12 12:02:55 -0700 | [diff] [blame] | 1676 | } |
| 1677 | } |
| 1678 | |
| 1679 | // Now set this one as the previous process, only if that really |
| 1680 | // makes sense to. |
| 1681 | if (r.app != null && fgApp != null && r.app != fgApp |
| 1682 | && r.lastVisibleTime > mService.mPreviousProcessVisibleTime |
Craig Mautner | 4ef2693 | 2013-09-18 15:15:52 -0700 | [diff] [blame] | 1683 | && r.app != mService.mHomeProcess) { |
Dianne Hackborn | a413dc0 | 2013-07-12 12:02:55 -0700 | [diff] [blame] | 1684 | mService.mPreviousProcess = r.app; |
| 1685 | mService.mPreviousProcessVisibleTime = r.lastVisibleTime; |
| 1686 | } |
| 1687 | } |
| 1688 | |
Wale Ogunwale | d046a01 | 2015-12-24 13:05:59 -0800 | [diff] [blame] | 1689 | boolean resumeFocusedStackTopActivityLocked() { |
| 1690 | return resumeFocusedStackTopActivityLocked(null, null, null); |
Craig Mautner | 05d2903 | 2013-05-03 13:40:13 -0700 | [diff] [blame] | 1691 | } |
| 1692 | |
Wale Ogunwale | d046a01 | 2015-12-24 13:05:59 -0800 | [diff] [blame] | 1693 | boolean resumeFocusedStackTopActivityLocked( |
Chong Zhang | 280d332 | 2015-11-03 17:27:26 -0800 | [diff] [blame] | 1694 | ActivityStack targetStack, ActivityRecord target, ActivityOptions targetOptions) { |
Wale Ogunwale | d046a01 | 2015-12-24 13:05:59 -0800 | [diff] [blame] | 1695 | if (targetStack != null && isFocusedStack(targetStack)) { |
| 1696 | return targetStack.resumeTopActivityUncheckedLocked(target, targetOptions); |
Craig Mautner | 05d2903 | 2013-05-03 13:40:13 -0700 | [diff] [blame] | 1697 | } |
Wale Ogunwale | d046a01 | 2015-12-24 13:05:59 -0800 | [diff] [blame] | 1698 | mFocusedStack.resumeTopActivityUncheckedLocked(null, null); |
| 1699 | return false; |
Craig Mautner | 8d341ef | 2013-03-26 09:03:27 -0700 | [diff] [blame] | 1700 | } |
| 1701 | |
Adrian Roos | 20d7df3 | 2016-01-12 18:59:43 +0100 | [diff] [blame] | 1702 | TaskRecord finishTopRunningActivityLocked(ProcessRecord app, String reason) { |
| 1703 | TaskRecord finishedTask = null; |
| 1704 | ActivityStack focusedStack = getFocusedStack(); |
Craig Mautner | e0a3884 | 2013-12-16 16:14:02 -0800 | [diff] [blame] | 1705 | for (int displayNdx = mActivityDisplays.size() - 1; displayNdx >= 0; --displayNdx) { |
| 1706 | final ArrayList<ActivityStack> stacks = mActivityDisplays.valueAt(displayNdx).mStacks; |
Craig Mautner | 4a1cb22 | 2013-12-04 16:14:06 -0800 | [diff] [blame] | 1707 | final int numStacks = stacks.size(); |
| 1708 | for (int stackNdx = 0; stackNdx < numStacks; ++stackNdx) { |
| 1709 | final ActivityStack stack = stacks.get(stackNdx); |
Adrian Roos | 20d7df3 | 2016-01-12 18:59:43 +0100 | [diff] [blame] | 1710 | TaskRecord t = stack.finishTopRunningActivityLocked(app, reason); |
| 1711 | if (stack == focusedStack || finishedTask == null) { |
| 1712 | finishedTask = t; |
| 1713 | } |
Craig Mautner | 4a1cb22 | 2013-12-04 16:14:06 -0800 | [diff] [blame] | 1714 | } |
Craig Mautner | 8d341ef | 2013-03-26 09:03:27 -0700 | [diff] [blame] | 1715 | } |
Adrian Roos | 20d7df3 | 2016-01-12 18:59:43 +0100 | [diff] [blame] | 1716 | return finishedTask; |
Craig Mautner | 8d341ef | 2013-03-26 09:03:27 -0700 | [diff] [blame] | 1717 | } |
| 1718 | |
Dianne Hackborn | 6ea0d0a | 2014-07-02 16:23:21 -0700 | [diff] [blame] | 1719 | void finishVoiceTask(IVoiceInteractionSession session) { |
| 1720 | for (int displayNdx = mActivityDisplays.size() - 1; displayNdx >= 0; --displayNdx) { |
| 1721 | final ArrayList<ActivityStack> stacks = mActivityDisplays.valueAt(displayNdx).mStacks; |
| 1722 | final int numStacks = stacks.size(); |
| 1723 | for (int stackNdx = 0; stackNdx < numStacks; ++stackNdx) { |
| 1724 | final ActivityStack stack = stacks.get(stackNdx); |
| 1725 | stack.finishVoiceTask(session); |
| 1726 | } |
| 1727 | } |
| 1728 | } |
| 1729 | |
Chong Zhang | 280d332 | 2015-11-03 17:27:26 -0800 | [diff] [blame] | 1730 | void findTaskToMoveToFrontLocked( |
| 1731 | TaskRecord task, int flags, ActivityOptions options, String reason) { |
Craig Mautner | aea74a5 | 2014-03-08 14:23:10 -0800 | [diff] [blame] | 1732 | if ((flags & ActivityManager.MOVE_TASK_NO_USER_ACTION) == 0) { |
| 1733 | mUserLeaving = true; |
Craig Mautner | 8d341ef | 2013-03-26 09:03:27 -0700 | [diff] [blame] | 1734 | } |
Craig Mautner | aea74a5 | 2014-03-08 14:23:10 -0800 | [diff] [blame] | 1735 | if ((flags & ActivityManager.MOVE_TASK_WITH_HOME) != 0) { |
| 1736 | // Caller wants the home activity moved with it. To accomplish this, |
| 1737 | // we'll just indicate that this task returns to the home task. |
Craig Mautner | 84984fa | 2014-06-19 11:19:20 -0700 | [diff] [blame] | 1738 | task.setTaskToReturnTo(HOME_ACTIVITY_TYPE); |
Craig Mautner | aea74a5 | 2014-03-08 14:23:10 -0800 | [diff] [blame] | 1739 | } |
Wale Ogunwale | 7d70117 | 2015-03-11 15:36:30 -0700 | [diff] [blame] | 1740 | if (task.stack == null) { |
| 1741 | Slog.e(TAG, "findTaskToMoveToFrontLocked: can't move task=" |
| 1742 | + task + " to front. Stack is null"); |
| 1743 | return; |
| 1744 | } |
Chong Zhang | 0fa656b | 2015-08-31 15:17:21 -0700 | [diff] [blame] | 1745 | |
Wale Ogunwale | b1faf60 | 2016-01-27 09:12:31 -0800 | [diff] [blame] | 1746 | if (task.isResizeable() && options != null) { |
Wale Ogunwale | 854809c | 2015-12-27 16:18:19 -0800 | [diff] [blame] | 1747 | int stackId = options.getLaunchStackId(); |
| 1748 | if (canUseActivityOptionsLaunchBounds(options, stackId)) { |
Filip Gruszczynski | dce2d16 | 2016-01-12 15:40:13 -0800 | [diff] [blame] | 1749 | final Rect bounds = TaskRecord.validateBounds(options.getLaunchBounds()); |
Chong Zhang | 0fa656b | 2015-08-31 15:17:21 -0700 | [diff] [blame] | 1750 | task.updateOverrideConfiguration(bounds); |
Wale Ogunwale | 854809c | 2015-12-27 16:18:19 -0800 | [diff] [blame] | 1751 | if (stackId == INVALID_STACK_ID) { |
| 1752 | stackId = task.getLaunchStackId(); |
| 1753 | } |
Chong Zhang | 112eb8c | 2015-11-02 11:17:00 -0800 | [diff] [blame] | 1754 | if (stackId != task.stack.mStackId) { |
Wale Ogunwale | 513346d | 2016-01-27 10:55:01 -0800 | [diff] [blame] | 1755 | final ActivityStack stack = moveTaskToStackUncheckedLocked( |
| 1756 | task, stackId, ON_TOP, !FORCE_FOCUS, reason); |
| 1757 | stackId = stack.mStackId; |
Chong Zhang | 112eb8c | 2015-11-02 11:17:00 -0800 | [diff] [blame] | 1758 | // moveTaskToStackUncheckedLocked() should already placed the task on top, |
| 1759 | // still need moveTaskToFrontLocked() below for any transition settings. |
| 1760 | } |
Wale Ogunwale | cacfaa2 | 2016-01-15 11:26:08 -0800 | [diff] [blame] | 1761 | if (StackId.resizeStackWithLaunchBounds(stackId)) { |
| 1762 | resizeStackLocked(stackId, bounds, |
| 1763 | null /* tempTaskBounds */, null /* tempTaskInsetBounds */, |
| 1764 | !PRESERVE_WINDOWS, true /* allowResizeInDockedMode */); |
| 1765 | } else { |
| 1766 | // WM resizeTask must be done after the task is moved to the correct stack, |
| 1767 | // because Task's setBounds() also updates dim layer's bounds, but that has |
| 1768 | // dependency on the stack. |
| 1769 | mWindowManager.resizeTask(task.taskId, bounds, task.mOverrideConfig, |
| 1770 | false /* relayout */, false /* forced */); |
| 1771 | } |
Chong Zhang | 0fa656b | 2015-08-31 15:17:21 -0700 | [diff] [blame] | 1772 | } |
| 1773 | } |
| 1774 | |
Chong Zhang | db20b5f | 2015-10-23 14:01:43 -0700 | [diff] [blame] | 1775 | final ActivityRecord r = task.getTopActivity(); |
| 1776 | task.stack.moveTaskToFrontLocked(task, false /* noAnimation */, options, |
| 1777 | r == null ? null : r.appTimeTracker, reason); |
| 1778 | |
Wale Ogunwale | ee006da | 2015-03-30 14:49:25 -0700 | [diff] [blame] | 1779 | if (DEBUG_STACK) Slog.d(TAG_STACK, |
| 1780 | "findTaskToMoveToFront: moved to front of stack=" + task.stack); |
Craig Mautner | 8d341ef | 2013-03-26 09:03:27 -0700 | [diff] [blame] | 1781 | } |
| 1782 | |
Wale Ogunwale | 854809c | 2015-12-27 16:18:19 -0800 | [diff] [blame] | 1783 | boolean canUseActivityOptionsLaunchBounds(ActivityOptions options, int launchStackId) { |
Wale Ogunwale | 7a8fa60 | 2015-11-18 15:56:57 -0800 | [diff] [blame] | 1784 | // 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] | 1785 | // window management or is launching into the pinned stack. |
Wale Ogunwale | 5122df0 | 2016-01-29 22:33:38 -0800 | [diff] [blame] | 1786 | if (options.getLaunchBounds() == null) { |
Wale Ogunwale | 854809c | 2015-12-27 16:18:19 -0800 | [diff] [blame] | 1787 | return false; |
| 1788 | } |
| 1789 | return (mService.mSupportsPictureInPicture && launchStackId == PINNED_STACK_ID) |
| 1790 | || mService.mSupportsFreeformWindowManagement; |
Wale Ogunwale | 7a8fa60 | 2015-11-18 15:56:57 -0800 | [diff] [blame] | 1791 | } |
| 1792 | |
Craig Mautner | 967212c | 2013-04-13 21:10:58 -0700 | [diff] [blame] | 1793 | ActivityStack getStack(int stackId) { |
Wale Ogunwale | 040b470 | 2015-08-06 18:10:50 -0700 | [diff] [blame] | 1794 | return getStack(stackId, !CREATE_IF_NEEDED, !ON_TOP); |
Wale Ogunwale | ddc1cb2 | 2015-07-25 19:23:04 -0700 | [diff] [blame] | 1795 | } |
| 1796 | |
| 1797 | ActivityStack getStack(int stackId, boolean createStaticStackIfNeeded, boolean createOnTop) { |
Craig Mautner | f4c909b | 2014-04-17 18:39:38 -0700 | [diff] [blame] | 1798 | ActivityContainer activityContainer = mActivityContainers.get(stackId); |
| 1799 | if (activityContainer != null) { |
| 1800 | return activityContainer.mStack; |
Craig Mautner | 8d341ef | 2013-03-26 09:03:27 -0700 | [diff] [blame] | 1801 | } |
Wale Ogunwale | 3797c22 | 2015-10-27 14:21:58 -0700 | [diff] [blame] | 1802 | if (!createStaticStackIfNeeded || !StackId.isStaticStack(stackId)) { |
Wale Ogunwale | ddc1cb2 | 2015-07-25 19:23:04 -0700 | [diff] [blame] | 1803 | return null; |
| 1804 | } |
| 1805 | return createStackOnDisplay(stackId, Display.DEFAULT_DISPLAY, createOnTop); |
Craig Mautner | 8d341ef | 2013-03-26 09:03:27 -0700 | [diff] [blame] | 1806 | } |
| 1807 | |
Craig Mautner | 967212c | 2013-04-13 21:10:58 -0700 | [diff] [blame] | 1808 | ArrayList<ActivityStack> getStacks() { |
Wale Ogunwale | 3797c22 | 2015-10-27 14:21:58 -0700 | [diff] [blame] | 1809 | ArrayList<ActivityStack> allStacks = new ArrayList<>(); |
Craig Mautner | e0a3884 | 2013-12-16 16:14:02 -0800 | [diff] [blame] | 1810 | for (int displayNdx = mActivityDisplays.size() - 1; displayNdx >= 0; --displayNdx) { |
| 1811 | allStacks.addAll(mActivityDisplays.valueAt(displayNdx).mStacks); |
Craig Mautner | 4a1cb22 | 2013-12-04 16:14:06 -0800 | [diff] [blame] | 1812 | } |
| 1813 | return allStacks; |
Craig Mautner | 967212c | 2013-04-13 21:10:58 -0700 | [diff] [blame] | 1814 | } |
| 1815 | |
Craig Mautner | 4a1cb22 | 2013-12-04 16:14:06 -0800 | [diff] [blame] | 1816 | IBinder getHomeActivityToken() { |
Craig Mautner | ee2e45a | 2014-06-27 12:10:03 -0700 | [diff] [blame] | 1817 | ActivityRecord homeActivity = getHomeActivity(); |
| 1818 | if (homeActivity != null) { |
| 1819 | return homeActivity.appToken; |
| 1820 | } |
| 1821 | return null; |
| 1822 | } |
| 1823 | |
| 1824 | ActivityRecord getHomeActivity() { |
Craig Mautner | db49fec | 2015-05-21 15:33:30 -0700 | [diff] [blame] | 1825 | return getHomeActivityForUser(mCurrentUser); |
Fyodor Kupolov | b501330 | 2015-04-17 17:59:14 -0700 | [diff] [blame] | 1826 | } |
| 1827 | |
| 1828 | ActivityRecord getHomeActivityForUser(int userId) { |
Craig Mautner | 4a1cb22 | 2013-12-04 16:14:06 -0800 | [diff] [blame] | 1829 | final ArrayList<TaskRecord> tasks = mHomeStack.getAllTasks(); |
| 1830 | for (int taskNdx = tasks.size() - 1; taskNdx >= 0; --taskNdx) { |
| 1831 | final TaskRecord task = tasks.get(taskNdx); |
| 1832 | if (task.isHomeTask()) { |
| 1833 | final ArrayList<ActivityRecord> activities = task.mActivities; |
| 1834 | for (int activityNdx = activities.size() - 1; activityNdx >= 0; --activityNdx) { |
| 1835 | final ActivityRecord r = activities.get(activityNdx); |
Fyodor Kupolov | b501330 | 2015-04-17 17:59:14 -0700 | [diff] [blame] | 1836 | if (r.isHomeActivity() |
| 1837 | && ((userId == UserHandle.USER_ALL) || (r.userId == userId))) { |
Craig Mautner | ee2e45a | 2014-06-27 12:10:03 -0700 | [diff] [blame] | 1838 | return r; |
Craig Mautner | 4a1cb22 | 2013-12-04 16:14:06 -0800 | [diff] [blame] | 1839 | } |
| 1840 | } |
| 1841 | } |
| 1842 | } |
| 1843 | return null; |
| 1844 | } |
| 1845 | |
Chong Zhang | b15758a | 2015-11-17 12:12:03 -0800 | [diff] [blame] | 1846 | /** |
| 1847 | * Returns if a stack should be treated as if it's docked. Returns true if the stack is |
| 1848 | * the docked stack itself, or if it's side-by-side to the docked stack. |
| 1849 | */ |
| 1850 | boolean isStackDockedInEffect(int stackId) { |
| 1851 | return stackId == DOCKED_STACK_ID || |
| 1852 | (StackId.isResizeableByDockedStack(stackId) && getStack(DOCKED_STACK_ID) != null); |
| 1853 | } |
| 1854 | |
Todd Kennedy | ca4d842 | 2015-01-15 15:19:22 -0800 | [diff] [blame] | 1855 | ActivityContainer createVirtualActivityContainer(ActivityRecord parentActivity, |
Craig Mautner | 4a1cb22 | 2013-12-04 16:14:06 -0800 | [diff] [blame] | 1856 | IActivityContainerCallback callback) { |
Craig Mautner | d163e75 | 2014-06-13 17:18:47 -0700 | [diff] [blame] | 1857 | ActivityContainer activityContainer = |
| 1858 | new VirtualActivityContainer(parentActivity, callback); |
Craig Mautner | f4c909b | 2014-04-17 18:39:38 -0700 | [diff] [blame] | 1859 | mActivityContainers.put(activityContainer.mStackId, activityContainer); |
Wale Ogunwale | 0fc365c | 2015-05-25 19:35:42 -0700 | [diff] [blame] | 1860 | if (DEBUG_CONTAINERS) Slog.d(TAG_CONTAINERS, |
| 1861 | "createActivityContainer: " + activityContainer); |
Craig Mautner | f4c909b | 2014-04-17 18:39:38 -0700 | [diff] [blame] | 1862 | parentActivity.mChildContainers.add(activityContainer); |
Craig Mautner | 4a1cb22 | 2013-12-04 16:14:06 -0800 | [diff] [blame] | 1863 | return activityContainer; |
| 1864 | } |
| 1865 | |
Craig Mautner | 34b73df | 2014-01-12 21:11:08 -0800 | [diff] [blame] | 1866 | void removeChildActivityContainers(ActivityRecord parentActivity) { |
Craig Mautner | f4c909b | 2014-04-17 18:39:38 -0700 | [diff] [blame] | 1867 | final ArrayList<ActivityContainer> childStacks = parentActivity.mChildContainers; |
| 1868 | for (int containerNdx = childStacks.size() - 1; containerNdx >= 0; --containerNdx) { |
| 1869 | ActivityContainer container = childStacks.remove(containerNdx); |
Wale Ogunwale | 0fc365c | 2015-05-25 19:35:42 -0700 | [diff] [blame] | 1870 | if (DEBUG_CONTAINERS) Slog.d(TAG_CONTAINERS, "removeChildActivityContainers: removing " |
| 1871 | + container); |
Craig Mautner | f4c909b | 2014-04-17 18:39:38 -0700 | [diff] [blame] | 1872 | container.release(); |
Craig Mautner | 34b73df | 2014-01-12 21:11:08 -0800 | [diff] [blame] | 1873 | } |
| 1874 | } |
| 1875 | |
Craig Mautner | 95da108 | 2014-02-24 17:54:35 -0800 | [diff] [blame] | 1876 | void deleteActivityContainer(IActivityContainer container) { |
| 1877 | ActivityContainer activityContainer = (ActivityContainer)container; |
| 1878 | if (activityContainer != null) { |
Wale Ogunwale | 0fc365c | 2015-05-25 19:35:42 -0700 | [diff] [blame] | 1879 | if (DEBUG_CONTAINERS) Slog.d(TAG_CONTAINERS, |
| 1880 | "deleteActivityContainer: callers=" + Debug.getCallers(4)); |
Craig Mautner | 95da108 | 2014-02-24 17:54:35 -0800 | [diff] [blame] | 1881 | final int stackId = activityContainer.mStackId; |
| 1882 | mActivityContainers.remove(stackId); |
| 1883 | mWindowManager.removeStack(stackId); |
| 1884 | } |
| 1885 | } |
| 1886 | |
Jorim Jaggi | dc249c4 | 2015-12-15 14:57:31 -0800 | [diff] [blame] | 1887 | void resizeStackLocked(int stackId, Rect bounds, Rect tempTaskBounds, Rect tempTaskInsetBounds, |
| 1888 | boolean preserveWindows, boolean allowResizeInDockedMode) { |
| 1889 | if (stackId == DOCKED_STACK_ID) { |
| 1890 | resizeDockedStackLocked(bounds, tempTaskBounds, tempTaskInsetBounds, null, null, |
| 1891 | preserveWindows); |
| 1892 | return; |
| 1893 | } |
Wale Ogunwale | 60454db | 2015-01-23 16:05:07 -0800 | [diff] [blame] | 1894 | final ActivityStack stack = getStack(stackId); |
| 1895 | if (stack == null) { |
| 1896 | Slog.w(TAG, "resizeStack: stackId " + stackId + " not found."); |
| 1897 | return; |
| 1898 | } |
Wale Ogunwale | 9d3de4c | 2015-02-01 16:49:44 -0800 | [diff] [blame] | 1899 | |
Jorim Jaggi | dc249c4 | 2015-12-15 14:57:31 -0800 | [diff] [blame] | 1900 | if (!allowResizeInDockedMode && getStack(DOCKED_STACK_ID) != null) { |
Wale Ogunwale | ffc11bb | 2015-10-10 13:05:45 -0700 | [diff] [blame] | 1901 | // If the docked stack exist we don't allow resizes of stacks not caused by the docked |
| 1902 | // stack size changing so things don't get out of sync. |
| 1903 | return; |
| 1904 | } |
| 1905 | |
Wale Ogunwale | cad05a0 | 2015-09-25 10:41:44 -0700 | [diff] [blame] | 1906 | Trace.traceBegin(TRACE_TAG_ACTIVITY_MANAGER, "am.resizeStack_" + stackId); |
Jorim Jaggi | c402520 | 2015-10-22 16:43:34 +0200 | [diff] [blame] | 1907 | mWindowManager.deferSurfaceLayout(); |
| 1908 | try { |
Jorim Jaggi | dc249c4 | 2015-12-15 14:57:31 -0800 | [diff] [blame] | 1909 | resizeStackUncheckedLocked(stack, bounds, tempTaskBounds, tempTaskInsetBounds); |
| 1910 | ensureConfigurationAndResume(stack, stack.topRunningActivityLocked(), preserveWindows); |
Jorim Jaggi | c402520 | 2015-10-22 16:43:34 +0200 | [diff] [blame] | 1911 | } finally { |
| 1912 | mWindowManager.continueSurfaceLayout(); |
| 1913 | Trace.traceEnd(TRACE_TAG_ACTIVITY_MANAGER); |
Wale Ogunwale | e4a0c57 | 2015-06-30 08:40:31 -0700 | [diff] [blame] | 1914 | } |
| 1915 | } |
| 1916 | |
Jorim Jaggi | dc249c4 | 2015-12-15 14:57:31 -0800 | [diff] [blame] | 1917 | private void resizeStackUncheckedLocked(ActivityStack stack, Rect bounds, Rect tempTaskBounds, |
| 1918 | Rect tempTaskInsetBounds) { |
Filip Gruszczynski | dce2d16 | 2016-01-12 15:40:13 -0800 | [diff] [blame] | 1919 | bounds = TaskRecord.validateBounds(bounds); |
Jorim Jaggi | dc249c4 | 2015-12-15 14:57:31 -0800 | [diff] [blame] | 1920 | |
| 1921 | mTmpBounds.clear(); |
| 1922 | mTmpConfigs.clear(); |
| 1923 | mTmpInsetBounds.clear(); |
Wale Ogunwale | b1faf60 | 2016-01-27 09:12:31 -0800 | [diff] [blame] | 1924 | final ArrayList<TaskRecord> tasks = stack.getAllTasks(); |
Jorim Jaggi | dc249c4 | 2015-12-15 14:57:31 -0800 | [diff] [blame] | 1925 | for (int i = tasks.size() - 1; i >= 0; i--) { |
Wale Ogunwale | b1faf60 | 2016-01-27 09:12:31 -0800 | [diff] [blame] | 1926 | final TaskRecord task = tasks.get(i); |
| 1927 | if (task.isResizeable()) { |
Jorim Jaggi | dc249c4 | 2015-12-15 14:57:31 -0800 | [diff] [blame] | 1928 | if (stack.mStackId == FREEFORM_WORKSPACE_STACK_ID) { |
| 1929 | // For freeform stack we don't adjust the size of the tasks to match that |
| 1930 | // of the stack, but we do try to make sure the tasks are still contained |
| 1931 | // with the bounds of the stack. |
| 1932 | tempRect2.set(task.mBounds); |
| 1933 | fitWithinBounds(tempRect2, bounds); |
| 1934 | task.updateOverrideConfiguration(tempRect2); |
| 1935 | } else { |
Filip Gruszczynski | dce2d16 | 2016-01-12 15:40:13 -0800 | [diff] [blame] | 1936 | task.updateOverrideConfiguration( |
Jorim Jaggi | 0a93214 | 2016-02-01 17:42:25 -0800 | [diff] [blame] | 1937 | tempTaskBounds != null ? tempTaskBounds : bounds, |
| 1938 | tempTaskInsetBounds != null ? tempTaskInsetBounds : bounds); |
Jorim Jaggi | dc249c4 | 2015-12-15 14:57:31 -0800 | [diff] [blame] | 1939 | } |
| 1940 | } |
| 1941 | |
| 1942 | mTmpConfigs.put(task.taskId, task.mOverrideConfig); |
| 1943 | mTmpBounds.put(task.taskId, task.mBounds); |
| 1944 | if (tempTaskInsetBounds != null) { |
| 1945 | mTmpInsetBounds.put(task.taskId, tempTaskInsetBounds); |
| 1946 | } |
| 1947 | } |
Jorim Jaggi | 0429f35 | 2015-12-22 16:29:16 +0100 | [diff] [blame] | 1948 | |
| 1949 | // We might trigger a configuration change. Save the current task bounds for freezing. |
| 1950 | mWindowManager.prepareFreezingTaskBounds(stack.mStackId); |
Jorim Jaggi | dc249c4 | 2015-12-15 14:57:31 -0800 | [diff] [blame] | 1951 | stack.mFullscreen = mWindowManager.resizeStack(stack.mStackId, bounds, mTmpConfigs, |
| 1952 | mTmpBounds, mTmpInsetBounds); |
| 1953 | stack.setBounds(bounds); |
| 1954 | } |
| 1955 | |
| 1956 | private void ensureConfigurationAndResume(ActivityStack stack, ActivityRecord r, |
| 1957 | boolean preserveWindows) { |
Jorim Jaggi | c3fb314 | 2016-02-04 19:49:28 -0800 | [diff] [blame] | 1958 | if (r == null || !r.visible) { |
Jorim Jaggi | dc249c4 | 2015-12-15 14:57:31 -0800 | [diff] [blame] | 1959 | return; |
| 1960 | } |
| 1961 | final boolean updated = stack.ensureActivityConfigurationLocked(r, 0, |
| 1962 | preserveWindows); |
Jorim Jaggi | dc249c4 | 2015-12-15 14:57:31 -0800 | [diff] [blame] | 1963 | if (!updated) { |
| 1964 | resumeFocusedStackTopActivityLocked(); |
| 1965 | } |
| 1966 | } |
| 1967 | |
| 1968 | void resizeDockedStackLocked(Rect dockedBounds, Rect tempDockedTaskBounds, |
| 1969 | Rect tempDockedTaskInsetBounds, |
| 1970 | Rect tempOtherTaskBounds, Rect tempOtherTaskInsetBounds, boolean preserveWindows) { |
| 1971 | final ActivityStack stack = getStack(DOCKED_STACK_ID); |
| 1972 | if (stack == null) { |
| 1973 | Slog.w(TAG, "resizeDockedStackLocked: docked stack not found"); |
| 1974 | return; |
| 1975 | } |
| 1976 | |
| 1977 | Trace.traceBegin(TRACE_TAG_ACTIVITY_MANAGER, "am.resizeDockedStack"); |
| 1978 | mWindowManager.deferSurfaceLayout(); |
| 1979 | try { |
| 1980 | ActivityRecord r = stack.topRunningActivityLocked(); |
| 1981 | resizeStackUncheckedLocked(stack, dockedBounds, tempDockedTaskBounds, |
| 1982 | tempDockedTaskInsetBounds); |
| 1983 | |
| 1984 | if (stack.mFullscreen) { |
| 1985 | // The dock stack went fullscreen which is kinda like dismissing it. |
| 1986 | // In this case we make all other static stacks fullscreen and move all |
| 1987 | // docked stack tasks to the fullscreen stack. |
| 1988 | for (int i = FIRST_STATIC_STACK_ID; i <= LAST_STATIC_STACK_ID; i++) { |
| 1989 | if (StackId.isResizeableByDockedStack(i) && getStack(i) != null) { |
| 1990 | resizeStackLocked(i, null, null, null, preserveWindows, |
| 1991 | true /* allowResizeInDockedMode */); |
| 1992 | } |
| 1993 | } |
| 1994 | |
| 1995 | ArrayList<TaskRecord> tasks = stack.getAllTasks(); |
| 1996 | final int count = tasks.size(); |
| 1997 | for (int i = 0; i < count; i++) { |
| 1998 | moveTaskToStackLocked(tasks.get(i).taskId, |
| 1999 | FULLSCREEN_WORKSPACE_STACK_ID, ON_TOP, FORCE_FOCUS, "resizeStack", |
| 2000 | false /* animate */); |
| 2001 | } |
| 2002 | |
| 2003 | // stack shouldn't contain anymore activities, so nothing to resume. |
| 2004 | r = null; |
| 2005 | } else { |
| 2006 | // Docked stacks occupy a dedicated region on screen so the size of all other |
| 2007 | // static stacks need to be adjusted so they don't overlap with the docked stack. |
| 2008 | // We get the bounds to use from window manager which has been adjusted for any |
| 2009 | // screen controls and is also the same for all stacks. |
Wale Ogunwale | ccb6ce2 | 2016-01-14 15:36:35 -0800 | [diff] [blame] | 2010 | mWindowManager.getStackDockedModeBounds( |
Wale Ogunwale | 961f485 | 2016-02-01 20:25:54 -0800 | [diff] [blame] | 2011 | HOME_STACK_ID, tempRect, true /* ignoreVisibility */); |
Jorim Jaggi | dc249c4 | 2015-12-15 14:57:31 -0800 | [diff] [blame] | 2012 | for (int i = FIRST_STATIC_STACK_ID; i <= LAST_STATIC_STACK_ID; i++) { |
| 2013 | if (StackId.isResizeableByDockedStack(i)) { |
| 2014 | ActivityStack otherStack = getStack(i); |
| 2015 | if (otherStack != null) { |
| 2016 | resizeStackLocked(i, tempRect, tempOtherTaskBounds, |
| 2017 | tempOtherTaskInsetBounds, preserveWindows, |
| 2018 | true /* allowResizeInDockedMode */); |
| 2019 | } |
| 2020 | } |
| 2021 | } |
| 2022 | } |
| 2023 | ensureConfigurationAndResume(stack, r, preserveWindows); |
| 2024 | } finally { |
| 2025 | mWindowManager.continueSurfaceLayout(); |
| 2026 | Trace.traceEnd(TRACE_TAG_ACTIVITY_MANAGER); |
| 2027 | } |
| 2028 | |
| 2029 | mResizeDockedStackTimeout.notifyResizing(dockedBounds, |
| 2030 | tempDockedTaskBounds != null |
| 2031 | || tempDockedTaskInsetBounds != null |
| 2032 | || tempOtherTaskBounds != null |
| 2033 | || tempOtherTaskInsetBounds != null); |
| 2034 | } |
| 2035 | |
Chong Zhang | f596cd5 | 2016-01-05 13:42:44 -0800 | [diff] [blame] | 2036 | boolean resizeTaskLocked(TaskRecord task, Rect bounds, int resizeMode, boolean preserveWindow) { |
Wale Ogunwale | b1faf60 | 2016-01-27 09:12:31 -0800 | [diff] [blame] | 2037 | if (!task.isResizeable()) { |
Wale Ogunwale | e4a0c57 | 2015-06-30 08:40:31 -0700 | [diff] [blame] | 2038 | Slog.w(TAG, "resizeTask: task " + task + " not resizeable."); |
Chong Zhang | f596cd5 | 2016-01-05 13:42:44 -0800 | [diff] [blame] | 2039 | return true; |
Wale Ogunwale | e4a0c57 | 2015-06-30 08:40:31 -0700 | [diff] [blame] | 2040 | } |
| 2041 | |
Chong Zhang | 87b2172 | 2015-09-21 15:39:51 -0700 | [diff] [blame] | 2042 | // If this is a forced resize, let it go through even if the bounds is not changing, |
| 2043 | // as we might need a relayout due to surface size change (to/from fullscreen). |
Chong Zhang | 6de2ae8 | 2015-09-30 18:25:21 -0700 | [diff] [blame] | 2044 | final boolean forced = (resizeMode & RESIZE_MODE_FORCED) != 0; |
Filip Gruszczynski | 84fa335 | 2016-01-25 16:28:49 -0800 | [diff] [blame] | 2045 | if (Objects.equals(task.mBounds, bounds) && !forced) { |
Wale Ogunwale | e4a0c57 | 2015-06-30 08:40:31 -0700 | [diff] [blame] | 2046 | // Nothing to do here... |
Chong Zhang | f596cd5 | 2016-01-05 13:42:44 -0800 | [diff] [blame] | 2047 | return true; |
Wale Ogunwale | e4a0c57 | 2015-06-30 08:40:31 -0700 | [diff] [blame] | 2048 | } |
Filip Gruszczynski | dce2d16 | 2016-01-12 15:40:13 -0800 | [diff] [blame] | 2049 | bounds = TaskRecord.validateBounds(bounds); |
Wale Ogunwale | e4a0c57 | 2015-06-30 08:40:31 -0700 | [diff] [blame] | 2050 | |
Wale Ogunwale | e4a0c57 | 2015-06-30 08:40:31 -0700 | [diff] [blame] | 2051 | if (!mWindowManager.isValidTaskId(task.taskId)) { |
| 2052 | // Task doesn't exist in window manager yet (e.g. was restored from recents). |
Wale Ogunwale | 706ed79 | 2015-08-02 10:29:44 -0700 | [diff] [blame] | 2053 | // All we can do for now is update the bounds so it can be used when the task is |
| 2054 | // added to window manager. |
Chong Zhang | 0fa656b | 2015-08-31 15:17:21 -0700 | [diff] [blame] | 2055 | task.updateOverrideConfiguration(bounds); |
Wale Ogunwale | 706ed79 | 2015-08-02 10:29:44 -0700 | [diff] [blame] | 2056 | if (task.stack != null && task.stack.mStackId != FREEFORM_WORKSPACE_STACK_ID) { |
| 2057 | // re-restore the task so it can have the proper stack association. |
Chong Zhang | 5dcb275 | 2015-08-18 13:50:26 -0700 | [diff] [blame] | 2058 | restoreRecentTaskLocked(task, FREEFORM_WORKSPACE_STACK_ID); |
Wale Ogunwale | 706ed79 | 2015-08-02 10:29:44 -0700 | [diff] [blame] | 2059 | } |
Chong Zhang | f596cd5 | 2016-01-05 13:42:44 -0800 | [diff] [blame] | 2060 | return true; |
Wale Ogunwale | e4a0c57 | 2015-06-30 08:40:31 -0700 | [diff] [blame] | 2061 | } |
| 2062 | |
Chong Zhang | 6de2ae8 | 2015-09-30 18:25:21 -0700 | [diff] [blame] | 2063 | // Do not move the task to another stack here. |
| 2064 | // This method assumes that the task is already placed in the right stack. |
| 2065 | // we do not mess with that decision and we only do the resize! |
Wale Ogunwale | cad05a0 | 2015-09-25 10:41:44 -0700 | [diff] [blame] | 2066 | |
Chong Zhang | 6de2ae8 | 2015-09-30 18:25:21 -0700 | [diff] [blame] | 2067 | Trace.traceBegin(TRACE_TAG_ACTIVITY_MANAGER, "am.resizeTask_" + task.taskId); |
Wale Ogunwale | 040b470 | 2015-08-06 18:10:50 -0700 | [diff] [blame] | 2068 | |
Filip Gruszczynski | aff7f13 | 2015-09-02 17:21:21 -0700 | [diff] [blame] | 2069 | final Configuration overrideConfig = task.updateOverrideConfiguration(bounds); |
Wale Ogunwale | 04ad7b1 | 2015-10-02 12:43:27 -0700 | [diff] [blame] | 2070 | // This variable holds information whether the configuration didn't change in a significant |
Filip Gruszczynski | ebcc875 | 2015-08-25 16:51:05 -0700 | [diff] [blame] | 2071 | // way and the activity was kept the way it was. If it's false, it means the activity had |
| 2072 | // to be relaunched due to configuration change. |
| 2073 | boolean kept = true; |
| 2074 | if (overrideConfig != null) { |
Wale Ogunwale | 9a08f82 | 2016-02-17 19:03:58 -0800 | [diff] [blame] | 2075 | final ActivityRecord r = task.topRunningActivityLocked(); |
Wale Ogunwale | 60454db | 2015-01-23 16:05:07 -0800 | [diff] [blame] | 2076 | if (r != null) { |
Wale Ogunwale | e4a0c57 | 2015-06-30 08:40:31 -0700 | [diff] [blame] | 2077 | final ActivityStack stack = task.stack; |
Filip Gruszczynski | a59ac9c | 2015-09-10 18:28:48 -0700 | [diff] [blame] | 2078 | kept = stack.ensureActivityConfigurationLocked(r, 0, preserveWindow); |
Filip Gruszczynski | ebcc875 | 2015-08-25 16:51:05 -0700 | [diff] [blame] | 2079 | // All other activities must be made visible with their correct configuration. |
Filip Gruszczynski | bc5a6c5 | 2015-09-22 13:13:24 -0700 | [diff] [blame] | 2080 | ensureActivitiesVisibleLocked(r, 0, !PRESERVE_WINDOWS); |
Filip Gruszczynski | ebcc875 | 2015-08-25 16:51:05 -0700 | [diff] [blame] | 2081 | if (!kept) { |
Wale Ogunwale | d046a01 | 2015-12-24 13:05:59 -0800 | [diff] [blame] | 2082 | resumeFocusedStackTopActivityLocked(); |
Wale Ogunwale | 60454db | 2015-01-23 16:05:07 -0800 | [diff] [blame] | 2083 | } |
| 2084 | } |
| 2085 | } |
Wale Ogunwale | 9a08f82 | 2016-02-17 19:03:58 -0800 | [diff] [blame] | 2086 | mWindowManager.resizeTask(task.taskId, task.mBounds, task.mOverrideConfig, kept, forced); |
Wale Ogunwale | cad05a0 | 2015-09-25 10:41:44 -0700 | [diff] [blame] | 2087 | |
| 2088 | Trace.traceEnd(TRACE_TAG_ACTIVITY_MANAGER); |
Chong Zhang | f596cd5 | 2016-01-05 13:42:44 -0800 | [diff] [blame] | 2089 | return kept; |
Wale Ogunwale | 60454db | 2015-01-23 16:05:07 -0800 | [diff] [blame] | 2090 | } |
| 2091 | |
Wale Ogunwale | ddc1cb2 | 2015-07-25 19:23:04 -0700 | [diff] [blame] | 2092 | ActivityStack createStackOnDisplay(int stackId, int displayId, boolean onTop) { |
Craig Mautner | e0a3884 | 2013-12-16 16:14:02 -0800 | [diff] [blame] | 2093 | ActivityDisplay activityDisplay = mActivityDisplays.get(displayId); |
| 2094 | if (activityDisplay == null) { |
Todd Kennedy | 4900bf9 | 2015-01-16 16:05:14 -0800 | [diff] [blame] | 2095 | return null; |
Craig Mautner | 4a1cb22 | 2013-12-04 16:14:06 -0800 | [diff] [blame] | 2096 | } |
| 2097 | |
Craig Mautner | f4c909b | 2014-04-17 18:39:38 -0700 | [diff] [blame] | 2098 | ActivityContainer activityContainer = new ActivityContainer(stackId); |
| 2099 | mActivityContainers.put(stackId, activityContainer); |
Wale Ogunwale | ddc1cb2 | 2015-07-25 19:23:04 -0700 | [diff] [blame] | 2100 | activityContainer.attachToDisplayLocked(activityDisplay, onTop); |
Todd Kennedy | 4900bf9 | 2015-01-16 16:05:14 -0800 | [diff] [blame] | 2101 | return activityContainer.mStack; |
Craig Mautner | 4a1cb22 | 2013-12-04 16:14:06 -0800 | [diff] [blame] | 2102 | } |
| 2103 | |
| 2104 | int getNextStackId() { |
Craig Mautner | 858d8a6 | 2013-04-23 17:08:34 -0700 | [diff] [blame] | 2105 | while (true) { |
Wale Ogunwale | ddc1cb2 | 2015-07-25 19:23:04 -0700 | [diff] [blame] | 2106 | if (mNextFreeStackId >= FIRST_DYNAMIC_STACK_ID |
| 2107 | && getStack(mNextFreeStackId) == null) { |
Craig Mautner | 858d8a6 | 2013-04-23 17:08:34 -0700 | [diff] [blame] | 2108 | break; |
| 2109 | } |
Wale Ogunwale | ddc1cb2 | 2015-07-25 19:23:04 -0700 | [diff] [blame] | 2110 | mNextFreeStackId++; |
Craig Mautner | 8d341ef | 2013-03-26 09:03:27 -0700 | [diff] [blame] | 2111 | } |
Wale Ogunwale | ddc1cb2 | 2015-07-25 19:23:04 -0700 | [diff] [blame] | 2112 | return mNextFreeStackId; |
Craig Mautner | 8d341ef | 2013-03-26 09:03:27 -0700 | [diff] [blame] | 2113 | } |
| 2114 | |
Chong Zhang | 5dcb275 | 2015-08-18 13:50:26 -0700 | [diff] [blame] | 2115 | /** |
| 2116 | * Restores a recent task to a stack |
| 2117 | * @param task The recent task to be restored. |
| 2118 | * @param stackId The stack to restore the task to (default launch stack will be used |
Wale Ogunwale | 3797c22 | 2015-10-27 14:21:58 -0700 | [diff] [blame] | 2119 | * if stackId is {@link android.app.ActivityManager.StackId#INVALID_STACK_ID}). |
Chong Zhang | 5dcb275 | 2015-08-18 13:50:26 -0700 | [diff] [blame] | 2120 | * @return true if the task has been restored successfully. |
| 2121 | */ |
| 2122 | private boolean restoreRecentTaskLocked(TaskRecord task, int stackId) { |
| 2123 | if (stackId == INVALID_STACK_ID) { |
Wale Ogunwale | 8b06a58 | 2015-10-22 14:38:21 -0700 | [diff] [blame] | 2124 | stackId = task.getLaunchStackId(); |
Wale Ogunwale | 513346d | 2016-01-27 10:55:01 -0800 | [diff] [blame] | 2125 | } else if (stackId == DOCKED_STACK_ID && !task.canGoInDockedStack()) { |
| 2126 | // Preferred stack is the docked stack, but the task can't go in the docked stack. |
| 2127 | // Put it in the fullscreen stack. |
| 2128 | stackId = FULLSCREEN_WORKSPACE_STACK_ID; |
Chong Zhang | 5dcb275 | 2015-08-18 13:50:26 -0700 | [diff] [blame] | 2129 | } |
Wale Ogunwale | 513346d | 2016-01-27 10:55:01 -0800 | [diff] [blame] | 2130 | |
Wale Ogunwale | 706ed79 | 2015-08-02 10:29:44 -0700 | [diff] [blame] | 2131 | if (task.stack != null) { |
| 2132 | // Task has already been restored once. See if we need to do anything more |
| 2133 | if (task.stack.mStackId == stackId) { |
| 2134 | // Nothing else to do since it is already restored in the right stack. |
| 2135 | return true; |
| 2136 | } |
| 2137 | // Remove current stack association, so we can re-associate the task with the |
| 2138 | // right stack below. |
Wale Ogunwale | 040b470 | 2015-08-06 18:10:50 -0700 | [diff] [blame] | 2139 | task.stack.removeTask(task, "restoreRecentTaskLocked", MOVING); |
Wale Ogunwale | 706ed79 | 2015-08-02 10:29:44 -0700 | [diff] [blame] | 2140 | } |
| 2141 | |
Wale Ogunwale | 6c5eb1c | 2015-11-10 07:52:22 -0800 | [diff] [blame] | 2142 | final ActivityStack stack = |
Wale Ogunwale | 040b470 | 2015-08-06 18:10:50 -0700 | [diff] [blame] | 2143 | getStack(stackId, CREATE_IF_NEEDED, !ON_TOP); |
Wale Ogunwale | 7de0535 | 2014-12-12 15:21:33 -0800 | [diff] [blame] | 2144 | |
| 2145 | if (stack == null) { |
| 2146 | // What does this mean??? Not sure how we would get here... |
Wale Ogunwale | ee006da | 2015-03-30 14:49:25 -0700 | [diff] [blame] | 2147 | if (DEBUG_RECENTS) Slog.v(TAG_RECENTS, |
| 2148 | "Unable to find/create stack to restore recent task=" + task); |
Wale Ogunwale | 7de0535 | 2014-12-12 15:21:33 -0800 | [diff] [blame] | 2149 | return false; |
| 2150 | } |
| 2151 | |
Wale Ogunwale | 5f98609 | 2015-12-04 15:35:38 -0800 | [diff] [blame] | 2152 | stack.addTask(task, false, "restoreRecentTask"); |
Wale Ogunwale | ee006da | 2015-03-30 14:49:25 -0700 | [diff] [blame] | 2153 | if (DEBUG_RECENTS) Slog.v(TAG_RECENTS, |
| 2154 | "Added restored task=" + task + " to stack=" + stack); |
Wale Ogunwale | 7de0535 | 2014-12-12 15:21:33 -0800 | [diff] [blame] | 2155 | final ArrayList<ActivityRecord> activities = task.mActivities; |
| 2156 | for (int activityNdx = activities.size() - 1; activityNdx >= 0; --activityNdx) { |
Filip Gruszczynski | e5390e7 | 2015-08-18 16:39:00 -0700 | [diff] [blame] | 2157 | stack.addConfigOverride(activities.get(activityNdx), task); |
Wale Ogunwale | 7de0535 | 2014-12-12 15:21:33 -0800 | [diff] [blame] | 2158 | } |
| 2159 | return true; |
Craig Mautner | ef73ee1 | 2014-04-23 11:45:37 -0700 | [diff] [blame] | 2160 | } |
| 2161 | |
Wale Ogunwale | 040b470 | 2015-08-06 18:10:50 -0700 | [diff] [blame] | 2162 | /** |
| 2163 | * Moves the specified task record to the input stack id. |
| 2164 | * WARNING: This method performs an unchecked/raw move of the task and |
| 2165 | * can leave the system in an unstable state if used incorrectly. |
Wale Ogunwale | 513346d | 2016-01-27 10:55:01 -0800 | [diff] [blame] | 2166 | * Use {@link #moveTaskToStackLocked} to perform safe task movement to a stack. |
Wale Ogunwale | 040b470 | 2015-08-06 18:10:50 -0700 | [diff] [blame] | 2167 | * @param task Task to move. |
| 2168 | * @param stackId Id of stack to move task to. |
| 2169 | * @param toTop True if the task should be placed at the top of the stack. |
Chong Zhang | 0289835 | 2015-08-21 17:27:14 -0700 | [diff] [blame] | 2170 | * @param forceFocus if focus should be moved to the new stack |
Wale Ogunwale | 040b470 | 2015-08-06 18:10:50 -0700 | [diff] [blame] | 2171 | * @param reason Reason the task is been moved. |
| 2172 | * @return The stack the task was moved to. |
| 2173 | */ |
Chong Zhang | 6de2ae8 | 2015-09-30 18:25:21 -0700 | [diff] [blame] | 2174 | ActivityStack moveTaskToStackUncheckedLocked( |
Chong Zhang | 0289835 | 2015-08-21 17:27:14 -0700 | [diff] [blame] | 2175 | TaskRecord task, int stackId, boolean toTop, boolean forceFocus, String reason) { |
| 2176 | final ActivityRecord r = task.getTopActivity(); |
Wale Ogunwale | d046a01 | 2015-12-24 13:05:59 -0800 | [diff] [blame] | 2177 | final ActivityStack prevStack = task.stack; |
| 2178 | final boolean wasFocused = isFocusedStack(prevStack) && (topRunningActivityLocked() == r); |
| 2179 | final boolean wasResumed = wasFocused && (prevStack.mResumedActivity == r); |
| 2180 | // In some cases the focused stack isn't the front stack. E.g. pinned stack. |
| 2181 | // Whenever we are moving the top activity from the front stack we want to make sure to move |
| 2182 | // the stack to the front. |
| 2183 | final boolean wasFront = isFrontStack(prevStack) |
| 2184 | && (prevStack.topRunningActivityLocked() == r); |
Chong Zhang | 0289835 | 2015-08-21 17:27:14 -0700 | [diff] [blame] | 2185 | |
Wale Ogunwale | b1faf60 | 2016-01-27 09:12:31 -0800 | [diff] [blame] | 2186 | final int resizeMode = task.mResizeMode; |
Wale Ogunwale | 513346d | 2016-01-27 10:55:01 -0800 | [diff] [blame] | 2187 | |
| 2188 | if (stackId == DOCKED_STACK_ID && resizeMode == RESIZE_MODE_UNRESIZEABLE) { |
| 2189 | // We don't allow moving a unresizeable task to the docked stack since the docked |
| 2190 | // stack is used for split-screen mode and will cause things like the docked divider to |
| 2191 | // show up. We instead leave the task in its current stack or move it to the fullscreen |
| 2192 | // stack if it isn't currently in a stack. |
| 2193 | stackId = (prevStack != null) ? prevStack.mStackId : FULLSCREEN_WORKSPACE_STACK_ID; |
Wale Ogunwale | 513346d | 2016-01-27 10:55:01 -0800 | [diff] [blame] | 2194 | Slog.w(TAG, "Can not move unresizeable task=" + task |
| 2195 | + " to docked stack. Moving to stackId=" + stackId + " instead."); |
| 2196 | } |
| 2197 | |
Wale Ogunwale | eb8e56c | 2015-09-22 20:38:16 -0700 | [diff] [blame] | 2198 | // Temporarily disable resizeablility of task we are moving. We don't want it to be resized |
| 2199 | // if a docked stack is created below which will lead to the stack we are moving from and |
| 2200 | // its resizeable tasks being resized. |
Jorim Jaggi | 8202b2a | 2016-02-03 19:24:31 -0800 | [diff] [blame] | 2201 | task.mTemporarilyUnresizable = true; |
Wale Ogunwale | b34a7ad | 2015-08-14 11:05:30 -0700 | [diff] [blame] | 2202 | final ActivityStack stack = getStack(stackId, CREATE_IF_NEEDED, toTop); |
Jorim Jaggi | 8202b2a | 2016-02-03 19:24:31 -0800 | [diff] [blame] | 2203 | task.mTemporarilyUnresizable = false; |
Wale Ogunwale | 040b470 | 2015-08-06 18:10:50 -0700 | [diff] [blame] | 2204 | mWindowManager.moveTaskToStack(task.taskId, stack.mStackId, toTop); |
Wale Ogunwale | 5f98609 | 2015-12-04 15:35:38 -0800 | [diff] [blame] | 2205 | stack.addTask(task, toTop, reason); |
Chong Zhang | 0289835 | 2015-08-21 17:27:14 -0700 | [diff] [blame] | 2206 | |
| 2207 | // If the task had focus before (or we're requested to move focus), |
Wale Ogunwale | d046a01 | 2015-12-24 13:05:59 -0800 | [diff] [blame] | 2208 | // move focus to the new stack by moving the stack to the front. |
| 2209 | stack.moveToFrontAndResumeStateIfNeeded( |
| 2210 | r, forceFocus || wasFocused || wasFront, wasResumed, reason); |
Chong Zhang | 0289835 | 2015-08-21 17:27:14 -0700 | [diff] [blame] | 2211 | |
Wale Ogunwale | 040b470 | 2015-08-06 18:10:50 -0700 | [diff] [blame] | 2212 | return stack; |
| 2213 | } |
| 2214 | |
Filip Gruszczynski | 90186c6 | 2015-10-26 14:07:00 -0700 | [diff] [blame] | 2215 | void moveTaskToStackLocked(int taskId, int stackId, boolean toTop, boolean forceFocus, |
Jorim Jaggi | 030979c | 2015-11-20 15:14:43 -0800 | [diff] [blame] | 2216 | String reason, boolean animate) { |
Craig Mautner | b3b36ba | 2013-05-20 13:21:10 -0700 | [diff] [blame] | 2217 | final TaskRecord task = anyTaskForIdLocked(taskId); |
| 2218 | if (task == null) { |
Wale Ogunwale | 53a29a9 | 2015-02-23 15:42:52 -0800 | [diff] [blame] | 2219 | Slog.w(TAG, "moveTaskToStack: no task for id=" + taskId); |
Craig Mautner | b3b36ba | 2013-05-20 13:21:10 -0700 | [diff] [blame] | 2220 | return; |
| 2221 | } |
Wale Ogunwale | 6c5eb1c | 2015-11-10 07:52:22 -0800 | [diff] [blame] | 2222 | |
Wale Ogunwale | 70c65c8 | 2015-11-13 13:25:16 -0800 | [diff] [blame] | 2223 | if (task.stack != null && task.stack.mStackId == stackId) { |
| 2224 | // You are already in the right stack silly... |
| 2225 | Slog.i(TAG, "moveTaskToStack: taskId=" + taskId + " already in stackId=" + stackId); |
| 2226 | return; |
| 2227 | } |
| 2228 | |
Wale Ogunwale | 6c5eb1c | 2015-11-10 07:52:22 -0800 | [diff] [blame] | 2229 | final ActivityRecord topActivity = task.getTopActivity(); |
Jorim Jaggi | e909802 | 2016-01-27 19:29:40 -0800 | [diff] [blame] | 2230 | final int sourceStackId = task.stack != null ? task.stack.mStackId : INVALID_STACK_ID; |
Chong Zhang | f596cd5 | 2016-01-05 13:42:44 -0800 | [diff] [blame] | 2231 | final boolean mightReplaceWindow = |
Jorim Jaggi | e909802 | 2016-01-27 19:29:40 -0800 | [diff] [blame] | 2232 | StackId.replaceWindowsOnTaskMove(sourceStackId, stackId) && topActivity != null; |
Chong Zhang | f596cd5 | 2016-01-05 13:42:44 -0800 | [diff] [blame] | 2233 | if (mightReplaceWindow) { |
Filip Gruszczynski | 49b80af | 2015-09-24 09:04:26 -0700 | [diff] [blame] | 2234 | // We are about to relaunch the activity because its configuration changed due to |
| 2235 | // being maximized, i.e. size change. The activity will first remove the old window |
| 2236 | // and then add a new one. This call will tell window manager about this, so it can |
| 2237 | // preserve the old window until the new one is drawn. This prevents having a gap |
| 2238 | // between the removal and addition, in which no window is visible. We also want the |
Wale Ogunwale | 7e8184b | 2015-10-05 14:37:03 -0700 | [diff] [blame] | 2239 | // entrance of the new window to be properly animated. |
Chong Zhang | f596cd5 | 2016-01-05 13:42:44 -0800 | [diff] [blame] | 2240 | // Note here we always set the replacing window first, as the flags might be needed |
| 2241 | // during the relaunch. If we end up not doing any relaunch, we clear the flags later. |
Jorim Jaggi | 030979c | 2015-11-20 15:14:43 -0800 | [diff] [blame] | 2242 | mWindowManager.setReplacingWindow(topActivity.appToken, animate); |
Filip Gruszczynski | 49b80af | 2015-09-24 09:04:26 -0700 | [diff] [blame] | 2243 | } |
Wale Ogunwale | 961f485 | 2016-02-01 20:25:54 -0800 | [diff] [blame] | 2244 | |
| 2245 | mWindowManager.deferSurfaceLayout(); |
Wale Ogunwale | b9b16a7 | 2016-01-27 12:24:44 -0800 | [diff] [blame] | 2246 | final int preferredLaunchStackId = stackId; |
Chong Zhang | f596cd5 | 2016-01-05 13:42:44 -0800 | [diff] [blame] | 2247 | boolean kept = true; |
Wale Ogunwale | 961f485 | 2016-02-01 20:25:54 -0800 | [diff] [blame] | 2248 | try { |
| 2249 | final ActivityStack stack = moveTaskToStackUncheckedLocked( |
Wale Ogunwale | 5658e4b | 2016-02-12 12:22:19 -0800 | [diff] [blame] | 2250 | task, stackId, toTop, forceFocus, reason + " moveTaskToStack"); |
Wale Ogunwale | 961f485 | 2016-02-01 20:25:54 -0800 | [diff] [blame] | 2251 | stackId = stack.mStackId; |
Jorim Jaggi | e909802 | 2016-01-27 19:29:40 -0800 | [diff] [blame] | 2252 | |
Wale Ogunwale | 961f485 | 2016-02-01 20:25:54 -0800 | [diff] [blame] | 2253 | if (!animate) { |
| 2254 | stack.mNoAnimActivities.add(topActivity); |
| 2255 | } |
Jorim Jaggi | e909802 | 2016-01-27 19:29:40 -0800 | [diff] [blame] | 2256 | |
Wale Ogunwale | 961f485 | 2016-02-01 20:25:54 -0800 | [diff] [blame] | 2257 | // We might trigger a configuration change. Save the current task bounds for freezing. |
| 2258 | mWindowManager.prepareFreezingTaskBounds(stack.mStackId); |
| 2259 | |
| 2260 | // Make sure the task has the appropriate bounds/size for the stack it is in. |
| 2261 | if (stackId == FULLSCREEN_WORKSPACE_STACK_ID && task.mBounds != null) { |
| 2262 | kept = resizeTaskLocked(task, stack.mBounds, RESIZE_MODE_SYSTEM, !mightReplaceWindow); |
| 2263 | } else if (stackId == FREEFORM_WORKSPACE_STACK_ID |
| 2264 | && task.mBounds == null && task.mLastNonFullscreenBounds != null) { |
| 2265 | kept = resizeTaskLocked(task, task.mLastNonFullscreenBounds, |
| 2266 | RESIZE_MODE_SYSTEM, !mightReplaceWindow); |
| 2267 | } else if (stackId == DOCKED_STACK_ID || stackId == PINNED_STACK_ID) { |
| 2268 | kept = resizeTaskLocked(task, stack.mBounds, RESIZE_MODE_SYSTEM, !mightReplaceWindow); |
| 2269 | } |
| 2270 | } finally { |
| 2271 | mWindowManager.continueSurfaceLayout(); |
Chong Zhang | f596cd5 | 2016-01-05 13:42:44 -0800 | [diff] [blame] | 2272 | } |
| 2273 | |
| 2274 | if (mightReplaceWindow) { |
| 2275 | // If we didn't actual do a relaunch (indicated by kept==true meaning we kept the old |
| 2276 | // window), we need to clear the replace window settings. Otherwise, we schedule a |
| 2277 | // timeout to remove the old window if the replacing window is not coming in time. |
Filip Gruszczynski | 84fa335 | 2016-01-25 16:28:49 -0800 | [diff] [blame] | 2278 | mWindowManager.scheduleClearReplacingWindowIfNeeded(topActivity.appToken, !kept); |
Wale Ogunwale | b34a7ad | 2015-08-14 11:05:30 -0700 | [diff] [blame] | 2279 | } |
| 2280 | |
Stefan Kuhne | 54714cd | 2015-05-12 13:42:18 -0700 | [diff] [blame] | 2281 | // The task might have already been running and its visibility needs to be synchronized with |
| 2282 | // the visibility of the stack / windows. |
Jorim Jaggi | e909802 | 2016-01-27 19:29:40 -0800 | [diff] [blame] | 2283 | ensureActivitiesVisibleLocked(null, 0, !mightReplaceWindow); |
Wale Ogunwale | d046a01 | 2015-12-24 13:05:59 -0800 | [diff] [blame] | 2284 | resumeFocusedStackTopActivityLocked(); |
Chong Zhang | b15758a | 2015-11-17 12:12:03 -0800 | [diff] [blame] | 2285 | |
Wale Ogunwale | b9b16a7 | 2016-01-27 12:24:44 -0800 | [diff] [blame] | 2286 | showNonResizeableDockToastIfNeeded(task, preferredLaunchStackId, stackId); |
Craig Mautner | 8d341ef | 2013-03-26 09:03:27 -0700 | [diff] [blame] | 2287 | } |
| 2288 | |
Wale Ogunwale | 079a004 | 2015-10-24 11:44:07 -0700 | [diff] [blame] | 2289 | boolean moveTopStackActivityToPinnedStackLocked(int stackId, Rect bounds) { |
| 2290 | final ActivityStack stack = getStack(stackId, !CREATE_IF_NEEDED, !ON_TOP); |
| 2291 | if (stack == null) { |
| 2292 | throw new IllegalArgumentException( |
| 2293 | "moveTopStackActivityToPinnedStackLocked: Unknown stackId=" + stackId); |
| 2294 | } |
| 2295 | |
| 2296 | final ActivityRecord r = stack.topRunningActivityLocked(); |
| 2297 | if (r == null) { |
| 2298 | Slog.w(TAG, "moveTopStackActivityToPinnedStackLocked: No top running activity" |
| 2299 | + " in stack=" + stack); |
| 2300 | return false; |
| 2301 | } |
| 2302 | |
Wale Ogunwale | 6cae765 | 2015-12-26 07:36:26 -0800 | [diff] [blame] | 2303 | if (!mService.mForceResizableActivities && !r.supportsPictureInPicture()) { |
Wale Ogunwale | b60692e | 2015-10-24 12:35:56 -0700 | [diff] [blame] | 2304 | Slog.w(TAG, |
| 2305 | "moveTopStackActivityToPinnedStackLocked: Picture-In-Picture not supported for " |
Filip Gruszczynski | 77d9448 | 2015-12-11 13:59:52 -0800 | [diff] [blame] | 2306 | + " r=" + r); |
Wale Ogunwale | 079a004 | 2015-10-24 11:44:07 -0700 | [diff] [blame] | 2307 | return false; |
| 2308 | } |
| 2309 | |
Wale Ogunwale | 480dca0 | 2016-02-06 13:58:29 -0800 | [diff] [blame] | 2310 | moveActivityToPinnedStackLocked(r, "moveTopActivityToPinnedStack", bounds); |
Wale Ogunwale | 9c604c7 | 2015-12-06 18:42:57 -0800 | [diff] [blame] | 2311 | return true; |
| 2312 | } |
| 2313 | |
Wale Ogunwale | 480dca0 | 2016-02-06 13:58:29 -0800 | [diff] [blame] | 2314 | void moveActivityToPinnedStackLocked(ActivityRecord r, String reason, Rect bounds) { |
| 2315 | mWindowManager.deferSurfaceLayout(); |
| 2316 | try { |
| 2317 | final TaskRecord task = r.task; |
| 2318 | |
| 2319 | // Need to make sure the pinned stack exist so we can resize it below... |
| 2320 | final ActivityStack stack = getStack(PINNED_STACK_ID, CREATE_IF_NEEDED, ON_TOP); |
| 2321 | |
| 2322 | // Resize the pinned stack to match the current size of the task the activity we are |
| 2323 | // going to be moving is currently contained in. We do this to have the right starting |
| 2324 | // animation bounds for the pinned stack to the desired bounds the caller wants. |
| 2325 | resizeStackLocked(PINNED_STACK_ID, task.mBounds, null /* tempTaskBounds */, |
| 2326 | null /* tempTaskInsetBounds */, !PRESERVE_WINDOWS, |
| 2327 | true /* allowResizeInDockedMode */); |
| 2328 | |
| 2329 | if (task.mActivities.size() == 1) { |
| 2330 | // There is only one activity in the task. So, we can just move the task over to |
| 2331 | // the stack without re-parenting the activity in a different task. |
| 2332 | moveTaskToStackLocked( |
| 2333 | task.taskId, PINNED_STACK_ID, ON_TOP, FORCE_FOCUS, reason, !ANIMATE); |
| 2334 | } else { |
| 2335 | stack.moveActivityToStack(r); |
| 2336 | } |
| 2337 | } finally { |
| 2338 | mWindowManager.continueSurfaceLayout(); |
Wale Ogunwale | 079a004 | 2015-10-24 11:44:07 -0700 | [diff] [blame] | 2339 | } |
| 2340 | |
Wale Ogunwale | 480dca0 | 2016-02-06 13:58:29 -0800 | [diff] [blame] | 2341 | // The task might have already been running and its visibility needs to be synchronized |
| 2342 | // with the visibility of the stack / windows. |
Wale Ogunwale | 079a004 | 2015-10-24 11:44:07 -0700 | [diff] [blame] | 2343 | ensureActivitiesVisibleLocked(null, 0, !PRESERVE_WINDOWS); |
Wale Ogunwale | d046a01 | 2015-12-24 13:05:59 -0800 | [diff] [blame] | 2344 | resumeFocusedStackTopActivityLocked(); |
Wale Ogunwale | 03ce863 | 2015-12-29 16:15:22 -0800 | [diff] [blame] | 2345 | |
Wale Ogunwale | 480dca0 | 2016-02-06 13:58:29 -0800 | [diff] [blame] | 2346 | mWindowManager.animateResizePinnedStack(bounds); |
| 2347 | mService.notifyActivityPinnedLocked(); |
Wale Ogunwale | 079a004 | 2015-10-24 11:44:07 -0700 | [diff] [blame] | 2348 | } |
| 2349 | |
Wale Ogunwale | ddc1cb2 | 2015-07-25 19:23:04 -0700 | [diff] [blame] | 2350 | void positionTaskInStackLocked(int taskId, int stackId, int position) { |
| 2351 | final TaskRecord task = anyTaskForIdLocked(taskId); |
| 2352 | if (task == null) { |
| 2353 | Slog.w(TAG, "positionTaskInStackLocked: no task for id=" + taskId); |
| 2354 | return; |
| 2355 | } |
Wale Ogunwale | 935e502 | 2015-11-10 12:36:10 -0800 | [diff] [blame] | 2356 | final ActivityStack stack = getStack(stackId, CREATE_IF_NEEDED, !ON_TOP); |
| 2357 | |
| 2358 | task.updateOverrideConfigurationForStack(stack); |
| 2359 | |
| 2360 | mWindowManager.positionTaskInStack( |
| 2361 | taskId, stackId, position, task.mBounds, task.mOverrideConfig); |
Wale Ogunwale | 5f98609 | 2015-12-04 15:35:38 -0800 | [diff] [blame] | 2362 | stack.positionTask(task, position); |
Wale Ogunwale | ddc1cb2 | 2015-07-25 19:23:04 -0700 | [diff] [blame] | 2363 | // The task might have already been running and its visibility needs to be synchronized with |
| 2364 | // the visibility of the stack / windows. |
Filip Gruszczynski | bc5a6c5 | 2015-09-22 13:13:24 -0700 | [diff] [blame] | 2365 | stack.ensureActivitiesVisibleLocked(null, 0, !PRESERVE_WINDOWS); |
Wale Ogunwale | d046a01 | 2015-12-24 13:05:59 -0800 | [diff] [blame] | 2366 | resumeFocusedStackTopActivityLocked(); |
Wale Ogunwale | ddc1cb2 | 2015-07-25 19:23:04 -0700 | [diff] [blame] | 2367 | } |
| 2368 | |
Craig Mautner | ac6f843 | 2013-07-17 13:24:59 -0700 | [diff] [blame] | 2369 | ActivityRecord findTaskLocked(ActivityRecord r) { |
Wale Ogunwale | 3938197 | 2015-12-17 17:15:29 -0800 | [diff] [blame] | 2370 | mTmpFindTaskResult.r = null; |
| 2371 | mTmpFindTaskResult.matchedByRootAffinity = false; |
Wale Ogunwale | ee006da | 2015-03-30 14:49:25 -0700 | [diff] [blame] | 2372 | if (DEBUG_TASKS) Slog.d(TAG_TASKS, "Looking for task of " + r); |
Craig Mautner | e0a3884 | 2013-12-16 16:14:02 -0800 | [diff] [blame] | 2373 | for (int displayNdx = mActivityDisplays.size() - 1; displayNdx >= 0; --displayNdx) { |
| 2374 | final ArrayList<ActivityStack> stacks = mActivityDisplays.valueAt(displayNdx).mStacks; |
Craig Mautner | 4a1cb22 | 2013-12-04 16:14:06 -0800 | [diff] [blame] | 2375 | for (int stackNdx = stacks.size() - 1; stackNdx >= 0; --stackNdx) { |
| 2376 | final ActivityStack stack = stacks.get(stackNdx); |
| 2377 | if (!r.isApplicationActivity() && !stack.isHomeStack()) { |
Wale Ogunwale | ee006da | 2015-03-30 14:49:25 -0700 | [diff] [blame] | 2378 | if (DEBUG_TASKS) Slog.d(TAG_TASKS, "Skipping stack: (home activity) " + stack); |
Craig Mautner | 1b4bf85 | 2014-05-26 15:06:32 -0700 | [diff] [blame] | 2379 | continue; |
| 2380 | } |
| 2381 | if (!stack.mActivityContainer.isEligibleForNewTasks()) { |
Wale Ogunwale | ee006da | 2015-03-30 14:49:25 -0700 | [diff] [blame] | 2382 | if (DEBUG_TASKS) Slog.d(TAG_TASKS, |
| 2383 | "Skipping stack: (new task not allowed) " + stack); |
Craig Mautner | 4a1cb22 | 2013-12-04 16:14:06 -0800 | [diff] [blame] | 2384 | continue; |
| 2385 | } |
Wale Ogunwale | 3938197 | 2015-12-17 17:15:29 -0800 | [diff] [blame] | 2386 | stack.findTaskLocked(r, mTmpFindTaskResult); |
| 2387 | // It is possible to have task in multiple stacks with the same root affinity. |
| 2388 | // If the match we found was based on root affinity we keep on looking to see if |
| 2389 | // there is a better match in another stack. We eventually return the match based |
| 2390 | // on root affinity if we don't find a better match. |
| 2391 | if (mTmpFindTaskResult.r != null && !mTmpFindTaskResult.matchedByRootAffinity) { |
| 2392 | return mTmpFindTaskResult.r; |
Craig Mautner | 4a1cb22 | 2013-12-04 16:14:06 -0800 | [diff] [blame] | 2393 | } |
Craig Mautner | 8849a5e | 2013-04-02 16:41:03 -0700 | [diff] [blame] | 2394 | } |
| 2395 | } |
Wale Ogunwale | 3938197 | 2015-12-17 17:15:29 -0800 | [diff] [blame] | 2396 | if (DEBUG_TASKS && mTmpFindTaskResult.r == null) Slog.d(TAG_TASKS, "No task found"); |
| 2397 | return mTmpFindTaskResult.r; |
Craig Mautner | 8849a5e | 2013-04-02 16:41:03 -0700 | [diff] [blame] | 2398 | } |
| 2399 | |
| 2400 | ActivityRecord findActivityLocked(Intent intent, ActivityInfo info) { |
Craig Mautner | e0a3884 | 2013-12-16 16:14:02 -0800 | [diff] [blame] | 2401 | for (int displayNdx = mActivityDisplays.size() - 1; displayNdx >= 0; --displayNdx) { |
| 2402 | final ArrayList<ActivityStack> stacks = mActivityDisplays.valueAt(displayNdx).mStacks; |
Craig Mautner | 4a1cb22 | 2013-12-04 16:14:06 -0800 | [diff] [blame] | 2403 | for (int stackNdx = stacks.size() - 1; stackNdx >= 0; --stackNdx) { |
| 2404 | final ActivityRecord ar = stacks.get(stackNdx).findActivityLocked(intent, info); |
| 2405 | if (ar != null) { |
| 2406 | return ar; |
| 2407 | } |
Craig Mautner | 8849a5e | 2013-04-02 16:41:03 -0700 | [diff] [blame] | 2408 | } |
| 2409 | } |
| 2410 | return null; |
| 2411 | } |
| 2412 | |
Craig Mautner | 8d341ef | 2013-03-26 09:03:27 -0700 | [diff] [blame] | 2413 | void goingToSleepLocked() { |
Craig Mautner | 0eea92c | 2013-05-16 13:35:39 -0700 | [diff] [blame] | 2414 | scheduleSleepTimeout(); |
| 2415 | if (!mGoingToSleep.isHeld()) { |
| 2416 | mGoingToSleep.acquire(); |
Craig Mautner | 7ea5bd4 | 2013-07-05 15:27:08 -0700 | [diff] [blame] | 2417 | if (mLaunchingActivity.isHeld()) { |
| 2418 | if (VALIDATE_WAKE_LOCK_CALLER && Binder.getCallingUid() != Process.myUid()) { |
| 2419 | throw new IllegalStateException("Calling must be system uid"); |
Craig Mautner | 0eea92c | 2013-05-16 13:35:39 -0700 | [diff] [blame] | 2420 | } |
Craig Mautner | 7ea5bd4 | 2013-07-05 15:27:08 -0700 | [diff] [blame] | 2421 | mLaunchingActivity.release(); |
| 2422 | mService.mHandler.removeMessages(LAUNCH_TIMEOUT_MSG); |
Craig Mautner | 0eea92c | 2013-05-16 13:35:39 -0700 | [diff] [blame] | 2423 | } |
Craig Mautner | 8d341ef | 2013-03-26 09:03:27 -0700 | [diff] [blame] | 2424 | } |
Amith Yamasani | ce15e15 | 2013-09-19 12:30:32 -0700 | [diff] [blame] | 2425 | checkReadyForSleepLocked(); |
Craig Mautner | 8d341ef | 2013-03-26 09:03:27 -0700 | [diff] [blame] | 2426 | } |
| 2427 | |
| 2428 | boolean shutdownLocked(int timeout) { |
Craig Mautner | 0eea92c | 2013-05-16 13:35:39 -0700 | [diff] [blame] | 2429 | goingToSleepLocked(); |
Craig Mautner | 0eea92c | 2013-05-16 13:35:39 -0700 | [diff] [blame] | 2430 | |
Craig Mautner | f4c909b | 2014-04-17 18:39:38 -0700 | [diff] [blame] | 2431 | boolean timedout = false; |
Craig Mautner | 0eea92c | 2013-05-16 13:35:39 -0700 | [diff] [blame] | 2432 | final long endTime = System.currentTimeMillis() + timeout; |
| 2433 | while (true) { |
| 2434 | boolean cantShutdown = false; |
Craig Mautner | e0a3884 | 2013-12-16 16:14:02 -0800 | [diff] [blame] | 2435 | for (int displayNdx = mActivityDisplays.size() - 1; displayNdx >= 0; --displayNdx) { |
| 2436 | final ArrayList<ActivityStack> stacks = mActivityDisplays.valueAt(displayNdx).mStacks; |
Craig Mautner | 4a1cb22 | 2013-12-04 16:14:06 -0800 | [diff] [blame] | 2437 | for (int stackNdx = stacks.size() - 1; stackNdx >= 0; --stackNdx) { |
| 2438 | cantShutdown |= stacks.get(stackNdx).checkReadyForSleepLocked(); |
| 2439 | } |
Craig Mautner | 0eea92c | 2013-05-16 13:35:39 -0700 | [diff] [blame] | 2440 | } |
| 2441 | if (cantShutdown) { |
| 2442 | long timeRemaining = endTime - System.currentTimeMillis(); |
| 2443 | if (timeRemaining > 0) { |
Craig Mautner | 8d341ef | 2013-03-26 09:03:27 -0700 | [diff] [blame] | 2444 | try { |
Craig Mautner | 0eea92c | 2013-05-16 13:35:39 -0700 | [diff] [blame] | 2445 | mService.wait(timeRemaining); |
Craig Mautner | 8d341ef | 2013-03-26 09:03:27 -0700 | [diff] [blame] | 2446 | } catch (InterruptedException e) { |
| 2447 | } |
Craig Mautner | 0eea92c | 2013-05-16 13:35:39 -0700 | [diff] [blame] | 2448 | } else { |
| 2449 | Slog.w(TAG, "Activity manager shutdown timed out"); |
| 2450 | timedout = true; |
| 2451 | break; |
Craig Mautner | 8d341ef | 2013-03-26 09:03:27 -0700 | [diff] [blame] | 2452 | } |
Craig Mautner | 0eea92c | 2013-05-16 13:35:39 -0700 | [diff] [blame] | 2453 | } else { |
| 2454 | break; |
Craig Mautner | 8d341ef | 2013-03-26 09:03:27 -0700 | [diff] [blame] | 2455 | } |
| 2456 | } |
Craig Mautner | 0eea92c | 2013-05-16 13:35:39 -0700 | [diff] [blame] | 2457 | |
| 2458 | // Force checkReadyForSleep to complete. |
| 2459 | mSleepTimeout = true; |
| 2460 | checkReadyForSleepLocked(); |
| 2461 | |
Craig Mautner | 8d341ef | 2013-03-26 09:03:27 -0700 | [diff] [blame] | 2462 | return timedout; |
| 2463 | } |
| 2464 | |
| 2465 | void comeOutOfSleepIfNeededLocked() { |
Craig Mautner | 0eea92c | 2013-05-16 13:35:39 -0700 | [diff] [blame] | 2466 | removeSleepTimeouts(); |
| 2467 | if (mGoingToSleep.isHeld()) { |
| 2468 | mGoingToSleep.release(); |
| 2469 | } |
Craig Mautner | e0a3884 | 2013-12-16 16:14:02 -0800 | [diff] [blame] | 2470 | for (int displayNdx = mActivityDisplays.size() - 1; displayNdx >= 0; --displayNdx) { |
| 2471 | final ArrayList<ActivityStack> stacks = mActivityDisplays.valueAt(displayNdx).mStacks; |
Craig Mautner | 4a1cb22 | 2013-12-04 16:14:06 -0800 | [diff] [blame] | 2472 | for (int stackNdx = stacks.size() - 1; stackNdx >= 0; --stackNdx) { |
| 2473 | final ActivityStack stack = stacks.get(stackNdx); |
| 2474 | stack.awakeFromSleepingLocked(); |
Wale Ogunwale | 1e60e0c | 2015-10-28 13:36:10 -0700 | [diff] [blame] | 2475 | if (isFocusedStack(stack)) { |
Wale Ogunwale | d046a01 | 2015-12-24 13:05:59 -0800 | [diff] [blame] | 2476 | resumeFocusedStackTopActivityLocked(); |
Craig Mautner | 4a1cb22 | 2013-12-04 16:14:06 -0800 | [diff] [blame] | 2477 | } |
Craig Mautner | 5314a40 | 2013-09-26 12:40:16 -0700 | [diff] [blame] | 2478 | } |
Craig Mautner | 8d341ef | 2013-03-26 09:03:27 -0700 | [diff] [blame] | 2479 | } |
Craig Mautner | 0eea92c | 2013-05-16 13:35:39 -0700 | [diff] [blame] | 2480 | mGoingToSleepActivities.clear(); |
| 2481 | } |
| 2482 | |
| 2483 | void activitySleptLocked(ActivityRecord r) { |
| 2484 | mGoingToSleepActivities.remove(r); |
| 2485 | checkReadyForSleepLocked(); |
| 2486 | } |
| 2487 | |
| 2488 | void checkReadyForSleepLocked() { |
| 2489 | if (!mService.isSleepingOrShuttingDown()) { |
| 2490 | // Do not care. |
| 2491 | return; |
| 2492 | } |
| 2493 | |
| 2494 | if (!mSleepTimeout) { |
| 2495 | boolean dontSleep = false; |
Craig Mautner | e0a3884 | 2013-12-16 16:14:02 -0800 | [diff] [blame] | 2496 | for (int displayNdx = mActivityDisplays.size() - 1; displayNdx >= 0; --displayNdx) { |
| 2497 | final ArrayList<ActivityStack> stacks = mActivityDisplays.valueAt(displayNdx).mStacks; |
Craig Mautner | 4a1cb22 | 2013-12-04 16:14:06 -0800 | [diff] [blame] | 2498 | for (int stackNdx = stacks.size() - 1; stackNdx >= 0; --stackNdx) { |
| 2499 | dontSleep |= stacks.get(stackNdx).checkReadyForSleepLocked(); |
| 2500 | } |
Craig Mautner | 0eea92c | 2013-05-16 13:35:39 -0700 | [diff] [blame] | 2501 | } |
| 2502 | |
| 2503 | if (mStoppingActivities.size() > 0) { |
| 2504 | // Still need to tell some activities to stop; can't sleep yet. |
Wale Ogunwale | ee006da | 2015-03-30 14:49:25 -0700 | [diff] [blame] | 2505 | if (DEBUG_PAUSE) Slog.v(TAG_PAUSE, "Sleep still need to stop " |
Craig Mautner | 0eea92c | 2013-05-16 13:35:39 -0700 | [diff] [blame] | 2506 | + mStoppingActivities.size() + " activities"); |
| 2507 | scheduleIdleLocked(); |
| 2508 | dontSleep = true; |
| 2509 | } |
| 2510 | |
| 2511 | if (mGoingToSleepActivities.size() > 0) { |
| 2512 | // Still need to tell some activities to sleep; can't sleep yet. |
Wale Ogunwale | ee006da | 2015-03-30 14:49:25 -0700 | [diff] [blame] | 2513 | if (DEBUG_PAUSE) Slog.v(TAG_PAUSE, "Sleep still need to sleep " |
Craig Mautner | 0eea92c | 2013-05-16 13:35:39 -0700 | [diff] [blame] | 2514 | + mGoingToSleepActivities.size() + " activities"); |
| 2515 | dontSleep = true; |
| 2516 | } |
| 2517 | |
| 2518 | if (dontSleep) { |
| 2519 | return; |
| 2520 | } |
| 2521 | } |
| 2522 | |
Craig Mautner | e0a3884 | 2013-12-16 16:14:02 -0800 | [diff] [blame] | 2523 | for (int displayNdx = mActivityDisplays.size() - 1; displayNdx >= 0; --displayNdx) { |
| 2524 | final ArrayList<ActivityStack> stacks = mActivityDisplays.valueAt(displayNdx).mStacks; |
Craig Mautner | 4a1cb22 | 2013-12-04 16:14:06 -0800 | [diff] [blame] | 2525 | for (int stackNdx = stacks.size() - 1; stackNdx >= 0; --stackNdx) { |
| 2526 | stacks.get(stackNdx).goToSleep(); |
| 2527 | } |
Craig Mautner | 0eea92c | 2013-05-16 13:35:39 -0700 | [diff] [blame] | 2528 | } |
| 2529 | |
| 2530 | removeSleepTimeouts(); |
| 2531 | |
| 2532 | if (mGoingToSleep.isHeld()) { |
| 2533 | mGoingToSleep.release(); |
| 2534 | } |
| 2535 | if (mService.mShuttingDown) { |
| 2536 | mService.notifyAll(); |
| 2537 | } |
Craig Mautner | 8d341ef | 2013-03-26 09:03:27 -0700 | [diff] [blame] | 2538 | } |
| 2539 | |
Craig Mautner | ce5f3cb | 2013-04-22 08:58:54 -0700 | [diff] [blame] | 2540 | boolean reportResumedActivityLocked(ActivityRecord r) { |
| 2541 | final ActivityStack stack = r.task.stack; |
Wale Ogunwale | 1e60e0c | 2015-10-28 13:36:10 -0700 | [diff] [blame] | 2542 | if (isFocusedStack(stack)) { |
Jeff Sharkey | 5782da7 | 2013-04-25 14:32:30 -0700 | [diff] [blame] | 2543 | mService.updateUsageStats(r, true); |
Craig Mautner | ce5f3cb | 2013-04-22 08:58:54 -0700 | [diff] [blame] | 2544 | } |
| 2545 | if (allResumedActivitiesComplete()) { |
Filip Gruszczynski | bc5a6c5 | 2015-09-22 13:13:24 -0700 | [diff] [blame] | 2546 | ensureActivitiesVisibleLocked(null, 0, !PRESERVE_WINDOWS); |
Craig Mautner | ce5f3cb | 2013-04-22 08:58:54 -0700 | [diff] [blame] | 2547 | mWindowManager.executeAppTransition(); |
| 2548 | return true; |
| 2549 | } |
| 2550 | return false; |
| 2551 | } |
| 2552 | |
Craig Mautner | 8d341ef | 2013-03-26 09:03:27 -0700 | [diff] [blame] | 2553 | void handleAppCrashLocked(ProcessRecord app) { |
Craig Mautner | e0a3884 | 2013-12-16 16:14:02 -0800 | [diff] [blame] | 2554 | for (int displayNdx = mActivityDisplays.size() - 1; displayNdx >= 0; --displayNdx) { |
| 2555 | final ArrayList<ActivityStack> stacks = mActivityDisplays.valueAt(displayNdx).mStacks; |
Wale Ogunwale | 28b2397 | 2015-07-29 16:01:50 -0700 | [diff] [blame] | 2556 | int stackNdx = stacks.size() - 1; |
| 2557 | while (stackNdx >= 0) { |
| 2558 | stacks.get(stackNdx).handleAppCrashLocked(app); |
| 2559 | stackNdx--; |
Craig Mautner | 4a1cb22 | 2013-12-04 16:14:06 -0800 | [diff] [blame] | 2560 | } |
Craig Mautner | 8d341ef | 2013-03-26 09:03:27 -0700 | [diff] [blame] | 2561 | } |
| 2562 | } |
| 2563 | |
Jose Lima | 4b6c669 | 2014-08-12 17:41:12 -0700 | [diff] [blame] | 2564 | boolean requestVisibleBehindLocked(ActivityRecord r, boolean visible) { |
Craig Mautner | ee2e45a | 2014-06-27 12:10:03 -0700 | [diff] [blame] | 2565 | final ActivityStack stack = r.task.stack; |
| 2566 | if (stack == null) { |
Wale Ogunwale | 0fc365c | 2015-05-25 19:35:42 -0700 | [diff] [blame] | 2567 | if (DEBUG_VISIBLE_BEHIND) Slog.d(TAG_VISIBLE_BEHIND, |
| 2568 | "requestVisibleBehind: r=" + r + " visible=" + visible + " stack is null"); |
Craig Mautner | ee2e45a | 2014-06-27 12:10:03 -0700 | [diff] [blame] | 2569 | return false; |
| 2570 | } |
Jose Lima | 4b6c669 | 2014-08-12 17:41:12 -0700 | [diff] [blame] | 2571 | final boolean isVisible = stack.hasVisibleBehindActivity(); |
Wale Ogunwale | 0fc365c | 2015-05-25 19:35:42 -0700 | [diff] [blame] | 2572 | if (DEBUG_VISIBLE_BEHIND) Slog.d(TAG_VISIBLE_BEHIND, |
| 2573 | "requestVisibleBehind r=" + r + " visible=" + visible + " isVisible=" + isVisible); |
Craig Mautner | ee2e45a | 2014-06-27 12:10:03 -0700 | [diff] [blame] | 2574 | |
| 2575 | final ActivityRecord top = topRunningActivityLocked(); |
Jose Lima | 4b6c669 | 2014-08-12 17:41:12 -0700 | [diff] [blame] | 2576 | if (top == null || top == r || (visible == isVisible)) { |
Wale Ogunwale | 0fc365c | 2015-05-25 19:35:42 -0700 | [diff] [blame] | 2577 | if (DEBUG_VISIBLE_BEHIND) Slog.d(TAG_VISIBLE_BEHIND, "requestVisibleBehind: quick return"); |
Jose Lima | 4b6c669 | 2014-08-12 17:41:12 -0700 | [diff] [blame] | 2578 | stack.setVisibleBehindActivity(visible ? r : null); |
Craig Mautner | ee2e45a | 2014-06-27 12:10:03 -0700 | [diff] [blame] | 2579 | return true; |
| 2580 | } |
| 2581 | |
| 2582 | // A non-top activity is reporting a visibility change. |
Craig Mautner | aea5ced | 2014-09-07 17:08:39 -0700 | [diff] [blame] | 2583 | if (visible && top.fullscreen) { |
| 2584 | // Let the caller know that it can't be seen. |
Wale Ogunwale | 0fc365c | 2015-05-25 19:35:42 -0700 | [diff] [blame] | 2585 | if (DEBUG_VISIBLE_BEHIND) Slog.d(TAG_VISIBLE_BEHIND, |
| 2586 | "requestVisibleBehind: returning top.fullscreen=" + top.fullscreen |
| 2587 | + " top.state=" + top.state + " top.app=" + top.app + " top.app.thread=" |
| 2588 | + top.app.thread); |
Craig Mautner | ee2e45a | 2014-06-27 12:10:03 -0700 | [diff] [blame] | 2589 | return false; |
Jose Lima | 34ff492 | 2014-08-18 15:19:41 -0700 | [diff] [blame] | 2590 | } else if (!visible && stack.getVisibleBehindActivity() != r) { |
| 2591 | // Only the activity set as currently visible behind should actively reset its |
| 2592 | // visible behind state. |
Wale Ogunwale | 0fc365c | 2015-05-25 19:35:42 -0700 | [diff] [blame] | 2593 | if (DEBUG_VISIBLE_BEHIND) Slog.d(TAG_VISIBLE_BEHIND, |
| 2594 | "requestVisibleBehind: returning visible=" + visible |
| 2595 | + " stack.getVisibleBehindActivity()=" + stack.getVisibleBehindActivity() |
| 2596 | + " r=" + r); |
Jose Lima | 34ff492 | 2014-08-18 15:19:41 -0700 | [diff] [blame] | 2597 | return false; |
Craig Mautner | ee2e45a | 2014-06-27 12:10:03 -0700 | [diff] [blame] | 2598 | } |
| 2599 | |
Jose Lima | 4b6c669 | 2014-08-12 17:41:12 -0700 | [diff] [blame] | 2600 | stack.setVisibleBehindActivity(visible ? r : null); |
| 2601 | if (!visible) { |
Filip Gruszczynski | 62c5e9d | 2016-02-04 11:06:54 -0800 | [diff] [blame] | 2602 | // If there is a translucent home activity, we need to force it stop being translucent, |
| 2603 | // because we can't depend on the application to necessarily perform that operation. |
| 2604 | // Check out b/14469711 for details. |
Craig Mautner | fa387ad | 2014-08-05 11:16:41 -0700 | [diff] [blame] | 2605 | final ActivityRecord next = stack.findNextTranslucentActivity(r); |
Filip Gruszczynski | 62c5e9d | 2016-02-04 11:06:54 -0800 | [diff] [blame] | 2606 | if (next != null && next.isHomeActivity()) { |
Craig Mautner | fa387ad | 2014-08-05 11:16:41 -0700 | [diff] [blame] | 2607 | mService.convertFromTranslucent(next.appToken); |
| 2608 | } |
| 2609 | } |
Craig Mautner | aea5ced | 2014-09-07 17:08:39 -0700 | [diff] [blame] | 2610 | if (top.app != null && top.app.thread != null) { |
| 2611 | // Notify the top app of the change. |
| 2612 | try { |
| 2613 | top.app.thread.scheduleBackgroundVisibleBehindChanged(top.appToken, visible); |
| 2614 | } catch (RemoteException e) { |
| 2615 | } |
Craig Mautner | ee2e45a | 2014-06-27 12:10:03 -0700 | [diff] [blame] | 2616 | } |
| 2617 | return true; |
| 2618 | } |
| 2619 | |
Craig Mautner | bb74246 | 2014-07-07 15:28:55 -0700 | [diff] [blame] | 2620 | // Called when WindowManager has finished animating the launchingBehind activity to the back. |
| 2621 | void handleLaunchTaskBehindCompleteLocked(ActivityRecord r) { |
| 2622 | r.mLaunchTaskBehind = false; |
| 2623 | final TaskRecord task = r.task; |
Winson | 8b1871d | 2015-11-20 09:56:20 -0800 | [diff] [blame] | 2624 | task.setLastThumbnailLocked(task.stack.screenshotActivitiesLocked(r)); |
Wale Ogunwale | c82f2f5 | 2014-12-09 09:32:50 -0800 | [diff] [blame] | 2625 | mRecentTasks.addLocked(task); |
Winson Chung | 740c3ac | 2014-11-12 16:14:38 -0800 | [diff] [blame] | 2626 | mService.notifyTaskStackChangedLocked(); |
Craig Mautner | bb74246 | 2014-07-07 15:28:55 -0700 | [diff] [blame] | 2627 | mWindowManager.setAppVisibility(r.appToken, false); |
| 2628 | } |
| 2629 | |
| 2630 | void scheduleLaunchTaskBehindComplete(IBinder token) { |
| 2631 | mHandler.obtainMessage(LAUNCH_TASK_BEHIND_COMPLETE, token).sendToTarget(); |
| 2632 | } |
| 2633 | |
Filip Gruszczynski | bc5a6c5 | 2015-09-22 13:13:24 -0700 | [diff] [blame] | 2634 | void ensureActivitiesVisibleLocked(ActivityRecord starting, int configChanges, |
| 2635 | boolean preserveWindows) { |
Craig Mautner | 580ea81 | 2013-04-25 12:58:38 -0700 | [diff] [blame] | 2636 | // First the front stacks. In case any are not fullscreen and are in front of home. |
Craig Mautner | e0a3884 | 2013-12-16 16:14:02 -0800 | [diff] [blame] | 2637 | for (int displayNdx = mActivityDisplays.size() - 1; displayNdx >= 0; --displayNdx) { |
| 2638 | final ArrayList<ActivityStack> stacks = mActivityDisplays.valueAt(displayNdx).mStacks; |
Craig Mautner | 4a1cb22 | 2013-12-04 16:14:06 -0800 | [diff] [blame] | 2639 | final int topStackNdx = stacks.size() - 1; |
| 2640 | for (int stackNdx = topStackNdx; stackNdx >= 0; --stackNdx) { |
| 2641 | final ActivityStack stack = stacks.get(stackNdx); |
Filip Gruszczynski | bc5a6c5 | 2015-09-22 13:13:24 -0700 | [diff] [blame] | 2642 | stack.ensureActivitiesVisibleLocked(starting, configChanges, preserveWindows); |
Craig Mautner | 580ea81 | 2013-04-25 12:58:38 -0700 | [diff] [blame] | 2643 | } |
Craig Mautner | 8d341ef | 2013-03-26 09:03:27 -0700 | [diff] [blame] | 2644 | } |
Craig Mautner | 8d341ef | 2013-03-26 09:03:27 -0700 | [diff] [blame] | 2645 | } |
| 2646 | |
Chong Zhang | fdcc4d4 | 2015-10-14 16:50:12 -0700 | [diff] [blame] | 2647 | void invalidateTaskLayers() { |
| 2648 | mTaskLayersChanged = true; |
| 2649 | } |
| 2650 | |
| 2651 | void rankTaskLayersIfNeeded() { |
| 2652 | if (!mTaskLayersChanged) { |
| 2653 | return; |
| 2654 | } |
| 2655 | mTaskLayersChanged = false; |
| 2656 | for (int displayNdx = 0; displayNdx < mActivityDisplays.size(); displayNdx++) { |
| 2657 | final ArrayList<ActivityStack> stacks = mActivityDisplays.valueAt(displayNdx).mStacks; |
| 2658 | int baseLayer = 0; |
| 2659 | for (int stackNdx = stacks.size() - 1; stackNdx >= 0; --stackNdx) { |
| 2660 | baseLayer += stacks.get(stackNdx).rankTaskLayers(baseLayer); |
| 2661 | } |
| 2662 | } |
| 2663 | } |
| 2664 | |
Dianne Hackborn | b5a380d | 2015-05-20 18:18:46 -0700 | [diff] [blame] | 2665 | void clearOtherAppTimeTrackers(AppTimeTracker except) { |
| 2666 | for (int displayNdx = mActivityDisplays.size() - 1; displayNdx >= 0; --displayNdx) { |
| 2667 | final ArrayList<ActivityStack> stacks = mActivityDisplays.valueAt(displayNdx).mStacks; |
| 2668 | final int topStackNdx = stacks.size() - 1; |
| 2669 | for (int stackNdx = topStackNdx; stackNdx >= 0; --stackNdx) { |
| 2670 | final ActivityStack stack = stacks.get(stackNdx); |
| 2671 | stack.clearOtherAppTimeTrackers(except); |
| 2672 | } |
| 2673 | } |
| 2674 | } |
| 2675 | |
Craig Mautner | 8d341ef | 2013-03-26 09:03:27 -0700 | [diff] [blame] | 2676 | void scheduleDestroyAllActivities(ProcessRecord app, String reason) { |
Craig Mautner | e0a3884 | 2013-12-16 16:14:02 -0800 | [diff] [blame] | 2677 | for (int displayNdx = mActivityDisplays.size() - 1; displayNdx >= 0; --displayNdx) { |
| 2678 | final ArrayList<ActivityStack> stacks = mActivityDisplays.valueAt(displayNdx).mStacks; |
Craig Mautner | 4a1cb22 | 2013-12-04 16:14:06 -0800 | [diff] [blame] | 2679 | final int numStacks = stacks.size(); |
| 2680 | for (int stackNdx = 0; stackNdx < numStacks; ++stackNdx) { |
| 2681 | final ActivityStack stack = stacks.get(stackNdx); |
Craig Mautner | ee2e45a | 2014-06-27 12:10:03 -0700 | [diff] [blame] | 2682 | stack.scheduleDestroyActivities(app, reason); |
Craig Mautner | 4a1cb22 | 2013-12-04 16:14:06 -0800 | [diff] [blame] | 2683 | } |
Craig Mautner | 8d341ef | 2013-03-26 09:03:27 -0700 | [diff] [blame] | 2684 | } |
| 2685 | } |
| 2686 | |
Dianne Hackborn | 89ad456 | 2014-08-24 16:45:38 -0700 | [diff] [blame] | 2687 | void releaseSomeActivitiesLocked(ProcessRecord app, String reason) { |
| 2688 | // Examine all activities currently running in the process. |
| 2689 | TaskRecord firstTask = null; |
| 2690 | // Tasks is non-null only if two or more tasks are found. |
| 2691 | ArraySet<TaskRecord> tasks = null; |
Wale Ogunwale | 0fc365c | 2015-05-25 19:35:42 -0700 | [diff] [blame] | 2692 | if (DEBUG_RELEASE) Slog.d(TAG_RELEASE, "Trying to release some activities in " + app); |
| 2693 | for (int i = 0; i < app.activities.size(); i++) { |
Dianne Hackborn | 89ad456 | 2014-08-24 16:45:38 -0700 | [diff] [blame] | 2694 | ActivityRecord r = app.activities.get(i); |
| 2695 | // First, if we find an activity that is in the process of being destroyed, |
| 2696 | // then we just aren't going to do anything for now; we want things to settle |
| 2697 | // down before we try to prune more activities. |
Wale Ogunwale | ee006da | 2015-03-30 14:49:25 -0700 | [diff] [blame] | 2698 | if (r.finishing || r.state == DESTROYING || r.state == DESTROYED) { |
Wale Ogunwale | 0fc365c | 2015-05-25 19:35:42 -0700 | [diff] [blame] | 2699 | if (DEBUG_RELEASE) Slog.d(TAG_RELEASE, "Abort release; already destroying: " + r); |
Dianne Hackborn | 89ad456 | 2014-08-24 16:45:38 -0700 | [diff] [blame] | 2700 | return; |
| 2701 | } |
| 2702 | // Don't consider any activies that are currently not in a state where they |
| 2703 | // can be destroyed. |
Wale Ogunwale | ee006da | 2015-03-30 14:49:25 -0700 | [diff] [blame] | 2704 | if (r.visible || !r.stopped || !r.haveState || r.state == RESUMED || r.state == PAUSING |
| 2705 | || r.state == PAUSED || r.state == STOPPING) { |
Wale Ogunwale | 0fc365c | 2015-05-25 19:35:42 -0700 | [diff] [blame] | 2706 | 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] | 2707 | continue; |
| 2708 | } |
| 2709 | if (r.task != null) { |
Wale Ogunwale | 0fc365c | 2015-05-25 19:35:42 -0700 | [diff] [blame] | 2710 | if (DEBUG_RELEASE) Slog.d(TAG_RELEASE, "Collecting release task " + r.task |
Dianne Hackborn | 89ad456 | 2014-08-24 16:45:38 -0700 | [diff] [blame] | 2711 | + " from " + r); |
| 2712 | if (firstTask == null) { |
| 2713 | firstTask = r.task; |
| 2714 | } else if (firstTask != r.task) { |
| 2715 | if (tasks == null) { |
| 2716 | tasks = new ArraySet<>(); |
| 2717 | tasks.add(firstTask); |
| 2718 | } |
| 2719 | tasks.add(r.task); |
| 2720 | } |
| 2721 | } |
| 2722 | } |
| 2723 | if (tasks == null) { |
Wale Ogunwale | 0fc365c | 2015-05-25 19:35:42 -0700 | [diff] [blame] | 2724 | 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] | 2725 | return; |
| 2726 | } |
| 2727 | // If we have activities in multiple tasks that are in a position to be destroyed, |
| 2728 | // let's iterate through the tasks and release the oldest one. |
| 2729 | final int numDisplays = mActivityDisplays.size(); |
| 2730 | for (int displayNdx = 0; displayNdx < numDisplays; ++displayNdx) { |
| 2731 | final ArrayList<ActivityStack> stacks = mActivityDisplays.valueAt(displayNdx).mStacks; |
| 2732 | // Step through all stacks starting from behind, to hit the oldest things first. |
| 2733 | for (int stackNdx = 0; stackNdx < stacks.size(); stackNdx++) { |
| 2734 | final ActivityStack stack = stacks.get(stackNdx); |
| 2735 | // Try to release activities in this stack; if we manage to, we are done. |
| 2736 | if (stack.releaseSomeActivitiesLocked(app, tasks, reason) > 0) { |
| 2737 | return; |
| 2738 | } |
| 2739 | } |
| 2740 | } |
| 2741 | } |
| 2742 | |
Amith Yamasani | 37a40c2 | 2015-06-17 13:25:42 -0700 | [diff] [blame] | 2743 | boolean switchUserLocked(int userId, UserState uss) { |
Wale Ogunwale | d697cea | 2015-02-20 17:19:49 -0800 | [diff] [blame] | 2744 | mUserStackInFront.put(mCurrentUser, mFocusedStack.getStackId()); |
Craig Mautner | 4f1df4f | 2013-10-15 15:44:14 -0700 | [diff] [blame] | 2745 | final int restoreStackId = mUserStackInFront.get(userId, HOME_STACK_ID); |
Craig Mautner | 2420ead | 2013-04-01 17:13:20 -0700 | [diff] [blame] | 2746 | mCurrentUser = userId; |
Craig Mautner | ac6f843 | 2013-07-17 13:24:59 -0700 | [diff] [blame] | 2747 | |
Craig Mautner | 858d8a6 | 2013-04-23 17:08:34 -0700 | [diff] [blame] | 2748 | mStartingUsers.add(uss); |
Craig Mautner | e0a3884 | 2013-12-16 16:14:02 -0800 | [diff] [blame] | 2749 | for (int displayNdx = mActivityDisplays.size() - 1; displayNdx >= 0; --displayNdx) { |
| 2750 | final ArrayList<ActivityStack> stacks = mActivityDisplays.valueAt(displayNdx).mStacks; |
Craig Mautner | 4a1cb22 | 2013-12-04 16:14:06 -0800 | [diff] [blame] | 2751 | for (int stackNdx = stacks.size() - 1; stackNdx >= 0; --stackNdx) { |
Craig Mautner | e0a3884 | 2013-12-16 16:14:02 -0800 | [diff] [blame] | 2752 | final ActivityStack stack = stacks.get(stackNdx); |
| 2753 | stack.switchUserLocked(userId); |
Alexandra Gherghina | dae57a1 | 2014-03-12 19:15:26 +0000 | [diff] [blame] | 2754 | TaskRecord task = stack.topTask(); |
| 2755 | if (task != null) { |
| 2756 | mWindowManager.moveTaskToTop(task.taskId); |
| 2757 | } |
Craig Mautner | 4a1cb22 | 2013-12-04 16:14:06 -0800 | [diff] [blame] | 2758 | } |
Craig Mautner | ac6f843 | 2013-07-17 13:24:59 -0700 | [diff] [blame] | 2759 | } |
Craig Mautner | 858d8a6 | 2013-04-23 17:08:34 -0700 | [diff] [blame] | 2760 | |
Craig Mautner | 4f1df4f | 2013-10-15 15:44:14 -0700 | [diff] [blame] | 2761 | ActivityStack stack = getStack(restoreStackId); |
| 2762 | if (stack == null) { |
| 2763 | stack = mHomeStack; |
| 2764 | } |
| 2765 | final boolean homeInFront = stack.isHomeStack(); |
Craig Mautner | e0a3884 | 2013-12-16 16:14:02 -0800 | [diff] [blame] | 2766 | if (stack.isOnHomeDisplay()) { |
Wale Ogunwale | 925d0d1 | 2015-09-23 15:40:07 -0700 | [diff] [blame] | 2767 | stack.moveToFront("switchUserOnHomeDisplay"); |
Craig Mautner | e0a3884 | 2013-12-16 16:14:02 -0800 | [diff] [blame] | 2768 | } else { |
| 2769 | // Stack was moved to another display while user was swapped out. |
Craig Mautner | 299f960 | 2015-01-26 09:47:33 -0800 | [diff] [blame] | 2770 | resumeHomeStackTask(HOME_ACTIVITY_TYPE, null, "switchUserOnOtherDisplay"); |
Craig Mautner | e0a3884 | 2013-12-16 16:14:02 -0800 | [diff] [blame] | 2771 | } |
Craig Mautner | 93529a4 | 2013-10-04 15:03:13 -0700 | [diff] [blame] | 2772 | return homeInFront; |
Craig Mautner | 2219a1b | 2013-03-25 09:44:30 -0700 | [diff] [blame] | 2773 | } |
| 2774 | |
Wale Ogunwale | 0bd2aa7 | 2015-04-16 13:50:44 -0700 | [diff] [blame] | 2775 | /** Checks whether the userid is a profile of the current user. */ |
| 2776 | boolean isCurrentProfileLocked(int userId) { |
| 2777 | if (userId == mCurrentUser) return true; |
Fyodor Kupolov | 610acda | 2015-10-19 18:44:07 -0700 | [diff] [blame] | 2778 | return mService.mUserController.isCurrentProfileLocked(userId); |
Wale Ogunwale | 0bd2aa7 | 2015-04-16 13:50:44 -0700 | [diff] [blame] | 2779 | } |
| 2780 | |
Chong Zhang | 45c25ce | 2015-08-10 22:18:26 -0700 | [diff] [blame] | 2781 | /** Checks whether the activity should be shown for current user. */ |
| 2782 | boolean okToShowLocked(ActivityRecord r) { |
| 2783 | return r != null && (isCurrentProfileLocked(r.userId) |
| 2784 | || (r.info.flags & FLAG_SHOW_FOR_ALL_USERS) != 0); |
| 2785 | } |
| 2786 | |
Craig Mautner | de4ef02 | 2013-04-07 19:01:33 -0700 | [diff] [blame] | 2787 | final ArrayList<ActivityRecord> processStoppingActivitiesLocked(boolean remove) { |
Craig Mautner | de4ef02 | 2013-04-07 19:01:33 -0700 | [diff] [blame] | 2788 | ArrayList<ActivityRecord> stops = null; |
| 2789 | |
| 2790 | final boolean nowVisible = allResumedActivitiesVisible(); |
Craig Mautner | 8c14c15 | 2015-01-15 17:32:07 -0800 | [diff] [blame] | 2791 | for (int activityNdx = mStoppingActivities.size() - 1; activityNdx >= 0; --activityNdx) { |
| 2792 | ActivityRecord s = mStoppingActivities.get(activityNdx); |
| 2793 | final boolean waitingVisible = mWaitingVisibleActivities.contains(s); |
Wale Ogunwale | f81c1d1 | 2016-01-12 12:20:18 -0800 | [diff] [blame] | 2794 | if (DEBUG_STATES) Slog.v(TAG, "Stopping " + s + ": nowVisible=" + nowVisible |
Craig Mautner | 8c14c15 | 2015-01-15 17:32:07 -0800 | [diff] [blame] | 2795 | + " waitingVisible=" + waitingVisible + " finishing=" + s.finishing); |
| 2796 | if (waitingVisible && nowVisible) { |
Craig Mautner | de4ef02 | 2013-04-07 19:01:33 -0700 | [diff] [blame] | 2797 | mWaitingVisibleActivities.remove(s); |
Craig Mautner | de4ef02 | 2013-04-07 19:01:33 -0700 | [diff] [blame] | 2798 | if (s.finishing) { |
| 2799 | // If this activity is finishing, it is sitting on top of |
| 2800 | // everyone else but we now know it is no longer needed... |
| 2801 | // so get rid of it. Otherwise, we need to go through the |
| 2802 | // normal flow and hide it once we determine that it is |
| 2803 | // hidden by the activities in front of it. |
Wale Ogunwale | f81c1d1 | 2016-01-12 12:20:18 -0800 | [diff] [blame] | 2804 | if (DEBUG_STATES) Slog.v(TAG, "Before stopping, can hide: " + s); |
Craig Mautner | ce5f3cb | 2013-04-22 08:58:54 -0700 | [diff] [blame] | 2805 | mWindowManager.setAppVisibility(s.appToken, false); |
Craig Mautner | de4ef02 | 2013-04-07 19:01:33 -0700 | [diff] [blame] | 2806 | } |
| 2807 | } |
Craig Mautner | 8c14c15 | 2015-01-15 17:32:07 -0800 | [diff] [blame] | 2808 | if ((!waitingVisible || mService.isSleepingOrShuttingDown()) && remove) { |
Wale Ogunwale | f81c1d1 | 2016-01-12 12:20:18 -0800 | [diff] [blame] | 2809 | if (DEBUG_STATES) Slog.v(TAG, "Ready to stop: " + s); |
Craig Mautner | de4ef02 | 2013-04-07 19:01:33 -0700 | [diff] [blame] | 2810 | if (stops == null) { |
Craig Mautner | 8c14c15 | 2015-01-15 17:32:07 -0800 | [diff] [blame] | 2811 | stops = new ArrayList<>(); |
Craig Mautner | de4ef02 | 2013-04-07 19:01:33 -0700 | [diff] [blame] | 2812 | } |
| 2813 | stops.add(s); |
Craig Mautner | 8c14c15 | 2015-01-15 17:32:07 -0800 | [diff] [blame] | 2814 | mStoppingActivities.remove(activityNdx); |
Craig Mautner | de4ef02 | 2013-04-07 19:01:33 -0700 | [diff] [blame] | 2815 | } |
| 2816 | } |
| 2817 | |
| 2818 | return stops; |
| 2819 | } |
| 2820 | |
Craig Mautner | cf910b0 | 2013-04-23 11:23:27 -0700 | [diff] [blame] | 2821 | void validateTopActivitiesLocked() { |
Wale Ogunwale | ee006da | 2015-03-30 14:49:25 -0700 | [diff] [blame] | 2822 | for (int displayNdx = mActivityDisplays.size() - 1; displayNdx >= 0; --displayNdx) { |
| 2823 | final ArrayList<ActivityStack> stacks = mActivityDisplays.valueAt(displayNdx).mStacks; |
| 2824 | for (int stackNdx = stacks.size() - 1; stackNdx >= 0; --stackNdx) { |
| 2825 | final ActivityStack stack = stacks.get(stackNdx); |
Filip Gruszczynski | 3e85ba2 | 2015-10-05 22:48:30 -0700 | [diff] [blame] | 2826 | final ActivityRecord r = stack.topRunningActivityLocked(); |
Wale Ogunwale | ee006da | 2015-03-30 14:49:25 -0700 | [diff] [blame] | 2827 | final ActivityState state = r == null ? DESTROYED : r.state; |
Wale Ogunwale | 1e60e0c | 2015-10-28 13:36:10 -0700 | [diff] [blame] | 2828 | if (isFocusedStack(stack)) { |
Wale Ogunwale | ee006da | 2015-03-30 14:49:25 -0700 | [diff] [blame] | 2829 | if (r == null) Slog.e(TAG, |
| 2830 | "validateTop...: null top activity, stack=" + stack); |
| 2831 | else { |
| 2832 | final ActivityRecord pausing = stack.mPausingActivity; |
| 2833 | if (pausing != null && pausing == r) Slog.e(TAG, |
| 2834 | "validateTop...: top stack has pausing activity r=" + r |
| 2835 | + " state=" + state); |
| 2836 | if (state != INITIALIZING && state != RESUMED) Slog.e(TAG, |
| 2837 | "validateTop...: activity in front not resumed r=" + r |
| 2838 | + " state=" + state); |
| 2839 | } |
Craig Mautner | cf910b0 | 2013-04-23 11:23:27 -0700 | [diff] [blame] | 2840 | } else { |
Wale Ogunwale | ee006da | 2015-03-30 14:49:25 -0700 | [diff] [blame] | 2841 | final ActivityRecord resumed = stack.mResumedActivity; |
| 2842 | if (resumed != null && resumed == r) Slog.e(TAG, |
| 2843 | "validateTop...: back stack has resumed activity r=" + r |
| 2844 | + " state=" + state); |
| 2845 | if (r != null && (state == INITIALIZING || state == RESUMED)) Slog.e(TAG, |
| 2846 | "validateTop...: activity in back resumed r=" + r + " state=" + state); |
Craig Mautner | cf910b0 | 2013-04-23 11:23:27 -0700 | [diff] [blame] | 2847 | } |
| 2848 | } |
| 2849 | } |
Craig Mautner | 76ea224 | 2013-05-15 11:40:05 -0700 | [diff] [blame] | 2850 | } |
| 2851 | |
Craig Mautner | e057020 | 2015-05-13 13:06:11 -0700 | [diff] [blame] | 2852 | private String lockTaskModeToString() { |
| 2853 | switch (mLockTaskModeState) { |
| 2854 | case LOCK_TASK_MODE_LOCKED: |
| 2855 | return "LOCKED"; |
| 2856 | case LOCK_TASK_MODE_PINNED: |
| 2857 | return "PINNED"; |
| 2858 | case LOCK_TASK_MODE_NONE: |
| 2859 | return "NONE"; |
| 2860 | default: return "unknown=" + mLockTaskModeState; |
| 2861 | } |
| 2862 | } |
| 2863 | |
Craig Mautner | 2708430 | 2013-03-25 08:05:25 -0700 | [diff] [blame] | 2864 | public void dump(PrintWriter pw, String prefix) { |
Craig Mautner | d1bbdb462 | 2013-10-22 09:53:20 -0700 | [diff] [blame] | 2865 | pw.print(prefix); pw.print("mFocusedStack=" + mFocusedStack); |
Craig Mautner | 4a1cb22 | 2013-12-04 16:14:06 -0800 | [diff] [blame] | 2866 | pw.print(" mLastFocusedStack="); pw.println(mLastFocusedStack); |
Craig Mautner | d1bbdb462 | 2013-10-22 09:53:20 -0700 | [diff] [blame] | 2867 | pw.print(prefix); pw.println("mSleepTimeout=" + mSleepTimeout); |
Suprabh Shukla | 09a88f5 | 2015-12-02 14:36:31 -0800 | [diff] [blame] | 2868 | pw.print(prefix); |
| 2869 | pw.println("mCurTaskIdForUser=" + mCurTaskIdForUser); |
Craig Mautner | d1bbdb462 | 2013-10-22 09:53:20 -0700 | [diff] [blame] | 2870 | pw.print(prefix); pw.println("mUserStackInFront=" + mUserStackInFront); |
Craig Mautner | 95da108 | 2014-02-24 17:54:35 -0800 | [diff] [blame] | 2871 | pw.print(prefix); pw.println("mActivityContainers=" + mActivityContainers); |
Craig Mautner | e057020 | 2015-05-13 13:06:11 -0700 | [diff] [blame] | 2872 | pw.print(prefix); pw.print("mLockTaskModeState=" + lockTaskModeToString()); |
| 2873 | final SparseArray<String[]> packages = mService.mLockTaskPackages; |
| 2874 | if (packages.size() > 0) { |
| 2875 | pw.println(" mLockTaskPackages (userId:packages)="); |
| 2876 | for (int i = 0; i < packages.size(); ++i) { |
| 2877 | pw.print(prefix); pw.print(prefix); pw.print(packages.keyAt(i)); |
| 2878 | pw.print(":"); pw.println(Arrays.toString(packages.valueAt(i))); |
| 2879 | } |
| 2880 | } |
| 2881 | pw.println(" mLockTaskModeTasks" + mLockTaskModeTasks); |
Craig Mautner | 2708430 | 2013-03-25 08:05:25 -0700 | [diff] [blame] | 2882 | } |
Craig Mautner | 8d341ef | 2013-03-26 09:03:27 -0700 | [diff] [blame] | 2883 | |
Craig Mautner | 20e7227 | 2013-04-01 13:45:53 -0700 | [diff] [blame] | 2884 | ArrayList<ActivityRecord> getDumpActivitiesLocked(String name) { |
Wale Ogunwale | d697cea | 2015-02-20 17:19:49 -0800 | [diff] [blame] | 2885 | return mFocusedStack.getDumpActivitiesLocked(name); |
Craig Mautner | 20e7227 | 2013-04-01 13:45:53 -0700 | [diff] [blame] | 2886 | } |
| 2887 | |
Dianne Hackborn | 390517b | 2013-05-30 15:03:32 -0700 | [diff] [blame] | 2888 | static boolean printThisActivity(PrintWriter pw, ActivityRecord activity, String dumpPackage, |
| 2889 | boolean needSep, String prefix) { |
| 2890 | if (activity != null) { |
| 2891 | if (dumpPackage == null || dumpPackage.equals(activity.packageName)) { |
| 2892 | if (needSep) { |
| 2893 | pw.println(); |
Dianne Hackborn | 390517b | 2013-05-30 15:03:32 -0700 | [diff] [blame] | 2894 | } |
| 2895 | pw.print(prefix); |
| 2896 | pw.println(activity); |
Dianne Hackborn | 7ad34e5 | 2013-06-05 18:41:45 -0700 | [diff] [blame] | 2897 | return true; |
Dianne Hackborn | 390517b | 2013-05-30 15:03:32 -0700 | [diff] [blame] | 2898 | } |
| 2899 | } |
Dianne Hackborn | 7ad34e5 | 2013-06-05 18:41:45 -0700 | [diff] [blame] | 2900 | return false; |
Dianne Hackborn | 390517b | 2013-05-30 15:03:32 -0700 | [diff] [blame] | 2901 | } |
| 2902 | |
Craig Mautner | 8d341ef | 2013-03-26 09:03:27 -0700 | [diff] [blame] | 2903 | boolean dumpActivitiesLocked(FileDescriptor fd, PrintWriter pw, boolean dumpAll, |
| 2904 | boolean dumpClient, String dumpPackage) { |
Dianne Hackborn | 7ad34e5 | 2013-06-05 18:41:45 -0700 | [diff] [blame] | 2905 | boolean printed = false; |
| 2906 | boolean needSep = false; |
Craig Mautner | e0a3884 | 2013-12-16 16:14:02 -0800 | [diff] [blame] | 2907 | for (int displayNdx = 0; displayNdx < mActivityDisplays.size(); ++displayNdx) { |
| 2908 | ActivityDisplay activityDisplay = mActivityDisplays.valueAt(displayNdx); |
Craig Mautner | ee2e45a | 2014-06-27 12:10:03 -0700 | [diff] [blame] | 2909 | pw.print("Display #"); pw.print(activityDisplay.mDisplayId); |
Craig Mautner | 737fae2 | 2014-10-15 12:52:10 -0700 | [diff] [blame] | 2910 | pw.println(" (activities from top to bottom):"); |
Craig Mautner | e0a3884 | 2013-12-16 16:14:02 -0800 | [diff] [blame] | 2911 | ArrayList<ActivityStack> stacks = activityDisplay.mStacks; |
Craig Mautner | 737fae2 | 2014-10-15 12:52:10 -0700 | [diff] [blame] | 2912 | for (int stackNdx = stacks.size() - 1; stackNdx >= 0; --stackNdx) { |
Craig Mautner | 4a1cb22 | 2013-12-04 16:14:06 -0800 | [diff] [blame] | 2913 | final ActivityStack stack = stacks.get(stackNdx); |
| 2914 | StringBuilder stackHeader = new StringBuilder(128); |
| 2915 | stackHeader.append(" Stack #"); |
| 2916 | stackHeader.append(stack.mStackId); |
| 2917 | stackHeader.append(":"); |
Wale Ogunwale | b34a7ad | 2015-08-14 11:05:30 -0700 | [diff] [blame] | 2918 | stackHeader.append("\n"); |
| 2919 | stackHeader.append(" mFullscreen=" + stack.mFullscreen); |
| 2920 | stackHeader.append("\n"); |
| 2921 | stackHeader.append(" mBounds=" + stack.mBounds); |
Craig Mautner | 4a1cb22 | 2013-12-04 16:14:06 -0800 | [diff] [blame] | 2922 | printed |= stack.dumpActivitiesLocked(fd, pw, dumpAll, dumpClient, dumpPackage, |
| 2923 | needSep, stackHeader.toString()); |
| 2924 | printed |= dumpHistoryList(fd, pw, stack.mLRUActivities, " ", "Run", false, |
| 2925 | !dumpAll, false, dumpPackage, true, |
| 2926 | " Running activities (most recent first):", null); |
Craig Mautner | 8d341ef | 2013-03-26 09:03:27 -0700 | [diff] [blame] | 2927 | |
Craig Mautner | 4a1cb22 | 2013-12-04 16:14:06 -0800 | [diff] [blame] | 2928 | needSep = printed; |
| 2929 | boolean pr = printThisActivity(pw, stack.mPausingActivity, dumpPackage, needSep, |
| 2930 | " mPausingActivity: "); |
Dianne Hackborn | 7ad34e5 | 2013-06-05 18:41:45 -0700 | [diff] [blame] | 2931 | if (pr) { |
| 2932 | printed = true; |
Craig Mautner | 4a1cb22 | 2013-12-04 16:14:06 -0800 | [diff] [blame] | 2933 | needSep = false; |
Dianne Hackborn | 7ad34e5 | 2013-06-05 18:41:45 -0700 | [diff] [blame] | 2934 | } |
Craig Mautner | 4a1cb22 | 2013-12-04 16:14:06 -0800 | [diff] [blame] | 2935 | pr = printThisActivity(pw, stack.mResumedActivity, dumpPackage, needSep, |
| 2936 | " mResumedActivity: "); |
| 2937 | if (pr) { |
| 2938 | printed = true; |
| 2939 | needSep = false; |
| 2940 | } |
| 2941 | if (dumpAll) { |
| 2942 | pr = printThisActivity(pw, stack.mLastPausedActivity, dumpPackage, needSep, |
| 2943 | " mLastPausedActivity: "); |
| 2944 | if (pr) { |
| 2945 | printed = true; |
| 2946 | needSep = true; |
| 2947 | } |
| 2948 | printed |= printThisActivity(pw, stack.mLastNoHistoryActivity, dumpPackage, |
| 2949 | needSep, " mLastNoHistoryActivity: "); |
| 2950 | } |
| 2951 | needSep = printed; |
Craig Mautner | 8d341ef | 2013-03-26 09:03:27 -0700 | [diff] [blame] | 2952 | } |
| 2953 | } |
| 2954 | |
Dianne Hackborn | 7ad34e5 | 2013-06-05 18:41:45 -0700 | [diff] [blame] | 2955 | printed |= dumpHistoryList(fd, pw, mFinishingActivities, " ", "Fin", false, !dumpAll, |
| 2956 | false, dumpPackage, true, " Activities waiting to finish:", null); |
| 2957 | printed |= dumpHistoryList(fd, pw, mStoppingActivities, " ", "Stop", false, !dumpAll, |
| 2958 | false, dumpPackage, true, " Activities waiting to stop:", null); |
| 2959 | printed |= dumpHistoryList(fd, pw, mWaitingVisibleActivities, " ", "Wait", false, !dumpAll, |
| 2960 | false, dumpPackage, true, " Activities waiting for another to become visible:", |
| 2961 | null); |
| 2962 | printed |= dumpHistoryList(fd, pw, mGoingToSleepActivities, " ", "Sleep", false, !dumpAll, |
| 2963 | false, dumpPackage, true, " Activities waiting to sleep:", null); |
| 2964 | printed |= dumpHistoryList(fd, pw, mGoingToSleepActivities, " ", "Sleep", false, !dumpAll, |
| 2965 | false, dumpPackage, true, " Activities waiting to sleep:", null); |
Craig Mautner | f333327 | 2013-04-22 10:55:53 -0700 | [diff] [blame] | 2966 | |
Dianne Hackborn | 7ad34e5 | 2013-06-05 18:41:45 -0700 | [diff] [blame] | 2967 | return printed; |
Craig Mautner | 8d341ef | 2013-03-26 09:03:27 -0700 | [diff] [blame] | 2968 | } |
| 2969 | |
Dianne Hackborn | 390517b | 2013-05-30 15:03:32 -0700 | [diff] [blame] | 2970 | static boolean dumpHistoryList(FileDescriptor fd, PrintWriter pw, List<ActivityRecord> list, |
Craig Mautner | 8d341ef | 2013-03-26 09:03:27 -0700 | [diff] [blame] | 2971 | String prefix, String label, boolean complete, boolean brief, boolean client, |
Dianne Hackborn | 7ad34e5 | 2013-06-05 18:41:45 -0700 | [diff] [blame] | 2972 | String dumpPackage, boolean needNL, String header1, String header2) { |
Craig Mautner | 8d341ef | 2013-03-26 09:03:27 -0700 | [diff] [blame] | 2973 | TaskRecord lastTask = null; |
Dianne Hackborn | 390517b | 2013-05-30 15:03:32 -0700 | [diff] [blame] | 2974 | String innerPrefix = null; |
| 2975 | String[] args = null; |
| 2976 | boolean printed = false; |
Craig Mautner | 8d341ef | 2013-03-26 09:03:27 -0700 | [diff] [blame] | 2977 | for (int i=list.size()-1; i>=0; i--) { |
| 2978 | final ActivityRecord r = list.get(i); |
| 2979 | if (dumpPackage != null && !dumpPackage.equals(r.packageName)) { |
| 2980 | continue; |
| 2981 | } |
Dianne Hackborn | 390517b | 2013-05-30 15:03:32 -0700 | [diff] [blame] | 2982 | if (innerPrefix == null) { |
| 2983 | innerPrefix = prefix + " "; |
| 2984 | args = new String[0]; |
| 2985 | } |
| 2986 | printed = true; |
Craig Mautner | 8d341ef | 2013-03-26 09:03:27 -0700 | [diff] [blame] | 2987 | final boolean full = !brief && (complete || !r.isInHistory()); |
| 2988 | if (needNL) { |
Dianne Hackborn | 390517b | 2013-05-30 15:03:32 -0700 | [diff] [blame] | 2989 | pw.println(""); |
Craig Mautner | 8d341ef | 2013-03-26 09:03:27 -0700 | [diff] [blame] | 2990 | needNL = false; |
| 2991 | } |
Dianne Hackborn | 7ad34e5 | 2013-06-05 18:41:45 -0700 | [diff] [blame] | 2992 | if (header1 != null) { |
| 2993 | pw.println(header1); |
| 2994 | header1 = null; |
| 2995 | } |
| 2996 | if (header2 != null) { |
| 2997 | pw.println(header2); |
| 2998 | header2 = null; |
Dianne Hackborn | 390517b | 2013-05-30 15:03:32 -0700 | [diff] [blame] | 2999 | } |
Craig Mautner | 8d341ef | 2013-03-26 09:03:27 -0700 | [diff] [blame] | 3000 | if (lastTask != r.task) { |
| 3001 | lastTask = r.task; |
| 3002 | pw.print(prefix); |
| 3003 | pw.print(full ? "* " : " "); |
| 3004 | pw.println(lastTask); |
| 3005 | if (full) { |
| 3006 | lastTask.dump(pw, prefix + " "); |
| 3007 | } else if (complete) { |
| 3008 | // Complete + brief == give a summary. Isn't that obvious?!? |
| 3009 | if (lastTask.intent != null) { |
| 3010 | pw.print(prefix); pw.print(" "); |
| 3011 | pw.println(lastTask.intent.toInsecureStringWithClip()); |
| 3012 | } |
| 3013 | } |
| 3014 | } |
| 3015 | pw.print(prefix); pw.print(full ? " * " : " "); pw.print(label); |
| 3016 | pw.print(" #"); pw.print(i); pw.print(": "); |
| 3017 | pw.println(r); |
| 3018 | if (full) { |
| 3019 | r.dump(pw, innerPrefix); |
| 3020 | } else if (complete) { |
| 3021 | // Complete + brief == give a summary. Isn't that obvious?!? |
| 3022 | pw.print(innerPrefix); pw.println(r.intent.toInsecureString()); |
| 3023 | if (r.app != null) { |
| 3024 | pw.print(innerPrefix); pw.println(r.app); |
| 3025 | } |
| 3026 | } |
| 3027 | if (client && r.app != null && r.app.thread != null) { |
| 3028 | // flush anything that is already in the PrintWriter since the thread is going |
| 3029 | // to write to the file descriptor directly |
| 3030 | pw.flush(); |
| 3031 | try { |
| 3032 | TransferPipe tp = new TransferPipe(); |
| 3033 | try { |
| 3034 | r.app.thread.dumpActivity(tp.getWriteFd().getFileDescriptor(), |
| 3035 | r.appToken, innerPrefix, args); |
| 3036 | // Short timeout, since blocking here can |
| 3037 | // deadlock with the application. |
| 3038 | tp.go(fd, 2000); |
| 3039 | } finally { |
| 3040 | tp.kill(); |
| 3041 | } |
| 3042 | } catch (IOException e) { |
| 3043 | pw.println(innerPrefix + "Failure while dumping the activity: " + e); |
| 3044 | } catch (RemoteException e) { |
| 3045 | pw.println(innerPrefix + "Got a RemoteException while dumping the activity"); |
| 3046 | } |
| 3047 | needNL = true; |
| 3048 | } |
| 3049 | } |
Dianne Hackborn | 390517b | 2013-05-30 15:03:32 -0700 | [diff] [blame] | 3050 | return printed; |
Craig Mautner | 8d341ef | 2013-03-26 09:03:27 -0700 | [diff] [blame] | 3051 | } |
Craig Mautner | ce5f3cb | 2013-04-22 08:58:54 -0700 | [diff] [blame] | 3052 | |
Craig Mautner | f333327 | 2013-04-22 10:55:53 -0700 | [diff] [blame] | 3053 | void scheduleIdleTimeoutLocked(ActivityRecord next) { |
Wale Ogunwale | 0fc365c | 2015-05-25 19:35:42 -0700 | [diff] [blame] | 3054 | if (DEBUG_IDLE) Slog.d(TAG_IDLE, |
| 3055 | "scheduleIdleTimeoutLocked: Callers=" + Debug.getCallers(4)); |
Craig Mautner | c64f73e | 2013-04-24 16:44:56 -0700 | [diff] [blame] | 3056 | Message msg = mHandler.obtainMessage(IDLE_TIMEOUT_MSG, next); |
| 3057 | mHandler.sendMessageDelayed(msg, IDLE_TIMEOUT); |
Craig Mautner | f333327 | 2013-04-22 10:55:53 -0700 | [diff] [blame] | 3058 | } |
| 3059 | |
| 3060 | final void scheduleIdleLocked() { |
Craig Mautner | 05d2903 | 2013-05-03 13:40:13 -0700 | [diff] [blame] | 3061 | mHandler.sendEmptyMessage(IDLE_NOW_MSG); |
Craig Mautner | f333327 | 2013-04-22 10:55:53 -0700 | [diff] [blame] | 3062 | } |
| 3063 | |
| 3064 | void removeTimeoutsForActivityLocked(ActivityRecord r) { |
Wale Ogunwale | 0fc365c | 2015-05-25 19:35:42 -0700 | [diff] [blame] | 3065 | if (DEBUG_IDLE) Slog.d(TAG_IDLE, "removeTimeoutsForActivity: Callers=" |
| 3066 | + Debug.getCallers(4)); |
Craig Mautner | f333327 | 2013-04-22 10:55:53 -0700 | [diff] [blame] | 3067 | mHandler.removeMessages(IDLE_TIMEOUT_MSG, r); |
| 3068 | } |
| 3069 | |
Craig Mautner | 05d2903 | 2013-05-03 13:40:13 -0700 | [diff] [blame] | 3070 | final void scheduleResumeTopActivities() { |
Craig Mautner | 34b73df | 2014-01-12 21:11:08 -0800 | [diff] [blame] | 3071 | if (!mHandler.hasMessages(RESUME_TOP_ACTIVITY_MSG)) { |
| 3072 | mHandler.sendEmptyMessage(RESUME_TOP_ACTIVITY_MSG); |
| 3073 | } |
Craig Mautner | 05d2903 | 2013-05-03 13:40:13 -0700 | [diff] [blame] | 3074 | } |
| 3075 | |
Craig Mautner | 0eea92c | 2013-05-16 13:35:39 -0700 | [diff] [blame] | 3076 | void removeSleepTimeouts() { |
| 3077 | mSleepTimeout = false; |
| 3078 | mHandler.removeMessages(SLEEP_TIMEOUT_MSG); |
| 3079 | } |
| 3080 | |
| 3081 | final void scheduleSleepTimeout() { |
| 3082 | removeSleepTimeouts(); |
| 3083 | mHandler.sendEmptyMessageDelayed(SLEEP_TIMEOUT_MSG, SLEEP_TIMEOUT); |
| 3084 | } |
| 3085 | |
Craig Mautner | 4a1cb22 | 2013-12-04 16:14:06 -0800 | [diff] [blame] | 3086 | @Override |
| 3087 | public void onDisplayAdded(int displayId) { |
Dianne Hackborn | fb81d09 | 2015-08-03 17:14:46 -0700 | [diff] [blame] | 3088 | if (DEBUG_STACK) Slog.v(TAG, "Display added displayId=" + displayId); |
Craig Mautner | 4a1cb22 | 2013-12-04 16:14:06 -0800 | [diff] [blame] | 3089 | mHandler.sendMessage(mHandler.obtainMessage(HANDLE_DISPLAY_ADDED, displayId, 0)); |
| 3090 | } |
| 3091 | |
| 3092 | @Override |
| 3093 | public void onDisplayRemoved(int displayId) { |
Dianne Hackborn | fb81d09 | 2015-08-03 17:14:46 -0700 | [diff] [blame] | 3094 | if (DEBUG_STACK) Slog.v(TAG, "Display removed displayId=" + displayId); |
Craig Mautner | 4a1cb22 | 2013-12-04 16:14:06 -0800 | [diff] [blame] | 3095 | mHandler.sendMessage(mHandler.obtainMessage(HANDLE_DISPLAY_REMOVED, displayId, 0)); |
| 3096 | } |
| 3097 | |
| 3098 | @Override |
| 3099 | public void onDisplayChanged(int displayId) { |
Dianne Hackborn | fb81d09 | 2015-08-03 17:14:46 -0700 | [diff] [blame] | 3100 | if (DEBUG_STACK) Slog.v(TAG, "Display changed displayId=" + displayId); |
Craig Mautner | 4a1cb22 | 2013-12-04 16:14:06 -0800 | [diff] [blame] | 3101 | mHandler.sendMessage(mHandler.obtainMessage(HANDLE_DISPLAY_CHANGED, displayId, 0)); |
| 3102 | } |
| 3103 | |
Wale Ogunwale | f16a281 | 2015-04-01 11:23:15 -0700 | [diff] [blame] | 3104 | private void handleDisplayAdded(int displayId) { |
Craig Mautner | 4504de5 | 2013-12-20 09:06:56 -0800 | [diff] [blame] | 3105 | boolean newDisplay; |
Craig Mautner | 4a1cb22 | 2013-12-04 16:14:06 -0800 | [diff] [blame] | 3106 | synchronized (mService) { |
Craig Mautner | 4504de5 | 2013-12-20 09:06:56 -0800 | [diff] [blame] | 3107 | newDisplay = mActivityDisplays.get(displayId) == null; |
| 3108 | if (newDisplay) { |
| 3109 | ActivityDisplay activityDisplay = new ActivityDisplay(displayId); |
Craig Mautner | 1a70a16 | 2014-09-13 12:09:31 -0700 | [diff] [blame] | 3110 | if (activityDisplay.mDisplay == null) { |
| 3111 | Slog.w(TAG, "Display " + displayId + " gone before initialization complete"); |
| 3112 | return; |
| 3113 | } |
Craig Mautner | 4504de5 | 2013-12-20 09:06:56 -0800 | [diff] [blame] | 3114 | mActivityDisplays.put(displayId, activityDisplay); |
Filip Gruszczynski | d2f1d94 | 2015-10-14 15:10:12 -0700 | [diff] [blame] | 3115 | calculateDefaultMinimalSizeOfResizeableTasks(activityDisplay); |
Craig Mautner | 4504de5 | 2013-12-20 09:06:56 -0800 | [diff] [blame] | 3116 | } |
Craig Mautner | 4a1cb22 | 2013-12-04 16:14:06 -0800 | [diff] [blame] | 3117 | } |
Craig Mautner | 4504de5 | 2013-12-20 09:06:56 -0800 | [diff] [blame] | 3118 | if (newDisplay) { |
| 3119 | mWindowManager.onDisplayAdded(displayId); |
| 3120 | } |
Craig Mautner | 4a1cb22 | 2013-12-04 16:14:06 -0800 | [diff] [blame] | 3121 | } |
| 3122 | |
Filip Gruszczynski | d2f1d94 | 2015-10-14 15:10:12 -0700 | [diff] [blame] | 3123 | private void calculateDefaultMinimalSizeOfResizeableTasks(ActivityDisplay display) { |
| 3124 | if (display.mDisplayId != Display.DEFAULT_DISPLAY) { |
| 3125 | return; |
| 3126 | } |
| 3127 | final float fraction = mService.mContext.getResources().getFraction(com.android.internal.R. |
| 3128 | fraction.config_displayFractionForDefaultMinimalSizeOfResizeableTask, 1, 1); |
| 3129 | mDefaultMinimalSizeOfResizeableTask = (int) (fraction * Math.min( |
| 3130 | display.mDisplayInfo.logicalWidth, display.mDisplayInfo.logicalHeight)); |
| 3131 | } |
| 3132 | |
Wale Ogunwale | f16a281 | 2015-04-01 11:23:15 -0700 | [diff] [blame] | 3133 | private void handleDisplayRemoved(int displayId) { |
Craig Mautner | 4a1cb22 | 2013-12-04 16:14:06 -0800 | [diff] [blame] | 3134 | synchronized (mService) { |
Craig Mautner | e0a3884 | 2013-12-16 16:14:02 -0800 | [diff] [blame] | 3135 | ActivityDisplay activityDisplay = mActivityDisplays.get(displayId); |
| 3136 | if (activityDisplay != null) { |
| 3137 | ArrayList<ActivityStack> stacks = activityDisplay.mStacks; |
Craig Mautner | 4a1cb22 | 2013-12-04 16:14:06 -0800 | [diff] [blame] | 3138 | for (int stackNdx = stacks.size() - 1; stackNdx >= 0; --stackNdx) { |
Craig Mautner | 34b73df | 2014-01-12 21:11:08 -0800 | [diff] [blame] | 3139 | stacks.get(stackNdx).mActivityContainer.detachLocked(); |
Craig Mautner | 4a1cb22 | 2013-12-04 16:14:06 -0800 | [diff] [blame] | 3140 | } |
Craig Mautner | e0a3884 | 2013-12-16 16:14:02 -0800 | [diff] [blame] | 3141 | mActivityDisplays.remove(displayId); |
Craig Mautner | 4a1cb22 | 2013-12-04 16:14:06 -0800 | [diff] [blame] | 3142 | } |
| 3143 | } |
| 3144 | mWindowManager.onDisplayRemoved(displayId); |
| 3145 | } |
| 3146 | |
Wale Ogunwale | f16a281 | 2015-04-01 11:23:15 -0700 | [diff] [blame] | 3147 | private void handleDisplayChanged(int displayId) { |
Craig Mautner | 4a1cb22 | 2013-12-04 16:14:06 -0800 | [diff] [blame] | 3148 | synchronized (mService) { |
Craig Mautner | e0a3884 | 2013-12-16 16:14:02 -0800 | [diff] [blame] | 3149 | ActivityDisplay activityDisplay = mActivityDisplays.get(displayId); |
| 3150 | if (activityDisplay != null) { |
Craig Mautner | 4a1cb22 | 2013-12-04 16:14:06 -0800 | [diff] [blame] | 3151 | // TODO: Update the bounds. |
| 3152 | } |
| 3153 | } |
| 3154 | mWindowManager.onDisplayChanged(displayId); |
| 3155 | } |
| 3156 | |
Wale Ogunwale | f16a281 | 2015-04-01 11:23:15 -0700 | [diff] [blame] | 3157 | private StackInfo getStackInfoLocked(ActivityStack stack) { |
Craig Mautner | 4a1cb22 | 2013-12-04 16:14:06 -0800 | [diff] [blame] | 3158 | StackInfo info = new StackInfo(); |
| 3159 | mWindowManager.getStackBounds(stack.mStackId, info.bounds); |
| 3160 | info.displayId = Display.DEFAULT_DISPLAY; |
| 3161 | info.stackId = stack.mStackId; |
Filip Gruszczynski | 21199bd | 2015-12-02 12:49:58 -0800 | [diff] [blame] | 3162 | info.userId = stack.mCurrentUser; |
Craig Mautner | 4a1cb22 | 2013-12-04 16:14:06 -0800 | [diff] [blame] | 3163 | |
| 3164 | ArrayList<TaskRecord> tasks = stack.getAllTasks(); |
| 3165 | final int numTasks = tasks.size(); |
| 3166 | int[] taskIds = new int[numTasks]; |
| 3167 | String[] taskNames = new String[numTasks]; |
Wale Ogunwale | e4a0c57 | 2015-06-30 08:40:31 -0700 | [diff] [blame] | 3168 | Rect[] taskBounds = new Rect[numTasks]; |
Filip Gruszczynski | 21199bd | 2015-12-02 12:49:58 -0800 | [diff] [blame] | 3169 | int[] taskUserIds = new int[numTasks]; |
Craig Mautner | 4a1cb22 | 2013-12-04 16:14:06 -0800 | [diff] [blame] | 3170 | for (int i = 0; i < numTasks; ++i) { |
| 3171 | final TaskRecord task = tasks.get(i); |
| 3172 | taskIds[i] = task.taskId; |
| 3173 | taskNames[i] = task.origActivity != null ? task.origActivity.flattenToString() |
| 3174 | : task.realActivity != null ? task.realActivity.flattenToString() |
| 3175 | : task.getTopActivity() != null ? task.getTopActivity().packageName |
| 3176 | : "unknown"; |
Wale Ogunwale | e4a0c57 | 2015-06-30 08:40:31 -0700 | [diff] [blame] | 3177 | taskBounds[i] = new Rect(); |
| 3178 | mWindowManager.getTaskBounds(task.taskId, taskBounds[i]); |
Filip Gruszczynski | 21199bd | 2015-12-02 12:49:58 -0800 | [diff] [blame] | 3179 | taskUserIds[i] = task.userId; |
Craig Mautner | 4a1cb22 | 2013-12-04 16:14:06 -0800 | [diff] [blame] | 3180 | } |
| 3181 | info.taskIds = taskIds; |
| 3182 | info.taskNames = taskNames; |
Wale Ogunwale | 868a5e1 | 2015-08-02 16:19:20 -0700 | [diff] [blame] | 3183 | info.taskBounds = taskBounds; |
Filip Gruszczynski | 21199bd | 2015-12-02 12:49:58 -0800 | [diff] [blame] | 3184 | info.taskUserIds = taskUserIds; |
Craig Mautner | 4a1cb22 | 2013-12-04 16:14:06 -0800 | [diff] [blame] | 3185 | return info; |
| 3186 | } |
| 3187 | |
| 3188 | StackInfo getStackInfoLocked(int stackId) { |
| 3189 | ActivityStack stack = getStack(stackId); |
| 3190 | if (stack != null) { |
Wale Ogunwale | f16a281 | 2015-04-01 11:23:15 -0700 | [diff] [blame] | 3191 | return getStackInfoLocked(stack); |
Craig Mautner | 4a1cb22 | 2013-12-04 16:14:06 -0800 | [diff] [blame] | 3192 | } |
| 3193 | return null; |
| 3194 | } |
| 3195 | |
| 3196 | ArrayList<StackInfo> getAllStackInfosLocked() { |
Wale Ogunwale | e4a0c57 | 2015-06-30 08:40:31 -0700 | [diff] [blame] | 3197 | ArrayList<StackInfo> list = new ArrayList<>(); |
Craig Mautner | e0a3884 | 2013-12-16 16:14:02 -0800 | [diff] [blame] | 3198 | for (int displayNdx = 0; displayNdx < mActivityDisplays.size(); ++displayNdx) { |
| 3199 | ArrayList<ActivityStack> stacks = mActivityDisplays.valueAt(displayNdx).mStacks; |
Craig Mautner | 4a1cb22 | 2013-12-04 16:14:06 -0800 | [diff] [blame] | 3200 | for (int ndx = stacks.size() - 1; ndx >= 0; --ndx) { |
Wale Ogunwale | f16a281 | 2015-04-01 11:23:15 -0700 | [diff] [blame] | 3201 | list.add(getStackInfoLocked(stacks.get(ndx))); |
Craig Mautner | 4a1cb22 | 2013-12-04 16:14:06 -0800 | [diff] [blame] | 3202 | } |
| 3203 | } |
| 3204 | return list; |
| 3205 | } |
| 3206 | |
Craig Mautner | 15df08a | 2015-04-01 12:17:18 -0700 | [diff] [blame] | 3207 | TaskRecord getLockedTaskLocked() { |
| 3208 | final int top = mLockTaskModeTasks.size() - 1; |
| 3209 | if (top >= 0) { |
| 3210 | return mLockTaskModeTasks.get(top); |
| 3211 | } |
| 3212 | return null; |
| 3213 | } |
| 3214 | |
| 3215 | boolean isLockedTask(TaskRecord task) { |
| 3216 | return mLockTaskModeTasks.contains(task); |
| 3217 | } |
| 3218 | |
| 3219 | boolean isLastLockedTask(TaskRecord task) { |
| 3220 | return mLockTaskModeTasks.size() == 1 && mLockTaskModeTasks.contains(task); |
| 3221 | } |
| 3222 | |
| 3223 | void removeLockedTaskLocked(final TaskRecord task) { |
Craig Mautner | 432f64e | 2015-05-20 14:59:57 -0700 | [diff] [blame] | 3224 | if (!mLockTaskModeTasks.remove(task)) { |
| 3225 | return; |
| 3226 | } |
| 3227 | if (DEBUG_LOCKTASK) Slog.w(TAG_LOCKTASK, "removeLockedTaskLocked: removed " + task); |
| 3228 | if (mLockTaskModeTasks.isEmpty()) { |
Craig Mautner | 15df08a | 2015-04-01 12:17:18 -0700 | [diff] [blame] | 3229 | // Last one. |
Craig Mautner | e057020 | 2015-05-13 13:06:11 -0700 | [diff] [blame] | 3230 | if (DEBUG_LOCKTASK) Slog.d(TAG_LOCKTASK, "removeLockedTask: task=" + task + |
| 3231 | " last task, reverting locktask mode. Callers=" + Debug.getCallers(3)); |
Craig Mautner | 15df08a | 2015-04-01 12:17:18 -0700 | [diff] [blame] | 3232 | final Message lockTaskMsg = Message.obtain(); |
| 3233 | lockTaskMsg.arg1 = task.userId; |
| 3234 | lockTaskMsg.what = LOCK_TASK_END_MSG; |
| 3235 | mHandler.sendMessage(lockTaskMsg); |
| 3236 | } |
| 3237 | } |
| 3238 | |
Wale Ogunwale | b9b16a7 | 2016-01-27 12:24:44 -0800 | [diff] [blame] | 3239 | void showNonResizeableDockToastIfNeeded( |
| 3240 | TaskRecord task, int preferredStackId, int actualStackId) { |
| 3241 | if (!isStackDockedInEffect(actualStackId) && preferredStackId != DOCKED_STACK_ID) { |
| 3242 | return; |
| 3243 | } |
| 3244 | |
| 3245 | if (!task.canGoInDockedStack() || task.inCropWindowsResizeMode()) { |
| 3246 | // Display warning toast if we tried to put a non-dockable task in the docked stack or |
| 3247 | // the task is running in cropped window mode. |
| 3248 | mWindowManager.scheduleShowNonResizeableDockToast(task.taskId); |
| 3249 | } |
Chong Zhang | b15758a | 2015-11-17 12:12:03 -0800 | [diff] [blame] | 3250 | } |
| 3251 | |
Craig Mautner | 6cd6cec | 2015-04-01 00:02:12 -0700 | [diff] [blame] | 3252 | void showLockTaskToast() { |
| 3253 | mLockTaskNotify.showToast(mLockTaskModeState); |
Jason Monk | a8f569c | 2014-07-07 12:15:21 -0400 | [diff] [blame] | 3254 | } |
| 3255 | |
Craig Mautner | c21ae9e | 2015-04-15 09:45:42 -0700 | [diff] [blame] | 3256 | void showLockTaskEscapeMessageLocked(TaskRecord task) { |
| 3257 | if (mLockTaskModeTasks.contains(task)) { |
| 3258 | mHandler.sendEmptyMessage(SHOW_LOCK_TASK_ESCAPE_MESSAGE_MSG); |
| 3259 | } |
| 3260 | } |
| 3261 | |
Craig Mautner | 432f64e | 2015-05-20 14:59:57 -0700 | [diff] [blame] | 3262 | void setLockTaskModeLocked(TaskRecord task, int lockTaskModeState, String reason, |
| 3263 | boolean andResume) { |
Craig Mautner | aea74a5 | 2014-03-08 14:23:10 -0800 | [diff] [blame] | 3264 | if (task == null) { |
Christopher Tate | 3bd9061 | 2014-06-18 16:37:52 -0700 | [diff] [blame] | 3265 | // Take out of lock task mode if necessary |
Craig Mautner | 15df08a | 2015-04-01 12:17:18 -0700 | [diff] [blame] | 3266 | final TaskRecord lockedTask = getLockedTaskLocked(); |
| 3267 | if (lockedTask != null) { |
| 3268 | removeLockedTaskLocked(lockedTask); |
| 3269 | if (!mLockTaskModeTasks.isEmpty()) { |
| 3270 | // 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] | 3271 | if (DEBUG_LOCKTASK) Slog.w(TAG_LOCKTASK, |
| 3272 | "setLockTaskModeLocked: Tasks remaining, can't unlock"); |
Craig Mautner | 15df08a | 2015-04-01 12:17:18 -0700 | [diff] [blame] | 3273 | lockedTask.performClearTaskLocked(); |
Wale Ogunwale | d046a01 | 2015-12-24 13:05:59 -0800 | [diff] [blame] | 3274 | resumeFocusedStackTopActivityLocked(); |
Craig Mautner | 15df08a | 2015-04-01 12:17:18 -0700 | [diff] [blame] | 3275 | return; |
| 3276 | } |
Christopher Tate | 3bd9061 | 2014-06-18 16:37:52 -0700 | [diff] [blame] | 3277 | } |
Craig Mautner | e057020 | 2015-05-13 13:06:11 -0700 | [diff] [blame] | 3278 | if (DEBUG_LOCKTASK) Slog.w(TAG_LOCKTASK, |
| 3279 | "setLockTaskModeLocked: No tasks to unlock. Callers=" + Debug.getCallers(4)); |
Craig Mautner | aea74a5 | 2014-03-08 14:23:10 -0800 | [diff] [blame] | 3280 | return; |
| 3281 | } |
Craig Mautner | 15df08a | 2015-04-01 12:17:18 -0700 | [diff] [blame] | 3282 | |
| 3283 | // Should have already been checked, but do it again. |
| 3284 | if (task.mLockTaskAuth == LOCK_TASK_AUTH_DONT_LOCK) { |
Craig Mautner | e057020 | 2015-05-13 13:06:11 -0700 | [diff] [blame] | 3285 | if (DEBUG_LOCKTASK) Slog.w(TAG_LOCKTASK, |
| 3286 | "setLockTaskModeLocked: Can't lock due to auth"); |
Craig Mautner | aea74a5 | 2014-03-08 14:23:10 -0800 | [diff] [blame] | 3287 | return; |
| 3288 | } |
Craig Mautner | 15df08a | 2015-04-01 12:17:18 -0700 | [diff] [blame] | 3289 | if (isLockTaskModeViolation(task)) { |
Craig Mautner | e057020 | 2015-05-13 13:06:11 -0700 | [diff] [blame] | 3290 | Slog.e(TAG_LOCKTASK, "setLockTaskMode: Attempt to start an unauthorized lock task."); |
Craig Mautner | 15df08a | 2015-04-01 12:17:18 -0700 | [diff] [blame] | 3291 | return; |
| 3292 | } |
| 3293 | |
| 3294 | if (mLockTaskModeTasks.isEmpty()) { |
| 3295 | // First locktask. |
| 3296 | final Message lockTaskMsg = Message.obtain(); |
| 3297 | lockTaskMsg.obj = task.intent.getComponent().getPackageName(); |
| 3298 | lockTaskMsg.arg1 = task.userId; |
| 3299 | lockTaskMsg.what = LOCK_TASK_START_MSG; |
| 3300 | lockTaskMsg.arg2 = lockTaskModeState; |
| 3301 | mHandler.sendMessage(lockTaskMsg); |
| 3302 | } |
| 3303 | // Add it or move it to the top. |
Craig Mautner | e057020 | 2015-05-13 13:06:11 -0700 | [diff] [blame] | 3304 | if (DEBUG_LOCKTASK) Slog.w(TAG_LOCKTASK, "setLockTaskModeLocked: Locking to " + task + |
| 3305 | " Callers=" + Debug.getCallers(4)); |
Craig Mautner | 15df08a | 2015-04-01 12:17:18 -0700 | [diff] [blame] | 3306 | mLockTaskModeTasks.remove(task); |
| 3307 | mLockTaskModeTasks.add(task); |
| 3308 | |
| 3309 | if (task.mLockTaskUid == -1) { |
Wale Ogunwale | 5c18d05 | 2015-10-12 10:34:14 -0700 | [diff] [blame] | 3310 | task.mLockTaskUid = task.effectiveUid; |
Craig Mautner | 15df08a | 2015-04-01 12:17:18 -0700 | [diff] [blame] | 3311 | } |
Craig Mautner | 432f64e | 2015-05-20 14:59:57 -0700 | [diff] [blame] | 3312 | |
| 3313 | if (andResume) { |
| 3314 | findTaskToMoveToFrontLocked(task, 0, null, reason); |
Wale Ogunwale | d046a01 | 2015-12-24 13:05:59 -0800 | [diff] [blame] | 3315 | resumeFocusedStackTopActivityLocked(); |
Craig Mautner | 432f64e | 2015-05-20 14:59:57 -0700 | [diff] [blame] | 3316 | } |
Craig Mautner | aea74a5 | 2014-03-08 14:23:10 -0800 | [diff] [blame] | 3317 | } |
| 3318 | |
| 3319 | boolean isLockTaskModeViolation(TaskRecord task) { |
Jason Monk | 25d237b | 2015-06-19 10:39:39 -0400 | [diff] [blame] | 3320 | return isLockTaskModeViolation(task, false); |
| 3321 | } |
| 3322 | |
| 3323 | boolean isLockTaskModeViolation(TaskRecord task, boolean isNewClearTask) { |
| 3324 | if (getLockedTaskLocked() == task && !isNewClearTask) { |
Craig Mautner | 15df08a | 2015-04-01 12:17:18 -0700 | [diff] [blame] | 3325 | return false; |
| 3326 | } |
| 3327 | final int lockTaskAuth = task.mLockTaskAuth; |
| 3328 | switch (lockTaskAuth) { |
| 3329 | case LOCK_TASK_AUTH_DONT_LOCK: |
| 3330 | return !mLockTaskModeTasks.isEmpty(); |
Benjamin Franz | 469dd58 | 2015-06-09 14:24:36 +0100 | [diff] [blame] | 3331 | case LOCK_TASK_AUTH_LAUNCHABLE_PRIV: |
Craig Mautner | 15df08a | 2015-04-01 12:17:18 -0700 | [diff] [blame] | 3332 | case LOCK_TASK_AUTH_LAUNCHABLE: |
| 3333 | case LOCK_TASK_AUTH_WHITELISTED: |
| 3334 | return false; |
| 3335 | case LOCK_TASK_AUTH_PINNABLE: |
| 3336 | // Pinnable tasks can't be launched on top of locktask tasks. |
| 3337 | return !mLockTaskModeTasks.isEmpty(); |
| 3338 | default: |
| 3339 | Slog.w(TAG, "isLockTaskModeViolation: invalid lockTaskAuth value=" + lockTaskAuth); |
| 3340 | return true; |
| 3341 | } |
Craig Mautner | aea74a5 | 2014-03-08 14:23:10 -0800 | [diff] [blame] | 3342 | } |
| 3343 | |
Craig Mautner | 15df08a | 2015-04-01 12:17:18 -0700 | [diff] [blame] | 3344 | void onLockTaskPackagesUpdatedLocked() { |
| 3345 | boolean didSomething = false; |
| 3346 | for (int taskNdx = mLockTaskModeTasks.size() - 1; taskNdx >= 0; --taskNdx) { |
| 3347 | final TaskRecord lockedTask = mLockTaskModeTasks.get(taskNdx); |
Benjamin Franz | 469dd58 | 2015-06-09 14:24:36 +0100 | [diff] [blame] | 3348 | final boolean wasWhitelisted = |
| 3349 | (lockedTask.mLockTaskAuth == LOCK_TASK_AUTH_LAUNCHABLE) || |
| 3350 | (lockedTask.mLockTaskAuth == LOCK_TASK_AUTH_WHITELISTED); |
Craig Mautner | 15df08a | 2015-04-01 12:17:18 -0700 | [diff] [blame] | 3351 | lockedTask.setLockTaskAuth(); |
Benjamin Franz | 469dd58 | 2015-06-09 14:24:36 +0100 | [diff] [blame] | 3352 | final boolean isWhitelisted = |
| 3353 | (lockedTask.mLockTaskAuth == LOCK_TASK_AUTH_LAUNCHABLE) || |
| 3354 | (lockedTask.mLockTaskAuth == LOCK_TASK_AUTH_WHITELISTED); |
| 3355 | if (wasWhitelisted && !isWhitelisted) { |
Craig Mautner | 15df08a | 2015-04-01 12:17:18 -0700 | [diff] [blame] | 3356 | // Lost whitelisting authorization. End it now. |
Craig Mautner | 432f64e | 2015-05-20 14:59:57 -0700 | [diff] [blame] | 3357 | if (DEBUG_LOCKTASK) Slog.d(TAG_LOCKTASK, "onLockTaskPackagesUpdated: removing " + |
| 3358 | lockedTask + " mLockTaskAuth=" + lockedTask.lockTaskAuthToString()); |
Craig Mautner | 15df08a | 2015-04-01 12:17:18 -0700 | [diff] [blame] | 3359 | removeLockedTaskLocked(lockedTask); |
| 3360 | lockedTask.performClearTaskLocked(); |
| 3361 | didSomething = true; |
| 3362 | } |
| 3363 | } |
| 3364 | for (int displayNdx = mActivityDisplays.size() - 1; displayNdx >= 0; --displayNdx) { |
| 3365 | ArrayList<ActivityStack> stacks = mActivityDisplays.valueAt(displayNdx).mStacks; |
| 3366 | for (int stackNdx = stacks.size() - 1; stackNdx >= 0; --stackNdx) { |
| 3367 | final ActivityStack stack = stacks.get(stackNdx); |
| 3368 | stack.onLockTaskPackagesUpdatedLocked(); |
| 3369 | } |
| 3370 | } |
Craig Mautner | e057020 | 2015-05-13 13:06:11 -0700 | [diff] [blame] | 3371 | final ActivityRecord r = topRunningActivityLocked(); |
| 3372 | final TaskRecord task = r != null ? r.task : null; |
| 3373 | if (mLockTaskModeTasks.isEmpty() && task != null |
| 3374 | && task.mLockTaskAuth == LOCK_TASK_AUTH_LAUNCHABLE) { |
| 3375 | // This task must have just been authorized. |
Craig Mautner | 432f64e | 2015-05-20 14:59:57 -0700 | [diff] [blame] | 3376 | if (DEBUG_LOCKTASK) Slog.d(TAG_LOCKTASK, |
| 3377 | "onLockTaskPackagesUpdated: starting new locktask task=" + task); |
| 3378 | setLockTaskModeLocked(task, ActivityManager.LOCK_TASK_MODE_LOCKED, "package updated", |
| 3379 | false); |
| 3380 | didSomething = true; |
Craig Mautner | e057020 | 2015-05-13 13:06:11 -0700 | [diff] [blame] | 3381 | } |
Craig Mautner | 15df08a | 2015-04-01 12:17:18 -0700 | [diff] [blame] | 3382 | if (didSomething) { |
Wale Ogunwale | d046a01 | 2015-12-24 13:05:59 -0800 | [diff] [blame] | 3383 | resumeFocusedStackTopActivityLocked(); |
Craig Mautner | aea74a5 | 2014-03-08 14:23:10 -0800 | [diff] [blame] | 3384 | } |
| 3385 | } |
| 3386 | |
Benjamin Franz | 4326114 | 2015-02-11 15:59:44 +0000 | [diff] [blame] | 3387 | int getLockTaskModeState() { |
| 3388 | return mLockTaskModeState; |
Craig Mautner | aea74a5 | 2014-03-08 14:23:10 -0800 | [diff] [blame] | 3389 | } |
| 3390 | |
Jorim Jaggi | fe89d12 | 2015-12-22 16:28:44 +0100 | [diff] [blame] | 3391 | void activityRelaunchedLocked(IBinder token) { |
| 3392 | mWindowManager.notifyAppRelaunchingFinished(token); |
| 3393 | } |
| 3394 | |
| 3395 | void activityRelaunchingLocked(ActivityRecord r) { |
| 3396 | mWindowManager.notifyAppRelaunching(r.appToken); |
| 3397 | } |
| 3398 | |
Filip Gruszczynski | 77d9448 | 2015-12-11 13:59:52 -0800 | [diff] [blame] | 3399 | void logStackState() { |
| 3400 | mActivityMetricsLogger.logWindowState(); |
| 3401 | } |
| 3402 | |
Wale Ogunwale | 22e2526 | 2016-02-01 10:32:02 -0800 | [diff] [blame] | 3403 | void scheduleReportMultiWindowChanged(TaskRecord task) { |
| 3404 | for (int i = task.mActivities.size() - 1; i >= 0; i--) { |
| 3405 | final ActivityRecord r = task.mActivities.get(i); |
| 3406 | if (r.app != null && r.app.thread != null) { |
| 3407 | mMultiWindowModeChangedActivities.add(r); |
| 3408 | } |
| 3409 | } |
| 3410 | |
| 3411 | if (!mHandler.hasMessages(REPORT_MULTI_WINDOW_MODE_CHANGED_MSG)) { |
| 3412 | mHandler.sendEmptyMessage(REPORT_MULTI_WINDOW_MODE_CHANGED_MSG); |
| 3413 | } |
| 3414 | } |
| 3415 | |
| 3416 | void scheduleReportPictureInPictureChangedIfNeeded(TaskRecord task, ActivityStack prevStack) { |
| 3417 | final ActivityStack stack = task.stack; |
| 3418 | if (prevStack == null || prevStack == stack |
| 3419 | || (prevStack.mStackId != PINNED_STACK_ID && stack.mStackId != PINNED_STACK_ID)) { |
| 3420 | return; |
| 3421 | } |
| 3422 | |
| 3423 | for (int i = task.mActivities.size() - 1; i >= 0; i--) { |
| 3424 | final ActivityRecord r = task.mActivities.get(i); |
| 3425 | if (r.app != null && r.app.thread != null) { |
| 3426 | mPipModeChangedActivities.add(r); |
| 3427 | } |
| 3428 | } |
| 3429 | |
| 3430 | if (!mHandler.hasMessages(REPORT_PIP_MODE_CHANGED_MSG)) { |
| 3431 | mHandler.sendEmptyMessage(REPORT_PIP_MODE_CHANGED_MSG); |
| 3432 | } |
| 3433 | } |
| 3434 | |
Craig Mautner | ce5f3cb | 2013-04-22 08:58:54 -0700 | [diff] [blame] | 3435 | private final class ActivityStackSupervisorHandler extends Handler { |
Craig Mautner | f333327 | 2013-04-22 10:55:53 -0700 | [diff] [blame] | 3436 | |
Craig Mautner | ce5f3cb | 2013-04-22 08:58:54 -0700 | [diff] [blame] | 3437 | public ActivityStackSupervisorHandler(Looper looper) { |
| 3438 | super(looper); |
| 3439 | } |
| 3440 | |
Craig Mautner | f333327 | 2013-04-22 10:55:53 -0700 | [diff] [blame] | 3441 | void activityIdleInternal(ActivityRecord r) { |
| 3442 | synchronized (mService) { |
| 3443 | activityIdleInternalLocked(r != null ? r.appToken : null, true, null); |
| 3444 | } |
Craig Mautner | 7ea5bd4 | 2013-07-05 15:27:08 -0700 | [diff] [blame] | 3445 | } |
| 3446 | |
Craig Mautner | ce5f3cb | 2013-04-22 08:58:54 -0700 | [diff] [blame] | 3447 | @Override |
| 3448 | public void handleMessage(Message msg) { |
| 3449 | switch (msg.what) { |
Wale Ogunwale | 22e2526 | 2016-02-01 10:32:02 -0800 | [diff] [blame] | 3450 | case REPORT_MULTI_WINDOW_MODE_CHANGED_MSG: { |
| 3451 | synchronized (mService) { |
| 3452 | for (int i = mMultiWindowModeChangedActivities.size() - 1; i >= 0; i--) { |
| 3453 | final ActivityRecord r = mMultiWindowModeChangedActivities.remove(i); |
| 3454 | r.scheduleMultiWindowChanged(); |
| 3455 | } |
| 3456 | } |
| 3457 | } break; |
| 3458 | case REPORT_PIP_MODE_CHANGED_MSG: { |
| 3459 | synchronized (mService) { |
| 3460 | for (int i = mPipModeChangedActivities.size() - 1; i >= 0; i--) { |
| 3461 | final ActivityRecord r = mPipModeChangedActivities.remove(i); |
| 3462 | r.schedulePictureInPictureChanged(); |
| 3463 | } |
| 3464 | } |
| 3465 | } break; |
Craig Mautner | f333327 | 2013-04-22 10:55:53 -0700 | [diff] [blame] | 3466 | case IDLE_TIMEOUT_MSG: { |
Wale Ogunwale | 0fc365c | 2015-05-25 19:35:42 -0700 | [diff] [blame] | 3467 | if (DEBUG_IDLE) Slog.d(TAG_IDLE, |
| 3468 | "handleMessage: IDLE_TIMEOUT_MSG: r=" + msg.obj); |
Craig Mautner | f333327 | 2013-04-22 10:55:53 -0700 | [diff] [blame] | 3469 | if (mService.mDidDexOpt) { |
| 3470 | mService.mDidDexOpt = false; |
| 3471 | Message nmsg = mHandler.obtainMessage(IDLE_TIMEOUT_MSG); |
| 3472 | nmsg.obj = msg.obj; |
| 3473 | mHandler.sendMessageDelayed(nmsg, IDLE_TIMEOUT); |
| 3474 | return; |
| 3475 | } |
| 3476 | // We don't at this point know if the activity is fullscreen, |
| 3477 | // so we need to be conservative and assume it isn't. |
| 3478 | activityIdleInternal((ActivityRecord)msg.obj); |
| 3479 | } break; |
| 3480 | case IDLE_NOW_MSG: { |
Wale Ogunwale | 0fc365c | 2015-05-25 19:35:42 -0700 | [diff] [blame] | 3481 | if (DEBUG_IDLE) Slog.d(TAG_IDLE, "handleMessage: IDLE_NOW_MSG: r=" + msg.obj); |
Craig Mautner | f333327 | 2013-04-22 10:55:53 -0700 | [diff] [blame] | 3482 | activityIdleInternal((ActivityRecord)msg.obj); |
| 3483 | } break; |
Craig Mautner | 05d2903 | 2013-05-03 13:40:13 -0700 | [diff] [blame] | 3484 | case RESUME_TOP_ACTIVITY_MSG: { |
| 3485 | synchronized (mService) { |
Wale Ogunwale | d046a01 | 2015-12-24 13:05:59 -0800 | [diff] [blame] | 3486 | resumeFocusedStackTopActivityLocked(); |
Craig Mautner | 05d2903 | 2013-05-03 13:40:13 -0700 | [diff] [blame] | 3487 | } |
| 3488 | } break; |
Craig Mautner | 0eea92c | 2013-05-16 13:35:39 -0700 | [diff] [blame] | 3489 | case SLEEP_TIMEOUT_MSG: { |
| 3490 | synchronized (mService) { |
| 3491 | if (mService.isSleepingOrShuttingDown()) { |
| 3492 | Slog.w(TAG, "Sleep timeout! Sleeping now."); |
| 3493 | mSleepTimeout = true; |
| 3494 | checkReadyForSleepLocked(); |
| 3495 | } |
| 3496 | } |
| 3497 | } break; |
Craig Mautner | 7ea5bd4 | 2013-07-05 15:27:08 -0700 | [diff] [blame] | 3498 | case LAUNCH_TIMEOUT_MSG: { |
| 3499 | if (mService.mDidDexOpt) { |
| 3500 | mService.mDidDexOpt = false; |
| 3501 | mHandler.sendEmptyMessageDelayed(LAUNCH_TIMEOUT_MSG, LAUNCH_TIMEOUT); |
| 3502 | return; |
| 3503 | } |
| 3504 | synchronized (mService) { |
| 3505 | if (mLaunchingActivity.isHeld()) { |
| 3506 | Slog.w(TAG, "Launch timeout has expired, giving up wake lock!"); |
| 3507 | if (VALIDATE_WAKE_LOCK_CALLER |
| 3508 | && Binder.getCallingUid() != Process.myUid()) { |
| 3509 | throw new IllegalStateException("Calling must be system uid"); |
| 3510 | } |
| 3511 | mLaunchingActivity.release(); |
| 3512 | } |
| 3513 | } |
| 3514 | } break; |
Craig Mautner | 4a1cb22 | 2013-12-04 16:14:06 -0800 | [diff] [blame] | 3515 | case HANDLE_DISPLAY_ADDED: { |
Wale Ogunwale | f16a281 | 2015-04-01 11:23:15 -0700 | [diff] [blame] | 3516 | handleDisplayAdded(msg.arg1); |
Craig Mautner | 4a1cb22 | 2013-12-04 16:14:06 -0800 | [diff] [blame] | 3517 | } break; |
| 3518 | case HANDLE_DISPLAY_CHANGED: { |
Wale Ogunwale | f16a281 | 2015-04-01 11:23:15 -0700 | [diff] [blame] | 3519 | handleDisplayChanged(msg.arg1); |
Craig Mautner | 4a1cb22 | 2013-12-04 16:14:06 -0800 | [diff] [blame] | 3520 | } break; |
| 3521 | case HANDLE_DISPLAY_REMOVED: { |
Wale Ogunwale | f16a281 | 2015-04-01 11:23:15 -0700 | [diff] [blame] | 3522 | handleDisplayRemoved(msg.arg1); |
Craig Mautner | 4a1cb22 | 2013-12-04 16:14:06 -0800 | [diff] [blame] | 3523 | } break; |
Craig Mautner | e3a00d7 | 2014-04-16 08:31:19 -0700 | [diff] [blame] | 3524 | case CONTAINER_CALLBACK_VISIBILITY: { |
| 3525 | final ActivityContainer container = (ActivityContainer) msg.obj; |
Craig Mautner | d94b47f | 2014-06-02 15:06:40 -0700 | [diff] [blame] | 3526 | final IActivityContainerCallback callback = container.mCallback; |
| 3527 | if (callback != null) { |
| 3528 | try { |
| 3529 | callback.setVisible(container.asBinder(), msg.arg1 == 1); |
| 3530 | } catch (RemoteException e) { |
| 3531 | } |
Craig Mautner | e3a00d7 | 2014-04-16 08:31:19 -0700 | [diff] [blame] | 3532 | } |
Craig Mautner | d94b47f | 2014-06-02 15:06:40 -0700 | [diff] [blame] | 3533 | } break; |
justinzhang | 5286d3f | 2014-05-12 17:06:01 -0400 | [diff] [blame] | 3534 | case LOCK_TASK_START_MSG: { |
| 3535 | // When lock task starts, we disable the status bars. |
| 3536 | try { |
Jason Monk | 62515be | 2014-05-21 16:06:19 -0400 | [diff] [blame] | 3537 | if (mLockTaskNotify == null) { |
| 3538 | mLockTaskNotify = new LockTaskNotify(mService.mContext); |
justinzhang | 5286d3f | 2014-05-12 17:06:01 -0400 | [diff] [blame] | 3539 | } |
Jason Monk | 62515be | 2014-05-21 16:06:19 -0400 | [diff] [blame] | 3540 | mLockTaskNotify.show(true); |
Benjamin Franz | 4326114 | 2015-02-11 15:59:44 +0000 | [diff] [blame] | 3541 | mLockTaskModeState = msg.arg2; |
Jason Monk | 62515be | 2014-05-21 16:06:19 -0400 | [diff] [blame] | 3542 | if (getStatusBarService() != null) { |
Benjamin Franz | 4326114 | 2015-02-11 15:59:44 +0000 | [diff] [blame] | 3543 | int flags = 0; |
Craig Mautner | 15df08a | 2015-04-01 12:17:18 -0700 | [diff] [blame] | 3544 | if (mLockTaskModeState == LOCK_TASK_MODE_LOCKED) { |
Benjamin Franz | 4326114 | 2015-02-11 15:59:44 +0000 | [diff] [blame] | 3545 | flags = StatusBarManager.DISABLE_MASK |
| 3546 | & (~StatusBarManager.DISABLE_BACK); |
Craig Mautner | 15df08a | 2015-04-01 12:17:18 -0700 | [diff] [blame] | 3547 | } else if (mLockTaskModeState == LOCK_TASK_MODE_PINNED) { |
Benjamin Franz | 4326114 | 2015-02-11 15:59:44 +0000 | [diff] [blame] | 3548 | flags = StatusBarManager.DISABLE_MASK |
| 3549 | & (~StatusBarManager.DISABLE_BACK) |
| 3550 | & (~StatusBarManager.DISABLE_HOME) |
| 3551 | & (~StatusBarManager.DISABLE_RECENT); |
Jason Monk | 62515be | 2014-05-21 16:06:19 -0400 | [diff] [blame] | 3552 | } |
| 3553 | getStatusBarService().disable(flags, mToken, |
| 3554 | mService.mContext.getPackageName()); |
| 3555 | } |
| 3556 | mWindowManager.disableKeyguard(mToken, LOCK_TASK_TAG); |
Jason Monk | 35c62a4 | 2014-06-17 10:24:47 -0400 | [diff] [blame] | 3557 | if (getDevicePolicyManager() != null) { |
| 3558 | getDevicePolicyManager().notifyLockTaskModeChanged(true, |
Jason Monk | 62515be | 2014-05-21 16:06:19 -0400 | [diff] [blame] | 3559 | (String)msg.obj, msg.arg1); |
Jason Monk | 35c62a4 | 2014-06-17 10:24:47 -0400 | [diff] [blame] | 3560 | } |
justinzhang | 5286d3f | 2014-05-12 17:06:01 -0400 | [diff] [blame] | 3561 | } catch (RemoteException ex) { |
| 3562 | throw new RuntimeException(ex); |
| 3563 | } |
Craig Mautner | b6011c1 | 2014-06-04 20:59:13 -0700 | [diff] [blame] | 3564 | } break; |
justinzhang | 5286d3f | 2014-05-12 17:06:01 -0400 | [diff] [blame] | 3565 | case LOCK_TASK_END_MSG: { |
| 3566 | // When lock task ends, we enable the status bars. |
| 3567 | try { |
Jason Monk | 62515be | 2014-05-21 16:06:19 -0400 | [diff] [blame] | 3568 | if (getStatusBarService() != null) { |
| 3569 | getStatusBarService().disable(StatusBarManager.DISABLE_NONE, mToken, |
| 3570 | mService.mContext.getPackageName()); |
| 3571 | } |
| 3572 | mWindowManager.reenableKeyguard(mToken); |
Jason Monk | 35c62a4 | 2014-06-17 10:24:47 -0400 | [diff] [blame] | 3573 | if (getDevicePolicyManager() != null) { |
| 3574 | getDevicePolicyManager().notifyLockTaskModeChanged(false, null, |
| 3575 | msg.arg1); |
| 3576 | } |
Jason Monk | 62515be | 2014-05-21 16:06:19 -0400 | [diff] [blame] | 3577 | if (mLockTaskNotify == null) { |
| 3578 | mLockTaskNotify = new LockTaskNotify(mService.mContext); |
| 3579 | } |
| 3580 | mLockTaskNotify.show(false); |
| 3581 | try { |
Jason Monk | 94cfd9d | 2014-10-31 13:18:21 -0400 | [diff] [blame] | 3582 | boolean shouldLockKeyguard = Settings.Secure.getInt( |
Jason Monk | 62515be | 2014-05-21 16:06:19 -0400 | [diff] [blame] | 3583 | mService.mContext.getContentResolver(), |
Jason Monk | 94cfd9d | 2014-10-31 13:18:21 -0400 | [diff] [blame] | 3584 | Settings.Secure.LOCK_TO_APP_EXIT_LOCKED) != 0; |
Craig Mautner | 15df08a | 2015-04-01 12:17:18 -0700 | [diff] [blame] | 3585 | if (mLockTaskModeState == LOCK_TASK_MODE_PINNED && shouldLockKeyguard) { |
Jason Monk | 62515be | 2014-05-21 16:06:19 -0400 | [diff] [blame] | 3586 | mWindowManager.lockNow(null); |
Jason Monk | 7779bf1 | 2014-07-14 10:20:21 -0400 | [diff] [blame] | 3587 | mWindowManager.dismissKeyguard(); |
Jason Monk | e069779 | 2014-08-04 16:28:09 -0400 | [diff] [blame] | 3588 | new LockPatternUtils(mService.mContext) |
| 3589 | .requireCredentialEntry(UserHandle.USER_ALL); |
Jason Monk | 62515be | 2014-05-21 16:06:19 -0400 | [diff] [blame] | 3590 | } |
| 3591 | } catch (SettingNotFoundException e) { |
| 3592 | // No setting, don't lock. |
| 3593 | } |
justinzhang | 5286d3f | 2014-05-12 17:06:01 -0400 | [diff] [blame] | 3594 | } catch (RemoteException ex) { |
| 3595 | throw new RuntimeException(ex); |
Benjamin Franz | 4326114 | 2015-02-11 15:59:44 +0000 | [diff] [blame] | 3596 | } finally { |
Craig Mautner | 15df08a | 2015-04-01 12:17:18 -0700 | [diff] [blame] | 3597 | mLockTaskModeState = LOCK_TASK_MODE_NONE; |
justinzhang | 5286d3f | 2014-05-12 17:06:01 -0400 | [diff] [blame] | 3598 | } |
Craig Mautner | b6011c1 | 2014-06-04 20:59:13 -0700 | [diff] [blame] | 3599 | } break; |
Craig Mautner | c21ae9e | 2015-04-15 09:45:42 -0700 | [diff] [blame] | 3600 | case SHOW_LOCK_TASK_ESCAPE_MESSAGE_MSG: { |
| 3601 | if (mLockTaskNotify == null) { |
| 3602 | mLockTaskNotify = new LockTaskNotify(mService.mContext); |
| 3603 | } |
| 3604 | mLockTaskNotify.showToast(LOCK_TASK_MODE_PINNED); |
| 3605 | } break; |
Craig Mautner | d94b47f | 2014-06-02 15:06:40 -0700 | [diff] [blame] | 3606 | case CONTAINER_CALLBACK_TASK_LIST_EMPTY: { |
| 3607 | final ActivityContainer container = (ActivityContainer) msg.obj; |
| 3608 | final IActivityContainerCallback callback = container.mCallback; |
| 3609 | if (callback != null) { |
| 3610 | try { |
| 3611 | callback.onAllActivitiesComplete(container.asBinder()); |
| 3612 | } catch (RemoteException e) { |
| 3613 | } |
| 3614 | } |
| 3615 | } break; |
Craig Mautner | bb74246 | 2014-07-07 15:28:55 -0700 | [diff] [blame] | 3616 | case LAUNCH_TASK_BEHIND_COMPLETE: { |
| 3617 | synchronized (mService) { |
Wale Ogunwale | 7d70117 | 2015-03-11 15:36:30 -0700 | [diff] [blame] | 3618 | ActivityRecord r = ActivityRecord.forTokenLocked((IBinder) msg.obj); |
Craig Mautner | bb74246 | 2014-07-07 15:28:55 -0700 | [diff] [blame] | 3619 | if (r != null) { |
| 3620 | handleLaunchTaskBehindCompleteLocked(r); |
| 3621 | } |
| 3622 | } |
| 3623 | } break; |
Chong Zhang | c806d90 | 2015-11-30 09:44:27 -0800 | [diff] [blame] | 3624 | |
Craig Mautner | ce5f3cb | 2013-04-22 08:58:54 -0700 | [diff] [blame] | 3625 | } |
| 3626 | } |
| 3627 | } |
Craig Mautner | ed6649f | 2013-12-02 14:08:25 -0800 | [diff] [blame] | 3628 | |
Ying Wang | b081a59 | 2014-04-22 15:20:16 -0700 | [diff] [blame] | 3629 | class ActivityContainer extends android.app.IActivityContainer.Stub { |
Filip Gruszczynski | dc39490 | 2015-12-14 10:20:22 -0800 | [diff] [blame] | 3630 | final static int FORCE_NEW_TASK_FLAGS = FLAG_ACTIVITY_NEW_TASK | |
| 3631 | FLAG_ACTIVITY_MULTIPLE_TASK | Intent.FLAG_ACTIVITY_NO_ANIMATION; |
Craig Mautner | 4a1cb22 | 2013-12-04 16:14:06 -0800 | [diff] [blame] | 3632 | final int mStackId; |
Craig Mautner | f4c909b | 2014-04-17 18:39:38 -0700 | [diff] [blame] | 3633 | IActivityContainerCallback mCallback = null; |
Craig Mautner | 4a1cb22 | 2013-12-04 16:14:06 -0800 | [diff] [blame] | 3634 | final ActivityStack mStack; |
Craig Mautner | f4c909b | 2014-04-17 18:39:38 -0700 | [diff] [blame] | 3635 | ActivityRecord mParentActivity = null; |
| 3636 | String mIdString; |
Craig Mautner | ed6649f | 2013-12-02 14:08:25 -0800 | [diff] [blame] | 3637 | |
Craig Mautner | e3a00d7 | 2014-04-16 08:31:19 -0700 | [diff] [blame] | 3638 | boolean mVisible = true; |
| 3639 | |
Craig Mautner | 4a1cb22 | 2013-12-04 16:14:06 -0800 | [diff] [blame] | 3640 | /** 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] | 3641 | ActivityDisplay mActivityDisplay; |
Craig Mautner | 4a1cb22 | 2013-12-04 16:14:06 -0800 | [diff] [blame] | 3642 | |
Craig Mautner | f4c909b | 2014-04-17 18:39:38 -0700 | [diff] [blame] | 3643 | final static int CONTAINER_STATE_HAS_SURFACE = 0; |
| 3644 | final static int CONTAINER_STATE_NO_SURFACE = 1; |
| 3645 | final static int CONTAINER_STATE_FINISHING = 2; |
| 3646 | int mContainerState = CONTAINER_STATE_HAS_SURFACE; |
| 3647 | |
| 3648 | ActivityContainer(int stackId) { |
Craig Mautner | 4a1cb22 | 2013-12-04 16:14:06 -0800 | [diff] [blame] | 3649 | synchronized (mService) { |
| 3650 | mStackId = stackId; |
Wale Ogunwale | c82f2f5 | 2014-12-09 09:32:50 -0800 | [diff] [blame] | 3651 | mStack = new ActivityStack(this, mRecentTasks); |
Craig Mautner | f4c909b | 2014-04-17 18:39:38 -0700 | [diff] [blame] | 3652 | mIdString = "ActivtyContainer{" + mStackId + "}"; |
Wale Ogunwale | ee006da | 2015-03-30 14:49:25 -0700 | [diff] [blame] | 3653 | if (DEBUG_STACK) Slog.d(TAG_STACK, "Creating " + this); |
Craig Mautner | 4a1cb22 | 2013-12-04 16:14:06 -0800 | [diff] [blame] | 3654 | } |
Craig Mautner | ed6649f | 2013-12-02 14:08:25 -0800 | [diff] [blame] | 3655 | } |
Craig Mautner | 4a1cb22 | 2013-12-04 16:14:06 -0800 | [diff] [blame] | 3656 | |
Wale Ogunwale | ddc1cb2 | 2015-07-25 19:23:04 -0700 | [diff] [blame] | 3657 | void attachToDisplayLocked(ActivityDisplay activityDisplay, boolean onTop) { |
Wale Ogunwale | ee006da | 2015-03-30 14:49:25 -0700 | [diff] [blame] | 3658 | if (DEBUG_STACK) Slog.d(TAG_STACK, "attachToDisplayLocked: " + this |
Wale Ogunwale | ddc1cb2 | 2015-07-25 19:23:04 -0700 | [diff] [blame] | 3659 | + " to display=" + activityDisplay + " onTop=" + onTop); |
Craig Mautner | e0a3884 | 2013-12-16 16:14:02 -0800 | [diff] [blame] | 3660 | mActivityDisplay = activityDisplay; |
Filip Gruszczynski | e5390e7 | 2015-08-18 16:39:00 -0700 | [diff] [blame] | 3661 | mStack.attachDisplay(activityDisplay, onTop); |
Wale Ogunwale | ddc1cb2 | 2015-07-25 19:23:04 -0700 | [diff] [blame] | 3662 | activityDisplay.attachActivities(mStack, onTop); |
Craig Mautner | 4a1cb22 | 2013-12-04 16:14:06 -0800 | [diff] [blame] | 3663 | } |
| 3664 | |
| 3665 | @Override |
Jeff Brown | ca9bc70 | 2014-02-11 14:32:56 -0800 | [diff] [blame] | 3666 | public void attachToDisplay(int displayId) { |
Craig Mautner | 4a1cb22 | 2013-12-04 16:14:06 -0800 | [diff] [blame] | 3667 | synchronized (mService) { |
Craig Mautner | e0a3884 | 2013-12-16 16:14:02 -0800 | [diff] [blame] | 3668 | ActivityDisplay activityDisplay = mActivityDisplays.get(displayId); |
| 3669 | if (activityDisplay == null) { |
Craig Mautner | 4a1cb22 | 2013-12-04 16:14:06 -0800 | [diff] [blame] | 3670 | return; |
| 3671 | } |
Wale Ogunwale | ddc1cb2 | 2015-07-25 19:23:04 -0700 | [diff] [blame] | 3672 | attachToDisplayLocked(activityDisplay, true); |
Craig Mautner | 4a1cb22 | 2013-12-04 16:14:06 -0800 | [diff] [blame] | 3673 | } |
| 3674 | } |
| 3675 | |
| 3676 | @Override |
Jeff Brown | ca9bc70 | 2014-02-11 14:32:56 -0800 | [diff] [blame] | 3677 | public int getDisplayId() { |
Craig Mautner | d163e75 | 2014-06-13 17:18:47 -0700 | [diff] [blame] | 3678 | synchronized (mService) { |
| 3679 | if (mActivityDisplay != null) { |
| 3680 | return mActivityDisplay.mDisplayId; |
| 3681 | } |
Craig Mautner | e0a3884 | 2013-12-16 16:14:02 -0800 | [diff] [blame] | 3682 | } |
| 3683 | return -1; |
Craig Mautner | 4a1cb22 | 2013-12-04 16:14:06 -0800 | [diff] [blame] | 3684 | } |
| 3685 | |
Jeff Brown | ca9bc70 | 2014-02-11 14:32:56 -0800 | [diff] [blame] | 3686 | @Override |
Winson Chung | d16c565 | 2015-01-26 16:11:07 -0800 | [diff] [blame] | 3687 | public int getStackId() { |
| 3688 | synchronized (mService) { |
| 3689 | return mStackId; |
| 3690 | } |
| 3691 | } |
| 3692 | |
| 3693 | @Override |
Jeff Brown | ca9bc70 | 2014-02-11 14:32:56 -0800 | [diff] [blame] | 3694 | public boolean injectEvent(InputEvent event) { |
| 3695 | final long origId = Binder.clearCallingIdentity(); |
| 3696 | try { |
Craig Mautner | d163e75 | 2014-06-13 17:18:47 -0700 | [diff] [blame] | 3697 | synchronized (mService) { |
| 3698 | if (mActivityDisplay != null) { |
| 3699 | return mInputManagerInternal.injectInputEvent(event, |
| 3700 | mActivityDisplay.mDisplayId, |
| 3701 | InputManager.INJECT_INPUT_EVENT_MODE_ASYNC); |
| 3702 | } |
Jeff Brown | ca9bc70 | 2014-02-11 14:32:56 -0800 | [diff] [blame] | 3703 | } |
| 3704 | return false; |
| 3705 | } finally { |
| 3706 | Binder.restoreCallingIdentity(origId); |
| 3707 | } |
| 3708 | } |
| 3709 | |
Craig Mautner | f4c909b | 2014-04-17 18:39:38 -0700 | [diff] [blame] | 3710 | @Override |
| 3711 | public void release() { |
Craig Mautner | d163e75 | 2014-06-13 17:18:47 -0700 | [diff] [blame] | 3712 | synchronized (mService) { |
| 3713 | if (mContainerState == CONTAINER_STATE_FINISHING) { |
| 3714 | return; |
| 3715 | } |
| 3716 | mContainerState = CONTAINER_STATE_FINISHING; |
| 3717 | |
Craig Mautner | d163e75 | 2014-06-13 17:18:47 -0700 | [diff] [blame] | 3718 | long origId = Binder.clearCallingIdentity(); |
| 3719 | try { |
Craig Mautner | ee36c77 | 2014-07-16 14:56:05 -0700 | [diff] [blame] | 3720 | mStack.finishAllActivitiesLocked(false); |
Filip Gruszczynski | 07a0e49 | 2015-12-17 14:16:38 -0800 | [diff] [blame] | 3721 | mService.mActivityStarter.removePendingActivityLaunchesLocked(mStack); |
Craig Mautner | d163e75 | 2014-06-13 17:18:47 -0700 | [diff] [blame] | 3722 | } finally { |
| 3723 | Binder.restoreCallingIdentity(origId); |
| 3724 | } |
| 3725 | } |
Craig Mautner | f4c909b | 2014-04-17 18:39:38 -0700 | [diff] [blame] | 3726 | } |
| 3727 | |
Craig Mautner | 6025770 | 2014-09-17 15:02:33 -0700 | [diff] [blame] | 3728 | protected void detachLocked() { |
Wale Ogunwale | ee006da | 2015-03-30 14:49:25 -0700 | [diff] [blame] | 3729 | if (DEBUG_STACK) Slog.d(TAG_STACK, "detachLocked: " + this + " from display=" |
Craig Mautner | 34b73df | 2014-01-12 21:11:08 -0800 | [diff] [blame] | 3730 | + mActivityDisplay + " Callers=" + Debug.getCallers(2)); |
Craig Mautner | e0a3884 | 2013-12-16 16:14:02 -0800 | [diff] [blame] | 3731 | if (mActivityDisplay != null) { |
| 3732 | mActivityDisplay.detachActivitiesLocked(mStack); |
| 3733 | mActivityDisplay = null; |
Filip Gruszczynski | e5390e7 | 2015-08-18 16:39:00 -0700 | [diff] [blame] | 3734 | mStack.detachDisplay(); |
Craig Mautner | 4a1cb22 | 2013-12-04 16:14:06 -0800 | [diff] [blame] | 3735 | } |
| 3736 | } |
| 3737 | |
| 3738 | @Override |
Craig Mautner | e0a3884 | 2013-12-16 16:14:02 -0800 | [diff] [blame] | 3739 | public final int startActivity(Intent intent) { |
Filip Gruszczynski | 07a0e49 | 2015-12-17 14:16:38 -0800 | [diff] [blame] | 3740 | return mService.startActivity(intent, this); |
Craig Mautner | 4a1cb22 | 2013-12-04 16:14:06 -0800 | [diff] [blame] | 3741 | } |
| 3742 | |
| 3743 | @Override |
Craig Mautner | 5f2bb4c | 2015-03-12 16:10:27 -0700 | [diff] [blame] | 3744 | public final int startActivityIntentSender(IIntentSender intentSender) |
| 3745 | throws TransactionTooLargeException { |
Craig Mautner | df88d73 | 2014-01-27 09:21:32 -0800 | [diff] [blame] | 3746 | mService.enforceNotIsolatedCaller("ActivityContainer.startActivityIntentSender"); |
| 3747 | |
| 3748 | if (!(intentSender instanceof PendingIntentRecord)) { |
| 3749 | throw new IllegalArgumentException("Bad PendingIntent object"); |
| 3750 | } |
| 3751 | |
Fyodor Kupolov | f63b89c | 2015-10-27 18:08:56 -0700 | [diff] [blame] | 3752 | final int userId = mService.mUserController.handleIncomingUser(Binder.getCallingPid(), |
Dianne Hackborn | 409297d | 2014-07-10 17:39:20 -0700 | [diff] [blame] | 3753 | Binder.getCallingUid(), mCurrentUser, false, |
| 3754 | ActivityManagerService.ALLOW_FULL_ONLY, "ActivityContainer", null); |
Craig Mautner | b916836 | 2015-02-26 20:40:19 -0800 | [diff] [blame] | 3755 | |
| 3756 | final PendingIntentRecord pendingIntent = (PendingIntentRecord) intentSender; |
| 3757 | checkEmbeddedAllowedInner(userId, pendingIntent.key.requestIntent, |
| 3758 | pendingIntent.key.requestResolvedType); |
| 3759 | |
| 3760 | return pendingIntent.sendInner(0, null, null, null, null, null, null, 0, |
| 3761 | FORCE_NEW_TASK_FLAGS, FORCE_NEW_TASK_FLAGS, null, this); |
| 3762 | } |
| 3763 | |
Filip Gruszczynski | 07a0e49 | 2015-12-17 14:16:38 -0800 | [diff] [blame] | 3764 | void checkEmbeddedAllowedInner(int userId, Intent intent, String resolvedType) { |
Jeff Hao | 1b012d3 | 2014-08-20 10:35:34 -0700 | [diff] [blame] | 3765 | ActivityInfo aInfo = resolveActivity(intent, resolvedType, 0, null, userId); |
Craig Mautner | 05678d5 | 2014-05-05 12:32:40 -0700 | [diff] [blame] | 3766 | if (aInfo != null && (aInfo.flags & ActivityInfo.FLAG_ALLOW_EMBEDDED) == 0) { |
Craig Mautner | 247ab65 | 2014-04-25 10:09:00 -0700 | [diff] [blame] | 3767 | throw new SecurityException( |
| 3768 | "Attempt to embed activity that has not set allowEmbedded=\"true\""); |
| 3769 | } |
| 3770 | } |
| 3771 | |
Craig Mautner | df88d73 | 2014-01-27 09:21:32 -0800 | [diff] [blame] | 3772 | @Override |
Craig Mautner | 4a1cb22 | 2013-12-04 16:14:06 -0800 | [diff] [blame] | 3773 | public IBinder asBinder() { |
| 3774 | return this; |
| 3775 | } |
| 3776 | |
Craig Mautner | 4504de5 | 2013-12-20 09:06:56 -0800 | [diff] [blame] | 3777 | @Override |
Craig Mautner | f4c909b | 2014-04-17 18:39:38 -0700 | [diff] [blame] | 3778 | public void setSurface(Surface surface, int width, int height, int density) { |
Craig Mautner | df88d73 | 2014-01-27 09:21:32 -0800 | [diff] [blame] | 3779 | mService.enforceNotIsolatedCaller("ActivityContainer.attachToSurface"); |
Craig Mautner | 4504de5 | 2013-12-20 09:06:56 -0800 | [diff] [blame] | 3780 | } |
| 3781 | |
Craig Mautner | 4a1cb22 | 2013-12-04 16:14:06 -0800 | [diff] [blame] | 3782 | ActivityStackSupervisor getOuter() { |
| 3783 | return ActivityStackSupervisor.this; |
| 3784 | } |
| 3785 | |
Craig Mautner | d163e75 | 2014-06-13 17:18:47 -0700 | [diff] [blame] | 3786 | boolean isAttachedLocked() { |
Craig Mautner | e0a3884 | 2013-12-16 16:14:02 -0800 | [diff] [blame] | 3787 | return mActivityDisplay != null; |
Craig Mautner | 4a1cb22 | 2013-12-04 16:14:06 -0800 | [diff] [blame] | 3788 | } |
| 3789 | |
Craig Mautner | 6985bad | 2014-04-21 15:22:06 -0700 | [diff] [blame] | 3790 | // 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] | 3791 | void setVisible(boolean visible) { |
| 3792 | if (mVisible != visible) { |
| 3793 | mVisible = visible; |
| 3794 | if (mCallback != null) { |
| 3795 | mHandler.obtainMessage(CONTAINER_CALLBACK_VISIBILITY, visible ? 1 : 0, |
| 3796 | 0 /* unused */, this).sendToTarget(); |
| 3797 | } |
| 3798 | } |
| 3799 | } |
| 3800 | |
Craig Mautner | 6985bad | 2014-04-21 15:22:06 -0700 | [diff] [blame] | 3801 | void setDrawn() { |
| 3802 | } |
| 3803 | |
Craig Mautner | 1b4bf85 | 2014-05-26 15:06:32 -0700 | [diff] [blame] | 3804 | // You can always start a new task on a regular ActivityStack. |
| 3805 | boolean isEligibleForNewTasks() { |
| 3806 | return true; |
| 3807 | } |
| 3808 | |
Craig Mautner | d163e75 | 2014-06-13 17:18:47 -0700 | [diff] [blame] | 3809 | void onTaskListEmptyLocked() { |
Wale Ogunwale | 04f4d6b | 2015-03-11 09:23:25 -0700 | [diff] [blame] | 3810 | detachLocked(); |
| 3811 | deleteActivityContainer(this); |
| 3812 | mHandler.obtainMessage(CONTAINER_CALLBACK_TASK_LIST_EMPTY, this).sendToTarget(); |
Craig Mautner | d94b47f | 2014-06-02 15:06:40 -0700 | [diff] [blame] | 3813 | } |
| 3814 | |
Craig Mautner | 34b73df | 2014-01-12 21:11:08 -0800 | [diff] [blame] | 3815 | @Override |
| 3816 | public String toString() { |
| 3817 | return mIdString + (mActivityDisplay == null ? "N" : "A"); |
| 3818 | } |
Craig Mautner | ed6649f | 2013-12-02 14:08:25 -0800 | [diff] [blame] | 3819 | } |
| 3820 | |
Craig Mautner | f4c909b | 2014-04-17 18:39:38 -0700 | [diff] [blame] | 3821 | private class VirtualActivityContainer extends ActivityContainer { |
| 3822 | Surface mSurface; |
Craig Mautner | 6985bad | 2014-04-21 15:22:06 -0700 | [diff] [blame] | 3823 | boolean mDrawn = false; |
Craig Mautner | f4c909b | 2014-04-17 18:39:38 -0700 | [diff] [blame] | 3824 | |
| 3825 | VirtualActivityContainer(ActivityRecord parent, IActivityContainerCallback callback) { |
| 3826 | super(getNextStackId()); |
| 3827 | mParentActivity = parent; |
| 3828 | mCallback = callback; |
| 3829 | mContainerState = CONTAINER_STATE_NO_SURFACE; |
Craig Mautner | d163e75 | 2014-06-13 17:18:47 -0700 | [diff] [blame] | 3830 | mIdString = "VirtualActivityContainer{" + mStackId + ", parent=" + mParentActivity + "}"; |
Craig Mautner | f4c909b | 2014-04-17 18:39:38 -0700 | [diff] [blame] | 3831 | } |
| 3832 | |
| 3833 | @Override |
| 3834 | public void setSurface(Surface surface, int width, int height, int density) { |
| 3835 | super.setSurface(surface, width, height, density); |
| 3836 | |
| 3837 | synchronized (mService) { |
| 3838 | final long origId = Binder.clearCallingIdentity(); |
| 3839 | try { |
| 3840 | setSurfaceLocked(surface, width, height, density); |
| 3841 | } finally { |
| 3842 | Binder.restoreCallingIdentity(origId); |
| 3843 | } |
| 3844 | } |
| 3845 | } |
| 3846 | |
| 3847 | private void setSurfaceLocked(Surface surface, int width, int height, int density) { |
| 3848 | if (mContainerState == CONTAINER_STATE_FINISHING) { |
| 3849 | return; |
| 3850 | } |
| 3851 | VirtualActivityDisplay virtualActivityDisplay = |
| 3852 | (VirtualActivityDisplay) mActivityDisplay; |
| 3853 | if (virtualActivityDisplay == null) { |
| 3854 | virtualActivityDisplay = |
Craig Mautner | 6985bad | 2014-04-21 15:22:06 -0700 | [diff] [blame] | 3855 | new VirtualActivityDisplay(width, height, density); |
Craig Mautner | f4c909b | 2014-04-17 18:39:38 -0700 | [diff] [blame] | 3856 | mActivityDisplay = virtualActivityDisplay; |
| 3857 | mActivityDisplays.put(virtualActivityDisplay.mDisplayId, virtualActivityDisplay); |
Wale Ogunwale | ddc1cb2 | 2015-07-25 19:23:04 -0700 | [diff] [blame] | 3858 | attachToDisplayLocked(virtualActivityDisplay, true); |
Craig Mautner | f4c909b | 2014-04-17 18:39:38 -0700 | [diff] [blame] | 3859 | } |
| 3860 | |
| 3861 | if (mSurface != null) { |
| 3862 | mSurface.release(); |
Craig Mautner | f4c909b | 2014-04-17 18:39:38 -0700 | [diff] [blame] | 3863 | } |
| 3864 | |
Craig Mautner | 6985bad | 2014-04-21 15:22:06 -0700 | [diff] [blame] | 3865 | mSurface = surface; |
Craig Mautner | f4c909b | 2014-04-17 18:39:38 -0700 | [diff] [blame] | 3866 | if (surface != null) { |
Wale Ogunwale | d046a01 | 2015-12-24 13:05:59 -0800 | [diff] [blame] | 3867 | resumeFocusedStackTopActivityLocked(); |
Craig Mautner | f4c909b | 2014-04-17 18:39:38 -0700 | [diff] [blame] | 3868 | } else { |
| 3869 | mContainerState = CONTAINER_STATE_NO_SURFACE; |
Craig Mautner | 6985bad | 2014-04-21 15:22:06 -0700 | [diff] [blame] | 3870 | ((VirtualActivityDisplay) mActivityDisplay).setSurface(null); |
Craig Mautner | d13a558 | 2014-05-05 12:07:40 -0700 | [diff] [blame] | 3871 | if (mStack.mPausingActivity == null && mStack.mResumedActivity != null) { |
Dianne Hackborn | a4e102e | 2014-09-04 22:52:27 -0700 | [diff] [blame] | 3872 | mStack.startPausingLocked(false, true, false, false); |
Craig Mautner | d13a558 | 2014-05-05 12:07:40 -0700 | [diff] [blame] | 3873 | } |
Craig Mautner | f4c909b | 2014-04-17 18:39:38 -0700 | [diff] [blame] | 3874 | } |
Craig Mautner | 6985bad | 2014-04-21 15:22:06 -0700 | [diff] [blame] | 3875 | |
Craig Mautner | d163e75 | 2014-06-13 17:18:47 -0700 | [diff] [blame] | 3876 | setSurfaceIfReadyLocked(); |
Craig Mautner | 6985bad | 2014-04-21 15:22:06 -0700 | [diff] [blame] | 3877 | |
Wale Ogunwale | ee006da | 2015-03-30 14:49:25 -0700 | [diff] [blame] | 3878 | if (DEBUG_STACK) Slog.d(TAG_STACK, |
| 3879 | "setSurface: " + this + " to display=" + virtualActivityDisplay); |
Craig Mautner | 6985bad | 2014-04-21 15:22:06 -0700 | [diff] [blame] | 3880 | } |
Craig Mautner | f4c909b | 2014-04-17 18:39:38 -0700 | [diff] [blame] | 3881 | |
Craig Mautner | 6985bad | 2014-04-21 15:22:06 -0700 | [diff] [blame] | 3882 | @Override |
Craig Mautner | d163e75 | 2014-06-13 17:18:47 -0700 | [diff] [blame] | 3883 | boolean isAttachedLocked() { |
| 3884 | return mSurface != null && super.isAttachedLocked(); |
Craig Mautner | d13a558 | 2014-05-05 12:07:40 -0700 | [diff] [blame] | 3885 | } |
| 3886 | |
| 3887 | @Override |
Craig Mautner | 6985bad | 2014-04-21 15:22:06 -0700 | [diff] [blame] | 3888 | void setDrawn() { |
| 3889 | synchronized (mService) { |
| 3890 | mDrawn = true; |
Craig Mautner | d163e75 | 2014-06-13 17:18:47 -0700 | [diff] [blame] | 3891 | setSurfaceIfReadyLocked(); |
Craig Mautner | 6985bad | 2014-04-21 15:22:06 -0700 | [diff] [blame] | 3892 | } |
| 3893 | } |
| 3894 | |
Craig Mautner | 1b4bf85 | 2014-05-26 15:06:32 -0700 | [diff] [blame] | 3895 | // Never start a new task on an ActivityView if it isn't explicitly specified. |
| 3896 | @Override |
| 3897 | boolean isEligibleForNewTasks() { |
| 3898 | return false; |
| 3899 | } |
| 3900 | |
Craig Mautner | d163e75 | 2014-06-13 17:18:47 -0700 | [diff] [blame] | 3901 | private void setSurfaceIfReadyLocked() { |
Wale Ogunwale | ee006da | 2015-03-30 14:49:25 -0700 | [diff] [blame] | 3902 | if (DEBUG_STACK) Slog.v(TAG_STACK, "setSurfaceIfReadyLocked: mDrawn=" + mDrawn + |
Craig Mautner | 6985bad | 2014-04-21 15:22:06 -0700 | [diff] [blame] | 3903 | " mContainerState=" + mContainerState + " mSurface=" + mSurface); |
| 3904 | if (mDrawn && mSurface != null && mContainerState == CONTAINER_STATE_NO_SURFACE) { |
| 3905 | ((VirtualActivityDisplay) mActivityDisplay).setSurface(mSurface); |
| 3906 | mContainerState = CONTAINER_STATE_HAS_SURFACE; |
| 3907 | } |
Craig Mautner | f4c909b | 2014-04-17 18:39:38 -0700 | [diff] [blame] | 3908 | } |
| 3909 | } |
| 3910 | |
Craig Mautner | 4a1cb22 | 2013-12-04 16:14:06 -0800 | [diff] [blame] | 3911 | /** Exactly one of these classes per Display in the system. Capable of holding zero or more |
| 3912 | * attached {@link ActivityStack}s */ |
Craig Mautner | f4c909b | 2014-04-17 18:39:38 -0700 | [diff] [blame] | 3913 | class ActivityDisplay { |
Craig Mautner | 4a1cb22 | 2013-12-04 16:14:06 -0800 | [diff] [blame] | 3914 | /** Actual Display this object tracks. */ |
Craig Mautner | 34b73df | 2014-01-12 21:11:08 -0800 | [diff] [blame] | 3915 | int mDisplayId; |
| 3916 | Display mDisplay; |
| 3917 | DisplayInfo mDisplayInfo = new DisplayInfo(); |
Craig Mautner | ed6649f | 2013-12-02 14:08:25 -0800 | [diff] [blame] | 3918 | |
Craig Mautner | 4a1cb22 | 2013-12-04 16:14:06 -0800 | [diff] [blame] | 3919 | /** All of the stacks on this display. Order matters, topmost stack is in front of all other |
| 3920 | * stacks, bottommost behind. Accessed directly by ActivityManager package classes */ |
Wale Ogunwale | 1f544be | 2015-12-17 10:27:23 -0800 | [diff] [blame] | 3921 | final ArrayList<ActivityStack> mStacks = new ArrayList<>(); |
Craig Mautner | 4a1cb22 | 2013-12-04 16:14:06 -0800 | [diff] [blame] | 3922 | |
Jose Lima | 4b6c669 | 2014-08-12 17:41:12 -0700 | [diff] [blame] | 3923 | ActivityRecord mVisibleBehindActivity; |
Craig Mautner | ee2e45a | 2014-06-27 12:10:03 -0700 | [diff] [blame] | 3924 | |
Craig Mautner | f4c909b | 2014-04-17 18:39:38 -0700 | [diff] [blame] | 3925 | ActivityDisplay() { |
| 3926 | } |
Craig Mautner | 4504de5 | 2013-12-20 09:06:56 -0800 | [diff] [blame] | 3927 | |
Craig Mautner | 1a70a16 | 2014-09-13 12:09:31 -0700 | [diff] [blame] | 3928 | // After instantiation, check that mDisplay is not null before using this. The alternative |
| 3929 | // is for this to throw an exception if mDisplayManager.getDisplay() returns null. |
Craig Mautner | e0a3884 | 2013-12-16 16:14:02 -0800 | [diff] [blame] | 3930 | ActivityDisplay(int displayId) { |
Craig Mautner | 1a70a16 | 2014-09-13 12:09:31 -0700 | [diff] [blame] | 3931 | final Display display = mDisplayManager.getDisplay(displayId); |
| 3932 | if (display == null) { |
| 3933 | return; |
| 3934 | } |
| 3935 | init(display); |
Craig Mautner | 4504de5 | 2013-12-20 09:06:56 -0800 | [diff] [blame] | 3936 | } |
| 3937 | |
Craig Mautner | f4c909b | 2014-04-17 18:39:38 -0700 | [diff] [blame] | 3938 | void init(Display display) { |
Craig Mautner | 4504de5 | 2013-12-20 09:06:56 -0800 | [diff] [blame] | 3939 | mDisplay = display; |
| 3940 | mDisplayId = display.getDisplayId(); |
Craig Mautner | 4a1cb22 | 2013-12-04 16:14:06 -0800 | [diff] [blame] | 3941 | mDisplay.getDisplayInfo(mDisplayInfo); |
Craig Mautner | ed6649f | 2013-12-02 14:08:25 -0800 | [diff] [blame] | 3942 | } |
Craig Mautner | 4a1cb22 | 2013-12-04 16:14:06 -0800 | [diff] [blame] | 3943 | |
Wale Ogunwale | ddc1cb2 | 2015-07-25 19:23:04 -0700 | [diff] [blame] | 3944 | void attachActivities(ActivityStack stack, boolean onTop) { |
Wale Ogunwale | ee006da | 2015-03-30 14:49:25 -0700 | [diff] [blame] | 3945 | if (DEBUG_STACK) Slog.v(TAG_STACK, |
Wale Ogunwale | ddc1cb2 | 2015-07-25 19:23:04 -0700 | [diff] [blame] | 3946 | "attachActivities: attaching " + stack + " to displayId=" + mDisplayId |
| 3947 | + " onTop=" + onTop); |
| 3948 | if (onTop) { |
| 3949 | mStacks.add(stack); |
| 3950 | } else { |
| 3951 | mStacks.add(0, stack); |
| 3952 | } |
Craig Mautner | 4a1cb22 | 2013-12-04 16:14:06 -0800 | [diff] [blame] | 3953 | } |
| 3954 | |
Craig Mautner | e0a3884 | 2013-12-16 16:14:02 -0800 | [diff] [blame] | 3955 | void detachActivitiesLocked(ActivityStack stack) { |
Wale Ogunwale | ee006da | 2015-03-30 14:49:25 -0700 | [diff] [blame] | 3956 | if (DEBUG_STACK) Slog.v(TAG_STACK, "detachActivitiesLocked: detaching " + stack |
Craig Mautner | e0a3884 | 2013-12-16 16:14:02 -0800 | [diff] [blame] | 3957 | + " from displayId=" + mDisplayId); |
| 3958 | mStacks.remove(stack); |
Craig Mautner | 4a1cb22 | 2013-12-04 16:14:06 -0800 | [diff] [blame] | 3959 | } |
| 3960 | |
Jose Lima | 4b6c669 | 2014-08-12 17:41:12 -0700 | [diff] [blame] | 3961 | void setVisibleBehindActivity(ActivityRecord r) { |
| 3962 | mVisibleBehindActivity = r; |
Craig Mautner | ee2e45a | 2014-06-27 12:10:03 -0700 | [diff] [blame] | 3963 | } |
| 3964 | |
Jose Lima | 4b6c669 | 2014-08-12 17:41:12 -0700 | [diff] [blame] | 3965 | boolean hasVisibleBehindActivity() { |
| 3966 | return mVisibleBehindActivity != null; |
Craig Mautner | ee2e45a | 2014-06-27 12:10:03 -0700 | [diff] [blame] | 3967 | } |
| 3968 | |
Craig Mautner | 34b73df | 2014-01-12 21:11:08 -0800 | [diff] [blame] | 3969 | @Override |
| 3970 | public String toString() { |
Craig Mautner | f4c909b | 2014-04-17 18:39:38 -0700 | [diff] [blame] | 3971 | return "ActivityDisplay={" + mDisplayId + " numStacks=" + mStacks.size() + "}"; |
| 3972 | } |
| 3973 | } |
| 3974 | |
| 3975 | class VirtualActivityDisplay extends ActivityDisplay { |
| 3976 | VirtualDisplay mVirtualDisplay; |
| 3977 | |
Craig Mautner | 6985bad | 2014-04-21 15:22:06 -0700 | [diff] [blame] | 3978 | VirtualActivityDisplay(int width, int height, int density) { |
Craig Mautner | f4c909b | 2014-04-17 18:39:38 -0700 | [diff] [blame] | 3979 | DisplayManagerGlobal dm = DisplayManagerGlobal.getInstance(); |
Michael Wright | c39d47a | 2014-07-08 18:07:36 -0700 | [diff] [blame] | 3980 | mVirtualDisplay = dm.createVirtualDisplay(mService.mContext, null, |
| 3981 | VIRTUAL_DISPLAY_BASE_NAME, width, height, density, null, |
| 3982 | DisplayManager.VIRTUAL_DISPLAY_FLAG_PUBLIC | |
| 3983 | DisplayManager.VIRTUAL_DISPLAY_FLAG_OWN_CONTENT_ONLY, null, null); |
Craig Mautner | f4c909b | 2014-04-17 18:39:38 -0700 | [diff] [blame] | 3984 | |
| 3985 | init(mVirtualDisplay.getDisplay()); |
| 3986 | |
| 3987 | mWindowManager.handleDisplayAdded(mDisplayId); |
| 3988 | } |
| 3989 | |
| 3990 | void setSurface(Surface surface) { |
| 3991 | if (mVirtualDisplay != null) { |
| 3992 | mVirtualDisplay.setSurface(surface); |
| 3993 | } |
| 3994 | } |
| 3995 | |
| 3996 | @Override |
| 3997 | void detachActivitiesLocked(ActivityStack stack) { |
| 3998 | super.detachActivitiesLocked(stack); |
| 3999 | if (mVirtualDisplay != null) { |
| 4000 | mVirtualDisplay.release(); |
| 4001 | mVirtualDisplay = null; |
| 4002 | } |
| 4003 | } |
| 4004 | |
| 4005 | @Override |
| 4006 | public String toString() { |
| 4007 | return "VirtualActivityDisplay={" + mDisplayId + "}"; |
Craig Mautner | 34b73df | 2014-01-12 21:11:08 -0800 | [diff] [blame] | 4008 | } |
Craig Mautner | ed6649f | 2013-12-02 14:08:25 -0800 | [diff] [blame] | 4009 | } |
Jose Lima | 58e66d6 | 2014-05-27 20:00:27 -0700 | [diff] [blame] | 4010 | |
Wale Ogunwale | 3e3e66f | 2015-09-10 15:40:19 -0700 | [diff] [blame] | 4011 | /** |
| 4012 | * Adjust bounds to stay within stack bounds. |
| 4013 | * |
| 4014 | * Since bounds might be outside of stack bounds, this method tries to move the bounds in a way |
| 4015 | * that keep them unchanged, but be contained within the stack bounds. |
| 4016 | * |
| 4017 | * @param bounds Bounds to be adjusted. |
| 4018 | * @param stackBounds Bounds within which the other bounds should remain. |
| 4019 | */ |
| 4020 | private static void fitWithinBounds(Rect bounds, Rect stackBounds) { |
| 4021 | if (stackBounds == null || stackBounds.contains(bounds)) { |
| 4022 | return; |
| 4023 | } |
| 4024 | |
| 4025 | if (bounds.left < stackBounds.left || bounds.right > stackBounds.right) { |
| 4026 | final int maxRight = stackBounds.right |
| 4027 | - (stackBounds.width() / FIT_WITHIN_BOUNDS_DIVIDER); |
| 4028 | int horizontalDiff = stackBounds.left - bounds.left; |
| 4029 | if ((horizontalDiff < 0 && bounds.left >= maxRight) |
| 4030 | || (bounds.left + horizontalDiff >= maxRight)) { |
| 4031 | horizontalDiff = maxRight - bounds.left; |
| 4032 | } |
| 4033 | bounds.left += horizontalDiff; |
| 4034 | bounds.right += horizontalDiff; |
| 4035 | } |
| 4036 | |
| 4037 | if (bounds.top < stackBounds.top || bounds.bottom > stackBounds.bottom) { |
| 4038 | final int maxBottom = stackBounds.bottom |
| 4039 | - (stackBounds.height() / FIT_WITHIN_BOUNDS_DIVIDER); |
| 4040 | int verticalDiff = stackBounds.top - bounds.top; |
| 4041 | if ((verticalDiff < 0 && bounds.top >= maxBottom) |
| 4042 | || (bounds.top + verticalDiff >= maxBottom)) { |
| 4043 | verticalDiff = maxBottom - bounds.top; |
| 4044 | } |
| 4045 | bounds.top += verticalDiff; |
| 4046 | bounds.bottom += verticalDiff; |
| 4047 | } |
| 4048 | } |
| 4049 | |
Filip Gruszczynski | caae14e | 2015-12-16 14:40:04 -0800 | [diff] [blame] | 4050 | ActivityStack findStackBehind(ActivityStack stack) { |
| 4051 | // TODO(multi-display): We are only looking for stacks on the default display. |
| 4052 | final ActivityDisplay display = mActivityDisplays.get(Display.DEFAULT_DISPLAY); |
| 4053 | if (display == null) { |
| 4054 | return null; |
| 4055 | } |
| 4056 | final ArrayList<ActivityStack> stacks = display.mStacks; |
| 4057 | for (int i = stacks.size() - 1; i >= 0; i--) { |
| 4058 | if (stacks.get(i) == stack && i > 0) { |
| 4059 | return stacks.get(i - 1); |
| 4060 | } |
| 4061 | } |
| 4062 | throw new IllegalStateException("Failed to find a stack behind stack=" + stack |
| 4063 | + " in=" + stacks); |
| 4064 | } |
Craig Mautner | 2708430 | 2013-03-25 08:05:25 -0700 | [diff] [blame] | 4065 | } |