• 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 #ifndef TELEPHONY_AUDIO_MANAGER_H
17 #define TELEPHONY_AUDIO_MANAGER_H
18 
19 #include <mutex>
20 #include <set>
21 
22 #include "audio_device_manager.h"
23 #include "audio_proxy.h"
24 #include "audio_scene_processor.h"
25 #include "call_manager_inner_type.h"
26 #include "call_state_listener_base.h"
27 #include "ring.h"
28 #include "singleton.h"
29 #include "sound.h"
30 #include "tone.h"
31 
32 namespace OHOS {
33 namespace Telephony {
34 class AudioControlManager : public CallStateListenerBase, public std::enable_shared_from_this<AudioControlManager> {
35     DECLARE_DELAYED_SINGLETON(AudioControlManager)
36 
37 public:
38     void Init();
39     int32_t SetAudioDevice(const AudioDevice &device);
40     bool PlayRingtone(); // plays the default ringtone
41     bool StopRingtone();
42     int32_t PlayRingback();
43     int32_t StopRingback();
44     int32_t PlayWaitingTone();
45     int32_t StopWaitingTone();
46     int32_t PlayDtmfTone(char str);
47     int32_t StopDtmfTone();
48     int32_t OnPostDialNextChar(char str);
49     int32_t PlayCallTone(ToneDescriptor type);
50     int32_t StopCallTone();
51     int32_t MuteRinger();
52     int32_t SetMute(bool on);
53     void SetVolumeAudible();
54     bool IsTonePlaying() const;
55     bool IsAudioActivated() const;
56     bool IsCurrentRinging() const;
57     bool IsActiveCallExists() const;
58     bool ShouldSwitchActive() const;
59     bool ShouldSwitchDialing() const;
60     bool ShouldSwitchAlerting() const;
61     bool ShouldSwitchIncoming() const;
62     AudioDeviceType GetInitAudioDeviceType() const;
63     std::set<sptr<CallBase>> GetCallList();
64     sptr<CallBase> GetCurrentActiveCall();
65     AudioInterruptState GetAudioInterruptState();
66     bool UpdateCurrentCallState();
67     void SetRingState(RingState state);
68     void SetSoundState(SoundState state);
69     void SetToneState(ToneState state);
70     void SetLocalRingbackNeeded(bool isNeeded);
71     void NewCallCreated(sptr<CallBase> &callObjectPtr) override;
72     void CallDestroyed(const DisconnectedDetails &details) override;
73     void IncomingCallActivated(sptr<CallBase> &callObjectPtr) override;
74     void IncomingCallHungUp(sptr<CallBase> &callObjectPtr, bool isSendSms, std::string content) override;
75     void CallStateUpdated(sptr<CallBase> &callObjectPtr, TelCallState priorState, TelCallState nextState) override;
76     void VideoStateUpdated(
77         sptr<CallBase> &callObjectPtr, VideoStateType priorVideoState, VideoStateType nextVideoState);
78     void UpdateDeviceTypeForVideoCall();
79     void UpdateDeviceTypeForCrs();
80     void MuteNetWorkRingTone();
81     bool IsVideoCall(VideoStateType videoState);
82     bool IsSoundPlaying();
83     bool StopSoundtone();
84     bool PlaySoundtone();
85 
86 private:
87     RingState ringState_ = RingState::STOPPED;
88     void HandleNextState(sptr<CallBase> &callObjectPtr, TelCallState nextState);
89     void HandlePriorState(sptr<CallBase> &callObjectPtr, TelCallState priorState);
90     void HandleCallStateUpdated(sptr<CallBase> &callObjectPtr, TelCallState priorState, TelCallState nextState);
91     void HandleNewActiveCall(sptr<CallBase> &callObjectPtr);
92     bool IsNumberAllowed(const std::string &phoneNum);
93     void PlayCallEndedTone(TelCallState priorState, TelCallState nextState, CallEndedType type);
94     sptr<CallBase> GetCallBase(int32_t callId);
95     AudioInterruptState audioInterruptState_ = AudioInterruptState::INTERRUPT_STATE_DEACTIVATED;
96     bool ShouldPlayRingtone() const;
97     bool IsEmergencyCallExists() const;
98     void UpdateForegroundLiveCall();
99     void ProcessAudioWhenCallActive(sptr<CallBase> &callObjectPtr);
100     ToneState toneState_ = ToneState::STOPPED;
101     SoundState soundState_ = SoundState::STOPPED;
102     bool isLocalRingbackNeeded_;
103     bool isCrsVibrating_ = false;
104     std::set<sptr<CallBase>> totalCalls_;
105     std::unique_ptr<Ring> ring_;
106     std::unique_ptr<Tone> tone_;
107     std::unique_ptr<Sound> sound_;
108     std::mutex mutex_;
109     sptr<CallBase> frontCall_ = nullptr;
110 };
111 } // namespace Telephony
112 } // namespace OHOS
113 #endif // TELEPHONY_AUDIO_MANAGER_H
114