Skip to content

Commit

Permalink
Include vendor/product ID in Gamepad.id string
Browse files Browse the repository at this point in the history
Chrome typically includes the vendor and product ID as hexadecimal
values within the Gamepad.id string to aid developers in identifying
controller models. Historically, these IDs were omitted from the ID
string on Android because they were not available pre-KitKat.

Chrome 72 discontinued support for Android Jelly Bean. Now that we
don't need to maintain consistent IDs between old and new versions of
Android, let's add the device IDs and mapping info to the product name
string using the same format as on desktop Chrome.

Bug: 1175926
Change-Id: I03b004d6cbca3fc7f8efa34a3d36b2c61d22fb5a
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2734880
Commit-Queue: Jobed H <jobed.h@chromium.org>
Reviewed-by: Matt Reynolds <mattreynolds@chromium.org>
Cr-Commit-Position: refs/heads/master@{#861039}
  • Loading branch information
jobed-h authored and Chromium LUCI CQ committed Mar 9, 2021
1 parent f6d3aec commit 128f0d6
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 12 deletions.
2 changes: 1 addition & 1 deletion AUTHORS
Original file line number Diff line number Diff line change
Expand Up @@ -706,7 +706,7 @@ Mayank Gupta <mayank.g1@samsung.com>
Mayur Kankanwadi <mayurk.vk@samsung.com>
Md Abdullah Al Alamin <a.alamin.cse@gmail.com>
Md. Hasanur Rashid <hasanur.r@samsung.com>
Md Jobed Hossain <jrony15@gmail.com>
Md Jobed Hossain <jobed.h@samsung.com>
Md Sami Uddin <md.sami@samsung.com>
Michael Cirone <mikecirone@gmail.com>
Michael Constant <mconst@gmail.com>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,11 @@ class GamepadDevice {
private int mDeviceId;
// The index of the gamepad in the Navigator.
private int mDeviceIndex;
// The vendor ID of the gamepad, or zero if the gamepad does not have a vendor ID.
private int mDeviceVendorId;
// The product ID of the gamepad, or zero if the gamepad does not have a product ID.
private int mDeviceProductId;

// Last time the data for this gamepad was updated.
private long mTimestamp;

Expand Down Expand Up @@ -75,6 +80,8 @@ class GamepadDevice {
mDeviceIndex = index;
mDeviceId = inputDevice.getId();
mDeviceName = inputDevice.getName();
mDeviceVendorId = inputDevice.getVendorId();
mDeviceProductId = inputDevice.getProductId();
mTimestamp = SystemClock.uptimeMillis();
// Get axis ids and initialize axes values.
final List<MotionRange> ranges = inputDevice.getMotionRanges();
Expand Down Expand Up @@ -128,6 +135,22 @@ public String getName() {
return mDeviceName;
}

/**
* @return Vendor Id of the gamepad device.
* It can be zero if gamepad doesn't have a vendor ID.
*/
public int getVendorId() {
return mDeviceVendorId;
}

/**
* @return The product ID of the gamepad.
* It can be zero if gamepad doesn't have a product ID.
*/
public int getProductId() {
return mDeviceProductId;
}

/**
* @return Device index of the gamepad device.
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -289,13 +289,17 @@ private void grabGamepadData(long webGamepadsPtr) {
final GamepadDevice device = getDevice(i);
if (device != null) {
device.updateButtonsAndAxesMapping();
GamepadListJni.get().setGamepadData(GamepadList.this, webGamepadsPtr, i,
device.isStandardGamepad(), true, device.getName(),
GamepadListJni.get().setGamepadData(GamepadList.this, webGamepadsPtr,
/*index=*/i, device.isStandardGamepad(), /*connected=*/true,
device.getName(), device.getVendorId(), device.getProductId(),
device.getTimestamp(), device.getAxes(), device.getButtons(),
device.getButtonsLength());
} else {
GamepadListJni.get().setGamepadData(GamepadList.this, webGamepadsPtr, i, false,
false, null, 0, null, null, 0);
GamepadListJni.get().setGamepadData(GamepadList.this, webGamepadsPtr,
/*index=*/i, /*mapping=*/false, /*connected=*/false,
/*devicename=*/null, /*vendorId=*/0, /*productId=*/0,
/*timestamp=*/0, /*axes=*/null, /*buttons=*/null,
/*buttonsLength=*/0);
}
}
}
Expand Down Expand Up @@ -326,7 +330,7 @@ private static class LazyHolder {
@NativeMethods
interface Natives {
void setGamepadData(GamepadList caller, long webGamepadsPtr, int index, boolean mapping,
boolean connected, String devicename, long timestamp, float[] axes, float[] buttons,
int buttonsLength);
boolean connected, String devicename, int vendorId, int productId, long timestamp,
float[] axes, float[] buttons, int buttonsLength);
}
}
11 changes: 6 additions & 5 deletions device/gamepad/gamepad_platform_data_fetcher_android.cc
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,8 @@ static void JNI_GamepadList_SetGamepadData(
jboolean mapping,
jboolean connected,
const JavaParamRef<jstring>& devicename,
jint vendor_id,
jint product_id,
jlong timestamp,
const JavaParamRef<jfloatArray>& jaxes,
const JavaParamRef<jfloatArray>& jbuttons,
Expand Down Expand Up @@ -95,11 +97,10 @@ static void JNI_GamepadList_SetGamepadData(
// be mapped to vendor and product information but it is only available at
// kernel level and it can not be queried using class
// android.hardware.input.InputManager.
base::string16 gamepad_id;
base::android::ConvertJavaStringToUTF16(env, devicename, &gamepad_id);
pad.SetID(gamepad_id);

pad.mapping = mapping ? GamepadMapping::kStandard : GamepadMapping::kNone;
std::string gamepad_id =
base::android::ConvertJavaStringToUTF8(env, devicename);
GamepadDataFetcher::UpdateGamepadStrings(gamepad_id, vendor_id, product_id,
mapping, pad);
}

pad.connected = true;
Expand Down

0 comments on commit 128f0d6

Please sign in to comment.