Internal refactor

PiperOrigin-RevId: 815749899
This commit is contained in:
Guogang Li
2025-10-06 09:03:08 -07:00
committed by Copybara-Service
parent a065584164
commit cce45b745e
114 changed files with 2096 additions and 2141 deletions
+3 -3
View File
@@ -56,8 +56,8 @@ cc_library(
"base_bwu_handler.cc",
"base_endpoint_channel.cc",
"base_pcp_handler.cc",
"ble_endpoint_channel.cc",
"ble_l2cap_endpoint_channel.cc",
"ble_v2_endpoint_channel.cc",
"bluetooth_bwu_handler.cc",
"bluetooth_device_name.cc",
"bluetooth_endpoint_channel.cc",
@@ -97,8 +97,8 @@ cc_library(
"base_bwu_handler.h",
"base_endpoint_channel.h",
"base_pcp_handler.h",
"ble_endpoint_channel.h",
"ble_l2cap_endpoint_channel.h",
"ble_v2_endpoint_channel.h",
"bluetooth_bwu_handler.h",
"bluetooth_device_name.h",
"bluetooth_endpoint_channel.h",
@@ -160,7 +160,7 @@ cc_library(
"//connections/implementation/mediums:webrtc_utils",
"//connections/implementation/mediums/advertisements:dct_advertisement",
"//connections/implementation/mediums/advertisements:util",
"//connections/implementation/mediums/ble_v2:ble_advertisement_header",
"//connections/implementation/mediums/ble:ble_advertisement_header",
"//connections/implementation/proto:offline_wire_formats_cc_proto",
"//connections/v3:v3_types",
"//internal/analytics:event_logger",
@@ -1159,7 +1159,7 @@ void BasePcpHandler::StripOutUnavailableMediums(
allowed.bluetooth = mediums_->GetBluetoothClassic().IsAvailable();
}
if (allowed.ble) {
allowed.ble = mediums_->GetBleV2().IsAvailable();
allowed.ble = mediums_->GetBle().IsAvailable();
}
if (allowed.web_rtc) {
allowed.web_rtc = mediums_->GetWebRtc().IsAvailable();
@@ -1206,7 +1206,7 @@ void BasePcpHandler::StripOutUnavailableMediums(
allowed.bluetooth = mediums_->GetBluetoothClassic().IsAvailable();
}
if (allowed.ble) {
allowed.ble = mediums_->GetBleV2().IsAvailable();
allowed.ble = mediums_->GetBle().IsAvailable();
}
if (allowed.web_rtc) {
allowed.web_rtc = mediums_->GetWebRtc().IsAvailable();
@@ -55,7 +55,7 @@
#include "internal/interop/device.h"
#include "internal/interop/device_provider.h"
#include "internal/platform/atomic_boolean.h"
#include "internal/platform/ble_v2.h"
#include "internal/platform/ble.h"
#include "internal/platform/bluetooth_adapter.h"
#include "internal/platform/byte_array.h"
#include "internal/platform/cancelable_alarm.h"
@@ -236,12 +236,12 @@ class BasePcpHandler : public PcpHandler,
BluetoothDevice bluetooth_device;
};
struct BleV2Endpoint : public BasePcpHandler::DiscoveredEndpoint {
BleV2Endpoint(DiscoveredEndpoint endpoint, BleV2Peripheral peripheral)
struct BleEndpoint : public BasePcpHandler::DiscoveredEndpoint {
BleEndpoint(DiscoveredEndpoint endpoint, BlePeripheral peripheral)
: DiscoveredEndpoint(std::move(endpoint)),
ble_peripheral(std::move(peripheral)) {}
BleV2Peripheral ble_peripheral;
BlePeripheral ble_peripheral;
};
struct AwdlEndpoint : public DiscoveredEndpoint {
@@ -561,8 +561,7 @@ class BasePcpHandler : public PcpHandler,
// address is created and appended into discovered_endpoints_ with key
// endpoint_id.
bool AppendRemoteBluetoothMacAddressEndpoint(
const std::string& endpoint_id,
MacAddress remote_bluetooth_mac_address,
const std::string& endpoint_id, MacAddress remote_bluetooth_mac_address,
const DiscoveryOptions& local_discovery_options)
ABSL_LOCKS_EXCLUDED(discovered_endpoint_mutex_);
@@ -12,13 +12,13 @@
// See the License for the specific language governing permissions and
// limitations under the License.
#include "connections/implementation/ble_v2_endpoint_channel.h"
#include "connections/implementation/ble_endpoint_channel.h"
#include <string>
#include <utility>
#include "connections/implementation/base_endpoint_channel.h"
#include "internal/platform/ble_v2.h"
#include "internal/platform/ble.h"
#include "internal/platform/exception.h"
#include "internal/platform/input_stream.h"
#include "internal/platform/logging.h"
@@ -29,14 +29,14 @@ namespace connections {
namespace {
OutputStream* GetOutputStreamOrNull(BleV2Socket& socket) {
OutputStream* GetOutputStreamOrNull(BleSocket& socket) {
if (socket.IsValid()) {
return &socket.GetOutputStream();
}
return nullptr;
}
InputStream* GetInputStreamOrNull(BleV2Socket& socket) {
InputStream* GetInputStreamOrNull(BleSocket& socket) {
if (socket.IsValid()) {
return &socket.GetInputStream();
}
@@ -45,24 +45,24 @@ InputStream* GetInputStreamOrNull(BleV2Socket& socket) {
} // namespace
BleV2EndpointChannel::BleV2EndpointChannel(const std::string& service_id,
const std::string& channel_name,
BleV2Socket socket)
BleEndpointChannel::BleEndpointChannel(const std::string& service_id,
const std::string& channel_name,
BleSocket socket)
: BaseEndpointChannel(service_id, channel_name,
GetInputStreamOrNull(socket),
GetOutputStreamOrNull(socket)),
ble_socket_(std::move(socket)) {}
location::nearby::proto::connections::Medium BleV2EndpointChannel::GetMedium()
location::nearby::proto::connections::Medium BleEndpointChannel::GetMedium()
const {
return location::nearby::proto::connections::Medium::BLE;
}
int BleV2EndpointChannel::GetMaxTransmitPacketSize() const {
int BleEndpointChannel::GetMaxTransmitPacketSize() const {
return kDefaultBleMaxTransmitPacketSize;
}
void BleV2EndpointChannel::CloseImpl() {
void BleEndpointChannel::CloseImpl() {
Exception status = ble_socket_.Close();
if (!status.Ok()) {
LOG(WARNING) << "Failed to close underlying socket for BleEndpointChannel "
@@ -12,22 +12,22 @@
// See the License for the specific language governing permissions and
// limitations under the License.
#ifndef CONNECTIONS_IMPLEMENTATION_BLE_V2_ENDPOINT_CHANNEL_H_
#define CONNECTIONS_IMPLEMENTATION_BLE_V2_ENDPOINT_CHANNEL_H_
#ifndef CONNECTIONS_IMPLEMENTATION_BLE_ENDPOINT_CHANNEL_H_
#define CONNECTIONS_IMPLEMENTATION_BLE_ENDPOINT_CHANNEL_H_
#include <string>
#include "connections/implementation/base_endpoint_channel.h"
#include "internal/platform/ble_v2.h"
#include "internal/platform/ble.h"
namespace nearby {
namespace connections {
class BleV2EndpointChannel final : public BaseEndpointChannel {
class BleEndpointChannel final : public BaseEndpointChannel {
public:
// Creates both outgoing and incoming Ble channels.
BleV2EndpointChannel(const std::string& service_id,
const std::string& channel_name, BleV2Socket socket);
BleEndpointChannel(const std::string& service_id,
const std::string& channel_name, BleSocket socket);
location::nearby::proto::connections::Medium GetMedium() const override;
@@ -38,10 +38,10 @@ class BleV2EndpointChannel final : public BaseEndpointChannel {
void CloseImpl() override;
BleV2Socket ble_socket_;
BleSocket ble_socket_;
};
} // namespace connections
} // namespace nearby
#endif // CONNECTIONS_IMPLEMENTATION_BLE_V2_ENDPOINT_CHANNEL_H_
#endif // CONNECTIONS_IMPLEMENTATION_BLE_ENDPOINT_CHANNEL_H_
@@ -18,7 +18,7 @@
#include <utility>
#include "connections/implementation/base_endpoint_channel.h"
#include "internal/platform/ble_v2.h"
#include "internal/platform/ble.h"
#include "internal/platform/exception.h"
#include "internal/platform/input_stream.h"
#include "internal/platform/logging.h"
@@ -18,7 +18,7 @@
#include <string>
#include "connections/implementation/base_endpoint_channel.h"
#include "internal/platform/ble_v2.h"
#include "internal/platform/ble.h"
namespace nearby {
namespace connections {
+5 -5
View File
@@ -977,11 +977,11 @@ BwuManager::ProcessBwuPathAvailableEventInternal(
location::nearby::connections::OsInfo::APPLE &&
old_medium == Medium::BLE && medium == Medium::WIFI_HOTSPOT) {
disable_ble_scanning = true;
LOG(INFO) << "For Apple OS, if upgrade from BLE_V2 to WIFI_HOTSPOT, "
LOG(INFO) << "For Apple OS, if upgrade from BLE to WIFI_HOTSPOT, "
"we need to pause "
"BLE_V2 scanning because it can interfere with WIFI "
"BLE scanning because it can interfere with WIFI "
"Hotspot scanning and connection.";
ble_v2_medium_.PauseMediumScanning();
ble_medium_.PauseMediumScanning();
}
}
@@ -993,8 +993,8 @@ BwuManager::ProcessBwuPathAvailableEventInternal(
config_package_nearby::nearby_connections_feature::
kEnableStopBleScanningOnWifiUpgrade)) {
if (disable_ble_scanning) {
LOG(INFO) << "Resume BLE_V2 scanning.";
ble_v2_medium_.ResumeMediumScanning();
LOG(INFO) << "Resume BLE scanning.";
ble_medium_.ResumeMediumScanning();
}
}
+2 -2
View File
@@ -28,7 +28,7 @@
#include "connections/implementation/endpoint_channel.h"
#include "connections/implementation/endpoint_channel_manager.h"
#include "connections/implementation/endpoint_manager.h"
#include "connections/implementation/mediums/ble_v2.h"
#include "connections/implementation/mediums/ble.h"
#include "connections/implementation/mediums/mediums.h"
#include "connections/medium_selector.h"
#include "internal/platform/cancelable_alarm.h"
@@ -234,7 +234,7 @@ class BwuManager : public EndpointManager::FrameProcessor {
Mediums* mediums_;
absl::flat_hash_map<Medium, std::unique_ptr<BwuHandler>> handlers_;
BleV2& ble_v2_medium_{mediums_->GetBleV2()};
Ble& ble_medium_{mediums_->GetBle()};
EndpointManager* endpoint_manager_;
EndpointChannelManager* channel_manager_;
+9 -9
View File
@@ -21,7 +21,7 @@ cc_library(
name = "mediums",
srcs = [
"awdl.cc",
"ble_v2.cc",
"ble.cc",
"bluetooth_classic.cc",
"bluetooth_radio.cc",
"mediums.cc",
@@ -33,7 +33,7 @@ cc_library(
],
hdrs = [
"awdl.h",
"ble_v2.h",
"ble.h",
"bluetooth_classic.h",
"bluetooth_radio.h",
"mediums.h",
@@ -54,9 +54,9 @@ cc_library(
"//connections:core_types",
"//connections/implementation:types",
"//connections/implementation/flags:connections_flags",
"//connections/implementation/mediums/ble_v2",
"//connections/implementation/mediums/ble_v2:ble_advertisement_header",
"//connections/implementation/mediums/ble_v2:bloom_filter",
"//connections/implementation/mediums/ble",
"//connections/implementation/mediums/ble:ble_advertisement_header",
"//connections/implementation/mediums/ble:bloom_filter",
"//connections/implementation/mediums/multiplex",
"//connections/implementation/mediums/webrtc",
"//connections/implementation/proto:offline_wire_formats_cc_proto",
@@ -115,7 +115,7 @@ cc_library(
name = "lost_entity_tracker",
hdrs = ["lost_entity_tracker.h"],
visibility = [
"//connections/implementation/mediums/ble_v2:__pkg__",
"//connections/implementation/mediums/ble:__pkg__",
],
deps = [
"//internal/platform:types",
@@ -131,7 +131,7 @@ cc_library(
visibility = [
"//connections/implementation:__pkg__",
"//connections/implementation/mediums/advertisements:__pkg__",
"//connections/implementation/mediums/ble_v2:__subpackages__",
"//connections/implementation/mediums/ble:__subpackages__",
"//connections/implementation/mediums/multiplex:__pkg__",
"//internal/platform/implementation/windows:__pkg__",
],
@@ -146,7 +146,7 @@ cc_test(
size = "small",
srcs = [
"awdl_test.cc",
"ble_v2_test.cc",
"ble_test.cc",
"bluetooth_classic_test.cc",
"bluetooth_radio_test.cc",
"lost_entity_tracker_test.cc",
@@ -163,7 +163,7 @@ cc_test(
"//connections:core_types",
"//connections/implementation:types",
"//connections/implementation/flags:connections_flags",
"//connections/implementation/mediums/ble_v2",
"//connections/implementation/mediums/ble",
"//internal/flags:nearby_flags",
"//internal/platform:base",
"//internal/platform:cancellation_flag",
@@ -12,7 +12,7 @@
// See the License for the specific language governing permissions and
// limitations under the License.
#include "connections/implementation/mediums/ble_v2.h"
#include "connections/implementation/mediums/ble.h"
#include <algorithm>
#include <cstdint>
@@ -32,24 +32,24 @@
#include "absl/time/time.h"
#include "absl/types/optional.h"
#include "connections/implementation/flags/nearby_connections_feature_flags.h"
#include "connections/implementation/mediums/ble_v2/advertisement_read_result.h"
#include "connections/implementation/mediums/ble_v2/ble_advertisement.h"
#include "connections/implementation/mediums/ble_v2/ble_advertisement_header.h"
#include "connections/implementation/mediums/ble_v2/ble_utils.h"
#include "connections/implementation/mediums/ble_v2/bloom_filter.h"
#include "connections/implementation/mediums/ble_v2/discovered_peripheral_tracker.h"
#include "connections/implementation/mediums/ble/advertisement_read_result.h"
#include "connections/implementation/mediums/ble/ble_advertisement.h"
#include "connections/implementation/mediums/ble/ble_advertisement_header.h"
#include "connections/implementation/mediums/ble/ble_utils.h"
#include "connections/implementation/mediums/ble/bloom_filter.h"
#include "connections/implementation/mediums/ble/discovered_peripheral_tracker.h"
#include "connections/implementation/mediums/bluetooth_radio.h"
#include "connections/implementation/mediums/utils.h"
#include "connections/implementation/pcp.h"
#include "connections/power_level.h"
#include "internal/flags/nearby_flags.h"
#include "internal/platform/ble_v2.h"
#include "internal/platform/ble.h"
#include "internal/platform/byte_array.h"
#include "internal/platform/cancelable_alarm.h"
#include "internal/platform/cancellation_flag.h"
#include "internal/platform/expected.h"
#include "internal/platform/feature_flags.h"
#include "internal/platform/implementation/ble_v2.h"
#include "internal/platform/implementation/ble.h"
#include "internal/platform/implementation/platform.h"
#include "internal/platform/logging.h"
#include "internal/platform/mutex.h"
@@ -63,9 +63,9 @@ namespace connections {
namespace {
using ::location::nearby::proto::connections::OperationResultCode;
using ::nearby::api::ble_v2::BleAdvertisementData;
using ::nearby::api::ble_v2::GattCharacteristic;
using ::nearby::api::ble_v2::TxPowerLevel;
using ::nearby::api::ble::BleAdvertisementData;
using ::nearby::api::ble::GattCharacteristic;
using ::nearby::api::ble::TxPowerLevel;
constexpr int kMaxAdvertisementLength = 512;
constexpr int kDummyServiceIdLength = 128;
@@ -76,10 +76,10 @@ void AssumeHeld(Mutex& m) ABSL_ASSERT_EXCLUSIVE_LOCK(m) {}
} // namespace
BleV2::BleV2(BluetoothRadio& radio)
Ble::Ble(BluetoothRadio& radio)
: radio_(radio), adapter_(radio_.GetBluetoothAdapter()) {}
BleV2::~BleV2() {
Ble::~Ble() {
// Destructor is not taking locks, but methods it is calling are.
if (FeatureFlags::GetInstance().GetFlags().enable_ble_v2_async_scanning) {
// If using asynchronous scanning, check the corresponding map.
@@ -115,16 +115,16 @@ BleV2::~BleV2() {
}
}
bool BleV2::IsAvailable() const {
bool Ble::IsAvailable() const {
MutexLock lock(&mutex_);
return IsAvailableLocked();
}
ErrorOr<bool> BleV2::StartAdvertising(const std::string& service_id,
PowerLevel power_level,
AdvertisingType advertising_type,
const ByteArray& advertisement_bytes) {
ErrorOr<bool> Ble::StartAdvertising(const std::string& service_id,
PowerLevel power_level,
AdvertisingType advertising_type,
const ByteArray& advertisement_bytes) {
MutexLock lock(&mutex_);
if (advertisement_bytes.Empty()) {
@@ -222,7 +222,7 @@ ErrorOr<bool> BleV2::StartAdvertising(const std::string& service_id,
return {true};
}
bool BleV2::StopAdvertising(const std::string& service_id) {
bool Ble::StopAdvertising(const std::string& service_id) {
MutexLock lock(&mutex_);
if (!IsAdvertisingLocked(service_id)) {
LOG(INFO) << "Cannot stop BLE advertising for service_id=" << service_id
@@ -285,19 +285,19 @@ bool BleV2::StopAdvertising(const std::string& service_id) {
return true;
}
bool BleV2::IsAdvertising(const std::string& service_id) const {
bool Ble::IsAdvertising(const std::string& service_id) const {
MutexLock lock(&mutex_);
return IsAdvertisingLocked(service_id);
}
bool BleV2::IsAdvertisingForLegacyDevice(const std::string& service_id) const {
bool Ble::IsAdvertisingForLegacyDevice(const std::string& service_id) const {
MutexLock lock(&mutex_);
return IsAdvertisingForLegacyDeviceLocked(service_id);
}
ErrorOr<bool> BleV2::StartLegacyAdvertising(
ErrorOr<bool> Ble::StartLegacyAdvertising(
const std::string& input_service_id, const std::string& local_endpoint_id,
const std::string& fast_advertisement_service_uuid) {
LOG(INFO) << "StartLegacyAdvertising: " << input_service_id
@@ -305,13 +305,12 @@ ErrorOr<bool> BleV2::StartLegacyAdvertising(
MutexLock lock(&mutex_);
if (!radio_.IsEnabled()) {
LOG(INFO) << "Can't start BLE v2 legacy advertising because "
LOG(INFO) << "Can't start BLE legacy advertising because "
"Bluetooth was never turned on";
return {Error(OperationResultCode::MISCELLEANEOUS_BT_SYSTEM_SERVICE_NULL)};
}
if (!IsAvailableLocked()) {
LOG(INFO)
<< "Can't turn on BLE v2 legacy advertising. BLE is not available.";
LOG(INFO) << "Can't turn on BLE legacy advertising. BLE is not available.";
return {Error(OperationResultCode::MEDIUM_UNAVAILABLE_BLE_NOT_AVAILABLE)};
}
if (medium_.IsExtendedAdvertisementsAvailable()) {
@@ -325,21 +324,20 @@ ErrorOr<bool> BleV2::StartLegacyAdvertising(
return {Error(OperationResultCode::CLIENT_BLE_DUPLICATE_ADVERTISING)};
}
std::unique_ptr<api::ble_v2::BleMedium::AdvertisingSession>
std::unique_ptr<api::ble::BleMedium::AdvertisingSession>
legacy_device_advertizing_session = medium_.StartAdvertising(
CreateAdvertisingDataForLegacyDevice(),
{.tx_power_level = TxPowerLevel::kMedium, .is_connectable = true},
api::ble_v2::BleMedium::AdvertisingCallback{
api::ble::BleMedium::AdvertisingCallback{
.start_advertising_result =
[this, &service_id](absl::Status status) mutable {
AssumeHeld(mutex_);
if (status.ok()) {
LOG(INFO)
<< "BLE V2 advertising for legacy device started "
"successfully for service ID "
<< &service_id;
LOG(INFO) << "BLE advertising for legacy device started "
"successfully for service ID "
<< &service_id;
} else {
LOG(ERROR) << "BLE V2 advertising for legacy "
LOG(ERROR) << "BLE advertising for legacy "
"device failed for service ID "
<< &service_id << ": " << status;
service_ids_to_advertising_sessions_.erase(service_id);
@@ -347,7 +345,7 @@ ErrorOr<bool> BleV2::StartLegacyAdvertising(
},
});
if (legacy_device_advertizing_session == nullptr) {
LOG(ERROR) << "Failed to turn on BLE v2 advertising for legacy "
LOG(ERROR) << "Failed to turn on BLE advertising for legacy "
"device for service ID "
<< service_id;
return {
@@ -359,7 +357,7 @@ ErrorOr<bool> BleV2::StartLegacyAdvertising(
return {true};
}
bool BleV2::StopLegacyAdvertising(const std::string& input_service_id) {
bool Ble::StopLegacyAdvertising(const std::string& input_service_id) {
LOG(INFO) << "StopLegacyAdvertising:" << input_service_id;
MutexLock lock(&mutex_);
@@ -384,16 +382,16 @@ bool BleV2::StopLegacyAdvertising(const std::string& input_service_id) {
return status.ok();
}
void BleV2::AddAlternateUuidForService(uint16_t uuid,
const std::string& service_id) {
void Ble::AddAlternateUuidForService(uint16_t uuid,
const std::string& service_id) {
MutexLock lock(&mutex_);
medium_.AddAlternateUuidForService(uuid, service_id);
}
ErrorOr<bool> BleV2::StartScanning(const std::string& service_id, Pcp pcp,
PowerLevel power_level,
bool include_dct_advertisement,
DiscoveredPeripheralCallback callback) {
ErrorOr<bool> Ble::StartScanning(const std::string& service_id, Pcp pcp,
PowerLevel power_level,
bool include_dct_advertisement,
DiscoveredPeripheralCallback callback) {
MutexLock lock(&mutex_);
if (service_id.empty()) {
@@ -446,7 +444,7 @@ ErrorOr<bool> BleV2::StartScanning(const std::string& service_id, Pcp pcp,
service_uuids, PowerLevelToTxPowerLevel(power_level),
{
.advertisement_found_cb =
[this](BleV2Peripheral peripheral,
[this](BlePeripheral peripheral,
BleAdvertisementData advertisement_data) {
RunOnBleThread([this, peripheral = std::move(peripheral),
advertisement_data]() {
@@ -454,8 +452,8 @@ ErrorOr<bool> BleV2::StartScanning(const std::string& service_id, Pcp pcp,
discovered_peripheral_tracker_
.ProcessFoundBleAdvertisement(
std::move(peripheral), advertisement_data,
[this](BleV2Peripheral peripheral,
int num_slots, int psm,
[this](BlePeripheral peripheral, int num_slots,
int psm,
const std::vector<std::string>&
interesting_service_ids,
mediums::AdvertisementReadResult&
@@ -487,7 +485,7 @@ ErrorOr<bool> BleV2::StartScanning(const std::string& service_id, Pcp pcp,
PowerLevelToTxPowerLevel(power_level),
{
.advertisement_found_cb =
[this](BleV2Peripheral peripheral,
[this](BlePeripheral peripheral,
BleAdvertisementData advertisement_data) {
RunOnBleThread([this, peripheral = std::move(peripheral),
advertisement_data]() {
@@ -495,8 +493,8 @@ ErrorOr<bool> BleV2::StartScanning(const std::string& service_id, Pcp pcp,
discovered_peripheral_tracker_
.ProcessFoundBleAdvertisement(
std::move(peripheral), advertisement_data,
[this](BleV2Peripheral peripheral,
int num_slots, int psm,
[this](BlePeripheral peripheral, int num_slots,
int psm,
const std::vector<std::string>&
interesting_service_ids,
mediums::AdvertisementReadResult&
@@ -540,7 +538,7 @@ ErrorOr<bool> BleV2::StartScanning(const std::string& service_id, Pcp pcp,
return {true};
}
bool BleV2::StopScanning(const std::string& service_id) {
bool Ble::StopScanning(const std::string& service_id) {
MutexLock lock(&mutex_);
if (FeatureFlags::GetInstance().GetFlags().enable_ble_v2_async_scanning) {
return StopAsyncScanningLocked(service_id);
@@ -570,23 +568,23 @@ bool BleV2::StopScanning(const std::string& service_id) {
return medium_.StopScanning();
}
bool BleV2::PauseMediumScanning() {
bool Ble::PauseMediumScanning() {
MutexLock lock(&mutex_);
return medium_.PauseMediumScanning();
}
bool BleV2::ResumeMediumScanning() {
bool Ble::ResumeMediumScanning() {
MutexLock lock(&mutex_);
return medium_.ResumeMediumScanning();
}
bool BleV2::IsScanning(const std::string& service_id) const {
bool Ble::IsScanning(const std::string& service_id) const {
MutexLock lock(&mutex_);
return IsScanningLocked(service_id);
}
ErrorOr<bool> BleV2::StartAcceptingConnections(
ErrorOr<bool> Ble::StartAcceptingConnections(
const std::string& service_id, AcceptedConnectionCallback callback) {
MutexLock lock(&mutex_);
@@ -616,7 +614,7 @@ ErrorOr<bool> BleV2::StartAcceptingConnections(
return {Error(OperationResultCode::MEDIUM_UNAVAILABLE_BLE_NOT_AVAILABLE)};
}
BleV2ServerSocket server_socket = medium_.OpenServerSocket(service_id);
BleServerSocket server_socket = medium_.OpenServerSocket(service_id);
if (!server_socket.IsValid()) {
LOG(ERROR)
<< "Failed to start accepting Ble GATT connections for service_id="
@@ -633,11 +631,10 @@ ErrorOr<bool> BleV2::StartAcceptingConnections(
// listening for new incoming connections until
// StopAcceptingL2capConnections() is invoked.
accept_loops_runner_.Execute(
"ble-accept",
[this, service_id, callback = std::move(callback),
server_socket = std::move(owned_server_socket)]() mutable {
"ble-accept", [this, service_id, callback = std::move(callback),
server_socket = std::move(owned_server_socket)]() mutable {
while (true) {
BleV2Socket client_socket = server_socket.Accept();
BleSocket client_socket = server_socket.Accept();
if (!client_socket.IsValid()) {
LOG(WARNING) << "The client Ble GATT socket to accept is invalid.";
server_socket.Close();
@@ -663,7 +660,7 @@ ErrorOr<bool> BleV2::StartAcceptingConnections(
}
// TODO(mingshiouwu): Add unit test for ble_l2cap flow
ErrorOr<int> BleV2::StartAcceptingL2capConnections(
ErrorOr<int> Ble::StartAcceptingL2capConnections(
const std::string& service_id, AcceptedL2capConnectionCallback callback) {
MutexLock lock(&mutex_);
if (service_id.empty()) {
@@ -746,7 +743,7 @@ ErrorOr<int> BleV2::StartAcceptingL2capConnections(
return {psm};
}
bool BleV2::StopAcceptingConnections(const std::string& service_id) {
bool Ble::StopAcceptingConnections(const std::string& service_id) {
MutexLock lock(&mutex_);
const auto it = server_sockets_.find(service_id);
@@ -765,7 +762,7 @@ bool BleV2::StopAcceptingConnections(const std::string& service_id) {
// Store a handle to the BleServerSocket, so we can use it after
// removing the entry from server_sockets_; making it scoped
// is a bonus that takes care of deallocation before we leave this method.
BleV2ServerSocket& listening_socket = item.mapped();
BleServerSocket& listening_socket = item.mapped();
// Regardless of whether or not we fail to close the existing
// BleServerSocket, remove it from server_sockets_ so that it
@@ -781,7 +778,7 @@ bool BleV2::StopAcceptingConnections(const std::string& service_id) {
return true;
}
bool BleV2::StopAcceptingL2capConnections(const std::string& service_id) {
bool Ble::StopAcceptingL2capConnections(const std::string& service_id) {
MutexLock lock(&mutex_);
const auto it = l2cap_server_sockets_.find(service_id);
@@ -816,22 +813,22 @@ bool BleV2::StopAcceptingL2capConnections(const std::string& service_id) {
return true;
}
bool BleV2::IsAcceptingConnections(const std::string& service_id) {
bool Ble::IsAcceptingConnections(const std::string& service_id) {
MutexLock lock(&mutex_);
return IsAcceptingConnectionsLocked(service_id);
}
bool BleV2::IsAcceptingL2capConnections(const std::string& service_id) {
bool Ble::IsAcceptingL2capConnections(const std::string& service_id) {
MutexLock lock(&mutex_);
return IsAcceptingL2capConnectionsLocked(service_id);
}
ErrorOr<BleV2Socket> BleV2::Connect(const std::string& service_id,
const BleV2Peripheral& peripheral,
CancellationFlag* cancellation_flag) {
ErrorOr<BleSocket> Ble::Connect(const std::string& service_id,
const BlePeripheral& peripheral,
CancellationFlag* cancellation_flag) {
MutexLock lock(&mutex_);
// Socket to return. To allow for NRVO to work, it has to be a single object.
BleV2Socket socket;
BleSocket socket;
if (service_id.empty()) {
LOG(INFO) << "Refusing to create client Ble socket because "
@@ -863,8 +860,8 @@ ErrorOr<BleV2Socket> BleV2::Connect(const std::string& service_id,
return socket;
}
ErrorOr<BleL2capSocket> BleV2::ConnectOverL2cap(
const std::string& service_id, const BleV2Peripheral& peripheral,
ErrorOr<BleL2capSocket> Ble::ConnectOverL2cap(
const std::string& service_id, const BlePeripheral& peripheral,
CancellationFlag* cancellation_flag) {
MutexLock lock(&mutex_);
@@ -900,18 +897,18 @@ ErrorOr<BleL2capSocket> BleV2::ConnectOverL2cap(
return socket;
}
bool BleV2::IsAvailableLocked() const { return medium_.IsValid(); }
bool Ble::IsAvailableLocked() const { return medium_.IsValid(); }
bool BleV2::IsAdvertisingLocked(const std::string& service_id) const {
bool Ble::IsAdvertisingLocked(const std::string& service_id) const {
return advertising_infos_.contains(service_id);
}
bool BleV2::IsAdvertisingForLegacyDeviceLocked(
bool Ble::IsAdvertisingForLegacyDeviceLocked(
const std::string& service_id) const {
return service_ids_to_advertising_sessions_.contains(service_id + "-Legacy");
}
bool BleV2::IsScanningLocked(const std::string& service_id) const {
bool Ble::IsScanningLocked(const std::string& service_id) const {
if (FeatureFlags::GetInstance().GetFlags().enable_ble_v2_async_scanning) {
// If using asynchronous scanning, check the corresponding map.
auto it = service_ids_to_scanning_sessions_.find(service_id);
@@ -920,19 +917,19 @@ bool BleV2::IsScanningLocked(const std::string& service_id) const {
return scanned_service_ids_.contains(service_id);
}
bool BleV2::IsAcceptingConnectionsLocked(const std::string& service_id) {
bool Ble::IsAcceptingConnectionsLocked(const std::string& service_id) {
return server_sockets_.contains(service_id);
}
bool BleV2::IsAcceptingL2capConnectionsLocked(const std::string& service_id) {
bool Ble::IsAcceptingL2capConnectionsLocked(const std::string& service_id) {
return l2cap_server_sockets_.contains(service_id);
}
bool BleV2::IsAdvertisementGattServerRunningLocked() {
bool Ble::IsAdvertisementGattServerRunningLocked() {
return gatt_server_ && gatt_server_->IsValid();
}
bool BleV2::StartAdvertisementGattServerLocked(
bool Ble::StartAdvertisementGattServerLocked(
const std::string& service_id, const ByteArray& gatt_advertisement) {
if (IsAdvertisementGattServerRunningLocked()) {
LOG(INFO) << "Advertisement GATT server is not started because one "
@@ -961,7 +958,7 @@ bool BleV2::StartAdvertisementGattServerLocked(
return true;
}
bool BleV2::GenerateAdvertisementCharacteristic(
bool Ble::GenerateAdvertisementCharacteristic(
int slot, const ByteArray& gatt_advertisement, GattServer& gatt_server) {
GattCharacteristic::Permission permission =
GattCharacteristic::Permission::kRead;
@@ -994,8 +991,8 @@ bool BleV2::GenerateAdvertisementCharacteristic(
return true;
}
void BleV2::ProcessFetchGattAdvertisementsRequest(
BleV2Peripheral peripheral, int num_slots, int psm,
void Ble::ProcessFetchGattAdvertisementsRequest(
BlePeripheral peripheral, int num_slots, int psm,
const std::vector<std::string>& interesting_service_ids,
mediums::AdvertisementReadResult& advertisement_read_result) {
if (!peripheral.IsValid()) {
@@ -1105,7 +1102,7 @@ void BleV2::ProcessFetchGattAdvertisementsRequest(
advertisement_read_result.RecordLastReadStatus(read_success);
}
bool BleV2::StopAdvertisementGattServerLocked() {
bool Ble::StopAdvertisementGattServerLocked() {
if (!IsAdvertisementGattServerRunningLocked()) {
VLOG(1) << "Unable to stop the advertisement GATT server because it's not "
"running.";
@@ -1116,7 +1113,7 @@ bool BleV2::StopAdvertisementGattServerLocked() {
return true;
}
ByteArray BleV2::CreateAdvertisementHeader(
ByteArray Ble::CreateAdvertisementHeader(
int psm, bool extended_advertisement_advertised) {
// Create a randomized dummy service id to anonymize the header with.
ByteArray dummy_service_id_bytes =
@@ -1150,8 +1147,7 @@ ByteArray BleV2::CreateAdvertisementHeader(
advertisement_hash, psm));
}
api::ble_v2::BleAdvertisementData
BleV2::CreateAdvertisingDataForLegacyDevice() {
api::ble::BleAdvertisementData Ble::CreateAdvertisingDataForLegacyDevice() {
BleAdvertisementData advertising_data;
advertising_data.is_extended_advertisement = false;
@@ -1163,7 +1159,7 @@ BleV2::CreateAdvertisingDataForLegacyDevice() {
return advertising_data;
}
bool BleV2::StartAdvertisingLocked(const std::string& service_id) {
bool Ble::StartAdvertisingLocked(const std::string& service_id) {
const auto it = advertising_infos_.find(service_id);
if (it == advertising_infos_.end()) {
LOG(WARNING) << "Failed to BLE advertise with service_id=" << service_id;
@@ -1180,7 +1176,7 @@ bool BleV2::StartAdvertisingLocked(const std::string& service_id) {
}
}
bool BleV2::StartFastAdvertisingLocked(
bool Ble::StartFastAdvertisingLocked(
const std::string& service_id, PowerLevel power_level,
const mediums::BleAdvertisement& medium_advertisement) {
// Begin building the fast BLE advertisement.
@@ -1221,7 +1217,7 @@ bool BleV2::StartFastAdvertisingLocked(
return true;
}
bool BleV2::StartRegularAdvertisingLocked(
bool Ble::StartRegularAdvertisingLocked(
const std::string& service_id, PowerLevel power_level,
const mediums::BleAdvertisement& medium_advertisement) {
// Begin building the regular BLE advertisement.
@@ -1269,7 +1265,7 @@ bool BleV2::StartRegularAdvertisingLocked(
return extended_regular_advertisement_success || gatt_advertisement_success;
}
bool BleV2::StartGattAdvertisingLocked(
bool Ble::StartGattAdvertisingLocked(
const std::string& service_id, PowerLevel power_level, int psm,
const ByteArray& medium_advertisement_bytes,
bool extended_advertisement_advertised) {
@@ -1349,9 +1345,9 @@ bool BleV2::StartGattAdvertisingLocked(
return true;
}
bool BleV2::StartDctAdvertisingLocked(const std::string& service_id,
PowerLevel power_level,
const ByteArray& dct_advertisement) {
bool Ble::StartDctAdvertisingLocked(const std::string& service_id,
PowerLevel power_level,
const ByteArray& dct_advertisement) {
BleAdvertisementData advertising_data;
advertising_data.is_extended_advertisement = false;
advertising_data.service_data.insert(
@@ -1363,8 +1359,8 @@ bool BleV2::StartDctAdvertisingLocked(const std::string& service_id,
.is_connectable = false});
}
bool BleV2::StartAsyncScanningLocked(absl::string_view service_id,
PowerLevel power_level) {
bool Ble::StartAsyncScanningLocked(absl::string_view service_id,
PowerLevel power_level) {
CHECK(FeatureFlags::GetInstance().GetFlags().enable_ble_v2_async_scanning);
// Use the asynchronous StartScanning method instead of the synchronous one.
@@ -1377,7 +1373,7 @@ bool BleV2::StartAsyncScanningLocked(absl::string_view service_id,
auto scanning_session = medium_.StartScanning(
mediums::bleutils::kCopresenceServiceUuid,
PowerLevelToTxPowerLevel(power_level),
api::ble_v2::BleMedium::ScanningCallback{
api::ble::BleMedium::ScanningCallback{
.start_scanning_result =
[this, &service_id](absl::Status status) mutable {
// The `mutex_` is already held here. Use
@@ -1389,27 +1385,27 @@ bool BleV2::StartAsyncScanningLocked(absl::string_view service_id,
// attempted to acquire the lock here I hit a deadlock.
AssumeHeld(mutex_);
if (status.ok()) {
LOG(INFO) << "BLE V2 async StartScanning started "
LOG(INFO) << "BLE async StartScanning started "
"successfully for service ID"
<< &service_id;
} else {
LOG(ERROR) << "BLE V2 async StartScanning "
LOG(ERROR) << "BLE async StartScanning "
"failed for service ID"
<< &service_id << ": " << status;
service_ids_to_scanning_sessions_.erase(service_id);
}
},
.advertisement_found_cb =
[this](api::ble_v2::BlePeripheral::UniqueId peripheral_id,
[this](api::ble::BlePeripheral::UniqueId peripheral_id,
BleAdvertisementData advertisement_data) {
AssumeHeld(mutex_);
BleV2Peripheral proxy(medium_, peripheral_id);
BlePeripheral proxy(medium_, peripheral_id);
RunOnBleThread([this, proxy = std::move(proxy),
advertisement_data]() {
MutexLock lock(&mutex_);
discovered_peripheral_tracker_.ProcessFoundBleAdvertisement(
std::move(proxy), advertisement_data,
[this](BleV2Peripheral proxy, int num_slots, int psm,
[this](BlePeripheral proxy, int num_slots, int psm,
const std::vector<std::string>&
interesting_service_ids,
mediums::AdvertisementReadResult&
@@ -1427,7 +1423,7 @@ bool BleV2::StartAsyncScanningLocked(absl::string_view service_id,
});
},
.advertisement_lost_cb =
[](api::ble_v2::BlePeripheral::UniqueId peripheral_id) {
[](api::ble::BlePeripheral::UniqueId peripheral_id) {
// TODO(b/345514862): Implement.
},
});
@@ -1457,7 +1453,7 @@ bool BleV2::StartAsyncScanningLocked(absl::string_view service_id,
return true;
}
bool BleV2::StopAsyncScanningLocked(absl::string_view service_id) {
bool Ble::StopAsyncScanningLocked(absl::string_view service_id) {
CHECK(FeatureFlags::GetInstance().GetFlags().enable_ble_v2_async_scanning);
// If using asynchronous scanning, check the corresponding map.
auto scanning_session = service_ids_to_scanning_sessions_.find(service_id);
@@ -1479,7 +1475,7 @@ bool BleV2::StopAsyncScanningLocked(absl::string_view service_id) {
return true;
}
TxPowerLevel BleV2::PowerLevelToTxPowerLevel(PowerLevel power_level) {
TxPowerLevel Ble::PowerLevelToTxPowerLevel(PowerLevel power_level) {
switch (power_level) {
case PowerLevel::kHighPower:
return TxPowerLevel::kHigh;
@@ -1492,7 +1488,7 @@ TxPowerLevel BleV2::PowerLevelToTxPowerLevel(PowerLevel power_level) {
}
}
void BleV2::RunOnBleThread(Runnable runnable) {
void Ble::RunOnBleThread(Runnable runnable) {
serial_executor_.Execute(std::move(runnable));
}
@@ -12,8 +12,8 @@
// See the License for the specific language governing permissions and
// limitations under the License.
#ifndef CORE_INTERNAL_MEDIUMS_BLE_V2_H_
#define CORE_INTERNAL_MEDIUMS_BLE_V2_H_
#ifndef CORE_INTERNAL_MEDIUMS_BLE_H_
#define CORE_INTERNAL_MEDIUMS_BLE_H_
#include <cstdint>
#include <memory>
@@ -27,21 +27,21 @@
#include "absl/container/flat_hash_set.h"
#include "absl/functional/any_invocable.h"
#include "absl/strings/string_view.h"
#include "connections/implementation/mediums/ble_v2/advertisement_read_result.h"
#include "connections/implementation/mediums/ble_v2/ble_advertisement.h"
#include "connections/implementation/mediums/ble_v2/discovered_peripheral_callback.h"
#include "connections/implementation/mediums/ble_v2/discovered_peripheral_tracker.h"
#include "connections/implementation/mediums/ble_v2/instant_on_lost_manager.h"
#include "connections/implementation/mediums/ble/advertisement_read_result.h"
#include "connections/implementation/mediums/ble/ble_advertisement.h"
#include "connections/implementation/mediums/ble/discovered_peripheral_callback.h"
#include "connections/implementation/mediums/ble/discovered_peripheral_tracker.h"
#include "connections/implementation/mediums/ble/instant_on_lost_manager.h"
#include "connections/implementation/mediums/bluetooth_radio.h"
#include "connections/implementation/pcp.h"
#include "connections/power_level.h"
#include "internal/platform/ble_v2.h"
#include "internal/platform/ble.h"
#include "internal/platform/bluetooth_adapter.h"
#include "internal/platform/byte_array.h"
#include "internal/platform/cancelable_alarm.h"
#include "internal/platform/cancellation_flag.h"
#include "internal/platform/expected.h"
#include "internal/platform/implementation/ble_v2.h"
#include "internal/platform/implementation/ble.h"
#include "internal/platform/multi_thread_executor.h"
#include "internal/platform/mutex.h"
#include "internal/platform/mutex_lock.h"
@@ -54,13 +54,13 @@ namespace connections {
// Provides the operations that can be performed on the Bluetooth Low Energy
// (BLE) medium.
class BleV2 final {
class Ble final {
public:
using DiscoveredPeripheralCallback = mediums::DiscoveredPeripheralCallback;
// Callback that is invoked when a new connection is accepted.
using AcceptedConnectionCallback = absl::AnyInvocable<void(
BleV2Socket socket, const std::string& service_id)>;
using AcceptedConnectionCallback =
absl::AnyInvocable<void(BleSocket socket, const std::string& service_id)>;
// Callback that is invoked when a new l2cap connection is accepted.
using AcceptedL2capConnectionCallback = absl::AnyInvocable<void(
@@ -74,8 +74,8 @@ class BleV2 final {
kDct = 2,
};
explicit BleV2(BluetoothRadio& bluetooth_radio);
~BleV2();
explicit Ble(BluetoothRadio& bluetooth_radio);
~Ble();
// Returns true, if BLE communications are supported by a platform.
bool IsAvailable() const ABSL_LOCKS_EXCLUDED(mutex_);
@@ -111,7 +111,7 @@ class BleV2 final {
const std::string& fast_advertisement_service_uuid)
ABSL_LOCKS_EXCLUDED(mutex_);
// (TODO:hais) update this after ble_v2 async api refactor.
// (TODO:hais) update this after ble async api refactor.
// Stop Ble advertising with dummy bytes for legacy device.
bool StopLegacyAdvertising(const std::string& service_id)
ABSL_LOCKS_EXCLUDED(mutex_);
@@ -184,15 +184,15 @@ class BleV2 final {
// Establishes connection to Ble peripheral.
// Returns socket instance. On success, BleSocket.IsValid() return true.
ErrorOr<BleV2Socket> Connect(const std::string& service_id,
const BleV2Peripheral& peripheral,
CancellationFlag* cancellation_flag)
ErrorOr<BleSocket> Connect(const std::string& service_id,
const BlePeripheral& peripheral,
CancellationFlag* cancellation_flag)
ABSL_LOCKS_EXCLUDED(mutex_);
// Establishes connection to Ble peripheral.
// Returns socket instance. On success, BleSocket.IsValid() return true.
ErrorOr<BleL2capSocket> ConnectOverL2cap(const std::string& service_id,
const BleV2Peripheral& peripheral,
const BlePeripheral& peripheral,
CancellationFlag* cancellation_flag)
ABSL_LOCKS_EXCLUDED(mutex_);
@@ -251,7 +251,7 @@ class BleV2 final {
GattServer& gatt_server)
ABSL_EXCLUSIVE_LOCKS_REQUIRED(mutex_);
void ProcessFetchGattAdvertisementsRequest(
BleV2Peripheral peripheral, int num_slots, int psm,
BlePeripheral peripheral, int num_slots, int psm,
const std::vector<std::string>& interesting_service_ids,
mediums::AdvertisementReadResult& advertisement_read_result)
ABSL_EXCLUSIVE_LOCKS_REQUIRED(mutex_);
@@ -261,7 +261,7 @@ class BleV2 final {
bool extended_advertisement_advertised)
ABSL_SHARED_LOCKS_REQUIRED(mutex_);
// For devices that don't have extended nor gatt adverting.
api::ble_v2::BleAdvertisementData CreateAdvertisingDataForLegacyDevice();
api::ble::BleAdvertisementData CreateAdvertisingDataForLegacyDevice();
bool StartAdvertisingLocked(const std::string& service_id)
ABSL_EXCLUSIVE_LOCKS_REQUIRED(mutex_);
bool StartFastAdvertisingLocked(
@@ -288,7 +288,7 @@ class BleV2 final {
// Called by StartScanning when using the async methods.
bool StopAsyncScanningLocked(absl::string_view service_id)
ABSL_EXCLUSIVE_LOCKS_REQUIRED(mutex_);
api::ble_v2::TxPowerLevel PowerLevelToTxPowerLevel(PowerLevel power_level);
api::ble::TxPowerLevel PowerLevelToTxPowerLevel(PowerLevel power_level);
void RunOnBleThread(Runnable runnable);
static constexpr int kMaxConcurrentAcceptLoops = 5;
@@ -299,24 +299,24 @@ class BleV2 final {
mutable Mutex mutex_;
BluetoothRadio& radio_ ABSL_GUARDED_BY(mutex_);
BluetoothAdapter& adapter_ ABSL_GUARDED_BY(mutex_);
BleV2Medium medium_ ABSL_GUARDED_BY(mutex_){adapter_};
BleMedium medium_ ABSL_GUARDED_BY(mutex_){adapter_};
absl::btree_map<std::string, AdvertisingInfo> advertising_infos_
ABSL_GUARDED_BY(mutex_);
std::unique_ptr<GattServer> gatt_server_ ABSL_GUARDED_BY(mutex_);
absl::flat_hash_map<int, std::pair<std::string, ByteArray>>
gatt_advertisements_ ABSL_GUARDED_BY(mutex_);
absl::flat_hash_set<api::ble_v2::GattCharacteristic>
hosted_gatt_characteristics_ ABSL_GUARDED_BY(mutex_);
absl::flat_hash_set<api::ble::GattCharacteristic> hosted_gatt_characteristics_
ABSL_GUARDED_BY(mutex_);
absl::flat_hash_set<std::string> scanned_service_ids_ ABSL_GUARDED_BY(mutex_);
// This map has the same purpose as the set above, but is used only by
// the async StartScanning method.
absl::flat_hash_map<std::string,
std::unique_ptr<api::ble_v2::BleMedium::ScanningSession>>
std::unique_ptr<api::ble::BleMedium::ScanningSession>>
service_ids_to_scanning_sessions_ ABSL_GUARDED_BY(mutex_);
// Save advertising sessions by service id, used by the async StartAdvertising
// method.
absl::flat_hash_map<
std::string, std::unique_ptr<api::ble_v2::BleMedium::AdvertisingSession>>
absl::flat_hash_map<std::string,
std::unique_ptr<api::ble::BleMedium::AdvertisingSession>>
service_ids_to_advertising_sessions_ ABSL_GUARDED_BY(mutex_);
std::unique_ptr<CancelableAlarm> lost_alarm_;
mediums::DiscoveredPeripheralTracker discovered_peripheral_tracker_
@@ -328,12 +328,12 @@ class BleV2 final {
// A map of service_id -> ServerSocket. If map is non-empty, we
// are currently listening for incoming connections.
absl::flat_hash_map<std::string, BleV2ServerSocket> server_sockets_
absl::flat_hash_map<std::string, BleServerSocket> server_sockets_
ABSL_GUARDED_BY(mutex_);
// Tracks currently connected incoming sockets. This lets the device know when
// it's okay to restart GATT server related operations.
absl::flat_hash_map<std::string, BleV2Socket> incoming_sockets_
absl::flat_hash_map<std::string, BleSocket> incoming_sockets_
ABSL_GUARDED_BY(mutex_);
mediums::InstantOnLostManager instant_on_lost_manager_;
@@ -353,4 +353,4 @@ class BleV2 final {
} // namespace connections
} // namespace nearby
#endif // CORE_INTERNAL_MEDIUMS_BLE_V2_H_
#endif // CORE_INTERNAL_MEDIUMS_BLE_H_
@@ -53,7 +53,7 @@ cc_library(
)
cc_library(
name = "ble_v2",
name = "ble",
srcs = [
"advertisement_read_result.cc",
"ble_advertisement.cc",
@@ -111,7 +111,7 @@ cc_library(
)
cc_test(
name = "ble_v2_test",
name = "ble_test",
srcs = [
"advertisement_read_result_test.cc",
"ble_advertisement_header_test.cc",
@@ -125,8 +125,8 @@ cc_test(
"instant_on_lost_manager_test.cc",
],
deps = [
":ble",
":ble_advertisement_header",
":ble_v2",
":bloom_filter",
"//connections/implementation:types",
"//connections/implementation/flags:connections_flags",
@@ -12,7 +12,7 @@
// See the License for the specific language governing permissions and
// limitations under the License.
#include "connections/implementation/mediums/ble_v2/advertisement_read_result.h"
#include "connections/implementation/mediums/ble/advertisement_read_result.h"
#include <algorithm>
#include <vector>
@@ -12,8 +12,8 @@
// See the License for the specific language governing permissions and
// limitations under the License.
#ifndef CORE_INTERNAL_MEDIUMS_BLE_V2_ADVERTISEMENT_READ_RESULT_H_
#define CORE_INTERNAL_MEDIUMS_BLE_V2_ADVERTISEMENT_READ_RESULT_H_
#ifndef CORE_INTERNAL_MEDIUMS_BLE_ADVERTISEMENT_READ_RESULT_H_
#define CORE_INTERNAL_MEDIUMS_BLE_ADVERTISEMENT_READ_RESULT_H_
#include <cstdint>
#include <vector>
@@ -119,4 +119,4 @@ class AdvertisementReadResult {
} // namespace connections
} // namespace nearby
#endif // CORE_INTERNAL_MEDIUMS_BLE_V2_ADVERTISEMENT_READ_RESULT_H_
#endif // CORE_INTERNAL_MEDIUMS_BLE_ADVERTISEMENT_READ_RESULT_H_
@@ -12,7 +12,7 @@
// See the License for the specific language governing permissions and
// limitations under the License.
#include "connections/implementation/mediums/ble_v2/advertisement_read_result.h"
#include "connections/implementation/mediums/ble/advertisement_read_result.h"
#include "gtest/gtest.h"
#include "absl/time/clock.h"
@@ -12,7 +12,7 @@
// See the License for the specific language governing permissions and
// limitations under the License.
#include "connections/implementation/mediums/ble_v2/ble_advertisement.h"
#include "connections/implementation/mediums/ble/ble_advertisement.h"
#include <cstddef>
#include <cstdint>
@@ -23,7 +23,7 @@
#include "absl/status/status.h"
#include "absl/status/statusor.h"
#include "absl/strings/str_cat.h"
#include "connections/implementation/mediums/ble_v2/ble_advertisement_header.h"
#include "connections/implementation/mediums/ble/ble_advertisement_header.h"
#include "internal/platform/byte_array.h"
#include "internal/platform/logging.h"
#include "internal/platform/stream_reader.h"
@@ -46,18 +46,18 @@ bool HasField(uint8_t field_mask, uint8_t psm_bit) {
BleAdvertisement::BleAdvertisement(Version version,
SocketVersion socket_version,
const ByteArray &service_id_hash,
const ByteArray &data,
const ByteArray &device_token, int psm) {
const ByteArray& service_id_hash,
const ByteArray& data,
const ByteArray& device_token, int psm) {
DoInitialize(/*fast_advertisement=*/service_id_hash.Empty(), version,
socket_version, service_id_hash, data, device_token, psm);
}
void BleAdvertisement::DoInitialize(bool fast_advertisement, Version version,
SocketVersion socket_version,
const ByteArray &service_id_hash,
const ByteArray &data,
const ByteArray &device_token, int psm) {
const ByteArray& service_id_hash,
const ByteArray& data,
const ByteArray& device_token, int psm) {
// Check that the given input is valid.
fast_advertisement_ = fast_advertisement;
if (!fast_advertisement_) {
@@ -87,7 +87,7 @@ void BleAdvertisement::DoInitialize(bool fast_advertisement, Version version,
}
absl::StatusOr<BleAdvertisement> BleAdvertisement::CreateBleAdvertisement(
const ByteArray &ble_advertisement_bytes) {
const ByteArray& ble_advertisement_bytes) {
if (ble_advertisement_bytes.Empty()) {
return absl::InvalidArgumentError(
"Cannot deserialize BleAdvertisement: null bytes passed in.");
@@ -277,7 +277,7 @@ ByteArray BleAdvertisement::ByteArrayWithExtraField() const {
return ByteArray(std::move(advertisement_with_extra_fields_bytes));
}
bool BleAdvertisement::operator==(const BleAdvertisement &rhs) const {
bool BleAdvertisement::operator==(const BleAdvertisement& rhs) const {
return this->GetVersion() == rhs.GetVersion() &&
this->GetSocketVersion() == rhs.GetSocketVersion() &&
this->IsFastAdvertisement() == rhs.IsFastAdvertisement() &&
@@ -298,11 +298,11 @@ bool BleAdvertisement::IsSupportedSocketVersion(SocketVersion socket_version) {
}
BleAdvertisement::BleExtraFields::BleExtraFields(
int psm, const ByteArray &rx_instant_connection_adv)
int psm, const ByteArray& rx_instant_connection_adv)
: psm_(psm), rx_instant_connection_adv_(rx_instant_connection_adv) {}
BleAdvertisement::BleExtraFields::BleExtraFields(
const ByteArray &ble_extra_fields_bytes) {
const ByteArray& ble_extra_fields_bytes) {
if (ble_extra_fields_bytes.Empty()) {
return;
}
@@ -12,8 +12,8 @@
// See the License for the specific language governing permissions and
// limitations under the License.
#ifndef CORE_INTERNAL_MEDIUMS_BLE_V2_BLE_ADVERTISEMENT_H_
#define CORE_INTERNAL_MEDIUMS_BLE_V2_BLE_ADVERTISEMENT_H_
#ifndef CORE_INTERNAL_MEDIUMS_BLE_BLE_ADVERTISEMENT_H_
#define CORE_INTERNAL_MEDIUMS_BLE_BLE_ADVERTISEMENT_H_
#include <string>
#include <utility>
@@ -21,7 +21,7 @@
#include "absl/status/statusor.h"
#include "absl/strings/escaping.h"
#include "absl/strings/str_format.h"
#include "connections/implementation/mediums/ble_v2/ble_advertisement_header.h"
#include "connections/implementation/mediums/ble/ble_advertisement_header.h"
#include "internal/platform/byte_array.h"
namespace nearby {
@@ -83,9 +83,9 @@ class BleAdvertisement {
static constexpr int kMaxFastAdvertisementLength = 27;
static constexpr int kExtraFieldsMaskLength = 1;
// Hashable
bool operator==(const BleAdvertisement &rhs) const;
bool operator==(const BleAdvertisement& rhs) const;
template <typename H>
friend H AbslHashValue(H h, const BleAdvertisement &b) {
friend H AbslHashValue(H h, const BleAdvertisement& b) {
return H::combine(std::move(h), b.version_, b.socket_version_,
b.fast_advertisement_, b.service_id_hash_, b.data_,
b.device_token_, b.psm_);
@@ -93,16 +93,16 @@ class BleAdvertisement {
BleAdvertisement() = default;
BleAdvertisement(Version version, SocketVersion socket_version,
const ByteArray &service_id_hash, const ByteArray &data,
const ByteArray &device_token,
const ByteArray& service_id_hash, const ByteArray& data,
const ByteArray& device_token,
int psm = BleAdvertisementHeader::kDefaultPsmValue);
static absl::StatusOr<BleAdvertisement> CreateBleAdvertisement(
const ByteArray &ble_advertisement_bytes);
BleAdvertisement(const BleAdvertisement &) = default;
BleAdvertisement &operator=(const BleAdvertisement &) = default;
BleAdvertisement(BleAdvertisement &&) = default;
BleAdvertisement &operator=(BleAdvertisement &&) = default;
const ByteArray& ble_advertisement_bytes);
BleAdvertisement(const BleAdvertisement&) = default;
BleAdvertisement& operator=(const BleAdvertisement&) = default;
BleAdvertisement(BleAdvertisement&&) = default;
BleAdvertisement& operator=(BleAdvertisement&&) = default;
~BleAdvertisement() = default;
// Returns ByteArray for legacy advertisement.
@@ -117,17 +117,17 @@ class BleAdvertisement {
bool IsFastAdvertisement() const { return fast_advertisement_; }
bool IsSecondProfile() const { return is_second_profile_; }
ByteArray GetServiceIdHash() const { return service_id_hash_; }
ByteArray &GetData() & { return data_; }
const ByteArray &GetData() const & { return data_; }
ByteArray &&GetData() && { return std::move(data_); }
const ByteArray &&GetData() const && { return std::move(data_); }
ByteArray& GetData() & { return data_; }
const ByteArray& GetData() const& { return data_; }
ByteArray&& GetData() && { return std::move(data_); }
const ByteArray&& GetData() const&& { return std::move(data_); }
ByteArray GetDeviceToken() const { return device_token_; }
int GetPsm() const { return psm_; }
void SetPsm(int psm) { psm_ = psm; }
ByteArray GetRxInstantConnectionAdv() const {
return rx_instant_connection_adv_;
}
void SetRxInstantConnectionAdv(const ByteArray &rx_instant_connection_adv) {
void SetRxInstantConnectionAdv(const ByteArray& rx_instant_connection_adv) {
rx_instant_connection_adv_ = rx_instant_connection_adv;
}
std::string ToReadableString() const {
@@ -161,8 +161,8 @@ class BleAdvertisement {
static constexpr int kRxInstantConnectionAdvSizeLength = 1;
explicit BleExtraFields(int psm,
const ByteArray &rx_instant_connection_adv);
explicit BleExtraFields(const ByteArray &ble_extra_fields_bytes);
const ByteArray& rx_instant_connection_adv);
explicit BleExtraFields(const ByteArray& ble_extra_fields_bytes);
explicit operator ByteArray() const;
int GetPsm() const { return psm_; }
@@ -178,8 +178,8 @@ class BleAdvertisement {
void DoInitialize(bool fast_advertisement, Version version,
SocketVersion socket_version,
const ByteArray &service_id_hash, const ByteArray &data,
const ByteArray &device_token, int psm);
const ByteArray& service_id_hash, const ByteArray& data,
const ByteArray& device_token, int psm);
static bool IsSupportedVersion(Version version);
static bool IsSupportedSocketVersion(SocketVersion socket_version);
int ComputeAdvertisementLength(int data_length, int total_optional_length,
@@ -207,4 +207,4 @@ class BleAdvertisement {
} // namespace connections
} // namespace nearby
#endif // CORE_INTERNAL_MEDIUMS_BLE_V2_BLE_ADVERTISEMENT_H_
#endif // CORE_INTERNAL_MEDIUMS_BLE_BLE_ADVERTISEMENT_H_
@@ -12,7 +12,7 @@
// See the License for the specific language governing permissions and
// limitations under the License.
#include "connections/implementation/mediums/ble_v2/ble_advertisement_header.h"
#include "connections/implementation/mediums/ble/ble_advertisement_header.h"
#include <string>
#include <utility>
@@ -12,8 +12,8 @@
// See the License for the specific language governing permissions and
// limitations under the License.
#ifndef CORE_INTERNAL_MEDIUMS_BLE_V2_BLE_ADVERTISEMENT_HEADER_H_
#define CORE_INTERNAL_MEDIUMS_BLE_V2_BLE_ADVERTISEMENT_HEADER_H_
#ifndef CORE_INTERNAL_MEDIUMS_BLE_BLE_ADVERTISEMENT_HEADER_H_
#define CORE_INTERNAL_MEDIUMS_BLE_BLE_ADVERTISEMENT_HEADER_H_
#include <string>
@@ -56,9 +56,9 @@ class BleAdvertisementHeader {
static constexpr int kPsmValueByteLength = 2;
// Hashable
bool operator==(const BleAdvertisementHeader &rhs) const;
bool operator==(const BleAdvertisementHeader& rhs) const;
template <typename H>
friend H AbslHashValue(H h, const BleAdvertisementHeader &b) {
friend H AbslHashValue(H h, const BleAdvertisementHeader& b) {
return H::combine(std::move(h), b.version_,
b.support_extended_advertisement_, b.num_slots_,
b.service_id_bloom_filter_, b.advertisement_hash_,
@@ -68,14 +68,14 @@ class BleAdvertisementHeader {
BleAdvertisementHeader() = default;
BleAdvertisementHeader(Version version, bool support_extended_advertisement,
int num_slots,
const ByteArray &service_id_bloom_filter,
const ByteArray &advertisement_hash, int psm);
const ByteArray& service_id_bloom_filter,
const ByteArray& advertisement_hash, int psm);
explicit BleAdvertisementHeader(
const ByteArray &ble_advertisement_header_bytes);
BleAdvertisementHeader(const BleAdvertisementHeader &) = default;
BleAdvertisementHeader &operator=(const BleAdvertisementHeader &) = default;
BleAdvertisementHeader(BleAdvertisementHeader &&) = default;
BleAdvertisementHeader &operator=(BleAdvertisementHeader &&) = default;
const ByteArray& ble_advertisement_header_bytes);
BleAdvertisementHeader(const BleAdvertisementHeader&) = default;
BleAdvertisementHeader& operator=(const BleAdvertisementHeader&) = default;
BleAdvertisementHeader(BleAdvertisementHeader&&) = default;
BleAdvertisementHeader& operator=(BleAdvertisementHeader&&) = default;
~BleAdvertisementHeader() = default;
explicit operator ByteArray() const;
@@ -112,4 +112,4 @@ class BleAdvertisementHeader {
} // namespace connections
} // namespace nearby
#endif // CORE_INTERNAL_MEDIUMS_BLE_V2_BLE_ADVERTISEMENT_HEADER_H_
#endif // CORE_INTERNAL_MEDIUMS_BLE_BLE_ADVERTISEMENT_HEADER_H_
@@ -12,7 +12,7 @@
// See the License for the specific language governing permissions and
// limitations under the License.
#include "connections/implementation/mediums/ble_v2/ble_advertisement_header.h"
#include "connections/implementation/mediums/ble/ble_advertisement_header.h"
#include <string>
@@ -12,7 +12,7 @@
// See the License for the specific language governing permissions and
// limitations under the License.
#include "connections/implementation/mediums/ble_v2/ble_advertisement.h"
#include "connections/implementation/mediums/ble/ble_advertisement.h"
#include <algorithm>
#include <cstddef>
@@ -26,7 +26,7 @@
#include "absl/status/status.h"
#include "absl/status/statusor.h"
#include "absl/strings/string_view.h"
#include "connections/implementation/mediums/ble_v2/ble_advertisement_header.h"
#include "connections/implementation/mediums/ble/ble_advertisement_header.h"
#include "internal/platform/byte_array.h"
namespace nearby {
@@ -12,7 +12,7 @@
// See the License for the specific language governing permissions and
// limitations under the License.
#include "connections/implementation/mediums/ble_v2/ble_l2cap_packet.h"
#include "connections/implementation/mediums/ble/ble_l2cap_packet.h"
#include <string>
#include <utility>
@@ -20,7 +20,7 @@
#include "absl/status/status.h"
#include "absl/status/statusor.h"
#include "absl/strings/str_cat.h"
#include "connections/implementation/mediums/ble_v2/ble_advertisement.h"
#include "connections/implementation/mediums/ble/ble_advertisement.h"
#include "connections/implementation/mediums/utils.h"
#include "internal/platform/byte_array.h"
#include "internal/platform/logging.h"
@@ -12,13 +12,13 @@
// See the License for the specific language governing permissions and
// limitations under the License.
#ifndef CORE_INTERNAL_MEDIUMS_BLE_V2_BLE_L2CAP_PACKET_H_
#define CORE_INTERNAL_MEDIUMS_BLE_V2_BLE_L2CAP_PACKET_H_
#ifndef CORE_INTERNAL_MEDIUMS_BLE_BLE_L2CAP_PACKET_H_
#define CORE_INTERNAL_MEDIUMS_BLE_BLE_L2CAP_PACKET_H_
#include <string>
#include "absl/status/statusor.h"
#include "connections/implementation/mediums/ble_v2/ble_advertisement.h"
#include "connections/implementation/mediums/ble/ble_advertisement.h"
#include "internal/platform/byte_array.h"
namespace nearby {
@@ -132,4 +132,4 @@ class BleL2capPacket {
} // namespace connections
} // namespace nearby
#endif // CORE_INTERNAL_MEDIUMS_BLE_V2_BLE_L2CAP_PACKET_H_
#endif // CORE_INTERNAL_MEDIUMS_BLE_BLE_L2CAP_PACKET_H_
@@ -12,7 +12,7 @@
// See the License for the specific language governing permissions and
// limitations under the License.
#include "connections/implementation/mediums/ble_v2/ble_l2cap_packet.h"
#include "connections/implementation/mediums/ble/ble_l2cap_packet.h"
#include <string>
@@ -140,7 +140,7 @@ TEST(BleL2capPacketTest, CreateFromBytesWithInvalidCommand) {
TEST(BleL2capPacketTest, CreateFromBytesWithoutDataLength) {
ByteArray byte_array{1};
char *byte_array_data = byte_array.data();
char* byte_array_data = byte_array.data();
byte_array_data[0] =
static_cast<char>(BleL2capPacket::Command::kRequestAdvertisement);
@@ -150,7 +150,7 @@ TEST(BleL2capPacketTest, CreateFromBytesWithoutDataLength) {
TEST(BleL2capPacketTest, CreateFromBytesWithEmptyDataLength) {
ByteArray byte_array{3};
char *byte_array_data = byte_array.data();
char* byte_array_data = byte_array.data();
byte_array_data[0] =
static_cast<char>(BleL2capPacket::Command::kRequestAdvertisement);
byte_array_data[1] = 0x00;
@@ -162,7 +162,7 @@ TEST(BleL2capPacketTest, CreateFromBytesWithEmptyDataLength) {
TEST(BleL2capPacketTest, CreateFromBytesWithInvalidServiceIdHashLength) {
ByteArray byte_array{3};
char *byte_array_data = byte_array.data();
char* byte_array_data = byte_array.data();
byte_array_data[0] =
static_cast<char>(BleL2capPacket::Command::kRequestAdvertisement);
byte_array_data[1] = 0x00;
@@ -174,7 +174,7 @@ TEST(BleL2capPacketTest, CreateFromBytesWithInvalidServiceIdHashLength) {
TEST(BleL2capPacketTest, CreateFromBytesWithTooLongAdvertisementLength) {
ByteArray byte_array{3};
char *byte_array_data = byte_array.data();
char* byte_array_data = byte_array.data();
byte_array_data[0] =
static_cast<char>(BleL2capPacket::Command::kResponseAdvertisement);
byte_array_data[1] = 0xFF;
@@ -186,7 +186,7 @@ TEST(BleL2capPacketTest, CreateFromBytesWithTooLongAdvertisementLength) {
TEST(BleL2capPacketTest, CreateFromBytesWithInvalidLengthAdvertisement) {
ByteArray byte_array{4};
char *byte_array_data = byte_array.data();
char* byte_array_data = byte_array.data();
byte_array_data[0] =
static_cast<char>(BleL2capPacket::Command::kResponseAdvertisement);
byte_array_data[1] = 0x00;
@@ -12,7 +12,7 @@
// See the License for the specific language governing permissions and
// limitations under the License.
#include "connections/implementation/mediums/ble_v2/ble_packet.h"
#include "connections/implementation/mediums/ble/ble_packet.h"
#include <cstdint>
#include <limits>
@@ -12,8 +12,8 @@
// See the License for the specific language governing permissions and
// limitations under the License.
#ifndef CORE_INTERNAL_MEDIUMS_BLE_V2_BLE_PACKET_H_
#define CORE_INTERNAL_MEDIUMS_BLE_V2_BLE_PACKET_H_
#ifndef CORE_INTERNAL_MEDIUMS_BLE_BLE_PACKET_H_
#define CORE_INTERNAL_MEDIUMS_BLE_BLE_PACKET_H_
#include "absl/status/statusor.h"
#include "internal/platform/byte_array.h"
@@ -105,4 +105,4 @@ class BlePacket {
} // namespace connections
} // namespace nearby
#endif // CORE_INTERNAL_MEDIUMS_BLE_V2_BLE_PACKET_H_
#endif // CORE_INTERNAL_MEDIUMS_BLE_BLE_PACKET_H_
@@ -12,7 +12,7 @@
// See the License for the specific language governing permissions and
// limitations under the License.
#include "connections/implementation/mediums/ble_v2/ble_packet.h"
#include "connections/implementation/mediums/ble/ble_packet.h"
#include <algorithm>
#include <string>
@@ -12,7 +12,7 @@
// See the License for the specific language governing permissions and
// limitations under the License.
#include "connections/implementation/mediums/ble_v2/ble_utils.h"
#include "connections/implementation/mediums/ble/ble_utils.h"
#include <cstddef>
#include <cstdint>
@@ -22,9 +22,9 @@
#include "absl/base/attributes.h"
#include "absl/strings/str_cat.h"
#include "absl/strings/str_format.h"
#include "connections/implementation/mediums/ble_v2/ble_advertisement.h"
#include "connections/implementation/mediums/ble_v2/ble_advertisement_header.h"
#include "connections/implementation/mediums/ble_v2/ble_packet.h"
#include "connections/implementation/mediums/ble/ble_advertisement.h"
#include "connections/implementation/mediums/ble/ble_advertisement_header.h"
#include "connections/implementation/mediums/ble/ble_packet.h"
#include "connections/implementation/mediums/utils.h"
#include "internal/platform/byte_array.h"
#include "internal/platform/prng.h"
@@ -12,15 +12,15 @@
// See the License for the specific language governing permissions and
// limitations under the License.
#ifndef CORE_INTERNAL_MEDIUMS_BLE_V2_UTILS_H_
#define CORE_INTERNAL_MEDIUMS_BLE_V2_UTILS_H_
#ifndef CORE_INTERNAL_MEDIUMS_BLE_UTILS_H_
#define CORE_INTERNAL_MEDIUMS_BLE_UTILS_H_
#include <cstddef>
#include <optional>
#include <string>
#include "absl/base/attributes.h"
#include "connections/implementation/mediums/ble_v2//ble_advertisement.h"
#include "connections/implementation/mediums/ble//ble_advertisement.h"
#include "internal/platform/byte_array.h"
#include "internal/platform/uuid.h"
@@ -68,4 +68,4 @@ std::optional<Uuid> GenerateAdvertisementUuid(int slot);
} // namespace connections
} // namespace nearby
#endif // CORE_INTERNAL_MEDIUMS_BLE_V2_UTILS_H_
#endif // CORE_INTERNAL_MEDIUMS_BLE_UTILS_H_
@@ -12,7 +12,7 @@
// See the License for the specific language governing permissions and
// limitations under the License.
#include "connections/implementation/mediums/ble_v2/ble_utils.h"
#include "connections/implementation/mediums/ble/ble_utils.h"
#include <optional>
#include <string>
@@ -12,7 +12,7 @@
// See the License for the specific language governing permissions and
// limitations under the License.
#include "connections/implementation/mediums/ble_v2/bloom_filter.h"
#include "connections/implementation/mediums/ble/bloom_filter.h"
#include "absl/numeric/int128.h"
#include "absl/strings/numbers.h"
@@ -12,8 +12,8 @@
// See the License for the specific language governing permissions and
// limitations under the License.
#ifndef CORE_INTERNAL_MEDIUMS_BLE_V2_BLOOM_FILTER_H_
#define CORE_INTERNAL_MEDIUMS_BLE_V2_BLOOM_FILTER_H_
#ifndef CORE_INTERNAL_MEDIUMS_BLE_BLOOM_FILTER_H_
#define CORE_INTERNAL_MEDIUMS_BLE_BLOOM_FILTER_H_
#include <bitset>
#include <vector>
@@ -96,4 +96,4 @@ class BitSetImpl final : public BitSet {
} // namespace connections
} // namespace nearby
#endif // CORE_INTERNAL_MEDIUMS_BLE_V2_BLOOM_FILTER_H_
#endif // CORE_INTERNAL_MEDIUMS_BLE_BLOOM_FILTER_H_
@@ -12,7 +12,7 @@
// See the License for the specific language governing permissions and
// limitations under the License.
#include "connections/implementation/mediums/ble_v2/bloom_filter.h"
#include "connections/implementation/mediums/ble/bloom_filter.h"
#include <algorithm>
@@ -12,13 +12,13 @@
// See the License for the specific language governing permissions and
// limitations under the License.
#ifndef CORE_INTERNAL_MEDIUMS_BLE_V2_DISCOVERED_PERIPHERAL_CALLBACK_H_
#define CORE_INTERNAL_MEDIUMS_BLE_V2_DISCOVERED_PERIPHERAL_CALLBACK_H_
#ifndef CORE_INTERNAL_MEDIUMS_BLE_DISCOVERED_PERIPHERAL_CALLBACK_H_
#define CORE_INTERNAL_MEDIUMS_BLE_DISCOVERED_PERIPHERAL_CALLBACK_H_
#include <string>
#include "absl/functional/any_invocable.h"
#include "internal/platform/ble_v2.h"
#include "internal/platform/ble.h"
#include "internal/platform/byte_array.h"
namespace nearby {
@@ -28,20 +28,20 @@ namespace mediums {
// Callback that is invoked when a {@link BlePeripheral} is discovered.
struct DiscoveredPeripheralCallback {
absl::AnyInvocable<void(
BleV2Peripheral peripheral, const std::string& service_id,
BlePeripheral peripheral, const std::string& service_id,
const ByteArray& advertisement_bytes, bool fast_advertisement)>
peripheral_discovered_cb =
[](BleV2Peripheral, const std::string&, const ByteArray&, bool) {};
[](BlePeripheral, const std::string&, const ByteArray&, bool) {};
absl::AnyInvocable<void(
BleV2Peripheral peripheral, const std::string& service_id,
BlePeripheral peripheral, const std::string& service_id,
const ByteArray& advertisement_bytes, bool fast_advertisement)>
peripheral_lost_cb =
[](BleV2Peripheral, const std::string&, const ByteArray&, bool) {};
[](BlePeripheral, const std::string&, const ByteArray&, bool) {};
absl::AnyInvocable<void(
BleV2Peripheral peripheral, const std::string& service_id,
BlePeripheral peripheral, const std::string& service_id,
const ByteArray& advertisement_bytes, bool fast_advertisement)>
instant_lost_cb =
[](BleV2Peripheral, const std::string&, const ByteArray&, bool) {};
[](BlePeripheral, const std::string&, const ByteArray&, bool) {};
absl::AnyInvocable<void(void)> legacy_device_discovered_cb = []() {};
};
@@ -49,4 +49,4 @@ struct DiscoveredPeripheralCallback {
} // namespace connections
} // namespace nearby
#endif // CORE_INTERNAL_MEDIUMS_BLE_V2_DISCOVERED_PERIPHERAL_CALLBACK_H_
#endif // CORE_INTERNAL_MEDIUMS_BLE_DISCOVERED_PERIPHERAL_CALLBACK_H_
@@ -12,7 +12,7 @@
// See the License for the specific language governing permissions and
// limitations under the License.
#include "connections/implementation/mediums/ble_v2/discovered_peripheral_tracker.h"
#include "connections/implementation/mediums/ble/discovered_peripheral_tracker.h"
#include <algorithm>
#include <iterator>
@@ -30,28 +30,28 @@
#include "connections/implementation/flags/nearby_connections_feature_flags.h"
#include "connections/implementation/mediums/advertisements/advertisement_util.h"
#include "connections/implementation/mediums/advertisements/dct_advertisement.h"
#include "connections/implementation/mediums/ble_v2/advertisement_read_result.h"
#include "connections/implementation/mediums/ble_v2/ble_advertisement.h"
#include "connections/implementation/mediums/ble_v2/ble_advertisement_header.h"
#include "connections/implementation/mediums/ble_v2/ble_utils.h"
#include "connections/implementation/mediums/ble_v2/bloom_filter.h"
#include "connections/implementation/mediums/ble_v2/discovered_peripheral_callback.h"
#include "connections/implementation/mediums/ble_v2/instant_on_lost_advertisement.h"
#include "connections/implementation/mediums/ble/advertisement_read_result.h"
#include "connections/implementation/mediums/ble/ble_advertisement.h"
#include "connections/implementation/mediums/ble/ble_advertisement_header.h"
#include "connections/implementation/mediums/ble/ble_utils.h"
#include "connections/implementation/mediums/ble/bloom_filter.h"
#include "connections/implementation/mediums/ble/discovered_peripheral_callback.h"
#include "connections/implementation/mediums/ble/instant_on_lost_advertisement.h"
#include "connections/implementation/mediums/lost_entity_tracker.h"
#include "connections/implementation/pcp.h"
#include "connections/implementation/webrtc_state.h"
#include "internal/flags/nearby_flags.h"
#include "internal/platform/ble_v2.h"
#include "internal/platform/ble.h"
#include "internal/platform/byte_array.h"
#include "internal/platform/feature_flags.h"
#include "internal/platform/implementation/ble_v2.h"
#include "internal/platform/implementation/ble.h"
#include "internal/platform/implementation/system_clock.h"
#include "internal/platform/logging.h"
#include "internal/platform/multi_thread_executor.h"
#include "internal/platform/mutex_lock.h"
#include "internal/platform/uuid.h"
using ::nearby::api::ble_v2::BleAdvertisementData;
using ::nearby::api::ble::BleAdvertisementData;
namespace nearby {
namespace connections {
@@ -163,7 +163,7 @@ void DiscoveredPeripheralTracker::StopTracking(const std::string& service_id) {
}
void DiscoveredPeripheralTracker::ProcessFoundBleAdvertisement(
BleV2Peripheral peripheral, BleAdvertisementData advertisement_data,
BlePeripheral peripheral, BleAdvertisementData advertisement_data,
AdvertisementFetcher advertisement_fetcher) {
MutexLock lock(&mutex_);
@@ -245,7 +245,7 @@ bool DiscoveredPeripheralTracker::HandleOnLostAdvertisementLocked(
// Need to report OnLost for each gatt_advertisement.
for (const auto& gatt_advertisement : gatt_advertisements) {
BleV2Peripheral lost_peripheral = it.second.peripheral;
BlePeripheral lost_peripheral = it.second.peripheral;
lost_peripheral.SetId(ByteArray(gatt_advertisement));
if (gatt_advertisement.IsValid()) {
if (NearbyFlags::GetInstance().GetBoolFlag(
@@ -293,7 +293,7 @@ void DiscoveredPeripheralTracker::ProcessLostGattAdvertisements() {
for (const auto& gatt_advertisement : lost_gatt_advertisements) {
const auto it = gatt_advertisement_infos_.find(gatt_advertisement);
if (it != gatt_advertisement_infos_.end()) {
BleV2Peripheral lost_peripheral = it->second.peripheral;
BlePeripheral lost_peripheral = it->second.peripheral;
if (lost_peripheral.IsValid()) {
lost_peripheral.SetId(ByteArray(gatt_advertisement));
service_id_info.discovered_peripheral_callback.peripheral_lost_cb(
@@ -326,7 +326,7 @@ void DiscoveredPeripheralTracker::ClearDataForServiceId(
}
bool DiscoveredPeripheralTracker::IsSkippableGattAdvertisement(
const api::ble_v2::BleAdvertisementData& advertisement_data) {
const api::ble::BleAdvertisementData& advertisement_data) {
if (!is_extended_advertisement_available_) {
// Don't skip any advertisement if the scanner doesn't support extended
// advertisement.
@@ -384,8 +384,8 @@ void DiscoveredPeripheralTracker::ClearGattAdvertisement(
}
void DiscoveredPeripheralTracker::HandleAdvertisement(
BleV2Peripheral peripheral,
const nearby::api::ble_v2::BleAdvertisementData& advertisement_data) {
BlePeripheral peripheral,
const nearby::api::ble::BleAdvertisementData& advertisement_data) {
ByteArray advertisement_bytes =
ExtractInterestingAdvertisementBytes(advertisement_data);
if (advertisement_bytes.Empty()) {
@@ -430,7 +430,7 @@ void DiscoveredPeripheralTracker::HandleAdvertisement(
}
ByteArray DiscoveredPeripheralTracker::ExtractInterestingAdvertisementBytes(
const nearby::api::ble_v2::BleAdvertisementData& advertisement_data) {
const nearby::api::ble::BleAdvertisementData& advertisement_data) {
// Iterate through all tracked service IDs to see if any of their fast
// advertisements are contained within this BLE advertisement.
for (const auto& item : service_id_infos_) {
@@ -463,7 +463,7 @@ BleAdvertisementHeader DiscoveredPeripheralTracker::CreateAdvertisementHeader(
}
BleAdvertisementHeader DiscoveredPeripheralTracker::HandleRawGattAdvertisements(
BleV2Peripheral peripheral,
BlePeripheral peripheral,
const BleAdvertisementHeader& advertisement_header,
const std::vector<const ByteArray*>& gatt_advertisement_bytes_list,
const Uuid& service_uuid) {
@@ -511,7 +511,7 @@ BleAdvertisementHeader DiscoveredPeripheralTracker::HandleRawGattAdvertisements(
}
if (peripheral.IsValid()) {
peripheral.SetPsm(new_psm);
BleV2Peripheral discovered_peripheral = peripheral;
BlePeripheral discovered_peripheral = peripheral;
discovered_peripheral.SetId(ByteArray(gatt_advertisement));
if (IsInstantLostAdvertisement(new_advertisement_header)) {
@@ -733,8 +733,8 @@ DiscoveredPeripheralTracker::HandleDctAdvertisement(
}
void DiscoveredPeripheralTracker::HandleAdvertisementHeader(
BleV2Peripheral peripheral,
const nearby::api::ble_v2::BleAdvertisementData& advertisement_data,
BlePeripheral peripheral,
const nearby::api::ble::BleAdvertisementData& advertisement_data,
AdvertisementFetcher advertisement_fetcher) {
// Attempt to parse the advertisement header.
BleAdvertisementHeader advertisement_header(
@@ -847,7 +847,7 @@ void DiscoveredPeripheralTracker::HandleAdvertisementHeader(
}
ByteArray DiscoveredPeripheralTracker::ExtractAdvertisementHeaderBytes(
const nearby::api::ble_v2::BleAdvertisementData& advertisement_data) {
const nearby::api::ble::BleAdvertisementData& advertisement_data) {
const auto it =
advertisement_data.service_data.find(bleutils::kCopresenceServiceUuid);
if (it != advertisement_data.service_data.end()) {
@@ -930,7 +930,7 @@ bool DiscoveredPeripheralTracker::ShouldReadRawAdvertisementFromServer(
std::vector<const ByteArray*>
DiscoveredPeripheralTracker::FetchRawAdvertisements(
BleV2Peripheral peripheral,
BlePeripheral peripheral,
const BleAdvertisementHeader& advertisement_header,
AdvertisementFetcher advertisement_fetcher) {
// Fetch the raw GATT advertisements and store the results.
@@ -952,7 +952,7 @@ DiscoveredPeripheralTracker::FetchRawAdvertisements(
}
void DiscoveredPeripheralTracker::FetchRawAdvertisementsInThread(
BleV2Peripheral peripheral,
BlePeripheral peripheral,
const BleAdvertisementHeader& advertisement_header,
AdvertisementFetcher advertisement_fetcher) {
std::vector<std::string> service_ids;
@@ -12,8 +12,8 @@
// See the License for the specific language governing permissions and
// limitations under the License.
#ifndef CORE_INTERNAL_MEDIUMS_BLE_V2_DISCOVERED_PERIPHERAL_TRACKER_H_
#define CORE_INTERNAL_MEDIUMS_BLE_V2_DISCOVERED_PERIPHERAL_TRACKER_H_
#ifndef CORE_INTERNAL_MEDIUMS_BLE_DISCOVERED_PERIPHERAL_TRACKER_H_
#define CORE_INTERNAL_MEDIUMS_BLE_DISCOVERED_PERIPHERAL_TRACKER_H_
#include <array>
#include <deque>
@@ -28,17 +28,17 @@
#include "absl/functional/any_invocable.h"
#include "absl/time/time.h"
#include "connections/implementation/mediums//lost_entity_tracker.h"
#include "connections/implementation/mediums/ble_v2/advertisement_read_result.h"
#include "connections/implementation/mediums/ble_v2/ble_advertisement.h"
#include "connections/implementation/mediums/ble_v2/ble_advertisement_header.h"
#include "connections/implementation/mediums/ble_v2/discovered_peripheral_callback.h"
#include "connections/implementation/mediums/ble/advertisement_read_result.h"
#include "connections/implementation/mediums/ble/ble_advertisement.h"
#include "connections/implementation/mediums/ble/ble_advertisement_header.h"
#include "connections/implementation/mediums/ble/discovered_peripheral_callback.h"
#include "connections/implementation/mediums/lost_entity_tracker.h"
#include "connections/implementation/pcp.h"
#include "internal/platform/atomic_boolean.h"
#include "internal/platform/ble_v2.h"
#include "internal/platform/ble.h"
#include "internal/platform/byte_array.h"
#include "internal/platform/condition_variable.h"
#include "internal/platform/implementation/ble_v2.h"
#include "internal/platform/implementation/ble.h"
#include "internal/platform/multi_thread_executor.h"
#include "internal/platform/mutex.h"
#include "internal/platform/uuid.h"
@@ -65,7 +65,7 @@ class DiscoveredPeripheralTracker {
// `advertisement_read_result` is in/out mutable reference that the caller
// should take of its life cycle and pass a valid reference.
using AdvertisementFetcher = absl::AnyInvocable<void(
BleV2Peripheral peripheral, int num_slots, int psm,
BlePeripheral peripheral, int num_slots, int psm,
const std::vector<std::string>& interesting_service_ids,
mediums::AdvertisementReadResult& advertisement_read_result)>;
@@ -101,8 +101,8 @@ class DiscoveredPeripheralTracker {
// advertisement if the advertisement header is been
// processed.
void ProcessFoundBleAdvertisement(
BleV2Peripheral peripheral,
api::ble_v2::BleAdvertisementData advertisement_data,
BlePeripheral peripheral,
api::ble::BleAdvertisementData advertisement_data,
AdvertisementFetcher advertisement_fetcher) ABSL_LOCKS_EXCLUDED(mutex_);
// Processes the set of lost GATT advertisements and notifies the client of
@@ -148,14 +148,14 @@ class DiscoveredPeripheralTracker {
BleAdvertisementHeader advertisement_header;
// A proxy BlePeripheral for found/lost discovery callback.
BleV2Peripheral peripheral;
BlePeripheral peripheral;
// Hash for instant on lost.
ByteArray instant_on_lost_hash;
};
struct GattFetchTask {
BleV2Peripheral peripheral;
BlePeripheral peripheral;
BleAdvertisementHeader advertisement_header;
AdvertisementFetcher advertisement_fetcher;
absl::Time scheduled_time;
@@ -169,7 +169,7 @@ class DiscoveredPeripheralTracker {
// as exented_advertisement. This is to avoid reading advertisement from GATT
// connection, which has been advertised by extended advertisement.
bool IsSkippableGattAdvertisement(
const api::ble_v2::BleAdvertisementData& advertisement_data)
const api::ble::BleAdvertisementData& advertisement_data)
ABSL_EXCLUSIVE_LOCKS_REQUIRED(mutex_);
// Clears out all data related to the provided GATT advertisement. This
@@ -187,13 +187,13 @@ class DiscoveredPeripheralTracker {
// Handles the legacy fast advertisement or the extended fast/regular
// advertisement.
void HandleAdvertisement(
BleV2Peripheral peripheral,
const api::ble_v2::BleAdvertisementData& advertisement_data)
BlePeripheral peripheral,
const api::ble::BleAdvertisementData& advertisement_data)
ABSL_EXCLUSIVE_LOCKS_REQUIRED(mutex_);
// Extracts the advertisement byte array from `AdvertisementData`.
ByteArray ExtractInterestingAdvertisementBytes(
const api::ble_v2::BleAdvertisementData& advertisement_data)
const api::ble::BleAdvertisementData& advertisement_data)
ABSL_EXCLUSIVE_LOCKS_REQUIRED(mutex_);
// Creates an advertisement header that's purely a hash of the fast/regular
@@ -204,7 +204,7 @@ class DiscoveredPeripheralTracker {
// Returns BleAdvertisementHeader, it may be replaced if the header is mock
// and there's a psm value in advertisement.
BleAdvertisementHeader HandleRawGattAdvertisements(
BleV2Peripheral peripheral,
BlePeripheral peripheral,
const BleAdvertisementHeader& advertisement_header,
const std::vector<const ByteArray*>& gatt_advertisement_bytes_list,
const Uuid& service_uuid) ABSL_EXCLUSIVE_LOCKS_REQUIRED(mutex_);
@@ -229,20 +229,20 @@ class DiscoveredPeripheralTracker {
bool IsDummyAdvertisementHeader(
const BleAdvertisementHeader& advertisement_header);
std::optional<api::ble_v2::BleAdvertisementData> HandleDctAdvertisement(
const api::ble_v2::BleAdvertisementData& advertisement_data)
std::optional<api::ble::BleAdvertisementData> HandleDctAdvertisement(
const api::ble::BleAdvertisementData& advertisement_data)
ABSL_EXCLUSIVE_LOCKS_REQUIRED(mutex_);
// Handles the advertisement header for regular advertisement.
void HandleAdvertisementHeader(
BleV2Peripheral peripheral,
const api::ble_v2::BleAdvertisementData& advertisement_data,
BlePeripheral peripheral,
const api::ble::BleAdvertisementData& advertisement_data,
AdvertisementFetcher advertisement_fetcher)
ABSL_EXCLUSIVE_LOCKS_REQUIRED(mutex_);
// Extracts the advertisement header byte array from `AdvertisementData`.
ByteArray ExtractAdvertisementHeaderBytes(
const api::ble_v2::BleAdvertisementData& advertisement_data)
const api::ble::BleAdvertisementData& advertisement_data)
ABSL_EXCLUSIVE_LOCKS_REQUIRED(mutex_);
// Returns true if the advertisement header contains a service ID we're
@@ -263,13 +263,13 @@ class DiscoveredPeripheralTracker {
// advertisement_fetcher : a fetcher passed from BLE medium to read the
// advertisement from BLE characteristics by GATT server.
std::vector<const ByteArray*> FetchRawAdvertisements(
BleV2Peripheral peripheral,
BlePeripheral peripheral,
const BleAdvertisementHeader& advertisement_header,
AdvertisementFetcher advertisement_fetcher)
ABSL_EXCLUSIVE_LOCKS_REQUIRED(mutex_);
void FetchRawAdvertisementsInThread(
BleV2Peripheral peripheral,
BlePeripheral peripheral,
const BleAdvertisementHeader& advertisement_header,
AdvertisementFetcher advertisement_fetcher);
@@ -287,13 +287,13 @@ class DiscoveredPeripheralTracker {
// 2. Matches a peripheral's advertisement hash that has previously been
// discovered.
bool HandleOnLostAdvertisementLocked(
const ::nearby::api::ble_v2::BleAdvertisementData& advertisement_data)
const ::nearby::api::ble::BleAdvertisementData& advertisement_data)
ABSL_EXCLUSIVE_LOCKS_REQUIRED(mutex_);
// Returns true if the advertisement header met the special conditions of
// a legacy device dummy advertisement.
static bool IsLegacyDeviceAdvertisementData(
const api::ble_v2::BleAdvertisementData& advertisement_data);
const api::ble::BleAdvertisementData& advertisement_data);
// Helps to handle advertisement for Instant On lost.
bool IsInstantLostAdvertisement(
@@ -377,4 +377,4 @@ class DiscoveredPeripheralTracker {
} // namespace connections
} // namespace nearby
#endif // CORE_INTERNAL_MEDIUMS_BLE_V2_DISCOVERED_PERIPHERAL_TRACKER_H_
#endif // CORE_INTERNAL_MEDIUMS_BLE_DISCOVERED_PERIPHERAL_TRACKER_H_
@@ -12,7 +12,7 @@
// See the License for the specific language governing permissions and
// limitations under the License.
#include "connections/implementation/mediums/ble_v2/discovered_peripheral_tracker.h"
#include "connections/implementation/mediums/ble/discovered_peripheral_tracker.h"
#include <atomic>
#include <list>
@@ -32,22 +32,22 @@
#include "absl/time/time.h"
#include "connections/implementation/flags/nearby_connections_feature_flags.h"
#include "connections/implementation/mediums/advertisements/dct_advertisement.h"
#include "connections/implementation/mediums/ble_v2/advertisement_read_result.h"
#include "connections/implementation/mediums/ble_v2/ble_advertisement.h"
#include "connections/implementation/mediums/ble_v2/ble_advertisement_header.h"
#include "connections/implementation/mediums/ble_v2/ble_utils.h"
#include "connections/implementation/mediums/ble_v2/bloom_filter.h"
#include "connections/implementation/mediums/ble_v2/discovered_peripheral_callback.h"
#include "connections/implementation/mediums/ble_v2/instant_on_lost_advertisement.h"
#include "connections/implementation/mediums/ble/advertisement_read_result.h"
#include "connections/implementation/mediums/ble/ble_advertisement.h"
#include "connections/implementation/mediums/ble/ble_advertisement_header.h"
#include "connections/implementation/mediums/ble/ble_utils.h"
#include "connections/implementation/mediums/ble/bloom_filter.h"
#include "connections/implementation/mediums/ble/discovered_peripheral_callback.h"
#include "connections/implementation/mediums/ble/instant_on_lost_advertisement.h"
#include "connections/implementation/mediums/utils.h"
#include "connections/implementation/pcp.h"
#include "internal/flags/nearby_flags.h"
#include "internal/platform/ble_v2.h"
#include "internal/platform/ble.h"
#include "internal/platform/bluetooth_adapter.h"
#include "internal/platform/byte_array.h"
#include "internal/platform/count_down_latch.h"
#include "internal/platform/feature_flags.h"
#include "internal/platform/implementation/ble_v2.h"
#include "internal/platform/implementation/ble.h"
#include "internal/platform/mac_address.h"
#include "internal/platform/medium_environment.h"
#include "internal/platform/mutex.h"
@@ -173,14 +173,11 @@ ByteArray GenerateRandomAdvertisementHash() {
class MockDiscoveredPeripheralCallback : public DiscoveredPeripheralCallback {
public:
MOCK_METHOD(void, OnPeripheralDiscovered,
(BleV2Peripheral, const std::string&, const ByteArray&, bool),
());
(BlePeripheral, const std::string&, const ByteArray&, bool), ());
MOCK_METHOD(void, OnPeripheralLost,
(BleV2Peripheral, const std::string&, const ByteArray&, bool),
());
(BlePeripheral, const std::string&, const ByteArray&, bool), ());
MOCK_METHOD(void, OnInstantLost,
(BleV2Peripheral, const std::string&, const ByteArray&, bool),
());
(BlePeripheral, const std::string&, const ByteArray&, bool), ());
MOCK_METHOD(void, OnLegacyDeviceDiscovered, (), ());
};
@@ -215,8 +212,8 @@ class DiscoveredPeripheralTrackerTest
enable_read_gatt_for_extended_advertisement);
adapter_peripheral_ = std::make_unique<BluetoothAdapter>();
adapter_central_ = std::make_unique<BluetoothAdapter>();
ble_peripheral_ = std::make_unique<BleV2Medium>(*adapter_peripheral_);
ble_central_ = std::make_unique<BleV2Medium>(*adapter_central_);
ble_peripheral_ = std::make_unique<BleMedium>(*adapter_peripheral_);
ble_central_ = std::make_unique<BleMedium>(*adapter_central_);
}
void TearDown() override {
@@ -225,17 +222,17 @@ class DiscoveredPeripheralTrackerTest
NearbyFlags::GetInstance().ResetOverridedValues();
}
BleV2Peripheral CreateBlePeripheral() {
return BleV2Peripheral(*ble_central_,
adapter_peripheral_->GetAddress().address());
BlePeripheral CreateBlePeripheral() {
return BlePeripheral(*ble_central_,
adapter_peripheral_->GetAddress().address());
}
// Simulates to see a fast advertisement.
void FindFastAdvertisement(
const api::ble_v2::BleAdvertisementData& advertisement_data,
const api::ble::BleAdvertisementData& advertisement_data,
const std::vector<ByteArray>& advertisement_bytes_list,
CountDownLatch& fetch_latch) {
BleV2Peripheral peripheral = CreateBlePeripheral();
BlePeripheral peripheral = CreateBlePeripheral();
discovered_peripheral_tracker_->ProcessFoundBleAdvertisement(
peripheral, advertisement_data,
@@ -245,11 +242,11 @@ class DiscoveredPeripheralTrackerTest
// Simulates to see an extended advertisement, which don't need to fetch
// advertisement from GATT.
void FindExtendedAdvertisement(
const api::ble_v2::BleAdvertisementData& advertisement_data,
const api::ble::BleAdvertisementData& advertisement_data,
CountDownLatch& fetch_latch) {
BleV2Peripheral peripheral = CreateBlePeripheral();
BlePeripheral peripheral = CreateBlePeripheral();
DiscoveredPeripheralTracker::AdvertisementFetcher placeholder_fetcher =
[](BleV2Peripheral, int, int, const std::vector<std::string>&,
[](BlePeripheral, int, int, const std::vector<std::string>&,
mediums::AdvertisementReadResult&) {};
discovered_peripheral_tracker_->ProcessFoundBleAdvertisement(
peripheral, advertisement_data, std::move(placeholder_fetcher));
@@ -258,10 +255,10 @@ class DiscoveredPeripheralTrackerTest
// Simulates to see a regular advertisement.
void FindAdvertisement(
const api::ble_v2::BleAdvertisementData& advertisement_data,
const api::ble::BleAdvertisementData& advertisement_data,
const std::vector<ByteArray>& advertisement_bytes_list,
CountDownLatch& fetch_latch) {
BleV2Peripheral peripheral = CreateBlePeripheral();
BlePeripheral peripheral = CreateBlePeripheral();
discovered_peripheral_tracker_->ProcessFoundBleAdvertisement(
peripheral, advertisement_data,
@@ -269,10 +266,10 @@ class DiscoveredPeripheralTrackerTest
}
void FindAdvertisementWithDelay(
const api::ble_v2::BleAdvertisementData& advertisement_data,
const api::ble::BleAdvertisementData& advertisement_data,
const std::vector<ByteArray>& advertisement_bytes_list,
CountDownLatch& fetch_latch, absl::Duration delay) {
BleV2Peripheral peripheral = CreateBlePeripheral();
BlePeripheral peripheral = CreateBlePeripheral();
discovered_peripheral_tracker_->ProcessFoundBleAdvertisement(
peripheral, advertisement_data,
@@ -304,7 +301,7 @@ class DiscoveredPeripheralTrackerTest
CountDownLatch& fetch_latch,
const std::vector<ByteArray>& advertisement_bytes_list) {
return [this, &fetch_latch, advertisement_bytes_list](
BleV2Peripheral peripheral, int num_slots, int psm,
BlePeripheral peripheral, int num_slots, int psm,
const std::vector<std::string>& interesting_service_ids,
mediums::AdvertisementReadResult& advertisement_read_result) {
MutexLock lock(&mutex_);
@@ -325,7 +322,7 @@ class DiscoveredPeripheralTrackerTest
const std::vector<ByteArray>& advertisement_bytes_list,
absl::Duration delay) {
return [this, &fetch_latch, advertisement_bytes_list, delay](
BleV2Peripheral peripheral, int num_slots, int psm,
BlePeripheral peripheral, int num_slots, int psm,
const std::vector<std::string>& interesting_service_ids,
mediums::AdvertisementReadResult& advertisement_read_result) {
MutexLock lock(&mutex_);
@@ -344,8 +341,8 @@ class DiscoveredPeripheralTrackerTest
std::unique_ptr<BluetoothAdapter> adapter_peripheral_;
std::unique_ptr<BluetoothAdapter> adapter_central_;
std::unique_ptr<BleV2Medium> ble_peripheral_;
std::unique_ptr<BleV2Medium> ble_central_;
std::unique_ptr<BleMedium> ble_peripheral_;
std::unique_ptr<BleMedium> ble_central_;
mutable Mutex mutex_;
int fetch_count_ ABSL_GUARDED_BY(mutex_) = 0;
std::unique_ptr<DiscoveredPeripheralTracker> discovered_peripheral_tracker_;
@@ -362,7 +359,7 @@ TEST_P(DiscoveredPeripheralTrackerTest,
std::string(kServiceIdA), false, Pcp::kP2pPointToPoint,
{
.peripheral_discovered_cb =
[&found_latch](BleV2Peripheral peripheral,
[&found_latch](BlePeripheral peripheral,
const std::string& service_id,
const ByteArray& advertisement_bytes,
bool fast_advertisement) {
@@ -373,7 +370,7 @@ TEST_P(DiscoveredPeripheralTrackerTest,
},
Uuid(kFastAdvertisementServiceUuid));
api::ble_v2::BleAdvertisementData advertisement_data{};
api::ble::BleAdvertisementData advertisement_data{};
if (!fast_advertisement_bytes.Empty()) {
advertisement_data.service_data.insert(
{Uuid(kFastAdvertisementServiceUuid), fast_advertisement_bytes});
@@ -398,7 +395,7 @@ TEST_P(DiscoveredPeripheralTrackerTest, DctAdvertisementPeripheralDiscovered) {
std::string(kServiceIdA), true, Pcp::kP2pPointToPoint,
{
.peripheral_discovered_cb =
[&found_latch](BleV2Peripheral peripheral,
[&found_latch](BlePeripheral peripheral,
const std::string& service_id,
const ByteArray& advertisement_bytes,
bool fast_advertisement) {
@@ -408,7 +405,7 @@ TEST_P(DiscoveredPeripheralTrackerTest, DctAdvertisementPeripheralDiscovered) {
},
Uuid(kFastAdvertisementServiceUuid));
api::ble_v2::BleAdvertisementData advertisement_data{};
api::ble::BleAdvertisementData advertisement_data{};
advertisement_data.service_data.insert(
{bleutils::kDctServiceUuid, dct_advertisement_bytes});
@@ -438,7 +435,7 @@ TEST_P(DiscoveredPeripheralTrackerTest,
std::string(kServiceIdA), false, Pcp::kP2pPointToPoint,
{.peripheral_discovered_cb =
[&found_latch](
BleV2Peripheral peripheral, const std::string& service_id,
BlePeripheral peripheral, const std::string& service_id,
const ByteArray& advertisement_bytes, bool fast_advertisement) {
EXPECT_EQ(advertisement_bytes, ByteArray(std::string(kData)));
EXPECT_FALSE(fast_advertisement);
@@ -448,7 +445,7 @@ TEST_P(DiscoveredPeripheralTrackerTest,
[&legacy_found_latch]() { legacy_found_latch.CountDown(); }},
{});
api::ble_v2::BleAdvertisementData advertisement_data{};
api::ble::BleAdvertisementData advertisement_data{};
if (!advertisement_header_bytes.Empty()) {
advertisement_data.service_data.insert(
{bleutils::kCopresenceServiceUuid, advertisement_header_bytes});
@@ -477,7 +474,7 @@ TEST_P(DiscoveredPeripheralTrackerTest,
{
.peripheral_discovered_cb =
[&callback_times, &found_latch](
BleV2Peripheral peripheral, const std::string& service_id,
BlePeripheral peripheral, const std::string& service_id,
const ByteArray& advertisement_bytes,
bool fast_advertisement) {
callback_times++;
@@ -488,7 +485,7 @@ TEST_P(DiscoveredPeripheralTrackerTest,
},
Uuid(kFastAdvertisementServiceUuid));
api::ble_v2::BleAdvertisementData advertisement_data{};
api::ble::BleAdvertisementData advertisement_data{};
if (!fast_advertisement_bytes.Empty()) {
advertisement_data.service_data.insert(
{Uuid(kFastAdvertisementServiceUuid), fast_advertisement_bytes});
@@ -502,7 +499,7 @@ TEST_P(DiscoveredPeripheralTrackerTest,
{
.peripheral_discovered_cb =
[&callback_times, &found_latch](
BleV2Peripheral peripheral, const std::string& service_id,
BlePeripheral peripheral, const std::string& service_id,
const ByteArray& advertisement_bytes,
bool fast_advertisement) {
callback_times++;
@@ -521,7 +518,7 @@ TEST_P(DiscoveredPeripheralTrackerTest,
{
.peripheral_discovered_cb =
[&callback_times, &found_latch](
BleV2Peripheral peripheral, const std::string& service_id,
BlePeripheral peripheral, const std::string& service_id,
const ByteArray& advertisement_bytes,
bool fast_advertisement) {
callback_times++;
@@ -548,7 +545,7 @@ TEST_P(DiscoveredPeripheralTrackerTest,
{
.peripheral_discovered_cb =
[&callback_times, &found_latch](
BleV2Peripheral peripheral, const std::string& service_id,
BlePeripheral peripheral, const std::string& service_id,
const ByteArray& advertisement_bytes,
bool fast_advertisement) {
callback_times++;
@@ -559,7 +556,7 @@ TEST_P(DiscoveredPeripheralTrackerTest,
},
Uuid(kFastAdvertisementServiceUuid));
api::ble_v2::BleAdvertisementData advertisement_data{};
api::ble::BleAdvertisementData advertisement_data{};
if (!fast_advertisement_bytes.Empty()) {
advertisement_data.service_data.insert(
{Uuid(kFastAdvertisementServiceUuid), fast_advertisement_bytes});
@@ -592,7 +589,7 @@ TEST_P(DiscoveredPeripheralTrackerTest,
std::string(kServiceIdA), false, Pcp::kP2pPointToPoint,
{
.peripheral_discovered_cb =
[&found_latch](BleV2Peripheral peripheral,
[&found_latch](BlePeripheral peripheral,
const std::string& service_id,
const ByteArray& advertisement_bytes,
bool fast_advertisement) {
@@ -603,7 +600,7 @@ TEST_P(DiscoveredPeripheralTrackerTest,
},
Uuid("FE3C"));
api::ble_v2::BleAdvertisementData advertisement_data{};
api::ble::BleAdvertisementData advertisement_data{};
if (!fast_advertisement_bytes.Empty()) {
advertisement_data.service_data.insert(
{Uuid(kFastAdvertisementServiceUuid), fast_advertisement_bytes});
@@ -635,7 +632,7 @@ TEST_P(DiscoveredPeripheralTrackerTest,
std::string(kServiceIdA), false, Pcp::kP2pPointToPoint,
{
.peripheral_discovered_cb =
[&found_latch_a](BleV2Peripheral peripheral,
[&found_latch_a](BlePeripheral peripheral,
const std::string& service_id,
const ByteArray& advertisement_bytes,
bool fast_advertisement) {
@@ -649,7 +646,7 @@ TEST_P(DiscoveredPeripheralTrackerTest,
std::string(kServiceIdB), false, Pcp::kP2pPointToPoint,
{
.peripheral_discovered_cb =
[&found_latch_b](BleV2Peripheral peripheral,
[&found_latch_b](BlePeripheral peripheral,
const std::string& service_id,
const ByteArray& advertisement_bytes,
bool fast_advertisement) {
@@ -660,7 +657,7 @@ TEST_P(DiscoveredPeripheralTrackerTest,
},
{});
api::ble_v2::BleAdvertisementData advertisement_data{};
api::ble::BleAdvertisementData advertisement_data{};
if (!advertisement_header_bytes.Empty()) {
advertisement_data.service_data.insert(
{bleutils::kCopresenceServiceUuid, advertisement_header_bytes});
@@ -694,7 +691,7 @@ TEST_P(DiscoveredPeripheralTrackerTest,
std::string(kServiceIdA), false, Pcp::kP2pPointToPoint,
{
.peripheral_discovered_cb =
[&found_latch](BleV2Peripheral peripheral,
[&found_latch](BlePeripheral peripheral,
const std::string& service_id,
const ByteArray& advertisement_bytes,
bool fast_advertisement) {
@@ -705,7 +702,7 @@ TEST_P(DiscoveredPeripheralTrackerTest,
},
{});
api::ble_v2::BleAdvertisementData advertisement_data{};
api::ble::BleAdvertisementData advertisement_data{};
if (!advertisement_header_bytes.Empty()) {
advertisement_data.service_data.insert(
{bleutils::kCopresenceServiceUuid, advertisement_header_bytes});
@@ -735,13 +732,13 @@ TEST_P(DiscoveredPeripheralTrackerTest,
{
.peripheral_discovered_cb =
[&found_latch](
BleV2Peripheral peripheral, const std::string& service_id,
BlePeripheral peripheral, const std::string& service_id,
const ByteArray& advertisement_bytes,
bool fast_advertisement) { found_latch.CountDown(); },
},
{});
api::ble_v2::BleAdvertisementData advertisement_data{};
api::ble::BleAdvertisementData advertisement_data{};
if (!advertisement_header_bytes.Empty()) {
advertisement_data.service_data.insert(
{bleutils::kCopresenceServiceUuid, advertisement_header_bytes});
@@ -776,7 +773,7 @@ TEST_P(DiscoveredPeripheralTrackerTest,
{
.peripheral_discovered_cb =
[&callback_times, &found_latch](
BleV2Peripheral peripheral, const std::string& service_id,
BlePeripheral peripheral, const std::string& service_id,
const ByteArray& advertisement_bytes,
bool fast_advertisement) {
callback_times++;
@@ -787,7 +784,7 @@ TEST_P(DiscoveredPeripheralTrackerTest,
},
{});
api::ble_v2::BleAdvertisementData advertisement_data{};
api::ble::BleAdvertisementData advertisement_data{};
if (!advertisement_header_bytes.Empty()) {
advertisement_data.service_data.insert(
{bleutils::kCopresenceServiceUuid, advertisement_header_bytes});
@@ -822,7 +819,7 @@ TEST_P(DiscoveredPeripheralTrackerTest,
{
.peripheral_discovered_cb =
[&callback_times, &found_latch](
BleV2Peripheral peripheral, const std::string& service_id,
BlePeripheral peripheral, const std::string& service_id,
const ByteArray& advertisement_bytes,
bool fast_advertisement) {
callback_times++;
@@ -833,7 +830,7 @@ TEST_P(DiscoveredPeripheralTrackerTest,
},
{});
api::ble_v2::BleAdvertisementData advertisement_data{};
api::ble::BleAdvertisementData advertisement_data{};
if (!advertisement_header_bytes.Empty()) {
advertisement_data.service_data.insert(
{bleutils::kCopresenceServiceUuid, advertisement_header_bytes});
@@ -870,13 +867,13 @@ TEST_P(DiscoveredPeripheralTrackerTest,
{
.peripheral_discovered_cb =
[&found_latch](
BleV2Peripheral peripheral, const std::string& service_id,
BlePeripheral peripheral, const std::string& service_id,
const ByteArray& advertisement_bytes,
bool fast_advertisement) { found_latch.CountDown(); },
},
{});
api::ble_v2::BleAdvertisementData advertisement_data{};
api::ble::BleAdvertisementData advertisement_data{};
if (!advertisement_header_bytes.Empty()) {
advertisement_data.service_data.insert(
{bleutils::kCopresenceServiceUuid, advertisement_header_bytes});
@@ -906,7 +903,7 @@ TEST_P(DiscoveredPeripheralTrackerTest,
std::string(kServiceIdA), false, Pcp::kP2pPointToPoint,
{
.peripheral_discovered_cb =
[&found_latch](BleV2Peripheral peripheral,
[&found_latch](BlePeripheral peripheral,
const std::string& service_id,
const ByteArray& advertisement_bytes,
bool fast_advertisement) {
@@ -916,7 +913,7 @@ TEST_P(DiscoveredPeripheralTrackerTest,
},
.peripheral_lost_cb =
[&lost_latch, &lost_callback_times](
BleV2Peripheral peripheral, const std::string& service_id,
BlePeripheral peripheral, const std::string& service_id,
const ByteArray& advertisement_bytes,
bool fast_advertisement) {
lost_callback_times++;
@@ -925,7 +922,7 @@ TEST_P(DiscoveredPeripheralTrackerTest,
},
Uuid(kFastAdvertisementServiceUuid));
api::ble_v2::BleAdvertisementData advertisement_data{};
api::ble::BleAdvertisementData advertisement_data{};
if (!advertisement_header_bytes.Empty()) {
advertisement_data.service_data.insert(
{bleutils::kCopresenceServiceUuid, advertisement_header_bytes});
@@ -969,7 +966,7 @@ TEST_P(DiscoveredPeripheralTrackerTest,
std::string(kServiceIdA), false, Pcp::kP2pPointToPoint,
{
.peripheral_discovered_cb =
[&found_latch](BleV2Peripheral peripheral,
[&found_latch](BlePeripheral peripheral,
const std::string& service_id,
const ByteArray& advertisement_bytes,
bool fast_advertisement) {
@@ -979,13 +976,13 @@ TEST_P(DiscoveredPeripheralTrackerTest,
},
.peripheral_lost_cb =
[&lost_latch](
BleV2Peripheral peripheral, const std::string& service_id,
BlePeripheral peripheral, const std::string& service_id,
const ByteArray& advertisement_bytes,
bool fast_advertisement) { lost_latch.CountDown(); },
},
Uuid(kFastAdvertisementServiceUuid));
api::ble_v2::BleAdvertisementData advertisement_data{};
api::ble::BleAdvertisementData advertisement_data{};
if (!advertisement_header_bytes.Empty()) {
advertisement_data.service_data.insert(
{bleutils::kCopresenceServiceUuid, advertisement_header_bytes});
@@ -1026,7 +1023,7 @@ TEST_P(DiscoveredPeripheralTrackerTest, LostPeripheralForAdvertisementLost) {
std::string(kServiceIdA), false, Pcp::kP2pPointToPoint,
{
.peripheral_discovered_cb =
[&found_latch](BleV2Peripheral peripheral,
[&found_latch](BlePeripheral peripheral,
const std::string& service_id,
const ByteArray& advertisement_bytes,
bool fast_advertisement) {
@@ -1036,13 +1033,13 @@ TEST_P(DiscoveredPeripheralTrackerTest, LostPeripheralForAdvertisementLost) {
},
.peripheral_lost_cb =
[&lost_latch](
BleV2Peripheral peripheral, const std::string& service_id,
BlePeripheral peripheral, const std::string& service_id,
const ByteArray& advertisement_bytes,
bool fast_advertisement) { lost_latch.CountDown(); },
},
{});
api::ble_v2::BleAdvertisementData advertisement_data{};
api::ble::BleAdvertisementData advertisement_data{};
if (!advertisement_header_bytes.Empty()) {
advertisement_data.service_data.insert(
{bleutils::kCopresenceServiceUuid, advertisement_header_bytes});
@@ -1085,7 +1082,7 @@ TEST_P(DiscoveredPeripheralTrackerTest,
std::string(kServiceIdA), false, Pcp::kP2pPointToPoint,
{
.peripheral_discovered_cb =
[&found_latch_a](BleV2Peripheral peripheral,
[&found_latch_a](BlePeripheral peripheral,
const std::string& service_id,
const ByteArray& advertisement_bytes,
bool fast_advertisement) {
@@ -1095,7 +1092,7 @@ TEST_P(DiscoveredPeripheralTrackerTest,
},
.peripheral_lost_cb =
[&lost_latch_a](
BleV2Peripheral peripheral, const std::string& service_id,
BlePeripheral peripheral, const std::string& service_id,
const ByteArray& advertisement_bytes,
bool fast_advertisement) { lost_latch_a.CountDown(); },
},
@@ -1104,7 +1101,7 @@ TEST_P(DiscoveredPeripheralTrackerTest,
std::string(kServiceIdB), false, Pcp::kP2pPointToPoint,
{
.peripheral_discovered_cb =
[&found_latch_b](BleV2Peripheral peripheral,
[&found_latch_b](BlePeripheral peripheral,
const std::string& service_id,
const ByteArray& advertisement_bytes,
bool fast_advertisement) {
@@ -1114,13 +1111,13 @@ TEST_P(DiscoveredPeripheralTrackerTest,
},
.peripheral_lost_cb =
[&lost_latch_b](
BleV2Peripheral peripheral, const std::string& service_id,
BlePeripheral peripheral, const std::string& service_id,
const ByteArray& advertisement_bytes,
bool fast_advertisement) { lost_latch_b.CountDown(); },
},
{});
api::ble_v2::BleAdvertisementData advertisement_data{};
api::ble::BleAdvertisementData advertisement_data{};
if (!advertisement_header_bytes.Empty()) {
advertisement_data.service_data.insert(
{bleutils::kCopresenceServiceUuid, advertisement_header_bytes});
@@ -1166,7 +1163,7 @@ TEST_P(DiscoveredPeripheralTrackerTest,
std::string(kServiceIdA), false, Pcp::kP2pPointToPoint,
{
.peripheral_discovered_cb =
[&found_latch](BleV2Peripheral peripheral,
[&found_latch](BlePeripheral peripheral,
const std::string& service_id,
const ByteArray& advertisement_bytes,
bool fast_advertisement) {
@@ -1176,13 +1173,13 @@ TEST_P(DiscoveredPeripheralTrackerTest,
},
.peripheral_lost_cb =
[&lost_latch](
BleV2Peripheral peripheral, const std::string& service_id,
BlePeripheral peripheral, const std::string& service_id,
const ByteArray& advertisement_bytes,
bool fast_advertisement) { lost_latch.CountDown(); },
},
{});
api::ble_v2::BleAdvertisementData advertisement_data{};
api::ble::BleAdvertisementData advertisement_data{};
if (!advertisement_header_bytes.Empty()) {
advertisement_data.service_data.insert(
{bleutils::kCopresenceServiceUuid, advertisement_header_bytes});
@@ -1220,7 +1217,7 @@ TEST_P(DiscoveredPeripheralTrackerTest, LostPeripheralForInstantOnLost) {
std::string(kServiceIdA), false, Pcp::kP2pPointToPoint,
{
.peripheral_discovered_cb =
[&found_latch](BleV2Peripheral peripheral,
[&found_latch](BlePeripheral peripheral,
const std::string& service_id,
const ByteArray& advertisement_bytes,
bool fast_advertisement) {
@@ -1230,13 +1227,13 @@ TEST_P(DiscoveredPeripheralTrackerTest, LostPeripheralForInstantOnLost) {
},
.peripheral_lost_cb =
[&lost_latch](
BleV2Peripheral peripheral, const std::string& service_id,
BlePeripheral peripheral, const std::string& service_id,
const ByteArray& advertisement_bytes,
bool fast_advertisement) { lost_latch.CountDown(); },
},
{});
api::ble_v2::BleAdvertisementData advertisement_data{};
api::ble::BleAdvertisementData advertisement_data{};
if (!advertisement_header_bytes.Empty()) {
advertisement_data.service_data.insert(
{bleutils::kCopresenceServiceUuid, advertisement_header_bytes});
@@ -1253,7 +1250,7 @@ TEST_P(DiscoveredPeripheralTrackerTest, LostPeripheralForInstantOnLost) {
std::list<std::string>({std::string(
bleutils::GenerateAdvertisementHash(advertisement_bytes))}));
ASSERT_OK(advertisement);
api::ble_v2::BleAdvertisementData loss_advertisement_data{};
api::ble::BleAdvertisementData loss_advertisement_data{};
loss_advertisement_data.service_data.insert(
{bleutils::kCopresenceServiceUuid, ByteArray(advertisement->ToBytes())});
@@ -1286,7 +1283,7 @@ TEST_P(DiscoveredPeripheralTrackerTest, InstantLostPeripheralForInstantOnLost) {
std::string(kServiceIdA), false, Pcp::kP2pPointToPoint,
{
.peripheral_discovered_cb =
[&found_latch](BleV2Peripheral peripheral,
[&found_latch](BlePeripheral peripheral,
const std::string& service_id,
const ByteArray& advertisement_bytes,
bool fast_advertisement) {
@@ -1296,13 +1293,13 @@ TEST_P(DiscoveredPeripheralTrackerTest, InstantLostPeripheralForInstantOnLost) {
},
.instant_lost_cb =
[&lost_latch](
BleV2Peripheral peripheral, const std::string& service_id,
BlePeripheral peripheral, const std::string& service_id,
const ByteArray& advertisement_bytes,
bool fast_advertisement) { lost_latch.CountDown(); },
},
{});
api::ble_v2::BleAdvertisementData advertisement_data{};
api::ble::BleAdvertisementData advertisement_data{};
if (!advertisement_header_bytes.Empty()) {
advertisement_data.service_data.insert(
{bleutils::kCopresenceServiceUuid, advertisement_header_bytes});
@@ -1319,7 +1316,7 @@ TEST_P(DiscoveredPeripheralTrackerTest, InstantLostPeripheralForInstantOnLost) {
std::list<std::string>({std::string(
bleutils::GenerateAdvertisementHash(advertisement_bytes))}));
ASSERT_OK(advertisement);
api::ble_v2::BleAdvertisementData loss_advertisement_data{};
api::ble::BleAdvertisementData loss_advertisement_data{};
loss_advertisement_data.service_data.insert(
{bleutils::kCopresenceServiceUuid, ByteArray(advertisement->ToBytes())});
@@ -1353,7 +1350,7 @@ TEST_P(DiscoveredPeripheralTrackerTest,
std::string(kServiceIdA), false, Pcp::kP2pPointToPoint,
{
.peripheral_discovered_cb =
[&mock_callback](BleV2Peripheral peripheral,
[&mock_callback](BlePeripheral peripheral,
const std::string& service_id,
const ByteArray& advertisement_bytes,
bool fast_advertisement) {
@@ -1362,7 +1359,7 @@ TEST_P(DiscoveredPeripheralTrackerTest,
fast_advertisement);
},
.instant_lost_cb =
[&mock_callback](BleV2Peripheral peripheral,
[&mock_callback](BlePeripheral peripheral,
const std::string& service_id,
const ByteArray& advertisement_bytes,
bool fast_advertisement) {
@@ -1373,7 +1370,7 @@ TEST_P(DiscoveredPeripheralTrackerTest,
},
{});
api::ble_v2::BleAdvertisementData advertisement_data{};
api::ble::BleAdvertisementData advertisement_data{};
if (!advertisement_header_bytes.Empty()) {
advertisement_data.service_data.insert(
{bleutils::kCopresenceServiceUuid, advertisement_header_bytes});
@@ -1391,7 +1388,7 @@ TEST_P(DiscoveredPeripheralTrackerTest,
std::list<std::string>({std::string(
bleutils::GenerateAdvertisementHash(advertisement_bytes))}));
ASSERT_OK(advertisement);
api::ble_v2::BleAdvertisementData loss_advertisement_data{};
api::ble::BleAdvertisementData loss_advertisement_data{};
loss_advertisement_data.service_data.insert(
{bleutils::kCopresenceServiceUuid, ByteArray(advertisement->ToBytes())});
@@ -1432,7 +1429,7 @@ TEST_P(DiscoveredPeripheralTrackerTest,
std::string(kServiceIdA), false, Pcp::kP2pPointToPoint,
{
.peripheral_discovered_cb =
[&found_latch](BleV2Peripheral peripheral,
[&found_latch](BlePeripheral peripheral,
const std::string& service_id,
const ByteArray& advertisement_bytes,
bool fast_advertisement) {
@@ -1442,13 +1439,13 @@ TEST_P(DiscoveredPeripheralTrackerTest,
},
.peripheral_lost_cb =
[&lost_latch](
BleV2Peripheral peripheral, const std::string& service_id,
BlePeripheral peripheral, const std::string& service_id,
const ByteArray& advertisement_bytes,
bool fast_advertisement) { lost_latch.CountDown(); },
},
Uuid(kFastAdvertisementServiceUuid));
api::ble_v2::BleAdvertisementData advertisement_data{};
api::ble::BleAdvertisementData advertisement_data{};
if (!fast_advertisement_bytes.Empty()) {
advertisement_data.service_data.insert(
{Uuid(kFastAdvertisementServiceUuid), fast_advertisement_bytes});
@@ -1463,7 +1460,7 @@ TEST_P(DiscoveredPeripheralTrackerTest,
auto advertisement = InstantOnLostAdvertisement::CreateFromHashes(
std::list<std::string>({std::string(advertisement_hash)}));
ASSERT_OK(advertisement);
api::ble_v2::BleAdvertisementData loss_advertisement_data{};
api::ble::BleAdvertisementData loss_advertisement_data{};
loss_advertisement_data.service_data.insert(
{bleutils::kCopresenceServiceUuid, ByteArray(advertisement->ToBytes())});
@@ -1479,7 +1476,7 @@ TEST_P(DiscoveredPeripheralTrackerTest, HandleDummyAdvertisement) {
.enable_invoking_legacy_device_discovered_cb = true,
};
MediumEnvironment::Instance().SetFeatureFlags(flag);
api::ble_v2::BleAdvertisementData advertising_data{};
api::ble::BleAdvertisementData advertising_data{};
advertising_data.is_extended_advertisement = false;
ByteArray encoded_bytes{
DiscoveredPeripheralTracker::kDummyAdvertisementValue};
@@ -1492,7 +1489,7 @@ TEST_P(DiscoveredPeripheralTrackerTest, HandleDummyAdvertisement) {
std::string(kServiceIdA), false, Pcp::kP2pPointToPoint,
{
.peripheral_discovered_cb =
[](BleV2Peripheral peripheral, const std::string& service_id,
[](BlePeripheral peripheral, const std::string& service_id,
const ByteArray& advertisement_bytes,
bool fast_advertisement) {
FAIL() << "Should NOT report found for dummy advertisement";
@@ -1515,7 +1512,7 @@ TEST_P(DiscoveredPeripheralTrackerTest, SkipDummyAdvertisement) {
.enable_invoking_legacy_device_discovered_cb = false,
};
MediumEnvironment::Instance().SetFeatureFlags(flag);
api::ble_v2::BleAdvertisementData advertising_data{};
api::ble::BleAdvertisementData advertising_data{};
advertising_data.is_extended_advertisement = false;
ByteArray encoded_bytes{
DiscoveredPeripheralTracker::kDummyAdvertisementValue};
@@ -1528,7 +1525,7 @@ TEST_P(DiscoveredPeripheralTrackerTest, SkipDummyAdvertisement) {
std::string(kServiceIdA), false, Pcp::kP2pPointToPoint,
{
.peripheral_discovered_cb =
[](BleV2Peripheral peripheral, const std::string& service_id,
[](BlePeripheral peripheral, const std::string& service_id,
const ByteArray& advertisement_bytes,
bool fast_advertisement) {
FAIL() << "Should NOT report found for dummy advertisement";
@@ -1565,7 +1562,7 @@ TEST_P(DiscoveredPeripheralTrackerTest, FetchGattAdvertisementInThread) {
std::string(kServiceIdA), false, Pcp::kP2pPointToPoint,
{
.peripheral_discovered_cb =
[&found_latch](BleV2Peripheral peripheral,
[&found_latch](BlePeripheral peripheral,
const std::string& service_id,
const ByteArray& advertisement_bytes,
bool fast_advertisement) {
@@ -1576,7 +1573,7 @@ TEST_P(DiscoveredPeripheralTrackerTest, FetchGattAdvertisementInThread) {
},
{});
api::ble_v2::BleAdvertisementData advertisement_data{};
api::ble::BleAdvertisementData advertisement_data{};
if (!advertisement_header_bytes.Empty()) {
advertisement_data.service_data.insert(
{bleutils::kCopresenceServiceUuid, advertisement_header_bytes});
@@ -1612,7 +1609,7 @@ TEST_P(DiscoveredPeripheralTrackerTest,
std::string(kServiceIdA), false, Pcp::kP2pPointToPoint,
{
.peripheral_discovered_cb =
[&found_latch](BleV2Peripheral peripheral,
[&found_latch](BlePeripheral peripheral,
const std::string& service_id,
const ByteArray& advertisement_bytes,
bool fast_advertisement) {
@@ -1623,7 +1620,7 @@ TEST_P(DiscoveredPeripheralTrackerTest,
},
{});
api::ble_v2::BleAdvertisementData advertisement_data{};
api::ble::BleAdvertisementData advertisement_data{};
if (!advertisement_header_bytes.Empty()) {
advertisement_data.service_data.insert(
{bleutils::kCopresenceServiceUuid, advertisement_header_bytes});
@@ -1665,7 +1662,7 @@ TEST_P(DiscoveredPeripheralTrackerTest,
std::string(kServiceIdA), false, Pcp::kP2pPointToPoint,
{
.peripheral_discovered_cb =
[&found_latch](BleV2Peripheral peripheral,
[&found_latch](BlePeripheral peripheral,
const std::string& service_id,
const ByteArray& advertisement_bytes,
bool fast_advertisement) {
@@ -1675,7 +1672,7 @@ TEST_P(DiscoveredPeripheralTrackerTest,
},
{});
api::ble_v2::BleAdvertisementData advertisement_data{};
api::ble::BleAdvertisementData advertisement_data{};
if (!advertisement_header_bytes.Empty()) {
advertisement_data.service_data.insert(
{bleutils::kCopresenceServiceUuid, advertisement_header_bytes});
@@ -1684,7 +1681,7 @@ TEST_P(DiscoveredPeripheralTrackerTest,
FindAdvertisementWithDelay(advertisement_data, {advertisement_bytes},
fetch_latch, kDefaultGattFetchDelay);
api::ble_v2::BleAdvertisementData advertisement_data_2{};
api::ble::BleAdvertisementData advertisement_data_2{};
if (!advertisement_header_bytes_2.Empty()) {
advertisement_data_2.service_data.insert(
{bleutils::kCopresenceServiceUuid, advertisement_header_bytes_2});
@@ -1724,7 +1721,7 @@ TEST_P(DiscoveredPeripheralTrackerTest,
std::string(kServiceIdA), false, Pcp::kP2pPointToPoint,
{
.peripheral_discovered_cb =
[&found_latch](BleV2Peripheral peripheral,
[&found_latch](BlePeripheral peripheral,
const std::string& service_id,
const ByteArray& advertisement_bytes,
bool fast_advertisement) {
@@ -1736,7 +1733,7 @@ TEST_P(DiscoveredPeripheralTrackerTest,
bleutils::kCopresenceServiceUuid);
// 1. First receive a GATT advertisement data, it should be skipped.
api::ble_v2::BleAdvertisementData advertisement_data{};
api::ble::BleAdvertisementData advertisement_data{};
if (!advertisement_header_bytes.Empty()) {
advertisement_data.service_data.insert(
{bleutils::kCopresenceServiceUuid, advertisement_header_bytes});
@@ -1745,7 +1742,7 @@ TEST_P(DiscoveredPeripheralTrackerTest,
FindAdvertisement(advertisement_data, {advertisement_bytes}, fetch_latch);
// 2. Receive extended advertisement data first.
api::ble_v2::BleAdvertisementData extended_advertisement_data{};
api::ble::BleAdvertisementData extended_advertisement_data{};
extended_advertisement_data.is_extended_advertisement = true;
extended_advertisement_data.service_data.insert(
{bleutils::kCopresenceServiceUuid, advertisement_bytes});
@@ -1786,7 +1783,7 @@ TEST_P(DiscoveredPeripheralTrackerTest,
std::string(kServiceIdA), false, Pcp::kP2pPointToPoint,
{
.peripheral_discovered_cb =
[&found_latch](BleV2Peripheral peripheral,
[&found_latch](BlePeripheral peripheral,
const std::string& service_id,
const ByteArray& advertisement_bytes,
bool fast_advertisement) {
@@ -1798,7 +1795,7 @@ TEST_P(DiscoveredPeripheralTrackerTest,
bleutils::kCopresenceServiceUuid);
// 1. First receive a GATT advertisement data, it should be skipped.
api::ble_v2::BleAdvertisementData advertisement_data{};
api::ble::BleAdvertisementData advertisement_data{};
if (!advertisement_header_bytes.Empty()) {
advertisement_data.service_data.insert(
{bleutils::kCopresenceServiceUuid, advertisement_header_bytes});
@@ -1844,7 +1841,7 @@ TEST_P(DiscoveredPeripheralTrackerTest, SkipExpiredGattAdvertisement) {
std::string(kServiceIdA), false, Pcp::kP2pPointToPoint,
{
.peripheral_discovered_cb =
[&found_latch](BleV2Peripheral peripheral,
[&found_latch](BlePeripheral peripheral,
const std::string& service_id,
const ByteArray& advertisement_bytes,
bool fast_advertisement) {
@@ -1856,7 +1853,7 @@ TEST_P(DiscoveredPeripheralTrackerTest, SkipExpiredGattAdvertisement) {
bleutils::kCopresenceServiceUuid);
// 1. First receive a GATT advertisement data, it should be skipped.
api::ble_v2::BleAdvertisementData advertisement_data{};
api::ble::BleAdvertisementData advertisement_data{};
if (!advertisement_header_bytes.Empty()) {
advertisement_data.service_data.insert(
{bleutils::kCopresenceServiceUuid, advertisement_header_bytes});
@@ -1905,7 +1902,7 @@ TEST_P(DiscoveredPeripheralTrackerTest,
{
.peripheral_discovered_cb =
[&found_latch, &callback_count](
BleV2Peripheral peripheral, const std::string& service_id,
BlePeripheral peripheral, const std::string& service_id,
const ByteArray& advertisement_bytes,
bool fast_advertisement) {
++callback_count;
@@ -1916,7 +1913,7 @@ TEST_P(DiscoveredPeripheralTrackerTest,
(*fake_clock)->FastForward(absl::Seconds(4));
// 1. Received extended advertisement.
api::ble_v2::BleAdvertisementData extended_advertisement_data{};
api::ble::BleAdvertisementData extended_advertisement_data{};
extended_advertisement_data.is_extended_advertisement = true;
extended_advertisement_data.service_data.insert(
{bleutils::kCopresenceServiceUuid, advertisement_bytes});
@@ -1924,7 +1921,7 @@ TEST_P(DiscoveredPeripheralTrackerTest,
FindExtendedAdvertisement(extended_advertisement_data, fetch_latch);
// 2. Received GATT advertisement.
api::ble_v2::BleAdvertisementData advertisement_data{};
api::ble::BleAdvertisementData advertisement_data{};
if (!advertisement_header_bytes.Empty()) {
advertisement_data.service_data.insert(
{bleutils::kCopresenceServiceUuid, advertisement_header_bytes});
@@ -1979,7 +1976,7 @@ TEST_P(DiscoveredPeripheralTrackerTest,
{
.peripheral_discovered_cb =
[&found_latch, &discovered_peripheral_order](
BleV2Peripheral peripheral, const std::string& service_id,
BlePeripheral peripheral, const std::string& service_id,
const ByteArray& advertisement_bytes,
bool fast_advertisement) {
discovered_peripheral_order.push_back(
@@ -1991,20 +1988,20 @@ TEST_P(DiscoveredPeripheralTrackerTest,
(*fake_clock)->FastForward(absl::Seconds(4));
// 1. Find peripheral A with GATT advertisement.
api::ble_v2::BleAdvertisementData advertisement_data_a{};
api::ble::BleAdvertisementData advertisement_data_a{};
advertisement_data_a.service_data.insert(
{bleutils::kCopresenceServiceUuid, advertisement_header_a});
FindAdvertisementWithDelay(advertisement_data_a, {advertisement_a},
fetch_latch, kDefaultGattFetchDelay);
// 2. Find peripheral B with extended advertisement.
api::ble_v2::BleAdvertisementData advertisement_data_b{};
api::ble::BleAdvertisementData advertisement_data_b{};
advertisement_data_b.service_data.insert(
{bleutils::kCopresenceServiceUuid, advertisement_header_b});
FindAdvertisement(advertisement_data_b, {advertisement_b}, fetch_latch);
// 3. Find peripheral C with GATT advertisement.
api::ble_v2::BleAdvertisementData advertisement_data_c{};
api::ble::BleAdvertisementData advertisement_data_c{};
advertisement_data_c.service_data.insert(
{bleutils::kCopresenceServiceUuid, advertisement_header_c});
FindAdvertisement(advertisement_data_c, {advertisement_c}, fetch_latch);
@@ -12,7 +12,7 @@
// See the License for the specific language governing permissions and
// limitations under the License.
#include "connections/implementation/mediums/ble_v2/instant_on_lost_advertisement.h"
#include "connections/implementation/mediums/ble/instant_on_lost_advertisement.h"
#include <cstdint>
#include <list>
@@ -24,7 +24,7 @@
#include "absl/strings/str_cat.h"
#include "absl/strings/str_format.h"
#include "absl/strings/string_view.h"
#include "connections/implementation/mediums/ble_v2/ble_advertisement_header.h"
#include "connections/implementation/mediums/ble/ble_advertisement_header.h"
#include "internal/platform/logging.h"
namespace nearby {
@@ -12,8 +12,8 @@
// See the License for the specific language governing permissions and
// limitations under the License.
#ifndef THIRD_PARTY_NEARBY_CONNECTIONS_IMPLEMENTATION_MEDIUMS_BLE_V2_INSTANT_ON_LOST_ADVERTISEMENT_H_
#define THIRD_PARTY_NEARBY_CONNECTIONS_IMPLEMENTATION_MEDIUMS_BLE_V2_INSTANT_ON_LOST_ADVERTISEMENT_H_
#ifndef THIRD_PARTY_NEARBY_CONNECTIONS_IMPLEMENTATION_MEDIUMS_BLE_INSTANT_ON_LOST_ADVERTISEMENT_H_
#define THIRD_PARTY_NEARBY_CONNECTIONS_IMPLEMENTATION_MEDIUMS_BLE_INSTANT_ON_LOST_ADVERTISEMENT_H_
#include <list>
#include <string>
@@ -64,4 +64,4 @@ class InstantOnLostAdvertisement {
} // namespace connections
} // namespace nearby
#endif // THIRD_PARTY_NEARBY_CONNECTIONS_IMPLEMENTATION_MEDIUMS_BLE_V2_INSTANT_ON_LOST_ADVERTISEMENT_H_
#endif // THIRD_PARTY_NEARBY_CONNECTIONS_IMPLEMENTATION_MEDIUMS_BLE_INSTANT_ON_LOST_ADVERTISEMENT_H_
@@ -12,7 +12,7 @@
// See the License for the specific language governing permissions and
// limitations under the License.
#include "connections/implementation/mediums/ble_v2/instant_on_lost_advertisement.h"
#include "connections/implementation/mediums/ble/instant_on_lost_advertisement.h"
#include <array>
#include <list>
@@ -12,7 +12,7 @@
// See the License for the specific language governing permissions and
// limitations under the License.
#include "connections/implementation/mediums/ble_v2/instant_on_lost_manager.h"
#include "connections/implementation/mediums/ble/instant_on_lost_manager.h"
#include <list>
#include <memory>
@@ -24,15 +24,15 @@
#include "absl/strings/string_view.h"
#include "absl/time/time.h"
#include "connections/implementation/flags/nearby_connections_feature_flags.h"
#include "connections/implementation/mediums/ble_v2/ble_utils.h"
#include "connections/implementation/mediums/ble_v2/instant_on_lost_advertisement.h"
#include "connections/implementation/mediums/ble/ble_utils.h"
#include "connections/implementation/mediums/ble/instant_on_lost_advertisement.h"
#include "internal/flags/nearby_flags.h"
#include "internal/platform/ble_v2.h"
#include "internal/platform/ble.h"
#include "internal/platform/byte_array.h"
#include "internal/platform/cancelable_alarm.h"
#include "internal/platform/count_down_latch.h"
#include "internal/platform/exception.h"
#include "internal/platform/implementation/ble_v2.h"
#include "internal/platform/implementation/ble.h"
#include "internal/platform/implementation/system_clock.h"
#include "internal/platform/logging.h"
@@ -185,10 +185,10 @@ bool InstantOnLostManager::IsOnLostAdvertisingForTesting() {
}
bool InstantOnLostManager::StartInstantOnLostAdvertisement() {
api::ble_v2::BleAdvertisementData advertisement_data;
api::ble_v2::AdvertiseParameters advertise_parameters;
api::ble::BleAdvertisementData advertisement_data;
api::ble::AdvertiseParameters advertise_parameters;
advertise_parameters.is_connectable = false;
advertise_parameters.tx_power_level = api::ble_v2::TxPowerLevel::kHigh;
advertise_parameters.tx_power_level = api::ble::TxPowerLevel::kHigh;
RemoveExpiredOnLostAdvertisements();
absl::StatusOr<InstantOnLostAdvertisement> on_lost_advertisement =
@@ -12,8 +12,8 @@
// See the License for the specific language governing permissions and
// limitations under the License.
#ifndef THIRD_PARTY_NEARBY_CONNECTIONS_IMPLEMENTATION_MEDIUMS_BLE_V2_INSTANT_ON_LOST_MANAGER_H_
#define THIRD_PARTY_NEARBY_CONNECTIONS_IMPLEMENTATION_MEDIUMS_BLE_V2_INSTANT_ON_LOST_MANAGER_H_
#ifndef THIRD_PARTY_NEARBY_CONNECTIONS_IMPLEMENTATION_MEDIUMS_BLE_INSTANT_ON_LOST_MANAGER_H_
#define THIRD_PARTY_NEARBY_CONNECTIONS_IMPLEMENTATION_MEDIUMS_BLE_INSTANT_ON_LOST_MANAGER_H_
#include <list>
#include <memory>
@@ -23,7 +23,7 @@
#include "absl/functional/any_invocable.h"
#include "absl/strings/string_view.h"
#include "absl/time/time.h"
#include "internal/platform/ble_v2.h"
#include "internal/platform/ble.h"
#include "internal/platform/bluetooth_adapter.h"
#include "internal/platform/byte_array.h"
#include "internal/platform/cancelable_alarm.h"
@@ -74,7 +74,7 @@ class InstantOnLostManager {
// BLE medium used for lost packet advertising.
BluetoothAdapter adapter_;
BleV2Medium ble_medium_ = BleV2Medium{adapter_};
BleMedium ble_medium_ = BleMedium{adapter_};
bool is_on_lost_advertising_ = false;
absl::Time last_advertising_start_time_ = absl::InfinitePast();
@@ -89,4 +89,4 @@ class InstantOnLostManager {
} // namespace connections
} // namespace nearby
#endif // THIRD_PARTY_NEARBY_CONNECTIONS_IMPLEMENTATION_MEDIUMS_BLE_V2_INSTANT_ON_LOST_MANAGER_H_
#endif // THIRD_PARTY_NEARBY_CONNECTIONS_IMPLEMENTATION_MEDIUMS_BLE_INSTANT_ON_LOST_MANAGER_H_
@@ -12,7 +12,7 @@
// See the License for the specific language governing permissions and
// limitations under the License.
#include "connections/implementation/mediums/ble_v2/instant_on_lost_manager.h"
#include "connections/implementation/mediums/ble/instant_on_lost_manager.h"
#include <memory>
#include <string>
@@ -12,7 +12,7 @@
// See the License for the specific language governing permissions and
// limitations under the License.
#include "connections/implementation/mediums/ble_v2.h"
#include "connections/implementation/mediums/ble.h"
#include <cstdint>
#include <string>
@@ -22,12 +22,12 @@
#include "absl/strings/string_view.h"
#include "absl/time/time.h"
#include "connections/implementation/flags/nearby_connections_feature_flags.h"
#include "connections/implementation/mediums/ble_v2/discovered_peripheral_callback.h"
#include "connections/implementation/mediums/ble/discovered_peripheral_callback.h"
#include "connections/implementation/mediums/bluetooth_radio.h"
#include "connections/implementation/pcp.h"
#include "connections/power_level.h"
#include "internal/flags/nearby_flags.h"
#include "internal/platform/ble_v2.h"
#include "internal/platform/ble.h"
#include "internal/platform/byte_array.h"
#include "internal/platform/cancellation_flag.h"
#include "internal/platform/count_down_latch.h"
@@ -63,7 +63,7 @@ constexpr absl::string_view kAdvertisementStringB = "\x01\x02\x03\x04";
constexpr absl::string_view kLocalEndpointId = "local_endpoint_id";
constexpr absl::string_view kFastAdvertisementServiceUuid{"\xf3\xfe"};
class BleV2Test : public testing::TestWithParam<FeatureFlags> {
class BleTest : public testing::TestWithParam<FeatureFlags> {
public:
void SetUp() override {
NearbyFlags::GetInstance().OverrideInt64FlagValue(
@@ -76,14 +76,14 @@ class BleV2Test : public testing::TestWithParam<FeatureFlags> {
MediumEnvironment& env_{MediumEnvironment::Instance()};
};
TEST_P(BleV2Test, CanConnect) {
TEST_P(BleTest, CanConnect) {
FeatureFlags feature_flags = GetParam();
env_.SetFeatureFlags(feature_flags);
env_.Start();
BluetoothRadio radio_client;
BluetoothRadio radio_server;
BleV2 ble_client{radio_client};
BleV2 ble_server{radio_server};
Ble ble_client{radio_client};
Ble ble_server{radio_server};
radio_client.Enable();
radio_server.Enable();
std::string service_id(kServiceIDA);
@@ -91,25 +91,24 @@ TEST_P(BleV2Test, CanConnect) {
CountDownLatch discovered_latch(1);
CountDownLatch accept_latch(1);
BleV2Socket socket_for_server;
BleSocket socket_for_server;
EXPECT_TRUE(ble_server.StartAcceptingConnections(
service_id, [&](BleV2Socket socket, const std::string&) {
service_id, [&](BleSocket socket, const std::string&) {
socket_for_server = std::move(socket);
accept_latch.CountDown();
}));
ble_server.StartAdvertising(service_id, PowerLevel::kHighPower,
BleV2::AdvertisingType::kFast,
advertisement_bytes);
Ble::AdvertisingType::kFast, advertisement_bytes);
BleV2Peripheral discovered_peripheral;
BlePeripheral discovered_peripheral;
ble_client.StartScanning(
service_id, Pcp::kP2pPointToPoint, PowerLevel::kHighPower,
/*include_dct_advertisement=*/false,
mediums::DiscoveredPeripheralCallback{
.peripheral_discovered_cb =
[&discovered_latch, &discovered_peripheral](
BleV2Peripheral peripheral, const std::string& service_id,
BlePeripheral peripheral, const std::string& service_id,
const ByteArray& advertisement_bytes,
bool fast_advertisement) {
discovered_peripheral = peripheral;
@@ -122,7 +121,7 @@ TEST_P(BleV2Test, CanConnect) {
ASSERT_TRUE(discovered_peripheral.IsValid());
CancellationFlag flag;
ErrorOr<BleV2Socket> socket_for_client_result =
ErrorOr<BleSocket> socket_for_client_result =
ble_client.Connect(service_id, discovered_peripheral, &flag);
EXPECT_TRUE(accept_latch.Await(kWaitDuration).result());
EXPECT_TRUE(ble_server.StopAcceptingConnections(service_id));
@@ -135,14 +134,14 @@ TEST_P(BleV2Test, CanConnect) {
env_.Stop();
}
TEST_P(BleV2Test, CanCancelConnect) {
TEST_P(BleTest, CanCancelConnect) {
FeatureFlags feature_flags = GetParam();
env_.SetFeatureFlags(feature_flags);
env_.Start();
BluetoothRadio radio_client;
BluetoothRadio radio_server;
BleV2 ble_client{radio_client};
BleV2 ble_server{radio_server};
Ble ble_client{radio_client};
Ble ble_server{radio_server};
radio_client.Enable();
radio_server.Enable();
std::string service_id(kServiceIDA);
@@ -150,25 +149,24 @@ TEST_P(BleV2Test, CanCancelConnect) {
CountDownLatch discovered_latch(1);
CountDownLatch accept_latch(1);
BleV2Socket socket_for_server;
BleSocket socket_for_server;
EXPECT_TRUE(ble_server.StartAcceptingConnections(
service_id, [&](BleV2Socket socket, const std::string&) {
service_id, [&](BleSocket socket, const std::string&) {
socket_for_server = std::move(socket);
accept_latch.CountDown();
}));
ble_server.StartAdvertising(service_id, PowerLevel::kHighPower,
BleV2::AdvertisingType::kFast,
advertisement_bytes);
Ble::AdvertisingType::kFast, advertisement_bytes);
BleV2Peripheral discovered_peripheral;
BlePeripheral discovered_peripheral;
ble_client.StartScanning(
service_id, Pcp::kP2pPointToPoint, PowerLevel::kHighPower,
/*include_dct_advertisement=*/false,
mediums::DiscoveredPeripheralCallback{
.peripheral_discovered_cb =
[&discovered_latch, &discovered_peripheral](
BleV2Peripheral peripheral, const std::string& service_id,
BlePeripheral peripheral, const std::string& service_id,
const ByteArray& advertisement_bytes,
bool fast_advertisement) {
discovered_peripheral = peripheral;
@@ -181,7 +179,7 @@ TEST_P(BleV2Test, CanCancelConnect) {
ASSERT_TRUE(discovered_peripheral.IsValid());
CancellationFlag flag(true);
ErrorOr<BleV2Socket> socket_for_client_result =
ErrorOr<BleSocket> socket_for_client_result =
ble_client.Connect(service_id, discovered_peripheral, &flag);
// If FeatureFlag is disabled, Cancelled is false as no-op.
if (!feature_flags.enable_cancellation_flag) {
@@ -204,15 +202,15 @@ TEST_P(BleV2Test, CanCancelConnect) {
env_.Stop();
}
INSTANTIATE_TEST_SUITE_P(ParametrisedBleTest, BleV2Test,
INSTANTIATE_TEST_SUITE_P(ParametrisedBleTest, BleTest,
::testing::ValuesIn(kTestCases));
TEST_F(BleV2Test, CanConstructValidObject) {
TEST_F(BleTest, CanConstructValidObject) {
env_.Start();
BluetoothRadio radio_a;
BluetoothRadio radio_b;
BleV2 ble_a(radio_a);
BleV2 ble_b(radio_b);
Ble ble_a(radio_a);
Ble ble_b(radio_b);
EXPECT_TRUE(ble_a.IsMediumValid());
EXPECT_TRUE(ble_a.IsAvailable());
@@ -222,74 +220,74 @@ TEST_F(BleV2Test, CanConstructValidObject) {
env_.Stop();
}
TEST_F(BleV2Test, CanNotStartAdvertisingWithEmptyAdvertisementBytes) {
TEST_F(BleTest, CanNotStartAdvertisingWithEmptyAdvertisementBytes) {
env_.Start();
BluetoothRadio radio_a;
BleV2 ble_a(radio_a);
Ble ble_a(radio_a);
radio_a.Enable();
ByteArray advertisement_bytes;
EXPECT_FALSE(ble_a.StartAdvertising(
std::string(kServiceIDA), PowerLevel::kHighPower,
BleV2::AdvertisingType::kRegular, advertisement_bytes));
Ble::AdvertisingType::kRegular, advertisement_bytes));
env_.Stop();
}
TEST_F(BleV2Test, CanNotStartAdvertisingWhenRadioNotEnabled) {
TEST_F(BleTest, CanNotStartAdvertisingWhenRadioNotEnabled) {
env_.Start();
BluetoothRadio radio_a;
BleV2 ble_a(radio_a);
Ble ble_a(radio_a);
radio_a.Disable();
ByteArray advertisement_bytes((std::string(kAdvertisementString)));
EXPECT_FALSE(ble_a.StartAdvertising(
std::string(kServiceIDA), PowerLevel::kHighPower,
BleV2::AdvertisingType::kRegular, advertisement_bytes));
Ble::AdvertisingType::kRegular, advertisement_bytes));
env_.Stop();
}
TEST_F(BleV2Test, CanStartAdvertisingWithDifferentPowerLevels) {
TEST_F(BleTest, CanStartAdvertisingWithDifferentPowerLevels) {
env_.Start();
BluetoothRadio radio_a;
BleV2 ble_a(radio_a);
Ble ble_a(radio_a);
radio_a.Enable();
ByteArray advertisement_bytes((std::string(kAdvertisementString)));
EXPECT_TRUE(ble_a.StartAdvertising(
std::string(kServiceIDA), PowerLevel::kLowPower,
BleV2::AdvertisingType::kRegular, advertisement_bytes));
Ble::AdvertisingType::kRegular, advertisement_bytes));
EXPECT_TRUE(ble_a.StopAdvertising(std::string(kServiceIDA)));
EXPECT_TRUE(ble_a.StartAdvertising(
std::string(kServiceIDA), PowerLevel::kHighPower,
BleV2::AdvertisingType::kRegular, advertisement_bytes));
Ble::AdvertisingType::kRegular, advertisement_bytes));
EXPECT_TRUE(ble_a.StopAdvertising(std::string(kServiceIDA)));
env_.Stop();
}
TEST_F(BleV2Test, CanStartAdvertisingWithDifferentAdvertisingTypes) {
TEST_F(BleTest, CanStartAdvertisingWithDifferentAdvertisingTypes) {
env_.Start();
BluetoothRadio radio_a;
BleV2 ble_a(radio_a);
Ble ble_a(radio_a);
radio_a.Enable();
ByteArray advertisement_bytes((std::string(kAdvertisementString)));
EXPECT_TRUE(ble_a.StartAdvertising(
std::string(kServiceIDA), PowerLevel::kHighPower,
BleV2::AdvertisingType::kRegular, advertisement_bytes));
Ble::AdvertisingType::kRegular, advertisement_bytes));
EXPECT_TRUE(ble_a.StopAdvertising(std::string(kServiceIDA)));
EXPECT_TRUE(ble_a.StartAdvertising(
std::string(kServiceIDA), PowerLevel::kHighPower,
BleV2::AdvertisingType::kFast, advertisement_bytes));
EXPECT_TRUE(
ble_a.StartAdvertising(std::string(kServiceIDA), PowerLevel::kHighPower,
Ble::AdvertisingType::kFast, advertisement_bytes));
EXPECT_TRUE(ble_a.StopAdvertising(std::string(kServiceIDA)));
env_.Stop();
}
TEST_F(BleV2Test, CanStartFastAdvertising) {
TEST_F(BleTest, CanStartFastAdvertising) {
env_.Start();
BluetoothRadio radio_a;
BluetoothRadio radio_b;
BleV2 ble_a(radio_a);
BleV2 ble_b(radio_b);
Ble ble_a(radio_a);
Ble ble_b(radio_b);
radio_a.Enable();
radio_b.Enable();
ByteArray advertisement_bytes((std::string(kAdvertisementString)));
@@ -300,7 +298,7 @@ TEST_F(BleV2Test, CanStartFastAdvertising) {
/*include_dct_advertisement=*/false,
mediums::DiscoveredPeripheralCallback{
.peripheral_discovered_cb =
[&found_latch](BleV2Peripheral peripheral,
[&found_latch](BlePeripheral peripheral,
const std::string& service_id,
const ByteArray& advertisement_bytes,
bool fast_advertisement) {
@@ -309,35 +307,35 @@ TEST_F(BleV2Test, CanStartFastAdvertising) {
},
});
EXPECT_TRUE(ble_a.StartAdvertising(
std::string(kServiceIDA), PowerLevel::kHighPower,
BleV2::AdvertisingType::kFast, advertisement_bytes));
EXPECT_TRUE(
ble_a.StartAdvertising(std::string(kServiceIDA), PowerLevel::kHighPower,
Ble::AdvertisingType::kFast, advertisement_bytes));
EXPECT_TRUE(found_latch.Await(kWaitDuration).result());
EXPECT_TRUE(ble_a.StopAdvertising(std::string(kServiceIDA)));
ble_b.StopScanning(std::string(kServiceIDA));
env_.Stop();
}
TEST_F(BleV2Test, CanStartFastScanning) {
TEST_F(BleTest, CanStartFastScanning) {
env_.Start();
BluetoothRadio radio_a;
BluetoothRadio radio_b;
BleV2 ble_a(radio_a);
BleV2 ble_b(radio_b);
Ble ble_a(radio_a);
Ble ble_b(radio_b);
radio_a.Enable();
radio_b.Enable();
ByteArray advertisement_bytes((std::string(kAdvertisementString)));
CountDownLatch found_latch(1);
ble_b.StartAdvertising(std::string(kServiceIDA), PowerLevel::kHighPower,
BleV2::AdvertisingType::kFast, advertisement_bytes);
Ble::AdvertisingType::kFast, advertisement_bytes);
EXPECT_TRUE(ble_a.StartScanning(
std::string(kServiceIDA), Pcp::kP2pPointToPoint, PowerLevel::kHighPower,
/*include_dct_advertisement=*/false,
mediums::DiscoveredPeripheralCallback{
.peripheral_discovered_cb =
[&found_latch](BleV2Peripheral peripheral,
[&found_latch](BlePeripheral peripheral,
const std::string& service_id,
const ByteArray& advertisement_bytes,
bool fast_advertisement) {
@@ -352,12 +350,12 @@ TEST_F(BleV2Test, CanStartFastScanning) {
env_.Stop();
}
TEST_F(BleV2Test, CanStartAdvertising) {
TEST_F(BleTest, CanStartAdvertising) {
env_.Start();
BluetoothRadio radio_a;
BluetoothRadio radio_b;
BleV2 ble_a(radio_a);
BleV2 ble_b(radio_b);
Ble ble_a(radio_a);
Ble ble_b(radio_b);
radio_a.Enable();
radio_b.Enable();
ByteArray advertisement_bytes((std::string(kAdvertisementString)));
@@ -368,7 +366,7 @@ TEST_F(BleV2Test, CanStartAdvertising) {
/*include_dct_advertisement=*/false,
mediums::DiscoveredPeripheralCallback{
.peripheral_discovered_cb =
[&found_latch](BleV2Peripheral peripheral,
[&found_latch](BlePeripheral peripheral,
const std::string& service_id,
const ByteArray& advertisement_bytes,
bool fast_advertisement) {
@@ -379,33 +377,33 @@ TEST_F(BleV2Test, CanStartAdvertising) {
EXPECT_TRUE(ble_a.StartAdvertising(
std::string(kServiceIDA), PowerLevel::kHighPower,
BleV2::AdvertisingType::kRegular, advertisement_bytes));
Ble::AdvertisingType::kRegular, advertisement_bytes));
EXPECT_TRUE(found_latch.Await(kWaitDuration).result());
EXPECT_TRUE(ble_a.StopAdvertising(std::string(kServiceIDA)));
ble_b.StopScanning(std::string(kServiceIDA));
env_.Stop();
}
TEST_F(BleV2Test, CanStartScanning) {
TEST_F(BleTest, CanStartScanning) {
env_.Start();
BluetoothRadio radio_a;
BluetoothRadio radio_b;
BleV2 ble_a(radio_a);
BleV2 ble_b(radio_b);
Ble ble_a(radio_a);
Ble ble_b(radio_b);
radio_a.Enable();
radio_b.Enable();
ByteArray advertisement_bytes((std::string(kAdvertisementString)));
CountDownLatch found_latch(1);
ble_b.StartAdvertising(std::string(kServiceIDA), PowerLevel::kHighPower,
BleV2::AdvertisingType::kRegular, advertisement_bytes);
Ble::AdvertisingType::kRegular, advertisement_bytes);
EXPECT_TRUE(ble_a.StartScanning(
std::string(kServiceIDA), Pcp::kP2pPointToPoint, PowerLevel::kHighPower,
/*include_dct_advertisement=*/false,
mediums::DiscoveredPeripheralCallback{
.peripheral_discovered_cb =
[&found_latch](BleV2Peripheral peripheral,
[&found_latch](BlePeripheral peripheral,
const std::string& service_id,
const ByteArray& advertisement_bytes,
bool fast_advertisement) {
@@ -420,10 +418,10 @@ TEST_F(BleV2Test, CanStartScanning) {
env_.Stop();
}
TEST_F(BleV2Test, CanNotStartScanningWhenRadioNotEnabled) {
TEST_F(BleTest, CanNotStartScanningWhenRadioNotEnabled) {
env_.Start();
BluetoothRadio radio_a;
BleV2 ble_a(radio_a);
Ble ble_a(radio_a);
radio_a.Disable();
EXPECT_FALSE(ble_a.StartScanning(
@@ -433,22 +431,21 @@ TEST_F(BleV2Test, CanNotStartScanningWhenRadioNotEnabled) {
env_.Stop();
}
TEST_F(BleV2Test, CanNotStartAcceptingConnectionsWhenRadioNotEnabled) {
TEST_F(BleTest, CanNotStartAcceptingConnectionsWhenRadioNotEnabled) {
env_.Start();
BluetoothRadio radio_a;
BleV2 ble_a(radio_a);
Ble ble_a(radio_a);
radio_a.Disable();
EXPECT_FALSE(ble_a.StartAcceptingConnections(
std::string(kServiceIDA),
[&](BleV2Socket socket, const std::string&) {}));
std::string(kServiceIDA), [&](BleSocket socket, const std::string&) {}));
env_.Stop();
}
TEST_F(BleV2Test, CanStartScanningWithDifferentPowerLevels) {
TEST_F(BleTest, CanStartScanningWithDifferentPowerLevels) {
env_.Start();
BluetoothRadio radio_a;
BleV2 ble_a(radio_a);
Ble ble_a(radio_a);
radio_a.Enable();
EXPECT_TRUE(ble_a.StartScanning(std::string(kServiceIDA),
@@ -464,40 +461,40 @@ TEST_F(BleV2Test, CanStartScanningWithDifferentPowerLevels) {
env_.Stop();
}
TEST_F(BleV2Test, CanNotConnectWithInvalidPeripheral) {
TEST_F(BleTest, CanNotConnectWithInvalidPeripheral) {
env_.Start();
BluetoothRadio radio_client;
BleV2 ble_client{radio_client};
Ble ble_client{radio_client};
radio_client.Enable();
std::string service_id(kServiceIDA);
BleV2Peripheral invalid_peripheral;
BlePeripheral invalid_peripheral;
CancellationFlag flag;
ErrorOr<BleV2Socket> socket_for_client_result =
ErrorOr<BleSocket> socket_for_client_result =
ble_client.Connect(service_id, invalid_peripheral, &flag);
EXPECT_TRUE(socket_for_client_result.has_error());
env_.Stop();
}
TEST_F(BleV2Test, CanNotConnectWithEmptyServiceId) {
TEST_F(BleTest, CanNotConnectWithEmptyServiceId) {
env_.Start();
BluetoothRadio radio_client;
BleV2 ble_client{radio_client};
Ble ble_client{radio_client};
radio_client.Enable();
std::string empty_service_id;
BleV2Peripheral peripheral;
BlePeripheral peripheral;
CancellationFlag flag;
ErrorOr<BleV2Socket> socket_for_client_result =
ErrorOr<BleSocket> socket_for_client_result =
ble_client.Connect(empty_service_id, peripheral, &flag);
EXPECT_TRUE(socket_for_client_result.has_error());
env_.Stop();
}
TEST_F(BleV2Test, CanStartStopMultipleScanningWithDifferentServiceIds) {
TEST_F(BleTest, CanStartStopMultipleScanningWithDifferentServiceIds) {
env_.Start();
BluetoothRadio radio;
BleV2 ble(radio);
Ble ble(radio);
radio.Enable();
EXPECT_TRUE(ble.StartScanning(std::string(kServiceIDA), Pcp::kP2pPointToPoint,
@@ -519,24 +516,24 @@ TEST_F(BleV2Test, CanStartStopMultipleScanningWithDifferentServiceIds) {
env_.Stop();
}
TEST_F(BleV2Test, DestructWorksForStartAdvertisingAndScanningWithoutStop) {
TEST_F(BleTest, DestructWorksForStartAdvertisingAndScanningWithoutStop) {
env_.Start();
BluetoothRadio radio_a;
BluetoothRadio radio_b;
BleV2 ble_a(radio_a);
BleV2 ble_b(radio_b);
Ble ble_a(radio_a);
Ble ble_b(radio_b);
radio_a.Enable();
radio_b.Enable();
ByteArray advertisement_bytes((std::string(kAdvertisementString)));
// Device A starts advertising with service IDA and IDB.
EXPECT_TRUE(ble_a.StartAdvertising(
std::string(kServiceIDA), PowerLevel::kHighPower,
BleV2::AdvertisingType::kFast, advertisement_bytes));
EXPECT_TRUE(ble_a.StartAdvertising(
std::string(kServiceIDB), PowerLevel::kHighPower,
BleV2::AdvertisingType::kFast, advertisement_bytes));
EXPECT_TRUE(
ble_a.StartAdvertising(std::string(kServiceIDA), PowerLevel::kHighPower,
Ble::AdvertisingType::kFast, advertisement_bytes));
EXPECT_TRUE(
ble_a.StartAdvertising(std::string(kServiceIDB), PowerLevel::kHighPower,
Ble::AdvertisingType::kFast, advertisement_bytes));
// Device B starts scanning with service IDA and IDB
EXPECT_TRUE(ble_b.StartScanning(std::string(kServiceIDA),
@@ -550,12 +547,12 @@ TEST_F(BleV2Test, DestructWorksForStartAdvertisingAndScanningWithoutStop) {
env_.Stop();
}
TEST_F(BleV2Test, StartFastScanningDiscoverAndLostPeripheral) {
TEST_F(BleTest, StartFastScanningDiscoverAndLostPeripheral) {
env_.Start();
BluetoothRadio radio_a;
BluetoothRadio radio_b;
BleV2 ble_a(radio_a);
BleV2 ble_b(radio_b);
Ble ble_a(radio_a);
Ble ble_b(radio_b);
radio_a.Enable();
radio_b.Enable();
ByteArray advertisement_bytes((std::string(kAdvertisementString)));
@@ -563,14 +560,14 @@ TEST_F(BleV2Test, StartFastScanningDiscoverAndLostPeripheral) {
CountDownLatch lost_latch(1);
ble_b.StartAdvertising(std::string(kServiceIDA), PowerLevel::kHighPower,
BleV2::AdvertisingType::kFast, advertisement_bytes);
Ble::AdvertisingType::kFast, advertisement_bytes);
ble_a.StartScanning(
std::string(kServiceIDA), Pcp::kP2pPointToPoint, PowerLevel::kHighPower,
/*include_dct_advertisement=*/false,
mediums::DiscoveredPeripheralCallback{
.peripheral_discovered_cb =
[&found_latch](BleV2Peripheral peripheral,
[&found_latch](BlePeripheral peripheral,
const std::string& service_id,
const ByteArray& advertisement_bytes,
bool fast_advertisement) {
@@ -579,7 +576,7 @@ TEST_F(BleV2Test, StartFastScanningDiscoverAndLostPeripheral) {
},
.peripheral_lost_cb =
[&lost_latch](
BleV2Peripheral peripheral, const std::string& service_id,
BlePeripheral peripheral, const std::string& service_id,
const ByteArray& advertisement_bytes,
bool fast_advertisement) { lost_latch.CountDown(); },
});
@@ -598,13 +595,12 @@ TEST_F(BleV2Test, StartFastScanningDiscoverAndLostPeripheral) {
env_.Stop();
}
TEST_F(BleV2Test,
StartFastScanningDiscoverButNoPeripheralLostAfterStopScanning) {
TEST_F(BleTest, StartFastScanningDiscoverButNoPeripheralLostAfterStopScanning) {
env_.Start();
BluetoothRadio radio_a;
BluetoothRadio radio_b;
BleV2 ble_a(radio_a);
BleV2 ble_b(radio_b);
Ble ble_a(radio_a);
Ble ble_b(radio_b);
radio_a.Enable();
radio_b.Enable();
ByteArray advertisement_bytes((std::string(kAdvertisementString)));
@@ -612,14 +608,14 @@ TEST_F(BleV2Test,
CountDownLatch lost_latch(1);
ble_b.StartAdvertising(std::string(kServiceIDA), PowerLevel::kHighPower,
BleV2::AdvertisingType::kFast, advertisement_bytes);
Ble::AdvertisingType::kFast, advertisement_bytes);
ble_a.StartScanning(
std::string(kServiceIDA), Pcp::kP2pPointToPoint, PowerLevel::kHighPower,
/*include_dct_advertisement=*/false,
mediums::DiscoveredPeripheralCallback{
.peripheral_discovered_cb =
[&found_latch](BleV2Peripheral peripheral,
[&found_latch](BlePeripheral peripheral,
const std::string& service_id,
const ByteArray& advertisement_bytes,
bool fast_advertisement) {
@@ -628,7 +624,7 @@ TEST_F(BleV2Test,
},
.peripheral_lost_cb =
[&lost_latch](
BleV2Peripheral peripheral, const std::string& service_id,
BlePeripheral peripheral, const std::string& service_id,
const ByteArray& advertisement_bytes,
bool fast_advertisement) { lost_latch.CountDown(); },
});
@@ -645,12 +641,12 @@ TEST_F(BleV2Test,
env_.Stop();
}
TEST_F(BleV2Test, StartScanningDiscoverAndLostPeripheral) {
TEST_F(BleTest, StartScanningDiscoverAndLostPeripheral) {
env_.Start();
BluetoothRadio radio_a;
BluetoothRadio radio_b;
BleV2 ble_a(radio_a);
BleV2 ble_b(radio_b);
Ble ble_a(radio_a);
Ble ble_b(radio_b);
radio_a.Enable();
radio_b.Enable();
ByteArray advertisement_bytes((std::string(kAdvertisementString)));
@@ -658,14 +654,14 @@ TEST_F(BleV2Test, StartScanningDiscoverAndLostPeripheral) {
CountDownLatch lost_latch(1);
ble_b.StartAdvertising(std::string(kServiceIDA), PowerLevel::kHighPower,
BleV2::AdvertisingType::kRegular, advertisement_bytes);
Ble::AdvertisingType::kRegular, advertisement_bytes);
ble_a.StartScanning(
std::string(kServiceIDA), Pcp::kP2pPointToPoint, PowerLevel::kHighPower,
/*include_dct_advertisement=*/false,
mediums::DiscoveredPeripheralCallback{
.peripheral_discovered_cb =
[&found_latch](BleV2Peripheral peripheral,
[&found_latch](BlePeripheral peripheral,
const std::string& service_id,
const ByteArray& advertisement_bytes,
bool fast_advertisement) {
@@ -674,7 +670,7 @@ TEST_F(BleV2Test, StartScanningDiscoverAndLostPeripheral) {
},
.peripheral_lost_cb =
[&lost_latch](
BleV2Peripheral peripheral, const std::string& service_id,
BlePeripheral peripheral, const std::string& service_id,
const ByteArray& advertisement_bytes,
bool fast_advertisement) { lost_latch.CountDown(); },
});
@@ -693,12 +689,12 @@ TEST_F(BleV2Test, StartScanningDiscoverAndLostPeripheral) {
env_.Stop();
}
TEST_F(BleV2Test, StartScanningDiscoverButNoPeripheralLostAfterStopScanning) {
TEST_F(BleTest, StartScanningDiscoverButNoPeripheralLostAfterStopScanning) {
env_.Start();
BluetoothRadio radio_a;
BluetoothRadio radio_b;
BleV2 ble_a(radio_a);
BleV2 ble_b(radio_b);
Ble ble_a(radio_a);
Ble ble_b(radio_b);
radio_a.Enable();
radio_b.Enable();
ByteArray advertisement_bytes((std::string(kAdvertisementString)));
@@ -706,14 +702,14 @@ TEST_F(BleV2Test, StartScanningDiscoverButNoPeripheralLostAfterStopScanning) {
CountDownLatch lost_latch(1);
ble_b.StartAdvertising(std::string(kServiceIDA), PowerLevel::kHighPower,
BleV2::AdvertisingType::kRegular, advertisement_bytes);
Ble::AdvertisingType::kRegular, advertisement_bytes);
ble_a.StartScanning(
std::string(kServiceIDA), Pcp::kP2pPointToPoint, PowerLevel::kHighPower,
/*include_dct_advertisement=*/false,
mediums::DiscoveredPeripheralCallback{
.peripheral_discovered_cb =
[&found_latch](BleV2Peripheral peripheral,
[&found_latch](BlePeripheral peripheral,
const std::string& service_id,
const ByteArray& advertisement_bytes,
bool fast_advertisement) {
@@ -722,7 +718,7 @@ TEST_F(BleV2Test, StartScanningDiscoverButNoPeripheralLostAfterStopScanning) {
},
.peripheral_lost_cb =
[&lost_latch](
BleV2Peripheral peripheral, const std::string& service_id,
BlePeripheral peripheral, const std::string& service_id,
const ByteArray& advertisement_bytes,
bool fast_advertisement) { lost_latch.CountDown(); },
});
@@ -739,10 +735,10 @@ TEST_F(BleV2Test, StartScanningDiscoverButNoPeripheralLostAfterStopScanning) {
env_.Stop();
}
TEST_F(BleV2Test, CanStartAndStopLegacyAdvertising) {
TEST_F(BleTest, CanStartAndStopLegacyAdvertising) {
env_.Start();
BluetoothRadio radio_a;
BleV2 ble_a{radio_a};
Ble ble_a{radio_a};
radio_a.Enable();
std::string service_id(kServiceIDA);
EXPECT_TRUE(
@@ -755,10 +751,10 @@ TEST_F(BleV2Test, CanStartAndStopLegacyAdvertising) {
env_.Stop();
}
TEST_F(BleV2Test, CanNotStartLegacyAdvertisingWhenRadioNotEnabled) {
TEST_F(BleTest, CanNotStartLegacyAdvertisingWhenRadioNotEnabled) {
env_.Start();
BluetoothRadio radio_a;
BleV2 ble_a{radio_a};
Ble ble_a{radio_a};
radio_a.Disable();
std::string service_id(kServiceIDA);
EXPECT_FALSE(
@@ -768,10 +764,10 @@ TEST_F(BleV2Test, CanNotStartLegacyAdvertisingWhenRadioNotEnabled) {
env_.Stop();
}
TEST_F(BleV2Test, CanNotStopLegacyAdvertisingForNonExistingServiceId) {
TEST_F(BleTest, CanNotStopLegacyAdvertisingForNonExistingServiceId) {
env_.Start();
BluetoothRadio radio_a;
BleV2 ble_a{radio_a};
Ble ble_a{radio_a};
radio_a.Enable();
std::string service_id(kServiceIDA);
EXPECT_FALSE(ble_a.IsAdvertisingForLegacyDevice(service_id));
@@ -785,16 +781,16 @@ TEST_F(BleV2Test, CanNotStopLegacyAdvertisingForNonExistingServiceId) {
env_.Stop();
}
TEST_F(BleV2Test, StartLegacyAdvertisingNotBlockedByRegularAdvertising) {
TEST_F(BleTest, StartLegacyAdvertisingNotBlockedByRegularAdvertising) {
env_.Start();
BluetoothRadio radio_a;
BleV2 ble_a{radio_a};
Ble ble_a{radio_a};
radio_a.Enable();
std::string service_id(kServiceIDA);
ByteArray advertisement_bytes((std::string(kAdvertisementString)));
ble_a.StartAdvertising(std::string(kServiceIDA), PowerLevel::kHighPower,
BleV2::AdvertisingType::kRegular, advertisement_bytes);
Ble::AdvertisingType::kRegular, advertisement_bytes);
EXPECT_TRUE(ble_a.IsAdvertising(service_id));
EXPECT_TRUE(
ble_a.StartLegacyAdvertising(service_id, std::string(kLocalEndpointId),
@@ -804,10 +800,10 @@ TEST_F(BleV2Test, StartLegacyAdvertisingNotBlockedByRegularAdvertising) {
env_.Stop();
}
TEST_F(BleV2Test, DuplicateStartLegacyAdvertisingReturnsFalse) {
TEST_F(BleTest, DuplicateStartLegacyAdvertisingReturnsFalse) {
env_.Start();
BluetoothRadio radio_a;
BleV2 ble_a{radio_a};
Ble ble_a{radio_a};
radio_a.Enable();
std::string service_id(kServiceIDA);
EXPECT_FALSE(ble_a.IsAdvertisingForLegacyDevice(service_id));
@@ -823,14 +819,14 @@ TEST_F(BleV2Test, DuplicateStartLegacyAdvertisingReturnsFalse) {
env_.Stop();
}
TEST_F(BleV2Test, HandleLegacyAdvertising) {
TEST_F(BleTest, HandleLegacyAdvertising) {
env_.SetFeatureFlags(
{FeatureFlags{.enable_invoking_legacy_device_discovered_cb = true}});
env_.Start();
BluetoothRadio radio_a;
BluetoothRadio radio_b;
BleV2 ble_a(radio_a);
BleV2 ble_b(radio_b);
Ble ble_a(radio_a);
Ble ble_b(radio_b);
radio_a.Enable();
radio_b.Enable();
ByteArray advertisement_bytes((std::string(kAdvertisementString)));
@@ -846,7 +842,7 @@ TEST_F(BleV2Test, HandleLegacyAdvertising) {
/*include_dct_advertisement=*/false,
mediums::DiscoveredPeripheralCallback{
.peripheral_discovered_cb =
[](BleV2Peripheral peripheral, const std::string& service_id,
[](BlePeripheral peripheral, const std::string& service_id,
const ByteArray& advertisement_bytes,
bool fast_advertisement) {
FAIL() << "Legacy device shouldn't be reported here.";
@@ -863,27 +859,27 @@ TEST_F(BleV2Test, HandleLegacyAdvertising) {
env_.Stop();
}
TEST_F(BleV2Test, CanStartAsyncScanning) {
TEST_F(BleTest, CanStartAsyncScanning) {
env_.SetFeatureFlags({FeatureFlags{.enable_ble_v2_async_scanning = true}});
env_.Start();
BluetoothRadio radio_a;
BluetoothRadio radio_b;
BleV2 ble_a(radio_a);
BleV2 ble_b(radio_b);
Ble ble_a(radio_a);
Ble ble_b(radio_b);
radio_a.Enable();
radio_b.Enable();
ByteArray advertisement_bytes((std::string(kAdvertisementString)));
CountDownLatch found_latch(1);
ble_b.StartAdvertising(std::string(kServiceIDA), PowerLevel::kHighPower,
BleV2::AdvertisingType::kRegular, advertisement_bytes);
Ble::AdvertisingType::kRegular, advertisement_bytes);
EXPECT_TRUE(ble_a.StartScanning(
std::string(kServiceIDA), Pcp::kP2pPointToPoint, PowerLevel::kHighPower,
/*include_dct_advertisement=*/false,
mediums::DiscoveredPeripheralCallback{
.peripheral_discovered_cb =
[&found_latch](BleV2Peripheral peripheral,
[&found_latch](BlePeripheral peripheral,
const std::string& service_id,
const ByteArray& advertisement_bytes,
bool fast_advertisement) {
@@ -898,20 +894,20 @@ TEST_F(BleV2Test, CanStartAsyncScanning) {
env_.Stop();
}
TEST_F(BleV2Test, StartAsyncScanningWithPlatformErrors) {
TEST_F(BleTest, StartAsyncScanningWithPlatformErrors) {
env_.SetFeatureFlags({FeatureFlags{.enable_ble_v2_async_scanning = true}});
env_.Start();
BluetoothRadio radio_a;
BluetoothRadio radio_b;
BleV2 ble_a(radio_a);
BleV2 ble_b(radio_b);
Ble ble_a(radio_a);
Ble ble_b(radio_b);
radio_a.Enable();
radio_b.Enable();
ByteArray advertisement_bytes((std::string(kAdvertisementString)));
CountDownLatch found_latch(1);
ble_b.StartAdvertising(std::string(kServiceIDA), PowerLevel::kHighPower,
BleV2::AdvertisingType::kRegular, advertisement_bytes);
Ble::AdvertisingType::kRegular, advertisement_bytes);
// Disable radio a to simulate platform error.
radio_a.Disable();
@@ -920,7 +916,7 @@ TEST_F(BleV2Test, StartAsyncScanningWithPlatformErrors) {
/*include_dct_advertisement=*/false,
mediums::DiscoveredPeripheralCallback{
.peripheral_discovered_cb =
[&found_latch](BleV2Peripheral peripheral,
[&found_latch](BlePeripheral peripheral,
const std::string& service_id,
const ByteArray& advertisement_bytes,
bool fast_advertisement) {
@@ -935,7 +931,7 @@ TEST_F(BleV2Test, StartAsyncScanningWithPlatformErrors) {
/*include_dct_advertisement=*/false,
mediums::DiscoveredPeripheralCallback{
.peripheral_discovered_cb =
[&found_latch](BleV2Peripheral peripheral,
[&found_latch](BlePeripheral peripheral,
const std::string& service_id,
const ByteArray& advertisement_bytes,
bool fast_advertisement) {
@@ -954,13 +950,13 @@ TEST_F(BleV2Test, StartAsyncScanningWithPlatformErrors) {
env_.Stop();
}
TEST_F(BleV2Test, StartAsyncScanningDiscoverAndLostPeripheral) {
TEST_F(BleTest, StartAsyncScanningDiscoverAndLostPeripheral) {
env_.SetFeatureFlags({FeatureFlags{.enable_ble_v2_async_scanning = true}});
env_.Start();
BluetoothRadio radio_a;
BluetoothRadio radio_b;
BleV2 ble_a(radio_a);
BleV2 ble_b(radio_b);
Ble ble_a(radio_a);
Ble ble_b(radio_b);
radio_a.Enable();
radio_b.Enable();
ByteArray advertisement_bytes((std::string(kAdvertisementString)));
@@ -968,14 +964,14 @@ TEST_F(BleV2Test, StartAsyncScanningDiscoverAndLostPeripheral) {
CountDownLatch lost_latch(1);
ble_b.StartAdvertising(std::string(kServiceIDA), PowerLevel::kHighPower,
BleV2::AdvertisingType::kRegular, advertisement_bytes);
Ble::AdvertisingType::kRegular, advertisement_bytes);
EXPECT_TRUE(ble_a.StartScanning(
std::string(kServiceIDA), Pcp::kP2pPointToPoint, PowerLevel::kHighPower,
/*include_dct_advertisement=*/false,
mediums::DiscoveredPeripheralCallback{
.peripheral_discovered_cb =
[&found_latch](BleV2Peripheral peripheral,
[&found_latch](BlePeripheral peripheral,
const std::string& service_id,
const ByteArray& advertisement_bytes,
bool fast_advertisement) {
@@ -984,7 +980,7 @@ TEST_F(BleV2Test, StartAsyncScanningDiscoverAndLostPeripheral) {
},
.peripheral_lost_cb =
[&lost_latch](
BleV2Peripheral peripheral, const std::string& service_id,
BlePeripheral peripheral, const std::string& service_id,
const ByteArray& advertisement_bytes,
bool fast_advertisement) { lost_latch.CountDown(); },
}));
@@ -1002,14 +998,14 @@ TEST_F(BleV2Test, StartAsyncScanningDiscoverAndLostPeripheral) {
env_.Stop();
}
TEST_F(BleV2Test,
TEST_F(BleTest,
StartAsyncScanningDiscoverButNoPeripheralLostAfterStopScanning) {
env_.SetFeatureFlags({FeatureFlags{.enable_ble_v2_async_scanning = true}});
env_.Start();
BluetoothRadio radio_a;
BluetoothRadio radio_b;
BleV2 ble_a(radio_a);
BleV2 ble_b(radio_b);
Ble ble_a(radio_a);
Ble ble_b(radio_b);
radio_a.Enable();
radio_b.Enable();
ByteArray advertisement_bytes((std::string(kAdvertisementString)));
@@ -1017,14 +1013,14 @@ TEST_F(BleV2Test,
CountDownLatch lost_latch(1);
ble_b.StartAdvertising(std::string(kServiceIDA), PowerLevel::kHighPower,
BleV2::AdvertisingType::kRegular, advertisement_bytes);
Ble::AdvertisingType::kRegular, advertisement_bytes);
EXPECT_TRUE(ble_a.StartScanning(
std::string(kServiceIDA), Pcp::kP2pPointToPoint, PowerLevel::kHighPower,
/*include_dct_advertisement=*/false,
mediums::DiscoveredPeripheralCallback{
.peripheral_discovered_cb =
[&found_latch](BleV2Peripheral peripheral,
[&found_latch](BlePeripheral peripheral,
const std::string& service_id,
const ByteArray& advertisement_bytes,
bool fast_advertisement) {
@@ -1033,7 +1029,7 @@ TEST_F(BleV2Test,
},
.peripheral_lost_cb =
[&lost_latch](
BleV2Peripheral peripheral, const std::string& service_id,
BlePeripheral peripheral, const std::string& service_id,
const ByteArray& advertisement_bytes,
bool fast_advertisement) { lost_latch.CountDown(); },
}));
@@ -1050,15 +1046,15 @@ TEST_F(BleV2Test,
env_.Stop();
}
TEST_F(BleV2Test, CanStartStopMultipleAsyncScanningWithDifferentServiceIds) {
TEST_F(BleTest, CanStartStopMultipleAsyncScanningWithDifferentServiceIds) {
env_.SetFeatureFlags({FeatureFlags{.enable_ble_v2_async_scanning = true}});
env_.Start();
BluetoothRadio radio_scanner;
BluetoothRadio radio_advertiser_a;
BluetoothRadio radio_advertiser_b;
BleV2 ble_scanner(radio_scanner);
BleV2 ble_advertiser_a(radio_advertiser_a);
BleV2 ble_advertiser_b(radio_advertiser_b);
Ble ble_scanner(radio_scanner);
Ble ble_advertiser_a(radio_advertiser_a);
Ble ble_advertiser_b(radio_advertiser_b);
radio_scanner.Enable();
radio_advertiser_a.Enable();
radio_advertiser_b.Enable();
@@ -1069,17 +1065,17 @@ TEST_F(BleV2Test, CanStartStopMultipleAsyncScanningWithDifferentServiceIds) {
ble_advertiser_a.StartAdvertising(
std::string(kServiceIDA), PowerLevel::kHighPower,
BleV2::AdvertisingType::kRegular, advertisement_bytes_a);
Ble::AdvertisingType::kRegular, advertisement_bytes_a);
ble_advertiser_b.StartAdvertising(
std::string(kServiceIDB), PowerLevel::kHighPower,
BleV2::AdvertisingType::kRegular, advertisement_bytes_b);
Ble::AdvertisingType::kRegular, advertisement_bytes_b);
ble_scanner.StartScanning(
std::string(kServiceIDA), Pcp::kP2pPointToPoint, PowerLevel::kHighPower,
/*include_dct_advertisement=*/false,
mediums::DiscoveredPeripheralCallback{
.peripheral_discovered_cb =
[&found_latch_a](BleV2Peripheral peripheral,
[&found_latch_a](BlePeripheral peripheral,
const std::string& service_id,
const ByteArray& advertisement_bytes,
bool fast_advertisement) {
@@ -1094,7 +1090,7 @@ TEST_F(BleV2Test, CanStartStopMultipleAsyncScanningWithDifferentServiceIds) {
/*include_dct_advertisement=*/false,
mediums::DiscoveredPeripheralCallback{
.peripheral_discovered_cb =
[&found_latch_b](BleV2Peripheral peripheral,
[&found_latch_b](BlePeripheral peripheral,
const std::string& service_id,
const ByteArray& advertisement_bytes,
bool fast_advertisement) {
@@ -1111,15 +1107,15 @@ TEST_F(BleV2Test, CanStartStopMultipleAsyncScanningWithDifferentServiceIds) {
env_.Stop();
}
TEST_F(BleV2Test, StartMultipleAsyncScanningDiscoverAndLostPeripheral) {
TEST_F(BleTest, StartMultipleAsyncScanningDiscoverAndLostPeripheral) {
env_.SetFeatureFlags({FeatureFlags{.enable_ble_v2_async_scanning = true}});
env_.Start();
BluetoothRadio radio_scanner;
BluetoothRadio radio_advertiser_a;
BluetoothRadio radio_advertiser_b;
BleV2 ble_scanner(radio_scanner);
BleV2 ble_advertiser_a(radio_advertiser_a);
BleV2 ble_advertiser_b(radio_advertiser_b);
Ble ble_scanner(radio_scanner);
Ble ble_advertiser_a(radio_advertiser_a);
Ble ble_advertiser_b(radio_advertiser_b);
radio_scanner.Enable();
radio_advertiser_a.Enable();
radio_advertiser_b.Enable();
@@ -1132,17 +1128,17 @@ TEST_F(BleV2Test, StartMultipleAsyncScanningDiscoverAndLostPeripheral) {
ble_advertiser_a.StartAdvertising(
std::string(kServiceIDA), PowerLevel::kHighPower,
BleV2::AdvertisingType::kRegular, advertisement_bytes_a);
Ble::AdvertisingType::kRegular, advertisement_bytes_a);
ble_advertiser_b.StartAdvertising(
std::string(kServiceIDB), PowerLevel::kHighPower,
BleV2::AdvertisingType::kRegular, advertisement_bytes_b);
Ble::AdvertisingType::kRegular, advertisement_bytes_b);
ble_scanner.StartScanning(
std::string(kServiceIDA), Pcp::kP2pPointToPoint, PowerLevel::kHighPower,
/*include_dct_advertisement=*/false,
mediums::DiscoveredPeripheralCallback{
.peripheral_discovered_cb =
[&found_latch_a](BleV2Peripheral peripheral,
[&found_latch_a](BlePeripheral peripheral,
const std::string& service_id,
const ByteArray& advertisement_bytes,
bool fast_advertisement) {
@@ -1151,7 +1147,7 @@ TEST_F(BleV2Test, StartMultipleAsyncScanningDiscoverAndLostPeripheral) {
found_latch_a.CountDown();
},
.peripheral_lost_cb =
[&lost_latch_a](BleV2Peripheral peripheral,
[&lost_latch_a](BlePeripheral peripheral,
const std::string& service_id,
const ByteArray& advertisement_bytes,
bool fast_advertisement) {
@@ -1166,7 +1162,7 @@ TEST_F(BleV2Test, StartMultipleAsyncScanningDiscoverAndLostPeripheral) {
/*include_dct_advertisement=*/false,
mediums::DiscoveredPeripheralCallback{
.peripheral_discovered_cb =
[&found_latch_b](BleV2Peripheral peripheral,
[&found_latch_b](BlePeripheral peripheral,
const std::string& service_id,
const ByteArray& advertisement_bytes,
bool fast_advertisement) {
@@ -1175,7 +1171,7 @@ TEST_F(BleV2Test, StartMultipleAsyncScanningDiscoverAndLostPeripheral) {
found_latch_b.CountDown();
},
.peripheral_lost_cb =
[&lost_latch_b](BleV2Peripheral peripheral,
[&lost_latch_b](BlePeripheral peripheral,
const std::string& service_id,
const ByteArray& advertisement_bytes,
bool fast_advertisement) {
@@ -13,7 +13,9 @@
// limitations under the License.
#include "connections/implementation/mediums/mediums.h"
#include "connections/implementation/mediums/awdl.h"
#include "connections/implementation/mediums/ble.h"
namespace nearby {
namespace connections {
@@ -22,7 +24,7 @@ BluetoothRadio& Mediums::GetBluetoothRadio() { return bluetooth_radio_; }
BluetoothClassic& Mediums::GetBluetoothClassic() { return bluetooth_classic_; }
BleV2& Mediums::GetBleV2() { return ble_v2_; }
Ble& Mediums::GetBle() { return ble_; }
Wifi& Mediums::GetWifi() { return wifi_; }
+4 -4
View File
@@ -16,7 +16,7 @@
#define CORE_INTERNAL_MEDIUMS_MEDIUMS_H_
#include "connections/implementation/mediums/awdl.h"
#include "connections/implementation/mediums/ble_v2.h"
#include "connections/implementation/mediums/ble.h"
#include "connections/implementation/mediums/bluetooth_classic.h"
#include "connections/implementation/mediums/bluetooth_radio.h"
#ifdef NO_WEBRTC
@@ -25,8 +25,8 @@
#include "connections/implementation/mediums/webrtc.h"
#endif
#include "connections/implementation/mediums/wifi.h"
#include "connections/implementation/mediums/wifi_hotspot.h"
#include "connections/implementation/mediums/wifi_direct.h"
#include "connections/implementation/mediums/wifi_hotspot.h"
#include "connections/implementation/mediums/wifi_lan.h"
namespace nearby {
@@ -45,7 +45,7 @@ class Mediums {
BluetoothClassic& GetBluetoothClassic();
// Returns a handle to the Ble medium.
BleV2& GetBleV2();
Ble& GetBle();
// Returns a handle to the Wifi medium.
Wifi& GetWifi();
@@ -76,7 +76,7 @@ class Mediums {
// corresponding radio.
BluetoothRadio bluetooth_radio_;
BluetoothClassic bluetooth_classic_{bluetooth_radio_};
BleV2 ble_v2_{bluetooth_radio_};
Ble ble_{bluetooth_radio_};
Wifi wifi_;
WifiLan wifi_lan_;
WifiHotspot wifi_hotspot_;
@@ -32,8 +32,8 @@
#include "connections/implementation/awdl_endpoint_channel.h"
#include "connections/implementation/base_pcp_handler.h"
#include "connections/implementation/ble_advertisement.h"
#include "connections/implementation/ble_endpoint_channel.h"
#include "connections/implementation/ble_l2cap_endpoint_channel.h"
#include "connections/implementation/ble_v2_endpoint_channel.h"
#include "connections/implementation/bluetooth_device_name.h"
#include "connections/implementation/bluetooth_endpoint_channel.h"
#include "connections/implementation/bwu_manager.h"
@@ -44,8 +44,8 @@
#include "connections/implementation/injected_bluetooth_device_store.h"
#include "connections/implementation/mediums/advertisements/advertisement_util.h"
#include "connections/implementation/mediums/advertisements/dct_advertisement.h"
#include "connections/implementation/mediums/ble_v2.h"
#include "connections/implementation/mediums/ble_v2/ble_advertisement_header.h"
#include "connections/implementation/mediums/ble.h"
#include "connections/implementation/mediums/ble/ble_advertisement_header.h"
#include "connections/implementation/mediums/bluetooth_classic.h"
#include "connections/implementation/mediums/mediums.h"
#include "connections/implementation/mediums/utils.h"
@@ -62,7 +62,7 @@
#include "internal/flags/nearby_flags.h"
#include "internal/interop/device.h"
#include "internal/platform/awdl.h"
#include "internal/platform/ble_v2.h"
#include "internal/platform/ble.h"
#include "internal/platform/bluetooth_adapter.h"
#include "internal/platform/bluetooth_classic.h"
#include "internal/platform/byte_array.h"
@@ -115,7 +115,7 @@ P2pClusterPcpHandler::P2pClusterPcpHandler(
awdl_medium_(mediums->GetAwdl()),
bluetooth_radio_(mediums->GetBluetoothRadio()),
bluetooth_medium_(mediums->GetBluetoothClassic()),
ble_v2_medium_(mediums->GetBleV2()),
ble_medium_(mediums->GetBle()),
wifi_lan_medium_(mediums->GetWifiLan()),
wifi_hotspot_medium_(mediums->GetWifiHotspot()),
wifi_direct_medium_(mediums->GetWifiDirect()),
@@ -141,7 +141,7 @@ std::vector<Medium> P2pClusterPcpHandler::GetConnectionMediumsByPriority() {
if (bluetooth_medium_.IsAvailable()) {
mediums.push_back(BLUETOOTH);
}
if (ble_v2_medium_.IsAvailable()) {
if (ble_medium_.IsAvailable()) {
mediums.push_back(BLE);
}
@@ -223,13 +223,13 @@ BasePcpHandler::StartOperationResult P2pClusterPcpHandler::StartAdvertisingImpl(
if (api::ImplementationPlatform::GetCurrentOS() ==
api::OSName::kChromeOS ||
api::ImplementationPlatform::GetCurrentOS() == api::OSName::kLinux) {
if (ble_v2_medium_.StartLegacyAdvertising(
if (ble_medium_.StartLegacyAdvertising(
service_id, local_endpoint_id,
advertising_options.fast_advertisement_service_uuid)) {
LOG(INFO) << __func__
<< "Ble v2 started advertising for legacy device.";
<< "Ble started advertising for legacy device.";
mediums_started_successfully.push_back(bluetooth_medium);
VLOG(1) << __func__ << "After Ble v2, BT added";
VLOG(1) << __func__ << "After Ble, BT added";
bluetooth_classic_advertiser_client_id_ = client->GetClientId();
} else {
LOG(WARNING) << "P2pClusterPcpHandler::StartAdvertisingImpl: "
@@ -255,9 +255,9 @@ BasePcpHandler::StartOperationResult P2pClusterPcpHandler::StartAdvertisingImpl(
if (advertising_options.allowed.ble) {
ErrorOr<Medium> ble_result = {Error(OperationResultCode::DETAIL_UNKNOWN)};
ble_result = StartBleV2Advertising(client, service_id, local_endpoint_id,
local_endpoint_info, advertising_options,
web_rtc_state);
ble_result = StartBleAdvertising(client, service_id, local_endpoint_id,
local_endpoint_info, advertising_options,
web_rtc_state);
if (ble_result.has_value() && ble_result.value() != UNKNOWN_MEDIUM) {
VLOG(1) << "P2pClusterPcpHandler::StartAdvertisingImpl: Ble added";
mediums_started_successfully.push_back(ble_result.value());
@@ -299,7 +299,7 @@ Status P2pClusterPcpHandler::StopAdvertisingImpl(ClientProxy* client) {
bluetooth_medium_.TurnOffDiscoverability();
if (api::ImplementationPlatform::GetCurrentOS() == api::OSName::kChromeOS ||
api::ImplementationPlatform::GetCurrentOS() == api::OSName::kLinux) {
ble_v2_medium_.StopLegacyAdvertising(client->GetAdvertisingServiceId());
ble_medium_.StopLegacyAdvertising(client->GetAdvertisingServiceId());
}
bluetooth_classic_advertiser_client_id_ = 0;
} else {
@@ -310,11 +310,11 @@ Status P2pClusterPcpHandler::StopAdvertisingImpl(ClientProxy* client) {
}
bluetooth_medium_.StopAcceptingConnections(client->GetAdvertisingServiceId());
ble_v2_medium_.StopAdvertising(client->GetAdvertisingServiceId());
ble_v2_medium_.StopAcceptingConnections(client->GetAdvertisingServiceId());
ble_medium_.StopAdvertising(client->GetAdvertisingServiceId());
ble_medium_.StopAcceptingConnections(client->GetAdvertisingServiceId());
if (NearbyFlags::GetInstance().GetBoolFlag(
config_package_nearby::nearby_connections_feature::kEnableBleL2cap)) {
ble_v2_medium_.StopAcceptingL2capConnections(
ble_medium_.StopAcceptingL2capConnections(
client->GetAdvertisingServiceId());
}
@@ -529,7 +529,7 @@ void P2pClusterPcpHandler::BluetoothDeviceLostHandler(
});
}
bool P2pClusterPcpHandler::IsRecognizedBleV2Endpoint(
bool P2pClusterPcpHandler::IsRecognizedBleEndpoint(
absl::string_view service_id, const BleAdvertisement& advertisement) const {
if (!advertisement.IsValid()) {
LOG(INFO) << "BleAdvertisement doesn't conform to the format, discarding.";
@@ -570,8 +570,8 @@ bool P2pClusterPcpHandler::IsRecognizedBleV2Endpoint(
return true;
}
void P2pClusterPcpHandler::BleV2PeripheralDiscoveredHandler(
ClientProxy* client, BleV2Peripheral peripheral,
void P2pClusterPcpHandler::BlePeripheralDiscoveredHandler(
ClientProxy* client, BlePeripheral peripheral,
const std::string& service_id, const ByteArray& advertisement_bytes,
bool fast_advertisement) {
RunOnPcpHandlerThread(
@@ -605,13 +605,13 @@ void P2pClusterPcpHandler::BleV2PeripheralDiscoveredHandler(
// Make sure the BLE advertisement points to a valid
// endpoint we're discovering.
if (!IsRecognizedBleV2Endpoint(service_id, advertisement)) {
LOG(ERROR) << "IsRecognizedBleV2Endpoint failed";
if (!IsRecognizedBleEndpoint(service_id, advertisement)) {
LOG(ERROR) << "IsRecognizedBleEndpoint failed";
return;
}
// Report the discovered endpoint to the client.
BleV2EndpointState ble_endpoint_state;
BleEndpointFeatureState ble_endpoint_state;
ByteArray peripheral_id = peripheral.GetId();
found_endpoints_in_ble_discover_cb_.insert(
{peripheral_id, ble_endpoint_state});
@@ -622,7 +622,7 @@ void P2pClusterPcpHandler::BleV2PeripheralDiscoveredHandler(
StopEndpointLostByMediumAlarm(advertisement.GetEndpointId(), BLE);
OnEndpointFound(
client,
std::make_shared<BleV2Endpoint>(BleV2Endpoint{
std::make_shared<BleEndpoint>(BleEndpoint{
{advertisement.GetEndpointId(), advertisement.GetEndpointInfo(),
service_id, BLE, advertisement.GetWebRtcState()},
std::move(peripheral),
@@ -666,8 +666,8 @@ void P2pClusterPcpHandler::BleV2PeripheralDiscoveredHandler(
}
// TODO(b/222392304): More test coverage.
void P2pClusterPcpHandler::BleV2PeripheralLostHandler(
ClientProxy* client, BleV2Peripheral peripheral,
void P2pClusterPcpHandler::BlePeripheralLostHandler(
ClientProxy* client, BlePeripheral peripheral,
const std::string& service_id, const ByteArray& advertisement_bytes,
bool fast_advertisement) {
RunOnPcpHandlerThread(
@@ -692,7 +692,7 @@ void P2pClusterPcpHandler::BleV2PeripheralLostHandler(
// Make sure the BLE advertisement points to a valid
// endpoint we're discovering.
if (!IsRecognizedBleV2Endpoint(service_id, advertisement)) return;
if (!IsRecognizedBleEndpoint(service_id, advertisement)) return;
// Remove this BlePeripheral from found_ble_endpoints_, and
// report the endpoint as lost to the client.
@@ -701,7 +701,7 @@ void P2pClusterPcpHandler::BleV2PeripheralLostHandler(
if (item == found_endpoints_in_ble_discover_cb_.end()) {
return;
}
BleV2EndpointState ble_endpoint_state(item->second);
BleEndpointFeatureState ble_endpoint_state(item->second);
found_endpoints_in_ble_discover_cb_.erase(item);
if (ble_endpoint_state.ble) {
@@ -741,8 +741,8 @@ void P2pClusterPcpHandler::BleV2PeripheralLostHandler(
});
}
void P2pClusterPcpHandler::BleV2InstantLostHandler(
ClientProxy* client, BleV2Peripheral peripheral,
void P2pClusterPcpHandler::BleInstantLostHandler(
ClientProxy* client, BlePeripheral peripheral,
const std::string& service_id, const ByteArray& advertisement_bytes,
bool fast_advertisement) {
RunOnPcpHandlerThread(
@@ -770,7 +770,7 @@ void P2pClusterPcpHandler::BleV2InstantLostHandler(
// Make sure the BLE advertisement points to a valid
// endpoint we're discovering.
if (!IsRecognizedBleV2Endpoint(service_id, advertisement)) return;
if (!IsRecognizedBleEndpoint(service_id, advertisement)) return;
// Remove this BlePeripheral from found_ble_endpoints_, and
// report the endpoint as lost to the client.
@@ -788,7 +788,7 @@ void P2pClusterPcpHandler::BleV2InstantLostHandler(
});
}
void P2pClusterPcpHandler::BleV2LegacyDeviceDiscoveredHandler() {
void P2pClusterPcpHandler::BleLegacyDeviceDiscoveredHandler() {
if (!NearbyFlags::GetInstance().GetBoolFlag(
config_package_nearby::nearby_connections_feature::
kDisableBluetoothClassicScanning)) {
@@ -1098,14 +1098,14 @@ BasePcpHandler::StartOperationResult P2pClusterPcpHandler::StartDiscoveryImpl(
if (discovery_options.allowed.ble) {
ErrorOr<Medium> ble_result = {Error(OperationResultCode::DETAIL_UNKNOWN)};
ble_result = StartBleV2Scanning(client, service_id, discovery_options);
Medium ble_v2_medium = UNKNOWN_MEDIUM;
ble_result = StartBleScanning(client, service_id, discovery_options);
Medium ble_medium = UNKNOWN_MEDIUM;
if (ble_result.has_value()) {
ble_v2_medium = ble_result.value();
ble_medium = ble_result.value();
}
if (ble_v2_medium != UNKNOWN_MEDIUM) {
LOG(INFO) << "P2pClusterPcpHandler::StartDiscoveryImpl: Ble v2 added";
mediums_started_successfully.push_back(ble_v2_medium);
if (ble_medium != UNKNOWN_MEDIUM) {
LOG(INFO) << "P2pClusterPcpHandler::StartDiscoveryImpl: Ble added";
mediums_started_successfully.push_back(ble_medium);
}
std::unique_ptr<ConnectionsLog::OperationResultWithMedium>
@@ -1184,7 +1184,7 @@ Status P2pClusterPcpHandler::StopDiscoveryImpl(ClientProxy* client) {
<< " because it is not in discovery.";
}
ble_v2_medium_.StopScanning(client->GetDiscoveryServiceId());
ble_medium_.StopScanning(client->GetDiscoveryServiceId());
if (NearbyFlags::GetInstance().GetBoolFlag(
config_package_nearby::nearby_connections_feature::
@@ -1245,9 +1245,9 @@ BasePcpHandler::ConnectImplResult P2pClusterPcpHandler::ConnectImpl(
break;
}
case BLE: {
auto* ble_v2_endpoint = down_cast<BleV2Endpoint*>(endpoint);
if (ble_v2_endpoint) {
return BleV2ConnectImpl(client, ble_v2_endpoint);
auto* ble_endpoint = down_cast<BleEndpoint*>(endpoint);
if (ble_endpoint) {
return BleConnectImpl(client, ble_endpoint);
}
break;
@@ -1318,30 +1318,30 @@ P2pClusterPcpHandler::StartListeningForIncomingConnectionsImpl(
if (options.enable_ble_listening &&
NearbyFlags::GetInstance().GetBoolFlag(
config_package_nearby::nearby_connections_feature::kEnableBleL2cap) &&
!ble_v2_medium_.IsAcceptingL2capConnections(std::string(service_id))) {
if (!ble_v2_medium_.StartAcceptingL2capConnections(
!ble_medium_.IsAcceptingL2capConnections(std::string(service_id))) {
if (!ble_medium_.StartAcceptingL2capConnections(
std::string(service_id),
absl::bind_front(
&P2pClusterPcpHandler::BleL2capConnectionAcceptedHandler, this,
client_proxy, local_endpoint_id,
options.listening_endpoint_type))) {
LOG(WARNING) << "Failed to start listening for incoming L2CAP "
"connections on ble_v2";
"connections on ble";
} else {
accepting_ble_connections_success = true;
}
}
if (options.enable_ble_listening &&
!ble_v2_medium_.IsAcceptingConnections(std::string(service_id))) {
if (!ble_v2_medium_.StartAcceptingConnections(
!ble_medium_.IsAcceptingConnections(std::string(service_id))) {
if (!ble_medium_.StartAcceptingConnections(
std::string(service_id),
absl::bind_front(
&P2pClusterPcpHandler::BleV2ConnectionAcceptedHandler, this,
&P2pClusterPcpHandler::BleConnectionAcceptedHandler, this,
client_proxy, local_endpoint_id,
options.listening_endpoint_type))) {
LOG(WARNING)
<< "Failed to start listening for incoming connections on ble_v2";
<< "Failed to start listening for incoming connections on ble";
} else {
accepting_ble_connections_success = true;
}
@@ -1409,12 +1409,11 @@ void P2pClusterPcpHandler::StopListeningForIncomingConnectionsImpl(
}
}
if (ble_v2_medium_.IsAcceptingConnections(
if (ble_medium_.IsAcceptingConnections(
client->GetListeningForIncomingConnectionsServiceId())) {
if (!ble_v2_medium_.StopAcceptingConnections(
if (!ble_medium_.StopAcceptingConnections(
client->GetListeningForIncomingConnectionsServiceId())) {
LOG(WARNING)
<< "Unable to stop ble_v2 medium from accepting connections.";
LOG(WARNING) << "Unable to stop ble medium from accepting connections.";
}
}
}
@@ -1429,8 +1428,8 @@ P2pClusterPcpHandler::UpdateAdvertisingOptionsImpl(
// ble
if (NeedsToTurnOffAdvertisingMedium(BLE, old_options, advertising_options) ||
needs_restart) {
mediums_->GetBleV2().StopAdvertising(std::string(service_id));
mediums_->GetBleV2().StopAcceptingConnections(std::string(service_id));
mediums_->GetBle().StopAdvertising(std::string(service_id));
mediums_->GetBle().StopAcceptingConnections(std::string(service_id));
}
// awdl
if (NearbyFlags::GetInstance().GetBoolFlag(
@@ -1458,7 +1457,7 @@ P2pClusterPcpHandler::UpdateAdvertisingOptionsImpl(
std::string(service_id));
if (api::ImplementationPlatform::GetCurrentOS() == api::OSName::kChromeOS ||
api::ImplementationPlatform::GetCurrentOS() == api::OSName::kLinux) {
mediums_->GetBleV2().StopLegacyAdvertising(
mediums_->GetBle().StopLegacyAdvertising(
client->GetAdvertisingServiceId());
}
}
@@ -1487,7 +1486,7 @@ P2pClusterPcpHandler::UpdateAdvertisingOptionsImpl(
operation_result_with_mediums.push_back(*operation_result_with_medium);
} else {
ErrorOr<Medium> ble_result = {Error(OperationResultCode::DETAIL_UNKNOWN)};
ble_result = StartBleV2Advertising(
ble_result = StartBleAdvertising(
client, std::string(service_id), std::string(local_endpoint_id),
ByteArray(std::string(local_endpoint_info)), advertising_options,
web_rtc_state);
@@ -1591,19 +1590,19 @@ P2pClusterPcpHandler::UpdateAdvertisingOptionsImpl(
api::OSName::kChromeOS ||
api::ImplementationPlatform::GetCurrentOS() ==
api::OSName::kLinux) {
if (ble_v2_medium_.StartLegacyAdvertising(
if (ble_medium_.StartLegacyAdvertising(
std::string(service_id), std::string(local_endpoint_id),
advertising_options.fast_advertisement_service_uuid)) {
LOG(INFO) << __func__
<< "Ble v2 started advertising for legacy device.";
<< "Ble started advertising for legacy device.";
restarted_mediums.push_back(BLUETOOTH);
LOG(INFO) << __func__
<< "After Ble v2 started advertising, for "
<< "After Ble started advertising, for "
"legacy, BT added to restarted mediums";
} else {
LOG(WARNING)
<< __func__
<< "BLE v2 failed advertising for legacy device, revert BTC";
<< "BLE failed advertising for legacy device, revert BTC";
bluetooth_medium_.TurnOffDiscoverability();
bluetooth_medium_.StopAcceptingConnections(std::string(service_id));
}
@@ -1654,7 +1653,7 @@ P2pClusterPcpHandler::UpdateDiscoveryOptionsImpl(
bool needs_restart = old_options.low_power != discovery_options.low_power;
// ble
if (NeedsToTurnOffDiscoveryMedium(BLE, old_options, discovery_options)) {
ble_v2_medium_.StopScanning(std::string(service_id));
ble_medium_.StopScanning(std::string(service_id));
StartEndpointLostByMediumAlarms(client, BLE);
}
// bt classic
@@ -1700,13 +1699,13 @@ P2pClusterPcpHandler::UpdateDiscoveryOptionsImpl(
operation_result_with_mediums.push_back(*operation_result_with_medium);
} else {
ErrorOr<Medium> ble_result = {Error(OperationResultCode::DETAIL_UNKNOWN)};
ble_result = StartBleV2Scanning(client, std::string(service_id),
discovery_options);
ble_result =
StartBleScanning(client, std::string(service_id), discovery_options);
if (ble_result.has_value()) {
restarted_mediums.push_back(BLE);
} else {
LOG(WARNING) << "UpdateDiscoveryOptionsImpl: unable to "
"restart blev2 scanning";
"restart ble scanning";
}
std::unique_ptr<ConnectionsLog::OperationResultWithMedium>
@@ -1995,7 +1994,7 @@ void P2pClusterPcpHandler::StartBluetoothDiscoveryWithPause(
operation_result_with_mediums,
int update_index) {
if (bluetooth_radio_.IsEnabled()) {
if (ble_v2_medium_.IsExtendedAdvertisementsAvailable() &&
if (ble_medium_.IsExtendedAdvertisementsAvailable() &&
std::find(mediums_started_successfully.begin(),
mediums_started_successfully.end(),
BLE) != mediums_started_successfully.end()) {
@@ -2088,9 +2087,9 @@ BasePcpHandler::ConnectImplResult P2pClusterPcpHandler::BluetoothConnectImpl(
.endpoint_channel = std::move(channel)};
}
void P2pClusterPcpHandler::BleV2ConnectionAcceptedHandler(
void P2pClusterPcpHandler::BleConnectionAcceptedHandler(
ClientProxy* client, absl::string_view local_endpoint_info,
NearbyDevice::Type device_type, BleV2Socket socket,
NearbyDevice::Type device_type, BleSocket socket,
const std::string& service_id) {
if (!socket.IsValid()) {
LOG(WARNING) << "Invalid socket in accept callback("
@@ -2103,7 +2102,7 @@ void P2pClusterPcpHandler::BleV2ConnectionAcceptedHandler(
[this, client, service_id, device_type,
socket = std::move(socket)]() RUN_ON_PCP_HANDLER_THREAD() mutable {
ByteArray remote_peripheral_info = socket.GetRemotePeripheral().GetId();
auto channel = std::make_unique<BleV2EndpointChannel>(
auto channel = std::make_unique<BleEndpointChannel>(
service_id, std::string(remote_peripheral_info), socket);
OnIncomingConnection(client, remote_peripheral_info, std::move(channel),
@@ -2134,7 +2133,7 @@ void P2pClusterPcpHandler::BleL2capConnectionAcceptedHandler(
});
}
ErrorOr<Medium> P2pClusterPcpHandler::StartBleV2Advertising(
ErrorOr<Medium> P2pClusterPcpHandler::StartBleAdvertising(
ClientProxy* client, const std::string& service_id,
const std::string& local_endpoint_id, const ByteArray& local_endpoint_info,
const AdvertisingOptions& advertising_options, WebRtcState web_rtc_state) {
@@ -2142,17 +2141,17 @@ ErrorOr<Medium> P2pClusterPcpHandler::StartBleV2Advertising(
// request comes in very quickly. BLE allows connecting over BLE itself, as
// well as advertising the Bluetooth MAC address to allow connecting over
// Bluetooth Classic.
LOG(INFO) << "P2pClusterPcpHandler::StartBleV2Advertising: service_id="
LOG(INFO) << "P2pClusterPcpHandler::StartBleAdvertising: service_id="
<< service_id << " : start";
ErrorOr<int> ble_l2cap_result = 0;
if (!ble_v2_medium_.IsAcceptingConnections(service_id)) {
if (!ble_medium_.IsAcceptingConnections(service_id)) {
// TODO(b/380411884): Remove this check since we shouldn't enable radio by
// NC.
if (!bluetooth_radio_.Enable()) {
LOG(WARNING)
<< "In StartBleV2Advertising("
<< "In StartBleAdvertising("
<< absl::BytesToHexString(local_endpoint_info.data())
<< "), client=" << client->GetClientId()
<< " failed to start accepting for incoming BLE connections to "
@@ -2163,7 +2162,7 @@ ErrorOr<Medium> P2pClusterPcpHandler::StartBleV2Advertising(
if (NearbyFlags::GetInstance().GetBoolFlag(
config_package_nearby::nearby_connections_feature::
kEnableBleL2cap)) {
ble_l2cap_result = ble_v2_medium_.StartAcceptingL2capConnections(
ble_l2cap_result = ble_medium_.StartAcceptingL2capConnections(
service_id,
absl::bind_front(
&P2pClusterPcpHandler::BleL2capConnectionAcceptedHandler, this,
@@ -2171,23 +2170,23 @@ ErrorOr<Medium> P2pClusterPcpHandler::StartBleV2Advertising(
NearbyDevice::Type::kConnectionsDevice));
}
ErrorOr<bool> ble_v2_result = ble_v2_medium_.StartAcceptingConnections(
ErrorOr<bool> ble_result = ble_medium_.StartAcceptingConnections(
service_id,
absl::bind_front(&P2pClusterPcpHandler::BleV2ConnectionAcceptedHandler,
absl::bind_front(&P2pClusterPcpHandler::BleConnectionAcceptedHandler,
this, client, local_endpoint_info.AsStringView(),
NearbyDevice::Type::kConnectionsDevice));
if (ble_v2_result.has_error() && ble_l2cap_result.has_error()) {
if (ble_result.has_error() && ble_l2cap_result.has_error()) {
LOG(WARNING)
<< "In StartBleV2Advertising("
<< "In StartBleAdvertising("
<< absl::BytesToHexString(local_endpoint_info.data())
<< "), client=" << client->GetClientId()
<< " failed to start accepting for incoming BLE connections to "
"service_id="
<< service_id;
return {Error(ble_v2_result.error().operation_result_code().value())};
return {Error(ble_result.error().operation_result_code().value())};
}
LOG(INFO)
<< "In StartBleV2Advertising("
<< "In StartBleAdvertising("
<< absl::BytesToHexString(local_endpoint_info.data())
<< "), client=" << client->GetClientId()
<< " started accepting for incoming BLE connections to service_id="
@@ -2205,7 +2204,7 @@ ErrorOr<Medium> P2pClusterPcpHandler::StartBleV2Advertising(
// NC.
if (!bluetooth_radio_.Enable()) {
LOG(WARNING)
<< "In BT StartBleV2Advertising("
<< "In BT StartBleAdvertising("
<< absl::BytesToHexString(local_endpoint_info.data())
<< "), client=" << client->GetClientId()
<< " failed to start accepting for incoming BLE connections to "
@@ -2222,17 +2221,17 @@ ErrorOr<Medium> P2pClusterPcpHandler::StartBleV2Advertising(
NearbyDevice::Type::kConnectionsDevice));
if (accept_result.has_error()) {
LOG(WARNING)
<< "In BT StartBleV2Advertising("
<< "In BT StartBleAdvertising("
<< absl::BytesToHexString(local_endpoint_info.data())
<< "), client=" << client->GetClientId()
<< " failed to start accepting for incoming BLE connections to "
"service_id="
<< service_id;
ble_v2_medium_.StopAcceptingConnections(service_id);
ble_medium_.StopAcceptingConnections(service_id);
return {Error(accept_result.error().operation_result_code().value())};
}
LOG(INFO)
<< "In BT StartBleV2Advertising("
<< "In BT StartBleAdvertising("
<< absl::BytesToHexString(local_endpoint_info.data())
<< "), client=" << client->GetClientId()
<< " started accepting for incoming BLE connections to service_id="
@@ -2240,7 +2239,7 @@ ErrorOr<Medium> P2pClusterPcpHandler::StartBleV2Advertising(
}
}
LOG(INFO) << "In StartBleV2Advertising("
LOG(INFO) << "In StartBleAdvertising("
<< absl::BytesToHexString(local_endpoint_info.data())
<< "), client=" << client->GetClientId()
<< " start to generate BleAdvertisement with service_id="
@@ -2284,42 +2283,42 @@ ErrorOr<Medium> P2pClusterPcpHandler::StartBleV2Advertising(
}
}
if (advertisement_bytes.Empty() && dct_advertisement_bytes.Empty()) {
LOG(WARNING) << "In StartBleV2Advertising("
LOG(WARNING) << "In StartBleAdvertising("
<< absl::BytesToHexString(local_endpoint_info.data())
<< "), client=" << client->GetClientId()
<< " failed to create an advertisement.";
ble_v2_medium_.StopAcceptingConnections(service_id);
ble_medium_.StopAcceptingConnections(service_id);
return {Error(OperationResultCode::NEARBY_BLE_ADVERTISE_TO_BYTES_FAILURE)};
}
LOG(INFO) << "In StartBleV2Advertising("
LOG(INFO) << "In StartBleAdvertising("
<< absl::BytesToHexString(local_endpoint_info.data())
<< "), client=" << client->GetClientId()
<< " generated BleAdvertisement with service_id=" << service_id;
ErrorOr<bool> ble_v2_result = false;
ErrorOr<bool> ble_result = false;
if (dct_advertisement_bytes.Empty()) {
ble_v2_result = ble_v2_medium_.StartAdvertising(
ble_result = ble_medium_.StartAdvertising(
service_id, power_level,
advertising_options.fast_advertisement_service_uuid.empty()
? BleV2::AdvertisingType::kRegular
: BleV2::AdvertisingType::kFast,
? Ble::AdvertisingType::kRegular
: Ble::AdvertisingType::kFast,
advertisement_bytes);
} else {
ble_v2_result = ble_v2_medium_.StartAdvertising(
service_id, power_level, BleV2::AdvertisingType::kDct,
dct_advertisement_bytes);
ble_result = ble_medium_.StartAdvertising(service_id, power_level,
Ble::AdvertisingType::kDct,
dct_advertisement_bytes);
}
if (ble_v2_result.has_error()) {
LOG(WARNING) << "In StartBleV2Advertising("
if (ble_result.has_error()) {
LOG(WARNING) << "In StartBleAdvertising("
<< absl::BytesToHexString(local_endpoint_info.data())
<< "), client=" << client->GetClientId()
<< " couldn't start BLE Advertising with BleAdvertisement "
<< absl::BytesToHexString(advertisement_bytes.data());
ble_v2_medium_.StopAcceptingConnections(service_id);
return {Error(ble_v2_result.error().operation_result_code().value())};
ble_medium_.StopAcceptingConnections(service_id);
return {Error(ble_result.error().operation_result_code().value())};
}
LOG(INFO) << "In StartBleV2Advertising("
LOG(INFO) << "In StartBleAdvertising("
<< absl::BytesToHexString(local_endpoint_info.data())
<< "), client=" << client->GetClientId()
<< " started BLE Advertising with BleAdvertisement "
@@ -2327,50 +2326,50 @@ ErrorOr<Medium> P2pClusterPcpHandler::StartBleV2Advertising(
return {BLE};
}
ErrorOr<Medium> P2pClusterPcpHandler::StartBleV2Scanning(
ErrorOr<Medium> P2pClusterPcpHandler::StartBleScanning(
ClientProxy* client, const std::string& service_id,
const DiscoveryOptions& discovery_options) {
PowerLevel power_level = discovery_options.low_power ? PowerLevel::kLowPower
: PowerLevel::kHighPower;
// TODO(b/380411884): Remove this check since we shouldn't enable radio by NC.
if (!bluetooth_radio_.Enable()) {
LOG(INFO) << "In StartBleV2Scanning(), client=" << client->GetClientId()
LOG(INFO) << "In StartBleScanning(), client=" << client->GetClientId()
<< " couldn't start scanning on BLE for service_id="
<< service_id;
return {Error(OperationResultCode::DEVICE_STATE_RADIO_ENABLING_FAILURE)};
}
if (discovery_options.ble_options.alternate_uuid.has_value()) {
ble_v2_medium_.AddAlternateUuidForService(
ble_medium_.AddAlternateUuidForService(
*discovery_options.ble_options.alternate_uuid, service_id);
}
ErrorOr<bool> ble_v2_result = ble_v2_medium_.StartScanning(
ErrorOr<bool> ble_result = ble_medium_.StartScanning(
service_id, GetPcp(), power_level, client->IsDctEnabled(),
{
.peripheral_discovered_cb = absl::bind_front(
&P2pClusterPcpHandler::BleV2PeripheralDiscoveredHandler, this,
&P2pClusterPcpHandler::BlePeripheralDiscoveredHandler, this,
client),
.peripheral_lost_cb = absl::bind_front(
&P2pClusterPcpHandler::BleV2PeripheralLostHandler, this, client),
&P2pClusterPcpHandler::BlePeripheralLostHandler, this, client),
.instant_lost_cb = absl::bind_front(
&P2pClusterPcpHandler::BleV2InstantLostHandler, this, client),
&P2pClusterPcpHandler::BleInstantLostHandler, this, client),
.legacy_device_discovered_cb = absl::bind_front(
&P2pClusterPcpHandler::BleV2LegacyDeviceDiscoveredHandler, this),
&P2pClusterPcpHandler::BleLegacyDeviceDiscoveredHandler, this),
});
if (!ble_v2_result.has_error()) {
LOG(INFO) << "In StartBleV2Scanning(), client=" << client->GetClientId()
if (!ble_result.has_error()) {
LOG(INFO) << "In StartBleScanning(), client=" << client->GetClientId()
<< " started scanning for BLE advertisements for service_id="
<< service_id;
return {BLE};
}
LOG(INFO) << "In StartBleV2Scanning(), client=" << client->GetClientId()
LOG(INFO) << "In StartBleScanning(), client=" << client->GetClientId()
<< " couldn't start scanning on BLE for service_id=" << service_id;
return {Error(ble_v2_result.error().operation_result_code().value())};
return {Error(ble_result.error().operation_result_code().value())};
}
BasePcpHandler::ConnectImplResult P2pClusterPcpHandler::BleV2ConnectImpl(
ClientProxy* client, BleV2Endpoint* endpoint) {
BleV2Peripheral& peripheral = endpoint->ble_peripheral;
BasePcpHandler::ConnectImplResult P2pClusterPcpHandler::BleConnectImpl(
ClientProxy* client, BleEndpoint* endpoint) {
BlePeripheral& peripheral = endpoint->ble_peripheral;
VLOG(1) << "Client " << client->GetClientId()
<< " is attempting to connect to (" << peripheral.ToReadableString()
@@ -2381,11 +2380,11 @@ BasePcpHandler::ConnectImplResult P2pClusterPcpHandler::BleV2ConnectImpl(
peripheral.GetPsm() !=
mediums::BleAdvertisementHeader::kDefaultPsmValue) {
ErrorOr<BleL2capSocket> ble_l2cap_socket_result =
ble_v2_medium_.ConnectOverL2cap(
ble_medium_.ConnectOverL2cap(
endpoint->service_id, peripheral,
client->GetCancellationFlag(endpoint->endpoint_id));
if (!ble_l2cap_socket_result.has_error()) {
LOG(INFO) << "In BleV2ConnectImpl(), connected to Ble L2CAP device "
LOG(INFO) << "In BleConnectImpl(), connected to Ble L2CAP device "
<< absl::BytesToHexString(peripheral.GetId().data())
<< " for endpoint(id=" << endpoint->endpoint_id << ").";
auto channel = std::make_unique<BleL2capEndpointChannel>(
@@ -2398,18 +2397,18 @@ BasePcpHandler::ConnectImplResult P2pClusterPcpHandler::BleV2ConnectImpl(
.endpoint_channel = std::move(channel),
};
} else {
LOG(WARNING) << "In BleV2ConnectImpl(), failed to connect to Ble L2CAP "
LOG(WARNING) << "In BleConnectImpl(), failed to connect to Ble L2CAP "
"device "
<< absl::BytesToHexString(peripheral.GetId().data())
<< " for endpoint(id=" << endpoint->endpoint_id << ").";
}
}
ErrorOr<BleV2Socket> ble_socket_result = ble_v2_medium_.Connect(
endpoint->service_id, peripheral,
client->GetCancellationFlag(endpoint->endpoint_id));
ErrorOr<BleSocket> ble_socket_result =
ble_medium_.Connect(endpoint->service_id, peripheral,
client->GetCancellationFlag(endpoint->endpoint_id));
if (ble_socket_result.has_error()) {
LOG(ERROR) << "In BleV2ConnectImpl(), failed to connect to BLE device "
LOG(ERROR) << "In BleConnectImpl(), failed to connect to BLE device "
<< absl::BytesToHexString(peripheral.GetId().data())
<< " for endpoint(id=" << endpoint->endpoint_id << ").";
return BasePcpHandler::ConnectImplResult{
@@ -2419,7 +2418,7 @@ BasePcpHandler::ConnectImplResult P2pClusterPcpHandler::BleV2ConnectImpl(
};
}
auto channel = std::make_unique<BleV2EndpointChannel>(
auto channel = std::make_unique<BleEndpointChannel>(
endpoint->service_id, /*channel_name=*/endpoint->endpoint_id,
ble_socket_result.value());
@@ -2614,10 +2613,10 @@ ErrorOr<Medium> P2pClusterPcpHandler::StartWifiLanAdvertising(
NearbyDevice::Type::kConnectionsDevice));
if (wifi_lan_result.has_error()) {
LOG(WARNING) << "In StartWifiLanAdvertising("
<< absl::BytesToHexString(local_endpoint_info.data())
<< "), client=" << client->GetClientId()
<< " couldn't advertise with WifiLanServiceInfo "
<< nsd_service_info.GetServiceName();
<< absl::BytesToHexString(local_endpoint_info.data())
<< "), client=" << client->GetClientId()
<< " couldn't advertise with WifiLanServiceInfo "
<< nsd_service_info.GetServiceName();
return {Error(wifi_lan_result.error().operation_result_code().value())};
}
VLOG(1) << "In StartWifiLanAdvertising("
@@ -33,7 +33,7 @@
#include "connections/implementation/endpoint_manager.h"
#include "connections/implementation/injected_bluetooth_device_store.h"
#include "connections/implementation/mediums/awdl.h"
#include "connections/implementation/mediums/ble_v2.h"
#include "connections/implementation/mediums/ble.h"
#include "connections/implementation/mediums/bluetooth_classic.h"
#include "connections/implementation/mediums/bluetooth_radio.h"
#include "connections/implementation/mediums/mediums.h"
@@ -46,7 +46,7 @@
#include "connections/status.h"
#include "connections/v3/connection_listening_options.h"
#include "internal/interop/device.h"
#include "internal/platform/ble_v2.h"
#include "internal/platform/ble.h"
#include "internal/platform/bluetooth_adapter.h"
#include "internal/platform/bluetooth_classic.h"
#include "internal/platform/nsd_service_info.h"
@@ -154,7 +154,7 @@ class P2pClusterPcpHandler : public BasePcpHandler {
ByteArray endpoint_info;
};
struct BleV2EndpointState {
struct BleEndpointFeatureState {
bool ble = false;
bool l2cap = false;
bool bt = false;
@@ -162,7 +162,7 @@ class P2pClusterPcpHandler : public BasePcpHandler {
using BluetoothDiscoveredDeviceCallback =
BluetoothClassic::DiscoveredDeviceCallback;
using BleV2DiscoveredPeripheralCallback = BleV2::DiscoveredPeripheralCallback;
using BleDiscoveredPeripheralCallback = Ble::DiscoveredPeripheralCallback;
using WifiLanDiscoveredServiceCallback = WifiLan::DiscoveredServiceCallback;
using AwdlDiscoveredServiceCallback = Awdl::DiscoveredServiceCallback;
@@ -214,44 +214,43 @@ class P2pClusterPcpHandler : public BasePcpHandler {
BasePcpHandler::ConnectImplResult BluetoothConnectImpl(
ClientProxy* client, BluetoothEndpoint* endpoint);
// BleV2
bool IsRecognizedBleV2Endpoint(absl::string_view service_id,
const BleAdvertisement& advertisement) const;
void BleV2PeripheralDiscoveredHandler(ClientProxy* client,
BleV2Peripheral peripheral,
const std::string& service_id,
const ByteArray& advertisement_bytes,
bool fast_advertisement);
void BleV2PeripheralLostHandler(ClientProxy* client,
BleV2Peripheral peripheral,
const std::string& service_id,
const ByteArray& advertisement_bytes,
bool fast_advertisement);
void BleV2InstantLostHandler(ClientProxy* client, BleV2Peripheral peripheral,
const std::string& service_id,
const ByteArray& advertisement_bytes,
bool fast_advertisement);
void BleV2LegacyDeviceDiscoveredHandler();
void BleV2ConnectionAcceptedHandler(ClientProxy* client,
absl::string_view local_endpoint_info,
NearbyDevice::Type device_type,
BleV2Socket socket,
const std::string& service_id);
// Ble
bool IsRecognizedBleEndpoint(absl::string_view service_id,
const BleAdvertisement& advertisement) const;
void BlePeripheralDiscoveredHandler(ClientProxy* client,
BlePeripheral peripheral,
const std::string& service_id,
const ByteArray& advertisement_bytes,
bool fast_advertisement);
void BlePeripheralLostHandler(ClientProxy* client, BlePeripheral peripheral,
const std::string& service_id,
const ByteArray& advertisement_bytes,
bool fast_advertisement);
void BleInstantLostHandler(ClientProxy* client, BlePeripheral peripheral,
const std::string& service_id,
const ByteArray& advertisement_bytes,
bool fast_advertisement);
void BleLegacyDeviceDiscoveredHandler();
void BleConnectionAcceptedHandler(ClientProxy* client,
absl::string_view local_endpoint_info,
NearbyDevice::Type device_type,
BleSocket socket,
const std::string& service_id);
void BleL2capConnectionAcceptedHandler(ClientProxy* client,
absl::string_view local_endpoint_info,
NearbyDevice::Type device_type,
BleL2capSocket socket,
const std::string& service_id);
ErrorOr<location::nearby::proto::connections::Medium> StartBleV2Advertising(
ErrorOr<location::nearby::proto::connections::Medium> StartBleAdvertising(
ClientProxy* client, const std::string& service_id,
const std::string& local_endpoint_id,
const ByteArray& local_endpoint_info,
const AdvertisingOptions& advertising_options, WebRtcState web_rtc_state);
ErrorOr<location::nearby::proto::connections::Medium> StartBleV2Scanning(
ErrorOr<location::nearby::proto::connections::Medium> StartBleScanning(
ClientProxy* client, const std::string& service_id,
const DiscoveryOptions& discovery_options);
BasePcpHandler::ConnectImplResult BleV2ConnectImpl(ClientProxy* client,
BleV2Endpoint* endpoint);
BasePcpHandler::ConnectImplResult BleConnectImpl(ClientProxy* client,
BleEndpoint* endpoint);
// Awdl
void AwdlServiceDiscoveredHandler(ClientProxy* client,
NsdServiceInfo service_info,
@@ -301,7 +300,7 @@ class P2pClusterPcpHandler : public BasePcpHandler {
Awdl& awdl_medium_;
BluetoothRadio& bluetooth_radio_;
BluetoothClassic& bluetooth_medium_;
BleV2& ble_v2_medium_;
Ble& ble_medium_;
WifiLan& wifi_lan_medium_;
WifiHotspot& wifi_hotspot_medium_;
WifiDirect& wifi_direct_medium_;
@@ -317,7 +316,7 @@ class P2pClusterPcpHandler : public BasePcpHandler {
absl::flat_hash_map<std::string, BleEndpointState> found_ble_endpoints_;
// Maps a BlePeripheral.Id_ to its corresponding BleEndpointState.
absl::flat_hash_map<ByteArray, BleV2EndpointState>
absl::flat_hash_map<ByteArray, BleEndpointFeatureState>
found_endpoints_in_ble_discover_cb_;
// Maps service id to its client.
@@ -175,7 +175,7 @@ TEST_F(P2pClusterPcpHandlerTest, NoBluetoothDiscoveryWhenRadioIsOff) {
handler.StartDiscovery(&client_a_, service_id_,
GetBluetoothAndBleDiscoveryOptions(), {});
EXPECT_FALSE(mediums.GetBluetoothClassic().IsDiscovering(service_id_));
EXPECT_TRUE(mediums.GetBleV2().IsScanning(service_id_));
EXPECT_TRUE(mediums.GetBle().IsScanning(service_id_));
mediums.GetBluetoothRadio().Enable();
handler.StopDiscovery(&client_a_);
@@ -187,7 +187,7 @@ TEST_F(P2pClusterPcpHandlerTest,
std::string endpoint_name{"endpoint_name"};
env_.Start();
// Enable BLE V2 extended advertisement for client_a_.
// Enable BLE extended advertisement for client_a_.
env_.SetBleExtendedAdvertisementsAvailable(true);
Mediums mediums_a;
EndpointChannelManager ecm_a;
@@ -196,7 +196,7 @@ TEST_F(P2pClusterPcpHandlerTest,
BwuManager bwu_a(mediums_a, em_a, ecm_a, {}, {});
P2pClusterPcpHandler handler_a(&mediums_a, &em_a, &ecm_a, &bwu_a, ibds_a);
// Disable BLE V2 extended advertisement for client_b_.
// Disable BLE extended advertisement for client_b_.
env_.SetBleExtendedAdvertisementsAvailable(false);
Mediums mediums_b;
EndpointChannelManager ecm_b;
@@ -359,14 +359,13 @@ TEST_P(P2pClusterPcpHandlerTestWithParam, AdvertiseForLegacyDeviceWithBt) {
handler_a.StartAdvertising(&client_a_, service_id_, advertising_options_,
{.endpoint_info = ByteArray{endpoint_name}}),
Status{Status::kSuccess});
// advertising for legacy device depends on both BT and BLE V2 enabled.
// advertising for legacy device depends on both BT and BLE enabled.
if (std::get<0>(GetParam()).bluetooth) {
EXPECT_TRUE(mediums_a.GetBleV2().IsAdvertisingForLegacyDevice(service_id_));
EXPECT_TRUE(mediums_a.GetBle().IsAdvertisingForLegacyDevice(service_id_));
}
handler_a.StopAdvertising(&client_a_);
if (std::get<0>(GetParam()).bluetooth) {
EXPECT_FALSE(
mediums_a.GetBleV2().IsAdvertisingForLegacyDevice(service_id_));
EXPECT_FALSE(mediums_a.GetBle().IsAdvertisingForLegacyDevice(service_id_));
}
env_.Stop();
}
@@ -390,20 +389,19 @@ TEST_P(P2pClusterPcpHandlerTestWithParam, CanUpdateAdvertisingOptions) {
ASSERT_FALSE(mediums_a.GetWifiLan().IsAcceptingConnections(service_id_));
mediums_a.GetWifiLan().StopAdvertising(service_id_);
ASSERT_FALSE(mediums_a.GetWifiLan().IsAdvertising(service_id_));
mediums_a.GetBleV2().StopAcceptingConnections(service_id_);
ASSERT_FALSE(mediums_a.GetBleV2().IsAcceptingConnections(service_id_));
mediums_a.GetBleV2().StopAdvertising(service_id_);
ASSERT_FALSE(mediums_a.GetBleV2().IsAdvertising(service_id_));
mediums_a.GetBle().StopAcceptingConnections(service_id_);
ASSERT_FALSE(mediums_a.GetBle().IsAcceptingConnections(service_id_));
mediums_a.GetBle().StopAdvertising(service_id_);
ASSERT_FALSE(mediums_a.GetBle().IsAdvertising(service_id_));
BooleanMediumSelector enabled = advertising_options_.allowed;
if (enabled.bluetooth) {
EXPECT_FALSE(
mediums_a.GetBleV2().IsAdvertisingForLegacyDevice(service_id_));
EXPECT_FALSE(mediums_a.GetBle().IsAdvertisingForLegacyDevice(service_id_));
}
EXPECT_EQ(
handler_a.StartAdvertising(&client_a_, service_id_, advertising_options_,
{.endpoint_info = ByteArray{endpoint_name}}),
Status{Status::kSuccess});
EXPECT_EQ(enabled.ble, mediums_a.GetBleV2().IsAdvertising(service_id_));
EXPECT_EQ(enabled.ble, mediums_a.GetBle().IsAdvertising(service_id_));
EXPECT_EQ(enabled.wifi_lan,
mediums_a.GetWifiLan().IsAdvertising(service_id_));
EXPECT_EQ(
@@ -412,7 +410,7 @@ TEST_P(P2pClusterPcpHandlerTestWithParam, CanUpdateAdvertisingOptions) {
EXPECT_EQ(enabled.bluetooth,
mediums_a.GetBluetoothClassic().TurnOffDiscoverability());
if (enabled.bluetooth) {
EXPECT_TRUE(mediums_a.GetBleV2().IsAdvertisingForLegacyDevice(service_id_));
EXPECT_TRUE(mediums_a.GetBle().IsAdvertisingForLegacyDevice(service_id_));
}
// Turn discoverability back on
mediums_a.GetBluetoothClassic().TurnOnDiscoverability(service_id_);
@@ -428,11 +426,10 @@ TEST_P(P2pClusterPcpHandlerTestWithParam, CanUpdateAdvertisingOptions) {
EXPECT_EQ(
handler_a.UpdateAdvertisingOptions(&client_a_, service_id_, new_options),
Status{Status::kSuccess});
EXPECT_EQ(enabled.ble, mediums_a.GetBleV2().IsAdvertising(service_id_));
EXPECT_EQ(enabled.ble, mediums_a.GetBle().IsAdvertising(service_id_));
// Low power won't restart BT, nor BLE advertising for legacy device.
if (enabled.bluetooth) {
EXPECT_FALSE(
mediums_a.GetBleV2().IsAdvertisingForLegacyDevice(service_id_));
EXPECT_FALSE(mediums_a.GetBle().IsAdvertisingForLegacyDevice(service_id_));
}
EXPECT_FALSE(mediums_a.GetWifiLan().IsAdvertising(service_id_));
EXPECT_FALSE(mediums_a.GetBluetoothClassic().TurnOffDiscoverability());
@@ -463,10 +460,10 @@ TEST_P(P2pClusterPcpHandlerTestWithParam,
ASSERT_FALSE(mediums_a.GetWifiLan().IsAcceptingConnections(service_id_));
mediums_a.GetWifiLan().StopAdvertising(service_id_);
ASSERT_FALSE(mediums_a.GetWifiLan().IsAdvertising(service_id_));
mediums_a.GetBleV2().StopAcceptingConnections(service_id_);
ASSERT_FALSE(mediums_a.GetBleV2().IsAcceptingConnections(service_id_));
mediums_a.GetBleV2().StopAdvertising(service_id_);
ASSERT_FALSE(mediums_a.GetBleV2().IsAdvertising(service_id_));
mediums_a.GetBle().StopAcceptingConnections(service_id_);
ASSERT_FALSE(mediums_a.GetBle().IsAcceptingConnections(service_id_));
mediums_a.GetBle().StopAdvertising(service_id_);
ASSERT_FALSE(mediums_a.GetBle().IsAdvertising(service_id_));
AdvertisingOptions old_options{
{
Strategy::kP2pCluster,
@@ -478,30 +475,29 @@ TEST_P(P2pClusterPcpHandlerTestWithParam,
false, // enable_bluetooth_listening
};
if (enabled.bluetooth) {
EXPECT_FALSE(
mediums_a.GetBleV2().IsAdvertisingForLegacyDevice(service_id_));
EXPECT_FALSE(mediums_a.GetBle().IsAdvertisingForLegacyDevice(service_id_));
}
EXPECT_EQ(
handler_a.StartAdvertising(&client_a_, service_id_, old_options,
{.endpoint_info = ByteArray{endpoint_name}}),
Status{Status::kSuccess});
EXPECT_EQ(enabled.ble, mediums_a.GetBleV2().IsAdvertising(service_id_));
EXPECT_EQ(enabled.ble, mediums_a.GetBle().IsAdvertising(service_id_));
EXPECT_EQ(enabled.wifi_lan,
mediums_a.GetWifiLan().IsAdvertising(service_id_));
EXPECT_EQ(
enabled.bluetooth,
mediums_a.GetBluetoothClassic().IsAcceptingConnections(service_id_));
if (enabled.bluetooth) {
EXPECT_TRUE(mediums_a.GetBleV2().IsAdvertisingForLegacyDevice(service_id_));
EXPECT_TRUE(mediums_a.GetBle().IsAdvertisingForLegacyDevice(service_id_));
}
EXPECT_EQ(enabled.bluetooth,
mediums_a.GetBluetoothClassic().TurnOffDiscoverability());
EXPECT_EQ(handler_a.UpdateAdvertisingOptions(&client_a_, service_id_,
advertising_options_),
Status{Status::kSuccess});
EXPECT_EQ(enabled.ble, mediums_a.GetBleV2().IsAdvertising(service_id_));
EXPECT_EQ(enabled.ble, mediums_a.GetBle().IsAdvertising(service_id_));
if (enabled.bluetooth) {
EXPECT_TRUE(mediums_a.GetBleV2().IsAdvertisingForLegacyDevice(service_id_));
EXPECT_TRUE(mediums_a.GetBle().IsAdvertisingForLegacyDevice(service_id_));
}
EXPECT_EQ(enabled.wifi_lan,
mediums_a.GetWifiLan().IsAdvertising(service_id_));
@@ -512,8 +508,7 @@ TEST_P(P2pClusterPcpHandlerTestWithParam,
mediums_a.GetBluetoothClassic().IsAcceptingConnections(service_id_));
handler_a.StopAdvertising(&client_a_);
if (enabled.bluetooth) {
EXPECT_FALSE(
mediums_a.GetBleV2().IsAdvertisingForLegacyDevice(service_id_));
EXPECT_FALSE(mediums_a.GetBle().IsAdvertisingForLegacyDevice(service_id_));
}
env_.Stop();
}
@@ -589,7 +584,7 @@ TEST_P(P2pClusterPcpHandlerTestWithParam, CanDiscoverLegacy) {
},
}),
Status{Status::kSuccess});
// advertising for legacy device depends on both BT and BLE V2 enabled.
// advertising for legacy device depends on both BT and BLE enabled.
EXPECT_TRUE(latch.Await(absl::Milliseconds(1000)).result());
// We discovered endpoint over one medium. Before we finish the test, we have
// to stop discovery for other mediums that may be still ongoing.
@@ -618,7 +613,7 @@ TEST_P(P2pClusterPcpHandlerTestWithParam, PauseBluetoothClassicDiscovery) {
handler_a.StartDiscovery(&client_a_, service_id_, discovery_options_, {}),
Status{Status::kSuccess});
EXPECT_TRUE(mediums_a.GetBleV2().IsScanning(service_id_));
EXPECT_TRUE(mediums_a.GetBle().IsScanning(service_id_));
EXPECT_FALSE(mediums_a.GetBluetoothClassic().IsDiscovering(service_id_));
// Before we finish the test, we have to stop discovery for other mediums that
// may be still ongoing.
@@ -636,7 +631,7 @@ TEST_P(P2pClusterPcpHandlerTestWithParam, ResumeBluetoothClassicDiscovery) {
std::string endpoint_name{"endpoint_name"};
env_.Start();
// Enable BLE V2 extended advertisement for client_a_.
// Enable BLE extended advertisement for client_a_.
env_.SetBleExtendedAdvertisementsAvailable(true);
Mediums mediums_a;
EndpointChannelManager ecm_a;
@@ -645,7 +640,7 @@ TEST_P(P2pClusterPcpHandlerTestWithParam, ResumeBluetoothClassicDiscovery) {
BwuManager bwu_a(mediums_a, em_a, ecm_a, {}, {});
P2pClusterPcpHandler handler_a(&mediums_a, &em_a, &ecm_a, &bwu_a, ibds_a);
// Disable BLE V2 extended advertisement for client_b_.
// Disable BLE extended advertisement for client_b_.
env_.SetBleExtendedAdvertisementsAvailable(false);
Mediums mediums_b;
EndpointChannelManager ecm_b;
@@ -668,7 +663,7 @@ TEST_P(P2pClusterPcpHandlerTestWithParam, ResumeBluetoothClassicDiscovery) {
}),
Status{Status::kSuccess});
EXPECT_TRUE(mediums_a.GetBleV2().IsScanning(service_id_));
EXPECT_TRUE(mediums_a.GetBle().IsScanning(service_id_));
EXPECT_FALSE(mediums_a.GetBluetoothClassic().IsDiscovering(service_id_));
EXPECT_EQ(
@@ -679,7 +674,7 @@ TEST_P(P2pClusterPcpHandlerTestWithParam, ResumeBluetoothClassicDiscovery) {
EXPECT_TRUE(latch.Await(absl::Milliseconds(1000)).result());
absl::SleepFor(absl::Milliseconds(100));
EXPECT_TRUE(mediums_a.GetBleV2().IsScanning(service_id_));
EXPECT_TRUE(mediums_a.GetBle().IsScanning(service_id_));
EXPECT_TRUE(mediums_a.GetBluetoothClassic().IsDiscovering(service_id_));
// Before we finish the test, we have to stop discovery for other mediums that
@@ -783,7 +778,7 @@ TEST_P(P2pClusterPcpHandlerTestWithParam, CanUpdateDiscoveryOptions) {
handler_a.StartDiscovery(&client_a_, service_id_, discovery_options_, {}),
Status{Status::kSuccess});
BooleanMediumSelector enabled = std::get<0>(GetParam());
EXPECT_EQ(enabled.ble, mediums_a.GetBleV2().IsScanning(service_id_));
EXPECT_EQ(enabled.ble, mediums_a.GetBle().IsScanning(service_id_));
EXPECT_EQ(enabled.wifi_lan,
mediums_a.GetWifiLan().IsDiscovering(service_id_));
DiscoveryOptions new_options{
@@ -800,7 +795,7 @@ TEST_P(P2pClusterPcpHandlerTestWithParam, CanUpdateDiscoveryOptions) {
EXPECT_EQ(
handler_a.UpdateDiscoveryOptions(&client_a_, service_id_, new_options),
Status{Status::kSuccess});
EXPECT_EQ(enabled.ble, mediums_a.GetBleV2().IsScanning(service_id_));
EXPECT_EQ(enabled.ble, mediums_a.GetBle().IsScanning(service_id_));
EXPECT_FALSE(mediums_a.GetWifiLan().IsDiscovering(service_id_));
handler_a.StopDiscovery(&client_a_);
env_.Stop();
@@ -825,8 +820,8 @@ TEST_P(P2pClusterPcpHandlerTestWithParam, CanUpdateDiscoveryOptionsNoLowPower) {
ASSERT_FALSE(mediums_a.GetBluetoothClassic().TurnOffDiscoverability());
mediums_a.GetWifiLan().StopDiscovery(service_id_);
ASSERT_FALSE(mediums_a.GetWifiLan().IsDiscovering(service_id_));
mediums_a.GetBleV2().StopScanning(service_id_);
ASSERT_FALSE(mediums_a.GetBleV2().IsScanning(service_id_));
mediums_a.GetBle().StopScanning(service_id_);
ASSERT_FALSE(mediums_a.GetBle().IsScanning(service_id_));
DiscoveryOptions old_options = discovery_options_;
old_options.low_power = true;
old_options.allowed = old_enabled;
@@ -835,7 +830,7 @@ TEST_P(P2pClusterPcpHandlerTestWithParam, CanUpdateDiscoveryOptionsNoLowPower) {
// Start discovery
EXPECT_EQ(handler_a.StartDiscovery(&client_a_, service_id_, old_options, {}),
Status{Status::kSuccess});
EXPECT_EQ(old_enabled.ble, mediums_a.GetBleV2().IsScanning(service_id_));
EXPECT_EQ(old_enabled.ble, mediums_a.GetBle().IsScanning(service_id_));
EXPECT_EQ(old_enabled.wifi_lan,
mediums_a.GetWifiLan().IsDiscovering(service_id_));
EXPECT_EQ(old_enabled.bluetooth,
@@ -846,7 +841,7 @@ TEST_P(P2pClusterPcpHandlerTestWithParam, CanUpdateDiscoveryOptionsNoLowPower) {
handler_a.UpdateDiscoveryOptions(&client_a_, service_id_, new_options)
.Ok());
LOG(INFO) << "updated discovery options";
EXPECT_EQ(new_enabled.ble, mediums_a.GetBleV2().IsScanning(service_id_));
EXPECT_EQ(new_enabled.ble, mediums_a.GetBle().IsScanning(service_id_));
EXPECT_EQ(new_enabled.wifi_lan,
mediums_a.GetWifiLan().IsDiscovering(service_id_));
EXPECT_EQ(new_enabled.bluetooth,
@@ -871,13 +866,13 @@ TEST_P(P2pClusterPcpHandlerTestWithParam,
ASSERT_FALSE(mediums_a.GetBluetoothClassic().TurnOffDiscoverability());
mediums_a.GetWifiLan().StopDiscovery(service_id_);
ASSERT_FALSE(mediums_a.GetWifiLan().IsDiscovering(service_id_));
mediums_a.GetBleV2().StopScanning(service_id_);
ASSERT_FALSE(mediums_a.GetBleV2().IsScanning(service_id_));
mediums_a.GetBle().StopScanning(service_id_);
ASSERT_FALSE(mediums_a.GetBle().IsScanning(service_id_));
// Start discovery
EXPECT_EQ(
handler_a.StartDiscovery(&client_a_, service_id_, discovery_options_, {}),
Status{Status::kSuccess});
EXPECT_EQ(enabled.ble, mediums_a.GetBleV2().IsScanning(service_id_));
EXPECT_EQ(enabled.ble, mediums_a.GetBle().IsScanning(service_id_));
EXPECT_EQ(enabled.wifi_lan,
mediums_a.GetWifiLan().IsDiscovering(service_id_));
@@ -888,7 +883,7 @@ TEST_P(P2pClusterPcpHandlerTestWithParam,
discovery_options_);
EXPECT_TRUE(result.Ok());
LOG(INFO) << "updated discovery options";
EXPECT_EQ(enabled.ble, mediums_a.GetBleV2().IsScanning(service_id_));
EXPECT_EQ(enabled.ble, mediums_a.GetBle().IsScanning(service_id_));
EXPECT_EQ(enabled.wifi_lan,
mediums_a.GetWifiLan().IsDiscovering(service_id_));
// We didn't restart the medium.
@@ -1174,7 +1169,7 @@ TEST_P(P2pClusterPcpHandlerTestWithParam,
ASSERT_FALSE(
mediums_a.GetBluetoothClassic().IsAcceptingConnections(service_id_));
ASSERT_FALSE(mediums_a.GetWifiLan().IsAcceptingConnections(service_id_));
ASSERT_FALSE(mediums_a.GetBleV2().IsAcceptingConnections(service_id_));
ASSERT_FALSE(mediums_a.GetBle().IsAcceptingConnections(service_id_));
// call handler.
auto result = handler_a.StartListeningForIncomingConnections(
@@ -1183,7 +1178,7 @@ TEST_P(P2pClusterPcpHandlerTestWithParam,
EXPECT_TRUE(
mediums_a.GetBluetoothClassic().IsAcceptingConnections(service_id_));
EXPECT_TRUE(mediums_a.GetWifiLan().IsAcceptingConnections(service_id_));
EXPECT_TRUE(mediums_a.GetBleV2().IsAcceptingConnections(service_id_));
EXPECT_TRUE(mediums_a.GetBle().IsAcceptingConnections(service_id_));
EXPECT_EQ(result.second.size(), 3);
ASSERT_TRUE(client_a_.IsListeningForIncomingConnections());
EXPECT_EQ(client_a_.GetListeningForIncomingConnectionsServiceId(),
@@ -1221,7 +1216,7 @@ TEST_P(P2pClusterPcpHandlerTestWithParam,
ASSERT_FALSE(
mediums_a.GetBluetoothClassic().IsAcceptingConnections(service_id_));
ASSERT_FALSE(mediums_a.GetWifiLan().IsAcceptingConnections(service_id_));
ASSERT_FALSE(mediums_a.GetBleV2().IsAcceptingConnections(service_id_));
ASSERT_FALSE(mediums_a.GetBle().IsAcceptingConnections(service_id_));
// call handler.
auto result = handler_a.StartListeningForIncomingConnections(
&client_a_, service_id_, v3_options, {});
@@ -1229,13 +1224,13 @@ TEST_P(P2pClusterPcpHandlerTestWithParam,
ASSERT_TRUE(
mediums_a.GetBluetoothClassic().IsAcceptingConnections(service_id_));
ASSERT_TRUE(mediums_a.GetWifiLan().IsAcceptingConnections(service_id_));
ASSERT_TRUE(mediums_a.GetBleV2().IsAcceptingConnections(service_id_));
ASSERT_TRUE(mediums_a.GetBle().IsAcceptingConnections(service_id_));
// stop.
handler_a.StopListeningForIncomingConnections(&client_a_);
EXPECT_FALSE(
mediums_a.GetBluetoothClassic().IsAcceptingConnections(service_id_));
EXPECT_FALSE(mediums_a.GetWifiLan().IsAcceptingConnections(service_id_));
EXPECT_FALSE(mediums_a.GetBleV2().IsAcceptingConnections(service_id_));
EXPECT_FALSE(mediums_a.GetBle().IsAcceptingConnections(service_id_));
env_.Stop();
}
@@ -63,7 +63,7 @@ P2pPointToPointPcpHandler::GetConnectionMediumsByPriority() {
if (mediums_->GetBluetoothClassic().IsAvailable()) {
mediums.push_back(location::nearby::proto::connections::BLUETOOTH);
}
if (mediums_->GetBleV2().IsAvailable()) {
if (mediums_->GetBle().IsAvailable()) {
mediums.push_back(location::nearby::proto::connections::BLE);
}
return mediums;
@@ -58,7 +58,7 @@ P2pStarPcpHandler::GetConnectionMediumsByPriority() {
if (mediums_->GetBluetoothClassic().IsAvailable()) {
mediums.push_back(location::nearby::proto::connections::BLUETOOTH);
}
if (mediums_->GetBleV2().IsAvailable()) {
if (mediums_->GetBle().IsAvailable()) {
mediums.push_back(location::nearby::proto::connections::BLE);
}
return mediums;