mirror of
https://github.com/kidfromjupiter/nearby.git
synced 2026-09-14 14:46:12 -04:00
Deprecate DisableBluetoothClassicScanning flag.
PiperOrigin-RevId: 856914065
This commit is contained in:
committed by
Copybara-Service
parent
e2714e1685
commit
2cda47c30c
@@ -31,9 +31,6 @@ namespace nearby_connections_feature {
|
||||
// The timeout in millis to report peripheral device lost.
|
||||
constexpr auto kBlePeripheralLostTimeoutMillis =
|
||||
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.
|
||||
constexpr auto kDisableInstantOnLostOnBleWithoutExtended =
|
||||
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
|
||||
// support extended advertisement.
|
||||
if (NearbyFlags::GetInstance().GetBoolFlag(
|
||||
config_package_nearby::nearby_connections_feature::
|
||||
kDisableBluetoothClassicScanning)) {
|
||||
if (!advertisement_header.IsSupportExtendedAdvertisement()) {
|
||||
for (auto& item : service_id_infos_) {
|
||||
item.second.discovered_peripheral_callback
|
||||
.legacy_device_discovered_cb();
|
||||
}
|
||||
if (!advertisement_header.IsSupportExtendedAdvertisement()) {
|
||||
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>> {
|
||||
public:
|
||||
void SetUp() override {
|
||||
NearbyFlags::GetInstance().OverrideBoolFlagValue(
|
||||
config_package_nearby::nearby_connections_feature::
|
||||
kDisableBluetoothClassicScanning,
|
||||
false);
|
||||
NearbyFlags::GetInstance().OverrideBoolFlagValue(
|
||||
config_package_nearby::nearby_connections_feature::kEnableInstantOnLost,
|
||||
false);
|
||||
@@ -285,13 +281,6 @@ class DiscoveredPeripheralTrackerTest
|
||||
return fetch_count_;
|
||||
}
|
||||
|
||||
void DisableBluetoothScanning() {
|
||||
NearbyFlags::GetInstance().OverrideBoolFlagValue(
|
||||
config_package_nearby::nearby_connections_feature::
|
||||
kDisableBluetoothClassicScanning,
|
||||
true);
|
||||
}
|
||||
|
||||
void EnableInstantOnLost() {
|
||||
NearbyFlags::GetInstance().OverrideBoolFlagValue(
|
||||
config_package_nearby::nearby_connections_feature::kEnableInstantOnLost,
|
||||
@@ -423,7 +412,6 @@ TEST_P(DiscoveredPeripheralTrackerTest, DctAdvertisementPeripheralDiscovered) {
|
||||
|
||||
TEST_P(DiscoveredPeripheralTrackerTest,
|
||||
ReportFoundLegacyDeviceWhenFoundBleAdvertisementPeripheralDiscovered) {
|
||||
DisableBluetoothScanning();
|
||||
std::vector<std::string> service_ids = {std::string(kServiceIdA)};
|
||||
ByteArray advertisement_header_bytes = CreateBleAdvertisementHeader(
|
||||
GenerateRandomAdvertisementHash(), service_ids);
|
||||
|
||||
@@ -789,12 +789,6 @@ void P2pClusterPcpHandler::BleInstantLostHandler(
|
||||
}
|
||||
|
||||
void P2pClusterPcpHandler::BleLegacyDeviceDiscoveredHandler() {
|
||||
if (!NearbyFlags::GetInstance().GetBoolFlag(
|
||||
config_package_nearby::nearby_connections_feature::
|
||||
kDisableBluetoothClassicScanning)) {
|
||||
return;
|
||||
}
|
||||
|
||||
RunOnPcpHandlerThread(
|
||||
"p2p-ble-legacy-peripheral-discovered",
|
||||
[this]() RUN_ON_PCP_HANDLER_THREAD() {
|
||||
@@ -1119,31 +1113,9 @@ BasePcpHandler::StartOperationResult P2pClusterPcpHandler::StartDiscoveryImpl(
|
||||
}
|
||||
|
||||
if (discovery_options.allowed.bluetooth) {
|
||||
if (NearbyFlags::GetInstance().GetBoolFlag(
|
||||
config_package_nearby::nearby_connections_feature::
|
||||
kDisableBluetoothClassicScanning)) {
|
||||
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);
|
||||
}
|
||||
StartBluetoothDiscoveryWithPause(
|
||||
client, service_id, discovery_options, mediums_started_successfully,
|
||||
operation_result_with_mediums, /*update_index=*/0);
|
||||
}
|
||||
|
||||
if (mediums_started_successfully.empty()) {
|
||||
@@ -1186,13 +1158,8 @@ Status P2pClusterPcpHandler::StopDiscoveryImpl(ClientProxy* client) {
|
||||
|
||||
ble_medium_.StopScanning(client->GetDiscoveryServiceId());
|
||||
|
||||
if (NearbyFlags::GetInstance().GetBoolFlag(
|
||||
config_package_nearby::nearby_connections_feature::
|
||||
kDisableBluetoothClassicScanning)) {
|
||||
paused_bluetooth_clients_discoveries_.erase(
|
||||
client->GetDiscoveryServiceId());
|
||||
}
|
||||
|
||||
paused_bluetooth_clients_discoveries_.erase(
|
||||
client->GetDiscoveryServiceId());
|
||||
return {Status::kSuccess};
|
||||
}
|
||||
|
||||
@@ -1742,32 +1709,9 @@ P2pClusterPcpHandler::UpdateDiscoveryOptionsImpl(
|
||||
OperationResultCode::DETAIL_SUCCESS);
|
||||
operation_result_with_mediums.push_back(*operation_result_with_medium);
|
||||
} else {
|
||||
if (NearbyFlags::GetInstance().GetBoolFlag(
|
||||
config_package_nearby::nearby_connections_feature::
|
||||
kDisableBluetoothClassicScanning)) {
|
||||
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);
|
||||
}
|
||||
StartBluetoothDiscoveryWithPause(
|
||||
client, std::string(service_id), discovery_options, restarted_mediums,
|
||||
operation_result_with_mediums, update_index);
|
||||
}
|
||||
}
|
||||
// awdl (note: keep the awdl logic before the wifi lan logic)
|
||||
|
||||
@@ -16,7 +16,6 @@
|
||||
|
||||
#include <cstdint>
|
||||
#include <string>
|
||||
#include <tuple>
|
||||
|
||||
#include "gtest/gtest.h"
|
||||
#include "absl/time/clock.h"
|
||||
@@ -90,20 +89,12 @@ class P2pClusterPcpHandlerTest : public testing::Test {
|
||||
NearbyFlags::GetInstance().OverrideBoolFlagValue(
|
||||
config_package_nearby::nearby_connections_feature::kEnableAwdl, true);
|
||||
SetBleExtendedAdvertisementsAvailable(true);
|
||||
SetDisableBluetoothClassicScanning(true);
|
||||
}
|
||||
|
||||
void SetBleExtendedAdvertisementsAvailable(bool available) {
|
||||
env_.SetBleExtendedAdvertisementsAvailable(false);
|
||||
}
|
||||
|
||||
void SetDisableBluetoothClassicScanning(bool disable) {
|
||||
NearbyFlags::GetInstance().OverrideBoolFlagValue(
|
||||
config_package_nearby::nearby_connections_feature::
|
||||
kDisableBluetoothClassicScanning,
|
||||
disable);
|
||||
}
|
||||
|
||||
AdvertisingOptions GetBluetoothOnlyAdvertisingOptions() {
|
||||
return AdvertisingOptions{
|
||||
{Strategy::kP2pCluster,
|
||||
@@ -240,20 +231,13 @@ TEST_F(P2pClusterPcpHandlerTest,
|
||||
}
|
||||
|
||||
class P2pClusterPcpHandlerTestWithParam
|
||||
: public testing::TestWithParam<
|
||||
/*mediums=*/std::tuple<BooleanMediumSelector,
|
||||
/*disable_bluetooth_scanning*/ bool>> {
|
||||
: public testing::TestWithParam</*mediums=*/BooleanMediumSelector> {
|
||||
protected:
|
||||
void SetUp() override {
|
||||
LOG(INFO) << "SetUp: begin";
|
||||
env_.SetBleExtendedAdvertisementsAvailable(false);
|
||||
NearbyFlags::GetInstance().OverrideBoolFlagValue(
|
||||
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(
|
||||
config_package_nearby::nearby_connections_feature::kEnableDct, true);
|
||||
NearbyFlags::GetInstance().OverrideBoolFlagValue(
|
||||
@@ -277,8 +261,6 @@ class P2pClusterPcpHandlerTestWithParam
|
||||
if (advertising_options_.allowed.awdl) {
|
||||
LOG(INFO) << "SetUp: Awdl enabled";
|
||||
}
|
||||
LOG(INFO) << "SetUp: is_disable_bluetooth_scanning: "
|
||||
<< is_disable_bluetooth_scanning;
|
||||
LOG(INFO) << "SetUp: end";
|
||||
}
|
||||
|
||||
@@ -288,19 +270,19 @@ class P2pClusterPcpHandlerTestWithParam
|
||||
ConnectionOptions connection_options_{
|
||||
{
|
||||
Strategy::kP2pCluster,
|
||||
std::get<0>(GetParam()),
|
||||
GetParam(),
|
||||
},
|
||||
};
|
||||
AdvertisingOptions advertising_options_{
|
||||
{
|
||||
Strategy::kP2pCluster,
|
||||
std::get<0>(GetParam()),
|
||||
GetParam(),
|
||||
},
|
||||
};
|
||||
DiscoveryOptions discovery_options_{
|
||||
{
|
||||
Strategy::kP2pCluster,
|
||||
std::get<0>(GetParam()),
|
||||
GetParam(),
|
||||
},
|
||||
};
|
||||
MediumEnvironment& env_{MediumEnvironment::Instance()};
|
||||
@@ -385,11 +367,11 @@ TEST_P(P2pClusterPcpHandlerTestWithParam, AdvertiseForLegacyDeviceWithBt) {
|
||||
{.endpoint_info = ByteArray{endpoint_name}}),
|
||||
Status{Status::kSuccess});
|
||||
// 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_));
|
||||
}
|
||||
handler_a.StopAdvertising(&client_a_);
|
||||
if (std::get<0>(GetParam()).bluetooth) {
|
||||
if (GetParam().bluetooth) {
|
||||
EXPECT_FALSE(mediums_a.GetBle().IsAdvertisingForLegacyDevice(service_id_));
|
||||
}
|
||||
env_.Stop();
|
||||
@@ -619,7 +601,7 @@ TEST_P(P2pClusterPcpHandlerTestWithParam, CanDiscoverLegacy) {
|
||||
|
||||
TEST_P(P2pClusterPcpHandlerTestWithParam, PauseBluetoothClassicDiscovery) {
|
||||
// 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) {
|
||||
return;
|
||||
}
|
||||
@@ -648,7 +630,7 @@ TEST_P(P2pClusterPcpHandlerTestWithParam, PauseBluetoothClassicDiscovery) {
|
||||
|
||||
TEST_P(P2pClusterPcpHandlerTestWithParam, ResumeBluetoothClassicDiscovery) {
|
||||
// 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) {
|
||||
return;
|
||||
}
|
||||
@@ -802,14 +784,14 @@ TEST_P(P2pClusterPcpHandlerTestWithParam, CanUpdateDiscoveryOptions) {
|
||||
EXPECT_EQ(
|
||||
handler_a.StartDiscovery(&client_a_, service_id_, discovery_options_, {}),
|
||||
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.wifi_lan,
|
||||
mediums_a.GetWifiLan().IsDiscovering(service_id_));
|
||||
DiscoveryOptions new_options{
|
||||
{
|
||||
Strategy::kP2pCluster,
|
||||
std::get<0>(GetParam()),
|
||||
GetParam(),
|
||||
},
|
||||
false, // auto_upgrade_bandwidth
|
||||
false, // enforce_topology_constraints
|
||||
@@ -1664,10 +1646,6 @@ class P2pLostHandlerTestWithParam : public testing::TestWithParam<bool> {
|
||||
NearbyFlags::GetInstance().OverrideBoolFlagValue(
|
||||
config_package_nearby::nearby_connections_feature::kEnableAwdl, true);
|
||||
env_.SetBleExtendedAdvertisementsAvailable(true);
|
||||
NearbyFlags::GetInstance().OverrideBoolFlagValue(
|
||||
config_package_nearby::nearby_connections_feature::
|
||||
kDisableBluetoothClassicScanning,
|
||||
false);
|
||||
NearbyFlags::GetInstance().OverrideBoolFlagValue(
|
||||
config_package_nearby::nearby_connections_feature::kEnableInstantOnLost,
|
||||
GetParam());
|
||||
@@ -1808,10 +1786,9 @@ TEST_P(P2pLostHandlerTestWithParam, CanConnectWithInstantLostEnabled) {
|
||||
env_.SetBleExtendedAdvertisementsAvailable(false);
|
||||
}
|
||||
|
||||
INSTANTIATE_TEST_SUITE_P(
|
||||
ParametrisedPcpHandlerTest, P2pClusterPcpHandlerTestWithParam,
|
||||
::testing::Combine(/*mediums=*/::testing::ValuesIn(kTestCases),
|
||||
/*disable_bluetooth_scanning=*/::testing::Bool()));
|
||||
INSTANTIATE_TEST_SUITE_P(ParametrisedPcpHandlerTest,
|
||||
P2pClusterPcpHandlerTestWithParam,
|
||||
::testing::ValuesIn(kTestCases));
|
||||
INSTANTIATE_TEST_SUITE_P(ParametrisedP2pLostHandlerTest,
|
||||
P2pLostHandlerTestWithParam, testing::Bool());
|
||||
|
||||
|
||||
@@ -61,9 +61,6 @@ constexpr auto kLoggingLevel =
|
||||
// Enable/disable auto-update on settings page
|
||||
constexpr auto kShowAutoUpdateSetting =
|
||||
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.
|
||||
constexpr auto kDeleteUnexpectedReceivedFileFix =
|
||||
flags::Flag<bool>(kConfigPackage, "45657036", false);
|
||||
@@ -115,7 +112,6 @@ inline absl::btree_map<int, const flags::Flag<bool>&> GetBoolFlags() {
|
||||
{45418908, kEnableSelfShareUi},
|
||||
{45459748, kEnableSendingDesktopEvents},
|
||||
{45409033, kShowAutoUpdateSetting},
|
||||
{45630055, kUseGrpcClient},
|
||||
{45657036, kDeleteUnexpectedReceivedFileFix},
|
||||
{45673628, kEnableWifiHotspotForHpRealtekDevices},
|
||||
{45683539, kUseAlternateServiceUuidForDiscovery},
|
||||
|
||||
Reference in New Issue
Block a user