commit 63df885248efaaa6b2ed7e3c51d7e831c045b17a
parent dac09b7cc7026d7ddc3b1f9f50d017c0177c3e94
Author: Makoto Kato <m_kato@ga2.so-net.ne.jp>
Date: Tue, 16 Dec 2025 10:47:23 +0000
Bug 2003445 - Use InputDevice.getName for gamepad device name. r=geckoview-reviewers,nalexander
Actually, we use hard-coded name for gamepad device, but we should use
`InputDevice.getName()` to get the real device name.
Also, we cannot emulate `InputDevice` in unit test, so there is no way
to test on emulator.
Differential Revision: https://phabricator.services.mozilla.com/D276573
Diffstat:
2 files changed, 9 insertions(+), 4 deletions(-)
diff --git a/dom/gamepad/android/AndroidGamepad.cpp b/dom/gamepad/android/AndroidGamepad.cpp
@@ -26,13 +26,18 @@ class AndroidGamepadManager final
AndroidGamepadManager() = delete;
public:
- static jni::ByteArray::LocalRef NativeAddGamepad() {
+ static jni::ByteArray::LocalRef NativeAddGamepad(jni::String::Param aName) {
RefPtr<GamepadPlatformService> service =
GamepadPlatformService::GetParentService();
MOZ_RELEASE_ASSERT(service);
+ nsCString name = aName->ToCString();
+ if (name.IsEmpty()) {
+ name.AssignLiteral("android");
+ }
+
const GamepadHandle gamepadHandle = service->AddGamepad(
- "android", GamepadMappingType::Standard, GamepadHand::_empty,
+ name.get(), GamepadMappingType::Standard, GamepadHand::_empty,
kStandardGamepadButtons, kStandardGamepadAxes, 0, 0, 0);
return mozilla::jni::ByteArray::New(
diff --git a/mobile/android/geckoview/src/main/java/org/mozilla/gecko/AndroidGamepadManager.java b/mobile/android/geckoview/src/main/java/org/mozilla/gecko/AndroidGamepadManager.java
@@ -125,7 +125,7 @@ public class AndroidGamepadManager {
}
@WrapForJNI(calledFrom = "ui")
- private static native byte[] nativeAddGamepad();
+ private static native byte[] nativeAddGamepad(String aName);
@WrapForJNI(calledFrom = "ui")
private static native void nativeRemoveGamepad(byte[] aGamepadHandle);
@@ -357,7 +357,7 @@ public class AndroidGamepadManager {
private static void addGamepad(final InputDevice device) {
sPendingGamepads.put(device.getId(), new ArrayList<KeyEvent>());
- final byte[] gamepadId = nativeAddGamepad();
+ final byte[] gamepadId = nativeAddGamepad(device.getName());
ThreadUtils.runOnUiThread(
new Runnable() {
@Override