Skip to content

Commit d0543f9

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 d0543f9

File tree

3 files changed

+38
-10
lines changed

3 files changed

+38
-10
lines changed
+10-6
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,24 @@
1+
## 10.2.1
2+
3+
* Check for BLUETOOTH_SCAN, BLUETOOTH_ADVERTISE or BLUETOOTH_CONNECT instead of BLUETOOTH permissions on api versions above 30.
4+
15
## 10.2.0
26

3-
* Added support for the new Android 13 permissions: SCHEDULE_EXACT_ALARM, READ_MEDIA_IMAGES, READ_MEDIA_VIDEO and READ_MEDIA_AUDIO
7+
- Added support for the new Android 13 permissions: SCHEDULE_EXACT_ALARM, READ_MEDIA_IMAGES, READ_MEDIA_VIDEO and READ_MEDIA_AUDIO
48

59
## 10.1.0
610

7-
* Added support for the new Android 13 permission: NEARBY_WIFI_DEVICES.
11+
- Added support for the new Android 13 permission: NEARBY_WIFI_DEVICES.
812

913
## 10.0.0
1014

11-
* __BREAKING CHANGE__: Updated Android `compileSdkVersion` to `33` to handle the new `POST_NOTIFICATIONS` permission.
12-
> When updating to version 10.0.0 make sure to update the `android/app/build.gradle` file and set the `compileSdkVersion` to `33`.
15+
- **BREAKING CHANGE**: Updated Android `compileSdkVersion` to `33` to handle the new `POST_NOTIFICATIONS` permission.
16+
> When updating to version 10.0.0 make sure to update the `android/app/build.gradle` file and set the `compileSdkVersion` to `33`.
1317
1418
## 9.0.2+1
1519

16-
* Undoes PR [#765](https://github.com/baseflow/flutter-permission-handler/pull/765) which by mistake requests write_external_storage permission based on the target SDK instead of the actual SDK of the Android device.
20+
- Undoes PR [#765](https://github.com/baseflow/flutter-permission-handler/pull/765) which by mistake requests write_external_storage permission based on the target SDK instead of the actual SDK of the Android device.
1721

1822
## 9.0.2
1923

20-
* Moves Android implementation into its own package.
24+
- Moves Android implementation into its own package.

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
}

permission_handler_android/pubspec.yaml

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
name: permission_handler_android
22
description: Permission plugin for Flutter. This plugin provides the Android API to request and check permissions.
3-
version: 10.2.0
3+
version: 10.2.1
44
homepage: https://github.com/baseflow/flutter-permission-handler
55

66
environment:

0 commit comments

Comments
 (0)