Loading services/inputflinger/include/InputReaderBase.h +2 −0 Original line number Diff line number Diff line Loading @@ -87,6 +87,8 @@ public: virtual int32_t getSwitchState(int32_t deviceId, uint32_t sourceMask, int32_t sw) = 0; virtual int32_t getKeyCodeForKeyLocation(int32_t deviceId, int32_t locationKeyCode) const = 0; /* Toggle Caps Lock */ virtual void toggleCapsLockState(int32_t deviceId) = 0; Loading services/inputflinger/reader/EventHub.cpp +36 −0 Original line number Diff line number Diff line Loading @@ -880,6 +880,42 @@ int32_t EventHub::getKeyCodeState(int32_t deviceId, int32_t keyCode) const { return AKEY_STATE_UNKNOWN; } int32_t EventHub::getKeyCodeForKeyLocation(int32_t deviceId, int32_t locationKeyCode) const { std::scoped_lock _l(mLock); Device* device = getDeviceLocked(deviceId); if (device == nullptr || !device->hasValidFd() || device->keyMap.keyCharacterMap == nullptr || device->keyMap.keyLayoutMap == nullptr) { return AKEYCODE_UNKNOWN; } std::vector<int32_t> scanCodes; device->keyMap.keyLayoutMap->findScanCodesForKey(locationKeyCode, &scanCodes); if (scanCodes.empty()) { ALOGW("Failed to get key code for key location: no scan code maps to key code %d for input" "device %d", locationKeyCode, deviceId); return AKEYCODE_UNKNOWN; } if (scanCodes.size() > 1) { ALOGW("Multiple scan codes map to the same key code %d, returning only the first match", locationKeyCode); } int32_t outKeyCode; status_t mapKeyRes = device->getKeyCharacterMap()->mapKey(scanCodes[0], 0 /*usageCode*/, &outKeyCode); switch (mapKeyRes) { case OK: return outKeyCode; case NAME_NOT_FOUND: // key character map doesn't re-map this scanCode, hence the keyCode remains the same return locationKeyCode; default: ALOGW("Failed to get key code for key location: Key character map returned error %s", statusToString(mapKeyRes).c_str()); return AKEYCODE_UNKNOWN; } } int32_t EventHub::getSwitchState(int32_t deviceId, int32_t sw) const { if (sw >= 0 && sw <= SW_MAX) { std::scoped_lock _l(mLock); Loading services/inputflinger/reader/InputDevice.cpp +17 −0 Original line number Diff line number Diff line Loading @@ -475,6 +475,23 @@ bool InputDevice::markSupportedKeyCodes(uint32_t sourceMask, size_t numCodes, return result; } int32_t InputDevice::getKeyCodeForKeyLocation(int32_t locationKeyCode) const { std::optional<int32_t> result = first_in_mappers<int32_t>( [locationKeyCode](const InputMapper& mapper) -> std::optional<int32_t> const { if (sourcesMatchMask(mapper.getSources(), AINPUT_SOURCE_KEYBOARD)) { return std::make_optional(mapper.getKeyCodeForKeyLocation(locationKeyCode)); } return std::nullopt; }); if (!result) { ALOGE("Failed to get key code for key location: No matching InputMapper with source mask " "KEYBOARD found. The provided input device with id %d has sources %s.", getId(), inputEventSourceToString(getSources()).c_str()); return AKEYCODE_UNKNOWN; } return *result; } void InputDevice::vibrate(const VibrationSequence& sequence, ssize_t repeat, int32_t token) { for_each_mapper([sequence, repeat, token](InputMapper& mapper) { mapper.vibrate(sequence, repeat, token); Loading services/inputflinger/reader/InputReader.cpp +13 −1 Original line number Diff line number Diff line Loading @@ -303,7 +303,7 @@ void InputReader::processEventsForDeviceLocked(int32_t eventHubId, const RawEven device->process(rawEvents, count); } InputDevice* InputReader::findInputDeviceLocked(int32_t deviceId) { InputDevice* InputReader::findInputDeviceLocked(int32_t deviceId) const { auto deviceIt = std::find_if(mDevices.begin(), mDevices.end(), [deviceId](const auto& devicePair) { return devicePair.second->getId() == deviceId; Loading Loading @@ -589,6 +589,18 @@ bool InputReader::markSupportedKeyCodesLocked(int32_t deviceId, uint32_t sourceM return result; } int32_t InputReader::getKeyCodeForKeyLocation(int32_t deviceId, int32_t locationKeyCode) const { std::scoped_lock _l(mLock); InputDevice* device = findInputDeviceLocked(deviceId); if (device == nullptr) { ALOGW("Failed to get key code for key location: Input device with id %d not found", deviceId); return AKEYCODE_UNKNOWN; } return device->getKeyCodeForKeyLocation(locationKeyCode); } void InputReader::requestRefreshConfiguration(uint32_t changes) { std::scoped_lock _l(mLock); Loading services/inputflinger/reader/include/EventHub.h +3 −0 Original line number Diff line number Diff line Loading @@ -306,6 +306,7 @@ public: virtual int32_t getSwitchState(int32_t deviceId, int32_t sw) const = 0; virtual status_t getAbsoluteAxisValue(int32_t deviceId, int32_t axis, int32_t* outValue) const = 0; virtual int32_t getKeyCodeForKeyLocation(int32_t deviceId, int32_t locationKeyCode) const = 0; /* * Examine key input devices for specific framework keycode support Loading Loading @@ -482,6 +483,8 @@ public: int32_t getScanCodeState(int32_t deviceId, int32_t scanCode) const override final; int32_t getKeyCodeState(int32_t deviceId, int32_t keyCode) const override final; int32_t getSwitchState(int32_t deviceId, int32_t sw) const override final; int32_t getKeyCodeForKeyLocation(int32_t deviceId, int32_t locationKeyCode) const override final; status_t getAbsoluteAxisValue(int32_t deviceId, int32_t axis, int32_t* outValue) const override final; Loading Loading
services/inputflinger/include/InputReaderBase.h +2 −0 Original line number Diff line number Diff line Loading @@ -87,6 +87,8 @@ public: virtual int32_t getSwitchState(int32_t deviceId, uint32_t sourceMask, int32_t sw) = 0; virtual int32_t getKeyCodeForKeyLocation(int32_t deviceId, int32_t locationKeyCode) const = 0; /* Toggle Caps Lock */ virtual void toggleCapsLockState(int32_t deviceId) = 0; Loading
services/inputflinger/reader/EventHub.cpp +36 −0 Original line number Diff line number Diff line Loading @@ -880,6 +880,42 @@ int32_t EventHub::getKeyCodeState(int32_t deviceId, int32_t keyCode) const { return AKEY_STATE_UNKNOWN; } int32_t EventHub::getKeyCodeForKeyLocation(int32_t deviceId, int32_t locationKeyCode) const { std::scoped_lock _l(mLock); Device* device = getDeviceLocked(deviceId); if (device == nullptr || !device->hasValidFd() || device->keyMap.keyCharacterMap == nullptr || device->keyMap.keyLayoutMap == nullptr) { return AKEYCODE_UNKNOWN; } std::vector<int32_t> scanCodes; device->keyMap.keyLayoutMap->findScanCodesForKey(locationKeyCode, &scanCodes); if (scanCodes.empty()) { ALOGW("Failed to get key code for key location: no scan code maps to key code %d for input" "device %d", locationKeyCode, deviceId); return AKEYCODE_UNKNOWN; } if (scanCodes.size() > 1) { ALOGW("Multiple scan codes map to the same key code %d, returning only the first match", locationKeyCode); } int32_t outKeyCode; status_t mapKeyRes = device->getKeyCharacterMap()->mapKey(scanCodes[0], 0 /*usageCode*/, &outKeyCode); switch (mapKeyRes) { case OK: return outKeyCode; case NAME_NOT_FOUND: // key character map doesn't re-map this scanCode, hence the keyCode remains the same return locationKeyCode; default: ALOGW("Failed to get key code for key location: Key character map returned error %s", statusToString(mapKeyRes).c_str()); return AKEYCODE_UNKNOWN; } } int32_t EventHub::getSwitchState(int32_t deviceId, int32_t sw) const { if (sw >= 0 && sw <= SW_MAX) { std::scoped_lock _l(mLock); Loading
services/inputflinger/reader/InputDevice.cpp +17 −0 Original line number Diff line number Diff line Loading @@ -475,6 +475,23 @@ bool InputDevice::markSupportedKeyCodes(uint32_t sourceMask, size_t numCodes, return result; } int32_t InputDevice::getKeyCodeForKeyLocation(int32_t locationKeyCode) const { std::optional<int32_t> result = first_in_mappers<int32_t>( [locationKeyCode](const InputMapper& mapper) -> std::optional<int32_t> const { if (sourcesMatchMask(mapper.getSources(), AINPUT_SOURCE_KEYBOARD)) { return std::make_optional(mapper.getKeyCodeForKeyLocation(locationKeyCode)); } return std::nullopt; }); if (!result) { ALOGE("Failed to get key code for key location: No matching InputMapper with source mask " "KEYBOARD found. The provided input device with id %d has sources %s.", getId(), inputEventSourceToString(getSources()).c_str()); return AKEYCODE_UNKNOWN; } return *result; } void InputDevice::vibrate(const VibrationSequence& sequence, ssize_t repeat, int32_t token) { for_each_mapper([sequence, repeat, token](InputMapper& mapper) { mapper.vibrate(sequence, repeat, token); Loading
services/inputflinger/reader/InputReader.cpp +13 −1 Original line number Diff line number Diff line Loading @@ -303,7 +303,7 @@ void InputReader::processEventsForDeviceLocked(int32_t eventHubId, const RawEven device->process(rawEvents, count); } InputDevice* InputReader::findInputDeviceLocked(int32_t deviceId) { InputDevice* InputReader::findInputDeviceLocked(int32_t deviceId) const { auto deviceIt = std::find_if(mDevices.begin(), mDevices.end(), [deviceId](const auto& devicePair) { return devicePair.second->getId() == deviceId; Loading Loading @@ -589,6 +589,18 @@ bool InputReader::markSupportedKeyCodesLocked(int32_t deviceId, uint32_t sourceM return result; } int32_t InputReader::getKeyCodeForKeyLocation(int32_t deviceId, int32_t locationKeyCode) const { std::scoped_lock _l(mLock); InputDevice* device = findInputDeviceLocked(deviceId); if (device == nullptr) { ALOGW("Failed to get key code for key location: Input device with id %d not found", deviceId); return AKEYCODE_UNKNOWN; } return device->getKeyCodeForKeyLocation(locationKeyCode); } void InputReader::requestRefreshConfiguration(uint32_t changes) { std::scoped_lock _l(mLock); Loading
services/inputflinger/reader/include/EventHub.h +3 −0 Original line number Diff line number Diff line Loading @@ -306,6 +306,7 @@ public: virtual int32_t getSwitchState(int32_t deviceId, int32_t sw) const = 0; virtual status_t getAbsoluteAxisValue(int32_t deviceId, int32_t axis, int32_t* outValue) const = 0; virtual int32_t getKeyCodeForKeyLocation(int32_t deviceId, int32_t locationKeyCode) const = 0; /* * Examine key input devices for specific framework keycode support Loading Loading @@ -482,6 +483,8 @@ public: int32_t getScanCodeState(int32_t deviceId, int32_t scanCode) const override final; int32_t getKeyCodeState(int32_t deviceId, int32_t keyCode) const override final; int32_t getSwitchState(int32_t deviceId, int32_t sw) const override final; int32_t getKeyCodeForKeyLocation(int32_t deviceId, int32_t locationKeyCode) const override final; status_t getAbsoluteAxisValue(int32_t deviceId, int32_t axis, int32_t* outValue) const override final; Loading