• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 "audio_base.h"
20 
21 #include <map>
22 
23 #include "singleton.h"
24 
25 #include "call_manager_inner_type.h"
26 
27 namespace OHOS {
28 namespace Telephony {
29 /**
30  * @class AudioDeviceManager
31  * describes the available devices of a call.
32  */
33 class AudioDeviceManager : public std::enable_shared_from_this<AudioDeviceManager> {
34     DECLARE_DELAYED_SINGLETON(AudioDeviceManager)
35 public:
36     void Init();
37     bool InitAudioDevice();
38     bool ProcessEvent(AudioEvent event);
39     static bool IsEarpieceAvailable();
40     static bool IsSpeakerAvailable();
41     static bool IsBtScoConnected();
42     static bool IsWiredHeadsetConnected();
43     static void SetSpeakerAvailable(bool available);
44     static void SetWiredHeadsetAvailable(bool available);
45     static void SetBtScoAvailable(bool available);
46     bool ConnectBtScoWithAddress(const std::string &bluetoothAddress);
47     bool SwitchDevice(AudioDevice device);
48 
49 private:
50     std::mutex mutex_;
51     AudioDevice audioDevice_;
52     static bool isBtScoDevEnable_;
53     bool isWiredHeadsetDevEnable_ = false;
54     bool isSpeakerDevEnable_ = false;
55     bool isEarpieceDevEnable_ = false;
56     std::unique_ptr<AudioBase> currentAudioDevice_;
57     static bool isEarpieceAvailable_;
58     static bool isSpeakerAvailable_;
59     static bool isWiredHeadsetConnected_;
60     static bool isBtScoConnected_;
61     bool isAudioActivated_;
62     using AudioDeviceManagerFunc = bool (AudioDeviceManager::*)();
63     std::map<uint32_t, AudioDeviceManagerFunc> memberFuncMap_;
64     bool SwitchDevice(AudioEvent event);
65     bool EnableBtSco();
66     bool EnableWiredHeadset();
67     bool EnableSpeaker();
68     bool EnableEarpiece();
69     bool DisableAll();
70     bool IsBtScoDevEnable();
71     bool IsSpeakerDevEnable();
72     bool IsEarpieceDevEnable();
73     bool IsWiredHeadsetDevEnable();
74     void SetBtScoDevEnable();
75     void SetSpeakerDevEnable();
76     void SetEarpieceDevEnable();
77     void SetWiredHeadsetDevEnable();
78     AudioDevice GetCurrentAudioDevice();
79     void SetCurrentAudioDevice(AudioDevice device);
80 };
81 } // namespace Telephony
82 } // namespace OHOS
83 #endif // TELEPHONY_AUDIO_DEVICE_MANAGER_H