hasKeycode API should take into account key remapping
Keyboards can generate certain keycodes even if the keys are not
present in the device HID descriptor, by using key remapping APIs
Test: atest ModifierKeyRemappingTest
Bug: 368397939
Flag: EXEMPT bugfix
Change-Id: I30afda89f289eddc2b05fb124555aebfb182852e
diff --git a/services/inputflinger/reader/EventHub.cpp b/services/inputflinger/reader/EventHub.cpp
index 0865eed..10cc1ee 100644
--- a/services/inputflinger/reader/EventHub.cpp
+++ b/services/inputflinger/reader/EventHub.cpp
@@ -659,6 +659,19 @@
}
bool EventHub::Device::hasKeycodeLocked(int keycode) const {
+ if (hasKeycodeInternalLocked(keycode)) {
+ return true;
+ }
+
+ for (auto& fromKey : getKeyCharacterMap()->findKeyCodesMappedToKeyCode(keycode)) {
+ if (hasKeycodeInternalLocked(fromKey)) {
+ return true;
+ }
+ }
+ return false;
+}
+
+bool EventHub::Device::hasKeycodeInternalLocked(int keycode) const {
if (!keyMap.haveKeyLayout()) {
return false;
}
@@ -676,7 +689,6 @@
if (usageCodes.size() > 0 && mscBitmask.test(MSC_SCAN)) {
return true;
}
-
return false;
}