• 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 FOUNDATION_APPEXECFWK_STANDARD_TOOLS_BM_INCLUDE_BUNDLE_COMMAND_H
17 #define FOUNDATION_APPEXECFWK_STANDARD_TOOLS_BM_INCLUDE_BUNDLE_COMMAND_H
18 
19 #include "shell_command.h"
20 #include "bundle_mgr_interface.h"
21 #include "bundle_installer_interface.h"
22 
23 namespace OHOS {
24 namespace AppExecFwk {
25 namespace {
26 const std::string TOOL_NAME = "bm";
27 
28 const std::string HELP_MSG = "usage: bm <command> <options>\n"
29                              "These are common bm commands list:\n"
30                              "  help         list available commands\n"
31                              "  install      install a bundle with options\n"
32                              "  uninstall    uninstall a bundle with options\n"
33                              "  dump         dump the bundle info\n"
34                              "  clean        clean the bundle data\n"
35                              "  enable       enable the bundle\n"
36                              "  disable      disable the bundle\n"
37                              "  get          obtain device udid\n"
38                              "  quickfix     quick fix, including query and install\n"
39                              "  compile      Compile the software package\n"
40                              "  dump-overlay dump overlay info of the specific overlay bundle\n"
41                              "  dump-target-overlay dump overlay info of the specific target bundle\n"
42                              "  dump-dependencies dump dependencies by given bundle name and module name\n"
43                              "  dump-shared dump inter-application shared library information by bundle name\n";
44 
45 const std::string HELP_MSG_USER_MODE = "usage: bm <command> <options>\n"
46                              "These are common bm commands list:\n"
47                              "  help         list available commands\n"
48                              "  install      install a bundle with options\n"
49                              "  uninstall    uninstall a bundle with options\n"
50                              "  dump         dump the bundle info\n"
51                              "  get          obtain device udid\n"
52                              "  quickfix     quick fix, including query and install\n"
53                              "  compile      Compile the software package\n"
54                              "  dump-overlay dump overlay info of the specific overlay bundle\n"
55                              "  dump-target-overlay dump overlay info of the specific target bundle\n"
56                              "  dump-dependencies dump dependencies by given bundle name and module name\n"
57                              "  dump-shared dump inter-application shared library information by bundle name\n";
58 
59 const std::string HELP_MSG_COMPILE =
60     "usage: bm compile [-m mode] [-r reset] (bundle-name | -a)\n"
61     "options list:\n"
62     "  -h, --help                           list available commands.\n"
63     "  -m, --mode <mode-name>               select partial or full mode.\n"
64     "  -r, --reset                          clear bundle configuration file data.\n"
65     "  -a, --all                            compile or reset all software packages.\n";
66 
67 const std::string HELP_MSG_INSTALL =
68     "usage: bm install <options>\n"
69     "options list:\n"
70     "  -h, --help                                                     list available commands\n"
71     "  -p, --bundle-path <file-path>                                  install a hap or hsp by a specified path\n"
72     "  -p, --bundle-path <file-path> <file-path> ...                  install one bundle by some hap or hsp paths\n"
73     "  -p, --bundle-path <bundle-direction>                           install one bundle by a direction,\n"
74     "                                                                    under which are some hap or hsp files\n"
75     "  -r -p <bundle-file-path>                                       replace an existing bundle\n"
76     "  -r --bundle-path <bundle-file-path>                            replace an existing bundle\n"
77     "  -s, --shared-bundle-dir-path <shared-bundle-dir-path>          install inter-application hsp files\n"
78     "  -u, --user-id <user-id>                                        specify a user id\n"
79     "  -w, --waitting-time <waitting-time>                            specify waitting time for installation,\n"
80     "                                                                    the minimum waitting time is 180s,\n"
81     "                                                                    the maximum waitting time is 600s\n";
82 
83 const std::string HELP_MSG_UNINSTALL =
84     "usage: bm uninstall <options>\n"
85     "options list:\n"
86     "  -h, --help                           list available commands\n"
87     "  -n, --bundle-name <bundle-name>      uninstall a bundle by bundle name\n"
88     "  -m, --module-name <module-name>      uninstall a module by module name\n"
89     "  -u, --user-id <user-id>              specify a user id\n"
90     "  -k, --keep-data                      keep the user data after uninstall\n"
91     "  -s, --shared                         uninstall inter-application shared library\n"
92     "  -v, --version                        uninstall a inter-application shared library by versionCode\n";
93 
94 const std::string HELP_MSG_UNINSTALL_SHARE =
95     "usage: bm uninstall-shared <options>\n"
96     "options list:\n"
97     "  -h, --help                           list available commands\n"
98     "  -n, --bundle-name <bundle-name>      uninstall a share library by bundle name\n"
99     "  -v, --version <versionCode>          uninstall a share library by versionCode\n";
100 
101 const std::string HELP_MSG_DUMP =
102     "usage: bm dump <options>\n"
103     "options list:\n"
104     "  -h, --help                           list available commands\n"
105     "  -a, --all                            list all bundles in system\n"
106     "  -n, --bundle-name <bundle-name>      list the bundle info by a bundle name\n"
107     "  -s, --shortcut-info                  list the shortcut info\n"
108     "  -d, --device-id <device-id>          specify a device id\n"
109     "  -u, --user-id <user-id>              specify a user id\n";
110 
111 const std::string HELP_MSG_CLEAN =
112     "usage: bm clean <options>\n"
113     "options list:\n"
114     "  -h, --help                                      list available commands\n"
115     "  -n, --bundle-name  <bundle-name>                bundle name\n"
116     "  -c, --cache                                     clean bundle cache files by bundle name\n"
117     "  -d, --data                                      clean bundle data files by bundle name\n"
118     "  -u, --user-id <user-id>                         specify a user id\n";
119 
120 const std::string HELP_MSG_ENABLE =
121     "usage: bm enable <options>\n"
122     "options list:\n"
123     "  -h, --help                             list available commands\n"
124     "  -n, --bundle-name  <bundle-name>       enable bundle by bundle name\n"
125     "  -a, --ability-name <ability-name>      enable ability by ability name\n"
126     "  -u, --user-id <user-id>                specify a user id\n";
127 
128 const std::string HELP_MSG_DISABLE =
129     "usage: bm disable <options>\n"
130     "options list:\n"
131     "  -h, --help                             list available commands\n"
132     "  -n, --bundle-name  <bundle-name>       disable bundle by bundle name\n"
133     "  -a, --ability-name <ability-name>      disable ability by ability name\n"
134     "  -u, --user-id <user-id>                specify a user id\n";
135 
136 const std::string HELP_MSG_GET =
137     "usage: bm get <options>\n"
138     "options list:\n"
139     "  -u, --udid                             obtain udid of the current device\n";
140 
141 const std::string HELP_MSG_QUICK_FIX =
142     "usage: bm quickfix <options>\n"
143     "options list:\n"
144     "-h, --help                                   list available commands\n"
145     "-q, --query                                  indicates query quickfix, used with -b or --bundle-name\n"
146     "-b, --bundle-name <bundle-name>              query quickfix status and information by a specified bundle name\n"
147     "-d, --debug                                  apply a quickfix debug mode\n"
148     "-a, --apply                                  indicates apply quickfix, used with -f or --file-path\n"
149     "-f, --file-path <file-path>                  apply a quickfix file by a specified path\n"
150     "-f, --file-path <file-path> <file-path> ...  apply some quickfix files of one bundle\n"
151     "-f, --file-path <bundle-direction>           apply quickfix files by direction, under which are quickfix files\n";
152 
153 const std::string HELP_MSG_OVERLAY =
154     "usage: bm dump-overlay <options>\n"
155     "options list:\n"
156     "  -h, --help                                         list available commands\n"
157     "  -b, --bundle-name <bundle-name>                    bundle name of the overlay bundle\n"
158     "  -m, --module-name <module-name>                    module name of the overlay bundle\n"
159     "  -t, --target-module-name <target-module-name>      target module name of overlay bundle\n"
160     "  -u, --user-id <user-id>                            specify a user id\n";
161 
162 const std::string HELP_MSG_OVERLAY_TARGET =
163     "usage: bm dump-target-overlay <options>\n"
164     "options list:\n"
165     "  -h, --help                                         list available commands\n"
166     "  -b, --bundle-name <bundle-name>                    bundle name of the target overlay bundle\n"
167     "  -m, --module-name <module-name>                    module name of the target overlay bundle\n"
168     "  -u, --user-id <user-id>                            specify a user id\n";
169 
170 const std::string HELP_MSG_DUMP_SHARED =
171     "usage: bm dump-shared <options>\n"
172     "eg:bm dump-shared -n <bundle-name> \n"
173     "options list:\n"
174     "  -h, --help                             list available commands\n"
175     "  -a, --all                              list all inter-application shared library name in system\n"
176     "  -n, --bundle-name  <bundle-name>       dump inter-application shared library information by bundleName\n";
177 
178 const std::string HELP_MSG_DUMP_SHARED_DEPENDENCIES =
179     "usage: bm dump-dependencies <options>\n"
180     "eg:bm dump-dependencies -n <bundle-name> -m <module-name> \n"
181     "options list:\n"
182     "  -h, --help                             list available commands\n"
183     "  -n, --bundle-name  <bundle-name>       dump dependencies by bundleName and moduleName\n"
184     "  -m, --module-name  <module-name>       dump dependencies by bundleName and moduleName\n";
185 
186 const std::string STRING_INCORRECT_OPTION = "error: incorrect option";
187 const std::string HELP_MSG_NO_BUNDLE_PATH_OPTION =
188     "error: you must specify a bundle path with '-p' or '--bundle-path'.";
189 
190 const std::string HELP_MSG_NO_BUNDLE_NAME_OPTION =
191     "error: you must specify a bundle name with '-n' or '--bundle-name'.";
192 
193 const std::string STRING_INSTALL_BUNDLE_OK = "install bundle successfully.";
194 const std::string STRING_INSTALL_BUNDLE_NG = "error: failed to install bundle.";
195 
196 const std::string STRING_UNINSTALL_BUNDLE_OK = "uninstall bundle successfully.";
197 const std::string STRING_UNINSTALL_BUNDLE_NG = "error: failed to uninstall bundle.";
198 
199 const std::string HELP_MSG_NO_DATA_OR_CACHE_OPTION =
200     "error: you must specify '-c' or '-d' for 'bm clean' option.";
201 const std::string STRING_CLEAN_CACHE_BUNDLE_OK = "clean bundle cache files successfully.";
202 const std::string STRING_CLEAN_CACHE_BUNDLE_NG = "error: failed to clean bundle cache files.";
203 
204 const std::string STRING_CLEAN_DATA_BUNDLE_OK = "clean bundle data files successfully.";
205 const std::string STRING_CLEAN_DATA_BUNDLE_NG = "error: failed to clean bundle data files.";
206 
207 const std::string STRING_ENABLE_BUNDLE_OK = "enable bundle successfully.";
208 const std::string STRING_ENABLE_BUNDLE_NG = "error: failed to enable bundle.";
209 
210 const std::string STRING_DISABLE_BUNDLE_OK = "disable bundle successfully.";
211 const std::string STRING_DISABLE_BUNDLE_NG = "error: failed to disable bundle.";
212 
213 const std::string STRING_GET_UDID_OK = "udid of current device is :";
214 const std::string STRING_GET_UDID_NG = "error: failed to get udid";
215 
216 const std::string HELP_MSG_NO_REMOVABLE_OPTION =
217     "error: you must specify a bundle name with '-n' or '--bundle-name' \n"
218     "and a module name with '-m' or '--module-name' \n";
219 
220 const std::string HELP_MSG_DUMP_FAILED = "error: failed to get information and the parameters may be wrong.";
221 const std::string HELP_MSG_COMPILE_FAILED = "error: failed to get information and the parameters may be wrong.";
222 const std::string STRING_REQUIRE_CORRECT_VALUE = "error: option requires a correct value.\n";
223 
224 const std::string STRING_DUMP_OVERLAY_OK = "overlay info is:";
225 const std::string STRING_DUMP_OVERLAY_NG = "error: failed to get overlay info";
226 
227 const std::string STRING_DUMP_TARGET_OVERLAY_OK = "target overlay info is:";
228 const std::string STRING_DUMP_TARGET_OVERLAY_NG = "error: failed to get target overlay info";
229 const std::string MSG_ERR_BUNDLEMANAGER_OVERLAY_FEATURE_IS_NOT_SUPPORTED = "feature is not supported.\n";
230 const std::string COMPILE_SUCCESS_OK = "compile AOT success.\n";
231 const std::string COMPILE_RESET = "reset AOT success.\n";
232 } // namespace
233 
234 class BundleManagerShellCommand : public ShellCommand {
235 public:
236     BundleManagerShellCommand(int argc, char *argv[]);
~BundleManagerShellCommand()237     ~BundleManagerShellCommand() override
238     {}
239 
240 private:
241     ErrCode CreateCommandMap() override;
242     ErrCode CreateMessageMap() override;
243     ErrCode Init() override;
244 
245     ErrCode RunAsHelpCommand();
246     ErrCode RunAsInstallCommand();
247     ErrCode RunAsUninstallCommand();
248     ErrCode RunAsDumpCommand();
249     ErrCode RunAsCleanCommand();
250     ErrCode RunAsEnableCommand();
251     ErrCode RunAsDisableCommand();
252     ErrCode RunAsGetCommand();
253     ErrCode RunAsQuickFixCommand();
254     ErrCode RunAsDumpOverlay();
255     ErrCode RunAsDumpTargetOverlay();
256     ErrCode RunAsDumpSharedDependenciesCommand();
257     ErrCode RunAsDumpSharedCommand();
258     ErrCode RunAsCompileCommand();
259 
260     std::string CompileProcessAot(
261         const std::string &bundleName, const std::string &compileMode, bool isAllBundle) const;
262     std::string CompileReset(const std::string &bundleName, bool isAllBundle) const;
263 
264     std::string DumpBundleList(int32_t userId) const;
265     std::string DumpBundleInfo(const std::string &bundleName, int32_t userId) const;
266     std::string DumpShortcutInfos(const std::string &bundleName, int32_t userId) const;
267     std::string DumpDistributedBundleInfo(const std::string &deviceId, const std::string &bundleName);
268     std::string DumpDependentModuleNames(const std::string &bundleName, const std::string &moduleName) const;
269     std::string DumpSharedDependencies(const std::string &bundleName, const std::string &moduleName) const;
270     std::string DumpShared(const std::string &bundleName) const;
271     std::string DumpSharedAll() const;
272 
273     int32_t InstallOperation(const std::vector<std::string> &bundlePaths, InstallParam &installParam,
274         int32_t waittingTime) const;
275     int32_t UninstallOperation(const std::string &bundleName, const std::string &moduleName,
276                                InstallParam &installParam) const;
277     int32_t UninstallSharedOperation(const UninstallParam &uninstallParam) const;
278     std::string GetUdid() const;
279     bool IsInstallOption(int index) const;
280     void GetAbsPaths(const std::vector<std::string> &paths, std::vector<std::string> &absPaths) const;
281 
282     ErrCode GetBundlePath(const std::string& param, std::vector<std::string>& bundlePaths) const;
283 
284     bool CleanBundleCacheFilesOperation(const std::string &bundleName, int32_t userId) const;
285     bool CleanBundleDataFilesOperation(const std::string &bundleName, int32_t userId) const;
286 
287     bool SetApplicationEnabledOperation(const AbilityInfo &abilityInfo, bool isEnable, int32_t userId) const;
288     std::string DumpOverlayInfo(const std::string &bundleName, const std::string &moduleName,
289         const std::string &targetModuleName, int32_t userId);
290     std::string DumpTargetOverlayInfo(const std::string &bundleName, const std::string &moduleName, int32_t userId);
291     ErrCode ParseSharedDependenciesCommand(int32_t option, std::string &bundleName, std::string &moduleName);
292     ErrCode ParseSharedCommand(int32_t option, std::string &bundleName, bool &dumpSharedAll);
293 
294     sptr<IBundleMgr> bundleMgrProxy_;
295     sptr<IBundleInstaller> bundleInstallerProxy_;
296 };
297 }  // namespace AppExecFwk
298 }  // namespace OHOS
299 
300 #endif  // FOUNDATION_APPEXECFWK_STANDARD_TOOLS_BM_INCLUDE_BUNDLE_COMMAND_H