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

Commit 2d151ac3 authored by Siarhei Vishniakou's avatar Siarhei Vishniakou
Browse files

InputVerifier: only check pointer sources

Check for the source inside InputVerifier. Sources like MOUSE_RELATIVE
could send ACTION_MOVE events without a prior DOWN event. Verifying such
streams is tricky, so let's simply skip such events for now.

Also in this CL, add some verifications to the number of pointers inside
the event.

Bug: 211379801
Test: enable event verification and run native tests
Test: atest inputflinger_tests libinput_tests
Change-Id: I3703ba57af7ede77712b91b7429ac46c0624a616
parent a22dbac7
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
@@ -46,7 +46,7 @@ class InputVerifier {
public:
    InputVerifier(const std::string& name);

    android::base::Result<void> processMovement(int32_t deviceId, int32_t action,
    android::base::Result<void> processMovement(int32_t deviceId, int32_t source, int32_t action,
                                                uint32_t pointerCount,
                                                const PointerProperties* pointerProperties,
                                                const PointerCoords* pointerCoords, int32_t flags);
+22 −0
Original line number Diff line number Diff line
@@ -90,6 +90,28 @@ rust_bindgen {
        "--allowlist-var=AMOTION_EVENT_ACTION_DOWN",
        "--allowlist-var=AMOTION_EVENT_ACTION_POINTER_INDEX_SHIFT",
        "--allowlist-var=MAX_POINTER_ID",
        "--allowlist-var=AINPUT_SOURCE_CLASS_NONE",
        "--allowlist-var=AINPUT_SOURCE_CLASS_BUTTON",
        "--allowlist-var=AINPUT_SOURCE_CLASS_POINTER",
        "--allowlist-var=AINPUT_SOURCE_CLASS_NAVIGATION",
        "--allowlist-var=AINPUT_SOURCE_CLASS_POSITION",
        "--allowlist-var=AINPUT_SOURCE_CLASS_JOYSTICK",
        "--allowlist-var=AINPUT_SOURCE_UNKNOWN",
        "--allowlist-var=AINPUT_SOURCE_KEYBOARD",
        "--allowlist-var=AINPUT_SOURCE_DPAD",
        "--allowlist-var=AINPUT_SOURCE_GAMEPAD",
        "--allowlist-var=AINPUT_SOURCE_TOUCHSCREEN",
        "--allowlist-var=AINPUT_SOURCE_MOUSE",
        "--allowlist-var=AINPUT_SOURCE_STYLUS",
        "--allowlist-var=AINPUT_SOURCE_BLUETOOTH_STYLUS",
        "--allowlist-var=AINPUT_SOURCE_TRACKBALL",
        "--allowlist-var=AINPUT_SOURCE_MOUSE_RELATIVE",
        "--allowlist-var=AINPUT_SOURCE_TOUCHPAD",
        "--allowlist-var=AINPUT_SOURCE_TOUCH_NAVIGATION",
        "--allowlist-var=AINPUT_SOURCE_JOYSTICK",
        "--allowlist-var=AINPUT_SOURCE_HDMI",
        "--allowlist-var=AINPUT_SOURCE_SENSOR",
        "--allowlist-var=AINPUT_SOURCE_ROTARY_ENCODER",
    ],

    static_libs: [
+2 −2
Original line number Diff line number Diff line
@@ -632,8 +632,8 @@ status_t InputPublisher::publishMotionEvent(
                                MotionEvent::actionToString(action).c_str()));
    if (verifyEvents()) {
        Result<void> result =
                mInputVerifier.processMovement(deviceId, action, pointerCount, pointerProperties,
                                               pointerCoords, flags);
                mInputVerifier.processMovement(deviceId, source, action, pointerCount,
                                               pointerProperties, pointerCoords, flags);
        if (!result.ok()) {
            LOG(FATAL) << "Bad stream: " << result.error();
        }
+3 −3
Original line number Diff line number Diff line
@@ -33,7 +33,7 @@ namespace android {
InputVerifier::InputVerifier(const std::string& name)
      : mVerifier(android::input::verifier::create(rust::String::lossy(name))){};

Result<void> InputVerifier::processMovement(DeviceId deviceId, int32_t action,
Result<void> InputVerifier::processMovement(DeviceId deviceId, int32_t source, int32_t action,
                                            uint32_t pointerCount,
                                            const PointerProperties* pointerProperties,
                                            const PointerCoords* pointerCoords, int32_t flags) {
@@ -43,8 +43,8 @@ Result<void> InputVerifier::processMovement(DeviceId deviceId, int32_t action,
    }
    rust::Slice<const RustPointerProperties> properties{rpp.data(), rpp.size()};
    rust::String errorMessage =
            android::input::verifier::process_movement(*mVerifier, deviceId, action, properties,
                                                       static_cast<uint32_t>(flags));
            android::input::verifier::process_movement(*mVerifier, deviceId, source, action,
                                                       properties, static_cast<uint32_t>(flags));
    if (errorMessage.empty()) {
        return {};
    } else {
+56 −0
Original line number Diff line number Diff line
@@ -23,6 +23,54 @@ use std::fmt;
#[derive(Debug, Copy, Clone, Eq, PartialEq, Ord, PartialOrd, Hash)]
pub struct DeviceId(pub i32);

#[repr(u32)]
pub enum SourceClass {
    None = input_bindgen::AINPUT_SOURCE_CLASS_NONE,
    Button = input_bindgen::AINPUT_SOURCE_CLASS_BUTTON,
    Pointer = input_bindgen::AINPUT_SOURCE_CLASS_POINTER,
    Navigation = input_bindgen::AINPUT_SOURCE_CLASS_NAVIGATION,
    Position = input_bindgen::AINPUT_SOURCE_CLASS_POSITION,
    Joystick = input_bindgen::AINPUT_SOURCE_CLASS_JOYSTICK,
}

bitflags! {
    /// Source of the input device or input events.
    pub struct Source: u32 {
        /// SOURCE_UNKNOWN
        const Unknown = input_bindgen::AINPUT_SOURCE_UNKNOWN;
        /// SOURCE_KEYBOARD
        const Keyboard = input_bindgen::AINPUT_SOURCE_KEYBOARD;
        /// SOURCE_DPAD
        const Dpad = input_bindgen::AINPUT_SOURCE_DPAD;
        /// SOURCE_GAMEPAD
        const Gamepad = input_bindgen::AINPUT_SOURCE_GAMEPAD;
        /// SOURCE_TOUCHSCREEN
        const Touchscreen = input_bindgen::AINPUT_SOURCE_TOUCHSCREEN;
        /// SOURCE_MOUSE
        const Mouse = input_bindgen::AINPUT_SOURCE_MOUSE;
        /// SOURCE_STYLUS
        const Stylus = input_bindgen::AINPUT_SOURCE_STYLUS;
        /// SOURCE_BLUETOOTH_STYLUS
        const BluetoothStylus = input_bindgen::AINPUT_SOURCE_BLUETOOTH_STYLUS;
        /// SOURCE_TRACKBALL
        const Trackball = input_bindgen::AINPUT_SOURCE_TRACKBALL;
        /// SOURCE_MOUSE_RELATIVE
        const MouseRelative = input_bindgen::AINPUT_SOURCE_MOUSE_RELATIVE;
        /// SOURCE_TOUCHPAD
        const Touchpad = input_bindgen::AINPUT_SOURCE_TOUCHPAD;
        /// SOURCE_TOUCH_NAVIGATION
        const TouchNavigation = input_bindgen::AINPUT_SOURCE_TOUCH_NAVIGATION;
        /// SOURCE_JOYSTICK
        const Joystick = input_bindgen::AINPUT_SOURCE_JOYSTICK;
        /// SOURCE_HDMI
        const HDMI = input_bindgen::AINPUT_SOURCE_HDMI;
        /// SOURCE_SENSOR
        const Sensor = input_bindgen::AINPUT_SOURCE_SENSOR;
        /// SOURCE_ROTARY_ENCODER
        const RotaryEncoder = input_bindgen::AINPUT_SOURCE_ROTARY_ENCODER;
    }
}

/// A rust enum representation of a MotionEvent action.
#[repr(u32)]
pub enum MotionAction {
@@ -134,3 +182,11 @@ bitflags! {
        const NO_FOCUS_CHANGE = input_bindgen::AMOTION_EVENT_FLAG_NO_FOCUS_CHANGE;
    }
}

impl Source {
    /// Return true if this source is from the provided class
    pub fn is_from_class(&self, source_class: SourceClass) -> bool {
        let class_bits = source_class as u32;
        self.bits() & class_bits == class_bits
    }
}
Loading