Add preference value to track is advanced protection is enabled.

PiperOrigin-RevId: 808651443
This commit is contained in:
Francis Tsui
2025-09-18 10:57:39 -07:00
committed by Copybara-Service
parent 8ded7ccfca
commit d4503955fe
7 changed files with 157 additions and 164 deletions
+1 -2
View File
@@ -29,10 +29,9 @@ cc_library(
visibility = ["//visibility:public"],
deps = [
"//sharing/internal/api:platform",
"//sharing/internal/public:pref_names",
"//sharing/proto:enums_cc_proto",
"@com_google_absl//absl/base:core_headers",
"@com_google_absl//absl/status",
"@com_google_absl//absl/time",
],
)
+59 -95
View File
@@ -15,17 +15,17 @@
#include "sharing/common/nearby_share_prefs.h"
#include <string>
#include <vector>
#include "absl/base/attributes.h"
#include "absl/time/clock.h"
#include "sharing/internal/api/preference_manager.h"
#include "sharing/internal/public/pref_names.h"
#include "sharing/proto/enums.pb.h"
namespace nearby {
namespace sharing {
namespace prefs {
namespace {
using ::nearby::sharing::PrefNames;
using ::nearby::sharing::api::PreferenceManager;
using DataUsage = ::nearby::sharing::proto::DataUsage;
@@ -33,55 +33,42 @@ using FastInitiationNotificationState =
::nearby::sharing::proto::FastInitiationNotificationState;
} // namespace
ABSL_CONST_INIT const char kNearbySharingAllowedContactsName[] =
"nearby_sharing.allowed_contacts";
ABSL_CONST_INIT const char kNearbySharingBackgroundVisibilityName[] =
"nearby_sharing.background_visibility";
ABSL_CONST_INIT const char kNearbySharingBackgroundFallbackVisibilityName[] =
"nearby_sharing.background_fallback_visibility";
ABSL_CONST_INIT const char
kNearbySharingBackgroundVisibilityExpirationSeconds[] =
"nearby_sharing.background_visibility_expiration_seconds";
ABSL_CONST_INIT const char kNearbySharingContactUploadHashName[] =
"nearby_sharing.contact_upload_hash";
ABSL_CONST_INIT const char kNearbySharingContactUploadTimeName[] =
"nearby_sharing.contact_upload_time";
ABSL_CONST_INIT const char kNearbySharingCustomSavePath[] =
"nearby_sharing.custom_save_path";
ABSL_CONST_INIT const char kNearbySharingDataUsageName[] =
"nearby_sharing.data_usage";
ABSL_CONST_INIT const char kNearbySharingDeviceIdName[] =
"nearby_sharing.device_id";
ABSL_CONST_INIT const char kNearbySharingDeviceNameName[] =
"nearby_sharing.device_name";
ABSL_CONST_INIT const char kNearbySharingFastInitiationNotificationStateName[] =
"nearby_sharing.fast_initiation_notification_state";
ABSL_CONST_INIT const char kNearbySharingPublicCertificateExpirationDictName[] =
"nearbyshare.public_certificate_expiration_dict";
ABSL_CONST_INIT const char kNearbySharingPrivateCertificateListName[] =
"nearbyshare.private_certificate_list";
ABSL_CONST_INIT const char
kNearbySharingSchedulerContactDownloadAndUploadName[] =
"nearby_sharing.scheduler.contact_download_and_upload";
ABSL_CONST_INIT const char
kNearbySharingSchedulerDownloadPublicCertificatesName[] =
"nearby_sharing.scheduler.download_public_certificates";
ABSL_CONST_INIT const char
kNearbySharingSchedulerPrivateCertificateExpirationName[] =
"nearby_sharing.scheduler.private_certificate_expiration";
ABSL_CONST_INIT const char
kNearbySharingSchedulerPublicCertificateExpirationName[] =
"nearby_sharing.scheduler.public_certificate_expiration";
ABSL_CONST_INIT const char kNearbySharingSchedulerUploadDeviceNameName[] =
"nearby_sharing.scheduler.upload_device_name";
ABSL_CONST_INIT const char
kNearbySharingSchedulerUploadLocalDeviceCertificatesName[] =
"nearby_sharing.scheduler.upload_local_device_certificates";
ABSL_CONST_INIT const char kNearbySharingUsersName[] = "nearby_sharing.users";
ABSL_CONST_INIT const char kNearbySharingIsAnalyticsEnabledName[] =
"nearby_sharing.is_analytics_enabled";
ABSL_CONST_INIT const char kNearbySharingIsAllContactsEnabledName[] =
"nearby_sharing.is_all_contacts_enabled";
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) {
@@ -91,64 +78,41 @@ void RegisterNearbySharingPrefs(PreferenceManager& preference_manager,
// During logging out, we reset all settings and set these settings to new
// values. To avoid setting them twice, we skip them here if
// skip_persistent_ones is set to true.
preference_manager.SetString(kNearbySharingCustomSavePath, std::string());
preference_manager.SetInteger(kNearbySharingBackgroundVisibilityName,
preference_manager.SetString(PrefNames::kCustomSavePath, std::string());
preference_manager.SetInteger(PrefNames::kVisibility,
static_cast<int>(kDefaultVisibility));
preference_manager.SetInteger(
kNearbySharingBackgroundFallbackVisibilityName,
static_cast<int>(kDefaultFallbackVisibility));
preference_manager.SetBoolean(kNearbySharingIsAnalyticsEnabledName, false);
preference_manager.SetInteger(PrefNames::kFallbackVisibility,
static_cast<int>(kDefaultFallbackVisibility));
preference_manager.SetBoolean(PrefNames::kIsAnalyticsEnabled, false);
}
preference_manager.SetInteger(
kNearbySharingFastInitiationNotificationStateName,
PrefNames::kFastInitiationNotificationState,
/*value=*/static_cast<int>(
FastInitiationNotificationState::ENABLED_FAST_INIT));
preference_manager.SetInteger(
kNearbySharingDataUsageName,
static_cast<int>(DataUsage::WIFI_ONLY_DATA_USAGE));
PrefNames::kDataUsage, static_cast<int>(DataUsage::WIFI_ONLY_DATA_USAGE));
preference_manager.SetString(kNearbySharingContactUploadHashName,
std::string());
preference_manager.SetString(PrefNames::kDeviceId, std::string());
preference_manager.SetString(kNearbySharingDeviceIdName, std::string());
preference_manager.SetString(PrefNames::kDeviceName, std::string());
preference_manager.SetString(kNearbySharingDeviceNameName, std::string());
preference_manager.SetStringArray(kNearbySharingAllowedContactsName,
std::vector<std::string>());
preference_manager.Remove(kNearbySharingPublicCertificateExpirationDictName);
preference_manager.Remove(kNearbySharingPrivateCertificateListName);
preference_manager.Remove(
kNearbySharingSchedulerContactDownloadAndUploadName);
preference_manager.Remove(
kNearbySharingSchedulerDownloadPublicCertificatesName);
preference_manager.Remove(
kNearbySharingSchedulerPrivateCertificateExpirationName);
preference_manager.Remove(
kNearbySharingSchedulerPublicCertificateExpirationName);
preference_manager.Remove(kNearbySharingSchedulerUploadDeviceNameName);
preference_manager.Remove(
kNearbySharingSchedulerUploadLocalDeviceCertificatesName);
preference_manager.Remove(kNearbySharingUsersName);
preference_manager.SetBoolean(kNearbySharingIsAllContactsEnabledName, true);
preference_manager.Remove(PrefNames::kPublicCertificateExpirationDict);
preference_manager.Remove(PrefNames::kPrivateCertificateList);
preference_manager.Remove(PrefNames::kSchedulerDownloadPublicCertificates);
preference_manager.Remove(PrefNames::kSchedulerPrivateCertificateExpiration);
preference_manager.Remove(PrefNames::kSchedulerPublicCertificateExpiration);
preference_manager.Remove(PrefNames::kSchedulerUploadLocalDeviceCertificates);
preference_manager.Remove(PrefNames::kUsers);
preference_manager.SetBoolean(PrefNames::kAdvancedProtectionEnabled, false);
}
void ResetSchedulers(PreferenceManager& preference_manager) {
preference_manager.Remove(
kNearbySharingSchedulerContactDownloadAndUploadName);
preference_manager.Remove(
kNearbySharingSchedulerDownloadPublicCertificatesName);
preference_manager.Remove(
kNearbySharingSchedulerPrivateCertificateExpirationName);
preference_manager.Remove(
kNearbySharingSchedulerPublicCertificateExpirationName);
preference_manager.Remove(kNearbySharingSchedulerUploadDeviceNameName);
preference_manager.Remove(
kNearbySharingSchedulerUploadLocalDeviceCertificatesName);
preference_manager.Remove(PrefNames::kSchedulerDownloadPublicCertificates);
preference_manager.Remove(PrefNames::kSchedulerPrivateCertificateExpiration);
preference_manager.Remove(PrefNames::kSchedulerPublicCertificateExpiration);
preference_manager.Remove(PrefNames::kSchedulerUploadLocalDeviceCertificates);
}
} // namespace prefs
+26 -30
View File
@@ -23,36 +23,32 @@ namespace nearby {
namespace sharing {
namespace prefs {
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 kNearbySharingContactUploadHashName[];
ABSL_CONST_INIT extern const char kNearbySharingContactUploadTimeName[];
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
kNearbySharingSchedulerContactDownloadAndUploadName[];
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 kNearbySharingSchedulerUploadDeviceNameName[];
ABSL_CONST_INIT extern const char
kNearbySharingSchedulerUploadLocalDeviceCertificatesName[];
ABSL_CONST_INIT extern const char kNearbySharingUsersName[];
ABSL_CONST_INIT extern const char kNearbySharingIsAnalyticsEnabledName[];
ABSL_CONST_INIT extern const char kNearbySharingAutoAppStartEnabledName[];
// 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;
@@ -23,18 +23,15 @@
#include <vector>
#include "gtest/gtest.h"
#include "absl/container/flat_hash_map.h"
#include "absl/time/time.h"
#include "internal/platform/implementation/account_manager.h"
#include "internal/test/fake_account_manager.h"
#include "sharing/common/nearby_share_prefs.h"
#include "sharing/contacts/nearby_share_contact_manager.h"
#include "sharing/internal/api/fake_nearby_share_client.h"
#include "sharing/internal/test/fake_context.h"
#include "sharing/local_device_data/fake_nearby_share_local_device_data_manager.h"
#include "sharing/proto/contact_rpc.pb.h"
#include "sharing/proto/rpc_resources.pb.h"
#include "sharing/scheduling/fake_nearby_share_scheduler.h"
#include "sharing/scheduling/fake_nearby_share_scheduler_factory.h"
#include "sharing/scheduling/nearby_share_scheduler_factory.h"
@@ -47,9 +44,6 @@ constexpr char kTestDefaultDeviceName[] = "Josh's Chromebook";
constexpr char kTestProfileUserName[] = "test@google.com";
constexpr char kTestAccountId[] = "test_account_id";
// From nearby_share_contact_manager_impl.cc.
constexpr absl::Duration kContactDownloadPeriod = absl::Hours(12);
class NearbyShareContactManagerImplTest
: public ::testing::Test {
protected:
@@ -75,8 +69,6 @@ class NearbyShareContactManagerImplTest
manager_ = NearbyShareContactManagerImpl::Factory::Create(
&fake_context_, fake_account_manager_, &nearby_client_factory_);
VerifySchedulerInitialization();
}
void TearDown() override {
@@ -101,25 +93,6 @@ class NearbyShareContactManagerImplTest
return nearby_client_factory_.instances().back();
}
FakeNearbyShareScheduler* download_and_upload_scheduler() {
return scheduler_factory_.pref_name_to_periodic_instance()
.at(prefs::kNearbySharingSchedulerContactDownloadAndUploadName)
.fake_scheduler;
}
// Verify scheduler input parameters.
void VerifySchedulerInitialization() {
FakeNearbyShareSchedulerFactory::PeriodicInstance
download_and_upload_scheduler_instance =
scheduler_factory_.pref_name_to_periodic_instance().at(
prefs::kNearbySharingSchedulerContactDownloadAndUploadName);
EXPECT_TRUE(download_and_upload_scheduler_instance.fake_scheduler);
EXPECT_EQ(download_and_upload_scheduler_instance.request_period,
kContactDownloadPeriod);
EXPECT_TRUE(download_and_upload_scheduler_instance.retry_failures);
EXPECT_TRUE(download_and_upload_scheduler_instance.require_connectivity);
}
FakeAccountManager fake_account_manager_;
FakeContext fake_context_;
std::vector<ContactsDownloadedNotification>
+12
View File
@@ -17,6 +17,18 @@ load("@rules_cc//cc:cc_test.bzl", "cc_test")
licenses(["notice"])
cc_library(
name = "pref_names",
hdrs = [
"pref_names.h",
],
compatible_with = ["//buildenv/target:non_prod"],
visibility = ["//visibility:public"],
deps = [
"@com_google_absl//absl/strings",
],
)
cc_library(
name = "types",
hdrs = [
+59
View File
@@ -0,0 +1,59 @@
// Copyright 2025 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_SHARING_INTERNAL_PUBLIC_PREF_NAMES_H_
#define THIRD_PARTY_NEARBY_SHARING_INTERNAL_PUBLIC_PREF_NAMES_H_
#include "absl/strings/string_view.h"
namespace nearby::sharing {
// A class container for Nearby Share prefs names.
class PrefNames {
public:
static constexpr absl::string_view kVisibility =
"nearby_sharing.background_visibility";
static constexpr absl::string_view kFallbackVisibility =
"nearby_sharing.background_fallback_visibility";
static constexpr absl::string_view kVisibilityExpirationSeconds =
"nearby_sharing.background_visibility_expiration_seconds";
static constexpr absl::string_view kCustomSavePath =
"nearby_sharing.custom_save_path";
static constexpr absl::string_view kDataUsage = "nearby_sharing.data_usage";
static constexpr absl::string_view kDeviceId = "nearby_sharing.device_id";
static constexpr absl::string_view kDeviceName = "nearby_sharing.device_name";
static constexpr absl::string_view kFastInitiationNotificationState =
"nearby_sharing.fast_initiation_notification_state";
static constexpr absl::string_view kPrivateCertificateList =
"nearby_sharing.private_certificate_list";
static constexpr absl::string_view kPublicCertificateExpirationDict =
"nearbyshare.public_certificate_expiration_dict";
static constexpr absl::string_view kSchedulerDownloadPublicCertificates =
"nearby_sharing.scheduler.download_public_certificates";
static constexpr absl::string_view kSchedulerPrivateCertificateExpiration =
"nearby_sharing.scheduler.private_certificate_expiration";
static constexpr absl::string_view kSchedulerPublicCertificateExpiration =
"nearby_sharing.scheduler.public_certificate_expiration";
static constexpr absl::string_view kSchedulerUploadLocalDeviceCertificates =
"nearby_sharing.scheduler.upload_local_device_certificates";
static constexpr absl::string_view kUsers = "nearby_sharing.users";
static constexpr absl::string_view kIsAnalyticsEnabled =
"nearby_sharing.is_analytics_enabled";
static constexpr absl::string_view kAdvancedProtectionEnabled =
"nearby_sharing.advanced_protection_enabled";
};
} // namespace nearby::sharing
#endif // THIRD_PARTY_NEARBY_SHARING_INTERNAL_PUBLIC_PREF_NAMES_H_
-10
View File
@@ -1180,11 +1180,6 @@ std::string NearbySharingServiceImpl::Dump() const {
// Dump scheduled tasks
sstream << "Nearby Tasks/Certificates State" << std::endl;
sstream << " Download & upload contacts: "
<< ConvertToReadableSchedule(
preference_manager_,
prefs::kNearbySharingSchedulerContactDownloadAndUploadName)
<< std::endl;
sstream << " Download public certificates: "
<< ConvertToReadableSchedule(
preference_manager_,
@@ -1196,11 +1191,6 @@ std::string NearbySharingServiceImpl::Dump() const {
preference_manager_,
prefs::kNearbySharingSchedulerUploadLocalDeviceCertificatesName)
<< std::endl;
sstream << " Upload device name: "
<< ConvertToReadableSchedule(
preference_manager_,
prefs::kNearbySharingSchedulerUploadDeviceNameName)
<< std::endl;
sstream << " Private certificates expiration: "
<< ConvertToReadableSchedule(
preference_manager_,