Skip to content

Commit

Permalink
Ambient EQ: Add UI control
Browse files Browse the repository at this point in the history
- Adds the UI toggle when the devices internal display supports it
- Sets the value to a pref

Bug: 1021193
Change-Id: Ie079dd63c53bb8d0d4e7b7900aa7d411be09c8e5
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1790126
Commit-Queue: Zentaro Kavanagh <zentaro@chromium.org>
Reviewed-by: Steven Bennetts <stevenjb@chromium.org>
Reviewed-by: James Cook <jamescook@chromium.org>
Auto-Submit: Zentaro Kavanagh <zentaro@chromium.org>
Cr-Commit-Position: refs/heads/master@{#716473}
  • Loading branch information
Zentaro Kavanagh authored and Commit Bot committed Nov 19, 2019
1 parent 7e20abf commit 27a9c3b
Show file tree
Hide file tree
Showing 11 changed files with 109 additions and 2 deletions.
3 changes: 3 additions & 0 deletions ash/public/cpp/ash_pref_names.cc
Original file line number Diff line number Diff line change
Expand Up @@ -197,6 +197,9 @@ const char kMessageCenterLockScreenModeShow[] = "show";
const char kMessageCenterLockScreenModeHide[] = "hide";
const char kMessageCenterLockScreenModeHideSensitive[] = "hideSensitive";

// A boolean pref storing the enabled status of the ambient color feature.
const char kAmbientColorEnabled[] = "ash.ambient_color.enabled";

// A boolean pref storing the enabled status of the NightLight feature.
const char kNightLightEnabled[] = "ash.night_light.enabled";

Expand Down
1 change: 1 addition & 0 deletions ash/public/cpp/ash_pref_names.h
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@ ASH_PUBLIC_EXPORT extern const char kMessageCenterLockScreenModeShow[];
ASH_PUBLIC_EXPORT extern const char kMessageCenterLockScreenModeHide[];
ASH_PUBLIC_EXPORT extern const char kMessageCenterLockScreenModeHideSensitive[];

ASH_PUBLIC_EXPORT extern const char kAmbientColorEnabled[];
ASH_PUBLIC_EXPORT extern const char kNightLightEnabled[];
ASH_PUBLIC_EXPORT extern const char kNightLightTemperature[];
ASH_PUBLIC_EXPORT extern const char kNightLightScheduleType[];
Expand Down
17 changes: 17 additions & 0 deletions ash/system/night_light/night_light_controller_impl.cc
Original file line number Diff line number Diff line change
Expand Up @@ -344,6 +344,7 @@ void NightLightControllerImpl::RegisterProfilePrefs(
kDefaultStartTimeOffsetMinutes);
registry->RegisterIntegerPref(prefs::kNightLightCustomEndTime,
kDefaultEndTimeOffsetMinutes);
registry->RegisterBooleanPref(prefs::kAmbientColorEnabled, false);

// Non-public prefs, only meant to be used by ash.
registry->RegisterDoublePref(prefs::kNightLightCachedLatitude, 0.0);
Expand Down Expand Up @@ -483,6 +484,11 @@ TimeOfDay NightLightControllerImpl::GetCustomEndTime() const {
return TimeOfDay(kDefaultEndTimeOffsetMinutes);
}

bool NightLightControllerImpl::GetAmbientColorEnabled() const {
return active_user_pref_service_ &&
active_user_pref_service_->GetBoolean(prefs::kAmbientColorEnabled);
}

void NightLightControllerImpl::SetEnabled(bool enabled,
AnimationDuration animation_type) {
if (active_user_pref_service_) {
Expand Down Expand Up @@ -676,6 +682,11 @@ void NightLightControllerImpl::StartWatchingPrefsChanges() {
base::BindRepeating(
&NightLightControllerImpl::OnCustomSchedulePrefsChanged,
base::Unretained(this)));
pref_change_registrar_->Add(
prefs::kAmbientColorEnabled,
base::BindRepeating(
&NightLightControllerImpl::OnAmbientColorEnabledPrefChanged,
base::Unretained(this)));

// Note: No need to observe changes in the cached latitude/longitude since
// they're only accessed here in ash. We only load them when the active user
Expand Down Expand Up @@ -707,6 +718,12 @@ void NightLightControllerImpl::OnEnabledPrefChanged() {
NotifyStatusChanged();
}

void NightLightControllerImpl::OnAmbientColorEnabledPrefChanged() {
DCHECK(active_user_pref_service_);
// TODO(dcastagna): Use GetAmbientColorEnabled() to toggle the state
// of Ambient EQ. See b/138731765
}

void NightLightControllerImpl::OnColorTemperaturePrefChanged() {
DCHECK(active_user_pref_service_);
const float color_temperature = GetColorTemperature();
Expand Down
5 changes: 5 additions & 0 deletions ash/system/night_light/night_light_controller_impl.h
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,7 @@ class ASH_EXPORT NightLightControllerImpl
ScheduleType GetScheduleType() const;
TimeOfDay GetCustomStartTime() const;
TimeOfDay GetCustomEndTime() const;
bool GetAmbientColorEnabled() const;

// Set the desired NightLight settings in the current active user prefs.
void SetEnabled(bool enabled, AnimationDuration animation_type);
Expand Down Expand Up @@ -189,6 +190,10 @@ class ASH_EXPORT NightLightControllerImpl
// Called when the user pref for the enabled status of NightLight is changed.
void OnEnabledPrefChanged();

// Called when the user pref for the enabled status of Ambient Color is
// changed.
void OnAmbientColorEnabledPrefChanged();

// Called when the user pref for the color temperature is changed.
void OnColorTemperaturePrefChanged();

Expand Down
6 changes: 6 additions & 0 deletions chrome/app/settings_strings.grdp
Original file line number Diff line number Diff line change
Expand Up @@ -4797,6 +4797,12 @@
<message name="IDS_SETTINGS_DISPLAY_ORIENTATION_STANDARD" desc="In Device Settings > Displays, the label for standard orientation (0 rotation).">
0&#x00B0; (Default)
</message>
<message name="IDS_SETTINGS_DISPLAY_AMBIENT_COLOR_TITLE" desc="In Device Settings > Displays, the label for toggling ambient color.">
Ambient colors
</message>
<message name="IDS_SETTINGS_DISPLAY_AMBIENT_COLOR_SUBTITLE" desc="In Device Settings > Displays, descriptive sublabel for ambient color.">
Adjusts the screen color to match the environment
</message>
<message name="IDS_SETTINGS_DISPLAY_OVERSCAN_TEXT" desc="Text explaining that this setting is used to adjust the boundaries of the selected display.">
Adjust the boundaries of your desktop within the display
</message>
Expand Down
2 changes: 2 additions & 0 deletions chrome/browser/extensions/api/settings_private/prefs_util.cc
Original file line number Diff line number Diff line change
Expand Up @@ -523,6 +523,8 @@ const PrefsUtil::TypedPrefMap& PrefsUtil::GetWhitelistedKeys() {
settings_api::PrefType::PREF_TYPE_NUMBER;

// Ash settings.
(*s_whitelist)[ash::prefs::kAmbientColorEnabled] =
settings_api::PrefType::PREF_TYPE_BOOLEAN;
(*s_whitelist)[ash::prefs::kEnableStylusTools] =
settings_api::PrefType::PREF_TYPE_BOOLEAN;
(*s_whitelist)[ash::prefs::kLaunchPaletteOnEjectEvent] =
Expand Down
11 changes: 10 additions & 1 deletion chrome/browser/resources/settings/device_page/display.html
Original file line number Diff line number Diff line change
Expand Up @@ -228,7 +228,16 @@ <h2>[[selectedDisplay.name]]</h2>
</div>
</template>

<!-- Link row to overscan dialog -->
<template is="dom-if" if="[[showAmbientColorSetting_(
ambientColorAvailable_, selectedDisplay)]]">
<settings-toggle-button id="ambientColor"
class="indented"
pref="{{prefs.ash.ambient_color.enabled}}"
label="$i18n{displayAmbientColorTitle}"
sub-label="$i18n{displayAmbientColorSubtitle}">
</settings-toggle-button>
</template>

<cr-link-row class="indented hr" id="overscan"
label="$i18n{displayOverscanPageTitle}"
sub-label="$i18n{displayOverscanPageText}" on-click="onOverscanTap_"
Expand Down
19 changes: 19 additions & 0 deletions chrome/browser/resources/settings/device_page/display.js
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,14 @@ Polymer({
}
},

/** @private */
ambientColorAvailable_: {
type: Boolean,
value: function() {
return loadTimeData.getBoolean('deviceSupportsAmbientColor');
}
},

/** @private */
listAllDisplayModes_: {
type: Boolean,
Expand Down Expand Up @@ -513,6 +521,17 @@ Polymer({
return !display.isInternal;
},

/**
* Returns true if the ambient color setting should be shown for |display|.
* @param {boolean} ambientColorAvailable
* @param {chrome.system.display.DisplayUnitInfo} display
* @return {boolean}
* @private
*/
showAmbientColorSetting_: function(ambientColorAvailable, display) {
return ambientColorAvailable && display && display.isInternal;
},

/**
* @return {boolean}
* @private
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@
#include "ui/base/l10n/l10n_util.h"

#if defined(OS_CHROMEOS)
#include "ash/public/cpp/ash_features.h"
#include "ash/public/cpp/ash_switches.h"
#include "ash/public/mojom/assistant_state_controller.mojom.h"
#include "base/system/sys_info.h"
Expand All @@ -97,6 +98,7 @@
#include "chrome/common/webui_url_constants.h"
#include "chromeos/constants/chromeos_features.h"
#include "chromeos/constants/chromeos_switches.h"
#include "chromeos/dbus/power/power_manager_client.h"
#include "chromeos/services/assistant/public/features.h"
#include "chromeos/services/multidevice_setup/public/cpp/url_provider.h"
#include "chromeos/strings/grit/chromeos_strings.h"
Expand Down Expand Up @@ -997,6 +999,9 @@ void AddDeviceStrings(content::WebUIDataSource* html_source) {
{"displayArrangementTitle", IDS_SETTINGS_DISPLAY_ARRANGEMENT_TITLE},
{"displayMirror", IDS_SETTINGS_DISPLAY_MIRROR},
{"displayMirrorDisplayName", IDS_SETTINGS_DISPLAY_MIRROR_DISPLAY_NAME},
{"displayAmbientColorTitle", IDS_SETTINGS_DISPLAY_AMBIENT_COLOR_TITLE},
{"displayAmbientColorSubtitle",
IDS_SETTINGS_DISPLAY_AMBIENT_COLOR_SUBTITLE},
{"displayNightLightLabel", IDS_SETTINGS_DISPLAY_NIGHT_LIGHT_LABEL},
{"displayNightLightOnAtSunset",
IDS_SETTINGS_DISPLAY_NIGHT_LIGHT_ON_AT_SUNSET},
Expand Down Expand Up @@ -1069,6 +1074,11 @@ void AddDeviceStrings(content::WebUIDataSource* html_source) {
html_source->AddBoolean("listAllDisplayModes",
display::features::IsListAllDisplayModesEnabled());

const bool ambient_eq_supported =
ash::features::IsAllowAmbientEQEnabled() &&
chromeos::PowerManagerClient::Get()->SupportsAmbientColor();
html_source->AddBoolean("deviceSupportsAmbientColor", ambient_eq_supported);

html_source->AddBoolean(
"enableTouchCalibrationSetting",
cmd.HasSwitch(chromeos::switches::kEnableTouchCalibrationSetting));
Expand Down
35 changes: 34 additions & 1 deletion chrome/test/data/webui/settings/chromeos/device_page_tests.js
Original file line number Diff line number Diff line change
Expand Up @@ -210,6 +210,13 @@ cr.define('device_page_tests', function() {
function getFakePrefs() {
return {
ash: {
ambient_color: {
enabled: {
key: 'ash.ambient_color.enabled',
type: chrome.settingsPrivate.PrefType.BOOLEAN,
value: false,
},
},
night_light: {
enabled: {
key: 'ash.night_light.enabled',
Expand Down Expand Up @@ -419,8 +426,15 @@ cr.define('device_page_tests', function() {
name: 'fakeDisplayName' + n,
mirroring: '',
isPrimary: n == 1,
isInternal: n == 1,
rotation: 0,
modes: [],
modes: [{
deviceScaleFactor: 1.0,
widthInNativePixels: 1920,
heightInNativePixels: 1080,
width: 1920,
height: 1080,
}],
bounds: {
left: 0,
top: 0,
Expand Down Expand Up @@ -790,6 +804,15 @@ cr.define('device_page_tests', function() {
expectFalse(displayPage.showUnifiedDesktop_(
false, false, displayPage.displays));

// Sanity check the first display is internal.
expectTrue(displayPage.displays[0].isInternal);

// Ambient EQ only shown when enabled.
expectTrue(displayPage.showAmbientColorSetting_(
true, displayPage.displays[0]));
expectFalse(displayPage.showAmbientColorSetting_(
false, displayPage.displays[0]));

// Verify that the arrangement section is not shown.
expectEquals(null, displayPage.$$('#arrangement-section'));

Expand Down Expand Up @@ -822,6 +845,16 @@ cr.define('device_page_tests', function() {
expectFalse(displayPage.showUnifiedDesktop_(
false, false, displayPage.displays));

// Sanity check the second display is not internal.
expectFalse(displayPage.displays[1].isInternal);

// Ambient EQ never shown on non-internal display regardless of
// whether it is enabled.
expectFalse(displayPage.showAmbientColorSetting_(
true, displayPage.displays[1]));
expectFalse(displayPage.showAmbientColorSetting_(
false, displayPage.displays[1]));

// Verify that the arrangement section is shown.
expectTrue(!!displayPage.$$('#arrangement-section'));

Expand Down
2 changes: 2 additions & 0 deletions tools/metrics/histograms/enums.xml
Original file line number Diff line number Diff line change
Expand Up @@ -36355,6 +36355,7 @@ from previous Chrome versions.
<int value="-1274502866" label="AllowDisableMouseAcceleration:enabled"/>
<int value="-1272593346" label="NewTabLoadingAnimation:disabled"/>
<int value="-1271563519" label="enable-appcontainer"/>
<int value="-1271441871" label="AmbientColor:enabled"/>
<int value="-1269962982" label="SyncUSSPasswords:disabled"/>
<int value="-1269093329" label="AndroidOmniboxPreviewsBadge:disabled"/>
<int value="-1269084216" label="ash-md"/>
Expand Down Expand Up @@ -37626,6 +37627,7 @@ from previous Chrome versions.
<int value="360391863" label="NTPOfflineBadge:enabled"/>
<int value="360599302" label="enable-gpu-rasterization"/>
<int value="362644448" label="memlog-in-process"/>
<int value="362853088" label="AmbientColor:disabled"/>
<int value="365068212" label="PiexWasm:disabled"/>
<int value="365467768" label="prefetch-search-results"/>
<int value="367063319" label="PasswordImport:disabled"/>
Expand Down

0 comments on commit 27a9c3b

Please sign in to comment.