0628添加dumper

Signed-off-by: wangyb0625 <wangyibo38@huawei.com>
This commit is contained in:
wangyb0625
2022-06-28 23:29:59 +08:00
parent 3ada6c3346
commit a9bf27a2df
10 changed files with 334 additions and 0 deletions
@@ -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<std::string>& args, std::string &result);
private:
bool isImplsoLoaded_ = false;
std::shared_ptr<SoftbusListener> softbusListener_;
@@ -113,6 +113,13 @@ public:
*/
const sptr<IpcRemoteBroker> 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<std::u16string>& args) override;
private:
IpcServerStub();
~IpcServerStub() = default;
@@ -269,5 +269,23 @@ bool DeviceManagerService::IsDMServiceImplReady()
isImplsoLoaded_ = true;
return true;
}
int32_t DeviceManagerService::DmHiDumper(const std::vector<std::string>& args, std::string &result)
{
std::vector<HidumperFlag> 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<DmDeviceInfo> 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
@@ -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<IpcRemoteBroker> IpcServerStub::GetDmListener(std::string pkgName) co
return dmListener;
}
int32_t IpcServerStub::Dump(int32_t fd, const std::vector<std::u16string>& args)
{
LOGI("DistributedHardwareService Dump.");
std::vector<std::string> 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<IRemoteObject> &remote)
{
LOGW("AppDeathRecipient: OnRemoteDied");
+3
View File
@@ -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",
+17
View File
@@ -16,6 +16,7 @@
#define OHOS_DM_DFX_CONSTANTS_H
#include <string>
#include <unordered_map>
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<std::string, HidumperFlag> 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
+44
View File
@@ -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 <cstdint>
#include <set>
#include <string>
#include <vector>
#include <unordered_map>
#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<std::string>& 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
+49
View File
@@ -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 <cstdint>
#include <set>
#include <string>
#include <vector>
#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<std::string>& args, std::string &result);
void GetArgsType(const std::vector<std::string>& args, std::vector<HidumperFlag> &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<DmDeviceInfo> nodeInfos_;
};
} // namespace DistributedHardware
} // namespace OHOS
#endif // OHOS_DM_HIDUMPER_H
+46
View File
@@ -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<std::string>& 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
+126
View File
@@ -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 <string>
#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<std::string>& 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<std::string>& args, std::vector<HidumperFlag> &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