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

Commit 6a036e21 authored by Garfield Tan's avatar Garfield Tan
Browse files

Inherit source windowing mode in some cases.

We allow freeform windows on fullscreen displays launch activities in
freeform windows if they'll be on the same display.

Bug: 139274544
Bug: 163178199
Test: FreeformWindowingModeTests#testFreeformWindowManagementSupport
passed on fullscreen display.
Test: atest WmTests:TaskLaunchParamsModifierTests

Change-Id: Ib1b75145c0b0b38b07bcde2ca66a1d772a2c2d0f
Merged-In: Ib1b75145c0b0b38b07bcde2ca66a1d772a2c2d0f
parent 0090d82f
Loading
Loading
Loading
Loading
+40 −3
Original line number Original line Diff line number Diff line
@@ -159,11 +159,23 @@ class TaskLaunchParamsModifier implements LaunchParamsModifier {
        }
        }


        // STEP 2: Resolve launch windowing mode.
        // STEP 2: Resolve launch windowing mode.
        // STEP 2.1: Determine if any parameter has specified initial bounds. That might be the
        // STEP 2.1: Determine if any parameter can specify initial bounds/windowing mode. That
        // launch bounds from activity options, or size/gravity passed in layout. It also treats the
        // might be the launch bounds from activity options, or size/gravity passed in layout. It
        // launch windowing mode in options as a suggestion for future resolution.
        // also treats the launch windowing mode in options and source activity windowing mode in
        // some cases as a suggestion for future resolution.
        int launchMode = options != null ? options.getLaunchWindowingMode()
        int launchMode = options != null ? options.getLaunchWindowingMode()
                : WINDOWING_MODE_UNDEFINED;
                : WINDOWING_MODE_UNDEFINED;
        // In some cases we want to use the source's windowing mode as the default value, e.g. when
        // source is a freeform window in a fullscreen display launching an activity on the same
        // display.
        if (launchMode == WINDOWING_MODE_UNDEFINED
                && canInheritWindowingModeFromSource(display, source)) {
            launchMode = source.getWindowingMode();
            if (DEBUG) {
                appendLog("inherit-from-source="
                        + WindowConfiguration.windowingModeToString(launchMode));
            }
        }
        // hasInitialBounds is set if either activity options or layout has specified bounds. If
        // hasInitialBounds is set if either activity options or layout has specified bounds. If
        // that's set we'll skip some adjustments later to avoid overriding the initial bounds.
        // that's set we'll skip some adjustments later to avoid overriding the initial bounds.
        boolean hasInitialBounds = false;
        boolean hasInitialBounds = false;
@@ -334,6 +346,31 @@ class TaskLaunchParamsModifier implements LaunchParamsModifier {
                ? displayId : DEFAULT_DISPLAY;
                ? displayId : DEFAULT_DISPLAY;
    }
    }


    private boolean canInheritWindowingModeFromSource(@NonNull ActivityDisplay display,
            @Nullable ActivityRecord source) {
        if (source == null) {
            return false;
        }

        // There is not really any strong reason to tie the launching windowing mode and the source
        // on freeform displays. The launching windowing mode is more tied to the content of the new
        // activities.
        if (display.inFreeformWindowingMode()) {
            return false;
        }

        final int sourceWindowingMode = source.getWindowingMode();
        if (sourceWindowingMode != WINDOWING_MODE_FULLSCREEN
                && sourceWindowingMode != WINDOWING_MODE_FREEFORM) {
            return false;
        }

        // Only inherit windowing mode if both source and target activities are on the same display.
        // Otherwise we may have unintended freeform windows showing up if an activity in freeform
        // window launches an activity on a fullscreen display by specifying display ID.
        return display.mDisplayId == source.getDisplayId();
    }

    private boolean canApplyFreeformWindowPolicy(@NonNull ActivityDisplay display, int launchMode) {
    private boolean canApplyFreeformWindowPolicy(@NonNull ActivityDisplay display, int launchMode) {
        return mSupervisor.mService.mSupportsFreeformWindowManagement
        return mSupervisor.mService.mSupportsFreeformWindowManagement
                && (display.inFreeformWindowingMode() || launchMode == WINDOWING_MODE_FREEFORM);
                && (display.inFreeformWindowingMode() || launchMode == WINDOWING_MODE_FREEFORM);
+31 −0
Original line number Original line Diff line number Diff line
@@ -248,6 +248,20 @@ public class TaskLaunchParamsModifierTests extends ActivityTestsBase {
                WINDOWING_MODE_FULLSCREEN);
                WINDOWING_MODE_FULLSCREEN);
    }
    }


    @Test
    public void testInheritsFreeformModeFromSourceOnFullscreenDisplay() {
        final TestActivityDisplay fullscreenDisplay = createNewActivityDisplay(
                WINDOWING_MODE_FULLSCREEN);
        final ActivityRecord source = createSourceActivity(fullscreenDisplay);
        source.setWindowingMode(WINDOWING_MODE_FREEFORM);

        assertEquals(RESULT_CONTINUE, mTarget.onCalculate(/* task */ null, /* layout */ null,
                mActivity, source, /* options */ null, mCurrent, mResult));

        assertEquivalentWindowingMode(WINDOWING_MODE_FREEFORM, mResult.mWindowingMode,
                WINDOWING_MODE_FULLSCREEN);
    }

    @Test
    @Test
    public void testKeepsPictureInPictureLaunchModeInOptions() {
    public void testKeepsPictureInPictureLaunchModeInOptions() {
        final TestActivityDisplay freeformDisplay = createNewActivityDisplay(
        final TestActivityDisplay freeformDisplay = createNewActivityDisplay(
@@ -557,6 +571,23 @@ public class TaskLaunchParamsModifierTests extends ActivityTestsBase {
        assertEquals(expected, mResult.mBounds);
        assertEquals(expected, mResult.mBounds);
    }
    }


    @Test
    public void testRespectsLaunchBoundsWithFreeformSourceOnFullscreenDisplay() {
        final TestActivityDisplay fullscreenDisplay = createNewActivityDisplay(
                WINDOWING_MODE_FULLSCREEN);
        final ActivityRecord source = createSourceActivity(fullscreenDisplay);
        source.setWindowingMode(WINDOWING_MODE_FREEFORM);

        final ActivityOptions options = ActivityOptions.makeBasic();
        final Rect expected = new Rect(0, 0, 150, 150);
        options.setLaunchBounds(expected);

        assertEquals(RESULT_CONTINUE, mTarget.onCalculate(/* task */ null, /* layout */ null,
                mActivity, source, options, mCurrent, mResult));

        assertEquals(expected, mResult.mBounds);
    }

    @Test
    @Test
    public void testNonEmptyLayoutBoundsRespectsGravityWithEmptySize_LeftGravity() {
    public void testNonEmptyLayoutBoundsRespectsGravityWithEmptySize_LeftGravity() {
        final TestActivityDisplay freeformDisplay = createNewActivityDisplay(
        final TestActivityDisplay freeformDisplay = createNewActivityDisplay(