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 static bool CheckFileSizeIsValid(const std::list<HapVerifyInfo>& hapVerifyInfos); 73 74 private: 75 static bool CheckAppFieldsIsSame(const std::list<HapVerifyInfo>& hapVerifyInfos); 76 static bool CheckIsPluginApp(const std::list<HapVerifyInfo>& hapVerifyInfos); 77 static bool AppFieldsIsSame(const VerifyCollection& verifyCollection, const HapVerifyInfo& hapVerifyInfo); 78 static bool IsEntryOrFeature(const std::string& moduleType); 79 static bool CheckModuleNameIsValid(const std::list<HapVerifyInfo>& hapVerifyInfos); 80 static bool CheckDuplicatedIsValid(const HapVerifyInfo& hapVerifyInfo1, const HapVerifyInfo& hapVerifyInfo2); 81 static bool CheckDistroFilterDisjoint(const DistroFilter& distroFilter1, const DistroFilter& distroFilter2); 82 static bool CheckPolicyValueDisjoint(const PolicyValue& policyValue1, const PolicyValue& policyValue2); 83 static bool CheckPackageNameIsValid(const std::list<HapVerifyInfo>& hapVerifyInfos); 84 static void ShowCheckTips(const HapVerifyInfo& hapVerifyInfo1, const HapVerifyInfo& hapVerifyInfo2, 85 const std::string& tip); 86 static bool CheckEntryIsValid(const std::list<HapVerifyInfo>& hapVerifyInfos); 87 static void ClassifyEntry(const std::list<HapVerifyInfo>& entryHapVerifyInfos, 88 std::map<std::string, std::list<HapVerifyInfo>>& deviceHaps); 89 static bool CheckFeature(const HapVerifyInfo& featureHap, 90 const std::map<std::string, std::list<HapVerifyInfo>>& deviceHap); 91 static bool CheckFeatureDistroFilter(const HapVerifyInfo& featureHap, 92 const std::list<HapVerifyInfo>& entryHaps); 93 static bool CheckApiVersionCovered(const ApiVersion& apiVersion, 94 const std::list<HapVerifyInfo>& entryHaps); 95 static bool CheckScreenShapeCovered(const ScreenShape& screenShape, 96 const std::list<HapVerifyInfo>& entryHaps); 97 static bool CheckScreenWindowCovered(const ScreenWindow& screenWindow, 98 const std::list<HapVerifyInfo>& entryHaps); 99 static bool CheckScreenDensityCovered(const ScreenDensity& screenDensity, 100 const std::list<HapVerifyInfo>& entryHaps); 101 static bool CheckCountryCodeCovered(const CountryCode& countryCode, 102 const std::list<HapVerifyInfo>& entryHaps); 103 static bool CheckEntryPolicyValueCoverAll(const std::list<std::string>& include, 104 const std::list<std::string>& exclude); 105 static bool CheckPolicyValueCovered(const PolicyValue& policyValue, 106 const std::list<std::string>& include, std::list<std::string>& exclude); 107 static bool CheckCoveredExcludePolicyValue(const std::list<std::string>& value, 108 const std::list<std::string>& include, std::list<std::string>& exclude); 109 static bool CheckCoveredIncludePolicyValue(const std::list<std::string>& value, 110 const std::list<std::string>& include, std::list<std::string>& exclude); 111 static bool CheckDependencyIsValid(const std::list<HapVerifyInfo>& hapVerifyInfos); 112 static bool DfsTraverseDependency(const HapVerifyInfo& hapVerifyInfo, 113 const std::list<HapVerifyInfo>& hapVerifyInfos, std::list<HapVerifyInfo>& dependencyList); 114 static bool CheckDependencyListCirculate(const std::list<HapVerifyInfo>& dependencyList); 115 static bool IsSameHapVerifyInfo(const HapVerifyInfo& hapVerifyInfo1, const HapVerifyInfo& hapVerifyInfo2); 116 static bool CheckModuleJoint(const HapVerifyInfo& infoLeft, const HapVerifyInfo& infoRight); 117 static void GetHapVerifyInfosNames(const std::list<HapVerifyInfo>& hapVerifyInfos, 118 std::list<std::string>& moduleNames); 119 static bool CheckDependencyInFileList(const DependencyItem& dependencyItem, 120 const std::list<HapVerifyInfo>& hapVerifyInfos); 121 static void GetLayerHapVerifyInfos(const std::string& moduleName, const HapVerifyInfo& hapVerifyInfo, 122 const std::list<HapVerifyInfo>& hapVerifyInfos, std::list<HapVerifyInfo>& layerHapVerifyInfos); 123 static bool CheckAtomicServiceIsValid(const std::list<HapVerifyInfo>& hapVerifyInfos); 124 static bool GetDeviceHapVerifyInfoMap(const std::list<HapVerifyInfo>& hapVerifyInfos, 125 std::map<std::string, std::list<HapVerifyInfo>>& deviceInfoMap); 126 static bool CheckAtomicServicePreloadsIsValid(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 ModuleDebugValidation(const std::list<HapVerifyInfo> hapList, const std::list<HapVerifyInfo> hspList); 140 static bool AppFieldsIsValid(const std::list<HapVerifyInfo>& hapVerifyInfos, 141 int32_t minCompatibleVersionCode, int32_t targetApiVersion, int32_t minApiVersion); 142 static bool AppAssetAccessGroupsIsSame(const std::list<std::string>& assetAccessGroups, 143 const HapVerifyInfo& hapVerifyInfo); 144 }; 145 } // namespace AppPackingTool 146 } // namespace OHOS 147 #endif // DEVELOPTOOLS_PACKING_TOOL_APT_FRAMEWORKS_INCLUDE_HAP_VERIFY_UTILS_H 148