Commit f36265bb authored by Li Lin's avatar Li Lin Committed by Commit Bot

Fixed the issue that switching modality from voice input to text input cancel the conversation.

Bug: b:114302330
Change-Id: I2e295a6ac8b3e78ecc92dd7bfba20b2e673cd04e
Reviewed-on: https://chromium-review.googlesource.com/1212094
Commit-Queue: Li Lin <llin@chromium.org>
Reviewed-by: default avatarDaniel Cheng <dcheng@chromium.org>
Reviewed-by: default avatarXiaohui Chen <xiaohuic@chromium.org>
Cr-Commit-Position: refs/heads/master@{#592880}
parent 4d89f64d
...@@ -131,7 +131,7 @@ void AssistantInteractionController::OnUiModeChanged(AssistantUiMode ui_mode) { ...@@ -131,7 +131,7 @@ void AssistantInteractionController::OnUiModeChanged(AssistantUiMode ui_mode) {
// navigate away from the main stage. // navigate away from the main stage.
if (ui_mode == AssistantUiMode::kWebUi && if (ui_mode == AssistantUiMode::kWebUi &&
model_.pending_query().type() == AssistantQueryType::kVoice) { model_.pending_query().type() == AssistantQueryType::kVoice) {
StopActiveInteraction(); StopActiveInteraction(false);
} }
break; break;
case InputModality::kKeyboard: case InputModality::kKeyboard:
...@@ -148,7 +148,7 @@ void AssistantInteractionController::OnUiVisibilityChanged( ...@@ -148,7 +148,7 @@ void AssistantInteractionController::OnUiVisibilityChanged(
case AssistantVisibility::kClosed: case AssistantVisibility::kClosed:
// When the UI is closed we need to stop any active interaction. We also // When the UI is closed we need to stop any active interaction. We also
// reset the interaction state and restore the default input modality. // reset the interaction state and restore the default input modality.
StopActiveInteraction(); StopActiveInteraction(true);
model_.ClearInteraction(); model_.ClearInteraction();
model_.SetInputModality(InputModality::kKeyboard); model_.SetInputModality(InputModality::kKeyboard);
break; break;
...@@ -157,7 +157,7 @@ void AssistantInteractionController::OnUiVisibilityChanged( ...@@ -157,7 +157,7 @@ void AssistantInteractionController::OnUiVisibilityChanged(
// don't listen to the user while not visible. We also restore the default // don't listen to the user while not visible. We also restore the default
// input modality for the next launch. // input modality for the next launch.
if (model_.pending_query().type() == AssistantQueryType::kVoice) { if (model_.pending_query().type() == AssistantQueryType::kVoice) {
StopActiveInteraction(); StopActiveInteraction(false);
} }
model_.SetInputModality(InputModality::kKeyboard); model_.SetInputModality(InputModality::kKeyboard);
break; break;
...@@ -224,7 +224,7 @@ void AssistantInteractionController::OnInputModalityChanged( ...@@ -224,7 +224,7 @@ void AssistantInteractionController::OnInputModalityChanged(
// automatically interrupt any pre-existing activity. Stopping the active // automatically interrupt any pre-existing activity. Stopping the active
// interaction here for voice input modality would actually have the undesired // interaction here for voice input modality would actually have the undesired
// effect of stopping the voice interaction. // effect of stopping the voice interaction.
StopActiveInteraction(); StopActiveInteraction(false);
} }
void AssistantInteractionController::OnInteractionStarted( void AssistantInteractionController::OnInteractionStarted(
...@@ -441,7 +441,7 @@ void AssistantInteractionController::OnDialogPlateButtonPressed( ...@@ -441,7 +441,7 @@ void AssistantInteractionController::OnDialogPlateButtonPressed(
StartVoiceInteraction(); StartVoiceInteraction();
break; break;
case MicState::kOpen: case MicState::kOpen:
StopActiveInteraction(); StopActiveInteraction(false);
break; break;
} }
} }
...@@ -454,7 +454,7 @@ void AssistantInteractionController::OnDialogPlateContentsCommitted( ...@@ -454,7 +454,7 @@ void AssistantInteractionController::OnDialogPlateContentsCommitted(
void AssistantInteractionController::StartMetalayerInteraction( void AssistantInteractionController::StartMetalayerInteraction(
const gfx::Rect& region) { const gfx::Rect& region) {
StopActiveInteraction(); StopActiveInteraction(false);
model_.SetPendingQuery(std::make_unique<AssistantTextQuery>( model_.SetPendingQuery(std::make_unique<AssistantTextQuery>(
l10n_util::GetStringUTF8(IDS_ASH_ASSISTANT_CHIP_WHATS_ON_MY_SCREEN))); l10n_util::GetStringUTF8(IDS_ASH_ASSISTANT_CHIP_WHATS_ON_MY_SCREEN)));
...@@ -463,7 +463,7 @@ void AssistantInteractionController::StartMetalayerInteraction( ...@@ -463,7 +463,7 @@ void AssistantInteractionController::StartMetalayerInteraction(
} }
void AssistantInteractionController::StartScreenContextInteraction() { void AssistantInteractionController::StartScreenContextInteraction() {
StopActiveInteraction(); StopActiveInteraction(false);
model_.SetPendingQuery(std::make_unique<AssistantTextQuery>( model_.SetPendingQuery(std::make_unique<AssistantTextQuery>(
l10n_util::GetStringUTF8(IDS_ASH_ASSISTANT_CHIP_WHATS_ON_MY_SCREEN))); l10n_util::GetStringUTF8(IDS_ASH_ASSISTANT_CHIP_WHATS_ON_MY_SCREEN)));
...@@ -474,7 +474,7 @@ void AssistantInteractionController::StartScreenContextInteraction() { ...@@ -474,7 +474,7 @@ void AssistantInteractionController::StartScreenContextInteraction() {
void AssistantInteractionController::StartTextInteraction( void AssistantInteractionController::StartTextInteraction(
const std::string text) { const std::string text) {
StopActiveInteraction(); StopActiveInteraction(false);
model_.SetPendingQuery(std::make_unique<AssistantTextQuery>(text)); model_.SetPendingQuery(std::make_unique<AssistantTextQuery>(text));
...@@ -482,14 +482,15 @@ void AssistantInteractionController::StartTextInteraction( ...@@ -482,14 +482,15 @@ void AssistantInteractionController::StartTextInteraction(
} }
void AssistantInteractionController::StartVoiceInteraction() { void AssistantInteractionController::StartVoiceInteraction() {
StopActiveInteraction(); StopActiveInteraction(false);
model_.SetPendingQuery(std::make_unique<AssistantVoiceQuery>()); model_.SetPendingQuery(std::make_unique<AssistantVoiceQuery>());
assistant_->StartVoiceInteraction(); assistant_->StartVoiceInteraction();
} }
void AssistantInteractionController::StopActiveInteraction() { void AssistantInteractionController::StopActiveInteraction(
bool cancel_conversation) {
// Even though the interaction state will be asynchronously set to inactive // Even though the interaction state will be asynchronously set to inactive
// via a call to OnInteractionFinished(Resolution), we explicitly set it to // via a call to OnInteractionFinished(Resolution), we explicitly set it to
// inactive here to prevent processing any additional UI related service // inactive here to prevent processing any additional UI related service
...@@ -497,7 +498,7 @@ void AssistantInteractionController::StopActiveInteraction() { ...@@ -497,7 +498,7 @@ void AssistantInteractionController::StopActiveInteraction() {
model_.SetInteractionState(InteractionState::kInactive); model_.SetInteractionState(InteractionState::kInactive);
model_.ClearPendingQuery(); model_.ClearPendingQuery();
assistant_->StopActiveInteraction(); assistant_->StopActiveInteraction(cancel_conversation);
// Because we are stopping an interaction in progress, we discard any pending // Because we are stopping an interaction in progress, we discard any pending
// response for it that is cached to prevent it from being finalized when the // response for it that is cached to prevent it from being finalized when the
......
...@@ -103,7 +103,7 @@ class AssistantInteractionController ...@@ -103,7 +103,7 @@ class AssistantInteractionController
void StartScreenContextInteraction(); void StartScreenContextInteraction();
void StartTextInteraction(const std::string text); void StartTextInteraction(const std::string text);
void StartVoiceInteraction(); void StartVoiceInteraction();
void StopActiveInteraction(); void StopActiveInteraction(bool cancel_conversation);
void OpenUrl(const GURL& url); void OpenUrl(const GURL& url);
......
...@@ -217,9 +217,11 @@ void AssistantManagerServiceImpl::StartVoiceInteraction() { ...@@ -217,9 +217,11 @@ void AssistantManagerServiceImpl::StartVoiceInteraction() {
assistant_manager_->StartAssistantInteraction(); assistant_manager_->StartAssistantInteraction();
} }
void AssistantManagerServiceImpl::StopActiveInteraction() { void AssistantManagerServiceImpl::StopActiveInteraction(
bool cancel_conversation) {
platform_api_->SetMicState(false); platform_api_->SetMicState(false);
assistant_manager_->StopAssistantInteraction(); assistant_manager_internal_->StopAssistantInteractionInternal(
cancel_conversation);
} }
void AssistantManagerServiceImpl::StartCachedScreenContextInteraction() { void AssistantManagerServiceImpl::StartCachedScreenContextInteraction() {
......
...@@ -83,7 +83,7 @@ class AssistantManagerServiceImpl ...@@ -83,7 +83,7 @@ class AssistantManagerServiceImpl
void StartCachedScreenContextInteraction() override; void StartCachedScreenContextInteraction() override;
void StartMetalayerInteraction(const gfx::Rect& region) override; void StartMetalayerInteraction(const gfx::Rect& region) override;
void StartVoiceInteraction() override; void StartVoiceInteraction() override;
void StopActiveInteraction() override; void StopActiveInteraction(bool cancel_conversation) override;
void SendTextQuery(const std::string& query) override; void SendTextQuery(const std::string& query) override;
void AddAssistantInteractionSubscriber( void AddAssistantInteractionSubscriber(
mojom::AssistantInteractionSubscriberPtr subscriber) override; mojom::AssistantInteractionSubscriberPtr subscriber) override;
......
...@@ -53,7 +53,8 @@ void FakeAssistantManagerServiceImpl::StartMetalayerInteraction( ...@@ -53,7 +53,8 @@ void FakeAssistantManagerServiceImpl::StartMetalayerInteraction(
void FakeAssistantManagerServiceImpl::StartVoiceInteraction() {} void FakeAssistantManagerServiceImpl::StartVoiceInteraction() {}
void FakeAssistantManagerServiceImpl::StopActiveInteraction() {} void FakeAssistantManagerServiceImpl::StopActiveInteraction(
bool cancel_conversation) {}
void FakeAssistantManagerServiceImpl::SendTextQuery(const std::string& query) {} void FakeAssistantManagerServiceImpl::SendTextQuery(const std::string& query) {}
......
...@@ -42,7 +42,7 @@ class FakeAssistantManagerServiceImpl : public AssistantManagerService { ...@@ -42,7 +42,7 @@ class FakeAssistantManagerServiceImpl : public AssistantManagerService {
void StartCachedScreenContextInteraction() override; void StartCachedScreenContextInteraction() override;
void StartMetalayerInteraction(const gfx::Rect& region) override; void StartMetalayerInteraction(const gfx::Rect& region) override;
void StartVoiceInteraction() override; void StartVoiceInteraction() override;
void StopActiveInteraction() override; void StopActiveInteraction(bool cancel_conversation) override;
void SendTextQuery(const std::string& query) override; void SendTextQuery(const std::string& query) override;
void AddAssistantInteractionSubscriber( void AddAssistantInteractionSubscriber(
mojom::AssistantInteractionSubscriberPtr subscriber) override; mojom::AssistantInteractionSubscriberPtr subscriber) override;
......
...@@ -26,9 +26,10 @@ interface Assistant { ...@@ -26,9 +26,10 @@ interface Assistant {
// Starts a new Assistant voice interaction. // Starts a new Assistant voice interaction.
StartVoiceInteraction(); StartVoiceInteraction();
// Stops the active Assistant interaction. If there is no active interaction, // Stops the active Assistant interaction and cancel the conversation if
// this method is a no-op. // |cancel_conversation|. If there is no active interaction, this method
StopActiveInteraction(); // is a no-op.
StopActiveInteraction(bool cancel_conversation);
// Send text query to assistant. Result will be returned through registered // Send text query to assistant. Result will be returned through registered
// |AssistantInteractionSubscriber|. // |AssistantInteractionSubscriber|.
......
...@@ -27,7 +27,7 @@ class MockAssistant : public mojom::Assistant { ...@@ -27,7 +27,7 @@ class MockAssistant : public mojom::Assistant {
MOCK_METHOD0(StartVoiceInteraction, void()); MOCK_METHOD0(StartVoiceInteraction, void());
MOCK_METHOD0(StopActiveInteraction, void()); MOCK_METHOD1(StopActiveInteraction, void(bool));
MOCK_METHOD1(SendTextQuery, void(const std::string&)); MOCK_METHOD1(SendTextQuery, void(const std::string&));
......
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