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
This commit is contained in:
Sam Lantinga 2021-11-12 01:21:29 -08:00
parent 162772aa63
commit 97c71371f2
2 changed files with 8 additions and 1 deletions

0
Android.mk Normal file → Executable file
View File

View File

@ -554,7 +554,14 @@ public class HIDDeviceManager {
if (usbDevice != null && !mUsbManager.hasPermission(usbDevice)) { if (usbDevice != null && !mUsbManager.hasPermission(usbDevice)) {
HIDDeviceOpenPending(deviceID); HIDDeviceOpenPending(deviceID);
try { 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) { } catch (Exception e) {
Log.v(TAG, "Couldn't request permission for USB device " + usbDevice); Log.v(TAG, "Couldn't request permission for USB device " + usbDevice);
HIDDeviceOpenResult(deviceID, false); HIDDeviceOpenResult(deviceID, false);