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

Commit 897fe257 authored by Eghosa Ewansiha-Vlachavas's avatar Eghosa Ewansiha-Vlachavas Committed by Android (Google) Code Review
Browse files

Merge "Use new config to check windowing mode for upscaling enabling/disabling" into main

parents a5d0277b f6af3e78
Loading
Loading
Loading
Loading
+8 −5
Original line number Diff line number Diff line
@@ -145,11 +145,13 @@ class AppCompatSizeCompatModePolicy {
        }
    }

    void updateSizeCompatScale(@NonNull Rect resolvedAppBounds, @NonNull Rect containerAppBounds) {
    void updateSizeCompatScale(@NonNull Rect resolvedAppBounds, @NonNull Rect containerAppBounds,
            @NonNull Configuration newParentConfig) {
        mSizeCompatScale = mActivityRecord.mAppCompatController.getTransparentPolicy()
                .findOpaqueNotFinishingActivityBelow()
                .map(activityRecord -> mSizeCompatScale)
                .orElseGet(() -> calculateSizeCompatScale(resolvedAppBounds, containerAppBounds));
                .orElseGet(() -> calculateSizeCompatScale(
                        resolvedAppBounds, containerAppBounds, newParentConfig));
    }

    void clearSizeCompatModeAttributes() {
@@ -290,7 +292,7 @@ class AppCompatSizeCompatModePolicy {
        // Calculates the scale the size compatibility bounds into the region which is available
        // to application.
        final float lastSizeCompatScale = mSizeCompatScale;
        updateSizeCompatScale(resolvedAppBounds, containerAppBounds);
        updateSizeCompatScale(resolvedAppBounds, containerAppBounds, newParentConfiguration);

        final int containerTopInset = containerAppBounds.top - containerBounds.top;
        final boolean topNotAligned =
@@ -423,7 +425,7 @@ class AppCompatSizeCompatModePolicy {
    }

    private float calculateSizeCompatScale(@NonNull Rect resolvedAppBounds,
            @NonNull Rect containerAppBounds) {
            @NonNull Rect containerAppBounds, @NonNull Configuration newParentConfig) {
        final int contentW = resolvedAppBounds.width();
        final int contentH = resolvedAppBounds.height();
        final int viewportW = containerAppBounds.width();
@@ -432,7 +434,8 @@ class AppCompatSizeCompatModePolicy {
        // original container or if it's a freeform window in desktop mode.
        boolean shouldAllowUpscaling = !(contentW <= viewportW && contentH <= viewportH)
                || (canEnterDesktopMode(mActivityRecord.mAtmService.mContext)
                    && mActivityRecord.getWindowingMode() == WINDOWING_MODE_FREEFORM);
                && newParentConfig.windowConfiguration.getWindowingMode()
                    == WINDOWING_MODE_FREEFORM);
        return shouldAllowUpscaling ? Math.min(
                (float) viewportW / contentW, (float) viewportH / contentH) : 1f;
    }
+35 −3
Original line number Diff line number Diff line
@@ -1640,7 +1640,7 @@ public class SizeCompatTests extends WindowTestsBase {
                .build();
        setUpApp(display);
        prepareUnresizable(mActivity, /* maxAspect */ 0f, SCREEN_ORIENTATION_PORTRAIT);
        mActivity.setWindowingMode(WINDOWING_MODE_FREEFORM);
        mTask.getWindowConfiguration().setWindowingMode(WINDOWING_MODE_FREEFORM);
        assertFalse(mActivity.inSizeCompatMode());

        // Resize app to make original app bounds larger than parent bounds.
@@ -1667,7 +1667,7 @@ public class SizeCompatTests extends WindowTestsBase {
                .build();
        setUpApp(display);
        prepareUnresizable(mActivity, /* maxAspect */ 0f, SCREEN_ORIENTATION_PORTRAIT);
        mActivity.setWindowingMode(WINDOWING_MODE_FREEFORM);
        mTask.getWindowConfiguration().setWindowingMode(WINDOWING_MODE_FREEFORM);
        assertFalse(mActivity.inSizeCompatMode());

        // Resize app to make original app bounds smaller than parent bounds.
@@ -1692,7 +1692,7 @@ public class SizeCompatTests extends WindowTestsBase {
                .build();
        setUpApp(display);
        prepareUnresizable(mActivity, /* maxAspect */ 0f, SCREEN_ORIENTATION_PORTRAIT);
        mActivity.setWindowingMode(WINDOWING_MODE_FREEFORM);
        mTask.getWindowConfiguration().setWindowingMode(WINDOWING_MODE_FREEFORM);
        assertFalse(mActivity.inSizeCompatMode());
        final Rect originalAppBounds = mActivity.getBounds();

@@ -1705,6 +1705,38 @@ public class SizeCompatTests extends WindowTestsBase {
        assertEquals(originalAppBounds, mActivity.getBounds());
    }

    /**
     * Test that when desktop mode is enabled, a freeform unresizeable activity is not up-scaled
     * when exiting freeform despite its larger parent bounds.
     */
    @Test
    @EnableFlags(Flags.FLAG_ENABLE_DESKTOP_WINDOWING_MODE)
    public void testCompatScaling_freeformUnresizeableApp_exitFreeform_notScaled() {
        doReturn(true).when(() ->
                DesktopModeHelper.canEnterDesktopMode(any()));
        final int dw = 600;
        final int dh = 800;
        final DisplayContent display = new TestDisplayContent.Builder(mAtm, dw, dh)
                .setWindowingMode(WINDOWING_MODE_FREEFORM)
                .build();
        setUpApp(display);
        prepareUnresizable(mActivity, /* maxAspect */ 0f, SCREEN_ORIENTATION_PORTRAIT);
        mTask.getWindowConfiguration().setWindowingMode(WINDOWING_MODE_FREEFORM);
        final Rect originalAppBounds = mActivity.getBounds();

        assertFalse(mActivity.inSizeCompatMode());

        // Resize app to make original app bounds smaller than parent bounds.
        mTask.getWindowConfiguration().setAppBounds(
                new Rect(0, 0, dw + 300, dh + 400));
        // Change windowing mode from freeform to fullscreen
        mTask.getWindowConfiguration().setWindowingMode(WINDOWING_MODE_FULLSCREEN);
        mActivity.onConfigurationChanged(mTask.getConfiguration());
        // App should enter size compat mode but remain its original size.
        assertTrue(mActivity.inSizeCompatMode());
        assertEquals(originalAppBounds, mActivity.getBounds());
    }

    @Test
    public void testGetLetterboxInnerBounds_noScalingApplied() {
        // Set up a display in portrait and ignoring orientation request.