InputVerifier: verify button events and states (attempt 2)

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.

This is the second attempt to land this change, due to the original
causing test failures. Change I5c259c13d433d3010d2cf9c6fe01e08ba5990ef7
fixes the failures. v2 also adds a separate flag for button state
verification, as it is actually used in production to check events
injected by assistive technologies, whether or not the flag that I
previously thought was guarding it is enabled.

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: 392870542
Flag: com.android.input.flags.enable_button_state_verification
Change-Id: I46f489b26df8785563e41e58135b6b5de4ff62a2
diff --git a/libs/input/InputVerifier.cpp b/libs/input/InputVerifier.cpp
index cec2445..7811ace 100644
--- a/libs/input/InputVerifier.cpp
+++ b/libs/input/InputVerifier.cpp
@@ -17,6 +17,7 @@
 #define LOG_TAG "InputVerifier"
 
 #include <android-base/logging.h>
+#include <com_android_input_flags.h>
 #include <input/InputVerifier.h>
 #include "input_cxx_bridge.rs.h"
 
@@ -26,17 +27,23 @@
 
 using DeviceId = int32_t;
 
+namespace input_flags = com::android::input::flags;
+
 namespace android {
 
 // --- InputVerifier ---
 
 InputVerifier::InputVerifier(const std::string& name)
-      : mVerifier(android::input::verifier::create(rust::String::lossy(name))){};
+      : mVerifier(
+                android::input::verifier::create(rust::String::lossy(name),
+                                                 input_flags::enable_button_state_verification())) {
+}
 
 Result<void> 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<RustPointerProperties> rpp;
     for (size_t i = 0; i < pointerCount; i++) {
         rpp.emplace_back(RustPointerProperties{.id = pointerProperties[i].id});
@@ -44,7 +51,9 @@
     rust::Slice<const RustPointerProperties> properties{rpp.data(), rpp.size()};
     rust::String errorMessage =
             android::input::verifier::process_movement(*mVerifier, deviceId, source, action,
-                                                       properties, static_cast<uint32_t>(flags));
+                                                       actionButton, properties,
+                                                       static_cast<uint32_t>(flags),
+                                                       static_cast<uint32_t>(buttonState));
     if (errorMessage.empty()) {
         return {};
     } else {