From a1c296ea2b2a4a7acd7f8a1be555f8a14487227b Mon Sep 17 00:00:00 2001 From: zhuzhihui7 Date: Wed, 26 Mar 2025 20:03:03 +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=A1=86=E6=9E=B6=E4=BD=BF=E8=83=BD=E7=A1=AC=E4=BB=B6=E5=90=8C?= =?UTF-8?q?=E8=B4=A6=E6=88=B7=E6=A0=A1=E9=AA=8C=E5=8C=BA=E5=88=86=E8=93=9D?= =?UTF-8?q?=E9=BB=84=E5=8C=BA?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: zhuzhihui7 --- .../componentmanager/component_manager.h | 3 +- .../componentmanager/component_manager.cpp | 30 +++++++++---------- .../src/task/offline_task.cpp | 5 ++++ .../src/task/online_task.cpp | 5 ++++ 4 files changed, 25 insertions(+), 18 deletions(-) diff --git a/services/distributedhardwarefwkservice/include/componentmanager/component_manager.h b/services/distributedhardwarefwkservice/include/componentmanager/component_manager.h index 730b6f7e..5c6145ec 100644 --- a/services/distributedhardwarefwkservice/include/componentmanager/component_manager.h +++ b/services/distributedhardwarefwkservice/include/componentmanager/component_manager.h @@ -94,8 +94,7 @@ 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); + int32_t CheckIdenticalAccount(const std::string &networkId); class ComponentManagerEventHandler : public AppExecFwk::EventHandler { public: diff --git a/services/distributedhardwarefwkservice/src/componentmanager/component_manager.cpp b/services/distributedhardwarefwkservice/src/componentmanager/component_manager.cpp index 86285c9e..47adca01 100644 --- a/services/distributedhardwarefwkservice/src/componentmanager/component_manager.cpp +++ b/services/distributedhardwarefwkservice/src/componentmanager/component_manager.cpp @@ -1008,6 +1008,8 @@ int32_t ComponentManager::DisableSink(const DHDescriptor &dhDescriptor, int32_t int32_t ComponentManager::EnableSource(const std::string &networkId, const DHDescriptor &dhDescriptor, int32_t callingUid, int32_t callingPid) { + DHLOGI("Begin enable source, networkId: %{public}s, dhType: %{public}#X.", + GetAnonyString(networkId).c_str(), dhDescriptor.dhType); sptr listener; int32_t ret = EnableSourceInternal(networkId, dhDescriptor, callingUid, callingPid, listener); if (ret == DH_FWK_SUCCESS) { @@ -1016,12 +1018,16 @@ int32_t ComponentManager::EnableSource(const std::string &networkId, DHLOGI("Callback business source OnEnable."); } } + DHLOGI("End enable source, networkId: %{public}s, dhType: %{public}#X.", + GetAnonyString(networkId).c_str(), dhDescriptor.dhType); return ret; } int32_t ComponentManager::DisableSource(const std::string &networkId, const DHDescriptor &dhDescriptor, int32_t callingUid, int32_t callingPid) { + DHLOGI("Begin disable source, networkId: %{public}s, dhType: %{public}#X.", + GetAnonyString(networkId).c_str(), dhDescriptor.dhType); sptr listener; int32_t ret = DisableSourceInternal(networkId, dhDescriptor, callingUid, callingPid, listener); if (ret == DH_FWK_SUCCESS) { @@ -1030,6 +1036,8 @@ int32_t ComponentManager::DisableSource(const std::string &networkId, DHLOGI("Callback business source OnDisable."); } } + DHLOGI("End disable source, networkId: %{public}s, dhType: %{public}#X.", + GetAnonyString(networkId).c_str(), dhDescriptor.dhType); return ret; } @@ -1059,24 +1067,14 @@ int32_t ComponentManager::ForceDisableSource(const std::string &networkId, const return ret; } -int32_t ComponentManager::CheckIdenticalAccount(const std::string &networkId, - const std::string &uuid, const DHDescriptor &dhDescriptor) +int32_t ComponentManager::CheckIdenticalAccount(const std::string &networkId) { - EnableParam param; - auto ret = GetEnableParam(networkId, uuid, dhDescriptor.id, dhDescriptor.dhType, param); - if (ret != DH_FWK_SUCCESS) { - 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; - } - } - ret = CheckSubtypeResource(param.subtype, networkId); - if (ret != DH_FWK_SUCCESS) { - DHLOGE("CheckSubtypeResource failed, ret = %{public}d.", ret); - return ret; +#ifdef DHARDWARE_CHECK_RESOURCE + if (!IsIdenticalAccount(networkId)) { + DHLOGE("Enable resources must be logged in with the same account."); + return ERR_DH_FWK_COMPONENT_ENABLE_FAILED; } +#endif return DH_FWK_SUCCESS; } diff --git a/services/distributedhardwarefwkservice/src/task/offline_task.cpp b/services/distributedhardwarefwkservice/src/task/offline_task.cpp index 5b9c0c90..105966ea 100644 --- a/services/distributedhardwarefwkservice/src/task/offline_task.cpp +++ b/services/distributedhardwarefwkservice/src/task/offline_task.cpp @@ -22,6 +22,7 @@ #include "anonymous_string.h" #include "capability_info_manager.h" +#include "component_manager.h" #include "constants.h" #include "device_manager.h" #include "dh_context.h" @@ -108,6 +109,10 @@ void OffLineTask::CreateDisableTask() { DHLOGI("networkId = %{public}s, uuid = %{public}s", GetAnonyString(GetNetworkId()).c_str(), GetAnonyString(GetUUID()).c_str()); + if (ComponentManager::GetInstance().CheckIdenticalAccount(GetNetworkId()) != DH_FWK_SUCCESS) { + DHLOGE("Check identical account failed, networkId: %{public}s.", GetAnonyString(GetNetworkId()).c_str()); + return; + } std::string deviceId = GetDeviceIdByUUID(GetUUID()); std::vector> devDhInfos; std::vector> capabilityInfos; diff --git a/services/distributedhardwarefwkservice/src/task/online_task.cpp b/services/distributedhardwarefwkservice/src/task/online_task.cpp index e044b817..5cf51bf5 100644 --- a/services/distributedhardwarefwkservice/src/task/online_task.cpp +++ b/services/distributedhardwarefwkservice/src/task/online_task.cpp @@ -17,6 +17,7 @@ #include "anonymous_string.h" #include "capability_info_manager.h" +#include "component_manager.h" #include "device_manager.h" #include "dh_utils_tool.h" #include "distributed_hardware_errno.h" @@ -105,6 +106,10 @@ void OnLineTask::CreateEnableTask() { DHLOGI("CreateEnableTask, networkId: %{public}s, uuid: %{public}s, udid: %{public}s", GetAnonyString(GetNetworkId()).c_str(), GetAnonyString(GetUUID()).c_str(), GetAnonyString(GetUDID()).c_str()); + if (ComponentManager::GetInstance().CheckIdenticalAccount(GetNetworkId()) != DH_FWK_SUCCESS) { + DHLOGE("Check identical account failed, networkId: %{public}s.", GetAnonyString(GetNetworkId()).c_str()); + return; + } std::string deviceId = GetDeviceIdByUUID(GetUUID()); std::vector> devDhInfos; std::vector> capabilityInfos; -- Gitee