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 3191 - haptic system on android?
Summary: haptic system on android?
Status: RESOLVED FIXED
Alias: None
Product: SDL
Classification: Unclassified
Component: haptic (show other bugs)
Version: 2.0.3
Hardware: All Android (All)
: P2 normal
Assignee: Sylvain
QA Contact: Sam Lantinga
URL:
Keywords:
: 3747 (view as bug list)
Depends on:
Blocks:
 
Reported: 2015-12-01 10:21 UTC by jintiao
Modified: 2017-08-14 13:19 UTC (History)
4 users (show)

See Also:


Attachments
android-haptic-support.patch (20.68 KB, text/plain)
2015-12-04 05:08 UTC, jintiao
Details
android-haptic-support.patch (11.20 KB, patch)
2016-05-05 21:17 UTC, Milan Nikolic
Details | Diff
android-haptic-support.patch (20.44 KB, patch)
2016-05-05 22:13 UTC, Milan Nikolic
Details | Diff
patch (2.67 KB, patch)
2017-08-13 12:00 UTC, Sylvain
Details | Diff
patch (3.65 KB, patch)
2017-08-14 08:55 UTC, Sylvain
Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description jintiao 2015-12-01 10:21:16 UTC
hi developers.

have anybody ever try the haptic system on android? 
seems SDL_HapticOpenFromJoystick/SDL_HapticOpen will always return "Haptic: There are 0 haptic devices available".

android's permission policy is different from linux, the current solution for haptic device detection depends on stat/open (/dev/input/eventXX), which will get a "permission denied" error on android.
Comment 1 Philipp Wiesemann 2015-12-03 22:00:55 UTC
See also bug 3183.
Comment 2 jintiao 2015-12-04 05:08:39 UTC
Created attachment 2327 [details]
android-haptic-support.patch

I try to make the haptic system works on android, here's my patch
Comment 3 Philipp Wiesemann 2015-12-04 21:51:31 UTC
Thank you for working on a patch against SDL 2.0.3.

It looks like it is not finished yet but I still want to point out that some parts do not work on older Android devices (the planned SDL 2.0.4 currently still supports API Level 10).

There either need to be version checks at runtime or the whole minimal API level needs to be raised or maybe some parts could be replaced with the vibrator service which is more available (but not connected to single devices if this matters).
Comment 4 Ryan C. Gordon 2015-12-29 06:02:43 UTC
(In reply to Philipp Wiesemann from comment #3)
> It looks like it is not finished yet but I still want to point out that some
> parts do not work on older Android devices (the planned SDL 2.0.4 currently
> still supports API Level 10).

After 2.0.4, we should probably bump the API Level requirement, honestly. I'll revisit these patches after 2.0.4 ships and see if we can make it work for 2.0.5.

--ryan.
Comment 5 Milan Nikolic 2016-05-05 21:17:43 UTC
Created attachment 2444 [details]
android-haptic-support.patch

Hi,

Attached is a rebased patch that can be applied to latest hg. 

It builds fine but doesn't detect haptic device. It seems minimum api version is 16, and it did crash for me on version 14.
Comment 6 Philipp Wiesemann 2016-05-05 22:05:42 UTC
"SDL_syshaptic.c" is missing in the new patch.
Comment 7 Milan Nikolic 2016-05-05 22:13:30 UTC
Created attachment 2445 [details]
android-haptic-support.patch

Sorry, this one is with diff --new-file .
Comment 8 Sam Lantinga 2017-08-12 15:15:29 UTC
Can you guys verify that this patch works?
https://hg.libsdl.org/SDL/rev/c728c661cec7
Comment 9 Sylvain 2017-08-12 21:08:52 UTC
Quick test, I think there is some issue at runtime :


public static void pollHapticDevices() {...}
public static void hapticRun(){...}

( https://hg.libsdl.org/SDL/file/c728c661cec7/android-project/src/org/libsdl/app/SDLActivity.java#l1712 )

should go in the class SDLActivity {}

(same way as: https://hg.libsdl.org/SDL/file/c728c661cec7/android-project/src/org/libsdl/app/SDLActivity.java#l790 )
Comment 10 Sam Lantinga 2017-08-12 22:06:56 UTC
Sylvain, can you give me a tested patch for that?

Thanks!
Comment 11 Sylvain 2017-08-13 12:00:01 UTC
Created attachment 2832 [details]
patch

here's a patch so that it compiles, and add forward declarations to avoid warnings.
Comment 12 Sylvain 2017-08-13 12:17:47 UTC
A remark : 

I tried to run haptic on my smartphone and it did not work.
Probably, it works correctly with an external joystick with haptic (but I dont have one ..).

I thought it would also register the default internal vibrator of the phone ?

I tried to add the system vibrator service, in pollHapticDevices(): 

        {
           Vibrator vib = (Vibrator) SDLActivity.mSingleton.getContext().getSystemService(Context.VIBRATOR_SERVICE);
           if(vib.hasVibrator ()) {
              SDLHaptic haptic = new SDLHaptic();
              haptic.device_id = 999999;
              haptic.name = "VIBRATOR_SERVICE";
              haptic.vib = vib; 
//              mHaptics.add(haptic);  // dont add the device to the remove list
              SDLActivity.nativeAddHaptic(haptic.device_id, haptic.name);
           }
        }

And in run() method: 

   public void run(int device_id, int length) {
        if (device_id == 999999) {
            Vibrator vib = (Vibrator) SDLActivity.mSingleton.getContext().getSystemService(Context.VIBRATOR_SERVICE);
            vib.vibrate (length);

        }
Comment 13 Sam Lantinga 2017-08-14 04:22:26 UTC
Did that work? There's another patch for vibration on Android in bug 3183
Comment 14 Sylvain 2017-08-14 08:55:23 UTC
Created attachment 2845 [details]
patch

patch for SDLActivity.java:

- make it compile (same as previous patch).

- add vibrator service in the list of haptic devices. I use an hard-coded device_id for it ...

- I have removed also the function OpenURL that come by mistake from another commit.


you still can pick the warning patch diff of the previous patch (only file src/core/android/SDL_android.c)
Comment 15 Sam Lantinga 2017-08-14 13:18:53 UTC
*** Bug 3747 has been marked as a duplicate of this bug. ***
Comment 16 Sam Lantinga 2017-08-14 13:19:15 UTC
This is in, thanks!
https://hg.libsdl.org/SDL/rev/4276937a9792