From 68014ab1f13e4abcae2ad66e70e26b52c8d2a620 Mon Sep 17 00:00:00 2001 From: gaoqiang_strong Date: Mon, 18 Apr 2022 17:07:36 +0800 Subject: [PATCH 01/10] add hidumper Signed-off-by: gaoqiang_strong --- common/include/dscreen_errcode.h | 1 + .../include/dscreen_sink_service.h | 2 + .../include/dscreen_source_service.h | 2 + .../src/dscreen_source_service.cpp | 60 +++++++++++++++++++ 4 files changed, 65 insertions(+) diff --git a/common/include/dscreen_errcode.h b/common/include/dscreen_errcode.h index a6101bbe..7a55bd6a 100644 --- a/common/include/dscreen_errcode.h +++ b/common/include/dscreen_errcode.h @@ -53,6 +53,7 @@ enum DScreenErrorCode { ERR_DH_SCREEN_SA_REGISTER_SCREENLISTENER_FAIL = -500029, ERR_DH_SCREEN_SA_UNREGISTER_SCREENLISTENER_FAIL = -500030, ERR_DH_SCREEN_SA_DSCREEN_NEGOTIATE_CODEC_FAIL = -500031, + ERR_DH_SCREEN_SA_DSCREEN_DUMP_FAIL = -500033, // Transport component error code ERR_DH_SCREEN_TRANS_ERROR = -51000, ERR_DH_SCREEN_TRANS_TIMEOUT = -51001, diff --git a/services/screenservice/sinkservice/dscreenservice/include/dscreen_sink_service.h b/services/screenservice/sinkservice/dscreenservice/include/dscreen_sink_service.h index a314bacb..c19095b2 100644 --- a/services/screenservice/sinkservice/dscreenservice/include/dscreen_sink_service.h +++ b/services/screenservice/sinkservice/dscreenservice/include/dscreen_sink_service.h @@ -15,6 +15,7 @@ #ifndef OHOS_DSCREEN_SINK_SERVICE_H #define OHOS_DSCREEN_SINK_SERVICE_H +#include #include "ipc_object_stub.h" #include "system_ability.h" @@ -35,6 +36,7 @@ public: int32_t SubscribeLocalHardware(const std::string &dhId, const std::string ¶m) override; int32_t UnsubscribeLocalHardware(const std::string &dhId) override; void DScreenNotify(const std::string &devId, int32_t eventCode, const std::string &eventContent) override; + int32_t Dump(int32_t fd, const std::vector& args) override; protected: void OnStart() override; diff --git a/services/screenservice/sourceservice/dscreenservice/include/dscreen_source_service.h b/services/screenservice/sourceservice/dscreenservice/include/dscreen_source_service.h index d66e1859..af829c4d 100644 --- a/services/screenservice/sourceservice/dscreenservice/include/dscreen_source_service.h +++ b/services/screenservice/sourceservice/dscreenservice/include/dscreen_source_service.h @@ -15,6 +15,7 @@ #ifndef OHOS_DSCREEN_SOURCE_SERVICE_H #define OHOS_DSCREEN_SOURCE_SERVICE_H +#include #include "system_ability.h" #include "ipc_object_stub.h" @@ -40,6 +41,7 @@ public: int32_t ConfigDistributedHardware(const std::string &devId, const std::string &dhId, const std::string &key, const std::string &value) override; void DScreenNotify(const std::string &devId, const int32_t eventCode, const std::string &eventContent) override; + int32_t Dump(int32_t fd, const std::vector& args) override; protected: void OnStart() override; diff --git a/services/screenservice/sourceservice/dscreenservice/src/dscreen_source_service.cpp b/services/screenservice/sourceservice/dscreenservice/src/dscreen_source_service.cpp index e1cb0ef3..13b96d3c 100644 --- a/services/screenservice/sourceservice/dscreenservice/src/dscreen_source_service.cpp +++ b/services/screenservice/sourceservice/dscreenservice/src/dscreen_source_service.cpp @@ -139,5 +139,65 @@ void DScreenSourceService::DScreenNotify(const std::string &devId, const int32_t DHLOGI("DScreenNotify, devId: %s, eventCode: %d", GetAnonyString(devId).c_str(), eventCode); DScreenManager::GetInstance().HandleDScreenNotify(devId, eventCode, eventContent); } + +int DScreenSourceService::Dump(int32_t fd, const std::vector& args) override; +{ + DHLOGI("Dump."); + if (fd < 0) { + DHLOGE("fd is invalid."); + return ERR_DH_SCREEN_SA_DSCREEN_DUMP_FAIL; + } + + signal(SIGPIPE, SIG_IGN); // ignore SIGPIPE crash + UniqueFd ufd = OHOS::UniqueFd(fd); // auto close + fd = ufd.Get(); + + int32_t optind = 1; + int32_t argc = args.size() + 1; + char *argv[argc]; + for (int i = 1; i < argc; i++) { + argv[i] = Str16ToStr8(args.at(i - 1).data()); + } + char optStr[] = "-hdneqb"; + int c = 0; + while ((c = getopt(argc, argv, optStr) != -1) { + switch (c) { + case "h": + dprintf(fd, "Usage:\n"); + dprintf(fd, " -h: command help.\n"); + dprintf(fd, " -d: default dump.\n"); + dprintf(fd, " -n: none dump.\n"); + dprintf(fd, " -e: failed dump.\n"); + dprintf(fd, " -q: dump quit after 1s.\n"); + dprintf(fd, " -b: endless dump.\n"); + break; + case "d": + dprintf(fd, " -d: default dump.\n"); + break; + } + } + + std::string arg = (args.size() == 0) ? "" : Str16ToStr8(args.at(0)); + if (arg.compare("-h") == 0) { + dprintf(fd, "Usage:\n"); + dprintf(fd, " -h: command help.\n"); + dprintf(fd, " -d: default dump.\n"); + dprintf(fd, " -n: none dump.\n"); + dprintf(fd, " -e: failed dump.\n"); + dprintf(fd, " -q: dump quit after 1s.\n"); + dprintf(fd, " -b: endless dump.\n"); + } else if (arg.compare("-n") == 0) { + // none + } else if (arg.compare("-e") == 0) { + dprintf(fd, " -e: failed dump.\n"); + return ERR_DH_SCREEN_SA_DSCREEN_DUMP_FAIL; + } else if (arg.compare("-b") == 0) { + // + } else if (arg.compare("-q") == 0) { + // + } + + return DH_SUCCESS; +} } // namespace DistributedHardware } // namespace OHOS \ No newline at end of file -- Gitee From 087b2a18a5edbef6b3a5e2e7bc459802443652a0 Mon Sep 17 00:00:00 2001 From: gaoqiang_strong Date: Tue, 19 Apr 2022 17:52:31 +0800 Subject: [PATCH 02/10] add hidumper file Signed-off-by: gaoqiang_strong --- services/common/utils/include/hidump_helper.h | 75 ++++ services/common/utils/src/hidump_helper.cpp | 379 ++++++++++++++++++ .../include/dscreen_source_service.h | 2 +- .../src/dscreen_source_service.cpp | 28 +- 4 files changed, 481 insertions(+), 3 deletions(-) create mode 100644 services/common/utils/include/hidump_helper.h create mode 100644 services/common/utils/src/hidump_helper.cpp diff --git a/services/common/utils/include/hidump_helper.h b/services/common/utils/include/hidump_helper.h new file mode 100644 index 00000000..50af4c21 --- /dev/null +++ b/services/common/utils/include/hidump_helper.h @@ -0,0 +1,75 @@ +/* + * Copyright (c) 2022-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 FOUNDATION_APPEXECFWK_SERVICES_BUNDLEMGR_INCLUDE_HIDUMPE_HELPER_H +#define FOUNDATION_APPEXECFWK_SERVICES_BUNDLEMGR_INCLUDE_HIDUMPE_HELPER_H + +#include +#include + +#include "bundle_data_mgr.h" + +namespace OHOS { +namespace AppExecFwk { +enum class HidumpFlag { + UNKNOW = 0, + GET_HELP, + GET_ABILITY, + GET_ABILITY_LIST, + GET_ABILITY_BY_NAME, + GET_BUNDLE, + GET_BUNDLE_LIST, + GET_BUNDLE_BY_NAME, + GET_DEVICEID, +}; + +struct HidumpParam { + HidumpFlag hidumpFlag = HidumpFlag::UNKNOW; + std::string args; +}; + +class HidumpHelper { +public: + explicit HidumpHelper(const std::weak_ptr &dataMgr); + ~HidumpHelper() = default; + /** + * @brief Process hidump. + * @param args Indicates the args. + * @param result Indicates the result. + * @return Returns whether the interface is called successfully. + */ + bool Dump(const std::vector& args, std::string &result); + +private: + ErrCode ProcessOneParam(const std::string& args, std::string &result); + ErrCode ProcessTwoParam(const std::string& firstParam, + const std::string& secondParam, std::string &result); + void ShowHelp(std::string &result); + void ShowIllealInfomation(std::string &result); + ErrCode ProcessDump(const HidumpParam& hidumpParam, std::string &result); + + ErrCode GetAllAbilityInfo(std::string &result); + ErrCode GetAllAbilityNameList(std::string &result); + ErrCode GetAbilityInfoByName(const std::string &name, std::string &result); + ErrCode GetAllBundleInfo(std::string &result); + ErrCode GetAllBundleNameList(std::string &result); + ErrCode GetBundleInfoByName(const std::string &name, std::string &result); + ErrCode GetAllDeviced(std::string &result); + + std::weak_ptr dataMgr_; +}; +} // namespace AppExecFwk +} // namespace OHOS +#endif // FOUNDATION_APPEXECFWK_SERVICES_BUNDLEMGR_INCLUDE_HIDUMPE_HELPER_H diff --git a/services/common/utils/src/hidump_helper.cpp b/services/common/utils/src/hidump_helper.cpp new file mode 100644 index 00000000..9ca232c2 --- /dev/null +++ b/services/common/utils/src/hidump_helper.cpp @@ -0,0 +1,379 @@ +/* + * Copyright (c) 2022-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 "dscreen_constants.h" +#include "dscreen_errcode.h" +#include "dscreen_log.h" + +namespace OHOS { +namespace AppExecFwk { +namespace { +const int32_t MIN_ARGS_SIZE = 1; +const int32_t MAX_ARGS_SIZE = 2; +const int32_t FIRST_PARAM = 0; +const int32_t SECOND_PARAM = 1; +const std::string ARGS_HELP = "-h"; + +const std::unordered_map ARGS_MAP = { + { ARGS_HELP, HidumpFlag::GET_HELP }, + // to do +}; +} + +HidumpHelper::HidumpHelper(const std::weak_ptr &dataMgr) + : dataMgr_(dataMgr) {} + +bool HidumpHelper::Dump(const std::vector& args, std::string &result) +{ + result.clear(); + ErrCode errCode = ERR_OK; + int32_t argsSize = static_cast(args.size()); + switch (argsSize) { + case MIN_ARGS_SIZE: { + errCode = ProcessOneParam(args[FIRST_PARAM], result); + break; + } + case MAX_ARGS_SIZE: { + errCode = ProcessTwoParam(args[FIRST_PARAM], args[SECOND_PARAM], result); + break; + } + default: { + errCode = ERR_APPEXECFWK_HIDUMP_INVALID_ARGS; + break; + } + } + + bool ret = false; + switch (errCode) { + case ERR_OK: { + ret = true; + break; + } + case ERR_DH_SCREEN_HIDUMP_INVALID_ARGS: { + ShowIllealInfomation(result); + ret = true; + break; + } + case ERR_DH_SCREEN_HIDUMP_UNKONW: { + result.append(NO_INFOMATION); + ret = true; + break; + } + case ERR_DH_SCREEN_HIDUMP_SERVICE_ERROR: { + ret = false; + break; + } + default: { + break; + } + } + + return ret; +} + +ErrCode HidumpHelper::ProcessOneParam(const std::string& args, std::string &result) +{ + HidumpParam hidumpParam; + auto operatorIter = ARGS_MAP.find(args); + if (operatorIter != ARGS_MAP.end()) { + hidumpParam.hidumpFlag = operatorIter->second; + } + + if (hidumpParam.hidumpFlag == HidumpFlag::GET_HELP) { + ShowHelp(result); + return ERR_OK; + } + + return ProcessDump(hidumpParam, result); +} + +ErrCode HidumpHelper::ProcessTwoParam( + const std::string& firstParam, const std::string& secondParam, std::string &result) +{ + HidumpParam hidumpParam; + hidumpParam.args = secondParam; + auto operatorIter = ARGS_MAP.find(firstParam); + if (operatorIter != ARGS_MAP.end()) { + hidumpParam.hidumpFlag = operatorIter->second; + } + + switch (hidumpParam.hidumpFlag) { + case HidumpFlag::GET_ABILITY: { + hidumpParam.hidumpFlag = HidumpFlag::GET_ABILITY_BY_NAME; + break; + } + case HidumpFlag::GET_BUNDLE: { + hidumpParam.hidumpFlag = HidumpFlag::GET_BUNDLE_BY_NAME; + break; + } + default: { + break; + } + } + + return ProcessDump(hidumpParam, result); +} + +ErrCode HidumpHelper::ProcessDump(const HidumpParam& hidumpParam, std::string &result) +{ + result.clear(); + ErrCode errCode = ERR_APPEXECFWK_HIDUMP_ERROR; + switch (hidumpParam.hidumpFlag) { + case HidumpFlag::GET_ABILITY: { + errCode = GetAllAbilityInfo(result); + break; + } + case HidumpFlag::GET_ABILITY_LIST: { + errCode = GetAllAbilityNameList(result); + break; + } + case HidumpFlag::GET_ABILITY_BY_NAME: { + errCode = GetAbilityInfoByName(hidumpParam.args, result); + break; + } + case HidumpFlag::GET_BUNDLE: { + errCode = GetAllBundleInfo(result); + break; + } + case HidumpFlag::GET_BUNDLE_LIST: { + errCode = GetAllBundleNameList(result); + break; + } + case HidumpFlag::GET_BUNDLE_BY_NAME: { + errCode = GetBundleInfoByName(hidumpParam.args, result); + break; + } + case HidumpFlag::GET_DEVICEID: { + errCode = GetAllDeviced(result); + break; + } + default: { + errCode = ERR_APPEXECFWK_HIDUMP_INVALID_ARGS; + break; + } + } + + return errCode; +} + +ErrCode HidumpHelper::GetAllAbilityInfo(std::string &result) +{ + auto shareDataMgr = dataMgr_.lock(); + if (!shareDataMgr) { + return ERR_APPEXECFWK_HIDUMP_SERVICE_ERROR; + } + + std::vector bundleInfos; + if (!shareDataMgr->GetBundleInfos(static_cast( + BundleFlag::GET_BUNDLE_WITH_ABILITIES | BundleFlag::GET_BUNDLE_WITH_EXTENSION_INFO), + bundleInfos, Constants::ANY_USERID)) { + APP_LOGE("get bundleInfos failed."); + return ERR_APPEXECFWK_HIDUMP_ERROR; + } + + for (auto &bundleInfo : bundleInfos) { + for (auto &abilityInfo : bundleInfo.abilityInfos) { + result.append(abilityInfo.name); + result.append(":\n"); + nlohmann::json jsonObject = abilityInfo; + result.append(jsonObject.dump(Constants::DUMP_INDENT)); + result.append("\n"); + } + } + + APP_LOGD("get all ability info success"); + return ERR_OK; +} + +ErrCode HidumpHelper::GetAllAbilityNameList(std::string &result) +{ + auto shareDataMgr = dataMgr_.lock(); + if (!shareDataMgr) { + return ERR_APPEXECFWK_HIDUMP_SERVICE_ERROR; + } + + std::vector bundleInfos; + if (!shareDataMgr->GetBundleInfos(static_cast( + BundleFlag::GET_BUNDLE_WITH_ABILITIES | BundleFlag::GET_BUNDLE_WITH_EXTENSION_INFO), + bundleInfos, Constants::ANY_USERID)) { + APP_LOGE("get bundleInfos failed."); + return ERR_APPEXECFWK_HIDUMP_ERROR; + } + + for (auto &bundleInfo : bundleInfos) { + for (auto abilityInfo : bundleInfo.abilityInfos) { + result.append(abilityInfo.name); + result.append("\n"); + } + } + + APP_LOGD("get all ability list info success"); + return ERR_OK; +} + +ErrCode HidumpHelper::GetAbilityInfoByName(const std::string &name, std::string &result) +{ + auto shareDataMgr = dataMgr_.lock(); + if (!shareDataMgr) { + return ERR_APPEXECFWK_HIDUMP_SERVICE_ERROR; + } + + std::vector bundleInfos; + if (!shareDataMgr->GetBundleInfos(static_cast( + BundleFlag::GET_BUNDLE_WITH_ABILITIES | BundleFlag::GET_BUNDLE_WITH_EXTENSION_INFO), + bundleInfos, Constants::ANY_USERID)) { + APP_LOGE("get bundleInfos failed."); + return ERR_APPEXECFWK_HIDUMP_ERROR; + } + + for (auto &bundleInfo : bundleInfos) { + for (auto abilityInfo : bundleInfo.abilityInfos) { + if (abilityInfo.name == name) { + result.append(abilityInfo.name); + result.append(":\n"); + nlohmann::json jsonObject = abilityInfo; + result.append(jsonObject.dump(Constants::DUMP_INDENT)); + result.append("\n"); + return ERR_OK; + } + } + } + + return ERR_APPEXECFWK_HIDUMP_ERROR; +} + +ErrCode HidumpHelper::GetAllBundleInfo(std::string &result) +{ + auto shareDataMgr = dataMgr_.lock(); + if (!shareDataMgr) { + return ERR_APPEXECFWK_HIDUMP_SERVICE_ERROR; + } + + std::vector bundleInfos; + if (!shareDataMgr->GetBundleInfos(static_cast( + BundleFlag::GET_BUNDLE_WITH_ABILITIES | BundleFlag::GET_BUNDLE_WITH_EXTENSION_INFO), + bundleInfos, Constants::ANY_USERID)) { + APP_LOGE("get bundleInfos failed."); + return false; + } + + for (auto &info : bundleInfos) { + result.append(info.name); + result.append(":\n"); + nlohmann::json jsonObject = info; + jsonObject["hapModuleInfos"] = info.hapModuleInfos; + result.append(jsonObject.dump(Constants::DUMP_INDENT)); + result.append("\n"); + } + APP_LOGD("get all bundle info success"); + return ERR_OK; +} + +ErrCode HidumpHelper::GetAllBundleNameList(std::string &result) +{ + auto shareDataMgr = dataMgr_.lock(); + if (!shareDataMgr) { + return ERR_APPEXECFWK_HIDUMP_SERVICE_ERROR; + } + + std::vector bundleNames; + if (!shareDataMgr->GetBundleList(bundleNames, Constants::ANY_USERID)) { + APP_LOGE("get bundle list failed"); + return ERR_APPEXECFWK_HIDUMP_ERROR; + } + + for (auto &name : bundleNames) { + result.append(name); + result.append("\n"); + } + + return ERR_OK; +} + +ErrCode HidumpHelper::GetBundleInfoByName(const std::string &name, std::string &result) +{ + APP_LOGD("hidump bundle info begin"); + auto shareDataMgr = dataMgr_.lock(); + if (!shareDataMgr) { + return ERR_APPEXECFWK_HIDUMP_SERVICE_ERROR; + } + + BundleInfo bundleInfo; + if (!shareDataMgr->GetBundleInfo(name, + BundleFlag::GET_BUNDLE_WITH_ABILITIES | BundleFlag::GET_BUNDLE_WITH_REQUESTED_PERMISSION | + BundleFlag::GET_BUNDLE_WITH_EXTENSION_INFO, bundleInfo, Constants::ANY_USERID)) { + APP_LOGE("get bundleInfo(%{public}s) failed", name.c_str()); + return ERR_APPEXECFWK_HIDUMP_ERROR; + } + + result.append(name); + result.append(":\n"); + nlohmann::json jsonObject = bundleInfo; + jsonObject["hapModuleInfos"] = bundleInfo.hapModuleInfos; + result.append(jsonObject.dump(Constants::DUMP_INDENT)); + result.append("\n"); + APP_LOGD("get %{public}s bundle info success", name.c_str()); + return ERR_OK; +} + +ErrCode HidumpHelper::GetAllDeviced(std::string &result) +{ + auto shareDataMgr = dataMgr_.lock(); + if (!shareDataMgr) { + return ERR_APPEXECFWK_HIDUMP_SERVICE_ERROR; + } + + std::vector deviceIds; + if (!shareDataMgr->QueryAllDeviceIds(deviceIds)) { + APP_LOGE("get all deviceId failed"); + return ERR_APPEXECFWK_HIDUMP_ERROR; + } + + for (auto deviceId : deviceIds) { + result.append(deviceId); + result.append("\n"); + } + + return ERR_OK; +} + +void HidumpHelper::ShowHelp(std::string &result) +{ + result.append("Usage:dump [options]\n") + .append("Description:\n") + .append("-ability ") + .append("dump all ability infomation in the system\n") + .append("-ability [abilityName]\n") + .append(" dump ability list information of the specified name in the system\n") + .append("-ability-list ") + .append("dump list of all ability names in the system\n") + .append("-bundle ") + .append("dump all bundle infomation in the system\n") + .append("-bundle [bundleName]\n") + .append(" dump bundle list information of the specified name in the system\n") + .append("-bundle-list ") + .append("dump list of all bundle names in the system\n") + .append("-device ") + .append("dump the list of devices involved in the ability infomation in the system\n"); +} + +void HidumpHelper::ShowIllealInfomation(std::string &result) +{ + result.append(ILLEGAL_INFOMATION); +} +} // namespace AppExecFwk +} // namespace OHOS diff --git a/services/screenservice/sourceservice/dscreenservice/include/dscreen_source_service.h b/services/screenservice/sourceservice/dscreenservice/include/dscreen_source_service.h index af829c4d..40d18094 100644 --- a/services/screenservice/sourceservice/dscreenservice/include/dscreen_source_service.h +++ b/services/screenservice/sourceservice/dscreenservice/include/dscreen_source_service.h @@ -41,7 +41,7 @@ public: int32_t ConfigDistributedHardware(const std::string &devId, const std::string &dhId, const std::string &key, const std::string &value) override; void DScreenNotify(const std::string &devId, const int32_t eventCode, const std::string &eventContent) override; - int32_t Dump(int32_t fd, const std::vector& args) override; + int Dump(int32_t fd, const std::vector& args) override; protected: void OnStart() override; diff --git a/services/screenservice/sourceservice/dscreenservice/src/dscreen_source_service.cpp b/services/screenservice/sourceservice/dscreenservice/src/dscreen_source_service.cpp index 13b96d3c..543120dd 100644 --- a/services/screenservice/sourceservice/dscreenservice/src/dscreen_source_service.cpp +++ b/services/screenservice/sourceservice/dscreenservice/src/dscreen_source_service.cpp @@ -140,7 +140,29 @@ void DScreenSourceService::DScreenNotify(const std::string &devId, const int32_t DScreenManager::GetInstance().HandleDScreenNotify(devId, eventCode, eventContent); } -int DScreenSourceService::Dump(int32_t fd, const std::vector& args) override; +int DScreenSourceService::Dump(int32_t fd, const std::vector& args) +{ + DHLOGI("Dump."); + std::string result; + std::vector argsStr; + for (auto item : args) { + argsStr.emplace_back(Str16ToStr8(item)); + } + + if (dump(argsStr, result)) { + DHLOGE("Hidump error"); + return ERR_APPEXECFWK_HIDUMP_ERROR; + } + + int ret = dprintf(fd, "%s\n", result.c_str()); + if (ret < 0) { + DHLOGE("dprintf error"); + return ERR_APPEXECFWK_HIDUMP_ERROR; + } + + return ERR_OK; +} +/*int DScreenSourceService::Dump(int32_t fd, const std::vector& args) { DHLOGI("Dump."); if (fd < 0) { @@ -198,6 +220,8 @@ int DScreenSourceService::Dump(int32_t fd, const std::vector& ar } return DH_SUCCESS; -} +}*/ + + } // namespace DistributedHardware } // namespace OHOS \ No newline at end of file -- Gitee From 0634e7e3879ad57f48341714c4dfb1a7372bc9e7 Mon Sep 17 00:00:00 2001 From: gaoqiang_strong Date: Wed, 20 Apr 2022 17:13:51 +0800 Subject: [PATCH 03/10] hidumper Signed-off-by: gaoqiang_strong --- common/include/dscreen_errcode.h | 4 + services/common/utils/include/hidump_helper.h | 36 ++- services/common/utils/src/hidump_helper.cpp | 266 ++++-------------- .../src/dscreen_source_service.cpp | 61 ---- 4 files changed, 79 insertions(+), 288 deletions(-) diff --git a/common/include/dscreen_errcode.h b/common/include/dscreen_errcode.h index 7a55bd6a..8eb35085 100644 --- a/common/include/dscreen_errcode.h +++ b/common/include/dscreen_errcode.h @@ -90,6 +90,10 @@ enum DScreenErrorCode { ERR_DH_SCREEN_SCREENCLIENT_ADD_WINDOW_ERROR = -54002, ERR_DH_SCREEN_SCREENCLIENT_MOVE_WINDOW_ERROR = -54003, ERR_DH_SCREEN_SCREENCLIENT_HIDE_WINDOW_ERROR = -54004, + //hidumper + ERR_DH_SCREEN_HIDUMP_UNKONW = -55000, + ERR_DH_SCREEN_HIDUMP_ERROR = -55001, + ERR_DH_SCREEN_HIDUMP_INVALID_ARGS = -55002, }; } // namespace DistributedHardware } // namespace OHOS diff --git a/services/common/utils/include/hidump_helper.h b/services/common/utils/include/hidump_helper.h index 50af4c21..d7524eb6 100644 --- a/services/common/utils/include/hidump_helper.h +++ b/services/common/utils/include/hidump_helper.h @@ -26,13 +26,12 @@ namespace AppExecFwk { enum class HidumpFlag { UNKNOW = 0, GET_HELP, - GET_ABILITY, - GET_ABILITY_LIST, - GET_ABILITY_BY_NAME, - GET_BUNDLE, - GET_BUNDLE_LIST, - GET_BUNDLE_BY_NAME, - GET_DEVICEID, + GET_ENABLE_INFO, + GET_SCREEN_INFO, + GET_SESSION_INFO, + GET_ENCODER_INFO, + GET_DECODER_INFO, + GET_DISABLE_INFO, }; struct HidumpParam { @@ -42,7 +41,7 @@ struct HidumpParam { class HidumpHelper { public: - explicit HidumpHelper(const std::weak_ptr &dataMgr); + explicit HidumpHelper(); ~HidumpHelper() = default; /** * @brief Process hidump. @@ -53,22 +52,19 @@ public: bool Dump(const std::vector& args, std::string &result); private: - ErrCode ProcessOneParam(const std::string& args, std::string &result); - ErrCode ProcessTwoParam(const std::string& firstParam, + int32_t ProcessOneParam(const std::string& args, std::string &result); + int32_t ProcessTwoParam(const std::string& firstParam, const std::string& secondParam, std::string &result); void ShowHelp(std::string &result); void ShowIllealInfomation(std::string &result); - ErrCode ProcessDump(const HidumpParam& hidumpParam, std::string &result); + int32_t ProcessDump(const HidumpParam& hidumpParam, std::string &result); - ErrCode GetAllAbilityInfo(std::string &result); - ErrCode GetAllAbilityNameList(std::string &result); - ErrCode GetAbilityInfoByName(const std::string &name, std::string &result); - ErrCode GetAllBundleInfo(std::string &result); - ErrCode GetAllBundleNameList(std::string &result); - ErrCode GetBundleInfoByName(const std::string &name, std::string &result); - ErrCode GetAllDeviced(std::string &result); - - std::weak_ptr dataMgr_; + int32_t GetEnableInfo(std::string &result); + int32_t GetScreenInfo(std::string &result); + int32_t GetSessionInfo(const std::string &name, std::string &result); + int32_t GetEncoderInfo(std::string &result); + int32_t GetDecoderInfo(std::string &result); + int32_t GetDisableInfo(const std::string &name, std::string &result); }; } // namespace AppExecFwk } // namespace OHOS diff --git a/services/common/utils/src/hidump_helper.cpp b/services/common/utils/src/hidump_helper.cpp index 9ca232c2..50d78ded 100644 --- a/services/common/utils/src/hidump_helper.cpp +++ b/services/common/utils/src/hidump_helper.cpp @@ -20,27 +20,35 @@ #include "dscreen_log.h" namespace OHOS { -namespace AppExecFwk { +namespace DistributedHardware { namespace { const int32_t MIN_ARGS_SIZE = 1; const int32_t MAX_ARGS_SIZE = 2; const int32_t FIRST_PARAM = 0; const int32_t SECOND_PARAM = 1; const std::string ARGS_HELP = "-h"; +const std::string ARGS_ENABLE_INFO = "-enableInfo"; +const std::string ARGS_SCREEN_INFO = "-screenInfo"; +const std::string ARGS_SESSION_INFO = "-sessionInfo"; +const std::string ARGS_ENCODER_INFO = "-encoderInfo"; +const std::string ARGS_DECODER_INFO = "-decoderInfo"; +const std::string ARGS_DISABLE_INFO = "-disableInfo"; const std::unordered_map ARGS_MAP = { { ARGS_HELP, HidumpFlag::GET_HELP }, - // to do + { ARGS_ENABLE_INFO, HidumpFlag::GET_ENABLE_INFO }, + { ARGS_SCREEN_INFO, HidumpFlag::GET_SCREEN_INFO }, + { ARGS_SESSION_INFO, HidumpFlag::GET_SESSION_INFO }, + { ARGS_ENCODER_INFO, HidumpFlag::GET_ENCODER_INFO }, + { ARGS_DECODER_INFO, HidumpFlag::GET_DECODER_INFO }, + { ARGS_DISABLE_INFO, HidumpFlag::GET_DISABLE_INFO }, }; } -HidumpHelper::HidumpHelper(const std::weak_ptr &dataMgr) - : dataMgr_(dataMgr) {} - bool HidumpHelper::Dump(const std::vector& args, std::string &result) { result.clear(); - ErrCode errCode = ERR_OK; + int32_t errCode = DH_SUCCESS; int32_t argsSize = static_cast(args.size()); switch (argsSize) { case MIN_ARGS_SIZE: { @@ -52,14 +60,14 @@ bool HidumpHelper::Dump(const std::vector& args, std::string &resul break; } default: { - errCode = ERR_APPEXECFWK_HIDUMP_INVALID_ARGS; + errCode = ERR_DH_SCREEN_HIDUMP_INVALID_ARGS; break; } } bool ret = false; switch (errCode) { - case ERR_OK: { + case DH_SUCCESS: { ret = true; break; } @@ -73,7 +81,7 @@ bool HidumpHelper::Dump(const std::vector& args, std::string &resul ret = true; break; } - case ERR_DH_SCREEN_HIDUMP_SERVICE_ERROR: { + case ERR_DH_SCREEN_HIDUMP_ERROR: { ret = false; break; } @@ -81,11 +89,10 @@ bool HidumpHelper::Dump(const std::vector& args, std::string &resul break; } } - return ret; } -ErrCode HidumpHelper::ProcessOneParam(const std::string& args, std::string &result) +int32_t HidumpHelper::ProcessOneParam(const std::string& args, std::string &result) { HidumpParam hidumpParam; auto operatorIter = ARGS_MAP.find(args); @@ -95,13 +102,13 @@ ErrCode HidumpHelper::ProcessOneParam(const std::string& args, std::string &resu if (hidumpParam.hidumpFlag == HidumpFlag::GET_HELP) { ShowHelp(result); - return ERR_OK; + return DH_SUCCESS; } return ProcessDump(hidumpParam, result); } -ErrCode HidumpHelper::ProcessTwoParam( +int32_t HidumpHelper::ProcessTwoParam( const std::string& firstParam, const std::string& secondParam, std::string &result) { HidumpParam hidumpParam; @@ -128,41 +135,37 @@ ErrCode HidumpHelper::ProcessTwoParam( return ProcessDump(hidumpParam, result); } -ErrCode HidumpHelper::ProcessDump(const HidumpParam& hidumpParam, std::string &result) +int32_t HidumpHelper::ProcessDump(const HidumpParam& hidumpParam, std::string &result) { result.clear(); - ErrCode errCode = ERR_APPEXECFWK_HIDUMP_ERROR; + int32_t errCode = ERR_DH_SCREEN_HIDUMP_ERROR; switch (hidumpParam.hidumpFlag) { - case HidumpFlag::GET_ABILITY: { - errCode = GetAllAbilityInfo(result); + case HidumpFlag::GET_ENABLE_INFO: { + errCode = GetEnableInfo(result); break; } - case HidumpFlag::GET_ABILITY_LIST: { - errCode = GetAllAbilityNameList(result); + case HidumpFlag::GET_SCREEN_INFO: { + errCode = GetScreenInfo(result); break; } - case HidumpFlag::GET_ABILITY_BY_NAME: { - errCode = GetAbilityInfoByName(hidumpParam.args, result); + case HidumpFlag::GET_SESSION_INFO: { + errCode = GetSessionInfo(hidumpParam.args, result); break; } - case HidumpFlag::GET_BUNDLE: { - errCode = GetAllBundleInfo(result); + case HidumpFlag::GET_ENCODER_INFO: { + errCode = GetEncoderInfo(result); break; } - case HidumpFlag::GET_BUNDLE_LIST: { - errCode = GetAllBundleNameList(result); + case HidumpFlag::GET_DECODER_INFO: { + errCode = GetDecoderInfo(result); break; } - case HidumpFlag::GET_BUNDLE_BY_NAME: { - errCode = GetBundleInfoByName(hidumpParam.args, result); - break; - } - case HidumpFlag::GET_DEVICEID: { - errCode = GetAllDeviced(result); + case HidumpFlag::GET_DISABLE_INFO: { + errCode = GetDisableInfo(hidumpParam.args, result); break; } default: { - errCode = ERR_APPEXECFWK_HIDUMP_INVALID_ARGS; + errCode = ERR_DH_SCREEN_HIDUMP_INVALID_ARGS; break; } } @@ -170,205 +173,54 @@ ErrCode HidumpHelper::ProcessDump(const HidumpParam& hidumpParam, std::string &r return errCode; } -ErrCode HidumpHelper::GetAllAbilityInfo(std::string &result) +int32_t HidumpHelper::GetEnableInfo(std::string &result) { - auto shareDataMgr = dataMgr_.lock(); - if (!shareDataMgr) { - return ERR_APPEXECFWK_HIDUMP_SERVICE_ERROR; - } - std::vector bundleInfos; - if (!shareDataMgr->GetBundleInfos(static_cast( - BundleFlag::GET_BUNDLE_WITH_ABILITIES | BundleFlag::GET_BUNDLE_WITH_EXTENSION_INFO), - bundleInfos, Constants::ANY_USERID)) { - APP_LOGE("get bundleInfos failed."); - return ERR_APPEXECFWK_HIDUMP_ERROR; - } - - for (auto &bundleInfo : bundleInfos) { - for (auto &abilityInfo : bundleInfo.abilityInfos) { - result.append(abilityInfo.name); - result.append(":\n"); - nlohmann::json jsonObject = abilityInfo; - result.append(jsonObject.dump(Constants::DUMP_INDENT)); - result.append("\n"); - } - } - - APP_LOGD("get all ability info success"); - return ERR_OK; + return DH_SUCCESS; } -ErrCode HidumpHelper::GetAllAbilityNameList(std::string &result) +int32_t HidumpHelper::GetScreenInfo(std::string &result) { - auto shareDataMgr = dataMgr_.lock(); - if (!shareDataMgr) { - return ERR_APPEXECFWK_HIDUMP_SERVICE_ERROR; - } - std::vector bundleInfos; - if (!shareDataMgr->GetBundleInfos(static_cast( - BundleFlag::GET_BUNDLE_WITH_ABILITIES | BundleFlag::GET_BUNDLE_WITH_EXTENSION_INFO), - bundleInfos, Constants::ANY_USERID)) { - APP_LOGE("get bundleInfos failed."); - return ERR_APPEXECFWK_HIDUMP_ERROR; - } - - for (auto &bundleInfo : bundleInfos) { - for (auto abilityInfo : bundleInfo.abilityInfos) { - result.append(abilityInfo.name); - result.append("\n"); - } - } - - APP_LOGD("get all ability list info success"); - return ERR_OK; + return DH_SUCCESS; } -ErrCode HidumpHelper::GetAbilityInfoByName(const std::string &name, std::string &result) +int32_t HidumpHelper::GetSessionInfo(const std::string &name, std::string &result) { - auto shareDataMgr = dataMgr_.lock(); - if (!shareDataMgr) { - return ERR_APPEXECFWK_HIDUMP_SERVICE_ERROR; - } - - std::vector bundleInfos; - if (!shareDataMgr->GetBundleInfos(static_cast( - BundleFlag::GET_BUNDLE_WITH_ABILITIES | BundleFlag::GET_BUNDLE_WITH_EXTENSION_INFO), - bundleInfos, Constants::ANY_USERID)) { - APP_LOGE("get bundleInfos failed."); - return ERR_APPEXECFWK_HIDUMP_ERROR; - } - - for (auto &bundleInfo : bundleInfos) { - for (auto abilityInfo : bundleInfo.abilityInfos) { - if (abilityInfo.name == name) { - result.append(abilityInfo.name); - result.append(":\n"); - nlohmann::json jsonObject = abilityInfo; - result.append(jsonObject.dump(Constants::DUMP_INDENT)); - result.append("\n"); - return ERR_OK; - } - } - } - - return ERR_APPEXECFWK_HIDUMP_ERROR; + return ERR_DH_SCREEN_HIDUMP_ERROR; } -ErrCode HidumpHelper::GetAllBundleInfo(std::string &result) +int32_t HidumpHelper::GetEncoderInfo(std::string &result) { - auto shareDataMgr = dataMgr_.lock(); - if (!shareDataMgr) { - return ERR_APPEXECFWK_HIDUMP_SERVICE_ERROR; - } - - std::vector bundleInfos; - if (!shareDataMgr->GetBundleInfos(static_cast( - BundleFlag::GET_BUNDLE_WITH_ABILITIES | BundleFlag::GET_BUNDLE_WITH_EXTENSION_INFO), - bundleInfos, Constants::ANY_USERID)) { - APP_LOGE("get bundleInfos failed."); - return false; - } - - for (auto &info : bundleInfos) { - result.append(info.name); - result.append(":\n"); - nlohmann::json jsonObject = info; - jsonObject["hapModuleInfos"] = info.hapModuleInfos; - result.append(jsonObject.dump(Constants::DUMP_INDENT)); - result.append("\n"); - } - APP_LOGD("get all bundle info success"); - return ERR_OK; -} - -ErrCode HidumpHelper::GetAllBundleNameList(std::string &result) -{ - auto shareDataMgr = dataMgr_.lock(); - if (!shareDataMgr) { - return ERR_APPEXECFWK_HIDUMP_SERVICE_ERROR; - } - - std::vector bundleNames; - if (!shareDataMgr->GetBundleList(bundleNames, Constants::ANY_USERID)) { - APP_LOGE("get bundle list failed"); - return ERR_APPEXECFWK_HIDUMP_ERROR; - } - - for (auto &name : bundleNames) { - result.append(name); - result.append("\n"); - } - - return ERR_OK; + return DH_SUCCESS; } -ErrCode HidumpHelper::GetBundleInfoByName(const std::string &name, std::string &result) +int32_t HidumpHelper::GetDecoderInfo(std::string &result) { - APP_LOGD("hidump bundle info begin"); - auto shareDataMgr = dataMgr_.lock(); - if (!shareDataMgr) { - return ERR_APPEXECFWK_HIDUMP_SERVICE_ERROR; - } - - BundleInfo bundleInfo; - if (!shareDataMgr->GetBundleInfo(name, - BundleFlag::GET_BUNDLE_WITH_ABILITIES | BundleFlag::GET_BUNDLE_WITH_REQUESTED_PERMISSION | - BundleFlag::GET_BUNDLE_WITH_EXTENSION_INFO, bundleInfo, Constants::ANY_USERID)) { - APP_LOGE("get bundleInfo(%{public}s) failed", name.c_str()); - return ERR_APPEXECFWK_HIDUMP_ERROR; - } - - result.append(name); - result.append(":\n"); - nlohmann::json jsonObject = bundleInfo; - jsonObject["hapModuleInfos"] = bundleInfo.hapModuleInfos; - result.append(jsonObject.dump(Constants::DUMP_INDENT)); - result.append("\n"); - APP_LOGD("get %{public}s bundle info success", name.c_str()); - return ERR_OK; + return DH_SUCCESS; } -ErrCode HidumpHelper::GetAllDeviced(std::string &result) +int32_t HidumpHelper::GetDisableInfo(const std::string &name, std::string &result) { - auto shareDataMgr = dataMgr_.lock(); - if (!shareDataMgr) { - return ERR_APPEXECFWK_HIDUMP_SERVICE_ERROR; - } - - std::vector deviceIds; - if (!shareDataMgr->QueryAllDeviceIds(deviceIds)) { - APP_LOGE("get all deviceId failed"); - return ERR_APPEXECFWK_HIDUMP_ERROR; - } - - for (auto deviceId : deviceIds) { - result.append(deviceId); - result.append("\n"); - } - - return ERR_OK; + return DH_SUCCESS; } void HidumpHelper::ShowHelp(std::string &result) { result.append("Usage:dump [options]\n") .append("Description:\n") - .append("-ability ") - .append("dump all ability infomation in the system\n") - .append("-ability [abilityName]\n") - .append(" dump ability list information of the specified name in the system\n") - .append("-ability-list ") - .append("dump list of all ability names in the system\n") - .append("-bundle ") - .append("dump all bundle infomation in the system\n") - .append("-bundle [bundleName]\n") - .append(" dump bundle list information of the specified name in the system\n") - .append("-bundle-list ") - .append("dump list of all bundle names in the system\n") - .append("-device ") - .append("dump the list of devices involved in the ability infomation in the system\n"); + .append("-enableInfo ") + .append("dump screen enable status information in the system\n") + .append("-screenInfo ") + .append("dump all screen information in the system\n") + .append("-sessionInfo ") + .append("dump all session information in the system\n") + .append("-encoderInfo ") + .append("dump all encoder infomation in the system\n") + .append("-decoderInfo ") + .append("dump all decoder infomation in the system\n") + .append("-disableInfo ") + .append("dump screen disable status information in the system\n"); } void HidumpHelper::ShowIllealInfomation(std::string &result) diff --git a/services/screenservice/sourceservice/dscreenservice/src/dscreen_source_service.cpp b/services/screenservice/sourceservice/dscreenservice/src/dscreen_source_service.cpp index 543120dd..5b69a89a 100644 --- a/services/screenservice/sourceservice/dscreenservice/src/dscreen_source_service.cpp +++ b/services/screenservice/sourceservice/dscreenservice/src/dscreen_source_service.cpp @@ -162,66 +162,5 @@ int DScreenSourceService::Dump(int32_t fd, const std::vector& ar return ERR_OK; } -/*int DScreenSourceService::Dump(int32_t fd, const std::vector& args) -{ - DHLOGI("Dump."); - if (fd < 0) { - DHLOGE("fd is invalid."); - return ERR_DH_SCREEN_SA_DSCREEN_DUMP_FAIL; - } - - signal(SIGPIPE, SIG_IGN); // ignore SIGPIPE crash - UniqueFd ufd = OHOS::UniqueFd(fd); // auto close - fd = ufd.Get(); - - int32_t optind = 1; - int32_t argc = args.size() + 1; - char *argv[argc]; - for (int i = 1; i < argc; i++) { - argv[i] = Str16ToStr8(args.at(i - 1).data()); - } - char optStr[] = "-hdneqb"; - int c = 0; - while ((c = getopt(argc, argv, optStr) != -1) { - switch (c) { - case "h": - dprintf(fd, "Usage:\n"); - dprintf(fd, " -h: command help.\n"); - dprintf(fd, " -d: default dump.\n"); - dprintf(fd, " -n: none dump.\n"); - dprintf(fd, " -e: failed dump.\n"); - dprintf(fd, " -q: dump quit after 1s.\n"); - dprintf(fd, " -b: endless dump.\n"); - break; - case "d": - dprintf(fd, " -d: default dump.\n"); - break; - } - } - - std::string arg = (args.size() == 0) ? "" : Str16ToStr8(args.at(0)); - if (arg.compare("-h") == 0) { - dprintf(fd, "Usage:\n"); - dprintf(fd, " -h: command help.\n"); - dprintf(fd, " -d: default dump.\n"); - dprintf(fd, " -n: none dump.\n"); - dprintf(fd, " -e: failed dump.\n"); - dprintf(fd, " -q: dump quit after 1s.\n"); - dprintf(fd, " -b: endless dump.\n"); - } else if (arg.compare("-n") == 0) { - // none - } else if (arg.compare("-e") == 0) { - dprintf(fd, " -e: failed dump.\n"); - return ERR_DH_SCREEN_SA_DSCREEN_DUMP_FAIL; - } else if (arg.compare("-b") == 0) { - // - } else if (arg.compare("-q") == 0) { - // - } - - return DH_SUCCESS; -}*/ - - } // namespace DistributedHardware } // namespace OHOS \ No newline at end of file -- Gitee From 28a2951fbd94b23a3c5edd8402423f841b289d74 Mon Sep 17 00:00:00 2001 From: gaoqiang_strong Date: Thu, 21 Apr 2022 10:42:30 +0800 Subject: [PATCH 04/10] add dump Signed-off-by: gaoqiang_strong --- services/common/utils/include/hidump_helper.h | 16 ++++------------ services/common/utils/src/hidump_helper.cpp | 19 ++++--------------- services/screenservice/sourceservice/BUILD.gn | 2 ++ .../src/dscreen_source_service.cpp | 3 ++- 4 files changed, 12 insertions(+), 28 deletions(-) diff --git a/services/common/utils/include/hidump_helper.h b/services/common/utils/include/hidump_helper.h index d7524eb6..6ba318e5 100644 --- a/services/common/utils/include/hidump_helper.h +++ b/services/common/utils/include/hidump_helper.h @@ -19,10 +19,8 @@ #include #include -#include "bundle_data_mgr.h" - namespace OHOS { -namespace AppExecFwk { +namespace DistributedHardware { enum class HidumpFlag { UNKNOW = 0, GET_HELP, @@ -40,18 +38,12 @@ struct HidumpParam { }; class HidumpHelper { +DECLARE_SINGLE_INSTANCE_BASE(HidumpHelper); public: - explicit HidumpHelper(); - ~HidumpHelper() = default; - /** - * @brief Process hidump. - * @param args Indicates the args. - * @param result Indicates the result. - * @return Returns whether the interface is called successfully. - */ bool Dump(const std::vector& args, std::string &result); - private: + explicit HidumpHelper() = default; + ~HidumpHelper() = default; int32_t ProcessOneParam(const std::string& args, std::string &result); int32_t ProcessTwoParam(const std::string& firstParam, const std::string& secondParam, std::string &result); diff --git a/services/common/utils/src/hidump_helper.cpp b/services/common/utils/src/hidump_helper.cpp index 50d78ded..aacb4935 100644 --- a/services/common/utils/src/hidump_helper.cpp +++ b/services/common/utils/src/hidump_helper.cpp @@ -15,12 +15,15 @@ #include "hidump_helper.h" +#include "single_instance.h" + #include "dscreen_constants.h" #include "dscreen_errcode.h" #include "dscreen_log.h" namespace OHOS { namespace DistributedHardware { +IMPLEMENT_SINGLE_INSTANCE(HidumpHelper); namespace { const int32_t MIN_ARGS_SIZE = 1; const int32_t MAX_ARGS_SIZE = 2; @@ -118,20 +121,6 @@ int32_t HidumpHelper::ProcessTwoParam( hidumpParam.hidumpFlag = operatorIter->second; } - switch (hidumpParam.hidumpFlag) { - case HidumpFlag::GET_ABILITY: { - hidumpParam.hidumpFlag = HidumpFlag::GET_ABILITY_BY_NAME; - break; - } - case HidumpFlag::GET_BUNDLE: { - hidumpParam.hidumpFlag = HidumpFlag::GET_BUNDLE_BY_NAME; - break; - } - default: { - break; - } - } - return ProcessDump(hidumpParam, result); } @@ -225,7 +214,7 @@ void HidumpHelper::ShowHelp(std::string &result) void HidumpHelper::ShowIllealInfomation(std::string &result) { - result.append(ILLEGAL_INFOMATION); + result.append(); } } // namespace AppExecFwk } // namespace OHOS diff --git a/services/screenservice/sourceservice/BUILD.gn b/services/screenservice/sourceservice/BUILD.gn index 922c9844..ebd0b6cd 100644 --- a/services/screenservice/sourceservice/BUILD.gn +++ b/services/screenservice/sourceservice/BUILD.gn @@ -49,12 +49,14 @@ ohos_shared_library("distributed_screen_source") { "${interfaces_path}/innerkits/native_cpp/screen_source/src/dscreen_source_proxy.cpp", "${services_path}/common/utils/src/dscreen_maprelation.cpp", "${services_path}/common/utils/src/video_param.cpp", + "${services_path}/common/utils/src/hidump_helper.cpp", "./dscreenmgr/src/dscreen.cpp", "./dscreenmgr/src/dscreen_manager.cpp", "./dscreenmgr/src/screen_manager_adapter.cpp", "./dscreenservice/src/callback/dscreen_source_callback_proxy.cpp", "./dscreenservice/src/dscreen_source_service.cpp", "./dscreenservice/src/dscreen_source_stub.cpp", + ] deps = [ diff --git a/services/screenservice/sourceservice/dscreenservice/src/dscreen_source_service.cpp b/services/screenservice/sourceservice/dscreenservice/src/dscreen_source_service.cpp index 5b69a89a..69adfcf7 100644 --- a/services/screenservice/sourceservice/dscreenservice/src/dscreen_source_service.cpp +++ b/services/screenservice/sourceservice/dscreenservice/src/dscreen_source_service.cpp @@ -26,6 +26,7 @@ #include "dscreen_errcode.h" #include "dscreen_log.h" #include "dscreen_util.h" +#include "hidump_helper.h" namespace OHOS { namespace DistributedHardware { @@ -149,7 +150,7 @@ int DScreenSourceService::Dump(int32_t fd, const std::vector& ar argsStr.emplace_back(Str16ToStr8(item)); } - if (dump(argsStr, result)) { + if (HidumpHelper::GetInstance().Dump(argsStr, result)) { DHLOGE("Hidump error"); return ERR_APPEXECFWK_HIDUMP_ERROR; } -- Gitee From 15bfd29f5f3bf683a2aae6d3e3694632798cf9d4 Mon Sep 17 00:00:00 2001 From: gaoqiang_strong Date: Sun, 24 Apr 2022 10:16:41 +0800 Subject: [PATCH 05/10] dumper Signed-off-by: gaoqiang_strong --- services/common/utils/include/hidump_helper.h | 2 ++ services/common/utils/src/hidump_helper.cpp | 25 +++++++++++++------ .../src/dscreen_source_service.cpp | 8 +++--- 3 files changed, 24 insertions(+), 11 deletions(-) diff --git a/services/common/utils/include/hidump_helper.h b/services/common/utils/include/hidump_helper.h index 6ba318e5..40940ddf 100644 --- a/services/common/utils/include/hidump_helper.h +++ b/services/common/utils/include/hidump_helper.h @@ -19,6 +19,8 @@ #include #include +#include "single_instance.h" + namespace OHOS { namespace DistributedHardware { enum class HidumpFlag { diff --git a/services/common/utils/src/hidump_helper.cpp b/services/common/utils/src/hidump_helper.cpp index aacb4935..fd7d2160 100644 --- a/services/common/utils/src/hidump_helper.cpp +++ b/services/common/utils/src/hidump_helper.cpp @@ -15,8 +15,6 @@ #include "hidump_helper.h" -#include "single_instance.h" - #include "dscreen_constants.h" #include "dscreen_errcode.h" #include "dscreen_log.h" @@ -50,9 +48,13 @@ const std::unordered_map ARGS_MAP = { bool HidumpHelper::Dump(const std::vector& args, std::string &result) { + DHLOGI("HidumpHelper Dump args.size():%d.", args.size()); result.clear(); int32_t errCode = DH_SUCCESS; int32_t argsSize = static_cast(args.size()); + for (int i = 0; i < args.size(); i++) { + DHLOGI("HidumpHelper Dump args[%d]: %s.", i, args.at(i).c_str()); + } switch (argsSize) { case MIN_ARGS_SIZE: { errCode = ProcessOneParam(args[FIRST_PARAM], result); @@ -80,7 +82,7 @@ bool HidumpHelper::Dump(const std::vector& args, std::string &resul break; } case ERR_DH_SCREEN_HIDUMP_UNKONW: { - result.append(NO_INFOMATION); + result.append(""); ret = true; break; } @@ -97,6 +99,7 @@ bool HidumpHelper::Dump(const std::vector& args, std::string &resul int32_t HidumpHelper::ProcessOneParam(const std::string& args, std::string &result) { + DHLOGI("ProcessOneParam Dump."); HidumpParam hidumpParam; auto operatorIter = ARGS_MAP.find(args); if (operatorIter != ARGS_MAP.end()) { @@ -114,6 +117,7 @@ int32_t HidumpHelper::ProcessOneParam(const std::string& args, std::string &resu int32_t HidumpHelper::ProcessTwoParam( const std::string& firstParam, const std::string& secondParam, std::string &result) { + DHLOGI("ProcessTwoParam Dump."); HidumpParam hidumpParam; hidumpParam.args = secondParam; auto operatorIter = ARGS_MAP.find(firstParam); @@ -126,6 +130,7 @@ int32_t HidumpHelper::ProcessTwoParam( int32_t HidumpHelper::ProcessDump(const HidumpParam& hidumpParam, std::string &result) { + DHLOGI("ProcessDump Dump."); result.clear(); int32_t errCode = ERR_DH_SCREEN_HIDUMP_ERROR; switch (hidumpParam.hidumpFlag) { @@ -164,38 +169,43 @@ int32_t HidumpHelper::ProcessDump(const HidumpParam& hidumpParam, std::string &r int32_t HidumpHelper::GetEnableInfo(std::string &result) { - + DHLOGI("GetEnableInfo Dump."); return DH_SUCCESS; } int32_t HidumpHelper::GetScreenInfo(std::string &result) { - + DHLOGI("GetScreenInfo Dump."); return DH_SUCCESS; } int32_t HidumpHelper::GetSessionInfo(const std::string &name, std::string &result) { - return ERR_DH_SCREEN_HIDUMP_ERROR; + DHLOGI("GetSessionInfo Dump."); + return DH_SUCCESS; } int32_t HidumpHelper::GetEncoderInfo(std::string &result) { + DHLOGI("GetEncoderInfo Dump."); return DH_SUCCESS; } int32_t HidumpHelper::GetDecoderInfo(std::string &result) { + DHLOGI("GetDecoderInfo Dump."); return DH_SUCCESS; } int32_t HidumpHelper::GetDisableInfo(const std::string &name, std::string &result) { + DHLOGI("GetDisableInfo Dump."); return DH_SUCCESS; } void HidumpHelper::ShowHelp(std::string &result) { + DHLOGI("ShowHelp Dump."); result.append("Usage:dump [options]\n") .append("Description:\n") .append("-enableInfo ") @@ -214,7 +224,8 @@ void HidumpHelper::ShowHelp(std::string &result) void HidumpHelper::ShowIllealInfomation(std::string &result) { - result.append(); + DHLOGI("ShowIllealInfomation Dump."); + result.append(""); } } // namespace AppExecFwk } // namespace OHOS diff --git a/services/screenservice/sourceservice/dscreenservice/src/dscreen_source_service.cpp b/services/screenservice/sourceservice/dscreenservice/src/dscreen_source_service.cpp index 69adfcf7..b168f490 100644 --- a/services/screenservice/sourceservice/dscreenservice/src/dscreen_source_service.cpp +++ b/services/screenservice/sourceservice/dscreenservice/src/dscreen_source_service.cpp @@ -143,22 +143,22 @@ void DScreenSourceService::DScreenNotify(const std::string &devId, const int32_t int DScreenSourceService::Dump(int32_t fd, const std::vector& args) { - DHLOGI("Dump."); + DHLOGI("DScreenSourceService Dump."); std::string result; std::vector argsStr; for (auto item : args) { argsStr.emplace_back(Str16ToStr8(item)); } - if (HidumpHelper::GetInstance().Dump(argsStr, result)) { + if (!HidumpHelper::GetInstance().Dump(argsStr, result)) { DHLOGE("Hidump error"); - return ERR_APPEXECFWK_HIDUMP_ERROR; + return ERR_DH_SCREEN_HIDUMP_ERROR; } int ret = dprintf(fd, "%s\n", result.c_str()); if (ret < 0) { DHLOGE("dprintf error"); - return ERR_APPEXECFWK_HIDUMP_ERROR; + return ERR_DH_SCREEN_HIDUMP_ERROR; } return ERR_OK; -- Gitee From 3f2aa8dac58fe9fc272c3d64523e78a432658feb Mon Sep 17 00:00:00 2001 From: gaoqiang_strong Date: Sun, 24 Apr 2022 10:22:12 +0800 Subject: [PATCH 06/10] dumper Signed-off-by: gaoqiang_strong --- common/include/dscreen_errcode.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/common/include/dscreen_errcode.h b/common/include/dscreen_errcode.h index 8eb35085..0e1550f3 100644 --- a/common/include/dscreen_errcode.h +++ b/common/include/dscreen_errcode.h @@ -90,7 +90,7 @@ enum DScreenErrorCode { ERR_DH_SCREEN_SCREENCLIENT_ADD_WINDOW_ERROR = -54002, ERR_DH_SCREEN_SCREENCLIENT_MOVE_WINDOW_ERROR = -54003, ERR_DH_SCREEN_SCREENCLIENT_HIDE_WINDOW_ERROR = -54004, - //hidumper + // hidumper ERR_DH_SCREEN_HIDUMP_UNKONW = -55000, ERR_DH_SCREEN_HIDUMP_ERROR = -55001, ERR_DH_SCREEN_HIDUMP_INVALID_ARGS = -55002, -- Gitee From eebead3b27a9b29547a25fdfb5f664a3f64efef6 Mon Sep 17 00:00:00 2001 From: gaoqiang_strong Date: Sun, 24 Apr 2022 10:38:55 +0800 Subject: [PATCH 07/10] dumper Signed-off-by: gaoqiang_strong --- services/common/utils/src/hidump_helper.cpp | 2 ++ 1 file changed, 2 insertions(+) diff --git a/services/common/utils/src/hidump_helper.cpp b/services/common/utils/src/hidump_helper.cpp index fd7d2160..f3a696f8 100644 --- a/services/common/utils/src/hidump_helper.cpp +++ b/services/common/utils/src/hidump_helper.cpp @@ -15,6 +15,8 @@ #include "hidump_helper.h" +#include + #include "dscreen_constants.h" #include "dscreen_errcode.h" #include "dscreen_log.h" -- Gitee From d0e6e93b2a52ba7de300d7b5594e711b01300ed0 Mon Sep 17 00:00:00 2001 From: gaoqiang_strong Date: Mon, 25 Apr 2022 09:24:11 +0800 Subject: [PATCH 08/10] dumper Signed-off-by: gaoqiang_strong --- .../sinkservice/dscreenservice/include/dscreen_sink_service.h | 1 - 1 file changed, 1 deletion(-) diff --git a/services/screenservice/sinkservice/dscreenservice/include/dscreen_sink_service.h b/services/screenservice/sinkservice/dscreenservice/include/dscreen_sink_service.h index c19095b2..1cdf5dbe 100644 --- a/services/screenservice/sinkservice/dscreenservice/include/dscreen_sink_service.h +++ b/services/screenservice/sinkservice/dscreenservice/include/dscreen_sink_service.h @@ -36,7 +36,6 @@ public: int32_t SubscribeLocalHardware(const std::string &dhId, const std::string ¶m) override; int32_t UnsubscribeLocalHardware(const std::string &dhId) override; void DScreenNotify(const std::string &devId, int32_t eventCode, const std::string &eventContent) override; - int32_t Dump(int32_t fd, const std::vector& args) override; protected: void OnStart() override; -- Gitee From 950d37bd286597e5c1d36764c65dda262441b07a Mon Sep 17 00:00:00 2001 From: gaoqiang_strong Date: Tue, 10 May 2022 15:22:44 +0800 Subject: [PATCH 09/10] =?UTF-8?q?=E2=80=9Cdumper=E2=80=9D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: gaoqiang_strong --- common/include/dscreen_constants.h | 24 ++++++++ services/common/utils/include/hidump_helper.h | 22 ++----- services/common/utils/src/hidump_helper.cpp | 57 +++++++++---------- .../src/dscreen_source_service.cpp | 14 +++-- 4 files changed, 65 insertions(+), 52 deletions(-) diff --git a/common/include/dscreen_constants.h b/common/include/dscreen_constants.h index c4b08a4b..4e9d59fd 100644 --- a/common/include/dscreen_constants.h +++ b/common/include/dscreen_constants.h @@ -57,6 +57,30 @@ enum VideoFormat : uint8_t { VIDEO_DATA_FORMAT_RGBA8888 = 3, }; +enum class HidumpFlag { + UNKNOW = 0, + GET_HELP, + GET_ENABLE_INFO, + GET_SCREEN_INFO, + GET_SESSION_INFO, + GET_ENCODER_INFO, + GET_DECODER_INFO, + GET_DISABLE_INFO, +}; + +struct HidumpParam { + HidumpFlag hidumpFlag = HidumpFlag::UNKNOW; + std::string args; +}; + +struct ScreenDumpInfo { + std::string version; + std::string attrs; + std::string devId; + std::string dhId; + std::string reqId; +}; + /* Screen package name */ const std::string PKG_NAME = "ohos.dhardware.dscreen"; diff --git a/services/common/utils/include/hidump_helper.h b/services/common/utils/include/hidump_helper.h index 40940ddf..973ab5c9 100644 --- a/services/common/utils/include/hidump_helper.h +++ b/services/common/utils/include/hidump_helper.h @@ -23,29 +23,15 @@ namespace OHOS { namespace DistributedHardware { -enum class HidumpFlag { - UNKNOW = 0, - GET_HELP, - GET_ENABLE_INFO, - GET_SCREEN_INFO, - GET_SESSION_INFO, - GET_ENCODER_INFO, - GET_DECODER_INFO, - GET_DISABLE_INFO, -}; - -struct HidumpParam { - HidumpFlag hidumpFlag = HidumpFlag::UNKNOW; - std::string args; -}; - class HidumpHelper { DECLARE_SINGLE_INSTANCE_BASE(HidumpHelper); public: - bool Dump(const std::vector& args, std::string &result); + void SetScreenDumpInfo(ScreenDumpInfo& dumpInfo); + void Dump(const std::vector& args, std::string &result); private: explicit HidumpHelper() = default; ~HidumpHelper() = default; + int32_t ProcessParam(const std::string& args, std::string &result); int32_t ProcessOneParam(const std::string& args, std::string &result); int32_t ProcessTwoParam(const std::string& firstParam, const std::string& secondParam, std::string &result); @@ -59,6 +45,8 @@ private: int32_t GetEncoderInfo(std::string &result); int32_t GetDecoderInfo(std::string &result); int32_t GetDisableInfo(const std::string &name, std::string &result); +private: + ScreenDumpInfo dumpInfo_; }; } // namespace AppExecFwk } // namespace OHOS diff --git a/services/common/utils/src/hidump_helper.cpp b/services/common/utils/src/hidump_helper.cpp index f3a696f8..a2549a09 100644 --- a/services/common/utils/src/hidump_helper.cpp +++ b/services/common/utils/src/hidump_helper.cpp @@ -25,8 +25,9 @@ namespace OHOS { namespace DistributedHardware { IMPLEMENT_SINGLE_INSTANCE(HidumpHelper); namespace { -const int32_t MIN_ARGS_SIZE = 1; -const int32_t MAX_ARGS_SIZE = 2; +const int32_t ZERO_ARGS_SIZE = 0; +const int32_t ONE_ARGS_SIZE = 1; +const int32_t TWO_ARGS_SIZE = 2; const int32_t FIRST_PARAM = 0; const int32_t SECOND_PARAM = 1; const std::string ARGS_HELP = "-h"; @@ -48,55 +49,49 @@ const std::unordered_map ARGS_MAP = { }; } -bool HidumpHelper::Dump(const std::vector& args, std::string &result) +void HidumpHelper::SetScreenDumpInfo(ScreenDumpInfo &dumpInfo) +{ + dumpInfo_ = dumpInfo; +} + +void HidumpHelper::Dump(const std::vector& args, std::string &result) { DHLOGI("HidumpHelper Dump args.size():%d.", args.size()); result.clear(); - int32_t errCode = DH_SUCCESS; - int32_t argsSize = static_cast(args.size()); - for (int i = 0; i < args.size(); i++) { - DHLOGI("HidumpHelper Dump args[%d]: %s.", i, args.at(i).c_str()); - } - switch (argsSize) { - case MIN_ARGS_SIZE: { - errCode = ProcessOneParam(args[FIRST_PARAM], result); + int32_t errCode = ProcessParam(args, result); + switch (errCode) { + case ERR_DH_SCREEN_HIDUMP_INVALID_ARGS: { + ShowIllealInfomation(result); break; } - case MAX_ARGS_SIZE: { - errCode = ProcessTwoParam(args[FIRST_PARAM], args[SECOND_PARAM], result); + case ERR_DH_SCREEN_HIDUMP_UNKONW: { + result.append(""); break; } default: { - errCode = ERR_DH_SCREEN_HIDUMP_INVALID_ARGS; break; } } +} - bool ret = false; - switch (errCode) { - case DH_SUCCESS: { - ret = true; - break; - } - case ERR_DH_SCREEN_HIDUMP_INVALID_ARGS: { - ShowIllealInfomation(result); - ret = true; - break; - } - case ERR_DH_SCREEN_HIDUMP_UNKONW: { - result.append(""); - ret = true; +int32_t HidumpHelper::ProcessParam(const std::string& args, std::string &result) +{ + DHLOGI("ProcessParam Dump."); + int32_t argsSize = static_cast(args.size()); + switch (argsSize) { + case MIN_ARGS_SIZE: { + errCode = ProcessOneParam(args[FIRST_PARAM], result); break; } - case ERR_DH_SCREEN_HIDUMP_ERROR: { - ret = false; + case MAX_ARGS_SIZE: { + errCode = ProcessTwoParam(args[FIRST_PARAM], args[SECOND_PARAM], result); break; } default: { + errCode = ERR_DH_SCREEN_HIDUMP_INVALID_ARGS; break; } } - return ret; } int32_t HidumpHelper::ProcessOneParam(const std::string& args, std::string &result) diff --git a/services/screenservice/sourceservice/dscreenservice/src/dscreen_source_service.cpp b/services/screenservice/sourceservice/dscreenservice/src/dscreen_source_service.cpp index b9447077..e80242cb 100644 --- a/services/screenservice/sourceservice/dscreenservice/src/dscreen_source_service.cpp +++ b/services/screenservice/sourceservice/dscreenservice/src/dscreen_source_service.cpp @@ -105,6 +105,15 @@ int32_t DScreenSourceService::RegisterDistributedHardware(const std::string &dev DHLOGI("RegisterDistributedHardware"); std::string version = param.version; std::string attrs = param.attrs; + + ScreenDumpInfo screenDumpInfo = { + version, + attrs, + GetAnonyString(devId), + GetAnonyString(dhId), + reqId + }; + HidumpHelper::GetInstance().SetScreenDumpInfo(screenDumpInfo); DHLOGD("enable distributedScreen. devId: %s, dhId: %s, reqId: %s, attrs: %s, version: %s", GetAnonyString(devId).c_str(), GetAnonyString(dhId).c_str(), reqId.c_str(), attrs.c_str(), version.c_str()); int ret = DScreenManager::GetInstance().EnableDistributedScreen(devId, dhId, attrs, reqId); @@ -152,10 +161,7 @@ int DScreenSourceService::Dump(int32_t fd, const std::vector& ar argsStr.emplace_back(Str16ToStr8(item)); } - if (!HidumpHelper::GetInstance().Dump(argsStr, result)) { - DHLOGE("Hidump error"); - return ERR_DH_SCREEN_HIDUMP_ERROR; - } + HidumpHelper::GetInstance().Dump(argsStr, result); int ret = dprintf(fd, "%s\n", result.c_str()); if (ret < 0) { -- Gitee From d0a4dba56cb52df11d86839cc7158923cabe8a0d Mon Sep 17 00:00:00 2001 From: gaoqiang_strong Date: Wed, 11 May 2022 17:34:48 +0800 Subject: [PATCH 10/10] dumper Signed-off-by: gaoqiang_strong --- .../utils/include/dscreen_maprelation.h | 65 ----- services/common/utils/src/hidump_helper.cpp | 228 ------------------ .../screenregionmgr/include/screenregion.h | 2 + .../screenregionmgr/include/screenregionmgr.h | 2 +- .../screenregionmgr/src/screenregion.cpp | 10 + .../screenregionmgr/src/screenregionmgr.cpp | 32 +++ services/screenservice/sourceservice/BUILD.gn | 1 - .../dscreenmgr/include/dscreen_manager.h | 1 + .../dscreenmgr/src/dscreen_manager.cpp | 32 +++ .../src/dscreen_source_service.cpp | 8 +- 10 files changed, 79 insertions(+), 302 deletions(-) delete mode 100644 services/common/utils/include/dscreen_maprelation.h delete mode 100644 services/common/utils/src/hidump_helper.cpp diff --git a/services/common/utils/include/dscreen_maprelation.h b/services/common/utils/include/dscreen_maprelation.h deleted file mode 100644 index 25c44027..00000000 --- a/services/common/utils/include/dscreen_maprelation.h +++ /dev/null @@ -1,65 +0,0 @@ -/* - * 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_DSCREEN_MAP_RELATION_H -#define OHOS_DSCREEN_MAP_RELATION_H - -#include "nlohmann/json.hpp" - -using json = nlohmann::json; - -namespace OHOS { -namespace DistributedHardware { -struct ScreenRect { - int32_t startX; - int32_t startY; - uint16_t width; - uint16_t height; -}; -struct DisplayRect { - int32_t startX; - int32_t startY; - int32_t width; - int32_t height; -}; - -class DScreenMapRelation { -public: - void SetDisplayId(uint64_t displayId); - uint64_t GetDisplayId() const; - void SetScreenId(uint64_t screenId); - uint64_t GetScreenId() const; - void SetDisplayRect(const DisplayRect &displayRect); - DisplayRect& GetDisplayRect(); - void SetScreenRect(const ScreenRect &screenRect); - ScreenRect& GetScreenRect(); -private: - friend void to_json(json &j, const DScreenMapRelation &dScreenMapRelation); - friend void from_json(const json &j, DScreenMapRelation &dScreenMapRelation); - - uint64_t displayId_; - uint64_t screenId_; - DisplayRect displayRect_; - ScreenRect screenRect_; -}; -void to_json(const json &j, const DScreenMapRelation &dScreenMapRelation); -void from_json(const json &j, DScreenMapRelation &dScreenMapRelation); -void to_json(json &j, const DisplayRect &rect); -void to_json(json &j, const ScreenRect &rect); -void from_json(const json &j, DisplayRect &rect); -void from_json(const json &j, ScreenRect &rect); -} // namespace DistributedHardware -} // namespace OHOS -#endif \ No newline at end of file diff --git a/services/common/utils/src/hidump_helper.cpp b/services/common/utils/src/hidump_helper.cpp deleted file mode 100644 index a2549a09..00000000 --- a/services/common/utils/src/hidump_helper.cpp +++ /dev/null @@ -1,228 +0,0 @@ -/* - * Copyright (c) 2022-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 "dscreen_constants.h" -#include "dscreen_errcode.h" -#include "dscreen_log.h" - -namespace OHOS { -namespace DistributedHardware { -IMPLEMENT_SINGLE_INSTANCE(HidumpHelper); -namespace { -const int32_t ZERO_ARGS_SIZE = 0; -const int32_t ONE_ARGS_SIZE = 1; -const int32_t TWO_ARGS_SIZE = 2; -const int32_t FIRST_PARAM = 0; -const int32_t SECOND_PARAM = 1; -const std::string ARGS_HELP = "-h"; -const std::string ARGS_ENABLE_INFO = "-enableInfo"; -const std::string ARGS_SCREEN_INFO = "-screenInfo"; -const std::string ARGS_SESSION_INFO = "-sessionInfo"; -const std::string ARGS_ENCODER_INFO = "-encoderInfo"; -const std::string ARGS_DECODER_INFO = "-decoderInfo"; -const std::string ARGS_DISABLE_INFO = "-disableInfo"; - -const std::unordered_map ARGS_MAP = { - { ARGS_HELP, HidumpFlag::GET_HELP }, - { ARGS_ENABLE_INFO, HidumpFlag::GET_ENABLE_INFO }, - { ARGS_SCREEN_INFO, HidumpFlag::GET_SCREEN_INFO }, - { ARGS_SESSION_INFO, HidumpFlag::GET_SESSION_INFO }, - { ARGS_ENCODER_INFO, HidumpFlag::GET_ENCODER_INFO }, - { ARGS_DECODER_INFO, HidumpFlag::GET_DECODER_INFO }, - { ARGS_DISABLE_INFO, HidumpFlag::GET_DISABLE_INFO }, -}; -} - -void HidumpHelper::SetScreenDumpInfo(ScreenDumpInfo &dumpInfo) -{ - dumpInfo_ = dumpInfo; -} - -void HidumpHelper::Dump(const std::vector& args, std::string &result) -{ - DHLOGI("HidumpHelper Dump args.size():%d.", args.size()); - result.clear(); - int32_t errCode = ProcessParam(args, result); - switch (errCode) { - case ERR_DH_SCREEN_HIDUMP_INVALID_ARGS: { - ShowIllealInfomation(result); - break; - } - case ERR_DH_SCREEN_HIDUMP_UNKONW: { - result.append(""); - break; - } - default: { - break; - } - } -} - -int32_t HidumpHelper::ProcessParam(const std::string& args, std::string &result) -{ - DHLOGI("ProcessParam Dump."); - int32_t argsSize = static_cast(args.size()); - switch (argsSize) { - case MIN_ARGS_SIZE: { - errCode = ProcessOneParam(args[FIRST_PARAM], result); - break; - } - case MAX_ARGS_SIZE: { - errCode = ProcessTwoParam(args[FIRST_PARAM], args[SECOND_PARAM], result); - break; - } - default: { - errCode = ERR_DH_SCREEN_HIDUMP_INVALID_ARGS; - break; - } - } -} - -int32_t HidumpHelper::ProcessOneParam(const std::string& args, std::string &result) -{ - DHLOGI("ProcessOneParam Dump."); - HidumpParam hidumpParam; - auto operatorIter = ARGS_MAP.find(args); - if (operatorIter != ARGS_MAP.end()) { - hidumpParam.hidumpFlag = operatorIter->second; - } - - if (hidumpParam.hidumpFlag == HidumpFlag::GET_HELP) { - ShowHelp(result); - return DH_SUCCESS; - } - - return ProcessDump(hidumpParam, result); -} - -int32_t HidumpHelper::ProcessTwoParam( - const std::string& firstParam, const std::string& secondParam, std::string &result) -{ - DHLOGI("ProcessTwoParam Dump."); - HidumpParam hidumpParam; - hidumpParam.args = secondParam; - auto operatorIter = ARGS_MAP.find(firstParam); - if (operatorIter != ARGS_MAP.end()) { - hidumpParam.hidumpFlag = operatorIter->second; - } - - return ProcessDump(hidumpParam, result); -} - -int32_t HidumpHelper::ProcessDump(const HidumpParam& hidumpParam, std::string &result) -{ - DHLOGI("ProcessDump Dump."); - result.clear(); - int32_t errCode = ERR_DH_SCREEN_HIDUMP_ERROR; - switch (hidumpParam.hidumpFlag) { - case HidumpFlag::GET_ENABLE_INFO: { - errCode = GetEnableInfo(result); - break; - } - case HidumpFlag::GET_SCREEN_INFO: { - errCode = GetScreenInfo(result); - break; - } - case HidumpFlag::GET_SESSION_INFO: { - errCode = GetSessionInfo(hidumpParam.args, result); - break; - } - case HidumpFlag::GET_ENCODER_INFO: { - errCode = GetEncoderInfo(result); - break; - } - case HidumpFlag::GET_DECODER_INFO: { - errCode = GetDecoderInfo(result); - break; - } - case HidumpFlag::GET_DISABLE_INFO: { - errCode = GetDisableInfo(hidumpParam.args, result); - break; - } - default: { - errCode = ERR_DH_SCREEN_HIDUMP_INVALID_ARGS; - break; - } - } - - return errCode; -} - -int32_t HidumpHelper::GetEnableInfo(std::string &result) -{ - DHLOGI("GetEnableInfo Dump."); - return DH_SUCCESS; -} - -int32_t HidumpHelper::GetScreenInfo(std::string &result) -{ - DHLOGI("GetScreenInfo Dump."); - return DH_SUCCESS; -} - -int32_t HidumpHelper::GetSessionInfo(const std::string &name, std::string &result) -{ - DHLOGI("GetSessionInfo Dump."); - return DH_SUCCESS; -} - -int32_t HidumpHelper::GetEncoderInfo(std::string &result) -{ - DHLOGI("GetEncoderInfo Dump."); - return DH_SUCCESS; -} - -int32_t HidumpHelper::GetDecoderInfo(std::string &result) -{ - DHLOGI("GetDecoderInfo Dump."); - return DH_SUCCESS; -} - -int32_t HidumpHelper::GetDisableInfo(const std::string &name, std::string &result) -{ - DHLOGI("GetDisableInfo Dump."); - return DH_SUCCESS; -} - -void HidumpHelper::ShowHelp(std::string &result) -{ - DHLOGI("ShowHelp Dump."); - result.append("Usage:dump [options]\n") - .append("Description:\n") - .append("-enableInfo ") - .append("dump screen enable status information in the system\n") - .append("-screenInfo ") - .append("dump all screen information in the system\n") - .append("-sessionInfo ") - .append("dump all session information in the system\n") - .append("-encoderInfo ") - .append("dump all encoder infomation in the system\n") - .append("-decoderInfo ") - .append("dump all decoder infomation in the system\n") - .append("-disableInfo ") - .append("dump screen disable status information in the system\n"); -} - -void HidumpHelper::ShowIllealInfomation(std::string &result) -{ - DHLOGI("ShowIllealInfomation Dump."); - result.append(""); -} -} // namespace AppExecFwk -} // namespace OHOS diff --git a/services/screenservice/sinkservice/screenregionmgr/include/screenregion.h b/services/screenservice/sinkservice/screenregionmgr/include/screenregion.h index 8c400b67..6709424f 100644 --- a/services/screenservice/sinkservice/screenregionmgr/include/screenregion.h +++ b/services/screenservice/sinkservice/screenregionmgr/include/screenregion.h @@ -45,6 +45,8 @@ public: std::string GetRemoteDevId(); uint64_t GetScreenId(); uint64_t GetDisplayId(); + std::shared_ptr GetVideoParam(); + int32_t GetWindowId(); int32_t SetUp(); int32_t Start(); int32_t Stop(); diff --git a/services/screenservice/sinkservice/screenregionmgr/include/screenregionmgr.h b/services/screenservice/sinkservice/screenregionmgr/include/screenregionmgr.h index 65fcd09a..798b0806 100644 --- a/services/screenservice/sinkservice/screenregionmgr/include/screenregionmgr.h +++ b/services/screenservice/sinkservice/screenregionmgr/include/screenregionmgr.h @@ -31,7 +31,7 @@ DECLARE_SINGLE_INSTANCE_BASE(ScreenRegionManager); public: int32_t ReleaseAllRegions(); void HandleDScreenNotify(const std::string &devId, int32_t eventCode, const std::string &eventContent); - + void GetScreenDumpInfo(std::string &result); private: ScreenRegionManager(); ~ScreenRegionManager(); diff --git a/services/screenservice/sinkservice/screenregionmgr/src/screenregion.cpp b/services/screenservice/sinkservice/screenregionmgr/src/screenregion.cpp index 93520843..cc3b4e28 100644 --- a/services/screenservice/sinkservice/screenregionmgr/src/screenregion.cpp +++ b/services/screenservice/sinkservice/screenregionmgr/src/screenregion.cpp @@ -73,6 +73,16 @@ std::string ScreenRegion::GetRemoteDevId() return remoteDevId_; } +std::shared_ptr ScreenRegion::GetVideoParam() +{ + return videoParam_; +} + +int32_t ScreenRegion::GetWindowId() +{ + return windowId_; +} + int32_t ScreenRegion::SetUp() { DHLOGI("ScreenRegion::SetUp, remoteDevId: %s", GetAnonyString(remoteDevId_).c_str()); diff --git a/services/screenservice/sinkservice/screenregionmgr/src/screenregionmgr.cpp b/services/screenservice/sinkservice/screenregionmgr/src/screenregionmgr.cpp index 48457eeb..2ef53b42 100644 --- a/services/screenservice/sinkservice/screenregionmgr/src/screenregionmgr.cpp +++ b/services/screenservice/sinkservice/screenregionmgr/src/screenregionmgr.cpp @@ -74,6 +74,38 @@ void ScreenRegionManager::HandleDScreenNotify(const std::string &remoteDevId, in DHLOGE("invalid event."); } +void ScreenRegionManager::GetScreenDumpInfo(std::string &result) +{ + DHLOGI("GetScreenDumpInfo."); + result.clear(); + result.append("screenRegion OnLine:\n[\n"); + if (screenRegions_.size() == 0) { + result.append(" exsit 0 screenRegion\n]"); + DHLOGD("no screenRegion"); + return; + } + + for (const auto &iter : screenRegions_) { + std::shared_ptr screenRegion = iter.second; + if (!screenRegion) { + continue; + } + uint64_t screenId = screenRegion->GetScreenId(); + std::string remoteDevId = screenRegion->GetRemoteDevId(); + std::shared_ptr videoParam = screenRegion->GetVideoParam(); + if (videoParam == nullptr) { + continue; + } + int32_t screenHeight = videoParam->GetScreenHeight(); + int32_t screenWidth = videoParam->GetScreenWidth(); + int32_t windowId = screenRegion->GetWindowId(); + std::string screenInfo = "{ windowId:" + windowId + ", devId:"+ GetAnonyString(devId) + + ", screenWidth:" + screenWidth + ", screenHeight:" + screenHeight + " }\n"; + result.append(screenInfo); + } + result.append("]"); +} + void ScreenRegionManager::HandleNotifySetUp(const std::string &remoteDevId, const std::string &eventContent) { DHLOGI("HandleNotifySetUp, remoteDevId: %s", GetAnonyString(remoteDevId).c_str()); diff --git a/services/screenservice/sourceservice/BUILD.gn b/services/screenservice/sourceservice/BUILD.gn index ebd0b6cd..1b9d422e 100644 --- a/services/screenservice/sourceservice/BUILD.gn +++ b/services/screenservice/sourceservice/BUILD.gn @@ -49,7 +49,6 @@ ohos_shared_library("distributed_screen_source") { "${interfaces_path}/innerkits/native_cpp/screen_source/src/dscreen_source_proxy.cpp", "${services_path}/common/utils/src/dscreen_maprelation.cpp", "${services_path}/common/utils/src/video_param.cpp", - "${services_path}/common/utils/src/hidump_helper.cpp", "./dscreenmgr/src/dscreen.cpp", "./dscreenmgr/src/dscreen_manager.cpp", "./dscreenmgr/src/screen_manager_adapter.cpp", diff --git a/services/screenservice/sourceservice/dscreenmgr/include/dscreen_manager.h b/services/screenservice/sourceservice/dscreenmgr/include/dscreen_manager.h index 9af60db0..67c3cdd2 100644 --- a/services/screenservice/sourceservice/dscreenmgr/include/dscreen_manager.h +++ b/services/screenservice/sourceservice/dscreenmgr/include/dscreen_manager.h @@ -58,6 +58,7 @@ public: void RegisterDScreenCallback(const sptr &callback); void HandleScreenChange(const std::shared_ptr &changedScreen, Rosen::ScreenGroupChangeEvent event); std::shared_ptr FindDScreenByScreenId(uint64_t screenId); + void GetScreenDumpInfo(std::string &result); private: ~DScreenManager(); diff --git a/services/screenservice/sourceservice/dscreenmgr/src/dscreen_manager.cpp b/services/screenservice/sourceservice/dscreenmgr/src/dscreen_manager.cpp index 49812b88..ddc1bc1a 100644 --- a/services/screenservice/sourceservice/dscreenmgr/src/dscreen_manager.cpp +++ b/services/screenservice/sourceservice/dscreenmgr/src/dscreen_manager.cpp @@ -293,6 +293,38 @@ std::shared_ptr DScreenManager::FindDScreenByScreenId(uint64_t screenId return nullptr; } +void DScreenManager::GetScreenDumpInfo(std::string &result) +{ + DHLOGI("GetScreenDumpInfo."); + result.clear(); + result.append("RemoteScreens OnLine:\n[\n"); + if (dScreens_.size() == 0) { + result.append(" exsit 0 virtualScreen\n]"); + DHLOGD("no virtualscreen"); + return; + } + + for (const auto &iter : dScreens_) { + std::shared_ptr dScreen = iter.second; + if (!dScreen) { + continue; + } + uint64_t screenId = dScreen->GetScreenId(); + std::string devId = dScreen->GetDevId(); + std::shared_ptr videoParam = dScreen->GetVideoParam(); + if (videoParam == nullptr) { + continue; + } + int32_t screenHeight = videoParam->GetScreenHeight(); + int32_t screenWidth = videoParam->GetScreenWidth(); + DScreenState state = dScreen->GetState(); + std::string screenInfo = "{ virtualScreenId:" + screenId + ", devId:"+ GetAnonyString(devId) + + ", screenWidth:" + screenWidth + ", screenHeight:" + screenHeight + ", state:" + state + " }\n"; + result.append(screenInfo); + } + result.append("]"); +} + void DScreenManager::HandleDScreenNotify(const std::string &devId, int32_t eventCode, const std::string &eventContent) { diff --git a/services/screenservice/sourceservice/dscreenservice/src/dscreen_source_service.cpp b/services/screenservice/sourceservice/dscreenservice/src/dscreen_source_service.cpp index e80242cb..2c6ae8db 100644 --- a/services/screenservice/sourceservice/dscreenservice/src/dscreen_source_service.cpp +++ b/services/screenservice/sourceservice/dscreenservice/src/dscreen_source_service.cpp @@ -156,13 +156,7 @@ int DScreenSourceService::Dump(int32_t fd, const std::vector& ar { DHLOGI("DScreenSourceService Dump."); std::string result; - std::vector argsStr; - for (auto item : args) { - argsStr.emplace_back(Str16ToStr8(item)); - } - - HidumpHelper::GetInstance().Dump(argsStr, result); - + DScreenManager::GetInstance().GetScreenDumpInfo(result); int ret = dprintf(fd, "%s\n", result.c_str()); if (ret < 0) { DHLOGE("dprintf error"); -- Gitee