Skip to content

Commit

Permalink
Don't drop MotionEvents with unknown tool type. (flutter#5931)
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
amirh authored Aug 2, 2018
1 parent 391ac2f commit 3b66f20
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 4 deletions.
3 changes: 3 additions & 0 deletions lib/ui/pointer.dart
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,9 @@ enum PointerDeviceKind {

/// A pointer device with a stylus that has been inverted.
invertedStylus,

/// An unknown pointer device.
unknown
}

/// Information about the state of a pointer.
Expand Down
8 changes: 4 additions & 4 deletions shell/platform/android/io/flutter/view/FlutterView.java
Original file line number Diff line number Diff line change
Expand Up @@ -382,6 +382,7 @@ public InputConnection onCreateInputConnection(EditorInfo outAttrs) {
private static final int kPointerDeviceKindMouse = 1;
private static final int kPointerDeviceKindStylus = 2;
private static final int kPointerDeviceKindInvertedStylus = 3;
private static final int kPointerDeviceKindUnknown = 4;

private int getPointerChangeForAction(int maskedAction) {
// Primary pointer:
Expand Down Expand Up @@ -416,9 +417,11 @@ private int getPointerDeviceTypeForToolType(int toolType) {
return kPointerDeviceKindStylus;
case MotionEvent.TOOL_TYPE_MOUSE:
return kPointerDeviceKindMouse;
case MotionEvent.TOOL_TYPE_ERASER:
return kPointerDeviceKindInvertedStylus;
default:
// MotionEvent.TOOL_TYPE_UNKNOWN will reach here.
return -1;
return kPointerDeviceKindUnknown;
}
}

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

int pointerKind = getPointerDeviceTypeForToolType(event.getToolType(pointerIndex));
if (pointerKind == -1) {
return;
}

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

Expand Down

0 comments on commit 3b66f20

Please sign in to comment.