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