1 /* 2 * Copyright (C) 2021-2023 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_DEVICE_MANAGER_H 17 #define TELEPHONY_AUDIO_DEVICE_MANAGER_H 18 19 #include <map> 20 21 #include "audio_base.h" 22 #include "call_manager_inner_type.h" 23 #include "singleton.h" 24 25 namespace OHOS { 26 namespace Telephony { 27 /** 28 * @class AudioDeviceManager 29 * describes the available devices of a call. 30 */ 31 class AudioDeviceManager : public std::enable_shared_from_this<AudioDeviceManager> { 32 DECLARE_DELAYED_SINGLETON(AudioDeviceManager) 33 public: 34 void Init(); 35 bool InitAudioDevice(); 36 bool ProcessEvent(AudioEvent event); 37 static bool IsEarpieceAvailable(); 38 static bool IsSpeakerAvailable(); 39 static bool IsBtScoConnected(); 40 static bool IsDistributedCallConnected(); 41 static bool IsWiredHeadsetConnected(); 42 static void SetDeviceAvailable(AudioDeviceType deviceType, bool available); 43 bool SwitchDevice(AudioDeviceType device); 44 void AddAudioDeviceList(const std::string &address, AudioDeviceType deviceType); 45 void RemoveAudioDeviceList(const std::string &address, AudioDeviceType deviceType); 46 void ResetBtAudioDevicesList(); 47 void ResetDistributedCallDevicesList(); 48 int32_t ReportAudioDeviceChange(); 49 int32_t ReportAudioDeviceInfo(); 50 void SetCurrentAudioDevice(AudioDeviceType deviceType); 51 bool CheckAndSwitchDistributedAudioDevice(); 52 void OnActivedCallDisconnected(); 53 void SetMuteState(bool isMuted); 54 bool GetMuteState(); 55 56 private: 57 std::mutex mutex_; 58 std::mutex infoMutex_; 59 AudioDeviceType audioDeviceType_; 60 static bool isBtScoDevEnable_; 61 static bool isDCallDevEnable_; 62 bool isWiredHeadsetDevEnable_ = false; 63 bool isSpeakerDevEnable_ = false; 64 bool isEarpieceDevEnable_ = false; 65 std::unique_ptr<AudioBase> currentAudioDevice_; 66 static bool isEarpieceAvailable_; 67 static bool isSpeakerAvailable_; 68 static bool isWiredHeadsetConnected_; 69 static bool isBtScoConnected_; 70 static bool isDCallDevConnected_; 71 bool isAudioActivated_; 72 using AudioDeviceManagerFunc = bool (AudioDeviceManager::*)(); 73 std::map<uint32_t, AudioDeviceManagerFunc> memberFuncMap_; 74 AudioDeviceInfo info_; 75 bool SwitchDevice(AudioEvent event); 76 bool EnableBtSco(); 77 bool EnableDistributedCall(); 78 bool EnableWiredHeadset(); 79 bool EnableSpeaker(); 80 bool EnableEarpiece(); 81 bool DisableAll(); 82 bool IsBtScoDevEnable(); 83 bool IsDCallDevEnable(); 84 bool IsSpeakerDevEnable(); 85 bool IsEarpieceDevEnable(); 86 bool IsWiredHeadsetDevEnable(); 87 AudioDeviceType GetCurrentAudioDevice(); 88 bool IsDistributedAudioDeviceType(AudioDeviceType deviceType); 89 }; 90 } // namespace Telephony 91 } // namespace OHOS 92 #endif // TELEPHONY_AUDIO_DEVICE_MANAGER_H