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

Commit ffd0da08 authored by Graciela Wissen Putri's avatar Graciela Wissen Putri
Browse files

Use original aspect ratio for unresizeable

Floating activity in size compat mode has bounds that are including
parent insets as they do not intersect. Aspect ratio in floating size
compat mode will not be the same as original activity aspect ratio.
Cache original aspect ratio in AppCompatDisplayInsets and use for
resolving intiial bounds if available.

Flag: com.android.window.flags.preserve_recents_task_configuration_on_relaunch
Fix: 402779827
Test: atest DesktopModeLaunchParamsModifierTests
      atest DesktopTasksControllerTest
Change-Id: Iff7e5b7afadb897b26b6afb3a657ea06931513f8
parent 8fee1444
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.
     */
@@ -382,12 +388,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;
    }

    /**
@@ -404,7 +411,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);
    }

@@ -420,6 +427,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();
    }

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

    @Override
@@ -457,6 +466,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
@@ -1657,6 +1657,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
@@ -184,6 +184,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) {
@@ -315,6 +319,7 @@ final class AppCompatUtils {
        info.topActivityLetterboxBounds = null;
        info.cameraCompatTaskInfo.freeformCameraCompatMode =
                CameraCompatTaskInfo.CAMERA_COMPAT_FREEFORM_UNSPECIFIED;
        info.topNonResizableActivityAspectRatio = TaskInfo.PROPERTY_VALUE_UNSET;
        info.clearTopActivityFlags();
    }
}
Loading