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

Commit 612231d2 authored by Siarhei Vishniakou's avatar Siarhei Vishniakou Committed by Android (Google) Code Review
Browse files

Merge "Add verifyInputEvent api to InputDispatcher"

parents 5f0ae0e0 54d3e189
Loading
Loading
Loading
Loading
+62 −0
Original line number Diff line number Diff line
@@ -73,6 +73,19 @@ enum {
    AMOTION_EVENT_FLAG_TAINTED = 0x80000000,
};

/**
 * Allowed VerifiedKeyEvent flags. All other flags from KeyEvent do not get verified.
 * These values must be kept in sync with VerifiedKeyEvent.java
 */
constexpr int32_t VERIFIED_KEY_EVENT_FLAGS = AKEY_EVENT_FLAG_CANCELED;

/**
 * Allowed VerifiedMotionEventFlags. All other flags from MotionEvent do not get verified.
 * These values must be kept in sync with VerifiedMotionEvent.java
 */
constexpr int32_t VERIFIED_MOTION_EVENT_FLAGS =
        AMOTION_EVENT_FLAG_WINDOW_IS_OBSCURED | AMOTION_EVENT_FLAG_WINDOW_IS_PARTIALLY_OBSCURED;

enum {
    /* Used when a motion event is not associated with any display.
     * Typically used for non-pointer events. */
@@ -718,6 +731,55 @@ protected:
    bool mInTouchMode;
};

/**
 * Base class for verified events.
 * Do not create a VerifiedInputEvent explicitly.
 * Use helper functions to create them from InputEvents.
 */
struct __attribute__((__packed__)) VerifiedInputEvent {
    enum class Type : int32_t {
        KEY = AINPUT_EVENT_TYPE_KEY,
        MOTION = AINPUT_EVENT_TYPE_MOTION,
    };

    Type type;
    int32_t deviceId;
    nsecs_t eventTimeNanos;
    uint32_t source;
    int32_t displayId;
};

/**
 * Same as KeyEvent, but only contains the data that can be verified.
 * If you update this class, you must also update VerifiedKeyEvent.java
 */
struct __attribute__((__packed__)) VerifiedKeyEvent : public VerifiedInputEvent {
    int32_t action;
    nsecs_t downTimeNanos;
    int32_t flags;
    int32_t keyCode;
    int32_t scanCode;
    int32_t metaState;
    int32_t repeatCount;
};

/**
 * Same as MotionEvent, but only contains the data that can be verified.
 * If you update this class, you must also update VerifiedMotionEvent.java
 */
struct __attribute__((__packed__)) VerifiedMotionEvent : public VerifiedInputEvent {
    float rawX;
    float rawY;
    int32_t actionMasked;
    nsecs_t downTimeNanos;
    int32_t flags;
    int32_t metaState;
    int32_t buttonState;
};

VerifiedKeyEvent verifiedKeyEventFromKeyEvent(const KeyEvent& event);
VerifiedMotionEvent verifiedMotionEventFromMotionEvent(const MotionEvent& event);

/*
 * Input event factory.
 */
+24 −0
Original line number Diff line number Diff line
@@ -57,6 +57,30 @@ const char* inputEventTypeToString(int32_t type) {
    return "UNKNOWN";
}

VerifiedKeyEvent verifiedKeyEventFromKeyEvent(const KeyEvent& event) {
    return {{VerifiedInputEvent::Type::KEY, event.getDeviceId(), event.getEventTime(),
             event.getSource(), event.getDisplayId()},
            event.getAction(),
            event.getDownTime(),
            event.getFlags() & VERIFIED_KEY_EVENT_FLAGS,
            event.getKeyCode(),
            event.getScanCode(),
            event.getMetaState(),
            event.getRepeatCount()};
}

VerifiedMotionEvent verifiedMotionEventFromMotionEvent(const MotionEvent& event) {
    return {{VerifiedInputEvent::Type::MOTION, event.getDeviceId(), event.getEventTime(),
             event.getSource(), event.getDisplayId()},
            event.getRawX(0),
            event.getRawY(0),
            event.getActionMasked(),
            event.getDownTime(),
            event.getFlags() & VERIFIED_MOTION_EVENT_FLAGS,
            event.getMetaState(),
            event.getButtonState()};
}

void InputEvent::initialize(int32_t deviceId, uint32_t source, int32_t displayId,
                            std::array<uint8_t, 32> hmac) {
    mDeviceId = deviceId;
+1 −1
Original line number Diff line number Diff line
@@ -10,12 +10,12 @@ cc_test {
        "LatencyStatistics_test.cpp",
        "TouchVideoFrame_test.cpp",
        "VelocityTracker_test.cpp",
        "VerifiedInputEvent_test.cpp",
    ],
    cflags: [
        "-Wall",
        "-Wextra",
        "-Werror",
        "-Wno-unused-variable",
    ],
    shared_libs: [
        "libinput",
+0 −1
Original line number Diff line number Diff line
@@ -46,7 +46,6 @@ TEST_F(PointerCoordsTest, ClearSetsBitsToZero) {
}

TEST_F(PointerCoordsTest, AxisValues) {
    float* valuePtr;
    PointerCoords coords;
    coords.clear();

+1 −0
Original line number Diff line number Diff line
@@ -38,6 +38,7 @@ protected:
    virtual void SetUp() {
        status_t result = InputChannel::openInputChannelPair("channel name",
                serverChannel, clientChannel);
        ASSERT_EQ(OK, result);

        mPublisher = new InputPublisher(serverChannel);
        mConsumer = new InputConsumer(clientChannel);
Loading