Skip to content

Commit 09040f4

Browse files
committed
Android: new Java template files for SDL 2.30.12
1 parent a926989 commit 09040f4

File tree

8 files changed

+904
-602
lines changed

8 files changed

+904
-602
lines changed

Diff for: templates/android/template/app/src/main/java/org/libsdl/app/HIDDeviceBLESteamController.java

+2-2
Original file line numberDiff line numberDiff line change
@@ -186,7 +186,7 @@ public BluetoothGatt getGatt() {
186186
// Because on Chromebooks we show up as a dual-mode device, it will attempt to connect TRANSPORT_AUTO, which will use TRANSPORT_BREDR instead
187187
// of TRANSPORT_LE. Let's force ourselves to connect low energy.
188188
private BluetoothGatt connectGatt(boolean managed) {
189-
if (Build.VERSION.SDK_INT >= 23) {
189+
if (Build.VERSION.SDK_INT >= 23 /* Android 6.0 (M) */) {
190190
try {
191191
return mDevice.connectGatt(mManager.getContext(), managed, this, TRANSPORT_LE);
192192
} catch (Exception e) {
@@ -429,7 +429,7 @@ public void run() {
429429
}
430430
});
431431
}
432-
}
432+
}
433433
else if (newState == 0) {
434434
mIsConnected = false;
435435
}

Diff for: templates/android/template/app/src/main/java/org/libsdl/app/HIDDeviceManager.java

+29-6
Original file line numberDiff line numberDiff line change
@@ -170,7 +170,7 @@ private void initializeUSB() {
170170
Log.i(TAG," Interface protocol: " + mUsbInterface.getInterfaceProtocol());
171171
Log.i(TAG," Endpoint count: " + mUsbInterface.getEndpointCount());
172172
173-
// Get endpoint details
173+
// Get endpoint details
174174
for (int epi = 0; epi < mUsbInterface.getEndpointCount(); epi++)
175175
{
176176
UsbEndpoint mEndpoint = mUsbInterface.getEndpoint(epi);
@@ -248,7 +248,11 @@ private boolean isXbox360Controller(UsbDevice usbDevice, UsbInterface usbInterfa
248248
0x1689, // Razer Onza
249249
0x1949, // Lab126, Inc.
250250
0x1bad, // Harmonix
251+
0x20d6, // PowerA
251252
0x24c6, // PowerA
253+
0x2c22, // Qanba
254+
0x2dc8, // 8BitDo
255+
0x9886, // ASTRO Gaming
252256
};
253257

254258
if (usbInterface.getInterfaceClass() == UsbConstants.USB_CLASS_VENDOR_SPEC &&
@@ -269,13 +273,20 @@ private boolean isXboxOneController(UsbDevice usbDevice, UsbInterface usbInterfa
269273
final int XB1_IFACE_SUBCLASS = 71;
270274
final int XB1_IFACE_PROTOCOL = 208;
271275
final int[] SUPPORTED_VENDORS = {
276+
0x03f0, // HP
277+
0x044f, // Thrustmaster
272278
0x045e, // Microsoft
273279
0x0738, // Mad Catz
280+
0x0b05, // ASUS
274281
0x0e6f, // PDP
275282
0x0f0d, // Hori
283+
0x10f5, // Turtle Beach
276284
0x1532, // Razer Wildcat
285+
0x20d6, // PowerA
277286
0x24c6, // PowerA
287+
0x2dc8, // 8BitDo
278288
0x2e24, // Hyperkin
289+
0x3537, // GameSir
279290
};
280291

281292
if (usbInterface.getId() == 0 &&
@@ -349,13 +360,19 @@ private void connectHIDDeviceUSB(UsbDevice usbDevice) {
349360
private void initializeBluetooth() {
350361
Log.d(TAG, "Initializing Bluetooth");
351362

352-
if (Build.VERSION.SDK_INT <= 30 &&
363+
if (Build.VERSION.SDK_INT >= 31 /* Android 12 */ &&
364+
mContext.getPackageManager().checkPermission(android.Manifest.permission.BLUETOOTH_CONNECT, mContext.getPackageName()) != PackageManager.PERMISSION_GRANTED) {
365+
Log.d(TAG, "Couldn't initialize Bluetooth, missing android.permission.BLUETOOTH_CONNECT");
366+
return;
367+
}
368+
369+
if (Build.VERSION.SDK_INT <= 30 /* Android 11.0 (R) */ &&
353370
mContext.getPackageManager().checkPermission(android.Manifest.permission.BLUETOOTH, mContext.getPackageName()) != PackageManager.PERMISSION_GRANTED) {
354371
Log.d(TAG, "Couldn't initialize Bluetooth, missing android.permission.BLUETOOTH");
355372
return;
356373
}
357374

358-
if (!mContext.getPackageManager().hasSystemFeature(PackageManager.FEATURE_BLUETOOTH_LE) || (Build.VERSION.SDK_INT < 18)) {
375+
if (!mContext.getPackageManager().hasSystemFeature(PackageManager.FEATURE_BLUETOOTH_LE) || (Build.VERSION.SDK_INT < 18 /* Android 4.3 (JELLY_BEAN_MR2) */)) {
359376
Log.d(TAG, "Couldn't initialize Bluetooth, this version of Android does not support Bluetooth LE");
360377
return;
361378
}
@@ -520,7 +537,7 @@ public void setFrozen(boolean frozen) {
520537
for (HIDDevice device : mDevicesById.values()) {
521538
device.setFrozen(frozen);
522539
}
523-
}
540+
}
524541
}
525542

526543
//////////////////////////////////////////////////////////////////////////////////////////////////////
@@ -569,12 +586,18 @@ public boolean openDevice(int deviceID) {
569586
try {
570587
final int FLAG_MUTABLE = 0x02000000; // PendingIntent.FLAG_MUTABLE, but don't require SDK 31
571588
int flags;
572-
if (Build.VERSION.SDK_INT >= 31) {
589+
if (Build.VERSION.SDK_INT >= 31 /* Android 12.0 (S) */) {
573590
flags = FLAG_MUTABLE;
574591
} else {
575592
flags = 0;
576593
}
577-
mUsbManager.requestPermission(usbDevice, PendingIntent.getBroadcast(mContext, 0, new Intent(HIDDeviceManager.ACTION_USB_PERMISSION), flags));
594+
if (Build.VERSION.SDK_INT >= 33 /* Android 14.0 (U) */) {
595+
Intent intent = new Intent(HIDDeviceManager.ACTION_USB_PERMISSION);
596+
intent.setPackage(mContext.getPackageName());
597+
mUsbManager.requestPermission(usbDevice, PendingIntent.getBroadcast(mContext, 0, intent, flags));
598+
} else {
599+
mUsbManager.requestPermission(usbDevice, PendingIntent.getBroadcast(mContext, 0, new Intent(HIDDeviceManager.ACTION_USB_PERMISSION), flags));
600+
}
578601
} catch (Exception e) {
579602
Log.v(TAG, "Couldn't request permission for USB device " + usbDevice);
580603
HIDDeviceOpenResult(deviceID, false);

Diff for: templates/android/template/app/src/main/java/org/libsdl/app/HIDDeviceUSB.java

+3-3
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ public int getProductId() {
5252
@Override
5353
public String getSerialNumber() {
5454
String result = null;
55-
if (Build.VERSION.SDK_INT >= 21) {
55+
if (Build.VERSION.SDK_INT >= 21 /* Android 5.0 (LOLLIPOP) */) {
5656
try {
5757
result = mDevice.getSerialNumber();
5858
}
@@ -74,7 +74,7 @@ public int getVersion() {
7474
@Override
7575
public String getManufacturerName() {
7676
String result = null;
77-
if (Build.VERSION.SDK_INT >= 21) {
77+
if (Build.VERSION.SDK_INT >= 21 /* Android 5.0 (LOLLIPOP) */) {
7878
result = mDevice.getManufacturerName();
7979
}
8080
if (result == null) {
@@ -86,7 +86,7 @@ public String getManufacturerName() {
8686
@Override
8787
public String getProductName() {
8888
String result = null;
89-
if (Build.VERSION.SDK_INT >= 21) {
89+
if (Build.VERSION.SDK_INT >= 21 /* Android 5.0 (LOLLIPOP) */) {
9090
result = mDevice.getProductName();
9191
}
9292
if (result == null) {

Diff for: templates/android/template/app/src/main/java/org/libsdl/app/SDL.java

+10-5
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ public static void initialize() {
2929

3030
// This function stores the current activity (SDL or not)
3131
public static void setContext(Context context) {
32+
SDLAudioManager.setContext(context);
3233
mContext = context;
3334
}
3435

@@ -37,6 +38,10 @@ public static Context getContext() {
3738
}
3839

3940
public static void loadLibrary(String libraryName) throws UnsatisfiedLinkError, SecurityException, NullPointerException {
41+
loadLibrary(libraryName, mContext);
42+
}
43+
44+
public static void loadLibrary(String libraryName, Context context) throws UnsatisfiedLinkError, SecurityException, NullPointerException {
4045

4146
if (libraryName == null) {
4247
throw new NullPointerException("No library name provided.");
@@ -52,10 +57,10 @@ public static void loadLibrary(String libraryName) throws UnsatisfiedLinkError,
5257
// To use ReLinker, just add it as a dependency. For more information, see
5358
// https://github.com/KeepSafe/ReLinker for ReLinker's repository.
5459
//
55-
Class<?> relinkClass = mContext.getClassLoader().loadClass("com.getkeepsafe.relinker.ReLinker");
56-
Class<?> relinkListenerClass = mContext.getClassLoader().loadClass("com.getkeepsafe.relinker.ReLinker$LoadListener");
57-
Class<?> contextClass = mContext.getClassLoader().loadClass("android.content.Context");
58-
Class<?> stringClass = mContext.getClassLoader().loadClass("java.lang.String");
60+
Class<?> relinkClass = context.getClassLoader().loadClass("com.getkeepsafe.relinker.ReLinker");
61+
Class<?> relinkListenerClass = context.getClassLoader().loadClass("com.getkeepsafe.relinker.ReLinker$LoadListener");
62+
Class<?> contextClass = context.getClassLoader().loadClass("android.content.Context");
63+
Class<?> stringClass = context.getClassLoader().loadClass("java.lang.String");
5964

6065
// Get a 'force' instance of the ReLinker, so we can ensure libraries are reinstalled if
6166
// they've changed during updates.
@@ -65,7 +70,7 @@ public static void loadLibrary(String libraryName) throws UnsatisfiedLinkError,
6570

6671
// Actually load the library!
6772
Method loadMethod = relinkInstanceClass.getDeclaredMethod("loadLibrary", contextClass, stringClass, stringClass, relinkListenerClass);
68-
loadMethod.invoke(relinkInstance, mContext, libraryName, null, null);
73+
loadMethod.invoke(relinkInstance, context, libraryName, null, null);
6974
}
7075
catch (final Throwable e) {
7176
// Fall back

0 commit comments

Comments
 (0)