Loading libs/WindowManager/Shell/src/com/android/wm/shell/common/pip/PipBoundsAlgorithm.java +8 −4 Original line number Diff line number Diff line Loading @@ -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); Loading libs/WindowManager/Shell/src/com/android/wm/shell/common/pip/PipBoundsState.java +8 −9 Original line number Diff line number Diff line Loading @@ -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. */ Loading Loading @@ -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() { Loading @@ -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); } } Loading libs/WindowManager/Shell/src/com/android/wm/shell/pip/phone/PipController.java +1 −17 Original line number Diff line number Diff line Loading @@ -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; Loading Loading @@ -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 Loading libs/WindowManager/Shell/tests/unittest/src/com/android/wm/shell/pip/PipBoundsAlgorithmTest.java +7 −5 Original line number Diff line number Diff line Loading @@ -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()); Loading @@ -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(); Loading libs/WindowManager/Shell/tests/unittest/src/com/android/wm/shell/pip/PipBoundsStateTest.java +4 −8 Original line number Diff line number Diff line Loading @@ -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()); Loading @@ -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 Loading
libs/WindowManager/Shell/src/com/android/wm/shell/common/pip/PipBoundsAlgorithm.java +8 −4 Original line number Diff line number Diff line Loading @@ -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); Loading
libs/WindowManager/Shell/src/com/android/wm/shell/common/pip/PipBoundsState.java +8 −9 Original line number Diff line number Diff line Loading @@ -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. */ Loading Loading @@ -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() { Loading @@ -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); } } Loading
libs/WindowManager/Shell/src/com/android/wm/shell/pip/phone/PipController.java +1 −17 Original line number Diff line number Diff line Loading @@ -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; Loading Loading @@ -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 Loading
libs/WindowManager/Shell/tests/unittest/src/com/android/wm/shell/pip/PipBoundsAlgorithmTest.java +7 −5 Original line number Diff line number Diff line Loading @@ -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()); Loading @@ -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(); Loading
libs/WindowManager/Shell/tests/unittest/src/com/android/wm/shell/pip/PipBoundsStateTest.java +4 −8 Original line number Diff line number Diff line Loading @@ -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()); Loading @@ -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