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

Commit 2e1dcabe authored by Mateusz Cicheński's avatar Mateusz Cicheński Committed by Android (Google) Code Review
Browse files

Merge "Make PiP reentry state to use scale instead of size" into main

parents f0ed0127 1e3222e8
Loading
Loading
Loading
Loading
+8 −4
Original line number Original line Diff line number Diff line
@@ -125,11 +125,15 @@ public class PipBoundsAlgorithm {
    public Rect getEntryDestinationBoundsIgnoringKeepClearAreas() {
    public Rect getEntryDestinationBoundsIgnoringKeepClearAreas() {
        final PipBoundsState.PipReentryState reentryState = mPipBoundsState.getReentryState();
        final PipBoundsState.PipReentryState reentryState = mPipBoundsState.getReentryState();


        final Rect destinationBounds = reentryState != null
        final Rect destinationBounds = getDefaultBounds();
                ? getDefaultBounds(reentryState.getSnapFraction(), reentryState.getSize())
        if (reentryState != null) {
                : getDefaultBounds();
            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,
        Rect aspectRatioBounds = transformBoundsToAspectRatioIfValid(destinationBounds,
                mPipBoundsState.getAspectRatio(), false /* useCurrentMinEdgeSize */,
                mPipBoundsState.getAspectRatio(), false /* useCurrentMinEdgeSize */,
                useCurrentSize);
                useCurrentSize);
+8 −9
Original line number Original line Diff line number Diff line
@@ -298,8 +298,8 @@ public class PipBoundsState {
    }
    }


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


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


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


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


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


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

        mPipBoundsState.saveReentryState(snapFraction);
        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);
    }
    }


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


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

        final float reentrySnapFraction = mPipBoundsAlgorithm.getSnapFraction(reentryBounds);
        final float reentrySnapFraction = mPipBoundsAlgorithm.getSnapFraction(reentryBounds);


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


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


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


        final Rect destinationBounds = mPipBoundsAlgorithm.getEntryDestinationBounds();
        final Rect destinationBounds = mPipBoundsAlgorithm.getEntryDestinationBounds();


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


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


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


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


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


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


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


        mPipBoundsState.setLastPipComponentName(mTestComponentName1);
        mPipBoundsState.setLastPipComponentName(mTestComponentName1);


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


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


        mPipBoundsState.setLastPipComponentName(mTestComponentName2);
        mPipBoundsState.setLastPipComponentName(mTestComponentName2);


Loading