mirror of
https://github.com/kidfromjupiter/nearby.git
synced 2026-09-14 22:56:12 -04:00
Merge pull request #5 from hai007/cl-336363104
roll forward to cl/336363104
This commit is contained in:
@@ -335,6 +335,7 @@ Status BasePcpHandler::RequestConnection(ClientProxy* client,
|
||||
OnEndpointFound(client, webrtc_endpoint);
|
||||
}
|
||||
|
||||
<<<<<<< HEAD
|
||||
auto discovered_endpoints = GetDiscoveredEndpoints(endpoint_id);
|
||||
std::unique_ptr<EndpointChannel> channel;
|
||||
ConnectImplResult connect_impl_result;
|
||||
@@ -348,6 +349,21 @@ Status BasePcpHandler::RequestConnection(ClientProxy* client,
|
||||
discovered_endpoints.push_back(additional_endpoint.get());
|
||||
}
|
||||
|
||||
=======
|
||||
auto remote_bluetooth_mac_address =
|
||||
BluetoothUtils::ToString(options.remote_bluetooth_mac_address);
|
||||
if (!remote_bluetooth_mac_address.empty()) {
|
||||
if (AddRemoteBluetoothMacAddressEndpoint(endpoint_id,
|
||||
remote_bluetooth_mac_address))
|
||||
NEARBY_LOGS(INFO) << "Appended remote Bluetooth MAC Address endpoint "
|
||||
<< "[" << remote_bluetooth_mac_address << "]";
|
||||
}
|
||||
|
||||
auto discovered_endpoints = GetDiscoveredEndpoints(endpoint_id);
|
||||
std::unique_ptr<EndpointChannel> channel;
|
||||
ConnectImplResult connect_impl_result;
|
||||
|
||||
>>>>>>> release
|
||||
for (auto connect_endpoint : discovered_endpoints) {
|
||||
connect_impl_result = ConnectImpl(client, connect_endpoint);
|
||||
if (connect_impl_result.status.Ok()) {
|
||||
@@ -651,7 +667,21 @@ void BasePcpHandler::OnIncomingFrame(OfflineFrame& frame,
|
||||
const ConnectionResponseFrame& connection_response =
|
||||
frame.v1().connection_response();
|
||||
|
||||
<<<<<<< HEAD
|
||||
if (connection_response.status() == Status::kSuccess) {
|
||||
=======
|
||||
// For backward compatible, here still check both status and
|
||||
// response parameters until the response feature is roll out in all
|
||||
// supported devices.
|
||||
bool accepted = false;
|
||||
if (connection_response.has_response()) {
|
||||
accepted =
|
||||
connection_response.response() == ConnectionResponseFrame::ACCEPT;
|
||||
} else {
|
||||
accepted = connection_response.status() == Status::kSuccess;
|
||||
}
|
||||
if (accepted) {
|
||||
>>>>>>> release
|
||||
NEARBY_LOG(INFO, "OnConnectionResponse: remote accepted; id=%s",
|
||||
endpoint_id.c_str());
|
||||
client->RemoteEndpointAcceptedConnection(endpoint_id);
|
||||
@@ -992,6 +1022,7 @@ proto::connections::Medium BasePcpHandler::ChooseBestUpgradeMedium(
|
||||
return proto::connections::Medium::UNKNOWN_MEDIUM;
|
||||
}
|
||||
|
||||
<<<<<<< HEAD
|
||||
std::unique_ptr<BasePcpHandler::DiscoveredEndpoint>
|
||||
BasePcpHandler::GetRemoteBluetoothMacAddressEndpoint(
|
||||
std::string endpoint_id, std::string remote_bluetooth_mac_address,
|
||||
@@ -1005,14 +1036,36 @@ BasePcpHandler::GetRemoteBluetoothMacAddressEndpoint(
|
||||
<< "Cannot append remote Bluetooth MAC Address, because endpointId "
|
||||
<< endpoint_id << " has not been discovered";
|
||||
return nullptr;
|
||||
=======
|
||||
bool BasePcpHandler::AddRemoteBluetoothMacAddressEndpoint(
|
||||
std::string endpoint_id, std::string remote_bluetooth_mac_address) {
|
||||
if (!discovery_options_.allowed.bluetooth) {
|
||||
return false;
|
||||
}
|
||||
|
||||
auto endpoints = GetDiscoveredEndpoints(endpoint_id);
|
||||
if (endpoints.empty()) {
|
||||
NEARBY_LOGS(INFO) << "Cannot append remote Bluetooth MAC Address endpoint, "
|
||||
"because endpointId "
|
||||
<< endpoint_id << " has not been discovered "
|
||||
<< "[" << remote_bluetooth_mac_address << "]";
|
||||
return false;
|
||||
>>>>>>> release
|
||||
}
|
||||
|
||||
for (auto endpoint : endpoints) {
|
||||
if (endpoint->medium == proto::connections::Medium::BLUETOOTH) {
|
||||
NEARBY_LOGS(INFO)
|
||||
<<<<<<< HEAD
|
||||
<< "Cannot append remote Bluetooth MAC Address, because the "
|
||||
"endpoint has already been found over Bluetooth.";
|
||||
return nullptr;
|
||||
=======
|
||||
<< "Cannot append remote Bluetooth MAC Address endpoint, because the "
|
||||
"endpoint has already been found over Bluetooth "
|
||||
<< "[" << remote_bluetooth_mac_address << "]";
|
||||
return false;
|
||||
>>>>>>> release
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1020,6 +1073,7 @@ BasePcpHandler::GetRemoteBluetoothMacAddressEndpoint(
|
||||
mediums_->GetBluetoothClassic().GetRemoteDevice(
|
||||
remote_bluetooth_mac_address);
|
||||
if (!remote_bluetooth_device.IsValid()) {
|
||||
<<<<<<< HEAD
|
||||
NEARBY_LOGS(INFO)
|
||||
<< "Cannot append remote Bluetooth MAC Address, because a valid "
|
||||
"Bluetooth device could not be derived.";
|
||||
@@ -1028,6 +1082,17 @@ BasePcpHandler::GetRemoteBluetoothMacAddressEndpoint(
|
||||
|
||||
auto bluetooth_endpoint =
|
||||
std::make_unique<BluetoothEndpoint>(BluetoothEndpoint{
|
||||
=======
|
||||
NEARBY_LOGS(INFO) << "Cannot append remote Bluetooth MAC Address endpoint, "
|
||||
"because a valid "
|
||||
"Bluetooth device could not be derived "
|
||||
<< "[" << remote_bluetooth_mac_address << "]";
|
||||
return false;
|
||||
}
|
||||
|
||||
auto bluetooth_endpoint =
|
||||
std::make_shared<BluetoothEndpoint>(BluetoothEndpoint{
|
||||
>>>>>>> release
|
||||
{
|
||||
endpoint_id,
|
||||
endpoints[0]->endpoint_info,
|
||||
@@ -1036,9 +1101,15 @@ BasePcpHandler::GetRemoteBluetoothMacAddressEndpoint(
|
||||
},
|
||||
remote_bluetooth_device,
|
||||
});
|
||||
<<<<<<< HEAD
|
||||
NEARBY_LOGS(INFO) << "Appended remote Bluetooth device "
|
||||
<< remote_bluetooth_mac_address;
|
||||
return bluetooth_endpoint;
|
||||
=======
|
||||
|
||||
discovered_endpoints_.emplace(endpoint_id, std::move(bluetooth_endpoint));
|
||||
return true;
|
||||
>>>>>>> release
|
||||
}
|
||||
|
||||
void BasePcpHandler::EvaluateConnectionResult(ClientProxy* client,
|
||||
|
||||
@@ -84,6 +84,16 @@ Swapper<T> MakeSwapper(T* value) {
|
||||
return Swapper<T>(value);
|
||||
}
|
||||
|
||||
<<<<<<< HEAD
|
||||
=======
|
||||
// Represents the WebRtc state that mediums are connectable or not.
|
||||
enum class WebRtcState {
|
||||
kUndefined = 0,
|
||||
kConnectable = 1,
|
||||
kUnconnectable = 2,
|
||||
};
|
||||
|
||||
>>>>>>> release
|
||||
// A base implementation of the PcpHandler interface that takes care of all
|
||||
// bookkeeping and handshake protocols that are common across all PcpHandler
|
||||
// implementations -- thus, every concrete PcpHandler implementation must extend
|
||||
@@ -412,10 +422,18 @@ class BasePcpHandler : public PcpHandler,
|
||||
proto::connections::Medium ChooseBestUpgradeMedium(
|
||||
const std::vector<proto::connections::Medium>& supported_mediums);
|
||||
|
||||
<<<<<<< HEAD
|
||||
std::unique_ptr<BasePcpHandler::DiscoveredEndpoint>
|
||||
GetRemoteBluetoothMacAddressEndpoint(
|
||||
std::string endpoint_id, std::string remote_bluetooth_mac_address,
|
||||
std::vector<DiscoveredEndpoint*> endpoints);
|
||||
=======
|
||||
// Returns true if the bluetooth endpoint based on remote bluetooth mac
|
||||
// address is created and added into discovered_endpoints_ with key
|
||||
// endpoint_id.
|
||||
bool AddRemoteBluetoothMacAddressEndpoint(
|
||||
std::string endpoint_id, std::string remote_bluetooth_mac_address);
|
||||
>>>>>>> release
|
||||
|
||||
void ProcessPreConnectionInitiationFailure(const std::string& endpoint_id,
|
||||
EndpointChannel* channel,
|
||||
|
||||
@@ -16,6 +16,10 @@
|
||||
|
||||
#include <inttypes.h>
|
||||
|
||||
<<<<<<< HEAD
|
||||
=======
|
||||
#include "core_v2/internal/base_pcp_handler.h"
|
||||
>>>>>>> release
|
||||
#include "platform_v2/base/base_input_stream.h"
|
||||
#include "platform_v2/public/logging.h"
|
||||
#include "absl/strings/escaping.h"
|
||||
@@ -28,23 +32,45 @@ BleAdvertisement::BleAdvertisement(Version version, Pcp pcp,
|
||||
const ByteArray& service_id_hash,
|
||||
const std::string& endpoint_id,
|
||||
const ByteArray& endpoint_info,
|
||||
<<<<<<< HEAD
|
||||
const std::string& bluetooth_mac_address) {
|
||||
DoInitialize(/*fast_advertisement=*/false, version, pcp, service_id_hash,
|
||||
endpoint_id, endpoint_info, bluetooth_mac_address);
|
||||
=======
|
||||
const std::string& bluetooth_mac_address,
|
||||
const ByteArray& uwb_address,
|
||||
WebRtcState web_rtc_state) {
|
||||
DoInitialize(/*fast_advertisement=*/false, version, pcp, service_id_hash,
|
||||
endpoint_id, endpoint_info, bluetooth_mac_address, uwb_address,
|
||||
web_rtc_state);
|
||||
>>>>>>> release
|
||||
}
|
||||
|
||||
BleAdvertisement::BleAdvertisement(Version version, Pcp pcp,
|
||||
const std::string& endpoint_id,
|
||||
<<<<<<< HEAD
|
||||
const ByteArray& endpoint_info) {
|
||||
DoInitialize(/*fast_advertisement=*/true, version, pcp, {}, endpoint_id,
|
||||
endpoint_info, {});
|
||||
=======
|
||||
const ByteArray& endpoint_info,
|
||||
const ByteArray& uwb_address) {
|
||||
DoInitialize(/*fast_advertisement=*/true, version, pcp, {}, endpoint_id,
|
||||
endpoint_info, {}, uwb_address, WebRtcState::kUndefined);
|
||||
>>>>>>> release
|
||||
}
|
||||
|
||||
void BleAdvertisement::DoInitialize(bool fast_advertisement, Version version,
|
||||
Pcp pcp, const ByteArray& service_id_hash,
|
||||
const std::string& endpoint_id,
|
||||
const ByteArray& endpoint_info,
|
||||
<<<<<<< HEAD
|
||||
const std::string& bluetooth_mac_address) {
|
||||
=======
|
||||
const std::string& bluetooth_mac_address,
|
||||
const ByteArray& uwb_address,
|
||||
WebRtcState web_rtc_state) {
|
||||
>>>>>>> release
|
||||
fast_advertisement_ = fast_advertisement;
|
||||
if (!fast_advertisement_) {
|
||||
if (service_id_hash.size() != kServiceIdHashLength) return;
|
||||
@@ -71,10 +97,19 @@ void BleAdvertisement::DoInitialize(bool fast_advertisement, Version version,
|
||||
service_id_hash_ = service_id_hash;
|
||||
endpoint_id_ = endpoint_id;
|
||||
endpoint_info_ = endpoint_info;
|
||||
<<<<<<< HEAD
|
||||
=======
|
||||
uwb_address_ = uwb_address;
|
||||
>>>>>>> release
|
||||
if (!fast_advertisement_) {
|
||||
if (!BluetoothUtils::FromString(bluetooth_mac_address).Empty()) {
|
||||
bluetooth_mac_address_ = bluetooth_mac_address;
|
||||
}
|
||||
<<<<<<< HEAD
|
||||
=======
|
||||
|
||||
web_rtc_state_ = web_rtc_state;
|
||||
>>>>>>> release
|
||||
}
|
||||
}
|
||||
|
||||
@@ -134,7 +169,11 @@ BleAdvertisement::BleAdvertisement(bool fast_advertisement,
|
||||
// The next 4 bytes are supposed to be the endpoint_id.
|
||||
endpoint_id_ = std::string{base_input_stream.ReadBytes(kEndpointIdLength)};
|
||||
|
||||
<<<<<<< HEAD
|
||||
// The next 1 byte are supposed to be the length of the endpoint_info.
|
||||
=======
|
||||
// The next 1 byte is supposed to be the length of the endpoint_info.
|
||||
>>>>>>> release
|
||||
std::uint32_t expected_endpoint_info_length = base_input_stream.ReadUint8();
|
||||
|
||||
// The next x bytes are the endpoint info. (Max length is 131 bytes or 17
|
||||
@@ -151,7 +190,11 @@ BleAdvertisement::BleAdvertisement(bool fast_advertisement,
|
||||
fast_advertisement_, expected_endpoint_info_length,
|
||||
endpoint_info_.size());
|
||||
|
||||
<<<<<<< HEAD
|
||||
// Clear enpoint_id for validadity.
|
||||
=======
|
||||
// Clear enpoint_id for validity.
|
||||
>>>>>>> release
|
||||
endpoint_id_.clear();
|
||||
return;
|
||||
}
|
||||
@@ -164,6 +207,38 @@ BleAdvertisement::BleAdvertisement(bool fast_advertisement,
|
||||
BluetoothUtils::ToString(bluetooth_mac_address_bytes);
|
||||
}
|
||||
|
||||
<<<<<<< HEAD
|
||||
=======
|
||||
// The next 1 byte is supposed to be the length of the uwb_address.
|
||||
std::uint32_t expected_uwb_address_length = base_input_stream.ReadUint8();
|
||||
// If the length of uwb_address is not zero, then retrieve it.
|
||||
if (expected_uwb_address_length != 0) {
|
||||
uwb_address_ = base_input_stream.ReadBytes(expected_uwb_address_length);
|
||||
if (uwb_address_.Empty() ||
|
||||
uwb_address_.size() != expected_uwb_address_length) {
|
||||
NEARBY_LOG(INFO,
|
||||
"Cannot deserialize BleAdvertisement: "
|
||||
"expected uwbAddress size to be %d bytes, got %" PRIu64,
|
||||
expected_uwb_address_length, uwb_address_.size());
|
||||
|
||||
// Clear enpoint_id for validity.
|
||||
endpoint_id_.clear();
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
// The next 1 byte is extra field.
|
||||
web_rtc_state_ = WebRtcState::kUndefined;
|
||||
if (!fast_advertisement_) {
|
||||
if (base_input_stream.IsAvailable(kExtraFieldLength)) {
|
||||
auto extra_field = static_cast<char>(base_input_stream.ReadUint8());
|
||||
web_rtc_state_ = (extra_field & kWebRtcConnectableFlagBitmask) == 1
|
||||
? WebRtcState::kConnectable
|
||||
: WebRtcState::kUnconnectable;
|
||||
}
|
||||
}
|
||||
|
||||
>>>>>>> release
|
||||
base_input_stream.Close();
|
||||
}
|
||||
|
||||
@@ -182,13 +257,20 @@ BleAdvertisement::operator ByteArray() const {
|
||||
if (fast_advertisement_) {
|
||||
// clang-format off
|
||||
out = absl::StrCat(std::string(1, version_and_pcp_byte),
|
||||
<<<<<<< HEAD
|
||||
endpoint_id_,
|
||||
std::string(1, endpoint_info_.size()),
|
||||
std::string(endpoint_info_));
|
||||
=======
|
||||
endpoint_id_,
|
||||
std::string(1, endpoint_info_.size()),
|
||||
std::string(endpoint_info_));
|
||||
>>>>>>> release
|
||||
// clang-format on
|
||||
} else {
|
||||
// clang-format off
|
||||
out = absl::StrCat(std::string(1, version_and_pcp_byte),
|
||||
<<<<<<< HEAD
|
||||
std::string(service_id_hash_),
|
||||
endpoint_id_,
|
||||
std::string(1, endpoint_info_.size()),
|
||||
@@ -197,6 +279,16 @@ BleAdvertisement::operator ByteArray() const {
|
||||
|
||||
// The next 6 bytes are the bluetooth mac address. If bluetooth_mac_address
|
||||
// is invalid or empty, we get back a null byte array.
|
||||
=======
|
||||
std::string(service_id_hash_),
|
||||
endpoint_id_,
|
||||
std::string(1, endpoint_info_.size()),
|
||||
std::string(endpoint_info_));
|
||||
// clang-format on
|
||||
|
||||
// The next 6 bytes are the bluetooth mac address. If bluetooth_mac_address
|
||||
// is invalid or empty, we get back a empty byte array.
|
||||
>>>>>>> release
|
||||
auto bluetooth_mac_address_bytes{
|
||||
BluetoothUtils::FromString(bluetooth_mac_address_)};
|
||||
if (!bluetooth_mac_address_bytes.Empty()) {
|
||||
@@ -204,6 +296,28 @@ BleAdvertisement::operator ByteArray() const {
|
||||
}
|
||||
}
|
||||
|
||||
<<<<<<< HEAD
|
||||
=======
|
||||
// The next bytes are UWB address field.
|
||||
if (!uwb_address_.Empty()) {
|
||||
absl::StrAppend(&out, std::string(1, uwb_address_.size()));
|
||||
absl::StrAppend(&out, std::string(uwb_address_));
|
||||
} else {
|
||||
// Write UWB address with length 0 to be able to read the next field when
|
||||
// decode.
|
||||
absl::StrAppend(&out, std::string(1, uwb_address_.size()));
|
||||
}
|
||||
|
||||
// The next 1 byte is extra field.
|
||||
if (!fast_advertisement_) {
|
||||
int web_rtc_connectable_flag =
|
||||
(web_rtc_state_ == WebRtcState::kConnectable) ? 1 : 0;
|
||||
char extra_field_byte = static_cast<char>(web_rtc_connectable_flag) &
|
||||
kWebRtcConnectableFlagBitmask;
|
||||
absl::StrAppend(&out, std::string(1, extra_field_byte));
|
||||
}
|
||||
|
||||
>>>>>>> release
|
||||
return ByteArray(std::move(out));
|
||||
}
|
||||
|
||||
|
||||
@@ -15,6 +15,10 @@
|
||||
#ifndef CORE_V2_INTERNAL_BLE_ADVERTISEMENT_H_
|
||||
#define CORE_V2_INTERNAL_BLE_ADVERTISEMENT_H_
|
||||
|
||||
<<<<<<< HEAD
|
||||
=======
|
||||
#include "core_v2/internal/base_pcp_handler.h"
|
||||
>>>>>>> release
|
||||
#include "core_v2/internal/pcp.h"
|
||||
#include "platform_v2/base/bluetooth_utils.h"
|
||||
#include "platform_v2/base/byte_array.h"
|
||||
@@ -27,7 +31,11 @@ namespace connections {
|
||||
// Advertising + Discovery.
|
||||
//
|
||||
// <p>[VERSION][PCP][SERVICE_ID_HASH][ENDPOINT_ID][ENDPOINT_INFO_SIZE]
|
||||
<<<<<<< HEAD
|
||||
// [ENDPOINT_INFO][BLUETOOTH_MAC]
|
||||
=======
|
||||
// [ENDPOINT_INFO][BLUETOOTH_MAC][UWB_ADDRESS_SIZE][UWB_ADDRESS][EXTRA_FIELD]
|
||||
>>>>>>> release
|
||||
//
|
||||
// <p>The fast version of this advertisement simply omits SERVICE_ID_HASH and
|
||||
// the Bluetooth MAC address.
|
||||
@@ -49,27 +57,56 @@ class BleAdvertisement {
|
||||
static constexpr int kServiceIdHashLength = 3;
|
||||
static constexpr int kEndpointIdLength = 4;
|
||||
static constexpr int kEndpointInfoSizeLength = 1;
|
||||
<<<<<<< HEAD
|
||||
static constexpr int kEndpointInfoLengthBitmask = 0x0FF;
|
||||
static constexpr int kMinAdvertisementLength =
|
||||
kVersionAndPcpLength + kServiceIdHashLength + kEndpointIdLength +
|
||||
kEndpointInfoSizeLength + BluetoothUtils::kBluetoothMacAddressLength;
|
||||
=======
|
||||
static constexpr int kBluetoothMacAddressLength =
|
||||
BluetoothUtils::kBluetoothMacAddressLength;
|
||||
static constexpr int kUwbAddressSizeLength = 1;
|
||||
static constexpr int kExtraFieldLength = 1;
|
||||
static constexpr int kEndpointInfoLengthBitmask = 0x0FF;
|
||||
static constexpr int kWebRtcConnectableFlagBitmask = 0x01;
|
||||
static constexpr int kMinAdvertisementLength =
|
||||
kVersionAndPcpLength + kServiceIdHashLength + kEndpointIdLength +
|
||||
kEndpointInfoSizeLength + kBluetoothMacAddressLength;
|
||||
>>>>>>> release
|
||||
|
||||
// The difference between normal and fast advertisements is that the fast one
|
||||
// omits the SERVICE_ID_HASH and Bluetooth MAC address. This is done to save
|
||||
// space.
|
||||
<<<<<<< HEAD
|
||||
static constexpr int kMinFastAdvertisementLength =
|
||||
kMinAdvertisementLength - kServiceIdHashLength -
|
||||
BluetoothUtils::kBluetoothMacAddressLength;
|
||||
=======
|
||||
static constexpr int kMinFastAdvertisementLength = kMinAdvertisementLength -
|
||||
kServiceIdHashLength -
|
||||
kBluetoothMacAddressLength;
|
||||
>>>>>>> release
|
||||
static constexpr int kMaxEndpointInfoLength = 131;
|
||||
static constexpr int kMaxFastEndpointInfoLength = 17;
|
||||
|
||||
BleAdvertisement() = default;
|
||||
BleAdvertisement(Version version, Pcp pcp, const std::string& endpoint_id,
|
||||
<<<<<<< HEAD
|
||||
const ByteArray& endpoint_info);
|
||||
BleAdvertisement(Version version, Pcp pcp, const ByteArray& service_id_hash,
|
||||
const std::string& endpoint_id,
|
||||
const ByteArray& endpoint_info,
|
||||
const std::string& bluetooth_mac_address);
|
||||
=======
|
||||
const ByteArray& endpoint_info,
|
||||
const ByteArray& uwb_address);
|
||||
BleAdvertisement(Version version, Pcp pcp, const ByteArray& service_id_hash,
|
||||
const std::string& endpoint_id,
|
||||
const ByteArray& endpoint_info,
|
||||
const std::string& bluetooth_mac_address,
|
||||
const ByteArray& uwb_address,
|
||||
WebRtcState web_rtc_state);
|
||||
>>>>>>> release
|
||||
BleAdvertisement(bool fast_advertisement,
|
||||
const ByteArray& ble_advertisement_bytes);
|
||||
BleAdvertisement(const BleAdvertisement&) = default;
|
||||
@@ -88,21 +125,41 @@ class BleAdvertisement {
|
||||
std::string GetEndpointId() const { return endpoint_id_; }
|
||||
ByteArray GetEndpointInfo() const { return endpoint_info_; }
|
||||
std::string GetBluetoothMacAddress() const { return bluetooth_mac_address_; }
|
||||
<<<<<<< HEAD
|
||||
=======
|
||||
ByteArray GetUwbAddress() const { return uwb_address_; }
|
||||
WebRtcState GetWebRtcState() const { return web_rtc_state_; }
|
||||
>>>>>>> release
|
||||
|
||||
private:
|
||||
void DoInitialize(bool fast_advertisement, Version version, Pcp pcp,
|
||||
const ByteArray& service_id_hash,
|
||||
const std::string& endpoint_id,
|
||||
const ByteArray& endpoint_info,
|
||||
<<<<<<< HEAD
|
||||
const std::string& bluetooth_mac_address);
|
||||
|
||||
bool fast_advertisement_ = false;
|
||||
Version version_ = Version::kUndefined;
|
||||
Pcp pcp_ = Pcp::kUnknown;
|
||||
=======
|
||||
const std::string& bluetooth_mac_address,
|
||||
const ByteArray& uwb_address, WebRtcState web_rtc_state);
|
||||
|
||||
bool fast_advertisement_ = false;
|
||||
Version version_{Version::kUndefined};
|
||||
Pcp pcp_{Pcp::kUnknown};
|
||||
>>>>>>> release
|
||||
ByteArray service_id_hash_;
|
||||
std::string endpoint_id_;
|
||||
ByteArray endpoint_info_;
|
||||
std::string bluetooth_mac_address_;
|
||||
<<<<<<< HEAD
|
||||
=======
|
||||
// TODO(b/169550050): Define UWB address field.
|
||||
ByteArray uwb_address_;
|
||||
WebRtcState web_rtc_state_{WebRtcState::kUndefined};
|
||||
>>>>>>> release
|
||||
};
|
||||
|
||||
} // namespace connections
|
||||
|
||||
@@ -14,6 +14,10 @@
|
||||
|
||||
#include "core_v2/internal/ble_advertisement.h"
|
||||
|
||||
<<<<<<< HEAD
|
||||
=======
|
||||
#include "core_v2/internal/base_pcp_handler.h"
|
||||
>>>>>>> release
|
||||
#include "gtest/gtest.h"
|
||||
|
||||
namespace location {
|
||||
@@ -29,6 +33,7 @@ constexpr absl::string_view kEndpointName{
|
||||
"How much wood can a woodchuck chuck if a wood chuck would chuck wood?"};
|
||||
constexpr absl::string_view kFastAdvertisementEndpointName{"Fast Advertise"};
|
||||
constexpr absl::string_view kBluetoothMacAddress{"00:00:E6:88:64:13"};
|
||||
<<<<<<< HEAD
|
||||
|
||||
TEST(BleAdvertisementTest, ConstructionWorks) {
|
||||
ByteArray service_id_hash{std::string(kServiceIdHashBytes)};
|
||||
@@ -37,6 +42,22 @@ TEST(BleAdvertisementTest, ConstructionWorks) {
|
||||
kVersion, kPcp,
|
||||
service_id_hash, std::string(kEndpointId),
|
||||
endpoint_info, std::string(kBluetoothMacAddress)};
|
||||
=======
|
||||
constexpr WebRtcState kWebRtcState = WebRtcState::kConnectable;
|
||||
|
||||
// TODO(b/169550050): Implement UWBAddress.
|
||||
TEST(BleAdvertisementTest, ConstructionWorks) {
|
||||
ByteArray service_id_hash{std::string(kServiceIdHashBytes)};
|
||||
ByteArray endpoint_info{std::string(kEndpointName)};
|
||||
BleAdvertisement ble_advertisement{kVersion,
|
||||
kPcp,
|
||||
service_id_hash,
|
||||
std::string(kEndpointId),
|
||||
endpoint_info,
|
||||
std::string(kBluetoothMacAddress),
|
||||
ByteArray{},
|
||||
kWebRtcState};
|
||||
>>>>>>> release
|
||||
|
||||
EXPECT_TRUE(ble_advertisement.IsValid());
|
||||
EXPECT_FALSE(ble_advertisement.IsFastAdvertisement());
|
||||
@@ -46,12 +67,24 @@ TEST(BleAdvertisementTest, ConstructionWorks) {
|
||||
EXPECT_EQ(kEndpointId, ble_advertisement.GetEndpointId());
|
||||
EXPECT_EQ(endpoint_info, ble_advertisement.GetEndpointInfo());
|
||||
EXPECT_EQ(kBluetoothMacAddress, ble_advertisement.GetBluetoothMacAddress());
|
||||
<<<<<<< HEAD
|
||||
=======
|
||||
EXPECT_EQ(kWebRtcState, ble_advertisement.GetWebRtcState());
|
||||
>>>>>>> release
|
||||
}
|
||||
|
||||
TEST(BleAdvertisementTest, ConstructionWorksForFastAdvertisement) {
|
||||
ByteArray fast_endpoint_info{std::string(kFastAdvertisementEndpointName)};
|
||||
<<<<<<< HEAD
|
||||
BleAdvertisement ble_advertisement{kVersion, kPcp, std::string(kEndpointId),
|
||||
fast_endpoint_info};
|
||||
=======
|
||||
BleAdvertisement ble_advertisement{kVersion,
|
||||
kPcp,
|
||||
std::string(kEndpointId),
|
||||
fast_endpoint_info,
|
||||
ByteArray{}};
|
||||
>>>>>>> release
|
||||
|
||||
EXPECT_TRUE(ble_advertisement.IsValid());
|
||||
EXPECT_TRUE(ble_advertisement.IsFastAdvertisement());
|
||||
@@ -59,6 +92,10 @@ TEST(BleAdvertisementTest, ConstructionWorksForFastAdvertisement) {
|
||||
EXPECT_EQ(kPcp, ble_advertisement.GetPcp());
|
||||
EXPECT_EQ(kEndpointId, ble_advertisement.GetEndpointId());
|
||||
EXPECT_EQ(fast_endpoint_info, ble_advertisement.GetEndpointInfo());
|
||||
<<<<<<< HEAD
|
||||
=======
|
||||
EXPECT_EQ(WebRtcState::kUndefined, ble_advertisement.GetWebRtcState());
|
||||
>>>>>>> release
|
||||
}
|
||||
|
||||
TEST(BleAdvertisementTest, ConstructionWorksWithEmptyEndpointInfo) {
|
||||
@@ -70,7 +107,13 @@ TEST(BleAdvertisementTest, ConstructionWorksWithEmptyEndpointInfo) {
|
||||
service_id_hash,
|
||||
std::string(kEndpointId),
|
||||
empty_endpoint_info,
|
||||
<<<<<<< HEAD
|
||||
std::string(kBluetoothMacAddress)};
|
||||
=======
|
||||
std::string(kBluetoothMacAddress),
|
||||
ByteArray{},
|
||||
kWebRtcState};
|
||||
>>>>>>> release
|
||||
|
||||
EXPECT_TRUE(ble_advertisement.IsValid());
|
||||
EXPECT_FALSE(ble_advertisement.IsFastAdvertisement());
|
||||
@@ -80,14 +123,26 @@ TEST(BleAdvertisementTest, ConstructionWorksWithEmptyEndpointInfo) {
|
||||
EXPECT_EQ(kEndpointId, ble_advertisement.GetEndpointId());
|
||||
EXPECT_EQ(empty_endpoint_info, ble_advertisement.GetEndpointInfo());
|
||||
EXPECT_EQ(kBluetoothMacAddress, ble_advertisement.GetBluetoothMacAddress());
|
||||
<<<<<<< HEAD
|
||||
=======
|
||||
EXPECT_EQ(kWebRtcState, ble_advertisement.GetWebRtcState());
|
||||
>>>>>>> release
|
||||
}
|
||||
|
||||
TEST(BleAdvertisementTest,
|
||||
ConstructionWorksWithEmptyEndpointInfoForFastAdvertisement) {
|
||||
ByteArray empty_endpoint_info;
|
||||
|
||||
<<<<<<< HEAD
|
||||
BleAdvertisement ble_advertisement{kVersion, kPcp, std::string(kEndpointId),
|
||||
empty_endpoint_info};
|
||||
=======
|
||||
BleAdvertisement ble_advertisement{kVersion,
|
||||
kPcp,
|
||||
std::string(kEndpointId),
|
||||
empty_endpoint_info,
|
||||
ByteArray{}};
|
||||
>>>>>>> release
|
||||
|
||||
EXPECT_TRUE(ble_advertisement.IsValid());
|
||||
EXPECT_TRUE(ble_advertisement.IsFastAdvertisement());
|
||||
@@ -95,6 +150,10 @@ TEST(BleAdvertisementTest,
|
||||
EXPECT_EQ(kPcp, ble_advertisement.GetPcp());
|
||||
EXPECT_EQ(kEndpointId, ble_advertisement.GetEndpointId());
|
||||
EXPECT_EQ(empty_endpoint_info, ble_advertisement.GetEndpointInfo());
|
||||
<<<<<<< HEAD
|
||||
=======
|
||||
EXPECT_EQ(WebRtcState::kUndefined, ble_advertisement.GetWebRtcState());
|
||||
>>>>>>> release
|
||||
}
|
||||
|
||||
TEST(BleAdvertisementTest, ConstructionWorksWithEmojiEndpointInfo) {
|
||||
@@ -106,7 +165,13 @@ TEST(BleAdvertisementTest, ConstructionWorksWithEmojiEndpointInfo) {
|
||||
service_id_hash,
|
||||
std::string(kEndpointId),
|
||||
emoji_endpoint_info,
|
||||
<<<<<<< HEAD
|
||||
std::string(kBluetoothMacAddress)};
|
||||
=======
|
||||
std::string(kBluetoothMacAddress),
|
||||
ByteArray{},
|
||||
kWebRtcState};
|
||||
>>>>>>> release
|
||||
|
||||
EXPECT_TRUE(ble_advertisement.IsValid());
|
||||
EXPECT_FALSE(ble_advertisement.IsFastAdvertisement());
|
||||
@@ -116,14 +181,26 @@ TEST(BleAdvertisementTest, ConstructionWorksWithEmojiEndpointInfo) {
|
||||
EXPECT_EQ(kEndpointId, ble_advertisement.GetEndpointId());
|
||||
EXPECT_EQ(emoji_endpoint_info, ble_advertisement.GetEndpointInfo());
|
||||
EXPECT_EQ(kBluetoothMacAddress, ble_advertisement.GetBluetoothMacAddress());
|
||||
<<<<<<< HEAD
|
||||
=======
|
||||
EXPECT_EQ(kWebRtcState, ble_advertisement.GetWebRtcState());
|
||||
>>>>>>> release
|
||||
}
|
||||
|
||||
TEST(BleAdvertisementTest,
|
||||
ConstructionWorksWithEmojiEndpointInfoForFastAdvertisement) {
|
||||
ByteArray emoji_endpoint_info{std::string("\u0001F450 \u0001F450")};
|
||||
|
||||
<<<<<<< HEAD
|
||||
BleAdvertisement ble_advertisement{kVersion, kPcp, std::string(kEndpointId),
|
||||
emoji_endpoint_info};
|
||||
=======
|
||||
BleAdvertisement ble_advertisement{kVersion,
|
||||
kPcp,
|
||||
std::string(kEndpointId),
|
||||
emoji_endpoint_info,
|
||||
ByteArray{}};
|
||||
>>>>>>> release
|
||||
|
||||
EXPECT_TRUE(ble_advertisement.IsValid());
|
||||
EXPECT_TRUE(ble_advertisement.IsFastAdvertisement());
|
||||
@@ -131,6 +208,10 @@ TEST(BleAdvertisementTest,
|
||||
EXPECT_EQ(kPcp, ble_advertisement.GetPcp());
|
||||
EXPECT_EQ(kEndpointId, ble_advertisement.GetEndpointId());
|
||||
EXPECT_EQ(emoji_endpoint_info, ble_advertisement.GetEndpointInfo());
|
||||
<<<<<<< HEAD
|
||||
=======
|
||||
EXPECT_EQ(WebRtcState::kUndefined, ble_advertisement.GetWebRtcState());
|
||||
>>>>>>> release
|
||||
}
|
||||
|
||||
TEST(BleAdvertisementTest, ConstructionFailsWithLongEndpointInfo) {
|
||||
@@ -139,10 +220,21 @@ TEST(BleAdvertisementTest, ConstructionFailsWithLongEndpointInfo) {
|
||||
ByteArray long_endpoint_info{long_endpoint_name};
|
||||
|
||||
ByteArray service_id_hash{std::string(kServiceIdHashBytes)};
|
||||
<<<<<<< HEAD
|
||||
BleAdvertisement ble_advertisement{
|
||||
kVersion, kPcp,
|
||||
service_id_hash, std::string(kEndpointId),
|
||||
long_endpoint_info, std::string(kBluetoothMacAddress)};
|
||||
=======
|
||||
BleAdvertisement ble_advertisement{kVersion,
|
||||
kPcp,
|
||||
service_id_hash,
|
||||
std::string(kEndpointId),
|
||||
long_endpoint_info,
|
||||
std::string(kBluetoothMacAddress),
|
||||
ByteArray{},
|
||||
kWebRtcState};
|
||||
>>>>>>> release
|
||||
|
||||
EXPECT_FALSE(ble_advertisement.IsValid());
|
||||
}
|
||||
@@ -153,8 +245,16 @@ TEST(BleAdvertisementTest,
|
||||
BleAdvertisement::kMaxFastEndpointInfoLength + 1, 'x');
|
||||
ByteArray long_endpoint_info{long_endpoint_name};
|
||||
|
||||
<<<<<<< HEAD
|
||||
BleAdvertisement ble_advertisement{kVersion, kPcp, std::string(kEndpointId),
|
||||
long_endpoint_info};
|
||||
=======
|
||||
BleAdvertisement ble_advertisement{kVersion,
|
||||
kPcp,
|
||||
std::string(kEndpointId),
|
||||
long_endpoint_info,
|
||||
ByteArray{}};
|
||||
>>>>>>> release
|
||||
|
||||
EXPECT_FALSE(ble_advertisement.IsValid());
|
||||
}
|
||||
@@ -164,10 +264,21 @@ TEST(BleAdvertisementTest, ConstructionFailsWithBadVersion) {
|
||||
|
||||
ByteArray service_id_hash{std::string(kServiceIdHashBytes)};
|
||||
ByteArray endpoint_info{std::string(kEndpointName)};
|
||||
<<<<<<< HEAD
|
||||
BleAdvertisement ble_advertisement{
|
||||
bad_version, kPcp,
|
||||
service_id_hash, std::string(kEndpointId),
|
||||
endpoint_info, std::string(kBluetoothMacAddress)};
|
||||
=======
|
||||
BleAdvertisement ble_advertisement{bad_version,
|
||||
kPcp,
|
||||
service_id_hash,
|
||||
std::string(kEndpointId),
|
||||
endpoint_info,
|
||||
std::string(kBluetoothMacAddress),
|
||||
ByteArray{},
|
||||
kWebRtcState};
|
||||
>>>>>>> release
|
||||
|
||||
EXPECT_FALSE(ble_advertisement.IsValid());
|
||||
}
|
||||
@@ -177,8 +288,16 @@ TEST(BleAdvertisementTest,
|
||||
auto bad_version = static_cast<BleAdvertisement::Version>(666);
|
||||
|
||||
ByteArray fast_endpoint_info{std::string(kFastAdvertisementEndpointName)};
|
||||
<<<<<<< HEAD
|
||||
BleAdvertisement ble_advertisement{
|
||||
bad_version, kPcp, std::string(kEndpointId), fast_endpoint_info};
|
||||
=======
|
||||
BleAdvertisement ble_advertisement{bad_version,
|
||||
kPcp,
|
||||
std::string(kEndpointId),
|
||||
fast_endpoint_info,
|
||||
ByteArray{}};
|
||||
>>>>>>> release
|
||||
|
||||
EXPECT_FALSE(ble_advertisement.IsValid());
|
||||
}
|
||||
@@ -188,10 +307,21 @@ TEST(BleAdvertisementTest, ConstructionFailsWithBadPCP) {
|
||||
|
||||
ByteArray service_id_hash{std::string(kServiceIdHashBytes)};
|
||||
ByteArray endpoint_info{std::string(kEndpointName)};
|
||||
<<<<<<< HEAD
|
||||
BleAdvertisement ble_advertisement{
|
||||
kVersion, bad_pcp,
|
||||
service_id_hash, std::string(kEndpointId),
|
||||
endpoint_info, std::string(kBluetoothMacAddress)};
|
||||
=======
|
||||
BleAdvertisement ble_advertisement{kVersion,
|
||||
bad_pcp,
|
||||
service_id_hash,
|
||||
std::string(kEndpointId),
|
||||
endpoint_info,
|
||||
std::string(kBluetoothMacAddress),
|
||||
ByteArray{},
|
||||
kWebRtcState};
|
||||
>>>>>>> release
|
||||
|
||||
EXPECT_FALSE(ble_advertisement.IsValid());
|
||||
}
|
||||
@@ -200,8 +330,16 @@ TEST(BleAdvertisementTest, ConstructionFailsWithBadPCPForFastAdvertisement) {
|
||||
auto bad_pcp = static_cast<Pcp>(666);
|
||||
|
||||
ByteArray fast_endpoint_info{std::string(kFastAdvertisementEndpointName)};
|
||||
<<<<<<< HEAD
|
||||
BleAdvertisement ble_advertisement{
|
||||
kVersion, bad_pcp, std::string(kEndpointId), fast_endpoint_info};
|
||||
=======
|
||||
BleAdvertisement ble_advertisement{kVersion,
|
||||
bad_pcp,
|
||||
std::string(kEndpointId),
|
||||
fast_endpoint_info,
|
||||
ByteArray{}};
|
||||
>>>>>>> release
|
||||
|
||||
EXPECT_FALSE(ble_advertisement.IsValid());
|
||||
}
|
||||
@@ -211,10 +349,21 @@ TEST(BleAdvertisementTest, ConstructionSucceedsWithEmptyBluetoothMacAddress) {
|
||||
|
||||
ByteArray service_id_hash{std::string(kServiceIdHashBytes)};
|
||||
ByteArray endpoint_info{std::string(kEndpointName)};
|
||||
<<<<<<< HEAD
|
||||
BleAdvertisement ble_advertisement{
|
||||
kVersion, kPcp,
|
||||
service_id_hash, std::string(kEndpointId),
|
||||
endpoint_info, empty_bluetooth_mac_address};
|
||||
=======
|
||||
BleAdvertisement ble_advertisement{kVersion,
|
||||
kPcp,
|
||||
service_id_hash,
|
||||
std::string(kEndpointId),
|
||||
endpoint_info,
|
||||
empty_bluetooth_mac_address,
|
||||
ByteArray{},
|
||||
kWebRtcState};
|
||||
>>>>>>> release
|
||||
|
||||
EXPECT_TRUE(ble_advertisement.IsValid());
|
||||
}
|
||||
@@ -224,10 +373,21 @@ TEST(BleAdvertisementTest, ConstructionSucceedsWithInvalidBluetoothMacAddress) {
|
||||
|
||||
ByteArray service_id_hash{std::string(kServiceIdHashBytes)};
|
||||
ByteArray endpoint_info{std::string(kEndpointName)};
|
||||
<<<<<<< HEAD
|
||||
BleAdvertisement ble_advertisement{
|
||||
kVersion, kPcp,
|
||||
service_id_hash, std::string(kEndpointId),
|
||||
endpoint_info, bad_bluetooth_mac_address};
|
||||
=======
|
||||
BleAdvertisement ble_advertisement{kVersion,
|
||||
kPcp,
|
||||
service_id_hash,
|
||||
std::string(kEndpointId),
|
||||
endpoint_info,
|
||||
bad_bluetooth_mac_address,
|
||||
ByteArray{},
|
||||
kWebRtcState};
|
||||
>>>>>>> release
|
||||
|
||||
EXPECT_TRUE(ble_advertisement.IsValid());
|
||||
EXPECT_EQ(kVersion, ble_advertisement.GetVersion());
|
||||
@@ -236,16 +396,31 @@ TEST(BleAdvertisementTest, ConstructionSucceedsWithInvalidBluetoothMacAddress) {
|
||||
EXPECT_EQ(kEndpointId, ble_advertisement.GetEndpointId());
|
||||
EXPECT_EQ(endpoint_info, ble_advertisement.GetEndpointInfo());
|
||||
EXPECT_TRUE(ble_advertisement.GetBluetoothMacAddress().empty());
|
||||
<<<<<<< HEAD
|
||||
=======
|
||||
EXPECT_EQ(kWebRtcState, ble_advertisement.GetWebRtcState());
|
||||
>>>>>>> release
|
||||
}
|
||||
|
||||
TEST(BleAdvertisementTest, ConstructionFromBytesWorks) {
|
||||
// Serialize good data into a good Ble Advertisement.
|
||||
ByteArray service_id_hash{std::string(kServiceIdHashBytes)};
|
||||
ByteArray endpoint_info{std::string(kEndpointName)};
|
||||
<<<<<<< HEAD
|
||||
BleAdvertisement org_ble_advertisement{
|
||||
kVersion, kPcp,
|
||||
service_id_hash, std::string(kEndpointId),
|
||||
endpoint_info, std::string(kBluetoothMacAddress)};
|
||||
=======
|
||||
BleAdvertisement org_ble_advertisement{kVersion,
|
||||
kPcp,
|
||||
service_id_hash,
|
||||
std::string(kEndpointId),
|
||||
endpoint_info,
|
||||
std::string(kBluetoothMacAddress),
|
||||
ByteArray{},
|
||||
kWebRtcState};
|
||||
>>>>>>> release
|
||||
ByteArray ble_advertisement_bytes(org_ble_advertisement);
|
||||
|
||||
BleAdvertisement ble_advertisement{false, ble_advertisement_bytes};
|
||||
@@ -258,13 +433,25 @@ TEST(BleAdvertisementTest, ConstructionFromBytesWorks) {
|
||||
EXPECT_EQ(kEndpointId, ble_advertisement.GetEndpointId());
|
||||
EXPECT_EQ(endpoint_info, ble_advertisement.GetEndpointInfo());
|
||||
EXPECT_EQ(kBluetoothMacAddress, ble_advertisement.GetBluetoothMacAddress());
|
||||
<<<<<<< HEAD
|
||||
=======
|
||||
EXPECT_EQ(kWebRtcState, ble_advertisement.GetWebRtcState());
|
||||
>>>>>>> release
|
||||
}
|
||||
|
||||
TEST(BleAdvertisementTest, ConstructionFromBytesWorksForFastAdvertisement) {
|
||||
// Serialize good data into a good Ble Advertisement.
|
||||
ByteArray fast_endpoint_info{std::string(kFastAdvertisementEndpointName)};
|
||||
<<<<<<< HEAD
|
||||
BleAdvertisement org_ble_advertisement{
|
||||
kVersion, kPcp, std::string(kEndpointId), fast_endpoint_info};
|
||||
=======
|
||||
BleAdvertisement org_ble_advertisement{kVersion,
|
||||
kPcp,
|
||||
std::string(kEndpointId),
|
||||
fast_endpoint_info,
|
||||
ByteArray{}};
|
||||
>>>>>>> release
|
||||
ByteArray ble_advertisement_bytes(org_ble_advertisement);
|
||||
|
||||
BleAdvertisement ble_advertisement{true, ble_advertisement_bytes};
|
||||
@@ -275,6 +462,10 @@ TEST(BleAdvertisementTest, ConstructionFromBytesWorksForFastAdvertisement) {
|
||||
EXPECT_EQ(kPcp, ble_advertisement.GetPcp());
|
||||
EXPECT_EQ(kEndpointId, ble_advertisement.GetEndpointId());
|
||||
EXPECT_EQ(fast_endpoint_info, ble_advertisement.GetEndpointInfo());
|
||||
<<<<<<< HEAD
|
||||
=======
|
||||
EXPECT_EQ(WebRtcState::kUndefined, ble_advertisement.GetWebRtcState());
|
||||
>>>>>>> release
|
||||
}
|
||||
|
||||
// Bytes at the end should be ignored so that they can be used as reserve bytes
|
||||
@@ -283,10 +474,21 @@ TEST(BleAdvertisementTest, ConstructionFromLongLengthBytesWorks) {
|
||||
// Serialize good data into a good Ble Advertisement.
|
||||
ByteArray service_id_hash{std::string(kServiceIdHashBytes)};
|
||||
ByteArray endpoint_info{std::string(kEndpointName)};
|
||||
<<<<<<< HEAD
|
||||
BleAdvertisement ble_advertisement{
|
||||
kVersion, kPcp,
|
||||
service_id_hash, std::string(kEndpointId),
|
||||
endpoint_info, std::string(kBluetoothMacAddress)};
|
||||
=======
|
||||
BleAdvertisement ble_advertisement{kVersion,
|
||||
kPcp,
|
||||
service_id_hash,
|
||||
std::string(kEndpointId),
|
||||
endpoint_info,
|
||||
std::string(kBluetoothMacAddress),
|
||||
ByteArray{},
|
||||
kWebRtcState};
|
||||
>>>>>>> release
|
||||
ByteArray ble_advertisement_bytes(ble_advertisement);
|
||||
|
||||
// Add bytes to the end of the valid Ble advertisement.
|
||||
@@ -307,6 +509,10 @@ TEST(BleAdvertisementTest, ConstructionFromLongLengthBytesWorks) {
|
||||
EXPECT_EQ(endpoint_info, long_ble_advertisement.GetEndpointInfo());
|
||||
EXPECT_EQ(kBluetoothMacAddress,
|
||||
long_ble_advertisement.GetBluetoothMacAddress());
|
||||
<<<<<<< HEAD
|
||||
=======
|
||||
EXPECT_EQ(kWebRtcState, ble_advertisement.GetWebRtcState());
|
||||
>>>>>>> release
|
||||
}
|
||||
|
||||
TEST(BleAdvertisementTest, ConstructionFromNullBytesFails) {
|
||||
@@ -325,10 +531,21 @@ TEST(BleAdvertisementTest, ConstructionFromShortLengthBytesFails) {
|
||||
// Serialize good data into a good Ble Advertisement.
|
||||
ByteArray service_id_hash{std::string(kServiceIdHashBytes)};
|
||||
ByteArray endpoint_info{std::string(kEndpointName)};
|
||||
<<<<<<< HEAD
|
||||
BleAdvertisement ble_advertisement{
|
||||
kVersion, kPcp,
|
||||
service_id_hash, std::string(kEndpointId),
|
||||
endpoint_info, std::string(kBluetoothMacAddress)};
|
||||
=======
|
||||
BleAdvertisement ble_advertisement{kVersion,
|
||||
kPcp,
|
||||
service_id_hash,
|
||||
std::string(kEndpointId),
|
||||
endpoint_info,
|
||||
std::string(kBluetoothMacAddress),
|
||||
ByteArray{},
|
||||
kWebRtcState};
|
||||
>>>>>>> release
|
||||
ByteArray ble_advertisement_bytes(ble_advertisement);
|
||||
|
||||
// Shorten the valid Ble Advertisement.
|
||||
@@ -341,12 +558,24 @@ TEST(BleAdvertisementTest, ConstructionFromShortLengthBytesFails) {
|
||||
|
||||
EXPECT_FALSE(short_ble_advertisement.IsValid());
|
||||
}
|
||||
<<<<<<< HEAD
|
||||
=======
|
||||
|
||||
>>>>>>> release
|
||||
TEST(BleAdvertisementTest,
|
||||
ConstructionFromShortLengthBytesFailsForFastAdvertisement) {
|
||||
// Serialize good data into a good Ble Advertisement.
|
||||
ByteArray fast_endpoint_info{std::string(kFastAdvertisementEndpointName)};
|
||||
<<<<<<< HEAD
|
||||
BleAdvertisement ble_advertisement{kVersion, kPcp, std::string(kEndpointId),
|
||||
fast_endpoint_info};
|
||||
=======
|
||||
BleAdvertisement ble_advertisement{kVersion,
|
||||
kPcp,
|
||||
std::string(kEndpointId),
|
||||
fast_endpoint_info,
|
||||
ByteArray{}};
|
||||
>>>>>>> release
|
||||
ByteArray ble_advertisement_bytes(ble_advertisement);
|
||||
|
||||
// Shorten the valid Ble Advertisement.
|
||||
@@ -364,10 +593,21 @@ TEST(BleAdvertisementTest,
|
||||
// Serialize good data into a good Ble Advertisement.
|
||||
ByteArray service_id_hash{std::string(kServiceIdHashBytes)};
|
||||
ByteArray endpoint_info{std::string(kEndpointName)};
|
||||
<<<<<<< HEAD
|
||||
BleAdvertisement ble_advertisement{
|
||||
kVersion, kPcp,
|
||||
service_id_hash, std::string(kEndpointId),
|
||||
endpoint_info, std::string(kBluetoothMacAddress)};
|
||||
=======
|
||||
BleAdvertisement ble_advertisement{kVersion,
|
||||
kPcp,
|
||||
service_id_hash,
|
||||
std::string(kEndpointId),
|
||||
endpoint_info,
|
||||
std::string(kBluetoothMacAddress),
|
||||
ByteArray{},
|
||||
kWebRtcState};
|
||||
>>>>>>> release
|
||||
ByteArray ble_advertisement_bytes(ble_advertisement);
|
||||
|
||||
// Corrupt the EndpointNameLength bits.
|
||||
@@ -385,8 +625,16 @@ TEST(BleAdvertisementTest,
|
||||
ConstructionFromByesWithWrongEndpointInfoLengthFailsForFastAdvertisement) {
|
||||
// Serialize good data into a good Ble Advertisement.
|
||||
ByteArray fast_endpoint_info{std::string(kFastAdvertisementEndpointName)};
|
||||
<<<<<<< HEAD
|
||||
BleAdvertisement ble_advertisement{kVersion, kPcp, std::string(kEndpointId),
|
||||
fast_endpoint_info};
|
||||
=======
|
||||
BleAdvertisement ble_advertisement{kVersion,
|
||||
kPcp,
|
||||
std::string(kEndpointId),
|
||||
fast_endpoint_info,
|
||||
ByteArray{}};
|
||||
>>>>>>> release
|
||||
ByteArray ble_advertisement_bytes = ByteArray(ble_advertisement);
|
||||
|
||||
// Corrupt the EndpointInfoLength bits.
|
||||
|
||||
@@ -32,7 +32,13 @@ namespace connections {
|
||||
BluetoothDeviceName::BluetoothDeviceName(Version version, Pcp pcp,
|
||||
absl::string_view endpoint_id,
|
||||
const ByteArray& service_id_hash,
|
||||
<<<<<<< HEAD
|
||||
const ByteArray& endpoint_info) {
|
||||
=======
|
||||
const ByteArray& endpoint_info,
|
||||
const ByteArray& uwb_address,
|
||||
WebRtcState web_rtc_state) {
|
||||
>>>>>>> release
|
||||
if (version != Version::kV1 || endpoint_id.empty() ||
|
||||
endpoint_id.length() != kEndpointIdLength ||
|
||||
service_id_hash.size() != kServiceIdHashLength) {
|
||||
@@ -52,6 +58,11 @@ BluetoothDeviceName::BluetoothDeviceName(Version version, Pcp pcp,
|
||||
endpoint_id_ = std::string(endpoint_id);
|
||||
service_id_hash_ = service_id_hash;
|
||||
endpoint_info_ = endpoint_info;
|
||||
<<<<<<< HEAD
|
||||
=======
|
||||
uwb_address_ = uwb_address;
|
||||
web_rtc_state_ = web_rtc_state;
|
||||
>>>>>>> release
|
||||
}
|
||||
|
||||
BluetoothDeviceName::BluetoothDeviceName(
|
||||
@@ -67,6 +78,7 @@ BluetoothDeviceName::BluetoothDeviceName(
|
||||
return;
|
||||
}
|
||||
|
||||
<<<<<<< HEAD
|
||||
if (bluetooth_device_name_bytes.size() > kMaxBluetoothDeviceNameLength) {
|
||||
NEARBY_LOG(INFO,
|
||||
"Cannot deserialize BluetoothDeviceName: expecting max %d raw "
|
||||
@@ -76,6 +88,8 @@ BluetoothDeviceName::BluetoothDeviceName(
|
||||
return;
|
||||
}
|
||||
|
||||
=======
|
||||
>>>>>>> release
|
||||
if (bluetooth_device_name_bytes.size() < kMinBluetoothDeviceNameLength) {
|
||||
NEARBY_LOG(INFO,
|
||||
"Cannot deserialize BluetoothDeviceName: expecting min %d raw "
|
||||
@@ -117,11 +131,26 @@ BluetoothDeviceName::BluetoothDeviceName(
|
||||
// The next 3 bytes are supposed to be the service_id_hash.
|
||||
service_id_hash_ = base_input_stream.ReadBytes(kServiceIdHashLength);
|
||||
|
||||
<<<<<<< HEAD
|
||||
// The next 7 bytes are supposed to be reserved, and can be left
|
||||
// untouched.
|
||||
base_input_stream.ReadBytes(kReservedLength);
|
||||
|
||||
// The next 1 byte are supposed to be the length of the endpoint_info.
|
||||
=======
|
||||
|
||||
// The next 1 byte is field containning WebRtc state.
|
||||
auto field_byte = static_cast<char>(base_input_stream.ReadUint8());
|
||||
web_rtc_state_ = (field_byte & kWebRtcConnectableFlagBitmask) == 1
|
||||
? WebRtcState::kConnectable
|
||||
: WebRtcState::kUnconnectable;
|
||||
|
||||
// The next 6 bytes are supposed to be reserved, and can be left
|
||||
// untouched.
|
||||
base_input_stream.ReadBytes(kReservedLength);
|
||||
|
||||
// The next 1 byte is supposed to be the length of the endpoint_info.
|
||||
>>>>>>> release
|
||||
std::uint32_t expected_endpoint_info_length = base_input_stream.ReadUint8();
|
||||
|
||||
// The rest bytes are supposed to be the endpoint_info
|
||||
@@ -137,6 +166,32 @@ BluetoothDeviceName::BluetoothDeviceName(
|
||||
endpoint_id_.clear();
|
||||
return;
|
||||
}
|
||||
<<<<<<< HEAD
|
||||
=======
|
||||
|
||||
// If the input stream has extra bytes, it's for UWB address. The first byte
|
||||
// is the address length. It can be 2-byte short address or 8-byte extended
|
||||
// address.
|
||||
if (base_input_stream.IsAvailable(1)) {
|
||||
// The next 1 byte is supposed to be the length of the uwb_address.
|
||||
std::uint32_t expected_uwb_address_length = base_input_stream.ReadUint8();
|
||||
// If the length of usb_address is not zero, then retrieve it.
|
||||
if (expected_uwb_address_length != 0) {
|
||||
uwb_address_ = base_input_stream.ReadBytes(expected_uwb_address_length);
|
||||
if (uwb_address_.Empty() ||
|
||||
uwb_address_.size() != expected_uwb_address_length) {
|
||||
NEARBY_LOG(INFO,
|
||||
"Cannot deserialize BluetoothDeviceName: "
|
||||
"expected uwbAddress size to be %d bytes, got %" PRIu64,
|
||||
expected_uwb_address_length, uwb_address_.size());
|
||||
|
||||
// Clear enpoint_id for validadity.
|
||||
endpoint_id_.clear();
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
>>>>>>> release
|
||||
}
|
||||
|
||||
BluetoothDeviceName::operator std::string() const {
|
||||
@@ -151,6 +206,15 @@ BluetoothDeviceName::operator std::string() const {
|
||||
version_and_pcp_byte |=
|
||||
static_cast<char>(static_cast<uint32_t>(pcp_) & kPcpBitmask);
|
||||
|
||||
<<<<<<< HEAD
|
||||
=======
|
||||
// A byte contains WebRtcState state.
|
||||
int web_rtc_connectable_flag =
|
||||
(web_rtc_state_ == WebRtcState::kConnectable) ? 1 : 0;
|
||||
char field_byte = static_cast<char>(web_rtc_connectable_flag) &
|
||||
kWebRtcConnectableFlagBitmask;
|
||||
|
||||
>>>>>>> release
|
||||
ByteArray reserved_bytes{kReservedLength};
|
||||
|
||||
ByteArray usable_endpoint_info(endpoint_info_);
|
||||
@@ -167,11 +231,24 @@ BluetoothDeviceName::operator std::string() const {
|
||||
std::string out = absl::StrCat(std::string(1, version_and_pcp_byte),
|
||||
endpoint_id_,
|
||||
std::string(service_id_hash_),
|
||||
<<<<<<< HEAD
|
||||
=======
|
||||
std::string(1, field_byte),
|
||||
>>>>>>> release
|
||||
std::string(reserved_bytes),
|
||||
std::string(1, usable_endpoint_info.size()),
|
||||
std::string(usable_endpoint_info));
|
||||
// clang-format on
|
||||
|
||||
<<<<<<< HEAD
|
||||
=======
|
||||
// If UWB address is available, attach it at the end.
|
||||
if (!uwb_address_.Empty()) {
|
||||
absl::StrAppend(&out, std::string(1, uwb_address_.size()));
|
||||
absl::StrAppend(&out, std::string(uwb_address_));
|
||||
}
|
||||
|
||||
>>>>>>> release
|
||||
return Base64Utils::Encode(ByteArray{std::move(out)});
|
||||
}
|
||||
|
||||
|
||||
@@ -17,6 +17,10 @@
|
||||
|
||||
#include <cstdint>
|
||||
|
||||
<<<<<<< HEAD
|
||||
=======
|
||||
#include "core_v2/internal/base_pcp_handler.h"
|
||||
>>>>>>> release
|
||||
#include "core_v2/internal/pcp.h"
|
||||
#include "platform_v2/base/byte_array.h"
|
||||
#include "absl/strings/string_view.h"
|
||||
@@ -44,7 +48,13 @@ class BluetoothDeviceName {
|
||||
BluetoothDeviceName() = default;
|
||||
BluetoothDeviceName(Version version, Pcp pcp, absl::string_view endpoint_id,
|
||||
const ByteArray& service_id_hash,
|
||||
<<<<<<< HEAD
|
||||
const ByteArray& endpoint_info);
|
||||
=======
|
||||
const ByteArray& endpoint_info,
|
||||
const ByteArray& uwb_address,
|
||||
WebRtcState web_rtc_state);
|
||||
>>>>>>> release
|
||||
explicit BluetoothDeviceName(absl::string_view bluetooth_device_name_string);
|
||||
BluetoothDeviceName(const BluetoothDeviceName&) = default;
|
||||
BluetoothDeviceName& operator=(const BluetoothDeviceName&) = default;
|
||||
@@ -60,6 +70,7 @@ class BluetoothDeviceName {
|
||||
std::string GetEndpointId() const { return endpoint_id_; }
|
||||
ByteArray GetServiceIdHash() const { return service_id_hash_; }
|
||||
ByteArray GetEndpointInfo() const { return endpoint_info_; }
|
||||
<<<<<<< HEAD
|
||||
|
||||
private:
|
||||
static constexpr int kMaxBluetoothDeviceNameLength = 147;
|
||||
@@ -68,16 +79,36 @@ class BluetoothDeviceName {
|
||||
static constexpr int kMaxEndpointInfoLength = 131;
|
||||
static constexpr int kMinBluetoothDeviceNameLength =
|
||||
kMaxBluetoothDeviceNameLength - kMaxEndpointInfoLength;
|
||||
=======
|
||||
ByteArray GetUwbAddress() const { return uwb_address_; }
|
||||
WebRtcState GetWebRtcState() const { return web_rtc_state_; }
|
||||
|
||||
private:
|
||||
static constexpr int kEndpointIdLength = 4;
|
||||
static constexpr int kReservedLength = 6;
|
||||
static constexpr int kMaxEndpointInfoLength = 131;
|
||||
static constexpr int kMinBluetoothDeviceNameLength = 16;
|
||||
>>>>>>> release
|
||||
|
||||
static constexpr int kVersionBitmask = 0x0E0;
|
||||
static constexpr int kPcpBitmask = 0x01F;
|
||||
static constexpr int kEndpointNameLengthBitmask = 0x0FF;
|
||||
<<<<<<< HEAD
|
||||
=======
|
||||
static constexpr int kWebRtcConnectableFlagBitmask = 0x01;
|
||||
>>>>>>> release
|
||||
|
||||
Version version_{Version::kUndefined};
|
||||
Pcp pcp_{Pcp::kUnknown};
|
||||
std::string endpoint_id_;
|
||||
ByteArray service_id_hash_;
|
||||
ByteArray endpoint_info_;
|
||||
<<<<<<< HEAD
|
||||
=======
|
||||
// TODO(b/169550050): Define UWB address field.
|
||||
ByteArray uwb_address_;
|
||||
WebRtcState web_rtc_state_{WebRtcState::kUndefined};
|
||||
>>>>>>> release
|
||||
};
|
||||
|
||||
} // namespace connections
|
||||
|
||||
@@ -31,12 +31,28 @@ constexpr Pcp kPcp = Pcp::kP2pCluster;
|
||||
constexpr absl::string_view kEndPointID{"AB12"};
|
||||
constexpr absl::string_view kServiceIDHashBytes{"\x0a\x0b\x0c"};
|
||||
constexpr absl::string_view kEndPointName{"RAWK + ROWL!"};
|
||||
<<<<<<< HEAD
|
||||
|
||||
TEST(BluetoothDeviceNameTest, ConstructionWorks) {
|
||||
ByteArray service_id_hash{std::string(kServiceIDHashBytes)};
|
||||
ByteArray endpoint_info{std::string(kEndPointName)};
|
||||
BluetoothDeviceName bluetooth_device_name{kVersion, kPcp, kEndPointID,
|
||||
service_id_hash, endpoint_info};
|
||||
=======
|
||||
constexpr WebRtcState kWebRtcState = WebRtcState::kConnectable;
|
||||
|
||||
// TODO(b/169550050): Implement UWBAddress.
|
||||
TEST(BluetoothDeviceNameTest, ConstructionWorks) {
|
||||
ByteArray service_id_hash{std::string(kServiceIDHashBytes)};
|
||||
ByteArray endpoint_info{std::string(kEndPointName)};
|
||||
BluetoothDeviceName bluetooth_device_name{kVersion,
|
||||
kPcp,
|
||||
kEndPointID,
|
||||
service_id_hash,
|
||||
endpoint_info,
|
||||
ByteArray{},
|
||||
kWebRtcState};
|
||||
>>>>>>> release
|
||||
|
||||
EXPECT_TRUE(bluetooth_device_name.IsValid());
|
||||
EXPECT_EQ(kVersion, bluetooth_device_name.GetVersion());
|
||||
@@ -44,14 +60,28 @@ TEST(BluetoothDeviceNameTest, ConstructionWorks) {
|
||||
EXPECT_EQ(kEndPointID, bluetooth_device_name.GetEndpointId());
|
||||
EXPECT_EQ(service_id_hash, bluetooth_device_name.GetServiceIdHash());
|
||||
EXPECT_EQ(endpoint_info, bluetooth_device_name.GetEndpointInfo());
|
||||
<<<<<<< HEAD
|
||||
=======
|
||||
EXPECT_EQ(kWebRtcState, bluetooth_device_name.GetWebRtcState());
|
||||
>>>>>>> release
|
||||
}
|
||||
|
||||
TEST(BluetoothDeviceNameTest, ConstructionWorksWithEmptyEndpointName) {
|
||||
ByteArray empty_endpoint_info;
|
||||
|
||||
ByteArray service_id_hash{std::string(kServiceIDHashBytes)};
|
||||
<<<<<<< HEAD
|
||||
BluetoothDeviceName bluetooth_device_name{
|
||||
kVersion, kPcp, kEndPointID, service_id_hash, empty_endpoint_info};
|
||||
=======
|
||||
BluetoothDeviceName bluetooth_device_name{kVersion,
|
||||
kPcp,
|
||||
kEndPointID,
|
||||
service_id_hash,
|
||||
empty_endpoint_info,
|
||||
ByteArray{},
|
||||
kWebRtcState};
|
||||
>>>>>>> release
|
||||
|
||||
EXPECT_TRUE(bluetooth_device_name.IsValid());
|
||||
EXPECT_EQ(kVersion, bluetooth_device_name.GetVersion());
|
||||
@@ -59,6 +89,10 @@ TEST(BluetoothDeviceNameTest, ConstructionWorksWithEmptyEndpointName) {
|
||||
EXPECT_EQ(kEndPointID, bluetooth_device_name.GetEndpointId());
|
||||
EXPECT_EQ(service_id_hash, bluetooth_device_name.GetServiceIdHash());
|
||||
EXPECT_EQ(empty_endpoint_info, bluetooth_device_name.GetEndpointInfo());
|
||||
<<<<<<< HEAD
|
||||
=======
|
||||
EXPECT_EQ(kWebRtcState, bluetooth_device_name.GetWebRtcState());
|
||||
>>>>>>> release
|
||||
}
|
||||
|
||||
TEST(BluetoothDeviceNameTest, ConstructionFailsWithBadVersion) {
|
||||
@@ -66,8 +100,18 @@ TEST(BluetoothDeviceNameTest, ConstructionFailsWithBadVersion) {
|
||||
|
||||
ByteArray service_id_hash{std::string(kServiceIDHashBytes)};
|
||||
ByteArray endpoint_info{std::string(kEndPointName)};
|
||||
<<<<<<< HEAD
|
||||
BluetoothDeviceName bluetooth_device_name{bad_version, kPcp, kEndPointID,
|
||||
service_id_hash, endpoint_info};
|
||||
=======
|
||||
BluetoothDeviceName bluetooth_device_name{bad_version,
|
||||
kPcp,
|
||||
kEndPointID,
|
||||
service_id_hash,
|
||||
endpoint_info,
|
||||
ByteArray{},
|
||||
kWebRtcState};
|
||||
>>>>>>> release
|
||||
|
||||
EXPECT_FALSE(bluetooth_device_name.IsValid());
|
||||
}
|
||||
@@ -77,8 +121,18 @@ TEST(BluetoothDeviceNameTest, ConstructionFailsWithBadPcp) {
|
||||
|
||||
ByteArray service_id_hash{std::string(kServiceIDHashBytes)};
|
||||
ByteArray endpoint_info{std::string(kEndPointName)};
|
||||
<<<<<<< HEAD
|
||||
BluetoothDeviceName bluetooth_device_name{kVersion, bad_pcp, kEndPointID,
|
||||
service_id_hash, endpoint_info};
|
||||
=======
|
||||
BluetoothDeviceName bluetooth_device_name{kVersion,
|
||||
bad_pcp,
|
||||
kEndPointID,
|
||||
service_id_hash,
|
||||
endpoint_info,
|
||||
ByteArray{},
|
||||
kWebRtcState};
|
||||
>>>>>>> release
|
||||
|
||||
EXPECT_FALSE(bluetooth_device_name.IsValid());
|
||||
}
|
||||
@@ -88,8 +142,18 @@ TEST(BluetoothDeviceNameTest, ConstructionFailsWithShortEndpointId) {
|
||||
|
||||
ByteArray service_id_hash{std::string(kServiceIDHashBytes)};
|
||||
ByteArray endpoint_info{std::string(kEndPointName)};
|
||||
<<<<<<< HEAD
|
||||
BluetoothDeviceName bluetooth_device_name{kVersion, kPcp, short_endpoint_id,
|
||||
service_id_hash, endpoint_info};
|
||||
=======
|
||||
BluetoothDeviceName bluetooth_device_name{kVersion,
|
||||
kPcp,
|
||||
short_endpoint_id,
|
||||
service_id_hash,
|
||||
endpoint_info,
|
||||
ByteArray{},
|
||||
kWebRtcState};
|
||||
>>>>>>> release
|
||||
|
||||
EXPECT_FALSE(bluetooth_device_name.IsValid());
|
||||
}
|
||||
@@ -99,8 +163,18 @@ TEST(BluetoothDeviceNameTest, ConstructionFailsWithLongEndpointId) {
|
||||
|
||||
ByteArray service_id_hash{std::string(kServiceIDHashBytes)};
|
||||
ByteArray endpoint_info{std::string(kEndPointName)};
|
||||
<<<<<<< HEAD
|
||||
BluetoothDeviceName bluetooth_device_name{kVersion, kPcp, long_endpoint_id,
|
||||
service_id_hash, endpoint_info};
|
||||
=======
|
||||
BluetoothDeviceName bluetooth_device_name{kVersion,
|
||||
kPcp,
|
||||
long_endpoint_id,
|
||||
service_id_hash,
|
||||
endpoint_info,
|
||||
ByteArray{},
|
||||
kWebRtcState};
|
||||
>>>>>>> release
|
||||
|
||||
EXPECT_FALSE(bluetooth_device_name.IsValid());
|
||||
}
|
||||
@@ -110,8 +184,18 @@ TEST(BluetoothDeviceNameTest, ConstructionFailsWithShortServiceIdHash) {
|
||||
|
||||
ByteArray short_service_id_hash{short_service_id_hash_bytes};
|
||||
ByteArray endpoint_info{std::string(kEndPointName)};
|
||||
<<<<<<< HEAD
|
||||
BluetoothDeviceName bluetooth_device_name{
|
||||
kVersion, kPcp, kEndPointID, short_service_id_hash, endpoint_info};
|
||||
=======
|
||||
BluetoothDeviceName bluetooth_device_name{kVersion,
|
||||
kPcp,
|
||||
kEndPointID,
|
||||
short_service_id_hash,
|
||||
endpoint_info,
|
||||
ByteArray{},
|
||||
kWebRtcState};
|
||||
>>>>>>> release
|
||||
|
||||
EXPECT_FALSE(bluetooth_device_name.IsValid());
|
||||
}
|
||||
@@ -121,8 +205,18 @@ TEST(BluetoothDeviceNameTest, ConstructionFailsWithLongServiceIdHash) {
|
||||
|
||||
ByteArray long_service_id_hash{long_service_id_hash_bytes};
|
||||
ByteArray endpoint_info{std::string(kEndPointName)};
|
||||
<<<<<<< HEAD
|
||||
BluetoothDeviceName bluetooth_device_name{
|
||||
kVersion, kPcp, kEndPointID, long_service_id_hash, endpoint_info};
|
||||
=======
|
||||
BluetoothDeviceName bluetooth_device_name{kVersion,
|
||||
kPcp,
|
||||
kEndPointID,
|
||||
long_service_id_hash,
|
||||
endpoint_info,
|
||||
ByteArray{},
|
||||
kWebRtcState};
|
||||
>>>>>>> release
|
||||
|
||||
EXPECT_FALSE(bluetooth_device_name.IsValid());
|
||||
}
|
||||
@@ -141,8 +235,18 @@ TEST(BluetoothDeviceNameTest, ConstructionFailsWithWrongEndpointNameLength) {
|
||||
// Serialize good data into a good Bluetooth Device Name.
|
||||
ByteArray service_id_hash{std::string(kServiceIDHashBytes)};
|
||||
ByteArray endpoint_info{std::string(kEndPointName)};
|
||||
<<<<<<< HEAD
|
||||
BluetoothDeviceName bluetooth_device_name{kVersion, kPcp, kEndPointID,
|
||||
service_id_hash, endpoint_info};
|
||||
=======
|
||||
BluetoothDeviceName bluetooth_device_name{kVersion,
|
||||
kPcp,
|
||||
kEndPointID,
|
||||
service_id_hash,
|
||||
endpoint_info,
|
||||
ByteArray{},
|
||||
kWebRtcState};
|
||||
>>>>>>> release
|
||||
auto bluetooth_device_name_string = std::string(bluetooth_device_name);
|
||||
|
||||
// Base64-decode the good Bluetooth Device Name.
|
||||
@@ -169,8 +273,18 @@ TEST(BluetoothDeviceNameTest, CanParseGeneratedName) {
|
||||
ByteArray service_id_hash{std::string(kServiceIDHashBytes)};
|
||||
ByteArray endpoint_info{std::string(kEndPointName)};
|
||||
// Build name1 from scratch.
|
||||
<<<<<<< HEAD
|
||||
BluetoothDeviceName name1{kVersion, kPcp, kEndPointID, service_id_hash,
|
||||
endpoint_info};
|
||||
=======
|
||||
BluetoothDeviceName name1{kVersion,
|
||||
kPcp,
|
||||
kEndPointID,
|
||||
service_id_hash,
|
||||
endpoint_info,
|
||||
ByteArray{},
|
||||
kWebRtcState};
|
||||
>>>>>>> release
|
||||
// Build name2 from string composed from name1.
|
||||
BluetoothDeviceName name2{std::string(name1)};
|
||||
EXPECT_TRUE(name1.IsValid());
|
||||
@@ -180,6 +294,10 @@ TEST(BluetoothDeviceNameTest, CanParseGeneratedName) {
|
||||
EXPECT_EQ(name1.GetEndpointId(), name2.GetEndpointId());
|
||||
EXPECT_EQ(name1.GetServiceIdHash(), name2.GetServiceIdHash());
|
||||
EXPECT_EQ(name1.GetEndpointInfo(), name2.GetEndpointInfo());
|
||||
<<<<<<< HEAD
|
||||
=======
|
||||
EXPECT_EQ(name1.GetWebRtcState(), name2.GetWebRtcState());
|
||||
>>>>>>> release
|
||||
}
|
||||
|
||||
} // namespace
|
||||
|
||||
@@ -15,6 +15,10 @@
|
||||
#include "core_v2/internal/bwu_manager.h"
|
||||
|
||||
#include <algorithm>
|
||||
<<<<<<< HEAD
|
||||
=======
|
||||
#include <memory>
|
||||
>>>>>>> release
|
||||
|
||||
#include "core_v2/internal/bwu_handler.h"
|
||||
#include "core_v2/internal/offline_frames.h"
|
||||
@@ -206,7 +210,11 @@ void BwuManager::OnEndpointDisconnect(ClientProxy* client,
|
||||
handler_->OnEndpointDisconnect(client, endpoint_id);
|
||||
}
|
||||
|
||||
<<<<<<< HEAD
|
||||
auto item = old_channels_.extract(endpoint_id);
|
||||
=======
|
||||
auto item = previous_endpoint_channels_.extract(endpoint_id);
|
||||
>>>>>>> release
|
||||
|
||||
if (!item.empty()) {
|
||||
auto old_channel = item.mapped();
|
||||
@@ -274,7 +282,14 @@ void BwuManager::OnBwuNegotiationFrame(ClientProxy* client,
|
||||
}
|
||||
|
||||
void BwuManager::OnIncomingConnection(
|
||||
<<<<<<< HEAD
|
||||
ClientProxy* client, BwuHandler::IncomingSocketConnection* connection) {
|
||||
=======
|
||||
ClientProxy* client,
|
||||
BwuHandler::IncomingSocketConnection* mutable_connection) {
|
||||
auto connection = std::make_shared<BwuHandler::IncomingSocketConnection>(
|
||||
std::move(*mutable_connection));
|
||||
>>>>>>> release
|
||||
RunOnBwuManagerThread([this, client, connection]() {
|
||||
EndpointChannel* channel = connection->channel.get();
|
||||
if (channel == nullptr) {
|
||||
@@ -343,7 +358,11 @@ void BwuManager::RunUpgradeProtocol(
|
||||
// continue when we receive a corresponding
|
||||
// BANDWIDTH_UPGRADE_NEGOTIATION.LAST_WRITE_TO_PRIOR_CHANNEL OfflineFrame from
|
||||
// the remote device, so for now, just store that previous EndpointChannel.
|
||||
<<<<<<< HEAD
|
||||
old_channels_.emplace(endpoint_id, old_channel);
|
||||
=======
|
||||
previous_endpoint_channels_.emplace(endpoint_id, old_channel);
|
||||
>>>>>>> release
|
||||
|
||||
// If we already read LAST_WRITE on the old endpoint channel, then we can
|
||||
// safely close it now.
|
||||
|
||||
@@ -170,10 +170,15 @@ class BwuManager : public EndpointManager::FrameProcessor {
|
||||
// Stores each upgraded endpoint's previous EndpointChannel (that was
|
||||
// displaced in favor of a new EndpointChannel) temporarily, until it can
|
||||
// safely be shut down for good in processLastWriteToPriorChannelEvent().
|
||||
<<<<<<< HEAD
|
||||
absl::flat_hash_map<std::string, std::unique_ptr<EndpointChannel>>
|
||||
previous_endpoint_channels_;
|
||||
absl::flat_hash_map<std::string, std::shared_ptr<EndpointChannel>>
|
||||
old_channels_;
|
||||
=======
|
||||
absl::flat_hash_map<std::string, std::shared_ptr<EndpointChannel>>
|
||||
previous_endpoint_channels_;
|
||||
>>>>>>> release
|
||||
absl::flat_hash_set<std::string> successfully_upgraded_endpoints_;
|
||||
// Maps endpointId -> ClientProxy for which
|
||||
// initiateBwuForEndpoint() has been called but which have not
|
||||
|
||||
@@ -39,7 +39,13 @@ cc_library(
|
||||
"//core_v2/internal:__subpackages__",
|
||||
],
|
||||
deps = [
|
||||
<<<<<<< HEAD
|
||||
"//core_v2:core_types",
|
||||
=======
|
||||
":utils",
|
||||
"//core_v2:core_types",
|
||||
"//core_v2/internal/mediums/ble_v2",
|
||||
>>>>>>> release
|
||||
"//core_v2/internal/mediums/webrtc",
|
||||
"//platform_v2/base",
|
||||
"//platform_v2/public:comm",
|
||||
@@ -63,6 +69,10 @@ cc_library(
|
||||
hdrs = ["utils.h"],
|
||||
visibility = [
|
||||
"//core_v2/internal:__pkg__",
|
||||
<<<<<<< HEAD
|
||||
=======
|
||||
"//core_v2/internal/mediums:__pkg__",
|
||||
>>>>>>> release
|
||||
"//core_v2/internal/mediums/ble_v2:__pkg__",
|
||||
"//core_v2/internal/mediums/webrtc:__pkg__",
|
||||
],
|
||||
|
||||
@@ -18,6 +18,12 @@
|
||||
#include <string>
|
||||
#include <utility>
|
||||
|
||||
<<<<<<< HEAD
|
||||
=======
|
||||
#include "core_v2/internal/mediums/ble_v2/ble_advertisement.h"
|
||||
#include "core_v2/internal/mediums/utils.h"
|
||||
#include "platform_v2/base/prng.h"
|
||||
>>>>>>> release
|
||||
#include "platform_v2/public/logging.h"
|
||||
#include "platform_v2/public/mutex_lock.h"
|
||||
|
||||
@@ -25,6 +31,18 @@ namespace location {
|
||||
namespace nearby {
|
||||
namespace connections {
|
||||
|
||||
<<<<<<< HEAD
|
||||
=======
|
||||
ByteArray Ble::GenerateHash(const std::string& source, size_t size) {
|
||||
return Utils::Sha256Hash(source, size);
|
||||
}
|
||||
|
||||
ByteArray Ble::GenerateDeviceToken() {
|
||||
return Utils::Sha256Hash(std::to_string(Prng().NextUint32()),
|
||||
mediums::BleAdvertisement::kDeviceTokenLength);
|
||||
}
|
||||
|
||||
>>>>>>> release
|
||||
Ble::Ble(BluetoothRadio& radio) : radio_(radio) {}
|
||||
|
||||
bool Ble::IsAvailable() const {
|
||||
@@ -77,7 +95,27 @@ bool Ble::StartAdvertising(const std::string& service_id,
|
||||
<< ", service id=" << service_id
|
||||
<< ", fast advertisement service uuid="
|
||||
<< fast_advertisement_service_uuid;
|
||||
<<<<<<< HEAD
|
||||
if (!medium_.StartAdvertising(service_id, advertisement_bytes,
|
||||
=======
|
||||
|
||||
// Wrap the connections advertisement to the medium advertisement.
|
||||
const bool fast_advertisement = !fast_advertisement_service_uuid.empty();
|
||||
ByteArray service_id_hash{GenerateHash(
|
||||
service_id, mediums::BleAdvertisement::kServiceIdHashLength)};
|
||||
ByteArray medium_advertisement_bytes{mediums::BleAdvertisement{
|
||||
mediums::BleAdvertisement::Version::kV2,
|
||||
mediums::BleAdvertisement::SocketVersion::kV2,
|
||||
fast_advertisement ? ByteArray{} : service_id_hash, advertisement_bytes,
|
||||
GenerateDeviceToken()}};
|
||||
if (medium_advertisement_bytes.Empty()) {
|
||||
NEARBY_LOGS(INFO) << "Failed to BLE advertise because we could not "
|
||||
"create a medium advertisement.";
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!medium_.StartAdvertising(service_id, medium_advertisement_bytes,
|
||||
>>>>>>> release
|
||||
fast_advertisement_service_uuid)) {
|
||||
NEARBY_LOGS(INFO)
|
||||
<< "Failed to turn on BLE advertising with advertisement bytes="
|
||||
@@ -124,6 +162,11 @@ bool Ble::StartScanning(const std::string& service_id,
|
||||
DiscoveredPeripheralCallback callback) {
|
||||
MutexLock lock(&mutex_);
|
||||
|
||||
<<<<<<< HEAD
|
||||
=======
|
||||
discovered_peripheral_callback_ = std::move(callback);
|
||||
|
||||
>>>>>>> release
|
||||
if (service_id.empty()) {
|
||||
NEARBY_LOGS(INFO)
|
||||
<< "Refusing to start BLE scanning with empty service id.";
|
||||
@@ -148,8 +191,34 @@ bool Ble::StartScanning(const std::string& service_id,
|
||||
return false;
|
||||
}
|
||||
|
||||
<<<<<<< HEAD
|
||||
if (!medium_.StartScanning(service_id, fast_advertisement_service_uuid,
|
||||
callback)) {
|
||||
=======
|
||||
if (!medium_.StartScanning(
|
||||
service_id, fast_advertisement_service_uuid,
|
||||
{
|
||||
.peripheral_discovered_cb =
|
||||
[this](BlePeripheral& peripheral,
|
||||
const std::string& service_id,
|
||||
const ByteArray& medium_advertisement_bytes,
|
||||
bool fast_advertisement) {
|
||||
// Unwrap connection BleAdvertisement from medium
|
||||
// BleAdvertisement.
|
||||
auto connection_advertisement_bytes =
|
||||
UnwrapAdvertisementBytes(medium_advertisement_bytes);
|
||||
discovered_peripheral_callback_.peripheral_discovered_cb(
|
||||
peripheral, service_id, connection_advertisement_bytes,
|
||||
fast_advertisement);
|
||||
},
|
||||
.peripheral_lost_cb =
|
||||
[this](BlePeripheral& peripheral,
|
||||
const std::string& service_id) {
|
||||
discovered_peripheral_callback_.peripheral_lost_cb(
|
||||
peripheral, service_id);
|
||||
},
|
||||
})) {
|
||||
>>>>>>> release
|
||||
NEARBY_LOGS(INFO) << "Failed to start scan of BLE services.";
|
||||
return false;
|
||||
}
|
||||
@@ -286,6 +355,19 @@ BleSocket Ble::Connect(BlePeripheral& peripheral,
|
||||
return socket;
|
||||
}
|
||||
|
||||
<<<<<<< HEAD
|
||||
=======
|
||||
ByteArray Ble::UnwrapAdvertisementBytes(
|
||||
const ByteArray& medium_advertisement_data) {
|
||||
mediums::BleAdvertisement medium_ble_advertisement{medium_advertisement_data};
|
||||
if (!medium_ble_advertisement.IsValid()) {
|
||||
return ByteArray{};
|
||||
}
|
||||
|
||||
return medium_ble_advertisement.GetData();
|
||||
}
|
||||
|
||||
>>>>>>> release
|
||||
} // namespace connections
|
||||
} // namespace nearby
|
||||
} // namespace location
|
||||
|
||||
@@ -102,8 +102,11 @@ class Ble {
|
||||
ABSL_LOCKS_EXCLUDED(mutex_);
|
||||
|
||||
private:
|
||||
<<<<<<< HEAD
|
||||
static constexpr int kMaxAdvertisementLength = 512;
|
||||
|
||||
=======
|
||||
>>>>>>> release
|
||||
struct AdvertisingInfo {
|
||||
bool Empty() const { return service_ids.empty(); }
|
||||
void Clear() { service_ids.clear(); }
|
||||
@@ -146,6 +149,14 @@ class Ble {
|
||||
absl::flat_hash_set<std::string> service_ids;
|
||||
};
|
||||
|
||||
<<<<<<< HEAD
|
||||
=======
|
||||
static constexpr int kMaxAdvertisementLength = 512;
|
||||
|
||||
static ByteArray GenerateHash(const std::string& source, size_t size);
|
||||
static ByteArray GenerateDeviceToken();
|
||||
|
||||
>>>>>>> release
|
||||
// Same as IsAvailable(), but must be called with mutex_ held.
|
||||
bool IsAvailableLocked() const ABSL_EXCLUSIVE_LOCKS_REQUIRED(mutex_);
|
||||
|
||||
@@ -161,6 +172,13 @@ class Ble {
|
||||
bool IsAcceptingConnectionsLocked(const std::string& service_id)
|
||||
ABSL_EXCLUSIVE_LOCKS_REQUIRED(mutex_);
|
||||
|
||||
<<<<<<< HEAD
|
||||
=======
|
||||
// Extract connection advertisement from medium advertisement.
|
||||
ByteArray UnwrapAdvertisementBytes(
|
||||
const ByteArray& medium_advertisement_data);
|
||||
|
||||
>>>>>>> release
|
||||
mutable Mutex mutex_;
|
||||
BluetoothRadio& radio_ ABSL_GUARDED_BY(mutex_);
|
||||
BluetoothAdapter& adapter_ ABSL_GUARDED_BY(mutex_){
|
||||
@@ -168,6 +186,10 @@ class Ble {
|
||||
BleMedium medium_ ABSL_GUARDED_BY(mutex_){adapter_};
|
||||
AdvertisingInfo advertising_info_ ABSL_GUARDED_BY(mutex_);
|
||||
ScanningInfo scanning_info_ ABSL_GUARDED_BY(mutex_);
|
||||
<<<<<<< HEAD
|
||||
=======
|
||||
DiscoveredPeripheralCallback discovered_peripheral_callback_;
|
||||
>>>>>>> release
|
||||
AcceptingConnectionsInfo accepting_connections_info_ ABSL_GUARDED_BY(mutex_);
|
||||
};
|
||||
|
||||
|
||||
@@ -74,12 +74,20 @@ TEST_F(BleTest, CanStartAdvertising) {
|
||||
CountDownLatch found_latch(1);
|
||||
|
||||
ble_b.StartScanning(
|
||||
<<<<<<< HEAD
|
||||
service_id,
|
||||
fast_advertisement_service_uuid,
|
||||
=======
|
||||
service_id, fast_advertisement_service_uuid,
|
||||
>>>>>>> release
|
||||
DiscoveredPeripheralCallback{
|
||||
.peripheral_discovered_cb =
|
||||
[&found_latch](
|
||||
BlePeripheral& peripheral, const std::string& service_id,
|
||||
<<<<<<< HEAD
|
||||
=======
|
||||
const ByteArray& advertisement_bytes,
|
||||
>>>>>>> release
|
||||
bool fast_advertisement) { found_latch.CountDown(); },
|
||||
});
|
||||
|
||||
@@ -109,12 +117,20 @@ TEST_F(BleTest, CanStartDiscovery) {
|
||||
fast_advertisement_service_uuid);
|
||||
|
||||
EXPECT_TRUE(ble_a.StartScanning(
|
||||
<<<<<<< HEAD
|
||||
service_id,
|
||||
fast_advertisement_service_uuid,
|
||||
=======
|
||||
service_id, fast_advertisement_service_uuid,
|
||||
>>>>>>> release
|
||||
DiscoveredPeripheralCallback{
|
||||
.peripheral_discovered_cb =
|
||||
[&accept_latch](
|
||||
BlePeripheral& peripheral, const std::string& service_id,
|
||||
<<<<<<< HEAD
|
||||
=======
|
||||
const ByteArray& advertisement_bytes,
|
||||
>>>>>>> release
|
||||
bool fast_advertisement) { accept_latch.CountDown(); },
|
||||
.peripheral_lost_cb =
|
||||
[&lost_latch](BlePeripheral& peripheral,
|
||||
@@ -154,12 +170,20 @@ TEST_F(BleTest, CanStartAcceptingConnectionsAndConnect) {
|
||||
});
|
||||
BlePeripheral discovered_peripheral;
|
||||
ble_b.StartScanning(
|
||||
<<<<<<< HEAD
|
||||
service_id,
|
||||
fast_advertisement_service_uuid,
|
||||
=======
|
||||
service_id, fast_advertisement_service_uuid,
|
||||
>>>>>>> release
|
||||
{
|
||||
.peripheral_discovered_cb =
|
||||
[&found_latch, &discovered_peripheral](
|
||||
BlePeripheral& peripheral, const std::string& service_id,
|
||||
<<<<<<< HEAD
|
||||
=======
|
||||
const ByteArray& advertisement_bytes,
|
||||
>>>>>>> release
|
||||
bool fast_advertisement) {
|
||||
discovered_peripheral = peripheral;
|
||||
NEARBY_LOG(
|
||||
|
||||
@@ -30,6 +30,7 @@ BleAdvertisement::BleAdvertisement(Version version,
|
||||
const ByteArray &service_id_hash,
|
||||
const ByteArray &data,
|
||||
const ByteArray &device_token) {
|
||||
<<<<<<< HEAD
|
||||
DoInitialize(/*fast_advertisement=*/false, version, socket_version,
|
||||
service_id_hash, data, device_token);
|
||||
}
|
||||
@@ -40,6 +41,10 @@ BleAdvertisement::BleAdvertisement(Version version,
|
||||
const ByteArray &device_token) {
|
||||
DoInitialize(/*fast_advertisement=*/true, version, socket_version,
|
||||
{}, data, device_token);
|
||||
=======
|
||||
DoInitialize(/*fast_advertisement=*/service_id_hash.Empty(), version,
|
||||
socket_version, service_id_hash, data, device_token);
|
||||
>>>>>>> release
|
||||
}
|
||||
|
||||
void BleAdvertisement::DoInitialize(bool fast_advertisement, Version version,
|
||||
|
||||
@@ -61,8 +61,11 @@ class BleAdvertisement {
|
||||
BleAdvertisement(Version version, SocketVersion socket_version,
|
||||
const ByteArray &service_id_hash, const ByteArray &data,
|
||||
const ByteArray &device_token);
|
||||
<<<<<<< HEAD
|
||||
BleAdvertisement(Version version, SocketVersion socket_version,
|
||||
const ByteArray &data, const ByteArray &device_token);
|
||||
=======
|
||||
>>>>>>> release
|
||||
explicit BleAdvertisement(const ByteArray &ble_advertisement_bytes);
|
||||
BleAdvertisement(const BleAdvertisement &) = default;
|
||||
BleAdvertisement &operator=(const BleAdvertisement &) = default;
|
||||
|
||||
@@ -67,6 +67,10 @@ TEST(BleAdvertisementTest, ConstructionWorksV1ForFastAdvertisement) {
|
||||
|
||||
BleAdvertisement ble_advertisement{BleAdvertisement::Version::kV1,
|
||||
BleAdvertisement::SocketVersion::kV1,
|
||||
<<<<<<< HEAD
|
||||
=======
|
||||
ByteArray{},
|
||||
>>>>>>> release
|
||||
fast_data,
|
||||
device_token};
|
||||
|
||||
@@ -97,6 +101,10 @@ TEST(BleAdvertisementTest, ConstructionFailsWithBadVersion) {
|
||||
|
||||
BleAdvertisement fast_ble_advertisement{bad_version,
|
||||
kSocketVersion,
|
||||
<<<<<<< HEAD
|
||||
=======
|
||||
ByteArray{},
|
||||
>>>>>>> release
|
||||
data,
|
||||
device_token};
|
||||
EXPECT_FALSE(fast_ble_advertisement.IsValid());
|
||||
@@ -119,6 +127,10 @@ TEST(BleAdvertisementTest, ConstructionFailsWithBadSocketVersion) {
|
||||
|
||||
BleAdvertisement fast_ble_advertisement{kVersion,
|
||||
bad_socket_version,
|
||||
<<<<<<< HEAD
|
||||
=======
|
||||
ByteArray{},
|
||||
>>>>>>> release
|
||||
data,
|
||||
device_token};
|
||||
EXPECT_FALSE(fast_ble_advertisement.IsValid());
|
||||
@@ -174,6 +186,10 @@ TEST(BleAdvertisementTest, ConstructionFailsWithLongData) {
|
||||
|
||||
BleAdvertisement fast_ble_advertisement{kVersion,
|
||||
kSocketVersion,
|
||||
<<<<<<< HEAD
|
||||
=======
|
||||
ByteArray{},
|
||||
>>>>>>> release
|
||||
bad_data,
|
||||
device_token};
|
||||
EXPECT_FALSE(fast_ble_advertisement.IsValid());
|
||||
@@ -205,6 +221,10 @@ TEST(BleAdvertisementTest,
|
||||
|
||||
BleAdvertisement ble_advertisement{kVersion,
|
||||
kSocketVersion,
|
||||
<<<<<<< HEAD
|
||||
=======
|
||||
ByteArray{},
|
||||
>>>>>>> release
|
||||
fast_data,
|
||||
ByteArray{}};
|
||||
|
||||
@@ -242,12 +262,20 @@ TEST(BleAdvertisementTest, ConstructionFailsWithWrongSizeofDeviceToken) {
|
||||
|
||||
BleAdvertisement fast_ble_advertisement_1{kVersion,
|
||||
kSocketVersion,
|
||||
<<<<<<< HEAD
|
||||
=======
|
||||
ByteArray{},
|
||||
>>>>>>> release
|
||||
data,
|
||||
bad_device_token_1};
|
||||
EXPECT_FALSE(fast_ble_advertisement_1.IsValid());
|
||||
|
||||
BleAdvertisement fast_ble_advertisement_2{kVersion,
|
||||
kSocketVersion,
|
||||
<<<<<<< HEAD
|
||||
=======
|
||||
ByteArray{},
|
||||
>>>>>>> release
|
||||
data,
|
||||
bad_device_token_2};
|
||||
EXPECT_FALSE(fast_ble_advertisement_2.IsValid());
|
||||
@@ -284,6 +312,10 @@ TEST(BleAdvertisementTest,
|
||||
|
||||
BleAdvertisement org_ble_advertisement{kVersion,
|
||||
kSocketVersion,
|
||||
<<<<<<< HEAD
|
||||
=======
|
||||
ByteArray{},
|
||||
>>>>>>> release
|
||||
fast_data,
|
||||
device_token};
|
||||
|
||||
@@ -326,6 +358,10 @@ TEST(BleAdvertisementTest,
|
||||
|
||||
BleAdvertisement org_ble_advertisement{kVersion,
|
||||
kSocketVersion,
|
||||
<<<<<<< HEAD
|
||||
=======
|
||||
ByteArray{},
|
||||
>>>>>>> release
|
||||
ByteArray(),
|
||||
device_token};
|
||||
ByteArray ble_advertisement_bytes{org_ble_advertisement};
|
||||
@@ -380,6 +416,10 @@ TEST(BleAdvertisementTest,
|
||||
|
||||
BleAdvertisement org_ble_advertisement{kVersion,
|
||||
kSocketVersion,
|
||||
<<<<<<< HEAD
|
||||
=======
|
||||
ByteArray{},
|
||||
>>>>>>> release
|
||||
fast_data,
|
||||
device_token};
|
||||
ByteArray org_ble_advertisement_bytes{org_ble_advertisement};
|
||||
@@ -438,6 +478,10 @@ TEST(BleAdvertisementTest,
|
||||
|
||||
BleAdvertisement org_ble_advertisement{kVersion,
|
||||
kSocketVersion,
|
||||
<<<<<<< HEAD
|
||||
=======
|
||||
ByteArray{},
|
||||
>>>>>>> release
|
||||
fast_data,
|
||||
device_token};
|
||||
ByteArray org_ble_advertisement_bytes{org_ble_advertisement};
|
||||
@@ -489,6 +533,10 @@ TEST(BleAdvertisementTest,
|
||||
|
||||
BleAdvertisement org_ble_advertisement{kVersion,
|
||||
kSocketVersion,
|
||||
<<<<<<< HEAD
|
||||
=======
|
||||
ByteArray{},
|
||||
>>>>>>> release
|
||||
fast_data,
|
||||
device_token};
|
||||
ByteArray org_ble_advertisement_bytes{org_ble_advertisement};
|
||||
|
||||
@@ -245,6 +245,13 @@ bool ConnectionFlow::Close() {
|
||||
|
||||
bool ConnectionFlow::InitPeerConnection(WebRtcMedium& webrtc_medium) {
|
||||
Future<bool> success_future;
|
||||
<<<<<<< HEAD
|
||||
=======
|
||||
// CreatePeerConnection callback may be invoked after ConnectionFlow lifetime
|
||||
// has ended, in case of a timeout. Future is captured by value, and is safe
|
||||
// to access, but it is not safe to access ConnectionFlow member variables
|
||||
// unless the Future::Set() returns true.
|
||||
>>>>>>> release
|
||||
webrtc_medium.CreatePeerConnection(
|
||||
&peer_connection_observer_,
|
||||
[this, success_future](rtc::scoped_refptr<webrtc::PeerConnectionInterface>
|
||||
@@ -254,6 +261,14 @@ bool ConnectionFlow::InitPeerConnection(WebRtcMedium& webrtc_medium) {
|
||||
return;
|
||||
}
|
||||
|
||||
<<<<<<< HEAD
|
||||
=======
|
||||
// If this fails, means we have already assigned something to
|
||||
// success_future; it is either:
|
||||
// 1) this is the 2nd call of this callback (and this is a bug), or
|
||||
// 2) Get(timeout) has set the future value as exception already.
|
||||
if (success_future.IsSet()) return;
|
||||
>>>>>>> release
|
||||
peer_connection_ = peer_connection;
|
||||
success_future.Set(true);
|
||||
});
|
||||
|
||||
@@ -18,6 +18,10 @@
|
||||
#include <utility>
|
||||
|
||||
#include "core/internal/message_lite.h"
|
||||
<<<<<<< HEAD
|
||||
=======
|
||||
#include "core_v2/status.h"
|
||||
>>>>>>> release
|
||||
#include "proto/connections/offline_wire_formats.pb.h"
|
||||
#include "platform_v2/base/byte_array.h"
|
||||
|
||||
@@ -85,7 +89,18 @@ ByteArray ForConnectionResponse(std::int32_t status) {
|
||||
auto* v1_frame = frame.mutable_v1();
|
||||
v1_frame->set_type(V1Frame::CONNECTION_RESPONSE);
|
||||
auto* sub_frame = v1_frame->mutable_connection_response();
|
||||
<<<<<<< HEAD
|
||||
sub_frame->set_status(status);
|
||||
=======
|
||||
|
||||
// For backward compatiblility, here still sets both status and response
|
||||
// parameters until the response feature is roll out in all supported
|
||||
// devices.
|
||||
sub_frame->set_status(status);
|
||||
sub_frame->set_response(status == Status::kSuccess
|
||||
? ConnectionResponseFrame::ACCEPT
|
||||
: ConnectionResponseFrame::REJECT);
|
||||
>>>>>>> release
|
||||
|
||||
return ToBytes(std::move(frame));
|
||||
}
|
||||
|
||||
@@ -107,7 +107,14 @@ TEST(OfflineFramesTest, CanGenerateConnectionResponse) {
|
||||
version: V1
|
||||
v1: <
|
||||
type: CONNECTION_RESPONSE
|
||||
<<<<<<< HEAD
|
||||
connection_response: < status: 1 >
|
||||
=======
|
||||
connection_response: <
|
||||
status: 1
|
||||
response: REJECT
|
||||
>
|
||||
>>>>>>> release
|
||||
>)pb";
|
||||
ByteArray bytes = ForConnectionResponse(1);
|
||||
auto response = FromBytes(bytes);
|
||||
|
||||
@@ -328,9 +328,16 @@ bool P2pClusterPcpHandler::IsRecognizedBleEndpoint(
|
||||
|
||||
void P2pClusterPcpHandler::BlePeripheralDiscoveredHandler(
|
||||
ClientProxy* client, BlePeripheral& peripheral,
|
||||
<<<<<<< HEAD
|
||||
const std::string& service_id, bool fast_advertisement) {
|
||||
RunOnPcpHandlerThread([this, client, &peripheral, service_id,
|
||||
fast_advertisement]() {
|
||||
=======
|
||||
const std::string& service_id, const ByteArray& advertisement_bytes,
|
||||
bool fast_advertisement) {
|
||||
RunOnPcpHandlerThread([this, client, &peripheral, service_id,
|
||||
advertisement_bytes, fast_advertisement]() {
|
||||
>>>>>>> release
|
||||
// Make sure we are still discovering before proceeding.
|
||||
if (!client->IsDiscovering()) {
|
||||
NEARBY_LOG(INFO,
|
||||
@@ -341,8 +348,12 @@ void P2pClusterPcpHandler::BlePeripheralDiscoveredHandler(
|
||||
}
|
||||
|
||||
// Parse the BLE advertisement bytes.
|
||||
<<<<<<< HEAD
|
||||
BleAdvertisement advertisement(
|
||||
fast_advertisement, peripheral.GetAdvertisementBytes(service_id));
|
||||
=======
|
||||
BleAdvertisement advertisement(fast_advertisement, advertisement_bytes);
|
||||
>>>>>>> release
|
||||
|
||||
// Make sure the BLE advertisement points to a valid
|
||||
// endpoint we're discovering.
|
||||
@@ -582,6 +593,12 @@ BasePcpHandler::StartOperationResult P2pClusterPcpHandler::StartDiscoveryImpl(
|
||||
.device_discovered_cb = absl::bind_front(
|
||||
&P2pClusterPcpHandler::BluetoothDeviceDiscoveredHandler, this,
|
||||
client, service_id),
|
||||
<<<<<<< HEAD
|
||||
=======
|
||||
.device_name_changed_cb = absl::bind_front(
|
||||
&P2pClusterPcpHandler::BluetoothDeviceDiscoveredHandler, this,
|
||||
client, service_id),
|
||||
>>>>>>> release
|
||||
.device_lost_cb = absl::bind_front(
|
||||
&P2pClusterPcpHandler::BluetoothDeviceLostHandler, this, client,
|
||||
service_id),
|
||||
@@ -728,9 +745,17 @@ proto::connections::Medium P2pClusterPcpHandler::StartBluetoothAdvertising(
|
||||
absl::BytesToHexString(service_id_hash.data()).c_str(),
|
||||
absl::BytesToHexString(local_endpoint_info.data()).c_str());
|
||||
// Generate a BluetoothDeviceName with which to become Bluetooth discoverable.
|
||||
<<<<<<< HEAD
|
||||
std::string device_name(BluetoothDeviceName(
|
||||
kBluetoothDeviceNameVersion, GetPcp(), local_endpoint_id, service_id_hash,
|
||||
local_endpoint_info));
|
||||
=======
|
||||
// TODO(b/169550050): Implement UWBAddress.
|
||||
// TODO(b/169303359): Implement WebRtcState.
|
||||
std::string device_name(BluetoothDeviceName(
|
||||
kBluetoothDeviceNameVersion, GetPcp(), local_endpoint_id, service_id_hash,
|
||||
local_endpoint_info, ByteArray{}, WebRtcState::kUnconnectable));
|
||||
>>>>>>> release
|
||||
if (device_name.empty()) {
|
||||
NEARBY_LOG(INFO,
|
||||
"P2pClusterPcpHandler::StartBluetoothAdvertising: generate "
|
||||
@@ -901,10 +926,18 @@ proto::connections::Medium P2pClusterPcpHandler::StartBleAdvertising(
|
||||
// Generate a BleAdvertisement. If a fast advertisement service UUID was
|
||||
// provided, create a fast BleAdvertisement.
|
||||
ByteArray advertisement_bytes;
|
||||
<<<<<<< HEAD
|
||||
if (fast_advertisement) {
|
||||
advertisement_bytes =
|
||||
ByteArray(BleAdvertisement(kBleAdvertisementVersion, GetPcp(),
|
||||
local_endpoint_id, local_endpoint_info));
|
||||
=======
|
||||
// TODO(b/169550050): Implement UWBAddress.
|
||||
if (fast_advertisement) {
|
||||
advertisement_bytes = ByteArray(
|
||||
BleAdvertisement(kBleAdvertisementVersion, GetPcp(), local_endpoint_id,
|
||||
local_endpoint_info, ByteArray{}));
|
||||
>>>>>>> release
|
||||
} else {
|
||||
const ByteArray service_id_hash =
|
||||
GenerateHash(service_id, BleAdvertisement::kServiceIdHashLength);
|
||||
@@ -913,9 +946,17 @@ proto::connections::Medium P2pClusterPcpHandler::StartBleAdvertising(
|
||||
ShouldAdvertiseBluetoothMacOverBle(power_level))
|
||||
bluetooth_mac_address = bluetooth_medium_.GetMacAddress();
|
||||
|
||||
<<<<<<< HEAD
|
||||
advertisement_bytes = ByteArray(BleAdvertisement(
|
||||
kBleAdvertisementVersion, GetPcp(), service_id_hash, local_endpoint_id,
|
||||
local_endpoint_info, bluetooth_mac_address));
|
||||
=======
|
||||
// TODO(b/169303359): Implement WebRtcState.
|
||||
advertisement_bytes = ByteArray(BleAdvertisement(
|
||||
kBleAdvertisementVersion, GetPcp(), service_id_hash, local_endpoint_id,
|
||||
local_endpoint_info, bluetooth_mac_address, ByteArray{},
|
||||
WebRtcState::kUnconnectable));
|
||||
>>>>>>> release
|
||||
}
|
||||
if (advertisement_bytes.Empty()) {
|
||||
NEARBY_LOG(INFO,
|
||||
@@ -1036,9 +1077,17 @@ proto::connections::Medium P2pClusterPcpHandler::StartWifiLanAdvertising(
|
||||
absl::BytesToHexString(service_id_hash.data()).c_str(),
|
||||
absl::BytesToHexString(local_endpoint_info.data()).c_str());
|
||||
// Generate a WifiLanServiceInfo with which to become WifiLan discoverable.
|
||||
<<<<<<< HEAD
|
||||
std::string service_info_name(WifiLanServiceInfo(
|
||||
kWifiLanServiceInfoVersion, GetPcp(), local_endpoint_id, service_id_hash,
|
||||
local_endpoint_info));
|
||||
=======
|
||||
// TODO(b/169550050): Implement UWBAddress.
|
||||
// TODO(b/169303359): Implement WebRtcState.
|
||||
std::string service_info_name(WifiLanServiceInfo(
|
||||
kWifiLanServiceInfoVersion, GetPcp(), local_endpoint_id, service_id_hash,
|
||||
local_endpoint_info, ByteArray{}, WebRtcState::kUnconnectable));
|
||||
>>>>>>> release
|
||||
if (service_info_name.empty()) {
|
||||
NEARBY_LOG(INFO,
|
||||
"P2pClusterPcpHandler::StartWifiLanAdvertising: generate "
|
||||
|
||||
@@ -165,6 +165,10 @@ class P2pClusterPcpHandler : public BasePcpHandler {
|
||||
void BlePeripheralDiscoveredHandler(ClientProxy* client,
|
||||
BlePeripheral& peripheral,
|
||||
const std::string& service_id,
|
||||
<<<<<<< HEAD
|
||||
=======
|
||||
const ByteArray& advertisement_bytes,
|
||||
>>>>>>> release
|
||||
bool fast_advertisement);
|
||||
void BlePeripheralLostHandler(ClientProxy* client, BlePeripheral& peripheral,
|
||||
const std::string& service_id);
|
||||
|
||||
@@ -31,7 +31,13 @@ namespace connections {
|
||||
WifiLanServiceInfo::WifiLanServiceInfo(Version version, Pcp pcp,
|
||||
absl::string_view endpoint_id,
|
||||
const ByteArray& service_id_hash,
|
||||
<<<<<<< HEAD
|
||||
const ByteArray& endpoint_info) {
|
||||
=======
|
||||
const ByteArray& endpoint_info,
|
||||
const ByteArray& uwb_address,
|
||||
WebRtcState web_rtc_state) {
|
||||
>>>>>>> release
|
||||
if (version != Version::kV1 || endpoint_id.empty() ||
|
||||
endpoint_id.length() != kEndpointIdLength ||
|
||||
service_id_hash.size() != kServiceIdHashLength) {
|
||||
@@ -51,6 +57,11 @@ WifiLanServiceInfo::WifiLanServiceInfo(Version version, Pcp pcp,
|
||||
service_id_hash_ = service_id_hash;
|
||||
endpoint_id_ = std::string(endpoint_id);
|
||||
endpoint_info_ = endpoint_info;
|
||||
<<<<<<< HEAD
|
||||
=======
|
||||
uwb_address_ = uwb_address;
|
||||
web_rtc_state_ = web_rtc_state;
|
||||
>>>>>>> release
|
||||
}
|
||||
|
||||
WifiLanServiceInfo::WifiLanServiceInfo(absl::string_view service_info_string) {
|
||||
@@ -64,6 +75,7 @@ WifiLanServiceInfo::WifiLanServiceInfo(absl::string_view service_info_string) {
|
||||
return;
|
||||
}
|
||||
|
||||
<<<<<<< HEAD
|
||||
if (service_info_bytes.size() > kMaxLanServiceNameLength) {
|
||||
NEARBY_LOG(INFO,
|
||||
"Cannot deserialize WifiLanServiceInfo: expecting max %d raw "
|
||||
@@ -72,6 +84,8 @@ WifiLanServiceInfo::WifiLanServiceInfo(absl::string_view service_info_string) {
|
||||
return;
|
||||
}
|
||||
|
||||
=======
|
||||
>>>>>>> release
|
||||
if (service_info_bytes.size() < kMinLanServiceNameLength) {
|
||||
NEARBY_LOG(INFO,
|
||||
"Cannot deserialize WifiLanServiceInfo: expecting min %d raw "
|
||||
@@ -119,6 +133,23 @@ WifiLanServiceInfo::WifiLanServiceInfo(absl::string_view service_info_string) {
|
||||
// The next 3 bytes are supposed to be the service_id_hash.
|
||||
service_id_hash_ = base_input_stream.ReadBytes(kServiceIdHashLength);
|
||||
|
||||
<<<<<<< HEAD
|
||||
=======
|
||||
// The next 1 byte are supposed to be the length of the UWB address.
|
||||
std::uint32_t expected_uwb_address_length = base_input_stream.ReadUint8();
|
||||
|
||||
// The next bytes are supposed to be UWB address if length is not zero.
|
||||
if (expected_uwb_address_length != 0) {
|
||||
uwb_address_ = base_input_stream.ReadBytes(expected_uwb_address_length);
|
||||
}
|
||||
|
||||
// The next 1 byte is extra field.
|
||||
auto extra_field = static_cast<char>(base_input_stream.ReadUint8());
|
||||
web_rtc_state_ = (extra_field & kWebRtcConnectableFlagBitmask) == 1
|
||||
? WebRtcState::kConnectable
|
||||
: WebRtcState::kUnconnectable;
|
||||
|
||||
>>>>>>> release
|
||||
// The next 1 byte are supposed to be the length of the endpoint_info.
|
||||
std::uint32_t expected_endpoint_info_length = base_input_stream.ReadUint8();
|
||||
|
||||
@@ -149,6 +180,15 @@ WifiLanServiceInfo::operator std::string() const {
|
||||
version_and_pcp_byte |=
|
||||
static_cast<char>(static_cast<uint32_t>(pcp_) & kPcpBitmask);
|
||||
|
||||
<<<<<<< HEAD
|
||||
=======
|
||||
// A byte contains WebRtcState state.
|
||||
int web_rtc_connectable_flag =
|
||||
(web_rtc_state_ == WebRtcState::kConnectable) ? 1 : 0;
|
||||
char field_byte = static_cast<char>(web_rtc_connectable_flag) &
|
||||
kWebRtcConnectableFlagBitmask;
|
||||
|
||||
>>>>>>> release
|
||||
ByteArray usable_endpoint_info(endpoint_info_);
|
||||
if (endpoint_info_.size() > kMaxEndpointInfoLength) {
|
||||
NEARBY_LOG(
|
||||
@@ -160,6 +200,7 @@ WifiLanServiceInfo::operator std::string() const {
|
||||
usable_endpoint_info.SetData(endpoint_info_.data(), kMaxEndpointInfoLength);
|
||||
}
|
||||
|
||||
<<<<<<< HEAD
|
||||
// clang-format off
|
||||
std::string out = absl::StrCat(std::string(1, version_and_pcp_byte),
|
||||
endpoint_id_,
|
||||
@@ -167,6 +208,31 @@ WifiLanServiceInfo::operator std::string() const {
|
||||
std::string(1, usable_endpoint_info.size()),
|
||||
std::string(usable_endpoint_info));
|
||||
// clang-format on
|
||||
=======
|
||||
std::string out;
|
||||
if (!uwb_address_.Empty()) {
|
||||
// clang-format off
|
||||
out = absl::StrCat(std::string(1, version_and_pcp_byte),
|
||||
endpoint_id_,
|
||||
std::string(service_id_hash_),
|
||||
std::string(1, uwb_address_.size()),
|
||||
std::string(uwb_address_),
|
||||
std::string(1, field_byte),
|
||||
std::string(1, usable_endpoint_info.size()),
|
||||
std::string(usable_endpoint_info));
|
||||
// clang-format on
|
||||
} else {
|
||||
// clang-format off
|
||||
out = absl::StrCat(std::string(1, version_and_pcp_byte),
|
||||
endpoint_id_,
|
||||
std::string(service_id_hash_),
|
||||
std::string(1, uwb_address_.size()),
|
||||
std::string(1, field_byte),
|
||||
std::string(1, usable_endpoint_info.size()),
|
||||
std::string(usable_endpoint_info));
|
||||
// clang-format on
|
||||
}
|
||||
>>>>>>> release
|
||||
|
||||
return Base64Utils::Encode(ByteArray{std::move(out)});
|
||||
}
|
||||
|
||||
@@ -17,6 +17,10 @@
|
||||
|
||||
#include <cstdint>
|
||||
|
||||
<<<<<<< HEAD
|
||||
=======
|
||||
#include "core_v2/internal/base_pcp_handler.h"
|
||||
>>>>>>> release
|
||||
#include "core_v2/internal/pcp.h"
|
||||
#include "platform_v2/base/byte_array.h"
|
||||
#include "absl/strings/string_view.h"
|
||||
@@ -42,7 +46,13 @@ class WifiLanServiceInfo {
|
||||
WifiLanServiceInfo() = default;
|
||||
WifiLanServiceInfo(Version version, Pcp pcp, absl::string_view endpoint_id,
|
||||
const ByteArray& service_id_hash,
|
||||
<<<<<<< HEAD
|
||||
const ByteArray& endpoint_info);
|
||||
=======
|
||||
const ByteArray& endpoint_info,
|
||||
const ByteArray& uwb_address,
|
||||
WebRtcState web_rtc_state);
|
||||
>>>>>>> release
|
||||
explicit WifiLanServiceInfo(absl::string_view service_info_string);
|
||||
WifiLanServiceInfo(const WifiLanServiceInfo&) = default;
|
||||
WifiLanServiceInfo& operator=(const WifiLanServiceInfo&) = default;
|
||||
@@ -58,6 +68,7 @@ class WifiLanServiceInfo {
|
||||
std::string GetEndpointId() const { return endpoint_id_; }
|
||||
ByteArray GetEndpointInfo() const { return endpoint_info_; }
|
||||
ByteArray GetServiceIdHash() const { return service_id_hash_; }
|
||||
<<<<<<< HEAD
|
||||
|
||||
private:
|
||||
// The maximum length of encrypted WifiLanServiceInfo string.
|
||||
@@ -68,10 +79,21 @@ class WifiLanServiceInfo {
|
||||
static constexpr int kEndpointIdLength = 4;
|
||||
// The maximum length for endpoint id in encrypted WifiLanServiceInfo string.
|
||||
static constexpr int kMaxEndpointInfoLength = 131;
|
||||
=======
|
||||
ByteArray GetUwbAddress() const { return uwb_address_; }
|
||||
WebRtcState GetWebRtcState() const { return web_rtc_state_; }
|
||||
|
||||
private:
|
||||
static constexpr int kMinLanServiceNameLength = 9;
|
||||
static constexpr int kEndpointIdLength = 4;
|
||||
static constexpr int kMaxEndpointInfoLength = 131;
|
||||
static constexpr int kUwbAddressLengthSize = 1;
|
||||
>>>>>>> release
|
||||
|
||||
static constexpr int kVersionBitmask = 0x0E0;
|
||||
static constexpr int kPcpBitmask = 0x01F;
|
||||
static constexpr int kVersionShift = 5;
|
||||
<<<<<<< HEAD
|
||||
|
||||
// WifiLanServiceInfo version.
|
||||
Version version_ = Version::kUndefined;
|
||||
@@ -83,6 +105,18 @@ class WifiLanServiceInfo {
|
||||
ByteArray service_id_hash_;
|
||||
// Connected endpoint info.
|
||||
ByteArray endpoint_info_;
|
||||
=======
|
||||
static constexpr int kWebRtcConnectableFlagBitmask = 0x01;
|
||||
|
||||
Version version_{Version::kUndefined};
|
||||
Pcp pcp_{Pcp::kUnknown};
|
||||
std::string endpoint_id_;
|
||||
ByteArray service_id_hash_;
|
||||
ByteArray endpoint_info_;
|
||||
// TODO(b/169550050): Define UWB address field.
|
||||
ByteArray uwb_address_;
|
||||
WebRtcState web_rtc_state_{WebRtcState::kUndefined};
|
||||
>>>>>>> release
|
||||
};
|
||||
|
||||
} // namespace connections
|
||||
|
||||
@@ -31,12 +31,28 @@ constexpr Pcp kPcp = Pcp::kP2pCluster;
|
||||
constexpr absl::string_view kEndPointID{"AB12"};
|
||||
constexpr absl::string_view kServiceIDHashBytes{"\x0a\x0b\x0c"};
|
||||
constexpr absl::string_view kEndPointName{"RAWK + ROWL!"};
|
||||
<<<<<<< HEAD
|
||||
|
||||
TEST(WifiLanServiceInfoTest, ConstructionWorks) {
|
||||
ByteArray service_id_hash{std::string(kServiceIDHashBytes)};
|
||||
ByteArray endpoint_info{std::string(kEndPointName)};
|
||||
WifiLanServiceInfo wifi_lan_service_info{
|
||||
kVersion, kPcp, kEndPointID, service_id_hash, endpoint_info};
|
||||
=======
|
||||
constexpr WebRtcState kWebRtcState = WebRtcState::kConnectable;
|
||||
|
||||
// TODO(b/169550050): Implement UWBAddress.
|
||||
TEST(WifiLanServiceInfoTest, ConstructionWorks) {
|
||||
ByteArray service_id_hash{std::string(kServiceIDHashBytes)};
|
||||
ByteArray endpoint_info{std::string(kEndPointName)};
|
||||
WifiLanServiceInfo wifi_lan_service_info{kVersion,
|
||||
kPcp,
|
||||
kEndPointID,
|
||||
service_id_hash,
|
||||
endpoint_info,
|
||||
ByteArray{},
|
||||
kWebRtcState};
|
||||
>>>>>>> release
|
||||
|
||||
EXPECT_TRUE(wifi_lan_service_info.IsValid());
|
||||
EXPECT_EQ(kPcp, wifi_lan_service_info.GetPcp());
|
||||
@@ -49,8 +65,18 @@ TEST(WifiLanServiceInfoTest, ConstructionWorks) {
|
||||
TEST(WifiLanServiceInfoTest, ConstructionFromSerializedStringWorks) {
|
||||
ByteArray service_id_hash{std::string(kServiceIDHashBytes)};
|
||||
ByteArray endpoint_info{std::string(kEndPointName)};
|
||||
<<<<<<< HEAD
|
||||
WifiLanServiceInfo org_wifi_lan_service_info{kVersion, kPcp, kEndPointID,
|
||||
service_id_hash, endpoint_info};
|
||||
=======
|
||||
WifiLanServiceInfo org_wifi_lan_service_info{kVersion,
|
||||
kPcp,
|
||||
kEndPointID,
|
||||
service_id_hash,
|
||||
endpoint_info,
|
||||
ByteArray{},
|
||||
kWebRtcState};
|
||||
>>>>>>> release
|
||||
std::string wifi_lan_service_info_string{org_wifi_lan_service_info};
|
||||
|
||||
WifiLanServiceInfo wifi_lan_service_info{wifi_lan_service_info_string};
|
||||
@@ -61,6 +87,10 @@ TEST(WifiLanServiceInfoTest, ConstructionFromSerializedStringWorks) {
|
||||
EXPECT_EQ(kEndPointID, wifi_lan_service_info.GetEndpointId());
|
||||
EXPECT_EQ(service_id_hash, wifi_lan_service_info.GetServiceIdHash());
|
||||
EXPECT_EQ(endpoint_info, wifi_lan_service_info.GetEndpointInfo());
|
||||
<<<<<<< HEAD
|
||||
=======
|
||||
EXPECT_EQ(kWebRtcState, wifi_lan_service_info.GetWebRtcState());
|
||||
>>>>>>> release
|
||||
}
|
||||
|
||||
TEST(WifiLanServiceInfoTest, ConstructionFailsWithBadVersion) {
|
||||
@@ -68,8 +98,18 @@ TEST(WifiLanServiceInfoTest, ConstructionFailsWithBadVersion) {
|
||||
|
||||
ByteArray service_id_hash{std::string(kServiceIDHashBytes)};
|
||||
ByteArray endpoint_info{std::string(kEndPointName)};
|
||||
<<<<<<< HEAD
|
||||
WifiLanServiceInfo wifi_lan_service_info{bad_version, kPcp, kEndPointID,
|
||||
service_id_hash, endpoint_info};
|
||||
=======
|
||||
WifiLanServiceInfo wifi_lan_service_info{bad_version,
|
||||
kPcp,
|
||||
kEndPointID,
|
||||
service_id_hash,
|
||||
endpoint_info,
|
||||
ByteArray{},
|
||||
kWebRtcState};
|
||||
>>>>>>> release
|
||||
|
||||
EXPECT_FALSE(wifi_lan_service_info.IsValid());
|
||||
}
|
||||
@@ -79,8 +119,18 @@ TEST(WifiLanServiceInfoTest, ConstructionFailsWithBadPCP) {
|
||||
|
||||
ByteArray service_id_hash{std::string(kServiceIDHashBytes)};
|
||||
ByteArray endpoint_info{std::string(kEndPointName)};
|
||||
<<<<<<< HEAD
|
||||
WifiLanServiceInfo wifi_lan_service_info{kVersion, bad_pcp, kEndPointID,
|
||||
service_id_hash, endpoint_info};
|
||||
=======
|
||||
WifiLanServiceInfo wifi_lan_service_info{kVersion,
|
||||
bad_pcp,
|
||||
kEndPointID,
|
||||
service_id_hash,
|
||||
endpoint_info,
|
||||
ByteArray{},
|
||||
kWebRtcState};
|
||||
>>>>>>> release
|
||||
|
||||
EXPECT_FALSE(wifi_lan_service_info.IsValid());
|
||||
}
|
||||
@@ -90,8 +140,18 @@ TEST(WifiLanServiceInfoTest, ConstructionFailsWithShortEndpointId) {
|
||||
|
||||
ByteArray service_id_hash{std::string(kServiceIDHashBytes)};
|
||||
ByteArray endpoint_info{std::string(kEndPointName)};
|
||||
<<<<<<< HEAD
|
||||
WifiLanServiceInfo wifi_lan_service_info{kVersion, kPcp, short_endpoint_id,
|
||||
service_id_hash, endpoint_info};
|
||||
=======
|
||||
WifiLanServiceInfo wifi_lan_service_info{kVersion,
|
||||
kPcp,
|
||||
short_endpoint_id,
|
||||
service_id_hash,
|
||||
endpoint_info,
|
||||
ByteArray{},
|
||||
kWebRtcState};
|
||||
>>>>>>> release
|
||||
|
||||
EXPECT_FALSE(wifi_lan_service_info.IsValid());
|
||||
}
|
||||
@@ -101,8 +161,18 @@ TEST(WifiLanServiceInfoTest, ConstructionFailsWithLongEndpointId) {
|
||||
|
||||
ByteArray service_id_hash{std::string(kServiceIDHashBytes)};
|
||||
ByteArray endpoint_info{std::string(kEndPointName)};
|
||||
<<<<<<< HEAD
|
||||
WifiLanServiceInfo wifi_lan_service_info{kVersion, kPcp, long_endpoint_id,
|
||||
service_id_hash, endpoint_info};
|
||||
=======
|
||||
WifiLanServiceInfo wifi_lan_service_info{kVersion,
|
||||
kPcp,
|
||||
long_endpoint_id,
|
||||
service_id_hash,
|
||||
endpoint_info,
|
||||
ByteArray{},
|
||||
kWebRtcState};
|
||||
>>>>>>> release
|
||||
|
||||
EXPECT_FALSE(wifi_lan_service_info.IsValid());
|
||||
}
|
||||
@@ -112,8 +182,18 @@ TEST(WifiLanServiceInfoTest, ConstructionFailsWithShortServiceIdHash) {
|
||||
|
||||
ByteArray short_service_id_hash{short_service_id_hash_bytes};
|
||||
ByteArray endpoint_info{std::string(kEndPointName)};
|
||||
<<<<<<< HEAD
|
||||
WifiLanServiceInfo wifi_lan_service_info{
|
||||
kVersion, kPcp, kEndPointID, short_service_id_hash, endpoint_info};
|
||||
=======
|
||||
WifiLanServiceInfo wifi_lan_service_info{kVersion,
|
||||
kPcp,
|
||||
kEndPointID,
|
||||
short_service_id_hash,
|
||||
endpoint_info,
|
||||
ByteArray{},
|
||||
kWebRtcState};
|
||||
>>>>>>> release
|
||||
|
||||
EXPECT_FALSE(wifi_lan_service_info.IsValid());
|
||||
}
|
||||
@@ -123,8 +203,18 @@ TEST(WifiLanServiceInfoTest, ConstructionFailsWithLongServiceIdHash) {
|
||||
|
||||
ByteArray long_service_id_hash{long_service_id_hash_bytes};
|
||||
ByteArray endpoint_info{std::string(kEndPointName)};
|
||||
<<<<<<< HEAD
|
||||
WifiLanServiceInfo wifi_lan_service_info{kVersion, kPcp, kEndPointID,
|
||||
long_service_id_hash, endpoint_info};
|
||||
=======
|
||||
WifiLanServiceInfo wifi_lan_service_info{kVersion,
|
||||
kPcp,
|
||||
kEndPointID,
|
||||
long_service_id_hash,
|
||||
endpoint_info,
|
||||
ByteArray{},
|
||||
kWebRtcState};
|
||||
>>>>>>> release
|
||||
|
||||
EXPECT_FALSE(wifi_lan_service_info.IsValid());
|
||||
}
|
||||
|
||||
@@ -65,7 +65,13 @@ bool BleMedium::StartScanning(
|
||||
&context.peripheral, &peripheral,
|
||||
peripheral.GetName().c_str());
|
||||
discovered_peripheral_callback_.peripheral_discovered_cb(
|
||||
<<<<<<< HEAD
|
||||
context.peripheral, service_id, fast_advertisement);
|
||||
=======
|
||||
context.peripheral, service_id,
|
||||
context.peripheral.GetAdvertisementBytes(service_id),
|
||||
fast_advertisement);
|
||||
>>>>>>> release
|
||||
}
|
||||
},
|
||||
.peripheral_lost_cb =
|
||||
|
||||
@@ -85,11 +85,20 @@ class BleMedium final {
|
||||
public:
|
||||
using Platform = api::ImplementationPlatform;
|
||||
struct DiscoveredPeripheralCallback {
|
||||
<<<<<<< HEAD
|
||||
std::function<void(BlePeripheral& peripheral,
|
||||
const std::string& service_id,
|
||||
bool fast_advertisement)>
|
||||
peripheral_discovered_cb =
|
||||
DefaultCallback<BlePeripheral&, const std::string&, bool>();
|
||||
=======
|
||||
std::function<void(BlePeripheral& peripheral, const std::string& service_id,
|
||||
const ByteArray& advertisement_bytes,
|
||||
bool fast_advertisement)>
|
||||
peripheral_discovered_cb =
|
||||
DefaultCallback<BlePeripheral&, const std::string&,
|
||||
const ByteArray&, bool>();
|
||||
>>>>>>> release
|
||||
std::function<void(BlePeripheral& peripheral,
|
||||
const std::string& service_id)>
|
||||
peripheral_lost_cb =
|
||||
|
||||
@@ -72,12 +72,20 @@ TEST_F(BleMediumTest, CanStartAdvertising) {
|
||||
fast_advertisement_service_uuid);
|
||||
|
||||
EXPECT_TRUE(ble_b.StartScanning(
|
||||
<<<<<<< HEAD
|
||||
service_id,
|
||||
fast_advertisement_service_uuid,
|
||||
=======
|
||||
service_id, fast_advertisement_service_uuid,
|
||||
>>>>>>> release
|
||||
DiscoveredPeripheralCallback{
|
||||
.peripheral_discovered_cb =
|
||||
[&found_latch](
|
||||
BlePeripheral& peripheral, const std::string& service_id,
|
||||
<<<<<<< HEAD
|
||||
=======
|
||||
const ByteArray& advertisement_bytes,
|
||||
>>>>>>> release
|
||||
bool fast_advertisement) { found_latch.CountDown(); },
|
||||
}));
|
||||
EXPECT_TRUE(found_latch.Await(kWaitDuration).result());
|
||||
@@ -99,12 +107,20 @@ TEST_F(BleMediumTest, CanStartScanning) {
|
||||
CountDownLatch lost_latch(1);
|
||||
|
||||
ble_a.StartScanning(
|
||||
<<<<<<< HEAD
|
||||
service_id,
|
||||
fast_advertisement_service_uuid,
|
||||
=======
|
||||
service_id, fast_advertisement_service_uuid,
|
||||
>>>>>>> release
|
||||
DiscoveredPeripheralCallback{
|
||||
.peripheral_discovered_cb =
|
||||
[&found_latch](
|
||||
BlePeripheral& peripheral, const std::string& service_id,
|
||||
<<<<<<< HEAD
|
||||
=======
|
||||
const ByteArray& advertisement_bytes,
|
||||
>>>>>>> release
|
||||
bool fast_advertisement) { found_latch.CountDown(); },
|
||||
.peripheral_lost_cb =
|
||||
[&lost_latch](BlePeripheral& peripheral,
|
||||
@@ -134,12 +150,20 @@ TEST_F(BleMediumTest, CanStopDiscovery) {
|
||||
CountDownLatch lost_latch(1);
|
||||
|
||||
ble_a.StartScanning(
|
||||
<<<<<<< HEAD
|
||||
service_id,
|
||||
fast_advertisement_service_uuid,
|
||||
=======
|
||||
service_id, fast_advertisement_service_uuid,
|
||||
>>>>>>> release
|
||||
DiscoveredPeripheralCallback{
|
||||
.peripheral_discovered_cb =
|
||||
[&found_latch](
|
||||
BlePeripheral& peripheral, const std::string& service_id,
|
||||
<<<<<<< HEAD
|
||||
=======
|
||||
const ByteArray& advertisement_bytes,
|
||||
>>>>>>> release
|
||||
bool fast_advertisement) { found_latch.CountDown(); },
|
||||
.peripheral_lost_cb =
|
||||
[&lost_latch](BlePeripheral& peripheral,
|
||||
@@ -170,12 +194,20 @@ TEST_F(BleMediumTest, CanStartAcceptingConnectionsAndConnect) {
|
||||
|
||||
BlePeripheral* discovered_peripheral = nullptr;
|
||||
ble_a.StartScanning(
|
||||
<<<<<<< HEAD
|
||||
service_id,
|
||||
fast_advertisement_service_uuid,
|
||||
=======
|
||||
service_id, fast_advertisement_service_uuid,
|
||||
>>>>>>> release
|
||||
DiscoveredPeripheralCallback{
|
||||
.peripheral_discovered_cb =
|
||||
[&found_latch, &discovered_peripheral](
|
||||
BlePeripheral& peripheral, const std::string& service_id,
|
||||
<<<<<<< HEAD
|
||||
=======
|
||||
const ByteArray& advertisement_bytes,
|
||||
>>>>>>> release
|
||||
bool fast_advertisement) {
|
||||
NEARBY_LOG(
|
||||
INFO,
|
||||
|
||||
@@ -34,6 +34,12 @@ class Future final {
|
||||
void AddListener(Runnable runnable, api::Executor* executor) {
|
||||
impl_->AddListener(std::move(runnable), executor);
|
||||
}
|
||||
<<<<<<< HEAD
|
||||
=======
|
||||
bool IsSet() const {
|
||||
return impl_->IsSet();
|
||||
}
|
||||
>>>>>>> release
|
||||
|
||||
private:
|
||||
// Instance of future implementation is wrapped in shared_ptr<> to make
|
||||
|
||||
@@ -39,8 +39,14 @@ class SettableFuture : public api::SettableFuture<T> {
|
||||
exception_ = {Exception::kSuccess};
|
||||
completed_.Notify();
|
||||
InvokeAllLocked();
|
||||
<<<<<<< HEAD
|
||||
}
|
||||
return true;
|
||||
=======
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
>>>>>>> release
|
||||
}
|
||||
|
||||
void AddListener(Runnable runnable, api::Executor* executor) override {
|
||||
@@ -52,6 +58,14 @@ class SettableFuture : public api::SettableFuture<T> {
|
||||
}
|
||||
}
|
||||
|
||||
<<<<<<< HEAD
|
||||
=======
|
||||
bool IsSet() const {
|
||||
MutexLock lock(&mutex_);
|
||||
return done_;
|
||||
}
|
||||
|
||||
>>>>>>> release
|
||||
bool SetException(Exception exception) override {
|
||||
MutexLock lock(&mutex_);
|
||||
return SetExceptionLocked(exception);
|
||||
@@ -108,7 +122,11 @@ class SettableFuture : public api::SettableFuture<T> {
|
||||
listeners_.clear();
|
||||
}
|
||||
|
||||
<<<<<<< HEAD
|
||||
Mutex mutex_;
|
||||
=======
|
||||
mutable Mutex mutex_;
|
||||
>>>>>>> release
|
||||
ConditionVariable completed_{&mutex_};
|
||||
std::vector<std::pair<api::Executor*, std::function<void()>>> listeners_;
|
||||
bool done_{false};
|
||||
|
||||
Reference in New Issue
Block a user