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

Commit dac39549 authored by Alp Yalcin's avatar Alp Yalcin
Browse files

[1/n] Round to the nearest integer after all division operations in the bounds calculation

Currently, we are adding +0.5f to round to the nearest integer in bounds calculation. However, there are 2 division operations that are missing the addition of +0.5f. This causes test failures, especially when we update the default initial bounds scale from 75% to 72%

This CL fixes the issue by adding +0.5f margin to these left cases, which prepares the ground for updating to 72% scale. We also add the same +0.5f margin to 2 test cases to prevent test failures by only one unit difference, which occurs due to `float` to `int` casts after the division operation in the tests.

Flag: EXEMPT calculation fix
Test: atest WmTests:DesktopModeLaunchParamsModifierTests
Bug: 433505659
Change-Id: I8bcb65efe628b439ccc4cdebae8d9d9a6368a18f
parent f085c10b
Loading
Loading
Loading
Loading
+2 −2
Original line number Diff line number Diff line
@@ -292,7 +292,7 @@ public final class DesktopModeBoundsCalculator {
        if (orientation == ORIENTATION_PORTRAIT) {
            // Portrait activity.
            // Calculate required width given ideal height and aspect ratio.
            int tempWidth = (int) (targetHeight / aspectRatio);
            int tempWidth = (int) ((targetHeight / aspectRatio) + 0.5f);
            if (tempWidth <= targetWidth) {
                // If the calculated width does not exceed the ideal width, overall size is within
                // ideal size and can be applied.
@@ -319,7 +319,7 @@ public final class DesktopModeBoundsCalculator {
                // aspect ratio. Instead apply ideal width and calculate required height to respect
                // aspect ratio.
                finalWidth = targetWidth;
                finalHeight = (int) (finalWidth / aspectRatio);
                finalHeight = (int) ((finalWidth / aspectRatio) + 0.5f);
            }
        }
        return new Size(finalWidth, finalHeight + captionHeight);
+4 −3
Original line number Diff line number Diff line
@@ -893,8 +893,8 @@ public class DesktopModeLaunchParamsModifierTests extends
        final int desiredHeight =
                (int) (LANDSCAPE_DISPLAY_BOUNDS.height() * DESKTOP_MODE_INITIAL_BOUNDS_SCALE);
        final int desiredWidth =
                (int) (desiredHeight / activity.mAppCompatController
                        .getAspectRatioOverrides().getSplitScreenAspectRatio());
                (int) ((desiredHeight / activity.mAppCompatController
                        .getAspectRatioOverrides().getSplitScreenAspectRatio()) + 0.5f);

        assertEquals(RESULT_CONTINUE, new CalculateRequestBuilder().setTask(task)
                .setActivity(activity).calculate());
@@ -1092,7 +1092,8 @@ public class DesktopModeLaunchParamsModifierTests extends

        final int desiredHeight =
                (int) (LANDSCAPE_DISPLAY_BOUNDS.height() * DESKTOP_MODE_INITIAL_BOUNDS_SCALE);
        final int desiredWidth = (int) (desiredHeight / userAspectRatioOverrideValueSplitScreen);
        final int desiredWidth =
                (int) ((desiredHeight / userAspectRatioOverrideValueSplitScreen) + 0.5f);

        assertEquals(RESULT_CONTINUE, new CalculateRequestBuilder().setTask(task)
                .setActivity(activity).calculate());