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

Commit 186dfef8 authored by Jiaming Liu's avatar Jiaming Liu
Browse files

Rename privileged TaskFragment operations

Add PRIVILEGED_ prefix to make it clear that these operations are only
available to system organizers.

Bug: 395668520
Test: atest TaskFragmentOrganizerControllerTest
Flag: EXEMPT refactor
Change-Id: I888c017d3e244ad92587e061404d363aa13c2f8e
parent 8c6b48a9
Loading
Loading
Loading
Loading
+48 −40
Original line number Diff line number Diff line
@@ -89,26 +89,6 @@ public final class TaskFragmentOperation implements Parcelable {
     */
    public static final int OP_TYPE_SET_ISOLATED_NAVIGATION = 11;

    /**
     * Reorders the TaskFragment to be the bottom-most in the Task. Note that this op will bring the
     * TaskFragment to the bottom of the Task below all the other Activities and TaskFragments.
     *
     * This is only allowed for system organizers. See
     * {@link com.android.server.wm.TaskFragmentOrganizerController#registerOrganizer(
     * ITaskFragmentOrganizer, boolean)}
     */
    public static final int OP_TYPE_REORDER_TO_BOTTOM_OF_TASK = 12;

    /**
     * Reorders the TaskFragment to be the top-most in the Task. Note that this op will bring the
     * TaskFragment to the top of the Task above all the other Activities and TaskFragments.
     *
     * This is only allowed for system organizers. See
     * {@link com.android.server.wm.TaskFragmentOrganizerController#registerOrganizer(
     * ITaskFragmentOrganizer, boolean)}
     */
    public static final int OP_TYPE_REORDER_TO_TOP_OF_TASK = 13;

    /**
     * Creates a decor surface in the parent Task of the TaskFragment. The created decor surface
     * will be provided in {@link TaskFragmentTransaction#TYPE_TASK_FRAGMENT_PARENT_INFO_CHANGED}
@@ -118,27 +98,17 @@ public final class TaskFragmentOperation implements Parcelable {
     *
     * The decor surface can be used to draw the divider between TaskFragments or other decorations.
     */
    public static final int OP_TYPE_CREATE_OR_MOVE_TASK_FRAGMENT_DECOR_SURFACE = 14;
    public static final int OP_TYPE_CREATE_OR_MOVE_TASK_FRAGMENT_DECOR_SURFACE = 12;

    /**
     * Removes the decor surface in the parent Task of the TaskFragment.
     */
    public static final int OP_TYPE_REMOVE_TASK_FRAGMENT_DECOR_SURFACE = 15;
    public static final int OP_TYPE_REMOVE_TASK_FRAGMENT_DECOR_SURFACE = 13;

    /**
     * Applies dimming on the parent Task which could cross two TaskFragments.
     */
    public static final int OP_TYPE_SET_DIM_ON_TASK = 16;

    /**
     * Sets this TaskFragment to move to bottom of the Task if any of the activities below it is
     * launched in a mode requiring clear top.
     *
     * This is only allowed for system organizers. See
     * {@link com.android.server.wm.TaskFragmentOrganizerController#registerOrganizer(
     * ITaskFragmentOrganizer, boolean)}
     */
    public static final int OP_TYPE_SET_MOVE_TO_BOTTOM_IF_CLEAR_WHEN_LAUNCH = 17;
    public static final int OP_TYPE_SET_DIM_ON_TASK = 14;

    /**
     * Sets whether the decor surface will be boosted. When not boosted, the decor surface is placed
@@ -147,7 +117,7 @@ public final class TaskFragmentOperation implements Parcelable {
     * surface is placed above all the non-boosted windows in the Task, the content of these
     * non-boosted windows will be hidden and inputs are disabled.
     */
    public static final int OP_TYPE_SET_DECOR_SURFACE_BOOSTED = 18;
    public static final int OP_TYPE_SET_DECOR_SURFACE_BOOSTED = 15;

    /**
     * Sets the TaskFragment to be pinned.
@@ -159,7 +129,44 @@ public final class TaskFragmentOperation implements Parcelable {
     * <p>
     * See {@link #OP_TYPE_REORDER_TO_FRONT} on how to reorder a pinned TaskFragment to the top.
     */
    public static final int OP_TYPE_SET_PINNED = 19;
    public static final int OP_TYPE_SET_PINNED = 16;

    /**
     * The start index of the privileged operations. Only system organizers are allowed to use
     * operations with index greater than or equal to this value.
     */
    public static final int PRIVILEGED_OP_START = 1000;

    /**
     * Reorders the TaskFragment to be the bottom-most in the Task. Note that this op will bring the
     * TaskFragment to the bottom of the Task below all the other Activities and TaskFragments.
     *
     * This is only allowed for system organizers. See
     * {@link com.android.server.wm.TaskFragmentOrganizerController#registerOrganizer(
     * ITaskFragmentOrganizer, boolean)}
     */
    public static final int OP_TYPE_PRIVILEGED_REORDER_TO_BOTTOM_OF_TASK = PRIVILEGED_OP_START + 1;

    /**
     * Reorders the TaskFragment to be the top-most in the Task. Note that this op will bring the
     * TaskFragment to the top of the Task above all the other Activities and TaskFragments.
     *
     * This is only allowed for system organizers. See
     * {@link com.android.server.wm.TaskFragmentOrganizerController#registerOrganizer(
     * ITaskFragmentOrganizer, boolean)}
     */
    public static final int OP_TYPE_PRIVILEGED_REORDER_TO_TOP_OF_TASK = PRIVILEGED_OP_START + 2;

    /**
     * Sets this TaskFragment to move to bottom of the Task if any of the activities below it is
     * launched in a mode requiring clear top.
     *
     * This is only allowed for system organizers. See
     * {@link com.android.server.wm.TaskFragmentOrganizerController#registerOrganizer(
     * ITaskFragmentOrganizer, boolean)}
     */
    public static final int OP_TYPE_PRIVILEGED_SET_MOVE_TO_BOTTOM_IF_CLEAR_WHEN_LAUNCH =
            PRIVILEGED_OP_START + 3;

    /**
     * Sets whether this TaskFragment can affect system UI flags such as the status bar. Default
@@ -169,7 +176,8 @@ public final class TaskFragmentOperation implements Parcelable {
     * {@link com.android.server.wm.TaskFragmentOrganizerController#registerOrganizer(
     * ITaskFragmentOrganizer, boolean)}
     */
    public static final int OP_TYPE_SET_CAN_AFFECT_SYSTEM_UI_FLAGS = 20;
    public static final int OP_TYPE_PRIVILEGED_SET_CAN_AFFECT_SYSTEM_UI_FLAGS =
            PRIVILEGED_OP_START + 4;

    @IntDef(prefix = { "OP_TYPE_" }, value = {
            OP_TYPE_UNKNOWN,
@@ -185,15 +193,15 @@ public final class TaskFragmentOperation implements Parcelable {
            OP_TYPE_SET_RELATIVE_BOUNDS,
            OP_TYPE_REORDER_TO_FRONT,
            OP_TYPE_SET_ISOLATED_NAVIGATION,
            OP_TYPE_REORDER_TO_BOTTOM_OF_TASK,
            OP_TYPE_REORDER_TO_TOP_OF_TASK,
            OP_TYPE_CREATE_OR_MOVE_TASK_FRAGMENT_DECOR_SURFACE,
            OP_TYPE_REMOVE_TASK_FRAGMENT_DECOR_SURFACE,
            OP_TYPE_SET_DIM_ON_TASK,
            OP_TYPE_SET_MOVE_TO_BOTTOM_IF_CLEAR_WHEN_LAUNCH,
            OP_TYPE_SET_DECOR_SURFACE_BOOSTED,
            OP_TYPE_SET_PINNED,
            OP_TYPE_SET_CAN_AFFECT_SYSTEM_UI_FLAGS,
            OP_TYPE_PRIVILEGED_REORDER_TO_BOTTOM_OF_TASK,
            OP_TYPE_PRIVILEGED_REORDER_TO_TOP_OF_TASK,
            OP_TYPE_PRIVILEGED_SET_MOVE_TO_BOTTOM_IF_CLEAR_WHEN_LAUNCH,
            OP_TYPE_PRIVILEGED_SET_CAN_AFFECT_SYSTEM_UI_FLAGS,
    })
    @Retention(RetentionPolicy.SOURCE)
    public @interface OperationType {}
+2 −1
Original line number Diff line number Diff line
@@ -83,7 +83,8 @@ constructor(
                            resultT.addTaskFragmentOperation(
                                fragmentToken,
                                TaskFragmentOperation.Builder(
                                        TaskFragmentOperation.OP_TYPE_REORDER_TO_TOP_OF_TASK
                                        TaskFragmentOperation
                                            .OP_TYPE_PRIVILEGED_REORDER_TO_TOP_OF_TASK
                                    )
                                    .build(),
                            )
+15 −36
Original line number Diff line number Diff line
@@ -30,24 +30,25 @@ import static android.window.TaskFragmentOperation.OP_TYPE_CLEAR_ADJACENT_TASK_F
import static android.window.TaskFragmentOperation.OP_TYPE_CREATE_OR_MOVE_TASK_FRAGMENT_DECOR_SURFACE;
import static android.window.TaskFragmentOperation.OP_TYPE_CREATE_TASK_FRAGMENT;
import static android.window.TaskFragmentOperation.OP_TYPE_DELETE_TASK_FRAGMENT;
import static android.window.TaskFragmentOperation.OP_TYPE_PRIVILEGED_REORDER_TO_BOTTOM_OF_TASK;
import static android.window.TaskFragmentOperation.OP_TYPE_PRIVILEGED_REORDER_TO_TOP_OF_TASK;
import static android.window.TaskFragmentOperation.OP_TYPE_PRIVILEGED_SET_CAN_AFFECT_SYSTEM_UI_FLAGS;
import static android.window.TaskFragmentOperation.OP_TYPE_PRIVILEGED_SET_MOVE_TO_BOTTOM_IF_CLEAR_WHEN_LAUNCH;
import static android.window.TaskFragmentOperation.OP_TYPE_REMOVE_TASK_FRAGMENT_DECOR_SURFACE;
import static android.window.TaskFragmentOperation.OP_TYPE_REORDER_TO_BOTTOM_OF_TASK;
import static android.window.TaskFragmentOperation.OP_TYPE_REORDER_TO_FRONT;
import static android.window.TaskFragmentOperation.OP_TYPE_REORDER_TO_TOP_OF_TASK;
import static android.window.TaskFragmentOperation.OP_TYPE_REPARENT_ACTIVITY_TO_TASK_FRAGMENT;
import static android.window.TaskFragmentOperation.OP_TYPE_REQUEST_FOCUS_ON_TASK_FRAGMENT;
import static android.window.TaskFragmentOperation.OP_TYPE_SET_ADJACENT_TASK_FRAGMENTS;
import static android.window.TaskFragmentOperation.OP_TYPE_SET_ANIMATION_PARAMS;
import static android.window.TaskFragmentOperation.OP_TYPE_SET_CAN_AFFECT_SYSTEM_UI_FLAGS;
import static android.window.TaskFragmentOperation.OP_TYPE_SET_COMPANION_TASK_FRAGMENT;
import static android.window.TaskFragmentOperation.OP_TYPE_SET_DECOR_SURFACE_BOOSTED;
import static android.window.TaskFragmentOperation.OP_TYPE_SET_DIM_ON_TASK;
import static android.window.TaskFragmentOperation.OP_TYPE_SET_ISOLATED_NAVIGATION;
import static android.window.TaskFragmentOperation.OP_TYPE_SET_MOVE_TO_BOTTOM_IF_CLEAR_WHEN_LAUNCH;
import static android.window.TaskFragmentOperation.OP_TYPE_SET_PINNED;
import static android.window.TaskFragmentOperation.OP_TYPE_SET_RELATIVE_BOUNDS;
import static android.window.TaskFragmentOperation.OP_TYPE_START_ACTIVITY_IN_TASK_FRAGMENT;
import static android.window.TaskFragmentOperation.OP_TYPE_UNKNOWN;
import static android.window.TaskFragmentOperation.PRIVILEGED_OP_START;
import static android.window.WindowContainerTransaction.Change.CHANGE_FOCUSABLE;
import static android.window.WindowContainerTransaction.Change.CHANGE_FORCE_TRANSLUCENT;
import static android.window.WindowContainerTransaction.Change.CHANGE_HIDDEN;
@@ -1786,7 +1787,7 @@ class WindowOrganizerController extends IWindowOrganizerController.Stub
                taskFragment.setIsolatedNav(isolatedNav);
                break;
            }
            case OP_TYPE_REORDER_TO_BOTTOM_OF_TASK: {
            case OP_TYPE_PRIVILEGED_REORDER_TO_BOTTOM_OF_TASK: {
                final Task task = taskFragment.getTask();
                if (task != null) {
                    if (task.getBottomChild() != taskFragment) {
@@ -1802,7 +1803,7 @@ class WindowOrganizerController extends IWindowOrganizerController.Stub
                }
                break;
            }
            case OP_TYPE_REORDER_TO_TOP_OF_TASK: {
            case OP_TYPE_PRIVILEGED_REORDER_TO_TOP_OF_TASK: {
                final Task task = taskFragment.getTask();
                if (task != null) {
                    if (task.getTopChild() != taskFragment) {
@@ -1852,7 +1853,7 @@ class WindowOrganizerController extends IWindowOrganizerController.Stub
                        : EMBEDDED_DIM_AREA_TASK_FRAGMENT);
                break;
            }
            case OP_TYPE_SET_MOVE_TO_BOTTOM_IF_CLEAR_WHEN_LAUNCH: {
            case OP_TYPE_PRIVILEGED_SET_MOVE_TO_BOTTOM_IF_CLEAR_WHEN_LAUNCH: {
                taskFragment.setMoveToBottomIfClearWhenLaunch(operation.getBooleanValue());
                break;
            }
@@ -1888,7 +1889,7 @@ class WindowOrganizerController extends IWindowOrganizerController.Stub
                taskFragment.setPinned(pinned);
                break;
            }
            case OP_TYPE_SET_CAN_AFFECT_SYSTEM_UI_FLAGS: {
            case OP_TYPE_PRIVILEGED_SET_CAN_AFFECT_SYSTEM_UI_FLAGS: {
                taskFragment.setCanAffectSystemUiFlags(operation.getBooleanValue());

                // Request to apply the flags.
@@ -1938,45 +1939,23 @@ class WindowOrganizerController extends IWindowOrganizerController.Stub
            return false;
        }
        final int opType = operation.getOpType();
        if (opType == OP_TYPE_CREATE_TASK_FRAGMENT) {
            // No need to check TaskFragment.
            return true;
        }

        if (!validateTaskFragment(taskFragment, opType, errorCallbackToken, organizer)) {
            return false;
        }

        if ((opType == OP_TYPE_REORDER_TO_BOTTOM_OF_TASK
                || opType == OP_TYPE_REORDER_TO_TOP_OF_TASK)
        if (opType >= PRIVILEGED_OP_START
                && !mTaskFragmentOrganizerController.isSystemOrganizer(organizer.asBinder())) {
            final Throwable exception = new SecurityException(
                    "Only a system organizer can perform OP_TYPE_REORDER_TO_BOTTOM_OF_TASK or "
                            + "OP_TYPE_REORDER_TO_TOP_OF_TASK."
                    "Only a system organizer can perform privileged operations. opType=" + opType
            );
            sendTaskFragmentOperationFailure(organizer, errorCallbackToken, taskFragment,
                    opType, exception);
            return false;
        }

        if ((opType == OP_TYPE_SET_MOVE_TO_BOTTOM_IF_CLEAR_WHEN_LAUNCH)
                && !mTaskFragmentOrganizerController.isSystemOrganizer(organizer.asBinder())) {
            final Throwable exception = new SecurityException(
                    "Only a system organizer can perform "
                            + "OP_TYPE_SET_MOVE_TO_BOTTOM_IF_CLEAR_WHEN_LAUNCH."
            );
            sendTaskFragmentOperationFailure(organizer, errorCallbackToken, taskFragment,
                    opType, exception);
            return false;
        if (opType == OP_TYPE_CREATE_TASK_FRAGMENT) {
            // No need to check TaskFragment.
            return true;
        }

        if ((opType == OP_TYPE_SET_CAN_AFFECT_SYSTEM_UI_FLAGS)
                && !mTaskFragmentOrganizerController.isSystemOrganizer(organizer.asBinder())) {
            final Throwable exception = new SecurityException(
                    "Only a system organizer can perform OP_TYPE_SET_CAN_AFFECT_SYSTEM_UI_FLAGS."
            );
            sendTaskFragmentOperationFailure(organizer, errorCallbackToken, taskFragment,
                    opType, exception);
        if (!validateTaskFragment(taskFragment, opType, errorCallbackToken, organizer)) {
            return false;
        }

+11 −11
Original line number Diff line number Diff line
@@ -29,14 +29,14 @@ import static android.view.WindowManager.TRANSIT_OPEN;
import static android.window.TaskFragmentOperation.OP_TYPE_CREATE_OR_MOVE_TASK_FRAGMENT_DECOR_SURFACE;
import static android.window.TaskFragmentOperation.OP_TYPE_CREATE_TASK_FRAGMENT;
import static android.window.TaskFragmentOperation.OP_TYPE_DELETE_TASK_FRAGMENT;
import static android.window.TaskFragmentOperation.OP_TYPE_PRIVILEGED_REORDER_TO_BOTTOM_OF_TASK;
import static android.window.TaskFragmentOperation.OP_TYPE_PRIVILEGED_REORDER_TO_TOP_OF_TASK;
import static android.window.TaskFragmentOperation.OP_TYPE_PRIVILEGED_SET_CAN_AFFECT_SYSTEM_UI_FLAGS;
import static android.window.TaskFragmentOperation.OP_TYPE_REMOVE_TASK_FRAGMENT_DECOR_SURFACE;
import static android.window.TaskFragmentOperation.OP_TYPE_REORDER_TO_BOTTOM_OF_TASK;
import static android.window.TaskFragmentOperation.OP_TYPE_REORDER_TO_FRONT;
import static android.window.TaskFragmentOperation.OP_TYPE_REORDER_TO_TOP_OF_TASK;
import static android.window.TaskFragmentOperation.OP_TYPE_REPARENT_ACTIVITY_TO_TASK_FRAGMENT;
import static android.window.TaskFragmentOperation.OP_TYPE_SET_ADJACENT_TASK_FRAGMENTS;
import static android.window.TaskFragmentOperation.OP_TYPE_SET_ANIMATION_PARAMS;
import static android.window.TaskFragmentOperation.OP_TYPE_SET_CAN_AFFECT_SYSTEM_UI_FLAGS;
import static android.window.TaskFragmentOperation.OP_TYPE_SET_DIM_ON_TASK;
import static android.window.TaskFragmentOperation.OP_TYPE_START_ACTIVITY_IN_TASK_FRAGMENT;
import static android.window.TaskFragmentOrganizer.KEY_ERROR_CALLBACK_OP_TYPE;
@@ -1821,7 +1821,7 @@ public class TaskFragmentOrganizerControllerTest extends WindowTestsBase {

        // Reorder TaskFragment to bottom
        final TaskFragmentOperation operation = new TaskFragmentOperation.Builder(
                OP_TYPE_REORDER_TO_BOTTOM_OF_TASK).build();
                OP_TYPE_PRIVILEGED_REORDER_TO_BOTTOM_OF_TASK).build();
        mTransaction.addTaskFragmentOperation(tf1.getFragmentToken(), operation);
        assertApplyTransactionAllowed(mTransaction);

@@ -1858,7 +1858,7 @@ public class TaskFragmentOrganizerControllerTest extends WindowTestsBase {

        // Reorder TaskFragment to top
        final TaskFragmentOperation operation = new TaskFragmentOperation.Builder(
                OP_TYPE_REORDER_TO_TOP_OF_TASK).build();
                OP_TYPE_PRIVILEGED_REORDER_TO_TOP_OF_TASK).build();
        mTransaction.addTaskFragmentOperation(tf0.getFragmentToken(), operation);
        assertApplyTransactionAllowed(mTransaction);

@@ -1903,13 +1903,13 @@ public class TaskFragmentOrganizerControllerTest extends WindowTestsBase {
    @Test
    public void testApplyTransaction_reorderToBottomOfTask_failsIfNotSystemOrganizer() {
        testApplyTransaction_reorder_failsIfNotSystemOrganizer_common(
                OP_TYPE_REORDER_TO_BOTTOM_OF_TASK);
                OP_TYPE_PRIVILEGED_REORDER_TO_BOTTOM_OF_TASK);
    }

    @Test
    public void testApplyTransaction_reorderToTopOfTask_failsIfNotSystemOrganizer() {
        testApplyTransaction_reorder_failsIfNotSystemOrganizer_common(
                OP_TYPE_REORDER_TO_TOP_OF_TASK);
                OP_TYPE_PRIVILEGED_REORDER_TO_TOP_OF_TASK);
    }

    @Test
@@ -1922,7 +1922,7 @@ public class TaskFragmentOrganizerControllerTest extends WindowTestsBase {

        // Setting the flag to false.
        TaskFragmentOperation operation = new TaskFragmentOperation.Builder(
                OP_TYPE_SET_CAN_AFFECT_SYSTEM_UI_FLAGS).setBooleanValue(false).build();
                OP_TYPE_PRIVILEGED_SET_CAN_AFFECT_SYSTEM_UI_FLAGS).setBooleanValue(false).build();
        mTransaction.addTaskFragmentOperation(tf.getFragmentToken(), operation);

        assertApplyTransactionAllowed(mTransaction);
@@ -1931,7 +1931,7 @@ public class TaskFragmentOrganizerControllerTest extends WindowTestsBase {

        // Setting the flag back to true.
        operation = new TaskFragmentOperation.Builder(
                OP_TYPE_SET_CAN_AFFECT_SYSTEM_UI_FLAGS).setBooleanValue(true).build();
                OP_TYPE_PRIVILEGED_SET_CAN_AFFECT_SYSTEM_UI_FLAGS).setBooleanValue(true).build();
        mTransaction.addTaskFragmentOperation(tf.getFragmentToken(), operation);

        assertApplyTransactionAllowed(mTransaction);
@@ -1945,7 +1945,7 @@ public class TaskFragmentOrganizerControllerTest extends WindowTestsBase {
        final TaskFragment tf = createTaskFragment(task);

        TaskFragmentOperation operation = new TaskFragmentOperation.Builder(
                OP_TYPE_SET_CAN_AFFECT_SYSTEM_UI_FLAGS).setBooleanValue(false).build();
                OP_TYPE_PRIVILEGED_SET_CAN_AFFECT_SYSTEM_UI_FLAGS).setBooleanValue(false).build();
        mTransaction
                .addTaskFragmentOperation(tf.getFragmentToken(), operation)
                .setErrorCallbackToken(mErrorToken);
@@ -1955,7 +1955,7 @@ public class TaskFragmentOrganizerControllerTest extends WindowTestsBase {
        // The pending event will be dispatched on the handler (from requestTraversal).
        waitHandlerIdle(mWm.mAnimationHandler);

        assertTaskFragmentErrorTransaction(OP_TYPE_SET_CAN_AFFECT_SYSTEM_UI_FLAGS,
        assertTaskFragmentErrorTransaction(OP_TYPE_PRIVILEGED_SET_CAN_AFFECT_SYSTEM_UI_FLAGS,
                SecurityException.class);
    }