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

Commit 1030142f authored by Prabir Pradhan's avatar Prabir Pradhan
Browse files

Move absolute axis validation from EventHub to InputDevice

We recently added a crash when a we receive a misconfigured event froma
device. However, it seems like our critera for determining if an
absolute axis is correctly configured has issues.

In this case, we ignore an axis if its min and max value are equal.
Since the min and max are inclusive, it's perfectly valid for them to be
equal. As long as evdev is reporting valid events, EventHub should
continue to track and report them.

Deeming axes with min and max values that are equal is an artificial
constraint we have placed in InputReader historically. To maintain that
same constraint as before, we move the validation to InputDevice.

Bug: 293156873
Test: Presubmit
Change-Id: Id7c841f2d06668536a1b61c0e9e5250c15aad550
parent 2556d724
Loading
Loading
Loading
Loading
+16 −10
Original line number Diff line number Diff line
@@ -643,9 +643,6 @@ void EventHub::Device::populateAbsoluteAxisStates() {
                  identifier.name.c_str(), fd, strerror(errno));
            continue;
        }
        if (info.minimum == info.maximum) {
            continue;
        }
        auto& [axisInfo, value] = absState[axis];
        axisInfo.valid = true;
        axisInfo.minValue = info.minimum;
@@ -778,26 +775,35 @@ void EventHub::Device::trackInputEvent(const struct input_event& event) {
            LOG_ALWAYS_FATAL_IF(!currentFrameDropped &&
                                        !keyState.set(static_cast<size_t>(event.code),
                                                      event.value != 0),
                                "%s: received invalid EV_KEY event code: %s", __func__,
                                "%s: device '%s' received invalid EV_KEY event code: %s value: %d",
                                __func__, identifier.name.c_str(),
                                InputEventLookup::getLinuxEvdevLabel(EV_KEY, event.code, 1)
                                        .code.c_str());
                                        .code.c_str(),
                                event.value);
            break;
        }
        case EV_SW: {
            LOG_ALWAYS_FATAL_IF(!currentFrameDropped &&
                                        !swState.set(static_cast<size_t>(event.code),
                                                     event.value != 0),
                                "%s: received invalid EV_SW event code: %s", __func__,
                                "%s: device '%s' received invalid EV_SW event code: %s value: %d",
                                __func__, identifier.name.c_str(),
                                InputEventLookup::getLinuxEvdevLabel(EV_SW, event.code, 1)
                                        .code.c_str());
                                        .code.c_str(),
                                event.value);
            break;
        }
        case EV_ABS: {
            if (currentFrameDropped) {
                break;
            }
            auto it = absState.find(event.code);
            LOG_ALWAYS_FATAL_IF(!currentFrameDropped && it == absState.end(),
                                "%s: received invalid EV_ABS event code: %s", __func__,
            LOG_ALWAYS_FATAL_IF(it == absState.end(),
                                "%s: device '%s' received invalid EV_ABS event code: %s value: %d",
                                __func__, identifier.name.c_str(),
                                InputEventLookup::getLinuxEvdevLabel(EV_ABS, event.code, 0)
                                        .code.c_str());
                                        .code.c_str(),
                                event.value);
            it->second.value = event.value;
            break;
        }
+12 −1
Original line number Diff line number Diff line
@@ -289,7 +289,18 @@ public:
        return mEventHub->getDeviceControllerNumber(mId);
    }
    inline status_t getAbsoluteAxisInfo(int32_t code, RawAbsoluteAxisInfo* axisInfo) const {
        return mEventHub->getAbsoluteAxisInfo(mId, code, axisInfo);
        if (const auto status = mEventHub->getAbsoluteAxisInfo(mId, code, axisInfo); status != OK) {
            return status;
        }

        // Validate axis info for InputDevice.
        if (axisInfo->valid && axisInfo->minValue == axisInfo->maxValue) {
            // Historically, we deem axes with the same min and max values as invalid to avoid
            // dividing by zero when scaling by max - min.
            // TODO(b/291772515): Perform axis info validation on a per-axis basis when it is used.
            axisInfo->valid = false;
        }
        return OK;
    }
    inline bool hasRelativeAxis(int32_t code) const {
        return mEventHub->hasRelativeAxis(mId, code);