diff --git a/services/distributedhardwarefwkservice/include/componentmanager/component_manager.h b/services/distributedhardwarefwkservice/include/componentmanager/component_manager.h index d49d33a3cef2c913e7fba3b662d8d23b67f630ba..66b03fe19d963d2ebc2b6913ae1b3fadb959690a 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 35b43d0a9867225b3e7a00b99439ef45e8ecf6f3..091040e0fd95517131022eb945418bc1237db571 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 06d705a3badbf261603293f4fa199bf1e17ec776..e2df9dbe185190f8f33085a4faeafaa7c4621eb6 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 f3f2e05da32a69b09f6f773e1d5bea463f3ffe27..3bf08b543b19ba86417d3416af3e319a094cc269 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 ff606ed9dc3d06714541fe37c227a1b98c2dc06b..070516ad5faf59c4884b26c938b5342f31e56d39 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 dc95fa36d20049a72178dc2bbbb1e5fc3a9784df..b442757876cde5ccbd5684e6ffb9d3a11adfd410 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 6b36e6dbe4b04d0ef39b570cd4ed2ceaed932ff8..6bccec3a777f66b204a64cca18e3f9bc48338a06 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 ba35cf186b44f5a560486f21e7da2c0af7b10f37..98ff5a6492a1606eaed8855f386ccc5d70a69e6c 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