From 6d85cf2bd7cba6890f1b2bb26073105c3b8fc432 Mon Sep 17 00:00:00 2001 From: Tim Kilbourn Date: Wed, 8 Apr 2015 10:23:35 -0700 Subject: [PATCH] Simplify input-audio device mapping Instead of matching on unique ids, allow an .idc file to specify whether the input device also has a mic. Bug: 15374820 Change-Id: Ib5f934f1f37f6b98bb906a5be86c6bfa9a5f09c8 --- api/current.txt | 2 +- api/system-current.txt | 2 +- core/java/android/view/InputDevice.java | 39 ++++++++++--------------- core/jni/android_view_InputDevice.cpp | 16 +++++----- 4 files changed, 25 insertions(+), 34 deletions(-) diff --git a/api/current.txt b/api/current.txt index b6a630ba429fe..f11fd42c3372d 100644 --- a/api/current.txt +++ b/api/current.txt @@ -33569,10 +33569,10 @@ 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...); + method public boolean hasMic(); method public boolean isVirtual(); method public boolean supportsSource(int); method public void writeToParcel(android.os.Parcel, int); diff --git a/api/system-current.txt b/api/system-current.txt index 318d1dbd80020..e06a495824156 100644 --- a/api/system-current.txt +++ b/api/system-current.txt @@ -36118,10 +36118,10 @@ 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...); + method public boolean hasMic(); method public boolean isVirtual(); method public boolean supportsSource(int); 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 2eac5495a9d88..1ee478023223c 100644 --- a/core/java/android/view/InputDevice.java +++ b/core/java/android/view/InputDevice.java @@ -49,7 +49,6 @@ 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; @@ -57,6 +56,7 @@ public final class InputDevice implements Parcelable { private final int mKeyboardType; private final KeyCharacterMap mKeyCharacterMap; private final boolean mHasVibrator; + private final boolean mHasMic; private final boolean mHasButtonUnderPad; private final ArrayList mMotionRanges = new ArrayList(); @@ -357,8 +357,8 @@ 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 uniqueId, String descriptor, boolean isExternal, int sources, - int keyboardType, KeyCharacterMap keyCharacterMap, boolean hasVibrator, + int productId, String descriptor, boolean isExternal, int sources, int keyboardType, + KeyCharacterMap keyCharacterMap, boolean hasVibrator, boolean hasMic, boolean hasButtonUnderPad) { mId = id; mGeneration = generation; @@ -366,13 +366,13 @@ public final class InputDevice implements Parcelable { mName = name; mVendorId = vendorId; mProductId = productId; - mUniqueId = uniqueId; mDescriptor = descriptor; mIsExternal = isExternal; mSources = sources; mKeyboardType = keyboardType; mKeyCharacterMap = keyCharacterMap; mHasVibrator = hasVibrator; + mHasMic = hasMic; mHasButtonUnderPad = hasButtonUnderPad; mIdentifier = new InputDeviceIdentifier(descriptor, vendorId, productId); } @@ -384,13 +384,13 @@ 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(); mKeyboardType = in.readInt(); mKeyCharacterMap = KeyCharacterMap.CREATOR.createFromParcel(in); mHasVibrator = in.readInt() != 0; + mHasMic = in.readInt() != 0; mHasButtonUnderPad = in.readInt() != 0; mIdentifier = new InputDeviceIdentifier(mDescriptor, mVendorId, mProductId); @@ -508,23 +508,6 @@ public final class InputDevice implements Parcelable { return mProductId; } - /** - * Gets the vendor's unique id for the given device, if available. - *

- * 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. - *

- * This method is dependent on the vendor, whereas {@link #getDescriptor} - * attempts to create a unique id even when the vendor has not provided one. - *

- * - * @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. *

@@ -736,6 +719,14 @@ public final class InputDevice implements Parcelable { } } + /** + * Reports whether the device has a built-in microphone. + * @return Whether the device has a built-in microphone. + */ + public boolean hasMic() { + return mHasMic; + } + /** * Reports whether the device has a button under its touchpad * @return Whether the device has a button under its touchpad @@ -864,13 +855,13 @@ 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); out.writeInt(mKeyboardType); mKeyCharacterMap.writeToParcel(out, flags); out.writeInt(mHasVibrator ? 1 : 0); + out.writeInt(mHasMic ? 1 : 0); out.writeInt(mHasButtonUnderPad ? 1 : 0); final int numRanges = mMotionRanges.size(); @@ -916,6 +907,8 @@ public final class InputDevice implements Parcelable { description.append(" Has Vibrator: ").append(mHasVibrator).append("\n"); + description.append(" Has mic: ").append(mHasMic).append("\n"); + description.append(" Sources: 0x").append(Integer.toHexString(mSources)).append(" ("); appendSourceDescriptionIfApplicable(description, SOURCE_KEYBOARD, "keyboard"); appendSourceDescriptionIfApplicable(description, SOURCE_DPAD, "dpad"); diff --git a/core/jni/android_view_InputDevice.cpp b/core/jni/android_view_InputDevice.cpp index fb91c8f67a676..9cf6a9d088907 100644 --- a/core/jni/android_view_InputDevice.cpp +++ b/core/jni/android_view_InputDevice.cpp @@ -48,11 +48,6 @@ jobject android_view_InputDevice_create(JNIEnv* env, const InputDeviceInfo& devi return NULL; } - ScopedLocalRef uniqueIdObj(env, env->NewStringUTF(deviceInfo.getIdentifier().uniqueId)); - if (!uniqueIdObj.get()) { - return NULL; - } - ScopedLocalRef kcmObj(env, android_view_KeyCharacterMap_create(env, deviceInfo.getId(), deviceInfo.getKeyCharacterMap())); @@ -62,13 +57,16 @@ jobject android_view_InputDevice_create(JNIEnv* env, const InputDeviceInfo& devi const InputDeviceIdentifier& ident = deviceInfo.getIdentifier(); + // Not sure why, but JNI is complaining when I pass this through directly. + jboolean hasMic = deviceInfo.hasMic() ? JNI_TRUE : JNI_FALSE; + ScopedLocalRef inputDeviceObj(env, env->NewObject(gInputDeviceClassInfo.clazz, gInputDeviceClassInfo.ctor, deviceInfo.getId(), deviceInfo.getGeneration(), deviceInfo.getControllerNumber(), nameObj.get(), static_cast(ident.vendor), static_cast(ident.product), - uniqueIdObj.get(), descriptorObj.get(), deviceInfo.isExternal(), - deviceInfo.getSources(), deviceInfo.getKeyboardType(), kcmObj.get(), - deviceInfo.hasVibrator(), deviceInfo.hasButtonUnderPad())); + descriptorObj.get(), deviceInfo.isExternal(), deviceInfo.getSources(), + deviceInfo.getKeyboardType(), kcmObj.get(), deviceInfo.hasVibrator(), + hasMic, deviceInfo.hasButtonUnderPad())); const Vector& ranges = deviceInfo.getMotionRanges(); for (size_t i = 0; i < ranges.size(); i++) { @@ -90,7 +88,7 @@ int register_android_view_InputDevice(JNIEnv* env) gInputDeviceClassInfo.clazz = MakeGlobalRefOrDie(env, gInputDeviceClassInfo.clazz); gInputDeviceClassInfo.ctor = GetMethodIDOrDie(env, gInputDeviceClassInfo.clazz, "", - "(IIILjava/lang/String;IILjava/lang/String;Ljava/lang/String;ZIILandroid/view/KeyCharacterMap;ZZ)V"); + "(IIILjava/lang/String;IILjava/lang/String;ZIILandroid/view/KeyCharacterMap;ZZZ)V"); gInputDeviceClassInfo.addMotionRange = GetMethodIDOrDie(env, gInputDeviceClassInfo.clazz, "addMotionRange", "(IIFFFFF)V");