mirror of
https://github.com/kidfromjupiter/nearby.git
synced 2026-09-14 14:46:12 -04:00
Remove deprecated string aliases.
PiperOrigin-RevId: 876303135
This commit is contained in:
committed by
Copybara-Service
parent
e5046f6b55
commit
1a543b0d7f
+2
-2
@@ -620,7 +620,6 @@ cc_test(
|
||||
":transfer_metadata",
|
||||
":transfer_metadata_matchers",
|
||||
":types",
|
||||
"//base:casts",
|
||||
"//internal/analytics:mock_event_logger",
|
||||
"//internal/base:file_path",
|
||||
"//internal/base:files",
|
||||
@@ -640,6 +639,7 @@ cc_test(
|
||||
"//sharing/flags/generated:generated_flags",
|
||||
"//sharing/internal/api:mock_sharing_platform",
|
||||
"//sharing/internal/api:platform",
|
||||
"//sharing/internal/public:pref_names",
|
||||
"//sharing/internal/test:nearby_test",
|
||||
"//sharing/local_device_data",
|
||||
"//sharing/local_device_data:test_support",
|
||||
@@ -727,6 +727,7 @@ cc_test(
|
||||
"//internal/test",
|
||||
"//sharing/common",
|
||||
"//sharing/common:enum",
|
||||
"//sharing/internal/public:pref_names",
|
||||
"//sharing/internal/test:nearby_test",
|
||||
"//sharing/local_device_data:test_support",
|
||||
"//sharing/proto:enums_cc_proto",
|
||||
@@ -735,7 +736,6 @@ cc_test(
|
||||
"@com_google_absl//absl/strings:string_view",
|
||||
"@com_google_absl//absl/synchronization",
|
||||
"@com_google_absl//absl/time",
|
||||
"@com_google_absl//absl/types:span",
|
||||
"@com_google_googletest//:gtest_main",
|
||||
],
|
||||
)
|
||||
|
||||
@@ -36,11 +36,11 @@
|
||||
#include "sharing/certificates/constants.h"
|
||||
#include "sharing/certificates/nearby_share_certificate_storage.h"
|
||||
#include "sharing/certificates/nearby_share_private_certificate.h"
|
||||
#include "sharing/common/nearby_share_prefs.h"
|
||||
#include "sharing/internal/api/preference_manager.h"
|
||||
#include "sharing/internal/api/private_certificate_data.h"
|
||||
#include "sharing/internal/api/public_certificate_database.h"
|
||||
#include "sharing/internal/public/logging.h"
|
||||
#include "sharing/internal/public/pref_names.h"
|
||||
#include "sharing/proto/rpc_resources.pb.h"
|
||||
#include "sharing/proto/timestamp.pb.h"
|
||||
|
||||
@@ -350,7 +350,7 @@ std::vector<NearbySharePrivateCertificate>
|
||||
NearbyShareCertificateStorageImpl::GetPrivateCertificates() {
|
||||
std::vector<PrivateCertificateData> list =
|
||||
preference_manager_.GetPrivateCertificateArray(
|
||||
prefs::kNearbySharingPrivateCertificateListName);
|
||||
PrefNames::kPrivateCertificateList);
|
||||
std::vector<NearbySharePrivateCertificate> certs;
|
||||
certs.reserve(list.size());
|
||||
for (const PrivateCertificateData& cert_data : list) {
|
||||
@@ -391,7 +391,7 @@ void NearbyShareCertificateStorageImpl::ReplacePrivateCertificates(
|
||||
list.push_back(cert.ToCertificateData());
|
||||
}
|
||||
preference_manager_.SetPrivateCertificateArray(
|
||||
prefs::kNearbySharingPrivateCertificateListName, list);
|
||||
PrefNames::kPrivateCertificateList, list);
|
||||
}
|
||||
|
||||
void NearbyShareCertificateStorageImpl::AddPublicCertificates(
|
||||
@@ -504,7 +504,7 @@ void NearbyShareCertificateStorageImpl::ClearPublicCertificates(
|
||||
bool NearbyShareCertificateStorageImpl::FetchPublicCertificateExpirations() {
|
||||
std::vector<std::pair<std::string, int64_t>> expirations =
|
||||
preference_manager_.GetCertificateExpirationArray(
|
||||
prefs::kNearbySharingPublicCertificateExpirationDictName);
|
||||
PrefNames::kPublicCertificateExpirationDict);
|
||||
public_certificate_expirations_.clear();
|
||||
if (expirations.empty()) {
|
||||
return false;
|
||||
@@ -535,7 +535,7 @@ void NearbyShareCertificateStorageImpl::SavePublicCertificateExpirations() {
|
||||
}
|
||||
|
||||
preference_manager_.SetCertificateExpirationArray(
|
||||
prefs::kNearbySharingPublicCertificateExpirationDictName, expirations);
|
||||
PrefNames::kPublicCertificateExpirationDict, expirations);
|
||||
}
|
||||
|
||||
} // namespace nearby::sharing
|
||||
|
||||
@@ -38,9 +38,9 @@
|
||||
#include "sharing/certificates/nearby_share_certificate_storage.h"
|
||||
#include "sharing/certificates/nearby_share_private_certificate.h"
|
||||
#include "sharing/certificates/test_util.h"
|
||||
#include "sharing/common/nearby_share_prefs.h"
|
||||
#include "sharing/internal/api/mock_public_certificate_db.h"
|
||||
#include "sharing/internal/api/private_certificate_data.h"
|
||||
#include "sharing/internal/public/pref_names.h"
|
||||
#include "sharing/internal/test/fake_preference_manager.h"
|
||||
#include "sharing/internal/test/fake_public_certificate_db.h"
|
||||
#include "sharing/proto/enums.pb.h"
|
||||
@@ -153,10 +153,8 @@ class NearbyShareCertificateStorageImplTest : public ::testing::Test {
|
||||
NearbyShareCertificateStorageImplTest&) = delete;
|
||||
|
||||
void SetUp() override {
|
||||
preference_manager_.Remove(
|
||||
prefs::kNearbySharingPublicCertificateExpirationDictName);
|
||||
preference_manager_.Remove(
|
||||
prefs::kNearbySharingPrivateCertificateListName);
|
||||
preference_manager_.Remove(PrefNames::kPublicCertificateExpirationDict);
|
||||
preference_manager_.Remove(PrefNames::kPrivateCertificateList);
|
||||
}
|
||||
|
||||
std::map<std::string, PublicCertificate> PrepopulatePublicCertificates() {
|
||||
@@ -185,8 +183,7 @@ class NearbyShareCertificateStorageImplTest : public ::testing::Test {
|
||||
entries.emplace(cert.secret_id(), std::move(cert));
|
||||
}
|
||||
preference_manager_.SetCertificateExpirationArray(
|
||||
prefs::kNearbySharingPublicCertificateExpirationDictName,
|
||||
expirations);
|
||||
PrefNames::kPublicCertificateExpirationDict, expirations);
|
||||
return entries;
|
||||
}
|
||||
|
||||
@@ -835,21 +832,20 @@ TEST_F(NearbyShareCertificateStorageImplTest,
|
||||
|
||||
std::vector<api::PrivateCertificateData> private_cert_data =
|
||||
preference_manager_.GetPrivateCertificateArray(
|
||||
prefs::kNearbySharingPrivateCertificateListName);
|
||||
PrefNames::kPrivateCertificateList);
|
||||
ASSERT_EQ(private_cert_data.size(), 3u);
|
||||
// Set to invalid base64 encoded string.
|
||||
private_cert_data[0].key_pair = "::..\\|@#";
|
||||
preference_manager_.SetPrivateCertificateArray(
|
||||
prefs::kNearbySharingPrivateCertificateListName, private_cert_data);
|
||||
PrefNames::kPrivateCertificateList, private_cert_data);
|
||||
|
||||
std::vector<NearbySharePrivateCertificate> certs =
|
||||
cert_store->GetPrivateCertificates();
|
||||
|
||||
// Verify corrupted cert has been removed.
|
||||
EXPECT_TRUE(certs.empty());
|
||||
private_cert_data =
|
||||
preference_manager_.GetPrivateCertificateArray(
|
||||
prefs::kNearbySharingPrivateCertificateListName);
|
||||
private_cert_data = preference_manager_.GetPrivateCertificateArray(
|
||||
PrefNames::kPrivateCertificateList);
|
||||
EXPECT_TRUE(private_cert_data.empty());
|
||||
}
|
||||
|
||||
|
||||
@@ -16,7 +16,6 @@
|
||||
|
||||
#include <string>
|
||||
|
||||
#include "absl/base/attributes.h"
|
||||
#include "sharing/internal/api/preference_manager.h"
|
||||
#include "sharing/internal/public/pref_names.h"
|
||||
#include "sharing/proto/enums.pb.h"
|
||||
@@ -27,49 +26,10 @@ namespace prefs {
|
||||
namespace {
|
||||
using ::nearby::sharing::PrefNames;
|
||||
using ::nearby::sharing::api::PreferenceManager;
|
||||
|
||||
using DataUsage = ::nearby::sharing::proto::DataUsage;
|
||||
using FastInitiationNotificationState =
|
||||
::nearby::sharing::proto::FastInitiationNotificationState;
|
||||
using ::nearby::sharing::proto::DataUsage;
|
||||
using ::nearby::sharing::proto::FastInitiationNotificationState;
|
||||
} // namespace
|
||||
|
||||
ABSL_CONST_INIT const char* kNearbySharingBackgroundVisibilityName =
|
||||
PrefNames::kVisibility.data();
|
||||
ABSL_CONST_INIT const char* kNearbySharingBackgroundFallbackVisibilityName =
|
||||
PrefNames::kFallbackVisibility.data();
|
||||
ABSL_CONST_INIT const char*
|
||||
kNearbySharingBackgroundVisibilityExpirationSeconds =
|
||||
PrefNames::kVisibilityExpirationSeconds.data();
|
||||
ABSL_CONST_INIT const char* kNearbySharingCustomSavePath =
|
||||
PrefNames::kCustomSavePath.data();
|
||||
ABSL_CONST_INIT const char* kNearbySharingDataUsageName =
|
||||
PrefNames::kDataUsage.data();
|
||||
ABSL_CONST_INIT const char* kNearbySharingDeviceIdName =
|
||||
PrefNames::kDeviceId.data();
|
||||
ABSL_CONST_INIT const char* kNearbySharingDeviceNameName =
|
||||
PrefNames::kDeviceName.data();
|
||||
ABSL_CONST_INIT const char* kNearbySharingFastInitiationNotificationStateName =
|
||||
PrefNames::kFastInitiationNotificationState.data();
|
||||
ABSL_CONST_INIT const char* kNearbySharingPrivateCertificateListName =
|
||||
PrefNames::kPrivateCertificateList.data();
|
||||
ABSL_CONST_INIT const char* kNearbySharingPublicCertificateExpirationDictName =
|
||||
PrefNames::kPublicCertificateExpirationDict.data();
|
||||
ABSL_CONST_INIT const char*
|
||||
kNearbySharingSchedulerDownloadPublicCertificatesName =
|
||||
PrefNames::kSchedulerDownloadPublicCertificates.data();
|
||||
ABSL_CONST_INIT const char*
|
||||
kNearbySharingSchedulerPrivateCertificateExpirationName =
|
||||
PrefNames::kSchedulerPrivateCertificateExpiration.data();
|
||||
ABSL_CONST_INIT const char*
|
||||
kNearbySharingSchedulerPublicCertificateExpirationName =
|
||||
PrefNames::kSchedulerPublicCertificateExpiration.data();
|
||||
ABSL_CONST_INIT const char*
|
||||
kNearbySharingSchedulerUploadLocalDeviceCertificatesName =
|
||||
PrefNames::kSchedulerUploadLocalDeviceCertificates.data();
|
||||
ABSL_CONST_INIT const char* kNearbySharingUsersName = PrefNames::kUsers.data();
|
||||
ABSL_CONST_INIT const char* kNearbySharingIsAnalyticsEnabledName =
|
||||
PrefNames::kIsAnalyticsEnabled.data();
|
||||
|
||||
void RegisterNearbySharingPrefs(PreferenceManager& preference_manager,
|
||||
bool skip_persistent_ones) {
|
||||
// These prefs are not synced across devices on purpose.
|
||||
|
||||
@@ -23,33 +23,6 @@ namespace nearby {
|
||||
namespace sharing {
|
||||
namespace prefs {
|
||||
|
||||
// These are for backward compatibility only. New code should use the
|
||||
// nearby::sharing::api::PrefNames class instead.
|
||||
ABSL_CONST_INIT extern const char* kNearbySharingBackgroundVisibilityName;
|
||||
ABSL_CONST_INIT extern const char*
|
||||
kNearbySharingBackgroundFallbackVisibilityName;
|
||||
ABSL_CONST_INIT extern const char*
|
||||
kNearbySharingBackgroundVisibilityExpirationSeconds;
|
||||
ABSL_CONST_INIT extern const char* kNearbySharingCustomSavePath;
|
||||
ABSL_CONST_INIT extern const char* kNearbySharingDataUsageName;
|
||||
ABSL_CONST_INIT extern const char* kNearbySharingDeviceIdName;
|
||||
ABSL_CONST_INIT extern const char* kNearbySharingDeviceNameName;
|
||||
ABSL_CONST_INIT extern const char*
|
||||
kNearbySharingFastInitiationNotificationStateName;
|
||||
ABSL_CONST_INIT extern const char* kNearbySharingPrivateCertificateListName;
|
||||
ABSL_CONST_INIT extern const char*
|
||||
kNearbySharingPublicCertificateExpirationDictName;
|
||||
ABSL_CONST_INIT extern const char*
|
||||
kNearbySharingSchedulerDownloadPublicCertificatesName;
|
||||
ABSL_CONST_INIT extern const char*
|
||||
kNearbySharingSchedulerPrivateCertificateExpirationName;
|
||||
ABSL_CONST_INIT extern const char*
|
||||
kNearbySharingSchedulerPublicCertificateExpirationName;
|
||||
ABSL_CONST_INIT extern const char*
|
||||
kNearbySharingSchedulerUploadLocalDeviceCertificatesName;
|
||||
ABSL_CONST_INIT extern const char* kNearbySharingUsersName;
|
||||
ABSL_CONST_INIT extern const char* kNearbySharingIsAnalyticsEnabledName;
|
||||
|
||||
ABSL_CONST_INIT const proto::DeviceVisibility kDefaultVisibility =
|
||||
proto::DeviceVisibility::DEVICE_VISIBILITY_HIDDEN;
|
||||
ABSL_CONST_INIT const proto::DeviceVisibility kDefaultFallbackVisibility =
|
||||
|
||||
@@ -33,11 +33,11 @@ cc_library(
|
||||
"//internal/platform:types",
|
||||
"//internal/platform/implementation:account_manager",
|
||||
"//internal/platform/implementation:types",
|
||||
"//sharing/common",
|
||||
"//sharing/common:enum",
|
||||
"//sharing/internal/api:platform",
|
||||
"//sharing/internal/base:utf_utils",
|
||||
"//sharing/internal/public:logging",
|
||||
"//sharing/internal/public:pref_names",
|
||||
"//sharing/proto:share_cc_proto",
|
||||
"@com_google_absl//absl/memory",
|
||||
"@com_google_absl//absl/strings",
|
||||
|
||||
@@ -28,9 +28,9 @@
|
||||
#include "internal/platform/implementation/account_manager.h"
|
||||
#include "internal/platform/implementation/device_info.h"
|
||||
#include "sharing/common/nearby_share_enums.h"
|
||||
#include "sharing/common/nearby_share_prefs.h"
|
||||
#include "sharing/internal/api/preference_manager.h"
|
||||
#include "sharing/internal/base/utf_string_conversions.h"
|
||||
#include "sharing/internal/public/pref_names.h"
|
||||
#include "sharing/local_device_data/nearby_share_local_device_data_manager.h"
|
||||
#include "sharing/proto/device_rpc.pb.h"
|
||||
#include "sharing/proto/field_mask.pb.h"
|
||||
@@ -100,8 +100,8 @@ NearbyShareLocalDeviceDataManagerImpl::
|
||||
~NearbyShareLocalDeviceDataManagerImpl() = default;
|
||||
|
||||
std::string NearbyShareLocalDeviceDataManagerImpl::GetDeviceName() const {
|
||||
std::string device_name = preference_manager_.GetString(
|
||||
prefs::kNearbySharingDeviceNameName, std::string());
|
||||
std::string device_name =
|
||||
preference_manager_.GetString(PrefNames::kDeviceName, std::string());
|
||||
return device_name.empty() ? GetDefaultDeviceName() : device_name;
|
||||
}
|
||||
|
||||
@@ -126,7 +126,7 @@ DeviceNameValidationResult NearbyShareLocalDeviceDataManagerImpl::SetDeviceName(
|
||||
auto error = ValidateDeviceName(name);
|
||||
if (error != DeviceNameValidationResult::kValid) return error;
|
||||
|
||||
preference_manager_.SetString(prefs::kNearbySharingDeviceNameName, name);
|
||||
preference_manager_.SetString(PrefNames::kDeviceName, name);
|
||||
|
||||
NotifyLocalDeviceDataChanged(/*did_device_name_change=*/true,
|
||||
/*did_full_name_change=*/false,
|
||||
|
||||
@@ -73,6 +73,7 @@
|
||||
#include "sharing/internal/api/mock_app_info.h"
|
||||
#include "sharing/internal/api/mock_sharing_platform.h"
|
||||
#include "sharing/internal/api/preference_manager.h"
|
||||
#include "sharing/internal/public/pref_names.h"
|
||||
#include "sharing/internal/test/fake_bluetooth_adapter.h"
|
||||
#include "sharing/internal/test/fake_connectivity_manager.h"
|
||||
#include "sharing/internal/test/fake_context.h"
|
||||
@@ -1820,8 +1821,7 @@ TEST_F(NearbySharingServiceImplTest,
|
||||
SetLanConnected(true);
|
||||
SetVisibility(DeviceVisibility::DEVICE_VISIBILITY_ALL_CONTACTS);
|
||||
preference_manager().SetInteger(
|
||||
prefs::kNearbySharingDataUsageName,
|
||||
static_cast<int>(DataUsage::OFFLINE_DATA_USAGE));
|
||||
PrefNames::kDataUsage, static_cast<int>(DataUsage::OFFLINE_DATA_USAGE));
|
||||
FlushTesting();
|
||||
MockTransferUpdateCallback callback;
|
||||
NearbySharingService::StatusCodes result = RegisterReceiveSurface(
|
||||
@@ -1833,8 +1833,7 @@ TEST_F(NearbySharingServiceImplTest,
|
||||
fake_nearby_connections_manager_->advertising_data_usage());
|
||||
|
||||
preference_manager().SetInteger(
|
||||
prefs::kNearbySharingDataUsageName,
|
||||
static_cast<int>(DataUsage::ONLINE_DATA_USAGE));
|
||||
PrefNames::kDataUsage, static_cast<int>(DataUsage::ONLINE_DATA_USAGE));
|
||||
FlushTesting();
|
||||
EXPECT_TRUE(fake_nearby_connections_manager_->IsAdvertising());
|
||||
EXPECT_EQ(DataUsage::ONLINE_DATA_USAGE,
|
||||
@@ -1847,7 +1846,7 @@ TEST_F(
|
||||
TestObserver observer(service_.get());
|
||||
SetLanConnected(true);
|
||||
preference_manager().SetInteger(
|
||||
prefs::kNearbySharingBackgroundVisibilityName,
|
||||
PrefNames::kVisibility,
|
||||
static_cast<int>(DeviceVisibility::DEVICE_VISIBILITY_ALL_CONTACTS));
|
||||
FlushTesting();
|
||||
|
||||
@@ -1893,7 +1892,7 @@ TEST_F(NearbySharingServiceImplTest,
|
||||
RegisterReceiveSurfaceWithVendorId_StartAdvertisingVendorId) {
|
||||
SetLanConnected(true);
|
||||
preference_manager().SetInteger(
|
||||
prefs::kNearbySharingBackgroundVisibilityName,
|
||||
PrefNames::kVisibility,
|
||||
static_cast<int>(DeviceVisibility::DEVICE_VISIBILITY_EVERYONE));
|
||||
FlushTesting();
|
||||
|
||||
@@ -1918,7 +1917,7 @@ TEST_F(NearbySharingServiceImplTest,
|
||||
RegisterReceiveSurfaceWithVendorId_DoesNotAdvertiseInContacts) {
|
||||
SetLanConnected(true);
|
||||
preference_manager().SetInteger(
|
||||
prefs::kNearbySharingBackgroundVisibilityName,
|
||||
PrefNames::kVisibility,
|
||||
static_cast<int>(DeviceVisibility::DEVICE_VISIBILITY_ALL_CONTACTS));
|
||||
FlushTesting();
|
||||
|
||||
@@ -1943,7 +1942,7 @@ TEST_F(NearbySharingServiceImplTest,
|
||||
RegisterReceiveSurfaceWithDifferentVendorIdIsBlocked) {
|
||||
SetLanConnected(true);
|
||||
preference_manager().SetInteger(
|
||||
prefs::kNearbySharingBackgroundVisibilityName,
|
||||
PrefNames::kVisibility,
|
||||
static_cast<int>(DeviceVisibility::DEVICE_VISIBILITY_ALL_CONTACTS));
|
||||
FlushTesting();
|
||||
|
||||
@@ -1969,7 +1968,7 @@ TEST_F(NearbySharingServiceImplTest,
|
||||
RegisterReceiveSurfaceWithVendorId_OkWithBgNoVendorId) {
|
||||
SetLanConnected(true);
|
||||
preference_manager().SetInteger(
|
||||
prefs::kNearbySharingBackgroundVisibilityName,
|
||||
PrefNames::kVisibility,
|
||||
static_cast<int>(DeviceVisibility::DEVICE_VISIBILITY_EVERYONE));
|
||||
FlushTesting();
|
||||
|
||||
@@ -2077,7 +2076,7 @@ TEST_F(NearbySharingServiceImplTest,
|
||||
ForegroundReceiveSurfaceNoOneVisibilityIsAdvertising) {
|
||||
SetLanConnected(true);
|
||||
preference_manager().SetInteger(
|
||||
prefs::kNearbySharingBackgroundVisibilityName,
|
||||
PrefNames::kVisibility,
|
||||
static_cast<int>(DeviceVisibility::DEVICE_VISIBILITY_SELF_SHARE));
|
||||
FlushTesting();
|
||||
MockTransferUpdateCallback callback;
|
||||
@@ -2093,7 +2092,7 @@ TEST_F(NearbySharingServiceImplTest,
|
||||
SetLanConnected(true);
|
||||
SetVisibility(DeviceVisibility::DEVICE_VISIBILITY_SELF_SHARE);
|
||||
preference_manager().SetInteger(
|
||||
prefs::kNearbySharingBackgroundVisibilityName,
|
||||
PrefNames::kVisibility,
|
||||
static_cast<int>(DeviceVisibility::DEVICE_VISIBILITY_UNSPECIFIED));
|
||||
FlushTesting();
|
||||
MockTransferUpdateCallback callback;
|
||||
@@ -2118,7 +2117,7 @@ TEST_F(NearbySharingServiceImplTest,
|
||||
EXPECT_TRUE(fake_nearby_connections_manager_->IsAdvertising());
|
||||
|
||||
preference_manager().SetInteger(
|
||||
prefs::kNearbySharingBackgroundVisibilityName,
|
||||
PrefNames::kVisibility,
|
||||
static_cast<int>(DeviceVisibility::DEVICE_VISIBILITY_HIDDEN));
|
||||
FlushTesting();
|
||||
EXPECT_FALSE(fake_nearby_connections_manager_->IsAdvertising());
|
||||
@@ -2189,7 +2188,7 @@ TEST_F(NearbySharingServiceImplTest,
|
||||
ForegroundReceiveSurfaceSelectedContactsVisibilityIsAdvertising) {
|
||||
SetLanConnected(true);
|
||||
preference_manager().SetInteger(
|
||||
prefs::kNearbySharingBackgroundVisibilityName,
|
||||
PrefNames::kVisibility,
|
||||
static_cast<int>(DeviceVisibility::DEVICE_VISIBILITY_SELECTED_CONTACTS));
|
||||
FlushTesting();
|
||||
MockTransferUpdateCallback callback;
|
||||
@@ -2204,7 +2203,7 @@ TEST_F(NearbySharingServiceImplTest,
|
||||
BackgroundReceiveSurfaceSelectedContactsVisibilityIsAdvertising) {
|
||||
SetLanConnected(true);
|
||||
preference_manager().SetInteger(
|
||||
prefs::kNearbySharingBackgroundVisibilityName,
|
||||
PrefNames::kVisibility,
|
||||
static_cast<int>(DeviceVisibility::DEVICE_VISIBILITY_SELECTED_CONTACTS));
|
||||
FlushTesting();
|
||||
MockTransferUpdateCallback callback;
|
||||
@@ -2219,7 +2218,7 @@ TEST_F(NearbySharingServiceImplTest,
|
||||
ForegroundReceiveSurfaceAllContactsVisibilityIsAdvertising) {
|
||||
SetLanConnected(true);
|
||||
preference_manager().SetInteger(
|
||||
prefs::kNearbySharingBackgroundVisibilityName,
|
||||
PrefNames::kVisibility,
|
||||
static_cast<int>(DeviceVisibility::DEVICE_VISIBILITY_ALL_CONTACTS));
|
||||
FlushTesting();
|
||||
MockTransferUpdateCallback callback;
|
||||
@@ -2234,7 +2233,7 @@ TEST_F(NearbySharingServiceImplTest,
|
||||
BackgroundReceiveSurfaceAllContactsVisibilityNotAdvertising) {
|
||||
SetLanConnected(true);
|
||||
preference_manager().SetInteger(
|
||||
prefs::kNearbySharingBackgroundVisibilityName,
|
||||
PrefNames::kVisibility,
|
||||
static_cast<int>(DeviceVisibility::DEVICE_VISIBILITY_ALL_CONTACTS));
|
||||
FlushTesting();
|
||||
MockTransferUpdateCallback callback;
|
||||
@@ -2499,7 +2498,7 @@ TEST_F(NearbySharingServiceImplTest,
|
||||
TEST_F(NearbySharingServiceImplTest, IncomingConnectionOutOfStorage) {
|
||||
SetDiskSpace(kFreeDiskSpace);
|
||||
preference_manager().SetString(
|
||||
prefs::kNearbySharingCustomSavePath,
|
||||
PrefNames::kCustomSavePath,
|
||||
fake_device_info_.GetDownloadPath().ToString());
|
||||
fake_nearby_connections_manager_->SetRawAuthenticationToken(kEndpointId,
|
||||
GetToken());
|
||||
@@ -4453,7 +4452,7 @@ TEST_F(NearbySharingServiceImplTest,
|
||||
RegisterSendSurfaceWithDifferentVendorIdIsBlocked) {
|
||||
SetLanConnected(true);
|
||||
preference_manager().SetInteger(
|
||||
prefs::kNearbySharingBackgroundVisibilityName,
|
||||
PrefNames::kVisibility,
|
||||
static_cast<int>(DeviceVisibility::DEVICE_VISIBILITY_ALL_CONTACTS));
|
||||
FlushTesting();
|
||||
|
||||
@@ -4641,7 +4640,7 @@ TEST_F(NearbySharingServiceImplTest, LoginAndLogoutShouldResetSettings) {
|
||||
service_->GetSettings()->SetIsAnalyticsEnabled(true);
|
||||
|
||||
std::string device_id =
|
||||
preference_manager_.GetString(prefs::kNearbySharingDeviceIdName, "");
|
||||
preference_manager_.GetString(PrefNames::kDeviceId, "");
|
||||
EXPECT_TRUE(device_id.empty());
|
||||
|
||||
// Create account.
|
||||
@@ -4660,7 +4659,7 @@ TEST_F(NearbySharingServiceImplTest, LoginAndLogoutShouldResetSettings) {
|
||||
EXPECT_EQ(service_->GetAccountManager()->GetCurrentAccount()->id,
|
||||
kTestAccountId);
|
||||
device_id =
|
||||
preference_manager_.GetString(prefs::kNearbySharingDeviceIdName, "");
|
||||
preference_manager_.GetString(PrefNames::kDeviceId, "");
|
||||
EXPECT_FALSE(device_id.empty());
|
||||
EXPECT_EQ(device_id.size(), 10u);
|
||||
for (const char c : device_id) EXPECT_TRUE(std::isalnum(c));
|
||||
@@ -4678,7 +4677,7 @@ TEST_F(NearbySharingServiceImplTest, LoginAndLogoutShouldResetSettings) {
|
||||
EXPECT_FALSE(service_->GetAccountManager()->GetCurrentAccount().has_value());
|
||||
EXPECT_TRUE(sharing_service_task_runner_->SyncWithTimeout(kTaskWaitTimeout));
|
||||
device_id =
|
||||
preference_manager_.GetString(prefs::kNearbySharingDeviceIdName, "");
|
||||
preference_manager_.GetString(PrefNames::kDeviceId, "");
|
||||
EXPECT_TRUE(device_id.empty());
|
||||
}
|
||||
|
||||
|
||||
@@ -34,6 +34,7 @@
|
||||
#include "sharing/internal/api/preference_manager.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/enums.pb.h"
|
||||
#include "sharing/thread_timer.h"
|
||||
@@ -107,7 +108,7 @@ FastInitiationNotificationState
|
||||
NearbyShareSettings::GetFastInitiationNotificationState() const {
|
||||
return static_cast<FastInitiationNotificationState>(
|
||||
preference_manager_.GetInteger(
|
||||
prefs::kNearbySharingFastInitiationNotificationStateName,
|
||||
PrefNames::kFastInitiationNotificationState,
|
||||
static_cast<int>(
|
||||
FastInitiationNotificationState::ENABLED_FAST_INIT)));
|
||||
}
|
||||
@@ -133,7 +134,7 @@ std::string NearbyShareSettings::GetDeviceName() const {
|
||||
|
||||
DataUsage NearbyShareSettings::GetDataUsage() const {
|
||||
return static_cast<DataUsage>(
|
||||
preference_manager_.GetInteger(prefs::kNearbySharingDataUsageName, 0));
|
||||
preference_manager_.GetInteger(PrefNames::kDataUsage, 0));
|
||||
}
|
||||
|
||||
void NearbyShareSettings::StartVisibilityTimer(
|
||||
@@ -156,9 +157,9 @@ void NearbyShareSettings::StartVisibilityTimer(
|
||||
|
||||
void NearbyShareSettings::RestoreFallbackVisibility() {
|
||||
int64_t expiration_seconds = preference_manager_.GetInteger(
|
||||
prefs::kNearbySharingBackgroundVisibilityExpirationSeconds, 0);
|
||||
PrefNames::kVisibilityExpirationSeconds, 0);
|
||||
int64_t fallback_visibility = preference_manager_.GetInteger(
|
||||
prefs::kNearbySharingBackgroundFallbackVisibilityName,
|
||||
PrefNames::kFallbackVisibility,
|
||||
static_cast<int>(prefs::kDefaultFallbackVisibility));
|
||||
fallback_visibility_ = static_cast<DeviceVisibility>(fallback_visibility);
|
||||
|
||||
@@ -182,8 +183,7 @@ void NearbyShareSettings::RestoreFallbackVisibility() {
|
||||
|
||||
std::string NearbyShareSettings::GetCustomSavePath() const {
|
||||
return preference_manager_.GetString(
|
||||
prefs::kNearbySharingCustomSavePath,
|
||||
device_info_.GetDownloadPath().ToString());
|
||||
PrefNames::kCustomSavePath, device_info_.GetDownloadPath().ToString());
|
||||
}
|
||||
|
||||
bool NearbyShareSettings::IsDisabledByPolicy() const { return false; }
|
||||
@@ -204,9 +204,8 @@ void NearbyShareSettings::SetFastInitiationNotificationState(
|
||||
GetNotificationStatus(state));
|
||||
}
|
||||
|
||||
preference_manager_.SetInteger(
|
||||
prefs::kNearbySharingFastInitiationNotificationStateName,
|
||||
static_cast<int>(state));
|
||||
preference_manager_.SetInteger(PrefNames::kFastInitiationNotificationState,
|
||||
static_cast<int>(state));
|
||||
}
|
||||
|
||||
void NearbyShareSettings::SetDeviceName(
|
||||
@@ -222,15 +221,14 @@ void NearbyShareSettings::SetDataUsage(DataUsage data_usage) {
|
||||
if (analytics_recorder_ != nullptr) {
|
||||
analytics_recorder_->NewSetDataUsage(GetDataUsage(), data_usage);
|
||||
}
|
||||
preference_manager_.SetInteger(prefs::kNearbySharingDataUsageName,
|
||||
preference_manager_.SetInteger(PrefNames::kDataUsage,
|
||||
static_cast<int>(data_usage));
|
||||
}
|
||||
|
||||
DeviceVisibility NearbyShareSettings::GetVisibility() const {
|
||||
DeviceVisibility visibility =
|
||||
static_cast<DeviceVisibility>(preference_manager_.GetInteger(
|
||||
prefs::kNearbySharingBackgroundVisibilityName,
|
||||
static_cast<int>(prefs::kDefaultVisibility)));
|
||||
PrefNames::kVisibility, static_cast<int>(prefs::kDefaultVisibility)));
|
||||
if (visibility == DeviceVisibility::DEVICE_VISIBILITY_SELECTED_CONTACTS) {
|
||||
// Set the visibility to self share if it's only visible to selected
|
||||
// contacts, as part of QuickShare rebrand work.
|
||||
@@ -272,17 +270,16 @@ void NearbyShareSettings::SetVisibility(DeviceVisibility visibility,
|
||||
VLOG(1) << __func__ << ": temporary visibility timer starts.";
|
||||
absl::Time fallback_visibility_timestamp = now + expiration;
|
||||
preference_manager_.SetInteger(
|
||||
prefs::kNearbySharingBackgroundVisibilityExpirationSeconds,
|
||||
PrefNames::kVisibilityExpirationSeconds,
|
||||
absl::ToUnixSeconds(fallback_visibility_timestamp));
|
||||
StartVisibilityTimer(expiration);
|
||||
} else {
|
||||
preference_manager_.SetInteger(
|
||||
prefs::kNearbySharingBackgroundVisibilityExpirationSeconds, 0);
|
||||
preference_manager_.SetInteger(PrefNames::kVisibilityExpirationSeconds, 0);
|
||||
}
|
||||
|
||||
last_visibility_timestamp_ = now;
|
||||
last_visibility_ = last_visibility;
|
||||
preference_manager_.SetInteger(prefs::kNearbySharingBackgroundVisibilityName,
|
||||
preference_manager_.SetInteger(PrefNames::kVisibility,
|
||||
static_cast<int>(visibility));
|
||||
}
|
||||
|
||||
@@ -301,7 +298,7 @@ NearbyShareSettings::GetRawFallbackVisibility() const {
|
||||
return {
|
||||
.visibility = fallback_visibility_,
|
||||
.fallback_time = absl::FromUnixSeconds(preference_manager_.GetInteger(
|
||||
prefs::kNearbySharingBackgroundVisibilityExpirationSeconds, 0))
|
||||
PrefNames::kVisibilityExpirationSeconds, 0))
|
||||
};
|
||||
}
|
||||
|
||||
@@ -332,29 +329,28 @@ void NearbyShareSettings::SetFallbackVisibility(DeviceVisibility visibility) {
|
||||
}
|
||||
|
||||
fallback_visibility_ = visibility;
|
||||
preference_manager_.SetInteger(
|
||||
prefs::kNearbySharingBackgroundFallbackVisibilityName,
|
||||
static_cast<int>(visibility));
|
||||
preference_manager_.SetInteger(PrefNames::kFallbackVisibility,
|
||||
static_cast<int>(visibility));
|
||||
}
|
||||
|
||||
void NearbyShareSettings::SetCustomSavePathAsync(
|
||||
absl::string_view save_path, const std::function<void()>& callback) {
|
||||
absl::MutexLock lock(mutex_);
|
||||
preference_manager_.SetString(prefs::kNearbySharingCustomSavePath, save_path);
|
||||
preference_manager_.SetString(PrefNames::kCustomSavePath, save_path);
|
||||
callback();
|
||||
}
|
||||
|
||||
void NearbyShareSettings::OnPreferenceChanged(absl::string_view key) {
|
||||
if (key == prefs::kNearbySharingFastInitiationNotificationStateName) {
|
||||
if (key == PrefNames::kFastInitiationNotificationState) {
|
||||
NotifyAllObservers(key, Observer::Data(static_cast<int64_t>(
|
||||
GetFastInitiationNotificationState())));
|
||||
} else if (key == prefs::kNearbySharingBackgroundVisibilityName) {
|
||||
} else if (key == PrefNames::kVisibility) {
|
||||
NotifyAllObservers(key,
|
||||
Observer::Data(static_cast<int64_t>(GetVisibility())));
|
||||
} else if (key == prefs::kNearbySharingDataUsageName) {
|
||||
} else if (key == PrefNames::kDataUsage) {
|
||||
NotifyAllObservers(key,
|
||||
Observer::Data(static_cast<int64_t>(GetDataUsage())));
|
||||
} else if (key == prefs::kNearbySharingCustomSavePath) {
|
||||
} else if (key == PrefNames::kCustomSavePath) {
|
||||
NotifyAllObservers(key, Observer::Data(GetCustomSavePath()));
|
||||
} else {
|
||||
// Not a monitored key.
|
||||
@@ -368,8 +364,7 @@ void NearbyShareSettings::OnLocalDeviceDataChanged(bool did_device_name_change,
|
||||
if (!did_device_name_change) return;
|
||||
|
||||
std::string device_name = GetDeviceName();
|
||||
NotifyAllObservers(prefs::kNearbySharingDeviceNameName,
|
||||
Observer::Data(device_name));
|
||||
NotifyAllObservers(PrefNames::kDeviceName, Observer::Data(device_name));
|
||||
}
|
||||
|
||||
void NearbyShareSettings::NotifyAllObservers(absl::string_view key,
|
||||
@@ -380,12 +375,11 @@ void NearbyShareSettings::NotifyAllObservers(absl::string_view key,
|
||||
}
|
||||
|
||||
bool NearbyShareSettings::GetIsAnalyticsEnabled() const {
|
||||
return preference_manager_.GetBoolean(
|
||||
prefs::kNearbySharingIsAnalyticsEnabledName, true);
|
||||
return preference_manager_.GetBoolean(PrefNames::kIsAnalyticsEnabled, true);
|
||||
}
|
||||
|
||||
void NearbyShareSettings::SetIsAnalyticsEnabled(bool is_analytics_enabled) {
|
||||
preference_manager_.SetBoolean(prefs::kNearbySharingIsAnalyticsEnabledName,
|
||||
preference_manager_.SetBoolean(PrefNames::kIsAnalyticsEnabled,
|
||||
is_analytics_enabled);
|
||||
}
|
||||
|
||||
|
||||
@@ -31,6 +31,7 @@
|
||||
#include "internal/test/fake_task_runner.h"
|
||||
#include "sharing/common/nearby_share_enums.h"
|
||||
#include "sharing/common/nearby_share_prefs.h"
|
||||
#include "sharing/internal/public/pref_names.h"
|
||||
#include "sharing/internal/test/fake_context.h"
|
||||
#include "sharing/internal/test/fake_preference_manager.h"
|
||||
#include "sharing/local_device_data/fake_nearby_share_local_device_data_manager.h"
|
||||
@@ -49,16 +50,16 @@ class FakeNearbyShareSettingsObserver : public NearbyShareSettings::Observer {
|
||||
public:
|
||||
void OnSettingChanged(absl::string_view key, const Data& data) override {
|
||||
absl::MutexLock lock(mutex_);
|
||||
if (key == prefs::kNearbySharingFastInitiationNotificationStateName) {
|
||||
if (key == PrefNames::kFastInitiationNotificationState) {
|
||||
fast_initiation_notification_state_ =
|
||||
static_cast<FastInitiationNotificationState>(data.value.as_int64);
|
||||
} else if (key == prefs::kNearbySharingDataUsageName) {
|
||||
} else if (key == PrefNames::kDataUsage) {
|
||||
data_usage_ = static_cast<DataUsage>(data.value.as_int64);
|
||||
} else if (key == prefs::kNearbySharingCustomSavePath) {
|
||||
} else if (key == PrefNames::kCustomSavePath) {
|
||||
custom_save_path_ = data.value.as_string;
|
||||
} else if (key == prefs::kNearbySharingBackgroundVisibilityName) {
|
||||
} else if (key == PrefNames::kVisibility) {
|
||||
visibility_ = static_cast<DeviceVisibility>(data.value.as_int64);
|
||||
} else if (key == prefs::kNearbySharingDeviceNameName) {
|
||||
} else if (key == PrefNames::kDeviceName) {
|
||||
device_name_ = data.value.as_string;
|
||||
}
|
||||
}
|
||||
@@ -132,13 +133,12 @@ class NearbyShareSettingsTest : public ::testing::Test {
|
||||
NearbyShareSettings* settings() { return nearby_share_settings_.get(); }
|
||||
|
||||
void SetVisibilityExpirationPreference(int expiration) {
|
||||
preference_manager_.SetInteger(
|
||||
prefs::kNearbySharingBackgroundVisibilityExpirationSeconds, expiration);
|
||||
preference_manager_.SetInteger(PrefNames::kVisibilityExpirationSeconds,
|
||||
expiration);
|
||||
}
|
||||
|
||||
void SetCustomSavePath(absl::string_view path) {
|
||||
preference_manager_.SetString(
|
||||
prefs::kNearbySharingCustomSavePath, path);
|
||||
preference_manager_.SetString(PrefNames::kCustomSavePath, path);
|
||||
}
|
||||
|
||||
// Waits for running tasks to complete.
|
||||
@@ -332,9 +332,8 @@ TEST_F(NearbyShareSettingsTest,
|
||||
settings()->SetVisibility(DeviceVisibility::DEVICE_VISIBILITY_EVERYONE);
|
||||
// Verify that the saved fallback visibility is intact, since we can go back
|
||||
// to temporary.
|
||||
EXPECT_EQ(preference_manager_.GetInteger(
|
||||
prefs::kNearbySharingBackgroundFallbackVisibilityName,
|
||||
prefs::kDefaultFallbackVisibility),
|
||||
EXPECT_EQ(preference_manager_.GetInteger(PrefNames::kFallbackVisibility,
|
||||
prefs::kDefaultFallbackVisibility),
|
||||
static_cast<int>(DeviceVisibility::DEVICE_VISIBILITY_SELF_SHARE));
|
||||
// Verify that the fallback visibility is unspecified.
|
||||
NearbyShareSettings::FallbackVisibilityInfo fallback_visibility =
|
||||
@@ -396,15 +395,15 @@ TEST(NearbyShareVisibilityTest, RestoresFallbackVisibility_ExpiredTimer) {
|
||||
kDefaultDeviceName);
|
||||
// Set everyone mode temporarily.
|
||||
preference_manager.SetInteger(
|
||||
prefs::kNearbySharingBackgroundVisibilityName,
|
||||
PrefNames::kVisibility,
|
||||
static_cast<int>(DeviceVisibility::DEVICE_VISIBILITY_EVERYONE));
|
||||
// Set expiration to 10 seconds ago.
|
||||
preference_manager.SetInteger(
|
||||
prefs::kNearbySharingBackgroundVisibilityExpirationSeconds,
|
||||
PrefNames::kVisibilityExpirationSeconds,
|
||||
absl::ToUnixSeconds(context.GetClock()->Now() - absl::Seconds(10)));
|
||||
// Set fallback visibility to self share.
|
||||
preference_manager.SetInteger(
|
||||
prefs::kNearbySharingBackgroundFallbackVisibilityName,
|
||||
PrefNames::kFallbackVisibility,
|
||||
static_cast<int>(DeviceVisibility::DEVICE_VISIBILITY_SELF_SHARE));
|
||||
// Create a Nearby Share settings instance.
|
||||
NearbyShareSettings settings(&context, context.GetClock(), fake_device_info,
|
||||
@@ -424,15 +423,15 @@ TEST(NearbyShareVisibilityTest, RestoresFallbackVisibility_FutureTimer) {
|
||||
kDefaultDeviceName);
|
||||
// Set everyone mode temporarily.
|
||||
preference_manager.SetInteger(
|
||||
prefs::kNearbySharingBackgroundVisibilityName,
|
||||
PrefNames::kVisibility,
|
||||
static_cast<int>(DeviceVisibility::DEVICE_VISIBILITY_EVERYONE));
|
||||
// Set expiration to 10 seconds in the future.
|
||||
preference_manager.SetInteger(
|
||||
prefs::kNearbySharingBackgroundVisibilityExpirationSeconds,
|
||||
PrefNames::kVisibilityExpirationSeconds,
|
||||
absl::ToUnixSeconds(context.GetClock()->Now() + absl::Seconds(10)));
|
||||
// Set fallback visibility to self share.
|
||||
preference_manager.SetInteger(
|
||||
prefs::kNearbySharingBackgroundFallbackVisibilityName,
|
||||
PrefNames::kFallbackVisibility,
|
||||
static_cast<int>(DeviceVisibility::DEVICE_VISIBILITY_SELF_SHARE));
|
||||
// Create a Nearby Share settings instance.
|
||||
NearbyShareSettings settings(&context, context.GetClock(), fake_device_info,
|
||||
|
||||
Reference in New Issue
Block a user