Commit 1e3ba8f5 authored by Meilin Wang's avatar Meilin Wang Committed by Commit Bot

Enable "Turn on/off night mode" query on Assistant.

Add SetNightLightEnabled function in mojom::DeviceActions.
Call this function in assistant_manager_service_impl.cc to
enable/disable Night Light mode when query comes.

Test: local compile and manually test.
Bug: b:112698292
Change-Id: Id4ae0ed07fc2bc1197c0b702fd14c46284d1ba33
Reviewed-on: https://chromium-review.googlesource.com/1256216
Commit-Queue: Meilin Wang <meilinw@chromium.org>
Reviewed-by: default avatarXiaohui Chen <xiaohuic@chromium.org>
Reviewed-by: default avatarSam McNally <sammc@chromium.org>
Cr-Commit-Position: refs/heads/master@{#596266}
parent 117f07a4
......@@ -4,6 +4,8 @@
#include "chrome/browser/ui/ash/assistant/device_actions.h"
#include <utility>
#include "ash/public/cpp/ash_pref_names.h"
#include "chrome/browser/chromeos/profiles/profile_helper.h"
#include "chrome/browser/profiles/profile.h"
......@@ -70,3 +72,13 @@ void DeviceActions::SetScreenBrightnessLevel(double level, bool gradual) {
->GetPowerManagerClient()
->SetScreenBrightness(request);
}
void DeviceActions::SetNightLightEnabled(bool enabled) {
const user_manager::User* const user =
user_manager::UserManager::Get()->GetActiveUser();
Profile* profile = chromeos::ProfileHelper::Get()->GetProfileByUser(user);
DCHECK(profile);
// Simply toggle the user pref, which is being observed by ash's night
// light controller.
profile->GetPrefs()->SetBoolean(ash::prefs::kNightLightEnabled, enabled);
}
......@@ -19,6 +19,7 @@ class DeviceActions : public chromeos::assistant::mojom::DeviceActions {
void GetScreenBrightnessLevel(
GetScreenBrightnessLevelCallback callback) override;
void SetScreenBrightnessLevel(double level, bool gradual) override;
void SetNightLightEnabled(bool enabled) override;
private:
DISALLOW_COPY_AND_ASSIGN(DeviceActions);
......
......@@ -48,6 +48,7 @@ constexpr char kWiFiDeviceSettingId[] = "WIFI";
constexpr char kBluetoothDeviceSettingId[] = "BLUETOOTH";
constexpr char kVolumeLevelDeviceSettingId[] = "VOLUME_LEVEL";
constexpr char kScreenBrightnessDeviceSettingId[] = "BRIGHTNESS_LEVEL";
constexpr char kNightLightDeviceSettingId[] = "NIGHT_LIGHT_SWITCH";
constexpr char kTimerFireNotificationGroupId[] = "assistant/timer_fire";
constexpr char kQueryDeeplinkPrefix[] = "googleassistant://send-query?q=";
constexpr base::Feature kAssistantTimerNotificationFeature{
......@@ -618,6 +619,12 @@ void AssistantManagerServiceImpl::OnModifySettingsAction(
},
weak_factory_.GetWeakPtr(), modify_setting_args));
}
if (modify_setting_args.setting_id() == kNightLightDeviceSettingId) {
HandleOnOffChange(modify_setting_args, [&](bool enabled) {
this->service_->device_actions()->SetNightLightEnabled(enabled);
});
}
}
ActionModule::Result AssistantManagerServiceImpl::HandleModifySettingClientOp(
......@@ -636,7 +643,8 @@ bool AssistantManagerServiceImpl::IsSettingSupported(
return (setting_id == kWiFiDeviceSettingId ||
setting_id == kBluetoothDeviceSettingId ||
setting_id == kVolumeLevelDeviceSettingId ||
setting_id == kScreenBrightnessDeviceSettingId);
setting_id == kScreenBrightnessDeviceSettingId ||
setting_id == kNightLightDeviceSettingId);
}
bool AssistantManagerServiceImpl::SupportsModifySettings() {
......
......@@ -154,6 +154,9 @@ interface DeviceActions {
// Sets the screen brightness level (0-1.0). If |gradual| is true, the
// transition will be animated.
SetScreenBrightnessLevel(double level, bool gradual);
// Enables or disables Night Light.
SetNightLightEnabled(bool enabled);
};
// Enumeration of possible completions for an Assistant interaction.
......
......@@ -142,6 +142,7 @@ class FakeDeviceActions : mojom::DeviceActions {
std::move(callback).Run(true, 1.0);
}
void SetScreenBrightnessLevel(double level, bool gradual) override {}
void SetNightLightEnabled(bool enabled) override {}
mojo::Binding<mojom::DeviceActions> binding_;
......
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