diff --git a/permission_handler_android/CHANGELOG.md b/permission_handler_android/CHANGELOG.md index 365efaafd..6e470f112 100644 --- a/permission_handler_android/CHANGELOG.md +++ b/permission_handler_android/CHANGELOG.md @@ -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. \ No newline at end of file +- Moves Android implementation into its own package. diff --git a/permission_handler_android/android/src/main/java/com/baseflow/permissionhandler/PermissionManager.java b/permission_handler_android/android/src/main/java/com/baseflow/permissionhandler/PermissionManager.java index 2ab48d991..560919f0a 100644 --- a/permission_handler_android/android/src/main/java/com/baseflow/permissionhandler/PermissionManager.java +++ b/permission_handler_android/android/src/main/java/com/baseflow/permissionhandler/PermissionManager.java @@ -481,12 +481,36 @@ private int checkNotificationPermissionStatus(Context context) { } private int checkBluetoothPermissionStatus(Context context) { - List 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 names = PermissionUtils.getManifestNames(context, permission); + return names != null || !names.isEmpty(); + } +} } diff --git a/permission_handler_android/pubspec.yaml b/permission_handler_android/pubspec.yaml index 35c68edd2..496002e5b 100644 --- a/permission_handler_android/pubspec.yaml +++ b/permission_handler_android/pubspec.yaml @@ -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: