• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 RunAsUninstallPreInstallBundleCommand();
61     ErrCode RunAsDumpSandboxCommand();
62     ErrCode RunAsGetStringCommand();
63     ErrCode RunAsGetIconCommand();
64     ErrCode RunAsAddInstallRuleCommand();
65     ErrCode RunAsGetInstallRuleCommand();
66     ErrCode RunAsDeleteInstallRuleCommand();
67     ErrCode RunAsCleanInstallRuleCommand();
68     ErrCode RunAsAddAppRunningRuleCommand();
69     ErrCode RunAsDeleteAppRunningRuleCommand();
70     ErrCode RunAsCleanAppRunningRuleCommand();
71     ErrCode RunAsGetAppRunningControlRuleCommand();
72     ErrCode RunAsGetAppRunningControlRuleResultCommand();
73     ErrCode RunAsDeployQuickFix();
74     ErrCode RunAsSwitchQuickFix();
75     ErrCode RunAsDeleteQuickFix();
76     ErrCode RunAsSetDebugMode();
77     ErrCode RunAsGetBundleStats();
78     ErrCode RunAsBatchGetBundleStats();
79     ErrCode RunAsGetAppProvisionInfo();
80     ErrCode RunAsGetContinueBundleName();
81     ErrCode RunAsGetDistributedBundleName();
82     ErrCode HandleBundleEventCallback();
83     ErrCode ResetAOTCompileStatus();
84     ErrCode SendCommonEvent();
85     ErrCode RunAsGetProxyDataCommand();
86     ErrCode RunAsGetAllProxyDataCommand();
87     ErrCode RunAsSetExtNameOrMIMEToAppCommand();
88     ErrCode RunAsDelExtNameOrMIMEToAppCommand();
89     ErrCode RunAsQueryDataGroupInfos();
90     ErrCode RunAsGetGroupDir();
91     ErrCode RunAsGetJsonProfile();
92     ErrCode RunAsGetUninstalledBundleInfo();
93     ErrCode RunAsGetOdid();
94     ErrCode RunGetUidByBundleName();
95     ErrCode CheckImplicitQueryWantOption(int option, std::string &value);
96     ErrCode ImplicitQuerySkillUriInfo(const std::string &bundleName,
97         const std::string &action, const std::string &entity, const std::string &uri,
98         const std::string &type, std::string &msg);
99     ErrCode RunAsImplicitQuerySkillUriInfo();
100     ErrCode RunAsQueryAbilityInfoByContinueType();
101     ErrCode RunAsCleanBundleCacheFilesAutomaticCommand();
102     ErrCode RunAsUpdateAppEncryptedStatus();
103     ErrCode RunAsGetDirByBundleNameAndAppIndex();
104     ErrCode RunAsGetAllBundleDirs();
105     ErrCode GetAllBundleDirs(int32_t userId, std::string& msg);
106     ErrCode RunAsGetAllBundleCacheStat();
107     ErrCode GetAllBundleCacheStat(std::string& msg);
108     ErrCode RunAsCleanAllBundleCache();
109     ErrCode CleanAllBundleCache(std::string& msg);
110     ErrCode RunAsIsBundleInstalled();
111     ErrCode RunAsGetCompatibleDeviceType();
112     ErrCode RunAsGetSimpleAppInfoForUid();
113     ErrCode RunAsGetBundleNameByAppId();
114     ErrCode RunAsGetAssetAccessGroups();
115     ErrCode RunAsSetAppDistributionTypes();
116     ErrCode RunAsGetBundleNamesForUidExtCommand();
117     ErrCode RunAsGetAppIdentifierAndAppIndex();
118 
119     std::condition_variable cv_;
120     std::mutex mutex_;
121     bool dataReady_ {false};
122 
123     sptr<IBundleMgr> bundleMgrProxy_;
124     sptr<IBundleInstaller> bundleInstallerProxy_;
125 #ifdef DISTRIBUTED_BUNDLE_FRAMEWORK
126     sptr<IDistributedBms> distributedBmsProxy_;
127 #endif
128 
129     bool CheckRemovableErrorOption(int option, int counter, const std::string &commandName);
130     bool CheckRemovableCorrectOption(int option, const std::string &commandName, int &isRemovable, std::string &name);
131     bool SetIsRemovableOperation(const std::string &bundleName, const std::string &moduleName, int isRemovable) const;
132     bool GetIsRemovableOperation(
133         const std::string &bundleName, const std::string &moduleName, std::string &result) const;
134     bool CheckSandboxErrorOption(int option, int counter, const std::string &commandName);
135     bool CheckGetStringCorrectOption(int option, const std::string &commandName, int &temp, std::string &name);
136     bool CheckGetIconCorrectOption(int option, const std::string &commandName, int &temp, std::string &name);
137     ErrCode CheckAddInstallRuleCorrectOption(int option, const std::string &commandName,
138         std::vector<std::string> &appIds, int &controlRuleType, int &userId, int &euid);
139     ErrCode CheckGetInstallRuleCorrectOption(int option, const std::string &commandName, int &controlRuleType,
140         int &userId, int &euid);
141     ErrCode CheckDeleteInstallRuleCorrectOption(int option, const std::string &commandName,
142         int &controlRuleType, std::vector<std::string> &appIds, int &userId, int &euid);
143     ErrCode CheckCleanInstallRuleCorrectOption(int option, const std::string &commandName,
144         int &controlRuleType, int &userId, int &euid);
145     ErrCode CheckAppRunningRuleCorrectOption(int option, const std::string &commandName,
146         std::vector<AppRunningControlRule> &controlRule, int &userId, int &euid);
147     ErrCode CheckCleanAppRunningRuleCorrectOption(int option, const std::string &commandName, int &userId, int &euid);
148     ErrCode CheckGetAppRunningRuleCorrectOption(int option, const std::string &commandName,
149         int32_t &userId, int &euid);
150     ErrCode CheckGetAppRunningRuleResultCorrectOption(int option, const std::string &commandName,
151         std::string &bundleName, int32_t &userId, int &euid);
152     bool CheckSandboxCorrectOption(int option, const std::string &commandName, int &data, std::string &bundleName);
153     bool CheckGetProxyDataCorrectOption(int option, const std::string &commandName, int &temp, std::string &name);
154     bool CheckGetAllProxyDataCorrectOption(int option, const std::string &commandName, int &temp, std::string &name);
155     bool CheckExtOrMimeCorrectOption(int option, const std::string &commandName, int &temp, std::string &name);
156     ErrCode InstallSandboxOperation(
157         const std::string &bundleName, const int32_t userId, const int32_t dlpType, int32_t &appIndex) const;
158     ErrCode UninstallSandboxOperation(
159         const std::string &bundleName, const int32_t appIndex, const int32_t userId) const;
160     ErrCode DumpSandboxBundleInfo(const std::string &bundleName, const int32_t appIndex, const int32_t userId,
161         std::string &dumpResults);
162     ErrCode StringToInt(std::string option, const std::string &commandName, int &temp, bool &result);
163     ErrCode StringToUnsignedLongLong(std::string optarg, const std::string &commandName,
164         uint64_t &temp, bool &result);
165     bool StrToUint32(const std::string &str, uint32_t &value);
166     ErrCode DeployQuickFix(const std::vector<std::string> &quickFixPaths,
167         std::shared_ptr<QuickFixResult> &quickFixRes, bool isDebug);
168     ErrCode SwitchQuickFix(const std::string &bundleName, int32_t enable,
169         std::shared_ptr<QuickFixResult> &quickFixRes);
170     ErrCode DeleteQuickFix(const std::string &bundleName, std::shared_ptr<QuickFixResult> &quickFixRes);
171     ErrCode GetQuickFixPath(int32_t index, std::vector<std::string> &quickFixPaths) const;
172     ErrCode SetDebugMode(int32_t debugMode);
173     bool GetBundleStats(const std::string &bundleName, int32_t userId, std::string &msg, int32_t appIndex);
174     bool BatchGetBundleStats(const std::vector<std::string> &bundleNames, int32_t userId, std::string &msg);
175     ErrCode GetAppProvisionInfo(const std::string &bundleName, int32_t userId, std::string &msg);
176     ErrCode GetDistributedBundleName(const std::string &networkId, int32_t accessTokenId, std::string &msg);
177     ErrCode BundleNameAndUserIdCommonFunc(std::string &bundleName, int32_t &userId, int32_t &appIndex);
178     ErrCode BatchBundleNameAndUserIdCommonFunc(std::vector<std::string> &bundleNames, int32_t &userId);
179     ErrCode CheckGetDistributedBundleNameCorrectOption(int32_t option, const std::string &commandName,
180         std::string &networkId, int32_t &accessTokenId);
181     bool QueryDataGroupInfos(const std::string &bundleName, int32_t userId, std::string& msg);
182     bool ParseEventCallbackOptions(bool &onlyUnregister, int32_t &uid);
183     bool ParseResetAOTCompileStatusOptions(std::string &bundleName, std::string &moduleName,
184         int32_t &triggerMode, int32_t &uid);
185     void Sleep(int32_t seconds);
186     bool HandleUnknownOption(const std::string &commandName, bool &ret);
187     ErrCode CallRegisterBundleEventCallback(sptr<BundleEventCallbackImpl> bundleEventCallback);
188     ErrCode CallUnRegisterBundleEventCallback(sptr<BundleEventCallbackImpl> bundleEventCallback);
189     ErrCode CheckGetGroupIdCorrectOption(int32_t option, std::string &dataGroupId);
190     bool GetGroupDir(const std::string &dataGroupId, std::string& msg);
191     ErrCode CheckGetBundleNameOption(int32_t option, std::string &bundleName);
192     ErrCode CheckCleanBundleCacheFilesAutomaticOption(int option, const std::string &commandName,
193         uint64_t &cacheSize);
194     ErrCode GetContinueBundleName(const std::string &bundleName, int32_t userId, std::string& msg);
195     bool CheckGetAssetAccessGroupsOption(int32_t option, const std::string &commandName,
196         std::string &bundleName);
197     bool CheckSetAppDistributionTypesOption(int32_t option, const std::string &commandName,
198         std::string &appDistributionTypes);
199     bool ProcessAppDistributionTypeEnums(std::vector<std::string> appDistributionTypeStrings,
200         std::set<AppDistributionTypeEnum> &appDistributionTypeEnums);
201     void ReloadNativeTokenInfo();
202     ErrCode InnerGetSimpleAppInfoForUid(const int32_t &option, std::vector<std::int32_t> &uids);
203     ErrCode UninstallPreInstallBundleOperation(
204         const std::string &bundleName, InstallParam &installParam) const;
205     bool CheckUnisntallCorrectOption(int option, const std::string &commandName,
206         int &temp, std::string &Name);
207     bool CheckGetAppIdentifierAndAppIndexOption(int32_t option, const std::string &commandName,
208         uint32_t &accessTokenId);
209 };
210 }  // namespace AppExecFwk
211 }  // namespace OHOS
212 
213 #endif  // FOUNDATION_BUNDLEMANAGER_BUNDLE_FRAMEWORK_BUNDLE_TOOL_INCLUDE_BUNDLE_TEST_TOOL_H