From f4964459d7699b2b65ab3704e6c857448c70a6a6 Mon Sep 17 00:00:00 2001 From: yupanwen Date: Thu, 28 Aug 2025 10:26:23 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E6=A8=A1=E6=8B=9F=E8=80=B3?= =?UTF-8?q?=E6=9C=BA=E8=BF=9E=E6=8E=A5=E6=B2=A1=E6=9C=89=E5=BC=B9=E7=AA=97?= =?UTF-8?q?=E6=8F=90=E7=A4=BA?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: 136******92 Change-Id: I4069ec24c95846c63711e4e6650032e59fc8ce34 --- .../pipe/src/audio_policy_config_manager.cpp | 4 +-- .../service_main/src/audio_core_service.cpp | 27 ++++++++++++++----- .../audio_policy_service_third_unit_test.cpp | 22 +++++++++++++++ 3 files changed, 45 insertions(+), 8 deletions(-) diff --git a/services/audio_policy/server/domain/pipe/src/audio_policy_config_manager.cpp b/services/audio_policy/server/domain/pipe/src/audio_policy_config_manager.cpp index 3360ad0863..d152112abf 100644 --- a/services/audio_policy/server/domain/pipe/src/audio_policy_config_manager.cpp +++ b/services/audio_policy/server/domain/pipe/src/audio_policy_config_manager.cpp @@ -20,7 +20,7 @@ #include "audio_policy_config_parser.h" #include "audio_source_strategy_parser.h" #include "audio_policy_utils.h" -#include "audio_policy_service.h" +#include "audio_core_service.h" #include "audio_ec_manager.h" namespace OHOS { @@ -166,7 +166,7 @@ void AudioPolicyConfigManager::OnVoipConfigParsed(bool enableFastVoip) void AudioPolicyConfigManager::OnUpdateAnahsSupport(std::string anahsShowType) { AUDIO_INFO_LOG("show type: %{public}s", anahsShowType.c_str()); - AudioPolicyService::GetAudioPolicyService().OnUpdateAnahsSupport(anahsShowType); + AudioCoreService::GetCoreService()->OnUpdateAnahsSupport(anahsShowType); } void AudioPolicyConfigManager::OnUpdateEac3Support(bool isSupported) diff --git a/services/audio_policy/server/service/service_main/src/audio_core_service.cpp b/services/audio_policy/server/service/service_main/src/audio_core_service.cpp index 50022d7cdb..6a2e32f482 100644 --- a/services/audio_policy/server/service/service_main/src/audio_core_service.cpp +++ b/services/audio_policy/server/service/service_main/src/audio_core_service.cpp @@ -36,6 +36,8 @@ static const char* CHECK_FAST_BLOCK_PREFIX = "Is_Fast_Blocked_For_AppName#"; static const int32_t BLUETOOTH_FETCH_RESULT_DEFAULT = 0; static const int32_t BLUETOOTH_FETCH_RESULT_CONTINUE = 1; static const int32_t BLUETOOTH_FETCH_RESULT_ERROR = 2; +static constexpr int32_t MAX_TRY = 100; +static constexpr int32_t DELAY_MS = 100; } static bool IsRemoteOffloadActive(uint32_t remoteOffloadStreamPropSize, int32_t streamUsage) @@ -101,6 +103,7 @@ void AudioCoreService::Init() { serviceFlag_.reset(); eventEntry_ = std::make_shared(shared_from_this()); + deviceStatusListener_ = std::make_shared(*eventEntry_); // shared_ptr.get() -> * audioA2dpOffloadManager_ = std::make_shared(); if (audioA2dpOffloadManager_ != nullptr) { @@ -113,7 +116,6 @@ void AudioCoreService::Init() audioDeviceStatus_.Init(audioA2dpOffloadManager_, audioPolicyServerHandler_); audioCapturerSession_.Init(audioA2dpOffloadManager_); - deviceStatusListener_ = std::make_shared(*eventEntry_); // shared_ptr.get() -> * isFastControlled_ = GetFastControlParam(); // Register device status listener int32_t status = deviceStatusListener_->RegisterDeviceStatusListener(); @@ -211,7 +213,7 @@ int32_t AudioCoreService::CreateCapturerClient( std::shared_ptr streamDesc, uint32_t &audioFlag, uint32_t &sessionId) { CHECK_AND_RETURN_RET_LOG(streamDesc != nullptr, ERR_INVALID_PARAM, "streamDesc is nullptr"); - + AUDIO_INFO_LOG("[DeviceFetchStart] for stream %{public}d", sessionId); streamDesc->oldDeviceDescs_ = streamDesc->newDeviceDescs_; std::shared_ptr inputDeviceDesc = @@ -302,7 +304,7 @@ bool AudioCoreService::IsForcedNormal(std::shared_ptr &st void AudioCoreService::UpdatePlaybackStreamFlag(std::shared_ptr &streamDesc, bool isCreateProcess) { CHECK_AND_RETURN_LOG(streamDesc, "Input param error"); - + if (isCreateProcess && streamDesc->rendererInfo_.forceToNormal) { AUDIO_INFO_LOG("client force create normal"); streamDesc->audioFlag_ = AUDIO_OUTPUT_FLAG_NORMAL; @@ -557,7 +559,7 @@ int32_t AudioCoreService::SetAudioScene(AudioScene audioScene, const int32_t uid if (!isSameScene) { OnAudioSceneChange(audioScene); } - + if (audioScene == AUDIO_SCENE_PHONE_CALL) { // Make sure the STREAM_VOICE_CALL volume is set before the calling starts. audioVolumeManager_.SetVoiceCallVolume(audioVolumeManager_.GetSystemVolumeLevel(STREAM_VOICE_CALL)); @@ -1183,7 +1185,20 @@ int32_t AudioCoreService::UnsetAudioDeviceAnahsCallback() void AudioCoreService::OnUpdateAnahsSupport(std::string anahsShowType) { AUDIO_INFO_LOG("OnUpdateAnahsSupport show type: %{public}s", anahsShowType.c_str()); - deviceStatusListener_->UpdateAnahsPlatformType(anahsShowType); + thread th([this](string &&anahsShowType) { + for (int32_t i = 0; i < MAX_TRY; ++i) { + if (i > 0) { + this_thread::sleep_for(std::chrono::milliseconds(DELAY_MS)); + } + if (deviceStatusListener_) { + deviceStatusListener_->UpdateAnahsPlatformType(anahsShowType); + return; + } + } + AUDIO_ERR_LOG("Try UpdateAnahsPlatformType over %{public}d times, failed", MAX_TRY); + }, move(anahsShowType)); + pthread_setname_np(th.native_handle(), "OS_ANAHS_TYP"); + th.detach(); } void AudioCoreService::RegisterBluetoothListener() @@ -1428,7 +1443,7 @@ int32_t AudioCoreService::CaptureConcurrentCheck(uint32_t sessionId) if (streamDesc->audioMode_ != AUDIO_MODE_RECORD) { return ERR_NOT_SUPPORTED; } - + auto dfxResult = std::make_unique(); if (!WriteCapturerConcurrentMsg(streamDesc, dfxResult)) { return ERR_INVALID_HANDLE; diff --git a/services/audio_policy/test/unittest/audio_policy_service_unit_test/src/audio_policy_service_third_unit_test.cpp b/services/audio_policy/test/unittest/audio_policy_service_unit_test/src/audio_policy_service_third_unit_test.cpp index 843c8bd237..c9608d2737 100644 --- a/services/audio_policy/test/unittest/audio_policy_service_unit_test/src/audio_policy_service_third_unit_test.cpp +++ b/services/audio_policy/test/unittest/audio_policy_service_unit_test/src/audio_policy_service_third_unit_test.cpp @@ -1066,6 +1066,28 @@ HWTEST_F(AudioPolicyServiceThirdUnitTest, OnUpdateAnahsSupport_001, TestSize.Lev EXPECT_NE(server->audioPolicyService_.deviceStatusListener_, nullptr); } +/** + * @tc.name : Test OnUpdateAnahsSupport. + * @tc.number: OnUpdateAnahsSupport_002 + * @tc.desc : Test AudioPolicyService interfaces. + */ +HWTEST_F(AudioPolicyServiceThirdUnitTest, OnUpdateAnahsSupport_002, TestSize.Level1) +{ + auto server = GetServerPtr(); + ASSERT_NE(nullptr, server); + + std::string anahsShowType = "anahsShowType"; + + auto coreSvc = AudioCoreService::GetCoreService(); + auto bakUp = coreSvc->deviceStatusListener_; + CHECK_AND_RETURN(bakUp); + coreSvc->deviceStatusListener_ = nullptr; + coreSvc->OnUpdateAnahsSupport(anahsShowType); + coreSvc->deviceStatusListener_ = bakUp; + coreSvc->OnUpdateAnahsSupport(anahsShowType); + EXPECT_NE(coreSvc->deviceStatusListener_, nullptr); +} + /** * @tc.name : Test OnDeviceStatusUpdated. * @tc.number: OnDeviceStatusUpdated_001 -- Gitee