From 80d19282f735997bc1b748afa0a4d5f3d3dcba6c Mon Sep 17 00:00:00 2001 From: FormularSumo Date: Thu, 19 Aug 2021 11:40:09 +0100 Subject: [PATCH] If Android version >= API 23 PendingIntent.FLAGIMMUTABLE "If your app targets Android 12, you must specify the mutability of each PendingIntent object that your app creates. This additional requirement improves your app's security." FLAG_IMMUTABLE was added in API 23 so that's why I'm using "> API 23". Using API 30 would also fix the Android 12 issue. Alternatively if PendingIntents should be mutable you could change it to "FLAG_MUTABLE". --- .../src/main/java/org/libsdl/app/HIDDeviceManager.java | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/android-project/app/src/main/java/org/libsdl/app/HIDDeviceManager.java b/android-project/app/src/main/java/org/libsdl/app/HIDDeviceManager.java index 041dc380f..ce21969d0 100644 --- a/android-project/app/src/main/java/org/libsdl/app/HIDDeviceManager.java +++ b/android-project/app/src/main/java/org/libsdl/app/HIDDeviceManager.java @@ -584,7 +584,14 @@ public class HIDDeviceManager { if (usbDevice != null && !mUsbManager.hasPermission(usbDevice)) { HIDDeviceOpenPending(deviceID); try { - mUsbManager.requestPermission(usbDevice, PendingIntent.getBroadcast(mContext, 0, new Intent(HIDDeviceManager.ACTION_USB_PERMISSION), 0)); + int flags; + if (Build.VERSION.SDK_INT >= 23) { + flags = PendingIntent.FLAG_IMMUTABLE; + } + else { + flags = 0; + } + 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);