• 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 <unistd.h>
22 
23 #include "message_parcel.h"
24 #include "nlohmann/json.hpp"
25 #include "parcel_macro.h"
26 #include "string_ex.h"
27 
28 #include "app_log_wrapper.h"
29 #include "bundle_constants.h"
30 #include "json_util.h"
31 
32 namespace OHOS {
33 namespace AppExecFwk {
34 namespace {
35 const std::string APPLICATION_NAME = "name";
36 const std::string APPLICATION_BUNDLE_NAME = "bundleName";
37 const std::string APPLICATION_VERSION_CODE = "versionCode";
38 const std::string APPLICATION_VERSION_NAME = "versionName";
39 const std::string APPLICATION_MIN_COMPATIBLE_VERSION_CODE = "minCompatibleVersionCode";
40 const std::string APPLICATION_API_COMPATIBLE_VERSION = "apiCompatibleVersion";
41 const std::string APPLICATION_API_TARGET_VERSION = "apiTargetVersion";
42 const std::string APPLICATION_ICON_PATH = "iconPath";
43 const std::string APPLICATION_ICON_ID = "iconId";
44 const std::string APPLICATION_LABEL = "label";
45 const std::string APPLICATION_LABEL_ID = "labelId";
46 const std::string APPLICATION_DESCRIPTION = "description";
47 const std::string APPLICATION_DESCRIPTION_ID = "descriptionId";
48 const std::string APPLICATION_KEEP_ALIVE = "keepAlive";
49 const std::string APPLICATION_REMOVABLE = "removable";
50 const std::string APPLICATION_SINGLE_USER = "singleUser";
51 const std::string APPLICATION_USER_DATA_CLEARABLE = "userDataClearable";
52 const std::string APPLICATION_IS_SYSTEM_APP = "isSystemApp";
53 const std::string APPLICATION_IS_LAUNCHER_APP = "isLauncherApp";
54 const std::string APPLICATION_CODE_PATH = "codePath";
55 const std::string APPLICATION_DATA_DIR = "dataDir";
56 const std::string APPLICATION_DATA_BASE_DIR = "dataBaseDir";
57 const std::string APPLICATION_CACHE_DIR = "cacheDir";
58 const std::string APPLICATION_ENTRY_DIR = "entryDir";
59 const std::string APPLICATION_API_RELEASETYPE = "apiReleaseType";
60 const std::string APPLICATION_DEBUG = "debug";
61 const std::string APPLICATION_DEVICE_ID = "deviceId";
62 const std::string APPLICATION_DISTRIBUTED_NOTIFICATION_ENABLED = "distributedNotificationEnabled";
63 const std::string APPLICATION_ENTITY_TYPE = "entityType";
64 const std::string APPLICATION_PROCESS = "process";
65 const std::string APPLICATION_SUPPORTED_MODES = "supportedModes";
66 const std::string APPLICATION_VENDOR = "vendor";
67 const std::string APPLICATION_ACCESSIBLE = "accessible";
68 const std::string APPLICATION_PRIVILEGE_LEVEL = "appPrivilegeLevel";
69 const std::string APPLICATION_ACCESSTOKEN_ID = "accessTokenId";
70 const std::string APPLICATION_ENABLED = "enabled";
71 const std::string APPLICATION_UID = "uid";
72 const std::string APPLICATION_PERMISSIONS = "permissions";
73 const std::string APPLICATION_MODULE_SOURCE_DIRS = "moduleSourceDirs";
74 const std::string APPLICATION_MODULE_INFOS = "moduleInfos";
75 const std::string APPLICATION_META_DATA_CONFIG_JSON = "metaData";
76 const std::string APPLICATION_META_DATA_MODULE_JSON = "metadata";
77 const std::string APPLICATION_IS_CLONED = "isCloned";
78 const std::string APPLICATION_ICON = "icon";
79 const std::string APPLICATION_FLAGS = "flags";
80 const std::string APPLICATION_ENTRY_MODULE_NAME = "entryModuleName";
81 const std::string APPLICATION_NATIVE_LIBRARY_PATH = "nativeLibraryPath";
82 const std::string APPLICATION_CPU_ABI = "cpuAbi";
83 const std::string APPLICATION_IS_COMPRESS_NATIVE_LIBS = "isCompressNativeLibs";
84 const std::string APPLICATION_SIGNATURE_KEY = "signatureKey";
85 }
86 
Metadata(const std::string & paramName,const std::string & paramValue,const std::string & paramResource)87 Metadata::Metadata(const std::string &paramName, const std::string &paramValue, const std::string &paramResource)
88     : name(paramName), value(paramValue), resource(paramResource)
89 {
90 }
91 
ReadFromParcel(Parcel & parcel)92 bool Metadata::ReadFromParcel(Parcel &parcel)
93 {
94     name = Str16ToStr8(parcel.ReadString16());
95     value = Str16ToStr8(parcel.ReadString16());
96     resource = Str16ToStr8(parcel.ReadString16());
97     return true;
98 }
99 
Marshalling(Parcel & parcel) const100 bool Metadata::Marshalling(Parcel &parcel) const
101 {
102     WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(String16, parcel, Str8ToStr16(name));
103     WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(String16, parcel, Str8ToStr16(value));
104     WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(String16, parcel, Str8ToStr16(resource));
105     return true;
106 }
107 
Unmarshalling(Parcel & parcel)108 Metadata *Metadata::Unmarshalling(Parcel &parcel)
109 {
110     Metadata *metadata = new (std::nothrow) Metadata;
111     if (metadata && !metadata->ReadFromParcel(parcel)) {
112         APP_LOGE("read from parcel failed");
113         delete metadata;
114         metadata = nullptr;
115     }
116     return metadata;
117 }
118 
CustomizeData(std::string paramName,std::string paramValue,std::string paramExtra)119 CustomizeData::CustomizeData(std::string paramName, std::string paramValue, std::string paramExtra)
120     :name(paramName), value(paramValue), extra(paramExtra)
121 {
122 }
123 
ReadFromParcel(Parcel & parcel)124 bool CustomizeData::ReadFromParcel(Parcel &parcel)
125 {
126     name = Str16ToStr8(parcel.ReadString16());
127     value = Str16ToStr8(parcel.ReadString16());
128     extra = Str16ToStr8(parcel.ReadString16());
129     return true;
130 }
131 
Unmarshalling(Parcel & parcel)132 CustomizeData *CustomizeData::Unmarshalling(Parcel &parcel)
133 {
134     CustomizeData *customizeData = new (std::nothrow) CustomizeData;
135     if (customizeData && !customizeData->ReadFromParcel(parcel)) {
136         APP_LOGE("read from parcel failed");
137         delete customizeData;
138         customizeData = nullptr;
139     }
140     return customizeData;
141 }
142 
Marshalling(Parcel & parcel) const143 bool CustomizeData::Marshalling(Parcel &parcel) const
144 {
145     WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(String16, parcel, Str8ToStr16(name));
146     WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(String16, parcel, Str8ToStr16(value));
147     WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(String16, parcel, Str8ToStr16(extra));
148     return true;
149 }
150 
ReadMetaDataFromParcel(Parcel & parcel)151 bool ApplicationInfo::ReadMetaDataFromParcel(Parcel &parcel)
152 {
153     int32_t metaDataSize = parcel.ReadInt32();
154     for (int32_t i = 0; i < metaDataSize; i++) {
155         std::string mouduleName = Str16ToStr8(parcel.ReadString16());
156         int32_t customizeDataSize = parcel.ReadInt32();
157         std::vector<CustomizeData> customizeDatas;
158         metaData[mouduleName] = customizeDatas;
159         for (int j = 0; j < customizeDataSize; j++) {
160             std::unique_ptr<CustomizeData> customizeData(parcel.ReadParcelable<CustomizeData>());
161             if (!customizeData) {
162                 APP_LOGE("ReadParcelable<CustomizeData> failed");
163                 return false;
164             }
165             metaData[mouduleName].emplace_back(*customizeData);
166         }
167     }
168     return true;
169 }
170 
ReadFromParcel(Parcel & parcel)171 bool ApplicationInfo::ReadFromParcel(Parcel &parcel)
172 {
173     MessageParcel *messageParcel = reinterpret_cast<MessageParcel *>(&parcel);
174     if (!messageParcel) {
175         APP_LOGE("Type conversion failed");
176         return false;
177     }
178     uint32_t length = messageParcel->ReadUint32();
179     if (length == 0) {
180         APP_LOGE("Invalid data length");
181         return false;
182     }
183     const char *data = reinterpret_cast<const char *>(messageParcel->ReadRawData(length));
184     if (!data) {
185         APP_LOGE("Fail to read raw data, length = %{public}d", length);
186         return false;
187     }
188     nlohmann::json jsonObject = nlohmann::json::parse(data, nullptr, false);
189     if (jsonObject.is_discarded()) {
190         APP_LOGE("failed to parse ApplicationInfo");
191         return false;
192     }
193     *this = jsonObject.get<ApplicationInfo>();
194     return true;
195 }
196 
Unmarshalling(Parcel & parcel)197 ApplicationInfo *ApplicationInfo::Unmarshalling(Parcel &parcel)
198 {
199     ApplicationInfo *info = new (std::nothrow) ApplicationInfo();
200     if (info && !info->ReadFromParcel(parcel)) {
201         APP_LOGW("read from parcel failed");
202         delete info;
203         info = nullptr;
204     }
205     return info;
206 }
207 
Marshalling(Parcel & parcel) const208 bool ApplicationInfo::Marshalling(Parcel &parcel) const
209 {
210     MessageParcel *messageParcel = reinterpret_cast<MessageParcel *>(&parcel);
211     if (!messageParcel) {
212         APP_LOGE("Type conversion failed");
213         return false;
214     }
215     nlohmann::json json = *this;
216     std::string str = json.dump();
217     if (!messageParcel->WriteUint32(str.size() + 1)) {
218         APP_LOGE("Failed to write data size");
219         return false;
220     }
221     if (!messageParcel->WriteRawData(str.c_str(), str.size() + 1)) {
222         APP_LOGE("Failed to write data");
223         return false;
224     }
225     return true;
226 }
227 
Dump(std::string prefix,int fd)228 void ApplicationInfo::Dump(std::string prefix, int fd)
229 {
230     APP_LOGI("called dump ApplicationInfo");
231     if (fd < 0) {
232         APP_LOGE("dump ApplicationInfo fd error");
233         return;
234     }
235     int flags = fcntl(fd, F_GETFL);
236     if (flags < 0) {
237         APP_LOGE("dump ApplicationInfo fcntl error, errno : %{public}d", errno);
238         return;
239     }
240     uint uflags = static_cast<uint>(flags);
241     uflags &= O_ACCMODE;
242     if ((uflags == O_WRONLY) || (uflags == O_RDWR)) {
243         nlohmann::json jsonObject = *this;
244         std::string result;
245         result.append(prefix);
246         result.append(jsonObject.dump(Constants::DUMP_INDENT));
247         int ret = TEMP_FAILURE_RETRY(write(fd, result.c_str(), result.size()));
248         if (ret < 0) {
249             APP_LOGE("dump ApplicationInfo write error, errno : %{public}d", errno);
250         }
251     }
252     return;
253 }
254 
to_json(nlohmann::json & jsonObject,const ApplicationInfo & applicationInfo)255 void to_json(nlohmann::json &jsonObject, const ApplicationInfo &applicationInfo)
256 {
257     jsonObject = nlohmann::json {
258         {APPLICATION_NAME, applicationInfo.name},
259         {APPLICATION_BUNDLE_NAME, applicationInfo.bundleName},
260         {APPLICATION_VERSION_CODE, applicationInfo.versionCode},
261         {APPLICATION_VERSION_NAME, applicationInfo.versionName},
262         {APPLICATION_MIN_COMPATIBLE_VERSION_CODE, applicationInfo.minCompatibleVersionCode},
263         {APPLICATION_API_COMPATIBLE_VERSION, applicationInfo.apiCompatibleVersion},
264         {APPLICATION_API_TARGET_VERSION, applicationInfo.apiTargetVersion},
265         {APPLICATION_ICON_PATH, applicationInfo.iconPath},
266         {APPLICATION_ICON_ID, applicationInfo.iconId},
267         {APPLICATION_LABEL, applicationInfo.label},
268         {APPLICATION_LABEL_ID, applicationInfo.labelId},
269         {APPLICATION_DESCRIPTION, applicationInfo.description},
270         {APPLICATION_DESCRIPTION_ID, applicationInfo.descriptionId},
271         {APPLICATION_KEEP_ALIVE, applicationInfo.keepAlive},
272         {APPLICATION_REMOVABLE, applicationInfo.removable},
273         {APPLICATION_SINGLE_USER, applicationInfo.singleUser},
274         {APPLICATION_USER_DATA_CLEARABLE, applicationInfo.userDataClearable},
275         {APPLICATION_ACCESSIBLE, applicationInfo.accessible},
276         {APPLICATION_IS_SYSTEM_APP, applicationInfo.isSystemApp},
277         {APPLICATION_IS_LAUNCHER_APP, applicationInfo.isLauncherApp},
278         {APPLICATION_CODE_PATH, applicationInfo.codePath},
279         {APPLICATION_DATA_DIR, applicationInfo.dataDir},
280         {APPLICATION_DATA_BASE_DIR, applicationInfo.dataBaseDir},
281         {APPLICATION_CACHE_DIR, applicationInfo.cacheDir},
282         {APPLICATION_ENTRY_DIR, applicationInfo.entryDir},
283         {APPLICATION_API_RELEASETYPE, applicationInfo.apiReleaseType},
284         {APPLICATION_DEBUG, applicationInfo.debug},
285         {APPLICATION_DEVICE_ID, applicationInfo.deviceId},
286         {APPLICATION_DISTRIBUTED_NOTIFICATION_ENABLED, applicationInfo.distributedNotificationEnabled},
287         {APPLICATION_ENTITY_TYPE, applicationInfo.entityType},
288         {APPLICATION_PROCESS, applicationInfo.process},
289         {APPLICATION_SUPPORTED_MODES, applicationInfo.supportedModes},
290         {APPLICATION_VENDOR, applicationInfo.vendor},
291         {APPLICATION_PRIVILEGE_LEVEL, applicationInfo.appPrivilegeLevel},
292         {APPLICATION_ACCESSTOKEN_ID, applicationInfo.accessTokenId},
293         {APPLICATION_ENABLED, applicationInfo.enabled},
294         {APPLICATION_UID, applicationInfo.uid},
295         {APPLICATION_PERMISSIONS, applicationInfo.permissions},
296         {APPLICATION_MODULE_SOURCE_DIRS, applicationInfo.moduleSourceDirs},
297         {APPLICATION_MODULE_INFOS, applicationInfo.moduleInfos},
298         {APPLICATION_META_DATA_CONFIG_JSON, applicationInfo.metaData},
299         {APPLICATION_META_DATA_MODULE_JSON, applicationInfo.metadata},
300         {APPLICATION_IS_CLONED, applicationInfo.isCloned},
301         {APPLICATION_ICON, applicationInfo.icon},
302         {APPLICATION_FLAGS, applicationInfo.flags},
303         {APPLICATION_ENTRY_MODULE_NAME, applicationInfo.entryModuleName},
304         {APPLICATION_NATIVE_LIBRARY_PATH, applicationInfo.nativeLibraryPath},
305         {APPLICATION_CPU_ABI, applicationInfo.cpuAbi},
306         {APPLICATION_IS_COMPRESS_NATIVE_LIBS, applicationInfo.isCompressNativeLibs},
307         {APPLICATION_SIGNATURE_KEY, applicationInfo.signatureKey}
308     };
309 }
310 
from_json(const nlohmann::json & jsonObject,ApplicationInfo & applicationInfo)311 void from_json(const nlohmann::json &jsonObject, ApplicationInfo &applicationInfo)
312 {
313     const auto &jsonObjectEnd = jsonObject.end();
314     int32_t parseResult = ERR_OK;
315     GetValueIfFindKey<std::string>(jsonObject,
316         jsonObjectEnd,
317         APPLICATION_NAME,
318         applicationInfo.name,
319         JsonType::STRING,
320         false,
321         parseResult,
322         ArrayType::NOT_ARRAY);
323     GetValueIfFindKey<std::string>(jsonObject,
324         jsonObjectEnd,
325         APPLICATION_BUNDLE_NAME,
326         applicationInfo.bundleName,
327         JsonType::STRING,
328         false,
329         parseResult,
330         ArrayType::NOT_ARRAY);
331     GetValueIfFindKey<uint32_t>(jsonObject,
332         jsonObjectEnd,
333         APPLICATION_VERSION_CODE,
334         applicationInfo.versionCode,
335         JsonType::NUMBER,
336         false,
337         parseResult,
338         ArrayType::NOT_ARRAY);
339     GetValueIfFindKey<std::string>(jsonObject,
340         jsonObjectEnd,
341         APPLICATION_VERSION_NAME,
342         applicationInfo.versionName,
343         JsonType::STRING,
344         false,
345         parseResult,
346         ArrayType::NOT_ARRAY);
347     GetValueIfFindKey<int32_t>(jsonObject,
348         jsonObjectEnd,
349         APPLICATION_MIN_COMPATIBLE_VERSION_CODE,
350         applicationInfo.minCompatibleVersionCode,
351         JsonType::NUMBER,
352         false,
353         parseResult,
354         ArrayType::NOT_ARRAY);
355     GetValueIfFindKey<int32_t>(jsonObject,
356         jsonObjectEnd,
357         APPLICATION_API_COMPATIBLE_VERSION,
358         applicationInfo.apiCompatibleVersion,
359         JsonType::NUMBER,
360         false,
361         parseResult,
362         ArrayType::NOT_ARRAY);
363     GetValueIfFindKey<int32_t>(jsonObject,
364         jsonObjectEnd,
365         APPLICATION_API_TARGET_VERSION,
366         applicationInfo.apiTargetVersion,
367         JsonType::NUMBER,
368         false,
369         parseResult,
370         ArrayType::NOT_ARRAY);
371     GetValueIfFindKey<std::string>(jsonObject,
372         jsonObjectEnd,
373         APPLICATION_ICON_PATH,
374         applicationInfo.iconPath,
375         JsonType::STRING,
376         false,
377         parseResult,
378         ArrayType::NOT_ARRAY);
379     GetValueIfFindKey<int32_t>(jsonObject,
380         jsonObjectEnd,
381         APPLICATION_ICON_ID,
382         applicationInfo.iconId,
383         JsonType::NUMBER,
384         false,
385         parseResult,
386         ArrayType::NOT_ARRAY);
387     GetValueIfFindKey<std::string>(jsonObject,
388         jsonObjectEnd,
389         APPLICATION_LABEL,
390         applicationInfo.label,
391         JsonType::STRING,
392         false,
393         parseResult,
394         ArrayType::NOT_ARRAY);
395     GetValueIfFindKey<int32_t>(jsonObject,
396         jsonObjectEnd,
397         APPLICATION_LABEL_ID,
398         applicationInfo.labelId,
399         JsonType::NUMBER,
400         false,
401         parseResult,
402         ArrayType::NOT_ARRAY);
403     GetValueIfFindKey<std::string>(jsonObject,
404         jsonObjectEnd,
405         APPLICATION_DESCRIPTION,
406         applicationInfo.description,
407         JsonType::STRING,
408         false,
409         parseResult,
410         ArrayType::NOT_ARRAY);
411     GetValueIfFindKey<int32_t>(jsonObject,
412         jsonObjectEnd,
413         APPLICATION_DESCRIPTION_ID,
414         applicationInfo.descriptionId,
415         JsonType::NUMBER,
416         false,
417         parseResult,
418         ArrayType::NOT_ARRAY);
419     GetValueIfFindKey<bool>(jsonObject,
420         jsonObjectEnd,
421         APPLICATION_KEEP_ALIVE,
422         applicationInfo.keepAlive,
423         JsonType::BOOLEAN,
424         false,
425         parseResult,
426         ArrayType::NOT_ARRAY);
427     GetValueIfFindKey<bool>(jsonObject,
428         jsonObjectEnd,
429         APPLICATION_REMOVABLE,
430         applicationInfo.removable,
431         JsonType::BOOLEAN,
432         false,
433         parseResult,
434         ArrayType::NOT_ARRAY);
435     GetValueIfFindKey<bool>(jsonObject,
436         jsonObjectEnd,
437         APPLICATION_SINGLE_USER,
438         applicationInfo.singleUser,
439         JsonType::BOOLEAN,
440         false,
441         parseResult,
442         ArrayType::NOT_ARRAY);
443     GetValueIfFindKey<bool>(jsonObject,
444         jsonObjectEnd,
445         APPLICATION_USER_DATA_CLEARABLE,
446         applicationInfo.userDataClearable,
447         JsonType::BOOLEAN,
448         false,
449         parseResult,
450         ArrayType::NOT_ARRAY);
451     GetValueIfFindKey<bool>(jsonObject,
452         jsonObjectEnd,
453         APPLICATION_ACCESSIBLE,
454         applicationInfo.accessible,
455         JsonType::BOOLEAN,
456         false,
457         parseResult,
458         ArrayType::NOT_ARRAY);
459     GetValueIfFindKey<bool>(jsonObject,
460         jsonObjectEnd,
461         APPLICATION_IS_SYSTEM_APP,
462         applicationInfo.isSystemApp,
463         JsonType::BOOLEAN,
464         false,
465         parseResult,
466         ArrayType::NOT_ARRAY);
467     GetValueIfFindKey<bool>(jsonObject,
468         jsonObjectEnd,
469         APPLICATION_IS_LAUNCHER_APP,
470         applicationInfo.isLauncherApp,
471         JsonType::BOOLEAN,
472         false,
473         parseResult,
474         ArrayType::NOT_ARRAY);
475     GetValueIfFindKey<std::string>(jsonObject,
476         jsonObjectEnd,
477         APPLICATION_CODE_PATH,
478         applicationInfo.codePath,
479         JsonType::STRING,
480         false,
481         parseResult,
482         ArrayType::NOT_ARRAY);
483     GetValueIfFindKey<std::string>(jsonObject,
484         jsonObjectEnd,
485         APPLICATION_DATA_DIR,
486         applicationInfo.dataDir,
487         JsonType::STRING,
488         false,
489         parseResult,
490         ArrayType::NOT_ARRAY);
491     GetValueIfFindKey<std::string>(jsonObject,
492         jsonObjectEnd,
493         APPLICATION_DATA_BASE_DIR,
494         applicationInfo.dataBaseDir,
495         JsonType::STRING,
496         false,
497         parseResult,
498         ArrayType::NOT_ARRAY);
499     GetValueIfFindKey<std::string>(jsonObject,
500         jsonObjectEnd,
501         APPLICATION_CACHE_DIR,
502         applicationInfo.cacheDir,
503         JsonType::STRING,
504         false,
505         parseResult,
506         ArrayType::NOT_ARRAY);
507     GetValueIfFindKey<std::string>(jsonObject,
508         jsonObjectEnd,
509         APPLICATION_ENTRY_DIR,
510         applicationInfo.entryDir,
511         JsonType::STRING,
512         false,
513         parseResult,
514         ArrayType::NOT_ARRAY);
515     GetValueIfFindKey<std::string>(jsonObject,
516         jsonObjectEnd,
517         APPLICATION_API_RELEASETYPE,
518         applicationInfo.apiReleaseType,
519         JsonType::STRING,
520         false,
521         parseResult,
522         ArrayType::NOT_ARRAY);
523     GetValueIfFindKey<bool>(jsonObject,
524         jsonObjectEnd,
525         APPLICATION_DEBUG,
526         applicationInfo.debug,
527         JsonType::BOOLEAN,
528         false,
529         parseResult,
530         ArrayType::NOT_ARRAY);
531     GetValueIfFindKey<std::string>(jsonObject,
532         jsonObjectEnd,
533         APPLICATION_DEVICE_ID,
534         applicationInfo.deviceId,
535         JsonType::STRING,
536         false,
537         parseResult,
538         ArrayType::NOT_ARRAY);
539     GetValueIfFindKey<bool>(jsonObject,
540         jsonObjectEnd,
541         APPLICATION_DISTRIBUTED_NOTIFICATION_ENABLED,
542         applicationInfo.distributedNotificationEnabled,
543         JsonType::BOOLEAN,
544         false,
545         parseResult,
546         ArrayType::NOT_ARRAY);
547     GetValueIfFindKey<std::string>(jsonObject,
548         jsonObjectEnd,
549         APPLICATION_ENTITY_TYPE,
550         applicationInfo.entityType,
551         JsonType::STRING,
552         false,
553         parseResult,
554         ArrayType::NOT_ARRAY);
555     GetValueIfFindKey<std::string>(jsonObject,
556         jsonObjectEnd,
557         APPLICATION_PROCESS,
558         applicationInfo.process,
559         JsonType::STRING,
560         false,
561         parseResult,
562         ArrayType::NOT_ARRAY);
563     GetValueIfFindKey<int>(jsonObject,
564         jsonObjectEnd,
565         APPLICATION_SUPPORTED_MODES,
566         applicationInfo.supportedModes,
567         JsonType::NUMBER,
568         false,
569         parseResult,
570         ArrayType::NOT_ARRAY);
571     GetValueIfFindKey<std::string>(jsonObject,
572         jsonObjectEnd,
573         APPLICATION_VENDOR,
574         applicationInfo.vendor,
575         JsonType::STRING,
576         false,
577         parseResult,
578         ArrayType::NOT_ARRAY);
579     GetValueIfFindKey<std::string>(jsonObject,
580         jsonObjectEnd,
581         APPLICATION_PRIVILEGE_LEVEL,
582         applicationInfo.appPrivilegeLevel,
583         JsonType::STRING,
584         false,
585         parseResult,
586         ArrayType::NOT_ARRAY);
587     GetValueIfFindKey<uint32_t>(jsonObject,
588         jsonObjectEnd,
589         APPLICATION_ACCESSTOKEN_ID,
590         applicationInfo.accessTokenId,
591         JsonType::NUMBER,
592         false,
593         parseResult,
594         ArrayType::NOT_ARRAY);
595     GetValueIfFindKey<bool>(jsonObject,
596         jsonObjectEnd,
597         APPLICATION_ENABLED,
598         applicationInfo.enabled,
599         JsonType::BOOLEAN,
600         false,
601         parseResult,
602         ArrayType::NOT_ARRAY);
603     GetValueIfFindKey<int>(jsonObject,
604         jsonObjectEnd,
605         APPLICATION_UID,
606         applicationInfo.uid,
607         JsonType::NUMBER,
608         false,
609         parseResult,
610         ArrayType::NOT_ARRAY);
611     GetValueIfFindKey<std::vector<std::string>>(jsonObject,
612         jsonObjectEnd,
613         APPLICATION_PERMISSIONS,
614         applicationInfo.permissions,
615         JsonType::ARRAY,
616         false,
617         parseResult,
618         ArrayType::STRING);
619     GetValueIfFindKey<std::vector<std::string>>(jsonObject,
620         jsonObjectEnd,
621         APPLICATION_MODULE_SOURCE_DIRS,
622         applicationInfo.moduleSourceDirs,
623         JsonType::ARRAY,
624         false,
625         parseResult,
626         ArrayType::STRING);
627     GetValueIfFindKey<std::vector<ModuleInfo>>(jsonObject,
628         jsonObjectEnd,
629         APPLICATION_MODULE_INFOS,
630         applicationInfo.moduleInfos,
631         JsonType::ARRAY,
632         false,
633         parseResult,
634         ArrayType::OBJECT);
635     GetValueIfFindKey<std::map<std::string, std::vector<CustomizeData>>>(jsonObject,
636         jsonObjectEnd,
637         APPLICATION_META_DATA_CONFIG_JSON,
638         applicationInfo.metaData,
639         JsonType::OBJECT,
640         false,
641         parseResult,
642         ArrayType::NOT_ARRAY);
643     GetValueIfFindKey<std::map<std::string, std::vector<Metadata>>>(jsonObject,
644         jsonObjectEnd,
645         APPLICATION_META_DATA_MODULE_JSON,
646         applicationInfo.metadata,
647         JsonType::OBJECT,
648         false,
649         parseResult,
650         ArrayType::NOT_ARRAY);
651     GetValueIfFindKey<bool>(jsonObject,
652         jsonObjectEnd,
653         APPLICATION_IS_CLONED,
654         applicationInfo.isCloned,
655         JsonType::BOOLEAN,
656         false,
657         parseResult,
658         ArrayType::NOT_ARRAY);
659     GetValueIfFindKey<std::string>(jsonObject,
660         jsonObjectEnd,
661         APPLICATION_ICON,
662         applicationInfo.icon,
663         JsonType::STRING,
664         false,
665         parseResult,
666         ArrayType::NOT_ARRAY);
667     GetValueIfFindKey<int>(jsonObject,
668         jsonObjectEnd,
669         APPLICATION_FLAGS,
670         applicationInfo.flags,
671         JsonType::NUMBER,
672         false,
673         parseResult,
674         ArrayType::NOT_ARRAY);
675     GetValueIfFindKey<std::string>(jsonObject,
676         jsonObjectEnd,
677         APPLICATION_ENTRY_MODULE_NAME,
678         applicationInfo.entryModuleName,
679         JsonType::STRING,
680         false,
681         parseResult,
682         ArrayType::NOT_ARRAY);
683     GetValueIfFindKey<std::string>(jsonObject,
684         jsonObjectEnd,
685         APPLICATION_NATIVE_LIBRARY_PATH,
686         applicationInfo.nativeLibraryPath,
687         JsonType::STRING,
688         false,
689         parseResult,
690         ArrayType::NOT_ARRAY);
691     GetValueIfFindKey<std::string>(jsonObject,
692         jsonObjectEnd,
693         APPLICATION_CPU_ABI,
694         applicationInfo.cpuAbi,
695         JsonType::STRING,
696         false,
697         parseResult,
698         ArrayType::NOT_ARRAY);
699     GetValueIfFindKey<bool>(jsonObject,
700         jsonObjectEnd,
701         APPLICATION_IS_COMPRESS_NATIVE_LIBS,
702         applicationInfo.isCompressNativeLibs,
703         JsonType::BOOLEAN,
704         false,
705         parseResult,
706         ArrayType::NOT_ARRAY);
707     GetValueIfFindKey<std::string>(jsonObject,
708         jsonObjectEnd,
709         APPLICATION_SIGNATURE_KEY,
710         applicationInfo.signatureKey,
711         JsonType::STRING,
712         false,
713         parseResult,
714         ArrayType::NOT_ARRAY);
715     if (parseResult != ERR_OK) {
716         APP_LOGE("from_json error, error code : %{public}d", parseResult);
717     }
718 }
719 
ConvertToCompatibleApplicationInfo(CompatibleApplicationInfo & compatibleApplicationInfo) const720 void ApplicationInfo::ConvertToCompatibleApplicationInfo(CompatibleApplicationInfo& compatibleApplicationInfo) const
721 {
722     APP_LOGD("ApplicationInfo::ConvertToCompatibleApplicationInfo called");
723     compatibleApplicationInfo.name = name;
724     compatibleApplicationInfo.icon = icon;
725     compatibleApplicationInfo.label = label;
726     compatibleApplicationInfo.description = description;
727     compatibleApplicationInfo.cpuAbi = cpuAbi;
728     compatibleApplicationInfo.process = process;
729     compatibleApplicationInfo.systemApp = isSystemApp;
730     compatibleApplicationInfo.isCompressNativeLibs = isCompressNativeLibs;
731     compatibleApplicationInfo.iconId = iconId;
732     compatibleApplicationInfo.labelId = labelId;
733     compatibleApplicationInfo.descriptionId = descriptionId;
734     compatibleApplicationInfo.permissions = permissions;
735     compatibleApplicationInfo.moduleInfos = moduleInfos;
736     compatibleApplicationInfo.supportedModes = supportedModes;
737     compatibleApplicationInfo.enabled = enabled;
738     compatibleApplicationInfo.debug = debug;
739 }
740 }  // namespace AppExecFwk
741 }  // namespace OHOS
742