@@ -390,15 +390,6 @@ int32_t KeyboardInputMapper::getMetaState() {
390390 return mMetaState ;
391391}
392392
393- bool KeyboardInputMapper::updateMetaState (int32_t keyCode) {
394- if (!android::isMetaKey (keyCode) || !getDeviceContext ().hasKeyCode (keyCode)) {
395- return false ;
396- }
397-
398- updateMetaStateIfNeeded (keyCode, false );
399- return true ;
400- }
401-
402393bool KeyboardInputMapper::updateMetaStateIfNeeded (int32_t keyCode, bool down) {
403394 int32_t oldMetaState = mMetaState ;
404395 int32_t newMetaState = android::updateMetaState (keyCode, down, oldMetaState);
@@ -434,17 +425,21 @@ void KeyboardInputMapper::updateLedState(bool reset) {
434425 mMetaState &= ~(AMETA_CAPS_LOCK_ON | AMETA_NUM_LOCK_ON | AMETA_SCROLL_LOCK_ON);
435426 mMetaState |= getContext ()->getLedMetaState ();
436427
437- constexpr int32_t META_NUM = 3 ;
438- const std::vector<int32_t > keyCodes{AKEYCODE_CAPS_LOCK, AKEYCODE_NUM_LOCK,
439- AKEYCODE_SCROLL_LOCK};
440- const std::array<int32_t , META_NUM> metaCodes = {AMETA_CAPS_LOCK_ON, AMETA_NUM_LOCK_ON,
441- AMETA_SCROLL_LOCK_ON};
442- std::array<uint8_t , META_NUM> flags = {0 , 0 , 0 };
443- bool hasKeyLayout = getDeviceContext ().markSupportedKeyCodes (keyCodes, flags.data ());
428+ std::vector<int32_t > keyCodesToCheck{AKEYCODE_NUM_LOCK, AKEYCODE_SCROLL_LOCK};
429+ std::vector<int32_t > metaCodes{AMETA_NUM_LOCK_ON, AMETA_SCROLL_LOCK_ON};
430+ // Check for physical CapsLock key only for non-alphabetic keyboards. For Alphabetic
431+ // keyboards, we will allow Caps Lock even if there is no physical CapsLock key.
432+ if (getDeviceContext ().getKeyboardType () != KeyboardType::ALPHABETIC) {
433+ keyCodesToCheck.push_back (AKEYCODE_CAPS_LOCK);
434+ metaCodes.push_back (AMETA_CAPS_LOCK_ON);
435+ }
436+ size_t size = keyCodesToCheck.size ();
437+ std::vector<uint8_t > flags (size, 0 );
438+ bool hasKeyLayout = getDeviceContext ().markSupportedKeyCodes (keyCodesToCheck, flags.data ());
444439 // If the device doesn't have the physical meta key it shouldn't generate the corresponding
445440 // meta state.
446441 if (hasKeyLayout) {
447- for (int i = 0 ; i < META_NUM ; i++) {
442+ for (size_t i = 0 ; i < size ; i++) {
448443 if (!flags[i]) {
449444 mMetaState &= ~metaCodes[i];
450445 }
0 commit comments