Skip to content

Commit

Permalink
Fix android bluetooth permission request above api version 30
Browse files Browse the repository at this point in the history
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
  • Loading branch information
rufman committed Feb 10, 2023
1 parent 2e47f05 commit 64aaf3c
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 10 deletions.
16 changes: 10 additions & 6 deletions permission_handler_android/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,20 +1,24 @@
## 10.2.1

* Check for BLUETOOTH_SCAN, BLUETOOTH_ADVERTISE or BLUETOOTH_CONNECT instead of BLUETOOTH permissions on api versions above 30.

## 10.2.0

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

## 10.1.0

* Added support for the new Android 13 permission: NEARBY_WIFI_DEVICES.
- Added support for the new Android 13 permission: NEARBY_WIFI_DEVICES.

## 10.0.0

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

* 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.
- 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.

## 9.0.2

* Moves Android implementation into its own package.
- Moves Android implementation into its own package.
Original file line number Diff line number Diff line change
Expand Up @@ -481,12 +481,36 @@ private int checkNotificationPermissionStatus(Context context) {
}

private int checkBluetoothPermissionStatus(Context context) {
List<String> names = PermissionUtils.getManifestNames(context, PermissionConstants.PERMISSION_GROUP_BLUETOOTH);
boolean missingInManifest = names == null || names.isEmpty();
if (missingInManifest) {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.S) {
// BLUETOOTH permission was removed in Android S in favor of BLUETOOTH_SCAN,
// BLUETOOTH_ADVERTISE and BLUETOOTH_CONNECT.
// This means above version 30 we need to check if any one of those permissions
// are present instead.
boolean scanPermission = checkPermissionStatus(context,
PermissionConstants.PERMISSION_GROUP_BLUETOOTH_SCAN);
boolean advertisePermission = checkPermissionStatus(context,
PermissionConstants.PERMISSION_GROUP_BLUETOOTH_ADVERTISE);
boolean connectPermission = checkPermissionStatus(context,
PermissionConstants.PERMISSION_GROUP_BLUETOOTH_CONNECT);

if (!scanPermission && !advertisePermission && !connectPermission) {
Log.d(PermissionConstants.LOG_TAG, "Of the bluetooth permissions (BLUETOOTH_SCAN, BLUETOOTH_ADVERTISE or BLUETOOTH_CONNECT) missing in manifest");
return PermissionConstants.PERMISSION_STATUS_DENIED;
}
return PermissionConstants.PERMISSION_STATUS_GRANTED;
}
// legacy check for BLUETOOTH permission
boolean bluetoothPermission = checkPermissionStatus(context, PermissionConstants.PERMISSION_GROUP_BLUETOOTH);
if (!bluetoothPermission) {
Log.d(PermissionConstants.LOG_TAG, "Bluetooth permission missing in manifest");
return PermissionConstants.PERMISSION_STATUS_DENIED;
}
return PermissionConstants.PERMISSION_STATUS_GRANTED;
}

private boolean checkPermissionStatus(Context context, @PermissionConstants.PermissionGroup int permission) {
List<String> names = PermissionUtils.getManifestNames(context, permission);
return names != null || !names.isEmpty();
}
}
}
2 changes: 1 addition & 1 deletion permission_handler_android/pubspec.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
name: permission_handler_android
description: Permission plugin for Flutter. This plugin provides the Android API to request and check permissions.
version: 10.2.0
version: 10.2.1
homepage: https://github.com/baseflow/flutter-permission-handler

environment:
Expand Down

0 comments on commit 64aaf3c

Please sign in to comment.