Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit b54b65b0 authored by Winson Chung's avatar Winson Chung
Browse files

Fixing issue with lingering dismiss PiP overlay.

- Always try and remove the dismiss overlay when animating touch ends, or
  if the input consumer is unregistered to handle cases where the
  interaction is interrupted by the pip animation.

Bug: 37309693
Test: Intermittent, enter pip and try to tap and then tap-drag the PIP
Change-Id: I05f360f1d9d264590725e13eb2cc9254a3f21eef
parent ef16fa98
Loading
Loading
Loading
Loading
+33 −17
Original line number Diff line number Diff line
@@ -225,7 +225,7 @@ public class PipTouchHandler implements TunerService.Tunable {
        if (mIsMinimized) {
            setMinimizedStateInternal(false);
        }
        mDismissViewController.destroyDismissTarget();
        cleanUpDismissTarget();
        mShowPipMenuOnAnimationEnd = true;
    }

@@ -334,6 +334,12 @@ public class PipTouchHandler implements TunerService.Tunable {
        mAccessibilityManager.setPictureInPictureActionReplacingConnection(isRegistered
                ? new PipAccessibilityInteractionConnection(mMotionHelper,
                        this::onAccessibilityShowMenu, mHandler) : null);

        if (!isRegistered && mTouchState.isUserInteracting()) {
            // If the input consumer is unregistered while the user is interacting, then we may not
            // get the final TOUCH_UP event, so clean up the dismiss target as well
            cleanUpDismissTarget();
        }
    }

    private void onAccessibilityShowMenu() {
@@ -578,12 +584,12 @@ public class PipTouchHandler implements TunerService.Tunable {

            if (touchState.startedDragging()) {
                mSavedSnapFraction = -1f;
            }

            if (touchState.startedDragging() && ENABLE_DISMISS_DRAG_TO_EDGE) {
                if (ENABLE_DISMISS_DRAG_TO_EDGE) {
                    mHandler.removeCallbacks(mShowDismissAffordance);
                    mDismissViewController.showDismissTarget();
                }
            }

            if (touchState.isDragging()) {
                // Move the pinned stack freely
@@ -625,6 +631,12 @@ public class PipTouchHandler implements TunerService.Tunable {

        @Override
        public boolean onUp(PipTouchState touchState) {
            if (ENABLE_DISMISS_DRAG_TO_EDGE) {
                // Clean up the dismiss target regardless of the touch state in case the touch
                // enabled state changes while the user is interacting
                cleanUpDismissTarget();
            }

            if (!touchState.isUserInteracting()) {
                return false;
            }
@@ -640,8 +652,7 @@ public class PipTouchHandler implements TunerService.Tunable {
            final boolean isFlingToBot = isFling && vel.y > 0 && !isHorizontal
                    && (mMovementWithinDismiss || isUpWithinDimiss);
            if (ENABLE_DISMISS_DRAG_TO_EDGE) {
                try {
                    mHandler.removeCallbacks(mShowDismissAffordance);
                // Check if the user dragged or flung the PiP offscreen to dismiss it
                if (mMotionHelper.shouldDismissPip() || isFlingToBot) {
                    mMotionHelper.animateDismiss(mMotionHelper.getBounds(), vel.x,
                        vel.y, mUpdateScrimListener);
@@ -650,9 +661,6 @@ public class PipTouchHandler implements TunerService.Tunable {
                            METRIC_VALUE_DISMISSED_BY_DRAG);
                    return true;
                }
                } finally {
                    mDismissViewController.destroyDismissTarget();
                }
            }

            if (touchState.isDragging()) {
@@ -728,6 +736,14 @@ public class PipTouchHandler implements TunerService.Tunable {
                : mNormalMovementBounds;
    }

    /**
     * Removes the dismiss target and cancels any pending callbacks to show it.
     */
    private void cleanUpDismissTarget() {
        mHandler.removeCallbacks(mShowDismissAffordance);
        mDismissViewController.destroyDismissTarget();
    }

    public void dump(PrintWriter pw, String prefix) {
        final String innerPrefix = prefix + "  ";
        pw.println(prefix + TAG);