1 /*
2 * Copyright (C) 2021-2022 Huawei Device Co., Ltd.
3 * Licensed under the Apache License, Version 2.0 (the "License");
4 * you may not use this file except in compliance with the License.
5 * You may obtain a copy of the License at
6 *
7 * http://www.apache.org/licenses/LICENSE-2.0
8 *
9 * Unless required by applicable law or agreed to in writing, software
10 * distributed under the License is distributed on an "AS IS" BASIS,
11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 * See the License for the specific language governing permissions and
13 * limitations under the License.
14 */
15
16 #include "hfp_hf_statemachine.h"
17
18 #include "hfp_hf_data_connection_server.h"
19 #include "hfp_hf_service.h"
20 #include "power_manager.h"
21 #include "audio_system_manager.h"
22
23 namespace OHOS {
24 namespace bluetooth {
HfpHfStateMachine(const std::string & address)25 HfpHfStateMachine::HfpHfStateMachine(const std::string &address)
26 : address_(address), profile_(address)
27 {}
28
Init()29 void HfpHfStateMachine::Init()
30 {
31 profile_.Init();
32 calls_ = std::make_unique<HfpHfCallManager>(address_);
33 connTimer_ = std::make_unique<utility::Timer>(std::bind(&bluetooth::HfpHfStateMachine::ConnectionTimeout, this));
34
35 std::unique_ptr<utility::StateMachine::State> disconnectedState =
36 std::make_unique<HfpHfDisconnected>(DISCONNECTED, *this, profile_);
37 std::unique_ptr<utility::StateMachine::State> connectingState =
38 std::make_unique<HfpHfConnecting>(CONNECTING, *this, profile_);
39 std::unique_ptr<utility::StateMachine::State> disconnectingState =
40 std::make_unique<HfpHfDisconnecting>(DISCONNECTING, *this, profile_);
41 std::unique_ptr<utility::StateMachine::State> connectedState =
42 std::make_unique<HfpHfConnected>(CONNECTED, *this, profile_);
43 std::unique_ptr<utility::StateMachine::State> audioConnecting =
44 std::make_unique<HfpHfAudioConnecting>(AUDIO_CONNECTING, *this, profile_, *connectedState);
45 std::unique_ptr<utility::StateMachine::State> audioDisconnecting =
46 std::make_unique<HfpHfAudioDisconnecting>(AUDIO_DISCONNECTING, *this, profile_, *connectedState);
47 std::unique_ptr<utility::StateMachine::State> audioConnected =
48 std::make_unique<HfpHfAudioConnected>(AUDIO_CONNECTED, *this, profile_, *connectedState);
49
50 Move(disconnectedState);
51 Move(connectingState);
52 Move(disconnectingState);
53 Move(audioConnecting);
54 Move(audioDisconnecting);
55 Move(audioConnected);
56 Move(connectedState); // Add parenet state at last
57
58 InitState(DISCONNECTED);
59 }
60
Entry()61 void HfpHfDisconnected::Entry()
62 {
63 stateMachine_.ProcessDeferredMessage();
64
65 if (isReentry_) {
66 stateMachine_.SetRemoving(true);
67 profile_.RemoveStateMachine();
68 stateMachine_.NotifyStateTransitions();
69 }
70 }
71
Exit()72 void HfpHfDisconnected::Exit()
73 {
74 isReentry_ = true;
75 }
76
Dispatch(const utility::Message & msg)77 bool HfpHfDisconnected::Dispatch(const utility::Message &msg)
78 {
79 HfpHfMessage &event = (HfpHfMessage &)msg;
80 LOG_DEBUG("[HFP HF]%{public}s():[Disconnected][%{public}s]", __FUNCTION__, HfpHfStateMachine::GetEventName(event.what_).c_str());
81 switch (event.what_) {
82 case HFP_HF_CONNECT_EVT:
83 profile_.DoServiceDiscovery(HFP_HF_INITIATOR);
84 Transition(HfpHfStateMachine::CONNECTING);
85 break;
86 case HFP_HF_CONNECT_REQUEST_EVT:
87 profile_.AcceptDataConnection(event.arg1_);
88 Transition(HfpHfStateMachine::CONNECTING);
89 break;
90 case HFP_HF_AUDIO_CONNECT_REQUEST_EVT:
91 profile_.RejectAudioConnection();
92 break;
93 default:
94 break;
95 }
96 return true;
97 }
98
Entry()99 void HfpHfConnecting::Entry()
100 {
101 stateMachine_.ProcessDeferredMessage();
102 stateMachine_.NotifyStateTransitions();
103 stateMachine_.StartConnectionTimer();
104 }
Exit()105 void HfpHfConnecting::Exit()
106 {
107 stateMachine_.StopConnectionTimer();
108 }
109
Dispatch(const utility::Message & msg)110 bool HfpHfConnecting::Dispatch(const utility::Message &msg)
111 {
112 HfpHfMessage &event = (HfpHfMessage &)msg;
113 LOG_DEBUG("[HFP HF]%{public}s():[Connecting][%{public}s]", __FUNCTION__, HfpHfStateMachine::GetEventName(event.what_).c_str());
114 switch (event.what_) {
115 case HFP_HF_SDP_DISCOVERY_RESULT_SUCCESS:
116 if (profile_.ServiceDiscoveryResult() != HFP_HF_SUCCESS) {
117 Transition(HfpHfStateMachine::DISCONNECTED);
118 }
119 break;
120 case HFP_HF_SDP_DISCOVERY_RESULT_FAIL:
121 Transition(HfpHfStateMachine::DISCONNECTED);
122 break;
123 case HFP_HF_CONNECT_EVT:
124 case HFP_HF_DISCONNECT_EVT:
125 stateMachine_.AddDeferredMessage(event);
126 break;
127 case HFP_HF_DATA_AVAILABLE_EVT:
128 profile_.ReadData();
129 break;
130 case HFP_HF_CONNECTED_EVT:
131 profile_.EstablishServiceLevelConnection();
132 break;
133 case HFP_HF_DISCONNECTED_EVT:
134 profile_.RemoveRemoteScnLoging();
135 Transition(HfpHfStateMachine::DISCONNECTED);
136 break;
137 case HFP_HF_AUDIO_CONNECT_REQUEST_EVT:
138 profile_.ProcessAudioConnectRequest();
139 break;
140 case HFP_HF_AUDIO_CONNECTED_EVT:
141 case HFP_HF_AUDIO_DISCONNECTED_EVT:
142 stateMachine_.AddDeferredMessage(event);
143 break;
144 case HFP_HF_CONNECT_FAILED_EVT:
145 profile_.RemoveRemoteScnLoging();
146 Transition(HfpHfStateMachine::DISCONNECTED);
147 break;
148 case HFP_HF_SLC_ESTABLISHED_EVT:
149 profile_.ProcessSlcEstablished();
150 Transition(HfpHfStateMachine::CONNECTED);
151 break;
152 case HFP_HF_BATTERY_LEVEL_CHANGED_EVT:
153 profile_.ReportBatteryLevel(event.arg1_);
154 break;
155 case HFP_HF_ENHANCED_DRIVER_SAFETY_CHANGED_EVT:
156 profile_.ReportDriverSafety(event.arg1_);
157 break;
158 case HFP_HF_INTERACTIVE_EVT:
159 stateMachine_.AddDeferredMessage(event);
160 break;
161 case HFP_HF_CONNECTION_TIMEOUT_EVT:
162 Transition(HfpHfStateMachine::DISCONNECTED);
163 break;
164 default:
165 break;
166 }
167 return true;
168 }
169
Entry()170 void HfpHfDisconnecting::Entry()
171 {
172 stateMachine_.ProcessDeferredMessage();
173 stateMachine_.NotifyStateTransitions();
174 stateMachine_.StartConnectionTimer();
175 }
176
Exit()177 void HfpHfDisconnecting::Exit()
178 {
179 stateMachine_.StopConnectionTimer();
180 }
181
Dispatch(const utility::Message & msg)182 bool HfpHfDisconnecting::Dispatch(const utility::Message &msg)
183 {
184 HfpHfMessage &event = (HfpHfMessage &)msg;
185 LOG_DEBUG("[HFP HF]%{public}s():[Disconnecting][%{public}s]", __FUNCTION__, HfpHfStateMachine::GetEventName(event.what_).c_str());
186 switch (event.what_) {
187 case HFP_HF_CONNECT_EVT:
188 stateMachine_.AddDeferredMessage(event);
189 break;
190 case HFP_HF_DISCONNECTED_EVT:
191 IPowerManager::GetInstance().StatusUpdate(
192 RequestStatus::CONNECT_OFF, PROFILE_NAME_HFP_HF, RawAddress(event.dev_));
193 profile_.RemoveRemoteScnLoging();
194 Transition(HfpHfStateMachine::DISCONNECTED);
195 break;
196 case HFP_HF_DISCONNECT_FAILED_EVT:
197 case HFP_HF_CONNECTION_TIMEOUT_EVT:
198 Transition(HfpHfStateMachine::CONNECTED);
199 break;
200 case HFP_HF_AUDIO_CONNECT_REQUEST_EVT:
201 profile_.RejectAudioConnection();
202 break;
203 default:
204 break;
205 }
206 return true;
207 }
208
Entry()209 void HfpHfConnected::Entry()
210 {
211 stateMachine_.ProcessDeferredMessage();
212 stateMachine_.NotifyStateTransitions();
213 }
214
Dispatch(const utility::Message & msg)215 bool HfpHfConnected::Dispatch(const utility::Message &msg)
216 {
217 HfpHfMessage &event = (HfpHfMessage &)msg;
218 LOG_DEBUG("[HFP HF]%{public}s():[Connected][%{public}s]", __FUNCTION__, HfpHfStateMachine::GetEventName(event.what_).c_str());
219 switch (event.what_) {
220 case HFP_HF_CONNECT_AUDIO_EVT:
221 case HFP_HF_RETRY_CONNECT_AUDIO_EVT:
222 profile_.SetupCodecConnection();
223 Transition(HfpHfStateMachine::AUDIO_CONNECTING);
224 break;
225 case HFP_HF_AUDIO_CONNECT_REQUEST_EVT:
226 profile_.ProcessAudioConnectRequest();
227 Transition(HfpHfStateMachine::AUDIO_CONNECTING);
228 break;
229 case HFP_HF_AUDIO_CONNECTING_EVT:
230 Transition(HfpHfStateMachine::AUDIO_CONNECTING);
231 break;
232 case HFP_HF_AUDIO_CONNECTED_EVT:
233 IPowerManager::GetInstance().StatusUpdate(
234 RequestStatus::SCO_ON, PROFILE_NAME_HFP_HF, RawAddress(event.dev_));
235 Transition(HfpHfStateMachine::AUDIO_CONNECTED);
236 break;
237 case HFP_HF_DISCONNECT_EVT:
238 profile_.ReleaseDataConnection();
239 Transition(HfpHfStateMachine::DISCONNECTING);
240 break;
241 case HFP_HF_DISCONNECTED_EVT:
242 IPowerManager::GetInstance().StatusUpdate(
243 RequestStatus::CONNECT_OFF, PROFILE_NAME_HFP_HF, RawAddress(event.dev_));
244 profile_.RemoveRemoteScnLoging();
245 Transition(HfpHfStateMachine::DISCONNECTED);
246 break;
247 case HFP_HF_DATA_AVAILABLE_EVT:
248 profile_.ReadData();
249 break;
250 case HFP_HF_INTERACTIVE_EVT:
251 stateMachine_.ProcessInteractiveEvent(event);
252 break;
253 case HFP_HF_SEND_DTMF_EVT:
254 profile_.SendDtmf(event.arg1_);
255 break;
256 case HFP_HF_SET_VOLUME_EVT:
257 profile_.SetHfVolume(event.arg1_, event.arg3_);
258 break;
259 case HFP_HF_ACCEPT_CALL_EVT:
260 stateMachine_.ProcessAcceptCall(event.arg1_);
261 break;
262 case HFP_HF_HOLD_CALL_EVT:
263 stateMachine_.ProcessHoldCall();
264 break;
265 case HFP_HF_REJECT_CALL_EVT:
266 stateMachine_.ProcessRejectCall();
267 break;
268 case HFP_HF_SEND_KEY_PRESSED:
269 stateMachine_.PrecessSendKeyPressed();
270 break;
271 case HFP_HF_HANDLE_INCOMING_CALL_EVT:
272 stateMachine_.ProcessHandleIncomingCall(event.arg1_);
273 break;
274 case HFP_HF_HANDLE_MULTI_CALL_EVT:
275 stateMachine_.ProcessHandleMultiCall(event.arg1_, event.arg3_);
276 break;
277 case HFP_HF_DIAL_LAST_NUMBER:
278 stateMachine_.ProcessDialLastNumber();
279 break;
280 case HFP_HF_DIAL_MEMORY:
281 stateMachine_.ProcessDialMemory(event.arg1_);
282 break;
283 case HFP_HF_SEND_VOICE_TAG:
284 stateMachine_.ProcessSendVoiceTag(event.arg1_);
285 break;
286 case HFP_HF_FINISH_CALL_EVT:
287 stateMachine_.ProcessFinishCall(event);
288 break;
289 case HFP_HF_DIAL_CALL_EVT:
290 stateMachine_.ProcessDialCall(event);
291 break;
292 case HFP_HF_OPEN_VOICE_RECOGNITION_EVT:
293 stateMachine_.ProcessOpenVoiceRecognition();
294 break;
295 case HFP_HF_CLOSE_VOICE_RECOGNITION_EVT:
296 stateMachine_.ProcessCloseVoiceRecognition();
297 break;
298 case HFP_HF_BATTERY_LEVEL_CHANGED_EVT:
299 profile_.ReportBatteryLevel(event.arg1_);
300 break;
301 case HFP_HF_ENHANCED_DRIVER_SAFETY_CHANGED_EVT:
302 profile_.ReportDriverSafety(event.arg1_);
303 break;
304 case HFP_HF_SEND_AT_COMMAND_EVT:
305 profile_.SendAtCommand(event.arg1_, event.str_);
306 break;
307 default:
308 break;
309 }
310 return true;
311 }
312
Entry()313 void HfpHfAudioConnecting::Entry()
314 {
315 stateMachine_.ProcessDeferredMessage();
316 stateMachine_.NotifyStateTransitions();
317 stateMachine_.StartConnectionTimer();
318 }
319
Exit()320 void HfpHfAudioConnecting::Exit()
321 {
322 stateMachine_.StopConnectionTimer();
323 }
324
Dispatch(const utility::Message & msg)325 bool HfpHfAudioConnecting::Dispatch(const utility::Message &msg)
326 {
327 HfpHfMessage &event = (HfpHfMessage &)msg;
328 LOG_DEBUG("[HFP HF]%{public}s():[AudioConnecting][%{public}s]", __FUNCTION__,
329 HfpHfStateMachine::GetEventName(event.what_).c_str());
330 switch (event.what_) {
331 case HFP_HF_CONNECT_AUDIO_EVT:
332 case HFP_HF_AUDIO_CONNECTING_EVT:
333 break;
334 case HFP_HF_AUDIO_CONNECT_REQUEST_EVT:
335 profile_.ProcessAudioConnReqInAudioConnecting();
336 break;
337 case HFP_HF_DISCONNECT_AUDIO_EVT:
338 case HFP_HF_DISCONNECT_EVT:
339 stateMachine_.AddDeferredMessage(event);
340 break;
341 case HFP_HF_AUDIO_CONNECTED_EVT:
342 IPowerManager::GetInstance().StatusUpdate(
343 RequestStatus::SCO_ON, PROFILE_NAME_HFP_HF, RawAddress(event.dev_));
344 profile_.RestorCodecSetupRole();
345 Transition(HfpHfStateMachine::AUDIO_CONNECTED);
346 break;
347 case HFP_HF_AUDIO_CONNECT_FAILED_EVT:
348 case HFP_HF_CONNECTION_TIMEOUT_EVT:
349 case HFP_HF_AUDIO_DISCONNECTED_EVT:
350 profile_.RestorCodecSetupRole();
351 stateMachine_.NotifyChildStateToParentState(HFP_HF_AUDIO_STATE_CONNECTING, HFP_HF_AUDIO_STATE_DISCONNECTED);
352 Transition(HfpHfStateMachine::CONNECTED);
353 break;
354 case HFP_HF_DISCONNECTED_EVT:
355 stateMachine_.AddDeferredMessage(event);
356 stateMachine_.NotifyChildStateToParentState(HFP_HF_AUDIO_STATE_CONNECTING, HFP_HF_AUDIO_STATE_DISCONNECTED);
357 Transition(HfpHfStateMachine::CONNECTED);
358 break;
359 default:
360 return false;
361 }
362 return true;
363 }
364
Entry()365 void HfpHfAudioDisconnecting::Entry()
366 {
367 stateMachine_.NotifyStateTransitions();
368 stateMachine_.StartConnectionTimer();
369 }
370
Exit()371 void HfpHfAudioDisconnecting::Exit()
372 {
373 stateMachine_.StopConnectionTimer();
374 }
375
Dispatch(const utility::Message & msg)376 bool HfpHfAudioDisconnecting::Dispatch(const utility::Message &msg)
377 {
378 HfpHfMessage &event = (HfpHfMessage &)msg;
379 LOG_DEBUG("[HFP HF]%{public}s():[AudioConnected][%{public}s]", __FUNCTION__,
380 HfpHfStateMachine::GetEventName(event.what_).c_str());
381 switch (event.what_) {
382 case HFP_HF_DISCONNECT_EVT:
383 case HFP_HF_CONNECT_AUDIO_EVT:
384 case HFP_HF_AUDIO_CONNECT_REQUEST_EVT:
385 case HFP_HF_DISCONNECTED_EVT:
386 stateMachine_.AddDeferredMessage(event);
387 break;
388 case HFP_HF_AUDIO_CONNECTING_EVT:
389 case HFP_HF_DISCONNECT_AUDIO_EVT:
390 case HFP_HF_AUDIO_DISCONNECTING_EVT:
391 case HFP_HF_AUDIO_CONNECTED_EVT:
392 case HFP_HF_AUDIO_CONNECT_FAILED_EVT:
393 break;
394 case HFP_HF_AUDIO_DISCONNECTED_EVT:
395 stateMachine_.ProcessAudioDisconnected();
396 Transition(HfpHfStateMachine::CONNECTED);
397 break;
398 case HFP_HF_AUDIO_DISCONNECT_FAILED_EVT:
399 case HFP_HF_CONNECTION_TIMEOUT_EVT:
400 stateMachine_.NotifyChildStateToParentState(HFP_HF_AUDIO_STATE_DISCONNECTING, HFP_HF_AUDIO_STATE_CONNECTED);
401 Transition(HfpHfStateMachine::AUDIO_CONNECTED);
402 break;
403 default:
404 return false;
405 }
406 return true;
407 }
408
Entry()409 void HfpHfAudioConnected::Entry()
410 {
411 stateMachine_.ProcessDeferredMessage();
412 stateMachine_.NotifyStateTransitions();
413 }
414
Dispatch(const utility::Message & msg)415 bool HfpHfAudioConnected::Dispatch(const utility::Message &msg)
416 {
417 HfpHfMessage &event = (HfpHfMessage &)msg;
418 LOG_DEBUG("[HFP HF]%{public}s():[AudioConnected][%{public}s]", __FUNCTION__,
419 HfpHfStateMachine::GetEventName(event.what_).c_str());
420 switch (event.what_) {
421 case HFP_HF_DISCONNECT_EVT:
422 ProcessDisconnect(event);
423 break;
424 case HFP_HF_DISCONNECTED_EVT:
425 stateMachine_.AddDeferredMessage(event);
426 break;
427 case HFP_HF_CONNECT_AUDIO_EVT:
428 case HFP_HF_AUDIO_CONNECT_REQUEST_EVT:
429 case HFP_HF_AUDIO_CONNECTING_EVT:
430 case HFP_HF_AUDIO_CONNECTED_EVT:
431 break;
432 case HFP_HF_AUDIO_DISCONNECTING_EVT:
433 Transition(HfpHfStateMachine::AUDIO_DISCONNECTING);
434 break;
435 case HFP_HF_DISCONNECT_AUDIO_EVT:
436 profile_.ReleaseAudioConnection();
437 break;
438 case HFP_HF_AUDIO_DISCONNECTED_EVT:
439 stateMachine_.ProcessAudioDisconnected();
440 Transition(HfpHfStateMachine::CONNECTED);
441 break;
442 default:
443 return false;
444 }
445 return true;
446 }
447
ProcessDisconnect(const HfpHfMessage & event)448 void HfpHfAudioConnected::ProcessDisconnect(const HfpHfMessage &event)
449 {
450 profile_.ReleaseAudioConnection();
451 stateMachine_.routeHfAudio(false);
452 stateMachine_.AddDeferredMessage(event);
453 }
454
ProcessFinishCall(const HfpHfMessage & event)455 void HfpHfStateMachine::ProcessFinishCall(const HfpHfMessage &event)
456 {
457 if ((calls_->GetCallByState(HFP_HF_CALL_STATE_ACTIVE) != nullptr) ||
458 (calls_->GetCallByState(HFP_HF_CALL_STATE_DIALING) != nullptr) ||
459 (calls_->GetCallByState(HFP_HF_CALL_STATE_ALERTING) != nullptr)) {
460 LOG_DEBUG("[HFP HF]%{public}s():Finish active or dialing or alerting call", __FUNCTION__);
461 if (!profile_.SendChup()) {
462 LOG_ERROR("[HFP HF]%{public}s():Send CHUP failed", __FUNCTION__);
463 }
464 } else if (calls_->GetCallByState(HFP_HF_CALL_STATE_HELD) != nullptr) {
465 LOG_DEBUG("[HFP HF]%{public}s():Finish hold call", __FUNCTION__);
466 if (!profile_.SendChld(HFP_HF_CHLD_ACTION_0)) {
467 LOG_ERROR("[HFP HF]%{public}s():Send CHLD 0 failed", __FUNCTION__);
468 }
469 } else {
470 LOG_DEBUG("[HFP HF]%{public}s():no call to finish", __FUNCTION__);
471 }
472 return;
473 }
474
ProcessDialCall(const HfpHfMessage & event)475 void HfpHfStateMachine::ProcessDialCall(const HfpHfMessage &event)
476 {
477 profile_.DialOutCall(event.calls_.GetNumber());
478 }
479
ProcessOpenVoiceRecognition()480 void HfpHfStateMachine::ProcessOpenVoiceRecognition()
481 {
482 if (GetOpenVoiceRecognitionState() == HFP_HF_VR_STATE_CLOSED) {
483 if (!profile_.OpenVoiceRecognition()) {
484 LOG_ERROR("[HFP HF]%{public}s():can't open the voice recognition!", __FUNCTION__);
485 }
486 }
487 }
488
ProcessCloseVoiceRecognition()489 void HfpHfStateMachine::ProcessCloseVoiceRecognition()
490 {
491 if (GetOpenVoiceRecognitionState() == HFP_HF_VR_STATE_OPENED) {
492 if (!profile_.CloseVoiceRecognition()) {
493 LOG_ERROR("[HFP HF]%{public}s():can't close the voice recognition!", __FUNCTION__);
494 }
495 }
496 }
497
ProcessRejectCall()498 void HfpHfStateMachine::ProcessRejectCall()
499 {
500 if (calls_->GetCallByState(HFP_HF_CALL_STATE_INCOMING) != nullptr) {
501 LOG_DEBUG("[HFP HF]%{public}s():Reject incoming call", __FUNCTION__);
502 if (!profile_.SendChup()) {
503 LOG_ERROR("[HFP HF]%{public}s():Send CHUP failed", __FUNCTION__);
504 }
505 } else if ((calls_->GetCallByState(HFP_HF_CALL_STATE_HELD) != nullptr) ||
506 (calls_->GetCallByState(HFP_HF_CALL_STATE_WAITING) != nullptr)) {
507 LOG_DEBUG("[HFP HF]%{public}s():Reject held or waiting call", __FUNCTION__);
508 if (!profile_.SendChld(HFP_HF_CHLD_ACTION_0)) {
509 LOG_ERROR("[HFP HF]%{public}s():Send CHLD 0 failed", __FUNCTION__);
510 }
511 } else {
512 LOG_DEBUG("[HFP HF]%{public}s():No call to reject", __FUNCTION__);
513 }
514 return;
515 }
516
PrecessSendKeyPressed()517 void HfpHfStateMachine::PrecessSendKeyPressed()
518 {
519 LOG_INFO("[HFP HF]%{public}s():enter", __FUNCTION__);
520 if (!profile_.SendKeyPressed()) {
521 LOG_ERROR("[HFP HF]%{public}s():PrecessSendKeyPressed failed", __FUNCTION__);
522 }
523 }
524
ProcessHandleIncomingCall(int flag)525 void HfpHfStateMachine::ProcessHandleIncomingCall(int flag)
526 {
527 HILOGI("[HFP HF]:handle incoming call flag = %{public}d", flag);
528 if (calls_->GetCallByState(HFP_HF_CALL_STATE_INCOMING) != nullptr) {
529 if (flag != static_cast<int>(HfpHfHandleIncomingCalAction::HFP_HF_HOLD_INCOMING_ACTION)) {
530 HILOGE("[HFP HF]:No incoming call hold");
531 }
532 if (profile_.SendBtrh(flag)) {
533 HILOGE("[HFP HF]:Send BTRH = %{public}d failed", flag);
534 }
535 } else if (calls_->GetCallByState(HFP_HF_CALL_STATE_RESPONSE_HELD) != nullptr) {
536 if (!profile_.SendBtrh(flag)) {
537 HILOGE("[HFP HF]:Send BTRH = %{public}d failed", flag);
538 }
539 } else {
540 HILOGI("[HFP HF]:No call handle");
541 }
542 return;
543 }
544
ProcessHandleMultiCall(int flag,int index)545 void HfpHfStateMachine::ProcessHandleMultiCall(int flag, int index)
546 {
547 HILOGI("[HFP HF]:enter flag = %{public}d, index = %{public}d", flag, index);
548 if (!profile_.SendChld(flag, index)) {
549 HILOGE("[HFP HF]:Send CHLD failed");
550 }
551 }
552
ProcessDialLastNumber()553 void HfpHfStateMachine::ProcessDialLastNumber()
554 {
555 HILOGI("[HFP HF]:enter");
556 if (!profile_.CallLastDialedNumber()) {
557 HILOGE("[HFP HF]:ProcessDialLastNumber failed");
558 }
559 }
560
ProcessDialMemory(int index)561 void HfpHfStateMachine::ProcessDialMemory(int index)
562 {
563 HILOGI("[HFP HF]:enter index = %{public}d", index);
564 if (!profile_.DialMemory(index)) {
565 HILOGE("[HFP HF]:ProcessDialMemory failed");
566 }
567 }
568
ProcessSendVoiceTag(int index)569 void HfpHfStateMachine::ProcessSendVoiceTag(int index)
570 {
571 LOG_INFO("[HFP HF]%{public}s():enter index = %{public}d", __FUNCTION__, index);
572 if (!profile_.SendVoiceTag(index)) {
573 LOG_ERROR("[HFP HF]%{public}s():ProcessSendVoiceTag failed", __FUNCTION__);
574 }
575 }
576
ProcessHoldCall()577 void HfpHfStateMachine::ProcessHoldCall()
578 {
579 if (calls_->GetCallByState(HFP_HF_CALL_STATE_ACTIVE) != nullptr) {
580 LOG_DEBUG("[HFP HF]%{public}s():Hold active call", __FUNCTION__);
581 if (!profile_.SendChld(HFP_HF_CHLD_ACTION_2)) {
582 LOG_ERROR("[HFP HF]%{public}s():Send CHLD 2 failed", __FUNCTION__);
583 }
584 } else {
585 LOG_DEBUG("[HFP HF]%{public}s():No call to hold", __FUNCTION__);
586 }
587 return;
588 }
589
ProcessAcceptCall(int flag)590 void HfpHfStateMachine::ProcessAcceptCall(int flag)
591 {
592 if (calls_->GetCallByState(HFP_HF_CALL_STATE_INCOMING) != nullptr) {
593 if (flag != HFP_HF_ACCEPT_CALL_ACTION_NONE) {
594 return;
595 }
596
597 LOG_DEBUG("[HFP HF]%{public}s():Accept incoming call", __FUNCTION__);
598 if (!profile_.SendAta()) {
599 LOG_ERROR("[HFP HF]%{public}s():Send ATA failed", __FUNCTION__);
600 }
601 } else if (calls_->GetCallByState(HFP_HF_CALL_STATE_WAITING) != nullptr) {
602 if ((calls_->GetCallByState(HFP_HF_CALL_STATE_ACTIVE) == nullptr) && (flag != HFP_HF_ACCEPT_CALL_ACTION_NONE)) {
603 return;
604 }
605
606 int action;
607 if ((flag == HFP_HF_ACCEPT_CALL_ACTION_NONE) || (flag == HFP_HF_ACCEPT_CALL_ACTION_HOLD)) {
608 action = HFP_HF_CHLD_ACTION_2;
609 } else if (flag == HFP_HF_ACCEPT_CALL_ACTION_FINISH) {
610 action = HFP_HF_CHLD_ACTION_1;
611 } else {
612 LOG_ERROR("[HFP HF]%{public}s():Invalid flag[%{public}d]", __FUNCTION__, flag);
613 return;
614 }
615
616 LOG_DEBUG("[HFP HF]%{public}s():Accept waiting call", __FUNCTION__);
617 if (!profile_.SendChld(action)) {
618 LOG_ERROR("[HFP HF]%{public}s():Send CHLD[%{public}d] failed", __FUNCTION__, action);
619 }
620 } else if (calls_->GetCallByState(HFP_HF_CALL_STATE_HELD) != nullptr) {
621 int action = HFP_HF_CHLD_ACTION_2;
622 if (flag == HFP_HF_ACCEPT_CALL_ACTION_FINISH) {
623 action = HFP_HF_CHLD_ACTION_1;
624 } else if ((flag == HFP_HF_ACCEPT_CALL_ACTION_NONE) || (flag == HFP_HF_ACCEPT_CALL_ACTION_HOLD)) {
625 action = HFP_HF_CHLD_ACTION_2;
626 } else if (calls_->GetCallByState(HFP_HF_CALL_STATE_ACTIVE) != nullptr) {
627 action = HFP_HF_CHLD_ACTION_3;
628 }
629
630 LOG_DEBUG("[HFP HF]%{public}s():Accept held call", __FUNCTION__);
631 if (!profile_.SendChld(action)) {
632 LOG_ERROR("[HFP HF]%{public}s():Send CHLD[%{public}d] failed", __FUNCTION__, action);
633 }
634 } else {
635 LOG_DEBUG("[HFP HF]%{public}s():No call to accept", __FUNCTION__);
636 }
637
638 if (flag == HFP_HF_ACCEPT_CALL_ACTION_HOLD) {
639 routeHfAudio(true);
640 }
641 return;
642 }
643
ProcessInteractiveEvent(const HfpHfMessage & event)644 void HfpHfStateMachine::ProcessInteractiveEvent(const HfpHfMessage &event)
645 {
646 LOG_DEBUG("[HFP HF]%{public}s():[%{public}s]", __FUNCTION__, GetInteractiveEventType(event.type_).c_str());
647 switch (event.type_) {
648 case HFP_HF_TYPE_NETWORK_STATE:
649 ProcessNetworkStateEvent(event);
650 break;
651 case HFP_HF_TYPE_NETWORK_ROAM:
652 ProcessNetworkRoamEvent(event);
653 break;
654 case HFP_HF_TYPE_NETWORK_SIGNAL:
655 ProcessNetworkSignalEvent(event);
656 break;
657 case HFP_HF_TYPE_BATTERY_LEVEL:
658 ProcessBatteryLevelEvent(event);
659 break;
660 case HFP_HF_TYPE_CURRENT_OPERATOR:
661 ProcessOperatorEvent(event);
662 break;
663 case HFP_HF_TYPE_CALL_STATE:
664 case HFP_HF_TYPE_CALL_SETUP_STATE:
665 case HFP_HF_TYPE_CALL_HELD_STATE:
666 case HFP_HF_TYPE_HOLD_RESULT:
667 case HFP_HF_TYPE_CALLING_LINE_IDENTIFICATION:
668 case HFP_HF_TYPE_CALL_WAITING:
669 ProcessCallIndicatorEvent(event);
670 break;
671 case HFP_HF_TYPE_CURRENT_CALLS:
672 ProcessCurrentCallEvent(event);
673 break;
674 case HFP_HF_TYPE_SET_VOLUME:
675 ProcessSetVolumeEvent(event);
676 break;
677 case HFP_HF_TYPE_SUBSCRIBER_NUMBER:
678 ProcessSubscriberNumberEvent(event);
679 break;
680 case HFP_HF_TYPE_INBAND_RING:
681 ProcessInbandRingEvent(event);
682 break;
683 case HFP_HF_TYPE_QUERY_CURRENT_CALLS_DONE:
684 calls_->UpdateCallDone();
685 break;
686 case HFP_HF_TYPE_VOICE_RECOGNITION_CHANGED:
687 ProcessVrChangedEvent(event);
688 break;
689 case HFP_HF_TYPE_OPEN_VR_RESULT:
690 ProcessOpenVrResultEvent(event);
691 break;
692 case HFP_HF_TYPE_CLOSE_VR_RESULT:
693 ProcessCloseVrResultEvent(event);
694 break;
695 default:
696 break;
697 }
698 }
699
NotifyStateTransitions()700 void HfpHfStateMachine::NotifyStateTransitions()
701 {
702 HfpHfService *service = HfpHfService::GetService();
703 int toState = GetDeviceStateInt();
704 if (service != nullptr) {
705 RawAddress device(address_);
706 if ((preState_ != toState) && (preState_ <= HFP_HF_STATE_CONNECTED) && (toState <= HFP_HF_STATE_CONNECTED)) {
707 service->NotifyStateChanged(device, toState);
708 }
709
710 if ((preState_ != toState) && (preState_ >= HFP_HF_AUDIO_STATE_DISCONNECTED) &&
711 (toState >= HFP_HF_AUDIO_STATE_DISCONNECTED)) {
712 service->NotifyScoStateChanged(device, toState);
713 }
714 }
715
716 if (toState == HFP_HF_AUDIO_STATE_CONNECTED) {
717 SyncScoEvents(toState);
718 }
719
720 preState_ = toState;
721 }
722
NotifyChildStateToParentState(int fromState,int toState)723 void HfpHfStateMachine::NotifyChildStateToParentState(int fromState, int toState)
724 {
725 HfpHfService *service = HfpHfService::GetService();
726 if (service != nullptr) {
727 if ((fromState != toState) && (fromState >= HFP_HF_AUDIO_STATE_DISCONNECTED) &&
728 (toState >= HFP_HF_AUDIO_STATE_DISCONNECTED)) {
729 RawAddress device(address_);
730 service->NotifyScoStateChanged(device, toState);
731 }
732 }
733
734 if (toState == HFP_HF_AUDIO_STATE_DISCONNECTED) {
735 SyncScoEvents(toState);
736 }
737
738 preState_ = toState;
739 ProcessDeferredMessage();
740 }
741
ProcessAudioDisconnected()742 void HfpHfStateMachine::ProcessAudioDisconnected()
743 {
744 IPowerManager::GetInstance().StatusUpdate(RequestStatus::SCO_OFF, PROFILE_NAME_HFP_HF, RawAddress(address_));
745 NotifyChildStateToParentState(HFP_HF_AUDIO_STATE_CONNECTED, HFP_HF_AUDIO_STATE_DISCONNECTED);
746 }
747
SyncScoEvents(int state)748 void HfpHfStateMachine::SyncScoEvents(int state)
749 {
750 if (state == HFP_HF_AUDIO_STATE_CONNECTED) {
751 int spkVolume = OHOS::AudioStandard::AudioSystemManager::GetInstance()->GetVolume(
752 OHOS::AudioStandard::STREAM_VOICE_CALL);
753 int micVolume = OHOS::AudioStandard::AudioSystemManager::GetInstance()->GetVolume(
754 OHOS::AudioStandard::STREAM_VOICE_CALL);
755 profile_.SetHfVolume(spkVolume, HFP_HF_VOLUME_TYPE_SPK);
756 profile_.SetHfVolume(micVolume, HFP_HF_VOLUME_TYPE_MIC);
757
758 routeHfAudio(true);
759 OHOS::AudioStandard::AudioSystemManager::GetInstance()->SetAudioParameter(
760 "hfp_volume", std::to_string(spkVolume));
761 }
762
763 if (state == HFP_HF_AUDIO_STATE_DISCONNECTED) {
764 routeHfAudio(false);
765 if (voiceRecognitionStatus_ == HFP_HF_VR_STATE_OPENED) {
766 NotifyVoiceRecognitionStatusChanged(HFP_HF_VR_STATE_CLOSED);
767 }
768 }
769 }
770
GetOpenVoiceRecognitionState() const771 int HfpHfStateMachine::GetOpenVoiceRecognitionState() const
772 {
773 return voiceRecognitionStatus_;
774 }
775
GetIsInbandRing() const776 bool HfpHfStateMachine::GetIsInbandRing() const
777 {
778 return isInBandRing_;
779 }
780
GetVolume() const781 int HfpHfStateMachine::GetVolume() const
782 {
783 return volume_;
784 }
785
GetDeviceStateInt() const786 int HfpHfStateMachine::GetDeviceStateInt() const
787 {
788 return static_cast<const HfpHfState*>(GetState())->GetStateInt();
789 }
790
GetCurrentCallList()791 std::vector<HandsFreeUnitCalls> HfpHfStateMachine::GetCurrentCallList()
792 {
793 return calls_->GetCurrentCalls();
794 }
795
AddDeferredMessage(const HfpHfMessage & msg)796 void HfpHfStateMachine::AddDeferredMessage(const HfpHfMessage &msg)
797 {
798 deferMsgs_.push_back(msg);
799 }
800
ProcessDeferredMessage()801 void HfpHfStateMachine::ProcessDeferredMessage()
802 {
803 auto size = deferMsgs_.size();
804 while (size-- > 0 && !deferMsgs_.empty()) {
805 HfpHfMessage event = deferMsgs_.front();
806 deferMsgs_.pop_front();
807 HfpHfService::GetService()->PostEvent(event);
808 }
809 }
810
StartConnectionTimer() const811 void HfpHfStateMachine::StartConnectionTimer() const
812 {
813 connTimer_->Start(CONNECTION_TIMEOUT_MS);
814 LOG_INFO("[HFP HF]%{public}s():Start connection timer!", __FUNCTION__);
815 }
816
StopConnectionTimer() const817 void HfpHfStateMachine::StopConnectionTimer() const
818 {
819 connTimer_->Stop();
820 LOG_INFO("[HFP HF]%{public}s():Stop connection timer!", __FUNCTION__);
821 }
822
ConnectionTimeout() const823 void HfpHfStateMachine::ConnectionTimeout() const
824 {
825 HfpHfMessage event(HFP_HF_CONNECTION_TIMEOUT_EVT);
826 event.dev_ = address_;
827 HfpHfService::GetService()->PostEvent(event);
828 }
829
IsRemoving() const830 bool HfpHfStateMachine::IsRemoving() const
831 {
832 return isRemoving_;
833 }
834
SetRemoving(bool isRemoving)835 void HfpHfStateMachine::SetRemoving(bool isRemoving)
836 {
837 isRemoving_ = isRemoving;
838 }
839
ProcessNetworkStateEvent(const HfpHfMessage & event)840 void HfpHfStateMachine::ProcessNetworkStateEvent(const HfpHfMessage &event)
841 {
842 HfpHfService *service = HfpHfService::GetService();
843 RawAddress rawAddress(address_);
844 if (networkState_ != event.arg1_) {
845 networkState_ = event.arg1_;
846 service->NotifyRegistrationStatusChanged(rawAddress, networkState_);
847 }
848
849 if (networkState_ == HFP_HF_NETWORK_STATE_AVAILABLE) {
850 if (!profile_.QueryOperatorName(true)) {
851 LOG_ERROR("[HFP HF]%{public}s():can't query the operator name!", __FUNCTION__);
852 }
853 }
854 }
ProcessNetworkRoamEvent(const HfpHfMessage & event)855 void HfpHfStateMachine::ProcessNetworkRoamEvent(const HfpHfMessage &event)
856 {
857 HfpHfService *service = HfpHfService::GetService();
858 RawAddress rawAddress(address_);
859 if (networkTRoam_ != event.arg1_) {
860 networkTRoam_ = event.arg1_;
861 service->NotifyRoamingStatusChanged(rawAddress, networkTRoam_);
862 }
863 }
ProcessNetworkSignalEvent(const HfpHfMessage & event)864 void HfpHfStateMachine::ProcessNetworkSignalEvent(const HfpHfMessage &event)
865 {
866 HfpHfService *service = HfpHfService::GetService();
867 RawAddress rawAddress(address_);
868 if (networkSignal_ != event.arg1_) {
869 networkSignal_ = event.arg1_;
870 service->NotifySignalStrengthChanged(rawAddress, networkSignal_);
871 }
872 }
ProcessBatteryLevelEvent(const HfpHfMessage & event)873 void HfpHfStateMachine::ProcessBatteryLevelEvent(const HfpHfMessage &event)
874 {
875 HfpHfService *service = HfpHfService::GetService();
876 RawAddress rawAddress(address_);
877 if (batteryLevel_ != event.arg1_) {
878 batteryLevel_ = event.arg1_;
879 service->NotifyBatteryLevelChanged(rawAddress, batteryLevel_);
880 }
881 }
882
ProcessOperatorEvent(const HfpHfMessage & event)883 void HfpHfStateMachine::ProcessOperatorEvent(const HfpHfMessage &event)
884 {
885 HfpHfService *service = HfpHfService::GetService();
886 RawAddress rawAddress(address_);
887 if (operatorName_ != event.str_) {
888 operatorName_ = event.str_;
889 service->NotifyOperatorSelectionChanged(rawAddress, operatorName_);
890 }
891 }
892
ProcessCallIndicatorEvent(const HfpHfMessage & event)893 void HfpHfStateMachine::ProcessCallIndicatorEvent(const HfpHfMessage &event)
894 {
895 if (!profile_.QueryCurrentCalls()) {
896 LOG_ERROR("[HFP HF]%{public}s():can't query the current calls!", __FUNCTION__);
897 }
898 }
899
ProcessCurrentCallEvent(const HfpHfMessage & event) const900 void HfpHfStateMachine::ProcessCurrentCallEvent(const HfpHfMessage &event) const
901 {
902 HandsFreeUnitCalls call(address_,
903 event.call_.index,
904 event.call_.status,
905 event.call_.number,
906 (event.call_.mprty == HFP_HF_MPTY_TYPE_MULTI),
907 (event.call_.dir == HFP_HF_DIRECTION_TYPE_OUTGOING),
908 isInBandRing_);
909 calls_->UpdateCall(call);
910 }
911
ProcessSetVolumeEvent(const HfpHfMessage & event) const912 void HfpHfStateMachine::ProcessSetVolumeEvent(const HfpHfMessage &event) const
913 {
914 if (event.arg1_ == HFP_HF_VOLUME_TYPE_SPK) {
915 OHOS::AudioStandard::AudioSystemManager::GetInstance()->SetVolume(
916 OHOS::AudioStandard::STREAM_VOICE_CALL, event.arg3_);
917 } else if (event.arg1_ == HFP_HF_VOLUME_TYPE_MIC) {
918 OHOS::AudioStandard::AudioSystemManager::GetInstance()->SetMicrophoneMute(event.arg3_ == 0);
919 } else {
920 LOG_ERROR("[HFP HF]%{public}s():the error volume type!", __FUNCTION__);
921 }
922 }
923
ProcessSubscriberNumberEvent(const HfpHfMessage & event)924 void HfpHfStateMachine::ProcessSubscriberNumberEvent(const HfpHfMessage &event)
925 {
926 HfpHfService *service = HfpHfService::GetService();
927 RawAddress rawAddress(address_);
928 if (subscriberNumber_ != event.str_) {
929 subscriberNumber_ = event.str_;
930 if (service != nullptr) {
931 service->NotifySubscriberNumberChanged(rawAddress, subscriberNumber_);
932 } else {
933 LOG_DEBUG("[HFP HF]%{public}s():service is null.", __FUNCTION__);
934 }
935 }
936 }
ProcessInbandRingEvent(const HfpHfMessage & event)937 void HfpHfStateMachine::ProcessInbandRingEvent(const HfpHfMessage &event)
938 {
939 HfpHfService *service = HfpHfService::GetService();
940 RawAddress rawAddress(address_);
941 bool ring = (event.arg1_ == 0) ? false : true;
942 bool isFirstTime = (event.arg3_ == 0) ? false : true;
943 if (isInBandRing_ != ring || isFirstTime == true) {
944 isInBandRing_ = ring;
945 service->NotifyInBandRingTone(rawAddress, event.arg1_);
946 }
947 }
948
NotifyVoiceRecognitionStatusChanged(int status)949 void HfpHfStateMachine::NotifyVoiceRecognitionStatusChanged(int status)
950 {
951 if (status == voiceRecognitionStatus_) {
952 return;
953 }
954 voiceRecognitionStatus_ = status;
955 HfpHfService *service = HfpHfService::GetService();
956 if (service != nullptr) {
957 RawAddress device(address_);
958 service->NotifyVoiceRecognitionStatusChanged(device, voiceRecognitionStatus_);
959 }
960 }
961
routeHfAudio(bool state)962 void HfpHfStateMachine::routeHfAudio(bool state)
963 {
964 if (state) {
965 if (!isAudioRouted_) {
966 OHOS::AudioStandard::AudioSystemManager::GetInstance()->SetAudioParameter("hfp_enable", "true");
967 }
968 } else {
969 OHOS::AudioStandard::AudioSystemManager::GetInstance()->SetAudioParameter("hfp_enable", "false");
970 }
971 isAudioRouted_ = state;
972 }
973
ProcessVrChangedEvent(const HfpHfMessage & event)974 void HfpHfStateMachine::ProcessVrChangedEvent(const HfpHfMessage &event)
975 {
976 NotifyVoiceRecognitionStatusChanged(event.arg1_);
977 }
978
ProcessOpenVrResultEvent(const HfpHfMessage & event)979 void HfpHfStateMachine::ProcessOpenVrResultEvent(const HfpHfMessage &event)
980 {
981 int status = voiceRecognitionStatus_;
982 if (event.arg1_ == HFP_HF_AT_RESULT_OK) {
983 status = HFP_HF_VR_STATE_OPENED;
984 }
985
986 NotifyVoiceRecognitionStatusChanged(status);
987 }
988
ProcessCloseVrResultEvent(const HfpHfMessage & event)989 void HfpHfStateMachine::ProcessCloseVrResultEvent(const HfpHfMessage &event)
990 {
991 int status = voiceRecognitionStatus_;
992 if (event.arg1_ == HFP_HF_AT_RESULT_OK) {
993 status = HFP_HF_VR_STATE_CLOSED;
994 }
995
996 NotifyVoiceRecognitionStatusChanged(status);
997 }
998
GetEventName(int what)999 std::string HfpHfStateMachine::GetEventName(int what)
1000 {
1001 switch (what) {
1002 case HFP_HF_INVALID_EVT:
1003 return "HFP_HF_INVALID_EVT";
1004 case HFP_HF_SERVICE_STARTUP_EVT:
1005 return "HFP_HF_SERVICE_STARTUP_EVT";
1006 case HFP_HF_SERVICE_SHUTDOWN_EVT:
1007 return "HFP_HF_SERVICE_SHUTDOWN_EVT";
1008 case HFP_HF_CONNECT_EVT:
1009 return "HFP_HF_CONNECT_EVT";
1010 case HFP_HF_DISCONNECT_EVT:
1011 return "HFP_HF_DISCONNECT_EVT";
1012 case HFP_HF_CONNECT_AUDIO_EVT:
1013 return "HFP_HF_CONNECT_AUDIO_EVT";
1014 case HFP_HF_DISCONNECT_AUDIO_EVT:
1015 return "HFP_HF_DISCONNECT_AUDIO_EVT";
1016 case HFP_HF_RETRY_CONNECT_AUDIO_EVT:
1017 return "HFP_HF_RETRY_CONNECT_AUDIO_EVT";
1018 case HFP_HF_REMOVE_STATE_MACHINE_EVT:
1019 return "HFP_HF_REMOVE_STATE_MACHINE_EVT";
1020 case HFP_HF_INTERACTIVE_EVT:
1021 return "HFP_HF_INTERACTIVE_EVT";
1022 case HFP_HF_CONNECTION_TIMEOUT_EVT:
1023 return "HFP_HF_CONNECTION_TIMEOUT_EVT";
1024 case HFP_HF_DISCONNECT_TIMEOUT_EVT:
1025 return "HFP_HF_DISCONNECT_TIMEOUT_EVT";
1026 case HFP_HF_CONNECT_AUDIO_TIMEOUT_EVT:
1027 return "HFP_HF_CONNECT_AUDIO_TIMEOUT_EVT";
1028 case HFP_HF_DISCONNECT_AUDIO_TIMEOUT_EVT:
1029 return "HFP_HF_DISCONNECT_AUDIO_TIMEOUT_EVT";
1030 case HFP_HF_SEND_DTMF_EVT:
1031 return "HFP_HF_SEND_DTMF_EVT";
1032 case HFP_HF_ACCEPT_CALL_EVT:
1033 return "HFP_HF_ACCEPT_CALL_EVT";
1034 case HFP_HF_HOLD_CALL_EVT:
1035 return "HFP_HF_HOLD_CALL_EVT";
1036 case HFP_HF_REJECT_CALL_EVT:
1037 return "HFP_HF_REJECT_CALL_EVT";
1038 case HFP_HF_HANDLE_INCOMING_CALL_EVT:
1039 return "HFP_HF_HANDLE_INCOMING_CALL_EVT";
1040 case HFP_HF_HANDLE_MULTI_CALL_EVT:
1041 return "HFP_HF_HANDLE_MULTI_CALL_EVT";
1042 case HFP_HF_DIAL_LAST_NUMBER:
1043 return "HFP_HF_DIAL_LAST_NUMBER";
1044 case HFP_HF_DIAL_MEMORY:
1045 return "HFP_HF_DIAL_MEMORY";
1046 case HFP_HF_FINISH_CALL_EVT:
1047 return "HFP_HF_FINISH_CALL_EVT";
1048 case HFP_HF_DIAL_CALL_EVT:
1049 return "HFP_HF_DIAL_CALL_EVT";
1050 case HFP_HF_OPEN_VOICE_RECOGNITION_EVT:
1051 return "HFP_HF_OPEN_VOICE_RECOGNITION_EVT";
1052 case HFP_HF_CLOSE_VOICE_RECOGNITION_EVT:
1053 return "HFP_HF_CLOSE_VOICE_RECOGNITION_EVT";
1054 case HFP_HF_SET_VOLUME_EVT:
1055 return "HFP_HF_SET_VOLUME_EVT";
1056 case HFP_HF_BATTERY_LEVEL_CHANGED_EVT:
1057 return "HFP_HF_BATTERY_LEVEL_CHANGED_EVT";
1058 case HFP_HF_ENHANCED_DRIVER_SAFETY_CHANGED_EVT:
1059 return "HFP_HF_ENHANCED_DRIVER_SAFETY_CHANGED_EVT";
1060 case HFP_HF_SDP_DISCOVERY_RESULT_SUCCESS:
1061 return "HFP_HF_SDP_DISCOVERY_RESULT_SUCCESS";
1062 case HFP_HF_SDP_DISCOVERY_RESULT_FAIL:
1063 return "HFP_HF_SDP_DISCOVERY_RESULT_FAIL";
1064 case HFP_HF_CONNECT_REQUEST_EVT:
1065 return "HFP_HF_CONNECT_REQUEST_EVT";
1066 case HFP_HF_CONNECTED_EVT:
1067 return "HFP_HF_CONNECTED_EVT";
1068 case HFP_HF_DISCONNECTED_EVT:
1069 return "HFP_HF_DISCONNECTED_EVT";
1070 case HFP_HF_CONNECT_FAILED_EVT:
1071 return "HFP_HF_CONNECT_FAILED_EVT";
1072 case HFP_HF_DISCONNECT_FAILED_EVT:
1073 return "HFP_HF_DISCONNECT_FAILED_EVT";
1074 case HFP_HF_DATA_AVAILABLE_EVT:
1075 return "HFP_HF_DATA_AVAILABLE_EVT";
1076 case HFP_HF_SLC_ESTABLISHED_EVT:
1077 return "HFP_HF_SLC_ESTABLISHED_EVT";
1078 case HFP_HF_AUDIO_CONNECT_REQUEST_EVT:
1079 return "HFP_HF_AUDIO_CONNECT_REQUEST_EVT";
1080 case HFP_HF_AUDIO_CONNECTING_EVT:
1081 return "HFP_HF_AUDIO_CONNECTING_EVT";
1082 case HFP_HF_AUDIO_DISCONNECTING_EVT:
1083 return "HFP_HF_AUDIO_DISCONNECTING_EVT";
1084 case HFP_HF_AUDIO_CONNECTED_EVT:
1085 return "HFP_HF_AUDIO_CONNECTED_EVT";
1086 case HFP_HF_AUDIO_CONNECT_FAILED_EVT:
1087 return "HFP_HF_AUDIO_CONNECT_FAILED_EVT";
1088 case HFP_HF_AUDIO_DISCONNECTED_EVT:
1089 return "HFP_HF_AUDIO_DISCONNECTED_EVT";
1090 case HFP_HF_AUDIO_DISCONNECT_FAILED_EVT:
1091 return "HFP_HF_AUDIO_DISCONNECT_FAILED_EVT";
1092 case HFP_HF_SEND_AT_COMMAND_EVT:
1093 return "HFP_HF_SEND_AT_COMMAND_EVT";
1094 default:
1095 return "Unknown";
1096 }
1097 }
1098
GetInteractiveEventType(int type) const1099 std::string HfpHfStateMachine::GetInteractiveEventType(int type) const
1100 {
1101 switch (type) {
1102 case HFP_HF_TYPE_NONE:
1103 return "HFP_HF_TYPE_NONE";
1104 case HFP_HF_TYPE_NETWORK_STATE:
1105 return "HFP_HF_TYPE_NETWORK_STATE";
1106 case HFP_HF_TYPE_NETWORK_ROAM:
1107 return "HFP_HF_TYPE_NETWORK_ROAM";
1108 case HFP_HF_TYPE_NETWORK_SIGNAL:
1109 return "HFP_HF_TYPE_NETWORK_SIGNAL";
1110 case HFP_HF_TYPE_BATTERY_LEVEL:
1111 return "HFP_HF_TYPE_BATTERY_LEVEL";
1112 case HFP_HF_TYPE_CURRENT_OPERATOR:
1113 return "HFP_HF_TYPE_CURRENT_OPERATOR";
1114 case HFP_HF_TYPE_CALL_STATE:
1115 return "HFP_HF_TYPE_CALL_STATE";
1116 case HFP_HF_TYPE_CALL_SETUP_STATE:
1117 return "HFP_HF_TYPE_CALL_SETUP_STATE";
1118 case HFP_HF_TYPE_CALL_HELD_STATE:
1119 return "HFP_HF_TYPE_CALL_HELD_STATE";
1120 case HFP_HF_TYPE_HOLD_RESULT:
1121 return "HFP_HF_TYPE_HOLD_RESULT";
1122 case HFP_HF_TYPE_CALLING_LINE_IDENTIFICATION:
1123 return "HFP_HF_TYPE_CALLING_LINE_IDENTIFICATION";
1124 case HFP_HF_TYPE_CALL_WAITING:
1125 return "HFP_HF_TYPE_CALL_WAITING";
1126 case HFP_HF_TYPE_CURRENT_CALLS:
1127 return "HFP_HF_TYPE_CURRENT_CALLS";
1128 case HFP_HF_TYPE_SET_VOLUME:
1129 return "HFP_HF_TYPE_SET_VOLUME";
1130 case HFP_HF_TYPE_AT_CMD_RESULT:
1131 return "HFP_HF_TYPE_AT_CMD_RESULT";
1132 case HFP_HF_TYPE_SUBSCRIBER_NUMBER:
1133 return "HFP_HF_TYPE_SUBSCRIBER_NUMBER";
1134 case HFP_HF_TYPE_INBAND_RING:
1135 return "HFP_HF_TYPE_INBAND_RING";
1136 case HFP_HF_TYPE_LAST_NUMBER:
1137 return "HFP_HF_TYPE_LAST_NUMBER";
1138 case HFP_HF_TYPE_RING_ALERT:
1139 return "HFP_HF_TYPE_RING_ALERT";
1140 case HFP_HF_TYPE_UNKNOWN:
1141 return "HFP_HF_TYPE_UNKNOWN";
1142 case HFP_HF_TYPE_QUERY_CURRENT_CALLS_DONE:
1143 return "HFP_HF_TYPE_QUERY_CURRENT_CALLS_DONE";
1144 case HFP_HF_SETUP_CODEC_CVSD:
1145 return "HFP_HF_SETUP_CODEC_CVSD";
1146 case HFP_HF_SLC_ESTABLISHED_EVT:
1147 return "HFP_HF_SLC_ESTABLISHED_EVT";
1148 case HFP_HF_AUDIO_CONNECT_REQUEST_EVT:
1149 return "HFP_HF_AUDIO_CONNECT_REQUEST_EVT";
1150 default:
1151 return "Unknown";
1152 }
1153 }
1154 } // namespace bluetooth
1155 } // namespace OHOS
1156