1e1c44949Sopenharmony_ci/* 2e1c44949Sopenharmony_ci * Copyright (C) 2021-2024 Huawei Device Co., Ltd. 3e1c44949Sopenharmony_ci * Licensed under the Apache License, Version 2.0 (the "License"); 4e1c44949Sopenharmony_ci * you may not use this file except in compliance with the License. 5e1c44949Sopenharmony_ci * You may obtain a copy of the License at 6e1c44949Sopenharmony_ci * 7e1c44949Sopenharmony_ci * http://www.apache.org/licenses/LICENSE-2.0 8e1c44949Sopenharmony_ci * 9e1c44949Sopenharmony_ci * Unless required by applicable law or agreed to in writing, software 10e1c44949Sopenharmony_ci * distributed under the License is distributed on an "AS IS" BASIS, 11e1c44949Sopenharmony_ci * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12e1c44949Sopenharmony_ci * See the License for the specific language governing permissions and 13e1c44949Sopenharmony_ci * limitations under the License. 14e1c44949Sopenharmony_ci */ 15e1c44949Sopenharmony_ci 16e1c44949Sopenharmony_ci#ifndef TELEPHONY_AUDIO_MANAGER_H 17e1c44949Sopenharmony_ci#define TELEPHONY_AUDIO_MANAGER_H 18e1c44949Sopenharmony_ci 19e1c44949Sopenharmony_ci#include <mutex> 20e1c44949Sopenharmony_ci#include <set> 21e1c44949Sopenharmony_ci 22e1c44949Sopenharmony_ci#include "audio_device_manager.h" 23e1c44949Sopenharmony_ci#include "audio_proxy.h" 24e1c44949Sopenharmony_ci#include "audio_scene_processor.h" 25e1c44949Sopenharmony_ci#include "call_manager_inner_type.h" 26e1c44949Sopenharmony_ci#include "call_state_listener_base.h" 27e1c44949Sopenharmony_ci#include "ring.h" 28e1c44949Sopenharmony_ci#include "singleton.h" 29e1c44949Sopenharmony_ci#include "sound.h" 30e1c44949Sopenharmony_ci#include "tone.h" 31e1c44949Sopenharmony_ci 32e1c44949Sopenharmony_cinamespace OHOS { 33e1c44949Sopenharmony_cinamespace Telephony { 34e1c44949Sopenharmony_ciclass AudioControlManager : public CallStateListenerBase, public std::enable_shared_from_this<AudioControlManager> { 35e1c44949Sopenharmony_ci DECLARE_DELAYED_SINGLETON(AudioControlManager) 36e1c44949Sopenharmony_ci 37e1c44949Sopenharmony_cipublic: 38e1c44949Sopenharmony_ci void Init(); 39e1c44949Sopenharmony_ci int32_t SetAudioDevice(const AudioDevice &device); 40e1c44949Sopenharmony_ci int32_t SetAudioDevice(const AudioDevice &device, bool isByUser); 41e1c44949Sopenharmony_ci bool PlayRingtone(); // plays the default ringtone 42e1c44949Sopenharmony_ci bool StopRingtone(); 43e1c44949Sopenharmony_ci int32_t PlayRingback(); 44e1c44949Sopenharmony_ci int32_t StopRingback(); 45e1c44949Sopenharmony_ci int32_t PlayWaitingTone(); 46e1c44949Sopenharmony_ci int32_t StopWaitingTone(); 47e1c44949Sopenharmony_ci int32_t PlayDtmfTone(char str); 48e1c44949Sopenharmony_ci int32_t StopDtmfTone(); 49e1c44949Sopenharmony_ci int32_t OnPostDialNextChar(char str); 50e1c44949Sopenharmony_ci int32_t PlayCallTone(ToneDescriptor type); 51e1c44949Sopenharmony_ci int32_t StopCallTone(); 52e1c44949Sopenharmony_ci int32_t MuteRinger(); 53e1c44949Sopenharmony_ci int32_t SetMute(bool on); 54e1c44949Sopenharmony_ci void SetVolumeAudible(); 55e1c44949Sopenharmony_ci bool IsTonePlaying(); 56e1c44949Sopenharmony_ci bool IsAudioActivated() const; 57e1c44949Sopenharmony_ci bool IsCurrentRinging() const; 58e1c44949Sopenharmony_ci bool IsActiveCallExists() const; 59e1c44949Sopenharmony_ci bool ShouldSwitchActive() const; 60e1c44949Sopenharmony_ci bool ShouldSwitchDialing() const; 61e1c44949Sopenharmony_ci bool ShouldSwitchAlerting() const; 62e1c44949Sopenharmony_ci bool ShouldSwitchIncoming() const; 63e1c44949Sopenharmony_ci AudioDeviceType GetInitAudioDeviceType() const; 64e1c44949Sopenharmony_ci std::set<sptr<CallBase>> GetCallList(); 65e1c44949Sopenharmony_ci sptr<CallBase> GetCurrentActiveCall(); 66e1c44949Sopenharmony_ci AudioInterruptState GetAudioInterruptState(); 67e1c44949Sopenharmony_ci bool UpdateCurrentCallState(); 68e1c44949Sopenharmony_ci void SetRingState(RingState state); 69e1c44949Sopenharmony_ci void SetSoundState(SoundState state); 70e1c44949Sopenharmony_ci void SetToneState(ToneState state); 71e1c44949Sopenharmony_ci void SetLocalRingbackNeeded(bool isNeeded); 72e1c44949Sopenharmony_ci void NewCallCreated(sptr<CallBase> &callObjectPtr) override; 73e1c44949Sopenharmony_ci void CallDestroyed(const DisconnectedDetails &details) override; 74e1c44949Sopenharmony_ci void IncomingCallActivated(sptr<CallBase> &callObjectPtr) override; 75e1c44949Sopenharmony_ci void IncomingCallHungUp(sptr<CallBase> &callObjectPtr, bool isSendSms, std::string content) override; 76e1c44949Sopenharmony_ci void CallStateUpdated(sptr<CallBase> &callObjectPtr, TelCallState priorState, TelCallState nextState) override; 77e1c44949Sopenharmony_ci void VideoStateUpdated( 78e1c44949Sopenharmony_ci sptr<CallBase> &callObjectPtr, VideoStateType priorVideoState, VideoStateType nextVideoState); 79e1c44949Sopenharmony_ci void CheckTypeAndSetAudioDevice(sptr<CallBase> &callObjectPtr, VideoStateType priorVideoState, 80e1c44949Sopenharmony_ci VideoStateType nextVideoState, AudioDeviceType &initDeviceType, AudioDevice &device); 81e1c44949Sopenharmony_ci void UpdateDeviceTypeForVideoOrSatelliteCall(); 82e1c44949Sopenharmony_ci void UpdateDeviceTypeForCrs(); 83e1c44949Sopenharmony_ci void UpdateDeviceTypeForVideoDialing(); 84e1c44949Sopenharmony_ci void MuteNetWorkRingTone(); 85e1c44949Sopenharmony_ci bool IsVideoCall(VideoStateType videoState); 86e1c44949Sopenharmony_ci bool IsSoundPlaying(); 87e1c44949Sopenharmony_ci bool StopSoundtone(); 88e1c44949Sopenharmony_ci bool PlaySoundtone(); 89e1c44949Sopenharmony_ci void PlayCallEndedTone(CallEndedType type); 90e1c44949Sopenharmony_ci 91e1c44949Sopenharmony_ciprivate: 92e1c44949Sopenharmony_ci RingState ringState_ = RingState::STOPPED; 93e1c44949Sopenharmony_ci void HandleNextState(sptr<CallBase> &callObjectPtr, TelCallState nextState); 94e1c44949Sopenharmony_ci void HandlePriorState(sptr<CallBase> &callObjectPtr, TelCallState priorState); 95e1c44949Sopenharmony_ci void HandleCallStateUpdatedForVoip(sptr<CallBase> &callObjectPtr, TelCallState priorState, TelCallState nextState); 96e1c44949Sopenharmony_ci void HandleCallStateUpdated(sptr<CallBase> &callObjectPtr, TelCallState priorState, TelCallState nextState); 97e1c44949Sopenharmony_ci void HandleNewActiveCall(sptr<CallBase> &callObjectPtr); 98e1c44949Sopenharmony_ci bool IsNumberAllowed(const std::string &phoneNum); 99e1c44949Sopenharmony_ci sptr<CallBase> GetCallBase(int32_t callId); 100e1c44949Sopenharmony_ci AudioInterruptState audioInterruptState_ = AudioInterruptState::INTERRUPT_STATE_DEACTIVATED; 101e1c44949Sopenharmony_ci bool ShouldPlayRingtone() const; 102e1c44949Sopenharmony_ci bool IsEmergencyCallExists(); 103e1c44949Sopenharmony_ci void UpdateForegroundLiveCall(); 104e1c44949Sopenharmony_ci bool IsBtOrWireHeadPlugin(); 105e1c44949Sopenharmony_ci void ProcessAudioWhenCallActive(sptr<CallBase> &callObjectPtr); 106e1c44949Sopenharmony_ci int32_t HandleDistributeAudioDevice(const AudioDevice &device); 107e1c44949Sopenharmony_ci void SendMuteRingEvent(); 108e1c44949Sopenharmony_ci bool IsDistributeCallSinkStatus(); 109e1c44949Sopenharmony_ci bool IsRingingVibrateModeOn(); 110e1c44949Sopenharmony_ci int32_t SwitchAudioDevice(AudioDeviceType audioDeviceType); 111e1c44949Sopenharmony_ci ToneState toneState_ = ToneState::STOPPED; 112e1c44949Sopenharmony_ci SoundState soundState_ = SoundState::STOPPED; 113e1c44949Sopenharmony_ci bool isLocalRingbackNeeded_ = false; 114e1c44949Sopenharmony_ci bool isCrsVibrating_ = false; 115e1c44949Sopenharmony_ci std::set<sptr<CallBase>> totalCalls_; 116e1c44949Sopenharmony_ci std::unique_ptr<Ring> ring_; 117e1c44949Sopenharmony_ci std::unique_ptr<Tone> tone_; 118e1c44949Sopenharmony_ci std::unique_ptr<Sound> sound_; 119e1c44949Sopenharmony_ci std::mutex mutex_; 120e1c44949Sopenharmony_ci std::recursive_mutex toneStateLock_; 121e1c44949Sopenharmony_ci sptr<CallBase> frontCall_ = nullptr; 122e1c44949Sopenharmony_ci bool isSetAudioDeviceByUser_ = false; 123e1c44949Sopenharmony_ci}; 124e1c44949Sopenharmony_ci} // namespace Telephony 125e1c44949Sopenharmony_ci} // namespace OHOS 126e1c44949Sopenharmony_ci#endif // TELEPHONY_AUDIO_MANAGER_H 127