From 331f339f9a8f41fed17906a677caf3da64e254c0 Mon Sep 17 00:00:00 2001 From: Philip Peitsch Date: Sat, 13 Jul 2024 20:11:13 +1000 Subject: [PATCH] Mark broadcast receivers as exported for Android v34 (#1020) --- src/android/BLECentralPlugin.java | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/src/android/BLECentralPlugin.java b/src/android/BLECentralPlugin.java index 1514a96d..038d15f2 100644 --- a/src/android/BLECentralPlugin.java +++ b/src/android/BLECentralPlugin.java @@ -53,6 +53,8 @@ import java.util.*; +import androidx.core.content.ContextCompat; + import static android.bluetooth.BluetoothDevice.DEVICE_TYPE_DUAL; import static android.bluetooth.BluetoothDevice.DEVICE_TYPE_LE; import static android.bluetooth.BluetoothDevice.ACTION_BOND_STATE_CHANGED; @@ -114,6 +116,8 @@ public class BLECentralPlugin extends CordovaPlugin { private static final String START_LOCATION_STATE_NOTIFICATIONS = "startLocationStateNotifications"; private static final String STOP_LOCATION_STATE_NOTIFICATIONS = "stopLocationStateNotifications"; + private static final int RECEIVER_EXPORTED = 0x2; // ContextCompat.RECEIVER_EXPORTED + // callbacks CallbackContext discoverCallback; private CallbackContext enableBluetoothCallback; @@ -660,7 +664,7 @@ public void onReceive(Context context, Intent intent) { try { IntentFilter intentFilter = new IntentFilter(BluetoothAdapter.ACTION_STATE_CHANGED); - webView.getContext().registerReceiver(this.stateReceiver, intentFilter); + ContextCompat.registerReceiver(webView.getContext(), stateReceiver, intentFilter, RECEIVER_EXPORTED); } catch (Exception e) { LOG.e(TAG, "Error registering state receiver: " + e.getMessage(), e); } @@ -707,7 +711,7 @@ public void onReceive(Context context, Intent intent) { try { IntentFilter intentFilter = new IntentFilter(LocationManager.PROVIDERS_CHANGED_ACTION); intentFilter.addAction(Intent.ACTION_PROVIDER_CHANGED); - webView.getContext().registerReceiver(this.locationStateReceiver, intentFilter); + ContextCompat.registerReceiver(webView.getContext(), this.locationStateReceiver, intentFilter, RECEIVER_EXPORTED); } catch (Exception e) { LOG.e(TAG, "Error registering location state receiver: " + e.getMessage(), e); } @@ -742,7 +746,7 @@ private void connect(CallbackContext callbackContext, String macAddress) { return; } - if (!peripherals.containsKey(macAddress) && BLECentralPlugin.this.bluetoothAdapter.checkBluetoothAddress(macAddress)) { + if (!peripherals.containsKey(macAddress) && BluetoothAdapter.checkBluetoothAddress(macAddress)) { BluetoothDevice device = BLECentralPlugin.this.bluetoothAdapter.getRemoteDevice(macAddress); Peripheral peripheral = new Peripheral(device); peripherals.put(macAddress, peripheral); @@ -848,7 +852,7 @@ public void onReceive(Context context, Intent intent) { IntentFilter intentFilter = new IntentFilter(BluetoothDevice.ACTION_PAIRING_REQUEST); intentFilter.setPriority(IntentFilter.SYSTEM_HIGH_PRIORITY); - webView.getContext().registerReceiver(broadCastReceiver, intentFilter); + ContextCompat.registerReceiver(webView.getContext(), broadCastReceiver, intentFilter, RECEIVER_EXPORTED); callbackContext.success("OK"); } catch (Exception e) { @@ -1506,7 +1510,7 @@ public void onReceive(Context context, Intent intent) { } } }; - ContextCompat.registerReceiver(webView.getContext(), bondStateReceiver, new IntentFilter(ACTION_BOND_STATE_CHANGED), ContextCompat.RECEIVER_EXPORTED); + ContextCompat.registerReceiver(webView.getContext(), bondStateReceiver, new IntentFilter(ACTION_BOND_STATE_CHANGED), RECEIVER_EXPORTED); } }