From 32e24c2fb5b94b65f1d495a398eae3504d4f9e4e Mon Sep 17 00:00:00 2001 From: Amir Hardon Date: Thu, 2 Aug 2018 15:39:35 -0700 Subject: [PATCH] Don't drop MotionEvents with unknown tool type. 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. --- lib/ui/pointer.dart | 3 +++ shell/platform/android/io/flutter/view/FlutterView.java | 8 ++++---- 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/lib/ui/pointer.dart b/lib/ui/pointer.dart index 77eda837e47b6..98a4f92385e95 100644 --- a/lib/ui/pointer.dart +++ b/lib/ui/pointer.dart @@ -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. diff --git a/shell/platform/android/io/flutter/view/FlutterView.java b/shell/platform/android/io/flutter/view/FlutterView.java index 808c58a01b4da..dcd0eec65fc5e 100644 --- a/shell/platform/android/io/flutter/view/FlutterView.java +++ b/shell/platform/android/io/flutter/view/FlutterView.java @@ -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: @@ -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; } } @@ -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.