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