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

Commit c64214f9 authored by Graciela Putri's avatar Graciela Putri Committed by Android (Google) Code Review
Browse files

Merge "Use original aspect ratio for unresizeable" into main

parents ce3bdcbb ffd0da08
Loading
Loading
Loading
Loading
+15 −5
Original line number Diff line number Diff line
@@ -73,6 +73,12 @@ public class AppCompatTaskInfo implements Parcelable {
    @Nullable
    public Rect topActivityLetterboxBounds;

    /**
     * Contains the aspect ratio of the top non-resizable activity or
     * {@link TaskInfo#PROPERTY_VALUE_UNSET} otherwise.
     */
    public float topNonResizableActivityAspectRatio = PROPERTY_VALUE_UNSET;

    /**
     * Stores camera-related app compat information about a particular Task.
     */
@@ -400,12 +406,13 @@ public class AppCompatTaskInfo implements Parcelable {
        return (mTopActivityFlags & FLAGS_ORGANIZER_INTERESTED)
                    == (that.mTopActivityFlags & FLAGS_ORGANIZER_INTERESTED)
                && topActivityLetterboxVerticalPosition == that.topActivityLetterboxVerticalPosition
                && topActivityLetterboxWidth == that.topActivityLetterboxWidth
                && topActivityLetterboxHeight == that.topActivityLetterboxHeight
                && topActivityAppBounds.equals(that.topActivityAppBounds)
                && topActivityLetterboxHorizontalPosition
                    == that.topActivityLetterboxHorizontalPosition
                && cameraCompatTaskInfo.equalsForTaskOrganizer(that.cameraCompatTaskInfo);
                && topActivityLetterboxWidth == that.topActivityLetterboxWidth
                && topActivityLetterboxHeight == that.topActivityLetterboxHeight
                && Objects.equals(topActivityAppBounds, that.topActivityAppBounds)
                && cameraCompatTaskInfo.equalsForTaskOrganizer(that.cameraCompatTaskInfo)
                && topNonResizableActivityAspectRatio == that.topNonResizableActivityAspectRatio;
    }

    /**
@@ -422,7 +429,7 @@ public class AppCompatTaskInfo implements Parcelable {
                    == that.topActivityLetterboxHorizontalPosition
                && topActivityLetterboxWidth == that.topActivityLetterboxWidth
                && topActivityLetterboxHeight == that.topActivityLetterboxHeight
                && topActivityAppBounds.equals(that.topActivityAppBounds)
                && Objects.equals(topActivityAppBounds, that.topActivityAppBounds)
                && cameraCompatTaskInfo.equalsForCompatUi(that.cameraCompatTaskInfo);
    }

@@ -438,6 +445,7 @@ public class AppCompatTaskInfo implements Parcelable {
        topActivityAppBounds.set(Objects.requireNonNull(source.readTypedObject(Rect.CREATOR)));
        topActivityLetterboxBounds = source.readTypedObject(Rect.CREATOR);
        cameraCompatTaskInfo = source.readTypedObject(CameraCompatTaskInfo.CREATOR);
        topNonResizableActivityAspectRatio = source.readFloat();
    }

    /**
@@ -453,6 +461,7 @@ public class AppCompatTaskInfo implements Parcelable {
        dest.writeTypedObject(topActivityAppBounds, flags);
        dest.writeTypedObject(topActivityLetterboxBounds, flags);
        dest.writeTypedObject(cameraCompatTaskInfo, flags);
        dest.writeFloat(topNonResizableActivityAspectRatio);
    }

    @Override
@@ -475,6 +484,7 @@ public class AppCompatTaskInfo implements Parcelable {
                + " hasMinAspectRatioOverride=" + hasMinAspectRatioOverride()
                + " topActivityLetterboxBounds=" + topActivityLetterboxBounds
                + " cameraCompatTaskInfo=" + cameraCompatTaskInfo.toString()
                + " topNonResizableActivityAspectRatio=" + topNonResizableActivityAspectRatio
                + "}";
    }

+3 −0
Original line number Diff line number Diff line
@@ -232,6 +232,9 @@ fun maximizeSizeGivenAspectRatio(

/** Calculates the aspect ratio of an activity from its fullscreen bounds. */
fun calculateAspectRatio(taskInfo: RunningTaskInfo): Float {
    if (taskInfo.appCompatTaskInfo.topNonResizableActivityAspectRatio > 0) {
        return taskInfo.appCompatTaskInfo.topNonResizableActivityAspectRatio
    }
    val appBounds =
        if (taskInfo.appCompatTaskInfo.topActivityAppBounds.isEmpty) {
            taskInfo.configuration.windowConfiguration.appBounds
+30 −0
Original line number Diff line number Diff line
@@ -1684,6 +1684,36 @@ class DesktopTasksControllerTest(flags: FlagsParameterization) : ShellTestCase()
        assertThat(findBoundsChange(wct, task)).isEqualTo(UNRESIZABLE_LANDSCAPE_BOUNDS)
    }

    @Test
    fun addMoveToDeskTaskChanges_inSizeCompatMode_originalAspectRatioMaintained() {
        setUpLandscapeDisplay()
        val task =
            setUpFullscreenTask(
                isResizable = false,
                screenOrientation = SCREEN_ORIENTATION_PORTRAIT,
                deviceOrientation = ORIENTATION_PORTRAIT,
            )
        // Simulate floating size compat mode bounds (same aspect ratio as display without insets).
        task.appCompatTaskInfo.topActivityAppBounds.set(
            0,
            0,
            DISPLAY_DIMENSION_LONG / 2,
            DISPLAY_DIMENSION_SHORT / 2,
        )
        val originalAspectRatio = 1.5f
        task.appCompatTaskInfo.topNonResizableActivityAspectRatio = originalAspectRatio

        val wct = WindowContainerTransaction()
        controller.addMoveToDeskTaskChanges(wct, task, deskId = 0)

        val finalBounds = findBoundsChange(wct, task)
        assertNotNull(finalBounds, "finalBounds should be resolved")
        val finalAspectRatio =
            maxOf(finalBounds.height(), finalBounds.width()) /
                minOf(finalBounds.height(), finalBounds.width()).toFloat()
        assertThat(finalAspectRatio).isWithin(FLOAT_TOLERANCE).of(originalAspectRatio)
    }

    @Test
    @EnableFlags(Flags.FLAG_ENABLE_PROJECTED_DISPLAY_DESKTOP_MODE)
    @DisableFlags(Flags.FLAG_ENABLE_MULTIPLE_DESKTOPS_BACKEND)
+9 −0
Original line number Diff line number Diff line
@@ -22,6 +22,8 @@ import static android.content.res.Configuration.ORIENTATION_LANDSCAPE;
import static android.view.Surface.ROTATION_270;
import static android.view.Surface.ROTATION_90;

import static com.android.server.wm.AppCompatUtils.computeAspectRatio;

import android.annotation.NonNull;
import android.annotation.Nullable;
import android.content.res.Configuration;
@@ -49,6 +51,8 @@ class AppCompatDisplayInsets {
     * the unresizable activity is first shown.
     */
    final boolean mIsInFixedOrientationOrAspectRatioLetterbox;
    /** The original aspect ratio of the activity. */
    final float mAspectRatio;
    /**
     * The nonDecorInsets for each rotation. Includes the navigation bar and cutout insets. It
     * is used to compute the appBounds.
@@ -79,6 +83,7 @@ class AppCompatDisplayInsets {
                mStableInsets[rotation] = emptyRect;
            }
            mIsInFixedOrientationOrAspectRatioLetterbox = false;
            mAspectRatio = computeAspectRatio(containerBounds);
            return;
        }

@@ -139,6 +144,10 @@ class AppCompatDisplayInsets {
            updateInsetsForBounds(unfilledContainerBounds, dw, dh, mNonDecorInsets[rotation]);
            updateInsetsForBounds(unfilledContainerBounds, dw, dh, mStableInsets[rotation]);
        }

        final Rect appBounds = new Rect(filledContainerBounds);
        appBounds.inset(mNonDecorInsets[filledContainerRotation]);
        mAspectRatio = computeAspectRatio(appBounds);
    }

    /**
+5 −0
Original line number Diff line number Diff line
@@ -191,6 +191,10 @@ final class AppCompatUtils {
        appCompatTaskInfo.setIsFromLetterboxDoubleTap(reachabilityOverrides.isFromDoubleTap());

        appCompatTaskInfo.topActivityAppBounds.set(getAppBounds(top));
        appCompatTaskInfo.topNonResizableActivityAspectRatio =
                top.getAppCompatDisplayInsets() != null
                        ? top.getAppCompatDisplayInsets().mAspectRatio
                        : TaskInfo.PROPERTY_VALUE_UNSET;
        final boolean isTopActivityLetterboxed = top.areBoundsLetterboxed();
        appCompatTaskInfo.setTopActivityLetterboxed(isTopActivityLetterboxed);
        if (isTopActivityLetterboxed) {
@@ -322,6 +326,7 @@ final class AppCompatUtils {
        info.topActivityLetterboxBounds = null;
        info.cameraCompatTaskInfo.freeformCameraCompatMode =
                CameraCompatTaskInfo.CAMERA_COMPAT_FREEFORM_UNSPECIFIED;
        info.topNonResizableActivityAspectRatio = TaskInfo.PROPERTY_VALUE_UNSET;
        info.clearTopActivityFlags();
    }
}
Loading