diff --git a/api/current.txt b/api/current.txt index 01264173ab77c..ff47557fbfe74 100644 --- a/api/current.txt +++ b/api/current.txt @@ -25832,7 +25832,9 @@ package android.view { method public android.view.InputDevice.MotionRange getMotionRange(int, int); method public java.util.List getMotionRanges(); method public java.lang.String getName(); + method public int getProductId(); method public int getSources(); + method public int getVendorId(); method public android.os.Vibrator getVibrator(); method public boolean isVirtual(); method public void writeToParcel(android.os.Parcel, int); diff --git a/core/java/android/view/InputDevice.java b/core/java/android/view/InputDevice.java index debf4ee7e7c34..f43e4ab3c133e 100644 --- a/core/java/android/view/InputDevice.java +++ b/core/java/android/view/InputDevice.java @@ -46,6 +46,8 @@ public final class InputDevice implements Parcelable { private final int mGeneration; private final int mControllerNumber; private final String mName; + private final int mVendorId; + private final int mProductId; private final String mDescriptor; private final boolean mIsExternal; private final int mSources; @@ -343,13 +345,15 @@ public final class InputDevice implements Parcelable { }; // Called by native code. - private InputDevice(int id, int generation, int controllerNumber, String name, - String descriptor, boolean isExternal, int sources, int keyboardType, + 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) { mId = id; mGeneration = generation; mControllerNumber = controllerNumber; mName = name; + mVendorId = vendorId; + mProductId = productId; mDescriptor = descriptor; mIsExternal = isExternal; mSources = sources; @@ -364,6 +368,8 @@ public final class InputDevice implements Parcelable { mGeneration = in.readInt(); mControllerNumber = in.readInt(); mName = in.readString(); + mVendorId = in.readInt(); + mProductId = in.readInt(); mDescriptor = in.readString(); mIsExternal = in.readInt() != 0; mSources = in.readInt(); @@ -442,6 +448,33 @@ public final class InputDevice implements Parcelable { return mGeneration; } + /** + * Gets the vendor id for the given device, if available. + *

+ * A vendor id uniquely identifies the company who manufactured the device. A value of 0 will + * be assigned where a vendor id is not available. + *

+ * + * @return The vendor id of a given device + */ + public int getVendorId() { + return mVendorId; + } + + /** + * Gets the product id for the given device, if available. + *

+ * A product id uniquely identifies which product within the address space of a given vendor, + * identified by the device's vendor id. A value of 0 will be assigned where a product id is + * not available. + *

+ * + * @return The product id of a given device + */ + public int getProductId() { + return mProductId; + } + /** * Gets the input device descriptor, which is a stable identifier for an input device. *

@@ -757,6 +790,8 @@ public final class InputDevice implements Parcelable { out.writeInt(mGeneration); out.writeInt(mControllerNumber); out.writeString(mName); + out.writeInt(mVendorId); + out.writeInt(mProductId); out.writeString(mDescriptor); out.writeInt(mIsExternal ? 1 : 0); out.writeInt(mSources); diff --git a/core/jni/android_view_InputDevice.cpp b/core/jni/android_view_InputDevice.cpp index 5c8e010127766..bef0f848c25b5 100644 --- a/core/jni/android_view_InputDevice.cpp +++ b/core/jni/android_view_InputDevice.cpp @@ -53,11 +53,15 @@ jobject android_view_InputDevice_create(JNIEnv* env, const InputDeviceInfo& devi return NULL; } + const InputDeviceIdentifier& ident = deviceInfo.getIdentifier(); + ScopedLocalRef inputDeviceObj(env, env->NewObject(gInputDeviceClassInfo.clazz, - gInputDeviceClassInfo.ctor, deviceInfo.getId(), deviceInfo.getGeneration(), - deviceInfo.getControllerNumber(), nameObj.get(), descriptorObj.get(), - deviceInfo.isExternal(), deviceInfo.getSources(), deviceInfo.getKeyboardType(), - kcmObj.get(), deviceInfo.hasVibrator(), deviceInfo.hasButtonUnderPad())); + gInputDeviceClassInfo.ctor, deviceInfo.getId(), deviceInfo.getGeneration(), + deviceInfo.getControllerNumber(), nameObj.get(), + static_cast(ident.vendor), static_cast(ident.product), + descriptorObj.get(), deviceInfo.isExternal(), deviceInfo.getSources(), + deviceInfo.getKeyboardType(), kcmObj.get(), deviceInfo.hasVibrator(), + deviceInfo.hasButtonUnderPad())); const Vector& ranges = deviceInfo.getMotionRanges(); for (size_t i = 0; i < ranges.size(); i++) { @@ -88,7 +92,7 @@ int register_android_view_InputDevice(JNIEnv* env) GET_METHOD_ID(gInputDeviceClassInfo.ctor, gInputDeviceClassInfo.clazz, "", - "(IIILjava/lang/String;Ljava/lang/String;ZIILandroid/view/KeyCharacterMap;ZZ)V"); + "(IIILjava/lang/String;IILjava/lang/String;ZIILandroid/view/KeyCharacterMap;ZZ)V"); GET_METHOD_ID(gInputDeviceClassInfo.addMotionRange, gInputDeviceClassInfo.clazz, "addMotionRange", "(IIFFFFF)V");