Modify getState to prefer AKEY_STATE_DOWN and AKEY_STATE_UP over AKEY_STATE_UNKNOWN.
For the getState() routines that operate on multiple devices / mappers:
Return AKEY_STATE_DOWN (or AKEY_STATE_VIRTUAL) if any of the devices/mappers
have the key down.
Otherwise, return AKEY_STATE_UP if at least one device/mapper returns AKEY_STATE_UP.
Otherwise, return AKEY_STATE_UNKNOWN.
Change-Id: I1ef6251d73af916b51f408a41c5e4adf5bdc237a
diff --git a/services/input/InputReader.cpp b/services/input/InputReader.cpp
index 88c19a4..9a73527 100644
--- a/services/input/InputReader.cpp
+++ b/services/input/InputReader.cpp
@@ -644,9 +644,13 @@
for (size_t i = 0; i < numDevices; i++) {
InputDevice* device = mDevices.valueAt(i);
if (! device->isIgnored() && sourcesMatchMask(device->getSources(), sourceMask)) {
- result = (device->*getStateFunc)(sourceMask, code);
- if (result >= AKEY_STATE_DOWN) {
- return result;
+ // If any device reports AKEY_STATE_DOWN or AKEY_STATE_VIRTUAL, return that
+ // value. Otherwise, return AKEY_STATE_UP as long as one device reports it.
+ int32_t currentResult = (device->*getStateFunc)(sourceMask, code);
+ if (currentResult >= AKEY_STATE_DOWN) {
+ return currentResult;
+ } else if (currentResult == AKEY_STATE_UP) {
+ result = currentResult;
}
}
}
@@ -1000,9 +1004,13 @@
for (size_t i = 0; i < numMappers; i++) {
InputMapper* mapper = mMappers[i];
if (sourcesMatchMask(mapper->getSources(), sourceMask)) {
- result = (mapper->*getStateFunc)(sourceMask, code);
- if (result >= AKEY_STATE_DOWN) {
- return result;
+ // If any mapper reports AKEY_STATE_DOWN or AKEY_STATE_VIRTUAL, return that
+ // value. Otherwise, return AKEY_STATE_UP as long as one mapper reports it.
+ int32_t currentResult = (mapper->*getStateFunc)(sourceMask, code);
+ if (currentResult >= AKEY_STATE_DOWN) {
+ return currentResult;
+ } else if (currentResult == AKEY_STATE_UP) {
+ result = currentResult;
}
}
}