From 956b605dd6bb9c79e60cf59db3cfc47fb6998bdf Mon Sep 17 00:00:00 2001 From: Philip Peitsch Date: Tue, 23 Jul 2024 13:18:10 +1000 Subject: [PATCH] Only mark export/non-export for non-system receivers on Android v34 (#1020) A clear exception has been carved out for system broadcasts registered via Context#registerReceiver See https://developer.android.com/about/versions/14/behavior-changes-14#system-broadcasts --- src/android/BLECentralPlugin.java | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/android/BLECentralPlugin.java b/src/android/BLECentralPlugin.java index 7a693e5c..a59de0c9 100644 --- a/src/android/BLECentralPlugin.java +++ b/src/android/BLECentralPlugin.java @@ -665,7 +665,7 @@ public void onReceive(Context context, Intent intent) { try { IntentFilter intentFilter = new IntentFilter(BluetoothAdapter.ACTION_STATE_CHANGED); - registerSystemReceiverCompat(this.stateReceiver, intentFilter); + webView.getContext().registerReceiver(this.stateReceiver, intentFilter); } catch (Exception e) { LOG.e(TAG, "Error registering state receiver: " + e.getMessage(), e); } @@ -712,7 +712,7 @@ public void onReceive(Context context, Intent intent) { try { IntentFilter intentFilter = new IntentFilter(LocationManager.PROVIDERS_CHANGED_ACTION); intentFilter.addAction(Intent.ACTION_PROVIDER_CHANGED); - registerSystemReceiverCompat(this.locationStateReceiver, intentFilter); + registerNonSystemReceiverCompat(this.locationStateReceiver, intentFilter); } catch (Exception e) { LOG.e(TAG, "Error registering location state receiver: " + e.getMessage(), e); } @@ -853,7 +853,7 @@ public void onReceive(Context context, Intent intent) { IntentFilter intentFilter = new IntentFilter(BluetoothDevice.ACTION_PAIRING_REQUEST); intentFilter.setPriority(IntentFilter.SYSTEM_HIGH_PRIORITY); - registerSystemReceiverCompat(broadCastReceiver, intentFilter); + webView.getContext().registerReceiver(broadCastReceiver, intentFilter); callbackContext.success("OK"); } catch (Exception e) { @@ -1511,7 +1511,7 @@ public void onReceive(Context context, Intent intent) { } } }; - registerSystemReceiverCompat(bondStateReceiver, new IntentFilter(ACTION_BOND_STATE_CHANGED)); + webView.getContext().registerReceiver(bondStateReceiver, new IntentFilter(ACTION_BOND_STATE_CHANGED)); } } @@ -1523,7 +1523,7 @@ private void removeBondStateListener() { } @SuppressLint({"UnspecifiedRegisterReceiverFlag", "WrongConstant"}) - private void registerSystemReceiverCompat(BroadcastReceiver receiver, IntentFilter filter) { + private void registerNonSystemReceiverCompat(BroadcastReceiver receiver, IntentFilter filter) { Context context = webView.getContext(); if (Build.VERSION.SDK_INT >= 34 /*14*/) { context.registerReceiver(receiver, filter, 2); // // Context.RECEIVER_EXPORTED