mirror of
https://github.com/kidfromjupiter/nearby.git
synced 2026-09-14 22:56:12 -04:00
ClientProxy: Wire in DeviceProvider
PiperOrigin-RevId: 532259220
This commit is contained in:
committed by
Copybara-Service
parent
a925ed1072
commit
99e951dc53
@@ -140,6 +140,7 @@ cc_library(
|
||||
"//connections/implementation/mediums:utils",
|
||||
"//connections/implementation/mediums/webrtc",
|
||||
"//connections/implementation/proto:offline_wire_formats_cc_proto",
|
||||
"//connections/v3:v3_types",
|
||||
"//internal/analytics:event_logger",
|
||||
"//internal/flags:nearby_flags",
|
||||
"//internal/interop:device",
|
||||
@@ -247,6 +248,7 @@ cc_test(
|
||||
"//connections/implementation/flags:connections_flags",
|
||||
"//connections/implementation/mediums",
|
||||
"//connections/implementation/proto:offline_wire_formats_cc_proto",
|
||||
"//connections/v3:v3_types",
|
||||
"//internal/analytics:event_logger",
|
||||
"//internal/flags:nearby_flags",
|
||||
"//internal/platform:base",
|
||||
|
||||
@@ -27,6 +27,7 @@
|
||||
#include "absl/container/flat_hash_set.h"
|
||||
#include "absl/strings/escaping.h"
|
||||
#include "absl/strings/str_format.h"
|
||||
#include "connections/v3/connections_device_provider.h"
|
||||
#include "internal/analytics/event_logger.h"
|
||||
#include "internal/platform/error_code_recorder.h"
|
||||
#include "internal/platform/feature_flags.h"
|
||||
@@ -70,11 +71,13 @@ std::int64_t ClientProxy::GetClientId() const { return client_id_; }
|
||||
|
||||
std::string ClientProxy::GetLocalEndpointId() {
|
||||
MutexLock lock(&mutex_);
|
||||
if (local_endpoint_id_.empty()) {
|
||||
if (!local_endpoint_id_.empty()) {
|
||||
return local_endpoint_id_;
|
||||
}
|
||||
if (device_provider_ == nullptr) {
|
||||
local_endpoint_id_ = GenerateLocalEndpointId();
|
||||
NEARBY_LOGS(INFO) << "ClientProxy [Local Endpoint Generated]: client="
|
||||
<< GetClientId()
|
||||
<< "; endpoint_id=" << local_endpoint_id_;
|
||||
} else {
|
||||
local_endpoint_id_ = device_provider_->GetLocalDevice()->GetEndpointId();
|
||||
}
|
||||
return local_endpoint_id_;
|
||||
}
|
||||
|
||||
@@ -20,6 +20,7 @@
|
||||
#include <memory>
|
||||
#include <optional>
|
||||
#include <string>
|
||||
#include <utility>
|
||||
#include <vector>
|
||||
|
||||
#include "connections/advertising_options.h"
|
||||
@@ -31,6 +32,7 @@
|
||||
#include "connections/strategy.h"
|
||||
#include "internal/analytics/event_logger.h"
|
||||
#include "internal/interop/device.h"
|
||||
#include "internal/interop/device_provider.h"
|
||||
#include "internal/platform/byte_array.h"
|
||||
#include "internal/platform/cancelable_alarm.h"
|
||||
#include "internal/platform/cancellation_flag.h"
|
||||
@@ -206,6 +208,10 @@ class ClientProxy final {
|
||||
absl::string_view endpoint_id,
|
||||
const location::nearby::connections::OsInfo& remote_os_info);
|
||||
|
||||
void RegisterDeviceProvider(std::unique_ptr<NearbyDeviceProvider> provider) {
|
||||
device_provider_ = std::move(provider);
|
||||
}
|
||||
|
||||
private:
|
||||
struct Connection {
|
||||
// Status: may be either:
|
||||
@@ -282,7 +288,7 @@ class ClientProxy final {
|
||||
// Bluetooth Classic enabled. When high_visibility_mode_ is true, the endpoint
|
||||
// id is stable for 30s. When high_visibility_mode_ is false, the endpoint id
|
||||
// always rotates.
|
||||
bool high_vis_mode_{false};
|
||||
bool high_vis_mode_ = false;
|
||||
// Caches the endpoint id when it is in high visibility mode advertisement for
|
||||
// 30s. Currently, Nearby Connections keeps rotating endpoint id. The client
|
||||
// (Nearby Share) treats different endpoints as different receivers, duplicate
|
||||
@@ -339,6 +345,7 @@ class ClientProxy final {
|
||||
std::unique_ptr<ErrorCodeRecorder> error_code_recorder_;
|
||||
// Local device OS information.
|
||||
location::nearby::connections::OsInfo local_os_info_;
|
||||
std::unique_ptr<NearbyDeviceProvider> device_provider_;
|
||||
};
|
||||
|
||||
} // namespace connections
|
||||
|
||||
@@ -15,6 +15,7 @@
|
||||
#include "connections/implementation/client_proxy.h"
|
||||
|
||||
#include <cstdio>
|
||||
#include <memory>
|
||||
#include <optional>
|
||||
#include <string>
|
||||
|
||||
@@ -28,6 +29,7 @@
|
||||
#include "absl/types/span.h"
|
||||
#include "connections/listeners.h"
|
||||
#include "connections/strategy.h"
|
||||
#include "connections/v3/connections_device_provider.h"
|
||||
#include "internal/analytics/event_logger.h"
|
||||
#include "internal/platform/byte_array.h"
|
||||
#include "internal/platform/feature_flags.h"
|
||||
@@ -427,6 +429,16 @@ TEST_F(ClientProxyTest, GeneratedEndpointIdIsUnique) {
|
||||
EXPECT_NE(client1_.GetLocalEndpointId(), client2_.GetLocalEndpointId());
|
||||
}
|
||||
|
||||
TEST_F(ClientProxyTest, GeneratedEndpointIdIsUniqueWithDeviceProvider) {
|
||||
client1_.RegisterDeviceProvider(
|
||||
std::make_unique<v3::ConnectionsDeviceProvider>(
|
||||
v3::ConnectionsDeviceProvider("", {})));
|
||||
client2_.RegisterDeviceProvider(
|
||||
std::make_unique<v3::ConnectionsDeviceProvider>(
|
||||
v3::ConnectionsDeviceProvider("", {})));
|
||||
EXPECT_NE(client1_.GetLocalEndpointId(), client2_.GetLocalEndpointId());
|
||||
}
|
||||
|
||||
TEST_F(ClientProxyTest, ResetClearsState) {
|
||||
client1_.Reset();
|
||||
EXPECT_FALSE(client1_.IsAdvertising());
|
||||
|
||||
Reference in New Issue
Block a user