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( ...@@ -124,10 +124,10 @@ ChromeCryptAuthService::ChromeCryptAuthService(
gcm_manager_->StartListening(); gcm_manager_->StartListening();
registrar_.Init(profile_->GetPrefs()); registrar_.Init(profile_->GetPrefs());
registrar_.Add(prefs::kEasyUnlockAllowed, registrar_.Add(multidevice_setup::kSmartLockAllowedPrefName,
base::Bind(&ChromeCryptAuthService::OnPrefsChanged, base::Bind(&ChromeCryptAuthService::OnPrefsChanged,
weak_ptr_factory_.GetWeakPtr())); weak_ptr_factory_.GetWeakPtr()));
registrar_.Add(multidevice_setup::kInstantTetheringFeatureAllowedPrefName, registrar_.Add(multidevice_setup::kInstantTetheringAllowedPrefName,
base::Bind(&ChromeCryptAuthService::OnPrefsChanged, base::Bind(&ChromeCryptAuthService::OnPrefsChanged,
weak_ptr_factory_.GetWeakPtr())); weak_ptr_factory_.GetWeakPtr()));
...@@ -210,7 +210,11 @@ void ChromeCryptAuthService::OnRefreshTokenUpdatedForAccount( ...@@ -210,7 +210,11 @@ void ChromeCryptAuthService::OnRefreshTokenUpdatedForAccount(
void ChromeCryptAuthService::PerformEnrollmentAndDeviceSyncIfPossible() { void ChromeCryptAuthService::PerformEnrollmentAndDeviceSyncIfPossible() {
DCHECK(identity_manager_->HasPrimaryAccountWithRefreshToken()); 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."; PA_LOG(INFO) << "CryptAuth enrollment is disabled by enterprise policy.";
return; return;
} }
...@@ -228,15 +232,6 @@ void ChromeCryptAuthService::PerformEnrollmentAndDeviceSyncIfPossible() { ...@@ -228,15 +232,6 @@ void ChromeCryptAuthService::PerformEnrollmentAndDeviceSyncIfPossible() {
enrollment_manager_->Start(); 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() { void ChromeCryptAuthService::OnPrefsChanged() {
// Note: We only start the CryptAuth services if a feature was toggled on. In // 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 // the inverse case, we simply leave the services running until the user logs
......
...@@ -68,7 +68,6 @@ class ChromeCryptAuthService ...@@ -68,7 +68,6 @@ class ChromeCryptAuthService
void OnAuthenticationStateChanged(); void OnAuthenticationStateChanged();
void PerformEnrollmentAndDeviceSyncIfPossible(); void PerformEnrollmentAndDeviceSyncIfPossible();
bool IsEnrollmentAllowedByPolicy();
void OnPrefsChanged(); void OnPrefsChanged();
std::unique_ptr<cryptauth::CryptAuthClientFactory> client_factory_; std::unique_ptr<cryptauth::CryptAuthClientFactory> client_factory_;
......
...@@ -24,13 +24,12 @@ namespace device_sync { ...@@ -24,13 +24,12 @@ namespace device_sync {
namespace { 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) { bool IsEnrollmentAllowedByPolicy(content::BrowserContext* context) {
// We allow CryptAuth enrollments if at least one of the features which return multidevice_setup::AreAnyMultiDeviceFeaturesAllowed(
// depends on CryptAuth is enabled by enterprise policy. Profile::FromBrowserContext(context)->GetPrefs());
PrefService* pref_service = Profile::FromBrowserContext(context)->GetPrefs();
return pref_service->GetBoolean(prefs::kEasyUnlockAllowed) ||
pref_service->GetBoolean(
multidevice_setup::kInstantTetheringFeatureAllowedPrefName);
} }
} // namespace } // namespace
......
...@@ -175,10 +175,9 @@ TetherService::TetherService( ...@@ -175,10 +175,9 @@ TetherService::TetherService(
} }
registrar_.Init(profile_->GetPrefs()); registrar_.Init(profile_->GetPrefs());
registrar_.Add( registrar_.Add(chromeos::multidevice_setup::kInstantTetheringAllowedPrefName,
chromeos::multidevice_setup::kInstantTetheringFeatureAllowedPrefName, base::BindRepeating(&TetherService::OnPrefsChanged,
base::BindRepeating(&TetherService::OnPrefsChanged, weak_ptr_factory_.GetWeakPtr()));
weak_ptr_factory_.GetWeakPtr()));
UMA_HISTOGRAM_BOOLEAN("InstantTethering.UserPreference.OnStartup", UMA_HISTOGRAM_BOOLEAN("InstantTethering.UserPreference.OnStartup",
IsEnabledByPreference()); IsEnabledByPreference());
...@@ -394,7 +393,7 @@ void TetherService::UpdateEnabledState() { ...@@ -394,7 +393,7 @@ void TetherService::UpdateEnabledState() {
if (is_enabled != was_pref_enabled) { if (is_enabled != was_pref_enabled) {
profile_->GetPrefs()->SetBoolean( profile_->GetPrefs()->SetBoolean(
chromeos::multidevice_setup::kInstantTetheringFeatureEnabledPrefName, chromeos::multidevice_setup::kInstantTetheringEnabledPrefName,
is_enabled); is_enabled);
UMA_HISTOGRAM_BOOLEAN("InstantTethering.UserPreference.OnToggle", UMA_HISTOGRAM_BOOLEAN("InstantTethering.UserPreference.OnToggle",
is_enabled); is_enabled);
...@@ -611,12 +610,12 @@ bool TetherService::IsCellularAvailableButNotEnabled() const { ...@@ -611,12 +610,12 @@ bool TetherService::IsCellularAvailableButNotEnabled() const {
bool TetherService::IsAllowedByPolicy() const { bool TetherService::IsAllowedByPolicy() const {
return profile_->GetPrefs()->GetBoolean( return profile_->GetPrefs()->GetBoolean(
chromeos::multidevice_setup::kInstantTetheringFeatureAllowedPrefName); chromeos::multidevice_setup::kInstantTetheringAllowedPrefName);
} }
bool TetherService::IsEnabledByPreference() const { bool TetherService::IsEnabledByPreference() const {
return profile_->GetPrefs()->GetBoolean( return profile_->GetPrefs()->GetBoolean(
chromeos::multidevice_setup::kInstantTetheringFeatureEnabledPrefName); chromeos::multidevice_setup::kInstantTetheringEnabledPrefName);
} }
TetherService::TetherFeatureState TetherService::GetTetherFeatureState() { TetherService::TetherFeatureState TetherService::GetTetherFeatureState() {
......
...@@ -994,8 +994,7 @@ TEST_F(TetherServiceTest, TestNoTetherHosts) { ...@@ -994,8 +994,7 @@ TEST_F(TetherServiceTest, TestNoTetherHosts) {
TEST_F(TetherServiceTest, TestProhibitedByPolicy) { TEST_F(TetherServiceTest, TestProhibitedByPolicy) {
profile_->GetPrefs()->SetBoolean( profile_->GetPrefs()->SetBoolean(
chromeos::multidevice_setup::kInstantTetheringFeatureAllowedPrefName, chromeos::multidevice_setup::kInstantTetheringAllowedPrefName, false);
false);
CreateTetherService(); CreateTetherService();
...@@ -1207,8 +1206,7 @@ TEST_F(TetherServiceTest, TestCellularIsAvailable) { ...@@ -1207,8 +1206,7 @@ TEST_F(TetherServiceTest, TestCellularIsAvailable) {
TEST_F(TetherServiceTest, TestDisabled) { TEST_F(TetherServiceTest, TestDisabled) {
profile_->GetPrefs()->SetBoolean( profile_->GetPrefs()->SetBoolean(
chromeos::multidevice_setup::kInstantTetheringFeatureEnabledPrefName, chromeos::multidevice_setup::kInstantTetheringEnabledPrefName, false);
false);
CreateTetherService(); CreateTetherService();
...@@ -1217,7 +1215,7 @@ TEST_F(TetherServiceTest, TestDisabled) { ...@@ -1217,7 +1215,7 @@ TEST_F(TetherServiceTest, TestDisabled) {
network_state_handler()->GetTechnologyState( network_state_handler()->GetTechnologyState(
chromeos::NetworkTypePattern::Tether())); chromeos::NetworkTypePattern::Tether()));
EXPECT_FALSE(profile_->GetPrefs()->GetBoolean( EXPECT_FALSE(profile_->GetPrefs()->GetBoolean(
chromeos::multidevice_setup::kInstantTetheringFeatureEnabledPrefName)); chromeos::multidevice_setup::kInstantTetheringEnabledPrefName));
VerifyTetherActiveStatus(false /* expected_active */); VerifyTetherActiveStatus(false /* expected_active */);
VerifyTetherFeatureStateRecorded( VerifyTetherFeatureStateRecorded(
...@@ -1239,7 +1237,7 @@ TEST_F(TetherServiceTest, TestEnabled) { ...@@ -1239,7 +1237,7 @@ TEST_F(TetherServiceTest, TestEnabled) {
network_state_handler()->GetTechnologyState( network_state_handler()->GetTechnologyState(
chromeos::NetworkTypePattern::Tether())); chromeos::NetworkTypePattern::Tether()));
EXPECT_FALSE(profile_->GetPrefs()->GetBoolean( EXPECT_FALSE(profile_->GetPrefs()->GetBoolean(
chromeos::multidevice_setup::kInstantTetheringFeatureEnabledPrefName)); chromeos::multidevice_setup::kInstantTetheringEnabledPrefName));
VerifyTetherActiveStatus(false /* expected_active */); VerifyTetherActiveStatus(false /* expected_active */);
histogram_tester_.ExpectBucketCount( histogram_tester_.ExpectBucketCount(
"InstantTethering.UserPreference.OnToggle", false, "InstantTethering.UserPreference.OnToggle", false,
...@@ -1250,7 +1248,7 @@ TEST_F(TetherServiceTest, TestEnabled) { ...@@ -1250,7 +1248,7 @@ TEST_F(TetherServiceTest, TestEnabled) {
network_state_handler()->GetTechnologyState( network_state_handler()->GetTechnologyState(
chromeos::NetworkTypePattern::Tether())); chromeos::NetworkTypePattern::Tether()));
EXPECT_TRUE(profile_->GetPrefs()->GetBoolean( EXPECT_TRUE(profile_->GetPrefs()->GetBoolean(
chromeos::multidevice_setup::kInstantTetheringFeatureEnabledPrefName)); chromeos::multidevice_setup::kInstantTetheringEnabledPrefName));
VerifyTetherActiveStatus(true /* expected_active */); VerifyTetherActiveStatus(true /* expected_active */);
histogram_tester_.ExpectBucketCount( histogram_tester_.ExpectBucketCount(
"InstantTethering.UserPreference.OnToggle", true, "InstantTethering.UserPreference.OnToggle", true,
......
...@@ -1001,7 +1001,6 @@ jumbo_static_library("extensions") { ...@@ -1001,7 +1001,6 @@ jumbo_static_library("extensions") {
"//ash/public/cpp", "//ash/public/cpp",
"//chromeos/components/proximity_auth", "//chromeos/components/proximity_auth",
"//chromeos/components/proximity_auth/logging", "//chromeos/components/proximity_auth/logging",
"//chromeos/services/multidevice_setup/public/cpp:prefs",
"//components/arc", "//components/arc",
"//components/chrome_apps", "//components/chrome_apps",
"//components/constrained_window", "//components/constrained_window",
......
...@@ -51,7 +51,6 @@ ...@@ -51,7 +51,6 @@
#include "chrome/browser/chromeos/system/timezone_util.h" #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_method_short.h"
#include "chrome/browser/extensions/api/settings_private/chromeos_resolve_time_zone_by_geolocation_on_off.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 "chromeos/settings/cros_settings_names.h"
#include "components/arc/arc_prefs.h" #include "components/arc/arc_prefs.h"
#include "ui/chromeos/events/pref_names.h" #include "ui/chromeos/events/pref_names.h"
...@@ -487,13 +486,6 @@ const PrefsUtil::TypedPrefMap& PrefsUtil::GetWhitelistedKeys() { ...@@ -487,13 +486,6 @@ const PrefsUtil::TypedPrefMap& PrefsUtil::GetWhitelistedKeys() {
(*s_whitelist)[::prefs::kLanguageXkbAutoRepeatInterval] = (*s_whitelist)[::prefs::kLanguageXkbAutoRepeatInterval] =
settings_api::PrefType::PREF_TYPE_NUMBER; 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. // Native Printing settings.
(*s_whitelist)[::prefs::kUserNativePrintersAllowed] = (*s_whitelist)[::prefs::kUserNativePrintersAllowed] =
settings_api::PrefType::PREF_TYPE_BOOLEAN; settings_api::PrefType::PREF_TYPE_BOOLEAN;
......
...@@ -606,10 +606,10 @@ const PolicyToPreferenceMapEntry kSimplePolicyMap[] = { ...@@ -606,10 +606,10 @@ const PolicyToPreferenceMapEntry kSimplePolicyMap[] = {
prefs::kTouchVirtualKeyboardEnabled, prefs::kTouchVirtualKeyboardEnabled,
base::Value::Type::BOOLEAN }, base::Value::Type::BOOLEAN },
{ key::kEasyUnlockAllowed, { key::kEasyUnlockAllowed,
prefs::kEasyUnlockAllowed, chromeos::multidevice_setup::kSmartLockAllowedPrefName,
base::Value::Type::BOOLEAN }, base::Value::Type::BOOLEAN },
{ key::kInstantTetheringAllowed, { key::kInstantTetheringAllowed,
chromeos::multidevice_setup::kInstantTetheringFeatureAllowedPrefName, chromeos::multidevice_setup::kInstantTetheringAllowedPrefName,
base::Value::Type::BOOLEAN }, base::Value::Type::BOOLEAN },
{ key::kCaptivePortalAuthenticationIgnoresProxy, { key::kCaptivePortalAuthenticationIgnoresProxy,
prefs::kCaptivePortalAuthenticationIgnoresProxy, prefs::kCaptivePortalAuthenticationIgnoresProxy,
......
...@@ -55,6 +55,10 @@ static_library("proximity_auth") { ...@@ -55,6 +55,10 @@ static_library("proximity_auth") {
"//chromeos", "//chromeos",
"//chromeos/components/proximity_auth/logging", "//chromeos/components/proximity_auth/logging",
"//chromeos/components/proximity_auth/public/interfaces", "//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/cpp/client",
"//chromeos/services/secure_channel/public/mojom", "//chromeos/services/secure_channel/public/mojom",
"//components/account_id", "//components/account_id",
...@@ -116,6 +120,10 @@ source_set("unit_tests") { ...@@ -116,6 +120,10 @@ source_set("unit_tests") {
"//chromeos", "//chromeos",
"//chromeos/components/proximity_auth/logging", "//chromeos/components/proximity_auth/logging",
"//chromeos/components/proximity_auth/logging:unit_tests", "//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", "//chromeos/services/secure_channel/public/cpp/client:test_support",
"//components/cryptauth:test_support", "//components/cryptauth:test_support",
"//components/prefs:test_support", "//components/prefs:test_support",
......
...@@ -12,6 +12,7 @@ ...@@ -12,6 +12,7 @@
#include "base/values.h" #include "base/values.h"
#include "chromeos/components/proximity_auth/logging/logging.h" #include "chromeos/components/proximity_auth/logging/logging.h"
#include "chromeos/components/proximity_auth/proximity_auth_pref_names.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_registry_simple.h"
#include "components/prefs/pref_service.h" #include "components/prefs/pref_service.h"
#include "components/prefs/scoped_user_pref_update.h" #include "components/prefs/scoped_user_pref_update.h"
...@@ -74,7 +75,8 @@ bool ProximityAuthLocalStatePrefManager::IsEasyUnlockAllowed() const { ...@@ -74,7 +75,8 @@ bool ProximityAuthLocalStatePrefManager::IsEasyUnlockAllowed() const {
bool pref_value; bool pref_value;
const base::DictionaryValue* user_prefs = GetActiveUserPrefsDictionary(); const base::DictionaryValue* user_prefs = GetActiveUserPrefsDictionary();
if (!user_prefs || !user_prefs->GetBooleanWithoutPathExpansion( if (!user_prefs || !user_prefs->GetBooleanWithoutPathExpansion(
prefs::kEasyUnlockAllowed, &pref_value)) { chromeos::multidevice_setup::kSmartLockAllowedPrefName,
&pref_value)) {
PA_LOG(ERROR) << "Failed to get easyunlock_allowed."; PA_LOG(ERROR) << "Failed to get easyunlock_allowed.";
return true; return true;
} }
...@@ -85,7 +87,8 @@ bool ProximityAuthLocalStatePrefManager::IsEasyUnlockEnabled() const { ...@@ -85,7 +87,8 @@ bool ProximityAuthLocalStatePrefManager::IsEasyUnlockEnabled() const {
bool pref_value; bool pref_value;
const base::DictionaryValue* user_prefs = GetActiveUserPrefsDictionary(); const base::DictionaryValue* user_prefs = GetActiveUserPrefsDictionary();
if (!user_prefs || !user_prefs->GetBooleanWithoutPathExpansion( if (!user_prefs || !user_prefs->GetBooleanWithoutPathExpansion(
prefs::kEasyUnlockEnabled, &pref_value)) { chromeos::multidevice_setup::kSmartLockEnabledPrefName,
&pref_value)) {
PA_LOG(ERROR) << "Failed to get easyunlock_enabled."; PA_LOG(ERROR) << "Failed to get easyunlock_enabled.";
return false; return false;
} }
......
...@@ -11,6 +11,7 @@ ...@@ -11,6 +11,7 @@
#include "base/json/json_reader.h" #include "base/json/json_reader.h"
#include "base/macros.h" #include "base/macros.h"
#include "chromeos/components/proximity_auth/proximity_auth_pref_names.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/scoped_user_pref_update.h"
#include "components/prefs/testing_pref_service.h" #include "components/prefs/testing_pref_service.h"
#include "testing/gmock/include/gmock/gmock.h" #include "testing/gmock/include/gmock/gmock.h"
...@@ -63,9 +64,9 @@ class ProximityAuthLocalStatePrefManagerTest : public testing::Test { ...@@ -63,9 +64,9 @@ class ProximityAuthLocalStatePrefManagerTest : public testing::Test {
user1_prefs->SetKey( user1_prefs->SetKey(
proximity_auth::prefs::kProximityAuthIsChromeOSLoginEnabled, proximity_auth::prefs::kProximityAuthIsChromeOSLoginEnabled,
base::Value(kIsChromeOSLoginEnabled1)); base::Value(kIsChromeOSLoginEnabled1));
user1_prefs->SetKey(proximity_auth::prefs::kEasyUnlockAllowed, user1_prefs->SetKey(chromeos::multidevice_setup::kSmartLockAllowedPrefName,
base::Value(kIsEasyUnlockAllowed1)); base::Value(kIsEasyUnlockAllowed1));
user1_prefs->SetKey(proximity_auth::prefs::kEasyUnlockEnabled, user1_prefs->SetKey(chromeos::multidevice_setup::kSmartLockEnabledPrefName,
base::Value(kIsEasyUnlockEnabled1)); base::Value(kIsEasyUnlockEnabled1));
DictionaryPrefUpdate update1(&local_state_, DictionaryPrefUpdate update1(&local_state_,
prefs::kEasyUnlockLocalStateUserPrefs); prefs::kEasyUnlockLocalStateUserPrefs);
...@@ -79,9 +80,9 @@ class ProximityAuthLocalStatePrefManagerTest : public testing::Test { ...@@ -79,9 +80,9 @@ class ProximityAuthLocalStatePrefManagerTest : public testing::Test {
user2_prefs->SetKey( user2_prefs->SetKey(
proximity_auth::prefs::kProximityAuthIsChromeOSLoginEnabled, proximity_auth::prefs::kProximityAuthIsChromeOSLoginEnabled,
base::Value(kIsChromeOSLoginEnabled2)); base::Value(kIsChromeOSLoginEnabled2));
user2_prefs->SetKey(proximity_auth::prefs::kEasyUnlockAllowed, user2_prefs->SetKey(chromeos::multidevice_setup::kSmartLockAllowedPrefName,
base::Value(kIsEasyUnlockAllowed2)); base::Value(kIsEasyUnlockAllowed2));
user2_prefs->SetKey(proximity_auth::prefs::kEasyUnlockEnabled, user2_prefs->SetKey(chromeos::multidevice_setup::kSmartLockEnabledPrefName,
base::Value(kIsEasyUnlockEnabled2)); base::Value(kIsEasyUnlockEnabled2));
DictionaryPrefUpdate update2(&local_state_, DictionaryPrefUpdate update2(&local_state_,
......
...@@ -7,14 +7,6 @@ ...@@ -7,14 +7,6 @@
namespace proximity_auth { namespace proximity_auth {
namespace prefs { 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., // Whether or not the state of EasyUnlock has actively been changed, e.g.,
// explicitly enabled by the user (through setup) or disabled via Settings. // explicitly enabled by the user (through setup) or disabled via Settings.
const char kEasyUnlockEnabledStateSet[] = "easy_unlock.enabled_state_set"; const char kEasyUnlockEnabledStateSet[] = "easy_unlock.enabled_state_set";
......
...@@ -8,8 +8,6 @@ ...@@ -8,8 +8,6 @@
namespace proximity_auth { namespace proximity_auth {
namespace prefs { namespace prefs {
extern const char kEasyUnlockAllowed[];
extern const char kEasyUnlockEnabled[];
extern const char kEasyUnlockEnabledStateSet[]; extern const char kEasyUnlockEnabledStateSet[];
extern const char kEasyUnlockProximityThreshold[]; extern const char kEasyUnlockProximityThreshold[];
extern const char kEasyUnlockLocalStateUserPrefs[]; extern const char kEasyUnlockLocalStateUserPrefs[];
......
...@@ -12,6 +12,7 @@ ...@@ -12,6 +12,7 @@
#include "base/values.h" #include "base/values.h"
#include "chromeos/components/proximity_auth/logging/logging.h" #include "chromeos/components/proximity_auth/logging/logging.h"
#include "chromeos/components/proximity_auth/proximity_auth_pref_names.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/pref_registry/pref_registry_syncable.h"
#include "components/prefs/pref_service.h" #include "components/prefs/pref_service.h"
#include "components/prefs/scoped_user_pref_update.h" #include "components/prefs/scoped_user_pref_update.h"
...@@ -29,8 +30,6 @@ ProximityAuthProfilePrefManager::~ProximityAuthProfilePrefManager() { ...@@ -29,8 +30,6 @@ ProximityAuthProfilePrefManager::~ProximityAuthProfilePrefManager() {
// static // static
void ProximityAuthProfilePrefManager::RegisterPrefs( void ProximityAuthProfilePrefManager::RegisterPrefs(
user_prefs::PrefRegistrySyncable* registry) { user_prefs::PrefRegistrySyncable* registry) {
registry->RegisterBooleanPref(prefs::kEasyUnlockAllowed, true);
registry->RegisterBooleanPref(prefs::kEasyUnlockEnabled, false);
registry->RegisterBooleanPref(prefs::kEasyUnlockEnabledStateSet, false); registry->RegisterBooleanPref(prefs::kEasyUnlockEnabledStateSet, false);
registry->RegisterInt64Pref( registry->RegisterInt64Pref(
prefs::kProximityAuthLastPromotionCheckTimestampMs, 0L); prefs::kProximityAuthLastPromotionCheckTimestampMs, 0L);
...@@ -60,8 +59,10 @@ void ProximityAuthProfilePrefManager::StartSyncingToLocalState( ...@@ -60,8 +59,10 @@ void ProximityAuthProfilePrefManager::StartSyncingToLocalState(
weak_ptr_factory_.GetWeakPtr()); weak_ptr_factory_.GetWeakPtr());
registrar_.Init(pref_service_); registrar_.Init(pref_service_);
registrar_.Add(prefs::kEasyUnlockAllowed, on_pref_changed_callback); registrar_.Add(chromeos::multidevice_setup::kSmartLockAllowedPrefName,
registrar_.Add(prefs::kEasyUnlockEnabled, on_pref_changed_callback); on_pref_changed_callback);
registrar_.Add(chromeos::multidevice_setup::kSmartLockEnabledPrefName,
on_pref_changed_callback);
registrar_.Add(proximity_auth::prefs::kEasyUnlockProximityThreshold, registrar_.Add(proximity_auth::prefs::kEasyUnlockProximityThreshold,
on_pref_changed_callback); on_pref_changed_callback);
registrar_.Add(proximity_auth::prefs::kProximityAuthIsChromeOSLoginEnabled, registrar_.Add(proximity_auth::prefs::kProximityAuthIsChromeOSLoginEnabled,
...@@ -74,10 +75,12 @@ void ProximityAuthProfilePrefManager::SyncPrefsToLocalState() { ...@@ -74,10 +75,12 @@ void ProximityAuthProfilePrefManager::SyncPrefsToLocalState() {
std::unique_ptr<base::DictionaryValue> user_prefs_dict( std::unique_ptr<base::DictionaryValue> user_prefs_dict(
new base::DictionaryValue()); new base::DictionaryValue());
user_prefs_dict->SetKey(prefs::kEasyUnlockAllowed, user_prefs_dict->SetKey(
base::Value(IsEasyUnlockAllowed())); chromeos::multidevice_setup::kSmartLockAllowedPrefName,
user_prefs_dict->SetKey(prefs::kEasyUnlockEnabled, base::Value(IsEasyUnlockAllowed()));
base::Value(IsEasyUnlockEnabled())); user_prefs_dict->SetKey(
chromeos::multidevice_setup::kSmartLockEnabledPrefName,
base::Value(IsEasyUnlockEnabled()));
user_prefs_dict->SetKey(prefs::kEasyUnlockProximityThreshold, user_prefs_dict->SetKey(prefs::kEasyUnlockProximityThreshold,
base::Value(GetProximityThreshold())); base::Value(GetProximityThreshold()));
user_prefs_dict->SetKey(prefs::kProximityAuthIsChromeOSLoginEnabled, user_prefs_dict->SetKey(prefs::kProximityAuthIsChromeOSLoginEnabled,
...@@ -90,16 +93,20 @@ void ProximityAuthProfilePrefManager::SyncPrefsToLocalState() { ...@@ -90,16 +93,20 @@ void ProximityAuthProfilePrefManager::SyncPrefsToLocalState() {
} }
bool ProximityAuthProfilePrefManager::IsEasyUnlockAllowed() const { bool ProximityAuthProfilePrefManager::IsEasyUnlockAllowed() const {
return pref_service_->GetBoolean(prefs::kEasyUnlockAllowed); return pref_service_->GetBoolean(
chromeos::multidevice_setup::kSmartLockAllowedPrefName);
} }
void ProximityAuthProfilePrefManager::SetIsEasyUnlockEnabled( void ProximityAuthProfilePrefManager::SetIsEasyUnlockEnabled(
bool is_easy_unlock_enabled) const { 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 { bool ProximityAuthProfilePrefManager::IsEasyUnlockEnabled() const {
return pref_service_->GetBoolean(prefs::kEasyUnlockEnabled); return pref_service_->GetBoolean(
chromeos::multidevice_setup::kSmartLockEnabledPrefName);
} }
void ProximityAuthProfilePrefManager::SetEasyUnlockEnabledStateSet() const { void ProximityAuthProfilePrefManager::SetEasyUnlockEnabledStateSet() const {
......
...@@ -12,6 +12,7 @@ ...@@ -12,6 +12,7 @@
#include "base/macros.h" #include "base/macros.h"
#include "chromeos/components/proximity_auth/proximity_auth_local_state_pref_manager.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/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/prefs/testing_pref_service.h"
#include "components/sync_preferences/testing_pref_service_syncable.h" #include "components/sync_preferences/testing_pref_service_syncable.h"
#include "testing/gmock/include/gmock/gmock.h" #include "testing/gmock/include/gmock/gmock.h"
...@@ -38,6 +39,7 @@ class ProximityAuthProfilePrefManagerTest : public testing::Test { ...@@ -38,6 +39,7 @@ class ProximityAuthProfilePrefManagerTest : public testing::Test {
void SetUp() override { void SetUp() override {
ProximityAuthProfilePrefManager::RegisterPrefs(pref_service_.registry()); ProximityAuthProfilePrefManager::RegisterPrefs(pref_service_.registry());
chromeos::multidevice_setup::RegisterFeaturePrefs(pref_service_.registry());
} }
sync_preferences::TestingPrefServiceSyncable pref_service_; sync_preferences::TestingPrefServiceSyncable pref_service_;
...@@ -51,13 +53,14 @@ TEST_F(ProximityAuthProfilePrefManagerTest, IsEasyUnlockAllowed) { ...@@ -51,13 +53,14 @@ TEST_F(ProximityAuthProfilePrefManagerTest, IsEasyUnlockAllowed) {
EXPECT_TRUE(pref_manager.IsEasyUnlockAllowed()); EXPECT_TRUE(pref_manager.IsEasyUnlockAllowed());
// Simulating setting kEasyUnlockAllowed pref through enterprise policy. // 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()); EXPECT_FALSE(pref_manager.IsEasyUnlockAllowed());
} }
TEST_F(ProximityAuthProfilePrefManagerTest, IsEasyUnlockEnabled) { TEST_F(ProximityAuthProfilePrefManagerTest, IsEasyUnlockEnabled) {
ProximityAuthProfilePrefManager pref_manager(&pref_service_); ProximityAuthProfilePrefManager pref_manager(&pref_service_);
EXPECT_FALSE(pref_manager.IsEasyUnlockEnabled()); EXPECT_TRUE(pref_manager.IsEasyUnlockEnabled());
pref_manager.SetIsEasyUnlockEnabled(true); pref_manager.SetIsEasyUnlockEnabled(true);
EXPECT_TRUE(pref_manager.IsEasyUnlockEnabled()); EXPECT_TRUE(pref_manager.IsEasyUnlockEnabled());
...@@ -135,7 +138,8 @@ TEST_F(ProximityAuthProfilePrefManagerTest, SyncsToLocalPrefOnChange) { ...@@ -135,7 +138,8 @@ TEST_F(ProximityAuthProfilePrefManagerTest, SyncsToLocalPrefOnChange) {
// Test changing the kEasyUnlockAllowed pref value directly (e.g. through // Test changing the kEasyUnlockAllowed pref value directly (e.g. through
// enterprise policy). // enterprise policy).
EXPECT_TRUE(local_pref_manager.IsEasyUnlockAllowed()); 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(profile_pref_manager.IsEasyUnlockAllowed());
EXPECT_FALSE(local_pref_manager.IsEasyUnlockAllowed()); EXPECT_FALSE(local_pref_manager.IsEasyUnlockAllowed());
} }
......
...@@ -21,29 +21,21 @@ namespace multidevice_setup { ...@@ -21,29 +21,21 @@ namespace multidevice_setup {
namespace { 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> base::flat_map<mojom::Feature, std::string>
GenerateFeatureToEnabledPrefNameMap() { GenerateFeatureToEnabledPrefNameMap() {
return base::flat_map<mojom::Feature, std::string>{ return base::flat_map<mojom::Feature, std::string>{
{mojom::Feature::kBetterTogetherSuite, kSuiteEnabledPrefName}, {mojom::Feature::kBetterTogetherSuite,
{mojom::Feature::kInstantTethering, kBetterTogetherSuiteEnabledPrefName},
kInstantTetheringFeatureEnabledPrefName}, {mojom::Feature::kInstantTethering, kInstantTetheringEnabledPrefName},
{mojom::Feature::kMessages, kAndroidMessagesFeatureEnabledPrefName}, {mojom::Feature::kMessages, kMessagesEnabledPrefName},
{mojom::Feature::kSmartLock, kSmartLockFeatureEnabledPrefName}}; {mojom::Feature::kSmartLock, kSmartLockEnabledPrefName}};
} }
base::flat_map<mojom::Feature, std::string> base::flat_map<mojom::Feature, std::string>
GenerateFeatureToAllowedPrefNameMap() { GenerateFeatureToAllowedPrefNameMap() {
return base::flat_map<mojom::Feature, std::string>{ return base::flat_map<mojom::Feature, std::string>{
{mojom::Feature::kInstantTethering, {mojom::Feature::kInstantTethering, kInstantTetheringAllowedPrefName},
kInstantTetheringFeatureAllowedPrefName}, {mojom::Feature::kSmartLock, kSmartLockAllowedPrefName}};
{mojom::Feature::kSmartLock, kSmartLockFeatureAllowedPrefName}};
} }
// Each feature's default value is kUnavailableNoVerifiedHost until proven // Each feature's default value is kUnavailableNoVerifiedHost until proven
......
...@@ -22,12 +22,6 @@ namespace multidevice_setup { ...@@ -22,12 +22,6 @@ namespace multidevice_setup {
namespace { 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 CreateTestHostDevice() {
cryptauth::RemoteDeviceRef host_device = cryptauth::RemoteDeviceRef host_device =
cryptauth::CreateRemoteDeviceRefForTest(); cryptauth::CreateRemoteDeviceRefForTest();
...@@ -63,10 +57,6 @@ class MultiDeviceSetupFeatureStateManagerImplTest : public testing::Test { ...@@ -63,10 +57,6 @@ class MultiDeviceSetupFeatureStateManagerImplTest : public testing::Test {
std::make_unique<sync_preferences::TestingPrefServiceSyncable>(); std::make_unique<sync_preferences::TestingPrefServiceSyncable>();
user_prefs::PrefRegistrySyncable* registry = test_pref_service_->registry(); user_prefs::PrefRegistrySyncable* registry = test_pref_service_->registry();
RegisterFeaturePrefs(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>(); fake_host_status_provider_ = std::make_unique<FakeHostStatusProvider>();
...@@ -210,7 +200,7 @@ TEST_F(MultiDeviceSetupFeatureStateManagerImplTest, BetterTogetherSuite) { ...@@ -210,7 +200,7 @@ TEST_F(MultiDeviceSetupFeatureStateManagerImplTest, BetterTogetherSuite) {
mojom::Feature::kBetterTogetherSuite, mojom::Feature::kBetterTogetherSuite,
mojom::FeatureState::kEnabledByUser); mojom::FeatureState::kEnabledByUser);
test_pref_service()->SetBoolean(kSuiteEnabledPrefName, false); test_pref_service()->SetBoolean(kBetterTogetherSuiteEnabledPrefName, false);
EXPECT_EQ( EXPECT_EQ(
mojom::FeatureState::kDisabledByUser, mojom::FeatureState::kDisabledByUser,
manager()->GetFeatureStates()[mojom::Feature::kBetterTogetherSuite]); manager()->GetFeatureStates()[mojom::Feature::kBetterTogetherSuite]);
...@@ -245,16 +235,14 @@ TEST_F(MultiDeviceSetupFeatureStateManagerImplTest, InstantTethering) { ...@@ -245,16 +235,14 @@ TEST_F(MultiDeviceSetupFeatureStateManagerImplTest, InstantTethering) {
mojom::Feature::kInstantTethering, mojom::Feature::kInstantTethering,
mojom::FeatureState::kEnabledByUser); mojom::FeatureState::kEnabledByUser);
test_pref_service()->SetBoolean(kInstantTetheringFeatureEnabledPrefName, test_pref_service()->SetBoolean(kInstantTetheringEnabledPrefName, false);
false);
EXPECT_EQ(mojom::FeatureState::kDisabledByUser, EXPECT_EQ(mojom::FeatureState::kDisabledByUser,
manager()->GetFeatureStates()[mojom::Feature::kInstantTethering]); manager()->GetFeatureStates()[mojom::Feature::kInstantTethering]);
VerifyFeatureStateChange(3u /* expected_index */, VerifyFeatureStateChange(3u /* expected_index */,
mojom::Feature::kInstantTethering, mojom::Feature::kInstantTethering,
mojom::FeatureState::kDisabledByUser); mojom::FeatureState::kDisabledByUser);
test_pref_service()->SetBoolean(kInstantTetheringFeatureAllowedPrefName, test_pref_service()->SetBoolean(kInstantTetheringAllowedPrefName, false);
false);
EXPECT_EQ(mojom::FeatureState::kDisabledByPolicy, EXPECT_EQ(mojom::FeatureState::kDisabledByPolicy,
manager()->GetFeatureStates()[mojom::Feature::kInstantTethering]); manager()->GetFeatureStates()[mojom::Feature::kInstantTethering]);
VerifyFeatureStateChange(4u /* expected_index */, VerifyFeatureStateChange(4u /* expected_index */,
...@@ -285,8 +273,7 @@ TEST_F(MultiDeviceSetupFeatureStateManagerImplTest, Messages) { ...@@ -285,8 +273,7 @@ TEST_F(MultiDeviceSetupFeatureStateManagerImplTest, Messages) {
VerifyFeatureStateChange(2u /* expected_index */, mojom::Feature::kMessages, VerifyFeatureStateChange(2u /* expected_index */, mojom::Feature::kMessages,
mojom::FeatureState::kEnabledByUser); mojom::FeatureState::kEnabledByUser);
test_pref_service()->SetBoolean(kAndroidMessagesFeatureEnabledPrefName, test_pref_service()->SetBoolean(kMessagesEnabledPrefName, false);
false);
EXPECT_EQ(mojom::FeatureState::kDisabledByUser, EXPECT_EQ(mojom::FeatureState::kDisabledByUser,
manager()->GetFeatureStates()[mojom::Feature::kMessages]); manager()->GetFeatureStates()[mojom::Feature::kMessages]);
VerifyFeatureStateChange(3u /* expected_index */, mojom::Feature::kMessages, VerifyFeatureStateChange(3u /* expected_index */, mojom::Feature::kMessages,
...@@ -317,13 +304,13 @@ TEST_F(MultiDeviceSetupFeatureStateManagerImplTest, SmartLock) { ...@@ -317,13 +304,13 @@ TEST_F(MultiDeviceSetupFeatureStateManagerImplTest, SmartLock) {
VerifyFeatureStateChange(2u /* expected_index */, mojom::Feature::kSmartLock, VerifyFeatureStateChange(2u /* expected_index */, mojom::Feature::kSmartLock,
mojom::FeatureState::kEnabledByUser); mojom::FeatureState::kEnabledByUser);
test_pref_service()->SetBoolean(kSmartLockFeatureEnabledPrefName, false); test_pref_service()->SetBoolean(kSmartLockEnabledPrefName, false);
EXPECT_EQ(mojom::FeatureState::kDisabledByUser, EXPECT_EQ(mojom::FeatureState::kDisabledByUser,
manager()->GetFeatureStates()[mojom::Feature::kSmartLock]); manager()->GetFeatureStates()[mojom::Feature::kSmartLock]);
VerifyFeatureStateChange(3u /* expected_index */, mojom::Feature::kSmartLock, VerifyFeatureStateChange(3u /* expected_index */, mojom::Feature::kSmartLock,
mojom::FeatureState::kDisabledByUser); mojom::FeatureState::kDisabledByUser);
test_pref_service()->SetBoolean(kSmartLockFeatureAllowedPrefName, false); test_pref_service()->SetBoolean(kSmartLockAllowedPrefName, false);
EXPECT_EQ(mojom::FeatureState::kDisabledByPolicy, EXPECT_EQ(mojom::FeatureState::kDisabledByPolicy,
manager()->GetFeatureStates()[mojom::Feature::kSmartLock]); manager()->GetFeatureStates()[mojom::Feature::kSmartLock]);
VerifyFeatureStateChange(4u /* expected_index */, mojom::Feature::kSmartLock, VerifyFeatureStateChange(4u /* expected_index */, mojom::Feature::kSmartLock,
......
...@@ -5,41 +5,41 @@ ...@@ -5,41 +5,41 @@
#include "chromeos/services/multidevice_setup/public/cpp/prefs.h" #include "chromeos/services/multidevice_setup/public/cpp/prefs.h"
#include "components/prefs/pref_registry_simple.h" #include "components/prefs/pref_registry_simple.h"
#include "components/prefs/pref_service.h"
namespace chromeos { namespace chromeos {
namespace multidevice_setup { namespace multidevice_setup {
// Note that the pref names have slightly inconsistent naming conventions // Note: Pref name strings follow an inconsistent naming convention because some
// because some were named before the unified MultiDeviceSetup project and we // of them were created before the MultiDeviceSetup project.
// 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";
// This pref is a gatekeeper for all MultiDevice features (e.g. Easy Unlock, // "Allowed by user policy" preferences:
// Instant Tethering). Setting the pref to 'true' is necessary but not const char kInstantTetheringAllowedPrefName[] = "tether.allowed";
// sufficient to enable the individual features, which are each controlled by const char kSmartLockAllowedPrefName[] = "easy_unlock.allowed";
// their own pref and may involve additional setup steps.
const char kSuiteEnabledPrefName[] = "multidevice_setup.suite_enabled";
// Individual feature prefs. // "Enabled by user" preferences:
const char kAndroidMessagesFeatureEnabledPrefName[] = const char kBetterTogetherSuiteEnabledPrefName[] =
"multidevice.sms_connect_enabled"; "multidevice_setup.suite_enabled";
const char kInstantTetheringEnabledPrefName[] = "tether.enabled";
// Whether Instant Tethering is allowed by policy. const char kMessagesEnabledPrefName[] = "multidevice.sms_connect_enabled";
const char kInstantTetheringFeatureAllowedPrefName[] = "tether.allowed"; const char kSmartLockEnabledPrefName[] = "easy_unlock.enabled";
// 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";
void RegisterFeaturePrefs(PrefRegistrySimple* registry) { void RegisterFeaturePrefs(PrefRegistrySimple* registry) {
registry->RegisterBooleanPref(kSuiteEnabledPrefName, true); registry->RegisterBooleanPref(kInstantTetheringAllowedPrefName, true);
registry->RegisterBooleanPref(kAndroidMessagesFeatureEnabledPrefName, true); // TODO(khorimoto): Register "messages allowed" preference.
registry->RegisterBooleanPref(kInstantTetheringFeatureAllowedPrefName, true); registry->RegisterBooleanPref(kSmartLockAllowedPrefName, true);
registry->RegisterBooleanPref(kInstantTetheringFeatureEnabledPrefName, 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 } // namespace multidevice_setup
......
...@@ -6,17 +6,29 @@ ...@@ -6,17 +6,29 @@
#define CHROMEOS_SERVICES_MULTIDEVICE_SETUP_PUBLIC_CPP_PREFS_H_ #define CHROMEOS_SERVICES_MULTIDEVICE_SETUP_PUBLIC_CPP_PREFS_H_
class PrefRegistrySimple; class PrefRegistrySimple;
class PrefService;
namespace chromeos { namespace chromeos {
namespace multidevice_setup { namespace multidevice_setup {
extern const char kSuiteEnabledPrefName[]; // Preferences which represent whether features are allowed by user policy. A
extern const char kAndroidMessagesFeatureEnabledPrefName[]; // "false" value means that the administrator has prohibited the feature and
extern const char kInstantTetheringFeatureAllowedPrefName[]; // that users do not have the option of attempting to enable the feature.
extern const char kInstantTetheringFeatureEnabledPrefName[]; 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); void RegisterFeaturePrefs(PrefRegistrySimple* registry);
bool AreAnyMultiDeviceFeaturesAllowed(PrefService* pref_service);
} // namespace multidevice_setup } // 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