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

Commit 1969192d authored by Tyler Freeman's avatar Tyler Freeman
Browse files

fix(magnification fling): stop fling animation if they put their finger down

Fix: 319175022
Flag: ACONFIG com.android.server.accessibility.fullscreen_fling_gesture DISABLED
Test: atest com.android.server.accessibility.magnification.FullScreenMagnificationGestureHandlerTest
NO_IFTTT=just TODO comments

Change-Id: I57014e3102ec6b2b2531f8c2ce3913786161ac25
parent daf8ef3e
Loading
Loading
Loading
Loading
+47 −1
Original line number Diff line number Diff line
@@ -447,6 +447,17 @@ public class FullScreenMagnificationController implements
            }
        }

        void cancelFlingAnimation() {
            if (DEBUG) {
                Slog.i(LOG_TAG, "cancelFlingAnimation()");
            }
            if (Thread.currentThread().getId() == mMainThreadId) {
                mSpecAnimationBridge.cancelFlingAnimation();
            } else {
                mControllerCtx.getHandler().post(mSpecAnimationBridge::cancelFlingAnimation);
            }
        }

        /**
         * Get the ID of the last service that changed the magnification spec.
         *
@@ -843,6 +854,20 @@ public class FullScreenMagnificationController implements
                    });
        }


        @GuardedBy("mLock")
        void cancelFling(int id) {
            if (!mRegistered) {
                return;
            }

            if (id != INVALID_SERVICE_ID) {
                mIdOfLastServiceToMagnify = id;
            }

            cancelFlingAnimation();
        }

        boolean updateCurrentSpecWithOffsetsLocked(float nonNormOffsetX, float nonNormOffsetY) {
            if (DEBUG) {
                Slog.i(LOG_TAG,
@@ -1543,6 +1568,22 @@ public class FullScreenMagnificationController implements
        }
    }

    /**
     * Call to cancel the fling animation if it is running. Call this on any ACTION_DOWN event.
     *
     * @param displayId The logical display id.
     * @param id the ID of the service requesting the change
     */
    public void cancelFling(int displayId, int id) {
        synchronized (mLock) {
            final DisplayMagnification display = mDisplays.get(displayId);
            if (display == null) {
                return;
            }
            display.cancelFling(id);
        }
    }

    /**
     * Get the ID of the last service that changed the magnification spec.
     *
@@ -2031,11 +2072,16 @@ public class FullScreenMagnificationController implements
        }

        @MainThread
        private void cancelAnimations() {
        void cancelAnimations() {
            if (mValueAnimator.isRunning()) {
                mValueAnimator.cancel();
            }

            cancelFlingAnimation();
        }

        @MainThread
        void cancelFlingAnimation() {
            if (!Flags.fullscreenFlingGesture()) {
                return;
            }
+14 −0
Original line number Diff line number Diff line
@@ -324,6 +324,10 @@ public class FullScreenMagnificationGestureHandler extends MagnificationGestureH

    @Override
    void onMotionEventInternal(MotionEvent event, MotionEvent rawEvent, int policyFlags) {
        if (event.getActionMasked() == ACTION_DOWN) {
            cancelFling();
        }

        handleEventWith(mCurrentState, event, rawEvent, policyFlags);
    }

@@ -1824,6 +1828,16 @@ public class FullScreenMagnificationGestureHandler extends MagnificationGestureH
        }
    }

    private void cancelFling() {
        if (!Flags.fullscreenFlingGesture()) {
            return;
        }

        mFullScreenMagnificationController.cancelFling(
                    mDisplayId,
                    AccessibilityManagerService.MAGNIFICATION_GESTURE_HANDLER_ID);
    }

    final class SinglePanningState extends SimpleOnGestureListener implements State {


+39 −0
Original line number Diff line number Diff line
@@ -1143,6 +1143,45 @@ public class FullScreenMagnificationGestureHandlerTest {
        );
    }

    @Test
    @RequiresFlagsEnabled(Flags.FLAG_FULLSCREEN_FLING_GESTURE)
    public void testDownEvent_cancelsFling()
            throws InterruptedException {
        goFromStateIdleTo(STATE_ACTIVATED);
        PointF pointer1 = DEFAULT_POINT;
        PointF pointer2 = new PointF(DEFAULT_X * 1.5f, DEFAULT_Y);

        send(downEvent());
        send(pointerEvent(ACTION_POINTER_DOWN, new PointF[] {pointer1, pointer2}, 1));

        // first move triggers the panning state
        pointer1.offset(100, 0);
        pointer2.offset(100, 0);
        fastForward(20);
        send(pointerEvent(ACTION_MOVE, new PointF[] {pointer1, pointer2}, 0));

        // second move actually pans
        pointer1.offset(100, 0);
        pointer2.offset(100, 0);
        fastForward(20);
        send(pointerEvent(ACTION_MOVE, new PointF[] {pointer1, pointer2}, 0));
        pointer1.offset(100, 0);
        pointer2.offset(100, 0);
        fastForward(20);
        send(pointerEvent(ACTION_MOVE, new PointF[] {pointer1, pointer2}, 0));

        assertIn(STATE_PANNING);
        mHandler.timeAdvance();
        returnToNormalFrom(STATE_PANNING);

        mHandler.timeAdvance();

        send(downEvent());
        mHandler.timeAdvance();

        verify(mMockScroller).forceFinished(eq(true));
    }

    @Test
    public void testShortcutTriggered_invokeShowWindowPromptAction() {
        goFromStateIdleTo(STATE_SHORTCUT_TRIGGERED);