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