summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
author Gavin Williams <gavinwill@google.com> 2025-02-21 19:47:31 -0800
committer Android (Google) Code Review <android-gerrit@google.com> 2025-02-21 19:47:31 -0800
commita00a9dd5391f7d541307c96cedb0b2367b00a095 (patch)
tree413daf91c1a58b8ef0043e032f59ddfae2fc3277
parent72d5882b76963a5bf1e72502d50252bb309ac38d (diff)
parent5a14c39bbba60de25f72c7d89aa7b088a32d1f1d (diff)
Merge "a11y: Add onChange() tests for AutoClickController" into main
-rw-r--r--services/accessibility/java/com/android/server/accessibility/autoclick/AutoclickController.java5
-rw-r--r--services/tests/servicestests/src/com/android/server/accessibility/autoclick/AutoclickControllerTest.java140
2 files changed, 145 insertions, 0 deletions
diff --git a/services/accessibility/java/com/android/server/accessibility/autoclick/AutoclickController.java b/services/accessibility/java/com/android/server/accessibility/autoclick/AutoclickController.java
index aa82df493f84..9ee7ec952ec1 100644
--- a/services/accessibility/java/com/android/server/accessibility/autoclick/AutoclickController.java
+++ b/services/accessibility/java/com/android/server/accessibility/autoclick/AutoclickController.java
@@ -230,6 +230,11 @@ public class AutoclickController extends BaseEventStreamTransformation {
return Flags.enableAutoclickIndicator() && mAutoclickTypePanel.isPaused();
}
+ @VisibleForTesting
+ void onChangeForTesting(boolean selfChange, Uri uri) {
+ mAutoclickSettingsObserver.onChange(selfChange, uri);
+ }
+
/**
* Observes autoclick setting values, and updates ClickScheduler delay and indicator size
* whenever the setting value changes.
diff --git a/services/tests/servicestests/src/com/android/server/accessibility/autoclick/AutoclickControllerTest.java b/services/tests/servicestests/src/com/android/server/accessibility/autoclick/AutoclickControllerTest.java
index 0745c68fd337..17d8882b487c 100644
--- a/services/tests/servicestests/src/com/android/server/accessibility/autoclick/AutoclickControllerTest.java
+++ b/services/tests/servicestests/src/com/android/server/accessibility/autoclick/AutoclickControllerTest.java
@@ -41,6 +41,7 @@ import android.view.MotionEvent;
import android.view.WindowManager;
import android.view.accessibility.AccessibilityManager;
+import com.android.internal.accessibility.util.AccessibilityUtils;
import com.android.server.accessibility.AccessibilityTraceManager;
import org.junit.After;
@@ -79,7 +80,9 @@ public class AutoclickControllerTest {
@After
public void tearDown() {
+ mController.onDestroy();
mTestableLooper.processAllMessages();
+ TestableLooper.remove(this);
}
@Test
@@ -403,6 +406,133 @@ public class AutoclickControllerTest {
@Test
@EnableFlags(com.android.server.accessibility.Flags.FLAG_ENABLE_AUTOCLICK_INDICATOR)
+ public void onCursorAreaSizeSettingsChange_moveWithinCustomRadius_clickNotTriggered() {
+ // Move mouse to initialize autoclick panel before enabling ignore minor cursor movement.
+ injectFakeMouseActionHoverMoveEvent();
+ enableIgnoreMinorCursorMovement();
+
+ // Set a custom cursor area size.
+ int customSize = 250;
+ Settings.Secure.putIntForUser(mTestableContext.getContentResolver(),
+ Settings.Secure.ACCESSIBILITY_AUTOCLICK_CURSOR_AREA_SIZE,
+ customSize,
+ mTestableContext.getUserId());
+ mController.onChangeForTesting(/* selfChange= */ true,
+ Settings.Secure.getUriFor(
+ Settings.Secure.ACCESSIBILITY_AUTOCLICK_CURSOR_AREA_SIZE));
+ assertThat(mController.mAutoclickIndicatorView.getRadiusForTesting()).isEqualTo(customSize);
+
+ // Move the mouse down, less than customSize radius so a click is not triggered.
+ float moveDownY = customSize - 25;
+ MotionEvent hoverMove = MotionEvent.obtain(
+ /* downTime= */ 0,
+ /* eventTime= */ 150,
+ /* action= */ MotionEvent.ACTION_HOVER_MOVE,
+ /* x= */ 0f,
+ /* y= */ moveDownY,
+ /* metaState= */ 0);
+ hoverMove.setSource(InputDevice.SOURCE_MOUSE);
+ mController.onMotionEvent(hoverMove, hoverMove, /* policyFlags= */ 0);
+ assertThat(mController.mClickScheduler.getIsActiveForTesting()).isFalse();
+ }
+
+ @Test
+ @EnableFlags(com.android.server.accessibility.Flags.FLAG_ENABLE_AUTOCLICK_INDICATOR)
+ public void onCursorAreaSizeSettingsChange_moveOutsideCustomRadius_clickTriggered() {
+ // Move mouse to initialize autoclick panel before enabling ignore minor cursor movement.
+ injectFakeMouseActionHoverMoveEvent();
+ enableIgnoreMinorCursorMovement();
+
+ // Set a custom cursor area size.
+ int customSize = 250;
+ Settings.Secure.putIntForUser(mTestableContext.getContentResolver(),
+ Settings.Secure.ACCESSIBILITY_AUTOCLICK_CURSOR_AREA_SIZE,
+ customSize,
+ mTestableContext.getUserId());
+ mController.onChangeForTesting(/* selfChange= */ true,
+ Settings.Secure.getUriFor(
+ Settings.Secure.ACCESSIBILITY_AUTOCLICK_CURSOR_AREA_SIZE));
+ assertThat(mController.mAutoclickIndicatorView.getRadiusForTesting()).isEqualTo(customSize);
+
+ // Move the mouse right, greater than customSize radius so a click is triggered.
+ float moveRightX = customSize + 100;
+ MotionEvent hoverMove = MotionEvent.obtain(
+ /* downTime= */ 0,
+ /* eventTime= */ 200,
+ /* action= */ MotionEvent.ACTION_HOVER_MOVE,
+ /* x= */ moveRightX,
+ /* y= */ 0,
+ /* metaState= */ 0);
+ hoverMove.setSource(InputDevice.SOURCE_MOUSE);
+ mController.onMotionEvent(hoverMove, hoverMove, /* policyFlags= */ 0);
+ assertThat(mController.mClickScheduler.getIsActiveForTesting()).isTrue();
+ }
+
+ @Test
+ @EnableFlags(com.android.server.accessibility.Flags.FLAG_ENABLE_AUTOCLICK_INDICATOR)
+ public void onIgnoreCursorMovementFromSettingsChange_clickTriggered() {
+ // Send initial mouse movement.
+ injectFakeMouseActionHoverMoveEvent();
+
+ // Set a custom cursor area size.
+ int customSize = 250;
+ Settings.Secure.putIntForUser(mTestableContext.getContentResolver(),
+ Settings.Secure.ACCESSIBILITY_AUTOCLICK_CURSOR_AREA_SIZE,
+ customSize,
+ mTestableContext.getUserId());
+ mController.onChangeForTesting(/* selfChange= */ true,
+ 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.
+ float moveDownY = customSize - 100;
+ MotionEvent hoverMove = MotionEvent.obtain(
+ /* downTime= */ 0,
+ /* eventTime= */ 150,
+ /* action= */ MotionEvent.ACTION_HOVER_MOVE,
+ /* x= */ 0f,
+ /* y= */ moveDownY,
+ /* metaState= */ 0);
+ hoverMove.setSource(InputDevice.SOURCE_MOUSE);
+ mController.onMotionEvent(hoverMove, hoverMove, /* policyFlags= */ 0);
+ assertThat(mController.mClickScheduler.getIsActiveForTesting()).isTrue();
+ }
+
+ @Test
+ @EnableFlags(com.android.server.accessibility.Flags.FLAG_ENABLE_AUTOCLICK_INDICATOR)
+ public void onIgnoreCursorMovementFromSettingsChange_clickNotTriggered() {
+ // Move mouse to initialize autoclick panel before enabling ignore minor cursor movement.
+ injectFakeMouseActionHoverMoveEvent();
+ enableIgnoreMinorCursorMovement();
+
+ // Set a custom cursor area size.
+ int customSize = 250;
+ Settings.Secure.putIntForUser(mTestableContext.getContentResolver(),
+ Settings.Secure.ACCESSIBILITY_AUTOCLICK_CURSOR_AREA_SIZE,
+ customSize,
+ mTestableContext.getUserId());
+ mController.onChangeForTesting(/* selfChange= */ true,
+ 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.
+ float moveRightX = customSize - 100;
+ MotionEvent hoverMove = MotionEvent.obtain(
+ /* downTime= */ 0,
+ /* eventTime= */ 200,
+ /* action= */ MotionEvent.ACTION_HOVER_MOVE,
+ /* x= */ moveRightX,
+ /* y= */ 0,
+ /* metaState= */ 0);
+ hoverMove.setSource(InputDevice.SOURCE_MOUSE);
+ mController.onMotionEvent(hoverMove, hoverMove, /* policyFlags= */ 0);
+ assertThat(mController.mClickScheduler.getIsActiveForTesting()).isFalse();
+ }
+
+ @Test
+ @EnableFlags(com.android.server.accessibility.Flags.FLAG_ENABLE_AUTOCLICK_INDICATOR)
public void pauseButton_flagOn_clickNotTriggeredWhenPaused() {
injectFakeMouseActionHoverMoveEvent();
@@ -473,4 +603,14 @@ public class AutoclickControllerTest {
/* y= */ 0,
/* metaState= */ 0);
}
+
+ private void enableIgnoreMinorCursorMovement() {
+ Settings.Secure.putIntForUser(mTestableContext.getContentResolver(),
+ Settings.Secure.ACCESSIBILITY_AUTOCLICK_IGNORE_MINOR_CURSOR_MOVEMENT,
+ AccessibilityUtils.State.ON,
+ mTestableContext.getUserId());
+ mController.onChangeForTesting(/* selfChange= */ true,
+ Settings.Secure.getUriFor(
+ Settings.Secure.ACCESSIBILITY_AUTOCLICK_IGNORE_MINOR_CURSOR_MOVEMENT));
+ }
}