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 RunAsGetContinueBundleName(); 79 ErrCode RunAsGetDistributedBundleName(); 80 ErrCode HandleBundleEventCallback(); 81 ErrCode ResetAOTCompileStatus(); 82 ErrCode SendCommonEvent(); 83 ErrCode RunAsGetProxyDataCommand(); 84 ErrCode RunAsGetAllProxyDataCommand(); 85 ErrCode RunAsSetExtNameOrMIMEToAppCommand(); 86 ErrCode RunAsDelExtNameOrMIMEToAppCommand(); 87 ErrCode RunAsQueryDataGroupInfos(); 88 ErrCode RunAsGetGroupDir(); 89 ErrCode RunAsGetJsonProfile(); 90 ErrCode RunAsGetUninstalledBundleInfo(); 91 ErrCode RunAsGetOdid(); 92 ErrCode RunGetUidByBundleName(); 93 ErrCode CheckImplicitQueryWantOption(int option, std::string &value); 94 ErrCode ImplicitQuerySkillUriInfo(const std::string &bundleName, 95 const std::string &action, const std::string &entity, const std::string &uri, 96 const std::string &type, std::string &msg); 97 ErrCode RunAsImplicitQuerySkillUriInfo(); 98 ErrCode RunAsQueryAbilityInfoByContinueType(); 99 ErrCode RunAsCleanBundleCacheFilesAutomaticCommand(); 100 ErrCode RunAsGetBundleNameByAppId(); 101 102 std::condition_variable cv_; 103 std::mutex mutex_; 104 bool dataReady_ {false}; 105 106 sptr<IBundleMgr> bundleMgrProxy_; 107 sptr<IBundleInstaller> bundleInstallerProxy_; 108 #ifdef DISTRIBUTED_BUNDLE_FRAMEWORK 109 sptr<IDistributedBms> distributedBmsProxy_; 110 #endif 111 112 bool CheckRemovableErrorOption(int option, int counter, const std::string &commandName); 113 bool CheckRemovableCorrectOption(int option, const std::string &commandName, int &isRemovable, std::string &name); 114 bool SetIsRemovableOperation(const std::string &bundleName, const std::string &moduleName, int isRemovable) const; 115 bool GetIsRemovableOperation( 116 const std::string &bundleName, const std::string &moduleName, std::string &result) const; 117 bool CheckSandboxErrorOption(int option, int counter, const std::string &commandName); 118 bool CheckGetStringCorrectOption(int option, const std::string &commandName, int &temp, std::string &name); 119 bool CheckGetIconCorrectOption(int option, const std::string &commandName, int &temp, std::string &name); 120 ErrCode CheckAddInstallRuleCorrectOption(int option, const std::string &commandName, 121 std::vector<std::string> &appIds, int &controlRuleType, int &userId, int &euid); 122 ErrCode CheckGetInstallRuleCorrectOption(int option, const std::string &commandName, int &controlRuleType, 123 int &userId, int &euid); 124 ErrCode CheckDeleteInstallRuleCorrectOption(int option, const std::string &commandName, 125 int &controlRuleType, std::vector<std::string> &appIds, int &userId, int &euid); 126 ErrCode CheckCleanInstallRuleCorrectOption(int option, const std::string &commandName, 127 int &controlRuleType, int &userId, int &euid); 128 ErrCode CheckAppRunningRuleCorrectOption(int option, const std::string &commandName, 129 std::vector<AppRunningControlRule> &controlRule, int &userId, int &euid); 130 ErrCode CheckCleanAppRunningRuleCorrectOption(int option, const std::string &commandName, int &userId, int &euid); 131 ErrCode CheckGetAppRunningRuleCorrectOption(int option, const std::string &commandName, 132 int32_t &userId, int &euid); 133 ErrCode CheckGetAppRunningRuleResultCorrectOption(int option, const std::string &commandName, 134 std::string &bundleName, int32_t &userId, int &euid); 135 bool CheckSandboxCorrectOption(int option, const std::string &commandName, int &data, std::string &bundleName); 136 bool CheckGetProxyDataCorrectOption(int option, const std::string &commandName, int &temp, std::string &name); 137 bool CheckGetAllProxyDataCorrectOption(int option, const std::string &commandName, int &temp, std::string &name); 138 bool CheckExtOrMimeCorrectOption(int option, const std::string &commandName, int &temp, std::string &name); 139 ErrCode InstallSandboxOperation( 140 const std::string &bundleName, const int32_t userId, const int32_t dlpType, int32_t &appIndex) const; 141 ErrCode UninstallSandboxOperation( 142 const std::string &bundleName, const int32_t appIndex, const int32_t userId) const; 143 ErrCode DumpSandboxBundleInfo(const std::string &bundleName, const int32_t appIndex, const int32_t userId, 144 std::string &dumpResults); 145 ErrCode StringToInt(std::string option, const std::string &commandName, int &temp, bool &result); 146 ErrCode StringToUnsignedLongLong(std::string optarg, const std::string &commandName, 147 uint64_t &temp, bool &result); 148 ErrCode DeployQuickFix(const std::vector<std::string> &quickFixPaths, 149 std::shared_ptr<QuickFixResult> &quickFixRes, bool isDebug); 150 ErrCode SwitchQuickFix(const std::string &bundleName, int32_t enable, 151 std::shared_ptr<QuickFixResult> &quickFixRes); 152 ErrCode DeleteQuickFix(const std::string &bundleName, std::shared_ptr<QuickFixResult> &quickFixRes); 153 ErrCode GetQuickFixPath(int32_t index, std::vector<std::string> &quickFixPaths) const; 154 ErrCode SetDebugMode(int32_t debugMode); 155 bool GetBundleStats(const std::string &bundleName, int32_t userId, std::string &msg, int32_t appIndex); 156 ErrCode GetAppProvisionInfo(const std::string &bundleName, int32_t userId, std::string &msg); 157 ErrCode GetDistributedBundleName(const std::string &networkId, int32_t accessTokenId, std::string &msg); 158 ErrCode BundleNameAndUserIdCommonFunc(std::string &bundleName, int32_t &userId, int32_t &appIndex); 159 ErrCode CheckGetDistributedBundleNameCorrectOption(int32_t option, const std::string &commandName, 160 std::string &networkId, int32_t &accessTokenId); 161 bool QueryDataGroupInfos(const std::string &bundleName, int32_t userId, std::string& msg); 162 bool ParseEventCallbackOptions(bool &onlyUnregister, int32_t &uid); 163 bool ParseResetAOTCompileStatusOptions(std::string &bundleName, std::string &moduleName, 164 int32_t &triggerMode, int32_t &uid); 165 void Sleep(int32_t seconds); 166 bool HandleUnknownOption(const std::string &commandName, bool &ret); 167 ErrCode CallRegisterBundleEventCallback(sptr<BundleEventCallbackImpl> bundleEventCallback); 168 ErrCode CallUnRegisterBundleEventCallback(sptr<BundleEventCallbackImpl> bundleEventCallback); 169 ErrCode CheckGetGroupIdCorrectOption(int32_t option, std::string &dataGroupId); 170 bool GetGroupDir(const std::string &dataGroupId, std::string& msg); 171 ErrCode CheckGetBundleNameOption(int32_t option, std::string &bundleName); 172 ErrCode CheckCleanBundleCacheFilesAutomaticOption(int option, const std::string &commandName, 173 uint64_t &cacheSize); 174 ErrCode GetContinueBundleName(const std::string &bundleName, int32_t userId, std::string& msg); 175 }; 176 } // namespace AppExecFwk 177 } // namespace OHOS 178 179 #endif // FOUNDATION_BUNDLEMANAGER_BUNDLE_FRAMEWORK_BUNDLE_TOOL_INCLUDE_BUNDLE_TEST_TOOL_H