Fixed bug 3843 - Android missing some code in SDLHapticHandler Sylvain Some check for android SDK version are missing from https://hg.libsdl.org/SDL/rev/3d7a29a369a0 here's a patch
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96
diff --git a/android-project/src/org/libsdl/app/SDLControllerManager.java b/android-project/src/org/libsdl/app/SDLControllerManager.java
index c050764..ef946ac 100644
--- a/android-project/src/org/libsdl/app/SDLControllerManager.java
+++ b/android-project/src/org/libsdl/app/SDLControllerManager.java
@@ -300,7 +300,7 @@ class SDLHapticHandler {
public void pollHapticDevices() {
final int deviceId_VIBRATOR_SERVICE = 999999;
- boolean hasVibrator = false;
+ boolean hasVibratorService = false;
int[] deviceIds = InputDevice.getDeviceIds();
// It helps processing the device ids in reverse order
@@ -308,37 +308,45 @@ class SDLHapticHandler {
// so the first controller seen by SDL matches what the receiver
// considers to be the first controller
- for(int i=deviceIds.length-1; i>-1; i--) {
- SDLHaptic haptic = getHaptic(deviceIds[i]);
- if (haptic == null) {
- InputDevice device = InputDevice.getDevice(deviceIds[i]);
- Vibrator vib = device.getVibrator();
- if (vib.hasVibrator()) {
- haptic = new SDLHaptic();
- haptic.device_id = deviceIds[i];
- haptic.name = device.getName();
- haptic.vib = vib;
- mHaptics.add(haptic);
- SDLControllerManager.nativeAddHaptic(haptic.device_id, haptic.name);
+ if (Build.VERSION.SDK_INT >= 16)
+ {
+ for (int i = deviceIds.length - 1; i > -1; i--) {
+ SDLHaptic haptic = getHaptic(deviceIds[i]);
+ if (haptic == null) {
+ InputDevice device = InputDevice.getDevice(deviceIds[i]);
+ Vibrator vib = device.getVibrator();
+ if (vib.hasVibrator()) {
+ haptic = new SDLHaptic();
+ haptic.device_id = deviceIds[i];
+ haptic.name = device.getName();
+ haptic.vib = vib;
+ mHaptics.add(haptic);
+ SDLControllerManager.nativeAddHaptic(haptic.device_id, haptic.name);
+ }
}
}
}
/* Check VIBRATOR_SERVICE */
- {
- Vibrator vib = (Vibrator) SDL.getContext().getSystemService(Context.VIBRATOR_SERVICE);
- if (vib != null && vib.hasVibrator()) {
- hasVibrator = true;
- SDLHaptic haptic = getHaptic(deviceId_VIBRATOR_SERVICE);
- if (haptic == null) {
- haptic = new SDLHaptic();
- haptic.device_id = deviceId_VIBRATOR_SERVICE;
- haptic.name = "VIBRATOR_SERVICE";
- haptic.vib = vib;
- mHaptics.add(haptic);
- SDLControllerManager.nativeAddHaptic(haptic.device_id, haptic.name);
- }
- }
+ Vibrator vib = (Vibrator) SDL.getContext().getSystemService(Context.VIBRATOR_SERVICE);
+ if (vib != null) {
+ if (Build.VERSION.SDK_INT >= 11) {
+ hasVibratorService = vib.hasVibrator();
+ } else {
+ hasVibratorService = true;
+ }
+
+ if (hasVibratorService) {
+ SDLHaptic haptic = getHaptic(deviceId_VIBRATOR_SERVICE);
+ if (haptic == null) {
+ haptic = new SDLHaptic();
+ haptic.device_id = deviceId_VIBRATOR_SERVICE;
+ haptic.name = "VIBRATOR_SERVICE";
+ haptic.vib = vib;
+ mHaptics.add(haptic);
+ SDLControllerManager.nativeAddHaptic(haptic.device_id, haptic.name);
+ }
+ }
}
/* Check removed devices */
@@ -350,8 +358,8 @@ class SDLHapticHandler {
if (device_id == deviceIds[j]) break;
}
- if (device_id == deviceId_VIBRATOR_SERVICE && hasVibrator) {
- // don't remove the vibrator if it is still present
+ if (device_id == deviceId_VIBRATOR_SERVICE && hasVibratorService) {
+ // don't remove the vibrator if it is still present
} else if (j == deviceIds.length) {
removedDevices.add(device_id);
}