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

Commit 51afcf8b authored by Riddle Hsu's avatar Riddle Hsu
Browse files

Return natural orientation according to available screen size

It aligns the same policy as
TaskFragment#computeConfigResourceOverrides to resolve orientation.

Otherwise when the display size is close to square. A nosensor
activity may get natural orientation in portrait but get task
orientation in landscape, which causes unexpected letterbox.

e.g. physical screen size is 1000x1010 -> portrait
But screenWidthDp=500, screenHeightDp=490 (occupied by insets)
-> landscape

Bug: 233855302
Test: atest DisplayContentTests#testOrientationForAspectRatio
Change-Id: I6d148e6dc5fe543f20c0b5aef0fc9255c2e481aa
parent bdd1caeb
Loading
Loading
Loading
Loading
+7 −2
Original line number Diff line number Diff line
@@ -5124,8 +5124,13 @@ class DisplayContent extends RootDisplayArea implements WindowManagerPolicy.Disp

    /** @return the orientation of the display when it's rotation is ROTATION_0. */
    int getNaturalOrientation() {
        return mBaseDisplayWidth < mBaseDisplayHeight
                ? ORIENTATION_PORTRAIT : ORIENTATION_LANDSCAPE;
        final Configuration config = getConfiguration();
        if (config.windowConfiguration.getDisplayRotation() == ROTATION_0) {
            return config.orientation;
        }
        final Rect frame = mDisplayPolicy.getDecorInsetsInfo(
                ROTATION_0, mBaseDisplayWidth, mBaseDisplayHeight).mConfigFrame;
        return frame.width() <= frame.height() ? ORIENTATION_PORTRAIT : ORIENTATION_LANDSCAPE;
    }

    void performLayout(boolean initial, boolean updateInputWindows) {
+2 −0
Original line number Diff line number Diff line
@@ -993,7 +993,9 @@ public class DisplayContentTests extends WindowTestsBase {
        dc.getDisplayPolicy().getDecorInsetsInfo(ROTATION_0, dc.mBaseDisplayHeight,
                dc.mBaseDisplayWidth).mConfigFrame.set(0, 0, 1000, 990);
        dc.computeScreenConfiguration(config, ROTATION_0);
        dc.onRequestedOverrideConfigurationChanged(config);
        assertEquals(Configuration.ORIENTATION_LANDSCAPE, config.orientation);
        assertEquals(Configuration.ORIENTATION_LANDSCAPE, dc.getNaturalOrientation());
    }

    @Test