diff options
| -rw-r--r-- | services/core/java/com/android/server/wm/Task.java | 20 | ||||
| -rw-r--r-- | services/tests/wmtests/src/com/android/server/wm/SizeCompatTests.java | 10 |
2 files changed, 21 insertions, 9 deletions
diff --git a/services/core/java/com/android/server/wm/Task.java b/services/core/java/com/android/server/wm/Task.java index 557c92e9704e..86287edbd098 100644 --- a/services/core/java/com/android/server/wm/Task.java +++ b/services/core/java/com/android/server/wm/Task.java @@ -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); } diff --git a/services/tests/wmtests/src/com/android/server/wm/SizeCompatTests.java b/services/tests/wmtests/src/com/android/server/wm/SizeCompatTests.java index cc37e2bf94ca..d68dde5734ca 100644 --- a/services/tests/wmtests/src/com/android/server/wm/SizeCompatTests.java +++ b/services/tests/wmtests/src/com/android/server/wm/SizeCompatTests.java @@ -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) { |