Cleanup EventLogger interface.

PiperOrigin-RevId: 625797877
This commit is contained in:
Francis Tsui
2024-04-17 13:59:30 -07:00
committed by Copybara-Service
parent 42f7afb940
commit 012b9b0569
20 changed files with 486 additions and 553 deletions
+1 -3
View File
@@ -242,7 +242,7 @@ cc_test(
"//connections/implementation/mediums",
"//connections/implementation/proto:offline_wire_formats_cc_proto",
"//connections/v3:v3_types",
"//internal/analytics:event_logger",
"//internal/analytics:mock_event_logger",
"//internal/flags:nearby_flags",
"//internal/interop:authentication_status",
"//internal/interop:authentication_transport_interface",
@@ -257,10 +257,8 @@ cc_test(
"//proto:connections_enums_cc_proto",
"@com_github_protobuf_matchers//protobuf-matchers",
"@com_google_absl//absl/base:core_headers",
"@com_google_absl//absl/container:flat_hash_set",
"@com_google_absl//absl/status",
"@com_google_absl//absl/strings",
"@com_google_absl//absl/strings:str_format",
"@com_google_absl//absl/synchronization",
"@com_google_absl//absl/time",
"@com_google_absl//absl/types:span",
+1 -3
View File
@@ -56,9 +56,8 @@ cc_test(
shard_count = 16,
deps = [
":analytics",
"//internal/analytics:event_logger",
"//internal/analytics:mock_event_logger",
"//internal/platform:base",
"//internal/platform:comm",
"//internal/platform:error_code_recorder",
"//internal/platform:types",
"//internal/platform/implementation/g3", # build_cleaner: keep
@@ -68,6 +67,5 @@ cc_test(
"@com_github_protobuf_matchers//protobuf-matchers",
"@com_google_absl//absl/time",
"@com_google_googletest//:gtest_main",
"@com_google_protobuf//:protobuf_lite",
],
)
@@ -17,7 +17,6 @@
#include <stddef.h>
#include <cstdint>
#include <memory>
#include <string>
#include <vector>
@@ -25,16 +24,14 @@
#include "gmock/gmock.h"
#include "protobuf-matchers/protocol-buffer-matchers.h"
#include "gtest/gtest.h"
#include "absl/time/clock.h"
#include "absl/time/time.h"
#include "internal/analytics/event_logger.h"
#include "internal/analytics/mock_event_logger.h"
#include "internal/platform/count_down_latch.h"
#include "internal/platform/error_code_params.h"
#include "internal/platform/error_code_recorder.h"
#include "internal/platform/exception.h"
#include "internal/proto/analytics/connections_log.proto.h"
#include "proto/connections_enums.proto.h"
#include "google/protobuf/message_lite.h"
namespace nearby {
namespace analytics {
@@ -70,7 +67,7 @@ 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 ::nearby::analytics::EventLogger;
using ::nearby::analytics::MockEventLogger;
using ::proto2::contrib::parse_proto::ParseTextProtoOrDie;
using ::testing::Contains;
using ::protobuf_matchers::EqualsProto;
@@ -79,7 +76,7 @@ using ::testing::proto::Partially;
constexpr absl::Duration kDefaultTimeout = absl::Milliseconds(1000);
class FakeEventLogger : public EventLogger {
class FakeEventLogger : public MockEventLogger {
public:
explicit FakeEventLogger(CountDownLatch& client_session_done_latch)
: client_session_done_latch_(client_session_done_latch) {}
@@ -90,20 +87,15 @@ class FakeEventLogger : public EventLogger {
start_client_session_done_latch_ptr_(
start_client_session_done_latch_ptr) {}
void Log(const ::google::protobuf::MessageLite& message) override {
auto connections_log = dynamic_cast<const ConnectionsLog*>(&message);
if (connections_log == nullptr) {
return;
}
EventType event_type = connections_log->event_type();
void Log(const ConnectionsLog& message) override {
EventType event_type = message.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();
logged_client_session_ = message.client_session();
}
if (event_type == ERROR_CODE) {
error_code_ = connections_log->error_code();
error_code_ = message.error_code();
}
if (event_type == STOP_CLIENT_SESSION) {
client_session_done_latch_.CountDown();
@@ -25,17 +25,13 @@
#include "gmock/gmock.h"
#include "protobuf-matchers/protocol-buffer-matchers.h"
#include "gtest/gtest.h"
#include "absl/container/flat_hash_set.h"
#include "absl/strings/str_format.h"
#include "absl/time/clock.h"
#include "absl/time/time.h"
#include "absl/types/span.h"
#include "connections/listeners.h"
#include "connections/strategy.h"
#include "connections/v3/bandwidth_info.h"
#include "connections/v3/connection_listening_options.h"
#include "connections/v3/connections_device_provider.h"
#include "internal/analytics/event_logger.h"
#include "internal/analytics/mock_event_logger.h"
#include "internal/interop/device_provider.h"
#include "internal/platform/byte_array.h"
#include "internal/platform/count_down_latch.h"
@@ -64,15 +60,13 @@ constexpr FeatureFlags::Flags kTestCases[] = {
},
};
class FakeEventLogger : public ::nearby::analytics::EventLogger {
class FakeEventLogger : public ::nearby::analytics::MockEventLogger {
public:
explicit FakeEventLogger() = default;
void Log(const ::google::protobuf::MessageLite& message) override {
ConnectionsLog log;
log.CheckTypeAndMergeFrom(message);
void Log(const ConnectionsLog& message) override {
MutexLock lock(&mutex_);
logs_.push_back(std::move(log));
logs_.push_back(message);
}
int GetCompleteClientSessionCount() {
-2
View File
@@ -29,7 +29,6 @@ cc_library(
"//internal/analytics:event_logger",
"//internal/proto/analytics:fast_pair_log_cc_proto",
"//proto:fast_pair_enums_cc_proto",
"@com_google_protobuf//:protobuf_lite",
],
)
@@ -43,6 +42,5 @@ cc_test(
"//proto:fast_pair_enums_cc_proto",
"@com_github_protobuf_matchers//protobuf-matchers",
"@com_google_googletest//:gtest_main",
"@com_google_protobuf//:protobuf_lite",
],
)
+1 -2
View File
@@ -19,7 +19,6 @@
#include "internal/analytics/event_logger.h"
#include "internal/proto/analytics/fast_pair_log.proto.h"
#include "proto/fast_pair_enums.proto.h"
#include "google/protobuf/message_lite.h"
namespace nearby {
namespace fastpair {
@@ -118,7 +117,7 @@ void AnalyticsRecorder::NewKeyBasedPairingInfo(int request_flag,
// start private methods
void AnalyticsRecorder::LogEvent(const ::google::protobuf::MessageLite& message) {
void AnalyticsRecorder::LogEvent(const FastPairLog& message) {
if (event_logger_ == nullptr) {
return;
}
+4 -7
View File
@@ -20,7 +20,6 @@
#include "internal/analytics/event_logger.h"
#include "internal/proto/analytics/fast_pair_log.proto.h"
#include "proto/fast_pair_enums.proto.h"
#include "google/protobuf/message_lite.h"
namespace nearby {
namespace fastpair {
@@ -35,8 +34,7 @@ class AnalyticsRecorder {
void NewGattEvent(int error_from_os);
void NewBrEdrHandoverEvent(
::nearby::proto::fastpair::FastPairEvent::BrEdrHandoverErrorCode
error_code
nearby::proto::fastpair::FastPairEvent::BrEdrHandoverErrorCode error_code
);
@@ -45,7 +43,7 @@ class AnalyticsRecorder {
int unbond_reason);
void NewConnectEvent(
::nearby::proto::fastpair::FastPairEvent::ConnectErrorCode error_code,
nearby::proto::fastpair::FastPairEvent::ConnectErrorCode error_code,
int profile_uuid);
void NewProviderInfo(int number_account_keys_on_provider);
@@ -56,10 +54,9 @@ class AnalyticsRecorder {
int response_flag, int response_device_count);
private:
std::unique_ptr<::nearby::proto::fastpair::FastPairLog> createFastPairLog();
void LogEvent(const ::google::protobuf::MessageLite& message);
void LogEvent(const nearby::proto::fastpair::FastPairLog& message);
::nearby::analytics::EventLogger* event_logger_ = nullptr;
nearby::analytics::EventLogger* event_logger_ = nullptr;
};
} // namespace analytics
+30 -44
View File
@@ -14,15 +14,12 @@
#include "fastpair/analytics/analytics_recorder.h"
#include <memory>
#include "gmock/gmock.h"
#include "protobuf-matchers/protocol-buffer-matchers.h"
#include "gtest/gtest.h"
#include "internal/analytics/mock_event_logger.h"
#include "internal/proto/analytics/fast_pair_log.proto.h"
#include "proto/fast_pair_enums.proto.h"
#include "google/protobuf/message_lite.h"
namespace nearby {
namespace fastpair {
@@ -32,13 +29,14 @@ namespace {
using ::nearby::analytics::MockEventLogger;
using ::nearby::proto::fastpair::FastPairEvent;
using ::nearby::proto::fastpair::FastPairLog;
using ::testing::An;
class AnalyticsRecorderTest : public ::testing::Test {
public:
AnalyticsRecorderTest() = default;
~AnalyticsRecorderTest() override = default;
const MockEventLogger& event_logger() { return event_logger_; }
MockEventLogger& event_logger() { return event_logger_; }
AnalyticsRecorder analytics_recoder() { return analytics_recorder_; }
@@ -48,22 +46,18 @@ class AnalyticsRecorderTest : public ::testing::Test {
};
TEST_F(AnalyticsRecorderTest, NewGattEvent) {
EXPECT_CALL(event_logger(), Log)
.WillOnce([=](const ::google::protobuf::MessageLite& message) {
auto log = dynamic_cast<const FastPairLog*>(&message);
ASSERT_NE(log, nullptr);
EXPECT_EQ(log->gatt_event().error_from_os(), 1);
EXPECT_CALL(event_logger(), Log(An<const FastPairLog&>()))
.WillOnce([=](const FastPairLog& message) {
EXPECT_EQ(message.gatt_event().error_from_os(), 1);
});
analytics_recoder().NewGattEvent(1);
}
TEST_F(AnalyticsRecorderTest, NewBrEdrHandoverEvent) {
EXPECT_CALL(event_logger(), Log)
.WillOnce([=](const ::google::protobuf::MessageLite& message) {
auto log = dynamic_cast<const FastPairLog*>(&message);
ASSERT_NE(log, nullptr);
ASSERT_EQ(log->br_edr_handover_event().error_code(),
EXPECT_CALL(event_logger(), Log(An<const FastPairLog&>()))
.WillOnce([=](const FastPairLog& message) {
ASSERT_EQ(message.br_edr_handover_event().error_code(),
FastPairEvent::BLUETOOTH_MAC_INVALID);
});
analytics_recoder().NewBrEdrHandoverEvent(
@@ -71,58 +65,50 @@ TEST_F(AnalyticsRecorderTest, NewBrEdrHandoverEvent) {
}
TEST_F(AnalyticsRecorderTest, NewCreateBondEvent) {
EXPECT_CALL(event_logger(), Log)
.WillOnce([=](const ::google::protobuf::MessageLite& message) {
auto log = dynamic_cast<const FastPairLog*>(&message);
ASSERT_NE(log, nullptr);
ASSERT_EQ(log->bond_event().error_code(), FastPairEvent::NO_PERMISSION);
ASSERT_EQ(log->bond_event().unbond_reason(), 12);
EXPECT_CALL(event_logger(), Log(An<const FastPairLog&>()))
.WillOnce([=](const FastPairLog& message) {
ASSERT_EQ(message.bond_event().error_code(),
FastPairEvent::NO_PERMISSION);
ASSERT_EQ(message.bond_event().unbond_reason(), 12);
});
analytics_recoder().NewCreateBondEvent(FastPairEvent::NO_PERMISSION, 12);
}
TEST_F(AnalyticsRecorderTest, NewConnectEvent) {
EXPECT_CALL(event_logger(), Log)
.WillOnce([=](const ::google::protobuf::MessageLite& message) {
auto log = dynamic_cast<const FastPairLog*>(&message);
ASSERT_NE(log, nullptr);
ASSERT_EQ(log->connect_event().error_code(),
EXPECT_CALL(event_logger(), Log(An<const FastPairLog&>()))
.WillOnce([=](const FastPairLog& message) {
ASSERT_EQ(message.connect_event().error_code(),
FastPairEvent::GET_PROFILE_PROXY_FAILED);
ASSERT_EQ(log->connect_event().profile_uuid(), 13);
ASSERT_EQ(message.connect_event().profile_uuid(), 13);
});
analytics_recoder().NewConnectEvent(FastPairEvent::GET_PROFILE_PROXY_FAILED,
13);
}
TEST_F(AnalyticsRecorderTest, NewProviderInfo) {
EXPECT_CALL(event_logger(), Log)
.WillOnce([=](const ::google::protobuf::MessageLite& message) {
auto log = dynamic_cast<const FastPairLog*>(&message);
ASSERT_NE(log, nullptr);
ASSERT_EQ(log->provider_info().number_account_keys_on_provider(), 14);
EXPECT_CALL(event_logger(), Log(An<const FastPairLog&>()))
.WillOnce([=](const FastPairLog& message) {
ASSERT_EQ(message.provider_info().number_account_keys_on_provider(),
14);
});
analytics_recoder().NewProviderInfo(14);
}
TEST_F(AnalyticsRecorderTest, NewFootprintsInfo) {
EXPECT_CALL(event_logger(), Log)
.WillOnce([=](const ::google::protobuf::MessageLite& message) {
auto log = dynamic_cast<const FastPairLog*>(&message);
ASSERT_NE(log, nullptr);
ASSERT_EQ(log->footprints_info().number_devices_on_footprints(), 15);
EXPECT_CALL(event_logger(), Log(An<const FastPairLog&>()))
.WillOnce([=](const FastPairLog& message) {
ASSERT_EQ(message.footprints_info().number_devices_on_footprints(), 15);
});
analytics_recoder().NewFootprintsInfo(15);
}
TEST_F(AnalyticsRecorderTest, NewKeyBasedPairingInfo) {
EXPECT_CALL(event_logger(), Log)
.WillOnce([=](const ::google::protobuf::MessageLite& message) {
auto log = dynamic_cast<const FastPairLog*>(&message);
ASSERT_NE(log, nullptr);
ASSERT_EQ(log->key_based_pairing_info().request_flag(), 16);
ASSERT_EQ(log->key_based_pairing_info().response_type(), 17);
ASSERT_EQ(log->key_based_pairing_info().response_flag(), 18);
ASSERT_EQ(log->key_based_pairing_info().response_device_count(), 19);
EXPECT_CALL(event_logger(), Log(An<const FastPairLog&>()))
.WillOnce([=](const FastPairLog& message) {
ASSERT_EQ(message.key_based_pairing_info().request_flag(), 16);
ASSERT_EQ(message.key_based_pairing_info().response_type(), 17);
ASSERT_EQ(message.key_based_pairing_info().response_flag(), 18);
ASSERT_EQ(message.key_based_pairing_info().response_device_count(), 19);
});
analytics_recoder().NewKeyBasedPairingInfo(16, 17, 18, 19);
}
+6 -1
View File
@@ -26,7 +26,12 @@ cc_library(
"//location/nearby/cpp/sharing:__subpackages__",
"//sharing:__subpackages__",
],
deps = ["@com_google_protobuf//:protobuf_lite"],
deps = [
"//internal/proto/analytics:connections_log_cc_proto",
"//internal/proto/analytics:experiments_log_cc_proto",
"//internal/proto/analytics:fast_pair_log_cc_proto",
"//sharing/proto/analytics:sharing_log_cc_proto",
],
)
cc_library(
+12 -2
View File
@@ -15,7 +15,10 @@
#ifndef NEARBY_ANALYTICS_EVENT_LOGGER_H_
#define NEARBY_ANALYTICS_EVENT_LOGGER_H_
#include "google/protobuf/message_lite.h"
#include "internal/proto/analytics/connections_log.pb.h"
#include "internal/proto/analytics/experiments_log.pb.h"
#include "internal/proto/analytics/fast_pair_log.pb.h"
#include "sharing/proto/analytics/nearby_sharing_log.pb.h"
namespace nearby {
namespace analytics {
@@ -29,7 +32,14 @@ class EventLogger {
// Logs the proto details. Might block to do I/O, e.g. upload
// synchronously to some metrics server.
virtual void Log(const ::google::protobuf::MessageLite& message) = 0;
virtual void Log(
const location::nearby::analytics::proto::ConnectionsLog& message) = 0;
virtual void Log(const sharing::analytics::proto::SharingLog& message) = 0;
virtual void Log(const nearby::proto::fastpair::FastPairLog& message) = 0;
// Configure experiment parameters used by this logger.
virtual void ConfigureExperiments(
const experiments::ExperimentsLog& message) = 0;
};
} // namespace analytics
+11 -2
View File
@@ -17,7 +17,6 @@
#include "gmock/gmock.h"
#include "internal/analytics/event_logger.h"
#include "google/protobuf/message_lite.h"
namespace nearby::analytics {
@@ -26,7 +25,17 @@ class MockEventLogger : public ::nearby::analytics::EventLogger {
MockEventLogger() = default;
~MockEventLogger() override = default;
MOCK_METHOD(void, Log, (const ::google::protobuf::MessageLite& message), (override));
MOCK_METHOD(
void, Log,
(const location::nearby::analytics::proto::ConnectionsLog& message),
(override));
MOCK_METHOD(void, Log, (const sharing::analytics::proto::SharingLog& message),
(override));
MOCK_METHOD(void, Log, (const nearby::proto::fastpair::FastPairLog& message),
(override));
MOCK_METHOD(void, ConfigureExperiments,
(const experiments::ExperimentsLog& message), (override));
};
} // namespace nearby::analytics
+2 -1
View File
@@ -33,7 +33,6 @@ proto_library(
proto_library(
name = "fast_pair_log_proto",
srcs = ["fast_pair_log.proto"],
compatible_with = ["//buildenv/target:non_prod"],
deps = ["//proto:fast_pair_enums_proto"],
)
@@ -51,6 +50,7 @@ cc_proto_library(
name = "connections_log_cc_proto",
visibility = [
"//connections:__subpackages__",
"//internal/analytics:__pkg__",
"//location/nearby/analytics/cpp:__subpackages__",
],
deps = [":connections_log_proto"],
@@ -64,6 +64,7 @@ proto_library(
cc_proto_library(
name = "experiments_log_cc_proto",
visibility = [
"//internal/analytics:__pkg__",
"//location/nearby/analytics/cpp/logging:__subpackages__",
"//location/nearby/cpp/experiments:__subpackages__",
],
+1 -1
View File
@@ -16,7 +16,7 @@ syntax = "proto2";
package nearby.proto.fastpair;
import "third_party/nearby/proto/fast_pair_enums.proto";
import "proto/fast_pair_enums.proto";
option optimize_for = LITE_RUNTIME;
option java_package = "nearby.proto.fastpair";
-1
View File
@@ -56,7 +56,6 @@ proto_library(
proto_library(
name = "fast_pair_enums_proto",
srcs = ["fast_pair_enums.proto"],
compatible_with = ["//buildenv/target:non_prod"],
)
cc_proto_library(
+1 -1
View File
@@ -1058,7 +1058,7 @@ std::unique_ptr<SharingLog> AnalyticsRecorder::CreateSharingLog(
return sharing_log;
}
void AnalyticsRecorder::LogEvent(const ::google::protobuf::MessageLite& message) {
void AnalyticsRecorder::LogEvent(const SharingLog& message) {
if (event_logger_ == nullptr) {
return;
}
+39 -42
View File
@@ -30,7 +30,6 @@
#include "sharing/proto/analytics/nearby_sharing_log.pb.h"
#include "sharing/proto/enums.pb.h"
#include "sharing/share_target.h"
#include "google/protobuf/message_lite.h"
namespace nearby {
namespace sharing {
@@ -44,7 +43,7 @@ class AnalyticsRecorder {
void NewEstablishConnection(
int64_t session_id,
::location::nearby::proto::sharing::EstablishConnectionStatus
location::nearby::proto::sharing::EstablishConnectionStatus
connection_status,
ShareTarget share_target, int transfer_position,
int concurrent_connections, int64_t duration_millis,
@@ -63,14 +62,14 @@ class AnalyticsRecorder {
void NewTapHelp();
void NewLaunchDeviceContactConsent(
::location::nearby::proto::sharing::ConsentAcceptanceStatus status);
location::nearby::proto::sharing::ConsentAcceptanceStatus status);
void NewAdvertiseDevicePresenceEnd(int64_t session_id);
void NewAdvertiseDevicePresenceStart(
int64_t session_id, ::nearby::sharing::proto::DeviceVisibility visibility,
::location::nearby::proto::sharing::SessionStatus status,
::nearby::sharing::proto::DataUsage data_usage,
int64_t session_id, nearby::sharing::proto::DeviceVisibility visibility,
location::nearby::proto::sharing::SessionStatus status,
nearby::sharing::proto::DataUsage data_usage,
std::optional<std::string> referrer_package);
void NewDescribeAttachments(
@@ -83,7 +82,7 @@ class AnalyticsRecorder {
int64_t latency_since_send_surface_registered_millis);
void NewEnableNearbySharing(
::location::nearby::proto::sharing::NearbySharingStatus status);
location::nearby::proto::sharing::NearbySharingStatus status);
void NewOpenReceivedAttachments(
const std::vector<std::unique_ptr<Attachment>>& attachments,
@@ -91,12 +90,12 @@ class AnalyticsRecorder {
void NewProcessReceivedAttachmentsEnd(
int64_t session_id,
::location::nearby::proto::sharing::ProcessReceivedAttachmentsStatus
location::nearby::proto::sharing::ProcessReceivedAttachmentsStatus
status);
void NewReceiveAttachmentsEnd(
int64_t session_id, int64_t received_bytes,
::location::nearby::proto::sharing::AttachmentTransmissionStatus status,
location::nearby::proto::sharing::AttachmentTransmissionStatus status,
std::optional<std::string> referrer_package);
void NewReceiveAttachmentsStart(
@@ -112,10 +111,10 @@ class AnalyticsRecorder {
void NewReceiveIntroduction(
int64_t session_id, ShareTarget share_target,
std::optional<std::string> referrer_package,
::location::nearby::proto::sharing::OSType share_target_os_type);
location::nearby::proto::sharing::OSType share_target_os_type);
void NewRespondToIntroduction(
::location::nearby::proto::sharing::ResponseToIntroduction action,
location::nearby::proto::sharing::ResponseToIntroduction action,
int64_t session_id);
void NewTapPrivacyNotification();
@@ -126,18 +125,18 @@ class AnalyticsRecorder {
void NewScanForShareTargetsStart(
int64_t session_id,
::location::nearby::proto::sharing::SessionStatus status,
location::nearby::proto::sharing::SessionStatus status,
AnalyticsInformation analytics_information, int64_t flow_id,
std::optional<std::string> referrer_package);
void NewSendAttachmentsEnd(
int64_t session_id, int64_t sent_bytes, ShareTarget share_target,
::location::nearby::proto::sharing::AttachmentTransmissionStatus status,
location::nearby::proto::sharing::AttachmentTransmissionStatus status,
int transfer_position, int concurrent_connections,
int64_t duration_millis, std::optional<std::string> referrer_package,
::location::nearby::proto::sharing::ConnectionLayerStatus
location::nearby::proto::sharing::ConnectionLayerStatus
connection_layer_status,
::location::nearby::proto::sharing::OSType share_target_os_type);
location::nearby::proto::sharing::OSType share_target_os_type);
void NewSendAttachmentsStart(
int64_t session_id,
@@ -151,28 +150,27 @@ class AnalyticsRecorder {
void NewSendIntroduction(
ShareTargetType target_type, int64_t session_id,
::location::nearby::proto::sharing::DeviceRelationship relationship,
::location::nearby::proto::sharing::OSType share_target_os_type);
location::nearby::proto::sharing::DeviceRelationship relationship,
location::nearby::proto::sharing::OSType share_target_os_type);
void NewSendIntroduction(
int64_t session_id, ShareTarget share_target, int transfer_position,
int concurrent_connections,
::location::nearby::proto::sharing::OSType share_target_os_type);
location::nearby::proto::sharing::OSType share_target_os_type);
void NewSetVisibility(
::nearby::sharing::proto::DeviceVisibility src_visibility,
::nearby::sharing::proto::DeviceVisibility dst_visibility,
int64_t duration_millis);
void NewSetVisibility(nearby::sharing::proto::DeviceVisibility src_visibility,
nearby::sharing::proto::DeviceVisibility dst_visibility,
int64_t duration_millis);
void NewDeviceSettings(AnalyticsDeviceSettings settings);
void NewFastShareServerResponse(
::location::nearby::proto::sharing::ServerActionName name,
::location::nearby::proto::sharing::ServerResponseState state,
location::nearby::proto::sharing::ServerActionName name,
location::nearby::proto::sharing::ServerResponseState state,
int64_t latency_millis);
void NewSetDataUsage(::nearby::sharing::proto::DataUsage original_preference,
::nearby::sharing::proto::DataUsage preference);
void NewSetDataUsage(nearby::sharing::proto::DataUsage original_preference,
nearby::sharing::proto::DataUsage preference);
void NewAddQuickSettingsTile();
@@ -181,41 +179,40 @@ class AnalyticsRecorder {
void NewTapQuickSettingsTile();
void NewToggleShowNotification(
::location::nearby::proto::sharing::ShowNotificationStatus prev_status,
::location::nearby::proto::sharing::ShowNotificationStatus
current_status);
location::nearby::proto::sharing::ShowNotificationStatus prev_status,
location::nearby::proto::sharing::ShowNotificationStatus current_status);
void NewSetDeviceName(int device_name_size);
void NewRequestSettingPermissions(
::location::nearby::proto::sharing::PermissionRequestType type,
::location::nearby::proto::sharing::PermissionRequestResult result);
location::nearby::proto::sharing::PermissionRequestType type,
location::nearby::proto::sharing::PermissionRequestResult result);
void NewInstallAPKStatus(
::location::nearby::proto::sharing::InstallAPKStatus status,
::location::nearby::proto::sharing::ApkSource source);
location::nearby::proto::sharing::InstallAPKStatus status,
location::nearby::proto::sharing::ApkSource source);
void NewVerifyAPKStatus(
::location::nearby::proto::sharing::VerifyAPKStatus status,
::location::nearby::proto::sharing::ApkSource source);
location::nearby::proto::sharing::VerifyAPKStatus status,
location::nearby::proto::sharing::ApkSource source);
void NewSendDesktopNotification(
::location::nearby::proto::sharing::DesktopNotification event);
location::nearby::proto::sharing::DesktopNotification event);
void NewSendDesktopTransferEvent(
::location::nearby::proto::sharing::DesktopTransferEventType event);
location::nearby::proto::sharing::DesktopTransferEventType event);
// Generates a random number for session ID or flow ID.
int64_t GenerateNextId();
private:
std::unique_ptr<::nearby::sharing::analytics::proto::SharingLog>
std::unique_ptr<nearby::sharing::analytics::proto::SharingLog>
CreateSharingLog(
::location::nearby::proto::sharing::EventCategory event_category,
::location::nearby::proto::sharing::EventType event_type);
void LogEvent(const ::google::protobuf::MessageLite& message);
location::nearby::proto::sharing::EventCategory event_category,
location::nearby::proto::sharing::EventType event_type);
void LogEvent(const nearby::sharing::analytics::proto::SharingLog& message);
::nearby::analytics::EventLogger* event_logger_ = nullptr;
nearby::analytics::EventLogger* event_logger_ = nullptr;
};
} // namespace analytics
File diff suppressed because it is too large Load Diff
+44 -2
View File
@@ -17,7 +17,6 @@
#include "internal/analytics/event_logger.h"
#include "sharing/common/nearby_share_prefs.h"
#include "sharing/internal/api/preference_manager.h"
#include "google/protobuf/message_lite.h"
namespace nearby {
namespace sharing {
@@ -31,7 +30,8 @@ NearbySharingEventLogger::NearbySharingEventLogger(
NearbySharingEventLogger::~NearbySharingEventLogger() = default;
void NearbySharingEventLogger::Log(const ::google::protobuf::MessageLite& message) {
void NearbySharingEventLogger::Log(
const location::nearby::analytics::proto::ConnectionsLog& message) {
if (event_logger_ == nullptr) {
return;
}
@@ -44,5 +44,47 @@ void NearbySharingEventLogger::Log(const ::google::protobuf::MessageLite& messag
event_logger_->Log(message);
}
void NearbySharingEventLogger::Log(
const sharing::analytics::proto::SharingLog& message) {
if (event_logger_ == nullptr) {
return;
}
if (!preference_manager_.GetBoolean(
prefs::kNearbySharingIsAnalyticsEnabledName, false)) {
return;
}
event_logger_->Log(message);
}
void NearbySharingEventLogger::Log(
const nearby::proto::fastpair::FastPairLog& message) {
if (event_logger_ == nullptr) {
return;
}
if (!preference_manager_.GetBoolean(
prefs::kNearbySharingIsAnalyticsEnabledName, false)) {
return;
}
event_logger_->Log(message);
}
void NearbySharingEventLogger::ConfigureExperiments(
const experiments::ExperimentsLog& message) {
if (event_logger_ == nullptr) {
return;
}
if (!preference_manager_.GetBoolean(
prefs::kNearbySharingIsAnalyticsEnabledName, false)) {
return;
}
event_logger_->ConfigureExperiments(message);
}
} // namespace sharing
} // namespace nearby
+6 -2
View File
@@ -17,7 +17,6 @@
#include "internal/analytics/event_logger.h"
#include "sharing/internal/api/preference_manager.h"
#include "google/protobuf/message_lite.h"
namespace nearby {
namespace sharing {
@@ -32,7 +31,12 @@ class NearbySharingEventLogger : public nearby::analytics::EventLogger {
nearby::analytics::EventLogger* event_logger);
~NearbySharingEventLogger() override;
void Log(const ::google::protobuf::MessageLite& message) override;
void Log(const location::nearby::analytics::proto::ConnectionsLog& message)
override;
void Log(const sharing::analytics::proto::SharingLog& message) override;
void Log(const nearby::proto::fastpair::FastPairLog& message) override;
void ConfigureExperiments(
const experiments::ExperimentsLog& message) override;
private:
const nearby::sharing::api::PreferenceManager& preference_manager_;
+7 -9
View File
@@ -34,6 +34,7 @@ using ::location::nearby::proto::sharing::EventCategory;
using ::location::nearby::proto::sharing::EventType;
using ::nearby::analytics::MockEventLogger;
using ::nearby::sharing::analytics::proto::SharingLog;
using ::testing::An;
class NearbySharingEventLoggerTest : public ::testing::Test {
public:
@@ -50,7 +51,7 @@ class NearbySharingEventLoggerTest : public ::testing::Test {
enabled);
}
const MockEventLogger* event_logger() { return event_logger_.get(); }
MockEventLogger* event_logger() { return event_logger_.get(); }
std::unique_ptr<SharingLog> GetTestEvent() {
auto sharing_log =
@@ -77,13 +78,10 @@ class NearbySharingEventLoggerTest : public ::testing::Test {
TEST_F(NearbySharingEventLoggerTest, LogEventWhenEnabled) {
SetEventLogger(true);
EXPECT_CALL(*event_logger(), Log)
.WillOnce([&](const ::google::protobuf::MessageLite& message) {
const SharingLog* sharing_log =
dynamic_cast<const SharingLog*>(&message);
ASSERT_NE(sharing_log, nullptr);
EXPECT_EQ(sharing_log->event_category(), EventCategory::SETTINGS_EVENT);
EXPECT_EQ(sharing_log->event_type(), EventType::TAP_HELP);
EXPECT_CALL(*event_logger(), Log(An<const SharingLog&>()))
.WillOnce([&](const SharingLog& message) {
EXPECT_EQ(message.event_category(), EventCategory::SETTINGS_EVENT);
EXPECT_EQ(message.event_type(), EventType::TAP_HELP);
});
std::unique_ptr<SharingLog> event = GetTestEvent();
@@ -92,7 +90,7 @@ TEST_F(NearbySharingEventLoggerTest, LogEventWhenEnabled) {
TEST_F(NearbySharingEventLoggerTest, NoLogEventWhenDisabled) {
SetEventLogger(false);
EXPECT_CALL(*event_logger(), Log).Times(0);
EXPECT_CALL(*event_logger(), Log(An<const SharingLog&>())).Times(0);
std::unique_ptr<SharingLog> event = GetTestEvent();
sharing_event_logger()->Log(*event);