diff --git a/common/utils/include/distributed_hardware_errno.h b/common/utils/include/distributed_hardware_errno.h index ffc05fd2b19cf2a052b190bca3da1a7f11ec6420..96a88bfe39b3e2a247f8d8f02b5d75878a64b0c0 100644 --- a/common/utils/include/distributed_hardware_errno.h +++ b/common/utils/include/distributed_hardware_errno.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2021 Huawei Device Co., Ltd. + * Copyright (c) 2021-2022 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 @@ -89,6 +89,11 @@ namespace DistributedHardware { constexpr int32_t ERR_DH_FWK_ACCESS_UNINIT_DM_FAILED = -10901; constexpr int32_t ERR_DH_FWK_ACCESS_REGISTER_DM_FAILED = -10902; constexpr int32_t ERR_DH_FWK_ACCESS_UNREGISTER_DM_FAILED = -10903; + + /* Hidump errno, range: [-11000, -11000] */ + constexpr int32_t ERR_DH_FWK_HIDUMP_ERROR = -11000; + constexpr int32_t ERR_DH_FWK_HIDUMP_INVALID_ARGS = -11001; + constexpr int32_t ERR_DH_FWK_HIDUMP_DPRINTF_ERROR = -11002; } // namespace DistributedHardware } // namespace OHOS #endif diff --git a/common/utils/include/idistributed_hardware_manager.h b/common/utils/include/idistributed_hardware_manager.h index aed2954f353757cc33e81624c119fecc130cc70f..46dcd6ad026ce6d89fda841cb88c88cd32215248 100644 --- a/common/utils/include/idistributed_hardware_manager.h +++ b/common/utils/include/idistributed_hardware_manager.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2021 Huawei Device Co., Ltd. + * Copyright (c) 2022 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 @@ -34,6 +34,7 @@ public: 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; }; } // namespace DistributedHardware } // namespace OHOS diff --git a/sa_profile/dhardware.cfg b/sa_profile/dhardware.cfg index f521718de2f0dfba17858fefcfdde795409d16b1..0bd3bf15d958c00e54a7b2e4ea30567038045e26 100644 --- a/sa_profile/dhardware.cfg +++ b/sa_profile/dhardware.cfg @@ -2,8 +2,9 @@ "services" : [{ "name" : "dhardware", "path" : ["/system/bin/sa_main", "/system/profile/dhardware.xml"], - "uid" : "system", - "gid" : ["system"], + "uid" : "dhardware", + "gid" : ["dhardware"], + "caps" : ["DAC_READ_SEARCH", "DAC_OVERRIDE"], "ondemand" : true }] } \ No newline at end of file diff --git a/services/distributedhardwarefwkservice/include/accessmanager/access_manager.h b/services/distributedhardwarefwkservice/include/accessmanager/access_manager.h index 5156dcbb9106343fa3b508dd21ad9b02d8f8a841..48f18c22b1f5d85e4c9a72808090c2f81c37bf42 100644 --- a/services/distributedhardwarefwkservice/include/accessmanager/access_manager.h +++ b/services/distributedhardwarefwkservice/include/accessmanager/access_manager.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2021 Huawei Device Co., Ltd. + * Copyright (c) 2021-2022 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 @@ -48,6 +48,8 @@ public: virtual void OnDeviceReady(const DmDeviceInfo &deviceInfo) override; virtual void OnDeviceChanged(const DmDeviceInfo &deviceInfo) override; + int32_t Dump(const std::vector &argsStr, std::string &result); + private: AccessManager() = default; int32_t RegisterDevStateCallback(); diff --git a/services/distributedhardwarefwkservice/include/distributed_hardware_manager_factory.h b/services/distributedhardwarefwkservice/include/distributed_hardware_manager_factory.h index 6fbaae81c694775599e4520d5b9a0ea103c36992..fe37f6a1d437b1deb88c0a4421b80c4914953c0a 100644 --- a/services/distributedhardwarefwkservice/include/distributed_hardware_manager_factory.h +++ b/services/distributedhardwarefwkservice/include/distributed_hardware_manager_factory.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2021 Huawei Device Co., Ltd. + * Copyright (c) 2021-2022 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 @@ -32,6 +32,8 @@ public: int32_t SendOffLineEvent(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); + private: bool Init(); void UnInit(); diff --git a/services/distributedhardwarefwkservice/include/distributed_hardware_service.h b/services/distributedhardwarefwkservice/include/distributed_hardware_service.h index 8f91391af76db508af8fb2404e534b8f6f1dcea3..21c671f5d354c6f326049868f1ac70e120f91dd1 100644 --- a/services/distributedhardwarefwkservice/include/distributed_hardware_service.h +++ b/services/distributedhardwarefwkservice/include/distributed_hardware_service.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2021 Huawei Device Co., Ltd. + * Copyright (c) 2021-2022 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 @@ -35,6 +35,7 @@ public: DistributedHardwareService(int32_t saId, bool runOnCreate); ~DistributedHardwareService() = default; int32_t QuerySinkVersion(std::unordered_map &versionMap) override; + int Dump(int32_t fd, const std::vector& args) override; protected: void OnStart() override; diff --git a/services/distributedhardwarefwkservice/src/accessmanager/access_manager.cpp b/services/distributedhardwarefwkservice/src/accessmanager/access_manager.cpp index 51fd624d3fc1ee2b95d34f1a23df504c547a54bb..672e9b383459da7d3757fc53b2896db6970265c5 100644 --- a/services/distributedhardwarefwkservice/src/accessmanager/access_manager.cpp +++ b/services/distributedhardwarefwkservice/src/accessmanager/access_manager.cpp @@ -166,5 +166,10 @@ void AccessManager::SendTrustedDeviceOnline() DistributedHardwareManagerFactory::GetInstance().SendOnLineEvent(networkId, uuid, deviceInfo.deviceTypeId); } } + +int32_t AccessManager::Dump(const std::vector &argsStr, std::string &result) +{ + return DistributedHardwareManagerFactory::GetInstance().Dump(argsStr, result); +} } // namespace DistributedHardware } // namespace OHOS diff --git a/services/distributedhardwarefwkservice/src/distributed_hardware_manager_factory.cpp b/services/distributedhardwarefwkservice/src/distributed_hardware_manager_factory.cpp index 59312f05fa13201112fbcd2febfd437ac6207dd0..1dcbedf9b39b014b5c6c8856344e1a1a19541187 100644 --- a/services/distributedhardwarefwkservice/src/distributed_hardware_manager_factory.cpp +++ b/services/distributedhardwarefwkservice/src/distributed_hardware_manager_factory.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2021 Huawei Device Co., Ltd. + * Copyright (c) 2021-2022 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 @@ -17,6 +17,7 @@ #include #include +#include #include "anonymous_string.h" #include "constants.h" @@ -84,7 +85,8 @@ void DistributedHardwareManagerFactory::CheckExitSAOrNot() const auto uuid = GetUUIDBySoftBus(networkId); DHLOGI("Send trusted device online, networkId = %s, uuid = %s", GetAnonyString(networkId).c_str(), GetAnonyString(uuid).c_str()); - SendOnLineEvent(networkId, uuid, deviceInfo.deviceTypeId); + std::thread(&DistributedHardwareManagerFactory::SendOnLineEvent, this, networkId, uuid, + deviceInfo.deviceTypeId).detach(); } } @@ -205,5 +207,14 @@ int32_t DistributedHardwareManagerFactory::GetComponentVersion(std::unordered_ma } return distributedHardwareMgrPtr_->GetComponentVersion(versionMap); } + +int32_t DistributedHardwareManagerFactory::Dump(const std::vector &argsStr, std::string &result) +{ + if (distributedHardwareMgrPtr_ == nullptr) { + DHLOGE("distributedHardwareMgr is null"); + return ERR_DH_FWK_HIDUMP_ERROR; + } + return distributedHardwareMgrPtr_->Dump(argsStr, result); +} } // namespace DistributedHardware } // namespace OHOS diff --git a/services/distributedhardwarefwkservice/src/distributed_hardware_service.cpp b/services/distributedhardwarefwkservice/src/distributed_hardware_service.cpp index 773c243451a6a850967adf56f612bbfe1293f4ea..6c130aa711a10d6cbf7828958f4324f4ebe18a21 100644 --- a/services/distributedhardwarefwkservice/src/distributed_hardware_service.cpp +++ b/services/distributedhardwarefwkservice/src/distributed_hardware_service.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2021 Huawei Device Co., Ltd. + * Copyright (c) 2021-2022 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 @@ -82,5 +82,28 @@ int32_t DistributedHardwareService::QuerySinkVersion(std::unordered_map& args) +{ + DHLOGI("DistributedHardwareService Dump."); + + std::vector argsStr {}; + for (auto item : args) { + argsStr.emplace_back(Str16ToStr8(item)); + } + + std::string result(""); + int ret = AccessManager::GetInstance()->Dump(argsStr, result); + if (ret != DH_FWK_SUCCESS) { + DHLOGE("Dump error, ret = %d", ret); + } + + if (dprintf(fd, "%s\n", result.c_str()) < 0) { + DHLOGE("Hidump dprintf error"); + ret = ERR_DH_FWK_HIDUMP_DPRINTF_ERROR; + } + + return ret; +} } // namespace DistributedHardware } // namespace OHOS diff --git a/services/distributedhardwarefwkserviceimpl/BUILD.gn b/services/distributedhardwarefwkserviceimpl/BUILD.gn index 19efe6518f812343b141b5dd19546b84ad986b39..6e3b3a20217fd08611be789314fcc1bdbe12138d 100644 --- a/services/distributedhardwarefwkserviceimpl/BUILD.gn +++ b/services/distributedhardwarefwkserviceimpl/BUILD.gn @@ -1,4 +1,4 @@ -# Copyright (c) 2021 Huawei Device Co., Ltd. +# Copyright (c) 2021-2022 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 @@ -29,6 +29,7 @@ ohos_shared_library("distributedhardwarefwksvr_impl") { "include/utils", "include/localhardwaremanager", "include/resourcemanager", + "include/hidumphelper", "${common_path}/log/include", "${common_path}/utils/include", "${utils_path}/include", @@ -43,6 +44,8 @@ ohos_shared_library("distributedhardwarefwksvr_impl") { "src/componentmanager/component_manager.cpp", "src/distributed_hardware_manager.cpp", "src/distributed_hardware_proxy.cpp", + "src/hidumphelper/enabled_comps_dump.cpp", + "src/hidumphelper/hidump_helper.cpp", "src/localhardwaremanager/local_hardware_manager.cpp", "src/localhardwaremanager/plugin_listener_impl.cpp", "src/resourcemanager/capability_info.cpp", diff --git a/services/distributedhardwarefwkserviceimpl/include/componentmanager/component_manager.h b/services/distributedhardwarefwkserviceimpl/include/componentmanager/component_manager.h index 7342a03bed608d63fb70a629772b5a1bfe081f99..8a592df899ef97f93bab471bf023c7a6d30af70e 100644 --- a/services/distributedhardwarefwkserviceimpl/include/componentmanager/component_manager.h +++ b/services/distributedhardwarefwkserviceimpl/include/componentmanager/component_manager.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2021 Huawei Device Co., Ltd. + * Copyright (c) 2021-2022 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 @@ -17,6 +17,7 @@ #define OHOS_DISTRIBUTED_HARDWARE_COMPONENT_MANAGER_H #include +#include #include #include #include @@ -44,6 +45,8 @@ public: int32_t Disable(const std::string &networkId, const std::string &uuid, const std::string &dhId, const DHType dhType); + void DumpLoadedComps(std::set &compSourceType, std::set &compSinkType); + private: enum class Action : int32_t { START_SOURCE, diff --git a/services/distributedhardwarefwkserviceimpl/include/distributed_hardware_manager.h b/services/distributedhardwarefwkserviceimpl/include/distributed_hardware_manager.h index 77f92f6de4e509675b93f91e80f1174c5570ef75..a94c3e00f52499fb7cbf870db5bec8c8fbb23a6f 100644 --- a/services/distributedhardwarefwkserviceimpl/include/distributed_hardware_manager.h +++ b/services/distributedhardwarefwkserviceimpl/include/distributed_hardware_manager.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2021 Huawei Device Co., Ltd. + * Copyright (c) 2021-2022 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 @@ -31,6 +31,8 @@ public: int32_t SendOffLineEvent(const std::string &networkId, const std::string &uuid, uint16_t deviceType) override; size_t GetOnLineCount() override; int32_t GetComponentVersion(std::unordered_map &versionMap) override; + + int32_t Dump(const std::vector &argsStr, std::string &result) override; }; } // namespace DistributedHardware } // namespace OHOS diff --git a/services/distributedhardwarefwkserviceimpl/include/hidumphelper/enabled_comps_dump.h b/services/distributedhardwarefwkserviceimpl/include/hidumphelper/enabled_comps_dump.h new file mode 100644 index 0000000000000000000000000000000000000000..d99cd0f251229f40ac5574cdcaaffb5f58f3d2fe --- /dev/null +++ b/services/distributedhardwarefwkserviceimpl/include/hidumphelper/enabled_comps_dump.h @@ -0,0 +1,61 @@ +/* + * Copyright (c) 2022 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_ENABLED_COMPS_DUMP_H +#define OHOS_DISTRIBUTED_ENABLED_COMPS_DUMP_H +#include +#include +#include +#include + +#include "device_type.h" +#include "single_instance.h" + +namespace OHOS { +namespace DistributedHardware { +struct HidumpCompInfo { + std::string deviceId_; + std::string dhId_; + DHType dhType_; + + HidumpCompInfo(std::string deviceId, DHType dhType, std::string dhId) + : deviceId_(deviceId), dhId_(dhId), dhType_(dhType) {} + + bool operator < (const HidumpCompInfo &other) const + { + return (((this->deviceId_ == other.deviceId_) && (this->dhId_ < other.dhId_)) || + (this->deviceId_ < other.deviceId_)); + } +}; + +class EnabledCompsDump { +DECLARE_SINGLE_INSTANCE_BASE(EnabledCompsDump); +public: + void DumpEnabledComp(const std::string &uuid, const DHType dhType, const std::string &dhId); + void DumpDisabledComp(const std::string &uuid, const DHType dhType, const std::string &dhId); + + void Dump(std::set &compInfoSet); + +private: + explicit EnabledCompsDump() = default; + ~EnabledCompsDump() = default; + +private: + std::mutex compInfosMutex_; + std::set compInfoSet_; +}; +} // namespace DistributedHardware +} // namespace OHOS +#endif \ No newline at end of file diff --git a/services/distributedhardwarefwkserviceimpl/include/hidumphelper/hidump_helper.h b/services/distributedhardwarefwkserviceimpl/include/hidumphelper/hidump_helper.h new file mode 100644 index 0000000000000000000000000000000000000000..a89a5952423d832ab936aca7832d054498ec8123 --- /dev/null +++ b/services/distributedhardwarefwkserviceimpl/include/hidumphelper/hidump_helper.h @@ -0,0 +1,56 @@ +/* + * Copyright (c) 2022 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_HIDUMP_HELPER_H +#define OHOS_DISTRIBUTED_HARDWARE_HIDUMP_HELPER_H +#include +#include +#include + +#include "enabled_comps_dump.h" +#include "device_type.h" +#include "single_instance.h" + +namespace OHOS { +namespace DistributedHardware { +enum class HidumpFlag { + UNKNOWN = 0, + GET_HELP, + GET_LOADED_COMP_LIST, + GET_ENABLED_COMP_LIST, + GET_TASK_LIST, + GET_CAPABILITY_LIST, +}; + +class HidumpHelper { +DECLARE_SINGLE_INSTANCE_BASE(HidumpHelper); +public: + int32_t Dump(const std::vector& args, std::string &result); + +private: + explicit HidumpHelper() = default; + ~HidumpHelper() = default; + + int32_t ProcessDump(const HidumpFlag &flag, std::string &result); + int32_t ShowAllLoadedComps(std::string &result); + int32_t ShowAllEnabledComps(std::string &result); + int32_t ShowAllTaskInfos(std::string &result); + int32_t ShowAllCapabilityInfos(std::string &result); + int32_t ShowHelp(std::string &result); + int32_t ShowIllealInfomation(std::string &result); +}; +} // namespace DistributedHardware +} // namespace OHOS +#endif \ No newline at end of file diff --git a/services/distributedhardwarefwkserviceimpl/include/resourcemanager/capability_info_manager.h b/services/distributedhardwarefwkserviceimpl/include/resourcemanager/capability_info_manager.h index bbbd9c269512dcc44afc7d0ab18cbda311f25350..7bbe92e624178d725ab50770ba932f3a5e28fe65 100644 --- a/services/distributedhardwarefwkserviceimpl/include/resourcemanager/capability_info_manager.h +++ b/services/distributedhardwarefwkserviceimpl/include/resourcemanager/capability_info_manager.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2021 Huawei Device Co., Ltd. + * Copyright (c) 2021-2022 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 @@ -88,11 +88,11 @@ public: int32_t ManualSync(const std::string &networkId); /* Database data changes callback */ virtual void OnChange(const DistributedKv::ChangeNotification &changeNotification) override; - virtual void OnChange(const DistributedKv::ChangeNotification &changeNotification, - std::shared_ptr snapshot) override; /* EventBus async processing callback */ void OnEvent(CapabilityInfoEvent &e) override; + void DumpCapabilityInfos(std::vector &capInfos); + private: CapabilityInfoManager(); void HandleCapabilityAddChange(const std::vector &insertRecords); diff --git a/services/distributedhardwarefwkserviceimpl/include/task/task_board.h b/services/distributedhardwarefwkserviceimpl/include/task/task_board.h index d7ffaaceb7d882993b2fe6f9d61ea95f689ec996..463955120c671563abfd57ee5b6911484c2a7d6f 100644 --- a/services/distributedhardwarefwkserviceimpl/include/task/task_board.h +++ b/services/distributedhardwarefwkserviceimpl/include/task/task_board.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2021 Huawei Device Co., Ltd. + * Copyright (c) 2021-2022 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 @@ -35,6 +35,8 @@ public: void RemoveTask(std::string taskId); int32_t WaitForALLTaskFinish(); + void DumpAllTasks(std::vector &taskInfos); + private: void RemoveTaskInner(std::string taskId); diff --git a/services/distributedhardwarefwkserviceimpl/include/utils/impl_utils.h b/services/distributedhardwarefwkserviceimpl/include/utils/impl_utils.h index 4c7ab4c73505597e28920dae0765e3018d15c8ce..992cc601c746b6f6deafbd659850927dfaf99b23 100644 --- a/services/distributedhardwarefwkserviceimpl/include/utils/impl_utils.h +++ b/services/distributedhardwarefwkserviceimpl/include/utils/impl_utils.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2021 Huawei Device Co., Ltd. + * Copyright (c) 2021-2022 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 @@ -67,6 +67,14 @@ struct TaskParam { std::string dhId; DHType dhType; }; + +struct TaskDump { + std::string id; + TaskType taskType; + TaskParam taskParm; + TaskState taskState; + std::vector taskSteps; +}; } // namespace DistributedHardware } // namespace OHOS #endif diff --git a/services/distributedhardwarefwkserviceimpl/src/componentloader/component_loader.cpp b/services/distributedhardwarefwkserviceimpl/src/componentloader/component_loader.cpp index 3f03d718055cc526316a4f6ce2bb6b1c99bb7b88..86a00f594bdf43f9825cbcff8172d0a1ca0da6c4 100644 --- a/services/distributedhardwarefwkserviceimpl/src/componentloader/component_loader.cpp +++ b/services/distributedhardwarefwkserviceimpl/src/componentloader/component_loader.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2021 Huawei Device Co., Ltd. + * Copyright (c) 2021-2022 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 @@ -23,6 +23,7 @@ #include "constants.h" #include "distributed_hardware_log.h" +#include "hidump_helper.h" using nlohmann::json; diff --git a/services/distributedhardwarefwkserviceimpl/src/componentmanager/component_manager.cpp b/services/distributedhardwarefwkserviceimpl/src/componentmanager/component_manager.cpp index b07d364afea56ab3e918919284f5323224e95d45..e433516791824d6ce4d02c329f35950daac7b0be 100644 --- a/services/distributedhardwarefwkserviceimpl/src/componentmanager/component_manager.cpp +++ b/services/distributedhardwarefwkserviceimpl/src/componentmanager/component_manager.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2021 Huawei Device Co., Ltd. + * Copyright (c) 2021-2022 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 @@ -28,6 +28,7 @@ #include "dh_utils_tool.h" #include "distributed_hardware_errno.h" #include "distributed_hardware_log.h" +#include "enabled_comps_dump.h" #include "ipc_object_stub.h" #include "iservice_registry.h" #include "system_ability_definition.h" @@ -257,6 +258,7 @@ int32_t ComponentManager::Enable(const std::string &networkId, const std::string } if (compEnable->Enable(networkId, dhId, param, find->second) == DH_FWK_SUCCESS) { DHLOGE("enable success, retryCount = %d", retryCount); + EnabledCompsDump::GetInstance().DumpEnabledComp(uuid, dhType, dhId); return DH_FWK_SUCCESS; } DHLOGE("enable failed, retryCount = %d", retryCount); @@ -265,6 +267,7 @@ int32_t ComponentManager::Enable(const std::string &networkId, const std::string } DHLOGI("enable result is %d, uuid = %s, dhId = %s", result, GetAnonyString(uuid).c_str(), GetAnonyString(dhId).c_str()); + EnabledCompsDump::GetInstance().DumpEnabledComp(uuid, dhType, dhId); return result; } @@ -286,6 +289,7 @@ int32_t ComponentManager::Disable(const std::string &networkId, const std::strin } if (compDisable->Disable(networkId, dhId, find->second) == DH_FWK_SUCCESS) { DHLOGE("disable success, retryCount = %d", retryCount); + EnabledCompsDump::GetInstance().DumpDisabledComp(uuid, dhType, dhId); return DH_FWK_SUCCESS; } DHLOGE("disable failed, retryCount = %d", retryCount); @@ -294,6 +298,7 @@ int32_t ComponentManager::Disable(const std::string &networkId, const std::strin } DHLOGI("disable result is %d, uuid = %s, dhId = %s", result, GetAnonyString(uuid).c_str(), GetAnonyString(dhId).c_str()); + EnabledCompsDump::GetInstance().DumpDisabledComp(uuid, dhType, dhId); return result; } @@ -412,5 +417,15 @@ sptr ComponentManager::GetRemoteDHMS(const std::string &ne } return iface_cast(object); } + +void ComponentManager::DumpLoadedComps(std::set &compSourceType, std::set &compSinkType) +{ + for (auto compSource : compSource_) { + compSourceType.emplace(compSource.first); + } + for (auto compSink : compSink_) { + compSinkType.emplace(compSink.first); + } +} } // namespace DistributedHardware } // namespace OHOS diff --git a/services/distributedhardwarefwkserviceimpl/src/distributed_hardware_manager.cpp b/services/distributedhardwarefwkserviceimpl/src/distributed_hardware_manager.cpp index 5b741ba1cdccac41a104aa8dfbcaf09920601aa2..173594129b837241b4cf974dc3a003d7b4d33316 100644 --- a/services/distributedhardwarefwkserviceimpl/src/distributed_hardware_manager.cpp +++ b/services/distributedhardwarefwkserviceimpl/src/distributed_hardware_manager.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2021 Huawei Device Co., Ltd. + * Copyright (c) 2021-2022 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 @@ -23,6 +23,7 @@ #include "dh_utils_tool.h" #include "distributed_hardware_errno.h" #include "distributed_hardware_log.h" +#include "hidump_helper.h" #include "local_hardware_manager.h" #include "task_board.h" #include "task_executor.h" @@ -176,5 +177,10 @@ int32_t DistributedHardwareManager::GetComponentVersion(std::unordered_map &argsStr, std::string &result) +{ + return HidumpHelper::GetInstance().Dump(argsStr, result); +} } // namespace DistributedHardware } // namespace OHOS diff --git a/services/distributedhardwarefwkserviceimpl/src/hidumphelper/enabled_comps_dump.cpp b/services/distributedhardwarefwkserviceimpl/src/hidumphelper/enabled_comps_dump.cpp new file mode 100644 index 0000000000000000000000000000000000000000..feeb4fe5762667a17634f4335ac036eb19f05a44 --- /dev/null +++ b/services/distributedhardwarefwkserviceimpl/src/hidumphelper/enabled_comps_dump.cpp @@ -0,0 +1,48 @@ +/* + * Copyright (c) 2022 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 "enabled_comps_dump.h" +#include "dh_utils_tool.h" + +namespace OHOS { +namespace DistributedHardware { +IMPLEMENT_SINGLE_INSTANCE(EnabledCompsDump); + +void EnabledCompsDump::DumpEnabledComp(const std::string &uuid, const DHType dhType, const std::string &dhId) +{ + HidumpCompInfo info (GetDeviceIdByUUID(uuid), dhType, dhId); + + std::lock_guard lock(compInfosMutex_); + compInfoSet_.emplace(info); +} + +void EnabledCompsDump::DumpDisabledComp(const std::string &uuid, const DHType dhType, const std::string &dhId) +{ + HidumpCompInfo info (GetDeviceIdByUUID(uuid), dhType, dhId); + + std::lock_guard lock(compInfosMutex_); + auto it = compInfoSet_.find(info); + if (it != compInfoSet_.end()) { + compInfoSet_.erase(it); + } +} + +void EnabledCompsDump::Dump(std::set &compInfoSet) +{ + std::lock_guard lock(compInfosMutex_); + compInfoSet = compInfoSet_; +} +} // namespace DistributedHardware +} // namespace OHOS \ No newline at end of file diff --git a/services/distributedhardwarefwkserviceimpl/src/hidumphelper/hidump_helper.cpp b/services/distributedhardwarefwkserviceimpl/src/hidumphelper/hidump_helper.cpp new file mode 100644 index 0000000000000000000000000000000000000000..03ab72729a01c26396630951007c788d4e162b00 --- /dev/null +++ b/services/distributedhardwarefwkserviceimpl/src/hidumphelper/hidump_helper.cpp @@ -0,0 +1,289 @@ +/* + * Copyright (c) 2022 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 "hidump_helper.h" + +#include + +#include "capability_info_manager.h" +#include "component_manager.h" +#include "distributed_hardware_errno.h" +#include "distributed_hardware_log.h" +#include "task_board.h" + +namespace OHOS { +namespace DistributedHardware { +IMPLEMENT_SINGLE_INSTANCE(HidumpHelper); +namespace { +const std::string ARGS_HELP = "-h"; +const std::string LOADED_COMP_LIST = "-l"; +const std::string ENABLED_COMP_LIST = "-e"; +const std::string TASK_LIST = "-t"; +const std::string CAPABILITY_LIST = "-c"; + +const std::unordered_map MAP_ARGS = { + { ARGS_HELP, HidumpFlag::GET_HELP }, + { LOADED_COMP_LIST, HidumpFlag::GET_LOADED_COMP_LIST }, + { ENABLED_COMP_LIST, HidumpFlag::GET_ENABLED_COMP_LIST }, + { TASK_LIST, HidumpFlag::GET_TASK_LIST }, + { CAPABILITY_LIST, HidumpFlag::GET_CAPABILITY_LIST }, +}; + +std::unordered_map g_mapDhTypeName = { + { DHType::UNKNOWN, "UNKNOWN" }, + { DHType::CAMERA, "CAMERA" }, + { DHType::MIC, "MIC" }, + { DHType::SPEAKER, "SPEAKER" }, + { DHType::DISPLAY, "DISPLAY" }, + { DHType::GPS, "GPS" }, + { DHType::BUTTON, "BUTTON" }, + { DHType::HFP, "HFP" }, + { DHType::A2D, "A2D" }, + { DHType::VIRMODEM_MIC, "VIRMODEM_MIC" }, + { DHType::VIRMODEM_SPEAKER, "VIRMODEM_SPEAKER" }, +}; + +std::unordered_map g_mapTaskType = { + { TaskType::UNKNOWN, "UNKNOWN" }, + { TaskType::ENABLE, "ENABLE" }, + { TaskType::DISABLE, "DISABLE" }, + { TaskType::ON_LINE, "ON_LINE" }, + { TaskType::OFF_LINE, "OFF_LINE" }, +}; + +std::unordered_map g_mapTaskStep = { + { TaskStep::DO_ENABLE, "DO_ENABLE" }, + { TaskStep::DO_DISABLE, "DO_DISABLE" }, + { TaskStep::SYNC_ONLINE_INFO, "SYNC_ONLINE_INFO" }, + { TaskStep::REGISTER_ONLINE_DISTRIBUTED_HARDWARE, "REGISTER_ONLINE_DISTRIBUTED_HARDWARE" }, + { TaskStep::UNREGISTER_OFFLINE_DISTRIBUTED_HARDWARE, "UNREGISTER_OFFLINE_DISTRIBUTED_HARDWARE" }, + { TaskStep::CLEAR_OFFLINE_INFO, "CLEAR_OFFLINE_INFO" }, + { TaskStep::WAIT_UNREGISTGER_COMPLETE, "WAIT_UNREGISTGER_COMPLETE" }, +}; + +std::unordered_map g_mapTaskState = { + { TaskState::INIT, "INIT" }, + { TaskState::RUNNING, "RUNNING" }, + { TaskState::SUCCESS, "SUCCESS" }, + { TaskState::FAIL, "FAIL" }, +}; +} + +int32_t HidumpHelper::Dump(const std::vector& args, std::string &result) +{ + DHLOGI("HidumpHelper dump start."); + result.clear(); + int32_t errCode = ERR_DH_FWK_HIDUMP_ERROR; + + if (args.empty()) { + return ProcessDump(HidumpFlag::GET_HELP, result); + } + + auto flag = MAP_ARGS.find(args[0]); + if ((args.size() > 1) || (flag == MAP_ARGS.end())) { + errCode = ProcessDump(HidumpFlag::UNKNOWN, result); + } else { + errCode = ProcessDump(flag->second, result); + } + + return errCode; +} + +int32_t HidumpHelper::ProcessDump(const HidumpFlag &flag, std::string &result) +{ + DHLOGI("Process Dump."); + int32_t errCode = ERR_DH_FWK_HIDUMP_ERROR; + switch (flag) { + case HidumpFlag::GET_HELP: { + errCode = ShowHelp(result); + break; + } + case HidumpFlag::GET_LOADED_COMP_LIST: { + errCode = ShowAllLoadedComps(result); + break; + } + case HidumpFlag::GET_ENABLED_COMP_LIST : { + errCode = ShowAllEnabledComps(result); + break; + } + case HidumpFlag::GET_TASK_LIST : { + errCode = ShowAllTaskInfos(result); + break; + } + case HidumpFlag::GET_CAPABILITY_LIST : { + errCode = ShowAllCapabilityInfos(result); + break; + } + default: { + errCode = ShowIllealInfomation(result); + break; + } + } + + return errCode; +} + +int32_t HidumpHelper::ShowAllLoadedComps(std::string &result) +{ + DHLOGI("Dump all loaded compTypes."); + std::set loadedCompSource {}; + std::set loadedCompSink {}; + ComponentManager::GetInstance().DumpLoadedComps(loadedCompSource, loadedCompSink); + + result.append("Local loaded components:\n{"); + result.append("\n Source : ["); + if (!loadedCompSource.empty()) { + for (auto compSource : loadedCompSource) { + result.append(" "); + result.append(g_mapDhTypeName[compSource]); + result.append(","); + } + result.replace(result.size() - 1, 1, " "); + } + result.append("]"); + + result.append("\n Sink : ["); + if (!loadedCompSink.empty()) { + for (auto compSink : loadedCompSink) { + result.append(" "); + result.append(g_mapDhTypeName[compSink]); + result.append(","); + } + result.replace(result.size() - 1, 1, " "); + } + result.append("]"); + result.append("\n}\n"); + return DH_FWK_SUCCESS; +} + +int32_t HidumpHelper::ShowAllEnabledComps(std::string &result) +{ + DHLOGI("Dump all enabled comps."); + std::set compInfoSet {}; + EnabledCompsDump::GetInstance().Dump(compInfoSet); + + result.append("All enabled components:"); + if (compInfoSet.empty()) { + return DH_FWK_SUCCESS; + } + + for (auto info : compInfoSet) { + result.append("\n{"); + result.append("\n DeviceId : "); + result.append(GetAnonyString(info.deviceId_)); + result.append("\n DHType : "); + result.append(g_mapDhTypeName[info.dhType_]); + result.append("\n DHId : "); + result.append(GetAnonyString(info.dhId_)); + result.append("\n},"); + } + result.replace(result.size() - 1, 1, "\n"); + return DH_FWK_SUCCESS; +} + +int32_t HidumpHelper::ShowAllTaskInfos(std::string &result) +{ + DHLOGI("Dump all task infos."); + std::vector taskInfos {}; + TaskBoard::GetInstance().DumpAllTasks(taskInfos); + + result.append("All task infos:"); + if (taskInfos.empty()) { + return DH_FWK_SUCCESS; + } + + for (auto taskInfo : taskInfos) { + result.append("\n{"); + result.append("\n TaskId : "); + result.append(taskInfo.id); + result.append("\n TaskType : "); + result.append(g_mapTaskType[taskInfo.taskType]); + result.append("\n DHType : "); + result.append(g_mapDhTypeName[taskInfo.taskParm.dhType]); + result.append("\n DHId : "); + result.append(GetAnonyString(taskInfo.taskParm.dhId)); + result.append("\n TaskState : "); + result.append(g_mapTaskState[taskInfo.taskState]); + result.append("\n TaskStep : [ "); + std::vector taskSteps = taskInfo.taskSteps; + for (auto step : taskSteps) { + result.append(g_mapTaskStep[step]); + result.append(" "); + } + result.append("]\n"); + result.append("},"); + } + result.replace(result.size() - 1, 1, "\n"); + return DH_FWK_SUCCESS; +} + +int32_t HidumpHelper::ShowAllCapabilityInfos(std::string &result) +{ + DHLOGI("Dump all capability infos."); + std::vector capInfos; + CapabilityInfoManager::GetInstance()->DumpCapabilityInfos(capInfos); + + result.append("All capability info of online components :"); + if (capInfos.empty()) { + return DH_FWK_SUCCESS; + } + + for (auto info : capInfos) { + result.append("\n{"); + result.append("\n DeviceName : "); + result.append(GetAnonyString(info.GetDeviceName())); + result.append("\n DeviceId : "); + result.append(GetAnonyString(info.GetDeviceId())); + result.append("\n DeviceType : "); + result.append(std::to_string(info.GetDeviceType())); + result.append("\n DHType : "); + result.append(g_mapDhTypeName[info.GetDHType()]); + result.append("\n DHId : "); + result.append(GetAnonyString(info.GetDHId())); + result.append("\n DHAttrs :\n"); + result.append(info.GetDHAttrs()); + result.append("\n},"); + } + result.replace(result.size() - 1, 1, "\n"); + return DH_FWK_SUCCESS; +} + +int32_t HidumpHelper::ShowHelp(std::string &result) +{ + DHLOGI("Show dump help."); + result.append("DistributedHardwareFramework dump options:\n"); + result.append(" -h "); + result.append(": Show help\n"); + result.append(" -l "); + result.append(": Show all loaded components\n"); + result.append(" -e "); + result.append(": Show all enabled components\n"); + result.append(" -t "); + result.append(": Show all tasks\n"); + result.append(" -c "); + result.append(": Show all Capability info of online components\n\n"); + + return DH_FWK_SUCCESS; +} + +int32_t HidumpHelper::ShowIllealInfomation(std::string &result) +{ + DHLOGI("ShowIllealInfomation Dump."); + result.clear(); + result.append("Unrecognized option, -h for help."); + return ERR_DH_FWK_HIDUMP_INVALID_ARGS; +} +} // namespace DistributedHardware +} // namespace OHOS \ No newline at end of file diff --git a/services/distributedhardwarefwkserviceimpl/src/resourcemanager/capability_info_manager.cpp b/services/distributedhardwarefwkserviceimpl/src/resourcemanager/capability_info_manager.cpp index 7d6db2c06cf557cfcae87fa68e3bc93cd365582e..07e054739173af88fb187d3193add9e4b8d6fae1 100644 --- a/services/distributedhardwarefwkserviceimpl/src/resourcemanager/capability_info_manager.cpp +++ b/services/distributedhardwarefwkserviceimpl/src/resourcemanager/capability_info_manager.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2021 Huawei Device Co., Ltd. + * Copyright (c) 2021-2022 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 @@ -321,10 +321,6 @@ void CapabilityInfoManager::OnChange(const DistributedKv::ChangeNotification &ch } } -void CapabilityInfoManager::OnChange(const DistributedKv::ChangeNotification &changeNotification, - std::shared_ptr snapshot) -{} - void CapabilityInfoManager::OnEvent(CapabilityInfoEvent &ev) { switch (ev.GetAction()) { @@ -535,5 +531,13 @@ int32_t CapabilityInfoManager::GetDataByKeyPrefix(const std::string &keyPrefix, } return DH_FWK_SUCCESS; } + +void CapabilityInfoManager::DumpCapabilityInfos(std::vector &capInfos) +{ + for (auto info : globalCapInfoMap_) { + CapabilityInfo capInfo = *(info.second); + capInfos.emplace_back(capInfo); + } +} } // namespace DistributedHardware } // namespace OHOS diff --git a/services/distributedhardwarefwkserviceimpl/src/task/task_board.cpp b/services/distributedhardwarefwkserviceimpl/src/task/task_board.cpp index 93ba6f0d788be37b099b60b30a2833f28ff4f27b..59b635b77373d2d4a788028295ec819c29a45372 100644 --- a/services/distributedhardwarefwkserviceimpl/src/task/task_board.cpp +++ b/services/distributedhardwarefwkserviceimpl/src/task/task_board.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2021 Huawei Device Co., Ltd. + * Copyright (c) 2021-2022 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 @@ -85,5 +85,22 @@ void TaskBoard::RemoveTaskInner(std::string taskId) tasks_.erase(taskId); } + +void TaskBoard::DumpAllTasks(std::vector &taskInfos) +{ + std::lock_guard lock(tasksMtx_); + for (auto t : tasks_) { + TaskDump taskInfo = { + .id = t.second->GetId(), + .taskType = t.second->GetTaskType(), + .taskParm.networkId = t.second->GetNetworkId(), + .taskParm.uuid = t.second->GetUUID(), + .taskParm.dhId = t.second->GetDhId(), + .taskParm.dhType = t.second->GetDhType(), + .taskSteps = t.second->GetTaskSteps() + }; + taskInfos.emplace_back(taskInfo); + } +} } // namespace DistributedHardware } // namespace OHOS