diff --git a/core/java/android/view/InputDevice.java b/core/java/android/view/InputDevice.java index 9fd8ecb1727f9..9b1d8673390b9 100644 --- a/core/java/android/view/InputDevice.java +++ b/core/java/android/view/InputDevice.java @@ -80,6 +80,7 @@ public final class InputDevice implements Parcelable { private final boolean mHasButtonUnderPad; private final boolean mHasSensor; private final boolean mHasBattery; + private final boolean mSupportsUsi; private final ArrayList mMotionRanges = new ArrayList(); @GuardedBy("mMotionRanges") @@ -462,7 +463,7 @@ public final class InputDevice implements Parcelable { int productId, String descriptor, boolean isExternal, int sources, int keyboardType, KeyCharacterMap keyCharacterMap, @InputDeviceCountryCode int countryCode, boolean hasVibrator, boolean hasMicrophone, boolean hasButtonUnderPad, - boolean hasSensor, boolean hasBattery) { + boolean hasSensor, boolean hasBattery, boolean supportsUsi) { mId = id; mGeneration = generation; mControllerNumber = controllerNumber; @@ -481,6 +482,7 @@ public final class InputDevice implements Parcelable { mHasSensor = hasSensor; mHasBattery = hasBattery; mIdentifier = new InputDeviceIdentifier(descriptor, vendorId, productId); + mSupportsUsi = supportsUsi; } private InputDevice(Parcel in) { @@ -501,6 +503,7 @@ public final class InputDevice implements Parcelable { mHasButtonUnderPad = in.readInt() != 0; mHasSensor = in.readInt() != 0; mHasBattery = in.readInt() != 0; + mSupportsUsi = in.readInt() != 0; mIdentifier = new InputDeviceIdentifier(mDescriptor, mVendorId, mProductId); int numRanges = in.readInt(); @@ -538,6 +541,7 @@ public final class InputDevice implements Parcelable { private boolean mHasBattery = false; @InputDeviceCountryCode private int mCountryCode = InputDeviceCountryCode.INVALID; + private boolean mSupportsUsi = false; /** @see InputDevice#getId() */ public Builder setId(int id) { @@ -641,12 +645,18 @@ public final class InputDevice implements Parcelable { return this; } + /** @see InputDevice#supportsUsi() () */ + public Builder setSupportsUsi(boolean supportsUsi) { + mSupportsUsi = supportsUsi; + return this; + } + /** Build {@link InputDevice}. */ public InputDevice build() { return new InputDevice(mId, mGeneration, mControllerNumber, mName, mVendorId, mProductId, mDescriptor, mIsExternal, mSources, mKeyboardType, mKeyCharacterMap, mCountryCode, mHasVibrator, mHasMicrophone, mHasButtonUnderPad, mHasSensor, - mHasBattery); + mHasBattery, mSupportsUsi); } } @@ -1178,6 +1188,15 @@ public final class InputDevice implements Parcelable { return mHasBattery; } + /** + * Reports whether the device supports the Universal Stylus Initiative (USI) protocol for + * styluses. + * @hide + */ + public boolean supportsUsi() { + return mSupportsUsi; + } + /** * Provides information about the range of values for a particular {@link MotionEvent} axis. * @@ -1308,6 +1327,7 @@ public final class InputDevice implements Parcelable { out.writeInt(mHasButtonUnderPad ? 1 : 0); out.writeInt(mHasSensor ? 1 : 0); out.writeInt(mHasBattery ? 1 : 0); + out.writeInt(mSupportsUsi ? 1 : 0); final int numRanges = mMotionRanges.size(); out.writeInt(numRanges); @@ -1361,6 +1381,8 @@ public final class InputDevice implements Parcelable { description.append(" Has mic: ").append(mHasMicrophone).append("\n"); + description.append(" Supports USI: ").append(mSupportsUsi).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 aece8c35a9e6a..39ec0374dc5ee 100644 --- a/core/jni/android_view_InputDevice.cpp +++ b/core/jni/android_view_InputDevice.cpp @@ -57,9 +57,6 @@ 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, @@ -70,8 +67,9 @@ jobject android_view_InputDevice_create(JNIEnv* env, const InputDeviceInfo& devi deviceInfo.isExternal(), deviceInfo.getSources(), deviceInfo.getKeyboardType(), kcmObj.get(), deviceInfo.getCountryCode(), deviceInfo.hasVibrator(), - hasMic, deviceInfo.hasButtonUnderPad(), - deviceInfo.hasSensor(), deviceInfo.hasBattery())); + deviceInfo.hasMic(), deviceInfo.hasButtonUnderPad(), + deviceInfo.hasSensor(), deviceInfo.hasBattery(), + deviceInfo.supportsUsi())); const std::vector& ranges = deviceInfo.getMotionRanges(); for (const InputDeviceInfo::MotionRange& range: ranges) { @@ -94,7 +92,7 @@ int register_android_view_InputDevice(JNIEnv* env) gInputDeviceClassInfo.ctor = GetMethodIDOrDie(env, gInputDeviceClassInfo.clazz, "", "(IIILjava/lang/String;IILjava/lang/" - "String;ZIILandroid/view/KeyCharacterMap;IZZZZZ)V"); + "String;ZIILandroid/view/KeyCharacterMap;IZZZZZZ)V"); gInputDeviceClassInfo.addMotionRange = GetMethodIDOrDie(env, gInputDeviceClassInfo.clazz, "addMotionRange", "(IIFFFFF)V"); diff --git a/tests/Input/src/com/android/test/input/InputDeviceTest.java b/tests/Input/src/com/android/test/input/InputDeviceTest.java index 06a96dfb8176e..8aaf18af06644 100644 --- a/tests/Input/src/com/android/test/input/InputDeviceTest.java +++ b/tests/Input/src/com/android/test/input/InputDeviceTest.java @@ -87,6 +87,7 @@ public class InputDeviceTest { .setHasSensor(true) .setHasBattery(true) .setCountryCode(InputDeviceCountryCode.INTERNATIONAL) + .setSupportsUsi(true) .build(); Parcel parcel = Parcel.obtain();