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

Commit 3826d47f authored by Siarhei Vishniakou's avatar Siarhei Vishniakou
Browse files

Use uint32_t for input source

The input source type originates from EventHub as an unsigned integer.
But later, it somehow becomes a signed value.
Even the InputListeners specify the source as uint32_t. To maintain the
consistency prior to adding new API that would again use source, convert
the source to uint32_t.
This also helps remove some static_casts, as well as ensures that the
order of input arguments is harder to confuse.

Bug: 134977432
Test: atest libinput_tests inputflinger_tests inputflinger_benchmarks
Change-Id: Iba10da08ee3a1004d50827785f570dab72a919d1
parent 57c509e7
Loading
Loading
Loading
Loading
+7 −7
Original line number Diff line number Diff line
@@ -354,9 +354,9 @@ public:

    inline int32_t getDeviceId() const { return mDeviceId; }

    inline int32_t getSource() const { return mSource; }
    inline uint32_t getSource() const { return mSource; }

    inline void setSource(int32_t source) { mSource = source; }
    inline void setSource(uint32_t source) { mSource = source; }

    inline int32_t getDisplayId() const { return mDisplayId; }

@@ -365,12 +365,12 @@ public:
    inline std::array<uint8_t, 32> getHmac() const { return mHmac; }

protected:
    void initialize(int32_t deviceId, int32_t source, int32_t displayId,
    void initialize(int32_t deviceId, uint32_t source, int32_t displayId,
                    std::array<uint8_t, 32> hmac);
    void initialize(const InputEvent& from);

    int32_t mDeviceId;
    int32_t mSource;
    uint32_t mSource;
    int32_t mDisplayId;
    std::array<uint8_t, 32> mHmac;
};
@@ -405,7 +405,7 @@ public:
    static const char* getLabel(int32_t keyCode);
    static int32_t getKeyCodeFromLabel(const char* label);

    void initialize(int32_t deviceId, int32_t source, int32_t displayId,
    void initialize(int32_t deviceId, uint32_t source, int32_t displayId,
                    std::array<uint8_t, 32> hmac, int32_t action, int32_t flags, int32_t keyCode,
                    int32_t scanCode, int32_t metaState, int32_t repeatCount, nsecs_t downTime,
                    nsecs_t eventTime);
@@ -629,7 +629,7 @@ public:

    ssize_t findPointerIndex(int32_t pointerId) const;

    void initialize(int32_t deviceId, int32_t source, int32_t displayId,
    void initialize(int32_t deviceId, uint32_t source, int32_t displayId,
                    std::array<uint8_t, 32> hmac, int32_t action, int32_t actionButton,
                    int32_t flags, int32_t edgeFlags, int32_t metaState, int32_t buttonState,
                    MotionClassification classification, float xScale, float yScale, float xOffset,
@@ -657,7 +657,7 @@ public:
    status_t writeToParcel(Parcel* parcel) const;
#endif

    static bool isTouchEvent(int32_t source, int32_t action);
    static bool isTouchEvent(uint32_t source, int32_t action);
    inline bool isTouchEvent() const {
        return isTouchEvent(mSource, mAction);
    }
+6 −6
Original line number Diff line number Diff line
@@ -57,7 +57,7 @@ const char* inputEventTypeToString(int32_t type) {
    return "UNKNOWN";
}

void InputEvent::initialize(int32_t deviceId, int32_t source, int32_t displayId,
void InputEvent::initialize(int32_t deviceId, uint32_t source, int32_t displayId,
                            std::array<uint8_t, 32> hmac) {
    mDeviceId = deviceId;
    mSource = source;
@@ -82,7 +82,7 @@ int32_t KeyEvent::getKeyCodeFromLabel(const char* label) {
    return getKeyCodeByLabel(label);
}

void KeyEvent::initialize(int32_t deviceId, int32_t source, int32_t displayId,
void KeyEvent::initialize(int32_t deviceId, uint32_t source, int32_t displayId,
                          std::array<uint8_t, 32> hmac, int32_t action, int32_t flags,
                          int32_t keyCode, int32_t scanCode, int32_t metaState, int32_t repeatCount,
                          nsecs_t downTime, nsecs_t eventTime) {
@@ -245,7 +245,7 @@ void PointerProperties::copyFrom(const PointerProperties& other) {

// --- MotionEvent ---

void MotionEvent::initialize(int32_t deviceId, int32_t source, int32_t displayId,
void MotionEvent::initialize(int32_t deviceId, uint32_t source, int32_t displayId,
                             std::array<uint8_t, 32> hmac, int32_t action, int32_t actionButton,
                             int32_t flags, int32_t edgeFlags, int32_t metaState,
                             int32_t buttonState, MotionClassification classification, float xScale,
@@ -488,7 +488,7 @@ status_t MotionEvent::readFromParcel(Parcel* parcel) {
    }

    mDeviceId = parcel->readInt32();
    mSource = parcel->readInt32();
    mSource = parcel->readUint32();
    mDisplayId = parcel->readInt32();
    std::vector<uint8_t> hmac;
    status_t result = parcel->readByteVector(&hmac);
@@ -549,7 +549,7 @@ status_t MotionEvent::writeToParcel(Parcel* parcel) const {
    parcel->writeInt32(sampleCount);

    parcel->writeInt32(mDeviceId);
    parcel->writeInt32(mSource);
    parcel->writeUint32(mSource);
    parcel->writeInt32(mDisplayId);
    std::vector<uint8_t> hmac(mHmac.begin(), mHmac.end());
    parcel->writeByteVector(hmac);
@@ -590,7 +590,7 @@ status_t MotionEvent::writeToParcel(Parcel* parcel) const {
}
#endif

bool MotionEvent::isTouchEvent(int32_t source, int32_t action) {
bool MotionEvent::isTouchEvent(uint32_t source, int32_t action) {
    if (source & AINPUT_SOURCE_CLASS_POINTER) {
        // Specifically excludes HOVER_MOVE and SCROLL.
        switch (action & AMOTION_EVENT_ACTION_MASK) {
+4 −4
Original line number Diff line number Diff line
@@ -189,7 +189,7 @@ TEST_F(KeyEventTest, Properties) {

    ASSERT_EQ(AINPUT_EVENT_TYPE_KEY, event.getType());
    ASSERT_EQ(2, event.getDeviceId());
    ASSERT_EQ(static_cast<int>(AINPUT_SOURCE_GAMEPAD), event.getSource());
    ASSERT_EQ(AINPUT_SOURCE_GAMEPAD, event.getSource());
    ASSERT_EQ(DISPLAY_ID, event.getDisplayId());
    EXPECT_EQ(HMAC, event.getHmac());
    ASSERT_EQ(AKEY_EVENT_ACTION_DOWN, event.getAction());
@@ -203,7 +203,7 @@ TEST_F(KeyEventTest, Properties) {

    // Set source.
    event.setSource(AINPUT_SOURCE_JOYSTICK);
    ASSERT_EQ(static_cast<int>(AINPUT_SOURCE_JOYSTICK), event.getSource());
    ASSERT_EQ(AINPUT_SOURCE_JOYSTICK, event.getSource());

    // Set display id.
    constexpr int32_t newDisplayId = 2;
@@ -311,7 +311,7 @@ void MotionEventTest::assertEqualsEventWithHistory(const MotionEvent* event) {
    // Check properties.
    ASSERT_EQ(AINPUT_EVENT_TYPE_MOTION, event->getType());
    ASSERT_EQ(2, event->getDeviceId());
    ASSERT_EQ(static_cast<int>(AINPUT_SOURCE_TOUCHSCREEN), event->getSource());
    ASSERT_EQ(AINPUT_SOURCE_TOUCHSCREEN, event->getSource());
    ASSERT_EQ(DISPLAY_ID, event->getDisplayId());
    EXPECT_EQ(HMAC, event->getHmac());
    ASSERT_EQ(AMOTION_EVENT_ACTION_MOVE, event->getAction());
@@ -448,7 +448,7 @@ TEST_F(MotionEventTest, Properties) {

    // Set source.
    event.setSource(AINPUT_SOURCE_JOYSTICK);
    ASSERT_EQ(static_cast<int>(AINPUT_SOURCE_JOYSTICK), event.getSource());
    ASSERT_EQ(AINPUT_SOURCE_JOYSTICK, event.getSource());

    // Set displayId.
    constexpr int32_t newDisplayId = 2;
+2 −2
Original line number Diff line number Diff line
@@ -73,7 +73,7 @@ void InputPublisherAndConsumerTest::PublishAndConsumeKeyEvent() {

    constexpr uint32_t seq = 15;
    constexpr int32_t deviceId = 1;
    constexpr int32_t source = AINPUT_SOURCE_KEYBOARD;
    constexpr uint32_t source = AINPUT_SOURCE_KEYBOARD;
    constexpr int32_t displayId = ADISPLAY_ID_DEFAULT;
    constexpr std::array<uint8_t, 32> hmac = {31, 30, 29, 28, 27, 26, 25, 24, 23, 22, 21,
                                              20, 19, 18, 17, 16, 15, 14, 13, 12, 11, 10,
@@ -139,7 +139,7 @@ void InputPublisherAndConsumerTest::PublishAndConsumeMotionEvent() {

    constexpr uint32_t seq = 15;
    constexpr int32_t deviceId = 1;
    constexpr int32_t source = AINPUT_SOURCE_TOUCHSCREEN;
    constexpr uint32_t source = AINPUT_SOURCE_TOUCHSCREEN;
    constexpr int32_t displayId = ADISPLAY_ID_DEFAULT;
    constexpr std::array<uint8_t, 32> hmac = {0,  1,  2,  3,  4,  5,  6,  7,  8,  9,  10,
                                              11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21,