Commit 46a14456 by PieterAelse Committed by GitHub

Added support for the 3 new Bluetooth permissions of Android 12. (#671)

Co-authored-by: Pieter Otten <pieter.otten@signify.com>
parent be4ae86c
## 8.2.0
* Added support for the new Android 12 Bluetooth permissions: BLUETOOTH_SCAN, BLUETOOTH_ADVERTISE and BLUETOOTH_CONNECT.
* Updated Android compile and target SDK to 31 (Android 12 (S)).
* Updated Gradle and dependencies of Android project.
* Updated applicationID of example app
## 8.1.6
* Android: Fixed a `NullPointerException` when changing permissions in the Location Settings intent.
......
......@@ -10,7 +10,7 @@ buildscript {
}
dependencies {
classpath 'com.android.tools.build:gradle:3.5.0'
classpath 'com.android.tools.build:gradle:4.0.2'
}
}
......@@ -28,7 +28,7 @@ project.getTasks().withType(JavaCompile){
apply plugin: 'com.android.library'
android {
compileSdkVersion 30
compileSdkVersion 31
defaultConfig {
minSdkVersion 16
......@@ -44,8 +44,8 @@ android {
}
dependencies {
implementation 'androidx.annotation:annotation:1.1.0'
implementation 'androidx.core:core:1.1.0'
implementation 'androidx.annotation:annotation:1.2.0'
implementation 'androidx.core:core:1.6.0'
}
repositories {
......
org.gradle.jvmargs=-Xmx1536M
android.useAndroidX=true
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-6.8-bin.zip
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
......@@ -43,6 +43,10 @@ final class PermissionConstants {
static final int PERMISSION_GROUP_APP_TRACK_TRANSPARENCY = 25;
static final int PERMISSION_GROUP_CRITICAL_ALERTS = 26;
static final int PERMISSION_GROUP_ACCESS_NOTIFICATION_POLICY = 27;
static final int PERMISSION_GROUP_BLUETOOTH_SCAN = 28;
static final int PERMISSION_GROUP_BLUETOOTH_ADVERTISE = 29;
static final int PERMISSION_GROUP_BLUETOOTH_CONNECT = 30;
@Retention(RetentionPolicy.SOURCE)
@IntDef({
......@@ -70,7 +74,10 @@ final class PermissionConstants {
PERMISSION_GROUP_MANAGE_EXTERNAL_STORAGE,
PERMISSION_GROUP_SYSTEM_ALERT_WINDOW,
PERMISSION_GROUP_REQUEST_INSTALL_PACKAGES,
PERMISSION_GROUP_ACCESS_NOTIFICATION_POLICY
PERMISSION_GROUP_ACCESS_NOTIFICATION_POLICY,
PERMISSION_GROUP_BLUETOOTH_SCAN,
PERMISSION_GROUP_BLUETOOTH_ADVERTISE,
PERMISSION_GROUP_BLUETOOTH_CONNECT
})
@interface PermissionGroup {
}
......
......@@ -69,6 +69,12 @@ public class PermissionUtils {
return PermissionConstants.PERMISSION_GROUP_REQUEST_INSTALL_PACKAGES;
case Manifest.permission.ACCESS_NOTIFICATION_POLICY:
return PermissionConstants.PERMISSION_GROUP_ACCESS_NOTIFICATION_POLICY;
case Manifest.permission.BLUETOOTH_SCAN:
return PermissionConstants.PERMISSION_GROUP_BLUETOOTH_SCAN;
case Manifest.permission.BLUETOOTH_ADVERTISE:
return PermissionConstants.PERMISSION_GROUP_BLUETOOTH_ADVERTISE;
case Manifest.permission.BLUETOOTH_CONNECT:
return PermissionConstants.PERMISSION_GROUP_BLUETOOTH_CONNECT;
default:
return PermissionConstants.PERMISSION_GROUP_UNKNOWN;
}
......@@ -247,6 +253,24 @@ public class PermissionUtils {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M && hasPermissionInManifest(context, permissionNames, Manifest.permission.ACCESS_NOTIFICATION_POLICY ))
permissionNames.add(Manifest.permission.ACCESS_NOTIFICATION_POLICY);
break;
case PermissionConstants.PERMISSION_GROUP_BLUETOOTH_SCAN:
// The BLUETOOTH_SCAN permission is introduced in Android S, meaning we should
// not handle permissions on pre Android S devices.
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.S && hasPermissionInManifest(context, permissionNames, Manifest.permission.BLUETOOTH_SCAN ))
permissionNames.add(Manifest.permission.BLUETOOTH_SCAN);
break;
case PermissionConstants.PERMISSION_GROUP_BLUETOOTH_ADVERTISE:
// The BLUETOOTH_ADVERTISE permission is introduced in Android S, meaning we should
// not handle permissions on pre Android S devices.
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.S && hasPermissionInManifest(context, permissionNames, Manifest.permission.BLUETOOTH_ADVERTISE ))
permissionNames.add(Manifest.permission.BLUETOOTH_ADVERTISE);
break;
case PermissionConstants.PERMISSION_GROUP_BLUETOOTH_CONNECT:
// The BLUETOOTH_CONNECT permission is introduced in Android S, meaning we should
// not handle permissions on pre Android S devices.
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.S && hasPermissionInManifest(context, permissionNames, Manifest.permission.BLUETOOTH_CONNECT ))
permissionNames.add(Manifest.permission.BLUETOOTH_CONNECT);
break;
case PermissionConstants.PERMISSION_GROUP_NOTIFICATION:
case PermissionConstants.PERMISSION_GROUP_MEDIA_LIBRARY:
case PermissionConstants.PERMISSION_GROUP_PHOTOS:
......
......@@ -25,17 +25,16 @@ apply plugin: 'com.android.application'
apply from: "$flutterRoot/packages/flutter_tools/gradle/flutter.gradle"
android {
compileSdkVersion 30
compileSdkVersion 31
lintOptions {
disable 'InvalidPackage'
}
defaultConfig {
// TODO: Specify your own unique Application ID (https://developer.android.com/studio/build/application-id.html).
applicationId "com.example.permissionhandlerexample"
applicationId "com.baseflow.permissionhandler.example"
minSdkVersion 16
targetSdkVersion 29
targetSdkVersion 31
versionCode flutterVersionCode.toInteger()
versionName flutterVersionName
}
......
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.permissionhandlerexample">
package="com.baseflow.permissionhandler.example">
<!-- Flutter needs it to communicate with the running application
to allow setting breakpoints, to provide hot reload, etc.
-->
......
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
package="com.example.permissionhandlerexample">
package="com.baseflow.permissionhandler.example">
<!--
Internet permissions do not affect the `permission_handler` plugin, but are required if your app needs access to
......@@ -62,6 +62,9 @@
<!-- Permissions options for the `bluetooth` group -->
<uses-permission android:name="android.permission.BLUETOOTH" />
<uses-permission android:name="android.permission.BLUETOOTH_SCAN" />
<uses-permission android:name="android.permission.BLUETOOTH_ADVERTISE" />
<uses-permission android:name="android.permission.BLUETOOTH_CONNECT" />
<!-- Permissions options for the `manage external storage` group -->
<uses-permission android:name="android.permission.MANAGE_EXTERNAL_STORAGE" />
......@@ -80,17 +83,20 @@
android:icon="@mipmap/ic_launcher"
android:label="permission_handler_example"
tools:ignore="AllowBackup,GoogleAppIndexingWarning">
<activity android:name="io.flutter.embedding.android.FlutterActivity"
android:launchMode="singleTop"
android:theme="@android:style/Theme.Black.NoTitleBar"
android:configChanges="orientation|keyboardHidden|keyboard|screenSize|locale|layoutDirection"
android:hardwareAccelerated="true"
android:windowSoftInputMode="adjustResize">
android:windowSoftInputMode="adjustResize"
android:exported="true">
<intent-filter>
<action android:name="android.intent.action.MAIN"/>
<category android:name="android.intent.category.LAUNCHER"/>
</intent-filter>
</activity>
<meta-data
android:name="flutterEmbedding"
android:value="2" />
......
......@@ -5,7 +5,7 @@ buildscript {
}
dependencies {
classpath 'com.android.tools.build:gradle:3.5.0'
classpath 'com.android.tools.build:gradle:4.0.2'
}
}
......
org.gradle.jvmargs=-Xmx1536M
android.enableJetifier=true
android.useAndroidX=true
android.enableR8=true
......@@ -3,4 +3,4 @@ distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-5.6.2-all.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-6.1.1-all.zip
import 'package:flutter/material.dart';
import 'dart:io';
import 'package:baseflow_plugin_template/baseflow_plugin_template.dart';
import 'package:flutter/material.dart';
import 'package:permission_handler/permission_handler.dart';
void main() {
......@@ -46,7 +47,10 @@ class _PermissionHandlerWidgetState extends State<PermissionHandlerWidget> {
permission != Permission.manageExternalStorage &&
permission != Permission.systemAlertWindow &&
permission != Permission.requestInstallPackages &&
permission != Permission.accessNotificationPolicy;
permission != Permission.accessNotificationPolicy &&
permission != Permission.bluetoothScan &&
permission != Permission.bluetoothAdvertise &&
permission != Permission.bluetoothConnect;
} else {
return permission != Permission.unknown &&
permission != Permission.mediaLibrary &&
......
......@@ -139,6 +139,9 @@ typedef NS_ENUM(int, PermissionGroup) {
PermissionGroupAppTrackingTransparency,
PermissionGroupCriticalAlerts,
PermissionGroupAccessNotificationPolicy,
PermissionGroupBluetoothScan,
PermissionGroupBluetoothAdvertise,
PermissionGroupBluetoothConnect,
};
typedef NS_ENUM(int, PermissionStatus) {
......
name: permission_handler
description: Permission plugin for Flutter. This plugin provides a cross-platform (iOS, Android) API to request and check permissions.
version: 8.1.6
version: 8.2.0
homepage: https://github.com/baseflowit/flutter-permission-handler
flutter:
......@@ -16,7 +16,8 @@ dependencies:
flutter:
sdk: flutter
meta: ^1.3.0
permission_handler_platform_interface: ^3.6.1
permission_handler_platform_interface:
path: ../permission_handler_platform_interface # FIXME: Publish new version and use it here
dev_dependencies:
flutter_test:
......
## 3.7.0
* Added support for the new Android 12 Bluetooth permissions: BLUETOOTH_SCAN, BLUETOOTH_ADVERTISE and BLUETOOTH_CONNECT.
## 3.6.2
* Updated the MethodChannelMock due to breaking changes in the platform channel test interface.
......
......@@ -162,6 +162,20 @@ class Permission {
///iOS: Nothing
static const accessNotificationPolicy = Permission._(27);
///Android: Allows the user to look for Bluetooth devices
///(e.g. BLE peripherals).
///iOS: Nothing
static const bluetoothScan = Permission._(28);
///Android: Allows the user to make this device discoverable to other
///Bluetooth devices.
///iOS: Nothing
static const bluetoothAdvertise = Permission._(29);
///Android: Allows the user to connect with already paired Bluetooth devices.
///iOS: Nothing
static const bluetoothConnect = Permission._(30);
/// Returns a list of all possible [PermissionGroup] values.
static const List<Permission> values = <Permission>[
calendar,
......@@ -192,6 +206,9 @@ class Permission {
appTrackingTransparency,
criticalAlerts,
accessNotificationPolicy,
bluetoothScan,
bluetoothAdvertise,
bluetoothConnect,
];
static const List<String> _names = <String>[
......@@ -223,6 +240,9 @@ class Permission {
'appTrackingTransparency',
'criticalAlerts',
'accessNotificationPolicy',
'bluetoothScan',
'bluetoothAdvertise',
'bluetoothConnect',
];
@override
......
......@@ -3,7 +3,7 @@ description: A common platform interface for the permission_handler plugin.
homepage: https://github.com/baseflow/flutter-permission-handler/tree/master/permission_handler_platform_interface
# NOTE: We strongly prefer non-breaking changes, even at the expense of a
# less-clean API. See https://flutter.dev/go/platform-interface-breaking-changes
version: 3.6.2
version: 3.7.0
dependencies:
flutter:
......
......@@ -6,7 +6,7 @@ void main() {
() {
const values = Permission.values;
expect(values.length, 28);
expect(values.length, 31);
});
test('check if byValue returns corresponding PermissionGroup value', () {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment