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

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

Merge "Move KeyCharacterMap to enum class"

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

    enum Format {
    enum class Format {
        // 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,
        // cannot override device-specific options.
        FORMAT_OVERLAY = 1,
        OVERLAY = 1,
        // Either base or overlay layout ok.
        FORMAT_ANY = 2,
        ANY = 2,
    };

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

    /* 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.
     * Returns 0 if none (eg. for non-printing keys). */
@@ -222,7 +222,7 @@ private:
    };

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

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

// --- KeyCharacterMap ---

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

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

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

@@ -593,7 +591,7 @@ std::shared_ptr<KeyCharacterMap> KeyCharacterMap::readFromParcel(Parcel* parcel)
        return nullptr;
    }
    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();
    if (parcel->errorCheck()) {
        return nullptr;
@@ -651,7 +649,7 @@ void KeyCharacterMap::writeToParcel(Parcel* parcel) const {
        ALOGE("%s: Null parcel", __func__);
        return;
    }
    parcel->writeInt32(mType);
    parcel->writeInt32(static_cast<int32_t>(mType));

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

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

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

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

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