diff options
author | 2022-05-18 09:42:52 -0700 | |
---|---|---|
committer | 2022-06-16 17:35:36 +0000 | |
commit | d945d3e55ecd98d6554a9fdf6dfa1beb1c64a189 (patch) | |
tree | 3495973415e51d81fd3113af36d89533fbcce665 /libs/input/Keyboard.cpp | |
parent | 3dee0df77f44dd85b0f03b14db7966e1ba8faeb3 (diff) |
Do not load keylayout if required kernel module is missing
Some key layouts require the presence of a specific kernel module. If
the kernel module is not present, the layout should not be loaded.
In this CL, we add an option to specify which kernel modules / configs
are needed inside the kl file.
Bug: 228005926
Test: atest libinput_tests
Change-Id: I0d2ab6298bd41df6dc56120bf0385e10da6c3bfe
Merged-In: I0d2ab6298bd41df6dc56120bf0385e10da6c3bfe
Diffstat (limited to 'libs/input/Keyboard.cpp')
-rw-r--r-- | libs/input/Keyboard.cpp | 39 |
1 files changed, 26 insertions, 13 deletions
diff --git a/libs/input/Keyboard.cpp b/libs/input/Keyboard.cpp index f0895b32ef..c3f5151fd1 100644 --- a/libs/input/Keyboard.cpp +++ b/libs/input/Keyboard.cpp @@ -20,16 +20,23 @@ #include <unistd.h> #include <limits.h> -#include <input/Keyboard.h> +#include <input/InputDevice.h> #include <input/InputEventLabels.h> -#include <input/KeyLayoutMap.h> #include <input/KeyCharacterMap.h> -#include <input/InputDevice.h> +#include <input/KeyLayoutMap.h> +#include <input/Keyboard.h> +#include <log/log.h> #include <utils/Errors.h> -#include <utils/Log.h> namespace android { +static std::string getPath(const InputDeviceIdentifier& deviceIdentifier, const std::string& name, + InputDeviceConfigurationFileType type) { + return name.empty() + ? getInputDeviceConfigurationFilePathByDeviceIdentifier(deviceIdentifier, type) + : getInputDeviceConfigurationFilePathByName(name, type); +} + // --- KeyMap --- KeyMap::KeyMap() { @@ -111,11 +118,25 @@ status_t KeyMap::loadKeyLayout(const InputDeviceIdentifier& deviceIdentifier, } base::Result<std::shared_ptr<KeyLayoutMap>> ret = KeyLayoutMap::load(path); + if (ret.ok()) { + keyLayoutMap = *ret; + keyLayoutFile = path; + return OK; + } + + // Try to load fallback layout if the regular layout could not be loaded due to missing + // kernel modules + std::string fallbackPath( + getInputDeviceConfigurationFilePathByDeviceIdentifier(deviceIdentifier, + InputDeviceConfigurationFileType:: + KEY_LAYOUT, + "_fallback")); + ret = KeyLayoutMap::load(fallbackPath); if (!ret.ok()) { return ret.error().code(); } keyLayoutMap = *ret; - keyLayoutFile = path; + keyLayoutFile = fallbackPath; return OK; } @@ -137,14 +158,6 @@ status_t KeyMap::loadKeyCharacterMap(const InputDeviceIdentifier& deviceIdentifi return OK; } -std::string KeyMap::getPath(const InputDeviceIdentifier& deviceIdentifier, - const std::string& name, InputDeviceConfigurationFileType type) { - return name.empty() - ? getInputDeviceConfigurationFilePathByDeviceIdentifier(deviceIdentifier, type) - : getInputDeviceConfigurationFilePathByName(name, type); -} - - // --- Global functions --- bool isKeyboardSpecialFunction(const PropertyMap* config) { |