mirror of
https://github.com/kidfromjupiter/nearby.git
synced 2026-09-14 14:46:12 -04:00
Switch ConnectionOptions to use MacAddress class.
PiperOrigin-RevId: 802210252
This commit is contained in:
committed by
Copybara-Service
parent
c4d770bb27
commit
77ce859862
@@ -93,6 +93,7 @@ cc_library(
|
||||
"//connections/implementation/proto:offline_wire_formats_cc_proto",
|
||||
"//internal/interop:authentication_status",
|
||||
"//internal/platform:base",
|
||||
"//internal/platform:mac_address",
|
||||
"//internal/platform:types",
|
||||
"//internal/platform:util",
|
||||
"//proto:connections_enums_cc_proto",
|
||||
|
||||
+5
-16
@@ -45,7 +45,6 @@
|
||||
#include "internal/flags/flag.h"
|
||||
#include "internal/flags/flag_reader.h"
|
||||
#include "internal/flags/nearby_flags.h"
|
||||
#include "internal/platform/bluetooth_utils.h"
|
||||
#include "internal/platform/byte_array.h"
|
||||
#include "internal/platform/file.h"
|
||||
#include "internal/platform/logging.h"
|
||||
@@ -554,21 +553,11 @@ void NcRequestConnection(
|
||||
cpp_connection_options.low_power = connection_options->low_power;
|
||||
if (connection_options->remote_bluetooth_mac_address.size > 0) {
|
||||
nearby::MacAddress mac_address;
|
||||
if (!nearby::MacAddress::FromString(
|
||||
std::string(connection_options->remote_bluetooth_mac_address.data,
|
||||
connection_options->remote_bluetooth_mac_address.size),
|
||||
mac_address) ||
|
||||
!mac_address.IsSet()) {
|
||||
cpp_connection_options.remote_bluetooth_mac_address = nearby::ByteArray();
|
||||
} else {
|
||||
nearby::ByteArray address_bytes(
|
||||
nearby::BluetoothUtils::kBluetoothMacAddressLength);
|
||||
mac_address.ToBytes(
|
||||
absl::MakeSpan(reinterpret_cast<uint8_t*>(address_bytes.data()),
|
||||
address_bytes.size()));
|
||||
cpp_connection_options.remote_bluetooth_mac_address =
|
||||
std::move(address_bytes);
|
||||
}
|
||||
nearby::MacAddress::FromString(
|
||||
std::string(connection_options->remote_bluetooth_mac_address.data,
|
||||
connection_options->remote_bluetooth_mac_address.size),
|
||||
mac_address);
|
||||
cpp_connection_options.remote_bluetooth_mac_address = mac_address;
|
||||
}
|
||||
if (connection_options->common_options.strategy.type == NC_STRATEGY_TYPE_NONE)
|
||||
cpp_connection_options.strategy = ::nearby::connections::Strategy::kNone;
|
||||
|
||||
@@ -19,6 +19,7 @@
|
||||
#include "connections/implementation/proto/offline_wire_formats.pb.h"
|
||||
#include "connections/options_base.h"
|
||||
#include "internal/platform/byte_array.h"
|
||||
#include "internal/platform/mac_address.h"
|
||||
#include "proto/connections_enums.pb.h"
|
||||
|
||||
namespace nearby {
|
||||
@@ -49,7 +50,7 @@ struct ConnectionOptions : public OptionsBase {
|
||||
|
||||
// Whether this is intended to be used in conjunction with InjectEndpoint().
|
||||
bool is_out_of_band_connection = false;
|
||||
ByteArray remote_bluetooth_mac_address;
|
||||
MacAddress remote_bluetooth_mac_address;
|
||||
std::string fast_advertisement_service_uuid;
|
||||
int keep_alive_interval_millis = 0;
|
||||
int keep_alive_timeout_millis = 0;
|
||||
|
||||
@@ -859,19 +859,14 @@ Status BasePcpHandler::RequestConnection(
|
||||
return;
|
||||
}
|
||||
|
||||
MacAddress remote_bluetooth_mac_address;
|
||||
MacAddress::FromBytes(
|
||||
absl::MakeSpan(
|
||||
reinterpret_cast<const uint8_t*>(
|
||||
connection_options.remote_bluetooth_mac_address.data()),
|
||||
connection_options.remote_bluetooth_mac_address.size()),
|
||||
remote_bluetooth_mac_address);
|
||||
if (remote_bluetooth_mac_address.IsSet()) {
|
||||
if (connection_options.remote_bluetooth_mac_address.IsSet()) {
|
||||
if (AppendRemoteBluetoothMacAddressEndpoint(
|
||||
endpoint_id, remote_bluetooth_mac_address,
|
||||
endpoint_id, connection_options.remote_bluetooth_mac_address,
|
||||
client->GetDiscoveryOptions()))
|
||||
LOG(INFO) << "Appended remote Bluetooth MAC Address endpoint ["
|
||||
<< remote_bluetooth_mac_address.ToString() << "]";
|
||||
LOG(INFO)
|
||||
<< "Appended remote Bluetooth MAC Address endpoint ["
|
||||
<< connection_options.remote_bluetooth_mac_address.ToString()
|
||||
<< "]";
|
||||
}
|
||||
|
||||
if (AppendWebRTCEndpoint(endpoint_id, client->GetDiscoveryOptions()))
|
||||
@@ -1004,19 +999,14 @@ Status BasePcpHandler::RequestConnectionV3(
|
||||
return;
|
||||
}
|
||||
|
||||
MacAddress remote_bluetooth_mac_address;
|
||||
MacAddress::FromBytes(
|
||||
absl::MakeSpan(
|
||||
reinterpret_cast<const uint8_t*>(
|
||||
connection_options.remote_bluetooth_mac_address.data()),
|
||||
connection_options.remote_bluetooth_mac_address.size()),
|
||||
remote_bluetooth_mac_address);
|
||||
if (remote_bluetooth_mac_address.IsSet()) {
|
||||
if (connection_options.remote_bluetooth_mac_address.IsSet()) {
|
||||
if (AppendRemoteBluetoothMacAddressEndpoint(
|
||||
endpoint_id, remote_bluetooth_mac_address,
|
||||
endpoint_id, connection_options.remote_bluetooth_mac_address,
|
||||
client->GetDiscoveryOptions()))
|
||||
LOG(INFO) << "Appended remote Bluetooth MAC Address endpoint ["
|
||||
<< remote_bluetooth_mac_address.ToString() << "]";
|
||||
LOG(INFO)
|
||||
<< "Appended remote Bluetooth MAC Address endpoint ["
|
||||
<< connection_options.remote_bluetooth_mac_address.ToString()
|
||||
<< "]";
|
||||
}
|
||||
|
||||
if (AppendWebRTCEndpoint(endpoint_id, client->GetDiscoveryOptions()))
|
||||
|
||||
@@ -63,6 +63,7 @@
|
||||
#include "internal/platform/future.h"
|
||||
#include "internal/platform/input_stream.h"
|
||||
#include "internal/platform/logging.h"
|
||||
#include "internal/platform/mac_address.h"
|
||||
#include "internal/platform/medium_environment.h"
|
||||
#include "internal/platform/output_stream.h"
|
||||
#include "internal/platform/pipe.h"
|
||||
@@ -433,6 +434,7 @@ class BasePcpHandlerTest
|
||||
NearbyFlags::GetInstance().OverrideBoolFlagValue(
|
||||
config_package_nearby::nearby_connections_feature::kEnableInstantOnLost,
|
||||
false);
|
||||
MacAddress::FromString("12:34:56:78:9a:bc", remote_mac_address_);
|
||||
}
|
||||
|
||||
void StartAdvertising(ClientProxy* client, MockPcpHandler* pcp_handler,
|
||||
@@ -626,8 +628,7 @@ class BasePcpHandlerTest
|
||||
.listener = connection_listener_,
|
||||
};
|
||||
ConnectionOptions connection_options{
|
||||
.remote_bluetooth_mac_address =
|
||||
ByteArray{std::string("\x12\x34\x56\x78\x9a\xbc")},
|
||||
.remote_bluetooth_mac_address = remote_mac_address_,
|
||||
.keep_alive_interval_millis =
|
||||
FeatureFlags::GetInstance().GetFlags().keep_alive_interval_millis,
|
||||
.keep_alive_timeout_millis =
|
||||
@@ -700,7 +701,7 @@ class BasePcpHandlerTest
|
||||
.listener = connection_listener_,
|
||||
};
|
||||
ConnectionOptions connection_options{
|
||||
.remote_bluetooth_mac_address = ByteArray{"\x12\x34\x56\x78\x9a\xbc"},
|
||||
.remote_bluetooth_mac_address = remote_mac_address_,
|
||||
.keep_alive_interval_millis =
|
||||
FeatureFlags::GetInstance().GetFlags().keep_alive_interval_millis,
|
||||
.keep_alive_timeout_millis =
|
||||
@@ -775,8 +776,7 @@ class BasePcpHandlerTest
|
||||
.listener = connection_listener_,
|
||||
};
|
||||
ConnectionOptions connection_options{
|
||||
.remote_bluetooth_mac_address =
|
||||
ByteArray{std::string("\x12\x34\x56\x78\x9a\xbc")},
|
||||
.remote_bluetooth_mac_address = remote_mac_address_,
|
||||
.keep_alive_interval_millis =
|
||||
FeatureFlags::GetInstance().GetFlags().keep_alive_interval_millis,
|
||||
.keep_alive_timeout_millis =
|
||||
@@ -878,6 +878,7 @@ class BasePcpHandlerTest
|
||||
SetSafeToDisconnect set_safe_to_disconnect_{true};
|
||||
MediumEnvironment& env_ = MediumEnvironment::Instance();
|
||||
NiceMock<MockNearbyDevice> mock_device_;
|
||||
MacAddress remote_mac_address_;
|
||||
};
|
||||
|
||||
TEST_P(BasePcpHandlerTest, ConstructorDestructorWorks) {
|
||||
@@ -1323,7 +1324,7 @@ TEST_P(BasePcpHandlerTest, RequestConnectionV3_ConnectImplFailure) {
|
||||
.listener = connection_listener_,
|
||||
};
|
||||
ConnectionOptions connection_options{
|
||||
.remote_bluetooth_mac_address = ByteArray{"\x12\x34\x56\x78\x9a\xbc"},
|
||||
.remote_bluetooth_mac_address = remote_mac_address_,
|
||||
.keep_alive_interval_millis =
|
||||
FeatureFlags::GetInstance().GetFlags().keep_alive_interval_millis,
|
||||
.keep_alive_timeout_millis =
|
||||
@@ -1399,7 +1400,7 @@ TEST_P(BasePcpHandlerTest, RequestConnection_ConnectImplFailure) {
|
||||
.listener = connection_listener_,
|
||||
};
|
||||
ConnectionOptions connection_options{
|
||||
.remote_bluetooth_mac_address = ByteArray{"\x12\x34\x56\x78\x9a\xbc"},
|
||||
.remote_bluetooth_mac_address = remote_mac_address_,
|
||||
.keep_alive_interval_millis =
|
||||
FeatureFlags::GetInstance().GetFlags().keep_alive_interval_millis,
|
||||
.keep_alive_timeout_millis =
|
||||
|
||||
@@ -37,9 +37,11 @@ objc_library(
|
||||
"//connections/implementation/flags:connections_flags",
|
||||
"//internal/flags:nearby_flags",
|
||||
"//internal/platform:base",
|
||||
"//internal/platform:mac_address",
|
||||
"//internal/platform/implementation/apple", # buildcleaner: keep
|
||||
"//internal/platform/implementation/apple/Log:GNCLogger",
|
||||
"//third_party/apple_frameworks:Foundation",
|
||||
"@com_google_absl//absl/types:span",
|
||||
],
|
||||
)
|
||||
|
||||
|
||||
@@ -14,8 +14,9 @@
|
||||
|
||||
#import "connections/swift/NearbyCoreAdapter/Sources/GNCConnectionOptions+CppConversions.h"
|
||||
|
||||
#include "absl/types/span.h"
|
||||
#include "connections/connection_options.h"
|
||||
#include "internal/platform/byte_array.h"
|
||||
#include "internal/platform/mac_address.h"
|
||||
|
||||
#import "connections/swift/NearbyCoreAdapter/Sources/GNCSupportedMediums+CppConversions.h"
|
||||
#import "internal/platform/implementation/apple/Log/GNCLogger.h"
|
||||
@@ -40,8 +41,13 @@ using ::nearby::connections::ConnectionOptions;
|
||||
connection_options.keep_alive_interval_millis = self.keepAliveIntervalInSeconds * 1000;
|
||||
connection_options.keep_alive_timeout_millis = self.keepAliveTimeoutInSeconds * 1000;
|
||||
|
||||
connection_options.remote_bluetooth_mac_address = nearby::ByteArray(
|
||||
(char *)[self.remoteBluetoothMACAddress bytes], [self.remoteBluetoothMACAddress length]);
|
||||
nearby::MacAddress mac_address;
|
||||
nearby::MacAddress::FromBytes(
|
||||
absl::MakeConstSpan(
|
||||
(const uint8_t*)[self.remoteBluetoothMACAddress bytes],
|
||||
[self.remoteBluetoothMACAddress length]),
|
||||
mac_address);
|
||||
connection_options.remote_bluetooth_mac_address = mac_address;
|
||||
|
||||
return connection_options;
|
||||
}
|
||||
|
||||
@@ -325,6 +325,7 @@ cc_library(
|
||||
"//internal/flags:nearby_flags",
|
||||
"//internal/network:url",
|
||||
"//internal/platform:base",
|
||||
"//internal/platform:mac_address",
|
||||
"//internal/platform:types",
|
||||
"//internal/platform/implementation:account_manager",
|
||||
"//internal/platform/implementation:types",
|
||||
|
||||
@@ -32,6 +32,7 @@
|
||||
#include "connections/strategy.h"
|
||||
#include "internal/analytics/event_logger.h"
|
||||
#include "internal/platform/logging.h"
|
||||
#include "internal/platform/mac_address.h"
|
||||
#include "sharing/internal/public/connectivity_manager.h"
|
||||
#include "sharing/nearby_connections_service.h"
|
||||
#include "sharing/nearby_connections_types.h"
|
||||
@@ -214,9 +215,11 @@ void NearbyConnectionsServiceImpl::RequestConnection(
|
||||
*connection_options.keep_alive_timeout / absl::Milliseconds(1);
|
||||
}
|
||||
if (connection_options.remote_bluetooth_mac_address.has_value()) {
|
||||
auto mac_address = *connection_options.remote_bluetooth_mac_address;
|
||||
options.remote_bluetooth_mac_address =
|
||||
NcByteArray(std::string(mac_address.begin(), mac_address.end()));
|
||||
MacAddress mac_address;
|
||||
MacAddress::FromBytes(
|
||||
absl::MakeConstSpan(*connection_options.remote_bluetooth_mac_address),
|
||||
mac_address);
|
||||
options.remote_bluetooth_mac_address = mac_address;
|
||||
}
|
||||
options.non_disruptive_hotspot_mode =
|
||||
connection_options.non_disruptive_hotspot_mode;
|
||||
|
||||
Reference in New Issue
Block a user