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

Commit 1e3222e8 authored by Mateusz Cicheński's avatar Mateusz Cicheński
Browse files

Make PiP reentry state to use scale instead of size

Beforehand the state was using fixed size, which could be below minimum
size for a given screen size, e.g. after you fold/unfold the device.

This change makes it so that the bounds scale is used instead of size,
which makes the PiP size always align with PiP Size Spec after reentry.

Bug: 316249837
Test: before http://recall/-/ekEuGtt9d9HWqkUtAzpHx8/fiQwpwJW7bnFUeuop8olCB
Test: after http://recall/-/ekEuGtt9d9HWqkUtAzpHx8/gVg5R7FmwHU5xrxplIHsGH
Flag: none

Change-Id: I9962a40ccf5e96ab544f580740f5d2870ea8121d
parent 1d895a47
Loading
Loading
Loading
Loading
+8 −4
Original line number Diff line number Diff line
@@ -125,11 +125,15 @@ public class PipBoundsAlgorithm {
    public Rect getEntryDestinationBoundsIgnoringKeepClearAreas() {
        final PipBoundsState.PipReentryState reentryState = mPipBoundsState.getReentryState();

        final Rect destinationBounds = reentryState != null
                ? getDefaultBounds(reentryState.getSnapFraction(), reentryState.getSize())
                : getDefaultBounds();
        final Rect destinationBounds = getDefaultBounds();
        if (reentryState != null) {
            final Size scaledBounds = new Size(
                    Math.round(mPipBoundsState.getMaxSize().x * reentryState.getBoundsScale()),
                    Math.round(mPipBoundsState.getMaxSize().y * reentryState.getBoundsScale()));
            destinationBounds.set(getDefaultBounds(reentryState.getSnapFraction(), scaledBounds));
        }

        final boolean useCurrentSize = reentryState != null && reentryState.getSize() != null;
        final boolean useCurrentSize = reentryState != null;
        Rect aspectRatioBounds = transformBoundsToAspectRatioIfValid(destinationBounds,
                mPipBoundsState.getAspectRatio(), false /* useCurrentMinEdgeSize */,
                useCurrentSize);
+8 −9
Original line number Diff line number Diff line
@@ -298,8 +298,8 @@ public class PipBoundsState {
    }

    /** Save the reentry state to restore to when re-entering PIP mode. */
    public void saveReentryState(Size size, float fraction) {
        mPipReentryState = new PipReentryState(size, fraction);
    public void saveReentryState(float fraction) {
        mPipReentryState = new PipReentryState(mBoundsScale, fraction);
    }

    /** Returns the saved reentry state. */
@@ -601,17 +601,16 @@ public class PipBoundsState {
    public static final class PipReentryState {
        private static final String TAG = PipReentryState.class.getSimpleName();

        private final @Nullable Size mSize;
        private final float mSnapFraction;
        private final float mBoundsScale;

        PipReentryState(@Nullable Size size, float snapFraction) {
            mSize = size;
        PipReentryState(float boundsScale, float snapFraction) {
            mBoundsScale = boundsScale;
            mSnapFraction = snapFraction;
        }

        @Nullable
        public Size getSize() {
            return mSize;
        public float getBoundsScale() {
            return mBoundsScale;
        }

        public float getSnapFraction() {
@@ -621,7 +620,7 @@ public class PipBoundsState {
        void dump(PrintWriter pw, String prefix) {
            final String innerPrefix = prefix + "  ";
            pw.println(prefix + TAG);
            pw.println(innerPrefix + "mSize=" + mSize);
            pw.println(innerPrefix + "mBoundsScale=" + mBoundsScale);
            pw.println(innerPrefix + "mSnapFraction=" + mSnapFraction);
        }
    }
+1 −17
Original line number Diff line number Diff line
@@ -48,7 +48,6 @@ import android.graphics.Rect;
import android.os.RemoteException;
import android.os.SystemProperties;
import android.util.Pair;
import android.util.Size;
import android.view.DisplayInfo;
import android.view.InsetsState;
import android.view.SurfaceControl;
@@ -1042,22 +1041,7 @@ public class PipController implements PipTransitionController.PipTransitionCallb
    /** Save the state to restore to on re-entry. */
    public void saveReentryState(Rect pipBounds) {
        float snapFraction = mPipBoundsAlgorithm.getSnapFraction(pipBounds);

        if (!mPipBoundsState.hasUserResizedPip()) {
            mPipBoundsState.saveReentryState(null /* bounds */, snapFraction);
            return;
        }

        Size reentrySize = new Size(pipBounds.width(), pipBounds.height());

        // TODO: b/279937014 Investigate why userResizeBounds are empty with shell transitions on
        // fallback to using the userResizeBounds if userResizeBounds are not empty
        if (!mTouchHandler.getUserResizeBounds().isEmpty()) {
            Rect userResizeBounds = mTouchHandler.getUserResizeBounds();
            reentrySize = new Size(userResizeBounds.width(), userResizeBounds.height());
        }

        mPipBoundsState.saveReentryState(reentrySize, snapFraction);
        mPipBoundsState.saveReentryState(snapFraction);
    }

    @Override
+7 −5
Original line number Diff line number Diff line
@@ -354,14 +354,17 @@ public class PipBoundsAlgorithmTest extends ShellTestCase {
    }

    @Test
    public void getEntryDestinationBounds_reentryStateExists_restoreLastSize() {
    public void getEntryDestinationBounds_reentryStateExists_restoreProportionalSize() {
        mPipBoundsState.setAspectRatio(DEFAULT_ASPECT_RATIO);
        final Size maxSize = mSizeSpecSource.getMaxSize(DEFAULT_ASPECT_RATIO);
        mPipBoundsState.setMaxSize(maxSize.getWidth(), maxSize.getHeight());
        final Rect reentryBounds = mPipBoundsAlgorithm.getEntryDestinationBounds();
        reentryBounds.scale(1.25f);
        mPipBoundsState.setBounds(reentryBounds); // this updates the bounds scale used in reentry

        final float reentrySnapFraction = mPipBoundsAlgorithm.getSnapFraction(reentryBounds);

        mPipBoundsState.saveReentryState(
                new Size(reentryBounds.width(), reentryBounds.height()), reentrySnapFraction);
        mPipBoundsState.saveReentryState(reentrySnapFraction);
        final Rect destinationBounds = mPipBoundsAlgorithm.getEntryDestinationBounds();

        assertEquals(reentryBounds.width(), destinationBounds.width());
@@ -375,8 +378,7 @@ public class PipBoundsAlgorithmTest extends ShellTestCase {
        reentryBounds.offset(0, -100);
        final float reentrySnapFraction = mPipBoundsAlgorithm.getSnapFraction(reentryBounds);

        mPipBoundsState.saveReentryState(
                new Size(reentryBounds.width(), reentryBounds.height()), reentrySnapFraction);
        mPipBoundsState.saveReentryState(reentrySnapFraction);

        final Rect destinationBounds = mPipBoundsAlgorithm.getEntryDestinationBounds();

+4 −8
Original line number Diff line number Diff line
@@ -114,22 +114,19 @@ public class PipBoundsStateTest extends ShellTestCase {

    @Test
    public void testSetReentryState() {
        final Size size = new Size(100, 100);
        final float snapFraction = 0.5f;

        mPipBoundsState.saveReentryState(size, snapFraction);
        mPipBoundsState.saveReentryState(snapFraction);

        final PipBoundsState.PipReentryState state = mPipBoundsState.getReentryState();
        assertEquals(size, state.getSize());
        assertEquals(snapFraction, state.getSnapFraction(), 0.01);
    }

    @Test
    public void testClearReentryState() {
        final Size size = new Size(100, 100);
        final float snapFraction = 0.5f;

        mPipBoundsState.saveReentryState(size, snapFraction);
        mPipBoundsState.saveReentryState(snapFraction);
        mPipBoundsState.clearReentryState();

        assertNull(mPipBoundsState.getReentryState());
@@ -138,20 +135,19 @@ public class PipBoundsStateTest extends ShellTestCase {
    @Test
    public void testSetLastPipComponentName_notChanged_doesNotClearReentryState() {
        mPipBoundsState.setLastPipComponentName(mTestComponentName1);
        mPipBoundsState.saveReentryState(DEFAULT_SIZE, DEFAULT_SNAP_FRACTION);
        mPipBoundsState.saveReentryState(DEFAULT_SNAP_FRACTION);

        mPipBoundsState.setLastPipComponentName(mTestComponentName1);

        final PipBoundsState.PipReentryState state = mPipBoundsState.getReentryState();
        assertNotNull(state);
        assertEquals(DEFAULT_SIZE, state.getSize());
        assertEquals(DEFAULT_SNAP_FRACTION, state.getSnapFraction(), 0.01);
    }

    @Test
    public void testSetLastPipComponentName_changed_clearReentryState() {
        mPipBoundsState.setLastPipComponentName(mTestComponentName1);
        mPipBoundsState.saveReentryState(DEFAULT_SIZE, DEFAULT_SNAP_FRACTION);
        mPipBoundsState.saveReentryState(DEFAULT_SNAP_FRACTION);

        mPipBoundsState.setLastPipComponentName(mTestComponentName2);

Loading