• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2023-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 BLUETOOTH_DEVICE_MANAGER_H
17 #define BLUETOOTH_DEVICE_MANAGER_H
18 
19 #include <mutex>
20 #include "bluetooth_hfp_ag.h"
21 #include "bluetooth_device_utils.h"
22 #include "audio_info.h"
23 #include "audio_errors.h"
24 #include "audio_log.h"
25 #include "audio_system_manager.h"
26 #include "idevice_status_observer.h"
27 
28 namespace OHOS {
29 namespace Bluetooth {
30 
31 int32_t RegisterDeviceObserver(AudioStandard::IDeviceStatusObserver &observer);
32 void UnregisterDeviceObserver();
33 void SendUserSelectionEvent(AudioStandard::DeviceType devType, const std::string &macAddress, int32_t eventType);
34 
35 class MediaBluetoothDeviceManager {
36 public:
37     MediaBluetoothDeviceManager() = default;
38     virtual ~MediaBluetoothDeviceManager() = default;
39     static void SetMediaStack(const BluetoothRemoteDevice &device, int action);
40     static void HandleConnectDevice(const BluetoothRemoteDevice &device);
41     static void HandleDisconnectDevice(const BluetoothRemoteDevice &device);
42     static void HandleWearDevice(const BluetoothRemoteDevice &device);
43     static void HandleUnwearDevice(const BluetoothRemoteDevice &device);
44     static void HandleEnableDevice(const BluetoothRemoteDevice &device);
45     static void HandleDisableDevice(const BluetoothRemoteDevice &device);
46     static void HandleWearEnable(const BluetoothRemoteDevice &device);
47     static void HandleWearDisable(const BluetoothRemoteDevice &device);
48     static void HandleUserSelection(const BluetoothRemoteDevice &device);
49     static void AddDeviceInConfigVector(const BluetoothRemoteDevice &device,
50         std::vector<BluetoothRemoteDevice> &deviceVector);
51     static void RemoveDeviceInConfigVector(const BluetoothRemoteDevice &device,
52         std::vector<BluetoothRemoteDevice> &deviceVector);
53     static void NotifyToUpdateAudioDevice(const BluetoothRemoteDevice &device,
54         AudioStandard::AudioDeviceDescriptor &desc, DeviceStatus deviceStatus);
55     static bool IsA2dpBluetoothDeviceExist(const std::string& macAddress);
56     static int32_t GetConnectedA2dpBluetoothDevice(const std::string& macAddress, BluetoothRemoteDevice &device);
57     static void UpdateA2dpDeviceConfiguration(const BluetoothRemoteDevice &device,
58         const AudioStandard::AudioStreamInfo &streamInfo);
59     static void ClearAllA2dpBluetoothDevice();
60 
61 private:
62     static std::map<std::string, BluetoothRemoteDevice> a2dpBluetoothDeviceMap_;
63     static std::map<std::string, BluetoothDeviceAction> wearDetectionStateMap_;
64     static std::vector<BluetoothRemoteDevice> privacyDevices_;
65     static std::vector<BluetoothRemoteDevice> commonDevices_;
66     static std::vector<BluetoothRemoteDevice> negativeDevices_;
67 };
68 
69 class HfpBluetoothDeviceManager {
70 public:
71     HfpBluetoothDeviceManager() = default;
72     virtual ~HfpBluetoothDeviceManager() = default;
73     static void SetHfpStack(const BluetoothRemoteDevice &device, int action);
74     static void HandleConnectDevice(const BluetoothRemoteDevice &device);
75     static void HandleDisconnectDevice(const BluetoothRemoteDevice &device);
76     static void HandleWearDevice(const BluetoothRemoteDevice &device);
77     static void HandleUnwearDevice(const BluetoothRemoteDevice &device);
78     static void HandleEnableDevice(const BluetoothRemoteDevice &device);
79     static void HandleDisableDevice(const BluetoothRemoteDevice &device);
80     static void HandleWearEnable(const BluetoothRemoteDevice &device);
81     static void HandleWearDisable(const BluetoothRemoteDevice &device);
82     static void HandleUserSelection(const BluetoothRemoteDevice &device);
83     static void AddDeviceInConfigVector(const BluetoothRemoteDevice &device,
84         std::vector<BluetoothRemoteDevice> &deviceVector);
85     static void RemoveDeviceInConfigVector(const BluetoothRemoteDevice &device,
86         std::vector<BluetoothRemoteDevice> &deviceVector);
87     static void NotifyToUpdateAudioDevice(const BluetoothRemoteDevice &device,
88         AudioStandard::AudioDeviceDescriptor &desc, DeviceStatus deviceStatus);
89     static bool IsHfpBluetoothDeviceExist(const std::string& macAddress);
90     static void UpdateHfpDeviceConfiguration(const BluetoothRemoteDevice &device,
91         const AudioStandard::AudioStreamInfo &streamInfo);
92     static void OnScoStateChanged(const BluetoothRemoteDevice &device, bool isConnected);
93     static int32_t GetConnectedHfpBluetoothDevice(const std::string& macAddress, BluetoothRemoteDevice &device);
94     static void ClearAllHfpBluetoothDevice();
95 
96 private:
97     static std::map<std::string, BluetoothRemoteDevice> hfpBluetoothDeviceMap_;
98     static std::map<std::string, BluetoothDeviceAction> wearDetectionStateMap_;
99     static std::vector<BluetoothRemoteDevice> privacyDevices_;
100     static std::vector<BluetoothRemoteDevice> commonDevices_;
101     static std::vector<BluetoothRemoteDevice> negativeDevices_;
102 };
103 } // namespace Bluetooth
104 } // namespace OHOS
105 
106 #endif // BLUETOOTH_DEVICE_MANAGER_H