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

Commit a891bc20 authored by Eghosa Ewansiha-Vlachavas's avatar Eghosa Ewansiha-Vlachavas Committed by Android (Google) Code Review
Browse files

Merge "Don't reassign `desiredAspectRatio` parameter in`applyAspectRatio`" into main

parents 2df0ca88 5d6321ed
Loading
Loading
Loading
Loading
+14 −13
Original line number Original line Diff line number Diff line
@@ -9317,8 +9317,9 @@ final class ActivityRecord extends WindowToken implements WindowManagerService.A
        final Task rootTask = getRootTask();
        final Task rootTask = getRootTask();
        final float minAspectRatio = getMinAspectRatio();
        final float minAspectRatio = getMinAspectRatio();
        final TaskFragment organizedTf = getOrganizedTaskFragment();
        final TaskFragment organizedTf = getOrganizedTaskFragment();
        float aspectRatioToApply = desiredAspectRatio;
        if (task == null || rootTask == null
        if (task == null || rootTask == null
                || (maxAspectRatio < 1 && minAspectRatio < 1 && desiredAspectRatio < 1)
                || (maxAspectRatio < 1 && minAspectRatio < 1 && aspectRatioToApply < 1)
                // Don't set aspect ratio if we are in VR mode.
                // Don't set aspect ratio if we are in VR mode.
                || isInVrUiMode(getConfiguration())
                || isInVrUiMode(getConfiguration())
                // TODO(b/232898850): Always respect aspect ratio requests.
                // TODO(b/232898850): Always respect aspect ratio requests.
@@ -9331,30 +9332,30 @@ final class ActivityRecord extends WindowToken implements WindowManagerService.A
        final int containingAppHeight = containingAppBounds.height();
        final int containingAppHeight = containingAppBounds.height();
        final float containingRatio = computeAspectRatio(containingAppBounds);
        final float containingRatio = computeAspectRatio(containingAppBounds);


        if (desiredAspectRatio < 1) {
        if (aspectRatioToApply < 1) {
            desiredAspectRatio = containingRatio;
            aspectRatioToApply = containingRatio;
        }
        }


        if (maxAspectRatio >= 1 && desiredAspectRatio > maxAspectRatio) {
        if (maxAspectRatio >= 1 && aspectRatioToApply > maxAspectRatio) {
            desiredAspectRatio = maxAspectRatio;
            aspectRatioToApply = maxAspectRatio;
        } else if (minAspectRatio >= 1 && desiredAspectRatio < minAspectRatio) {
        } else if (minAspectRatio >= 1 && aspectRatioToApply < minAspectRatio) {
            desiredAspectRatio = minAspectRatio;
            aspectRatioToApply = minAspectRatio;
        }
        }


        int activityWidth = containingAppWidth;
        int activityWidth = containingAppWidth;
        int activityHeight = containingAppHeight;
        int activityHeight = containingAppHeight;


        if (containingRatio - desiredAspectRatio > ASPECT_RATIO_ROUNDING_TOLERANCE) {
        if (containingRatio - aspectRatioToApply > ASPECT_RATIO_ROUNDING_TOLERANCE) {
            if (containingAppWidth < containingAppHeight) {
            if (containingAppWidth < containingAppHeight) {
                // Width is the shorter side, so we use that to figure-out what the max. height
                // Width is the shorter side, so we use that to figure-out what the max. height
                // should be given the aspect ratio.
                // should be given the aspect ratio.
                activityHeight = (int) ((activityWidth * desiredAspectRatio) + 0.5f);
                activityHeight = (int) ((activityWidth * aspectRatioToApply) + 0.5f);
            } else {
            } else {
                // Height is the shorter side, so we use that to figure-out what the max. width
                // Height is the shorter side, so we use that to figure-out what the max. width
                // should be given the aspect ratio.
                // should be given the aspect ratio.
                activityWidth = (int) ((activityHeight * desiredAspectRatio) + 0.5f);
                activityWidth = (int) ((activityHeight * aspectRatioToApply) + 0.5f);
            }
            }
        } else if (desiredAspectRatio - containingRatio > ASPECT_RATIO_ROUNDING_TOLERANCE) {
        } else if (aspectRatioToApply - containingRatio > ASPECT_RATIO_ROUNDING_TOLERANCE) {
            boolean adjustWidth;
            boolean adjustWidth;
            switch (getRequestedConfigurationOrientation()) {
            switch (getRequestedConfigurationOrientation()) {
                case ORIENTATION_LANDSCAPE:
                case ORIENTATION_LANDSCAPE:
@@ -9382,9 +9383,9 @@ final class ActivityRecord extends WindowToken implements WindowManagerService.A
                    break;
                    break;
            }
            }
            if (adjustWidth) {
            if (adjustWidth) {
                activityWidth = (int) ((activityHeight / desiredAspectRatio) + 0.5f);
                activityWidth = (int) ((activityHeight / aspectRatioToApply) + 0.5f);
            } else {
            } else {
                activityHeight = (int) ((activityWidth / desiredAspectRatio) + 0.5f);
                activityHeight = (int) ((activityWidth / aspectRatioToApply) + 0.5f);
            }
            }
        }
        }