From 012b9b0569512d5e54ff45175c227cdc2c763d45 Mon Sep 17 00:00:00 2001 From: Francis Tsui Date: Wed, 17 Apr 2024 13:58:09 -0700 Subject: [PATCH] Cleanup EventLogger interface. PiperOrigin-RevId: 625797877 --- connections/implementation/BUILD | 4 +- connections/implementation/analytics/BUILD | 4 +- .../analytics/analytics_recorder_test.cc | 22 +- .../implementation/client_proxy_test.cc | 14 +- fastpair/analytics/BUILD | 2 - fastpair/analytics/analytics_recorder.cc | 3 +- fastpair/analytics/analytics_recorder.h | 11 +- fastpair/analytics/analytics_recorder_test.cc | 74 +- internal/analytics/BUILD | 7 +- internal/analytics/event_logger.h | 14 +- internal/analytics/mock_event_logger.h | 13 +- internal/proto/analytics/BUILD | 3 +- internal/proto/analytics/fast_pair_log.proto | 2 +- proto/BUILD | 1 - sharing/analytics/analytics_recorder.cc | 2 +- sharing/analytics/analytics_recorder.h | 81 +- sharing/analytics/analytics_recorder_test.cc | 712 ++++++++---------- sharing/nearby_sharing_event_logger.cc | 46 +- sharing/nearby_sharing_event_logger.h | 8 +- sharing/nearby_sharing_event_logger_test.cc | 16 +- 20 files changed, 486 insertions(+), 553 deletions(-) diff --git a/connections/implementation/BUILD b/connections/implementation/BUILD index cb79c9b7..3ba0201a 100644 --- a/connections/implementation/BUILD +++ b/connections/implementation/BUILD @@ -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", diff --git a/connections/implementation/analytics/BUILD b/connections/implementation/analytics/BUILD index 059aa381..ddcca922 100644 --- a/connections/implementation/analytics/BUILD +++ b/connections/implementation/analytics/BUILD @@ -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", ], ) diff --git a/connections/implementation/analytics/analytics_recorder_test.cc b/connections/implementation/analytics/analytics_recorder_test.cc index 1cde99f2..c65ed311 100644 --- a/connections/implementation/analytics/analytics_recorder_test.cc +++ b/connections/implementation/analytics/analytics_recorder_test.cc @@ -17,7 +17,6 @@ #include #include -#include #include #include @@ -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(&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(); diff --git a/connections/implementation/client_proxy_test.cc b/connections/implementation/client_proxy_test.cc index 48561f64..c4382557 100644 --- a/connections/implementation/client_proxy_test.cc +++ b/connections/implementation/client_proxy_test.cc @@ -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() { diff --git a/fastpair/analytics/BUILD b/fastpair/analytics/BUILD index dfb41b67..e076f3ed 100644 --- a/fastpair/analytics/BUILD +++ b/fastpair/analytics/BUILD @@ -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", ], ) diff --git a/fastpair/analytics/analytics_recorder.cc b/fastpair/analytics/analytics_recorder.cc index 87977029..c6ac23ef 100644 --- a/fastpair/analytics/analytics_recorder.cc +++ b/fastpair/analytics/analytics_recorder.cc @@ -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; } diff --git a/fastpair/analytics/analytics_recorder.h b/fastpair/analytics/analytics_recorder.h index fc575f49..14f6da00 100644 --- a/fastpair/analytics/analytics_recorder.h +++ b/fastpair/analytics/analytics_recorder.h @@ -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 diff --git a/fastpair/analytics/analytics_recorder_test.cc b/fastpair/analytics/analytics_recorder_test.cc index c0a30db2..ea0dfcb8 100644 --- a/fastpair/analytics/analytics_recorder_test.cc +++ b/fastpair/analytics/analytics_recorder_test.cc @@ -14,15 +14,12 @@ #include "fastpair/analytics/analytics_recorder.h" -#include - #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(&message); - ASSERT_NE(log, nullptr); - EXPECT_EQ(log->gatt_event().error_from_os(), 1); + EXPECT_CALL(event_logger(), Log(An())) + .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(&message); - ASSERT_NE(log, nullptr); - ASSERT_EQ(log->br_edr_handover_event().error_code(), + EXPECT_CALL(event_logger(), Log(An())) + .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(&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())) + .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(&message); - ASSERT_NE(log, nullptr); - ASSERT_EQ(log->connect_event().error_code(), + EXPECT_CALL(event_logger(), Log(An())) + .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(&message); - ASSERT_NE(log, nullptr); - ASSERT_EQ(log->provider_info().number_account_keys_on_provider(), 14); + EXPECT_CALL(event_logger(), Log(An())) + .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(&message); - ASSERT_NE(log, nullptr); - ASSERT_EQ(log->footprints_info().number_devices_on_footprints(), 15); + EXPECT_CALL(event_logger(), Log(An())) + .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(&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())) + .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); } diff --git a/internal/analytics/BUILD b/internal/analytics/BUILD index 543f3e63..38417a5b 100644 --- a/internal/analytics/BUILD +++ b/internal/analytics/BUILD @@ -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( diff --git a/internal/analytics/event_logger.h b/internal/analytics/event_logger.h index e90ae41b..43c18178 100644 --- a/internal/analytics/event_logger.h +++ b/internal/analytics/event_logger.h @@ -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 diff --git a/internal/analytics/mock_event_logger.h b/internal/analytics/mock_event_logger.h index 167a6827..9378ff5f 100644 --- a/internal/analytics/mock_event_logger.h +++ b/internal/analytics/mock_event_logger.h @@ -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 diff --git a/internal/proto/analytics/BUILD b/internal/proto/analytics/BUILD index 52ca1719..eec05596 100644 --- a/internal/proto/analytics/BUILD +++ b/internal/proto/analytics/BUILD @@ -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__", ], diff --git a/internal/proto/analytics/fast_pair_log.proto b/internal/proto/analytics/fast_pair_log.proto index 3266fe42..ab0316ef 100644 --- a/internal/proto/analytics/fast_pair_log.proto +++ b/internal/proto/analytics/fast_pair_log.proto @@ -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"; diff --git a/proto/BUILD b/proto/BUILD index 8b99368a..551a163d 100644 --- a/proto/BUILD +++ b/proto/BUILD @@ -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( diff --git a/sharing/analytics/analytics_recorder.cc b/sharing/analytics/analytics_recorder.cc index 56dab633..186877df 100644 --- a/sharing/analytics/analytics_recorder.cc +++ b/sharing/analytics/analytics_recorder.cc @@ -1058,7 +1058,7 @@ std::unique_ptr AnalyticsRecorder::CreateSharingLog( return sharing_log; } -void AnalyticsRecorder::LogEvent(const ::google::protobuf::MessageLite& message) { +void AnalyticsRecorder::LogEvent(const SharingLog& message) { if (event_logger_ == nullptr) { return; } diff --git a/sharing/analytics/analytics_recorder.h b/sharing/analytics/analytics_recorder.h index cdcb58f0..4ec1077d 100644 --- a/sharing/analytics/analytics_recorder.h +++ b/sharing/analytics/analytics_recorder.h @@ -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 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>& 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 referrer_package); void NewReceiveAttachmentsStart( @@ -112,10 +111,10 @@ class AnalyticsRecorder { void NewReceiveIntroduction( int64_t session_id, ShareTarget share_target, std::optional 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 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 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 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 diff --git a/sharing/analytics/analytics_recorder_test.cc b/sharing/analytics/analytics_recorder_test.cc index cb66eefa..b45230c1 100644 --- a/sharing/analytics/analytics_recorder_test.cc +++ b/sharing/analytics/analytics_recorder_test.cc @@ -52,6 +52,7 @@ using ::nearby::analytics::MockEventLogger; using ::nearby::sharing::analytics::proto::SharingLog; using ::nearby::sharing::proto::DataUsage; using ::nearby::sharing::proto::DeviceVisibility; +using ::testing::An; constexpr absl::string_view kFileName = "fileName"; constexpr absl::string_view kTextBody = "textBody"; @@ -65,7 +66,7 @@ class AnalyticsRecorderTest : public ::testing::Test { AnalyticsRecorderTest() = default; ~AnalyticsRecorderTest() override = default; - const MockEventLogger& event_logger() { return event_logger_; } + MockEventLogger& event_logger() { return event_logger_; } AnalyticsRecorder analytics_recoder() { return analytics_recorder_; } @@ -79,112 +80,96 @@ TEST_F(AnalyticsRecorderTest, NewEstablishConnection) { share_target.device_name = "share_target"; share_target.type = ShareTargetType::kPhone; - EXPECT_CALL(event_logger(), Log) - .WillOnce([=](const ::google::protobuf::MessageLite& message) { - auto log = dynamic_cast(&message); - ASSERT_NE(log, nullptr); - EXPECT_EQ(log->event_type(), EventType::ESTABLISH_CONNECTION); - EXPECT_EQ(log->event_category(), EventCategory::SENDING_EVENT); - EXPECT_EQ(log->establish_connection().status(), - ::location::nearby::proto::sharing:: - EstablishConnectionStatus::CONNECTION_STATUS_SUCCESS); - EXPECT_EQ(log->establish_connection().session_id(), 1); - EXPECT_EQ(log->establish_connection().transfer_position(), 1); - EXPECT_EQ(log->establish_connection().concurrent_connections(), 1); - EXPECT_EQ(log->establish_connection().duration_millis(), 100); - EXPECT_EQ(log->establish_connection().share_target_info().os_type(), - ::location::nearby::proto::sharing::OSType::ANDROID); - EXPECT_EQ(log->establish_connection().referrer_name(), kAppPackageName); + EXPECT_CALL(event_logger(), Log(An())) + .WillOnce([](const SharingLog& log) { + EXPECT_EQ(log.event_type(), EventType::ESTABLISH_CONNECTION); + EXPECT_EQ(log.event_category(), EventCategory::SENDING_EVENT); + EXPECT_EQ(log.establish_connection().status(), + location::nearby::proto::sharing::EstablishConnectionStatus:: + CONNECTION_STATUS_SUCCESS); + EXPECT_EQ(log.establish_connection().session_id(), 1); + EXPECT_EQ(log.establish_connection().transfer_position(), 1); + EXPECT_EQ(log.establish_connection().concurrent_connections(), 1); + EXPECT_EQ(log.establish_connection().duration_millis(), 100); + EXPECT_EQ(log.establish_connection().share_target_info().os_type(), + location::nearby::proto::sharing::OSType::ANDROID); + EXPECT_EQ(log.establish_connection().referrer_name(), kAppPackageName); }); analytics_recoder().NewEstablishConnection( 1, - ::location::nearby::proto::sharing::EstablishConnectionStatus:: + location::nearby::proto::sharing::EstablishConnectionStatus:: CONNECTION_STATUS_SUCCESS, share_target, 1, 1, 100, std::string(kAppPackageName)); } TEST_F(AnalyticsRecorderTest, NewAcceptAgreements) { - EXPECT_CALL(event_logger(), Log) - .WillOnce([=](const ::google::protobuf::MessageLite& message) { - auto log = dynamic_cast(&message); - ASSERT_NE(log, nullptr); - EXPECT_EQ(log->event_type(), EventType::ACCEPT_AGREEMENTS); - EXPECT_EQ(log->event_category(), EventCategory::SETTINGS_EVENT); + EXPECT_CALL(event_logger(), Log(An())) + .WillOnce([](const SharingLog& log) { + EXPECT_EQ(log.event_type(), EventType::ACCEPT_AGREEMENTS); + EXPECT_EQ(log.event_category(), EventCategory::SETTINGS_EVENT); }); analytics_recoder().NewAcceptAgreements(); } TEST_F(AnalyticsRecorderTest, NewDeclineAgreements) { - EXPECT_CALL(event_logger(), Log) - .WillOnce([=](const ::google::protobuf::MessageLite& message) { - auto log = dynamic_cast(&message); - ASSERT_NE(log, nullptr); - EXPECT_EQ(log->event_type(), EventType::DECLINE_AGREEMENTS); - EXPECT_EQ(log->event_category(), EventCategory::SETTINGS_EVENT); + EXPECT_CALL(event_logger(), Log(An())) + .WillOnce([](const SharingLog& log) { + EXPECT_EQ(log.event_type(), EventType::DECLINE_AGREEMENTS); + EXPECT_EQ(log.event_category(), EventCategory::SETTINGS_EVENT); }); analytics_recoder().NewDeclineAgreements(); } TEST_F(AnalyticsRecorderTest, NewAddContact) { - EXPECT_CALL(event_logger(), Log) - .WillOnce([=](const ::google::protobuf::MessageLite& message) { - auto log = dynamic_cast(&message); - ASSERT_NE(log, nullptr); - EXPECT_EQ(log->event_type(), EventType::ADD_CONTACT); - EXPECT_EQ(log->event_category(), EventCategory::SETTINGS_EVENT); + EXPECT_CALL(event_logger(), Log(An())) + .WillOnce([](const SharingLog& log) { + EXPECT_EQ(log.event_type(), EventType::ADD_CONTACT); + EXPECT_EQ(log.event_category(), EventCategory::SETTINGS_EVENT); }); analytics_recoder().NewAddContact(); } TEST_F(AnalyticsRecorderTest, NewRemoveContact) { - EXPECT_CALL(event_logger(), Log) - .WillOnce([=](const ::google::protobuf::MessageLite& message) { - auto log = dynamic_cast(&message); - ASSERT_NE(log, nullptr); - EXPECT_EQ(log->event_type(), EventType::REMOVE_CONTACT); - EXPECT_EQ(log->event_category(), EventCategory::SETTINGS_EVENT); + EXPECT_CALL(event_logger(), Log(An())) + .WillOnce([](const SharingLog& log) { + EXPECT_EQ(log.event_type(), EventType::REMOVE_CONTACT); + EXPECT_EQ(log.event_category(), EventCategory::SETTINGS_EVENT); }); analytics_recoder().NewRemoveContact(); } TEST_F(AnalyticsRecorderTest, NewTapFeedback) { - EXPECT_CALL(event_logger(), Log) - .WillOnce([=](const ::google::protobuf::MessageLite& message) { - auto log = dynamic_cast(&message); - ASSERT_NE(log, nullptr); - EXPECT_EQ(log->event_type(), EventType::TAP_FEEDBACK); - EXPECT_EQ(log->event_category(), EventCategory::SETTINGS_EVENT); + EXPECT_CALL(event_logger(), Log(An())) + .WillOnce([](const SharingLog& log) { + EXPECT_EQ(log.event_type(), EventType::TAP_FEEDBACK); + EXPECT_EQ(log.event_category(), EventCategory::SETTINGS_EVENT); }); analytics_recoder().NewTapFeedback(); } TEST_F(AnalyticsRecorderTest, NewTapHelp) { - EXPECT_CALL(event_logger(), Log) - .WillOnce([=](const ::google::protobuf::MessageLite& message) { - auto log = dynamic_cast(&message); - ASSERT_NE(log, nullptr); - EXPECT_EQ(log->event_type(), EventType::TAP_HELP); - EXPECT_EQ(log->event_category(), EventCategory::SETTINGS_EVENT); + EXPECT_CALL(event_logger(), Log(An())) + .WillOnce([](const SharingLog& log) { + EXPECT_EQ(log.event_type(), EventType::TAP_HELP); + EXPECT_EQ(log.event_category(), EventCategory::SETTINGS_EVENT); }); analytics_recoder().NewTapHelp(); } TEST_F(AnalyticsRecorderTest, NewLaunchDeviceContactConsent) { - EXPECT_CALL(event_logger(), Log) - .WillOnce([=](const ::google::protobuf::MessageLite& message) { - auto log = dynamic_cast(&message); - ASSERT_NE(log, nullptr); - EXPECT_EQ(log->event_type(), EventType::LAUNCH_CONSENT); - EXPECT_EQ(log->event_category(), EventCategory::SETTINGS_EVENT); - EXPECT_EQ(log->launch_consent().status(), - ::location::nearby::proto::sharing::ConsentAcceptanceStatus:: + EXPECT_CALL(event_logger(), Log(An())) + .WillOnce([](const SharingLog& log) { + EXPECT_EQ(log.event_type(), EventType::LAUNCH_CONSENT); + EXPECT_EQ(log.event_category(), EventCategory::SETTINGS_EVENT); + EXPECT_EQ(log.launch_consent().status(), + location::nearby::proto::sharing::ConsentAcceptanceStatus:: CONSENT_ACCEPTED); }); @@ -194,112 +179,103 @@ TEST_F(AnalyticsRecorderTest, NewLaunchDeviceContactConsent) { } TEST_F(AnalyticsRecorderTest, NewAdvertiseDevicePresenceEnd) { - EXPECT_CALL(event_logger(), Log) - .WillOnce([=](const ::google::protobuf::MessageLite& message) { - auto log = dynamic_cast(&message); - ASSERT_NE(log, nullptr); - EXPECT_EQ(log->event_type(), EventType::ADVERTISE_DEVICE_PRESENCE_END); - EXPECT_EQ(log->event_category(), EventCategory::RECEIVING_EVENT); - EXPECT_EQ(log->advertise_device_presence_end().session_id(), 100); + EXPECT_CALL(event_logger(), Log(An())) + .WillOnce([](const SharingLog& log) { + EXPECT_EQ(log.event_type(), EventType::ADVERTISE_DEVICE_PRESENCE_END); + EXPECT_EQ(log.event_category(), EventCategory::RECEIVING_EVENT); + EXPECT_EQ(log.advertise_device_presence_end().session_id(), 100); }); analytics_recoder().NewAdvertiseDevicePresenceEnd(100); } TEST_F(AnalyticsRecorderTest, NewAdvertiseDevicePresenceStart) { - EXPECT_CALL(event_logger(), Log) - .WillOnce([=](const ::google::protobuf::MessageLite& message) { - auto log = dynamic_cast(&message); - ASSERT_NE(log, nullptr); - EXPECT_EQ(log->event_type(), - EventType::ADVERTISE_DEVICE_PRESENCE_START); - EXPECT_EQ(log->event_category(), EventCategory::RECEIVING_EVENT); - EXPECT_EQ( - log->advertise_device_presence_start().visibility(), - ::location::nearby::proto::sharing::Visibility::CONTACTS_ONLY); - EXPECT_EQ(log->advertise_device_presence_start().status(), - ::location::nearby::proto::sharing::SessionStatus:: + EXPECT_CALL(event_logger(), Log(An())) + .WillOnce([](const SharingLog& log) { + EXPECT_EQ(log.event_type(), EventType::ADVERTISE_DEVICE_PRESENCE_START); + EXPECT_EQ(log.event_category(), EventCategory::RECEIVING_EVENT); + EXPECT_EQ(log.advertise_device_presence_start().visibility(), + location::nearby::proto::sharing::Visibility::CONTACTS_ONLY); + EXPECT_EQ(log.advertise_device_presence_start().status(), + location::nearby::proto::sharing::SessionStatus:: SUCCEEDED_SESSION_STATUS); - EXPECT_EQ(log->advertise_device_presence_start().data_usage(), - ::location::nearby::proto::sharing::DataUsage::OFFLINE); - EXPECT_EQ(log->advertise_device_presence_start().referrer_name(), + EXPECT_EQ(log.advertise_device_presence_start().data_usage(), + location::nearby::proto::sharing::DataUsage::OFFLINE); + EXPECT_EQ(log.advertise_device_presence_start().referrer_name(), kAppPackageName); - EXPECT_EQ(log->advertise_device_presence_start().session_id(), 100); + EXPECT_EQ(log.advertise_device_presence_start().session_id(), 100); }); analytics_recoder().NewAdvertiseDevicePresenceStart( 100, DeviceVisibility::DEVICE_VISIBILITY_ALL_CONTACTS, - ::location::nearby::proto::sharing::SessionStatus:: - SUCCEEDED_SESSION_STATUS, + location::nearby::proto::sharing::SessionStatus::SUCCEEDED_SESSION_STATUS, DataUsage::OFFLINE_DATA_USAGE, std::string(kAppPackageName)); } TEST_F(AnalyticsRecorderTest, NewDescribeAttachments) { - EXPECT_CALL(event_logger(), Log) - .WillOnce([=](const ::google::protobuf::MessageLite& message) { - auto log = dynamic_cast(&message); - ASSERT_NE(log, nullptr); - EXPECT_EQ(log->event_type(), EventType::DESCRIBE_ATTACHMENTS); - EXPECT_EQ(log->event_category(), EventCategory::SENDING_EVENT); - EXPECT_EQ(log->describe_attachments() + EXPECT_CALL(event_logger(), Log(An())) + .WillOnce([](const SharingLog& log) { + EXPECT_EQ(log.event_type(), EventType::DESCRIBE_ATTACHMENTS); + EXPECT_EQ(log.event_category(), EventCategory::SENDING_EVENT); + EXPECT_EQ(log.describe_attachments() .attachments_info() .text_attachment_size(), 5); - EXPECT_EQ(log->describe_attachments() + EXPECT_EQ(log.describe_attachments() .attachments_info() .text_attachment(0) .size_bytes(), kTextBody.size()); - EXPECT_EQ(log->describe_attachments() + EXPECT_EQ(log.describe_attachments() .attachments_info() .text_attachment(0) .type(), SharingLog::TextAttachment::UNKNOWN_TEXT_TYPE); - EXPECT_EQ(log->describe_attachments() + EXPECT_EQ(log.describe_attachments() .attachments_info() .text_attachment(1) .type(), SharingLog::TextAttachment::PHONE_NUMBER); - EXPECT_EQ(log->describe_attachments() + EXPECT_EQ(log.describe_attachments() .attachments_info() .text_attachment(2) .type(), SharingLog::TextAttachment::URL); - EXPECT_EQ(log->describe_attachments() + EXPECT_EQ(log.describe_attachments() .attachments_info() .text_attachment(3) .type(), SharingLog::TextAttachment::ADDRESS); - EXPECT_EQ(log->describe_attachments() + EXPECT_EQ(log.describe_attachments() .attachments_info() .text_attachment(4) .type(), SharingLog::TextAttachment::UNKNOWN_TEXT_TYPE); - EXPECT_EQ(log->describe_attachments() + EXPECT_EQ(log.describe_attachments() .attachments_info() .file_attachment_size(), 4); - EXPECT_EQ(log->describe_attachments() + EXPECT_EQ(log.describe_attachments() .attachments_info() .file_attachment(0) .size_bytes(), 2); - EXPECT_EQ(log->describe_attachments() + EXPECT_EQ(log.describe_attachments() .attachments_info() .file_attachment(0) .type(), SharingLog::FileAttachment::IMAGE); - EXPECT_EQ(log->describe_attachments() + EXPECT_EQ(log.describe_attachments() .attachments_info() .file_attachment(1) .type(), SharingLog::FileAttachment::DOCUMENT); - EXPECT_EQ(log->describe_attachments() + EXPECT_EQ(log.describe_attachments() .attachments_info() .file_attachment(2) .type(), SharingLog::FileAttachment::AUDIO); - EXPECT_EQ(log->describe_attachments() + EXPECT_EQ(log.describe_attachments() .attachments_info() .file_attachment(3) .type(), @@ -337,17 +313,15 @@ TEST_F(AnalyticsRecorderTest, NewDescribeAttachments) { } TEST_F(AnalyticsRecorderTest, EmptyDescribeAttachments) { - EXPECT_CALL(event_logger(), Log) - .WillOnce([=](const ::google::protobuf::MessageLite& message) { - auto log = dynamic_cast(&message); - ASSERT_NE(log, nullptr); - EXPECT_EQ(log->event_type(), EventType::DESCRIBE_ATTACHMENTS); - EXPECT_EQ(log->event_category(), EventCategory::SENDING_EVENT); - EXPECT_EQ(log->describe_attachments() + EXPECT_CALL(event_logger(), Log(An())) + .WillOnce([](const SharingLog& log) { + EXPECT_EQ(log.event_type(), EventType::DESCRIBE_ATTACHMENTS); + EXPECT_EQ(log.event_category(), EventCategory::SENDING_EVENT); + EXPECT_EQ(log.describe_attachments() .attachments_info() .text_attachment_size(), 0); - EXPECT_EQ(log->describe_attachments() + EXPECT_EQ(log.describe_attachments() .attachments_info() .file_attachment_size(), 0); @@ -358,33 +332,29 @@ TEST_F(AnalyticsRecorderTest, EmptyDescribeAttachments) { } TEST_F(AnalyticsRecorderTest, NewDiscoverShareTarget) { - EXPECT_CALL(event_logger(), Log) - .WillOnce([=](const ::google::protobuf::MessageLite& message) { - auto log = dynamic_cast(&message); - ASSERT_NE(log, nullptr); - EXPECT_EQ(log->event_type(), EventType::DISCOVER_SHARE_TARGET); - EXPECT_EQ(log->event_category(), EventCategory::SENDING_EVENT); + EXPECT_CALL(event_logger(), Log(An())) + .WillOnce([](const SharingLog& log) { + EXPECT_EQ(log.event_type(), EventType::DISCOVER_SHARE_TARGET); + EXPECT_EQ(log.event_category(), EventCategory::SENDING_EVENT); + EXPECT_EQ(log.discover_share_target().duration_since_scanning().nanos(), + (2100 % 1000) * 1000000); EXPECT_EQ( - log->discover_share_target().duration_since_scanning().nanos(), - (2100 % 1000) * 1000000); - EXPECT_EQ( - log->discover_share_target().duration_since_scanning().seconds(), + log.discover_share_target().duration_since_scanning().seconds(), 2100 / 1000); EXPECT_EQ( - log->discover_share_target() + log.discover_share_target() .share_target_info() .device_relationship(), ::location::nearby::proto::sharing::DeviceRelationship::IS_CONTACT); - EXPECT_EQ( - log->discover_share_target().share_target_info().device_type(), - ::location::nearby::proto::sharing::DeviceType::LAPTOP); - EXPECT_EQ(log->discover_share_target().share_target_info().os_type(), + EXPECT_EQ(log.discover_share_target().share_target_info().device_type(), + ::location::nearby::proto::sharing::DeviceType::LAPTOP); + EXPECT_EQ(log.discover_share_target().share_target_info().os_type(), ::location::nearby::proto::sharing::OSType::UNKNOWN_OS_TYPE); - EXPECT_EQ(log->discover_share_target().session_id(), 1); - EXPECT_EQ(log->discover_share_target().flow_id(), 100); - EXPECT_FALSE(log->discover_share_target().has_referrer_name()); + EXPECT_EQ(log.discover_share_target().session_id(), 1); + EXPECT_EQ(log.discover_share_target().flow_id(), 100); + EXPECT_FALSE(log.discover_share_target().has_referrer_name()); EXPECT_EQ( - log->discover_share_target().latency_since_activity_start_millis(), + log.discover_share_target().latency_since_activity_start_millis(), 2); }); @@ -399,14 +369,12 @@ TEST_F(AnalyticsRecorderTest, NewDiscoverShareTarget) { } TEST_F(AnalyticsRecorderTest, NewEnableNearbySharing) { - EXPECT_CALL(event_logger(), Log) - .WillOnce([=](const ::google::protobuf::MessageLite& message) { - auto log = dynamic_cast(&message); - ASSERT_NE(log, nullptr); - EXPECT_EQ(log->event_type(), EventType::ENABLE_NEARBY_SHARING); - EXPECT_EQ(log->event_category(), EventCategory::SETTINGS_EVENT); - EXPECT_EQ(log->enable_nearby_sharing().status(), - ::location::nearby::proto::sharing::NearbySharingStatus::ON); + EXPECT_CALL(event_logger(), Log(An())) + .WillOnce([](const SharingLog& log) { + EXPECT_EQ(log.event_type(), EventType::ENABLE_NEARBY_SHARING); + EXPECT_EQ(log.event_category(), EventCategory::SETTINGS_EVENT); + EXPECT_EQ(log.enable_nearby_sharing().status(), + location::nearby::proto::sharing::NearbySharingStatus::ON); }); analytics_recoder().NewEnableNearbySharing( @@ -414,21 +382,19 @@ TEST_F(AnalyticsRecorderTest, NewEnableNearbySharing) { } TEST_F(AnalyticsRecorderTest, NewOpenReceivedAttachments) { - EXPECT_CALL(event_logger(), Log) - .WillOnce([=](const ::google::protobuf::MessageLite& message) { - auto log = dynamic_cast(&message); - ASSERT_NE(log, nullptr); - EXPECT_EQ(log->event_type(), EventType::OPEN_RECEIVED_ATTACHMENTS); - EXPECT_EQ(log->event_category(), EventCategory::RECEIVING_EVENT); - EXPECT_EQ(log->open_received_attachments() + EXPECT_CALL(event_logger(), Log(An())) + .WillOnce([](const SharingLog& log) { + EXPECT_EQ(log.event_type(), EventType::OPEN_RECEIVED_ATTACHMENTS); + EXPECT_EQ(log.event_category(), EventCategory::RECEIVING_EVENT); + EXPECT_EQ(log.open_received_attachments() .attachments_info() .text_attachment_size(), 0); - EXPECT_EQ(log->open_received_attachments() + EXPECT_EQ(log.open_received_attachments() .attachments_info() .file_attachment_size(), 0); - EXPECT_EQ(log->open_received_attachments().session_id(), 1); + EXPECT_EQ(log.open_received_attachments().session_id(), 1); }); analytics_recoder().NewOpenReceivedAttachments( @@ -436,39 +402,35 @@ TEST_F(AnalyticsRecorderTest, NewOpenReceivedAttachments) { } TEST_F(AnalyticsRecorderTest, NewProcessReceivedAttachmentsEnd) { - EXPECT_CALL(event_logger(), Log) - .WillOnce([=](const ::google::protobuf::MessageLite& message) { - auto log = dynamic_cast(&message); - ASSERT_NE(log, nullptr); - EXPECT_EQ(log->event_type(), + EXPECT_CALL(event_logger(), Log(An())) + .WillOnce([](const SharingLog& log) { + EXPECT_EQ(log.event_type(), EventType::PROCESS_RECEIVED_ATTACHMENTS_END); - EXPECT_EQ(log->event_category(), EventCategory::RECEIVING_EVENT); - EXPECT_EQ(log->process_received_attachments_end().session_id(), 1); - EXPECT_EQ(log->process_received_attachments_end().status(), - ::location::nearby::proto::sharing:: - ProcessReceivedAttachmentsStatus:: - PROCESSING_STATUS_COMPLETE_PROCESSING_ATTACHMENTS); + EXPECT_EQ(log.event_category(), EventCategory::RECEIVING_EVENT); + EXPECT_EQ(log.process_received_attachments_end().session_id(), 1); + EXPECT_EQ( + log.process_received_attachments_end().status(), + location::nearby::proto::sharing::ProcessReceivedAttachmentsStatus:: + PROCESSING_STATUS_COMPLETE_PROCESSING_ATTACHMENTS); }); analytics_recoder().NewProcessReceivedAttachmentsEnd( - 1, ::location::nearby::proto::sharing::ProcessReceivedAttachmentsStatus:: + 1, location::nearby::proto::sharing::ProcessReceivedAttachmentsStatus:: PROCESSING_STATUS_COMPLETE_PROCESSING_ATTACHMENTS); } TEST_F(AnalyticsRecorderTest, NewReceiveAttachmentsEnd) { - EXPECT_CALL(event_logger(), Log) - .WillOnce([=](const ::google::protobuf::MessageLite& message) { - auto log = dynamic_cast(&message); - ASSERT_NE(log, nullptr); - EXPECT_EQ(log->event_type(), EventType::RECEIVE_ATTACHMENTS_END); - EXPECT_EQ(log->event_category(), EventCategory::RECEIVING_EVENT); - EXPECT_EQ(log->receive_attachments_end().session_id(), 1); - EXPECT_EQ(log->receive_attachments_end().received_bytes(), 2); + EXPECT_CALL(event_logger(), Log(An())) + .WillOnce([](const SharingLog& log) { + EXPECT_EQ(log.event_type(), EventType::RECEIVE_ATTACHMENTS_END); + EXPECT_EQ(log.event_category(), EventCategory::RECEIVING_EVENT); + EXPECT_EQ(log.receive_attachments_end().session_id(), 1); + EXPECT_EQ(log.receive_attachments_end().received_bytes(), 2); EXPECT_EQ( - log->receive_attachments_end().status(), + log.receive_attachments_end().status(), ::location::nearby::proto::sharing::AttachmentTransmissionStatus:: COMPLETE_ATTACHMENT_TRANSMISSION_STATUS); - EXPECT_EQ(log->receive_attachments_end().referrer_name(), + EXPECT_EQ(log.receive_attachments_end().referrer_name(), kAppPackageName); }); @@ -480,14 +442,12 @@ TEST_F(AnalyticsRecorderTest, NewReceiveAttachmentsEnd) { } TEST_F(AnalyticsRecorderTest, NewReceiveAttachmentsStart) { - EXPECT_CALL(event_logger(), Log) - .WillOnce([=](const ::google::protobuf::MessageLite& message) { - auto log = dynamic_cast(&message); - ASSERT_NE(log, nullptr); - EXPECT_EQ(log->event_type(), EventType::RECEIVE_ATTACHMENTS_START); - EXPECT_EQ(log->event_category(), EventCategory::RECEIVING_EVENT); - EXPECT_EQ(log->receive_attachments_start().session_id(), 1); - EXPECT_EQ(log->receive_attachments_start() + EXPECT_CALL(event_logger(), Log(An())) + .WillOnce([](const SharingLog& log) { + EXPECT_EQ(log.event_type(), EventType::RECEIVE_ATTACHMENTS_START); + EXPECT_EQ(log.event_category(), EventCategory::RECEIVING_EVENT); + EXPECT_EQ(log.receive_attachments_start().session_id(), 1); + EXPECT_EQ(log.receive_attachments_start() .attachments_info() .file_attachment_size(), 0); @@ -498,13 +458,11 @@ TEST_F(AnalyticsRecorderTest, NewReceiveAttachmentsStart) { } TEST_F(AnalyticsRecorderTest, NewReceiveFastInitialization) { - EXPECT_CALL(event_logger(), Log) - .WillOnce([=](const ::google::protobuf::MessageLite& message) { - auto log = dynamic_cast(&message); - ASSERT_NE(log, nullptr); - EXPECT_EQ(log->event_type(), EventType::RECEIVE_FAST_INITIALIZATION); - EXPECT_EQ(log->event_category(), EventCategory::RECEIVING_EVENT); - EXPECT_EQ(log->receive_initialization() + EXPECT_CALL(event_logger(), Log(An())) + .WillOnce([](const SharingLog& log) { + EXPECT_EQ(log.event_type(), EventType::RECEIVE_FAST_INITIALIZATION); + EXPECT_EQ(log.event_category(), EventCategory::RECEIVING_EVENT); + EXPECT_EQ(log.receive_initialization() .time_elapse_since_screen_unlock_millis(), 1); }); @@ -513,42 +471,36 @@ TEST_F(AnalyticsRecorderTest, NewReceiveFastInitialization) { } TEST_F(AnalyticsRecorderTest, NewAcceptFastInitialization) { - EXPECT_CALL(event_logger(), Log) - .WillOnce([=](const ::google::protobuf::MessageLite& message) { - auto log = dynamic_cast(&message); - ASSERT_NE(log, nullptr); - EXPECT_EQ(log->event_type(), EventType::ACCEPT_FAST_INITIALIZATION); - EXPECT_EQ(log->event_category(), EventCategory::RECEIVING_EVENT); + EXPECT_CALL(event_logger(), Log(An())) + .WillOnce([](const SharingLog& log) { + EXPECT_EQ(log.event_type(), EventType::ACCEPT_FAST_INITIALIZATION); + EXPECT_EQ(log.event_category(), EventCategory::RECEIVING_EVENT); }); analytics_recoder().NewAcceptFastInitialization(); } TEST_F(AnalyticsRecorderTest, NewDismissFastInitialization) { - EXPECT_CALL(event_logger(), Log) - .WillOnce([=](const ::google::protobuf::MessageLite& message) { - auto log = dynamic_cast(&message); - ASSERT_NE(log, nullptr); - EXPECT_EQ(log->event_type(), EventType::DISMISS_FAST_INITIALIZATION); - EXPECT_EQ(log->event_category(), EventCategory::RECEIVING_EVENT); + EXPECT_CALL(event_logger(), Log(An())) + .WillOnce([](const SharingLog& log) { + EXPECT_EQ(log.event_type(), EventType::DISMISS_FAST_INITIALIZATION); + EXPECT_EQ(log.event_category(), EventCategory::RECEIVING_EVENT); }); analytics_recoder().NewDismissFastInitialization(); } TEST_F(AnalyticsRecorderTest, NewReceiveIntroduction) { - EXPECT_CALL(event_logger(), Log) - .WillOnce([=](const ::google::protobuf::MessageLite& message) { - auto log = dynamic_cast(&message); - ASSERT_NE(log, nullptr); - EXPECT_EQ(log->event_type(), EventType::RECEIVE_INTRODUCTION); - EXPECT_EQ(log->event_category(), EventCategory::RECEIVING_EVENT); - EXPECT_EQ(log->receive_introduction().session_id(), 1); - EXPECT_EQ(log->receive_introduction().share_target_info().os_type(), + EXPECT_CALL(event_logger(), Log(An())) + .WillOnce([](const SharingLog& log) { + EXPECT_EQ(log.event_type(), EventType::RECEIVE_INTRODUCTION); + EXPECT_EQ(log.event_category(), EventCategory::RECEIVING_EVENT); + EXPECT_EQ(log.receive_introduction().session_id(), 1); + EXPECT_EQ(log.receive_introduction().share_target_info().os_type(), ::location::nearby::proto::sharing::OSType::WINDOWS); - EXPECT_EQ(log->receive_introduction().share_target_info().device_type(), + EXPECT_EQ(log.receive_introduction().share_target_info().device_type(), ::location::nearby::proto::sharing::DeviceType::PHONE); - EXPECT_EQ(log->receive_introduction().referrer_name(), kAppPackageName); + EXPECT_EQ(log.receive_introduction().referrer_name(), kAppPackageName); }); ShareTarget share_target; @@ -559,14 +511,12 @@ TEST_F(AnalyticsRecorderTest, NewReceiveIntroduction) { } TEST_F(AnalyticsRecorderTest, NewRespondToIntroduction) { - EXPECT_CALL(event_logger(), Log) - .WillOnce([=](const ::google::protobuf::MessageLite& message) { - auto log = dynamic_cast(&message); - ASSERT_NE(log, nullptr); - EXPECT_EQ(log->event_type(), EventType::RESPOND_TO_INTRODUCTION); - EXPECT_EQ(log->event_category(), EventCategory::RECEIVING_EVENT); - EXPECT_EQ(log->respond_introduction().session_id(), 1); - EXPECT_EQ(log->respond_introduction().action(), + EXPECT_CALL(event_logger(), Log(An())) + .WillOnce([](const SharingLog& log) { + EXPECT_EQ(log.event_type(), EventType::RESPOND_TO_INTRODUCTION); + EXPECT_EQ(log.event_category(), EventCategory::RECEIVING_EVENT); + EXPECT_EQ(log.respond_introduction().session_id(), 1); + EXPECT_EQ(log.respond_introduction().action(), ::location::nearby::proto::sharing::ResponseToIntroduction:: ACCEPT_INTRODUCTION); }); @@ -578,58 +528,50 @@ TEST_F(AnalyticsRecorderTest, NewRespondToIntroduction) { } TEST_F(AnalyticsRecorderTest, NewTapPrivacyNotification) { - EXPECT_CALL(event_logger(), Log) - .WillOnce([=](const ::google::protobuf::MessageLite& message) { - auto log = dynamic_cast(&message); - ASSERT_NE(log, nullptr); - EXPECT_EQ(log->event_type(), EventType::TAP_PRIVACY_NOTIFICATION); - EXPECT_EQ(log->event_category(), EventCategory::RECEIVING_EVENT); + EXPECT_CALL(event_logger(), Log(An())) + .WillOnce([](const SharingLog& log) { + EXPECT_EQ(log.event_type(), EventType::TAP_PRIVACY_NOTIFICATION); + EXPECT_EQ(log.event_category(), EventCategory::RECEIVING_EVENT); }); analytics_recoder().NewTapPrivacyNotification(); } TEST_F(AnalyticsRecorderTest, NewDismissPrivacyNotification) { - EXPECT_CALL(event_logger(), Log) - .WillOnce([=](const ::google::protobuf::MessageLite& message) { - auto log = dynamic_cast(&message); - ASSERT_NE(log, nullptr); - EXPECT_EQ(log->event_type(), EventType::DISMISS_PRIVACY_NOTIFICATION); - EXPECT_EQ(log->event_category(), EventCategory::RECEIVING_EVENT); + EXPECT_CALL(event_logger(), Log(An())) + .WillOnce([](const SharingLog& log) { + EXPECT_EQ(log.event_type(), EventType::DISMISS_PRIVACY_NOTIFICATION); + EXPECT_EQ(log.event_category(), EventCategory::RECEIVING_EVENT); }); analytics_recoder().NewDismissPrivacyNotification(); } TEST_F(AnalyticsRecorderTest, NewScanForShareTargetsEnd) { - EXPECT_CALL(event_logger(), Log) - .WillOnce([=](const ::google::protobuf::MessageLite& message) { - auto log = dynamic_cast(&message); - ASSERT_NE(log, nullptr); - EXPECT_EQ(log->event_type(), EventType::SCAN_FOR_SHARE_TARGETS_END); - EXPECT_EQ(log->event_category(), EventCategory::SENDING_EVENT); - EXPECT_EQ(log->scan_for_share_targets_end().session_id(), 100); + EXPECT_CALL(event_logger(), Log(An())) + .WillOnce([](const SharingLog& log) { + EXPECT_EQ(log.event_type(), EventType::SCAN_FOR_SHARE_TARGETS_END); + EXPECT_EQ(log.event_category(), EventCategory::SENDING_EVENT); + EXPECT_EQ(log.scan_for_share_targets_end().session_id(), 100); }); analytics_recoder().NewScanForShareTargetsEnd(100); } TEST_F(AnalyticsRecorderTest, NewScanForShareTargetsStart) { - EXPECT_CALL(event_logger(), Log) - .WillOnce([=](const ::google::protobuf::MessageLite& message) { - auto log = dynamic_cast(&message); - ASSERT_NE(log, nullptr); - EXPECT_EQ(log->event_type(), EventType::SCAN_FOR_SHARE_TARGETS_START); - EXPECT_EQ(log->event_category(), EventCategory::SENDING_EVENT); - EXPECT_EQ(log->scan_for_share_targets_start().session_id(), 3); - EXPECT_EQ(log->scan_for_share_targets_start().status(), + EXPECT_CALL(event_logger(), Log(An())) + .WillOnce([](const SharingLog& log) { + EXPECT_EQ(log.event_type(), EventType::SCAN_FOR_SHARE_TARGETS_START); + EXPECT_EQ(log.event_category(), EventCategory::SENDING_EVENT); + EXPECT_EQ(log.scan_for_share_targets_start().session_id(), 3); + EXPECT_EQ(log.scan_for_share_targets_start().status(), ::location::nearby::proto::sharing::SessionStatus:: FAILED_SESSION_STATUS); - EXPECT_EQ(log->scan_for_share_targets_start().flow_id(), 100); + EXPECT_EQ(log.scan_for_share_targets_start().flow_id(), 100); EXPECT_EQ( - log->scan_for_share_targets_start().scan_type(), + log.scan_for_share_targets_start().scan_type(), ::location::nearby::proto::sharing::ScanType::FOREGROUND_SCAN); - EXPECT_FALSE(log->scan_for_share_targets_start().has_referrer_name()); + EXPECT_FALSE(log.scan_for_share_targets_start().has_referrer_name()); }); analytics_recoder().NewScanForShareTargetsStart( @@ -639,26 +581,24 @@ TEST_F(AnalyticsRecorderTest, NewScanForShareTargetsStart) { } TEST_F(AnalyticsRecorderTest, NewSendAttachmentsEnd) { - EXPECT_CALL(event_logger(), Log) - .WillOnce([=](const ::google::protobuf::MessageLite& message) { - auto log = dynamic_cast(&message); - ASSERT_NE(log, nullptr); - EXPECT_EQ(log->event_type(), EventType::SEND_ATTACHMENTS_END); - EXPECT_EQ(log->event_category(), EventCategory::SENDING_EVENT); - EXPECT_EQ(log->send_attachments_end().session_id(), 1); - EXPECT_EQ(log->send_attachments_end().sent_bytes(), 2); - EXPECT_EQ(log->send_attachments_end().share_target_info().os_type(), + EXPECT_CALL(event_logger(), Log(An())) + .WillOnce([](const SharingLog& log) { + EXPECT_EQ(log.event_type(), EventType::SEND_ATTACHMENTS_END); + EXPECT_EQ(log.event_category(), EventCategory::SENDING_EVENT); + EXPECT_EQ(log.send_attachments_end().session_id(), 1); + EXPECT_EQ(log.send_attachments_end().sent_bytes(), 2); + EXPECT_EQ(log.send_attachments_end().share_target_info().os_type(), ::location::nearby::proto::sharing::OSType::ANDROID); - EXPECT_EQ(log->send_attachments_end().share_target_info().device_type(), + EXPECT_EQ(log.send_attachments_end().share_target_info().device_type(), ::location::nearby::proto::sharing::DeviceType::PHONE); - EXPECT_EQ(log->send_attachments_end().transfer_position(), 1); - EXPECT_EQ(log->send_attachments_end().concurrent_connections(), 2); - EXPECT_EQ(log->send_attachments_end().duration_millis(), 100); + EXPECT_EQ(log.send_attachments_end().transfer_position(), 1); + EXPECT_EQ(log.send_attachments_end().concurrent_connections(), 2); + EXPECT_EQ(log.send_attachments_end().duration_millis(), 100); EXPECT_EQ( - log->send_attachments_end().status(), + log.send_attachments_end().status(), ::location::nearby::proto::sharing::AttachmentTransmissionStatus:: COMPLETE_ATTACHMENT_TRANSMISSION_STATUS); - EXPECT_EQ(log->send_attachments_end().referrer_name(), kAppPackageName); + EXPECT_EQ(log.send_attachments_end().referrer_name(), kAppPackageName); }); ShareTarget share_target; @@ -675,19 +615,17 @@ TEST_F(AnalyticsRecorderTest, NewSendAttachmentsEnd) { } TEST_F(AnalyticsRecorderTest, NewSendAttachmentsStart) { - EXPECT_CALL(event_logger(), Log) - .WillOnce([=](const ::google::protobuf::MessageLite& message) { - auto log = dynamic_cast(&message); - ASSERT_NE(log, nullptr); - EXPECT_EQ(log->event_type(), EventType::SEND_ATTACHMENTS_START); - EXPECT_EQ(log->event_category(), EventCategory::SENDING_EVENT); - EXPECT_EQ(log->send_attachments_start().session_id(), 1); - EXPECT_EQ(log->send_attachments_start() + EXPECT_CALL(event_logger(), Log(An())) + .WillOnce([](const SharingLog& log) { + EXPECT_EQ(log.event_type(), EventType::SEND_ATTACHMENTS_START); + EXPECT_EQ(log.event_category(), EventCategory::SENDING_EVENT); + EXPECT_EQ(log.send_attachments_start().session_id(), 1); + EXPECT_EQ(log.send_attachments_start() .attachments_info() .file_attachment_size(), 0); - EXPECT_EQ(log->send_attachments_start().transfer_position(), 100); - EXPECT_EQ(log->send_attachments_start().concurrent_connections(), 200); + EXPECT_EQ(log.send_attachments_start().transfer_position(), 100); + EXPECT_EQ(log.send_attachments_start().concurrent_connections(), 200); }); analytics_recoder().NewSendAttachmentsStart( @@ -695,30 +633,26 @@ TEST_F(AnalyticsRecorderTest, NewSendAttachmentsStart) { } TEST_F(AnalyticsRecorderTest, NewSendFastInitialization) { - EXPECT_CALL(event_logger(), Log) - .WillOnce([=](const ::google::protobuf::MessageLite& message) { - auto log = dynamic_cast(&message); - ASSERT_NE(log, nullptr); - EXPECT_EQ(log->event_type(), EventType::SEND_FAST_INITIALIZATION); - EXPECT_EQ(log->event_category(), EventCategory::SENDING_EVENT); + EXPECT_CALL(event_logger(), Log(An())) + .WillOnce([](const SharingLog& log) { + EXPECT_EQ(log.event_type(), EventType::SEND_FAST_INITIALIZATION); + EXPECT_EQ(log.event_category(), EventCategory::SENDING_EVENT); }); analytics_recoder().NewSendFastInitialization(); } TEST_F(AnalyticsRecorderTest, NewSendStart) { - EXPECT_CALL(event_logger(), Log) - .WillOnce([=](const ::google::protobuf::MessageLite& message) { - auto log = dynamic_cast(&message); - ASSERT_NE(log, nullptr); - EXPECT_EQ(log->event_type(), EventType::SEND_START); - EXPECT_EQ(log->event_category(), EventCategory::SENDING_EVENT); - EXPECT_EQ(log->send_start().session_id(), 123); - EXPECT_EQ(log->send_start().transfer_position(), 1); - EXPECT_EQ(log->send_start().concurrent_connections(), 2); - EXPECT_EQ(log->send_start().share_target_info().device_type(), + EXPECT_CALL(event_logger(), Log(An())) + .WillOnce([](const SharingLog& log) { + EXPECT_EQ(log.event_type(), EventType::SEND_START); + EXPECT_EQ(log.event_category(), EventCategory::SENDING_EVENT); + EXPECT_EQ(log.send_start().session_id(), 123); + EXPECT_EQ(log.send_start().transfer_position(), 1); + EXPECT_EQ(log.send_start().concurrent_connections(), 2); + EXPECT_EQ(log.send_start().share_target_info().device_type(), ::location::nearby::proto::sharing::DeviceType::LAPTOP); - EXPECT_EQ(log->send_start().share_target_info().os_type(), + EXPECT_EQ(log.send_start().share_target_info().os_type(), ::location::nearby::proto::sharing::OSType::UNKNOWN_OS_TYPE); }); @@ -731,19 +665,17 @@ TEST_F(AnalyticsRecorderTest, NewSendStart) { } TEST_F(AnalyticsRecorderTest, NewSendIntroductionWithRelationship) { - EXPECT_CALL(event_logger(), Log) - .WillOnce([=](const ::google::protobuf::MessageLite& message) { - auto log = dynamic_cast(&message); - ASSERT_NE(log, nullptr); - EXPECT_EQ(log->event_type(), EventType::SEND_INTRODUCTION); - EXPECT_EQ(log->event_category(), EventCategory::SENDING_EVENT); - EXPECT_EQ(log->send_introduction().session_id(), 5); - EXPECT_EQ(log->send_introduction().share_target_info().device_type(), + EXPECT_CALL(event_logger(), Log(An())) + .WillOnce([](const SharingLog& log) { + EXPECT_EQ(log.event_type(), EventType::SEND_INTRODUCTION); + EXPECT_EQ(log.event_category(), EventCategory::SENDING_EVENT); + EXPECT_EQ(log.send_introduction().session_id(), 5); + EXPECT_EQ(log.send_introduction().share_target_info().device_type(), ::location::nearby::proto::sharing::DeviceType::LAPTOP); - EXPECT_EQ(log->send_introduction().share_target_info().os_type(), + EXPECT_EQ(log.send_introduction().share_target_info().os_type(), ::location::nearby::proto::sharing::OSType::MACOS); EXPECT_EQ( - log->send_introduction().share_target_info().device_relationship(), + log.send_introduction().share_target_info().device_relationship(), ::location::nearby::proto::sharing::DeviceRelationship::IS_CONTACT); }); @@ -754,18 +686,16 @@ TEST_F(AnalyticsRecorderTest, NewSendIntroductionWithRelationship) { } TEST_F(AnalyticsRecorderTest, NewSendIntroduction) { - EXPECT_CALL(event_logger(), Log) - .WillOnce([=](const ::google::protobuf::MessageLite& message) { - auto log = dynamic_cast(&message); - ASSERT_NE(log, nullptr); - EXPECT_EQ(log->event_type(), EventType::SEND_INTRODUCTION); - EXPECT_EQ(log->event_category(), EventCategory::SENDING_EVENT); - EXPECT_EQ(log->send_introduction().session_id(), 1); - EXPECT_EQ(log->send_introduction().transfer_position(), 2); - EXPECT_EQ(log->send_introduction().concurrent_connections(), 3); - EXPECT_EQ(log->send_introduction().share_target_info().device_type(), + EXPECT_CALL(event_logger(), Log(An())) + .WillOnce([](const SharingLog& log) { + EXPECT_EQ(log.event_type(), EventType::SEND_INTRODUCTION); + EXPECT_EQ(log.event_category(), EventCategory::SENDING_EVENT); + EXPECT_EQ(log.send_introduction().session_id(), 1); + EXPECT_EQ(log.send_introduction().transfer_position(), 2); + EXPECT_EQ(log.send_introduction().concurrent_connections(), 3); + EXPECT_EQ(log.send_introduction().share_target_info().device_type(), ::location::nearby::proto::sharing::DeviceType::LAPTOP); - EXPECT_EQ(log->send_introduction().share_target_info().os_type(), + EXPECT_EQ(log.send_introduction().share_target_info().os_type(), ::location::nearby::proto::sharing::OSType::UNKNOWN_OS_TYPE); }); @@ -777,17 +707,15 @@ TEST_F(AnalyticsRecorderTest, NewSendIntroduction) { } TEST_F(AnalyticsRecorderTest, NewSetVisibility) { - EXPECT_CALL(event_logger(), Log) - .WillOnce([=](const ::google::protobuf::MessageLite& message) { - auto log = dynamic_cast(&message); - ASSERT_NE(log, nullptr); - EXPECT_EQ(log->event_type(), EventType::SET_VISIBILITY); - EXPECT_EQ(log->event_category(), EventCategory::SETTINGS_EVENT); - EXPECT_EQ(log->set_visibility().duration_millis(), 100); - EXPECT_EQ(log->set_visibility().source_visibility(), + EXPECT_CALL(event_logger(), Log(An())) + .WillOnce([](const SharingLog& log) { + EXPECT_EQ(log.event_type(), EventType::SET_VISIBILITY); + EXPECT_EQ(log.event_category(), EventCategory::SETTINGS_EVENT); + EXPECT_EQ(log.set_visibility().duration_millis(), 100); + EXPECT_EQ(log.set_visibility().source_visibility(), ::location::nearby::proto::sharing::Visibility::EVERYONE); EXPECT_EQ( - log->set_visibility().visibility(), + log.set_visibility().visibility(), ::location::nearby::proto::sharing::Visibility::CONTACTS_ONLY); }); @@ -797,18 +725,16 @@ TEST_F(AnalyticsRecorderTest, NewSetVisibility) { } TEST_F(AnalyticsRecorderTest, NewDeviceSettings) { - EXPECT_CALL(event_logger(), Log) - .WillOnce([=](const ::google::protobuf::MessageLite& message) { - auto log = dynamic_cast(&message); - ASSERT_NE(log, nullptr); - EXPECT_EQ(log->event_type(), EventType::DEVICE_SETTINGS); - EXPECT_EQ(log->event_category(), EventCategory::SETTINGS_EVENT); - EXPECT_EQ(log->device_settings().device_name_size(), 10); - EXPECT_EQ(log->device_settings().visibility(), + EXPECT_CALL(event_logger(), Log(An())) + .WillOnce([](const SharingLog& log) { + EXPECT_EQ(log.event_type(), EventType::DEVICE_SETTINGS); + EXPECT_EQ(log.event_category(), EventCategory::SETTINGS_EVENT); + EXPECT_EQ(log.device_settings().device_name_size(), 10); + EXPECT_EQ(log.device_settings().visibility(), ::location::nearby::proto::sharing::Visibility::EVERYONE); - EXPECT_EQ(log->device_settings().data_usage(), + EXPECT_EQ(log.device_settings().data_usage(), ::location::nearby::proto::sharing::DataUsage::WIFI_ONLY); - EXPECT_EQ(log->device_settings().is_show_notification_enabled(), true); + EXPECT_EQ(log.device_settings().is_show_notification_enabled(), true); }); AnalyticsDeviceSettings device_settings; @@ -820,17 +746,15 @@ TEST_F(AnalyticsRecorderTest, NewDeviceSettings) { } TEST_F(AnalyticsRecorderTest, NewFastShareServerResponse) { - EXPECT_CALL(event_logger(), Log) - .WillOnce([=](const ::google::protobuf::MessageLite& message) { - auto log = dynamic_cast(&message); - ASSERT_NE(log, nullptr); - EXPECT_EQ(log->event_type(), EventType::FAST_SHARE_SERVER_RESPONSE); - EXPECT_EQ(log->event_category(), EventCategory::SETTINGS_EVENT); - EXPECT_EQ(log->fast_share_server_response().latency_millis(), 200); - EXPECT_EQ(log->fast_share_server_response().name(), + EXPECT_CALL(event_logger(), Log(An())) + .WillOnce([](const SharingLog& log) { + EXPECT_EQ(log.event_type(), EventType::FAST_SHARE_SERVER_RESPONSE); + EXPECT_EQ(log.event_category(), EventCategory::SETTINGS_EVENT); + EXPECT_EQ(log.fast_share_server_response().latency_millis(), 200); + EXPECT_EQ(log.fast_share_server_response().name(), ::location::nearby::proto::sharing::ServerActionName:: UPLOAD_CONTACTS); - EXPECT_EQ(log->fast_share_server_response().status(), + EXPECT_EQ(log.fast_share_server_response().status(), ::location::nearby::proto::sharing::ServerResponseState:: SERVER_RESPONSE_SUCCESS); }); @@ -843,15 +767,13 @@ TEST_F(AnalyticsRecorderTest, NewFastShareServerResponse) { } TEST_F(AnalyticsRecorderTest, NewSetDataUsage) { - EXPECT_CALL(event_logger(), Log) - .WillOnce([=](const ::google::protobuf::MessageLite& message) { - auto log = dynamic_cast(&message); - ASSERT_NE(log, nullptr); - EXPECT_EQ(log->event_type(), EventType::SET_DATA_USAGE); - EXPECT_EQ(log->event_category(), EventCategory::SETTINGS_EVENT); - EXPECT_EQ(log->set_data_usage().preference(), + EXPECT_CALL(event_logger(), Log(An())) + .WillOnce([](const SharingLog& log) { + EXPECT_EQ(log.event_type(), EventType::SET_DATA_USAGE); + EXPECT_EQ(log.event_category(), EventCategory::SETTINGS_EVENT); + EXPECT_EQ(log.set_data_usage().preference(), ::location::nearby::proto::sharing::DataUsage::OFFLINE); - EXPECT_EQ(log->set_data_usage().original_preference(), + EXPECT_EQ(log.set_data_usage().original_preference(), ::location::nearby::proto::sharing::DataUsage::WIFI_ONLY); }); @@ -860,52 +782,44 @@ TEST_F(AnalyticsRecorderTest, NewSetDataUsage) { } TEST_F(AnalyticsRecorderTest, NewAddQuickSettingsTile) { - EXPECT_CALL(event_logger(), Log) - .WillOnce([=](const ::google::protobuf::MessageLite& message) { - auto log = dynamic_cast(&message); - ASSERT_NE(log, nullptr); - EXPECT_EQ(log->event_type(), EventType::ADD_QUICK_SETTINGS_TILE); - EXPECT_EQ(log->event_category(), EventCategory::SETTINGS_EVENT); + EXPECT_CALL(event_logger(), Log(An())) + .WillOnce([](const SharingLog& log) { + EXPECT_EQ(log.event_type(), EventType::ADD_QUICK_SETTINGS_TILE); + EXPECT_EQ(log.event_category(), EventCategory::SETTINGS_EVENT); }); analytics_recoder().NewAddQuickSettingsTile(); } TEST_F(AnalyticsRecorderTest, NewRemoveQuickSettingsTile) { - EXPECT_CALL(event_logger(), Log) - .WillOnce([=](const ::google::protobuf::MessageLite& message) { - auto log = dynamic_cast(&message); - ASSERT_NE(log, nullptr); - EXPECT_EQ(log->event_type(), EventType::REMOVE_QUICK_SETTINGS_TILE); - EXPECT_EQ(log->event_category(), EventCategory::SETTINGS_EVENT); + EXPECT_CALL(event_logger(), Log(An())) + .WillOnce([](const SharingLog& log) { + EXPECT_EQ(log.event_type(), EventType::REMOVE_QUICK_SETTINGS_TILE); + EXPECT_EQ(log.event_category(), EventCategory::SETTINGS_EVENT); }); analytics_recoder().NewRemoveQuickSettingsTile(); } TEST_F(AnalyticsRecorderTest, NewTapQuickSettingsTile) { - EXPECT_CALL(event_logger(), Log) - .WillOnce([=](const ::google::protobuf::MessageLite& message) { - auto log = dynamic_cast(&message); - ASSERT_NE(log, nullptr); - EXPECT_EQ(log->event_type(), EventType::TAP_QUICK_SETTINGS_TILE); - EXPECT_EQ(log->event_category(), EventCategory::SETTINGS_EVENT); + EXPECT_CALL(event_logger(), Log(An())) + .WillOnce([](const SharingLog& log) { + EXPECT_EQ(log.event_type(), EventType::TAP_QUICK_SETTINGS_TILE); + EXPECT_EQ(log.event_category(), EventCategory::SETTINGS_EVENT); }); analytics_recoder().NewTapQuickSettingsTile(); } TEST_F(AnalyticsRecorderTest, NewToggleShowNotification) { - EXPECT_CALL(event_logger(), Log) - .WillOnce([=](const ::google::protobuf::MessageLite& message) { - auto log = dynamic_cast(&message); - ASSERT_NE(log, nullptr); - EXPECT_EQ(log->event_type(), EventType::TOGGLE_SHOW_NOTIFICATION); - EXPECT_EQ(log->event_category(), EventCategory::SETTINGS_EVENT); + EXPECT_CALL(event_logger(), Log(An())) + .WillOnce([](const SharingLog& log) { + EXPECT_EQ(log.event_type(), EventType::TOGGLE_SHOW_NOTIFICATION); + EXPECT_EQ(log.event_category(), EventCategory::SETTINGS_EVENT); EXPECT_EQ( - log->toggle_show_notification().previous_status(), + log.toggle_show_notification().previous_status(), ::location::nearby::proto::sharing::ShowNotificationStatus::SHOW); - EXPECT_EQ(log->toggle_show_notification().current_status(), + EXPECT_EQ(log.toggle_show_notification().current_status(), ::location::nearby::proto::sharing::ShowNotificationStatus:: NOT_SHOW); }); @@ -916,30 +830,26 @@ TEST_F(AnalyticsRecorderTest, NewToggleShowNotification) { } TEST_F(AnalyticsRecorderTest, NewSetDeviceName) { - EXPECT_CALL(event_logger(), Log) - .WillOnce([=](const ::google::protobuf::MessageLite& message) { - auto log = dynamic_cast(&message); - ASSERT_NE(log, nullptr); - EXPECT_EQ(log->event_type(), EventType::SET_DEVICE_NAME); - EXPECT_EQ(log->event_category(), EventCategory::SETTINGS_EVENT); - EXPECT_EQ(log->set_device_name().device_name_size(), 16); + EXPECT_CALL(event_logger(), Log(An())) + .WillOnce([](const SharingLog& log) { + EXPECT_EQ(log.event_type(), EventType::SET_DEVICE_NAME); + EXPECT_EQ(log.event_category(), EventCategory::SETTINGS_EVENT); + EXPECT_EQ(log.set_device_name().device_name_size(), 16); }); analytics_recoder().NewSetDeviceName(16); } TEST_F(AnalyticsRecorderTest, NewRequestSettingPermissions) { - EXPECT_CALL(event_logger(), Log) - .WillOnce([=](const ::google::protobuf::MessageLite& message) { - auto log = dynamic_cast(&message); - ASSERT_NE(log, nullptr); - EXPECT_EQ(log->event_type(), EventType::REQUEST_SETTING_PERMISSIONS); - EXPECT_EQ(log->event_category(), EventCategory::SETTINGS_EVENT); - EXPECT_EQ(log->request_setting_permissions().permission_type(), + EXPECT_CALL(event_logger(), Log(An())) + .WillOnce([](const SharingLog& log) { + EXPECT_EQ(log.event_type(), EventType::REQUEST_SETTING_PERMISSIONS); + EXPECT_EQ(log.event_category(), EventCategory::SETTINGS_EVENT); + EXPECT_EQ(log.request_setting_permissions().permission_type(), ::location::nearby::proto::sharing::PermissionRequestType:: PERMISSION_BLUETOOTH); EXPECT_EQ( - log->request_setting_permissions().permission_request_result(), + log.request_setting_permissions().permission_request_result(), ::location::nearby::proto::sharing::PermissionRequestResult:: PERMISSION_GRANTED); }); @@ -952,17 +862,15 @@ TEST_F(AnalyticsRecorderTest, NewRequestSettingPermissions) { } TEST_F(AnalyticsRecorderTest, NewInstallAPKStatus) { - EXPECT_CALL(event_logger(), Log) - .WillOnce([=](const ::google::protobuf::MessageLite& message) { - auto log = dynamic_cast(&message); - ASSERT_NE(log, nullptr); - EXPECT_EQ(log->event_type(), EventType::INSTALL_APK); - EXPECT_EQ(log->event_category(), EventCategory::RECEIVING_EVENT); - EXPECT_EQ(log->install_apk_status().status(0), + EXPECT_CALL(event_logger(), Log(An())) + .WillOnce([](const SharingLog& log) { + EXPECT_EQ(log.event_type(), EventType::INSTALL_APK); + EXPECT_EQ(log.event_category(), EventCategory::RECEIVING_EVENT); + EXPECT_EQ(log.install_apk_status().status(0), ::location::nearby::proto::sharing::InstallAPKStatus:: SUCCESS_INSTALLATION); EXPECT_EQ( - log->install_apk_status().source(0), + log.install_apk_status().source(0), ::location::nearby::proto::sharing::ApkSource::APK_FROM_SD_CARD); }); @@ -973,17 +881,15 @@ TEST_F(AnalyticsRecorderTest, NewInstallAPKStatus) { } TEST_F(AnalyticsRecorderTest, NewVerifyAPKStatus) { - EXPECT_CALL(event_logger(), Log) - .WillOnce([=](const ::google::protobuf::MessageLite& message) { - auto log = dynamic_cast(&message); - ASSERT_NE(log, nullptr); - EXPECT_EQ(log->event_type(), EventType::VERIFY_APK); - EXPECT_EQ(log->event_category(), EventCategory::RECEIVING_EVENT); + EXPECT_CALL(event_logger(), Log(An())) + .WillOnce([](const SharingLog& log) { + EXPECT_EQ(log.event_type(), EventType::VERIFY_APK); + EXPECT_EQ(log.event_category(), EventCategory::RECEIVING_EVENT); EXPECT_EQ( - log->verify_apk_status().status(0), + log.verify_apk_status().status(0), ::location::nearby::proto::sharing::VerifyAPKStatus::INSTALLABLE); EXPECT_EQ( - log->verify_apk_status().source(0), + log.verify_apk_status().source(0), ::location::nearby::proto::sharing::ApkSource::APK_FROM_SD_CARD); }); diff --git a/sharing/nearby_sharing_event_logger.cc b/sharing/nearby_sharing_event_logger.cc index 425060ba..37ea2ee4 100644 --- a/sharing/nearby_sharing_event_logger.cc +++ b/sharing/nearby_sharing_event_logger.cc @@ -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 diff --git a/sharing/nearby_sharing_event_logger.h b/sharing/nearby_sharing_event_logger.h index 0842754c..53c8d4b4 100644 --- a/sharing/nearby_sharing_event_logger.h +++ b/sharing/nearby_sharing_event_logger.h @@ -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_; diff --git a/sharing/nearby_sharing_event_logger_test.cc b/sharing/nearby_sharing_event_logger_test.cc index 3dbd885b..7b373736 100644 --- a/sharing/nearby_sharing_event_logger_test.cc +++ b/sharing/nearby_sharing_event_logger_test.cc @@ -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 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(&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())) + .WillOnce([&](const SharingLog& message) { + EXPECT_EQ(message.event_category(), EventCategory::SETTINGS_EVENT); + EXPECT_EQ(message.event_type(), EventType::TAP_HELP); }); std::unique_ptr 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())).Times(0); std::unique_ptr event = GetTestEvent(); sharing_event_logger()->Log(*event);