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

Commit c5bed728 authored by Asmita Poddar's avatar Asmita Poddar Committed by Android (Google) Code Review
Browse files

Merge "Change mouse keys scroll rate" into main

parents 1bf29854 010a3b57
Loading
Loading
Loading
Loading
+7 −3
Original line number Diff line number Diff line
@@ -73,12 +73,16 @@ public class MouseKeysInterceptor extends BaseEventStreamTransformation

    private static final int MESSAGE_MOVE_MOUSE_POINTER = 1;
    private static final int MESSAGE_SCROLL_MOUSE_POINTER = 2;
    private static final float MOUSE_POINTER_MOVEMENT_STEP = 1.8f;
    private static final int KEY_NOT_SET = -1;

    /** Time interval after which mouse action will be repeated */
    private static final int INTERVAL_MILLIS = 10;

    @VisibleForTesting
    public static final float MOUSE_POINTER_MOVEMENT_STEP = 1.8f;
    @VisibleForTesting
    public static final float MOUSE_SCROLL_STEP = 0.2f;

    private final AccessibilityManagerService mAms;
    private final Handler mHandler;
    private final InputManager mInputManager;
@@ -281,8 +285,8 @@ public class MouseKeysInterceptor extends BaseEventStreamTransformation
        MouseKeyEvent mouseKeyEvent = MouseKeyEvent.from(
                keyCode, mActiveInputDeviceId, mDeviceKeyCodeMap);
        float y = switch (mouseKeyEvent) {
            case UP_MOVE_OR_SCROLL -> 1.0f;
            case DOWN_MOVE_OR_SCROLL -> -1.0f;
            case UP_MOVE_OR_SCROLL -> MOUSE_SCROLL_STEP;
            case DOWN_MOVE_OR_SCROLL -> -MOUSE_SCROLL_STEP;
            default -> 0.0f;
        };
        waitForVirtualMouseCreation();
+6 −5
Original line number Diff line number Diff line
@@ -61,7 +61,6 @@ class MouseKeysInterceptorTest {
    companion object {
        const val DISPLAY_ID = 1
        const val DEVICE_ID = 123
        const val MOUSE_POINTER_MOVEMENT_STEP = 1.8f
        // This delay is required for key events to be sent and handled correctly.
        // The handler only performs a move/scroll event if it receives the key event
        // at INTERVAL_MILLIS (which happens in practice). Hence, we need this delay in the tests.
@@ -159,8 +158,8 @@ class MouseKeysInterceptorTest {
        testLooper.dispatchAll()

        // Verify the sendRelativeEvent method is called once and capture the arguments
        verifyRelativeEvents(arrayOf(-MOUSE_POINTER_MOVEMENT_STEP / sqrt(2.0f)),
            arrayOf(MOUSE_POINTER_MOVEMENT_STEP / sqrt(2.0f)))
        verifyRelativeEvents(arrayOf(-MouseKeysInterceptor.MOUSE_POINTER_MOVEMENT_STEP / sqrt(2.0f)),
            arrayOf(MouseKeysInterceptor.MOUSE_POINTER_MOVEMENT_STEP / sqrt(2.0f)))
    }

    @Test
@@ -232,7 +231,8 @@ class MouseKeysInterceptorTest {
        testLooper.dispatchAll()

        // Verify the sendScrollEvent method is called once and capture the arguments
        verifyScrollEvents(arrayOf<Float>(0f), arrayOf<Float>(1.0f))
        verifyScrollEvents(arrayOf<Float>(0f),
	    arrayOf<Float>(MouseKeysInterceptor.MOUSE_SCROLL_STEP))
    }

    @Test
@@ -247,7 +247,8 @@ class MouseKeysInterceptorTest {
        testLooper.dispatchAll()

        // Verify the sendRelativeEvent method is called once and capture the arguments
        verifyRelativeEvents(arrayOf<Float>(0f), arrayOf<Float>(-MOUSE_POINTER_MOVEMENT_STEP))
        verifyRelativeEvents(arrayOf<Float>(0f),
	    arrayOf<Float>(-MouseKeysInterceptor.MOUSE_POINTER_MOVEMENT_STEP))
    }

    private fun verifyRelativeEvents(expectedX: Array<Float>, expectedY: Array<Float>) {