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

Commit 415b450b authored by Tim Kilbourn's avatar Tim Kilbourn
Browse files

Add unique id to InputDevice.

If an input device driver assigns unique ids to devices (e.g., MAC
address), this method will be used to retrieve it from the device.

Change-Id: If1fd6643c5be7af5b989ef47f4bb653e7a63b6c6
parent 15f78bbd
Loading
Loading
Loading
Loading
+1 −0
Original line number Diff line number Diff line
@@ -33177,6 +33177,7 @@ package android.view {
    method public java.lang.String getName();
    method public int getProductId();
    method public int getSources();
    method public java.lang.String getUniqueId();
    method public int getVendorId();
    method public android.os.Vibrator getVibrator();
    method public boolean[] hasKeys(int...);
+1 −0
Original line number Diff line number Diff line
@@ -35533,6 +35533,7 @@ package android.view {
    method public java.lang.String getName();
    method public int getProductId();
    method public int getSources();
    method public java.lang.String getUniqueId();
    method public int getVendorId();
    method public android.os.Vibrator getVibrator();
    method public boolean[] hasKeys(int...);
+24 −2
Original line number Diff line number Diff line
@@ -49,6 +49,7 @@ public final class InputDevice implements Parcelable {
    private final String mName;
    private final int mVendorId;
    private final int mProductId;
    private final String mUniqueId;
    private final String mDescriptor;
    private final InputDeviceIdentifier mIdentifier;
    private final boolean mIsExternal;
@@ -356,14 +357,16 @@ public final class InputDevice implements Parcelable {

    // Called by native code.
    private InputDevice(int id, int generation, int controllerNumber, String name, int vendorId,
            int productId, String descriptor, boolean isExternal, int sources, int keyboardType,
            KeyCharacterMap keyCharacterMap, boolean hasVibrator, boolean hasButtonUnderPad) {
            int productId, String uniqueId, String descriptor, boolean isExternal, int sources,
            int keyboardType, KeyCharacterMap keyCharacterMap, boolean hasVibrator,
            boolean hasButtonUnderPad) {
        mId = id;
        mGeneration = generation;
        mControllerNumber = controllerNumber;
        mName = name;
        mVendorId = vendorId;
        mProductId = productId;
        mUniqueId = uniqueId;
        mDescriptor = descriptor;
        mIsExternal = isExternal;
        mSources = sources;
@@ -381,6 +384,7 @@ public final class InputDevice implements Parcelable {
        mName = in.readString();
        mVendorId = in.readInt();
        mProductId = in.readInt();
        mUniqueId = in.readString();
        mDescriptor = in.readString();
        mIsExternal = in.readInt() != 0;
        mSources = in.readInt();
@@ -504,6 +508,23 @@ public final class InputDevice implements Parcelable {
        return mProductId;
    }

    /**
     * Gets the vendor's unique id for the given device, if available.
     * <p>
     * A vendor may assign a unique id to a device (e.g., MAC address for
     * Bluetooth devices). A null value will be assigned where a unique id is
     * not available.
     * </p><p>
     * This method is dependent on the vendor, whereas {@link #getDescriptor}
     * attempts to create a unique id even when the vendor has not provided one.
     * </p>
     *
     * @return The unique id of a given device
     */
    public String getUniqueId() {
        return mUniqueId;
    }

    /**
     * Gets the input device descriptor, which is a stable identifier for an input device.
     * <p>
@@ -843,6 +864,7 @@ public final class InputDevice implements Parcelable {
        out.writeString(mName);
        out.writeInt(mVendorId);
        out.writeInt(mProductId);
        out.writeString(mUniqueId);
        out.writeString(mDescriptor);
        out.writeInt(mIsExternal ? 1 : 0);
        out.writeInt(mSources);
+8 −3
Original line number Diff line number Diff line
@@ -48,6 +48,11 @@ jobject android_view_InputDevice_create(JNIEnv* env, const InputDeviceInfo& devi
        return NULL;
    }

    ScopedLocalRef<jstring> uniqueIdObj(env, env->NewStringUTF(deviceInfo.getIdentifier().uniqueId));
    if (!uniqueIdObj.get()) {
        return NULL;
    }

    ScopedLocalRef<jobject> kcmObj(env,
            android_view_KeyCharacterMap_create(env, deviceInfo.getId(),
            deviceInfo.getKeyCharacterMap()));
@@ -61,9 +66,9 @@ jobject android_view_InputDevice_create(JNIEnv* env, const InputDeviceInfo& devi
                gInputDeviceClassInfo.ctor, deviceInfo.getId(), deviceInfo.getGeneration(),
                deviceInfo.getControllerNumber(), nameObj.get(),
                static_cast<int32_t>(ident.vendor), static_cast<int32_t>(ident.product),
                descriptorObj.get(), deviceInfo.isExternal(), deviceInfo.getSources(),
                deviceInfo.getKeyboardType(), kcmObj.get(), deviceInfo.hasVibrator(),
                deviceInfo.hasButtonUnderPad()));
                uniqueIdObj.get(), descriptorObj.get(), deviceInfo.isExternal(),
                deviceInfo.getSources(), deviceInfo.getKeyboardType(), kcmObj.get(),
                deviceInfo.hasVibrator(), deviceInfo.hasButtonUnderPad()));

    const Vector<InputDeviceInfo::MotionRange>& ranges = deviceInfo.getMotionRanges();
    for (size_t i = 0; i < ranges.size(); i++) {