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