From 4998d93c8291ecebbf5c402940f0f67c078794ac Mon Sep 17 00:00:00 2001 From: saga Date: Wed, 22 May 2024 22:28:45 +0800 Subject: [PATCH 1/8] add device changed handle Signed-off-by: saga --- .../include/distributed_hardware_errno.h | 1 + .../componentmanager/component_manager.h | 1 - .../componentmanager/component_privacy.h | 2 + .../include/distributed_hardware_manager.h | 1 + .../distributed_hardware_manager_factory.h | 1 + .../include/task/device_changed_task.h | 36 ++++++ .../include/utils/impl_utils.h | 6 +- .../src/accessmanager/access_manager.cpp | 21 +++- .../componentmanager/component_manager.cpp | 21 ---- .../componentmanager/component_privacy.cpp | 43 +++++++ .../src/distributed_hardware_manager.cpp | 24 ++++ .../distributed_hardware_manager_factory.cpp | 28 +++++ .../src/task/device_changed_task.cpp | 111 ++++++++++++++++++ .../src/task/task_factory.cpp | 4 + 14 files changed, 274 insertions(+), 26 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/services/distributedhardwarefwkservice/include/componentmanager/component_manager.h b/services/distributedhardwarefwkservice/include/componentmanager/component_manager.h index d071f397..040d7f23 100644 --- a/services/distributedhardwarefwkservice/include/componentmanager/component_manager.h +++ b/services/distributedhardwarefwkservice/include/componentmanager/component_manager.h @@ -114,7 +114,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/componentmanager/component_privacy.h b/services/distributedhardwarefwkservice/include/componentmanager/component_privacy.h index 72fa15af..f5a0c2f1 100644 --- a/services/distributedhardwarefwkservice/include/componentmanager/component_privacy.h +++ b/services/distributedhardwarefwkservice/include/componentmanager/component_privacy.h @@ -39,6 +39,8 @@ public: void SetPageFlagTrue(); void SetPageFlagFalse(); bool GetPageFlag(); + bool IsSensitiveResource(); + bool IsIdenticalAccount(const std::string &networkId); class ComponentEventHandler : public AppExecFwk::EventHandler { public: 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..792f85ae --- /dev/null +++ b/services/distributedhardwarefwkservice/include/task/device_changed_task.h @@ -0,0 +1,36 @@ +/* + * 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 DoSyncInfo(); + //void CreateEnableTask(); +}; +} // 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..d67b9ae4 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, deviceTypeId = %{public}d", + GetAnonyString(deviceInfo.networkId).c_str(), GetAnonyString(deviceInfo.deviceName).c_str(), + deviceInfo.deviceTypeId); + + 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/componentmanager/component_manager.cpp b/services/distributedhardwarefwkservice/src/componentmanager/component_manager.cpp index 811cf229..7bf4bedb 100644 --- a/services/distributedhardwarefwkservice/src/componentmanager/component_manager.cpp +++ b/services/distributedhardwarefwkservice/src/componentmanager/component_manager.cpp @@ -913,27 +913,6 @@ std::map ComponentManager::GetDHSinkInstance( return compSink_; } -bool ComponentManager::IsIdenticalAccount(const std::string &networkId) -{ - 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) { DHLOGI("UpdateBusinessState, networkId: %{public}s, dhId: %{public}s, state: %{public}" PRIu32, diff --git a/services/distributedhardwarefwkservice/src/componentmanager/component_privacy.cpp b/services/distributedhardwarefwkservice/src/componentmanager/component_privacy.cpp index a740fbb8..b9bdd488 100644 --- a/services/distributedhardwarefwkservice/src/componentmanager/component_privacy.cpp +++ b/services/distributedhardwarefwkservice/src/componentmanager/component_privacy.cpp @@ -309,5 +309,48 @@ void ComponentPrivacy::ComponentEventHandler::ProcessStopPage(const AppExecFwk:: std::string subtype = cJSON_GetObjectItem(innerMsg, PRIVACY_SUBTYPE.c_str())->valuestring; comPrivacyObj_->StopPrivacePage(subtype); } + +bool ComponentPrivacy::IsIdenticalAccount(const std::string &networkId) +{ + 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; +} + +bool ComponentPrivacy::IsSensitiveResource() +{ + EnableParam param; + auto ret = GetEnableParam(networkId, uuid, dhId, dhType, param); + if (ret != DH_FWK_SUCCESS) { + DHLOGE("GetEnableParam failed, uuid = %{public}s, dhId = %{public}s, errCode = %{public}d", + GetAnonyString(uuid).c_str(), GetAnonyString(dhId).c_str(), ret); + if (RetryGetEnableParam(networkId, uuid, dhId, dhType, param) != DH_FWK_SUCCESS) { + return false; + } + } + 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 false; + } + + return resourceDesc[subtype]; +} + } // namespace DistributedHardware } // namespace OHOS 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..ccc75ccb 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 (!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..a775a7d9 --- /dev/null +++ b/services/distributedhardwarefwkservice/src/task/device_changed_task.cpp @@ -0,0 +1,111 @@ +/* + * 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 "dh_utils_tool.h" +#include "distributed_hardware_errno.h" +#include "distributed_hardware_log.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 online 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 online 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()); + 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()); + } + + for (const auto &info : devDhInfos) { + 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..7592cf89 100644 --- a/services/distributedhardwarefwkservice/src/task/task_factory.cpp +++ b/services/distributedhardwarefwkservice/src/task/task_factory.cpp @@ -52,6 +52,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 ec2ed58cbadaf8e499772c67bacb70c4de6e17a1 Mon Sep 17 00:00:00 2001 From: saga Date: Wed, 22 May 2024 22:28:45 +0800 Subject: [PATCH 2/8] add device changed handle Signed-off-by: saga --- .../include/distributed_hardware_errno.h | 1 + .../componentmanager/component_manager.h | 1 - .../componentmanager/component_privacy.h | 2 + .../include/distributed_hardware_manager.h | 1 + .../distributed_hardware_manager_factory.h | 1 + .../include/task/device_changed_task.h | 36 ++++++ .../include/utils/impl_utils.h | 6 +- .../src/accessmanager/access_manager.cpp | 21 +++- .../componentmanager/component_manager.cpp | 21 ---- .../componentmanager/component_privacy.cpp | 43 +++++++ .../src/distributed_hardware_manager.cpp | 24 ++++ .../distributed_hardware_manager_factory.cpp | 28 +++++ .../src/task/device_changed_task.cpp | 119 ++++++++++++++++++ .../src/task/task_factory.cpp | 4 + 14 files changed, 282 insertions(+), 26 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/services/distributedhardwarefwkservice/include/componentmanager/component_manager.h b/services/distributedhardwarefwkservice/include/componentmanager/component_manager.h index d071f397..040d7f23 100644 --- a/services/distributedhardwarefwkservice/include/componentmanager/component_manager.h +++ b/services/distributedhardwarefwkservice/include/componentmanager/component_manager.h @@ -114,7 +114,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/componentmanager/component_privacy.h b/services/distributedhardwarefwkservice/include/componentmanager/component_privacy.h index 72fa15af..f5a0c2f1 100644 --- a/services/distributedhardwarefwkservice/include/componentmanager/component_privacy.h +++ b/services/distributedhardwarefwkservice/include/componentmanager/component_privacy.h @@ -39,6 +39,8 @@ public: void SetPageFlagTrue(); void SetPageFlagFalse(); bool GetPageFlag(); + bool IsSensitiveResource(); + bool IsIdenticalAccount(const std::string &networkId); class ComponentEventHandler : public AppExecFwk::EventHandler { public: 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..792f85ae --- /dev/null +++ b/services/distributedhardwarefwkservice/include/task/device_changed_task.h @@ -0,0 +1,36 @@ +/* + * 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 DoSyncInfo(); + //void CreateEnableTask(); +}; +} // 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..d67b9ae4 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, deviceTypeId = %{public}d", + GetAnonyString(deviceInfo.networkId).c_str(), GetAnonyString(deviceInfo.deviceName).c_str(), + deviceInfo.deviceTypeId); + + 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/componentmanager/component_manager.cpp b/services/distributedhardwarefwkservice/src/componentmanager/component_manager.cpp index 811cf229..7bf4bedb 100644 --- a/services/distributedhardwarefwkservice/src/componentmanager/component_manager.cpp +++ b/services/distributedhardwarefwkservice/src/componentmanager/component_manager.cpp @@ -913,27 +913,6 @@ std::map ComponentManager::GetDHSinkInstance( return compSink_; } -bool ComponentManager::IsIdenticalAccount(const std::string &networkId) -{ - 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) { DHLOGI("UpdateBusinessState, networkId: %{public}s, dhId: %{public}s, state: %{public}" PRIu32, diff --git a/services/distributedhardwarefwkservice/src/componentmanager/component_privacy.cpp b/services/distributedhardwarefwkservice/src/componentmanager/component_privacy.cpp index a740fbb8..b9bdd488 100644 --- a/services/distributedhardwarefwkservice/src/componentmanager/component_privacy.cpp +++ b/services/distributedhardwarefwkservice/src/componentmanager/component_privacy.cpp @@ -309,5 +309,48 @@ void ComponentPrivacy::ComponentEventHandler::ProcessStopPage(const AppExecFwk:: std::string subtype = cJSON_GetObjectItem(innerMsg, PRIVACY_SUBTYPE.c_str())->valuestring; comPrivacyObj_->StopPrivacePage(subtype); } + +bool ComponentPrivacy::IsIdenticalAccount(const std::string &networkId) +{ + 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; +} + +bool ComponentPrivacy::IsSensitiveResource() +{ + EnableParam param; + auto ret = GetEnableParam(networkId, uuid, dhId, dhType, param); + if (ret != DH_FWK_SUCCESS) { + DHLOGE("GetEnableParam failed, uuid = %{public}s, dhId = %{public}s, errCode = %{public}d", + GetAnonyString(uuid).c_str(), GetAnonyString(dhId).c_str(), ret); + if (RetryGetEnableParam(networkId, uuid, dhId, dhType, param) != DH_FWK_SUCCESS) { + return false; + } + } + 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 false; + } + + return resourceDesc[subtype]; +} + } // namespace DistributedHardware } // namespace OHOS 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..82d4193e --- /dev/null +++ b/services/distributedhardwarefwkservice/src/task/device_changed_task.cpp @@ -0,0 +1,119 @@ +/* + * 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 "dh_utils_tool.h" +#include "distributed_hardware_errno.h" +#include "distributed_hardware_log.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 online 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 online 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()); + 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; + } + + for (const auto &info : devDhInfos) { + //skip enabled component + std::string deviceKey = GetCapabilityKey(GetDeviceIdByUUID(GetUUID()), info.first); + auto enabledDevices = TaskBoard::GetEnabledDevice(); + 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..7592cf89 100644 --- a/services/distributedhardwarefwkservice/src/task/task_factory.cpp +++ b/services/distributedhardwarefwkservice/src/task/task_factory.cpp @@ -52,6 +52,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 4cd3a75ed869abf6a1900b3382dc958a705e6c5e Mon Sep 17 00:00:00 2001 From: saga Date: Sat, 25 May 2024 18:31:33 +0800 Subject: [PATCH 3/8] add device changed 2 Signed-off-by: saga --- .../src/distributed_hardware_manager_factory.cpp | 4 ---- 1 file changed, 4 deletions(-) diff --git a/services/distributedhardwarefwkservice/src/distributed_hardware_manager_factory.cpp b/services/distributedhardwarefwkservice/src/distributed_hardware_manager_factory.cpp index 1a3478e2..17e65851 100644 --- a/services/distributedhardwarefwkservice/src/distributed_hardware_manager_factory.cpp +++ b/services/distributedhardwarefwkservice/src/distributed_hardware_manager_factory.cpp @@ -217,11 +217,7 @@ int32_t DistributedHardwareManagerFactory::SendDeviceChangedEvent(const std::str DHLOGI("distributedHardwareMgr is null"); return ERR_DH_FWK_HARDWARE_MANAGER_DEVICE_NOT_ONLINE; } -<<<<<<< HEAD //if device not online, no need to handle device change event -======= - ->>>>>>> 4998d93c8291ecebbf5c402940f0f67c078794ac if (!DHContext::GetInstance().IsDeviceOnline(uuid)) { DHLOGI("Device not online, networkId: %{public}s, uuid: %{public}s", GetAnonyString(networkId).c_str(), GetAnonyString(uuid).c_str()); -- Gitee From 5d2491f9bcdbd62bcc51a7af21d53c1b2a9bc712 Mon Sep 17 00:00:00 2001 From: saga Date: Sat, 25 May 2024 18:31:33 +0800 Subject: [PATCH 4/8] add device changed 2 Signed-off-by: saga --- .../src/distributed_hardware_manager_factory.cpp | 4 ---- .../src/task/device_changed_task.cpp | 2 +- 2 files changed, 1 insertion(+), 5 deletions(-) diff --git a/services/distributedhardwarefwkservice/src/distributed_hardware_manager_factory.cpp b/services/distributedhardwarefwkservice/src/distributed_hardware_manager_factory.cpp index 1a3478e2..17e65851 100644 --- a/services/distributedhardwarefwkservice/src/distributed_hardware_manager_factory.cpp +++ b/services/distributedhardwarefwkservice/src/distributed_hardware_manager_factory.cpp @@ -217,11 +217,7 @@ int32_t DistributedHardwareManagerFactory::SendDeviceChangedEvent(const std::str DHLOGI("distributedHardwareMgr is null"); return ERR_DH_FWK_HARDWARE_MANAGER_DEVICE_NOT_ONLINE; } -<<<<<<< HEAD //if device not online, no need to handle device change event -======= - ->>>>>>> 4998d93c8291ecebbf5c402940f0f67c078794ac if (!DHContext::GetInstance().IsDeviceOnline(uuid)) { DHLOGI("Device not online, networkId: %{public}s, uuid: %{public}s", GetAnonyString(networkId).c_str(), GetAnonyString(uuid).c_str()); diff --git a/services/distributedhardwarefwkservice/src/task/device_changed_task.cpp b/services/distributedhardwarefwkservice/src/task/device_changed_task.cpp index 82d4193e..5c0eaca3 100644 --- a/services/distributedhardwarefwkservice/src/task/device_changed_task.cpp +++ b/services/distributedhardwarefwkservice/src/task/device_changed_task.cpp @@ -98,13 +98,13 @@ void DeviceChangedTask::HandleDeviceChanged() } for (const auto &info : devDhInfos) { + //skip enabled component std::string deviceKey = GetCapabilityKey(GetDeviceIdByUUID(GetUUID()), info.first); auto enabledDevices = TaskBoard::GetEnabledDevice(); if (enabledDevices.find(deviceKey) != enabledDevices.end()) { continue; } - TaskParam taskParam = { .networkId = GetNetworkId(), .uuid = GetUUID(), -- Gitee From e795ba05b9568ffac418bbaf7a00e7406e452b44 Mon Sep 17 00:00:00 2001 From: saga Date: Sun, 26 May 2024 17:59:22 +0800 Subject: [PATCH 5/8] when device info changed need to enable again Signed-off-by: saga --- .../include/task/device_changed_task.h | 2 +- .../src/task/device_changed_task.cpp | 3 +-- 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/services/distributedhardwarefwkservice/include/task/device_changed_task.h b/services/distributedhardwarefwkservice/include/task/device_changed_task.h index 792f85ae..2c685eb4 100644 --- a/services/distributedhardwarefwkservice/include/task/device_changed_task.h +++ b/services/distributedhardwarefwkservice/include/task/device_changed_task.h @@ -28,7 +28,7 @@ public: virtual void DoTask(); private: - //void DoSyncInfo(); + void HandleDeviceChanged(); //void CreateEnableTask(); }; } // namespace DistributedHardware diff --git a/services/distributedhardwarefwkservice/src/task/device_changed_task.cpp b/services/distributedhardwarefwkservice/src/task/device_changed_task.cpp index 82d4193e..79fcb6e4 100644 --- a/services/distributedhardwarefwkservice/src/task/device_changed_task.cpp +++ b/services/distributedhardwarefwkservice/src/task/device_changed_task.cpp @@ -97,14 +97,13 @@ void DeviceChangedTask::HandleDeviceChanged() return; } + auto enabledDevices = TaskBoard::GetEnabledDevice(); for (const auto &info : devDhInfos) { //skip enabled component std::string deviceKey = GetCapabilityKey(GetDeviceIdByUUID(GetUUID()), info.first); - auto enabledDevices = TaskBoard::GetEnabledDevice(); if (enabledDevices.find(deviceKey) != enabledDevices.end()) { continue; } - TaskParam taskParam = { .networkId = GetNetworkId(), .uuid = GetUUID(), -- Gitee From de2ce406f757856b77320c864d71e5efd0d93a0b Mon Sep 17 00:00:00 2001 From: saga Date: Mon, 27 May 2024 10:50:50 +0800 Subject: [PATCH 6/8] When the device information is changed, the distributed hardware needs to be re-enabled Signed-off-by: saga --- OAT.xml | 1 + application/AppScope/app.json | 4 +- application/AppScope/app.json5 | 4 +- .../entry/hvigorfile.ts | 23 +--- .../main/resources/bo_CN/element/string.json | 8 ++ .../mcc460-bo_CN/element/string.json | 8 ++ .../resources/mcc460-en/element/string.json | 8 ++ .../resources/mcc460-ug/element/string.json | 8 ++ .../mcc460-zh_CN/element/string.json | 8 ++ .../mcc460-zh_HK/element/string.json | 8 ++ .../mcc460-zh_TW/element/string.json | 8 ++ .../src/main/resources/ug/element/string.json | 8 ++ .../main/resources/zh_CN/element/string.json | 116 +++++++++--------- .../main/resources/zh_HK/element/string.json | 8 ++ .../main/resources/zh_TW/element/string.json | 8 ++ .../main/resources/zz_ZX/element/string.json | 16 +++ application/hvigorfile.ts | 21 ++++ bundle.json | 1 - .../distributedhardwarefwkservice/BUILD.gn | 3 +- .../componentmanager/component_manager.h | 5 +- .../componentmanager/component_privacy.h | 2 - .../include/task/device_changed_task.h | 1 - .../src/accessmanager/access_manager.cpp | 6 +- .../componentmanager/component_manager.cpp | 46 +++---- .../componentmanager/component_privacy.cpp | 43 ------- .../local_hardware_manager.cpp | 7 +- .../src/resourcemanager/db_adapter.cpp | 19 +-- .../local_capability_info_manager.cpp | 1 - .../src/task/device_changed_task.cpp | 8 +- .../src/task/monitor_task_timer.cpp | 75 ----------- .../src/task/task_factory.cpp | 1 + utils/BUILD.gn | 1 - 32 files changed, 236 insertions(+), 248 deletions(-) rename services/distributedhardwarefwkservice/include/task/monitor_task_timer.h => application/entry/hvigorfile.ts (52%) create mode 100644 application/entry/src/main/resources/mcc460-bo_CN/element/string.json create mode 100644 application/entry/src/main/resources/mcc460-en/element/string.json create mode 100644 application/entry/src/main/resources/mcc460-ug/element/string.json create mode 100644 application/entry/src/main/resources/mcc460-zh_CN/element/string.json create mode 100644 application/entry/src/main/resources/mcc460-zh_HK/element/string.json create mode 100644 application/entry/src/main/resources/mcc460-zh_TW/element/string.json create mode 100644 application/hvigorfile.ts delete mode 100644 services/distributedhardwarefwkservice/src/task/monitor_task_timer.cpp diff --git a/OAT.xml b/OAT.xml index 175029b2..0bb9efb6 100644 --- a/OAT.xml +++ b/OAT.xml @@ -59,6 +59,7 @@ Note:If the text contains special characters, please escape them according to th + diff --git a/application/AppScope/app.json b/application/AppScope/app.json index 9b8224c9..b90f1302 100644 --- a/application/AppScope/app.json +++ b/application/AppScope/app.json @@ -2,8 +2,8 @@ "app": { "bundleName": "com.ohos.dhardwareui", "vendor": "example", - "versionCode": 1000001, - "versionName": "1.0.1", + "versionCode": 1000002, + "versionName": "1.0.2", "icon": "$media:app_icon", "label": "$string:app_name", "minAPIVersion": 11, diff --git a/application/AppScope/app.json5 b/application/AppScope/app.json5 index 1b0c42e7..69262b14 100644 --- a/application/AppScope/app.json5 +++ b/application/AppScope/app.json5 @@ -16,8 +16,8 @@ "app": { "bundleName": "com.ohos.dhardwareui", "vendor": "example", - "versionCode": 1000001, - "versionName": "1.0.1", + "versionCode": 1000002, + "versionName": "1.0.2", "icon": "$media:app_icon", "label": "$string:app_name", "minAPIVersion": 11, diff --git a/services/distributedhardwarefwkservice/include/task/monitor_task_timer.h b/application/entry/hvigorfile.ts similarity index 52% rename from services/distributedhardwarefwkservice/include/task/monitor_task_timer.h rename to application/entry/hvigorfile.ts index 703da1b9..1c4ceb9e 100644 --- a/services/distributedhardwarefwkservice/include/task/monitor_task_timer.h +++ b/application/entry/hvigorfile.ts @@ -1,5 +1,5 @@ /* - * Copyright (c) 2022 Huawei Device Co., Ltd. + * Copyright (c) 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 @@ -13,22 +13,9 @@ * limitations under the License. */ -#ifndef OHOS_DISTRIBUTED_HARDWARE_MONITOR_TASK_TIMER_H -#define OHOS_DISTRIBUTED_HARDWARE_MONITOR_TASK_TIMER_H +import { hapTasks } from '@ohos/hvigor-ohos-plugin'; -#include "dh_timer.h" - -namespace OHOS { -namespace DistributedHardware { -class MonitorTaskTimer : public DHTimer { -public: - MonitorTaskTimer(std::string timerId, int32_t delayTimerMs); - ~MonitorTaskTimer() override; - -private: - void ExecuteInner() override; - void HandleStopTimer() override; +export default { + system: hapTasks, /* Built-in plugin of Hvigor. It cannot be modified. */ + plugins:[] /* Custom plugin to extend the functionality of Hvigor. */ }; -} // namespace DistributedHardware -} // namespace OHOS -#endif diff --git a/application/entry/src/main/resources/bo_CN/element/string.json b/application/entry/src/main/resources/bo_CN/element/string.json index cb47ab55..6bd9656c 100644 --- a/application/entry/src/main/resources/bo_CN/element/string.json +++ b/application/entry/src/main/resources/bo_CN/element/string.json @@ -27,6 +27,14 @@ { "name":"continue", "value":"མུ་མཐུད།" + }, + { + "name":"continue_desc", + "value":"སྒྲིག་ཆས་གཅིག་གི་ཐོག་ཏུ་བཤར་ལྟ་དང་རྩོམ་སྒྲིག་བྱས་རྗེས། ཉེ་འགྲམ་གྱི་ཧྭ་ཝེ་ཐོ་ཨང་གཅིག་པ་ཐོ་འཇུག་བྱས་ཡོད་པའི་སྒྲིག་ཆས་ཐོག་ཏུ་མུ་མཐུད་ཆོག རྩོལ་ནུས་འདི་བཀོལ་སྤྱོད་བྱ་བར་ཕྱོགས་གཉིས་པོས་༼འཕྲོ་མཐུད་༽ Wi-Fi དང་ སོ་སྔོན་ཁ་ཕྱེ་ནས་གནས་དགོས།" + }, + { + "name":"continue_title", + "value":"འཕྲོ་མཐུད།" } ] } \ No newline at end of file diff --git a/application/entry/src/main/resources/mcc460-bo_CN/element/string.json b/application/entry/src/main/resources/mcc460-bo_CN/element/string.json new file mode 100644 index 00000000..284cee98 --- /dev/null +++ b/application/entry/src/main/resources/mcc460-bo_CN/element/string.json @@ -0,0 +1,8 @@ +{ + "string":[ + { + "name":"continue_desc", + "value":"སྒྲིག་ཆས་གཅིག་གི་ཐོག་ཏུ་བཤར་ལྟ་དང་རྩོམ་སྒྲིག་བྱས་རྗེས། ཉེ་འགྲམ་གྱི་ཧྭ་ཝེ་ཐོ་ཨང་གཅིག་པ་ཐོ་འཇུག་བྱས་ཡོད་པའི་སྒྲིག་ཆས་ཐོག་ཏུ་མུ་མཐུད་ཆོག རྩོལ་ནུས་འདི་བཀོལ་སྤྱོད་བྱ་བར་ཕྱོགས་གཉིས་པོས་༼འཕྲོ་མཐུད་༽ WLAN དང་ སོ་སྔོན་ཁ་ཕྱེ་ནས་གནས་དགོས།" + } + ] +} \ No newline at end of file diff --git a/application/entry/src/main/resources/mcc460-en/element/string.json b/application/entry/src/main/resources/mcc460-en/element/string.json new file mode 100644 index 00000000..b55ac320 --- /dev/null +++ b/application/entry/src/main/resources/mcc460-en/element/string.json @@ -0,0 +1,8 @@ +{ + "string":[ + { + "name":"continue_desc", + "value":"Browse or edit on one device, then continue on another nearby device logged in with the same Huawei ID. This function requires that both devices have enabled \"Application connection,\" WLAN, and Bluetooth." + } + ] +} \ No newline at end of file diff --git a/application/entry/src/main/resources/mcc460-ug/element/string.json b/application/entry/src/main/resources/mcc460-ug/element/string.json new file mode 100644 index 00000000..985e2152 --- /dev/null +++ b/application/entry/src/main/resources/mcc460-ug/element/string.json @@ -0,0 +1,8 @@ +{ + "string":[ + { + "name":"continue_desc", + "value":"بىر ئۈسكۈنىدە كۆرۈۋاتقان ياكى تەھرىرلەۋاتقان ئىشنى ئەتراپتىكى ئوخشاش خۇاۋېي ھېسابىغا تىزىملاپ كىرگەن يەنە بىر ئۈسكۈنىدە داۋاملاشتۇرۇشقا بولىدۇ. ھەر ئىككى ئۈسكۈنىدە «ئۆتكۈزۈش»، WLAN ۋە كۆكچىش ئوچۇق بولۇشى كېرەك." + } + ] +} \ No newline at end of file diff --git a/application/entry/src/main/resources/mcc460-zh_CN/element/string.json b/application/entry/src/main/resources/mcc460-zh_CN/element/string.json new file mode 100644 index 00000000..8eeef049 --- /dev/null +++ b/application/entry/src/main/resources/mcc460-zh_CN/element/string.json @@ -0,0 +1,8 @@ +{ + "string":[ + { + "name":"continue_desc", + "value":"在一台设备上进行浏览或编辑,然后可在附近另一台登录相同华为帐号的设备上继续。此功能需双方设备开启“接续”、WLAN 和蓝牙。" + } + ] +} \ No newline at end of file diff --git a/application/entry/src/main/resources/mcc460-zh_HK/element/string.json b/application/entry/src/main/resources/mcc460-zh_HK/element/string.json new file mode 100644 index 00000000..2c7d4ff7 --- /dev/null +++ b/application/entry/src/main/resources/mcc460-zh_HK/element/string.json @@ -0,0 +1,8 @@ +{ + "string":[ + { + "name":"continue_desc", + "value":"在一部裝置上進行瀏覽或編輯,然後可在附近另一部登入相同華為帳戶的裝置上繼續。此功能需雙方裝置啟用「接續」、WLAN 和藍牙。" + } + ] +} \ No newline at end of file diff --git a/application/entry/src/main/resources/mcc460-zh_TW/element/string.json b/application/entry/src/main/resources/mcc460-zh_TW/element/string.json new file mode 100644 index 00000000..5db7559e --- /dev/null +++ b/application/entry/src/main/resources/mcc460-zh_TW/element/string.json @@ -0,0 +1,8 @@ +{ + "string":[ + { + "name":"continue_desc", + "value":"在一台裝置中瀏覽或編輯,然後可以在附近另一台登入相同華為 ID 的裝置中繼續。此功能需要兩台裝置皆已啟用「接續」、WLAN 和藍牙。" + } + ] +} \ No newline at end of file diff --git a/application/entry/src/main/resources/ug/element/string.json b/application/entry/src/main/resources/ug/element/string.json index b46b448c..e73f05a9 100644 --- a/application/entry/src/main/resources/ug/element/string.json +++ b/application/entry/src/main/resources/ug/element/string.json @@ -27,6 +27,14 @@ { "name":"continue", "value":"داۋاملاشتۇرۇش" + }, + { + "name":"continue_desc", + "value":"بىر ئۈسكۈنىدە كۆرۈۋاتقان ياكى تەھرىرلەۋاتقان ئىشنى ئەتراپتىكى ئوخشاش خۇاۋېي ھېسابىغا تىزىملاپ كىرگەن يەنە بىر ئۈسكۈنىدە داۋاملاشتۇرۇشقا بولىدۇ. ھەر ئىككى ئۈسكۈنىدە «ئۆتكۈزۈش»، Wi-Fi ۋە كۆكچىش ئوچۇق بولۇشى كېرەك." + }, + { + "name":"continue_title", + "value":"ئۆتكۈزۈش" } ] } \ No newline at end of file diff --git a/application/entry/src/main/resources/zh_CN/element/string.json b/application/entry/src/main/resources/zh_CN/element/string.json index 289fc27b..3f5c8ca4 100644 --- a/application/entry/src/main/resources/zh_CN/element/string.json +++ b/application/entry/src/main/resources/zh_CN/element/string.json @@ -1,60 +1,60 @@ { - "string": [ - { - "name": "module_desc", - "value": "模块描述" - }, - { - "name": "EntryAbility_desc", - "value": "description" - }, - { - "name": "EntryAbility_label", - "value": "分布式硬件控制UI" - }, - { - "name": "connected_to", - "value": "已连接至%1$s" - }, - { - "name": "stop_device", - "value": "您可以断开连接以停止使用此设备的%1$s" - }, - { - "name": "pause", - "value": "暂停" - }, - { - "name": "continue", - "value": "继续" - }, - { - "name": "DHTypeName_Camera", - "value": "相机" - }, - { - "name": "DHTypeName_Mic", - "value": "麦克风" - }, - { - "name": "disconnect", - "value": "断开连接" - }, - { - "name": "ContinueSwitchAbility_desc", - "value": "description" - }, - { - "name": "ContinueSwitchAbility_label", - "value": "label" - }, - { - "name": "continue_title", - "value": "接续" - }, - { - "name": "continue_desc", - "value": "在一台设备上进行浏览或编辑,然后可在附近另一台登录相同华为账号的设备上继续。此功能需双方设备开启“接续”,WLAN和蓝牙。" - } - ] + "string":[ + { + "name":"module_desc", + "value":"模块描述" + }, + { + "name":"EntryAbility_desc", + "value":"description" + }, + { + "name":"EntryAbility_label", + "value":"分布式硬件控制UI" + }, + { + "name":"connected_to", + "value":"已连接至%1$s" + }, + { + "name":"stop_device", + "value":"您可以断开连接以停止使用此设备的%1$s" + }, + { + "name":"pause", + "value":"暂停" + }, + { + "name":"continue", + "value":"继续" + }, + { + "name":"DHTypeName_Camera", + "value":"相机" + }, + { + "name":"DHTypeName_Mic", + "value":"麦克风" + }, + { + "name":"disconnect", + "value":"断开连接" + }, + { + "name":"ContinueSwitchAbility_desc", + "value":"description" + }, + { + "name":"ContinueSwitchAbility_label", + "value":"label" + }, + { + "name":"continue_title", + "value":"接续" + }, + { + "name":"continue_desc", + "value":"在一台设备上进行浏览或编辑,然后可在附近另一台登录相同华为帐号的设备上继续。此功能需双方设备开启“接续”、Wi-Fi 和蓝牙。" + } + ] } \ No newline at end of file diff --git a/application/entry/src/main/resources/zh_HK/element/string.json b/application/entry/src/main/resources/zh_HK/element/string.json index 2ce592dc..1a7562d8 100644 --- a/application/entry/src/main/resources/zh_HK/element/string.json +++ b/application/entry/src/main/resources/zh_HK/element/string.json @@ -27,6 +27,14 @@ { "name":"continue", "value":"繼續" + }, + { + "name":"continue_desc", + "value":"在一部裝置上進行瀏覽或編輯,然後可在附近另一部登入相同華為帳戶的裝置上繼續。此功能需雙方裝置啟用「接續」、Wi-Fi 和藍牙。" + }, + { + "name":"continue_title", + "value":"接續" } ] } \ No newline at end of file diff --git a/application/entry/src/main/resources/zh_TW/element/string.json b/application/entry/src/main/resources/zh_TW/element/string.json index b06bc7d1..b7da129b 100644 --- a/application/entry/src/main/resources/zh_TW/element/string.json +++ b/application/entry/src/main/resources/zh_TW/element/string.json @@ -27,6 +27,14 @@ { "name":"continue", "value":"繼續" + }, + { + "name":"continue_desc", + "value":"在一台裝置中瀏覽或編輯,然後可以在附近另一台登入相同華為 ID 的裝置中繼續。此功能需要兩台裝置皆已啟用「接續」、Wi-Fi 和藍牙。" + }, + { + "name":"continue_title", + "value":"接續" } ] } \ No newline at end of file diff --git a/application/entry/src/main/resources/zz_ZX/element/string.json b/application/entry/src/main/resources/zz_ZX/element/string.json index b70e661a..dbc9dba7 100644 --- a/application/entry/src/main/resources/zz_ZX/element/string.json +++ b/application/entry/src/main/resources/zz_ZX/element/string.json @@ -39,6 +39,22 @@ { "name":"continue", "value":"[TS_867711]_Resume" + }, + { + "name":"continue_desc", + "value":"[TS_921308]_Browse or edit on one device, then continue on another nearby device logged in with the same Huawei ID. This function requires that both devices have enabled \"Application connection,\" Wifi, and Bluetooth." + }, + { + "name":"ContinueSwitchAbility_label", + "value":"[TS_921307]_label" + }, + { + "name":"continue_title", + "value":"[TS_921305]_Continuation" + }, + { + "name":"ContinueSwitchAbility_desc", + "value":"[TS_921306]_description" } ] } \ No newline at end of file diff --git a/application/hvigorfile.ts b/application/hvigorfile.ts new file mode 100644 index 00000000..8096108d --- /dev/null +++ b/application/hvigorfile.ts @@ -0,0 +1,21 @@ +/* + * Copyright (c) 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. + */ + +import { appTasks } from '@ohos/hvigor-ohos-plugin'; + +export default { + system: appTasks, /* Built-in plugin of Hvigor. It cannot be modified. */ + plugins:[] /* Custom plugin to extend the functionality of Hvigor. */ +}; diff --git a/bundle.json b/bundle.json index 4f8e8db1..86b33cd7 100644 --- a/bundle.json +++ b/bundle.json @@ -55,7 +55,6 @@ "bounds_checking_function", "power_manager", "openssl", - "json", "ffmpeg", "zlib" ] diff --git a/services/distributedhardwarefwkservice/BUILD.gn b/services/distributedhardwarefwkservice/BUILD.gn index 92597676..08e875e7 100644 --- a/services/distributedhardwarefwkservice/BUILD.gn +++ b/services/distributedhardwarefwkservice/BUILD.gn @@ -95,9 +95,9 @@ ohos_shared_library("distributedhardwarefwksvr") { "src/resourcemanager/version_info_manager.cpp", "src/task/disable_task.cpp", "src/task/enable_task.cpp", - "src/task/monitor_task_timer.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", @@ -138,7 +138,6 @@ ohos_shared_library("distributedhardwarefwksvr") { "hitrace:hitrace_meter", "init:libbegetutil", "ipc:ipc_core", - "json:nlohmann_json_static", "kv_store:distributeddata_inner", "power_manager:powermgr_client", "resource_schedule_service:ressched_client", diff --git a/services/distributedhardwarefwkservice/include/componentmanager/component_manager.h b/services/distributedhardwarefwkservice/include/componentmanager/component_manager.h index 040d7f23..cdb9e2b9 100644 --- a/services/distributedhardwarefwkservice/include/componentmanager/component_manager.h +++ b/services/distributedhardwarefwkservice/include/componentmanager/component_manager.h @@ -34,7 +34,6 @@ #include "idistributed_hardware_source.h" #include "impl_utils.h" #include "low_latency_listener.h" -#include "monitor_task_timer.h" #include "meta_capability_info.h" #include "task_board.h" #include "task_factory.h" @@ -114,12 +113,12 @@ 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(); int32_t InitSAMonitor(); void StartComponent(); - void StartTaskMonitor(); void RegisterDHStateListener(); void RegisterDataSyncTriggerListener(); void InitDHCommTool(); @@ -128,7 +127,6 @@ private: void UnregisterDHStateListener(); void UnregisterDataSyncTriggerListener(); void UnInitDHCommTool(); - void StopTaskMonitor(); void StopComponent(); void StopPrivacy(); int32_t GetEnableCapParam(const std::string &networkId, const std::string &uuid, DHType dhType, EnableParam ¶m, @@ -147,7 +145,6 @@ private: std::shared_ptr cameraCompPrivacy_ = nullptr; std::shared_ptr compMonitorPtr_ = nullptr; sptr lowLatencyListener_ = nullptr; - std::shared_ptr monitorTaskTimer_ = nullptr; std::atomic isUnInitTimeOut_; // record the remote device business state, {{deviceUUID, dhId}, BusinessState}. diff --git a/services/distributedhardwarefwkservice/include/componentmanager/component_privacy.h b/services/distributedhardwarefwkservice/include/componentmanager/component_privacy.h index f5a0c2f1..72fa15af 100644 --- a/services/distributedhardwarefwkservice/include/componentmanager/component_privacy.h +++ b/services/distributedhardwarefwkservice/include/componentmanager/component_privacy.h @@ -39,8 +39,6 @@ public: void SetPageFlagTrue(); void SetPageFlagFalse(); bool GetPageFlag(); - bool IsSensitiveResource(); - bool IsIdenticalAccount(const std::string &networkId); class ComponentEventHandler : public AppExecFwk::EventHandler { public: diff --git a/services/distributedhardwarefwkservice/include/task/device_changed_task.h b/services/distributedhardwarefwkservice/include/task/device_changed_task.h index 2c685eb4..bd86723c 100644 --- a/services/distributedhardwarefwkservice/include/task/device_changed_task.h +++ b/services/distributedhardwarefwkservice/include/task/device_changed_task.h @@ -29,7 +29,6 @@ public: private: void HandleDeviceChanged(); - //void CreateEnableTask(); }; } // namespace DistributedHardware } // namespace OHOS diff --git a/services/distributedhardwarefwkservice/src/accessmanager/access_manager.cpp b/services/distributedhardwarefwkservice/src/accessmanager/access_manager.cpp index d67b9ae4..f10b8fa3 100644 --- a/services/distributedhardwarefwkservice/src/accessmanager/access_manager.cpp +++ b/services/distributedhardwarefwkservice/src/accessmanager/access_manager.cpp @@ -176,9 +176,8 @@ void AccessManager::OnDeviceReady(const DmDeviceInfo &deviceInfo) void AccessManager::OnDeviceChanged(const DmDeviceInfo &deviceInfo) { std::lock_guard lock(accessMutex_); - DHLOGI("start, networkId = %{public}s, deviceName = %{public}s, deviceTypeId = %{public}d", - GetAnonyString(deviceInfo.networkId).c_str(), GetAnonyString(deviceInfo.deviceName).c_str(), - deviceInfo.deviceTypeId); + 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) { @@ -190,6 +189,7 @@ void AccessManager::OnDeviceChanged(const DmDeviceInfo &deviceInfo) 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, diff --git a/services/distributedhardwarefwkservice/src/componentmanager/component_manager.cpp b/services/distributedhardwarefwkservice/src/componentmanager/component_manager.cpp index 7bf4bedb..c5b372f1 100644 --- a/services/distributedhardwarefwkservice/src/componentmanager/component_manager.cpp +++ b/services/distributedhardwarefwkservice/src/componentmanager/component_manager.cpp @@ -62,14 +62,12 @@ namespace { constexpr int32_t DISABLE_RETRY_MAX_TIMES = 3; constexpr int32_t ENABLE_PARAM_RETRY_TIME = 500 * 1000; constexpr int32_t INVALID_SA_ID = -1; - constexpr int32_t MONITOR_TASK_DELAY_MS = 5 * 1000; constexpr int32_t UNINIT_COMPONENT_TIMEOUT_SECONDS = 2; const std::string MONITOR_TASK_TIMER_ID = "monitor_task_timer_id"; } ComponentManager::ComponentManager() : compSource_({}), compSink_({}), compSrcSaId_({}), compMonitorPtr_(std::make_shared()), lowLatencyListener_(new(std::nothrow) LowLatencyListener), - monitorTaskTimer_(std::make_shared(MONITOR_TASK_TIMER_ID, MONITOR_TASK_DELAY_MS)), isUnInitTimeOut_(false), dhBizStates_({}), dhStateListener_(std::make_shared()), dataSyncTriggerListener_(std::make_shared()), dhCommToolPtr_(std::make_shared()), needRefreshTaskParams_({}) @@ -102,7 +100,6 @@ int32_t ComponentManager::Init() } StartComponent(); - StartTaskMonitor(); RegisterDHStateListener(); RegisterDataSyncTriggerListener(); InitDHCommTool(); @@ -163,13 +160,6 @@ void ComponentManager::StartComponent() } } -void ComponentManager::StartTaskMonitor() -{ - if (monitorTaskTimer_ != nullptr) { - monitorTaskTimer_->StartTimer(); - } -} - void ComponentManager::RegisterDHStateListener() { for (const auto &item : compSource_) { @@ -213,7 +203,6 @@ int32_t ComponentManager::UnInit() UnregisterDHStateListener(); UnregisterDataSyncTriggerListener(); UnInitDHCommTool(); - StopTaskMonitor(); StopPrivacy(); UnInitSAMonitor(); StopComponent(); @@ -281,14 +270,6 @@ void ComponentManager::UnInitDHCommTool() dhCommToolPtr_->UnInit(); } -void ComponentManager::StopTaskMonitor() -{ - // stop monitor task timer - if (monitorTaskTimer_ != nullptr) { - monitorTaskTimer_->StopTimer(); - } -} - void ComponentManager::StopComponent() { // stop source and sink sa @@ -719,14 +700,14 @@ int32_t ComponentManager::GetCapParam(const std::string &uuid, const std::string std::string deviceId = GetDeviceIdByUUID(uuid); auto ret = CapabilityInfoManager::GetInstance()->GetCapability(deviceId, dhId, capability); if ((ret == DH_FWK_SUCCESS) && (capability != nullptr)) { - DHLOGE("GetCapability success, deviceId: %{public}s, uuid: %{public}s, dhId: %{public}s, ret: %{public}d", + DHLOGI("GetCapability success, deviceId: %{public}s, uuid: %{public}s, dhId: %{public}s, ret: %{public}d", GetAnonyString(deviceId).c_str(), GetAnonyString(uuid).c_str(), GetAnonyString(dhId).c_str(), ret); return ret; } ret = LocalCapabilityInfoManager::GetInstance()->GetCapability(deviceId, dhId, capability); if ((ret == DH_FWK_SUCCESS) && (capability != nullptr)) { - DHLOGE("Local GetCaps success, deviceId: %{public}s, uuid: %{public}s, dhId: %{public}s, ret: %{public}d", + DHLOGI("Local GetCaps success, deviceId: %{public}s, uuid: %{public}s, dhId: %{public}s, ret: %{public}d", GetAnonyString(deviceId).c_str(), GetAnonyString(uuid).c_str(), GetAnonyString(dhId).c_str(), ret); return ret; } @@ -739,7 +720,7 @@ int32_t ComponentManager::GetMetaParam(const std::string &uuid, const std::strin { auto ret = MetaInfoManager::GetInstance()->GetMetaCapInfo(GetDeviceIdByUUID(uuid), dhId, metaCapPtr); if ((ret == DH_FWK_SUCCESS) && (metaCapPtr != nullptr)) { - DHLOGE("GetCapability success, uuid =%{public}s, dhId = %{public}s, errCode = %{public}d", + DHLOGI("GetCapability success, uuid =%{public}s, dhId = %{public}s, errCode = %{public}d", GetAnonyString(uuid).c_str(), GetAnonyString(dhId).c_str(), ret); return ret; } @@ -913,6 +894,27 @@ std::map ComponentManager::GetDHSinkInstance( return compSink_; } +bool ComponentManager::IsIdenticalAccount(const std::string &networkId) +{ + 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) { DHLOGI("UpdateBusinessState, networkId: %{public}s, dhId: %{public}s, state: %{public}" PRIu32, diff --git a/services/distributedhardwarefwkservice/src/componentmanager/component_privacy.cpp b/services/distributedhardwarefwkservice/src/componentmanager/component_privacy.cpp index b9bdd488..a740fbb8 100644 --- a/services/distributedhardwarefwkservice/src/componentmanager/component_privacy.cpp +++ b/services/distributedhardwarefwkservice/src/componentmanager/component_privacy.cpp @@ -309,48 +309,5 @@ void ComponentPrivacy::ComponentEventHandler::ProcessStopPage(const AppExecFwk:: std::string subtype = cJSON_GetObjectItem(innerMsg, PRIVACY_SUBTYPE.c_str())->valuestring; comPrivacyObj_->StopPrivacePage(subtype); } - -bool ComponentPrivacy::IsIdenticalAccount(const std::string &networkId) -{ - 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; -} - -bool ComponentPrivacy::IsSensitiveResource() -{ - EnableParam param; - auto ret = GetEnableParam(networkId, uuid, dhId, dhType, param); - if (ret != DH_FWK_SUCCESS) { - DHLOGE("GetEnableParam failed, uuid = %{public}s, dhId = %{public}s, errCode = %{public}d", - GetAnonyString(uuid).c_str(), GetAnonyString(dhId).c_str(), ret); - if (RetryGetEnableParam(networkId, uuid, dhId, dhType, param) != DH_FWK_SUCCESS) { - return false; - } - } - 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 false; - } - - return resourceDesc[subtype]; -} - } // namespace DistributedHardware } // namespace OHOS diff --git a/services/distributedhardwarefwkservice/src/localhardwaremanager/local_hardware_manager.cpp b/services/distributedhardwarefwkservice/src/localhardwaremanager/local_hardware_manager.cpp index 5812b213..8a52d1b4 100644 --- a/services/distributedhardwarefwkservice/src/localhardwaremanager/local_hardware_manager.cpp +++ b/services/distributedhardwarefwkservice/src/localhardwaremanager/local_hardware_manager.cpp @@ -116,8 +116,7 @@ void LocalHardwareManager::QueryLocalHardware(const DHType dhType, IHardwareHand DHLOGE("Query hardwareHandler and obtain empty, dhType: %{public}#X", dhType); usleep(QUERY_INTERVAL_TIME); } else { - DHLOGI("Query hardwareHandler success, dhType: %{public}#X!, size: %{public}d", - dhType, static_cast(dhItems.size())); + DHLOGI("Query hardwareHandler success, dhType: %{public}#X!, size: %{public}zu", dhType, dhItems.size()); /* * Failed to delete data when the device restarts or other exception situation. * So check and remove the non-exist local capabilityInfo. @@ -141,8 +140,8 @@ void LocalHardwareManager::QueryMetaHardware(const DHType dhType, IHardwareHandl DHLOGE("Query metahardwareHandler and obtain empty, dhType: %{public}#X", dhType); usleep(QUERY_INTERVAL_TIME); } else { - DHLOGI("Query metahardwareHandler success, dhType: %{public}#X!, size: %{public}d", - dhType, static_cast(metaDhItems.size())); + DHLOGI("Query metahardwareHandler success, dhType: %{public}#X!, size: %{public}zu", + dhType, metaDhItems.size()); metaDHItemsMap_[dhType] = metaDhItems; break; } diff --git a/services/distributedhardwarefwkservice/src/resourcemanager/db_adapter.cpp b/services/distributedhardwarefwkservice/src/resourcemanager/db_adapter.cpp index 75548046..e34aee75 100644 --- a/services/distributedhardwarefwkservice/src/resourcemanager/db_adapter.cpp +++ b/services/distributedhardwarefwkservice/src/resourcemanager/db_adapter.cpp @@ -98,7 +98,10 @@ DistributedKv::Status DBAdapter::GetLocalKvStorePtr() int32_t DBAdapter::Init(bool isAutoSync, DistributedKv::DataType dataType) { - DHLOGI("Init DB, storeId: %{public}s", storeId_.storeId.c_str()); + this->isAutoSync = isAutoSync; + this->dataType = dataType; + DHLOGI("Init DB, storeId: %{public}s, dataType: %{public}d", + storeId_.storeId.c_str(), static_cast(dataType)); std::lock_guard lock(dbAdapterMutex_); int32_t tryTimes = MAX_INIT_RETRY_TIMES; while (tryTimes > 0) { @@ -123,14 +126,15 @@ int32_t DBAdapter::Init(bool isAutoSync, DistributedKv::DataType dataType) DHLOGE("Init KvStorePtr failed"); return ERR_DH_FWK_RESOURCE_KV_STORAGE_POINTER_NULL; } - this->isAutoSync = isAutoSync; - this->dataType = dataType; return DH_FWK_SUCCESS; } int32_t DBAdapter::InitLocal() { - DHLOGI("Init local DB, storeId: %{public}s", storeId_.storeId.c_str()); + this->isAutoSync = false; + this->dataType = DistributedKv::DataType::TYPE_STATICS; + DHLOGI("Init local DB, storeId: %{public}s, dataType: %{public}d", + storeId_.storeId.c_str(), static_cast(this->dataType)); std::lock_guard lock(dbAdapterMutex_); int32_t tryTimes = MAX_INIT_RETRY_TIMES; while (tryTimes > 0) { @@ -148,7 +152,6 @@ int32_t DBAdapter::InitLocal() DHLOGE("Init KvStorePtr failed"); return ERR_DH_FWK_RESOURCE_KV_STORAGE_POINTER_NULL; } - this->isAutoSync = false; return DH_FWK_SUCCESS; } @@ -229,7 +232,8 @@ void DBAdapter::TriggerDynamicQuery(const std::string &key) int32_t DBAdapter::GetDataByKey(const std::string &key, std::string &data) { - DHLOGI("Get data by key: %{public}s", GetAnonyString(key).c_str()); + DHLOGI("Get data by key: %{public}s, storeId: %{public}s, dataType: %{public}d", + GetAnonyString(key).c_str(), storeId_.storeId.c_str(), static_cast(this->dataType)); std::lock_guard lock(dbAdapterMutex_); if (kvStoragePtr_ == nullptr) { DHLOGE("kvStoragePtr_ is null"); @@ -251,7 +255,8 @@ int32_t DBAdapter::GetDataByKey(const std::string &key, std::string &data) int32_t DBAdapter::GetDataByKeyPrefix(const std::string &keyPrefix, std::vector &values) { - DHLOGI("Get data by key prefix: %{public}s", GetAnonyString(keyPrefix).c_str()); + DHLOGI("Get data by key prefix: %{public}s, storeId: %{public}s, dataType: %{public}d", + GetAnonyString(keyPrefix).c_str(), storeId_.storeId.c_str(), static_cast(this->dataType)); std::lock_guard lock(dbAdapterMutex_); if (kvStoragePtr_ == nullptr) { DHLOGE("kvStoragePtr_ is null"); diff --git a/services/distributedhardwarefwkservice/src/resourcemanager/local_capability_info_manager.cpp b/services/distributedhardwarefwkservice/src/resourcemanager/local_capability_info_manager.cpp index 6e2f56ea..574e9842 100644 --- a/services/distributedhardwarefwkservice/src/resourcemanager/local_capability_info_manager.cpp +++ b/services/distributedhardwarefwkservice/src/resourcemanager/local_capability_info_manager.cpp @@ -123,7 +123,6 @@ int32_t LocalCapabilityInfoManager::AddCapability(const std::vector keys; std::vector values; std::string key; - std::string data; for (auto &resInfo : resInfos) { if (resInfo == nullptr) { continue; diff --git a/services/distributedhardwarefwkservice/src/task/device_changed_task.cpp b/services/distributedhardwarefwkservice/src/task/device_changed_task.cpp index 51786321..16602268 100644 --- a/services/distributedhardwarefwkservice/src/task/device_changed_task.cpp +++ b/services/distributedhardwarefwkservice/src/task/device_changed_task.cpp @@ -16,9 +16,13 @@ #include "device_changed_task.h" #include "anonymous_string.h" +#include "capability_info_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" @@ -43,7 +47,7 @@ DeviceChangedTask::~DeviceChangedTask() void DeviceChangedTask::DoTask() { - DHLOGD("start online task, id = %{public}s, uuid = %{public}s", GetId().c_str(), GetAnonyString(GetUUID()).c_str()); + 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) { @@ -57,7 +61,7 @@ void DeviceChangedTask::DoTask() } } SetTaskState(TaskState::SUCCESS); - DHLOGD("finish online task, remove it, id = %{public}s.", GetId().c_str()); + DHLOGD("finish device changed task, remove it, id = %{public}s.", GetId().c_str()); TaskBoard::GetInstance().RemoveTask(this->GetId()); } diff --git a/services/distributedhardwarefwkservice/src/task/monitor_task_timer.cpp b/services/distributedhardwarefwkservice/src/task/monitor_task_timer.cpp deleted file mode 100644 index d02e8a97..00000000 --- a/services/distributedhardwarefwkservice/src/task/monitor_task_timer.cpp +++ /dev/null @@ -1,75 +0,0 @@ -/* - * Copyright (c) 2022-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 "monitor_task_timer.h" - -#include "anonymous_string.h" -#include "capability_info.h" -#include "capability_info_manager.h" -#include "distributed_hardware_errno.h" -#include "distributed_hardware_log.h" -#include "dh_timer.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 "MonitorTaskTimer" -MonitorTaskTimer::MonitorTaskTimer(std::string timerId, int32_t delayTimeMs) : DHTimer(timerId, delayTimeMs) -{ - DHLOGI("MonitorTaskTimer ctor!"); -} - -MonitorTaskTimer::~MonitorTaskTimer() -{ - DHLOGI("MonitorTaskTimer dtor!"); -} - -void MonitorTaskTimer::ExecuteInner() -{ - DHLOGD("ExecuteInner!"); - auto enabledDevices = TaskBoard::GetInstance().GetEnabledDevice(); - std::shared_ptr capInfoPtr = nullptr; - TaskParam taskParam; - std::string capabilityKey; - for (auto item : enabledDevices) { - capabilityKey = item.first; - taskParam = item.second; - if (taskParam.dhType != DHType::INPUT) { - continue; - } - if (CapabilityInfoManager::GetInstance()->GetDataByKey(capabilityKey, capInfoPtr) != DH_FWK_SUCCESS) { - DHLOGI("CapabilityInfoManager can not find this key in DB, key: %{public}s, networkId: %{public}s, " - "uuid: %{public}s, dhId: %{public}s", GetAnonyString(capabilityKey).c_str(), - GetAnonyString(taskParam.networkId).c_str(), GetAnonyString(taskParam.uuid).c_str(), - GetAnonyString(taskParam.dhId).c_str()); - auto task = TaskFactory::GetInstance().CreateTask(TaskType::DISABLE, taskParam, nullptr); - TaskExecutor::GetInstance().PushTask(task); - } - } - - if (capInfoPtr != nullptr) { - capInfoPtr = nullptr; - } -} - -void MonitorTaskTimer::HandleStopTimer() -{ - DHLOGI("HandleStopTimer!"); -} -} // namespace DistributedHardware -} // namespace OHOS diff --git a/services/distributedhardwarefwkservice/src/task/task_factory.cpp b/services/distributedhardwarefwkservice/src/task/task_factory.cpp index 7592cf89..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 { diff --git a/utils/BUILD.gn b/utils/BUILD.gn index a8988f47..8f822fad 100644 --- a/utils/BUILD.gn +++ b/utils/BUILD.gn @@ -65,7 +65,6 @@ ohos_shared_library("distributedhardwareutils") { "hilog:libhilog", "hisysevent:libhisysevent", "hitrace:hitrace_meter", - "json:nlohmann_json_static", "openssl:libcrypto_shared", "safwk:system_ability_fwk", "zlib:shared_libz", -- Gitee From 1d0fe615e52d28e7f41d753267acd1e03f8920ce Mon Sep 17 00:00:00 2001 From: saga Date: Mon, 27 May 2024 10:50:50 +0800 Subject: [PATCH 7/8] When the device information is changed, the distributed hardware needs to be re-enabled Signed-off-by: saga --- OAT.xml | 1 + application/AppScope/app.json | 4 +- application/AppScope/app.json5 | 4 +- .../entry/hvigorfile.ts | 23 +--- .../main/resources/bo_CN/element/string.json | 8 ++ .../mcc460-bo_CN/element/string.json | 8 ++ .../resources/mcc460-en/element/string.json | 8 ++ .../resources/mcc460-ug/element/string.json | 8 ++ .../mcc460-zh_CN/element/string.json | 8 ++ .../mcc460-zh_HK/element/string.json | 8 ++ .../mcc460-zh_TW/element/string.json | 8 ++ .../src/main/resources/ug/element/string.json | 8 ++ .../main/resources/zh_CN/element/string.json | 116 +++++++++--------- .../main/resources/zh_HK/element/string.json | 8 ++ .../main/resources/zh_TW/element/string.json | 8 ++ .../main/resources/zz_ZX/element/string.json | 16 +++ application/hvigorfile.ts | 21 ++++ bundle.json | 1 - .../include/idistributed_hardware_manager.h | 2 + .../distributedhardwarefwkservice/BUILD.gn | 3 +- .../componentmanager/component_manager.h | 6 +- .../componentmanager/component_privacy.h | 2 - .../include/task/device_changed_task.h | 1 - .../src/accessmanager/access_manager.cpp | 6 +- .../componentmanager/component_manager.cpp | 46 +++---- .../componentmanager/component_privacy.cpp | 43 ------- .../local_hardware_manager.cpp | 7 +- .../src/resourcemanager/db_adapter.cpp | 19 +-- .../local_capability_info_manager.cpp | 1 - .../src/task/device_changed_task.cpp | 11 +- .../src/task/monitor_task_timer.cpp | 75 ----------- .../src/task/task_factory.cpp | 1 + utils/BUILD.gn | 1 - 33 files changed, 240 insertions(+), 250 deletions(-) rename services/distributedhardwarefwkservice/include/task/monitor_task_timer.h => application/entry/hvigorfile.ts (52%) create mode 100644 application/entry/src/main/resources/mcc460-bo_CN/element/string.json create mode 100644 application/entry/src/main/resources/mcc460-en/element/string.json create mode 100644 application/entry/src/main/resources/mcc460-ug/element/string.json create mode 100644 application/entry/src/main/resources/mcc460-zh_CN/element/string.json create mode 100644 application/entry/src/main/resources/mcc460-zh_HK/element/string.json create mode 100644 application/entry/src/main/resources/mcc460-zh_TW/element/string.json create mode 100644 application/hvigorfile.ts delete mode 100644 services/distributedhardwarefwkservice/src/task/monitor_task_timer.cpp diff --git a/OAT.xml b/OAT.xml index 175029b2..0bb9efb6 100644 --- a/OAT.xml +++ b/OAT.xml @@ -59,6 +59,7 @@ Note:If the text contains special characters, please escape them according to th + diff --git a/application/AppScope/app.json b/application/AppScope/app.json index 9b8224c9..b90f1302 100644 --- a/application/AppScope/app.json +++ b/application/AppScope/app.json @@ -2,8 +2,8 @@ "app": { "bundleName": "com.ohos.dhardwareui", "vendor": "example", - "versionCode": 1000001, - "versionName": "1.0.1", + "versionCode": 1000002, + "versionName": "1.0.2", "icon": "$media:app_icon", "label": "$string:app_name", "minAPIVersion": 11, diff --git a/application/AppScope/app.json5 b/application/AppScope/app.json5 index 1b0c42e7..69262b14 100644 --- a/application/AppScope/app.json5 +++ b/application/AppScope/app.json5 @@ -16,8 +16,8 @@ "app": { "bundleName": "com.ohos.dhardwareui", "vendor": "example", - "versionCode": 1000001, - "versionName": "1.0.1", + "versionCode": 1000002, + "versionName": "1.0.2", "icon": "$media:app_icon", "label": "$string:app_name", "minAPIVersion": 11, diff --git a/services/distributedhardwarefwkservice/include/task/monitor_task_timer.h b/application/entry/hvigorfile.ts similarity index 52% rename from services/distributedhardwarefwkservice/include/task/monitor_task_timer.h rename to application/entry/hvigorfile.ts index 703da1b9..1c4ceb9e 100644 --- a/services/distributedhardwarefwkservice/include/task/monitor_task_timer.h +++ b/application/entry/hvigorfile.ts @@ -1,5 +1,5 @@ /* - * Copyright (c) 2022 Huawei Device Co., Ltd. + * Copyright (c) 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 @@ -13,22 +13,9 @@ * limitations under the License. */ -#ifndef OHOS_DISTRIBUTED_HARDWARE_MONITOR_TASK_TIMER_H -#define OHOS_DISTRIBUTED_HARDWARE_MONITOR_TASK_TIMER_H +import { hapTasks } from '@ohos/hvigor-ohos-plugin'; -#include "dh_timer.h" - -namespace OHOS { -namespace DistributedHardware { -class MonitorTaskTimer : public DHTimer { -public: - MonitorTaskTimer(std::string timerId, int32_t delayTimerMs); - ~MonitorTaskTimer() override; - -private: - void ExecuteInner() override; - void HandleStopTimer() override; +export default { + system: hapTasks, /* Built-in plugin of Hvigor. It cannot be modified. */ + plugins:[] /* Custom plugin to extend the functionality of Hvigor. */ }; -} // namespace DistributedHardware -} // namespace OHOS -#endif diff --git a/application/entry/src/main/resources/bo_CN/element/string.json b/application/entry/src/main/resources/bo_CN/element/string.json index cb47ab55..6bd9656c 100644 --- a/application/entry/src/main/resources/bo_CN/element/string.json +++ b/application/entry/src/main/resources/bo_CN/element/string.json @@ -27,6 +27,14 @@ { "name":"continue", "value":"མུ་མཐུད།" + }, + { + "name":"continue_desc", + "value":"སྒྲིག་ཆས་གཅིག་གི་ཐོག་ཏུ་བཤར་ལྟ་དང་རྩོམ་སྒྲིག་བྱས་རྗེས། ཉེ་འགྲམ་གྱི་ཧྭ་ཝེ་ཐོ་ཨང་གཅིག་པ་ཐོ་འཇུག་བྱས་ཡོད་པའི་སྒྲིག་ཆས་ཐོག་ཏུ་མུ་མཐུད་ཆོག རྩོལ་ནུས་འདི་བཀོལ་སྤྱོད་བྱ་བར་ཕྱོགས་གཉིས་པོས་༼འཕྲོ་མཐུད་༽ Wi-Fi དང་ སོ་སྔོན་ཁ་ཕྱེ་ནས་གནས་དགོས།" + }, + { + "name":"continue_title", + "value":"འཕྲོ་མཐུད།" } ] } \ No newline at end of file diff --git a/application/entry/src/main/resources/mcc460-bo_CN/element/string.json b/application/entry/src/main/resources/mcc460-bo_CN/element/string.json new file mode 100644 index 00000000..284cee98 --- /dev/null +++ b/application/entry/src/main/resources/mcc460-bo_CN/element/string.json @@ -0,0 +1,8 @@ +{ + "string":[ + { + "name":"continue_desc", + "value":"སྒྲིག་ཆས་གཅིག་གི་ཐོག་ཏུ་བཤར་ལྟ་དང་རྩོམ་སྒྲིག་བྱས་རྗེས། ཉེ་འགྲམ་གྱི་ཧྭ་ཝེ་ཐོ་ཨང་གཅིག་པ་ཐོ་འཇུག་བྱས་ཡོད་པའི་སྒྲིག་ཆས་ཐོག་ཏུ་མུ་མཐུད་ཆོག རྩོལ་ནུས་འདི་བཀོལ་སྤྱོད་བྱ་བར་ཕྱོགས་གཉིས་པོས་༼འཕྲོ་མཐུད་༽ WLAN དང་ སོ་སྔོན་ཁ་ཕྱེ་ནས་གནས་དགོས།" + } + ] +} \ No newline at end of file diff --git a/application/entry/src/main/resources/mcc460-en/element/string.json b/application/entry/src/main/resources/mcc460-en/element/string.json new file mode 100644 index 00000000..b55ac320 --- /dev/null +++ b/application/entry/src/main/resources/mcc460-en/element/string.json @@ -0,0 +1,8 @@ +{ + "string":[ + { + "name":"continue_desc", + "value":"Browse or edit on one device, then continue on another nearby device logged in with the same Huawei ID. This function requires that both devices have enabled \"Application connection,\" WLAN, and Bluetooth." + } + ] +} \ No newline at end of file diff --git a/application/entry/src/main/resources/mcc460-ug/element/string.json b/application/entry/src/main/resources/mcc460-ug/element/string.json new file mode 100644 index 00000000..985e2152 --- /dev/null +++ b/application/entry/src/main/resources/mcc460-ug/element/string.json @@ -0,0 +1,8 @@ +{ + "string":[ + { + "name":"continue_desc", + "value":"بىر ئۈسكۈنىدە كۆرۈۋاتقان ياكى تەھرىرلەۋاتقان ئىشنى ئەتراپتىكى ئوخشاش خۇاۋېي ھېسابىغا تىزىملاپ كىرگەن يەنە بىر ئۈسكۈنىدە داۋاملاشتۇرۇشقا بولىدۇ. ھەر ئىككى ئۈسكۈنىدە «ئۆتكۈزۈش»، WLAN ۋە كۆكچىش ئوچۇق بولۇشى كېرەك." + } + ] +} \ No newline at end of file diff --git a/application/entry/src/main/resources/mcc460-zh_CN/element/string.json b/application/entry/src/main/resources/mcc460-zh_CN/element/string.json new file mode 100644 index 00000000..8eeef049 --- /dev/null +++ b/application/entry/src/main/resources/mcc460-zh_CN/element/string.json @@ -0,0 +1,8 @@ +{ + "string":[ + { + "name":"continue_desc", + "value":"在一台设备上进行浏览或编辑,然后可在附近另一台登录相同华为帐号的设备上继续。此功能需双方设备开启“接续”、WLAN 和蓝牙。" + } + ] +} \ No newline at end of file diff --git a/application/entry/src/main/resources/mcc460-zh_HK/element/string.json b/application/entry/src/main/resources/mcc460-zh_HK/element/string.json new file mode 100644 index 00000000..2c7d4ff7 --- /dev/null +++ b/application/entry/src/main/resources/mcc460-zh_HK/element/string.json @@ -0,0 +1,8 @@ +{ + "string":[ + { + "name":"continue_desc", + "value":"在一部裝置上進行瀏覽或編輯,然後可在附近另一部登入相同華為帳戶的裝置上繼續。此功能需雙方裝置啟用「接續」、WLAN 和藍牙。" + } + ] +} \ No newline at end of file diff --git a/application/entry/src/main/resources/mcc460-zh_TW/element/string.json b/application/entry/src/main/resources/mcc460-zh_TW/element/string.json new file mode 100644 index 00000000..5db7559e --- /dev/null +++ b/application/entry/src/main/resources/mcc460-zh_TW/element/string.json @@ -0,0 +1,8 @@ +{ + "string":[ + { + "name":"continue_desc", + "value":"在一台裝置中瀏覽或編輯,然後可以在附近另一台登入相同華為 ID 的裝置中繼續。此功能需要兩台裝置皆已啟用「接續」、WLAN 和藍牙。" + } + ] +} \ No newline at end of file diff --git a/application/entry/src/main/resources/ug/element/string.json b/application/entry/src/main/resources/ug/element/string.json index b46b448c..e73f05a9 100644 --- a/application/entry/src/main/resources/ug/element/string.json +++ b/application/entry/src/main/resources/ug/element/string.json @@ -27,6 +27,14 @@ { "name":"continue", "value":"داۋاملاشتۇرۇش" + }, + { + "name":"continue_desc", + "value":"بىر ئۈسكۈنىدە كۆرۈۋاتقان ياكى تەھرىرلەۋاتقان ئىشنى ئەتراپتىكى ئوخشاش خۇاۋېي ھېسابىغا تىزىملاپ كىرگەن يەنە بىر ئۈسكۈنىدە داۋاملاشتۇرۇشقا بولىدۇ. ھەر ئىككى ئۈسكۈنىدە «ئۆتكۈزۈش»، Wi-Fi ۋە كۆكچىش ئوچۇق بولۇشى كېرەك." + }, + { + "name":"continue_title", + "value":"ئۆتكۈزۈش" } ] } \ No newline at end of file diff --git a/application/entry/src/main/resources/zh_CN/element/string.json b/application/entry/src/main/resources/zh_CN/element/string.json index 289fc27b..3f5c8ca4 100644 --- a/application/entry/src/main/resources/zh_CN/element/string.json +++ b/application/entry/src/main/resources/zh_CN/element/string.json @@ -1,60 +1,60 @@ { - "string": [ - { - "name": "module_desc", - "value": "模块描述" - }, - { - "name": "EntryAbility_desc", - "value": "description" - }, - { - "name": "EntryAbility_label", - "value": "分布式硬件控制UI" - }, - { - "name": "connected_to", - "value": "已连接至%1$s" - }, - { - "name": "stop_device", - "value": "您可以断开连接以停止使用此设备的%1$s" - }, - { - "name": "pause", - "value": "暂停" - }, - { - "name": "continue", - "value": "继续" - }, - { - "name": "DHTypeName_Camera", - "value": "相机" - }, - { - "name": "DHTypeName_Mic", - "value": "麦克风" - }, - { - "name": "disconnect", - "value": "断开连接" - }, - { - "name": "ContinueSwitchAbility_desc", - "value": "description" - }, - { - "name": "ContinueSwitchAbility_label", - "value": "label" - }, - { - "name": "continue_title", - "value": "接续" - }, - { - "name": "continue_desc", - "value": "在一台设备上进行浏览或编辑,然后可在附近另一台登录相同华为账号的设备上继续。此功能需双方设备开启“接续”,WLAN和蓝牙。" - } - ] + "string":[ + { + "name":"module_desc", + "value":"模块描述" + }, + { + "name":"EntryAbility_desc", + "value":"description" + }, + { + "name":"EntryAbility_label", + "value":"分布式硬件控制UI" + }, + { + "name":"connected_to", + "value":"已连接至%1$s" + }, + { + "name":"stop_device", + "value":"您可以断开连接以停止使用此设备的%1$s" + }, + { + "name":"pause", + "value":"暂停" + }, + { + "name":"continue", + "value":"继续" + }, + { + "name":"DHTypeName_Camera", + "value":"相机" + }, + { + "name":"DHTypeName_Mic", + "value":"麦克风" + }, + { + "name":"disconnect", + "value":"断开连接" + }, + { + "name":"ContinueSwitchAbility_desc", + "value":"description" + }, + { + "name":"ContinueSwitchAbility_label", + "value":"label" + }, + { + "name":"continue_title", + "value":"接续" + }, + { + "name":"continue_desc", + "value":"在一台设备上进行浏览或编辑,然后可在附近另一台登录相同华为帐号的设备上继续。此功能需双方设备开启“接续”、Wi-Fi 和蓝牙。" + } + ] } \ No newline at end of file diff --git a/application/entry/src/main/resources/zh_HK/element/string.json b/application/entry/src/main/resources/zh_HK/element/string.json index 2ce592dc..1a7562d8 100644 --- a/application/entry/src/main/resources/zh_HK/element/string.json +++ b/application/entry/src/main/resources/zh_HK/element/string.json @@ -27,6 +27,14 @@ { "name":"continue", "value":"繼續" + }, + { + "name":"continue_desc", + "value":"在一部裝置上進行瀏覽或編輯,然後可在附近另一部登入相同華為帳戶的裝置上繼續。此功能需雙方裝置啟用「接續」、Wi-Fi 和藍牙。" + }, + { + "name":"continue_title", + "value":"接續" } ] } \ No newline at end of file diff --git a/application/entry/src/main/resources/zh_TW/element/string.json b/application/entry/src/main/resources/zh_TW/element/string.json index b06bc7d1..b7da129b 100644 --- a/application/entry/src/main/resources/zh_TW/element/string.json +++ b/application/entry/src/main/resources/zh_TW/element/string.json @@ -27,6 +27,14 @@ { "name":"continue", "value":"繼續" + }, + { + "name":"continue_desc", + "value":"在一台裝置中瀏覽或編輯,然後可以在附近另一台登入相同華為 ID 的裝置中繼續。此功能需要兩台裝置皆已啟用「接續」、Wi-Fi 和藍牙。" + }, + { + "name":"continue_title", + "value":"接續" } ] } \ No newline at end of file diff --git a/application/entry/src/main/resources/zz_ZX/element/string.json b/application/entry/src/main/resources/zz_ZX/element/string.json index b70e661a..dbc9dba7 100644 --- a/application/entry/src/main/resources/zz_ZX/element/string.json +++ b/application/entry/src/main/resources/zz_ZX/element/string.json @@ -39,6 +39,22 @@ { "name":"continue", "value":"[TS_867711]_Resume" + }, + { + "name":"continue_desc", + "value":"[TS_921308]_Browse or edit on one device, then continue on another nearby device logged in with the same Huawei ID. This function requires that both devices have enabled \"Application connection,\" Wifi, and Bluetooth." + }, + { + "name":"ContinueSwitchAbility_label", + "value":"[TS_921307]_label" + }, + { + "name":"continue_title", + "value":"[TS_921305]_Continuation" + }, + { + "name":"ContinueSwitchAbility_desc", + "value":"[TS_921306]_description" } ] } \ No newline at end of file diff --git a/application/hvigorfile.ts b/application/hvigorfile.ts new file mode 100644 index 00000000..8096108d --- /dev/null +++ b/application/hvigorfile.ts @@ -0,0 +1,21 @@ +/* + * Copyright (c) 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. + */ + +import { appTasks } from '@ohos/hvigor-ohos-plugin'; + +export default { + system: appTasks, /* Built-in plugin of Hvigor. It cannot be modified. */ + plugins:[] /* Custom plugin to extend the functionality of Hvigor. */ +}; diff --git a/bundle.json b/bundle.json index 4f8e8db1..86b33cd7 100644 --- a/bundle.json +++ b/bundle.json @@ -55,7 +55,6 @@ "bounds_checking_function", "power_manager", "openssl", - "json", "ffmpeg", "zlib" ] 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 92597676..08e875e7 100644 --- a/services/distributedhardwarefwkservice/BUILD.gn +++ b/services/distributedhardwarefwkservice/BUILD.gn @@ -95,9 +95,9 @@ ohos_shared_library("distributedhardwarefwksvr") { "src/resourcemanager/version_info_manager.cpp", "src/task/disable_task.cpp", "src/task/enable_task.cpp", - "src/task/monitor_task_timer.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", @@ -138,7 +138,6 @@ ohos_shared_library("distributedhardwarefwksvr") { "hitrace:hitrace_meter", "init:libbegetutil", "ipc:ipc_core", - "json:nlohmann_json_static", "kv_store:distributeddata_inner", "power_manager:powermgr_client", "resource_schedule_service:ressched_client", diff --git a/services/distributedhardwarefwkservice/include/componentmanager/component_manager.h b/services/distributedhardwarefwkservice/include/componentmanager/component_manager.h index 040d7f23..db59cc43 100644 --- a/services/distributedhardwarefwkservice/include/componentmanager/component_manager.h +++ b/services/distributedhardwarefwkservice/include/componentmanager/component_manager.h @@ -34,7 +34,6 @@ #include "idistributed_hardware_source.h" #include "impl_utils.h" #include "low_latency_listener.h" -#include "monitor_task_timer.h" #include "meta_capability_info.h" #include "task_board.h" #include "task_factory.h" @@ -77,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); @@ -119,7 +118,6 @@ private: int32_t InitComponentHandler(); int32_t InitSAMonitor(); void StartComponent(); - void StartTaskMonitor(); void RegisterDHStateListener(); void RegisterDataSyncTriggerListener(); void InitDHCommTool(); @@ -128,7 +126,6 @@ private: void UnregisterDHStateListener(); void UnregisterDataSyncTriggerListener(); void UnInitDHCommTool(); - void StopTaskMonitor(); void StopComponent(); void StopPrivacy(); int32_t GetEnableCapParam(const std::string &networkId, const std::string &uuid, DHType dhType, EnableParam ¶m, @@ -147,7 +144,6 @@ private: std::shared_ptr cameraCompPrivacy_ = nullptr; std::shared_ptr compMonitorPtr_ = nullptr; sptr lowLatencyListener_ = nullptr; - std::shared_ptr monitorTaskTimer_ = nullptr; std::atomic isUnInitTimeOut_; // record the remote device business state, {{deviceUUID, dhId}, BusinessState}. diff --git a/services/distributedhardwarefwkservice/include/componentmanager/component_privacy.h b/services/distributedhardwarefwkservice/include/componentmanager/component_privacy.h index f5a0c2f1..72fa15af 100644 --- a/services/distributedhardwarefwkservice/include/componentmanager/component_privacy.h +++ b/services/distributedhardwarefwkservice/include/componentmanager/component_privacy.h @@ -39,8 +39,6 @@ public: void SetPageFlagTrue(); void SetPageFlagFalse(); bool GetPageFlag(); - bool IsSensitiveResource(); - bool IsIdenticalAccount(const std::string &networkId); class ComponentEventHandler : public AppExecFwk::EventHandler { public: diff --git a/services/distributedhardwarefwkservice/include/task/device_changed_task.h b/services/distributedhardwarefwkservice/include/task/device_changed_task.h index 2c685eb4..bd86723c 100644 --- a/services/distributedhardwarefwkservice/include/task/device_changed_task.h +++ b/services/distributedhardwarefwkservice/include/task/device_changed_task.h @@ -29,7 +29,6 @@ public: private: void HandleDeviceChanged(); - //void CreateEnableTask(); }; } // namespace DistributedHardware } // namespace OHOS diff --git a/services/distributedhardwarefwkservice/src/accessmanager/access_manager.cpp b/services/distributedhardwarefwkservice/src/accessmanager/access_manager.cpp index d67b9ae4..f10b8fa3 100644 --- a/services/distributedhardwarefwkservice/src/accessmanager/access_manager.cpp +++ b/services/distributedhardwarefwkservice/src/accessmanager/access_manager.cpp @@ -176,9 +176,8 @@ void AccessManager::OnDeviceReady(const DmDeviceInfo &deviceInfo) void AccessManager::OnDeviceChanged(const DmDeviceInfo &deviceInfo) { std::lock_guard lock(accessMutex_); - DHLOGI("start, networkId = %{public}s, deviceName = %{public}s, deviceTypeId = %{public}d", - GetAnonyString(deviceInfo.networkId).c_str(), GetAnonyString(deviceInfo.deviceName).c_str(), - deviceInfo.deviceTypeId); + 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) { @@ -190,6 +189,7 @@ void AccessManager::OnDeviceChanged(const DmDeviceInfo &deviceInfo) 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, diff --git a/services/distributedhardwarefwkservice/src/componentmanager/component_manager.cpp b/services/distributedhardwarefwkservice/src/componentmanager/component_manager.cpp index 7bf4bedb..c5b372f1 100644 --- a/services/distributedhardwarefwkservice/src/componentmanager/component_manager.cpp +++ b/services/distributedhardwarefwkservice/src/componentmanager/component_manager.cpp @@ -62,14 +62,12 @@ namespace { constexpr int32_t DISABLE_RETRY_MAX_TIMES = 3; constexpr int32_t ENABLE_PARAM_RETRY_TIME = 500 * 1000; constexpr int32_t INVALID_SA_ID = -1; - constexpr int32_t MONITOR_TASK_DELAY_MS = 5 * 1000; constexpr int32_t UNINIT_COMPONENT_TIMEOUT_SECONDS = 2; const std::string MONITOR_TASK_TIMER_ID = "monitor_task_timer_id"; } ComponentManager::ComponentManager() : compSource_({}), compSink_({}), compSrcSaId_({}), compMonitorPtr_(std::make_shared()), lowLatencyListener_(new(std::nothrow) LowLatencyListener), - monitorTaskTimer_(std::make_shared(MONITOR_TASK_TIMER_ID, MONITOR_TASK_DELAY_MS)), isUnInitTimeOut_(false), dhBizStates_({}), dhStateListener_(std::make_shared()), dataSyncTriggerListener_(std::make_shared()), dhCommToolPtr_(std::make_shared()), needRefreshTaskParams_({}) @@ -102,7 +100,6 @@ int32_t ComponentManager::Init() } StartComponent(); - StartTaskMonitor(); RegisterDHStateListener(); RegisterDataSyncTriggerListener(); InitDHCommTool(); @@ -163,13 +160,6 @@ void ComponentManager::StartComponent() } } -void ComponentManager::StartTaskMonitor() -{ - if (monitorTaskTimer_ != nullptr) { - monitorTaskTimer_->StartTimer(); - } -} - void ComponentManager::RegisterDHStateListener() { for (const auto &item : compSource_) { @@ -213,7 +203,6 @@ int32_t ComponentManager::UnInit() UnregisterDHStateListener(); UnregisterDataSyncTriggerListener(); UnInitDHCommTool(); - StopTaskMonitor(); StopPrivacy(); UnInitSAMonitor(); StopComponent(); @@ -281,14 +270,6 @@ void ComponentManager::UnInitDHCommTool() dhCommToolPtr_->UnInit(); } -void ComponentManager::StopTaskMonitor() -{ - // stop monitor task timer - if (monitorTaskTimer_ != nullptr) { - monitorTaskTimer_->StopTimer(); - } -} - void ComponentManager::StopComponent() { // stop source and sink sa @@ -719,14 +700,14 @@ int32_t ComponentManager::GetCapParam(const std::string &uuid, const std::string std::string deviceId = GetDeviceIdByUUID(uuid); auto ret = CapabilityInfoManager::GetInstance()->GetCapability(deviceId, dhId, capability); if ((ret == DH_FWK_SUCCESS) && (capability != nullptr)) { - DHLOGE("GetCapability success, deviceId: %{public}s, uuid: %{public}s, dhId: %{public}s, ret: %{public}d", + DHLOGI("GetCapability success, deviceId: %{public}s, uuid: %{public}s, dhId: %{public}s, ret: %{public}d", GetAnonyString(deviceId).c_str(), GetAnonyString(uuid).c_str(), GetAnonyString(dhId).c_str(), ret); return ret; } ret = LocalCapabilityInfoManager::GetInstance()->GetCapability(deviceId, dhId, capability); if ((ret == DH_FWK_SUCCESS) && (capability != nullptr)) { - DHLOGE("Local GetCaps success, deviceId: %{public}s, uuid: %{public}s, dhId: %{public}s, ret: %{public}d", + DHLOGI("Local GetCaps success, deviceId: %{public}s, uuid: %{public}s, dhId: %{public}s, ret: %{public}d", GetAnonyString(deviceId).c_str(), GetAnonyString(uuid).c_str(), GetAnonyString(dhId).c_str(), ret); return ret; } @@ -739,7 +720,7 @@ int32_t ComponentManager::GetMetaParam(const std::string &uuid, const std::strin { auto ret = MetaInfoManager::GetInstance()->GetMetaCapInfo(GetDeviceIdByUUID(uuid), dhId, metaCapPtr); if ((ret == DH_FWK_SUCCESS) && (metaCapPtr != nullptr)) { - DHLOGE("GetCapability success, uuid =%{public}s, dhId = %{public}s, errCode = %{public}d", + DHLOGI("GetCapability success, uuid =%{public}s, dhId = %{public}s, errCode = %{public}d", GetAnonyString(uuid).c_str(), GetAnonyString(dhId).c_str(), ret); return ret; } @@ -913,6 +894,27 @@ std::map ComponentManager::GetDHSinkInstance( return compSink_; } +bool ComponentManager::IsIdenticalAccount(const std::string &networkId) +{ + 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) { DHLOGI("UpdateBusinessState, networkId: %{public}s, dhId: %{public}s, state: %{public}" PRIu32, diff --git a/services/distributedhardwarefwkservice/src/componentmanager/component_privacy.cpp b/services/distributedhardwarefwkservice/src/componentmanager/component_privacy.cpp index b9bdd488..a740fbb8 100644 --- a/services/distributedhardwarefwkservice/src/componentmanager/component_privacy.cpp +++ b/services/distributedhardwarefwkservice/src/componentmanager/component_privacy.cpp @@ -309,48 +309,5 @@ void ComponentPrivacy::ComponentEventHandler::ProcessStopPage(const AppExecFwk:: std::string subtype = cJSON_GetObjectItem(innerMsg, PRIVACY_SUBTYPE.c_str())->valuestring; comPrivacyObj_->StopPrivacePage(subtype); } - -bool ComponentPrivacy::IsIdenticalAccount(const std::string &networkId) -{ - 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; -} - -bool ComponentPrivacy::IsSensitiveResource() -{ - EnableParam param; - auto ret = GetEnableParam(networkId, uuid, dhId, dhType, param); - if (ret != DH_FWK_SUCCESS) { - DHLOGE("GetEnableParam failed, uuid = %{public}s, dhId = %{public}s, errCode = %{public}d", - GetAnonyString(uuid).c_str(), GetAnonyString(dhId).c_str(), ret); - if (RetryGetEnableParam(networkId, uuid, dhId, dhType, param) != DH_FWK_SUCCESS) { - return false; - } - } - 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 false; - } - - return resourceDesc[subtype]; -} - } // namespace DistributedHardware } // namespace OHOS diff --git a/services/distributedhardwarefwkservice/src/localhardwaremanager/local_hardware_manager.cpp b/services/distributedhardwarefwkservice/src/localhardwaremanager/local_hardware_manager.cpp index 5812b213..8a52d1b4 100644 --- a/services/distributedhardwarefwkservice/src/localhardwaremanager/local_hardware_manager.cpp +++ b/services/distributedhardwarefwkservice/src/localhardwaremanager/local_hardware_manager.cpp @@ -116,8 +116,7 @@ void LocalHardwareManager::QueryLocalHardware(const DHType dhType, IHardwareHand DHLOGE("Query hardwareHandler and obtain empty, dhType: %{public}#X", dhType); usleep(QUERY_INTERVAL_TIME); } else { - DHLOGI("Query hardwareHandler success, dhType: %{public}#X!, size: %{public}d", - dhType, static_cast(dhItems.size())); + DHLOGI("Query hardwareHandler success, dhType: %{public}#X!, size: %{public}zu", dhType, dhItems.size()); /* * Failed to delete data when the device restarts or other exception situation. * So check and remove the non-exist local capabilityInfo. @@ -141,8 +140,8 @@ void LocalHardwareManager::QueryMetaHardware(const DHType dhType, IHardwareHandl DHLOGE("Query metahardwareHandler and obtain empty, dhType: %{public}#X", dhType); usleep(QUERY_INTERVAL_TIME); } else { - DHLOGI("Query metahardwareHandler success, dhType: %{public}#X!, size: %{public}d", - dhType, static_cast(metaDhItems.size())); + DHLOGI("Query metahardwareHandler success, dhType: %{public}#X!, size: %{public}zu", + dhType, metaDhItems.size()); metaDHItemsMap_[dhType] = metaDhItems; break; } diff --git a/services/distributedhardwarefwkservice/src/resourcemanager/db_adapter.cpp b/services/distributedhardwarefwkservice/src/resourcemanager/db_adapter.cpp index 75548046..e34aee75 100644 --- a/services/distributedhardwarefwkservice/src/resourcemanager/db_adapter.cpp +++ b/services/distributedhardwarefwkservice/src/resourcemanager/db_adapter.cpp @@ -98,7 +98,10 @@ DistributedKv::Status DBAdapter::GetLocalKvStorePtr() int32_t DBAdapter::Init(bool isAutoSync, DistributedKv::DataType dataType) { - DHLOGI("Init DB, storeId: %{public}s", storeId_.storeId.c_str()); + this->isAutoSync = isAutoSync; + this->dataType = dataType; + DHLOGI("Init DB, storeId: %{public}s, dataType: %{public}d", + storeId_.storeId.c_str(), static_cast(dataType)); std::lock_guard lock(dbAdapterMutex_); int32_t tryTimes = MAX_INIT_RETRY_TIMES; while (tryTimes > 0) { @@ -123,14 +126,15 @@ int32_t DBAdapter::Init(bool isAutoSync, DistributedKv::DataType dataType) DHLOGE("Init KvStorePtr failed"); return ERR_DH_FWK_RESOURCE_KV_STORAGE_POINTER_NULL; } - this->isAutoSync = isAutoSync; - this->dataType = dataType; return DH_FWK_SUCCESS; } int32_t DBAdapter::InitLocal() { - DHLOGI("Init local DB, storeId: %{public}s", storeId_.storeId.c_str()); + this->isAutoSync = false; + this->dataType = DistributedKv::DataType::TYPE_STATICS; + DHLOGI("Init local DB, storeId: %{public}s, dataType: %{public}d", + storeId_.storeId.c_str(), static_cast(this->dataType)); std::lock_guard lock(dbAdapterMutex_); int32_t tryTimes = MAX_INIT_RETRY_TIMES; while (tryTimes > 0) { @@ -148,7 +152,6 @@ int32_t DBAdapter::InitLocal() DHLOGE("Init KvStorePtr failed"); return ERR_DH_FWK_RESOURCE_KV_STORAGE_POINTER_NULL; } - this->isAutoSync = false; return DH_FWK_SUCCESS; } @@ -229,7 +232,8 @@ void DBAdapter::TriggerDynamicQuery(const std::string &key) int32_t DBAdapter::GetDataByKey(const std::string &key, std::string &data) { - DHLOGI("Get data by key: %{public}s", GetAnonyString(key).c_str()); + DHLOGI("Get data by key: %{public}s, storeId: %{public}s, dataType: %{public}d", + GetAnonyString(key).c_str(), storeId_.storeId.c_str(), static_cast(this->dataType)); std::lock_guard lock(dbAdapterMutex_); if (kvStoragePtr_ == nullptr) { DHLOGE("kvStoragePtr_ is null"); @@ -251,7 +255,8 @@ int32_t DBAdapter::GetDataByKey(const std::string &key, std::string &data) int32_t DBAdapter::GetDataByKeyPrefix(const std::string &keyPrefix, std::vector &values) { - DHLOGI("Get data by key prefix: %{public}s", GetAnonyString(keyPrefix).c_str()); + DHLOGI("Get data by key prefix: %{public}s, storeId: %{public}s, dataType: %{public}d", + GetAnonyString(keyPrefix).c_str(), storeId_.storeId.c_str(), static_cast(this->dataType)); std::lock_guard lock(dbAdapterMutex_); if (kvStoragePtr_ == nullptr) { DHLOGE("kvStoragePtr_ is null"); diff --git a/services/distributedhardwarefwkservice/src/resourcemanager/local_capability_info_manager.cpp b/services/distributedhardwarefwkservice/src/resourcemanager/local_capability_info_manager.cpp index 6e2f56ea..574e9842 100644 --- a/services/distributedhardwarefwkservice/src/resourcemanager/local_capability_info_manager.cpp +++ b/services/distributedhardwarefwkservice/src/resourcemanager/local_capability_info_manager.cpp @@ -123,7 +123,6 @@ int32_t LocalCapabilityInfoManager::AddCapability(const std::vector keys; std::vector values; std::string key; - std::string data; for (auto &resInfo : resInfos) { if (resInfo == nullptr) { continue; diff --git a/services/distributedhardwarefwkservice/src/task/device_changed_task.cpp b/services/distributedhardwarefwkservice/src/task/device_changed_task.cpp index 51786321..ca930099 100644 --- a/services/distributedhardwarefwkservice/src/task/device_changed_task.cpp +++ b/services/distributedhardwarefwkservice/src/task/device_changed_task.cpp @@ -16,9 +16,14 @@ #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" @@ -43,7 +48,7 @@ DeviceChangedTask::~DeviceChangedTask() void DeviceChangedTask::DoTask() { - DHLOGD("start online task, id = %{public}s, uuid = %{public}s", GetId().c_str(), GetAnonyString(GetUUID()).c_str()); + 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) { @@ -57,7 +62,7 @@ void DeviceChangedTask::DoTask() } } SetTaskState(TaskState::SUCCESS); - DHLOGD("finish online task, remove it, id = %{public}s.", GetId().c_str()); + DHLOGD("finish device changed task, remove it, id = %{public}s.", GetId().c_str()); TaskBoard::GetInstance().RemoveTask(this->GetId()); } @@ -101,7 +106,7 @@ void DeviceChangedTask::HandleDeviceChanged() return; } - auto enabledDevices = TaskBoard::GetEnabledDevice(); + auto enabledDevices = TaskBoard::GetInstance().GetEnabledDevice(); for (const auto &info : devDhInfos) { //skip enabled component diff --git a/services/distributedhardwarefwkservice/src/task/monitor_task_timer.cpp b/services/distributedhardwarefwkservice/src/task/monitor_task_timer.cpp deleted file mode 100644 index d02e8a97..00000000 --- a/services/distributedhardwarefwkservice/src/task/monitor_task_timer.cpp +++ /dev/null @@ -1,75 +0,0 @@ -/* - * Copyright (c) 2022-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 "monitor_task_timer.h" - -#include "anonymous_string.h" -#include "capability_info.h" -#include "capability_info_manager.h" -#include "distributed_hardware_errno.h" -#include "distributed_hardware_log.h" -#include "dh_timer.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 "MonitorTaskTimer" -MonitorTaskTimer::MonitorTaskTimer(std::string timerId, int32_t delayTimeMs) : DHTimer(timerId, delayTimeMs) -{ - DHLOGI("MonitorTaskTimer ctor!"); -} - -MonitorTaskTimer::~MonitorTaskTimer() -{ - DHLOGI("MonitorTaskTimer dtor!"); -} - -void MonitorTaskTimer::ExecuteInner() -{ - DHLOGD("ExecuteInner!"); - auto enabledDevices = TaskBoard::GetInstance().GetEnabledDevice(); - std::shared_ptr capInfoPtr = nullptr; - TaskParam taskParam; - std::string capabilityKey; - for (auto item : enabledDevices) { - capabilityKey = item.first; - taskParam = item.second; - if (taskParam.dhType != DHType::INPUT) { - continue; - } - if (CapabilityInfoManager::GetInstance()->GetDataByKey(capabilityKey, capInfoPtr) != DH_FWK_SUCCESS) { - DHLOGI("CapabilityInfoManager can not find this key in DB, key: %{public}s, networkId: %{public}s, " - "uuid: %{public}s, dhId: %{public}s", GetAnonyString(capabilityKey).c_str(), - GetAnonyString(taskParam.networkId).c_str(), GetAnonyString(taskParam.uuid).c_str(), - GetAnonyString(taskParam.dhId).c_str()); - auto task = TaskFactory::GetInstance().CreateTask(TaskType::DISABLE, taskParam, nullptr); - TaskExecutor::GetInstance().PushTask(task); - } - } - - if (capInfoPtr != nullptr) { - capInfoPtr = nullptr; - } -} - -void MonitorTaskTimer::HandleStopTimer() -{ - DHLOGI("HandleStopTimer!"); -} -} // namespace DistributedHardware -} // namespace OHOS diff --git a/services/distributedhardwarefwkservice/src/task/task_factory.cpp b/services/distributedhardwarefwkservice/src/task/task_factory.cpp index 7592cf89..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 { diff --git a/utils/BUILD.gn b/utils/BUILD.gn index a8988f47..8f822fad 100644 --- a/utils/BUILD.gn +++ b/utils/BUILD.gn @@ -65,7 +65,6 @@ ohos_shared_library("distributedhardwareutils") { "hilog:libhilog", "hisysevent:libhisysevent", "hitrace:hitrace_meter", - "json:nlohmann_json_static", "openssl:libcrypto_shared", "safwk:system_ability_fwk", "zlib:shared_libz", -- Gitee From 0ebcf2340448b94503a9367c59f555c93badb3ca Mon Sep 17 00:00:00 2001 From: saga Date: Sat, 25 May 2024 18:31:33 +0800 Subject: [PATCH 8/8] add device changed 2 Signed-off-by: saga --- .../src/task/device_changed_task.cpp | 1 - 1 file changed, 1 deletion(-) diff --git a/services/distributedhardwarefwkservice/src/task/device_changed_task.cpp b/services/distributedhardwarefwkservice/src/task/device_changed_task.cpp index ca930099..a90995b5 100644 --- a/services/distributedhardwarefwkservice/src/task/device_changed_task.cpp +++ b/services/distributedhardwarefwkservice/src/task/device_changed_task.cpp @@ -114,7 +114,6 @@ void DeviceChangedTask::HandleDeviceChanged() if (enabledDevices.find(deviceKey) != enabledDevices.end()) { continue; } - TaskParam taskParam = { .networkId = GetNetworkId(), .uuid = GetUUID(), -- Gitee