From e98c6533ac7ee58e455a4d74f315e34f770ef19c Mon Sep 17 00:00:00 2001 From: li-tiangang4 Date: Sat, 17 May 2025 15:57:12 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E6=94=B9dcamera=E3=80=81daudio?= =?UTF-8?q?=E9=83=A8=E4=BB=B6sink=E6=9C=8D=E5=8A=A1=E6=8C=89=E9=9C=80?= =?UTF-8?q?=E5=90=AF=E5=8A=A8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: li-tiangang4 --- .../componentmanager/component_manager.h | 1 + .../componentmanager/component_manager.cpp | 52 +++++++++++++------ .../src/task/enable_task.cpp | 13 ++++- .../src/task/online_task.cpp | 2 +- .../src/component_manager_test.cpp | 7 +++ .../task/include/mock_component_manager.h | 2 + .../common/task/src/enable_task_test.cpp | 5 +- .../task/src/mock_component_manager.cpp | 5 ++ 8 files changed, 65 insertions(+), 22 deletions(-) diff --git a/services/distributedhardwarefwkservice/include/componentmanager/component_manager.h b/services/distributedhardwarefwkservice/include/componentmanager/component_manager.h index d49d33a3..66b03fe1 100644 --- a/services/distributedhardwarefwkservice/include/componentmanager/component_manager.h +++ b/services/distributedhardwarefwkservice/include/componentmanager/component_manager.h @@ -80,6 +80,7 @@ public: */ bool FetchNeedRefreshTask(const std::pair &taskKey, TaskParam &taskParam); + int32_t CheckSinkConfigStart(const DHType dhType, bool &enableSink); int32_t CheckDemandStart(const std::string &uuid, const DHType dhType, bool &enableSource); int32_t RegisterDHStatusListener(sptr listener, int32_t callingUid, int32_t callingPid); int32_t UnregisterDHStatusListener(sptr listener, int32_t callingUid, int32_t callingPid); diff --git a/services/distributedhardwarefwkservice/src/componentmanager/component_manager.cpp b/services/distributedhardwarefwkservice/src/componentmanager/component_manager.cpp index 35b43d0a..091040e0 100644 --- a/services/distributedhardwarefwkservice/src/componentmanager/component_manager.cpp +++ b/services/distributedhardwarefwkservice/src/componentmanager/component_manager.cpp @@ -782,45 +782,65 @@ std::shared_ptr ComponentManager return this->eventHandler_; } +int32_t ComponentManager::CheckSinkConfigStart(const DHType dhType, bool &enableSink) +{ + DHLOGI("CheckSinkConfigStart the dhType: %{public}#X configuration start.", dhType); + DHVersion localDhVersion; + auto ret = ComponentLoader::GetInstance().GetLocalDHVersion(localDhVersion); + if (ret != DH_FWK_SUCCESS) { + DHLOGE("GetLocalDHVersion fail."); + return ret; + } + auto iterLocal = localDhVersion.compVersions.find(dhType); + if (iterLocal == localDhVersion.compVersions.end()) { + DHLOGE("Not find dhType: %{public}#X in local!", dhType); + return ERR_DH_FWK_TYPE_NOT_EXIST; + } + if (!iterLocal->second.haveFeature) { + enableSink = true; + DHLOGI("Local DhType: %{public}#X is old configuration, need enable sink.", dhType); + return DH_FWK_SUCCESS; + } + + if (iterLocal->second.sinkSupportedFeatures.size() > 0) { + enableSink = true; + } + return DH_FWK_SUCCESS; +} + int32_t ComponentManager::CheckDemandStart(const std::string &uuid, const DHType dhType, bool &enableSource) { - // Initialize output parameters + DHLOGI("CheckDemandStart the dhType: %{public}#X configuration start.", dhType); enableSource = false; - - // Get remote config CompVersion compVersion; auto ret = GetRemoteVerInfo(compVersion, uuid, dhType); if (ret != DH_FWK_SUCCESS) { - DHLOGE("GetRemoteVerInfo fail, errCode = %{public}d!", ret); + DHLOGE("GetRemoteVerInfo fail."); return ret; } - // Get local config DHVersion dhVersion; ret = ComponentLoader::GetInstance().GetLocalDHVersion(dhVersion); if (ret != DH_FWK_SUCCESS) { - DHLOGE("GetLocalDHVersion fail, errCode = %{public}d!", ret); + DHLOGE("GetLocalDHVersion fail."); return ret; } auto iterLocal = dhVersion.compVersions.find(dhType); if (iterLocal == dhVersion.compVersions.end()) { - DHLOGE("Not find dhType in local: %{public}#X!", dhType); + DHLOGE("Not find dhType: %{public}#X in local!", dhType); return ERR_DH_FWK_TYPE_NOT_EXIST; } - // Check local config if (!iterLocal->second.haveFeature) { enableSource = true; + DHLOGI("Local dhType: %{public}#X is old configuration, need enable source", dhType); return DH_FWK_SUCCESS; } - if (iterLocal->second.sourceFeatureFilters.size() == 0) { return DH_FWK_SUCCESS; } - // Check if the configurations on both ends match enableSource = IsFeatureMatched(iterLocal->second.sourceFeatureFilters, compVersion.sinkSupportedFeatures); - return DH_FWK_SUCCESS; } @@ -1026,12 +1046,7 @@ int32_t ComponentManager::CheckIdenticalAccount(const std::string &networkId, int32_t ComponentManager::GetRemoteVerInfo(CompVersion &compVersion, const std::string &uuid, DHType dhType) { MetaCapInfoMap metaInfoMap; - auto ret = MetaInfoManager::GetInstance()->GetMetaDataByDHType(dhType, metaInfoMap); - if (ret != DH_FWK_SUCCESS) { - DHLOGE("GetMetaDataByDHType failed, uuid =%{public}s, dhType = %{public}#X, errCode = %{public}d.", - GetAnonyString(uuid).c_str(), dhType, ret); - return ret; - } + MetaInfoManager::GetInstance()->GetMetaDataByDHType(dhType, metaInfoMap); for (const auto &metaInfo : metaInfoMap) { if (DHContext::GetInstance().GetUUIDByDeviceId(metaInfo.second->GetDeviceId()) == uuid) { compVersion = metaInfo.second->GetCompVersion(); @@ -1053,6 +1068,7 @@ bool ComponentManager::IsFeatureMatched(const std::vector &sourceFe } } } + DHLOGE("The sourcefeature and the sinkfeature do not match."); return false; } @@ -1775,6 +1791,7 @@ int32_t ComponentManager::UninitCompSink(DHType dhType) ActionResult ComponentManager::StopSource(DHType dhType) { + DHLOGI("StopSource, dhType: %{public}#X", dhType); std::shared_lock lock(compSourceMutex_); std::unordered_map> futures; if (compSource_.find(dhType) == compSource_.end()) { @@ -1797,6 +1814,7 @@ ActionResult ComponentManager::StopSource(DHType dhType) ActionResult ComponentManager::StopSink(DHType dhType) { + DHLOGI("StopSink, dhType: %{public}#X", dhType); std::shared_lock lock(compSinkMutex_); std::unordered_map> futures; if (compSink_.find(dhType) == compSink_.end()) { diff --git a/services/distributedhardwarefwkservice/src/task/enable_task.cpp b/services/distributedhardwarefwkservice/src/task/enable_task.cpp index 06d705a3..e2df9dbe 100644 --- a/services/distributedhardwarefwkservice/src/task/enable_task.cpp +++ b/services/distributedhardwarefwkservice/src/task/enable_task.cpp @@ -145,12 +145,21 @@ int32_t EnableTask::DoAutoEnable() { std::string localUdid = GetLocalUdid(); if (localUdid == GetUDID()) { + bool enableSink = false; + auto ret = ComponentManager::GetInstance().CheckSinkConfigStart(GetDhType(), enableSink); + if (ret != DH_FWK_SUCCESS) { + DHLOGE("CheckSinkConfigStart failed!"); + return ret; + } + if (!enableSink) { + DHLOGE("No need Enablesink."); + return ERR_DH_FWK_COMPONENT_LIMIT_DEMAND_START; + } DHDescriptor dhDescriptor { .id = GetDhId(), .dhType = GetDhType() }; - DHLOGI("EnableSink DhType = %{public}#X", GetDhType()); - auto ret = ComponentManager::GetInstance().EnableSink(dhDescriptor, GetCallingUid(), GetCallingPid()); + ret = ComponentManager::GetInstance().EnableSink(dhDescriptor, GetCallingUid(), GetCallingPid()); if (ret != DH_FWK_SUCCESS) { DHLOGE("EnableSink DhType = %{public}#X, failed!", GetDhType()); } diff --git a/services/distributedhardwarefwkservice/src/task/online_task.cpp b/services/distributedhardwarefwkservice/src/task/online_task.cpp index f3f2e05d..3bf08b54 100644 --- a/services/distributedhardwarefwkservice/src/task/online_task.cpp +++ b/services/distributedhardwarefwkservice/src/task/online_task.cpp @@ -159,8 +159,8 @@ void OnLineTask::CreateEnableTask() void OnLineTask::CreateEnableSinkTask() { - DHLOGI("CreateEnableSinkTask start"); DeviceInfo localDeviceInfo = GetLocalDeviceInfo(); + DHLOGI("CreateEnableSinkTask, uuid: %{public}s", GetAnonyString(localDeviceInfo.uuid).c_str()); std::vector> localMetaInfos; std::vector> metaCapInfos; MetaInfoManager::GetInstance()->GetMetaCapInfosByUdidHash(localDeviceInfo.udidHash, metaCapInfos); diff --git a/services/distributedhardwarefwkservice/test/unittest/common/componentmanager/component_manager/src/component_manager_test.cpp b/services/distributedhardwarefwkservice/test/unittest/common/componentmanager/component_manager/src/component_manager_test.cpp index ff606ed9..070516ad 100644 --- a/services/distributedhardwarefwkservice/test/unittest/common/componentmanager/component_manager/src/component_manager_test.cpp +++ b/services/distributedhardwarefwkservice/test/unittest/common/componentmanager/component_manager/src/component_manager_test.cpp @@ -1233,5 +1233,12 @@ HWTEST_F(ComponentManagerTest, OnStateChanged_001, testing::ext::TestSize.Level1 networkId = "networkId_test"; ASSERT_NO_FATAL_FAILURE(dhStateListenenr.OnStateChanged(networkId, dhId, state)); } + +HWTEST_F(ComponentManagerTest, CheckSinkConfigStart_001, TestSize.Level1) +{ + bool enableSink = false; + auto ret = ComponentManager::GetInstance().CheckSinkConfigStart(DHType::GPS, enableSink); + EXPECT_EQ(ret, ERR_DH_FWK_TYPE_NOT_EXIST); +} } // namespace DistributedHardware } // namespace OHOS diff --git a/services/distributedhardwarefwkservice/test/unittest/common/task/include/mock_component_manager.h b/services/distributedhardwarefwkservice/test/unittest/common/task/include/mock_component_manager.h index dc95fa36..b4427578 100644 --- a/services/distributedhardwarefwkservice/test/unittest/common/task/include/mock_component_manager.h +++ b/services/distributedhardwarefwkservice/test/unittest/common/task/include/mock_component_manager.h @@ -34,6 +34,7 @@ public: virtual int32_t DisableSink(const DHDescriptor &dhDescriptor, int32_t callingUid, int32_t callingPid) = 0; virtual int32_t DisableSource(const std::string &networkId, const DHDescriptor &dhDescriptor, int32_t callingUid, int32_t callingPid) = 0; + virtual int32_t CheckSinkConfigStart(const DHType dhType, bool &enableSink) = 0; static std::shared_ptr GetOrCtreateInstance(); static void ReleaseInstance(); @@ -51,6 +52,7 @@ public: MOCK_METHOD(int32_t, EnableSource, (const std::string&, const DHDescriptor&, int32_t, int32_t)); MOCK_METHOD(int32_t, DisableSink, (const DHDescriptor&, int32_t, int32_t)); MOCK_METHOD(int32_t, DisableSource, (const std::string&, const DHDescriptor&, int32_t, int32_t)); + MOCK_METHOD(int32_t, CheckSinkConfigStart, (const DHType, bool&)); }; } // namespace DistributedHardware } // namespace OHOS diff --git a/services/distributedhardwarefwkservice/test/unittest/common/task/src/enable_task_test.cpp b/services/distributedhardwarefwkservice/test/unittest/common/task/src/enable_task_test.cpp index 6b36e6db..6bccec3a 100644 --- a/services/distributedhardwarefwkservice/test/unittest/common/task/src/enable_task_test.cpp +++ b/services/distributedhardwarefwkservice/test/unittest/common/task/src/enable_task_test.cpp @@ -130,8 +130,8 @@ HWTEST_F(EnableTaskTest, RegisterHardware_005, TestSize.Level0) { auto enableTask = std::make_shared(TASK_PARAM_1.networkId, TASK_PARAM_1.uuid, GetLocalUdid(), TASK_PARAM_1.dhId, TASK_PARAM_1.dhType); - EXPECT_CALL(*componentManager_, EnableSink(_, _, _)).Times(1).WillRepeatedly(Return(0)); - ASSERT_EQ(enableTask->RegisterHardware(), 0); + EXPECT_CALL(*componentManager_, CheckSinkConfigStart(_, _)).Times(1).WillRepeatedly(Return(0)); + ASSERT_EQ(enableTask->RegisterHardware(), ERR_DH_FWK_COMPONENT_LIMIT_DEMAND_START); } /** @@ -144,6 +144,7 @@ HWTEST_F(EnableTaskTest, RegisterHardware_006, TestSize.Level0) { auto enableTask = std::make_shared(TASK_PARAM_1.networkId, TASK_PARAM_1.uuid, GetLocalUdid(), TASK_PARAM_1.dhId, TASK_PARAM_1.dhType); + EXPECT_CALL(*componentManager_, CheckSinkConfigStart(_, _)).WillOnce(DoAll(SetArgReferee<1>(true), Return(0))); EXPECT_CALL(*componentManager_, EnableSink(_, _, _)).Times(1).WillRepeatedly(Return(1)); ASSERT_EQ(enableTask->RegisterHardware(), 1); } diff --git a/services/distributedhardwarefwkservice/test/unittest/common/task/src/mock_component_manager.cpp b/services/distributedhardwarefwkservice/test/unittest/common/task/src/mock_component_manager.cpp index ba35cf18..98ff5a64 100644 --- a/services/distributedhardwarefwkservice/test/unittest/common/task/src/mock_component_manager.cpp +++ b/services/distributedhardwarefwkservice/test/unittest/common/task/src/mock_component_manager.cpp @@ -74,5 +74,10 @@ int32_t ComponentManager::DisableSource(const std::string &networkId, { return IComponentManager::GetOrCtreateInstance()->DisableSource(networkId, dhDescriptor, callingUid, callingPid); } + +int32_t ComponentManager::CheckSinkConfigStart(const DHType dhType, bool &enableSink) +{ + return IComponentManager::GetOrCtreateInstance()->CheckSinkConfigStart(dhType, enableSink); +} } // namespace DistributedHardware } // namespace OHOS -- Gitee