From 248e39006f0398ae9164dfab7f0e1c91d6b235e0 Mon Sep 17 00:00:00 2001 From: wanderer-dl122 Date: Fri, 6 May 2022 17:38:06 +0800 Subject: [PATCH 1/4] anonymize string Signed-off-by: wanderer-dl122 --- .../src/accessmanager/access_manager.cpp | 4 ++-- .../componentmanager/component_disable.cpp | 14 ++++++----- .../src/componentmanager/component_enable.cpp | 14 ++++++----- .../componentmanager/component_manager.cpp | 24 +++++++++++-------- .../src/task/disable_task.cpp | 5 ++-- .../src/task/enable_task.cpp | 5 ++-- 6 files changed, 38 insertions(+), 28 deletions(-) diff --git a/services/distributedhardwarefwkservice/src/accessmanager/access_manager.cpp b/services/distributedhardwarefwkservice/src/accessmanager/access_manager.cpp index 36e170d1..51fd624d 100644 --- a/services/distributedhardwarefwkservice/src/accessmanager/access_manager.cpp +++ b/services/distributedhardwarefwkservice/src/accessmanager/access_manager.cpp @@ -118,7 +118,7 @@ void AccessManager::OnDeviceOnline(const DmDeviceInfo &deviceInfo) { std::lock_guard lock(accessMutex_); DHLOGI("start, networkId = %s, deviceName = %s, deviceTypeId = %d", GetAnonyString(deviceInfo.deviceId).c_str(), - deviceInfo.deviceName, deviceInfo.deviceTypeId); + GetAnonyString(deviceInfo.deviceName).c_str(), deviceInfo.deviceTypeId); auto networkId = std::string(deviceInfo.deviceId); // deviceId of DM actually is networkId auto uuid = GetUUIDBySoftBus(networkId); @@ -132,7 +132,7 @@ void AccessManager::OnDeviceOffline(const DmDeviceInfo &deviceInfo) { std::lock_guard lock(accessMutex_); DHLOGI("start, networkId = %s, deviceName = %s, deviceTypeId = %d", GetAnonyString(deviceInfo.deviceId).c_str(), - deviceInfo.deviceName, deviceInfo.deviceTypeId); + GetAnonyString(deviceInfo.deviceName).c_str(), deviceInfo.deviceTypeId); auto networkId = std::string(deviceInfo.deviceId); // deviceId of DM actually is networkId auto uuid = GetUUIDBySoftBus(networkId); diff --git a/services/distributedhardwarefwkserviceimpl/src/componentmanager/component_disable.cpp b/services/distributedhardwarefwkserviceimpl/src/componentmanager/component_disable.cpp index 9c53fab5..4d1dadd5 100644 --- a/services/distributedhardwarefwkserviceimpl/src/componentmanager/component_disable.cpp +++ b/services/distributedhardwarefwkserviceimpl/src/componentmanager/component_disable.cpp @@ -32,16 +32,17 @@ ComponentDisable::~ComponentDisable() {} int32_t ComponentDisable::Disable(const std::string &networkId, const std::string &dhId, IDistributedHardwareSource *handler) { - DHLOGD("networkId = %s dhId = %s.", GetAnonyString(networkId).c_str(), dhId.c_str()); + DHLOGD("networkId = %s dhId = %s.", GetAnonyString(networkId).c_str(), GetAnonyString(dhId).c_str()); if (handler == nullptr) { - DHLOGE("handler is null, networkId = %s dhId = %s.", GetAnonyString(networkId).c_str(), dhId.c_str()); + DHLOGE("handler is null, networkId = %s dhId = %s.",GetAnonyString(networkId).c_str(), + GetAnonyString(dhId).c_str()); return ERR_DH_FWK_PARA_INVALID; } auto ret = handler->UnregisterDistributedHardware(networkId, dhId, shared_from_this()); if (ret != DH_FWK_SUCCESS) { DHLOGE("UnregisterDistributedHardware failed, networkId = %s dhId = %s.", GetAnonyString(networkId).c_str(), - dhId.c_str()); + GetAnonyString(dhId).c_str()); return ERR_DH_FWK_COMPONENT_UNREGISTER_FAILED; } @@ -50,7 +51,8 @@ int32_t ComponentDisable::Disable(const std::string &networkId, const std::strin auto waitStatus = conVar_.wait_for(lock, std::chrono::milliseconds(DISABLE_TIMEOUT_MS), [this]() { return status_ != std::numeric_limits::max(); }); if (!waitStatus) { - DHLOGE("disable timeout, networkId = %s dhId = %s.", GetAnonyString(networkId).c_str(), dhId.c_str()); + DHLOGE("disable timeout, networkId = %s dhId = %s.", GetAnonyString(networkId).c_str(), + GetAnonyString(dhId).c_str()); return ERR_DH_FWK_COMPONENT_DISABLE_TIMEOUT; } return (status_ == DH_FWK_SUCCESS) ? DH_FWK_SUCCESS : ERR_DH_FWK_COMPONENT_DISABLE_FAILED; @@ -61,10 +63,10 @@ int32_t ComponentDisable::OnUnregisterResult(const std::string &networkId, const { if (status == DH_FWK_SUCCESS) { DHLOGI("disable success, networkId = %s, dhId = %s, data = %s.", GetAnonyString(networkId).c_str(), - dhId.c_str(), data.c_str()); + GetAnonyString(dhId).c_str(), data.c_str()); } else { DHLOGE("disable failed, networkId = %s, dhId = %s, status = %d, data = %s.", GetAnonyString(networkId).c_str(), - dhId.c_str(), status, data.c_str()); + GetAnonyString(dhId).c_str(), status, data.c_str()); } std::unique_lock lock(mutex_); diff --git a/services/distributedhardwarefwkserviceimpl/src/componentmanager/component_enable.cpp b/services/distributedhardwarefwkserviceimpl/src/componentmanager/component_enable.cpp index c5a3b433..ebbf1cbc 100644 --- a/services/distributedhardwarefwkserviceimpl/src/componentmanager/component_enable.cpp +++ b/services/distributedhardwarefwkserviceimpl/src/componentmanager/component_enable.cpp @@ -32,16 +32,17 @@ ComponentEnable::~ComponentEnable() {} int32_t ComponentEnable::Enable(const std::string &networkId, const std::string &dhId, const EnableParam ¶m, IDistributedHardwareSource *handler) { - DHLOGD("networkId = %s dhId = %s.", GetAnonyString(networkId).c_str(), dhId.c_str()); + DHLOGD("networkId = %s dhId = %s.", GetAnonyString(networkId).c_str(), GetAnonyString(dhId).c_str()); if (handler == nullptr) { - DHLOGE("handler is null, networkId = %s dhId = %s.", GetAnonyString(networkId).c_str(), dhId.c_str()); + DHLOGE("handler is null, networkId = %s dhId = %s.", GetAnonyString(networkId).c_str(), + GetAnonyString(dhId).c_str()); return ERR_DH_FWK_PARA_INVALID; } auto ret = handler->RegisterDistributedHardware(networkId, dhId, param, shared_from_this()); if (ret != DH_FWK_SUCCESS) { DHLOGE("RegisterDistributedHardware failed, networkId = %s dhId = %s.", GetAnonyString(networkId).c_str(), - dhId.c_str()); + GetAnonyString(dhId).c_str()); return ERR_DH_FWK_COMPONENT_REGISTER_FAILED; } @@ -50,7 +51,8 @@ int32_t ComponentEnable::Enable(const std::string &networkId, const std::string auto waitStatus = conVar_.wait_for(lock, std::chrono::milliseconds(ENABLE_TIMEOUT_MS), [this]() { return status_ != std::numeric_limits::max(); }); if (!waitStatus) { - DHLOGE("enable timeout, networkId = %s dhId = %s", GetAnonyString(networkId).c_str(), dhId.c_str()); + DHLOGE("enable timeout, networkId = %s dhId = %s", GetAnonyString(networkId).c_str(), + GetAnonyString(dhId).c_str()); return ERR_DH_FWK_COMPONENT_ENABLE_TIMEOUT; } return (status_ == DH_FWK_SUCCESS) ? DH_FWK_SUCCESS : ERR_DH_FWK_COMPONENT_ENABLE_FAILED; @@ -61,10 +63,10 @@ int32_t ComponentEnable::OnRegisterResult(const std::string &networkId, const st { if (status == DH_FWK_SUCCESS) { DHLOGI("enable success, networkId = %s, dhId = %s, data = %s.", GetAnonyString(networkId).c_str(), - dhId.c_str(), data.c_str()); + GetAnonyString(dhId).c_str(), data.c_str()); } else { DHLOGE("enable failed, networkId = %s, dhId = %s, status = %d, data = %s.", GetAnonyString(networkId).c_str(), - dhId.c_str(), status, data.c_str()); + GetAnonyString(dhId).c_str(), status, data.c_str()); } std::unique_lock lock(mutex_); diff --git a/services/distributedhardwarefwkserviceimpl/src/componentmanager/component_manager.cpp b/services/distributedhardwarefwkserviceimpl/src/componentmanager/component_manager.cpp index a844dc3d..b07d364a 100644 --- a/services/distributedhardwarefwkserviceimpl/src/componentmanager/component_manager.cpp +++ b/services/distributedhardwarefwkserviceimpl/src/componentmanager/component_manager.cpp @@ -225,14 +225,14 @@ int32_t ComponentManager::Enable(const std::string &networkId, const std::string DHLOGI("start."); auto find = compSource_.find(dhType); if (find == compSource_.end()) { - DHLOGE("can not find handler for dhId = %s.", dhId.c_str()); + DHLOGE("can not find handler for dhId = %s.", GetAnonyString(dhId).c_str()); return ERR_DH_FWK_PARA_INVALID; } EnableParam param; auto ret = GetEnableParam(networkId, uuid, dhId, dhType, param); if (ret != DH_FWK_SUCCESS) { DHLOGE("GetEnableParam failed, uuid = %s, dhId = %s, errCode = %d", GetAnonyString(uuid).c_str(), - dhId.c_str(), ret); + GetAnonyString(dhId).c_str(), ret); for (int32_t retryCount = 0; retryCount < ENABLE_RETRY_MAX_TIMES; retryCount++) { if (!DHContext::GetInstance().IsDeviceOnline(uuid)) { DHLOGE("device is already offline, no need try GetEnableParam, uuid = %s", @@ -263,7 +263,8 @@ int32_t ComponentManager::Enable(const std::string &networkId, const std::string } return result; } - DHLOGI("enable result is %d, uuid = %s, dhId = %s", result, GetAnonyString(uuid).c_str(), dhId.c_str()); + DHLOGI("enable result is %d, uuid = %s, dhId = %s", result, GetAnonyString(uuid).c_str(), + GetAnonyString(dhId).c_str()); return result; } @@ -291,7 +292,8 @@ int32_t ComponentManager::Disable(const std::string &networkId, const std::strin } return result; } - DHLOGI("disable result is %d, uuid = %s, dhId = %s", result, GetAnonyString(uuid).c_str(), dhId.c_str()); + DHLOGI("disable result is %d, uuid = %s, dhId = %s", result, GetAnonyString(uuid).c_str(), + GetAnonyString(dhId).c_str()); return result; } @@ -302,7 +304,8 @@ DHType ComponentManager::GetDHType(const std::string &uuid, const std::string &d if ((ret == DH_FWK_SUCCESS) && (capability != nullptr)) { return capability->GetDHType(); } - DHLOGE("get dhType failed, uuid = %s, dhId = %s", GetAnonyString(uuid).c_str(), dhId.c_str()); + DHLOGE("get dhType failed, uuid = %s, dhId = %s", GetAnonyString(uuid).c_str(), + GetAnonyString(dhId).c_str()); return DHType::UNKNOWN; } @@ -312,20 +315,21 @@ int32_t ComponentManager::GetEnableParam(const std::string &networkId, const std std::shared_ptr capability = nullptr; auto ret = CapabilityInfoManager::GetInstance()->GetCapability(GetDeviceIdByUUID(uuid), dhId, capability); if ((ret != DH_FWK_SUCCESS) || (capability == nullptr)) { - DHLOGE("GetCapability failed, uuid =%s, dhId = %s, errCode = %d", GetAnonyString(uuid).c_str(), dhId.c_str(), - ret); + DHLOGE("GetCapability failed, uuid =%s, dhId = %s, errCode = %d", GetAnonyString(uuid).c_str(), + GetAnonyString(dhId).c_str(), ret); return ret; } param.attrs = capability->GetDHAttrs(); param.version = GetSinkVersion(networkId, uuid, dhType); if (param.version.empty()) { - DHLOGI("Get Sink Version failed, uuid = %s, dhId = %s", GetAnonyString(uuid).c_str(), dhId.c_str()); + DHLOGI("Get Sink Version failed, uuid = %s, dhId = %s", GetAnonyString(uuid).c_str(), + GetAnonyString(dhId).c_str()); return ERR_DH_FWK_COMPONENT_GET_SINK_VERSION_FAILED; } - DHLOGI("success. uuid =%s, dhId = %s, version = %s", GetAnonyString(uuid).c_str(), dhId.c_str(), - param.version.c_str()); + DHLOGI("success. uuid =%s, dhId = %s, version = %s", GetAnonyString(uuid).c_str(), + GetAnonyString(dhId).c_str(), param.version.c_str()); return DH_FWK_SUCCESS; } diff --git a/services/distributedhardwarefwkserviceimpl/src/task/disable_task.cpp b/services/distributedhardwarefwkserviceimpl/src/task/disable_task.cpp index 4fcf43b1..ceb1d514 100644 --- a/services/distributedhardwarefwkserviceimpl/src/task/disable_task.cpp +++ b/services/distributedhardwarefwkserviceimpl/src/task/disable_task.cpp @@ -47,7 +47,8 @@ void DisableTask::DoTask() void DisableTask::DoTaskInner() { - DHLOGD("id = %s, uuid = %s, dhId = %s", GetId().c_str(), GetAnonyString(GetUUID()).c_str(), GetDhId().c_str()); + DHLOGD("id = %s, uuid = %s, dhId = %s", GetId().c_str(), GetAnonyString(GetUUID()).c_str(), + GetAnonyString(GetDhId()).c_str()); SetTaskState(TaskState::RUNNING); /* trigger Unregister Distributed Hardware Task, sync function */ @@ -69,7 +70,7 @@ int32_t DisableTask::UnRegisterHardware() { auto result = ComponentManager::GetInstance().Disable(GetNetworkId(), GetUUID(), GetDhId(), GetDhType()); DHLOGI("disable task %s, id = %s, uuid = %s, dhId = %s", (result == DH_FWK_SUCCESS) ? "success" : "failed", - GetId().c_str(), GetAnonyString(GetUUID()).c_str(), GetDhId().c_str()); + GetId().c_str(), GetAnonyString(GetUUID()).c_str(), GetAnonyString(GetDhId()).c_str()); return result; } } // namespace DistributedHardware diff --git a/services/distributedhardwarefwkserviceimpl/src/task/enable_task.cpp b/services/distributedhardwarefwkserviceimpl/src/task/enable_task.cpp index fbc4c3ae..d1e89f43 100644 --- a/services/distributedhardwarefwkserviceimpl/src/task/enable_task.cpp +++ b/services/distributedhardwarefwkserviceimpl/src/task/enable_task.cpp @@ -46,7 +46,8 @@ void EnableTask::DoTask() void EnableTask::DoTaskInner() { - DHLOGD("id = %s, uuid = %s, dhId = %s", GetId().c_str(), GetAnonyString(GetUUID()).c_str(), GetDhId().c_str()); + DHLOGD("id = %s, uuid = %s, dhId = %s", GetId().c_str(), GetAnonyString(GetUUID()).c_str(), + GetAnonyString(GetDhId()).c_str()); SetTaskState(TaskState::RUNNING); auto result = RegisterHardware(); auto state = (result == DH_FWK_SUCCESS) ? TaskState::SUCCESS : TaskState::FAIL; @@ -59,7 +60,7 @@ int32_t EnableTask::RegisterHardware() { auto result = ComponentManager::GetInstance().Enable(GetNetworkId(), GetUUID(), GetDhId(), GetDhType()); DHLOGI("enable task %s, id = %s, uuid = %s, dhId = %s", (result == DH_FWK_SUCCESS) ? "success" : "failed", - GetId().c_str(), GetAnonyString(GetUUID()).c_str(), GetDhId().c_str()); + GetId().c_str(), GetAnonyString(GetUUID()).c_str(), GetAnonyString(GetDhId()).c_str()); return result; } } // namespace DistributedHardware -- Gitee From 7ebe129ccd0c75d09ea1bb7834f37e2bbf5d84ec Mon Sep 17 00:00:00 2001 From: wanderer-dl122 Date: Fri, 6 May 2022 17:51:14 +0800 Subject: [PATCH 2/4] anonymize string Signed-off-by: wanderer-dl122 --- .../src/componentmanager/component_disable.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/services/distributedhardwarefwkserviceimpl/src/componentmanager/component_disable.cpp b/services/distributedhardwarefwkserviceimpl/src/componentmanager/component_disable.cpp index 4d1dadd5..9cb2c82e 100644 --- a/services/distributedhardwarefwkserviceimpl/src/componentmanager/component_disable.cpp +++ b/services/distributedhardwarefwkserviceimpl/src/componentmanager/component_disable.cpp @@ -34,7 +34,7 @@ int32_t ComponentDisable::Disable(const std::string &networkId, const std::strin { DHLOGD("networkId = %s dhId = %s.", GetAnonyString(networkId).c_str(), GetAnonyString(dhId).c_str()); if (handler == nullptr) { - DHLOGE("handler is null, networkId = %s dhId = %s.",GetAnonyString(networkId).c_str(), + DHLOGE("handler is null, networkId = %s dhId = %s.", GetAnonyString(networkId).c_str(), GetAnonyString(dhId).c_str()); return ERR_DH_FWK_PARA_INVALID; } -- Gitee From 11252b2e47403bf063c7c59cd26db72d8f38715a Mon Sep 17 00:00:00 2001 From: wanderer-dl122 Date: Sat, 7 May 2022 15:16:22 +0800 Subject: [PATCH 3/4] anonymize string Signed-off-by: wanderer-dl122 --- .../src/task/task_factory.cpp | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/services/distributedhardwarefwkserviceimpl/src/task/task_factory.cpp b/services/distributedhardwarefwkserviceimpl/src/task/task_factory.cpp index 838b7281..edbe9417 100644 --- a/services/distributedhardwarefwkserviceimpl/src/task/task_factory.cpp +++ b/services/distributedhardwarefwkserviceimpl/src/task/task_factory.cpp @@ -31,8 +31,9 @@ namespace DistributedHardware { IMPLEMENT_SINGLE_INSTANCE(TaskFactory); std::shared_ptr TaskFactory::CreateTask(TaskType taskType, TaskParam taskParam, std::shared_ptr fatherTask) { - DHLOGI("taskType = %d, networkId = %s, uuid = %s, dhId = %s", static_cast(taskType), - GetAnonyString(taskParam.networkId).c_str(), GetAnonyString(taskParam.uuid).c_str(), taskParam.dhId.c_str()); + DHLOGI("taskType = %d, networkId = %s, uuid = %s, dhId = %s", + static_cast(taskType), GetAnonyString(taskParam.networkId).c_str(), + GetAnonyString(taskParam.uuid).c_str(), GetAnonyString(taskParam.dhId).c_str()); std::shared_ptr task = nullptr; switch (taskType) { case TaskType::ENABLE: { -- Gitee From 7eea822b25d8df9f1a7b026317e29f2e3e787b9e Mon Sep 17 00:00:00 2001 From: wanderer-dl122 Date: Sat, 7 May 2022 15:24:59 +0800 Subject: [PATCH 4/4] anonymize string Signed-off-by: wanderer-dl122 --- .../distributedhardwarefwkserviceimpl/src/task/task_factory.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/services/distributedhardwarefwkserviceimpl/src/task/task_factory.cpp b/services/distributedhardwarefwkserviceimpl/src/task/task_factory.cpp index edbe9417..9886365a 100644 --- a/services/distributedhardwarefwkserviceimpl/src/task/task_factory.cpp +++ b/services/distributedhardwarefwkserviceimpl/src/task/task_factory.cpp @@ -33,7 +33,7 @@ std::shared_ptr TaskFactory::CreateTask(TaskType taskType, TaskParam taskP { DHLOGI("taskType = %d, networkId = %s, uuid = %s, dhId = %s", static_cast(taskType), GetAnonyString(taskParam.networkId).c_str(), - GetAnonyString(taskParam.uuid).c_str(), GetAnonyString(taskParam.dhId).c_str()); + GetAnonyString(taskParam.uuid).c_str(), GetAnonyString(taskParam.dhId).c_str()); std::shared_ptr task = nullptr; switch (taskType) { case TaskType::ENABLE: { -- Gitee