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

Commit dec3080b authored by Vaibhav Devmurari's avatar Vaibhav Devmurari
Browse files

Pass layout info in native callback for quicker layout setup.

Passing language tag and layout type to getKeyboardLayoutOverlay()
callback allows us to setup keyboard layout before device creation
is complete. Hence when we get onInputDeviceAdded() is callback, the
layout is already set up.

Test: atest VirtualKeyboardLayoutTest
Bug: 271905768
Change-Id: I46a6e4b0f512beb4a560374feda4104ff32d27cc
parent de231db0
Loading
Loading
Loading
Loading
+2 −1
Original line number Diff line number Diff line
@@ -437,7 +437,8 @@ public:

    /* Gets the keyboard layout for a particular input device. */
    virtual std::shared_ptr<KeyCharacterMap> getKeyboardLayoutOverlay(
            const InputDeviceIdentifier& identifier) = 0;
            const InputDeviceIdentifier& identifier,
            const std::optional<KeyboardLayoutInfo> keyboardLayoutInfo) = 0;

    /* Gets a user-supplied alias for a particular input device, or an empty string if none. */
    virtual std::string getDeviceAlias(const InputDeviceIdentifier& identifier) = 0;
+0 −17
Original line number Diff line number Diff line
@@ -225,23 +225,6 @@ std::list<NotifyArgs> InputDevice::configure(nsecs_t when,
            mIsWaking = mConfiguration.getBool("device.wake").value_or(false);
        }

        if (!changes.any() || changes.test(Change::KEYBOARD_LAYOUTS)) {
            if (!mClasses.test(InputDeviceClass::VIRTUAL)) {
                std::shared_ptr<KeyCharacterMap> keyboardLayout =
                        mContext->getPolicy()->getKeyboardLayoutOverlay(mIdentifier);
                bool shouldBumpGeneration = false;
                for_each_subdevice(
                        [&keyboardLayout, &shouldBumpGeneration](InputDeviceContext& context) {
                            if (context.setKeyboardLayoutOverlay(keyboardLayout)) {
                                shouldBumpGeneration = true;
                            }
                        });
                if (shouldBumpGeneration) {
                    bumpGeneration();
                }
            }
        }

        if (!changes.any() || changes.test(Change::DEVICE_ALIAS)) {
            if (!(mClasses.test(InputDeviceClass::VIRTUAL))) {
                std::string alias = mContext->getPolicy()->getDeviceAlias(mIdentifier);
+32 −8
Original line number Diff line number Diff line
@@ -86,20 +86,26 @@ int32_t KeyboardInputMapper::getDisplayId() {
    return ADISPLAY_ID_NONE;
}

std::optional<KeyboardLayoutInfo> KeyboardInputMapper::getKeyboardLayoutInfo() const {
    if (mKeyboardLayoutInfo) {
        return mKeyboardLayoutInfo;
    }
    std::optional<RawLayoutInfo> layoutInfo = getDeviceContext().getRawLayoutInfo();
    if (!layoutInfo) {
        return std::nullopt;
    }
    return KeyboardLayoutInfo(layoutInfo->languageTag, layoutInfo->layoutType);
}

void KeyboardInputMapper::populateDeviceInfo(InputDeviceInfo& info) {
    InputMapper::populateDeviceInfo(info);

    info.setKeyboardType(mKeyboardType);
    info.setKeyCharacterMap(getDeviceContext().getKeyCharacterMap());

    if (mKeyboardLayoutInfo) {
        info.setKeyboardLayoutInfo(*mKeyboardLayoutInfo);
    } else {
        std::optional<RawLayoutInfo> layoutInfo = getDeviceContext().getRawLayoutInfo();
        if (layoutInfo) {
            info.setKeyboardLayoutInfo(
                    KeyboardLayoutInfo(layoutInfo->languageTag, layoutInfo->layoutType));
        }
    std::optional keyboardLayoutInfo = getKeyboardLayoutInfo();
    if (keyboardLayoutInfo) {
        info.setKeyboardLayoutInfo(*keyboardLayoutInfo);
    }
}

@@ -152,13 +158,31 @@ std::list<NotifyArgs> KeyboardInputMapper::reconfigure(nsecs_t when,
                getValueByKey(config.keyboardLayoutAssociations, getDeviceContext().getLocation());
        if (mKeyboardLayoutInfo != newKeyboardLayoutInfo) {
            mKeyboardLayoutInfo = newKeyboardLayoutInfo;
            // Also update keyboard layout overlay as soon as we find the new layout info
            updateKeyboardLayoutOverlay();
            bumpGeneration();
        }
    }

    if (!changes.any() || changes.test(InputReaderConfiguration::Change::KEYBOARD_LAYOUTS)) {
        if (!getDeviceContext().getDeviceClasses().test(InputDeviceClass::VIRTUAL) &&
            updateKeyboardLayoutOverlay()) {
            bumpGeneration();
        }
    }
    return out;
}

bool KeyboardInputMapper::updateKeyboardLayoutOverlay() {
    std::shared_ptr<KeyCharacterMap> keyboardLayout =
            getDeviceContext()
                    .getContext()
                    ->getPolicy()
                    ->getKeyboardLayoutOverlay(getDeviceContext().getDeviceIdentifier(),
                                               getKeyboardLayoutInfo());
    return getDeviceContext().setKeyboardLayoutOverlay(keyboardLayout);
}

void KeyboardInputMapper::configureParameters() {
    const PropertyMap& config = getDeviceContext().getConfiguration();
    mParameters.orientationAware = config.getBool("keyboard.orientationAware").value_or(false);
+2 −0
Original line number Diff line number Diff line
@@ -99,6 +99,8 @@ private:
    bool updateMetaStateIfNeeded(int32_t keyCode, bool down);

    std::optional<size_t> findKeyDownIndex(int32_t scanCode);
    std::optional<KeyboardLayoutInfo> getKeyboardLayoutInfo() const;
    bool updateKeyboardLayoutOverlay();

    void resetLedState();
    void initializeLedState(LedState& ledState, int32_t led);
+1 −1
Original line number Diff line number Diff line
@@ -227,7 +227,7 @@ void FakeInputReaderPolicy::notifyInputDevicesChanged(
}

std::shared_ptr<KeyCharacterMap> FakeInputReaderPolicy::getKeyboardLayoutOverlay(
        const InputDeviceIdentifier&) {
        const InputDeviceIdentifier&, const std::optional<KeyboardLayoutInfo>) {
    return nullptr;
}

Loading