/* * Copyright (c) 2023-2023 Huawei Device Co., Ltd. * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ #ifndef BLUETOOTH_DEVICE_MANAGER_H #define BLUETOOTH_DEVICE_MANAGER_H #include #include "bluetooth_hfp_ag.h" #include "bluetooth_device_utils.h" #include "audio_info.h" #include "audio_errors.h" #include "audio_common_log.h" #include "audio_system_manager.h" #include "idevice_status_observer.h" namespace OHOS { namespace Bluetooth { int32_t RegisterDeviceObserver(AudioStandard::IDeviceStatusObserver &observer); void UnregisterDeviceObserver(); void SendUserSelectionEvent(AudioStandard::DeviceType devType, const std::string &macAddress, int32_t eventType); bool IsBTWearDetectionEnable(const BluetoothRemoteDevice &device); std::string GetEncryptAddr(const std::string &addr); class MediaBluetoothDeviceManager { public: MediaBluetoothDeviceManager() = default; virtual ~MediaBluetoothDeviceManager() = default; static void SetMediaStack(const BluetoothRemoteDevice &device, int action); static void HandleConnectingDevice(const BluetoothRemoteDevice &device); static void HandleConnectDevice(const BluetoothRemoteDevice &device); static void HandleDisconnectDevice(const BluetoothRemoteDevice &device); static void HandleWearDevice(const BluetoothRemoteDevice &device); static void HandleUnwearDevice(const BluetoothRemoteDevice &device); static void HandleEnableDevice(const BluetoothRemoteDevice &device); static void HandleDisableDevice(const BluetoothRemoteDevice &device); static void HandleWearEnable(const BluetoothRemoteDevice &device); static void HandleWearDisable(const BluetoothRemoteDevice &device); static void HandleUserSelection(const BluetoothRemoteDevice &device); static void HandleVirtualConnectDevice(const BluetoothRemoteDevice &device); static void HandleRemoveVirtualConnectDevice(const BluetoothRemoteDevice &device); static void AddDeviceInConfigVector(const BluetoothRemoteDevice &device, std::vector &deviceVector); static void RemoveDeviceInConfigVector(const BluetoothRemoteDevice &device, std::vector &deviceVector); static void NotifyToUpdateAudioDevice(const BluetoothRemoteDevice &device, AudioStandard::AudioDeviceDescriptor &desc, DeviceStatus deviceStatus); static void NotifyToUpdateVirtualDevice(const BluetoothRemoteDevice &device, AudioStandard::AudioDeviceDescriptor &desc, DeviceStatus deviceStatus); static bool IsA2dpBluetoothDeviceExist(const std::string& macAddress); static bool IsA2dpBluetoothDeviceConnecting(const std::string& macAddress); static int32_t GetConnectedA2dpBluetoothDevice(const std::string& macAddress, BluetoothRemoteDevice &device); static void UpdateA2dpDeviceConfiguration(const BluetoothRemoteDevice &device, const AudioStandard::AudioStreamInfo &streamInfo); static std::vector GetAllA2dpBluetoothDevice(); static void ClearAllA2dpBluetoothDevice(); static std::vector GetA2dpVirtualDeviceList(); private: static std::map a2dpBluetoothDeviceMap_; static std::map wearDetectionStateMap_; static std::vector privacyDevices_; static std::vector commonDevices_; static std::vector negativeDevices_; static std::vector connectingDevices_; static std::vector virtualDevices_; }; struct BluetoothStopVirtualCallHandle { BluetoothRemoteDevice device; bool isWaitingForStoppingVirtualCall; }; class HfpBluetoothDeviceManager { public: HfpBluetoothDeviceManager() = default; virtual ~HfpBluetoothDeviceManager() = default; static void SetHfpStack(const BluetoothRemoteDevice &device, int action); static void HandleConnectingDevice(const BluetoothRemoteDevice &device); static void HandleConnectDevice(const BluetoothRemoteDevice &device); static void HandleDisconnectDevice(const BluetoothRemoteDevice &device); static void HandleWearDevice(const BluetoothRemoteDevice &device); static void HandleUnwearDevice(const BluetoothRemoteDevice &device); static void HandleEnableDevice(const BluetoothRemoteDevice &device); static void HandleDisableDevice(const BluetoothRemoteDevice &device); static void HandleWearEnable(const BluetoothRemoteDevice &device); static void HandleWearDisable(const BluetoothRemoteDevice &device); static void HandleUserSelection(const BluetoothRemoteDevice &device); static void HandleStopVirtualCall(const BluetoothRemoteDevice &device); static void HandleVirtualConnectDevice(const BluetoothRemoteDevice &device); static void HandleRemoveVirtualConnectDevice(const BluetoothRemoteDevice &device); static void AddDeviceInConfigVector(const BluetoothRemoteDevice &device, std::vector &deviceVector); static void RemoveDeviceInConfigVector(const BluetoothRemoteDevice &device, std::vector &deviceVector); static void NotifyToUpdateAudioDevice(const BluetoothRemoteDevice &device, AudioStandard::AudioDeviceDescriptor &desc, DeviceStatus deviceStatus); static void NotifyToUpdateVirtualDevice(const BluetoothRemoteDevice &device, AudioStandard::AudioDeviceDescriptor &desc, DeviceStatus deviceStatus); static bool IsHfpBluetoothDeviceExist(const std::string& macAddress); static bool IsHfpBluetoothDeviceConnecting(const std::string& macAddress); static void UpdateHfpDeviceConfiguration(const BluetoothRemoteDevice &device, const AudioStandard::AudioStreamInfo &streamInfo); static void OnScoStateChanged(const BluetoothRemoteDevice &device, bool isConnected, int reason); static int32_t GetConnectedHfpBluetoothDevice(const std::string& macAddress, BluetoothRemoteDevice &device); static std::vector GetAllHfpBluetoothDevice(); static void ClearAllHfpBluetoothDevice(); static std::vector GetHfpVirtualDeviceList(); private: static std::map hfpBluetoothDeviceMap_; static std::map wearDetectionStateMap_; static std::vector privacyDevices_; static std::vector commonDevices_; static std::vector negativeDevices_; static std::vector connectingDevices_; static std::vector virtualDevices_; static std::mutex stopVirtualCallHandleLock_; static BluetoothStopVirtualCallHandle stopVirtualCallHandle_; }; } // namespace Bluetooth } // namespace OHOS #endif // BLUETOOTH_DEVICE_MANAGER_H