1 /* 2 * Copyright (c) 2021 Huawei Device Co., Ltd. 3 * Licensed under the Apache License, Version 2.0 (the "License"); 4 * you may not use this file except in compliance with the License. 5 * You may obtain a copy of the License at 6 * 7 * http://www.apache.org/licenses/LICENSE-2.0 8 * 9 * Unless required by applicable law or agreed to in writing, software 10 * distributed under the License is distributed on an "AS IS" BASIS, 11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 * See the License for the specific language governing permissions and 13 * limitations under the License. 14 */ 15 16 #ifndef FOUNDATION_AAFWK_STANDARD_TOOLS_AA_INCLUDE_ABILITY_COMMAND_H 17 #define FOUNDATION_AAFWK_STANDARD_TOOLS_AA_INCLUDE_ABILITY_COMMAND_H 18 19 #include "shell_command.h" 20 #include "ability_manager_interface.h" 21 22 namespace OHOS { 23 namespace AAFwk { 24 namespace { 25 const std::string TOOL_NAME = "aa"; 26 27 const std::string HELP_MSG = "usage: aa <command> <options>\n" 28 "These are common aa commands list:\n" 29 " help list available commands\n" 30 " start start ability with options\n" 31 " stop-service stop service with options\n" 32 " dump dump the ability info\n" 33 " force-stop <bundle-name> force stop the process with bundle name\n" 34 " test start the test framework with options\n"; 35 36 const std::string HELP_MSG_SCREEN = 37 "usage: aa screen <options>\n" 38 "options list:\n" 39 " -h, --help list available commands\n" 40 " -p, --power <state> power on or off with a state name\n"; 41 42 const std::string HELP_MSG_START = 43 "usage: aa start <options>\n" 44 "options list:\n" 45 " -h, --help list available commands\n" 46 " [-d <device-id>] -a <ability-name> -b <bundle-name> [-D] start ability with an element name\n"; 47 48 const std::string HELP_MSG_STOP_SERVICE = 49 "usage: aa stop-service <options>\n" 50 "options list:\n" 51 " -h, --help list available commands\n" 52 " [-d <device-id>] -a <ability-name> -b <bundle-name> stop service with an element name\n"; 53 54 const std::string HELP_MSG_DUMP = "usage: aa dump <options>\n" 55 "options list:\n" 56 " -h, --help list available commands\n" 57 " -a, --all dump all abilities\n" 58 " -s, --stack <number> dump the ability info of a specificed stack\n" 59 " -m, --mission <number> dump the ability info of a specificed mission\n" 60 " -l, --stack-list dump the mission list of every stack\n" 61 " -e, --serv dump the service abilities\n" 62 " -d, --data dump the data abilities\n"; 63 64 const std::string HELP_MSG_DUMPSYS = "usage: aa dump <options>\n" 65 "options list:\n" 66 " -h, --help list available commands\n" 67 " -a, --all dump all abilities\n" 68 " -l, --mission-list dump mission list\n" 69 " -i, --ability dump abilityRecordId\n" 70 " -e, --extension dump elementName (API7 ExtensionRecords," 71 "API8 serviceAbilityRecords)\n" 72 " -p, --pending dump pendingWantRecordId\n" 73 " -r, --process dump process\n" 74 " -d, --data dump the data abilities\n" 75 " -u, --userId userId\n" 76 " -c, --client client\n" 77 " -c, -u are auxiliary parameters and cannot be used alone\n" 78 " The original -s parameter is invalid\n" 79 " The original -m parameter is invalid\n"; 80 81 const std::string HELP_MSG_TEST = 82 "usage: aa test <options>\n" 83 "options list:\n" 84 " -h, --help list available commands\n" 85 " -b <bundle-name> -s unittest <test-runner> start the test framework with options\n" 86 " [-p <package-name>] the name of package with test-runner, " 87 "required for the FA model\n" 88 " [-m <module-name>] the name of module with test-runner, " 89 "required for the STAGE model\n" 90 " [-s class <test-class>]\n" 91 " [-s level <test-level>]\n" 92 " [-s size <test-size>]\n" 93 " [-s testType <test-testType>]\n" 94 " [-s timeout <test-timeout>]\n" 95 " [-s <any-key> <any-value>]\n" 96 " [-w <wait-time>]\n" 97 " [-D]\n"; 98 99 const std::string HELP_MSG_FORCE_STOP = "usage: aa force-stop <bundle-name>\n"; 100 101 const std::string HELP_MSG_NO_ABILITY_NAME_OPTION = "error: -a <ability-name> is expected"; 102 const std::string HELP_MSG_NO_BUNDLE_NAME_OPTION = "error: -b <bundle-name> is expected"; 103 104 const std::string STRING_START_ABILITY_OK = "start ability successfully."; 105 const std::string STRING_START_ABILITY_NG = "error: failed to start ability."; 106 107 const std::string STRING_STOP_SERVICE_ABILITY_OK = "stop service ability successfully."; 108 const std::string STRING_STOP_SERVICE_ABILITY_NG = "error: failed to stop service ability."; 109 110 const std::string STRING_SCREEN_POWER_ON = "on"; 111 112 const std::string STRING_SCREEN_POWER_ON_OK = "power on screen successfully."; 113 const std::string STRING_SCREEN_POWER_ON_NG = "error: failed to power on screen."; 114 const std::string STRING_SCREEN_POWER_OFF_OK = "power off screen successfully."; 115 const std::string STRING_SCREEN_POWER_OFF_NG = "error: failed to power off screen."; 116 117 const std::string STRING_FORCE_STOP_OK = "force stop process successfully."; 118 const std::string STRING_FORCE_STOP_NG = "error: failed to force stop process."; 119 120 const std::string STRING_START_USER_TEST_OK = "start user test successfully."; 121 const std::string STRING_START_USER_TEST_NG = "error: failed to start user test."; 122 123 const int USER_TEST_COMMAND_START_INDEX = 2; 124 const int USER_TEST_COMMAND_PARAMS_NUM = 2; 125 const int TIME_RATE_MS = 1000; 126 127 const int NUMBER_TWO = 2; 128 const int NUMBER_ONE = 1; 129 130 const std::string DEBUG_VALUE = "true"; 131 } // namespace 132 133 class AbilityManagerShellCommand : public ShellCommand { 134 public: 135 AbilityManagerShellCommand(int argc, char *argv[]); ~AbilityManagerShellCommand()136 ~AbilityManagerShellCommand() override 137 {} 138 139 ErrCode CreateMessageMap() override; 140 bool IsTestCommandIntegrity(const std::map<std::string, std::string> ¶ms); 141 ErrCode StartUserTest(const std::map<std::string, std::string> ¶ms, const bool isDebug); 142 143 private: 144 ErrCode CreateCommandMap() override; 145 ErrCode init() override; 146 147 ErrCode RunAsHelpCommand(); 148 ErrCode RunAsScreenCommand(); 149 ErrCode RunAsStartAbility(); 150 ErrCode RunAsStopService(); 151 ErrCode RunAsDumpCommand(); 152 ErrCode RunAsDumpsysCommand(); 153 ErrCode RunAsForceStop(); 154 sptr<IAbilityManager> GetAbilityManagerService(); 155 156 ErrCode RunAsDumpCommandOptopt(); 157 ErrCode MakeWantFromCmd(Want &want, std::string &windowMode); 158 ErrCode RunAsTestCommand(); 159 ErrCode TestCommandError(const std::string &info); 160 }; 161 } // namespace AAFwk 162 } // namespace OHOS 163 164 #endif // FOUNDATION_AAFWK_STANDARD_TOOLS_AA_INCLUDE_ABILITY_COMMAND_H 165