Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 1a25e57a authored by Harry Cutts's avatar Harry Cutts Committed by Android (Google) Code Review
Browse files

Merge "InputVerifier: verify button events and states (attempt 2)" into main

parents c95ea817 26640c99
Loading
Loading
Loading
Loading
+2 −0
Original line number Diff line number Diff line
@@ -849,6 +849,7 @@ enum {
 * Refer to the documentation on the MotionEvent class for descriptions of each button.
 */
enum {
    // LINT.IfChange(AMOTION_EVENT_BUTTON)
    /** primary */
    AMOTION_EVENT_BUTTON_PRIMARY = 1 << 0,
    /** secondary */
@@ -861,6 +862,7 @@ enum {
    AMOTION_EVENT_BUTTON_FORWARD = 1 << 4,
    AMOTION_EVENT_BUTTON_STYLUS_PRIMARY = 1 << 5,
    AMOTION_EVENT_BUTTON_STYLUS_SECONDARY = 1 << 6,
    // LINT.ThenChange(/frameworks/native/libs/input/rust/input.rs)
};

/**
+3 −2
Original line number Diff line number Diff line
@@ -47,9 +47,10 @@ public:
    InputVerifier(const std::string& name);

    android::base::Result<void> processMovement(int32_t 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);

    void resetDevice(int32_t deviceId);

+7 −0
Original line number Diff line number Diff line
@@ -133,6 +133,13 @@ rust_bindgen {
        "--allowlist-var=AMOTION_EVENT_ACTION_POINTER_DOWN",
        "--allowlist-var=AMOTION_EVENT_ACTION_POINTER_INDEX_SHIFT",
        "--allowlist-var=AMOTION_EVENT_ACTION_UP",
        "--allowlist-var=AMOTION_EVENT_BUTTON_BACK",
        "--allowlist-var=AMOTION_EVENT_BUTTON_FORWARD",
        "--allowlist-var=AMOTION_EVENT_BUTTON_PRIMARY",
        "--allowlist-var=AMOTION_EVENT_BUTTON_SECONDARY",
        "--allowlist-var=AMOTION_EVENT_BUTTON_STYLUS_PRIMARY",
        "--allowlist-var=AMOTION_EVENT_BUTTON_STYLUS_SECONDARY",
        "--allowlist-var=AMOTION_EVENT_BUTTON_TERTIARY",
        "--allowlist-var=MAX_POINTER_ID",
        "--verbose",
    ],
+3 −3
Original line number Diff line number Diff line
@@ -651,9 +651,9 @@ status_t InputPublisher::publishMotionEvent(
    const status_t status = mChannel->sendMessage(&msg);

    if (status == OK && verifyEvents()) {
        Result<void> result =
                mInputVerifier.processMovement(deviceId, source, action, pointerCount,
                                               pointerProperties, pointerCoords, flags);
        Result<void> result = mInputVerifier.processMovement(deviceId, source, action, actionButton,
                                                             pointerCount, pointerProperties,
                                                             pointerCoords, flags, buttonState);
        if (!result.ok()) {
            LOG(ERROR) << "Bad stream: " << result.error();
            return BAD_VALUE;
+13 −4
Original line number Diff line number Diff line
@@ -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 android::input::RustPointerProperties;

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 @@ Result<void> InputVerifier::processMovement(DeviceId deviceId, int32_t source, i
    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 {
Loading