From 30d86a6b5ca58676ec5698156876ff62dc01d1e6 Mon Sep 17 00:00:00 2001 From: "jorgegil@google.com" Date: Mon, 15 Mar 2021 15:41:16 -0700 Subject: [PATCH] Update the PIP exclusion bounds when PIP is offset by shelf/ime Bug: 182509392 Test: enter PIP, stash, open chrome to trigger offset - verify back gesture works correctly Change-Id: If80ec31035d7da9718267133e10493bd2a363495 --- .../android/wm/shell/pip/PipBoundsState.java | 17 ++++++++++++ .../wm/shell/pip/PipTaskOrganizer.java | 2 ++ .../wm/shell/pip/phone/PipController.java | 11 +------- .../wm/shell/pip/phone/PipMotionHelper.java | 4 +-- .../wm/shell/pip/phone/PipTouchHandler.java | 26 ------------------- 5 files changed, 21 insertions(+), 39 deletions(-) diff --git a/libs/WindowManager/Shell/src/com/android/wm/shell/pip/PipBoundsState.java b/libs/WindowManager/Shell/src/com/android/wm/shell/pip/PipBoundsState.java index cb39b4e63655e..e3594d0cd3673 100644 --- a/libs/WindowManager/Shell/src/com/android/wm/shell/pip/PipBoundsState.java +++ b/libs/WindowManager/Shell/src/com/android/wm/shell/pip/PipBoundsState.java @@ -35,6 +35,7 @@ import java.io.PrintWriter; import java.lang.annotation.Retention; import java.lang.annotation.RetentionPolicy; import java.util.Objects; +import java.util.function.Consumer; /** * Singleton source of truth for the current state of PIP bounds. @@ -84,6 +85,7 @@ public final class PipBoundsState { private @Nullable Runnable mOnMinimalSizeChangeCallback; private @Nullable TriConsumer mOnShelfVisibilityChangeCallback; + private @Nullable Consumer mOnPipExclusionBoundsChangeCallback; public PipBoundsState(@NonNull Context context) { mContext = context; @@ -102,6 +104,9 @@ public final class PipBoundsState { /** Set the current PIP bounds. */ public void setBounds(@NonNull Rect bounds) { mBounds.set(bounds); + if (mOnPipExclusionBoundsChangeCallback != null) { + mOnPipExclusionBoundsChangeCallback.accept(bounds); + } } /** Get the current PIP bounds. */ @@ -386,6 +391,18 @@ public final class PipBoundsState { mOnShelfVisibilityChangeCallback = onShelfVisibilityChangeCallback; } + /** + * Set a callback to watch out for PiP bounds. This is mostly used by SystemUI's + * Back-gesture handler, to avoid conflicting with PiP when it's stashed. + */ + public void setPipExclusionBoundsChangeCallback( + @Nullable Consumer onPipExclusionBoundsChangeCallback) { + mOnPipExclusionBoundsChangeCallback = onPipExclusionBoundsChangeCallback; + if (mOnPipExclusionBoundsChangeCallback != null) { + mOnPipExclusionBoundsChangeCallback.accept(getBounds()); + } + } + /** Source of truth for the current bounds of PIP that may be in motion. */ public static class MotionBoundsState { /** The bounds used when PIP is in motion (e.g. during a drag or animation) */ diff --git a/libs/WindowManager/Shell/src/com/android/wm/shell/pip/PipTaskOrganizer.java b/libs/WindowManager/Shell/src/com/android/wm/shell/pip/PipTaskOrganizer.java index 36dc4e409f984..fa31a0a4e5162 100644 --- a/libs/WindowManager/Shell/src/com/android/wm/shell/pip/PipTaskOrganizer.java +++ b/libs/WindowManager/Shell/src/com/android/wm/shell/pip/PipTaskOrganizer.java @@ -566,6 +566,8 @@ public class PipTaskOrganizer implements ShellTaskOrganizer.TaskListener, mInSwipePipToHomeTransition = false; mPictureInPictureParams = null; mState = State.UNDEFINED; + // Re-set the PIP bounds to none. + mPipBoundsState.setBounds(new Rect()); mPipUiEventLoggerLogger.setTaskInfo(null); mPipMenuController.detach(); 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 9a584c67f97c0..1f5c136e950d5 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 @@ -494,15 +494,6 @@ public class PipController implements PipTransitionController.PipTransitionCallb mPipTaskOrganizer.stopSwipePipToHome(componentName, destinationBounds); } - /** - * Set a listener to watch out for PiP bounds. This is mostly used by SystemUI's - * Back-gesture handler, to avoid conflicting with PiP when it's stashed. - */ - private void setPipExclusionBoundsChangeListener( - Consumer pipExclusionBoundsChangeListener) { - mTouchHandler.setPipExclusionBoundsChangeListener(pipExclusionBoundsChangeListener); - } - @Override public void onPipTransitionStarted(int direction, Rect pipBounds) { if (isOutPipDirection(direction)) { @@ -712,7 +703,7 @@ public class PipController implements PipTransitionController.PipTransitionCallb @Override public void setPipExclusionBoundsChangeListener(Consumer listener) { mMainExecutor.execute(() -> { - PipController.this.setPipExclusionBoundsChangeListener(listener); + mPipBoundsState.setPipExclusionBoundsChangeCallback(listener); }); } diff --git a/libs/WindowManager/Shell/src/com/android/wm/shell/pip/phone/PipMotionHelper.java b/libs/WindowManager/Shell/src/com/android/wm/shell/pip/phone/PipMotionHelper.java index 81a7ae1be4829..402846f79ab73 100644 --- a/libs/WindowManager/Shell/src/com/android/wm/shell/pip/phone/PipMotionHelper.java +++ b/libs/WindowManager/Shell/src/com/android/wm/shell/pip/phone/PipMotionHelper.java @@ -29,7 +29,6 @@ import android.os.Looper; import android.util.Log; import android.view.Choreographer; -import androidx.annotation.VisibleForTesting; import androidx.dynamicanimation.animation.AnimationHandler; import androidx.dynamicanimation.animation.AnimationHandler.FrameCallbackScheduler; import androidx.dynamicanimation.animation.SpringForce; @@ -489,8 +488,7 @@ public class PipMotionHelper implements PipAppOpsListener.Callback, /** * Animates the PiP to offset it from the IME or shelf. */ - @VisibleForTesting - public void animateToOffset(Rect originalBounds, int offset) { + void animateToOffset(Rect originalBounds, int offset) { if (DEBUG) { Log.d(TAG, "animateToOffset: originalBounds=" + originalBounds + " offset=" + offset + " callers=\n" + Debug.getCallers(5, " ")); diff --git a/libs/WindowManager/Shell/src/com/android/wm/shell/pip/phone/PipTouchHandler.java b/libs/WindowManager/Shell/src/com/android/wm/shell/pip/phone/PipTouchHandler.java index 44e262492b97b..b0a7319dece22 100644 --- a/libs/WindowManager/Shell/src/com/android/wm/shell/pip/phone/PipTouchHandler.java +++ b/libs/WindowManager/Shell/src/com/android/wm/shell/pip/phone/PipTouchHandler.java @@ -57,8 +57,6 @@ import com.android.wm.shell.pip.PipTransitionController; import com.android.wm.shell.pip.PipUiEventLogger; import java.io.PrintWriter; -import java.lang.ref.WeakReference; -import java.util.function.Consumer; /** * Manages all the touch handling for PIP on the Phone, including moving, dismissing and expanding @@ -73,7 +71,6 @@ public class PipTouchHandler { // Allow PIP to resize to a slightly bigger state upon touch private boolean mEnableResize; private final Context mContext; - private final PipTaskOrganizer mPipTaskOrganizer; private final PipBoundsAlgorithm mPipBoundsAlgorithm; private final @NonNull PipBoundsState mPipBoundsState; private final PipUiEventLogger mPipUiEventLogger; @@ -81,7 +78,6 @@ public class PipTouchHandler { private final ShellExecutor mMainExecutor; private PipResizeGestureHandler mPipResizeGestureHandler; - private WeakReference> mPipExclusionBoundsChangeListener; private final PhonePipMenuController mMenuController; private final AccessibilityManager mAccessibilityManager; @@ -170,7 +166,6 @@ public class PipTouchHandler { mContext = context; mMainExecutor = mainExecutor; mAccessibilityManager = context.getSystemService(AccessibilityManager.class); - mPipTaskOrganizer = pipTaskOrganizer; mPipBoundsAlgorithm = pipBoundsAlgorithm; mPipBoundsState = pipBoundsState; mMenuController = menuController; @@ -290,11 +285,6 @@ public class PipTouchHandler { mFloatingContentCoordinator.onContentRemoved(mMotionHelper); } - // Reset exclusion to none. - if (mPipExclusionBoundsChangeListener != null - && mPipExclusionBoundsChangeListener.get() != null) { - mPipExclusionBoundsChangeListener.get().accept(new Rect()); - } mPipResizeGestureHandler.onActivityUnpinned(); } @@ -931,10 +921,6 @@ public class PipTouchHandler { } private void stashEndAction() { - if (mPipExclusionBoundsChangeListener != null - && mPipExclusionBoundsChangeListener.get() != null) { - mPipExclusionBoundsChangeListener.get().accept(mPipBoundsState.getBounds()); - } if (mPipBoundsState.getBounds().left < 0 && mPipBoundsState.getStashedState() != STASH_TYPE_LEFT) { mPipUiEventLogger.log( @@ -954,11 +940,6 @@ public class PipTouchHandler { // dismiss overlay, so just finish it after the animation completes mMenuController.hideMenu(); } - // Reset exclusion to none. - if (mPipExclusionBoundsChangeListener != null - && mPipExclusionBoundsChangeListener.get() != null) { - mPipExclusionBoundsChangeListener.get().accept(new Rect()); - } } private boolean shouldStash(PointF vel, Rect motionBounds) { @@ -982,13 +963,6 @@ public class PipTouchHandler { } } - void setPipExclusionBoundsChangeListener(Consumer pipExclusionBoundsChangeListener) { - mPipExclusionBoundsChangeListener = new WeakReference<>(pipExclusionBoundsChangeListener); - pipExclusionBoundsChangeListener.accept(mPipTaskOrganizer.isInPip() - ? mPipBoundsState.getBounds() : new Rect()); - - } - /** * Updates the current movement bounds based on whether the menu is currently visible and * resized.