PiperOrigin-RevId: 924405158
This commit is contained in:
Francis Tsui
2026-05-31 18:52:58 -07:00
committed by Copybara-Service
parent ab1183e2b4
commit 736cbb280e
23 changed files with 655 additions and 612 deletions
+1
View File
@@ -562,6 +562,7 @@ let package = Package(
.headerSearchPath("./"),
.headerSearchPath("compiled_proto/"),
.define("NO_WEBRTC"),
.define("NC_OSS_BUILD"),
]
),
.target(
+1 -1
View File
@@ -46,8 +46,8 @@ cc_library(
"//connections/implementation:client_proxy",
"//connections/implementation:internal",
"//connections/implementation:service_id_constants",
"//connections/implementation/analytics",
"//connections/v3:v3_types",
"//internal/analytics:event_logger",
"//internal/interop:device",
"//internal/platform:base",
"//internal/platform:logging",
+2
View File
@@ -51,6 +51,7 @@ cc_library(
":nc_types",
"//connections:core",
"//connections:core_types",
"//connections/implementation/analytics:analytics_recorder_impl",
"//connections/implementation/flags:connections_flags",
"//internal/analytics:event_logger",
"//internal/flags:flag_reader",
@@ -74,6 +75,7 @@ cc_library(
],
"//conditions:default": [],
}),
alwayslink = True,
)
# iOS only.
+19 -2
View File
@@ -20,6 +20,7 @@
#include <cstddef>
#include <cstdint>
#include <cstring>
#include <memory>
#include <string>
#include <utility>
#include <vector>
@@ -34,6 +35,9 @@
#include "connections/connection_options.h"
#include "connections/core.h"
#include "connections/discovery_options.h"
#if !defined(NC_OSS_BUILD)
#include "connections/implementation/analytics/analytics_recorder_impl.h"
#endif // !defined(NC_OSS_BUILD)
#include "connections/listeners.h"
#include "connections/medium_selector.h"
#include "connections/out_of_band_connection_metadata.h"
@@ -244,6 +248,7 @@ NcContext* GetContext(NC_INSTANCE instance) {
return cpp_connection_request_info;
}
#if !defined(NC_OSS_BUILD)
NC_INSTANCE NcCreateService() {
return NcCreateServiceWithEventLogger(nullptr);
}
@@ -259,12 +264,24 @@ NcCreateServiceWithEventLogger(const NC_EVENT_LOGGER* event_logger) {
nc_context.router = new ::nearby::connections::ServiceControllerRouter();
nc_context.event_logger =
event_logger == nullptr ? nullptr : new NcEventLogger(event_logger);
nc_context.core = new ::nearby::connections::Core(nc_context.event_logger,
nc_context.router);
nc_context.core = new ::nearby::connections::Core(
std::make_unique<::nearby::analytics::AnalyticsRecorderImpl>(
nc_context.event_logger),
nc_context.router);
kNcContextMap->insert({nc_context.core, nc_context});
return nc_context.core;
}
#else // !defined(NC_OSS_BUILD)
NC_INSTANCE NcCreateService() {
NcContext nc_context;
nc_context.router = new ::nearby::connections::ServiceControllerRouter();
nc_context.core = new ::nearby::connections::Core(nc_context.router);
kNcContextMap->insert({nc_context.core, nc_context});
return nc_context.core;
}
#endif // !defined(NC_OSS_BUILD)
void NcCloseService(NC_INSTANCE instance) {
NcContext* nc_context = GetContext(instance);
+2
View File
@@ -27,11 +27,13 @@ extern "C" {
// Creates a new Nearby Connections service.
NC_API NC_INSTANCE NcCreateService();
#if !defined(NC_OSS_BUILD)
// Creates a new Nearby Connections service with an event logger.
// The passed-in |event_logger| must remain valid until NcCloseService() is
// called.
NC_API NC_INSTANCE
NcCreateServiceWithEventLogger(const NC_EVENT_LOGGER* event_logger);
#endif // !defined(NC_OSS_BUILD)
// Closes a Nearby Connections service.
NC_API void NcCloseService(NC_INSTANCE instance);
+3 -3
View File
@@ -25,6 +25,7 @@
#include "connections/advertising_options.h"
#include "connections/connection_options.h"
#include "connections/discovery_options.h"
#include "connections/implementation/analytics/analytics_recorder.h"
#include "connections/implementation/client_proxy.h"
#include "connections/implementation/service_controller_router.h"
#include "connections/listeners.h"
@@ -37,7 +38,6 @@
#include "connections/v3/discovery_options.h"
#include "connections/v3/listeners.h"
#include "connections/v3/listening_result.h"
#include "internal/analytics/event_logger.h"
#include "internal/interop/device.h"
#include "internal/interop/device_provider.h"
@@ -49,9 +49,9 @@ class Core {
public:
explicit Core(ServiceControllerRouter* router);
// Client needs to call this constructor if analytics logger is needed.
Core(::nearby::analytics::EventLogger* event_logger,
Core(std::unique_ptr<analytics::AnalyticsRecorder> analytics_recorder,
ServiceControllerRouter* router)
: client_(event_logger), router_(router) {}
: client_(std::move(analytics_recorder)), router_(router) {}
~Core();
Core(Core&&);
Core& operator=(Core&&);
+3 -4
View File
@@ -112,12 +112,10 @@ cc_library(
deps = [
"//connections:core_types",
"//connections/implementation/analytics",
"//connections/implementation/analytics:analytics_recorder_impl",
"//connections/implementation/flags:connections_flags",
"//connections/implementation/mediums/advertisements:dct_advertisement",
"//connections/implementation/proto:offline_wire_formats_cc_proto",
"//connections/v3:v3_types",
"//internal/analytics:event_logger",
"//internal/base:file_path",
"//internal/base:files",
"//internal/flags:nearby_flags",
@@ -392,12 +390,13 @@ cc_test(
":offline_frames",
":types",
"//connections:core_types",
"//connections/implementation/analytics",
"//connections/implementation/analytics:mock_analytics_recorder",
"//connections/implementation/flags:connections_flags",
"//connections/implementation/mediums",
"//connections/implementation/mediums:webrtc_peer_id",
"//connections/implementation/proto:offline_wire_formats_cc_proto",
"//connections/v3:v3_types",
"//internal/analytics:mock_event_logger",
"//internal/flags:nearby_flags",
"//internal/interop:authentication_status",
"//internal/interop:authentication_transport_interface",
@@ -408,7 +407,6 @@ cc_test(
"//internal/platform:test_util",
"//internal/platform:types",
"//internal/platform/implementation/g3", # build_cleaner: keep
"//internal/proto/analytics:connections_log_cc_proto",
"//proto:connections_enums_cc_proto",
"@com_github_protobuf_matchers//protobuf-matchers",
"@com_google_absl//absl/base:core_headers",
@@ -467,6 +465,7 @@ cc_test(
deps = [
":client_proxy",
"//connections:core_types",
"//connections/implementation/analytics:mock_analytics_recorder",
"//connections/implementation/flags:connections_flags",
"//connections/v3:v3_types",
"//internal/analytics:mock_event_logger",
+22 -1
View File
@@ -47,7 +47,10 @@ cc_library(
"analytics_recorder_impl.h",
],
copts = ["-DCORE_ADAPTER_DLL"],
visibility = ["//connections/implementation:__pkg__"],
visibility = [
"//connections/c:__pkg__",
"//sharing:__pkg__",
],
deps = [
":analytics",
"//connections:core_types",
@@ -67,6 +70,24 @@ cc_library(
],
)
cc_library(
name = "mock_analytics_recorder",
testonly = True,
hdrs = [
"mock_analytics_recorder.h",
],
compatible_with = ["//buildenv/target:non_prod"],
visibility = ["//connections:__subpackages__"],
deps = [
":analytics",
"//connections:core_types",
"//internal/platform:error_code_recorder",
"//proto:connections_enums_cc_proto",
"@com_google_absl//absl/time",
"@com_google_googletest//:gtest_for_library_testonly",
],
)
cc_test(
name = "analytics_test",
size = "small",
@@ -0,0 +1,196 @@
// Copyright 2026 Google LLC
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// https://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
#ifndef ANALYTICS_MOCK_ANALYTICS_RECORDER_H_
#define ANALYTICS_MOCK_ANALYTICS_RECORDER_H_
#include <cstdint>
#include <string>
#include <vector>
#include "gmock/gmock.h"
#include "absl/time/time.h"
#include "connections/implementation/analytics/advertising_metadata_params.h"
#include "connections/implementation/analytics/analytics_recorder.h"
#include "connections/implementation/analytics/connection_attempt_metadata_params.h"
#include "connections/implementation/analytics/discovery_metadata_params.h"
#include "connections/payload_type.h"
#include "connections/strategy.h"
#include "internal/platform/error_code_params.h"
#include "proto/connections_enums.pb.h"
namespace nearby::analytics {
class MockAnalyticsRecorder : public AnalyticsRecorder {
public:
MockAnalyticsRecorder() = default;
~MockAnalyticsRecorder() override = default;
// Advertising phase
MOCK_METHOD(void, OnStartAdvertising,
(connections::Strategy strategy,
const std::vector<location::nearby::proto::connections::Medium>&
mediums,
AdvertisingMetadataParams* advertising_metadata_params),
(override));
MOCK_METHOD(void, OnStopAdvertising, (), (override));
MOCK_METHOD(int, GetNextAdvertisingUpdateIndex, (), (override));
// Connection listening
MOCK_METHOD(void, OnStartedIncomingConnectionListening,
(connections::Strategy strategy), (override));
MOCK_METHOD(void, OnStoppedIncomingConnectionListening, (), (override));
// Discovery phase
MOCK_METHOD(void, OnStartDiscovery,
(connections::Strategy strategy,
const std::vector<location::nearby::proto::connections::Medium>&
mediums,
DiscoveryMetadataParams* discovery_metadata_params),
(override));
MOCK_METHOD(void, OnStopDiscovery, (), (override));
MOCK_METHOD(int, GetNextDiscoveryUpdateIndex, (), (override));
MOCK_METHOD(void, OnEndpointFound,
(location::nearby::proto::connections::Medium medium),
(override));
// Connection request
MOCK_METHOD(void, OnRequestConnection,
(const connections::Strategy& strategy,
const std::string& endpoint_id),
(override));
MOCK_METHOD(void, OnConnectionRequestReceived,
(const std::string& remote_endpoint_id), (override));
MOCK_METHOD(void, OnConnectionRequestSent,
(const std::string& remote_endpoint_id), (override));
MOCK_METHOD(void, OnRemoteEndpointAccepted,
(const std::string& remote_endpoint_id), (override));
MOCK_METHOD(void, OnLocalEndpointAccepted,
(const std::string& remote_endpoint_id), (override));
MOCK_METHOD(void, OnRemoteEndpointRejected,
(const std::string& remote_endpoint_id), (override));
MOCK_METHOD(void, OnLocalEndpointRejected,
(const std::string& remote_endpoint_id), (override));
// Connection attempt
MOCK_METHOD(
void, OnIncomingConnectionAttempt,
(location::nearby::proto::connections::ConnectionAttemptType type,
location::nearby::proto::connections::Medium medium,
location::nearby::proto::connections::ConnectionAttemptResult result,
absl::Duration duration, const std::string& connection_token,
ConnectionAttemptMetadataParams* connection_attempt_metadata_params),
(override));
MOCK_METHOD(
void, OnOutgoingConnectionAttempt,
(const std::string& remote_endpoint_id,
location::nearby::proto::connections::ConnectionAttemptType type,
location::nearby::proto::connections::Medium medium,
location::nearby::proto::connections::ConnectionAttemptResult result,
absl::Duration duration, const std::string& connection_token,
ConnectionAttemptMetadataParams* connection_attempt_metadata_params),
(override));
// Connection established
MOCK_METHOD(void, OnConnectionEstablished,
(const std::string& endpoint_id,
location::nearby::proto::connections::Medium medium,
const std::string& connection_token),
(override));
MOCK_METHOD(void, OnConnectionClosed,
(const std::string& endpoint_id,
location::nearby::proto::connections::Medium medium,
location::nearby::proto::connections::DisconnectionReason reason,
SafeDisconnectionResult result),
(override));
// Payload
MOCK_METHOD(void, OnIncomingPayloadStarted,
(const std::string& endpoint_id, std::int64_t payload_id,
connections::PayloadType type, std::int64_t total_size_bytes),
(override));
MOCK_METHOD(void, OnPayloadChunkReceived,
(const std::string& endpoint_id, std::int64_t payload_id,
std::int64_t chunk_size_bytes),
(override));
MOCK_METHOD(void, OnIncomingPayloadDone,
(const std::string& endpoint_id, std::int64_t payload_id,
location::nearby::proto::connections::PayloadStatus status,
location::nearby::proto::connections::OperationResultCode
operation_result_code),
(override));
MOCK_METHOD(void, OnOutgoingPayloadStarted,
(const std::vector<std::string>& endpoint_ids,
std::int64_t payload_id, connections::PayloadType type,
std::int64_t total_size_bytes),
(override));
MOCK_METHOD(void, OnPayloadChunkSent,
(const std::string& endpoint_id, std::int64_t payload_id,
std::int64_t chunk_size_bytes),
(override));
MOCK_METHOD(void, OnOutgoingPayloadDone,
(const std::string& endpoint_id, std::int64_t payload_id,
location::nearby::proto::connections::PayloadStatus status,
location::nearby::proto::connections::OperationResultCode
operation_result_code),
(override));
// BandwidthUpgrade
MOCK_METHOD(void, OnBandwidthUpgradeStarted,
(const std::string& endpoint_id,
location::nearby::proto::connections::Medium from_medium,
location::nearby::proto::connections::Medium to_medium,
location::nearby::proto::connections::ConnectionAttemptDirection
direction,
const std::string& connection_token),
(override));
MOCK_METHOD(void, UpdateBwUpgradeNetworkInfo,
(const std::string& endpoint_id, int num_interfaces,
int num_ipv6_only_interfaces),
(override));
MOCK_METHOD(void, OnBandwidthUpgradeError,
(const std::string& endpoint_id,
location::nearby::proto::connections::BandwidthUpgradeResult
result,
location::nearby::proto::connections::BandwidthUpgradeErrorStage
error_stage,
location::nearby::proto::connections::OperationResultCode
operation_result_code),
(override));
MOCK_METHOD(void, OnBandwidthUpgradeSuccess, (const std::string& endpoint_id),
(override));
// Error Code
MOCK_METHOD(void, OnErrorCode, (const ErrorCodeParams& params), (override));
MOCK_METHOD(void, LogStartSession, (), (override));
MOCK_METHOD(void, LogSession, (), (override));
MOCK_METHOD(bool, IsSessionLogged, (), (override));
MOCK_METHOD(
location::nearby::proto::connections::OperationResultCategory,
GetOperationResultCategory,
(location::nearby::proto::connections::OperationResultCode result_code),
(override));
MOCK_METHOD(void, Sync, (), (override));
};
} // namespace nearby::analytics
#endif // ANALYTICS_MOCK_ANALYTICS_RECORDER_H_
+10 -37
View File
@@ -53,7 +53,6 @@
#include "connections/implementation/mediums/webrtc_peer_id.h"
#include "connections/implementation/offline_frames.h"
#include "connections/implementation/pcp.h"
#include "connections/implementation/proto/offline_wire_formats.pb.h"
#include "connections/implementation/webrtc_state.h"
#include "connections/listeners.h"
#include "connections/medium_selector.h"
@@ -86,12 +85,10 @@
#include "internal/platform/runnable.h"
#include "internal/platform/wifi.h"
#include "internal/platform/wifi_lan_connection_info.h"
#include "proto/connections_enums.pb.h"
namespace nearby::connections {
namespace {
using ::location::nearby::analytics::proto::ConnectionsLog;
using ::location::nearby::connections::ConnectionRequestFrame;
using ::location::nearby::connections::ConnectionResponseFrame;
using ::location::nearby::connections::ConnectionsDevice;
@@ -103,6 +100,7 @@ using ::location::nearby::connections::V1Frame;
using ::location::nearby::proto::connections::OperationResultCode;
using ::location::nearby::proto::connections::WifiDirectAuthType;
using ::nearby::analytics::AnalyticsRecorder;
using ::nearby::analytics::OperationResultWithMedium;
using ::securegcm::UKey2Handshake;
constexpr int kEndpointCancelAlarmTimeout = 10;
@@ -118,28 +116,6 @@ std::string AuthenticationStatusToString(nearby::AuthenticationStatus status) {
}
}
std::vector<analytics::OperationResultWithMedium>
ConvertToCppOperationResultWithMediums(
const std::vector<ConnectionsLog::OperationResultWithMedium>&
proto_results) {
std::vector<analytics::OperationResultWithMedium> cpp_results;
cpp_results.reserve(proto_results.size());
for (const auto& proto_result : proto_results) {
analytics::OperationResultWithMedium cpp_result;
cpp_result.medium = proto_result.medium();
if (proto_result.has_update_index()) {
cpp_result.update_index = proto_result.update_index();
}
cpp_result.result_category = proto_result.result_category();
cpp_result.result_code = proto_result.result_code();
if (proto_result.has_connection_mode()) {
cpp_result.connection_mode = proto_result.connection_mode();
}
cpp_results.push_back(cpp_result);
}
return cpp_results;
}
} // namespace
BasePcpHandler::BasePcpHandler(Mediums* mediums,
@@ -306,8 +282,7 @@ Status BasePcpHandler::StartAdvertising(
advertising_listener_ = info.listener;
client->StartedAdvertising(service_id, GetStrategy(), info.listener,
absl::MakeSpan(result.mediums),
ConvertToCppOperationResultWithMediums(
result.operation_result_with_mediums),
result.operation_result_with_mediums,
compatible_advertising_options);
client->UpdateLocalEndpointInfo(info.endpoint_info.string_data());
response.Set({Status::kSuccess});
@@ -538,8 +513,7 @@ Status BasePcpHandler::StartDiscovery(ClientProxy* client,
client->StartedDiscovery(service_id, GetStrategy(),
std::move(listener),
absl::MakeSpan(result.mediums),
ConvertToCppOperationResultWithMediums(
result.operation_result_with_mediums),
result.operation_result_with_mediums,
stripped_discovery_options);
response.Set({Status::kSuccess});
});
@@ -1324,22 +1298,21 @@ void BasePcpHandler::StripOutUnavailableMediums(
}
}
std::unique_ptr<ConnectionsLog::OperationResultWithMedium>
OperationResultWithMedium
BasePcpHandler::GetOperationResultWithMediumByResultCode(
ClientProxy* client, location::nearby::proto::connections::Medium medium,
int update_index,
location::nearby::proto::connections::OperationResultCode
operation_result_code,
location::nearby::proto::connections::ConnectionMode connection_mode) {
auto operation_result_with_medium =
std::make_unique<ConnectionsLog::OperationResultWithMedium>();
operation_result_with_medium->set_medium(medium);
operation_result_with_medium->set_result_code(operation_result_code);
operation_result_with_medium->set_result_category(
OperationResultWithMedium operation_result_with_medium;
operation_result_with_medium.set_medium(medium);
operation_result_with_medium.set_result_code(operation_result_code);
operation_result_with_medium.set_result_category(
client->GetAnalyticsRecorder().GetOperationResultCategory(
operation_result_code));
operation_result_with_medium->set_connection_mode(connection_mode);
operation_result_with_medium->set_update_index(update_index);
operation_result_with_medium.set_connection_mode(connection_mode);
operation_result_with_medium.set_update_index(update_index);
return operation_result_with_medium;
}
@@ -31,6 +31,7 @@
#include "connections/advertising_options.h"
#include "connections/connection_options.h"
#include "connections/discovery_options.h"
#include "connections/implementation/analytics/operation_result_with_medium.h"
#include "connections/implementation/bwu_manager.h"
#include "connections/implementation/client_proxy.h"
#include "connections/implementation/encryption_runner.h"
@@ -189,8 +190,7 @@ class BasePcpHandler : public PcpHandler,
// If success, the mediums on which we are now advertising/discovering, for
// analytics.
std::vector<location::nearby::proto::connections::Medium> mediums;
std::vector<location::nearby::analytics::proto::ConnectionsLog::
OperationResultWithMedium>
std::vector<nearby::analytics::OperationResultWithMedium>
operation_result_with_mediums;
};
@@ -412,8 +412,7 @@ class BasePcpHandler : public PcpHandler,
void StripOutWifiHotspotMedium(ConnectionInfo& connection_info);
std::unique_ptr<location::nearby::analytics::proto::ConnectionsLog::
OperationResultWithMedium>
nearby::analytics::OperationResultWithMedium
GetOperationResultWithMediumByResultCode(
ClientProxy* client, location::nearby::proto::connections::Medium medium,
int update_index,
@@ -32,6 +32,8 @@
#include "connections/advertising_options.h"
#include "connections/connection_options.h"
#include "connections/discovery_options.h"
#include "connections/implementation/analytics/analytics_recorder.h"
#include "connections/implementation/analytics/mock_analytics_recorder.h"
#include "connections/implementation/base_endpoint_channel.h"
#include "connections/implementation/bwu_manager.h"
#include "connections/implementation/client_proxy.h"
@@ -54,8 +56,6 @@
#include "connections/status.h"
#include "connections/strategy.h"
#include "connections/v3/connection_listening_options.h"
#include "internal/analytics/mock_event_logger.h"
#include "internal/analytics/sharing_log_matchers.h"
#include "internal/flags/nearby_flags.h"
#include "internal/interop/authentication_status.h"
#include "internal/interop/authentication_transport.h"
@@ -71,28 +71,21 @@
#include "internal/platform/medium_environment.h"
#include "internal/platform/output_stream.h"
#include "internal/platform/pipe.h"
#include "internal/proto/analytics/connections_log.pb.h"
#include "proto/connections_enums.pb.h"
#include "proto/connections_enums.proto.h"
namespace nearby {
namespace connections {
namespace nearby::connections {
namespace {
using ::location::nearby::analytics::proto::ConnectionsLog;
using ::location::nearby::connections::OsInfo;
using ::location::nearby::proto::connections::EventType;
using ::location::nearby::proto::connections::Medium;
using ::nearby::analytics::HasEventType;
using ::testing::_;
using ::testing::AtLeast;
using ::protobuf_matchers::EqualsProto;
using ::testing::Matcher;
using ::testing::MockFunction;
using ::testing::NiceMock;
using ::testing::Return;
using ::testing::StrictMock;
using ::testing::proto::Partially;
constexpr absl::string_view kTestEndpointId = "REMOTETEST";
@@ -452,7 +445,7 @@ class BasePcpHandlerTest
};
BasePcpHandlerTest() {
client_ = std::make_unique<ClientProxy>(&mock_event_logger_);
client_ = std::make_unique<ClientProxy>(CreateAnalyticsRecorder());
}
void SetUp() override {
@@ -461,6 +454,13 @@ class BasePcpHandlerTest
void TearDown() override { env_.Stop(); }
std::unique_ptr<analytics::AnalyticsRecorder> CreateAnalyticsRecorder() {
auto recorder =
std::make_unique<analytics::MockAnalyticsRecorder>();
mock_analytics_recorder_ptr_ = recorder.get();
return recorder;
}
void StartAdvertising(ClientProxy* client, MockPcpHandler* pcp_handler,
BooleanMediumSelector allowed = GetParam()) {
AdvertisingOptions advertising_options{
@@ -896,7 +896,7 @@ class BasePcpHandlerTest
MediumEnvironment& env_ = MediumEnvironment::Instance();
NiceMock<MockNearbyDevice> mock_device_;
MacAddress remote_mac_address_;
nearby::analytics::MockEventLogger mock_event_logger_;
nearby::analytics::MockAnalyticsRecorder* mock_analytics_recorder_ptr_;
std::unique_ptr<ClientProxy> client_;
};
@@ -2555,7 +2555,7 @@ TEST_F(BasePcpHandlerTest, TestDeviceFilterForConnectionsWithPresence) {
TEST_F(BasePcpHandlerTest, IncomingConnectionFailsWithEmptyEndpointId) {
env_.Start({.use_simulated_clock = true});
client_ = std::make_unique<ClientProxy>(&mock_event_logger_);
client_ = std::make_unique<ClientProxy>(CreateAnalyticsRecorder());
Mediums m;
EndpointChannelManager ecm;
EndpointManager em(&ecm);
@@ -2572,6 +2572,8 @@ TEST_F(BasePcpHandlerTest, IncomingConnectionFailsWithEmptyEndpointId) {
MockPcpHandler::StartOperationResult{.status = {Status::kSuccess}}));
EXPECT_CALL(pcp_handler, CanReceiveIncomingConnection)
.WillRepeatedly(Return(true));
EXPECT_CALL(*mock_analytics_recorder_ptr_,
OnStartedIncomingConnectionListening(_));
EXPECT_TRUE(pcp_handler
.StartListeningForIncomingConnections(client_.get(),
"service", options, {})
@@ -2593,45 +2595,13 @@ TEST_F(BasePcpHandlerTest, IncomingConnectionFailsWithEmptyEndpointId) {
// do a dummy write to get to the actual write.
channel_pair.first->Write("");
channel_pair.first->Write(frame.SerializeAsString());
absl::string_view expected_log = R"pb(
event_type: CLIENT_SESSION
client_session {
strategy_session {
connection_attempt {
type: INITIAL
direction: INCOMING
medium: BLUETOOTH
attempt_result: RESULT_ERROR
operation_result {
result_category: CATEGORY_CONNECTIVITY_ERROR
result_code: CONNECTIVITY_CHANNEL_IO_ERROR_ON_BT
}
}
}
}
)pb";
absl::string_view client_session_log = R"pb(
event_type: CLIENT_SESSION
version: "v1.5.0"
)pb";
EXPECT_CALL(mock_event_logger_,
Log(Matcher<const ConnectionsLog&>(
HasEventType(EventType::STOP_STRATEGY_SESSION))))
.Times(1);
EXPECT_CALL(mock_event_logger_,
Log(Matcher<const ConnectionsLog&>(
HasEventType(EventType::STOP_CLIENT_SESSION))))
.Times(3);
EXPECT_CALL(mock_event_logger_,
Log(Matcher<const ConnectionsLog&>(
HasEventType(EventType::START_CLIENT_SESSION))))
.Times(3);
EXPECT_CALL(mock_event_logger_, Log(Matcher<const ConnectionsLog&>(Partially(
EqualsProto(client_session_log)))))
.Times(2);
EXPECT_CALL(mock_event_logger_, Log(Matcher<const ConnectionsLog&>(
Partially(EqualsProto(expected_log)))));
EXPECT_CALL(*mock_analytics_recorder_ptr_, LogSession()).Times(3);
EXPECT_CALL(*mock_analytics_recorder_ptr_, LogStartSession()).Times(3);
EXPECT_CALL(
*mock_analytics_recorder_ptr_,
OnIncomingConnectionAttempt(
location::nearby::proto::connections::INITIAL, Medium::BLUETOOTH,
location::nearby::proto::connections::RESULT_ERROR, _, _, _));
EXPECT_EQ(pcp_handler
.OnIncomingConnection(
client_.get(), ByteArray("remote endpoint"),
@@ -2645,7 +2615,7 @@ TEST_F(BasePcpHandlerTest, IncomingConnectionFailsWithEmptyEndpointId) {
TEST_F(BasePcpHandlerTest, IncomingConnectionWithNoDataFailsWithoutLogging) {
env_.Start({.use_simulated_clock = true});
// Recreate ClientProxy so that AnalyticRecorder uses simulated clock.
client_ = std::make_unique<ClientProxy>(&mock_event_logger_);
client_ = std::make_unique<ClientProxy>(CreateAnalyticsRecorder());
Mediums m;
EndpointChannelManager ecm;
EndpointManager em(&ecm);
@@ -2662,6 +2632,8 @@ TEST_F(BasePcpHandlerTest, IncomingConnectionWithNoDataFailsWithoutLogging) {
MockPcpHandler::StartOperationResult{.status = {Status::kSuccess}}));
EXPECT_CALL(pcp_handler, CanReceiveIncomingConnection)
.WillRepeatedly(Return(true));
EXPECT_CALL(*mock_analytics_recorder_ptr_,
OnStartedIncomingConnectionListening(_));
EXPECT_TRUE(pcp_handler
.StartListeningForIncomingConnections(client_.get(),
"service", options, {})
@@ -2673,59 +2645,8 @@ TEST_F(BasePcpHandlerTest, IncomingConnectionWithNoDataFailsWithoutLogging) {
std::move(input_a), std::move(output_a));
EXPECT_CALL(*input_channel, Read())
.WillRepeatedly(Return(ExceptionOr<ByteArray>(Exception::kNoData)));
absl::string_view expected_log = R"pb(
event_type: CLIENT_SESSION
client_session {
strategy_session {
connection_attempt {
type: INITIAL
direction: INCOMING
attempt_result: RESULT_ERROR
}
}
}
)pb";
absl::string_view client_session_log = R"pb(
event_type: CLIENT_SESSION
client_session { duration_millis: 0 }
version: "v1.5.0"
)pb";
absl::string_view client_session_log2 = R"pb(
event_type: CLIENT_SESSION
client_session {
duration_millis: 0
strategy_session {
duration_millis: 0
strategy: UNKNOWN_STRATEGY
role: ADVERTISER
}
}
version: "v1.5.0"
)pb";
EXPECT_CALL(mock_event_logger_,
Log(Matcher<const ConnectionsLog&>(
HasEventType(EventType::STOP_STRATEGY_SESSION))))
.Times(1);
EXPECT_CALL(mock_event_logger_,
Log(Matcher<const ConnectionsLog&>(
HasEventType(EventType::STOP_CLIENT_SESSION))))
.Times(3);
EXPECT_CALL(mock_event_logger_,
Log(Matcher<const ConnectionsLog&>(
HasEventType(EventType::START_CLIENT_SESSION))))
.Times(3);
EXPECT_CALL(
mock_event_logger_,
Log(Matcher<const ConnectionsLog&>(EqualsProto(client_session_log))))
.Times(2);
EXPECT_CALL(
mock_event_logger_,
Log(Matcher<const ConnectionsLog&>(EqualsProto(client_session_log2))));
EXPECT_CALL(
mock_event_logger_,
Log(Matcher<const ConnectionsLog&>(Partially(EqualsProto(expected_log)))))
.Times(0);
EXPECT_CALL(*mock_analytics_recorder_ptr_, LogSession()).Times(3);
EXPECT_CALL(*mock_analytics_recorder_ptr_, LogStartSession()).Times(3);
EXPECT_EQ(
pcp_handler
.OnIncomingConnection(client_.get(), ByteArray("remote endpoint"),
@@ -3029,5 +2950,4 @@ TEST_F(BasePcpHandlerTest, TestForceUpdateEndpointIdAdvertisingOption) {
}
} // namespace
} // namespace connections
} // namespace nearby
} // namespace nearby::connections
+148 -7
View File
@@ -38,7 +38,7 @@
#include "connections/discovery_options.h"
#include "connections/implementation/analytics/advertising_metadata_params.h"
#include "connections/implementation/analytics/analytics_recorder.h"
#include "connections/implementation/analytics/analytics_recorder_impl.h"
#include "connections/implementation/analytics/connection_attempt_metadata_params.h"
#include "connections/implementation/analytics/discovery_metadata_params.h"
#include "connections/implementation/analytics/operation_result_with_medium.h"
#include "connections/implementation/flags/nearby_connections_feature_flags.h"
@@ -46,6 +46,7 @@
#include "connections/listeners.h"
#include "connections/medium_selector.h"
#include "connections/payload.h"
#include "connections/payload_type.h"
#include "connections/status.h"
#include "connections/strategy.h"
#include "connections/v3/bandwidth_info.h"
@@ -54,7 +55,6 @@
#include "connections/v3/connections_device.h"
#include "connections/v3/connections_device_provider.h"
#include "connections/v3/listeners.h"
#include "internal/analytics/event_logger.h"
#include "internal/base/file_path.h"
#include "internal/base/files.h"
#include "internal/flags/nearby_flags.h"
@@ -99,11 +99,154 @@ constexpr absl::string_view kAdvertisingTimestamp = "nc.advertising.timestamp";
constexpr absl::Duration kAdvertisingKeepAliveDuration = absl::Seconds(30);
class NoOpAnalyticsRecorder : public AnalyticsRecorder {
public:
NoOpAnalyticsRecorder() = default;
~NoOpAnalyticsRecorder() override = default;
// Advertising phase
void OnStartAdvertising(
connections::Strategy strategy,
const std::vector<location::nearby::proto::connections::Medium>& mediums,
AdvertisingMetadataParams* advertising_metadata_params) override {}
void OnStopAdvertising() override {}
int GetNextAdvertisingUpdateIndex() override { return 0; }
// Connection listening
void OnStartedIncomingConnectionListening(
connections::Strategy strategy) override {}
void OnStoppedIncomingConnectionListening() override {}
// Discovery phase
void OnStartDiscovery(
connections::Strategy strategy,
const std::vector<location::nearby::proto::connections::Medium>& mediums,
DiscoveryMetadataParams* discovery_metadata_params) override {}
void OnStopDiscovery() override {}
int GetNextDiscoveryUpdateIndex() override { return 0; }
void OnEndpointFound(
location::nearby::proto::connections::Medium medium) override {}
// Connection request
void OnRequestConnection(const connections::Strategy& strategy,
const std::string& endpoint_id) override {}
void OnConnectionRequestReceived(
const std::string& remote_endpoint_id) override {}
void OnConnectionRequestSent(
const std::string& remote_endpoint_id) override {}
void OnRemoteEndpointAccepted(
const std::string& remote_endpoint_id) override {}
void OnLocalEndpointAccepted(
const std::string& remote_endpoint_id) override {}
void OnRemoteEndpointRejected(
const std::string& remote_endpoint_id) override {}
void OnLocalEndpointRejected(
const std::string& remote_endpoint_id) override {}
// Connection attempt
void OnIncomingConnectionAttempt(
location::nearby::proto::connections::ConnectionAttemptType type,
location::nearby::proto::connections::Medium medium,
location::nearby::proto::connections::ConnectionAttemptResult result,
absl::Duration duration, const std::string& connection_token,
ConnectionAttemptMetadataParams* connection_attempt_metadata_params)
override {}
void OnOutgoingConnectionAttempt(
const std::string& remote_endpoint_id,
location::nearby::proto::connections::ConnectionAttemptType type,
location::nearby::proto::connections::Medium medium,
location::nearby::proto::connections::ConnectionAttemptResult result,
absl::Duration duration, const std::string& connection_token,
ConnectionAttemptMetadataParams* connection_attempt_metadata_params)
override {}
// Connection established
void OnConnectionEstablished(
const std::string& endpoint_id,
location::nearby::proto::connections::Medium medium,
const std::string& connection_token) override {}
void OnConnectionClosed(
const std::string& endpoint_id,
location::nearby::proto::connections::Medium medium,
location::nearby::proto::connections::DisconnectionReason reason,
nearby::analytics::SafeDisconnectionResult result) override {}
// Payload
void OnIncomingPayloadStarted(const std::string& endpoint_id,
std::int64_t payload_id,
connections::PayloadType type,
std::int64_t total_size_bytes) override {}
void OnPayloadChunkReceived(const std::string& endpoint_id,
std::int64_t payload_id,
std::int64_t chunk_size_bytes) override {}
void OnIncomingPayloadDone(
const std::string& endpoint_id, std::int64_t payload_id,
location::nearby::proto::connections::PayloadStatus status,
location::nearby::proto::connections::OperationResultCode
operation_result_code) override {}
void OnOutgoingPayloadStarted(
const std::vector<std::string>& endpoint_ids, std::int64_t payload_id,
connections::PayloadType type, std::int64_t total_size_bytes) override {}
void OnPayloadChunkSent(const std::string& endpoint_id,
std::int64_t payload_id,
std::int64_t chunk_size_bytes) override {}
void OnOutgoingPayloadDone(
const std::string& endpoint_id, std::int64_t payload_id,
location::nearby::proto::connections::PayloadStatus status,
location::nearby::proto::connections::OperationResultCode
operation_result_code) override {}
// BandwidthUpgrade
void OnBandwidthUpgradeStarted(
const std::string& endpoint_id,
location::nearby::proto::connections::Medium from_medium,
location::nearby::proto::connections::Medium to_medium,
location::nearby::proto::connections::ConnectionAttemptDirection
direction,
const std::string& connection_token) override {}
void UpdateBwUpgradeNetworkInfo(const std::string& endpoint_id,
int num_interfaces,
int num_ipv6_only_interfaces) override {}
void OnBandwidthUpgradeError(
const std::string& endpoint_id,
location::nearby::proto::connections::BandwidthUpgradeResult result,
location::nearby::proto::connections::BandwidthUpgradeErrorStage
error_stage,
location::nearby::proto::connections::OperationResultCode
operation_result_code) override {}
void OnBandwidthUpgradeSuccess(const std::string& endpoint_id) override {}
// Error Code
void OnErrorCode(const ErrorCodeParams& params) override {}
void LogStartSession() override {}
void LogSession() override {}
bool IsSessionLogged() override { return false; }
location::nearby::proto::connections::OperationResultCategory
GetOperationResultCategory(
location::nearby::proto::connections::OperationResultCode result_code)
override {
return location::nearby::proto::connections::OperationResultCategory::
CATEGORY_UNKNOWN;
}
void Sync() override {}
};
} // namespace
ClientProxy::ClientProxy(::nearby::analytics::EventLogger* event_logger)
: client_id_(Prng().NextInt64()) {
VLOG(1) << "ClientProxy ctor event_logger=" << event_logger;
ClientProxy::ClientProxy(std::unique_ptr<AnalyticsRecorder> analytics_recorder)
: client_id_(Prng().NextInt64()),
analytics_recorder_(std::move(analytics_recorder)) {
if (analytics_recorder_ == nullptr) {
analytics_recorder_ = std::make_unique<NoOpAnalyticsRecorder>();
}
if (NearbyFlags::GetInstance().GetBoolFlag(
config_package_nearby::nearby_connections_feature::
kEnableNearbyConnectionsPreferences)) {
@@ -112,8 +255,6 @@ ClientProxy::ClientProxy(::nearby::analytics::EventLogger* event_logger)
is_dct_enabled_ = NearbyFlags::GetInstance().GetBoolFlag(
config_package_nearby::nearby_connections_feature::kEnableDct);
analytics_recorder_ =
std::make_unique<analytics::AnalyticsRecorderImpl>(event_logger);
error_code_recorder_ = std::make_unique<ErrorCodeRecorder>(
[this](const ErrorCodeParams& params) {
analytics_recorder_->OnErrorCode(params);
+2 -3
View File
@@ -42,7 +42,6 @@
#include "connections/v3/connection_listening_options.h"
#include "connections/v3/connections_device_provider.h"
#include "connections/v3/listeners.h"
#include "internal/analytics/event_logger.h"
#include "internal/interop/device.h"
#include "internal/interop/device_provider.h"
#include "internal/platform/byte_array.h"
@@ -66,8 +65,8 @@ class ClientProxy final {
static constexpr absl::Duration
kHighPowerAdvertisementEndpointIdCacheTimeout = absl::Seconds(30);
explicit ClientProxy(
::nearby::analytics::EventLogger* event_logger = nullptr);
explicit ClientProxy(std::unique_ptr<nearby::analytics::AnalyticsRecorder>
analytics_recorder = nullptr);
~ClientProxy();
ClientProxy(ClientProxy&&) = default;
ClientProxy& operator=(ClientProxy&&) = default;
+67 -70
View File
@@ -25,7 +25,6 @@
#include "gmock/gmock.h"
#include "protobuf-matchers/protocol-buffer-matchers.h"
#include "gtest/gtest.h"
#include "absl/base/thread_annotations.h"
#include "absl/strings/str_format.h"
#include "absl/strings/string_view.h"
#include "absl/time/clock.h"
@@ -34,6 +33,7 @@
#include "connections/advertising_options.h"
#include "connections/connection_options.h"
#include "connections/discovery_options.h"
#include "connections/implementation/analytics/mock_analytics_recorder.h"
#include "connections/implementation/flags/nearby_connections_feature_flags.h"
#include "connections/listeners.h"
#include "connections/medium_selector.h"
@@ -45,7 +45,6 @@
#include "connections/v3/connection_result.h"
#include "connections/v3/connections_device_provider.h"
#include "connections/v3/listeners.h"
#include "internal/analytics/mock_event_logger.h"
#include "internal/flags/nearby_flags.h"
#include "internal/interop/device.h"
#include "internal/interop/device_provider.h"
@@ -54,8 +53,6 @@
#include "internal/platform/count_down_latch.h"
#include "internal/platform/feature_flags.h"
#include "internal/platform/medium_environment.h"
#include "internal/platform/mutex.h"
#include "internal/platform/mutex_lock.h"
#include "internal/platform/single_thread_executor.h"
#include "proto/connections_enums.pb.h"
@@ -63,11 +60,11 @@ namespace nearby {
namespace connections {
namespace {
using ::location::nearby::analytics::proto::ConnectionsLog;
using ::location::nearby::connections::OsInfo;
using ::location::nearby::proto::connections::CLIENT_SESSION;
using ::location::nearby::proto::connections::START_CLIENT_SESSION;
using ::location::nearby::proto::connections::STOP_CLIENT_SESSION;
using ::testing::_;
using ::testing::IsEmpty;
using ::testing::MockFunction;
using ::testing::StrictMock;
@@ -81,46 +78,6 @@ constexpr FeatureFlags::Flags kTestCases[] = {
},
};
class FakeEventLogger : public ::nearby::analytics::MockEventLogger {
public:
explicit FakeEventLogger() = default;
void Log(const ConnectionsLog& message) override {
MutexLock lock(&mutex_);
logs_.push_back(message);
}
int GetCompleteClientSessionCount() {
MutexLock lock(&mutex_);
bool has_start_client_session = false;
bool has_client_session = false;
int session_count = 0;
// We expect series of START_CLIENT_SESSION, CLIENT_SESSION and
// STOP_CLIENT_SESSION events, possibly interleaved with other events.
for (const auto& log : logs_) {
if (log.event_type() == START_CLIENT_SESSION) {
EXPECT_FALSE(has_start_client_session);
EXPECT_FALSE(has_client_session);
has_start_client_session = true;
} else if (log.event_type() == CLIENT_SESSION) {
EXPECT_TRUE(has_start_client_session);
EXPECT_FALSE(has_client_session);
has_client_session = true;
} else if (log.event_type() == STOP_CLIENT_SESSION) {
EXPECT_TRUE(has_start_client_session);
EXPECT_TRUE(has_client_session);
has_start_client_session = false;
has_client_session = false;
++session_count;
}
}
return session_count;
}
Mutex mutex_;
std::vector<ConnectionsLog> logs_ ABSL_GUARDED_BY(mutex_);
};
class MockDeviceProvider : public nearby::NearbyDeviceProvider {
public:
MOCK_METHOD((const NearbyDevice*), GetLocalDevice, (), (override));
@@ -169,8 +126,14 @@ class ClientProxyTest : public ::testing::TestWithParam<FeatureFlags::Flags> {
/*use_simulated_clock=*/true,
/*use_temporary_directory_for_app_path=*/true};
env_.Start(config);
client1_ = std::make_unique<ClientProxy>(&event_logger1_);
client2_ = std::make_unique<ClientProxy>(&event_logger2_);
auto analytics_recorder1 =
std::make_unique<analytics::MockAnalyticsRecorder>();
mock_analytics_recorder1_ptr_ = analytics_recorder1.get();
client1_ = std::make_unique<ClientProxy>(std::move(analytics_recorder1));
auto analytics_recorder2 =
std::make_unique<analytics::MockAnalyticsRecorder>();
mock_analytics_recorder2_ptr_ = analytics_recorder2.get();
client2_ = std::make_unique<ClientProxy>(std::move(analytics_recorder2));
}
void TearDown() override {
@@ -384,8 +347,8 @@ class ClientProxyTest : public ::testing::TestWithParam<FeatureFlags::Flags> {
MediumEnvironment& env_ = MediumEnvironment::Instance();
Strategy strategy_{Strategy::kP2pPointToPoint};
const std::string service_id_{"service"};
FakeEventLogger event_logger1_;
FakeEventLogger event_logger2_;
analytics::MockAnalyticsRecorder* mock_analytics_recorder1_ptr_;
analytics::MockAnalyticsRecorder* mock_analytics_recorder2_ptr_;
std::unique_ptr<ClientProxy> client1_;
std::unique_ptr<ClientProxy> client2_;
std::string auth_token_ = "auth_token";
@@ -1182,11 +1145,13 @@ TEST_F(ClientProxyTest, NotLogSessionForStoppedAdvertisingWithConnection) {
// After
StopAdvertising(client1()); // No Advertising
EXPECT_EQ(event_logger1_.GetCompleteClientSessionCount(), 0);
EXPECT_CALL(*mock_analytics_recorder1_ptr_, LogSession()).Times(1);
}
TEST_F(ClientProxyTest,
LogSessionForStoppedAdvertisingWhenNoConnectionsAndNoDiscovering) {
EXPECT_CALL(*mock_analytics_recorder1_ptr_,
OnStartAdvertising(strategy_, mediums_, _));
Endpoint advertising_endpoint =
StartAdvertising(client1(), advertising_connection_listener_);
@@ -1195,36 +1160,47 @@ TEST_F(ClientProxyTest,
advertising_endpoint.id)); // No Connections
EXPECT_FALSE(client1()->IsDiscovering()); // No Discovery
EXPECT_TRUE(client1()->IsAdvertising()); // Advertising
EXPECT_EQ(event_logger1_.GetCompleteClientSessionCount(), 0);
// After
EXPECT_CALL(*mock_analytics_recorder1_ptr_, OnStopAdvertising());
StopAdvertising(client1());
EXPECT_GT(event_logger1_.GetCompleteClientSessionCount(), 0);
}
TEST_F(ClientProxyTest, NotLogSessionForStoppedDiscoveryWithConnection) {
EXPECT_CALL(*mock_analytics_recorder1_ptr_,
OnStartAdvertising(strategy_, mediums_, _));
Endpoint advertising_endpoint =
StartAdvertising(client1(), advertising_connection_listener_);
EXPECT_CALL(*mock_analytics_recorder2_ptr_,
OnStartDiscovery(strategy_, mediums_, _));
StartDiscovery(client2(), GetDiscoveryListener());
EXPECT_CALL(*mock_analytics_recorder2_ptr_,
OnEndpointFound(Medium::BLUETOOTH));
OnDiscoveryEndpointFound(client2(), advertising_endpoint);
// Before
EXPECT_CALL(*mock_analytics_recorder2_ptr_,
OnConnectionRequestReceived(advertising_endpoint.id));
OnDiscoveryConnectionInitiated(
client2(), advertising_endpoint); // Connections are available
EXPECT_FALSE(client2()->IsAdvertising()); // No Advertising
EXPECT_TRUE(client2()->IsDiscovering()); // Discovering
// After
EXPECT_CALL(*mock_analytics_recorder2_ptr_, OnStopDiscovery());
StopDiscovery(client2());
EXPECT_EQ(event_logger2_.GetCompleteClientSessionCount(), 0);
}
TEST_F(ClientProxyTest,
NotLogSessionForStoppedDiscoveryWithoutConnectionsAndAdvertising) {
EXPECT_CALL(*mock_analytics_recorder1_ptr_,
OnStartAdvertising(strategy_, mediums_, _));
Endpoint advertising_endpoint =
StartAdvertising(client1(), advertising_connection_listener_);
EXPECT_CALL(*mock_analytics_recorder2_ptr_,
OnStartDiscovery(strategy_, mediums_, _));
StartDiscovery(client2(), GetDiscoveryListener());
// Before
@@ -1234,30 +1210,40 @@ TEST_F(ClientProxyTest,
advertising_endpoint.id)); // No Connections
// After
EXPECT_CALL(*mock_analytics_recorder2_ptr_, OnStopDiscovery());
StopDiscovery(client2());
EXPECT_GT(event_logger2_.GetCompleteClientSessionCount(), 0);
}
TEST_F(ClientProxyTest, LogSessionOnDisconnectedWithOneConnection) {
EXPECT_CALL(*mock_analytics_recorder1_ptr_,
OnStartAdvertising(strategy_, mediums_, _));
Endpoint advertising_endpoint =
StartAdvertising(client1(), advertising_connection_listener_);
EXPECT_CALL(*mock_analytics_recorder2_ptr_,
OnStartDiscovery(strategy_, mediums_, _));
StartDiscovery(client2(), GetDiscoveryListener());
EXPECT_CALL(*mock_analytics_recorder2_ptr_,
OnEndpointFound(Medium::BLUETOOTH));
OnDiscoveryEndpointFound(client2(), advertising_endpoint);
EXPECT_CALL(*mock_analytics_recorder2_ptr_,
OnConnectionRequestReceived(advertising_endpoint.id));
OnDiscoveryConnectionInitiated(client2(), advertising_endpoint);
// Before
EXPECT_FALSE(client2()->IsAdvertising()); // No Advertising
EXPECT_CALL(*mock_analytics_recorder2_ptr_, OnStopDiscovery());
StopDiscovery(client2()); // No Discovery
EXPECT_TRUE(client2()->HasPendingConnectionToEndpoint(
advertising_endpoint.id)); // One Connection
// After
OnDiscoveryConnectionDisconnected(client2(), advertising_endpoint);
EXPECT_GT(event_logger2_.GetCompleteClientSessionCount(), 0);
}
TEST_F(ClientProxyTest,
NotLogSessionOnDisconnectedWithoutConnectionsDiscoveringAdvertising) {
EXPECT_CALL(*mock_analytics_recorder1_ptr_,
OnStartAdvertising(strategy_, mediums_, _));
Endpoint advertising_endpoint =
StartAdvertising(client1(), advertising_connection_listener_);
@@ -1269,13 +1255,16 @@ TEST_F(ClientProxyTest,
// After
client2()->OnDisconnected(advertising_endpoint.id, /*notify=*/false);
EXPECT_EQ(event_logger2_.GetCompleteClientSessionCount(), 0);
}
TEST_F(ClientProxyTest, NotLogSessionOnDisconnectedWhenMoreThanOneConnection) {
ClientProxy client3;
EXPECT_CALL(*mock_analytics_recorder1_ptr_,
OnStartAdvertising(strategy_, mediums_, _));
Endpoint advertising_endpoint_1 =
StartAdvertising(client1(), advertising_connection_listener_);
EXPECT_CALL(*mock_analytics_recorder2_ptr_,
OnStartAdvertising(strategy_, mediums_, _));
Endpoint advertising_endpoint_2 =
StartAdvertising(client2(), advertising_connection_listener_);
StartDiscovery(&client3, GetDiscoveryListener());
@@ -1296,15 +1285,22 @@ TEST_F(ClientProxyTest, NotLogSessionOnDisconnectedWhenMoreThanOneConnection) {
// After
client2()->OnDisconnected(advertising_endpoint_1.id, /*notify=*/false);
EXPECT_EQ(event_logger2_.GetCompleteClientSessionCount(), 0);
}
TEST_F(ClientProxyTest,
NotLogSessionOnDisconnectedForDiscoveringWithOnlyOneConnection) {
EXPECT_CALL(*mock_analytics_recorder1_ptr_,
OnStartAdvertising(strategy_, mediums_, _));
Endpoint advertising_endpoint =
StartAdvertising(client1(), advertising_connection_listener_);
EXPECT_CALL(*mock_analytics_recorder2_ptr_,
OnStartDiscovery(strategy_, mediums_, _));
StartDiscovery(client2(), GetDiscoveryListener());
EXPECT_CALL(*mock_analytics_recorder2_ptr_,
OnEndpointFound(Medium::BLUETOOTH));
OnDiscoveryEndpointFound(client2(), advertising_endpoint);
EXPECT_CALL(*mock_analytics_recorder2_ptr_,
OnConnectionRequestReceived(advertising_endpoint.id));
OnDiscoveryConnectionInitiated(client2(), advertising_endpoint);
// Before
@@ -1315,26 +1311,27 @@ TEST_F(ClientProxyTest,
// After
OnDiscoveryConnectionDisconnected(client2(), advertising_endpoint);
// Since we are no longer checking IsDiscovering(), we complete sessions now
// solely based on advertising.
EXPECT_EQ(event_logger2_.GetCompleteClientSessionCount(), 1);
}
TEST_F(ClientProxyTest, LogSessionForResetClientProxy) {
EXPECT_CALL(*mock_analytics_recorder1_ptr_,
OnStartAdvertising(strategy_, mediums_, _));
Endpoint advertising_endpoint =
StartAdvertising(client1(), advertising_connection_listener_);
EXPECT_CALL(*mock_analytics_recorder2_ptr_,
OnStartDiscovery(strategy_, mediums_, _));
StartDiscovery(client2(), GetDiscoveryListener());
EXPECT_CALL(*mock_analytics_recorder2_ptr_,
OnEndpointFound(Medium::BLUETOOTH));
OnDiscoveryEndpointFound(client2(), advertising_endpoint);
EXPECT_CALL(*mock_analytics_recorder2_ptr_,
OnConnectionRequestReceived(advertising_endpoint.id));
OnDiscoveryConnectionInitiated(client2(), advertising_endpoint);
EXPECT_EQ(event_logger1_.GetCompleteClientSessionCount(), 0);
EXPECT_CALL(*mock_analytics_recorder1_ptr_, OnStopAdvertising());
client1()->Reset();
// TODO(b/290936886): Why are there more than one complete sessions?
EXPECT_GT(event_logger1_.GetCompleteClientSessionCount(), 0);
EXPECT_EQ(event_logger2_.GetCompleteClientSessionCount(), 0);
EXPECT_CALL(*mock_analytics_recorder2_ptr_, OnStopDiscovery());
client2()->Reset();
EXPECT_GT(event_logger2_.GetCompleteClientSessionCount(), 0);
}
TEST_F(ClientProxyTest, GetLocalInfoCorrect) {
@@ -1536,7 +1533,7 @@ TEST_F(ClientProxyTest, SaveClientInfoFromPreferences) {
config_package_nearby::nearby_connections_feature::
kEnableNearbyConnectionsPreferences,
true);
client1_ = std::make_unique<ClientProxy>(&event_logger1_);
client1_ = std::make_unique<ClientProxy>();
Endpoint advertising_endpoint =
StartAdvertising(client1(), advertising_connection_listener_);
std::string endpoint_id = advertising_endpoint.id;
@@ -1544,7 +1541,7 @@ TEST_F(ClientProxyTest, SaveClientInfoFromPreferences) {
// Destroy the client and create a new one.
client1_.reset();
client1_ = std::make_unique<ClientProxy>(&event_logger1_);
client1_ = std::make_unique<ClientProxy>();
// The new client should load the same endpoint ID.
EXPECT_EQ(client1()->GetLocalEndpointId(), endpoint_id);
@@ -1559,7 +1556,7 @@ TEST_F(ClientProxyTest, NotLoadClientInfoFromPreferencesOnExpired) {
config_package_nearby::nearby_connections_feature::
kEnableNearbyConnectionsPreferences,
true);
client1_ = std::make_unique<ClientProxy>(&event_logger1_);
client1_ = std::make_unique<ClientProxy>();
Endpoint advertising_endpoint =
StartAdvertising(client1(), advertising_connection_listener_);
std::string endpoint_id = advertising_endpoint.id;
@@ -1569,7 +1566,7 @@ TEST_F(ClientProxyTest, NotLoadClientInfoFromPreferencesOnExpired) {
client1_.reset();
FastForward(absl::Hours(25));
client1_ = std::make_unique<ClientProxy>(&event_logger1_);
client1_ = std::make_unique<ClientProxy>();
// The new client should load the same endpoint ID.
EXPECT_NE(client1()->GetLocalEndpointId(), endpoint_id);
-3
View File
@@ -244,13 +244,11 @@ cc_test(
],
deps = [
":mediums",
"//connections:core_types",
"//connections/implementation:bwu_handler",
"//connections/implementation:client_proxy",
"//connections/implementation:endpoint_channel",
"//connections/implementation:offline_frames",
"//connections/implementation/flags:connections_flags",
"//internal/analytics:mock_event_logger",
"//internal/flags:nearby_flags",
"//internal/platform:base",
"//internal/platform:cancellation_flag",
@@ -263,7 +261,6 @@ cc_test(
"//internal/platform/implementation:comm",
"//internal/platform/implementation:platform",
"//internal/platform/implementation/g3", # build_cleaner: keep
"//internal/proto/analytics:connections_log_cc_proto",
"@com_github_protobuf_matchers//protobuf-matchers",
"@com_google_absl//absl/strings:string_view",
"@com_google_absl//absl/time",
@@ -31,9 +31,6 @@
#include "connections/implementation/mediums/awdl.h"
#include "connections/implementation/mediums/awdl_endpoint_channel.h"
#include "connections/implementation/mediums/mediums.h"
#include "connections/strategy.h"
#include "internal/analytics/mock_event_logger.h"
#include "internal/analytics/sharing_log_matchers.h"
#include "internal/platform/awdl.h"
#include "internal/platform/cancellation_flag.h"
#include "internal/platform/count_down_latch.h"
@@ -47,7 +44,6 @@
#include "internal/platform/mock_output_stream.h"
#include "internal/platform/nsd_service_info.h"
#include "internal/platform/output_stream.h"
#include "internal/proto/analytics/connections_log.pb.h"
namespace nearby {
@@ -101,17 +97,13 @@ MockAwdlMedium* awdl_medium_mock = nullptr;
namespace connections {
namespace {
using ::location::nearby::analytics::proto::ConnectionsLog;
using ::location::nearby::connections::BandwidthUpgradeNegotiationFrame;
using ::location::nearby::connections::OfflineFrame;
using ::location::nearby::connections::V1Frame;
using ::location::nearby::proto::connections::EventType;
using ::location::nearby::proto::connections::OperationResultCode;
using ::nearby::analytics::HasEventType;
using ::testing::_;
using ::testing::ByMove;
using ::protobuf_matchers::EqualsProto;
using ::testing::Matcher;
using ::testing::MockFunction;
using ::testing::Return;
using ::testing::ReturnRef;
@@ -141,14 +133,13 @@ class AwdlBwuHandlerTest : public ::testing::Test {
std::unique_ptr<BwuHandler::IncomingSocketConnection>)>
incoming_connection_callback_;
AwdlBwuHandler handler_;
nearby::analytics::MockEventLogger mock_event_logger_;
MockInputStream mock_input_stream_;
MockOutputStream mock_output_stream_;
};
TEST_F(AwdlBwuHandlerTest,
CreateUpgradedEndpointChannel_InvalidCredentials_Fails) {
ClientProxy client(&mock_event_logger_);
ClientProxy client;
BandwidthUpgradeNegotiationFrame::UpgradePathInfo path_info;
path_info.mutable_awdl_credentials(); // Empty credentials
@@ -162,7 +153,7 @@ TEST_F(AwdlBwuHandlerTest,
}
TEST_F(AwdlBwuHandlerTest, CreateUpgradedEndpointChannel_Success) {
ClientProxy client(&mock_event_logger_);
ClientProxy client;
client.AddCancellationFlag(std::string(kEndpointId));
MockInputStream input_stream;
MockOutputStream output_stream;
@@ -205,7 +196,7 @@ TEST_F(AwdlBwuHandlerTest, CreateUpgradedEndpointChannel_Success) {
TEST_F(AwdlBwuHandlerTest,
InitializeUpgradedMediumForEndpoint_StartAcceptingConnectionsFails) {
MediumEnvironment::Instance().Start({.use_simulated_clock = true});
ClientProxy client(&mock_event_logger_);
ClientProxy client;
client.AddCancellationFlag(std::string(kEndpointId));
EXPECT_CALL(*awdl_medium_mock, ListenForService(_, 0))
@@ -227,18 +218,7 @@ TEST_F(AwdlBwuHandlerTest, InitializeUpgradedMediumForEndpoint_Success) {
// real-world milliseconds elapsed between the test start and test end, this
// duration evaluated to something > 0.
{
ClientProxy client(&mock_event_logger_);
client.GetAnalyticsRecorder().OnStartAdvertising(
Strategy::kP2pPointToPoint,
{location::nearby::proto::connections::Medium::BLUETOOTH},
/*advertising_metadata_params=*/nullptr);
client.GetAnalyticsRecorder().OnBandwidthUpgradeStarted(
std::string(kEndpointId),
location::nearby::proto::connections::Medium::BLUETOOTH,
location::nearby::proto::connections::Medium::AWDL,
location::nearby::proto::connections::ConnectionAttemptDirection::
OUTGOING,
/*connection_token=*/"");
ClientProxy client;
client.AddCancellationFlag(std::string(kEndpointId));
auto awdl_server_socket = std::make_unique<MockAwdlServerSocket>();
@@ -299,67 +279,6 @@ TEST_F(AwdlBwuHandlerTest, InitializeUpgradedMediumForEndpoint_Success) {
EXPECT_THAT(result_frame, EqualsProto(expected_frame));
constexpr absl::string_view kClientSessionLog = R"pb(
event_type: CLIENT_SESSION
client_session { duration_millis: 0 }
version: "v1.5.0"
)pb";
constexpr absl::string_view kExpectedUpgradeLog = R"pb(
event_type: CLIENT_SESSION
client_session {
duration_millis: 0
strategy_session {
duration_millis: 0
strategy: P2P_POINT_TO_POINT
role: ADVERTISER
advertising_phase {
duration_millis: 0
medium: BLUETOOTH
advertising_metadata {
supports_extended_ble_advertisements: false
connected_ap_frequency: 0
supports_nfc_technology: false
}
stop_reason: FINISH_SESSION_STOP_ADVERTISING
}
upgrade_attempt {
direction: OUTGOING
duration_millis: 0
from_medium: BLUETOOTH
to_medium: AWDL
upgrade_result: UNFINISHED_ERROR
error_stage: UPGRADE_UNFINISHED
connection_token: ""
operation_result {
result_category: CATEGORY_DEVICE_STATE_ERROR
result_code: DEVICE_STATE_ERROR_UNFINISHED_UPGRADE_ATTEMPTS
}
}
}
}
version: "v1.5.0"
)pb";
EXPECT_CALL(mock_event_logger_,
Log(Matcher<const ConnectionsLog&>(
HasEventType(EventType::STOP_STRATEGY_SESSION))))
.Times(1);
EXPECT_CALL(mock_event_logger_,
Log(Matcher<const ConnectionsLog&>(
HasEventType(EventType::STOP_CLIENT_SESSION))))
.Times(3);
EXPECT_CALL(mock_event_logger_,
Log(Matcher<const ConnectionsLog&>(
HasEventType(EventType::START_CLIENT_SESSION))))
.Times(3);
EXPECT_CALL(
mock_event_logger_,
Log(Matcher<const ConnectionsLog&>(EqualsProto(kClientSessionLog))))
.Times(2);
EXPECT_CALL(
mock_event_logger_,
Log(Matcher<const ConnectionsLog&>(EqualsProto(kExpectedUpgradeLog))));
// Flush pending logs.
client.GetAnalyticsRecorder().LogSession();
handler_.RevertInitiatorState();
}
MediumEnvironment::Instance().Stop();
@@ -367,7 +286,7 @@ TEST_F(AwdlBwuHandlerTest, InitializeUpgradedMediumForEndpoint_Success) {
TEST_F(AwdlBwuHandlerTest, OnIncomingAwdlConnection_Success) {
MediumEnvironment::Instance().Start({.use_simulated_clock = true});
ClientProxy client(&mock_event_logger_);
ClientProxy client;
client.AddCancellationFlag(std::string(kEndpointId));
auto awdl_server_socket = std::make_unique<MockAwdlServerSocket>();
@@ -411,7 +330,7 @@ TEST_F(AwdlBwuHandlerTest, OnIncomingAwdlConnection_Success) {
TEST_F(AwdlBwuHandlerTest, AwdlIncomingSocket_ToStringAndClose) {
MediumEnvironment::Instance().Start({.use_simulated_clock = true});
ClientProxy client(&mock_event_logger_);
ClientProxy client;
client.AddCancellationFlag(std::string(kEndpointId));
auto awdl_server_socket = std::make_unique<MockAwdlServerSocket>();
@@ -461,7 +380,7 @@ TEST_F(AwdlBwuHandlerTest, AwdlIncomingSocket_ToStringAndClose) {
TEST_F(AwdlBwuHandlerTest, HandleRevertInitiatorStateForService_Success) {
MediumEnvironment::Instance().Start({.use_simulated_clock = true});
ClientProxy client(&mock_event_logger_);
ClientProxy client;
client.AddCancellationFlag(std::string(kEndpointId));
auto awdl_server_socket = std::make_unique<MockAwdlServerSocket>();
@@ -492,7 +411,7 @@ TEST_F(AwdlBwuHandlerTest, GetUpgradeMedium_ReturnsAwdl) {
}
TEST_F(AwdlBwuHandlerTest, OnEndpointDisconnect_DoesNotCrash) {
ClientProxy client(&mock_event_logger_);
ClientProxy client;
auto* bwu_handler = static_cast<BwuHandler*>(&handler_);
// This method is a no-op, just verifying it doesn't crash.
bwu_handler->OnEndpointDisconnect(&client, std::string(kEndpointId));
@@ -26,9 +26,6 @@
#include "connections/implementation/bwu_handler.h"
#include "connections/implementation/client_proxy.h"
#include "connections/implementation/mediums/mediums.h"
#include "connections/strategy.h"
#include "internal/analytics/mock_event_logger.h"
#include "internal/analytics/sharing_log_matchers.h"
#include "internal/platform/implementation/platform.h"
#include "internal/platform/implementation/upgrade_address_info.h"
#include "internal/platform/implementation/wifi_lan.h"
@@ -40,7 +37,6 @@
#include "internal/platform/mock_wifi_lan_socket.h"
#include "internal/platform/service_address.h"
#include "internal/platform/wifi_lan.h"
#include "internal/proto/analytics/connections_log.pb.h"
namespace nearby {
@@ -48,18 +44,14 @@ MockWifiLanMedium* wifi_lan_medium = nullptr;
namespace connections {
namespace {
using ::location::nearby::analytics::proto::ConnectionsLog;
using ::location::nearby::connections::BandwidthUpgradeNegotiationFrame;
using ::location::nearby::connections::OfflineFrame;
using ::location::nearby::connections::V1Frame;
using ::location::nearby::proto::connections::EventType;
using ::location::nearby::proto::connections::OperationResultCode;
using ::nearby::analytics::HasEventType;
using ::testing::_;
using ::testing::ByMove;
using ::protobuf_matchers::EqualsProto;
using ::testing::InSequence;
using ::testing::Matcher;
using ::testing::MockFunction;
using ::testing::Return;
using ::testing::ReturnRef;
@@ -81,12 +73,11 @@ class WifiLanBwuHandlerTest : public ::testing::Test {
std::unique_ptr<BwuHandler::IncomingSocketConnection>)>
incoming_connection_callback_;
WifiLanBwuHandler handler_;
nearby::analytics::MockEventLogger mock_event_logger_;
};
TEST_F(WifiLanBwuHandlerTest,
CreateUpgradedEndpointChannel_EmptyPathInfo_Fails) {
ClientProxy client(&mock_event_logger_);
ClientProxy client;
BandwidthUpgradeNegotiationFrame::UpgradePathInfo path_info;
// Create an empty wifi_lan_socket.
path_info.mutable_wifi_lan_socket();
@@ -100,7 +91,7 @@ TEST_F(WifiLanBwuHandlerTest,
};
TEST_F(WifiLanBwuHandlerTest, CreateUpgradedEndpointChannel_IpAddress_Success) {
ClientProxy client(&mock_event_logger_);
ClientProxy client;
client.AddCancellationFlag(std::string(kEndpointId));
MockInputStream input_stream;
MockOutputStream output_stream;
@@ -133,7 +124,7 @@ TEST_F(WifiLanBwuHandlerTest, CreateUpgradedEndpointChannel_IpAddress_Success) {
TEST_F(WifiLanBwuHandlerTest,
CreateUpgradedEndpointChannel_AddressCandidates_FirstCandidate_Success) {
ClientProxy client(&mock_event_logger_);
ClientProxy client;
client.AddCancellationFlag(std::string(kEndpointId));
MockInputStream input_stream;
MockOutputStream output_stream;
@@ -172,7 +163,7 @@ TEST_F(WifiLanBwuHandlerTest,
TEST_F(WifiLanBwuHandlerTest,
CreateUpgradedEndpointChannel_AddressCandidates_FirstCandidate_Fails) {
ClientProxy client(&mock_event_logger_);
ClientProxy client;
client.AddCancellationFlag(std::string(kEndpointId));
MockInputStream input_stream;
MockOutputStream output_stream;
@@ -220,18 +211,7 @@ TEST_F(WifiLanBwuHandlerTest,
TEST_F(WifiLanBwuHandlerTest, InitializeUpgradedMediumForEndpoint_Success) {
MediumEnvironment::Instance().Start({.use_simulated_clock = true});
ClientProxy client(&mock_event_logger_);
client.GetAnalyticsRecorder().OnStartAdvertising(
Strategy::kP2pPointToPoint,
{location::nearby::proto::connections::Medium::BLUETOOTH},
/*advertising_metadata_params=*/nullptr);
client.GetAnalyticsRecorder().OnBandwidthUpgradeStarted(
std::string(kEndpointId),
location::nearby::proto::connections::Medium::BLUETOOTH,
location::nearby::proto::connections::Medium::WIFI_LAN,
location::nearby::proto::connections::ConnectionAttemptDirection::
OUTGOING,
/*connection_token=*/"");
ClientProxy client;
client.AddCancellationFlag(std::string(kEndpointId));
auto wifi_lan_server_socket = std::make_unique<MockWifiLanServerSocket>();
EXPECT_CALL(*wifi_lan_server_socket, GetPort()).WillRepeatedly(Return(8080));
@@ -279,76 +259,12 @@ TEST_F(WifiLanBwuHandlerTest, InitializeUpgradedMediumForEndpoint_Success) {
OfflineFrame result_frame;
EXPECT_TRUE(result_frame.ParseFromString(result));
EXPECT_THAT(result_frame, EqualsProto(expected_frame));
constexpr absl::string_view kClientSessionLog = R"pb(
event_type: CLIENT_SESSION
client_session { duration_millis: 0 }
version: "v1.5.0"
)pb";
constexpr absl::string_view kExpectedUpgradeLog = R"pb(
event_type: CLIENT_SESSION
client_session {
duration_millis: 0
strategy_session {
duration_millis: 0
strategy: P2P_POINT_TO_POINT
role: ADVERTISER
advertising_phase {
duration_millis: 0
medium: BLUETOOTH
advertising_metadata {
supports_extended_ble_advertisements: false
connected_ap_frequency: 0
supports_nfc_technology: false
}
stop_reason: FINISH_SESSION_STOP_ADVERTISING
}
upgrade_attempt {
direction: OUTGOING
duration_millis: 0
from_medium: BLUETOOTH
to_medium: WIFI_LAN
upgrade_result: UNFINISHED_ERROR
error_stage: UPGRADE_UNFINISHED
connection_token: ""
operation_result {
result_category: CATEGORY_DEVICE_STATE_ERROR
result_code: DEVICE_STATE_ERROR_UNFINISHED_UPGRADE_ATTEMPTS
}
num_interfaces: 1
num_ipv6_only_interfaces: 1
}
}
}
version: "v1.5.0"
)pb";
EXPECT_CALL(mock_event_logger_,
Log(Matcher<const ConnectionsLog&>(
HasEventType(EventType::STOP_STRATEGY_SESSION))))
.Times(1);
EXPECT_CALL(mock_event_logger_,
Log(Matcher<const ConnectionsLog&>(
HasEventType(EventType::STOP_CLIENT_SESSION))))
.Times(3);
EXPECT_CALL(mock_event_logger_,
Log(Matcher<const ConnectionsLog&>(
HasEventType(EventType::START_CLIENT_SESSION))))
.Times(3);
EXPECT_CALL(
mock_event_logger_,
Log(Matcher<const ConnectionsLog&>(EqualsProto(kClientSessionLog))))
.Times(2);
EXPECT_CALL(
mock_event_logger_,
Log(Matcher<const ConnectionsLog&>(EqualsProto(kExpectedUpgradeLog))));
// Flush pending logs.
client.GetAnalyticsRecorder().LogSession();
}
TEST_F(WifiLanBwuHandlerTest,
InitializeUpgradedMediumForEndpoint_EmptyCandidates_StopsAccepting) {
MediumEnvironment::Instance().Start({.use_simulated_clock = true});
ClientProxy client(&mock_event_logger_);
ClientProxy client;
client.AddCancellationFlag(std::string(kEndpointId));
auto mock_server_socket = std::make_unique<MockWifiLanServerSocket>();
@@ -377,7 +293,7 @@ TEST_F(
WifiLanBwuHandlerTest,
InitializeUpgradedMediumForEndpoint_AlreadyAccepting_KeepAccepting) {
MediumEnvironment::Instance().Start({.use_simulated_clock = true});
ClientProxy client(&mock_event_logger_);
ClientProxy client;
client.AddCancellationFlag(std::string(kEndpointId));
auto mock_server_socket = std::make_unique<MockWifiLanServerSocket>();
@@ -29,6 +29,7 @@
#include "absl/strings/string_view.h"
#include "connections/advertising_options.h"
#include "connections/discovery_options.h"
#include "connections/implementation/analytics/operation_result_with_medium.h"
#include "connections/implementation/base_pcp_handler.h"
#include "connections/implementation/ble_advertisement.h"
#include "connections/implementation/bluetooth_device_name.h"
@@ -82,7 +83,6 @@ namespace nearby {
namespace connections {
namespace {
using ::location::nearby::analytics::proto::ConnectionsLog;
using ::location::nearby::proto::connections::OperationResultCode;
using ::location::nearby::proto::connections::Medium::AWDL;
using ::location::nearby::proto::connections::Medium::BLE;
@@ -90,6 +90,7 @@ using ::location::nearby::proto::connections::Medium::BLUETOOTH;
using ::location::nearby::proto::connections::Medium::UNKNOWN_MEDIUM;
using ::location::nearby::proto::connections::Medium::WEB_RTC;
using ::location::nearby::proto::connections::Medium::WIFI_LAN;
using ::nearby::analytics::OperationResultWithMedium;
} // namespace
@@ -157,8 +158,7 @@ BasePcpHandler::StartOperationResult P2pClusterPcpHandler::StartAdvertisingImpl(
const std::string& local_endpoint_id, const ByteArray& local_endpoint_info,
const AdvertisingOptions& advertising_options) {
std::vector<Medium> mediums_started_successfully;
std::vector<ConnectionsLog::OperationResultWithMedium>
operation_result_with_mediums;
std::vector<OperationResultWithMedium> operation_result_with_mediums;
WebRtcState web_rtc_state{WebRtcState::kUnconnectable};
@@ -178,13 +178,12 @@ BasePcpHandler::StartOperationResult P2pClusterPcpHandler::StartAdvertisingImpl(
VLOG(1) << "P2pClusterPcpHandler::StartAdvertisingImpl: Awdl added";
mediums_started_successfully.push_back(awdl_medium);
}
std::unique_ptr<ConnectionsLog::OperationResultWithMedium>
operation_result_with_medium = GetOperationResultWithMediumByResultCode(
operation_result_with_mediums.push_back(
GetOperationResultWithMediumByResultCode(
client, AWDL, /*update_index=*/0,
awdl_result.has_error()
? awdl_result.error().operation_result_code().value()
: OperationResultCode::DETAIL_SUCCESS);
operation_result_with_mediums.push_back(*operation_result_with_medium);
: OperationResultCode::DETAIL_SUCCESS));
}
// WifiLan
@@ -200,13 +199,12 @@ BasePcpHandler::StartOperationResult P2pClusterPcpHandler::StartAdvertisingImpl(
VLOG(1) << "P2pClusterPcpHandler::StartAdvertisingImpl: WifiLan added";
mediums_started_successfully.push_back(wifi_lan_medium);
}
std::unique_ptr<ConnectionsLog::OperationResultWithMedium>
operation_result_with_medium = GetOperationResultWithMediumByResultCode(
operation_result_with_mediums.push_back(
GetOperationResultWithMediumByResultCode(
client, WIFI_LAN, /*update_index=*/0,
wifi_lan_result.has_error()
? wifi_lan_result.error().operation_result_code().value()
: OperationResultCode::DETAIL_SUCCESS);
operation_result_with_mediums.push_back(*operation_result_with_medium);
: OperationResultCode::DETAIL_SUCCESS));
}
if (advertising_options.allowed.bluetooth) {
@@ -244,14 +242,13 @@ BasePcpHandler::StartOperationResult P2pClusterPcpHandler::StartAdvertisingImpl(
bluetooth_classic_advertiser_client_id_ = client->GetClientId();
}
}
std::unique_ptr<ConnectionsLog::OperationResultWithMedium>
operation_result_with_medium = GetOperationResultWithMediumByResultCode(
operation_result_with_mediums.push_back(
GetOperationResultWithMediumByResultCode(
client, BLUETOOTH,
/*update_index=*/0,
bluetooth_result.has_error()
? bluetooth_result.error().operation_result_code().value()
: OperationResultCode::DETAIL_SUCCESS);
operation_result_with_mediums.push_back(*operation_result_with_medium);
: OperationResultCode::DETAIL_SUCCESS));
}
if (advertising_options.allowed.ble) {
@@ -264,12 +261,12 @@ BasePcpHandler::StartOperationResult P2pClusterPcpHandler::StartAdvertisingImpl(
mediums_started_successfully.push_back(ble_result.value());
}
std::unique_ptr<ConnectionsLog::OperationResultWithMedium>
operation_result_with_medium = GetOperationResultWithMediumByResultCode(
operation_result_with_mediums.push_back(
GetOperationResultWithMediumByResultCode(
client, BLE, /*update_index=*/0,
ble_result.has_error()
? ble_result.error().operation_result_code().value()
: OperationResultCode::DETAIL_SUCCESS);
: OperationResultCode::DETAIL_SUCCESS));
}
if (mediums_started_successfully.empty()) {
@@ -1043,8 +1040,7 @@ BasePcpHandler::StartOperationResult P2pClusterPcpHandler::StartDiscoveryImpl(
}
std::vector<Medium> mediums_started_successfully;
std::vector<ConnectionsLog::OperationResultWithMedium>
operation_result_with_mediums;
std::vector<OperationResultWithMedium> operation_result_with_mediums;
// Due to singleton, apple only allow start discovery once. So need to keep
// the start discovery order of awdl before the wifi_lan.
@@ -1060,14 +1056,13 @@ BasePcpHandler::StartOperationResult P2pClusterPcpHandler::StartDiscoveryImpl(
LOG(INFO) << "P2pClusterPcpHandler::StartDiscoveryImpl: AWDL added";
mediums_started_successfully.push_back(awdl_medium);
}
std::unique_ptr<ConnectionsLog::OperationResultWithMedium>
operation_result_with_medium = GetOperationResultWithMediumByResultCode(
operation_result_with_mediums.push_back(
GetOperationResultWithMediumByResultCode(
client, AWDL,
/*update_index=*/0,
awdl_result.has_error()
? awdl_result.error().operation_result_code().value()
: OperationResultCode::DETAIL_SUCCESS);
operation_result_with_mediums.push_back(*operation_result_with_medium);
: OperationResultCode::DETAIL_SUCCESS));
}
// WifiLan
@@ -1081,14 +1076,13 @@ BasePcpHandler::StartOperationResult P2pClusterPcpHandler::StartDiscoveryImpl(
LOG(INFO) << "P2pClusterPcpHandler::StartDiscoveryImpl: WifiLan added";
mediums_started_successfully.push_back(wifi_lan_medium);
}
std::unique_ptr<ConnectionsLog::OperationResultWithMedium>
operation_result_with_medium = GetOperationResultWithMediumByResultCode(
operation_result_with_mediums.push_back(
GetOperationResultWithMediumByResultCode(
client, WIFI_LAN,
/*update_index=*/0,
wifi_lan_result.has_error()
? wifi_lan_result.error().operation_result_code().value()
: OperationResultCode::DETAIL_SUCCESS);
operation_result_with_mediums.push_back(*operation_result_with_medium);
: OperationResultCode::DETAIL_SUCCESS));
}
if (discovery_options.allowed.ble) {
@@ -1103,14 +1097,13 @@ BasePcpHandler::StartOperationResult P2pClusterPcpHandler::StartDiscoveryImpl(
mediums_started_successfully.push_back(ble_medium);
}
std::unique_ptr<ConnectionsLog::OperationResultWithMedium>
operation_result_with_medium = GetOperationResultWithMediumByResultCode(
operation_result_with_mediums.push_back(
GetOperationResultWithMediumByResultCode(
client, BLE,
/*update_index=*/0,
ble_result.has_error()
? ble_result.error().operation_result_code().value()
: OperationResultCode::DETAIL_SUCCESS);
operation_result_with_mediums.push_back(*operation_result_with_medium);
: OperationResultCode::DETAIL_SUCCESS));
}
if (discovery_options.allowed.bluetooth) {
@@ -1159,8 +1152,7 @@ Status P2pClusterPcpHandler::StopDiscoveryImpl(ClientProxy* client) {
ble_medium_.StopScanning(client->GetDiscoveryServiceId());
paused_bluetooth_clients_discoveries_.erase(
client->GetDiscoveryServiceId());
paused_bluetooth_clients_discoveries_.erase(client->GetDiscoveryServiceId());
return {Status::kSuccess};
}
@@ -1236,8 +1228,7 @@ P2pClusterPcpHandler::StartListeningForIncomingConnectionsImpl(
bool refactor_ble_l2cap = NearbyFlags::GetInstance().GetBoolFlag(
config_package_nearby::nearby_connections_feature::kRefactorBleL2cap);
std::vector<Medium> started_mediums;
std::vector<ConnectionsLog::OperationResultWithMedium>
operation_result_with_mediums;
std::vector<OperationResultWithMedium> operation_result_with_mediums;
int update_index =
client_proxy->GetAnalyticsRecorder().GetNextAdvertisingUpdateIndex();
if (options.enable_bluetooth_listening &&
@@ -1255,13 +1246,12 @@ P2pClusterPcpHandler::StartListeningForIncomingConnectionsImpl(
} else {
started_mediums.push_back(BLUETOOTH);
}
std::unique_ptr<ConnectionsLog::OperationResultWithMedium>
operation_result_with_medium = GetOperationResultWithMediumByResultCode(
operation_result_with_mediums.push_back(
GetOperationResultWithMediumByResultCode(
client_proxy, Medium::BLUETOOTH, update_index,
bluetooth_result.has_error()
? bluetooth_result.error().operation_result_code().value()
: OperationResultCode::DETAIL_SUCCESS);
operation_result_with_mediums.push_back(*operation_result_with_medium);
: OperationResultCode::DETAIL_SUCCESS));
}
// ble
@@ -1345,13 +1335,12 @@ P2pClusterPcpHandler::StartListeningForIncomingConnectionsImpl(
} else {
started_mediums.push_back(WIFI_LAN);
}
std::unique_ptr<ConnectionsLog::OperationResultWithMedium>
operation_result_with_medium = GetOperationResultWithMediumByResultCode(
operation_result_with_mediums.push_back(
GetOperationResultWithMediumByResultCode(
client_proxy, Medium::BLUETOOTH, update_index,
wifi_lan_result.has_error()
? wifi_lan_result.error().operation_result_code().value()
: OperationResultCode::DETAIL_SUCCESS);
operation_result_with_mediums.push_back(*operation_result_with_medium);
: OperationResultCode::DETAIL_SUCCESS));
}
if (started_mediums.empty()) {
LOG(WARNING) << absl::StrFormat(
@@ -1444,8 +1433,7 @@ P2pClusterPcpHandler::UpdateAdvertisingOptionsImpl(
// restart
std::vector<Medium> restarted_mediums;
std::vector<ConnectionsLog::OperationResultWithMedium>
operation_result_with_mediums;
std::vector<OperationResultWithMedium> operation_result_with_mediums;
int update_index =
client->GetAnalyticsRecorder().GetNextAdvertisingUpdateIndex();
Status status = {Status::kSuccess};
@@ -1458,12 +1446,9 @@ P2pClusterPcpHandler::UpdateAdvertisingOptionsImpl(
if (new_mediums.ble) {
if (old_mediums.ble && !needs_restart) {
restarted_mediums.push_back(BLE);
std::unique_ptr<ConnectionsLog::OperationResultWithMedium>
operation_result_with_medium =
GetOperationResultWithMediumByResultCode(
client, BLE, update_index,
OperationResultCode::DETAIL_SUCCESS);
operation_result_with_mediums.push_back(*operation_result_with_medium);
operation_result_with_mediums.push_back(
GetOperationResultWithMediumByResultCode(
client, BLE, update_index, OperationResultCode::DETAIL_SUCCESS));
} else {
ErrorOr<Medium> ble_result = {Error(OperationResultCode::DETAIL_UNKNOWN)};
ble_result = StartBleAdvertising(
@@ -1476,14 +1461,12 @@ P2pClusterPcpHandler::UpdateAdvertisingOptionsImpl(
status = {Status::kBleError};
}
std::unique_ptr<ConnectionsLog::OperationResultWithMedium>
operation_result_with_medium =
GetOperationResultWithMediumByResultCode(
client, BLE, update_index,
ble_result.has_error()
? ble_result.error().operation_result_code().value()
: OperationResultCode::DETAIL_SUCCESS);
operation_result_with_mediums.push_back(*operation_result_with_medium);
operation_result_with_mediums.push_back(
GetOperationResultWithMediumByResultCode(
client, BLE, update_index,
ble_result.has_error()
? ble_result.error().operation_result_code().value()
: OperationResultCode::DETAIL_SUCCESS));
}
}
// awdl
@@ -1492,12 +1475,9 @@ P2pClusterPcpHandler::UpdateAdvertisingOptionsImpl(
new_mediums.awdl && !advertising_options.low_power) {
if (old_mediums.awdl && !needs_restart) {
restarted_mediums.push_back(AWDL);
std::unique_ptr<ConnectionsLog::OperationResultWithMedium>
operation_result_with_medium =
GetOperationResultWithMediumByResultCode(
client, AWDL, update_index,
OperationResultCode::DETAIL_SUCCESS);
operation_result_with_mediums.push_back(*operation_result_with_medium);
operation_result_with_mediums.push_back(
GetOperationResultWithMediumByResultCode(
client, AWDL, update_index, OperationResultCode::DETAIL_SUCCESS));
} else {
ErrorOr<Medium> awdl_result = StartAwdlAdvertising(
client, std::string(service_id), std::string(local_endpoint_id),
@@ -1507,26 +1487,22 @@ P2pClusterPcpHandler::UpdateAdvertisingOptionsImpl(
} else {
status = {Status::kWifiLanError};
}
std::unique_ptr<ConnectionsLog::OperationResultWithMedium>
operation_result_with_medium =
GetOperationResultWithMediumByResultCode(
client, AWDL, update_index,
awdl_result.has_error()
? awdl_result.error().operation_result_code().value()
: OperationResultCode::DETAIL_SUCCESS);
operation_result_with_mediums.push_back(*operation_result_with_medium);
operation_result_with_mediums.push_back(
GetOperationResultWithMediumByResultCode(
client, AWDL, update_index,
awdl_result.has_error()
? awdl_result.error().operation_result_code().value()
: OperationResultCode::DETAIL_SUCCESS));
}
}
// wifi lan
if (new_mediums.wifi_lan && !advertising_options.low_power) {
if (old_mediums.wifi_lan && !needs_restart) {
restarted_mediums.push_back(WIFI_LAN);
std::unique_ptr<ConnectionsLog::OperationResultWithMedium>
operation_result_with_medium =
GetOperationResultWithMediumByResultCode(
client, WIFI_LAN, update_index,
OperationResultCode::DETAIL_SUCCESS);
operation_result_with_mediums.push_back(*operation_result_with_medium);
operation_result_with_mediums.push_back(
GetOperationResultWithMediumByResultCode(
client, WIFI_LAN, update_index,
OperationResultCode::DETAIL_SUCCESS));
} else {
ErrorOr<Medium> wifi_lan_result = StartWifiLanAdvertising(
client, std::string(service_id), std::string(local_endpoint_id),
@@ -1537,26 +1513,22 @@ P2pClusterPcpHandler::UpdateAdvertisingOptionsImpl(
} else {
status = {Status::kWifiLanError};
}
std::unique_ptr<ConnectionsLog::OperationResultWithMedium>
operation_result_with_medium =
GetOperationResultWithMediumByResultCode(
client, WIFI_LAN, update_index,
wifi_lan_result.has_error()
? wifi_lan_result.error().operation_result_code().value()
: OperationResultCode::DETAIL_SUCCESS);
operation_result_with_mediums.push_back(*operation_result_with_medium);
operation_result_with_mediums.push_back(
GetOperationResultWithMediumByResultCode(
client, WIFI_LAN, update_index,
wifi_lan_result.has_error()
? wifi_lan_result.error().operation_result_code().value()
: OperationResultCode::DETAIL_SUCCESS));
}
}
// bluetooth classic
if (new_mediums.bluetooth && !advertising_options.low_power) {
if (old_mediums.bluetooth && !needs_restart) {
restarted_mediums.push_back(BLUETOOTH);
std::unique_ptr<ConnectionsLog::OperationResultWithMedium>
operation_result_with_medium =
GetOperationResultWithMediumByResultCode(
client, BLUETOOTH, update_index,
OperationResultCode::DETAIL_SUCCESS);
operation_result_with_mediums.push_back(*operation_result_with_medium);
operation_result_with_mediums.push_back(
GetOperationResultWithMediumByResultCode(
client, BLUETOOTH, update_index,
OperationResultCode::DETAIL_SUCCESS));
} else {
const ByteArray bluetooth_hash = GenerateHash(
std::string(service_id), BluetoothDeviceName::kServiceIdHashLength);
@@ -1590,27 +1562,19 @@ P2pClusterPcpHandler::UpdateAdvertisingOptionsImpl(
restarted_mediums.push_back(BLUETOOTH);
}
std::unique_ptr<ConnectionsLog::OperationResultWithMedium>
operation_result_with_medium =
GetOperationResultWithMediumByResultCode(
client, BLUETOOTH, update_index,
bluetooth_result.has_error()
? bluetooth_result.error()
.operation_result_code()
.value()
: OperationResultCode::DETAIL_SUCCESS);
operation_result_with_mediums.push_back(*operation_result_with_medium);
operation_result_with_mediums.push_back(
GetOperationResultWithMediumByResultCode(
client, BLUETOOTH, update_index,
bluetooth_result.has_error()
? bluetooth_result.error().operation_result_code().value()
: OperationResultCode::DETAIL_SUCCESS));
} else {
std::unique_ptr<ConnectionsLog::OperationResultWithMedium>
operation_result_with_medium =
GetOperationResultWithMediumByResultCode(
client, BLUETOOTH, update_index,
bluetooth_result.has_error()
? bluetooth_result.error()
.operation_result_code()
.value()
: OperationResultCode::DETAIL_SUCCESS);
operation_result_with_mediums.push_back(*operation_result_with_medium);
operation_result_with_mediums.push_back(
GetOperationResultWithMediumByResultCode(
client, BLUETOOTH, update_index,
bluetooth_result.has_error()
? bluetooth_result.error().operation_result_code().value()
: OperationResultCode::DETAIL_SUCCESS));
return StartOperationResult{.status = {Status::kBluetoothError},
.mediums = restarted_mediums,
.operation_result_with_mediums = std::move(
@@ -1662,8 +1626,7 @@ P2pClusterPcpHandler::UpdateDiscoveryOptionsImpl(
bool should_start_discovery = false;
auto new_mediums = discovery_options.allowed;
auto old_mediums = old_options.allowed;
std::vector<ConnectionsLog::OperationResultWithMedium>
operation_result_with_mediums;
std::vector<OperationResultWithMedium> operation_result_with_mediums;
int update_index =
client->GetAnalyticsRecorder().GetNextDiscoveryUpdateIndex();
// ble
@@ -1671,12 +1634,9 @@ P2pClusterPcpHandler::UpdateDiscoveryOptionsImpl(
should_start_discovery = true;
if (old_mediums.ble) {
restarted_mediums.push_back(BLE);
std::unique_ptr<ConnectionsLog::OperationResultWithMedium>
operation_result_with_medium =
GetOperationResultWithMediumByResultCode(
client, BLE, update_index,
OperationResultCode::DETAIL_SUCCESS);
operation_result_with_mediums.push_back(*operation_result_with_medium);
operation_result_with_mediums.push_back(
GetOperationResultWithMediumByResultCode(
client, BLE, update_index, OperationResultCode::DETAIL_SUCCESS));
} else {
ErrorOr<Medium> ble_result = {Error(OperationResultCode::DETAIL_UNKNOWN)};
ble_result =
@@ -1688,14 +1648,12 @@ P2pClusterPcpHandler::UpdateDiscoveryOptionsImpl(
"restart ble scanning";
}
std::unique_ptr<ConnectionsLog::OperationResultWithMedium>
operation_result_with_medium =
GetOperationResultWithMediumByResultCode(
client, BLE, update_index,
ble_result.has_error()
? ble_result.error().operation_result_code().value()
: OperationResultCode::DETAIL_SUCCESS);
operation_result_with_mediums.push_back(*operation_result_with_medium);
operation_result_with_mediums.push_back(
GetOperationResultWithMediumByResultCode(
client, BLE, update_index,
ble_result.has_error()
? ble_result.error().operation_result_code().value()
: OperationResultCode::DETAIL_SUCCESS));
}
}
// bt classic
@@ -1703,12 +1661,10 @@ P2pClusterPcpHandler::UpdateDiscoveryOptionsImpl(
should_start_discovery = true;
if (!needs_restart && old_mediums.bluetooth) {
restarted_mediums.push_back(BLUETOOTH);
std::unique_ptr<ConnectionsLog::OperationResultWithMedium>
operation_result_with_medium =
GetOperationResultWithMediumByResultCode(
client, BLUETOOTH, update_index,
OperationResultCode::DETAIL_SUCCESS);
operation_result_with_mediums.push_back(*operation_result_with_medium);
operation_result_with_mediums.push_back(
GetOperationResultWithMediumByResultCode(
client, BLUETOOTH, update_index,
OperationResultCode::DETAIL_SUCCESS));
} else {
StartBluetoothDiscoveryWithPause(
client, std::string(service_id), discovery_options, restarted_mediums,
@@ -1722,12 +1678,10 @@ P2pClusterPcpHandler::UpdateDiscoveryOptionsImpl(
should_start_discovery = true;
if (!needs_restart && old_mediums.awdl) {
restarted_mediums.push_back(AWDL);
std::unique_ptr<ConnectionsLog::OperationResultWithMedium>
operation_result_with_medium =
GetOperationResultWithMediumByResultCode(
client, AWDL, update_index,
OperationResultCode::DETAIL_SUCCESS);
operation_result_with_mediums.push_back(*operation_result_with_medium);
operation_result_with_mediums.push_back(
GetOperationResultWithMediumByResultCode(
client, AWDL, update_index,
OperationResultCode::DETAIL_SUCCESS));
} else {
ErrorOr<Medium> awdl_result =
StartAwdlDiscovery(client, std::string(service_id));
@@ -1737,14 +1691,12 @@ P2pClusterPcpHandler::UpdateDiscoveryOptionsImpl(
LOG(WARNING) << "UpdateDiscoveryOptionsImpl: unable to restart "
"awdl scanning";
}
std::unique_ptr<ConnectionsLog::OperationResultWithMedium>
operation_result_with_medium =
GetOperationResultWithMediumByResultCode(
client, AWDL, update_index,
awdl_result.has_error()
? awdl_result.error().operation_result_code().value()
: OperationResultCode::DETAIL_SUCCESS);
operation_result_with_mediums.push_back(*operation_result_with_medium);
operation_result_with_mediums.push_back(
GetOperationResultWithMediumByResultCode(
client, AWDL, update_index,
awdl_result.has_error()
? awdl_result.error().operation_result_code().value()
: OperationResultCode::DETAIL_SUCCESS));
}
}
// wifi lan
@@ -1752,12 +1704,10 @@ P2pClusterPcpHandler::UpdateDiscoveryOptionsImpl(
should_start_discovery = true;
if (!needs_restart && old_mediums.wifi_lan) {
restarted_mediums.push_back(WIFI_LAN);
std::unique_ptr<ConnectionsLog::OperationResultWithMedium>
operation_result_with_medium =
GetOperationResultWithMediumByResultCode(
client, WIFI_LAN, update_index,
OperationResultCode::DETAIL_SUCCESS);
operation_result_with_mediums.push_back(*operation_result_with_medium);
operation_result_with_mediums.push_back(
GetOperationResultWithMediumByResultCode(
client, WIFI_LAN, update_index,
OperationResultCode::DETAIL_SUCCESS));
} else {
ErrorOr<Medium> wifi_lan_result =
StartWifiLanDiscovery(client, std::string(service_id));
@@ -1767,14 +1717,12 @@ P2pClusterPcpHandler::UpdateDiscoveryOptionsImpl(
LOG(WARNING) << "UpdateDiscoveryOptionsImpl: unable to restart "
"wifi lan scanning";
}
std::unique_ptr<ConnectionsLog::OperationResultWithMedium>
operation_result_with_medium =
GetOperationResultWithMediumByResultCode(
client, WIFI_LAN, update_index,
wifi_lan_result.has_error()
? wifi_lan_result.error().operation_result_code().value()
: OperationResultCode::DETAIL_SUCCESS);
operation_result_with_mediums.push_back(*operation_result_with_medium);
operation_result_with_mediums.push_back(
GetOperationResultWithMediumByResultCode(
client, WIFI_LAN, update_index,
wifi_lan_result.has_error()
? wifi_lan_result.error().operation_result_code().value()
: OperationResultCode::DETAIL_SUCCESS));
}
}
if (restarted_mediums.empty() && should_start_discovery) {
@@ -1947,8 +1895,7 @@ void P2pClusterPcpHandler::StartBluetoothDiscoveryWithPause(
ClientProxy* client, const std::string& service_id,
const DiscoveryOptions& discovery_options,
std::vector<Medium>& mediums_started_successfully,
std::vector<ConnectionsLog::OperationResultWithMedium>&
operation_result_with_mediums,
std::vector<OperationResultWithMedium>& operation_result_with_mediums,
int update_index) {
if (bluetooth_radio_.IsEnabled()) {
if (ble_medium_.IsExtendedAdvertisementsAvailable() &&
@@ -1966,16 +1913,12 @@ void P2pClusterPcpHandler::StartBluetoothDiscoveryWithPause(
bluetooth_classic_client_id_to_service_id_map_.insert(
{client->GetClientId(), service_id});
}
std::unique_ptr<ConnectionsLog::OperationResultWithMedium>
operation_result_with_medium =
GetOperationResultWithMediumByResultCode(
client, BLUETOOTH, update_index,
bluetooth_result.has_error()
? bluetooth_result.error()
.operation_result_code()
.value()
: OperationResultCode::DETAIL_SUCCESS);
operation_result_with_mediums.push_back(*operation_result_with_medium);
operation_result_with_mediums.push_back(
GetOperationResultWithMediumByResultCode(
client, BLUETOOTH, update_index,
bluetooth_result.has_error()
? bluetooth_result.error().operation_result_code().value()
: OperationResultCode::DETAIL_SUCCESS));
} else {
LOG(INFO) << "Pause bluetooth discovery for service id : "
<< service_id;
@@ -1993,14 +1936,12 @@ void P2pClusterPcpHandler::StartBluetoothDiscoveryWithPause(
bluetooth_classic_client_id_to_service_id_map_.insert(
{client->GetClientId(), service_id});
}
std::unique_ptr<ConnectionsLog::OperationResultWithMedium>
operation_result_with_medium =
GetOperationResultWithMediumByResultCode(
client, BLUETOOTH, update_index,
bluetooth_result.has_error()
? bluetooth_result.error().operation_result_code().value()
: OperationResultCode::DETAIL_SUCCESS);
operation_result_with_mediums.push_back(*operation_result_with_medium);
operation_result_with_mediums.push_back(
GetOperationResultWithMediumByResultCode(
client, BLUETOOTH, update_index,
bluetooth_result.has_error()
? bluetooth_result.error().operation_result_code().value()
: OperationResultCode::DETAIL_SUCCESS));
}
} else {
LOG(WARNING) << "Ignore to discover on bluetooth for service id: "
@@ -25,6 +25,7 @@
#include "absl/strings/string_view.h"
#include "connections/advertising_options.h"
#include "connections/discovery_options.h"
#include "connections/implementation/analytics/operation_result_with_medium.h"
#include "connections/implementation/base_pcp_handler.h"
#include "connections/implementation/ble_advertisement.h"
#include "connections/implementation/bluetooth_device_name.h"
@@ -207,8 +208,8 @@ class P2pClusterPcpHandler : public BasePcpHandler {
ClientProxy* client, const std::string& service_id,
const DiscoveryOptions& discovery_options,
std::vector<Medium>& mediums_started_successfully,
std::vector<location::nearby::analytics::proto::ConnectionsLog::
OperationResultWithMedium>& operation_result_with_mediums,
std::vector<nearby::analytics::OperationResultWithMedium>&
operation_result_with_mediums,
int update_index);
BasePcpHandler::ConnectImplResult BluetoothConnectImpl(
ClientProxy* client, BluetoothEndpoint* endpoint);
@@ -36,7 +36,6 @@
#include "connections/implementation/flags/nearby_connections_feature_flags.h"
#include "connections/implementation/internal_payload.h"
#include "connections/implementation/internal_payload_factory.h"
#include "connections/implementation/proto/offline_wire_formats.pb.h"
#include "connections/listeners.h"
#include "connections/medium_selector.h"
#include "connections/payload.h"
@@ -52,7 +51,6 @@
#include "internal/platform/logging.h"
#include "internal/platform/mutex_lock.h"
#include "internal/platform/single_thread_executor.h"
#include "proto/connections_enums.pb.h"
namespace nearby {
namespace connections {
+1
View File
@@ -389,6 +389,7 @@ cc_library(
"//connections:core",
"//connections:core_types",
"//connections/implementation:internal",
"//connections/implementation/analytics:analytics_recorder_impl",
"//internal/analytics:event_logger",
"//internal/base",
"//internal/base:file_path",
+4 -1
View File
@@ -31,6 +31,7 @@
#include "connections/connection_options.h"
#include "connections/core.h"
#include "connections/discovery_options.h"
#include "connections/implementation/analytics/analytics_recorder_impl.h"
#include "connections/implementation/service_controller_router.h"
#include "connections/listeners.h"
#include "connections/medium_selector.h"
@@ -51,6 +52,7 @@ namespace nearby {
namespace sharing {
namespace {
using ::nearby::analytics::AnalyticsRecorderImpl;
using ::nearby::connections::ConnectionRequestInfo;
using ::nearby::connections::ConnectionResponseInfo;
using ::nearby::connections::Core;
@@ -85,7 +87,8 @@ NearbyConnectionsServiceImpl::NearbyConnectionsServiceImpl(
// at an invalid instance.
return connectivity_manager_.IsHPRealtekDevice();
});
static Core* core = new Core(event_logger, router);
static Core* core =
new Core(std::make_unique<AnalyticsRecorderImpl>(event_logger), router);
service_handle_ = core;
}