1 // Copyright 2018 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #include "chromeos/services/assistant/fake_assistant_manager_service_impl.h"
6
7 #include <utility>
8
9 namespace chromeos {
10 namespace assistant {
11
12 FakeAssistantManagerServiceImpl::FakeAssistantManagerServiceImpl() = default;
13
14 FakeAssistantManagerServiceImpl::~FakeAssistantManagerServiceImpl() = default;
15
FinishStart()16 void FakeAssistantManagerServiceImpl::FinishStart() {
17 SetStateAndInformObservers(State::RUNNING);
18 }
19
Start(const base::Optional<UserInfo> & user,bool enable_hotword)20 void FakeAssistantManagerServiceImpl::Start(
21 const base::Optional<UserInfo>& user,
22 bool enable_hotword) {
23 SetStateAndInformObservers(State::STARTING);
24 SetUser(user);
25 }
26
Stop()27 void FakeAssistantManagerServiceImpl::Stop() {
28 SetStateAndInformObservers(State::STOPPED);
29 }
30
SetUser(const base::Optional<UserInfo> & user)31 void FakeAssistantManagerServiceImpl::SetUser(
32 const base::Optional<UserInfo>& user) {
33 if (user) {
34 gaia_id_ = user.value().gaia_id;
35 access_token_ = user.value().access_token;
36 } else {
37 gaia_id_ = base::nullopt;
38 access_token_ = base::nullopt;
39 }
40 }
41
EnableListening(bool enable)42 void FakeAssistantManagerServiceImpl::EnableListening(bool enable) {}
43
EnableHotword(bool enable)44 void FakeAssistantManagerServiceImpl::EnableHotword(bool enable) {}
45
EnableAmbientMode(bool enabled)46 void FakeAssistantManagerServiceImpl::EnableAmbientMode(bool enabled) {}
47
SetArcPlayStoreEnabled(bool enabled)48 void FakeAssistantManagerServiceImpl::SetArcPlayStoreEnabled(bool enabled) {}
49
SetAssistantContextEnabled(bool enabled)50 void FakeAssistantManagerServiceImpl::SetAssistantContextEnabled(bool enabled) {
51 }
52
GetState() const53 AssistantManagerService::State FakeAssistantManagerServiceImpl::GetState()
54 const {
55 return state_;
56 }
57
GetAssistantSettings()58 AssistantSettings* FakeAssistantManagerServiceImpl::GetAssistantSettings() {
59 return &assistant_settings_;
60 }
61
AddAndFireStateObserver(StateObserver * observer)62 void FakeAssistantManagerServiceImpl::AddAndFireStateObserver(
63 StateObserver* observer) {
64 state_observers_.AddObserver(observer);
65 observer->OnStateChanged(GetState());
66 }
67
RemoveStateObserver(const StateObserver * observer)68 void FakeAssistantManagerServiceImpl::RemoveStateObserver(
69 const StateObserver* observer) {
70 state_observers_.RemoveObserver(observer);
71 }
72
UpdateInternalMediaPlayerStatus(MediaSessionAction action)73 void FakeAssistantManagerServiceImpl::UpdateInternalMediaPlayerStatus(
74 MediaSessionAction action) {
75 action_ = action;
76 }
77
StartEditReminderInteraction(const std::string & client_id)78 void FakeAssistantManagerServiceImpl::StartEditReminderInteraction(
79 const std::string& client_id) {}
80
StartScreenContextInteraction(ax::mojom::AssistantStructurePtr assistant_structure,const std::vector<uint8_t> & assistant_screenshot)81 void FakeAssistantManagerServiceImpl::StartScreenContextInteraction(
82 ax::mojom::AssistantStructurePtr assistant_structure,
83 const std::vector<uint8_t>& assistant_screenshot) {}
84
StartTextInteraction(const std::string & query,AssistantQuerySource source,bool allow_tts)85 void FakeAssistantManagerServiceImpl::StartTextInteraction(
86 const std::string& query,
87 AssistantQuerySource source,
88 bool allow_tts) {}
89
StartVoiceInteraction()90 void FakeAssistantManagerServiceImpl::StartVoiceInteraction() {}
91
StopActiveInteraction(bool cancel_conversation)92 void FakeAssistantManagerServiceImpl::StopActiveInteraction(
93 bool cancel_conversation) {}
94
AddAssistantInteractionSubscriber(AssistantInteractionSubscriber * subscriber)95 void FakeAssistantManagerServiceImpl::AddAssistantInteractionSubscriber(
96 AssistantInteractionSubscriber* subscriber) {}
97
RemoveAssistantInteractionSubscriber(AssistantInteractionSubscriber * subscriber)98 void FakeAssistantManagerServiceImpl::RemoveAssistantInteractionSubscriber(
99 AssistantInteractionSubscriber* subscriber) {}
100
RetrieveNotification(const AssistantNotification & notification,int action_index)101 void FakeAssistantManagerServiceImpl::RetrieveNotification(
102 const AssistantNotification& notification,
103 int action_index) {}
104
DismissNotification(const AssistantNotification & notification)105 void FakeAssistantManagerServiceImpl::DismissNotification(
106 const AssistantNotification& notification) {}
107
OnAccessibilityStatusChanged(bool spoken_feedback_enabled)108 void FakeAssistantManagerServiceImpl::OnAccessibilityStatusChanged(
109 bool spoken_feedback_enabled) {}
110
SendAssistantFeedback(const AssistantFeedback & feedback)111 void FakeAssistantManagerServiceImpl::SendAssistantFeedback(
112 const AssistantFeedback& feedback) {}
113
NotifyEntryIntoAssistantUi(AssistantEntryPoint entry_point)114 void FakeAssistantManagerServiceImpl::NotifyEntryIntoAssistantUi(
115 AssistantEntryPoint entry_point) {}
116
AddTimeToTimer(const std::string & id,base::TimeDelta duration)117 void FakeAssistantManagerServiceImpl::AddTimeToTimer(const std::string& id,
118 base::TimeDelta duration) {
119 }
120
PauseTimer(const std::string & id)121 void FakeAssistantManagerServiceImpl::PauseTimer(const std::string& id) {}
122
RemoveAlarmOrTimer(const std::string & id)123 void FakeAssistantManagerServiceImpl::RemoveAlarmOrTimer(
124 const std::string& id) {}
125
ResumeTimer(const std::string & id)126 void FakeAssistantManagerServiceImpl::ResumeTimer(const std::string& id) {}
127
SetStateAndInformObservers(State new_state)128 void FakeAssistantManagerServiceImpl::SetStateAndInformObservers(
129 State new_state) {
130 State old_state = state_;
131 state_ = new_state;
132
133 // In reality we will not skip states, i.e. we will always get |STARTING|
134 // before ever encountering |STARTED|. As such our fake implementation will
135 // send out all intermediate states between |old_state| and |new_state|.
136 MaybeSendStateChange(State::STOPPED, old_state, new_state);
137 MaybeSendStateChange(State::STARTING, old_state, new_state);
138 MaybeSendStateChange(State::STARTED, old_state, new_state);
139 MaybeSendStateChange(State::RUNNING, old_state, new_state);
140 }
141
MaybeSendStateChange(State state,State old_state,State target_state)142 void FakeAssistantManagerServiceImpl::MaybeSendStateChange(State state,
143 State old_state,
144 State target_state) {
145 if (state > old_state && state <= target_state) {
146 for (auto& observer : state_observers_)
147 observer.OnStateChanged(state);
148 }
149 }
150
151 } // namespace assistant
152 } // namespace chromeos
153