From e5657f27c9ffc22c9f198bc765dd92c0aac4240d Mon Sep 17 00:00:00 2001 From: Linnan Li Date: Fri, 13 Sep 2024 21:54:37 +0800 Subject: Move key remapping to InputReader thread(1/n) Currently, the key remapping operation occurs on a non-Reader thread, which leads to concurrent operations on the KCM object by this thread and the Reader, causing unpredictable concurrency issues. Here, we move this operation to the Reader thread, aligning it with most configuration refresh methods, which can resolve the aforementioned issues. Additionally, we are removing the device traversal method on the Java side because we actually intend for the key remapping operation to apply to all full-keyboard devices. This can be fully achieved during the InputReader refresh, so we are also removing the deviceId parameter from the remapping interface. There should be no behavioral changes. Bug: 358042225 Test: atest CtsInputTestCases Test: atest InputTests Test: atest inputflinger_tests Flag: EXEMPT refactor Change-Id: I6ab802b70dc1242c796f672ac30672d10e34857f Signed-off-by: Linnan Li --- libs/input/KeyCharacterMap.cpp | 15 ++------------- 1 file changed, 2 insertions(+), 13 deletions(-) (limited to 'libs/input/KeyCharacterMap.cpp') diff --git a/libs/input/KeyCharacterMap.cpp b/libs/input/KeyCharacterMap.cpp index 1cf5612d45..b0563abaf7 100644 --- a/libs/input/KeyCharacterMap.cpp +++ b/libs/input/KeyCharacterMap.cpp @@ -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& keyRemapping) { + mKeyRemapping = keyRemapping; } status_t KeyCharacterMap::mapKey(int32_t scanCode, int32_t usageCode, int32_t* outKeyCode) const { -- cgit v1.2.3-59-g8ed1b