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_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 IsWiredHeadsetConnected(); 41 static void SetDeviceAvailable(AudioDeviceType deviceType, bool available); 42 bool ConnectBtScoWithAddress(const std::string &bluetoothAddress); 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 int32_t ReportAudioDeviceChange(); 48 void SetCurrentAudioDevice(AudioDeviceType deviceType); 49 50 private: 51 std::mutex mutex_; 52 std::mutex infoMutex_; 53 AudioDeviceType audioDeviceType_; 54 static bool isBtScoDevEnable_; 55 bool isWiredHeadsetDevEnable_ = false; 56 bool isSpeakerDevEnable_ = false; 57 bool isEarpieceDevEnable_ = false; 58 std::unique_ptr<AudioBase> currentAudioDevice_; 59 static bool isEarpieceAvailable_; 60 static bool isSpeakerAvailable_; 61 static bool isWiredHeadsetConnected_; 62 static bool isBtScoConnected_; 63 bool isAudioActivated_; 64 using AudioDeviceManagerFunc = bool (AudioDeviceManager::*)(); 65 std::map<uint32_t, AudioDeviceManagerFunc> memberFuncMap_; 66 AudioDeviceInfo info_; 67 bool SwitchDevice(AudioEvent event); 68 bool EnableBtSco(); 69 bool EnableWiredHeadset(); 70 bool EnableSpeaker(); 71 bool EnableEarpiece(); 72 bool DisableAll(); 73 bool IsBtScoDevEnable(); 74 bool IsSpeakerDevEnable(); 75 bool IsEarpieceDevEnable(); 76 bool IsWiredHeadsetDevEnable(); 77 AudioDeviceType GetCurrentAudioDevice(); 78 }; 79 } // namespace Telephony 80 } // namespace OHOS 81 #endif // TELEPHONY_AUDIO_DEVICE_MANAGER_H