Skip to content

Commit 168dabd

Browse files
Fix android bluetooth permission request above api version 30
The BLUETOOTH permission was removed in api version 30 in favor of BLUETOOTH_SCAN, BLUETOOTH_ADVERTISE and BLUETOOTH_CONNECT. This means that manifests targetting api version above 30 will not have this permission set. For these versions the manifest should be checked for the new permissions. This change ensures that the documented behavior of the bluetooth permission always returning `true` is true. Fixes issues Baseflow#884
1 parent 2e47f05 commit 168dabd

File tree

1 file changed

+27
-3
lines changed

1 file changed

+27
-3
lines changed

permission_handler_android/android/src/main/java/com/baseflow/permissionhandler/PermissionManager.java

+27-3
Original file line numberDiff line numberDiff line change
@@ -481,12 +481,36 @@ private int checkNotificationPermissionStatus(Context context) {
481481
}
482482

483483
private int checkBluetoothPermissionStatus(Context context) {
484-
List<String> names = PermissionUtils.getManifestNames(context, PermissionConstants.PERMISSION_GROUP_BLUETOOTH);
485-
boolean missingInManifest = names == null || names.isEmpty();
486-
if (missingInManifest) {
484+
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.S) {
485+
// BLUETOOTH permission was removed in Android S in favor of BLUETOOTH_SCAN,
486+
// BLUETOOTH_ADVERTISE and BLUETOOTH_CONNECT.
487+
// This means above version 30 we need to check if any one of those permissions
488+
// are present instead.
489+
boolean scanPermission = checkPermissionStatus(context,
490+
PermissionConstants.PERMISSION_GROUP_BLUETOOTH_SCAN);
491+
boolean advertisePermission = checkPermissionStatus(context,
492+
PermissionConstants.PERMISSION_GROUP_BLUETOOTH_ADVERTISE);
493+
boolean connectPermission = checkPermissionStatus(context,
494+
PermissionConstants.PERMISSION_GROUP_BLUETOOTH_CONNECT);
495+
496+
if (!scanPermission && !advertisePermission && !connectPermission) {
497+
Log.d(PermissionConstants.LOG_TAG, "Of the bluetooth permissions (BLUETOOTH_SCAN, BLUETOOTH_ADVERTISE or BLUETOOTH_CONNECT) missing in manifest");
498+
return PermissionConstants.PERMISSION_STATUS_DENIED;
499+
}
500+
return PermissionConstants.PERMISSION_STATUS_GRANTED;
501+
}
502+
// legacy check for BLUETOOTH permission
503+
boolean bluetoothPermission = checkPermissionStatus(context, PermissionConstants.PERMISSION_GROUP_BLUETOOTH);
504+
if (!bluetoothPermission) {
487505
Log.d(PermissionConstants.LOG_TAG, "Bluetooth permission missing in manifest");
488506
return PermissionConstants.PERMISSION_STATUS_DENIED;
489507
}
490508
return PermissionConstants.PERMISSION_STATUS_GRANTED;
491509
}
510+
511+
private boolean checkPermissionStatus(Context context, @PermissionConstants.PermissionGroup int permission) {
512+
List<String> names = PermissionUtils.getManifestNames(context, permission);
513+
return names != null || !names.isEmpty();
514+
}
515+
}
492516
}

0 commit comments

Comments
 (0)