diff --git a/fastpair/BUILD b/fastpair/BUILD index 1f0bca00..471eb496 100644 --- a/fastpair/BUILD +++ b/fastpair/BUILD @@ -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", diff --git a/fastpair/fast_pair_service.cc b/fastpair/fast_pair_service.cc index 01f58684..916e7ed2 100644 --- a/fastpair/fast_pair_service.cc +++ b/fastpair/fast_pair_service.cc @@ -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::ServiceCallbacks{ .on_initial_discovery = diff --git a/internal/platform/flags/BUILD b/internal/platform/flags/BUILD index 15f5cf6f..327cf1d6 100644 --- a/internal/platform/flags/BUILD +++ b/internal/platform/flags/BUILD @@ -19,6 +19,8 @@ cc_library( "nearby_platform_feature_flags.h", ], visibility = [ + "//connections:__subpackages__", + "//fastpair:__subpackages__", "//internal:__subpackages__", "//location/nearby/cpp:__subpackages__", ], diff --git a/internal/platform/flags/nearby_platform_feature_flags.h b/internal/platform/flags/nearby_platform_feature_flags.h index 6465404f..f2570cf2 100644 --- a/internal/platform/flags/nearby_platform_feature_flags.h +++ b/internal/platform/flags/nearby_platform_feature_flags.h @@ -37,7 +37,11 @@ constexpr auto kEnablePlatformThreadToNetwork = // Disable/Enable GATT feature in BLE V2. constexpr auto kEnableBleV2Gatt = - flags::Flag(kConfigPackage, "45415180", true); + flags::Flag(kConfigPackage, "45415180", false); + +// Disable/Enable GATT feature in BLE V2. +constexpr auto kEnableBleV2GattOnNonExtendedDevice = + flags::Flag(kConfigPackage, "45415267", false); } // namespace nearby_platform_feature } // namespace config_package_nearby diff --git a/internal/platform/implementation/windows/ble_gatt_client.cc b/internal/platform/implementation/windows/ble_gatt_client.cc index 505f56ca..41d56644 100644 --- a/internal/platform/implementation/windows/ble_gatt_client.cc +++ b/internal/platform/implementation/windows/ble_gatt_client.cc @@ -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 = diff --git a/internal/platform/implementation/windows/ble_v2.cc b/internal/platform/implementation/windows/ble_v2.cc index da8fc63d..ce1a08aa 100644 --- a/internal/platform/implementation/windows/ble_v2.cc +++ b/internal/platform/implementation/windows/ble_v2.cc @@ -374,10 +374,18 @@ std::unique_ptr 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(adapter_, std::move(callback)); @@ -396,8 +404,17 @@ std::unique_ptr 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 {