Loading services/accessibility/java/com/android/server/accessibility/autoclick/AutoclickController.java +5 −0 Original line number Diff line number Diff line Loading @@ -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). Loading services/tests/servicestests/src/com/android/server/accessibility/autoclick/AutoclickControllerTest.java +74 −0 Original line number Diff line number Diff line Loading @@ -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); Loading Loading
services/accessibility/java/com/android/server/accessibility/autoclick/AutoclickController.java +5 −0 Original line number Diff line number Diff line Loading @@ -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). Loading
services/tests/servicestests/src/com/android/server/accessibility/autoclick/AutoclickControllerTest.java +74 −0 Original line number Diff line number Diff line Loading @@ -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); Loading