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

Commit c545ce99 authored by Riddle Hsu's avatar Riddle Hsu
Browse files

Compute configuration orientation by available screen size

It aligns the same calculation as
TaskFragment#computeConfigResourceOverrides.

Otherwise when the display size is close to square and there are
decor windows, the configuration of activity and non-activity
component will be inconsistent.

Bug: 233855302
Test: atest DisplayContentTests#testOrientationForAspectRatio
Change-Id: If6a1d5e28b51b14a2d154872b3e65f6b3c82c101
parent 488eb985
Loading
Loading
Loading
Loading
+2 −1
Original line number Diff line number Diff line
@@ -2422,13 +2422,14 @@ class DisplayContent extends RootDisplayArea implements WindowManagerPolicy.Disp
        // AppBounds at the root level should mirror the app screen size.
        outConfig.windowConfiguration.setAppBounds(info.mNonDecorFrame);
        outConfig.windowConfiguration.setRotation(rotation);
        outConfig.orientation = (dw <= dh) ? ORIENTATION_PORTRAIT : ORIENTATION_LANDSCAPE;

        final float density = mDisplayMetrics.density;
        outConfig.screenWidthDp = (int) (info.mConfigFrame.width() / density + 0.5f);
        outConfig.screenHeightDp = (int) (info.mConfigFrame.height() / density + 0.5f);
        outConfig.compatScreenWidthDp = (int) (outConfig.screenWidthDp / mCompatibleScreenScale);
        outConfig.compatScreenHeightDp = (int) (outConfig.screenHeightDp / mCompatibleScreenScale);
        outConfig.orientation = (outConfig.screenWidthDp <= outConfig.screenHeightDp)
                ? ORIENTATION_PORTRAIT : ORIENTATION_LANDSCAPE;
        outConfig.screenLayout = computeScreenLayout(
                Configuration.resetScreenLayout(outConfig.screenLayout),
                outConfig.screenWidthDp, outConfig.screenHeightDp);
+7 −0
Original line number Diff line number Diff line
@@ -969,6 +969,13 @@ public class DisplayContentTests extends WindowTestsBase {
        assertEquals(
                "Screen orientation must be defined by the window even on close-to-square display.",
                window.mAttrs.screenOrientation, dc.getOrientation());

        // Assume that a decor window occupies the display height, so the configuration orientation
        // should be landscape.
        dc.getDisplayPolicy().getDecorInsetsInfo(ROTATION_0, dc.mBaseDisplayHeight,
                dc.mBaseDisplayWidth).mConfigFrame.set(0, 0, 1000, 990);
        dc.computeScreenConfiguration(config, ROTATION_0);
        assertEquals(Configuration.ORIENTATION_LANDSCAPE, config.orientation);
    }

    @Test