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

Commit 102936ef authored by Michael Wright's avatar Michael Wright
Browse files

Move KeyCharacterMap to enum class

Bug: 160010896
Test: compiles
Change-Id: Ia8c0d976665acf817f083726dcac10db0cd91048
parent dde67b89
Loading
Loading
Loading
Loading
+14 −14
Original line number Original line Diff line number Diff line
@@ -42,27 +42,27 @@ namespace android {
 */
 */
class KeyCharacterMap {
class KeyCharacterMap {
public:
public:
    enum KeyboardType {
    enum class KeyboardType : int32_t {
        KEYBOARD_TYPE_UNKNOWN = 0,
        UNKNOWN = 0,
        KEYBOARD_TYPE_NUMERIC = 1,
        NUMERIC = 1,
        KEYBOARD_TYPE_PREDICTIVE = 2,
        PREDICTIVE = 2,
        KEYBOARD_TYPE_ALPHA = 3,
        ALPHA = 3,
        KEYBOARD_TYPE_FULL = 4,
        FULL = 4,
        /**
        /**
         * Deprecated. Set 'keyboard.specialFunction' to '1' in the device's IDC file instead.
         * Deprecated. Set 'keyboard.specialFunction' to '1' in the device's IDC file instead.
         */
         */
        KEYBOARD_TYPE_SPECIAL_FUNCTION = 5,
        SPECIAL_FUNCTION = 5,
        KEYBOARD_TYPE_OVERLAY = 6,
        OVERLAY = 6,
    };
    };


    enum Format {
    enum class Format {
        // Base keyboard layout, may contain device-specific options, such as "type" declaration.
        // Base keyboard layout, may contain device-specific options, such as "type" declaration.
        FORMAT_BASE = 0,
        BASE = 0,
        // Overlay keyboard layout, more restrictive, may be published by applications,
        // Overlay keyboard layout, more restrictive, may be published by applications,
        // cannot override device-specific options.
        // cannot override device-specific options.
        FORMAT_OVERLAY = 1,
        OVERLAY = 1,
        // Either base or overlay layout ok.
        // Either base or overlay layout ok.
        FORMAT_ANY = 2,
        ANY = 2,
    };
    };


    // Substitute key code and meta state for fallback action.
    // Substitute key code and meta state for fallback action.
@@ -86,7 +86,7 @@ public:
    void combine(const KeyCharacterMap& overlay);
    void combine(const KeyCharacterMap& overlay);


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


    /* Gets the primary character for this key as in the label physically printed on it.
    /* Gets the primary character for this key as in the label physically printed on it.
     * Returns 0 if none (eg. for non-printing keys). */
     * Returns 0 if none (eg. for non-printing keys). */
@@ -222,7 +222,7 @@ private:
    };
    };


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


    KeyedVector<int32_t, int32_t> mKeysByScanCode;
    KeyedVector<int32_t, int32_t> mKeysByScanCode;
+16 −18
Original line number Original line Diff line number Diff line
@@ -83,9 +83,7 @@ static String8 toString(const char16_t* chars, size_t numChars) {


// --- KeyCharacterMap ---
// --- KeyCharacterMap ---


KeyCharacterMap::KeyCharacterMap() :
KeyCharacterMap::KeyCharacterMap() : mType(KeyboardType::UNKNOWN) {}
    mType(KEYBOARD_TYPE_UNKNOWN) {
}


KeyCharacterMap::KeyCharacterMap(const KeyCharacterMap& other)
KeyCharacterMap::KeyCharacterMap(const KeyCharacterMap& other)
      : mType(other.mType),
      : mType(other.mType),
@@ -184,7 +182,7 @@ void KeyCharacterMap::combine(const KeyCharacterMap& overlay) {
    mLoadFileName = overlay.mLoadFileName;
    mLoadFileName = overlay.mLoadFileName;
}
}


int32_t KeyCharacterMap::getKeyboardType() const {
KeyCharacterMap::KeyboardType KeyCharacterMap::getKeyboardType() const {
    return mType;
    return mType;
}
}


@@ -593,7 +591,7 @@ std::shared_ptr<KeyCharacterMap> KeyCharacterMap::readFromParcel(Parcel* parcel)
        return nullptr;
        return nullptr;
    }
    }
    std::shared_ptr<KeyCharacterMap> map = std::shared_ptr<KeyCharacterMap>(new KeyCharacterMap());
    std::shared_ptr<KeyCharacterMap> map = std::shared_ptr<KeyCharacterMap>(new KeyCharacterMap());
    map->mType = parcel->readInt32();
    map->mType = static_cast<KeyCharacterMap::KeyboardType>(parcel->readInt32());
    size_t numKeys = parcel->readInt32();
    size_t numKeys = parcel->readInt32();
    if (parcel->errorCheck()) {
    if (parcel->errorCheck()) {
        return nullptr;
        return nullptr;
@@ -651,7 +649,7 @@ void KeyCharacterMap::writeToParcel(Parcel* parcel) const {
        ALOGE("%s: Null parcel", __func__);
        ALOGE("%s: Null parcel", __func__);
        return;
        return;
    }
    }
    parcel->writeInt32(mType);
    parcel->writeInt32(static_cast<int32_t>(mType));


    size_t numKeys = mKeys.size();
    size_t numKeys = mKeys.size();
    parcel->writeInt32(numKeys);
    parcel->writeInt32(numKeys);
@@ -776,20 +774,20 @@ status_t KeyCharacterMap::Parser::parse() {
        return BAD_VALUE;
        return BAD_VALUE;
    }
    }


    if (mMap->mType == KEYBOARD_TYPE_UNKNOWN) {
    if (mMap->mType == KeyboardType::UNKNOWN) {
        ALOGE("%s: Keyboard layout missing required keyboard 'type' declaration.",
        ALOGE("%s: Keyboard layout missing required keyboard 'type' declaration.",
                mTokenizer->getLocation().string());
                mTokenizer->getLocation().string());
        return BAD_VALUE;
        return BAD_VALUE;
    }
    }


    if (mFormat == FORMAT_BASE) {
    if (mFormat == Format::BASE) {
        if (mMap->mType == KEYBOARD_TYPE_OVERLAY) {
        if (mMap->mType == KeyboardType::OVERLAY) {
            ALOGE("%s: Base keyboard layout must specify a keyboard 'type' other than 'OVERLAY'.",
            ALOGE("%s: Base keyboard layout must specify a keyboard 'type' other than 'OVERLAY'.",
                    mTokenizer->getLocation().string());
                    mTokenizer->getLocation().string());
            return BAD_VALUE;
            return BAD_VALUE;
        }
        }
    } else if (mFormat == FORMAT_OVERLAY) {
    } else if (mFormat == Format::OVERLAY) {
        if (mMap->mType != KEYBOARD_TYPE_OVERLAY) {
        if (mMap->mType != KeyboardType::OVERLAY) {
            ALOGE("%s: Overlay keyboard layout missing required keyboard "
            ALOGE("%s: Overlay keyboard layout missing required keyboard "
                    "'type OVERLAY' declaration.",
                    "'type OVERLAY' declaration.",
                    mTokenizer->getLocation().string());
                    mTokenizer->getLocation().string());
@@ -801,7 +799,7 @@ status_t KeyCharacterMap::Parser::parse() {
}
}


status_t KeyCharacterMap::Parser::parseType() {
status_t KeyCharacterMap::Parser::parseType() {
    if (mMap->mType != KEYBOARD_TYPE_UNKNOWN) {
    if (mMap->mType != KeyboardType::UNKNOWN) {
        ALOGE("%s: Duplicate keyboard 'type' declaration.",
        ALOGE("%s: Duplicate keyboard 'type' declaration.",
                mTokenizer->getLocation().string());
                mTokenizer->getLocation().string());
        return BAD_VALUE;
        return BAD_VALUE;
@@ -810,20 +808,20 @@ status_t KeyCharacterMap::Parser::parseType() {
    KeyboardType type;
    KeyboardType type;
    String8 typeToken = mTokenizer->nextToken(WHITESPACE);
    String8 typeToken = mTokenizer->nextToken(WHITESPACE);
    if (typeToken == "NUMERIC") {
    if (typeToken == "NUMERIC") {
        type = KEYBOARD_TYPE_NUMERIC;
        type = KeyboardType::NUMERIC;
    } else if (typeToken == "PREDICTIVE") {
    } else if (typeToken == "PREDICTIVE") {
        type = KEYBOARD_TYPE_PREDICTIVE;
        type = KeyboardType::PREDICTIVE;
    } else if (typeToken == "ALPHA") {
    } else if (typeToken == "ALPHA") {
        type = KEYBOARD_TYPE_ALPHA;
        type = KeyboardType::ALPHA;
    } else if (typeToken == "FULL") {
    } else if (typeToken == "FULL") {
        type = KEYBOARD_TYPE_FULL;
        type = KeyboardType::FULL;
    } else if (typeToken == "SPECIAL_FUNCTION") {
    } else if (typeToken == "SPECIAL_FUNCTION") {
        ALOGW("The SPECIAL_FUNCTION type is now declared in the device's IDC file, please set "
        ALOGW("The SPECIAL_FUNCTION type is now declared in the device's IDC file, please set "
                "the property 'keyboard.specialFunction' to '1' there instead.");
                "the property 'keyboard.specialFunction' to '1' there instead.");
        // TODO: return BAD_VALUE here in Q
        // TODO: return BAD_VALUE here in Q
        type = KEYBOARD_TYPE_SPECIAL_FUNCTION;
        type = KeyboardType::SPECIAL_FUNCTION;
    } else if (typeToken == "OVERLAY") {
    } else if (typeToken == "OVERLAY") {
        type = KEYBOARD_TYPE_OVERLAY;
        type = KeyboardType::OVERLAY;
    } else {
    } else {
        ALOGE("%s: Expected keyboard type label, got '%s'.", mTokenizer->getLocation().string(),
        ALOGE("%s: Expected keyboard type label, got '%s'.", mTokenizer->getLocation().string(),
                typeToken.string());
                typeToken.string());
+4 −4
Original line number Original line Diff line number Diff line
@@ -128,7 +128,7 @@ status_t KeyMap::loadKeyCharacterMap(const InputDeviceIdentifier& deviceIdentifi
    }
    }


    base::Result<std::shared_ptr<KeyCharacterMap>> ret =
    base::Result<std::shared_ptr<KeyCharacterMap>> ret =
            KeyCharacterMap::load(path, KeyCharacterMap::FORMAT_BASE);
            KeyCharacterMap::load(path, KeyCharacterMap::Format::BASE);
    if (!ret) {
    if (!ret) {
        return ret.error().code();
        return ret.error().code();
    }
    }
@@ -159,9 +159,9 @@ bool isKeyboardSpecialFunction(const PropertyMap* config) {
bool isEligibleBuiltInKeyboard(const InputDeviceIdentifier& deviceIdentifier,
bool isEligibleBuiltInKeyboard(const InputDeviceIdentifier& deviceIdentifier,
        const PropertyMap* deviceConfiguration, const KeyMap* keyMap) {
        const PropertyMap* deviceConfiguration, const KeyMap* keyMap) {
    // TODO: remove the third OR statement (SPECIAL_FUNCTION) in Q
    // TODO: remove the third OR statement (SPECIAL_FUNCTION) in Q
    if (!keyMap->haveKeyCharacterMap() || isKeyboardSpecialFunction(deviceConfiguration)
    if (!keyMap->haveKeyCharacterMap() || isKeyboardSpecialFunction(deviceConfiguration) ||
            || keyMap->keyCharacterMap->getKeyboardType()
        keyMap->keyCharacterMap->getKeyboardType() ==
                    == KeyCharacterMap::KEYBOARD_TYPE_SPECIAL_FUNCTION) {
                KeyCharacterMap::KeyboardType::SPECIAL_FUNCTION) {
        return false;
        return false;
    }
    }