Commit 4372b34c authored by Kyle Horimoto's avatar Kyle Horimoto Committed by Commit Bot

[CrOS MultiDevice] Refactor multi-device preferences.

This CL:
(1) Moves SmartLock's enabled and allowed preferences to the
    MultiDeviceSetup service (see go/cros-multidevice-prefs).
(2) Renames existing preferences so that they are named in the same
    format.
(3) Removes some of these preferences from the settings whitelist,
    since they are not edited in settings.

Note: This CL unblocks adding enterprise policies to
FeatureStateManager, which must have access to the preferences.

TBR=stevenjb@chromium.org

Bug: 870113, 824568
Change-Id: Icffa4ed6b80095dd51e53b30a352289f584deba7
Reviewed-on: https://chromium-review.googlesource.com/1186033
Commit-Queue: Kyle Horimoto <khorimoto@chromium.org>
Reviewed-by: default avatarMichael Giuffrida <michaelpg@chromium.org>
Reviewed-by: default avatarMaksim Ivanov <emaxx@chromium.org>
Reviewed-by: default avatarRyan Hansberry <hansberry@chromium.org>
Cr-Commit-Position: refs/heads/master@{#585932}
parent 0d639a0e
......@@ -124,10 +124,10 @@ ChromeCryptAuthService::ChromeCryptAuthService(
gcm_manager_->StartListening();
registrar_.Init(profile_->GetPrefs());
registrar_.Add(prefs::kEasyUnlockAllowed,
registrar_.Add(multidevice_setup::kSmartLockAllowedPrefName,
base::Bind(&ChromeCryptAuthService::OnPrefsChanged,
weak_ptr_factory_.GetWeakPtr()));
registrar_.Add(multidevice_setup::kInstantTetheringFeatureAllowedPrefName,
registrar_.Add(multidevice_setup::kInstantTetheringAllowedPrefName,
base::Bind(&ChromeCryptAuthService::OnPrefsChanged,
weak_ptr_factory_.GetWeakPtr()));
......@@ -210,7 +210,11 @@ void ChromeCryptAuthService::OnRefreshTokenUpdatedForAccount(
void ChromeCryptAuthService::PerformEnrollmentAndDeviceSyncIfPossible() {
DCHECK(identity_manager_->HasPrimaryAccountWithRefreshToken());
if (!IsEnrollmentAllowedByPolicy()) {
// CryptAuth enrollment is allowed only if at least one multi-device feature
// is enabled. This ensures that we do not unnecessarily register devices on
// the CryptAuth back-end when the registration would never actually be used.
if (!multidevice_setup::AreAnyMultiDeviceFeaturesAllowed(
profile_->GetPrefs())) {
PA_LOG(INFO) << "CryptAuth enrollment is disabled by enterprise policy.";
return;
}
......@@ -228,15 +232,6 @@ void ChromeCryptAuthService::PerformEnrollmentAndDeviceSyncIfPossible() {
enrollment_manager_->Start();
}
bool ChromeCryptAuthService::IsEnrollmentAllowedByPolicy() {
// We allow CryptAuth enrollments if at least one of the features which
// depends on CryptAuth is enabled by enterprise policy.
PrefService* pref_service = profile_->GetPrefs();
return pref_service->GetBoolean(prefs::kEasyUnlockAllowed) ||
pref_service->GetBoolean(
multidevice_setup::kInstantTetheringFeatureAllowedPrefName);
}
void ChromeCryptAuthService::OnPrefsChanged() {
// Note: We only start the CryptAuth services if a feature was toggled on. In
// the inverse case, we simply leave the services running until the user logs
......
......@@ -68,7 +68,6 @@ class ChromeCryptAuthService
void OnAuthenticationStateChanged();
void PerformEnrollmentAndDeviceSyncIfPossible();
bool IsEnrollmentAllowedByPolicy();
void OnPrefsChanged();
std::unique_ptr<cryptauth::CryptAuthClientFactory> client_factory_;
......
......@@ -24,13 +24,12 @@ namespace device_sync {
namespace {
// CryptAuth enrollment is allowed only if at least one multi-device feature is
// enabled. This ensures that we do not unnecessarily register devices on the
// CryptAuth back-end when the registration would never actually be used.
bool IsEnrollmentAllowedByPolicy(content::BrowserContext* context) {
// We allow CryptAuth enrollments if at least one of the features which
// depends on CryptAuth is enabled by enterprise policy.
PrefService* pref_service = Profile::FromBrowserContext(context)->GetPrefs();
return pref_service->GetBoolean(prefs::kEasyUnlockAllowed) ||
pref_service->GetBoolean(
multidevice_setup::kInstantTetheringFeatureAllowedPrefName);
return multidevice_setup::AreAnyMultiDeviceFeaturesAllowed(
Profile::FromBrowserContext(context)->GetPrefs());
}
} // namespace
......
......@@ -175,10 +175,9 @@ TetherService::TetherService(
}
registrar_.Init(profile_->GetPrefs());
registrar_.Add(
chromeos::multidevice_setup::kInstantTetheringFeatureAllowedPrefName,
base::BindRepeating(&TetherService::OnPrefsChanged,
weak_ptr_factory_.GetWeakPtr()));
registrar_.Add(chromeos::multidevice_setup::kInstantTetheringAllowedPrefName,
base::BindRepeating(&TetherService::OnPrefsChanged,
weak_ptr_factory_.GetWeakPtr()));
UMA_HISTOGRAM_BOOLEAN("InstantTethering.UserPreference.OnStartup",
IsEnabledByPreference());
......@@ -394,7 +393,7 @@ void TetherService::UpdateEnabledState() {
if (is_enabled != was_pref_enabled) {
profile_->GetPrefs()->SetBoolean(
chromeos::multidevice_setup::kInstantTetheringFeatureEnabledPrefName,
chromeos::multidevice_setup::kInstantTetheringEnabledPrefName,
is_enabled);
UMA_HISTOGRAM_BOOLEAN("InstantTethering.UserPreference.OnToggle",
is_enabled);
......@@ -611,12 +610,12 @@ bool TetherService::IsCellularAvailableButNotEnabled() const {
bool TetherService::IsAllowedByPolicy() const {
return profile_->GetPrefs()->GetBoolean(
chromeos::multidevice_setup::kInstantTetheringFeatureAllowedPrefName);
chromeos::multidevice_setup::kInstantTetheringAllowedPrefName);
}
bool TetherService::IsEnabledByPreference() const {
return profile_->GetPrefs()->GetBoolean(
chromeos::multidevice_setup::kInstantTetheringFeatureEnabledPrefName);
chromeos::multidevice_setup::kInstantTetheringEnabledPrefName);
}
TetherService::TetherFeatureState TetherService::GetTetherFeatureState() {
......
......@@ -994,8 +994,7 @@ TEST_F(TetherServiceTest, TestNoTetherHosts) {
TEST_F(TetherServiceTest, TestProhibitedByPolicy) {
profile_->GetPrefs()->SetBoolean(
chromeos::multidevice_setup::kInstantTetheringFeatureAllowedPrefName,
false);
chromeos::multidevice_setup::kInstantTetheringAllowedPrefName, false);
CreateTetherService();
......@@ -1207,8 +1206,7 @@ TEST_F(TetherServiceTest, TestCellularIsAvailable) {
TEST_F(TetherServiceTest, TestDisabled) {
profile_->GetPrefs()->SetBoolean(
chromeos::multidevice_setup::kInstantTetheringFeatureEnabledPrefName,
false);
chromeos::multidevice_setup::kInstantTetheringEnabledPrefName, false);
CreateTetherService();
......@@ -1217,7 +1215,7 @@ TEST_F(TetherServiceTest, TestDisabled) {
network_state_handler()->GetTechnologyState(
chromeos::NetworkTypePattern::Tether()));
EXPECT_FALSE(profile_->GetPrefs()->GetBoolean(
chromeos::multidevice_setup::kInstantTetheringFeatureEnabledPrefName));
chromeos::multidevice_setup::kInstantTetheringEnabledPrefName));
VerifyTetherActiveStatus(false /* expected_active */);
VerifyTetherFeatureStateRecorded(
......@@ -1239,7 +1237,7 @@ TEST_F(TetherServiceTest, TestEnabled) {
network_state_handler()->GetTechnologyState(
chromeos::NetworkTypePattern::Tether()));
EXPECT_FALSE(profile_->GetPrefs()->GetBoolean(
chromeos::multidevice_setup::kInstantTetheringFeatureEnabledPrefName));
chromeos::multidevice_setup::kInstantTetheringEnabledPrefName));
VerifyTetherActiveStatus(false /* expected_active */);
histogram_tester_.ExpectBucketCount(
"InstantTethering.UserPreference.OnToggle", false,
......@@ -1250,7 +1248,7 @@ TEST_F(TetherServiceTest, TestEnabled) {
network_state_handler()->GetTechnologyState(
chromeos::NetworkTypePattern::Tether()));
EXPECT_TRUE(profile_->GetPrefs()->GetBoolean(
chromeos::multidevice_setup::kInstantTetheringFeatureEnabledPrefName));
chromeos::multidevice_setup::kInstantTetheringEnabledPrefName));
VerifyTetherActiveStatus(true /* expected_active */);
histogram_tester_.ExpectBucketCount(
"InstantTethering.UserPreference.OnToggle", true,
......
......@@ -1001,7 +1001,6 @@ jumbo_static_library("extensions") {
"//ash/public/cpp",
"//chromeos/components/proximity_auth",
"//chromeos/components/proximity_auth/logging",
"//chromeos/services/multidevice_setup/public/cpp:prefs",
"//components/arc",
"//components/chrome_apps",
"//components/constrained_window",
......
......@@ -51,7 +51,6 @@
#include "chrome/browser/chromeos/system/timezone_util.h"
#include "chrome/browser/extensions/api/settings_private/chromeos_resolve_time_zone_by_geolocation_method_short.h"
#include "chrome/browser/extensions/api/settings_private/chromeos_resolve_time_zone_by_geolocation_on_off.h"
#include "chromeos/services/multidevice_setup/public/cpp/prefs.h"
#include "chromeos/settings/cros_settings_names.h"
#include "components/arc/arc_prefs.h"
#include "ui/chromeos/events/pref_names.h"
......@@ -487,13 +486,6 @@ const PrefsUtil::TypedPrefMap& PrefsUtil::GetWhitelistedKeys() {
(*s_whitelist)[::prefs::kLanguageXkbAutoRepeatInterval] =
settings_api::PrefType::PREF_TYPE_NUMBER;
// Multidevice settings.
(*s_whitelist)[chromeos::multidevice_setup::kSuiteEnabledPrefName] =
settings_api::PrefType::PREF_TYPE_BOOLEAN;
(*s_whitelist)
[chromeos::multidevice_setup::kAndroidMessagesFeatureEnabledPrefName] =
settings_api::PrefType::PREF_TYPE_BOOLEAN;
// Native Printing settings.
(*s_whitelist)[::prefs::kUserNativePrintersAllowed] =
settings_api::PrefType::PREF_TYPE_BOOLEAN;
......
......@@ -606,10 +606,10 @@ const PolicyToPreferenceMapEntry kSimplePolicyMap[] = {
prefs::kTouchVirtualKeyboardEnabled,
base::Value::Type::BOOLEAN },
{ key::kEasyUnlockAllowed,
prefs::kEasyUnlockAllowed,
chromeos::multidevice_setup::kSmartLockAllowedPrefName,
base::Value::Type::BOOLEAN },
{ key::kInstantTetheringAllowed,
chromeos::multidevice_setup::kInstantTetheringFeatureAllowedPrefName,
chromeos::multidevice_setup::kInstantTetheringAllowedPrefName,
base::Value::Type::BOOLEAN },
{ key::kCaptivePortalAuthenticationIgnoresProxy,
prefs::kCaptivePortalAuthenticationIgnoresProxy,
......
......@@ -55,6 +55,10 @@ static_library("proximity_auth") {
"//chromeos",
"//chromeos/components/proximity_auth/logging",
"//chromeos/components/proximity_auth/public/interfaces",
# TODO(hansberry): Remove this dependency once https://crbug.com/870123 is
# fixed.
"//chromeos/services/multidevice_setup/public/cpp:prefs",
"//chromeos/services/secure_channel/public/cpp/client",
"//chromeos/services/secure_channel/public/mojom",
"//components/account_id",
......@@ -116,6 +120,10 @@ source_set("unit_tests") {
"//chromeos",
"//chromeos/components/proximity_auth/logging",
"//chromeos/components/proximity_auth/logging:unit_tests",
# TODO(hansberry): Remove this dependency once https://crbug.com/870123 is
# fixed.
"//chromeos/services/multidevice_setup/public/cpp:prefs",
"//chromeos/services/secure_channel/public/cpp/client:test_support",
"//components/cryptauth:test_support",
"//components/prefs:test_support",
......
......@@ -12,6 +12,7 @@
#include "base/values.h"
#include "chromeos/components/proximity_auth/logging/logging.h"
#include "chromeos/components/proximity_auth/proximity_auth_pref_names.h"
#include "chromeos/services/multidevice_setup/public/cpp/prefs.h"
#include "components/prefs/pref_registry_simple.h"
#include "components/prefs/pref_service.h"
#include "components/prefs/scoped_user_pref_update.h"
......@@ -74,7 +75,8 @@ bool ProximityAuthLocalStatePrefManager::IsEasyUnlockAllowed() const {
bool pref_value;
const base::DictionaryValue* user_prefs = GetActiveUserPrefsDictionary();
if (!user_prefs || !user_prefs->GetBooleanWithoutPathExpansion(
prefs::kEasyUnlockAllowed, &pref_value)) {
chromeos::multidevice_setup::kSmartLockAllowedPrefName,
&pref_value)) {
PA_LOG(ERROR) << "Failed to get easyunlock_allowed.";
return true;
}
......@@ -85,7 +87,8 @@ bool ProximityAuthLocalStatePrefManager::IsEasyUnlockEnabled() const {
bool pref_value;
const base::DictionaryValue* user_prefs = GetActiveUserPrefsDictionary();
if (!user_prefs || !user_prefs->GetBooleanWithoutPathExpansion(
prefs::kEasyUnlockEnabled, &pref_value)) {
chromeos::multidevice_setup::kSmartLockEnabledPrefName,
&pref_value)) {
PA_LOG(ERROR) << "Failed to get easyunlock_enabled.";
return false;
}
......
......@@ -11,6 +11,7 @@
#include "base/json/json_reader.h"
#include "base/macros.h"
#include "chromeos/components/proximity_auth/proximity_auth_pref_names.h"
#include "chromeos/services/multidevice_setup/public/cpp/prefs.h"
#include "components/prefs/scoped_user_pref_update.h"
#include "components/prefs/testing_pref_service.h"
#include "testing/gmock/include/gmock/gmock.h"
......@@ -63,9 +64,9 @@ class ProximityAuthLocalStatePrefManagerTest : public testing::Test {
user1_prefs->SetKey(
proximity_auth::prefs::kProximityAuthIsChromeOSLoginEnabled,
base::Value(kIsChromeOSLoginEnabled1));
user1_prefs->SetKey(proximity_auth::prefs::kEasyUnlockAllowed,
user1_prefs->SetKey(chromeos::multidevice_setup::kSmartLockAllowedPrefName,
base::Value(kIsEasyUnlockAllowed1));
user1_prefs->SetKey(proximity_auth::prefs::kEasyUnlockEnabled,
user1_prefs->SetKey(chromeos::multidevice_setup::kSmartLockEnabledPrefName,
base::Value(kIsEasyUnlockEnabled1));
DictionaryPrefUpdate update1(&local_state_,
prefs::kEasyUnlockLocalStateUserPrefs);
......@@ -79,9 +80,9 @@ class ProximityAuthLocalStatePrefManagerTest : public testing::Test {
user2_prefs->SetKey(
proximity_auth::prefs::kProximityAuthIsChromeOSLoginEnabled,
base::Value(kIsChromeOSLoginEnabled2));
user2_prefs->SetKey(proximity_auth::prefs::kEasyUnlockAllowed,
user2_prefs->SetKey(chromeos::multidevice_setup::kSmartLockAllowedPrefName,
base::Value(kIsEasyUnlockAllowed2));
user2_prefs->SetKey(proximity_auth::prefs::kEasyUnlockEnabled,
user2_prefs->SetKey(chromeos::multidevice_setup::kSmartLockEnabledPrefName,
base::Value(kIsEasyUnlockEnabled2));
DictionaryPrefUpdate update2(&local_state_,
......
......@@ -7,14 +7,6 @@
namespace proximity_auth {
namespace prefs {
// Whether a user is allowed to use Easy Unlock. This pref is expected to be set
// through an enterprise policy.
const char kEasyUnlockAllowed[] = "easy_unlock.allowed";
// Whether or not EasyUnlock has been enabled by the user (i.e. they went
// through the setup flow and there is at least one unlock key).
const char kEasyUnlockEnabled[] = "easy_unlock.enabled";
// Whether or not the state of EasyUnlock has actively been changed, e.g.,
// explicitly enabled by the user (through setup) or disabled via Settings.
const char kEasyUnlockEnabledStateSet[] = "easy_unlock.enabled_state_set";
......
......@@ -8,8 +8,6 @@
namespace proximity_auth {
namespace prefs {
extern const char kEasyUnlockAllowed[];
extern const char kEasyUnlockEnabled[];
extern const char kEasyUnlockEnabledStateSet[];
extern const char kEasyUnlockProximityThreshold[];
extern const char kEasyUnlockLocalStateUserPrefs[];
......
......@@ -12,6 +12,7 @@
#include "base/values.h"
#include "chromeos/components/proximity_auth/logging/logging.h"
#include "chromeos/components/proximity_auth/proximity_auth_pref_names.h"
#include "chromeos/services/multidevice_setup/public/cpp/prefs.h"
#include "components/pref_registry/pref_registry_syncable.h"
#include "components/prefs/pref_service.h"
#include "components/prefs/scoped_user_pref_update.h"
......@@ -29,8 +30,6 @@ ProximityAuthProfilePrefManager::~ProximityAuthProfilePrefManager() {
// static
void ProximityAuthProfilePrefManager::RegisterPrefs(
user_prefs::PrefRegistrySyncable* registry) {
registry->RegisterBooleanPref(prefs::kEasyUnlockAllowed, true);
registry->RegisterBooleanPref(prefs::kEasyUnlockEnabled, false);
registry->RegisterBooleanPref(prefs::kEasyUnlockEnabledStateSet, false);
registry->RegisterInt64Pref(
prefs::kProximityAuthLastPromotionCheckTimestampMs, 0L);
......@@ -60,8 +59,10 @@ void ProximityAuthProfilePrefManager::StartSyncingToLocalState(
weak_ptr_factory_.GetWeakPtr());
registrar_.Init(pref_service_);
registrar_.Add(prefs::kEasyUnlockAllowed, on_pref_changed_callback);
registrar_.Add(prefs::kEasyUnlockEnabled, on_pref_changed_callback);
registrar_.Add(chromeos::multidevice_setup::kSmartLockAllowedPrefName,
on_pref_changed_callback);
registrar_.Add(chromeos::multidevice_setup::kSmartLockEnabledPrefName,
on_pref_changed_callback);
registrar_.Add(proximity_auth::prefs::kEasyUnlockProximityThreshold,
on_pref_changed_callback);
registrar_.Add(proximity_auth::prefs::kProximityAuthIsChromeOSLoginEnabled,
......@@ -74,10 +75,12 @@ void ProximityAuthProfilePrefManager::SyncPrefsToLocalState() {
std::unique_ptr<base::DictionaryValue> user_prefs_dict(
new base::DictionaryValue());
user_prefs_dict->SetKey(prefs::kEasyUnlockAllowed,
base::Value(IsEasyUnlockAllowed()));
user_prefs_dict->SetKey(prefs::kEasyUnlockEnabled,
base::Value(IsEasyUnlockEnabled()));
user_prefs_dict->SetKey(
chromeos::multidevice_setup::kSmartLockAllowedPrefName,
base::Value(IsEasyUnlockAllowed()));
user_prefs_dict->SetKey(
chromeos::multidevice_setup::kSmartLockEnabledPrefName,
base::Value(IsEasyUnlockEnabled()));
user_prefs_dict->SetKey(prefs::kEasyUnlockProximityThreshold,
base::Value(GetProximityThreshold()));
user_prefs_dict->SetKey(prefs::kProximityAuthIsChromeOSLoginEnabled,
......@@ -90,16 +93,20 @@ void ProximityAuthProfilePrefManager::SyncPrefsToLocalState() {
}
bool ProximityAuthProfilePrefManager::IsEasyUnlockAllowed() const {
return pref_service_->GetBoolean(prefs::kEasyUnlockAllowed);
return pref_service_->GetBoolean(
chromeos::multidevice_setup::kSmartLockAllowedPrefName);
}
void ProximityAuthProfilePrefManager::SetIsEasyUnlockEnabled(
bool is_easy_unlock_enabled) const {
pref_service_->SetBoolean(prefs::kEasyUnlockEnabled, is_easy_unlock_enabled);
pref_service_->SetBoolean(
chromeos::multidevice_setup::kSmartLockEnabledPrefName,
is_easy_unlock_enabled);
}
bool ProximityAuthProfilePrefManager::IsEasyUnlockEnabled() const {
return pref_service_->GetBoolean(prefs::kEasyUnlockEnabled);
return pref_service_->GetBoolean(
chromeos::multidevice_setup::kSmartLockEnabledPrefName);
}
void ProximityAuthProfilePrefManager::SetEasyUnlockEnabledStateSet() const {
......
......@@ -12,6 +12,7 @@
#include "base/macros.h"
#include "chromeos/components/proximity_auth/proximity_auth_local_state_pref_manager.h"
#include "chromeos/components/proximity_auth/proximity_auth_pref_names.h"
#include "chromeos/services/multidevice_setup/public/cpp/prefs.h"
#include "components/prefs/testing_pref_service.h"
#include "components/sync_preferences/testing_pref_service_syncable.h"
#include "testing/gmock/include/gmock/gmock.h"
......@@ -38,6 +39,7 @@ class ProximityAuthProfilePrefManagerTest : public testing::Test {
void SetUp() override {
ProximityAuthProfilePrefManager::RegisterPrefs(pref_service_.registry());
chromeos::multidevice_setup::RegisterFeaturePrefs(pref_service_.registry());
}
sync_preferences::TestingPrefServiceSyncable pref_service_;
......@@ -51,13 +53,14 @@ TEST_F(ProximityAuthProfilePrefManagerTest, IsEasyUnlockAllowed) {
EXPECT_TRUE(pref_manager.IsEasyUnlockAllowed());
// Simulating setting kEasyUnlockAllowed pref through enterprise policy.
pref_service_.SetBoolean(prefs::kEasyUnlockAllowed, false);
pref_service_.SetBoolean(
chromeos::multidevice_setup::kSmartLockAllowedPrefName, false);
EXPECT_FALSE(pref_manager.IsEasyUnlockAllowed());
}
TEST_F(ProximityAuthProfilePrefManagerTest, IsEasyUnlockEnabled) {
ProximityAuthProfilePrefManager pref_manager(&pref_service_);
EXPECT_FALSE(pref_manager.IsEasyUnlockEnabled());
EXPECT_TRUE(pref_manager.IsEasyUnlockEnabled());
pref_manager.SetIsEasyUnlockEnabled(true);
EXPECT_TRUE(pref_manager.IsEasyUnlockEnabled());
......@@ -135,7 +138,8 @@ TEST_F(ProximityAuthProfilePrefManagerTest, SyncsToLocalPrefOnChange) {
// Test changing the kEasyUnlockAllowed pref value directly (e.g. through
// enterprise policy).
EXPECT_TRUE(local_pref_manager.IsEasyUnlockAllowed());
pref_service_.SetBoolean(prefs::kEasyUnlockAllowed, false);
pref_service_.SetBoolean(
chromeos::multidevice_setup::kSmartLockAllowedPrefName, false);
EXPECT_FALSE(profile_pref_manager.IsEasyUnlockAllowed());
EXPECT_FALSE(local_pref_manager.IsEasyUnlockAllowed());
}
......
......@@ -21,29 +21,21 @@ namespace multidevice_setup {
namespace {
// TODO(jordynass): Use constants declared in
// chromeos/services/multidevice_setup/public/cpp/prefs.h once migration is
// complete, then delete these fields which are duplicates. See
// https://crbug.com/870065.
const char kSmartLockFeatureEnabledPrefName[] = "easy_unlock.enabled";
const char kSmartLockFeatureAllowedPrefName[] = "easy_unlock.allowed";
base::flat_map<mojom::Feature, std::string>
GenerateFeatureToEnabledPrefNameMap() {
return base::flat_map<mojom::Feature, std::string>{
{mojom::Feature::kBetterTogetherSuite, kSuiteEnabledPrefName},
{mojom::Feature::kInstantTethering,
kInstantTetheringFeatureEnabledPrefName},
{mojom::Feature::kMessages, kAndroidMessagesFeatureEnabledPrefName},
{mojom::Feature::kSmartLock, kSmartLockFeatureEnabledPrefName}};
{mojom::Feature::kBetterTogetherSuite,
kBetterTogetherSuiteEnabledPrefName},
{mojom::Feature::kInstantTethering, kInstantTetheringEnabledPrefName},
{mojom::Feature::kMessages, kMessagesEnabledPrefName},
{mojom::Feature::kSmartLock, kSmartLockEnabledPrefName}};
}
base::flat_map<mojom::Feature, std::string>
GenerateFeatureToAllowedPrefNameMap() {
return base::flat_map<mojom::Feature, std::string>{
{mojom::Feature::kInstantTethering,
kInstantTetheringFeatureAllowedPrefName},
{mojom::Feature::kSmartLock, kSmartLockFeatureAllowedPrefName}};
{mojom::Feature::kInstantTethering, kInstantTetheringAllowedPrefName},
{mojom::Feature::kSmartLock, kSmartLockAllowedPrefName}};
}
// Each feature's default value is kUnavailableNoVerifiedHost until proven
......
......@@ -22,12 +22,6 @@ namespace multidevice_setup {
namespace {
// TODO(jordynass): Use constants declared in
// chromeos/services/multidevice_setup/public/cpp/prefs.h once migration is
// complete, then delete these fields which are duplicates.
const char kSmartLockFeatureEnabledPrefName[] = "easy_unlock.enabled";
const char kSmartLockFeatureAllowedPrefName[] = "easy_unlock.allowed";
cryptauth::RemoteDeviceRef CreateTestHostDevice() {
cryptauth::RemoteDeviceRef host_device =
cryptauth::CreateRemoteDeviceRefForTest();
......@@ -63,10 +57,6 @@ class MultiDeviceSetupFeatureStateManagerImplTest : public testing::Test {
std::make_unique<sync_preferences::TestingPrefServiceSyncable>();
user_prefs::PrefRegistrySyncable* registry = test_pref_service_->registry();
RegisterFeaturePrefs(registry);
// TODO(jordynass): Remove the registration of these preferences once they
// are migrated.
registry->RegisterBooleanPref(kSmartLockFeatureAllowedPrefName, true);
registry->RegisterBooleanPref(kSmartLockFeatureEnabledPrefName, true);
fake_host_status_provider_ = std::make_unique<FakeHostStatusProvider>();
......@@ -210,7 +200,7 @@ TEST_F(MultiDeviceSetupFeatureStateManagerImplTest, BetterTogetherSuite) {
mojom::Feature::kBetterTogetherSuite,
mojom::FeatureState::kEnabledByUser);
test_pref_service()->SetBoolean(kSuiteEnabledPrefName, false);
test_pref_service()->SetBoolean(kBetterTogetherSuiteEnabledPrefName, false);
EXPECT_EQ(
mojom::FeatureState::kDisabledByUser,
manager()->GetFeatureStates()[mojom::Feature::kBetterTogetherSuite]);
......@@ -245,16 +235,14 @@ TEST_F(MultiDeviceSetupFeatureStateManagerImplTest, InstantTethering) {
mojom::Feature::kInstantTethering,
mojom::FeatureState::kEnabledByUser);
test_pref_service()->SetBoolean(kInstantTetheringFeatureEnabledPrefName,
false);
test_pref_service()->SetBoolean(kInstantTetheringEnabledPrefName, false);
EXPECT_EQ(mojom::FeatureState::kDisabledByUser,
manager()->GetFeatureStates()[mojom::Feature::kInstantTethering]);
VerifyFeatureStateChange(3u /* expected_index */,
mojom::Feature::kInstantTethering,
mojom::FeatureState::kDisabledByUser);
test_pref_service()->SetBoolean(kInstantTetheringFeatureAllowedPrefName,
false);
test_pref_service()->SetBoolean(kInstantTetheringAllowedPrefName, false);
EXPECT_EQ(mojom::FeatureState::kDisabledByPolicy,
manager()->GetFeatureStates()[mojom::Feature::kInstantTethering]);
VerifyFeatureStateChange(4u /* expected_index */,
......@@ -285,8 +273,7 @@ TEST_F(MultiDeviceSetupFeatureStateManagerImplTest, Messages) {
VerifyFeatureStateChange(2u /* expected_index */, mojom::Feature::kMessages,
mojom::FeatureState::kEnabledByUser);
test_pref_service()->SetBoolean(kAndroidMessagesFeatureEnabledPrefName,
false);
test_pref_service()->SetBoolean(kMessagesEnabledPrefName, false);
EXPECT_EQ(mojom::FeatureState::kDisabledByUser,
manager()->GetFeatureStates()[mojom::Feature::kMessages]);
VerifyFeatureStateChange(3u /* expected_index */, mojom::Feature::kMessages,
......@@ -317,13 +304,13 @@ TEST_F(MultiDeviceSetupFeatureStateManagerImplTest, SmartLock) {
VerifyFeatureStateChange(2u /* expected_index */, mojom::Feature::kSmartLock,
mojom::FeatureState::kEnabledByUser);
test_pref_service()->SetBoolean(kSmartLockFeatureEnabledPrefName, false);
test_pref_service()->SetBoolean(kSmartLockEnabledPrefName, false);
EXPECT_EQ(mojom::FeatureState::kDisabledByUser,
manager()->GetFeatureStates()[mojom::Feature::kSmartLock]);
VerifyFeatureStateChange(3u /* expected_index */, mojom::Feature::kSmartLock,
mojom::FeatureState::kDisabledByUser);
test_pref_service()->SetBoolean(kSmartLockFeatureAllowedPrefName, false);
test_pref_service()->SetBoolean(kSmartLockAllowedPrefName, false);
EXPECT_EQ(mojom::FeatureState::kDisabledByPolicy,
manager()->GetFeatureStates()[mojom::Feature::kSmartLock]);
VerifyFeatureStateChange(4u /* expected_index */, mojom::Feature::kSmartLock,
......
......@@ -5,41 +5,41 @@
#include "chromeos/services/multidevice_setup/public/cpp/prefs.h"
#include "components/prefs/pref_registry_simple.h"
#include "components/prefs/pref_service.h"
namespace chromeos {
namespace multidevice_setup {
// Note that the pref names have slightly inconsistent naming conventions
// because some were named before the unified MultiDeviceSetup project and we
// wanted to avoid changing the internal names of existing prefs. The general
// naming pattern for each individual feature enabling pref moving forward
// should be of the form
// const char k[FeatureName]FeatureEnabledPrefName =
// "multidevice_setup.[feature_name]_enabled";
// Note: Pref name strings follow an inconsistent naming convention because some
// of them were created before the MultiDeviceSetup project.
// This pref is a gatekeeper for all MultiDevice features (e.g. Easy Unlock,
// Instant Tethering). Setting the pref to 'true' is necessary but not
// sufficient to enable the individual features, which are each controlled by
// their own pref and may involve additional setup steps.
const char kSuiteEnabledPrefName[] = "multidevice_setup.suite_enabled";
// "Allowed by user policy" preferences:
const char kInstantTetheringAllowedPrefName[] = "tether.allowed";
const char kSmartLockAllowedPrefName[] = "easy_unlock.allowed";
// Individual feature prefs.
const char kAndroidMessagesFeatureEnabledPrefName[] =
"multidevice.sms_connect_enabled";
// Whether Instant Tethering is allowed by policy.
const char kInstantTetheringFeatureAllowedPrefName[] = "tether.allowed";
// Whether Instant Tethering is enabled by the user. Note that if the feature is
// enabled by the user but disallowed by policy, it is unavailable.
const char kInstantTetheringFeatureEnabledPrefName[] = "tether.enabled";
// "Enabled by user" preferences:
const char kBetterTogetherSuiteEnabledPrefName[] =
"multidevice_setup.suite_enabled";
const char kInstantTetheringEnabledPrefName[] = "tether.enabled";
const char kMessagesEnabledPrefName[] = "multidevice.sms_connect_enabled";
const char kSmartLockEnabledPrefName[] = "easy_unlock.enabled";
void RegisterFeaturePrefs(PrefRegistrySimple* registry) {
registry->RegisterBooleanPref(kSuiteEnabledPrefName, true);
registry->RegisterBooleanPref(kAndroidMessagesFeatureEnabledPrefName, true);
registry->RegisterBooleanPref(kInstantTetheringFeatureAllowedPrefName, true);
registry->RegisterBooleanPref(kInstantTetheringFeatureEnabledPrefName, true);
registry->RegisterBooleanPref(kInstantTetheringAllowedPrefName, true);
// TODO(khorimoto): Register "messages allowed" preference.
registry->RegisterBooleanPref(kSmartLockAllowedPrefName, true);
registry->RegisterBooleanPref(kBetterTogetherSuiteEnabledPrefName, true);
registry->RegisterBooleanPref(kInstantTetheringEnabledPrefName, true);
registry->RegisterBooleanPref(kMessagesEnabledPrefName, true);
registry->RegisterBooleanPref(kSmartLockEnabledPrefName, true);
}
bool AreAnyMultiDeviceFeaturesAllowed(PrefService* pref_service) {
// TODO(khorimoto): Read from "messages allowed" preference when available.
return pref_service->GetBoolean(kInstantTetheringAllowedPrefName) ||
pref_service->GetBoolean(kSmartLockAllowedPrefName);
}
} // namespace multidevice_setup
......
......@@ -6,17 +6,29 @@
#define CHROMEOS_SERVICES_MULTIDEVICE_SETUP_PUBLIC_CPP_PREFS_H_
class PrefRegistrySimple;
class PrefService;
namespace chromeos {
namespace multidevice_setup {
extern const char kSuiteEnabledPrefName[];
extern const char kAndroidMessagesFeatureEnabledPrefName[];
extern const char kInstantTetheringFeatureAllowedPrefName[];
extern const char kInstantTetheringFeatureEnabledPrefName[];
// Preferences which represent whether features are allowed by user policy. A
// "false" value means that the administrator has prohibited the feature and
// that users do not have the option of attempting to enable the feature.
extern const char kInstantTetheringAllowedPrefName[];
// TODO(khorimoto): Add messages "allowed" preference.
extern const char kSmartLockAllowedPrefName[];
// Preferences which represent whether features are enabled by the user via
// settings. If a feature is prohibited (see above preferences), the "enabled"
// preferences are ignored since the feature is not usable.
extern const char kBetterTogetherSuiteEnabledPrefName[];
extern const char kInstantTetheringEnabledPrefName[];
extern const char kMessagesEnabledPrefName[];
extern const char kSmartLockEnabledPrefName[];
void RegisterFeaturePrefs(PrefRegistrySimple* registry);
bool AreAnyMultiDeviceFeaturesAllowed(PrefService* pref_service);
} // namespace multidevice_setup
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment