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

Commit 3eac44c5 authored by Thales Lima's avatar Thales Lima Committed by Steven Ng
Browse files

Hide blocked tasks when starting Lock Task

Hide all tasks that are not allowlisted in TaskFragment, while LockTask is enabled. (CL 1/n)

Bug: 402443859
Test: Manual using TestDPC
Flag: com.android.window.flags.enable_desktop_windowing_enterprise_bugfix
Change-Id: I149f15aa38df4a29c3804beca5a03940a7f5a828
parent 93ae6995
Loading
Loading
Loading
Loading
+3 −1
Original line number Diff line number Diff line
@@ -472,7 +472,9 @@ public class LockTaskController {
        // 3. Telephony then starts the default package for making the call
        final TelecomManager tm = getTelecomManager();
        final String dialerPackage = tm != null ? tm.getSystemDialerPackage() : null;
        if (dialerPackage != null && dialerPackage.equals(intent.getComponent().getPackageName())) {
        final String intentPackage =
                intent.getComponent() == null ? null : intent.getComponent().getPackageName();
        if (dialerPackage != null && dialerPackage.equals(intentPackage)) {
            return true;
        }

+37 −0
Original line number Diff line number Diff line
@@ -18,6 +18,8 @@ package com.android.server.wm;

import static android.Manifest.permission.EMBED_ANY_APP_IN_UNTRUSTED_MODE;
import static android.Manifest.permission.MANAGE_ACTIVITY_TASKS;
import static android.app.ActivityManager.LOCK_TASK_MODE_LOCKED;
import static android.app.ActivityManager.LOCK_TASK_MODE_PINNED;
import static android.app.ActivityTaskManager.INVALID_TASK_ID;
import static android.app.WindowConfiguration.ACTIVITY_TYPE_ASSISTANT;
import static android.app.WindowConfiguration.ACTIVITY_TYPE_HOME;
@@ -51,6 +53,7 @@ import static android.view.Display.INVALID_DISPLAY;
import static android.view.Surface.ROTATION_270;
import static android.view.Surface.ROTATION_90;
import static android.view.WindowManager.LayoutParams.FLAG_DIM_BEHIND;
import static android.window.DesktopExperienceFlags.ENABLE_DESKTOP_WINDOWING_ENTERPRISE_BUGFIX;

import static com.android.internal.protolog.WmProtoLogGroups.WM_DEBUG_STATES;
import static com.android.server.wm.ActivityRecord.State.PAUSED;
@@ -196,6 +199,7 @@ class TaskFragment extends WindowContainer<WindowContainer> {
    final ActivityTaskSupervisor mTaskSupervisor;
    final RootWindowContainer mRootWindowContainer;
    private final TaskFragmentOrganizerController mTaskFragmentOrganizerController;
    private final LockTaskController mLockTaskController;

    // TODO(b/233177466): Move mMinWidth and mMinHeight to Task and remove usages in TaskFragment
    /**
@@ -440,6 +444,7 @@ class TaskFragment extends WindowContainer<WindowContainer> {
        mRelativeEmbeddedBounds = isEmbedded ? new Rect() : null;
        mTaskFragmentOrganizerController =
                mAtmService.mWindowOrganizerController.mTaskFragmentOrganizerController;
        mLockTaskController = mAtmService.getLockTaskController();
        mFragmentToken = fragmentToken;
        mRemoteToken = new RemoteToken(this);
    }
@@ -1270,6 +1275,10 @@ class TaskFragment extends WindowContainer<WindowContainer> {
            return TASK_FRAGMENT_VISIBILITY_VISIBLE;
        }

        if (thisTask != null && !isPermittedInLockTask(thisTask)) {
            return TASK_FRAGMENT_VISIBILITY_INVISIBLE;
        }

        boolean gotTranslucentFullscreen = false;
        boolean gotTranslucentAdjacent = false;
        boolean shouldBeVisible = true;
@@ -1410,6 +1419,34 @@ class TaskFragment extends WindowContainer<WindowContainer> {
        return top != null && top.mLaunchTaskBehind;
    }

    /**
     * Checks if a task is allowed to run in the lock task mode.
     *
     * <p>Returns {@code true} if {@link ENABLE_DESKTOP_WINDOWING_ENTERPRISE_BUGFIX} flag is not
     * enabled.
     *
     * <p>Returns {@code true} if the device is not currently in lock task.
     *
     * <p>A task is permitted if it's a leaf task that is allowed by the lock task admin policy, or
     * if any of its descendant leaf tasks are permitted by the policy.
     *
     * @param task The task to evaluate.
     * @return {@code true} if the task is allowed to run, {@code false} otherwise.
     */
    private boolean isPermittedInLockTask(@NonNull Task task) {
        if (!ENABLE_DESKTOP_WINDOWING_ENTERPRISE_BUGFIX.isTrue()) {
            return true;
        }
        final int lockTaskState = mLockTaskController.getLockTaskModeState();
        final boolean isInLockTask =
                lockTaskState == LOCK_TASK_MODE_LOCKED || lockTaskState == LOCK_TASK_MODE_PINNED;
        if (!isInLockTask) {
            return true;
        }
        return task.forAllTasks(
                leafTask -> !mLockTaskController.isLockTaskModeViolation(leafTask));
    }

    final void updateActivityVisibilities(@Nullable ActivityRecord starting,
            boolean notifyClients) {
        mTaskSupervisor.beginActivityVisibilityUpdate();