Added flag to enable GATT on non-extended device

PiperOrigin-RevId: 538851144
This commit is contained in:
Guogang Li
2023-06-08 11:56:24 -07:00
committed by Copybara-Service
parent 742f57423c
commit ae900f0baf
6 changed files with 52 additions and 8 deletions
@@ -114,8 +114,20 @@ bool BleGattClient::DiscoverServiceAndCharacteristics(
if (!NearbyFlags::GetInstance().GetBoolFlag(
platform::config_package_nearby::nearby_platform_feature::
kEnableBleV2Gatt)) {
NEARBY_LOGS(WARNING) << __func__ << ": GATT is disabled.";
return false;
auto windows_bluetooth_adapter_ = ::winrt::Windows::Devices::Bluetooth::
BluetoothAdapter::GetDefaultAsync()
.get();
if (windows_bluetooth_adapter_.IsExtendedAdvertisingSupported()) {
NEARBY_LOGS(WARNING) << __func__ << ": GATT is disabled.";
return false;
}
if (!NearbyFlags::GetInstance().GetBoolFlag(
platform::config_package_nearby::nearby_platform_feature::
kEnableBleV2GattOnNonExtendedDevice)) {
NEARBY_LOGS(WARNING) << __func__ << ": GATT is disabled.";
return false;
}
}
std::string flat_characteristics =
@@ -374,10 +374,18 @@ std::unique_ptr<api::ble_v2::GattServer> BleV2Medium::StartGattServer(
if (!NearbyFlags::GetInstance().GetBoolFlag(
platform::config_package_nearby::nearby_platform_feature::
kEnableBleV2Gatt)) {
NEARBY_LOGS(WARNING) << __func__ << ": GATT is disabled.";
return nullptr;
}
if (adapter_->IsExtendedAdvertisingSupported()) {
NEARBY_LOGS(WARNING) << __func__ << ": GATT is disabled.";
return nullptr;
}
if (!NearbyFlags::GetInstance().GetBoolFlag(
platform::config_package_nearby::nearby_platform_feature::
kEnableBleV2GattOnNonExtendedDevice)) {
NEARBY_LOGS(WARNING) << __func__ << ": GATT is disabled.";
return nullptr;
}
}
auto gatt_server =
std::make_unique<BleGattServer>(adapter_, std::move(callback));
@@ -396,8 +404,17 @@ std::unique_ptr<api::ble_v2::GattClient> BleV2Medium::ConnectToGattServer(
if (!NearbyFlags::GetInstance().GetBoolFlag(
platform::config_package_nearby::nearby_platform_feature::
kEnableBleV2Gatt)) {
NEARBY_LOGS(WARNING) << __func__ << ": GATT is disabled.";
return nullptr;
if (adapter_->IsExtendedAdvertisingSupported()) {
NEARBY_LOGS(WARNING) << __func__ << ": GATT is disabled.";
return nullptr;
}
if (!NearbyFlags::GetInstance().GetBoolFlag(
platform::config_package_nearby::nearby_platform_feature::
kEnableBleV2GattOnNonExtendedDevice)) {
NEARBY_LOGS(WARNING) << __func__ << ": GATT is disabled.";
return nullptr;
}
}
try {