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