mirror of
https://github.com/kidfromjupiter/nearby.git
synced 2026-09-14 14:46:12 -04:00
Internal refactor
PiperOrigin-RevId: 815749899
This commit is contained in:
committed by
Copybara-Service
parent
a065584164
commit
cce45b745e
+13
-14
@@ -253,7 +253,7 @@ let package = Package(
|
||||
"connections/implementation/analytics/BUILD",
|
||||
"connections/implementation/flags/BUILD",
|
||||
"connections/implementation/mediums/advertisements/BUILD",
|
||||
"connections/implementation/mediums/ble_v2/BUILD",
|
||||
"connections/implementation/mediums/ble/BUILD",
|
||||
"connections/implementation/mediums/multiplex/BUILD",
|
||||
"connections/implementation/mediums/BUILD",
|
||||
"connections/implementation/BUILD",
|
||||
@@ -309,17 +309,17 @@ let package = Package(
|
||||
"connections/implementation/mediums/advertisements/dct_advertisement_test.cc",
|
||||
"connections/implementation/mediums/advertisements/advertisement_util_test.cc",
|
||||
"connections/implementation/mediums/awdl_test.cc",
|
||||
"connections/implementation/mediums/ble_v2_test.cc",
|
||||
"connections/implementation/mediums/ble_v2/bloom_filter_test.cc",
|
||||
"connections/implementation/mediums/ble_v2/ble_l2cap_packet_test.cc",
|
||||
"connections/implementation/mediums/ble_v2/ble_packet_test.cc",
|
||||
"connections/implementation/mediums/ble_v2/ble_advertisement_test.cc",
|
||||
"connections/implementation/mediums/ble_v2/advertisement_read_result_test.cc",
|
||||
"connections/implementation/mediums/ble_v2/ble_advertisement_header_test.cc",
|
||||
"connections/implementation/mediums/ble_v2/ble_utils_test.cc",
|
||||
"connections/implementation/mediums/ble_v2/discovered_peripheral_tracker_test.cc",
|
||||
"connections/implementation/mediums/ble_v2/instant_on_lost_advertisement_test.cc",
|
||||
"connections/implementation/mediums/ble_v2/instant_on_lost_manager_test.cc",
|
||||
"connections/implementation/mediums/ble_test.cc",
|
||||
"connections/implementation/mediums/ble/bloom_filter_test.cc",
|
||||
"connections/implementation/mediums/ble/ble_l2cap_packet_test.cc",
|
||||
"connections/implementation/mediums/ble/ble_packet_test.cc",
|
||||
"connections/implementation/mediums/ble/ble_advertisement_test.cc",
|
||||
"connections/implementation/mediums/ble/advertisement_read_result_test.cc",
|
||||
"connections/implementation/mediums/ble/ble_advertisement_header_test.cc",
|
||||
"connections/implementation/mediums/ble/ble_utils_test.cc",
|
||||
"connections/implementation/mediums/ble/discovered_peripheral_tracker_test.cc",
|
||||
"connections/implementation/mediums/ble/instant_on_lost_advertisement_test.cc",
|
||||
"connections/implementation/mediums/ble/instant_on_lost_manager_test.cc",
|
||||
"connections/implementation/mediums/multiplex/multiplex_frames_test.cc",
|
||||
"connections/implementation/mediums/multiplex/multiplex_socket_test.cc",
|
||||
"connections/implementation/mediums/multiplex/multiplex_output_stream_test.cc",
|
||||
@@ -375,7 +375,7 @@ let package = Package(
|
||||
"internal/platform/byte_array_test.cc",
|
||||
"internal/platform/credential_storage_impl_test.cc",
|
||||
"internal/platform/implementation/g3/awdl_test.cc",
|
||||
"internal/platform/implementation/g3/ble_v2_test.cc",
|
||||
"internal/platform/implementation/g3/ble_test.cc",
|
||||
"internal/platform/input_stream_test.cc",
|
||||
"internal/platform/mac_address_test.cc",
|
||||
"internal/platform/single_thread_executor_test.cc",
|
||||
@@ -402,7 +402,6 @@ let package = Package(
|
||||
"internal/platform/multi_thread_executor_test.cc",
|
||||
"internal/platform/ble_connection_info_test.cc",
|
||||
"internal/platform/ble_test.cc",
|
||||
"internal/platform/ble_v2_test.cc",
|
||||
"internal/platform/prng_test.cc",
|
||||
"internal/platform/implementation/apple/count_down_latch_test.cc",
|
||||
"internal/platform/implementation/apple/condition_variable_test.cc",
|
||||
|
||||
@@ -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_);
|
||||
|
||||
|
||||
+10
-10
@@ -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 "
|
||||
+8
-8
@@ -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 {
|
||||
|
||||
@@ -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();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -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_;
|
||||
|
||||
@@ -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",
|
||||
|
||||
+99
-103
@@ -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));
|
||||
}
|
||||
|
||||
+31
-31
@@ -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_
|
||||
+3
-3
@@ -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",
|
||||
+1
-1
@@ -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>
|
||||
+3
-3
@@ -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_
|
||||
+1
-1
@@ -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
-12
@@ -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;
|
||||
}
|
||||
+22
-22
@@ -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_
|
||||
+1
-1
@@ -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
-12
@@ -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_
|
||||
+1
-1
@@ -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>
|
||||
|
||||
+2
-2
@@ -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 {
|
||||
+2
-2
@@ -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"
|
||||
+4
-4
@@ -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_
|
||||
+6
-6
@@ -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;
|
||||
+1
-1
@@ -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>
|
||||
+3
-3
@@ -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_
|
||||
+1
-1
@@ -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>
|
||||
+4
-4
@@ -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"
|
||||
+4
-4
@@ -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_
|
||||
+1
-1
@@ -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>
|
||||
+1
-1
@@ -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"
|
||||
+3
-3
@@ -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_
|
||||
+1
-1
@@ -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>
|
||||
|
||||
+10
-10
@@ -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_
|
||||
+25
-25
@@ -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;
|
||||
+28
-28
@@ -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_
|
||||
+116
-119
@@ -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);
|
||||
+2
-2
@@ -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 {
|
||||
+3
-3
@@ -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_
|
||||
+1
-1
@@ -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>
|
||||
+8
-8
@@ -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 =
|
||||
+5
-5
@@ -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_
|
||||
+1
-1
@@ -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>
|
||||
+170
-174
@@ -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_; }
|
||||
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -288,7 +288,7 @@ cc_library(
|
||||
name = "comm",
|
||||
srcs = [
|
||||
"awdl.cc",
|
||||
"ble_v2.cc",
|
||||
"ble.cc",
|
||||
"bluetooth_classic.cc",
|
||||
"credential_storage_impl.cc",
|
||||
"file.cc",
|
||||
@@ -298,7 +298,7 @@ cc_library(
|
||||
],
|
||||
hdrs = [
|
||||
"awdl.h",
|
||||
"ble_v2.h",
|
||||
"ble.h",
|
||||
"bluetooth_adapter.h",
|
||||
"bluetooth_classic.h",
|
||||
"credential_storage_impl.h",
|
||||
@@ -471,7 +471,7 @@ cc_test(
|
||||
timeout = "moderate",
|
||||
srcs = [
|
||||
"ble_connection_info_test.cc",
|
||||
"ble_v2_test.cc",
|
||||
"ble_test.cc",
|
||||
"blocking_queue_stream_test.cc",
|
||||
"bluetooth_adapter_test.cc",
|
||||
"bluetooth_classic_test.cc",
|
||||
|
||||
@@ -12,7 +12,7 @@
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
#include "internal/platform/ble_v2.h"
|
||||
#include "internal/platform/ble.h"
|
||||
|
||||
#include <memory>
|
||||
#include <optional>
|
||||
@@ -24,7 +24,7 @@
|
||||
#include "absl/status/status.h"
|
||||
#include "absl/strings/string_view.h"
|
||||
#include "internal/platform/cancellation_flag.h"
|
||||
#include "internal/platform/implementation/ble_v2.h"
|
||||
#include "internal/platform/implementation/ble.h"
|
||||
#include "internal/platform/logging.h"
|
||||
#include "internal/platform/mutex_lock.h"
|
||||
#include "internal/platform/uuid.h"
|
||||
@@ -32,35 +32,35 @@
|
||||
namespace nearby {
|
||||
|
||||
namespace {
|
||||
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;
|
||||
using ReadValueCallback =
|
||||
::nearby::api::ble_v2::ServerGattConnectionCallback::ReadValueCallback;
|
||||
::nearby::api::ble::ServerGattConnectionCallback::ReadValueCallback;
|
||||
using WriteValueCallback =
|
||||
::nearby::api::ble_v2::ServerGattConnectionCallback::WriteValueCallback;
|
||||
::nearby::api::ble::ServerGattConnectionCallback::WriteValueCallback;
|
||||
} // namespace
|
||||
|
||||
bool BleV2Medium::StartAdvertising(
|
||||
bool BleMedium::StartAdvertising(
|
||||
const BleAdvertisementData& advertising_data,
|
||||
api::ble_v2::AdvertiseParameters advertise_parameters) {
|
||||
api::ble::AdvertiseParameters advertise_parameters) {
|
||||
return impl_->StartAdvertising(advertising_data, advertise_parameters);
|
||||
}
|
||||
|
||||
bool BleV2Medium::StopAdvertising() { return impl_->StopAdvertising(); }
|
||||
bool BleMedium::StopAdvertising() { return impl_->StopAdvertising(); }
|
||||
|
||||
std::unique_ptr<api::ble_v2::BleMedium::AdvertisingSession>
|
||||
BleV2Medium::StartAdvertising(
|
||||
const api::ble_v2::BleAdvertisementData& advertising_data,
|
||||
api::ble_v2::AdvertiseParameters advertise_set_parameters,
|
||||
api::ble_v2::BleMedium::AdvertisingCallback callback) {
|
||||
std::unique_ptr<api::ble::BleMedium::AdvertisingSession>
|
||||
BleMedium::StartAdvertising(
|
||||
const api::ble::BleAdvertisementData& advertising_data,
|
||||
api::ble::AdvertiseParameters advertise_set_parameters,
|
||||
api::ble::BleMedium::AdvertisingCallback callback) {
|
||||
return impl_->StartAdvertising(advertising_data, advertise_set_parameters,
|
||||
std::move(callback));
|
||||
}
|
||||
|
||||
bool BleV2Medium::StartScanning(const Uuid& service_uuid,
|
||||
TxPowerLevel tx_power_level,
|
||||
ScanCallback callback) {
|
||||
bool BleMedium::StartScanning(const Uuid& service_uuid,
|
||||
TxPowerLevel tx_power_level,
|
||||
ScanCallback callback) {
|
||||
MutexLock lock(&mutex_);
|
||||
if (scanning_enabled_) {
|
||||
LOG(INFO) << "Ble Scanning already enabled";
|
||||
@@ -68,12 +68,12 @@ bool BleV2Medium::StartScanning(const Uuid& service_uuid,
|
||||
}
|
||||
bool success = impl_->StartScanning(
|
||||
service_uuid, tx_power_level,
|
||||
api::ble_v2::BleMedium::ScanCallback{
|
||||
api::ble::BleMedium::ScanCallback{
|
||||
.advertisement_found_cb =
|
||||
[this](api::ble_v2::BlePeripheral::UniqueId peripheral_id,
|
||||
[this](api::ble::BlePeripheral::UniqueId peripheral_id,
|
||||
BleAdvertisementData advertisement_data) {
|
||||
MutexLock lock(&mutex_);
|
||||
BleV2Peripheral proxy(*this, peripheral_id);
|
||||
BlePeripheral proxy(*this, peripheral_id);
|
||||
if (!scanning_enabled_) return;
|
||||
scan_callback_.advertisement_found_cb(std::move(proxy),
|
||||
advertisement_data);
|
||||
@@ -87,9 +87,9 @@ bool BleV2Medium::StartScanning(const Uuid& service_uuid,
|
||||
return success;
|
||||
}
|
||||
|
||||
bool BleV2Medium::StartMultipleServicesScanning(
|
||||
bool BleMedium::StartMultipleServicesScanning(
|
||||
const std::vector<Uuid>& service_uuids,
|
||||
api::ble_v2::TxPowerLevel tx_power_level, ScanCallback callback) {
|
||||
api::ble::TxPowerLevel tx_power_level, ScanCallback callback) {
|
||||
MutexLock lock(&mutex_);
|
||||
if (scanning_enabled_) {
|
||||
LOG(INFO) << "Ble Scanning already enabled";
|
||||
@@ -97,12 +97,12 @@ bool BleV2Medium::StartMultipleServicesScanning(
|
||||
}
|
||||
bool success = impl_->StartMultipleServicesScanning(
|
||||
service_uuids, tx_power_level,
|
||||
api::ble_v2::BleMedium::ScanCallback{
|
||||
api::ble::BleMedium::ScanCallback{
|
||||
.advertisement_found_cb =
|
||||
[this](api::ble_v2::BlePeripheral::UniqueId peripheral_id,
|
||||
[this](api::ble::BlePeripheral::UniqueId peripheral_id,
|
||||
BleAdvertisementData advertisement_data) {
|
||||
MutexLock lock(&mutex_);
|
||||
BleV2Peripheral proxy(*this, peripheral_id);
|
||||
BlePeripheral proxy(*this, peripheral_id);
|
||||
if (!scanning_enabled_) return;
|
||||
scan_callback_.advertisement_found_cb(std::move(proxy),
|
||||
advertisement_data);
|
||||
@@ -116,9 +116,9 @@ bool BleV2Medium::StartMultipleServicesScanning(
|
||||
return success;
|
||||
}
|
||||
|
||||
BleV2Medium::~BleV2Medium() { StopScanning(); }
|
||||
BleMedium::~BleMedium() { StopScanning(); }
|
||||
|
||||
bool BleV2Medium::StopScanning() {
|
||||
bool BleMedium::StopScanning() {
|
||||
MutexLock lock(&mutex_);
|
||||
if (!scanning_enabled_) {
|
||||
return true;
|
||||
@@ -128,28 +128,27 @@ bool BleV2Medium::StopScanning() {
|
||||
LOG(INFO) << "Ble Scanning disabled";
|
||||
return impl_->StopScanning();
|
||||
}
|
||||
bool BleV2Medium::PauseMediumScanning() {
|
||||
bool BleMedium::PauseMediumScanning() {
|
||||
MutexLock lock(&mutex_);
|
||||
if (!scanning_enabled_) {
|
||||
return true;
|
||||
}
|
||||
LOG(INFO) << "Pause Medium level BLE_V2 Scanning";
|
||||
LOG(INFO) << "Pause Medium level BLE Scanning";
|
||||
return impl_->PauseMediumScanning();
|
||||
}
|
||||
|
||||
bool BleV2Medium::ResumeMediumScanning() {
|
||||
bool BleMedium::ResumeMediumScanning() {
|
||||
MutexLock lock(&mutex_);
|
||||
return impl_->ResumeMediumScanning();
|
||||
}
|
||||
|
||||
std::unique_ptr<api::ble_v2::BleMedium::ScanningSession>
|
||||
BleV2Medium::StartScanning(const Uuid& service_uuid,
|
||||
api::ble_v2::TxPowerLevel tx_power_level,
|
||||
api::ble_v2::BleMedium::ScanningCallback callback) {
|
||||
std::unique_ptr<api::ble::BleMedium::ScanningSession> BleMedium::StartScanning(
|
||||
const Uuid& service_uuid, api::ble::TxPowerLevel tx_power_level,
|
||||
api::ble::BleMedium::ScanningCallback callback) {
|
||||
LOG(INFO) << "platform mutex: " << &mutex_;
|
||||
return impl_->StartScanning(
|
||||
service_uuid, tx_power_level,
|
||||
api::ble_v2::BleMedium::ScanningCallback{
|
||||
api::ble::BleMedium::ScanningCallback{
|
||||
.start_scanning_result =
|
||||
[this, start_scanning_result =
|
||||
std::move(callback.start_scanning_result)](
|
||||
@@ -167,14 +166,14 @@ BleV2Medium::StartScanning(const Uuid& service_uuid,
|
||||
});
|
||||
}
|
||||
|
||||
std::unique_ptr<GattServer> BleV2Medium::StartGattServer(
|
||||
std::unique_ptr<GattServer> BleMedium::StartGattServer(
|
||||
ServerGattConnectionCallback callback) {
|
||||
{
|
||||
MutexLock lock(&mutex_);
|
||||
server_gatt_connection_callback_ = std::move(callback);
|
||||
}
|
||||
|
||||
std::unique_ptr<api::ble_v2::GattServer> api_gatt_server =
|
||||
std::unique_ptr<api::ble::GattServer> api_gatt_server =
|
||||
impl_->StartGattServer({
|
||||
.characteristic_subscription_cb =
|
||||
[this](const GattCharacteristic& characteristic) {
|
||||
@@ -189,10 +188,9 @@ std::unique_ptr<GattServer> BleV2Medium::StartGattServer(
|
||||
.characteristic_unsubscription_cb(characteristic);
|
||||
},
|
||||
.on_characteristic_read_cb =
|
||||
[this](
|
||||
const api::ble_v2::BlePeripheral::UniqueId remote_device_id,
|
||||
const GattCharacteristic& characteristic, int offset,
|
||||
ReadValueCallback callback) {
|
||||
[this](const api::ble::BlePeripheral::UniqueId remote_device_id,
|
||||
const GattCharacteristic& characteristic, int offset,
|
||||
ReadValueCallback callback) {
|
||||
MutexLock lock(&mutex_);
|
||||
if (server_gatt_connection_callback_
|
||||
.on_characteristic_read_cb) {
|
||||
@@ -205,10 +203,9 @@ std::unique_ptr<GattServer> BleV2Medium::StartGattServer(
|
||||
}
|
||||
},
|
||||
.on_characteristic_write_cb =
|
||||
[this](
|
||||
const api::ble_v2::BlePeripheral::UniqueId remote_device_id,
|
||||
const GattCharacteristic& characteristic, int offset,
|
||||
absl::string_view data, WriteValueCallback callback) {
|
||||
[this](const api::ble::BlePeripheral::UniqueId remote_device_id,
|
||||
const GattCharacteristic& characteristic, int offset,
|
||||
absl::string_view data, WriteValueCallback callback) {
|
||||
MutexLock lock(&mutex_);
|
||||
if (server_gatt_connection_callback_
|
||||
.on_characteristic_write_cb) {
|
||||
@@ -224,10 +221,10 @@ std::unique_ptr<GattServer> BleV2Medium::StartGattServer(
|
||||
return std::make_unique<GattServer>(std::move(api_gatt_server));
|
||||
}
|
||||
|
||||
std::unique_ptr<GattClient> BleV2Medium::ConnectToGattServer(
|
||||
BleV2Peripheral peripheral, TxPowerLevel tx_power_level,
|
||||
std::unique_ptr<GattClient> BleMedium::ConnectToGattServer(
|
||||
BlePeripheral peripheral, TxPowerLevel tx_power_level,
|
||||
ClientGattConnectionCallback callback) {
|
||||
std::optional<api::ble_v2::BlePeripheral::UniqueId> id =
|
||||
std::optional<api::ble::BlePeripheral::UniqueId> id =
|
||||
peripheral.GetUniqueId();
|
||||
if (!id.has_value()) {
|
||||
LOG(ERROR) << "Failed to connect to GattServer, invalid peripheral";
|
||||
@@ -243,33 +240,33 @@ std::unique_ptr<GattClient> BleV2Medium::ConnectToGattServer(
|
||||
}));
|
||||
}
|
||||
|
||||
BleV2ServerSocket BleV2Medium::OpenServerSocket(const std::string& service_id) {
|
||||
return BleV2ServerSocket(*this, impl_->OpenServerSocket(service_id));
|
||||
BleServerSocket BleMedium::OpenServerSocket(const std::string& service_id) {
|
||||
return BleServerSocket(*this, impl_->OpenServerSocket(service_id));
|
||||
}
|
||||
|
||||
BleL2capServerSocket BleV2Medium::OpenL2capServerSocket(
|
||||
BleL2capServerSocket BleMedium::OpenL2capServerSocket(
|
||||
const std::string& service_id) {
|
||||
return BleL2capServerSocket(*this, impl_->OpenL2capServerSocket(service_id));
|
||||
}
|
||||
|
||||
BleV2Socket BleV2Medium::Connect(const std::string& service_id,
|
||||
TxPowerLevel tx_power_level,
|
||||
const BleV2Peripheral& peripheral,
|
||||
CancellationFlag* cancellation_flag) {
|
||||
std::optional<api::ble_v2::BlePeripheral::UniqueId> id =
|
||||
BleSocket BleMedium::Connect(const std::string& service_id,
|
||||
TxPowerLevel tx_power_level,
|
||||
const BlePeripheral& peripheral,
|
||||
CancellationFlag* cancellation_flag) {
|
||||
std::optional<api::ble::BlePeripheral::UniqueId> id =
|
||||
peripheral.GetUniqueId();
|
||||
if (!id.has_value()) {
|
||||
LOG(ERROR) << "Failed to connect, invalid peripheral";
|
||||
return {};
|
||||
}
|
||||
return BleV2Socket(peripheral, impl_->Connect(service_id, tx_power_level, *id,
|
||||
cancellation_flag));
|
||||
return BleSocket(peripheral, impl_->Connect(service_id, tx_power_level, *id,
|
||||
cancellation_flag));
|
||||
}
|
||||
|
||||
BleL2capSocket BleV2Medium::ConnectOverL2cap(
|
||||
BleL2capSocket BleMedium::ConnectOverL2cap(
|
||||
const std::string& service_id, TxPowerLevel tx_power_level,
|
||||
const BleV2Peripheral& peripheral, CancellationFlag* cancellation_flag) {
|
||||
std::optional<api::ble_v2::BlePeripheral::UniqueId> id =
|
||||
const BlePeripheral& peripheral, CancellationFlag* cancellation_flag) {
|
||||
std::optional<api::ble::BlePeripheral::UniqueId> id =
|
||||
peripheral.GetUniqueId();
|
||||
if (!id.has_value()) {
|
||||
LOG(ERROR) << "Failed to connect over L2cap, invalid peripheral";
|
||||
@@ -281,10 +278,10 @@ BleL2capSocket BleV2Medium::ConnectOverL2cap(
|
||||
*id, cancellation_flag));
|
||||
}
|
||||
|
||||
bool BleV2Medium::IsExtendedAdvertisementsAvailable() {
|
||||
bool BleMedium::IsExtendedAdvertisementsAvailable() {
|
||||
return IsValid() && impl_->IsExtendedAdvertisementsAvailable();
|
||||
}
|
||||
|
||||
bool BleV2Peripheral::IsValid() const { return unique_id_.has_value(); }
|
||||
bool BlePeripheral::IsValid() const { return unique_id_.has_value(); }
|
||||
|
||||
} // namespace nearby
|
||||
@@ -12,8 +12,8 @@
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
#ifndef PLATFORM_PUBLIC_BLE_V2_H_
|
||||
#define PLATFORM_PUBLIC_BLE_V2_H_
|
||||
#ifndef PLATFORM_PUBLIC_BLE_H_
|
||||
#define PLATFORM_PUBLIC_BLE_H_
|
||||
|
||||
#include <cstdint>
|
||||
#include <memory>
|
||||
@@ -32,7 +32,7 @@
|
||||
#include "internal/platform/byte_array.h"
|
||||
#include "internal/platform/cancellation_flag.h"
|
||||
#include "internal/platform/exception.h"
|
||||
#include "internal/platform/implementation/ble_v2.h"
|
||||
#include "internal/platform/implementation/ble.h"
|
||||
#include "internal/platform/implementation/platform.h"
|
||||
#include "internal/platform/input_stream.h"
|
||||
#include "internal/platform/listeners.h"
|
||||
@@ -43,22 +43,21 @@
|
||||
|
||||
namespace nearby {
|
||||
|
||||
class BleV2Medium;
|
||||
class BleMedium;
|
||||
|
||||
// TODO: b/399815436 - Remove all the shared_ptr in this file.
|
||||
// Opaque wrapper over a BLE peripheral. Must contain enough data about a
|
||||
// particular BLE peripheral to connect to its GATT server.
|
||||
class BleV2Peripheral final {
|
||||
class BlePeripheral final {
|
||||
public:
|
||||
BleV2Peripheral() = default;
|
||||
BleV2Peripheral(BleV2Medium& medium,
|
||||
api::ble_v2::BlePeripheral::UniqueId unique_id)
|
||||
BlePeripheral() = default;
|
||||
BlePeripheral(BleMedium& medium, api::ble::BlePeripheral::UniqueId unique_id)
|
||||
: medium_(&medium), unique_id_(unique_id) {}
|
||||
BleV2Peripheral(const BleV2Peripheral&) = default;
|
||||
BleV2Peripheral& operator=(const BleV2Peripheral&) = default;
|
||||
BleV2Peripheral(BleV2Peripheral&& other) = default;
|
||||
BlePeripheral(const BlePeripheral&) = default;
|
||||
BlePeripheral& operator=(const BlePeripheral&) = default;
|
||||
BlePeripheral(BlePeripheral&& other) = default;
|
||||
|
||||
BleV2Peripheral& operator=(BleV2Peripheral&& other) = default;
|
||||
BlePeripheral& operator=(BlePeripheral&& other) = default;
|
||||
|
||||
ByteArray GetId() const { return id_; }
|
||||
void SetId(const ByteArray& id) { id_ = id; }
|
||||
@@ -68,23 +67,23 @@ class BleV2Peripheral final {
|
||||
|
||||
bool IsValid() const;
|
||||
|
||||
std::optional<api::ble_v2::BlePeripheral::UniqueId> GetUniqueId() const {
|
||||
std::optional<api::ble::BlePeripheral::UniqueId> GetUniqueId() const {
|
||||
return unique_id_;
|
||||
}
|
||||
|
||||
api::ble_v2::BlePeripheral* GetImpl() const;
|
||||
api::ble::BlePeripheral* GetImpl() const;
|
||||
std::string ToReadableString() const {
|
||||
if (!IsValid()) {
|
||||
return "BleV2Peripheral { invalid }";
|
||||
return "BlePeripheral { invalid }";
|
||||
}
|
||||
return absl::StrFormat("BleV2Peripheral { id=%s, psm=%d}",
|
||||
return absl::StrFormat("BlePeripheral { id=%s, psm=%d}",
|
||||
absl::BytesToHexString(GetId().AsStringView()),
|
||||
GetPsm());
|
||||
}
|
||||
|
||||
private:
|
||||
BleV2Medium* medium_ = nullptr;
|
||||
std::optional<api::ble_v2::BlePeripheral::UniqueId> unique_id_;
|
||||
BleMedium* medium_ = nullptr;
|
||||
std::optional<api::ble::BlePeripheral::UniqueId> unique_id_;
|
||||
|
||||
// A unique identifier for this peripheral. It is the BLE advertisement bytes
|
||||
// it was found on.
|
||||
@@ -99,16 +98,16 @@ class BleV2Peripheral final {
|
||||
// Container of operations that can be performed over the BLE GATT client
|
||||
// socket.
|
||||
// This class is copyable but not moveable.
|
||||
class BleV2Socket final {
|
||||
class BleSocket final {
|
||||
public:
|
||||
BleV2Socket() = default;
|
||||
BleV2Socket(BleV2Peripheral peripheral,
|
||||
std::unique_ptr<api::ble_v2::BleSocket> socket)
|
||||
BleSocket() = default;
|
||||
BleSocket(BlePeripheral peripheral,
|
||||
std::unique_ptr<api::ble::BleSocket> socket)
|
||||
: peripheral_(peripheral) {
|
||||
state_->socket = std::move(socket);
|
||||
}
|
||||
BleV2Socket(const BleV2Socket&) = default;
|
||||
BleV2Socket& operator=(const BleV2Socket&) = default;
|
||||
BleSocket(const BleSocket&) = default;
|
||||
BleSocket& operator=(const BleSocket&) = default;
|
||||
|
||||
// Returns the InputStream of the BleSocket.
|
||||
// On error, returned stream will report Exception::kIo on any operation.
|
||||
@@ -139,7 +138,7 @@ class BleV2Socket final {
|
||||
}
|
||||
|
||||
// Returns BlePeripheral object which wraps a valid BlePeripheral pointer.
|
||||
BleV2Peripheral& GetRemotePeripheral() { return peripheral_; }
|
||||
BlePeripheral& GetRemotePeripheral() { return peripheral_; }
|
||||
|
||||
// Returns true if a socket is usable. If this method returns false,
|
||||
// it is not safe to call any other method.
|
||||
@@ -157,27 +156,27 @@ class BleV2Socket final {
|
||||
// Returned reference will remain valid for while BleSocket object is
|
||||
// itself valid. Typically BleSocket lifetime matches duration of the
|
||||
// connection, and is controlled by end user, since they hold the instance.
|
||||
api::ble_v2::BleSocket& GetImpl() { return *state_->socket; }
|
||||
api::ble::BleSocket& GetImpl() { return *state_->socket; }
|
||||
|
||||
private:
|
||||
struct SharedState {
|
||||
std::unique_ptr<api::ble_v2::BleSocket> socket;
|
||||
std::unique_ptr<api::ble::BleSocket> socket;
|
||||
absl::AnyInvocable<void()> close_notifier;
|
||||
};
|
||||
std::shared_ptr<SharedState> state_ = std::make_shared<SharedState>();
|
||||
BleV2Peripheral peripheral_;
|
||||
BlePeripheral peripheral_;
|
||||
};
|
||||
|
||||
// Container of operations that can be performed over the BLE GATT server
|
||||
// socket.
|
||||
// This class is copyable but not moveable.
|
||||
class BleV2ServerSocket final {
|
||||
class BleServerSocket final {
|
||||
public:
|
||||
BleV2ServerSocket(BleV2Medium& medium,
|
||||
std::unique_ptr<api::ble_v2::BleServerSocket> socket)
|
||||
BleServerSocket(BleMedium& medium,
|
||||
std::unique_ptr<api::ble::BleServerSocket> socket)
|
||||
: medium_(&medium), impl_(std::move(socket)) {}
|
||||
BleV2ServerSocket(const BleV2ServerSocket&) = default;
|
||||
BleV2ServerSocket& operator=(const BleV2ServerSocket&) = default;
|
||||
BleServerSocket(const BleServerSocket&) = default;
|
||||
BleServerSocket& operator=(const BleServerSocket&) = default;
|
||||
|
||||
// Blocks until either:
|
||||
// - at least one incoming connection request is available, or
|
||||
@@ -187,15 +186,15 @@ class BleV2ServerSocket final {
|
||||
// member function "IsValid()"
|
||||
// Once error is reported, it is permanent, and
|
||||
// ServerSocket has to be closed by caller.
|
||||
BleV2Socket Accept() {
|
||||
std::unique_ptr<api::ble_v2::BleSocket> socket = impl_->Accept();
|
||||
BleV2Peripheral peripheral;
|
||||
BleSocket Accept() {
|
||||
std::unique_ptr<api::ble::BleSocket> socket = impl_->Accept();
|
||||
BlePeripheral peripheral;
|
||||
if (socket == nullptr) {
|
||||
LOG(INFO) << "BleServerSocket Accept() failed on server socket: " << this;
|
||||
} else {
|
||||
peripheral = BleV2Peripheral(*medium_, socket->GetRemotePeripheralId());
|
||||
peripheral = BlePeripheral(*medium_, socket->GetRemotePeripheralId());
|
||||
}
|
||||
return BleV2Socket(peripheral, std::move(socket));
|
||||
return BleSocket(peripheral, std::move(socket));
|
||||
}
|
||||
|
||||
// Returns Exception::kIo on error, Exception::kSuccess otherwise.
|
||||
@@ -205,11 +204,11 @@ class BleV2ServerSocket final {
|
||||
}
|
||||
|
||||
bool IsValid() const { return impl_ != nullptr; }
|
||||
api::ble_v2::BleServerSocket& GetImpl() { return *impl_; }
|
||||
api::ble::BleServerSocket& GetImpl() { return *impl_; }
|
||||
|
||||
private:
|
||||
BleV2Medium* medium_;
|
||||
std::shared_ptr<api::ble_v2::BleServerSocket> impl_;
|
||||
BleMedium* medium_;
|
||||
std::shared_ptr<api::ble::BleServerSocket> impl_;
|
||||
};
|
||||
|
||||
// Opaque wrapper over a GattServer.
|
||||
@@ -219,27 +218,26 @@ class BleV2ServerSocket final {
|
||||
// of std::optional, because iOS platform is still in C++14.
|
||||
class GattServer final {
|
||||
public:
|
||||
explicit GattServer(std::unique_ptr<api::ble_v2::GattServer> gatt_server)
|
||||
explicit GattServer(std::unique_ptr<api::ble::GattServer> gatt_server)
|
||||
: impl_(std::move(gatt_server)) {}
|
||||
~GattServer() { Stop(); }
|
||||
|
||||
// NOLINTNEXTLINE(google3-legacy-absl-backports)
|
||||
absl::optional<api::ble_v2::GattCharacteristic> CreateCharacteristic(
|
||||
absl::optional<api::ble::GattCharacteristic> CreateCharacteristic(
|
||||
const Uuid& service_uuid, const Uuid& characteristic_uuid,
|
||||
const api::ble_v2::GattCharacteristic::Permission permission,
|
||||
const api::ble_v2::GattCharacteristic::Property property) {
|
||||
const api::ble::GattCharacteristic::Permission permission,
|
||||
const api::ble::GattCharacteristic::Property property) {
|
||||
return impl_->CreateCharacteristic(service_uuid, characteristic_uuid,
|
||||
permission, property);
|
||||
}
|
||||
|
||||
bool UpdateCharacteristic(
|
||||
const api::ble_v2::GattCharacteristic& characteristic,
|
||||
const ByteArray& value) {
|
||||
bool UpdateCharacteristic(const api::ble::GattCharacteristic& characteristic,
|
||||
const ByteArray& value) {
|
||||
return impl_->UpdateCharacteristic(characteristic, value);
|
||||
}
|
||||
|
||||
absl::Status NotifyCharacteristicChanged(
|
||||
const api::ble_v2::GattCharacteristic& characteristic, bool confirm,
|
||||
const api::ble::GattCharacteristic& characteristic, bool confirm,
|
||||
const ByteArray& new_value) {
|
||||
return impl_->NotifyCharacteristicChanged(characteristic, confirm,
|
||||
new_value);
|
||||
@@ -256,10 +254,10 @@ class GattServer final {
|
||||
// Returns reference to platform implementation.
|
||||
// This is used to communicate with platform code, and for debugging
|
||||
// purposes.
|
||||
api::ble_v2::GattServer* GetImpl() { return impl_.get(); }
|
||||
api::ble::GattServer* GetImpl() { return impl_.get(); }
|
||||
|
||||
private:
|
||||
std::unique_ptr<api::ble_v2::GattServer> impl_;
|
||||
std::unique_ptr<api::ble::GattServer> impl_;
|
||||
};
|
||||
|
||||
// Opaque wrapper for a GattClient.
|
||||
@@ -269,7 +267,7 @@ class GattServer final {
|
||||
class GattClient final {
|
||||
public:
|
||||
explicit GattClient(
|
||||
std::unique_ptr<api::ble_v2::GattClient> client_gatt_connection)
|
||||
std::unique_ptr<api::ble::GattClient> client_gatt_connection)
|
||||
: impl_(std::move(client_gatt_connection)) {}
|
||||
|
||||
bool DiscoverServiceAndCharacteristics(
|
||||
@@ -279,21 +277,21 @@ class GattClient final {
|
||||
}
|
||||
|
||||
// NOLINTNEXTLINE(google3-legacy-absl-backports)
|
||||
absl::optional<api::ble_v2::GattCharacteristic> GetCharacteristic(
|
||||
absl::optional<api::ble::GattCharacteristic> GetCharacteristic(
|
||||
const Uuid& service_uuid, const Uuid& characteristic_uuid) {
|
||||
return impl_->GetCharacteristic(service_uuid, characteristic_uuid);
|
||||
}
|
||||
|
||||
// NOLINTNEXTLINE(google3-legacy-absl-backports)
|
||||
absl::optional<std::string> ReadCharacteristic(
|
||||
const api::ble_v2::GattCharacteristic& characteristic) {
|
||||
const api::ble::GattCharacteristic& characteristic) {
|
||||
return impl_->ReadCharacteristic(characteristic);
|
||||
}
|
||||
|
||||
// NOLINTNEXTLINE(google3-legacy-absl-backports)
|
||||
bool WriteCharacteristic(
|
||||
const api::ble_v2::GattCharacteristic& characteristic,
|
||||
absl::string_view value, api::ble_v2::GattClient::WriteType write_type) {
|
||||
bool WriteCharacteristic(const api::ble::GattCharacteristic& characteristic,
|
||||
absl::string_view value,
|
||||
api::ble::GattClient::WriteType write_type) {
|
||||
return impl_->WriteCharacteristic(characteristic, value, write_type);
|
||||
}
|
||||
|
||||
@@ -301,7 +299,7 @@ class GattClient final {
|
||||
// unsubscribing.
|
||||
// NOLINTNEXTLINE(google3-legacy-absl-backports)
|
||||
bool SetCharacteristicSubscription(
|
||||
const api::ble_v2::GattCharacteristic& characteristic, bool enable,
|
||||
const api::ble::GattCharacteristic& characteristic, bool enable,
|
||||
absl::AnyInvocable<void(absl::string_view value)>
|
||||
on_characteristic_changed_cb) {
|
||||
return impl_->SetCharacteristicSubscription(
|
||||
@@ -317,17 +315,17 @@ class GattClient final {
|
||||
// Returns reference to platform implementation.
|
||||
// This is used to communicate with platform code, and for debugging
|
||||
// purposes.
|
||||
api::ble_v2::GattClient* GetImpl() { return impl_.get(); }
|
||||
api::ble::GattClient* GetImpl() { return impl_.get(); }
|
||||
|
||||
private:
|
||||
std::unique_ptr<api::ble_v2::GattClient> impl_;
|
||||
std::unique_ptr<api::ble::GattClient> impl_;
|
||||
};
|
||||
|
||||
class BleL2capSocket final {
|
||||
public:
|
||||
BleL2capSocket() = default;
|
||||
BleL2capSocket(BleV2Peripheral peripheral,
|
||||
std::unique_ptr<api::ble_v2::BleL2capSocket> socket)
|
||||
BleL2capSocket(BlePeripheral peripheral,
|
||||
std::unique_ptr<api::ble::BleL2capSocket> socket)
|
||||
: peripheral_(peripheral) {
|
||||
state_->socket = std::move(socket);
|
||||
}
|
||||
@@ -363,7 +361,7 @@ class BleL2capSocket final {
|
||||
}
|
||||
|
||||
// Returns BlePeripheral object which wraps a valid BlePeripheral pointer.
|
||||
BleV2Peripheral& GetRemotePeripheral() { return peripheral_; }
|
||||
BlePeripheral& GetRemotePeripheral() { return peripheral_; }
|
||||
|
||||
// Returns true if a socket is usable. If this method returns false,
|
||||
// it is not safe to call any other method.
|
||||
@@ -381,22 +379,21 @@ class BleL2capSocket final {
|
||||
// Returned reference will remain valid for while BleSocket object is
|
||||
// itself valid. Typically BleSocket lifetime matches duration of the
|
||||
// connection, and is controlled by end user, since they hold the instance.
|
||||
api::ble_v2::BleL2capSocket& GetImpl() { return *state_->socket; }
|
||||
api::ble::BleL2capSocket& GetImpl() { return *state_->socket; }
|
||||
|
||||
private:
|
||||
struct SharedState {
|
||||
std::unique_ptr<api::ble_v2::BleL2capSocket> socket;
|
||||
std::unique_ptr<api::ble::BleL2capSocket> socket;
|
||||
absl::AnyInvocable<void()> close_notifier;
|
||||
};
|
||||
std::shared_ptr<SharedState> state_ = std::make_shared<SharedState>();
|
||||
BleV2Peripheral peripheral_;
|
||||
BlePeripheral peripheral_;
|
||||
};
|
||||
|
||||
class BleL2capServerSocket final {
|
||||
public:
|
||||
BleL2capServerSocket(
|
||||
BleV2Medium& medium,
|
||||
std::unique_ptr<api::ble_v2::BleL2capServerSocket> socket)
|
||||
BleL2capServerSocket(BleMedium& medium,
|
||||
std::unique_ptr<api::ble::BleL2capServerSocket> socket)
|
||||
: medium_(&medium), impl_(std::move(socket)) {}
|
||||
BleL2capServerSocket(const BleL2capServerSocket&) = default;
|
||||
BleL2capServerSocket& operator=(const BleL2capServerSocket&) = default;
|
||||
@@ -412,14 +409,13 @@ class BleL2capServerSocket final {
|
||||
// Once error is reported, it is permanent, and
|
||||
// ServerSocket has to be closed by caller.
|
||||
BleL2capSocket Accept() {
|
||||
std::unique_ptr<api::ble_v2::BleL2capSocket> socket = impl_->Accept();
|
||||
BleV2Peripheral peripheral;
|
||||
std::unique_ptr<api::ble::BleL2capSocket> socket = impl_->Accept();
|
||||
BlePeripheral peripheral;
|
||||
if (socket == nullptr) {
|
||||
LOG(INFO) << "BleL2capServerSocket Accept() failed on server socket: "
|
||||
<< this;
|
||||
} else {
|
||||
peripheral =
|
||||
BleV2Peripheral(*medium_, socket->GetRemotePeripheralId());
|
||||
peripheral = BlePeripheral(*medium_, socket->GetRemotePeripheralId());
|
||||
}
|
||||
return BleL2capSocket(peripheral, std::move(socket));
|
||||
}
|
||||
@@ -433,15 +429,15 @@ class BleL2capServerSocket final {
|
||||
// Returns true if a BleL2capServerSocket is usable. If this method returns
|
||||
// false, it is not safe to call any other method.
|
||||
bool IsValid() const { return impl_ != nullptr; }
|
||||
api::ble_v2::BleL2capServerSocket& GetImpl() { return *impl_; }
|
||||
api::ble::BleL2capServerSocket& GetImpl() { return *impl_; }
|
||||
|
||||
private:
|
||||
BleV2Medium* medium_ = nullptr;
|
||||
std::shared_ptr<api::ble_v2::BleL2capServerSocket> impl_;
|
||||
BleMedium* medium_ = nullptr;
|
||||
std::shared_ptr<api::ble::BleL2capServerSocket> impl_;
|
||||
};
|
||||
|
||||
// Container of operations that can be performed over the BLE medium.
|
||||
class BleV2Medium final {
|
||||
class BleMedium final {
|
||||
public:
|
||||
// A wrapper callback for BLE scan results.
|
||||
//
|
||||
@@ -453,32 +449,30 @@ class BleV2Medium final {
|
||||
// instance.
|
||||
struct ScanCallback {
|
||||
absl::AnyInvocable<void(
|
||||
BleV2Peripheral peripheral,
|
||||
const api::ble_v2::BleAdvertisementData& advertisement_data)>
|
||||
BlePeripheral peripheral,
|
||||
const api::ble::BleAdvertisementData& advertisement_data)>
|
||||
advertisement_found_cb =
|
||||
nearby::DefaultCallback<BleV2Peripheral,
|
||||
const api::ble_v2::BleAdvertisementData&>();
|
||||
nearby::DefaultCallback<BlePeripheral,
|
||||
const api::ble::BleAdvertisementData&>();
|
||||
};
|
||||
|
||||
struct ServerGattConnectionCallback {
|
||||
absl::AnyInvocable<void(
|
||||
const api::ble_v2::GattCharacteristic& characteristic)>
|
||||
absl::AnyInvocable<void(const api::ble::GattCharacteristic& characteristic)>
|
||||
characteristic_subscription_cb =
|
||||
nearby::DefaultCallback<const api::ble_v2::GattCharacteristic&>();
|
||||
absl::AnyInvocable<void(
|
||||
const api::ble_v2::GattCharacteristic& characteristic)>
|
||||
nearby::DefaultCallback<const api::ble::GattCharacteristic&>();
|
||||
absl::AnyInvocable<void(const api::ble::GattCharacteristic& characteristic)>
|
||||
characteristic_unsubscription_cb =
|
||||
nearby::DefaultCallback<const api::ble_v2::GattCharacteristic&>();
|
||||
nearby::DefaultCallback<const api::ble::GattCharacteristic&>();
|
||||
absl::AnyInvocable<void(
|
||||
const api::ble_v2::BlePeripheral::UniqueId remote_device_id,
|
||||
const api::ble_v2::GattCharacteristic& characteristic, int offset,
|
||||
api::ble_v2::ServerGattConnectionCallback::ReadValueCallback callback)>
|
||||
const api::ble::BlePeripheral::UniqueId remote_device_id,
|
||||
const api::ble::GattCharacteristic& characteristic, int offset,
|
||||
api::ble::ServerGattConnectionCallback::ReadValueCallback callback)>
|
||||
on_characteristic_read_cb;
|
||||
absl::AnyInvocable<void(
|
||||
const api::ble_v2::BlePeripheral::UniqueId remote_device_id,
|
||||
const api::ble_v2::GattCharacteristic& characteristic, int offset,
|
||||
const api::ble::BlePeripheral::UniqueId remote_device_id,
|
||||
const api::ble::GattCharacteristic& characteristic, int offset,
|
||||
absl::string_view data,
|
||||
api::ble_v2::ServerGattConnectionCallback::WriteValueCallback callback)>
|
||||
api::ble::ServerGattConnectionCallback::WriteValueCallback callback)>
|
||||
on_characteristic_write_cb;
|
||||
};
|
||||
// TODO(b/231318879): Remove this wrapper callback and use impl callback if
|
||||
@@ -487,38 +481,37 @@ class BleV2Medium final {
|
||||
absl::AnyInvocable<void()> disconnected_cb = nearby::DefaultCallback<>();
|
||||
};
|
||||
|
||||
explicit BleV2Medium(BluetoothAdapter& adapter)
|
||||
: impl_(
|
||||
api::ImplementationPlatform::CreateBleV2Medium(adapter.GetImpl())),
|
||||
explicit BleMedium(BluetoothAdapter& adapter)
|
||||
: impl_(api::ImplementationPlatform::CreateBleMedium(adapter.GetImpl())),
|
||||
adapter_(adapter) {}
|
||||
|
||||
~BleV2Medium();
|
||||
~BleMedium();
|
||||
// Returns true once the BLE advertising has been initiated.
|
||||
// This interface will be deprecated soon.
|
||||
// TODO(b/271305977) remove this function.
|
||||
// Use 'unique_ptr<AdvertisingSession> StartAdvertising' instead.
|
||||
bool StartAdvertising(
|
||||
const api::ble_v2::BleAdvertisementData& advertising_data,
|
||||
api::ble_v2::AdvertiseParameters advertise_parameters);
|
||||
bool StartAdvertising(const api::ble::BleAdvertisementData& advertising_data,
|
||||
api::ble::AdvertiseParameters advertise_parameters);
|
||||
// This interface will be deprecated soon.
|
||||
// TODO(b/271305977) remove this function.
|
||||
bool StopAdvertising();
|
||||
|
||||
std::unique_ptr<api::ble_v2::BleMedium::AdvertisingSession> StartAdvertising(
|
||||
const api::ble_v2::BleAdvertisementData& advertising_data,
|
||||
api::ble_v2::AdvertiseParameters advertise_set_parameters,
|
||||
api::ble_v2::BleMedium::AdvertisingCallback callback);
|
||||
std::unique_ptr<api::ble::BleMedium::AdvertisingSession> StartAdvertising(
|
||||
const api::ble::BleAdvertisementData& advertising_data,
|
||||
api::ble::AdvertiseParameters advertise_set_parameters,
|
||||
api::ble::BleMedium::AdvertisingCallback callback);
|
||||
|
||||
// Returns true once the BLE scan has been initiated.
|
||||
// This interface will be deprecated soon.
|
||||
bool StartScanning(const Uuid& service_uuid,
|
||||
api::ble_v2::TxPowerLevel tx_power_level,
|
||||
ScanCallback callback);
|
||||
api::ble::TxPowerLevel tx_power_level,
|
||||
ScanCallback callback) ABSL_LOCKS_EXCLUDED(mutex_);
|
||||
|
||||
// Returns true once the BLE multiple services scan has been initiated.
|
||||
bool StartMultipleServicesScanning(const std::vector<Uuid>& service_uuids,
|
||||
api::ble_v2::TxPowerLevel tx_power_level,
|
||||
ScanCallback callback);
|
||||
api::ble::TxPowerLevel tx_power_level,
|
||||
ScanCallback callback)
|
||||
ABSL_LOCKS_EXCLUDED(mutex_);
|
||||
|
||||
// This interface will be deprecated soon.
|
||||
// TODO(b/271305977) remove this function.
|
||||
@@ -530,9 +523,9 @@ class BleV2Medium final {
|
||||
// Resume BLE scanning at platform Medium level.
|
||||
bool ResumeMediumScanning();
|
||||
|
||||
std::unique_ptr<api::ble_v2::BleMedium::ScanningSession> StartScanning(
|
||||
const Uuid& service_uuid, api::ble_v2::TxPowerLevel tx_power_level,
|
||||
api::ble_v2::BleMedium::ScanningCallback callback);
|
||||
std::unique_ptr<api::ble::BleMedium::ScanningSession> StartScanning(
|
||||
const Uuid& service_uuid, api::ble::TxPowerLevel tx_power_level,
|
||||
api::ble::BleMedium::ScanningCallback callback);
|
||||
|
||||
// Starts Gatt Server for waiting to client connection.
|
||||
std::unique_ptr<GattServer> StartGattServer(
|
||||
@@ -541,36 +534,36 @@ class BleV2Medium final {
|
||||
// Returns a new GattClient connection to a gatt server.
|
||||
// There is only one instance of GattServer can run at a time.
|
||||
std::unique_ptr<GattClient> ConnectToGattServer(
|
||||
BleV2Peripheral peripheral, api::ble_v2::TxPowerLevel tx_power_level,
|
||||
BlePeripheral peripheral, api::ble::TxPowerLevel tx_power_level,
|
||||
ClientGattConnectionCallback callback);
|
||||
|
||||
// Returns a new BleServerSocket.
|
||||
// On Success, BleServerSocket::IsValid() returns true.
|
||||
BleV2ServerSocket OpenServerSocket(const std::string& service_id);
|
||||
BleServerSocket OpenServerSocket(const std::string& service_id);
|
||||
|
||||
// Returns a new BleL2capServerSocket.
|
||||
// On Success, BleL2capServerSocket::IsValid() returns true.
|
||||
BleL2capServerSocket OpenL2capServerSocket(const std::string& service_id);
|
||||
|
||||
// Returns a new BleV2Socket.
|
||||
// On Success, BleV2Socket::IsValid() returns true.
|
||||
BleV2Socket Connect(const std::string& service_id,
|
||||
api::ble_v2::TxPowerLevel tx_power_level,
|
||||
const BleV2Peripheral& peripheral,
|
||||
CancellationFlag* cancellation_flag);
|
||||
// Returns a new BleSocket.
|
||||
// On Success, BleSocket::IsValid() returns true.
|
||||
BleSocket Connect(const std::string& service_id,
|
||||
api::ble::TxPowerLevel tx_power_level,
|
||||
const BlePeripheral& peripheral,
|
||||
CancellationFlag* cancellation_flag);
|
||||
|
||||
// Returns a new BleL2capSocket.
|
||||
// On Success, BleL2capSocket::IsValid() returns true.
|
||||
BleL2capSocket ConnectOverL2cap(const std::string& service_id,
|
||||
api::ble_v2::TxPowerLevel tx_power_level,
|
||||
const BleV2Peripheral& peripheral,
|
||||
api::ble::TxPowerLevel tx_power_level,
|
||||
const BlePeripheral& peripheral,
|
||||
CancellationFlag* cancellation_flag);
|
||||
|
||||
bool IsExtendedAdvertisementsAvailable();
|
||||
|
||||
bool IsValid() const { return impl_ != nullptr; }
|
||||
|
||||
api::ble_v2::BleMedium* GetImpl() const { return impl_.get(); }
|
||||
api::ble::BleMedium* GetImpl() const { return impl_.get(); }
|
||||
BluetoothAdapter& GetAdapter() { return adapter_; }
|
||||
void AddAlternateUuidForService(uint16_t uuid,
|
||||
const std::string& service_id) {
|
||||
@@ -579,7 +572,7 @@ class BleV2Medium final {
|
||||
|
||||
private:
|
||||
Mutex mutex_;
|
||||
std::unique_ptr<api::ble_v2::BleMedium> impl_;
|
||||
std::unique_ptr<api::ble::BleMedium> impl_;
|
||||
BluetoothAdapter& adapter_;
|
||||
ServerGattConnectionCallback server_gatt_connection_callback_
|
||||
ABSL_GUARDED_BY(mutex_);
|
||||
@@ -589,4 +582,4 @@ class BleV2Medium final {
|
||||
|
||||
} // namespace nearby
|
||||
|
||||
#endif // PLATFORM_PUBLIC_BLE_V2_H_
|
||||
#endif // PLATFORM_PUBLIC_BLE_H_
|
||||
@@ -12,7 +12,7 @@
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
#include "internal/platform/ble_v2.h"
|
||||
#include "internal/platform/ble.h"
|
||||
|
||||
#include <memory>
|
||||
#include <optional>
|
||||
@@ -31,7 +31,7 @@
|
||||
#include "internal/platform/cancellation_flag.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/single_thread_executor.h"
|
||||
@@ -51,9 +51,9 @@ constexpr FeatureFlags kTestCases[] = {
|
||||
},
|
||||
};
|
||||
|
||||
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;
|
||||
using ::testing::Optional;
|
||||
using ::testing::status::StatusIs;
|
||||
|
||||
@@ -64,26 +64,26 @@ constexpr TxPowerLevel kTxPowerLevel(TxPowerLevel::kHigh);
|
||||
constexpr absl::string_view kServiceIDA{
|
||||
"com.google.location.nearby.apps.test.a"};
|
||||
|
||||
class BleV2MediumTest : public ::testing::TestWithParam<FeatureFlags> {
|
||||
class BleMediumTest : public ::testing::TestWithParam<FeatureFlags> {
|
||||
protected:
|
||||
MediumEnvironment& env_{MediumEnvironment::Instance()};
|
||||
};
|
||||
|
||||
TEST_P(BleV2MediumTest, CanConnectToService) {
|
||||
TEST_P(BleMediumTest, CanConnectToService) {
|
||||
FeatureFlags feature_flags = GetParam();
|
||||
env_.SetFeatureFlags(feature_flags);
|
||||
env_.Start();
|
||||
BluetoothAdapter adapter_a_;
|
||||
BluetoothAdapter adapter_b_;
|
||||
BleV2Medium ble_a(adapter_a_);
|
||||
BleV2Medium ble_b(adapter_b_);
|
||||
BleMedium ble_a(adapter_a_);
|
||||
BleMedium ble_b(adapter_b_);
|
||||
Uuid service_uuid(1234, 5678);
|
||||
std::string service_id(kServiceIDA);
|
||||
ByteArray advertisement_bytes{std::string(kAdvertisementString)};
|
||||
CountDownLatch found_latch(1);
|
||||
CountDownLatch lost_latch(1);
|
||||
|
||||
BleV2ServerSocket server_socket = ble_b.OpenServerSocket(service_id);
|
||||
BleServerSocket server_socket = ble_b.OpenServerSocket(service_id);
|
||||
EXPECT_TRUE(server_socket.IsValid());
|
||||
|
||||
// Assemble regular advertisement data
|
||||
@@ -93,21 +93,21 @@ TEST_P(BleV2MediumTest, CanConnectToService) {
|
||||
(ble_b.StartAdvertising(advertising_data, {.tx_power_level = kTxPowerLevel,
|
||||
.is_connectable = true}));
|
||||
|
||||
BleV2Peripheral discovered_peripheral;
|
||||
BlePeripheral discovered_peripheral;
|
||||
ble_a.StartScanning(
|
||||
service_uuid, kTxPowerLevel,
|
||||
{
|
||||
.advertisement_found_cb =
|
||||
[&found_latch, &discovered_peripheral](
|
||||
BleV2Peripheral peripheral,
|
||||
BlePeripheral peripheral,
|
||||
const BleAdvertisementData& advertisement_data) {
|
||||
discovered_peripheral = std::move(peripheral);
|
||||
found_latch.CountDown();
|
||||
},
|
||||
});
|
||||
EXPECT_TRUE(found_latch.Await(absl::Milliseconds(1000)).result());
|
||||
BleV2Socket socket_a;
|
||||
BleV2Socket socket_b;
|
||||
BleSocket socket_a;
|
||||
BleSocket socket_b;
|
||||
EXPECT_FALSE(socket_a.IsValid());
|
||||
EXPECT_FALSE(socket_b.IsValid());
|
||||
{
|
||||
@@ -137,21 +137,21 @@ TEST_P(BleV2MediumTest, CanConnectToService) {
|
||||
env_.Stop();
|
||||
}
|
||||
|
||||
TEST_P(BleV2MediumTest, CanConnectToServiceWithMultipleServices) {
|
||||
TEST_P(BleMediumTest, CanConnectToServiceWithMultipleServices) {
|
||||
FeatureFlags feature_flags = GetParam();
|
||||
env_.SetFeatureFlags(feature_flags);
|
||||
env_.Start();
|
||||
BluetoothAdapter adapter_a_;
|
||||
BluetoothAdapter adapter_b_;
|
||||
BleV2Medium ble_a(adapter_a_);
|
||||
BleV2Medium ble_b(adapter_b_);
|
||||
BleMedium ble_a(adapter_a_);
|
||||
BleMedium ble_b(adapter_b_);
|
||||
Uuid service_uuid(1234, 5678);
|
||||
std::string service_id(kServiceIDA);
|
||||
ByteArray advertisement_bytes{std::string(kAdvertisementString)};
|
||||
CountDownLatch found_latch(1);
|
||||
CountDownLatch lost_latch(1);
|
||||
|
||||
BleV2ServerSocket server_socket = ble_b.OpenServerSocket(service_id);
|
||||
BleServerSocket server_socket = ble_b.OpenServerSocket(service_id);
|
||||
EXPECT_TRUE(server_socket.IsValid());
|
||||
|
||||
// Assemble regular advertisement data
|
||||
@@ -161,21 +161,21 @@ TEST_P(BleV2MediumTest, CanConnectToServiceWithMultipleServices) {
|
||||
(ble_b.StartAdvertising(advertising_data, {.tx_power_level = kTxPowerLevel,
|
||||
.is_connectable = true}));
|
||||
|
||||
BleV2Peripheral discovered_peripheral;
|
||||
BlePeripheral discovered_peripheral;
|
||||
ble_a.StartMultipleServicesScanning(
|
||||
std::vector<Uuid>{service_uuid}, kTxPowerLevel,
|
||||
{
|
||||
.advertisement_found_cb =
|
||||
[&found_latch, &discovered_peripheral](
|
||||
BleV2Peripheral peripheral,
|
||||
BlePeripheral peripheral,
|
||||
const BleAdvertisementData& advertisement_data) {
|
||||
discovered_peripheral = std::move(peripheral);
|
||||
found_latch.CountDown();
|
||||
},
|
||||
});
|
||||
EXPECT_TRUE(found_latch.Await(absl::Milliseconds(1000)).result());
|
||||
BleV2Socket socket_a;
|
||||
BleV2Socket socket_b;
|
||||
BleSocket socket_a;
|
||||
BleSocket socket_b;
|
||||
EXPECT_FALSE(socket_a.IsValid());
|
||||
EXPECT_FALSE(socket_b.IsValid());
|
||||
{
|
||||
@@ -205,16 +205,16 @@ TEST_P(BleV2MediumTest, CanConnectToServiceWithMultipleServices) {
|
||||
env_.Stop();
|
||||
}
|
||||
|
||||
TEST_P(BleV2MediumTest, CanDiscoverMultipleServices) {
|
||||
TEST_P(BleMediumTest, CanDiscoverMultipleServices) {
|
||||
FeatureFlags feature_flags = GetParam();
|
||||
env_.SetFeatureFlags(feature_flags);
|
||||
env_.Start();
|
||||
BluetoothAdapter adapter_a_;
|
||||
BluetoothAdapter adapter_b_;
|
||||
BluetoothAdapter adapter_c_;
|
||||
BleV2Medium ble_a(adapter_a_);
|
||||
BleV2Medium ble_b(adapter_b_);
|
||||
BleV2Medium ble_c(adapter_c_);
|
||||
BleMedium ble_a(adapter_a_);
|
||||
BleMedium ble_b(adapter_b_);
|
||||
BleMedium ble_c(adapter_c_);
|
||||
Uuid service_uuid_a(1234, 5678);
|
||||
Uuid service_uuid_b(1234, 5679);
|
||||
std::string service_id(kServiceIDA);
|
||||
@@ -241,7 +241,7 @@ TEST_P(BleV2MediumTest, CanDiscoverMultipleServices) {
|
||||
std::vector<Uuid>{service_uuid_a, service_uuid_b}, kTxPowerLevel,
|
||||
{.advertisement_found_cb =
|
||||
[&found_latch, &found_service_a, &found_service_b, &service_uuid_a,
|
||||
&service_uuid_b](BleV2Peripheral peripheral,
|
||||
&service_uuid_b](BlePeripheral peripheral,
|
||||
const BleAdvertisementData& advertisement_data) {
|
||||
if (advertisement_data.service_data.contains(service_uuid_a)) {
|
||||
found_service_a = true;
|
||||
@@ -259,21 +259,21 @@ TEST_P(BleV2MediumTest, CanDiscoverMultipleServices) {
|
||||
env_.Stop();
|
||||
}
|
||||
|
||||
TEST_P(BleV2MediumTest, CanCancelConnect) {
|
||||
TEST_P(BleMediumTest, CanCancelConnect) {
|
||||
FeatureFlags feature_flags = GetParam();
|
||||
env_.SetFeatureFlags(feature_flags);
|
||||
env_.Start();
|
||||
BluetoothAdapter adapter_a_;
|
||||
BluetoothAdapter adapter_b_;
|
||||
BleV2Medium ble_a(adapter_a_);
|
||||
BleV2Medium ble_b(adapter_b_);
|
||||
BleMedium ble_a(adapter_a_);
|
||||
BleMedium ble_b(adapter_b_);
|
||||
Uuid service_uuid(1234, 5678);
|
||||
std::string service_id(kServiceIDA);
|
||||
ByteArray advertisement_bytes((std::string(kAdvertisementString)));
|
||||
CountDownLatch found_latch(1);
|
||||
CountDownLatch lost_latch(1);
|
||||
|
||||
BleV2ServerSocket server_socket = ble_b.OpenServerSocket(service_id);
|
||||
BleServerSocket server_socket = ble_b.OpenServerSocket(service_id);
|
||||
EXPECT_TRUE(server_socket.IsValid());
|
||||
|
||||
// Assemble regular advertisement data.
|
||||
@@ -283,21 +283,21 @@ TEST_P(BleV2MediumTest, CanCancelConnect) {
|
||||
(ble_b.StartAdvertising(advertising_data, {.tx_power_level = kTxPowerLevel,
|
||||
.is_connectable = true}));
|
||||
|
||||
BleV2Peripheral discovered_peripheral;
|
||||
BlePeripheral discovered_peripheral;
|
||||
ble_a.StartScanning(
|
||||
service_uuid, kTxPowerLevel,
|
||||
{
|
||||
.advertisement_found_cb =
|
||||
[&found_latch, &discovered_peripheral](
|
||||
BleV2Peripheral peripheral,
|
||||
BlePeripheral peripheral,
|
||||
const BleAdvertisementData& advertisement_data) {
|
||||
discovered_peripheral = std::move(peripheral);
|
||||
found_latch.CountDown();
|
||||
},
|
||||
});
|
||||
EXPECT_TRUE(found_latch.Await(absl::Milliseconds(1000)).result());
|
||||
BleV2Socket socket_a;
|
||||
BleV2Socket socket_b;
|
||||
BleSocket socket_a;
|
||||
BleSocket socket_b;
|
||||
EXPECT_FALSE(socket_a.IsValid());
|
||||
EXPECT_FALSE(socket_b.IsValid());
|
||||
{
|
||||
@@ -333,15 +333,15 @@ TEST_P(BleV2MediumTest, CanCancelConnect) {
|
||||
env_.Stop();
|
||||
}
|
||||
|
||||
INSTANTIATE_TEST_SUITE_P(ParametrisedBleMediumTest, BleV2MediumTest,
|
||||
INSTANTIATE_TEST_SUITE_P(ParametrisedBleMediumTest, BleMediumTest,
|
||||
::testing::ValuesIn(kTestCases));
|
||||
|
||||
TEST_F(BleV2MediumTest, ConstructorDestructorWorks) {
|
||||
TEST_F(BleMediumTest, ConstructorDestructorWorks) {
|
||||
env_.Start();
|
||||
BluetoothAdapter adapter_a;
|
||||
BluetoothAdapter adapter_b;
|
||||
BleV2Medium ble_a(adapter_a);
|
||||
BleV2Medium ble_b(adapter_b);
|
||||
BleMedium ble_a(adapter_a);
|
||||
BleMedium ble_b(adapter_b);
|
||||
|
||||
// Make sure we can create functional mediums.
|
||||
ASSERT_TRUE(ble_a.IsValid());
|
||||
@@ -352,12 +352,12 @@ TEST_F(BleV2MediumTest, ConstructorDestructorWorks) {
|
||||
env_.Stop();
|
||||
}
|
||||
|
||||
TEST_F(BleV2MediumTest, CanStartFastScanningAndFastAdvertising) {
|
||||
TEST_F(BleMediumTest, CanStartFastScanningAndFastAdvertising) {
|
||||
env_.Start();
|
||||
BluetoothAdapter adapter_a;
|
||||
BluetoothAdapter adapter_b;
|
||||
BleV2Medium ble_a(adapter_a);
|
||||
BleV2Medium ble_b(adapter_b);
|
||||
BleMedium ble_a(adapter_a);
|
||||
BleMedium ble_b(adapter_b);
|
||||
Uuid service_uuid(1234, 5678);
|
||||
ByteArray advertisement_bytes((std::string(kAdvertisementString)));
|
||||
CountDownLatch found_latch(1);
|
||||
@@ -366,7 +366,7 @@ TEST_F(BleV2MediumTest, CanStartFastScanningAndFastAdvertising) {
|
||||
service_uuid, kTxPowerLevel,
|
||||
{
|
||||
.advertisement_found_cb =
|
||||
[&found_latch](BleV2Peripheral peripheral,
|
||||
[&found_latch](BlePeripheral peripheral,
|
||||
const BleAdvertisementData& advertisement_data) {
|
||||
found_latch.CountDown();
|
||||
},
|
||||
@@ -387,24 +387,23 @@ TEST_F(BleV2MediumTest, CanStartFastScanningAndFastAdvertising) {
|
||||
advertising_data,
|
||||
{.tx_power_level = kTxPowerLevel, .is_connectable = true}));
|
||||
|
||||
EXPECT_TRUE(env_.GetBleV2MediumStatus(*ble_a.GetImpl()).value().is_scanning);
|
||||
EXPECT_TRUE(
|
||||
env_.GetBleV2MediumStatus(*ble_b.GetImpl()).value().is_advertising);
|
||||
EXPECT_TRUE(env_.GetBleMediumStatus(*ble_a.GetImpl()).value().is_scanning);
|
||||
EXPECT_TRUE(env_.GetBleMediumStatus(*ble_b.GetImpl()).value().is_advertising);
|
||||
EXPECT_TRUE(found_latch.Await(kWaitDuration).result());
|
||||
EXPECT_TRUE(ble_a.StopScanning());
|
||||
EXPECT_TRUE(ble_b.StopAdvertising());
|
||||
EXPECT_FALSE(env_.GetBleV2MediumStatus(*ble_a.GetImpl()).value().is_scanning);
|
||||
EXPECT_FALSE(env_.GetBleMediumStatus(*ble_a.GetImpl()).value().is_scanning);
|
||||
EXPECT_FALSE(
|
||||
env_.GetBleV2MediumStatus(*ble_b.GetImpl()).value().is_advertising);
|
||||
env_.GetBleMediumStatus(*ble_b.GetImpl()).value().is_advertising);
|
||||
env_.Stop();
|
||||
}
|
||||
|
||||
TEST_F(BleV2MediumTest, CanStartScanningAndAdvertising) {
|
||||
TEST_F(BleMediumTest, CanStartScanningAndAdvertising) {
|
||||
env_.Start();
|
||||
BluetoothAdapter adapter_a;
|
||||
BluetoothAdapter adapter_b;
|
||||
BleV2Medium ble_a(adapter_a);
|
||||
BleV2Medium ble_b(adapter_b);
|
||||
BleMedium ble_a(adapter_a);
|
||||
BleMedium ble_b(adapter_b);
|
||||
Uuid service_uuid(1234, 5678);
|
||||
ByteArray advertisement_bytes{std::string(kAdvertisementString)};
|
||||
ByteArray advertisement_header_bytes{std::string(kAdvertisementHeaderString)};
|
||||
@@ -414,7 +413,7 @@ TEST_F(BleV2MediumTest, CanStartScanningAndAdvertising) {
|
||||
service_uuid, kTxPowerLevel,
|
||||
{
|
||||
.advertisement_found_cb =
|
||||
[&found_latch](BleV2Peripheral peripheral,
|
||||
[&found_latch](BlePeripheral peripheral,
|
||||
const BleAdvertisementData& advertisement_data) {
|
||||
found_latch.CountDown();
|
||||
},
|
||||
@@ -435,105 +434,104 @@ TEST_F(BleV2MediumTest, CanStartScanningAndAdvertising) {
|
||||
advertising_data,
|
||||
{.tx_power_level = kTxPowerLevel, .is_connectable = true}));
|
||||
|
||||
EXPECT_TRUE(env_.GetBleV2MediumStatus(*ble_a.GetImpl()).value().is_scanning);
|
||||
EXPECT_TRUE(
|
||||
env_.GetBleV2MediumStatus(*ble_b.GetImpl()).value().is_advertising);
|
||||
EXPECT_TRUE(env_.GetBleMediumStatus(*ble_a.GetImpl()).value().is_scanning);
|
||||
EXPECT_TRUE(env_.GetBleMediumStatus(*ble_b.GetImpl()).value().is_advertising);
|
||||
EXPECT_TRUE(found_latch.Await(kWaitDuration).result());
|
||||
EXPECT_TRUE(ble_a.StopScanning());
|
||||
EXPECT_TRUE(ble_b.StopAdvertising());
|
||||
|
||||
EXPECT_FALSE(env_.GetBleV2MediumStatus(*ble_a.GetImpl()).value().is_scanning);
|
||||
EXPECT_FALSE(env_.GetBleMediumStatus(*ble_a.GetImpl()).value().is_scanning);
|
||||
EXPECT_FALSE(
|
||||
env_.GetBleV2MediumStatus(*ble_b.GetImpl()).value().is_advertising);
|
||||
env_.UnregisterBleV2Medium(*ble_a.GetImpl());
|
||||
env_.UnregisterBleV2Medium(*ble_b.GetImpl());
|
||||
EXPECT_EQ(env_.GetBleV2MediumStatus(*ble_a.GetImpl()), std::nullopt);
|
||||
EXPECT_EQ(env_.GetBleV2MediumStatus(*ble_b.GetImpl()), std::nullopt);
|
||||
env_.GetBleMediumStatus(*ble_b.GetImpl()).value().is_advertising);
|
||||
env_.UnregisterBleMedium(*ble_a.GetImpl());
|
||||
env_.UnregisterBleMedium(*ble_b.GetImpl());
|
||||
EXPECT_EQ(env_.GetBleMediumStatus(*ble_a.GetImpl()), std::nullopt);
|
||||
EXPECT_EQ(env_.GetBleMediumStatus(*ble_b.GetImpl()), std::nullopt);
|
||||
env_.Stop();
|
||||
}
|
||||
|
||||
TEST_F(BleV2MediumTest, StartThenStopAsyncScanning) {
|
||||
TEST_F(BleMediumTest, StartThenStopAsyncScanning) {
|
||||
env_.Start();
|
||||
BluetoothAdapter adapter_a;
|
||||
BleV2Medium ble_a(adapter_a);
|
||||
BleMedium ble_a(adapter_a);
|
||||
Uuid service_uuid(1234, 5678);
|
||||
CountDownLatch found_latch_a(1);
|
||||
|
||||
std::unique_ptr<api::ble_v2::BleMedium::ScanningSession> scanning_session_a =
|
||||
std::unique_ptr<api::ble::BleMedium::ScanningSession> scanning_session_a =
|
||||
ble_a.StartScanning(
|
||||
service_uuid, kTxPowerLevel,
|
||||
api::ble_v2::BleMedium::ScanningCallback{
|
||||
api::ble::BleMedium::ScanningCallback{
|
||||
.advertisement_found_cb =
|
||||
[&](api::ble_v2::BlePeripheral::UniqueId peripheral_id,
|
||||
[&](api::ble::BlePeripheral::UniqueId peripheral_id,
|
||||
BleAdvertisementData advertisement_data) -> void {
|
||||
found_latch_a.CountDown();
|
||||
},
|
||||
});
|
||||
|
||||
EXPECT_TRUE(env_.GetBleV2MediumStatus(*ble_a.GetImpl()).value().is_scanning);
|
||||
EXPECT_TRUE(env_.GetBleMediumStatus(*ble_a.GetImpl()).value().is_scanning);
|
||||
EXPECT_OK(scanning_session_a->stop_scanning());
|
||||
EXPECT_FALSE(env_.GetBleV2MediumStatus(*ble_a.GetImpl()).value().is_scanning);
|
||||
EXPECT_FALSE(env_.GetBleMediumStatus(*ble_a.GetImpl()).value().is_scanning);
|
||||
env_.Stop();
|
||||
}
|
||||
TEST_F(BleV2MediumTest, CanStartMultipleAsyncScanning) {
|
||||
TEST_F(BleMediumTest, CanStartMultipleAsyncScanning) {
|
||||
env_.Start();
|
||||
BluetoothAdapter adapter_a;
|
||||
BluetoothAdapter adapter_b;
|
||||
BleV2Medium ble_a(adapter_a);
|
||||
BleV2Medium ble_b(adapter_b);
|
||||
BleMedium ble_a(adapter_a);
|
||||
BleMedium ble_b(adapter_b);
|
||||
Uuid service_uuid(1234, 5678);
|
||||
CountDownLatch found_latch_a(1);
|
||||
CountDownLatch found_latch_b(1);
|
||||
|
||||
std::unique_ptr<api::ble_v2::BleMedium::ScanningSession> scanning_session_a =
|
||||
std::unique_ptr<api::ble::BleMedium::ScanningSession> scanning_session_a =
|
||||
ble_a.StartScanning(
|
||||
service_uuid, kTxPowerLevel,
|
||||
api::ble_v2::BleMedium::ScanningCallback{
|
||||
api::ble::BleMedium::ScanningCallback{
|
||||
.advertisement_found_cb =
|
||||
[&](api::ble_v2::BlePeripheral::UniqueId peripheral_id,
|
||||
[&](api::ble::BlePeripheral::UniqueId peripheral_id,
|
||||
BleAdvertisementData advertisement_data) -> void {
|
||||
found_latch_a.CountDown();
|
||||
},
|
||||
});
|
||||
std::unique_ptr<api::ble_v2::BleMedium::ScanningSession> scanning_session_b =
|
||||
std::unique_ptr<api::ble::BleMedium::ScanningSession> scanning_session_b =
|
||||
ble_b.StartScanning(
|
||||
service_uuid, kTxPowerLevel,
|
||||
api::ble_v2::BleMedium::ScanningCallback{
|
||||
api::ble::BleMedium::ScanningCallback{
|
||||
.advertisement_found_cb =
|
||||
[&](api::ble_v2::BlePeripheral::UniqueId peripheral_id,
|
||||
[&](api::ble::BlePeripheral::UniqueId peripheral_id,
|
||||
BleAdvertisementData advertisement_data) -> void {
|
||||
found_latch_b.CountDown();
|
||||
},
|
||||
});
|
||||
|
||||
EXPECT_TRUE(env_.GetBleV2MediumStatus(*ble_a.GetImpl()).value().is_scanning);
|
||||
EXPECT_TRUE(env_.GetBleV2MediumStatus(*ble_b.GetImpl()).value().is_scanning);
|
||||
EXPECT_TRUE(env_.GetBleMediumStatus(*ble_a.GetImpl()).value().is_scanning);
|
||||
EXPECT_TRUE(env_.GetBleMediumStatus(*ble_b.GetImpl()).value().is_scanning);
|
||||
|
||||
EXPECT_OK(scanning_session_a->stop_scanning());
|
||||
EXPECT_OK(scanning_session_b->stop_scanning());
|
||||
|
||||
EXPECT_FALSE(env_.GetBleV2MediumStatus(*ble_a.GetImpl()).value().is_scanning);
|
||||
EXPECT_FALSE(env_.GetBleV2MediumStatus(*ble_b.GetImpl()).value().is_scanning);
|
||||
EXPECT_FALSE(env_.GetBleMediumStatus(*ble_a.GetImpl()).value().is_scanning);
|
||||
EXPECT_FALSE(env_.GetBleMediumStatus(*ble_b.GetImpl()).value().is_scanning);
|
||||
env_.Stop();
|
||||
}
|
||||
|
||||
TEST_F(BleV2MediumTest, CanStartAsyncScanningAndAdvertising) {
|
||||
TEST_F(BleMediumTest, CanStartAsyncScanningAndAdvertising) {
|
||||
env_.Start();
|
||||
BluetoothAdapter adapter_a;
|
||||
BluetoothAdapter adapter_b;
|
||||
BleV2Medium ble_a(adapter_a);
|
||||
BleV2Medium ble_b(adapter_b);
|
||||
BleMedium ble_a(adapter_a);
|
||||
BleMedium ble_b(adapter_b);
|
||||
Uuid service_uuid(1234, 5678);
|
||||
ByteArray advertisement_bytes{std::string(kAdvertisementString)};
|
||||
ByteArray advertisement_header_bytes{std::string(kAdvertisementHeaderString)};
|
||||
CountDownLatch found_latch(1);
|
||||
|
||||
std::unique_ptr<api::ble_v2::BleMedium::ScanningSession> scanning_session =
|
||||
std::unique_ptr<api::ble::BleMedium::ScanningSession> scanning_session =
|
||||
ble_a.StartScanning(
|
||||
service_uuid, kTxPowerLevel,
|
||||
api::ble_v2::BleMedium::ScanningCallback{
|
||||
api::ble::BleMedium::ScanningCallback{
|
||||
.advertisement_found_cb =
|
||||
[&](api::ble_v2::BlePeripheral::UniqueId peripheral_id,
|
||||
[&](api::ble::BlePeripheral::UniqueId peripheral_id,
|
||||
BleAdvertisementData advertisement_data) -> void {
|
||||
found_latch.CountDown();
|
||||
},
|
||||
@@ -547,27 +545,26 @@ TEST_F(BleV2MediumTest, CanStartAsyncScanningAndAdvertising) {
|
||||
advertising_data,
|
||||
{.tx_power_level = kTxPowerLevel, .is_connectable = true}));
|
||||
|
||||
EXPECT_TRUE(env_.GetBleV2MediumStatus(*ble_a.GetImpl()).value().is_scanning);
|
||||
EXPECT_TRUE(
|
||||
env_.GetBleV2MediumStatus(*ble_b.GetImpl()).value().is_advertising);
|
||||
EXPECT_TRUE(env_.GetBleMediumStatus(*ble_a.GetImpl()).value().is_scanning);
|
||||
EXPECT_TRUE(env_.GetBleMediumStatus(*ble_b.GetImpl()).value().is_advertising);
|
||||
EXPECT_TRUE(found_latch.Await(kWaitDuration).result());
|
||||
EXPECT_OK(scanning_session->stop_scanning());
|
||||
|
||||
EXPECT_TRUE(ble_b.StopAdvertising());
|
||||
EXPECT_FALSE(env_.GetBleV2MediumStatus(*ble_a.GetImpl()).value().is_scanning);
|
||||
EXPECT_FALSE(env_.GetBleMediumStatus(*ble_a.GetImpl()).value().is_scanning);
|
||||
EXPECT_FALSE(
|
||||
env_.GetBleV2MediumStatus(*ble_b.GetImpl()).value().is_advertising);
|
||||
env_.UnregisterBleV2Medium(*ble_a.GetImpl());
|
||||
env_.UnregisterBleV2Medium(*ble_b.GetImpl());
|
||||
EXPECT_EQ(env_.GetBleV2MediumStatus(*ble_a.GetImpl()), std::nullopt);
|
||||
EXPECT_EQ(env_.GetBleV2MediumStatus(*ble_b.GetImpl()), std::nullopt);
|
||||
env_.GetBleMediumStatus(*ble_b.GetImpl()).value().is_advertising);
|
||||
env_.UnregisterBleMedium(*ble_a.GetImpl());
|
||||
env_.UnregisterBleMedium(*ble_b.GetImpl());
|
||||
EXPECT_EQ(env_.GetBleMediumStatus(*ble_a.GetImpl()), std::nullopt);
|
||||
EXPECT_EQ(env_.GetBleMediumStatus(*ble_b.GetImpl()), std::nullopt);
|
||||
env_.Stop();
|
||||
}
|
||||
|
||||
TEST_F(BleV2MediumTest, CanStartGattServer) {
|
||||
TEST_F(BleMediumTest, CanStartGattServer) {
|
||||
env_.Start();
|
||||
BluetoothAdapter adapter;
|
||||
BleV2Medium ble(adapter);
|
||||
BleMedium ble(adapter);
|
||||
Uuid service_uuid(1234, 5678);
|
||||
Uuid characteristic_uuid(5678, 1234);
|
||||
|
||||
@@ -596,12 +593,12 @@ TEST_F(BleV2MediumTest, CanStartGattServer) {
|
||||
env_.Stop();
|
||||
}
|
||||
|
||||
TEST_F(BleV2MediumTest, GattClientConnectToGattServerWorks) {
|
||||
TEST_F(BleMediumTest, GattClientConnectToGattServerWorks) {
|
||||
env_.Start();
|
||||
BluetoothAdapter adapter_a;
|
||||
BluetoothAdapter adapter_b;
|
||||
BleV2Medium ble_a(adapter_a);
|
||||
BleV2Medium ble_b(adapter_b);
|
||||
BleMedium ble_a(adapter_a);
|
||||
BleMedium ble_b(adapter_b);
|
||||
Uuid service_uuid(1234, 5678);
|
||||
Uuid characteristic_uuid(5678, 1234);
|
||||
|
||||
@@ -628,7 +625,7 @@ TEST_F(BleV2MediumTest, GattClientConnectToGattServerWorks) {
|
||||
MacAddress mac_address = adapter_a.GetAddress();
|
||||
EXPECT_TRUE(mac_address.IsSet());
|
||||
std::unique_ptr<GattClient> gatt_client = ble_b.ConnectToGattServer(
|
||||
BleV2Peripheral(ble_b, mac_address.address()), kTxPowerLevel,
|
||||
BlePeripheral(ble_b, mac_address.address()), kTxPowerLevel,
|
||||
/*ClientGattConnectionCallback=*/{});
|
||||
|
||||
ASSERT_NE(gatt_client, nullptr);
|
||||
@@ -651,12 +648,12 @@ TEST_F(BleV2MediumTest, GattClientConnectToGattServerWorks) {
|
||||
env_.Stop();
|
||||
}
|
||||
|
||||
TEST_F(BleV2MediumTest, GattClientConnectToStoppedGattServerFails) {
|
||||
TEST_F(BleMediumTest, GattClientConnectToStoppedGattServerFails) {
|
||||
env_.Start();
|
||||
BluetoothAdapter adapter_a;
|
||||
BluetoothAdapter adapter_b;
|
||||
BleV2Medium ble_a(adapter_a);
|
||||
BleV2Medium ble_b(adapter_b);
|
||||
BleMedium ble_a(adapter_a);
|
||||
BleMedium ble_b(adapter_b);
|
||||
std::unique_ptr<GattServer> gatt_server =
|
||||
ble_a.StartGattServer(/*ServerGattConnectionCallback=*/{});
|
||||
ASSERT_NE(gatt_server, nullptr);
|
||||
@@ -664,7 +661,7 @@ TEST_F(BleV2MediumTest, GattClientConnectToStoppedGattServerFails) {
|
||||
|
||||
gatt_server->Stop();
|
||||
std::unique_ptr<GattClient> gatt_client = ble_b.ConnectToGattServer(
|
||||
BleV2Peripheral(ble_b, mac_address.address()), kTxPowerLevel,
|
||||
BlePeripheral(ble_b, mac_address.address()), kTxPowerLevel,
|
||||
/*ClientGattConnectionCallback=*/{});
|
||||
|
||||
ASSERT_NE(gatt_client, nullptr);
|
||||
@@ -672,12 +669,12 @@ TEST_F(BleV2MediumTest, GattClientConnectToStoppedGattServerFails) {
|
||||
env_.Stop();
|
||||
}
|
||||
|
||||
TEST_F(BleV2MediumTest, GattClientNotifiedWhenServerDisconnects) {
|
||||
TEST_F(BleMediumTest, GattClientNotifiedWhenServerDisconnects) {
|
||||
env_.Start();
|
||||
BluetoothAdapter adapter_a;
|
||||
BluetoothAdapter adapter_b;
|
||||
BleV2Medium ble_a(adapter_a);
|
||||
BleV2Medium ble_b(adapter_b);
|
||||
BleMedium ble_a(adapter_a);
|
||||
BleMedium ble_b(adapter_b);
|
||||
std::unique_ptr<GattServer> gatt_server =
|
||||
ble_a.StartGattServer(/*ServerGattConnectionCallback=*/{});
|
||||
ASSERT_NE(gatt_server, nullptr);
|
||||
@@ -685,7 +682,7 @@ TEST_F(BleV2MediumTest, GattClientNotifiedWhenServerDisconnects) {
|
||||
// Start GattClient
|
||||
MacAddress mac_address = adapter_a.GetAddress();
|
||||
std::unique_ptr<GattClient> gatt_client = ble_b.ConnectToGattServer(
|
||||
BleV2Peripheral(ble_b, mac_address.address()), kTxPowerLevel,
|
||||
BlePeripheral(ble_b, mac_address.address()), kTxPowerLevel,
|
||||
/*ClientGattConnectionCallback=*/{.disconnected_cb = [&]() {
|
||||
disconnected_latch.CountDown();
|
||||
}});
|
||||
@@ -697,12 +694,12 @@ TEST_F(BleV2MediumTest, GattClientNotifiedWhenServerDisconnects) {
|
||||
env_.Stop();
|
||||
}
|
||||
|
||||
TEST_F(BleV2MediumTest, GattClientOperatiosOnCharacteristic) {
|
||||
TEST_F(BleMediumTest, GattClientOperatiosOnCharacteristic) {
|
||||
env_.Start();
|
||||
BluetoothAdapter adapter_a;
|
||||
BluetoothAdapter adapter_b;
|
||||
BleV2Medium ble_a(adapter_a);
|
||||
BleV2Medium ble_b(adapter_b);
|
||||
BleMedium ble_a(adapter_a);
|
||||
BleMedium ble_b(adapter_b);
|
||||
Uuid service_uuid(1234, 5678);
|
||||
Uuid characteristic_uuid(5678, 1234);
|
||||
std::string written_data;
|
||||
@@ -710,10 +707,10 @@ TEST_F(BleV2MediumTest, GattClientOperatiosOnCharacteristic) {
|
||||
std::unique_ptr<GattServer> gatt_server =
|
||||
ble_a.StartGattServer(/*ServerGattConnectionCallback=*/{
|
||||
.on_characteristic_write_cb =
|
||||
[&](const api::ble_v2::BlePeripheral::UniqueId remote_device_id,
|
||||
const api::ble_v2::GattCharacteristic& characteristic,
|
||||
[&](const api::ble::BlePeripheral::UniqueId remote_device_id,
|
||||
const api::ble::GattCharacteristic& characteristic,
|
||||
int offset, absl::string_view data,
|
||||
api::ble_v2::ServerGattConnectionCallback::WriteValueCallback
|
||||
api::ble::ServerGattConnectionCallback::WriteValueCallback
|
||||
callback) {
|
||||
written_data = data;
|
||||
callback(absl::OkStatus());
|
||||
@@ -723,7 +720,7 @@ TEST_F(BleV2MediumTest, GattClientOperatiosOnCharacteristic) {
|
||||
// Start GattClient.
|
||||
MacAddress mac_address = adapter_a.GetAddress();
|
||||
std::unique_ptr<GattClient> gatt_client = ble_b.ConnectToGattServer(
|
||||
BleV2Peripheral(ble_b, mac_address.address()), kTxPowerLevel,
|
||||
BlePeripheral(ble_b, mac_address.address()), kTxPowerLevel,
|
||||
/*ClientGattConnectionCallback=*/{});
|
||||
|
||||
ASSERT_NE(gatt_client, nullptr);
|
||||
@@ -759,7 +756,7 @@ TEST_F(BleV2MediumTest, GattClientOperatiosOnCharacteristic) {
|
||||
// Can write the characteristic value.
|
||||
EXPECT_TRUE(gatt_client->WriteCharacteristic(
|
||||
*client_characteristic, "hello",
|
||||
api::ble_v2::GattClient::WriteType::kWithResponse));
|
||||
api::ble::GattClient::WriteType::kWithResponse));
|
||||
EXPECT_EQ(written_data, "hello");
|
||||
|
||||
gatt_client->Disconnect();
|
||||
@@ -767,19 +764,19 @@ TEST_F(BleV2MediumTest, GattClientOperatiosOnCharacteristic) {
|
||||
// Failed to write/read characteristic value as gatt is disconnected.
|
||||
EXPECT_FALSE(gatt_client->WriteCharacteristic(
|
||||
*client_characteristic, "any",
|
||||
api::ble_v2::GattClient::WriteType::kWithResponse));
|
||||
api::ble::GattClient::WriteType::kWithResponse));
|
||||
EXPECT_THAT(gatt_client->ReadCharacteristic(*client_characteristic),
|
||||
std::nullopt);
|
||||
gatt_server->Stop();
|
||||
env_.Stop();
|
||||
}
|
||||
|
||||
TEST_F(BleV2MediumTest, GattClientSubscribeNotificationGattServerCanNotify) {
|
||||
TEST_F(BleMediumTest, GattClientSubscribeNotificationGattServerCanNotify) {
|
||||
env_.Start();
|
||||
BluetoothAdapter adapter_a;
|
||||
BluetoothAdapter adapter_b;
|
||||
BleV2Medium ble_a(adapter_a);
|
||||
BleV2Medium ble_b(adapter_b);
|
||||
BleMedium ble_a(adapter_a);
|
||||
BleMedium ble_b(adapter_b);
|
||||
Uuid service_uuid(1234, 5678);
|
||||
Uuid characteristic_uuid(5678, 1234);
|
||||
GattCharacteristic::Permission permissions =
|
||||
@@ -804,7 +801,7 @@ TEST_F(BleV2MediumTest, GattClientSubscribeNotificationGattServerCanNotify) {
|
||||
// Start GattClient
|
||||
MacAddress mac_address = adapter_a.GetAddress();
|
||||
std::unique_ptr<GattClient> gatt_client = ble_b.ConnectToGattServer(
|
||||
BleV2Peripheral(ble_b, mac_address.address()), kTxPowerLevel,
|
||||
BlePeripheral(ble_b, mac_address.address()), kTxPowerLevel,
|
||||
/*ClientGattConnectionCallback=*/{});
|
||||
ASSERT_NE(gatt_client, nullptr);
|
||||
|
||||
@@ -1,6 +1,3 @@
|
||||
load("@rules_cc//cc:cc_library.bzl", "cc_library")
|
||||
load("@rules_cc//cc:cc_test.bzl", "cc_test")
|
||||
|
||||
# Copyright 2020 Google LLC
|
||||
#
|
||||
# Licensed under the Apache License, Version 2.0 (the "License");
|
||||
@@ -14,6 +11,10 @@ load("@rules_cc//cc:cc_test.bzl", "cc_test")
|
||||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
|
||||
load("@rules_cc//cc:cc_library.bzl", "cc_library")
|
||||
load("@rules_cc//cc:cc_test.bzl", "cc_test")
|
||||
|
||||
licenses(["notice"])
|
||||
|
||||
cc_library(
|
||||
@@ -152,7 +153,7 @@ cc_library(
|
||||
name = "comm",
|
||||
hdrs = [
|
||||
"awdl.h",
|
||||
"ble_v2.h",
|
||||
"ble.h",
|
||||
"bluetooth_adapter.h",
|
||||
"bluetooth_classic.h",
|
||||
"credential_callbacks.h",
|
||||
|
||||
@@ -19,12 +19,12 @@
|
||||
#import "internal/platform/implementation/apple/Mediums/BLE/GNCBLEGATTCharacteristic.h"
|
||||
#import "internal/platform/implementation/apple/ble_utils.h"
|
||||
|
||||
#include "internal/platform/implementation/ble_v2.h"
|
||||
#include "internal/platform/implementation/ble.h"
|
||||
|
||||
using GattCharacteristic = ::nearby::api::ble_v2::GattCharacteristic;
|
||||
using Property = ::nearby::api::ble_v2::GattCharacteristic::Property;
|
||||
using Permission = ::nearby::api::ble_v2::GattCharacteristic::Permission;
|
||||
using WriteType = ::nearby::api::ble_v2::GattClient::WriteType;
|
||||
using GattCharacteristic = ::nearby::api::ble::GattCharacteristic;
|
||||
using Property = ::nearby::api::ble::GattCharacteristic::Property;
|
||||
using Permission = ::nearby::api::ble::GattCharacteristic::Permission;
|
||||
using WriteType = ::nearby::api::ble::GattClient::WriteType;
|
||||
using Uuid = ::nearby::Uuid;
|
||||
using ByteArray = ::nearby::ByteArray;
|
||||
|
||||
|
||||
@@ -308,9 +308,9 @@ void GNCEnsureFileAtPath(std::string path) {
|
||||
XCTAssertEqual(bluetooth_classic_medium.get(), nullptr);
|
||||
}
|
||||
|
||||
- (void)testCreateBleV2Medium {
|
||||
- (void)testCreateBleMedium {
|
||||
auto bluetooth_adapter = nearby::api::ImplementationPlatform::CreateBluetoothAdapter();
|
||||
auto ble_medium = nearby::api::ImplementationPlatform::CreateBleV2Medium(*bluetooth_adapter);
|
||||
auto ble_medium = nearby::api::ImplementationPlatform::CreateBleMedium(*bluetooth_adapter);
|
||||
XCTAssertNotEqual(ble_medium.get(), nullptr);
|
||||
}
|
||||
|
||||
|
||||
@@ -95,7 +95,7 @@
|
||||
}
|
||||
|
||||
- (void)testDefaultBlePeripheral {
|
||||
nearby::api::ble_v2::BlePeripheral &defaultPeripheral =
|
||||
nearby::api::ble::BlePeripheral &defaultPeripheral =
|
||||
nearby::apple::BlePeripheral::DefaultBlePeripheral();
|
||||
// 0xffffffffffffffff is the default value from
|
||||
// third_party/nearby/internal/platform/implementation/apple/ble_peripheral.mm when create static
|
||||
|
||||
@@ -24,7 +24,7 @@
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
#include "internal/platform/implementation/ble_v2.h"
|
||||
#include "internal/platform/implementation/ble.h"
|
||||
#include "internal/platform/uuid.h"
|
||||
|
||||
@class GNCBLEGATTClient;
|
||||
@@ -32,7 +32,7 @@
|
||||
namespace nearby {
|
||||
namespace apple {
|
||||
|
||||
class GattClient : public api::ble_v2::GattClient {
|
||||
class GattClient : public api::ble::GattClient {
|
||||
public:
|
||||
explicit GattClient(GNCBLEGATTClient *gatt_client_);
|
||||
~GattClient() override = default;
|
||||
@@ -51,21 +51,20 @@ class GattClient : public api::ble_v2::GattClient {
|
||||
// services and characteristics first.
|
||||
//
|
||||
// On success, returns the characteristic. On error, returns nullptr.
|
||||
std::optional<api::ble_v2::GattCharacteristic> GetCharacteristic(
|
||||
std::optional<api::ble::GattCharacteristic> GetCharacteristic(
|
||||
const Uuid &service_uuid, const Uuid &characteristic_uuid) override;
|
||||
|
||||
// Reads the requested characteristic from the associated remote device.
|
||||
//
|
||||
// On success, returns the characteristic's value. On error, returns nullptr.
|
||||
std::optional<std::string> ReadCharacteristic(
|
||||
const api::ble_v2::GattCharacteristic &characteristic) override;
|
||||
const api::ble::GattCharacteristic &characteristic) override;
|
||||
|
||||
// Writes a given characteristic and its values to the associated remote device.
|
||||
//
|
||||
// Returns whether or not the write was successful.
|
||||
bool WriteCharacteristic(const api::ble_v2::GattCharacteristic &characteristic,
|
||||
absl::string_view value,
|
||||
api::ble_v2::GattClient::WriteType type) override;
|
||||
bool WriteCharacteristic(const api::ble::GattCharacteristic &characteristic,
|
||||
absl::string_view value, api::ble::GattClient::WriteType type) override;
|
||||
|
||||
// Enable or disable notifications/indications for a given characteristic.
|
||||
//
|
||||
@@ -74,7 +73,7 @@ class GattClient : public api::ble_v2::GattClient {
|
||||
//
|
||||
// Returns whether or not the subscription was successful.
|
||||
bool SetCharacteristicSubscription(
|
||||
const api::ble_v2::GattCharacteristic &characteristic, bool enable,
|
||||
const api::ble::GattCharacteristic &characteristic, bool enable,
|
||||
absl::AnyInvocable<void(absl::string_view value)> on_characteristic_changed_cb) override;
|
||||
|
||||
// Disconnects an established connection, or cancels a connection attempt currently in progress.
|
||||
|
||||
@@ -21,7 +21,7 @@
|
||||
#include <utility>
|
||||
#include <vector>
|
||||
|
||||
#include "internal/platform/implementation/ble_v2.h"
|
||||
#include "internal/platform/implementation/ble.h"
|
||||
|
||||
#import "internal/platform/implementation/apple/Flags/GNCFeatureFlags.h"
|
||||
#import "internal/platform/implementation/apple/Log/GNCLogger.h"
|
||||
@@ -60,7 +60,7 @@ bool GattClient::DiscoverServiceAndCharacteristics(const Uuid &service_uuid,
|
||||
return blockError == nil;
|
||||
}
|
||||
|
||||
std::optional<api::ble_v2::GattCharacteristic> GattClient::GetCharacteristic(
|
||||
std::optional<api::ble::GattCharacteristic> GattClient::GetCharacteristic(
|
||||
const Uuid &service_uuid, const Uuid &characteristic_uuid) {
|
||||
CBUUID *serviceUUID = CBUUID128FromCPP(service_uuid);
|
||||
CBUUID *characteristicUUID = CBUUID128FromCPP(characteristic_uuid);
|
||||
@@ -90,7 +90,7 @@ std::optional<api::ble_v2::GattCharacteristic> GattClient::GetCharacteristic(
|
||||
}
|
||||
|
||||
std::optional<std::string> GattClient::ReadCharacteristic(
|
||||
const api::ble_v2::GattCharacteristic &characteristic) {
|
||||
const api::ble::GattCharacteristic &characteristic) {
|
||||
NSCondition *condition = [[NSCondition alloc] init];
|
||||
[condition lock];
|
||||
__block NSData *blockValue = nil;
|
||||
@@ -115,15 +115,15 @@ std::optional<std::string> GattClient::ReadCharacteristic(
|
||||
}
|
||||
|
||||
// TODO(b/290385712): Implement.
|
||||
bool GattClient::WriteCharacteristic(const api::ble_v2::GattCharacteristic &characteristic,
|
||||
bool GattClient::WriteCharacteristic(const api::ble::GattCharacteristic &characteristic,
|
||||
absl::string_view value,
|
||||
api::ble_v2::GattClient::WriteType type) {
|
||||
api::ble::GattClient::WriteType type) {
|
||||
return false;
|
||||
}
|
||||
|
||||
// TODO(b/290385712): Implement.
|
||||
bool GattClient::SetCharacteristicSubscription(
|
||||
const api::ble_v2::GattCharacteristic &characteristic, bool enable,
|
||||
const api::ble::GattCharacteristic &characteristic, bool enable,
|
||||
absl::AnyInvocable<void(absl::string_view value)> on_characteristic_changed_cb) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -21,7 +21,7 @@
|
||||
|
||||
#import <Foundation/Foundation.h>
|
||||
|
||||
#include "internal/platform/implementation/ble_v2.h"
|
||||
#include "internal/platform/implementation/ble.h"
|
||||
#include "internal/platform/uuid.h"
|
||||
|
||||
#import "internal/platform/implementation/apple/ble_peripheral.h"
|
||||
@@ -31,7 +31,7 @@
|
||||
namespace nearby {
|
||||
namespace apple {
|
||||
|
||||
class GattServer : public api::ble_v2::GattServer {
|
||||
class GattServer : public api::ble::GattServer {
|
||||
public:
|
||||
explicit GattServer(GNCBLEGATTServer *gatt_server_);
|
||||
~GattServer() override = default;
|
||||
@@ -43,21 +43,21 @@ class GattServer : public api::ble_v2::GattServer {
|
||||
// services with the same UUID.
|
||||
//
|
||||
// Returns no value upon error.
|
||||
std::optional<api::ble_v2::GattCharacteristic> CreateCharacteristic(
|
||||
std::optional<api::ble::GattCharacteristic> CreateCharacteristic(
|
||||
const Uuid &service_uuid, const Uuid &characteristic_uuid,
|
||||
api::ble_v2::GattCharacteristic::Permission permission,
|
||||
api::ble_v2::GattCharacteristic::Property property) override;
|
||||
api::ble::GattCharacteristic::Permission permission,
|
||||
api::ble::GattCharacteristic::Property property) override;
|
||||
|
||||
// Updates a local characteristic with the provided value.
|
||||
//
|
||||
// Returns whether or not the update was successful.
|
||||
bool UpdateCharacteristic(const api::ble_v2::GattCharacteristic &characteristic,
|
||||
bool UpdateCharacteristic(const api::ble::GattCharacteristic &characteristic,
|
||||
const nearby::ByteArray &value) override;
|
||||
|
||||
// Send a notification or indication that a local characteristic has been updated.
|
||||
//
|
||||
// Returns an absl::Status indicating success or what went wrong.
|
||||
absl::Status NotifyCharacteristicChanged(const api::ble_v2::GattCharacteristic &characteristic,
|
||||
absl::Status NotifyCharacteristicChanged(const api::ble::GattCharacteristic &characteristic,
|
||||
bool confirm, const ByteArray &new_value) override;
|
||||
|
||||
// Stops a GATT server.
|
||||
|
||||
@@ -17,7 +17,7 @@
|
||||
#import <CoreBluetooth/CoreBluetooth.h>
|
||||
#import <Foundation/Foundation.h>
|
||||
|
||||
#include "internal/platform/implementation/ble_v2.h"
|
||||
#include "internal/platform/implementation/ble.h"
|
||||
|
||||
#import "internal/platform/implementation/apple/Log/GNCLogger.h"
|
||||
#import "internal/platform/implementation/apple/Mediums/BLE/GNCBLEGATTServer.h"
|
||||
@@ -29,10 +29,10 @@ namespace apple {
|
||||
|
||||
GattServer::GattServer(GNCBLEGATTServer *gatt_server) : gatt_server_(gatt_server) {}
|
||||
|
||||
std::optional<api::ble_v2::GattCharacteristic> GattServer::CreateCharacteristic(
|
||||
std::optional<api::ble::GattCharacteristic> GattServer::CreateCharacteristic(
|
||||
const Uuid &service_uuid, const Uuid &characteristic_uuid,
|
||||
api::ble_v2::GattCharacteristic::Permission permission,
|
||||
api::ble_v2::GattCharacteristic::Property property) {
|
||||
api::ble::GattCharacteristic::Permission permission,
|
||||
api::ble::GattCharacteristic::Property property) {
|
||||
CBUUID *serviceUUID = CBUUID128FromCPP(service_uuid);
|
||||
CBUUID *characteristicUUID = CBUUID128FromCPP(characteristic_uuid);
|
||||
CBAttributePermissions permissions = CBAttributePermissionsFromCPP(permission);
|
||||
@@ -63,7 +63,7 @@ std::optional<api::ble_v2::GattCharacteristic> GattServer::CreateCharacteristic(
|
||||
return CPPGATTCharacteristicFromObjC(blockCharacteristic);
|
||||
}
|
||||
|
||||
bool GattServer::UpdateCharacteristic(const api::ble_v2::GattCharacteristic &characteristic,
|
||||
bool GattServer::UpdateCharacteristic(const api::ble::GattCharacteristic &characteristic,
|
||||
const nearby::ByteArray &value) {
|
||||
NSCondition *condition = [[NSCondition alloc] init];
|
||||
[condition lock];
|
||||
@@ -86,8 +86,7 @@ bool GattServer::UpdateCharacteristic(const api::ble_v2::GattCharacteristic &cha
|
||||
|
||||
// TODO(b/290385712): Implement.
|
||||
absl::Status GattServer::NotifyCharacteristicChanged(
|
||||
const api::ble_v2::GattCharacteristic &characteristic, bool confirm,
|
||||
const ByteArray &new_value) {
|
||||
const api::ble::GattCharacteristic &characteristic, bool confirm, const ByteArray &new_value) {
|
||||
return absl::UnimplementedError("");
|
||||
}
|
||||
|
||||
|
||||
@@ -16,14 +16,14 @@
|
||||
|
||||
#include "absl/functional/any_invocable.h"
|
||||
#include "internal/platform/exception.h"
|
||||
#include "internal/platform/implementation/ble_v2.h"
|
||||
#import "internal/platform/implementation/apple/ble_l2cap_socket.h"
|
||||
#include "internal/platform/implementation/ble.h"
|
||||
|
||||
namespace nearby {
|
||||
namespace apple {
|
||||
|
||||
// A BLE L2CAP server socket for listening incoming L2CAP socket.
|
||||
class BleL2capServerSocket : public api::ble_v2::BleL2capServerSocket {
|
||||
class BleL2capServerSocket : public api::ble::BleL2capServerSocket {
|
||||
public:
|
||||
BleL2capServerSocket() = default;
|
||||
~BleL2capServerSocket() override;
|
||||
@@ -43,7 +43,7 @@ class BleL2capServerSocket : public api::ble_v2::BleL2capServerSocket {
|
||||
// Returns nullptr on error.
|
||||
// Once error is reported, it is permanent, and L2CAP ServerSocket has to be
|
||||
// closed.
|
||||
std::unique_ptr<api::ble_v2::BleL2capSocket> Accept() override
|
||||
std::unique_ptr<api::ble::BleL2capSocket> Accept() override
|
||||
ABSL_LOCKS_EXCLUDED(mutex_);
|
||||
|
||||
// Closes the L2CAP server socket.
|
||||
|
||||
@@ -35,7 +35,7 @@ int BleL2capServerSocket::GetPSM() const { return psm_; }
|
||||
void BleL2capServerSocket::SetPSM(int psm) { psm_ = psm; }
|
||||
|
||||
// TODO: b/399815436 - Refactor Accept() and AddPendingSocket() for better readability.
|
||||
std::unique_ptr<api::ble_v2::BleL2capSocket> BleL2capServerSocket::Accept() {
|
||||
std::unique_ptr<api::ble::BleL2capSocket> BleL2capServerSocket::Accept() {
|
||||
absl::MutexLock lock(&mutex_);
|
||||
while (!closed_ && pending_sockets_.empty()) {
|
||||
cond_.Wait(&mutex_);
|
||||
|
||||
@@ -14,7 +14,7 @@
|
||||
|
||||
#include <memory>
|
||||
|
||||
#include "internal/platform/implementation/ble_v2.h"
|
||||
#include "internal/platform/implementation/ble.h"
|
||||
|
||||
#import "internal/platform/implementation/apple/ble_peripheral.h"
|
||||
|
||||
@@ -27,7 +27,7 @@ namespace apple {
|
||||
/** A readable stream of bytes. */
|
||||
class BleL2capInputStream : public InputStream {
|
||||
public:
|
||||
explicit BleL2capInputStream(GNCBLEL2CAPConnection* connection);
|
||||
explicit BleL2capInputStream(GNCBLEL2CAPConnection *connection);
|
||||
~BleL2capInputStream() override;
|
||||
|
||||
// Reads at most `size` bytes from the input stream.
|
||||
@@ -42,7 +42,7 @@ class BleL2capInputStream : public InputStream {
|
||||
|
||||
private:
|
||||
GNCMConnectionHandlers *connectionHandlers_;
|
||||
GNCBLEL2CAPConnection* connection_;
|
||||
GNCBLEL2CAPConnection *connection_;
|
||||
NSMutableArray<NSData *> *newDataPackets_;
|
||||
NSMutableData *accumulatedData_;
|
||||
NSCondition *condition_;
|
||||
@@ -51,7 +51,7 @@ class BleL2capInputStream : public InputStream {
|
||||
/** A writable stream of bytes. */
|
||||
class BleL2capOutputStream : public OutputStream {
|
||||
public:
|
||||
explicit BleL2capOutputStream(GNCBLEL2CAPConnection* connection)
|
||||
explicit BleL2capOutputStream(GNCBLEL2CAPConnection *connection)
|
||||
: connection_(connection), condition_([[NSCondition alloc] init]) {}
|
||||
~BleL2capOutputStream() override;
|
||||
|
||||
@@ -71,21 +71,21 @@ class BleL2capOutputStream : public OutputStream {
|
||||
Exception Close() override;
|
||||
|
||||
private:
|
||||
GNCBLEL2CAPConnection* connection_;
|
||||
GNCBLEL2CAPConnection *connection_;
|
||||
NSCondition *condition_;
|
||||
};
|
||||
|
||||
/**
|
||||
* Concrete BleL2capSocket implementation.
|
||||
*/
|
||||
class BleL2capSocket : public api::ble_v2::BleL2capSocket {
|
||||
class BleL2capSocket : public api::ble::BleL2capSocket {
|
||||
public:
|
||||
explicit BleL2capSocket(GNCBLEL2CAPConnection* connection);
|
||||
explicit BleL2capSocket(GNCBLEL2CAPConnection *connection);
|
||||
|
||||
// The peripheral used to create the socket must outlive the socket or undefined behavior will
|
||||
// occur.
|
||||
BleL2capSocket(GNCBLEL2CAPConnection *connection,
|
||||
api::ble_v2::BlePeripheral::UniqueId peripheral_id);
|
||||
api::ble::BlePeripheral::UniqueId peripheral_id);
|
||||
~BleL2capSocket() override;
|
||||
|
||||
// Returns the InputStream of the BleL2capSocket.
|
||||
@@ -109,7 +109,7 @@ class BleL2capSocket : public api::ble_v2::BleL2capSocket {
|
||||
|
||||
// Returns valid BlePeripheral pointer if there is a connection, and
|
||||
// nullptr otherwise.
|
||||
api::ble_v2::BlePeripheral::UniqueId GetRemotePeripheralId() override { return peripheral_id_; }
|
||||
api::ble::BlePeripheral::UniqueId GetRemotePeripheralId() override { return peripheral_id_; }
|
||||
|
||||
bool IsClosed() const ABSL_LOCKS_EXCLUDED(mutex_);
|
||||
|
||||
@@ -120,7 +120,7 @@ class BleL2capSocket : public api::ble_v2::BleL2capSocket {
|
||||
bool closed_ ABSL_GUARDED_BY(mutex_) = false;
|
||||
std::unique_ptr<BleL2capInputStream> input_stream_;
|
||||
std::unique_ptr<BleL2capOutputStream> output_stream_;
|
||||
api::ble_v2::BlePeripheral::UniqueId peripheral_id_;
|
||||
api::ble::BlePeripheral::UniqueId peripheral_id_;
|
||||
};
|
||||
|
||||
} // namespace apple
|
||||
|
||||
@@ -17,7 +17,7 @@
|
||||
#import "internal/platform/implementation/apple/Log/GNCLogger.h"
|
||||
#import "internal/platform/implementation/apple/Mediums/BLE/GNCBLEL2CAPConnection.h"
|
||||
#import "internal/platform/implementation/apple/utils.h"
|
||||
#include "internal/platform/implementation/ble_v2.h"
|
||||
#include "internal/platform/implementation/ble.h"
|
||||
|
||||
namespace nearby {
|
||||
namespace apple {
|
||||
@@ -166,7 +166,7 @@ BleL2capSocket::BleL2capSocket(GNCBLEL2CAPConnection *connection)
|
||||
: BleL2capSocket(connection, BlePeripheral::DefaultBlePeripheral().GetUniqueId()) {}
|
||||
|
||||
BleL2capSocket::BleL2capSocket(GNCBLEL2CAPConnection *connection,
|
||||
api::ble_v2::BlePeripheral::UniqueId peripheral_id)
|
||||
api::ble::BlePeripheral::UniqueId peripheral_id)
|
||||
: input_stream_(std::make_unique<BleL2capInputStream>(connection)),
|
||||
output_stream_(std::make_unique<BleL2capOutputStream>(connection)),
|
||||
peripheral_id_(peripheral_id) {}
|
||||
|
||||
@@ -30,7 +30,7 @@
|
||||
#import "internal/platform/implementation/apple/ble_server_socket.h"
|
||||
#import "internal/platform/implementation/apple/bluetooth_adapter_v2.h"
|
||||
#import "internal/platform/implementation/apple/single_thread_executor.h"
|
||||
#include "internal/platform/implementation/ble_v2.h"
|
||||
#include "internal/platform/implementation/ble.h"
|
||||
#include "internal/platform/implementation/bluetooth_adapter.h"
|
||||
#include "internal/platform/uuid.h"
|
||||
|
||||
@@ -44,7 +44,7 @@ namespace apple {
|
||||
|
||||
// The main BLE medium used inside of Nearby. This serves as the entry point for all BLE and GATT
|
||||
// related operations.
|
||||
class BleMedium : public api::ble_v2::BleMedium {
|
||||
class BleMedium : public api::ble::BleMedium {
|
||||
public:
|
||||
BleMedium();
|
||||
~BleMedium() override;
|
||||
@@ -55,16 +55,16 @@ class BleMedium : public api::ble_v2::BleMedium {
|
||||
// the stop_advertising callback in AdvertisingSession.
|
||||
//
|
||||
// Advertising must be stopped before attempting to start advertising again.
|
||||
std::unique_ptr<api::ble_v2::BleMedium::AdvertisingSession> StartAdvertising(
|
||||
const api::ble_v2::BleAdvertisementData &advertising_data,
|
||||
api::ble_v2::AdvertiseParameters advertise_set_parameters,
|
||||
api::ble_v2::BleMedium::AdvertisingCallback callback) override;
|
||||
std::unique_ptr<api::ble::BleMedium::AdvertisingSession> StartAdvertising(
|
||||
const api::ble::BleAdvertisementData &advertising_data,
|
||||
api::ble::AdvertiseParameters advertise_set_parameters,
|
||||
api::ble::BleMedium::AdvertisingCallback callback) override;
|
||||
|
||||
// Starts BLE advertising and returns whether or not it was successful.
|
||||
//
|
||||
// Advertising must be stopped before attempting to start advertising again.
|
||||
bool StartAdvertising(const api::ble_v2::BleAdvertisementData &advertising_data,
|
||||
api::ble_v2::AdvertiseParameters advertise_set_parameters) override;
|
||||
bool StartAdvertising(const api::ble::BleAdvertisementData &advertising_data,
|
||||
api::ble::AdvertiseParameters advertise_set_parameters) override;
|
||||
|
||||
// Stops advertising.
|
||||
//
|
||||
@@ -77,20 +77,20 @@ class BleMedium : public api::ble_v2::BleMedium {
|
||||
// scanning, invoke the stop_scanning callback in ScanningSession.
|
||||
//
|
||||
// Scanning must be stopped before attempting to start scanning again.
|
||||
std::unique_ptr<api::ble_v2::BleMedium::ScanningSession> StartScanning(
|
||||
const Uuid &service_uuid, api::ble_v2::TxPowerLevel tx_power_level,
|
||||
api::ble_v2::BleMedium::ScanningCallback callback) override;
|
||||
std::unique_ptr<api::ble::BleMedium::ScanningSession> StartScanning(
|
||||
const Uuid &service_uuid, api::ble::TxPowerLevel tx_power_level,
|
||||
api::ble::BleMedium::ScanningCallback callback) override;
|
||||
|
||||
// Starts scanning and returns whether or not it was successful.
|
||||
//
|
||||
// Scanning must be stopped before attempting to start scanning again.
|
||||
bool StartScanning(const Uuid &service_uuid, api::ble_v2::TxPowerLevel tx_power_level,
|
||||
api::ble_v2::BleMedium::ScanCallback callback) override;
|
||||
bool StartScanning(const Uuid &service_uuid, api::ble::TxPowerLevel tx_power_level,
|
||||
api::ble::BleMedium::ScanCallback callback) override;
|
||||
|
||||
// Starts scanning on multiple services and returns whether or not it was successful.
|
||||
bool StartMultipleServicesScanning(const std::vector<Uuid> &service_uuids,
|
||||
api::ble_v2::TxPowerLevel tx_power_level,
|
||||
api::ble_v2::BleMedium::ScanCallback callback) override;
|
||||
api::ble::TxPowerLevel tx_power_level,
|
||||
api::ble::BleMedium::ScanCallback callback) override;
|
||||
|
||||
// Stops scanning.
|
||||
//
|
||||
@@ -110,28 +110,28 @@ class BleMedium : public api::ble_v2::BleMedium {
|
||||
// TODO(b/290385712): ServerGattConnectionCallback methods are not yet implemented.
|
||||
//
|
||||
// Starts a GATT server. Returns a nullptr upon error.
|
||||
std::unique_ptr<api::ble_v2::GattServer> StartGattServer(
|
||||
api::ble_v2::ServerGattConnectionCallback callback) override;
|
||||
std::unique_ptr<api::ble::GattServer> StartGattServer(
|
||||
api::ble::ServerGattConnectionCallback callback) override;
|
||||
|
||||
// Connects to a GATT server and negotiates the specified connection parameters. Returns nullptr
|
||||
// upon error.
|
||||
//
|
||||
// The peripheral must outlive the GATT client or undefined behavior will occur. The peripheral
|
||||
// should not be modified by this method.
|
||||
std::unique_ptr<api::ble_v2::GattClient> ConnectToGattServer(
|
||||
api::ble_v2::BlePeripheral::UniqueId peripheral_id, api::ble_v2::TxPowerLevel tx_power_level,
|
||||
api::ble_v2::ClientGattConnectionCallback callback) override;
|
||||
std::unique_ptr<api::ble::GattClient> ConnectToGattServer(
|
||||
api::ble::BlePeripheral::UniqueId peripheral_id, api::ble::TxPowerLevel tx_power_level,
|
||||
api::ble::ClientGattConnectionCallback callback) override;
|
||||
|
||||
// Opens a BLE server socket based on service ID.
|
||||
//
|
||||
// On success, returns a new BleServerSocket. On error, returns nullptr.
|
||||
std::unique_ptr<api::ble_v2::BleServerSocket> OpenServerSocket(
|
||||
std::unique_ptr<api::ble::BleServerSocket> OpenServerSocket(
|
||||
const std::string &service_id) override;
|
||||
|
||||
// Opens a L2CAP server socket based on service ID.
|
||||
//
|
||||
// On success, returns a new BleL2capServerSocket. On error, returns nullptr.
|
||||
std::unique_ptr<api::ble_v2::BleL2capServerSocket> OpenL2capServerSocket(
|
||||
std::unique_ptr<api::ble::BleL2capServerSocket> OpenL2capServerSocket(
|
||||
const std::string &service_id) override;
|
||||
|
||||
// TODO(b/290385712): cancellation_flag support is not yet implemented.
|
||||
@@ -142,10 +142,10 @@ class BleMedium : public api::ble_v2::BleMedium {
|
||||
// should not be modified by this method.
|
||||
//
|
||||
// On success, returns a new BleSocket. On error, returns nullptr.
|
||||
std::unique_ptr<api::ble_v2::BleSocket> Connect(
|
||||
const std::string &service_id, api::ble_v2::TxPowerLevel tx_power_level,
|
||||
api::ble_v2::BlePeripheral::UniqueId peripheral_id,
|
||||
CancellationFlag *cancellation_flag) override;
|
||||
std::unique_ptr<api::ble::BleSocket> Connect(const std::string &service_id,
|
||||
api::ble::TxPowerLevel tx_power_level,
|
||||
api::ble::BlePeripheral::UniqueId peripheral_id,
|
||||
CancellationFlag *cancellation_flag) override;
|
||||
|
||||
// TODO(b/290385712): cancellation_flag support is not yet implemented.
|
||||
//
|
||||
@@ -155,9 +155,9 @@ class BleMedium : public api::ble_v2::BleMedium {
|
||||
// should not be modified by this method.
|
||||
//
|
||||
// On success, returns a new BleL2capSocket. On error, returns nullptr.
|
||||
std::unique_ptr<api::ble_v2::BleL2capSocket> ConnectOverL2cap(
|
||||
int psm, const std::string &service_id, api::ble_v2::TxPowerLevel tx_power_level,
|
||||
api::ble_v2::BlePeripheral::UniqueId peripheral_id,
|
||||
std::unique_ptr<api::ble::BleL2capSocket> ConnectOverL2cap(
|
||||
int psm, const std::string &service_id, api::ble::TxPowerLevel tx_power_level,
|
||||
api::ble::BlePeripheral::UniqueId peripheral_id,
|
||||
CancellationFlag *cancellation_flag) override;
|
||||
|
||||
// Returns whether the hardware supports BOTH advertising extensions and extended scans.
|
||||
@@ -171,7 +171,7 @@ class BleMedium : public api::ble_v2::BleMedium {
|
||||
//
|
||||
// Returns std::nullopt if cannot retrieve the BlePeripheral from the native
|
||||
// BLE peripheral id.
|
||||
std::optional<api::ble_v2::BlePeripheral::UniqueId> RetrieveBlePeripheralIdFromNativeId(
|
||||
std::optional<api::ble::BlePeripheral::UniqueId> RetrieveBlePeripheralIdFromNativeId(
|
||||
const std::string &ble_peripheral_native_id) override;
|
||||
|
||||
private:
|
||||
@@ -181,15 +181,14 @@ class BleMedium : public api::ble_v2::BleMedium {
|
||||
PeripheralsMap() = default;
|
||||
~PeripheralsMap() = default;
|
||||
|
||||
api::ble_v2::BlePeripheral::UniqueId Add(id<GNCPeripheral> peripheral)
|
||||
ABSL_LOCKS_EXCLUDED(mutex_);
|
||||
id<GNCPeripheral> Get(api::ble_v2::BlePeripheral::UniqueId peripheral_id)
|
||||
api::ble::BlePeripheral::UniqueId Add(id<GNCPeripheral> peripheral) ABSL_LOCKS_EXCLUDED(mutex_);
|
||||
id<GNCPeripheral> Get(api::ble::BlePeripheral::UniqueId peripheral_id)
|
||||
ABSL_LOCKS_EXCLUDED(mutex_);
|
||||
void Clear() ABSL_LOCKS_EXCLUDED(mutex_);
|
||||
|
||||
private:
|
||||
absl::Mutex mutex_;
|
||||
absl::flat_hash_map<api::ble_v2::BlePeripheral::UniqueId, id<GNCPeripheral>> peripherals_
|
||||
absl::flat_hash_map<api::ble::BlePeripheral::UniqueId, id<GNCPeripheral>> peripherals_
|
||||
ABSL_GUARDED_BY(mutex_);
|
||||
};
|
||||
|
||||
@@ -197,9 +196,9 @@ class BleMedium : public api::ble_v2::BleMedium {
|
||||
NSDictionary<CBUUID *, NSData *> *serviceData);
|
||||
void ClearAdvertisementPacketsMap();
|
||||
void CleanUpExpiredAdvertisementPackets(NSDate *now);
|
||||
bool ShouldReportAdvertisement(NSDate *now, api::ble_v2::BlePeripheral::UniqueId peripheral_id,
|
||||
bool ShouldReportAdvertisement(NSDate *now, api::ble::BlePeripheral::UniqueId peripheral_id,
|
||||
NSDictionary<CBUUID *, NSData *> *service_data);
|
||||
void AddAdvertisementPacketInfo(api::ble_v2::BlePeripheral::UniqueId peripheral_id,
|
||||
void AddAdvertisementPacketInfo(api::ble::BlePeripheral::UniqueId peripheral_id,
|
||||
NSDictionary<CBUUID *, NSData *> *service_data);
|
||||
NSDate *GetLastTimestampToCleanExpiredAdvertisementPackets();
|
||||
|
||||
@@ -216,7 +215,7 @@ class BleMedium : public api::ble_v2::BleMedium {
|
||||
|
||||
absl::Mutex advertisement_packets_mutex_;
|
||||
// A map for maintaining the set of advertisement packets that should be tracked.
|
||||
absl::flat_hash_map<api::ble_v2::BlePeripheral::UniqueId, AdvertisementPacketInfo>
|
||||
absl::flat_hash_map<api::ble::BlePeripheral::UniqueId, AdvertisementPacketInfo>
|
||||
advertisement_packets_map_ ABSL_GUARDED_BY(advertisement_packets_mutex_);
|
||||
// The timestamp of the last time to clean up expired advertisement packets. This is used to
|
||||
// prevent the map from growing indefinitely.
|
||||
@@ -228,10 +227,10 @@ class BleMedium : public api::ble_v2::BleMedium {
|
||||
GNSCentralManager *socketCentralManager_;
|
||||
|
||||
// Used for the blocking version of StartAdvertising and only has an advertisement found callback.
|
||||
api::ble_v2::BleMedium::ScanCallback scan_cb_;
|
||||
api::ble::BleMedium::ScanCallback scan_cb_;
|
||||
// Used for the async version of StartAdvertising and has both an advertisement found and result
|
||||
// callback.
|
||||
api::ble_v2::BleMedium::ScanningCallback scanning_cb_;
|
||||
api::ble::BleMedium::ScanningCallback scanning_cb_;
|
||||
|
||||
absl::Mutex l2cap_server_socket_mutex_;
|
||||
BleL2capServerSocket *l2cap_server_socket_ptr_ = nullptr;
|
||||
|
||||
@@ -24,7 +24,7 @@
|
||||
|
||||
#include "internal/platform/implementation/apple/ble_utils.h"
|
||||
#include "internal/platform/implementation/apple/utils.h"
|
||||
#include "internal/platform/implementation/ble_v2.h"
|
||||
#include "internal/platform/implementation/ble.h"
|
||||
#include "internal/platform/implementation/bluetooth_adapter.h"
|
||||
|
||||
#import "internal/platform/implementation/apple/Mediums/BLE/GNCBLEGATTCharacteristic.h"
|
||||
@@ -92,14 +92,14 @@ BleMedium::BleMedium() : medium_([[GNCBLEMedium alloc] init]) {
|
||||
// ble_medium.mm
|
||||
BleMedium::~BleMedium() { [medium_ stop]; }
|
||||
|
||||
std::unique_ptr<api::ble_v2::BleMedium::AdvertisingSession> BleMedium::StartAdvertising(
|
||||
const api::ble_v2::BleAdvertisementData &advertising_data,
|
||||
api::ble_v2::AdvertiseParameters advertise_set_parameters,
|
||||
api::ble_v2::BleMedium::AdvertisingCallback callback) {
|
||||
std::unique_ptr<api::ble::BleMedium::AdvertisingSession> BleMedium::StartAdvertising(
|
||||
const api::ble::BleAdvertisementData &advertising_data,
|
||||
api::ble::AdvertiseParameters advertise_set_parameters,
|
||||
api::ble::BleMedium::AdvertisingCallback callback) {
|
||||
NSMutableDictionary<CBUUID *, NSData *> *serviceData =
|
||||
ObjCServiceDataFromCPP(advertising_data.service_data);
|
||||
|
||||
__block api::ble_v2::BleMedium::AdvertisingCallback blockCallback = std::move(callback);
|
||||
__block api::ble::BleMedium::AdvertisingCallback blockCallback = std::move(callback);
|
||||
|
||||
[socketPeripheralManager_ start];
|
||||
|
||||
@@ -115,8 +115,8 @@ std::unique_ptr<api::ble_v2::BleMedium::AdvertisingSession> BleMedium::StartAdve
|
||||
}});
|
||||
}
|
||||
|
||||
bool BleMedium::StartAdvertising(const api::ble_v2::BleAdvertisementData &advertising_data,
|
||||
api::ble_v2::AdvertiseParameters advertise_set_parameters) {
|
||||
bool BleMedium::StartAdvertising(const api::ble::BleAdvertisementData &advertising_data,
|
||||
api::ble::AdvertiseParameters advertise_set_parameters) {
|
||||
NSMutableDictionary<CBUUID *, NSData *> *serviceData =
|
||||
ObjCServiceDataFromCPP(advertising_data.service_data);
|
||||
|
||||
@@ -158,7 +158,7 @@ bool BleMedium::StopAdvertising() {
|
||||
|
||||
void BleMedium::HandleAdvertisementFound(id<GNCPeripheral> peripheral,
|
||||
NSDictionary<CBUUID *, NSData *> *serviceData) {
|
||||
api::ble_v2::BleAdvertisementData data;
|
||||
api::ble::BleAdvertisementData data;
|
||||
NSDate *now = [NSDate date];
|
||||
|
||||
if ([now timeIntervalSinceDate:GetLastTimestampToCleanExpiredAdvertisementPackets()] >
|
||||
@@ -166,7 +166,7 @@ void BleMedium::HandleAdvertisementFound(id<GNCPeripheral> peripheral,
|
||||
ClearAdvertisementPacketsMap();
|
||||
}
|
||||
|
||||
api::ble_v2::BlePeripheral::UniqueId peripheral_id = peripheral.identifier.hash;
|
||||
api::ble::BlePeripheral::UniqueId peripheral_id = peripheral.identifier.hash;
|
||||
|
||||
if (!ShouldReportAdvertisement(now, peripheral_id, serviceData)) {
|
||||
return;
|
||||
@@ -177,7 +177,7 @@ void BleMedium::HandleAdvertisementFound(id<GNCPeripheral> peripheral,
|
||||
}
|
||||
|
||||
// Add the peripheral to the map if we haven't discovered it yet.
|
||||
api::ble_v2::BlePeripheral::UniqueId unique_id = peripherals_.Add(peripheral);
|
||||
api::ble::BlePeripheral::UniqueId unique_id = peripherals_.Add(peripheral);
|
||||
AddAdvertisementPacketInfo(unique_id, serviceData);
|
||||
|
||||
#if DEBUG
|
||||
@@ -196,9 +196,9 @@ void BleMedium::HandleAdvertisementFound(id<GNCPeripheral> peripheral,
|
||||
}
|
||||
}
|
||||
|
||||
std::unique_ptr<api::ble_v2::BleMedium::ScanningSession> BleMedium::StartScanning(
|
||||
const Uuid &service_uuid, api::ble_v2::TxPowerLevel tx_power_level,
|
||||
api::ble_v2::BleMedium::ScanningCallback callback) {
|
||||
std::unique_ptr<api::ble::BleMedium::ScanningSession> BleMedium::StartScanning(
|
||||
const Uuid &service_uuid, api::ble::TxPowerLevel tx_power_level,
|
||||
api::ble::BleMedium::ScanningCallback callback) {
|
||||
CBUUID *serviceUUID = CBUUID128FromCPP(service_uuid);
|
||||
scanning_cb_ = std::move(callback);
|
||||
|
||||
@@ -230,8 +230,8 @@ std::unique_ptr<api::ble_v2::BleMedium::ScanningSession> BleMedium::StartScannin
|
||||
}});
|
||||
}
|
||||
|
||||
bool BleMedium::StartScanning(const Uuid &service_uuid, api::ble_v2::TxPowerLevel tx_power_level,
|
||||
api::ble_v2::BleMedium::ScanCallback callback) {
|
||||
bool BleMedium::StartScanning(const Uuid &service_uuid, api::ble::TxPowerLevel tx_power_level,
|
||||
api::ble::BleMedium::ScanCallback callback) {
|
||||
CBUUID *serviceUUID = CBUUID128FromCPP(service_uuid);
|
||||
scan_cb_ = std::move(callback);
|
||||
|
||||
@@ -268,8 +268,8 @@ bool BleMedium::StartScanning(const Uuid &service_uuid, api::ble_v2::TxPowerLeve
|
||||
}
|
||||
|
||||
bool BleMedium::StartMultipleServicesScanning(const std::vector<Uuid> &service_uuids,
|
||||
api::ble_v2::TxPowerLevel tx_power_level,
|
||||
api::ble_v2::BleMedium::ScanCallback callback) {
|
||||
api::ble::TxPowerLevel tx_power_level,
|
||||
api::ble::BleMedium::ScanCallback callback) {
|
||||
if (service_uuids.empty()) {
|
||||
GNCLoggerError(@"No service UUIDs provided");
|
||||
return false;
|
||||
@@ -355,8 +355,8 @@ bool BleMedium::ResumeMediumScanning() {
|
||||
}
|
||||
|
||||
// TODO(b/290385712): Add implementation that calls ServerGattConnectionCallback methods.
|
||||
std::unique_ptr<api::ble_v2::GattServer> BleMedium::StartGattServer(
|
||||
api::ble_v2::ServerGattConnectionCallback callback) {
|
||||
std::unique_ptr<api::ble::GattServer> BleMedium::StartGattServer(
|
||||
api::ble::ServerGattConnectionCallback callback) {
|
||||
dispatch_semaphore_t semaphore = dispatch_semaphore_create(0);
|
||||
__block GNCBLEGATTServer *blockServer = nil;
|
||||
__block NSError *blockError = nil;
|
||||
@@ -381,16 +381,16 @@ std::unique_ptr<api::ble_v2::GattServer> BleMedium::StartGattServer(
|
||||
return std::make_unique<GattServer>(blockServer);
|
||||
}
|
||||
|
||||
std::unique_ptr<api::ble_v2::GattClient> BleMedium::ConnectToGattServer(
|
||||
api::ble_v2::BlePeripheral::UniqueId peripheral_id, api::ble_v2::TxPowerLevel tx_power_level,
|
||||
api::ble_v2::ClientGattConnectionCallback callback) {
|
||||
std::unique_ptr<api::ble::GattClient> BleMedium::ConnectToGattServer(
|
||||
api::ble::BlePeripheral::UniqueId peripheral_id, api::ble::TxPowerLevel tx_power_level,
|
||||
api::ble::ClientGattConnectionCallback callback) {
|
||||
id<GNCPeripheral> peripheral = peripherals_.Get(peripheral_id);
|
||||
if (!peripheral) {
|
||||
GNCLoggerError(@"[NEARBY] Failed to connect to Gatt server: peripheral is not found.");
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
api::ble_v2::ClientGattConnectionCallback thread_callback = {
|
||||
api::ble::ClientGattConnectionCallback thread_callback = {
|
||||
.on_characteristic_changed_cb =
|
||||
[this,
|
||||
call_on_characteristic_changed_cb = std::move(callback.on_characteristic_changed_cb)](
|
||||
@@ -409,7 +409,7 @@ std::unique_ptr<api::ble_v2::GattClient> BleMedium::ConnectToGattServer(
|
||||
});
|
||||
}};
|
||||
|
||||
__block api::ble_v2::ClientGattConnectionCallback blockCallback = std::move(thread_callback);
|
||||
__block api::ble::ClientGattConnectionCallback blockCallback = std::move(thread_callback);
|
||||
|
||||
dispatch_semaphore_t semaphore = dispatch_semaphore_create(0);
|
||||
__block GNCBLEGATTClient *blockClient = nil;
|
||||
@@ -440,7 +440,7 @@ std::unique_ptr<api::ble_v2::GattClient> BleMedium::ConnectToGattServer(
|
||||
}
|
||||
|
||||
// TODO(b/293336684): Old Weave code that need to be deleted once shared Weave is complete.
|
||||
std::unique_ptr<api::ble_v2::BleServerSocket> BleMedium::OpenServerSocket(
|
||||
std::unique_ptr<api::ble::BleServerSocket> BleMedium::OpenServerSocket(
|
||||
const std::string &service_id) {
|
||||
auto server_socket = std::make_unique<BleServerSocket>();
|
||||
__block auto server_socket_ptr = server_socket.get();
|
||||
@@ -512,7 +512,7 @@ std::unique_ptr<api::ble_v2::BleServerSocket> BleMedium::OpenServerSocket(
|
||||
return std::move(server_socket);
|
||||
}
|
||||
|
||||
std::unique_ptr<api::ble_v2::BleL2capServerSocket> BleMedium::OpenL2capServerSocket(
|
||||
std::unique_ptr<api::ble::BleL2capServerSocket> BleMedium::OpenL2capServerSocket(
|
||||
const std::string &service_id) {
|
||||
dispatch_semaphore_t semaphore = dispatch_semaphore_create(0);
|
||||
__block NSError *blockPSMPublishedError = nil;
|
||||
@@ -575,9 +575,9 @@ std::unique_ptr<api::ble_v2::BleL2capServerSocket> BleMedium::OpenL2capServerSoc
|
||||
|
||||
// TODO(b/290385712): Add support for @c cancellation_flag.
|
||||
// TODO(b/293336684): Old Weave code that need to be deleted once shared Weave is complete.
|
||||
std::unique_ptr<api::ble_v2::BleSocket> BleMedium::Connect(
|
||||
const std::string &service_id, api::ble_v2::TxPowerLevel tx_power_level,
|
||||
api::ble_v2::BlePeripheral::UniqueId peripheral_id, CancellationFlag *cancellation_flag) {
|
||||
std::unique_ptr<api::ble::BleSocket> BleMedium::Connect(
|
||||
const std::string &service_id, api::ble::TxPowerLevel tx_power_level,
|
||||
api::ble::BlePeripheral::UniqueId peripheral_id, CancellationFlag *cancellation_flag) {
|
||||
id<GNCPeripheral> peripheral = peripherals_.Get(peripheral_id);
|
||||
if (!peripheral) {
|
||||
GNCLoggerError(@"Failed to connect to Gatt server: peripheral is not found.");
|
||||
@@ -630,9 +630,9 @@ std::unique_ptr<api::ble_v2::BleSocket> BleMedium::Connect(
|
||||
return std::move(socket);
|
||||
}
|
||||
|
||||
std::unique_ptr<api::ble_v2::BleL2capSocket> BleMedium::ConnectOverL2cap(
|
||||
int psm, const std::string &service_id, api::ble_v2::TxPowerLevel tx_power_level,
|
||||
api::ble_v2::BlePeripheral::UniqueId peripheral_id, CancellationFlag *cancellation_flag) {
|
||||
std::unique_ptr<api::ble::BleL2capSocket> BleMedium::ConnectOverL2cap(
|
||||
int psm, const std::string &service_id, api::ble::TxPowerLevel tx_power_level,
|
||||
api::ble::BlePeripheral::UniqueId peripheral_id, CancellationFlag *cancellation_flag) {
|
||||
id<GNCPeripheral> peripheral = peripherals_.Get(peripheral_id);
|
||||
if (!peripheral) {
|
||||
GNCLoggerError(@"Failed to connect over L2CAP: peripheral is not found.");
|
||||
@@ -686,7 +686,7 @@ bool BleMedium::IsExtendedAdvertisementsAvailable() {
|
||||
return [medium_ supportsExtendedAdvertisements];
|
||||
}
|
||||
|
||||
std::optional<api::ble_v2::BlePeripheral::UniqueId> BleMedium::RetrieveBlePeripheralIdFromNativeId(
|
||||
std::optional<api::ble::BlePeripheral::UniqueId> BleMedium::RetrieveBlePeripheralIdFromNativeId(
|
||||
const std::string &ble_peripheral_native_id) {
|
||||
NSString *uuidString = [[NSString alloc] initWithUTF8String:ble_peripheral_native_id.c_str()];
|
||||
if (uuidString == nil) {
|
||||
@@ -736,7 +736,7 @@ void BleMedium::CleanUpExpiredAdvertisementPackets(NSDate *now) {
|
||||
}
|
||||
|
||||
bool BleMedium::ShouldReportAdvertisement(NSDate *now,
|
||||
api::ble_v2::BlePeripheral::UniqueId peripheral_id,
|
||||
api::ble::BlePeripheral::UniqueId peripheral_id,
|
||||
NSDictionary<CBUUID *, NSData *> *service_data) {
|
||||
absl::MutexLock lock(&advertisement_packets_mutex_);
|
||||
if (service_data == nil || service_data.count == 0) {
|
||||
@@ -768,21 +768,20 @@ bool BleMedium::ShouldReportAdvertisement(NSDate *now,
|
||||
return true;
|
||||
}
|
||||
|
||||
void BleMedium::AddAdvertisementPacketInfo(api::ble_v2::BlePeripheral::UniqueId peripheral_id,
|
||||
void BleMedium::AddAdvertisementPacketInfo(api::ble::BlePeripheral::UniqueId peripheral_id,
|
||||
NSDictionary<CBUUID *, NSData *> *service_data) {
|
||||
absl::MutexLock lock(&advertisement_packets_mutex_);
|
||||
advertisement_packets_map_[peripheral_id] = {[NSDate date], service_data};
|
||||
}
|
||||
|
||||
api::ble_v2::BlePeripheral::UniqueId BleMedium::PeripheralsMap::Add(id<GNCPeripheral> peripheral) {
|
||||
api::ble::BlePeripheral::UniqueId BleMedium::PeripheralsMap::Add(id<GNCPeripheral> peripheral) {
|
||||
absl::MutexLock lock(&mutex_);
|
||||
api::ble_v2::BlePeripheral::UniqueId peripheral_id = peripheral.identifier.hash;
|
||||
api::ble::BlePeripheral::UniqueId peripheral_id = peripheral.identifier.hash;
|
||||
peripherals_.insert({peripheral_id, peripheral});
|
||||
return peripheral_id;
|
||||
}
|
||||
|
||||
id<GNCPeripheral> BleMedium::PeripheralsMap::Get(
|
||||
api::ble_v2::BlePeripheral::UniqueId peripheral_id) {
|
||||
id<GNCPeripheral> BleMedium::PeripheralsMap::Get(api::ble::BlePeripheral::UniqueId peripheral_id) {
|
||||
absl::MutexLock lock(&mutex_);
|
||||
auto peripheral_it = peripherals_.find(peripheral_id);
|
||||
if (peripheral_it == peripherals_.end()) {
|
||||
|
||||
@@ -24,7 +24,7 @@
|
||||
|
||||
#include <string>
|
||||
|
||||
#include "internal/platform/implementation/ble_v2.h"
|
||||
#include "internal/platform/implementation/ble.h"
|
||||
|
||||
@protocol GNCPeripheral;
|
||||
|
||||
@@ -37,10 +37,10 @@ namespace apple {
|
||||
// Many times a CoreBluetooth peripheral is not available, namely, when the
|
||||
// remote device is a central. For these cases, an EmptyBlePeripheral should be
|
||||
// used instead.
|
||||
class BlePeripheral : public api::ble_v2::BlePeripheral {
|
||||
class BlePeripheral : public api::ble::BlePeripheral {
|
||||
public:
|
||||
// Returns a reference to a default BlePeripheral.
|
||||
static api::ble_v2::BlePeripheral& DefaultBlePeripheral();
|
||||
static api::ble::BlePeripheral& DefaultBlePeripheral();
|
||||
|
||||
explicit BlePeripheral(id<GNCPeripheral> peripheral);
|
||||
~BlePeripheral() override = default;
|
||||
|
||||
@@ -19,7 +19,7 @@
|
||||
|
||||
#include <string>
|
||||
|
||||
#include "internal/platform/implementation/ble_v2.h"
|
||||
#include "internal/platform/implementation/ble.h"
|
||||
|
||||
#import "internal/platform/implementation/apple/Mediums/BLE/GNCPeripheral.h"
|
||||
|
||||
@@ -29,11 +29,11 @@ namespace apple {
|
||||
#pragma mark - BlePeripheral
|
||||
|
||||
BlePeripheral::BlePeripheral(id<GNCPeripheral> peripheral)
|
||||
: api::ble_v2::BlePeripheral(peripheral.identifier.hash), peripheral_(peripheral) {}
|
||||
: api::ble::BlePeripheral(peripheral.identifier.hash), peripheral_(peripheral) {}
|
||||
|
||||
api::ble_v2::BlePeripheral& BlePeripheral::DefaultBlePeripheral() {
|
||||
static api::ble_v2::BlePeripheral* default_peripheral =
|
||||
new api::ble_v2::BlePeripheral(0xffffffffffffffff);
|
||||
api::ble::BlePeripheral& BlePeripheral::DefaultBlePeripheral() {
|
||||
static api::ble::BlePeripheral* default_peripheral =
|
||||
new api::ble::BlePeripheral(0xffffffffffffffff);
|
||||
return *default_peripheral;
|
||||
}
|
||||
|
||||
|
||||
@@ -12,12 +12,14 @@
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
// Note: File language is detected using heuristics. Many Objective-C++ headers are incorrectly
|
||||
// classified as C++ resulting in invalid linter errors. The use of "NSArray" and other Foundation
|
||||
// classes like "NSData", "NSDictionary" and "NSUUID" are highly weighted for Objective-C and
|
||||
// Objective-C++ scores. Oddly, "#import <Foundation/Foundation.h>" does not contribute any points.
|
||||
// This comment alone should be enough to trick the IDE in to believing this is actually some sort
|
||||
// of Objective-C file. See: cs/google3/devtools/search/lang/recognize_language_classifiers_data
|
||||
// Note: File language is detected using heuristics. Many Objective-C++ headers
|
||||
// are incorrectly classified as C++ resulting in invalid linter errors. The use
|
||||
// of "NSArray" and other Foundation classes like "NSData", "NSDictionary" and
|
||||
// "NSUUID" are highly weighted for Objective-C and Objective-C++ scores. Oddly,
|
||||
// "#import <Foundation/Foundation.h>" does not contribute any points. This
|
||||
// comment alone should be enough to trick the IDE in to believing this is
|
||||
// actually some sort of Objective-C file. See:
|
||||
// cs/google3/devtools/search/lang/recognize_language_classifiers_data
|
||||
|
||||
// TODO(b/293336684): Remove this file when shared Weave is complete.
|
||||
|
||||
@@ -27,15 +29,14 @@
|
||||
|
||||
#include "absl/functional/any_invocable.h"
|
||||
#include "internal/platform/exception.h"
|
||||
#include "internal/platform/implementation/ble_v2.h"
|
||||
|
||||
#import "internal/platform/implementation/apple/ble_socket.h"
|
||||
#include "internal/platform/implementation/ble.h"
|
||||
|
||||
namespace nearby {
|
||||
namespace apple {
|
||||
|
||||
// A BLE server socket for listening for incoming Weave sockets.
|
||||
class BleServerSocket : public api::ble_v2::BleServerSocket {
|
||||
class BleServerSocket : public api::ble::BleServerSocket {
|
||||
public:
|
||||
BleServerSocket() = default;
|
||||
~BleServerSocket() override;
|
||||
@@ -49,7 +50,7 @@ class BleServerSocket : public api::ble_v2::BleServerSocket {
|
||||
// On success, returns connected socket, ready to exchange data or nullptr on
|
||||
// error. Once error is reported, it is permanent, and ServerSocket must be
|
||||
// closed.
|
||||
std::unique_ptr<api::ble_v2::BleSocket> Accept() override
|
||||
std::unique_ptr<api::ble::BleSocket> Accept() override
|
||||
ABSL_LOCKS_EXCLUDED(mutex_);
|
||||
|
||||
// Close the server socket.
|
||||
|
||||
@@ -29,7 +29,7 @@ BleServerSocket::~BleServerSocket() {
|
||||
DoClose();
|
||||
}
|
||||
|
||||
std::unique_ptr<api::ble_v2::BleSocket> BleServerSocket::Accept() {
|
||||
std::unique_ptr<api::ble::BleSocket> BleServerSocket::Accept() {
|
||||
absl::MutexLock lock(&mutex_);
|
||||
while (!closed_ && pending_sockets_.empty()) {
|
||||
cond_.Wait(&mutex_);
|
||||
|
||||
@@ -25,7 +25,7 @@
|
||||
|
||||
#include <memory>
|
||||
|
||||
#include "internal/platform/implementation/ble_v2.h"
|
||||
#include "internal/platform/implementation/ble.h"
|
||||
|
||||
#import "internal/platform/implementation/apple/ble_peripheral.h"
|
||||
|
||||
@@ -88,13 +88,13 @@ class BleOutputStream : public OutputStream {
|
||||
};
|
||||
|
||||
// A BLE Weave socket.
|
||||
class BleSocket : public api::ble_v2::BleSocket {
|
||||
class BleSocket : public api::ble::BleSocket {
|
||||
public:
|
||||
explicit BleSocket(id<GNCMConnection> connection);
|
||||
|
||||
// The peripheral used to create the socket must outlive the socket or undefined behavior will
|
||||
// occur.
|
||||
BleSocket(id<GNCMConnection> connection, api::ble_v2::BlePeripheral::UniqueId peripheral_id);
|
||||
BleSocket(id<GNCMConnection> connection, api::ble::BlePeripheral::UniqueId peripheral_id);
|
||||
~BleSocket() override;
|
||||
|
||||
// Returns the InputStream of the BleSocket.
|
||||
@@ -116,7 +116,7 @@ class BleSocket : public api::ble_v2::BleSocket {
|
||||
|
||||
// Returns valid BlePeripheral pointer if there is a connection, and
|
||||
// nullptr otherwise.
|
||||
api::ble_v2::BlePeripheral::UniqueId GetRemotePeripheralId() override { return peripheral_id_; }
|
||||
api::ble::BlePeripheral::UniqueId GetRemotePeripheralId() override { return peripheral_id_; }
|
||||
|
||||
bool IsClosed() const ABSL_LOCKS_EXCLUDED(mutex_);
|
||||
|
||||
@@ -130,7 +130,7 @@ class BleSocket : public api::ble_v2::BleSocket {
|
||||
bool closed_ ABSL_GUARDED_BY(mutex_) = false;
|
||||
std::unique_ptr<BleInputStream> input_stream_;
|
||||
std::unique_ptr<BleOutputStream> output_stream_;
|
||||
api::ble_v2::BlePeripheral::UniqueId peripheral_id_;
|
||||
api::ble::BlePeripheral::UniqueId peripheral_id_;
|
||||
absl::AnyInvocable<void()> close_notifier_;
|
||||
};
|
||||
|
||||
|
||||
@@ -14,7 +14,7 @@
|
||||
|
||||
#import "internal/platform/implementation/apple/ble_socket.h"
|
||||
|
||||
#include "internal/platform/implementation/ble_v2.h"
|
||||
#include "internal/platform/implementation/ble.h"
|
||||
|
||||
#import "internal/platform/implementation/apple/Mediums/BLE/GNCMBleConnection.h"
|
||||
#import "internal/platform/implementation/apple/ble_peripheral.h"
|
||||
@@ -179,8 +179,7 @@ BleSocket::BleSocket(id<GNCMConnection> connection)
|
||||
output_stream_(new BleOutputStream(connection)),
|
||||
peripheral_id_(BlePeripheral::DefaultBlePeripheral().GetUniqueId()) {}
|
||||
|
||||
BleSocket::BleSocket(id<GNCMConnection> connection,
|
||||
api::ble_v2::BlePeripheral::UniqueId peripheral_id)
|
||||
BleSocket::BleSocket(id<GNCMConnection> connection, api::ble::BlePeripheral::UniqueId peripheral_id)
|
||||
: input_stream_(new BleInputStream()),
|
||||
output_stream_(new BleOutputStream(connection)),
|
||||
peripheral_id_(peripheral_id) {}
|
||||
|
||||
@@ -22,7 +22,7 @@
|
||||
#import <CoreBluetooth/CoreBluetooth.h>
|
||||
#import <Foundation/Foundation.h>
|
||||
|
||||
#include "internal/platform/implementation/ble_v2.h"
|
||||
#include "internal/platform/implementation/ble.h"
|
||||
|
||||
@class GNCBLEGATTCharacteristic;
|
||||
|
||||
@@ -36,25 +36,25 @@ CBUUID *CBUUID16FromCPP(const Uuid &uuid);
|
||||
CBUUID *CBUUID128FromCPP(const Uuid &uuid);
|
||||
|
||||
/** Converts a C++ write type enum to a CoreBluetooth write type. */
|
||||
CBCharacteristicWriteType CBCharacteristicWriteTypeFromCPP(api::ble_v2::GattClient::WriteType wt);
|
||||
CBCharacteristicWriteType CBCharacteristicWriteTypeFromCPP(api::ble::GattClient::WriteType wt);
|
||||
|
||||
/**
|
||||
* Converts a C++ permission enum to CoreBluetooth permissions.
|
||||
*
|
||||
/**
|
||||
* Converts a C++ permission enum to CoreBluetooth permissions.
|
||||
*
|
||||
* This conversion keeps multiple permission values intact.
|
||||
*/
|
||||
CBAttributePermissions CBAttributePermissionsFromCPP(api::ble_v2::GattCharacteristic::Permission p);
|
||||
CBAttributePermissions CBAttributePermissionsFromCPP(api::ble::GattCharacteristic::Permission p);
|
||||
|
||||
/**
|
||||
* Converts a C++ property enum to CoreBluetooth properties.
|
||||
*
|
||||
/**
|
||||
* Converts a C++ property enum to CoreBluetooth properties.
|
||||
*
|
||||
* This conversion keeps multiple property values intact.
|
||||
*/
|
||||
CBCharacteristicProperties CBCharacteristicPropertiesFromCPP(
|
||||
api::ble_v2::GattCharacteristic::Property p);
|
||||
api::ble::GattCharacteristic::Property p);
|
||||
|
||||
/** Converts a C++ characteristic to an Objective-C characteristic. */
|
||||
GNCBLEGATTCharacteristic *ObjCGATTCharacteristicFromCPP(const api::ble_v2::GattCharacteristic &c);
|
||||
GNCBLEGATTCharacteristic *ObjCGATTCharacteristicFromCPP(const api::ble::GattCharacteristic &c);
|
||||
|
||||
NSMutableDictionary<CBUUID *, NSData *> *ObjCServiceDataFromCPP(
|
||||
const absl::flat_hash_map<Uuid, nearby::ByteArray> &sd);
|
||||
@@ -62,24 +62,24 @@ NSMutableDictionary<CBUUID *, NSData *> *ObjCServiceDataFromCPP(
|
||||
/** Converts a 16 or 128 bit CoreBluetooth UUID to a C++ UUID. */
|
||||
Uuid CPPUUIDFromObjC(CBUUID *uuid);
|
||||
|
||||
/**
|
||||
* Converts CoreBluetooth permissions to a C++ permission enum.
|
||||
*
|
||||
/**
|
||||
* Converts CoreBluetooth permissions to a C++ permission enum.
|
||||
*
|
||||
* This conversion keeps multiple permission values intact.
|
||||
*/
|
||||
api::ble_v2::GattCharacteristic::Permission CPPGATTCharacteristicPermissionFromObjC(
|
||||
api::ble::GattCharacteristic::Permission CPPGATTCharacteristicPermissionFromObjC(
|
||||
CBAttributePermissions p);
|
||||
|
||||
/**
|
||||
* Converts CoreBluetooth properties to a C++ property enum.
|
||||
*
|
||||
/**
|
||||
* Converts CoreBluetooth properties to a C++ property enum.
|
||||
*
|
||||
* This conversion keeps multiple property values intact.
|
||||
*/
|
||||
api::ble_v2::GattCharacteristic::Property CPPGATTCharacteristicPropertyFromObjC(
|
||||
api::ble::GattCharacteristic::Property CPPGATTCharacteristicPropertyFromObjC(
|
||||
CBCharacteristicProperties p);
|
||||
|
||||
/** Converts an Objective-C characteristic to a C++ characteristic. */
|
||||
api::ble_v2::GattCharacteristic CPPGATTCharacteristicFromObjC(GNCBLEGATTCharacteristic *c);
|
||||
api::ble::GattCharacteristic CPPGATTCharacteristicFromObjC(GNCBLEGATTCharacteristic *c);
|
||||
|
||||
} // namespace apple
|
||||
} // namespace nearby
|
||||
|
||||
@@ -25,14 +25,14 @@
|
||||
namespace nearby {
|
||||
namespace apple {
|
||||
|
||||
using GattCharacteristic = api::ble_v2::GattCharacteristic;
|
||||
using Permission = api::ble_v2::GattCharacteristic::Permission;
|
||||
using Property = api::ble_v2::GattCharacteristic::Property;
|
||||
using WriteType = api::ble_v2::GattClient::WriteType;
|
||||
using GattCharacteristic = api::ble::GattCharacteristic;
|
||||
using Permission = api::ble::GattCharacteristic::Permission;
|
||||
using Property = api::ble::GattCharacteristic::Property;
|
||||
using WriteType = api::ble::GattClient::WriteType;
|
||||
|
||||
/**
|
||||
* Checks if enum `a` contains enum `b`
|
||||
*
|
||||
*
|
||||
* For example, `Contains(Permission::kRead | Permission::kWrite, Permission::kRead)` should return
|
||||
* `YES`.
|
||||
*/
|
||||
|
||||
@@ -16,19 +16,19 @@
|
||||
|
||||
#import <Foundation/Foundation.h>
|
||||
|
||||
#include <string>
|
||||
#include <memory>
|
||||
#include <string>
|
||||
|
||||
#include "absl/strings/string_view.h"
|
||||
#include "internal/base/files.h"
|
||||
#include "internal/platform/implementation/apple/awdl.h"
|
||||
#import "internal/platform/implementation/apple/Log/GNCLogger.h"
|
||||
#include "internal/platform/implementation/apple/atomic_boolean.h"
|
||||
#include "internal/platform/implementation/apple/atomic_uint32.h"
|
||||
#include "internal/platform/implementation/apple/awdl.h"
|
||||
#include "internal/platform/implementation/apple/ble.h"
|
||||
#include "internal/platform/implementation/apple/condition_variable.h"
|
||||
#include "internal/platform/implementation/apple/count_down_latch.h"
|
||||
#include "internal/platform/implementation/apple/device_info.h"
|
||||
#import "internal/platform/implementation/apple/Log/GNCLogger.h"
|
||||
#import "internal/platform/implementation/apple/multi_thread_executor.h"
|
||||
#include "internal/platform/implementation/apple/mutex.h"
|
||||
#include "internal/platform/implementation/apple/preferences_manager.h"
|
||||
@@ -172,7 +172,7 @@ std::unique_ptr<BluetoothClassicMedium> ImplementationPlatform::CreateBluetoothC
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
std::unique_ptr<ble_v2::BleMedium> ImplementationPlatform::CreateBleV2Medium(
|
||||
std::unique_ptr<ble::BleMedium> ImplementationPlatform::CreateBleMedium(
|
||||
api::BluetoothAdapter& adapter) {
|
||||
return std::make_unique<apple::BleMedium>();
|
||||
}
|
||||
@@ -256,7 +256,7 @@ absl::StatusOr<WebResponse> ImplementationPlatform::SendRequest(const WebRequest
|
||||
}
|
||||
if (blockData != nil) {
|
||||
// Body is not a UTF-8 encoded string and is just using `std::string` as a container for data.
|
||||
webResponse.body = std::string((char *)blockData.bytes, blockData.length);
|
||||
webResponse.body = std::string((char*)blockData.bytes, blockData.length);
|
||||
}
|
||||
return webResponse;
|
||||
}
|
||||
|
||||
@@ -12,8 +12,8 @@
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
#ifndef PLATFORM_API_BLE_V2_H_
|
||||
#define PLATFORM_API_BLE_V2_H_
|
||||
#ifndef PLATFORM_API_BLE_H_
|
||||
#define PLATFORM_API_BLE_H_
|
||||
|
||||
#include <algorithm>
|
||||
#include <cstdint>
|
||||
@@ -40,7 +40,7 @@
|
||||
|
||||
namespace nearby {
|
||||
namespace api {
|
||||
namespace ble_v2 {
|
||||
namespace ble {
|
||||
|
||||
// Coarse representation of power settings throughout all BLE operations.
|
||||
enum class TxPowerLevel {
|
||||
@@ -304,7 +304,7 @@ class GattServer {
|
||||
// Stops a GATT server.
|
||||
virtual void Stop() = 0;
|
||||
};
|
||||
// LINT.ThenChange(//depot/google3/third_party/nearby/internal/platform/ble_v2.h)
|
||||
// LINT.ThenChange(//depot/google3/third_party/nearby/internal/platform/ble.h)
|
||||
|
||||
// Callback for asynchronous events on the client side of a GATT connection.
|
||||
struct ClientGattConnectionCallback {
|
||||
@@ -641,8 +641,8 @@ class BleMedium {
|
||||
}
|
||||
};
|
||||
|
||||
} // namespace ble_v2
|
||||
} // namespace ble
|
||||
} // namespace api
|
||||
} // namespace nearby
|
||||
|
||||
#endif // PLATFORM_API_BLE_V2_H_
|
||||
#endif // PLATFORM_API_BLE_H_
|
||||
@@ -80,7 +80,7 @@ cc_library(
|
||||
testonly = True,
|
||||
srcs = [
|
||||
"awdl.cc",
|
||||
"ble_v2.cc",
|
||||
"ble.cc",
|
||||
"bluetooth_adapter.cc",
|
||||
"bluetooth_classic.cc",
|
||||
"credential_storage_impl.cc",
|
||||
@@ -90,7 +90,7 @@ cc_library(
|
||||
],
|
||||
hdrs = [
|
||||
"awdl.h",
|
||||
"ble_v2.h",
|
||||
"ble.h",
|
||||
"bluetooth_adapter.h",
|
||||
"bluetooth_classic.h",
|
||||
"credential_storage_impl.h",
|
||||
@@ -133,7 +133,7 @@ cc_test(
|
||||
name = "comm_test",
|
||||
srcs = [
|
||||
"awdl_test.cc",
|
||||
"ble_v2_test.cc",
|
||||
"ble_test.cc",
|
||||
],
|
||||
deps = [
|
||||
":comm",
|
||||
|
||||
+142
-142
@@ -12,7 +12,7 @@
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
#include "internal/platform/implementation/g3/ble_v2.h"
|
||||
#include "internal/platform/implementation/g3/ble.h"
|
||||
|
||||
#include <algorithm>
|
||||
#include <memory>
|
||||
@@ -34,7 +34,7 @@
|
||||
#include "internal/platform/cancellation_flag_listener.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/bluetooth_adapter.h"
|
||||
#include "internal/platform/implementation/g3/bluetooth_adapter.h"
|
||||
#include "internal/platform/logging.h"
|
||||
@@ -47,8 +47,8 @@ namespace g3 {
|
||||
|
||||
namespace {
|
||||
|
||||
using ::nearby::api::ble_v2::BleAdvertisementData;
|
||||
using ::nearby::api::ble_v2::TxPowerLevel;
|
||||
using ::nearby::api::ble::BleAdvertisementData;
|
||||
using ::nearby::api::ble::TxPowerLevel;
|
||||
|
||||
std::string TxPowerLevelToName(TxPowerLevel power_mode) {
|
||||
switch (power_mode) {
|
||||
@@ -67,21 +67,21 @@ std::string TxPowerLevelToName(TxPowerLevel power_mode) {
|
||||
|
||||
} // namespace
|
||||
|
||||
api::ble_v2::BlePeripheral::UniqueId BleV2Socket::GetRemotePeripheralId() {
|
||||
BleV2Socket* remote_socket = GetRemoteSocket();
|
||||
api::ble::BlePeripheral::UniqueId BleSocket::GetRemotePeripheralId() {
|
||||
BleSocket* remote_socket = GetRemoteSocket();
|
||||
if (remote_socket == nullptr || remote_socket->adapter_ == nullptr ||
|
||||
remote_socket->adapter_->GetBleV2Medium() == nullptr) {
|
||||
remote_socket->adapter_->GetBleMedium() == nullptr) {
|
||||
return 0LL;
|
||||
}
|
||||
BleV2Medium* medium =
|
||||
dynamic_cast<BleV2Medium*>(remote_socket->adapter_->GetBleV2Medium());
|
||||
BleMedium* medium =
|
||||
dynamic_cast<BleMedium*>(remote_socket->adapter_->GetBleMedium());
|
||||
if (medium == nullptr) {
|
||||
return 0LL;
|
||||
}
|
||||
return medium->GetAdapter().GetUniqueId();
|
||||
}
|
||||
|
||||
std::unique_ptr<api::ble_v2::BleSocket> BleV2ServerSocket::Accept() {
|
||||
std::unique_ptr<api::ble::BleSocket> BleServerSocket::Accept() {
|
||||
absl::MutexLock lock(mutex_);
|
||||
while (!closed_ && pending_sockets_.empty()) {
|
||||
cond_.Wait(&mutex_);
|
||||
@@ -92,14 +92,14 @@ std::unique_ptr<api::ble_v2::BleSocket> BleV2ServerSocket::Accept() {
|
||||
pending_sockets_.extract(pending_sockets_.begin()).value();
|
||||
CHECK(remote_socket);
|
||||
|
||||
auto local_socket = std::make_unique<BleV2Socket>(adapter_);
|
||||
auto local_socket = std::make_unique<BleSocket>(adapter_);
|
||||
local_socket->Connect(*remote_socket);
|
||||
remote_socket->Connect(*local_socket);
|
||||
cond_.SignalAll();
|
||||
return local_socket;
|
||||
}
|
||||
|
||||
bool BleV2ServerSocket::Connect(BleV2Socket& socket) {
|
||||
bool BleServerSocket::Connect(BleSocket& socket) {
|
||||
absl::MutexLock lock(mutex_);
|
||||
if (closed_) return false;
|
||||
if (socket.IsConnected()) {
|
||||
@@ -116,22 +116,22 @@ bool BleV2ServerSocket::Connect(BleV2Socket& socket) {
|
||||
return true;
|
||||
}
|
||||
|
||||
void BleV2ServerSocket::SetCloseNotifier(absl::AnyInvocable<void()> notifier) {
|
||||
void BleServerSocket::SetCloseNotifier(absl::AnyInvocable<void()> notifier) {
|
||||
absl::MutexLock lock(mutex_);
|
||||
close_notifier_ = std::move(notifier);
|
||||
}
|
||||
|
||||
BleV2ServerSocket::~BleV2ServerSocket() {
|
||||
BleServerSocket::~BleServerSocket() {
|
||||
absl::MutexLock lock(mutex_);
|
||||
DoClose();
|
||||
}
|
||||
|
||||
Exception BleV2ServerSocket::Close() {
|
||||
Exception BleServerSocket::Close() {
|
||||
absl::MutexLock lock(mutex_);
|
||||
return DoClose();
|
||||
}
|
||||
|
||||
Exception BleV2ServerSocket::DoClose() {
|
||||
Exception BleServerSocket::DoClose() {
|
||||
bool should_notify = !closed_;
|
||||
closed_ = true;
|
||||
if (should_notify) {
|
||||
@@ -148,24 +148,24 @@ Exception BleV2ServerSocket::DoClose() {
|
||||
return {Exception::kSuccess};
|
||||
}
|
||||
|
||||
BleV2Medium::BleV2Medium(BluetoothAdapter& adapter) : adapter_(adapter) {
|
||||
BleMedium::BleMedium(BluetoothAdapter& adapter) : adapter_(adapter) {
|
||||
CHECK(&adapter_);
|
||||
adapter_.SetBleV2Medium(this);
|
||||
adapter_.SetBleMedium(this);
|
||||
is_extended_advertisements_available_ =
|
||||
MediumEnvironment::Instance().IsBleExtendedAdvertisementsAvailable();
|
||||
|
||||
MediumEnvironment::Instance().RegisterBleV2Medium(*this,
|
||||
adapter_.GetUniqueId());
|
||||
MediumEnvironment::Instance().RegisterBleMedium(*this,
|
||||
adapter_.GetUniqueId());
|
||||
}
|
||||
|
||||
BleV2Medium::~BleV2Medium() {
|
||||
adapter_.SetBleV2Medium(nullptr);
|
||||
MediumEnvironment::Instance().UnregisterBleV2Medium(*this);
|
||||
BleMedium::~BleMedium() {
|
||||
adapter_.SetBleMedium(nullptr);
|
||||
MediumEnvironment::Instance().UnregisterBleMedium(*this);
|
||||
}
|
||||
|
||||
bool BleV2Medium::StartAdvertising(
|
||||
bool BleMedium::StartAdvertising(
|
||||
const BleAdvertisementData& advertising_data,
|
||||
api::ble_v2::AdvertiseParameters advertise_parameters) {
|
||||
api::ble::AdvertiseParameters advertise_parameters) {
|
||||
LOG(INFO)
|
||||
<< "G3 Ble StartAdvertising: advertising_data.is_extended_advertisement="
|
||||
<< advertising_data.is_extended_advertisement
|
||||
@@ -181,26 +181,26 @@ bool BleV2Medium::StartAdvertising(
|
||||
}
|
||||
|
||||
absl::MutexLock lock(mutex_);
|
||||
MediumEnvironment::Instance().UpdateBleV2MediumForAdvertising(
|
||||
MediumEnvironment::Instance().UpdateBleMediumForAdvertising(
|
||||
/*enabled=*/true, *this, adapter_.GetUniqueId(), advertising_data);
|
||||
return true;
|
||||
}
|
||||
|
||||
bool BleV2Medium::StopAdvertising() {
|
||||
bool BleMedium::StopAdvertising() {
|
||||
LOG(INFO) << "G3 Ble StopAdvertising";
|
||||
absl::MutexLock lock(mutex_);
|
||||
|
||||
BleAdvertisementData empty_advertisement_data = {};
|
||||
MediumEnvironment::Instance().UpdateBleV2MediumForAdvertising(
|
||||
MediumEnvironment::Instance().UpdateBleMediumForAdvertising(
|
||||
/*enabled=*/false, *this, adapter_.GetUniqueId(),
|
||||
empty_advertisement_data);
|
||||
return true;
|
||||
}
|
||||
|
||||
std::unique_ptr<BleV2Medium::AdvertisingSession> BleV2Medium::StartAdvertising(
|
||||
const api::ble_v2::BleAdvertisementData& advertising_data,
|
||||
api::ble_v2::AdvertiseParameters advertise_parameters,
|
||||
BleV2Medium::AdvertisingCallback callback) {
|
||||
std::unique_ptr<BleMedium::AdvertisingSession> BleMedium::StartAdvertising(
|
||||
const api::ble::BleAdvertisementData& advertising_data,
|
||||
api::ble::AdvertiseParameters advertise_parameters,
|
||||
BleMedium::AdvertisingCallback callback) {
|
||||
LOG(INFO)
|
||||
<< "G3 Ble StartAdvertising: advertising_data.is_extended_advertisement="
|
||||
<< advertising_data.is_extended_advertisement
|
||||
@@ -219,7 +219,7 @@ std::unique_ptr<BleV2Medium::AdvertisingSession> BleV2Medium::StartAdvertising(
|
||||
callback.start_advertising_result(absl::OkStatus());
|
||||
}
|
||||
absl::MutexLock lock(mutex_);
|
||||
MediumEnvironment::Instance().UpdateBleV2MediumForAdvertising(
|
||||
MediumEnvironment::Instance().UpdateBleMediumForAdvertising(
|
||||
/*enabled=*/true, *this, adapter_.GetUniqueId(), advertising_data);
|
||||
return std::make_unique<AdvertisingSession>(
|
||||
AdvertisingSession{.stop_advertising = [this] {
|
||||
@@ -229,13 +229,13 @@ std::unique_ptr<BleV2Medium::AdvertisingSession> BleV2Medium::StartAdvertising(
|
||||
}});
|
||||
}
|
||||
|
||||
bool BleV2Medium::StartScanning(const Uuid& service_uuid,
|
||||
TxPowerLevel tx_power_level,
|
||||
ScanCallback callback) {
|
||||
bool BleMedium::StartScanning(const Uuid& service_uuid,
|
||||
TxPowerLevel tx_power_level,
|
||||
ScanCallback callback) {
|
||||
LOG(INFO) << "G3 Ble StartScanning";
|
||||
auto internal_session_id = Prng().NextUint32();
|
||||
absl::MutexLock lock(mutex_);
|
||||
MediumEnvironment::Instance().UpdateBleV2MediumForScanning(
|
||||
MediumEnvironment::Instance().UpdateBleMediumForScanning(
|
||||
/*enabled=*/true, service_uuid, internal_session_id,
|
||||
{.advertisement_found_cb = std::move(callback.advertisement_found_cb)},
|
||||
*this);
|
||||
@@ -243,9 +243,9 @@ bool BleV2Medium::StartScanning(const Uuid& service_uuid,
|
||||
return true;
|
||||
}
|
||||
|
||||
bool BleV2Medium::StartMultipleServicesScanning(
|
||||
bool BleMedium::StartMultipleServicesScanning(
|
||||
const std::vector<Uuid>& service_uuids,
|
||||
api::ble_v2::TxPowerLevel tx_power_level, ScanCallback callback) {
|
||||
api::ble::TxPowerLevel tx_power_level, ScanCallback callback) {
|
||||
LOG(INFO) << "G3 Ble StartMultipleServicesScanning";
|
||||
|
||||
absl::MutexLock lock(mutex_);
|
||||
@@ -254,13 +254,13 @@ bool BleV2Medium::StartMultipleServicesScanning(
|
||||
auto internal_session_id = Prng().NextUint32();
|
||||
ScanCallback multiple_scan_callback = {
|
||||
.advertisement_found_cb =
|
||||
[this](api::ble_v2::BlePeripheral::UniqueId peripheral_id,
|
||||
[this](api::ble::BlePeripheral::UniqueId peripheral_id,
|
||||
BleAdvertisementData advertisement_data) {
|
||||
scan_callback_.advertisement_found_cb(peripheral_id,
|
||||
advertisement_data);
|
||||
}};
|
||||
|
||||
MediumEnvironment::Instance().UpdateBleV2MediumForScanning(
|
||||
MediumEnvironment::Instance().UpdateBleMediumForScanning(
|
||||
/*enabled=*/true, service_uuid, internal_session_id,
|
||||
{.advertisement_found_cb =
|
||||
std::move(multiple_scan_callback.advertisement_found_cb)},
|
||||
@@ -271,11 +271,11 @@ bool BleV2Medium::StartMultipleServicesScanning(
|
||||
return true;
|
||||
}
|
||||
|
||||
bool BleV2Medium::StopScanning() {
|
||||
bool BleMedium::StopScanning() {
|
||||
LOG(INFO) << "G3 Ble StopScanning";
|
||||
absl::MutexLock lock(mutex_);
|
||||
for (auto element : scanning_internal_session_ids_) {
|
||||
MediumEnvironment::Instance().UpdateBleV2MediumForScanning(
|
||||
MediumEnvironment::Instance().UpdateBleMediumForScanning(
|
||||
/*enabled=*/false,
|
||||
/*service_uuid=*/element.first,
|
||||
/*internal_session_id*/ element.second,
|
||||
@@ -284,16 +284,16 @@ bool BleV2Medium::StopScanning() {
|
||||
return true;
|
||||
}
|
||||
|
||||
std::unique_ptr<BleV2Medium::ScanningSession> BleV2Medium::StartScanning(
|
||||
std::unique_ptr<BleMedium::ScanningSession> BleMedium::StartScanning(
|
||||
const Uuid& service_uuid, TxPowerLevel tx_power_level,
|
||||
BleV2Medium::ScanningCallback callback) {
|
||||
BleMedium::ScanningCallback callback) {
|
||||
LOG(INFO) << "G3 Ble StartScanning";
|
||||
auto internal_session_id = Prng().NextUint32();
|
||||
|
||||
{
|
||||
absl::MutexLock lock(mutex_);
|
||||
|
||||
MediumEnvironment::Instance().UpdateBleV2MediumForScanning(
|
||||
MediumEnvironment::Instance().UpdateBleMediumForScanning(
|
||||
/*enabled=*/true, service_uuid, internal_session_id,
|
||||
std::move(callback), *this);
|
||||
scanning_internal_session_ids_.insert({service_uuid, internal_session_id});
|
||||
@@ -310,7 +310,7 @@ std::unique_ptr<BleV2Medium::ScanningSession> BleV2Medium::StartScanning(
|
||||
return absl::NotFoundError(
|
||||
"can't find the provided internal session");
|
||||
}
|
||||
MediumEnvironment::Instance().UpdateBleV2MediumForScanning(
|
||||
MediumEnvironment::Instance().UpdateBleMediumForScanning(
|
||||
/*enabled=*/false, service_uuid, internal_session_id,
|
||||
/*callback=*/{}, *this);
|
||||
scanning_internal_session_ids_.erase(
|
||||
@@ -320,25 +320,25 @@ std::unique_ptr<BleV2Medium::ScanningSession> BleV2Medium::StartScanning(
|
||||
});
|
||||
}
|
||||
|
||||
std::unique_ptr<api::ble_v2::GattServer> BleV2Medium::StartGattServer(
|
||||
api::ble_v2::ServerGattConnectionCallback callback) {
|
||||
std::unique_ptr<api::ble::GattServer> BleMedium::StartGattServer(
|
||||
api::ble::ServerGattConnectionCallback callback) {
|
||||
return std::make_unique<GattServer>(*this, std::move(callback));
|
||||
}
|
||||
|
||||
bool BleV2Medium::IsStopped(Borrowable<api::ble_v2::GattServer*> server) {
|
||||
bool BleMedium::IsStopped(Borrowable<api::ble::GattServer*> server) {
|
||||
auto borrowed = server.Borrow();
|
||||
if (!borrowed) {
|
||||
return true;
|
||||
}
|
||||
BleV2Medium::GattServer* gatt_server = static_cast<GattServer*>(*borrowed);
|
||||
BleMedium::GattServer* gatt_server = static_cast<GattServer*>(*borrowed);
|
||||
return gatt_server->IsStopped();
|
||||
}
|
||||
|
||||
std::unique_ptr<api::ble_v2::GattClient> BleV2Medium::ConnectToGattServer(
|
||||
api::ble_v2::BlePeripheral::UniqueId peripheral_id,
|
||||
std::unique_ptr<api::ble::GattClient> BleMedium::ConnectToGattServer(
|
||||
api::ble::BlePeripheral::UniqueId peripheral_id,
|
||||
TxPowerLevel tx_power_level,
|
||||
api::ble_v2::ClientGattConnectionCallback callback) {
|
||||
Borrowable<api::ble_v2::GattServer*> server =
|
||||
api::ble::ClientGattConnectionCallback callback) {
|
||||
Borrowable<api::ble::GattServer*> server =
|
||||
MediumEnvironment::Instance().GetGattServer(peripheral_id);
|
||||
if (IsStopped(server)) {
|
||||
LOG(WARNING) << "No GATT server found for " << peripheral_id;
|
||||
@@ -348,36 +348,36 @@ std::unique_ptr<api::ble_v2::GattClient> BleV2Medium::ConnectToGattServer(
|
||||
std::move(callback));
|
||||
}
|
||||
|
||||
bool BleV2Medium::IsExtendedAdvertisementsAvailable() {
|
||||
bool BleMedium::IsExtendedAdvertisementsAvailable() {
|
||||
return is_extended_advertisements_available_;
|
||||
}
|
||||
|
||||
BleV2Medium::GattServer::GattServer(
|
||||
BleV2Medium& medium, api::ble_v2::ServerGattConnectionCallback callback)
|
||||
BleMedium::GattServer::GattServer(
|
||||
BleMedium& medium, api::ble::ServerGattConnectionCallback callback)
|
||||
: medium_(medium), callback_(std::move(callback)) {
|
||||
BluetoothAdapter& adapter = medium.GetAdapter();
|
||||
MediumEnvironment::Instance().RegisterGattServer(
|
||||
medium_, adapter.GetUniqueId(), lender_.GetBorrowable());
|
||||
}
|
||||
|
||||
BleV2Medium::GattServer::~GattServer() {
|
||||
BleMedium::GattServer::~GattServer() {
|
||||
Stop();
|
||||
lender_.Release();
|
||||
MediumEnvironment::Instance().UnregisterGattServer(medium_);
|
||||
}
|
||||
std::optional<api::ble_v2::GattCharacteristic>
|
||||
BleV2Medium::GattServer::CreateCharacteristic(
|
||||
std::optional<api::ble::GattCharacteristic>
|
||||
BleMedium::GattServer::CreateCharacteristic(
|
||||
const Uuid& service_uuid, const Uuid& characteristic_uuid,
|
||||
api::ble_v2::GattCharacteristic::Permission permission,
|
||||
api::ble_v2::GattCharacteristic::Property property) {
|
||||
api::ble::GattCharacteristic::Permission permission,
|
||||
api::ble::GattCharacteristic::Property property) {
|
||||
absl::MutexLock lock(mutex_);
|
||||
api::ble_v2::GattCharacteristic characteristic = {
|
||||
.uuid = characteristic_uuid, .service_uuid = service_uuid};
|
||||
api::ble::GattCharacteristic characteristic = {.uuid = characteristic_uuid,
|
||||
.service_uuid = service_uuid};
|
||||
characteristics_[characteristic] = absl::NotFoundError("value not set");
|
||||
return characteristic;
|
||||
}
|
||||
|
||||
bool BleV2Medium::GattServer::DiscoverBleV2MediumGattCharacteristics(
|
||||
bool BleMedium::GattServer::DiscoverBleMediumGattCharacteristics(
|
||||
const Uuid& service_uuid, const std::vector<Uuid>& characteristic_uuids) {
|
||||
absl::MutexLock lock(mutex_);
|
||||
auto contains = [&](const Uuid& characteristic_uuid) {
|
||||
@@ -385,7 +385,7 @@ bool BleV2Medium::GattServer::DiscoverBleV2MediumGattCharacteristics(
|
||||
characteristic_uuid) != characteristic_uuids.end();
|
||||
};
|
||||
for (const auto& it : characteristics_) {
|
||||
const api::ble_v2::GattCharacteristic& characteristic = it.first;
|
||||
const api::ble::GattCharacteristic& characteristic = it.first;
|
||||
if (characteristic.service_uuid == service_uuid &&
|
||||
contains(characteristic.uuid)) {
|
||||
return true;
|
||||
@@ -394,8 +394,8 @@ bool BleV2Medium::GattServer::DiscoverBleV2MediumGattCharacteristics(
|
||||
return false;
|
||||
}
|
||||
|
||||
bool BleV2Medium::GattServer::UpdateCharacteristic(
|
||||
const api::ble_v2::GattCharacteristic& characteristic,
|
||||
bool BleMedium::GattServer::UpdateCharacteristic(
|
||||
const api::ble::GattCharacteristic& characteristic,
|
||||
const nearby::ByteArray& value) {
|
||||
absl::MutexLock lock(mutex_);
|
||||
LOG(INFO) << "G3 Ble GattServer UpdateCharacteristic, characteristic=("
|
||||
@@ -406,8 +406,8 @@ bool BleV2Medium::GattServer::UpdateCharacteristic(
|
||||
return true;
|
||||
}
|
||||
|
||||
absl::Status BleV2Medium::GattServer::NotifyCharacteristicChanged(
|
||||
const api::ble_v2::GattCharacteristic& characteristic, bool confirm,
|
||||
absl::Status BleMedium::GattServer::NotifyCharacteristicChanged(
|
||||
const api::ble::GattCharacteristic& characteristic, bool confirm,
|
||||
const ByteArray& new_value) {
|
||||
absl::MutexLock lock(mutex_);
|
||||
LOG(INFO) << "G3 Ble GattServer NotifyCharacteristicChanged, characteristic=("
|
||||
@@ -426,9 +426,9 @@ absl::Status BleV2Medium::GattServer::NotifyCharacteristicChanged(
|
||||
return status;
|
||||
}
|
||||
|
||||
absl::StatusOr<ByteArray> BleV2Medium::GattServer::ReadCharacteristic(
|
||||
const api::ble_v2::BlePeripheral::UniqueId remote_device_id,
|
||||
const api::ble_v2::GattCharacteristic& characteristic, int offset) {
|
||||
absl::StatusOr<ByteArray> BleMedium::GattServer::ReadCharacteristic(
|
||||
const api::ble::BlePeripheral::UniqueId remote_device_id,
|
||||
const api::ble::GattCharacteristic& characteristic, int offset) {
|
||||
{
|
||||
absl::MutexLock lock(mutex_);
|
||||
const auto it = characteristics_.find(characteristic);
|
||||
@@ -455,9 +455,9 @@ absl::StatusOr<ByteArray> BleV2Medium::GattServer::ReadCharacteristic(
|
||||
return result;
|
||||
}
|
||||
|
||||
absl::Status BleV2Medium::GattServer::WriteCharacteristic(
|
||||
const api::ble_v2::BlePeripheral::UniqueId remote_device_id,
|
||||
const api::ble_v2::GattCharacteristic& characteristic, int offset,
|
||||
absl::Status BleMedium::GattServer::WriteCharacteristic(
|
||||
const api::ble::BlePeripheral::UniqueId remote_device_id,
|
||||
const api::ble::GattCharacteristic& characteristic, int offset,
|
||||
absl::string_view data) {
|
||||
if (HasCharacteristic(characteristic)) {
|
||||
absl::Status result;
|
||||
@@ -475,9 +475,9 @@ absl::Status BleV2Medium::GattServer::WriteCharacteristic(
|
||||
absl::StrCat(characteristic, " not found"));
|
||||
}
|
||||
|
||||
bool BleV2Medium::GattServer::AddCharacteristicSubscription(
|
||||
const api::ble_v2::BlePeripheral::UniqueId remote_device_id,
|
||||
const api::ble_v2::GattCharacteristic& characteristic,
|
||||
bool BleMedium::GattServer::AddCharacteristicSubscription(
|
||||
const api::ble::BlePeripheral::UniqueId remote_device_id,
|
||||
const api::ble::GattCharacteristic& characteristic,
|
||||
absl::AnyInvocable<void(absl::string_view value)> callback) {
|
||||
absl::MutexLock lock(mutex_);
|
||||
const auto it = characteristics_.find(characteristic);
|
||||
@@ -489,9 +489,9 @@ bool BleV2Medium::GattServer::AddCharacteristicSubscription(
|
||||
return false;
|
||||
}
|
||||
|
||||
bool BleV2Medium::GattServer::RemoveCharacteristicSubscription(
|
||||
const api::ble_v2::BlePeripheral::UniqueId remote_device_id,
|
||||
const api::ble_v2::GattCharacteristic& characteristic) {
|
||||
bool BleMedium::GattServer::RemoveCharacteristicSubscription(
|
||||
const api::ble::BlePeripheral::UniqueId remote_device_id,
|
||||
const api::ble::GattCharacteristic& characteristic) {
|
||||
absl::MutexLock lock(mutex_);
|
||||
const auto it = characteristics_.find(characteristic);
|
||||
if (it != characteristics_.end()) {
|
||||
@@ -501,25 +501,25 @@ bool BleV2Medium::GattServer::RemoveCharacteristicSubscription(
|
||||
return false;
|
||||
}
|
||||
|
||||
bool BleV2Medium::GattServer::HasCharacteristic(
|
||||
const api::ble_v2::GattCharacteristic& characteristic) {
|
||||
bool BleMedium::GattServer::HasCharacteristic(
|
||||
const api::ble::GattCharacteristic& characteristic) {
|
||||
absl::MutexLock lock(mutex_);
|
||||
return characteristics_.find(characteristic) != characteristics_.end();
|
||||
}
|
||||
|
||||
void BleV2Medium::GattServer::Connect(GattClient* client) {
|
||||
void BleMedium::GattServer::Connect(GattClient* client) {
|
||||
absl::MutexLock lock(mutex_);
|
||||
connected_clients_.push_back(client);
|
||||
}
|
||||
|
||||
void BleV2Medium::GattServer::Disconnect(GattClient* client) {
|
||||
void BleMedium::GattServer::Disconnect(GattClient* client) {
|
||||
absl::MutexLock lock(mutex_);
|
||||
connected_clients_.erase(
|
||||
std::remove(connected_clients_.begin(), connected_clients_.end(), client),
|
||||
connected_clients_.end());
|
||||
}
|
||||
|
||||
void BleV2Medium::GattServer::Stop() {
|
||||
void BleMedium::GattServer::Stop() {
|
||||
if (stopped_) return;
|
||||
absl::MutexLock lock(mutex_);
|
||||
stopped_ = true;
|
||||
@@ -529,31 +529,31 @@ void BleV2Medium::GattServer::Stop() {
|
||||
characteristics_.clear();
|
||||
}
|
||||
|
||||
BleV2Medium::GattClient::GattClient(
|
||||
api::ble_v2::BlePeripheral::UniqueId peripheral_id,
|
||||
Borrowable<api::ble_v2::GattServer*> gatt_server,
|
||||
api::ble_v2::ClientGattConnectionCallback callback)
|
||||
BleMedium::GattClient::GattClient(
|
||||
api::ble::BlePeripheral::UniqueId peripheral_id,
|
||||
Borrowable<api::ble::GattServer*> gatt_server,
|
||||
api::ble::ClientGattConnectionCallback callback)
|
||||
: peripheral_id_(peripheral_id),
|
||||
gatt_server_(gatt_server),
|
||||
callback_(std::move(callback)) {
|
||||
Borrowed<api::ble_v2::GattServer*> borrowed = gatt_server_.Borrow();
|
||||
Borrowed<api::ble::GattServer*> borrowed = gatt_server_.Borrow();
|
||||
if (borrowed) {
|
||||
BleV2Medium::GattServer* gatt_server =
|
||||
static_cast<BleV2Medium::GattServer*>(*borrowed);
|
||||
BleMedium::GattServer* gatt_server =
|
||||
static_cast<BleMedium::GattServer*>(*borrowed);
|
||||
gatt_server->Connect(this);
|
||||
}
|
||||
}
|
||||
|
||||
BleV2Medium::GattClient::~GattClient() {
|
||||
Borrowed<api::ble_v2::GattServer*> borrowed = gatt_server_.Borrow();
|
||||
BleMedium::GattClient::~GattClient() {
|
||||
Borrowed<api::ble::GattServer*> borrowed = gatt_server_.Borrow();
|
||||
if (borrowed) {
|
||||
BleV2Medium::GattServer* gatt_server =
|
||||
static_cast<BleV2Medium::GattServer*>(*borrowed);
|
||||
BleMedium::GattServer* gatt_server =
|
||||
static_cast<BleMedium::GattServer*>(*borrowed);
|
||||
gatt_server->Disconnect(this);
|
||||
}
|
||||
}
|
||||
|
||||
bool BleV2Medium::GattClient::DiscoverServiceAndCharacteristics(
|
||||
bool BleMedium::GattClient::DiscoverServiceAndCharacteristics(
|
||||
const Uuid& service_uuid, const std::vector<Uuid>& characteristic_uuids) {
|
||||
LOG(INFO)
|
||||
<< "G3 Ble GattClient DiscoverServiceAndCharacteristics, service_uuid="
|
||||
@@ -562,19 +562,19 @@ bool BleV2Medium::GattClient::DiscoverServiceAndCharacteristics(
|
||||
if (!is_connection_alive_) {
|
||||
return false;
|
||||
}
|
||||
Borrowed<api::ble_v2::GattServer*> borrowed = gatt_server_.Borrow();
|
||||
Borrowed<api::ble::GattServer*> borrowed = gatt_server_.Borrow();
|
||||
if (!borrowed) {
|
||||
return false;
|
||||
}
|
||||
BleV2Medium::GattServer* gatt_server =
|
||||
static_cast<BleV2Medium::GattServer*>(*borrowed);
|
||||
return gatt_server->DiscoverBleV2MediumGattCharacteristics(
|
||||
BleMedium::GattServer* gatt_server =
|
||||
static_cast<BleMedium::GattServer*>(*borrowed);
|
||||
return gatt_server->DiscoverBleMediumGattCharacteristics(
|
||||
service_uuid, characteristic_uuids);
|
||||
}
|
||||
|
||||
std::optional<api::ble_v2::GattCharacteristic>
|
||||
BleV2Medium::GattClient::GetCharacteristic(const Uuid& service_uuid,
|
||||
const Uuid& characteristic_uuid) {
|
||||
std::optional<api::ble::GattCharacteristic>
|
||||
BleMedium::GattClient::GetCharacteristic(const Uuid& service_uuid,
|
||||
const Uuid& characteristic_uuid) {
|
||||
absl::MutexLock lock(mutex_);
|
||||
LOG(INFO) << "G3 Ble GattClient GetCharacteristic, service_uuid="
|
||||
<< service_uuid.Get16BitAsString()
|
||||
@@ -583,16 +583,16 @@ BleV2Medium::GattClient::GetCharacteristic(const Uuid& service_uuid,
|
||||
return std::nullopt;
|
||||
}
|
||||
// clang-format off
|
||||
api::ble_v2::GattCharacteristic characteristic = {
|
||||
api::ble::GattCharacteristic characteristic = {
|
||||
.uuid = characteristic_uuid,
|
||||
.service_uuid = service_uuid};
|
||||
// clang-format on
|
||||
Borrowed<api::ble_v2::GattServer*> borrowed = gatt_server_.Borrow();
|
||||
Borrowed<api::ble::GattServer*> borrowed = gatt_server_.Borrow();
|
||||
if (!borrowed) {
|
||||
return std::nullopt;
|
||||
}
|
||||
BleV2Medium::GattServer* gatt_server =
|
||||
static_cast<BleV2Medium::GattServer*>(*borrowed);
|
||||
BleMedium::GattServer* gatt_server =
|
||||
static_cast<BleMedium::GattServer*>(*borrowed);
|
||||
if (!gatt_server->HasCharacteristic(characteristic)) {
|
||||
LOG(WARNING) << "G3 Ble GattClient GetCharacteristic, characteristic=("
|
||||
<< characteristic.service_uuid.Get16BitAsString() << ","
|
||||
@@ -607,18 +607,18 @@ BleV2Medium::GattClient::GetCharacteristic(const Uuid& service_uuid,
|
||||
return characteristic;
|
||||
}
|
||||
|
||||
std::optional<std::string> BleV2Medium::GattClient::ReadCharacteristic(
|
||||
const api::ble_v2::GattCharacteristic& characteristic) {
|
||||
std::optional<std::string> BleMedium::GattClient::ReadCharacteristic(
|
||||
const api::ble::GattCharacteristic& characteristic) {
|
||||
absl::MutexLock lock(mutex_);
|
||||
if (!is_connection_alive_) {
|
||||
return std::nullopt;
|
||||
}
|
||||
Borrowed<api::ble_v2::GattServer*> borrowed = gatt_server_.Borrow();
|
||||
Borrowed<api::ble::GattServer*> borrowed = gatt_server_.Borrow();
|
||||
if (!borrowed) {
|
||||
return std::nullopt;
|
||||
}
|
||||
BleV2Medium::GattServer* gatt_server =
|
||||
static_cast<BleV2Medium::GattServer*>(*borrowed);
|
||||
BleMedium::GattServer* gatt_server =
|
||||
static_cast<BleMedium::GattServer*>(*borrowed);
|
||||
absl::StatusOr<ByteArray> value =
|
||||
gatt_server->ReadCharacteristic(peripheral_id_, characteristic,
|
||||
/*offset=*/0);
|
||||
@@ -635,19 +635,19 @@ std::optional<std::string> BleV2Medium::GattClient::ReadCharacteristic(
|
||||
return value->string_data();
|
||||
}
|
||||
|
||||
bool BleV2Medium::GattClient::WriteCharacteristic(
|
||||
const api::ble_v2::GattCharacteristic& characteristic,
|
||||
absl::string_view value, api::ble_v2::GattClient::WriteType write_type) {
|
||||
bool BleMedium::GattClient::WriteCharacteristic(
|
||||
const api::ble::GattCharacteristic& characteristic, absl::string_view value,
|
||||
api::ble::GattClient::WriteType write_type) {
|
||||
absl::MutexLock lock(mutex_);
|
||||
if (!is_connection_alive_) {
|
||||
return false;
|
||||
}
|
||||
Borrowed<api::ble_v2::GattServer*> borrowed = gatt_server_.Borrow();
|
||||
Borrowed<api::ble::GattServer*> borrowed = gatt_server_.Borrow();
|
||||
if (!borrowed) {
|
||||
return false;
|
||||
}
|
||||
BleV2Medium::GattServer* gatt_server =
|
||||
static_cast<BleV2Medium::GattServer*>(*borrowed);
|
||||
BleMedium::GattServer* gatt_server =
|
||||
static_cast<BleMedium::GattServer*>(*borrowed);
|
||||
LOG(INFO) << "G3 Ble WriteCharacteristic, characteristic=("
|
||||
<< characteristic.service_uuid.Get16BitAsString() << ","
|
||||
<< std::string(characteristic.uuid)
|
||||
@@ -661,20 +661,20 @@ bool BleV2Medium::GattClient::WriteCharacteristic(
|
||||
return status.ok();
|
||||
}
|
||||
|
||||
bool BleV2Medium::GattClient::SetCharacteristicSubscription(
|
||||
const api::ble_v2::GattCharacteristic& characteristic, bool enable,
|
||||
bool BleMedium::GattClient::SetCharacteristicSubscription(
|
||||
const api::ble::GattCharacteristic& characteristic, bool enable,
|
||||
absl::AnyInvocable<void(absl::string_view value)>
|
||||
on_characteristic_changed_cb) {
|
||||
absl::MutexLock lock(mutex_);
|
||||
if (!is_connection_alive_) {
|
||||
return false;
|
||||
}
|
||||
Borrowed<api::ble_v2::GattServer*> borrowed = gatt_server_.Borrow();
|
||||
Borrowed<api::ble::GattServer*> borrowed = gatt_server_.Borrow();
|
||||
if (!borrowed) {
|
||||
return false;
|
||||
}
|
||||
BleV2Medium::GattServer* gatt_server =
|
||||
static_cast<BleV2Medium::GattServer*>(*borrowed);
|
||||
BleMedium::GattServer* gatt_server =
|
||||
static_cast<BleMedium::GattServer*>(*borrowed);
|
||||
LOG(INFO) << "G3 Ble SetCharacteristicSubscription, characteristic=("
|
||||
<< characteristic.service_uuid.Get16BitAsString() << ","
|
||||
<< std::string(characteristic.uuid) << "), enable = " << enable;
|
||||
@@ -688,19 +688,19 @@ bool BleV2Medium::GattClient::SetCharacteristicSubscription(
|
||||
}
|
||||
}
|
||||
|
||||
void BleV2Medium::GattClient::Disconnect() {
|
||||
void BleMedium::GattClient::Disconnect() {
|
||||
bool was_alive = is_connection_alive_.exchange(false);
|
||||
if (!was_alive) return;
|
||||
LOG(INFO) << "G3 Ble GattClient Disconnect";
|
||||
Borrowed<api::ble_v2::GattServer*> borrowed = gatt_server_.Borrow();
|
||||
Borrowed<api::ble::GattServer*> borrowed = gatt_server_.Borrow();
|
||||
if (borrowed) {
|
||||
BleV2Medium::GattServer* gatt_server =
|
||||
static_cast<BleV2Medium::GattServer*>(*borrowed);
|
||||
BleMedium::GattServer* gatt_server =
|
||||
static_cast<BleMedium::GattServer*>(*borrowed);
|
||||
gatt_server->Disconnect(this);
|
||||
}
|
||||
}
|
||||
|
||||
void BleV2Medium::GattClient::OnServerDisconnected() {
|
||||
void BleMedium::GattClient::OnServerDisconnected() {
|
||||
bool was_alive = is_connection_alive_.exchange(false);
|
||||
if (!was_alive) return;
|
||||
LOG(INFO) << "G3 Ble GattServer disconnected";
|
||||
@@ -709,9 +709,9 @@ void BleV2Medium::GattClient::OnServerDisconnected() {
|
||||
}
|
||||
}
|
||||
|
||||
std::unique_ptr<api::ble_v2::BleServerSocket> BleV2Medium::OpenServerSocket(
|
||||
std::unique_ptr<api::ble::BleServerSocket> BleMedium::OpenServerSocket(
|
||||
const std::string& service_id) {
|
||||
auto server_socket = std::make_unique<BleV2ServerSocket>(&GetAdapter());
|
||||
auto server_socket = std::make_unique<BleServerSocket>(&GetAdapter());
|
||||
server_socket->SetCloseNotifier([this, service_id]() {
|
||||
absl::MutexLock lock(mutex_);
|
||||
server_sockets_.erase(service_id);
|
||||
@@ -723,29 +723,29 @@ std::unique_ptr<api::ble_v2::BleServerSocket> BleV2Medium::OpenServerSocket(
|
||||
return server_socket;
|
||||
}
|
||||
|
||||
std::unique_ptr<api::ble_v2::BleL2capServerSocket>
|
||||
BleV2Medium::OpenL2capServerSocket(const std::string& service_id) {
|
||||
std::unique_ptr<api::ble::BleL2capServerSocket>
|
||||
BleMedium::OpenL2capServerSocket(const std::string& service_id) {
|
||||
// TODO(mingshiouwu): add more codes for g3 testing.
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
std::unique_ptr<api::ble_v2::BleSocket> BleV2Medium::Connect(
|
||||
std::unique_ptr<api::ble::BleSocket> BleMedium::Connect(
|
||||
const std::string& service_id, TxPowerLevel tx_power_level,
|
||||
api::ble_v2::BlePeripheral::UniqueId remote_peripheral_id,
|
||||
api::ble::BlePeripheral::UniqueId remote_peripheral_id,
|
||||
CancellationFlag* cancellation_flag) {
|
||||
LOG(INFO) << "G3 Ble Connect [self]: medium=" << this
|
||||
<< ", adapter=" << &GetAdapter()
|
||||
<< ", peripheral id=" << adapter_.GetUniqueId()
|
||||
<< ", service_id=" << service_id;
|
||||
// First, find an instance of remote medium, that exposed this peripheral.
|
||||
BleV2Medium* remote_medium = dynamic_cast<BleV2Medium*>(
|
||||
MediumEnvironment::Instance().FindBleV2Medium(remote_peripheral_id));
|
||||
BleMedium* remote_medium = dynamic_cast<BleMedium*>(
|
||||
MediumEnvironment::Instance().FindBleMedium(remote_peripheral_id));
|
||||
if (remote_medium == nullptr) {
|
||||
LOG(INFO) << "Peripheral not found, id= " << remote_peripheral_id;
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
BleV2ServerSocket* remote_server_socket = nullptr;
|
||||
BleServerSocket* remote_server_socket = nullptr;
|
||||
LOG(INFO) << "G3 Ble Connect [peer]: medium=" << remote_medium
|
||||
<< ", peripheral=" << &remote_peripheral_id
|
||||
<< ", service_id=" << service_id;
|
||||
@@ -777,7 +777,7 @@ std::unique_ptr<api::ble_v2::BleSocket> BleV2Medium::Connect(
|
||||
}
|
||||
});
|
||||
|
||||
auto socket = std::make_unique<BleV2Socket>(&GetAdapter());
|
||||
auto socket = std::make_unique<BleSocket>(&GetAdapter());
|
||||
// Finally, Request to connect to this socket.
|
||||
if (!remote_server_socket->Connect(*socket)) {
|
||||
LOG(ERROR) << "G3 Ble Failed to connect to existing Ble "
|
||||
+81
-84
@@ -12,8 +12,8 @@
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
#ifndef PLATFORM_IMPL_G3_BLE_V2_H_
|
||||
#define PLATFORM_IMPL_G3_BLE_V2_H_
|
||||
#ifndef PLATFORM_IMPL_G3_BLE_H_
|
||||
#define PLATFORM_IMPL_G3_BLE_H_
|
||||
|
||||
#include <atomic>
|
||||
#include <cstdint>
|
||||
@@ -35,7 +35,7 @@
|
||||
#include "internal/platform/byte_array.h"
|
||||
#include "internal/platform/cancellation_flag.h"
|
||||
#include "internal/platform/exception.h"
|
||||
#include "internal/platform/implementation/ble_v2.h"
|
||||
#include "internal/platform/implementation/ble.h"
|
||||
#include "internal/platform/implementation/bluetooth_adapter.h"
|
||||
#include "internal/platform/implementation/g3/bluetooth_adapter.h"
|
||||
#include "internal/platform/implementation/g3/socket_base.h"
|
||||
@@ -46,9 +46,9 @@
|
||||
namespace nearby {
|
||||
namespace g3 {
|
||||
|
||||
class BleV2Socket : public api::ble_v2::BleSocket, public SocketBase {
|
||||
class BleSocket : public api::ble::BleSocket, public SocketBase {
|
||||
public:
|
||||
explicit BleV2Socket(BluetoothAdapter* adapter) : adapter_(adapter) {}
|
||||
explicit BleSocket(BluetoothAdapter* adapter) : adapter_(adapter) {}
|
||||
|
||||
// Returns the InputStream of this connected BleSocket.
|
||||
InputStream& GetInputStream() override {
|
||||
@@ -62,28 +62,28 @@ class BleV2Socket : public api::ble_v2::BleSocket, public SocketBase {
|
||||
}
|
||||
|
||||
// Returns address of a remote BleSocket or nullptr.
|
||||
BleV2Socket* GetRemoteSocket() {
|
||||
return static_cast<BleV2Socket*>(SocketBase::GetRemoteSocket());
|
||||
BleSocket* GetRemoteSocket() {
|
||||
return static_cast<BleSocket*>(SocketBase::GetRemoteSocket());
|
||||
}
|
||||
|
||||
// Returns Exception::kIo on error, Exception::kSuccess otherwise.
|
||||
Exception Close() override { return SocketBase::Close(); }
|
||||
|
||||
api::ble_v2::BlePeripheral::UniqueId GetRemotePeripheralId() override
|
||||
api::ble::BlePeripheral::UniqueId GetRemotePeripheralId() override
|
||||
ABSL_LOCKS_EXCLUDED(mutex_);
|
||||
|
||||
private:
|
||||
BluetoothAdapter* adapter_ = nullptr; // Our Adapter. Read only.
|
||||
};
|
||||
|
||||
class BleV2ServerSocket : public api::ble_v2::BleServerSocket {
|
||||
class BleServerSocket : public api::ble::BleServerSocket {
|
||||
public:
|
||||
explicit BleV2ServerSocket(BluetoothAdapter* adapter) : adapter_(adapter) {}
|
||||
BleV2ServerSocket(const BleV2ServerSocket&) = default;
|
||||
BleV2ServerSocket& operator=(const BleV2ServerSocket&) = default;
|
||||
BleV2ServerSocket(BleV2ServerSocket&&) = default;
|
||||
BleV2ServerSocket& operator=(BleV2ServerSocket&&) = default;
|
||||
~BleV2ServerSocket() override;
|
||||
explicit BleServerSocket(BluetoothAdapter* adapter) : adapter_(adapter) {}
|
||||
BleServerSocket(const BleServerSocket&) = default;
|
||||
BleServerSocket& operator=(const BleServerSocket&) = default;
|
||||
BleServerSocket(BleServerSocket&&) = default;
|
||||
BleServerSocket& operator=(BleServerSocket&&) = default;
|
||||
~BleServerSocket() override;
|
||||
|
||||
// Blocks until either:
|
||||
// - at least one incoming connection request is available, or
|
||||
@@ -95,7 +95,7 @@ class BleV2ServerSocket : public api::ble_v2::BleServerSocket {
|
||||
// Called by the server side of a connection.
|
||||
// Returns BleSocket to the server side.
|
||||
// If not null, returned socket is connected to its remote (client-side) peer.
|
||||
std::unique_ptr<api::ble_v2::BleSocket> Accept() override
|
||||
std::unique_ptr<api::ble::BleSocket> Accept() override
|
||||
ABSL_LOCKS_EXCLUDED(mutex_);
|
||||
|
||||
// Blocks until either:
|
||||
@@ -105,7 +105,7 @@ class BleV2ServerSocket : public api::ble_v2::BleServerSocket {
|
||||
//
|
||||
// Called by the client side of a connection.
|
||||
// Returns true, if socket is successfully connected.
|
||||
bool Connect(BleV2Socket& socket) ABSL_LOCKS_EXCLUDED(mutex_);
|
||||
bool Connect(BleSocket& socket) ABSL_LOCKS_EXCLUDED(mutex_);
|
||||
|
||||
// Called by the server side of a connection before passing ownership of
|
||||
// BleServerSocker to user, to track validity of a pointer to this
|
||||
@@ -123,67 +123,66 @@ class BleV2ServerSocket : public api::ble_v2::BleServerSocket {
|
||||
mutable absl::Mutex mutex_;
|
||||
absl::CondVar cond_;
|
||||
BluetoothAdapter* adapter_ = nullptr; // Our Adapter. Read only.
|
||||
absl::flat_hash_set<BleV2Socket*> pending_sockets_ ABSL_GUARDED_BY(mutex_);
|
||||
absl::flat_hash_set<BleSocket*> pending_sockets_ ABSL_GUARDED_BY(mutex_);
|
||||
absl::AnyInvocable<void()> close_notifier_ ABSL_GUARDED_BY(mutex_);
|
||||
bool closed_ ABSL_GUARDED_BY(mutex_) = false;
|
||||
};
|
||||
|
||||
// Container of operations that can be performed over the BLE medium.
|
||||
class BleV2Medium : public api::ble_v2::BleMedium {
|
||||
class BleMedium : public api::ble::BleMedium {
|
||||
public:
|
||||
explicit BleV2Medium(BluetoothAdapter& adapter);
|
||||
~BleV2Medium() override;
|
||||
explicit BleMedium(BluetoothAdapter& adapter);
|
||||
~BleMedium() override;
|
||||
|
||||
// Returns true once the Ble advertising has been initiated.
|
||||
bool StartAdvertising(
|
||||
const api::ble_v2::BleAdvertisementData& advertising_data,
|
||||
api::ble_v2::AdvertiseParameters advertise_parameters) override
|
||||
ABSL_LOCKS_EXCLUDED(mutex_);
|
||||
bool StartAdvertising(const api::ble::BleAdvertisementData& advertising_data,
|
||||
api::ble::AdvertiseParameters advertise_parameters)
|
||||
override ABSL_LOCKS_EXCLUDED(mutex_);
|
||||
bool StopAdvertising() override ABSL_LOCKS_EXCLUDED(mutex_);
|
||||
|
||||
std::unique_ptr<AdvertisingSession> StartAdvertising(
|
||||
const api::ble_v2::BleAdvertisementData& advertising_data,
|
||||
api::ble_v2::AdvertiseParameters advertise_parameters,
|
||||
const api::ble::BleAdvertisementData& advertising_data,
|
||||
api::ble::AdvertiseParameters advertise_parameters,
|
||||
AdvertisingCallback callback) override ABSL_LOCKS_EXCLUDED(mutex_);
|
||||
|
||||
bool StartScanning(const Uuid& service_uuid,
|
||||
api::ble_v2::TxPowerLevel tx_power_level,
|
||||
api::ble::TxPowerLevel tx_power_level,
|
||||
ScanCallback callback) override
|
||||
ABSL_LOCKS_EXCLUDED(mutex_);
|
||||
bool StartMultipleServicesScanning(const std::vector<Uuid>& service_uuids,
|
||||
api::ble_v2::TxPowerLevel tx_power_level,
|
||||
ScanCallback callback)
|
||||
override ABSL_LOCKS_EXCLUDED(mutex_);
|
||||
api::ble::TxPowerLevel tx_power_level,
|
||||
ScanCallback callback) override
|
||||
ABSL_LOCKS_EXCLUDED(mutex_);
|
||||
bool StopScanning() override ABSL_LOCKS_EXCLUDED(mutex_);
|
||||
std::unique_ptr<ScanningSession> StartScanning(
|
||||
const Uuid& service_uuid, api::ble_v2::TxPowerLevel tx_power_level,
|
||||
const Uuid& service_uuid, api::ble::TxPowerLevel tx_power_level,
|
||||
ScanningCallback callback) override ABSL_LOCKS_EXCLUDED(mutex_);
|
||||
std::unique_ptr<api::ble_v2::GattServer> StartGattServer(
|
||||
api::ble_v2::ServerGattConnectionCallback callback) override
|
||||
std::unique_ptr<api::ble::GattServer> StartGattServer(
|
||||
api::ble::ServerGattConnectionCallback callback) override
|
||||
ABSL_LOCKS_EXCLUDED(mutex_);
|
||||
std::unique_ptr<api::ble_v2::GattClient> ConnectToGattServer(
|
||||
api::ble_v2::BlePeripheral::UniqueId peripheral_id,
|
||||
api::ble_v2::TxPowerLevel tx_power_level,
|
||||
api::ble_v2::ClientGattConnectionCallback callback) override
|
||||
std::unique_ptr<api::ble::GattClient> ConnectToGattServer(
|
||||
api::ble::BlePeripheral::UniqueId peripheral_id,
|
||||
api::ble::TxPowerLevel tx_power_level,
|
||||
api::ble::ClientGattConnectionCallback callback) override
|
||||
ABSL_LOCKS_EXCLUDED(mutex_);
|
||||
|
||||
// Open server socket to listen for incoming connection.
|
||||
//
|
||||
// On success, returns a new BleServerSocket.
|
||||
// On error, returns nullptr.
|
||||
std::unique_ptr<api::ble_v2::BleServerSocket> OpenServerSocket(
|
||||
std::unique_ptr<api::ble::BleServerSocket> OpenServerSocket(
|
||||
const std::string& service_id) override ABSL_LOCKS_EXCLUDED(mutex_);
|
||||
|
||||
std::unique_ptr<api::ble_v2::BleL2capServerSocket> OpenL2capServerSocket(
|
||||
std::unique_ptr<api::ble::BleL2capServerSocket> OpenL2capServerSocket(
|
||||
const std::string& service_id) override ABSL_LOCKS_EXCLUDED(mutex_);
|
||||
|
||||
// Connects to existing remote Ble peripheral.
|
||||
//
|
||||
// On success, returns a new BleSocket.
|
||||
// On error, returns nullptr.
|
||||
std::unique_ptr<api::ble_v2::BleSocket> Connect(
|
||||
const std::string& service_id, api::ble_v2::TxPowerLevel tx_power_level,
|
||||
api::ble_v2::BlePeripheral::UniqueId remote_peripheral_id,
|
||||
std::unique_ptr<api::ble::BleSocket> Connect(
|
||||
const std::string& service_id, api::ble::TxPowerLevel tx_power_level,
|
||||
api::ble::BlePeripheral::UniqueId remote_peripheral_id,
|
||||
CancellationFlag* cancellation_flag) override ABSL_LOCKS_EXCLUDED(mutex_);
|
||||
|
||||
bool IsExtendedAdvertisementsAvailable() override;
|
||||
@@ -193,96 +192,94 @@ class BleV2Medium : public api::ble_v2::BleMedium {
|
||||
private:
|
||||
class GattClient;
|
||||
// A concrete implementation for GattServer.
|
||||
class GattServer : public api::ble_v2::GattServer {
|
||||
class GattServer : public api::ble::GattServer {
|
||||
public:
|
||||
GattServer(BleV2Medium& medium,
|
||||
api::ble_v2::ServerGattConnectionCallback callback);
|
||||
GattServer(BleMedium& medium,
|
||||
api::ble::ServerGattConnectionCallback callback);
|
||||
~GattServer() override;
|
||||
|
||||
std::optional<api::ble_v2::GattCharacteristic> CreateCharacteristic(
|
||||
std::optional<api::ble::GattCharacteristic> CreateCharacteristic(
|
||||
const Uuid& service_uuid, const Uuid& characteristic_uuid,
|
||||
api::ble_v2::GattCharacteristic::Permission permission,
|
||||
api::ble_v2::GattCharacteristic::Property property) override;
|
||||
api::ble::GattCharacteristic::Permission permission,
|
||||
api::ble::GattCharacteristic::Property property) override;
|
||||
|
||||
bool UpdateCharacteristic(
|
||||
const api::ble_v2::GattCharacteristic& characteristic,
|
||||
const api::ble::GattCharacteristic& characteristic,
|
||||
const nearby::ByteArray& value) override;
|
||||
|
||||
absl::Status NotifyCharacteristicChanged(
|
||||
const api::ble_v2::GattCharacteristic& characteristic, bool confirm,
|
||||
const api::ble::GattCharacteristic& characteristic, bool confirm,
|
||||
const ByteArray& new_value) override;
|
||||
|
||||
void Stop() override;
|
||||
bool IsStopped() { return stopped_; }
|
||||
bool DiscoverBleV2MediumGattCharacteristics(
|
||||
bool DiscoverBleMediumGattCharacteristics(
|
||||
const Uuid& service_uuid,
|
||||
const std::vector<Uuid>& characteristic_uuids);
|
||||
|
||||
absl::StatusOr<ByteArray> ReadCharacteristic(
|
||||
api::ble_v2::BlePeripheral::UniqueId remote_device_id,
|
||||
const api::ble_v2::GattCharacteristic& characteristic, int offset);
|
||||
api::ble::BlePeripheral::UniqueId remote_device_id,
|
||||
const api::ble::GattCharacteristic& characteristic, int offset);
|
||||
|
||||
absl::Status WriteCharacteristic(
|
||||
api::ble_v2::BlePeripheral::UniqueId remote_device_id,
|
||||
const api::ble_v2::GattCharacteristic& characteristic, int offset,
|
||||
api::ble::BlePeripheral::UniqueId remote_device_id,
|
||||
const api::ble::GattCharacteristic& characteristic, int offset,
|
||||
absl::string_view data);
|
||||
|
||||
bool AddCharacteristicSubscription(
|
||||
api::ble_v2::BlePeripheral::UniqueId remote_device_id,
|
||||
const api::ble_v2::GattCharacteristic& characteristic,
|
||||
api::ble::BlePeripheral::UniqueId remote_device_id,
|
||||
const api::ble::GattCharacteristic& characteristic,
|
||||
absl::AnyInvocable<void(absl::string_view value)>);
|
||||
bool RemoveCharacteristicSubscription(
|
||||
api::ble_v2::BlePeripheral::UniqueId remote_device_id,
|
||||
const api::ble_v2::GattCharacteristic& characteristic);
|
||||
api::ble::BlePeripheral::UniqueId remote_device_id,
|
||||
const api::ble::GattCharacteristic& characteristic);
|
||||
|
||||
bool HasCharacteristic(
|
||||
const api::ble_v2::GattCharacteristic& characteristic);
|
||||
bool HasCharacteristic(const api::ble::GattCharacteristic& characteristic);
|
||||
|
||||
void Connect(GattClient* client);
|
||||
void Disconnect(GattClient* client);
|
||||
|
||||
private:
|
||||
using SubscriberKey = std::pair<const api::ble_v2::BlePeripheral::UniqueId,
|
||||
api::ble_v2::GattCharacteristic>;
|
||||
using SubscriberKey = std::pair<const api::ble::BlePeripheral::UniqueId,
|
||||
api::ble::GattCharacteristic>;
|
||||
using SubscriberCallback =
|
||||
absl::AnyInvocable<void(absl::string_view value)>;
|
||||
absl::Mutex mutex_;
|
||||
BleV2Medium& medium_;
|
||||
api::ble_v2::ServerGattConnectionCallback callback_;
|
||||
absl::flat_hash_map<api::ble_v2::GattCharacteristic,
|
||||
absl::StatusOr<ByteArray>>
|
||||
BleMedium& medium_;
|
||||
api::ble::ServerGattConnectionCallback callback_;
|
||||
absl::flat_hash_map<api::ble::GattCharacteristic, absl::StatusOr<ByteArray>>
|
||||
characteristics_ ABSL_GUARDED_BY(mutex_);
|
||||
absl::flat_hash_map<SubscriberKey, SubscriberCallback> subscribers_
|
||||
ABSL_GUARDED_BY(mutex_);
|
||||
std::vector<GattClient*> connected_clients_ ABSL_GUARDED_BY(mutex_);
|
||||
std::atomic_bool stopped_ = false;
|
||||
Lender<api::ble_v2::GattServer*> lender_{this};
|
||||
Lender<api::ble::GattServer*> lender_{this};
|
||||
};
|
||||
|
||||
// A concrete implementation for GattClient.
|
||||
class GattClient : public api::ble_v2::GattClient {
|
||||
class GattClient : public api::ble::GattClient {
|
||||
public:
|
||||
GattClient(api::ble_v2::BlePeripheral::UniqueId peripheral_id,
|
||||
Borrowable<api::ble_v2::GattServer*> gatt_server,
|
||||
api::ble_v2::ClientGattConnectionCallback callback);
|
||||
GattClient(api::ble::BlePeripheral::UniqueId peripheral_id,
|
||||
Borrowable<api::ble::GattServer*> gatt_server,
|
||||
api::ble::ClientGattConnectionCallback callback);
|
||||
~GattClient() override;
|
||||
bool DiscoverServiceAndCharacteristics(
|
||||
const Uuid& service_uuid,
|
||||
const std::vector<Uuid>& characteristic_uuids) override;
|
||||
|
||||
std::optional<api::ble_v2::GattCharacteristic> GetCharacteristic(
|
||||
std::optional<api::ble::GattCharacteristic> GetCharacteristic(
|
||||
const Uuid& service_uuid, const Uuid& characteristic_uuid) override;
|
||||
|
||||
std::optional<std::string> ReadCharacteristic(
|
||||
const api::ble_v2::GattCharacteristic& characteristic) override;
|
||||
const api::ble::GattCharacteristic& characteristic) override;
|
||||
|
||||
bool WriteCharacteristic(
|
||||
const api::ble_v2::GattCharacteristic& characteristic,
|
||||
const api::ble::GattCharacteristic& characteristic,
|
||||
absl::string_view value,
|
||||
api::ble_v2::GattClient::WriteType write_type) override;
|
||||
api::ble::GattClient::WriteType write_type) override;
|
||||
|
||||
bool SetCharacteristicSubscription(
|
||||
const api::ble_v2::GattCharacteristic& characteristic, bool enable,
|
||||
const api::ble::GattCharacteristic& characteristic, bool enable,
|
||||
absl::AnyInvocable<void(absl::string_view value)>
|
||||
on_characteristic_changed_cb) override;
|
||||
|
||||
@@ -297,15 +294,15 @@ class BleV2Medium : public api::ble_v2::BleMedium {
|
||||
// disconnected/*false*/, the instance needs to be created again to bring
|
||||
// it alive.
|
||||
std::atomic_bool is_connection_alive_ = true;
|
||||
api::ble_v2::BlePeripheral::UniqueId peripheral_id_;
|
||||
Borrowable<api::ble_v2::GattServer*> gatt_server_;
|
||||
api::ble_v2::ClientGattConnectionCallback callback_;
|
||||
api::ble::BlePeripheral::UniqueId peripheral_id_;
|
||||
Borrowable<api::ble::GattServer*> gatt_server_;
|
||||
api::ble::ClientGattConnectionCallback callback_;
|
||||
};
|
||||
|
||||
bool IsStopped(Borrowable<api::ble_v2::GattServer*> server);
|
||||
bool IsStopped(Borrowable<api::ble::GattServer*> server);
|
||||
absl::Mutex mutex_;
|
||||
BluetoothAdapter& adapter_; // Our device adapter; read-only.
|
||||
absl::flat_hash_map<std::string, BleV2ServerSocket*> server_sockets_
|
||||
absl::flat_hash_map<std::string, BleServerSocket*> server_sockets_
|
||||
ABSL_GUARDED_BY(mutex_);
|
||||
absl::flat_hash_set<std::pair<Uuid, std::uint32_t>>
|
||||
scanning_internal_session_ids_ ABSL_GUARDED_BY(mutex_);
|
||||
@@ -316,4 +313,4 @@ class BleV2Medium : public api::ble_v2::BleMedium {
|
||||
} // namespace g3
|
||||
} // namespace nearby
|
||||
|
||||
#endif // PLATFORM_IMPL_G3_BLE_V2_H_
|
||||
#endif // PLATFORM_IMPL_G3_BLE_H_
|
||||
+43
-45
@@ -12,7 +12,7 @@
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
#include "internal/platform/implementation/g3/ble_v2.h"
|
||||
#include "internal/platform/implementation/g3/ble.h"
|
||||
|
||||
#include <string>
|
||||
|
||||
@@ -22,7 +22,7 @@
|
||||
#include "absl/status/status.h"
|
||||
#include "absl/strings/string_view.h"
|
||||
#include "internal/platform/byte_array.h"
|
||||
#include "internal/platform/implementation/ble_v2.h"
|
||||
#include "internal/platform/implementation/ble.h"
|
||||
#include "internal/platform/implementation/bluetooth_adapter.h"
|
||||
#include "internal/platform/implementation/g3/bluetooth_adapter.h"
|
||||
#include "internal/platform/uuid.h"
|
||||
@@ -53,117 +53,115 @@ class MockBluetoothAdapter : public BluetoothAdapter {
|
||||
MOCK_METHOD(api::BluetoothAdapter::ScanMode, GetScanMode, (),
|
||||
(const, override));
|
||||
MOCK_METHOD(int, GetNumSlots, (), (const));
|
||||
MOCK_METHOD(api::ble_v2::BlePeripheral::UniqueId, GetUniqueId, (), (const));
|
||||
MOCK_METHOD(void, SetBleV2Medium, (api::ble_v2::BleMedium * medium));
|
||||
MOCK_METHOD(api::ble::BlePeripheral::UniqueId, GetUniqueId, (), (const));
|
||||
MOCK_METHOD(void, SetBleMedium, (api::ble::BleMedium * medium));
|
||||
};
|
||||
|
||||
TEST(BleV2MediumTest, StartAdvertising) {
|
||||
TEST(BleMediumTest, StartAdvertising) {
|
||||
MockBluetoothAdapter mock_bluetooth_adapter;
|
||||
EXPECT_CALL(mock_bluetooth_adapter, IsEnabled()).WillRepeatedly(Return(true));
|
||||
|
||||
BleV2Medium ble_v2_medium(mock_bluetooth_adapter);
|
||||
api::ble_v2::BleAdvertisementData advertising_data;
|
||||
BleMedium ble_medium(mock_bluetooth_adapter);
|
||||
api::ble::BleAdvertisementData advertising_data;
|
||||
advertising_data.is_extended_advertisement = false;
|
||||
advertising_data.service_data.insert(
|
||||
{Uuid(kTestUuid), ByteArray("test_service_data")});
|
||||
|
||||
auto advertising_session = ble_v2_medium.StartAdvertising(
|
||||
auto advertising_session = ble_medium.StartAdvertising(
|
||||
advertising_data,
|
||||
{.tx_power_level = api::ble_v2::TxPowerLevel::kLow,
|
||||
.is_connectable = true},
|
||||
api::ble_v2::BleMedium::AdvertisingCallback{
|
||||
{.tx_power_level = api::ble::TxPowerLevel::kLow, .is_connectable = true},
|
||||
api::ble::BleMedium::AdvertisingCallback{
|
||||
.start_advertising_result = [](absl::Status) {},
|
||||
});
|
||||
EXPECT_TRUE(advertising_session != nullptr);
|
||||
}
|
||||
|
||||
TEST(BleV2MediumTest, StopAdvertising) {
|
||||
TEST(BleMediumTest, StopAdvertising) {
|
||||
MockBluetoothAdapter mock_bluetooth_adapter;
|
||||
EXPECT_CALL(mock_bluetooth_adapter, IsEnabled()).WillRepeatedly(Return(true));
|
||||
|
||||
BleV2Medium ble_v2_medium(mock_bluetooth_adapter);
|
||||
EXPECT_TRUE(ble_v2_medium.StopAdvertising());
|
||||
BleMedium ble_medium(mock_bluetooth_adapter);
|
||||
EXPECT_TRUE(ble_medium.StopAdvertising());
|
||||
}
|
||||
|
||||
TEST(BleV2MediumTest, StartScanning) {
|
||||
TEST(BleMediumTest, StartScanning) {
|
||||
MockBluetoothAdapter mock_bluetooth_adapter;
|
||||
EXPECT_CALL(mock_bluetooth_adapter, IsEnabled()).WillRepeatedly(Return(true));
|
||||
|
||||
BleV2Medium ble_v2_medium(mock_bluetooth_adapter);
|
||||
auto scanning_session = ble_v2_medium.StartScanning(
|
||||
Uuid(kTestUuid), api::ble_v2::TxPowerLevel::kLow,
|
||||
api::ble_v2::BleMedium::ScanningCallback{
|
||||
BleMedium ble_medium(mock_bluetooth_adapter);
|
||||
auto scanning_session = ble_medium.StartScanning(
|
||||
Uuid(kTestUuid), api::ble::TxPowerLevel::kLow,
|
||||
api::ble::BleMedium::ScanningCallback{
|
||||
.start_scanning_result = [](absl::Status) {},
|
||||
.advertisement_found_cb = [](api::ble_v2::BlePeripheral::UniqueId,
|
||||
api::ble_v2::BleAdvertisementData) {},
|
||||
.advertisement_found_cb = [](api::ble::BlePeripheral::UniqueId,
|
||||
api::ble::BleAdvertisementData) {},
|
||||
});
|
||||
EXPECT_TRUE(scanning_session != nullptr);
|
||||
}
|
||||
|
||||
TEST(BleV2MediumTest, StopScanning) {
|
||||
TEST(BleMediumTest, StopScanning) {
|
||||
MockBluetoothAdapter mock_bluetooth_adapter;
|
||||
EXPECT_CALL(mock_bluetooth_adapter, IsEnabled()).WillRepeatedly(Return(true));
|
||||
|
||||
BleV2Medium ble_v2_medium(mock_bluetooth_adapter);
|
||||
EXPECT_TRUE(ble_v2_medium.StopScanning());
|
||||
BleMedium ble_medium(mock_bluetooth_adapter);
|
||||
EXPECT_TRUE(ble_medium.StopScanning());
|
||||
}
|
||||
|
||||
TEST(BleV2MediumTest, StartGattServer) {
|
||||
TEST(BleMediumTest, StartGattServer) {
|
||||
MockBluetoothAdapter mock_bluetooth_adapter;
|
||||
EXPECT_CALL(mock_bluetooth_adapter, IsEnabled()).WillRepeatedly(Return(true));
|
||||
|
||||
BleV2Medium ble_v2_medium(mock_bluetooth_adapter);
|
||||
auto gatt_server = ble_v2_medium.StartGattServer({});
|
||||
BleMedium ble_medium(mock_bluetooth_adapter);
|
||||
auto gatt_server = ble_medium.StartGattServer({});
|
||||
EXPECT_TRUE(gatt_server != nullptr);
|
||||
}
|
||||
|
||||
TEST(BleV2MediumTest, ConnectToGattServer) {
|
||||
TEST(BleMediumTest, ConnectToGattServer) {
|
||||
MockBluetoothAdapter mock_bluetooth_adapter;
|
||||
EXPECT_CALL(mock_bluetooth_adapter, IsEnabled()).WillRepeatedly(Return(true));
|
||||
|
||||
BleV2Medium ble_v2_medium(mock_bluetooth_adapter);
|
||||
auto gatt_client = ble_v2_medium.ConnectToGattServer(
|
||||
/*peripheral_id=*/1234, api::ble_v2::TxPowerLevel::kLow, {});
|
||||
BleMedium ble_medium(mock_bluetooth_adapter);
|
||||
auto gatt_client = ble_medium.ConnectToGattServer(
|
||||
/*peripheral_id=*/1234, api::ble::TxPowerLevel::kLow, {});
|
||||
EXPECT_TRUE(gatt_client == nullptr);
|
||||
}
|
||||
|
||||
TEST(BleV2MediumTest, OpenServerSocket) {
|
||||
TEST(BleMediumTest, OpenServerSocket) {
|
||||
MockBluetoothAdapter mock_bluetooth_adapter;
|
||||
EXPECT_CALL(mock_bluetooth_adapter, IsEnabled()).WillRepeatedly(Return(true));
|
||||
|
||||
BleV2Medium ble_v2_medium(mock_bluetooth_adapter);
|
||||
auto server_socket =
|
||||
ble_v2_medium.OpenServerSocket(std::string(kTestServiceId));
|
||||
BleMedium ble_medium(mock_bluetooth_adapter);
|
||||
auto server_socket = ble_medium.OpenServerSocket(std::string(kTestServiceId));
|
||||
EXPECT_TRUE(server_socket != nullptr);
|
||||
}
|
||||
|
||||
TEST(BleV2MediumTest, Connect) {
|
||||
TEST(BleMediumTest, Connect) {
|
||||
MockBluetoothAdapter mock_bluetooth_adapter;
|
||||
EXPECT_CALL(mock_bluetooth_adapter, IsEnabled()).WillRepeatedly(Return(true));
|
||||
|
||||
BleV2Medium ble_v2_medium(mock_bluetooth_adapter);
|
||||
auto socket = ble_v2_medium.Connect(
|
||||
std::string(kTestServiceId), api::ble_v2::TxPowerLevel::kLow,
|
||||
BleMedium ble_medium(mock_bluetooth_adapter);
|
||||
auto socket = ble_medium.Connect(
|
||||
std::string(kTestServiceId), api::ble::TxPowerLevel::kLow,
|
||||
/*remote_peripheral_id=*/1234, /*cancellation_flag=*/nullptr);
|
||||
EXPECT_TRUE(socket == nullptr);
|
||||
}
|
||||
|
||||
TEST(BleV2MediumTest, OpenL2capServerSocket) {
|
||||
TEST(BleMediumTest, OpenL2capServerSocket) {
|
||||
MockBluetoothAdapter mock_bluetooth_adapter;
|
||||
EXPECT_CALL(mock_bluetooth_adapter, IsEnabled()).WillRepeatedly(Return(true));
|
||||
|
||||
BleV2Medium ble_v2_medium(mock_bluetooth_adapter);
|
||||
BleMedium ble_medium(mock_bluetooth_adapter);
|
||||
auto server_socket =
|
||||
ble_v2_medium.OpenL2capServerSocket(std::string(kTestServiceId));
|
||||
ble_medium.OpenL2capServerSocket(std::string(kTestServiceId));
|
||||
EXPECT_TRUE(server_socket == nullptr);
|
||||
}
|
||||
|
||||
TEST(BleV2MediumTest, IsExtendedAdvertisementsAvailable) {
|
||||
TEST(BleMediumTest, IsExtendedAdvertisementsAvailable) {
|
||||
MockBluetoothAdapter mock_bluetooth_adapter;
|
||||
EXPECT_CALL(mock_bluetooth_adapter, IsEnabled()).WillRepeatedly(Return(true));
|
||||
|
||||
BleV2Medium ble_v2_medium(mock_bluetooth_adapter);
|
||||
EXPECT_FALSE(ble_v2_medium.IsExtendedAdvertisementsAvailable());
|
||||
BleMedium ble_medium(mock_bluetooth_adapter);
|
||||
EXPECT_FALSE(ble_medium.IsExtendedAdvertisementsAvailable());
|
||||
}
|
||||
|
||||
} // namespace
|
||||
@@ -20,7 +20,7 @@
|
||||
|
||||
#include "absl/strings/string_view.h"
|
||||
#include "absl/synchronization/mutex.h"
|
||||
#include "internal/platform/implementation/ble_v2.h"
|
||||
#include "internal/platform/implementation/ble.h"
|
||||
#include "internal/platform/implementation/bluetooth_classic.h"
|
||||
#include "internal/platform/mac_address.h"
|
||||
#include "internal/platform/medium_environment.h"
|
||||
@@ -60,8 +60,8 @@ void BluetoothAdapter::SetBluetoothClassicMedium(
|
||||
bluetooth_classic_medium_ = medium;
|
||||
}
|
||||
|
||||
void BluetoothAdapter::SetBleV2Medium(api::ble_v2::BleMedium* medium) {
|
||||
ble_v2_medium_ = medium;
|
||||
void BluetoothAdapter::SetBleMedium(api::ble::BleMedium* medium) {
|
||||
ble_medium_ = medium;
|
||||
}
|
||||
|
||||
bool BluetoothAdapter::SetStatus(Status status) {
|
||||
|
||||
@@ -21,7 +21,7 @@
|
||||
#include "absl/base/thread_annotations.h"
|
||||
#include "absl/strings/string_view.h"
|
||||
#include "absl/synchronization/mutex.h"
|
||||
#include "internal/platform/implementation/ble_v2.h"
|
||||
#include "internal/platform/implementation/ble.h"
|
||||
#include "internal/platform/implementation/bluetooth_adapter.h"
|
||||
#include "internal/platform/implementation/bluetooth_classic.h"
|
||||
#include "internal/platform/mac_address.h"
|
||||
@@ -89,7 +89,7 @@ class BluetoothAdapter : public api::BluetoothAdapter {
|
||||
|
||||
// Returns BT MAC address assigned to this adapter.
|
||||
std::string GetMacAddress() const override { return mac_address_.ToString(); }
|
||||
MacAddress GetAddress() const override { return mac_address_; }
|
||||
MacAddress GetAddress() const override { return mac_address_; }
|
||||
|
||||
BluetoothDevice& GetDevice() { return device_; }
|
||||
|
||||
@@ -98,12 +98,10 @@ class BluetoothAdapter : public api::BluetoothAdapter {
|
||||
return bluetooth_classic_medium_;
|
||||
}
|
||||
|
||||
void SetBleV2Medium(api::ble_v2::BleMedium* medium);
|
||||
api::ble_v2::BleMedium* GetBleV2Medium() { return ble_v2_medium_; }
|
||||
void SetBleMedium(api::ble::BleMedium* medium);
|
||||
api::ble::BleMedium* GetBleMedium() { return ble_medium_; }
|
||||
|
||||
void SetMacAddress(MacAddress mac_address) {
|
||||
mac_address_ = mac_address;
|
||||
}
|
||||
void SetMacAddress(MacAddress mac_address) { mac_address_ = mac_address; }
|
||||
|
||||
std::uint64_t GetUniqueId() { return unique_id_; }
|
||||
|
||||
@@ -111,7 +109,7 @@ class BluetoothAdapter : public api::BluetoothAdapter {
|
||||
mutable absl::Mutex mutex_;
|
||||
BluetoothDevice device_{this};
|
||||
api::BluetoothClassicMedium* bluetooth_classic_medium_ = nullptr;
|
||||
api::ble_v2::BleMedium* ble_v2_medium_ = nullptr;
|
||||
api::ble::BleMedium* ble_medium_ = nullptr;
|
||||
MacAddress mac_address_;
|
||||
ScanMode mode_ ABSL_GUARDED_BY(mutex_) = ScanMode::kNone;
|
||||
std::string name_ ABSL_GUARDED_BY(mutex_) = "unknown G3 BT device";
|
||||
|
||||
@@ -29,7 +29,7 @@
|
||||
#include "internal/platform/implementation/atomic_boolean.h"
|
||||
#include "internal/platform/implementation/atomic_reference.h"
|
||||
#include "internal/platform/implementation/awdl.h"
|
||||
#include "internal/platform/implementation/ble_v2.h"
|
||||
#include "internal/platform/implementation/ble.h"
|
||||
#include "internal/platform/implementation/bluetooth_adapter.h"
|
||||
#include "internal/platform/implementation/bluetooth_classic.h"
|
||||
#include "internal/platform/implementation/condition_variable.h"
|
||||
@@ -61,7 +61,7 @@
|
||||
#endif
|
||||
#include "internal/platform/implementation/g3/atomic_boolean.h"
|
||||
#include "internal/platform/implementation/g3/atomic_reference.h"
|
||||
#include "internal/platform/implementation/g3/ble_v2.h"
|
||||
#include "internal/platform/implementation/g3/ble.h"
|
||||
#include "internal/platform/implementation/g3/bluetooth_adapter.h"
|
||||
#include "internal/platform/implementation/g3/bluetooth_classic.h"
|
||||
#include "internal/platform/implementation/g3/condition_variable.h"
|
||||
@@ -185,9 +185,9 @@ ImplementationPlatform::CreateBluetoothClassicMedium(
|
||||
return std::make_unique<g3::BluetoothClassicMedium>(adapter);
|
||||
}
|
||||
|
||||
std::unique_ptr<api::ble_v2::BleMedium>
|
||||
ImplementationPlatform::CreateBleV2Medium(api::BluetoothAdapter& adapter) {
|
||||
return std::make_unique<g3::BleV2Medium>(
|
||||
std::unique_ptr<api::ble::BleMedium>
|
||||
ImplementationPlatform::CreateBleMedium(api::BluetoothAdapter& adapter) {
|
||||
return std::make_unique<g3::BleMedium>(
|
||||
dynamic_cast<g3::BluetoothAdapter&>(adapter));
|
||||
}
|
||||
|
||||
|
||||
@@ -24,7 +24,7 @@
|
||||
#include "internal/platform/implementation/atomic_boolean.h"
|
||||
#include "internal/platform/implementation/atomic_reference.h"
|
||||
#include "internal/platform/implementation/awdl.h"
|
||||
#include "internal/platform/implementation/ble_v2.h"
|
||||
#include "internal/platform/implementation/ble.h"
|
||||
#include "internal/platform/implementation/bluetooth_adapter.h"
|
||||
#include "internal/platform/implementation/bluetooth_classic.h"
|
||||
#include "internal/platform/implementation/condition_variable.h"
|
||||
@@ -130,7 +130,7 @@ class ImplementationPlatform {
|
||||
static std::unique_ptr<BluetoothAdapter> CreateBluetoothAdapter();
|
||||
static std::unique_ptr<BluetoothClassicMedium> CreateBluetoothClassicMedium(
|
||||
BluetoothAdapter&);
|
||||
static std::unique_ptr<api::ble_v2::BleMedium> CreateBleV2Medium(
|
||||
static std::unique_ptr<api::ble::BleMedium> CreateBleMedium(
|
||||
api::BluetoothAdapter&);
|
||||
static std::unique_ptr<api::CredentialStorage> CreateCredentialStorage();
|
||||
static std::unique_ptr<ServerSyncMedium> CreateServerSyncMedium();
|
||||
|
||||
@@ -101,11 +101,11 @@ cc_library(
|
||||
cc_library(
|
||||
name = "comm",
|
||||
hdrs = [
|
||||
"ble.h",
|
||||
"ble_gatt_client.h",
|
||||
"ble_gatt_server.h",
|
||||
"ble_v2.h",
|
||||
"ble_v2_server_socket.h",
|
||||
"ble_v2_socket.h",
|
||||
"ble_server_socket.h",
|
||||
"ble_socket.h",
|
||||
"bluetooth_adapter.h",
|
||||
"bluetooth_classic.h",
|
||||
"bluetooth_classic_device.h",
|
||||
@@ -202,11 +202,11 @@ cc_library(
|
||||
cc_library(
|
||||
name = "windows",
|
||||
srcs = [
|
||||
"ble.cc",
|
||||
"ble_gatt_client.cc",
|
||||
"ble_gatt_server.cc",
|
||||
"ble_v2.cc",
|
||||
"ble_v2_server_socket.cc",
|
||||
"ble_v2_socket.cc",
|
||||
"ble_server_socket.cc",
|
||||
"ble_socket.cc",
|
||||
"bluetooth_adapter.cc",
|
||||
"bluetooth_classic_device.cc",
|
||||
"bluetooth_classic_medium.cc",
|
||||
@@ -271,8 +271,8 @@ cc_library(
|
||||
":types",
|
||||
"//connections/implementation/flags:connections_flags",
|
||||
"//connections/implementation/mediums:utils",
|
||||
"//connections/implementation/mediums/ble_v2:ble_advertisement_header",
|
||||
"//connections/implementation/mediums/ble_v2:bloom_filter",
|
||||
"//connections/implementation/mediums/ble:ble_advertisement_header",
|
||||
"//connections/implementation/mediums/ble:bloom_filter",
|
||||
"//internal/account",
|
||||
"//internal/base:file_path",
|
||||
"//internal/base:files",
|
||||
@@ -336,7 +336,7 @@ cc_test(
|
||||
"atomic_boolean_test.cc",
|
||||
"atomic_reference_test.cc",
|
||||
"ble_gatt_server_test.cc",
|
||||
"ble_v2_test.cc",
|
||||
"ble_test.cc",
|
||||
"bluetooth_adapter_test.cc",
|
||||
"count_down_latch_test.cc",
|
||||
"crypto_test.cc",
|
||||
|
||||
+75
-77
@@ -12,7 +12,7 @@
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
#include "internal/platform/implementation/windows/ble_v2.h"
|
||||
#include "internal/platform/implementation/windows/ble.h"
|
||||
|
||||
#include <algorithm>
|
||||
#include <chrono> // NOLINT
|
||||
@@ -34,20 +34,20 @@
|
||||
#include "absl/synchronization/mutex.h"
|
||||
#include "absl/time/clock.h"
|
||||
#include "absl/time/time.h"
|
||||
#include "connections/implementation/mediums/ble_v2/ble_advertisement_header.h"
|
||||
#include "connections/implementation/mediums/ble_v2/bloom_filter.h"
|
||||
#include "connections/implementation/mediums/ble/ble_advertisement_header.h"
|
||||
#include "connections/implementation/mediums/ble/bloom_filter.h"
|
||||
#include "connections/implementation/mediums/utils.h"
|
||||
#include "internal/flags/nearby_flags.h"
|
||||
#include "internal/platform/byte_array.h"
|
||||
#include "internal/platform/cancellation_flag.h"
|
||||
#include "internal/platform/cancellation_flag_listener.h"
|
||||
#include "internal/platform/flags/nearby_platform_feature_flags.h"
|
||||
#include "internal/platform/implementation/ble_v2.h"
|
||||
#include "internal/platform/implementation/ble.h"
|
||||
#include "internal/platform/implementation/bluetooth_adapter.h"
|
||||
#include "internal/platform/implementation/windows/ble_gatt_client.h"
|
||||
#include "internal/platform/implementation/windows/ble_gatt_server.h"
|
||||
#include "internal/platform/implementation/windows/ble_v2_server_socket.h"
|
||||
#include "internal/platform/implementation/windows/ble_v2_socket.h"
|
||||
#include "internal/platform/implementation/windows/ble_server_socket.h"
|
||||
#include "internal/platform/implementation/windows/ble_socket.h"
|
||||
#include "internal/platform/implementation/windows/bluetooth_adapter.h"
|
||||
#include "internal/platform/implementation/windows/utils.h"
|
||||
#include "internal/platform/logging.h"
|
||||
@@ -67,13 +67,13 @@ namespace {
|
||||
|
||||
using ::absl::Milliseconds;
|
||||
using ::absl::Minutes;
|
||||
using ::nearby::api::ble_v2::AdvertiseParameters;
|
||||
using ::nearby::api::ble_v2::BleAdvertisementData;
|
||||
using ::nearby::api::ble_v2::BleServerSocket;
|
||||
using ::nearby::api::ble_v2::BleSocket;
|
||||
using ::nearby::api::ble_v2::GattClient;
|
||||
using ::nearby::api::ble_v2::ServerGattConnectionCallback;
|
||||
using ::nearby::api::ble_v2::TxPowerLevel;
|
||||
using ::nearby::api::ble::AdvertiseParameters;
|
||||
using ::nearby::api::ble::BleAdvertisementData;
|
||||
using ::nearby::api::ble::BleServerSocket;
|
||||
using ::nearby::api::ble::BleSocket;
|
||||
using ::nearby::api::ble::GattClient;
|
||||
using ::nearby::api::ble::ServerGattConnectionCallback;
|
||||
using ::nearby::api::ble::TxPowerLevel;
|
||||
using ::nearby::connections::mediums::BitSetImpl;
|
||||
using ::nearby::connections::mediums::BleAdvertisementHeader;
|
||||
using ::nearby::connections::mediums::BloomFilter;
|
||||
@@ -133,8 +133,7 @@ std::string TxPowerLevelToName(TxPowerLevel tx_power_level) {
|
||||
// Use the device MAC address as the advertisement hash so that we have a unique
|
||||
// advertisement header for each device.
|
||||
BleAdvertisementHeader CreateAdvertisementHeader(
|
||||
MacAddress mac_address,
|
||||
const std::vector<std::string>& service_ids) {
|
||||
MacAddress mac_address, const std::vector<std::string>& service_ids) {
|
||||
BloomFilter bloom_filter(
|
||||
std::make_unique<BitSetImpl<
|
||||
BleAdvertisementHeader::kServiceIdBloomFilterByteLength>>());
|
||||
@@ -165,9 +164,9 @@ constexpr absl::Duration kMediumCheckInterval = Milliseconds(50);
|
||||
constexpr uint8_t kUuid16ServiceDataType = 0x16;
|
||||
} // namespace
|
||||
|
||||
BleV2Medium::AdvertisementWatcher::~AdvertisementWatcher() { Stop(); }
|
||||
BleMedium::AdvertisementWatcher::~AdvertisementWatcher() { Stop(); }
|
||||
|
||||
void BleV2Medium::AdvertisementWatcher::Initialize(
|
||||
void BleMedium::AdvertisementWatcher::Initialize(
|
||||
const TypedEventHandler<BluetoothLEAdvertisementWatcher,
|
||||
BluetoothLEAdvertisementReceivedEventArgs>&
|
||||
received_handler,
|
||||
@@ -199,7 +198,7 @@ void BleV2Medium::AdvertisementWatcher::Initialize(
|
||||
}
|
||||
}
|
||||
|
||||
void BleV2Medium::AdvertisementWatcher::InitializeWithServiceFilter(
|
||||
void BleMedium::AdvertisementWatcher::InitializeWithServiceFilter(
|
||||
uint16_t service_uuid,
|
||||
const TypedEventHandler<BluetoothLEAdvertisementWatcher,
|
||||
BluetoothLEAdvertisementReceivedEventArgs>&
|
||||
@@ -240,7 +239,7 @@ void BleV2Medium::AdvertisementWatcher::InitializeWithServiceFilter(
|
||||
}
|
||||
}
|
||||
|
||||
bool BleV2Medium::AdvertisementWatcher::Start() {
|
||||
bool BleMedium::AdvertisementWatcher::Start() {
|
||||
absl::MutexLock lock(&mutex_);
|
||||
if (!initialized_) {
|
||||
LOG(ERROR) << __func__ << ": Failed to start BLE watcher: not initialized.";
|
||||
@@ -277,7 +276,7 @@ bool BleV2Medium::AdvertisementWatcher::Start() {
|
||||
return true;
|
||||
}
|
||||
|
||||
void BleV2Medium::AdvertisementWatcher::Stop() {
|
||||
void BleMedium::AdvertisementWatcher::Stop() {
|
||||
absl::MutexLock lock(&mutex_);
|
||||
try {
|
||||
watcher_.Stop();
|
||||
@@ -300,12 +299,12 @@ void BleV2Medium::AdvertisementWatcher::Stop() {
|
||||
}
|
||||
}
|
||||
|
||||
BleV2Medium::BleV2Medium(api::BluetoothAdapter& adapter)
|
||||
BleMedium::BleMedium(api::BluetoothAdapter& adapter)
|
||||
: adapter_(dynamic_cast<BluetoothAdapter*>(&adapter)) {}
|
||||
|
||||
// Advertisement packet and populate accordingly.
|
||||
bool BleV2Medium::StartAdvertising(const BleAdvertisementData& advertising_data,
|
||||
AdvertiseParameters advertising_parameters) {
|
||||
bool BleMedium::StartAdvertising(const BleAdvertisementData& advertising_data,
|
||||
AdvertiseParameters advertising_parameters) {
|
||||
absl::MutexLock lock(&mutex_);
|
||||
std::string service_data_info;
|
||||
for (const auto& it : advertising_data.service_data) {
|
||||
@@ -321,14 +320,14 @@ bool BleV2Medium::StartAdvertising(const BleAdvertisementData& advertising_data,
|
||||
|
||||
if (advertising_data.is_extended_advertisement ||
|
||||
ble_gatt_server_ == nullptr) {
|
||||
// In BLE v2, the flag is set when the Bluetooth adapter supports extended
|
||||
// In BLE, the flag is set when the Bluetooth adapter supports extended
|
||||
// advertising and GATT server is using.
|
||||
return StartBleAdvertising(advertising_data, advertising_parameters);
|
||||
}
|
||||
return StartGattAdvertising(advertising_data, advertising_parameters);
|
||||
}
|
||||
|
||||
bool BleV2Medium::StopAdvertising() {
|
||||
bool BleMedium::StopAdvertising() {
|
||||
absl::MutexLock lock(&mutex_);
|
||||
LOG(INFO) << __func__ << ": Stop advertising.";
|
||||
bool result = true;
|
||||
@@ -353,10 +352,10 @@ bool BleV2Medium::StopAdvertising() {
|
||||
}
|
||||
|
||||
// TODO(hais) manually verify the new api before switching async flags.
|
||||
std::unique_ptr<BleV2Medium::AdvertisingSession> BleV2Medium::StartAdvertising(
|
||||
const api::ble_v2::BleAdvertisementData& advertising_data,
|
||||
api::ble_v2::AdvertiseParameters advertise_set_parameters,
|
||||
BleV2Medium::AdvertisingCallback callback) {
|
||||
std::unique_ptr<BleMedium::AdvertisingSession> BleMedium::StartAdvertising(
|
||||
const api::ble::BleAdvertisementData& advertising_data,
|
||||
api::ble::AdvertiseParameters advertise_set_parameters,
|
||||
BleMedium::AdvertisingCallback callback) {
|
||||
LOG(INFO) << __func__ << ": advertising_data.is_extended_advertisement="
|
||||
<< advertising_data.is_extended_advertisement
|
||||
<< ", advertising_data.service_data size="
|
||||
@@ -375,8 +374,8 @@ std::unique_ptr<BleV2Medium::AdvertisingSession> BleV2Medium::StartAdvertising(
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
return std::make_unique<BleV2Medium::AdvertisingSession>(
|
||||
BleV2Medium::AdvertisingSession{
|
||||
return std::make_unique<BleMedium::AdvertisingSession>(
|
||||
BleMedium::AdvertisingSession{
|
||||
.stop_advertising =
|
||||
[this]() {
|
||||
if (StopAdvertising()) {
|
||||
@@ -388,12 +387,12 @@ std::unique_ptr<BleV2Medium::AdvertisingSession> BleV2Medium::StartAdvertising(
|
||||
});
|
||||
}
|
||||
|
||||
std::unique_ptr<BleV2Medium::AdvertisementWatcher>
|
||||
BleV2Medium::CreateBleWatcher(uint16_t service_uuid) {
|
||||
std::unique_ptr<BleMedium::AdvertisementWatcher> BleMedium::CreateBleWatcher(
|
||||
uint16_t service_uuid) {
|
||||
auto watcher = std::make_unique<AdvertisementWatcher>();
|
||||
watcher->InitializeWithServiceFilter(
|
||||
service_uuid, {this, &BleV2Medium::AdvertisementReceivedHandler},
|
||||
{this, &BleV2Medium::WatcherHandler});
|
||||
service_uuid, {this, &BleMedium::AdvertisementReceivedHandler},
|
||||
{this, &BleMedium::WatcherHandler});
|
||||
|
||||
if (!watcher->Start()) {
|
||||
return nullptr;
|
||||
@@ -403,9 +402,9 @@ BleV2Medium::CreateBleWatcher(uint16_t service_uuid) {
|
||||
return watcher;
|
||||
}
|
||||
|
||||
bool BleV2Medium::StartScanning(const Uuid& service_uuid,
|
||||
TxPowerLevel tx_power_level,
|
||||
ScanCallback callback) {
|
||||
bool BleMedium::StartScanning(const Uuid& service_uuid,
|
||||
TxPowerLevel tx_power_level,
|
||||
ScanCallback callback) {
|
||||
absl::MutexLock lock(&mutex_);
|
||||
LOG(INFO) << __func__ << ": service UUID: " << std::string(service_uuid)
|
||||
<< ", TxPowerLevel: " << TxPowerLevelToName(tx_power_level);
|
||||
@@ -463,9 +462,9 @@ bool BleV2Medium::StartScanning(const Uuid& service_uuid,
|
||||
return true;
|
||||
}
|
||||
|
||||
std::unique_ptr<BleV2Medium::ScanningSession> BleV2Medium::StartScanning(
|
||||
std::unique_ptr<BleMedium::ScanningSession> BleMedium::StartScanning(
|
||||
const Uuid& service_uuid, TxPowerLevel tx_power_level,
|
||||
BleV2Medium::ScanningCallback callback) {
|
||||
BleMedium::ScanningCallback callback) {
|
||||
absl::MutexLock lock(&mutex_);
|
||||
LOG(INFO) << __func__ << ": service UUID: " << std::string(service_uuid)
|
||||
<< ", TxPowerLevel: " << TxPowerLevelToName(tx_power_level);
|
||||
@@ -478,8 +477,8 @@ std::unique_ptr<BleV2Medium::ScanningSession> BleV2Medium::StartScanning(
|
||||
if (watchers_.empty()) {
|
||||
LOG(WARNING) << __func__ << ": Starting BLE Scanning.";
|
||||
auto watcher = std::make_unique<AdvertisementWatcher>();
|
||||
watcher->Initialize({this, &BleV2Medium::AdvertisementFoundHandler},
|
||||
{this, &BleV2Medium::WatcherHandler});
|
||||
watcher->Initialize({this, &BleMedium::AdvertisementFoundHandler},
|
||||
{this, &BleMedium::WatcherHandler});
|
||||
if (!watcher->Start()) {
|
||||
return nullptr;
|
||||
}
|
||||
@@ -499,8 +498,8 @@ std::unique_ptr<BleV2Medium::ScanningSession> BleV2Medium::StartScanning(
|
||||
}
|
||||
|
||||
// Generate and return ScanningSession.
|
||||
return std::make_unique<BleV2Medium::ScanningSession>(
|
||||
BleV2Medium::ScanningSession{
|
||||
return std::make_unique<BleMedium::ScanningSession>(
|
||||
BleMedium::ScanningSession{
|
||||
.stop_scanning =
|
||||
[this, session_id, service_uuid]() {
|
||||
size_t num_erased_from_service_and_session_map = 0u;
|
||||
@@ -552,8 +551,8 @@ std::unique_ptr<BleV2Medium::ScanningSession> BleV2Medium::StartScanning(
|
||||
});
|
||||
}
|
||||
|
||||
std::unique_ptr<api::ble_v2::GattServer> BleV2Medium::StartGattServer(
|
||||
api::ble_v2::ServerGattConnectionCallback callback) {
|
||||
std::unique_ptr<api::ble::GattServer> BleMedium::StartGattServer(
|
||||
api::ble::ServerGattConnectionCallback callback) {
|
||||
absl::MutexLock lock(&mutex_);
|
||||
LOG(INFO) << __func__ << ": Start GATT server.";
|
||||
|
||||
@@ -573,10 +572,10 @@ std::unique_ptr<api::ble_v2::GattServer> BleV2Medium::StartGattServer(
|
||||
return gatt_server;
|
||||
}
|
||||
|
||||
std::unique_ptr<api::ble_v2::GattClient> BleV2Medium::ConnectToGattServer(
|
||||
api::ble_v2::BlePeripheral::UniqueId peripheral_id,
|
||||
std::unique_ptr<api::ble::GattClient> BleMedium::ConnectToGattServer(
|
||||
api::ble::BlePeripheral::UniqueId peripheral_id,
|
||||
TxPowerLevel tx_power_level,
|
||||
api::ble_v2::ClientGattConnectionCallback callback) {
|
||||
api::ble::ClientGattConnectionCallback callback) {
|
||||
absl::MutexLock lock(&mutex_);
|
||||
LOG(INFO) << "ConnectToGattServer is called with peripheral id: "
|
||||
<< peripheral_id
|
||||
@@ -585,8 +584,7 @@ std::unique_ptr<api::ble_v2::GattClient> BleV2Medium::ConnectToGattServer(
|
||||
try {
|
||||
// In windows, peripheral unique id is the same as the bluetooth address.
|
||||
BluetoothLEDevice ble_device =
|
||||
BluetoothLEDevice::FromBluetoothAddressAsync(peripheral_id)
|
||||
.get();
|
||||
BluetoothLEDevice::FromBluetoothAddressAsync(peripheral_id).get();
|
||||
|
||||
return std::make_unique<BleGattClient>(ble_device);
|
||||
} catch (std::exception exception) {
|
||||
@@ -601,7 +599,7 @@ std::unique_ptr<api::ble_v2::GattClient> BleV2Medium::ConnectToGattServer(
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
bool BleV2Medium::StopScanning() {
|
||||
bool BleMedium::StopScanning() {
|
||||
absl::MutexLock lock(&mutex_);
|
||||
|
||||
alternate_uuids_for_service_.clear();
|
||||
@@ -631,11 +629,11 @@ bool BleV2Medium::StopScanning() {
|
||||
return true;
|
||||
}
|
||||
|
||||
std::unique_ptr<api::ble_v2::BleServerSocket> BleV2Medium::OpenServerSocket(
|
||||
std::unique_ptr<api::ble::BleServerSocket> BleMedium::OpenServerSocket(
|
||||
const std::string& service_id) {
|
||||
VLOG(1) << "OpenServerSocket is called";
|
||||
|
||||
auto server_socket = std::make_unique<BleV2ServerSocket>(adapter_);
|
||||
auto server_socket = std::make_unique<windows::BleServerSocket>(adapter_);
|
||||
|
||||
if (!server_socket->Bind()) {
|
||||
LOG(ERROR) << __func__ << ": Failed to bing socket.";
|
||||
@@ -645,9 +643,9 @@ std::unique_ptr<api::ble_v2::BleServerSocket> BleV2Medium::OpenServerSocket(
|
||||
return server_socket;
|
||||
}
|
||||
|
||||
std::unique_ptr<api::ble_v2::BleSocket> BleV2Medium::Connect(
|
||||
std::unique_ptr<api::ble::BleSocket> BleMedium::Connect(
|
||||
const std::string& service_id, TxPowerLevel tx_power_level,
|
||||
api::ble_v2::BlePeripheral::UniqueId remote_peripheral_id,
|
||||
api::ble::BlePeripheral::UniqueId remote_peripheral_id,
|
||||
CancellationFlag* cancellation_flag) {
|
||||
LOG(INFO) << __func__ << ": Connect to service_id=" << service_id;
|
||||
|
||||
@@ -662,7 +660,7 @@ std::unique_ptr<api::ble_v2::BleSocket> BleV2Medium::Connect(
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
auto ble_socket = std::make_unique<BleV2Socket>();
|
||||
auto ble_socket = std::make_unique<windows::BleSocket>();
|
||||
|
||||
nearby::CancellationFlagListener cancellation_flag_listener(
|
||||
cancellation_flag, [socket = ble_socket.get()]() { socket->Close(); });
|
||||
@@ -676,13 +674,13 @@ std::unique_ptr<api::ble_v2::BleSocket> BleV2Medium::Connect(
|
||||
return ble_socket;
|
||||
}
|
||||
|
||||
bool BleV2Medium::IsExtendedAdvertisementsAvailable() {
|
||||
bool BleMedium::IsExtendedAdvertisementsAvailable() {
|
||||
return adapter_->IsExtendedAdvertisingSupported();
|
||||
}
|
||||
|
||||
bool BleV2Medium::StartBleAdvertising(
|
||||
const api::ble_v2::BleAdvertisementData& advertising_data,
|
||||
api::ble_v2::AdvertiseParameters advertising_parameters) {
|
||||
bool BleMedium::StartBleAdvertising(
|
||||
const api::ble::BleAdvertisementData& advertising_data,
|
||||
api::ble::AdvertiseParameters advertising_parameters) {
|
||||
LOG(INFO) << __func__ << ": Start BLE advertising, extended:"
|
||||
<< advertising_data.is_extended_advertisement;
|
||||
try {
|
||||
@@ -762,7 +760,7 @@ bool BleV2Medium::StartBleAdvertising(
|
||||
publisher_.UseExtendedAdvertisement(false);
|
||||
}
|
||||
publisher_token_ =
|
||||
publisher_.StatusChanged({this, &BleV2Medium::PublisherHandler});
|
||||
publisher_.StatusChanged({this, &BleMedium::PublisherHandler});
|
||||
|
||||
publisher_.Start();
|
||||
|
||||
@@ -802,7 +800,7 @@ bool BleV2Medium::StartBleAdvertising(
|
||||
}
|
||||
}
|
||||
|
||||
bool BleV2Medium::StopBleAdvertising() {
|
||||
bool BleMedium::StopBleAdvertising() {
|
||||
LOG(INFO) << __func__ << ": Stop BLE advertising.";
|
||||
try {
|
||||
if (!is_ble_publisher_started_) {
|
||||
@@ -863,9 +861,9 @@ bool BleV2Medium::StopBleAdvertising() {
|
||||
return false;
|
||||
}
|
||||
|
||||
bool BleV2Medium::StartGattAdvertising(
|
||||
const api::ble_v2::BleAdvertisementData& advertising_data,
|
||||
api::ble_v2::AdvertiseParameters advertising_parameters) {
|
||||
bool BleMedium::StartGattAdvertising(
|
||||
const api::ble::BleAdvertisementData& advertising_data,
|
||||
api::ble::AdvertiseParameters advertising_parameters) {
|
||||
LOG(INFO) << __func__ << ": Start GATT advertising.";
|
||||
try {
|
||||
if (!adapter_->IsEnabled()) {
|
||||
@@ -927,7 +925,7 @@ bool BleV2Medium::StartGattAdvertising(
|
||||
}
|
||||
}
|
||||
|
||||
bool BleV2Medium::StopGattAdvertising() {
|
||||
bool BleMedium::StopGattAdvertising() {
|
||||
try {
|
||||
LOG(INFO) << __func__ << ": Stop GATT advertising.";
|
||||
|
||||
@@ -968,7 +966,7 @@ bool BleV2Medium::StopGattAdvertising() {
|
||||
return false;
|
||||
}
|
||||
|
||||
void BleV2Medium::PublisherHandler(
|
||||
void BleMedium::PublisherHandler(
|
||||
BluetoothLEAdvertisementPublisher publisher,
|
||||
BluetoothLEAdvertisementPublisherStatusChangedEventArgs args) {
|
||||
// This method is called when publisher's status is changed.
|
||||
@@ -1049,7 +1047,7 @@ void BleV2Medium::PublisherHandler(
|
||||
}
|
||||
}
|
||||
|
||||
void BleV2Medium::WatcherHandler(
|
||||
void BleMedium::WatcherHandler(
|
||||
BluetoothLEAdvertisementWatcher watcher,
|
||||
BluetoothLEAdvertisementWatcherStoppedEventArgs args) {
|
||||
// This method is called when watcher stopped. Args give more detailed
|
||||
@@ -1096,7 +1094,7 @@ void BleV2Medium::WatcherHandler(
|
||||
}
|
||||
}
|
||||
|
||||
void BleV2Medium::AdvertisementReceivedHandler(
|
||||
void BleMedium::AdvertisementReceivedHandler(
|
||||
BluetoothLEAdvertisementWatcher watcher,
|
||||
BluetoothLEAdvertisementReceivedEventArgs args) {
|
||||
// Handle all BLE advertisements and determine whether the BLE Medium
|
||||
@@ -1139,7 +1137,7 @@ void BleV2Medium::AdvertisementReceivedHandler(
|
||||
<< " peripheral address: " << bluetooth_address.ToString()
|
||||
<< " unconsumed_buffer_length: " << unconsumed_buffer_length;
|
||||
|
||||
api::ble_v2::BleAdvertisementData ble_advertisement_data;
|
||||
api::ble::BleAdvertisementData ble_advertisement_data;
|
||||
if (unconsumed_buffer_length <= 27) {
|
||||
ble_advertisement_data.is_extended_advertisement = false;
|
||||
} else {
|
||||
@@ -1166,7 +1164,7 @@ void BleV2Medium::AdvertisementReceivedHandler(
|
||||
<< bluetooth_address.ToString()
|
||||
<< " for services: " << absl::StrJoin(alt_service_ids, ",");
|
||||
// Create fake advertisement data.
|
||||
api::ble_v2::BleAdvertisementData ble_advertisement_data;
|
||||
api::ble::BleAdvertisementData ble_advertisement_data;
|
||||
ble_advertisement_data.is_extended_advertisement = false;
|
||||
BleAdvertisementHeader header =
|
||||
CreateAdvertisementHeader(bluetooth_address, alt_service_ids);
|
||||
@@ -1176,7 +1174,7 @@ void BleV2Medium::AdvertisementReceivedHandler(
|
||||
}
|
||||
}
|
||||
|
||||
void BleV2Medium::AdvertisementFoundHandler(
|
||||
void BleMedium::AdvertisementFoundHandler(
|
||||
BluetoothLEAdvertisementWatcher watcher,
|
||||
BluetoothLEAdvertisementReceivedEventArgs args) {
|
||||
BluetoothLEAdvertisement advertisement = args.Advertisement();
|
||||
@@ -1199,7 +1197,7 @@ void BleV2Medium::AdvertisementFoundHandler(
|
||||
}
|
||||
|
||||
// Construct BleAdvertisementData from the windows Advertisement.
|
||||
api::ble_v2::BleAdvertisementData ble_advertisement_data;
|
||||
api::ble::BleAdvertisementData ble_advertisement_data;
|
||||
for (BluetoothLEAdvertisementDataSection service_data :
|
||||
advertisement.GetSectionsByType(kUuid16ServiceDataType)) {
|
||||
// Parse Advertisement Data for Section 0x16 (Service Data)
|
||||
@@ -1260,7 +1258,7 @@ void BleV2Medium::AdvertisementFoundHandler(
|
||||
}
|
||||
}
|
||||
|
||||
uint64_t BleV2Medium::GenerateSessionId() {
|
||||
uint64_t BleMedium::GenerateSessionId() {
|
||||
for (int i = 0; i < kGenerateSessionIdRetryLimit; i++) {
|
||||
uint64_t session_id = Prng().NextInt64();
|
||||
if (session_id == kFailedGenerateSessionId) continue;
|
||||
@@ -1272,8 +1270,8 @@ uint64_t BleV2Medium::GenerateSessionId() {
|
||||
return kFailedGenerateSessionId;
|
||||
}
|
||||
|
||||
void BleV2Medium::AddAlternateUuidForService(uint16_t uuid,
|
||||
const std::string& service_id) {
|
||||
void BleMedium::AddAlternateUuidForService(uint16_t uuid,
|
||||
const std::string& service_id) {
|
||||
absl::MutexLock lock(&mutex_);
|
||||
alternate_uuids_for_service_[uuid] = service_id;
|
||||
}
|
||||
+31
-32
@@ -12,8 +12,8 @@
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
#ifndef THIRD_PARTY_NEARBY_INTERNAL_PLATFORM_IMPLEMENTATION_WINDOWS_BLE_V2_H_
|
||||
#define THIRD_PARTY_NEARBY_INTERNAL_PLATFORM_IMPLEMENTATION_WINDOWS_BLE_V2_H_
|
||||
#ifndef THIRD_PARTY_NEARBY_INTERNAL_PLATFORM_IMPLEMENTATION_WINDOWS_BLE_H_
|
||||
#define THIRD_PARTY_NEARBY_INTERNAL_PLATFORM_IMPLEMENTATION_WINDOWS_BLE_H_
|
||||
|
||||
#include <algorithm>
|
||||
#include <cstdint>
|
||||
@@ -25,7 +25,7 @@
|
||||
#include "absl/container/flat_hash_map.h"
|
||||
#include "absl/synchronization/mutex.h"
|
||||
#include "internal/platform/cancellation_flag.h"
|
||||
#include "internal/platform/implementation/ble_v2.h"
|
||||
#include "internal/platform/implementation/ble.h"
|
||||
#include "internal/platform/implementation/bluetooth_adapter.h"
|
||||
#include "internal/platform/implementation/windows/ble_gatt_server.h"
|
||||
#include "internal/platform/implementation/windows/bluetooth_adapter.h"
|
||||
@@ -36,44 +36,43 @@ namespace nearby {
|
||||
namespace windows {
|
||||
|
||||
// Container of operations that can be performed over the BLE medium.
|
||||
class BleV2Medium : public api::ble_v2::BleMedium {
|
||||
class BleMedium : public api::ble::BleMedium {
|
||||
public:
|
||||
explicit BleV2Medium(api::BluetoothAdapter& adapter);
|
||||
~BleV2Medium() override = default;
|
||||
explicit BleMedium(api::BluetoothAdapter& adapter);
|
||||
~BleMedium() override = default;
|
||||
|
||||
// Returns true once the Ble advertising has been initiated.
|
||||
bool StartAdvertising(
|
||||
const api::ble_v2::BleAdvertisementData& advertising_data,
|
||||
api::ble_v2::AdvertiseParameters advertising_parameters) override
|
||||
ABSL_LOCKS_EXCLUDED(mutex_);
|
||||
bool StartAdvertising(const api::ble::BleAdvertisementData& advertising_data,
|
||||
api::ble::AdvertiseParameters advertising_parameters)
|
||||
override ABSL_LOCKS_EXCLUDED(mutex_);
|
||||
bool StopAdvertising() override ABSL_LOCKS_EXCLUDED(mutex_);
|
||||
|
||||
std::unique_ptr<AdvertisingSession> StartAdvertising(
|
||||
const api::ble_v2::BleAdvertisementData& advertising_data,
|
||||
api::ble_v2::AdvertiseParameters advertise_set_parameters,
|
||||
const api::ble::BleAdvertisementData& advertising_data,
|
||||
api::ble::AdvertiseParameters advertise_set_parameters,
|
||||
AdvertisingCallback callback) override ABSL_LOCKS_EXCLUDED(mutex_);
|
||||
|
||||
bool StartScanning(const Uuid& service_uuid,
|
||||
api::ble_v2::TxPowerLevel tx_power_level,
|
||||
api::ble::TxPowerLevel tx_power_level,
|
||||
ScanCallback callback) override
|
||||
ABSL_LOCKS_EXCLUDED(mutex_);
|
||||
bool StopScanning() override ABSL_LOCKS_EXCLUDED(mutex_);
|
||||
std::unique_ptr<ScanningSession> StartScanning(
|
||||
const Uuid& service_uuid, api::ble_v2::TxPowerLevel tx_power_level,
|
||||
const Uuid& service_uuid, api::ble::TxPowerLevel tx_power_level,
|
||||
ScanningCallback callback) override;
|
||||
std::unique_ptr<api::ble_v2::GattServer> StartGattServer(
|
||||
api::ble_v2::ServerGattConnectionCallback callback) override
|
||||
std::unique_ptr<api::ble::GattServer> StartGattServer(
|
||||
api::ble::ServerGattConnectionCallback callback) override
|
||||
ABSL_LOCKS_EXCLUDED(mutex_);
|
||||
std::unique_ptr<api::ble_v2::GattClient> ConnectToGattServer(
|
||||
api::ble_v2::BlePeripheral::UniqueId peripheral_id,
|
||||
api::ble_v2::TxPowerLevel tx_power_level,
|
||||
api::ble_v2::ClientGattConnectionCallback callback) override
|
||||
std::unique_ptr<api::ble::GattClient> ConnectToGattServer(
|
||||
api::ble::BlePeripheral::UniqueId peripheral_id,
|
||||
api::ble::TxPowerLevel tx_power_level,
|
||||
api::ble::ClientGattConnectionCallback callback) override
|
||||
ABSL_LOCKS_EXCLUDED(mutex_);
|
||||
std::unique_ptr<api::ble_v2::BleServerSocket> OpenServerSocket(
|
||||
std::unique_ptr<api::ble::BleServerSocket> OpenServerSocket(
|
||||
const std::string& service_id) override ABSL_LOCKS_EXCLUDED(mutex_);
|
||||
std::unique_ptr<api::ble_v2::BleSocket> Connect(
|
||||
const std::string& service_id, api::ble_v2::TxPowerLevel tx_power_level,
|
||||
api::ble_v2::BlePeripheral::UniqueId remote_peripheral_id,
|
||||
std::unique_ptr<api::ble::BleSocket> Connect(
|
||||
const std::string& service_id, api::ble::TxPowerLevel tx_power_level,
|
||||
api::ble::BlePeripheral::UniqueId remote_peripheral_id,
|
||||
CancellationFlag* cancellation_flag) override ABSL_LOCKS_EXCLUDED(mutex_);
|
||||
bool IsExtendedAdvertisementsAvailable() override;
|
||||
|
||||
@@ -81,7 +80,7 @@ class BleV2Medium : public api::ble_v2::BleMedium {
|
||||
const std::string& service_id) override;
|
||||
|
||||
private:
|
||||
friend class BleV2MediumTest;
|
||||
friend class BleMediumTest;
|
||||
|
||||
// A wrapper class for BluetoothLEAdvertisementWatcher.
|
||||
class AdvertisementWatcher {
|
||||
@@ -136,14 +135,14 @@ class BleV2Medium : public api::ble_v2::BleMedium {
|
||||
};
|
||||
|
||||
bool StartBleAdvertising(
|
||||
const api::ble_v2::BleAdvertisementData& advertising_data,
|
||||
api::ble_v2::AdvertiseParameters advertising_parameters)
|
||||
const api::ble::BleAdvertisementData& advertising_data,
|
||||
api::ble::AdvertiseParameters advertising_parameters)
|
||||
ABSL_EXCLUSIVE_LOCKS_REQUIRED(mutex_);
|
||||
bool StopBleAdvertising() ABSL_EXCLUSIVE_LOCKS_REQUIRED(mutex_);
|
||||
|
||||
bool StartGattAdvertising(
|
||||
const api::ble_v2::BleAdvertisementData& advertising_data,
|
||||
api::ble_v2::AdvertiseParameters advertising_parameters)
|
||||
const api::ble::BleAdvertisementData& advertising_data,
|
||||
api::ble::AdvertiseParameters advertising_parameters)
|
||||
ABSL_EXCLUSIVE_LOCKS_REQUIRED(mutex_);
|
||||
bool StopGattAdvertising() ABSL_EXCLUSIVE_LOCKS_REQUIRED(mutex_);
|
||||
|
||||
@@ -172,7 +171,7 @@ class BleV2Medium : public api::ble_v2::BleMedium {
|
||||
|
||||
uint64_t GenerateSessionId() ABSL_EXCLUSIVE_LOCKS_REQUIRED(mutex_);
|
||||
|
||||
std::unique_ptr<BleV2Medium::AdvertisementWatcher> CreateBleWatcher(
|
||||
std::unique_ptr<BleMedium::AdvertisementWatcher> CreateBleWatcher(
|
||||
uint16_t service_uuid);
|
||||
|
||||
absl::Mutex mutex_;
|
||||
@@ -180,7 +179,7 @@ class BleV2Medium : public api::ble_v2::BleMedium {
|
||||
BluetoothAdapter* const adapter_;
|
||||
Uuid service_uuid_;
|
||||
uint16_t service_uuid16_ = 0;
|
||||
api::ble_v2::TxPowerLevel tx_power_level_;
|
||||
api::ble::TxPowerLevel tx_power_level_;
|
||||
ScanCallback scan_callback_;
|
||||
std::vector<std::unique_ptr<AdvertisementWatcher>> watchers_
|
||||
ABSL_GUARDED_BY(mutex_);
|
||||
@@ -214,4 +213,4 @@ class BleV2Medium : public api::ble_v2::BleMedium {
|
||||
} // namespace windows
|
||||
} // namespace nearby
|
||||
|
||||
#endif // THIRD_PARTY_NEARBY_INTERNAL_PLATFORM_IMPLEMENTATION_WINDOWS_BLE_V2_H_
|
||||
#endif // THIRD_PARTY_NEARBY_INTERNAL_PLATFORM_IMPLEMENTATION_WINDOWS_BLE_H_
|
||||
@@ -36,7 +36,7 @@
|
||||
#include "internal/flags/nearby_flags.h"
|
||||
#include "internal/platform/byte_array.h"
|
||||
#include "internal/platform/flags/nearby_platform_feature_flags.h"
|
||||
#include "internal/platform/implementation/ble_v2.h"
|
||||
#include "internal/platform/implementation/ble.h"
|
||||
#include "internal/platform/implementation/windows/bluetooth_adapter.h"
|
||||
#include "internal/platform/implementation/windows/utils.h"
|
||||
#include "internal/platform/logging.h"
|
||||
@@ -79,9 +79,9 @@ using ::winrt::Windows::Foundation::Collections::IVectorView;
|
||||
using ::winrt::Windows::Storage::Streams::Buffer;
|
||||
using ::winrt::Windows::Storage::Streams::DataReader;
|
||||
using ::winrt::Windows::Storage::Streams::IBuffer;
|
||||
using Property = api::ble_v2::GattCharacteristic::Property;
|
||||
using Permission = api::ble_v2::GattCharacteristic::Permission;
|
||||
using WriteType = api::ble_v2::GattClient::WriteType;
|
||||
using Property = api::ble::GattCharacteristic::Property;
|
||||
using Permission = api::ble::GattCharacteristic::Permission;
|
||||
using WriteType = api::ble::GattClient::WriteType;
|
||||
|
||||
constexpr int kGattTimeoutInSeconds = 5;
|
||||
|
||||
@@ -269,9 +269,8 @@ bool BleGattClient::DiscoverServiceAndCharacteristics(
|
||||
return false;
|
||||
}
|
||||
|
||||
absl::optional<api::ble_v2::GattCharacteristic>
|
||||
BleGattClient::GetCharacteristic(const Uuid& service_uuid,
|
||||
const Uuid& characteristic_uuid) {
|
||||
absl::optional<api::ble::GattCharacteristic> BleGattClient::GetCharacteristic(
|
||||
const Uuid& service_uuid, const Uuid& characteristic_uuid) {
|
||||
absl::MutexLock lock(&mutex_);
|
||||
VLOG(1) << __func__ << ": Stared to get characteristic UUID="
|
||||
<< std::string(characteristic_uuid)
|
||||
@@ -285,12 +284,12 @@ BleGattClient::GetCharacteristic(const Uuid& service_uuid,
|
||||
return absl::nullopt;
|
||||
}
|
||||
|
||||
api::ble_v2::GattCharacteristic result;
|
||||
api::ble::GattCharacteristic result;
|
||||
result.service_uuid = service_uuid;
|
||||
result.uuid = characteristic_uuid;
|
||||
|
||||
// Note: Windows has protection level on GattCharacteristic. cannot
|
||||
// find a way to map it to api::ble_v2::GattCharacteristic.
|
||||
// find a way to map it to api::ble::GattCharacteristic.
|
||||
GattCharacteristicProperties properties =
|
||||
gatt_characteristic->CharacteristicProperties();
|
||||
result.permission = Permission::kNone;
|
||||
@@ -336,7 +335,7 @@ BleGattClient::GetCharacteristic(const Uuid& service_uuid,
|
||||
}
|
||||
|
||||
absl::optional<std::string> BleGattClient::ReadCharacteristic(
|
||||
const api::ble_v2::GattCharacteristic& characteristic) {
|
||||
const api::ble::GattCharacteristic& characteristic) {
|
||||
absl::MutexLock lock(&mutex_);
|
||||
VLOG(1) << __func__
|
||||
<< ": Read characteristic=" << std::string(characteristic.uuid);
|
||||
@@ -390,8 +389,8 @@ absl::optional<std::string> BleGattClient::ReadCharacteristic(
|
||||
}
|
||||
|
||||
bool BleGattClient::WriteCharacteristic(
|
||||
const api::ble_v2::GattCharacteristic& characteristic,
|
||||
absl::string_view value, api::ble_v2::GattClient::WriteType write_type) {
|
||||
const api::ble::GattCharacteristic& characteristic, absl::string_view value,
|
||||
api::ble::GattClient::WriteType write_type) {
|
||||
absl::MutexLock lock(&mutex_);
|
||||
VLOG(1) << __func__
|
||||
<< ": write characteristic: " << std::string(characteristic.uuid);
|
||||
@@ -441,7 +440,7 @@ bool BleGattClient::WriteCharacteristic(
|
||||
}
|
||||
|
||||
bool BleGattClient::SetCharacteristicSubscription(
|
||||
const api::ble_v2::GattCharacteristic& characteristic, bool enable,
|
||||
const api::ble::GattCharacteristic& characteristic, bool enable,
|
||||
absl::AnyInvocable<void(absl::string_view value)>
|
||||
on_characteristic_changed_cb) {
|
||||
absl::MutexLock lock(&mutex_);
|
||||
@@ -629,7 +628,7 @@ bool BleGattClient::WriteCharacteristicConfigurationDescriptor(
|
||||
}
|
||||
|
||||
void BleGattClient::OnCharacteristicValueChanged(
|
||||
const api::ble_v2::GattCharacteristic& characteristic,
|
||||
const api::ble::GattCharacteristic& characteristic,
|
||||
GattValueChangedEventArgs args) {
|
||||
VLOG(1) << __func__ << ": Gatt Characteristic value changed.";
|
||||
IBuffer buffer = args.CharacteristicValue();
|
||||
|
||||
@@ -30,7 +30,7 @@
|
||||
#include "absl/synchronization/mutex.h"
|
||||
#include "absl/types/optional.h"
|
||||
#include "internal/platform/byte_array.h"
|
||||
#include "internal/platform/implementation/ble_v2.h"
|
||||
#include "internal/platform/implementation/ble.h"
|
||||
#include "internal/platform/uuid.h"
|
||||
#include "winrt/Windows.Devices.Bluetooth.GenericAttributeProfile.h"
|
||||
#include "winrt/Windows.Devices.Bluetooth.h"
|
||||
@@ -39,7 +39,7 @@
|
||||
namespace nearby {
|
||||
namespace windows {
|
||||
|
||||
class BleGattClient : public api::ble_v2::GattClient {
|
||||
class BleGattClient : public api::ble::GattClient {
|
||||
public:
|
||||
explicit BleGattClient(
|
||||
::winrt::Windows::Devices::Bluetooth::BluetoothLEDevice ble_device);
|
||||
@@ -50,22 +50,21 @@ class BleGattClient : public api::ble_v2::GattClient {
|
||||
const std::vector<Uuid>& characteristic_uuids) override
|
||||
ABSL_LOCKS_EXCLUDED(mutex_);
|
||||
|
||||
absl::optional<api::ble_v2::GattCharacteristic> GetCharacteristic(
|
||||
absl::optional<api::ble::GattCharacteristic> GetCharacteristic(
|
||||
const Uuid& service_uuid, const Uuid& characteristic_uuid) override
|
||||
ABSL_LOCKS_EXCLUDED(mutex_);
|
||||
|
||||
absl::optional<std::string> ReadCharacteristic(
|
||||
const api::ble_v2::GattCharacteristic& characteristic) override
|
||||
const api::ble::GattCharacteristic& characteristic) override
|
||||
ABSL_LOCKS_EXCLUDED(mutex_);
|
||||
|
||||
bool WriteCharacteristic(
|
||||
const api::ble_v2::GattCharacteristic& characteristic,
|
||||
absl::string_view value,
|
||||
api::ble_v2::GattClient::WriteType write_type) override
|
||||
bool WriteCharacteristic(const api::ble::GattCharacteristic& characteristic,
|
||||
absl::string_view value,
|
||||
api::ble::GattClient::WriteType write_type) override
|
||||
ABSL_LOCKS_EXCLUDED(mutex_);
|
||||
|
||||
bool SetCharacteristicSubscription(
|
||||
const api::ble_v2::GattCharacteristic& characteristic, bool enable,
|
||||
const api::ble::GattCharacteristic& characteristic, bool enable,
|
||||
absl::AnyInvocable<void(absl::string_view value)>
|
||||
on_characteristic_changed_cb) override ABSL_LOCKS_EXCLUDED(mutex_);
|
||||
|
||||
@@ -95,7 +94,7 @@ class BleGattClient : public api::ble_v2::GattClient {
|
||||
ABSL_EXCLUSIVE_LOCKS_REQUIRED(mutex_);
|
||||
|
||||
void OnCharacteristicValueChanged(
|
||||
const api::ble_v2::GattCharacteristic& characteristic,
|
||||
const api::ble::GattCharacteristic& characteristic,
|
||||
::winrt::Windows::Devices::Bluetooth::GenericAttributeProfile::
|
||||
GattValueChangedEventArgs args);
|
||||
|
||||
@@ -107,7 +106,7 @@ class BleGattClient : public api::ble_v2::GattClient {
|
||||
GattDeviceServicesResult gatt_devices_services_result_
|
||||
ABSL_GUARDED_BY(mutex_) = nullptr;
|
||||
|
||||
absl::flat_hash_map<api::ble_v2::GattCharacteristic, GattCharacteristicData>
|
||||
absl::flat_hash_map<api::ble::GattCharacteristic, GattCharacteristicData>
|
||||
native_characteristic_map_ ABSL_GUARDED_BY(mutex_);
|
||||
};
|
||||
|
||||
|
||||
@@ -35,7 +35,7 @@
|
||||
#include "absl/time/time.h"
|
||||
#include "absl/types/optional.h"
|
||||
#include "internal/platform/byte_array.h"
|
||||
#include "internal/platform/implementation/ble_v2.h"
|
||||
#include "internal/platform/implementation/ble.h"
|
||||
#include "internal/platform/implementation/bluetooth_adapter.h"
|
||||
#include "internal/platform/implementation/windows/bluetooth_adapter.h"
|
||||
#include "internal/platform/implementation/windows/utils.h"
|
||||
@@ -85,8 +85,8 @@ using ::winrt::Windows::Devices::Bluetooth::GenericAttributeProfile::
|
||||
using ::winrt::Windows::Foundation::Collections::IVectorView;
|
||||
using ::winrt::Windows::Storage::Streams::Buffer;
|
||||
using ::winrt::Windows::Storage::Streams::DataWriter;
|
||||
using Permission = api::ble_v2::GattCharacteristic::Permission;
|
||||
using Property = api::ble_v2::GattCharacteristic::Property;
|
||||
using Permission = api::ble::GattCharacteristic::Permission;
|
||||
using Property = api::ble::GattCharacteristic::Property;
|
||||
|
||||
constexpr absl::Duration kGattServerTimeout = absl::Milliseconds(500);
|
||||
constexpr int kGattServerCheckIntervalInMills = 50;
|
||||
@@ -113,17 +113,17 @@ std::string ConvertGattStatusToString(
|
||||
} // namespace
|
||||
|
||||
BleGattServer::BleGattServer(api::BluetoothAdapter* adapter,
|
||||
api::ble_v2::ServerGattConnectionCallback callback)
|
||||
api::ble::ServerGattConnectionCallback callback)
|
||||
: adapter_(dynamic_cast<BluetoothAdapter*>(adapter)),
|
||||
gatt_connection_callback_(std::move(callback)) {
|
||||
DCHECK(adapter_ != nullptr);
|
||||
}
|
||||
|
||||
absl::optional<api::ble_v2::GattCharacteristic>
|
||||
absl::optional<api::ble::GattCharacteristic>
|
||||
BleGattServer::CreateCharacteristic(
|
||||
const Uuid& service_uuid, const Uuid& characteristic_uuid,
|
||||
api::ble_v2::GattCharacteristic::Permission permission,
|
||||
api::ble_v2::GattCharacteristic::Property property) {
|
||||
api::ble::GattCharacteristic::Permission permission,
|
||||
api::ble::GattCharacteristic::Property property) {
|
||||
absl::MutexLock lock(&mutex_);
|
||||
LOG(INFO) << __func__ << ": create characteristic, service_uuid: "
|
||||
<< std::string(service_uuid)
|
||||
@@ -136,7 +136,7 @@ BleGattServer::CreateCharacteristic(
|
||||
|
||||
service_uuid_ = service_uuid;
|
||||
|
||||
api::ble_v2::GattCharacteristic gatt_characteristic;
|
||||
api::ble::GattCharacteristic gatt_characteristic;
|
||||
gatt_characteristic.uuid = characteristic_uuid;
|
||||
gatt_characteristic.service_uuid = service_uuid;
|
||||
gatt_characteristic.permission = permission;
|
||||
@@ -151,7 +151,7 @@ BleGattServer::CreateCharacteristic(
|
||||
}
|
||||
|
||||
bool BleGattServer::UpdateCharacteristic(
|
||||
const api::ble_v2::GattCharacteristic& characteristic,
|
||||
const api::ble::GattCharacteristic& characteristic,
|
||||
const nearby::ByteArray& value) {
|
||||
absl::MutexLock lock(&mutex_);
|
||||
LOG(INFO) << __func__
|
||||
@@ -192,7 +192,7 @@ bool BleGattServer::UpdateCharacteristic(
|
||||
}
|
||||
|
||||
absl::Status BleGattServer::NotifyCharacteristicChanged(
|
||||
const api::ble_v2::GattCharacteristic& characteristic, bool confirm,
|
||||
const api::ble::GattCharacteristic& characteristic, bool confirm,
|
||||
const ByteArray& new_value) {
|
||||
absl::MutexLock lock(&mutex_);
|
||||
// Currently, the method is not hooked up at platform layer.
|
||||
@@ -598,9 +598,8 @@ void BleGattServer::Characteristic_SubscribedClientsChanged(
|
||||
::winrt::to_hstring(gatt_local_characteristic.Uuid()));
|
||||
|
||||
try {
|
||||
std::vector<api::ble_v2::GattCharacteristic>
|
||||
added_subscribed_characteristics;
|
||||
std::vector<api::ble_v2::GattCharacteristic>
|
||||
std::vector<api::ble::GattCharacteristic> added_subscribed_characteristics;
|
||||
std::vector<api::ble::GattCharacteristic>
|
||||
removed_subscribed_characteristics;
|
||||
|
||||
GattCharacteristicData* characteristic_data =
|
||||
@@ -685,7 +684,7 @@ void BleGattServer::ServiceProvider_AdvertisementStatusChanged(
|
||||
}
|
||||
|
||||
void BleGattServer::NotifyValueChanged(
|
||||
const api::ble_v2::GattCharacteristic& gatt_characteristic) {
|
||||
const api::ble::GattCharacteristic& gatt_characteristic) {
|
||||
try {
|
||||
GattCharacteristicData* characteristic_data =
|
||||
FindGattCharacteristicData(gatt_characteristic);
|
||||
@@ -743,7 +742,7 @@ BleGattServer::FindGattCharacteristicData(
|
||||
|
||||
BleGattServer::GattCharacteristicData*
|
||||
BleGattServer::FindGattCharacteristicData(
|
||||
const api::ble_v2::GattCharacteristic& gatt_characteristic) {
|
||||
const api::ble::GattCharacteristic& gatt_characteristic) {
|
||||
for (auto& characteristic_data : gatt_characteristic_datas_) {
|
||||
if (gatt_characteristic.uuid ==
|
||||
characteristic_data.gatt_characteristic.uuid) {
|
||||
|
||||
@@ -29,7 +29,7 @@
|
||||
#include "absl/synchronization/notification.h"
|
||||
#include "absl/types/optional.h"
|
||||
#include "internal/platform/byte_array.h"
|
||||
#include "internal/platform/implementation/ble_v2.h"
|
||||
#include "internal/platform/implementation/ble.h"
|
||||
#include "internal/platform/implementation/bluetooth_adapter.h"
|
||||
#include "internal/platform/implementation/windows/bluetooth_adapter.h"
|
||||
#include "internal/platform/uuid.h"
|
||||
@@ -41,24 +41,24 @@
|
||||
namespace nearby {
|
||||
namespace windows {
|
||||
|
||||
class BleGattServer : public api::ble_v2::GattServer {
|
||||
class BleGattServer : public api::ble::GattServer {
|
||||
public:
|
||||
// Make sure the adapter parameter is not null.
|
||||
BleGattServer(api::BluetoothAdapter* adapter,
|
||||
api::ble_v2::ServerGattConnectionCallback callback);
|
||||
api::ble::ServerGattConnectionCallback callback);
|
||||
~BleGattServer() override = default;
|
||||
absl::optional<api::ble_v2::GattCharacteristic> CreateCharacteristic(
|
||||
absl::optional<api::ble::GattCharacteristic> CreateCharacteristic(
|
||||
const Uuid& service_uuid, const Uuid& characteristic_uuid,
|
||||
api::ble_v2::GattCharacteristic::Permission permission,
|
||||
api::ble_v2::GattCharacteristic::Property property) override
|
||||
api::ble::GattCharacteristic::Permission permission,
|
||||
api::ble::GattCharacteristic::Property property) override
|
||||
ABSL_LOCKS_EXCLUDED(mutex_);
|
||||
|
||||
bool UpdateCharacteristic(
|
||||
const api::ble_v2::GattCharacteristic& characteristic,
|
||||
const nearby::ByteArray& value) override ABSL_LOCKS_EXCLUDED(mutex_);
|
||||
bool UpdateCharacteristic(const api::ble::GattCharacteristic& characteristic,
|
||||
const nearby::ByteArray& value) override
|
||||
ABSL_LOCKS_EXCLUDED(mutex_);
|
||||
|
||||
absl::Status NotifyCharacteristicChanged(
|
||||
const api::ble_v2::GattCharacteristic& characteristic, bool confirm,
|
||||
const api::ble::GattCharacteristic& characteristic, bool confirm,
|
||||
const ByteArray& new_value) override ABSL_LOCKS_EXCLUDED(mutex_);
|
||||
|
||||
void Stop() override ABSL_LOCKS_EXCLUDED(mutex_);
|
||||
@@ -73,7 +73,7 @@ class BleGattServer : public api::ble_v2::GattServer {
|
||||
private:
|
||||
// Used to save native data related to the GATT characteristic.
|
||||
struct GattCharacteristicData {
|
||||
api::ble_v2::GattCharacteristic gatt_characteristic;
|
||||
api::ble::GattCharacteristic gatt_characteristic;
|
||||
ByteArray data;
|
||||
::winrt::Windows::Devices::Bluetooth::GenericAttributeProfile::
|
||||
GattLocalCharacteristic local_characteristic = nullptr;
|
||||
@@ -88,7 +88,7 @@ class BleGattServer : public api::ble_v2::GattServer {
|
||||
|
||||
bool InitializeGattServer() ABSL_EXCLUSIVE_LOCKS_REQUIRED(mutex_);
|
||||
void NotifyValueChanged(
|
||||
const api::ble_v2::GattCharacteristic& gatt_characteristic)
|
||||
const api::ble::GattCharacteristic& gatt_characteristic)
|
||||
ABSL_EXCLUSIVE_LOCKS_REQUIRED(mutex_);
|
||||
|
||||
GattCharacteristicData* FindGattCharacteristicData(
|
||||
@@ -96,7 +96,7 @@ class BleGattServer : public api::ble_v2::GattServer {
|
||||
GattLocalCharacteristic& gatt_local_characteristic)
|
||||
ABSL_EXCLUSIVE_LOCKS_REQUIRED(mutex_);
|
||||
GattCharacteristicData* FindGattCharacteristicData(
|
||||
const api::ble_v2::GattCharacteristic& gatt_characteristic)
|
||||
const api::ble::GattCharacteristic& gatt_characteristic)
|
||||
ABSL_EXCLUSIVE_LOCKS_REQUIRED(mutex_);
|
||||
|
||||
::winrt::fire_and_forget Characteristic_ReadRequestedAsync(
|
||||
@@ -127,7 +127,7 @@ class BleGattServer : public api::ble_v2::GattServer {
|
||||
absl::Mutex mutex_;
|
||||
|
||||
BluetoothAdapter* const adapter_ = nullptr;
|
||||
api::ble_v2::ServerGattConnectionCallback gatt_connection_callback_{};
|
||||
api::ble::ServerGattConnectionCallback gatt_connection_callback_{};
|
||||
|
||||
::winrt::Windows::Devices::Bluetooth::GenericAttributeProfile::
|
||||
GattServiceProvider gatt_service_provider_ ABSL_GUARDED_BY(mutex_) =
|
||||
|
||||
@@ -21,7 +21,8 @@
|
||||
#include "gtest/gtest.h"
|
||||
#include "absl/synchronization/notification.h"
|
||||
#include "absl/time/time.h"
|
||||
#include "internal/platform/implementation/ble_v2.h"
|
||||
#include "internal/platform/byte_array.h"
|
||||
#include "internal/platform/implementation/ble.h"
|
||||
#include "internal/platform/implementation/windows/bluetooth_adapter.h"
|
||||
|
||||
namespace nearby {
|
||||
@@ -30,26 +31,25 @@ namespace {
|
||||
|
||||
TEST(BleV2GattServer, DISABLED_StartStopAdvertising) {
|
||||
BluetoothAdapter bluetoothAdapter;
|
||||
BleGattServer blev2_gatt_server(&bluetoothAdapter, {});
|
||||
BleGattServer ble_gatt_server(&bluetoothAdapter, {});
|
||||
|
||||
ByteArray
|
||||
service_data; // {.tx_power_level = api::ble_v2::TxPowerLevel::kHigh}
|
||||
ByteArray service_data; // {.tx_power_level = api::ble::TxPowerLevel::kHigh}
|
||||
|
||||
EXPECT_TRUE(blev2_gatt_server.StartAdvertisement(service_data, true));
|
||||
EXPECT_TRUE(ble_gatt_server.StartAdvertisement(service_data, true));
|
||||
|
||||
EXPECT_TRUE(blev2_gatt_server.StopAdvertisement());
|
||||
EXPECT_TRUE(ble_gatt_server.StopAdvertisement());
|
||||
}
|
||||
|
||||
TEST(BleV2GattServer, DISABLED_Stop) {
|
||||
BluetoothAdapter bluetoothAdapter;
|
||||
BleGattServer blev2_gatt_server(&bluetoothAdapter, {});
|
||||
BleGattServer ble_gatt_server(&bluetoothAdapter, {});
|
||||
|
||||
blev2_gatt_server.Stop();
|
||||
ble_gatt_server.Stop();
|
||||
}
|
||||
|
||||
TEST(BleV2GattServer, DISABLED_StopNotifierIsCalled) {
|
||||
BluetoothAdapter bluetoothAdapter;
|
||||
BleGattServer blev2_gatt_server(&bluetoothAdapter, {});
|
||||
BleGattServer ble_gatt_server(&bluetoothAdapter, {});
|
||||
bool is_close_notifier_called = false;
|
||||
absl::Notification notification;
|
||||
std::function<void()> notifier = [&is_close_notifier_called,
|
||||
@@ -57,25 +57,25 @@ TEST(BleV2GattServer, DISABLED_StopNotifierIsCalled) {
|
||||
is_close_notifier_called = true;
|
||||
notification.Notify();
|
||||
};
|
||||
blev2_gatt_server.SetCloseNotifier(std::move(notifier));
|
||||
ble_gatt_server.SetCloseNotifier(std::move(notifier));
|
||||
|
||||
blev2_gatt_server.Stop();
|
||||
ble_gatt_server.Stop();
|
||||
notification.WaitForNotificationWithTimeout(absl::Seconds(1));
|
||||
EXPECT_TRUE(is_close_notifier_called);
|
||||
}
|
||||
|
||||
TEST(BleV2GattServer, DISABLED_CreateCharacteristic) {
|
||||
BluetoothAdapter bluetoothAdapter;
|
||||
BleGattServer blev2_gatt_server(&bluetoothAdapter, {});
|
||||
BleGattServer ble_gatt_server(&bluetoothAdapter, {});
|
||||
|
||||
Uuid service_uuid;
|
||||
Uuid characteristic_uuid;
|
||||
const api::ble_v2::GattCharacteristic::Permission permissions =
|
||||
api::ble_v2::GattCharacteristic::Permission::kNone;
|
||||
const api::ble_v2::GattCharacteristic::Property properties =
|
||||
api::ble_v2::GattCharacteristic::Property::kNone;
|
||||
const api::ble::GattCharacteristic::Permission permissions =
|
||||
api::ble::GattCharacteristic::Permission::kNone;
|
||||
const api::ble::GattCharacteristic::Property properties =
|
||||
api::ble::GattCharacteristic::Property::kNone;
|
||||
|
||||
EXPECT_TRUE(blev2_gatt_server
|
||||
EXPECT_TRUE(ble_gatt_server
|
||||
.CreateCharacteristic(service_uuid, characteristic_uuid,
|
||||
permissions, properties)
|
||||
.has_value());
|
||||
@@ -83,21 +83,21 @@ TEST(BleV2GattServer, DISABLED_CreateCharacteristic) {
|
||||
|
||||
TEST(BleV2GattServer, DISABLED_UpdateCharacteristic) {
|
||||
BluetoothAdapter bluetoothAdapter;
|
||||
BleGattServer blev2_gatt_server(&bluetoothAdapter, {});
|
||||
BleGattServer ble_gatt_server(&bluetoothAdapter, {});
|
||||
|
||||
Uuid service_uuid;
|
||||
Uuid characteristic_uuid;
|
||||
const api::ble_v2::GattCharacteristic::Permission permissions =
|
||||
api::ble_v2::GattCharacteristic::Permission::kNone;
|
||||
const api::ble_v2::GattCharacteristic::Property properties =
|
||||
api::ble_v2::GattCharacteristic::Property::kNone;
|
||||
const api::ble::GattCharacteristic::Permission permissions =
|
||||
api::ble::GattCharacteristic::Permission::kNone;
|
||||
const api::ble::GattCharacteristic::Property properties =
|
||||
api::ble::GattCharacteristic::Property::kNone;
|
||||
|
||||
auto gatt_characteristic = blev2_gatt_server.CreateCharacteristic(
|
||||
auto gatt_characteristic = ble_gatt_server.CreateCharacteristic(
|
||||
service_uuid, characteristic_uuid, permissions, properties);
|
||||
ByteArray value;
|
||||
|
||||
EXPECT_TRUE(blev2_gatt_server.UpdateCharacteristic(
|
||||
gatt_characteristic.value(), value));
|
||||
EXPECT_TRUE(
|
||||
ble_gatt_server.UpdateCharacteristic(gatt_characteristic.value(), value));
|
||||
}
|
||||
|
||||
} // namespace
|
||||
|
||||
+9
-9
@@ -12,7 +12,7 @@
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
#include "internal/platform/implementation/windows/ble_v2_server_socket.h"
|
||||
#include "internal/platform/implementation/windows/ble_server_socket.h"
|
||||
|
||||
#include <cstddef>
|
||||
#include <exception>
|
||||
@@ -21,9 +21,9 @@
|
||||
#include "absl/synchronization/mutex.h"
|
||||
#include "absl/synchronization/notification.h"
|
||||
#include "internal/platform/exception.h"
|
||||
#include "internal/platform/implementation/ble_v2.h"
|
||||
#include "internal/platform/implementation/ble.h"
|
||||
#include "internal/platform/implementation/bluetooth_adapter.h"
|
||||
#include "internal/platform/implementation/windows/ble_v2_socket.h"
|
||||
#include "internal/platform/implementation/windows/ble_socket.h"
|
||||
#include "internal/platform/implementation/windows/bluetooth_adapter.h"
|
||||
#include "internal/platform/implementation/windows/utils.h"
|
||||
#include "internal/platform/logging.h"
|
||||
@@ -31,12 +31,12 @@
|
||||
namespace nearby {
|
||||
namespace windows {
|
||||
|
||||
BleV2ServerSocket::BleV2ServerSocket(api::BluetoothAdapter* adapter)
|
||||
BleServerSocket::BleServerSocket(api::BluetoothAdapter* adapter)
|
||||
: adapter_(dynamic_cast<BluetoothAdapter*>(adapter)) {
|
||||
DCHECK_NE(adapter_, nullptr);
|
||||
}
|
||||
|
||||
std::unique_ptr<api::ble_v2::BleSocket> BleV2ServerSocket::Accept() {
|
||||
std::unique_ptr<api::ble::BleSocket> BleServerSocket::Accept() {
|
||||
absl::MutexLock lock(&mutex_);
|
||||
VLOG(1) << __func__ << ": Accept is called.";
|
||||
|
||||
@@ -45,14 +45,14 @@ std::unique_ptr<api::ble_v2::BleSocket> BleV2ServerSocket::Accept() {
|
||||
}
|
||||
if (closed_) return nullptr;
|
||||
|
||||
BleV2Socket ble_socket = pending_sockets_.front();
|
||||
BleSocket ble_socket = pending_sockets_.front();
|
||||
pending_sockets_.pop_front();
|
||||
|
||||
LOG(INFO) << __func__ << ": Accepted a remote connection.";
|
||||
return std::make_unique<BleV2Socket>(ble_socket);
|
||||
return std::make_unique<BleSocket>(ble_socket);
|
||||
}
|
||||
|
||||
Exception BleV2ServerSocket::Close() {
|
||||
Exception BleServerSocket::Close() {
|
||||
// TODO(b/271031645): implement BLE socket using weave
|
||||
absl::MutexLock lock(&mutex_);
|
||||
VLOG(1) << __func__ << ": Close is called.";
|
||||
@@ -67,7 +67,7 @@ Exception BleV2ServerSocket::Close() {
|
||||
return {Exception::kSuccess};
|
||||
}
|
||||
|
||||
bool BleV2ServerSocket::Bind() {
|
||||
bool BleServerSocket::Bind() {
|
||||
// TODO(b/271031645): implement BLE socket using weave
|
||||
LOG(ERROR) << __func__ << ": GATT socket started.";
|
||||
return true;
|
||||
+10
-10
@@ -12,8 +12,8 @@
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
#ifndef THIRD_PARTY_NEARBY_INTERNAL_PLATFORM_IMPLEMENTATION_WINDOWS_BLE_V2_SERVER_SOCKET_H_
|
||||
#define THIRD_PARTY_NEARBY_INTERNAL_PLATFORM_IMPLEMENTATION_WINDOWS_BLE_V2_SERVER_SOCKET_H_
|
||||
#ifndef THIRD_PARTY_NEARBY_INTERNAL_PLATFORM_IMPLEMENTATION_WINDOWS_BLE_SERVER_SOCKET_H_
|
||||
#define THIRD_PARTY_NEARBY_INTERNAL_PLATFORM_IMPLEMENTATION_WINDOWS_BLE_SERVER_SOCKET_H_
|
||||
|
||||
#include <deque>
|
||||
#include <memory>
|
||||
@@ -21,19 +21,19 @@
|
||||
|
||||
#include "absl/synchronization/mutex.h"
|
||||
#include "absl/synchronization/notification.h"
|
||||
#include "internal/platform/implementation/ble_v2.h"
|
||||
#include "internal/platform/implementation/windows/ble_v2_socket.h"
|
||||
#include "internal/platform/implementation/ble.h"
|
||||
#include "internal/platform/implementation/windows/ble_socket.h"
|
||||
#include "internal/platform/implementation/windows/bluetooth_adapter.h"
|
||||
|
||||
namespace nearby {
|
||||
namespace windows {
|
||||
|
||||
class BleV2ServerSocket : public api::ble_v2::BleServerSocket {
|
||||
class BleServerSocket : public api::ble::BleServerSocket {
|
||||
public:
|
||||
explicit BleV2ServerSocket(api::BluetoothAdapter* adapter);
|
||||
~BleV2ServerSocket() override = default;
|
||||
explicit BleServerSocket(api::BluetoothAdapter* adapter);
|
||||
~BleServerSocket() override = default;
|
||||
|
||||
std::unique_ptr<::nearby::api::ble_v2::BleSocket> Accept() override;
|
||||
std::unique_ptr<::nearby::api::ble::BleSocket> Accept() override;
|
||||
|
||||
Exception Close() override;
|
||||
|
||||
@@ -47,10 +47,10 @@ class BleV2ServerSocket : public api::ble_v2::BleServerSocket {
|
||||
absl::Mutex mutex_;
|
||||
absl::CondVar cond_;
|
||||
bool closed_ = false;
|
||||
std::deque<BleV2Socket> pending_sockets_ ABSL_GUARDED_BY(mutex_);
|
||||
std::deque<BleSocket> pending_sockets_ ABSL_GUARDED_BY(mutex_);
|
||||
};
|
||||
|
||||
} // namespace windows
|
||||
} // namespace nearby
|
||||
|
||||
#endif // THIRD_PARTY_NEARBY_INTERNAL_PLATFORM_IMPLEMENTATION_WINDOWS_BLE_V2_SERVER_SOCKET_H_
|
||||
#endif // THIRD_PARTY_NEARBY_INTERNAL_PLATFORM_IMPLEMENTATION_WINDOWS_BLE_SERVER_SOCKET_H_
|
||||
+10
-10
@@ -12,7 +12,7 @@
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
#include "internal/platform/implementation/windows/ble_v2_socket.h"
|
||||
#include "internal/platform/implementation/windows/ble_socket.h"
|
||||
|
||||
#include <cstdint>
|
||||
|
||||
@@ -25,43 +25,43 @@
|
||||
namespace nearby {
|
||||
namespace windows {
|
||||
|
||||
InputStream& BleV2Socket::GetInputStream() { return input_stream_; }
|
||||
InputStream& BleSocket::GetInputStream() { return input_stream_; }
|
||||
|
||||
OutputStream& BleV2Socket::GetOutputStream() { return output_stream_; }
|
||||
OutputStream& BleSocket::GetOutputStream() { return output_stream_; }
|
||||
|
||||
Exception BleV2Socket::Close() { return {Exception::kSuccess}; }
|
||||
Exception BleSocket::Close() { return {Exception::kSuccess}; }
|
||||
|
||||
bool BleV2Socket::Connect() {
|
||||
bool BleSocket::Connect() {
|
||||
// TODO(b/271031645): implement BLE socket using weave
|
||||
VLOG(1) << __func__ << ": Connect to BLE peripheral";
|
||||
return false;
|
||||
}
|
||||
|
||||
ExceptionOr<ByteArray> BleV2Socket::BleInputStream::Read(std::int64_t size) {
|
||||
ExceptionOr<ByteArray> BleSocket::BleInputStream::Read(std::int64_t size) {
|
||||
// TODO(b/271031645): implement BLE socket using weave
|
||||
VLOG(1) << __func__ << ": Read data size=" << size;
|
||||
return ExceptionOr<ByteArray>(Exception::kIo);
|
||||
}
|
||||
|
||||
Exception BleV2Socket::BleInputStream::Close() {
|
||||
Exception BleSocket::BleInputStream::Close() {
|
||||
// TODO(b/271031645): implement BLE socket using weave
|
||||
VLOG(1) << __func__ << ": Close BLE input stream.";
|
||||
return {Exception::kSuccess};
|
||||
}
|
||||
|
||||
Exception BleV2Socket::BleOutputStream::Write(const ByteArray& data) {
|
||||
Exception BleSocket::BleOutputStream::Write(const ByteArray& data) {
|
||||
// TODO(b/271031645): implement BLE socket using weave
|
||||
VLOG(1) << __func__ << ": Write data size=" << data.size();
|
||||
return {Exception::kIo};
|
||||
}
|
||||
|
||||
Exception BleV2Socket::BleOutputStream::Flush() {
|
||||
Exception BleSocket::BleOutputStream::Flush() {
|
||||
// TODO(b/271031645): implement BLE socket using weave
|
||||
LOG(INFO) << __func__ << ": Flush is called.";
|
||||
return {Exception::kSuccess};
|
||||
}
|
||||
|
||||
Exception BleV2Socket::BleOutputStream::Close() {
|
||||
Exception BleSocket::BleOutputStream::Close() {
|
||||
// TODO(b/271031645): implement BLE socket using weave
|
||||
LOG(INFO) << __func__ << ": close is called.";
|
||||
return {Exception::kSuccess};
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user