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

Commit d6ae0d93 authored by TreeHugger Robot's avatar TreeHugger Robot Committed by Android (Google) Code Review
Browse files

Merge changes from topic "KeyCharacterMapRefactor"

* changes:
  Move KeyCharacterMap from RefBase to shared_ptr.
  Move KeyLayoutMap from RefBase to shared_ptr.
parents 87a07cbb 3a1e4468
Loading
Loading
Loading
Loading
+3 −3
Original line number Diff line number Diff line
@@ -108,11 +108,11 @@ public:
    inline void setKeyboardType(int32_t keyboardType) { mKeyboardType = keyboardType; }
    inline int32_t getKeyboardType() const { return mKeyboardType; }

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

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

@@ -136,7 +136,7 @@ private:
    bool mHasMic;
    uint32_t mSources;
    int32_t mKeyboardType;
    sp<KeyCharacterMap> mKeyCharacterMap;
    std::shared_ptr<KeyCharacterMap> mKeyCharacterMap;
    bool mHasVibrator;
    bool mHasButtonUnderPad;

+15 −16
Original line number Diff line number Diff line
@@ -23,12 +23,12 @@
#include <binder/IBinder.h>
#endif

#include <android-base/result.h>
#include <input/Input.h>
#include <utils/Errors.h>
#include <utils/KeyedVector.h>
#include <utils/Tokenizer.h>
#include <utils/Unicode.h>
#include <utils/RefBase.h>

// Maximum number of keys supported by KeyCharacterMaps
#define MAX_KEYS 8192
@@ -42,7 +42,7 @@ namespace android {
 *
 * This object is immutable after it has been loaded.
 */
class KeyCharacterMap : public RefBase {
class KeyCharacterMap {
public:
    enum KeyboardType {
        KEYBOARD_TYPE_UNKNOWN = 0,
@@ -74,18 +74,18 @@ public:
    };

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

    /* Loads a key character map from its string contents. */
    static status_t loadContents(const std::string& filename,
            const char* contents, Format format, sp<KeyCharacterMap>* outMap);
    static base::Result<std::shared_ptr<KeyCharacterMap>> loadContents(const std::string& filename,
                                                                       const char* contents,
                                                                       Format format);

    /* Combines a base key character map and an overlay. */
    static sp<KeyCharacterMap> combine(const sp<KeyCharacterMap>& base,
            const sp<KeyCharacterMap>& overlay);
    const std::string getLoadFileName() const;

    /* Returns an empty key character map. */
    static sp<KeyCharacterMap> empty();
    /* Combines this key character map with an overlay. */
    void combine(const KeyCharacterMap& overlay);

    /* Gets the keyboard type. */
    int32_t getKeyboardType() const;
@@ -136,13 +136,14 @@ public:

#ifdef __ANDROID__
    /* Reads a key map from a parcel. */
    static sp<KeyCharacterMap> readFromParcel(Parcel* parcel);
    static std::shared_ptr<KeyCharacterMap> readFromParcel(Parcel* parcel);

    /* Writes a key map to a parcel. */
    void writeToParcel(Parcel* parcel) const;
#endif

protected:
    KeyCharacterMap(const KeyCharacterMap& other);

    virtual ~KeyCharacterMap();

private:
@@ -224,16 +225,14 @@ private:
        status_t parseCharacterLiteral(char16_t* outCharacter);
    };

    static sp<KeyCharacterMap> sEmpty;

    KeyedVector<int32_t, Key*> mKeys;
    int mType;
    std::string mLoadFileName;

    KeyedVector<int32_t, int32_t> mKeysByScanCode;
    KeyedVector<int32_t, int32_t> mKeysByUsageCode;

    KeyCharacterMap();
    KeyCharacterMap(const KeyCharacterMap& other);

    bool getKey(int32_t keyCode, const Key** outKey) const;
    bool getKeyBehavior(int32_t keyCode, int32_t metaState,
@@ -242,7 +241,7 @@ private:

    bool findKey(char16_t ch, int32_t* outKeyCode, int32_t* outMetaState) const;

    static status_t load(Tokenizer* tokenizer, Format format, sp<KeyCharacterMap>* outMap);
    static base::Result<std::shared_ptr<KeyCharacterMap>> load(Tokenizer* tokenizer, Format format);

    static void addKey(Vector<KeyEvent>& outEvents,
            int32_t deviceId, int32_t keyCode, int32_t metaState, bool down, nsecs_t time);
+9 −4
Original line number Diff line number Diff line
@@ -17,11 +17,12 @@
#ifndef _LIBINPUT_KEY_LAYOUT_MAP_H
#define _LIBINPUT_KEY_LAYOUT_MAP_H

#include <android-base/result.h>
#include <stdint.h>
#include <utils/Errors.h>
#include <utils/KeyedVector.h>
#include <utils/Tokenizer.h>
#include <utils/RefBase.h>
#include <utils/Tokenizer.h>

namespace android {

@@ -60,9 +61,12 @@ struct AxisInfo {
 *
 * This object is immutable after it has been loaded.
 */
class KeyLayoutMap : public RefBase {
class KeyLayoutMap {
public:
    static status_t load(const std::string& filename, sp<KeyLayoutMap>* outMap);
    static base::Result<std::shared_ptr<KeyLayoutMap>> load(const std::string& filename);
    static base::Result<std::shared_ptr<KeyLayoutMap>> load(Tokenizer* tokenizer);
    static base::Result<std::shared_ptr<KeyLayoutMap>> loadContents(const std::string& filename,
                                                                    const char* contents);

    status_t mapKey(int32_t scanCode, int32_t usageCode,
            int32_t* outKeyCode, uint32_t* outFlags) const;
@@ -71,8 +75,8 @@ public:
    status_t findUsageCodeForLed(int32_t ledCode, int32_t* outUsageCode) const;

    status_t mapAxis(int32_t scanCode, AxisInfo* outAxisInfo) const;
    const std::string getLoadFileName() const;

protected:
    virtual ~KeyLayoutMap();

private:
@@ -91,6 +95,7 @@ private:
    KeyedVector<int32_t, AxisInfo> mAxes;
    KeyedVector<int32_t, Led> mLedsByScanCode;
    KeyedVector<int32_t, Led> mLedsByUsageCode;
    std::string mLoadFileName;

    KeyLayoutMap();

+2 −2
Original line number Diff line number Diff line
@@ -34,10 +34,10 @@ class KeyCharacterMap;
class KeyMap {
public:
    std::string keyLayoutFile;
    sp<KeyLayoutMap> keyLayoutMap;
    std::shared_ptr<KeyLayoutMap> keyLayoutMap;

    std::string keyCharacterMapFile;
    sp<KeyCharacterMap> keyCharacterMap;
    std::shared_ptr<KeyCharacterMap> keyCharacterMap;

    KeyMap();
    ~KeyMap();
+14 −8
Original line number Diff line number Diff line
@@ -153,14 +153,20 @@ InputDeviceInfo::InputDeviceInfo() {
    initialize(-1, 0, -1, InputDeviceIdentifier(), "", false, false);
}

InputDeviceInfo::InputDeviceInfo(const InputDeviceInfo& other) :
        mId(other.mId), mGeneration(other.mGeneration), mControllerNumber(other.mControllerNumber),
        mIdentifier(other.mIdentifier), mAlias(other.mAlias), mIsExternal(other.mIsExternal),
        mHasMic(other.mHasMic), mSources(other.mSources),
        mKeyboardType(other.mKeyboardType), mKeyCharacterMap(other.mKeyCharacterMap),
        mHasVibrator(other.mHasVibrator), mHasButtonUnderPad(other.mHasButtonUnderPad),
        mMotionRanges(other.mMotionRanges) {
}
InputDeviceInfo::InputDeviceInfo(const InputDeviceInfo& other)
      : mId(other.mId),
        mGeneration(other.mGeneration),
        mControllerNumber(other.mControllerNumber),
        mIdentifier(other.mIdentifier),
        mAlias(other.mAlias),
        mIsExternal(other.mIsExternal),
        mHasMic(other.mHasMic),
        mSources(other.mSources),
        mKeyboardType(other.mKeyboardType),
        mKeyCharacterMap(other.mKeyCharacterMap),
        mHasVibrator(other.mHasVibrator),
        mHasButtonUnderPad(other.mHasButtonUnderPad),
        mMotionRanges(other.mMotionRanges) {}

InputDeviceInfo::~InputDeviceInfo() {
}
Loading