1e1c44949Sopenharmony_ci/*
2e1c44949Sopenharmony_ci * Copyright (C) 2021-2023 Huawei Device Co., Ltd.
3e1c44949Sopenharmony_ci * Licensed under the Apache License, Version 2.0 (the "License");
4e1c44949Sopenharmony_ci * you may not use this file except in compliance with the License.
5e1c44949Sopenharmony_ci * You may obtain a copy of the License at
6e1c44949Sopenharmony_ci *
7e1c44949Sopenharmony_ci *     http://www.apache.org/licenses/LICENSE-2.0
8e1c44949Sopenharmony_ci *
9e1c44949Sopenharmony_ci * Unless required by applicable law or agreed to in writing, software
10e1c44949Sopenharmony_ci * distributed under the License is distributed on an "AS IS" BASIS,
11e1c44949Sopenharmony_ci * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12e1c44949Sopenharmony_ci * See the License for the specific language governing permissions and
13e1c44949Sopenharmony_ci * limitations under the License.
14e1c44949Sopenharmony_ci */
15e1c44949Sopenharmony_ci
16e1c44949Sopenharmony_ci#ifndef TELEPHONY_AUDIO_DEVICE_MANAGER_H
17e1c44949Sopenharmony_ci#define TELEPHONY_AUDIO_DEVICE_MANAGER_H
18e1c44949Sopenharmony_ci
19e1c44949Sopenharmony_ci#include <map>
20e1c44949Sopenharmony_ci
21e1c44949Sopenharmony_ci#include "audio_base.h"
22e1c44949Sopenharmony_ci#include "call_base.h"
23e1c44949Sopenharmony_ci#include "call_manager_inner_type.h"
24e1c44949Sopenharmony_ci#include "singleton.h"
25e1c44949Sopenharmony_ci
26e1c44949Sopenharmony_cinamespace OHOS {
27e1c44949Sopenharmony_cinamespace Telephony {
28e1c44949Sopenharmony_ci/**
29e1c44949Sopenharmony_ci * @class AudioDeviceManager
30e1c44949Sopenharmony_ci * describes the available devices of a call.
31e1c44949Sopenharmony_ci */
32e1c44949Sopenharmony_ciclass AudioDeviceManager : public std::enable_shared_from_this<AudioDeviceManager> {
33e1c44949Sopenharmony_ci    DECLARE_DELAYED_SINGLETON(AudioDeviceManager)
34e1c44949Sopenharmony_cipublic:
35e1c44949Sopenharmony_ci    void Init();
36e1c44949Sopenharmony_ci    bool InitAudioDevice();
37e1c44949Sopenharmony_ci    bool ProcessEvent(AudioEvent event);
38e1c44949Sopenharmony_ci    static bool IsEarpieceAvailable();
39e1c44949Sopenharmony_ci    static bool IsSpeakerAvailable();
40e1c44949Sopenharmony_ci    static bool IsBtScoConnected();
41e1c44949Sopenharmony_ci    static bool IsBtActived();
42e1c44949Sopenharmony_ci    static bool IsDistributedCallConnected();
43e1c44949Sopenharmony_ci    static bool IsWiredHeadsetConnected();
44e1c44949Sopenharmony_ci    static void SetDeviceAvailable(AudioDeviceType deviceType, bool available);
45e1c44949Sopenharmony_ci    bool SwitchDevice(AudioDeviceType device);
46e1c44949Sopenharmony_ci    void AddAudioDeviceList(const std::string &address, AudioDeviceType deviceType, const std::string &deviceName);
47e1c44949Sopenharmony_ci    void RemoveAudioDeviceList(const std::string &address, AudioDeviceType deviceType);
48e1c44949Sopenharmony_ci    void ResetBtAudioDevicesList();
49e1c44949Sopenharmony_ci    void ResetDistributedCallDevicesList();
50e1c44949Sopenharmony_ci    int32_t ReportAudioDeviceChange(const AudioDevice &device);
51e1c44949Sopenharmony_ci    bool CheckAndSwitchDistributedAudioDevice();
52e1c44949Sopenharmony_ci    int32_t ReportAudioDeviceInfo();
53e1c44949Sopenharmony_ci    int32_t ReportAudioDeviceInfo(sptr<CallBase> call);
54e1c44949Sopenharmony_ci    void SetCurrentAudioDevice(AudioDeviceType deviceType);
55e1c44949Sopenharmony_ci    void SetCurrentAudioDevice(const AudioDevice &device);
56e1c44949Sopenharmony_ci    void OnActivedCallDisconnected();
57e1c44949Sopenharmony_ci    void SetMuteState(bool isMuted);
58e1c44949Sopenharmony_ci    bool GetMuteState();
59e1c44949Sopenharmony_ci    std::string ConvertAddress();
60e1c44949Sopenharmony_ci
61e1c44949Sopenharmony_ci    /**
62e1c44949Sopenharmony_ci     * UpdateEarpieceDevice
63e1c44949Sopenharmony_ci     *
64e1c44949Sopenharmony_ci     * @brief update earpiece device
65e1c44949Sopenharmony_ci     */
66e1c44949Sopenharmony_ci    void UpdateEarpieceDevice();
67e1c44949Sopenharmony_ci
68e1c44949Sopenharmony_ci    /**
69e1c44949Sopenharmony_ci     * @brief Update bluetooth device name
70e1c44949Sopenharmony_ci     *
71e1c44949Sopenharmony_ci     * @param macAddress[in], mac address
72e1c44949Sopenharmony_ci     * @param deviceName[in], device name
73e1c44949Sopenharmony_ci     */
74e1c44949Sopenharmony_ci    void UpdateBluetoothDeviceName(const std::string &macAddress, const std::string &deviceName);
75e1c44949Sopenharmony_ci
76e1c44949Sopenharmony_ciprivate:
77e1c44949Sopenharmony_ci    std::mutex mutex_;
78e1c44949Sopenharmony_ci    std::mutex infoMutex_;
79e1c44949Sopenharmony_ci    AudioDeviceType audioDeviceType_;
80e1c44949Sopenharmony_ci    static bool isBtScoDevEnable_;
81e1c44949Sopenharmony_ci    static bool isDCallDevEnable_;
82e1c44949Sopenharmony_ci    bool isWiredHeadsetDevEnable_ = false;
83e1c44949Sopenharmony_ci    bool isSpeakerDevEnable_ = false;
84e1c44949Sopenharmony_ci    bool isEarpieceDevEnable_ = false;
85e1c44949Sopenharmony_ci    std::unique_ptr<AudioBase> currentAudioDevice_;
86e1c44949Sopenharmony_ci    static bool isEarpieceAvailable_;
87e1c44949Sopenharmony_ci    static bool isSpeakerAvailable_;
88e1c44949Sopenharmony_ci    static bool isUpdateEarpieceDevice_;
89e1c44949Sopenharmony_ci    static bool isWiredHeadsetConnected_;
90e1c44949Sopenharmony_ci    static bool isBtScoConnected_;
91e1c44949Sopenharmony_ci    static bool isDCallDevConnected_;
92e1c44949Sopenharmony_ci    bool isAudioActivated_;
93e1c44949Sopenharmony_ci    using AudioDeviceManagerFunc = std::function<bool()>;
94e1c44949Sopenharmony_ci    std::map<uint32_t, AudioDeviceManagerFunc> memberFuncMap_;
95e1c44949Sopenharmony_ci    AudioDeviceInfo info_;
96e1c44949Sopenharmony_ci    bool SwitchDevice(AudioEvent event);
97e1c44949Sopenharmony_ci    bool EnableBtSco();
98e1c44949Sopenharmony_ci    bool EnableWiredHeadset();
99e1c44949Sopenharmony_ci    bool EnableSpeaker();
100e1c44949Sopenharmony_ci    bool EnableEarpiece();
101e1c44949Sopenharmony_ci    bool DisableAll();
102e1c44949Sopenharmony_ci    bool IsBtScoDevEnable();
103e1c44949Sopenharmony_ci    bool IsDCallDevEnable();
104e1c44949Sopenharmony_ci    bool IsSpeakerDevEnable();
105e1c44949Sopenharmony_ci    bool IsEarpieceDevEnable();
106e1c44949Sopenharmony_ci    bool IsWiredHeadsetDevEnable();
107e1c44949Sopenharmony_ci    AudioDeviceType GetCurrentAudioDevice();
108e1c44949Sopenharmony_ci    bool IsDistributedAudioDeviceType(AudioDeviceType deviceType);
109e1c44949Sopenharmony_ci    bool IsSupportEarpiece();
110e1c44949Sopenharmony_ci};
111e1c44949Sopenharmony_ci} // namespace Telephony
112e1c44949Sopenharmony_ci} // namespace OHOS
113e1c44949Sopenharmony_ci#endif // TELEPHONY_AUDIO_DEVICE_MANAGER_H