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

Commit 91039d00 authored by Kazuki Takise's avatar Kazuki Takise Committed by Chris Li
Browse files

Respect previously resolved size if layout has no size value

Some apps such as Kindle only specify gravity, but no size in
window layout. In this case, we use the default task size for them,
but it should be better to use the previously resolved size.

Bug: 172668149
Bug: 173077136
Test: atest WmTests:TaskLaunchParamsModifierTests
Change-Id: I1f841aa85d9586785f6baf9628cb627efcf50b98
Merged-In: I1f841aa85d9586785f6baf9628cb627efcf50b98
(cherry picked from commit 45107f47)
parent 330f99f6
Loading
Loading
Loading
Loading
+17 −10
Original line number Diff line number Diff line
@@ -180,6 +180,7 @@ class TaskLaunchParamsModifier implements LaunchParamsModifier {
        } else if (launchMode == WINDOWING_MODE_FULLSCREEN) {
            if (DEBUG) appendLog("activity-options-fullscreen=" + outParams.mBounds);
        } else if (layout != null && canApplyFreeformPolicy) {
            mTmpBounds.set(currentParams.mBounds);
            getLayoutBounds(display, root, layout, mTmpBounds);
            if (!mTmpBounds.isEmpty()) {
                launchMode = WINDOWING_MODE_FREEFORM;
@@ -500,11 +501,11 @@ class TaskLaunchParamsModifier implements LaunchParamsModifier {
    }

    private void getLayoutBounds(@NonNull DisplayContent display, @NonNull ActivityRecord root,
            @NonNull ActivityInfo.WindowLayout windowLayout, @NonNull Rect outBounds) {
            @NonNull ActivityInfo.WindowLayout windowLayout, @NonNull Rect inOutBounds) {
        final int verticalGravity = windowLayout.gravity & Gravity.VERTICAL_GRAVITY_MASK;
        final int horizontalGravity = windowLayout.gravity & Gravity.HORIZONTAL_GRAVITY_MASK;
        if (!windowLayout.hasSpecifiedSize() && verticalGravity == 0 && horizontalGravity == 0) {
            outBounds.setEmpty();
            inOutBounds.setEmpty();
            return;
        }

@@ -518,11 +519,17 @@ class TaskLaunchParamsModifier implements LaunchParamsModifier {
        int width;
        int height;
        if (!windowLayout.hasSpecifiedSize()) {
            outBounds.setEmpty();
            if (!inOutBounds.isEmpty()) {
                // If the bounds is resolved already and WindowLayout doesn't have any opinion on
                // its size, use the already resolved size and apply the gravity to it.
                width = inOutBounds.width();
                height = inOutBounds.height();
            } else {
                getTaskBounds(root, display, windowLayout, WINDOWING_MODE_FREEFORM,
                    /* hasInitialBounds */ false, outBounds);
            width = outBounds.width();
            height = outBounds.height();
                        /* hasInitialBounds */ false, inOutBounds);
                width = inOutBounds.width();
                height = inOutBounds.height();
            }
        } else {
            width = defaultWidth;
            if (windowLayout.width > 0 && windowLayout.width < defaultWidth) {
@@ -563,11 +570,11 @@ class TaskLaunchParamsModifier implements LaunchParamsModifier {
                fractionOfVerticalOffset = 0.5f;
        }

        outBounds.set(0, 0, width, height);
        outBounds.offset(displayStableBounds.left, displayStableBounds.top);
        inOutBounds.set(0, 0, width, height);
        inOutBounds.offset(displayStableBounds.left, displayStableBounds.top);
        final int xOffset = (int) (fractionOfHorizontalOffset * (defaultWidth - width));
        final int yOffset = (int) (fractionOfVerticalOffset * (defaultHeight - height));
        outBounds.offset(xOffset, yOffset);
        inOutBounds.offset(xOffset, yOffset);
    }

    private boolean shouldLaunchUnresizableAppInFreeform(ActivityRecord activity,
+8 −1
Original line number Diff line number Diff line
@@ -521,6 +521,7 @@ public class TaskLaunchParamsModifierTests extends WindowTestsBase {
                WINDOWING_MODE_FULLSCREEN);
    }


    @Test
    public void testKeepsPictureInPictureLaunchModeInOptions() {
        final TestDisplayContent freeformDisplay = createNewDisplayContent(
@@ -588,11 +589,14 @@ public class TaskLaunchParamsModifierTests extends WindowTestsBase {
    }

    @Test
    public void testNonEmptyLayoutInfersFreeformWithEmptySize() {
    public void testLayoutWithGravityAndEmptySizeInfersFreeformAndRespectsCurrentSize() {
        final TestDisplayContent freeformDisplay = createNewDisplayContent(
                WINDOWING_MODE_FREEFORM);

        final Rect expectedLaunchBounds = new Rect(0, 0, 200, 100);

        mCurrent.mPreferredTaskDisplayArea = freeformDisplay.getDefaultTaskDisplayArea();
        mCurrent.mBounds.set(expectedLaunchBounds);

        final ActivityInfo.WindowLayout layout = new WindowLayoutBuilder()
                .setGravity(Gravity.LEFT).build();
@@ -600,6 +604,9 @@ public class TaskLaunchParamsModifierTests extends WindowTestsBase {
        assertEquals(RESULT_CONTINUE,
                new CalculateRequestBuilder().setLayout(layout).calculate());

        assertEquals(expectedLaunchBounds.width(), mResult.mBounds.width());
        assertEquals(expectedLaunchBounds.height(), mResult.mBounds.height());

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