Loading include/input/KeyCharacterMap.h +3 −3 Original line number Diff line number Diff line Loading @@ -126,9 +126,9 @@ public: bool getEvents(int32_t deviceId, const char16_t* chars, size_t numChars, Vector<KeyEvent>& outEvents) const; /* Maps an Android key code to another Android key code. This mapping is applied after scanCode * and usageCodes are mapped to corresponding Android Keycode */ void addKeyRemapping(int32_t fromKeyCode, int32_t toKeyCode); /* Maps some Android key code to another Android key code. This mapping is applied after * scanCode and usageCodes are mapped to corresponding Android Keycode */ void setKeyRemapping(const std::map<int32_t, int32_t>& keyRemapping); /* Maps a scan code and usage code to a key code, in case this key map overrides * the mapping in some way. */ Loading libs/input/KeyCharacterMap.cpp +2 −13 Original line number Diff line number Diff line Loading @@ -317,19 +317,8 @@ bool KeyCharacterMap::getEvents(int32_t deviceId, const char16_t* chars, size_t return true; } void KeyCharacterMap::addKeyRemapping(int32_t fromKeyCode, int32_t toKeyCode) { if (fromKeyCode == toKeyCode) { mKeyRemapping.erase(fromKeyCode); #if DEBUG_MAPPING ALOGD("addKeyRemapping: Cleared remapping forKeyCode=%d ~ Result Successful.", fromKeyCode); #endif return; } mKeyRemapping.insert_or_assign(fromKeyCode, toKeyCode); #if DEBUG_MAPPING ALOGD("addKeyRemapping: fromKeyCode=%d, toKeyCode=%d ~ Result Successful.", fromKeyCode, toKeyCode); #endif void KeyCharacterMap::setKeyRemapping(const std::map<int32_t, int32_t>& keyRemapping) { mKeyRemapping = keyRemapping; } status_t KeyCharacterMap::mapKey(int32_t scanCode, int32_t usageCode, int32_t* outKeyCode) const { Loading services/inputflinger/include/InputReaderBase.h +6 −3 Original line number Diff line number Diff line Loading @@ -93,6 +93,9 @@ struct InputReaderConfiguration { // The touchpad settings changed. TOUCHPAD_SETTINGS = 1u << 13, // The key remapping has changed. KEY_REMAPPING = 1u << 14, // All devices must be reopened. MUST_REOPEN = 1u << 31, }; Loading Loading @@ -246,6 +249,9 @@ struct InputReaderConfiguration { // True if a pointer icon should be shown for direct stylus pointers. bool stylusPointerIconEnabled; // Keycodes to be remapped. std::map<int32_t /* fromKeyCode */, int32_t /* toKeyCode */> keyRemapping; InputReaderConfiguration() : virtualKeyQuietTime(0), defaultPointerDisplayId(ui::LogicalDisplayId::DEFAULT), Loading Loading @@ -333,9 +339,6 @@ public: virtual int32_t getKeyCodeState(int32_t deviceId, uint32_t sourceMask, int32_t keyCode) = 0; virtual int32_t getSwitchState(int32_t deviceId, uint32_t sourceMask, int32_t sw) = 0; virtual void addKeyRemapping(int32_t deviceId, int32_t fromKeyCode, int32_t toKeyCode) const = 0; virtual int32_t getKeyCodeForKeyLocation(int32_t deviceId, int32_t locationKeyCode) const = 0; /* Toggle Caps Lock */ Loading services/inputflinger/reader/EventHub.cpp +3 −2 Original line number Diff line number Diff line Loading @@ -1177,7 +1177,8 @@ bool EventHub::markSupportedKeyCodes(int32_t deviceId, const std::vector<int32_t return false; } void EventHub::addKeyRemapping(int32_t deviceId, int32_t fromKeyCode, int32_t toKeyCode) const { void EventHub::setKeyRemapping(int32_t deviceId, const std::map<int32_t, int32_t>& keyRemapping) const { std::scoped_lock _l(mLock); Device* device = getDeviceLocked(deviceId); if (device == nullptr) { Loading @@ -1185,7 +1186,7 @@ void EventHub::addKeyRemapping(int32_t deviceId, int32_t fromKeyCode, int32_t to } const std::shared_ptr<KeyCharacterMap> kcm = device->getKeyCharacterMap(); if (kcm) { kcm->addKeyRemapping(fromKeyCode, toKeyCode); kcm->setKeyRemapping(keyRemapping); } } Loading services/inputflinger/reader/InputDevice.cpp +12 −6 Original line number Diff line number Diff line Loading @@ -365,6 +365,18 @@ std::list<NotifyArgs> InputDevice::configureInternal(nsecs_t when, // so update the enabled state when there is a change in display info. out += updateEnableState(when, readerConfig, forceEnable); } if (!changes.any() || changes.test(InputReaderConfiguration::Change::KEY_REMAPPING)) { const bool isFullKeyboard = (mSources & AINPUT_SOURCE_KEYBOARD) == AINPUT_SOURCE_KEYBOARD && mKeyboardType == KeyboardType::ALPHABETIC; if (isFullKeyboard) { for_each_subdevice([&readerConfig](auto& context) { context.setKeyRemapping(readerConfig.keyRemapping); }); bumpGeneration(); } } } return out; } Loading Loading @@ -689,12 +701,6 @@ void InputDevice::updateMetaState(int32_t keyCode) { }); } void InputDevice::addKeyRemapping(int32_t fromKeyCode, int32_t toKeyCode) { for_each_subdevice([fromKeyCode, toKeyCode](auto& context) { context.addKeyRemapping(fromKeyCode, toKeyCode); }); } void InputDevice::bumpGeneration() { mGeneration = mContext->bumpGeneration(); } Loading Loading
include/input/KeyCharacterMap.h +3 −3 Original line number Diff line number Diff line Loading @@ -126,9 +126,9 @@ public: bool getEvents(int32_t deviceId, const char16_t* chars, size_t numChars, Vector<KeyEvent>& outEvents) const; /* Maps an Android key code to another Android key code. This mapping is applied after scanCode * and usageCodes are mapped to corresponding Android Keycode */ void addKeyRemapping(int32_t fromKeyCode, int32_t toKeyCode); /* Maps some Android key code to another Android key code. This mapping is applied after * scanCode and usageCodes are mapped to corresponding Android Keycode */ void setKeyRemapping(const std::map<int32_t, int32_t>& keyRemapping); /* Maps a scan code and usage code to a key code, in case this key map overrides * the mapping in some way. */ Loading
libs/input/KeyCharacterMap.cpp +2 −13 Original line number Diff line number Diff line Loading @@ -317,19 +317,8 @@ bool KeyCharacterMap::getEvents(int32_t deviceId, const char16_t* chars, size_t return true; } void KeyCharacterMap::addKeyRemapping(int32_t fromKeyCode, int32_t toKeyCode) { if (fromKeyCode == toKeyCode) { mKeyRemapping.erase(fromKeyCode); #if DEBUG_MAPPING ALOGD("addKeyRemapping: Cleared remapping forKeyCode=%d ~ Result Successful.", fromKeyCode); #endif return; } mKeyRemapping.insert_or_assign(fromKeyCode, toKeyCode); #if DEBUG_MAPPING ALOGD("addKeyRemapping: fromKeyCode=%d, toKeyCode=%d ~ Result Successful.", fromKeyCode, toKeyCode); #endif void KeyCharacterMap::setKeyRemapping(const std::map<int32_t, int32_t>& keyRemapping) { mKeyRemapping = keyRemapping; } status_t KeyCharacterMap::mapKey(int32_t scanCode, int32_t usageCode, int32_t* outKeyCode) const { Loading
services/inputflinger/include/InputReaderBase.h +6 −3 Original line number Diff line number Diff line Loading @@ -93,6 +93,9 @@ struct InputReaderConfiguration { // The touchpad settings changed. TOUCHPAD_SETTINGS = 1u << 13, // The key remapping has changed. KEY_REMAPPING = 1u << 14, // All devices must be reopened. MUST_REOPEN = 1u << 31, }; Loading Loading @@ -246,6 +249,9 @@ struct InputReaderConfiguration { // True if a pointer icon should be shown for direct stylus pointers. bool stylusPointerIconEnabled; // Keycodes to be remapped. std::map<int32_t /* fromKeyCode */, int32_t /* toKeyCode */> keyRemapping; InputReaderConfiguration() : virtualKeyQuietTime(0), defaultPointerDisplayId(ui::LogicalDisplayId::DEFAULT), Loading Loading @@ -333,9 +339,6 @@ public: virtual int32_t getKeyCodeState(int32_t deviceId, uint32_t sourceMask, int32_t keyCode) = 0; virtual int32_t getSwitchState(int32_t deviceId, uint32_t sourceMask, int32_t sw) = 0; virtual void addKeyRemapping(int32_t deviceId, int32_t fromKeyCode, int32_t toKeyCode) const = 0; virtual int32_t getKeyCodeForKeyLocation(int32_t deviceId, int32_t locationKeyCode) const = 0; /* Toggle Caps Lock */ Loading
services/inputflinger/reader/EventHub.cpp +3 −2 Original line number Diff line number Diff line Loading @@ -1177,7 +1177,8 @@ bool EventHub::markSupportedKeyCodes(int32_t deviceId, const std::vector<int32_t return false; } void EventHub::addKeyRemapping(int32_t deviceId, int32_t fromKeyCode, int32_t toKeyCode) const { void EventHub::setKeyRemapping(int32_t deviceId, const std::map<int32_t, int32_t>& keyRemapping) const { std::scoped_lock _l(mLock); Device* device = getDeviceLocked(deviceId); if (device == nullptr) { Loading @@ -1185,7 +1186,7 @@ void EventHub::addKeyRemapping(int32_t deviceId, int32_t fromKeyCode, int32_t to } const std::shared_ptr<KeyCharacterMap> kcm = device->getKeyCharacterMap(); if (kcm) { kcm->addKeyRemapping(fromKeyCode, toKeyCode); kcm->setKeyRemapping(keyRemapping); } } Loading
services/inputflinger/reader/InputDevice.cpp +12 −6 Original line number Diff line number Diff line Loading @@ -365,6 +365,18 @@ std::list<NotifyArgs> InputDevice::configureInternal(nsecs_t when, // so update the enabled state when there is a change in display info. out += updateEnableState(when, readerConfig, forceEnable); } if (!changes.any() || changes.test(InputReaderConfiguration::Change::KEY_REMAPPING)) { const bool isFullKeyboard = (mSources & AINPUT_SOURCE_KEYBOARD) == AINPUT_SOURCE_KEYBOARD && mKeyboardType == KeyboardType::ALPHABETIC; if (isFullKeyboard) { for_each_subdevice([&readerConfig](auto& context) { context.setKeyRemapping(readerConfig.keyRemapping); }); bumpGeneration(); } } } return out; } Loading Loading @@ -689,12 +701,6 @@ void InputDevice::updateMetaState(int32_t keyCode) { }); } void InputDevice::addKeyRemapping(int32_t fromKeyCode, int32_t toKeyCode) { for_each_subdevice([fromKeyCode, toKeyCode](auto& context) { context.addKeyRemapping(fromKeyCode, toKeyCode); }); } void InputDevice::bumpGeneration() { mGeneration = mContext->bumpGeneration(); } Loading