• 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 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 RunAsGetProxyDataCommand();
81     ErrCode RunAsGetAllProxyDataCommand();
82     ErrCode RunAsSetExtNameOrMIMEToAppCommand();
83     ErrCode RunAsDelExtNameOrMIMEToAppCommand();
84     ErrCode RunAsQueryDataGroupInfos();
85     ErrCode RunAsGetGroupDir();
86 
87     std::condition_variable cv_;
88     std::mutex mutex_;
89     bool dataReady_ {false};
90 
91     sptr<IBundleMgr> bundleMgrProxy_;
92     sptr<IBundleInstaller> bundleInstallerProxy_;
93 #ifdef DISTRIBUTED_BUNDLE_FRAMEWORK
94     sptr<IDistributedBms> distributedBmsProxy_;
95 #endif
96 
97     bool CheckRemovableErrorOption(int option, int counter, const std::string &commandName);
98     bool CheckRemovableCorrectOption(int option, const std::string &commandName, int &isRemovable, std::string &name);
99     bool SetIsRemovableOperation(const std::string &bundleName, const std::string &moduleName, int isRemovable) const;
100     bool GetIsRemovableOperation(
101         const std::string &bundleName, const std::string &moduleName, std::string &result) const;
102     bool CheckSandboxErrorOption(int option, int counter, const std::string &commandName);
103     bool CheckGetStringCorrectOption(int option, const std::string &commandName, int &temp, std::string &name);
104     bool CheckGetIconCorrectOption(int option, const std::string &commandName, int &temp, std::string &name);
105     ErrCode CheckAddInstallRuleCorrectOption(int option, const std::string &commandName,
106         std::vector<std::string> &appIds, int &controlRuleType, int &userId, int &euid);
107     ErrCode CheckGetInstallRuleCorrectOption(int option, const std::string &commandName, int &controlRuleType,
108         int &userId, int &euid);
109     ErrCode CheckDeleteInstallRuleCorrectOption(int option, const std::string &commandName,
110         int &controlRuleType, std::vector<std::string> &appIds, int &userId, int &euid);
111     ErrCode CheckCleanInstallRuleCorrectOption(int option, const std::string &commandName,
112         int &controlRuleType, int &userId, int &euid);
113     ErrCode CheckAppRunningRuleCorrectOption(int option, const std::string &commandName,
114         std::vector<AppRunningControlRule> &controlRule, int &userId, int &euid);
115     ErrCode CheckCleanAppRunningRuleCorrectOption(int option, const std::string &commandName, int &userId, int &euid);
116     ErrCode CheckGetAppRunningRuleCorrectOption(int option, const std::string &commandName,
117         int32_t &userId, int &euid);
118     ErrCode CheckGetAppRunningRuleResultCorrectOption(int option, const std::string &commandName,
119         std::string &bundleName, int32_t &userId, int &euid);
120     bool CheckSandboxCorrectOption(int option, const std::string &commandName, int &data, std::string &bundleName);
121     bool CheckGetProxyDataCorrectOption(int option, const std::string &commandName, int &temp, std::string &name);
122     bool CheckGetAllProxyDataCorrectOption(int option, const std::string &commandName, int &temp, std::string &name);
123     bool CheckExtOrMimeCorrectOption(int option, const std::string &commandName, int &temp, std::string &name);
124     ErrCode InstallSandboxOperation(
125         const std::string &bundleName, const int32_t userId, const int32_t dlpType, int32_t &appIndex) const;
126     ErrCode UninstallSandboxOperation(
127         const std::string &bundleName, const int32_t appIndex, const int32_t userId) const;
128     ErrCode DumpSandboxBundleInfo(const std::string &bundleName, const int32_t appIndex, const int32_t userId,
129         std::string &dumpResults);
130     ErrCode StringToInt(std::string option, const std::string &commandName, int &temp, bool &result);
131     ErrCode DeployQuickFix(const std::vector<std::string> &quickFixPaths,
132         std::shared_ptr<QuickFixResult> &quickFixRes);
133     ErrCode SwitchQuickFix(const std::string &bundleName, int32_t enable,
134         std::shared_ptr<QuickFixResult> &quickFixRes);
135     ErrCode DeleteQuickFix(const std::string &bundleName, std::shared_ptr<QuickFixResult> &quickFixRes);
136     ErrCode GetQuickFixPath(int32_t index, std::vector<std::string> &quickFixPaths) const;
137     ErrCode SetDebugMode(int32_t debugMode);
138     bool GetBundleStats(const std::string &bundleName, int32_t userId, std::string &msg);
139     ErrCode GetAppProvisionInfo(const std::string &bundleName, int32_t userId, std::string &msg);
140     ErrCode GetDistributedBundleName(const std::string &networkId, int32_t accessTokenId, std::string &msg);
141     ErrCode BundleNameAndUserIdCommonFunc(std::string &bundleName, int32_t &userId);
142     ErrCode CheckGetDistributedBundleNameCorrectOption(int32_t option, const std::string &commandName,
143         std::string &networkId, int32_t &accessTokenId);
144     bool QueryDataGroupInfos(const std::string &bundleName, int32_t userId, std::string& msg);
145     bool ParseEventCallbackOptions(bool &onlyUnregister, int32_t &uid);
146     void Sleep(int32_t seconds);
147     ErrCode CallRegisterBundleEventCallback(sptr<BundleEventCallbackImpl> bundleEventCallback);
148     ErrCode CallUnRegisterBundleEventCallback(sptr<BundleEventCallbackImpl> bundleEventCallback);
149     ErrCode CheckGetGroupIdCorrectOption(int32_t option, std::string &dataGroupId);
150     bool GetGroupDir(const std::string &dataGroupId, std::string& msg);
151 };
152 }  // namespace AppExecFwk
153 }  // namespace OHOS
154 
155 #endif  // FFOUNDATION_BUNDLEMANAGER_BUNDLE_FRAMEWORK_BUNDLE_TOOL_INCLUDE_BUNDLE_TEST_TOOL_H