• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 "audio_control_manager.h"
17 
18 #include "call_control_manager.h"
19 #include "call_state_processor.h"
20 #include "telephony_log_wrapper.h"
21 
22 namespace OHOS {
23 namespace Telephony {
24 constexpr int32_t DTMF_PLAY_TIME = 30;
25 
AudioControlManager()26 AudioControlManager::AudioControlManager()
27     : isLocalRingbackNeeded_(false), ring_(nullptr), tone_(nullptr), sound_(nullptr)
28 {}
29 
~AudioControlManager()30 AudioControlManager::~AudioControlManager()
31 {
32     DelayedSingleton<AudioProxy>::GetInstance()->UnsetDeviceChangeCallback();
33     DelayedSingleton<AudioProxy>::GetInstance()->UnsetAudioPreferDeviceChangeCallback();
34 }
35 
Init()36 void AudioControlManager::Init()
37 {
38     DelayedSingleton<AudioDeviceManager>::GetInstance()->Init();
39     DelayedSingleton<AudioSceneProcessor>::GetInstance()->Init();
40     DelayedSingleton<AudioProxy>::GetInstance()->SetAudioDeviceChangeCallback();
41     DelayedSingleton<AudioProxy>::GetInstance()->SetAudioPreferDeviceChangeCallback();
42 }
43 
CallStateUpdated(sptr<CallBase> & callObjectPtr,TelCallState priorState,TelCallState nextState)44 void AudioControlManager::CallStateUpdated(
45     sptr<CallBase> &callObjectPtr, TelCallState priorState, TelCallState nextState)
46 {
47     if (callObjectPtr == nullptr) {
48         TELEPHONY_LOGE("call object nullptr");
49         return;
50     }
51     if (totalCalls_.count(callObjectPtr) == 0) {
52         int32_t callId = callObjectPtr->GetCallID();
53         TelCallState callState = callObjectPtr->GetTelCallState();
54         TELEPHONY_LOGI("add new call , call id : %{public}d , call state : %{public}d", callId, callState);
55         totalCalls_.insert(callObjectPtr);
56     }
57     HandleCallStateUpdated(callObjectPtr, priorState, nextState);
58     if (nextState == TelCallState::CALL_STATUS_DISCONNECTED && totalCalls_.count(callObjectPtr) > 0) {
59         totalCalls_.erase(callObjectPtr);
60     }
61 }
62 
IncomingCallActivated(sptr<CallBase> & callObjectPtr)63 void AudioControlManager::IncomingCallActivated(sptr<CallBase> &callObjectPtr)
64 {
65     if (callObjectPtr == nullptr) {
66         TELEPHONY_LOGE("call object ptr nullptr");
67         return;
68     }
69     DelayedSingleton<AudioProxy>::GetInstance()->SetMicrophoneMute(false); // unmute microphone
70 }
71 
IncomingCallHungUp(sptr<CallBase> & callObjectPtr,bool isSendSms,std::string content)72 void AudioControlManager::IncomingCallHungUp(sptr<CallBase> &callObjectPtr, bool isSendSms, std::string content)
73 {
74     if (callObjectPtr == nullptr) {
75         TELEPHONY_LOGE("call object ptr nullptr");
76         return;
77     }
78     StopRingtone();
79     DelayedSingleton<AudioProxy>::GetInstance()->SetMicrophoneMute(false); // unmute microphone
80 }
81 
HandleCallStateUpdated(sptr<CallBase> & callObjectPtr,TelCallState priorState,TelCallState nextState)82 void AudioControlManager::HandleCallStateUpdated(
83     sptr<CallBase> &callObjectPtr, TelCallState priorState, TelCallState nextState)
84 {
85     HandleNextState(callObjectPtr, nextState);
86     if (priorState == nextState) {
87         TELEPHONY_LOGI("prior state equals next state");
88         return;
89     }
90     HandlePriorState(callObjectPtr, priorState);
91 }
92 
HandleNextState(sptr<CallBase> & callObjectPtr,TelCallState nextState)93 void AudioControlManager::HandleNextState(sptr<CallBase> &callObjectPtr, TelCallState nextState)
94 {
95     AudioEvent event = AudioEvent::UNKNOWN_EVENT;
96     DelayedSingleton<CallStateProcessor>::GetInstance()->AddCall(callObjectPtr->GetCallID(), nextState);
97     switch (nextState) {
98         case TelCallState::CALL_STATUS_DIALING:
99             event = AudioEvent::NEW_DIALING_CALL;
100             audioInterruptState_ = AudioInterruptState::INTERRUPT_STATE_RINGING;
101             break;
102         case TelCallState::CALL_STATUS_ALERTING:
103             event = AudioEvent::NEW_ALERTING_CALL;
104             audioInterruptState_ = AudioInterruptState::INTERRUPT_STATE_RINGING;
105             break;
106         case TelCallState::CALL_STATUS_ACTIVE:
107             HandleNewActiveCall(callObjectPtr);
108             audioInterruptState_ = AudioInterruptState::INTERRUPT_STATE_ACTIVATED;
109             break;
110         case TelCallState::CALL_STATUS_INCOMING:
111             event = AudioEvent::NEW_INCOMING_CALL;
112             audioInterruptState_ = AudioInterruptState::INTERRUPT_STATE_RINGING;
113             break;
114         case TelCallState::CALL_STATUS_DISCONNECTING:
115         case TelCallState::CALL_STATUS_DISCONNECTED:
116             audioInterruptState_ = AudioInterruptState::INTERRUPT_STATE_DEACTIVATED;
117             break;
118         default:
119             break;
120     }
121     if (event == AudioEvent::UNKNOWN_EVENT) {
122         return;
123     }
124     DelayedSingleton<AudioSceneProcessor>::GetInstance()->ProcessEvent(event);
125 }
126 
HandlePriorState(sptr<CallBase> & callObjectPtr,TelCallState priorState)127 void AudioControlManager::HandlePriorState(sptr<CallBase> &callObjectPtr, TelCallState priorState)
128 {
129     AudioEvent event = AudioEvent::UNKNOWN_EVENT;
130     DelayedSingleton<CallStateProcessor>::GetInstance()->DeleteCall(callObjectPtr->GetCallID(), priorState);
131     int32_t stateNumber = DelayedSingleton<CallStateProcessor>::GetInstance()->GetCallNumber(priorState);
132     switch (priorState) {
133         case TelCallState::CALL_STATUS_DIALING:
134             if (stateNumber == EMPTY_VALUE) {
135                 StopRingback(); // should stop ringtone while no more alerting calls
136                 event = AudioEvent::NO_MORE_DIALING_CALL;
137             }
138             break;
139         case TelCallState::CALL_STATUS_ALERTING:
140             if (stateNumber == EMPTY_VALUE) {
141                 StopRingback(); // should stop ringtone while no more alerting calls
142                 event = AudioEvent::NO_MORE_ALERTING_CALL;
143             }
144             break;
145         case TelCallState::CALL_STATUS_INCOMING:
146             if (stateNumber == EMPTY_VALUE) {
147                 if (callObjectPtr->GetCallRunningState() == CallRunningState::CALL_RUNNING_STATE_ACTIVE) {
148                     PlaySoundtone();
149                 } else {
150                     StopRingtone();
151                 }
152                 event = AudioEvent::NO_MORE_INCOMING_CALL;
153             }
154             break;
155         case TelCallState::CALL_STATUS_ACTIVE:
156             if (stateNumber == EMPTY_VALUE) {
157                 // unmute microphone while no more active call
158                 DelayedSingleton<AudioProxy>::GetInstance()->SetMicrophoneMute(false);
159                 event = AudioEvent::NO_MORE_ACTIVE_CALL;
160             }
161             StopRingback();
162             break;
163         default:
164             break;
165     }
166     if (event == AudioEvent::UNKNOWN_EVENT) {
167         return;
168     }
169     DelayedSingleton<AudioSceneProcessor>::GetInstance()->ProcessEvent(event);
170 }
171 
HandleNewActiveCall(sptr<CallBase> & callObjectPtr)172 void AudioControlManager::HandleNewActiveCall(sptr<CallBase> &callObjectPtr)
173 {
174     std::string number = callObjectPtr->GetAccountNumber();
175     if (number.empty()) {
176         TELEPHONY_LOGE("call object account number empty");
177         return;
178     }
179     CallType callType = callObjectPtr->GetCallType();
180     AudioEvent event = AudioEvent::UNKNOWN_EVENT;
181     switch (callType) {
182         case CallType::TYPE_CS:
183             event = AudioEvent::NEW_ACTIVE_CS_CALL;
184             break;
185         case CallType::TYPE_IMS:
186             event = AudioEvent::NEW_ACTIVE_IMS_CALL;
187             break;
188         case CallType::TYPE_OTT:
189             event = AudioEvent::NEW_ACTIVE_OTT_CALL;
190             break;
191         default:
192             break;
193     }
194     if (event == AudioEvent::UNKNOWN_EVENT) {
195         return;
196     }
197     DelayedSingleton<AudioSceneProcessor>::GetInstance()->ProcessEvent(event);
198 }
199 
200 /**
201  * @param device , audio device
202  * usually called by the ui interaction , in purpose of switching to another audio device
203  */
SetAudioDevice(const AudioDevice & device)204 int32_t AudioControlManager::SetAudioDevice(const AudioDevice &device)
205 {
206     AudioDeviceType audioDeviceType = AudioDeviceType::DEVICE_UNKNOWN;
207     switch (device.deviceType) {
208         case AudioDeviceType::DEVICE_SPEAKER:
209         case AudioDeviceType::DEVICE_EARPIECE:
210         case AudioDeviceType::DEVICE_WIRED_HEADSET:
211             audioDeviceType = device.deviceType;
212             break;
213         case AudioDeviceType::DEVICE_BLUETOOTH_SCO:
214             if (!DelayedSingleton<AudioDeviceManager>::GetInstance()->ConnectBtScoWithAddress(device.address)) {
215                 return CALL_ERR_AUDIO_SET_AUDIO_DEVICE_FAILED;
216             }
217             return TELEPHONY_SUCCESS;
218         default:
219             break;
220     }
221     if (audioDeviceType != AudioDeviceType::DEVICE_UNKNOWN &&
222         DelayedSingleton<AudioDeviceManager>::GetInstance()->SwitchDevice(audioDeviceType)) {
223         return TELEPHONY_SUCCESS;
224     }
225     return CALL_ERR_AUDIO_SET_AUDIO_DEVICE_FAILED;
226 }
227 
PlayRingtone()228 bool AudioControlManager::PlayRingtone()
229 {
230     if (!ShouldPlayRingtone()) {
231         TELEPHONY_LOGE("should not play ringtone");
232         return false;
233     }
234     if (ring_ == nullptr) {
235         ring_ = std::make_unique<Ring>();
236         if (ring_ == nullptr) {
237             TELEPHONY_LOGE("create ring object failed");
238             return false;
239         }
240     }
241     if (ring_->Play() != TELEPHONY_SUCCESS) {
242         TELEPHONY_LOGE("play ringtone failed");
243         return false;
244     }
245     TELEPHONY_LOGI("play ringtone success");
246     return true;
247 }
248 
PlayRingtone(const std::string & phoneNum)249 bool AudioControlManager::PlayRingtone(const std::string &phoneNum)
250 {
251     if (!IsNumberAllowed(phoneNum)) {
252         TELEPHONY_LOGE("number is not allowed");
253         return false;
254     }
255     if (!ShouldPlayRingtone()) {
256         TELEPHONY_LOGE("should not play ringtone");
257         return false;
258     }
259     if (ring_ == nullptr) {
260         ring_ = std::make_unique<Ring>();
261         if (ring_ == nullptr) {
262             TELEPHONY_LOGE("create ring failed");
263             return false;
264         }
265     }
266     if (ring_->Play() != TELEPHONY_SUCCESS) {
267         TELEPHONY_LOGE("play ringtone failed");
268         return false;
269     }
270     TELEPHONY_LOGI("play ringtone success");
271     return true;
272 }
273 
PlayRingtone(const std::string & phoneNum,const std::string & ringtonePath)274 bool AudioControlManager::PlayRingtone(const std::string &phoneNum, const std::string &ringtonePath)
275 {
276     if (!IsNumberAllowed(phoneNum)) {
277         TELEPHONY_LOGE("number is not allowed");
278         return false;
279     }
280     if (!ShouldPlayRingtone()) {
281         TELEPHONY_LOGE("should not play ringtone");
282         return false;
283     }
284     if (ring_ == nullptr) {
285         ring_ = std::make_unique<Ring>(ringtonePath);
286         if (ring_ == nullptr) {
287             TELEPHONY_LOGE("create ring failed");
288             return false;
289         }
290     }
291     if (ring_->Play() == TELEPHONY_SUCCESS) {
292         TELEPHONY_LOGE("play ringtone failed");
293         return false;
294     }
295     TELEPHONY_LOGI("play ringtone success");
296     return true;
297 }
298 
PlaySoundtone()299 bool AudioControlManager::PlaySoundtone()
300 {
301     if (soundState_ == SoundState::SOUNDING) {
302         TELEPHONY_LOGE("should not play soundTone");
303         return false;
304     }
305     if (sound_ == nullptr) {
306         sound_ = std::make_unique<Sound>();
307         if (sound_ == nullptr) {
308             TELEPHONY_LOGE("create sound object failed");
309             return false;
310         }
311     }
312     if (sound_->Play() != TELEPHONY_SUCCESS) {
313         TELEPHONY_LOGE("play soundtone failed");
314         return false;
315     }
316     TELEPHONY_LOGI("play soundtone success");
317     return true;
318 }
319 
StopSoundtone()320 bool AudioControlManager::StopSoundtone()
321 {
322     if (soundState_ == SoundState::STOPPED) {
323         TELEPHONY_LOGI("soundtone already stopped");
324         return true;
325     }
326     if (sound_ == nullptr) {
327         TELEPHONY_LOGE("sound_ is nullptr");
328         return false;
329     }
330     if (sound_->Stop() != TELEPHONY_SUCCESS) {
331         TELEPHONY_LOGE("stop soundtone failed");
332         return false;
333     }
334     sound_->ReleaseRenderer();
335     TELEPHONY_LOGI("stop soundtone success");
336     return true;
337 }
338 
StopRingtone()339 bool AudioControlManager::StopRingtone()
340 {
341     if (ringState_ == RingState::STOPPED) {
342         TELEPHONY_LOGI("ringtone already stopped");
343         return true;
344     }
345     if (ring_ == nullptr) {
346         TELEPHONY_LOGE("ring_ is nullptr");
347         return false;
348     }
349     if (ring_->Stop() != TELEPHONY_SUCCESS) {
350         TELEPHONY_LOGE("stop ringtone failed");
351         return false;
352     }
353     ring_->ReleaseRenderer();
354     TELEPHONY_LOGI("stop ringtone success");
355     return true;
356 }
357 
358 /**
359  * while audio state changed , maybe need to reinitialize the audio device
360  * in order to get the initialization status of audio device , need to consider varieties of  audio conditions
361  */
GetInitAudioDeviceType() const362 AudioDeviceType AudioControlManager::GetInitAudioDeviceType() const
363 {
364     if (audioInterruptState_ == AudioInterruptState::INTERRUPT_STATE_DEACTIVATED) {
365         return AudioDeviceType::DEVICE_DISABLE;
366     } else {
367         /**
368          * Init audio device type according to the priority in different call state:
369          * In voice call state, bluetooth sco > wired headset > earpiece > speaker
370          * In video call state, bluetooth sco > wired headset > speaker > earpiece
371          */
372         if (AudioDeviceManager::IsBtScoConnected()) {
373             return AudioDeviceType::DEVICE_BLUETOOTH_SCO;
374         }
375         if (AudioDeviceManager::IsWiredHeadsetConnected()) {
376             return AudioDeviceType::DEVICE_WIRED_HEADSET;
377         }
378         sptr<CallBase> liveCall = CallObjectManager::GetForegroundLiveCall();
379         if (liveCall != nullptr && liveCall->GetVideoStateType() == VideoStateType::TYPE_VIDEO) {
380             TELEPHONY_LOGI("current video call speaker is active");
381             return AudioDeviceType::DEVICE_SPEAKER;
382         }
383         if (AudioDeviceManager::IsEarpieceAvailable()) {
384             return AudioDeviceType::DEVICE_EARPIECE;
385         }
386         return AudioDeviceType::DEVICE_SPEAKER;
387     }
388 }
389 
390 /**
391  * @param isMute , mute state
392  * usually called by the ui interaction , mute or unmute microphone
393  */
SetMute(bool isMute)394 int32_t AudioControlManager::SetMute(bool isMute)
395 {
396     bool hasCall = DelayedSingleton<CallControlManager>::GetInstance()->HasCall();
397     if (!hasCall) {
398         TELEPHONY_LOGE("no call exists, set mute failed");
399         return CALL_ERR_AUDIO_SETTING_MUTE_FAILED;
400     }
401     bool enabled = false;
402     if ((DelayedSingleton<CallControlManager>::GetInstance()->HasEmergency(enabled) == TELEPHONY_SUCCESS) && enabled) {
403         isMute = false;
404     }
405     if (DelayedSingleton<AudioProxy>::GetInstance()->SetMicrophoneMute(isMute)) {
406         TELEPHONY_LOGI("set mute success , current mute state : %{public}d", isMute);
407         return TELEPHONY_SUCCESS;
408     }
409     TELEPHONY_LOGE("set mute failed");
410     return CALL_ERR_AUDIO_SETTING_MUTE_FAILED;
411 }
412 
MuteRinger()413 int32_t AudioControlManager::MuteRinger()
414 {
415     if (ringState_ == RingState::STOPPED) {
416         TELEPHONY_LOGI("ring already stopped");
417         return TELEPHONY_SUCCESS;
418     }
419     if (!PlaySoundtone()) {
420         TELEPHONY_LOGE("PlaySoundtone fail");
421         return CALL_ERR_AUDIO_SETTING_MUTE_FAILED;
422     }
423     TELEPHONY_LOGI("mute ring success");
424     return TELEPHONY_SUCCESS;
425 }
426 
PlayCallEndedTone(TelCallState priorState,TelCallState nextState,CallEndedType type)427 void AudioControlManager::PlayCallEndedTone(TelCallState priorState, TelCallState nextState, CallEndedType type)
428 {
429     if (nextState != TelCallState::CALL_STATUS_DISCONNECTED) {
430         return;
431     }
432     if (priorState == TelCallState::CALL_STATUS_ACTIVE || priorState == TelCallState::CALL_STATUS_DIALING ||
433         priorState == TelCallState::CALL_STATUS_HOLDING) {
434         switch (type) {
435             case CallEndedType::PHONE_IS_BUSY:
436                 PlayCallTone(ToneDescriptor::TONE_ENGAGED);
437                 break;
438             case CallEndedType::CALL_ENDED_NORMALLY:
439                 PlayCallTone(ToneDescriptor::TONE_FINISHED);
440                 break;
441             case CallEndedType::UNKNOWN:
442                 PlayCallTone(ToneDescriptor::TONE_UNKNOWN);
443                 break;
444             case CallEndedType::INVALID_NUMBER:
445                 PlayCallTone(ToneDescriptor::TONE_INVALID_NUMBER);
446                 break;
447             default:
448                 break;
449         }
450     }
451 }
452 
GetCallList()453 std::set<sptr<CallBase>> AudioControlManager::GetCallList()
454 {
455     std::lock_guard<std::mutex> lock(mutex_);
456     return totalCalls_;
457 }
458 
GetCurrentActiveCall()459 sptr<CallBase> AudioControlManager::GetCurrentActiveCall()
460 {
461     int32_t callId = DelayedSingleton<CallStateProcessor>::GetInstance()->GetCurrentActiveCall();
462     if (callId != INVALID_CALLID) {
463         return GetCallBase(callId);
464     }
465     return nullptr;
466 }
467 
GetCallBase(int32_t callId)468 sptr<CallBase> AudioControlManager::GetCallBase(int32_t callId)
469 {
470     sptr<CallBase> callBase = nullptr;
471     std::lock_guard<std::mutex> lock(mutex_);
472     for (auto &call : totalCalls_) {
473         if (call->GetCallID() == callId) {
474             callBase = call;
475             break;
476         }
477     }
478     return callBase;
479 }
480 
IsEmergencyCallExists() const481 bool AudioControlManager::IsEmergencyCallExists() const
482 {
483     for (auto call : totalCalls_) {
484         if (call->GetEmergencyState()) {
485             return true;
486         }
487     }
488     return false;
489 }
490 
GetAudioInterruptState()491 AudioInterruptState AudioControlManager::GetAudioInterruptState()
492 {
493     return audioInterruptState_;
494 }
495 
SetVolumeAudible()496 void AudioControlManager::SetVolumeAudible()
497 {
498     DelayedSingleton<AudioProxy>::GetInstance()->SetVolumeAudible();
499 }
500 
SetRingState(RingState state)501 void AudioControlManager::SetRingState(RingState state)
502 {
503     ringState_ = state;
504 }
505 
SetSoundState(SoundState state)506 void AudioControlManager::SetSoundState(SoundState state)
507 {
508     soundState_ = state;
509 }
510 
SetToneState(ToneState state)511 void AudioControlManager::SetToneState(ToneState state)
512 {
513     toneState_ = state;
514 }
515 
SetLocalRingbackNeeded(bool isNeeded)516 void AudioControlManager::SetLocalRingbackNeeded(bool isNeeded)
517 {
518     isLocalRingbackNeeded_ = isNeeded;
519 }
520 
IsNumberAllowed(const std::string & phoneNum)521 bool AudioControlManager::IsNumberAllowed(const std::string &phoneNum)
522 {
523     // check whether the phone number is allowed or not , should not ring if number is not allowed
524     return true;
525 }
526 
ShouldPlayRingtone() const527 bool AudioControlManager::ShouldPlayRingtone() const
528 {
529     auto processor = DelayedSingleton<CallStateProcessor>::GetInstance();
530     int32_t alertingCallNum = processor->GetCallNumber(TelCallState::CALL_STATUS_ALERTING);
531     int32_t incomingCallNum = processor->GetCallNumber(TelCallState::CALL_STATUS_INCOMING);
532     if (incomingCallNum != EXIST_ONLY_ONE_CALL || alertingCallNum > EMPTY_VALUE || ringState_ == RingState::RINGING) {
533         return false;
534     }
535     return true;
536 }
537 
IsAudioActivated() const538 bool AudioControlManager::IsAudioActivated() const
539 {
540     return audioInterruptState_ == AudioInterruptState::INTERRUPT_STATE_ACTIVATED ||
541         audioInterruptState_ == AudioInterruptState::INTERRUPT_STATE_RINGING;
542 }
543 
PlayCallTone(ToneDescriptor type)544 int32_t AudioControlManager::PlayCallTone(ToneDescriptor type)
545 {
546     if (toneState_ == ToneState::TONEING) {
547         TELEPHONY_LOGE("should not play callTone");
548         return CALL_ERR_AUDIO_TONE_PLAY_FAILED;
549     }
550     toneState_ = ToneState::TONEING;
551     tone_ = std::make_unique<Tone>(type);
552     if (tone_ == nullptr) {
553         TELEPHONY_LOGE("create tone failed");
554         return TELEPHONY_ERR_LOCAL_PTR_NULL;
555     }
556     if (tone_->Play() != TELEPHONY_SUCCESS) {
557         TELEPHONY_LOGE("play calltone failed");
558         return CALL_ERR_AUDIO_TONE_PLAY_FAILED;
559     }
560     TELEPHONY_LOGI("play calltone success");
561     return TELEPHONY_SUCCESS;
562 }
563 
StopCallTone()564 int32_t AudioControlManager::StopCallTone()
565 {
566     if (toneState_ == ToneState::STOPPED) {
567         TELEPHONY_LOGI("tone is already stopped");
568         return TELEPHONY_SUCCESS;
569     }
570     if (tone_ == nullptr) {
571         TELEPHONY_LOGE("tone_ is nullptr");
572         return TELEPHONY_ERR_LOCAL_PTR_NULL;
573     }
574     if (tone_->Stop() != TELEPHONY_SUCCESS) {
575         TELEPHONY_LOGE("stop calltone failed");
576         return CALL_ERR_AUDIO_TONE_STOP_FAILED;
577     }
578     tone_->ReleaseRenderer();
579     toneState_ = ToneState::STOPPED;
580     TELEPHONY_LOGI("stop call tone success");
581     return TELEPHONY_SUCCESS;
582 }
583 
IsTonePlaying() const584 bool AudioControlManager::IsTonePlaying() const
585 {
586     return toneState_ == ToneState::TONEING;
587 }
588 
IsCurrentRinging() const589 bool AudioControlManager::IsCurrentRinging() const
590 {
591     return ringState_ == RingState::RINGING;
592 }
593 
PlayRingback()594 int32_t AudioControlManager::PlayRingback()
595 {
596     if (!isLocalRingbackNeeded_) {
597         return CALL_ERR_AUDIO_TONE_PLAY_FAILED;
598     }
599     return PlayCallTone(ToneDescriptor::TONE_RINGBACK);
600 }
601 
StopRingback()602 int32_t AudioControlManager::StopRingback()
603 {
604     return StopCallTone();
605 }
606 
PlayWaitingTone()607 int32_t AudioControlManager::PlayWaitingTone()
608 {
609     return PlayCallTone(ToneDescriptor::TONE_WAITING);
610 }
611 
StopWaitingTone()612 int32_t AudioControlManager::StopWaitingTone()
613 {
614     return StopCallTone();
615 }
616 
PlayDtmfTone(char str)617 int32_t AudioControlManager::PlayDtmfTone(char str)
618 {
619     ToneDescriptor dtmfTone = Tone::ConvertDigitToTone(str);
620     return PlayCallTone(dtmfTone);
621 }
622 
StopDtmfTone()623 int32_t AudioControlManager::StopDtmfTone()
624 {
625     return StopCallTone();
626 }
627 
OnPostDialNextChar(char str)628 int32_t AudioControlManager::OnPostDialNextChar(char str)
629 {
630     int32_t result = PlayDtmfTone(str);
631     if (result != TELEPHONY_SUCCESS) {
632         return result;
633     }
634     std::this_thread::sleep_for(std::chrono::milliseconds(DTMF_PLAY_TIME));
635     result = StopDtmfTone();
636     if (result != TELEPHONY_SUCCESS) {
637         return result;
638     }
639     return TELEPHONY_SUCCESS;
640 }
641 
NewCallCreated(sptr<CallBase> & callObjectPtr)642 void AudioControlManager::NewCallCreated(sptr<CallBase> &callObjectPtr) {}
643 
CallDestroyed(const DisconnectedDetails & details)644 void AudioControlManager::CallDestroyed(const DisconnectedDetails &details) {}
645 
IsSoundPlaying()646 bool AudioControlManager::IsSoundPlaying()
647 {
648     return soundState_ == SoundState::SOUNDING;
649 }
650 } // namespace Telephony
651 } // namespace OHOS