Add requestConnectionPriority support (#221)
* feat: add requestConnectionPriority - Add BleConnectionPriority enum (balanced, highPerformance, lowPower) - Add BleCapabilities.supportsConnectionPriorityApi flag - Implement on Android via BluetoothGatt.requestConnectionPriority() - Throw notSupported on iOS, macOS, Windows, Linux, and Web - Update pigeon definition and regenerate platform channel files - Bump version 1.2.0 -> 1.3.0 * fix: improve requestConnectionPriority implementation - Remove redundant BleCapabilities guard in Dart layer (native handles it) - Add BleConnectionPriority Kotlin enum mirroring Dart enum - Map to explicit Android SDK constants via when expression - Add firstOrNull with ILLEGAL_ARGUMENT for unknown priority values - Add catch (e: Exception) block for broader error handling - Fix enum doc comment (throws belongs on method, not enum) - Remove stale capability check guidance from docs and README --------- Co-authored-by: aqeel-bmec-co <aqeel@bmec.co> Co-authored-by: aqeel-bmec-co <85945830+aqeel-bmec-co@users.noreply.github.com>
This commit is contained in:
@@ -1389,6 +1389,41 @@ void UniversalBlePlatformChannel::SetUp(
|
||||
channel.SetMessageHandler(nullptr);
|
||||
}
|
||||
}
|
||||
{
|
||||
BasicMessageChannel<> channel(binary_messenger, "dev.flutter.pigeon.universal_ble.UniversalBlePlatformChannel.requestConnectionPriority" + 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_device_id_arg = args.at(0);
|
||||
if (encodable_device_id_arg.IsNull()) {
|
||||
reply(WrapError("device_id_arg unexpectedly null."));
|
||||
return;
|
||||
}
|
||||
const auto& device_id_arg = std::get<std::string>(encodable_device_id_arg);
|
||||
const auto& encodable_priority_arg = args.at(1);
|
||||
if (encodable_priority_arg.IsNull()) {
|
||||
reply(WrapError("priority_arg unexpectedly null."));
|
||||
return;
|
||||
}
|
||||
const int64_t priority_arg = encodable_priority_arg.LongValue();
|
||||
api->RequestConnectionPriority(device_id_arg, priority_arg, [reply](std::optional<FlutterError>&& output) {
|
||||
if (output.has_value()) {
|
||||
reply(WrapError(output.value()));
|
||||
return;
|
||||
}
|
||||
EncodableList wrapped;
|
||||
wrapped.push_back(EncodableValue());
|
||||
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.setLogLevel" + prepended_suffix, &GetCodec());
|
||||
if (api != nullptr) {
|
||||
|
||||
@@ -528,6 +528,10 @@ class UniversalBlePlatformChannel {
|
||||
virtual void ReadRssi(
|
||||
const std::string& device_id,
|
||||
std::function<void(ErrorOr<int64_t> reply)> result) = 0;
|
||||
virtual void RequestConnectionPriority(
|
||||
const std::string& device_id,
|
||||
int64_t priority,
|
||||
std::function<void(std::optional<FlutterError> reply)> result) = 0;
|
||||
virtual std::optional<FlutterError> SetLogLevel(const UniversalBleLogLevel& log_level) = 0;
|
||||
|
||||
// The codec used by UniversalBlePlatformChannel.
|
||||
|
||||
@@ -436,6 +436,14 @@ void UniversalBlePlugin::RequestMtu(
|
||||
}
|
||||
}
|
||||
|
||||
void UniversalBlePlugin::RequestConnectionPriority(
|
||||
const std::string &device_id, int64_t priority,
|
||||
std::function<void(std::optional<FlutterError> reply)> result) {
|
||||
result(create_flutter_error(
|
||||
UniversalBleErrorCode::kNotSupported,
|
||||
"requestConnectionPriority is not supported on Windows platform"));
|
||||
}
|
||||
|
||||
void UniversalBlePlugin::ReadRssi(
|
||||
const std::string &device_id,
|
||||
std::function<void(ErrorOr<int64_t> reply)> result) {
|
||||
|
||||
@@ -207,6 +207,9 @@ private:
|
||||
std::function<void(std::optional<FlutterError> reply)> result) override;
|
||||
void RequestMtu(const std::string &device_id, int64_t expected_mtu,
|
||||
std::function<void(ErrorOr<int64_t> reply)> result) override;
|
||||
void RequestConnectionPriority(
|
||||
const std::string &device_id, int64_t priority,
|
||||
std::function<void(std::optional<FlutterError> reply)> result) override;
|
||||
void ReadRssi(const std::string &device_id,
|
||||
std::function<void(ErrorOr<int64_t> reply)> result) override;
|
||||
void IsPaired(const std::string &device_id,
|
||||
|
||||
Reference in New Issue
Block a user