diff --git a/libs/WindowManager/Shell/src/com/android/wm/shell/pip/phone/PipController.java b/libs/WindowManager/Shell/src/com/android/wm/shell/pip/phone/PipController.java index b0bb14b49db6c..f8e1435755830 100644 --- a/libs/WindowManager/Shell/src/com/android/wm/shell/pip/phone/PipController.java +++ b/libs/WindowManager/Shell/src/com/android/wm/shell/pip/phone/PipController.java @@ -1060,13 +1060,22 @@ 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()) { - final Rect reentryBounds = mTouchHandler.getUserResizeBounds(); - final Size reentrySize = new Size(reentryBounds.width(), reentryBounds.height()); - mPipBoundsState.saveReentryState(reentrySize, snapFraction); - } else { + + 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 diff --git a/libs/WindowManager/Shell/tests/unittest/src/com/android/wm/shell/pip/phone/PipControllerTest.java b/libs/WindowManager/Shell/tests/unittest/src/com/android/wm/shell/pip/phone/PipControllerTest.java index 6995d10dd78d5..04f2c99783da7 100644 --- a/libs/WindowManager/Shell/tests/unittest/src/com/android/wm/shell/pip/phone/PipControllerTest.java +++ b/libs/WindowManager/Shell/tests/unittest/src/com/android/wm/shell/pip/phone/PipControllerTest.java @@ -268,7 +268,7 @@ public class PipControllerTest extends ShellTestCase { } @Test - public void saveReentryState_userHasResized_savesSize() { + public void saveReentryState_nonEmptyUserResizeBounds_savesSize() { final Rect bounds = new Rect(0, 0, 10, 10); final Rect resizedBounds = new Rect(0, 0, 30, 30); when(mMockPipBoundsAlgorithm.getSnapFraction(bounds)).thenReturn(1.0f); @@ -280,6 +280,19 @@ public class PipControllerTest extends ShellTestCase { verify(mMockPipBoundsState).saveReentryState(new Size(30, 30), 1.0f); } + @Test + public void saveReentryState_emptyUserResizeBounds_savesSize() { + final Rect bounds = new Rect(0, 0, 10, 10); + final Rect resizedBounds = new Rect(0, 0, 0, 0); + when(mMockPipBoundsAlgorithm.getSnapFraction(bounds)).thenReturn(1.0f); + when(mMockPipTouchHandler.getUserResizeBounds()).thenReturn(resizedBounds); + when(mMockPipBoundsState.hasUserResizedPip()).thenReturn(true); + + mPipController.saveReentryState(bounds); + + verify(mMockPipBoundsState).saveReentryState(new Size(10, 10), 1.0f); + } + @Test public void onDisplayConfigurationChanged_inPip_movePip() { final int displayId = 1;