Skip to content

Commit 3b66f20

Browse files
authored
Don't drop MotionEvents with unknown tool type. (flutter#5931)
Instead, send them with the new unknown PointerDeviceKind. We hit this when running `adb shell input tap` in tests which sends events with an unknown tool type. This also fills in a missing conversion for TOOL_TYPE_ERASER.
1 parent 391ac2f commit 3b66f20

File tree

2 files changed

+7
-4
lines changed

2 files changed

+7
-4
lines changed

lib/ui/pointer.dart

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,9 @@ enum PointerDeviceKind {
4949

5050
/// A pointer device with a stylus that has been inverted.
5151
invertedStylus,
52+
53+
/// An unknown pointer device.
54+
unknown
5255
}
5356

5457
/// Information about the state of a pointer.

shell/platform/android/io/flutter/view/FlutterView.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -382,6 +382,7 @@ public InputConnection onCreateInputConnection(EditorInfo outAttrs) {
382382
private static final int kPointerDeviceKindMouse = 1;
383383
private static final int kPointerDeviceKindStylus = 2;
384384
private static final int kPointerDeviceKindInvertedStylus = 3;
385+
private static final int kPointerDeviceKindUnknown = 4;
385386

386387
private int getPointerChangeForAction(int maskedAction) {
387388
// Primary pointer:
@@ -416,9 +417,11 @@ private int getPointerDeviceTypeForToolType(int toolType) {
416417
return kPointerDeviceKindStylus;
417418
case MotionEvent.TOOL_TYPE_MOUSE:
418419
return kPointerDeviceKindMouse;
420+
case MotionEvent.TOOL_TYPE_ERASER:
421+
return kPointerDeviceKindInvertedStylus;
419422
default:
420423
// MotionEvent.TOOL_TYPE_UNKNOWN will reach here.
421-
return -1;
424+
return kPointerDeviceKindUnknown;
422425
}
423426
}
424427

@@ -429,9 +432,6 @@ private void addPointerForIndex(MotionEvent event, int pointerIndex, ByteBuffer
429432
}
430433

431434
int pointerKind = getPointerDeviceTypeForToolType(event.getToolType(pointerIndex));
432-
if (pointerKind == -1) {
433-
return;
434-
}
435435

436436
long timeStamp = event.getEventTime() * 1000; // Convert from milliseconds to microseconds.
437437

0 commit comments

Comments
 (0)