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

Commit 7e32c880 authored by TreeHugger Robot's avatar TreeHugger Robot Committed by Android (Google) Code Review
Browse files

Merge "Replace non-alphanumerics with _ in VirtualKeyMap"

parents b645f7ef b45635c8
Loading
Loading
Loading
Loading
+9 −0
Original line number Diff line number Diff line
@@ -51,6 +51,15 @@ struct InputDeviceIdentifier {
    // is intended to be a minimum way to distinguish from other active devices and may
    // reuse values that are not associated with an input anymore.
    uint16_t nonce;

    /**
     * Return InputDeviceIdentifier.name that has been adjusted as follows:
     *     - all characters besides alphanumerics, dash,
     *       and underscore have been replaced with underscores.
     * This helps in situations where a file that matches the device name is needed,
     * while conforming to the filename limitations.
     */
    std::string getCanonicalName() const;
};

/*
+12 −0
Original line number Diff line number Diff line
@@ -140,6 +140,18 @@ std::string getInputDeviceConfigurationFilePathByName(
    return "";
}

// --- InputDeviceIdentifier

std::string InputDeviceIdentifier::getCanonicalName() const {
    std::string replacedName = name;
    for (char& ch : replacedName) {
        if (!isValidNameChar(ch)) {
            ch = '_';
        }
    }
    return replacedName;
}


// --- InputDeviceInfo ---

+1 −1
Original line number Diff line number Diff line
@@ -1617,7 +1617,7 @@ bool EventHub::loadVirtualKeyMapLocked(Device* device) {
    // The virtual key map is supplied by the kernel as a system board property file.
    std::string path;
    path += "/sys/board_properties/virtualkeys.";
    path += device->identifier.name;
    path += device->identifier.getCanonicalName();
    if (access(path.c_str(), R_OK)) {
        return false;
    }