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(const std::vector<sptr<AudioStandard::AudioDeviceDescriptor>> &desc) override; 51 }; 52 53 class AudioProxy : public std::enable_shared_from_this<AudioProxy> { 54 DECLARE_DELAYED_SINGLETON(AudioProxy) 55 public: 56 bool SetAudioScene(AudioStandard::AudioScene audioScene); 57 int32_t ActivateAudioInterrupt(const AudioStandard::AudioInterrupt &audioInterrupt); 58 int32_t DeactivateAudioInterrupt(const AudioStandard::AudioInterrupt &audioInterrupt); 59 int32_t DeactivateAudioInterrupt(); 60 void SetVolumeAudible(); 61 bool IsMicrophoneMute(); 62 int32_t StartVibrator(); 63 int32_t StopVibrator(); 64 bool SetMicrophoneMute(bool mute); 65 bool SetEarpieceDevActive(); 66 bool SetSpeakerDevActive(); 67 bool SetBluetoothDevActive(); 68 bool SetWiredHeadsetDevActive(); 69 AudioStandard::AudioRingerMode GetRingerMode() const; 70 int32_t GetVolume(AudioStandard::AudioVolumeType audioVolumeType); 71 int32_t SetVolume(AudioStandard::AudioVolumeType audioVolumeType, int32_t volume); 72 int32_t SetMaxVolume(AudioStandard::AudioVolumeType audioVolumeType); 73 bool IsStreamActive(AudioStandard::AudioVolumeType audioVolumeType); 74 bool IsStreamMute(AudioStandard::AudioVolumeType audioVolumeType); 75 int32_t GetMaxVolume(AudioStandard::AudioVolumeType audioVolumeType); 76 int32_t GetMinVolume(AudioStandard::AudioVolumeType audioVolumeType); 77 int32_t SetAudioDeviceChangeCallback(); 78 bool IsVibrateMode() const; 79 int32_t StartVibrate(); 80 int32_t CancelVibrate(); 81 std::string GetDefaultRingPath() const; 82 std::string GetDefaultTonePath() const; 83 std::string GetDefaultDtmfPath() const; 84 int32_t UnsetDeviceChangeCallback(); 85 void SetWiredHeadsetState(bool isConnected); 86 int32_t GetPreferredOutputAudioDevice(AudioDevice &device); 87 int32_t SetAudioPreferDeviceChangeCallback(); 88 int32_t UnsetAudioPreferDeviceChangeCallback(); 89 90 private: 91 const std::string defaultRingPath_ = "/system/etc/telephony/rings/ring.wav"; 92 const std::string defaultTonePath_ = "/system/etc/telephony/tones/tone.wav"; 93 const std::string defaultDtmfPath_ = "/system/etc/telephony/dtmfs/dtmf.wav"; 94 std::shared_ptr<AudioStandard::AudioManagerDeviceChangeCallback> deviceCallback_; 95 std::shared_ptr<AudioStandard::AudioPreferredOutputDeviceChangeCallback> preferredDeviceCallback_; 96 bool isWiredHeadsetConnected_ = false; 97 }; 98 } // namespace Telephony 99 } // namespace OHOS 100 #endif // TELEPHONY_AUDIO_PROXY_H 101