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

Commit 5a71e885 authored by Vaibhav Devmurari's avatar Vaibhav Devmurari
Browse files

hasKeycode API should take into account key remapping

Keyboards can generate certain keycodes even if the keys are not
present in the device HID descriptor, by using key remapping APIs

Test: atest ModifierKeyRemappingTest
Bug: 368397939
Flag: EXEMPT bugfix
Change-Id: I30afda89f289eddc2b05fb124555aebfb182852e
parent 9623dd50
Loading
Loading
Loading
Loading
+3 −0
Original line number Diff line number Diff line
@@ -137,6 +137,9 @@ public:
    /* Returns keycode after applying Android key code remapping defined in mKeyRemapping */
    int32_t applyKeyRemapping(int32_t fromKeyCode) const;

    /** Returns list of keycodes that remap to provided keycode (@see setKeyRemapping()) */
    std::vector<int32_t> findKeyCodesMappedToKeyCode(int32_t toKeyCode) const;

    /* Returns the <keyCode, metaState> pair after applying key behavior defined in the kcm file,
     * that tries to find a replacement key code based on current meta state */
    std::pair<int32_t /*keyCode*/, int32_t /*metaState*/> applyKeyBehavior(int32_t keyCode,
+11 −0
Original line number Diff line number Diff line
@@ -365,6 +365,17 @@ int32_t KeyCharacterMap::applyKeyRemapping(int32_t fromKeyCode) const {
    return toKeyCode;
}

std::vector<int32_t> KeyCharacterMap::findKeyCodesMappedToKeyCode(int32_t toKeyCode) const {
    std::vector<int32_t> fromKeyCodes;

    for (const auto& [from, to] : mKeyRemapping) {
        if (toKeyCode == to) {
            fromKeyCodes.push_back(from);
        }
    }
    return fromKeyCodes;
}

std::pair<int32_t, int32_t> KeyCharacterMap::applyKeyBehavior(int32_t fromKeyCode,
                                                              int32_t fromMetaState) const {
    int32_t toKeyCode = fromKeyCode;
+13 −1
Original line number Diff line number Diff line
@@ -659,6 +659,19 @@ void EventHub::Device::populateAbsoluteAxisStates() {
}

bool EventHub::Device::hasKeycodeLocked(int keycode) const {
    if (hasKeycodeInternalLocked(keycode)) {
        return true;
    }

    for (auto& fromKey : getKeyCharacterMap()->findKeyCodesMappedToKeyCode(keycode)) {
        if (hasKeycodeInternalLocked(fromKey)) {
            return true;
        }
    }
    return false;
}

bool EventHub::Device::hasKeycodeInternalLocked(int keycode) const {
    if (!keyMap.haveKeyLayout()) {
        return false;
    }
@@ -676,7 +689,6 @@ bool EventHub::Device::hasKeycodeLocked(int keycode) const {
    if (usageCodes.size() > 0 && mscBitmask.test(MSC_SCAN)) {
        return true;
    }

    return false;
}

+1 −0
Original line number Diff line number Diff line
@@ -680,6 +680,7 @@ private:
        void configureFd();
        void populateAbsoluteAxisStates();
        bool hasKeycodeLocked(int keycode) const;
        bool hasKeycodeInternalLocked(int keycode) const;
        void loadConfigurationLocked();
        bool loadVirtualKeyMapLocked();
        status_t loadKeyMapLocked();