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

Commit 1145152e authored by Alexander Hofbauer's avatar Alexander Hofbauer
Browse files

InputManager: Add system setting to define keyboard locales

KEYLAYOUT_OVERRIDES expects a string of "devicename,layoutfile" to set
keyboard layout and character map to files in /system/usr/keylayout and
/system/user/keychars.

This overrides the default behaviour of opening files that match the
device's input name if there's no configuration file.
parent fdd9ce35
Loading
Loading
Loading
Loading
+8 −0
Original line number Diff line number Diff line
@@ -2008,6 +2008,13 @@ public final class Settings {
         */
        public static final String SHOW_TOUCHES = "show_touches";

        /**
         * The keylayout that will be used by EventHub instead of the default
         * one.
	 * @hide
         */
        public static final String KEYLAYOUT_OVERRIDES = "keylayout";

        /**
         * Log raw orientation data from {@link WindowOrientationListener} for use with the
         * orientationplot.py tool.
@@ -2465,6 +2472,7 @@ public final class Settings {
            QUIET_HOURS_MUTE,
            QUIET_HOURS_STILL,
            QUIET_HOURS_DIM,
            KEYLAYOUT_OVERRIDES,
        };

        // Settings moved to Settings.Secure
+14 −0
Original line number Diff line number Diff line
@@ -1016,6 +1016,16 @@ status_t EventHub::openDeviceLocked(const char *devicePath) {
    // We need to do this for joysticks too because the key layout may specify axes.
    status_t keyMapStatus = NAME_NOT_FOUND;
    if (device->classes & (INPUT_DEVICE_CLASS_KEYBOARD | INPUT_DEVICE_CLASS_JOYSTICK)) {
        String8 layout;
        if (mOrKeyLayouts.tryGetProperty(device->identifier.name, layout)) {
            LOGI("Replacing key layout and character map of %s with %s",
                    device->identifier.name.string(), layout.string());
            if (!device->configuration) {
                device->configuration = new PropertyMap();
            }
            device->configuration->addProperty(String8("keyboard.layout"), layout);
            device->configuration->addProperty(String8("keyboard.characterMap"), layout);
        }
        // Load the keymap for the device.
        keyMapStatus = loadKeyMapLocked(device);
    }
@@ -1333,5 +1343,9 @@ void EventHub::monitor() {
    mLock.unlock();
}

void EventHub::setKeyLayout(const char* deviceName, const char* keyLayout) {
    mOrKeyLayouts.addProperty(String8(deviceName), String8(keyLayout));
}


}; // namespace android
+7 −0
Original line number Diff line number Diff line
@@ -221,6 +221,8 @@ public:

    /* Called by the heatbeat to ensures that the reader has not deadlocked. */
    virtual void monitor() = 0;

    virtual void setKeyLayout(const char* deviceName, const char* keyLayout) = 0;
};

class EventHub : public EventHubInterface
@@ -275,6 +277,8 @@ public:
    virtual void dump(String8& dump);
    virtual void monitor();

    virtual void setKeyLayout(const char* deviceName, const char* keyLayout);

protected:
    virtual ~EventHub();

@@ -370,6 +374,9 @@ private:

    // Set to the number of CPUs.
    int32_t mNumCpus;

    // List of key layouts and character maps to be overridden
    PropertyMap mOrKeyLayouts;
};

}; // namespace android
+5 −0
Original line number Diff line number Diff line
@@ -700,6 +700,11 @@ void InputReader::requestRefreshConfiguration(uint32_t changes) {
    }
}

void InputReader::setKeyLayout(const char* deviceName, const char* keyLayout) {
    AutoMutex _l(mLock);
    mEventHub->setKeyLayout(deviceName, keyLayout);
}

void InputReader::dump(String8& dump) {
    AutoMutex _l(mLock);

+6 −0
Original line number Diff line number Diff line
@@ -267,6 +267,10 @@ public:
     * The changes flag is a bitfield that indicates what has changed and whether
     * the input devices must all be reopened. */
    virtual void requestRefreshConfiguration(uint32_t changes) = 0;

    /* Sets a specific input device's keyLayout to be overridden by filename.
     */
    virtual void setKeyLayout(const char* deviceName, const char* keyLayout) = 0;
};


@@ -335,6 +339,8 @@ public:

    virtual void requestRefreshConfiguration(uint32_t changes);

    virtual void setKeyLayout(const char* deviceName, const char* keyLayout);

protected:
    // These members are protected so they can be instrumented by test cases.
    virtual InputDevice* createDeviceLocked(int32_t deviceId,
Loading