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_event_callback_host.h" 21 #include "bundle_mgr_interface.h" 22 #include "bundle_installer_interface.h" 23 #ifdef DISTRIBUTED_BUNDLE_FRAMEWORK 24 #include "distributed_bms_interface.h" 25 #endif 26 27 namespace OHOS { 28 namespace AppExecFwk { 29 class BundleEventCallbackImpl : public BundleEventCallbackHost { 30 public: 31 BundleEventCallbackImpl(); 32 virtual ~BundleEventCallbackImpl() override; 33 virtual void OnReceiveEvent(const EventFwk::CommonEventData eventData) override; 34 35 private: 36 DISALLOW_COPY_AND_MOVE(BundleEventCallbackImpl); 37 }; 38 39 class BundleTestTool : public ShellCommand { 40 public: 41 BundleTestTool(int argc, char *argv[]); 42 ~BundleTestTool(); 43 44 private: 45 ErrCode CreateCommandMap() override; 46 ErrCode CreateMessageMap() override; 47 ErrCode Init() override; 48 void CreateQuickFixMsgMap(std::unordered_map<int32_t, std::string> &quickFixMsgMap); 49 std::string GetResMsg(int32_t code); 50 std::string GetResMsg(int32_t code, const std::shared_ptr<QuickFixResult> &quickFixRes); 51 52 ErrCode RunAsHelpCommand(); 53 ErrCode RunAsCheckCommand(); 54 ErrCode CheckOperation(int userId, std::string deviceId, std::string bundleName, 55 std::string moduleName, std::string abilityName); 56 ErrCode RunAsSetRemovableCommand(); 57 ErrCode RunAsGetRemovableCommand(); 58 ErrCode RunAsInstallSandboxCommand(); 59 ErrCode RunAsUninstallSandboxCommand(); 60 ErrCode RunAsDumpSandboxCommand(); 61 ErrCode RunAsGetStringCommand(); 62 ErrCode RunAsGetIconCommand(); 63 ErrCode RunAsAddInstallRuleCommand(); 64 ErrCode RunAsGetInstallRuleCommand(); 65 ErrCode RunAsDeleteInstallRuleCommand(); 66 ErrCode RunAsCleanInstallRuleCommand(); 67 ErrCode RunAsAddAppRunningRuleCommand(); 68 ErrCode RunAsDeleteAppRunningRuleCommand(); 69 ErrCode RunAsCleanAppRunningRuleCommand(); 70 ErrCode RunAsGetAppRunningControlRuleCommand(); 71 ErrCode RunAsGetAppRunningControlRuleResultCommand(); 72 ErrCode RunAsDeployQuickFix(); 73 ErrCode RunAsSwitchQuickFix(); 74 ErrCode RunAsDeleteQuickFix(); 75 ErrCode RunAsSetDebugMode(); 76 ErrCode RunAsGetBundleStats(); 77 ErrCode RunAsGetAppProvisionInfo(); 78 ErrCode RunAsGetDistributedBundleName(); 79 ErrCode HandleBundleEventCallback(); 80 ErrCode ResetAOTCompileStatus(); 81 ErrCode SendCommonEvent(); 82 ErrCode RunAsGetProxyDataCommand(); 83 ErrCode RunAsGetAllProxyDataCommand(); 84 ErrCode RunAsSetExtNameOrMIMEToAppCommand(); 85 ErrCode RunAsDelExtNameOrMIMEToAppCommand(); 86 ErrCode RunAsQueryDataGroupInfos(); 87 ErrCode RunAsGetGroupDir(); 88 ErrCode RunAsGetJsonProfile(); 89 ErrCode RunAsGetUninstalledBundleInfo(); 90 91 std::condition_variable cv_; 92 std::mutex mutex_; 93 bool dataReady_ {false}; 94 95 sptr<IBundleMgr> bundleMgrProxy_; 96 sptr<IBundleInstaller> bundleInstallerProxy_; 97 #ifdef DISTRIBUTED_BUNDLE_FRAMEWORK 98 sptr<IDistributedBms> distributedBmsProxy_; 99 #endif 100 101 bool CheckRemovableErrorOption(int option, int counter, const std::string &commandName); 102 bool CheckRemovableCorrectOption(int option, const std::string &commandName, int &isRemovable, std::string &name); 103 bool SetIsRemovableOperation(const std::string &bundleName, const std::string &moduleName, int isRemovable) const; 104 bool GetIsRemovableOperation( 105 const std::string &bundleName, const std::string &moduleName, std::string &result) const; 106 bool CheckSandboxErrorOption(int option, int counter, const std::string &commandName); 107 bool CheckGetStringCorrectOption(int option, const std::string &commandName, int &temp, std::string &name); 108 bool CheckGetIconCorrectOption(int option, const std::string &commandName, int &temp, std::string &name); 109 ErrCode CheckAddInstallRuleCorrectOption(int option, const std::string &commandName, 110 std::vector<std::string> &appIds, int &controlRuleType, int &userId, int &euid); 111 ErrCode CheckGetInstallRuleCorrectOption(int option, const std::string &commandName, int &controlRuleType, 112 int &userId, int &euid); 113 ErrCode CheckDeleteInstallRuleCorrectOption(int option, const std::string &commandName, 114 int &controlRuleType, std::vector<std::string> &appIds, int &userId, int &euid); 115 ErrCode CheckCleanInstallRuleCorrectOption(int option, const std::string &commandName, 116 int &controlRuleType, int &userId, int &euid); 117 ErrCode CheckAppRunningRuleCorrectOption(int option, const std::string &commandName, 118 std::vector<AppRunningControlRule> &controlRule, int &userId, int &euid); 119 ErrCode CheckCleanAppRunningRuleCorrectOption(int option, const std::string &commandName, int &userId, int &euid); 120 ErrCode CheckGetAppRunningRuleCorrectOption(int option, const std::string &commandName, 121 int32_t &userId, int &euid); 122 ErrCode CheckGetAppRunningRuleResultCorrectOption(int option, const std::string &commandName, 123 std::string &bundleName, int32_t &userId, int &euid); 124 bool CheckSandboxCorrectOption(int option, const std::string &commandName, int &data, std::string &bundleName); 125 bool CheckGetProxyDataCorrectOption(int option, const std::string &commandName, int &temp, std::string &name); 126 bool CheckGetAllProxyDataCorrectOption(int option, const std::string &commandName, int &temp, std::string &name); 127 bool CheckExtOrMimeCorrectOption(int option, const std::string &commandName, int &temp, std::string &name); 128 ErrCode InstallSandboxOperation( 129 const std::string &bundleName, const int32_t userId, const int32_t dlpType, int32_t &appIndex) const; 130 ErrCode UninstallSandboxOperation( 131 const std::string &bundleName, const int32_t appIndex, const int32_t userId) const; 132 ErrCode DumpSandboxBundleInfo(const std::string &bundleName, const int32_t appIndex, const int32_t userId, 133 std::string &dumpResults); 134 ErrCode StringToInt(std::string option, const std::string &commandName, int &temp, bool &result); 135 ErrCode DeployQuickFix(const std::vector<std::string> &quickFixPaths, 136 std::shared_ptr<QuickFixResult> &quickFixRes, bool isDebug); 137 ErrCode SwitchQuickFix(const std::string &bundleName, int32_t enable, 138 std::shared_ptr<QuickFixResult> &quickFixRes); 139 ErrCode DeleteQuickFix(const std::string &bundleName, std::shared_ptr<QuickFixResult> &quickFixRes); 140 ErrCode GetQuickFixPath(int32_t index, std::vector<std::string> &quickFixPaths) const; 141 ErrCode SetDebugMode(int32_t debugMode); 142 bool GetBundleStats(const std::string &bundleName, int32_t userId, std::string &msg); 143 ErrCode GetAppProvisionInfo(const std::string &bundleName, int32_t userId, std::string &msg); 144 ErrCode GetDistributedBundleName(const std::string &networkId, int32_t accessTokenId, std::string &msg); 145 ErrCode BundleNameAndUserIdCommonFunc(std::string &bundleName, int32_t &userId); 146 ErrCode CheckGetDistributedBundleNameCorrectOption(int32_t option, const std::string &commandName, 147 std::string &networkId, int32_t &accessTokenId); 148 bool QueryDataGroupInfos(const std::string &bundleName, int32_t userId, std::string& msg); 149 bool ParseEventCallbackOptions(bool &onlyUnregister, int32_t &uid); 150 bool ParseResetAOTCompileStatusOptions(std::string &bundleName, std::string &moduleName, 151 int32_t &triggerMode, int32_t &uid); 152 void Sleep(int32_t seconds); 153 ErrCode CallRegisterBundleEventCallback(sptr<BundleEventCallbackImpl> bundleEventCallback); 154 ErrCode CallUnRegisterBundleEventCallback(sptr<BundleEventCallbackImpl> bundleEventCallback); 155 ErrCode CheckGetGroupIdCorrectOption(int32_t option, std::string &dataGroupId); 156 bool GetGroupDir(const std::string &dataGroupId, std::string& msg); 157 ErrCode CheckGetBundleNameOption(int32_t option, std::string &bundleName); 158 }; 159 } // namespace AppExecFwk 160 } // namespace OHOS 161 162 #endif // FOUNDATION_BUNDLEMANAGER_BUNDLE_FRAMEWORK_BUNDLE_TOOL_INCLUDE_BUNDLE_TEST_TOOL_H