Allow toggle caps lock even if device doesn't a have caps lock key
For Alphabetic keyboards without CapsLock key, we should allow system
to toggle CapsLock modifier state.
Test: atest CtsInputTestCases
Bug: 368397939
Flag: EXEMPT bugfix
Change-Id: I57cfe94bf5ab7804a9a1579dae769c18684776cb
diff --git a/services/inputflinger/reader/mapper/KeyboardInputMapper.cpp b/services/inputflinger/reader/mapper/KeyboardInputMapper.cpp
index 38dcd65..567a3e2 100644
--- a/services/inputflinger/reader/mapper/KeyboardInputMapper.cpp
+++ b/services/inputflinger/reader/mapper/KeyboardInputMapper.cpp
@@ -390,15 +390,6 @@
return mMetaState;
}
-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) {
int32_t oldMetaState = mMetaState;
int32_t newMetaState = android::updateMetaState(keyCode, down, oldMetaState);
@@ -434,17 +425,21 @@
mMetaState &= ~(AMETA_CAPS_LOCK_ON | AMETA_NUM_LOCK_ON | AMETA_SCROLL_LOCK_ON);
mMetaState |= getContext()->getLedMetaState();
- constexpr int32_t META_NUM = 3;
- const std::vector<int32_t> keyCodes{AKEYCODE_CAPS_LOCK, AKEYCODE_NUM_LOCK,
- AKEYCODE_SCROLL_LOCK};
- const std::array<int32_t, META_NUM> metaCodes = {AMETA_CAPS_LOCK_ON, AMETA_NUM_LOCK_ON,
- AMETA_SCROLL_LOCK_ON};
- std::array<uint8_t, META_NUM> flags = {0, 0, 0};
- bool hasKeyLayout = getDeviceContext().markSupportedKeyCodes(keyCodes, flags.data());
+ std::vector<int32_t> keyCodesToCheck{AKEYCODE_NUM_LOCK, AKEYCODE_SCROLL_LOCK};
+ std::vector<int32_t> metaCodes{AMETA_NUM_LOCK_ON, AMETA_SCROLL_LOCK_ON};
+ // Check for physical CapsLock key only for non-alphabetic keyboards. For Alphabetic
+ // keyboards, we will allow Caps Lock even if there is no physical CapsLock key.
+ if (getDeviceContext().getKeyboardType() != KeyboardType::ALPHABETIC) {
+ keyCodesToCheck.push_back(AKEYCODE_CAPS_LOCK);
+ metaCodes.push_back(AMETA_CAPS_LOCK_ON);
+ }
+ size_t size = keyCodesToCheck.size();
+ std::vector<uint8_t> flags(size, 0);
+ bool hasKeyLayout = getDeviceContext().markSupportedKeyCodes(keyCodesToCheck, flags.data());
// If the device doesn't have the physical meta key it shouldn't generate the corresponding
// meta state.
if (hasKeyLayout) {
- for (int i = 0; i < META_NUM; i++) {
+ for (size_t i = 0; i < size; i++) {
if (!flags[i]) {
mMetaState &= ~metaCodes[i];
}