Android: use RECEIVER_NOT_EXPORTED for receivers on API 33+

(cherry picked from commit 88017f5023)
This commit is contained in:
Craig Chandler
2026-04-07 11:02:35 +09:30
committed by Sam Lantinga
parent 473efcf53c
commit 5297f5a772

View File

@@ -193,7 +193,7 @@ public class HIDDeviceManager {
filter.addAction(UsbManager.ACTION_USB_DEVICE_ATTACHED);
filter.addAction(UsbManager.ACTION_USB_DEVICE_DETACHED);
filter.addAction(HIDDeviceManager.ACTION_USB_PERMISSION);
mContext.registerReceiver(mUsbBroadcast, filter);
registerReceiverCompat(mUsbBroadcast, filter);
for (UsbDevice usbDevice : mUsbManager.getDeviceList().values()) {
handleUsbDeviceAttached(usbDevice);
@@ -404,7 +404,7 @@ public class HIDDeviceManager {
IntentFilter filter = new IntentFilter();
filter.addAction(BluetoothDevice.ACTION_ACL_CONNECTED);
filter.addAction(BluetoothDevice.ACTION_ACL_DISCONNECTED);
mContext.registerReceiver(mBluetoothBroadcast, filter);
registerReceiverCompat(mBluetoothBroadcast, filter);
if (mIsChromebook) {
mHandler = new Handler(Looper.getMainLooper());
@@ -428,6 +428,14 @@ public class HIDDeviceManager {
}
}
private void registerReceiverCompat(BroadcastReceiver receiver, IntentFilter filter) {
if (Build.VERSION.SDK_INT >= 33) {
mContext.registerReceiver(receiver, filter, Context.RECEIVER_NOT_EXPORTED);
} else {
mContext.registerReceiver(receiver, filter);
}
}
// Chromebooks do not pass along ACTION_ACL_CONNECTED / ACTION_ACL_DISCONNECTED properly.
// This function provides a sort of dummy version of that, watching for changes in the
// connected devices and attempting to add controllers as things change.