• 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 "singleton.h"
23 
24 #include "call_manager_inner_type.h"
25 
26 #include "audio_proxy.h"
27 #include "call_state_listener_base.h"
28 #include "tone.h"
29 #include "ring.h"
30 #include "audio_device_manager.h"
31 #include "audio_scene_processor.h"
32 
33 namespace OHOS {
34 namespace Telephony {
35 class AudioControlManager : public CallStateListenerBase, public std::enable_shared_from_this<AudioControlManager> {
36     DECLARE_DELAYED_SINGLETON(AudioControlManager)
37 public:
38     void Init();
39     int32_t SetAudioDevice(AudioDevice device);
40     bool PlayRingtone(); // plays the default ringtone
41     bool PlayRingtone(const std::string &phoneNum); // plays the default ringtone
42     bool PlayRingtone(const std::string &phoneNum, const std::string &ringtonePath); // plays the specific ringtone
43     bool StopRingtone();
44     int32_t PlayRingback();
45     int32_t StopRingback();
46     int32_t PlayWaitingTone();
47     int32_t StopWaitingTone();
48     int32_t PlayCallTone(ToneDescriptor type);
49     int32_t StopCallTone();
50     int32_t MuteRinger();
51     int32_t SetMute(bool on);
52     void SetVolumeAudible();
53     bool IsTonePlaying() const;
54     bool IsAudioActivated() const;
55     bool IsCurrentRinging() const;
56     bool IsActiveCallExists() const;
57     bool ShouldSwitchActive() const;
58     bool ShouldSwitchDialing() const;
59     bool ShouldSwitchAlerting() const;
60     bool ShouldSwitchIncoming() const;
61     AudioDevice GetInitAudioDevice() const;
62     std::set<sptr<CallBase>> GetCallList();
63     sptr<CallBase> GetCurrentActiveCall() const;
64     AudioInterruptState GetAudioInterruptState();
65     bool UpdateCurrentCallState();
66     void SetRingState(RingState state);
67     void SetLocalRingbackNeeded(bool isNeeded);
68     void SetAudioInterruptState(AudioInterruptState state);
69     void NewCallCreated(sptr<CallBase> &callObjectPtr) override;
70     void CallDestroyed(const DisconnectedDetails &details) override;
71     void IncomingCallActivated(sptr<CallBase> &callObjectPtr) override;
72     void IncomingCallHungUp(sptr<CallBase> &callObjectPtr, bool isSendSms, std::string content) override;
73     void CallStateUpdated(sptr<CallBase> &callObjectPtr, TelCallState priorState, TelCallState nextState) override;
74 
75 private:
76     RingState ringState_ = RingState::STOPPED;
77     void HandleNextState(sptr<CallBase> &callObjectPtr, TelCallState nextState);
78     void HandlePriorState(sptr<CallBase> &callObjectPtr, TelCallState priorState);
79     void HandleCallStateUpdated(sptr<CallBase> &callObjectPtr, TelCallState priorState, TelCallState nextState);
80     void HandleNewActiveCall(sptr<CallBase> &callObjectPtr);
81     bool IsNumberAllowed(const std::string &phoneNum);
82     void PlayCallEndedTone(TelCallState priorState, TelCallState nextState, CallEndedType type);
83     sptr<CallBase> GetCallBase(const std::string &phoneNum) const;
84     AudioInterruptState audioInterruptState_ = AudioInterruptState::INTERRUPT_STATE_DEACTIVATED;
85     bool ShouldPlayRingtone() const;
86     bool IsEmergencyCallExists() const;
87     bool isTonePlaying_;
88     bool isLocalRingbackNeeded_;
89     std::set<sptr<CallBase>> totalCalls_;
90     std::unique_ptr<Ring> ring_;
91     std::unique_ptr<Tone> tone_;
92 };
93 } // namespace Telephony
94 } // namespace OHOS
95 #endif // TELEPHONY_AUDIO_MANAGER_H
96