From 0eb6ecff7693dfae1fe60f476ba5cb04ecad6c6b Mon Sep 17 00:00:00 2001 From: Hongwei Wang Date: Thu, 25 Jun 2020 22:27:07 -0700 Subject: [PATCH] Ignore resize request when exiting PiP When PipTaskOrganizer#removePip is called, the animator in PipMotionHelper may still be running and issues a conflict window container transaction at its end. This causes the activity resuming to a weird bounds after drag to dismiss and re-open, in split-screen mode. Fixes this by - In PipMotionHelper, if it's a dismiss action, do not issue the window container transaction - In PipTaskOrganizer, if we know we're exiting, do not accept any resize request Video: http://rcll/aaaaaabFQoRHlzixHdtY/fCOxvnTXu9RtFYERIdskNf Bug: 159943928 Test: see video Change-Id: Ia9dd02f9707f9da74166bee24a015c2bb4e223c2 --- .../systemui/pip/PipTaskOrganizer.java | 20 ++++++++++++++----- .../systemui/pip/phone/PipMotionHelper.java | 7 +++++-- 2 files changed, 20 insertions(+), 7 deletions(-) diff --git a/packages/SystemUI/src/com/android/systemui/pip/PipTaskOrganizer.java b/packages/SystemUI/src/com/android/systemui/pip/PipTaskOrganizer.java index a7dd53e48a817..f7bb3fe291724 100644 --- a/packages/SystemUI/src/com/android/systemui/pip/PipTaskOrganizer.java +++ b/packages/SystemUI/src/com/android/systemui/pip/PipTaskOrganizer.java @@ -612,7 +612,9 @@ public class PipTaskOrganizer extends TaskOrganizer implements @PipAnimationController.TransitionDirection int direction, int durationMs, Consumer updateBoundsCallback) { if (!mInPip) { - // can be initiated in other component, ignore if we are no longer in PIP + // TODO: tend to use shouldBlockResizeRequest here as well but need to consider + // the fact that when in exitPip, scheduleAnimateResizePip is executed in the window + // container transaction callback and we want to set the mExitingPip immediately. return; } @@ -668,8 +670,7 @@ public class PipTaskOrganizer extends TaskOrganizer implements private void scheduleFinishResizePip(Rect destinationBounds, @PipAnimationController.TransitionDirection int direction, Consumer updateBoundsCallback) { - if (!mInPip) { - // can be initiated in other component, ignore if we are no longer in PIP + if (shouldBlockResizeRequest()) { return; } @@ -697,8 +698,7 @@ public class PipTaskOrganizer extends TaskOrganizer implements */ public void scheduleOffsetPip(Rect originalBounds, int offset, int duration, Consumer updateBoundsCallback) { - if (!mInPip) { - // can be initiated in other component, ignore if we are no longer in PIP + if (shouldBlockResizeRequest()) { return; } if (mShouldDeferEnteringPip) { @@ -869,6 +869,16 @@ public class PipTaskOrganizer extends TaskOrganizer implements : params.getAspectRatio(); } + /** + * Resize request can be initiated in other component, ignore if we are no longer in PIP + * or we're exiting from it. + * + * @return {@code true} if the resize request should be blocked/ignored. + */ + private boolean shouldBlockResizeRequest() { + return !mInPip || mExitingPip; + } + /** * Sync with {@link #mSplitDivider} on destination bounds if PiP is going to split screen. * diff --git a/packages/SystemUI/src/com/android/systemui/pip/phone/PipMotionHelper.java b/packages/SystemUI/src/com/android/systemui/pip/phone/PipMotionHelper.java index e60123e863a40..8a2e4ae118787 100644 --- a/packages/SystemUI/src/com/android/systemui/pip/phone/PipMotionHelper.java +++ b/packages/SystemUI/src/com/android/systemui/pip/phone/PipMotionHelper.java @@ -533,8 +533,11 @@ public class PipMotionHelper implements PipAppOpsListener.Callback, && !mSpringingToTouch && !mMagnetizedPip.getObjectStuckToTarget()) { mBounds.set(mTemporaryBounds); - mPipTaskOrganizer.scheduleFinishResizePip(mBounds); - + if (!mDismissalPending) { + // do not schedule resize if PiP is dismissing, which may cause app re-open to + // mBounds instead of it's normal bounds. + mPipTaskOrganizer.scheduleFinishResizePip(mBounds); + } mTemporaryBounds.setEmpty(); }