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

Commit e2502506 authored by Treehugger Robot's avatar Treehugger Robot Committed by Android (Google) Code Review
Browse files

Merge "Disabled two-finger dragging on TouchpadDebugView" into main

parents 6ced56d5 841b68bb
Loading
Loading
Loading
Loading
+4 −0
Original line number Diff line number Diff line
@@ -180,6 +180,10 @@ public class TouchpadDebugView extends LinearLayout {

    @Override
    public boolean onTouchEvent(MotionEvent event) {
        if (event.getClassification() == MotionEvent.CLASSIFICATION_TWO_FINGER_SWIPE) {
            return false;
        }

        float deltaX;
        float deltaY;
        switch (event.getAction()) {
+42 −2
Original line number Diff line number Diff line
@@ -16,6 +16,7 @@

package com.android.server.input.debug;

import static android.view.InputDevice.SOURCE_MOUSE;
import static android.view.InputDevice.SOURCE_TOUCHSCREEN;

import static org.junit.Assert.assertEquals;
@@ -92,7 +93,7 @@ public class TouchpadDebugViewTest {

        InputDevice inputDevice = new InputDevice.Builder()
                .setId(TOUCHPAD_DEVICE_ID)
                .setSources(InputDevice.SOURCE_TOUCHPAD | InputDevice.SOURCE_MOUSE)
                .setSources(InputDevice.SOURCE_TOUCHPAD | SOURCE_MOUSE)
                .setName("Test Device " + TOUCHPAD_DEVICE_ID)
                .build();

@@ -354,4 +355,43 @@ public class TouchpadDebugViewTest {
        mTouchpadDebugView.updateGestureInfo(gestureType, TOUCHPAD_DEVICE_ID);
        assertEquals(child.getText().toString(), TouchpadDebugView.getGestureText(gestureType));
    }

    @Test
    public void testTwoFingerDrag() {
        float offsetX = ViewConfiguration.get(mTestableContext).getScaledTouchSlop() + 10;
        float offsetY = ViewConfiguration.get(mTestableContext).getScaledTouchSlop() + 10;

        // Simulate ACTION_DOWN event (gesture starts).
        MotionEvent actionDown = new MotionEventBuilder(MotionEvent.ACTION_DOWN, SOURCE_MOUSE)
                .pointer(new PointerBuilder(0, MotionEvent.TOOL_TYPE_FINGER)
                        .x(40f)
                        .y(40f)
                )
                .classification(MotionEvent.CLASSIFICATION_TWO_FINGER_SWIPE)
                .build();
        mTouchpadDebugView.dispatchTouchEvent(actionDown);

        // Simulate ACTION_MOVE event (dragging with two fingers, processed as one pointer).
        MotionEvent actionMove = new MotionEventBuilder(MotionEvent.ACTION_MOVE, SOURCE_MOUSE)
                .pointer(new PointerBuilder(0, MotionEvent.TOOL_TYPE_FINGER)
                        .x(40f + offsetX)
                        .y(40f + offsetY)
                )
                .classification(MotionEvent.CLASSIFICATION_TWO_FINGER_SWIPE)
                .build();
        mTouchpadDebugView.dispatchTouchEvent(actionMove);

        // Simulate ACTION_UP event (gesture ends).
        MotionEvent actionUp = new MotionEventBuilder(MotionEvent.ACTION_UP, SOURCE_MOUSE)
                .pointer(new PointerBuilder(0, MotionEvent.TOOL_TYPE_FINGER)
                        .x(40f + offsetX)
                        .y(40f + offsetY)
                )
                .classification(MotionEvent.CLASSIFICATION_TWO_FINGER_SWIPE)
                .build();
        mTouchpadDebugView.dispatchTouchEvent(actionUp);

        // Verify that no updateViewLayout is called (as expected for a two-finger drag gesture).
        verify(mWindowManager, times(0)).updateViewLayout(any(), any());
    }
}
 No newline at end of file