diff options
| author | 2024-09-18 18:43:25 +0000 | |
|---|---|---|
| committer | 2024-09-18 18:43:25 +0000 | |
| commit | e2502506d70a3b362a09ee2d48643537b01a692c (patch) | |
| tree | 899e1cd846912074b977a2e94a2b486b37e2651d | |
| parent | 6ced56d50907178d50ce3c768b15657e5fd910c7 (diff) | |
| parent | 841b68bbf14452c46cf82a066a51bdd5545af2a0 (diff) | |
Merge "Disabled two-finger dragging on TouchpadDebugView" into main
| -rw-r--r-- | services/core/java/com/android/server/input/debug/TouchpadDebugView.java | 4 | ||||
| -rw-r--r-- | tests/Input/src/com/android/server/input/debug/TouchpadDebugViewTest.java | 44 |
2 files changed, 46 insertions, 2 deletions
diff --git a/services/core/java/com/android/server/input/debug/TouchpadDebugView.java b/services/core/java/com/android/server/input/debug/TouchpadDebugView.java index 5ff8568f81b2..0e940d281b09 100644 --- a/services/core/java/com/android/server/input/debug/TouchpadDebugView.java +++ b/services/core/java/com/android/server/input/debug/TouchpadDebugView.java @@ -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()) { diff --git a/tests/Input/src/com/android/server/input/debug/TouchpadDebugViewTest.java b/tests/Input/src/com/android/server/input/debug/TouchpadDebugViewTest.java index eac2e9282714..b3a998ebca0d 100644 --- a/tests/Input/src/com/android/server/input/debug/TouchpadDebugViewTest.java +++ b/tests/Input/src/com/android/server/input/debug/TouchpadDebugViewTest.java @@ -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 |