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

Commit 640a7747 authored by Bartosz Chominski's avatar Bartosz Chominski
Browse files

Throw exception for invalid display ID in AM#isTaskMoveAllowedOnDisplay

Due to feedback from the API Council

Bug: 400407139
Bug: 423018654
Flag: com.android.window.flags.enable_window_repositioning_api
Test: CTS in another CL
Change-Id: Ibc5bfc1dcc698da663dbf5f252c989cd63a220c7
parent 1e3e76ae
Loading
Loading
Loading
Loading
+2 −0
Original line number Diff line number Diff line
@@ -3197,6 +3197,8 @@ public class ActivityManager {
     *
     * @param displayId Target display ID
     * @return Whether the windowing mode active on display with given ID allows task repositioning
     *
     * @throws IllegalArgumentException if there is no display with given display ID
     */
    @FlaggedApi(com.android.window.flags.Flags.FLAG_ENABLE_WINDOW_REPOSITIONING_API)
    @SuppressLint("RequiresPermission")
+7 −1
Original line number Diff line number Diff line
@@ -1970,13 +1970,19 @@ public class ActivityTaskManagerService extends IActivityTaskManager.Stub {
     *
     * @param displayId Target display ID
     * @return Whether the windowing mode active on display with given ID allows task repositioning
     *
     * @throws IllegalArgumentException if there is no display with given display ID
     */
    public boolean isTaskMoveAllowedOnDisplay(int displayId) {
        final DisplayContent dc = mRootWindowContainer.getDisplayContent(displayId);
        if (dc == null) {
            throw new IllegalArgumentException("There is no display with ID = " + displayId);
        }
        if (checkCallingPermission(Manifest.permission.REPOSITION_SELF_WINDOWS)
                != PackageManager.PERMISSION_GRANTED) {
            return false;
        }
        return mRootWindowContainer.isTaskMoveAllowedOnDisplay(displayId);
        return dc.isTaskMoveAllowedOnDisplay();
    }

    @Override
+0 −5
Original line number Diff line number Diff line
@@ -3918,9 +3918,4 @@ class RootWindowContainer extends WindowContainer<DisplayContent>
            }
        }
    }

    boolean isTaskMoveAllowedOnDisplay(int displayId) {
        DisplayContent dc = getDisplayContent(displayId);
        return dc == null ? false : dc.isTaskMoveAllowedOnDisplay();
    }
}
+12 −4
Original line number Diff line number Diff line
@@ -1567,18 +1567,22 @@ public class ActivityTaskManagerServiceTests extends WindowTestsBase {
    @EnableFlags(FLAG_ENABLE_WINDOW_REPOSITIONING_API)
    @Test
    public void testIsTaskMoveAllowedOnDisplay_permissionGranted() {
        final int displayId = 73;
        final int displayId = Display.DEFAULT_DISPLAY;
        final DisplayContent dc = mRootWindowContainer.getDisplayContent(displayId);

        MockitoSession session =
                mockitoSession().spyStatic(ActivityTaskManagerService.class).startMocking();
        try {
            doReturn(true).when(mRootWindowContainer).isTaskMoveAllowedOnDisplay(displayId);
            doReturn(PERMISSION_GRANTED).when(() -> {
                return ActivityTaskManagerService.checkPermission(
                        eq(REPOSITION_SELF_WINDOWS), anyInt(), anyInt());
            });

            doReturn(true).when(dc).isTaskMoveAllowedOnDisplay();
            assertTrue(mAtm.isTaskMoveAllowedOnDisplay(displayId));

            doReturn(false).when(dc).isTaskMoveAllowedOnDisplay();
            assertFalse(mAtm.isTaskMoveAllowedOnDisplay(displayId));
        } finally {
            session.finishMocking();
        }
@@ -1587,17 +1591,21 @@ public class ActivityTaskManagerServiceTests extends WindowTestsBase {
    @EnableFlags(FLAG_ENABLE_WINDOW_REPOSITIONING_API)
    @Test
    public void testIsTaskMoveAllowedOnDisplay_permissionDenied() {
        final int displayId = 73;
        final int displayId = Display.DEFAULT_DISPLAY;
        final DisplayContent dc = mRootWindowContainer.getDisplayContent(displayId);

        MockitoSession session =
                mockitoSession().spyStatic(ActivityTaskManagerService.class).startMocking();
        try {
            doReturn(true).when(mRootWindowContainer).isTaskMoveAllowedOnDisplay(displayId);
            doReturn(PERMISSION_DENIED).when(() -> {
                return ActivityTaskManagerService.checkPermission(
                        eq(REPOSITION_SELF_WINDOWS), anyInt(), anyInt());
            });

            doReturn(true).when(dc).isTaskMoveAllowedOnDisplay();
            assertFalse(mAtm.isTaskMoveAllowedOnDisplay(displayId));

            doReturn(false).when(dc).isTaskMoveAllowedOnDisplay();
            assertFalse(mAtm.isTaskMoveAllowedOnDisplay(displayId));
        } finally {
            session.finishMocking();
+0 −14
Original line number Diff line number Diff line
@@ -41,8 +41,6 @@ import static com.android.server.wm.ActivityRecord.State.STOPPING;
import static com.android.server.wm.ActivityTaskSupervisor.ON_TOP;
import static com.android.server.wm.RootWindowContainer.MATCH_ATTACHED_TASK_OR_RECENT_TASKS_AND_RESTORE;
import static com.android.server.wm.WindowContainer.POSITION_BOTTOM;
import static com.android.window.flags.Flags.FLAG_ENABLE_WINDOW_REPOSITIONING_API;


import static com.google.common.truth.Truth.assertThat;

@@ -1397,18 +1395,6 @@ public class RootWindowContainerTests extends WindowTestsBase {
                anyBoolean());
    }

    @EnableFlags(FLAG_ENABLE_WINDOW_REPOSITIONING_API)
    @Test
    public void testIsTaskMoveAllowedOnDisplay() {
        final DisplayContent dc = mRootWindowContainer.getDisplayContent(DEFAULT_DISPLAY);

        doReturn(true).when(dc).isTaskMoveAllowedOnDisplay();
        assertTrue(mRootWindowContainer.isTaskMoveAllowedOnDisplay(DEFAULT_DISPLAY));

        doReturn(false).when(dc).isTaskMoveAllowedOnDisplay();
        assertFalse(mRootWindowContainer.isTaskMoveAllowedOnDisplay(DEFAULT_DISPLAY));
    }

    /**
     * Mock {@link RootWindowContainer#resolveHomeActivity} for returning consistent activity
     * info for test cases.