Move third_party/nearby/cpp/analytics to third_party/nearby/internal/analytics.

PiperOrigin-RevId: 420135432
This commit is contained in:
suetfei
2022-01-06 13:47:33 -08:00
committed by Copybara-Service
parent cdcd37c616
commit acc6f2de9a
15 changed files with 20 additions and 20 deletions
-65
View File
@@ -1,65 +0,0 @@
licenses(["notice"])
# Copyright 2020 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.
cc_library(
name = "analytics",
srcs = [
"analytics_recorder.cc",
],
hdrs = [
"analytics_recorder.h",
"connection_attempt_metadata_params.h",
],
compatible_with = ["//buildenv/target:non_prod"],
copts = ["-DCORE_ADAPTER_DLL"],
visibility = [
"//core:__subpackages__",
"//proto/analytics:__subpackages__",
],
deps = [
"//absl/container:btree",
"//absl/time",
"//core:core_types",
"//core:event_logger",
"//platform/base",
"//platform/base:error_code_recorder",
"//platform/public:logging",
"//platform/public:types",
"//proto:connections_enums_portable_proto",
"//proto/analytics:connections_log_cc_proto",
"//proto/errorcode:error_code_enums_portable_proto",
],
)
cc_test(
name = "analytics_test",
size = "small",
srcs = [
"analytics_recorder_test.cc",
],
shard_count = 16,
deps = [
":analytics",
"//testing/base/public:gunit_main",
"//absl/time",
"//platform/base:error_code_recorder",
"//platform/impl/g3", # build_cleaner: keep
"//platform/public:comm",
"//platform/public:logging",
"//platform/public:types",
"//proto:connections_enums_portable_proto",
"//proto/analytics:connections_log_cc_proto",
],
)
File diff suppressed because it is too large Load Diff
-369
View File
@@ -1,369 +0,0 @@
// Copyright 2020 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_ANALYTICS_RECORDER_H_
#define ANALYTICS_ANALYTICS_RECORDER_H_
#include <string>
#include "absl/container/btree_map.h"
#include "absl/time/time.h"
#include "third_party/nearby/cpp/analytics/connection_attempt_metadata_params.h"
#include "core/event_logger.h"
#include "core/payload.h"
#include "core/strategy.h"
#include "platform/base/error_code_params.h"
#include "platform/public/mutex.h"
#include "platform/public/single_thread_executor.h"
#include "proto/analytics/connections_log.pb.h"
#include "proto/connections_enums.pb.h"
namespace location {
namespace nearby {
namespace analytics {
class AnalyticsRecorder {
public:
explicit AnalyticsRecorder(EventLogger *event_logger);
virtual ~AnalyticsRecorder();
// TODO(edwinwu): Implement to pass real values for AdvertisingMetadata and
// DiscoveryMetaData: is_extended_advertisement_supported,
// connected_ap_frequency, and is_nfc_available. Set as default values for
// analytics recorder.
// Advertising phase
void OnStartAdvertising(
connections::Strategy strategy,
const std::vector<location::nearby::proto::connections::Medium> &mediums,
bool is_extended_advertisement_supported = false,
int connected_ap_frequency = 0, bool is_nfc_available = false)
ABSL_LOCKS_EXCLUDED(mutex_);
void OnStopAdvertising() ABSL_LOCKS_EXCLUDED(mutex_);
// Discovery phase
void OnStartDiscovery(
connections::Strategy strategy,
const std::vector<location::nearby::proto::connections::Medium> &mediums,
bool is_extended_advertisement_supported = false,
int connected_ap_frequency = 0, bool is_nfc_available = false)
ABSL_LOCKS_EXCLUDED(mutex_);
void OnStopDiscovery() ABSL_LOCKS_EXCLUDED(mutex_);
void OnEndpointFound(location::nearby::proto::connections::Medium medium)
ABSL_LOCKS_EXCLUDED(mutex_);
// Connection request
void OnConnectionRequestReceived(const std::string &remote_endpoint_id)
ABSL_LOCKS_EXCLUDED(mutex_);
void OnConnectionRequestSent(const std::string &remote_endpoint_id)
ABSL_LOCKS_EXCLUDED(mutex_);
void OnRemoteEndpointAccepted(const std::string &remote_endpoint_id)
ABSL_LOCKS_EXCLUDED(mutex_);
void OnLocalEndpointAccepted(const std::string &remote_endpoint_id)
ABSL_LOCKS_EXCLUDED(mutex_);
void OnRemoteEndpointRejected(const std::string &remote_endpoint_id)
ABSL_LOCKS_EXCLUDED(mutex_);
void OnLocalEndpointRejected(const std::string &remote_endpoint_id)
ABSL_LOCKS_EXCLUDED(mutex_);
// 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)
ABSL_LOCKS_EXCLUDED(mutex_);
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)
ABSL_LOCKS_EXCLUDED(mutex_);
// TODO(edwinwu): Implement network operator, country code, tdls, wifi hotspot
//, max wifi tx/rx speed and channel width. Set as default values for
// analytics recorder.
static std::unique_ptr<ConnectionAttemptMetadataParams>
BuildConnectionAttemptMetadataParams(
location::nearby::proto::connections::ConnectionTechnology technology,
location::nearby::proto::connections::ConnectionBand band, int frequency,
int try_count, const std::string &network_operator = {},
const std::string &country_code = {}, bool is_tdls_used = false,
bool wifi_hotspot_enabled = false, int max_wifi_tx_speed = 0,
int max_wifi_rx_speed = 0, int channel_width = -1);
// Connection established
void OnConnectionEstablished(
const std::string &endpoint_id,
location::nearby::proto::connections::Medium medium,
const std::string &connection_token) ABSL_LOCKS_EXCLUDED(mutex_);
void OnConnectionClosed(
const std::string &endpoint_id,
location::nearby::proto::connections::Medium medium,
location::nearby::proto::connections ::DisconnectionReason reason)
ABSL_LOCKS_EXCLUDED(mutex_);
// Payload
void OnIncomingPayloadStarted(const std::string &endpoint_id,
std::int64_t payload_id,
connections::Payload::Type type,
std::int64_t total_size_bytes)
ABSL_LOCKS_EXCLUDED(mutex_);
void OnPayloadChunkReceived(const std::string &endpoint_id,
std::int64_t payload_id,
std::int64_t chunk_size_bytes)
ABSL_LOCKS_EXCLUDED(mutex_);
void OnIncomingPayloadDone(
const std::string &endpoint_id, std::int64_t payload_id,
location::nearby::proto::connections::PayloadStatus status)
ABSL_LOCKS_EXCLUDED(mutex_);
void OnOutgoingPayloadStarted(const std::vector<std::string> &endpoint_ids,
std::int64_t payload_id,
connections::Payload::Type type,
std::int64_t total_size_bytes)
ABSL_LOCKS_EXCLUDED(mutex_);
void OnPayloadChunkSent(const std::string &endpoint_id,
std::int64_t payload_id,
std::int64_t chunk_size_bytes)
ABSL_LOCKS_EXCLUDED(mutex_);
void OnOutgoingPayloadDone(
const std::string &endpoint_id, std::int64_t payload_id,
location::nearby::proto::connections::PayloadStatus status)
ABSL_LOCKS_EXCLUDED(mutex_);
// 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) ABSL_LOCKS_EXCLUDED(mutex_);
void OnBandwidthUpgradeError(
const std::string &endpoint_id,
location::nearby::proto::connections::BandwidthUpgradeResult result,
location::nearby::proto::connections::BandwidthUpgradeErrorStage
error_stage) ABSL_LOCKS_EXCLUDED(mutex_);
void OnBandwidthUpgradeSuccess(const std::string &endpoint_id)
ABSL_LOCKS_EXCLUDED(mutex_);
// Error Code
void OnErrorCode(const ErrorCodeParams &params);
// Invokes event_logger_.Log() at the end of life of client. Log action is
// called in a separate thread to allow synchronous potentially lengthy
// execution.
void LogSession() ABSL_LOCKS_EXCLUDED(mutex_);
private:
// Tracks the chunks and duration of a Payload on a particular medium.
class PendingPayload {
public:
PendingPayload(location::nearby::proto::connections::PayloadType type,
std::int64_t total_size_bytes)
: start_time_(SystemClock::ElapsedRealtime()),
type_(type),
total_size_bytes_(total_size_bytes),
num_bytes_transferred_(0),
num_chunks_(0) {}
~PendingPayload() = default;
void AddChunk(std::int64_t chunk_size_bytes);
proto::ConnectionsLog::Payload GetProtoPayload(
location::nearby::proto::connections::PayloadStatus status);
location::nearby::proto::connections::PayloadType type() const {
return type_;
}
std::int64_t total_size_bytes() const { return total_size_bytes_; }
private:
absl::Time start_time_;
location::nearby::proto::connections::PayloadType type_;
std::int64_t total_size_bytes_;
std::int64_t num_bytes_transferred_;
int num_chunks_;
};
class LogicalConnection {
public:
LogicalConnection(
location::nearby::proto::connections::Medium initial_medium,
const std::string &connection_token) {
PhysicalConnectionEstablished(initial_medium, connection_token);
}
LogicalConnection(const LogicalConnection &) = delete;
LogicalConnection(LogicalConnection &&other)
: current_medium_(std::move(other.current_medium_)),
physical_connections_(std::move(other.physical_connections_)),
incoming_payloads_(std::move(other.incoming_payloads_)),
outgoing_payloads_(std::move(other.outgoing_payloads_)) {}
LogicalConnection &operator=(const LogicalConnection &) = delete;
LogicalConnection &&operator=(LogicalConnection &&) = delete;
~LogicalConnection() = default;
void PhysicalConnectionEstablished(
location::nearby::proto::connections::Medium medium,
const std::string &connection_token);
void PhysicalConnectionClosed(
location::nearby::proto::connections::Medium medium,
location::nearby::proto::connections::DisconnectionReason reason);
void CloseAllPhysicalConnections();
void IncomingPayloadStarted(
std::int64_t payload_id,
location::nearby::proto::connections::PayloadType type,
std::int64_t total_size_bytes);
void ChunkReceived(std::int64_t payload_id, std::int64_t size_bytes);
void IncomingPayloadDone(
std::int64_t payload_id,
location::nearby::proto::connections::PayloadStatus status);
void OutgoingPayloadStarted(
std::int64_t payload_id,
location::nearby::proto::connections::PayloadType type,
std::int64_t total_size_bytes);
void ChunkSent(std::int64_t payload_id, std::int64_t size_bytes);
void OutgoingPayloadDone(
std::int64_t payload_id,
location::nearby::proto::connections::PayloadStatus status);
std::vector<proto::ConnectionsLog::EstablishedConnection>
GetEstablisedConnections();
private:
void FinishPhysicalConnection(
proto::ConnectionsLog::EstablishedConnection *established_connection,
location::nearby::proto::connections::DisconnectionReason reason);
std::vector<proto::ConnectionsLog::Payload> ResolvePendingPayloads(
absl::btree_map<std::int64_t, std::unique_ptr<PendingPayload>>
&pending_payloads,
location::nearby::proto::connections::DisconnectionReason reason);
location::nearby::proto::connections::Medium current_medium_ =
location::nearby::proto::connections::UNKNOWN_MEDIUM;
absl::btree_map<
location::nearby::proto::connections::Medium,
std::unique_ptr<proto::ConnectionsLog::EstablishedConnection>>
physical_connections_;
absl::btree_map<std::int64_t, std::unique_ptr<PendingPayload>>
incoming_payloads_;
absl::btree_map<std::int64_t, std::unique_ptr<PendingPayload>>
outgoing_payloads_;
};
bool CanRecordAnalyticsLocked(const std::string &method_name)
ABSL_SHARED_LOCKS_REQUIRED(mutex_);
// Callbacks the ConnectionsLog proto byte array data to the EventLogger with
// ClientSession sub-proto.
void LogClientSession();
// Callbacks the ConnectionsLog proto byte array data to the EventLogger.
void LogEvent(location::nearby::proto::connections::EventType event_type);
void UpdateStrategySessionLocked(
connections::Strategy strategy,
location::nearby::proto::connections::SessionRole role)
ABSL_EXCLUSIVE_LOCKS_REQUIRED(mutex_);
void RecordAdvertisingPhaseDurationLocked() const
ABSL_SHARED_LOCKS_REQUIRED(mutex_);
void FinishAdvertisingPhaseLocked() ABSL_EXCLUSIVE_LOCKS_REQUIRED(mutex_);
void RecordDiscoveryPhaseDurationLocked() const
ABSL_SHARED_LOCKS_REQUIRED(mutex_);
void FinishDiscoveryPhaseLocked() ABSL_EXCLUSIVE_LOCKS_REQUIRED(mutex_);
bool UpdateAdvertiserConnectionRequestLocked(
proto::ConnectionsLog::ConnectionRequest *request)
ABSL_SHARED_LOCKS_REQUIRED(mutex_);
bool UpdateDiscovererConnectionRequestLocked(
proto::ConnectionsLog::ConnectionRequest *request)
ABSL_SHARED_LOCKS_REQUIRED(mutex_);
bool BothEndpointsRespondedLocked(
proto::ConnectionsLog::ConnectionRequest *request)
ABSL_SHARED_LOCKS_REQUIRED(mutex_);
void LocalEndpointRespondedLocked(
const std::string &remote_endpoint_id,
location::nearby::proto::connections::ConnectionRequestResponse response)
ABSL_EXCLUSIVE_LOCKS_REQUIRED(mutex_);
void RemoteEndpointRespondedLocked(
const std::string &remote_endpoint_id,
location::nearby::proto::connections::ConnectionRequestResponse response)
ABSL_EXCLUSIVE_LOCKS_REQUIRED(mutex_);
void MarkConnectionRequestIgnoredLocked(
proto::ConnectionsLog::ConnectionRequest *request)
ABSL_SHARED_LOCKS_REQUIRED(mutex_);
void FinishUpgradeAttemptLocked(
const std::string &endpoint_id,
location::nearby::proto::connections::BandwidthUpgradeResult result,
location::nearby::proto::connections::BandwidthUpgradeErrorStage
error_stage,
bool erase_item = true) ABSL_SHARED_LOCKS_REQUIRED(mutex_);
void FinishStrategySessionLocked() ABSL_EXCLUSIVE_LOCKS_REQUIRED(mutex_);
location::nearby::proto::connections::ConnectionsStrategy
StrategyToConnectionStrategy(connections::Strategy strategy);
location::nearby::proto::connections::PayloadType
PayloadTypeToProtoPayloadType(connections::Payload::Type type);
// Not owned by AnalyticsRecorder. Pointer must refer to a valid object
// that outlives the one constructed.
EventLogger *event_logger_;
SingleThreadExecutor serial_executor_;
// Protects all sub-protos reading and writing in ConnectionLog.
Mutex mutex_;
// ClientSession
std::unique_ptr<proto::ConnectionsLog::ClientSession> client_session_ =
absl::make_unique<proto::ConnectionsLog::ClientSession>();
absl::Time started_client_session_time_;
bool session_was_logged_ ABSL_GUARDED_BY(mutex_) = false;
// Current StrategySession
connections::Strategy current_strategy_ ABSL_GUARDED_BY(mutex_) =
connections::Strategy::kNone;
std::unique_ptr<proto::ConnectionsLog::StrategySession>
current_strategy_session_ ABSL_GUARDED_BY(mutex_);
absl::Time started_strategy_session_time_ ABSL_GUARDED_BY(mutex_);
// Current AdvertisingPhase
std::unique_ptr<proto::ConnectionsLog::AdvertisingPhase>
current_advertising_phase_;
absl::Time started_advertising_phase_time_;
// Current DiscoveryPhase
std::unique_ptr<proto::ConnectionsLog::DiscoveryPhase>
current_discovery_phase_;
absl::Time started_discovery_phase_time_;
absl::btree_map<std::string,
std::unique_ptr<proto::ConnectionsLog::ConnectionRequest>>
incoming_connection_requests_ ABSL_GUARDED_BY(mutex_);
absl::btree_map<std::string,
std::unique_ptr<proto::ConnectionsLog::ConnectionRequest>>
outgoing_connection_requests_ ABSL_GUARDED_BY(mutex_);
absl::btree_map<std::string, std::unique_ptr<LogicalConnection>>
active_connections_ ABSL_GUARDED_BY(mutex_);
absl::btree_map<
std::string,
std::unique_ptr<proto::ConnectionsLog::BandwidthUpgradeAttempt>>
bandwidth_upgrade_attempts_ ABSL_GUARDED_BY(mutex_);
};
} // namespace analytics
} // namespace nearby
} // namespace location
#endif // ANALYTICS_ANALYTICS_RECORDER_H_
-940
View File
@@ -1,940 +0,0 @@
// Copyright 2020 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.
#include "third_party/nearby/cpp/analytics/analytics_recorder.h"
#include <string>
#include <utility>
#include "gmock/gmock.h"
#include "gtest/gtest.h"
#include "absl/time/time.h"
#include "third_party/nearby/cpp/analytics/connection_attempt_metadata_params.h"
#include "platform/base/error_code_params.h"
#include "platform/base/error_code_recorder.h"
#include "platform/public/count_down_latch.h"
#include "platform/public/logging.h"
#include "proto/analytics/connections_log.pb.h"
#include "proto/connections_enums.pb.h"
namespace location {
namespace nearby {
namespace analytics {
namespace {
using ::location::nearby::analytics::proto::ConnectionsLog;
using ::location::nearby::errorcode::proto::DISCONNECT;
using ::location::nearby::errorcode::proto::DISCONNECT_NETWORK_FAILED;
using ::location::nearby::errorcode::proto::INVALID_PARAMETER;
using ::location::nearby::errorcode::proto::NULL_BLUETOOTH_DEVICE_NAME;
using ::location::nearby::errorcode::proto::START_DISCOVERING;
using ::location::nearby::errorcode::proto::START_EXTENDED_DISCOVERING_FAILED;
using ::location::nearby::errorcode::proto::
TACHYON_SEND_MESSAGE_STATUS_EXCEPTION;
using ::location::nearby::proto::connections::BLE;
using ::location::nearby::proto::connections::BLUETOOTH;
using ::location::nearby::proto::connections::CLIENT_SESSION;
using ::location::nearby::proto::connections::ERROR_CODE;
using ::location::nearby::proto::connections::EventType;
using ::location::nearby::proto::connections::INCOMING;
using ::location::nearby::proto::connections::INITIAL;
using ::location::nearby::proto::connections::LOCAL_DISCONNECTION;
using ::location::nearby::proto::connections::Medium;
using ::location::nearby::proto::connections::RESULT_ERROR;
using ::location::nearby::proto::connections::RESULT_SUCCESS;
using ::location::nearby::proto::connections::START_STRATEGY_SESSION;
using ::location::nearby::proto::connections::STOP_CLIENT_SESSION;
using ::location::nearby::proto::connections::STOP_STRATEGY_SESSION;
using ::location::nearby::proto::connections::SUCCESS;
using ::location::nearby::proto::connections::UPGRADED;
using ::location::nearby::proto::connections::WEB_RTC;
using ::location::nearby::proto::connections::WIFI_LAN;
using ::location::nearby::proto::connections::WIFI_LAN_MEDIUM_ERROR;
using ::location::nearby::proto::connections::WIFI_LAN_SOCKET_CREATION;
using ::testing::Contains;
using ::testing::EqualsProto;
using ::testing::proto::Partially;
constexpr absl::Duration kDefaultTimeout = absl::Milliseconds(1000);
class FakeEventLogger : public EventLogger {
public:
explicit FakeEventLogger(CountDownLatch& client_session_done_latch)
: client_session_done_latch_(client_session_done_latch) {}
void Log(const ConnectionsLog& connections_log) override {
EventType event_type = connections_log.event_type();
logged_event_types_.push_back(event_type);
if (event_type == CLIENT_SESSION) {
logged_client_session_count_++;
logged_client_session_ = connections_log.client_session();
}
if (event_type == ERROR_CODE) {
error_code_ = connections_log.error_code();
}
if (event_type == STOP_CLIENT_SESSION) {
client_session_done_latch_.CountDown();
}
}
int GetLoggedClientSessionCount() const {
return logged_client_session_count_;
}
const ConnectionsLog::ClientSession& GetLoggedClientSession() {
return logged_client_session_;
}
const ConnectionsLog::ErrorCode& GetErrorCode() { return error_code_; }
std::vector<EventType> GetLoggedEventTypes() { return logged_event_types_; }
private:
int logged_client_session_count_ = 0;
CountDownLatch& client_session_done_latch_;
ConnectionsLog::ClientSession logged_client_session_;
ConnectionsLog::ErrorCode error_code_;
std::vector<EventType> logged_event_types_;
};
TEST(AnalyticsRecorderTest, SessionOnlyLoggedOnceWorks) {
CountDownLatch client_session_done_latch(1);
FakeEventLogger event_logger(client_session_done_latch);
AnalyticsRecorder analytics_recorder(&event_logger);
analytics_recorder.LogSession();
analytics_recorder.LogSession();
analytics_recorder.LogSession();
analytics_recorder.LogSession();
ASSERT_TRUE(client_session_done_latch.Await(kDefaultTimeout).result());
// Only called once.
EXPECT_EQ(event_logger.GetLoggedClientSessionCount(), 1);
}
TEST(AnalyticsRecorderTest, SetFieldsCorrectlyForNestedAdvertisingCalls) {
connections::Strategy strategy = connections::Strategy::kP2pStar;
std::vector<Medium> mediums = {BLE, BLUETOOTH};
CountDownLatch client_session_done_latch(1);
FakeEventLogger event_logger(client_session_done_latch);
AnalyticsRecorder analytics_recorder(&event_logger);
analytics_recorder.OnStartAdvertising(strategy, mediums);
analytics_recorder.OnStopAdvertising();
analytics_recorder.OnStartAdvertising(strategy, {BLUETOOTH});
analytics_recorder.LogSession();
ASSERT_TRUE(client_session_done_latch.Await(kDefaultTimeout).result());
EXPECT_THAT(event_logger.GetLoggedClientSession(), Partially(EqualsProto(R"pb(
strategy_session <
strategy: P2P_STAR
role: ADVERTISER
advertising_phase <
medium: BLE
medium: BLUETOOTH
advertising_metadata <
supports_extended_ble_advertisements: false
connected_ap_frequency: 0
supports_nfc_technology: false
>
>
advertising_phase <
medium: BLUETOOTH
advertising_metadata <
supports_extended_ble_advertisements: false
connected_ap_frequency: 0
supports_nfc_technology: false
>
>
>)pb")));
}
TEST(AnalyticsRecorderTest, SetFieldsCorrectlyForNestedDiscoveryCalls) {
connections::Strategy strategy = connections::Strategy::kP2pStar;
std::vector<Medium> mediums = {BLE, BLUETOOTH};
CountDownLatch client_session_done_latch(1);
FakeEventLogger event_logger(client_session_done_latch);
AnalyticsRecorder analytics_recorder(&event_logger);
analytics_recorder.OnStartDiscovery(strategy, mediums, true, 1, false);
analytics_recorder.OnStopDiscovery();
analytics_recorder.OnEndpointFound(BLUETOOTH);
analytics_recorder.OnEndpointFound(BLE);
analytics_recorder.OnStartDiscovery(strategy, {BLUETOOTH}, true, 1, false);
analytics_recorder.LogSession();
ASSERT_TRUE(client_session_done_latch.Await(kDefaultTimeout).result());
EXPECT_THAT(event_logger.GetLoggedClientSession(), Partially(EqualsProto(R"pb(
strategy_session <
strategy: P2P_STAR
role: DISCOVERER
discovery_phase <
medium: BLE
medium: BLUETOOTH
discovered_endpoint < medium: BLUETOOTH >
discovered_endpoint < medium: BLE >
discovery_metadata <
supports_extended_ble_advertisements: true
connected_ap_frequency: 1
supports_nfc_technology: false
>
>
discovery_phase <
medium: BLUETOOTH
discovery_metadata <
supports_extended_ble_advertisements: true
connected_ap_frequency: 1
supports_nfc_technology: false
>
>
>)pb")));
}
TEST(AnalyticsRecorderTest,
OneStrategySessionForMultipleRoundsOfDiscoveryAdvertising) {
connections::Strategy strategy = connections::Strategy::kP2pStar;
std::vector<Medium> mediums = {BLE, BLUETOOTH};
CountDownLatch client_session_done_latch(1);
FakeEventLogger event_logger(client_session_done_latch);
AnalyticsRecorder analytics_recorder(&event_logger);
analytics_recorder.OnStartAdvertising(strategy, mediums);
analytics_recorder.OnStartDiscovery(strategy, mediums);
analytics_recorder.OnStopAdvertising();
analytics_recorder.OnStopDiscovery();
analytics_recorder.OnStartAdvertising(strategy, mediums);
analytics_recorder.OnStopAdvertising();
analytics_recorder.OnStartDiscovery(strategy, mediums);
analytics_recorder.OnStopDiscovery();
analytics_recorder.OnStartDiscovery(strategy, mediums);
analytics_recorder.OnStartAdvertising(strategy, mediums);
analytics_recorder.OnStopDiscovery();
analytics_recorder.OnStopAdvertising();
analytics_recorder.LogSession();
ASSERT_TRUE(client_session_done_latch.Await(kDefaultTimeout).result());
std::vector<EventType> event_types = event_logger.GetLoggedEventTypes();
EXPECT_THAT(event_types, Contains(START_STRATEGY_SESSION).Times(1));
EXPECT_THAT(event_types, Contains(STOP_STRATEGY_SESSION).Times(1));
EXPECT_THAT(event_logger.GetLoggedClientSession(), Partially(EqualsProto(R"pb(
strategy_session <
strategy: P2P_STAR
role: ADVERTISER
role: DISCOVERER
discovery_phase <
medium: BLE
medium: BLUETOOTH
discovery_metadata <
supports_extended_ble_advertisements: false
connected_ap_frequency: 0
supports_nfc_technology: false
>
>
discovery_phase <
medium: BLE
medium: BLUETOOTH
discovery_metadata <
supports_extended_ble_advertisements: false
connected_ap_frequency: 0
supports_nfc_technology: false
>
>
discovery_phase <
medium: BLE
medium: BLUETOOTH
discovery_metadata <
supports_extended_ble_advertisements: false
connected_ap_frequency: 0
supports_nfc_technology: false
>
>
advertising_phase <
medium: BLE
medium: BLUETOOTH
advertising_metadata <
supports_extended_ble_advertisements: false
connected_ap_frequency: 0
supports_nfc_technology: false
>
>
advertising_phase <
medium: BLE
medium: BLUETOOTH
advertising_metadata <
supports_extended_ble_advertisements: false
connected_ap_frequency: 0
supports_nfc_technology: false
>
>
advertising_phase <
medium: BLE
medium: BLUETOOTH
advertising_metadata <
supports_extended_ble_advertisements: false
connected_ap_frequency: 0
supports_nfc_technology: false
>
>
>)pb")));
}
TEST(AnalyticsRecorderTest, AdvertiserConnectionRequestsWorks) {
connections::Strategy strategy = connections::Strategy::kP2pStar;
std::vector<Medium> mediums = {BLE, BLUETOOTH};
std::string endpoint_id_0 = "endpoint_id_0";
std::string endpoint_id_1 = "endpoint_id_1";
std::string endpoint_id_2 = "endpoint_id_2";
std::string endpoint_id_3 = "endpoint_id_3";
CountDownLatch client_session_done_latch(1);
FakeEventLogger event_logger(client_session_done_latch);
AnalyticsRecorder analytics_recorder(&event_logger);
analytics_recorder.OnStartAdvertising(strategy, mediums);
analytics_recorder.OnConnectionRequestReceived(endpoint_id_0);
analytics_recorder.OnLocalEndpointAccepted(endpoint_id_0);
analytics_recorder.OnRemoteEndpointAccepted(endpoint_id_0);
analytics_recorder.OnConnectionRequestReceived(endpoint_id_1);
analytics_recorder.OnLocalEndpointAccepted(endpoint_id_1);
analytics_recorder.OnRemoteEndpointRejected(endpoint_id_1);
analytics_recorder.OnConnectionRequestReceived(endpoint_id_2);
analytics_recorder.OnLocalEndpointRejected(endpoint_id_2);
analytics_recorder.OnRemoteEndpointAccepted(endpoint_id_2);
analytics_recorder.OnConnectionRequestReceived(endpoint_id_3);
analytics_recorder.OnLocalEndpointRejected(endpoint_id_3);
analytics_recorder.OnRemoteEndpointRejected(endpoint_id_3);
analytics_recorder.LogSession();
ASSERT_TRUE(client_session_done_latch.Await(kDefaultTimeout).result());
EXPECT_THAT(event_logger.GetLoggedClientSession(), Partially(EqualsProto(R"pb(
strategy_session <
strategy: P2P_STAR
role: ADVERTISER
advertising_phase <
medium: BLE
medium: BLUETOOTH
advertising_metadata <
supports_extended_ble_advertisements: false
connected_ap_frequency: 0
supports_nfc_technology: false
>
received_connection_request <
local_response: ACCEPTED
remote_response: ACCEPTED
>
received_connection_request <
local_response: ACCEPTED
remote_response: REJECTED
>
received_connection_request <
local_response: REJECTED
remote_response: ACCEPTED
>
received_connection_request <
local_response: REJECTED
remote_response: REJECTED
>
>
>)pb")));
}
TEST(AnalyticsRecorderTest, DiscoveryConnectionRequestsWorks) {
connections::Strategy strategy = connections::Strategy::kP2pStar;
std::vector<Medium> mediums = {BLE, BLUETOOTH};
std::string endpoint_id_0 = "endpoint_id_0";
std::string endpoint_id_1 = "endpoint_id_1";
std::string endpoint_id_2 = "endpoint_id_2";
std::string endpoint_id_3 = "endpoint_id_3";
CountDownLatch client_session_done_latch(1);
FakeEventLogger event_logger(client_session_done_latch);
AnalyticsRecorder analytics_recorder(&event_logger);
analytics_recorder.OnStartDiscovery(strategy, mediums);
analytics_recorder.OnConnectionRequestSent(endpoint_id_0);
analytics_recorder.OnLocalEndpointAccepted(endpoint_id_0);
analytics_recorder.OnRemoteEndpointAccepted(endpoint_id_0);
analytics_recorder.OnConnectionRequestSent(endpoint_id_1);
analytics_recorder.OnLocalEndpointAccepted(endpoint_id_1);
analytics_recorder.OnRemoteEndpointRejected(endpoint_id_1);
analytics_recorder.OnConnectionRequestSent(endpoint_id_2);
analytics_recorder.OnLocalEndpointRejected(endpoint_id_2);
analytics_recorder.OnRemoteEndpointAccepted(endpoint_id_2);
analytics_recorder.OnConnectionRequestSent(endpoint_id_3);
analytics_recorder.OnLocalEndpointRejected(endpoint_id_3);
analytics_recorder.OnRemoteEndpointRejected(endpoint_id_3);
analytics_recorder.LogSession();
ASSERT_TRUE(client_session_done_latch.Await(kDefaultTimeout).result());
EXPECT_THAT(event_logger.GetLoggedClientSession(), Partially(EqualsProto(R"pb(
strategy_session <
strategy: P2P_STAR
role: DISCOVERER
discovery_phase <
medium: BLE
medium: BLUETOOTH
discovery_metadata <
supports_extended_ble_advertisements: false
connected_ap_frequency: 0
supports_nfc_technology: false
>
sent_connection_request <
local_response: ACCEPTED
remote_response: ACCEPTED
>
sent_connection_request <
local_response: ACCEPTED
remote_response: REJECTED
>
sent_connection_request <
local_response: REJECTED
remote_response: ACCEPTED
>
sent_connection_request <
local_response: REJECTED
remote_response: REJECTED
>
>
>)pb")));
}
TEST(AnalyticsRecorderTest,
AdvertiserUnfinishedConnectionRequestsIncludedAsIgnored) {
connections::Strategy strategy = connections::Strategy::kP2pStar;
std::vector<Medium> mediums = {BLE, BLUETOOTH};
std::string endpoint_id_0 = "endpoint_id_0";
std::string endpoint_id_1 = "endpoint_id_1";
std::string endpoint_id_2 = "endpoint_id_2";
CountDownLatch client_session_done_latch(1);
FakeEventLogger event_logger(client_session_done_latch);
AnalyticsRecorder analytics_recorder(&event_logger);
analytics_recorder.OnStartAdvertising(strategy, mediums);
// Ignored by local.
analytics_recorder.OnConnectionRequestReceived(endpoint_id_0);
analytics_recorder.OnRemoteEndpointAccepted(endpoint_id_0);
// Ignored by remote.
analytics_recorder.OnConnectionRequestReceived(endpoint_id_1);
analytics_recorder.OnLocalEndpointAccepted(endpoint_id_1);
// Ignored by both.
analytics_recorder.OnConnectionRequestReceived(endpoint_id_2);
analytics_recorder.LogSession();
ASSERT_TRUE(client_session_done_latch.Await(kDefaultTimeout).result());
EXPECT_THAT(event_logger.GetLoggedClientSession(), Partially(EqualsProto(R"pb(
strategy_session <
strategy: P2P_STAR
role: ADVERTISER
advertising_phase <
medium: BLE
medium: BLUETOOTH
advertising_metadata <
supports_extended_ble_advertisements: false
connected_ap_frequency: 0
supports_nfc_technology: false
>
received_connection_request <
local_response: IGNORED
remote_response: ACCEPTED
>
received_connection_request <
local_response: ACCEPTED
remote_response: IGNORED
>
received_connection_request <
local_response: IGNORED
remote_response: IGNORED
>
>
>)pb")));
}
TEST(AnalyticsRecorderTest,
DiscovererUnfinishedConnectionRequestsIncludedAsIgnored) {
connections::Strategy strategy = connections::Strategy::kP2pStar;
std::vector<Medium> mediums = {BLE, BLUETOOTH};
std::string endpoint_id_0 = "endpoint_id_0";
std::string endpoint_id_1 = "endpoint_id_1";
std::string endpoint_id_2 = "endpoint_id_2";
CountDownLatch client_session_done_latch(1);
FakeEventLogger event_logger(client_session_done_latch);
AnalyticsRecorder analytics_recorder(&event_logger);
analytics_recorder.OnStartDiscovery(strategy, mediums);
// Ignored by local.
analytics_recorder.OnConnectionRequestSent(endpoint_id_0);
analytics_recorder.OnRemoteEndpointAccepted(endpoint_id_0);
// Ignored by remote.
analytics_recorder.OnConnectionRequestSent(endpoint_id_1);
analytics_recorder.OnLocalEndpointAccepted(endpoint_id_1);
// Ignored by both.
analytics_recorder.OnConnectionRequestSent(endpoint_id_2);
analytics_recorder.LogSession();
ASSERT_TRUE(client_session_done_latch.Await(kDefaultTimeout).result());
EXPECT_THAT(event_logger.GetLoggedClientSession(), Partially(EqualsProto(R"pb(
strategy_session <
strategy: P2P_STAR
role: DISCOVERER
discovery_phase <
medium: BLE
medium: BLUETOOTH
discovery_metadata <
supports_extended_ble_advertisements: false
connected_ap_frequency: 0
supports_nfc_technology: false
>
sent_connection_request <
local_response: IGNORED
remote_response: ACCEPTED
>
sent_connection_request <
local_response: ACCEPTED
remote_response: IGNORED
>
sent_connection_request <
local_response: IGNORED
remote_response: IGNORED
>
>
>)pb")));
}
TEST(AnalyticsRecorderTest, SuccessfulIncomingConnectionAttempt) {
connections::Strategy strategy = connections::Strategy::kP2pStar;
std::vector<Medium> mediums = {BLE, BLUETOOTH};
std::string endpoint_id = "endpoint_id";
std::string connection_token = "";
CountDownLatch client_session_done_latch(1);
FakeEventLogger event_logger(client_session_done_latch);
AnalyticsRecorder analytics_recorder{&event_logger};
analytics_recorder.OnStartAdvertising(strategy, mediums);
analytics_recorder.OnIncomingConnectionAttempt(
INITIAL, BLUETOOTH, RESULT_SUCCESS, absl::Duration{}, connection_token,
nullptr);
analytics_recorder.OnStopAdvertising();
analytics_recorder.LogSession();
ASSERT_TRUE(client_session_done_latch.Await(kDefaultTimeout).result());
EXPECT_THAT(event_logger.GetLoggedClientSession(), Partially(EqualsProto(R"pb(
strategy_session <
strategy: P2P_STAR
role: ADVERTISER
advertising_phase <
medium: BLE
medium: BLUETOOTH
advertising_metadata <
supports_extended_ble_advertisements: false
connected_ap_frequency: 0
supports_nfc_technology: false
>
>
connection_attempt <
type: INITIAL
direction: INCOMING
medium: BLUETOOTH
attempt_result: RESULT_SUCCESS
connection_token: ""
connection_attempt_metadata <
technology: CONNECTION_TECHNOLOGY_UNKNOWN_TECHNOLOGY
band: CONNECTION_BAND_UNKNOWN_BAND
frequency: -1
network_operator: ""
country_code: ""
is_tdls_used: false
try_counts: 0
wifi_hotspot_status: false
max_tx_speed: 0
max_rx_speed: 0
wifi_channel_width: -1
>
>
>)pb")));
}
TEST(AnalyticsRecorderTest,
FailedConnectionAttemptUpdatesConnectionRequestNotSent) {
connections::Strategy strategy = connections::Strategy::kP2pStar;
std::vector<Medium> mediums = {BLE, BLUETOOTH};
std::string endpoint_id = "endpoint_id";
std::string connection_token = "";
CountDownLatch client_session_done_latch(1);
FakeEventLogger event_logger(client_session_done_latch);
AnalyticsRecorder analytics_recorder(&event_logger);
auto connections_attempt_metadata_params =
analytics_recorder.BuildConnectionAttemptMetadataParams(
::location::nearby::proto::connections::
CONNECTION_TECHNOLOGY_HOTSPOT_LOCALONLY,
::location::nearby::proto::connections::
CONNECTION_BAND_WIFI_BAND_6GHZ,
/*frequency*/ 2400, /*try_count*/ 0, /*network_operator*/ {},
/*country_code*/ {}, /*is_tdls_used*/ false,
/*wifi_hotspot_enabled*/ false, /*max_wifi_tx_speed*/ 0,
/*max_wifi_rx_speed*/ 0, /*channel_width*/ 0);
analytics_recorder.OnStartDiscovery(strategy, mediums);
analytics_recorder.OnConnectionRequestSent(endpoint_id);
analytics_recorder.OnOutgoingConnectionAttempt(
endpoint_id, INITIAL, BLUETOOTH, RESULT_ERROR, absl::Duration{},
connection_token, connections_attempt_metadata_params.get());
analytics_recorder.LogSession();
ASSERT_TRUE(client_session_done_latch.Await(kDefaultTimeout).result());
EXPECT_THAT(event_logger.GetLoggedClientSession(), Partially(EqualsProto(R"pb(
strategy_session <
strategy: P2P_STAR
role: DISCOVERER
discovery_phase <
medium: BLE
medium: BLUETOOTH
discovery_metadata <
supports_extended_ble_advertisements: false
connected_ap_frequency: 0
supports_nfc_technology: false
>
sent_connection_request <
local_response: NOT_SENT
remote_response: NOT_SENT
>
>
connection_attempt <
type: INITIAL
direction: OUTGOING
medium: BLUETOOTH
attempt_result: RESULT_ERROR
connection_token: ""
connection_attempt_metadata <
technology: CONNECTION_TECHNOLOGY_HOTSPOT_LOCALONLY
band: CONNECTION_BAND_WIFI_BAND_6GHZ
frequency: 2400
network_operator: ""
country_code: ""
is_tdls_used: false
try_counts: 0
wifi_hotspot_status: false
max_tx_speed: 0
max_rx_speed: 0
wifi_channel_width: 0
>
>
>)pb")));
}
TEST(AnalyticsRecorderTest, UnfinishedEstablishedConnectionsAddedAsUnfinished) {
connections::Strategy strategy = connections::Strategy::kP2pStar;
std::vector<Medium> mediums = {BLE, BLUETOOTH};
std::string endpoint_id = "endpoint_id";
std::string connection_token = "connection_token";
CountDownLatch client_session_done_latch(1);
FakeEventLogger event_logger(client_session_done_latch);
AnalyticsRecorder analytics_recorder(&event_logger);
analytics_recorder.OnStartAdvertising(strategy, mediums);
analytics_recorder.OnConnectionEstablished(endpoint_id, BLUETOOTH,
connection_token);
analytics_recorder.OnConnectionClosed(endpoint_id, BLUETOOTH, UPGRADED);
analytics_recorder.OnConnectionEstablished(endpoint_id, WIFI_LAN,
connection_token);
analytics_recorder.LogSession();
ASSERT_TRUE(client_session_done_latch.Await(kDefaultTimeout).result());
EXPECT_THAT(event_logger.GetLoggedClientSession(), Partially(EqualsProto(R"pb(
strategy_session <
strategy: P2P_STAR
role: ADVERTISER
advertising_phase <
medium: BLE
medium: BLUETOOTH
advertising_metadata <
supports_extended_ble_advertisements: false
connected_ap_frequency: 0
supports_nfc_technology: false
>
>
established_connection <
medium: BLUETOOTH
disconnection_reason: UPGRADED
connection_token: "connection_token"
>
established_connection <
medium: WIFI_LAN
disconnection_reason: UNFINISHED
connection_token: "connection_token"
>
>)pb")));
}
TEST(AnalyticsRecorderTest, OutgoingPayloadUpgraded) {
connections::Strategy strategy = connections::Strategy::kP2pStar;
std::vector<Medium> mediums = {BLE, BLUETOOTH};
std::string endpoint_id = "endpoint_id";
std::int64_t payload_id = 123456789;
std::string connection_token = "connection_token";
CountDownLatch client_session_done_latch(1);
FakeEventLogger event_logger(client_session_done_latch);
AnalyticsRecorder analytics_recorder(&event_logger);
analytics_recorder.OnStartAdvertising(strategy, mediums);
analytics_recorder.OnConnectionEstablished(endpoint_id, BLUETOOTH,
connection_token);
analytics_recorder.OnOutgoingPayloadStarted(
{endpoint_id}, payload_id, connections::Payload::Type::kFile, 50);
analytics_recorder.OnPayloadChunkSent(endpoint_id, payload_id, 10);
analytics_recorder.OnPayloadChunkSent(endpoint_id, payload_id, 10);
analytics_recorder.OnConnectionClosed(endpoint_id, BLUETOOTH, UPGRADED);
analytics_recorder.OnConnectionEstablished(endpoint_id, WIFI_LAN,
connection_token);
analytics_recorder.OnPayloadChunkSent(endpoint_id, payload_id, 10);
analytics_recorder.OnPayloadChunkSent(endpoint_id, payload_id, 10);
analytics_recorder.OnPayloadChunkSent(endpoint_id, payload_id, 10);
analytics_recorder.OnOutgoingPayloadDone(endpoint_id, payload_id, SUCCESS);
analytics_recorder.OnConnectionClosed(endpoint_id, WIFI_LAN,
LOCAL_DISCONNECTION);
analytics_recorder.LogSession();
ASSERT_TRUE(client_session_done_latch.Await(kDefaultTimeout).result());
EXPECT_THAT(event_logger.GetLoggedClientSession(), Partially(EqualsProto(R"pb(
strategy_session <
strategy: P2P_STAR
role: ADVERTISER
advertising_phase <
medium: BLE
medium: BLUETOOTH
advertising_metadata <
supports_extended_ble_advertisements: false
connected_ap_frequency: 0
supports_nfc_technology: false
>
>
established_connection <
medium: BLUETOOTH
sent_payload <
type: FILE
total_size_bytes: 50
num_bytes_transferred: 20
num_chunks: 2
status: MOVED_TO_NEW_MEDIUM
>
disconnection_reason: UPGRADED
connection_token: "connection_token"
>
established_connection <
medium: WIFI_LAN
sent_payload <
type: FILE
total_size_bytes: 50
num_bytes_transferred: 30
num_chunks: 3
status: SUCCESS
>
disconnection_reason: LOCAL_DISCONNECTION
connection_token: "connection_token"
>
>)pb")));
}
TEST(AnalyticsRecorderTest, UpgradeAttemptWorks) {
connections::Strategy strategy = connections::Strategy::kP2pStar;
std::vector<Medium> mediums = {BLE, BLUETOOTH};
std::string endpoint_id = "endpoint_id";
std::string endpoint_id_1 = "endpoint_id_1";
std::string endpoint_id_2 = "endpoint_id_2";
std::string connection_token = "connection_token";
CountDownLatch client_session_done_latch(1);
FakeEventLogger event_logger(client_session_done_latch);
AnalyticsRecorder analytics_recorder(&event_logger);
analytics_recorder.OnStartAdvertising(strategy, mediums);
analytics_recorder.OnBandwidthUpgradeStarted(endpoint_id, BLE, WIFI_LAN,
INCOMING, connection_token);
analytics_recorder.OnBandwidthUpgradeStarted(
endpoint_id_1, BLUETOOTH, WIFI_LAN, INCOMING, connection_token);
// Error to upgrade.
analytics_recorder.OnBandwidthUpgradeError(endpoint_id, WIFI_LAN_MEDIUM_ERROR,
WIFI_LAN_SOCKET_CREATION);
// Success to upgrade.
analytics_recorder.OnBandwidthUpgradeSuccess(endpoint_id_1);
// Upgrade is unfinished.
analytics_recorder.OnBandwidthUpgradeStarted(
endpoint_id_2, BLUETOOTH, WIFI_LAN, INCOMING, connection_token);
analytics_recorder.LogSession();
ASSERT_TRUE(client_session_done_latch.Await(kDefaultTimeout).result());
EXPECT_THAT(event_logger.GetLoggedClientSession(), Partially(EqualsProto(R"pb(
strategy_session <
strategy: P2P_STAR
role: ADVERTISER
advertising_phase <
medium: BLE
medium: BLUETOOTH
advertising_metadata <
supports_extended_ble_advertisements: false
connected_ap_frequency: 0
supports_nfc_technology: false
>
>
upgrade_attempt <
direction: INCOMING
from_medium: BLE
to_medium: WIFI_LAN
upgrade_result: WIFI_LAN_MEDIUM_ERROR
error_stage: WIFI_LAN_SOCKET_CREATION
connection_token: "connection_token"
>
upgrade_attempt <
direction: INCOMING
from_medium: BLUETOOTH
to_medium: WIFI_LAN
upgrade_result: UPGRADE_RESULT_SUCCESS
error_stage: UPGRADE_SUCCESS
connection_token: "connection_token"
>
upgrade_attempt {
direction: INCOMING
from_medium: BLUETOOTH
to_medium: WIFI_LAN
upgrade_result: UNFINISHED_ERROR
error_stage: UPGRADE_UNFINISHED
connection_token: "connection_token"
}
>)pb")));
}
TEST(AnalyticsRecorderTest, SetErrorCodeFieldsCorrectly) {
connections::Strategy strategy = connections::Strategy::kP2pStar;
std::vector<Medium> mediums = {WEB_RTC};
std::string connection_token = "connection_token";
CountDownLatch client_session_done_latch(1);
FakeEventLogger event_logger(client_session_done_latch);
AnalyticsRecorder analytics_recorder(&event_logger);
analytics_recorder.OnStartDiscovery(strategy, mediums);
ErrorCodeParams error_code_params = ErrorCodeRecorder::BuildErrorCodeParams(
WEB_RTC, DISCONNECT, DISCONNECT_NETWORK_FAILED,
TACHYON_SEND_MESSAGE_STATUS_EXCEPTION, "", connection_token);
analytics_recorder.OnErrorCode(error_code_params);
analytics_recorder.LogSession();
ASSERT_TRUE(client_session_done_latch.Await(kDefaultTimeout).result());
EXPECT_THAT(event_logger.GetErrorCode(), Partially(EqualsProto(R"pb(
medium: WEB_RTC
event: DISCONNECT
description: TACHYON_SEND_MESSAGE_STATUS_EXCEPTION
disconnect_error: DISCONNECT_NETWORK_FAILED
connection_token: "connection_token"
)pb")));
}
TEST(AnalyticsRecorderTest, SetErrorCodeFieldsCorrectlyForUnknownDescription) {
connections::Strategy strategy = connections::Strategy::kP2pStar;
std::vector<Medium> mediums = {BLUETOOTH};
std::string connection_token = "connection_token";
CountDownLatch client_session_done_latch(1);
FakeEventLogger event_logger(client_session_done_latch);
AnalyticsRecorder analytics_recorder(&event_logger);
analytics_recorder.OnStartDiscovery(strategy, mediums);
ErrorCodeParams error_code_params;
// Skip setting error_code_params.description
error_code_params.medium = BLUETOOTH;
error_code_params.event = START_DISCOVERING;
error_code_params.start_discovering_error = START_EXTENDED_DISCOVERING_FAILED;
error_code_params.connection_token = connection_token;
analytics_recorder.OnErrorCode(error_code_params);
analytics_recorder.LogSession();
ASSERT_TRUE(client_session_done_latch.Await(kDefaultTimeout).result());
EXPECT_THAT(event_logger.GetErrorCode(), Partially(EqualsProto(R"pb(
medium: BLUETOOTH
event: START_DISCOVERING
description: UNKNOWN
start_discovering_error: START_EXTENDED_DISCOVERING_FAILED
connection_token: "connection_token"
)pb")));
}
TEST(AnalyticsRecorderTest, SetErrorCodeFieldsCorrectlyForCommonError) {
connections::Strategy strategy = connections::Strategy::kP2pStar;
std::vector<Medium> mediums = {BLUETOOTH};
std::string connection_token = "connection_token";
CountDownLatch client_session_done_latch(1);
FakeEventLogger event_logger(client_session_done_latch);
AnalyticsRecorder analytics_recorder(&event_logger);
analytics_recorder.OnStartDiscovery(strategy, mediums);
ErrorCodeParams error_code_params = ErrorCodeRecorder::BuildErrorCodeParams(
BLUETOOTH, START_DISCOVERING, INVALID_PARAMETER,
NULL_BLUETOOTH_DEVICE_NAME, "", connection_token);
analytics_recorder.OnErrorCode(error_code_params);
analytics_recorder.LogSession();
ASSERT_TRUE(client_session_done_latch.Await(kDefaultTimeout).result());
EXPECT_THAT(event_logger.GetErrorCode(), Partially(EqualsProto(R"pb(
medium: BLUETOOTH
event: START_DISCOVERING
description: NULL_BLUETOOTH_DEVICE_NAME
common_error: INVALID_PARAMETER
connection_token: "connection_token"
)pb")));
}
} // namespace
} // namespace analytics
} // namespace nearby
} // namespace location
@@ -1,44 +0,0 @@
// Copyright 2020 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_CONNECTION_ATTEMPT_METADATA_PARAMS_H_
#define ANALYTICS_CONNECTION_ATTEMPT_METADATA_PARAMS_H_
#include "proto/connections_enums.pb.h"
namespace location {
namespace nearby {
// A struct to construct ConnectionAttemptMetadata for the analytics recorder.
struct ConnectionAttemptMetadataParams {
location::nearby::proto::connections::ConnectionTechnology technology =
location::nearby::proto::connections::
CONNECTION_TECHNOLOGY_UNKNOWN_TECHNOLOGY;
location::nearby::proto::connections::ConnectionBand band =
location::nearby::proto::connections::CONNECTION_BAND_UNKNOWN_BAND;
int frequency = -1; // -1 as Unknown.
int try_count = 0;
std::string network_operator = {};
std::string country_code = {};
bool is_tdls_used = false;
bool wifi_hotspot_enabled = false;
int max_wifi_tx_speed = 0;
int max_wifi_rx_speed = 0;
int channel_width = -1; // -1 as Unknown.
};
} // namespace nearby
} // namespace location
#endif // ANALYTICS_CONNECTION_ATTEMPT_METADATA_PARAMS_H_
+2 -2
View File
@@ -59,9 +59,9 @@ cc_library(
compatible_with = ["//buildenv/target:non_prod"],
copts = ["-DCORE_ADAPTER_DLL"],
visibility = [
"//third_party/nearby/cpp/analytics:__subpackages__",
"//core:__subpackages__",
"//platform/impl/ios:__subpackages__",
"//analytics:__subpackages__",
],
deps = [
"//absl/strings",
@@ -80,7 +80,7 @@ cc_library(
],
compatible_with = ["//buildenv/target:non_prod"],
visibility = [
"//third_party/nearby/cpp/analytics:__subpackages__",
"//analytics:__subpackages__",
],
deps = [
"//proto/analytics:connections_log_cc_proto",
+2 -2
View File
@@ -100,7 +100,6 @@ cc_library(
"//absl/strings",
"//absl/time",
"//absl/types:span",
"//third_party/nearby/cpp/analytics",
"//core:core_types",
"//core/internal/mediums",
"//core/internal/mediums:utils",
@@ -113,6 +112,7 @@ cc_library(
"//platform/public:comm",
"//platform/public:logging",
"//platform/public:types",
"//analytics",
"//proto:connections_enums_portable_proto",
"//proto/connections:offline_wire_formats_portable_proto",
"//securegcm:ukey2",
@@ -197,7 +197,6 @@ cc_test(
"//absl/synchronization",
"//absl/time",
"//absl/types:span",
"//third_party/nearby/cpp/analytics",
"//core:core_types",
"//core/internal/mediums",
"//core/internal/mediums:utils",
@@ -207,6 +206,7 @@ cc_test(
"//platform/public:comm",
"//platform/public:logging",
"//platform/public:types",
"//analytics",
"//proto:connections_enums_portable_proto",
"//proto/connections:offline_wire_formats_portable_proto",
"//securegcm:ukey2",
+2 -2
View File
@@ -101,7 +101,6 @@ cc_library(
"//third_party/absl/strings",
"//third_party/absl/time",
"//third_party/absl/types:span",
"//third_party/nearby/cpp/analytics",
"//third_party/nearby/cpp/core:core_types",
"//third_party/nearby/cpp/core/internal/mediums",
"//third_party/nearby/cpp/core/internal/mediums:utils",
@@ -113,6 +112,7 @@ cc_library(
"//third_party/nearby/cpp/platform/public:comm",
"//third_party/nearby/cpp/platform/public:logging",
"//third_party/nearby/cpp/platform/public:types",
"//third_party/nearby/internal/analytics",
"//third_party/nearby/proto:connections_enums_portable_proto",
"//third_party/nearby/proto/connections:offline_wire_formats_portable_proto",
"//third_party/ukey2",
@@ -199,7 +199,6 @@ cc_test(
"//third_party/absl/synchronization",
"//third_party/absl/time",
"//third_party/absl/types:span",
"//third_party/nearby/cpp/analytics",
"//third_party/nearby/cpp/core:core_types",
"//third_party/nearby/cpp/core/internal/mediums",
"//third_party/nearby/cpp/core/internal/mediums:utils",
@@ -209,6 +208,7 @@ cc_test(
"//third_party/nearby/cpp/platform/public:comm",
"//third_party/nearby/cpp/platform/public:logging",
"//third_party/nearby/cpp/platform/public:types",
"//third_party/nearby/internal/analytics",
"//third_party/nearby/proto:connections_enums_portable_proto",
"//third_party/nearby/proto/connections:offline_wire_formats_portable_proto",
"//third_party/ukey2",
+1 -1
View File
@@ -21,7 +21,6 @@
#include "securegcm/d2d_connection_context_v1.h"
#include "absl/base/thread_annotations.h"
#include "third_party/nearby/cpp/analytics/analytics_recorder.h"
#include "core/internal/endpoint_channel.h"
#include "platform/base/byte_array.h"
#include "platform/base/input_stream.h"
@@ -30,6 +29,7 @@
#include "platform/public/condition_variable.h"
#include "platform/public/mutex.h"
#include "platform/public/system_clock.h"
#include "analytics/analytics_recorder.h"
namespace location {
namespace nearby {
+1 -1
View File
@@ -20,7 +20,6 @@
#include <string>
#include <vector>
#include "third_party/nearby/cpp/analytics/analytics_recorder.h"
#include "core/listeners.h"
#include "core/options.h"
#include "core/status.h"
@@ -31,6 +30,7 @@
#include "platform/base/prng.h"
#include "platform/public/cancelable_alarm.h"
#include "platform/public/mutex.h"
#include "analytics/analytics_recorder.h"
// Prefer using absl:: versions of a set and a map; they tend to be more
// efficient: implementation is using open-addressing hash tables.
#include "absl/container/flat_hash_map.h"
+1 -1
View File
@@ -20,10 +20,10 @@
#include "securegcm/d2d_connection_context_v1.h"
#include "absl/time/clock.h"
#include "third_party/nearby/cpp/analytics/analytics_recorder.h"
#include "platform/base/byte_array.h"
#include "platform/base/exception.h"
#include "platform/public/mutex.h"
#include "analytics/analytics_recorder.h"
#include "proto/connections_enums.pb.h"
namespace location {
+2 -2
View File
@@ -44,11 +44,11 @@ cc_library(
compatible_with = ["//buildenv/target:non_prod"],
copts = ["-DCORE_ADAPTER_DLL"],
visibility = [
"//third_party/nearby/cpp/analytics:__subpackages__",
"//third_party/nearby/cpp/cal:__subpackages__",
"//core:__subpackages__",
"//platform:__subpackages__",
"//platform/api:__subpackages__",
"//analytics:__subpackages__",
"//proto/analytics:__subpackages__",
],
deps = [
@@ -140,9 +140,9 @@ cc_library(
],
compatible_with = ["//buildenv/target:non_prod"],
visibility = [
"//third_party/nearby/cpp/analytics:__subpackages__",
"//core/internal:__subpackages__",
"//platform/impl:__subpackages__",
"//analytics:__subpackages__",
],
deps = [
":logging",
+1 -1
View File
@@ -109,9 +109,9 @@ cc_library(
"platform.cc",
],
visibility = [
"//third_party/nearby/cpp/analytics:__subpackages__",
"//core:__subpackages__",
"//platform:__subpackages__",
"//analytics:__subpackages__",
"//proto/analytics:__subpackages__",
],
deps = [
+3 -3
View File
@@ -52,12 +52,12 @@ cc_library(
],
compatible_with = ["//buildenv/target:non_prod"],
visibility = [
"//third_party/nearby/cpp/analytics:__subpackages__",
"//core:__subpackages__",
"//platform/base:__pkg__",
"//platform/impl/ios:__subpackages__",
"//platform/impl/windows:__subpackages__",
"//platform/public:__pkg__",
"//analytics:__subpackages__",
],
deps = [
":logging",
@@ -90,9 +90,9 @@ cc_library(
copts = ["-DCORE_ADAPTER_DLL"],
visibility = [
"//googlemac/iPhone/Shared/Nearby/Connections:__subpackages__",
"//third_party/nearby/cpp/analytics:__subpackages__",
"//core:__subpackages__",
"//platform/public:__pkg__",
"//analytics:__subpackages__",
],
deps = [
":logging",
@@ -116,9 +116,9 @@ cc_library(
compatible_with = ["//buildenv/target:non_prod"],
copts = ["-DCORE_ADAPTER_DLL"],
visibility = [
"//third_party/nearby/cpp/analytics:__subpackages__",
"//core:__subpackages__",
"//platform:__subpackages__",
"//analytics:__subpackages__",
"//proto/analytics:__subpackages__",
],
deps = [