From 36132890cd72b8fd484e92b6239c20ef57700ef7 Mon Sep 17 00:00:00 2001 From: Janusz Sobczak Date: Fri, 23 Jun 2023 11:04:56 -0700 Subject: [PATCH] Initialize metadata repository Make sure that FastPairRepository is initalized. FastPairRepository is required to fetch metadata information PiperOrigin-RevId: 542906473 --- fastpair/BUILD | 1 + fastpair/fast_pair_service.cc | 8 ++++++-- fastpair/fast_pair_service.h | 5 +++++ fastpair/fast_pair_service_test.cc | 3 ++- 4 files changed, 14 insertions(+), 3 deletions(-) diff --git a/fastpair/BUILD b/fastpair/BUILD index f538bd31..b1c3f39e 100644 --- a/fastpair/BUILD +++ b/fastpair/BUILD @@ -98,6 +98,7 @@ cc_library( ":fast_pair_seeker", "//fastpair/internal", "//fastpair/repository:device_repository", + "//fastpair/server_access", "//internal/flags:nearby_flags", "//internal/platform:types", "//internal/platform/flags:platform_flags", diff --git a/fastpair/fast_pair_service.cc b/fastpair/fast_pair_service.cc index 916e7ed2..57942e41 100644 --- a/fastpair/fast_pair_service.cc +++ b/fastpair/fast_pair_service.cc @@ -23,6 +23,7 @@ #include "absl/strings/str_format.h" #include "fastpair/fast_pair_plugin.h" #include "fastpair/internal/fast_pair_seeker_impl.h" +#include "fastpair/server_access/fast_pair_repository_impl.h" #include "internal/flags/nearby_flags.h" #include "internal/platform/flags/nearby_platform_feature_flags.h" #include "internal/platform/logging.h" @@ -34,12 +35,15 @@ namespace { constexpr absl::Duration kTimeout = absl::Seconds(3); } -FastPairService::FastPairService() { +FastPairService::FastPairService() + : FastPairService(std::make_unique()) {} + +FastPairService::FastPairService(std::unique_ptr repository) + : fast_pair_repository_(std::move(repository)) { NearbyFlags::GetInstance().OverrideBoolFlagValue( platform::config_package_nearby::nearby_platform_feature:: kEnableBleV2Gatt, true); - seeker_ = std::make_unique( FastPairSeekerImpl::ServiceCallbacks{ .on_initial_discovery = diff --git a/fastpair/fast_pair_service.h b/fastpair/fast_pair_service.h index cdbe0257..720b48b2 100644 --- a/fastpair/fast_pair_service.h +++ b/fastpair/fast_pair_service.h @@ -26,6 +26,7 @@ #include "fastpair/fast_pair_plugin.h" #include "fastpair/fast_pair_seeker.h" #include "fastpair/repository/fast_pair_device_repository.h" +#include "fastpair/server_access/fast_pair_repository.h" #include "internal/platform/single_thread_executor.h" namespace nearby { @@ -36,6 +37,9 @@ namespace fastpair { class FastPairService { public: FastPairService(); + // Constructor for tests. Allows us to inject a serverless metadata + // repository. + explicit FastPairService(std::unique_ptr repository); ~FastPairService(); // Registers a plugin provider. `name` must be a unique. @@ -66,6 +70,7 @@ class FastPairService { absl::flat_hash_map> providers_; FastPairDeviceRepository devices_{&executor_}; + std::unique_ptr fast_pair_repository_; }; } // namespace fastpair diff --git a/fastpair/fast_pair_service_test.cc b/fastpair/fast_pair_service_test.cc index b0c05110..6011ea18 100644 --- a/fastpair/fast_pair_service_test.cc +++ b/fastpair/fast_pair_service_test.cc @@ -16,6 +16,7 @@ #include #include +#include #include "gmock/gmock.h" #include "protobuf-matchers/protocol-buffer-matchers.h" @@ -75,7 +76,7 @@ TEST(FastPairService, InitialDiscoveryEvent) { constexpr absl::string_view kPluginName = "my plugin"; auto repository = FakeFastPairRepository::Create(kModelId, kPublicAntiSpoof); FakeProvider provider; - FastPairService service; + FastPairService service(std::move(repository)); CountDownLatch latch(1); auto plugin_provider = std::make_unique(); plugin_provider->on_initial_discovery_event_ =