Skip to content

Commit

Permalink
Only mark export/non-export for non-system receivers on Android v34 (#…
Browse files Browse the repository at this point in the history
…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
  • Loading branch information
peitschie committed Jul 23, 2024
1 parent 8e7e078 commit 956b605
Showing 1 changed file with 5 additions and 5 deletions.
10 changes: 5 additions & 5 deletions src/android/BLECentralPlugin.java
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down Expand Up @@ -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);
}
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -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));
}
}

Expand All @@ -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
Expand Down

0 comments on commit 956b605

Please sign in to comment.