/* * Copyright (c) 2021-2022 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 * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ #ifndef FOUNDATION_APPEXECFWK_STANDARD_TOOLS_BM_INCLUDE_BUNDLE_COMMAND_H #define FOUNDATION_APPEXECFWK_STANDARD_TOOLS_BM_INCLUDE_BUNDLE_COMMAND_H #include "shell_command.h" #include "bundle_mgr_interface.h" #include "bundle_installer_interface.h" namespace OHOS { namespace AppExecFwk { namespace { const std::string TOOL_NAME = "bm"; const std::string HELP_MSG = "usage: bm \n" "These are common bm commands list:\n" " help list available commands\n" " install install a bundle with options\n" " uninstall uninstall a bundle with options\n" " dump dump the bundle info\n" " dump-dependencies dump the dependent moduleNames by given bundle name and module name\n" " clean clean the bundle data\n" " enable enable the bundle\n" " disable disable the bundle\n" " get obtain device udid\n" " quickfix quick fix, including query and install\n"; const std::string HELP_MSG_INSTALL = "usage: bm install \n" "options list:\n" " -h, --help list available commands\n" " -p, --bundle-path install a hap or hsp by a specified path\n" " -p, --bundle-path ... install one bundle by some hap or hsp paths\n" " -p, --bundle-path install one bundle by a direction,\n" " under which are some hap or hsp files\n" " -r -p replace an existing bundle\n" " -r --bundle-path replace an existing bundle\n" " -u, --user-id specify a user id\n" " -w, --waitting-time specify waitting time for installation, the minimum\n" " waitting time is 5s, the maximum waitting\n" " time is 600s\n"; const std::string HELP_MSG_UNINSTALL = "usage: bm uninstall \n" "options list:\n" " -h, --help list available commands\n" " -n, --bundle-name uninstall a bundle by bundle name\n" " -m, --module-name uninstall a module by module name\n" " -u, --user-id specify a user id\n" " -k, --keep-data keep the user data after uninstall\n"; const std::string HELP_MSG_DUMP = "usage: bm dump \n" "options list:\n" " -h, --help list available commands\n" " -a, --all list all bundles in system\n" " -n, --bundle-name list the bundle info by a bundle name\n" " -s, --shortcut-info list the shortcut info\n" " -d, --device-id specify a device id\n" " -u, --user-id specify a user id\n"; const std::string HELP_MSG_CLEAN = "usage: bm clean \n" "options list:\n" " -h, --help list available commands\n" " -n, --bundle-name bundle name\n" " -c, --cache clean bundle cache files by bundle name\n" " -d, --data clean bundle data files by bundle name\n" " -u, --user-id specify a user id\n"; const std::string HELP_MSG_ENABLE = "usage: bm enable \n" "options list:\n" " -h, --help list available commands\n" " -n, --bundle-name enable bundle by bundle name\n" " -a, --ability-name enable ability by ability name\n" " -u, --user-id specify a user id\n"; const std::string HELP_MSG_DISABLE = "usage: bm disable \n" "options list:\n" " -h, --help list available commands\n" " -n, --bundle-name disable bundle by bundle name\n" " -a, --ability-name disable ability by ability name\n" " -u, --user-id specify a user id\n"; const std::string HELP_MSG_GET = "usage: bm get \n" "options list:\n" " -u, --udid obtain udid of the current device\n"; const std::string HELP_MSG_DUMP_DEPENDENCIES = "usage: bm dump-dependencies \n" "eg:bm dump-dependencies -n -m \n" "options list:\n" " -h, --help list available commands\n" " -n, --bundle-name dump dependent moduleNames by bundleName and moduleName\n" " -m, --module-name dump dependent moduleNames by bundleName and moduleName\n"; const std::string HELP_MSG_QUICK_FIX = "usage: bm quickfix \n" "options list:\n" "-h, --help list available commands\n" "-q, --query indicates query quickfix, used with -b or --bundle-name\n" "-b, --bundle-name query quickfix status and information by a specified bundle name\n" "-a, --apply indicates apply quickfix, used with -f or --file-path\n" "-f, --file-path apply a quickfix file by a specified path\n" "-f, --file-path ... apply some quickfix files of one bundle\n" "-f, --file-path apply quickfix files by direction, under which are quickfix files\n"; const std::string STRING_INCORRECT_OPTION = "error: incorrect option"; const std::string HELP_MSG_NO_BUNDLE_PATH_OPTION = "error: you must specify a bundle path with '-p' or '--bundle-path'."; const std::string HELP_MSG_NO_BUNDLE_NAME_OPTION = "error: you must specify a bundle name with '-n' or '--bundle-name'."; const std::string STRING_INSTALL_BUNDLE_OK = "install bundle successfully."; const std::string STRING_INSTALL_BUNDLE_NG = "error: failed to install bundle."; const std::string STRING_UNINSTALL_BUNDLE_OK = "uninstall bundle successfully."; const std::string STRING_UNINSTALL_BUNDLE_NG = "error: failed to uninstall bundle."; const std::string HELP_MSG_NO_DATA_OR_CACHE_OPTION = "error: you must specify '-c' or '-d' for 'bm clean' option."; const std::string STRING_CLEAN_CACHE_BUNDLE_OK = "clean bundle cache files successfully."; const std::string STRING_CLEAN_CACHE_BUNDLE_NG = "error: failed to clean bundle cache files."; const std::string STRING_CLEAN_DATA_BUNDLE_OK = "clean bundle data files successfully."; const std::string STRING_CLEAN_DATA_BUNDLE_NG = "error: failed to clean bundle data files."; const std::string STRING_ENABLE_BUNDLE_OK = "enable bundle successfully."; const std::string STRING_ENABLE_BUNDLE_NG = "error: failed to enable bundle."; const std::string STRING_DISABLE_BUNDLE_OK = "disable bundle successfully."; const std::string STRING_DISABLE_BUNDLE_NG = "error: failed to disable bundle."; const std::string STRING_GET_UDID_OK = "udid of current device is :"; const std::string STRING_GET_UDID_NG = "error: failed to get udid"; const std::string HELP_MSG_NO_REMOVABLE_OPTION = "error: you must specify a bundle name with '-n' or '--bundle-name' \n" "and a module name with '-m' or '--module-name' \n"; const std::string HELP_MSG_DUMP_FAILED = "error: failed to get information and the parameters may be wrong."; const std::string STRING_REQUIRE_CORRECT_VALUE = "error: option requires a correct value.\n"; } // namespace class BundleManagerShellCommand : public ShellCommand { public: BundleManagerShellCommand(int argc, char *argv[]); ~BundleManagerShellCommand() override {} private: ErrCode CreateCommandMap() override; ErrCode CreateMessageMap() override; ErrCode Init() override; ErrCode RunAsHelpCommand(); ErrCode RunAsInstallCommand(); ErrCode RunAsUninstallCommand(); ErrCode RunAsDumpCommand(); ErrCode RunAsDumpDependenciesCommand(); ErrCode RunAsCleanCommand(); ErrCode RunAsEnableCommand(); ErrCode RunAsDisableCommand(); ErrCode RunAsGetCommand(); ErrCode RunAsQuickFixCommand(); std::string DumpBundleList(int32_t userId) const; std::string DumpBundleInfo(const std::string &bundleName, int32_t userId) const; std::string DumpShortcutInfos(const std::string &bundleName, int32_t userId) const; std::string DumpDistributedBundleInfo(const std::string &deviceId, const std::string &bundleName); std::string DumpDependentModuleNames(const std::string &bundleName, const std::string &moduleName) const; int32_t InstallOperation(const std::vector &bundlePaths, InstallParam &installParam, int32_t waittingTime) const; int32_t UninstallOperation(const std::string &bundleName, const std::string &moduleName, InstallParam &installParam) const; std::string GetUdid() const; ErrCode GetBundlePath(const std::string& param, std::vector& bundlePaths) const; bool CleanBundleCacheFilesOperation(const std::string &bundleName, int32_t userId) const; bool CleanBundleDataFilesOperation(const std::string &bundleName, int32_t userId) const; bool SetApplicationEnabledOperation(const AbilityInfo &abilityInfo, bool isEnable, int32_t userId) const; ErrCode ParseDependenciesCommand(int32_t option, std::string &bundleName, std::string &moduleName); sptr bundleMgrProxy_; sptr bundleInstallerProxy_; }; } // namespace AppExecFwk } // namespace OHOS #endif // FOUNDATION_APPEXECFWK_STANDARD_TOOLS_BM_INCLUDE_BUNDLE_COMMAND_H