Implement hasPermissions API (#201)
* Implement hasPermissions api * Bump minimum MacOS version to 10.15 * Apply suggestions from code review Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> --------- Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
This commit is contained in:
@@ -71,6 +71,18 @@ class UniversalBle {
|
||||
);
|
||||
}
|
||||
|
||||
/// Check if has permissions.
|
||||
/// [withAndroidFineLocation] is used to check fine location permission on Android 12+ (API 31+).
|
||||
/// On Android lower than 12, this method will check location permission regardless of the [withAndroidFineLocation] value.
|
||||
/// `Windows`, `Linux` and `Web` will always return true.
|
||||
static Future<bool> hasPermissions({
|
||||
bool withAndroidFineLocation = false,
|
||||
}) async {
|
||||
return _platform.hasPermissions(
|
||||
withAndroidFineLocation: withAndroidFineLocation,
|
||||
);
|
||||
}
|
||||
|
||||
/// Request permissions.
|
||||
/// if all permissions are already granted or granted by user, this method will succeed.
|
||||
/// it will throw exception if permissions are denied by user.
|
||||
|
||||
@@ -431,12 +431,6 @@ class UniversalBleLinux extends UniversalBlePlatform {
|
||||
.toList();
|
||||
}
|
||||
|
||||
@override
|
||||
Future<void> requestPermissions(
|
||||
{bool withAndroidFineLocation = false}) async {
|
||||
// No permissions to request on linux
|
||||
}
|
||||
|
||||
AvailabilityState get _availabilityState {
|
||||
return _activeAdapter?.powered == true
|
||||
? AvailabilityState.poweredOn
|
||||
|
||||
@@ -592,6 +592,35 @@ class UniversalBlePlatformChannel {
|
||||
}
|
||||
}
|
||||
|
||||
Future<bool> hasPermissions(bool withAndroidFineLocation) async {
|
||||
final pigeonVar_channelName =
|
||||
'dev.flutter.pigeon.universal_ble.UniversalBlePlatformChannel.hasPermissions$pigeonVar_messageChannelSuffix';
|
||||
final pigeonVar_channel = BasicMessageChannel<Object?>(
|
||||
pigeonVar_channelName,
|
||||
pigeonChannelCodec,
|
||||
binaryMessenger: pigeonVar_binaryMessenger,
|
||||
);
|
||||
final Future<Object?> pigeonVar_sendFuture =
|
||||
pigeonVar_channel.send(<Object?>[withAndroidFineLocation]);
|
||||
final pigeonVar_replyList = await pigeonVar_sendFuture as List<Object?>?;
|
||||
if (pigeonVar_replyList == null) {
|
||||
throw _createConnectionError(pigeonVar_channelName);
|
||||
} else if (pigeonVar_replyList.length > 1) {
|
||||
throw PlatformException(
|
||||
code: pigeonVar_replyList[0]! as String,
|
||||
message: pigeonVar_replyList[1] as String?,
|
||||
details: pigeonVar_replyList[2],
|
||||
);
|
||||
} else if (pigeonVar_replyList[0] == null) {
|
||||
throw PlatformException(
|
||||
code: 'null-error',
|
||||
message: 'Host platform returned null value for non-null return value.',
|
||||
);
|
||||
} else {
|
||||
return (pigeonVar_replyList[0] as bool?)!;
|
||||
}
|
||||
}
|
||||
|
||||
Future<void> requestPermissions(bool withAndroidFineLocation) async {
|
||||
final pigeonVar_channelName =
|
||||
'dev.flutter.pigeon.universal_ble.UniversalBlePlatformChannel.requestPermissions$pigeonVar_messageChannelSuffix';
|
||||
|
||||
@@ -145,6 +145,13 @@ class UniversalBlePigeonChannel extends UniversalBlePlatform {
|
||||
Future<void> unpair(String deviceId) =>
|
||||
_executeWithErrorHandling(() => _channel.unPair(deviceId));
|
||||
|
||||
@override
|
||||
Future<bool> hasPermissions({bool withAndroidFineLocation = false}) async {
|
||||
return await _executeWithErrorHandling(
|
||||
() => _channel.hasPermissions(withAndroidFineLocation),
|
||||
);
|
||||
}
|
||||
|
||||
@override
|
||||
Future<void> requestPermissions(
|
||||
{bool withAndroidFineLocation = false}) async {
|
||||
|
||||
@@ -37,7 +37,12 @@ abstract class UniversalBlePlatform {
|
||||
|
||||
Future<bool> disableBluetooth();
|
||||
|
||||
Future<void> requestPermissions({bool withAndroidFineLocation = false});
|
||||
Future<bool> hasPermissions({bool withAndroidFineLocation = false}) async {
|
||||
return true;
|
||||
}
|
||||
|
||||
Future<void> requestPermissions(
|
||||
{bool withAndroidFineLocation = false}) async {}
|
||||
|
||||
Future<void> startScan({
|
||||
ScanFilter? scanFilter,
|
||||
|
||||
@@ -275,12 +275,6 @@ class UniversalBleWeb extends UniversalBlePlatform {
|
||||
}
|
||||
|
||||
/// `Unimplemented`
|
||||
@override
|
||||
Future<void> requestPermissions(
|
||||
{bool withAndroidFineLocation = false}) async {
|
||||
// No permissions to request on Web
|
||||
}
|
||||
|
||||
@override
|
||||
Future<int> requestMtu(String deviceId, int expectedMtu) {
|
||||
throw UniversalBleException(
|
||||
|
||||
Reference in New Issue
Block a user