• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2021-2022 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 OHOS_ABILITY_RUNTIME_ABILITY_COMMAND_H
17 #define OHOS_ABILITY_RUNTIME_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 #ifdef ABILITY_COMMAND_FOR_TEST
35                              "  test                        start the test framework with options\n"
36                              "  ApplicationNotResponding     Pass in pid with options\n"
37                              "  block-ability <ability-record-id>       block ability with ability record id\n"
38                              "  block-ams-service                       block ams service\n"
39                              "  block-app-service                       block app service\n";
40 #else
41                              "  test                        start the test framework with options\n";
42 #endif
43 
44 const std::string HELP_MSG_SCREEN =
45     "usage: aa screen <options>\n"
46     "options list:\n"
47     "  -h, --help                                                   list available commands\n"
48     "  -p, --power <state>                                          power on or off with a state name\n";
49 
50 const std::string HELP_ApplicationNotResponding =
51     "usage: aa ApplicationNotResponding <options>\n"
52     "options list:\n"
53     "  -h, --help                   list available commands\n"
54     "  -p, --pid                    Pass in pid with option\n";
55 
56 const std::string HELP_MSG_START =
57     "usage: aa start <options>\n"
58     "options list:\n"
59     "  -h, --help                                                   list available commands\n"
60     "  [-d <device-id>] -a <ability-name> -b <bundle-name> [-m <module-name>] [-D] "
61     "  start ability with an element name\n";
62 
63 const std::string HELP_MSG_STOP_SERVICE =
64     "usage: aa stop-service <options>\n"
65     "options list:\n"
66     "  -h, --help                                                   list available commands\n"
67     "  [-d <device-id>] -a <ability-name> -b <bundle-name> [-m <module-name>] "
68     "  stop service with an element name\n";
69 
70 const std::string HELP_MSG_DUMPSYS = "usage: aa dump <options>\n"
71                                   "options list:\n"
72                                   "  -h, --help                   list available commands\n"
73                                   "  -a, --all                    dump all abilities\n"
74                                   "  -l, --mission-list           dump mission list\n"
75                                   "  -i, --ability                dump abilityRecordId\n"
76                                   "  -e, --extension              dump elementName (FA: serviceAbilityRecords,"
77                                                                   "Stage: ExtensionRecords)\n"
78                                   "  -p, --pending                dump pendingWantRecordId\n"
79                                   "  -r, --process                dump process\n"
80                                   "  -d, --data                   dump the data abilities\n"
81                                   "  -u, --userId                 userId\n"
82                                   "  -c, --client                 client\n"
83                                   "  -c, -u are auxiliary parameters and cannot be used alone\n"
84                                   "  The original -s parameter is invalid\n"
85                                   "  The original -m parameter is invalid\n";
86 
87 const std::string HELP_MSG_TEST =
88     "usage: aa test <options>\n"
89     "options list:\n"
90     "  -h, --help                                             list available commands\n"
91     "  -b <bundle-name> -s unittest <test-runner>             start the test framework with options\n"
92     "                  [-p <package-name>]                    the name of package with test-runner, "
93     "required for the FA model\n"
94     "                  [-m <module-name>]                     the name of module with test-runner, "
95     "required for the STAGE model\n"
96     "                  [-s class <test-class>]\n"
97     "                  [-s level <test-level>]\n"
98     "                  [-s size <test-size>]\n"
99     "                  [-s testType <test-testType>]\n"
100     "                  [-s timeout <test-timeout>]\n"
101     "                  [-s <any-key> <any-value>]\n"
102     "                  [-w <wait-time>]\n"
103     "                  [-D]\n";
104 
105 const std::string HELP_MSG_FORCE_STOP = "usage: aa force-stop <bundle-name>\n";
106 const std::string HELP_MSG_BLOCK_ABILITY = "usage: aa block-ability <abilityrecordid>\n";
107 const std::string HELP_MSG_FORCE_TIMEOUT =
108     "usage: aa force-timeout <ability-name> <INITIAL|INACTIVE|COMMAND|FOREGROUND|BACKGROUND|TERMINATING>\n"
109     "usage: aa force-timeout clean.";
110 const std::string HELP_MSG_FORCE_TIMEOUT_CLEAN = "clean";
111 
112 const std::string HELP_MSG_NO_ABILITY_NAME_OPTION = "error: -a <ability-name> is expected";
113 const std::string HELP_MSG_NO_BUNDLE_NAME_OPTION = "error: -b <bundle-name> is expected";
114 
115 const std::string STRING_START_ABILITY_OK = "start ability successfully.";
116 const std::string STRING_START_ABILITY_NG = "error: failed to start ability.";
117 
118 const std::string STRING_STOP_SERVICE_ABILITY_OK = "stop service ability successfully.";
119 const std::string STRING_STOP_SERVICE_ABILITY_NG = "error: failed to stop service ability.";
120 
121 const std::string STRING_FORCE_STOP_OK = "force stop process successfully.";
122 const std::string STRING_FORCE_STOP_NG = "error: failed to force stop process.";
123 
124 const std::string STRING_START_USER_TEST_NG = "error: failed to start user test.";
125 const std::string STRING_USER_TEST_STARTED = "user test started.";
126 const std::string STRING_USER_TEST_FINISHED = "user test finished.";
127 
128 const std::string STRING_BLOCK_ABILITY_OK = "block ability successfully.";
129 const std::string STRING_BLOCK_ABILITY_NG = "error: failed to block stop ability.";
130 
131 const std::string STRING_BLOCK_AMS_SERVICE_OK = "block ams service successfully.";
132 const std::string STRING_BLOCK_AMS_SERVICE_NG = "error: failed to block ams service.";
133 
134 const std::string STRING_BLOCK_APP_SERVICE_OK = "block app service successfully.";
135 const std::string STRING_BLOCK_APP_SERVICE_NG = "error: failed to block app service.";
136 
137 const int USER_TEST_COMMAND_START_INDEX = 2;
138 const int USER_TEST_COMMAND_PARAMS_NUM = 2;
139 const int TIME_RATE_MS = 1000;
140 const std::string STRING_FORCE_TIMEOUT_OK = "force ability timeout successfully.";
141 const std::string STRING_FORCE_TIMEOUT_NG = "error: failed to force ability timeout.";
142 
143 const int NUMBER_TWO = 2;
144 const int NUMBER_ONE = 1;
145 
146 const std::string DEBUG_VALUE = "true";
147 
148 const std::string STRING_TEST_REGEX_INTEGER_NUMBERS = "^(0|[1-9][0-9]*|-[1-9][0-9]*)$";
149 }  // namespace
150 
151 class AbilityManagerShellCommand : public ShellCommand {
152 public:
153     AbilityManagerShellCommand(int argc, char *argv[]);
~AbilityManagerShellCommand()154     ~AbilityManagerShellCommand() override
155     {}
156 
157     ErrCode CreateMessageMap() override;
158     bool IsTestCommandIntegrity(const std::map<std::string, std::string> &params);
159     ErrCode StartUserTest(const std::map<std::string, std::string> &params);
160 
161 private:
162     ErrCode CreateCommandMap() override;
163     ErrCode init() override;
164 
165     ErrCode RunAsHelpCommand();
166     ErrCode RunAsScreenCommand();
167     ErrCode RunAsStartAbility();
168     ErrCode RunAsStopService();
169     ErrCode RunAsDumpsysCommand();
170     ErrCode RunAsForceStop();
171     #ifdef ABILITY_COMMAND_FOR_TEST
172     ErrCode RunForceTimeoutForTest();
173     ErrCode RunAsSendAppNotRespondingProcessID();
174     ErrCode RunAsBlockAbilityCommand();
175     ErrCode RunAsBlockAmsServiceCommand();
176     ErrCode RunAsBlockAppServiceCommand();
177     ErrCode RunAsSendAppNotRespondingWithUnknownOption();
178     ErrCode RunAsSendAppNotRespondingWithOption(int32_t option, std::string &pid);
179     #endif
180     sptr<IAbilityManager> GetAbilityManagerService();
181 
182     ErrCode MakeWantFromCmd(Want &want, std::string &windowMode);
183     ErrCode RunAsTestCommand();
184     ErrCode TestCommandError(const std::string &info);
185 };
186 }  // namespace AAFwk
187 }  // namespace OHOS
188 
189 #endif  // OHOS_ABILITY_RUNTIME_ABILITY_COMMAND_H
190