Loading include/androidfw/KeyCharacterMap.h +27 −2 Original line number Diff line number Diff line Loading @@ -49,6 +49,17 @@ public: KEYBOARD_TYPE_ALPHA = 3, KEYBOARD_TYPE_FULL = 4, KEYBOARD_TYPE_SPECIAL_FUNCTION = 5, KEYBOARD_TYPE_OVERLAY = 6, }; enum Format { // Base keyboard layout, may contain device-specific options, such as "type" declaration. FORMAT_BASE = 0, // Overlay keyboard layout, more restrictive, may be published by applications, // cannot override device-specific options. FORMAT_OVERLAY = 1, // Either base or overlay layout ok. FORMAT_ANY = 2, }; // Substitute key code and meta state for fallback action. Loading @@ -58,7 +69,15 @@ public: }; /* Loads a key character map from a file. */ static status_t load(const String8& filename, sp<KeyCharacterMap>* outMap); static status_t load(const String8& filename, Format format, sp<KeyCharacterMap>* outMap); /* Loads a key character map from its string contents. */ static status_t loadContents(const String8& filename, const char* contents, Format format, sp<KeyCharacterMap>* outMap); /* Combines a base key character map and an overlay. */ static sp<KeyCharacterMap> combine(const sp<KeyCharacterMap>& base, const sp<KeyCharacterMap>& overlay); /* Returns an empty key character map. */ static sp<KeyCharacterMap> empty(); Loading Loading @@ -115,6 +134,7 @@ protected: private: struct Behavior { Behavior(); Behavior(const Behavior& other); /* The next behavior in the list, or NULL if none. */ Behavior* next; Loading @@ -131,6 +151,7 @@ private: struct Key { Key(); Key(const Key& other); ~Key(); /* The single character label printed on the key, or 0 if none. */ Loading Loading @@ -166,11 +187,12 @@ private: KeyCharacterMap* mMap; Tokenizer* mTokenizer; Format mFormat; State mState; int32_t mKeyCode; public: Parser(KeyCharacterMap* map, Tokenizer* tokenizer); Parser(KeyCharacterMap* map, Tokenizer* tokenizer, Format format); ~Parser(); status_t parse(); Loading @@ -188,6 +210,7 @@ private: int mType; KeyCharacterMap(); KeyCharacterMap(const KeyCharacterMap& other); bool getKey(int32_t keyCode, const Key** outKey) const; bool getKeyBehavior(int32_t keyCode, int32_t metaState, Loading @@ -195,6 +218,8 @@ 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 void addKey(Vector<KeyEvent>& outEvents, int32_t deviceId, int32_t keyCode, int32_t metaState, bool down, nsecs_t time); static void addMetaKeys(Vector<KeyEvent>& outEvents, Loading libs/androidfw/KeyCharacterMap.cpp +104 −23 Original line number Diff line number Diff line Loading @@ -89,6 +89,13 @@ KeyCharacterMap::KeyCharacterMap() : mType(KEYBOARD_TYPE_UNKNOWN) { } KeyCharacterMap::KeyCharacterMap(const KeyCharacterMap& other) : RefBase(), mType(other.mType) { for (size_t i = 0; i < other.mKeys.size(); i++) { mKeys.add(other.mKeys.keyAt(i), new Key(*other.mKeys.valueAt(i))); } } KeyCharacterMap::~KeyCharacterMap() { for (size_t i = 0; i < mKeys.size(); i++) { Key* key = mKeys.editValueAt(i); Loading @@ -96,7 +103,8 @@ KeyCharacterMap::~KeyCharacterMap() { } } status_t KeyCharacterMap::load(const String8& filename, sp<KeyCharacterMap>* outMap) { status_t KeyCharacterMap::load(const String8& filename, Format format, sp<KeyCharacterMap>* outMap) { outMap->clear(); Tokenizer* tokenizer; Loading @@ -104,6 +112,30 @@ status_t KeyCharacterMap::load(const String8& filename, sp<KeyCharacterMap>* out if (status) { ALOGE("Error %d opening key character map file %s.", status, filename.string()); } else { status = load(tokenizer, format, outMap); delete tokenizer; } return status; } status_t KeyCharacterMap::loadContents(const String8& filename, const char* contents, Format format, sp<KeyCharacterMap>* outMap) { outMap->clear(); Tokenizer* tokenizer; status_t status = Tokenizer::fromContents(filename, contents, &tokenizer); if (status) { ALOGE("Error %d opening key character map.", status); } else { status = load(tokenizer, format, outMap); delete tokenizer; } return status; } status_t KeyCharacterMap::load(Tokenizer* tokenizer, Format format, sp<KeyCharacterMap>* outMap) { status_t status = OK; sp<KeyCharacterMap> map = new KeyCharacterMap(); if (!map.get()) { ALOGE("Error allocating key character map."); Loading @@ -112,7 +144,7 @@ status_t KeyCharacterMap::load(const String8& filename, sp<KeyCharacterMap>* out #if DEBUG_PARSER_PERFORMANCE nsecs_t startTime = systemTime(SYSTEM_TIME_MONOTONIC); #endif Parser parser(map.get(), tokenizer); Parser parser(map.get(), tokenizer, format); status = parser.parse(); #if DEBUG_PARSER_PERFORMANCE nsecs_t elapsedTime = systemTime(SYSTEM_TIME_MONOTONIC) - startTime; Loading @@ -124,11 +156,33 @@ status_t KeyCharacterMap::load(const String8& filename, sp<KeyCharacterMap>* out *outMap = map; } } delete tokenizer; } return status; } sp<KeyCharacterMap> KeyCharacterMap::combine(const sp<KeyCharacterMap>& base, const sp<KeyCharacterMap>& overlay) { if (overlay == NULL) { return base; } if (base == NULL) { return overlay; } sp<KeyCharacterMap> map = new KeyCharacterMap(*base.get()); for (size_t i = 0; i < overlay->mKeys.size(); i++) { int32_t keyCode = overlay->mKeys.keyAt(i); Key* key = overlay->mKeys.valueAt(i); ssize_t oldIndex = map->mKeys.indexOfKey(keyCode); if (oldIndex >= 0) { delete map->mKeys.valueAt(oldIndex); map->mKeys.editValueAt(oldIndex) = new Key(*key); } else { map->mKeys.add(keyCode, new Key(*key)); } } return map; } sp<KeyCharacterMap> KeyCharacterMap::empty() { return sEmpty; } Loading Loading @@ -508,6 +562,11 @@ KeyCharacterMap::Key::Key() : label(0), number(0), firstBehavior(NULL) { } KeyCharacterMap::Key::Key(const Key& other) : label(other.label), number(other.number), firstBehavior(other.firstBehavior ? new Behavior(*other.firstBehavior) : NULL) { } KeyCharacterMap::Key::~Key() { Behavior* behavior = firstBehavior; while (behavior) { Loading @@ -524,11 +583,17 @@ KeyCharacterMap::Behavior::Behavior() : next(NULL), metaState(0), character(0), fallbackKeyCode(0) { } KeyCharacterMap::Behavior::Behavior(const Behavior& other) : next(other.next ? new Behavior(*other.next) : NULL), metaState(other.metaState), character(other.character), fallbackKeyCode(other.fallbackKeyCode) { } // --- KeyCharacterMap::Parser --- KeyCharacterMap::Parser::Parser(KeyCharacterMap* map, Tokenizer* tokenizer) : mMap(map), mTokenizer(tokenizer), mState(STATE_TOP) { KeyCharacterMap::Parser::Parser(KeyCharacterMap* map, Tokenizer* tokenizer, Format format) : mMap(map), mTokenizer(tokenizer), mFormat(format), mState(STATE_TOP) { } KeyCharacterMap::Parser::~Parser() { Loading Loading @@ -588,11 +653,25 @@ status_t KeyCharacterMap::Parser::parse() { return BAD_VALUE; } if (mFormat == FORMAT_BASE) { if (mMap->mType == KEYBOARD_TYPE_UNKNOWN) { ALOGE("%s: Missing required keyboard 'type' declaration.", ALOGE("%s: Base keyboard layout missing required keyboard 'type' declaration.", mTokenizer->getLocation().string()); return BAD_VALUE; } if (mMap->mType == KEYBOARD_TYPE_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) { ALOGE("%s: Overlay keyboard layout missing required keyboard " "'type OVERLAY' declaration.", mTokenizer->getLocation().string()); return BAD_VALUE; } } return NO_ERROR; } Loading @@ -616,6 +695,8 @@ status_t KeyCharacterMap::Parser::parseType() { type = KEYBOARD_TYPE_FULL; } else if (typeToken == "SPECIAL_FUNCTION") { type = KEYBOARD_TYPE_SPECIAL_FUNCTION; } else if (typeToken == "OVERLAY") { type = KEYBOARD_TYPE_OVERLAY; } else { ALOGE("%s: Expected keyboard type label, got '%s'.", mTokenizer->getLocation().string(), typeToken.string()); Loading libs/androidfw/Keyboard.cpp +2 −1 Original line number Diff line number Diff line Loading @@ -129,7 +129,8 @@ status_t KeyMap::loadKeyCharacterMap(const InputDeviceIdentifier& deviceIdentifi return NAME_NOT_FOUND; } status_t status = KeyCharacterMap::load(path, &keyCharacterMap); status_t status = KeyCharacterMap::load(path, KeyCharacterMap::FORMAT_BASE, &keyCharacterMap); if (status) { return status; } Loading packages/InputDevices/Android.mk +28 −2 Original line number Diff line number Diff line # Copyright (C) 2012 The Android Open Source Project # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. LOCAL_PATH:= $(call my-dir) include $(CLEAR_VARS) Loading @@ -12,5 +26,17 @@ LOCAL_CERTIFICATE := platform include $(BUILD_PACKAGE) ######################## include $(call all-makefiles-under,$(LOCAL_PATH)) # Validate all key maps. include $(CLEAR_VARS) validatekeymaps := $(HOST_OUT_EXECUTABLES)/validatekeymaps$(HOST_EXECUTABLE_SUFFIX) files := frameworks/base/packages/InputDevices/res/raw/*.kcm LOCAL_MODULE := validate_input_devices_keymaps LOCAL_MODULE_TAGS := optional LOCAL_REQUIRED_MODULES := validatekeymaps validate_input_devices_keymaps: $(files) $(hide) $(validatekeymaps) $(files) include $(BUILD_PHONY_PACKAGE) packages/InputDevices/res/raw/keyboard_layout_english_us.kcm +6 −1 Original line number Diff line number Diff line Loading @@ -12,4 +12,9 @@ # See the License for the specific language governing permissions and # limitations under the License. # PLACEHOLDER CONTENT # # # English (US) keyboard layout. # Assumes that the base keyboard layout is already English (US). # type OVERLAY Loading
include/androidfw/KeyCharacterMap.h +27 −2 Original line number Diff line number Diff line Loading @@ -49,6 +49,17 @@ public: KEYBOARD_TYPE_ALPHA = 3, KEYBOARD_TYPE_FULL = 4, KEYBOARD_TYPE_SPECIAL_FUNCTION = 5, KEYBOARD_TYPE_OVERLAY = 6, }; enum Format { // Base keyboard layout, may contain device-specific options, such as "type" declaration. FORMAT_BASE = 0, // Overlay keyboard layout, more restrictive, may be published by applications, // cannot override device-specific options. FORMAT_OVERLAY = 1, // Either base or overlay layout ok. FORMAT_ANY = 2, }; // Substitute key code and meta state for fallback action. Loading @@ -58,7 +69,15 @@ public: }; /* Loads a key character map from a file. */ static status_t load(const String8& filename, sp<KeyCharacterMap>* outMap); static status_t load(const String8& filename, Format format, sp<KeyCharacterMap>* outMap); /* Loads a key character map from its string contents. */ static status_t loadContents(const String8& filename, const char* contents, Format format, sp<KeyCharacterMap>* outMap); /* Combines a base key character map and an overlay. */ static sp<KeyCharacterMap> combine(const sp<KeyCharacterMap>& base, const sp<KeyCharacterMap>& overlay); /* Returns an empty key character map. */ static sp<KeyCharacterMap> empty(); Loading Loading @@ -115,6 +134,7 @@ protected: private: struct Behavior { Behavior(); Behavior(const Behavior& other); /* The next behavior in the list, or NULL if none. */ Behavior* next; Loading @@ -131,6 +151,7 @@ private: struct Key { Key(); Key(const Key& other); ~Key(); /* The single character label printed on the key, or 0 if none. */ Loading Loading @@ -166,11 +187,12 @@ private: KeyCharacterMap* mMap; Tokenizer* mTokenizer; Format mFormat; State mState; int32_t mKeyCode; public: Parser(KeyCharacterMap* map, Tokenizer* tokenizer); Parser(KeyCharacterMap* map, Tokenizer* tokenizer, Format format); ~Parser(); status_t parse(); Loading @@ -188,6 +210,7 @@ private: int mType; KeyCharacterMap(); KeyCharacterMap(const KeyCharacterMap& other); bool getKey(int32_t keyCode, const Key** outKey) const; bool getKeyBehavior(int32_t keyCode, int32_t metaState, Loading @@ -195,6 +218,8 @@ 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 void addKey(Vector<KeyEvent>& outEvents, int32_t deviceId, int32_t keyCode, int32_t metaState, bool down, nsecs_t time); static void addMetaKeys(Vector<KeyEvent>& outEvents, Loading
libs/androidfw/KeyCharacterMap.cpp +104 −23 Original line number Diff line number Diff line Loading @@ -89,6 +89,13 @@ KeyCharacterMap::KeyCharacterMap() : mType(KEYBOARD_TYPE_UNKNOWN) { } KeyCharacterMap::KeyCharacterMap(const KeyCharacterMap& other) : RefBase(), mType(other.mType) { for (size_t i = 0; i < other.mKeys.size(); i++) { mKeys.add(other.mKeys.keyAt(i), new Key(*other.mKeys.valueAt(i))); } } KeyCharacterMap::~KeyCharacterMap() { for (size_t i = 0; i < mKeys.size(); i++) { Key* key = mKeys.editValueAt(i); Loading @@ -96,7 +103,8 @@ KeyCharacterMap::~KeyCharacterMap() { } } status_t KeyCharacterMap::load(const String8& filename, sp<KeyCharacterMap>* outMap) { status_t KeyCharacterMap::load(const String8& filename, Format format, sp<KeyCharacterMap>* outMap) { outMap->clear(); Tokenizer* tokenizer; Loading @@ -104,6 +112,30 @@ status_t KeyCharacterMap::load(const String8& filename, sp<KeyCharacterMap>* out if (status) { ALOGE("Error %d opening key character map file %s.", status, filename.string()); } else { status = load(tokenizer, format, outMap); delete tokenizer; } return status; } status_t KeyCharacterMap::loadContents(const String8& filename, const char* contents, Format format, sp<KeyCharacterMap>* outMap) { outMap->clear(); Tokenizer* tokenizer; status_t status = Tokenizer::fromContents(filename, contents, &tokenizer); if (status) { ALOGE("Error %d opening key character map.", status); } else { status = load(tokenizer, format, outMap); delete tokenizer; } return status; } status_t KeyCharacterMap::load(Tokenizer* tokenizer, Format format, sp<KeyCharacterMap>* outMap) { status_t status = OK; sp<KeyCharacterMap> map = new KeyCharacterMap(); if (!map.get()) { ALOGE("Error allocating key character map."); Loading @@ -112,7 +144,7 @@ status_t KeyCharacterMap::load(const String8& filename, sp<KeyCharacterMap>* out #if DEBUG_PARSER_PERFORMANCE nsecs_t startTime = systemTime(SYSTEM_TIME_MONOTONIC); #endif Parser parser(map.get(), tokenizer); Parser parser(map.get(), tokenizer, format); status = parser.parse(); #if DEBUG_PARSER_PERFORMANCE nsecs_t elapsedTime = systemTime(SYSTEM_TIME_MONOTONIC) - startTime; Loading @@ -124,11 +156,33 @@ status_t KeyCharacterMap::load(const String8& filename, sp<KeyCharacterMap>* out *outMap = map; } } delete tokenizer; } return status; } sp<KeyCharacterMap> KeyCharacterMap::combine(const sp<KeyCharacterMap>& base, const sp<KeyCharacterMap>& overlay) { if (overlay == NULL) { return base; } if (base == NULL) { return overlay; } sp<KeyCharacterMap> map = new KeyCharacterMap(*base.get()); for (size_t i = 0; i < overlay->mKeys.size(); i++) { int32_t keyCode = overlay->mKeys.keyAt(i); Key* key = overlay->mKeys.valueAt(i); ssize_t oldIndex = map->mKeys.indexOfKey(keyCode); if (oldIndex >= 0) { delete map->mKeys.valueAt(oldIndex); map->mKeys.editValueAt(oldIndex) = new Key(*key); } else { map->mKeys.add(keyCode, new Key(*key)); } } return map; } sp<KeyCharacterMap> KeyCharacterMap::empty() { return sEmpty; } Loading Loading @@ -508,6 +562,11 @@ KeyCharacterMap::Key::Key() : label(0), number(0), firstBehavior(NULL) { } KeyCharacterMap::Key::Key(const Key& other) : label(other.label), number(other.number), firstBehavior(other.firstBehavior ? new Behavior(*other.firstBehavior) : NULL) { } KeyCharacterMap::Key::~Key() { Behavior* behavior = firstBehavior; while (behavior) { Loading @@ -524,11 +583,17 @@ KeyCharacterMap::Behavior::Behavior() : next(NULL), metaState(0), character(0), fallbackKeyCode(0) { } KeyCharacterMap::Behavior::Behavior(const Behavior& other) : next(other.next ? new Behavior(*other.next) : NULL), metaState(other.metaState), character(other.character), fallbackKeyCode(other.fallbackKeyCode) { } // --- KeyCharacterMap::Parser --- KeyCharacterMap::Parser::Parser(KeyCharacterMap* map, Tokenizer* tokenizer) : mMap(map), mTokenizer(tokenizer), mState(STATE_TOP) { KeyCharacterMap::Parser::Parser(KeyCharacterMap* map, Tokenizer* tokenizer, Format format) : mMap(map), mTokenizer(tokenizer), mFormat(format), mState(STATE_TOP) { } KeyCharacterMap::Parser::~Parser() { Loading Loading @@ -588,11 +653,25 @@ status_t KeyCharacterMap::Parser::parse() { return BAD_VALUE; } if (mFormat == FORMAT_BASE) { if (mMap->mType == KEYBOARD_TYPE_UNKNOWN) { ALOGE("%s: Missing required keyboard 'type' declaration.", ALOGE("%s: Base keyboard layout missing required keyboard 'type' declaration.", mTokenizer->getLocation().string()); return BAD_VALUE; } if (mMap->mType == KEYBOARD_TYPE_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) { ALOGE("%s: Overlay keyboard layout missing required keyboard " "'type OVERLAY' declaration.", mTokenizer->getLocation().string()); return BAD_VALUE; } } return NO_ERROR; } Loading @@ -616,6 +695,8 @@ status_t KeyCharacterMap::Parser::parseType() { type = KEYBOARD_TYPE_FULL; } else if (typeToken == "SPECIAL_FUNCTION") { type = KEYBOARD_TYPE_SPECIAL_FUNCTION; } else if (typeToken == "OVERLAY") { type = KEYBOARD_TYPE_OVERLAY; } else { ALOGE("%s: Expected keyboard type label, got '%s'.", mTokenizer->getLocation().string(), typeToken.string()); Loading
libs/androidfw/Keyboard.cpp +2 −1 Original line number Diff line number Diff line Loading @@ -129,7 +129,8 @@ status_t KeyMap::loadKeyCharacterMap(const InputDeviceIdentifier& deviceIdentifi return NAME_NOT_FOUND; } status_t status = KeyCharacterMap::load(path, &keyCharacterMap); status_t status = KeyCharacterMap::load(path, KeyCharacterMap::FORMAT_BASE, &keyCharacterMap); if (status) { return status; } Loading
packages/InputDevices/Android.mk +28 −2 Original line number Diff line number Diff line # Copyright (C) 2012 The Android Open Source Project # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. LOCAL_PATH:= $(call my-dir) include $(CLEAR_VARS) Loading @@ -12,5 +26,17 @@ LOCAL_CERTIFICATE := platform include $(BUILD_PACKAGE) ######################## include $(call all-makefiles-under,$(LOCAL_PATH)) # Validate all key maps. include $(CLEAR_VARS) validatekeymaps := $(HOST_OUT_EXECUTABLES)/validatekeymaps$(HOST_EXECUTABLE_SUFFIX) files := frameworks/base/packages/InputDevices/res/raw/*.kcm LOCAL_MODULE := validate_input_devices_keymaps LOCAL_MODULE_TAGS := optional LOCAL_REQUIRED_MODULES := validatekeymaps validate_input_devices_keymaps: $(files) $(hide) $(validatekeymaps) $(files) include $(BUILD_PHONY_PACKAGE)
packages/InputDevices/res/raw/keyboard_layout_english_us.kcm +6 −1 Original line number Diff line number Diff line Loading @@ -12,4 +12,9 @@ # See the License for the specific language governing permissions and # limitations under the License. # PLACEHOLDER CONTENT # # # English (US) keyboard layout. # Assumes that the base keyboard layout is already English (US). # type OVERLAY