1545fdf9bSopenharmony_ci/* 2545fdf9bSopenharmony_ci * Copyright (c) 2022 Huawei Device Co., Ltd. 3545fdf9bSopenharmony_ci * Licensed under the Apache License, Version 2.0 (the "License"); 4545fdf9bSopenharmony_ci * you may not use this file except in compliance with the License. 5545fdf9bSopenharmony_ci * You may obtain a copy of the License at 6545fdf9bSopenharmony_ci * 7545fdf9bSopenharmony_ci * http://www.apache.org/licenses/LICENSE-2.0 8545fdf9bSopenharmony_ci * 9545fdf9bSopenharmony_ci * Unless required by applicable law or agreed to in writing, software 10545fdf9bSopenharmony_ci * distributed under the License is distributed on an "AS IS" BASIS, 11545fdf9bSopenharmony_ci * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12545fdf9bSopenharmony_ci * See the License for the specific language governing permissions and 13545fdf9bSopenharmony_ci * limitations under the License. 14545fdf9bSopenharmony_ci */ 15545fdf9bSopenharmony_ci 16545fdf9bSopenharmony_ci#ifndef FOUNDATION_BUNDLEMANAGER_BUNDLE_FRAMEWORK_BUNDLE_TOOL_INCLUDE_BUNDLE_TEST_TOOL_H 17545fdf9bSopenharmony_ci#define FOUNDATION_BUNDLEMANAGER_BUNDLE_FRAMEWORK_BUNDLE_TOOL_INCLUDE_BUNDLE_TEST_TOOL_H 18545fdf9bSopenharmony_ci 19545fdf9bSopenharmony_ci#include "shell_command.h" 20545fdf9bSopenharmony_ci#include "bundle_event_callback_host.h" 21545fdf9bSopenharmony_ci#include "bundle_mgr_interface.h" 22545fdf9bSopenharmony_ci#include "bundle_installer_interface.h" 23545fdf9bSopenharmony_ci#ifdef DISTRIBUTED_BUNDLE_FRAMEWORK 24545fdf9bSopenharmony_ci#include "distributed_bms_interface.h" 25545fdf9bSopenharmony_ci#endif 26545fdf9bSopenharmony_ci 27545fdf9bSopenharmony_cinamespace OHOS { 28545fdf9bSopenharmony_cinamespace AppExecFwk { 29545fdf9bSopenharmony_ciclass BundleEventCallbackImpl : public BundleEventCallbackHost { 30545fdf9bSopenharmony_cipublic: 31545fdf9bSopenharmony_ci BundleEventCallbackImpl(); 32545fdf9bSopenharmony_ci virtual ~BundleEventCallbackImpl() override; 33545fdf9bSopenharmony_ci virtual void OnReceiveEvent(const EventFwk::CommonEventData eventData) override; 34545fdf9bSopenharmony_ci 35545fdf9bSopenharmony_ciprivate: 36545fdf9bSopenharmony_ci DISALLOW_COPY_AND_MOVE(BundleEventCallbackImpl); 37545fdf9bSopenharmony_ci}; 38545fdf9bSopenharmony_ci 39545fdf9bSopenharmony_ciclass BundleTestTool : public ShellCommand { 40545fdf9bSopenharmony_cipublic: 41545fdf9bSopenharmony_ci BundleTestTool(int argc, char *argv[]); 42545fdf9bSopenharmony_ci ~BundleTestTool(); 43545fdf9bSopenharmony_ci 44545fdf9bSopenharmony_ciprivate: 45545fdf9bSopenharmony_ci ErrCode CreateCommandMap() override; 46545fdf9bSopenharmony_ci ErrCode CreateMessageMap() override; 47545fdf9bSopenharmony_ci ErrCode Init() override; 48545fdf9bSopenharmony_ci void CreateQuickFixMsgMap(std::unordered_map<int32_t, std::string> &quickFixMsgMap); 49545fdf9bSopenharmony_ci std::string GetResMsg(int32_t code); 50545fdf9bSopenharmony_ci std::string GetResMsg(int32_t code, const std::shared_ptr<QuickFixResult> &quickFixRes); 51545fdf9bSopenharmony_ci 52545fdf9bSopenharmony_ci ErrCode RunAsHelpCommand(); 53545fdf9bSopenharmony_ci ErrCode RunAsCheckCommand(); 54545fdf9bSopenharmony_ci ErrCode CheckOperation(int userId, std::string deviceId, std::string bundleName, 55545fdf9bSopenharmony_ci std::string moduleName, std::string abilityName); 56545fdf9bSopenharmony_ci ErrCode RunAsSetRemovableCommand(); 57545fdf9bSopenharmony_ci ErrCode RunAsGetRemovableCommand(); 58545fdf9bSopenharmony_ci ErrCode RunAsInstallSandboxCommand(); 59545fdf9bSopenharmony_ci ErrCode RunAsUninstallSandboxCommand(); 60545fdf9bSopenharmony_ci ErrCode RunAsDumpSandboxCommand(); 61545fdf9bSopenharmony_ci ErrCode RunAsGetStringCommand(); 62545fdf9bSopenharmony_ci ErrCode RunAsGetIconCommand(); 63545fdf9bSopenharmony_ci ErrCode RunAsAddInstallRuleCommand(); 64545fdf9bSopenharmony_ci ErrCode RunAsGetInstallRuleCommand(); 65545fdf9bSopenharmony_ci ErrCode RunAsDeleteInstallRuleCommand(); 66545fdf9bSopenharmony_ci ErrCode RunAsCleanInstallRuleCommand(); 67545fdf9bSopenharmony_ci ErrCode RunAsAddAppRunningRuleCommand(); 68545fdf9bSopenharmony_ci ErrCode RunAsDeleteAppRunningRuleCommand(); 69545fdf9bSopenharmony_ci ErrCode RunAsCleanAppRunningRuleCommand(); 70545fdf9bSopenharmony_ci ErrCode RunAsGetAppRunningControlRuleCommand(); 71545fdf9bSopenharmony_ci ErrCode RunAsGetAppRunningControlRuleResultCommand(); 72545fdf9bSopenharmony_ci ErrCode RunAsDeployQuickFix(); 73545fdf9bSopenharmony_ci ErrCode RunAsSwitchQuickFix(); 74545fdf9bSopenharmony_ci ErrCode RunAsDeleteQuickFix(); 75545fdf9bSopenharmony_ci ErrCode RunAsSetDebugMode(); 76545fdf9bSopenharmony_ci ErrCode RunAsGetBundleStats(); 77545fdf9bSopenharmony_ci ErrCode RunAsGetAppProvisionInfo(); 78545fdf9bSopenharmony_ci ErrCode RunAsGetContinueBundleName(); 79545fdf9bSopenharmony_ci ErrCode RunAsGetDistributedBundleName(); 80545fdf9bSopenharmony_ci ErrCode HandleBundleEventCallback(); 81545fdf9bSopenharmony_ci ErrCode ResetAOTCompileStatus(); 82545fdf9bSopenharmony_ci ErrCode SendCommonEvent(); 83545fdf9bSopenharmony_ci ErrCode RunAsGetProxyDataCommand(); 84545fdf9bSopenharmony_ci ErrCode RunAsGetAllProxyDataCommand(); 85545fdf9bSopenharmony_ci ErrCode RunAsSetExtNameOrMIMEToAppCommand(); 86545fdf9bSopenharmony_ci ErrCode RunAsDelExtNameOrMIMEToAppCommand(); 87545fdf9bSopenharmony_ci ErrCode RunAsQueryDataGroupInfos(); 88545fdf9bSopenharmony_ci ErrCode RunAsGetGroupDir(); 89545fdf9bSopenharmony_ci ErrCode RunAsGetJsonProfile(); 90545fdf9bSopenharmony_ci ErrCode RunAsGetUninstalledBundleInfo(); 91545fdf9bSopenharmony_ci ErrCode RunAsGetOdid(); 92545fdf9bSopenharmony_ci ErrCode RunGetUidByBundleName(); 93545fdf9bSopenharmony_ci ErrCode CheckImplicitQueryWantOption(int option, std::string &value); 94545fdf9bSopenharmony_ci ErrCode ImplicitQuerySkillUriInfo(const std::string &bundleName, 95545fdf9bSopenharmony_ci const std::string &action, const std::string &entity, const std::string &uri, 96545fdf9bSopenharmony_ci const std::string &type, std::string &msg); 97545fdf9bSopenharmony_ci ErrCode RunAsImplicitQuerySkillUriInfo(); 98545fdf9bSopenharmony_ci ErrCode RunAsQueryAbilityInfoByContinueType(); 99545fdf9bSopenharmony_ci ErrCode RunAsCleanBundleCacheFilesAutomaticCommand(); 100545fdf9bSopenharmony_ci ErrCode RunAsUpdateAppEncryptedStatus(); 101545fdf9bSopenharmony_ci ErrCode RunAsGetDirByBundleNameAndAppIndex(); 102545fdf9bSopenharmony_ci ErrCode RunAsIsBundleInstalled(); 103545fdf9bSopenharmony_ci 104545fdf9bSopenharmony_ci std::condition_variable cv_; 105545fdf9bSopenharmony_ci std::mutex mutex_; 106545fdf9bSopenharmony_ci bool dataReady_ {false}; 107545fdf9bSopenharmony_ci 108545fdf9bSopenharmony_ci sptr<IBundleMgr> bundleMgrProxy_; 109545fdf9bSopenharmony_ci sptr<IBundleInstaller> bundleInstallerProxy_; 110545fdf9bSopenharmony_ci#ifdef DISTRIBUTED_BUNDLE_FRAMEWORK 111545fdf9bSopenharmony_ci sptr<IDistributedBms> distributedBmsProxy_; 112545fdf9bSopenharmony_ci#endif 113545fdf9bSopenharmony_ci 114545fdf9bSopenharmony_ci bool CheckRemovableErrorOption(int option, int counter, const std::string &commandName); 115545fdf9bSopenharmony_ci bool CheckRemovableCorrectOption(int option, const std::string &commandName, int &isRemovable, std::string &name); 116545fdf9bSopenharmony_ci bool SetIsRemovableOperation(const std::string &bundleName, const std::string &moduleName, int isRemovable) const; 117545fdf9bSopenharmony_ci bool GetIsRemovableOperation( 118545fdf9bSopenharmony_ci const std::string &bundleName, const std::string &moduleName, std::string &result) const; 119545fdf9bSopenharmony_ci bool CheckSandboxErrorOption(int option, int counter, const std::string &commandName); 120545fdf9bSopenharmony_ci bool CheckGetStringCorrectOption(int option, const std::string &commandName, int &temp, std::string &name); 121545fdf9bSopenharmony_ci bool CheckGetIconCorrectOption(int option, const std::string &commandName, int &temp, std::string &name); 122545fdf9bSopenharmony_ci ErrCode CheckAddInstallRuleCorrectOption(int option, const std::string &commandName, 123545fdf9bSopenharmony_ci std::vector<std::string> &appIds, int &controlRuleType, int &userId, int &euid); 124545fdf9bSopenharmony_ci ErrCode CheckGetInstallRuleCorrectOption(int option, const std::string &commandName, int &controlRuleType, 125545fdf9bSopenharmony_ci int &userId, int &euid); 126545fdf9bSopenharmony_ci ErrCode CheckDeleteInstallRuleCorrectOption(int option, const std::string &commandName, 127545fdf9bSopenharmony_ci int &controlRuleType, std::vector<std::string> &appIds, int &userId, int &euid); 128545fdf9bSopenharmony_ci ErrCode CheckCleanInstallRuleCorrectOption(int option, const std::string &commandName, 129545fdf9bSopenharmony_ci int &controlRuleType, int &userId, int &euid); 130545fdf9bSopenharmony_ci ErrCode CheckAppRunningRuleCorrectOption(int option, const std::string &commandName, 131545fdf9bSopenharmony_ci std::vector<AppRunningControlRule> &controlRule, int &userId, int &euid); 132545fdf9bSopenharmony_ci ErrCode CheckCleanAppRunningRuleCorrectOption(int option, const std::string &commandName, int &userId, int &euid); 133545fdf9bSopenharmony_ci ErrCode CheckGetAppRunningRuleCorrectOption(int option, const std::string &commandName, 134545fdf9bSopenharmony_ci int32_t &userId, int &euid); 135545fdf9bSopenharmony_ci ErrCode CheckGetAppRunningRuleResultCorrectOption(int option, const std::string &commandName, 136545fdf9bSopenharmony_ci std::string &bundleName, int32_t &userId, int &euid); 137545fdf9bSopenharmony_ci bool CheckSandboxCorrectOption(int option, const std::string &commandName, int &data, std::string &bundleName); 138545fdf9bSopenharmony_ci bool CheckGetProxyDataCorrectOption(int option, const std::string &commandName, int &temp, std::string &name); 139545fdf9bSopenharmony_ci bool CheckGetAllProxyDataCorrectOption(int option, const std::string &commandName, int &temp, std::string &name); 140545fdf9bSopenharmony_ci bool CheckExtOrMimeCorrectOption(int option, const std::string &commandName, int &temp, std::string &name); 141545fdf9bSopenharmony_ci ErrCode InstallSandboxOperation( 142545fdf9bSopenharmony_ci const std::string &bundleName, const int32_t userId, const int32_t dlpType, int32_t &appIndex) const; 143545fdf9bSopenharmony_ci ErrCode UninstallSandboxOperation( 144545fdf9bSopenharmony_ci const std::string &bundleName, const int32_t appIndex, const int32_t userId) const; 145545fdf9bSopenharmony_ci ErrCode DumpSandboxBundleInfo(const std::string &bundleName, const int32_t appIndex, const int32_t userId, 146545fdf9bSopenharmony_ci std::string &dumpResults); 147545fdf9bSopenharmony_ci ErrCode StringToInt(std::string option, const std::string &commandName, int &temp, bool &result); 148545fdf9bSopenharmony_ci ErrCode StringToUnsignedLongLong(std::string optarg, const std::string &commandName, 149545fdf9bSopenharmony_ci uint64_t &temp, bool &result); 150545fdf9bSopenharmony_ci ErrCode DeployQuickFix(const std::vector<std::string> &quickFixPaths, 151545fdf9bSopenharmony_ci std::shared_ptr<QuickFixResult> &quickFixRes, bool isDebug); 152545fdf9bSopenharmony_ci ErrCode SwitchQuickFix(const std::string &bundleName, int32_t enable, 153545fdf9bSopenharmony_ci std::shared_ptr<QuickFixResult> &quickFixRes); 154545fdf9bSopenharmony_ci ErrCode DeleteQuickFix(const std::string &bundleName, std::shared_ptr<QuickFixResult> &quickFixRes); 155545fdf9bSopenharmony_ci ErrCode GetQuickFixPath(int32_t index, std::vector<std::string> &quickFixPaths) const; 156545fdf9bSopenharmony_ci ErrCode SetDebugMode(int32_t debugMode); 157545fdf9bSopenharmony_ci bool GetBundleStats(const std::string &bundleName, int32_t userId, std::string &msg, int32_t appIndex); 158545fdf9bSopenharmony_ci ErrCode GetAppProvisionInfo(const std::string &bundleName, int32_t userId, std::string &msg); 159545fdf9bSopenharmony_ci ErrCode GetDistributedBundleName(const std::string &networkId, int32_t accessTokenId, std::string &msg); 160545fdf9bSopenharmony_ci ErrCode BundleNameAndUserIdCommonFunc(std::string &bundleName, int32_t &userId, int32_t &appIndex); 161545fdf9bSopenharmony_ci ErrCode CheckGetDistributedBundleNameCorrectOption(int32_t option, const std::string &commandName, 162545fdf9bSopenharmony_ci std::string &networkId, int32_t &accessTokenId); 163545fdf9bSopenharmony_ci bool QueryDataGroupInfos(const std::string &bundleName, int32_t userId, std::string& msg); 164545fdf9bSopenharmony_ci bool ParseEventCallbackOptions(bool &onlyUnregister, int32_t &uid); 165545fdf9bSopenharmony_ci bool ParseResetAOTCompileStatusOptions(std::string &bundleName, std::string &moduleName, 166545fdf9bSopenharmony_ci int32_t &triggerMode, int32_t &uid); 167545fdf9bSopenharmony_ci void Sleep(int32_t seconds); 168545fdf9bSopenharmony_ci bool HandleUnknownOption(const std::string &commandName, bool &ret); 169545fdf9bSopenharmony_ci ErrCode CallRegisterBundleEventCallback(sptr<BundleEventCallbackImpl> bundleEventCallback); 170545fdf9bSopenharmony_ci ErrCode CallUnRegisterBundleEventCallback(sptr<BundleEventCallbackImpl> bundleEventCallback); 171545fdf9bSopenharmony_ci ErrCode CheckGetGroupIdCorrectOption(int32_t option, std::string &dataGroupId); 172545fdf9bSopenharmony_ci bool GetGroupDir(const std::string &dataGroupId, std::string& msg); 173545fdf9bSopenharmony_ci ErrCode CheckGetBundleNameOption(int32_t option, std::string &bundleName); 174545fdf9bSopenharmony_ci ErrCode CheckCleanBundleCacheFilesAutomaticOption(int option, const std::string &commandName, 175545fdf9bSopenharmony_ci uint64_t &cacheSize); 176545fdf9bSopenharmony_ci ErrCode GetContinueBundleName(const std::string &bundleName, int32_t userId, std::string& msg); 177545fdf9bSopenharmony_ci}; 178545fdf9bSopenharmony_ci} // namespace AppExecFwk 179545fdf9bSopenharmony_ci} // namespace OHOS 180545fdf9bSopenharmony_ci 181545fdf9bSopenharmony_ci#endif // FOUNDATION_BUNDLEMANAGER_BUNDLE_FRAMEWORK_BUNDLE_TOOL_INCLUDE_BUNDLE_TEST_TOOL_H