Commit cc690fa1 authored by Yue Li's avatar Yue Li Committed by Commit Bot

Add observer methods for Assistant launch with mic open setting

Bug: b/115843337
Test: Update test case in unit_tests
Change-Id: I29bb87c4a138e4a14f99f4a28b1be54afeb1dedb
Reviewed-on: https://chromium-review.googlesource.com/1244441
Commit-Queue: Yue Li <updowndota@chromium.org>
Reviewed-by: default avatarXiyuan Xia <xiyuan@chromium.org>
Reviewed-by: default avatarDaniel Cheng <dcheng@chromium.org>
Cr-Commit-Position: refs/heads/master@{#595539}
parent da493e5f
...@@ -106,6 +106,9 @@ interface VoiceInteractionController { ...@@ -106,6 +106,9 @@ interface VoiceInteractionController {
// Called when the locale is changed. // Called when the locale is changed.
NotifyLocaleChanged(string locale); NotifyLocaleChanged(string locale);
// Called when the launch with mic open state is changed.
NotifyLaunchWithMicOpen(bool launch_with_mic_open);
// Return if the voice interaction setting is enabled/disabled. // Return if the voice interaction setting is enabled/disabled.
IsSettingEnabled() => (bool enabled); IsSettingEnabled() => (bool enabled);
......
...@@ -77,6 +77,11 @@ void VoiceInteractionController::NotifyLocaleChanged( ...@@ -77,6 +77,11 @@ void VoiceInteractionController::NotifyLocaleChanged(
[locale](auto* observer) { observer->OnLocaleChanged(locale); }); [locale](auto* observer) { observer->OnLocaleChanged(locale); });
} }
void VoiceInteractionController::NotifyLaunchWithMicOpen(
bool launch_with_mic_open) {
launch_with_mic_open_ = launch_with_mic_open;
}
void VoiceInteractionController::IsSettingEnabled( void VoiceInteractionController::IsSettingEnabled(
IsSettingEnabledCallback callback) { IsSettingEnabledCallback callback) {
std::move(callback).Run(settings_enabled_); std::move(callback).Run(settings_enabled_);
......
...@@ -31,6 +31,7 @@ class ASH_EXPORT VoiceInteractionController ...@@ -31,6 +31,7 @@ class ASH_EXPORT VoiceInteractionController
void NotifyFeatureAllowed(mojom::AssistantAllowedState state) override; void NotifyFeatureAllowed(mojom::AssistantAllowedState state) override;
void NotifyNotificationEnabled(bool enabled) override; void NotifyNotificationEnabled(bool enabled) override;
void NotifyLocaleChanged(const std::string& locale) override; void NotifyLocaleChanged(const std::string& locale) override;
void NotifyLaunchWithMicOpen(bool launch_with_mic_open) override;
void IsSettingEnabled(IsSettingEnabledCallback callback) override; void IsSettingEnabled(IsSettingEnabledCallback callback) override;
void IsSetupCompleted(IsSetupCompletedCallback callback) override; void IsSetupCompleted(IsSetupCompletedCallback callback) override;
void IsContextEnabled(IsContextEnabledCallback callback) override; void IsContextEnabled(IsContextEnabledCallback callback) override;
...@@ -51,6 +52,8 @@ class ASH_EXPORT VoiceInteractionController ...@@ -51,6 +52,8 @@ class ASH_EXPORT VoiceInteractionController
bool notification_enabled() const { return notification_enabled_; } bool notification_enabled() const { return notification_enabled_; }
bool launch_with_mic_open() const { return launch_with_mic_open_; }
void FlushForTesting(); void FlushForTesting();
private: private:
...@@ -80,6 +83,9 @@ class ASH_EXPORT VoiceInteractionController ...@@ -80,6 +83,9 @@ class ASH_EXPORT VoiceInteractionController
std::string locale_; std::string locale_;
// Whether the Assistant should launch with mic open;
bool launch_with_mic_open_ = false;
mojo::BindingSet<mojom::VoiceInteractionController> bindings_; mojo::BindingSet<mojom::VoiceInteractionController> bindings_;
mojo::InterfacePtrSet<mojom::VoiceInteractionObserver> observers_; mojo::InterfacePtrSet<mojom::VoiceInteractionObserver> observers_;
......
...@@ -53,6 +53,11 @@ void FakeVoiceInteractionController::NotifyLocaleChanged( ...@@ -53,6 +53,11 @@ void FakeVoiceInteractionController::NotifyLocaleChanged(
locale_ = locale; locale_ = locale;
} }
void FakeVoiceInteractionController::NotifyLaunchWithMicOpen(
bool launch_with_mic_open) {
launch_with_mic_open_ = launch_with_mic_open;
}
void FakeVoiceInteractionController::IsSettingEnabled( void FakeVoiceInteractionController::IsSettingEnabled(
IsSettingEnabledCallback callback) { IsSettingEnabledCallback callback) {
std::move(callback).Run(voice_interaction_settings_enabled_); std::move(callback).Run(voice_interaction_settings_enabled_);
......
...@@ -27,6 +27,7 @@ class FakeVoiceInteractionController ...@@ -27,6 +27,7 @@ class FakeVoiceInteractionController
void NotifyFeatureAllowed(ash::mojom::AssistantAllowedState state) override; void NotifyFeatureAllowed(ash::mojom::AssistantAllowedState state) override;
void NotifyNotificationEnabled(bool enabled) override; void NotifyNotificationEnabled(bool enabled) override;
void NotifyLocaleChanged(const std::string& locale) override; void NotifyLocaleChanged(const std::string& locale) override;
void NotifyLaunchWithMicOpen(bool launch_with_mic_open) override;
void IsSettingEnabled(IsSettingEnabledCallback callback) override; void IsSettingEnabled(IsSettingEnabledCallback callback) override;
void IsSetupCompleted(IsSetupCompletedCallback callback) override; void IsSetupCompleted(IsSetupCompletedCallback callback) override;
void IsContextEnabled(IsContextEnabledCallback callback) override; void IsContextEnabled(IsContextEnabledCallback callback) override;
...@@ -54,8 +55,8 @@ class FakeVoiceInteractionController ...@@ -54,8 +55,8 @@ class FakeVoiceInteractionController
bool voice_interaction_notification_enabled() const { bool voice_interaction_notification_enabled() const {
return voice_interaction_notification_enabled_; return voice_interaction_notification_enabled_;
} }
const std::string& locale() const { return locale_; } const std::string& locale() const { return locale_; }
bool launch_with_mic_open() const { return launch_with_mic_open_; }
private: private:
ash::mojom::VoiceInteractionState voice_interaction_state_ = ash::mojom::VoiceInteractionState voice_interaction_state_ =
...@@ -68,6 +69,7 @@ class FakeVoiceInteractionController ...@@ -68,6 +69,7 @@ class FakeVoiceInteractionController
std::string locale_; std::string locale_;
ash::mojom::AssistantAllowedState assistant_allowed_state_ = ash::mojom::AssistantAllowedState assistant_allowed_state_ =
ash::mojom::AssistantAllowedState::DISALLOWED_BY_INCOGNITO; ash::mojom::AssistantAllowedState::DISALLOWED_BY_INCOGNITO;
bool launch_with_mic_open_ = false;
mojo::Binding<ash::mojom::VoiceInteractionController> binding_; mojo::Binding<ash::mojom::VoiceInteractionController> binding_;
......
...@@ -145,6 +145,14 @@ void VoiceInteractionControllerClient::NotifyLocaleChanged() { ...@@ -145,6 +145,14 @@ void VoiceInteractionControllerClient::NotifyLocaleChanged() {
voice_interaction_controller_->NotifyLocaleChanged(out_locale); voice_interaction_controller_->NotifyLocaleChanged(out_locale);
} }
void VoiceInteractionControllerClient::NotifyLaunchWithMicOpen() {
DCHECK(profile_);
PrefService* prefs = profile_->GetPrefs();
bool voice_preferred =
prefs->GetBoolean(prefs::kVoiceInteractionLaunchWithMicOpen);
voice_interaction_controller_->NotifyLaunchWithMicOpen(voice_preferred);
}
void VoiceInteractionControllerClient::ActiveUserChanged( void VoiceInteractionControllerClient::ActiveUserChanged(
const user_manager::User* active_user) { const user_manager::User* active_user) {
if (active_user && active_user->is_profile_created()) if (active_user && active_user->is_profile_created())
...@@ -212,12 +220,18 @@ void VoiceInteractionControllerClient::SetProfile(Profile* profile) { ...@@ -212,12 +220,18 @@ void VoiceInteractionControllerClient::SetProfile(Profile* profile) {
base::BindRepeating( base::BindRepeating(
&VoiceInteractionControllerClient::NotifyNotificationEnabled, &VoiceInteractionControllerClient::NotifyNotificationEnabled,
base::Unretained(this))); base::Unretained(this)));
pref_change_registrar_->Add(
prefs::kVoiceInteractionLaunchWithMicOpen,
base::BindRepeating(
&VoiceInteractionControllerClient::NotifyLaunchWithMicOpen,
base::Unretained(this)));
NotifySetupCompleted(); NotifySetupCompleted();
NotifySettingsEnabled(); NotifySettingsEnabled();
NotifyContextEnabled(); NotifyContextEnabled();
NotifyLocaleChanged(); NotifyLocaleChanged();
NotifyNotificationEnabled(); NotifyNotificationEnabled();
NotifyLaunchWithMicOpen();
if (prefs->GetBoolean(prefs::kVoiceInteractionEnabled)) if (prefs->GetBoolean(prefs::kVoiceInteractionEnabled))
NotifyHotwordEnabled(); NotifyHotwordEnabled();
} }
......
...@@ -60,6 +60,7 @@ class VoiceInteractionControllerClient ...@@ -60,6 +60,7 @@ class VoiceInteractionControllerClient
void NotifyFeatureAllowed(); void NotifyFeatureAllowed();
void NotifyNotificationEnabled(); void NotifyNotificationEnabled();
void NotifyLocaleChanged(); void NotifyLocaleChanged();
void NotifyLaunchWithMicOpen();
// user_manager::UserManager::UserSessionStateObserver overrides: // user_manager::UserManager::UserSessionStateObserver overrides:
void ActiveUserChanged(const user_manager::User* active_user) override; void ActiveUserChanged(const user_manager::User* active_user) override;
......
...@@ -153,6 +153,13 @@ TEST_F(VoiceInteractionControllerClientTest, PrefChangeSendsNotification) { ...@@ -153,6 +153,13 @@ TEST_F(VoiceInteractionControllerClientTest, PrefChangeSendsNotification) {
ASSERT_EQ("en-CA", prefs->GetString(language::prefs::kApplicationLocale)); ASSERT_EQ("en-CA", prefs->GetString(language::prefs::kApplicationLocale));
voice_interaction_controller_client()->FlushMojoForTesting(); voice_interaction_controller_client()->FlushMojoForTesting();
EXPECT_EQ("en-CA", voice_interaction_controller()->locale()); EXPECT_EQ("en-CA", voice_interaction_controller()->locale());
ASSERT_EQ(false,
prefs->GetBoolean(prefs::kVoiceInteractionLaunchWithMicOpen));
prefs->SetBoolean(prefs::kVoiceInteractionLaunchWithMicOpen, true);
ASSERT_EQ(true, prefs->GetBoolean(prefs::kVoiceInteractionLaunchWithMicOpen));
voice_interaction_controller_client()->FlushMojoForTesting();
EXPECT_EQ(true, voice_interaction_controller()->launch_with_mic_open());
} }
} // namespace arc } // namespace arc
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