diff options
| author | 2023-01-23 13:43:50 +0000 | |
|---|---|---|
| committer | 2023-01-27 15:24:03 +0000 | |
| commit | ace36c79b4fd91704fc34bbf3fe56d09d9c4a53f (patch) | |
| tree | e392bf7acddf7b91e644d455fa31b1dac9488eb0 | |
| parent | 04f7a3b26e0314fbfd3f50bfa14dd17421e83939 (diff) | |
Replace containing aspect ratio hard comparison with rounded one
Bug: 244489223
Test: atest WmTests:SizeCompatTests#testApplyAspectRatio_containingRatioAlmostEqualToMaxRatio_boundsUnchanged
Change-Id: Id604e80d6c9be2231750157c7a06eb606ddefb1c
| -rw-r--r-- | services/core/java/com/android/server/wm/ActivityRecord.java | 7 | ||||
| -rw-r--r-- | services/tests/wmtests/src/com/android/server/wm/SizeCompatTests.java | 14 |
2 files changed, 19 insertions, 2 deletions
diff --git a/services/core/java/com/android/server/wm/ActivityRecord.java b/services/core/java/com/android/server/wm/ActivityRecord.java index 6b01a7726a43..5ef20c5f304e 100644 --- a/services/core/java/com/android/server/wm/ActivityRecord.java +++ b/services/core/java/com/android/server/wm/ActivityRecord.java @@ -439,6 +439,9 @@ final class ActivityRecord extends WindowToken implements WindowManagerService.A // finished destroying itself. private static final int DESTROY_TIMEOUT = 10 * 1000; + // Rounding tolerance to be used in aspect ratio computations + private static final float ASPECT_RATIO_ROUNDING_TOLERANCE = 0.005f; + final ActivityTaskManagerService mAtmService; @NonNull final ActivityInfo info; // activity info provided by developer in AndroidManifest @@ -8915,7 +8918,7 @@ final class ActivityRecord extends WindowToken implements WindowManagerService.A int activityWidth = containingAppWidth; int activityHeight = containingAppHeight; - if (containingRatio > desiredAspectRatio) { + if (containingRatio - desiredAspectRatio > ASPECT_RATIO_ROUNDING_TOLERANCE) { if (containingAppWidth < containingAppHeight) { // Width is the shorter side, so we use that to figure-out what the max. height // should be given the aspect ratio. @@ -8925,7 +8928,7 @@ final class ActivityRecord extends WindowToken implements WindowManagerService.A // should be given the aspect ratio. activityWidth = (int) ((activityHeight * desiredAspectRatio) + 0.5f); } - } else if (containingRatio < desiredAspectRatio) { + } else if (desiredAspectRatio - containingRatio > ASPECT_RATIO_ROUNDING_TOLERANCE) { boolean adjustWidth; switch (getRequestedConfigurationOrientation()) { case ORIENTATION_LANDSCAPE: 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 995932c46201..5e27ab05d71d 100644 --- a/services/tests/wmtests/src/com/android/server/wm/SizeCompatTests.java +++ b/services/tests/wmtests/src/com/android/server/wm/SizeCompatTests.java @@ -2802,6 +2802,20 @@ public class SizeCompatTests extends WindowTestsBase { } @Test + public void testApplyAspectRatio_containingRatioAlmostEqualToMaxRatio_boundsUnchanged() { + setUpDisplaySizeWithApp(1981, 2576); + mActivity.mDisplayContent.setIgnoreOrientationRequest(true /* ignoreOrientationRequest */); + mWm.mLetterboxConfiguration.setLetterboxVerticalPositionMultiplier(0.5f); + + final Rect originalBounds = new Rect(mActivity.getBounds()); + prepareUnresizable(mActivity, 1.3f, SCREEN_ORIENTATION_UNSPECIFIED); + + // The containing aspect ratio is now 1.3003534, while the desired aspect ratio is 1.3. The + // bounds of the activity should not be changed as the difference is too small + assertEquals(mActivity.getBounds(), originalBounds); + } + + @Test public void testUpdateResolvedBoundsHorizontalPosition_activityFillParentWidth() { // When activity width equals parent width, multiplier shouldn't have any effect. assertHorizontalPositionForDifferentDisplayConfigsForLandscapeActivity( |