Added flag for BLE v2 in nearby connections

PiperOrigin-RevId: 516585139
This commit is contained in:
Guogang Li
2023-03-14 11:35:49 -07:00
committed by Copybara-Service
parent ecac59ef2b
commit e539d021a3
15 changed files with 484 additions and 22 deletions
+2
View File
@@ -401,6 +401,7 @@ let package = Package(
"WORKSPACE",
// build files
"connections/implementation/analytics/BUILD",
"connections/implementation/flags/BUILD",
"connections/implementation/mediums/ble_v2/BUILD",
"connections/implementation/mediums/BUILD",
"connections/implementation/BUILD",
@@ -438,6 +439,7 @@ let package = Package(
"connections/implementation/wifi_direct_bwu_test.cc",
"connections/implementation/wifi_hotspot_test.cc",
"connections/implementation/analytics/analytics_recorder_test.cc",
"connections/implementation/flags/connections_flags_test.cc",
"connections/implementation/analytics/throughput_recorder_test.cc",
"connections/implementation/mediums/ble_v2_test.cc",
"connections/implementation/mediums/ble_v2/bloom_filter_test.cc",
+1
View File
@@ -31,6 +31,7 @@ lexan.cc_windows_dll(
deps = [
"//connections:core",
"//connections/c",
"//connections/implementation/flags:connections_flags",
"//internal/platform/implementation/windows",
"//third_party/dart_lang/v2:dart_api_dl",
"//third_party/webrtc/files/stable/webrtc/api:create_peerconnection_factory",
+6 -1
View File
@@ -18,6 +18,8 @@
#include <string>
#include "connections/core.h"
#include "connections/implementation/flags/connections_flags.h"
#include "connections/implementation/flags/nearby_connections_feature_flags.h"
#include "connections/payload.h"
#include "internal/platform/count_down_latch.h"
#include "internal/platform/logging.h"
@@ -375,7 +377,10 @@ void EnableBleV2Dart(Core *pCore, int64_t enable, Dart_Port result_cb) {
}
port = result_cb;
FeatureFlags::GetMutableFlagsForTesting().support_ble_v2 = enable;
connections::ConnectionsFlags::GetInstance().OverrideBoolFlagValue(
connections::config_package_nearby::nearby_connections_feature::
kEnableBleV2,
enable);
PostResult(result_cb, Status::kSuccess);
}
+2
View File
@@ -147,6 +147,7 @@ cc_library(
":ukey2",
"//connections:core_types",
"//connections/implementation/analytics",
"//connections/implementation/flags:connections_flags",
"//connections/implementation/mediums",
"//connections/implementation/mediums:utils",
"//connections/implementation/proto:offline_wire_formats_cc_proto",
@@ -256,6 +257,7 @@ cc_test(
":internal_test",
":ukey2",
"//connections:core_types",
"//connections/implementation/flags:connections_flags",
"//connections/implementation/mediums",
"//connections/implementation/proto:offline_wire_formats_cc_proto",
"//internal/analytics:event_logger",
+55
View File
@@ -0,0 +1,55 @@
# Copyright 2023 Google LLC
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# https://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
licenses(["notice"])
cc_library(
name = "connections_flags",
srcs = [
"connections_flags.cc",
],
hdrs = [
"connections_flags.h",
"nearby_connections_feature_flags.h",
],
copts = [
"-Ithird_party",
],
visibility = [
"//connections:__subpackages__",
"//internal/platform:__subpackages__",
"//location/nearby/cpp:__subpackages__",
],
deps = [
"//internal/flags:flag_reader",
"//internal/platform:types",
"@com_google_absl//absl/base:core_headers",
"@com_google_absl//absl/container:flat_hash_map",
"@com_google_absl//absl/strings",
"@com_google_absl//absl/synchronization",
],
)
cc_test(
name = "connections_flags_test",
srcs = ["connections_flags_test.cc"],
deps = [
":connections_flags",
"//internal/flags:flag_reader",
"//internal/platform/implementation/g3",
"@com_github_protobuf_matchers//protobuf-matchers",
"@com_google_absl//absl/strings",
"@com_google_googletest//:gtest",
"@com_google_googletest//:gtest_main",
],
)
@@ -0,0 +1,125 @@
// Copyright 2023 Google LLC
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// https://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
#include "connections/implementation/flags/connections_flags.h"
#include <string>
#include "internal/platform/mutex.h"
#include "internal/platform/mutex_lock.h"
namespace nearby {
namespace connections {
ConnectionsFlags& ConnectionsFlags::GetInstance() {
static ConnectionsFlags* sharing_flags = new ConnectionsFlags();
return *sharing_flags;
}
bool ConnectionsFlags::GetBoolFlag(const flags::Flag<bool>& flag) {
MutexLock lock(&mutex_);
const auto& it = overrided_bool_flag_values_.find(flag.name());
if (it != overrided_bool_flag_values_.end()) {
return it->second;
}
if (flag_reader_ != nullptr) {
return flag_reader_->GetBoolFlag(flag);
}
return default_flag_reader_.GetBoolFlag(flag);
}
int64_t ConnectionsFlags::GetInt64Flag(const flags::Flag<int64_t>& flag) {
MutexLock lock(&mutex_);
const auto& it = overrided_int64_flag_values_.find(flag.name());
if (it != overrided_int64_flag_values_.end()) {
return it->second;
}
if (flag_reader_ != nullptr) {
return flag_reader_->GetInt64Flag(flag);
}
return default_flag_reader_.GetInt64Flag(flag);
}
double ConnectionsFlags::GetDoubleFlag(const flags::Flag<double>& flag) {
MutexLock lock(&mutex_);
const auto& it = overrided_double_flag_values_.find(flag.name());
if (it != overrided_double_flag_values_.end()) {
return it->second;
}
if (flag_reader_ != nullptr) {
return flag_reader_->GetDoubleFlag(flag);
}
return default_flag_reader_.GetDoubleFlag(flag);
}
std::string ConnectionsFlags::GetStringFlag(
const flags::Flag<absl::string_view>& flag) {
MutexLock lock(&mutex_);
const auto& it = overrided_string_flag_values_.find(flag.name());
if (it != overrided_string_flag_values_.end()) {
return it->second;
}
if (flag_reader_ != nullptr) {
return flag_reader_->GetStringFlag(flag);
}
return default_flag_reader_.GetStringFlag(flag);
}
void ConnectionsFlags::SetFlagReader(flags::FlagReader& flag_reader) {
MutexLock lock(&mutex_);
flag_reader_ = &flag_reader;
}
void ConnectionsFlags::OverrideBoolFlagValue(const flags::Flag<bool>& flag,
bool new_value) {
MutexLock lock(&mutex_);
overrided_bool_flag_values_[flag.name()] = new_value;
}
void ConnectionsFlags::OverrideInt64FlagValue(const flags::Flag<int64_t>& flag,
int64_t new_value) {
MutexLock lock(&mutex_);
overrided_int64_flag_values_[flag.name()] = new_value;
}
void ConnectionsFlags::OverrideDoubleFlagValue(const flags::Flag<double>& flag,
double new_value) {
MutexLock lock(&mutex_);
overrided_double_flag_values_[flag.name()] = new_value;
}
void ConnectionsFlags::OverrideStringFlagValue(
const flags::Flag<absl::string_view>& flag, absl::string_view new_value) {
MutexLock lock(&mutex_);
overrided_string_flag_values_[flag.name()] = std::string(new_value);
}
void ConnectionsFlags::ResetOverridedValues() {
MutexLock lock(&mutex_);
overrided_bool_flag_values_.clear();
overrided_int64_flag_values_.clear();
overrided_double_flag_values_.clear();
overrided_string_flag_values_.clear();
}
} // namespace connections
} // namespace nearby
@@ -0,0 +1,96 @@
// Copyright 2023 Google LLC
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// https://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
#ifndef THIRD_PARTY_NEARBY_CONNECTIONS_IMPLEMENTATION_FLAGS_CONNECTIONS_FLAGS_H_
#define THIRD_PARTY_NEARBY_CONNECTIONS_IMPLEMENTATION_FLAGS_CONNECTIONS_FLAGS_H_
#include <string>
#include "absl/container/flat_hash_map.h"
#include "absl/strings/string_view.h"
#include "connections/implementation/flags/nearby_connections_feature_flags.h"
#include "internal/flags/default_flag_reader.h"
#include "internal/flags/flag_reader.h"
#include "internal/platform/mutex.h"
namespace nearby {
namespace connections {
class ConnectionsFlags : public nearby::flags::FlagReader {
public:
~ConnectionsFlags() override = default;
static ConnectionsFlags& GetInstance();
// Reads flag with boolean value.
bool GetBoolFlag(const flags::Flag<bool>& flag) override
ABSL_LOCKS_EXCLUDED(mutex_);
// Reads flag with int64_t value.
int64_t GetInt64Flag(const flags::Flag<int64_t>& flag) override
ABSL_LOCKS_EXCLUDED(mutex_);
// Reads flag with double value.
double GetDoubleFlag(const flags::Flag<double>& flag) override
ABSL_LOCKS_EXCLUDED(mutex_);
// Reads flag with string value.
std::string GetStringFlag(const flags::Flag<absl::string_view>& flag) override
ABSL_LOCKS_EXCLUDED(mutex_);
void SetFlagReader(flags::FlagReader& flag_reader)
ABSL_LOCKS_EXCLUDED(mutex_);
// Override the default value of the flags. The major purpose of the method is
// for test.
void OverrideBoolFlagValue(const flags::Flag<bool>& flag, bool new_value)
ABSL_LOCKS_EXCLUDED(mutex_);
void OverrideInt64FlagValue(const flags::Flag<int64_t>& flag,
int64_t new_value) ABSL_LOCKS_EXCLUDED(mutex_);
void OverrideDoubleFlagValue(const flags::Flag<double>& flag,
double new_value) ABSL_LOCKS_EXCLUDED(mutex_);
void OverrideStringFlagValue(const flags::Flag<absl::string_view>& flag,
absl::string_view new_value)
ABSL_LOCKS_EXCLUDED(mutex_);
// Reset all overrided values.
void ResetOverridedValues() ABSL_LOCKS_EXCLUDED(mutex_);
private:
ConnectionsFlags() = default;
flags::FlagReader* flag_reader_ = nullptr;
flags::DefaultFlagReader default_flag_reader_;
mutable Mutex mutex_;
absl::flat_hash_map<std::string, bool> overrided_bool_flag_values_
ABSL_GUARDED_BY(mutex_);
absl::flat_hash_map<std::string, int64_t> overrided_int64_flag_values_
ABSL_GUARDED_BY(mutex_);
absl::flat_hash_map<std::string, double> overrided_double_flag_values_
ABSL_GUARDED_BY(mutex_);
absl::flat_hash_map<std::string, std::string> overrided_string_flag_values_
ABSL_GUARDED_BY(mutex_);
};
} // namespace connections
} // namespace nearby
#endif // THIRD_PARTY_NEARBY_CONNECTIONS_IMPLEMENTATION_FLAGS_CONNECTIONS_FLAGS_H_
@@ -0,0 +1,121 @@
// Copyright 2023 Google LLC
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// https://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
#include "connections/implementation/flags/connections_flags.h"
#include <cstdint>
#include <memory>
#include <string>
#include <string_view>
#include "gmock/gmock.h"
#include "protobuf-matchers/protocol-buffer-matchers.h"
#include "gtest/gtest.h"
#include "absl/strings/string_view.h"
#include "internal/flags/flag.h"
#include "internal/flags/flag_reader.h"
namespace nearby {
namespace connections {
namespace {
constexpr auto kTestBoolFlag =
flags::Flag<bool>("test_package", "45401515", false);
constexpr auto kTestInt64Flag =
flags::Flag<int64_t>("test_package", "45401516", 666);
constexpr auto kTestDoubleFlag =
flags::Flag<double>("test_package", "45401517", 66.66);
constexpr auto kTestStringFlag =
flags::Flag<absl::string_view>("test_package", "45401518", "string");
constexpr bool kTestBoolFlagTestValue = true;
constexpr int64_t kTestInt64FlagTestValue = 666;
constexpr double kTestDoubleFlagTestValue = 88.8;
constexpr std::string_view kTestStringFlagTestValue = "hello";
class MockFlagReader : public flags::FlagReader {
public:
MOCK_METHOD(bool, GetBoolFlag, (const flags::Flag<bool>& flag), (override));
MOCK_METHOD(int64_t, GetInt64Flag, (const flags::Flag<int64_t>& flag),
(override));
MOCK_METHOD(double, GetDoubleFlag, (const flags::Flag<double>& flag),
(override));
MOCK_METHOD(std::string, GetStringFlag,
(const flags::Flag<absl::string_view>& flag), (override));
};
TEST(ConnectionsFlags, GetDefaultValues) {
EXPECT_EQ(ConnectionsFlags::GetInstance().GetBoolFlag(kTestBoolFlag),
kTestBoolFlag.default_value());
EXPECT_EQ(ConnectionsFlags::GetInstance().GetInt64Flag(kTestInt64Flag),
kTestInt64Flag.default_value());
EXPECT_EQ(ConnectionsFlags::GetInstance().GetDoubleFlag(kTestDoubleFlag),
kTestDoubleFlag.default_value());
EXPECT_EQ(ConnectionsFlags::GetInstance().GetStringFlag(kTestStringFlag),
kTestStringFlag.default_value());
}
TEST(ConnectionsFlags, OverrideDefaultValues) {
ConnectionsFlags::GetInstance().OverrideBoolFlagValue(kTestBoolFlag,
kTestBoolFlagTestValue);
EXPECT_EQ(ConnectionsFlags::GetInstance().GetBoolFlag(kTestBoolFlag),
kTestBoolFlagTestValue);
ConnectionsFlags::GetInstance().OverrideInt64FlagValue(
kTestInt64Flag, kTestInt64FlagTestValue);
EXPECT_EQ(ConnectionsFlags::GetInstance().GetInt64Flag(kTestInt64Flag),
kTestInt64FlagTestValue);
ConnectionsFlags::GetInstance().OverrideDoubleFlagValue(
kTestDoubleFlag, kTestDoubleFlagTestValue);
EXPECT_EQ(ConnectionsFlags::GetInstance().GetDoubleFlag(kTestDoubleFlag),
kTestDoubleFlagTestValue);
ConnectionsFlags::GetInstance().OverrideStringFlagValue(
kTestStringFlag, kTestStringFlagTestValue);
EXPECT_EQ(ConnectionsFlags::GetInstance().GetStringFlag(kTestStringFlag),
kTestStringFlagTestValue);
ConnectionsFlags::GetInstance().ResetOverridedValues();
}
TEST(ConnectionsFlags, SetFlagReader) {
auto flag_reader = std::make_unique<::testing::NiceMock<MockFlagReader>>();
ConnectionsFlags::GetInstance().SetFlagReader(*flag_reader.get());
EXPECT_CALL(*flag_reader, GetBoolFlag(::testing::_))
.WillOnce(::testing::Invoke([=](const flags::Flag<bool>& flag) {
return kTestBoolFlagTestValue;
}));
EXPECT_EQ(ConnectionsFlags::GetInstance().GetBoolFlag(kTestBoolFlag),
kTestBoolFlagTestValue);
EXPECT_CALL(*flag_reader, GetInt64Flag(::testing::_))
.WillOnce(::testing::Invoke([=](const flags::Flag<int64_t>& flag) {
return kTestInt64FlagTestValue;
}));
EXPECT_EQ(ConnectionsFlags::GetInstance().GetInt64Flag(kTestInt64Flag),
kTestInt64FlagTestValue);
EXPECT_CALL(*flag_reader, GetDoubleFlag(::testing::_))
.WillOnce(::testing::Invoke([=](const flags::Flag<double>& flag) {
return kTestDoubleFlagTestValue;
}));
EXPECT_EQ(ConnectionsFlags::GetInstance().GetDoubleFlag(kTestDoubleFlag),
kTestDoubleFlagTestValue);
EXPECT_CALL(*flag_reader, GetStringFlag(::testing::_))
.WillOnce(
::testing::Invoke([=](const flags::Flag<absl::string_view>& flag) {
return std::string(kTestStringFlagTestValue);
}));
EXPECT_EQ(ConnectionsFlags::GetInstance().GetStringFlag(kTestStringFlag),
kTestStringFlagTestValue);
}
} // namespace
} // namespace connections
} // namespace nearby
@@ -0,0 +1,42 @@
// Copyright 2023 Google LLC
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// https://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
#ifndef THIRD_PARTY_NEARBY_CONNECTIONS_IMPLEMENTATION_FLAGS_NEARBY_CONNECTIONS_FEATURE_FLAGS_H_
#define THIRD_PARTY_NEARBY_CONNECTIONS_IMPLEMENTATION_FLAGS_NEARBY_CONNECTIONS_FEATURE_FLAGS_H_
#include "absl/strings/string_view.h"
#include "internal/flags/flag.h"
namespace nearby {
namespace connections {
namespace config_package_nearby {
#ifndef PHENOTYPE_CONFIG_PACKAGE_NEARBY
#define PHENOTYPE_CONFIG_PACKAGE_NEARBY
constexpr absl::string_view kConfigPackage = "nearby";
#endif // PHENOTYPE_CONFIG_PACKAGE_NEARBY
// The Nearby Connections features.
namespace nearby_connections_feature {
// Disable/Enable BLE v2 in Nearby Connections SDK.
constexpr auto kEnableBleV2 =
flags::Flag<bool>(kConfigPackage, "45401515", false);
} // namespace nearby_connections_feature
} // namespace config_package_nearby
} // namespace connections
} // namespace nearby
#endif // THIRD_PARTY_NEARBY_CONNECTIONS_IMPLEMENTATION_FLAGS_NEARBY_CONNECTIONS_FEATURE_FLAGS_H_
@@ -40,6 +40,7 @@ cc_library(
],
deps = [
"//connections:core_types",
"//connections/implementation/flags:connections_flags",
"//connections/implementation/mediums:utils",
"//internal/platform:base",
"//internal/platform:comm",
@@ -20,6 +20,8 @@
#include <utility>
#include "absl/strings/str_cat.h"
#include "connections/implementation/flags/connections_flags.h"
#include "connections/implementation/flags/nearby_connections_feature_flags.h"
#include "internal/platform/base64_utils.h"
#include "internal/platform/base_input_stream.h"
#include "internal/platform/byte_array.h"
@@ -142,9 +144,8 @@ BleAdvertisementHeader::operator ByteArray() const {
std::string(advertisement_hash_),
std::string(psm_bytes));
// clang-format on
if (FeatureFlags::GetInstance()
.GetFlags()
.enable_ble_v2_advertisement_base64_encoding) {
if (ConnectionsFlags::GetInstance().GetBoolFlag(
config_package_nearby::nearby_connections_feature::kEnableBleV2)) {
return ByteArray(Base64Utils::Encode(ByteArray(std::move(out))));
} else {
return ByteArray(std::move(out));
@@ -26,6 +26,8 @@
#include "connections/implementation/ble_v2_endpoint_channel.h"
#include "connections/implementation/bluetooth_endpoint_channel.h"
#include "connections/implementation/bwu_manager.h"
#include "connections/implementation/flags/connections_flags.h"
#include "connections/implementation/flags/nearby_connections_feature_flags.h"
#include "connections/implementation/mediums/utils.h"
#include "connections/implementation/wifi_lan_endpoint_channel.h"
#include "internal/platform/nsd_service_info.h"
@@ -81,7 +83,8 @@ P2pClusterPcpHandler::GetConnectionMediumsByPriority() {
if (bluetooth_medium_.IsAvailable()) {
mediums.push_back(location::nearby::proto::connections::BLUETOOTH);
}
if (FeatureFlags::GetInstance().GetFlags().support_ble_v2) {
if (ConnectionsFlags::GetInstance().GetBoolFlag(
config_package_nearby::nearby_connections_feature::kEnableBleV2)) {
if (ble_v2_medium_.IsAvailable()) {
mediums.push_back(location::nearby::proto::connections::BLE);
}
@@ -136,7 +139,8 @@ BasePcpHandler::StartOperationResult P2pClusterPcpHandler::StartAdvertisingImpl(
}
if (advertising_options.allowed.ble) {
if (FeatureFlags::GetInstance().GetFlags().support_ble_v2) {
if (ConnectionsFlags::GetInstance().GetBoolFlag(
config_package_nearby::nearby_connections_feature::kEnableBleV2)) {
location::nearby::proto::connections::Medium ble_v2_medium =
StartBleV2Advertising(client, service_id, local_endpoint_id,
local_endpoint_info, advertising_options,
@@ -192,7 +196,8 @@ Status P2pClusterPcpHandler::StopAdvertisingImpl(ClientProxy* client) {
bluetooth_medium_.StopAcceptingConnections(client->GetAdvertisingServiceId());
if (FeatureFlags::GetInstance().GetFlags().support_ble_v2) {
if (ConnectionsFlags::GetInstance().GetBoolFlag(
config_package_nearby::nearby_connections_feature::kEnableBleV2)) {
ble_v2_medium_.StopAdvertising(client->GetAdvertisingServiceId());
ble_v2_medium_.StopAcceptingConnections(client->GetAdvertisingServiceId());
} else {
@@ -961,7 +966,8 @@ BasePcpHandler::StartOperationResult P2pClusterPcpHandler::StartDiscoveryImpl(
}
if (discovery_options.allowed.ble) {
if (FeatureFlags::GetInstance().GetFlags().support_ble_v2) {
if (ConnectionsFlags::GetInstance().GetBoolFlag(
config_package_nearby::nearby_connections_feature::kEnableBleV2)) {
location::nearby::proto::connections::Medium ble_v2_medium =
StartBleV2Scanning(
{
@@ -1029,7 +1035,8 @@ Status P2pClusterPcpHandler::StopDiscoveryImpl(ClientProxy* client) {
<< bluetooth_classic_discoverer_client_id_;
}
if (FeatureFlags::GetInstance().GetFlags().support_ble_v2) {
if (ConnectionsFlags::GetInstance().GetBoolFlag(
config_package_nearby::nearby_connections_feature::kEnableBleV2)) {
ble_v2_medium_.StopScanning(client->GetDiscoveryServiceId());
} else {
ble_medium_.StopScanning(client->GetDiscoveryServiceId());
@@ -1079,7 +1086,9 @@ BasePcpHandler::ConnectImplResult P2pClusterPcpHandler::ConnectImpl(
break;
}
case location::nearby::proto::connections::Medium::BLE: {
if (FeatureFlags::GetInstance().GetFlags().support_ble_v2) {
if (ConnectionsFlags::GetInstance().GetBoolFlag(
config_package_nearby::nearby_connections_feature::
kEnableBleV2)) {
auto* ble_v2_endpoint = down_cast<BleV2Endpoint*>(endpoint);
if (ble_v2_endpoint) {
return BleV2ConnectImpl(client, ble_v2_endpoint);
@@ -1876,8 +1885,8 @@ BasePcpHandler::ConnectImplResult P2pClusterPcpHandler::WifiLanConnectImpl(
endpoint->service_id, endpoint->service_info,
client->GetCancellationFlag(endpoint->endpoint_id));
NEARBY_LOGS(INFO) << "In WifiLanConnectImpl(), connect to service "
<< " socket=" << &socket.GetImpl()
<< " for endpoint(id=" << endpoint->endpoint_id << ").";
<< " socket=" << &socket.GetImpl()
<< " for endpoint(id=" << endpoint->endpoint_id << ").";
if (!socket.IsValid()) {
NEARBY_LOGS(ERROR)
<< "In WifiLanConnectImpl(), failed to connect to service "
@@ -22,6 +22,8 @@
#include "gtest/gtest.h"
#include "absl/time/time.h"
#include "connections/implementation/bwu_manager.h"
#include "connections/implementation/flags/connections_flags.h"
#include "connections/implementation/flags/nearby_connections_feature_flags.h"
#include "connections/implementation/injected_bluetooth_device_store.h"
#include "internal/platform/count_down_latch.h"
#include "internal/platform/logging.h"
@@ -60,15 +62,16 @@ constexpr BooleanMediumSelector kTestCases[] = {
},
};
// Combines the bool `support_ble_v2` as param testing but should revert it back
// Combines the bool `kEnableBleV2` as param testing but should revert it back
// if ble_v2 is done and ble will be replaced by ble_v2.
class P2pClusterPcpHandlerTest
: public testing::TestWithParam<std::tuple<BooleanMediumSelector, bool>> {
protected:
void SetUp() override {
NEARBY_LOG(INFO, "SetUp: begin");
FeatureFlags::GetMutableFlagsForTesting().support_ble_v2 =
std::get<1>(GetParam());
ConnectionsFlags::GetInstance().OverrideBoolFlagValue(
config_package_nearby::nearby_connections_feature::kEnableBleV2,
std::get<1>(GetParam()));
if (advertising_options_.allowed.ble) {
NEARBY_LOG(INFO, "SetUp: BLE enabled");
}
@@ -25,6 +25,8 @@
#include "gtest/gtest.h"
#include "absl/time/time.h"
#include "connections/implementation/bwu_manager.h"
#include "connections/implementation/flags/connections_flags.h"
#include "connections/implementation/flags/nearby_connections_feature_flags.h"
#include "connections/implementation/injected_bluetooth_device_store.h"
#include "internal/platform/count_down_latch.h"
#include "internal/platform/logging.h"
@@ -69,15 +71,16 @@ constexpr BooleanMediumSelector kTestCases[] = {
},
};
// Combines the bool `support_ble_v2` as param testing but should revert it back
// Combines the bool `kEnableBleV2` as param testing but should revert it back
// if ble_v2 is done and ble will be replaced by ble_v2.
class P2pPointToPointPcpHandlerTest
: public testing::TestWithParam<std::tuple<BooleanMediumSelector, bool>> {
protected:
void SetUp() override {
NEARBY_LOG(INFO, "SetUp: begin");
FeatureFlags::GetMutableFlagsForTesting().support_ble_v2 =
std::get<1>(GetParam());
ConnectionsFlags::GetInstance().OverrideBoolFlagValue(
config_package_nearby::nearby_connections_feature::kEnableBleV2,
std::get<1>(GetParam()));
if (advertising_options_.allowed.ble) {
NEARBY_LOG(INFO, "SetUp: BLE enabled");
}
-4
View File
@@ -45,10 +45,6 @@ class FeatureFlags {
// necessary to properly support multiple BWU mediums, multiple service, and
// multiple endpionts.
bool support_multiple_bwu_mediums = true;
// Ble v2/v1 switch flag: the flag will be removed once v2 refactor is done.
bool support_ble_v2 = false;
// Controls BLE advertisement data format in base64 or not.
bool enable_ble_v2_advertisement_base64_encoding = false;
// Allows the code to change the bluetooth radio state
bool enable_set_radio_state = false;
// If the feature is enabled, medium connection will timeout when cannot