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

Commit 23e8ae9c authored by Vaibhav Devmurari's avatar Vaibhav Devmurari
Browse files

Clear applied layout overlay if new layout overlay is null.

Need to allow resetting of key character map by setting overlay
map to null. This is required when moving from a IME setting
that has a KCM to another IME setting that has none.

Test: atest KeyboardLayoutChangeTest
Bug: 20805588
Change-Id: I62dc65970b61628486aff698a8ab8ccb31c109d6
parent 4079d69a
Loading
Loading
Loading
Loading
+3 −0
Original line number Diff line number Diff line
@@ -87,6 +87,9 @@ public:
    /* Combines this key character map with the provided overlay. */
    void combine(const KeyCharacterMap& overlay);

    /* Clears already applied layout overlay */
    void clearLayoutOverlay();

    /* Gets the keyboard type. */
    KeyboardType getKeyboardType() const;

+7 −0
Original line number Diff line number Diff line
@@ -255,6 +255,13 @@ void KeyCharacterMap::combine(const KeyCharacterMap& overlay) {
    mLayoutOverlayApplied = true;
}

void KeyCharacterMap::clearLayoutOverlay() {
    if (mLayoutOverlayApplied) {
        reloadBaseFromFile();
        mLayoutOverlayApplied = false;
    }
}

KeyCharacterMap::KeyboardType KeyCharacterMap::getKeyboardType() const {
    return mType;
}
+6 −1
Original line number Diff line number Diff line
@@ -1416,12 +1416,17 @@ const std::shared_ptr<KeyCharacterMap> EventHub::getKeyCharacterMap(int32_t devi
    return nullptr;
}

// If provided map is null, it will reset key character map to default KCM.
bool EventHub::setKeyboardLayoutOverlay(int32_t deviceId, std::shared_ptr<KeyCharacterMap> map) {
    std::scoped_lock _l(mLock);
    Device* device = getDeviceLocked(deviceId);
    if (device == nullptr || map == nullptr || device->keyMap.keyCharacterMap == nullptr) {
    if (device == nullptr || device->keyMap.keyCharacterMap == nullptr) {
        return false;
    }
    if (map == nullptr) {
        device->keyMap.keyCharacterMap->clearLayoutOverlay();
        return true;
    }
    device->keyMap.keyCharacterMap->combine(*map);
    return true;
}