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