Skip to content

Commit 8f226dc

Browse files
Jeff BrownAndroid Git Automerger
authored andcommitted
am ca97671: am 6f5a837: Merge "Fix getSwitchState according to device capabilities."
* commit 'ca97671e2b74ed31b5bef6fd0b39e489f1ec5f51': Fix getSwitchState according to device capabilities.
2 parents b4459d8 + ca97671 commit 8f226dc

File tree

2 files changed

+20
-6
lines changed

2 files changed

+20
-6
lines changed

include/ui/EventHub.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -239,6 +239,7 @@ class EventHub : public EventHubInterface
239239
String8 name;
240240
uint32_t classes;
241241
uint8_t* keyBitmask;
242+
uint8_t* switchBitmask;
242243
KeyLayoutMap* layoutMap;
243244
String8 keylayoutFilename;
244245
int fd;

libs/ui/EventHub.cpp

Lines changed: 19 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -94,11 +94,13 @@ static inline const char* toString(bool value) {
9494

9595
EventHub::device_t::device_t(int32_t _id, const char* _path, const char* name)
9696
: id(_id), path(_path), name(name), classes(0)
97-
, keyBitmask(NULL), layoutMap(new KeyLayoutMap()), fd(-1), next(NULL) {
97+
, keyBitmask(NULL), switchBitmask(NULL)
98+
, layoutMap(new KeyLayoutMap()), fd(-1), next(NULL) {
9899
}
99100

100101
EventHub::device_t::~device_t() {
101102
delete [] keyBitmask;
103+
delete [] switchBitmask;
102104
delete layoutMap;
103105
}
104106

@@ -243,11 +245,14 @@ int32_t EventHub::getSwitchState(int32_t deviceId, int32_t sw) const {
243245
}
244246

245247
int32_t EventHub::getSwitchStateLocked(device_t* device, int32_t sw) const {
246-
uint8_t sw_bitmask[sizeof_bit_array(SW_MAX + 1)];
247-
memset(sw_bitmask, 0, sizeof(sw_bitmask));
248-
if (ioctl(device->fd,
249-
EVIOCGSW(sizeof(sw_bitmask)), sw_bitmask) >= 0) {
250-
return test_bit(sw, sw_bitmask) ? AKEY_STATE_DOWN : AKEY_STATE_UP;
248+
if (device->switchBitmask != NULL
249+
&& test_bit(sw, device->switchBitmask)) {
250+
uint8_t sw_bitmask[sizeof_bit_array(SW_MAX + 1)];
251+
memset(sw_bitmask, 0, sizeof(sw_bitmask));
252+
if (ioctl(device->fd,
253+
EVIOCGSW(sizeof(sw_bitmask)), sw_bitmask) >= 0) {
254+
return test_bit(sw, sw_bitmask) ? AKEY_STATE_DOWN : AKEY_STATE_UP;
255+
}
251256
}
252257
return AKEY_STATE_UNKNOWN;
253258
}
@@ -759,6 +764,14 @@ int EventHub::openDevice(const char *deviceName) {
759764
}
760765
if (hasSwitches) {
761766
device->classes |= INPUT_DEVICE_CLASS_SWITCH;
767+
device->switchBitmask = new uint8_t[sizeof(sw_bitmask)];
768+
if (device->switchBitmask != NULL) {
769+
memcpy(device->switchBitmask, sw_bitmask, sizeof(sw_bitmask));
770+
} else {
771+
delete device;
772+
LOGE("out of memory allocating switch bitmask");
773+
return -1;
774+
}
762775
}
763776
#endif
764777

0 commit comments

Comments
 (0)