Deprecate DisableBluetoothClassicScanning flag.

PiperOrigin-RevId: 856914065
This commit is contained in:
Francis Tsui
2026-01-15 19:04:35 -08:00
committed by Copybara-Service
parent e2714e1685
commit 2cda47c30c
6 changed files with 25 additions and 127 deletions
@@ -31,9 +31,6 @@ namespace nearby_connections_feature {
// The timeout in millis to report peripheral device lost. // The timeout in millis to report peripheral device lost.
constexpr auto kBlePeripheralLostTimeoutMillis = constexpr auto kBlePeripheralLostTimeoutMillis =
flags::Flag<int64_t>(kConfigPackage, "45411439", 12000); flags::Flag<int64_t>(kConfigPackage, "45411439", 12000);
// When true, disable Bluetooth classic scanning.
constexpr auto kDisableBluetoothClassicScanning =
flags::Flag<bool>(kConfigPackage, "45639961", false);
// Disable instant on lost on BLE without extended feature. // Disable instant on lost on BLE without extended feature.
constexpr auto kDisableInstantOnLostOnBleWithoutExtended = constexpr auto kDisableInstantOnLostOnBleWithoutExtended =
flags::Flag<bool>(kConfigPackage, "45687098", true); flags::Flag<bool>(kConfigPackage, "45687098", true);
@@ -754,14 +754,10 @@ void DiscoveredPeripheralTracker::HandleAdvertisementHeader(
// Report a nearby legacy device is found when advertisement header doesn't // Report a nearby legacy device is found when advertisement header doesn't
// support extended advertisement. // support extended advertisement.
if (NearbyFlags::GetInstance().GetBoolFlag( if (!advertisement_header.IsSupportExtendedAdvertisement()) {
config_package_nearby::nearby_connections_feature:: for (auto& item : service_id_infos_) {
kDisableBluetoothClassicScanning)) { item.second.discovered_peripheral_callback
if (!advertisement_header.IsSupportExtendedAdvertisement()) { .legacy_device_discovered_cb();
for (auto& item : service_id_infos_) {
item.second.discovered_peripheral_callback
.legacy_device_discovered_cb();
}
} }
} }
@@ -191,10 +191,6 @@ class DiscoveredPeripheralTrackerTest
std::tuple</*kEnableReadGattForExtendedAdvertisement=*/bool>> { std::tuple</*kEnableReadGattForExtendedAdvertisement=*/bool>> {
public: public:
void SetUp() override { void SetUp() override {
NearbyFlags::GetInstance().OverrideBoolFlagValue(
config_package_nearby::nearby_connections_feature::
kDisableBluetoothClassicScanning,
false);
NearbyFlags::GetInstance().OverrideBoolFlagValue( NearbyFlags::GetInstance().OverrideBoolFlagValue(
config_package_nearby::nearby_connections_feature::kEnableInstantOnLost, config_package_nearby::nearby_connections_feature::kEnableInstantOnLost,
false); false);
@@ -285,13 +281,6 @@ class DiscoveredPeripheralTrackerTest
return fetch_count_; return fetch_count_;
} }
void DisableBluetoothScanning() {
NearbyFlags::GetInstance().OverrideBoolFlagValue(
config_package_nearby::nearby_connections_feature::
kDisableBluetoothClassicScanning,
true);
}
void EnableInstantOnLost() { void EnableInstantOnLost() {
NearbyFlags::GetInstance().OverrideBoolFlagValue( NearbyFlags::GetInstance().OverrideBoolFlagValue(
config_package_nearby::nearby_connections_feature::kEnableInstantOnLost, config_package_nearby::nearby_connections_feature::kEnableInstantOnLost,
@@ -423,7 +412,6 @@ TEST_P(DiscoveredPeripheralTrackerTest, DctAdvertisementPeripheralDiscovered) {
TEST_P(DiscoveredPeripheralTrackerTest, TEST_P(DiscoveredPeripheralTrackerTest,
ReportFoundLegacyDeviceWhenFoundBleAdvertisementPeripheralDiscovered) { ReportFoundLegacyDeviceWhenFoundBleAdvertisementPeripheralDiscovered) {
DisableBluetoothScanning();
std::vector<std::string> service_ids = {std::string(kServiceIdA)}; std::vector<std::string> service_ids = {std::string(kServiceIdA)};
ByteArray advertisement_header_bytes = CreateBleAdvertisementHeader( ByteArray advertisement_header_bytes = CreateBleAdvertisementHeader(
GenerateRandomAdvertisementHash(), service_ids); GenerateRandomAdvertisementHash(), service_ids);
@@ -789,12 +789,6 @@ void P2pClusterPcpHandler::BleInstantLostHandler(
} }
void P2pClusterPcpHandler::BleLegacyDeviceDiscoveredHandler() { void P2pClusterPcpHandler::BleLegacyDeviceDiscoveredHandler() {
if (!NearbyFlags::GetInstance().GetBoolFlag(
config_package_nearby::nearby_connections_feature::
kDisableBluetoothClassicScanning)) {
return;
}
RunOnPcpHandlerThread( RunOnPcpHandlerThread(
"p2p-ble-legacy-peripheral-discovered", "p2p-ble-legacy-peripheral-discovered",
[this]() RUN_ON_PCP_HANDLER_THREAD() { [this]() RUN_ON_PCP_HANDLER_THREAD() {
@@ -1119,31 +1113,9 @@ BasePcpHandler::StartOperationResult P2pClusterPcpHandler::StartDiscoveryImpl(
} }
if (discovery_options.allowed.bluetooth) { if (discovery_options.allowed.bluetooth) {
if (NearbyFlags::GetInstance().GetBoolFlag( StartBluetoothDiscoveryWithPause(
config_package_nearby::nearby_connections_feature:: client, service_id, discovery_options, mediums_started_successfully,
kDisableBluetoothClassicScanning)) { operation_result_with_mediums, /*update_index=*/0);
StartBluetoothDiscoveryWithPause(
client, service_id, discovery_options, mediums_started_successfully,
operation_result_with_mediums, /*update_index=*/0);
} else {
ErrorOr<Medium> bluetooth_result =
StartBluetoothDiscovery(client, service_id);
if (bluetooth_result.has_value()) {
LOG(INFO) << "P2pClusterPcpHandler::StartDiscoveryImpl: BT added";
mediums_started_successfully.push_back(*bluetooth_result);
bluetooth_classic_client_id_to_service_id_map_.insert(
{client->GetClientId(), service_id});
}
std::unique_ptr<ConnectionsLog::OperationResultWithMedium>
operation_result_with_medium =
GetOperationResultWithMediumByResultCode(
client, BLUETOOTH,
/*update_index=*/0,
bluetooth_result.has_error()
? bluetooth_result.error().operation_result_code().value()
: OperationResultCode::DETAIL_SUCCESS);
operation_result_with_mediums.push_back(*operation_result_with_medium);
}
} }
if (mediums_started_successfully.empty()) { if (mediums_started_successfully.empty()) {
@@ -1186,13 +1158,8 @@ Status P2pClusterPcpHandler::StopDiscoveryImpl(ClientProxy* client) {
ble_medium_.StopScanning(client->GetDiscoveryServiceId()); ble_medium_.StopScanning(client->GetDiscoveryServiceId());
if (NearbyFlags::GetInstance().GetBoolFlag( paused_bluetooth_clients_discoveries_.erase(
config_package_nearby::nearby_connections_feature:: client->GetDiscoveryServiceId());
kDisableBluetoothClassicScanning)) {
paused_bluetooth_clients_discoveries_.erase(
client->GetDiscoveryServiceId());
}
return {Status::kSuccess}; return {Status::kSuccess};
} }
@@ -1742,32 +1709,9 @@ P2pClusterPcpHandler::UpdateDiscoveryOptionsImpl(
OperationResultCode::DETAIL_SUCCESS); OperationResultCode::DETAIL_SUCCESS);
operation_result_with_mediums.push_back(*operation_result_with_medium); operation_result_with_mediums.push_back(*operation_result_with_medium);
} else { } else {
if (NearbyFlags::GetInstance().GetBoolFlag( StartBluetoothDiscoveryWithPause(
config_package_nearby::nearby_connections_feature:: client, std::string(service_id), discovery_options, restarted_mediums,
kDisableBluetoothClassicScanning)) { operation_result_with_mediums, update_index);
StartBluetoothDiscoveryWithPause(
client, std::string(service_id), discovery_options,
restarted_mediums, operation_result_with_mediums, update_index);
} else {
ErrorOr<Medium> bluetooth_result =
StartBluetoothDiscovery(client, std::string(service_id));
if (bluetooth_result.has_value()) {
restarted_mediums.push_back(BLUETOOTH);
} else {
LOG(WARNING)
<< "UpdateDiscoveryOptionsImpl: unable to restart bt scanning";
}
std::unique_ptr<ConnectionsLog::OperationResultWithMedium>
operation_result_with_medium =
GetOperationResultWithMediumByResultCode(
client, BLUETOOTH, update_index,
bluetooth_result.has_error()
? bluetooth_result.error()
.operation_result_code()
.value()
: OperationResultCode::DETAIL_SUCCESS);
operation_result_with_mediums.push_back(*operation_result_with_medium);
}
} }
} }
// awdl (note: keep the awdl logic before the wifi lan logic) // awdl (note: keep the awdl logic before the wifi lan logic)
@@ -16,7 +16,6 @@
#include <cstdint> #include <cstdint>
#include <string> #include <string>
#include <tuple>
#include "gtest/gtest.h" #include "gtest/gtest.h"
#include "absl/time/clock.h" #include "absl/time/clock.h"
@@ -90,20 +89,12 @@ class P2pClusterPcpHandlerTest : public testing::Test {
NearbyFlags::GetInstance().OverrideBoolFlagValue( NearbyFlags::GetInstance().OverrideBoolFlagValue(
config_package_nearby::nearby_connections_feature::kEnableAwdl, true); config_package_nearby::nearby_connections_feature::kEnableAwdl, true);
SetBleExtendedAdvertisementsAvailable(true); SetBleExtendedAdvertisementsAvailable(true);
SetDisableBluetoothClassicScanning(true);
} }
void SetBleExtendedAdvertisementsAvailable(bool available) { void SetBleExtendedAdvertisementsAvailable(bool available) {
env_.SetBleExtendedAdvertisementsAvailable(false); env_.SetBleExtendedAdvertisementsAvailable(false);
} }
void SetDisableBluetoothClassicScanning(bool disable) {
NearbyFlags::GetInstance().OverrideBoolFlagValue(
config_package_nearby::nearby_connections_feature::
kDisableBluetoothClassicScanning,
disable);
}
AdvertisingOptions GetBluetoothOnlyAdvertisingOptions() { AdvertisingOptions GetBluetoothOnlyAdvertisingOptions() {
return AdvertisingOptions{ return AdvertisingOptions{
{Strategy::kP2pCluster, {Strategy::kP2pCluster,
@@ -240,20 +231,13 @@ TEST_F(P2pClusterPcpHandlerTest,
} }
class P2pClusterPcpHandlerTestWithParam class P2pClusterPcpHandlerTestWithParam
: public testing::TestWithParam< : public testing::TestWithParam</*mediums=*/BooleanMediumSelector> {
/*mediums=*/std::tuple<BooleanMediumSelector,
/*disable_bluetooth_scanning*/ bool>> {
protected: protected:
void SetUp() override { void SetUp() override {
LOG(INFO) << "SetUp: begin"; LOG(INFO) << "SetUp: begin";
env_.SetBleExtendedAdvertisementsAvailable(false); env_.SetBleExtendedAdvertisementsAvailable(false);
NearbyFlags::GetInstance().OverrideBoolFlagValue( NearbyFlags::GetInstance().OverrideBoolFlagValue(
config_package_nearby::nearby_connections_feature::kEnableAwdl, true); config_package_nearby::nearby_connections_feature::kEnableAwdl, true);
bool is_disable_bluetooth_scanning = std::get<1>(GetParam());
NearbyFlags::GetInstance().OverrideBoolFlagValue(
config_package_nearby::nearby_connections_feature::
kDisableBluetoothClassicScanning,
is_disable_bluetooth_scanning);
NearbyFlags::GetInstance().OverrideBoolFlagValue( NearbyFlags::GetInstance().OverrideBoolFlagValue(
config_package_nearby::nearby_connections_feature::kEnableDct, true); config_package_nearby::nearby_connections_feature::kEnableDct, true);
NearbyFlags::GetInstance().OverrideBoolFlagValue( NearbyFlags::GetInstance().OverrideBoolFlagValue(
@@ -277,8 +261,6 @@ class P2pClusterPcpHandlerTestWithParam
if (advertising_options_.allowed.awdl) { if (advertising_options_.allowed.awdl) {
LOG(INFO) << "SetUp: Awdl enabled"; LOG(INFO) << "SetUp: Awdl enabled";
} }
LOG(INFO) << "SetUp: is_disable_bluetooth_scanning: "
<< is_disable_bluetooth_scanning;
LOG(INFO) << "SetUp: end"; LOG(INFO) << "SetUp: end";
} }
@@ -288,19 +270,19 @@ class P2pClusterPcpHandlerTestWithParam
ConnectionOptions connection_options_{ ConnectionOptions connection_options_{
{ {
Strategy::kP2pCluster, Strategy::kP2pCluster,
std::get<0>(GetParam()), GetParam(),
}, },
}; };
AdvertisingOptions advertising_options_{ AdvertisingOptions advertising_options_{
{ {
Strategy::kP2pCluster, Strategy::kP2pCluster,
std::get<0>(GetParam()), GetParam(),
}, },
}; };
DiscoveryOptions discovery_options_{ DiscoveryOptions discovery_options_{
{ {
Strategy::kP2pCluster, Strategy::kP2pCluster,
std::get<0>(GetParam()), GetParam(),
}, },
}; };
MediumEnvironment& env_{MediumEnvironment::Instance()}; MediumEnvironment& env_{MediumEnvironment::Instance()};
@@ -385,11 +367,11 @@ TEST_P(P2pClusterPcpHandlerTestWithParam, AdvertiseForLegacyDeviceWithBt) {
{.endpoint_info = ByteArray{endpoint_name}}), {.endpoint_info = ByteArray{endpoint_name}}),
Status{Status::kSuccess}); Status{Status::kSuccess});
// advertising for legacy device depends on both BT and BLE enabled. // advertising for legacy device depends on both BT and BLE enabled.
if (std::get<0>(GetParam()).bluetooth) { if (GetParam().bluetooth) {
EXPECT_TRUE(mediums_a.GetBle().IsAdvertisingForLegacyDevice(service_id_)); EXPECT_TRUE(mediums_a.GetBle().IsAdvertisingForLegacyDevice(service_id_));
} }
handler_a.StopAdvertising(&client_a_); handler_a.StopAdvertising(&client_a_);
if (std::get<0>(GetParam()).bluetooth) { if (GetParam().bluetooth) {
EXPECT_FALSE(mediums_a.GetBle().IsAdvertisingForLegacyDevice(service_id_)); EXPECT_FALSE(mediums_a.GetBle().IsAdvertisingForLegacyDevice(service_id_));
} }
env_.Stop(); env_.Stop();
@@ -619,7 +601,7 @@ TEST_P(P2pClusterPcpHandlerTestWithParam, CanDiscoverLegacy) {
TEST_P(P2pClusterPcpHandlerTestWithParam, PauseBluetoothClassicDiscovery) { TEST_P(P2pClusterPcpHandlerTestWithParam, PauseBluetoothClassicDiscovery) {
// Skip the case which not disable bluetooth scanning. // Skip the case which not disable bluetooth scanning.
if (!std::get<1>(GetParam()) || !advertising_options_.allowed.bluetooth || if (!advertising_options_.allowed.bluetooth ||
!advertising_options_.allowed.ble) { !advertising_options_.allowed.ble) {
return; return;
} }
@@ -648,7 +630,7 @@ TEST_P(P2pClusterPcpHandlerTestWithParam, PauseBluetoothClassicDiscovery) {
TEST_P(P2pClusterPcpHandlerTestWithParam, ResumeBluetoothClassicDiscovery) { TEST_P(P2pClusterPcpHandlerTestWithParam, ResumeBluetoothClassicDiscovery) {
// Skip the case which not disable bluetooth scanning. // Skip the case which not disable bluetooth scanning.
if (!std::get<1>(GetParam()) || !advertising_options_.allowed.bluetooth || if (!advertising_options_.allowed.bluetooth ||
!advertising_options_.allowed.ble) { !advertising_options_.allowed.ble) {
return; return;
} }
@@ -802,14 +784,14 @@ TEST_P(P2pClusterPcpHandlerTestWithParam, CanUpdateDiscoveryOptions) {
EXPECT_EQ( EXPECT_EQ(
handler_a.StartDiscovery(&client_a_, service_id_, discovery_options_, {}), handler_a.StartDiscovery(&client_a_, service_id_, discovery_options_, {}),
Status{Status::kSuccess}); Status{Status::kSuccess});
BooleanMediumSelector enabled = std::get<0>(GetParam()); BooleanMediumSelector enabled = GetParam();
EXPECT_EQ(enabled.ble, mediums_a.GetBle().IsScanning(service_id_)); EXPECT_EQ(enabled.ble, mediums_a.GetBle().IsScanning(service_id_));
EXPECT_EQ(enabled.wifi_lan, EXPECT_EQ(enabled.wifi_lan,
mediums_a.GetWifiLan().IsDiscovering(service_id_)); mediums_a.GetWifiLan().IsDiscovering(service_id_));
DiscoveryOptions new_options{ DiscoveryOptions new_options{
{ {
Strategy::kP2pCluster, Strategy::kP2pCluster,
std::get<0>(GetParam()), GetParam(),
}, },
false, // auto_upgrade_bandwidth false, // auto_upgrade_bandwidth
false, // enforce_topology_constraints false, // enforce_topology_constraints
@@ -1664,10 +1646,6 @@ class P2pLostHandlerTestWithParam : public testing::TestWithParam<bool> {
NearbyFlags::GetInstance().OverrideBoolFlagValue( NearbyFlags::GetInstance().OverrideBoolFlagValue(
config_package_nearby::nearby_connections_feature::kEnableAwdl, true); config_package_nearby::nearby_connections_feature::kEnableAwdl, true);
env_.SetBleExtendedAdvertisementsAvailable(true); env_.SetBleExtendedAdvertisementsAvailable(true);
NearbyFlags::GetInstance().OverrideBoolFlagValue(
config_package_nearby::nearby_connections_feature::
kDisableBluetoothClassicScanning,
false);
NearbyFlags::GetInstance().OverrideBoolFlagValue( NearbyFlags::GetInstance().OverrideBoolFlagValue(
config_package_nearby::nearby_connections_feature::kEnableInstantOnLost, config_package_nearby::nearby_connections_feature::kEnableInstantOnLost,
GetParam()); GetParam());
@@ -1808,10 +1786,9 @@ TEST_P(P2pLostHandlerTestWithParam, CanConnectWithInstantLostEnabled) {
env_.SetBleExtendedAdvertisementsAvailable(false); env_.SetBleExtendedAdvertisementsAvailable(false);
} }
INSTANTIATE_TEST_SUITE_P( INSTANTIATE_TEST_SUITE_P(ParametrisedPcpHandlerTest,
ParametrisedPcpHandlerTest, P2pClusterPcpHandlerTestWithParam, P2pClusterPcpHandlerTestWithParam,
::testing::Combine(/*mediums=*/::testing::ValuesIn(kTestCases), ::testing::ValuesIn(kTestCases));
/*disable_bluetooth_scanning=*/::testing::Bool()));
INSTANTIATE_TEST_SUITE_P(ParametrisedP2pLostHandlerTest, INSTANTIATE_TEST_SUITE_P(ParametrisedP2pLostHandlerTest,
P2pLostHandlerTestWithParam, testing::Bool()); P2pLostHandlerTestWithParam, testing::Bool());
@@ -61,9 +61,6 @@ constexpr auto kLoggingLevel =
// Enable/disable auto-update on settings page // Enable/disable auto-update on settings page
constexpr auto kShowAutoUpdateSetting = constexpr auto kShowAutoUpdateSetting =
flags::Flag<bool>(kConfigPackage, "45409033", false); flags::Flag<bool>(kConfigPackage, "45409033", false);
// When true, use gRpc client to access backend.
constexpr auto kUseGrpcClient =
flags::Flag<bool>(kConfigPackage, "45630055", false);
// When true, delete the file payload which received unexpectedly. // When true, delete the file payload which received unexpectedly.
constexpr auto kDeleteUnexpectedReceivedFileFix = constexpr auto kDeleteUnexpectedReceivedFileFix =
flags::Flag<bool>(kConfigPackage, "45657036", false); flags::Flag<bool>(kConfigPackage, "45657036", false);
@@ -115,7 +112,6 @@ inline absl::btree_map<int, const flags::Flag<bool>&> GetBoolFlags() {
{45418908, kEnableSelfShareUi}, {45418908, kEnableSelfShareUi},
{45459748, kEnableSendingDesktopEvents}, {45459748, kEnableSendingDesktopEvents},
{45409033, kShowAutoUpdateSetting}, {45409033, kShowAutoUpdateSetting},
{45630055, kUseGrpcClient},
{45657036, kDeleteUnexpectedReceivedFileFix}, {45657036, kDeleteUnexpectedReceivedFileFix},
{45673628, kEnableWifiHotspotForHpRealtekDevices}, {45673628, kEnableWifiHotspotForHpRealtekDevices},
{45683539, kUseAlternateServiceUuidForDiscovery}, {45683539, kUseAlternateServiceUuidForDiscovery},