• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2024 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 DEVELOPTOOLS_PACKING_TOOL_APT_FRAMEWORKS_INCLUDE_HAP_VERIFY_UTILS_H
17 #define DEVELOPTOOLS_PACKING_TOOL_APT_FRAMEWORKS_INCLUDE_HAP_VERIFY_UTILS_H
18 
19 #include <list>
20 #include <map>
21 #include <string>
22 
23 #include "distro_filter.h"
24 #include "hap_verify_info.h"
25 #include "multi_app_mode.h"
26 
27 namespace OHOS {
28 namespace AppPackingTool {
29 struct VerifyCollection {
30     std::string bundleName = "";
31     std::string vendor = "";
32     int32_t versionCode = -1;
33     std::string versionName = "";
34     int32_t minCompatibleVersionCode = -1;
35     int32_t compatibleApiVersion = -1;
36     int32_t targetApiVersion = -1;
37     std::string releaseType = "";
38     std::string targetBundleName = "";
39     int32_t targetPriority = 0;
40     bool debug = false;
41     std::list<std::string> moduleNames;
42     std::list<std::string> packageNames;
43     std::list<std::string> assetAccessGroups;
44 
45     bool split = true;
46     std::string main = "";
47     bool sharedApp = false;
48     std::string bundleType = "app";
49     std::string moduleName = "";
50     std::string moduleType = "";
51     MultiAppMode multiAppMode;
52 };
53 
54 enum PolicyValueType {
55     API_VERSION = 0,
56     SCREEN_SHAPE,
57     SCREEN_DENSITY,
58     SCREEN_WINDOW,
59     COUNTRY_CODE
60 };
61 
62 class HapVerifyUtils {
63 public:
HapVerifyUtils()64     HapVerifyUtils() {};
~HapVerifyUtils()65     virtual ~HapVerifyUtils() {};
66 
67     HapVerifyUtils(const HapVerifyUtils &) = delete;
68     HapVerifyUtils &operator=(const HapVerifyUtils &) = delete;
69 
70     static bool CheckHapIsValid(const std::list<HapVerifyInfo>& hapVerifyInfos);
71     static bool CheckSharedAppIsValid(const std::list<HapVerifyInfo>& hapVerifyInfos);
72 
73 private:
74     static bool CheckAppFieldsIsSame(const std::list<HapVerifyInfo>& hapVerifyInfos);
75     static bool CheckIsPluginApp(const std::list<HapVerifyInfo>& hapVerifyInfos);
76     static bool AppFieldsIsSame(const VerifyCollection& verifyCollection, const HapVerifyInfo& hapVerifyInfo);
77     static bool IsEntryOrFeature(const std::string& moduleType);
78     static bool CheckModuleNameIsValid(const std::list<HapVerifyInfo>& hapVerifyInfos);
79     static bool CheckDuplicatedIsValid(const HapVerifyInfo& hapVerifyInfo1, const HapVerifyInfo& hapVerifyInfo2);
80     static bool CheckDistroFilterDisjoint(const DistroFilter& distroFilter1, const DistroFilter& distroFilter2);
81     static bool CheckPolicyValueDisjoint(const PolicyValue& policyValue1, const PolicyValue& policyValue2);
82     static bool CheckPackageNameIsValid(const std::list<HapVerifyInfo>& hapVerifyInfos);
83     static void ShowCheckTips(const HapVerifyInfo& hapVerifyInfo1, const HapVerifyInfo& hapVerifyInfo2,
84         const std::string& tip);
85     static bool CheckEntryIsValid(const std::list<HapVerifyInfo>& hapVerifyInfos);
86     static void ClassifyEntry(const std::list<HapVerifyInfo>& entryHapVerifyInfos,
87         std::map<std::string, std::list<HapVerifyInfo>>& deviceHaps);
88     static bool CheckFeature(const HapVerifyInfo& featureHap,
89         const std::map<std::string, std::list<HapVerifyInfo>>& deviceHap);
90     static bool CheckFeatureDistroFilter(const HapVerifyInfo& featureHap,
91         const std::list<HapVerifyInfo>& entryHaps);
92     static bool CheckApiVersionCovered(const ApiVersion& apiVersion,
93         const std::list<HapVerifyInfo>& entryHaps);
94     static bool CheckScreenShapeCovered(const ScreenShape& screenShape,
95         const std::list<HapVerifyInfo>& entryHaps);
96     static bool CheckScreenWindowCovered(const ScreenWindow& screenWindow,
97         const std::list<HapVerifyInfo>& entryHaps);
98     static bool CheckScreenDensityCovered(const ScreenDensity& screenDensity,
99         const std::list<HapVerifyInfo>& entryHaps);
100     static bool CheckCountryCodeCovered(const CountryCode& countryCode,
101         const std::list<HapVerifyInfo>& entryHaps);
102     static bool CheckEntryPolicyValueCoverAll(const std::list<std::string>& include,
103         const std::list<std::string>& exclude);
104     static bool CheckPolicyValueCovered(const PolicyValue& policyValue,
105         const std::list<std::string>& include, std::list<std::string>& exclude);
106     static bool CheckCoveredExcludePolicyValue(const std::list<std::string>& value,
107         const std::list<std::string>& include, std::list<std::string>& exclude);
108     static bool CheckCoveredIncludePolicyValue(const std::list<std::string>& value,
109         const std::list<std::string>& include, std::list<std::string>& exclude);
110     static bool CheckDependencyIsValid(const std::list<HapVerifyInfo>& hapVerifyInfos);
111     static bool DfsTraverseDependency(const HapVerifyInfo& hapVerifyInfo,
112         const std::list<HapVerifyInfo>& hapVerifyInfos, std::list<HapVerifyInfo>& dependencyList);
113     static bool CheckDependencyListCirculate(const std::list<HapVerifyInfo>& dependencyList);
114     static bool IsSameHapVerifyInfo(const HapVerifyInfo& hapVerifyInfo1, const HapVerifyInfo& hapVerifyInfo2);
115     static bool CheckModuleJoint(const HapVerifyInfo& infoLeft, const HapVerifyInfo& infoRight);
116     static void GetHapVerifyInfosNames(const std::list<HapVerifyInfo>& hapVerifyInfos,
117         std::list<std::string>& moduleNames);
118     static bool CheckDependencyInFileList(const DependencyItem& dependencyItem,
119         const std::list<HapVerifyInfo>& hapVerifyInfos);
120     static void GetLayerHapVerifyInfos(const std::string& moduleName, const HapVerifyInfo& hapVerifyInfo,
121         const std::list<HapVerifyInfo>& hapVerifyInfos, std::list<HapVerifyInfo>& layerHapVerifyInfos);
122     static bool CheckAtomicServiceIsValid(const std::list<HapVerifyInfo>& hapVerifyInfos);
123     static bool GetDeviceHapVerifyInfoMap(const std::list<HapVerifyInfo>& hapVerifyInfos,
124         std::map<std::string, std::list<HapVerifyInfo>>& deviceInfoMap);
125     static bool CheckAtomicServicePreloadsIsValid(const std::list<HapVerifyInfo>& hapVerifyInfos);
126     static bool CheckFileSizeIsValid(const std::list<HapVerifyInfo>& hapVerifyInfos);
127     static bool CheckAtomicServiceModuleSize(const std::list<HapVerifyInfo>& hapVerifyInfos);
128     static void GetModuleDependency(const HapVerifyInfo& hapVerifyInfo,
129         const std::list<HapVerifyInfo>& hapVerifyInfoList, std::list<std::string>& moduleDependency);
130     static const HapVerifyInfo* FindAtomicServiceHapVerifyInfo(const std::string& moduleName,
131         const std::list<HapVerifyInfo>& hapVerifyInfos);
132     static bool CheckAbilityNameIsValid(const std::list<HapVerifyInfo>& hapVerifyInfos);
133     static bool CheckTargetModuleNameIsExisted(const std::list<HapVerifyInfo>& hapVerifyInfos);
134     static bool CheckCompileSdkIsValid(const std::list<HapVerifyInfo>& hapVerifyInfos);
135     static bool CheckProxyDataUriIsUnique(const std::list<HapVerifyInfo>& hapVerifyInfos);
136     static bool CheckContinueTypeIsValid(const std::list<HapVerifyInfo>& hapVerifyInfos);
137     static bool CheckContinueTypeIsValid(const HapVerifyInfo& hapVerifyInfo);
138     static bool CheckContinueTypeIsValid(const HapVerifyInfo& hapVerifyInfo1, const HapVerifyInfo& hapVerifyInfo2);
139     static bool AppFieldsIsValid(const std::list<HapVerifyInfo>& hapVerifyInfos,
140         int32_t minCompatibleVersionCode, int32_t targetApiVersion);
141     static bool AppAssetAccessGroupsIsSame(const std::list<std::string>& assetAccessGroups,
142         const HapVerifyInfo& hapVerifyInfo);
143 };
144 }  // namespace AppPackingTool
145 }  // namespace OHOS
146 #endif  // DEVELOPTOOLS_PACKING_TOOL_APT_FRAMEWORKS_INCLUDE_HAP_VERIFY_UTILS_H
147