Commit 1d7c203f authored by David Black's avatar David Black Committed by Commit Bot

Add StartVoiceInteraction/StopActiveInteraction APIs.

Details of when APIs should be called described in bug.

Note: This CL also removes an auto dismiss timer that was previously
added when there was no other way to exit. Removing it now that
keyboard shortcuts have been wired up.

Bug: b:79369258
Change-Id: I41f2c4b24a44a1ee55ca134b8f51cc19e1020b8d
Reviewed-on: https://chromium-review.googlesource.com/1048386
Commit-Queue: David Black <dmblack@google.com>
Reviewed-by: default avatarXiyuan Xia <xiyuan@chromium.org>
Reviewed-by: default avatarXiaohui Chen <xiaohuic@chromium.org>
Reviewed-by: default avatarDaniel Cheng <dcheng@chromium.org>
Cr-Commit-Position: refs/heads/master@{#557239}
parent 32b51f11
......@@ -14,12 +14,6 @@
namespace ash {
namespace {
constexpr base::TimeDelta kAutoDismissDelay = base::TimeDelta::FromSeconds(5);
} // namespace
AshAssistantController::AshAssistantController()
: assistant_controller_binding_(this),
assistant_event_subscriber_binding_(this),
......@@ -108,7 +102,6 @@ void AshAssistantController::StartInteraction() {
}
void AshAssistantController::StopInteraction() {
// TODO(dmblack): Instruct underlying service to stop listening.
if (assistant_interaction_model_.interaction_state() !=
InteractionState::kInactive) {
OnInteractionDismissed();
......@@ -138,40 +131,45 @@ void AshAssistantController::OnInteractionStateChanged(
void AshAssistantController::OnHighlighterEnabledChanged(bool enabled) {
// TODO(warx): add a reason enum to distinguish the case of deselecting the
// tool and done with a stylus selection.
assistant_bubble_timer_.Stop();
assistant_interaction_model_.SetInputModality(InputModality::kStylus);
assistant_interaction_model_.SetInteractionState(
enabled ? InteractionState::kActive : InteractionState::kInactive);
}
void AshAssistantController::OnInteractionStarted() {
assistant_bubble_timer_.Stop();
assistant_interaction_model_.SetInteractionState(InteractionState::kActive);
}
void AshAssistantController::OnInteractionFinished(
chromeos::assistant::mojom::AssistantInteractionResolution resolution) {
assistant_bubble_timer_.Start(
FROM_HERE, kAutoDismissDelay, this,
&AshAssistantController::OnInteractionDismissed);
}
void AshAssistantController::OnInteractionDismissed() {
assistant_bubble_timer_.Stop();
assistant_interaction_model_.SetInteractionState(InteractionState::kInactive);
// When the user-facing interaction is dismissed, we instruct the service to
// terminate any listening, speaking, or query in flight.
DCHECK(assistant_);
assistant_->StopActiveInteraction();
}
void AshAssistantController::OnDialogPlateContentsChanged(
const std::string& text) {
assistant_bubble_timer_.Stop();
if (text.empty()) {
// Note: This does not open the mic. It only updates the input modality to
// voice so that we will show the mic icon in the UI.
assistant_interaction_model_.SetInputModality(InputModality::kVoice);
} else {
// TODO(dmblack): Instruct the underlying service to stop any in flight
// voice interaction.
// If switching to keyboard modality from voice, we instruct the service to
// terminate any listening, speaking, or query in flight.
// TODO(dmblack): We probably want this same logic when switching to any
// modality from voice. Handle this instead in OnInputModalityChanged, but
// we will need to add a previous modality parameter to that API.
if (assistant_interaction_model_.input_modality() ==
InputModality::kVoice) {
DCHECK(assistant_);
assistant_->StopActiveInteraction();
}
assistant_interaction_model_.SetInputModality(InputModality::kKeyboard);
assistant_interaction_model_.SetMicState(MicState::kClosed);
}
......
......@@ -15,7 +15,6 @@
#include "ash/public/interfaces/ash_assistant_controller.mojom.h"
#include "ash/public/interfaces/assistant_card_renderer.mojom.h"
#include "base/macros.h"
#include "base/timer/timer.h"
#include "chromeos/services/assistant/public/mojom/assistant.mojom.h"
#include "mojo/public/cpp/bindings/binding.h"
......@@ -121,7 +120,6 @@ class AshAssistantController
mojom::AssistantCardRendererPtr assistant_card_renderer_;
std::unique_ptr<AssistantBubble> assistant_bubble_;
base::OneShotTimer assistant_bubble_timer_;
DISALLOW_COPY_AND_ASSIGN(AshAssistantController);
};
......
......@@ -127,6 +127,14 @@ void AssistantManagerServiceImpl::SendUpdateSettingsUiRequest(
});
}
void AssistantManagerServiceImpl::StartVoiceInteraction() {
assistant_manager_->StartAssistantInteraction();
}
void AssistantManagerServiceImpl::StopActiveInteraction() {
assistant_manager_->StopAssistantInteraction();
}
void AssistantManagerServiceImpl::SendTextQuery(const std::string& query) {
assistant_manager_internal_->SendTextQuery(query);
}
......
......@@ -59,6 +59,8 @@ class AssistantManagerServiceImpl
UpdateSettingsUiResponseCallback callback) override;
// mojom::Assistant overrides:
void StartVoiceInteraction() override;
void StopActiveInteraction() override;
void SendTextQuery(const std::string& query) override;
void AddAssistantEventSubscriber(
mojom::AssistantEventSubscriberPtr subscriber) override;
......
......@@ -42,6 +42,10 @@ void FakeAssistantManagerServiceImpl::SendUpdateSettingsUiRequest(
const std::string& update,
UpdateSettingsUiResponseCallback callback) {}
void FakeAssistantManagerServiceImpl::StartVoiceInteraction() {}
void FakeAssistantManagerServiceImpl::StopActiveInteraction() {}
void FakeAssistantManagerServiceImpl::SendTextQuery(const std::string& query) {}
void FakeAssistantManagerServiceImpl::AddAssistantEventSubscriber(
......
......@@ -37,6 +37,8 @@ class FakeAssistantManagerServiceImpl : public AssistantManagerService {
UpdateSettingsUiResponseCallback callback) override;
// mojom::AssistantEvent overrides:
void StartVoiceInteraction() override;
void StopActiveInteraction() override;
void SendTextQuery(const std::string& query) override;
void AddAssistantEventSubscriber(
mojom::AssistantEventSubscriberPtr subscriber) override;
......
......@@ -9,6 +9,13 @@ import "mojo/public/mojom/base/time.mojom";
// Interface to communicate with assistant backend.
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();
// Send text query to assistant. Result will be returned through registered
// |AssistantEventSubscriber|.
SendTextQuery(string query);
......
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