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
+2
View File
@@ -96,7 +96,9 @@ cc_library(
":fast_pair_seeker",
"//fastpair/internal",
"//fastpair/repository:device_repository",
"//internal/flags:nearby_flags",
"//internal/platform:types",
"//internal/platform/flags:platform_flags",
"@com_google_absl//absl/container:flat_hash_map",
"@com_google_absl//absl/status",
"@com_google_absl//absl/strings",
+7
View File
@@ -23,6 +23,8 @@
#include "absl/strings/str_format.h"
#include "fastpair/fast_pair_plugin.h"
#include "fastpair/internal/fast_pair_seeker_impl.h"
#include "internal/flags/nearby_flags.h"
#include "internal/platform/flags/nearby_platform_feature_flags.h"
#include "internal/platform/logging.h"
namespace nearby {
@@ -33,6 +35,11 @@ constexpr absl::Duration kTimeout = absl::Seconds(3);
}
FastPairService::FastPairService() {
NearbyFlags::GetInstance().OverrideBoolFlagValue(
platform::config_package_nearby::nearby_platform_feature::
kEnableBleV2Gatt,
true);
seeker_ = std::make_unique<FastPairSeekerImpl>(
FastPairSeekerImpl::ServiceCallbacks{
.on_initial_discovery =
+2
View File
@@ -19,6 +19,8 @@ cc_library(
"nearby_platform_feature_flags.h",
],
visibility = [
"//connections:__subpackages__",
"//fastpair:__subpackages__",
"//internal:__subpackages__",
"//location/nearby/cpp:__subpackages__",
],
@@ -37,7 +37,11 @@ constexpr auto kEnablePlatformThreadToNetwork =
// Disable/Enable GATT feature in BLE V2.
constexpr auto kEnableBleV2Gatt =
flags::Flag<bool>(kConfigPackage, "45415180", true);
flags::Flag<bool>(kConfigPackage, "45415180", false);
// Disable/Enable GATT feature in BLE V2.
constexpr auto kEnableBleV2GattOnNonExtendedDevice =
flags::Flag<bool>(kConfigPackage, "45415267", false);
} // namespace nearby_platform_feature
} // namespace config_package_nearby
@@ -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 {