From 1e8758baa730d24f5ea6887f5a0f8e76233d408a Mon Sep 17 00:00:00 2001 From: zhuchaochao Date: Thu, 7 Dec 2023 07:01:47 +0000 Subject: [PATCH] enable_disable bug fix Signed-off-by: zhuchaochao Change-Id: I0ed3ab24ad52782146667d4e96c3acdd6c76c8fe --- .../bluetooth_device_manager.cpp | 36 ++++++++++++++----- 1 file changed, 28 insertions(+), 8 deletions(-) diff --git a/frameworks/native/bluetoothclient/bluetooth_device_manager.cpp b/frameworks/native/bluetoothclient/bluetooth_device_manager.cpp index 92509172d9..406054604e 100644 --- a/frameworks/native/bluetoothclient/bluetooth_device_manager.cpp +++ b/frameworks/native/bluetoothclient/bluetooth_device_manager.cpp @@ -250,10 +250,15 @@ void MediaBluetoothDeviceManager::HandleEnableDevice(const BluetoothRemoteDevice bluetoothCategory = pos->second; } if (bluetoothCategory == BT_HEADPHONE) { + bool isWearSupported = false; + int32_t wearEnabledAbility = 0; + BluetoothAudioManager::GetInstance().IsWearDetectionSupported(device.GetDeviceAddr(), isWearSupported); + BluetoothAudioManager::GetInstance().IsWearDetectionEnabled(device.GetDeviceAddr(), wearEnabledAbility); std::lock_guard wearStateMapLock(g_a2dpWearStateMapLock); auto wearStateIter = wearDetectionStateMap_.find(device.GetDeviceAddr()); - if (wearStateIter != wearDetectionStateMap_.end() && - wearStateIter->second == BluetoothDeviceAction::WEAR_ACTION) { + if (!isWearSupported || wearEnabledAbility != WEAR_ENABLED || + (wearStateIter != wearDetectionStateMap_.end() && + wearStateIter->second == BluetoothDeviceAction::WEAR_ACTION)) { desc.deviceCategory_ = BT_HEADPHONE; } else { desc.deviceCategory_ = BT_UNWEAR_HEADPHONE; @@ -282,10 +287,15 @@ void MediaBluetoothDeviceManager::HandleDisableDevice(const BluetoothRemoteDevic bluetoothCategory = pos->second; } if (bluetoothCategory == BT_HEADPHONE) { + bool isWearSupported = false; + int32_t wearEnabledAbility = 0; + BluetoothAudioManager::GetInstance().IsWearDetectionSupported(device.GetDeviceAddr(), isWearSupported); + BluetoothAudioManager::GetInstance().IsWearDetectionEnabled(device.GetDeviceAddr(), wearEnabledAbility); std::lock_guard wearStateMapLock(g_a2dpWearStateMapLock); auto wearStateIter = wearDetectionStateMap_.find(device.GetDeviceAddr()); - if (wearStateIter != wearDetectionStateMap_.end() && - wearStateIter->second == BluetoothDeviceAction::WEAR_ACTION) { + if (!isWearSupported || wearEnabledAbility != WEAR_ENABLED || + (wearStateIter != wearDetectionStateMap_.end() && + wearStateIter->second == BluetoothDeviceAction::WEAR_ACTION)) { desc.deviceCategory_ = BT_HEADPHONE; } else { desc.deviceCategory_ = BT_UNWEAR_HEADPHONE; @@ -602,10 +612,15 @@ void HfpBluetoothDeviceManager::HandleEnableDevice(const BluetoothRemoteDevice & bluetoothCategory = pos->second; } if (bluetoothCategory == BT_HEADPHONE) { + bool isWearSupported = false; + int32_t wearEnabledAbility = 0; + BluetoothAudioManager::GetInstance().IsWearDetectionSupported(device.GetDeviceAddr(), isWearSupported); + BluetoothAudioManager::GetInstance().IsWearDetectionEnabled(device.GetDeviceAddr(), wearEnabledAbility); std::lock_guard wearStateMapLock(g_hfpWearStateMapLock); auto wearStateIter = wearDetectionStateMap_.find(device.GetDeviceAddr()); - if (wearStateIter != wearDetectionStateMap_.end() && - wearStateIter->second == BluetoothDeviceAction::WEAR_ACTION) { + if (!isWearSupported || wearEnabledAbility != WEAR_ENABLED || + (wearStateIter != wearDetectionStateMap_.end() && + wearStateIter->second == BluetoothDeviceAction::WEAR_ACTION)) { desc.deviceCategory_ = BT_HEADPHONE; } else { desc.deviceCategory_ = BT_UNWEAR_HEADPHONE; @@ -634,10 +649,15 @@ void HfpBluetoothDeviceManager::HandleDisableDevice(const BluetoothRemoteDevice bluetoothCategory = pos->second; } if (bluetoothCategory == BT_HEADPHONE) { + bool isWearSupported = false; + int32_t wearEnabledAbility = 0; + BluetoothAudioManager::GetInstance().IsWearDetectionSupported(device.GetDeviceAddr(), isWearSupported); + BluetoothAudioManager::GetInstance().IsWearDetectionEnabled(device.GetDeviceAddr(), wearEnabledAbility); std::lock_guard wearStateMapLock(g_hfpWearStateMapLock); auto wearStateIter = wearDetectionStateMap_.find(device.GetDeviceAddr()); - if (wearStateIter != wearDetectionStateMap_.end() && - wearStateIter->second == BluetoothDeviceAction::WEAR_ACTION) { + if (!isWearSupported || wearEnabledAbility != WEAR_ENABLED || + (wearStateIter != wearDetectionStateMap_.end() && + wearStateIter->second == BluetoothDeviceAction::WEAR_ACTION)) { desc.deviceCategory_ = BT_HEADPHONE; } else { desc.deviceCategory_ = BT_UNWEAR_HEADPHONE; -- Gitee