Replace non-alphanumerics with _ in VirtualKeyMap
We currently rewrite device name for finding the matching .idc, .kl,
.kcm files, but we aren't allowing this for virtual key maps.
Rewrite the name for virtual devices to provide some flexibility in
matching for the right files in sys/board_properties.
Bug: 113575658
Test: atest libinput_tests inputflinger_tests
Change-Id: I54d159e9ecf02327cae388ae14c0bcf21c415e6e
diff --git a/libs/input/InputDevice.cpp b/libs/input/InputDevice.cpp
index 778c453..7dcad5a 100644
--- a/libs/input/InputDevice.cpp
+++ b/libs/input/InputDevice.cpp
@@ -140,6 +140,18 @@
return "";
}
+// --- InputDeviceIdentifier
+
+std::string InputDeviceIdentifier::getCanonicalName() const {
+ std::string replacedName = name;
+ for (char& ch : replacedName) {
+ if (!isValidNameChar(ch)) {
+ ch = '_';
+ }
+ }
+ return replacedName;
+}
+
// --- InputDeviceInfo ---