From fb477b1399b4501acdb2516b6a0a00765dd8aba3 Mon Sep 17 00:00:00 2001 From: Harry Cutts Date: Fri, 17 Jan 2025 15:06:56 +0000 Subject: InputVerifier: verify button events and states Check the following things: * BUTTON_PRESS and _RELEASE actions have a single, valid action button * No redundant BUTTON_PRESS or _RELEASE actions (i.e. for buttons that are already pressed or released) * Button state remains consistent throughout the stream, i.e.: * Buttons are only added to the state by BUTTON_PRESS (though DOWN events can have "pending" buttons on them) * Buttons are only removed from the state by BUTTON_RELEASE * When a DOWN event has pending buttons in its state, it is immediately followed by a BUTTON_PRESS for each one We could also verify that press and release events for primary, secondary, and tertiary buttons are accompanied by down and up events. However, I couldn't find any documentation that states which buttons should result in down or up events, so I haven't implemented this for now. Test: connect a mouse and a touchpad, enable the verifier, play around with the buttons, and check that any issues found by the verifier appear to be legitimate. (I found b/391298464, and checked that the verifier caught a button problem with a partial fix to b/372571823.) Test: atest --host libinput_rust_tests Test: atest --host frameworks/native/libs/input/tests/InputVerifier_test.cpp Test: atest --host \ frameworks/native/services/inputflinger/tests/InputDispatcher_test.cpp Bug: 372571823 Flag: com.android.input.flags.enable_inbound_event_verification Change-Id: I59b886bfb632f0f26ee58c40f82f447f5ea59b41 --- libs/input/InputVerifier.cpp | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) (limited to 'libs/input/InputVerifier.cpp') diff --git a/libs/input/InputVerifier.cpp b/libs/input/InputVerifier.cpp index cec244539e..e8d4c733bd 100644 --- a/libs/input/InputVerifier.cpp +++ b/libs/input/InputVerifier.cpp @@ -34,9 +34,10 @@ InputVerifier::InputVerifier(const std::string& name) : mVerifier(android::input::verifier::create(rust::String::lossy(name))){}; Result InputVerifier::processMovement(DeviceId deviceId, int32_t source, int32_t action, - uint32_t pointerCount, + int32_t actionButton, uint32_t pointerCount, const PointerProperties* pointerProperties, - const PointerCoords* pointerCoords, int32_t flags) { + const PointerCoords* pointerCoords, int32_t flags, + int32_t buttonState) { std::vector rpp; for (size_t i = 0; i < pointerCount; i++) { rpp.emplace_back(RustPointerProperties{.id = pointerProperties[i].id}); @@ -44,7 +45,9 @@ Result InputVerifier::processMovement(DeviceId deviceId, int32_t source, i rust::Slice properties{rpp.data(), rpp.size()}; rust::String errorMessage = android::input::verifier::process_movement(*mVerifier, deviceId, source, action, - properties, static_cast(flags)); + actionButton, properties, + static_cast(flags), + static_cast(buttonState)); if (errorMessage.empty()) { return {}; } else { -- cgit v1.2.3-59-g8ed1b