• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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     static bool SetVirtualCall(bool isVirtual);
46     bool SwitchDevice(AudioDeviceType device);
47     void AddAudioDeviceList(const std::string &address, AudioDeviceType deviceType, const std::string &deviceName);
48     void RemoveAudioDeviceList(const std::string &address, AudioDeviceType deviceType);
49     void ResetBtAudioDevicesList();
50     void ResetDistributedCallDevicesList();
51     int32_t ReportAudioDeviceChange(const AudioDevice &device);
52     bool CheckAndSwitchDistributedAudioDevice();
53     int32_t ReportAudioDeviceInfo();
54     int32_t ReportAudioDeviceInfo(sptr<CallBase> call);
55     void SetCurrentAudioDevice(AudioDeviceType deviceType);
56     void SetCurrentAudioDevice(const AudioDevice &device);
57     void OnActivedCallDisconnected();
58     void SetMuteState(bool isMuted);
59     bool GetMuteState();
60     std::string ConvertAddress();
61 
62     /**
63      * UpdateEarpieceDevice
64      *
65      * @brief update earpiece device
66      */
67     void UpdateEarpieceDevice();
68 
69     /**
70      * @brief Update bluetooth device name
71      *
72      * @param macAddress[in], mac address
73      * @param deviceName[in], device name
74      */
75     void UpdateBluetoothDeviceName(const std::string &macAddress, const std::string &deviceName);
76 
77     AudioDeviceType GetCurrentAudioDevice();
78 
79 private:
80     std::mutex mutex_;
81     std::mutex infoMutex_;
82     AudioDeviceType audioDeviceType_;
83     static bool isBtScoDevEnable_;
84     static bool isDCallDevEnable_;
85     bool isWiredHeadsetDevEnable_ = false;
86     bool isSpeakerDevEnable_ = false;
87     bool isEarpieceDevEnable_ = false;
88     std::unique_ptr<AudioBase> currentAudioDevice_;
89     static bool isEarpieceAvailable_;
90     static bool isSpeakerAvailable_;
91     static bool isUpdateEarpieceDevice_;
92     static bool isWiredHeadsetConnected_;
93     static bool isBtScoConnected_;
94     static bool isDCallDevConnected_;
95     bool isAudioActivated_;
96     using AudioDeviceManagerFunc = std::function<bool()>;
97     std::map<uint32_t, AudioDeviceManagerFunc> memberFuncMap_;
98     AudioDeviceInfo info_;
99     bool SwitchDevice(AudioEvent event);
100     bool EnableBtSco();
101     bool EnableWiredHeadset();
102     bool EnableSpeaker();
103     bool EnableEarpiece();
104     bool DisableAll();
105     bool IsBtScoDevEnable();
106     bool IsDCallDevEnable();
107     bool IsSpeakerDevEnable();
108     bool IsEarpieceDevEnable();
109     bool IsWiredHeadsetDevEnable();
110     bool IsDistributedAudioDeviceType(AudioDeviceType deviceType);
111     bool IsSupportEarpiece();
112     void AddEarpiece();
113 };
114 } // namespace Telephony
115 } // namespace OHOS
116 #endif // TELEPHONY_AUDIO_DEVICE_MANAGER_H