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

Commit 1e08fe90 authored by Jeff Brown's avatar Jeff Brown
Browse files

Eliminate hw.keyboards system properties.

Stop using system properties to publish information about
the key character map path.  Instead, we can retrieve it
on demand by asking the window manager.

It was possible to exhaust the supply of system properties
when repeatedly adding and removing input devices.

Bug: 5532806
Change-Id: Idd361a24ad7db2edc185c8546db7fb05f9c28669
parent 9058435d
Loading
Loading
Loading
Loading
+9 −1
Original line number Diff line number Diff line
@@ -19,7 +19,6 @@ package android.view;
import android.os.Parcel;
import android.os.Parcelable;
import android.os.RemoteException;
import android.os.ServiceManager;

import java.util.ArrayList;
import java.util.List;
@@ -44,6 +43,7 @@ public final class InputDevice implements Parcelable {
    private String mName;
    private int mSources;
    private int mKeyboardType;
    private String mKeyCharacterMapFile;

    private final ArrayList<MotionRange> mMotionRanges = new ArrayList<MotionRange>();

@@ -360,6 +360,10 @@ public final class InputDevice implements Parcelable {
        return KeyCharacterMap.load(mId);
    }

    String getKeyCharacterMapFile() {
        return mKeyCharacterMapFile;
    }

    /**
     * Gets information about the range of values for a particular {@link MotionEvent} axis.
     * If the device supports multiple sources, the same axis may have different meanings
@@ -532,6 +536,7 @@ public final class InputDevice implements Parcelable {
        mName = in.readString();
        mSources = in.readInt();
        mKeyboardType = in.readInt();
        mKeyCharacterMapFile = in.readString();

        for (;;) {
            int axis = in.readInt();
@@ -549,6 +554,7 @@ public final class InputDevice implements Parcelable {
        out.writeString(mName);
        out.writeInt(mSources);
        out.writeInt(mKeyboardType);
        out.writeString(mKeyCharacterMapFile);

        final int numRanges = mMotionRanges.size();
        for (int i = 0; i < numRanges; i++) {
@@ -587,6 +593,8 @@ public final class InputDevice implements Parcelable {
        }
        description.append("\n");

        description.append("  Key Character Map: ").append(mKeyCharacterMapFile).append("\n");

        description.append("  Sources: 0x").append(Integer.toHexString(mSources)).append(" (");
        appendSourceDescriptionIfApplicable(description, SOURCE_KEYBOARD, "keyboard");
        appendSourceDescriptionIfApplicable(description, SOURCE_DPAD, "dpad");
+12 −3
Original line number Diff line number Diff line
@@ -20,7 +20,6 @@ import android.text.method.MetaKeyKeyListener;
import android.util.AndroidRuntimeException;
import android.util.SparseIntArray;
import android.os.RemoteException;
import android.os.ServiceManager;
import android.util.SparseArray;

import java.lang.Character;
@@ -140,7 +139,7 @@ public class KeyCharacterMap {
    private final int mDeviceId;
    private int mPtr;

    private static native int nativeLoad(int id);
    private static native int nativeLoad(String file);
    private static native void nativeDispose(int ptr);

    private static native char nativeGetCharacter(int ptr, int keyCode, int metaState);
@@ -178,7 +177,17 @@ public class KeyCharacterMap {
        synchronized (sInstances) {
            KeyCharacterMap map = sInstances.get(deviceId);
            if (map == null) {
                int ptr = nativeLoad(deviceId); // might throw
                String kcm = null;
                if (deviceId != VIRTUAL_KEYBOARD) {
                    InputDevice device = InputDevice.getDevice(deviceId);
                    if (device != null) {
                        kcm = device.getKeyCharacterMapFile();
                    }
                }
                if (kcm == null || kcm.length() == 0) {
                    kcm = "/system/usr/keychars/Virtual.kcm";
                }
                int ptr = nativeLoad(kcm); // might throw
                map = new KeyCharacterMap(deviceId, ptr);
                sInstances.put(deviceId, map);
            }
+14 −7
Original line number Diff line number Diff line
@@ -35,18 +35,25 @@ static struct {
} gFallbackActionClassInfo;


static jint nativeLoad(JNIEnv *env, jobject clazz, jint deviceId) {
static jint nativeLoad(JNIEnv *env, jobject clazz, jstring fileStr) {
    const char* file = env->GetStringUTFChars(fileStr, NULL);

    KeyCharacterMap* map;
    status_t status = KeyCharacterMap::loadByDeviceId(deviceId, &map);
    status_t status = KeyCharacterMap::load(String8(file), &map);
    jint result;
    if (status) {
        String8 msg;
        msg.appendFormat("Could not load key character map for device %d due to error %d.  "
                "Refer to the log for details.", deviceId, status);
        msg.appendFormat("Could not load key character map '%s' due to error %d.  "
                "Refer to the log for details.", file, status);
        jniThrowException(env, "android/view/KeyCharacterMap$KeyCharacterMapUnavailableException",
                msg.string());
        return 0;
        result = 0;
    } else {
        result = reinterpret_cast<jint>(map);
    }
    return reinterpret_cast<jint>(map);

    env->ReleaseStringUTFChars(fileStr, file);
    return result;
}

static void nativeDispose(JNIEnv *env, jobject clazz, jint ptr) {
@@ -141,7 +148,7 @@ static jobjectArray nativeGetEvents(JNIEnv *env, jobject clazz, jint ptr, jint d

static JNINativeMethod g_methods[] = {
    /* name, signature, funcPtr */
    { "nativeLoad", "(I)I",
    { "nativeLoad", "(Ljava/lang/String;)I",
            (void*)nativeLoad },
    { "nativeDispose", "(I)V",
            (void*)nativeDispose },
+4 −0
Original line number Diff line number Diff line
@@ -826,6 +826,9 @@ public:
    inline void setKeyboardType(int32_t keyboardType) { mKeyboardType = keyboardType; }
    inline int32_t getKeyboardType() const { return mKeyboardType; }

    inline void setKeyCharacterMapFile(const String8& value) { mKeyCharacterMapFile = value; }
    inline const String8& getKeyCharacterMapFile() const { return mKeyCharacterMapFile; }

    inline const Vector<MotionRange>& getMotionRanges() const {
        return mMotionRanges;
    }
@@ -835,6 +838,7 @@ private:
    String8 mName;
    uint32_t mSources;
    int32_t mKeyboardType;
    String8 mKeyCharacterMapFile;

    Vector<MotionRange> mMotionRanges;
};
+0 −1
Original line number Diff line number Diff line
@@ -53,7 +53,6 @@ public:
    ~KeyCharacterMap();

    static status_t load(const String8& filename, KeyCharacterMap** outMap);
    static status_t loadByDeviceId(int32_t deviceId, KeyCharacterMap** outMap);

    /* Gets the keyboard type. */
    int32_t getKeyboardType() const;
Loading