From 707350da362240c7c5b64f8a23c3c47c504059b2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9D=8E=E7=9D=BF?= Date: Fri, 5 Sep 2025 10:19:03 +0800 Subject: [PATCH] add capability report MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: 李睿 --- .../manager/hdi_adapter_manager.cpp | 4 ++-- .../native/audiocommon/include/audio_errors.h | 3 +++ .../domain/device/src/audio_device_status.cpp | 13 +++++++++++-- .../src/audio_device_status_unit_test.cpp | 19 +++++++++++++++++++ 4 files changed, 35 insertions(+), 4 deletions(-) diff --git a/frameworks/native/hdiadapter_new/manager/hdi_adapter_manager.cpp b/frameworks/native/hdiadapter_new/manager/hdi_adapter_manager.cpp index 3f84d2d837..ebddf1fa2a 100644 --- a/frameworks/native/hdiadapter_new/manager/hdi_adapter_manager.cpp +++ b/frameworks/native/hdiadapter_new/manager/hdi_adapter_manager.cpp @@ -138,7 +138,7 @@ std::shared_ptr HdiAdapterManager::GetRenderSink(uint32_t rend return renderSinks_[renderId].sink_; } if (!tryCreate) { - AUDIO_ERR_LOG("no available sink, renderId: %{public}u", renderId); + AUDIO_WARNING_LOG("no available sink, renderId: %{public}u", renderId); return nullptr; } AUDIO_INFO_LOG("create sink, renderId: %{public}u", renderId); @@ -163,7 +163,7 @@ std::shared_ptr HdiAdapterManager::GetCaptureSource(uint32_ return captureSources_[captureId].source_; } if (!tryCreate) { - AUDIO_ERR_LOG("no available source, captureId: %{public}u", captureId); + AUDIO_WARNING_LOG("no available source, captureId: %{public}u", captureId); return nullptr; } AUDIO_INFO_LOG("create source, captureId: %{public}u", captureId); diff --git a/interfaces/inner_api/native/audiocommon/include/audio_errors.h b/interfaces/inner_api/native/audiocommon/include/audio_errors.h index b41f8250d0..6b9fd92c66 100644 --- a/interfaces/inner_api/native/audiocommon/include/audio_errors.h +++ b/interfaces/inner_api/native/audiocommon/include/audio_errors.h @@ -182,6 +182,9 @@ const int32_t ERR_SET_VOL_FAILED_BY_VOLUME_CONTROL_DISABLED = BASE_AUDIO_ERR_OFF /** Unknown error */ const int32_t ERR_UNKNOWN = BASE_AUDIO_ERR_OFFSET - 200; + +/** success but not continue */ +const int32_t SUCCESS_BUT_NOT_CONTINUE = BASE_AUDIO_ERR_OFFSET - 300; } // namespace AudioStandard } // namespace OHOS #endif // AUDIO_ERRORS_H diff --git a/services/audio_policy/server/domain/device/src/audio_device_status.cpp b/services/audio_policy/server/domain/device/src/audio_device_status.cpp index 1f309eb675..4f6d713e1e 100644 --- a/services/audio_policy/server/domain/device/src/audio_device_status.cpp +++ b/services/audio_policy/server/domain/device/src/audio_device_status.cpp @@ -948,8 +948,17 @@ int32_t AudioDeviceStatus::HandleDistributedDeviceUpdate(DStatusInfo &statusInfo audioVolumeManager_.UpdateGroupInfo(INTERRUPT_TYPE, GROUP_NAME_DEFAULT, deviceDesc.interruptGroupId_, networkId, statusInfo.isConnected, statusInfo.mappingInterruptId); if (statusInfo.isConnected) { - if (audioConnectedDevice_.GetConnectedDeviceByType(networkId, devType) != nullptr) { - return ERROR; + std::shared_ptr connDevDesc = audioConnectedDevice_.GetConnectedDeviceByType(networkId, + devType); + if (connDevDesc != nullptr) { + CHECK_AND_RETURN_RET(!statusInfo.streamInfo.empty(), ERROR); + + // Remote device may connect twice, and device capability will be carried in either time. So we need to + // update device capability even if device is already connected, and return not success to avoid doing + // other connection logic. + connDevDesc->SetDeviceCapability(statusInfo.streamInfo, 0); + AUDIO_INFO_LOG("Update capability"); + return SUCCESS_BUT_NOT_CONTINUE; } int32_t ret = ActivateNewDevice(statusInfo.networkId, devType, statusInfo.connectType == ConnectType::CONNECT_TYPE_DISTRIBUTED); diff --git a/services/audio_policy/test/unittest/audio_device_status_unit_test/src/audio_device_status_unit_test.cpp b/services/audio_policy/test/unittest/audio_device_status_unit_test/src/audio_device_status_unit_test.cpp index 40b6de9a1e..539735fc68 100644 --- a/services/audio_policy/test/unittest/audio_device_status_unit_test/src/audio_device_status_unit_test.cpp +++ b/services/audio_policy/test/unittest/audio_device_status_unit_test/src/audio_device_status_unit_test.cpp @@ -301,6 +301,25 @@ HWTEST_F(AudioDeviceStatusUnitTest, AudioDeviceStatus_008, TestSize.Level1) reason = AudioStreamDeviceChangeReasonExt::ExtEnum::UNKNOWN; ret = audioDeviceStatus.HandleDistributedDeviceUpdate(statusInfo, descForCb, reason); EXPECT_EQ(ret, SUCCESS); + + DeviceStreamInfo deviceStreamInfo = {}; + std::list streamInfoList = { deviceStreamInfo }; + statusInfo.streamInfo = streamInfoList; + std::string testNetworkId = "testNetworkId_0"; + auto res = strncpy_s(statusInfo.networkId, NETWORK_ID_SIZE, testNetworkId.c_str(), testNetworkId.size()); + EXPECT_EQ(res, 0); + DeviceType devType = audioDeviceStatus.GetDeviceTypeFromPin(statusInfo.hdiPin); + std::shared_ptr audioDescriptor = + std::make_shared(devType, OUTPUT_DEVICE); + audioDescriptor->networkId_ = statusInfo.networkId; + audioDeviceStatus.audioConnectedDevice_.AddConnectedDevice(audioDescriptor); + + statusInfo.isConnected = true; + reason = AudioStreamDeviceChangeReasonExt::ExtEnum::UNKNOWN; + ret = audioDeviceStatus.HandleDistributedDeviceUpdate(statusInfo, descForCb, reason); + audioDeviceStatus.audioConnectedDevice_.DelConnectedDevice(audioDescriptor->networkId_, + audioDescriptor->deviceType_); + EXPECT_EQ(ret, SUCCESS_BUT_NOT_CONTINUE); } /** -- Gitee