Benjamin Franz | a83859f | 2017-07-03 16:34:14 +0100 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2017, 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 | |
Wale Ogunwale | 5950709 | 2018-10-29 09:00:30 -0700 | [diff] [blame] | 17 | package com.android.server.wm; |
Benjamin Franz | a83859f | 2017-07-03 16:34:14 +0100 | [diff] [blame] | 18 | |
| 19 | import static android.app.ActivityManager.LOCK_TASK_MODE_LOCKED; |
| 20 | import static android.app.ActivityManager.LOCK_TASK_MODE_NONE; |
| 21 | import static android.app.ActivityManager.LOCK_TASK_MODE_PINNED; |
Wale Ogunwale | 0568aed | 2017-09-08 13:29:37 -0700 | [diff] [blame] | 22 | import static android.app.WindowConfiguration.WINDOWING_MODE_UNDEFINED; |
Benjamin Franz | a83859f | 2017-07-03 16:34:14 +0100 | [diff] [blame] | 23 | import static android.content.Context.DEVICE_POLICY_SERVICE; |
| 24 | import static android.content.Context.STATUS_BAR_SERVICE; |
Charles He | 858f132 | 2017-11-27 17:11:04 -0800 | [diff] [blame] | 25 | import static android.content.Intent.ACTION_CALL_EMERGENCY; |
Yuhan Zhao | f3b3d41 | 2020-01-24 23:37:13 +0000 | [diff] [blame] | 26 | import static android.content.pm.ActivityInfo.LOCK_TASK_LAUNCH_MODE_ALWAYS; |
| 27 | import static android.content.pm.ActivityInfo.LOCK_TASK_LAUNCH_MODE_NEVER; |
Benjamin Franz | a83859f | 2017-07-03 16:34:14 +0100 | [diff] [blame] | 28 | import static android.os.UserHandle.USER_ALL; |
Amith Yamasani | 7cbbf222 | 2017-08-30 14:22:37 -0700 | [diff] [blame] | 29 | import static android.os.UserHandle.USER_CURRENT; |
Charles He | 858f132 | 2017-11-27 17:11:04 -0800 | [diff] [blame] | 30 | import static android.telecom.TelecomManager.EMERGENCY_DIALER_COMPONENT; |
Benjamin Franz | a83859f | 2017-07-03 16:34:14 +0100 | [diff] [blame] | 31 | import static android.view.Display.DEFAULT_DISPLAY; |
Charles He | 520b283 | 2017-09-02 15:27:16 +0100 | [diff] [blame] | 32 | |
Wale Ogunwale | 5950709 | 2018-10-29 09:00:30 -0700 | [diff] [blame] | 33 | import static com.android.server.wm.ActivityTaskManagerDebugConfig.DEBUG_LOCKTASK; |
| 34 | import static com.android.server.wm.ActivityTaskManagerDebugConfig.POSTFIX_LOCKTASK; |
| 35 | import static com.android.server.wm.ActivityTaskManagerDebugConfig.TAG_ATM; |
| 36 | import static com.android.server.wm.ActivityTaskManagerDebugConfig.TAG_WITH_CLASS_NAME; |
Louis Chang | cdec080 | 2019-11-11 11:45:07 +0800 | [diff] [blame] | 37 | import static com.android.server.wm.Task.LOCK_TASK_AUTH_DONT_LOCK; |
| 38 | import static com.android.server.wm.Task.LOCK_TASK_AUTH_LAUNCHABLE; |
| 39 | import static com.android.server.wm.Task.LOCK_TASK_AUTH_LAUNCHABLE_PRIV; |
| 40 | import static com.android.server.wm.Task.LOCK_TASK_AUTH_PINNABLE; |
| 41 | import static com.android.server.wm.Task.LOCK_TASK_AUTH_WHITELISTED; |
Benjamin Franz | a83859f | 2017-07-03 16:34:14 +0100 | [diff] [blame] | 42 | |
| 43 | import android.annotation.NonNull; |
| 44 | import android.annotation.Nullable; |
| 45 | import android.app.Activity; |
| 46 | import android.app.ActivityManager; |
Charles He | e078db7 | 2017-10-19 18:03:20 +0100 | [diff] [blame] | 47 | import android.app.StatusBarManager; |
| 48 | import android.app.admin.DevicePolicyManager; |
Benjamin Franz | a83859f | 2017-07-03 16:34:14 +0100 | [diff] [blame] | 49 | import android.app.admin.IDevicePolicyManager; |
Charles He | e078db7 | 2017-10-19 18:03:20 +0100 | [diff] [blame] | 50 | import android.content.ComponentName; |
Benjamin Franz | a83859f | 2017-07-03 16:34:14 +0100 | [diff] [blame] | 51 | import android.content.Context; |
Charles He | 858f132 | 2017-11-27 17:11:04 -0800 | [diff] [blame] | 52 | import android.content.Intent; |
Benjamin Franz | a83859f | 2017-07-03 16:34:14 +0100 | [diff] [blame] | 53 | import android.os.Binder; |
| 54 | import android.os.Debug; |
| 55 | import android.os.Handler; |
| 56 | import android.os.IBinder; |
| 57 | import android.os.RemoteException; |
| 58 | import android.os.ServiceManager; |
Adrian Roos | 1c8e3c0 | 2018-11-20 20:07:55 +0100 | [diff] [blame] | 59 | import android.os.UserHandle; |
Benjamin Franz | a83859f | 2017-07-03 16:34:14 +0100 | [diff] [blame] | 60 | import android.provider.Settings; |
Charles He | 858f132 | 2017-11-27 17:11:04 -0800 | [diff] [blame] | 61 | import android.telecom.TelecomManager; |
Charles He | e078db7 | 2017-10-19 18:03:20 +0100 | [diff] [blame] | 62 | import android.util.Pair; |
Benjamin Franz | a83859f | 2017-07-03 16:34:14 +0100 | [diff] [blame] | 63 | import android.util.Slog; |
Charles He | 520b283 | 2017-09-02 15:27:16 +0100 | [diff] [blame] | 64 | import android.util.SparseArray; |
Charles He | 858f132 | 2017-11-27 17:11:04 -0800 | [diff] [blame] | 65 | import android.util.SparseIntArray; |
Benjamin Franz | a83859f | 2017-07-03 16:34:14 +0100 | [diff] [blame] | 66 | |
| 67 | import com.android.internal.annotations.VisibleForTesting; |
Tony Mak | 2bf3691 | 2018-03-21 15:45:52 +0000 | [diff] [blame] | 68 | import com.android.internal.policy.IKeyguardDismissCallback; |
Benjamin Franz | a83859f | 2017-07-03 16:34:14 +0100 | [diff] [blame] | 69 | import com.android.internal.statusbar.IStatusBarService; |
| 70 | import com.android.internal.widget.LockPatternUtils; |
| 71 | import com.android.server.LocalServices; |
Wale Ogunwale | 5950709 | 2018-10-29 09:00:30 -0700 | [diff] [blame] | 72 | import com.android.server.am.ActivityManagerService; |
Benjamin Franz | a83859f | 2017-07-03 16:34:14 +0100 | [diff] [blame] | 73 | import com.android.server.statusbar.StatusBarManagerInternal; |
Benjamin Franz | a83859f | 2017-07-03 16:34:14 +0100 | [diff] [blame] | 74 | |
| 75 | import java.io.PrintWriter; |
| 76 | import java.util.ArrayList; |
Charles He | 520b283 | 2017-09-02 15:27:16 +0100 | [diff] [blame] | 77 | import java.util.Arrays; |
Benjamin Franz | a83859f | 2017-07-03 16:34:14 +0100 | [diff] [blame] | 78 | |
| 79 | /** |
| 80 | * Helper class that deals with all things related to task locking. This includes the screen pinning |
| 81 | * mode that can be launched via System UI as well as the fully locked mode that can be achieved |
| 82 | * on fully managed devices. |
| 83 | * |
Wale Ogunwale | 27c48ae | 2018-10-25 19:01:01 -0700 | [diff] [blame] | 84 | * Note: All methods in this class should only be called with the ActivityTaskManagerService lock |
| 85 | * held. |
Benjamin Franz | a83859f | 2017-07-03 16:34:14 +0100 | [diff] [blame] | 86 | * |
| 87 | * @see Activity#startLockTask() |
| 88 | * @see Activity#stopLockTask() |
| 89 | */ |
| 90 | public class LockTaskController { |
Wale Ogunwale | 9887561 | 2018-10-12 07:53:02 -0700 | [diff] [blame] | 91 | private static final String TAG = TAG_WITH_CLASS_NAME ? "LockTaskController" : TAG_ATM; |
Benjamin Franz | a83859f | 2017-07-03 16:34:14 +0100 | [diff] [blame] | 92 | private static final String TAG_LOCKTASK = TAG + POSTFIX_LOCKTASK; |
| 93 | |
| 94 | @VisibleForTesting |
Charles He | e078db7 | 2017-10-19 18:03:20 +0100 | [diff] [blame] | 95 | static final int STATUS_BAR_MASK_LOCKED = StatusBarManager.DISABLE_MASK |
| 96 | & (~StatusBarManager.DISABLE_EXPAND) |
| 97 | & (~StatusBarManager.DISABLE_NOTIFICATION_TICKER) |
| 98 | & (~StatusBarManager.DISABLE_SYSTEM_INFO) |
| 99 | & (~StatusBarManager.DISABLE_BACK); |
Benjamin Franz | a83859f | 2017-07-03 16:34:14 +0100 | [diff] [blame] | 100 | @VisibleForTesting |
Charles He | e078db7 | 2017-10-19 18:03:20 +0100 | [diff] [blame] | 101 | static final int STATUS_BAR_MASK_PINNED = StatusBarManager.DISABLE_MASK |
| 102 | & (~StatusBarManager.DISABLE_BACK) |
| 103 | & (~StatusBarManager.DISABLE_HOME) |
| 104 | & (~StatusBarManager.DISABLE_RECENT); |
| 105 | |
| 106 | private static final SparseArray<Pair<Integer, Integer>> STATUS_BAR_FLAG_MAP_LOCKED; |
| 107 | static { |
| 108 | STATUS_BAR_FLAG_MAP_LOCKED = new SparseArray<>(); |
| 109 | |
| 110 | STATUS_BAR_FLAG_MAP_LOCKED.append(DevicePolicyManager.LOCK_TASK_FEATURE_SYSTEM_INFO, |
| 111 | new Pair<>(StatusBarManager.DISABLE_CLOCK, StatusBarManager.DISABLE2_SYSTEM_ICONS)); |
| 112 | |
| 113 | STATUS_BAR_FLAG_MAP_LOCKED.append(DevicePolicyManager.LOCK_TASK_FEATURE_NOTIFICATIONS, |
| 114 | new Pair<>(StatusBarManager.DISABLE_NOTIFICATION_ICONS |
| 115 | | StatusBarManager.DISABLE_NOTIFICATION_ALERTS, |
| 116 | StatusBarManager.DISABLE2_NOTIFICATION_SHADE)); |
| 117 | |
| 118 | STATUS_BAR_FLAG_MAP_LOCKED.append(DevicePolicyManager.LOCK_TASK_FEATURE_HOME, |
| 119 | new Pair<>(StatusBarManager.DISABLE_HOME, StatusBarManager.DISABLE2_NONE)); |
| 120 | |
Benjamin Franz | caffa77 | 2018-02-05 16:36:10 +0000 | [diff] [blame] | 121 | STATUS_BAR_FLAG_MAP_LOCKED.append(DevicePolicyManager.LOCK_TASK_FEATURE_OVERVIEW, |
Charles He | e078db7 | 2017-10-19 18:03:20 +0100 | [diff] [blame] | 122 | new Pair<>(StatusBarManager.DISABLE_RECENT, StatusBarManager.DISABLE2_NONE)); |
| 123 | |
| 124 | STATUS_BAR_FLAG_MAP_LOCKED.append(DevicePolicyManager.LOCK_TASK_FEATURE_GLOBAL_ACTIONS, |
| 125 | new Pair<>(StatusBarManager.DISABLE_NONE, |
| 126 | StatusBarManager.DISABLE2_GLOBAL_ACTIONS)); |
| 127 | } |
Benjamin Franz | a83859f | 2017-07-03 16:34:14 +0100 | [diff] [blame] | 128 | |
| 129 | /** Tag used for disabling of keyguard */ |
| 130 | private static final String LOCK_TASK_TAG = "Lock-to-App"; |
| 131 | |
Adrian Roos | 1c8e3c0 | 2018-11-20 20:07:55 +0100 | [diff] [blame] | 132 | private final IBinder mToken = new LockTaskToken(); |
Benjamin Franz | a83859f | 2017-07-03 16:34:14 +0100 | [diff] [blame] | 133 | private final ActivityStackSupervisor mSupervisor; |
| 134 | private final Context mContext; |
| 135 | |
| 136 | // The following system services cannot be final, because they do not exist when this class |
| 137 | // is instantiated during device boot |
| 138 | @VisibleForTesting |
| 139 | IStatusBarService mStatusBarService; |
| 140 | @VisibleForTesting |
| 141 | IDevicePolicyManager mDevicePolicyManager; |
| 142 | @VisibleForTesting |
| 143 | WindowManagerService mWindowManager; |
| 144 | @VisibleForTesting |
| 145 | LockPatternUtils mLockPatternUtils; |
Charles He | 858f132 | 2017-11-27 17:11:04 -0800 | [diff] [blame] | 146 | @VisibleForTesting |
| 147 | TelecomManager mTelecomManager; |
Benjamin Franz | a83859f | 2017-07-03 16:34:14 +0100 | [diff] [blame] | 148 | |
| 149 | /** |
Charles He | ff9b4dff | 2017-09-22 10:18:37 +0100 | [diff] [blame] | 150 | * The chain of tasks in LockTask mode, in the order of when they first entered LockTask mode. |
| 151 | * |
| 152 | * The first task in the list, which started the current LockTask session, is called the root |
| 153 | * task. It coincides with the Home task in a typical multi-app kiosk deployment. When there are |
| 154 | * more than one locked tasks, the root task can't be finished. Nor can it be moved to the back |
Wale Ogunwale | 85fb19a | 2019-12-05 10:41:05 +0900 | [diff] [blame] | 155 | * of the stack by {@link ActivityStack#moveTaskToBack(Task)}; |
Charles He | ff9b4dff | 2017-09-22 10:18:37 +0100 | [diff] [blame] | 156 | * |
| 157 | * Calling {@link Activity#stopLockTask()} on the root task will finish all tasks but itself in |
| 158 | * this list, and the device will exit LockTask mode. |
| 159 | * |
| 160 | * The list is empty if LockTask is inactive. |
Benjamin Franz | a83859f | 2017-07-03 16:34:14 +0100 | [diff] [blame] | 161 | */ |
Louis Chang | cdec080 | 2019-11-11 11:45:07 +0800 | [diff] [blame] | 162 | private final ArrayList<Task> mLockTaskModeTasks = new ArrayList<>(); |
Benjamin Franz | a83859f | 2017-07-03 16:34:14 +0100 | [diff] [blame] | 163 | |
| 164 | /** |
Charles He | 520b283 | 2017-09-02 15:27:16 +0100 | [diff] [blame] | 165 | * Packages that are allowed to be launched into the lock task mode for each user. |
| 166 | */ |
| 167 | private final SparseArray<String[]> mLockTaskPackages = new SparseArray<>(); |
| 168 | |
| 169 | /** |
Charles He | e078db7 | 2017-10-19 18:03:20 +0100 | [diff] [blame] | 170 | * Features that are allowed by DPC to show during LockTask mode. |
| 171 | */ |
Charles He | 858f132 | 2017-11-27 17:11:04 -0800 | [diff] [blame] | 172 | private final SparseIntArray mLockTaskFeatures = new SparseIntArray(); |
Charles He | e078db7 | 2017-10-19 18:03:20 +0100 | [diff] [blame] | 173 | |
| 174 | /** |
Benjamin Franz | a83859f | 2017-07-03 16:34:14 +0100 | [diff] [blame] | 175 | * Store the current lock task mode. Possible values: |
| 176 | * {@link ActivityManager#LOCK_TASK_MODE_NONE}, {@link ActivityManager#LOCK_TASK_MODE_LOCKED}, |
| 177 | * {@link ActivityManager#LOCK_TASK_MODE_PINNED} |
| 178 | */ |
Charles He | ff9b4dff | 2017-09-22 10:18:37 +0100 | [diff] [blame] | 179 | private int mLockTaskModeState = LOCK_TASK_MODE_NONE; |
Benjamin Franz | a83859f | 2017-07-03 16:34:14 +0100 | [diff] [blame] | 180 | |
| 181 | /** |
| 182 | * This is ActivityStackSupervisor's Handler. |
| 183 | */ |
| 184 | private final Handler mHandler; |
| 185 | |
Adrian Roos | 1c8e3c0 | 2018-11-20 20:07:55 +0100 | [diff] [blame] | 186 | /** |
| 187 | * Stores the user for which we're trying to dismiss the keyguard and then subsequently |
| 188 | * disable it. |
| 189 | * |
| 190 | * Tracking this ensures we don't mistakenly disable the keyguard if we've stopped trying to |
| 191 | * between the dismiss request and when it succeeds. |
| 192 | * |
| 193 | * Must only be accessed from the Handler thread. |
| 194 | */ |
| 195 | private int mPendingDisableFromDismiss = UserHandle.USER_NULL; |
| 196 | |
Benjamin Franz | a83859f | 2017-07-03 16:34:14 +0100 | [diff] [blame] | 197 | LockTaskController(Context context, ActivityStackSupervisor supervisor, |
| 198 | Handler handler) { |
| 199 | mContext = context; |
| 200 | mSupervisor = supervisor; |
| 201 | mHandler = handler; |
| 202 | } |
| 203 | |
| 204 | /** |
| 205 | * Set the window manager instance used in this class. This is necessary, because the window |
| 206 | * manager does not exist during instantiation of this class. |
| 207 | */ |
| 208 | void setWindowManager(WindowManagerService windowManager) { |
| 209 | mWindowManager = windowManager; |
| 210 | } |
| 211 | |
| 212 | /** |
| 213 | * @return the current lock task state. This can be any of |
| 214 | * {@link ActivityManager#LOCK_TASK_MODE_NONE}, {@link ActivityManager#LOCK_TASK_MODE_LOCKED}, |
| 215 | * {@link ActivityManager#LOCK_TASK_MODE_PINNED}. |
| 216 | */ |
| 217 | int getLockTaskModeState() { |
| 218 | return mLockTaskModeState; |
| 219 | } |
| 220 | |
| 221 | /** |
Charles He | 520b283 | 2017-09-02 15:27:16 +0100 | [diff] [blame] | 222 | * @return whether the given task is locked at the moment. Locked tasks cannot be moved to the |
| 223 | * back of the stack. |
Benjamin Franz | a83859f | 2017-07-03 16:34:14 +0100 | [diff] [blame] | 224 | */ |
Charles He | ff9b4dff | 2017-09-22 10:18:37 +0100 | [diff] [blame] | 225 | @VisibleForTesting |
Louis Chang | cdec080 | 2019-11-11 11:45:07 +0800 | [diff] [blame] | 226 | boolean isTaskLocked(Task task) { |
Charles He | ff9b4dff | 2017-09-22 10:18:37 +0100 | [diff] [blame] | 227 | return mLockTaskModeTasks.contains(task); |
| 228 | } |
| 229 | |
| 230 | /** |
| 231 | * @return {@code true} whether this task first started the current LockTask session. |
| 232 | */ |
Louis Chang | cdec080 | 2019-11-11 11:45:07 +0800 | [diff] [blame] | 233 | private boolean isRootTask(Task task) { |
Charles He | ff9b4dff | 2017-09-22 10:18:37 +0100 | [diff] [blame] | 234 | return mLockTaskModeTasks.indexOf(task) == 0; |
| 235 | } |
| 236 | |
| 237 | /** |
| 238 | * @return whether the given activity is blocked from finishing, because it is the only activity |
| 239 | * of the last locked task and finishing it would mean that lock task mode is ended illegally. |
| 240 | */ |
| 241 | boolean activityBlockedFromFinish(ActivityRecord activity) { |
Louis Chang | cdec080 | 2019-11-11 11:45:07 +0800 | [diff] [blame] | 242 | final Task task = activity.getTask(); |
Charles He | ff9b4dff | 2017-09-22 10:18:37 +0100 | [diff] [blame] | 243 | if (activity == task.getRootActivity() |
Wale Ogunwale | 21e0648 | 2019-11-18 05:14:15 -0800 | [diff] [blame] | 244 | && activity == task.getTopNonFinishingActivity() |
Charles He | ff9b4dff | 2017-09-22 10:18:37 +0100 | [diff] [blame] | 245 | && task.mLockTaskAuth != LOCK_TASK_AUTH_LAUNCHABLE_PRIV |
| 246 | && isRootTask(task)) { |
| 247 | Slog.i(TAG, "Not finishing task in lock task mode"); |
Benjamin Franz | a83859f | 2017-07-03 16:34:14 +0100 | [diff] [blame] | 248 | showLockTaskToast(); |
| 249 | return true; |
| 250 | } |
| 251 | return false; |
| 252 | } |
| 253 | |
| 254 | /** |
Charles He | ff9b4dff | 2017-09-22 10:18:37 +0100 | [diff] [blame] | 255 | * @return whether the given task can be moved to the back of the stack with |
Wale Ogunwale | 85fb19a | 2019-12-05 10:41:05 +0900 | [diff] [blame] | 256 | * {@link ActivityStack#moveTaskToBack(Task)} |
Charles He | ff9b4dff | 2017-09-22 10:18:37 +0100 | [diff] [blame] | 257 | * @see #mLockTaskModeTasks |
Benjamin Franz | a83859f | 2017-07-03 16:34:14 +0100 | [diff] [blame] | 258 | */ |
Louis Chang | cdec080 | 2019-11-11 11:45:07 +0800 | [diff] [blame] | 259 | boolean canMoveTaskToBack(Task task) { |
Charles He | ff9b4dff | 2017-09-22 10:18:37 +0100 | [diff] [blame] | 260 | if (isRootTask(task)) { |
Benjamin Franz | a83859f | 2017-07-03 16:34:14 +0100 | [diff] [blame] | 261 | showLockTaskToast(); |
Charles He | ff9b4dff | 2017-09-22 10:18:37 +0100 | [diff] [blame] | 262 | return false; |
Benjamin Franz | a83859f | 2017-07-03 16:34:14 +0100 | [diff] [blame] | 263 | } |
Charles He | ff9b4dff | 2017-09-22 10:18:37 +0100 | [diff] [blame] | 264 | return true; |
Benjamin Franz | a83859f | 2017-07-03 16:34:14 +0100 | [diff] [blame] | 265 | } |
| 266 | |
| 267 | /** |
Charles He | d62f965 | 2017-11-01 10:05:51 +0000 | [diff] [blame] | 268 | * @return whether the requested task is allowed to be locked (either whitelisted, or declares |
| 269 | * lockTaskMode="always" in the manifest). |
| 270 | */ |
Louis Chang | cdec080 | 2019-11-11 11:45:07 +0800 | [diff] [blame] | 271 | boolean isTaskWhitelisted(Task task) { |
Charles He | d62f965 | 2017-11-01 10:05:51 +0000 | [diff] [blame] | 272 | switch(task.mLockTaskAuth) { |
| 273 | case LOCK_TASK_AUTH_WHITELISTED: |
| 274 | case LOCK_TASK_AUTH_LAUNCHABLE: |
| 275 | case LOCK_TASK_AUTH_LAUNCHABLE_PRIV: |
| 276 | return true; |
| 277 | case LOCK_TASK_AUTH_PINNABLE: |
| 278 | case LOCK_TASK_AUTH_DONT_LOCK: |
| 279 | default: |
| 280 | return false; |
| 281 | } |
| 282 | } |
| 283 | |
| 284 | /** |
| 285 | * @return whether the requested task is disallowed to be launched. |
Benjamin Franz | a83859f | 2017-07-03 16:34:14 +0100 | [diff] [blame] | 286 | */ |
Louis Chang | cdec080 | 2019-11-11 11:45:07 +0800 | [diff] [blame] | 287 | boolean isLockTaskModeViolation(Task task) { |
Benjamin Franz | a83859f | 2017-07-03 16:34:14 +0100 | [diff] [blame] | 288 | return isLockTaskModeViolation(task, false); |
| 289 | } |
| 290 | |
| 291 | /** |
| 292 | * @param isNewClearTask whether the task would be cleared as part of the operation. |
Charles He | d62f965 | 2017-11-01 10:05:51 +0000 | [diff] [blame] | 293 | * @return whether the requested task is disallowed to be launched. |
Benjamin Franz | a83859f | 2017-07-03 16:34:14 +0100 | [diff] [blame] | 294 | */ |
Louis Chang | cdec080 | 2019-11-11 11:45:07 +0800 | [diff] [blame] | 295 | boolean isLockTaskModeViolation(Task task, boolean isNewClearTask) { |
Benjamin Franz | a83859f | 2017-07-03 16:34:14 +0100 | [diff] [blame] | 296 | if (isLockTaskModeViolationInternal(task, isNewClearTask)) { |
| 297 | showLockTaskToast(); |
| 298 | return true; |
| 299 | } |
| 300 | return false; |
| 301 | } |
| 302 | |
Benjamin Franz | 7dcbfb0 | 2018-01-16 15:16:16 +0000 | [diff] [blame] | 303 | /** |
| 304 | * @return the root task of the lock task. |
| 305 | */ |
Louis Chang | cdec080 | 2019-11-11 11:45:07 +0800 | [diff] [blame] | 306 | Task getRootTask() { |
Benjamin Franz | 7dcbfb0 | 2018-01-16 15:16:16 +0000 | [diff] [blame] | 307 | if (mLockTaskModeTasks.isEmpty()) { |
| 308 | return null; |
| 309 | } |
| 310 | return mLockTaskModeTasks.get(0); |
| 311 | } |
| 312 | |
Louis Chang | cdec080 | 2019-11-11 11:45:07 +0800 | [diff] [blame] | 313 | private boolean isLockTaskModeViolationInternal(Task task, boolean isNewClearTask) { |
Benjamin Franz | a83859f | 2017-07-03 16:34:14 +0100 | [diff] [blame] | 314 | // TODO: Double check what's going on here. If the task is already in lock task mode, it's |
| 315 | // likely whitelisted, so will return false below. |
Charles He | ff9b4dff | 2017-09-22 10:18:37 +0100 | [diff] [blame] | 316 | if (isTaskLocked(task) && !isNewClearTask) { |
Benjamin Franz | a83859f | 2017-07-03 16:34:14 +0100 | [diff] [blame] | 317 | // If the task is already at the top and won't be cleared, then allow the operation |
| 318 | return false; |
| 319 | } |
Charles He | d62f965 | 2017-11-01 10:05:51 +0000 | [diff] [blame] | 320 | |
| 321 | // Allow recents activity if enabled by policy |
Wale Ogunwale | 4e79a1c | 2019-10-05 20:52:40 -0700 | [diff] [blame] | 322 | if (task.isActivityTypeRecents() && isRecentsAllowed(task.mUserId)) { |
Charles He | d62f965 | 2017-11-01 10:05:51 +0000 | [diff] [blame] | 323 | return false; |
Benjamin Franz | a83859f | 2017-07-03 16:34:14 +0100 | [diff] [blame] | 324 | } |
Charles He | d62f965 | 2017-11-01 10:05:51 +0000 | [diff] [blame] | 325 | |
Charles He | 858f132 | 2017-11-27 17:11:04 -0800 | [diff] [blame] | 326 | // Allow emergency calling when the device is protected by a locked keyguard |
Wale Ogunwale | 4e79a1c | 2019-10-05 20:52:40 -0700 | [diff] [blame] | 327 | if (isKeyguardAllowed(task.mUserId) && isEmergencyCallTask(task)) { |
Charles He | 858f132 | 2017-11-27 17:11:04 -0800 | [diff] [blame] | 328 | return false; |
| 329 | } |
| 330 | |
Charles He | d62f965 | 2017-11-01 10:05:51 +0000 | [diff] [blame] | 331 | return !(isTaskWhitelisted(task) || mLockTaskModeTasks.isEmpty()); |
| 332 | } |
| 333 | |
| 334 | private boolean isRecentsAllowed(int userId) { |
| 335 | return (getLockTaskFeaturesForUser(userId) |
Benjamin Franz | caffa77 | 2018-02-05 16:36:10 +0000 | [diff] [blame] | 336 | & DevicePolicyManager.LOCK_TASK_FEATURE_OVERVIEW) != 0; |
Benjamin Franz | a83859f | 2017-07-03 16:34:14 +0100 | [diff] [blame] | 337 | } |
| 338 | |
Charles He | 858f132 | 2017-11-27 17:11:04 -0800 | [diff] [blame] | 339 | private boolean isKeyguardAllowed(int userId) { |
| 340 | return (getLockTaskFeaturesForUser(userId) |
| 341 | & DevicePolicyManager.LOCK_TASK_FEATURE_KEYGUARD) != 0; |
| 342 | } |
| 343 | |
Yuhan Zhao | f3b3d41 | 2020-01-24 23:37:13 +0000 | [diff] [blame] | 344 | private boolean isBlockingInTaskEnabled(int userId) { |
| 345 | return (getLockTaskFeaturesForUser(userId) |
| 346 | & DevicePolicyManager.LOCK_TASK_FEATURE_BLOCK_ACTIVITY_START_IN_TASK) != 0; |
| 347 | } |
| 348 | |
| 349 | boolean isActivityAllowed(int userId, String packageName, int lockTaskLaunchMode) { |
| 350 | if (mLockTaskModeState != LOCK_TASK_MODE_LOCKED || !isBlockingInTaskEnabled(userId)) { |
| 351 | return true; |
| 352 | } |
| 353 | switch (lockTaskLaunchMode) { |
| 354 | case LOCK_TASK_LAUNCH_MODE_ALWAYS: |
| 355 | return true; |
| 356 | case LOCK_TASK_LAUNCH_MODE_NEVER: |
| 357 | return false; |
| 358 | default: |
| 359 | } |
| 360 | return isPackageWhitelisted(userId, packageName); |
| 361 | } |
| 362 | |
Louis Chang | cdec080 | 2019-11-11 11:45:07 +0800 | [diff] [blame] | 363 | private boolean isEmergencyCallTask(Task task) { |
Charles He | 858f132 | 2017-11-27 17:11:04 -0800 | [diff] [blame] | 364 | final Intent intent = task.intent; |
| 365 | if (intent == null) { |
| 366 | return false; |
| 367 | } |
| 368 | |
| 369 | // 1. The emergency keypad activity launched on top of the keyguard |
| 370 | if (EMERGENCY_DIALER_COMPONENT.equals(intent.getComponent())) { |
| 371 | return true; |
| 372 | } |
| 373 | |
| 374 | // 2. The intent sent by the keypad, which is handled by Telephony |
| 375 | if (ACTION_CALL_EMERGENCY.equals(intent.getAction())) { |
| 376 | return true; |
| 377 | } |
| 378 | |
| 379 | // 3. Telephony then starts the default package for making the call |
| 380 | final TelecomManager tm = getTelecomManager(); |
| 381 | final String dialerPackage = tm != null ? tm.getSystemDialerPackage() : null; |
| 382 | if (dialerPackage != null && dialerPackage.equals(intent.getComponent().getPackageName())) { |
| 383 | return true; |
| 384 | } |
| 385 | |
| 386 | return false; |
| 387 | } |
| 388 | |
Benjamin Franz | a83859f | 2017-07-03 16:34:14 +0100 | [diff] [blame] | 389 | /** |
| 390 | * Stop the current lock task mode. |
| 391 | * |
Charles He | ff9b4dff | 2017-09-22 10:18:37 +0100 | [diff] [blame] | 392 | * This is called by {@link ActivityManagerService} and performs various checks before actually |
| 393 | * finishing the locked task. |
| 394 | * |
| 395 | * @param task the task that requested the end of lock task mode ({@code null} for quitting app |
| 396 | * pinning mode) |
| 397 | * @param isSystemCaller indicates whether this request comes from the system via |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 398 | * {@link ActivityTaskManagerService#stopSystemLockTaskMode()}. If |
Charles He | ff9b4dff | 2017-09-22 10:18:37 +0100 | [diff] [blame] | 399 | * {@code true}, it means the user intends to stop pinned mode through UI; |
| 400 | * otherwise, it's called by an app and we need to stop locked or pinned |
| 401 | * mode, subject to checks. |
Benjamin Franz | a83859f | 2017-07-03 16:34:14 +0100 | [diff] [blame] | 402 | * @param callingUid the caller that requested the end of lock task mode. |
Charles He | ff9b4dff | 2017-09-22 10:18:37 +0100 | [diff] [blame] | 403 | * @throws IllegalArgumentException if the calling task is invalid (e.g., {@code null} or not in |
| 404 | * foreground) |
Benjamin Franz | a83859f | 2017-07-03 16:34:14 +0100 | [diff] [blame] | 405 | * @throws SecurityException if the caller is not authorized to stop the lock task mode, i.e. if |
| 406 | * they differ from the one that launched lock task mode. |
| 407 | */ |
Louis Chang | cdec080 | 2019-11-11 11:45:07 +0800 | [diff] [blame] | 408 | void stopLockTaskMode(@Nullable Task task, boolean isSystemCaller, int callingUid) { |
Charles He | ff9b4dff | 2017-09-22 10:18:37 +0100 | [diff] [blame] | 409 | if (mLockTaskModeState == LOCK_TASK_MODE_NONE) { |
Benjamin Franz | a83859f | 2017-07-03 16:34:14 +0100 | [diff] [blame] | 410 | return; |
| 411 | } |
| 412 | |
Charles He | ff9b4dff | 2017-09-22 10:18:37 +0100 | [diff] [blame] | 413 | if (isSystemCaller) { |
| 414 | if (mLockTaskModeState == LOCK_TASK_MODE_PINNED) { |
| 415 | clearLockedTasks("stopAppPinning"); |
| 416 | } else { |
| 417 | Slog.e(TAG_LOCKTASK, "Attempted to stop LockTask with isSystemCaller=true"); |
| 418 | showLockTaskToast(); |
| 419 | } |
| 420 | |
| 421 | } else { |
| 422 | // Ensure calling activity is not null |
| 423 | if (task == null) { |
| 424 | throw new IllegalArgumentException("can't stop LockTask for null task"); |
| 425 | } |
| 426 | |
| 427 | // Ensure the same caller for startLockTaskMode and stopLockTaskMode. |
| 428 | // It is possible lockTaskMode was started by the system process because |
| 429 | // android:lockTaskMode is set to a locking value in the application manifest |
| 430 | // instead of the app calling startLockTaskMode. In this case |
Louis Chang | cdec080 | 2019-11-11 11:45:07 +0800 | [diff] [blame] | 431 | // {@link Task.mLockTaskUid} will be 0, so we compare the callingUid to the |
| 432 | // {@link Task.effectiveUid} instead. Also caller with |
Charles He | ff9b4dff | 2017-09-22 10:18:37 +0100 | [diff] [blame] | 433 | // {@link MANAGE_ACTIVITY_STACKS} can stop any lock task. |
| 434 | if (callingUid != task.mLockTaskUid |
| 435 | && (task.mLockTaskUid != 0 || callingUid != task.effectiveUid)) { |
| 436 | throw new SecurityException("Invalid uid, expected " + task.mLockTaskUid |
| 437 | + " callingUid=" + callingUid + " effectiveUid=" + task.effectiveUid); |
| 438 | } |
| 439 | |
| 440 | // We don't care if it's pinned or locked mode; this will stop it anyways. |
| 441 | clearLockedTask(task); |
| 442 | } |
| 443 | } |
| 444 | |
| 445 | /** |
| 446 | * Clear all locked tasks and request the end of LockTask mode. |
| 447 | * |
Wale Ogunwale | 5950709 | 2018-10-29 09:00:30 -0700 | [diff] [blame] | 448 | * This method is called by UserController when starting a new foreground user, and, |
Louis Chang | cdec080 | 2019-11-11 11:45:07 +0800 | [diff] [blame] | 449 | * unlike {@link #stopLockTaskMode(Task, boolean, int)}, it doesn't perform the checks. |
Charles He | ff9b4dff | 2017-09-22 10:18:37 +0100 | [diff] [blame] | 450 | */ |
| 451 | void clearLockedTasks(String reason) { |
| 452 | if (DEBUG_LOCKTASK) Slog.i(TAG_LOCKTASK, "clearLockedTasks: " + reason); |
| 453 | if (!mLockTaskModeTasks.isEmpty()) { |
| 454 | clearLockedTask(mLockTaskModeTasks.get(0)); |
| 455 | } |
| 456 | } |
| 457 | |
| 458 | /** |
| 459 | * Clear one locked task from LockTask mode. |
| 460 | * |
| 461 | * If the requested task is the root task (see {@link #mLockTaskModeTasks}), then all locked |
| 462 | * tasks are cleared. Otherwise, only the requested task is cleared. LockTask mode is stopped |
| 463 | * when the last locked task is cleared. |
| 464 | * |
| 465 | * @param task the task to be cleared from LockTask mode. |
| 466 | */ |
Louis Chang | cdec080 | 2019-11-11 11:45:07 +0800 | [diff] [blame] | 467 | void clearLockedTask(final Task task) { |
Charles He | ff9b4dff | 2017-09-22 10:18:37 +0100 | [diff] [blame] | 468 | if (task == null || mLockTaskModeTasks.isEmpty()) return; |
| 469 | |
| 470 | if (task == mLockTaskModeTasks.get(0)) { |
| 471 | // We're removing the root task while there are other locked tasks. Therefore we should |
| 472 | // clear all locked tasks in reverse order. |
| 473 | for (int taskNdx = mLockTaskModeTasks.size() - 1; taskNdx > 0; --taskNdx) { |
| 474 | clearLockedTask(mLockTaskModeTasks.get(taskNdx)); |
| 475 | } |
| 476 | } |
| 477 | |
| 478 | removeLockedTask(task); |
| 479 | if (mLockTaskModeTasks.isEmpty()) { |
Benjamin Franz | a83859f | 2017-07-03 16:34:14 +0100 | [diff] [blame] | 480 | return; |
| 481 | } |
Charles He | ff9b4dff | 2017-09-22 10:18:37 +0100 | [diff] [blame] | 482 | task.performClearTaskLocked(); |
Louis Chang | 149d5c8 | 2019-12-30 09:47:39 +0800 | [diff] [blame] | 483 | mSupervisor.mRootWindowContainer.resumeFocusedStacksTopActivities(); |
Benjamin Franz | a83859f | 2017-07-03 16:34:14 +0100 | [diff] [blame] | 484 | } |
| 485 | |
| 486 | /** |
| 487 | * Remove the given task from the locked task list. If this was the last task in the list, |
| 488 | * lock task mode is stopped. |
| 489 | */ |
Louis Chang | cdec080 | 2019-11-11 11:45:07 +0800 | [diff] [blame] | 490 | private void removeLockedTask(final Task task) { |
Benjamin Franz | a83859f | 2017-07-03 16:34:14 +0100 | [diff] [blame] | 491 | if (!mLockTaskModeTasks.remove(task)) { |
| 492 | return; |
| 493 | } |
Charles He | ff9b4dff | 2017-09-22 10:18:37 +0100 | [diff] [blame] | 494 | if (DEBUG_LOCKTASK) Slog.d(TAG_LOCKTASK, "removeLockedTask: removed " + task); |
Benjamin Franz | a83859f | 2017-07-03 16:34:14 +0100 | [diff] [blame] | 495 | if (mLockTaskModeTasks.isEmpty()) { |
Benjamin Franz | a83859f | 2017-07-03 16:34:14 +0100 | [diff] [blame] | 496 | if (DEBUG_LOCKTASK) Slog.d(TAG_LOCKTASK, "removeLockedTask: task=" + task + |
| 497 | " last task, reverting locktask mode. Callers=" + Debug.getCallers(3)); |
Wale Ogunwale | 4e79a1c | 2019-10-05 20:52:40 -0700 | [diff] [blame] | 498 | mHandler.post(() -> performStopLockTask(task.mUserId)); |
Benjamin Franz | a83859f | 2017-07-03 16:34:14 +0100 | [diff] [blame] | 499 | } |
| 500 | } |
| 501 | |
Benjamin Franz | a83859f | 2017-07-03 16:34:14 +0100 | [diff] [blame] | 502 | // This method should only be called on the handler thread |
| 503 | private void performStopLockTask(int userId) { |
| 504 | // When lock task ends, we enable the status bars. |
| 505 | try { |
Charles He | e078db7 | 2017-10-19 18:03:20 +0100 | [diff] [blame] | 506 | setStatusBarState(LOCK_TASK_MODE_NONE, userId); |
| 507 | setKeyguardState(LOCK_TASK_MODE_NONE, userId); |
| 508 | if (mLockTaskModeState == LOCK_TASK_MODE_PINNED) { |
| 509 | lockKeyguardIfNeeded(); |
Benjamin Franz | a83859f | 2017-07-03 16:34:14 +0100 | [diff] [blame] | 510 | } |
Benjamin Franz | a83859f | 2017-07-03 16:34:14 +0100 | [diff] [blame] | 511 | if (getDevicePolicyManager() != null) { |
| 512 | getDevicePolicyManager().notifyLockTaskModeChanged(false, null, userId); |
| 513 | } |
Charles He | bfe82d1 | 2017-10-20 11:59:44 +0100 | [diff] [blame] | 514 | if (mLockTaskModeState == LOCK_TASK_MODE_PINNED) { |
Matthew Ng | 9c3bce5 | 2018-02-01 22:00:31 +0000 | [diff] [blame] | 515 | getStatusBarService().showPinningEnterExitToast(false /* entering */); |
Charles He | bfe82d1 | 2017-10-20 11:59:44 +0100 | [diff] [blame] | 516 | } |
Benjamin Franz | 3662b15 | 2018-01-16 17:23:44 +0000 | [diff] [blame] | 517 | mWindowManager.onLockTaskStateChanged(LOCK_TASK_MODE_NONE); |
Benjamin Franz | a83859f | 2017-07-03 16:34:14 +0100 | [diff] [blame] | 518 | } catch (RemoteException ex) { |
| 519 | throw new RuntimeException(ex); |
| 520 | } finally { |
| 521 | mLockTaskModeState = LOCK_TASK_MODE_NONE; |
| 522 | } |
| 523 | } |
| 524 | |
| 525 | /** |
Charles He | bfe82d1 | 2017-10-20 11:59:44 +0100 | [diff] [blame] | 526 | * Show the lock task violation toast. Currently we only show toast for screen pinning mode, and |
| 527 | * no-op if the device is in locked mode. |
Benjamin Franz | a83859f | 2017-07-03 16:34:14 +0100 | [diff] [blame] | 528 | */ |
| 529 | void showLockTaskToast() { |
Charles He | bfe82d1 | 2017-10-20 11:59:44 +0100 | [diff] [blame] | 530 | if (mLockTaskModeState == LOCK_TASK_MODE_PINNED) { |
Matthew Ng | 9c3bce5 | 2018-02-01 22:00:31 +0000 | [diff] [blame] | 531 | try { |
| 532 | getStatusBarService().showPinningEscapeToast(); |
| 533 | } catch (RemoteException e) { |
| 534 | Slog.e(TAG, "Failed to send pinning escape toast", e); |
| 535 | } |
Charles He | bfe82d1 | 2017-10-20 11:59:44 +0100 | [diff] [blame] | 536 | } |
Benjamin Franz | a83859f | 2017-07-03 16:34:14 +0100 | [diff] [blame] | 537 | } |
| 538 | |
| 539 | // Starting lock task |
| 540 | |
| 541 | /** |
| 542 | * Method to start lock task mode on a given task. |
| 543 | * |
| 544 | * @param task the task that should be locked. |
Charles He | ff9b4dff | 2017-09-22 10:18:37 +0100 | [diff] [blame] | 545 | * @param isSystemCaller indicates whether this request was initiated by the system via |
Wale Ogunwale | 04d9cb5 | 2018-04-30 13:55:07 -0700 | [diff] [blame] | 546 | * {@link ActivityTaskManagerService#startSystemLockTaskMode(int)}. If |
Charles He | ff9b4dff | 2017-09-22 10:18:37 +0100 | [diff] [blame] | 547 | * {@code true}, this intends to start pinned mode; otherwise, we look |
| 548 | * at the calling task's mLockTaskAuth to decide which mode to start. |
Benjamin Franz | a83859f | 2017-07-03 16:34:14 +0100 | [diff] [blame] | 549 | * @param callingUid the caller that requested the launch of lock task mode. |
| 550 | */ |
Louis Chang | cdec080 | 2019-11-11 11:45:07 +0800 | [diff] [blame] | 551 | void startLockTaskMode(@NonNull Task task, boolean isSystemCaller, int callingUid) { |
Charles He | ff9b4dff | 2017-09-22 10:18:37 +0100 | [diff] [blame] | 552 | if (!isSystemCaller) { |
Benjamin Franz | a83859f | 2017-07-03 16:34:14 +0100 | [diff] [blame] | 553 | task.mLockTaskUid = callingUid; |
| 554 | if (task.mLockTaskAuth == LOCK_TASK_AUTH_PINNABLE) { |
| 555 | // startLockTask() called by app, but app is not part of lock task whitelist. Show |
Charles He | ff9b4dff | 2017-09-22 10:18:37 +0100 | [diff] [blame] | 556 | // app pinning request. We will come back here with isSystemCaller true. |
Benjamin Franz | a83859f | 2017-07-03 16:34:14 +0100 | [diff] [blame] | 557 | if (DEBUG_LOCKTASK) Slog.w(TAG_LOCKTASK, "Mode default, asking user"); |
| 558 | StatusBarManagerInternal statusBarManager = LocalServices.getService( |
| 559 | StatusBarManagerInternal.class); |
| 560 | if (statusBarManager != null) { |
Wale Ogunwale | 4e79a1c | 2019-10-05 20:52:40 -0700 | [diff] [blame] | 561 | statusBarManager.showScreenPinningRequest(task.mTaskId); |
Benjamin Franz | a83859f | 2017-07-03 16:34:14 +0100 | [diff] [blame] | 562 | } |
| 563 | return; |
| 564 | } |
| 565 | } |
| 566 | |
| 567 | // System can only initiate screen pinning, not full lock task mode |
Charles He | ff9b4dff | 2017-09-22 10:18:37 +0100 | [diff] [blame] | 568 | if (DEBUG_LOCKTASK) Slog.w(TAG_LOCKTASK, |
| 569 | isSystemCaller ? "Locking pinned" : "Locking fully"); |
| 570 | setLockTaskMode(task, isSystemCaller ? LOCK_TASK_MODE_PINNED : LOCK_TASK_MODE_LOCKED, |
Benjamin Franz | a83859f | 2017-07-03 16:34:14 +0100 | [diff] [blame] | 571 | "startLockTask", true); |
| 572 | } |
| 573 | |
| 574 | /** |
| 575 | * Start lock task mode on the given task. |
| 576 | * @param lockTaskModeState whether fully locked or pinned mode. |
| 577 | * @param andResume whether the task should be brought to foreground as part of the operation. |
| 578 | */ |
Louis Chang | cdec080 | 2019-11-11 11:45:07 +0800 | [diff] [blame] | 579 | private void setLockTaskMode(@NonNull Task task, int lockTaskModeState, |
Benjamin Franz | a83859f | 2017-07-03 16:34:14 +0100 | [diff] [blame] | 580 | String reason, boolean andResume) { |
| 581 | // Should have already been checked, but do it again. |
| 582 | if (task.mLockTaskAuth == LOCK_TASK_AUTH_DONT_LOCK) { |
| 583 | if (DEBUG_LOCKTASK) Slog.w(TAG_LOCKTASK, |
| 584 | "setLockTaskMode: Can't lock due to auth"); |
| 585 | return; |
| 586 | } |
| 587 | if (isLockTaskModeViolation(task)) { |
| 588 | Slog.e(TAG_LOCKTASK, "setLockTaskMode: Attempt to start an unauthorized lock task."); |
| 589 | return; |
| 590 | } |
| 591 | |
Bryce Lee | 1a990e5 | 2018-04-23 10:54:11 -0700 | [diff] [blame] | 592 | final Intent taskIntent = task.intent; |
| 593 | if (mLockTaskModeTasks.isEmpty() && taskIntent != null) { |
Wale Ogunwale | 4e79a1c | 2019-10-05 20:52:40 -0700 | [diff] [blame] | 594 | mSupervisor.mRecentTasks.onLockTaskModeStateChanged(lockTaskModeState, task.mUserId); |
Benjamin Franz | a83859f | 2017-07-03 16:34:14 +0100 | [diff] [blame] | 595 | // Start lock task on the handler thread |
| 596 | mHandler.post(() -> performStartLockTask( |
Bryce Lee | 1a990e5 | 2018-04-23 10:54:11 -0700 | [diff] [blame] | 597 | taskIntent.getComponent().getPackageName(), |
Wale Ogunwale | 4e79a1c | 2019-10-05 20:52:40 -0700 | [diff] [blame] | 598 | task.mUserId, |
Benjamin Franz | a83859f | 2017-07-03 16:34:14 +0100 | [diff] [blame] | 599 | lockTaskModeState)); |
| 600 | } |
Benjamin Franz | a83859f | 2017-07-03 16:34:14 +0100 | [diff] [blame] | 601 | if (DEBUG_LOCKTASK) Slog.w(TAG_LOCKTASK, "setLockTaskMode: Locking to " + task + |
| 602 | " Callers=" + Debug.getCallers(4)); |
Charles He | ff9b4dff | 2017-09-22 10:18:37 +0100 | [diff] [blame] | 603 | |
| 604 | if (!mLockTaskModeTasks.contains(task)) { |
| 605 | mLockTaskModeTasks.add(task); |
| 606 | } |
Benjamin Franz | a83859f | 2017-07-03 16:34:14 +0100 | [diff] [blame] | 607 | |
| 608 | if (task.mLockTaskUid == -1) { |
| 609 | task.mLockTaskUid = task.effectiveUid; |
| 610 | } |
| 611 | |
| 612 | if (andResume) { |
Wale Ogunwale | 66e1685 | 2017-10-19 13:35:52 -0700 | [diff] [blame] | 613 | mSupervisor.findTaskToMoveToFront(task, 0, null, reason, |
Benjamin Franz | a83859f | 2017-07-03 16:34:14 +0100 | [diff] [blame] | 614 | lockTaskModeState != LOCK_TASK_MODE_NONE); |
Louis Chang | 149d5c8 | 2019-12-30 09:47:39 +0800 | [diff] [blame] | 615 | mSupervisor.mRootWindowContainer.resumeFocusedStacksTopActivities(); |
lumark | 588a3e8 | 2018-07-20 18:53:54 +0800 | [diff] [blame] | 616 | final ActivityStack stack = task.getStack(); |
| 617 | if (stack != null) { |
Wale Ogunwale | 3a256e6 | 2018-12-06 14:41:18 -0800 | [diff] [blame] | 618 | stack.getDisplay().mDisplayContent.executeAppTransition(); |
lumark | 588a3e8 | 2018-07-20 18:53:54 +0800 | [diff] [blame] | 619 | } |
Benjamin Franz | a83859f | 2017-07-03 16:34:14 +0100 | [diff] [blame] | 620 | } else if (lockTaskModeState != LOCK_TASK_MODE_NONE) { |
Wale Ogunwale | 0568aed | 2017-09-08 13:29:37 -0700 | [diff] [blame] | 621 | mSupervisor.handleNonResizableTaskIfNeeded(task, WINDOWING_MODE_UNDEFINED, |
Wale Ogunwale | a0f5b5e | 2017-10-11 09:37:23 -0700 | [diff] [blame] | 622 | DEFAULT_DISPLAY, task.getStack(), true /* forceNonResizable */); |
Benjamin Franz | a83859f | 2017-07-03 16:34:14 +0100 | [diff] [blame] | 623 | } |
| 624 | } |
| 625 | |
| 626 | // This method should only be called on the handler thread |
| 627 | private void performStartLockTask(String packageName, int userId, int lockTaskModeState) { |
| 628 | // When lock task starts, we disable the status bars. |
| 629 | try { |
Charles He | bfe82d1 | 2017-10-20 11:59:44 +0100 | [diff] [blame] | 630 | if (lockTaskModeState == LOCK_TASK_MODE_PINNED) { |
Matthew Ng | 9c3bce5 | 2018-02-01 22:00:31 +0000 | [diff] [blame] | 631 | getStatusBarService().showPinningEnterExitToast(true /* entering */); |
Charles He | bfe82d1 | 2017-10-20 11:59:44 +0100 | [diff] [blame] | 632 | } |
Benjamin Franz | 3662b15 | 2018-01-16 17:23:44 +0000 | [diff] [blame] | 633 | mWindowManager.onLockTaskStateChanged(lockTaskModeState); |
Benjamin Franz | a83859f | 2017-07-03 16:34:14 +0100 | [diff] [blame] | 634 | mLockTaskModeState = lockTaskModeState; |
Charles He | e078db7 | 2017-10-19 18:03:20 +0100 | [diff] [blame] | 635 | setStatusBarState(lockTaskModeState, userId); |
| 636 | setKeyguardState(lockTaskModeState, userId); |
Benjamin Franz | a83859f | 2017-07-03 16:34:14 +0100 | [diff] [blame] | 637 | if (getDevicePolicyManager() != null) { |
| 638 | getDevicePolicyManager().notifyLockTaskModeChanged(true, packageName, userId); |
| 639 | } |
| 640 | } catch (RemoteException ex) { |
| 641 | throw new RuntimeException(ex); |
| 642 | } |
| 643 | } |
| 644 | |
| 645 | /** |
Charles He | 520b283 | 2017-09-02 15:27:16 +0100 | [diff] [blame] | 646 | * Update packages that are allowed to be launched in lock task mode. |
| 647 | * @param userId Which user this whitelist is associated with |
| 648 | * @param packages The whitelist of packages allowed in lock task mode |
| 649 | * @see #mLockTaskPackages |
Benjamin Franz | a83859f | 2017-07-03 16:34:14 +0100 | [diff] [blame] | 650 | */ |
Charles He | 520b283 | 2017-09-02 15:27:16 +0100 | [diff] [blame] | 651 | void updateLockTaskPackages(int userId, String[] packages) { |
| 652 | mLockTaskPackages.put(userId, packages); |
| 653 | |
| 654 | boolean taskChanged = false; |
Benjamin Franz | a83859f | 2017-07-03 16:34:14 +0100 | [diff] [blame] | 655 | for (int taskNdx = mLockTaskModeTasks.size() - 1; taskNdx >= 0; --taskNdx) { |
Louis Chang | cdec080 | 2019-11-11 11:45:07 +0800 | [diff] [blame] | 656 | final Task lockedTask = mLockTaskModeTasks.get(taskNdx); |
Charles He | 520b283 | 2017-09-02 15:27:16 +0100 | [diff] [blame] | 657 | final boolean wasWhitelisted = lockedTask.mLockTaskAuth == LOCK_TASK_AUTH_LAUNCHABLE |
| 658 | || lockedTask.mLockTaskAuth == LOCK_TASK_AUTH_WHITELISTED; |
Benjamin Franz | a83859f | 2017-07-03 16:34:14 +0100 | [diff] [blame] | 659 | lockedTask.setLockTaskAuth(); |
Charles He | 520b283 | 2017-09-02 15:27:16 +0100 | [diff] [blame] | 660 | final boolean isWhitelisted = lockedTask.mLockTaskAuth == LOCK_TASK_AUTH_LAUNCHABLE |
| 661 | || lockedTask.mLockTaskAuth == LOCK_TASK_AUTH_WHITELISTED; |
| 662 | |
| 663 | if (mLockTaskModeState != LOCK_TASK_MODE_LOCKED |
Wale Ogunwale | 4e79a1c | 2019-10-05 20:52:40 -0700 | [diff] [blame] | 664 | || lockedTask.mUserId != userId |
Charles He | 520b283 | 2017-09-02 15:27:16 +0100 | [diff] [blame] | 665 | || !wasWhitelisted || isWhitelisted) { |
| 666 | continue; |
Benjamin Franz | a83859f | 2017-07-03 16:34:14 +0100 | [diff] [blame] | 667 | } |
Charles He | 520b283 | 2017-09-02 15:27:16 +0100 | [diff] [blame] | 668 | |
| 669 | // Terminate locked tasks that have recently lost whitelist authorization. |
| 670 | if (DEBUG_LOCKTASK) Slog.d(TAG_LOCKTASK, "onLockTaskPackagesUpdated: removing " + |
| 671 | lockedTask + " mLockTaskAuth()=" + lockedTask.lockTaskAuthToString()); |
| 672 | removeLockedTask(lockedTask); |
| 673 | lockedTask.performClearTaskLocked(); |
| 674 | taskChanged = true; |
Benjamin Franz | a83859f | 2017-07-03 16:34:14 +0100 | [diff] [blame] | 675 | } |
| 676 | |
Louis Chang | 149d5c8 | 2019-12-30 09:47:39 +0800 | [diff] [blame] | 677 | mSupervisor.mRootWindowContainer.forAllTasks(Task::setLockTaskAuth); |
Charles He | 520b283 | 2017-09-02 15:27:16 +0100 | [diff] [blame] | 678 | |
Louis Chang | 149d5c8 | 2019-12-30 09:47:39 +0800 | [diff] [blame] | 679 | final ActivityRecord r = mSupervisor.mRootWindowContainer.topRunningActivity(); |
Louis Chang | cdec080 | 2019-11-11 11:45:07 +0800 | [diff] [blame] | 680 | final Task task = (r != null) ? r.getTask() : null; |
Charles He | 520b283 | 2017-09-02 15:27:16 +0100 | [diff] [blame] | 681 | if (mLockTaskModeTasks.isEmpty() && task!= null |
Benjamin Franz | a83859f | 2017-07-03 16:34:14 +0100 | [diff] [blame] | 682 | && task.mLockTaskAuth == LOCK_TASK_AUTH_LAUNCHABLE) { |
| 683 | // This task must have just been authorized. |
| 684 | if (DEBUG_LOCKTASK) Slog.d(TAG_LOCKTASK, |
| 685 | "onLockTaskPackagesUpdated: starting new locktask task=" + task); |
Charles He | 520b283 | 2017-09-02 15:27:16 +0100 | [diff] [blame] | 686 | setLockTaskMode(task, LOCK_TASK_MODE_LOCKED, "package updated", false); |
| 687 | taskChanged = true; |
Benjamin Franz | a83859f | 2017-07-03 16:34:14 +0100 | [diff] [blame] | 688 | } |
Charles He | 520b283 | 2017-09-02 15:27:16 +0100 | [diff] [blame] | 689 | |
| 690 | if (taskChanged) { |
Louis Chang | 149d5c8 | 2019-12-30 09:47:39 +0800 | [diff] [blame] | 691 | mSupervisor.mRootWindowContainer.resumeFocusedStacksTopActivities(); |
Benjamin Franz | a83859f | 2017-07-03 16:34:14 +0100 | [diff] [blame] | 692 | } |
| 693 | } |
| 694 | |
Charles He | 520b283 | 2017-09-02 15:27:16 +0100 | [diff] [blame] | 695 | boolean isPackageWhitelisted(int userId, String pkg) { |
| 696 | if (pkg == null) { |
| 697 | return false; |
| 698 | } |
| 699 | String[] whitelist; |
| 700 | whitelist = mLockTaskPackages.get(userId); |
| 701 | if (whitelist == null) { |
| 702 | return false; |
| 703 | } |
| 704 | for (String whitelistedPkg : whitelist) { |
| 705 | if (pkg.equals(whitelistedPkg)) { |
| 706 | return true; |
| 707 | } |
| 708 | } |
| 709 | return false; |
| 710 | } |
| 711 | |
Benjamin Franz | a83859f | 2017-07-03 16:34:14 +0100 | [diff] [blame] | 712 | /** |
Charles He | e078db7 | 2017-10-19 18:03:20 +0100 | [diff] [blame] | 713 | * Update the UI features that are enabled for LockTask mode. |
| 714 | * @param userId Which user these feature flags are associated with |
| 715 | * @param flags Bitfield of feature flags |
| 716 | * @see DevicePolicyManager#setLockTaskFeatures(ComponentName, int) |
| 717 | */ |
| 718 | void updateLockTaskFeatures(int userId, int flags) { |
| 719 | int oldFlags = getLockTaskFeaturesForUser(userId); |
| 720 | if (flags == oldFlags) { |
| 721 | return; |
| 722 | } |
| 723 | |
| 724 | mLockTaskFeatures.put(userId, flags); |
Wale Ogunwale | 4e79a1c | 2019-10-05 20:52:40 -0700 | [diff] [blame] | 725 | if (!mLockTaskModeTasks.isEmpty() && userId == mLockTaskModeTasks.get(0).mUserId) { |
Charles He | e078db7 | 2017-10-19 18:03:20 +0100 | [diff] [blame] | 726 | mHandler.post(() -> { |
| 727 | if (mLockTaskModeState == LOCK_TASK_MODE_LOCKED) { |
| 728 | setStatusBarState(mLockTaskModeState, userId); |
| 729 | setKeyguardState(mLockTaskModeState, userId); |
| 730 | } |
| 731 | }); |
| 732 | } |
| 733 | } |
| 734 | |
| 735 | /** |
| 736 | * Helper method for configuring the status bar disabled state. |
| 737 | * Should only be called on the handler thread to avoid race. |
| 738 | */ |
| 739 | private void setStatusBarState(int lockTaskModeState, int userId) { |
| 740 | IStatusBarService statusBar = getStatusBarService(); |
| 741 | if (statusBar == null) { |
| 742 | Slog.e(TAG, "Can't find StatusBarService"); |
| 743 | return; |
| 744 | } |
| 745 | |
| 746 | // Default state, when lockTaskModeState == LOCK_TASK_MODE_NONE |
| 747 | int flags1 = StatusBarManager.DISABLE_NONE; |
| 748 | int flags2 = StatusBarManager.DISABLE2_NONE; |
| 749 | |
| 750 | if (lockTaskModeState == LOCK_TASK_MODE_PINNED) { |
| 751 | flags1 = STATUS_BAR_MASK_PINNED; |
| 752 | |
| 753 | } else if (lockTaskModeState == LOCK_TASK_MODE_LOCKED) { |
| 754 | int lockTaskFeatures = getLockTaskFeaturesForUser(userId); |
| 755 | Pair<Integer, Integer> statusBarFlags = getStatusBarDisableFlags(lockTaskFeatures); |
| 756 | flags1 = statusBarFlags.first; |
| 757 | flags2 = statusBarFlags.second; |
| 758 | } |
| 759 | |
| 760 | try { |
| 761 | statusBar.disable(flags1, mToken, mContext.getPackageName()); |
| 762 | statusBar.disable2(flags2, mToken, mContext.getPackageName()); |
| 763 | } catch (RemoteException e) { |
| 764 | Slog.e(TAG, "Failed to set status bar flags", e); |
| 765 | } |
| 766 | } |
| 767 | |
| 768 | /** |
| 769 | * Helper method for configuring the keyguard disabled state. |
| 770 | * Should only be called on the handler thread to avoid race. |
| 771 | */ |
| 772 | private void setKeyguardState(int lockTaskModeState, int userId) { |
Adrian Roos | 1c8e3c0 | 2018-11-20 20:07:55 +0100 | [diff] [blame] | 773 | mPendingDisableFromDismiss = UserHandle.USER_NULL; |
Charles He | e078db7 | 2017-10-19 18:03:20 +0100 | [diff] [blame] | 774 | if (lockTaskModeState == LOCK_TASK_MODE_NONE) { |
Adrian Roos | 1c8e3c0 | 2018-11-20 20:07:55 +0100 | [diff] [blame] | 775 | mWindowManager.reenableKeyguard(mToken, userId); |
Charles He | e078db7 | 2017-10-19 18:03:20 +0100 | [diff] [blame] | 776 | |
| 777 | } else if (lockTaskModeState == LOCK_TASK_MODE_LOCKED) { |
Charles He | 858f132 | 2017-11-27 17:11:04 -0800 | [diff] [blame] | 778 | if (isKeyguardAllowed(userId)) { |
Adrian Roos | 1c8e3c0 | 2018-11-20 20:07:55 +0100 | [diff] [blame] | 779 | mWindowManager.reenableKeyguard(mToken, userId); |
Charles He | 858f132 | 2017-11-27 17:11:04 -0800 | [diff] [blame] | 780 | } else { |
Tony Mak | 2bf3691 | 2018-03-21 15:45:52 +0000 | [diff] [blame] | 781 | // If keyguard is not secure and it is locked, dismiss the keyguard before |
| 782 | // disabling it, which avoids the platform to think the keyguard is still on. |
Brad Stenning | 2bdc21e | 2019-03-11 14:33:22 -0700 | [diff] [blame] | 783 | if (mWindowManager.isKeyguardLocked() && !mWindowManager.isKeyguardSecure(userId)) { |
Adrian Roos | 1c8e3c0 | 2018-11-20 20:07:55 +0100 | [diff] [blame] | 784 | mPendingDisableFromDismiss = userId; |
Tony Mak | 2bf3691 | 2018-03-21 15:45:52 +0000 | [diff] [blame] | 785 | mWindowManager.dismissKeyguard(new IKeyguardDismissCallback.Stub() { |
| 786 | @Override |
| 787 | public void onDismissError() throws RemoteException { |
| 788 | Slog.i(TAG, "setKeyguardState: failed to dismiss keyguard"); |
| 789 | } |
| 790 | |
| 791 | @Override |
| 792 | public void onDismissSucceeded() throws RemoteException { |
| 793 | mHandler.post( |
Adrian Roos | 1c8e3c0 | 2018-11-20 20:07:55 +0100 | [diff] [blame] | 794 | () -> { |
| 795 | if (mPendingDisableFromDismiss == userId) { |
| 796 | mWindowManager.disableKeyguard(mToken, LOCK_TASK_TAG, |
| 797 | userId); |
| 798 | mPendingDisableFromDismiss = UserHandle.USER_NULL; |
| 799 | } |
| 800 | }); |
Tony Mak | 2bf3691 | 2018-03-21 15:45:52 +0000 | [diff] [blame] | 801 | } |
| 802 | |
| 803 | @Override |
| 804 | public void onDismissCancelled() throws RemoteException { |
| 805 | Slog.i(TAG, "setKeyguardState: dismiss cancelled"); |
| 806 | } |
| 807 | }, null); |
| 808 | } else { |
Adrian Roos | 1c8e3c0 | 2018-11-20 20:07:55 +0100 | [diff] [blame] | 809 | mWindowManager.disableKeyguard(mToken, LOCK_TASK_TAG, userId); |
Tony Mak | 2bf3691 | 2018-03-21 15:45:52 +0000 | [diff] [blame] | 810 | } |
Charles He | e078db7 | 2017-10-19 18:03:20 +0100 | [diff] [blame] | 811 | } |
| 812 | |
| 813 | } else { // lockTaskModeState == LOCK_TASK_MODE_PINNED |
Adrian Roos | 1c8e3c0 | 2018-11-20 20:07:55 +0100 | [diff] [blame] | 814 | mWindowManager.disableKeyguard(mToken, LOCK_TASK_TAG, userId); |
Charles He | e078db7 | 2017-10-19 18:03:20 +0100 | [diff] [blame] | 815 | } |
| 816 | } |
| 817 | |
| 818 | /** |
| 819 | * Helper method for locking the device immediately. This may be necessary when the device |
| 820 | * leaves the pinned mode. |
| 821 | */ |
| 822 | private void lockKeyguardIfNeeded() { |
Jonathan Scott | 851d469 | 2019-04-29 18:03:58 +0100 | [diff] [blame] | 823 | if (shouldLockKeyguard()) { |
| 824 | mWindowManager.lockNow(null); |
| 825 | mWindowManager.dismissKeyguard(null /* callback */, null /* message */); |
| 826 | getLockPatternUtils().requireCredentialEntry(USER_ALL); |
| 827 | } |
| 828 | } |
| 829 | |
| 830 | private boolean shouldLockKeyguard() { |
| 831 | // This functionality should be kept consistent with |
| 832 | // com.android.settings.security.ScreenPinningSettings (see b/127605586) |
Charles He | e078db7 | 2017-10-19 18:03:20 +0100 | [diff] [blame] | 833 | try { |
Jonathan Scott | 851d469 | 2019-04-29 18:03:58 +0100 | [diff] [blame] | 834 | return Settings.Secure.getIntForUser( |
Charles He | e078db7 | 2017-10-19 18:03:20 +0100 | [diff] [blame] | 835 | mContext.getContentResolver(), |
Jonathan Scott | 851d469 | 2019-04-29 18:03:58 +0100 | [diff] [blame] | 836 | Settings.Secure.LOCK_TO_APP_EXIT_LOCKED, USER_CURRENT) != 0; |
Charles He | e078db7 | 2017-10-19 18:03:20 +0100 | [diff] [blame] | 837 | } catch (Settings.SettingNotFoundException e) { |
Jonathan Scott | 851d469 | 2019-04-29 18:03:58 +0100 | [diff] [blame] | 838 | // Log to SafetyNet for b/127605586 |
| 839 | android.util.EventLog.writeEvent(0x534e4554, "127605586", -1, ""); |
Jonathan Scott | aa2d6b8 | 2019-05-13 12:21:50 +0100 | [diff] [blame] | 840 | return getLockPatternUtils().isSecure(USER_CURRENT); |
Charles He | e078db7 | 2017-10-19 18:03:20 +0100 | [diff] [blame] | 841 | } |
| 842 | } |
| 843 | |
| 844 | /** |
| 845 | * Translates from LockTask feature flags to StatusBarManager disable and disable2 flags. |
| 846 | * @param lockTaskFlags Bitfield of flags as per |
| 847 | * {@link DevicePolicyManager#setLockTaskFeatures(ComponentName, int)} |
| 848 | * @return A {@link Pair} of {@link StatusBarManager#disable(int)} and |
| 849 | * {@link StatusBarManager#disable2(int)} flags |
| 850 | */ |
| 851 | @VisibleForTesting |
| 852 | Pair<Integer, Integer> getStatusBarDisableFlags(int lockTaskFlags) { |
| 853 | // Everything is disabled by default |
| 854 | int flags1 = StatusBarManager.DISABLE_MASK; |
| 855 | int flags2 = StatusBarManager.DISABLE2_MASK; |
| 856 | for (int i = STATUS_BAR_FLAG_MAP_LOCKED.size() - 1; i >= 0; i--) { |
| 857 | Pair<Integer, Integer> statusBarFlags = STATUS_BAR_FLAG_MAP_LOCKED.valueAt(i); |
| 858 | if ((STATUS_BAR_FLAG_MAP_LOCKED.keyAt(i) & lockTaskFlags) != 0) { |
| 859 | flags1 &= ~statusBarFlags.first; |
| 860 | flags2 &= ~statusBarFlags.second; |
| 861 | } |
| 862 | } |
| 863 | // Some flags are not used for LockTask purposes, so we mask them |
| 864 | flags1 &= STATUS_BAR_MASK_LOCKED; |
| 865 | return new Pair<>(flags1, flags2); |
| 866 | } |
| 867 | |
| 868 | /** |
| 869 | * Gets the cached value of LockTask feature flags for a specific user. |
| 870 | */ |
| 871 | private int getLockTaskFeaturesForUser(int userId) { |
| 872 | return mLockTaskFeatures.get(userId, DevicePolicyManager.LOCK_TASK_FEATURE_NONE); |
| 873 | } |
| 874 | |
Benjamin Franz | a83859f | 2017-07-03 16:34:14 +0100 | [diff] [blame] | 875 | // Should only be called on the handler thread |
| 876 | @Nullable |
| 877 | private IStatusBarService getStatusBarService() { |
| 878 | if (mStatusBarService == null) { |
| 879 | mStatusBarService = IStatusBarService.Stub.asInterface( |
| 880 | ServiceManager.checkService(STATUS_BAR_SERVICE)); |
| 881 | if (mStatusBarService == null) { |
| 882 | Slog.w("StatusBarManager", "warning: no STATUS_BAR_SERVICE"); |
| 883 | } |
| 884 | } |
| 885 | return mStatusBarService; |
| 886 | } |
| 887 | |
| 888 | // Should only be called on the handler thread |
| 889 | @Nullable |
| 890 | private IDevicePolicyManager getDevicePolicyManager() { |
| 891 | if (mDevicePolicyManager == null) { |
| 892 | mDevicePolicyManager = IDevicePolicyManager.Stub.asInterface( |
| 893 | ServiceManager.checkService(DEVICE_POLICY_SERVICE)); |
| 894 | if (mDevicePolicyManager == null) { |
| 895 | Slog.w(TAG, "warning: no DEVICE_POLICY_SERVICE"); |
| 896 | } |
| 897 | } |
| 898 | return mDevicePolicyManager; |
| 899 | } |
| 900 | |
| 901 | @NonNull |
| 902 | private LockPatternUtils getLockPatternUtils() { |
| 903 | if (mLockPatternUtils == null) { |
| 904 | // We don't preserve the LPU object to save memory |
| 905 | return new LockPatternUtils(mContext); |
| 906 | } |
| 907 | return mLockPatternUtils; |
| 908 | } |
| 909 | |
Charles He | 858f132 | 2017-11-27 17:11:04 -0800 | [diff] [blame] | 910 | @Nullable |
| 911 | private TelecomManager getTelecomManager() { |
| 912 | if (mTelecomManager == null) { |
| 913 | // We don't preserve the TelecomManager object to save memory |
| 914 | return mContext.getSystemService(TelecomManager.class); |
| 915 | } |
| 916 | return mTelecomManager; |
| 917 | } |
| 918 | |
Benjamin Franz | a83859f | 2017-07-03 16:34:14 +0100 | [diff] [blame] | 919 | public void dump(PrintWriter pw, String prefix) { |
Charles He | 520b283 | 2017-09-02 15:27:16 +0100 | [diff] [blame] | 920 | pw.println(prefix + "LockTaskController"); |
| 921 | prefix = prefix + " "; |
| 922 | pw.println(prefix + "mLockTaskModeState=" + lockTaskModeToString()); |
| 923 | pw.println(prefix + "mLockTaskModeTasks="); |
| 924 | for (int i = 0; i < mLockTaskModeTasks.size(); ++i) { |
| 925 | pw.println(prefix + " #" + i + " " + mLockTaskModeTasks.get(i)); |
| 926 | } |
| 927 | pw.println(prefix + "mLockTaskPackages (userId:packages)="); |
| 928 | for (int i = 0; i < mLockTaskPackages.size(); ++i) { |
| 929 | pw.println(prefix + " u" + mLockTaskPackages.keyAt(i) |
| 930 | + ":" + Arrays.toString(mLockTaskPackages.valueAt(i))); |
| 931 | } |
Benjamin Franz | a83859f | 2017-07-03 16:34:14 +0100 | [diff] [blame] | 932 | } |
| 933 | |
| 934 | private String lockTaskModeToString() { |
| 935 | switch (mLockTaskModeState) { |
| 936 | case LOCK_TASK_MODE_LOCKED: |
| 937 | return "LOCKED"; |
| 938 | case LOCK_TASK_MODE_PINNED: |
| 939 | return "PINNED"; |
| 940 | case LOCK_TASK_MODE_NONE: |
| 941 | return "NONE"; |
| 942 | default: return "unknown=" + mLockTaskModeState; |
| 943 | } |
| 944 | } |
Adrian Roos | 1c8e3c0 | 2018-11-20 20:07:55 +0100 | [diff] [blame] | 945 | |
| 946 | /** Marker class for the token used to disable keyguard. */ |
| 947 | static class LockTaskToken extends Binder { |
| 948 | private LockTaskToken() { |
| 949 | } |
| 950 | } |
Benjamin Franz | a83859f | 2017-07-03 16:34:14 +0100 | [diff] [blame] | 951 | } |