From 81bbacd8e165c50670b1484adb51eab0a9cce73a Mon Sep 17 00:00:00 2001 From: chen0088 Date: Thu, 12 Sep 2024 17:29:59 +0800 Subject: [PATCH] modify Signed-off-by: chen0088 --- .../distributedhardwarefwkservice/BUILD.gn | 4 +++ .../componentmanager/component_manager.h | 1 + .../componentmanager/component_manager.cpp | 29 +++++++++++++------ 3 files changed, 25 insertions(+), 9 deletions(-) diff --git a/services/distributedhardwarefwkservice/BUILD.gn b/services/distributedhardwarefwkservice/BUILD.gn index 993406cb..38abfe48 100644 --- a/services/distributedhardwarefwkservice/BUILD.gn +++ b/services/distributedhardwarefwkservice/BUILD.gn @@ -137,6 +137,10 @@ ohos_shared_library("distributedhardwarefwksvr") { defines += [ "DHARDWARE_OPEN_SOURCE" ] } + if (distributed_hardware_fwk_low_latency) { + defines += [ "DHARDWARE_CHECK_RESOURCE" ] + } + external_deps = [ "ability_base:want", "ability_runtime:ability_manager", diff --git a/services/distributedhardwarefwkservice/include/componentmanager/component_manager.h b/services/distributedhardwarefwkservice/include/componentmanager/component_manager.h index 05be1700..1de63a8e 100644 --- a/services/distributedhardwarefwkservice/include/componentmanager/component_manager.h +++ b/services/distributedhardwarefwkservice/include/componentmanager/component_manager.h @@ -137,6 +137,7 @@ private: int32_t GetCapParam(const std::string &uuid, const std::string &dhId, std::shared_ptr &capability); int32_t GetMetaParam(const std::string &uuid, const std::string &dhId, std::shared_ptr &metaCapPtr); + int32_t CheckSubtypeResource(const std::string &subtype, const std::string &networkId); private: std::map compSource_; diff --git a/services/distributedhardwarefwkservice/src/componentmanager/component_manager.cpp b/services/distributedhardwarefwkservice/src/componentmanager/component_manager.cpp index 4bb28b1a..6a850c57 100644 --- a/services/distributedhardwarefwkservice/src/componentmanager/component_manager.cpp +++ b/services/distributedhardwarefwkservice/src/componentmanager/component_manager.cpp @@ -557,15 +557,10 @@ int32_t ComponentManager::Enable(const std::string &networkId, const std::string return ret; } } - std::string subtype = param.subtype; - std::map resourceDesc = ComponentLoader::GetInstance().GetCompResourceDesc(); - if (resourceDesc.find(subtype) == resourceDesc.end()) { - DHLOGE("GetCompResourceDesc failed, subtype: %{public}s", subtype.c_str()); - return ERR_DH_FWK_RESOURCE_KEY_IS_EMPTY; - } - if (resourceDesc[subtype] && !IsIdenticalAccount(networkId)) { - DHLOGE("Privacy resources must be logged in with the same account."); - return ERR_DH_FWK_COMPONENT_ENABLE_FAILED; + ret = CheckSubtypeResource(param.subtype, networkId); + if (ret != DH_FWK_SUCCESS) { + DHLOGE("CheckSubtypeResource failed, ret = %{public}d.", ret); + return ret; } auto compEnable = std::make_shared(); @@ -592,6 +587,22 @@ int32_t ComponentManager::Enable(const std::string &networkId, const std::string return result; } +int32_t ComponentManager::CheckSubtypeResource(const std::string &subtype, const std::string &networkId) +{ +#ifdef DHARDWARE_CHECK_RESOURCE + std::map resourceDesc = ComponentLoader::GetInstance().GetCompResourceDesc(); + if (resourceDesc.find(subtype) == resourceDesc.end()) { + DHLOGE("GetCompResourceDesc failed, subtype: %{public}s", subtype.c_str()); + return ERR_DH_FWK_RESOURCE_KEY_IS_EMPTY; + } + if (resourceDesc[subtype] && !IsIdenticalAccount(networkId)) { + DHLOGE("Privacy resources must be logged in with the same account."); + return ERR_DH_FWK_COMPONENT_ENABLE_FAILED; + } +#endif + return DH_FWK_SUCCESS; +} + int32_t ComponentManager::RetryGetEnableParam(const std::string &networkId, const std::string &uuid, const std::string &dhId, const DHType dhType, EnableParam ¶m) { -- Gitee