Fix Metadata downloading callback issue

PiperOrigin-RevId: 508767628
This commit is contained in:
Qin Wang
2023-02-10 15:25:35 -08:00
committed by Copybara-Service
parent b204aed4cb
commit 1d01973d17
6 changed files with 11 additions and 17 deletions
@@ -85,6 +85,7 @@ void FastPairDataEncryptorImpl::Factory::CreateAsyncWithKeyExchange(
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.model_id,
[&device, &on_get_instance_callback](DeviceMetadata& metadata) {
@@ -98,6 +99,7 @@ void FastPairDataEncryptorImpl::Factory::DeviceMetadataRetrieved(
absl::AnyInvocable<void(std::unique_ptr<FastPairDataEncryptor>)>
on_get_instance_callback,
DeviceMetadata& device_metadata) {
DCHECK(&device_metadata);
std::optional<KeyPair> key_pair =
FastPairEncryption::GenerateKeysWithEcdhKeyAgreement(
device_metadata.GetDetails().anti_spoofing_key_pair().public_key());
@@ -109,7 +109,7 @@ void FastPairDiscoverableScannerImpl::OnDeviceFound(
}
model_id_parse_attempts_[peripheral.GetName()] = 1;
NEARBY_LOGS(WARNING) << __func__ << ": Attempting to get model ID";
NEARBY_LOGS(INFO) << __func__ << ": Attempting to get model ID";
std::vector<uint8_t> service_data;
std::string model_id_bytes = fast_pair_service_data.data();
std::move(std::begin(model_id_bytes), std::end(model_id_bytes),
@@ -152,6 +152,7 @@ void FastPairDiscoverableScannerImpl::OnModelIdRetrieved(
return;
}
NEARBY_LOGS(INFO) << __func__ << ": Attempting to get device metadata.";
FastPairRepository::Get()->GetDeviceMetadata(
model_id.value(),
absl::bind_front(
@@ -162,6 +163,7 @@ void FastPairDiscoverableScannerImpl::OnModelIdRetrieved(
void FastPairDiscoverableScannerImpl::OnDeviceMetadataRetrieved(
const std::string& address, const std::string model_id,
DeviceMetadata& device_metadata) {
DCHECK(&device_metadata);
// Ignore advertisements that aren't for Fast Pair but leverage the service
// UUID.
if (!IsValidDeviceType(device_metadata.GetDetails())) {
@@ -43,7 +43,8 @@ void FastPairMetadataDownloader::Run() {
void FastPairMetadataDownloader::Succeed(DeviceMetadata& device_metadata) {
DCHECK(was_run_);
DCHECK(success_callback_);
NEARBY_LOGS(INFO) << __func__ << ": Fast Pair download of "
<< device_metadata.GetDetails().name() << " succeeded.";
std::move(success_callback_)(device_metadata);
}
@@ -90,13 +90,12 @@ void FastPairMetadataDownloaderImpl::CallAccessServer(
repository_->GetObservedDevice(
request,
[&](const proto::GetObservedDeviceResponse& response) {
NEARBY_LOGS(INFO) << "Maggie: " << __func__
<< "Name: " << response.device().name();
NEARBY_LOGS(INFO) << "Maggie: " << __func__
NEARBY_LOGS(INFO) << __func__ << "Name: " << response.device().name();
NEARBY_LOGS(INFO) << __func__
<< "Image URL: " << response.device().image_url();
NEARBY_LOGS(INFO)
<< "Maggie: " << __func__ << "StringNotification: "
<< __func__ << "StringNotification: "
<< response.strings().initial_notification_description();
OnAccessServerSuccess(response);
},
@@ -44,17 +44,8 @@ FastPairRepositoryImpl::FastPairRepositoryImpl(
void FastPairRepositoryImpl::GetDeviceMetadata(
absl::string_view hex_model_id,
DeviceMetadataCallback callback) {
callback_ = std::move(callback);
downloader_ = FastPairMetadataDownloaderImpl::Factory::Create(
hex_model_id, repository_factory_.get(),
[&](DeviceMetadata& device_metadata) {
NEARBY_LOGS(INFO) << __func__ << ": Fast Pair download of "
<< device_metadata.GetDetails().name()
<< " succeeded.";
DCHECK(callback_);
std::move(callback_)(device_metadata);
},
[&]() {
hex_model_id, repository_factory_.get(), std::move(callback), []() {
NEARBY_LOGS(INFO) << __func__
<< ": Fast Pair Metadata download failed.";
});
@@ -44,7 +44,6 @@ class FastPairRepositoryImpl : public FastPairRepository {
std::unique_ptr<FastPairMetadataDownloader> downloader_;
std::unique_ptr<network::HttpClientFactory> http_factory_;
std::unique_ptr<FastPairMetadataRepositoryFactory> repository_factory_;
DeviceMetadataCallback callback_;
};
} // namespace fastpair
} // namespace nearby