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

Commit 9ad17851 authored by Riddle Hsu's avatar Riddle Hsu
Browse files

Correct size compat mode condition of aspect ratio

This fixes the case: when both min, max aspect ratio are set and
the current aspect ratio reaches the max, and the size doesn't
fill the parent, it will always be size compact mode.

By filtering out the simple conditions first, the checking of fixed
aspect ratio only applies to at least one side matches parent, that
also makes the logic better understood.

Bug: 112288258
Test: atest ActivityRecordTests# \
      testSizeCompatMode_FixedAspectRatioBoundsWithDecor
Change-Id: I82900ac940bf31c3ac2b87f7b133ba98aa2afe99
parent aecff3d7
Loading
Loading
Loading
Loading
+23 −13
Original line number Original line Diff line number Diff line
@@ -2730,30 +2730,40 @@ final class ActivityRecord extends ConfigurationContainer {
        final int appHeight = resolvedAppBounds.height();
        final int appHeight = resolvedAppBounds.height();
        final int parentAppWidth = parentAppBounds.width();
        final int parentAppWidth = parentAppBounds.width();
        final int parentAppHeight = parentAppBounds.height();
        final int parentAppHeight = parentAppBounds.height();
        if (parentAppWidth == appWidth && parentAppHeight == appHeight) {
            // Matched the parent bounds.
            return false;
        }
        if (parentAppWidth > appWidth && parentAppHeight > appHeight) {
            // Both sides are smaller than the parent.
            return true;
        }
        if (parentAppWidth < appWidth || parentAppHeight < appHeight) {
        if (parentAppWidth < appWidth || parentAppHeight < appHeight) {
            // One side is larger than the parent.
            // One side is larger than the parent.
            return true;
            return true;
        }
        }


        if (info.hasFixedAspectRatio()) {
        // The rest of the condition is that only one side is smaller than the parent, but it still
        // needs to exclude the cases where the size is limited by the fixed aspect ratio.
        if (info.maxAspectRatio > 0) {
            final float aspectRatio = (0.5f + Math.max(appWidth, appHeight))
            final float aspectRatio = (0.5f + Math.max(appWidth, appHeight))
                    / Math.min(appWidth, appHeight);
                    / Math.min(appWidth, appHeight);
            if (aspectRatio >= info.maxAspectRatio) {
                // The current size has reached the max aspect ratio.
                return false;
            }
        }
        if (info.minAspectRatio > 0) {
            // The activity should have at least the min aspect ratio, so this checks if the parent
            // still has available space to provide larger aspect ratio.
            final float parentAspectRatio = (0.5f + Math.max(parentAppWidth, parentAppHeight))
            final float parentAspectRatio = (0.5f + Math.max(parentAppWidth, parentAppHeight))
                    / Math.min(parentAppWidth, parentAppHeight);
                    / Math.min(parentAppWidth, parentAppHeight);
            // Check if the parent still has available space in long side.
            if (parentAspectRatio <= info.minAspectRatio) {
            if (aspectRatio < parentAspectRatio
                // The long side has reached the parent.
                    && (aspectRatio < info.maxAspectRatio || info.minAspectRatio > 0)) {
                return false;
                return true;
            }
            }
        }
        }

        return true;
        final Rect resolvedBounds = resolvedConfig.windowConfiguration.getBounds();
        // If the width or height is the same as parent, it is already the best fit of the override
        // bounds, therefore this condition is considered as not size compatibility mode. Here uses
        // right and bottom as width and height of parent because the bounds may contain decor
        // insets which has been accounted in override bounds. See {@link #computeBounds}.
        return parentAppBounds.right != resolvedBounds.width()
                && parentAppBounds.bottom != resolvedBounds.height();
    }
    }


    /**
    /**
+4 −1
Original line number Original line Diff line number Diff line
@@ -438,8 +438,11 @@ public class ActivityRecordTests extends ActivityTestsBase {
        doReturn(ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED)
        doReturn(ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED)
                .when(mActivity.mAppWindowToken).getOrientationIgnoreVisibility();
                .when(mActivity.mAppWindowToken).getOrientationIgnoreVisibility();
        mActivity.info.resizeMode = ActivityInfo.RESIZE_MODE_UNRESIZEABLE;
        mActivity.info.resizeMode = ActivityInfo.RESIZE_MODE_UNRESIZEABLE;
        mActivity.info.maxAspectRatio = 1;
        mActivity.info.minAspectRatio = mActivity.info.maxAspectRatio = 1;
        ensureActivityConfiguration();
        ensureActivityConfiguration();
        // The parent configuration doesn't change since the first resolved configuration, so the
        // activity shouldn't be in the size compatibility mode.
        assertFalse(mActivity.inSizeCompatMode());


        final Rect appBounds = mActivity.getWindowConfiguration().getAppBounds();
        final Rect appBounds = mActivity.getWindowConfiguration().getAppBounds();
        // Ensure the app bounds keep the declared aspect ratio.
        // Ensure the app bounds keep the declared aspect ratio.