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_manager_proxy.h" 24 #include "audio_system_manager.h" 25 #include "call_manager_errors.h" 26 #include "call_manager_inner_type.h" 27 #include "singleton.h" 28 29 namespace OHOS { 30 namespace Telephony { 31 constexpr uint16_t VOLUME_AUDIBLE_DIVISOR = 2; 32 33 enum AudioInterruptState { 34 INTERRUPT_STATE_UNKNOWN = 0, 35 INTERRUPT_STATE_DEACTIVATED, 36 INTERRUPT_STATE_ACTIVATED, 37 INTERRUPT_STATE_RINGING, 38 }; 39 40 enum class VibrationType { 41 VIBRATION_RINGTONE = 0, 42 }; 43 44 class AudioDeviceChangeCallback : public AudioStandard::AudioManagerDeviceChangeCallback { 45 void OnDeviceChange(const AudioStandard::DeviceChangeAction &deviceChangeAction) override; 46 }; 47 48 class AudioPreferDeviceChangeCallback : public AudioStandard::AudioPreferredOutputDeviceChangeCallback { 49 public: 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 bool SetBluetoothDevice(AudioDevice &device, 56 const std::vector<std::shared_ptr<AudioStandard::AudioDeviceDescriptor>> &desc); 57 }; 58 59 class AudioMicStateChangeCallback : public AudioStandard::AudioManagerMicStateChangeCallback { 60 public: 61 void OnMicStateUpdated(const AudioStandard::MicStateChangeEvent &micStateChangeEvent) override; 62 }; 63 64 class AudioProxy : public std::enable_shared_from_this<AudioProxy> { 65 DECLARE_DELAYED_SINGLETON(AudioProxy) 66 public: 67 bool SetVoiceRingtoneMute(bool isMute); 68 int32_t ActivateAudioInterrupt(const AudioStandard::AudioInterrupt &audioInterrupt); 69 int32_t DeactivateAudioInterrupt(const AudioStandard::AudioInterrupt &audioInterrupt); 70 int32_t DeactivateAudioInterrupt(); 71 void SetVolumeAudible(); 72 bool IsMicrophoneMute(); 73 int32_t StartVibrator(); 74 int32_t StopVibrator(); 75 bool SetMicrophoneMute(bool mute); 76 bool SetEarpieceDevActive(); 77 bool SetSpeakerDevActive(bool isActive); 78 bool SetBluetoothDevActive(); 79 bool SetWiredHeadsetDevActive(); 80 AudioStandard::AudioRingerMode GetRingerMode() const; 81 int32_t GetVolume(AudioStandard::AudioVolumeType audioVolumeType); 82 int32_t SetVolume(AudioStandard::AudioVolumeType audioVolumeType, int32_t volume); 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); 94 int32_t SetAudioPreferDeviceChangeCallback(); 95 int32_t UnsetAudioPreferDeviceChangeCallback(); 96 int32_t SetAudioMicStateChangeCallback(); 97 int32_t UnsetAudioMicStateChangeCallback(); 98 float GetSystemRingVolumeInDb(int32_t volumeLevel); 99 100 private: 101 const std::string defaultTonePath_ = "/system/etc/telephony/tones/tone.wav"; 102 const std::string defaultDtmfPath_ = "/system/etc/telephony/dtmfs/dtmf.wav"; 103 std::shared_ptr<AudioStandard::AudioManagerDeviceChangeCallback> deviceCallback_; 104 std::shared_ptr<AudioStandard::AudioPreferredOutputDeviceChangeCallback> preferredDeviceCallback_; 105 std::shared_ptr<AudioStandard::AudioManagerMicStateChangeCallback> audioMicStateChangeCallback_; 106 bool isWiredHeadsetConnected_ = false; 107 }; 108 } // namespace Telephony 109 } // namespace OHOS 110 #endif // TELEPHONY_AUDIO_PROXY_H 111