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

Commit cb40a00d authored by Arthur Hung's avatar Arthur Hung
Browse files

Fix toggleCapsLock failed for multiple EventHub devices

If a physical device includes multiple EventHub devices for different
funcions, it would also create multiple InputMappers to process raw
events. And it may contain multiple KeyboardInputMapper.

When 'toggleCapsLock' called, we have to check if device has the meta
state key such as CAPS_LOCK or NUMS_LOCK, then we should just update the
the first InputMapper that own the meta state key to prevent other
InputMapper update the global state multiple times.

Bug: 195405545
Test: atest inputflinger_tests
Test: shortcut key META-ALT
Change-Id: I9d09e13d1de416370b8570b6621db5c4bf1ba8eb
parent 4fb3da09
Loading
Loading
Loading
Loading
+9 −0
Original line number Diff line number Diff line
@@ -1209,6 +1209,15 @@ bool EventHub::hasScanCode(int32_t deviceId, int32_t scanCode) const {
    return false;
}

bool EventHub::hasKeyCode(int32_t deviceId, int32_t keyCode) const {
    std::scoped_lock _l(mLock);
    Device* device = getDeviceLocked(deviceId);
    if (device != nullptr) {
        return device->hasKeycodeLocked(keyCode);
    }
    return false;
}

bool EventHub::hasLed(int32_t deviceId, int32_t led) const {
    std::scoped_lock _l(mLock);
    Device* device = getDeviceLocked(deviceId);
+7 −1
Original line number Diff line number Diff line
@@ -559,7 +559,13 @@ int32_t InputDevice::getMetaState() {
}

void InputDevice::updateMetaState(int32_t keyCode) {
    for_each_mapper([keyCode](InputMapper& mapper) { mapper.updateMetaState(keyCode); });
    first_in_mappers<bool>([keyCode](InputMapper& mapper) {
        if (sourcesMatchMask(mapper.getSources(), AINPUT_SOURCE_KEYBOARD) &&
            mapper.updateMetaState(keyCode)) {
            return std::make_optional(true);
        }
        return std::optional<bool>();
    });
}

void InputDevice::bumpGeneration() {
+1 −0
Original line number Diff line number Diff line
@@ -555,6 +555,7 @@ void InputReader::toggleCapsLockState(int32_t deviceId) {
    }

    if (device->isIgnored()) {
        ALOGW("Ignoring toggleCapsLock for ignored deviceId %" PRId32 ".", deviceId);
        return;
    }

+2 −0
Original line number Diff line number Diff line
@@ -312,6 +312,7 @@ public:
                                       uint8_t* outFlags) const = 0;

    virtual bool hasScanCode(int32_t deviceId, int32_t scanCode) const = 0;
    virtual bool hasKeyCode(int32_t deviceId, int32_t keyCode) const = 0;

    /* LED related functions expect Android LED constants, not scan codes or HID usages */
    virtual bool hasLed(int32_t deviceId, int32_t led) const = 0;
@@ -489,6 +490,7 @@ public:
    std::vector<TouchVideoFrame> getVideoFrames(int32_t deviceId) override final;

    bool hasScanCode(int32_t deviceId, int32_t scanCode) const override final;
    bool hasKeyCode(int32_t deviceId, int32_t keyCode) const override final;
    bool hasLed(int32_t deviceId, int32_t led) const override final;
    void setLedState(int32_t deviceId, int32_t led, bool on) override final;

+1 −0
Original line number Diff line number Diff line
@@ -323,6 +323,7 @@ public:
    inline bool hasScanCode(int32_t scanCode) const {
        return mEventHub->hasScanCode(mId, scanCode);
    }
    inline bool hasKeyCode(int32_t keyCode) const { return mEventHub->hasKeyCode(mId, keyCode); }
    inline bool hasLed(int32_t led) const { return mEventHub->hasLed(mId, led); }
    inline void setLedState(int32_t led, bool on) { return mEventHub->setLedState(mId, led, on); }
    inline void getVirtualKeyDefinitions(std::vector<VirtualKeyDefinition>& outVirtualKeys) const {
Loading