• 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 SwitchDevice(AudioDevice device);
47 
48 private:
49     std::mutex mutex_;
50     AudioDevice audioDevice_;
51     static bool isBtScoDevEnable_;
52     bool isWiredHeadsetDevEnable_ = false;
53     bool isSpeakerDevEnable_ = false;
54     bool isEarpieceDevEnable_ = false;
55     std::unique_ptr<AudioBase> currentAudioDevice_;
56     static bool isEarpieceAvailable_;
57     static bool isSpeakerAvailable_;
58     static bool isWiredHeadsetConnected_;
59     static bool isBtScoConnected_;
60     bool isAudioActivated_;
61     using AudioDeviceManagerFunc = bool (AudioDeviceManager::*)();
62     std::map<uint32_t, AudioDeviceManagerFunc> memberFuncMap_;
63     bool SwitchDevice(AudioEvent event);
64     bool EnableBtSco();
65     bool EnableWiredHeadset();
66     bool EnableSpeaker();
67     bool EnableEarpiece();
68     bool DisableAll();
69     bool IsBtScoDevEnable();
70     bool IsSpeakerDevEnable();
71     bool IsEarpieceDevEnable();
72     bool IsWiredHeadsetDevEnable();
73     void SetBtScoDevEnable();
74     void SetSpeakerDevEnable();
75     void SetEarpieceDevEnable();
76     void SetWiredHeadsetDevEnable();
77     AudioDevice GetCurrentAudioDevice();
78     void SetCurrentAudioDevice(AudioDevice device);
79 };
80 } // namespace Telephony
81 } // namespace OHOS
82 #endif // TELEPHONY_AUDIO_DEVICE_MANAGER_H