From faf5fd84a9827467eb2d42f4a4fac8f9930f6325 Mon Sep 17 00:00:00 2001 From: zhu-bingwei123 Date: Tue, 5 Mar 2024 21:24:14 +0800 Subject: [PATCH] =?UTF-8?q?formComponent=20=E6=94=AF=E6=8C=81=20string?= =?UTF-8?q?=E7=B1=BB=E5=9E=8B=E7=9A=84formId?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: zhu-bingwei123 --- services/include/form_dump_mgr.h | 12 +++++ services/include/form_mgr_adapter.h | 7 +++ services/include/form_mgr_service.h | 2 + services/src/form_dump_mgr.cpp | 75 +++++++++++++++++++++++++++++ services/src/form_mgr_adapter.cpp | 14 ++++++ services/src/form_mgr_service.cpp | 20 +++++++- 6 files changed, 128 insertions(+), 2 deletions(-) diff --git a/services/include/form_dump_mgr.h b/services/include/form_dump_mgr.h index 8308b67599..8b717f9ece 100644 --- a/services/include/form_dump_mgr.h +++ b/services/include/form_dump_mgr.h @@ -22,6 +22,7 @@ #include "form_dump_mgr.h" #include "form_host_record.h" #include "form_info_mgr.h" +#include "running_form_info.h" namespace OHOS { namespace AppExecFwk { @@ -96,9 +97,20 @@ public: void DumpFormSubscribeInfo( const std::vector &subscribedKeys, const int64_t &count, std::string &formInfo) const; + /** + * @brief Dump running form information. + * @param runningFormInfos All the running form information + * @param infosResult The dump info of all the running form info. + */ + void DumpRunningFormInfos(const std::vector &runningFormInfos, + std::string &infosResult) const; + private: void AppendBundleFormInfo(const FormRecord &formRecordInfo, std::string &formInfo) const; void AppendRecycleStatus(const FormRecord &formRecordInfo, std::string &formInfo) const; + void AppendRunningFormInfors(const std::string &formHostBundleName, + const std::vector &runningFormInfos, + std::string &infosResult) const; }; } // namespace AppExecFwk } // namespace OHOS diff --git a/services/include/form_mgr_adapter.h b/services/include/form_mgr_adapter.h index f9a052a3bd..39beed20e7 100644 --- a/services/include/form_mgr_adapter.h +++ b/services/include/form_mgr_adapter.h @@ -192,6 +192,13 @@ public: */ int DumpFormTimerByFormId(const std::int64_t formId, std::string &isTimingService) const; + /** + * @brief Dump running form info. + * @param runningFormInfosResult The dump info of all the running form info. + * @return Returns ERR_OK on success, others on failure. + */ + int DumpFormRunningFormInfos(std::string &runningFormInfosResult) const; + /** * @brief set next refresh time. * @param formId The id of the form. diff --git a/services/include/form_mgr_service.h b/services/include/form_mgr_service.h index 0c56a56055..8036b29a49 100644 --- a/services/include/form_mgr_service.h +++ b/services/include/form_mgr_service.h @@ -596,6 +596,7 @@ private: KEY_DUMP_TEMPORARY, KEY_DUMP_STATIC, KEY_DUMP_VISIBLE, + KEY_DUMP_RUNNING, }; /** * @brief initialization of form manager service. @@ -621,6 +622,7 @@ private: void HiDumpHasFormVisible(const std::string &args, std::string &result); void HiDumpFormInfoByBundleName(const std::string &args, std::string &result); void HiDumpFormInfoByFormId(const std::string &args, std::string &result); + void HiDumpFormRunningFormInfos([[maybe_unused]] const std::string &args, std::string &result); bool CheckCallerIsSystemApp() const; static std::string GetCurrentDateTime(); private: diff --git a/services/src/form_dump_mgr.cpp b/services/src/form_dump_mgr.cpp index ccf79ff0a4..ea25432814 100644 --- a/services/src/form_dump_mgr.cpp +++ b/services/src/form_dump_mgr.cpp @@ -18,6 +18,8 @@ #include "fms_log_wrapper.h" #include "form_cache_mgr.h" #include "form_mgr_adapter.h" +#include +#include namespace OHOS { namespace AppExecFwk { @@ -252,6 +254,79 @@ void FormDumpMgr::DumpFormSubscribeInfo( formInfo += LINE_FEED; } +void FormDumpMgr::AppendRunningFormInfors(const std::string &formHostBundleName, + const std::vector &runningFormInfos, + std::string &infosResult) const +{ + HILOG_INFO("%{public}s called.", __func__); + + for (const auto& info : runningFormInfos) { + if (info.hostBundleName == formHostBundleName) { + infosResult += " FormId [ " + std::to_string(info.formId) + " ] \n"; + infosResult += " formName [ " + info.formName + " ]\n"; + infosResult += " bundleName [ " + info.bundleName + " ] \n"; + infosResult += " moduleName [ " + info.moduleName + " ] \n"; + infosResult += " abilityName [ " + info.abilityName + " ] \n"; + infosResult += " description [ " + info.description + " ] \n"; + infosResult += " dimension [ " + std::to_string(info.dimension) + " ] \n"; + + switch (info.formVisiblity) { + case FormVisibilityType::UNKNOWN: + infosResult += " formVisibility [ UNKNOWN ] \n"; + break; + case FormVisibilityType::VISIBLE: + infosResult += " formVisibility [ VISIBLE ] \n"; + break; + case FormVisibilityType::INVISIBLE: + infosResult += " formVisibility [ INVISIBLE ] \n"; + break; + default: + infosResult += " formVisibility [ UNKNOWN_TYPE ] \n"; + break; + } + + switch (info.formUsageState) { + case FormUsageState::USED: + infosResult += " FormUsageState [ USED ] \n"; + break; + case FormUsageState::UNUSED: + infosResult += " FormUsageState [ UNUSED ] \n"; + break; + default: + infosResult += " FormUsageState [ UNKNOWN_TYPE ] \n"; + break; + } + + infosResult += " \n"; + } + } +} + +/** + * @brief Dump Running form info. + * @param runningFormInfos Form Running Form infos. + * @param infosResult Running Form dump info. + */ +void FormDumpMgr::DumpRunningFormInfos(const std::vector &runningFormInfos, + std::string &infosResult) const +{ + HILOG_INFO("%{public}s called.", __func__); + + std::unordered_map countMap; + + for (const auto& info : runningFormInfos) { + countMap[info.hostBundleName]++; + } + + for (const auto& infoPair : countMap) { + infosResult += "hostBundleName [ " + infoPair.first + " ]\n"; + infosResult += "Total running form count: " + std::to_string(infoPair.second) + " ] \n"; + infosResult += " ================RunningFormInfo=================\n"; + + AppendRunningFormInfors(infoPair.first, runningFormInfos, infosResult); + } +} + void FormDumpMgr::AppendBundleFormInfo(const FormRecord &formRecordInfo, std::string &formInfo) const { FormInfo bundleFormInfo; diff --git a/services/src/form_mgr_adapter.cpp b/services/src/form_mgr_adapter.cpp index 1ae73e96f5..5fc93b60c2 100644 --- a/services/src/form_mgr_adapter.cpp +++ b/services/src/form_mgr_adapter.cpp @@ -1250,6 +1250,20 @@ int FormMgrAdapter::DumpFormTimerByFormId(const std::int64_t formId, std::string } return ERR_OK; } + +int FormMgrAdapter::DumpFormRunningFormInfos(std::string &runningFormInfosResult) const +{ + HILOG_INFO("%{public}s called.", __func__); + std::vector runningFormInfos; + auto ret = FormMgrAdapter::GetInstance().GetRunningFormInfos(true, runningFormInfos); + if (ret != ERR_OK) { + HILOG_ERROR("GetRunningFormInfos error."); + return ret; + } + + FormDumpMgr::GetInstance().DumpRunningFormInfos(runningFormInfos, runningFormInfosResult); + return ERR_OK; +} /** * @brief Get form configure info. * @param want The want of the request. diff --git a/services/src/form_mgr_service.cpp b/services/src/form_mgr_service.cpp index 81368eefbf..38907be4e9 100644 --- a/services/src/form_mgr_service.cpp +++ b/services/src/form_mgr_service.cpp @@ -83,7 +83,8 @@ const std::string FORM_DUMP_HELP = "options list:\n" " -s, --storage query form storage info\n" " -t, --temp query temporary form info\n" " -n query form info by a bundle name\n" - " -i query form info by a form ID\n"; + " -i query form info by a form ID\n" + " -r --running query running form info\n"; const std::map FormMgrService::dumpKeyMap_ = { {"-h", FormMgrService::DumpKey::KEY_DUMP_HELP}, @@ -98,6 +99,8 @@ const std::map FormMgrService::dumpKeyMap_ {"--temp", FormMgrService::DumpKey::KEY_DUMP_TEMPORARY}, {"-n", FormMgrService::DumpKey::KEY_DUMP_BY_BUNDLE_NAME}, {"-i", FormMgrService::DumpKey::KEY_DUMP_BY_FORM_ID}, + {"-r", FormMgrService::DumpKey::KEY_DUMP_RUNNING}, + {"--running", FormMgrService::DumpKey::KEY_DUMP_RUNNING}, }; FormMgrService::FormMgrService() @@ -490,6 +493,7 @@ int FormMgrService::DumpFormTimerByFormId(const std::int64_t formId, std::string } return FormMgrAdapter::GetInstance().DumpFormTimerByFormId(formId, isTimingService); } + /** * @brief Process js message event. * @param formId Indicates the unique id of form. @@ -1113,6 +1117,7 @@ void FormMgrService::DumpInit() dumpFuncMap_[DumpKey::KEY_DUMP_TEMPORARY] = &FormMgrService::HiDumpTemporaryFormInfos; dumpFuncMap_[DumpKey::KEY_DUMP_BY_BUNDLE_NAME] = &FormMgrService::HiDumpFormInfoByBundleName; dumpFuncMap_[DumpKey::KEY_DUMP_BY_FORM_ID] = &FormMgrService::HiDumpFormInfoByFormId; + dumpFuncMap_[DumpKey::KEY_DUMP_RUNNING] = &FormMgrService::HiDumpFormRunningFormInfos; } int FormMgrService::Dump(int fd, const std::vector &args) @@ -1219,7 +1224,7 @@ bool FormMgrService::ParseOption(const std::vector &args, DumpKe std::string optionKey = Str16ToStr8(args[0]); auto iter = dumpKeyMap_.find(optionKey); if (iter == dumpKeyMap_.end()) { - result = "error: unkown option."; + result = "error: unknown option."; return false; } @@ -1232,6 +1237,17 @@ bool FormMgrService::ParseOption(const std::vector &args, DumpKe return true; } +void FormMgrService::HiDumpFormRunningFormInfos([[maybe_unused]]const std::string &args, std::string &result) +{ + HILOG_DEBUG("called."); + + if (!CheckCallerIsSystemApp()) { + return; + } + + FormMgrAdapter::GetInstance().DumpFormRunningFormInfos(result); +} + void FormMgrService::HiDumpHelp([[maybe_unused]] const std::string &args, std::string &result) { result = FORM_DUMP_HELP; -- Gitee