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

Commit 58ba3d15 authored by Siarhei Vishniakou's avatar Siarhei Vishniakou
Browse files

Pass RawEvent latency from InputReader to InputListener

To keep track of the lower-level latency like touch driver latency, keep
track of the time when eventhub reads the events.

This information will be stored inside RawEvent as it is being read.

Next, this information will be passed to the InputListener. The InputListener will
report this data to LatencyTracker, which will aggregate this
information in order to get end-to-end touch latency.

Different mappers process the input_event events differently. So a
mapper-specific approach is used here.

Bug: 169866723
Test: atest inputflinger_tests
Change-Id: I5e4e90b3251351327022c467af99a6d84f82164e
parent 55ee8750
Loading
Loading
Loading
Loading
+29 −24
Original line number Diff line number Diff line
@@ -50,9 +50,10 @@ void NotifyConfigurationChangedArgs::notify(const sp<InputListenerInterface>& li

// --- NotifyKeyArgs ---

NotifyKeyArgs::NotifyKeyArgs(int32_t id, nsecs_t eventTime, int32_t deviceId, uint32_t source,
                             int32_t displayId, uint32_t policyFlags, int32_t action, int32_t flags,
                             int32_t keyCode, int32_t scanCode, int32_t metaState, nsecs_t downTime)
NotifyKeyArgs::NotifyKeyArgs(int32_t id, nsecs_t eventTime, nsecs_t readTime, int32_t deviceId,
                             uint32_t source, int32_t displayId, uint32_t policyFlags,
                             int32_t action, int32_t flags, int32_t keyCode, int32_t scanCode,
                             int32_t metaState, nsecs_t downTime)
      : NotifyArgs(id, eventTime),
        deviceId(deviceId),
        source(source),
@@ -63,7 +64,8 @@ NotifyKeyArgs::NotifyKeyArgs(int32_t id, nsecs_t eventTime, int32_t deviceId, ui
        keyCode(keyCode),
        scanCode(scanCode),
        metaState(metaState),
        downTime(downTime) {}
        downTime(downTime),
        readTime(readTime) {}

NotifyKeyArgs::NotifyKeyArgs(const NotifyKeyArgs& other)
      : NotifyArgs(other.id, other.eventTime),
@@ -76,13 +78,15 @@ NotifyKeyArgs::NotifyKeyArgs(const NotifyKeyArgs& other)
        keyCode(other.keyCode),
        scanCode(other.scanCode),
        metaState(other.metaState),
        downTime(other.downTime) {}
        downTime(other.downTime),
        readTime(other.readTime) {}

bool NotifyKeyArgs::operator==(const NotifyKeyArgs& rhs) const {
    return id == rhs.id && eventTime == rhs.eventTime && deviceId == rhs.deviceId &&
            source == rhs.source && displayId == rhs.displayId && policyFlags == rhs.policyFlags &&
            action == rhs.action && flags == rhs.flags && keyCode == rhs.keyCode &&
            scanCode == rhs.scanCode && metaState == rhs.metaState && downTime == rhs.downTime;
    return id == rhs.id && eventTime == rhs.eventTime && readTime == rhs.readTime &&
            deviceId == rhs.deviceId && source == rhs.source && displayId == rhs.displayId &&
            policyFlags == rhs.policyFlags && action == rhs.action && flags == rhs.flags &&
            keyCode == rhs.keyCode && scanCode == rhs.scanCode && metaState == rhs.metaState &&
            downTime == rhs.downTime;
}

void NotifyKeyArgs::notify(const sp<InputListenerInterface>& listener) const {
@@ -91,15 +95,13 @@ void NotifyKeyArgs::notify(const sp<InputListenerInterface>& listener) const {

// --- NotifyMotionArgs ---

NotifyMotionArgs::NotifyMotionArgs(int32_t id, nsecs_t eventTime, int32_t deviceId, uint32_t source,
                                   int32_t displayId, uint32_t policyFlags, int32_t action,
                                   int32_t actionButton, int32_t flags, int32_t metaState,
                                   int32_t buttonState, MotionClassification classification,
                                   int32_t edgeFlags, uint32_t pointerCount,
                                   const PointerProperties* pointerProperties,
                                   const PointerCoords* pointerCoords, float xPrecision,
                                   float yPrecision, float xCursorPosition, float yCursorPosition,
                                   nsecs_t downTime,
NotifyMotionArgs::NotifyMotionArgs(
        int32_t id, nsecs_t eventTime, nsecs_t readTime, int32_t deviceId, uint32_t source,
        int32_t displayId, uint32_t policyFlags, int32_t action, int32_t actionButton,
        int32_t flags, int32_t metaState, int32_t buttonState, MotionClassification classification,
        int32_t edgeFlags, uint32_t pointerCount, const PointerProperties* pointerProperties,
        const PointerCoords* pointerCoords, float xPrecision, float yPrecision,
        float xCursorPosition, float yCursorPosition, nsecs_t downTime,
        const std::vector<TouchVideoFrame>& videoFrames)
      : NotifyArgs(id, eventTime),
        deviceId(deviceId),
@@ -119,6 +121,7 @@ NotifyMotionArgs::NotifyMotionArgs(int32_t id, nsecs_t eventTime, int32_t device
        xCursorPosition(xCursorPosition),
        yCursorPosition(yCursorPosition),
        downTime(downTime),
        readTime(readTime),
        videoFrames(videoFrames) {
    for (uint32_t i = 0; i < pointerCount; i++) {
        this->pointerProperties[i].copyFrom(pointerProperties[i]);
@@ -145,6 +148,7 @@ NotifyMotionArgs::NotifyMotionArgs(const NotifyMotionArgs& other)
        xCursorPosition(other.xCursorPosition),
        yCursorPosition(other.yCursorPosition),
        downTime(other.downTime),
        readTime(other.readTime),
        videoFrames(other.videoFrames) {
    for (uint32_t i = 0; i < pointerCount; i++) {
        pointerProperties[i].copyFrom(other.pointerProperties[i]);
@@ -157,11 +161,12 @@ static inline bool isCursorPositionEqual(float lhs, float rhs) {
}

bool NotifyMotionArgs::operator==(const NotifyMotionArgs& rhs) const {
    bool equal = id == rhs.id && eventTime == rhs.eventTime && deviceId == rhs.deviceId &&
            source == rhs.source && displayId == rhs.displayId && policyFlags == rhs.policyFlags &&
            action == rhs.action && actionButton == rhs.actionButton && flags == rhs.flags &&
            metaState == rhs.metaState && buttonState == rhs.buttonState &&
            classification == rhs.classification && edgeFlags == rhs.edgeFlags &&
    bool equal = id == rhs.id && eventTime == rhs.eventTime && readTime == rhs.readTime &&
            deviceId == rhs.deviceId && source == rhs.source && displayId == rhs.displayId &&
            policyFlags == rhs.policyFlags && action == rhs.action &&
            actionButton == rhs.actionButton && flags == rhs.flags && metaState == rhs.metaState &&
            buttonState == rhs.buttonState && classification == rhs.classification &&
            edgeFlags == rhs.edgeFlags &&
            pointerCount == rhs.pointerCount
            // PointerProperties and PointerCoords are compared separately below
            && xPrecision == rhs.xPrecision && yPrecision == rhs.yPrecision &&
+3 −2
Original line number Diff line number Diff line
@@ -249,8 +249,9 @@ static NotifyMotionArgs generateMotionArgs() {

    const nsecs_t currentTime = now();
    // Define a valid motion event.
    NotifyMotionArgs args(/* id */ 0, currentTime, DEVICE_ID, AINPUT_SOURCE_TOUCHSCREEN,
                          ADISPLAY_ID_DEFAULT, POLICY_FLAG_PASS_TO_USER, AMOTION_EVENT_ACTION_DOWN,
    NotifyMotionArgs args(/* id */ 0, currentTime, currentTime, DEVICE_ID,
                          AINPUT_SOURCE_TOUCHSCREEN, ADISPLAY_ID_DEFAULT, POLICY_FLAG_PASS_TO_USER,
                          AMOTION_EVENT_ACTION_DOWN,
                          /* actionButton */ 0, /* flags */ 0, AMETA_NONE, /* buttonState */ 0,
                          MotionClassification::NONE, AMOTION_EVENT_EDGE_FLAG_NONE, 1,
                          pointerProperties, pointerCoords,
+9 −6
Original line number Diff line number Diff line
@@ -73,12 +73,14 @@ struct NotifyKeyArgs : public NotifyArgs {
    int32_t scanCode;
    int32_t metaState;
    nsecs_t downTime;
    nsecs_t readTime;

    inline NotifyKeyArgs() { }

    NotifyKeyArgs(int32_t id, nsecs_t eventTime, int32_t deviceId, uint32_t source,
                  int32_t displayId, uint32_t policyFlags, int32_t action, int32_t flags,
                  int32_t keyCode, int32_t scanCode, int32_t metaState, nsecs_t downTime);
    NotifyKeyArgs(int32_t id, nsecs_t eventTime, nsecs_t readTime, int32_t deviceId,
                  uint32_t source, int32_t displayId, uint32_t policyFlags, int32_t action,
                  int32_t flags, int32_t keyCode, int32_t scanCode, int32_t metaState,
                  nsecs_t downTime);

    bool operator==(const NotifyKeyArgs& rhs) const;

@@ -120,13 +122,14 @@ struct NotifyMotionArgs : public NotifyArgs {
    float xCursorPosition;
    float yCursorPosition;
    nsecs_t downTime;
    nsecs_t readTime;
    std::vector<TouchVideoFrame> videoFrames;

    inline NotifyMotionArgs() { }

    NotifyMotionArgs(int32_t id, nsecs_t eventTime, int32_t deviceId, uint32_t source,
                     int32_t displayId, uint32_t policyFlags, int32_t action, int32_t actionButton,
                     int32_t flags, int32_t metaState, int32_t buttonState,
    NotifyMotionArgs(int32_t id, nsecs_t eventTime, nsecs_t readTime, int32_t deviceId,
                     uint32_t source, int32_t displayId, uint32_t policyFlags, int32_t action,
                     int32_t actionButton, int32_t flags, int32_t metaState, int32_t buttonState,
                     MotionClassification classification, int32_t edgeFlags, uint32_t pointerCount,
                     const PointerProperties* pointerProperties, const PointerCoords* pointerCoords,
                     float xPrecision, float yPrecision, float xCursorPosition,
+1 −0
Original line number Diff line number Diff line
@@ -1280,6 +1280,7 @@ size_t EventHub::getEvents(int timeoutMillis, RawEvent* buffer, size_t bufferSiz
                    for (size_t i = 0; i < count; i++) {
                        struct input_event& iev = readBuffer[i];
                        event->when = processEventTimestamp(iev);
                        event->readTime = systemTime(SYSTEM_TIME_MONOTONIC);
                        event->deviceId = deviceId;
                        event->type = iev.type;
                        event->code = iev.code;
+2 −2
Original line number Diff line number Diff line
@@ -492,8 +492,8 @@ void InputDevice::flushSensor(InputDeviceSensorType sensorType) {
    for_each_mapper([sensorType](InputMapper& mapper) { mapper.flushSensor(sensorType); });
}

void InputDevice::cancelTouch(nsecs_t when) {
    for_each_mapper([when](InputMapper& mapper) { mapper.cancelTouch(when); });
void InputDevice::cancelTouch(nsecs_t when, nsecs_t readTime) {
    for_each_mapper([when, readTime](InputMapper& mapper) { mapper.cancelTouch(when, readTime); });
}

std::optional<int32_t> InputDevice::getBatteryCapacity() {
Loading