diff options
-rw-r--r-- | libs/androidfw/KeyLayoutMap.cpp | 12 | ||||
-rw-r--r-- | services/input/tests/InputReader_test.cpp | 30 |
2 files changed, 23 insertions, 19 deletions
diff --git a/libs/androidfw/KeyLayoutMap.cpp b/libs/androidfw/KeyLayoutMap.cpp index c9bc718..a7c2199 100644 --- a/libs/androidfw/KeyLayoutMap.cpp +++ b/libs/androidfw/KeyLayoutMap.cpp @@ -103,18 +103,18 @@ status_t KeyLayoutMap::mapKey(int32_t scanCode, int32_t usageCode, } const KeyLayoutMap::Key* KeyLayoutMap::getKey(int32_t scanCode, int32_t usageCode) const { - if (scanCode) { - ssize_t index = mKeysByScanCode.indexOfKey(scanCode); - if (index >= 0) { - return &mKeysByScanCode.valueAt(index); - } - } if (usageCode) { ssize_t index = mKeysByUsageCode.indexOfKey(usageCode); if (index >= 0) { return &mKeysByUsageCode.valueAt(index); } } + if (scanCode) { + ssize_t index = mKeysByScanCode.indexOfKey(scanCode); + if (index >= 0) { + return &mKeysByScanCode.valueAt(index); + } + } return NULL; } diff --git a/services/input/tests/InputReader_test.cpp b/services/input/tests/InputReader_test.cpp index 91cf026..eac9a1c 100644 --- a/services/input/tests/InputReader_test.cpp +++ b/services/input/tests/InputReader_test.cpp @@ -480,19 +480,7 @@ private: int32_t* outKeycode, uint32_t* outFlags) const { Device* device = getDevice(deviceId); if (device) { - const KeyInfo* key = NULL; - if (scanCode) { - ssize_t index = device->keysByScanCode.indexOfKey(scanCode); - if (index >= 0) { - key = &device->keysByScanCode.valueAt(index); - } - } - if (!key && usageCode) { - ssize_t index = device->keysByUsageCode.indexOfKey(usageCode); - if (index >= 0) { - key = &device->keysByUsageCode.valueAt(index); - } - } + const KeyInfo* key = getKey(device, scanCode, usageCode); if (key) { if (outKeycode) { *outKeycode = key->keyCode; @@ -506,6 +494,22 @@ private: return NAME_NOT_FOUND; } + const KeyInfo* getKey(Device* device, int32_t scanCode, int32_t usageCode) const { + if (usageCode) { + ssize_t index = device->keysByUsageCode.indexOfKey(usageCode); + if (index >= 0) { + return &device->keysByUsageCode.valueAt(index); + } + } + if (scanCode) { + ssize_t index = device->keysByScanCode.indexOfKey(scanCode); + if (index >= 0) { + return &device->keysByScanCode.valueAt(index); + } + } + return NULL; + } + virtual status_t mapAxis(int32_t deviceId, int32_t scanCode, AxisInfo* outAxisInfo) const { return NAME_NOT_FOUND; |