From 933aadbe573448e05313b51ec70356003f4158a5 Mon Sep 17 00:00:00 2001 From: Ghabry Date: Mon, 26 Aug 2024 19:01:50 +0200 Subject: [PATCH] Android: Bump SDL2 to 2.30.6 --- .../java/org/libsdl/app/HIDDeviceManager.java | 9 ++++++++- .../app/src/main/java/org/libsdl/app/SDL.java | 14 +++++++++----- .../org/libsdl/app/SDLControllerManager.java | 16 +++++++++------- 3 files changed, 26 insertions(+), 13 deletions(-) diff --git a/builds/android/app/src/main/java/org/libsdl/app/HIDDeviceManager.java b/builds/android/app/src/main/java/org/libsdl/app/HIDDeviceManager.java index e7281fdf26..21a1c1d18e 100644 --- a/builds/android/app/src/main/java/org/libsdl/app/HIDDeviceManager.java +++ b/builds/android/app/src/main/java/org/libsdl/app/HIDDeviceManager.java @@ -277,6 +277,7 @@ private boolean isXboxOneController(UsbDevice usbDevice, UsbInterface usbInterfa 0x044f, // Thrustmaster 0x045e, // Microsoft 0x0738, // Mad Catz + 0x0b05, // ASUS 0x0e6f, // PDP 0x0f0d, // Hori 0x10f5, // Turtle Beach @@ -590,7 +591,13 @@ public boolean openDevice(int deviceID) { } else { flags = 0; } - mUsbManager.requestPermission(usbDevice, PendingIntent.getBroadcast(mContext, 0, new Intent(HIDDeviceManager.ACTION_USB_PERMISSION), flags)); + if (Build.VERSION.SDK_INT >= 33 /* Android 14.0 (U) */) { + Intent intent = new Intent(HIDDeviceManager.ACTION_USB_PERMISSION); + intent.setPackage(mContext.getPackageName()); + mUsbManager.requestPermission(usbDevice, PendingIntent.getBroadcast(mContext, 0, intent, flags)); + } else { + mUsbManager.requestPermission(usbDevice, PendingIntent.getBroadcast(mContext, 0, new Intent(HIDDeviceManager.ACTION_USB_PERMISSION), flags)); + } } catch (Exception e) { Log.v(TAG, "Couldn't request permission for USB device " + usbDevice); HIDDeviceOpenResult(deviceID, false); diff --git a/builds/android/app/src/main/java/org/libsdl/app/SDL.java b/builds/android/app/src/main/java/org/libsdl/app/SDL.java index 44c21c1c75..139be9d151 100644 --- a/builds/android/app/src/main/java/org/libsdl/app/SDL.java +++ b/builds/android/app/src/main/java/org/libsdl/app/SDL.java @@ -38,6 +38,10 @@ public static Context getContext() { } public static void loadLibrary(String libraryName) throws UnsatisfiedLinkError, SecurityException, NullPointerException { + loadLibrary(libraryName, mContext); + } + + public static void loadLibrary(String libraryName, Context context) throws UnsatisfiedLinkError, SecurityException, NullPointerException { if (libraryName == null) { throw new NullPointerException("No library name provided."); @@ -53,10 +57,10 @@ public static void loadLibrary(String libraryName) throws UnsatisfiedLinkError, // To use ReLinker, just add it as a dependency. For more information, see // https://github.com/KeepSafe/ReLinker for ReLinker's repository. // - Class relinkClass = mContext.getClassLoader().loadClass("com.getkeepsafe.relinker.ReLinker"); - Class relinkListenerClass = mContext.getClassLoader().loadClass("com.getkeepsafe.relinker.ReLinker$LoadListener"); - Class contextClass = mContext.getClassLoader().loadClass("android.content.Context"); - Class stringClass = mContext.getClassLoader().loadClass("java.lang.String"); + Class relinkClass = context.getClassLoader().loadClass("com.getkeepsafe.relinker.ReLinker"); + Class relinkListenerClass = context.getClassLoader().loadClass("com.getkeepsafe.relinker.ReLinker$LoadListener"); + Class contextClass = context.getClassLoader().loadClass("android.content.Context"); + Class stringClass = context.getClassLoader().loadClass("java.lang.String"); // Get a 'force' instance of the ReLinker, so we can ensure libraries are reinstalled if // they've changed during updates. @@ -66,7 +70,7 @@ public static void loadLibrary(String libraryName) throws UnsatisfiedLinkError, // Actually load the library! Method loadMethod = relinkInstanceClass.getDeclaredMethod("loadLibrary", contextClass, stringClass, stringClass, relinkListenerClass); - loadMethod.invoke(relinkInstance, mContext, libraryName, null, null); + loadMethod.invoke(relinkInstance, context, libraryName, null, null); } catch (final Throwable e) { // Fall back diff --git a/builds/android/app/src/main/java/org/libsdl/app/SDLControllerManager.java b/builds/android/app/src/main/java/org/libsdl/app/SDLControllerManager.java index d6913f1571..9d8b20b7bb 100644 --- a/builds/android/app/src/main/java/org/libsdl/app/SDLControllerManager.java +++ b/builds/android/app/src/main/java/org/libsdl/app/SDLControllerManager.java @@ -546,13 +546,15 @@ public void pollHapticDevices() { 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 (vib != null) { + 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); + } } } }