Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 540a7c32 authored by Yanli Wan's avatar Yanli Wan
Browse files

Stop app pinning if lock task is requested from allowedlisted app

Bug: 213942596
Test: Manual
Change-Id: I86c71bef4f8c374fab01aa0a5f3997ba1a2b27cf
parent 7d3188b7
Loading
Loading
Loading
Loading
+6 −0
Original line number Diff line number Diff line
@@ -1069,6 +1069,12 @@
      "group": "WM_DEBUG_ORIENTATION",
      "at": "com\/android\/server\/wm\/WindowManagerService.java"
    },
    "-1075136930": {
      "message": "startLockTaskMode: Can't lock due to auth",
      "level": "WARN",
      "group": "WM_DEBUG_LOCKTASK",
      "at": "com\/android\/server\/wm\/LockTaskController.java"
    },
    "-1069336896": {
      "message": "onRootTaskOrderChanged(): rootTask=%s",
      "level": "DEBUG",
+3 −0
Original line number Diff line number Diff line
@@ -2566,6 +2566,9 @@ public class ActivityTaskManagerService extends IActivityTaskManager.Stub {
                    }
                    task = r.getTask();
                }
                // If {@code isSystemCaller} is {@code true}, it means the user intends to stop
                // pinned mode through UI; otherwise, it's called by an app and we need to stop
                // locked or pinned mode, subject to checks.
                getLockTaskController().stopLockTaskMode(task, isSystemCaller, callingUid);
            }
            // Launch in-call UI if a call is ongoing. This is necessary to allow stopping the lock
+14 −8
Original line number Diff line number Diff line
@@ -481,27 +481,24 @@ public class LockTaskController {
     *
     * @param task the task that requested the end of lock task mode ({@code null} for quitting app
     *             pinning mode)
     * @param isSystemCaller indicates whether this request comes from the system via
     *                       {@link ActivityTaskManagerService#stopSystemLockTaskMode()}. If
     *                       {@code true}, it means the user intends to stop pinned mode through UI;
     *                       otherwise, it's called by an app and we need to stop locked or pinned
     *                       mode, subject to checks.
     * @param stopAppPinning indicates whether to stop app pinning mode or to stop a task from
     *                       being locked.
     * @param callingUid the caller that requested the end of lock task mode.
     * @throws IllegalArgumentException if the calling task is invalid (e.g., {@code null} or not in
     *                                  foreground)
     * @throws SecurityException if the caller is not authorized to stop the lock task mode, i.e. if
     *                           they differ from the one that launched lock task mode.
     */
    void stopLockTaskMode(@Nullable Task task, boolean isSystemCaller, int callingUid) {
    void stopLockTaskMode(@Nullable Task task, boolean stopAppPinning, int callingUid) {
        if (mLockTaskModeState == LOCK_TASK_MODE_NONE) {
            return;
        }

        if (isSystemCaller) {
        if (stopAppPinning) {
            if (mLockTaskModeState == LOCK_TASK_MODE_PINNED) {
                clearLockedTasks("stopAppPinning");
            } else {
                Slog.e(TAG_LOCKTASK, "Attempted to stop LockTask with isSystemCaller=true");
                Slog.e(TAG_LOCKTASK, "Attempted to stop app pinning while fully locked");
                showLockTaskToast();
            }

@@ -642,6 +639,10 @@ public class LockTaskController {
     * @param callingUid the caller that requested the launch of lock task mode.
     */
    void startLockTaskMode(@NonNull Task task, boolean isSystemCaller, int callingUid) {
        if (task.mLockTaskAuth == LOCK_TASK_AUTH_DONT_LOCK) {
            ProtoLog.w(WM_DEBUG_LOCKTASK, "startLockTaskMode: Can't lock due to auth");
            return;
        }
        if (!isSystemCaller) {
            task.mLockTaskUid = callingUid;
            if (task.mLockTaskAuth == LOCK_TASK_AUTH_PINNABLE) {
@@ -654,6 +655,11 @@ public class LockTaskController {
                    statusBarManager.showScreenPinningRequest(task.mTaskId);
                }
                return;
            } else if (mLockTaskModeState == LOCK_TASK_MODE_PINNED) {
                // startLockTask() called by app, and app is part of lock task allowlist.
                // Deactivate the currently pinned task before doing so.
                Slog.i(TAG, "Stop app pinning before entering full lock task mode");
                stopLockTaskMode(/* task= */ null, /* stopAppPinning= */ true, callingUid);
            }
        }