We are currently migrating Bugzilla to GitHub issues.
Any changes made to the bug tracker now will be lost, so please do not post new bugs or make changes to them.
When we're done, all bug URLs will redirect to their equivalent location on the new bug tracker.

Bug 2361 - [Android] Joysticks do not have unique IDs
Summary: [Android] Joysticks do not have unique IDs
Status: RESOLVED FIXED
Alias: None
Product: SDL
Classification: Unclassified
Component: joystick (show other bugs)
Version: HG 2.1
Hardware: All Android (All)
: P2 normal
Assignee: Sylvain
QA Contact: Sam Lantinga
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2014-01-24 03:26 UTC by David Brady
Modified: 2017-08-28 17:04 UTC (History)
1 user (show)

See Also:


Attachments
Patch to get the descriptor for the device. (7.72 KB, text/plain)
2014-01-24 03:26 UTC, David Brady
Details
patch with multiple API (7.46 KB, patch)
2017-08-28 09:49 UTC, Sylvain
Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description David Brady 2014-01-24 03:26:05 UTC
Created attachment 1536 [details]
Patch to get the descriptor for the device.

When I attempted to make a mapping file for Android gamepads, I quickly discovered that most of the ones that I have here show up as the same device (Broadcom Bluetooth HID), meaning that it was impossible to make mappings on Android, since every device looked the same.

This patch will check for the existence of the getDescriptor function added in Jelly Bean, and use it if it's there.  The Android Dashboard says that the majority of Android phones should support this function, and doing it this way will not force us to bump up our API version.
Comment 1 Gabriel Jacobo 2014-01-24 13:23:27 UTC
The patch does not apply cleanly right now, besides that, getJoystickDescriptor is pasted twice (once inside DummyEdit)

As a matter of style, perhaps it would be best to create a SDLJoystickHandler_API16 class that inherits from SDLJoystickHandler_API12 where getJoystickDescriptor is based on InputDevice.getDescriptor, overriding a base method which just returns the joystick name (or whatever alternative we can fiure out).
Comment 2 David Brady 2014-01-24 18:20:40 UTC
Sorry, this patch was extremely rushed, as I'm trying to ship a project.  I mostly just wanted to see if it would be accepted.  I'll clean it up and try to resubmit next week.

I'm not sure I understand what it is that you would like me to do with it though?  I would really rather not bump up the minimum API version to 16, that's why I used reflection to call the function instead of calling it directly.  It sounds like you want me to create an API16 class that calls the function directly if we target API16?  I'm pretty new to Java, so sorry if I'm misunderstanding something.
Comment 3 Gabriel Jacobo 2014-01-24 18:26:56 UTC
It's quite easy to do, if you look at how SDLJoystickHandler_API and SDLJoystickHandler_API12 work. 

Basically, SDLJoystickHandler_API is an empty class that gets instantiated if the API level of the device is <= 11, and SDLJoystickHandler_API12 gets instantiated in devices that actually support joysticks:


        if(Build.VERSION.SDK_INT >= 12) {
            mJoystickHandler = new SDLJoystickHandler_API12();
        }
        else {
            mJoystickHandler = new SDLJoystickHandler();
        }


You can add a new SDLJoystickHandler_API16 that inherits from SDLJoystickHandler_API12 and that goes to town with any API level 16 functions, just as long as you instantiate it correctly depending on Build.VERSION.SDK_INT

It's the same reflection trick essentially, but what I suggested falls in line with what SDLActivity is doing now.
Comment 4 David Brady 2014-01-24 18:40:35 UTC
That's what I had thought when I originally saw that code, but I've never been able to get the project to build with API9.  Is there some trick to that?
Comment 5 Gabriel Jacobo 2014-01-24 18:42:47 UTC
API 9 is not supported by SDL, the minimum is 10. If 10 does not work, it's a bug :)

Requirements are listed at the top of this file: https://hg.libsdl.org/SDL/file/d7b7ec662687/README-android.txt
Comment 6 David Brady 2014-01-24 18:48:50 UTC
I meant 10...  It definitely does not work for me.  I must have some trouble in my project setup somewhere if it works for you.  Are you building from Eclipse or the command line, or both?
Comment 7 Gabriel Jacobo 2014-01-24 19:24:09 UTC
Only command line. The only "trick" I can think of is that you have to build against an API of level 12 (target=android-12). This does not prevent the app from running on level 10 devices though, due to the introspection thingy.
Comment 8 Sam Lantinga 2017-08-14 21:08:32 UTC
Hey Sylvain, you want to take a crack at implementing this patch using the correct API level abstraction? Does it look like a good change in general?
Comment 9 Sylvain 2017-08-28 09:49:20 UTC
Created attachment 2897 [details]
patch with multiple API

Hi ! 
Here's a patch with a API16 class extending API12 to provide the joystickDescriptor string.
Comment 10 Sam Lantinga 2017-08-28 17:04:02 UTC
Fixed, thanks!
https://hg.libsdl.org/SDL/rev/3e57ce45a890