Commit ffaf6d76 authored by Ryan Cui's avatar Ryan Cui Committed by Commit Bot

Add support for bluetooth actions

Bug: b/78189672
Change-Id: Id8716cca1f4cf15a5700a0a4afa822302a829662
Reviewed-on: https://chromium-review.googlesource.com/1142623
Commit-Queue: Ryan Cui <rcui@chromium.org>
Reviewed-by: default avatarDaniel Cheng <dcheng@chromium.org>
Reviewed-by: default avatarSteven Bennetts <stevenjb@chromium.org>
Reviewed-by: default avatarXiaohui Chen <xiaohuic@chromium.org>
Cr-Commit-Position: refs/heads/master@{#577218}
parent fbeda76c
...@@ -3,7 +3,13 @@ ...@@ -3,7 +3,13 @@
// found in the LICENSE file. // found in the LICENSE file.
#include "chrome/browser/ui/ash/assistant/device_actions.h" #include "chrome/browser/ui/ash/assistant/device_actions.h"
#include "ash/public/cpp/ash_pref_names.h"
#include "chrome/browser/chromeos/profiles/profile_helper.h"
#include "chrome/browser/profiles/profile.h"
#include "chromeos/network/network_state_handler.h" #include "chromeos/network/network_state_handler.h"
#include "components/prefs/pref_service.h"
#include "components/user_manager/user_manager.h"
using chromeos::NetworkHandler; using chromeos::NetworkHandler;
using chromeos::NetworkStateHandler; using chromeos::NetworkStateHandler;
...@@ -18,3 +24,14 @@ void DeviceActions::SetWifiEnabled(bool enabled) { ...@@ -18,3 +24,14 @@ void DeviceActions::SetWifiEnabled(bool enabled) {
NetworkTypePattern::WiFi(), enabled, NetworkTypePattern::WiFi(), enabled,
chromeos::network_handler::ErrorCallback()); chromeos::network_handler::ErrorCallback());
} }
void DeviceActions::SetBluetoothEnabled(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 bluetooth
// power controller.
profile->GetPrefs()->SetBoolean(ash::prefs::kUserBluetoothAdapterEnabled,
enabled);
}
...@@ -14,7 +14,8 @@ class DeviceActions : public chromeos::assistant::mojom::DeviceActions { ...@@ -14,7 +14,8 @@ class DeviceActions : public chromeos::assistant::mojom::DeviceActions {
~DeviceActions() override; ~DeviceActions() override;
// mojom::DeviceActions overrides: // mojom::DeviceActions overrides:
void SetWifiEnabled(bool enable) override; void SetWifiEnabled(bool enabled) override;
void SetBluetoothEnabled(bool enabled) override;
private: private:
DISALLOW_COPY_AND_ASSIGN(DeviceActions); DISALLOW_COPY_AND_ASSIGN(DeviceActions);
......
...@@ -380,20 +380,14 @@ void AssistantManagerServiceImpl::OnSpeechLevelUpdated( ...@@ -380,20 +380,14 @@ void AssistantManagerServiceImpl::OnSpeechLevelUpdated(
weak_factory_.GetWeakPtr(), speech_level)); weak_factory_.GetWeakPtr(), speech_level));
} }
void AssistantManagerServiceImpl::OnModifySettingsAction( void HandleOnOffChange(api::client_op::ModifySettingArgs modify_setting_args,
const std::string& modify_setting_args_proto) { std::function<void(bool)> on_off_handler) {
api::client_op::ModifySettingArgs modify_setting_args;
modify_setting_args.ParseFromString(modify_setting_args_proto);
DCHECK(IsSettingSupported(modify_setting_args.setting_id()));
// TODO(rcui): Add support for bluetooth, etc.
if (modify_setting_args.setting_id() == kWiFiDeviceSettingId) {
switch (modify_setting_args.change()) { switch (modify_setting_args.change()) {
case api::client_op::ModifySettingArgs_Change_ON: case api::client_op::ModifySettingArgs_Change_ON:
service_->device_actions()->SetWifiEnabled(true); on_off_handler(true);
return; return;
case api::client_op::ModifySettingArgs_Change_OFF: case api::client_op::ModifySettingArgs_Change_OFF:
service_->device_actions()->SetWifiEnabled(false); on_off_handler(false);
return; return;
case api::client_op::ModifySettingArgs_Change_TOGGLE: case api::client_op::ModifySettingArgs_Change_TOGGLE:
...@@ -406,6 +400,24 @@ void AssistantManagerServiceImpl::OnModifySettingsAction( ...@@ -406,6 +400,24 @@ void AssistantManagerServiceImpl::OnModifySettingsAction(
DLOG(ERROR) << "Unsupported change operation: " DLOG(ERROR) << "Unsupported change operation: "
<< modify_setting_args.change() << " for setting " << modify_setting_args.change() << " for setting "
<< modify_setting_args.setting_id(); << modify_setting_args.setting_id();
}
void AssistantManagerServiceImpl::OnModifySettingsAction(
const std::string& modify_setting_args_proto) {
api::client_op::ModifySettingArgs modify_setting_args;
modify_setting_args.ParseFromString(modify_setting_args_proto);
DCHECK(IsSettingSupported(modify_setting_args.setting_id()));
if (modify_setting_args.setting_id() == kWiFiDeviceSettingId) {
HandleOnOffChange(modify_setting_args, [this](bool enabled) {
this->service_->device_actions()->SetWifiEnabled(enabled);
});
}
if (modify_setting_args.setting_id() == kBluetoothDeviceSettingId) {
HandleOnOffChange(modify_setting_args, [this](bool enabled) {
this->service_->device_actions()->SetBluetoothEnabled(enabled);
});
} }
} }
......
...@@ -154,6 +154,9 @@ interface AudioInputObserver { ...@@ -154,6 +154,9 @@ interface AudioInputObserver {
interface DeviceActions { interface DeviceActions {
// Enables or disables WiFi. // Enables or disables WiFi.
SetWifiEnabled(bool enabled); SetWifiEnabled(bool enabled);
// Enables or disables Bluetooth.
SetBluetoothEnabled(bool enabled);
}; };
// Enumeration of possible completions for an Assistant interaction. // Enumeration of possible completions for an Assistant interaction.
......
...@@ -155,6 +155,7 @@ class FakeDeviceActions : mojom::DeviceActions { ...@@ -155,6 +155,7 @@ class FakeDeviceActions : mojom::DeviceActions {
private: private:
// mojom::DeviceActions: // mojom::DeviceActions:
void SetWifiEnabled(bool enabled) override {} void SetWifiEnabled(bool enabled) override {}
void SetBluetoothEnabled(bool enabled) override {}
mojo::Binding<mojom::DeviceActions> binding_; 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