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_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 35 const std::string HELP_MSG_INSTALL = 36 "usage: bm install <options>\n" 37 "options list:\n" 38 " -h, --help list available commands\n" 39 " -p, --bundle-path <bundle-file-path> install a bundle in a specified path\n" 40 " -r -p <bundle-file-path> replace an existing bundle\n" 41 " -r --bundle-path <bundle-file-path> replace an existing bundle\n"; 42 43 const std::string HELP_MSG_UNINSTALL = "usage: bm uninstall <options>\n" 44 "options list:\n" 45 " -h, --help list available commands\n" 46 " -n, --bundle-name <bundle-name> [-m, --module-name <module-name>]\n" 47 " uninstall a bundle by a bundle name\n"; 48 49 const std::string HELP_MSG_DUMP = "usage: bm dump <options>\n" 50 "options list:\n" 51 " -h, --help list available commands\n" 52 " -a, --all list all bundles in system\n" 53 " -i, --bundle-info list all bundles info in system\n" 54 " -n, --bundle-name <bundle-name> list the bundle info by a bundle name\n"; 55 56 const std::string HELP_MSG_NO_BUNDLE_PATH_OPTION = 57 "error: you must specify a bundle path with '-p' or '--bundle-path'."; 58 59 const std::string HELP_MSG_NO_BUNDLE_NAME_OPTION = 60 "error: you must specify a bundle name with '-n' or '--bundle-name'."; 61 62 const std::string STRING_INSTALL_BUNDLE_OK = "install bundle successfully."; 63 const std::string STRING_INSTALL_BUNDLE_NG = "error: failed to install bundle."; 64 65 const std::string STRING_UNINSTALL_BUNDLE_OK = "uninstall bundle successfully."; 66 const std::string STRING_UNINSTALL_BUNDLE_NG = "error: failed to uninstall bundle."; 67 } // namespace 68 69 class BundleManagerShellCommand : public OHOS::AAFwk::ShellCommand { 70 public: 71 BundleManagerShellCommand(int argc, char *argv[]); ~BundleManagerShellCommand()72 ~BundleManagerShellCommand() override 73 {} 74 75 private: 76 ErrCode CreateCommandMap() override; 77 ErrCode CreateMessageMap() override; 78 ErrCode init() override; 79 80 sptr<IBundleMgr> GetBundleMgrProxy() const; 81 sptr<IBundleInstaller> GetInstallerProxy() const; 82 83 ErrCode RunAsHelpCommand(); 84 ErrCode RunAsInstallCommand(); 85 ErrCode RunAsUninstallCommand(); 86 ErrCode RunAsDumpCommand(); 87 88 std::string DumpBundleList() const; 89 std::string DumpBundleInfo() const; 90 std::string DumpBundleInfos() const; 91 92 int32_t InstallOperation(const std::string &bundlePath, InstallParam &installParam) const; 93 int32_t UninstallOperation(const std::string &bundleName, const std::string &moduleName) const; 94 95 sptr<IBundleMgr> bundleMgrProxy_; 96 sptr<IBundleInstaller> bundleInstallerProxy_; 97 }; 98 } // namespace AppExecFwk 99 } // namespace OHOS 100 101 #endif // FOUNDATION_APPEXECFWK_STANDARD_TOOLS_BM_INCLUDE_BUNDLE_COMMAND_H