Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 0ac62eb4 authored by Siarhei Vishniakou's avatar Siarhei Vishniakou
Browse files

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
Merged-In: I0d2ab6298bd41df6dc56120bf0385e10da6c3bfe
Change-Id: I0d2ab6298bd41df6dc56120bf0385e10da6c3bfe
parent efe6ae66
Loading
Loading
Loading
Loading
+4 −2
Original line number Diff line number Diff line
@@ -300,6 +300,8 @@ enum class InputDeviceConfigurationFileType : int32_t {
/*
 * Gets the path of an input device configuration file, if one is available.
 * Considers both system provided and user installed configuration files.
 * The optional suffix is appended to the end of the file name (before the
 * extension).
 *
 * The device identifier is used to construct several default configuration file
 * names to try based on the device name, vendor, product, and version.
@@ -307,8 +309,8 @@ enum class InputDeviceConfigurationFileType : int32_t {
 * Returns an empty string if not found.
 */
extern std::string getInputDeviceConfigurationFilePathByDeviceIdentifier(
        const InputDeviceIdentifier& deviceIdentifier,
        InputDeviceConfigurationFileType type);
        const InputDeviceIdentifier& deviceIdentifier, InputDeviceConfigurationFileType type,
        const char* suffix = "");

/*
 * Gets the path of an input device configuration file, if one is available.
+5 −1
Original line number Diff line number Diff line
@@ -22,6 +22,7 @@
#include <utils/Errors.h>
#include <utils/KeyedVector.h>
#include <utils/Tokenizer.h>
#include <set>

#include <input/InputDevice.h>

@@ -64,7 +65,8 @@ struct AxisInfo {
 */
class KeyLayoutMap {
public:
    static base::Result<std::shared_ptr<KeyLayoutMap>> load(const std::string& filename);
    static base::Result<std::shared_ptr<KeyLayoutMap>> load(const std::string& filename,
                                                            const char* contents = nullptr);
    static base::Result<std::shared_ptr<KeyLayoutMap>> loadContents(const std::string& filename,
                                                                    const char* contents);

@@ -104,6 +106,7 @@ private:
    KeyedVector<int32_t, Led> mLedsByScanCode;
    KeyedVector<int32_t, Led> mLedsByUsageCode;
    std::unordered_map<int32_t, Sensor> mSensorsByAbsCode;
    std::set<std::string> mRequiredKernelConfigs;
    std::string mLoadFileName;

    KeyLayoutMap();
@@ -124,6 +127,7 @@ private:
        status_t parseAxis();
        status_t parseLed();
        status_t parseSensor();
        status_t parseRequiredKernelConfig();
    };
};

+1 −3
Original line number Diff line number Diff line
@@ -62,8 +62,6 @@ private:
    status_t loadKeyLayout(const InputDeviceIdentifier& deviceIdentifier, const std::string& name);
    status_t loadKeyCharacterMap(const InputDeviceIdentifier& deviceIdentifier,
                                 const std::string& name);
    std::string getPath(const InputDeviceIdentifier& deviceIdentifier,
            const std::string& name, InputDeviceConfigurationFileType type);
};

/**
+1 −0
Original line number Diff line number Diff line
@@ -67,6 +67,7 @@ cc_library {
        "libbase",
        "liblog",
        "libcutils",
        "libvintf",
    ],

    static_libs: [
+18 −12
Original line number Diff line number Diff line
@@ -53,15 +53,18 @@ static void appendInputDeviceConfigurationFileRelativePath(std::string& path,
}

std::string getInputDeviceConfigurationFilePathByDeviceIdentifier(
        const InputDeviceIdentifier& deviceIdentifier,
        InputDeviceConfigurationFileType type) {
        const InputDeviceIdentifier& deviceIdentifier, InputDeviceConfigurationFileType type,
        const char* suffix) {
    if (deviceIdentifier.vendor !=0 && deviceIdentifier.product != 0) {
        if (deviceIdentifier.version != 0) {
            // Try vendor product version.
            std::string versionPath = getInputDeviceConfigurationFilePathByName(
                    StringPrintf("Vendor_%04x_Product_%04x_Version_%04x",
                            deviceIdentifier.vendor, deviceIdentifier.product,
                            deviceIdentifier.version),
            std::string versionPath =
                    getInputDeviceConfigurationFilePathByName(StringPrintf("Vendor_%04x_Product_%"
                                                                           "04x_Version_%04x%s",
                                                                           deviceIdentifier.vendor,
                                                                           deviceIdentifier.product,
                                                                           deviceIdentifier.version,
                                                                           suffix),
                                                              type);
            if (!versionPath.empty()) {
                return versionPath;
@@ -69,9 +72,11 @@ std::string getInputDeviceConfigurationFilePathByDeviceIdentifier(
        }

        // Try vendor product.
        std::string productPath = getInputDeviceConfigurationFilePathByName(
                StringPrintf("Vendor_%04x_Product_%04x",
                        deviceIdentifier.vendor, deviceIdentifier.product),
        std::string productPath =
                getInputDeviceConfigurationFilePathByName(StringPrintf("Vendor_%04x_Product_%04x%s",
                                                                       deviceIdentifier.vendor,
                                                                       deviceIdentifier.product,
                                                                       suffix),
                                                          type);
        if (!productPath.empty()) {
            return productPath;
@@ -79,7 +84,8 @@ std::string getInputDeviceConfigurationFilePathByDeviceIdentifier(
    }

    // Try device name.
    return getInputDeviceConfigurationFilePathByName(deviceIdentifier.getCanonicalName(), type);
    return getInputDeviceConfigurationFilePathByName(deviceIdentifier.getCanonicalName() + suffix,
                                                     type);
}

std::string getInputDeviceConfigurationFilePathByName(
Loading