From 343761c05bd24ebf4c20d5b7161e6b5bb7e119c2 Mon Sep 17 00:00:00 2001 From: Asmita Poddar Date: Mon, 26 Feb 2024 14:26:24 +0000 Subject: Pass Device bus ID from native to Java Pass Device Bus from the native side to the Java side. This is done so we can log Device Bus ID in atoms. Since the same vendor ID could mean different vendors depending on whether the device is connected over bluetooth or USB, we require to know the device bus to disambiguate the vendor IDs. Bug: 308918242 Test: atest InputDeviceTest Test: atest inputflinger_tests (cherry picked from https://googleplex-android-review.googlesource.com/q/commit:b4015294e1c3452a00d4a326ca3871e6e56b5f78) Merged-In: I0ff2e31d7a8b610b0e1208cc5c444d1f785e162c Change-Id: I0ff2e31d7a8b610b0e1208cc5c444d1f785e162c --- core/java/android/view/InputDevice.java | 31 ++++++++++++++++++++-- core/jni/android_view_InputDevice.cpp | 5 ++-- .../com/android/test/input/InputDeviceTest.java | 2 ++ 3 files changed, 34 insertions(+), 4 deletions(-) diff --git a/core/java/android/view/InputDevice.java b/core/java/android/view/InputDevice.java index a436e08a0a2d..2eece6d4a454 100644 --- a/core/java/android/view/InputDevice.java +++ b/core/java/android/view/InputDevice.java @@ -69,6 +69,7 @@ public final class InputDevice implements Parcelable { private final String mName; private final int mVendorId; private final int mProductId; + private final int mDeviceBus; private final String mDescriptor; private final InputDeviceIdentifier mIdentifier; @UnsupportedAppUsage(maxTargetSdk = Build.VERSION_CODES.P) @@ -468,8 +469,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 descriptor, boolean isExternal, int sources, int keyboardType, - KeyCharacterMap keyCharacterMap, @Nullable String keyboardLanguageTag, + int productId, int deviceBus, String descriptor, boolean isExternal, int sources, + int keyboardType, KeyCharacterMap keyCharacterMap, @Nullable String keyboardLanguageTag, @Nullable String keyboardLayoutType, boolean hasVibrator, boolean hasMicrophone, boolean hasButtonUnderPad, boolean hasSensor, boolean hasBattery, int usiVersionMajor, int usiVersionMinor, int associatedDisplayId) { @@ -479,6 +480,7 @@ public final class InputDevice implements Parcelable { mName = name; mVendorId = vendorId; mProductId = productId; + mDeviceBus = deviceBus; mDescriptor = descriptor; mIsExternal = isExternal; mSources = sources; @@ -512,6 +514,7 @@ public final class InputDevice implements Parcelable { mName = in.readString(); mVendorId = in.readInt(); mProductId = in.readInt(); + mDeviceBus = in.readInt(); mDescriptor = in.readString(); mIsExternal = in.readInt() != 0; mSources = in.readInt(); @@ -551,6 +554,7 @@ public final class InputDevice implements Parcelable { private String mName = ""; private int mVendorId = 0; private int mProductId = 0; + private int mDeviceBus = 0; private String mDescriptor = ""; private boolean mIsExternal = false; private int mSources = 0; @@ -604,6 +608,12 @@ public final class InputDevice implements Parcelable { return this; } + /** @see InputDevice#getDeviceBus() */ + public Builder setDeviceBus(int deviceBus) { + mDeviceBus = deviceBus; + return this; + } + /** @see InputDevice#getDescriptor() */ public Builder setDescriptor(String descriptor) { mDescriptor = descriptor; @@ -705,6 +715,7 @@ public final class InputDevice implements Parcelable { mName, mVendorId, mProductId, + mDeviceBus, mDescriptor, mIsExternal, mSources, @@ -845,6 +856,21 @@ public final class InputDevice implements Parcelable { return mProductId; } + /** + * Gets the device bus used by given device, if available. + *

+ * The device bus is the communication system used for transferring data + * (e.g. USB, Bluetooth etc.). This value comes from the kernel (from input.h). + * A value of 0 will be assigned where the device bus is not available. + *

+ * + * @return The device bus of a given device + * @hide + */ + public int getDeviceBus() { + return mDeviceBus; + } + /** * Gets the input device descriptor, which is a stable identifier for an input device. *

@@ -1444,6 +1470,7 @@ public final class InputDevice implements Parcelable { out.writeString(mName); out.writeInt(mVendorId); out.writeInt(mProductId); + out.writeInt(mDeviceBus); 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 f97d41b6a122..baea3bc3e04f 100644 --- a/core/jni/android_view_InputDevice.cpp +++ b/core/jni/android_view_InputDevice.cpp @@ -83,7 +83,8 @@ jobject android_view_InputDevice_create(JNIEnv* env, const InputDeviceInfo& devi deviceInfo.getId(), deviceInfo.getGeneration(), deviceInfo.getControllerNumber(), nameObj.get(), static_cast(ident.vendor), - static_cast(ident.product), descriptorObj.get(), + static_cast(ident.product), + static_cast(ident.bus), descriptorObj.get(), deviceInfo.isExternal(), deviceInfo.getSources(), deviceInfo.getKeyboardType(), kcmObj.get(), keyboardLanguageTagObj.get(), keyboardLayoutTypeObj.get(), @@ -113,7 +114,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/" + "(IIILjava/lang/String;IIILjava/lang/" "String;ZIILandroid/view/KeyCharacterMap;Ljava/" "lang/String;Ljava/lang/String;ZZZZZIII)V"); diff --git a/tests/Input/src/com/android/test/input/InputDeviceTest.java b/tests/Input/src/com/android/test/input/InputDeviceTest.java index d075b5f01ef9..5434c82b07bd 100644 --- a/tests/Input/src/com/android/test/input/InputDeviceTest.java +++ b/tests/Input/src/com/android/test/input/InputDeviceTest.java @@ -51,6 +51,7 @@ public class InputDeviceTest { assertEquals(device.getName(), outDevice.getName()); assertEquals(device.getVendorId(), outDevice.getVendorId()); assertEquals(device.getProductId(), outDevice.getProductId()); + assertEquals(device.getDeviceBus(), outDevice.getDeviceBus()); assertEquals(device.getDescriptor(), outDevice.getDescriptor()); assertEquals(device.isExternal(), outDevice.isExternal()); assertEquals(device.getSources(), outDevice.getSources()); @@ -79,6 +80,7 @@ public class InputDeviceTest { .setName("Test Device " + DEVICE_ID) .setVendorId(44) .setProductId(45) + .setDeviceBus(3) .setDescriptor("descriptor") .setExternal(true) .setSources(InputDevice.SOURCE_HDMI) -- cgit v1.2.3-59-g8ed1b