Skip to content

Conversation

@Nintorch
Copy link
Contributor

@Nintorch Nintorch commented Dec 25, 2025

Hopefully fixes #56181 (if not, then we need to create a mapping for Xbox controllers ourselves)

This PR adds support for SDL-compatible joypad GUIDs on Android, so now we should be able to use SDL controller mapping database for Android controllers.
This PR adds support for Input.get_joy_info() for Android as well.

See also SDL's Android_AddJoystick, SDL's SDLControllerManager, and the way GUID was constructed in Godot's Linux joypad driver prior to the SDL3 joystick driver PR here.

DualShock 4 GUID before this PR

(Ignore that there's no fingerprint sensor here, it's a screenshot with a different PR applied)
Screenshot_2025-12-25-18-17-15-579_org godotengine editor v4 debug

DualShock 4 GUID after this PR + Input.get_joy_info()

Screenshot_2025-12-25-21-29-55-945_org godotengine editor v4 debug

@Nintorch Nintorch requested review from a team as code owners December 25, 2025 16:40
@Nintorch Nintorch changed the title Add support for SDL-compatible joypad GUID Add support for SDL-compatible joypad GUID on Android Dec 25, 2025
Copy link
Contributor

@m4gr3d m4gr3d left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Alongside manual testing, can you add unit tests to validate the added logic.

@Nintorch
Copy link
Contributor Author

Thank you for your review, m4gr3d! I will be able to fix the code later today!

@Nintorch Nintorch requested a review from a team as a code owner December 26, 2025 18:25
@Nintorch Nintorch force-pushed the android-sdl-guid branch 3 times, most recently from bc31ec9 to 60d7a23 Compare December 26, 2025 18:55
mJoysticksDevices.put(deviceId, joystick);

handleJoystickConnectionChangedEvent(id, true, joystick.name);
if (Build.VERSION.SDK_INT >= 19) { // device.getVendorId() and device.getProductId() are only present in API 19 and above.
Copy link
Contributor

@m4gr3d m4gr3d Dec 26, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
if (Build.VERSION.SDK_INT >= 19) { // device.getVendorId() and device.getProductId() are only present in API 19 and above.
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) { // InputDevice#getVendorId() and InputDevice#getProductId() are only present in API 19 and above.

mJoystickIds.delete(deviceId);
mJoysticksDevices.delete(deviceId);
handleJoystickConnectionChangedEvent(godotJoyId, false, "");
handleJoystickConnectionChangedEvent(godotJoyId, false, "", 0, 0, 0, 0);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In the update above the button_mask and axis_mask were defaulted to -1; is there a difference with using 0 here?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

They aren't used when a device gets disconnected

//Helps with creating new joypad mappings.
Log.i(TAG, "=== New Input Device: " + joystick.name);

ArrayList<InputDevice.MotionRange> axes_motion_ranges = new ArrayList<>();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
ArrayList<InputDevice.MotionRange> axes_motion_ranges = new ArrayList<>();
ArrayList<InputDevice.MotionRange> axesMotionRanges = new ArrayList<>();

Copy link
Contributor

@m4gr3d m4gr3d Dec 26, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Here and in the updates below, parameters and variables names should use the camelCase style. snake_case is only used in the C++ codebase.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Xbox controller L2 and R2 inputs swapped on Android

3 participants