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

Commit 3025c68b authored by Treehugger Robot's avatar Treehugger Robot Committed by Android (Google) Code Review
Browse files

Merge "Copy KeyCharacterMap object when we fill InputDeviceInfo(1/n)" into main

parents 120f056c d78dd9b1
Loading
Loading
Loading
Loading
+5 −6
Original line number Original line Diff line number Diff line
@@ -266,6 +266,7 @@ class InputDeviceInfo {
public:
public:
    InputDeviceInfo();
    InputDeviceInfo();
    InputDeviceInfo(const InputDeviceInfo& other);
    InputDeviceInfo(const InputDeviceInfo& other);
    InputDeviceInfo& operator=(const InputDeviceInfo& other);
    ~InputDeviceInfo();
    ~InputDeviceInfo();


    struct MotionRange {
    struct MotionRange {
@@ -315,13 +316,11 @@ public:


    inline const InputDeviceViewBehavior& getViewBehavior() const { return mViewBehavior; }
    inline const InputDeviceViewBehavior& getViewBehavior() const { return mViewBehavior; }


    inline void setKeyCharacterMap(const std::shared_ptr<KeyCharacterMap> value) {
    inline void setKeyCharacterMap(std::unique_ptr<KeyCharacterMap> value) {
        mKeyCharacterMap = value;
        mKeyCharacterMap = std::move(value);
    }
    }


    inline const std::shared_ptr<KeyCharacterMap> getKeyCharacterMap() const {
    inline const KeyCharacterMap* getKeyCharacterMap() const { return mKeyCharacterMap.get(); }
        return mKeyCharacterMap;
    }


    inline void setVibrator(bool hasVibrator) { mHasVibrator = hasVibrator; }
    inline void setVibrator(bool hasVibrator) { mHasVibrator = hasVibrator; }
    inline bool hasVibrator() const { return mHasVibrator; }
    inline bool hasVibrator() const { return mHasVibrator; }
@@ -364,7 +363,7 @@ private:
    std::optional<KeyboardLayoutInfo> mKeyboardLayoutInfo;
    std::optional<KeyboardLayoutInfo> mKeyboardLayoutInfo;
    uint32_t mSources;
    uint32_t mSources;
    int32_t mKeyboardType;
    int32_t mKeyboardType;
    std::shared_ptr<KeyCharacterMap> mKeyCharacterMap;
    std::unique_ptr<KeyCharacterMap> mKeyCharacterMap;
    std::optional<InputDeviceUsiVersion> mUsiVersion;
    std::optional<InputDeviceUsiVersion> mUsiVersion;
    ui::LogicalDisplayId mAssociatedDisplayId{ui::LogicalDisplayId::INVALID};
    ui::LogicalDisplayId mAssociatedDisplayId{ui::LogicalDisplayId::INVALID};
    bool mEnabled;
    bool mEnabled;
+1 −1
Original line number Original line Diff line number Diff line
@@ -72,7 +72,7 @@ public:
    };
    };


    /* Loads a key character map from a file. */
    /* Loads a key character map from a file. */
    static base::Result<std::shared_ptr<KeyCharacterMap>> load(const std::string& filename,
    static base::Result<std::unique_ptr<KeyCharacterMap>> load(const std::string& filename,
                                                               Format format);
                                                               Format format);


    /* Loads a key character map from its string contents. */
    /* Loads a key character map from its string contents. */
+31 −1
Original line number Original line Diff line number Diff line
@@ -191,7 +191,9 @@ InputDeviceInfo::InputDeviceInfo(const InputDeviceInfo& other)
        mKeyboardLayoutInfo(other.mKeyboardLayoutInfo),
        mKeyboardLayoutInfo(other.mKeyboardLayoutInfo),
        mSources(other.mSources),
        mSources(other.mSources),
        mKeyboardType(other.mKeyboardType),
        mKeyboardType(other.mKeyboardType),
        mKeyCharacterMap(other.mKeyCharacterMap),
        mKeyCharacterMap(other.mKeyCharacterMap
                                 ? std::make_unique<KeyCharacterMap>(*other.mKeyCharacterMap)
                                 : nullptr),
        mUsiVersion(other.mUsiVersion),
        mUsiVersion(other.mUsiVersion),
        mAssociatedDisplayId(other.mAssociatedDisplayId),
        mAssociatedDisplayId(other.mAssociatedDisplayId),
        mEnabled(other.mEnabled),
        mEnabled(other.mEnabled),
@@ -204,6 +206,34 @@ InputDeviceInfo::InputDeviceInfo(const InputDeviceInfo& other)
        mLights(other.mLights),
        mLights(other.mLights),
        mViewBehavior(other.mViewBehavior) {}
        mViewBehavior(other.mViewBehavior) {}


InputDeviceInfo& InputDeviceInfo::operator=(const InputDeviceInfo& other) {
    mId = other.mId;
    mGeneration = other.mGeneration;
    mControllerNumber = other.mControllerNumber;
    mIdentifier = other.mIdentifier;
    mAlias = other.mAlias;
    mIsExternal = other.mIsExternal;
    mHasMic = other.mHasMic;
    mKeyboardLayoutInfo = other.mKeyboardLayoutInfo;
    mSources = other.mSources;
    mKeyboardType = other.mKeyboardType;
    mKeyCharacterMap = other.mKeyCharacterMap
            ? std::make_unique<KeyCharacterMap>(*other.mKeyCharacterMap)
            : nullptr;
    mUsiVersion = other.mUsiVersion;
    mAssociatedDisplayId = other.mAssociatedDisplayId;
    mEnabled = other.mEnabled;
    mHasVibrator = other.mHasVibrator;
    mHasBattery = other.mHasBattery;
    mHasButtonUnderPad = other.mHasButtonUnderPad;
    mHasSensor = other.mHasSensor;
    mMotionRanges = other.mMotionRanges;
    mSensors = other.mSensors;
    mLights = other.mLights;
    mViewBehavior = other.mViewBehavior;
    return *this;
}

InputDeviceInfo::~InputDeviceInfo() {
InputDeviceInfo::~InputDeviceInfo() {
}
}


+3 −3
Original line number Original line Diff line number Diff line
@@ -84,15 +84,15 @@ static String8 toString(const char16_t* chars, size_t numChars) {


KeyCharacterMap::KeyCharacterMap(const std::string& filename) : mLoadFileName(filename) {}
KeyCharacterMap::KeyCharacterMap(const std::string& filename) : mLoadFileName(filename) {}


base::Result<std::shared_ptr<KeyCharacterMap>> KeyCharacterMap::load(const std::string& filename,
base::Result<std::unique_ptr<KeyCharacterMap>> KeyCharacterMap::load(const std::string& filename,
                                                                     Format format) {
                                                                     Format format) {
    Tokenizer* tokenizer;
    Tokenizer* tokenizer;
    status_t status = Tokenizer::open(String8(filename.c_str()), &tokenizer);
    status_t status = Tokenizer::open(String8(filename.c_str()), &tokenizer);
    if (status) {
    if (status) {
        return Errorf("Error {} opening key character map file {}.", status, filename.c_str());
        return Errorf("Error {} opening key character map file {}.", status, filename.c_str());
    }
    }
    std::shared_ptr<KeyCharacterMap> map =
    std::unique_ptr<KeyCharacterMap> map =
            std::shared_ptr<KeyCharacterMap>(new KeyCharacterMap(filename));
            std::unique_ptr<KeyCharacterMap>(new KeyCharacterMap(filename));
    if (!map.get()) {
    if (!map.get()) {
        ALOGE("Error allocating key character map.");
        ALOGE("Error allocating key character map.");
        return Errorf("Error allocating key character map.");
        return Errorf("Error allocating key character map.");
+3 −1
Original line number Original line Diff line number Diff line
@@ -132,7 +132,9 @@ std::optional<KeyboardLayoutInfo> KeyboardInputMapper::getKeyboardLayoutInfo() c
void KeyboardInputMapper::populateDeviceInfo(InputDeviceInfo& info) {
void KeyboardInputMapper::populateDeviceInfo(InputDeviceInfo& info) {
    InputMapper::populateDeviceInfo(info);
    InputMapper::populateDeviceInfo(info);


    info.setKeyCharacterMap(getDeviceContext().getKeyCharacterMap());
    if (const auto kcm = getDeviceContext().getKeyCharacterMap(); kcm != nullptr) {
        info.setKeyCharacterMap(std::make_unique<KeyCharacterMap>(*kcm));
    }


    std::optional keyboardLayoutInfo = getKeyboardLayoutInfo();
    std::optional keyboardLayoutInfo = getKeyboardLayoutInfo();
    if (keyboardLayoutInfo) {
    if (keyboardLayoutInfo) {