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

Commit 2cd60c5e authored by Wenyu Zhang's avatar Wenyu Zhang
Browse files

[1/3] autoclick: Do not reset timer when cursor moves within indicator

Even the ignore cursor movement setting is off, movement within the
visual indicator should not reset the timer.

demo: http://b/430320631#comment3.

The "Ignore minor cursor movement" settings should only affect whether
center dot will follow the cursor, which will be implemented in
following CLs.

Change-Id: Ib4248183bff4362b1a75b46e8513d21d635cee45
Bug: b/430320631
Test: AutoclickControllerTest
Flag: com.android.server.accessibility.enable_autoclick_indicator
parent 1149807e
Loading
Loading
Loading
Loading
+1 −2
Original line number Diff line number Diff line
@@ -1298,8 +1298,7 @@ public class AutoclickController extends BaseEventStreamTransformation implement
            // If the panel is hovered, always use the default slop so it's easier to click the
            // closely spaced buttons.
            double slop =
                    ((Flags.enableAutoclickIndicator() && mIgnoreMinorCursorMovement
                            && !isPanelHovered())
                    ((Flags.enableAutoclickIndicator() && !isPanelHovered())
                            ? mMovementSlop
                            : DEFAULT_MOVEMENT_SLOP);
            return delta > slop;
+14 −14
Original line number Diff line number Diff line
@@ -429,7 +429,7 @@ public class AutoclickControllerTest {
        long initialScheduledTime = mController.mClickScheduler.getScheduledClickTimeForTesting();

        // Significant change in x (30f difference) and y (30f difference)
        injectFakeMouseMoveEvent(/* x= */ 60f, /* y= */ 70f, MotionEvent.ACTION_HOVER_MOVE);
        injectFakeMouseMoveEvent(/* x= */ 100f, /* y= */ 100f, MotionEvent.ACTION_HOVER_MOVE);

        // Verify that the scheduled click time has changed (click was rescheduled).
        assertThat(mController.mClickScheduler.getScheduledClickTimeForTesting())
@@ -486,7 +486,7 @@ public class AutoclickControllerTest {

    @Test
    @EnableFlags(com.android.server.accessibility.Flags.FLAG_ENABLE_AUTOCLICK_INDICATOR)
    public void onIgnoreCursorMovementFromSettingsChange_clickTriggered() {
    public void onNotIgnoreCursorMovement_clickNotTriggered_whenMoveIsWithinSlop() {
        // Send initial mouse movement.
        injectFakeMouseActionHoverMoveEvent();

@@ -500,16 +500,16 @@ public class AutoclickControllerTest {
                Settings.Secure.getUriFor(
                        Settings.Secure.ACCESSIBILITY_AUTOCLICK_CURSOR_AREA_SIZE));

        // Move the mouse down less than customSize radius but ignore custom movement is not enabled
        // so a click is triggered.
        // Move the mouse down less than customSize radius. Even if ignore custom movement is not
        // enabled, a click is not triggered as long as the move is within the slop.
        float moveDownY = customSize - 100;
        injectFakeMouseMoveEvent(/* x= */ 0, /* y= */ moveDownY, MotionEvent.ACTION_HOVER_MOVE);
        assertThat(mController.mClickScheduler.getIsActiveForTesting()).isTrue();
        assertThat(mController.mClickScheduler.getIsActiveForTesting()).isFalse();
    }

    @Test
    @EnableFlags(com.android.server.accessibility.Flags.FLAG_ENABLE_AUTOCLICK_INDICATOR)
    public void onIgnoreCursorMovementFromSettingsChange_clickNotTriggered() {
    public void onIgnoreCursorMovement_clickNotTriggered_whenMoveIsWithinSlop() {
        // Move mouse to initialize autoclick panel before enabling ignore minor cursor movement.
        injectFakeMouseActionHoverMoveEvent();
        enableIgnoreMinorCursorMovement();
@@ -524,8 +524,8 @@ public class AutoclickControllerTest {
                Settings.Secure.getUriFor(
                        Settings.Secure.ACCESSIBILITY_AUTOCLICK_CURSOR_AREA_SIZE));

        // After enabling ignore custom movement, move the mouse right, less than customSize radius
        // so a click won't be triggered.
        // No matter if ignore custom movement is enabled or not, a click won't be triggered as long
        // as the move is inside the slop.
        float moveRightX = customSize - 100;
        injectFakeMouseMoveEvent(/* x= */ moveRightX, /* y= */ 0, MotionEvent.ACTION_HOVER_MOVE);
        assertThat(mController.mClickScheduler.getIsActiveForTesting()).isFalse();
@@ -581,7 +581,7 @@ public class AutoclickControllerTest {
        assertThat(mController.mClickScheduler.getScheduledClickTimeForTesting()).isEqualTo(-1);

        // Send move again to trigger click and verify there is now a pending click.
        injectFakeMouseMoveEvent(/* x= */ 30f, /* y= */ 0, MotionEvent.ACTION_HOVER_MOVE);
        injectFakeMouseMoveEvent(/* x= */ 100f, /* y= */ 0, MotionEvent.ACTION_HOVER_MOVE);
        assertThat(mController.mClickScheduler.getIsActiveForTesting()).isTrue();
        assertThat(mController.mClickScheduler.getScheduledClickTimeForTesting()).isNotEqualTo(-1);
    }
@@ -730,7 +730,7 @@ public class AutoclickControllerTest {
        initializeAutoclick();

        // Send hover move event.
        injectFakeMouseMoveEvent(/* x= */ 30f, /* y= */ 0, MotionEvent.ACTION_HOVER_MOVE);
        injectFakeMouseMoveEvent(/* x= */ 100f, /* y= */ 0, MotionEvent.ACTION_HOVER_MOVE);
        mTestableLooper.processAllMessages();

        // Verify left click sent.
@@ -750,7 +750,7 @@ public class AutoclickControllerTest {
        mController.mAutoclickTypePanel = mockAutoclickTypePanel;

        // Send hover move event.
        injectFakeMouseMoveEvent(/* x= */ 30f, /* y= */ 0, MotionEvent.ACTION_HOVER_MOVE);
        injectFakeMouseMoveEvent(/* x= */ 100f, /* y= */ 0, MotionEvent.ACTION_HOVER_MOVE);
        mTestableLooper.processAllMessages();

        // Verify right click sent.
@@ -773,7 +773,7 @@ public class AutoclickControllerTest {
        mController.mAutoclickScrollPanel = mockScrollPanel;

        // First hover move event.
        injectFakeMouseMoveEvent(/* x= */ 30f, /* y= */ 0, MotionEvent.ACTION_HOVER_MOVE);
        injectFakeMouseMoveEvent(/* x= */ 100f, /* y= */ 0, MotionEvent.ACTION_HOVER_MOVE);
        mTestableLooper.processAllMessages();

        // Verify scroll panel is shown once.
@@ -1138,7 +1138,7 @@ public class AutoclickControllerTest {
        mController.clickPanelController.handleAutoclickTypeChange(
                AutoclickTypePanel.AUTOCLICK_TYPE_DRAG);

        injectFakeMouseMoveEvent(/* x= */ 30, /* y= */ 0, MotionEvent.ACTION_HOVER_MOVE);
        injectFakeMouseMoveEvent(/* x= */ 100, /* y= */ 0, MotionEvent.ACTION_HOVER_MOVE);
        mTestableLooper.processAllMessages();

        // Verify only two motion events were sent.
@@ -1291,7 +1291,7 @@ public class AutoclickControllerTest {
        mController.mAutoclickTypePanel = mockAutoclickTypePanel;

        // Send hover move event.
        injectFakeMouseMoveEvent(/* x= */ 30f, /* y= */ 0, MotionEvent.ACTION_HOVER_MOVE);
        injectFakeMouseMoveEvent(/* x= */ 100f, /* y= */ 0, MotionEvent.ACTION_HOVER_MOVE);
        mTestableLooper.processAllMessages();
        assertThat(motionEventCaptor.downEvent).isNotNull();
        assertThat(motionEventCaptor.downEvent.getButtonState()).isEqualTo(