• 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_MODULE_JSON_H
17 #define DEVELOPTOOLS_PACKING_TOOL_APT_FRAMEWORKS_INCLUDE_MODULE_JSON_H
18 
19 #include <filesystem>
20 #include <list>
21 #include <memory>
22 #include <string>
23 
24 #include "hap_verify_info.h"
25 #include "module_api_version.h"
26 #include "module_metadata_info.h"
27 #include "normalize_version.h"
28 #include "pt_json.h"
29 #include "version.h"
30 
31 namespace OHOS {
32 namespace AppPackingTool {
33 class ModuleJson {
34 public:
ModuleJson()35     ModuleJson() {};
~ModuleJson()36     virtual ~ModuleJson() {};
37 
38     bool ParseFromString(const std::string& jsonString);
39     bool ParseFromFile(const std::string& jsonFile);
40     std::string ToString();
41     void Release();
42 
43     bool IsValid();
44 
45     // object funcs
46     bool GetAppObject(std::unique_ptr<PtJson>& appObj);
47     bool GetDeviceConfigObject(std::unique_ptr<PtJson>& deviceConfigObj);
48     bool GetVersionObject(std::unique_ptr<PtJson>& versionObj);
49     bool GetModuleObject(std::unique_ptr<PtJson>& moduleObj);
50     bool GetDistroObject(std::unique_ptr<PtJson>& distroObj);
51     bool GetDistroObjectByModuleObj(std::unique_ptr<PtJson>& moduleObj, std::unique_ptr<PtJson>& distroObj);
52     bool GetApiVersionObject(std::unique_ptr<PtJson>& apiVersionObj);
53 
54     // stage funcs, module.json
55     bool GetStageVersion(Version& version);
56     bool GetStageVersionByAppObj(std::unique_ptr<PtJson>& appObj, Version& version);
57     bool SetStageVersionCode(const int32_t& versionCode);
58     bool SetStageVersionName(const std::string& versionName);
59     bool GetStageModuleApiVersion(ModuleApiVersion& moduleApiVersion);
60     bool GetStageModuleApiVersionByAppObj(std::unique_ptr<PtJson>& appObj, ModuleApiVersion& moduleApiVersion);
61     bool GetStageModuleName(std::string& moduleName);
62     bool GetStageModuleNameByModuleObj(std::unique_ptr<PtJson>& moduleObj, std::string& moduleName);
63     bool GetStageEntry(std::list<std::string>& deviceTypes);
64     bool GetStageDeviceTypes(std::list<std::string>& deviceTypes);
65     bool GetStageDeviceTypesByModuleObj(std::unique_ptr<PtJson>& moduleObj, std::list<std::string>& deviceTypes);
66     bool GetStageHapVerifyInfo(HapVerifyInfo& hapVerifyInfo);
67     bool GetStageDistroFilter(DistroFilter& distroFilter,
68         const std::map<std::string, std::string>& resourceMap);
69     bool GetStageDistroFilterByModuleObj(std::unique_ptr<PtJson>& moduleObj,
70         const std::map<std::string, std::string>& resourceMap, DistroFilter& distroFilter);
71     bool GetStageInstallationFree(bool& installationFree);
72     bool GetStageInstallationFreeByModuleObj(std::unique_ptr<PtJson>& moduleObj, bool& installationFree);
73     bool GetStageBundleType(std::string& bundleType);
74     bool GetStageCompileSdkType(std::string& compileSdkType);
75     bool GetStageCompileSdkTypeByAppObj(std::unique_ptr<PtJson>& appObj, std::string& compileSdkType);
76     bool GetStageCompileSdkVersion(std::string& compileSdkVersion);
77     bool GetStageCompileSdkVersionByAppObj(std::unique_ptr<PtJson>& appObj, std::string& compileSdkVersion);
78     bool GetStageModuleType(std::string& moduleType);
79     bool GetStageModuleTypeByModuleObj(std::unique_ptr<PtJson>& moduleObj, std::string& moduleType);
80     bool GetStageDebug(bool& debug);
81     bool GetStageDebugByAppObj(std::unique_ptr<PtJson>& appObj, bool& debug);
82     bool GetStageAsanEnabled(bool& asanEnabled);
83     bool GetStageAsanEnabledByAppObj(std::unique_ptr<PtJson>& appObj, bool& asanEnabled);
84     bool GetStageTsanEnabled(bool& tsanEnabled);
85     bool GetStageTsanEnabledByAppObj(std::unique_ptr<PtJson>& appObj, bool& tsanEnabled);
86     bool GetStageApiReleaseType(std::string& apiReleaseType);
87     bool GetStageApiReleaseTypeByAppObj(std::unique_ptr<PtJson>& appObj, std::string& apiReleaseType);
88     bool GetStageCompressNativeLibs(bool& compressNativeLibs);
89     bool GetStageCompressNativeLibsByAppObj(std::unique_ptr<PtJson>& appObj, bool& compressNativeLibs);
90     bool GetAbilityContinueTypeMap(std::map<std::string, std::list<std::string>>& abilityContinueTypeMap);
91     bool GetAbilityContinueTypeMapByModuleObj(std::unique_ptr<PtJson>& moduleObj,
92         std::map<std::string, std::list<std::string>>& abilityContinueTypeMap);
93     bool GetExtensionAbilityNames(std::list<std::string>& extensionAbilityNames);
94     bool GetExtensionAbilityNamesByModuleObj(std::unique_ptr<PtJson>& moduleObj,
95         std::list<std::string>& extensionAbilityNames);
96     bool GetModuleMetadatas(std::list<ModuleMetadataInfo>& moduleMetadataInfos,
97         const std::map<std::string, std::string>& resourceMap);
98     bool GetModuleMetadatasByModuleObj(std::unique_ptr<PtJson>& moduleObj,
99         const std::map<std::string, std::string>& resourceMap, std::list<ModuleMetadataInfo>& moduleMetadataInfos);
100     bool ParseModuleMetadatasToDistroFilter(const std::list<ModuleMetadataInfo>& moduleMetadataInfos,
101         DistroFilter& distroFilter);
102 
103     bool IsExistedStageRequestPermissions();
104     bool IsExistedStageModuleTargetPriority();
105     bool IsExistedStageAppTargetPriority();
106 
107     // fa funcs config.json
108     bool GetFaVersion(Version& version);
109     bool GetFaVersionByAppObj(std::unique_ptr<PtJson>& appObj, Version& version);
110     bool GetFaVersionByVersionObj(std::unique_ptr<PtJson>& versionObj, Version& version);
111     bool SetFaVersionCode(const int32_t& versionCode);
112     bool SetFaVersionName(const std::string& versionName);
113     bool GetFaInstallationFree(bool& installationFree);
114     bool GetFaInstallationFreeByModuleObj(std::unique_ptr<PtJson>& moduleObj, bool& installationFree);
115     bool GetFaInstallationFreeByDistroObj(std::unique_ptr<PtJson>& distroObj, bool& installationFree);
116     bool GetFaBundleType(std::string& bundleType);
117     bool GetFaModuleApiVersion(ModuleApiVersion& moduleApiVersion);
118     bool GetFaModuleApiVersionByAppObj(std::unique_ptr<PtJson>& appObj, ModuleApiVersion& moduleApiVersion);
119     bool GetFaModuleApiVersionByApiVersionObj(std::unique_ptr<PtJson>& apiVersionObj,
120         ModuleApiVersion& moduleApiVersion);
121     bool GetFaModuleName(std::string& faModuleName);
122     bool GetFaModuleNameByModuleObj(std::unique_ptr<PtJson>& moduleObj, std::string& faModuleName);
123     bool GetFaModuleNameByDistroObj(std::unique_ptr<PtJson>& distroObj, std::string& faModuleName);
124     bool GetFaPackageStr(std::string& packageStr);
125     bool GetFaPackageStrByModuleObj(std::unique_ptr<PtJson>& moduleObj, std::string& packageStr);
126     bool GetFaEntry(std::list<std::string>& deviceTypes);
127     bool GetFaDeviceTypes(std::list<std::string>& deviceTypes);
128     bool GetFaDeviceTypesByModuleObj(std::unique_ptr<PtJson>& moduleObj, std::list<std::string>& deviceTypes);
129     bool GetFaHapVerifyInfo(HapVerifyInfo& hapVerifyInfo);
130     bool GetFaDistroFilter(DistroFilter& distroFilter);
131     bool GetFaDistroFilterByModuleObj(std::unique_ptr<PtJson>& moduleObj, DistroFilter& distroFilter);
132     bool GetFaCompileSdkType(std::string& compileSdkType);
133     bool GetFaCompileSdkTypeByAppObj(std::unique_ptr<PtJson>& appObj, std::string& compileSdkType);
134     bool GetFaCompileSdkVersion(std::string& compileSdkVersion);
135     bool GetFaCompileSdkVersionByAppObj(std::unique_ptr<PtJson>& appObj, std::string& compileSdkVersion);
136     bool GetFaModuleType(std::string& moduleType);
137     bool GetFaModuleTypeByModuleObj(std::unique_ptr<PtJson>& moduleObj, std::string& moduleType);
138     bool GetFaDebug(bool& debug);
139     bool GetFaDebugByDeviceConfigObj(std::unique_ptr<PtJson>& deviceConfigObj, bool& debug);
140     bool GetFaAsanEnabled(bool& asanEnabled);
141     bool GetFaAsanEnabledByAppObj(std::unique_ptr<PtJson>& appObj, bool& asanEnabled);
142     bool GetFaReleaseType(std::string& releaseType);
143     bool GetFaReleaseTypeByAppObj(std::unique_ptr<PtJson>& appObj, std::string& releaseType);
144 
145     // common funcs
146     bool GetBundleName(std::string& bundleName);
147     bool GetBundleNameByAppObj(std::unique_ptr<PtJson>& appObj, std::string& bundleName);
148     bool SetBundleName(const std::string& bundleName);
149     bool GetModuleName(std::string& moduleName);
150     bool GetModuleNameByModuleObj(std::unique_ptr<PtJson>& moduleObj, std::string& moduleName);
151     bool GetVendor(std::string& vendor);
152     bool GetVendorByAppObj(std::unique_ptr<PtJson>& appObj, std::string& vendor);
153     bool GetTargetBundleName(std::string& targetBundleName);
154     bool GetTargetBundleNameByAppObj(std::unique_ptr<PtJson>& appObj, std::string& targetBundleName);
155     bool GetTargetModuleName(std::string& targetModuleName);
156     bool GetTargetModuleNameByModuleObj(std::unique_ptr<PtJson>& moduleObj, std::string& targetModuleName);
157     bool GetTargetPriority(int32_t& targetPriority);
158     bool GetTargetPriorityByAppObj(std::unique_ptr<PtJson>& appObj, int32_t& targetPriority);
159     bool GetTargetModulePriority(int32_t& targetModulePriority);
160     bool GetTargetModulePriorityByModuleObj(std::unique_ptr<PtJson>& moduleObj, int32_t& targetModulePriority);
161     // config.json or module.json
162     bool GetAbilityNames(std::list<std::string>& abilityNames);
163     bool GetAbilityNamesByModuleObj(std::unique_ptr<PtJson>& moduleObj, std::list<std::string>& abilityNames);
164     // unknown
165     bool GetDependencyItems(std::list<DependencyItem>& dependencyItems, const std::string& defaultBundleName);
166     bool GetDependencyItemsByModuleObj(std::unique_ptr<PtJson>& moduleObj, std::list<DependencyItem>& dependencyItems,
167         const std::string& defaultBundleName);
168     bool GetAtomicServicePreloads(std::list<PreloadItem>& preloadItems);
169     bool GetAtomicServicePreloadsByModuleObj(std::unique_ptr<PtJson>& moduleObj, std::list<PreloadItem>& preloadItems);
170     bool GetProxyDataUris(std::list<std::string>& proxyDataUris);
171     bool GetProxyDataUrisByModuleObj(std::unique_ptr<PtJson>& moduleObj, std::list<std::string>& proxyDataUris);
172     bool GetProxyDataUrisByProxyDatasObj(std::unique_ptr<PtJson>& proxyDatasObj,
173         std::list<std::string>& proxyDataUris);
174 
175     bool GetAssetAccessGroups(std::list<std::string>& assetAccessGroups);
176     bool GetAssetAccessGroupsByModuleObj(std::unique_ptr<PtJson>& moduleObj, std::list<std::string>& assetAccessGroups);
177 
178     bool GetMultiAppMode(MultiAppMode& multiAppMode);
179     bool GetMultiAppModeByAppObj(std::unique_ptr<PtJson>& appObj, MultiAppMode& multiAppMode);
180 
181     bool IsModuleAtomicServiceValid();
182     bool CheckEntryInAtomicService();
183     bool CheckAtomicServiceInstallationFree();
184     bool CheckStageAsanTsanEnabledValid();
185     bool CheckStageAtomicService();
186     bool CheckStageOverlayCfg();
187 
188     bool GetGenerateBuildHash(bool& generateBuildHash);
189     bool RemoveGenerateBuildHash();
190     bool RemoveGenerateBuildHashFromAppObj();
191     bool RemoveGenerateBuildHashFromModuleObj();
192 
193     bool GetNormalizeVersion(NormalizeVersion& normalizeVersion, const bool& isStage = true);
194     bool SetVersionCodeAndName(const int32_t& versionCode, const std::string& versionName, const bool& isStage = true);
195 
196     bool SetBuildHash(const std::string& buildHash);
197 
198     // json function for hqf
199     bool GetPatchModuleName(std::string& patchModuleName);
200 
201 protected:
202     bool CheckStageBundleType(const std::string& moduleName, const std::string& moduleType,
203         const std::string& bundleType, const bool& installationFree);
204     bool GetAbilityNameByAbilityObj(std::unique_ptr<PtJson>& abilityObj, std::string& abilityName);
205     bool GetContinueTypesByAbilityObj(std::unique_ptr<PtJson>& abilityObj, std::list<std::string>& continueTypes);
206     bool GetDependencyBundleNameByDependencyItemObj(std::unique_ptr<PtJson>& dependencyItemObj,
207         std::string& bundleName, const std::string& defaultBundleName);
208     bool GetDependencyModuleNameByDependencyItemObj(std::unique_ptr<PtJson>& dependencyItemObj,
209         std::string& moduleName);
210     bool GetModuleMetadataInfoByModuleMetadataInfoObj(std::unique_ptr<PtJson>& moduleMetadataInfoObj,
211         const std::map<std::string, std::string>& resourceMap, ModuleMetadataInfo& moduleMetadataInfo);
212     bool GetExtensionAbilityNamesByExtensionAbilityObj(std::unique_ptr<PtJson>& extensionAbilitiesObj,
213         std::list<std::string>& extensionAbilityNames);
214     bool GetAbilityNamesByAbilitiesObj(std::unique_ptr<PtJson>& abilitiesObj, std::list<std::string>& abilityNames);
215     bool SetStageHapVerifyInfoByAppObj(std::unique_ptr<PtJson>& appObj, HapVerifyInfo& hapVerifyInfo);
216     bool SetStageHapVerifyInfoByModuleObj(std::unique_ptr<PtJson>& moduleObj, HapVerifyInfo& hapVerifyInfo);
217     bool SetStageHapVerifyInfoExtByModuleObj(std::unique_ptr<PtJson>& moduleObj, HapVerifyInfo& hapVerifyInfo);
218     bool SetFaHapVerifyInfoByAppObj(std::unique_ptr<PtJson>& appObj, HapVerifyInfo& hapVerifyInfo);
219     bool SetFaHapVerifyInfoByModuleObj(std::unique_ptr<PtJson>& moduleObj, HapVerifyInfo& hapVerifyInfo);
220 
221 private:
222     std::unique_ptr<PtJson> root_ = nullptr;
223 };
224 }  // namespace AppPackingTool
225 }  // namespace OHOS
226 #endif  // DEVELOPTOOLS_PACKING_TOOL_APT_FRAMEWORKS_INCLUDE_MODULE_JSON_H
227