From 97c71371f21187f146872d41f94a5593c0a374ba Mon Sep 17 00:00:00 2001 From: Sam Lantinga Date: Fri, 12 Nov 2021 01:21:29 -0800 Subject: [PATCH] If Android version >= API 31 PendingIntent.FLAG_MUTABLE "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." Thanks @FormularSumo and @cgutman --- Android.mk | 0 .../src/main/java/org/libsdl/app/HIDDeviceManager.java | 9 ++++++++- 2 files changed, 8 insertions(+), 1 deletion(-) mode change 100644 => 100755 Android.mk diff --git a/Android.mk b/Android.mk old mode 100644 new mode 100755 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 ae1c84266..ab0a0999c 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 @@ -554,7 +554,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)); + final int FLAG_MUTABLE = 0x02000000; // PendingIntent.FLAG_MUTABLE, but don't require SDK 31 + int flags; + if (Build.VERSION.SDK_INT >= 31) { + flags = FLAG_MUTABLE; + } 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);