• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2021 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_PROXY_H
17 #define TELEPHONY_AUDIO_PROXY_H
18 
19 #include <cstdint>
20 #include <memory>
21 #include <mutex>
22 
23 #include "audio_system_manager.h"
24 #include "call_manager_errors.h"
25 #include "call_manager_inner_type.h"
26 #include "singleton.h"
27 
28 namespace OHOS {
29 namespace Telephony {
30 constexpr uint16_t VOLUME_AUDIBLE_DIVISOR = 2;
31 
32 enum AudioInterruptState {
33     INTERRUPT_STATE_UNKNOWN = 0,
34     INTERRUPT_STATE_DEACTIVATED,
35     INTERRUPT_STATE_ACTIVATED,
36     INTERRUPT_STATE_RINGING,
37 };
38 
39 enum class VibrationType {
40     VIBRATION_RINGTONE = 0,
41 };
42 
43 class AudioDeviceChangeCallback : public AudioStandard::AudioManagerDeviceChangeCallback {
44     void OnDeviceChange(const AudioStandard::DeviceChangeAction &deviceChangeAction) override;
45 };
46 
47 class AudioPreferDeviceChangeCallback : public AudioStandard::AudioPreferredOutputDeviceChangeCallback {
48 public:
49     bool ProcessVoipCallOutputDeviceUpdated();
50     void OnPreferredOutputDeviceUpdated(
51         const std::vector<std::shared_ptr<AudioStandard::AudioDeviceDescriptor>> &desc) override;
52 
53 private:
54     bool IsDistributedDeviceSelected(const std::vector<std::shared_ptr<AudioStandard::AudioDeviceDescriptor>> &desc);
55 };
56 
57 class AudioMicStateChangeCallback : public AudioStandard::AudioManagerMicStateChangeCallback {
58 public:
59     void OnMicStateUpdated(const AudioStandard::MicStateChangeEvent &micStateChangeEvent) override;
60 };
61 
62 class AudioProxy : public std::enable_shared_from_this<AudioProxy> {
63     DECLARE_DELAYED_SINGLETON(AudioProxy)
64 public:
65     bool SetVoiceRingtoneMute(bool isMute);
66     int32_t ActivateAudioInterrupt(const AudioStandard::AudioInterrupt &audioInterrupt);
67     int32_t DeactivateAudioInterrupt(const AudioStandard::AudioInterrupt &audioInterrupt);
68     int32_t DeactivateAudioInterrupt();
69     void SetVolumeAudible();
70     bool IsMicrophoneMute();
71     int32_t StartVibrator();
72     int32_t StopVibrator();
73     bool SetMicrophoneMute(bool mute);
74     bool SetEarpieceDevActive();
75     bool SetSpeakerDevActive(bool isActive);
76     bool SetBluetoothDevActive();
77     bool SetWiredHeadsetDevActive();
78     AudioStandard::AudioRingerMode GetRingerMode() const;
79     int32_t GetVolume(AudioStandard::AudioVolumeType audioVolumeType);
80     int32_t SetVolume(AudioStandard::AudioVolumeType audioVolumeType, int32_t volume);
81     int32_t SetVolumeWithDevice(AudioStandard::AudioVolumeType audioVolumeType, int32_t volume,
82         AudioStandard::DeviceType deviceType);
83     int32_t SetMaxVolume(AudioStandard::AudioVolumeType audioVolumeType);
84     bool IsStreamActive(AudioStandard::AudioVolumeType audioVolumeType);
85     bool IsStreamMute(AudioStandard::AudioVolumeType audioVolumeType);
86     int32_t GetMaxVolume(AudioStandard::AudioVolumeType audioVolumeType);
87     int32_t GetMinVolume(AudioStandard::AudioVolumeType audioVolumeType);
88     int32_t SetAudioDeviceChangeCallback();
89     std::string GetDefaultTonePath() const;
90     std::string GetDefaultDtmfPath() const;
91     int32_t UnsetDeviceChangeCallback();
92     void SetWiredHeadsetState(bool isConnected);
93     int32_t GetPreferredOutputAudioDevice(AudioDevice &device, bool isNeedCurrentDevice = false);
94     int32_t SetAudioPreferDeviceChangeCallback();
95     int32_t UnsetAudioPreferDeviceChangeCallback();
96     int32_t SetAudioMicStateChangeCallback();
97     int32_t UnsetAudioMicStateChangeCallback();
98     float GetSystemRingVolumeInDb(int32_t volumeLevel);
99     bool SetDeviceActive(AudioStandard::DeviceType deviceType, bool flag);
100 
101 private:
102     const std::string defaultTonePath_ = "/system/etc/telephony/tones/tone.wav";
103     const std::string defaultDtmfPath_ = "/system/etc/telephony/dtmfs/dtmf.wav";
104     std::shared_ptr<AudioStandard::AudioManagerDeviceChangeCallback> deviceCallback_;
105     std::shared_ptr<AudioStandard::AudioPreferredOutputDeviceChangeCallback> preferredDeviceCallback_;
106     std::shared_ptr<AudioStandard::AudioManagerMicStateChangeCallback> audioMicStateChangeCallback_;
107     bool isWiredHeadsetConnected_ = false;
108     bool loopFlag_ = false;
109 };
110 } // namespace Telephony
111 } // namespace OHOS
112 #endif // TELEPHONY_AUDIO_PROXY_H
113