Commit fb1b9c65 authored by Aya ElAttar's avatar Aya ElAttar Committed by Commit Bot

Disabled settings icon via SystemFeaturesDisableList

Disabled the settings icon in the system tray when os settings is added
in SystemFeaturesDisableList policy

Bug: 1066795
Change-Id: I6131e5cb05b0e305f0d9007391d7cd5c1231adf8
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2130855Reviewed-by: default avatarTim Song <tengs@chromium.org>
Reviewed-by: default avatarAhmed Fakhry <afakhry@chromium.org>
Reviewed-by: default avatarSergey Poromov <poromov@chromium.org>
Commit-Queue: Aya Elsayed <ayaelattar@google.com>
Cr-Commit-Position: refs/heads/master@{#758769}
parent ea4521ce
...@@ -27,6 +27,7 @@ ...@@ -27,6 +27,7 @@
#include "ash/system/palette/palette_welcome_bubble.h" #include "ash/system/palette/palette_welcome_bubble.h"
#include "ash/system/power/power_prefs.h" #include "ash/system/power/power_prefs.h"
#include "ash/system/session/logout_button_tray.h" #include "ash/system/session/logout_button_tray.h"
#include "ash/system/unified/top_shortcuts_view.h"
#include "ash/touch/touch_devices_controller.h" #include "ash/touch/touch_devices_controller.h"
#include "ash/wallpaper/wallpaper_controller_impl.h" #include "ash/wallpaper/wallpaper_controller_impl.h"
#include "ash/wm/desks/desks_restore_util.h" #include "ash/wm/desks/desks_restore_util.h"
...@@ -79,6 +80,7 @@ void RegisterLocalStatePrefs(PrefRegistrySimple* registry, bool for_test) { ...@@ -79,6 +80,7 @@ void RegisterLocalStatePrefs(PrefRegistrySimple* registry, bool for_test) {
DetachableBaseHandler::RegisterPrefs(registry); DetachableBaseHandler::RegisterPrefs(registry);
PowerPrefs::RegisterLocalStatePrefs(registry); PowerPrefs::RegisterLocalStatePrefs(registry);
DisplayPrefs::RegisterLocalStatePrefs(registry); DisplayPrefs::RegisterLocalStatePrefs(registry);
TopShortcutsView::RegisterLocalStatePrefs(registry);
} }
void RegisterSigninProfilePrefs(PrefRegistrySimple* registry, bool for_test) { void RegisterSigninProfilePrefs(PrefRegistrySimple* registry, bool for_test) {
......
...@@ -370,6 +370,10 @@ const char kPowerSmartDimEnabled[] = "power.smart_dim_enabled"; ...@@ -370,6 +370,10 @@ const char kPowerSmartDimEnabled[] = "power.smart_dim_enabled";
// Boolean controlling whether ALS logging is enabled. // Boolean controlling whether ALS logging is enabled.
const char kPowerAlsLoggingEnabled[] = "power.als_logging_enabled"; const char kPowerAlsLoggingEnabled[] = "power.als_logging_enabled";
// Boolean controlling whether the settings is enabled. This pref is intended to
// be set only by policy not by user.
const char kOsSettingsEnabled[] = "os_settings_enabled";
// |kShelfAlignment| and |kShelfAutoHideBehavior| have a local variant. The // |kShelfAlignment| and |kShelfAutoHideBehavior| have a local variant. The
// local variant is not synced and is used if set. If the local variant is not // local variant is not synced and is used if set. If the local variant is not
// set its value is set from the synced value (once prefs have been // set its value is set from the synced value (once prefs have been
......
...@@ -103,6 +103,8 @@ ASH_PUBLIC_EXPORT extern const char kNightLightCachedLatitude[]; ...@@ -103,6 +103,8 @@ ASH_PUBLIC_EXPORT extern const char kNightLightCachedLatitude[];
ASH_PUBLIC_EXPORT extern const char kNightLightCachedLongitude[]; ASH_PUBLIC_EXPORT extern const char kNightLightCachedLongitude[];
ASH_PUBLIC_EXPORT extern const char kAutoNightLightNotificationDismissed[]; ASH_PUBLIC_EXPORT extern const char kAutoNightLightNotificationDismissed[];
ASH_PUBLIC_EXPORT extern const char kOsSettingsEnabled[];
ASH_PUBLIC_EXPORT extern const char kAllowScreenLock[]; ASH_PUBLIC_EXPORT extern const char kAllowScreenLock[];
ASH_PUBLIC_EXPORT extern const char kEnableAutoScreenLock[]; ASH_PUBLIC_EXPORT extern const char kEnableAutoScreenLock[];
ASH_PUBLIC_EXPORT extern const char kPowerAcScreenBrightnessPercent[]; ASH_PUBLIC_EXPORT extern const char kPowerAcScreenBrightnessPercent[];
......
...@@ -7,6 +7,7 @@ ...@@ -7,6 +7,7 @@
#include <numeric> #include <numeric>
#include "ash/accessibility/accessibility_controller_impl.h" #include "ash/accessibility/accessibility_controller_impl.h"
#include "ash/public/cpp/ash_pref_names.h"
#include "ash/public/cpp/ash_view_ids.h" #include "ash/public/cpp/ash_view_ids.h"
#include "ash/resources/vector_icons/vector_icons.h" #include "ash/resources/vector_icons/vector_icons.h"
#include "ash/session/session_controller_impl.h" #include "ash/session/session_controller_impl.h"
...@@ -23,7 +24,10 @@ ...@@ -23,7 +24,10 @@
#include "ash/system/unified/user_chooser_detailed_view_controller.h" #include "ash/system/unified/user_chooser_detailed_view_controller.h"
#include "ash/system/unified/user_chooser_view.h" #include "ash/system/unified/user_chooser_view.h"
#include "base/numerics/ranges.h" #include "base/numerics/ranges.h"
#include "components/prefs/pref_registry_simple.h"
#include "components/prefs/pref_service.h"
#include "ui/gfx/paint_vector_icon.h" #include "ui/gfx/paint_vector_icon.h"
#include "ui/views/controls/button/button.h"
#include "ui/views/controls/highlight_path_generator.h" #include "ui/views/controls/highlight_path_generator.h"
#include "ui/views/layout/box_layout.h" #include "ui/views/layout/box_layout.h"
#include "ui/views/layout/fill_layout.h" #include "ui/views/layout/fill_layout.h"
...@@ -198,6 +202,12 @@ TopShortcutsView::TopShortcutsView(UnifiedSystemTrayController* controller) ...@@ -198,6 +202,12 @@ TopShortcutsView::TopShortcutsView(UnifiedSystemTrayController* controller)
settings_button_ = new TopShortcutButton(this, kUnifiedMenuSettingsIcon, settings_button_ = new TopShortcutButton(this, kUnifiedMenuSettingsIcon,
IDS_ASH_STATUS_TRAY_SETTINGS); IDS_ASH_STATUS_TRAY_SETTINGS);
container_->AddChildView(settings_button_); container_->AddChildView(settings_button_);
local_state_pref_change_registrar_.Init(Shell::Get()->local_state());
local_state_pref_change_registrar_.Add(
prefs::kOsSettingsEnabled,
base::BindRepeating(&TopShortcutsView::UpdateSettingsButtonState,
base::Unretained(this)));
UpdateSettingsButtonState();
} }
// |collapse_button_| should be right-aligned, so we make the buttons // |collapse_button_| should be right-aligned, so we make the buttons
...@@ -208,6 +218,11 @@ TopShortcutsView::TopShortcutsView(UnifiedSystemTrayController* controller) ...@@ -208,6 +218,11 @@ TopShortcutsView::TopShortcutsView(UnifiedSystemTrayController* controller)
AddChildView(collapse_button_); AddChildView(collapse_button_);
} }
// static
void TopShortcutsView::RegisterLocalStatePrefs(PrefRegistrySimple* registry) {
registry->RegisterBooleanPref(prefs::kOsSettingsEnabled, true);
}
void TopShortcutsView::SetExpandedAmount(double expanded_amount) { void TopShortcutsView::SetExpandedAmount(double expanded_amount) {
collapse_button_->SetExpandedAmount(expanded_amount); collapse_button_->SetExpandedAmount(expanded_amount);
} }
...@@ -232,4 +247,14 @@ const char* TopShortcutsView::GetClassName() const { ...@@ -232,4 +247,14 @@ const char* TopShortcutsView::GetClassName() const {
return "TopShortcutsView"; return "TopShortcutsView";
} }
void TopShortcutsView::UpdateSettingsButtonState() {
PrefService* const local_state = Shell::Get()->local_state();
const bool settings_icon_enabled =
local_state->GetBoolean(prefs::kOsSettingsEnabled);
settings_button_->SetState(settings_icon_enabled
? views::Button::STATE_NORMAL
: views::Button::STATE_DISABLED);
}
} // namespace ash } // namespace ash
...@@ -7,9 +7,12 @@ ...@@ -7,9 +7,12 @@
#include "ash/accessibility/accessibility_observer.h" #include "ash/accessibility/accessibility_observer.h"
#include "ash/ash_export.h" #include "ash/ash_export.h"
#include "components/prefs/pref_change_registrar.h"
#include "ui/views/controls/button/button.h" #include "ui/views/controls/button/button.h"
#include "ui/views/view.h" #include "ui/views/view.h"
class PrefRegistrySimple;
namespace ash { namespace ash {
class CollapseButton; class CollapseButton;
...@@ -48,6 +51,8 @@ class ASH_EXPORT TopShortcutsView : public views::View, ...@@ -48,6 +51,8 @@ class ASH_EXPORT TopShortcutsView : public views::View,
public: public:
explicit TopShortcutsView(UnifiedSystemTrayController* controller); explicit TopShortcutsView(UnifiedSystemTrayController* controller);
static void RegisterLocalStatePrefs(PrefRegistrySimple* registry);
// Change the expanded state. CollapseButton icon will rotate. // Change the expanded state. CollapseButton icon will rotate.
void SetExpandedAmount(double expanded_amount); void SetExpandedAmount(double expanded_amount);
...@@ -60,6 +65,9 @@ class ASH_EXPORT TopShortcutsView : public views::View, ...@@ -60,6 +65,9 @@ class ASH_EXPORT TopShortcutsView : public views::View,
private: private:
friend class TopShortcutsViewTest; friend class TopShortcutsViewTest;
// Disables/Enables the |settings_button_| based on kSettingsIconEnabled pref.
void UpdateSettingsButtonState();
UnifiedSystemTrayController* controller_; UnifiedSystemTrayController* controller_;
// Owned by views hierarchy. // Owned by views hierarchy.
...@@ -71,6 +79,8 @@ class ASH_EXPORT TopShortcutsView : public views::View, ...@@ -71,6 +79,8 @@ class ASH_EXPORT TopShortcutsView : public views::View,
TopShortcutButton* power_button_ = nullptr; TopShortcutButton* power_button_ = nullptr;
CollapseButton* collapse_button_ = nullptr; CollapseButton* collapse_button_ = nullptr;
PrefChangeRegistrar local_state_pref_change_registrar_;
DISALLOW_COPY_AND_ASSIGN(TopShortcutsView); DISALLOW_COPY_AND_ASSIGN(TopShortcutsView);
}; };
......
...@@ -4,6 +4,7 @@ ...@@ -4,6 +4,7 @@
#include "ash/system/unified/top_shortcuts_view.h" #include "ash/system/unified/top_shortcuts_view.h"
#include "ash/public/cpp/ash_pref_names.h"
#include "ash/session/test_session_controller_client.h" #include "ash/session/test_session_controller_client.h"
#include "ash/system/unified/collapse_button.h" #include "ash/system/unified/collapse_button.h"
#include "ash/system/unified/sign_out_button.h" #include "ash/system/unified/sign_out_button.h"
...@@ -12,6 +13,7 @@ ...@@ -12,6 +13,7 @@
#include "ash/system/unified/unified_system_tray_model.h" #include "ash/system/unified/unified_system_tray_model.h"
#include "ash/test/ash_test_base.h" #include "ash/test/ash_test_base.h"
#include "base/macros.h" #include "base/macros.h"
#include "components/prefs/pref_registry_simple.h"
namespace ash { namespace ash {
...@@ -172,4 +174,19 @@ TEST_F(TopShortcutsViewTest, ButtonLayoutSupervisedUserFlow) { ...@@ -172,4 +174,19 @@ TEST_F(TopShortcutsViewTest, ButtonLayoutSupervisedUserFlow) {
Layout(); Layout();
} }
// Settings button is disabled when kSettingsIconDisabled is set.
TEST_F(TopShortcutsViewTest, DisableSettingsIconPolicy) {
const bool enable_settings = true;
GetSessionControllerClient()->AddUserSession(
"foo@example.com", user_manager::USER_TYPE_REGULAR, enable_settings);
SetUpView();
EXPECT_EQ(views::Button::STATE_NORMAL, GetSettingsButton()->state());
local_state()->SetBoolean(prefs::kOsSettingsEnabled, false);
EXPECT_EQ(views::Button::STATE_DISABLED, GetSettingsButton()->state());
local_state()->SetBoolean(prefs::kOsSettingsEnabled, true);
EXPECT_EQ(views::Button::STATE_NORMAL, GetSettingsButton()->state());
}
} // namespace ash } // namespace ash
...@@ -4,6 +4,7 @@ ...@@ -4,6 +4,7 @@
#include "system_features_disable_list_policy_handler.h" #include "system_features_disable_list_policy_handler.h"
#include "ash/public/cpp/ash_pref_names.h"
#include "base/values.h" #include "base/values.h"
#include "components/policy/core/common/policy_pref_names.h" #include "components/policy/core/common/policy_pref_names.h"
#include "components/policy/policy_constants.h" #include "components/policy/policy_constants.h"
...@@ -28,11 +29,16 @@ void SystemFeaturesDisableListPolicyHandler::ApplyList( ...@@ -28,11 +29,16 @@ void SystemFeaturesDisableListPolicyHandler::ApplyList(
PrefValueMap* prefs) { PrefValueMap* prefs) {
DCHECK(filtered_list.is_list()); DCHECK(filtered_list.is_list());
base::Value enums_list(base::Value::Type::LIST); base::Value enums_list(base::Value::Type::LIST);
bool os_settings_enabled = true;
for (const auto& element : filtered_list.GetList()) { for (const auto& element : filtered_list.GetList()) {
enums_list.Append(ConvertToEnum(element.GetString())); SystemFeature feature = ConvertToEnum(element.GetString());
enums_list.Append(feature);
if (feature == SystemFeature::OS_SETTINGS)
os_settings_enabled = false;
} }
prefs->SetValue(policy_prefs::kSystemFeaturesDisableList, prefs->SetValue(policy_prefs::kSystemFeaturesDisableList,
std::move(enums_list)); std::move(enums_list));
prefs->SetBoolean(ash::prefs::kOsSettingsEnabled, os_settings_enabled);
} }
SystemFeature SystemFeaturesDisableListPolicyHandler::ConvertToEnum( SystemFeature SystemFeaturesDisableListPolicyHandler::ConvertToEnum(
......
...@@ -3680,7 +3680,8 @@ ...@@ -3680,7 +3680,8 @@
"policies": { "policies": {
"SystemFeaturesDisableList": ["os_settings"] "SystemFeaturesDisableList": ["os_settings"]
}, },
"prefs": { "policy.system_features_disable_list": { "local_state": true } } "prefs": { "policy.system_features_disable_list": { "local_state": true },
"os_settings_enabled": { "local_state": true } }
} }
] ]
}, },
......
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