diff --git a/gen_proto.sh b/gen_proto.sh index d59e79be..09a33ed5 100755 --- a/gen_proto.sh +++ b/gen_proto.sh @@ -17,7 +17,6 @@ COMPILED_PROTO_PATH="compiled_proto" ${PROTOC} --cpp_out=${COMPILED_PROTO_PATH} internal/proto/analytics/connections_log.proto -${PROTOC} --cpp_out=${COMPILED_PROTO_PATH} internal/proto/analytics/experiments_log.proto ${PROTOC} --cpp_out=${COMPILED_PROTO_PATH} internal/proto/analytics/fast_pair_log.proto ${PROTOC} --cpp_out=${COMPILED_PROTO_PATH} sharing/proto/analytics/nearby_sharing_log.proto ${PROTOC} --cpp_out=${COMPILED_PROTO_PATH} proto/fast_pair_enums.proto diff --git a/internal/analytics/BUILD b/internal/analytics/BUILD index 38417a5b..14d5c1bb 100644 --- a/internal/analytics/BUILD +++ b/internal/analytics/BUILD @@ -28,7 +28,6 @@ cc_library( ], 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", ], diff --git a/internal/analytics/event_logger.h b/internal/analytics/event_logger.h index 43c18178..49962d48 100644 --- a/internal/analytics/event_logger.h +++ b/internal/analytics/event_logger.h @@ -16,7 +16,6 @@ #define NEARBY_ANALYTICS_EVENT_LOGGER_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" @@ -36,10 +35,6 @@ class EventLogger { 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 9378ff5f..36e443e7 100644 --- a/internal/analytics/mock_event_logger.h +++ b/internal/analytics/mock_event_logger.h @@ -33,9 +33,6 @@ class MockEventLogger : public ::nearby::analytics::EventLogger { (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 eec05596..2105f2eb 100644 --- a/internal/proto/analytics/BUILD +++ b/internal/proto/analytics/BUILD @@ -56,21 +56,6 @@ cc_proto_library( deps = [":connections_log_proto"], ) -proto_library( - name = "experiments_log_proto", - srcs = ["experiments_log.proto"], -) - -cc_proto_library( - name = "experiments_log_cc_proto", - visibility = [ - "//internal/analytics:__pkg__", - "//location/nearby/analytics/cpp/logging:__subpackages__", - "//location/nearby/cpp/experiments:__subpackages__", - ], - deps = [":experiments_log_proto"], -) - cc_test( name = "proto_analytics_test", size = "small", diff --git a/internal/proto/analytics/experiments_log.proto b/internal/proto/analytics/experiments_log.proto deleted file mode 100644 index 622c6220..00000000 --- a/internal/proto/analytics/experiments_log.proto +++ /dev/null @@ -1,41 +0,0 @@ -// Copyright 2024 Google LLC -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// https://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -syntax = "proto2"; - -package nearby.experiments; - -// import "storage/datapol/annotations/proto/semantic_annotations.proto"; - -option optimize_for = LITE_RUNTIME; -option java_outer_classname = "ExperimentsLogProtos"; -option java_package = "com.google.nearby.experiments"; -// option (datapol.file_vetting_status) = "latest"; - -// This proto encapsulates the experiments info to identify which logs belong -// to which experiments. It's passed from Phenotype -// (google3/location/nearby/cpp/experiments) to Clearcut event logger -// (google3/location/nearby/analytics/cpp/logging/) so that the event logger -// can generate the experiment-based Rasta metrics (go/rasta-overview). -// NextId: 3 -message ExperimentsLog { - // Experiment token associated with the Mendel config package. - optional bytes experiment_token = 1 - /* type = ST_EXPERIMENT_ID */; - - // Zwieback cookie shared between Phenotype and Clearcut clients so that - // Rasta metrics can reflect the correct population of devices. - optional string zwieback_cookie = 2 - /* type = ST_ZWIEBACK_ID */; -} diff --git a/sharing/BUILD b/sharing/BUILD index c9cfe767..6f867e78 100644 --- a/sharing/BUILD +++ b/sharing/BUILD @@ -109,7 +109,6 @@ cc_library( "nearby_file_handler.cc", "nearby_share_profile_info_provider_impl.cc", "nearby_sharing_decoder_impl.cc", - "nearby_sharing_event_logger.cc", "nearby_sharing_service.cc", "nearby_sharing_service_extension.cc", "nearby_sharing_service_factory.cc", @@ -137,7 +136,6 @@ cc_library( "nearby_file_handler.h", "nearby_share_profile_info_provider_impl.h", "nearby_sharing_decoder_impl.h", - "nearby_sharing_event_logger.h", "nearby_sharing_service.h", "nearby_sharing_service_extension.h", "nearby_sharing_service_factory.h", @@ -297,7 +295,6 @@ cc_test( "nearby_connections_types_test.cc", "nearby_file_handler_test.cc", "nearby_share_profile_info_provider_impl_test.cc", - "nearby_sharing_event_logger_test.cc", "nearby_sharing_service_extension_test.cc", "nearby_sharing_service_impl_test.cc", "nearby_sharing_service_test.cc", diff --git a/sharing/nearby_sharing_event_logger.cc b/sharing/nearby_sharing_event_logger.cc deleted file mode 100644 index 37ea2ee4..00000000 --- a/sharing/nearby_sharing_event_logger.cc +++ /dev/null @@ -1,90 +0,0 @@ -// Copyright 2022 Google LLC -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// https://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -#include "sharing/nearby_sharing_event_logger.h" - -#include "internal/analytics/event_logger.h" -#include "sharing/common/nearby_share_prefs.h" -#include "sharing/internal/api/preference_manager.h" - -namespace nearby { -namespace sharing { - -using ::nearby::sharing::api::PreferenceManager; - -NearbySharingEventLogger::NearbySharingEventLogger( - const PreferenceManager& preference_manager, - nearby::analytics::EventLogger* event_logger) - : preference_manager_(preference_manager), event_logger_(event_logger) {} - -NearbySharingEventLogger::~NearbySharingEventLogger() = default; - -void NearbySharingEventLogger::Log( - const location::nearby::analytics::proto::ConnectionsLog& message) { - if (event_logger_ == nullptr) { - return; - } - - if (!preference_manager_.GetBoolean( - prefs::kNearbySharingIsAnalyticsEnabledName, false)) { - return; - } - - 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 deleted file mode 100644 index 53c8d4b4..00000000 --- a/sharing/nearby_sharing_event_logger.h +++ /dev/null @@ -1,49 +0,0 @@ -// Copyright 2022 Google LLC -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// https://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -#ifndef THIRD_PARTY_NEARBY_SHARING_NEARBY_SHARING_EVENT_LOGGER_H_ -#define THIRD_PARTY_NEARBY_SHARING_NEARBY_SHARING_EVENT_LOGGER_H_ - -#include "internal/analytics/event_logger.h" -#include "sharing/internal/api/preference_manager.h" - -namespace nearby { -namespace sharing { - -// Nearby Sharing SDK needs to enable/disable of the event logger according to -// user settings. NearbySharingEventLogger skips analytics logging if analytics -// logging is disabled. -class NearbySharingEventLogger : public nearby::analytics::EventLogger { - public: - NearbySharingEventLogger( - const nearby::sharing::api::PreferenceManager& preference_manager, - nearby::analytics::EventLogger* event_logger); - ~NearbySharingEventLogger() 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_; - nearby::analytics::EventLogger* const event_logger_; -}; - -} // namespace sharing -} // namespace nearby - -#endif // THIRD_PARTY_NEARBY_SHARING_NEARBY_SHARING_EVENT_LOGGER_H_ diff --git a/sharing/nearby_sharing_event_logger_test.cc b/sharing/nearby_sharing_event_logger_test.cc deleted file mode 100644 index 7b373736..00000000 --- a/sharing/nearby_sharing_event_logger_test.cc +++ /dev/null @@ -1,101 +0,0 @@ -// Copyright 2022 Google LLC -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// https://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -#include "sharing/nearby_sharing_event_logger.h" - -#include -#include - -#include "gmock/gmock.h" -#include "protobuf-matchers/protocol-buffer-matchers.h" -#include "gtest/gtest.h" -#include "internal/analytics/mock_event_logger.h" -#include "proto/sharing_enums.pb.h" -#include "sharing/common/nearby_share_prefs.h" -#include "sharing/internal/test/fake_preference_manager.h" -#include "sharing/proto/analytics/nearby_sharing_log.pb.h" -#include "google/protobuf/message_lite.h" - -namespace nearby { -namespace sharing { -namespace { -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: - NearbySharingEventLoggerTest() = default; - - void SetUp() override { - event_logger_ = std::make_unique(); - sharing_event_logger_ = std::make_unique( - preference_manager_, event_logger_.get()); - } - - void SetEventLogger(bool enabled) { - preference_manager_.SetBoolean(prefs::kNearbySharingIsAnalyticsEnabledName, - enabled); - } - - MockEventLogger* event_logger() { return event_logger_.get(); } - - std::unique_ptr GetTestEvent() { - auto sharing_log = - std::unique_ptr(SharingLog::default_instance().New()); - sharing_log->set_event_category(EventCategory::SETTINGS_EVENT); - sharing_log->set_event_type(EventType::TAP_HELP); - - auto tap_help = - analytics::proto::SharingLog::TapHelp::default_instance().New(); - - sharing_log->set_allocated_tap_help(tap_help); - return sharing_log; - } - - NearbySharingEventLogger* sharing_event_logger() { - return sharing_event_logger_.get(); - } - - private: - nearby::FakePreferenceManager preference_manager_; - std::unique_ptr event_logger_; - std::unique_ptr sharing_event_logger_; -}; - -TEST_F(NearbySharingEventLoggerTest, LogEventWhenEnabled) { - SetEventLogger(true); - 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(); - sharing_event_logger()->Log(*event); -} - -TEST_F(NearbySharingEventLoggerTest, NoLogEventWhenDisabled) { - SetEventLogger(false); - EXPECT_CALL(*event_logger(), Log(An())).Times(0); - - std::unique_ptr event = GetTestEvent(); - sharing_event_logger()->Log(*event); -} - -} // namespace -} // namespace sharing -} // namespace nearby diff --git a/sharing/nearby_sharing_service_factory.cc b/sharing/nearby_sharing_service_factory.cc index dd27577c..b90e94bd 100644 --- a/sharing/nearby_sharing_service_factory.cc +++ b/sharing/nearby_sharing_service_factory.cc @@ -22,7 +22,6 @@ #include "sharing/internal/public/context_impl.h" #include "sharing/nearby_connections_manager_factory.h" #include "sharing/nearby_sharing_decoder_impl.h" -#include "sharing/nearby_sharing_event_logger.h" #include "sharing/nearby_sharing_service.h" #include "sharing/nearby_sharing_service_impl.h" @@ -40,25 +39,23 @@ NearbySharingServiceFactory* NearbySharingServiceFactory::GetInstance() { NearbySharingService* NearbySharingServiceFactory::CreateSharingService( LinkType link_type, SharingPlatform& sharing_platform, - std::unique_ptr<::nearby::analytics::EventLogger> event_logger) { + ::nearby::analytics::EventLogger* event_logger) { if (nearby_sharing_service_ != nullptr) { return nullptr; } context_ = std::make_unique(sharing_platform); - base_event_logger_ = std::move(event_logger); - sharing_event_logger_ = std::make_unique( - sharing_platform.GetPreferenceManager(), base_event_logger_.get()); + event_logger_ = event_logger; decoder_ = std::make_unique(); - nearby_connections_manager_ = + auto nearby_connections_manager = NearbyConnectionsManagerFactory::CreateConnectionsManager( link_type, context_.get(), sharing_platform.GetDeviceInfo(), - sharing_event_logger_.get()); + event_logger_); nearby_sharing_service_ = std::make_unique( context_.get(), sharing_platform, decoder_.get(), - std::move(nearby_connections_manager_), sharing_event_logger_.get()); + std::move(nearby_connections_manager), event_logger_); return nearby_sharing_service_.get(); } diff --git a/sharing/nearby_sharing_service_factory.h b/sharing/nearby_sharing_service_factory.h index 4cc42ab9..51720613 100644 --- a/sharing/nearby_sharing_service_factory.h +++ b/sharing/nearby_sharing_service_factory.h @@ -20,7 +20,6 @@ #include "internal/analytics/event_logger.h" #include "sharing/internal/api/sharing_platform.h" #include "sharing/internal/public/context.h" -#include "sharing/nearby_connections_manager.h" #include "sharing/nearby_sharing_decoder.h" #include "sharing/nearby_sharing_service.h" @@ -37,16 +36,14 @@ class NearbySharingServiceFactory { NearbySharingService* CreateSharingService( LinkType link_type, nearby::sharing::api::SharingPlatform& sharing_platform, - std::unique_ptr<::nearby::analytics::EventLogger> event_logger); + ::nearby::analytics::EventLogger* event_logger); private: NearbySharingServiceFactory() = default; std::unique_ptr context_; - std::unique_ptr<::nearby::analytics::EventLogger> base_event_logger_; - std::unique_ptr<::nearby::analytics::EventLogger> sharing_event_logger_; + ::nearby::analytics::EventLogger* event_logger_ = nullptr; std::unique_ptr decoder_; - std::unique_ptr nearby_connections_manager_; std::unique_ptr nearby_sharing_service_; };