From 7bdba3204187a67fa354bd2bc677b1b52070524d Mon Sep 17 00:00:00 2001 From: Riddle Hsu Date: Wed, 24 May 2023 00:11:09 +0800 Subject: [PATCH] Avoid invisible PiP handling input events When the PiP is faded out for an intermediate orientation state (swiped recents is portrait, display is landscape), its layer will still intercept input events. Move it outside screen when its alpha is 0 so it won't affect input. Also skip mPipAnimationCallback because the direction is not entering or exiting PiP. That avoids additional position change when the animation is finished. Bug: 283971760 Bug: 262835608 Test: Disable launcher rotation. Launch an app which enter PiP. Launch another landscape app and swipe up from bottom to enter recents. Drag the area where the PiP was, it should be able to scroll the recents. Change-Id: Ibc0ee8e3e4780fc0f6c14c5a54b25c9b30b235c6 --- .../android/wm/shell/pip/PipTransition.java | 20 ++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) diff --git a/libs/WindowManager/Shell/src/com/android/wm/shell/pip/PipTransition.java b/libs/WindowManager/Shell/src/com/android/wm/shell/pip/PipTransition.java index bfc1fb905adeb..b6d6bba4cb109 100644 --- a/libs/WindowManager/Shell/src/com/android/wm/shell/pip/PipTransition.java +++ b/libs/WindowManager/Shell/src/com/android/wm/shell/pip/PipTransition.java @@ -1069,10 +1069,28 @@ public class PipTransition extends PipTransitionController { } final float alphaStart = show ? 0 : 1; final float alphaEnd = show ? 1 : 0; + final PipAnimationController.PipTransactionHandler transactionHandler = + new PipAnimationController.PipTransactionHandler() { + @Override + public boolean handlePipTransaction(SurfaceControl leash, + SurfaceControl.Transaction tx, Rect destinationBounds, float alpha) { + if (alpha == 0) { + if (show) { + tx.setPosition(leash, destinationBounds.left, destinationBounds.top); + } else { + // Put PiP out of the display so it won't block touch when it is hidden. + final Rect displayBounds = mPipDisplayLayoutState.getDisplayBounds(); + final int max = Math.max(displayBounds.width(), displayBounds.height()); + tx.setPosition(leash, max, max); + } + } + return false; + } + }; mPipAnimationController .getAnimator(taskInfo, leash, mPipBoundsState.getBounds(), alphaStart, alphaEnd) .setTransitionDirection(TRANSITION_DIRECTION_SAME) - .setPipAnimationCallback(mPipAnimationCallback) + .setPipTransactionHandler(transactionHandler) .setDuration(mEnterExitAnimationDuration) .start(); mHasFadeOut = !show;