From 8cf7c7df3cbc7d13919ea58f33c4114e43b5adb3 Mon Sep 17 00:00:00 2001 From: wangyb0625 Date: Tue, 28 Jun 2022 23:29:59 +0800 Subject: [PATCH 1/4] =?UTF-8?q?0628=E6=B7=BB=E5=8A=A0dumper?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: wangyb0625 --- .../service/include/device_manager_service.h | 3 + .../include/ipc/standard/ipc_server_stub.h | 7 + .../service/src/device_manager_service.cpp | 18 +++ .../src/ipc/standard/ipc_server_stub.cpp | 21 +++ utils/BUILD.gn | 3 + utils/include/dfx/dm_dfx_constants.h | 17 +++ utils/include/dfx/lite/dm_hidumper.h | 44 ++++++ utils/include/dfx/standard/dm_hidumper.h | 49 +++++++ utils/src/dfx/lite/dm_hidumper.cpp | 46 +++++++ utils/src/dfx/standard/dm_hidumper.cpp | 126 ++++++++++++++++++ 10 files changed, 334 insertions(+) create mode 100644 utils/include/dfx/lite/dm_hidumper.h create mode 100644 utils/include/dfx/standard/dm_hidumper.h create mode 100644 utils/src/dfx/lite/dm_hidumper.cpp create mode 100644 utils/src/dfx/standard/dm_hidumper.cpp diff --git a/services/service/include/device_manager_service.h b/services/service/include/device_manager_service.h index 1531c0ec1..4dc49f7d3 100644 --- a/services/service/include/device_manager_service.h +++ b/services/service/include/device_manager_service.h @@ -28,6 +28,8 @@ #include "idevice_manager_service_impl.h" #include "single_instance.h" #include "softbus_listener.h" +#include "dm_dfx_constants.h" +#include "dm_hidumper.h" namespace OHOS { namespace DistributedHardware { @@ -81,6 +83,7 @@ public: bool IsDMServiceImplReady(); + int32_t DmHiDumper(const std::vector& args, std::string &result); private: bool isImplsoLoaded_ = false; std::shared_ptr softbusListener_; diff --git a/services/service/include/ipc/standard/ipc_server_stub.h b/services/service/include/ipc/standard/ipc_server_stub.h index ee8ed98c6..d8939b5b0 100644 --- a/services/service/include/ipc/standard/ipc_server_stub.h +++ b/services/service/include/ipc/standard/ipc_server_stub.h @@ -113,6 +113,13 @@ public: */ const sptr GetDmListener(std::string pkgName) const; + /** + * @tc.name: IpcServerStub::Dump + * @tc.desc: Dump of the Device Manager Service + * @tc.type: FUNC + */ + int32_t Dump(int32_t fd, const std::vector& args) override; + private: IpcServerStub(); ~IpcServerStub() = default; diff --git a/services/service/src/device_manager_service.cpp b/services/service/src/device_manager_service.cpp index d8d7f734b..926d80860 100644 --- a/services/service/src/device_manager_service.cpp +++ b/services/service/src/device_manager_service.cpp @@ -269,5 +269,23 @@ bool DeviceManagerService::IsDMServiceImplReady() isImplsoLoaded_ = true; return true; } + +int32_t DeviceManagerService::DmHiDumper(const std::vector& args, std::string &result) +{ + std::vector dumpflag; + HidumpHelper::GetInstance().GetArgsType(args, dumpflag); + for (unsigned int i = 0; i < dumpflag.size(); i++) { + if (dumpflag[i] == HidumperFlag::HIDUMPER_GET_TRUSTED_LIST) { + std::vector deviceList; + std::string extra; + GetTrustedDeviceList(DM_PKG_NAME, extra, deviceList); + for (unsigned int j = 0; j < deviceList.size(); j++) { + HidumpHelper::GetInstance().SetNodeInfo(deviceList[j]); + } + } + } + HidumpHelper::GetInstance().HiDump(args, result); + return DM_OK; +} } // namespace DistributedHardware } // namespace OHOS diff --git a/services/service/src/ipc/standard/ipc_server_stub.cpp b/services/service/src/ipc/standard/ipc_server_stub.cpp index 63d6e1178..e688c9e8d 100644 --- a/services/service/src/ipc/standard/ipc_server_stub.cpp +++ b/services/service/src/ipc/standard/ipc_server_stub.cpp @@ -22,6 +22,7 @@ #include "device_manager_service.h" #include "dm_constants.h" #include "dm_log.h" +#include "dm_hidumper.h" #include "if_system_ability_manager.h" #include "ipc_cmd_register.h" #include "ipc_skeleton.h" @@ -186,6 +187,26 @@ const sptr IpcServerStub::GetDmListener(std::string pkgName) co return dmListener; } +int32_t IpcServerStub::Dump(int32_t fd, const std::vector& args) +{ + LOGI("DistributedHardwareService Dump."); + std::vector argsStr {}; + for (auto item : args) { + argsStr.emplace_back(Str16ToStr8(item)); + } + std::string result(""); + int ret = DeviceManagerService::GetInstance().DmHiDumper(argsStr, result); + if (ret != DM_OK) { + LOGE("Dump error, ret = %d", ret); + } + ret = dprintf(fd, "%s\n", result.c_str()); + if (ret < 0) { + LOGE("HiDumper dprintf error"); + ret = ERR_DM_FAILED; + } + return ret; +} + void AppDeathRecipient::OnRemoteDied(const wptr &remote) { LOGW("AppDeathRecipient: OnRemoteDied"); diff --git a/utils/BUILD.gn b/utils/BUILD.gn index c411fc3bb..7e9e9e651 100644 --- a/utils/BUILD.gn +++ b/utils/BUILD.gn @@ -42,6 +42,7 @@ if (defined(ohos_lite)) { ] sources = [ + "${utils_path}/src/dfx/lite/dm_hidumper.cpp", "${utils_path}/src/dfx/lite/dm_hisysevent.cpp", "${utils_path}/src/dfx/lite/dm_hitrace.cpp", "${utils_path}/src/dm_anonymous.cpp", @@ -98,6 +99,7 @@ if (defined(ohos_lite)) { "//foundation/distributedschedule/samgr_lite/interfaces/kits/samgr", ] sources = [ + "src/dfx/lite/dm_hidumper.cpp", "src/dfx/lite/dm_hisysevent.cpp", "src/dfx/lite/dm_hitrace.cpp", "src/dm_anonymous.cpp", @@ -144,6 +146,7 @@ if (defined(ohos_lite)) { ohos_shared_library("devicemanagerutils") { sources = [ + "src/dfx/standard/dm_hidumper.cpp", "src/dfx/standard/dm_hisysevent.cpp", "src/dfx/standard/dm_hitrace.cpp", "src/dm_anonymous.cpp", diff --git a/utils/include/dfx/dm_dfx_constants.h b/utils/include/dfx/dm_dfx_constants.h index 3d4f17687..9d761ef4a 100644 --- a/utils/include/dfx/dm_dfx_constants.h +++ b/utils/include/dfx/dm_dfx_constants.h @@ -16,6 +16,7 @@ #define OHOS_DM_DFX_CONSTANTS_H #include +#include namespace OHOS { namespace DistributedHardware { @@ -64,6 +65,22 @@ const std::string DM_HITRACE_AUTH_TO_CONSULT = "DM_HITRACE_AUTH_TO_CONSULT"; const std::string DM_HITRACE_AUTH_TO_OPPEN_SESSION = "DM_HITRACE_AUTH_TO_OPPEN_SESSION"; const std::string DM_HITRACE_DEVICE_ONLINE = "DM_HITRACE_DEVICE_ONLINE"; const std::string DM_HITRACE_INIT = "DM_HITRACE_INIT"; + +// HiDumper Flag +enum class HidumperFlag { + HIDUMPER_UNKNOWN = 0, + HIDUMPER_GET_HELP, + HIDUMPER_GET_TRUSTED_LIST, +}; + +// HiDumper info +const std::string ARGS_HELP = "-help"; +const std::string HIDUMPER_GET_TRUSTED_LIST = "-getTrustlist"; + +const std::unordered_map MAP_ARGS = { + { ARGS_HELP, HidumperFlag::HIDUMPER_GET_HELP }, + { HIDUMPER_GET_TRUSTED_LIST, HidumperFlag::HIDUMPER_GET_TRUSTED_LIST }, +}; } // namespace DistributedHardware } // namespace OHOS #endif // OHOS_DM_DFX_CONSTANTS_H diff --git a/utils/include/dfx/lite/dm_hidumper.h b/utils/include/dfx/lite/dm_hidumper.h new file mode 100644 index 000000000..214255807 --- /dev/null +++ b/utils/include/dfx/lite/dm_hidumper.h @@ -0,0 +1,44 @@ +/* + * 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_DM_HIDUMPER_H +#define OHOS_DM_HIDUMPER_H + +#include +#include +#include +#include +#include + +#include "dm_constants.h" +#include "dm_dfx_constants.h" +#include "single_instance.h" + +namespace OHOS { +namespace DistributedHardware { +class HidumpHelper { +IMPLEMENT_SINGLE_INSTANCE(HidumpHelper); +public: + int32_t HiDump(const std::vector& args, std::string &result); + +private: + int32_t ProcessDump(const HidumperFlag &flag, std::string &result); + int32_t ShowAllLoadTrustedList(std::string &result); + int32_t ShowHelp(std::string &result); + int32_t ShowIllealInfomation(std::string &result); +}; +} // namespace DistributedHardware +} // namespace OHOS +#endif // OHOS_DM_HIDUMPER_H diff --git a/utils/include/dfx/standard/dm_hidumper.h b/utils/include/dfx/standard/dm_hidumper.h new file mode 100644 index 000000000..b4176bbf7 --- /dev/null +++ b/utils/include/dfx/standard/dm_hidumper.h @@ -0,0 +1,49 @@ +/* + * 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_DM_HIDUMPER_H +#define OHOS_DM_HIDUMPER_H + +#include +#include +#include +#include + +#include "dm_constants.h" +#include "dm_dfx_constants.h" +#include "single_instance.h" +#include "dm_log.h" +#include "dm_device_info.h" + +namespace OHOS { +namespace DistributedHardware { +class HidumpHelper { +DECLARE_SINGLE_INSTANCE(HidumpHelper); +public: + int32_t HiDump(const std::vector& args, std::string &result); + void GetArgsType(const std::vector& args, std::vector &Flag); + void SetNodeInfo(const DmDeviceInfo& deviceInfo); +private: + int32_t ProcessDump(const HidumperFlag &flag, std::string &result); + int32_t ShowAllLoadTrustedList(std::string &result); + int32_t ShowHelp(std::string &result); + int32_t ShowIllealInfomation(std::string &result); + +private: + std::vector nodeInfos_; +}; +} // namespace DistributedHardware +} // namespace OHOS +#endif // OHOS_DM_HIDUMPER_H diff --git a/utils/src/dfx/lite/dm_hidumper.cpp b/utils/src/dfx/lite/dm_hidumper.cpp new file mode 100644 index 000000000..933c16d82 --- /dev/null +++ b/utils/src/dfx/lite/dm_hidumper.cpp @@ -0,0 +1,46 @@ +/* + * 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 "dm_hidumper.h" + +namespace OHOS { +namespace DistributedHardware { +IMPLEMENT_SINGLE_INSTANCE(HidumpHelper); +int32_t HidumpHelper::HiDump(const std::vector& args, std::string &result) +{ + return DM_OK; +} + +int32_t HidumpHelper::ProcessDump(const HidumperFlag &flag, std::string &result) +{ + return DM_OK; +} + +int32_t HidumpHelper::ShowAllLoadTrustedList(std::string &result) +{ + return DM_OK; +} + +int32_t HidumpHelper::ShowHelp(std::string &result) +{ + return DM_OK; +} + +int32_t HidumpHelper::ShowIllealInfomation(std::string &result) +{ + return ERR_DM_FAILED; +} +} // namespace DistributedHardware +} // namespace OHOS diff --git a/utils/src/dfx/standard/dm_hidumper.cpp b/utils/src/dfx/standard/dm_hidumper.cpp new file mode 100644 index 000000000..9341e1585 --- /dev/null +++ b/utils/src/dfx/standard/dm_hidumper.cpp @@ -0,0 +1,126 @@ +/* + * 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 + +#include "dm_hidumper.h" +#include "dm_anonymous.h" +#include "dm_dfx_constants.h" +#include "dm_device_info.h" + +namespace OHOS { +namespace DistributedHardware { +IMPLEMENT_SINGLE_INSTANCE(HidumpHelper); +int32_t HidumpHelper::HiDump(const std::vector& args, std::string &result) +{ + LOGI("HidumpHelper hidumper start."); + result.clear(); + int32_t errCode = ERR_DM_FAILED; + if (args.empty()) { + return ProcessDump(HidumperFlag::HIDUMPER_GET_HELP, result); + } + auto flag = MAP_ARGS.find(args[0]); + if ((args.size() > 1) || (flag == MAP_ARGS.end())) { + errCode = ProcessDump(HidumperFlag::HIDUMPER_UNKNOWN, result); + } else { + errCode = ProcessDump(flag->second, result); + } + return errCode; +} + +void HidumpHelper::SetNodeInfo(const DmDeviceInfo& deviceInfo) +{ + nodeInfos_.push_back(deviceInfo); +} + +int32_t HidumpHelper::ProcessDump(const HidumperFlag &flag, std::string &result) +{ + LOGI("Process Dump."); + int32_t ret = ERR_DM_FAILED; + switch (flag) { + case HidumperFlag::HIDUMPER_GET_HELP: { + ret = ShowHelp(result); + break; + } + case HidumperFlag::HIDUMPER_GET_TRUSTED_LIST: { + ret = ShowAllLoadTrustedList(result); + break; + } + default: { + ret = ShowIllealInfomation(result); + break; + } + } + return ret; +} + +int32_t HidumpHelper::ShowAllLoadTrustedList(std::string &result) +{ + LOGI("Dump Show All Load Trust List."); + int32_t ret = DM_OK; + + if (nodeInfos_.size() == 0) { + LOGE("Hidumper get trusted list is 0"); + } + for (unsigned int i = 0; i < nodeInfos_.size(); ++i) { + result.append("\n{\n deviceId : ").append(GetAnonyString(nodeInfos_[i].deviceId).c_str()); + result.append("\n{\n deviceName : ").append(nodeInfos_[i].deviceName); + result.append("\n{\n networkId : ").append(GetAnonyString(nodeInfos_[i].networkId).c_str()); + } + nodeInfos_.clear(); + result.replace(result.size() - 1, 1, "\n"); + + LOGI("HidumpHelper ShowAllLoadTrustedList %s", result.c_str()); + return ret; +} + +int32_t HidumpHelper::ShowHelp(std::string &result) +{ + LOGI("Show hidumper help."); + result.append("DistributedHardwareDeviceManager hidumper options:\n"); + result.append(" -help "); + result.append(": Show help\n"); + result.append(" -getTrustlist "); + result.append(": Show all get trusted list:\n"); + result.append(" -getOnlineDeviceInfo "); + result.append(": Show all get online device list\n"); + result.append(" -getOfflineDeviceInfo "); + result.append(": Show all get offline device list\n\n"); + LOGI("result is %s", result.c_str()); + return DM_OK; +} + +int32_t HidumpHelper::ShowIllealInfomation(std::string &result) +{ + LOGI("ShowIllealInfomation Dump."); + result.clear(); + result.append("Unrecognized option, -h for help."); + return ERR_DM_FAILED; +} + +void HidumpHelper::GetArgsType(const std::vector& args, std::vector &Flag) +{ + LOGI("HidumpHelper::GetArgsType."); + if (args.empty()) { + Flag.push_back(HidumperFlag::HIDUMPER_GET_HELP); + } + + auto flag = MAP_ARGS.find(args[0]); + if ((args.size() > 1) || (flag == MAP_ARGS.end())) { + Flag.push_back(flag->second); + } +} +} // namespace DistributedHardware +} // namespace OHOS -- Gitee From 462e22518cd92cad6597259a1b8e1d579ba68fe7 Mon Sep 17 00:00:00 2001 From: wangyb0625 Date: Wed, 29 Jun 2022 17:39:09 +0800 Subject: [PATCH 2/4] =?UTF-8?q?=E5=A2=9E=E5=8A=A0dumper=20Signed-off-by:?= =?UTF-8?q?=20wangyb0625=20?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../include/softbus/softbus_listener.h | 1 + .../service/src/device_manager_service.cpp | 18 +++++++-- .../src/ipc/standard/ipc_server_stub.cpp | 2 + .../service/src/softbus/softbus_listener.cpp | 38 ++++++++++++++++++ utils/BUILD.gn | 3 ++ utils/include/dfx/dm_dfx_constants.h | 11 ++++-- utils/include/dfx/lite/dm_hidumper.h | 16 ++++---- utils/include/dfx/standard/dm_hidumper.h | 6 ++- utils/src/dfx/lite/dm_hidumper.cpp | 15 ++----- utils/src/dfx/standard/dm_hidumper.cpp | 39 +++++++++++-------- 10 files changed, 103 insertions(+), 46 deletions(-) diff --git a/services/service/include/softbus/softbus_listener.h b/services/service/include/softbus/softbus_listener.h index 526a69173..5ac58532c 100644 --- a/services/service/include/softbus/softbus_listener.h +++ b/services/service/include/softbus/softbus_listener.h @@ -101,6 +101,7 @@ public: ~SoftbusListener(); int32_t GetTrustedDeviceList(std::vector &deviceInfoList); int32_t GetLocalDeviceInfo(DmDeviceInfo &deviceInfo); + bool DumperIsDeviceOnline(const std::string &deviceId); private: int32_t Init(); diff --git a/services/service/src/device_manager_service.cpp b/services/service/src/device_manager_service.cpp index 926d80860..5e9dcf535 100644 --- a/services/service/src/device_manager_service.cpp +++ b/services/service/src/device_manager_service.cpp @@ -87,6 +87,8 @@ int32_t DeviceManagerService::GetLocalDeviceInfo(DmDeviceInfo &info) return ret; } + + int32_t DeviceManagerService::GetUdidByNetworkId(const std::string &pkgName, const std::string &netWorkId, std::string &udid) { @@ -272,15 +274,25 @@ bool DeviceManagerService::IsDMServiceImplReady() int32_t DeviceManagerService::DmHiDumper(const std::vector& args, std::string &result) { + LOGI("Hidumper GetTrustedDeviceList"); std::vector dumpflag; HidumpHelper::GetInstance().GetArgsType(args, dumpflag); + for (unsigned int i = 0; i < dumpflag.size(); i++) { if (dumpflag[i] == HidumperFlag::HIDUMPER_GET_TRUSTED_LIST) { std::vector deviceList; - std::string extra; - GetTrustedDeviceList(DM_PKG_NAME, extra, deviceList); + + int32_t ret = softbusListener_->GetTrustedDeviceList(deviceList); + if (ret != DM_OK) { + result.append("Hidumper GetTrustedDeviceList failed"); + LOGE("Hidumper GetTrustedDeviceList failed"); + return ERR_DM_FAILED; + } + bool deviceState = false; for (unsigned int j = 0; j < deviceList.size(); j++) { - HidumpHelper::GetInstance().SetNodeInfo(deviceList[j]); + deviceState = softbusListener_->DumperIsDeviceOnline(deviceList[j].deviceId); + HidumpHelper::GetInstance().SetNodeInfo(deviceList[j], deviceState); + LOGI("DeviceManagerService::DmHiDumper SetNodeInfo."); } } } diff --git a/services/service/src/ipc/standard/ipc_server_stub.cpp b/services/service/src/ipc/standard/ipc_server_stub.cpp index e688c9e8d..aca2d78dd 100644 --- a/services/service/src/ipc/standard/ipc_server_stub.cpp +++ b/services/service/src/ipc/standard/ipc_server_stub.cpp @@ -194,11 +194,13 @@ int32_t IpcServerStub::Dump(int32_t fd, const std::vector& args) for (auto item : args) { argsStr.emplace_back(Str16ToStr8(item)); } + std::string result(""); int ret = DeviceManagerService::GetInstance().DmHiDumper(argsStr, result); if (ret != DM_OK) { LOGE("Dump error, ret = %d", ret); } + ret = dprintf(fd, "%s\n", result.c_str()); if (ret < 0) { LOGE("HiDumper dprintf error"); diff --git a/services/service/src/softbus/softbus_listener.cpp b/services/service/src/softbus/softbus_listener.cpp index e4b5c5e1c..8ea1eb2d4 100644 --- a/services/service/src/softbus/softbus_listener.cpp +++ b/services/service/src/softbus/softbus_listener.cpp @@ -175,6 +175,44 @@ int32_t SoftbusListener::GetTrustedDeviceList(std::vector &deviceI return DM_OK; } +bool SoftbusListener::DumperIsDeviceOnline(const std::string &deviceId) +{ + NodeBasicInfo *info = nullptr; + int32_t infoNum = 0; + if (GetAllNodeDeviceInfo(DM_PKG_NAME.c_str(), &info, &infoNum) != DM_OK) { + LOGE("GetAllNodeDeviceInfo failed"); + return false; + } + bool bDeviceOnline = false; + for (int32_t i = 0; i < infoNum; ++i) { + NodeBasicInfo *nodeBasicInfo = info + i; + if (nodeBasicInfo == nullptr) { + LOGE("nodeBasicInfo is empty for index %d, infoNum %d.", i, infoNum); + continue; + } + std::string networkId = nodeBasicInfo->networkId; + if (networkId == deviceId) { + LOGI("DM_IsDeviceOnLine device %s online", GetAnonyString(deviceId).c_str()); + bDeviceOnline = true; + break; + } + uint8_t udid[UDID_BUF_LEN] = {0}; + int32_t ret = GetNodeKeyInfo(DM_PKG_NAME.c_str(), networkId.c_str(), NodeDeviceInfoKey::NODE_KEY_UDID, udid, + sizeof(udid)); + if (ret != DM_OK) { + LOGE("DM_IsDeviceOnLine GetNodeKeyInfo failed"); + break; + } + if (strcmp((char *)udid, deviceId.c_str()) == 0) { + LOGI("DM_IsDeviceOnLine device %s online", GetAnonyString(deviceId).c_str()); + bDeviceOnline = true; + break; + } + } + FreeNodeInfo(info); + return bDeviceOnline; +} + int32_t SoftbusListener::GetLocalDeviceInfo(DmDeviceInfo &deviceInfo) { LOGI("SoftbusListener::GetLocalDeviceInfo start"); diff --git a/utils/BUILD.gn b/utils/BUILD.gn index 7e9e9e651..7eb18acf7 100644 --- a/utils/BUILD.gn +++ b/utils/BUILD.gn @@ -28,6 +28,7 @@ if (defined(ohos_lite)) { "${utils_path}/include/dfx/lite", "${utils_path}/include/permission/lite", "${common_path}/include", + "${innerkits_path}/native_cpp/include", ] include_dirs += [ @@ -75,6 +76,7 @@ if (defined(ohos_lite)) { "${common_path}/include", "${common_path}/include/ipc", "${common_path}/include/ipc/model", + "${innerkits_path}/native_cpp/include", "include", "include/dfx", "include/dfx/lite", @@ -139,6 +141,7 @@ if (defined(ohos_lite)) { "${common_path}/include", "${common_path}/include/ipc", "${common_path}/include/ipc/model", + "${innerkits_path}/native_cpp/include", "include/permission/standard", "//third_party/mbedtls/include/mbedtls", ] diff --git a/utils/include/dfx/dm_dfx_constants.h b/utils/include/dfx/dm_dfx_constants.h index 9d761ef4a..e3aa466d4 100644 --- a/utils/include/dfx/dm_dfx_constants.h +++ b/utils/include/dfx/dm_dfx_constants.h @@ -71,15 +71,18 @@ enum class HidumperFlag { HIDUMPER_UNKNOWN = 0, HIDUMPER_GET_HELP, HIDUMPER_GET_TRUSTED_LIST, + HIDUMPER_GET_DEVICE_STATE, }; // HiDumper info -const std::string ARGS_HELP = "-help"; -const std::string HIDUMPER_GET_TRUSTED_LIST = "-getTrustlist"; +const std::string ARGS_HELP_INFO = "-help"; +const std::string HIDUMPER_GET_TRUSTED_LIST_INFO = "-getTrustlist"; +const std::string HIDUMPER_GET_DEVICE_STATE_INFO = "-getDeviceState"; const std::unordered_map MAP_ARGS = { - { ARGS_HELP, HidumperFlag::HIDUMPER_GET_HELP }, - { HIDUMPER_GET_TRUSTED_LIST, HidumperFlag::HIDUMPER_GET_TRUSTED_LIST }, + { ARGS_HELP_INFO, HidumperFlag::HIDUMPER_GET_HELP }, + { HIDUMPER_GET_TRUSTED_LIST_INFO, HidumperFlag::HIDUMPER_GET_TRUSTED_LIST }, + { HIDUMPER_GET_DEVICE_STATE_INFO, HidumperFlag::HIDUMPER_GET_DEVICE_STATE }, }; } // namespace DistributedHardware } // namespace OHOS diff --git a/utils/include/dfx/lite/dm_hidumper.h b/utils/include/dfx/lite/dm_hidumper.h index 214255807..241ca3245 100644 --- a/utils/include/dfx/lite/dm_hidumper.h +++ b/utils/include/dfx/lite/dm_hidumper.h @@ -20,24 +20,22 @@ #include #include #include -#include +#include "single_instance.h" #include "dm_constants.h" #include "dm_dfx_constants.h" -#include "single_instance.h" +#include "dm_log.h" +#include "dm_device_info.h" namespace OHOS { namespace DistributedHardware { class HidumpHelper { -IMPLEMENT_SINGLE_INSTANCE(HidumpHelper); + DECLARE_SINGLE_INSTANCE(HidumpHelper); + public: int32_t HiDump(const std::vector& args, std::string &result); - -private: - int32_t ProcessDump(const HidumperFlag &flag, std::string &result); - int32_t ShowAllLoadTrustedList(std::string &result); - int32_t ShowHelp(std::string &result); - int32_t ShowIllealInfomation(std::string &result); + int32_t GetArgsType(const std::vector& args, std::vector &Flag); + void SetNodeInfo(const DmDeviceInfo& deviceInfo, const bool deviceStates); }; } // namespace DistributedHardware } // namespace OHOS diff --git a/utils/include/dfx/standard/dm_hidumper.h b/utils/include/dfx/standard/dm_hidumper.h index b4176bbf7..6e39f0341 100644 --- a/utils/include/dfx/standard/dm_hidumper.h +++ b/utils/include/dfx/standard/dm_hidumper.h @@ -33,8 +33,9 @@ class HidumpHelper { DECLARE_SINGLE_INSTANCE(HidumpHelper); public: int32_t HiDump(const std::vector& args, std::string &result); - void GetArgsType(const std::vector& args, std::vector &Flag); - void SetNodeInfo(const DmDeviceInfo& deviceInfo); + int32_t GetArgsType(const std::vector& args, std::vector &Flag); + void SetNodeInfo(const DmDeviceInfo& deviceInfo, const bool deviceStates); + private: int32_t ProcessDump(const HidumperFlag &flag, std::string &result); int32_t ShowAllLoadTrustedList(std::string &result); @@ -43,6 +44,7 @@ private: private: std::vector nodeInfos_; + std::vector deviceState_; }; } // namespace DistributedHardware } // namespace OHOS diff --git a/utils/src/dfx/lite/dm_hidumper.cpp b/utils/src/dfx/lite/dm_hidumper.cpp index 933c16d82..3cabdae92 100644 --- a/utils/src/dfx/lite/dm_hidumper.cpp +++ b/utils/src/dfx/lite/dm_hidumper.cpp @@ -23,24 +23,15 @@ int32_t HidumpHelper::HiDump(const std::vector& args, std::string & return DM_OK; } -int32_t HidumpHelper::ProcessDump(const HidumperFlag &flag, std::string &result) +int32_t HidumpHelper::GetArgsType(const std::vector& args, std::vector &Flag) { return DM_OK; } -int32_t HidumpHelper::ShowAllLoadTrustedList(std::string &result) +void HidumpHelper::SetNodeInfo(const DmDeviceInfo& deviceInfo, const bool deviceStates) { - return DM_OK; + return; } -int32_t HidumpHelper::ShowHelp(std::string &result) -{ - return DM_OK; -} - -int32_t HidumpHelper::ShowIllealInfomation(std::string &result) -{ - return ERR_DM_FAILED; -} } // namespace DistributedHardware } // namespace OHOS diff --git a/utils/src/dfx/standard/dm_hidumper.cpp b/utils/src/dfx/standard/dm_hidumper.cpp index 9341e1585..4434021f3 100644 --- a/utils/src/dfx/standard/dm_hidumper.cpp +++ b/utils/src/dfx/standard/dm_hidumper.cpp @@ -28,6 +28,7 @@ int32_t HidumpHelper::HiDump(const std::vector& args, std::string & LOGI("HidumpHelper hidumper start."); result.clear(); int32_t errCode = ERR_DM_FAILED; + if (args.empty()) { return ProcessDump(HidumperFlag::HIDUMPER_GET_HELP, result); } @@ -40,9 +41,15 @@ int32_t HidumpHelper::HiDump(const std::vector& args, std::string & return errCode; } -void HidumpHelper::SetNodeInfo(const DmDeviceInfo& deviceInfo) +void HidumpHelper::SetNodeInfo(const DmDeviceInfo& deviceInfo, const bool deviceStates) { + LOGI("HidumpHelper::SetNodeInfo"); nodeInfos_.push_back(deviceInfo); + std::string deviceState = "offline"; + if (deviceStates) { + deviceState = "online"; + } + deviceState_.push_back(deviceState); } int32_t HidumpHelper::ProcessDump(const HidumperFlag &flag, std::string &result) @@ -68,20 +75,21 @@ int32_t HidumpHelper::ProcessDump(const HidumperFlag &flag, std::string &result) int32_t HidumpHelper::ShowAllLoadTrustedList(std::string &result) { - LOGI("Dump Show All Load Trust List."); + LOGI("Dump Show All Load Trust List"); int32_t ret = DM_OK; if (nodeInfos_.size() == 0) { - LOGE("Hidumper get trusted list is 0"); + LOGE("Hidumper get trusted list is empty"); + result.append("Hidumper get trusted list is empty"); } for (unsigned int i = 0; i < nodeInfos_.size(); ++i) { result.append("\n{\n deviceId : ").append(GetAnonyString(nodeInfos_[i].deviceId).c_str()); result.append("\n{\n deviceName : ").append(nodeInfos_[i].deviceName); result.append("\n{\n networkId : ").append(GetAnonyString(nodeInfos_[i].networkId).c_str()); + result.append("\n{\n deviceState : ").append(deviceState_[i]); } - nodeInfos_.clear(); - result.replace(result.size() - 1, 1, "\n"); + nodeInfos_.clear(); LOGI("HidumpHelper ShowAllLoadTrustedList %s", result.c_str()); return ret; } @@ -90,14 +98,10 @@ int32_t HidumpHelper::ShowHelp(std::string &result) { LOGI("Show hidumper help."); result.append("DistributedHardwareDeviceManager hidumper options:\n"); - result.append(" -help "); + result.append(" -help "); result.append(": Show help\n"); - result.append(" -getTrustlist "); - result.append(": Show all get trusted list:\n"); - result.append(" -getOnlineDeviceInfo "); - result.append(": Show all get online device list\n"); - result.append(" -getOfflineDeviceInfo "); - result.append(": Show all get offline device list\n\n"); + result.append(" -getTrustlist "); + result.append(": Show all get trusted list:\n\n"); LOGI("result is %s", result.c_str()); return DM_OK; } @@ -107,20 +111,23 @@ int32_t HidumpHelper::ShowIllealInfomation(std::string &result) LOGI("ShowIllealInfomation Dump."); result.clear(); result.append("Unrecognized option, -h for help."); - return ERR_DM_FAILED; + return DM_OK; } -void HidumpHelper::GetArgsType(const std::vector& args, std::vector &Flag) +int32_t HidumpHelper::GetArgsType(const std::vector& args, std::vector &Flag) { - LOGI("HidumpHelper::GetArgsType."); + LOGI("HidumpHelper::GetArgsType"); + int32_t ret = ERR_DM_FAILED; if (args.empty()) { Flag.push_back(HidumperFlag::HIDUMPER_GET_HELP); + return ret; } auto flag = MAP_ARGS.find(args[0]); - if ((args.size() > 1) || (flag == MAP_ARGS.end())) { + if (flag != MAP_ARGS.end()) { Flag.push_back(flag->second); } + return ret; } } // namespace DistributedHardware } // namespace OHOS -- Gitee From 00bd0cccaff2f582760e00bcf5c8aefec98dfdc7 Mon Sep 17 00:00:00 2001 From: wangyb0625 Date: Wed, 29 Jun 2022 19:42:33 +0800 Subject: [PATCH 3/4] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E6=A3=80=E8=A7=86?= =?UTF-8?q?=E6=84=8F=E8=A7=81=20Signed-off-by:=20wangyb0625=20?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../include/softbus/softbus_listener.h | 2 +- .../service/src/device_manager_service.cpp | 16 +++++----- .../service/src/softbus/softbus_listener.cpp | 2 +- utils/include/dfx/dm_dfx_constants.h | 2 -- utils/include/dfx/lite/dm_hidumper.h | 4 +-- utils/include/dfx/standard/dm_hidumper.h | 4 +-- utils/src/dfx/lite/dm_hidumper.cpp | 9 +++--- utils/src/dfx/standard/dm_hidumper.cpp | 30 +++++++++---------- 8 files changed, 32 insertions(+), 37 deletions(-) diff --git a/services/service/include/softbus/softbus_listener.h b/services/service/include/softbus/softbus_listener.h index 5ac58532c..ce0391525 100644 --- a/services/service/include/softbus/softbus_listener.h +++ b/services/service/include/softbus/softbus_listener.h @@ -101,7 +101,7 @@ public: ~SoftbusListener(); int32_t GetTrustedDeviceList(std::vector &deviceInfoList); int32_t GetLocalDeviceInfo(DmDeviceInfo &deviceInfo); - bool DumperIsDeviceOnline(const std::string &deviceId); + bool IsDeviceOnline(const std::string &deviceId); private: int32_t Init(); diff --git a/services/service/src/device_manager_service.cpp b/services/service/src/device_manager_service.cpp index 5e9dcf535..7c1de2c6c 100644 --- a/services/service/src/device_manager_service.cpp +++ b/services/service/src/device_manager_service.cpp @@ -87,8 +87,6 @@ int32_t DeviceManagerService::GetLocalDeviceInfo(DmDeviceInfo &info) return ret; } - - int32_t DeviceManagerService::GetUdidByNetworkId(const std::string &pkgName, const std::string &netWorkId, std::string &udid) { @@ -274,9 +272,9 @@ bool DeviceManagerService::IsDMServiceImplReady() int32_t DeviceManagerService::DmHiDumper(const std::vector& args, std::string &result) { - LOGI("Hidumper GetTrustedDeviceList"); + LOGI("HiDump GetTrustedDeviceList"); std::vector dumpflag; - HidumpHelper::GetInstance().GetArgsType(args, dumpflag); + HiDumpHelper::GetInstance().GetArgsType(args, dumpflag); for (unsigned int i = 0; i < dumpflag.size(); i++) { if (dumpflag[i] == HidumperFlag::HIDUMPER_GET_TRUSTED_LIST) { @@ -284,19 +282,19 @@ int32_t DeviceManagerService::DmHiDumper(const std::vector& args, s int32_t ret = softbusListener_->GetTrustedDeviceList(deviceList); if (ret != DM_OK) { - result.append("Hidumper GetTrustedDeviceList failed"); - LOGE("Hidumper GetTrustedDeviceList failed"); + result.append("HiDumpHelper GetTrustedDeviceList failed"); + LOGE("HiDumpHelper GetTrustedDeviceList failed"); return ERR_DM_FAILED; } bool deviceState = false; for (unsigned int j = 0; j < deviceList.size(); j++) { - deviceState = softbusListener_->DumperIsDeviceOnline(deviceList[j].deviceId); - HidumpHelper::GetInstance().SetNodeInfo(deviceList[j], deviceState); + deviceState = softbusListener_->IsDeviceOnline(deviceList[j].deviceId); + HiDumpHelper::GetInstance().SetNodeInfo(deviceList[j], deviceState); LOGI("DeviceManagerService::DmHiDumper SetNodeInfo."); } } } - HidumpHelper::GetInstance().HiDump(args, result); + HiDumpHelper::GetInstance().HiDump(args, result); return DM_OK; } } // namespace DistributedHardware diff --git a/services/service/src/softbus/softbus_listener.cpp b/services/service/src/softbus/softbus_listener.cpp index 8ea1eb2d4..ea141118f 100644 --- a/services/service/src/softbus/softbus_listener.cpp +++ b/services/service/src/softbus/softbus_listener.cpp @@ -175,7 +175,7 @@ int32_t SoftbusListener::GetTrustedDeviceList(std::vector &deviceI return DM_OK; } -bool SoftbusListener::DumperIsDeviceOnline(const std::string &deviceId) +bool SoftbusListener::IsDeviceOnline(const std::string &deviceId) { NodeBasicInfo *info = nullptr; int32_t infoNum = 0; diff --git a/utils/include/dfx/dm_dfx_constants.h b/utils/include/dfx/dm_dfx_constants.h index e3aa466d4..1605aefdc 100644 --- a/utils/include/dfx/dm_dfx_constants.h +++ b/utils/include/dfx/dm_dfx_constants.h @@ -77,12 +77,10 @@ enum class HidumperFlag { // HiDumper info const std::string ARGS_HELP_INFO = "-help"; const std::string HIDUMPER_GET_TRUSTED_LIST_INFO = "-getTrustlist"; -const std::string HIDUMPER_GET_DEVICE_STATE_INFO = "-getDeviceState"; const std::unordered_map MAP_ARGS = { { ARGS_HELP_INFO, HidumperFlag::HIDUMPER_GET_HELP }, { HIDUMPER_GET_TRUSTED_LIST_INFO, HidumperFlag::HIDUMPER_GET_TRUSTED_LIST }, - { HIDUMPER_GET_DEVICE_STATE_INFO, HidumperFlag::HIDUMPER_GET_DEVICE_STATE }, }; } // namespace DistributedHardware } // namespace OHOS diff --git a/utils/include/dfx/lite/dm_hidumper.h b/utils/include/dfx/lite/dm_hidumper.h index 241ca3245..298d61548 100644 --- a/utils/include/dfx/lite/dm_hidumper.h +++ b/utils/include/dfx/lite/dm_hidumper.h @@ -29,8 +29,8 @@ namespace OHOS { namespace DistributedHardware { -class HidumpHelper { - DECLARE_SINGLE_INSTANCE(HidumpHelper); +class HiDumpHelper { + DECLARE_SINGLE_INSTANCE(HiDumpHelper); public: int32_t HiDump(const std::vector& args, std::string &result); diff --git a/utils/include/dfx/standard/dm_hidumper.h b/utils/include/dfx/standard/dm_hidumper.h index 6e39f0341..dc1bf5b4c 100644 --- a/utils/include/dfx/standard/dm_hidumper.h +++ b/utils/include/dfx/standard/dm_hidumper.h @@ -29,8 +29,8 @@ namespace OHOS { namespace DistributedHardware { -class HidumpHelper { -DECLARE_SINGLE_INSTANCE(HidumpHelper); +class HiDumpHelper { +DECLARE_SINGLE_INSTANCE(HiDumpHelper); public: int32_t HiDump(const std::vector& args, std::string &result); int32_t GetArgsType(const std::vector& args, std::vector &Flag); diff --git a/utils/src/dfx/lite/dm_hidumper.cpp b/utils/src/dfx/lite/dm_hidumper.cpp index 3cabdae92..ca6ab9920 100644 --- a/utils/src/dfx/lite/dm_hidumper.cpp +++ b/utils/src/dfx/lite/dm_hidumper.cpp @@ -17,21 +17,20 @@ namespace OHOS { namespace DistributedHardware { -IMPLEMENT_SINGLE_INSTANCE(HidumpHelper); -int32_t HidumpHelper::HiDump(const std::vector& args, std::string &result) +IMPLEMENT_SINGLE_INSTANCE(HiDumpHelper); +int32_t HiDumpHelper::HiDump(const std::vector& args, std::string &result) { return DM_OK; } -int32_t HidumpHelper::GetArgsType(const std::vector& args, std::vector &Flag) +int32_t HiDumpHelper::GetArgsType(const std::vector& args, std::vector &Flag) { return DM_OK; } -void HidumpHelper::SetNodeInfo(const DmDeviceInfo& deviceInfo, const bool deviceStates) +void HiDumpHelper::SetNodeInfo(const DmDeviceInfo& deviceInfo, const bool deviceStates) { return; } - } // namespace DistributedHardware } // namespace OHOS diff --git a/utils/src/dfx/standard/dm_hidumper.cpp b/utils/src/dfx/standard/dm_hidumper.cpp index 4434021f3..fc72bef19 100644 --- a/utils/src/dfx/standard/dm_hidumper.cpp +++ b/utils/src/dfx/standard/dm_hidumper.cpp @@ -15,17 +15,17 @@ #include -#include "dm_hidumper.h" #include "dm_anonymous.h" #include "dm_dfx_constants.h" #include "dm_device_info.h" +#include "dm_hidumper.h" namespace OHOS { namespace DistributedHardware { -IMPLEMENT_SINGLE_INSTANCE(HidumpHelper); -int32_t HidumpHelper::HiDump(const std::vector& args, std::string &result) +IMPLEMENT_SINGLE_INSTANCE(HiDumpHelper); +int32_t HiDumpHelper::HiDump(const std::vector& args, std::string &result) { - LOGI("HidumpHelper hidumper start."); + LOGI("HiDumpHelper start."); result.clear(); int32_t errCode = ERR_DM_FAILED; @@ -41,9 +41,9 @@ int32_t HidumpHelper::HiDump(const std::vector& args, std::string & return errCode; } -void HidumpHelper::SetNodeInfo(const DmDeviceInfo& deviceInfo, const bool deviceStates) +void HiDumpHelper::SetNodeInfo(const DmDeviceInfo& deviceInfo, const bool deviceStates) { - LOGI("HidumpHelper::SetNodeInfo"); + LOGI("HiDumpHelper::SetNodeInfo"); nodeInfos_.push_back(deviceInfo); std::string deviceState = "offline"; if (deviceStates) { @@ -52,7 +52,7 @@ void HidumpHelper::SetNodeInfo(const DmDeviceInfo& deviceInfo, const bool device deviceState_.push_back(deviceState); } -int32_t HidumpHelper::ProcessDump(const HidumperFlag &flag, std::string &result) +int32_t HiDumpHelper::ProcessDump(const HidumperFlag &flag, std::string &result) { LOGI("Process Dump."); int32_t ret = ERR_DM_FAILED; @@ -73,7 +73,7 @@ int32_t HidumpHelper::ProcessDump(const HidumperFlag &flag, std::string &result) return ret; } -int32_t HidumpHelper::ShowAllLoadTrustedList(std::string &result) +int32_t HiDumpHelper::ShowAllLoadTrustedList(std::string &result) { LOGI("Dump Show All Load Trust List"); int32_t ret = DM_OK; @@ -90,13 +90,13 @@ int32_t HidumpHelper::ShowAllLoadTrustedList(std::string &result) } nodeInfos_.clear(); - LOGI("HidumpHelper ShowAllLoadTrustedList %s", result.c_str()); + LOGI("HiDumpHelper ShowAllLoadTrustedList %s", result.c_str()); return ret; } -int32_t HidumpHelper::ShowHelp(std::string &result) +int32_t HiDumpHelper::ShowHelp(std::string &result) { - LOGI("Show hidumper help."); + LOGI("Show hidumper help"); result.append("DistributedHardwareDeviceManager hidumper options:\n"); result.append(" -help "); result.append(": Show help\n"); @@ -106,17 +106,17 @@ int32_t HidumpHelper::ShowHelp(std::string &result) return DM_OK; } -int32_t HidumpHelper::ShowIllealInfomation(std::string &result) +int32_t HiDumpHelper::ShowIllealInfomation(std::string &result) { - LOGI("ShowIllealInfomation Dump."); + LOGI("ShowIllealInfomation Dump"); result.clear(); result.append("Unrecognized option, -h for help."); return DM_OK; } -int32_t HidumpHelper::GetArgsType(const std::vector& args, std::vector &Flag) +int32_t HiDumpHelper::GetArgsType(const std::vector& args, std::vector &Flag) { - LOGI("HidumpHelper::GetArgsType"); + LOGI("HiDumpHelper::GetArgsType"); int32_t ret = ERR_DM_FAILED; if (args.empty()) { Flag.push_back(HidumperFlag::HIDUMPER_GET_HELP); -- Gitee From e840794c8c92ca60f061e3742a3a699714579786 Mon Sep 17 00:00:00 2001 From: wangyb0625 Date: Thu, 30 Jun 2022 10:46:46 +0800 Subject: [PATCH 4/4] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E6=A3=80=E8=A7=86?= =?UTF-8?q?=E6=84=8F=E8=A7=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: wangyb0625 --- .../include/softbus/softbus_listener.h | 1 - .../service/src/device_manager_service.cpp | 5 +-- .../service/src/softbus/softbus_listener.cpp | 38 ------------------- utils/include/dfx/lite/dm_hidumper.h | 2 +- utils/include/dfx/standard/dm_hidumper.h | 3 +- utils/src/dfx/lite/dm_hidumper.cpp | 2 +- utils/src/dfx/standard/dm_hidumper.cpp | 21 ++++------ 7 files changed, 13 insertions(+), 59 deletions(-) diff --git a/services/service/include/softbus/softbus_listener.h b/services/service/include/softbus/softbus_listener.h index ce0391525..526a69173 100644 --- a/services/service/include/softbus/softbus_listener.h +++ b/services/service/include/softbus/softbus_listener.h @@ -101,7 +101,6 @@ public: ~SoftbusListener(); int32_t GetTrustedDeviceList(std::vector &deviceInfoList); int32_t GetLocalDeviceInfo(DmDeviceInfo &deviceInfo); - bool IsDeviceOnline(const std::string &deviceId); private: int32_t Init(); diff --git a/services/service/src/device_manager_service.cpp b/services/service/src/device_manager_service.cpp index 7c1de2c6c..8a9a802fd 100644 --- a/services/service/src/device_manager_service.cpp +++ b/services/service/src/device_manager_service.cpp @@ -286,10 +286,9 @@ int32_t DeviceManagerService::DmHiDumper(const std::vector& args, s LOGE("HiDumpHelper GetTrustedDeviceList failed"); return ERR_DM_FAILED; } - bool deviceState = false; + for (unsigned int j = 0; j < deviceList.size(); j++) { - deviceState = softbusListener_->IsDeviceOnline(deviceList[j].deviceId); - HiDumpHelper::GetInstance().SetNodeInfo(deviceList[j], deviceState); + HiDumpHelper::GetInstance().SetNodeInfo(deviceList[j]); LOGI("DeviceManagerService::DmHiDumper SetNodeInfo."); } } diff --git a/services/service/src/softbus/softbus_listener.cpp b/services/service/src/softbus/softbus_listener.cpp index ea141118f..e4b5c5e1c 100644 --- a/services/service/src/softbus/softbus_listener.cpp +++ b/services/service/src/softbus/softbus_listener.cpp @@ -175,44 +175,6 @@ int32_t SoftbusListener::GetTrustedDeviceList(std::vector &deviceI return DM_OK; } -bool SoftbusListener::IsDeviceOnline(const std::string &deviceId) -{ - NodeBasicInfo *info = nullptr; - int32_t infoNum = 0; - if (GetAllNodeDeviceInfo(DM_PKG_NAME.c_str(), &info, &infoNum) != DM_OK) { - LOGE("GetAllNodeDeviceInfo failed"); - return false; - } - bool bDeviceOnline = false; - for (int32_t i = 0; i < infoNum; ++i) { - NodeBasicInfo *nodeBasicInfo = info + i; - if (nodeBasicInfo == nullptr) { - LOGE("nodeBasicInfo is empty for index %d, infoNum %d.", i, infoNum); - continue; - } - std::string networkId = nodeBasicInfo->networkId; - if (networkId == deviceId) { - LOGI("DM_IsDeviceOnLine device %s online", GetAnonyString(deviceId).c_str()); - bDeviceOnline = true; - break; - } - uint8_t udid[UDID_BUF_LEN] = {0}; - int32_t ret = GetNodeKeyInfo(DM_PKG_NAME.c_str(), networkId.c_str(), NodeDeviceInfoKey::NODE_KEY_UDID, udid, - sizeof(udid)); - if (ret != DM_OK) { - LOGE("DM_IsDeviceOnLine GetNodeKeyInfo failed"); - break; - } - if (strcmp((char *)udid, deviceId.c_str()) == 0) { - LOGI("DM_IsDeviceOnLine device %s online", GetAnonyString(deviceId).c_str()); - bDeviceOnline = true; - break; - } - } - FreeNodeInfo(info); - return bDeviceOnline; -} - int32_t SoftbusListener::GetLocalDeviceInfo(DmDeviceInfo &deviceInfo) { LOGI("SoftbusListener::GetLocalDeviceInfo start"); diff --git a/utils/include/dfx/lite/dm_hidumper.h b/utils/include/dfx/lite/dm_hidumper.h index 298d61548..559af3358 100644 --- a/utils/include/dfx/lite/dm_hidumper.h +++ b/utils/include/dfx/lite/dm_hidumper.h @@ -35,7 +35,7 @@ class HiDumpHelper { public: int32_t HiDump(const std::vector& args, std::string &result); int32_t GetArgsType(const std::vector& args, std::vector &Flag); - void SetNodeInfo(const DmDeviceInfo& deviceInfo, const bool deviceStates); + void SetNodeInfo(const DmDeviceInfo& deviceInfo); }; } // namespace DistributedHardware } // namespace OHOS diff --git a/utils/include/dfx/standard/dm_hidumper.h b/utils/include/dfx/standard/dm_hidumper.h index dc1bf5b4c..cf866ef8b 100644 --- a/utils/include/dfx/standard/dm_hidumper.h +++ b/utils/include/dfx/standard/dm_hidumper.h @@ -34,7 +34,7 @@ DECLARE_SINGLE_INSTANCE(HiDumpHelper); public: int32_t HiDump(const std::vector& args, std::string &result); int32_t GetArgsType(const std::vector& args, std::vector &Flag); - void SetNodeInfo(const DmDeviceInfo& deviceInfo, const bool deviceStates); + void SetNodeInfo(const DmDeviceInfo& deviceInfo); private: int32_t ProcessDump(const HidumperFlag &flag, std::string &result); @@ -44,7 +44,6 @@ private: private: std::vector nodeInfos_; - std::vector deviceState_; }; } // namespace DistributedHardware } // namespace OHOS diff --git a/utils/src/dfx/lite/dm_hidumper.cpp b/utils/src/dfx/lite/dm_hidumper.cpp index ca6ab9920..b6aff1c8f 100644 --- a/utils/src/dfx/lite/dm_hidumper.cpp +++ b/utils/src/dfx/lite/dm_hidumper.cpp @@ -28,7 +28,7 @@ int32_t HiDumpHelper::GetArgsType(const std::vector& args, std::vec return DM_OK; } -void HiDumpHelper::SetNodeInfo(const DmDeviceInfo& deviceInfo, const bool deviceStates) +void HiDumpHelper::SetNodeInfo(const DmDeviceInfo& deviceInfo) { return; } diff --git a/utils/src/dfx/standard/dm_hidumper.cpp b/utils/src/dfx/standard/dm_hidumper.cpp index fc72bef19..78b989e19 100644 --- a/utils/src/dfx/standard/dm_hidumper.cpp +++ b/utils/src/dfx/standard/dm_hidumper.cpp @@ -41,15 +41,10 @@ int32_t HiDumpHelper::HiDump(const std::vector& args, std::string & return errCode; } -void HiDumpHelper::SetNodeInfo(const DmDeviceInfo& deviceInfo, const bool deviceStates) +void HiDumpHelper::SetNodeInfo(const DmDeviceInfo& deviceInfo) { LOGI("HiDumpHelper::SetNodeInfo"); nodeInfos_.push_back(deviceInfo); - std::string deviceState = "offline"; - if (deviceStates) { - deviceState = "online"; - } - deviceState_.push_back(deviceState); } int32_t HiDumpHelper::ProcessDump(const HidumperFlag &flag, std::string &result) @@ -75,18 +70,18 @@ int32_t HiDumpHelper::ProcessDump(const HidumperFlag &flag, std::string &result) int32_t HiDumpHelper::ShowAllLoadTrustedList(std::string &result) { - LOGI("Dump Show All Load Trust List"); + LOGI("dump all trusted device List"); int32_t ret = DM_OK; if (nodeInfos_.size() == 0) { - LOGE("Hidumper get trusted list is empty"); - result.append("Hidumper get trusted list is empty"); + LOGE("dump trusted device list is empty"); + result.append("dump trusted device list is empty"); } for (unsigned int i = 0; i < nodeInfos_.size(); ++i) { result.append("\n{\n deviceId : ").append(GetAnonyString(nodeInfos_[i].deviceId).c_str()); result.append("\n{\n deviceName : ").append(nodeInfos_[i].deviceName); result.append("\n{\n networkId : ").append(GetAnonyString(nodeInfos_[i].networkId).c_str()); - result.append("\n{\n deviceState : ").append(deviceState_[i]); + result.append("\n{\n deviceTypeId : ").append(std::to_string(nodeInfos_[i].deviceTypeId)); } nodeInfos_.clear(); @@ -99,9 +94,9 @@ int32_t HiDumpHelper::ShowHelp(std::string &result) LOGI("Show hidumper help"); result.append("DistributedHardwareDeviceManager hidumper options:\n"); result.append(" -help "); - result.append(": Show help\n"); + result.append(": show help\n"); result.append(" -getTrustlist "); - result.append(": Show all get trusted list:\n\n"); + result.append(": show all get trusted list:\n\n"); LOGI("result is %s", result.c_str()); return DM_OK; } @@ -110,7 +105,7 @@ int32_t HiDumpHelper::ShowIllealInfomation(std::string &result) { LOGI("ShowIllealInfomation Dump"); result.clear(); - result.append("Unrecognized option, -h for help."); + result.append("unrecognized option, -h for help."); return DM_OK; } -- Gitee