• 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 "bundle_info.h"
17 
18 #include "json_util.h"
19 #include "parcel_macro.h"
20 #include "string_ex.h"
21 
22 namespace OHOS {
23 namespace AppExecFwk {
24 namespace {
25 const std::string BUNDLE_INFO_NAME = "name";
26 const std::string BUNDLE_INFO_LABEL = "label";
27 const std::string BUNDLE_INFO_DESCRIPTION = "description";
28 const std::string BUNDLE_INFO_VENDOR = "vendor";
29 const std::string BUNDLE_INFO_IS_KEEP_ALIVE = "isKeepAlive";
30 const std::string BUNDLE_INFO_SINGLETON = "singleton";
31 const std::string BUNDLE_INFO_IS_NATIVE_APP = "isNativeApp";
32 const std::string BUNDLE_INFO_IS_PREINSTALL_APP = "isPreInstallApp";
33 const std::string BUNDLE_INFO_IS_DIFFERENT_NAME = "isDifferentName";
34 const std::string BUNDLE_INFO_ABILITY_INFOS = "abilityInfos";
35 const std::string BUNDLE_INFO_HAP_MODULE_INFOS = "hapModuleInfos";
36 const std::string BUNDLE_INFO_EXTENSION_ABILITY_INFOS = "extensionAbilityInfo";
37 const std::string BUNDLE_INFO_JOINT_USERID = "jointUserId";
38 const std::string BUNDLE_INFO_VERSION_CODE = "versionCode";
39 const std::string BUNDLE_INFO_MIN_COMPATIBLE_VERSION_CODE = "minCompatibleVersionCode";
40 const std::string BUNDLE_INFO_VERSION_NAME = "versionName";
41 const std::string BUNDLE_INFO_MIN_SDK_VERSION = "minSdkVersion";
42 const std::string BUNDLE_INFO_MAX_SDK_VERSION = "maxSdkVersion";
43 const std::string BUNDLE_INFO_MAIN_ENTRY = "mainEntry";
44 const std::string BUNDLE_INFO_CPU_ABI = "cpuAbi";
45 const std::string BUNDLE_INFO_APPID = "appId";
46 const std::string BUNDLE_INFO_COMPATIBLE_VERSION = "compatibleVersion";
47 const std::string BUNDLE_INFO_TARGET_VERSION = "targetVersion";
48 const std::string BUNDLE_INFO_RELEASE_TYPE = "releaseType";
49 const std::string BUNDLE_INFO_UID = "uid";
50 const std::string BUNDLE_INFO_GID = "gid";
51 const std::string BUNDLE_INFO_SEINFO = "seInfo";
52 const std::string BUNDLE_INFO_INSTALL_TIME = "installTime";
53 const std::string BUNDLE_INFO_UPDATE_TIME = "updateTime";
54 const std::string BUNDLE_INFO_ENTRY_MODULE_NAME = "entryModuleName";
55 const std::string BUNDLE_INFO_ENTRY_INSTALLATION_FREE = "entryInstallationFree";
56 const std::string BUNDLE_INFO_REQ_PERMISSIONS = "reqPermissions";
57 const std::string BUNDLE_INFO_REQ_PERMISSION_STATES = "reqPermissionStates";
58 const std::string BUNDLE_INFO_REQ_PERMISSION_DETAILS = "reqPermissionDetails";
59 const std::string BUNDLE_INFO_DEF_PERMISSIONS = "defPermissions";
60 const std::string BUNDLE_INFO_HAP_MODULE_NAMES = "hapModuleNames";
61 const std::string BUNDLE_INFO_MODULE_NAMES = "moduleNames";
62 const std::string BUNDLE_INFO_MODULE_PUBLIC_DIRS = "modulePublicDirs";
63 const std::string BUNDLE_INFO_MODULE_DIRS = "moduleDirs";
64 const std::string BUNDLE_INFO_MODULE_RES_PATHS = "moduleResPaths";
65 const std::string REQUESTPERMISSION_NAME = "name";
66 const std::string REQUESTPERMISSION_REASON = "reason";
67 const std::string REQUESTPERMISSION_REASON_ID = "reasonId";
68 const std::string REQUESTPERMISSION_USEDSCENE = "usedScene";
69 const std::string REQUESTPERMISSION_ABILITIES = "abilities";
70 const std::string REQUESTPERMISSION_ABILITY = "ability";
71 const std::string REQUESTPERMISSION_WHEN = "when";
72 const std::string REQUESTPERMISSION_MODULE_NAME = "moduleName";
73 const std::string SIGNATUREINFO_APPID = "appId";
74 const std::string SIGNATUREINFO_FINGERPRINT = "fingerprint";
75 const std::string BUNDLE_INFO_APP_INDEX = "appIndex";
76 const std::string BUNDLE_INFO_SIGNATURE_INFO = "signatureInfo";
77 const std::string OVERLAY_TYPE = "overlayType";
78 const std::string OVERLAY_BUNDLE_INFO = "overlayBundleInfos";
79 const std::string APP_IDENTIFIER = "appIdentifier";
80 const std::string BUNDLE_INFO_OLD_APPIDS = "oldAppIds";
81 const size_t BUNDLE_CAPACITY = 20480; // 20K
82 }
83 
ReadFromParcel(Parcel & parcel)84 bool RequestPermissionUsedScene::ReadFromParcel(Parcel &parcel)
85 {
86     int32_t size;
87     READ_PARCEL_AND_RETURN_FALSE_IF_FAIL(Int32, parcel, size);
88     CONTAINER_SECURITY_VERIFY(parcel, size, &abilities);
89     for (int32_t i = 0; i < size; i++) {
90         abilities.emplace_back(Str16ToStr8(parcel.ReadString16()));
91     }
92     when = Str16ToStr8(parcel.ReadString16());
93     return true;
94 }
95 
Marshalling(Parcel & parcel) const96 bool RequestPermissionUsedScene::Marshalling(Parcel &parcel) const
97 {
98     WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(Int32, parcel, abilities.size());
99     for (auto &ability : abilities) {
100         WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(String16, parcel, Str8ToStr16(ability));
101     }
102     WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(String16, parcel, Str8ToStr16(when));
103     return true;
104 }
105 
Unmarshalling(Parcel & parcel)106 RequestPermissionUsedScene *RequestPermissionUsedScene::Unmarshalling(Parcel &parcel)
107 {
108     RequestPermissionUsedScene *info = new (std::nothrow) RequestPermissionUsedScene();
109     if (info && !info->ReadFromParcel(parcel)) {
110         APP_LOGW("read from parcel failed");
111         delete info;
112         info = nullptr;
113     }
114     return info;
115 }
116 
ReadFromParcel(Parcel & parcel)117 bool RequestPermission::ReadFromParcel(Parcel &parcel)
118 {
119     name = Str16ToStr8(parcel.ReadString16());
120     reason = Str16ToStr8(parcel.ReadString16());
121     reasonId = parcel.ReadInt32();
122     std::unique_ptr<RequestPermissionUsedScene> scene(parcel.ReadParcelable<RequestPermissionUsedScene>());
123     if (!scene) {
124         APP_LOGE("ReadParcelable<RequestPermissionUsedScene> failed");
125         return false;
126     }
127     usedScene = *scene;
128     moduleName = Str16ToStr8(parcel.ReadString16());
129     return true;
130 }
131 
Marshalling(Parcel & parcel) const132 bool RequestPermission::Marshalling(Parcel &parcel) const
133 {
134     WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(String16, parcel, Str8ToStr16(name));
135     WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(String16, parcel, Str8ToStr16(reason));
136     WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(Int32, parcel, reasonId);
137     WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(Parcelable, parcel, &usedScene);
138     WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(String16, parcel, Str8ToStr16(moduleName));
139     return true;
140 }
141 
Unmarshalling(Parcel & parcel)142 RequestPermission *RequestPermission::Unmarshalling(Parcel &parcel)
143 {
144     RequestPermission *info = new (std::nothrow) RequestPermission();
145     if (info && !info->ReadFromParcel(parcel)) {
146         APP_LOGW("read from parcel failed");
147         delete info;
148         info = nullptr;
149     }
150     return info;
151 }
152 
ReadFromParcel(Parcel & parcel)153 bool SignatureInfo::ReadFromParcel(Parcel &parcel)
154 {
155     appId = Str16ToStr8(parcel.ReadString16());
156     fingerprint = Str16ToStr8(parcel.ReadString16());
157     appIdentifier = Str16ToStr8(parcel.ReadString16());
158     return true;
159 }
160 
Marshalling(Parcel & parcel) const161 bool SignatureInfo::Marshalling(Parcel &parcel) const
162 {
163     WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(String16, parcel, Str8ToStr16(appId));
164     WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(String16, parcel, Str8ToStr16(fingerprint));
165     WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(String16, parcel, Str8ToStr16(appIdentifier));
166     return true;
167 }
168 
Unmarshalling(Parcel & parcel)169 SignatureInfo *SignatureInfo::Unmarshalling(Parcel &parcel)
170 {
171     SignatureInfo *info = new (std::nothrow) SignatureInfo();
172     if (info && !info->ReadFromParcel(parcel)) {
173         APP_LOGW("read from parcel failed");
174         delete info;
175         info = nullptr;
176     }
177     return info;
178 }
179 
ReadFromParcel(Parcel & parcel)180 bool BundleInfo::ReadFromParcel(Parcel &parcel)
181 {
182     std::unique_ptr<ApplicationInfo> appInfo(parcel.ReadParcelable<ApplicationInfo>());
183     if (!appInfo) {
184         APP_LOGE("ReadParcelable<ApplicationInfo> failed");
185         return false;
186     }
187     applicationInfo = *appInfo;
188 
189     int32_t abilityInfosSize;
190     READ_PARCEL_AND_RETURN_FALSE_IF_FAIL(Int32, parcel, abilityInfosSize);
191     CONTAINER_SECURITY_VERIFY(parcel, abilityInfosSize, &abilityInfos);
192     for (auto i = 0; i < abilityInfosSize; i++) {
193         std::unique_ptr<AbilityInfo> abilityInfo(parcel.ReadParcelable<AbilityInfo>());
194         if (!abilityInfo) {
195             APP_LOGE("ReadParcelable<AbilityInfo> failed");
196             return false;
197         }
198         abilityInfos.emplace_back(*abilityInfo);
199     }
200 
201     int32_t extensionInfosSize;
202     READ_PARCEL_AND_RETURN_FALSE_IF_FAIL(Int32, parcel, extensionInfosSize);
203     CONTAINER_SECURITY_VERIFY(parcel, extensionInfosSize, &extensionInfos);
204     for (auto i = 0; i < extensionInfosSize; i++) {
205         std::unique_ptr<ExtensionAbilityInfo> extensionAbilityInfo(parcel.ReadParcelable<ExtensionAbilityInfo>());
206         if (!extensionAbilityInfo) {
207             APP_LOGE("ReadParcelable<ExtensionAbilityInfo> failed");
208             return false;
209         }
210         extensionInfos.emplace_back(*extensionAbilityInfo);
211     }
212 
213     int32_t hapModuleInfosSize;
214     READ_PARCEL_AND_RETURN_FALSE_IF_FAIL(Int32, parcel, hapModuleInfosSize);
215     CONTAINER_SECURITY_VERIFY(parcel, hapModuleInfosSize, &hapModuleInfos);
216     for (auto i = 0; i < hapModuleInfosSize; i++) {
217         std::unique_ptr<HapModuleInfo> hapModuleInfo(parcel.ReadParcelable<HapModuleInfo>());
218         if (!hapModuleInfo) {
219             APP_LOGE("ReadParcelable<HapModuleInfo> failed");
220             return false;
221         }
222         hapModuleInfos.emplace_back(*hapModuleInfo);
223     }
224 
225     name = Str16ToStr8(parcel.ReadString16());
226     versionCode = parcel.ReadUint32();
227     versionName = Str16ToStr8(parcel.ReadString16());
228     minCompatibleVersionCode = parcel.ReadUint32();
229     compatibleVersion = parcel.ReadUint32();
230     targetVersion = parcel.ReadUint32();
231     isKeepAlive = parcel.ReadBool();
232     singleton = parcel.ReadBool();
233     isPreInstallApp = parcel.ReadBool();
234 
235     vendor = Str16ToStr8(parcel.ReadString16());
236     releaseType = Str16ToStr8(parcel.ReadString16());
237     isNativeApp = parcel.ReadBool();
238 
239     mainEntry = Str16ToStr8(parcel.ReadString16());
240     entryModuleName = Str16ToStr8(parcel.ReadString16());
241     entryInstallationFree = parcel.ReadBool();
242 
243     appId = Str16ToStr8(parcel.ReadString16());
244     uid = parcel.ReadInt32();
245     gid = parcel.ReadInt32();
246     installTime = parcel.ReadInt64();
247     updateTime = parcel.ReadInt64();
248 
249     int32_t hapModuleNamesSize;
250     READ_PARCEL_AND_RETURN_FALSE_IF_FAIL(Int32, parcel, hapModuleNamesSize);
251     CONTAINER_SECURITY_VERIFY(parcel, hapModuleNamesSize, &hapModuleNames);
252     for (auto i = 0; i < hapModuleNamesSize; i++) {
253         hapModuleNames.emplace_back(Str16ToStr8(parcel.ReadString16()));
254     }
255 
256     int32_t moduleNamesSize;
257     READ_PARCEL_AND_RETURN_FALSE_IF_FAIL(Int32, parcel, moduleNamesSize);
258     CONTAINER_SECURITY_VERIFY(parcel, moduleNamesSize, &moduleNames);
259     for (auto i = 0; i < moduleNamesSize; i++) {
260         moduleNames.emplace_back(Str16ToStr8(parcel.ReadString16()));
261     }
262 
263     int32_t modulePublicDirsSize;
264     READ_PARCEL_AND_RETURN_FALSE_IF_FAIL(Int32, parcel, modulePublicDirsSize);
265     CONTAINER_SECURITY_VERIFY(parcel, modulePublicDirsSize, &modulePublicDirs);
266     for (auto i = 0; i < modulePublicDirsSize; i++) {
267         modulePublicDirs.emplace_back(Str16ToStr8(parcel.ReadString16()));
268     }
269 
270     int32_t moduleDirsSize;
271     READ_PARCEL_AND_RETURN_FALSE_IF_FAIL(Int32, parcel, moduleDirsSize);
272     CONTAINER_SECURITY_VERIFY(parcel, moduleDirsSize, &moduleDirs);
273     for (auto i = 0; i < moduleDirsSize; i++) {
274         moduleDirs.emplace_back(Str16ToStr8(parcel.ReadString16()));
275     }
276 
277     int32_t moduleResPathsSize;
278     READ_PARCEL_AND_RETURN_FALSE_IF_FAIL(Int32, parcel, moduleResPathsSize);
279     CONTAINER_SECURITY_VERIFY(parcel, moduleResPathsSize, &moduleResPaths);
280     for (auto i = 0; i < moduleResPathsSize; i++) {
281         moduleResPaths.emplace_back(Str16ToStr8(parcel.ReadString16()));
282     }
283 
284     int32_t reqPermissionsSize;
285     READ_PARCEL_AND_RETURN_FALSE_IF_FAIL(Int32, parcel, reqPermissionsSize);
286     CONTAINER_SECURITY_VERIFY(parcel, reqPermissionsSize, &reqPermissions);
287     for (auto i = 0; i < reqPermissionsSize; i++) {
288         reqPermissions.emplace_back(Str16ToStr8(parcel.ReadString16()));
289     }
290 
291     int32_t defPermissionsSize;
292     READ_PARCEL_AND_RETURN_FALSE_IF_FAIL(Int32, parcel, defPermissionsSize);
293     CONTAINER_SECURITY_VERIFY(parcel, defPermissionsSize, &defPermissions);
294     for (auto i = 0; i < defPermissionsSize; i++) {
295         defPermissions.emplace_back(Str16ToStr8(parcel.ReadString16()));
296     }
297 
298     int32_t reqPermissionStatesSize;
299     READ_PARCEL_AND_RETURN_FALSE_IF_FAIL(Int32, parcel, reqPermissionStatesSize);
300     CONTAINER_SECURITY_VERIFY(parcel, reqPermissionStatesSize, &reqPermissionStates);
301     for (auto i = 0; i < reqPermissionStatesSize; i++) {
302         reqPermissionStates.emplace_back(parcel.ReadInt32());
303     }
304 
305     int32_t reqPermissionDetailsSize;
306     READ_PARCEL_AND_RETURN_FALSE_IF_FAIL(Int32, parcel, reqPermissionDetailsSize);
307     CONTAINER_SECURITY_VERIFY(parcel, reqPermissionDetailsSize, &reqPermissionDetails);
308     for (auto i = 0; i < reqPermissionDetailsSize; i++) {
309         std::unique_ptr<RequestPermission> requestPermission(parcel.ReadParcelable<RequestPermission>());
310         if (!requestPermission) {
311             APP_LOGE("ReadParcelable<RequestPermission> failed");
312             return false;
313         }
314         reqPermissionDetails.emplace_back(*requestPermission);
315     }
316 
317     cpuAbi = Str16ToStr8(parcel.ReadString16());
318     seInfo = Str16ToStr8(parcel.ReadString16());
319     label = Str16ToStr8(parcel.ReadString16());
320     description = Str16ToStr8(parcel.ReadString16());
321     jointUserId = Str16ToStr8(parcel.ReadString16());
322     minSdkVersion = parcel.ReadInt32();
323     maxSdkVersion = parcel.ReadInt32();
324     isDifferentName = parcel.ReadBool();
325     appIndex = parcel.ReadInt32();
326 
327     std::unique_ptr<SignatureInfo> sigInfo(parcel.ReadParcelable<SignatureInfo>());
328     if (!sigInfo) {
329         APP_LOGE("ReadParcelable<SignatureInfo> failed");
330         return false;
331     }
332     signatureInfo = *sigInfo;
333     overlayType = parcel.ReadInt32();
334 
335     int32_t overlayBundleInfoSize;
336     READ_PARCEL_AND_RETURN_FALSE_IF_FAIL(Int32, parcel, overlayBundleInfoSize);
337     CONTAINER_SECURITY_VERIFY(parcel, overlayBundleInfoSize, &overlayBundleInfos);
338     for (auto i = 0; i < overlayBundleInfoSize; i++) {
339         std::unique_ptr<OverlayBundleInfo> overlayBundleInfo(parcel.ReadParcelable<OverlayBundleInfo>());
340         if (!overlayBundleInfo) {
341             APP_LOGE("ReadParcelable<OverlayBundleInfo> failed");
342             return false;
343         }
344         overlayBundleInfos.emplace_back(*overlayBundleInfo);
345     }
346     int32_t oldAppIdsSize;
347     READ_PARCEL_AND_RETURN_FALSE_IF_FAIL(Int32, parcel, oldAppIdsSize);
348     CONTAINER_SECURITY_VERIFY(parcel, oldAppIdsSize, &oldAppIds);
349     for (auto i = 0; i < oldAppIdsSize; i++) {
350         oldAppIds.emplace_back(Str16ToStr8(parcel.ReadString16()));
351     }
352     return true;
353 }
354 
Marshalling(Parcel & parcel) const355 bool BundleInfo::Marshalling(Parcel &parcel) const
356 {
357     WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(Parcelable, parcel, &applicationInfo);
358 
359     WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(Int32, parcel, abilityInfos.size());
360     for (auto &abilityInfo : abilityInfos) {
361         WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(Parcelable, parcel, &abilityInfo);
362     }
363 
364     WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(Int32, parcel, extensionInfos.size());
365     for (auto &extensionInfo : extensionInfos) {
366         WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(Parcelable, parcel, &extensionInfo);
367     }
368 
369     WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(Int32, parcel, hapModuleInfos.size());
370     for (auto &hapModuleInfo : hapModuleInfos) {
371         WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(Parcelable, parcel, &hapModuleInfo);
372     }
373 
374     CHECK_PARCEL_CAPACITY(parcel, BUNDLE_CAPACITY);
375     WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(String16, parcel, Str8ToStr16(name));
376     WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(Uint32, parcel, versionCode);
377     WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(String16, parcel, Str8ToStr16(versionName));
378     WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(Uint32, parcel, minCompatibleVersionCode);
379     WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(Uint32, parcel, compatibleVersion);
380     WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(Uint32, parcel, targetVersion);
381 
382     WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(Bool, parcel, isKeepAlive);
383     WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(Bool, parcel, singleton);
384     WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(Bool, parcel, isPreInstallApp);
385 
386     WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(String16, parcel, Str8ToStr16(vendor));
387     WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(String16, parcel, Str8ToStr16(releaseType));
388     WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(Bool, parcel, isNativeApp);
389 
390     WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(String16, parcel, Str8ToStr16(mainEntry));
391     WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(String16, parcel, Str8ToStr16(entryModuleName));
392     WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(Bool, parcel, entryInstallationFree);
393 
394     WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(String16, parcel, Str8ToStr16(appId));
395 
396     WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(Int32, parcel, uid);
397     WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(Int32, parcel, gid);
398 
399     WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(Int64, parcel, installTime);
400     WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(Int64, parcel, updateTime);
401 
402     WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(Int32, parcel, hapModuleNames.size());
403     for (auto &hapModuleName : hapModuleNames) {
404         WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(String16, parcel, Str8ToStr16(hapModuleName));
405     }
406 
407     WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(Int32, parcel, moduleNames.size());
408     for (auto &moduleName : moduleNames) {
409         WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(String16, parcel, Str8ToStr16(moduleName));
410     }
411     CHECK_PARCEL_CAPACITY(parcel, BUNDLE_CAPACITY);
412     WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(Int32, parcel, modulePublicDirs.size());
413     for (auto &modulePublicDir : modulePublicDirs) {
414         WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(String16, parcel, Str8ToStr16(modulePublicDir));
415     }
416 
417     WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(Int32, parcel, moduleDirs.size());
418     for (auto &moduleDir : moduleDirs) {
419         WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(String16, parcel, Str8ToStr16(moduleDir));
420     }
421 
422     WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(Int32, parcel, moduleResPaths.size());
423     for (auto &moduleResPath : moduleResPaths) {
424         WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(String16, parcel, Str8ToStr16(moduleResPath));
425     }
426 
427     WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(Int32, parcel, reqPermissions.size());
428     for (auto &reqPermission : reqPermissions) {
429         WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(String16, parcel, Str8ToStr16(reqPermission));
430     }
431 
432     WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(Int32, parcel, defPermissions.size());
433     for (auto &defPermission : defPermissions) {
434         WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(String16, parcel, Str8ToStr16(defPermission));
435     }
436 
437     WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(Int32, parcel, reqPermissionStates.size());
438     for (auto &reqPermissionState : reqPermissionStates) {
439         WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(Int32, parcel, reqPermissionState);
440     }
441 
442     WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(Int32, parcel, reqPermissionDetails.size());
443     for (auto &reqPermissionDetail : reqPermissionDetails) {
444         WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(Parcelable, parcel, &reqPermissionDetail);
445     }
446 
447     WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(String16, parcel, Str8ToStr16(cpuAbi));
448     WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(String16, parcel, Str8ToStr16(seInfo));
449     WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(String16, parcel, Str8ToStr16(label));
450     WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(String16, parcel, Str8ToStr16(description));
451     WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(String16, parcel, Str8ToStr16(jointUserId));
452     WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(Int32, parcel, minSdkVersion);
453     WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(Int32, parcel, maxSdkVersion);
454     WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(Bool, parcel, isDifferentName);
455     WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(Int32, parcel, appIndex);
456     WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(Parcelable, parcel, &signatureInfo);
457     WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(Int32, parcel, overlayType);
458     WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(Int32, parcel, overlayBundleInfos.size());
459     for (auto &overlayBundleInfo : overlayBundleInfos) {
460         WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(Parcelable, parcel, &overlayBundleInfo);
461     }
462     WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(Int32, parcel, oldAppIds.size());
463     for (auto &oldAppId : oldAppIds) {
464         WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(String16, parcel, Str8ToStr16(oldAppId));
465     }
466     return true;
467 }
468 
Unmarshalling(Parcel & parcel)469 BundleInfo *BundleInfo::Unmarshalling(Parcel &parcel)
470 {
471     BundleInfo *info = new (std::nothrow) BundleInfo();
472     if (info && !info->ReadFromParcel(parcel)) {
473         APP_LOGW("read from parcel failed");
474         delete info;
475         info = nullptr;
476     }
477     return info;
478 }
479 
to_json(nlohmann::json & jsonObject,const RequestPermissionUsedScene & usedScene)480 void to_json(nlohmann::json &jsonObject, const RequestPermissionUsedScene &usedScene)
481 {
482     jsonObject = nlohmann::json {
483         {REQUESTPERMISSION_ABILITIES, usedScene.abilities},
484         {REQUESTPERMISSION_WHEN, usedScene.when}
485     };
486 }
487 
to_json(nlohmann::json & jsonObject,const RequestPermission & requestPermission)488 void to_json(nlohmann::json &jsonObject, const RequestPermission &requestPermission)
489 {
490     jsonObject = nlohmann::json {
491         {REQUESTPERMISSION_NAME, requestPermission.name},
492         {REQUESTPERMISSION_REASON, requestPermission.reason},
493         {REQUESTPERMISSION_REASON_ID, requestPermission.reasonId},
494         {REQUESTPERMISSION_USEDSCENE, requestPermission.usedScene},
495         {REQUESTPERMISSION_MODULE_NAME, requestPermission.moduleName}
496     };
497 }
498 
to_json(nlohmann::json & jsonObject,const SignatureInfo & signatureInfo)499 void to_json(nlohmann::json &jsonObject, const SignatureInfo &signatureInfo)
500 {
501     jsonObject = nlohmann::json {
502         {SIGNATUREINFO_APPID, signatureInfo.appId},
503         {SIGNATUREINFO_FINGERPRINT, signatureInfo.fingerprint},
504         {APP_IDENTIFIER, signatureInfo.appIdentifier}
505     };
506 }
507 
from_json(const nlohmann::json & jsonObject,RequestPermissionUsedScene & usedScene)508 void from_json(const nlohmann::json &jsonObject, RequestPermissionUsedScene &usedScene)
509 {
510     const auto &jsonObjectEnd = jsonObject.end();
511     int32_t parseResult = ERR_OK;
512     GetValueIfFindKey<std::vector<std::string>>(jsonObject,
513         jsonObjectEnd,
514         REQUESTPERMISSION_ABILITIES,
515         usedScene.abilities,
516         JsonType::ARRAY,
517         false,
518         parseResult,
519         ArrayType::STRING);
520     GetValueIfFindKey<std::vector<std::string>>(jsonObject,
521         jsonObjectEnd,
522         REQUESTPERMISSION_ABILITY,
523         usedScene.abilities,
524         JsonType::ARRAY,
525         false,
526         parseResult,
527         ArrayType::STRING);
528     GetValueIfFindKey<std::string>(jsonObject,
529         jsonObjectEnd,
530         REQUESTPERMISSION_WHEN,
531         usedScene.when,
532         JsonType::STRING,
533         false,
534         parseResult,
535         ArrayType::NOT_ARRAY);
536     if (parseResult != ERR_OK) {
537         APP_LOGE("read RequestPermissionUsedScene from database error, error code : %{public}d", parseResult);
538     }
539 }
540 
from_json(const nlohmann::json & jsonObject,RequestPermission & requestPermission)541 void from_json(const nlohmann::json &jsonObject, RequestPermission &requestPermission)
542 {
543     const auto &jsonObjectEnd = jsonObject.end();
544     int32_t parseResult = ERR_OK;
545     GetValueIfFindKey<std::string>(jsonObject,
546         jsonObjectEnd,
547         REQUESTPERMISSION_NAME,
548         requestPermission.name,
549         JsonType::STRING,
550         false,
551         parseResult,
552         ArrayType::NOT_ARRAY);
553     GetValueIfFindKey<std::string>(jsonObject,
554         jsonObjectEnd,
555         REQUESTPERMISSION_REASON,
556         requestPermission.reason,
557         JsonType::STRING,
558         false,
559         parseResult,
560         ArrayType::NOT_ARRAY);
561     GetValueIfFindKey<int32_t>(jsonObject,
562         jsonObjectEnd,
563         REQUESTPERMISSION_REASON_ID,
564         requestPermission.reasonId,
565         JsonType::NUMBER,
566         false,
567         parseResult,
568         ArrayType::NOT_ARRAY);
569     GetValueIfFindKey<RequestPermissionUsedScene>(jsonObject,
570         jsonObjectEnd,
571         REQUESTPERMISSION_USEDSCENE,
572         requestPermission.usedScene,
573         JsonType::OBJECT,
574         false,
575         parseResult,
576         ArrayType::NOT_ARRAY);
577     GetValueIfFindKey<std::string>(jsonObject,
578         jsonObjectEnd,
579         REQUESTPERMISSION_MODULE_NAME,
580         requestPermission.moduleName,
581         JsonType::STRING,
582         false,
583         parseResult,
584         ArrayType::NOT_ARRAY);
585     if (parseResult != ERR_OK) {
586         APP_LOGE("read RequestPermission from database error, error code : %{public}d", parseResult);
587     }
588 }
589 
from_json(const nlohmann::json & jsonObject,SignatureInfo & signatureInfo)590 void from_json(const nlohmann::json &jsonObject, SignatureInfo &signatureInfo)
591 {
592     const auto &jsonObjectEnd = jsonObject.end();
593     int32_t parseResult = ERR_OK;
594     GetValueIfFindKey<std::string>(jsonObject,
595         jsonObjectEnd,
596         SIGNATUREINFO_APPID,
597         signatureInfo.appId,
598         JsonType::STRING,
599         false,
600         parseResult,
601         ArrayType::NOT_ARRAY);
602     GetValueIfFindKey<std::string>(jsonObject,
603         jsonObjectEnd,
604         SIGNATUREINFO_FINGERPRINT,
605         signatureInfo.fingerprint,
606         JsonType::STRING,
607         false,
608         parseResult,
609         ArrayType::NOT_ARRAY);
610     GetValueIfFindKey<std::string>(jsonObject,
611         jsonObjectEnd,
612         APP_IDENTIFIER,
613         signatureInfo.appIdentifier,
614         JsonType::STRING,
615         false,
616         parseResult,
617         ArrayType::NOT_ARRAY);
618     if (parseResult != ERR_OK) {
619         APP_LOGE("read SignatureInfo from database error, error code : %{public}d", parseResult);
620     }
621 }
622 
to_json(nlohmann::json & jsonObject,const BundleInfo & bundleInfo)623 void to_json(nlohmann::json &jsonObject, const BundleInfo &bundleInfo)
624 {
625     jsonObject = nlohmann::json {
626         {BUNDLE_INFO_NAME, bundleInfo.name},
627         {BUNDLE_INFO_LABEL, bundleInfo.label},
628         {BUNDLE_INFO_DESCRIPTION, bundleInfo.description},
629         {BUNDLE_INFO_VENDOR, bundleInfo.vendor},
630         {BUNDLE_INFO_IS_KEEP_ALIVE, bundleInfo.isKeepAlive},
631         {BUNDLE_INFO_IS_NATIVE_APP, bundleInfo.isNativeApp},
632         {BUNDLE_INFO_IS_PREINSTALL_APP, bundleInfo.isPreInstallApp},
633         {BUNDLE_INFO_IS_DIFFERENT_NAME, bundleInfo.isDifferentName},
634         {BUNDLE_INFO_ABILITY_INFOS, bundleInfo.abilityInfos},
635         {BUNDLE_INFO_HAP_MODULE_INFOS, bundleInfo.hapModuleInfos},
636         {BUNDLE_INFO_EXTENSION_ABILITY_INFOS, bundleInfo.extensionInfos},
637         {BUNDLE_INFO_JOINT_USERID, bundleInfo.jointUserId},
638         {BUNDLE_INFO_VERSION_CODE, bundleInfo.versionCode},
639         {BUNDLE_INFO_MIN_COMPATIBLE_VERSION_CODE, bundleInfo.minCompatibleVersionCode},
640         {BUNDLE_INFO_VERSION_NAME, bundleInfo.versionName},
641         {BUNDLE_INFO_MIN_SDK_VERSION, bundleInfo.minSdkVersion},
642         {BUNDLE_INFO_MAX_SDK_VERSION, bundleInfo.maxSdkVersion},
643         {BUNDLE_INFO_MAIN_ENTRY, bundleInfo.mainEntry},
644         {BUNDLE_INFO_CPU_ABI, bundleInfo.cpuAbi},
645         {BUNDLE_INFO_APPID, bundleInfo.appId},
646         {BUNDLE_INFO_COMPATIBLE_VERSION, bundleInfo.compatibleVersion},
647         {BUNDLE_INFO_TARGET_VERSION, bundleInfo.targetVersion},
648         {BUNDLE_INFO_RELEASE_TYPE, bundleInfo.releaseType},
649         {BUNDLE_INFO_UID, bundleInfo.uid},
650         {BUNDLE_INFO_GID, bundleInfo.gid},
651         {BUNDLE_INFO_SEINFO, bundleInfo.seInfo},
652         {BUNDLE_INFO_INSTALL_TIME, bundleInfo.installTime},
653         {BUNDLE_INFO_UPDATE_TIME, bundleInfo.updateTime},
654         {BUNDLE_INFO_ENTRY_MODULE_NAME, bundleInfo.entryModuleName},
655         {BUNDLE_INFO_ENTRY_INSTALLATION_FREE, bundleInfo.entryInstallationFree},
656         {BUNDLE_INFO_REQ_PERMISSIONS, bundleInfo.reqPermissions},
657         {BUNDLE_INFO_REQ_PERMISSION_STATES, bundleInfo.reqPermissionStates},
658         {BUNDLE_INFO_REQ_PERMISSION_DETAILS, bundleInfo.reqPermissionDetails},
659         {BUNDLE_INFO_DEF_PERMISSIONS, bundleInfo.defPermissions},
660         {BUNDLE_INFO_HAP_MODULE_NAMES, bundleInfo.hapModuleNames},
661         {BUNDLE_INFO_MODULE_NAMES, bundleInfo.moduleNames},
662         {BUNDLE_INFO_MODULE_PUBLIC_DIRS, bundleInfo.modulePublicDirs},
663         {BUNDLE_INFO_MODULE_DIRS, bundleInfo.moduleDirs},
664         {BUNDLE_INFO_MODULE_RES_PATHS, bundleInfo.moduleResPaths},
665         {BUNDLE_INFO_SINGLETON, bundleInfo.singleton},
666         {BUNDLE_INFO_APP_INDEX, bundleInfo.appIndex},
667         {BUNDLE_INFO_SIGNATURE_INFO, bundleInfo.signatureInfo},
668         {OVERLAY_TYPE, bundleInfo.overlayType},
669         {OVERLAY_BUNDLE_INFO, bundleInfo.overlayBundleInfos},
670         {BUNDLE_INFO_OLD_APPIDS, bundleInfo.oldAppIds}
671     };
672 }
673 
from_json(const nlohmann::json & jsonObject,BundleInfo & bundleInfo)674 void from_json(const nlohmann::json &jsonObject, BundleInfo &bundleInfo)
675 {
676     const auto &jsonObjectEnd = jsonObject.end();
677     int32_t parseResult = ERR_OK;
678     GetValueIfFindKey<std::string>(jsonObject,
679         jsonObjectEnd,
680         BUNDLE_INFO_NAME,
681         bundleInfo.name,
682         JsonType::STRING,
683         false,
684         parseResult,
685         ArrayType::NOT_ARRAY);
686     GetValueIfFindKey<std::string>(jsonObject,
687         jsonObjectEnd,
688         BUNDLE_INFO_LABEL,
689         bundleInfo.label,
690         JsonType::STRING,
691         false,
692         parseResult,
693         ArrayType::NOT_ARRAY);
694     GetValueIfFindKey<std::string>(jsonObject,
695         jsonObjectEnd,
696         BUNDLE_INFO_DESCRIPTION,
697         bundleInfo.description,
698         JsonType::STRING,
699         false,
700         parseResult,
701         ArrayType::NOT_ARRAY);
702     GetValueIfFindKey<std::string>(jsonObject,
703         jsonObjectEnd,
704         BUNDLE_INFO_VENDOR,
705         bundleInfo.vendor,
706         JsonType::STRING,
707         false,
708         parseResult,
709         ArrayType::NOT_ARRAY);
710     GetValueIfFindKey<bool>(jsonObject,
711         jsonObjectEnd,
712         BUNDLE_INFO_IS_KEEP_ALIVE,
713         bundleInfo.isKeepAlive,
714         JsonType::BOOLEAN,
715         false,
716         parseResult,
717         ArrayType::NOT_ARRAY);
718     GetValueIfFindKey<bool>(jsonObject,
719         jsonObjectEnd,
720         BUNDLE_INFO_IS_NATIVE_APP,
721         bundleInfo.isNativeApp,
722         JsonType::BOOLEAN,
723         false,
724         parseResult,
725         ArrayType::NOT_ARRAY);
726     GetValueIfFindKey<bool>(jsonObject,
727         jsonObjectEnd,
728         BUNDLE_INFO_IS_PREINSTALL_APP,
729         bundleInfo.isPreInstallApp,
730         JsonType::BOOLEAN,
731         false,
732         parseResult,
733         ArrayType::NOT_ARRAY);
734     GetValueIfFindKey<bool>(jsonObject,
735         jsonObjectEnd,
736         BUNDLE_INFO_IS_DIFFERENT_NAME,
737         bundleInfo.isDifferentName,
738         JsonType::BOOLEAN,
739         false,
740         parseResult,
741         ArrayType::NOT_ARRAY);
742     GetValueIfFindKey<std::vector<AbilityInfo>>(jsonObject,
743         jsonObjectEnd,
744         BUNDLE_INFO_ABILITY_INFOS,
745         bundleInfo.abilityInfos,
746         JsonType::ARRAY,
747         false,
748         parseResult,
749         ArrayType::OBJECT);
750     GetValueIfFindKey<std::vector<HapModuleInfo>>(jsonObject,
751         jsonObjectEnd,
752         BUNDLE_INFO_HAP_MODULE_INFOS,
753         bundleInfo.hapModuleInfos,
754         JsonType::ARRAY,
755         false,
756         parseResult,
757         ArrayType::OBJECT);
758     GetValueIfFindKey<uint32_t>(jsonObject,
759         jsonObjectEnd,
760         BUNDLE_INFO_VERSION_CODE,
761         bundleInfo.versionCode,
762         JsonType::NUMBER,
763         false,
764         parseResult,
765         ArrayType::NOT_ARRAY);
766     GetValueIfFindKey<uint32_t>(jsonObject,
767         jsonObjectEnd,
768         BUNDLE_INFO_MIN_COMPATIBLE_VERSION_CODE,
769         bundleInfo.minCompatibleVersionCode,
770         JsonType::NUMBER,
771         false,
772         parseResult,
773         ArrayType::NOT_ARRAY);
774     GetValueIfFindKey<std::string>(jsonObject,
775         jsonObjectEnd,
776         BUNDLE_INFO_VERSION_NAME,
777         bundleInfo.versionName,
778         JsonType::STRING,
779         false,
780         parseResult,
781         ArrayType::NOT_ARRAY);
782     GetValueIfFindKey<std::string>(jsonObject,
783         jsonObjectEnd,
784         BUNDLE_INFO_JOINT_USERID,
785         bundleInfo.jointUserId,
786         JsonType::STRING,
787         false,
788         parseResult,
789         ArrayType::NOT_ARRAY);
790     GetValueIfFindKey<int32_t>(jsonObject,
791         jsonObjectEnd,
792         BUNDLE_INFO_MIN_SDK_VERSION,
793         bundleInfo.minSdkVersion,
794         JsonType::NUMBER,
795         false,
796         parseResult,
797         ArrayType::NOT_ARRAY);
798     GetValueIfFindKey<int32_t>(jsonObject,
799         jsonObjectEnd,
800         BUNDLE_INFO_MAX_SDK_VERSION,
801         bundleInfo.maxSdkVersion,
802         JsonType::NUMBER,
803         false,
804         parseResult,
805         ArrayType::NOT_ARRAY);
806     GetValueIfFindKey<std::string>(jsonObject,
807         jsonObjectEnd,
808         BUNDLE_INFO_MAIN_ENTRY,
809         bundleInfo.mainEntry,
810         JsonType::STRING,
811         false,
812         parseResult,
813         ArrayType::NOT_ARRAY);
814     GetValueIfFindKey<std::string>(jsonObject,
815         jsonObjectEnd,
816         BUNDLE_INFO_CPU_ABI,
817         bundleInfo.cpuAbi,
818         JsonType::STRING,
819         false,
820         parseResult,
821         ArrayType::NOT_ARRAY);
822     GetValueIfFindKey<std::string>(jsonObject,
823         jsonObjectEnd,
824         BUNDLE_INFO_APPID,
825         bundleInfo.appId,
826         JsonType::STRING,
827         false,
828         parseResult,
829         ArrayType::NOT_ARRAY);
830     GetValueIfFindKey<int>(jsonObject,
831         jsonObjectEnd,
832         BUNDLE_INFO_COMPATIBLE_VERSION,
833         bundleInfo.compatibleVersion,
834         JsonType::NUMBER,
835         false,
836         parseResult,
837         ArrayType::NOT_ARRAY);
838     GetValueIfFindKey<uint32_t>(jsonObject,
839         jsonObjectEnd,
840         BUNDLE_INFO_TARGET_VERSION,
841         bundleInfo.targetVersion,
842         JsonType::NUMBER,
843         false,
844         parseResult,
845         ArrayType::NOT_ARRAY);
846     GetValueIfFindKey<std::string>(jsonObject,
847         jsonObjectEnd,
848         BUNDLE_INFO_RELEASE_TYPE,
849         bundleInfo.releaseType,
850         JsonType::STRING,
851         false,
852         parseResult,
853         ArrayType::NOT_ARRAY);
854     GetValueIfFindKey<int>(jsonObject,
855         jsonObjectEnd,
856         BUNDLE_INFO_UID,
857         bundleInfo.uid,
858         JsonType::NUMBER,
859         false,
860         parseResult,
861         ArrayType::NOT_ARRAY);
862     GetValueIfFindKey<int>(jsonObject,
863         jsonObjectEnd,
864         BUNDLE_INFO_GID,
865         bundleInfo.gid,
866         JsonType::NUMBER,
867         false,
868         parseResult,
869         ArrayType::NOT_ARRAY);
870     GetValueIfFindKey<std::string>(jsonObject,
871         jsonObjectEnd,
872         BUNDLE_INFO_SEINFO,
873         bundleInfo.seInfo,
874         JsonType::STRING,
875         false,
876         parseResult,
877         ArrayType::NOT_ARRAY);
878     GetValueIfFindKey<int64_t>(jsonObject,
879         jsonObjectEnd,
880         BUNDLE_INFO_INSTALL_TIME,
881         bundleInfo.installTime,
882         JsonType::NUMBER,
883         false,
884         parseResult,
885         ArrayType::NOT_ARRAY);
886     GetValueIfFindKey<int64_t>(jsonObject,
887         jsonObjectEnd,
888         BUNDLE_INFO_UPDATE_TIME,
889         bundleInfo.updateTime,
890         JsonType::NUMBER,
891         false,
892         parseResult,
893         ArrayType::NOT_ARRAY);
894     GetValueIfFindKey<std::string>(jsonObject,
895         jsonObjectEnd,
896         BUNDLE_INFO_ENTRY_MODULE_NAME,
897         bundleInfo.entryModuleName,
898         JsonType::STRING,
899         false,
900         parseResult,
901         ArrayType::NOT_ARRAY);
902     GetValueIfFindKey<bool>(jsonObject,
903         jsonObjectEnd,
904         BUNDLE_INFO_ENTRY_INSTALLATION_FREE,
905         bundleInfo.entryInstallationFree,
906         JsonType::BOOLEAN,
907         false,
908         parseResult,
909         ArrayType::NOT_ARRAY);
910     GetValueIfFindKey<std::vector<std::string>>(jsonObject,
911         jsonObjectEnd,
912         BUNDLE_INFO_REQ_PERMISSIONS,
913         bundleInfo.reqPermissions,
914         JsonType::ARRAY,
915         false,
916         parseResult,
917         ArrayType::STRING);
918     GetValueIfFindKey<std::vector<int32_t>>(jsonObject,
919         jsonObjectEnd,
920         BUNDLE_INFO_REQ_PERMISSION_STATES,
921         bundleInfo.reqPermissionStates,
922         JsonType::ARRAY,
923         false,
924         parseResult,
925         ArrayType::NUMBER);
926     GetValueIfFindKey<std::vector<RequestPermission>>(jsonObject,
927         jsonObjectEnd,
928         BUNDLE_INFO_REQ_PERMISSION_DETAILS,
929         bundleInfo.reqPermissionDetails,
930         JsonType::ARRAY,
931         false,
932         parseResult,
933         ArrayType::OBJECT);
934     GetValueIfFindKey<std::vector<std::string>>(jsonObject,
935         jsonObjectEnd,
936         BUNDLE_INFO_DEF_PERMISSIONS,
937         bundleInfo.defPermissions,
938         JsonType::ARRAY,
939         false,
940         parseResult,
941         ArrayType::STRING);
942     GetValueIfFindKey<std::vector<std::string>>(jsonObject,
943         jsonObjectEnd,
944         BUNDLE_INFO_HAP_MODULE_NAMES,
945         bundleInfo.hapModuleNames,
946         JsonType::ARRAY,
947         false,
948         parseResult,
949         ArrayType::STRING);
950     GetValueIfFindKey<std::vector<std::string>>(jsonObject,
951         jsonObjectEnd,
952         BUNDLE_INFO_MODULE_NAMES,
953         bundleInfo.moduleNames,
954         JsonType::ARRAY,
955         false,
956         parseResult,
957         ArrayType::STRING);
958     GetValueIfFindKey<std::vector<std::string>>(jsonObject,
959         jsonObjectEnd,
960         BUNDLE_INFO_MODULE_PUBLIC_DIRS,
961         bundleInfo.modulePublicDirs,
962         JsonType::ARRAY,
963         false,
964         parseResult,
965         ArrayType::STRING);
966     GetValueIfFindKey<std::vector<std::string>>(jsonObject,
967         jsonObjectEnd,
968         BUNDLE_INFO_MODULE_DIRS,
969         bundleInfo.moduleDirs,
970         JsonType::ARRAY,
971         false,
972         parseResult,
973         ArrayType::STRING);
974     GetValueIfFindKey<std::vector<std::string>>(jsonObject,
975         jsonObjectEnd,
976         BUNDLE_INFO_MODULE_RES_PATHS,
977         bundleInfo.moduleResPaths,
978         JsonType::ARRAY,
979         false,
980         parseResult,
981         ArrayType::STRING);
982     GetValueIfFindKey<bool>(jsonObject,
983         jsonObjectEnd,
984         BUNDLE_INFO_SINGLETON,
985         bundleInfo.singleton,
986         JsonType::BOOLEAN,
987         false,
988         parseResult,
989         ArrayType::NOT_ARRAY);
990     GetValueIfFindKey<std::vector<ExtensionAbilityInfo>>(jsonObject,
991         jsonObjectEnd,
992         BUNDLE_INFO_EXTENSION_ABILITY_INFOS,
993         bundleInfo.extensionInfos,
994         JsonType::ARRAY,
995         false,
996         parseResult,
997         ArrayType::OBJECT);
998     GetValueIfFindKey<int32_t>(jsonObject,
999         jsonObjectEnd,
1000         BUNDLE_INFO_APP_INDEX,
1001         bundleInfo.appIndex,
1002         JsonType::NUMBER,
1003         false,
1004         parseResult,
1005         ArrayType::NOT_ARRAY);
1006     GetValueIfFindKey<SignatureInfo>(jsonObject,
1007         jsonObjectEnd,
1008         BUNDLE_INFO_SIGNATURE_INFO,
1009         bundleInfo.signatureInfo,
1010         JsonType::OBJECT,
1011         false,
1012         parseResult,
1013         ArrayType::NOT_ARRAY);
1014     GetValueIfFindKey<int32_t>(jsonObject,
1015         jsonObjectEnd,
1016         OVERLAY_TYPE,
1017         bundleInfo.overlayType,
1018         JsonType::NUMBER,
1019         false,
1020         parseResult,
1021         ArrayType::NOT_ARRAY);
1022     GetValueIfFindKey<std::vector<OverlayBundleInfo>>(jsonObject,
1023         jsonObjectEnd,
1024         OVERLAY_BUNDLE_INFO,
1025         bundleInfo.overlayBundleInfos,
1026         JsonType::ARRAY,
1027         false,
1028         parseResult,
1029         ArrayType::OBJECT);
1030     GetValueIfFindKey<std::vector<std::string>>(jsonObject,
1031         jsonObjectEnd,
1032         BUNDLE_INFO_OLD_APPIDS,
1033         bundleInfo.oldAppIds,
1034         JsonType::ARRAY,
1035         false,
1036         parseResult,
1037         ArrayType::STRING);
1038     if (parseResult != ERR_OK) {
1039         APP_LOGE("BundleInfo from_json error, error code : %{public}d", parseResult);
1040     }
1041 }
1042 }  // namespace AppExecFwk
1043 }  // namespace OHOS
1044