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