From 080ae841998502c709a9f2f4a2d0f44cd7c959a3 Mon Sep 17 00:00:00 2001 From: Riddle Hsu Date: Mon, 15 Jun 2020 16:48:19 +0800 Subject: [PATCH] Set pillar box bounds in fixed orientation display Assume a non-resizable fixed portrait activity launched in a fixed landscape display, the activity should keep its portrait bounds by fitting the height to display and the width with the same ratio to height. Previously the pillar box bounds are only set to app bounds that causes the activity shown in landscape size compat mode. This change makes them consistent. Fixes: 158863196 Test: SizeCompatTests#testMoveToDifferentOrientDisplay Change-Id: Ib7c2b07d9b252a88d2e965cc16ca93f7804b16d0 --- .../com/android/server/wm/ActivityRecord.java | 31 ++++++++++--------- .../android/server/wm/SizeCompatTests.java | 19 ++++++++++-- 2 files changed, 33 insertions(+), 17 deletions(-) diff --git a/services/core/java/com/android/server/wm/ActivityRecord.java b/services/core/java/com/android/server/wm/ActivityRecord.java index be2f9d4104752..95444b4a0e323 100644 --- a/services/core/java/com/android/server/wm/ActivityRecord.java +++ b/services/core/java/com/android/server/wm/ActivityRecord.java @@ -7720,24 +7720,25 @@ final class ActivityRecord extends WindowToken implements WindowManagerService.A outAppBounds.set(outBounds); } } else { - outBounds.set(0, 0, mWidth, mHeight); - getFrameByOrientation(outAppBounds, orientation); - if (orientationRequested && !canChangeOrientation - && (outAppBounds.width() > outAppBounds.height()) != (mWidth > mHeight)) { - // The orientation is mismatched but the display cannot rotate. The bounds will - // fit to the short side of display. - if (orientation == ORIENTATION_LANDSCAPE) { - outAppBounds.bottom = (int) ((float) mWidth * mWidth / mHeight); - outAppBounds.right = mWidth; - } else { - outAppBounds.bottom = mHeight; - outAppBounds.right = (int) ((float) mHeight * mHeight / mWidth); + if (orientationRequested) { + getFrameByOrientation(outBounds, orientation); + if ((outBounds.width() > outBounds.height()) != (mWidth > mHeight)) { + // The orientation is mismatched but the display cannot rotate. The bounds + // will fit to the short side of display. + if (orientation == ORIENTATION_LANDSCAPE) { + outBounds.bottom = (int) ((float) mWidth * mWidth / mHeight); + outBounds.right = mWidth; + } else { + outBounds.bottom = mHeight; + outBounds.right = (int) ((float) mHeight * mHeight / mWidth); + } + outBounds.offset( + getHorizontalCenterOffset(mWidth, outBounds.width()), 0 /* dy */); } - outAppBounds.offset(getHorizontalCenterOffset(outBounds.width(), - outAppBounds.width()), 0 /* dy */); } else { - outAppBounds.set(outBounds); + outBounds.set(0, 0, mWidth, mHeight); } + outAppBounds.set(outBounds); } if (rotation != ROTATION_UNDEFINED) { 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 665cf83cd33c6..8ac2d916d2190 100644 --- a/services/tests/wmtests/src/com/android/server/wm/SizeCompatTests.java +++ b/services/tests/wmtests/src/com/android/server/wm/SizeCompatTests.java @@ -288,14 +288,29 @@ public class SizeCompatTests extends ActivityTestsBase { // Move the non-resizable activity to the new display. mStack.reparent(newDisplay.getDefaultTaskDisplayArea(), true /* onTop */); - // The configuration bounds should keep the same. + // The configuration bounds [820, 0 - 1820, 2500] should keep the same. assertEquals(origWidth, configBounds.width()); assertEquals(origHeight, configBounds.height()); assertScaled(); + final Rect newDisplayBounds = newDisplay.getWindowConfiguration().getBounds(); // The scaled bounds should exclude notch area (1000 - 100 == 360 * 2500 / 1000 = 900). - assertEquals(newDisplay.getBounds().height() - notchHeight, + assertEquals(newDisplayBounds.height() - notchHeight, (int) ((float) mActivity.getBounds().width() * origHeight / origWidth)); + + // Recompute the natural configuration in the new display. + mActivity.clearSizeCompatMode(); + mActivity.ensureActivityConfiguration(0 /* globalChanges */, false /* preserveWindow */); + // Because the display cannot rotate, the portrait activity will fit the short side of + // display with keeping portrait bounds [200, 0 - 700, 1000] in center. + assertEquals(newDisplayBounds.height(), configBounds.height()); + assertEquals(configBounds.height() * newDisplayBounds.height() / newDisplayBounds.width(), + configBounds.width()); + assertFitted(); + // The appBounds should be [200, 100 - 700, 1000]. + final Rect appBounds = mActivity.getWindowConfiguration().getAppBounds(); + assertEquals(configBounds.width(), appBounds.width()); + assertEquals(configBounds.height() - notchHeight, appBounds.height()); } @Test