From dcc6e6ede741905fa2ec2ff91722f85d3979276c Mon Sep 17 00:00:00 2001 From: Siarhei Vishniakou Date: Wed, 18 Oct 2023 09:20:07 -0700 Subject: Change isStylusEvent behaviour This function is now getting moved to Input.h. We are also making its behaviour deterministic: if at least one pointer is stylus, then the event is a stylus event (unless the source wasn't set to "stylus"). This way, an event with 1 finger and 1 stylus pointers will have the same consistent behaviour, regardless of the order that the pointers are stored inside the event. Bug: 211379801 Test: TEST=inputflinger_tests; m $TEST && $ANDROID_HOST_OUT/nativetest64/$TEST/$TEST Change-Id: Ie164e32b7c0e9cf21b3819b01a03ac2885666191 --- libs/input/Input.cpp | 13 +++++++++++++ 1 file changed, 13 insertions(+) (limited to 'libs/input/Input.cpp') diff --git a/libs/input/Input.cpp b/libs/input/Input.cpp index c1274110d3..bd5b67b1d0 100644 --- a/libs/input/Input.cpp +++ b/libs/input/Input.cpp @@ -217,6 +217,19 @@ bool isStylusToolType(ToolType toolType) { return toolType == ToolType::STYLUS || toolType == ToolType::ERASER; } +bool isStylusEvent(uint32_t source, const std::vector& properties) { + if (!isFromSource(source, AINPUT_SOURCE_STYLUS)) { + return false; + } + // Need at least one stylus pointer for this event to be considered a stylus event + for (const PointerProperties& pointerProperties : properties) { + if (isStylusToolType(pointerProperties.toolType)) { + return true; + } + } + return false; +} + VerifiedKeyEvent verifiedKeyEventFromKeyEvent(const KeyEvent& event) { return {{VerifiedInputEvent::Type::KEY, event.getDeviceId(), event.getEventTime(), event.getSource(), event.getDisplayId()}, -- cgit v1.2.3-59-g8ed1b