1 /*
2  * Copyright (c) 2021-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 "application_info.h"
17 
18 #include <errno.h>
19 #include <fcntl.h>
20 #include <string.h>
21 #include <set>
22 #include <unistd.h>
23 
24 #include "message_parcel.h"
25 #include "nlohmann/json.hpp"
26 #include "parcel_macro.h"
27 #include "string_ex.h"
28 
29 #include "app_log_wrapper.h"
30 #include "bundle_constants.h"
31 #include "json_serializer.h"
32 #include "json_util.h"
33 
34 namespace OHOS {
35 namespace AppExecFwk {
36 namespace {
37 const char* APPLICATION_NAME = "name";
38 const char* APPLICATION_VERSION_CODE = "versionCode";
39 const char* APPLICATION_VERSION_NAME = "versionName";
40 const char* APPLICATION_MIN_COMPATIBLE_VERSION_CODE = "minCompatibleVersionCode";
41 const char* APPLICATION_API_COMPATIBLE_VERSION = "apiCompatibleVersion";
42 const char* APPLICATION_API_TARGET_VERSION = "apiTargetVersion";
43 const char* APPLICATION_ICON_PATH = "iconPath";
44 const char* APPLICATION_ICON_ID = "iconId";
45 const char* APPLICATION_LABEL = "label";
46 const char* APPLICATION_LABEL_ID = "labelId";
47 const char* APPLICATION_DESCRIPTION = "description";
48 const char* APPLICATION_DESCRIPTION_ID = "descriptionId";
49 const char* APPLICATION_KEEP_ALIVE = "keepAlive";
50 const char* APPLICATION_REMOVABLE = "removable";
51 const char* APPLICATION_SINGLETON = "singleton";
52 const char* APPLICATION_USER_DATA_CLEARABLE = "userDataClearable";
53 const char* ALLOW_APP_RUN_WHEN_DEVICE_FIRST_LOCKED = "allowAppRunWhenDeviceFirstLocked";
54 const char* APPLICATION_IS_SYSTEM_APP = "isSystemApp";
55 const char* APPLICATION_IS_LAUNCHER_APP = "isLauncherApp";
56 const char* APPLICATION_IS_FREEINSTALL_APP = "isFreeInstallApp";
57 const char* APPLICATION_RUNNING_RESOURCES_APPLY = "runningResourcesApply";
58 const char* APPLICATION_ASSOCIATED_WAKE_UP = "associatedWakeUp";
59 const char* APPLICATION_HIDE_DESKTOP_ICON = "hideDesktopIcon";
60 const char* APPLICATION_FORM_VISIBLE_NOTIFY = "formVisibleNotify";
61 const char* APPLICATION_ALLOW_COMMON_EVENT = "allowCommonEvent";
62 const char* APPLICATION_CODE_PATH = "codePath";
63 const char* APPLICATION_DATA_DIR = "dataDir";
64 const char* APPLICATION_DATA_BASE_DIR = "dataBaseDir";
65 const char* APPLICATION_CACHE_DIR = "cacheDir";
66 const char* APPLICATION_ENTRY_DIR = "entryDir";
67 const char* APPLICATION_API_RELEASETYPE = "apiReleaseType";
68 const char* APPLICATION_DEBUG = "debug";
69 const char* APPLICATION_DEVICE_ID = "deviceId";
70 const char* APPLICATION_DISTRIBUTED_NOTIFICATION_ENABLED = "distributedNotificationEnabled";
71 const char* APPLICATION_ENTITY_TYPE = "entityType";
72 const char* APPLICATION_PROCESS = "process";
73 const char* APPLICATION_SUPPORTED_MODES = "supportedModes";
74 const char* APPLICATION_VENDOR = "vendor";
75 const char* APPLICATION_ACCESSIBLE = "accessible";
76 const char* APPLICATION_PRIVILEGE_LEVEL = "appPrivilegeLevel";
77 const char* APPLICATION_ACCESSTOKEN_ID = "accessTokenId";
78 const char* APPLICATION_ACCESSTOKEN_ID_EX = "accessTokenIdEx";
79 const char* APPLICATION_ENABLED = "enabled";
80 const char* APPLICATION_UID = "uid";
81 const char* APPLICATION_PERMISSIONS = "permissions";
82 const char* APPLICATION_MODULE_SOURCE_DIRS = "moduleSourceDirs";
83 const char* APPLICATION_HNP_PACKAGES = "hnpPackages";
84 const char* APPLICATION_HNP_PACKAGES_PACKAGE = "package";
85 const char* APPLICATION_HNP_PACKAGES_TYPE = "type";
86 const char* APPLICATION_MODULE_INFOS = "moduleInfos";
87 const char* APPLICATION_META_DATA_CONFIG_JSON = "metaData";
88 const char* APPLICATION_META_DATA_MODULE_JSON = "metadata";
89 const char* APPLICATION_FINGERPRINT = "fingerprint";
90 const char* APPLICATION_ICON = "icon";
91 const char* APPLICATION_FLAGS = "flags";
92 const char* APPLICATION_ENTRY_MODULE_NAME = "entryModuleName";
93 const char* APPLICATION_NATIVE_LIBRARY_PATH = "nativeLibraryPath";
94 const char* APPLICATION_CPU_ABI = "cpuAbi";
95 const char* APPLICATION_ARK_NATIVE_FILE_PATH = "arkNativeFilePath";
96 const char* APPLICATION_ARK_NATIVE_FILE_ABI = "arkNativeFileAbi";
97 const char* APPLICATION_IS_COMPRESS_NATIVE_LIBS = "isCompressNativeLibs";
98 const char* APPLICATION_SIGNATURE_KEY = "signatureKey";
99 const char* APPLICATION_TARGETBUNDLELIST = "targetBundleList";
100 const char* APPLICATION_APP_DISTRIBUTION_TYPE = "appDistributionType";
101 const char* APPLICATION_APP_PROVISION_TYPE = "appProvisionType";
102 const char* APPLICATION_ICON_RESOURCE = "iconResource";
103 const char* APPLICATION_LABEL_RESOURCE = "labelResource";
104 const char* APPLICATION_DESCRIPTION_RESOURCE = "descriptionResource";
105 const char* APPLICATION_MULTI_PROJECTS = "multiProjects";
106 const char* APPLICATION_CROWDTEST_DEADLINE = "crowdtestDeadline";
107 const char* APPLICATION_APP_QUICK_FIX = "appQuickFix";
108 const char* RESOURCE_ID = "id";
109 const uint16_t APPLICATION_CAPACITY = 10240; // 10K
110 const char* APPLICATION_NEED_APP_DETAIL = "needAppDetail";
111 const char* APPLICATION_APP_DETAIL_ABILITY_LIBRARY_PATH = "appDetailAbilityLibraryPath";
112 const char* APPLICATION_APP_TARGET_BUNDLE_NAME = "targetBundleName";
113 const char* APPLICATION_APP_TARGET_PRIORITY = "targetPriority";
114 const char* APPLICATION_APP_OVERLAY_STATE = "overlayState";
115 const char* APPLICATION_ASAN_ENABLED = "asanEnabled";
116 const char* APPLICATION_ASAN_LOG_PATH = "asanLogPath";
117 const char* APPLICATION_APP_TYPE = "bundleType";
118 const char* APPLICATION_COMPILE_SDK_VERSION = "compileSdkVersion";
119 const char* APPLICATION_COMPILE_SDK_TYPE = "compileSdkType";
120 const char* APPLICATION_RESOURCES_APPLY = "resourcesApply";
121 const char* APPLICATION_ALLOW_ENABLE_NOTIFICATION = "allowEnableNotification";
122 const char* APPLICATION_GWP_ASAN_ENABLED = "GWPAsanEnabled";
123 const char* APPLICATION_RESERVED_FLAG = "applicationReservedFlag";
124 const char* APPLICATION_TSAN_ENABLED = "tsanEnabled";
125 const char* APPLICATION_APP_ENVIRONMENTS = "appEnvironments";
126 const char* APPLICATION_MULTI_APP_MODE = "multiAppMode";
127 const char* APPLICATION_MULTI_APP_MODE_TYPE = "multiAppModeType";
128 const char* APPLICATION_MULTI_APP_MODE_MAX_ADDITIONAL_NUMBER = "maxCount";
129 const char* APP_ENVIRONMENTS_NAME = "name";
130 const char* APP_ENVIRONMENTS_VALUE = "value";
131 const char* APPLICATION_ORGANIZATION = "organization";
132 const char* APPLICATION_MAX_CHILD_PROCESS = "maxChildProcess";
133 const char* APPLICATION_APP_INDEX = "appIndex";
134 const char* APPLICATION_INSTALL_SOURCE = "installSource";
135 const char* APPLICATION_CONFIGURATION = "configuration";
136 const char* APPLICATION_HWASAN_ENABLED = "hwasanEnabled";
137 const char* APPLICATION_CLOUD_FILE_SYNC_ENABLED = "cloudFileSyncEnabled";
138 const char* APPLICATION_APPLICATION_FLAGS = "applicationFlags";
139 }
140 
ReadFromParcel(Parcel & parcel)141 bool MultiAppModeData::ReadFromParcel(Parcel &parcel)
142 {
143     multiAppModeType = static_cast<MultiAppModeType>(parcel.ReadInt32());
144     maxCount = parcel.ReadInt32();
145     return true;
146 }
147 
Marshalling(Parcel & parcel) const148 bool MultiAppModeData::Marshalling(Parcel &parcel) const
149 {
150     WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(Int32, parcel, static_cast<int32_t>(multiAppModeType));
151     WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(Int32, parcel, maxCount);
152     return true;
153 }
154 
Unmarshalling(Parcel & parcel)155 MultiAppModeData *MultiAppModeData::Unmarshalling(Parcel &parcel)
156 {
157     MultiAppModeData *multiAppMode = new (std::nothrow) MultiAppModeData;
158     if (multiAppMode && !multiAppMode->ReadFromParcel(parcel)) {
159         APP_LOGE("read from parcel failed");
160         delete multiAppMode;
161         multiAppMode = nullptr;
162     }
163     return multiAppMode;
164 }
165 
Metadata(const std::string & paramName,const std::string & paramValue,const std::string & paramResource)166 Metadata::Metadata(const std::string &paramName, const std::string &paramValue, const std::string &paramResource)
167     : name(paramName), value(paramValue), resource(paramResource)
168 {
169 }
170 
ReadFromParcel(Parcel & parcel)171 bool Metadata::ReadFromParcel(Parcel &parcel)
172 {
173     name = Str16ToStr8(parcel.ReadString16());
174     value = Str16ToStr8(parcel.ReadString16());
175     resource = Str16ToStr8(parcel.ReadString16());
176     return true;
177 }
178 
Marshalling(Parcel & parcel) const179 bool Metadata::Marshalling(Parcel &parcel) const
180 {
181     WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(String16, parcel, Str8ToStr16(name));
182     WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(String16, parcel, Str8ToStr16(value));
183     WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(String16, parcel, Str8ToStr16(resource));
184     return true;
185 }
186 
Unmarshalling(Parcel & parcel)187 Metadata *Metadata::Unmarshalling(Parcel &parcel)
188 {
189     Metadata *metadata = new (std::nothrow) Metadata;
190     if (metadata && !metadata->ReadFromParcel(parcel)) {
191         APP_LOGE("read from parcel failed");
192         delete metadata;
193         metadata = nullptr;
194     }
195     return metadata;
196 }
197 
ReadFromParcel(Parcel & parcel)198 bool HnpPackage::ReadFromParcel(Parcel &parcel)
199 {
200     package = Str16ToStr8(parcel.ReadString16());
201     type = Str16ToStr8(parcel.ReadString16());
202     return true;
203 }
204 
Marshalling(Parcel & parcel) const205 bool HnpPackage::Marshalling(Parcel &parcel) const
206 {
207     WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(String16, parcel, Str8ToStr16(package));
208     WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(String16, parcel, Str8ToStr16(type));
209     return true;
210 }
211 
Unmarshalling(Parcel & parcel)212 HnpPackage *HnpPackage::Unmarshalling(Parcel &parcel)
213 {
214     HnpPackage *hnpPackage = new (std::nothrow) HnpPackage;
215     if (hnpPackage && !hnpPackage->ReadFromParcel(parcel)) {
216         APP_LOGE("read from parcel failed");
217         delete hnpPackage;
218         hnpPackage = nullptr;
219     }
220     return hnpPackage;
221 }
222 
CustomizeData(std::string paramName,std::string paramValue,std::string paramExtra)223 CustomizeData::CustomizeData(std::string paramName, std::string paramValue, std::string paramExtra)
224     :name(paramName), value(paramValue), extra(paramExtra)
225 {
226 }
227 
ReadFromParcel(Parcel & parcel)228 bool CustomizeData::ReadFromParcel(Parcel &parcel)
229 {
230     name = Str16ToStr8(parcel.ReadString16());
231     value = Str16ToStr8(parcel.ReadString16());
232     extra = Str16ToStr8(parcel.ReadString16());
233     return true;
234 }
235 
Unmarshalling(Parcel & parcel)236 CustomizeData *CustomizeData::Unmarshalling(Parcel &parcel)
237 {
238     CustomizeData *customizeData = new (std::nothrow) CustomizeData;
239     if (customizeData && !customizeData->ReadFromParcel(parcel)) {
240         APP_LOGE("read from parcel failed");
241         delete customizeData;
242         customizeData = nullptr;
243     }
244     return customizeData;
245 }
246 
Marshalling(Parcel & parcel) const247 bool CustomizeData::Marshalling(Parcel &parcel) const
248 {
249     WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(String16, parcel, Str8ToStr16(name));
250     WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(String16, parcel, Str8ToStr16(value));
251     WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(String16, parcel, Str8ToStr16(extra));
252     return true;
253 }
254 
ReadFromParcel(Parcel & parcel)255 bool Resource::ReadFromParcel(Parcel &parcel)
256 {
257     bundleName = Str16ToStr8(parcel.ReadString16());
258     moduleName = Str16ToStr8(parcel.ReadString16());
259     id = parcel.ReadUint32();
260     return true;
261 }
262 
Marshalling(Parcel & parcel) const263 bool Resource::Marshalling(Parcel &parcel) const
264 {
265     WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(String16, parcel, Str8ToStr16(bundleName));
266     WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(String16, parcel, Str8ToStr16(moduleName));
267     WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(Uint32, parcel, id);
268     return true;
269 }
270 
Unmarshalling(Parcel & parcel)271 Resource *Resource::Unmarshalling(Parcel &parcel)
272 {
273     Resource *resource = new (std::nothrow) Resource;
274     if (resource && !resource->ReadFromParcel(parcel)) {
275         APP_LOGE("read from parcel failed");
276         delete resource;
277         resource = nullptr;
278     }
279     return resource;
280 }
281 
ReadMetaDataFromParcel(Parcel & parcel)282 bool ApplicationInfo::ReadMetaDataFromParcel(Parcel &parcel)
283 {
284     int32_t metaDataSize = parcel.ReadInt32();
285     CONTAINER_SECURITY_VERIFY(parcel, metaDataSize, &metaData);
286     for (int32_t i = 0; i < metaDataSize; i++) {
287         std::string moduleName = Str16ToStr8(parcel.ReadString16());
288         int32_t customizeDataSize = parcel.ReadInt32();
289         std::vector<CustomizeData> customizeDatas;
290         metaData[moduleName] = customizeDatas;
291         CONTAINER_SECURITY_VERIFY(parcel, customizeDataSize, &customizeDatas);
292         for (int j = 0; j < customizeDataSize; j++) {
293             std::unique_ptr<CustomizeData> customizeData(parcel.ReadParcelable<CustomizeData>());
294             if (!customizeData) {
295                 APP_LOGE("ReadParcelable<CustomizeData> failed");
296                 return false;
297             }
298             metaData[moduleName].emplace_back(*customizeData);
299         }
300     }
301     return true;
302 }
303 
ReadFromParcel(Parcel & parcel)304 bool ApplicationEnvironment::ReadFromParcel(Parcel &parcel)
305 {
306     name = Str16ToStr8(parcel.ReadString16());
307     value = Str16ToStr8(parcel.ReadString16());
308     return true;
309 }
310 
Marshalling(Parcel & parcel) const311 bool ApplicationEnvironment::Marshalling(Parcel &parcel) const
312 {
313     WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(String16, parcel, Str8ToStr16(name));
314     WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(String16, parcel, Str8ToStr16(value));
315     return true;
316 }
317 
Unmarshalling(Parcel & parcel)318 ApplicationEnvironment *ApplicationEnvironment::Unmarshalling(Parcel &parcel)
319 {
320     ApplicationEnvironment *info = new (std::nothrow) ApplicationEnvironment();
321     if (info && !info->ReadFromParcel(parcel)) {
322         APP_LOGW("read from parcel failed");
323         delete info;
324         info = nullptr;
325     }
326     return info;
327 }
328 
to_json(nlohmann::json & jsonObject,const ApplicationEnvironment & applicationEnvironment)329 void to_json(nlohmann::json &jsonObject, const ApplicationEnvironment &applicationEnvironment)
330 {
331     jsonObject = nlohmann::json {
332         {APP_ENVIRONMENTS_NAME, applicationEnvironment.name},
333         {APP_ENVIRONMENTS_VALUE, applicationEnvironment.value}
334     };
335 }
336 
from_json(const nlohmann::json & jsonObject,ApplicationEnvironment & applicationEnvironment)337 void from_json(const nlohmann::json &jsonObject, ApplicationEnvironment &applicationEnvironment)
338 {
339     const auto &jsonObjectEnd = jsonObject.end();
340     int32_t parseResult = ERR_OK;
341     GetValueIfFindKey<std::string>(jsonObject,
342         jsonObjectEnd,
343         APP_ENVIRONMENTS_NAME,
344         applicationEnvironment.name,
345         JsonType::STRING,
346         false,
347         parseResult,
348         ArrayType::NOT_ARRAY);
349     GetValueIfFindKey<std::string>(jsonObject,
350         jsonObjectEnd,
351         APP_ENVIRONMENTS_VALUE,
352         applicationEnvironment.value,
353         JsonType::STRING,
354         false,
355         parseResult,
356         ArrayType::NOT_ARRAY);
357     if (parseResult != ERR_OK) {
358         APP_LOGE("read database error : %{public}d", parseResult);
359     }
360 }
361 
ReadFromParcel(Parcel & parcel)362 bool ApplicationInfo::ReadFromParcel(Parcel &parcel)
363 {
364     name = Str16ToStr8(parcel.ReadString16());
365     bundleName = Str16ToStr8(parcel.ReadString16());
366     versionCode = parcel.ReadUint32();
367     versionName = Str16ToStr8(parcel.ReadString16());
368     minCompatibleVersionCode = parcel.ReadInt32();
369     apiCompatibleVersion = parcel.ReadUint32();
370     apiTargetVersion = parcel.ReadInt32();
371     crowdtestDeadline = parcel.ReadInt64();
372 
373     iconPath = Str16ToStr8(parcel.ReadString16());
374     iconId = parcel.ReadUint32();
375     std::unique_ptr<Resource> iconResourcePtr(parcel.ReadParcelable<Resource>());
376     if (!iconResourcePtr) {
377         APP_LOGE("icon ReadParcelable<Resource> failed");
378         return false;
379     }
380     iconResource = *iconResourcePtr;
381 
382     label = Str16ToStr8(parcel.ReadString16());
383     labelId = parcel.ReadUint32();
384     std::unique_ptr<Resource> labelResourcePtr(parcel.ReadParcelable<Resource>());
385     if (!labelResourcePtr) {
386         APP_LOGE("label ReadParcelable<Resource> failed");
387         return false;
388     }
389     labelResource = *labelResourcePtr;
390 
391     description = Str16ToStr8(parcel.ReadString16());
392     descriptionId = parcel.ReadUint32();
393     std::unique_ptr<Resource> descriptionResourcePtr(parcel.ReadParcelable<Resource>());
394     if (!descriptionResourcePtr) {
395         APP_LOGE("description ReadParcelable<Resource> failed");
396         return false;
397     }
398     descriptionResource = *descriptionResourcePtr;
399 
400     keepAlive = parcel.ReadBool();
401     removable = parcel.ReadBool();
402     singleton = parcel.ReadBool();
403     userDataClearable = parcel.ReadBool();
404     accessible = parcel.ReadBool();
405     isSystemApp = parcel.ReadBool();
406     isLauncherApp = parcel.ReadBool();
407     isFreeInstallApp = parcel.ReadBool();
408     runningResourcesApply = parcel.ReadBool();
409     associatedWakeUp = parcel.ReadBool();
410     hideDesktopIcon = parcel.ReadBool();
411     formVisibleNotify = parcel.ReadBool();
412     allowAppRunWhenDeviceFirstLocked = parcel.ReadBool();
413     int32_t allowCommonEventSize;
414     READ_PARCEL_AND_RETURN_FALSE_IF_FAIL(Int32, parcel, allowCommonEventSize);
415     CONTAINER_SECURITY_VERIFY(parcel, allowCommonEventSize, &allowCommonEvent);
416     for (auto i = 0; i < allowCommonEventSize; i++) {
417         allowCommonEvent.emplace_back(Str16ToStr8(parcel.ReadString16()));
418     }
419 
420     codePath = Str16ToStr8(parcel.ReadString16());
421     dataDir = Str16ToStr8(parcel.ReadString16());
422     dataBaseDir = Str16ToStr8(parcel.ReadString16());
423     cacheDir = Str16ToStr8(parcel.ReadString16());
424     entryDir = Str16ToStr8(parcel.ReadString16());
425 
426     apiReleaseType = Str16ToStr8(parcel.ReadString16());
427     debug = parcel.ReadBool();
428     deviceId = Str16ToStr8(parcel.ReadString16());
429     distributedNotificationEnabled = parcel.ReadBool();
430     allowEnableNotification = parcel.ReadBool();
431     entityType = Str16ToStr8(parcel.ReadString16());
432     process = Str16ToStr8(parcel.ReadString16());
433     supportedModes = parcel.ReadInt32();
434     vendor = Str16ToStr8(parcel.ReadString16());
435     appPrivilegeLevel = Str16ToStr8(parcel.ReadString16());
436     appDistributionType = Str16ToStr8(parcel.ReadString16());
437     appProvisionType = Str16ToStr8(parcel.ReadString16());
438     accessTokenId = parcel.ReadUint32();
439     accessTokenIdEx = parcel.ReadUint64();
440     enabled = parcel.ReadBool();
441     uid = parcel.ReadInt32();
442     nativeLibraryPath = Str16ToStr8(parcel.ReadString16());
443     cpuAbi = Str16ToStr8(parcel.ReadString16());
444     arkNativeFilePath = Str16ToStr8(parcel.ReadString16());
445     arkNativeFileAbi = Str16ToStr8(parcel.ReadString16());
446 
447     int32_t permissionsSize;
448     READ_PARCEL_AND_RETURN_FALSE_IF_FAIL(Int32, parcel, permissionsSize);
449     CONTAINER_SECURITY_VERIFY(parcel, permissionsSize, &permissions);
450     for (auto i = 0; i < permissionsSize; i++) {
451         permissions.emplace_back(Str16ToStr8(parcel.ReadString16()));
452     }
453 
454     int32_t moduleSourceDirsSize;
455     READ_PARCEL_AND_RETURN_FALSE_IF_FAIL(Int32, parcel, moduleSourceDirsSize);
456     CONTAINER_SECURITY_VERIFY(parcel, moduleSourceDirsSize, &moduleSourceDirs);
457     for (auto i = 0; i < moduleSourceDirsSize; i++) {
458         moduleSourceDirs.emplace_back(Str16ToStr8(parcel.ReadString16()));
459     }
460 
461     int32_t moduleInfosSize;
462     READ_PARCEL_AND_RETURN_FALSE_IF_FAIL(Int32, parcel, moduleInfosSize);
463     CONTAINER_SECURITY_VERIFY(parcel, moduleInfosSize, &moduleInfos);
464     for (auto i = 0; i < moduleInfosSize; i++) {
465         std::unique_ptr<ModuleInfo> moduleInfo(parcel.ReadParcelable<ModuleInfo>());
466         if (!moduleInfo) {
467             APP_LOGE("ReadParcelable<ModuleInfo> failed");
468             return false;
469         }
470         moduleInfos.emplace_back(*moduleInfo);
471     }
472 
473     int32_t hnpPackageSize;
474     READ_PARCEL_AND_RETURN_FALSE_IF_FAIL(Int32, parcel, hnpPackageSize);
475     CONTAINER_SECURITY_VERIFY(parcel, hnpPackageSize, &hnpPackages);
476     for (int32_t i = 0; i < hnpPackageSize; ++i) {
477         std::string key = Str16ToStr8(parcel.ReadString16());
478         int32_t hnpSize = parcel.ReadInt32();
479         CONTAINER_SECURITY_VERIFY(parcel, hnpSize, &hnpPackages[key]);
480         for (int n = 0; n < hnpSize; ++n) {
481             std::unique_ptr<HnpPackage> hnp(parcel.ReadParcelable<HnpPackage>());
482             if (!hnp) {
483                 APP_LOGE("ReadParcelable<HnpPackage> failed");
484                 return false;
485             }
486             hnpPackages[key].emplace_back(*hnp);
487         }
488     }
489 
490     int32_t metaDataSize;
491     READ_PARCEL_AND_RETURN_FALSE_IF_FAIL(Int32, parcel, metaDataSize);
492     CONTAINER_SECURITY_VERIFY(parcel, metaDataSize, &metaData);
493     for (int32_t i = 0; i < metaDataSize; ++i) {
494         std::string key = Str16ToStr8(parcel.ReadString16());
495         int32_t customizeDataSize = parcel.ReadInt32();
496         CONTAINER_SECURITY_VERIFY(parcel, customizeDataSize, &metaData[key]);
497         for (int n = 0; n < customizeDataSize; ++n) {
498             std::unique_ptr<CustomizeData> customizeData(parcel.ReadParcelable<CustomizeData>());
499             if (!customizeData) {
500                 APP_LOGE("ReadParcelable<CustomizeData> failed");
501                 return false;
502             }
503             metaData[key].emplace_back(*customizeData);
504         }
505     }
506 
507     int32_t metadataSize;
508     READ_PARCEL_AND_RETURN_FALSE_IF_FAIL(Int32, parcel, metadataSize);
509     CONTAINER_SECURITY_VERIFY(parcel, metadataSize, &metadata);
510     for (int32_t i = 0; i < metadataSize; ++i) {
511         std::string key = Str16ToStr8(parcel.ReadString16());
512         int32_t metaSize = parcel.ReadInt32();
513         CONTAINER_SECURITY_VERIFY(parcel, metaSize, &metadata[key]);
514         for (int n = 0; n < metaSize; ++n) {
515             std::unique_ptr<Metadata> meta(parcel.ReadParcelable<Metadata>());
516             if (!meta) {
517                 APP_LOGE("ReadParcelable<Metadata> failed");
518                 return false;
519             }
520             metadata[key].emplace_back(*meta);
521         }
522     }
523 
524     int32_t targetBundleListSize;
525     READ_PARCEL_AND_RETURN_FALSE_IF_FAIL(Int32, parcel, targetBundleListSize);
526     CONTAINER_SECURITY_VERIFY(parcel, targetBundleListSize, &targetBundleList);
527     for (auto i = 0; i < targetBundleListSize; i++) {
528         targetBundleList.emplace_back(Str16ToStr8(parcel.ReadString16()));
529     }
530 
531     fingerprint = Str16ToStr8(parcel.ReadString16());
532     icon = Str16ToStr8(parcel.ReadString16());
533     flags = parcel.ReadInt32();
534     entryModuleName = Str16ToStr8(parcel.ReadString16());
535     isCompressNativeLibs = parcel.ReadBool();
536     signatureKey = Str16ToStr8(parcel.ReadString16());
537     multiProjects = parcel.ReadBool();
538     std::unique_ptr<AppQuickFix> appQuickFixPtr(parcel.ReadParcelable<AppQuickFix>());
539     if (appQuickFixPtr == nullptr) {
540         APP_LOGE("ReadParcelable<AppQuickFixPtr> failed");
541         return false;
542     }
543     appQuickFix = *appQuickFixPtr;
544     needAppDetail = parcel.ReadBool();
545     appDetailAbilityLibraryPath = Str16ToStr8(parcel.ReadString16());
546     targetBundleName = Str16ToStr8(parcel.ReadString16());
547     targetPriority = parcel.ReadInt32();
548     overlayState = parcel.ReadInt32();
549     asanEnabled = parcel.ReadBool();
550     asanLogPath = Str16ToStr8(parcel.ReadString16());
551     bundleType = static_cast<BundleType>(parcel.ReadInt32());
552     compileSdkVersion = Str16ToStr8(parcel.ReadString16());
553     compileSdkType = Str16ToStr8(parcel.ReadString16());
554     int32_t resourceApplySize;
555     READ_PARCEL_AND_RETURN_FALSE_IF_FAIL(Int32, parcel, resourceApplySize);
556     CONTAINER_SECURITY_VERIFY(parcel, resourceApplySize, &resourcesApply);
557     for (int32_t i = 0; i < resourceApplySize; ++i) {
558         resourcesApply.emplace_back(parcel.ReadInt32());
559     }
560 
561     gwpAsanEnabled = parcel.ReadBool();
562     applicationReservedFlag = parcel.ReadUint32();
563     tsanEnabled = parcel.ReadBool();
564     hwasanEnabled = parcel.ReadBool();
565     int32_t applicationEnvironmentsSize;
566     READ_PARCEL_AND_RETURN_FALSE_IF_FAIL(Int32, parcel, applicationEnvironmentsSize);
567     CONTAINER_SECURITY_VERIFY(parcel, applicationEnvironmentsSize, &appEnvironments);
568     for (int32_t i = 0; i < applicationEnvironmentsSize; ++i) {
569         std::unique_ptr<ApplicationEnvironment> applicationEnvironment(parcel.ReadParcelable<ApplicationEnvironment>());
570         if (!applicationEnvironment) {
571             APP_LOGE("ReadParcelable<ApplicationEnvironment> failed");
572             return false;
573         }
574         appEnvironments.emplace_back(*applicationEnvironment);
575     }
576     organization = Str16ToStr8(parcel.ReadString16());
577 
578     std::unique_ptr<MultiAppModeData> multiAppModePtr(parcel.ReadParcelable<MultiAppModeData>());
579     if (!multiAppModePtr) {
580         APP_LOGE("icon ReadParcelable<MultiAppMode> failed");
581         return false;
582     }
583     multiAppMode = *multiAppModePtr;
584     maxChildProcess = parcel.ReadInt32();
585     appIndex = parcel.ReadInt32();
586     installSource = Str16ToStr8(parcel.ReadString16());
587 
588     configuration = Str16ToStr8(parcel.ReadString16());
589     cloudFileSyncEnabled = parcel.ReadBool();
590     applicationFlags = parcel.ReadInt32();
591     return true;
592 }
593 
Unmarshalling(Parcel & parcel)594 ApplicationInfo *ApplicationInfo::Unmarshalling(Parcel &parcel)
595 {
596     ApplicationInfo *info = new (std::nothrow) ApplicationInfo();
597     if (info && !info->ReadFromParcel(parcel)) {
598         APP_LOGW("read from parcel failed");
599         delete info;
600         info = nullptr;
601     }
602     return info;
603 }
604 
Marshalling(Parcel & parcel) const605 bool ApplicationInfo::Marshalling(Parcel &parcel) const
606 {
607     APP_LOGD("ApplicationInfo::Marshalling called, bundleName: %{public}s", bundleName.c_str());
608     CHECK_PARCEL_CAPACITY(parcel, APPLICATION_CAPACITY);
609     WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(String16, parcel, Str8ToStr16(name));
610     WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(String16, parcel, Str8ToStr16(bundleName));
611     WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(Uint32, parcel, versionCode);
612     WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(String16, parcel, Str8ToStr16(versionName));
613     WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(Int32, parcel, minCompatibleVersionCode);
614 
615     WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(Uint32, parcel, apiCompatibleVersion);
616     WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(Int32, parcel, apiTargetVersion);
617     WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(Int64, parcel, crowdtestDeadline);
618 
619     WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(String16, parcel, Str8ToStr16(iconPath));
620     WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(Uint32, parcel, iconId);
621     WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(Parcelable, parcel, &iconResource);
622 
623     WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(String16, parcel, Str8ToStr16(label));
624     WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(Uint32, parcel, labelId);
625     WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(Parcelable, parcel, &labelResource);
626 
627     WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(String16, parcel, Str8ToStr16(description));
628     WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(Uint32, parcel, descriptionId);
629     WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(Parcelable, parcel, &descriptionResource);
630 
631     WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(Bool, parcel, keepAlive);
632     WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(Bool, parcel, removable);
633     WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(Bool, parcel, singleton);
634     WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(Bool, parcel, userDataClearable);
635     WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(Bool, parcel, accessible);
636     WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(Bool, parcel, isSystemApp);
637     WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(Bool, parcel, isLauncherApp);
638     WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(Bool, parcel, isFreeInstallApp);
639     WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(Bool, parcel, runningResourcesApply);
640     WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(Bool, parcel, associatedWakeUp);
641     WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(Bool, parcel, hideDesktopIcon);
642     WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(Bool, parcel, formVisibleNotify);
643     WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(Bool, parcel, allowAppRunWhenDeviceFirstLocked);
644     WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(Int32, parcel, allowCommonEvent.size());
645     for (auto &event : allowCommonEvent) {
646         WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(String16, parcel, Str8ToStr16(event));
647     }
648 
649     WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(String16, parcel, Str8ToStr16(codePath));
650     WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(String16, parcel, Str8ToStr16(dataDir));
651     WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(String16, parcel, Str8ToStr16(dataBaseDir));
652     WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(String16, parcel, Str8ToStr16(cacheDir));
653     WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(String16, parcel, Str8ToStr16(entryDir));
654 
655     WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(String16, parcel, Str8ToStr16(apiReleaseType));
656     WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(Bool, parcel, debug);
657     WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(String16, parcel, Str8ToStr16(deviceId));
658     WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(Bool, parcel, distributedNotificationEnabled);
659     WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(Bool, parcel, allowEnableNotification);
660     WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(String16, parcel, Str8ToStr16(entityType));
661     WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(String16, parcel, Str8ToStr16(process));
662     WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(Int32, parcel, supportedModes);
663     WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(String16, parcel, Str8ToStr16(vendor));
664 
665     WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(String16, parcel, Str8ToStr16(appPrivilegeLevel));
666     WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(String16, parcel, Str8ToStr16(appDistributionType));
667     WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(String16, parcel, Str8ToStr16(appProvisionType));
668 
669     WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(Uint32, parcel, accessTokenId);
670     WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(Uint64, parcel, accessTokenIdEx);
671     WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(Bool, parcel, enabled);
672     WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(Int32, parcel, uid);
673 
674     WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(String16, parcel, Str8ToStr16(nativeLibraryPath));
675     WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(String16, parcel, Str8ToStr16(cpuAbi));
676     WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(String16, parcel, Str8ToStr16(arkNativeFilePath));
677     WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(String16, parcel, Str8ToStr16(arkNativeFileAbi));
678     CHECK_PARCEL_CAPACITY(parcel, APPLICATION_CAPACITY);
679     WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(Int32, parcel, permissions.size());
680     for (auto &permission : permissions) {
681         WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(String16, parcel, Str8ToStr16(permission));
682     }
683 
684     WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(Int32, parcel, moduleSourceDirs.size());
685     for (auto &moduleSourceDir : moduleSourceDirs) {
686         WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(String16, parcel, Str8ToStr16(moduleSourceDir));
687     }
688 
689     WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(Int32, parcel, moduleInfos.size());
690     for (auto &moduleInfo : moduleInfos) {
691         WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(Parcelable, parcel, &moduleInfo);
692     }
693 
694     WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(Int32, parcel, hnpPackages.size());
695     for (auto &item : hnpPackages) {
696         WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(String16, parcel, Str8ToStr16(item.first));
697         WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(Int32, parcel, item.second.size());
698         for (auto &hnp : item.second) {
699             WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(Parcelable, parcel, &hnp);
700         }
701     }
702 
703     WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(Int32, parcel, metaData.size());
704     for (auto &item : metaData) {
705         WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(String16, parcel, Str8ToStr16(item.first));
706         WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(Int32, parcel, item.second.size());
707         for (auto &customizeData : item.second) {
708             WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(Parcelable, parcel, &customizeData);
709         }
710     }
711 
712     WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(Int32, parcel, metadata.size());
713     for (auto &item : metadata) {
714         WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(String16, parcel, Str8ToStr16(item.first));
715         WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(Int32, parcel, item.second.size());
716         for (auto &meta : item.second) {
717             WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(Parcelable, parcel, &meta);
718         }
719     }
720 
721     WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(Int32, parcel, targetBundleList.size());
722     for (auto &targetBundle : targetBundleList) {
723         WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(String16, parcel, Str8ToStr16(targetBundle));
724     }
725 
726     WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(String16, parcel, Str8ToStr16(fingerprint));
727     WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(String16, parcel, Str8ToStr16(icon));
728     WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(Int32, parcel, flags);
729     WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(String16, parcel, Str8ToStr16(entryModuleName));
730     WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(Bool, parcel, isCompressNativeLibs);
731     WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(String16, parcel, Str8ToStr16(signatureKey));
732 
733     WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(Bool, parcel, multiProjects);
734     WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(Parcelable, parcel, &appQuickFix);
735     WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(Bool, parcel, needAppDetail);
736     WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(String16, parcel, Str8ToStr16(appDetailAbilityLibraryPath));
737     WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(String16, parcel, Str8ToStr16(targetBundleName));
738     WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(Int32, parcel, targetPriority);
739     WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(Int32, parcel, overlayState);
740     WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(Bool, parcel, asanEnabled);
741     WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(String16, parcel, Str8ToStr16(asanLogPath));
742     WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(Int32, parcel, static_cast<int32_t>(bundleType));
743     WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(String16, parcel, Str8ToStr16(compileSdkVersion));
744     WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(String16, parcel, Str8ToStr16(compileSdkType));
745     WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(Int32, parcel, resourcesApply.size());
746     for (auto &item : resourcesApply) {
747         WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(Int32, parcel, item);
748     }
749     WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(Bool, parcel, gwpAsanEnabled);
750     WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(Uint32, parcel, applicationReservedFlag);
751     WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(Bool, parcel, tsanEnabled);
752     WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(Bool, parcel, hwasanEnabled);
753     WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(Int32, parcel, appEnvironments.size());
754     for (auto &item : appEnvironments) {
755         WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(Parcelable, parcel, &item);
756     }
757     WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(String16, parcel, Str8ToStr16(organization));
758     WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(Parcelable, parcel, &multiAppMode);
759     WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(Int32, parcel, maxChildProcess);
760     WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(Int32, parcel, appIndex);
761     WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(String16, parcel, Str8ToStr16(installSource));
762 
763     WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(String16, parcel, Str8ToStr16(configuration));
764     WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(Bool, parcel, cloudFileSyncEnabled);
765     WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(Int32, parcel, applicationFlags);
766     return true;
767 }
768 
Dump(std::string prefix,int fd)769 void ApplicationInfo::Dump(std::string prefix, int fd)
770 {
771     APP_LOGI("called dump ApplicationInfo");
772     if (fd < 0) {
773         APP_LOGE("dump ApplicationInfo fd error");
774         return;
775     }
776     int flags = fcntl(fd, F_GETFL);
777     if (flags < 0) {
778         APP_LOGE("dump fcntl error : %{public}d", errno);
779         return;
780     }
781     uint uflags = static_cast<uint>(flags);
782     uflags &= O_ACCMODE;
783     if ((uflags == O_WRONLY) || (uflags == O_RDWR)) {
784         nlohmann::json jsonObject = *this;
785         std::string result;
786         result.append(prefix);
787         result.append(jsonObject.dump(Constants::DUMP_INDENT));
788         int ret = TEMP_FAILURE_RETRY(write(fd, result.c_str(), result.size()));
789         if (ret < 0) {
790             APP_LOGE("dump write error : %{public}d", errno);
791         }
792     }
793     return;
794 }
795 
CheckNeedPreload(const std::string & moduleName) const796 bool ApplicationInfo::CheckNeedPreload(const std::string &moduleName) const
797 {
798     std::set<std::string> preloadModules;
799     auto it = std::find_if(std::begin(moduleInfos), std::end(moduleInfos),
800         [&moduleName](ModuleInfo info) {
801             return info.moduleName == moduleName;
802         });
803     if (it != moduleInfos.end()) {
804         for (const std::string &name : it->preloads) {
805             preloadModules.insert(name);
806         }
807     }
808     if (preloadModules.empty()) {
809         APP_LOGD("the module have no preloads");
810         return false;
811     }
812     for (const ModuleInfo &moduleInfo : moduleInfos) {
813         auto iter = preloadModules.find(moduleInfo.moduleName);
814         if (iter != preloadModules.end()) {
815             preloadModules.erase(iter);
816         }
817     }
818     if (preloadModules.empty()) {
819         APP_LOGD("all preload modules exist locally");
820         return false;
821     }
822     APP_LOGD("need to process preload");
823     return true;
824 }
825 
to_json(nlohmann::json & jsonObject,const Resource & resource)826 void to_json(nlohmann::json &jsonObject, const Resource &resource)
827 {
828     jsonObject = nlohmann::json {
829         {Constants::BUNDLE_NAME, resource.bundleName},
830         {Constants::MODULE_NAME, resource.moduleName},
831         {RESOURCE_ID, resource.id}
832     };
833 }
834 
from_json(const nlohmann::json & jsonObject,Resource & resource)835 void from_json(const nlohmann::json &jsonObject, Resource &resource)
836 {
837     const auto &jsonObjectEnd = jsonObject.end();
838     int32_t parseResult = ERR_OK;
839     GetValueIfFindKey<std::string>(jsonObject,
840         jsonObjectEnd,
841         Constants::BUNDLE_NAME,
842         resource.bundleName,
843         JsonType::STRING,
844         true,
845         parseResult,
846         ArrayType::NOT_ARRAY);
847     GetValueIfFindKey<std::string>(jsonObject,
848         jsonObjectEnd,
849         Constants::MODULE_NAME,
850         resource.moduleName,
851         JsonType::STRING,
852         true,
853         parseResult,
854         ArrayType::NOT_ARRAY);
855     GetValueIfFindKey<uint32_t>(jsonObject,
856         jsonObjectEnd,
857         RESOURCE_ID,
858         resource.id,
859         JsonType::NUMBER,
860         true,
861         parseResult,
862         ArrayType::NOT_ARRAY);
863     if (parseResult != ERR_OK) {
864         APP_LOGE("read Resource error : %{public}d", parseResult);
865     }
866 }
867 
to_json(nlohmann::json & jsonObject,const MultiAppModeData & multiAppMode)868 void to_json(nlohmann::json &jsonObject, const MultiAppModeData &multiAppMode)
869 {
870     jsonObject = nlohmann::json {
871         {APPLICATION_MULTI_APP_MODE_TYPE, multiAppMode.multiAppModeType},
872         {APPLICATION_MULTI_APP_MODE_MAX_ADDITIONAL_NUMBER, multiAppMode.maxCount},
873     };
874 }
875 
from_json(const nlohmann::json & jsonObject,MultiAppModeData & multiAppMode)876 void from_json(const nlohmann::json &jsonObject, MultiAppModeData &multiAppMode)
877 {
878     const auto &jsonObjectEnd = jsonObject.end();
879     int32_t parseResult = ERR_OK;
880     GetValueIfFindKey<MultiAppModeType>(jsonObject, jsonObjectEnd, APPLICATION_MULTI_APP_MODE_TYPE,
881         multiAppMode.multiAppModeType, JsonType::NUMBER, false, parseResult, ArrayType::NOT_ARRAY);
882     GetValueIfFindKey<int32_t>(jsonObject, jsonObjectEnd, APPLICATION_MULTI_APP_MODE_MAX_ADDITIONAL_NUMBER,
883         multiAppMode.maxCount, JsonType::NUMBER, false, parseResult, ArrayType::NOT_ARRAY);
884     if (parseResult != ERR_OK) {
885         APP_LOGE("from_json error : %{public}d", parseResult);
886     }
887 }
888 
to_json(nlohmann::json & jsonObject,const HnpPackage & hnpPackage)889 void to_json(nlohmann::json &jsonObject, const HnpPackage &hnpPackage)
890 {
891     jsonObject = nlohmann::json {
892         {APPLICATION_HNP_PACKAGES_PACKAGE, hnpPackage.package},
893         {APPLICATION_HNP_PACKAGES_TYPE, hnpPackage.type},
894     };
895 }
896 
from_json(const nlohmann::json & jsonObject,HnpPackage & hnpPackage)897 void from_json(const nlohmann::json &jsonObject, HnpPackage &hnpPackage)
898 {
899     const auto &jsonObjectEnd = jsonObject.end();
900     int32_t parseResult = ERR_OK;
901     GetValueIfFindKey<std::string>(jsonObject,
902         jsonObjectEnd,
903         APPLICATION_HNP_PACKAGES_PACKAGE,
904         hnpPackage.package,
905         JsonType::STRING,
906         true,
907         parseResult,
908         ArrayType::NOT_ARRAY);
909     GetValueIfFindKey<std::string>(jsonObject,
910         jsonObjectEnd,
911         APPLICATION_HNP_PACKAGES_TYPE,
912         hnpPackage.type,
913         JsonType::STRING,
914         true,
915         parseResult,
916         ArrayType::NOT_ARRAY);
917     if (parseResult != ERR_OK) {
918         APP_LOGE("read Resource error %{public}d", parseResult);
919     }
920 }
921 
to_json(nlohmann::json & jsonObject,const ApplicationInfo & applicationInfo)922 void to_json(nlohmann::json &jsonObject, const ApplicationInfo &applicationInfo)
923 {
924     jsonObject = nlohmann::json {
925         {APPLICATION_NAME, applicationInfo.name},
926         {Constants::BUNDLE_NAME, applicationInfo.bundleName},
927         {APPLICATION_VERSION_CODE, applicationInfo.versionCode},
928         {APPLICATION_VERSION_NAME, applicationInfo.versionName},
929         {APPLICATION_MIN_COMPATIBLE_VERSION_CODE, applicationInfo.minCompatibleVersionCode},
930         {APPLICATION_API_COMPATIBLE_VERSION, applicationInfo.apiCompatibleVersion},
931         {APPLICATION_API_TARGET_VERSION, applicationInfo.apiTargetVersion},
932         {APPLICATION_ICON_PATH, applicationInfo.iconPath},
933         {APPLICATION_ICON_ID, applicationInfo.iconId},
934         {APPLICATION_LABEL, applicationInfo.label},
935         {APPLICATION_LABEL_ID, applicationInfo.labelId},
936         {APPLICATION_DESCRIPTION, applicationInfo.description},
937         {APPLICATION_DESCRIPTION_ID, applicationInfo.descriptionId},
938         {APPLICATION_KEEP_ALIVE, applicationInfo.keepAlive},
939         {APPLICATION_REMOVABLE, applicationInfo.removable},
940         {APPLICATION_SINGLETON, applicationInfo.singleton},
941         {APPLICATION_USER_DATA_CLEARABLE, applicationInfo.userDataClearable},
942         {ALLOW_APP_RUN_WHEN_DEVICE_FIRST_LOCKED, applicationInfo.allowAppRunWhenDeviceFirstLocked},
943         {APPLICATION_ACCESSIBLE, applicationInfo.accessible},
944         {APPLICATION_IS_SYSTEM_APP, applicationInfo.isSystemApp},
945         {APPLICATION_IS_LAUNCHER_APP, applicationInfo.isLauncherApp},
946         {APPLICATION_IS_FREEINSTALL_APP, applicationInfo.isFreeInstallApp},
947         {APPLICATION_RUNNING_RESOURCES_APPLY, applicationInfo.runningResourcesApply},
948         {APPLICATION_ASSOCIATED_WAKE_UP, applicationInfo.associatedWakeUp},
949         {APPLICATION_HIDE_DESKTOP_ICON, applicationInfo.hideDesktopIcon},
950         {APPLICATION_FORM_VISIBLE_NOTIFY, applicationInfo.formVisibleNotify},
951         {APPLICATION_ALLOW_COMMON_EVENT, applicationInfo.allowCommonEvent},
952         {APPLICATION_CODE_PATH, applicationInfo.codePath},
953         {APPLICATION_DATA_DIR, applicationInfo.dataDir},
954         {APPLICATION_DATA_BASE_DIR, applicationInfo.dataBaseDir},
955         {APPLICATION_CACHE_DIR, applicationInfo.cacheDir},
956         {APPLICATION_ENTRY_DIR, applicationInfo.entryDir},
957         {APPLICATION_API_RELEASETYPE, applicationInfo.apiReleaseType},
958         {APPLICATION_DEBUG, applicationInfo.debug},
959         {APPLICATION_DEVICE_ID, applicationInfo.deviceId},
960         {APPLICATION_DISTRIBUTED_NOTIFICATION_ENABLED, applicationInfo.distributedNotificationEnabled},
961         {APPLICATION_ALLOW_ENABLE_NOTIFICATION, applicationInfo.allowEnableNotification},
962         {APPLICATION_ENTITY_TYPE, applicationInfo.entityType},
963         {APPLICATION_PROCESS, applicationInfo.process},
964         {APPLICATION_SUPPORTED_MODES, applicationInfo.supportedModes},
965         {APPLICATION_VENDOR, applicationInfo.vendor},
966         {APPLICATION_PRIVILEGE_LEVEL, applicationInfo.appPrivilegeLevel},
967         {APPLICATION_ACCESSTOKEN_ID, applicationInfo.accessTokenId},
968         {APPLICATION_ACCESSTOKEN_ID_EX, applicationInfo.accessTokenIdEx},
969         {APPLICATION_ENABLED, applicationInfo.enabled},
970         {APPLICATION_UID, applicationInfo.uid},
971         {APPLICATION_PERMISSIONS, applicationInfo.permissions},
972         {APPLICATION_MODULE_SOURCE_DIRS, applicationInfo.moduleSourceDirs},
973         {APPLICATION_MODULE_INFOS, applicationInfo.moduleInfos},
974         {APPLICATION_HNP_PACKAGES, applicationInfo.hnpPackages},
975         {APPLICATION_META_DATA_CONFIG_JSON, applicationInfo.metaData},
976         {APPLICATION_META_DATA_MODULE_JSON, applicationInfo.metadata},
977         {APPLICATION_FINGERPRINT, applicationInfo.fingerprint},
978         {APPLICATION_ICON, applicationInfo.icon},
979         {APPLICATION_FLAGS, applicationInfo.flags},
980         {APPLICATION_ENTRY_MODULE_NAME, applicationInfo.entryModuleName},
981         {APPLICATION_NATIVE_LIBRARY_PATH, applicationInfo.nativeLibraryPath},
982         {APPLICATION_CPU_ABI, applicationInfo.cpuAbi},
983         {APPLICATION_ARK_NATIVE_FILE_PATH, applicationInfo.arkNativeFilePath},
984         {APPLICATION_ARK_NATIVE_FILE_ABI, applicationInfo.arkNativeFileAbi},
985         {APPLICATION_IS_COMPRESS_NATIVE_LIBS, applicationInfo.isCompressNativeLibs},
986         {APPLICATION_SIGNATURE_KEY, applicationInfo.signatureKey},
987         {APPLICATION_TARGETBUNDLELIST, applicationInfo.targetBundleList},
988         {APPLICATION_APP_DISTRIBUTION_TYPE, applicationInfo.appDistributionType},
989         {APPLICATION_APP_PROVISION_TYPE, applicationInfo.appProvisionType},
990         {APPLICATION_ICON_RESOURCE, applicationInfo.iconResource},
991         {APPLICATION_LABEL_RESOURCE, applicationInfo.labelResource},
992         {APPLICATION_DESCRIPTION_RESOURCE, applicationInfo.descriptionResource},
993         {APPLICATION_MULTI_PROJECTS, applicationInfo.multiProjects},
994         {APPLICATION_CROWDTEST_DEADLINE, applicationInfo.crowdtestDeadline},
995         {APPLICATION_APP_QUICK_FIX, applicationInfo.appQuickFix},
996         {APPLICATION_NEED_APP_DETAIL, applicationInfo.needAppDetail},
997         {APPLICATION_APP_DETAIL_ABILITY_LIBRARY_PATH, applicationInfo.appDetailAbilityLibraryPath},
998         {APPLICATION_APP_TARGET_BUNDLE_NAME, applicationInfo.targetBundleName},
999         {APPLICATION_APP_TARGET_PRIORITY, applicationInfo.targetPriority},
1000         {APPLICATION_APP_OVERLAY_STATE, applicationInfo.overlayState},
1001         {APPLICATION_ASAN_ENABLED, applicationInfo.asanEnabled},
1002         {APPLICATION_ASAN_LOG_PATH, applicationInfo.asanLogPath},
1003         {APPLICATION_APP_TYPE, applicationInfo.bundleType},
1004         {APPLICATION_COMPILE_SDK_VERSION, applicationInfo.compileSdkVersion},
1005         {APPLICATION_COMPILE_SDK_TYPE, applicationInfo.compileSdkType},
1006         {APPLICATION_RESOURCES_APPLY, applicationInfo.resourcesApply},
1007         {APPLICATION_GWP_ASAN_ENABLED, applicationInfo.gwpAsanEnabled},
1008         {APPLICATION_HWASAN_ENABLED, applicationInfo.hwasanEnabled},
1009         {APPLICATION_RESERVED_FLAG, applicationInfo.applicationReservedFlag},
1010         {APPLICATION_TSAN_ENABLED, applicationInfo.tsanEnabled},
1011         {APPLICATION_APP_ENVIRONMENTS, applicationInfo.appEnvironments},
1012         {APPLICATION_ORGANIZATION, applicationInfo.organization},
1013         {APPLICATION_MULTI_APP_MODE, applicationInfo.multiAppMode},
1014         {APPLICATION_MAX_CHILD_PROCESS, applicationInfo.maxChildProcess},
1015         {APPLICATION_APP_INDEX, applicationInfo.appIndex},
1016         {APPLICATION_INSTALL_SOURCE, applicationInfo.installSource},
1017         {APPLICATION_CONFIGURATION, applicationInfo.configuration},
1018         {APPLICATION_CLOUD_FILE_SYNC_ENABLED, applicationInfo.cloudFileSyncEnabled},
1019         {APPLICATION_APPLICATION_FLAGS, applicationInfo.applicationFlags},
1020     };
1021 }
1022 
from_json(const nlohmann::json & jsonObject,ApplicationInfo & applicationInfo)1023 void from_json(const nlohmann::json &jsonObject, ApplicationInfo &applicationInfo)
1024 {
1025     const auto &jsonObjectEnd = jsonObject.end();
1026     int32_t parseResult = ERR_OK;
1027     GetValueIfFindKey<std::string>(jsonObject, jsonObjectEnd, APPLICATION_NAME,
1028         applicationInfo.name, JsonType::STRING, false, parseResult, ArrayType::NOT_ARRAY);
1029     GetValueIfFindKey<std::string>(jsonObject, jsonObjectEnd, Constants::BUNDLE_NAME,
1030         applicationInfo.bundleName, JsonType::STRING, false, parseResult, ArrayType::NOT_ARRAY);
1031     GetValueIfFindKey<uint32_t>(jsonObject, jsonObjectEnd, APPLICATION_VERSION_CODE,
1032         applicationInfo.versionCode, JsonType::NUMBER, false, parseResult, ArrayType::NOT_ARRAY);
1033     GetValueIfFindKey<std::string>(jsonObject, jsonObjectEnd, APPLICATION_VERSION_NAME,
1034         applicationInfo.versionName, JsonType::STRING, false, parseResult, ArrayType::NOT_ARRAY);
1035     GetValueIfFindKey<int32_t>(jsonObject, jsonObjectEnd, APPLICATION_MIN_COMPATIBLE_VERSION_CODE,
1036         applicationInfo.minCompatibleVersionCode, JsonType::NUMBER, false, parseResult, ArrayType::NOT_ARRAY);
1037     GetValueIfFindKey<int32_t>(jsonObject, jsonObjectEnd, APPLICATION_API_COMPATIBLE_VERSION,
1038         applicationInfo.apiCompatibleVersion, JsonType::NUMBER, false, parseResult, ArrayType::NOT_ARRAY);
1039     GetValueIfFindKey<int32_t>(jsonObject, jsonObjectEnd, APPLICATION_API_TARGET_VERSION,
1040         applicationInfo.apiTargetVersion, JsonType::NUMBER, false, parseResult, ArrayType::NOT_ARRAY);
1041     GetValueIfFindKey<std::string>(jsonObject, jsonObjectEnd, APPLICATION_ICON_PATH,
1042         applicationInfo.iconPath, JsonType::STRING, false, parseResult, ArrayType::NOT_ARRAY);
1043     GetValueIfFindKey<uint32_t>(jsonObject, jsonObjectEnd, APPLICATION_ICON_ID,
1044         applicationInfo.iconId, JsonType::NUMBER, false, parseResult, ArrayType::NOT_ARRAY);
1045     GetValueIfFindKey<std::string>(jsonObject, jsonObjectEnd, APPLICATION_LABEL,
1046         applicationInfo.label, JsonType::STRING, false, parseResult, ArrayType::NOT_ARRAY);
1047     GetValueIfFindKey<uint32_t>(jsonObject, jsonObjectEnd, APPLICATION_LABEL_ID,
1048         applicationInfo.labelId, JsonType::NUMBER, false, parseResult, ArrayType::NOT_ARRAY);
1049     GetValueIfFindKey<std::string>(jsonObject, jsonObjectEnd, APPLICATION_DESCRIPTION,
1050         applicationInfo.description, JsonType::STRING, false, parseResult, ArrayType::NOT_ARRAY);
1051     GetValueIfFindKey<uint32_t>(jsonObject, jsonObjectEnd, APPLICATION_DESCRIPTION_ID,
1052         applicationInfo.descriptionId, JsonType::NUMBER, false, parseResult, ArrayType::NOT_ARRAY);
1053     GetValueIfFindKey<bool>(jsonObject, jsonObjectEnd, APPLICATION_KEEP_ALIVE,
1054         applicationInfo.keepAlive, JsonType::BOOLEAN, false, parseResult, ArrayType::NOT_ARRAY);
1055     GetValueIfFindKey<bool>(jsonObject, jsonObjectEnd, APPLICATION_REMOVABLE,
1056         applicationInfo.removable, JsonType::BOOLEAN, false, parseResult, ArrayType::NOT_ARRAY);
1057     GetValueIfFindKey<bool>(jsonObject, jsonObjectEnd, APPLICATION_SINGLETON,
1058         applicationInfo.singleton, JsonType::BOOLEAN, false, parseResult, ArrayType::NOT_ARRAY);
1059     GetValueIfFindKey<bool>(jsonObject, jsonObjectEnd, APPLICATION_USER_DATA_CLEARABLE,
1060         applicationInfo.userDataClearable, JsonType::BOOLEAN, false, parseResult, ArrayType::NOT_ARRAY);
1061     GetValueIfFindKey<bool>(jsonObject, jsonObjectEnd, ALLOW_APP_RUN_WHEN_DEVICE_FIRST_LOCKED,
1062         applicationInfo.allowAppRunWhenDeviceFirstLocked, JsonType::BOOLEAN, false, parseResult, ArrayType::NOT_ARRAY);
1063     GetValueIfFindKey<bool>(jsonObject, jsonObjectEnd, APPLICATION_ACCESSIBLE,
1064         applicationInfo.accessible, JsonType::BOOLEAN, false, parseResult, ArrayType::NOT_ARRAY);
1065     GetValueIfFindKey<bool>(jsonObject, jsonObjectEnd, APPLICATION_IS_SYSTEM_APP,
1066         applicationInfo.isSystemApp, JsonType::BOOLEAN, false, parseResult, ArrayType::NOT_ARRAY);
1067     GetValueIfFindKey<bool>(jsonObject, jsonObjectEnd, APPLICATION_IS_LAUNCHER_APP,
1068         applicationInfo.isLauncherApp, JsonType::BOOLEAN, false, parseResult, ArrayType::NOT_ARRAY);
1069     GetValueIfFindKey<bool>(jsonObject, jsonObjectEnd, APPLICATION_IS_FREEINSTALL_APP,
1070         applicationInfo.isFreeInstallApp, JsonType::BOOLEAN, false, parseResult, ArrayType::NOT_ARRAY);
1071     GetValueIfFindKey<bool>(jsonObject, jsonObjectEnd, APPLICATION_RUNNING_RESOURCES_APPLY,
1072         applicationInfo.runningResourcesApply, JsonType::BOOLEAN, false, parseResult, ArrayType::NOT_ARRAY);
1073     GetValueIfFindKey<bool>(jsonObject, jsonObjectEnd, APPLICATION_ASSOCIATED_WAKE_UP,
1074         applicationInfo.associatedWakeUp, JsonType::BOOLEAN, false, parseResult, ArrayType::NOT_ARRAY);
1075     GetValueIfFindKey<bool>(jsonObject, jsonObjectEnd, APPLICATION_HIDE_DESKTOP_ICON,
1076         applicationInfo.hideDesktopIcon, JsonType::BOOLEAN, false, parseResult, ArrayType::NOT_ARRAY);
1077     GetValueIfFindKey<bool>(jsonObject, jsonObjectEnd, APPLICATION_FORM_VISIBLE_NOTIFY,
1078         applicationInfo.formVisibleNotify, JsonType::BOOLEAN, false, parseResult, ArrayType::NOT_ARRAY);
1079     GetValueIfFindKey<std::vector<std::string>>(jsonObject, jsonObjectEnd, APPLICATION_ALLOW_COMMON_EVENT,
1080         applicationInfo.allowCommonEvent, JsonType::ARRAY, false, parseResult, ArrayType::STRING);
1081     GetValueIfFindKey<std::string>(jsonObject, jsonObjectEnd, APPLICATION_CODE_PATH,
1082         applicationInfo.codePath, JsonType::STRING, false, parseResult, ArrayType::NOT_ARRAY);
1083     GetValueIfFindKey<std::string>(jsonObject, jsonObjectEnd, APPLICATION_DATA_DIR,
1084         applicationInfo.dataDir, JsonType::STRING, false, parseResult, ArrayType::NOT_ARRAY);
1085     GetValueIfFindKey<std::string>(jsonObject, jsonObjectEnd, APPLICATION_DATA_BASE_DIR,
1086         applicationInfo.dataBaseDir, JsonType::STRING, false, parseResult, ArrayType::NOT_ARRAY);
1087     GetValueIfFindKey<std::string>(jsonObject, jsonObjectEnd, APPLICATION_CACHE_DIR,
1088         applicationInfo.cacheDir, JsonType::STRING, false, parseResult, ArrayType::NOT_ARRAY);
1089     GetValueIfFindKey<std::string>(jsonObject, jsonObjectEnd, APPLICATION_ENTRY_DIR,
1090         applicationInfo.entryDir, JsonType::STRING, false, parseResult, ArrayType::NOT_ARRAY);
1091     GetValueIfFindKey<std::string>(jsonObject, jsonObjectEnd, APPLICATION_API_RELEASETYPE,
1092         applicationInfo.apiReleaseType, JsonType::STRING, false, parseResult, ArrayType::NOT_ARRAY);
1093     GetValueIfFindKey<bool>(jsonObject, jsonObjectEnd, APPLICATION_DEBUG,
1094         applicationInfo.debug, JsonType::BOOLEAN, false, parseResult, ArrayType::NOT_ARRAY);
1095     GetValueIfFindKey<std::string>(jsonObject, jsonObjectEnd, APPLICATION_DEVICE_ID,
1096         applicationInfo.deviceId, JsonType::STRING, false, parseResult, ArrayType::NOT_ARRAY);
1097     GetValueIfFindKey<bool>(jsonObject, jsonObjectEnd, APPLICATION_DISTRIBUTED_NOTIFICATION_ENABLED,
1098         applicationInfo.distributedNotificationEnabled, JsonType::BOOLEAN, false, parseResult, ArrayType::NOT_ARRAY);
1099     GetValueIfFindKey<bool>(jsonObject, jsonObjectEnd, APPLICATION_ALLOW_ENABLE_NOTIFICATION,
1100         applicationInfo.allowEnableNotification, JsonType::BOOLEAN, false, parseResult, ArrayType::NOT_ARRAY);
1101     GetValueIfFindKey<std::string>(jsonObject, jsonObjectEnd, APPLICATION_ENTITY_TYPE,
1102         applicationInfo.entityType, JsonType::STRING, false, parseResult, ArrayType::NOT_ARRAY);
1103     GetValueIfFindKey<std::string>(jsonObject, jsonObjectEnd, APPLICATION_PROCESS,
1104         applicationInfo.process, JsonType::STRING, false, parseResult, ArrayType::NOT_ARRAY);
1105     GetValueIfFindKey<int>(jsonObject, jsonObjectEnd, APPLICATION_SUPPORTED_MODES,
1106         applicationInfo.supportedModes, JsonType::NUMBER, false, parseResult, ArrayType::NOT_ARRAY);
1107     GetValueIfFindKey<std::string>(jsonObject, jsonObjectEnd, APPLICATION_VENDOR,
1108         applicationInfo.vendor, JsonType::STRING, false, parseResult, ArrayType::NOT_ARRAY);
1109     GetValueIfFindKey<std::string>(jsonObject, jsonObjectEnd, APPLICATION_PRIVILEGE_LEVEL,
1110         applicationInfo.appPrivilegeLevel, JsonType::STRING, false, parseResult, ArrayType::NOT_ARRAY);
1111     GetValueIfFindKey<uint32_t>(jsonObject, jsonObjectEnd, APPLICATION_ACCESSTOKEN_ID,
1112         applicationInfo.accessTokenId, JsonType::NUMBER, false, parseResult, ArrayType::NOT_ARRAY);
1113     GetValueIfFindKey<uint64_t>(jsonObject, jsonObjectEnd, APPLICATION_ACCESSTOKEN_ID_EX,
1114         applicationInfo.accessTokenIdEx, JsonType::NUMBER, false, parseResult, ArrayType::NOT_ARRAY);
1115     GetValueIfFindKey<bool>(jsonObject, jsonObjectEnd, APPLICATION_ENABLED,
1116         applicationInfo.enabled, JsonType::BOOLEAN, false, parseResult, ArrayType::NOT_ARRAY);
1117     GetValueIfFindKey<int>(jsonObject, jsonObjectEnd, APPLICATION_UID,
1118         applicationInfo.uid, JsonType::NUMBER, false, parseResult, ArrayType::NOT_ARRAY);
1119     GetValueIfFindKey<std::vector<std::string>>(jsonObject, jsonObjectEnd, APPLICATION_PERMISSIONS,
1120         applicationInfo.permissions, JsonType::ARRAY, false, parseResult, ArrayType::STRING);
1121     GetValueIfFindKey<std::vector<std::string>>(jsonObject, jsonObjectEnd, APPLICATION_MODULE_SOURCE_DIRS,
1122         applicationInfo.moduleSourceDirs, JsonType::ARRAY, false, parseResult, ArrayType::STRING);
1123     GetValueIfFindKey<std::vector<ModuleInfo>>(jsonObject, jsonObjectEnd, APPLICATION_MODULE_INFOS,
1124         applicationInfo.moduleInfos, JsonType::ARRAY, false, parseResult, ArrayType::OBJECT);
1125     GetValueIfFindKey<std::map<std::string, std::vector<HnpPackage>>>(jsonObject, jsonObjectEnd,
1126         APPLICATION_HNP_PACKAGES, applicationInfo.hnpPackages, JsonType::OBJECT, false,
1127         parseResult, ArrayType::NOT_ARRAY);
1128     GetValueIfFindKey<std::map<std::string, std::vector<CustomizeData>>>(jsonObject, jsonObjectEnd,
1129         APPLICATION_META_DATA_CONFIG_JSON,
1130         applicationInfo.metaData, JsonType::OBJECT, false, parseResult, ArrayType::NOT_ARRAY);
1131     GetValueIfFindKey<std::map<std::string, std::vector<Metadata>>>(jsonObject, jsonObjectEnd,
1132         APPLICATION_META_DATA_MODULE_JSON,
1133         applicationInfo.metadata, JsonType::OBJECT, false, parseResult, ArrayType::NOT_ARRAY);
1134     GetValueIfFindKey<std::string>(jsonObject, jsonObjectEnd, APPLICATION_FINGERPRINT,
1135         applicationInfo.fingerprint, JsonType::STRING, false, parseResult, ArrayType::NOT_ARRAY);
1136     GetValueIfFindKey<std::string>(jsonObject, jsonObjectEnd, APPLICATION_ICON,
1137         applicationInfo.icon, JsonType::STRING, false, parseResult, ArrayType::NOT_ARRAY);
1138     GetValueIfFindKey<int>(jsonObject, jsonObjectEnd, APPLICATION_FLAGS,
1139         applicationInfo.flags, JsonType::NUMBER, false, parseResult, ArrayType::NOT_ARRAY);
1140     GetValueIfFindKey<std::string>(jsonObject, jsonObjectEnd, APPLICATION_ENTRY_MODULE_NAME,
1141         applicationInfo.entryModuleName, JsonType::STRING, false, parseResult, ArrayType::NOT_ARRAY);
1142     GetValueIfFindKey<std::string>(jsonObject, jsonObjectEnd, APPLICATION_NATIVE_LIBRARY_PATH,
1143         applicationInfo.nativeLibraryPath, JsonType::STRING, false, parseResult, ArrayType::NOT_ARRAY);
1144     GetValueIfFindKey<std::string>(jsonObject, jsonObjectEnd, APPLICATION_CPU_ABI,
1145         applicationInfo.cpuAbi, JsonType::STRING, false, parseResult, ArrayType::NOT_ARRAY);
1146     GetValueIfFindKey<std::string>(jsonObject, jsonObjectEnd, APPLICATION_ARK_NATIVE_FILE_PATH,
1147         applicationInfo.arkNativeFilePath, JsonType::STRING, false, parseResult, ArrayType::NOT_ARRAY);
1148     GetValueIfFindKey<std::string>(jsonObject, jsonObjectEnd, APPLICATION_ARK_NATIVE_FILE_ABI,
1149         applicationInfo.arkNativeFileAbi, JsonType::STRING, false, parseResult, ArrayType::NOT_ARRAY);
1150     GetValueIfFindKey<bool>(jsonObject, jsonObjectEnd, APPLICATION_IS_COMPRESS_NATIVE_LIBS,
1151         applicationInfo.isCompressNativeLibs, JsonType::BOOLEAN, false, parseResult, ArrayType::NOT_ARRAY);
1152     GetValueIfFindKey<std::string>(jsonObject, jsonObjectEnd, APPLICATION_SIGNATURE_KEY,
1153         applicationInfo.signatureKey, JsonType::STRING, false, parseResult, ArrayType::NOT_ARRAY);
1154     GetValueIfFindKey<std::vector<std::string>>(jsonObject, jsonObjectEnd, APPLICATION_TARGETBUNDLELIST,
1155         applicationInfo.targetBundleList, JsonType::ARRAY, false, parseResult, ArrayType::STRING);
1156     GetValueIfFindKey<std::string>(jsonObject, jsonObjectEnd, APPLICATION_APP_DISTRIBUTION_TYPE,
1157         applicationInfo.appDistributionType, JsonType::STRING, false, parseResult, ArrayType::NOT_ARRAY);
1158     GetValueIfFindKey<std::string>(jsonObject, jsonObjectEnd, APPLICATION_APP_PROVISION_TYPE,
1159         applicationInfo.appProvisionType, JsonType::STRING, false, parseResult, ArrayType::NOT_ARRAY);
1160     GetValueIfFindKey<Resource>(jsonObject, jsonObjectEnd, APPLICATION_ICON_RESOURCE,
1161         applicationInfo.iconResource, JsonType::OBJECT, false, parseResult, ArrayType::NOT_ARRAY);
1162     GetValueIfFindKey<Resource>(jsonObject, jsonObjectEnd, APPLICATION_LABEL_RESOURCE,
1163         applicationInfo.labelResource, JsonType::OBJECT, false, parseResult, ArrayType::NOT_ARRAY);
1164     GetValueIfFindKey<Resource>(jsonObject, jsonObjectEnd, APPLICATION_DESCRIPTION_RESOURCE,
1165         applicationInfo.descriptionResource, JsonType::OBJECT, false, parseResult, ArrayType::NOT_ARRAY);
1166     GetValueIfFindKey<bool>(jsonObject, jsonObjectEnd, APPLICATION_MULTI_PROJECTS,
1167         applicationInfo.multiProjects, JsonType::BOOLEAN, false, parseResult, ArrayType::NOT_ARRAY);
1168     GetValueIfFindKey<int64_t>(jsonObject, jsonObjectEnd, APPLICATION_CROWDTEST_DEADLINE,
1169         applicationInfo.crowdtestDeadline, JsonType::NUMBER, false, parseResult, ArrayType::NOT_ARRAY);
1170     GetValueIfFindKey<AppQuickFix>(jsonObject, jsonObjectEnd, APPLICATION_APP_QUICK_FIX,
1171         applicationInfo.appQuickFix, JsonType::OBJECT, false, parseResult, ArrayType::NOT_ARRAY);
1172     GetValueIfFindKey<bool>(jsonObject, jsonObjectEnd, APPLICATION_NEED_APP_DETAIL,
1173         applicationInfo.needAppDetail, JsonType::BOOLEAN, false, parseResult, ArrayType::NOT_ARRAY);
1174     GetValueIfFindKey<std::string>(jsonObject, jsonObjectEnd, APPLICATION_APP_DETAIL_ABILITY_LIBRARY_PATH,
1175         applicationInfo.appDetailAbilityLibraryPath, JsonType::STRING, false, parseResult, ArrayType::NOT_ARRAY);
1176     GetValueIfFindKey<std::string>(jsonObject, jsonObjectEnd, APPLICATION_APP_TARGET_BUNDLE_NAME,
1177         applicationInfo.targetBundleName, JsonType::STRING, false, parseResult, ArrayType::NOT_ARRAY);
1178     GetValueIfFindKey<int>(jsonObject, jsonObjectEnd, APPLICATION_APP_TARGET_PRIORITY,
1179         applicationInfo.targetPriority, JsonType::NUMBER, false, parseResult, ArrayType::NOT_ARRAY);
1180     GetValueIfFindKey<int>(jsonObject, jsonObjectEnd, APPLICATION_APP_OVERLAY_STATE,
1181         applicationInfo.overlayState, JsonType::NUMBER, false, parseResult, ArrayType::NOT_ARRAY);
1182     GetValueIfFindKey<bool>(jsonObject, jsonObjectEnd, APPLICATION_ASAN_ENABLED,
1183         applicationInfo.asanEnabled, JsonType::BOOLEAN, false, parseResult, ArrayType::NOT_ARRAY);
1184     GetValueIfFindKey<std::string>(jsonObject, jsonObjectEnd, APPLICATION_ASAN_LOG_PATH,
1185         applicationInfo.asanLogPath, JsonType::STRING, false, parseResult, ArrayType::NOT_ARRAY);
1186     GetValueIfFindKey<BundleType>(jsonObject, jsonObjectEnd, APPLICATION_APP_TYPE,
1187         applicationInfo.bundleType, JsonType::NUMBER, false, parseResult, ArrayType::NOT_ARRAY);
1188     GetValueIfFindKey<std::string>(jsonObject, jsonObjectEnd, APPLICATION_COMPILE_SDK_VERSION,
1189         applicationInfo.compileSdkVersion, JsonType::STRING, false, parseResult, ArrayType::NOT_ARRAY);
1190     GetValueIfFindKey<std::string>(jsonObject, jsonObjectEnd, APPLICATION_COMPILE_SDK_TYPE,
1191         applicationInfo.compileSdkType, JsonType::STRING, false, parseResult, ArrayType::NOT_ARRAY);
1192     GetValueIfFindKey<std::vector<int32_t>>(jsonObject, jsonObjectEnd, APPLICATION_RESOURCES_APPLY,
1193         applicationInfo.resourcesApply, JsonType::ARRAY, false, parseResult, ArrayType::NUMBER);
1194     GetValueIfFindKey<bool>(jsonObject, jsonObjectEnd, APPLICATION_GWP_ASAN_ENABLED,
1195         applicationInfo.gwpAsanEnabled, JsonType::BOOLEAN, false, parseResult, ArrayType::NOT_ARRAY);
1196     GetValueIfFindKey<uint32_t>(jsonObject, jsonObjectEnd, APPLICATION_RESERVED_FLAG,
1197         applicationInfo.applicationReservedFlag, JsonType::NUMBER, false, parseResult, ArrayType::NOT_ARRAY);
1198     GetValueIfFindKey<bool>(jsonObject, jsonObjectEnd, APPLICATION_TSAN_ENABLED,
1199         applicationInfo.tsanEnabled, JsonType::BOOLEAN, false, parseResult, ArrayType::NOT_ARRAY);
1200     GetValueIfFindKey<std::string>(jsonObject, jsonObjectEnd, APPLICATION_ORGANIZATION,
1201         applicationInfo.organization, JsonType::STRING, false, parseResult, ArrayType::NOT_ARRAY);
1202     GetValueIfFindKey<std::vector<ApplicationEnvironment>>(jsonObject, jsonObjectEnd,
1203         APPLICATION_APP_ENVIRONMENTS,
1204         applicationInfo.appEnvironments, JsonType::ARRAY, false, parseResult, ArrayType::OBJECT);
1205     GetValueIfFindKey<MultiAppModeData>(jsonObject, jsonObjectEnd, APPLICATION_MULTI_APP_MODE,
1206         applicationInfo.multiAppMode, JsonType::OBJECT, false, parseResult, ArrayType::NOT_ARRAY);
1207     GetValueIfFindKey<int32_t>(jsonObject, jsonObjectEnd, APPLICATION_APP_INDEX,
1208         applicationInfo.appIndex, JsonType::NUMBER, false, parseResult, ArrayType::NOT_ARRAY);
1209     GetValueIfFindKey<int32_t>(jsonObject, jsonObjectEnd, APPLICATION_MAX_CHILD_PROCESS,
1210         applicationInfo.maxChildProcess, JsonType::NUMBER, false, parseResult, ArrayType::NOT_ARRAY);
1211     GetValueIfFindKey<std::string>(jsonObject, jsonObjectEnd, APPLICATION_INSTALL_SOURCE,
1212         applicationInfo.installSource, JsonType::STRING, false, parseResult, ArrayType::NOT_ARRAY);
1213     GetValueIfFindKey<bool>(jsonObject, jsonObjectEnd, APPLICATION_HWASAN_ENABLED,
1214         applicationInfo.hwasanEnabled, JsonType::BOOLEAN, false, parseResult, ArrayType::NOT_ARRAY);
1215     GetValueIfFindKey<std::string>(jsonObject, jsonObjectEnd, APPLICATION_CONFIGURATION,
1216         applicationInfo.configuration, JsonType::STRING, false, parseResult, ArrayType::NOT_ARRAY);
1217     GetValueIfFindKey<bool>(jsonObject, jsonObjectEnd, APPLICATION_CLOUD_FILE_SYNC_ENABLED,
1218         applicationInfo.cloudFileSyncEnabled, JsonType::BOOLEAN, false, parseResult, ArrayType::NOT_ARRAY);
1219     GetValueIfFindKey<int32_t>(jsonObject, jsonObjectEnd, APPLICATION_APPLICATION_FLAGS,
1220         applicationInfo.applicationFlags, JsonType::NUMBER, false, parseResult, ArrayType::NOT_ARRAY);
1221     if (parseResult != ERR_OK) {
1222         APP_LOGE("from_json error : %{public}d", parseResult);
1223     }
1224 }
1225 
ConvertToCompatibleApplicationInfo(CompatibleApplicationInfo & compatibleApplicationInfo) const1226 void ApplicationInfo::ConvertToCompatibleApplicationInfo(CompatibleApplicationInfo& compatibleApplicationInfo) const
1227 {
1228     APP_LOGD("ApplicationInfo::ConvertToCompatibleApplicationInfo called");
1229     compatibleApplicationInfo.name = name;
1230     compatibleApplicationInfo.icon = icon;
1231     compatibleApplicationInfo.label = label;
1232     compatibleApplicationInfo.description = description;
1233     compatibleApplicationInfo.cpuAbi = cpuAbi;
1234     compatibleApplicationInfo.process = process;
1235     compatibleApplicationInfo.systemApp = isSystemApp;
1236     compatibleApplicationInfo.isCompressNativeLibs = isCompressNativeLibs;
1237     compatibleApplicationInfo.iconId = iconId;
1238     compatibleApplicationInfo.labelId = labelId;
1239     compatibleApplicationInfo.descriptionId = descriptionId;
1240     compatibleApplicationInfo.permissions = permissions;
1241     compatibleApplicationInfo.moduleInfos = moduleInfos;
1242     compatibleApplicationInfo.supportedModes = supportedModes;
1243     compatibleApplicationInfo.enabled = enabled;
1244     compatibleApplicationInfo.debug = debug;
1245 }
1246 }  // namespace AppExecFwk
1247 }  // namespace OHOS
1248