diff options
author | 2012-04-11 18:27:33 -0700 | |
---|---|---|
committer | 2012-04-11 20:28:09 -0700 | |
commit | 49ccac530b5a798e3c4a79b66b51b8546a0deed1 (patch) | |
tree | 0b25fa1110effb7e8aa46905928b0b159daa96ab /services/input/EventHub.cpp | |
parent | db13a6bf788cc48af86c8acf6f74b416dfd84199 (diff) |
Refactor key code mapping.
Added handling for EV_MSC / MSC_SCAN which typically reports
the HID usage associated with a key. This will enable key maps
to map keys with HID usages that Linux does not natively recognize.
Removed keyCode and flags fields from EventHub RawEvent since
they don't necessarily make sense in isolation now that we
pay attention to HID usage codes too.
Removed the fallback code for mapping keys and axes. In practice,
an input device should be self-sufficient. We should not ever
need to look at the built-in keyboard's key map. In fact, there
usually isn't a built-in keyboard anyhow. This code was originally
working around a problem where we weren't loading the key map
for touch screens with virtual keys, which has long since been fixed.
Change-Id: I0a319bdec44be9514f795526347397e94d53a127
Diffstat (limited to 'services/input/EventHub.cpp')
-rw-r--r-- | services/input/EventHub.cpp | 53 |
1 files changed, 12 insertions, 41 deletions
diff --git a/services/input/EventHub.cpp b/services/input/EventHub.cpp index 744f2ad4533f..2ba821e30e99 100644 --- a/services/input/EventHub.cpp +++ b/services/input/EventHub.cpp @@ -117,6 +117,8 @@ static void setDescriptor(InputDeviceIdentifier& identifier) { } } identifier.descriptor = sha1(rawDescriptor); + ALOGV("Created descriptor: raw=%s, cooked=%s", rawDescriptor.string(), + identifier.descriptor.string()); } // --- Global Functions --- @@ -434,58 +436,35 @@ bool EventHub::markSupportedKeyCodes(int32_t deviceId, size_t numCodes, return false; } -status_t EventHub::mapKey(int32_t deviceId, int scancode, - int32_t* outKeycode, uint32_t* outFlags) const -{ +status_t EventHub::mapKey(int32_t deviceId, int32_t scanCode, int32_t usageCode, + int32_t* outKeycode, uint32_t* outFlags) const { AutoMutex _l(mLock); Device* device = getDeviceLocked(deviceId); - + if (device && device->keyMap.haveKeyLayout()) { - status_t err = device->keyMap.keyLayoutMap->mapKey(scancode, outKeycode, outFlags); + status_t err = device->keyMap.keyLayoutMap->mapKey( + scanCode, usageCode, outKeycode, outFlags); if (err == NO_ERROR) { return NO_ERROR; } } - - if (mBuiltInKeyboardId != NO_BUILT_IN_KEYBOARD) { - device = getDeviceLocked(mBuiltInKeyboardId); - - if (device && device->keyMap.haveKeyLayout()) { - status_t err = device->keyMap.keyLayoutMap->mapKey(scancode, outKeycode, outFlags); - if (err == NO_ERROR) { - return NO_ERROR; - } - } - } - + *outKeycode = 0; *outFlags = 0; return NAME_NOT_FOUND; } -status_t EventHub::mapAxis(int32_t deviceId, int scancode, AxisInfo* outAxisInfo) const -{ +status_t EventHub::mapAxis(int32_t deviceId, int32_t scanCode, AxisInfo* outAxisInfo) const { AutoMutex _l(mLock); Device* device = getDeviceLocked(deviceId); if (device && device->keyMap.haveKeyLayout()) { - status_t err = device->keyMap.keyLayoutMap->mapAxis(scancode, outAxisInfo); + status_t err = device->keyMap.keyLayoutMap->mapAxis(scanCode, outAxisInfo); if (err == NO_ERROR) { return NO_ERROR; } } - if (mBuiltInKeyboardId != NO_BUILT_IN_KEYBOARD) { - device = getDeviceLocked(mBuiltInKeyboardId); - - if (device && device->keyMap.haveKeyLayout()) { - status_t err = device->keyMap.keyLayoutMap->mapAxis(scancode, outAxisInfo); - if (err == NO_ERROR) { - return NO_ERROR; - } - } - } - return NAME_NOT_FOUND; } @@ -729,16 +708,8 @@ size_t EventHub::getEvents(int timeoutMillis, RawEvent* buffer, size_t bufferSiz #endif event->deviceId = deviceId; event->type = iev.type; - event->scanCode = iev.code; + event->code = iev.code; event->value = iev.value; - event->keyCode = AKEYCODE_UNKNOWN; - event->flags = 0; - if (iev.type == EV_KEY && device->keyMap.haveKeyLayout()) { - status_t err = device->keyMap.keyLayoutMap->mapKey(iev.code, - &event->keyCode, &event->flags); - ALOGV("iev.code=%d keyCode=%d flags=0x%08x err=%d\n", - iev.code, event->keyCode, event->flags, err); - } event += 1; } capacity -= count; @@ -960,7 +931,7 @@ status_t EventHub::openDeviceLocked(const char *devicePath) { ALOGV(" name: \"%s\"\n", identifier.name.string()); ALOGV(" location: \"%s\"\n", identifier.location.string()); ALOGV(" unique id: \"%s\"\n", identifier.uniqueId.string()); - ALOGV(" descriptor: \"%s\" (%s)\n", identifier.descriptor.string(), rawDescriptor.string()); + ALOGV(" descriptor: \"%s\"\n", identifier.descriptor.string()); ALOGV(" driver: v%d.%d.%d\n", driverVersion >> 16, (driverVersion >> 8) & 0xff, driverVersion & 0xff); |