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_base.h" 23 #include "call_manager_inner_type.h" 24 #include "singleton.h" 25 26 namespace OHOS { 27 namespace Telephony { 28 /** 29 * @class AudioDeviceManager 30 * describes the available devices of a call. 31 */ 32 class AudioDeviceManager : public std::enable_shared_from_this<AudioDeviceManager> { 33 DECLARE_DELAYED_SINGLETON(AudioDeviceManager) 34 public: 35 void Init(); 36 bool InitAudioDevice(); 37 bool ProcessEvent(AudioEvent event); 38 static bool IsEarpieceAvailable(); 39 static bool IsSpeakerAvailable(); 40 static bool IsBtScoConnected(); 41 static bool IsBtActived(); 42 static bool IsDistributedCallConnected(); 43 static bool IsWiredHeadsetConnected(); 44 static void SetDeviceAvailable(AudioDeviceType deviceType, bool available); 45 bool SwitchDevice(AudioDeviceType device); 46 void AddAudioDeviceList(const std::string &address, AudioDeviceType deviceType, const std::string &deviceName); 47 void RemoveAudioDeviceList(const std::string &address, AudioDeviceType deviceType); 48 void ResetBtAudioDevicesList(); 49 void ResetDistributedCallDevicesList(); 50 int32_t ReportAudioDeviceChange(const AudioDevice &device); 51 bool CheckAndSwitchDistributedAudioDevice(); 52 int32_t ReportAudioDeviceInfo(); 53 int32_t ReportAudioDeviceInfo(sptr<CallBase> call); 54 void SetCurrentAudioDevice(AudioDeviceType deviceType); 55 void SetCurrentAudioDevice(const AudioDevice &device); 56 void OnActivedCallDisconnected(); 57 void SetMuteState(bool isMuted); 58 bool GetMuteState(); 59 std::string ConvertAddress(); 60 61 /** 62 * UpdateEarpieceDevice 63 * 64 * @brief update earpiece device 65 */ 66 void UpdateEarpieceDevice(); 67 68 /** 69 * @brief Update bluetooth device name 70 * 71 * @param macAddress[in], mac address 72 * @param deviceName[in], device name 73 */ 74 void UpdateBluetoothDeviceName(const std::string &macAddress, const std::string &deviceName); 75 76 private: 77 std::mutex mutex_; 78 std::mutex infoMutex_; 79 AudioDeviceType audioDeviceType_; 80 static bool isBtScoDevEnable_; 81 static bool isDCallDevEnable_; 82 bool isWiredHeadsetDevEnable_ = false; 83 bool isSpeakerDevEnable_ = false; 84 bool isEarpieceDevEnable_ = false; 85 std::unique_ptr<AudioBase> currentAudioDevice_; 86 static bool isEarpieceAvailable_; 87 static bool isSpeakerAvailable_; 88 static bool isUpdateEarpieceDevice_; 89 static bool isWiredHeadsetConnected_; 90 static bool isBtScoConnected_; 91 static bool isDCallDevConnected_; 92 bool isAudioActivated_; 93 using AudioDeviceManagerFunc = std::function<bool()>; 94 std::map<uint32_t, AudioDeviceManagerFunc> memberFuncMap_; 95 AudioDeviceInfo info_; 96 bool SwitchDevice(AudioEvent event); 97 bool EnableBtSco(); 98 bool EnableDistributedCall(); 99 bool EnableWiredHeadset(); 100 bool EnableSpeaker(); 101 bool EnableEarpiece(); 102 bool DisableAll(); 103 bool IsBtScoDevEnable(); 104 bool IsDCallDevEnable(); 105 bool IsSpeakerDevEnable(); 106 bool IsEarpieceDevEnable(); 107 bool IsWiredHeadsetDevEnable(); 108 AudioDeviceType GetCurrentAudioDevice(); 109 bool IsDistributedAudioDeviceType(AudioDeviceType deviceType); 110 bool IsSupportEarpiece(); 111 }; 112 } // namespace Telephony 113 } // namespace OHOS 114 #endif // TELEPHONY_AUDIO_DEVICE_MANAGER_H