1 /* 2 * Copyright (c) 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_BUNDLEMANAGER_BUNDLE_FRAMEWORK_BUNDLE_TOOL_INCLUDE_BUNDLE_TEST_TOOL_H 17 #define FOUNDATION_BUNDLEMANAGER_BUNDLE_FRAMEWORK_BUNDLE_TOOL_INCLUDE_BUNDLE_TEST_TOOL_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 class BundleTestTool : public ShellCommand { 26 public: 27 BundleTestTool(int argc, char *argv[]); 28 ~BundleTestTool(); 29 30 private: 31 ErrCode CreateCommandMap() override; 32 ErrCode CreateMessageMap() override; 33 ErrCode Init() override; 34 void CreateQuickFixMsgMap(std::unordered_map<int32_t, std::string> &quickFixMsgMap); 35 std::string GetResMsg(int32_t code); 36 std::string GetResMsg(int32_t code, const std::shared_ptr<QuickFixResult> &quickFixRes); 37 38 ErrCode RunAsHelpCommand(); 39 ErrCode RunAsCheckCommand(); 40 ErrCode CheckOperation(int userId, std::string deviceId, std::string bundleName, 41 std::string moduleName, std::string abilityName); 42 ErrCode RunAsSetRemovableCommand(); 43 ErrCode RunAsGetRemovableCommand(); 44 ErrCode RunAsInstallSandboxCommand(); 45 ErrCode RunAsUninstallSandboxCommand(); 46 ErrCode RunAsDumpSandboxCommand(); 47 ErrCode RunAsGetStringCommand(); 48 ErrCode RunAsGetIconCommand(); 49 ErrCode RunAsAddInstallRuleCommand(); 50 ErrCode RunAsGetInstallRuleCommand(); 51 ErrCode RunAsDeleteInstallRuleCommand(); 52 ErrCode RunAsCleanInstallRuleCommand(); 53 ErrCode RunAsAddAppRunningRuleCommand(); 54 ErrCode RunAsDeleteAppRunningRuleCommand(); 55 ErrCode RunAsCleanAppRunningRuleCommand(); 56 ErrCode RunAsGetAppRunningControlRuleCommand(); 57 ErrCode RunAsGetAppRunningControlRuleResultCommand(); 58 ErrCode RunAsDeployQuickFix(); 59 ErrCode RunAsSwitchQuickFix(); 60 ErrCode RunAsDeleteQuickFix(); 61 ErrCode RunAsSetDebugMode(); 62 ErrCode RunAsGetBundleStats(); 63 64 std::condition_variable cv_; 65 std::mutex mutex_; 66 bool dataReady_ {false}; 67 68 sptr<IBundleMgr> bundleMgrProxy_; 69 sptr<IBundleInstaller> bundleInstallerProxy_; 70 71 bool CheckRemovableErrorOption(int option, int counter, const std::string &commandName); 72 bool CheckRemovableCorrectOption(int option, const std::string &commandName, int &isRemovable, std::string &name); 73 bool SetIsRemovableOperation(const std::string &bundleName, const std::string &moduleName, int isRemovable) const; 74 bool GetIsRemovableOperation( 75 const std::string &bundleName, const std::string &moduleName, std::string &result) const; 76 bool CheckSandboxErrorOption(int option, int counter, const std::string &commandName); 77 bool CheckGetStringCorrectOption(int option, const std::string &commandName, int &temp, std::string &name); 78 bool CheckGetIconCorrectOption(int option, const std::string &commandName, int &temp, std::string &name); 79 ErrCode CheckAddInstallRuleCorrectOption(int option, const std::string &commandName, 80 std::vector<std::string> &appIds, int &controlRuleType, int &userId, int &euid); 81 ErrCode CheckGetInstallRuleCorrectOption(int option, const std::string &commandName, int &controlRuleType, 82 int &userId, int &euid); 83 ErrCode CheckDeleteInstallRuleCorrectOption(int option, const std::string &commandName, 84 int &controlRuleType, std::vector<std::string> &appIds, int &userId, int &euid); 85 ErrCode CheckCleanInstallRuleCorrectOption(int option, const std::string &commandName, 86 int &controlRuleType, int &userId, int &euid); 87 ErrCode CheckAppRunningRuleCorrectOption(int option, const std::string &commandName, 88 std::vector<AppRunningControlRule> &controlRule, int &userId, int &euid); 89 ErrCode CheckCleanAppRunningRuleCorrectOption(int option, const std::string &commandName, int &userId, int &euid); 90 ErrCode CheckGetAppRunningRuleCorrectOption(int option, const std::string &commandName, 91 int32_t &userId, int &euid); 92 ErrCode CheckGetAppRunningRuleResultCorrectOption(int option, const std::string &commandName, 93 std::string &bundleName, int32_t &userId, int &euid); 94 bool CheckSandboxCorrectOption(int option, const std::string &commandName, int &data, std::string &bundleName); 95 ErrCode InstallSandboxOperation( 96 const std::string &bundleName, const int32_t userId, const int32_t dlpType, int32_t &appIndex) const; 97 ErrCode UninstallSandboxOperation( 98 const std::string &bundleName, const int32_t appIndex, const int32_t userId) const; 99 ErrCode DumpSandboxBundleInfo(const std::string &bundleName, const int32_t appIndex, const int32_t userId, 100 std::string &dumpResults); 101 ErrCode StringToInt(std::string option, const std::string &commandName, int &temp, bool &result); 102 ErrCode DeployQuickFix(const std::vector<std::string> &quickFixPaths, 103 std::shared_ptr<QuickFixResult> &quickFixRes); 104 ErrCode SwitchQuickFix(const std::string &bundleName, int32_t enable, 105 std::shared_ptr<QuickFixResult> &quickFixRes); 106 ErrCode DeleteQuickFix(const std::string &bundleName, std::shared_ptr<QuickFixResult> &quickFixRes); 107 ErrCode GetQuickFixPath(int32_t index, std::vector<std::string>& quickFixPaths) const; 108 ErrCode SetDebugMode(int32_t debugMode); 109 bool GetBundleStats(const std::string &bundleName, int32_t userId, std::string& msg); 110 }; 111 } // namespace AppExecFwk 112 } // namespace OHOS 113 114 #endif // FFOUNDATION_BUNDLEMANAGER_BUNDLE_FRAMEWORK_BUNDLE_TOOL_INCLUDE_BUNDLE_TEST_TOOL_H