mirror of
https://github.com/kidfromjupiter/nearby.git
synced 2026-09-14 14:46:12 -04:00
Start scheduled task to call GetAccountInfo.
PiperOrigin-RevId: 809234366
This commit is contained in:
committed by
Copybara-Service
parent
47a84ca925
commit
d4c86c83c1
@@ -54,6 +54,7 @@ cc_library(
|
||||
"//sharing/internal/api:platform",
|
||||
"//sharing/internal/base",
|
||||
"//sharing/internal/public:logging",
|
||||
"//sharing/internal/public:pref_names",
|
||||
"//sharing/internal/public:types",
|
||||
"//sharing/local_device_data",
|
||||
"//sharing/proto:enums_cc_proto",
|
||||
@@ -61,6 +62,7 @@ cc_library(
|
||||
"//sharing/scheduling",
|
||||
"//util/hash:highway_fingerprint",
|
||||
"@com_google_absl//absl/algorithm",
|
||||
"@com_google_absl//absl/base:nullability",
|
||||
"@com_google_absl//absl/container:btree",
|
||||
"@com_google_absl//absl/container:flat_hash_map",
|
||||
"@com_google_absl//absl/container:flat_hash_set",
|
||||
@@ -131,6 +133,7 @@ cc_test(
|
||||
"//sharing/contacts:test_support",
|
||||
"//sharing/internal/api:mock_sharing_platform",
|
||||
"//sharing/internal/api:platform",
|
||||
"//sharing/internal/public:pref_names",
|
||||
"//sharing/internal/test:nearby_test",
|
||||
"//sharing/local_device_data:test_support",
|
||||
"//sharing/proto:enums_cc_proto",
|
||||
|
||||
@@ -51,7 +51,6 @@
|
||||
#include "sharing/certificates/nearby_share_decrypted_public_certificate.h"
|
||||
#include "sharing/certificates/nearby_share_encrypted_metadata_key.h"
|
||||
#include "sharing/certificates/nearby_share_private_certificate.h"
|
||||
#include "sharing/common/nearby_share_prefs.h"
|
||||
#include "sharing/internal/api/bluetooth_adapter.h"
|
||||
#include "sharing/internal/api/preference_manager.h"
|
||||
#include "sharing/internal/api/public_certificate_database.h"
|
||||
@@ -60,6 +59,7 @@
|
||||
#include "sharing/internal/base/encode.h"
|
||||
#include "sharing/internal/public/context.h"
|
||||
#include "sharing/internal/public/logging.h"
|
||||
#include "sharing/internal/public/pref_names.h"
|
||||
#include "sharing/local_device_data/nearby_share_local_device_data_manager.h"
|
||||
#include "sharing/proto/certificate_rpc.pb.h"
|
||||
#include "sharing/proto/encrypted_metadata.pb.h"
|
||||
@@ -74,6 +74,9 @@ namespace nearby {
|
||||
namespace sharing {
|
||||
namespace {
|
||||
|
||||
using ::google::nearby::identity::v1::AccountInfo;
|
||||
using ::google::nearby::identity::v1::GetAccountInfoRequest;
|
||||
using ::google::nearby::identity::v1::GetAccountInfoResponse;
|
||||
using ::google::nearby::identity::v1::PerVisibilitySharedCredentials;
|
||||
using ::google::nearby::identity::v1::PublishDeviceRequest;
|
||||
using ::google::nearby::identity::v1::PublishDeviceResponse;
|
||||
@@ -87,6 +90,8 @@ using ::nearby::sharing::proto::DeviceVisibility;
|
||||
using ::nearby::sharing::proto::EncryptedMetadata;
|
||||
using ::nearby::sharing::proto::PublicCertificate;
|
||||
|
||||
constexpr absl::Duration kGetAccountInfoPeriod = absl::Hours(1);
|
||||
|
||||
constexpr std::array<DeviceVisibility, 2> kVisibilities = {
|
||||
DeviceVisibility::DEVICE_VISIBILITY_ALL_CONTACTS,
|
||||
DeviceVisibility::DEVICE_VISIBILITY_SELF_SHARE,
|
||||
@@ -238,7 +243,7 @@ NearbyShareCertificateManagerImpl::NearbyShareCertificateManagerImpl(
|
||||
[&] { return NextPrivateCertificateExpirationTime(); },
|
||||
/*retry_failures=*/true,
|
||||
/*require_connectivity=*/false,
|
||||
prefs::kNearbySharingSchedulerPrivateCertificateExpirationName,
|
||||
PrefNames::kSchedulerPrivateCertificateExpiration,
|
||||
[this]() {
|
||||
VLOG(1)
|
||||
<< "Private certificate expiration scheduler is called.";
|
||||
@@ -254,7 +259,7 @@ NearbyShareCertificateManagerImpl::NearbyShareCertificateManagerImpl(
|
||||
[&] { return NextPublicCertificateExpirationTime(); },
|
||||
/*retry_failures=*/true,
|
||||
/*require_connectivity=*/false,
|
||||
prefs::kNearbySharingSchedulerPublicCertificateExpirationName,
|
||||
PrefNames::kSchedulerPublicCertificateExpiration,
|
||||
[this]() {
|
||||
VLOG(1)
|
||||
<< ": Public certificate expiration scheduler is called.";
|
||||
@@ -269,7 +274,7 @@ NearbyShareCertificateManagerImpl::NearbyShareCertificateManagerImpl(
|
||||
kNearbyShareLocalCertificateUploadPeriod,
|
||||
/*retry_failures=*/true,
|
||||
/*require_connectivity=*/true,
|
||||
prefs::kNearbySharingSchedulerUploadLocalDeviceCertificatesName,
|
||||
PrefNames::kSchedulerUploadLocalDeviceCertificates,
|
||||
[this]() {
|
||||
VLOG(1)
|
||||
<< "Upload local device certificates scheduler is called.";
|
||||
@@ -286,7 +291,7 @@ NearbyShareCertificateManagerImpl::NearbyShareCertificateManagerImpl(
|
||||
kNearbySharePublicCertificateDownloadPeriod,
|
||||
/*retry_failures=*/true,
|
||||
/*require_connectivity=*/true,
|
||||
prefs::kNearbySharingSchedulerDownloadPublicCertificatesName,
|
||||
PrefNames::kSchedulerDownloadPublicCertificates,
|
||||
[this]() {
|
||||
LOG(INFO)
|
||||
<< "Download public certificates scheduler is called.";
|
||||
@@ -295,6 +300,19 @@ NearbyShareCertificateManagerImpl::NearbyShareCertificateManagerImpl(
|
||||
DownloadPublicCertificatesInExecutor());
|
||||
});
|
||||
})),
|
||||
account_info_update_scheduler_(
|
||||
NearbyShareSchedulerFactory::CreatePeriodicScheduler(
|
||||
context_, preference_manager_, kGetAccountInfoPeriod,
|
||||
/*retry_failures=*/true,
|
||||
/*require_connectivity=*/true,
|
||||
PrefNames::kSchedulerGetAccountInfo,
|
||||
[this]() {
|
||||
LOG(INFO) << "Get account info scheduler is called.";
|
||||
executor_->PostTask([this]() {
|
||||
account_info_update_scheduler_->HandleResult(
|
||||
UpdateAccountInfoInExecutor());
|
||||
});
|
||||
})),
|
||||
executor_(context->CreateSequencedTaskRunner()) {
|
||||
local_device_data_manager_->AddObserver(this);
|
||||
}
|
||||
@@ -304,7 +322,7 @@ NearbyShareCertificateManagerImpl::~NearbyShareCertificateManagerImpl() {
|
||||
}
|
||||
|
||||
std::string NearbyShareCertificateManagerImpl::GetId() {
|
||||
return preference_manager_.GetString(prefs::kNearbySharingDeviceIdName, "");
|
||||
return preference_manager_.GetString(PrefNames::kDeviceId, "");
|
||||
}
|
||||
|
||||
void NearbyShareCertificateManagerImpl::CertificateDownloadContext::
|
||||
@@ -322,8 +340,7 @@ void NearbyShareCertificateManagerImpl::CertificateDownloadContext::
|
||||
[this](const absl::StatusOr<QuerySharedCredentialsResponse>&
|
||||
response) mutable {
|
||||
if (!response.ok()) {
|
||||
LOG(WARNING) << __func__
|
||||
<< ": Failed to download public certificates: "
|
||||
LOG(WARNING) << "Failed to download public certificates: "
|
||||
<< response.status();
|
||||
std::move(download_callback_)(response.status());
|
||||
return;
|
||||
@@ -331,29 +348,22 @@ void NearbyShareCertificateManagerImpl::CertificateDownloadContext::
|
||||
for (const auto& credential : response->shared_credentials()) {
|
||||
if (credential.data_type() !=
|
||||
SharedCredential::DATA_TYPE_PUBLIC_CERTIFICATE) {
|
||||
VLOG(1) << __func__
|
||||
<< ": skipping non "
|
||||
"DATA_TYPE_PUBLIC_CERTIFICATE, credential.id: "
|
||||
<< credential.id();
|
||||
continue;
|
||||
}
|
||||
PublicCertificate certificate;
|
||||
if (!certificate.ParseFromString(credential.data())) {
|
||||
LOG(ERROR)
|
||||
<< __func__
|
||||
<< ": Failed parsing to PublicCertificate, credential.id: "
|
||||
<< credential.id()
|
||||
<< " data: " << absl::BytesToHexString(credential.data());
|
||||
LOG(ERROR) << "Failed parsing to PublicCertificate, credential.id: "
|
||||
<< credential.id() << " data: "
|
||||
<< absl::BytesToHexString(credential.data());
|
||||
continue;
|
||||
}
|
||||
VLOG(1) << __func__
|
||||
<< ": Successfully parsed credential: " << credential.id();
|
||||
VLOG(1) << "Successfully parsed credential: " << credential.id();
|
||||
certificates_.push_back(certificate);
|
||||
}
|
||||
|
||||
if (response->next_page_token().empty()) {
|
||||
LOG(INFO) << __func__ << ": Completed download of "
|
||||
<< certificates_.size() << " certificates";
|
||||
LOG(INFO) << "Completed download of " << certificates_.size()
|
||||
<< " certificates";
|
||||
std::move(download_callback_)(std::move(certificates_));
|
||||
return;
|
||||
}
|
||||
@@ -599,6 +609,7 @@ void NearbyShareCertificateManagerImpl::OnStartScheduledTasks() {
|
||||
public_certificate_expiration_scheduler_->Start();
|
||||
force_contacts_update_scheduler_->Start();
|
||||
download_public_certificates_scheduler_->Start();
|
||||
account_info_update_scheduler_->Start();
|
||||
}
|
||||
|
||||
void NearbyShareCertificateManagerImpl::OnStopScheduledTasks() {
|
||||
@@ -606,6 +617,7 @@ void NearbyShareCertificateManagerImpl::OnStopScheduledTasks() {
|
||||
public_certificate_expiration_scheduler_->Stop();
|
||||
force_contacts_update_scheduler_->Stop();
|
||||
download_public_certificates_scheduler_->Stop();
|
||||
account_info_update_scheduler_->Stop();
|
||||
}
|
||||
|
||||
std::optional<NearbySharePrivateCertificate>
|
||||
@@ -857,5 +869,35 @@ bool NearbyShareCertificateManagerImpl::
|
||||
return result;
|
||||
}
|
||||
|
||||
bool NearbyShareCertificateManagerImpl::UpdateAccountInfoInExecutor() {
|
||||
GetAccountInfoRequest request;
|
||||
bool get_account_info_succeeded = false;
|
||||
absl::Notification notification;
|
||||
nearby_identity_client_->GetAccountInfo(
|
||||
std::move(request),
|
||||
[this, &get_account_info_succeeded, ¬ification](
|
||||
const absl::StatusOr<GetAccountInfoResponse>& response) mutable {
|
||||
if (!response.ok()) {
|
||||
LOG(WARNING) << "GetAccountInfo failed: " << response.status();
|
||||
} else {
|
||||
get_account_info_succeeded = true;
|
||||
const auto& capabilities = response->account_info().capabilities();
|
||||
bool has_titanium_capability =
|
||||
(std::find(capabilities.begin(), capabilities.end(),
|
||||
AccountInfo::CAPABILITY_TITANIUM) !=
|
||||
capabilities.end());
|
||||
preference_manager_.SetBoolean(PrefNames::kAdvancedProtectionEnabled,
|
||||
has_titanium_capability);
|
||||
LOG(INFO) << "GetAccountInfo succeeded, advanced protection enabled: "
|
||||
<< has_titanium_capability;
|
||||
}
|
||||
notification.Notify();
|
||||
});
|
||||
// MUST not terminate early, otherwise notification will go out of scope, and
|
||||
// the callback will call Notify on a destroyed object.
|
||||
notification.WaitForNotification();
|
||||
return get_account_info_succeeded;
|
||||
}
|
||||
|
||||
} // namespace sharing
|
||||
} // namespace nearby
|
||||
|
||||
@@ -23,6 +23,7 @@
|
||||
#include <utility>
|
||||
#include <vector>
|
||||
|
||||
#include "absl/base/nullability.h"
|
||||
#include "absl/functional/any_invocable.h"
|
||||
#include "absl/status/statusor.h"
|
||||
#include "absl/time/time.h"
|
||||
@@ -188,6 +189,9 @@ class NearbyShareCertificateManagerImpl
|
||||
// Returns the device id use to identify the local device in BE.
|
||||
std::string GetId();
|
||||
|
||||
// Calls the GetAccountInfo RPC to update the account info.
|
||||
bool UpdateAccountInfoInExecutor();
|
||||
|
||||
Context* const context_;
|
||||
AccountManager& account_manager_;
|
||||
NearbyShareLocalDeviceDataManager* const local_device_data_manager_;
|
||||
@@ -198,12 +202,19 @@ class NearbyShareCertificateManagerImpl
|
||||
nearby_identity_client_;
|
||||
|
||||
std::shared_ptr<NearbyShareCertificateStorage> certificate_storage_;
|
||||
std::unique_ptr<NearbyShareScheduler>
|
||||
absl_nonnull std::unique_ptr<NearbyShareScheduler>
|
||||
private_certificate_expiration_scheduler_;
|
||||
std::unique_ptr<NearbyShareScheduler>
|
||||
absl_nonnull std::unique_ptr<NearbyShareScheduler>
|
||||
public_certificate_expiration_scheduler_;
|
||||
std::unique_ptr<NearbyShareScheduler> force_contacts_update_scheduler_;
|
||||
std::unique_ptr<NearbyShareScheduler> download_public_certificates_scheduler_;
|
||||
absl_nonnull std::unique_ptr<NearbyShareScheduler>
|
||||
force_contacts_update_scheduler_;
|
||||
absl_nonnull std::unique_ptr<NearbyShareScheduler>
|
||||
download_public_certificates_scheduler_;
|
||||
// Scheduled task that updates the account info from BE.
|
||||
// Specifically, it will keep fetch the Titanium enrollment state and store in
|
||||
// preferences.
|
||||
absl_nonnull std::unique_ptr<NearbyShareScheduler>
|
||||
account_info_update_scheduler_;
|
||||
|
||||
std::unique_ptr<TaskRunner> executor_;
|
||||
};
|
||||
|
||||
@@ -48,10 +48,10 @@
|
||||
#include "sharing/certificates/nearby_share_encrypted_metadata_key.h"
|
||||
#include "sharing/certificates/nearby_share_private_certificate.h"
|
||||
#include "sharing/certificates/test_util.h"
|
||||
#include "sharing/common/nearby_share_prefs.h"
|
||||
#include "sharing/contacts/fake_nearby_share_contact_manager.h"
|
||||
#include "sharing/internal/api/fake_nearby_share_client.h"
|
||||
#include "sharing/internal/api/mock_sharing_platform.h"
|
||||
#include "sharing/internal/public/pref_names.h"
|
||||
#include "sharing/internal/test/fake_bluetooth_adapter.h"
|
||||
#include "sharing/internal/test/fake_context.h"
|
||||
#include "sharing/internal/test/fake_preference_manager.h"
|
||||
@@ -67,7 +67,9 @@
|
||||
namespace nearby {
|
||||
namespace sharing {
|
||||
namespace {
|
||||
using ::google::nearby::identity::v1::AccountInfo;
|
||||
using ::google::nearby::identity::v1::Device;
|
||||
using ::google::nearby::identity::v1::GetAccountInfoResponse;
|
||||
using ::google::nearby::identity::v1::PublishDeviceRequest;
|
||||
using ::google::nearby::identity::v1::PublishDeviceResponse;
|
||||
using ::google::nearby::identity::v1::QuerySharedCredentialsRequest;
|
||||
@@ -108,7 +110,7 @@ class NearbyShareCertificateManagerImplTest
|
||||
.WillByDefault(ReturnRef(fake_account_manager_));
|
||||
// Set time to t0.
|
||||
FastForward(t0 - fake_context_.GetClock()->Now());
|
||||
preference_manager_.SetString(prefs::kNearbySharingDeviceIdName, kDeviceId);
|
||||
preference_manager_.SetString(PrefNames::kDeviceId, kDeviceId);
|
||||
local_device_data_manager_ =
|
||||
std::make_unique<FakeNearbyShareLocalDeviceDataManager>(
|
||||
kDefaultDeviceName);
|
||||
@@ -156,26 +158,33 @@ class NearbyShareCertificateManagerImplTest
|
||||
|
||||
private_cert_exp_scheduler_ =
|
||||
scheduler_factory_.pref_name_to_expiration_instance()
|
||||
.find(
|
||||
prefs::kNearbySharingSchedulerPrivateCertificateExpirationName)
|
||||
.find(PrefNames::kSchedulerPrivateCertificateExpiration)
|
||||
->second.fake_scheduler;
|
||||
public_cert_exp_scheduler_ =
|
||||
scheduler_factory_.pref_name_to_expiration_instance()
|
||||
.find(prefs::kNearbySharingSchedulerPublicCertificateExpirationName)
|
||||
.find(PrefNames::kSchedulerPublicCertificateExpiration)
|
||||
->second.fake_scheduler;
|
||||
upload_scheduler_ =
|
||||
scheduler_factory_.pref_name_to_periodic_instance()
|
||||
.find(
|
||||
prefs::kNearbySharingSchedulerUploadLocalDeviceCertificatesName)
|
||||
.find(PrefNames::kSchedulerUploadLocalDeviceCertificates)
|
||||
->second.fake_scheduler;
|
||||
download_scheduler_ =
|
||||
scheduler_factory_.pref_name_to_periodic_instance()
|
||||
.find(prefs::kNearbySharingSchedulerDownloadPublicCertificatesName)
|
||||
.find(PrefNames::kSchedulerDownloadPublicCertificates)
|
||||
->second.fake_scheduler;
|
||||
account_info_update_scheduler_ =
|
||||
scheduler_factory_.pref_name_to_periodic_instance()
|
||||
.find(PrefNames::kSchedulerGetAccountInfo)
|
||||
->second.fake_scheduler;
|
||||
|
||||
PopulatePrivateCertificates();
|
||||
PopulatePublicCertificates();
|
||||
cert_manager_->StartScheduledTasks();
|
||||
EXPECT_TRUE(private_cert_exp_scheduler_->is_running());
|
||||
EXPECT_TRUE(public_cert_exp_scheduler_->is_running());
|
||||
EXPECT_TRUE(upload_scheduler_->is_running());
|
||||
EXPECT_TRUE(download_scheduler_->is_running());
|
||||
EXPECT_TRUE(account_info_update_scheduler_->is_running());
|
||||
}
|
||||
|
||||
// NearbyShareCertificateManager::Observer:
|
||||
@@ -333,8 +342,7 @@ class NearbyShareCertificateManagerImplTest
|
||||
responses.push_back(response);
|
||||
}
|
||||
PublishDeviceResponse response;
|
||||
response.add_contact_updates(
|
||||
PublishDeviceResponse::CONTACT_UPDATE_ADDED);
|
||||
response.add_contact_updates(PublishDeviceResponse::CONTACT_UPDATE_ADDED);
|
||||
responses.push_back(response);
|
||||
identity_client->SetPublishDeviceResponses(std::move(responses));
|
||||
|
||||
@@ -479,6 +487,7 @@ class NearbyShareCertificateManagerImplTest
|
||||
FakeNearbyShareScheduler* public_cert_exp_scheduler_ = nullptr;
|
||||
FakeNearbyShareScheduler* upload_scheduler_ = nullptr;
|
||||
FakeNearbyShareScheduler* download_scheduler_ = nullptr;
|
||||
FakeNearbyShareScheduler* account_info_update_scheduler_ = nullptr;
|
||||
MacAddress bluetooth_mac_address_;
|
||||
size_t num_public_certs_downloaded_notifications_ = 0;
|
||||
size_t num_private_certs_changed_notifications_ = 0;
|
||||
@@ -762,7 +771,6 @@ TEST_F(NearbyShareCertificateManagerImplTest,
|
||||
TEST_F(NearbyShareCertificateManagerImplTest,
|
||||
RefreshPrivateCertificates_OnLocalDeviceMetadataChanged) {
|
||||
Initialize();
|
||||
cert_manager_->StartScheduledTasks();
|
||||
|
||||
// Destroy and recreate private certificates if any metadata fields change.
|
||||
for (bool did_device_name_change : {true, false}) {
|
||||
@@ -800,7 +808,6 @@ TEST_F(NearbyShareCertificateManagerImplTest,
|
||||
RefreshPrivateCertificates_PublishDevice_OnVendorIdChanged) {
|
||||
Initialize();
|
||||
cert_store_->ReplacePrivateCertificates(private_certificates_);
|
||||
cert_manager_->StartScheduledTasks();
|
||||
|
||||
cert_manager_->SetVendorId(12345);
|
||||
|
||||
@@ -825,7 +832,6 @@ TEST_F(NearbyShareCertificateManagerImplTest,
|
||||
SetVendorId_WhenNoPrivateCertificates) {
|
||||
Initialize();
|
||||
cert_store_->ReplacePrivateCertificates({});
|
||||
cert_manager_->StartScheduledTasks();
|
||||
|
||||
cert_manager_->SetVendorId(12345);
|
||||
|
||||
@@ -853,7 +859,6 @@ TEST_F(NearbyShareCertificateManagerImplTest,
|
||||
FastForward(kNearbyShareCertificateValidityPeriod * 1.5);
|
||||
cert_store_->ReplacePrivateCertificates(private_certificates_);
|
||||
|
||||
cert_manager_->StartScheduledTasks();
|
||||
InvokePrivateCertificateRefresh(/*expected_success=*/true);
|
||||
|
||||
VerifyPrivateCertificates(/*expected_metadata=*/GetNearbyShareTestMetadata());
|
||||
@@ -866,8 +871,6 @@ TEST_F(NearbyShareCertificateManagerImplTest,
|
||||
|
||||
SetBluetoothAdapterIsPresent(false);
|
||||
|
||||
cert_manager_->StartScheduledTasks();
|
||||
|
||||
// Bluetooth MAC address is optional, so the refresh should still succeed.
|
||||
InvokePrivateCertificateRefresh(/*expected_success=*/true);
|
||||
}
|
||||
@@ -921,7 +924,7 @@ TEST_F(
|
||||
EXPECT_EQ(0, upload_scheduler_->num_immediate_requests());
|
||||
absl::Time next_schedule_time =
|
||||
scheduler_factory_.pref_name_to_expiration_instance()
|
||||
.find(prefs::kNearbySharingSchedulerPrivateCertificateExpirationName)
|
||||
.find(PrefNames::kSchedulerPrivateCertificateExpiration)
|
||||
->second.expiration_time_functor();
|
||||
|
||||
// Next expiration time is set to InfiniteFuture to disable the timer.
|
||||
@@ -949,5 +952,80 @@ TEST_F(NearbyShareCertificateManagerImplTest,
|
||||
EXPECT_EQ(download_scheduler_->num_immediate_requests(), 1);
|
||||
}
|
||||
|
||||
TEST_F(NearbyShareCertificateManagerImplTest, StopScheduledTasks) {
|
||||
Initialize();
|
||||
cert_manager_->StopScheduledTasks();
|
||||
EXPECT_FALSE(private_cert_exp_scheduler_->is_running());
|
||||
EXPECT_FALSE(public_cert_exp_scheduler_->is_running());
|
||||
EXPECT_FALSE(upload_scheduler_->is_running());
|
||||
EXPECT_FALSE(download_scheduler_->is_running());
|
||||
EXPECT_FALSE(account_info_update_scheduler_->is_running());
|
||||
}
|
||||
|
||||
TEST_F(NearbyShareCertificateManagerImplTest,
|
||||
UpdateAccountInfo_TitanumEnabled) {
|
||||
Initialize();
|
||||
FakeNearbyIdentityClient* identity_client = GetIdentityClient();
|
||||
GetAccountInfoResponse response;
|
||||
response.mutable_account_info()->mutable_capabilities()->Add(
|
||||
AccountInfo::CAPABILITY_TITANIUM);
|
||||
identity_client->SetGetAccountInfoResponse(response);
|
||||
|
||||
account_info_update_scheduler_->InvokeRequestCallback();
|
||||
Sync();
|
||||
|
||||
EXPECT_FALSE(GetIdentityClient()->get_account_info_requests().empty());
|
||||
EXPECT_TRUE(preference_manager_.GetBoolean(
|
||||
PrefNames::kAdvancedProtectionEnabled, /*default_value=*/false));
|
||||
}
|
||||
|
||||
TEST_F(NearbyShareCertificateManagerImplTest,
|
||||
UpdateAccountInfo_TitanumDisabled) {
|
||||
Initialize();
|
||||
preference_manager_.SetBoolean(PrefNames::kAdvancedProtectionEnabled, true);
|
||||
FakeNearbyIdentityClient* identity_client = GetIdentityClient();
|
||||
GetAccountInfoResponse response;
|
||||
identity_client->SetGetAccountInfoResponse(response);
|
||||
|
||||
account_info_update_scheduler_->InvokeRequestCallback();
|
||||
Sync();
|
||||
|
||||
EXPECT_FALSE(GetIdentityClient()->get_account_info_requests().empty());
|
||||
EXPECT_FALSE(preference_manager_.GetBoolean(
|
||||
PrefNames::kAdvancedProtectionEnabled, /*default_value=*/false));
|
||||
}
|
||||
|
||||
TEST_F(NearbyShareCertificateManagerImplTest,
|
||||
UpdateAccountInfo_TitanumUnspecified) {
|
||||
Initialize();
|
||||
preference_manager_.SetBoolean(PrefNames::kAdvancedProtectionEnabled, true);
|
||||
FakeNearbyIdentityClient* identity_client = GetIdentityClient();
|
||||
GetAccountInfoResponse response;
|
||||
response.mutable_account_info()->mutable_capabilities()->Add(
|
||||
AccountInfo::CAPABILITY_UNSPECIFIED);
|
||||
identity_client->SetGetAccountInfoResponse(response);
|
||||
|
||||
account_info_update_scheduler_->InvokeRequestCallback();
|
||||
Sync();
|
||||
|
||||
EXPECT_FALSE(GetIdentityClient()->get_account_info_requests().empty());
|
||||
EXPECT_FALSE(preference_manager_.GetBoolean(
|
||||
PrefNames::kAdvancedProtectionEnabled, /*default_value=*/false));
|
||||
}
|
||||
|
||||
TEST_F(NearbyShareCertificateManagerImplTest,
|
||||
UpdateAccountInfo_RpcFailed) {
|
||||
Initialize();
|
||||
preference_manager_.SetBoolean(PrefNames::kAdvancedProtectionEnabled, true);
|
||||
|
||||
account_info_update_scheduler_->InvokeRequestCallback();
|
||||
Sync();
|
||||
|
||||
// Identity client by default return Status::NotFound.
|
||||
EXPECT_FALSE(GetIdentityClient()->get_account_info_requests().empty());
|
||||
EXPECT_TRUE(preference_manager_.GetBoolean(
|
||||
PrefNames::kAdvancedProtectionEnabled, /*default_value=*/false));
|
||||
}
|
||||
|
||||
} // namespace sharing
|
||||
} // namespace nearby
|
||||
|
||||
@@ -113,6 +113,7 @@ void ResetSchedulers(PreferenceManager& preference_manager) {
|
||||
preference_manager.Remove(PrefNames::kSchedulerPrivateCertificateExpiration);
|
||||
preference_manager.Remove(PrefNames::kSchedulerPublicCertificateExpiration);
|
||||
preference_manager.Remove(PrefNames::kSchedulerUploadLocalDeviceCertificates);
|
||||
preference_manager.Remove(PrefNames::kSchedulerGetAccountInfo);
|
||||
}
|
||||
|
||||
} // namespace prefs
|
||||
|
||||
@@ -68,13 +68,13 @@ class FakeNearbyIdentityClient
|
||||
~FakeNearbyIdentityClient() override = default;
|
||||
|
||||
std::vector<google::nearby::identity::v1::PublishDeviceRequest>&
|
||||
publish_device_requests() {
|
||||
publish_device_requests() ABSL_LOCKS_EXCLUDED(mutex_) {
|
||||
absl::MutexLock lock(mutex_);
|
||||
return publish_device_requests_;
|
||||
}
|
||||
|
||||
std::vector<google::nearby::identity::v1::QuerySharedCredentialsRequest>&
|
||||
query_shared_credentials_requests() {
|
||||
query_shared_credentials_requests() ABSL_LOCKS_EXCLUDED(mutex_) {
|
||||
absl::MutexLock lock(mutex_);
|
||||
return query_shared_credentials_requests_;
|
||||
}
|
||||
@@ -84,12 +84,12 @@ class FakeNearbyIdentityClient
|
||||
absl::AnyInvocable<
|
||||
void(const absl::StatusOr<google::nearby::identity::v1::
|
||||
PublishDeviceResponse>& response) &&>
|
||||
callback) override;
|
||||
callback) ABSL_LOCKS_EXCLUDED(mutex_) override;
|
||||
|
||||
void SetPublishDeviceResponses(
|
||||
std::vector<
|
||||
absl::StatusOr<google::nearby::identity::v1::PublishDeviceResponse>>
|
||||
responses) {
|
||||
responses) ABSL_LOCKS_EXCLUDED(mutex_) {
|
||||
absl::MutexLock lock(mutex_);
|
||||
publish_device_responses_ = responses;
|
||||
}
|
||||
@@ -100,26 +100,32 @@ class FakeNearbyIdentityClient
|
||||
void(const absl::StatusOr<
|
||||
google::nearby::identity::v1::QuerySharedCredentialsResponse>&
|
||||
response) &&>
|
||||
callback) override;
|
||||
callback) ABSL_LOCKS_EXCLUDED(mutex_) override;
|
||||
|
||||
void SetQuerySharedCredentialsResponses(
|
||||
std::vector<absl::StatusOr<
|
||||
google::nearby::identity::v1::QuerySharedCredentialsResponse>>
|
||||
responses) {
|
||||
responses) ABSL_LOCKS_EXCLUDED(mutex_) {
|
||||
absl::MutexLock lock(mutex_);
|
||||
query_shared_credentials_responses_ = responses;
|
||||
}
|
||||
|
||||
std::vector<google::nearby::identity::v1::GetAccountInfoRequest>&
|
||||
get_account_info_requests() ABSL_LOCKS_EXCLUDED(mutex_) {
|
||||
absl::MutexLock lock(mutex_);
|
||||
return get_account_info_requests_;
|
||||
}
|
||||
|
||||
void GetAccountInfo(
|
||||
google::nearby::identity::v1::GetAccountInfoRequest request,
|
||||
absl::AnyInvocable<
|
||||
void(const absl::StatusOr<google::nearby::identity::v1::
|
||||
GetAccountInfoResponse>& response) &&>
|
||||
callback) override;
|
||||
callback) ABSL_LOCKS_EXCLUDED(mutex_) override;
|
||||
|
||||
void SetGetAccountInfoResponse(
|
||||
absl::StatusOr<google::nearby::identity::v1::GetAccountInfoResponse>
|
||||
response) {
|
||||
response) ABSL_LOCKS_EXCLUDED(mutex_) {
|
||||
absl::MutexLock lock(mutex_);
|
||||
get_account_info_response_ = response;
|
||||
}
|
||||
|
||||
@@ -52,6 +52,8 @@ class PrefNames {
|
||||
"nearby_sharing.is_analytics_enabled";
|
||||
static constexpr absl::string_view kAdvancedProtectionEnabled =
|
||||
"nearby_sharing.advanced_protection_enabled";
|
||||
static constexpr absl::string_view kSchedulerGetAccountInfo =
|
||||
"nearby_sharing.scheduler.get_account_info";
|
||||
};
|
||||
|
||||
} // namespace nearby::sharing
|
||||
|
||||
Reference in New Issue
Block a user