From c3619079fa0bdae4d38da48699e9db8da3e44d02 Mon Sep 17 00:00:00 2001 From: xuzheheng Date: Thu, 29 Jan 2026 11:10:33 +0800 Subject: [PATCH] =?UTF-8?q?dump=E4=BC=98=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: xuzheheng --- .../include/ability_manager_service.h | 4 +- .../abilitymgr/include/utils/dump_utils.h | 9 +++- .../src/ability_manager_service.cpp | 36 ++----------- services/abilitymgr/src/utils/dump_utils.cpp | 23 ++++++++- .../abilitymanagerservicee_fuzzer.cpp | 2 - .../dump_utils_test/dump_utils_test.cpp | 51 +++++++++++++++++++ 6 files changed, 87 insertions(+), 38 deletions(-) diff --git a/services/abilitymgr/include/ability_manager_service.h b/services/abilitymgr/include/ability_manager_service.h index 614c274f11..1ee79e25ed 100644 --- a/services/abilitymgr/include/ability_manager_service.h +++ b/services/abilitymgr/include/ability_manager_service.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2023-2025 Huawei Device Co., Ltd. + * Copyright (c) 2023-2026 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 @@ -2567,8 +2567,6 @@ private: void DataDumpSysStateInner( const std::string &args, std::vector &info, bool isClient, bool isUserID, int userId); ErrCode ProcessMultiParam(std::vector& argsStr, std::string& result); - void ShowHelp(std::string& result); - void ShowIllegalInfomation(std::string& result); int Dump(const std::vector& args, std::string& result); // multi user diff --git a/services/abilitymgr/include/utils/dump_utils.h b/services/abilitymgr/include/utils/dump_utils.h index 7d9acab05e..d2107561e6 100644 --- a/services/abilitymgr/include/utils/dump_utils.h +++ b/services/abilitymgr/include/utils/dump_utils.h @@ -1,5 +1,5 @@ /* -* Copyright (c) 2024 Huawei Device Co., Ltd. + * Copyright (c) 2024-2026 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 @@ -118,6 +118,13 @@ public: * @return The pair of the dump result and the dump key. */ static std::pair DumpsysMap(std::string argString); + + /** + * ShowHelp, display help information for dump tool. + * + * @param result The result string to be filled with help information. + */ + static void ShowHelp(std::string& result); }; } // namespace AAFwk } // namespace OHOS diff --git a/services/abilitymgr/src/ability_manager_service.cpp b/services/abilitymgr/src/ability_manager_service.cpp index 270880f616..1179b070d0 100644 --- a/services/abilitymgr/src/ability_manager_service.cpp +++ b/services/abilitymgr/src/ability_manager_service.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2023-2025 Huawei Device Co., Ltd. + * Copyright (c) 2023-2026 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 @@ -179,7 +179,7 @@ namespace { constexpr const char* ARGS_USER_ID = "-u"; constexpr const char* ARGS_CLIENT = "-c"; -constexpr const char* ILLEGAL_INFOMATION = "The arguments are illegal and you can enter '-h' for help."; +constexpr const char* ILLEGAL_INFORMATION = "The arguments are illegal and you can enter '-h' for help."; constexpr int32_t NEW_RULE_VALUE_SIZE = 6; constexpr int32_t APP_ALIVE_TIME_MS = 1000; // Allow background startup within 1 second after application startup @@ -11166,7 +11166,7 @@ int AbilityManagerService::Dump(const std::vector& args, std::st ErrCode errCode = ERR_OK; auto size = args.size(); if (size == 0) { - ShowHelp(result); + DumpUtils::ShowHelp(result); return errCode; } @@ -11176,11 +11176,11 @@ int AbilityManagerService::Dump(const std::vector& args, std::st } if (argsStr[0] == "-h") { - ShowHelp(result); + DumpUtils::ShowHelp(result); } else { errCode = ProcessMultiParam(argsStr, result); if (errCode == ERR_AAFWK_HIDUMP_INVALID_ARGS) { - ShowIllegalInfomation(result); + result.append(ILLEGAL_INFORMATION); } } return errCode; @@ -11234,32 +11234,6 @@ ErrCode AbilityManagerService::ProcessMultiParam(std::vector& argsS return ERR_OK; } -void AbilityManagerService::ShowHelp(std::string& result) -{ - result.append("Usage:\n") - .append("-h ") - .append("help text for the tool\n") - .append("-a [-c | -u {UserId}] ") - .append("dump all ability infomation in the system or all ability infomation of client/UserId\n") - .append("-l ") - .append("dump all mission list information in the system\n") - .append("-i {AbilityRecordId} ") - .append("dump an ability infomation by ability record id\n") - .append("-e ") - .append("dump all extension infomation in the system(FA: ServiceAbilityRecords, Stage: ExtensionRecords)\n") - .append("-p [PendingWantRecordId] ") - .append("dump all pendingwant record infomation in the system\n") - .append("-r ") - .append("dump all process in the system\n") - .append("-d ") - .append("dump all data ability infomation in the system"); -} - -void AbilityManagerService::ShowIllegalInfomation(std::string& result) -{ - result.append(ILLEGAL_INFOMATION); -} - int AbilityManagerService::DumpAbilityInfoDone(std::vector &infos, const sptr &callerToken) { TAG_LOGD(AAFwkTag::ABILITYMGR, "dumpAbilityInfoDone begin"); diff --git a/services/abilitymgr/src/utils/dump_utils.cpp b/services/abilitymgr/src/utils/dump_utils.cpp index 36003400c1..12c409c6fd 100644 --- a/services/abilitymgr/src/utils/dump_utils.cpp +++ b/services/abilitymgr/src/utils/dump_utils.cpp @@ -1,5 +1,5 @@ /* -* Copyright (c) 2024 Huawei Device Co., Ltd. + * Copyright (c) 2024-2026 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 @@ -112,5 +112,26 @@ std::pair DumpUtils::DumpsysMap(std::string argStri } return result; } + +void DumpUtils::ShowHelp(std::string& result) +{ + result.append("Usage:\n") + .append("-h ") + .append("help text for the tool\n") + .append("-a [-c | -u {UserId}] ") + .append("dump all ability information in the system or all ability information of client/UserId\n") + .append("-l ") + .append("dump all mission list information in the system\n") + .append("-i {AbilityRecordId} ") + .append("dump an ability information by ability record id\n") + .append("-e ") + .append("dump all extension information in the system(FA: ServiceAbilityRecords, Stage: ExtensionRecords)\n") + .append("-p [PendingWantRecordId] ") + .append("dump all pendingwant record information in the system\n") + .append("-r ") + .append("dump all process in the system\n") + .append("-d ") + .append("dump all data ability information in the system"); +} } // namespace AAFwk } // namespace OHOS diff --git a/test/fuzztest/abilitymanagerservicee_fuzzer/abilitymanagerservicee_fuzzer.cpp b/test/fuzztest/abilitymanagerservicee_fuzzer/abilitymanagerservicee_fuzzer.cpp index 47f3531b4b..c86894a9a1 100755 --- a/test/fuzztest/abilitymanagerservicee_fuzzer/abilitymanagerservicee_fuzzer.cpp +++ b/test/fuzztest/abilitymanagerservicee_fuzzer/abilitymanagerservicee_fuzzer.cpp @@ -76,8 +76,6 @@ bool DoSomethingInterestingWithMyAPI(const char* data, size_t size) abilityms->Dump(intParam, args); abilityms->Dump(args, stringParam); abilityms->ProcessMultiParam(info, stringParam); - abilityms->ShowHelp(stringParam); - abilityms->ShowIllegalInfomation(stringParam); abilityms->DumpAbilityInfoDone(info, token); abilityms->SetMissionLabel(token, stringParam); std::shared_ptr icon; diff --git a/test/unittest/dump_utils_test/dump_utils_test.cpp b/test/unittest/dump_utils_test/dump_utils_test.cpp index 68ad50d6d3..4e8139d401 100644 --- a/test/unittest/dump_utils_test/dump_utils_test.cpp +++ b/test/unittest/dump_utils_test/dump_utils_test.cpp @@ -311,5 +311,56 @@ HWTEST_F(DumpUtilsTest, DumpMap_003, TestSize.Level1) EXPECT_FALSE(result.first); TAG_LOGI(AAFwkTag::TEST, "DumpUtilsTest DumpMap_003 end"); } + +/* + * Feature: DumpUtils + * Function: ShowHelp + * SubFunction: NA + * FunctionPoints: DumpUtils ShowHelp + */ +HWTEST_F(DumpUtilsTest, ShowHelp_001, TestSize.Level1) +{ + TAG_LOGI(AAFwkTag::TEST, "DumpUtilsTest ShowHelp_001 start"); + std::string result; + DumpUtils::ShowHelp(result); + + // Check that help text contains expected content + EXPECT_FALSE(result.empty()); + EXPECT_NE(result.find("Usage:"), std::string::npos); + EXPECT_NE(result.find("-h"), std::string::npos); + EXPECT_NE(result.find("help text for the tool"), std::string::npos); + EXPECT_NE(result.find("-a"), std::string::npos); + EXPECT_NE(result.find("-l"), std::string::npos); + EXPECT_NE(result.find("-i"), std::string::npos); + EXPECT_NE(result.find("-e"), std::string::npos); + EXPECT_NE(result.find("-p"), std::string::npos); + EXPECT_NE(result.find("-r"), std::string::npos); + EXPECT_NE(result.find("-d"), std::string::npos); + + // Verify that "information" is spelled correctly (not "infomation") + EXPECT_EQ(result.find("infomation"), std::string::npos); + EXPECT_NE(result.find("information"), std::string::npos); + + TAG_LOGI(AAFwkTag::TEST, "DumpUtilsTest ShowHelp_001 end"); +} + +/* + * Feature: DumpUtils + * Function: ShowHelp + * SubFunction: NA + * FunctionPoints: DumpUtils ShowHelp + */ +HWTEST_F(DumpUtilsTest, ShowHelp_002, TestSize.Level1) +{ + TAG_LOGI(AAFwkTag::TEST, "DumpUtilsTest ShowHelp_002 start"); + std::string result = "Initial content\n"; + DumpUtils::ShowHelp(result); + + // Check that help text is appended to existing content + EXPECT_NE(result.find("Initial content"), std::string::npos); + EXPECT_NE(result.find("Usage:"), std::string::npos); + + TAG_LOGI(AAFwkTag::TEST, "DumpUtilsTest ShowHelp_002 end"); +} } // namespace AAFwk } // namespace OHOS \ No newline at end of file