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

Commit 6d233832 authored by Michael Checo's avatar Michael Checo
Browse files

Add Autoclick jitter and significant movement tests

Bug: b/390399954, b/395949910
Test: AutoclickControllerTest
Flag: com.android.server.accessibility.enable_autoclick_indicator
Change-Id: I34e72627fdf23c6dbc93dbf4400c5f4e4d702cb7
parent 862604ca
Loading
Loading
Loading
Loading
+5 −0
Original line number Diff line number Diff line
@@ -538,6 +538,11 @@ public class AutoclickController extends BaseEventStreamTransformation {
            return mActive;
        }

        @VisibleForTesting
        long getScheduledClickTimeForTesting() {
            return mScheduledClickTime;
        }

        /**
         * Updates delay that should be used when scheduling clicks. The delay will be used only for
         * clicks scheduled after this point (pending click tasks are not affected).
+74 −0
Original line number Diff line number Diff line
@@ -326,6 +326,80 @@ public class AutoclickControllerTest {
        assertThat(mController.mClickScheduler.getIsActiveForTesting()).isTrue();
    }

    @Test
    public void smallJitteryMovement_doesNotTriggerClick() {
        // Initial hover move to set an anchor point.
        MotionEvent initialHoverMove = MotionEvent.obtain(
                /* downTime= */ 0,
                /* eventTime= */ 100,
                /* action= */ MotionEvent.ACTION_HOVER_MOVE,
                /* x= */ 30f,
                /* y= */ 40f,
                /* metaState= */ 0);
        initialHoverMove.setSource(InputDevice.SOURCE_MOUSE);
        mController.onMotionEvent(initialHoverMove, initialHoverMove, /* policyFlags= */ 0);

        // Get the initial scheduled click time.
        long initialScheduledTime = mController.mClickScheduler.getScheduledClickTimeForTesting();

        // Simulate small, jittery movements (all within the default slop).
        MotionEvent jitteryMove1 = MotionEvent.obtain(
                /* downTime= */ 0,
                /* eventTime= */ 150,
                /* action= */ MotionEvent.ACTION_HOVER_MOVE,
                /* x= */ 31f,  // Small change in x
                /* y= */ 41f,  // Small change in y
                /* metaState= */ 0);
        jitteryMove1.setSource(InputDevice.SOURCE_MOUSE);
        mController.onMotionEvent(jitteryMove1, jitteryMove1, /* policyFlags= */ 0);

        MotionEvent jitteryMove2 = MotionEvent.obtain(
                /* downTime= */ 0,
                /* eventTime= */ 200,
                /* action= */ MotionEvent.ACTION_HOVER_MOVE,
                /* x= */ 30.5f, // Small change in x
                /* y= */ 39.8f, // Small change in y
                /* metaState= */ 0);
        jitteryMove2.setSource(InputDevice.SOURCE_MOUSE);
        mController.onMotionEvent(jitteryMove2, jitteryMove2, /* policyFlags= */ 0);

        // Verify that the scheduled click time has NOT changed.
        assertThat(mController.mClickScheduler.getScheduledClickTimeForTesting())
                .isEqualTo(initialScheduledTime);
    }

    @Test
    public void singleSignificantMovement_triggersClick() {
        // Initial hover move to set an anchor point.
        MotionEvent initialHoverMove = MotionEvent.obtain(
                /* downTime= */ 0,
                /* eventTime= */ 100,
                /* action= */ MotionEvent.ACTION_HOVER_MOVE,
                /* x= */ 30f,
                /* y= */ 40f,
                /* metaState= */ 0);
        initialHoverMove.setSource(InputDevice.SOURCE_MOUSE);
        mController.onMotionEvent(initialHoverMove, initialHoverMove, /* policyFlags= */ 0);

        // Get the initial scheduled click time.
        long initialScheduledTime = mController.mClickScheduler.getScheduledClickTimeForTesting();

        // Simulate a single, significant movement (greater than the default slop).
        MotionEvent significantMove = MotionEvent.obtain(
                /* downTime= */ 0,
                /* eventTime= */ 150,
                /* action= */ MotionEvent.ACTION_HOVER_MOVE,
                /* x= */ 60f,  // Significant change in x (30f difference)
                /* y= */ 70f,  // Significant change in y (30f difference)
                /* metaState= */ 0);
        significantMove.setSource(InputDevice.SOURCE_MOUSE);
        mController.onMotionEvent(significantMove, significantMove, /* policyFlags= */ 0);

        // Verify that the scheduled click time has changed (click was rescheduled).
        assertThat(mController.mClickScheduler.getScheduledClickTimeForTesting())
                .isNotEqualTo(initialScheduledTime);
    }

    private void injectFakeMouseActionHoverMoveEvent() {
        MotionEvent event = getFakeMotionHoverMoveEvent();
        event.setSource(InputDevice.SOURCE_MOUSE);