• 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_APPEXECFWK_SERVICES_BUNDLEMGR_INCLUDE_BUNDLE_INSTALL_CHECKER_H
17 #define FOUNDATION_APPEXECFWK_SERVICES_BUNDLEMGR_INCLUDE_BUNDLE_INSTALL_CHECKER_H
18 
19 #include <memory>
20 #include <string>
21 #include <vector>
22 
23 #include "app_privilege_capability.h"
24 #include "appexecfwk_errors.h"
25 #include "bundle_pack_info.h"
26 #include "bundle_verify_mgr.h"
27 #include "inner_bundle_info.h"
28 
29 namespace OHOS {
30 namespace AppExecFwk {
31 struct InstallCheckParam {
32     bool isPreInstallApp = false;
33     bool removable = true;
34     Constants::AppType appType = Constants::AppType::THIRD_PARTY_APP;
35     int64_t crowdtestDeadline = Constants::INVALID_CROWDTEST_DEADLINE; // for crowdtesting type hap
36 };
37 
38 class BundleInstallChecker {
39 public:
40     /**
41      * @brief Check syscap.
42      * @param bundlePaths Indicates the file paths of all HAP packages.
43      * @return Returns ERR_OK if the syscap satisfy; returns error code otherwise.
44      */
45     ErrCode CheckSysCap(const std::vector<std::string> &bundlePaths);
46 
47     /**
48      * @brief Check signature info of multiple haps.
49      * @param bundlePaths Indicates the file paths of all HAP packages.
50      * @param hapVerifyRes Indicates the signature info.
51      * @return Returns ERR_OK if the every hap has signature info and all haps have same signature info.
52      */
53     ErrCode CheckMultipleHapsSignInfo(
54         const std::vector<std::string> &bundlePaths,
55         std::vector<Security::Verify::HapVerifyResult> &hapVerifyRes);
56 
57     /**
58      * @brief To check the hap hash param.
59      * @param infos .Indicates all innerBundleInfo for all haps need to be installed.
60      * @param hashParams .Indicates all hashParams in installParam.
61      * @return Returns ERR_OK if haps checking successfully; returns error code otherwise.
62      */
63     ErrCode CheckHapHashParams(
64         std::unordered_map<std::string, InnerBundleInfo> &infos,
65         std::map<std::string, std::string> hashParams);
66 
67     /**
68      * @brief To check the version code and bundleName in all haps.
69      * @param infos .Indicates all innerBundleInfo for all haps need to be installed.
70      * @return Returns ERR_OK if haps checking successfully; returns error code otherwise.
71      */
72     ErrCode CheckAppLabelInfo(const std::unordered_map<std::string, InnerBundleInfo> &infos);
73     /**
74      * @brief To check native file in all haps.
75      * @param infos .Indicates all innerBundleInfo for all haps need to be installed.
76      * @return Returns ERR_OK if haps checking successfully; returns error code otherwise.
77      */
78     ErrCode CheckMultiNativeFile(std::unordered_map<std::string, InnerBundleInfo> &infos);
79     /**
80      * @brief To check ark native file in all haps.
81      * @param infos .Indicates all innerBundleInfo for all haps need to be installed.
82      * @return Returns ERR_OK if haps checking successfully; returns error code otherwise.
83      */
84     ErrCode CheckMultiArkNativeFile(std::unordered_map<std::string, InnerBundleInfo> &infos);
85     /**
86      * @brief To check native so in all haps.
87      * @param infos .Indicates all innerBundleInfo for all haps need to be installed.
88      * @return Returns ERR_OK if haps checking successfully; returns error code otherwise.
89      */
90     ErrCode CheckMultiNativeSo(std::unordered_map<std::string, InnerBundleInfo> &infos);
91     /**
92      * @brief To parse hap files and to obtain innerBundleInfo of each hap.
93      * @param bundlePaths Indicates the file paths of all HAP packages.
94      * @param checkParam Indicates the install check parameters.
95      * @param hapVerifyRes Indicates all signature info of all haps.
96      * @param infos Indicates the innerBundleinfo of each hap.
97      * @return Returns ERR_OK if each hap is parsed successfully; returns error code otherwise.
98      */
99     ErrCode ParseHapFiles(
100         const std::vector<std::string> &bundlePaths,
101         const InstallCheckParam &checkParam,
102         std::vector<Security::Verify::HapVerifyResult> &hapVerifyRes,
103         std::unordered_map<std::string, InnerBundleInfo> &infos);
104     /**
105      * @brief To check dependency whether or not exists.
106      * @param infos Indicates all innerBundleInfo for all haps need to be installed.
107      * @return Returns ERR_OK if haps checking successfully; returns error code otherwise.
108      */
109     ErrCode CheckDependency(std::unordered_map<std::string, InnerBundleInfo> &infos);
110 
111     void ResetProperties();
112 
IsContainEntry()113     bool IsContainEntry()
114     {
115         return isContainEntry_;
116     }
117 
118     ErrCode CheckModuleNameForMulitHaps(const std::unordered_map<std::string, InnerBundleInfo> &infos) const;
119 
120     bool IsExistedDistroModule(const InnerBundleInfo &newInfo, const InnerBundleInfo &info) const;
121 
122     bool IsContainModuleName(const InnerBundleInfo &newInfo, const InnerBundleInfo &info) const;
123 
124     ErrCode CheckDeviceType(std::unordered_map<std::string, InnerBundleInfo> &infos) const;
125 
126 private:
127 
128     ErrCode ParseBundleInfo(
129         const std::string &bundleFilePath,
130         InnerBundleInfo &info,
131         BundlePackInfo &packInfo) const;
132 
133     ErrCode CheckSystemSize(
134         const std::string &bundlePath,
135         const Constants::AppType appType) const;
136 
137     void SetEntryInstallationFree(
138         const BundlePackInfo &bundlePackInfo,
139         InnerBundleInfo &innerBundleInfo);
140 
141     void SetPackInstallationFree(BundlePackInfo &bundlePackInfo, const InnerBundleInfo &innerBundleInfo) const;
142 
143     void CollectProvisionInfo(
144         const Security::Verify::ProvisionInfo &provisionInfo,
145         const AppPrivilegeCapability &appPrivilegeCapability,
146         InnerBundleInfo &newInfo);
147 
148     void GetPrivilegeCapability(
149         const InstallCheckParam &checkParam, InnerBundleInfo &newInfo);
150 
151     void ParseAppPrivilegeCapability(
152         const Security::Verify::ProvisionInfo &provisionInfo,
153         AppPrivilegeCapability &appPrivilegeCapability);
154 
155     ErrCode CheckMainElement(const InnerBundleInfo &info);
156 
157     ErrCode CheckBundleName(const std::string &provisionInfoBundleName, const std::string &bundleName);
158 
159     void FetchPrivilegeCapabilityFromPreConfig(
160         const std::string &bundleName,
161         const std::string &appSignature,
162         AppPrivilegeCapability &appPrivilegeCapability);
163 
164     bool MatchSignature(const std::vector<std::string> &appSignatures, const std::string &signature);
165 
166     bool GetPrivilegeCapabilityValue(const std::vector<std::string> &existInJson,
167         const std::string &key, bool existInPreJson, bool existInProvision);
168 
169     ErrCode ProcessBundleInfoByPrivilegeCapability(const AppPrivilegeCapability &appPrivilegeCapability,
170         InnerBundleInfo &innerBundleInfo);
171 
172     bool NeedCheckDependency(const Dependency &dependency, const InnerBundleInfo &info);
173 
174     bool FindModuleInInstallingPackage(
175         const std::string &moduleName,
176         const std::string &bundleName,
177         const std::unordered_map<std::string, InnerBundleInfo> &infos);
178 
179     bool FindModuleInInstalledPackage(
180         const std::string &moduleName,
181         const std::string &bundleName,
182         uint32_t versionCode);
183 
184     bool isContainEntry_ = false;
185 
186     void SetAppProvisionMetadata(const std::vector<Security::Verify::Metadata> &provisionMetadatas,
187         InnerBundleInfo &newInfo);
188 };
189 }  // namespace AppExecFwk
190 }  // namespace OHOS
191 #endif  // FOUNDATION_APPEXECFWK_SERVICES_BUNDLEMGR_INCLUDE_BUNDLE_INSTALL_CHECKER_H