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

Commit 146fac19 authored by Zixuan Qu's avatar Zixuan Qu Committed by Android (Google) Code Review
Browse files

Merge "Gets keyboard layout info from user space when available."

parents b8df0ef2 fecb6064
Loading
Loading
Loading
Loading
+16 −0
Original line number Diff line number Diff line
@@ -205,6 +205,16 @@ struct InputDeviceBatteryInfo {
    int32_t id;
};

struct KeyboardLayoutInfo {
    explicit KeyboardLayoutInfo(std::string languageTag, std::string layoutType)
          : languageTag(languageTag), layoutType(layoutType) {}

    // A BCP 47 conformant language tag such as "en-US".
    std::string languageTag;
    // The layout type such as QWERTY or AZERTY.
    std::string layoutType;
};

/*
 * Describes the characteristics and capabilities of an input device.
 */
@@ -256,6 +266,11 @@ public:
    void setKeyboardType(int32_t keyboardType);
    inline int32_t getKeyboardType() const { return mKeyboardType; }

    void setKeyboardLayoutInfo(KeyboardLayoutInfo keyboardLayoutInfo);
    inline const std::optional<KeyboardLayoutInfo>& getKeyboardLayoutInfo() const {
        return mKeyboardLayoutInfo;
    }

    inline void setKeyCharacterMap(const std::shared_ptr<KeyCharacterMap> value) {
        mKeyCharacterMap = value;
    }
@@ -296,6 +311,7 @@ private:
    bool mIsExternal;
    bool mHasMic;
    hardware::input::InputDeviceCountryCode mCountryCode;
    std::optional<KeyboardLayoutInfo> mKeyboardLayoutInfo;
    uint32_t mSources;
    int32_t mKeyboardType;
    std::shared_ptr<KeyCharacterMap> mKeyCharacterMap;
+5 −0
Original line number Diff line number Diff line
@@ -179,6 +179,7 @@ InputDeviceInfo::InputDeviceInfo(const InputDeviceInfo& other)
        mIsExternal(other.mIsExternal),
        mHasMic(other.mHasMic),
        mCountryCode(other.mCountryCode),
        mKeyboardLayoutInfo(other.mKeyboardLayoutInfo),
        mSources(other.mSources),
        mKeyboardType(other.mKeyboardType),
        mKeyCharacterMap(other.mKeyCharacterMap),
@@ -270,6 +271,10 @@ void InputDeviceInfo::setKeyboardType(int32_t keyboardType) {
    mKeyboardType = std::max(mKeyboardType, keyboardType);
}

void InputDeviceInfo::setKeyboardLayoutInfo(KeyboardLayoutInfo layoutInfo) {
    mKeyboardLayoutInfo = std::move(layoutInfo);
}

std::vector<InputDeviceSensorInfo> InputDeviceInfo::getSensors() {
    std::vector<InputDeviceSensorInfo> infos;
    infos.reserve(mSensors.size());
+8 −1
Original line number Diff line number Diff line
@@ -194,6 +194,9 @@ struct InputReaderConfiguration {
        // The device type has been updated.
        CHANGE_DEVICE_TYPE = 1 << 10,

        // The keyboard layout association has changed.
        CHANGE_KEYBOARD_LAYOUT_ASSOCIATION = 1 << 11,

        // All devices must be reopened.
        CHANGE_MUST_REOPEN = 1 << 31,
    };
@@ -211,7 +214,7 @@ struct InputReaderConfiguration {
    // Used to determine which DisplayViewport should be tied to which InputDevice.
    std::unordered_map<std::string, uint8_t> portAssociations;

    // The associations between input device names and display unique ids.
    // The associations between input device physical port locations and display unique ids.
    // Used to determine which DisplayViewport should be tied to which InputDevice.
    std::unordered_map<std::string, std::string> uniqueIdAssociations;

@@ -219,6 +222,10 @@ struct InputReaderConfiguration {
    // This is used to determine which device type and source should be tied to which InputDevice.
    std::unordered_map<std::string, std::string> deviceTypeAssociations;

    // The map from the input device physical port location to the input device layout info.
    // Can be used to determine the layout of the keyboard device.
    std::unordered_map<std::string, KeyboardLayoutInfo> keyboardLayoutAssociations;

    // The suggested display ID to show the cursor.
    int32_t defaultPointerDisplayId;

+0 −10
Original line number Diff line number Diff line
@@ -56,16 +56,6 @@ InputDevice::InputDevice(InputReaderContext* context, int32_t id, int32_t genera

InputDevice::~InputDevice() {}

template <typename K, typename V>
std::optional<V> getValueByKey(const std::unordered_map<K, V>& map, K key) {
    auto it = map.find(key);
    std::optional<V> value = std::nullopt;
    if (it != map.end()) {
        value = it->second;
    }
    return value;
}

bool InputDevice::isEnabled() {
    if (!hasEventHubDevices()) {
        return false;
+12 −0
Original line number Diff line number Diff line
@@ -22,6 +22,8 @@
#include <log/log.h>
#include <log/log_event_list.h>

#include <unordered_map>

namespace android {
/**
 * Log debug messages for each raw event received from the EventHub.
@@ -113,4 +115,14 @@ static inline bool sourcesMatchMask(uint32_t sources, uint32_t sourceMask) {
    return (sources & sourceMask & ~AINPUT_SOURCE_CLASS_MASK) != 0;
}

template <typename K, typename V>
static inline std::optional<V> getValueByKey(const std::unordered_map<K, V>& map, K key) {
    auto it = map.find(key);
    std::optional<V> value = std::nullopt;
    if (it != map.end()) {
        value = it->second;
    }
    return value;
}

} // namespace android
Loading