From 5fd9baadcd131c5f6920a313fc77a8e0b55ef0be Mon Sep 17 00:00:00 2001 From: li-tiangang4 Date: Wed, 16 Apr 2025 16:44:47 +0800 Subject: [PATCH] =?UTF-8?q?=E8=AE=BE=E5=A4=87=E4=B8=8A=E7=BA=BF=E6=B7=BB?= =?UTF-8?q?=E5=8A=A0=E5=90=8C=E8=B4=A6=E5=8F=B7=E6=A0=A1=E9=AA=8C?= 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 | 24 --------------- .../src/task/online_task.cpp | 4 +++ utils/BUILD.gn | 4 +++ utils/include/dh_utils_tool.h | 2 ++ utils/src/dh_utils_tool.cpp | 30 +++++++++++++++++++ 6 files changed, 40 insertions(+), 25 deletions(-) diff --git a/services/distributedhardwarefwkservice/include/componentmanager/component_manager.h b/services/distributedhardwarefwkservice/include/componentmanager/component_manager.h index 9e980d9c..057ffa71 100644 --- a/services/distributedhardwarefwkservice/include/componentmanager/component_manager.h +++ b/services/distributedhardwarefwkservice/include/componentmanager/component_manager.h @@ -217,7 +217,6 @@ private: void DoRecover(DHType dhType); void ReStartSA(DHType dhType); void RecoverDistributedHardware(DHType dhType); - bool IsIdenticalAccount(const std::string &networkId); int32_t RetryGetEnableParam(const std::string &networkId, const std::string &uuid, const std::string &dhId, const DHType dhType, EnableParam ¶m); void StopPrivacy(); diff --git a/services/distributedhardwarefwkservice/src/componentmanager/component_manager.cpp b/services/distributedhardwarefwkservice/src/componentmanager/component_manager.cpp index 7067acf5..b29fc22b 100644 --- a/services/distributedhardwarefwkservice/src/componentmanager/component_manager.cpp +++ b/services/distributedhardwarefwkservice/src/componentmanager/component_manager.cpp @@ -677,30 +677,6 @@ std::map ComponentManager::GetDHSinkInstance( return compSink_; } -bool ComponentManager::IsIdenticalAccount(const std::string &networkId) -{ - if (!IsIdLengthValid(networkId)) { - return false; - } - DmAuthForm authForm = DmAuthForm::INVALID_TYPE; - std::vector deviceList; - DeviceManager::GetInstance().GetTrustedDeviceList(DH_FWK_PKG_NAME, "", deviceList); - if (deviceList.size() == 0 || deviceList.size() > MAX_ONLINE_DEVICE_SIZE) { - DHLOGE("DeviceList size is invalid!"); - return false; - } - for (const auto &deviceInfo : deviceList) { - if (std::string(deviceInfo.networkId) == networkId) { - authForm = deviceInfo.authForm; - break; - } - } - if (authForm == DmAuthForm::IDENTICAL_ACCOUNT) { - return true; - } - return false; -} - void ComponentManager::UpdateBusinessState(const std::string &networkId, const std::string &dhId, BusinessState state) { if (!IsIdLengthValid(networkId) || !IsIdLengthValid(dhId)) { diff --git a/services/distributedhardwarefwkservice/src/task/online_task.cpp b/services/distributedhardwarefwkservice/src/task/online_task.cpp index f3f2e05d..62f686f8 100644 --- a/services/distributedhardwarefwkservice/src/task/online_task.cpp +++ b/services/distributedhardwarefwkservice/src/task/online_task.cpp @@ -54,6 +54,10 @@ OnLineTask::~OnLineTask() void OnLineTask::DoTask() { + if (!IsIdenticalAccount(GetNetworkId())) { + DHLOGE("Check identical account failed, networkId: %{public}s.", GetAnonyString(GetNetworkId()).c_str()); + return; + } DHLOGD("start online task, id = %{public}s, networkId: %{public}s, uuid: %{public}s, udid: %{public}s", GetId().c_str(), GetAnonyString(GetNetworkId()).c_str(), GetAnonyString(GetUUID()).c_str(), GetAnonyString(GetUDID()).c_str()); diff --git a/utils/BUILD.gn b/utils/BUILD.gn index 4ffdda81..962f8bc8 100644 --- a/utils/BUILD.gn +++ b/utils/BUILD.gn @@ -72,6 +72,10 @@ ohos_shared_library("distributedhardwareutils") { "-Wl,-z,now", ] + if (distributed_hardware_fwk_low_latency) { + defines += [ "DHARDWARE_CHECK_ACCCOUNT" ] + } + external_deps = [ "cJSON:cjson", "c_utils:utils", diff --git a/utils/include/dh_utils_tool.h b/utils/include/dh_utils_tool.h index 7c7f2852..baecef6b 100644 --- a/utils/include/dh_utils_tool.h +++ b/utils/include/dh_utils_tool.h @@ -81,6 +81,8 @@ bool IsKeySizeValid(const std::string &key); bool IsHashSizeValid(const std::string &hashValue); int32_t GetDeviceSystemType(const std::string &extraData); + +bool IsIdenticalAccount(const std::string &networkId); } // namespace DistributedHardware } // namespace OHOS #endif diff --git a/utils/src/dh_utils_tool.cpp b/utils/src/dh_utils_tool.cpp index 31d45646..5af780d3 100644 --- a/utils/src/dh_utils_tool.cpp +++ b/utils/src/dh_utils_tool.cpp @@ -29,6 +29,7 @@ #include "parameter.h" #include "device_manager.h" +#include "device_type.h" #include "dm_device_info.h" #include "constants.h" @@ -367,5 +368,34 @@ int32_t GetDeviceSystemType(const std::string &extraData) cJSON_Delete(jsonObj); return osType; } + +bool IsIdenticalAccount(const std::string &networkId) +{ +#ifdef DHARDWARE_CHECK_ACCCOUNT + { + if (!IsIdLengthValid(networkId)) { + return false; + } + DmAuthForm authForm = DmAuthForm::INVALID_TYPE; + std::vector deviceList; + DeviceManager::GetInstance().GetTrustedDeviceList(DH_FWK_PKG_NAME, "", deviceList); + if (deviceList.size() == 0 || deviceList.size() > MAX_ONLINE_DEVICE_SIZE) { + DHLOGE("DeviceList size is invalid!"); + return false; + } + for (const auto &deviceInfo : deviceList) { + if (std::string(deviceInfo.networkId) == networkId) { + authForm = deviceInfo.authForm; + break; + } + } + if (authForm == DmAuthForm::IDENTICAL_ACCOUNT) { + return true; + } + return false; + } +#endif + return true; +} } // namespace DistributedHardware } // namespace OHOS -- Gitee