Fix toggleCapsLock failed for multiple EventHub devices
If a physical device includes multiple EventHub devices for different
funcions, it would also create multiple InputMappers to process raw
events. And it may contain multiple KeyboardInputMapper.
When 'toggleCapsLock' called, we have to check if device has the meta
state key such as CAPS_LOCK or NUMS_LOCK, then we should just update the
the first InputMapper that own the meta state key to prevent other
InputMapper update the global state multiple times.
Bug: 195405545
Test: atest inputflinger_tests
Test: shortcut key META-ALT
Change-Id: I9d09e13d1de416370b8570b6621db5c4bf1ba8eb
diff --git a/services/inputflinger/reader/mapper/InputMapper.cpp b/services/inputflinger/reader/mapper/InputMapper.cpp
index df1acd4..b9aef54 100644
--- a/services/inputflinger/reader/mapper/InputMapper.cpp
+++ b/services/inputflinger/reader/mapper/InputMapper.cpp
@@ -84,7 +84,9 @@
return 0;
}
-void InputMapper::updateMetaState(int32_t keyCode) {}
+bool InputMapper::updateMetaState(int32_t keyCode) {
+ return false;
+}
void InputMapper::updateExternalStylusState(const StylusState& state) {}
diff --git a/services/inputflinger/reader/mapper/InputMapper.h b/services/inputflinger/reader/mapper/InputMapper.h
index 15cff1c..d9adc0f 100644
--- a/services/inputflinger/reader/mapper/InputMapper.h
+++ b/services/inputflinger/reader/mapper/InputMapper.h
@@ -83,7 +83,11 @@
virtual std::optional<int32_t> getLightPlayerId(int32_t lightId) { return std::nullopt; }
virtual int32_t getMetaState();
- virtual void updateMetaState(int32_t keyCode);
+ /**
+ * Process the meta key and update the global meta state when changed.
+ * Return true if the meta key could be handled by the InputMapper.
+ */
+ virtual bool updateMetaState(int32_t keyCode);
virtual void updateExternalStylusState(const StylusState& state);
diff --git a/services/inputflinger/reader/mapper/KeyboardInputMapper.cpp b/services/inputflinger/reader/mapper/KeyboardInputMapper.cpp
index 104d087..52af38d 100644
--- a/services/inputflinger/reader/mapper/KeyboardInputMapper.cpp
+++ b/services/inputflinger/reader/mapper/KeyboardInputMapper.cpp
@@ -384,8 +384,13 @@
return mMetaState;
}
-void KeyboardInputMapper::updateMetaState(int32_t keyCode) {
+bool KeyboardInputMapper::updateMetaState(int32_t keyCode) {
+ if (!android::isMetaKey(keyCode) || !getDeviceContext().hasKeyCode(keyCode)) {
+ return false;
+ }
+
updateMetaStateIfNeeded(keyCode, false);
+ return true;
}
bool KeyboardInputMapper::updateMetaStateIfNeeded(int32_t keyCode, bool down) {
diff --git a/services/inputflinger/reader/mapper/KeyboardInputMapper.h b/services/inputflinger/reader/mapper/KeyboardInputMapper.h
index ca41712..fc92320 100644
--- a/services/inputflinger/reader/mapper/KeyboardInputMapper.h
+++ b/services/inputflinger/reader/mapper/KeyboardInputMapper.h
@@ -40,7 +40,7 @@
const int32_t* keyCodes, uint8_t* outFlags) override;
virtual int32_t getMetaState() override;
- virtual void updateMetaState(int32_t keyCode) override;
+ virtual bool updateMetaState(int32_t keyCode) override;
virtual std::optional<int32_t> getAssociatedDisplayId() override;
virtual void updateLedState(bool reset);