From 6fbf1e32e7729aa2dcc4e9fd84707fbbc683f70b Mon Sep 17 00:00:00 2001 From: huyue57 Date: Tue, 6 Feb 2024 14:55:19 +0800 Subject: [PATCH] =?UTF-8?q?=E8=93=9D=E7=89=99=E8=AE=BE=E5=A4=87=E4=B8=8A?= =?UTF-8?q?=E7=BA=BF=E5=8F=AF=E7=94=A8=E5=8D=B3=E6=BF=80=E6=B4=BB=EF=BC=8C?= =?UTF-8?q?=E6=97=A0=E9=A1=BB=E7=AD=89=E5=88=B0=E8=B5=B7=E6=B5=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: huyue57 Change-Id: I3814133030ce783bbdd5a9b21110f0adc2de341d --- .../bluetoothclient/audio_bluetooth_manager.cpp | 8 ++++++-- .../server/src/service/audio_policy_service.cpp | 15 ++++++++++++--- 2 files changed, 18 insertions(+), 5 deletions(-) diff --git a/frameworks/native/bluetoothclient/audio_bluetooth_manager.cpp b/frameworks/native/bluetoothclient/audio_bluetooth_manager.cpp index a2bb064dd0..10b240ef13 100644 --- a/frameworks/native/bluetoothclient/audio_bluetooth_manager.cpp +++ b/frameworks/native/bluetoothclient/audio_bluetooth_manager.cpp @@ -116,8 +116,12 @@ int32_t AudioA2dpManager::SetActiveA2dpDevice(const std::string& macAddress) a2dpInstance_ = A2dpSource::GetProfile(); CHECK_AND_RETURN_RET_LOG(a2dpInstance_ != nullptr, ERROR, "Failed to obtain A2DP profile instance"); BluetoothRemoteDevice device; - int32_t tmp = MediaBluetoothDeviceManager::GetConnectedA2dpBluetoothDevice(macAddress, device); - CHECK_AND_RETURN_RET_LOG(tmp == SUCCESS, ERROR, "SetActiveA2dpDevice: the configuring A2DP device doesn't exist."); + if (macAddress != "") { + int32_t tmp = MediaBluetoothDeviceManager::GetConnectedA2dpBluetoothDevice(macAddress, device); + CHECK_AND_RETURN_RET_LOG(tmp == SUCCESS, ERROR, "the configuring A2DP device doesn't exist."); + } else { + AUDIO_INFO_LOG("Deactive A2DP device"); + } int32_t ret = a2dpInstance_->SetActiveSinkDevice(device); CHECK_AND_RETURN_RET_LOG(ret == 0, ERROR, "SetActiveA2dpDevice failed. result: %{public}d", ret); activeA2dpDevice_ = device; diff --git a/services/audio_policy/server/src/service/audio_policy_service.cpp b/services/audio_policy/server/src/service/audio_policy_service.cpp index ec806ee992..f61731d0c0 100644 --- a/services/audio_policy/server/src/service/audio_policy_service.cpp +++ b/services/audio_policy/server/src/service/audio_policy_service.cpp @@ -1607,10 +1607,10 @@ void AudioPolicyService::FetchOutputDeviceWhenNoRunningStream() return; } SetVolumeForSwitchDevice(desc->deviceType_); - currentActiveDevice_ = AudioDeviceDescriptor(*desc); - if (desc->deviceType_ == DEVICE_TYPE_BLUETOOTH_A2DP || desc->deviceType_ == DEVICE_TYPE_BLUETOOTH_SCO) { - activeBTDevice_ = desc->macAddress_; + if (desc->deviceType_ == DEVICE_TYPE_BLUETOOTH_A2DP) { + SwitchActiveA2dpDevice(new AudioDeviceDescriptor(*desc)); } + currentActiveDevice_ = AudioDeviceDescriptor(*desc); AUDIO_DEBUG_LOG("currentActiveDevice update %{public}d", currentActiveDevice_.deviceType_); OnPreferredOutputDeviceUpdated(currentActiveDevice_); } @@ -2795,6 +2795,9 @@ void AudioPolicyService::UpdateActiveA2dpDeviceWhenDisconnecting(const std::stri IOHandles_.erase(BLUETOOTH_SPEAKER); } audioPolicyManager_.SetAbsVolumeScene(false); +#ifdef BLUETOOTH_ENABLE + Bluetooth::AudioA2dpManager::SetActiveA2dpDevice(""); +#endif return; } } @@ -5400,6 +5403,12 @@ void AudioPolicyService::OnPreferredStateUpdated(AudioDeviceDescriptor &desc, userSelectRecordCaptureDevice->macAddress_ == desc.macAddress_) { audioStateManager_.SetPerferredRecordCaptureDevice(new(std::nothrow) AudioDeviceDescriptor()); } +#ifdef BLUETOOTH_ENABLE + if (desc.deviceType_ == DEVICE_TYPE_BLUETOOTH_A2DP && + desc.macAddress_ == currentActiveDevice_.macAddress_) { + Bluetooth::AudioA2dpManager::SetActiveA2dpDevice(""); + } +#endif } else { reason = AudioStreamDeviceChangeReason::NEW_DEVICE_AVAILABLE; if (desc.deviceType_ == DEVICE_TYPE_BLUETOOTH_A2DP) { -- Gitee