diff options
author | Jeff Brown <jeffbrown@google.com> | 2011-08-10 17:28:09 -0700 |
---|---|---|
committer | Android (Google) Code Review <android-gerrit@google.com> | 2011-08-10 17:28:09 -0700 |
commit | 7034e4e66568cf4e5294a18ae4fc7a6636c62fa8 (patch) | |
tree | a337fa199c226a825bb2826fd0589d80c676d598 /services | |
parent | bf48b571cf5e25bb2bb3ce5c95f8f3ccb9797c39 (diff) | |
parent | ba421dddfd558b34726df5dfbf8a3bf748e285b1 (diff) | |
download | frameworks_base-7034e4e66568cf4e5294a18ae4fc7a6636c62fa8.zip frameworks_base-7034e4e66568cf4e5294a18ae4fc7a6636c62fa8.tar.gz frameworks_base-7034e4e66568cf4e5294a18ae4fc7a6636c62fa8.tar.bz2 |
Merge "Fix getSwitchState and others to check bitmasks. Bug: 5149443"
Diffstat (limited to 'services')
-rw-r--r-- | services/input/EventHub.cpp | 191 | ||||
-rw-r--r-- | services/input/EventHub.h | 7 |
2 files changed, 76 insertions, 122 deletions
diff --git a/services/input/EventHub.cpp b/services/input/EventHub.cpp index 7ea3de2..0a567fd 100644 --- a/services/input/EventHub.cpp +++ b/services/input/EventHub.cpp @@ -205,27 +205,30 @@ status_t EventHub::getAbsoluteAxisInfo(int32_t deviceId, int axis, RawAbsoluteAxisInfo* outAxisInfo) const { outAxisInfo->clear(); - AutoMutex _l(mLock); - Device* device = getDeviceLocked(deviceId); - if (device == NULL) return -1; - - struct input_absinfo info; + if (axis >= 0 && axis <= ABS_MAX) { + AutoMutex _l(mLock); - if(ioctl(device->fd, EVIOCGABS(axis), &info)) { - LOGW("Error reading absolute controller %d for device %s fd %d, errno=%d", - axis, device->identifier.name.string(), device->fd, errno); - return -errno; - } + Device* device = getDeviceLocked(deviceId); + if (device && test_bit(axis, device->absBitmask)) { + struct input_absinfo info; + if(ioctl(device->fd, EVIOCGABS(axis), &info)) { + LOGW("Error reading absolute controller %d for device %s fd %d, errno=%d", + axis, device->identifier.name.string(), device->fd, errno); + return -errno; + } - if (info.minimum != info.maximum) { - outAxisInfo->valid = true; - outAxisInfo->minValue = info.minimum; - outAxisInfo->maxValue = info.maximum; - outAxisInfo->flat = info.flat; - outAxisInfo->fuzz = info.fuzz; - outAxisInfo->resolution = info.resolution; + if (info.minimum != info.maximum) { + outAxisInfo->valid = true; + outAxisInfo->minValue = info.minimum; + outAxisInfo->maxValue = info.maximum; + outAxisInfo->flat = info.flat; + outAxisInfo->fuzz = info.fuzz; + outAxisInfo->resolution = info.resolution; + } + return OK; + } } - return OK; + return -1; } bool EventHub::hasRelativeAxis(int32_t deviceId, int axis) const { @@ -233,7 +236,7 @@ bool EventHub::hasRelativeAxis(int32_t deviceId, int axis) const { AutoMutex _l(mLock); Device* device = getDeviceLocked(deviceId); - if (device && device->relBitmask) { + if (device) { return test_bit(axis, device->relBitmask); } } @@ -245,7 +248,7 @@ bool EventHub::hasInputProperty(int32_t deviceId, int property) const { AutoMutex _l(mLock); Device* device = getDeviceLocked(deviceId); - if (device && device->propBitmask) { + if (device) { return test_bit(property, device->propBitmask); } } @@ -257,58 +260,37 @@ int32_t EventHub::getScanCodeState(int32_t deviceId, int32_t scanCode) const { AutoMutex _l(mLock); Device* device = getDeviceLocked(deviceId); - if (device != NULL) { - return getScanCodeStateLocked(device, scanCode); + if (device && test_bit(scanCode, device->keyBitmask)) { + uint8_t keyState[sizeof_bit_array(KEY_MAX + 1)]; + memset(keyState, 0, sizeof(keyState)); + if (ioctl(device->fd, EVIOCGKEY(sizeof(keyState)), keyState) >= 0) { + return test_bit(scanCode, keyState) ? AKEY_STATE_DOWN : AKEY_STATE_UP; + } } } return AKEY_STATE_UNKNOWN; } -int32_t EventHub::getScanCodeStateLocked(Device* device, int32_t scanCode) const { - uint8_t key_bitmask[sizeof_bit_array(KEY_MAX + 1)]; - memset(key_bitmask, 0, sizeof(key_bitmask)); - if (ioctl(device->fd, - EVIOCGKEY(sizeof(key_bitmask)), key_bitmask) >= 0) { - return test_bit(scanCode, key_bitmask) ? AKEY_STATE_DOWN : AKEY_STATE_UP; - } - return AKEY_STATE_UNKNOWN; -} - int32_t EventHub::getKeyCodeState(int32_t deviceId, int32_t keyCode) const { AutoMutex _l(mLock); Device* device = getDeviceLocked(deviceId); - if (device != NULL) { - return getKeyCodeStateLocked(device, keyCode); - } - return AKEY_STATE_UNKNOWN; -} - -int32_t EventHub::getKeyCodeStateLocked(Device* device, int32_t keyCode) const { - if (!device->keyMap.haveKeyLayout()) { - return AKEY_STATE_UNKNOWN; - } - - Vector<int32_t> scanCodes; - device->keyMap.keyLayoutMap->findScanCodesForKey(keyCode, &scanCodes); - - uint8_t key_bitmask[sizeof_bit_array(KEY_MAX + 1)]; - memset(key_bitmask, 0, sizeof(key_bitmask)); - if (ioctl(device->fd, EVIOCGKEY(sizeof(key_bitmask)), key_bitmask) >= 0) { - #if 0 - for (size_t i=0; i<=KEY_MAX; i++) { - LOGI("(Scan code %d: down=%d)", i, test_bit(i, key_bitmask)); - } - #endif - const size_t N = scanCodes.size(); - for (size_t i=0; i<N && i<=KEY_MAX; i++) { - int32_t sc = scanCodes.itemAt(i); - //LOGI("Code %d: down=%d", sc, test_bit(sc, key_bitmask)); - if (sc >= 0 && sc <= KEY_MAX && test_bit(sc, key_bitmask)) { - return AKEY_STATE_DOWN; + if (device && device->keyMap.haveKeyLayout()) { + Vector<int32_t> scanCodes; + device->keyMap.keyLayoutMap->findScanCodesForKey(keyCode, &scanCodes); + if (scanCodes.size() != 0) { + uint8_t keyState[sizeof_bit_array(KEY_MAX + 1)]; + memset(keyState, 0, sizeof(keyState)); + if (ioctl(device->fd, EVIOCGKEY(sizeof(keyState)), keyState) >= 0) { + for (size_t i = 0; i < scanCodes.size(); i++) { + int32_t sc = scanCodes.itemAt(i); + if (sc >= 0 && sc <= KEY_MAX && test_bit(sc, keyState)) { + return AKEY_STATE_DOWN; + } + } + return AKEY_STATE_UP; } } - return AKEY_STATE_UP; } return AKEY_STATE_UNKNOWN; } @@ -318,85 +300,64 @@ int32_t EventHub::getSwitchState(int32_t deviceId, int32_t sw) const { AutoMutex _l(mLock); Device* device = getDeviceLocked(deviceId); - if (device != NULL) { - return getSwitchStateLocked(device, sw); + if (device && test_bit(sw, device->swBitmask)) { + uint8_t swState[sizeof_bit_array(SW_MAX + 1)]; + memset(swState, 0, sizeof(swState)); + if (ioctl(device->fd, EVIOCGSW(sizeof(swState)), swState) >= 0) { + return test_bit(sw, swState) ? AKEY_STATE_DOWN : AKEY_STATE_UP; + } } } return AKEY_STATE_UNKNOWN; } -int32_t EventHub::getSwitchStateLocked(Device* device, int32_t sw) const { - uint8_t sw_bitmask[sizeof_bit_array(SW_MAX + 1)]; - memset(sw_bitmask, 0, sizeof(sw_bitmask)); - if (ioctl(device->fd, - EVIOCGSW(sizeof(sw_bitmask)), sw_bitmask) >= 0) { - return test_bit(sw, sw_bitmask) ? AKEY_STATE_DOWN : AKEY_STATE_UP; - } - return AKEY_STATE_UNKNOWN; -} - status_t EventHub::getAbsoluteAxisValue(int32_t deviceId, int32_t axis, int32_t* outValue) const { if (axis >= 0 && axis <= ABS_MAX) { AutoMutex _l(mLock); Device* device = getDeviceLocked(deviceId); - if (device != NULL) { - return getAbsoluteAxisValueLocked(device, axis, outValue); + if (device && test_bit(axis, device->absBitmask)) { + struct input_absinfo info; + if(ioctl(device->fd, EVIOCGABS(axis), &info)) { + LOGW("Error reading absolute controller %d for device %s fd %d, errno=%d", + axis, device->identifier.name.string(), device->fd, errno); + return -errno; + } + + *outValue = info.value; + return OK; } } *outValue = 0; return -1; } -status_t EventHub::getAbsoluteAxisValueLocked(Device* device, int32_t axis, - int32_t* outValue) const { - struct input_absinfo info; - - if(ioctl(device->fd, EVIOCGABS(axis), &info)) { - LOGW("Error reading absolute controller %d for device %s fd %d, errno=%d", - axis, device->identifier.name.string(), device->fd, errno); - return -errno; - } - - *outValue = info.value; - return OK; -} - bool EventHub::markSupportedKeyCodes(int32_t deviceId, size_t numCodes, const int32_t* keyCodes, uint8_t* outFlags) const { AutoMutex _l(mLock); Device* device = getDeviceLocked(deviceId); - if (device != NULL) { - return markSupportedKeyCodesLocked(device, numCodes, keyCodes, outFlags); - } - return false; -} - -bool EventHub::markSupportedKeyCodesLocked(Device* device, size_t numCodes, - const int32_t* keyCodes, uint8_t* outFlags) const { - if (!device->keyMap.haveKeyLayout()) { - return false; - } - - Vector<int32_t> scanCodes; - for (size_t codeIndex = 0; codeIndex < numCodes; codeIndex++) { - scanCodes.clear(); - - status_t err = device->keyMap.keyLayoutMap->findScanCodesForKey( - keyCodes[codeIndex], &scanCodes); - if (! err) { - // check the possible scan codes identified by the layout map against the - // map of codes actually emitted by the driver - for (size_t sc = 0; sc < scanCodes.size(); sc++) { - if (test_bit(scanCodes[sc], device->keyBitmask)) { - outFlags[codeIndex] = 1; - break; + if (device && device->keyMap.haveKeyLayout()) { + Vector<int32_t> scanCodes; + for (size_t codeIndex = 0; codeIndex < numCodes; codeIndex++) { + scanCodes.clear(); + + status_t err = device->keyMap.keyLayoutMap->findScanCodesForKey( + keyCodes[codeIndex], &scanCodes); + if (! err) { + // check the possible scan codes identified by the layout map against the + // map of codes actually emitted by the driver + for (size_t sc = 0; sc < scanCodes.size(); sc++) { + if (test_bit(scanCodes[sc], device->keyBitmask)) { + outFlags[codeIndex] = 1; + break; + } } } } + return true; } - return true; + return false; } status_t EventHub::mapKey(int32_t deviceId, int scancode, diff --git a/services/input/EventHub.h b/services/input/EventHub.h index 293a1a0..08f73ca 100644 --- a/services/input/EventHub.h +++ b/services/input/EventHub.h @@ -307,13 +307,6 @@ private: bool hasKeycodeLocked(Device* device, int keycode) const; - int32_t getScanCodeStateLocked(Device* device, int32_t scanCode) const; - int32_t getKeyCodeStateLocked(Device* device, int32_t keyCode) const; - int32_t getSwitchStateLocked(Device* device, int32_t sw) const; - int32_t getAbsoluteAxisValueLocked(Device* device, int32_t axis, int32_t* outValue) const; - bool markSupportedKeyCodesLocked(Device* device, size_t numCodes, - const int32_t* keyCodes, uint8_t* outFlags) const; - void loadConfigurationLocked(Device* device); status_t loadVirtualKeyMapLocked(Device* device); status_t loadKeyMapLocked(Device* device); |