Commit b65ed4f6 authored by wutao's avatar wutao Committed by Commit Bot

Assistant: Update device locale when starts service

This patch updates device_settings' locale when starts the service,
which can handle the situtation that user changes preferred language.

Bug: b/110094434, b/80431063
Test: manual. Can see updated locale in the log.
Change-Id: I0113fc35367fff9298e5bd3c3ec6976726efaa0f
Reviewed-on: https://chromium-review.googlesource.com/1111656Reviewed-by: default avatarXiyuan Xia <xiyuan@chromium.org>
Reviewed-by: default avatarXiaohui Chen <xiaohuic@chromium.org>
Commit-Queue: Tao Wu <wutao@chromium.org>
Cr-Commit-Position: refs/heads/master@{#569783}
parent 3e5df272
......@@ -8,13 +8,13 @@
namespace ash {
VoiceInteractionController::VoiceInteractionController() : binding_(this) {}
VoiceInteractionController::VoiceInteractionController() = default;
VoiceInteractionController::~VoiceInteractionController() = default;
void VoiceInteractionController::BindRequest(
mojom::VoiceInteractionControllerRequest request) {
binding_.Bind(std::move(request));
bindings_.AddBinding(this, std::move(request));
}
void VoiceInteractionController::NotifyStatusChanged(
......
......@@ -9,7 +9,7 @@
#include "ash/ash_export.h"
#include "ash/public/interfaces/voice_interaction_controller.mojom.h"
#include "mojo/public/cpp/bindings/binding.h"
#include "mojo/public/cpp/bindings/binding_set.h"
#include "mojo/public/cpp/bindings/interface_ptr_set.h"
namespace ash {
......@@ -60,7 +60,7 @@ class ASH_EXPORT VoiceInteractionController
mojom::AssistantAllowedState allowed_state_ =
mojom::AssistantAllowedState::ALLOWED;
mojo::Binding<mojom::VoiceInteractionController> binding_;
mojo::BindingSet<mojom::VoiceInteractionController> bindings_;
mojo::InterfacePtrSet<mojom::VoiceInteractionObserver> observers_;
......
......@@ -6,7 +6,9 @@
#include <utility>
#include "ash/public/interfaces/constants.mojom.h"
#include "base/bind.h"
#include "base/i18n/rtl.h"
#include "base/logging.h"
#include "base/strings/stringprintf.h"
#include "base/sys_info.h"
......@@ -21,6 +23,7 @@
#include "chromeos/system/version_loader.h"
#include "libassistant/shared/internal_api/assistant_manager_delegate.h"
#include "libassistant/shared/internal_api/assistant_manager_internal.h"
#include "services/service_manager/public/cpp/connector.h"
#include "url/gurl.h"
using assistant_client::ActionModule;
......@@ -40,7 +43,10 @@ AssistantManagerServiceImpl::AssistantManagerServiceImpl(
action_module_(std::make_unique<action::CrosActionModule>(this)),
display_connection_(std::make_unique<CrosDisplayConnection>(this)),
main_thread_task_runner_(base::ThreadTaskRunnerHandle::Get()),
weak_factory_(this) {}
weak_factory_(this) {
connector->BindInterface(ash::mojom::kServiceName,
&voice_interaction_controller_);
}
AssistantManagerServiceImpl::~AssistantManagerServiceImpl() {}
......@@ -271,7 +277,7 @@ void AssistantManagerServiceImpl::StartAssistantInternal(
assistant_client::Callback0 assistant_callback([
callback = std::move(callback),
update_settings_callback =
base::BindOnce(&AssistantManagerServiceImpl::UpdateDeviceIdAndType,
base::BindOnce(&AssistantManagerServiceImpl::UpdateDeviceSettings,
weak_factory_.GetWeakPtr())
]() mutable {
std::move(callback).Run();
......@@ -306,7 +312,7 @@ std::string AssistantManagerServiceImpl::BuildUserAgent(
return user_agent;
}
void AssistantManagerServiceImpl::UpdateDeviceIdAndType() {
void AssistantManagerServiceImpl::UpdateDeviceSettings() {
const std::string device_id = assistant_manager_->GetDeviceId();
if (device_id.empty())
return;
......@@ -324,6 +330,33 @@ void AssistantManagerServiceImpl::UpdateDeviceIdAndType() {
// the SettingsUiUpdateResult.
SendUpdateSettingsUiRequest(update.SerializeAsString(),
UpdateSettingsUiResponseCallback());
// Update device locale if voice interaction setup is completed.
main_thread_task_runner_->PostTask(
FROM_HERE,
base::BindOnce(
&AssistantManagerServiceImpl::IsVoiceInteractionSetupCompleted,
weak_factory_.GetWeakPtr(),
base::BindOnce(&AssistantManagerServiceImpl::UpdateDeviceLocale,
weak_factory_.GetWeakPtr())));
}
void AssistantManagerServiceImpl::UpdateDeviceLocale(bool is_setup_completed) {
if (!is_setup_completed)
return;
// Update device locale.
assistant::SettingsUiUpdate update;
assistant::AssistantDeviceSettingsUpdate* device_settings_update =
update.mutable_assistant_device_settings_update()
->add_assistant_device_settings_update();
device_settings_update->mutable_device_settings()->set_locale(
base::i18n::GetConfiguredLocale());
// Device settings update result is not handled because it is not included in
// the SettingsUiUpdateResult.
SendUpdateSettingsUiRequest(update.SerializeAsString(),
UpdateSettingsUiResponseCallback());
}
void AssistantManagerServiceImpl::HandleGetSettingsResponse(
......@@ -445,5 +478,10 @@ void AssistantManagerServiceImpl::OnSpeechLevelUpdatedOnMainThread(
[&speech_level](auto* ptr) { ptr->OnSpeechLevelUpdated(speech_level); });
}
void AssistantManagerServiceImpl::IsVoiceInteractionSetupCompleted(
ash::mojom::VoiceInteractionController::IsSetupCompletedCallback callback) {
voice_interaction_controller_->IsSetupCompleted(std::move(callback));
}
} // namespace assistant
} // namespace chromeos
......@@ -11,6 +11,7 @@
// TODO(xiaohuic): replace with "base/macros.h" once we remove
// libassistant/contrib dependency.
#include "ash/public/interfaces/voice_interaction_controller.mojom.h"
#include "chromeos/assistant/internal/action/cros_action_module.h"
#include "chromeos/assistant/internal/cros_display_connection.h"
#include "chromeos/services/assistant/assistant_manager_service.h"
......@@ -105,8 +106,11 @@ class AssistantManagerServiceImpl
assistant_client::AssistantManager* assistant_manager);
std::string BuildUserAgent(const std::string& arc_version) const;
// Update device id and type when assistant service starts.
void UpdateDeviceIdAndType();
// Update device id, type, and call |UpdateDeviceLocale| when assistant
// service starts.
void UpdateDeviceSettings();
// Update device locale if |is_setup_completed| is true;
void UpdateDeviceLocale(bool is_setup_completed);
void HandleGetSettingsResponse(
base::RepeatingCallback<void(const std::string&)> callback,
......@@ -129,6 +133,10 @@ class AssistantManagerServiceImpl
recognition_result);
void OnSpeechLevelUpdatedOnMainThread(const float speech_level);
void IsVoiceInteractionSetupCompleted(
ash::mojom::VoiceInteractionController::IsSetupCompletedCallback
callback);
State state_ = State::STOPPED;
PlatformApiImpl platform_api_;
std::unique_ptr<action::CrosActionModule> action_module_;
......@@ -138,6 +146,7 @@ class AssistantManagerServiceImpl
std::unique_ptr<CrosDisplayConnection> display_connection_;
mojo::InterfacePtrSet<mojom::AssistantEventSubscriber> subscribers_;
scoped_refptr<base::SingleThreadTaskRunner> main_thread_task_runner_;
ash::mojom::VoiceInteractionControllerPtr voice_interaction_controller_;
base::WeakPtrFactory<AssistantManagerServiceImpl> weak_factory_;
DISALLOW_COPY_AND_ASSIGN(AssistantManagerServiceImpl);
......
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