From 9e648fecd3a2f3588f51a1c1ba91eb1e5bf402a4 Mon Sep 17 00:00:00 2001 From: zhuzhihui7 Date: Fri, 28 Feb 2025 15:32:59 +0800 Subject: [PATCH] =?UTF-8?q?=E5=88=86=E5=B8=83=E5=BC=8F=E7=A1=AC=E4=BB=B6?= =?UTF-8?q?=E6=8C=89=E9=9C=80=E5=90=AF=E5=8A=A8=E9=85=8D=E7=BD=AE=E4=B8=8A?= =?UTF-8?q?=E4=BA=91=E4=BF=AE=E6=94=B9=EF=BC=9B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: zhuzhihui7 --- .../include/distributed_hardware_errno.h | 1 + .../componentmanager/component_manager.h | 8 +- .../resourcemanager/meta_capability_info.h | 18 ++- .../componentmanager/component_manager.cpp | 109 +++++++++--------- .../local_hardware_manager.cpp | 4 +- .../resourcemanager/meta_capability_info.cpp | 38 ++++-- .../src/task/online_task.cpp | 8 +- .../metainfomgr_fuzzer/metainfomgr_fuzzer.cpp | 3 +- .../src/component_manager_test.cpp | 6 +- .../resourcemanager/meta_cap_info_test.cpp | 60 ++++++---- .../meta_info_manager_test.cpp | 22 ++-- 11 files changed, 164 insertions(+), 113 deletions(-) diff --git a/common/utils/include/distributed_hardware_errno.h b/common/utils/include/distributed_hardware_errno.h index 09068db9..406412c1 100644 --- a/common/utils/include/distributed_hardware_errno.h +++ b/common/utils/include/distributed_hardware_errno.h @@ -51,6 +51,7 @@ namespace DistributedHardware { constexpr int32_t ERR_DH_FWK_COMPONENT_GET_ENABLE_PARAM_FAILED = -10013; constexpr int32_t ERR_DH_FWK_COMPONENT_LIMIT_DEMAND_START = -10014; constexpr int32_t ERR_DH_FWK_COMPONENT_REPEAT_CALL = -10015; + constexpr int32_t ERR_DH_FWK_COMPONENT_COMPVERSION_NOT_FOUND = -10016; /* ResourceManager errno, range: [-10400, -10499] */ constexpr int32_t ERR_DH_FWK_RESOURCE_DB_ADAPTER_POINTER_NULL = -10400; diff --git a/services/distributedhardwarefwkservice/include/componentmanager/component_manager.h b/services/distributedhardwarefwkservice/include/componentmanager/component_manager.h index e71453a3..730b6f7e 100644 --- a/services/distributedhardwarefwkservice/include/componentmanager/component_manager.h +++ b/services/distributedhardwarefwkservice/include/componentmanager/component_manager.h @@ -54,7 +54,7 @@ public: int32_t Init(); int32_t UnInit(); int32_t Enable(const std::string &networkId, const std::string &uuid, const std::string &dhId, - const DHType dhType); + const DHType dhType, bool isActive = false); int32_t Disable(const std::string &networkId, const std::string &uuid, const std::string &dhId, const DHType dhType); void UpdateBusinessState(const std::string &uuid, const std::string &dhId, BusinessState state); @@ -94,6 +94,8 @@ public: const DHDescriptor &dhDescriptor, int32_t callingUid, int32_t callingPid); int32_t ForceDisableSink(const DHDescriptor &dhDescriptor); int32_t ForceDisableSource(const std::string &networkId, const DHDescriptor &dhDescriptor); + int32_t CheckIdenticalAccount(const std::string &networkId, + const std::string &uuid, const DHDescriptor &dhDescriptor); class ComponentManagerEventHandler : public AppExecFwk::EventHandler { public: @@ -224,7 +226,7 @@ private: std::shared_ptr &metaCapPtr); int32_t CheckSubtypeResource(const std::string &subtype, const std::string &networkId); - int32_t GetRemoteVerInfo(VersionInfo &versionInfo, const std::string &uuid, DHType dhType); + int32_t GetRemoteVerInfo(CompVersion &compVersion, const std::string &uuid, DHType dhType); bool IsFeatureMatched(const std::vector &sourceFeatureFilters, const std::vector &sinkSupportedFeatures); int32_t EnableSinkInternal(const DHDescriptor &dhDescriptor, @@ -240,7 +242,7 @@ private: int32_t ForceDisableSourceInternal(const std::string &networkId, const DHDescriptor &dhDescriptor, std::vector> &listeners); int32_t RealEnableSource(const std::string &networkId, const std::string &uuid, const DHDescriptor &dhDescriptor, - DHStatusCtrl &statusCtrl, DHStatusEnableInfo &enableInfo, DHSourceStatus &status); + DHStatusCtrl &statusCtrl, DHStatusEnableInfo &enableInfo, DHSourceStatus &status, bool isActive); int32_t RealDisableSource(const std::string &networkId, const std::string &uuid, const DHDescriptor &dhDescriptor, DHStatusCtrl &statusCtrl, DHStatusEnableInfo &enableInfo, DHSourceStatus &status); diff --git a/services/distributedhardwarefwkservice/include/resourcemanager/meta_capability_info.h b/services/distributedhardwarefwkservice/include/resourcemanager/meta_capability_info.h index 6ae95635..55744495 100644 --- a/services/distributedhardwarefwkservice/include/resourcemanager/meta_capability_info.h +++ b/services/distributedhardwarefwkservice/include/resourcemanager/meta_capability_info.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2024 Huawei Device Co., Ltd. + * Copyright (c) 2024-2025 Huawei Device Co., Ltd. * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at @@ -24,19 +24,22 @@ #include "capability_info.h" #include "device_type.h" +#include "impl_utils.h" namespace OHOS { namespace DistributedHardware { class MetaCapabilityInfo : public CapabilityInfo { public: MetaCapabilityInfo() - : CapabilityInfo("", "", "", 0, DHType::UNKNOWN, "", ""), udidHash_(""), sinkVersion_("") - {} + : CapabilityInfo("", "", "", 0, DHType::UNKNOWN, "", ""), udidHash_("") + { + compVersion_.haveFeature = false; + } MetaCapabilityInfo(std::string dhId, std::string devId, std::string devName, uint16_t devType, DHType dhType, - std::string dhAttrs, std::string dhSubtype, std::string udidHash, std::string sinkVersion) + std::string dhAttrs, std::string dhSubtype, std::string udidHash, CompVersion compVersion) : CapabilityInfo(dhId, devId, devName, devType, dhType, dhAttrs, dhSubtype), - udidHash_(udidHash), sinkVersion_(sinkVersion) {} + udidHash_(udidHash), compVersion_(compVersion) {} virtual ~MetaCapabilityInfo() {} @@ -44,6 +47,9 @@ public: void SetUdidHash(const std::string &udidHash); std::string GetSinkVersion() const; void SetSinkVersion(const std::string &sinkVersion); + CompVersion& GetCompVersion(); + CompVersion GetCompVersion() const; + void SetCompVersion(const CompVersion &compVersion); virtual int32_t FromJsonString(const std::string &jsonStr); virtual std::string ToJsonString(); @@ -53,7 +59,7 @@ public: private: std::string udidHash_; - std::string sinkVersion_; + CompVersion compVersion_; }; void ToJson(cJSON *jsonObject, const MetaCapabilityInfo &metaCapInfo); diff --git a/services/distributedhardwarefwkservice/src/componentmanager/component_manager.cpp b/services/distributedhardwarefwkservice/src/componentmanager/component_manager.cpp index 8ddc61c8..86285c9e 100644 --- a/services/distributedhardwarefwkservice/src/componentmanager/component_manager.cpp +++ b/services/distributedhardwarefwkservice/src/componentmanager/component_manager.cpp @@ -223,7 +223,7 @@ bool ComponentManager::WaitForResult(const Action &action, ActionResult actionsR } int32_t ComponentManager::Enable(const std::string &networkId, const std::string &uuid, const std::string &dhId, - const DHType dhType) + const DHType dhType, bool isActive) { DHLOGI("start."); if (!IsIdLengthValid(networkId) || !IsIdLengthValid(uuid) || !IsIdLengthValid(dhId)) { @@ -243,10 +243,12 @@ int32_t ComponentManager::Enable(const std::string &networkId, const std::string return ret; } } - ret = CheckSubtypeResource(param.subtype, networkId); - if (ret != DH_FWK_SUCCESS) { - DHLOGE("CheckSubtypeResource failed, ret = %{public}d.", ret); - return ret; + if (!isActive) { + ret = CheckSubtypeResource(param.subtype, networkId); + if (ret != DH_FWK_SUCCESS) { + DHLOGE("CheckSubtypeResource failed, ret = %{public}d.", ret); + return ret; + } } auto compEnable = std::make_shared(); @@ -827,8 +829,8 @@ int32_t ComponentManager::CheckDemandStart(const std::string &uuid, enableSource = false; // Get remote config - VersionInfo versionInfo; - auto ret = GetRemoteVerInfo(versionInfo, uuid, dhType); + CompVersion compVersion; + auto ret = GetRemoteVerInfo(compVersion, uuid, dhType); if (ret != DH_FWK_SUCCESS) { DHLOGE("GetRemoteVerInfo fail, errCode = %{public}d!", ret); return ret; @@ -848,12 +850,6 @@ int32_t ComponentManager::CheckDemandStart(const std::string &uuid, return ERR_DH_FWK_TYPE_NOT_EXIST; } - auto iterRemote = versionInfo.compVersions.find(dhType); - if (iterRemote == versionInfo.compVersions.end()) { - DHLOGE("Not find dhType in remote: %{public}#X!", dhType); - return ERR_DH_FWK_TYPE_NOT_EXIST; - } - // Check local config if (!iterLocal->second.haveFeature) { enableSink = true; @@ -870,17 +866,17 @@ int32_t ComponentManager::CheckDemandStart(const std::string &uuid, } // Check remote config - if (!iterRemote->second.haveFeature) { // Remote config is null, need enable source + if (!compVersion.haveFeature) { // Remote config is null, need enable source enableSource = true; return DH_FWK_SUCCESS; } - if (iterRemote->second.sinkSupportedFeatures.size() == 0) { // Remote sink config is empty, not enable source + if (compVersion.sinkSupportedFeatures.size() == 0) { // Remote sink config is empty, not enable source return DH_FWK_SUCCESS; } // Check if the configurations on both ends match - enableSource = IsFeatureMatched(iterLocal->second.sourceFeatureFilters, iterRemote->second.sinkSupportedFeatures); + enableSource = IsFeatureMatched(iterLocal->second.sourceFeatureFilters, compVersion.sinkSupportedFeatures); return DH_FWK_SUCCESS; } @@ -1063,38 +1059,45 @@ int32_t ComponentManager::ForceDisableSource(const std::string &networkId, const return ret; } -int32_t ComponentManager::GetRemoteVerInfo(VersionInfo &versionInfo, const std::string &uuid, DHType dhType) +int32_t ComponentManager::CheckIdenticalAccount(const std::string &networkId, + const std::string &uuid, const DHDescriptor &dhDescriptor) { - auto deviceId = GetDeviceIdByUUID(uuid); - auto ret = VersionInfoManager::GetInstance()->GetVersionInfoByDeviceId(deviceId, versionInfo); + EnableParam param; + auto ret = GetEnableParam(networkId, uuid, dhDescriptor.id, dhDescriptor.dhType, param); if (ret != DH_FWK_SUCCESS) { - DHLOGE("Get Version info Manager failed, uuid =%{public}s, dhType = %{public}#X, errCode = %{public}d.", - GetAnonyString(uuid).c_str(), dhType, ret); - for (int32_t retryCount = 0; - retryCount < SYNC_DEVICE_INFO_TIMEOUT_MILLISECONDS/SYNC_DEVICE_INFO_INTERVAL_MILLISECONDS; - ++retryCount) { - std::this_thread::sleep_for(std::chrono::milliseconds(SYNC_DEVICE_INFO_INTERVAL_MILLISECONDS)); - ret = VersionInfoManager::GetInstance()->GetVersionInfoByDeviceId(deviceId, versionInfo); - if (ret == DH_FWK_SUCCESS) { - break; - } else { - DHLOGE("Attempted to retrieve VersionInfo again but still failed, " - "uuid =%{public}s, dhType = %{public}#X, errCode = %{public}d.", - GetAnonyString(uuid).c_str(), dhType, ret); - } - } - if (ret != DH_FWK_SUCCESS) { - DHLOGE("After trying again, it ultimately failed, " - "uuid =%{public}s, dhType = %{public}#X, errCode = %{public}d.", - GetAnonyString(uuid).c_str(), dhType, ret); + DHLOGE("GetEnableParam failed, uuid = %{public}s, dhId = %{public}s, errCode = %{public}d", + GetAnonyString(uuid).c_str(), GetAnonyString(dhDescriptor.id).c_str(), ret); + if (ComponentManager::GetInstance().RetryGetEnableParam( + networkId, uuid, dhDescriptor.id, dhDescriptor.dhType, param) != DH_FWK_SUCCESS) { return ret; - } else { - DHLOGI("After multiple attempts, obtaining VersionInfo was successful, " - "uuid =%{public}s, dhType = %{public}#X, errCode = %{public}d.", - GetAnonyString(uuid).c_str(), dhType, ret); } } - return ret; + ret = CheckSubtypeResource(param.subtype, networkId); + if (ret != DH_FWK_SUCCESS) { + DHLOGE("CheckSubtypeResource failed, ret = %{public}d.", ret); + return ret; + } + return DH_FWK_SUCCESS; +} + +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; + } + for (const auto &metaInfo : metaInfoMap) { + if (DHContext::GetInstance().GetUUIDByDeviceId(metaInfo.second->GetDeviceId()) == uuid) { + compVersion = metaInfo.second->GetCompVersion(); + return DH_FWK_SUCCESS; + } + } + DHLOGE("The metaInfo corresponding to uuid was not found, uuid =%{public}s, dhType = %{public}#X.", + GetAnonyString(uuid).c_str(), dhType); + return ERR_DH_FWK_COMPONENT_COMPVERSION_NOT_FOUND; } bool ComponentManager::IsFeatureMatched(const std::vector &sourceFeatureFilters, @@ -1238,14 +1241,8 @@ int32_t ComponentManager::EnableSourceInternal(const std::string &networkId, return ERR_DH_FWK_TYPE_NOT_EXIST; } - DHStatusSourceEnableInfoKey enableInfoKey { - .networkId = networkId, - .dhId = dhDescriptor.id - }; - DHStatusCtrlKey ctrlKey { - .uid = callingUid, - .pid = callingPid - }; + DHStatusSourceEnableInfoKey enableInfoKey { .networkId = networkId, .dhId = dhDescriptor.id }; + DHStatusCtrlKey ctrlKey { .uid = callingUid, .pid = callingPid }; auto uuid = DHContext::GetInstance().GetUUIDByNetworkId(networkId); std::lock_guard lock(dhSourceStatusMtx_); @@ -1277,7 +1274,8 @@ int32_t ComponentManager::EnableSourceInternal(const std::string &networkId, // Check load reference count if (status.refLoad) { - auto ret = Enable(networkId, uuid, dhDescriptor.id, dhDescriptor.dhType); + auto ret = Enable(networkId, uuid, dhDescriptor.id, dhDescriptor.dhType, + (callingUid != 0) || (callingPid != 0)); if (ret != DH_FWK_SUCCESS) { DHLOGE("Enable failed, ret = %{public}d.", ret); return ret; @@ -1289,7 +1287,8 @@ int32_t ComponentManager::EnableSourceInternal(const std::string &networkId, return DH_FWK_SUCCESS; } - auto ret = RealEnableSource(networkId, uuid, dhDescriptor, statusCtrl, enableInfo, status); + auto ret = RealEnableSource(networkId, uuid, dhDescriptor, statusCtrl, enableInfo, status, + (callingUid != 0) || (callingPid != 0)); if (ret != DH_FWK_SUCCESS) { DHLOGE("RealEnableSource failed, ret = %{public}d.", ret); return ret; @@ -1481,7 +1480,7 @@ int32_t ComponentManager::ForceDisableSourceInternal(const std::string &networkI int32_t ComponentManager::RealEnableSource(const std::string &networkId, const std::string &uuid, const DHDescriptor &dhDescriptor, DHStatusCtrl &statusCtrl, - DHStatusEnableInfo &enableInfo, DHSourceStatus &status) + DHStatusEnableInfo &enableInfo, DHSourceStatus &status, bool isActive) { auto ret = InitCompSource(dhDescriptor.dhType); if (ret != DH_FWK_SUCCESS) { @@ -1496,7 +1495,7 @@ int32_t ComponentManager::RealEnableSource(const std::string &networkId, const s UninitCompSource(dhDescriptor.dhType); return ERR_DH_FWK_COMPONENT_ENABLE_TIMEOUT; } - ret = Enable(networkId, uuid, dhDescriptor.id, dhDescriptor.dhType); + ret = Enable(networkId, uuid, dhDescriptor.id, dhDescriptor.dhType, isActive); if (ret != DH_FWK_SUCCESS) { DHLOGE("Enable failed, ret = %{public}d.", ret); StopSource(dhDescriptor.dhType); diff --git a/services/distributedhardwarefwkservice/src/localhardwaremanager/local_hardware_manager.cpp b/services/distributedhardwarefwkservice/src/localhardwaremanager/local_hardware_manager.cpp index f34843a2..18091cb5 100644 --- a/services/distributedhardwarefwkservice/src/localhardwaremanager/local_hardware_manager.cpp +++ b/services/distributedhardwarefwkservice/src/localhardwaremanager/local_hardware_manager.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2021-2024 Huawei Device Co., Ltd. + * Copyright (c) 2021-2025 Huawei Device Co., Ltd. * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at @@ -156,7 +156,7 @@ void LocalHardwareManager::AddLocalMetaCapInfo(const std::vector &dhItem for (auto dhItem : dhItems) { std::shared_ptr dhMetaCapInfo = std::make_shared( dhItem.dhId, deviceId, devName, devType, dhType, dhItem.attrs, dhItem.subtype, udidHash, - compversion.sinkVersion); + compversion); metaCapInfos.push_back(dhMetaCapInfo); } } diff --git a/services/distributedhardwarefwkservice/src/resourcemanager/meta_capability_info.cpp b/services/distributedhardwarefwkservice/src/resourcemanager/meta_capability_info.cpp index 5136655f..72d5de8a 100644 --- a/services/distributedhardwarefwkservice/src/resourcemanager/meta_capability_info.cpp +++ b/services/distributedhardwarefwkservice/src/resourcemanager/meta_capability_info.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2024 Huawei Device Co., Ltd. + * Copyright (c) 2024-2025 Huawei Device Co., Ltd. * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at @@ -24,6 +24,7 @@ #include "dh_utils_tool.h" #include "distributed_hardware_errno.h" #include "distributed_hardware_log.h" +#include "version_info.h" namespace OHOS { namespace DistributedHardware { @@ -42,12 +43,27 @@ void MetaCapabilityInfo::SetUdidHash(const std::string &udidHash) std::string MetaCapabilityInfo::GetSinkVersion() const { - return sinkVersion_; + return compVersion_.sinkVersion; } void MetaCapabilityInfo::SetSinkVersion(const std::string &sinkVersion) { - this->sinkVersion_ = sinkVersion; + this->compVersion_.sinkVersion = sinkVersion; +} + +CompVersion& MetaCapabilityInfo::GetCompVersion() +{ + return compVersion_; +} + +CompVersion MetaCapabilityInfo::GetCompVersion() const +{ + return compVersion_; +} + +void MetaCapabilityInfo::SetCompVersion(const CompVersion &compVersion) +{ + this->compVersion_ = compVersion; } int32_t MetaCapabilityInfo::FromJsonString(const std::string &jsonStr) @@ -158,7 +174,13 @@ void ToJson(cJSON *jsonObject, const MetaCapabilityInfo &metaCapInfo) cJSON_AddStringToObject(jsonObject, DH_ATTRS.c_str(), metaCapInfo.GetDHAttrs().c_str()); cJSON_AddStringToObject(jsonObject, DH_SUBTYPE.c_str(), metaCapInfo.GetDHSubtype().c_str()); cJSON_AddStringToObject(jsonObject, DEV_UDID_HASH.c_str(), metaCapInfo.GetUdidHash().c_str()); - cJSON_AddStringToObject(jsonObject, SINK_VER.c_str(), metaCapInfo.GetSinkVersion().c_str()); + cJSON *jsonObjCompVersion = cJSON_CreateObject(); + if (jsonObjCompVersion == NULL) { + DHLOGE("Failed to create cJSON object."); + return; + } + ToJson(jsonObjCompVersion, metaCapInfo.GetCompVersion()); + cJSON_AddItemToObject(jsonObject, COMP_VER.c_str(), jsonObjCompVersion); } void FromJson(const cJSON *jsonObject, MetaCapabilityInfo &metaCapInfo) @@ -224,12 +246,12 @@ void FromJsonContinue(const cJSON *jsonObject, MetaCapabilityInfo &metaCapInfo) } metaCapInfo.SetUdidHash(udidHashJson->valuestring); - cJSON *sinkVerJson = cJSON_GetObjectItem(jsonObject, SINK_VER.c_str()); - if (!IsString(sinkVerJson)) { - DHLOGE("SINK_VER is invalid!"); + cJSON *compVersionJson = cJSON_GetObjectItem(jsonObject, COMP_VER.c_str()); + if (compVersionJson == nullptr) { + DHLOGE("CompVersion is invalid!"); return; } - metaCapInfo.SetSinkVersion(sinkVerJson->valuestring); + FromJson(compVersionJson, metaCapInfo.GetCompVersion()); } } // namespace DistributedHardware } // namespace OHOS diff --git a/services/distributedhardwarefwkservice/src/task/online_task.cpp b/services/distributedhardwarefwkservice/src/task/online_task.cpp index f5c990c2..e044b817 100644 --- a/services/distributedhardwarefwkservice/src/task/online_task.cpp +++ b/services/distributedhardwarefwkservice/src/task/online_task.cpp @@ -88,13 +88,7 @@ void OnLineTask::DoSyncInfo() GetAnonyString(deviceId).c_str(), GetAnonyString(GetUUID()).c_str(), GetAnonyString(GetUDID()).c_str(), GetAnonyString(udidHash).c_str()); - auto ret = VersionInfoManager::GetInstance()->SyncVersionInfoFromDB(deviceId); - if (ret != DH_FWK_SUCCESS) { - DHLOGE("SyncVersionInfoFromDB failed, deviceId = %{public}s, uuid = %{public}s, errCode = %{public}d", - GetAnonyString(deviceId).c_str(), GetAnonyString(GetUUID()).c_str(), ret); - } - - ret = LocalCapabilityInfoManager::GetInstance()->SyncDeviceInfoFromDB(deviceId); + auto ret = LocalCapabilityInfoManager::GetInstance()->SyncDeviceInfoFromDB(deviceId); if (ret != DH_FWK_SUCCESS) { DHLOGE("SyncLocalCapabilityInfoFromDB failed, deviceId = %{public}s, errCode = %{public}d", GetAnonyString(deviceId).c_str(), ret); diff --git a/services/distributedhardwarefwkservice/test/fuzztest/metainfomgr_fuzzer/metainfomgr_fuzzer.cpp b/services/distributedhardwarefwkservice/test/fuzztest/metainfomgr_fuzzer/metainfomgr_fuzzer.cpp index 67ea65db..cf0c2725 100644 --- a/services/distributedhardwarefwkservice/test/fuzztest/metainfomgr_fuzzer/metainfomgr_fuzzer.cpp +++ b/services/distributedhardwarefwkservice/test/fuzztest/metainfomgr_fuzzer/metainfomgr_fuzzer.cpp @@ -64,7 +64,8 @@ void GetMetaCapInfoFuzzTest(const uint8_t* data, size_t size) std::string dhId(reinterpret_cast(data), size); uint16_t deviceType = 14; std::shared_ptr metaCapPtr = std::make_shared( - dhId, deviceId, "devName_test", deviceType, DHType::CAMERA, "attrs_test", "subtype", udidHash, "1.0"); + dhId, deviceId, "devName_test", deviceType, DHType::CAMERA, "attrs_test", "subtype", udidHash, + CompVersion{ .sinkVersion = "1.0" }); std::string key = deviceId + "###" + dhId; MetaInfoManager::GetInstance()->globalMetaInfoMap_[key] = metaCapPtr; MetaInfoManager::GetInstance()->GetMetaCapInfo(deviceId, dhId, metaCapPtr); 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 d2bc80c6..9bbbd9c6 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 @@ -76,7 +76,7 @@ const std::shared_ptr CAP_INFO_TEST = DH_SUBTYPE_TEST); const std::shared_ptr META_INFO_PTR_TEST = std::make_shared( DH_ID_TEST, DEV_ID_TEST, DEVICE_NAME, TEST_DEV_TYPE_PAD, DHType::CAMERA, DH_ATTR_1, DH_SUBTYPE_TEST, UDIDHASH_TEST, - TEST_SINK_VERSION_1); + CompVersion{ .sinkVersion = TEST_SINK_VERSION_1 }); } void ComponentManagerTest::SetUpTestCase(void) @@ -900,8 +900,10 @@ HWTEST_F(ComponentManagerTest, ReStartSA_001, TestSize.Level0) */ HWTEST_F(ComponentManagerTest, RecoverDistributedHardware_001, TestSize.Level0) { + CompVersion compVersion; + compVersion.sinkVersion = "1.0"; std::shared_ptr metaCapInfo = std::make_shared( - "", "", "devName_test", TEST_DEV_TYPE_PAD, DHType::CAMERA, "attrs_test", "subtype", "", "1.0"); + "", "", "devName_test", TEST_DEV_TYPE_PAD, DHType::CAMERA, "attrs_test", "subtype", "", compVersion); DHType dhType = DHType::CAMERA; std::string udidHash = Sha256(UDID_TEST); std::string key = udidHash + "###" + DH_ID_TEST; diff --git a/services/distributedhardwarefwkservice/test/unittest/common/resourcemanager/meta_cap_info_test.cpp b/services/distributedhardwarefwkservice/test/unittest/common/resourcemanager/meta_cap_info_test.cpp index e91603b2..d67d739c 100644 --- a/services/distributedhardwarefwkservice/test/unittest/common/resourcemanager/meta_cap_info_test.cpp +++ b/services/distributedhardwarefwkservice/test/unittest/common/resourcemanager/meta_cap_info_test.cpp @@ -61,7 +61,8 @@ HWTEST_F(MetaCapInfoTest, FromJsonString_001, TestSize.Level0) { uint16_t devType = 1; std::shared_ptr metaCapInfo = - std::make_shared("", "", "", devType, DHType::CAMERA, "", "", "", ""); + std::make_shared("", "", "", devType, DHType::CAMERA, "", "", "", + CompVersion{ .sinkVersion = "" }); std::string jsonStr = ""; auto ret = metaCapInfo->FromJsonString(jsonStr); EXPECT_EQ(ERR_DH_FWK_PARA_INVALID, ret); @@ -71,7 +72,8 @@ HWTEST_F(MetaCapInfoTest, FromJsonString_002, TestSize.Level0) { uint16_t devType = 1; std::shared_ptr metaCapInfo = - std::make_shared("", "", "", devType, DHType::CAMERA, "", "", "", ""); + std::make_shared("", "", "", devType, DHType::CAMERA, "", "", "", + CompVersion{ .sinkVersion = "" }); cJSON *jsonObj = cJSON_CreateObject(); ASSERT_TRUE(jsonObj != nullptr); cJSON_AddStringToObject(jsonObj, DH_ID.c_str(), DHID_TEST.c_str()); @@ -247,9 +249,10 @@ HWTEST_F(MetaCapInfoTest, FromJson_010, TestSize.Level0) HWTEST_F(MetaCapInfoTest, Compare_001, TestSize.Level0) { uint16_t devType = 1; - MetaCapabilityInfo metaCapInfo("", "", "", devType, DHType::CAMERA, "", "", "", ""); + MetaCapabilityInfo metaCapInfo("", "", "", devType, DHType::CAMERA, "", "", "", CompVersion{ .sinkVersion = "" }); std::shared_ptr metaCapInfoPtr = - std::make_shared("devid_123", "", "", devType, DHType::CAMERA, "", "", "", ""); + std::make_shared("devid_123", "", "", devType, DHType::CAMERA, "", "", "", + CompVersion{ .sinkVersion = "" }); auto ret = metaCapInfoPtr->Compare(metaCapInfo); EXPECT_EQ(false, ret); } @@ -257,9 +260,11 @@ HWTEST_F(MetaCapInfoTest, Compare_001, TestSize.Level0) HWTEST_F(MetaCapInfoTest, Compare_002, TestSize.Level0) { uint16_t devType = 1; - MetaCapabilityInfo metaCapInfo("devid_123", "", "", devType, DHType::CAMERA, "", "", "", ""); + MetaCapabilityInfo metaCapInfo("devid_123", "", "", devType, DHType::CAMERA, "", "", "", + CompVersion{ .sinkVersion = "" }); std::shared_ptr metaCapInfoPtr = - std::make_shared("devid_123", "dhid_123", "", devType, DHType::CAMERA, "", "", "", ""); + std::make_shared("devid_123", "dhid_123", "", devType, DHType::CAMERA, "", "", "", + CompVersion{ .sinkVersion = "" }); auto ret = metaCapInfoPtr->Compare(metaCapInfo); EXPECT_EQ(false, ret); } @@ -267,9 +272,10 @@ HWTEST_F(MetaCapInfoTest, Compare_002, TestSize.Level0) HWTEST_F(MetaCapInfoTest, Compare_003, TestSize.Level0) { uint16_t devType = 1; - MetaCapabilityInfo metaCapInfo("devid_123", "dhid_123", "", devType, DHType::CAMERA, "", "", "", ""); + MetaCapabilityInfo metaCapInfo("devid_123", "dhid_123", "", devType, DHType::CAMERA, "", "", "", + CompVersion{ .sinkVersion = "" }); std::shared_ptr metaCapInfoPtr = std::make_shared( - "devid_123", "dhid_123", "devname", devType, DHType::CAMERA, "", "", "", ""); + "devid_123", "dhid_123", "devname", devType, DHType::CAMERA, "", "", "", CompVersion{ .sinkVersion = "" }); auto ret = metaCapInfoPtr->Compare(metaCapInfo); EXPECT_EQ(false, ret); } @@ -277,9 +283,11 @@ HWTEST_F(MetaCapInfoTest, Compare_003, TestSize.Level0) HWTEST_F(MetaCapInfoTest, Compare_004, TestSize.Level0) { uint16_t devType = 1; - MetaCapabilityInfo metaCapInfo("devid_123", "dhid_123", "devname", devType, DHType::CAMERA, "", "", "", ""); + MetaCapabilityInfo metaCapInfo("devid_123", "dhid_123", "devname", devType, DHType::CAMERA, "", "", "", + CompVersion{ .sinkVersion = "" }); std::shared_ptr metaCapInfoPtr = - std::make_shared("devid_123", "dhid_123", "devname", 2, DHType::CAMERA, "", "", "", ""); + std::make_shared("devid_123", "dhid_123", "devname", 2, DHType::CAMERA, "", "", "", + CompVersion{ .sinkVersion = "" }); auto ret = metaCapInfoPtr->Compare(metaCapInfo); EXPECT_EQ(false, ret); } @@ -287,9 +295,10 @@ HWTEST_F(MetaCapInfoTest, Compare_004, TestSize.Level0) HWTEST_F(MetaCapInfoTest, Compare_005, TestSize.Level0) { uint16_t devType = 1; - MetaCapabilityInfo metaCapInfo("devid_123", "dhid_123", "devname", devType, DHType::CAMERA, "", "", "", ""); + MetaCapabilityInfo metaCapInfo("devid_123", "dhid_123", "devname", devType, DHType::CAMERA, "", "", "", + CompVersion{ .sinkVersion = "" }); std::shared_ptr metaCapInfoPtr = std::make_shared( - "devid_123", "dhid_123", "devname", devType, DHType::AUDIO, "", "", "", ""); + "devid_123", "dhid_123", "devname", devType, DHType::AUDIO, "", "", "", CompVersion{ .sinkVersion = "" }); auto ret = metaCapInfoPtr->Compare(metaCapInfo); EXPECT_EQ(false, ret); } @@ -297,9 +306,11 @@ HWTEST_F(MetaCapInfoTest, Compare_005, TestSize.Level0) HWTEST_F(MetaCapInfoTest, Compare_006, TestSize.Level0) { uint16_t devType = 1; - MetaCapabilityInfo metaCapInfo("devid_123", "dhid_123", "devname", devType, DHType::CAMERA, "", "", "", ""); + MetaCapabilityInfo metaCapInfo("devid_123", "dhid_123", "devname", devType, DHType::CAMERA, "", "", "", + CompVersion{ .sinkVersion = "" }); std::shared_ptr metaCapInfoPtr = std::make_shared( - "devid_123", "dhid_123", "devname", devType, DHType::CAMERA, "attrs", "", "", ""); + "devid_123", "dhid_123", "devname", devType, DHType::CAMERA, "attrs", "", "", + CompVersion{ .sinkVersion = "" }); auto ret = metaCapInfoPtr->Compare(metaCapInfo); EXPECT_EQ(false, ret); } @@ -307,9 +318,11 @@ HWTEST_F(MetaCapInfoTest, Compare_006, TestSize.Level0) HWTEST_F(MetaCapInfoTest, Compare_007, TestSize.Level0) { uint16_t devType = 1; - MetaCapabilityInfo metaCapInfo("devid_123", "dhid_123", "devname", devType, DHType::CAMERA, "attrs", "", "", ""); + MetaCapabilityInfo metaCapInfo("devid_123", "dhid_123", "devname", devType, DHType::CAMERA, "attrs", "", "", + CompVersion{ .sinkVersion = "" }); std::shared_ptr metaCapInfoPtr = std::make_shared( - "devid_123", "dhid_123", "devname", devType, DHType::CAMERA, "attrs", "subtype", "", ""); + "devid_123", "dhid_123", "devname", devType, DHType::CAMERA, "attrs", "subtype", "", + CompVersion{ .sinkVersion = "" }); auto ret = metaCapInfoPtr->Compare(metaCapInfo); EXPECT_EQ(false, ret); } @@ -318,9 +331,10 @@ HWTEST_F(MetaCapInfoTest, Compare_008, TestSize.Level0) { uint16_t devType = 1; MetaCapabilityInfo metaCapInfo("devid_123", "dhid_123", "devname", - devType, DHType::CAMERA, "attrs", "subtype", "", ""); + devType, DHType::CAMERA, "attrs", "subtype", "", CompVersion{ .sinkVersion = "" }); std::shared_ptr metaCapInfoPtr = std::make_shared( - "devid_123", "dhid_123", "devname", devType, DHType::CAMERA, "attrs", "subtype", "udidhash_123", ""); + "devid_123", "dhid_123", "devname", devType, DHType::CAMERA, "attrs", "subtype", "udidhash_123", + CompVersion{ .sinkVersion = "" }); auto ret = metaCapInfoPtr->Compare(metaCapInfo); EXPECT_EQ(false, ret); } @@ -329,9 +343,10 @@ HWTEST_F(MetaCapInfoTest, Compare_009, TestSize.Level0) { uint16_t devType = 1; MetaCapabilityInfo metaCapInfo("devid_123", "dhid_123", "devname", - devType, DHType::CAMERA, "attrs", "subtype", "udidhash_123", ""); + devType, DHType::CAMERA, "attrs", "subtype", "udidhash_123", CompVersion{ .sinkVersion = "" }); std::shared_ptr metaCapInfoPtr = std::make_shared( - "devid_123", "dhid_123", "devname", devType, DHType::CAMERA, "attrs", "subtype", "udidhash_123", "1.0"); + "devid_123", "dhid_123", "devname", devType, DHType::CAMERA, "attrs", "subtype", "udidhash_123", + CompVersion{ .sinkVersion = "1.0" }); auto ret = metaCapInfoPtr->Compare(metaCapInfo); EXPECT_EQ(false, ret); } @@ -340,9 +355,10 @@ HWTEST_F(MetaCapInfoTest, Compare_010, TestSize.Level0) { uint16_t devType = 1; MetaCapabilityInfo metaCapInfo("devid_123", "dhid_123", "devname", - devType, DHType::CAMERA, "attrs", "subtype", "udidhash_123", "1.0"); + devType, DHType::CAMERA, "attrs", "subtype", "udidhash_123", CompVersion{ .sinkVersion = "1.0" }); std::shared_ptr metaCapInfoPtr = std::make_shared( - "devid_123", "dhid_123", "devname", devType, DHType::CAMERA, "attrs", "subtype", "udidhash_123", "1.0"); + "devid_123", "dhid_123", "devname", devType, DHType::CAMERA, "attrs", "subtype", "udidhash_123", + CompVersion{ .sinkVersion = "1.0" }); auto ret = metaCapInfoPtr->Compare(metaCapInfo); EXPECT_EQ(true, ret); } diff --git a/services/distributedhardwarefwkservice/test/unittest/common/resourcemanager/meta_info_manager_test.cpp b/services/distributedhardwarefwkservice/test/unittest/common/resourcemanager/meta_info_manager_test.cpp index 4915eeb9..76c57959 100644 --- a/services/distributedhardwarefwkservice/test/unittest/common/resourcemanager/meta_info_manager_test.cpp +++ b/services/distributedhardwarefwkservice/test/unittest/common/resourcemanager/meta_info_manager_test.cpp @@ -76,7 +76,8 @@ HWTEST_F(MetaInfoMgrTest, AddMetaCapInfos_001, TestSize.Level0) for (int32_t i = 1; i < MAX_DB_RECORD_LENGTH; i++) { std::shared_ptr mateCapInfoTest = make_shared(std::to_string(i), - std::to_string(i), "devName_test", DEV_TYPE_TEST, DHType::CAMERA, "attrs", "subtype", udidHash, "1.0"); + std::to_string(i), "devName_test", DEV_TYPE_TEST, DHType::CAMERA, "attrs", "subtype", udidHash, + CompVersion{ .sinkVersion = "1.0" }); metaCapInfos.push_back(mateCapInfoTest); } ret = MetaInfoManager::GetInstance()->AddMetaCapInfos(metaCapInfos); @@ -88,8 +89,10 @@ HWTEST_F(MetaInfoMgrTest, AddMetaCapInfos_002, TestSize.Level0) std::string deviceId = "deviceId_test"; std::string udidHash = "udidHash_test"; std::string dhId = "dhId_test"; + CompVersion compVersion; + compVersion.sinkVersion = "1.0"; std::shared_ptr metaCapInfo = std::make_shared( - dhId, deviceId, "devName_test", DEV_TYPE_TEST, DHType::CAMERA, "attrs_test", "subtype", udidHash, "1.0"); + dhId, deviceId, "devName_test", DEV_TYPE_TEST, DHType::CAMERA, "attrs_test", "subtype", udidHash, compVersion); std::vector> metaCapInfos; metaCapInfos.push_back(metaCapInfo); auto ret = MetaInfoManager::GetInstance()->AddMetaCapInfos(metaCapInfos); @@ -215,9 +218,10 @@ HWTEST_F(MetaInfoMgrTest, GetMetaCapInfo_002, TestSize.Level0) std::string deviceId = "deviceId_test"; std::string udidHash = "udidHash_test"; std::string dhId = "dhId_test"; + CompVersion compVersion{ .sinkVersion = "1.0" }; std::shared_ptr metaCapPtr; std::shared_ptr dhMetaCapInfo = std::make_shared( - dhId, deviceId, "devName_test", DEV_TYPE_TEST, DHType::CAMERA, "attrs_test", "subtype", udidHash, "1.0"); + dhId, deviceId, "devName_test", DEV_TYPE_TEST, DHType::CAMERA, "attrs_test", "subtype", udidHash, compVersion); std::string key = udidHash + "###" + dhId; MetaInfoManager::GetInstance()->globalMetaInfoMap_[key] = dhMetaCapInfo; auto ret = MetaInfoManager::GetInstance()->GetMetaCapInfo(deviceId, dhId, metaCapPtr); @@ -238,7 +242,8 @@ HWTEST_F(MetaInfoMgrTest, GetMetaCapInfosByUdidHash_001, TestSize.Level0) std::string deviceId = "deviceId_test"; std::string dhId = "dhId_test"; std::shared_ptr metaCapInfo = std::make_shared( - dhId, deviceId, "devName_test", DEV_TYPE_TEST, DHType::CAMERA, "attrs_test", "subtype", udidHash, "1.0"); + dhId, deviceId, "devName_test", DEV_TYPE_TEST, DHType::CAMERA, "attrs_test", "subtype", udidHash, + CompVersion{ .sinkVersion = "1.0" }); std::string key = udidHash + "###" + dhId; MetaInfoManager::GetInstance()->globalMetaInfoMap_[key] = metaCapInfo; MetaInfoManager::GetInstance()->GetMetaCapInfosByUdidHash(deviceId, metaCapInfos); @@ -264,7 +269,8 @@ HWTEST_F(MetaInfoMgrTest, GetMetaCapByValue_001, TestSize.Level0) std::string udidHash = "udidHash_test"; std::string dhId = "dhId_test"; metaCapPtr = std::make_shared( - dhId, deviceId, "devName_test", DEV_TYPE_TEST, DHType::CAMERA, "attrs_test", "subtype", udidHash, "1.0"); + dhId, deviceId, "devName_test", DEV_TYPE_TEST, DHType::CAMERA, "attrs_test", "subtype", udidHash, + CompVersion{ .sinkVersion = "1.0" }); ret = MetaInfoManager::GetInstance()->GetMetaCapByValue(value, metaCapPtr); EXPECT_EQ(ERR_DH_FWK_JSON_PARSE_FAILED, ret); } @@ -276,7 +282,8 @@ HWTEST_F(MetaInfoMgrTest, GetMetaDataByDHType_001, TestSize.Level0) std::string dhId = "dhId_test"; MetaCapInfoMap metaInfoMap; std::shared_ptr dhMetaCapInfo = std::make_shared( - dhId, deviceId, "devName_test", DEV_TYPE_TEST, DHType::CAMERA, "attrs_test", "subtype", udidHash, "1.0"); + dhId, deviceId, "devName_test", DEV_TYPE_TEST, DHType::CAMERA, "attrs_test", "subtype", udidHash, + CompVersion{ .sinkVersion = "1.0" }); std::string key = udidHash + "###" + dhId; MetaInfoManager::GetInstance()->globalMetaInfoMap_[key] = dhMetaCapInfo; auto ret = MetaInfoManager::GetInstance()->GetMetaDataByDHType(DHType::AUDIO, metaInfoMap); @@ -315,7 +322,8 @@ HWTEST_F(MetaInfoMgrTest, RemoveMetaInfoInMemByUdid_001, TestSize.Level0) std::string udidHash = "udidHash_test"; std::string dhId = "dhId_test"; std::shared_ptr metaCapPtr = std::make_shared( - dhId, deviceId, "devName_test", DEV_TYPE_TEST, DHType::CAMERA, "attrs_test", "subtype", udidHash, "1.0"); + dhId, deviceId, "devName_test", DEV_TYPE_TEST, DHType::CAMERA, "attrs_test", "subtype", udidHash, + CompVersion{ .sinkVersion = "1.0" }); std::string key = peerudIdHash + "###" + dhId; MetaInfoManager::GetInstance()->globalMetaInfoMap_[key] = metaCapPtr; auto ret = MetaInfoManager::GetInstance()->RemoveMetaInfoInMemByUdid(deviceId); -- Gitee