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

Commit 8a68368b authored by Chris Li's avatar Chris Li
Browse files

Use the app request aspect ratio for Task letterboxing

Before, when app requests fix orientation with aspect ratio, it will
first be letterboxed at Task level with display ratio, and then be
letterboxed at Activity level with request ratio, which may become too
small (fill neither of display width and height).

This change is to have Task level letterboxing use the app request
aspect ratio (if set) instead of display ratio.

Bug: 170725334
Bug: 155431879
Test: atest WmTests:SizeCompatTests
Test: manual: adb shell wm set-ignore-orientation-request true
Change-Id: I568db28125fa11c2a78ff4d6930abb49ca3fffe8
parent d5f2cd95
Loading
Loading
Loading
Loading
+17 −3
Original line number Diff line number Diff line
@@ -2912,13 +2912,27 @@ class Task extends WindowContainer<WindowContainer> {

        final int parentWidth = parentBounds.width();
        final int parentHeight = parentBounds.height();
        final float aspect = ((float) parentHeight) / parentWidth;
        float aspect = Math.max(parentWidth, parentHeight)
                / (float) Math.min(parentWidth, parentHeight);

        // Adjust the Task letterbox bounds to fit the app request aspect ratio in order to use the
        // extra available space.
        if (refActivity != null) {
            final float maxAspectRatio = refActivity.info.maxAspectRatio;
            final float minAspectRatio = refActivity.info.minAspectRatio;
            if (aspect > maxAspectRatio && maxAspectRatio != 0) {
                aspect = maxAspectRatio;
            } else if (aspect < minAspectRatio) {
                aspect = minAspectRatio;
            }
        }

        if (forcedOrientation == ORIENTATION_LANDSCAPE) {
            final int height = (int) (parentWidth / aspect);
            final int height = (int) Math.rint(parentWidth / aspect);
            final int top = parentBounds.centerY() - height / 2;
            outBounds.set(parentBounds.left, top, parentBounds.right, top + height);
        } else {
            final int width = (int) (parentHeight * aspect);
            final int width = (int) Math.rint(parentHeight / aspect);
            final int left = parentBounds.centerX() - width / 2;
            outBounds.set(left, parentBounds.top, left + width, parentBounds.bottom);
        }
+4 −6
Original line number Diff line number Diff line
@@ -750,17 +750,15 @@ public class SizeCompatTests extends WindowTestsBase {
        final Rect taskBounds = mTask.getBounds();
        final Rect newActivityBounds = newActivity.getBounds();

        // Task bounds should be 700x1400 with the ratio as the display.
        // Task bounds should be (1400 / 1.3 = 1076)x1400 with the app requested ratio.
        assertTrue(mTask.isTaskLetterboxed());
        assertEquals(displayBounds.height(), taskBounds.height());
        assertEquals(displayBounds.height() * displayBounds.height() / displayBounds.width(),
        assertEquals((long) Math.rint(taskBounds.height() / newActivity.info.maxAspectRatio),
                taskBounds.width());

        // App bounds should be 700x(710 x 1.3 = 910)
        // App bounds should be fullscreen in Task bounds.
        assertFalse(newActivity.inSizeCompatMode());
        assertEquals(taskBounds.width(), newActivityBounds.width());
        assertEquals((long) Math.rint(taskBounds.width() * newActivity.info.maxAspectRatio),
                newActivityBounds.height());
        assertEquals(taskBounds, newActivityBounds);
    }

    private static WindowState addWindowToActivity(ActivityRecord activity) {