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

Commit 16f90693 authored by Siarhei Vishniakou's avatar Siarhei Vishniakou
Browse files

Process EV_MSC MSC_TIMESTAMP in InputMapper

An evdev driver could report EV_MSC MSC_TIMESTAMP input event to relay
the number of microseconds since the last reset. This data could be
useful for keeping track of the specific kernel time of a particular
input_event. Propagate this data here to the InputDispatcher level,
but only for the MultiTouchInputMapper.

Bug: 62940136
Test: report MSC_TIMESTAMP in kernel driver on Pixel 2 XL device and
observe the data in the inputflinger layer using HeatMapDemo app.
Test: m -j inputflinger_tests_InputReader_test
inputflinger_tests_InputDispatcher_test && adb push
out/target/product/$TARGET_PRODUCT/data/nativetest64/*
/data/nativetest64/
then on device:  /data/nativetest64/inputflinger_tests # ./InputReader_test

Change-Id: Id990ec46a380e7f367020863fd86e4bae6ce47e4
parent cf6c68cd
Loading
Loading
Loading
Loading
+6 −3
Original line number Diff line number Diff line
@@ -69,13 +69,15 @@ void NotifyKeyArgs::notify(const sp<InputListenerInterface>& listener) const {
NotifyMotionArgs::NotifyMotionArgs(nsecs_t eventTime, int32_t deviceId, uint32_t source,
        uint32_t policyFlags,
        int32_t action, int32_t actionButton, int32_t flags, int32_t metaState,
        int32_t buttonState, int32_t edgeFlags, int32_t displayId, uint32_t pointerCount,
        int32_t buttonState, int32_t edgeFlags, int32_t displayId, uint32_t deviceTimestamp,
        uint32_t pointerCount,
        const PointerProperties* pointerProperties, const PointerCoords* pointerCoords,
        float xPrecision, float yPrecision, nsecs_t downTime) :
        eventTime(eventTime), deviceId(deviceId), source(source), policyFlags(policyFlags),
        action(action), actionButton(actionButton),
        flags(flags), metaState(metaState), buttonState(buttonState),
        edgeFlags(edgeFlags), displayId(displayId), pointerCount(pointerCount),
        edgeFlags(edgeFlags), displayId(displayId), deviceTimestamp(deviceTimestamp),
        pointerCount(pointerCount),
        xPrecision(xPrecision), yPrecision(yPrecision), downTime(downTime) {
    for (uint32_t i = 0; i < pointerCount; i++) {
        this->pointerProperties[i].copyFrom(pointerProperties[i]);
@@ -88,7 +90,8 @@ NotifyMotionArgs::NotifyMotionArgs(const NotifyMotionArgs& other) :
        policyFlags(other.policyFlags),
        action(other.action), actionButton(other.actionButton), flags(other.flags),
        metaState(other.metaState), buttonState(other.buttonState),
        edgeFlags(other.edgeFlags), displayId(other.displayId), pointerCount(other.pointerCount),
        edgeFlags(other.edgeFlags), displayId(other.displayId),
        deviceTimestamp(other.deviceTimestamp), pointerCount(other.pointerCount),
        xPrecision(other.xPrecision), yPrecision(other.yPrecision), downTime(other.downTime) {
    for (uint32_t i = 0; i < pointerCount; i++) {
        pointerProperties[i].copyFrom(other.pointerProperties[i]);
+8 −1
Original line number Diff line number Diff line
@@ -90,6 +90,13 @@ struct NotifyMotionArgs : public NotifyArgs {
    int32_t buttonState;
    int32_t edgeFlags;
    int32_t displayId;
    /**
     * A timestamp in the input device's time base, not the platform's.
     * The units are microseconds since the last reset.
     * This can only be compared to other device timestamps from the same device.
     * This value will overflow after a little over an hour.
     */
    uint32_t deviceTimestamp;
    uint32_t pointerCount;
    PointerProperties pointerProperties[MAX_POINTERS];
    PointerCoords pointerCoords[MAX_POINTERS];
@@ -102,7 +109,7 @@ struct NotifyMotionArgs : public NotifyArgs {
    NotifyMotionArgs(nsecs_t eventTime, int32_t deviceId, uint32_t source, uint32_t policyFlags,
            int32_t action, int32_t actionButton, int32_t flags,
            int32_t metaState, int32_t buttonState,
            int32_t edgeFlags, int32_t displayId, uint32_t pointerCount,
            int32_t edgeFlags, int32_t displayId, uint32_t deviceTimestamp, uint32_t pointerCount,
            const PointerProperties* pointerProperties, const PointerCoords* pointerCoords,
            float xPrecision, float yPrecision, nsecs_t downTime);

+41 −22

File changed.

Preview size limit exceeded, changes collapsed.

+9 −0
Original line number Diff line number Diff line
@@ -947,6 +947,7 @@ public:

    inline size_t getSlotCount() const { return mSlotCount; }
    inline const Slot* getSlot(size_t index) const { return &mSlots[index]; }
    inline uint32_t getDeviceTimestamp() const { return mDeviceTimestamp; }

private:
    int32_t mCurrentSlot;
@@ -954,6 +955,7 @@ private:
    size_t mSlotCount;
    bool mUsingSlotsProtocol;
    bool mHaveStylus;
    uint32_t mDeviceTimestamp;

    void clearSlots(int32_t initialSlot);
};
@@ -1396,6 +1398,7 @@ protected:

    struct RawState {
        nsecs_t when;
        uint32_t deviceTimestamp;

        // Raw pointer sample data.
        RawPointerData rawPointerData;
@@ -1408,6 +1411,7 @@ protected:

        void copyFrom(const RawState& other) {
            when = other.when;
            deviceTimestamp = other.deviceTimestamp;
            rawPointerData.copyFrom(other.rawPointerData);
            buttonState = other.buttonState;
            rawVScroll = other.rawVScroll;
@@ -1416,6 +1420,7 @@ protected:

        void clear() {
            when = 0;
            deviceTimestamp = 0;
            rawPointerData.clear();
            buttonState = 0;
            rawVScroll = 0;
@@ -1424,6 +1429,7 @@ protected:
    };

    struct CookedState {
        uint32_t deviceTimestamp;
        // Cooked pointer sample data.
        CookedPointerData cookedPointerData;

@@ -1435,6 +1441,7 @@ protected:
        int32_t buttonState;

        void copyFrom(const CookedState& other) {
            deviceTimestamp = other.deviceTimestamp;
            cookedPointerData.copyFrom(other.cookedPointerData);
            fingerIdBits = other.fingerIdBits;
            stylusIdBits = other.stylusIdBits;
@@ -1443,6 +1450,7 @@ protected:
        }

        void clear() {
            deviceTimestamp = 0;
            cookedPointerData.clear();
            fingerIdBits.clear();
            stylusIdBits.clear();
@@ -1837,6 +1845,7 @@ private:
    void dispatchMotion(nsecs_t when, uint32_t policyFlags, uint32_t source,
            int32_t action, int32_t actionButton,
            int32_t flags, int32_t metaState, int32_t buttonState, int32_t edgeFlags,
            uint32_t deviceTimestamp,
            const PointerProperties* properties, const PointerCoords* coords,
            const uint32_t* idToIndex, BitSet32 idBits,
            int32_t changedId, float xPrecision, float yPrecision, nsecs_t downTime);
+30 −0
Original line number Diff line number Diff line
@@ -4384,6 +4384,7 @@ protected:
    void processSlot(MultiTouchInputMapper* mapper, int32_t slot);
    void processToolType(MultiTouchInputMapper* mapper, int32_t toolType);
    void processKey(MultiTouchInputMapper* mapper, int32_t code, int32_t value);
    void processTimestamp(MultiTouchInputMapper* mapper, uint32_t value);
    void processMTSync(MultiTouchInputMapper* mapper);
    void processSync(MultiTouchInputMapper* mapper);
};
@@ -4499,6 +4500,10 @@ void MultiTouchInputMapperTest::processKey(
    process(mapper, ARBITRARY_TIME, DEVICE_ID, EV_KEY, code, value);
}

void MultiTouchInputMapperTest::processTimestamp(MultiTouchInputMapper* mapper, uint32_t value) {
    process(mapper, ARBITRARY_TIME, DEVICE_ID, EV_MSC, MSC_TIMESTAMP, value);
}

void MultiTouchInputMapperTest::processMTSync(MultiTouchInputMapper* mapper) {
    process(mapper, ARBITRARY_TIME, DEVICE_ID, EV_SYN, SYN_MT_REPORT, 0);
}
@@ -5881,5 +5886,30 @@ TEST_F(MultiTouchInputMapperTest, Process_WhenAbsMTPressureIsPresent_HoversIfIts
            toDisplayX(150), toDisplayY(250), 0, 0, 0, 0, 0, 0, 0, 0));
}

TEST_F(MultiTouchInputMapperTest, Process_HandlesTimestamp) {
    MultiTouchInputMapper* mapper = new MultiTouchInputMapper(mDevice);

    addConfigurationProperty("touch.deviceType", "touchScreen");
    prepareDisplay(DISPLAY_ORIENTATION_0);
    prepareAxes(POSITION);
    addMapperAndConfigure(mapper);
    NotifyMotionArgs args;

    // By default, deviceTimestamp should be zero
    processPosition(mapper, 100, 100);
    processMTSync(mapper);
    processSync(mapper);
    ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyMotionWasCalled(&args));
    ASSERT_EQ(0U, args.deviceTimestamp);

    // Now the timestamp of 1000 is reported by evdev and should appear in MotionArgs
    processPosition(mapper, 0, 0);
    processTimestamp(mapper, 1000);
    processMTSync(mapper);
    processSync(mapper);
    ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyMotionWasCalled(&args));
    ASSERT_EQ(1000U, args.deviceTimestamp);
}


} // namespace android