From 3cf20ee3bc2f2fe1a34b95ffb1b4c57fa0f13f67 Mon Sep 17 00:00:00 2001 From: Janusz Sobczak Date: Thu, 22 Jun 2023 01:47:42 -0700 Subject: [PATCH] Store metadata in FastPairDevice Add DeviceMetadata to FastPairDevice after downloading it. It simplifies the code and prevents fetching the same metadata several times. FastPairDataEncryptorImpl does not download the metadata anymore. Metadata must have already been downloaded, otherwise we wouldn't know what FP protocol to use. PiperOrigin-RevId: 542490742 --- fastpair/BUILD | 1 + fastpair/common/BUILD | 5 +- .../{repository => common}/device_metadata.h | 10 +-- fastpair/common/fast_pair_device.h | 22 +++-- fastpair/common/fast_pair_device_test.cc | 30 +++++++ fastpair/common/fast_pair_version.h | 29 ++++++ fastpair/fast_pair_controller.cc | 29 ++++-- fastpair/fast_pair_controller.h | 1 + fastpair/handshake/BUILD | 1 + .../fast_pair_data_encryptor_impl.cc | 25 ++---- .../handshake/fast_pair_data_encryptor_impl.h | 2 +- .../fast_pair_data_encryptor_impl_test.cc | 41 +++------ .../fast_pair_handshake_impl_test.cc | 34 +++---- .../fastpair/fast_pair_pairer_impl_test.cc | 88 +++++++++++-------- fastpair/pairing/pairer_broker_impl_test.cc | 36 +++++--- fastpair/repository/BUILD | 1 - .../fast_pair_discoverable_scanner_impl.cc | 2 +- .../fast_pair_discoverable_scanner_impl.h | 2 +- fastpair/server_access/BUILD | 2 - .../fake_fast_pair_repository.cc | 6 +- .../server_access/fake_fast_pair_repository.h | 2 +- .../fast_pair_metadata_downloader.cc | 6 +- .../fast_pair_metadata_downloader.h | 2 +- .../fast_pair_metadata_downloader_impl.cc | 2 +- ...fast_pair_metadata_downloader_impl_test.cc | 2 +- fastpair/server_access/fast_pair_repository.h | 2 +- .../fast_pair_repository_impl_test.cc | 7 +- fastpair/ui/BUILD | 2 +- ...st_pair_notification_controller_observer.h | 2 +- .../fast_pair_notification_controller.cc | 2 +- .../fast_pair_notification_controller.h | 2 +- .../fast_pair_notification_controller_test.cc | 2 +- .../ui/fast_pair/fast_pair_presenter_impl.cc | 6 +- .../ui/fast_pair/fast_pair_presenter_impl.h | 2 +- .../mock_fast_pair_notification_controller.h | 2 +- 35 files changed, 239 insertions(+), 171 deletions(-) rename fastpair/{repository => common}/device_metadata.h (86%) create mode 100644 fastpair/common/fast_pair_version.h diff --git a/fastpair/BUILD b/fastpair/BUILD index 8b3aa563..f538bd31 100644 --- a/fastpair/BUILD +++ b/fastpair/BUILD @@ -28,6 +28,7 @@ cc_library( "//fastpair/common", "//fastpair/handshake", "//fastpair/message_stream", + "//fastpair/server_access", "//internal/base", "//internal/platform:comm", "//internal/platform:types", diff --git a/fastpair/common/BUILD b/fastpair/common/BUILD index 5415a907..83236bab 100644 --- a/fastpair/common/BUILD +++ b/fastpair/common/BUILD @@ -17,10 +17,12 @@ cc_library( "account_key_filter.h", "battery_notification.h", "constant.h", + "device_metadata.h", "fast_pair_device.h", "fast_pair_http_result.h", "fast_pair_prefs.h", "fast_pair_switches.h", + "fast_pair_version.h", "non_discoverable_advertisement.h", "pair_failure.h", "protocol.h", @@ -29,6 +31,7 @@ cc_library( "//fastpair:__subpackages__", ], deps = [ + "//fastpair/proto:fastpair_cc_proto", "//internal/crypto", "//internal/platform:logging", "//internal/preferences", @@ -64,9 +67,9 @@ cc_test( shard_count = 16, deps = [ ":common", + "//fastpair/proto:fastpair_cc_proto", "//internal/platform/implementation/g3", # build_cleaner: keep "@com_github_protobuf_matchers//protobuf-matchers", - "@com_google_absl//absl/strings", "@com_google_googletest//:gtest_main", ], ) diff --git a/fastpair/repository/device_metadata.h b/fastpair/common/device_metadata.h similarity index 86% rename from fastpair/repository/device_metadata.h rename to fastpair/common/device_metadata.h index 2fa9b40a..b33ddc51 100644 --- a/fastpair/repository/device_metadata.h +++ b/fastpair/common/device_metadata.h @@ -17,8 +17,8 @@ #include +#include "fastpair/common/fast_pair_version.h" #include "fastpair/proto/fastpair_rpcs.proto.h" -#include "fastpair/common/fast_pair_device.h" namespace nearby { namespace fastpair { @@ -27,9 +27,9 @@ class DeviceMetadata { explicit DeviceMetadata(const proto::GetObservedDeviceResponse response) : response_(std::move(response)) {} DeviceMetadata(DeviceMetadata &&) = default; - DeviceMetadata(const DeviceMetadata &) = delete; - DeviceMetadata &operator=(const DeviceMetadata &) = delete; - DeviceMetadata &operator=(DeviceMetadata &&) = delete; + DeviceMetadata(const DeviceMetadata &) = default; + DeviceMetadata &operator=(const DeviceMetadata &) = default; + DeviceMetadata &operator=(DeviceMetadata &&) = default; ~DeviceMetadata() = default; const proto::Device &GetDetails() const { return response_.device(); } const proto::GetObservedDeviceResponse &GetResponse() const { @@ -46,7 +46,7 @@ class DeviceMetadata { } private: - const proto::GetObservedDeviceResponse response_; + proto::GetObservedDeviceResponse response_; }; } // namespace fastpair } // namespace nearby diff --git a/fastpair/common/fast_pair_device.h b/fastpair/common/fast_pair_device.h index f6323968..b43aecc8 100644 --- a/fastpair/common/fast_pair_device.h +++ b/fastpair/common/fast_pair_device.h @@ -25,16 +25,13 @@ #include "absl/container/flat_hash_map.h" #include "absl/strings/string_view.h" #include "fastpair/common/account_key.h" +#include "fastpair/common/device_metadata.h" +#include "fastpair/common/fast_pair_version.h" #include "fastpair/common/protocol.h" namespace nearby { namespace fastpair { -enum class DeviceFastPairVersion { - kV1, - kHigherThanV1, -}; - // Thin class which is used by the higher level components of the Fast Pair // system to represent a device. class FastPairDevice { @@ -64,10 +61,11 @@ class FastPairDevice { display_name_ = std::string(display_name); } - std::optional GetVersion() { return version_; } - - void SetVersion(std::optional version) { - version_ = version; + std::optional GetVersion() const { + if (metadata_) { + return metadata_->GetFastPairVersion(); + } + return std::nullopt; } const AccountKey& GetAccountKey() const { return account_key_; } @@ -88,6 +86,10 @@ class FastPairDevice { Protocol GetProtocol() const { return protocol_; } + void SetMetadata(const DeviceMetadata& metadata) { metadata_ = metadata; } + + const std::optional& GetMetadata() const { return metadata_; } + const std::string& GetUniqueId() const { if (public_address_.has_value()) { return *public_address_; @@ -122,6 +124,8 @@ class FastPairDevice { // for eligible devices (V2 or higher) and used for detecting subsequent // pairing scenarios. AccountKey account_key_; + + std::optional metadata_; }; std::ostream& operator<<(std::ostream& stream, const FastPairDevice& device); diff --git a/fastpair/common/fast_pair_device_test.cc b/fastpair/common/fast_pair_device_test.cc index 9c54610c..36010f75 100644 --- a/fastpair/common/fast_pair_device_test.cc +++ b/fastpair/common/fast_pair_device_test.cc @@ -23,7 +23,9 @@ #include "protobuf-matchers/protocol-buffer-matchers.h" #include "gtest/gtest.h" #include "fastpair/common/account_key.h" +#include "fastpair/common/device_metadata.h" #include "fastpair/common/protocol.h" +#include "fastpair/proto/fastpair_rpcs.proto.h" namespace nearby { namespace fastpair { @@ -76,6 +78,34 @@ TEST(FastPairDevice, GetAndPublicAddress) { EXPECT_EQ(device.GetPublicAddress().value(), new_test_GetPublicAddress); } +TEST(FastPairDevice, GetVersionUnset) { + FastPairDevice device("model_id", "ble_address", + Protocol::kFastPairInitialPairing); + + EXPECT_FALSE(device.GetVersion()); +} + +TEST(FastPairDevice, GetVersionV1) { + FastPairDevice device("model_id", "ble_address", + Protocol::kFastPairInitialPairing); + proto::GetObservedDeviceResponse response; + device.SetMetadata(DeviceMetadata(response)); + + EXPECT_EQ(device.GetVersion(), DeviceFastPairVersion::kV1); +} + +TEST(FastPairDevice, GetVersionHigherThanV1) { + FastPairDevice device("model_id", "ble_address", + Protocol::kFastPairInitialPairing); + proto::GetObservedDeviceResponse response; + std::string anti_spoofing_key(kPublicKeyByteSize, 0); + response.mutable_device()->mutable_anti_spoofing_key_pair()->set_public_key( + anti_spoofing_key); + device.SetMetadata(DeviceMetadata(response)); + + EXPECT_EQ(device.GetVersion(), DeviceFastPairVersion::kHigherThanV1); +} + } // namespace } // namespace fastpair } // namespace nearby diff --git a/fastpair/common/fast_pair_version.h b/fastpair/common/fast_pair_version.h new file mode 100644 index 00000000..3bb65aa4 --- /dev/null +++ b/fastpair/common/fast_pair_version.h @@ -0,0 +1,29 @@ +// 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_FASTPAIR_COMMON_FAST_PAIR_VERSION_H_ +#define THIRD_PARTY_NEARBY_FASTPAIR_COMMON_FAST_PAIR_VERSION_H_ + +namespace nearby { +namespace fastpair { + +enum class DeviceFastPairVersion { + kV1, + kHigherThanV1, +}; + +} +} // namespace nearby + +#endif // THIRD_PARTY_NEARBY_FASTPAIR_COMMON_FAST_PAIR_VERSION_H_ diff --git a/fastpair/fast_pair_controller.cc b/fastpair/fast_pair_controller.cc index bce9a08e..40406930 100644 --- a/fastpair/fast_pair_controller.cc +++ b/fastpair/fast_pair_controller.cc @@ -24,6 +24,7 @@ #include "fastpair/common/protocol.h" #include "fastpair/handshake/fast_pair_data_encryptor_impl.h" #include "fastpair/message_stream/message_stream.h" +#include "fastpair/server_access/fast_pair_repository.h" #include "internal/platform/bluetooth_adapter.h" #include "internal/platform/bluetooth_classic.h" #include "internal/platform/single_thread_executor.h" @@ -91,18 +92,30 @@ FastPairController::GetDataEncryptor() { if (!encryptor_) { encryptor_ = std::make_unique>>(); - FastPairDataEncryptorImpl::Factory::CreateAsync( - device_, [borrowable = lender_.GetBorrowable()]( - std::unique_ptr encryptor) mutable { - auto borrowed = borrowable.Borrow(); - if (borrowed) { - (*borrowed)->SetDataEncryptor(std::move(encryptor)); - } - }); + if (device_.GetMetadata()) { + CreateDataEncryptor(); + } else { + FastPairRepository::Get()->GetDeviceMetadata( + device_.GetModelId(), [this](DeviceMetadata& metadata) { + device_.SetMetadata(metadata); + CreateDataEncryptor(); + }); + } } return *encryptor_; } +void FastPairController::CreateDataEncryptor() { + FastPairDataEncryptorImpl::Factory::CreateAsync( + device_, [borrowable = lender_.GetBorrowable()]( + std::unique_ptr encryptor) mutable { + auto borrowed = borrowable.Borrow(); + if (borrowed) { + (*borrowed)->SetDataEncryptor(std::move(encryptor)); + } + }); +} + Future FastPairController::GetGattClientRef() { Future result; diff --git a/fastpair/fast_pair_controller.h b/fastpair/fast_pair_controller.h index 356a0a10..b4dac03f 100644 --- a/fastpair/fast_pair_controller.h +++ b/fastpair/fast_pair_controller.h @@ -175,6 +175,7 @@ class FastPairController : public MessageStream::Observer { CHECK(gatt_client_ != nullptr); return gatt_client_.get(); } + void CreateDataEncryptor(); Mediums* mediums_; FastPairDevice device_; SingleThreadExecutor* executor_; diff --git a/fastpair/handshake/BUILD b/fastpair/handshake/BUILD index cee44fc5..bedd516a 100644 --- a/fastpair/handshake/BUILD +++ b/fastpair/handshake/BUILD @@ -139,6 +139,7 @@ cc_test( deps = [ ":handshake", "//fastpair/common", + "//fastpair/proto:fastpair_cc_proto", "//fastpair/server_access:test_support", "//internal/platform:base", "//internal/platform:test_util", diff --git a/fastpair/handshake/fast_pair_data_encryptor_impl.cc b/fastpair/handshake/fast_pair_data_encryptor_impl.cc index 1cac8f12..a65cee5e 100644 --- a/fastpair/handshake/fast_pair_data_encryptor_impl.cc +++ b/fastpair/handshake/fast_pair_data_encryptor_impl.cc @@ -29,6 +29,7 @@ #include "absl/strings/string_view.h" #include "fastpair/common/account_key.h" #include "fastpair/common/constant.h" +#include "fastpair/common/device_metadata.h" #include "fastpair/common/protocol.h" #include "fastpair/crypto/decrypted_passkey.h" #include "fastpair/crypto/decrypted_response.h" @@ -36,7 +37,6 @@ #include "fastpair/crypto/fast_pair_key_pair.h" #include "fastpair/dataparser/fast_pair_data_parser.h" #include "fastpair/handshake/fast_pair_data_encryptor.h" -#include "fastpair/repository/device_metadata.h" #include "fastpair/server_access/fast_pair_repository.h" #include "internal/platform/logging.h" @@ -88,27 +88,12 @@ void FastPairDataEncryptorImpl::Factory::CreateAsyncWithKeyExchange( const FastPairDevice& device, absl::AnyInvocable)> on_get_instance_callback) { - // We first have to get the metadata in order to get the public key to use - // to generate the new secret key pair. - NEARBY_LOGS(INFO) << __func__ << ": Attempting to get device metadata."; - FastPairRepository::Get()->GetDeviceMetadata( - device.GetModelId(), - [on_get_instance_callback = std::move(on_get_instance_callback)]( - DeviceMetadata& metadata) mutable { - FastPairDataEncryptorImpl::Factory::DeviceMetadataRetrieved( - std::move(on_get_instance_callback), metadata); - }); -} - -void FastPairDataEncryptorImpl::Factory::DeviceMetadataRetrieved( - absl::AnyInvocable)> - on_get_instance_callback, - DeviceMetadata& device_metadata) { - NEARBY_LOGS(INFO) << __func__; - DCHECK(&device_metadata); + NEARBY_LOGS(VERBOSE) << __func__; + auto& metadata = device.GetMetadata(); + DCHECK(metadata); std::optional key_pair = FastPairEncryption::GenerateKeysWithEcdhKeyAgreement( - device_metadata.GetDetails().anti_spoofing_key_pair().public_key()); + metadata->GetDetails().anti_spoofing_key_pair().public_key()); if (!key_pair.has_value()) { NEARBY_LOGS(INFO) << "Fail to generate key pair"; std::move(on_get_instance_callback)(nullptr); diff --git a/fastpair/handshake/fast_pair_data_encryptor_impl.h b/fastpair/handshake/fast_pair_data_encryptor_impl.h index 64db1bd5..a0c5291c 100644 --- a/fastpair/handshake/fast_pair_data_encryptor_impl.h +++ b/fastpair/handshake/fast_pair_data_encryptor_impl.h @@ -25,10 +25,10 @@ #include "absl/functional/any_invocable.h" #include "fastpair/common/constant.h" +#include "fastpair/common/device_metadata.h" #include "fastpair/common/fast_pair_device.h" #include "fastpair/crypto/fast_pair_key_pair.h" #include "fastpair/handshake/fast_pair_data_encryptor.h" -#include "fastpair/repository/device_metadata.h" namespace nearby { namespace fastpair { diff --git a/fastpair/handshake/fast_pair_data_encryptor_impl_test.cc b/fastpair/handshake/fast_pair_data_encryptor_impl_test.cc index 854c8b84..80124ad4 100644 --- a/fastpair/handshake/fast_pair_data_encryptor_impl_test.cc +++ b/fastpair/handshake/fast_pair_data_encryptor_impl_test.cc @@ -26,11 +26,11 @@ #include "absl/strings/escaping.h" #include "fastpair/common/account_key.h" #include "fastpair/common/constant.h" +#include "fastpair/common/device_metadata.h" #include "fastpair/common/protocol.h" #include "fastpair/crypto/fast_pair_encryption.h" #include "fastpair/dataparser/fast_pair_data_parser.h" #include "fastpair/handshake/fast_pair_data_encryptor.h" -#include "fastpair/server_access/fake_fast_pair_repository.h" #include "internal/platform/count_down_latch.h" namespace nearby { @@ -57,27 +57,15 @@ class FastPairDataEncryptorImplTest : public testing::Test { public: void TearDown() override { data_encryptor_.reset(); } - void FailedSetUpRepositoryWithNoDeviceMetadata() { - CountDownLatch latch(1); - repository_ = std::make_unique(); - FastPairDevice device(kValidModelId, kTestAddress, - Protocol::kFastPairInitialPairing); - FastPairDataEncryptorImpl::Factory::CreateAsync( - device, absl::bind_front( - &FastPairDataEncryptorImplTest::OnDataEncryptorCreateAsync, - this, latch)); - EXPECT_FALSE(latch.Await(kWaitTimeout).GetResult()); - } - - void FailedSetUpRepositoryWithNoPublicKey() { - repository_ = std::make_unique(); - proto::Device metadata; + void FailedSetUpDeviceWithNoPublicKey() { + proto::GetObservedDeviceResponse response; std::string decoded_key; absl::Base64Unescape(kInvalidPublicAntiSpoof, &decoded_key); - metadata.mutable_anti_spoofing_key_pair()->set_public_key(decoded_key); - repository_->SetFakeMetadata(kValidModelId, metadata); + response.mutable_device()->mutable_anti_spoofing_key_pair()->set_public_key( + decoded_key); FastPairDevice device(kValidModelId, kTestAddress, Protocol::kFastPairInitialPairing); + device.SetMetadata(DeviceMetadata(response)); CountDownLatch latch(1); FastPairDataEncryptorImpl::Factory::CreateAsync( device, absl::bind_front( @@ -87,14 +75,14 @@ class FastPairDataEncryptorImplTest : public testing::Test { } void SuccessCreateFastPairDataEncryptorWithKeyExchange() { - repository_ = std::make_unique(); - proto::Device metadata; + proto::GetObservedDeviceResponse response; std::string decoded_key; absl::Base64Unescape(kPublicAntiSpoof, &decoded_key); - metadata.mutable_anti_spoofing_key_pair()->set_public_key(decoded_key); - repository_->SetFakeMetadata(kValidModelId, metadata); + response.mutable_device()->mutable_anti_spoofing_key_pair()->set_public_key( + decoded_key); FastPairDevice device(kValidModelId, kTestAddress, Protocol::kFastPairInitialPairing); + device.SetMetadata(DeviceMetadata(response)); CountDownLatch latch(1); FastPairDataEncryptorImpl::Factory::CreateAsync( device, absl::bind_front( @@ -218,17 +206,10 @@ class FastPairDataEncryptorImplTest : public testing::Test { private: std::unique_ptr device_; - std::unique_ptr repository_; }; -TEST_F(FastPairDataEncryptorImplTest, FailedSetUpNoMetadata) { - EXPECT_FALSE(data_encryptor_); - FailedSetUpRepositoryWithNoDeviceMetadata(); - EXPECT_FALSE(data_encryptor_); -} - TEST_F(FastPairDataEncryptorImplTest, NoKeyPair) { - FailedSetUpRepositoryWithNoPublicKey(); + FailedSetUpDeviceWithNoPublicKey(); EXPECT_FALSE(data_encryptor_); } diff --git a/fastpair/handshake/fast_pair_handshake_impl_test.cc b/fastpair/handshake/fast_pair_handshake_impl_test.cc index fdbc6d65..b605e5d8 100644 --- a/fastpair/handshake/fast_pair_handshake_impl_test.cc +++ b/fastpair/handshake/fast_pair_handshake_impl_test.cc @@ -28,10 +28,12 @@ #include "absl/status/status.h" #include "absl/strings/escaping.h" #include "fastpair/common/constant.h" +#include "fastpair/common/device_metadata.h" #include "fastpair/common/fast_pair_device.h" #include "fastpair/common/pair_failure.h" #include "fastpair/common/protocol.h" #include "fastpair/handshake/fast_pair_gatt_service_client_impl.h" +#include "fastpair/proto/fastpair_rpcs.proto.h" #include "fastpair/server_access/fake_fast_pair_repository.h" #include "internal/platform/byte_array.h" #include "internal/platform/count_down_latch.h" @@ -139,22 +141,22 @@ class FastPairHandshakeImplTest : public testing::Test { absl::OkStatus(); } - void SetUpFastPairRepository() { - repository_ = std::make_unique(); - proto::Device metadata; + void SetUpValidAntiSpoofingKey(FastPairDevice* device) { + proto::GetObservedDeviceResponse response; std::string decoded_key; absl::Base64Unescape(kPublicAntiSpoof, &decoded_key); - metadata.mutable_anti_spoofing_key_pair()->set_public_key(decoded_key); - repository_->SetFakeMetadata(kMetadataId, metadata); + response.mutable_device()->mutable_anti_spoofing_key_pair()->set_public_key( + decoded_key); + device->SetMetadata(DeviceMetadata(response)); } - void FailedFastPairRepository() { - repository_ = std::make_unique(); - proto::Device metadata; + void SetUpInvalidAntiSpoofingKey(FastPairDevice* device) { + proto::GetObservedDeviceResponse response; std::string decoded_key; absl::Base64Unescape(kInvalidPublicAntiSpoof, &decoded_key); - metadata.mutable_anti_spoofing_key_pair()->set_public_key(decoded_key); - repository_->SetFakeMetadata(kMetadataId, metadata); + response.mutable_device()->mutable_anti_spoofing_key_pair()->set_public_key( + decoded_key); + device->SetMetadata(DeviceMetadata(response)); } absl::Status TriggerKeyBasedGattChanged() { @@ -208,10 +210,10 @@ TEST_F(FastPairHandshakeImplTest, Success) { notified = true; EXPECT_OK(TriggerKeyBasedGattChanged()); }); - SetUpFastPairRepository(); InsertCorrectGattCharacteristics(); fast_pair_device_ = std::make_unique( kMetadataId, provider_address_, Protocol::kFastPairInitialPairing); + SetUpValidAntiSpoofingKey(fast_pair_device_.get()); CountDownLatch latch(1); handshake_ = std::make_unique( *fast_pair_device_, mediums_, @@ -233,9 +235,9 @@ TEST_F(FastPairHandshakeImplTest, GattError) { notified = true; EXPECT_OK(TriggerKeyBasedGattChanged()); }); - SetUpFastPairRepository(); fast_pair_device_ = std::make_unique( kMetadataId, provider_address_, Protocol::kFastPairInitialPairing); + SetUpValidAntiSpoofingKey(fast_pair_device_.get()); CountDownLatch latch(1); handshake_ = std::make_unique( *fast_pair_device_, mediums_, @@ -256,10 +258,10 @@ TEST_F(FastPairHandshakeImplTest, DataEncryptorCreateError) { notified = true; EXPECT_OK(TriggerKeyBasedGattChanged()); }); - FailedFastPairRepository(); InsertCorrectGattCharacteristics(); fast_pair_device_ = std::make_unique( kMetadataId, provider_address_, Protocol::kFastPairInitialPairing); + SetUpInvalidAntiSpoofingKey(fast_pair_device_.get()); CountDownLatch latch(1); handshake_ = std::make_unique( *fast_pair_device_, mediums_, @@ -276,10 +278,10 @@ TEST_F(FastPairHandshakeImplTest, DataEncryptorCreateError) { TEST_F(FastPairHandshakeImplTest, WriteResponseError) { StartGattServer([]() {}); - SetUpFastPairRepository(); InsertCorrectGattCharacteristics(); fast_pair_device_ = std::make_unique( kMetadataId, provider_address_, Protocol::kFastPairInitialPairing); + SetUpValidAntiSpoofingKey(fast_pair_device_.get()); CountDownLatch latch(1); handshake_ = std::make_unique( *fast_pair_device_, mediums_, @@ -300,10 +302,10 @@ TEST_F(FastPairHandshakeImplTest, WriteResponseWrongSize) { notified = true; EXPECT_OK(TriggerKeyBasedGattChangedWithWrongSizeResponse()); }); - SetUpFastPairRepository(); InsertCorrectGattCharacteristics(); fast_pair_device_ = std::make_unique( kMetadataId, provider_address_, Protocol::kFastPairInitialPairing); + SetUpValidAntiSpoofingKey(fast_pair_device_.get()); CountDownLatch latch(1); handshake_ = std::make_unique( *fast_pair_device_, mediums_, @@ -325,10 +327,10 @@ TEST_F(FastPairHandshakeImplTest, ParseResponseError) { notified = true; EXPECT_OK(TriggerKeyBasedGattChangedWithWrongResponse()); }); - SetUpFastPairRepository(); InsertCorrectGattCharacteristics(); fast_pair_device_ = std::make_unique( kMetadataId, provider_address_, Protocol::kFastPairInitialPairing); + SetUpValidAntiSpoofingKey(fast_pair_device_.get()); CountDownLatch latch(1); handshake_ = std::make_unique( *fast_pair_device_, mediums_, diff --git a/fastpair/pairing/fastpair/fast_pair_pairer_impl_test.cc b/fastpair/pairing/fastpair/fast_pair_pairer_impl_test.cc index 32c7aa38..11d0cdbf 100644 --- a/fastpair/pairing/fastpair/fast_pair_pairer_impl_test.cc +++ b/fastpair/pairing/fastpair/fast_pair_pairer_impl_test.cc @@ -35,7 +35,9 @@ #include "fastpair//handshake/fast_pair_handshake_lookup.h" #include "fastpair/common/account_key.h" #include "fastpair/common/constant.h" +#include "fastpair/common/device_metadata.h" #include "fastpair/common/fast_pair_device.h" +#include "fastpair/common/fast_pair_version.h" #include "fastpair/common/protocol.h" #include "fastpair/handshake/fast_pair_data_encryptor_impl.h" #include "fastpair/handshake/fast_pair_handshake_impl.h" @@ -133,13 +135,18 @@ class FastPairPairerImplTest : public testing::Test { void CreateMockDevice(DeviceFastPairVersion version, Protocol protocol) { device_ = std::make_unique( kMetadataId, remote_device_->GetMacAddress(), protocol); - device_->SetVersion(version); if (version == DeviceFastPairVersion::kV1) { device_->SetPublicAddress(remote_device_->GetMacAddress()); } if (protocol == Protocol::kFastPairSubsequentPairing) { device_->SetAccountKey(AccountKey(account_key_)); } + CountDownLatch latch(1); + repository_->GetDeviceMetadata(kMetadataId, [&](DeviceMetadata& metadata) { + device_->SetMetadata(std::move(metadata)); + latch.CountDown(); + }); + latch.Await(); } void ConfigurePairingContext() { @@ -190,8 +197,11 @@ class FastPairPairerImplTest : public testing::Test { } // Sets up provider's metadata information. - void SetUpFastPairRepository() { - repository_ = FakeFastPairRepository::Create(kMetadataId, kPublicAntiSpoof); + void SetUpFastPairRepository(DeviceFastPairVersion version) { + repository_ = FakeFastPairRepository::Create( + kMetadataId, version == DeviceFastPairVersion::kHigherThanV1 + ? kPublicAntiSpoof + : ""); } // Sets upprovider's gatt_server. @@ -352,12 +362,12 @@ class FastPairPairerImplTest : public testing::Test { TEST_F(FastPairPairerImplTest, SuccessInitialPairingWithDeviceVersionHigherThanV1) { ConfigurePairingContext(); - CreateMockDevice(DeviceFastPairVersion::kHigherThanV1, - Protocol::kFastPairInitialPairing); bool triggered_keybase_value_change = false; bool triggered_passkey_value_change = false; - SetUpFastPairRepository(); + SetUpFastPairRepository(DeviceFastPairVersion::kHigherThanV1); + CreateMockDevice(DeviceFastPairVersion::kHigherThanV1, + Protocol::kFastPairInitialPairing); SetupProviderGattServer( [&]() { triggered_keybase_value_change = true; @@ -403,11 +413,11 @@ TEST_F(FastPairPairerImplTest, TEST_F(FastPairPairerImplTest, SuccessInitialPairingWithDeviceV1) { ConfigurePairingContext(); - CreateMockDevice(DeviceFastPairVersion::kV1, - Protocol::kFastPairInitialPairing); bool triggered_keybase_value_change = false; bool triggered_passkey_value_change = false; - SetUpFastPairRepository(); + SetUpFastPairRepository(DeviceFastPairVersion::kV1); + CreateMockDevice(DeviceFastPairVersion::kV1, + Protocol::kFastPairInitialPairing); SetupProviderGattServer( [&]() { triggered_keybase_value_change = true; @@ -451,11 +461,11 @@ TEST_F(FastPairPairerImplTest, SuccessInitialPairingWithDeviceV1) { TEST_F(FastPairPairerImplTest, SuccessSubsequentPairingWithDevice) { ConfigurePairingContext(); - CreateMockDevice(DeviceFastPairVersion::kHigherThanV1, - Protocol::kFastPairSubsequentPairing); bool triggered_keybase_value_change = false; bool triggered_passkey_value_change = false; - SetUpFastPairRepository(); + SetUpFastPairRepository(DeviceFastPairVersion::kHigherThanV1); + CreateMockDevice(DeviceFastPairVersion::kHigherThanV1, + Protocol::kFastPairSubsequentPairing); SetupProviderGattServer( [&]() { triggered_keybase_value_change = true; @@ -498,11 +508,11 @@ TEST_F(FastPairPairerImplTest, SuccessSubsequentPairingWithDevice) { TEST_F(FastPairPairerImplTest, SuccessRetroactivePairingWithDevice) { ConfigurePairingContext(); - CreateMockDevice(DeviceFastPairVersion::kHigherThanV1, - Protocol::kFastPairRetroactivePairing); bool triggered_keybase_value_change = false; bool triggered_passkey_value_change = false; - SetUpFastPairRepository(); + SetUpFastPairRepository(DeviceFastPairVersion::kHigherThanV1); + CreateMockDevice(DeviceFastPairVersion::kHigherThanV1, + Protocol::kFastPairRetroactivePairing); SetupProviderGattServer( [&]() { triggered_keybase_value_change = true; @@ -546,11 +556,11 @@ TEST_F(FastPairPairerImplTest, SuccessRetroactivePairingWithDevice) { } TEST_F(FastPairPairerImplTest, FailedToUnPair) { - CreateMockDevice(DeviceFastPairVersion::kHigherThanV1, - Protocol::kFastPairInitialPairing); bool triggered_keybase_value_change = false; bool triggered_passkey_value_change = false; - SetUpFastPairRepository(); + SetUpFastPairRepository(DeviceFastPairVersion::kHigherThanV1); + CreateMockDevice(DeviceFastPairVersion::kHigherThanV1, + Protocol::kFastPairInitialPairing); SetupProviderGattServer( [&]() { triggered_keybase_value_change = true; @@ -595,11 +605,11 @@ TEST_F(FastPairPairerImplTest, FailedToUnPair) { TEST_F(FastPairPairerImplTest, FailedToPairingWithAuthTimeout) { ConfigurePairingContext(); - CreateMockDevice(DeviceFastPairVersion::kHigherThanV1, - Protocol::kFastPairInitialPairing); bool triggered_keybase_value_change = false; bool triggered_passkey_value_change = false; - SetUpFastPairRepository(); + SetUpFastPairRepository(DeviceFastPairVersion::kHigherThanV1); + CreateMockDevice(DeviceFastPairVersion::kHigherThanV1, + Protocol::kFastPairInitialPairing); SetupProviderGattServer( [&]() { triggered_keybase_value_change = true; @@ -645,11 +655,11 @@ TEST_F(FastPairPairerImplTest, FailedToPairingWithAuthTimeout) { TEST_F(FastPairPairerImplTest, NoPasskeyResponse) { ConfigurePairingContext(); - CreateMockDevice(DeviceFastPairVersion::kHigherThanV1, - Protocol::kFastPairInitialPairing); bool triggered_keybase_value_change = false; bool triggered_passkey_value_change = false; - SetUpFastPairRepository(); + SetUpFastPairRepository(DeviceFastPairVersion::kHigherThanV1); + CreateMockDevice(DeviceFastPairVersion::kHigherThanV1, + Protocol::kFastPairInitialPairing); SetupProviderGattServer( [&]() { triggered_keybase_value_change = true; @@ -692,11 +702,11 @@ TEST_F(FastPairPairerImplTest, NoPasskeyResponse) { TEST_F(FastPairPairerImplTest, PasskeyMismatch) { ConfigurePairingContext(); - CreateMockDevice(DeviceFastPairVersion::kHigherThanV1, - Protocol::kFastPairInitialPairing); bool triggered_keybase_value_change = false; bool triggered_passkey_value_change = false; - SetUpFastPairRepository(); + SetUpFastPairRepository(DeviceFastPairVersion::kHigherThanV1); + CreateMockDevice(DeviceFastPairVersion::kHigherThanV1, + Protocol::kFastPairInitialPairing); SetupProviderGattServer( [&]() { triggered_keybase_value_change = true; @@ -742,11 +752,11 @@ TEST_F(FastPairPairerImplTest, PasskeyMismatch) { TEST_F(FastPairPairerImplTest, ReceiveWithWrongPasskeyResponse) { ConfigurePairingContext(); - CreateMockDevice(DeviceFastPairVersion::kHigherThanV1, - Protocol::kFastPairInitialPairing); bool triggered_keybase_value_change = false; bool triggered_passkey_value_change = false; - SetUpFastPairRepository(); + SetUpFastPairRepository(DeviceFastPairVersion::kHigherThanV1); + CreateMockDevice(DeviceFastPairVersion::kHigherThanV1, + Protocol::kFastPairInitialPairing); SetupProviderGattServer( [&]() { triggered_keybase_value_change = true; @@ -792,11 +802,11 @@ TEST_F(FastPairPairerImplTest, ReceiveWithWrongPasskeyResponse) { TEST_F(FastPairPairerImplTest, ReceiveWithWrongPasskeyMessageType) { ConfigurePairingContext(); - CreateMockDevice(DeviceFastPairVersion::kHigherThanV1, - Protocol::kFastPairInitialPairing); bool triggered_keybase_value_change = false; bool triggered_passkey_value_change = false; - SetUpFastPairRepository(); + SetUpFastPairRepository(DeviceFastPairVersion::kHigherThanV1); + CreateMockDevice(DeviceFastPairVersion::kHigherThanV1, + Protocol::kFastPairInitialPairing); SetupProviderGattServer( [&]() { triggered_keybase_value_change = true; @@ -843,11 +853,11 @@ TEST_F(FastPairPairerImplTest, ReceiveWithWrongPasskeyMessageType) { TEST_F(FastPairPairerImplTest, SuccessPairingWithDeviceButFailedToWriteAccountkey) { ConfigurePairingContext(); - CreateMockDevice(DeviceFastPairVersion::kHigherThanV1, - Protocol::kFastPairInitialPairing); bool triggered_keybase_value_change = false; bool triggered_passkey_value_change = false; - SetUpFastPairRepository(); + SetUpFastPairRepository(DeviceFastPairVersion::kHigherThanV1); + CreateMockDevice(DeviceFastPairVersion::kHigherThanV1, + Protocol::kFastPairInitialPairing); SetupProviderGattServer( [&]() { triggered_keybase_value_change = true; @@ -893,11 +903,11 @@ TEST_F(FastPairPairerImplTest, TEST_F(FastPairPairerImplTest, TestCancelPairing) { ConfigurePairingContext(); - CreateMockDevice(DeviceFastPairVersion::kHigherThanV1, - Protocol::kFastPairInitialPairing); bool triggered_keybase_value_change = false; bool triggered_passkey_value_change = false; - SetUpFastPairRepository(); + SetUpFastPairRepository(DeviceFastPairVersion::kHigherThanV1); + CreateMockDevice(DeviceFastPairVersion::kHigherThanV1, + Protocol::kFastPairInitialPairing); SetupProviderGattServer( [&]() { triggered_keybase_value_change = true; diff --git a/fastpair/pairing/pairer_broker_impl_test.cc b/fastpair/pairing/pairer_broker_impl_test.cc index a88298ea..674fb8d1 100644 --- a/fastpair/pairing/pairer_broker_impl_test.cc +++ b/fastpair/pairing/pairer_broker_impl_test.cc @@ -179,13 +179,18 @@ class PairerBrokerImplTest : public testing::Test { void CreateMockDevice(DeviceFastPairVersion version, Protocol protocol) { device_ = std::make_unique( kMetadataId, remote_device_->GetMacAddress(), protocol); - device_->SetVersion(version); if (version == DeviceFastPairVersion::kV1) { device_->SetPublicAddress(remote_device_->GetMacAddress()); } if (protocol == Protocol::kFastPairSubsequentPairing) { device_->SetAccountKey(AccountKey(account_key_)); } + CountDownLatch latch(1); + repository_->GetDeviceMetadata(kMetadataId, [&](DeviceMetadata& metadata) { + device_->SetMetadata(std::move(metadata)); + latch.CountDown(); + }); + latch.Await(); } void ConfigurePairingContext() { @@ -236,8 +241,11 @@ class PairerBrokerImplTest : public testing::Test { } // Sets up provider's metadata information. - void SetUpFastPairRepository() { - repository_ = FakeFastPairRepository::Create(kMetadataId, kPublicAntiSpoof); + void SetUpFastPairRepository(DeviceFastPairVersion version) { + repository_ = FakeFastPairRepository::Create( + kMetadataId, version == DeviceFastPairVersion::kHigherThanV1 + ? kPublicAntiSpoof + : ""); } // Sets upprovider's gatt_server. @@ -411,11 +419,11 @@ class PairerBrokerImplTest : public testing::Test { TEST_F(PairerBrokerImplTest, SuccessInitialPairingWithDeviceV1) { ConfigurePairingContext(); - CreateMockDevice(DeviceFastPairVersion::kV1, - Protocol::kFastPairInitialPairing); bool triggered_keybase_value_change = false; bool triggered_passkey_value_change = false; - SetUpFastPairRepository(); + SetUpFastPairRepository(DeviceFastPairVersion::kV1); + CreateMockDevice(DeviceFastPairVersion::kV1, + Protocol::kFastPairInitialPairing); SetupProviderGattServer( [&]() { triggered_keybase_value_change = true; @@ -455,9 +463,9 @@ TEST_F(PairerBrokerImplTest, SuccessInitialPairingWithDevice) { CountDownLatch pairing_completed_latch(1); CountDownLatch pairing_failure_latch(1); ConfigurePairingContext(); + SetUpFastPairRepository(DeviceFastPairVersion::kHigherThanV1); CreateMockDevice(DeviceFastPairVersion::kHigherThanV1, Protocol::kFastPairInitialPairing); - SetUpFastPairRepository(); SetupProviderGattServer( [&]() { triggered_keybase_value_change = true; @@ -498,9 +506,9 @@ TEST_F(PairerBrokerImplTest, SuccessSubsequentPairingWithDevice) { CountDownLatch pairing_completed_latch(1); CountDownLatch pairing_failure_latch(1); ConfigurePairingContext(); + SetUpFastPairRepository(DeviceFastPairVersion::kHigherThanV1); CreateMockDevice(DeviceFastPairVersion::kHigherThanV1, Protocol::kFastPairSubsequentPairing); - SetUpFastPairRepository(); pairer_broker_ = std::make_unique(*mediums_, &executor_); PairerBrokerObserver pairer_broker_observer( pairer_broker_.get(), &device_paired_latch, &account_key_writed_latch, @@ -535,11 +543,11 @@ TEST_F(PairerBrokerImplTest, SuccessSubsequentPairingWithDevice) { TEST_F(PairerBrokerImplTest, SuccessRetroactivePairingWithDevice) { ConfigurePairingContext(); - CreateMockDevice(DeviceFastPairVersion::kHigherThanV1, - Protocol::kFastPairRetroactivePairing); bool triggered_keybase_value_change = false; bool triggered_passkey_value_change = false; - SetUpFastPairRepository(); + SetUpFastPairRepository(DeviceFastPairVersion::kHigherThanV1); + CreateMockDevice(DeviceFastPairVersion::kHigherThanV1, + Protocol::kFastPairRetroactivePairing); SetupProviderGattServer( [&]() { triggered_keybase_value_change = true; @@ -579,9 +587,9 @@ TEST_F(PairerBrokerImplTest, FaileToCreateHandshakeRetryThreeTimes) { CountDownLatch pairing_completed_latch(1); CountDownLatch pairing_failure_latch(1); ConfigurePairingContext(); + SetUpFastPairRepository(DeviceFastPairVersion::kHigherThanV1); CreateMockDevice(DeviceFastPairVersion::kHigherThanV1, Protocol::kFastPairSubsequentPairing); - SetUpFastPairRepository(); pairer_broker_ = std::make_unique(*mediums_, &executor_); PairerBrokerObserver pairer_broker_observer( pairer_broker_.get(), &device_paired_latch, &account_key_writed_latch, @@ -614,9 +622,9 @@ TEST_F(PairerBrokerImplTest, FaileToWriteAccountkey) { CountDownLatch pairing_completed_latch(1); CountDownLatch pairing_failure_latch(1); ConfigurePairingContext(); + SetUpFastPairRepository(DeviceFastPairVersion::kHigherThanV1); CreateMockDevice(DeviceFastPairVersion::kHigherThanV1, Protocol::kFastPairInitialPairing); - SetUpFastPairRepository(); SetupProviderGattServer( [&]() { triggered_keybase_value_change = true; @@ -657,9 +665,9 @@ TEST_F(PairerBrokerImplTest, FailToPairRetryThreeTimes) { CountDownLatch pairing_completed_latch(1); CountDownLatch pairing_failure_latch(1); ConfigurePairingContext(); + SetUpFastPairRepository(DeviceFastPairVersion::kHigherThanV1); CreateMockDevice(DeviceFastPairVersion::kHigherThanV1, Protocol::kFastPairInitialPairing); - SetUpFastPairRepository(); SetupProviderGattServer( [&]() { triggered_keybase_value_change = true; diff --git a/fastpair/repository/BUILD b/fastpair/repository/BUILD index 1b6f3db5..f08a02ab 100644 --- a/fastpair/repository/BUILD +++ b/fastpair/repository/BUILD @@ -7,7 +7,6 @@ cc_library( "fast_pair_metadata_repository_impl.cc", ], hdrs = [ - "device_metadata.h", "fast_pair_metadata_fetcher.h", "fast_pair_metadata_fetcher_impl.h", "fast_pair_metadata_repository.h", diff --git a/fastpair/scanning/fastpair/fast_pair_discoverable_scanner_impl.cc b/fastpair/scanning/fastpair/fast_pair_discoverable_scanner_impl.cc index 4711e9e5..752b792c 100644 --- a/fastpair/scanning/fastpair/fast_pair_discoverable_scanner_impl.cc +++ b/fastpair/scanning/fastpair/fast_pair_discoverable_scanner_impl.cc @@ -181,7 +181,7 @@ void FastPairDiscoverableScannerImpl::OnDeviceMetadataRetrieved( } auto fast_pair_device = std::make_unique( model_id, address, Protocol::kFastPairInitialPairing); - fast_pair_device->SetVersion(device_metadata.GetFastPairVersion()); + fast_pair_device->SetMetadata(device_metadata); executor_->Execute( "add-device", diff --git a/fastpair/scanning/fastpair/fast_pair_discoverable_scanner_impl.h b/fastpair/scanning/fastpair/fast_pair_discoverable_scanner_impl.h index 30eb4941..4f4c81d7 100644 --- a/fastpair/scanning/fastpair/fast_pair_discoverable_scanner_impl.h +++ b/fastpair/scanning/fastpair/fast_pair_discoverable_scanner_impl.h @@ -20,8 +20,8 @@ #include #include +#include "fastpair/common/device_metadata.h" #include "fastpair/common/fast_pair_device.h" -#include "fastpair/repository/device_metadata.h" #include "fastpair/repository/fast_pair_device_repository.h" #include "fastpair/scanning/fastpair/fast_pair_discoverable_scanner.h" #include "fastpair/scanning/fastpair/fast_pair_scanner.h" diff --git a/fastpair/server_access/BUILD b/fastpair/server_access/BUILD index b803c952..fb330c13 100644 --- a/fastpair/server_access/BUILD +++ b/fastpair/server_access/BUILD @@ -61,7 +61,6 @@ cc_library( ":server_access", "//fastpair/common", "//fastpair/proto:fastpair_cc_proto", - "//fastpair/repository", "//internal/platform:types", "@com_google_absl//absl/container:flat_hash_map", "@com_google_absl//absl/strings", @@ -97,7 +96,6 @@ cc_test( ":server_access", "//fastpair/common", "//fastpair/proto:fastpair_cc_proto", - "//fastpair/repository", "//fastpair/repository:fake_fast_pair_metadata_repository", "//internal/platform/implementation/g3", "@com_github_protobuf_matchers//protobuf-matchers", diff --git a/fastpair/server_access/fake_fast_pair_repository.cc b/fastpair/server_access/fake_fast_pair_repository.cc index e2c501d5..beba4385 100644 --- a/fastpair/server_access/fake_fast_pair_repository.cc +++ b/fastpair/server_access/fake_fast_pair_repository.cc @@ -18,7 +18,9 @@ #include #include +#include "absl/strings/escaping.h" #include "absl/strings/string_view.h" +#include "fastpair/common/constant.h" #include "fastpair/proto/fastpair_rpcs.proto.h" namespace nearby { @@ -48,7 +50,9 @@ std::unique_ptr FakeFastPairRepository::Create( absl::string_view model_id, absl::string_view public_anti_spoof_key) { proto::Device metadata; auto repository = std::make_unique(); - if (public_anti_spoof_key.length() == kPublicKeyByteSize) { + if (public_anti_spoof_key.empty()) { + // Missing ASK is fine for V1 devices. + } else if (public_anti_spoof_key.length() == kPublicKeyByteSize) { metadata.mutable_anti_spoofing_key_pair()->set_public_key( public_anti_spoof_key); } else { diff --git a/fastpair/server_access/fake_fast_pair_repository.h b/fastpair/server_access/fake_fast_pair_repository.h index 66e0b407..d0006802 100644 --- a/fastpair/server_access/fake_fast_pair_repository.h +++ b/fastpair/server_access/fake_fast_pair_repository.h @@ -20,7 +20,7 @@ #include "absl/container/flat_hash_map.h" #include "absl/strings/string_view.h" -#include "fastpair/repository/device_metadata.h" +#include "fastpair/common/device_metadata.h" #include "fastpair/server_access/fast_pair_repository.h" #include "internal/platform/single_thread_executor.h" diff --git a/fastpair/server_access/fast_pair_metadata_downloader.cc b/fastpair/server_access/fast_pair_metadata_downloader.cc index 02d8fb39..b5b11018 100644 --- a/fastpair/server_access/fast_pair_metadata_downloader.cc +++ b/fastpair/server_access/fast_pair_metadata_downloader.cc @@ -18,10 +18,10 @@ #include #include -#include "fastpair/proto/fastpair_rpcs.pb.h" -#include "fastpair/repository/device_metadata.h" -#include "internal/platform/logging.h" #include "absl/strings/string_view.h" +#include "fastpair/common/device_metadata.h" +#include "fastpair/proto/fastpair_rpcs.pb.h" +#include "internal/platform/logging.h" namespace nearby { namespace fastpair { diff --git a/fastpair/server_access/fast_pair_metadata_downloader.h b/fastpair/server_access/fast_pair_metadata_downloader.h index cb6978cd..5225cc14 100644 --- a/fastpair/server_access/fast_pair_metadata_downloader.h +++ b/fastpair/server_access/fast_pair_metadata_downloader.h @@ -21,7 +21,7 @@ #include "absl/functional/any_invocable.h" #include "absl/strings/string_view.h" -#include "fastpair/repository/device_metadata.h" +#include "fastpair/common/device_metadata.h" namespace nearby { namespace fastpair { diff --git a/fastpair/server_access/fast_pair_metadata_downloader_impl.cc b/fastpair/server_access/fast_pair_metadata_downloader_impl.cc index 1c0f392b..7f268ec2 100644 --- a/fastpair/server_access/fast_pair_metadata_downloader_impl.cc +++ b/fastpair/server_access/fast_pair_metadata_downloader_impl.cc @@ -23,7 +23,7 @@ #include "absl/strings/numbers.h" #include "absl/strings/string_view.h" -#include "fastpair/repository/device_metadata.h" +#include "fastpair/common/device_metadata.h" #include "fastpair/repository/fast_pair_metadata_repository.h" #include "fastpair/server_access/fast_pair_metadata_downloader.h" #include "internal/platform/logging.h" diff --git a/fastpair/server_access/fast_pair_metadata_downloader_impl_test.cc b/fastpair/server_access/fast_pair_metadata_downloader_impl_test.cc index 4657bbd2..bbf1f093 100644 --- a/fastpair/server_access/fast_pair_metadata_downloader_impl_test.cc +++ b/fastpair/server_access/fast_pair_metadata_downloader_impl_test.cc @@ -22,9 +22,9 @@ #include "gtest/gtest.h" #include "absl/strings/string_view.h" +#include "fastpair/common/device_metadata.h" #include "fastpair/common/fast_pair_http_result.h" #include "fastpair/proto/fastpair_rpcs.proto.h" -#include "fastpair/repository/device_metadata.h" #include "fastpair/repository/fake_fast_pair_metadata_repository.h" #include "fastpair/server_access/fast_pair_metadata_downloader.h" diff --git a/fastpair/server_access/fast_pair_repository.h b/fastpair/server_access/fast_pair_repository.h index 9693ff94..89d238fe 100644 --- a/fastpair/server_access/fast_pair_repository.h +++ b/fastpair/server_access/fast_pair_repository.h @@ -21,7 +21,7 @@ #include "absl/functional/any_invocable.h" #include "absl/strings/string_view.h" -#include "fastpair/repository/device_metadata.h" +#include "fastpair/common/device_metadata.h" namespace nearby { namespace fastpair { diff --git a/fastpair/server_access/fast_pair_repository_impl_test.cc b/fastpair/server_access/fast_pair_repository_impl_test.cc index 7ff78009..b8c97f1e 100644 --- a/fastpair/server_access/fast_pair_repository_impl_test.cc +++ b/fastpair/server_access/fast_pair_repository_impl_test.cc @@ -23,8 +23,8 @@ #include "gmock/gmock.h" #include "protobuf-matchers/protocol-buffer-matchers.h" #include "gtest/gtest.h" +#include "fastpair/common/device_metadata.h" #include "fastpair/proto/fastpair_rpcs.proto.h" -#include "fastpair/repository/device_metadata.h" #include "fastpair/repository/fake_fast_pair_metadata_repository.h" #include "fastpair/server_access/fast_pair_metadata_downloader.h" #include "fastpair/server_access/fast_pair_metadata_downloader_impl.h" @@ -53,7 +53,7 @@ class FastPairRepositoryImplTest : public ::testing::Test { void GetObservedDataRequestSuccess( const proto::GetObservedDeviceResponse& response) { FakeFastPairMetadataRepository* repository = - fake_repository_factory_->fake_repository(); + fake_repository_factory_->fake_repository(); std::move(repository->get_observed_device_request()->callback)(response); } @@ -64,8 +64,7 @@ class FastPairRepositoryImplTest : public ::testing::Test { } std::optional result_; - FakeFastPairMetadataRepositoryFactory* - fake_repository_factory_; + FakeFastPairMetadataRepositoryFactory* fake_repository_factory_; std::unique_ptr repository_; }; diff --git a/fastpair/ui/BUILD b/fastpair/ui/BUILD index f0860e81..5cdf2bfc 100644 --- a/fastpair/ui/BUILD +++ b/fastpair/ui/BUILD @@ -88,7 +88,7 @@ cc_test( deps = [ ":fake_fast_pair_ui", ":fast_pair_ui", - "//fastpair/repository", + "//fastpair/common", "//internal/platform/implementation/g3", # build_cleaner: keep "@com_github_protobuf_matchers//protobuf-matchers", "@com_google_googletest//:gtest_main", diff --git a/fastpair/ui/fast_pair/fake_fast_pair_notification_controller_observer.h b/fastpair/ui/fast_pair/fake_fast_pair_notification_controller_observer.h index 7732cc5d..2c1a15d9 100644 --- a/fastpair/ui/fast_pair/fake_fast_pair_notification_controller_observer.h +++ b/fastpair/ui/fast_pair/fake_fast_pair_notification_controller_observer.h @@ -20,7 +20,7 @@ #include #include -#include "fastpair/repository/device_metadata.h" +#include "fastpair/common/device_metadata.h" #include "fastpair/ui/fast_pair/fast_pair_notification_controller.h" #include "internal/platform/count_down_latch.h" diff --git a/fastpair/ui/fast_pair/fast_pair_notification_controller.cc b/fastpair/ui/fast_pair/fast_pair_notification_controller.cc index 9fdee3d5..e38e4405 100644 --- a/fastpair/ui/fast_pair/fast_pair_notification_controller.cc +++ b/fastpair/ui/fast_pair/fast_pair_notification_controller.cc @@ -17,7 +17,7 @@ #include #include "absl/functional/any_invocable.h" -#include "fastpair/repository/device_metadata.h" +#include "fastpair/common/device_metadata.h" #include "fastpair/ui/actions.h" #include "internal/platform/logging.h" diff --git a/fastpair/ui/fast_pair/fast_pair_notification_controller.h b/fastpair/ui/fast_pair/fast_pair_notification_controller.h index 5006c565..9f792225 100644 --- a/fastpair/ui/fast_pair/fast_pair_notification_controller.h +++ b/fastpair/ui/fast_pair/fast_pair_notification_controller.h @@ -17,7 +17,7 @@ #include "absl/functional/any_invocable.h" #include "absl/strings/string_view.h" -#include "fastpair/repository/device_metadata.h" +#include "fastpair/common/device_metadata.h" #include "fastpair/ui/actions.h" #include "internal/base/observer_list.h" diff --git a/fastpair/ui/fast_pair/fast_pair_notification_controller_test.cc b/fastpair/ui/fast_pair/fast_pair_notification_controller_test.cc index 996ff577..871dd4a5 100644 --- a/fastpair/ui/fast_pair/fast_pair_notification_controller_test.cc +++ b/fastpair/ui/fast_pair/fast_pair_notification_controller_test.cc @@ -22,7 +22,7 @@ #include "gmock/gmock.h" #include "protobuf-matchers/protocol-buffer-matchers.h" #include "gtest/gtest.h" -#include "fastpair/repository/device_metadata.h" +#include "fastpair/common/device_metadata.h" #include "fastpair/ui/actions.h" #include "fastpair/ui/fast_pair/fake_fast_pair_notification_controller_observer.h" diff --git a/fastpair/ui/fast_pair/fast_pair_presenter_impl.cc b/fastpair/ui/fast_pair/fast_pair_presenter_impl.cc index 91dba042..b43f8558 100644 --- a/fastpair/ui/fast_pair/fast_pair_presenter_impl.cc +++ b/fastpair/ui/fast_pair/fast_pair_presenter_impl.cc @@ -18,8 +18,8 @@ #include #include +#include "fastpair/common/device_metadata.h" #include "fastpair/common/fast_pair_device.h" -#include "fastpair/repository/device_metadata.h" #include "fastpair/server_access/fast_pair_repository.h" #include "fastpair/ui/fast_pair/fast_pair_notification_controller.h" #include "internal/platform/logging.h" @@ -64,8 +64,8 @@ void FastPairPresenterImpl::ShowDiscovery( void FastPairPresenterImpl::OnDiscoveryMetadataRetrieved( FastPairDevice& device, const DeviceMetadata& device_metadata, FastPairNotificationController& notification_controller) { - device.SetVersion(device_metadata.GetFastPairVersion()); - notification_controller.ShowGuestDiscoveryNotification(device_metadata, + device.SetMetadata(device_metadata); + notification_controller.ShowGuestDiscoveryNotification(*device.GetMetadata(), std::move(callback_)); } } // namespace fastpair diff --git a/fastpair/ui/fast_pair/fast_pair_presenter_impl.h b/fastpair/ui/fast_pair/fast_pair_presenter_impl.h index dcc561b3..f3bd50ac 100644 --- a/fastpair/ui/fast_pair/fast_pair_presenter_impl.h +++ b/fastpair/ui/fast_pair/fast_pair_presenter_impl.h @@ -17,8 +17,8 @@ #include +#include "fastpair/common/device_metadata.h" #include "fastpair/common/fast_pair_device.h" -#include "fastpair/repository/device_metadata.h" #include "fastpair/ui/fast_pair/fast_pair_notification_controller.h" #include "fastpair/ui/fast_pair/fast_pair_presenter.h" diff --git a/fastpair/ui/fast_pair/mock_fast_pair_notification_controller.h b/fastpair/ui/fast_pair/mock_fast_pair_notification_controller.h index 64a6249b..84b72603 100644 --- a/fastpair/ui/fast_pair/mock_fast_pair_notification_controller.h +++ b/fastpair/ui/fast_pair/mock_fast_pair_notification_controller.h @@ -16,7 +16,7 @@ #define THIRD_PARTY_NEARBY_FASTPAIR_UI_FAST_PAIR_MOCK_FAST_PAIR_NOTIFICATION_CONTROLLER_H_ #include "gmock/gmock.h" -#include "fastpair/repository/device_metadata.h" +#include "fastpair/common/device_metadata.h" #include "fastpair/ui/actions.h" #include "fastpair/ui/fast_pair/fast_pair_notification_controller.h"