• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2023-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 #include "hap_module_info.h"
17 
18 #include "bundle_constants.h"
19 #include "hilog_tag_wrapper.h"
20 #include "json_util.h"
21 #include "nlohmann/json.hpp"
22 #include "string_ex.h"
23 
24 namespace OHOS {
25 namespace AppExecFwk {
26 namespace {
27 const std::string HAP_MODULE_INFO_NAME = "name";
28 const std::string HAP_MODULE_INFO_PACKAGE = "package";
29 const std::string HAP_MODULE_INFO_DESCRIPTION = "description";
30 const std::string HAP_MODULE_INFO_DESCRIPTION_ID = "descriptionId";
31 const std::string HAP_MODULE_INFO_ICON_PATH = "iconPath";
32 const std::string HAP_MODULE_INFO_ICON_ID = "iconId";
33 const std::string HAP_MODULE_INFO_LABEL = "label";
34 const std::string HAP_MODULE_INFO_LABEL_ID = "labelId";
35 const std::string HAP_MODULE_INFO_BACKGROUND_IMG = "backgroundImg";
36 const std::string HAP_MODULE_INFO_MAIN_ABILITY = "mainAbility";
37 const std::string HAP_MODULE_INFO_SRC_PATH = "srcPath";
38 const std::string HAP_MODULE_INFO_HASH_VALUE = "hashValue";
39 const std::string HAP_MODULE_INFO_SUPPORTED_MODES = "supportedModes";
40 const std::string HAP_MODULE_INFO_REQ_CAPABILITIES = "reqCapabilities";
41 const std::string HAP_MODULE_INFO_DEVICE_TYPES = "deviceTypes";
42 const std::string HAP_MODULE_INFO_ABILITY_INFOS = "abilityInfos";
43 const std::string HAP_MODULE_INFO_COLOR_MODE = "colorMode";
44 const std::string HAP_MODULE_INFO_MAIN_ELEMENTNAME = "mainElementName";
45 const std::string HAP_MODULE_INFO_PAGES = "pages";
46 const std::string HAP_MODULE_INFO_SYSTEM_THEME = "systemTheme";
47 const std::string HAP_MODULE_INFO_PROCESS = "process";
48 const std::string HAP_MODULE_INFO_RESOURCE_PATH = "resourcePath";
49 const std::string HAP_MODULE_INFO_SRC_ENTRANCE = "srcEntrance";
50 const std::string HAP_MODULE_INFO_UI_SYNTAX = "uiSyntax";
51 const std::string HAP_MODULE_INFO_VIRTUAL_MACHINE = "virtualMachine";
52 const std::string HAP_MODULE_INFO_DELIVERY_WITH_INSTALL = "deliveryWithInstall";
53 const std::string HAP_MODULE_INFO_INSTALLATION_FREE = "installationFree";
54 const std::string HAP_MODULE_INFO_IS_MODULE_JSON = "isModuleJson";
55 const std::string HAP_MODULE_INFO_IS_STAGE_BASED_MODEL = "isStageBasedModel";
56 const std::string HAP_MODULE_INFO_IS_REMOVABLE = "isRemovable";
57 const std::string HAP_MODULE_INFO_MODULE_TYPE = "moduleType";
58 const std::string HAP_MODULE_INFO_EXTENSION_INFOS = "extensionInfos";
59 const std::string HAP_MODULE_INFO_META_DATA = "metadata";
60 const std::string HAP_MODULE_INFO_DEPENDENCIES = "dependencies";
61 const std::string HAP_MODULE_INFO_UPGRADE_FLAG = "upgradeFlag";
62 const std::string HAP_MODULE_INFO_HAP_PATH = "hapPath";
63 const std::string HAP_MODULE_INFO_COMPILE_MODE = "compileMode";
64 const std::string HAP_MODULE_INFO_HQF_INFO = "hqfInfo";
65 const std::string HAP_MODULE_INFO_IS_LIB_ISOLATED = "isLibIsolated";
66 const std::string HAP_MODULE_INFO_NATIVE_LIBRARY_PATH = "nativeLibraryPath";
67 const std::string HAP_MODULE_INFO_CPU_ABI = "cpuAbi";
68 const std::string HAP_MODULE_INFO_MODULE_SOURCE_DIR = "moduleSourceDir";
69 const std::string HAP_OVERLAY_MODULE_INFO = "overlayModuleInfos";
70 const std::string HAP_MODULE_INFO_ATOMIC_SERVICE_MODULE_TYPE = "atomicServiceModuleType";
71 const std::string HAP_MODULE_INFO_PRELOADS = "preloads";
72 const std::string PRELOAD_ITEM_MODULE_NAME = "moduleName";
73 const std::string HAP_MODULE_INFO_VERSION_CODE = "versionCode";
74 const std::string HAP_MODULE_INFO_PROXY_DATAS = "proxyDatas";
75 const std::string PROXY_DATA_URI = "uri";
76 const std::string PROXY_DATA_REQUIRED_READ_PERMISSION = "requiredReadPermission";
77 const std::string PROXY_DATA_REQUIRED_WRITE_PERMISSION = "requiredWritePermission";
78 const std::string PROXY_DATA_METADATA = "metadata";
79 const std::string HAP_MODULE_INFO_BUILD_HASH = "buildHash";
80 const std::string HAP_MODULE_INFO_ISOLATION_MODE = "isolationMode";
81 const std::string HAP_MODULE_INFO_AOT_COMPILE_STATUS = "aotCompileStatus";
82 const std::string HAP_MODULE_INFO_COMPRESS_NATIVE_LIBS = "compressNativeLibs";
83 const std::string HAP_MODULE_INFO_NATIVE_LIBRARY_FILE_NAMES = "nativeLibraryFileNames";
84 const std::string HAP_MODULE_INFO_FILE_CONTEXT_MENU = "fileContextMenu";
85 const std::string HAP_MODULE_INFO_ROUTER_MAP = "routerMap";
86 const std::string HAP_MODULE_INFO_ROUTER_ARRAY = "routerArray";
87 
88 const std::string ROUTER_ITEM_KEY_NAME = "name";
89 const std::string ROUTER_ITEM_KEY_PAGE_SOURCE_FILE = "pageSourceFile";
90 const std::string ROUTER_ITEM_KEY_BUILD_FUNCTION = "buildFunction";
91 const std::string ROUTER_ITEM_KEY_DATA = "data";
92 const std::string ROUTER_ITEM_KEY_CUSTOM_DATA = "customData";
93 const std::string ROUTER_ITEM_KEY_OHMURL = "ohmurl";
94 const std::string ROUTER_ITEM_KEY_BUNDLE_NAME = "bundleName";
95 const std::string ROUTER_ITEM_KEY_MODULE_NAME = "moduleName";
96 const std::string HAP_MODULE_INFO_APP_ENVIRONMENTS = "appEnvironments";
97 
98 const std::string APP_ENVIRONMENTS_NAME = "name";
99 const std::string APP_ENVIRONMENTS_VALUE = "value";
100 const std::string HAP_MODULE_INFO_PACKAGE_NAME = "packageName";
101 const std::string HAP_MODULE_ABILITY_SRC_ENTRY_DELEGATOR = "abilitySrcEntryDelegator";
102 const std::string HAP_MODULE_ABILITY_STAGE_SRC_ENTRY_DELEGATOR = "abilityStageSrcEntryDelegator";
103 const std::string HAP_MODULE_INFO_APP_STARTUP = "appStartup";
104 
105 const std::string MODULE_OVERLAY_BUNDLE_NAME = "bundleName";
106 const std::string MODULE_OVERLAY_MODULE_NAME = "moduleName";
107 const std::string MODULE_OVERLAY_HAP_PATH = "hapPath";
108 const std::string MODULE_OVERLAY_PRIORITY = "priority";
109 const std::string MODULE_OVERLAY_STATE = "state";
110 const std::string MODULE_TARGET_MODULE_NAME = "targetModuleName";
111 }
to_json(nlohmann::json & jsonObject,const PreloadItem & preloadItem)112 void to_json(nlohmann::json &jsonObject, const PreloadItem &preloadItem)
113 {
114     jsonObject = nlohmann::json {
115         {PRELOAD_ITEM_MODULE_NAME, preloadItem.moduleName}
116     };
117 }
118 
from_json(const nlohmann::json & jsonObject,PreloadItem & preloadItem)119 void from_json(const nlohmann::json &jsonObject, PreloadItem &preloadItem)
120 {
121     const auto &jsonObjectEnd = jsonObject.end();
122     int32_t parseResult = ERR_OK;
123     GetValueIfFindKey<std::string>(jsonObject,
124         jsonObjectEnd,
125         PRELOAD_ITEM_MODULE_NAME,
126         preloadItem.moduleName,
127         JsonType::STRING,
128         false,
129         parseResult,
130         ArrayType::NOT_ARRAY);
131     if (parseResult != ERR_OK) {
132         TAG_LOGE(AAFwkTag::ABILITY_SIM, "read PreloadItem error:%{public}d", parseResult);
133     }
134 }
135 
to_json(nlohmann::json & jsonObject,const ProxyData & proxyData)136 void to_json(nlohmann::json &jsonObject, const ProxyData &proxyData)
137 {
138     jsonObject = nlohmann::json {
139         {PROXY_DATA_URI, proxyData.uri},
140         {PROXY_DATA_REQUIRED_READ_PERMISSION, proxyData.requiredReadPermission},
141         {PROXY_DATA_REQUIRED_WRITE_PERMISSION, proxyData.requiredWritePermission},
142         {PROXY_DATA_METADATA, proxyData.metadata}
143     };
144 }
145 
from_json(const nlohmann::json & jsonObject,ProxyData & proxyData)146 void from_json(const nlohmann::json &jsonObject, ProxyData &proxyData)
147 {
148     const auto &jsonObjectEnd = jsonObject.end();
149     int32_t parseResult = ERR_OK;
150     GetValueIfFindKey<std::string>(jsonObject,
151         jsonObjectEnd,
152         PROXY_DATA_URI,
153         proxyData.uri,
154         JsonType::STRING,
155         false,
156         parseResult,
157         ArrayType::NOT_ARRAY);
158     GetValueIfFindKey<std::string>(jsonObject,
159         jsonObjectEnd,
160         PROXY_DATA_REQUIRED_READ_PERMISSION,
161         proxyData.requiredReadPermission,
162         JsonType::STRING,
163         false,
164         parseResult,
165         ArrayType::NOT_ARRAY);
166     GetValueIfFindKey<std::string>(jsonObject,
167         jsonObjectEnd,
168         PROXY_DATA_REQUIRED_WRITE_PERMISSION,
169         proxyData.requiredWritePermission,
170         JsonType::STRING,
171         false,
172         parseResult,
173         ArrayType::NOT_ARRAY);
174     GetValueIfFindKey<Metadata>(jsonObject,
175         jsonObjectEnd,
176         PROXY_DATA_METADATA,
177         proxyData.metadata,
178         JsonType::OBJECT,
179         false,
180         parseResult,
181         ArrayType::NOT_ARRAY);
182     if (parseResult != ERR_OK) {
183         TAG_LOGE(AAFwkTag::ABILITY_SIM, "read ProxyData from database error:%{public}d", parseResult);
184     }
185 }
186 
to_json(nlohmann::json & jsonObject,const OverlayModuleInfo & overlayModuleInfo)187 void to_json(nlohmann::json &jsonObject, const OverlayModuleInfo &overlayModuleInfo)
188 {
189     jsonObject = nlohmann::json {
190         {MODULE_OVERLAY_BUNDLE_NAME, overlayModuleInfo.bundleName},
191         {MODULE_OVERLAY_MODULE_NAME, overlayModuleInfo.moduleName},
192         {MODULE_TARGET_MODULE_NAME, overlayModuleInfo.targetModuleName},
193         {MODULE_OVERLAY_HAP_PATH, overlayModuleInfo.hapPath},
194         {MODULE_OVERLAY_PRIORITY, overlayModuleInfo.priority},
195         {MODULE_OVERLAY_STATE, overlayModuleInfo.state}
196     };
197 }
198 
from_json(const nlohmann::json & jsonObject,OverlayModuleInfo & overlayModuleInfo)199 void from_json(const nlohmann::json &jsonObject, OverlayModuleInfo &overlayModuleInfo)
200 {
201     const auto &jsonObjectEnd = jsonObject.end();
202     int32_t parseResult = ERR_OK;
203     GetValueIfFindKey<std::string>(jsonObject,
204         jsonObjectEnd,
205         MODULE_OVERLAY_BUNDLE_NAME,
206         overlayModuleInfo.bundleName,
207         JsonType::STRING,
208         true,
209         parseResult,
210         ArrayType::NOT_ARRAY);
211     GetValueIfFindKey<std::string>(jsonObject,
212         jsonObjectEnd,
213         MODULE_OVERLAY_MODULE_NAME,
214         overlayModuleInfo.moduleName,
215         JsonType::STRING,
216         true,
217         parseResult,
218         ArrayType::NOT_ARRAY);
219     GetValueIfFindKey<std::string>(jsonObject,
220         jsonObjectEnd,
221         MODULE_TARGET_MODULE_NAME,
222         overlayModuleInfo.targetModuleName,
223         JsonType::STRING,
224         true,
225         parseResult,
226         ArrayType::NOT_ARRAY);
227     GetValueIfFindKey<std::string>(jsonObject,
228         jsonObjectEnd,
229         MODULE_OVERLAY_HAP_PATH,
230         overlayModuleInfo.hapPath,
231         JsonType::STRING,
232         true,
233         parseResult,
234         ArrayType::NOT_ARRAY);
235     GetValueIfFindKey<int32_t>(jsonObject,
236         jsonObjectEnd,
237         MODULE_OVERLAY_PRIORITY,
238         overlayModuleInfo.priority,
239         JsonType::NUMBER,
240         true,
241         parseResult,
242         ArrayType::NOT_ARRAY);
243     GetValueIfFindKey<int32_t>(jsonObject,
244         jsonObjectEnd,
245         MODULE_OVERLAY_STATE,
246         overlayModuleInfo.state,
247         JsonType::NUMBER,
248         true,
249         parseResult,
250         ArrayType::NOT_ARRAY);
251     if (parseResult != ERR_OK) {
252         TAG_LOGE(AAFwkTag::ABILITY_SIM, "overlayModuleInfo from_json error : %{public}d", parseResult);
253     }
254 }
255 
to_json(nlohmann::json & jsonObject,const RouterItem & routerItem)256 void to_json(nlohmann::json &jsonObject, const RouterItem &routerItem)
257 {
258     jsonObject = nlohmann::json {
259         {ROUTER_ITEM_KEY_NAME, routerItem.name},
260         {ROUTER_ITEM_KEY_PAGE_SOURCE_FILE, routerItem.pageSourceFile},
261         {ROUTER_ITEM_KEY_BUILD_FUNCTION, routerItem.buildFunction},
262         {ROUTER_ITEM_KEY_DATA, routerItem.data},
263         {ROUTER_ITEM_KEY_CUSTOM_DATA, routerItem.customData},
264         {ROUTER_ITEM_KEY_OHMURL, routerItem.ohmurl},
265         {ROUTER_ITEM_KEY_BUNDLE_NAME, routerItem.bundleName},
266         {ROUTER_ITEM_KEY_MODULE_NAME, routerItem.moduleName}
267     };
268 }
269 
from_json(const nlohmann::json & jsonObject,RouterItem & routerItem)270 void from_json(const nlohmann::json &jsonObject, RouterItem &routerItem)
271 {
272     const auto &jsonObjectEnd = jsonObject.end();
273     int32_t parseResult = ERR_OK;
274     GetValueIfFindKey<std::string>(jsonObject,
275         jsonObjectEnd,
276         ROUTER_ITEM_KEY_NAME,
277         routerItem.name,
278         JsonType::STRING,
279         true,
280         parseResult,
281         ArrayType::NOT_ARRAY);
282     GetValueIfFindKey<std::string>(jsonObject,
283         jsonObjectEnd,
284         ROUTER_ITEM_KEY_PAGE_SOURCE_FILE,
285         routerItem.pageSourceFile,
286         JsonType::STRING,
287         true,
288         parseResult,
289         ArrayType::NOT_ARRAY);
290     GetValueIfFindKey<std::string>(jsonObject,
291         jsonObjectEnd,
292         ROUTER_ITEM_KEY_BUILD_FUNCTION,
293         routerItem.buildFunction,
294         JsonType::STRING,
295         true,
296         parseResult,
297         ArrayType::NOT_ARRAY);
298     GetValueIfFindKey<std::string>(jsonObject,
299         jsonObjectEnd,
300         ROUTER_ITEM_KEY_OHMURL,
301         routerItem.ohmurl,
302         JsonType::STRING,
303         false,
304         parseResult,
305         ArrayType::NOT_ARRAY);
306     GetValueIfFindKey<std::string>(jsonObject,
307         jsonObjectEnd,
308         ROUTER_ITEM_KEY_BUNDLE_NAME,
309         routerItem.bundleName,
310         JsonType::STRING,
311         false,
312         parseResult,
313         ArrayType::NOT_ARRAY);
314     GetValueIfFindKey<std::string>(jsonObject,
315         jsonObjectEnd,
316         ROUTER_ITEM_KEY_MODULE_NAME,
317         routerItem.moduleName,
318         JsonType::STRING,
319         false,
320         parseResult,
321         ArrayType::NOT_ARRAY);
322     GetValueIfFindKey<std::map<std::string, std::string>>(jsonObject,
323         jsonObjectEnd,
324         ROUTER_ITEM_KEY_DATA,
325         routerItem.data,
326         JsonType::OBJECT,
327         false,
328         parseResult,
329         ArrayType::NOT_ARRAY);
330     if (parseResult != ERR_OK) {
331         TAG_LOGE(AAFwkTag::ABILITY_SIM, "read RouterItem jsonObject error : %{public}d", parseResult);
332     }
333 }
334 
to_json(nlohmann::json & jsonObject,const AppEnvironment & appEnvironment)335 void to_json(nlohmann::json &jsonObject, const AppEnvironment &appEnvironment)
336 {
337     jsonObject = nlohmann::json {
338         {APP_ENVIRONMENTS_NAME, appEnvironment.name},
339         {APP_ENVIRONMENTS_VALUE, appEnvironment.value}
340     };
341 }
342 
from_json(const nlohmann::json & jsonObject,AppEnvironment & appEnvironment)343 void from_json(const nlohmann::json &jsonObject, AppEnvironment &appEnvironment)
344 {
345     const auto &jsonObjectEnd = jsonObject.end();
346     int32_t parseResult = ERR_OK;
347     GetValueIfFindKey<std::string>(jsonObject,
348         jsonObjectEnd,
349         APP_ENVIRONMENTS_NAME,
350         appEnvironment.name,
351         JsonType::STRING,
352         false,
353         parseResult,
354         ArrayType::NOT_ARRAY);
355     GetValueIfFindKey<std::string>(jsonObject,
356         jsonObjectEnd,
357         APP_ENVIRONMENTS_VALUE,
358         appEnvironment.value,
359         JsonType::STRING,
360         false,
361         parseResult,
362         ArrayType::NOT_ARRAY);
363     if (parseResult != ERR_OK) {
364         TAG_LOGE(AAFwkTag::ABILITY_SIM, "read AppEnvironment error : %{public}d", parseResult);
365     }
366 }
367 
to_json(nlohmann::json & jsonObject,const HapModuleInfo & hapModuleInfo)368 void to_json(nlohmann::json &jsonObject, const HapModuleInfo &hapModuleInfo)
369 {
370     jsonObject = nlohmann::json {
371         {HAP_MODULE_INFO_NAME, hapModuleInfo.name}, {HAP_MODULE_INFO_PACKAGE, hapModuleInfo.package},
372         {Constants::MODULE_NAME, hapModuleInfo.moduleName}, {HAP_MODULE_INFO_DESCRIPTION, hapModuleInfo.description},
373         {HAP_MODULE_INFO_DESCRIPTION_ID, hapModuleInfo.descriptionId},
374         {HAP_MODULE_INFO_ICON_PATH, hapModuleInfo.iconPath}, {HAP_MODULE_INFO_ICON_ID, hapModuleInfo.iconId},
375         {HAP_MODULE_INFO_LABEL, hapModuleInfo.label}, {HAP_MODULE_INFO_LABEL_ID, hapModuleInfo.labelId},
376         {HAP_MODULE_INFO_BACKGROUND_IMG, hapModuleInfo.backgroundImg},
377         {HAP_MODULE_INFO_MAIN_ABILITY, hapModuleInfo.mainAbility},
378         {HAP_MODULE_INFO_SRC_PATH, hapModuleInfo.srcPath}, {HAP_MODULE_INFO_HASH_VALUE, hapModuleInfo.hashValue},
379         {HAP_MODULE_INFO_HAP_PATH, hapModuleInfo.hapPath},
380         {HAP_MODULE_INFO_SUPPORTED_MODES, hapModuleInfo.supportedModes},
381         {HAP_MODULE_INFO_REQ_CAPABILITIES, hapModuleInfo.reqCapabilities},
382         {HAP_MODULE_INFO_DEVICE_TYPES, hapModuleInfo.deviceTypes},
383         {HAP_MODULE_INFO_ABILITY_INFOS, hapModuleInfo.abilityInfos},
384         {HAP_MODULE_INFO_COLOR_MODE, hapModuleInfo.colorMode}, {Constants::BUNDLE_NAME, hapModuleInfo.bundleName},
385         {HAP_MODULE_INFO_MAIN_ELEMENTNAME, hapModuleInfo.mainElementName}, {HAP_MODULE_INFO_PAGES, hapModuleInfo.pages},
386         {HAP_MODULE_INFO_SYSTEM_THEME, hapModuleInfo.systemTheme},
387         {HAP_MODULE_INFO_PROCESS, hapModuleInfo.process}, {HAP_MODULE_INFO_RESOURCE_PATH, hapModuleInfo.resourcePath},
388         {HAP_MODULE_INFO_SRC_ENTRANCE, hapModuleInfo.srcEntrance}, {HAP_MODULE_INFO_UI_SYNTAX, hapModuleInfo.uiSyntax},
389         {HAP_MODULE_INFO_VIRTUAL_MACHINE, hapModuleInfo.virtualMachine},
390         {HAP_MODULE_INFO_DELIVERY_WITH_INSTALL, hapModuleInfo.deliveryWithInstall},
391         {HAP_MODULE_INFO_INSTALLATION_FREE, hapModuleInfo.installationFree},
392         {HAP_MODULE_INFO_IS_MODULE_JSON, hapModuleInfo.isModuleJson},
393         {HAP_MODULE_INFO_IS_STAGE_BASED_MODEL, hapModuleInfo.isStageBasedModel},
394         {HAP_MODULE_INFO_IS_REMOVABLE, hapModuleInfo.isRemovable},
395         {HAP_MODULE_INFO_UPGRADE_FLAG, hapModuleInfo.upgradeFlag},
396         {HAP_MODULE_INFO_MODULE_TYPE, hapModuleInfo.moduleType},
397         {HAP_MODULE_INFO_EXTENSION_INFOS, hapModuleInfo.extensionInfos},
398         {HAP_MODULE_INFO_META_DATA, hapModuleInfo.metadata},
399         {HAP_MODULE_INFO_DEPENDENCIES, hapModuleInfo.dependencies},
400         {HAP_MODULE_INFO_COMPILE_MODE, hapModuleInfo.compileMode},
401         {HAP_MODULE_INFO_IS_LIB_ISOLATED, hapModuleInfo.isLibIsolated},
402         {HAP_MODULE_INFO_NATIVE_LIBRARY_PATH, hapModuleInfo.nativeLibraryPath},
403         {HAP_MODULE_INFO_CPU_ABI, hapModuleInfo.cpuAbi},
404         {HAP_MODULE_INFO_MODULE_SOURCE_DIR, hapModuleInfo.moduleSourceDir},
405         {HAP_OVERLAY_MODULE_INFO, hapModuleInfo.overlayModuleInfos},
406         {HAP_MODULE_INFO_ATOMIC_SERVICE_MODULE_TYPE, hapModuleInfo.atomicServiceModuleType},
407         {HAP_MODULE_INFO_PRELOADS, hapModuleInfo.preloads},
408         {HAP_MODULE_INFO_PROXY_DATAS, hapModuleInfo.proxyDatas},
409         {HAP_MODULE_INFO_BUILD_HASH, hapModuleInfo.buildHash},
410         {HAP_MODULE_INFO_ISOLATION_MODE, hapModuleInfo.isolationMode},
411         {HAP_MODULE_INFO_AOT_COMPILE_STATUS, hapModuleInfo.aotCompileStatus},
412         {HAP_MODULE_INFO_COMPRESS_NATIVE_LIBS, hapModuleInfo.compressNativeLibs},
413         {HAP_MODULE_INFO_NATIVE_LIBRARY_FILE_NAMES, hapModuleInfo.nativeLibraryFileNames},
414         {HAP_MODULE_INFO_FILE_CONTEXT_MENU, hapModuleInfo.fileContextMenu},
415         {HAP_MODULE_INFO_ROUTER_MAP, hapModuleInfo.routerMap},
416         {HAP_MODULE_INFO_ROUTER_ARRAY, hapModuleInfo.routerArray},
417         {HAP_MODULE_INFO_APP_ENVIRONMENTS, hapModuleInfo.appEnvironments},
418         {HAP_MODULE_INFO_PACKAGE_NAME, hapModuleInfo.packageName},
419         {HAP_MODULE_ABILITY_SRC_ENTRY_DELEGATOR, hapModuleInfo.abilitySrcEntryDelegator},
420         {HAP_MODULE_ABILITY_STAGE_SRC_ENTRY_DELEGATOR, hapModuleInfo.abilityStageSrcEntryDelegator},
421         {HAP_MODULE_INFO_APP_STARTUP, hapModuleInfo.appStartup}
422     };
423 }
424 
from_json(const nlohmann::json & jsonObject,HapModuleInfo & hapModuleInfo)425 void from_json(const nlohmann::json &jsonObject, HapModuleInfo &hapModuleInfo)
426 {
427     const auto &jsonObjectEnd = jsonObject.end();
428     int32_t parseResult = ERR_OK;
429     GetValueIfFindKey<std::string>(jsonObject,
430         jsonObjectEnd,
431         HAP_MODULE_INFO_NAME,
432         hapModuleInfo.name,
433         JsonType::STRING,
434         false,
435         parseResult,
436         ArrayType::NOT_ARRAY);
437     GetValueIfFindKey<std::string>(jsonObject,
438         jsonObjectEnd,
439         HAP_MODULE_INFO_PACKAGE,
440         hapModuleInfo.package,
441         JsonType::STRING,
442         false,
443         parseResult,
444         ArrayType::NOT_ARRAY);
445     GetValueIfFindKey<std::string>(jsonObject,
446         jsonObjectEnd,
447         Constants::MODULE_NAME,
448         hapModuleInfo.moduleName,
449         JsonType::STRING,
450         false,
451         parseResult,
452         ArrayType::NOT_ARRAY);
453     GetValueIfFindKey<std::string>(jsonObject,
454         jsonObjectEnd,
455         HAP_MODULE_INFO_DESCRIPTION,
456         hapModuleInfo.description,
457         JsonType::STRING,
458         false,
459         parseResult,
460         ArrayType::NOT_ARRAY);
461     GetValueIfFindKey<int>(jsonObject,
462         jsonObjectEnd,
463         HAP_MODULE_INFO_DESCRIPTION_ID,
464         hapModuleInfo.descriptionId,
465         JsonType::NUMBER,
466         false,
467         parseResult,
468         ArrayType::NOT_ARRAY);
469     GetValueIfFindKey<std::string>(jsonObject,
470         jsonObjectEnd,
471         HAP_MODULE_INFO_ICON_PATH,
472         hapModuleInfo.iconPath,
473         JsonType::STRING,
474         false,
475         parseResult,
476         ArrayType::NOT_ARRAY);
477     GetValueIfFindKey<int>(jsonObject,
478         jsonObjectEnd,
479         HAP_MODULE_INFO_ICON_ID,
480         hapModuleInfo.iconId,
481         JsonType::NUMBER,
482         false,
483         parseResult,
484         ArrayType::NOT_ARRAY);
485     GetValueIfFindKey<std::string>(jsonObject,
486         jsonObjectEnd,
487         HAP_MODULE_INFO_LABEL,
488         hapModuleInfo.label,
489         JsonType::STRING,
490         false,
491         parseResult,
492         ArrayType::NOT_ARRAY);
493     GetValueIfFindKey<int>(jsonObject,
494         jsonObjectEnd,
495         HAP_MODULE_INFO_LABEL_ID,
496         hapModuleInfo.labelId,
497         JsonType::NUMBER,
498         false,
499         parseResult,
500         ArrayType::NOT_ARRAY);
501     GetValueIfFindKey<std::string>(jsonObject,
502         jsonObjectEnd,
503         HAP_MODULE_INFO_BACKGROUND_IMG,
504         hapModuleInfo.backgroundImg,
505         JsonType::STRING,
506         false,
507         parseResult,
508         ArrayType::NOT_ARRAY);
509     GetValueIfFindKey<std::string>(jsonObject,
510         jsonObjectEnd,
511         HAP_MODULE_INFO_MAIN_ABILITY,
512         hapModuleInfo.mainAbility,
513         JsonType::STRING,
514         false,
515         parseResult,
516         ArrayType::NOT_ARRAY);
517     GetValueIfFindKey<std::string>(jsonObject,
518         jsonObjectEnd,
519         HAP_MODULE_INFO_SRC_PATH,
520         hapModuleInfo.srcPath,
521         JsonType::STRING,
522         false,
523         parseResult,
524         ArrayType::NOT_ARRAY);
525     GetValueIfFindKey<std::string>(jsonObject,
526         jsonObjectEnd,
527         HAP_MODULE_INFO_HASH_VALUE,
528         hapModuleInfo.hashValue,
529         JsonType::STRING,
530         false,
531         parseResult,
532         ArrayType::NOT_ARRAY);
533     GetValueIfFindKey<std::string>(jsonObject,
534         jsonObjectEnd,
535         HAP_MODULE_INFO_HAP_PATH,
536         hapModuleInfo.hapPath,
537         JsonType::STRING,
538         false,
539         parseResult,
540         ArrayType::NOT_ARRAY);
541     GetValueIfFindKey<int>(jsonObject,
542         jsonObjectEnd,
543         HAP_MODULE_INFO_SUPPORTED_MODES,
544         hapModuleInfo.supportedModes,
545         JsonType::NUMBER,
546         false,
547         parseResult,
548         ArrayType::NOT_ARRAY);
549     GetValueIfFindKey<std::vector<std::string>>(jsonObject,
550         jsonObjectEnd,
551         HAP_MODULE_INFO_REQ_CAPABILITIES,
552         hapModuleInfo.reqCapabilities,
553         JsonType::ARRAY,
554         false,
555         parseResult,
556         ArrayType::STRING);
557     GetValueIfFindKey<std::vector<std::string>>(jsonObject,
558         jsonObjectEnd,
559         HAP_MODULE_INFO_DEVICE_TYPES,
560         hapModuleInfo.deviceTypes,
561         JsonType::ARRAY,
562         false,
563         parseResult,
564         ArrayType::STRING);
565     GetValueIfFindKey<std::vector<AbilityInfo>>(jsonObject,
566         jsonObjectEnd,
567         HAP_MODULE_INFO_ABILITY_INFOS,
568         hapModuleInfo.abilityInfos,
569         JsonType::ARRAY,
570         false,
571         parseResult,
572         ArrayType::OBJECT);
573     GetValueIfFindKey<ModuleColorMode>(jsonObject,
574         jsonObjectEnd,
575         HAP_MODULE_INFO_COLOR_MODE,
576         hapModuleInfo.colorMode,
577         JsonType::NUMBER,
578         false,
579         parseResult,
580         ArrayType::NOT_ARRAY);
581     GetValueIfFindKey<std::string>(jsonObject,
582         jsonObjectEnd,
583         Constants::BUNDLE_NAME,
584         hapModuleInfo.bundleName,
585         JsonType::STRING,
586         false,
587         parseResult,
588         ArrayType::NOT_ARRAY);
589     GetValueIfFindKey<std::string>(jsonObject,
590         jsonObjectEnd,
591         HAP_MODULE_INFO_MAIN_ELEMENTNAME,
592         hapModuleInfo.mainElementName,
593         JsonType::STRING,
594         false,
595         parseResult,
596         ArrayType::NOT_ARRAY);
597     GetValueIfFindKey<std::string>(jsonObject,
598         jsonObjectEnd,
599         HAP_MODULE_INFO_PAGES,
600         hapModuleInfo.pages,
601         JsonType::STRING,
602         false,
603         parseResult,
604         ArrayType::NOT_ARRAY);
605     GetValueIfFindKey<std::string>(jsonObject,
606         jsonObjectEnd,
607         HAP_MODULE_INFO_SYSTEM_THEME,
608         hapModuleInfo.systemTheme,
609         JsonType::STRING,
610         false,
611         parseResult,
612         ArrayType::NOT_ARRAY);
613     GetValueIfFindKey<std::string>(jsonObject,
614         jsonObjectEnd,
615         HAP_MODULE_INFO_PROCESS,
616         hapModuleInfo.process,
617         JsonType::STRING,
618         false,
619         parseResult,
620         ArrayType::NOT_ARRAY);
621     GetValueIfFindKey<std::string>(jsonObject,
622         jsonObjectEnd,
623         HAP_MODULE_INFO_RESOURCE_PATH,
624         hapModuleInfo.resourcePath,
625         JsonType::STRING,
626         false,
627         parseResult,
628         ArrayType::NOT_ARRAY);
629     GetValueIfFindKey<std::string>(jsonObject,
630         jsonObjectEnd,
631         HAP_MODULE_INFO_SRC_ENTRANCE,
632         hapModuleInfo.srcEntrance,
633         JsonType::STRING,
634         false,
635         parseResult,
636         ArrayType::NOT_ARRAY);
637     GetValueIfFindKey<std::string>(jsonObject,
638         jsonObjectEnd,
639         HAP_MODULE_INFO_UI_SYNTAX,
640         hapModuleInfo.uiSyntax,
641         JsonType::STRING,
642         false,
643         parseResult,
644         ArrayType::NOT_ARRAY);
645     GetValueIfFindKey<std::string>(jsonObject,
646         jsonObjectEnd,
647         HAP_MODULE_INFO_VIRTUAL_MACHINE,
648         hapModuleInfo.virtualMachine,
649         JsonType::STRING,
650         false,
651         parseResult,
652         ArrayType::NOT_ARRAY);
653     GetValueIfFindKey<bool>(jsonObject,
654         jsonObjectEnd,
655         HAP_MODULE_INFO_DELIVERY_WITH_INSTALL,
656         hapModuleInfo.deliveryWithInstall,
657         JsonType::BOOLEAN,
658         false,
659         parseResult,
660         ArrayType::NOT_ARRAY);
661     GetValueIfFindKey<bool>(jsonObject,
662         jsonObjectEnd,
663         HAP_MODULE_INFO_INSTALLATION_FREE,
664         hapModuleInfo.installationFree,
665         JsonType::BOOLEAN,
666         false,
667         parseResult,
668         ArrayType::NOT_ARRAY);
669     GetValueIfFindKey<bool>(jsonObject,
670         jsonObjectEnd,
671         HAP_MODULE_INFO_IS_MODULE_JSON,
672         hapModuleInfo.isModuleJson,
673         JsonType::BOOLEAN,
674         false,
675         parseResult,
676         ArrayType::NOT_ARRAY);
677     GetValueIfFindKey<bool>(jsonObject,
678         jsonObjectEnd,
679         HAP_MODULE_INFO_IS_STAGE_BASED_MODEL,
680         hapModuleInfo.isStageBasedModel,
681         JsonType::BOOLEAN,
682         false,
683         parseResult,
684         ArrayType::NOT_ARRAY);
685     GetValueIfFindKey<std::map<std::string, bool>>(jsonObject,
686         jsonObjectEnd,
687         HAP_MODULE_INFO_IS_REMOVABLE,
688         hapModuleInfo.isRemovable,
689         JsonType::OBJECT,
690         false,
691         parseResult,
692         ArrayType::NOT_ARRAY);
693     GetValueIfFindKey<int32_t>(jsonObject,
694         jsonObjectEnd,
695         HAP_MODULE_INFO_UPGRADE_FLAG,
696         hapModuleInfo.upgradeFlag,
697         JsonType::NUMBER,
698         false,
699         parseResult,
700         ArrayType::NOT_ARRAY);
701     GetValueIfFindKey<ModuleType>(jsonObject,
702         jsonObjectEnd,
703         HAP_MODULE_INFO_MODULE_TYPE,
704         hapModuleInfo.moduleType,
705         JsonType::NUMBER,
706         false,
707         parseResult,
708         ArrayType::NOT_ARRAY);
709     GetValueIfFindKey<std::vector<ExtensionAbilityInfo>>(jsonObject,
710         jsonObjectEnd,
711         HAP_MODULE_INFO_EXTENSION_INFOS,
712         hapModuleInfo.extensionInfos,
713         JsonType::ARRAY,
714         false,
715         parseResult,
716         ArrayType::OBJECT);
717     GetValueIfFindKey<std::vector<Metadata>>(jsonObject,
718         jsonObjectEnd,
719         HAP_MODULE_INFO_META_DATA,
720         hapModuleInfo.metadata,
721         JsonType::ARRAY,
722         false,
723         parseResult,
724         ArrayType::OBJECT);
725     GetValueIfFindKey<std::vector<Dependency>>(jsonObject,
726         jsonObjectEnd,
727         HAP_MODULE_INFO_DEPENDENCIES,
728         hapModuleInfo.dependencies,
729         JsonType::ARRAY,
730         false,
731         parseResult,
732         ArrayType::OBJECT);
733     GetValueIfFindKey<CompileMode>(jsonObject,
734         jsonObjectEnd,
735         HAP_MODULE_INFO_COMPILE_MODE,
736         hapModuleInfo.compileMode,
737         JsonType::NUMBER,
738         false,
739         parseResult,
740         ArrayType::NOT_ARRAY);
741     GetValueIfFindKey<HqfInfo>(jsonObject,
742         jsonObjectEnd,
743         HAP_MODULE_INFO_HQF_INFO,
744         hapModuleInfo.hqfInfo,
745         JsonType::OBJECT,
746         false,
747         parseResult,
748         ArrayType::NOT_ARRAY);
749     GetValueIfFindKey<bool>(jsonObject,
750         jsonObjectEnd,
751         HAP_MODULE_INFO_IS_LIB_ISOLATED,
752         hapModuleInfo.isLibIsolated,
753         JsonType::BOOLEAN,
754         false,
755         parseResult,
756         ArrayType::NOT_ARRAY);
757     GetValueIfFindKey<std::string>(jsonObject,
758         jsonObjectEnd,
759         HAP_MODULE_INFO_NATIVE_LIBRARY_PATH,
760         hapModuleInfo.nativeLibraryPath,
761         JsonType::STRING,
762         false,
763         parseResult,
764         ArrayType::NOT_ARRAY);
765     GetValueIfFindKey<std::string>(jsonObject,
766         jsonObjectEnd,
767         HAP_MODULE_INFO_CPU_ABI,
768         hapModuleInfo.cpuAbi,
769         JsonType::STRING,
770         false,
771         parseResult,
772         ArrayType::NOT_ARRAY);
773     GetValueIfFindKey<std::string>(jsonObject,
774         jsonObjectEnd,
775         HAP_MODULE_INFO_MODULE_SOURCE_DIR,
776         hapModuleInfo.moduleSourceDir,
777         JsonType::STRING,
778         false,
779         parseResult,
780         ArrayType::NOT_ARRAY);
781     GetValueIfFindKey<std::vector<OverlayModuleInfo>>(jsonObject,
782         jsonObjectEnd,
783         HAP_OVERLAY_MODULE_INFO,
784         hapModuleInfo.overlayModuleInfos,
785         JsonType::ARRAY,
786         false,
787         parseResult,
788         ArrayType::OBJECT);
789     GetValueIfFindKey<AtomicServiceModuleType>(jsonObject,
790         jsonObjectEnd,
791         HAP_MODULE_INFO_ATOMIC_SERVICE_MODULE_TYPE,
792         hapModuleInfo.atomicServiceModuleType,
793         JsonType::NUMBER,
794         false,
795         parseResult,
796         ArrayType::NOT_ARRAY);
797     GetValueIfFindKey<std::vector<PreloadItem>>(jsonObject,
798         jsonObjectEnd,
799         HAP_MODULE_INFO_PRELOADS,
800         hapModuleInfo.preloads,
801         JsonType::ARRAY,
802         false,
803         parseResult,
804         ArrayType::OBJECT);
805     GetValueIfFindKey<std::vector<ProxyData>>(jsonObject,
806         jsonObjectEnd,
807         HAP_MODULE_INFO_PROXY_DATAS,
808         hapModuleInfo.proxyDatas,
809         JsonType::ARRAY,
810         false,
811         parseResult,
812         ArrayType::OBJECT);
813     GetValueIfFindKey<std::string>(jsonObject,
814         jsonObjectEnd,
815         HAP_MODULE_INFO_BUILD_HASH,
816         hapModuleInfo.buildHash,
817         JsonType::STRING,
818         false,
819         parseResult,
820         ArrayType::NOT_ARRAY);
821     GetValueIfFindKey<IsolationMode>(jsonObject,
822         jsonObjectEnd,
823         HAP_MODULE_INFO_ISOLATION_MODE,
824         hapModuleInfo.isolationMode,
825         JsonType::NUMBER,
826         false,
827         parseResult,
828         ArrayType::NOT_ARRAY);
829     GetValueIfFindKey<AOTCompileStatus>(jsonObject,
830         jsonObjectEnd,
831         HAP_MODULE_INFO_AOT_COMPILE_STATUS,
832         hapModuleInfo.aotCompileStatus,
833         JsonType::NUMBER,
834         false,
835         parseResult,
836         ArrayType::NOT_ARRAY);
837     GetValueIfFindKey<bool>(jsonObject,
838         jsonObjectEnd,
839         HAP_MODULE_INFO_COMPRESS_NATIVE_LIBS,
840         hapModuleInfo.compressNativeLibs,
841         JsonType::BOOLEAN,
842         false,
843         parseResult,
844         ArrayType::NOT_ARRAY);
845     GetValueIfFindKey<std::vector<std::string>>(jsonObject,
846         jsonObjectEnd,
847         HAP_MODULE_INFO_NATIVE_LIBRARY_FILE_NAMES,
848         hapModuleInfo.nativeLibraryFileNames,
849         JsonType::ARRAY,
850         false,
851         parseResult,
852         ArrayType::STRING);
853     GetValueIfFindKey<std::string>(jsonObject,
854         jsonObjectEnd,
855         HAP_MODULE_INFO_FILE_CONTEXT_MENU,
856         hapModuleInfo.fileContextMenu,
857         JsonType::STRING,
858         false,
859         parseResult,
860         ArrayType::NOT_ARRAY);
861     GetValueIfFindKey<std::string>(jsonObject,
862         jsonObjectEnd,
863         HAP_MODULE_INFO_ROUTER_MAP,
864         hapModuleInfo.routerMap,
865         JsonType::STRING,
866         false,
867         parseResult,
868         ArrayType::NOT_ARRAY);
869     GetValueIfFindKey<std::vector<RouterItem>>(jsonObject,
870         jsonObjectEnd,
871         HAP_MODULE_INFO_ROUTER_ARRAY,
872         hapModuleInfo.routerArray,
873         JsonType::ARRAY,
874         false,
875         parseResult,
876         ArrayType::OBJECT);
877     GetValueIfFindKey<std::vector<AppEnvironment>>(jsonObject,
878         jsonObjectEnd,
879         HAP_MODULE_INFO_APP_ENVIRONMENTS,
880         hapModuleInfo.appEnvironments,
881         JsonType::ARRAY,
882         false,
883         parseResult,
884         ArrayType::OBJECT);
885     GetValueIfFindKey<std::string>(jsonObject,
886         jsonObjectEnd,
887         HAP_MODULE_INFO_PACKAGE_NAME,
888         hapModuleInfo.packageName,
889         JsonType::STRING,
890         false,
891         parseResult,
892         ArrayType::NOT_ARRAY);
893     GetValueIfFindKey<std::string>(jsonObject,
894         jsonObjectEnd,
895         HAP_MODULE_ABILITY_SRC_ENTRY_DELEGATOR,
896         hapModuleInfo.abilitySrcEntryDelegator,
897         JsonType::STRING,
898         false,
899         parseResult,
900         ArrayType::NOT_ARRAY);
901     GetValueIfFindKey<std::string>(jsonObject,
902         jsonObjectEnd,
903         HAP_MODULE_ABILITY_STAGE_SRC_ENTRY_DELEGATOR,
904         hapModuleInfo.abilityStageSrcEntryDelegator,
905         JsonType::STRING,
906         false,
907         parseResult,
908         ArrayType::NOT_ARRAY);
909     GetValueIfFindKey<std::string>(jsonObject,
910         jsonObjectEnd,
911         HAP_MODULE_INFO_APP_STARTUP,
912         hapModuleInfo.appStartup,
913         JsonType::STRING,
914         false,
915         parseResult,
916         ArrayType::NOT_ARRAY);
917     if (parseResult != ERR_OK) {
918         TAG_LOGE(AAFwkTag::ABILITY_SIM, "HapModuleInfo error:%{public}d", parseResult);
919     }
920 }
921 }  // namespace AppExecFwk
922 }  // namespace OHOS
923