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:
Rohit Sangwan
2025-12-13 02:40:21 +05:30
committed by GitHub
parent 89abb3bf03
commit 97936046e0
23 changed files with 175 additions and 36 deletions
+28
View File
@@ -612,6 +612,34 @@ void UniversalBlePlatformChannel::SetUp(
channel.SetMessageHandler(nullptr);
}
}
{
BasicMessageChannel<> channel(binary_messenger, "dev.flutter.pigeon.universal_ble.UniversalBlePlatformChannel.hasPermissions" + prepended_suffix, &GetCodec());
if (api != nullptr) {
channel.SetMessageHandler([api](const EncodableValue& message, const flutter::MessageReply<EncodableValue>& reply) {
try {
const auto& args = std::get<EncodableList>(message);
const auto& encodable_with_android_fine_location_arg = args.at(0);
if (encodable_with_android_fine_location_arg.IsNull()) {
reply(WrapError("with_android_fine_location_arg unexpectedly null."));
return;
}
const auto& with_android_fine_location_arg = std::get<bool>(encodable_with_android_fine_location_arg);
ErrorOr<bool> output = api->HasPermissions(with_android_fine_location_arg);
if (output.has_error()) {
reply(WrapError(output.error()));
return;
}
EncodableList wrapped;
wrapped.push_back(EncodableValue(std::move(output).TakeValue()));
reply(EncodableValue(std::move(wrapped)));
} catch (const std::exception& exception) {
reply(WrapError(exception.what()));
}
});
} else {
channel.SetMessageHandler(nullptr);
}
}
{
BasicMessageChannel<> channel(binary_messenger, "dev.flutter.pigeon.universal_ble.UniversalBlePlatformChannel.requestPermissions" + prepended_suffix, &GetCodec());
if (api != nullptr) {
+1
View File
@@ -387,6 +387,7 @@ class UniversalBlePlatformChannel {
UniversalBlePlatformChannel& operator=(const UniversalBlePlatformChannel&) = delete;
virtual ~UniversalBlePlatformChannel() {}
virtual void GetBluetoothAvailabilityState(std::function<void(ErrorOr<int64_t> reply)> result) = 0;
virtual ErrorOr<bool> HasPermissions(bool with_android_fine_location) = 0;
virtual void RequestPermissions(
bool with_android_fine_location,
std::function<void(std::optional<FlutterError> reply)> result) = 0;
+5
View File
@@ -119,6 +119,11 @@ void UniversalBlePlugin::DisableBluetooth(
});
}
ErrorOr<bool> UniversalBlePlugin::HasPermissions(bool with_android_fine_location) {
// Windows does not require runtime permissions for Bluetooth
return true;
}
void UniversalBlePlugin::RequestPermissions(
bool with_android_fine_location,
std::function<void(std::optional<FlutterError> reply)> result) {
+1
View File
@@ -177,6 +177,7 @@ private:
ErrorOr<bool> IsScanning() override;
std::optional<FlutterError> Connect(const std::string &device_id) override;
std::optional<FlutterError> Disconnect(const std::string &device_id) override;
ErrorOr<bool> HasPermissions(bool with_android_fine_location) override;
void RequestPermissions(
bool with_android_fine_location,
std::function<void(std::optional<FlutterError> reply)> result) override;