Correct rounding in PipSizeSpecHandler

Make sure to use rounding instead of flooring
while calculating maxWidth in PipSizeSpecHandler

Bug: 285638992
Test: atest WMShellUnitTests:PipSizeSpecHandlerTest
Test: atest PinnedStackTests

Change-Id: I648f6e4700e246c200952d6ae509aa70117c6dc9
This commit is contained in:
Ikram Gabiyev
2023-07-05 14:16:38 -07:00
parent be10d8551a
commit 9befce8b32
2 changed files with 13 additions and 12 deletions

View File

@@ -123,18 +123,19 @@ public class PipSizeSpecHandler {
final int totalVerticalPadding = getInsetBounds().top
+ (getDisplayBounds().height() - getInsetBounds().bottom);
final int shorterLength = (int) (1f * Math.min(
getDisplayBounds().width() - totalHorizontalPadding,
getDisplayBounds().height() - totalVerticalPadding));
final int shorterLength = Math.min(getDisplayBounds().width() - totalHorizontalPadding,
getDisplayBounds().height() - totalVerticalPadding);
int maxWidth, maxHeight;
// use the optimized max sizing logic only within a certain aspect ratio range
if (aspectRatio >= mOptimizedAspectRatio && aspectRatio <= 1 / mOptimizedAspectRatio) {
// this formula and its derivation is explained in b/198643358#comment16
maxWidth = (int) (mOptimizedAspectRatio * shorterLength
maxWidth = Math.round(mOptimizedAspectRatio * shorterLength
+ shorterLength * (aspectRatio - mOptimizedAspectRatio) / (1
+ aspectRatio));
// make sure the max width doesn't go beyond shorter screen length after rounding
maxWidth = Math.min(maxWidth, shorterLength);
maxHeight = Math.round(maxWidth / aspectRatio);
} else {
if (aspectRatio > 1f) {

View File

@@ -110,17 +110,17 @@ public class PipSizeSpecHandlerTest extends ShellTestCase {
sExpectedDefaultSizes.put(16f / 9, new Size(600, 338));
sExpectedMinSizes.put(16f / 9, new Size(501, 282));
sExpectedMaxSizes.put(4f / 3, new Size(892, 669));
sExpectedDefaultSizes.put(4f / 3, new Size(535, 401));
sExpectedMaxSizes.put(4f / 3, new Size(893, 670));
sExpectedDefaultSizes.put(4f / 3, new Size(536, 402));
sExpectedMinSizes.put(4f / 3, new Size(447, 335));
sExpectedMaxSizes.put(3f / 4, new Size(669, 892));
sExpectedDefaultSizes.put(3f / 4, new Size(401, 535));
sExpectedMaxSizes.put(3f / 4, new Size(670, 893));
sExpectedDefaultSizes.put(3f / 4, new Size(402, 536));
sExpectedMinSizes.put(3f / 4, new Size(335, 447));
sExpectedMaxSizes.put(9f / 16, new Size(562, 999));
sExpectedDefaultSizes.put(9f / 16, new Size(337, 599));
sExpectedMinSizes.put(9f / 16, new Size(281, 500));
sExpectedMaxSizes.put(9f / 16, new Size(563, 1001));
sExpectedDefaultSizes.put(9f / 16, new Size(338, 601));
sExpectedMinSizes.put(9f / 16, new Size(282, 501));
}
private void forEveryTestCaseCheck(Map<Float, Size> expectedSizes,
@@ -192,7 +192,7 @@ public class PipSizeSpecHandlerTest extends ShellTestCase {
// an initial size with 16:9 aspect ratio
Size initSize = new Size(600, 337);
Size expectedSize = new Size(337, 599);
Size expectedSize = new Size(338, 601);
Size actualSize = mPipSizeSpecHandler.getSizeForAspectRatio(initSize, 9f / 16);
Assert.assertEquals(expectedSize, actualSize);