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

Commit 23fb7a6a authored by Chris Li's avatar Chris Li Committed by Android (Google) Code Review
Browse files

Merge "Use the app request aspect ratio for Task letterboxing"

parents 92b3adcb 8a68368b
Loading
Loading
Loading
Loading
+17 −3
Original line number Diff line number Diff line
@@ -2921,13 +2921,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) {