From e96ae11abb129ab6357c68ec36e805669f7d053c Mon Sep 17 00:00:00 2001 From: saga Date: Mon, 27 May 2024 15:13:01 +0800 Subject: [PATCH 01/10] When device info changed, DH need re-enabled Signed-off-by: saga --- .../include/distributed_hardware_errno.h | 1 + .../include/idistributed_hardware_manager.h | 2 + .../distributedhardwarefwkservice/BUILD.gn | 1 + .../componentmanager/component_manager.h | 2 +- .../include/distributed_hardware_manager.h | 1 + .../distributed_hardware_manager_factory.h | 1 + .../include/task/device_changed_task.h | 35 +++++ .../include/utils/impl_utils.h | 6 +- .../src/accessmanager/access_manager.cpp | 21 ++- .../src/distributed_hardware_manager.cpp | 24 ++++ .../distributed_hardware_manager_factory.cpp | 28 ++++ .../src/task/device_changed_task.cpp | 128 ++++++++++++++++++ .../src/task/task_factory.cpp | 5 + 13 files changed, 250 insertions(+), 5 deletions(-) create mode 100644 services/distributedhardwarefwkservice/include/task/device_changed_task.h create mode 100644 services/distributedhardwarefwkservice/src/task/device_changed_task.cpp diff --git a/common/utils/include/distributed_hardware_errno.h b/common/utils/include/distributed_hardware_errno.h index 998aba9e..febf17d6 100644 --- a/common/utils/include/distributed_hardware_errno.h +++ b/common/utils/include/distributed_hardware_errno.h @@ -73,6 +73,7 @@ namespace DistributedHardware { constexpr int32_t ERR_DH_FWK_HARDWARE_MANAGER_DEVICE_REPEAT_ONLINE = -10500; constexpr int32_t ERR_DH_FWK_HARDWARE_MANAGER_DEVICE_REPEAT_OFFLINE = -10501; constexpr int32_t ERR_DH_FWK_HARDWARE_MANAGER_INIT_FAILED = -10502; + constexpr int32_t ERR_DH_FWK_HARDWARE_MANAGER_DEVICE_NOT_ONLINE = -10503; /* ComponentLoader errno, range: [-10600, -10699] */ constexpr int32_t ERR_DH_FWK_LOADER_HANDLER_IS_NULL = -10600; diff --git a/common/utils/include/idistributed_hardware_manager.h b/common/utils/include/idistributed_hardware_manager.h index dc2cf894..93553745 100644 --- a/common/utils/include/idistributed_hardware_manager.h +++ b/common/utils/include/idistributed_hardware_manager.h @@ -32,6 +32,8 @@ public: uint16_t deviceType) = 0; virtual int32_t SendOffLineEvent(const std::string &networkId, const std::string &uuid, uint16_t deviceType) = 0; + virtual int32_t SendDeviceChangedEvent(const std::string &networkId, const std::string &uuid, + uint16_t deviceType) = 0; virtual size_t GetOnLineCount() = 0; virtual int32_t GetComponentVersion(std::unordered_map &versionMap) = 0; virtual int32_t Dump(const std::vector &argsStr, std::string &result) = 0; diff --git a/services/distributedhardwarefwkservice/BUILD.gn b/services/distributedhardwarefwkservice/BUILD.gn index e516c6ec..08e875e7 100644 --- a/services/distributedhardwarefwkservice/BUILD.gn +++ b/services/distributedhardwarefwkservice/BUILD.gn @@ -97,6 +97,7 @@ ohos_shared_library("distributedhardwarefwksvr") { "src/task/enable_task.cpp", "src/task/offline_task.cpp", "src/task/online_task.cpp", + "src/task/device_changed_task.cpp", "src/task/task.cpp", "src/task/task_board.cpp", "src/task/task_executor.cpp", diff --git a/services/distributedhardwarefwkservice/include/componentmanager/component_manager.h b/services/distributedhardwarefwkservice/include/componentmanager/component_manager.h index cdb9e2b9..c58ec056 100644 --- a/services/distributedhardwarefwkservice/include/componentmanager/component_manager.h +++ b/services/distributedhardwarefwkservice/include/componentmanager/component_manager.h @@ -76,7 +76,7 @@ public: * @return false if the task param not exist, return false. */ bool FetchNeedRefreshTask(const std::pair &taskKey, TaskParam &taskParam); - + bool IsIdenticalAccount(const std::string &networkId); class ComponentManagerEventHandler : public AppExecFwk::EventHandler { public: ComponentManagerEventHandler(const std::shared_ptr &runner); diff --git a/services/distributedhardwarefwkservice/include/distributed_hardware_manager.h b/services/distributedhardwarefwkservice/include/distributed_hardware_manager.h index 97ce0f0a..601e8078 100644 --- a/services/distributedhardwarefwkservice/include/distributed_hardware_manager.h +++ b/services/distributedhardwarefwkservice/include/distributed_hardware_manager.h @@ -32,6 +32,7 @@ public: int32_t Release() override; int32_t SendOnLineEvent(const std::string &networkId, const std::string &uuid, uint16_t deviceType) override; int32_t SendOffLineEvent(const std::string &networkId, const std::string &uuid, uint16_t deviceType) override; + int32_t SendDeviceChangedEvent(const std::string &networkId, const std::string &uuid, uint16_t deviceType) override; size_t GetOnLineCount() override; int32_t GetComponentVersion(std::unordered_map &versionMap) override; diff --git a/services/distributedhardwarefwkservice/include/distributed_hardware_manager_factory.h b/services/distributedhardwarefwkservice/include/distributed_hardware_manager_factory.h index d249dbc8..9cc616a1 100644 --- a/services/distributedhardwarefwkservice/include/distributed_hardware_manager_factory.h +++ b/services/distributedhardwarefwkservice/include/distributed_hardware_manager_factory.h @@ -33,6 +33,7 @@ public: bool IsInit(); int32_t SendOnLineEvent(const std::string &networkId, const std::string &uuid, uint16_t deviceType); int32_t SendOffLineEvent(const std::string &networkId, const std::string &uuid, uint16_t deviceType); + int32_t SendDeviceChangedEvent(const std::string &networkId, const std::string &uuid, uint16_t deviceType); int32_t GetComponentVersion(std::unordered_map &versionMap); int Dump(const std::vector &argsStr, std::string &result); diff --git a/services/distributedhardwarefwkservice/include/task/device_changed_task.h b/services/distributedhardwarefwkservice/include/task/device_changed_task.h new file mode 100644 index 00000000..bd86723c --- /dev/null +++ b/services/distributedhardwarefwkservice/include/task/device_changed_task.h @@ -0,0 +1,35 @@ +/* + * Copyright (c) 2021 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 + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef OHOS_DISTRIBUTED_HARDWARE_DEVICE_CHANGED_TASK_H +#define OHOS_DISTRIBUTED_HARDWARE_DEVICE_CHANGED_TASK_H + +#include "task.h" + +namespace OHOS { +namespace DistributedHardware { +class DeviceChangedTask : public Task { +public: + DeviceChangedTask() = delete; + DeviceChangedTask(const std::string &networkId, const std::string &uuid, const std::string &dhId, const DHType dhType); + virtual ~DeviceChangedTask(); + virtual void DoTask(); + +private: + void HandleDeviceChanged(); +}; +} // namespace DistributedHardware +} // namespace OHOS +#endif \ No newline at end of file diff --git a/services/distributedhardwarefwkservice/include/utils/impl_utils.h b/services/distributedhardwarefwkservice/include/utils/impl_utils.h index f47aff56..6b792119 100644 --- a/services/distributedhardwarefwkservice/include/utils/impl_utils.h +++ b/services/distributedhardwarefwkservice/include/utils/impl_utils.h @@ -28,7 +28,8 @@ enum class TaskType : int32_t { ENABLE = 1, DISABLE = 2, ON_LINE = 3, - OFF_LINE = 4 + OFF_LINE = 4, + DEVICE_CHANGED = 5 }; enum class TaskStep : int32_t { @@ -38,7 +39,8 @@ enum class TaskStep : int32_t { REGISTER_ONLINE_DISTRIBUTED_HARDWARE = 4, UNREGISTER_OFFLINE_DISTRIBUTED_HARDWARE = 5, CLEAR_OFFLINE_INFO = 6, - WAIT_UNREGISTGER_COMPLETE = 7 + WAIT_UNREGISTGER_COMPLETE = 7, + DO_DEVICE_CHANGED = 8 }; enum class TaskState : int32_t { diff --git a/services/distributedhardwarefwkservice/src/accessmanager/access_manager.cpp b/services/distributedhardwarefwkservice/src/accessmanager/access_manager.cpp index 94c20417..f10b8fa3 100644 --- a/services/distributedhardwarefwkservice/src/accessmanager/access_manager.cpp +++ b/services/distributedhardwarefwkservice/src/accessmanager/access_manager.cpp @@ -175,8 +175,25 @@ void AccessManager::OnDeviceReady(const DmDeviceInfo &deviceInfo) void AccessManager::OnDeviceChanged(const DmDeviceInfo &deviceInfo) { - (void)deviceInfo; - return; + std::lock_guard lock(accessMutex_); + DHLOGI("start, networkId = %{public}s, deviceName = %{public}s", + GetAnonyString(deviceInfo.networkId).c_str(), GetAnonyString(deviceInfo.deviceName).c_str()); + + auto networkId = std::string(deviceInfo.networkId); + if (networkId.size() == 0 || networkId.size() > MAX_ID_LEN) { + DHLOGE("NetworkId is invalid!"); + return; + } + auto uuid = GetUUIDBySoftBus(networkId); + if (uuid.size() == 0 || uuid.size() > MAX_ID_LEN) { + DHLOGE("Uuid is invalid!"); + return; + } + + auto ret = + DistributedHardwareManagerFactory::GetInstance().SendDeviceChangedEvent(networkId, uuid, deviceInfo.deviceTypeId); + DHLOGI("device changed result = %{public}d, networkId = %{public}s, uuid = %{public}s", ret, + GetAnonyString(networkId).c_str(), GetAnonyString(uuid).c_str()); } void AccessManager::CheckTrustedDeviceOnline() diff --git a/services/distributedhardwarefwkservice/src/distributed_hardware_manager.cpp b/services/distributedhardwarefwkservice/src/distributed_hardware_manager.cpp index ee3f702b..13c4e190 100644 --- a/services/distributedhardwarefwkservice/src/distributed_hardware_manager.cpp +++ b/services/distributedhardwarefwkservice/src/distributed_hardware_manager.cpp @@ -146,6 +146,30 @@ int32_t DistributedHardwareManager::SendOffLineEvent(const std::string &networkI return DH_FWK_SUCCESS; } +int32_t DistributedHardwareManager::SendDeviceChangedEvent(const std::string &networkId, const std::string &uuid, + uint16_t deviceType) +{ + (void)deviceType; + + if (networkId.size() == 0 || networkId.size() > MAX_ID_LEN || uuid.size() == 0 || uuid.size() > MAX_ID_LEN) { + DHLOGE("NetworkId or uuid is invalid"); + return ERR_DH_FWK_PARA_INVALID; + } + + DHLOGI("networkId = %{public}s, uuid = %{public}s", GetAnonyString(networkId).c_str(), + GetAnonyString(uuid).c_str()); + + TaskParam taskParam = { + .networkId = networkId, + .uuid = uuid, + .dhId = "", + .dhType = DHType::UNKNOWN + }; + auto task = TaskFactory::GetInstance().CreateTask(TaskType::DEVICE_CHANGED, taskParam, nullptr); + TaskExecutor::GetInstance().PushTask(task); + return DH_FWK_SUCCESS; +} + size_t DistributedHardwareManager::GetOnLineCount() { return DHContext::GetInstance().GetOnlineCount(); diff --git a/services/distributedhardwarefwkservice/src/distributed_hardware_manager_factory.cpp b/services/distributedhardwarefwkservice/src/distributed_hardware_manager_factory.cpp index 6da58efc..17e65851 100644 --- a/services/distributedhardwarefwkservice/src/distributed_hardware_manager_factory.cpp +++ b/services/distributedhardwarefwkservice/src/distributed_hardware_manager_factory.cpp @@ -205,6 +205,34 @@ int32_t DistributedHardwareManagerFactory::SendOffLineEvent(const std::string &n return DH_FWK_SUCCESS; } +int32_t DistributedHardwareManagerFactory::SendDeviceChangedEvent(const std::string &networkId, const std::string &uuid, + uint16_t deviceType) +{ + if (networkId.empty() || networkId.size() > MAX_ID_LEN || uuid.empty() || uuid.size() > MAX_ID_LEN) { + DHLOGE("NetworkId or uuid is invalid"); + return ERR_DH_FWK_PARA_INVALID; + } + + if (!isInit) { + DHLOGI("distributedHardwareMgr is null"); + return ERR_DH_FWK_HARDWARE_MANAGER_DEVICE_NOT_ONLINE; + } + //if device not online, no need to handle device change event + if (!DHContext::GetInstance().IsDeviceOnline(uuid)) { + DHLOGI("Device not online, networkId: %{public}s, uuid: %{public}s", + GetAnonyString(networkId).c_str(), GetAnonyString(uuid).c_str()); + return ERR_DH_FWK_HARDWARE_MANAGER_DEVICE_NOT_ONLINE; + } + + auto result = DistributedHardwareManager::GetInstance().SendDeviceChangedEvent(networkId, uuid, deviceType); + if (result != DH_FWK_SUCCESS) { + DHLOGE("offline failed, errCode = %{public}d", result); + return result; + } + + return DH_FWK_SUCCESS; +} + int32_t DistributedHardwareManagerFactory::GetComponentVersion(std::unordered_map &versionMap) { DHLOGI("start"); diff --git a/services/distributedhardwarefwkservice/src/task/device_changed_task.cpp b/services/distributedhardwarefwkservice/src/task/device_changed_task.cpp new file mode 100644 index 00000000..a90995b5 --- /dev/null +++ b/services/distributedhardwarefwkservice/src/task/device_changed_task.cpp @@ -0,0 +1,128 @@ +/* + * Copyright (c) 2021-2024 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 + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "device_changed_task.h" + +#include "anonymous_string.h" +#include "capability_info_manager.h" +#include "component_manager.h" +#include "dh_utils_tool.h" +#include "capability_utils.h" +#include "distributed_hardware_errno.h" +#include "distributed_hardware_log.h" +#include "local_capability_info_manager.h" +#include "meta_info_manager.h" +#include "task_board.h" +#include "task_executor.h" +#include "task_factory.h" + +namespace OHOS { +namespace DistributedHardware { +#undef DH_LOG_TAG +#define DH_LOG_TAG "DeviceChangedTask" + +DeviceChangedTask::DeviceChangedTask(const std::string &networkId, const std::string &uuid, const std::string &dhId, + const DHType dhType) : Task(networkId, uuid, dhId, dhType) +{ + SetTaskType(TaskType::DEVICE_CHANGED); + SetTaskSteps(std::vector { TaskStep::DO_DEVICE_CHANGED }); + DHLOGD("id = %{public}s, uuid = %{public}s", GetId().c_str(), GetAnonyString(uuid).c_str()); +} + +DeviceChangedTask::~DeviceChangedTask() +{ + DHLOGD("id = %{public}s, uuid = %{public}s", GetId().c_str(), GetAnonyString(GetUUID()).c_str()); +} + +void DeviceChangedTask::DoTask() +{ + DHLOGD("start device changed task, id = %{public}s, uuid = %{public}s", GetId().c_str(), GetAnonyString(GetUUID()).c_str()); + this->SetTaskState(TaskState::RUNNING); + for (const auto& step : this->GetTaskSteps()) { + switch (step) { + case TaskStep::DO_DEVICE_CHANGED: { + HandleDeviceChanged(); + break; + } + default: { + break; + } + } + } + SetTaskState(TaskState::SUCCESS); + DHLOGD("finish device changed task, remove it, id = %{public}s.", GetId().c_str()); + TaskBoard::GetInstance().RemoveTask(this->GetId()); +} + + +void DeviceChangedTask::HandleDeviceChanged() +{ + DHLOGI("networkId = %{public}s, uuid = %{public}s", GetAnonyString(GetNetworkId()).c_str(), + GetAnonyString(GetUUID()).c_str()); + if (!ComponentManager::GetInstance().IsIdenticalAccount(GetNetworkId())) { + DHLOGI("not identical account"); + return; + } + std::string deviceId = GetDeviceIdByUUID(GetUUID()); + std::vector> devDhInfos; + std::vector> capabilityInfos; + CapabilityInfoManager::GetInstance()->GetCapabilitiesByDeviceId(deviceId, capabilityInfos); + std::for_each(capabilityInfos.begin(), capabilityInfos.end(), [&](std::shared_ptr cap) { + devDhInfos.push_back({cap->GetDHId(), cap->GetDHType()}); + }); + + if (devDhInfos.empty()) { + DHLOGW("Can not get cap info from CapabilityInfo, try use local Capability info"); + LocalCapabilityInfoManager::GetInstance()->GetCapabilitiesByDeviceId(deviceId, capabilityInfos); + std::for_each(capabilityInfos.begin(), capabilityInfos.end(), [&](std::shared_ptr cap) { + devDhInfos.push_back({cap->GetDHId(), cap->GetDHType()}); + }); + } + + if (devDhInfos.empty()) { + DHLOGW("Can not get cap info from local Capbility, try use meta info"); + std::vector> metaCapInfos; + MetaInfoManager::GetInstance()->GetMetaCapInfosByDeviceId(deviceId, metaCapInfos); + std::for_each(metaCapInfos.begin(), metaCapInfos.end(), [&](std::shared_ptr cap) { + devDhInfos.push_back({cap->GetDHId(), cap->GetDHType()}); + }); + } + + if (devDhInfos.empty()) { + DHLOGE("Can not get cap info, uuid = %{public}s, deviceId = %{public}s", GetAnonyString(GetUUID()).c_str(), + GetAnonyString(deviceId).c_str()); + return; + } + + auto enabledDevices = TaskBoard::GetInstance().GetEnabledDevice(); + for (const auto &info : devDhInfos) { + + //skip enabled component + std::string deviceKey = GetCapabilityKey(GetDeviceIdByUUID(GetUUID()), info.first); + if (enabledDevices.find(deviceKey) != enabledDevices.end()) { + continue; + } + TaskParam taskParam = { + .networkId = GetNetworkId(), + .uuid = GetUUID(), + .dhId = info.first, + .dhType = info.second + }; + auto task = TaskFactory::GetInstance().CreateTask(TaskType::ENABLE, taskParam, shared_from_this()); + TaskExecutor::GetInstance().PushTask(task); + } +} +} // namespace DistributedHardware +} // namespace OHOS diff --git a/services/distributedhardwarefwkservice/src/task/task_factory.cpp b/services/distributedhardwarefwkservice/src/task/task_factory.cpp index d20aecb3..d3e782e9 100644 --- a/services/distributedhardwarefwkservice/src/task/task_factory.cpp +++ b/services/distributedhardwarefwkservice/src/task/task_factory.cpp @@ -22,6 +22,7 @@ #include "offline_task.h" #include "online_task.h" #include "task_board.h" +#include "device_changed_task.h" namespace OHOS { namespace DistributedHardware { @@ -52,6 +53,10 @@ std::shared_ptr TaskFactory::CreateTask(TaskType taskType, TaskParam taskP task = std::make_shared(taskParam.networkId, taskParam.uuid, taskParam.dhId, taskParam.dhType); break; } + case TaskType::DEVICE_CHANGED: { + task = std::make_shared(taskParam.networkId, taskParam.uuid, taskParam.dhId, taskParam.dhType); + break; + } default: { DHLOGE("CreateTask type invalid, type: %{public}d", taskType); return nullptr; -- Gitee From 6cf2e4e90f27911b23c98770aa525acb6e238d9e Mon Sep 17 00:00:00 2001 From: saga Date: Mon, 27 May 2024 15:20:42 +0800 Subject: [PATCH 02/10] when device info changed ,DH need re-enabled privacy resources Signed-off-by: saga --- .../include/distributed_hardware_errno.h | 1 + .../include/idistributed_hardware_manager.h | 2 + .../distributedhardwarefwkservice/BUILD.gn | 1 + .../componentmanager/component_manager.h | 3 +- .../include/distributed_hardware_manager.h | 1 + .../distributed_hardware_manager_factory.h | 1 + .../include/task/device_changed_task.h | 35 +++++ .../include/utils/impl_utils.h | 6 +- .../src/accessmanager/access_manager.cpp | 21 ++- .../src/distributed_hardware_manager.cpp | 24 ++++ .../distributed_hardware_manager_factory.cpp | 28 ++++ .../src/task/device_changed_task.cpp | 127 ++++++++++++++++++ .../src/task/task_factory.cpp | 5 + 13 files changed, 249 insertions(+), 6 deletions(-) create mode 100644 services/distributedhardwarefwkservice/include/task/device_changed_task.h create mode 100644 services/distributedhardwarefwkservice/src/task/device_changed_task.cpp diff --git a/common/utils/include/distributed_hardware_errno.h b/common/utils/include/distributed_hardware_errno.h index 998aba9e..febf17d6 100644 --- a/common/utils/include/distributed_hardware_errno.h +++ b/common/utils/include/distributed_hardware_errno.h @@ -73,6 +73,7 @@ namespace DistributedHardware { constexpr int32_t ERR_DH_FWK_HARDWARE_MANAGER_DEVICE_REPEAT_ONLINE = -10500; constexpr int32_t ERR_DH_FWK_HARDWARE_MANAGER_DEVICE_REPEAT_OFFLINE = -10501; constexpr int32_t ERR_DH_FWK_HARDWARE_MANAGER_INIT_FAILED = -10502; + constexpr int32_t ERR_DH_FWK_HARDWARE_MANAGER_DEVICE_NOT_ONLINE = -10503; /* ComponentLoader errno, range: [-10600, -10699] */ constexpr int32_t ERR_DH_FWK_LOADER_HANDLER_IS_NULL = -10600; diff --git a/common/utils/include/idistributed_hardware_manager.h b/common/utils/include/idistributed_hardware_manager.h index dc2cf894..93553745 100644 --- a/common/utils/include/idistributed_hardware_manager.h +++ b/common/utils/include/idistributed_hardware_manager.h @@ -32,6 +32,8 @@ public: uint16_t deviceType) = 0; virtual int32_t SendOffLineEvent(const std::string &networkId, const std::string &uuid, uint16_t deviceType) = 0; + virtual int32_t SendDeviceChangedEvent(const std::string &networkId, const std::string &uuid, + uint16_t deviceType) = 0; virtual size_t GetOnLineCount() = 0; virtual int32_t GetComponentVersion(std::unordered_map &versionMap) = 0; virtual int32_t Dump(const std::vector &argsStr, std::string &result) = 0; diff --git a/services/distributedhardwarefwkservice/BUILD.gn b/services/distributedhardwarefwkservice/BUILD.gn index e516c6ec..08e875e7 100644 --- a/services/distributedhardwarefwkservice/BUILD.gn +++ b/services/distributedhardwarefwkservice/BUILD.gn @@ -97,6 +97,7 @@ ohos_shared_library("distributedhardwarefwksvr") { "src/task/enable_task.cpp", "src/task/offline_task.cpp", "src/task/online_task.cpp", + "src/task/device_changed_task.cpp", "src/task/task.cpp", "src/task/task_board.cpp", "src/task/task_executor.cpp", diff --git a/services/distributedhardwarefwkservice/include/componentmanager/component_manager.h b/services/distributedhardwarefwkservice/include/componentmanager/component_manager.h index cdb9e2b9..db59cc43 100644 --- a/services/distributedhardwarefwkservice/include/componentmanager/component_manager.h +++ b/services/distributedhardwarefwkservice/include/componentmanager/component_manager.h @@ -76,7 +76,7 @@ public: * @return false if the task param not exist, return false. */ bool FetchNeedRefreshTask(const std::pair &taskKey, TaskParam &taskParam); - + bool IsIdenticalAccount(const std::string &networkId); class ComponentManagerEventHandler : public AppExecFwk::EventHandler { public: ComponentManagerEventHandler(const std::shared_ptr &runner); @@ -113,7 +113,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); int32_t InitComponentHandler(); diff --git a/services/distributedhardwarefwkservice/include/distributed_hardware_manager.h b/services/distributedhardwarefwkservice/include/distributed_hardware_manager.h index 97ce0f0a..601e8078 100644 --- a/services/distributedhardwarefwkservice/include/distributed_hardware_manager.h +++ b/services/distributedhardwarefwkservice/include/distributed_hardware_manager.h @@ -32,6 +32,7 @@ public: int32_t Release() override; int32_t SendOnLineEvent(const std::string &networkId, const std::string &uuid, uint16_t deviceType) override; int32_t SendOffLineEvent(const std::string &networkId, const std::string &uuid, uint16_t deviceType) override; + int32_t SendDeviceChangedEvent(const std::string &networkId, const std::string &uuid, uint16_t deviceType) override; size_t GetOnLineCount() override; int32_t GetComponentVersion(std::unordered_map &versionMap) override; diff --git a/services/distributedhardwarefwkservice/include/distributed_hardware_manager_factory.h b/services/distributedhardwarefwkservice/include/distributed_hardware_manager_factory.h index d249dbc8..9cc616a1 100644 --- a/services/distributedhardwarefwkservice/include/distributed_hardware_manager_factory.h +++ b/services/distributedhardwarefwkservice/include/distributed_hardware_manager_factory.h @@ -33,6 +33,7 @@ public: bool IsInit(); int32_t SendOnLineEvent(const std::string &networkId, const std::string &uuid, uint16_t deviceType); int32_t SendOffLineEvent(const std::string &networkId, const std::string &uuid, uint16_t deviceType); + int32_t SendDeviceChangedEvent(const std::string &networkId, const std::string &uuid, uint16_t deviceType); int32_t GetComponentVersion(std::unordered_map &versionMap); int Dump(const std::vector &argsStr, std::string &result); diff --git a/services/distributedhardwarefwkservice/include/task/device_changed_task.h b/services/distributedhardwarefwkservice/include/task/device_changed_task.h new file mode 100644 index 00000000..bd86723c --- /dev/null +++ b/services/distributedhardwarefwkservice/include/task/device_changed_task.h @@ -0,0 +1,35 @@ +/* + * Copyright (c) 2021 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 + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef OHOS_DISTRIBUTED_HARDWARE_DEVICE_CHANGED_TASK_H +#define OHOS_DISTRIBUTED_HARDWARE_DEVICE_CHANGED_TASK_H + +#include "task.h" + +namespace OHOS { +namespace DistributedHardware { +class DeviceChangedTask : public Task { +public: + DeviceChangedTask() = delete; + DeviceChangedTask(const std::string &networkId, const std::string &uuid, const std::string &dhId, const DHType dhType); + virtual ~DeviceChangedTask(); + virtual void DoTask(); + +private: + void HandleDeviceChanged(); +}; +} // namespace DistributedHardware +} // namespace OHOS +#endif \ No newline at end of file diff --git a/services/distributedhardwarefwkservice/include/utils/impl_utils.h b/services/distributedhardwarefwkservice/include/utils/impl_utils.h index f47aff56..6b792119 100644 --- a/services/distributedhardwarefwkservice/include/utils/impl_utils.h +++ b/services/distributedhardwarefwkservice/include/utils/impl_utils.h @@ -28,7 +28,8 @@ enum class TaskType : int32_t { ENABLE = 1, DISABLE = 2, ON_LINE = 3, - OFF_LINE = 4 + OFF_LINE = 4, + DEVICE_CHANGED = 5 }; enum class TaskStep : int32_t { @@ -38,7 +39,8 @@ enum class TaskStep : int32_t { REGISTER_ONLINE_DISTRIBUTED_HARDWARE = 4, UNREGISTER_OFFLINE_DISTRIBUTED_HARDWARE = 5, CLEAR_OFFLINE_INFO = 6, - WAIT_UNREGISTGER_COMPLETE = 7 + WAIT_UNREGISTGER_COMPLETE = 7, + DO_DEVICE_CHANGED = 8 }; enum class TaskState : int32_t { diff --git a/services/distributedhardwarefwkservice/src/accessmanager/access_manager.cpp b/services/distributedhardwarefwkservice/src/accessmanager/access_manager.cpp index 94c20417..f10b8fa3 100644 --- a/services/distributedhardwarefwkservice/src/accessmanager/access_manager.cpp +++ b/services/distributedhardwarefwkservice/src/accessmanager/access_manager.cpp @@ -175,8 +175,25 @@ void AccessManager::OnDeviceReady(const DmDeviceInfo &deviceInfo) void AccessManager::OnDeviceChanged(const DmDeviceInfo &deviceInfo) { - (void)deviceInfo; - return; + std::lock_guard lock(accessMutex_); + DHLOGI("start, networkId = %{public}s, deviceName = %{public}s", + GetAnonyString(deviceInfo.networkId).c_str(), GetAnonyString(deviceInfo.deviceName).c_str()); + + auto networkId = std::string(deviceInfo.networkId); + if (networkId.size() == 0 || networkId.size() > MAX_ID_LEN) { + DHLOGE("NetworkId is invalid!"); + return; + } + auto uuid = GetUUIDBySoftBus(networkId); + if (uuid.size() == 0 || uuid.size() > MAX_ID_LEN) { + DHLOGE("Uuid is invalid!"); + return; + } + + auto ret = + DistributedHardwareManagerFactory::GetInstance().SendDeviceChangedEvent(networkId, uuid, deviceInfo.deviceTypeId); + DHLOGI("device changed result = %{public}d, networkId = %{public}s, uuid = %{public}s", ret, + GetAnonyString(networkId).c_str(), GetAnonyString(uuid).c_str()); } void AccessManager::CheckTrustedDeviceOnline() diff --git a/services/distributedhardwarefwkservice/src/distributed_hardware_manager.cpp b/services/distributedhardwarefwkservice/src/distributed_hardware_manager.cpp index ee3f702b..13c4e190 100644 --- a/services/distributedhardwarefwkservice/src/distributed_hardware_manager.cpp +++ b/services/distributedhardwarefwkservice/src/distributed_hardware_manager.cpp @@ -146,6 +146,30 @@ int32_t DistributedHardwareManager::SendOffLineEvent(const std::string &networkI return DH_FWK_SUCCESS; } +int32_t DistributedHardwareManager::SendDeviceChangedEvent(const std::string &networkId, const std::string &uuid, + uint16_t deviceType) +{ + (void)deviceType; + + if (networkId.size() == 0 || networkId.size() > MAX_ID_LEN || uuid.size() == 0 || uuid.size() > MAX_ID_LEN) { + DHLOGE("NetworkId or uuid is invalid"); + return ERR_DH_FWK_PARA_INVALID; + } + + DHLOGI("networkId = %{public}s, uuid = %{public}s", GetAnonyString(networkId).c_str(), + GetAnonyString(uuid).c_str()); + + TaskParam taskParam = { + .networkId = networkId, + .uuid = uuid, + .dhId = "", + .dhType = DHType::UNKNOWN + }; + auto task = TaskFactory::GetInstance().CreateTask(TaskType::DEVICE_CHANGED, taskParam, nullptr); + TaskExecutor::GetInstance().PushTask(task); + return DH_FWK_SUCCESS; +} + size_t DistributedHardwareManager::GetOnLineCount() { return DHContext::GetInstance().GetOnlineCount(); diff --git a/services/distributedhardwarefwkservice/src/distributed_hardware_manager_factory.cpp b/services/distributedhardwarefwkservice/src/distributed_hardware_manager_factory.cpp index 6da58efc..17e65851 100644 --- a/services/distributedhardwarefwkservice/src/distributed_hardware_manager_factory.cpp +++ b/services/distributedhardwarefwkservice/src/distributed_hardware_manager_factory.cpp @@ -205,6 +205,34 @@ int32_t DistributedHardwareManagerFactory::SendOffLineEvent(const std::string &n return DH_FWK_SUCCESS; } +int32_t DistributedHardwareManagerFactory::SendDeviceChangedEvent(const std::string &networkId, const std::string &uuid, + uint16_t deviceType) +{ + if (networkId.empty() || networkId.size() > MAX_ID_LEN || uuid.empty() || uuid.size() > MAX_ID_LEN) { + DHLOGE("NetworkId or uuid is invalid"); + return ERR_DH_FWK_PARA_INVALID; + } + + if (!isInit) { + DHLOGI("distributedHardwareMgr is null"); + return ERR_DH_FWK_HARDWARE_MANAGER_DEVICE_NOT_ONLINE; + } + //if device not online, no need to handle device change event + if (!DHContext::GetInstance().IsDeviceOnline(uuid)) { + DHLOGI("Device not online, networkId: %{public}s, uuid: %{public}s", + GetAnonyString(networkId).c_str(), GetAnonyString(uuid).c_str()); + return ERR_DH_FWK_HARDWARE_MANAGER_DEVICE_NOT_ONLINE; + } + + auto result = DistributedHardwareManager::GetInstance().SendDeviceChangedEvent(networkId, uuid, deviceType); + if (result != DH_FWK_SUCCESS) { + DHLOGE("offline failed, errCode = %{public}d", result); + return result; + } + + return DH_FWK_SUCCESS; +} + int32_t DistributedHardwareManagerFactory::GetComponentVersion(std::unordered_map &versionMap) { DHLOGI("start"); diff --git a/services/distributedhardwarefwkservice/src/task/device_changed_task.cpp b/services/distributedhardwarefwkservice/src/task/device_changed_task.cpp new file mode 100644 index 00000000..94cdbcf8 --- /dev/null +++ b/services/distributedhardwarefwkservice/src/task/device_changed_task.cpp @@ -0,0 +1,127 @@ +/* + * Copyright (c) 2021-2024 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 + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "device_changed_task.h" + +#include "anonymous_string.h" +#include "capability_info_manager.h" +#include "component_manager.h" +#include "dh_utils_tool.h" +#include "capability_utils.h" +#include "distributed_hardware_errno.h" +#include "distributed_hardware_log.h" +#include "local_capability_info_manager.h" +#include "meta_info_manager.h" +#include "task_board.h" +#include "task_executor.h" +#include "task_factory.h" + +namespace OHOS { +namespace DistributedHardware { +#undef DH_LOG_TAG +#define DH_LOG_TAG "DeviceChangedTask" + +DeviceChangedTask::DeviceChangedTask(const std::string &networkId, const std::string &uuid, const std::string &dhId, + const DHType dhType) : Task(networkId, uuid, dhId, dhType) +{ + SetTaskType(TaskType::DEVICE_CHANGED); + SetTaskSteps(std::vector { TaskStep::DO_DEVICE_CHANGED }); + DHLOGD("id = %{public}s, uuid = %{public}s", GetId().c_str(), GetAnonyString(uuid).c_str()); +} + +DeviceChangedTask::~DeviceChangedTask() +{ + DHLOGD("id = %{public}s, uuid = %{public}s", GetId().c_str(), GetAnonyString(GetUUID()).c_str()); +} + +void DeviceChangedTask::DoTask() +{ + DHLOGD("start device changed task, id = %{public}s, uuid = %{public}s", GetId().c_str(), GetAnonyString(GetUUID()).c_str()); + this->SetTaskState(TaskState::RUNNING); + for (const auto& step : this->GetTaskSteps()) { + switch (step) { + case TaskStep::DO_DEVICE_CHANGED: { + HandleDeviceChanged(); + break; + } + default: { + break; + } + } + } + SetTaskState(TaskState::SUCCESS); + DHLOGD("finish device changed task, remove it, id = %{public}s.", GetId().c_str()); + TaskBoard::GetInstance().RemoveTask(this->GetId()); +} + + +void DeviceChangedTask::HandleDeviceChanged() +{ + DHLOGI("networkId = %{public}s, uuid = %{public}s", GetAnonyString(GetNetworkId()).c_str(), + GetAnonyString(GetUUID()).c_str()); + if (!ComponentManager::GetInstance().IsIdenticalAccount(GetNetworkId())) { + DHLOGI("not identical account"); + return; + } + std::string deviceId = GetDeviceIdByUUID(GetUUID()); + std::vector> devDhInfos; + std::vector> capabilityInfos; + CapabilityInfoManager::GetInstance()->GetCapabilitiesByDeviceId(deviceId, capabilityInfos); + std::for_each(capabilityInfos.begin(), capabilityInfos.end(), [&](std::shared_ptr cap) { + devDhInfos.push_back({cap->GetDHId(), cap->GetDHType()}); + }); + + if (devDhInfos.empty()) { + DHLOGW("Can not get cap info from CapabilityInfo, try use local Capability info"); + LocalCapabilityInfoManager::GetInstance()->GetCapabilitiesByDeviceId(deviceId, capabilityInfos); + std::for_each(capabilityInfos.begin(), capabilityInfos.end(), [&](std::shared_ptr cap) { + devDhInfos.push_back({cap->GetDHId(), cap->GetDHType()}); + }); + } + + if (devDhInfos.empty()) { + DHLOGW("Can not get cap info from local Capbility, try use meta info"); + std::vector> metaCapInfos; + MetaInfoManager::GetInstance()->GetMetaCapInfosByDeviceId(deviceId, metaCapInfos); + std::for_each(metaCapInfos.begin(), metaCapInfos.end(), [&](std::shared_ptr cap) { + devDhInfos.push_back({cap->GetDHId(), cap->GetDHType()}); + }); + } + + if (devDhInfos.empty()) { + DHLOGE("Can not get cap info, uuid = %{public}s, deviceId = %{public}s", GetAnonyString(GetUUID()).c_str(), + GetAnonyString(deviceId).c_str()); + return; + } + + auto enabledDevices = TaskBoard::GetInstance().GetEnabledDevice(); + for (const auto &info : devDhInfos) { + //skip enabled component + std::string deviceKey = GetCapabilityKey(GetDeviceIdByUUID(GetUUID()), info.first); + if (enabledDevices.find(deviceKey) != enabledDevices.end()) { + continue; + } + TaskParam taskParam = { + .networkId = GetNetworkId(), + .uuid = GetUUID(), + .dhId = info.first, + .dhType = info.second + }; + auto task = TaskFactory::GetInstance().CreateTask(TaskType::ENABLE, taskParam, shared_from_this()); + TaskExecutor::GetInstance().PushTask(task); + } +} +} // namespace DistributedHardware +} // namespace OHOS diff --git a/services/distributedhardwarefwkservice/src/task/task_factory.cpp b/services/distributedhardwarefwkservice/src/task/task_factory.cpp index d20aecb3..d3e782e9 100644 --- a/services/distributedhardwarefwkservice/src/task/task_factory.cpp +++ b/services/distributedhardwarefwkservice/src/task/task_factory.cpp @@ -22,6 +22,7 @@ #include "offline_task.h" #include "online_task.h" #include "task_board.h" +#include "device_changed_task.h" namespace OHOS { namespace DistributedHardware { @@ -52,6 +53,10 @@ std::shared_ptr TaskFactory::CreateTask(TaskType taskType, TaskParam taskP task = std::make_shared(taskParam.networkId, taskParam.uuid, taskParam.dhId, taskParam.dhType); break; } + case TaskType::DEVICE_CHANGED: { + task = std::make_shared(taskParam.networkId, taskParam.uuid, taskParam.dhId, taskParam.dhType); + break; + } default: { DHLOGE("CreateTask type invalid, type: %{public}d", taskType); return nullptr; -- Gitee From f84cc19744564fb52dea7b37c4cdd9c122191e5d Mon Sep 17 00:00:00 2001 From: saga Date: Mon, 19 Aug 2024 13:01:12 +0000 Subject: [PATCH 03/10] update services/distributedhardwarefwkservice/src/accessmanager/access_manager.cpp. Signed-off-by: saga --- .../src/accessmanager/access_manager.cpp | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) diff --git a/services/distributedhardwarefwkservice/src/accessmanager/access_manager.cpp b/services/distributedhardwarefwkservice/src/accessmanager/access_manager.cpp index d210f4a2..521895f3 100644 --- a/services/distributedhardwarefwkservice/src/accessmanager/access_manager.cpp +++ b/services/distributedhardwarefwkservice/src/accessmanager/access_manager.cpp @@ -178,21 +178,22 @@ void AccessManager::OnDeviceChanged(const DmDeviceInfo &deviceInfo) deviceInfo.authForm); auto networkId = std::string(deviceInfo.networkId); - if (networkId.size() == 0 || networkId.size() > MAX_ID_LEN) { - DHLOGE("NetworkId is invalid!"); + if (!IsIdLengthValid(networkId)) { return; } - auto uuid = GetUUIDBySoftBus(networkId); - if (uuid.size() == 0 || uuid.size() > MAX_ID_LEN) { - DHLOGE("Uuid is invalid!"); + auto uuid = GetUUIDByDm(networkId); + if (!IsIdLengthValid(uuid)) { + return; + } + auto udid = GetUDIDByDm(networkId); + if (!IsIdLengthValid(udid)) { return; } - auto ret = - DistributedHardwareManagerFactory::GetInstance().SendDeviceChangedEvent(networkId, uuid, + DistributedHardwareManagerFactory::GetInstance().SendDeviceChangedEvent(networkId, uuid, udid, deviceInfo.deviceTypeId); - DHLOGI("device changed result = %{public}d, networkId = %{public}s, uuid = %{public}s", ret, - GetAnonyString(networkId).c_str(), GetAnonyString(uuid).c_str()); + DHLOGI("device changed result = %{public}d, networkId = %{public}s, uuid = %{public}s, udid: %{public}s", + ret, GetAnonyString(networkId).c_str(), GetAnonyString(uuid).c_str(), GetAnonyString(udid).c_str()); } void AccessManager::CheckTrustedDeviceOnline() -- Gitee From ab5a1aa7f8800dfebc336287f50429f1e160ef33 Mon Sep 17 00:00:00 2001 From: saga Date: Mon, 19 Aug 2024 13:09:42 +0000 Subject: [PATCH 04/10] update services/distributedhardwarefwkservice/include/task/device_changed_task.h. Signed-off-by: saga --- .../include/task/device_changed_task.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/services/distributedhardwarefwkservice/include/task/device_changed_task.h b/services/distributedhardwarefwkservice/include/task/device_changed_task.h index 5c89f812..e1c26216 100644 --- a/services/distributedhardwarefwkservice/include/task/device_changed_task.h +++ b/services/distributedhardwarefwkservice/include/task/device_changed_task.h @@ -23,7 +23,7 @@ namespace DistributedHardware { class DeviceChangedTask : public Task { public: DeviceChangedTask() = delete; - DeviceChangedTask(const std::string &networkId, const std::string &uuid, + DeviceChangedTask(const std::string &networkId, const std::string &uuid, const std::string &udid, const std::string &dhId, const DHType dhType); virtual ~DeviceChangedTask(); virtual void DoTask(); -- Gitee From 7bea2d2818b233cce7607b630c324cd8a555177e Mon Sep 17 00:00:00 2001 From: saga Date: Mon, 19 Aug 2024 13:13:26 +0000 Subject: [PATCH 05/10] update services/distributedhardwarefwkservice/src/distributed_hardware_manager.cpp. Signed-off-by: saga --- .../src/distributed_hardware_manager.cpp | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-) diff --git a/services/distributedhardwarefwkservice/src/distributed_hardware_manager.cpp b/services/distributedhardwarefwkservice/src/distributed_hardware_manager.cpp index bb0b065b..27b14444 100644 --- a/services/distributedhardwarefwkservice/src/distributed_hardware_manager.cpp +++ b/services/distributedhardwarefwkservice/src/distributed_hardware_manager.cpp @@ -145,21 +145,19 @@ int32_t DistributedHardwareManager::SendOffLineEvent(const std::string &networkI } int32_t DistributedHardwareManager::SendDeviceChangedEvent(const std::string &networkId, const std::string &uuid, - uint16_t deviceType) + const std::string &udid, uint16_t deviceType) { - (void)deviceType; - - if (networkId.size() == 0 || networkId.size() > MAX_ID_LEN || uuid.size() == 0 || uuid.size() > MAX_ID_LEN) { - DHLOGE("NetworkId or uuid is invalid"); + if (!IsIdLengthValid(networkId) || !IsIdLengthValid(uuid) || !IsIdLengthValid(udid)) { return ERR_DH_FWK_PARA_INVALID; } - - DHLOGI("networkId = %{public}s, uuid = %{public}s", GetAnonyString(networkId).c_str(), - GetAnonyString(uuid).c_str()); + (void)deviceType; + DHLOGI("networkId = %{public}s, uuid = %{public}s, udid = %{public}s", + GetAnonyString(networkId).c_str(), GetAnonyString(uuid).c_str(), GetAnonyString(udid).c_str()); TaskParam taskParam = { .networkId = networkId, .uuid = uuid, + .udid = udid, .dhId = "", .dhType = DHType::UNKNOWN }; -- Gitee From d1793c6de1517b9b39870f2e58941613bdd25842 Mon Sep 17 00:00:00 2001 From: saga Date: Mon, 19 Aug 2024 13:18:57 +0000 Subject: [PATCH 06/10] update services/distributedhardwarefwkservice/src/task/device_changed_task.cpp. Signed-off-by: saga --- .../src/task/device_changed_task.cpp | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/services/distributedhardwarefwkservice/src/task/device_changed_task.cpp b/services/distributedhardwarefwkservice/src/task/device_changed_task.cpp index 5405c495..368f7055 100644 --- a/services/distributedhardwarefwkservice/src/task/device_changed_task.cpp +++ b/services/distributedhardwarefwkservice/src/task/device_changed_task.cpp @@ -33,8 +33,8 @@ namespace DistributedHardware { #undef DH_LOG_TAG #define DH_LOG_TAG "DeviceChangedTask" -DeviceChangedTask::DeviceChangedTask(const std::string &networkId, const std::string &uuid, const std::string &dhId, - const DHType dhType) : Task(networkId, uuid, dhId, dhType) +DeviceChangedTask::DeviceChangedTask(const std::string &networkId, const std::string &uuid, const std::string &udid, + const std::string &dhId, const DHType dhType) : Task(networkId, uuid, udid, dhId, dhType) { SetTaskType(TaskType::DEVICE_CHANGED); SetTaskSteps(std::vector { TaskStep::DO_DEVICE_CHANGED }); @@ -94,8 +94,9 @@ void DeviceChangedTask::HandleDeviceChanged() if (devDhInfos.empty()) { DHLOGW("Can not get cap info from local Capbility, try use meta info"); + std::string udidHash = Sha256(GetUDID()); std::vector> metaCapInfos; - MetaInfoManager::GetInstance()->GetMetaCapInfosByDeviceId(deviceId, metaCapInfos); + MetaInfoManager::GetInstance()->GetMetaCapInfosByUdidHash(udidHash, metaCapInfos); std::for_each(metaCapInfos.begin(), metaCapInfos.end(), [&](std::shared_ptr cap) { devDhInfos.push_back({cap->GetDHId(), cap->GetDHType()}); }); @@ -117,6 +118,7 @@ void DeviceChangedTask::HandleDeviceChanged() TaskParam taskParam = { .networkId = GetNetworkId(), .uuid = GetUUID(), + .udid = GetUDID(), .dhId = info.first, .dhType = info.second }; -- Gitee From ec7832efadf2739b35822ccd157795bd70c19799 Mon Sep 17 00:00:00 2001 From: saga Date: Mon, 19 Aug 2024 13:24:21 +0000 Subject: [PATCH 07/10] update services/distributedhardwarefwkservice/src/task/task_factory.cpp. Signed-off-by: saga --- .../distributedhardwarefwkservice/src/task/task_factory.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/services/distributedhardwarefwkservice/src/task/task_factory.cpp b/services/distributedhardwarefwkservice/src/task/task_factory.cpp index 7053f5a4..1c2a3449 100644 --- a/services/distributedhardwarefwkservice/src/task/task_factory.cpp +++ b/services/distributedhardwarefwkservice/src/task/task_factory.cpp @@ -58,7 +58,7 @@ std::shared_ptr TaskFactory::CreateTask(TaskType taskType, TaskParam taskP break; } case TaskType::DEVICE_CHANGED: { - task = std::make_shared(taskParam.networkId, taskParam.uuid, + task = std::make_shared(taskParam.networkId, taskParam.uuid, taskParam.udid, taskParam.dhId, taskParam.dhType); break; } -- Gitee From c4a334674ce4fe2a1a1bec3f9123a44348c7939e Mon Sep 17 00:00:00 2001 From: saga Date: Mon, 19 Aug 2024 13:33:30 +0000 Subject: [PATCH 08/10] update services/distributedhardwarefwkservice/src/distributed_hardware_manager_factory.cpp. Signed-off-by: saga --- .../src/distributed_hardware_manager_factory.cpp | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/services/distributedhardwarefwkservice/src/distributed_hardware_manager_factory.cpp b/services/distributedhardwarefwkservice/src/distributed_hardware_manager_factory.cpp index 689dcb19..b329f9ab 100644 --- a/services/distributedhardwarefwkservice/src/distributed_hardware_manager_factory.cpp +++ b/services/distributedhardwarefwkservice/src/distributed_hardware_manager_factory.cpp @@ -219,10 +219,9 @@ int32_t DistributedHardwareManagerFactory::SendOffLineEvent(const std::string &n } int32_t DistributedHardwareManagerFactory::SendDeviceChangedEvent(const std::string &networkId, const std::string &uuid, - uint16_t deviceType) + const std::string &udid, uint16_t deviceType) { - if (networkId.empty() || networkId.size() > MAX_ID_LEN || uuid.empty() || uuid.size() > MAX_ID_LEN) { - DHLOGE("NetworkId or uuid is invalid"); + if (!IsIdLengthValid(networkId) || !IsIdLengthValid(uuid) || !IsIdLengthValid(udid)) { return ERR_DH_FWK_PARA_INVALID; } @@ -237,7 +236,7 @@ int32_t DistributedHardwareManagerFactory::SendDeviceChangedEvent(const std::str return ERR_DH_FWK_HARDWARE_MANAGER_DEVICE_NOT_ONLINE; } - auto result = DistributedHardwareManager::GetInstance().SendDeviceChangedEvent(networkId, uuid, deviceType); + auto result = DistributedHardwareManager::GetInstance().SendDeviceChangedEvent(networkId, uuid, udid, deviceType); if (result != DH_FWK_SUCCESS) { DHLOGE("offline failed, errCode = %{public}d", result); return result; -- Gitee From 6932bbc3eb79b2c4ac1a6e3175773d5f98b0a5d8 Mon Sep 17 00:00:00 2001 From: saga Date: Tue, 20 Aug 2024 06:44:04 +0000 Subject: [PATCH 09/10] update services/distributedhardwarefwkservice/src/task/device_changed_task.cpp. Signed-off-by: saga --- .../src/task/device_changed_task.cpp | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/services/distributedhardwarefwkservice/src/task/device_changed_task.cpp b/services/distributedhardwarefwkservice/src/task/device_changed_task.cpp index 368f7055..0c7fdb28 100644 --- a/services/distributedhardwarefwkservice/src/task/device_changed_task.cpp +++ b/services/distributedhardwarefwkservice/src/task/device_changed_task.cpp @@ -33,7 +33,7 @@ namespace DistributedHardware { #undef DH_LOG_TAG #define DH_LOG_TAG "DeviceChangedTask" -DeviceChangedTask::DeviceChangedTask(const std::string &networkId, const std::string &uuid, const std::string &udid, +DeviceChangedTask::DeviceChangedTask(const std::string &networkId, const std::string &uuid, const std::string &udid, const std::string &dhId, const DHType dhType) : Task(networkId, uuid, udid, dhId, dhType) { SetTaskType(TaskType::DEVICE_CHANGED); @@ -70,8 +70,7 @@ void DeviceChangedTask::DoTask() void DeviceChangedTask::HandleDeviceChanged() { - DHLOGI("networkId = %{public}s, uuid = %{public}s", GetAnonyString(GetNetworkId()).c_str(), - GetAnonyString(GetUUID()).c_str()); + DHLOGI("networkId = %{public}s", GetAnonyString(GetNetworkId()).c_str()); if (!ComponentManager::GetInstance().IsIdenticalAccount(GetNetworkId())) { DHLOGI("not identical account"); return; @@ -103,8 +102,7 @@ void DeviceChangedTask::HandleDeviceChanged() } if (devDhInfos.empty()) { - DHLOGE("Can not get cap info, uuid = %{public}s, deviceId = %{public}s", GetAnonyString(GetUUID()).c_str(), - GetAnonyString(deviceId).c_str()); + DHLOGE("Can not get cap info"); return; } -- Gitee From d69086eeef6730a373538acda40946c001d1e6e6 Mon Sep 17 00:00:00 2001 From: saga Date: Tue, 20 Aug 2024 09:10:15 +0000 Subject: [PATCH 10/10] update services/distributedhardwarefwkservice/src/distributed_hardware_manager_factory.cpp. Signed-off-by: saga --- .../src/distributed_hardware_manager_factory.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/services/distributedhardwarefwkservice/src/distributed_hardware_manager_factory.cpp b/services/distributedhardwarefwkservice/src/distributed_hardware_manager_factory.cpp index b329f9ab..153d3fe0 100644 --- a/services/distributedhardwarefwkservice/src/distributed_hardware_manager_factory.cpp +++ b/services/distributedhardwarefwkservice/src/distributed_hardware_manager_factory.cpp @@ -225,7 +225,7 @@ int32_t DistributedHardwareManagerFactory::SendDeviceChangedEvent(const std::str return ERR_DH_FWK_PARA_INVALID; } - if (!isInit) { + if (!IsInit()) { DHLOGI("distributedHardwareMgr is null"); return ERR_DH_FWK_HARDWARE_MANAGER_DEVICE_NOT_ONLINE; } -- Gitee