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_SINGLE_USER = "singleUser";
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_APPLICATION_INFO = "applicationInfo";
35 const std::string BUNDLE_INFO_ABILITY_INFOS = "abilityInfos";
36 const std::string BUNDLE_INFO_HAP_MODULE_INFOS = "hapModuleInfos";
37 const std::string BUNDLE_INFO_EXTENSION_ABILITY_INFOS = "extensionAbilityInfo";
38 const std::string BUNDLE_INFO_JOINT_USERID = "jointUserId";
39 const std::string BUNDLE_INFO_VERSION_CODE = "versionCode";
40 const std::string BUNDLE_INFO_MIN_COMPATIBLE_VERSION_CODE = "minCompatibleVersionCode";
41 const std::string BUNDLE_INFO_VERSION_NAME = "versionName";
42 const std::string BUNDLE_INFO_MIN_SDK_VERSION = "minSdkVersion";
43 const std::string BUNDLE_INFO_MAX_SDK_VERSION = "maxSdkVersion";
44 const std::string BUNDLE_INFO_MAIN_ENTRY = "mainEntry";
45 const std::string BUNDLE_INFO_CPU_ABI = "cpuAbi";
46 const std::string BUNDLE_INFO_APPID = "appId";
47 const std::string BUNDLE_INFO_COMPATIBLE_VERSION = "compatibleVersion";
48 const std::string BUNDLE_INFO_TARGET_VERSION = "targetVersion";
49 const std::string BUNDLE_INFO_RELEASE_TYPE = "releaseType";
50 const std::string BUNDLE_INFO_UID = "uid";
51 const std::string BUNDLE_INFO_GID = "gid";
52 const std::string BUNDLE_INFO_SEINFO = "seInfo";
53 const std::string BUNDLE_INFO_INSTALL_TIME = "installTime";
54 const std::string BUNDLE_INFO_UPDATE_TIME = "updateTime";
55 const std::string BUNDLE_INFO_ENTRY_MODULE_NAME = "entryModuleName";
56 const std::string BUNDLE_INFO_ENTRY_INSTALLATION_FREE = "entryInstallationFree";
57 const std::string BUNDLE_INFO_REQ_PERMISSIONS = "reqPermissions";
58 const std::string BUNDLE_INFO_REQ_PERMISSION_STATES = "reqPermissionStates";
59 const std::string BUNDLE_INFO_REQ_PERMISSION_DETAILS = "reqPermissionDetails";
60 const std::string BUNDLE_INFO_DEF_PERMISSIONS = "defPermissions";
61 const std::string BUNDLE_INFO_HAP_MODULE_NAMES = "hapModuleNames";
62 const std::string BUNDLE_INFO_MODULE_NAMES = "moduleNames";
63 const std::string BUNDLE_INFO_MODULE_PUBLIC_DIRS = "modulePublicDirs";
64 const std::string BUNDLE_INFO_MODULE_DIRS = "moduleDirs";
65 const std::string BUNDLE_INFO_MODULE_RES_PATHS = "moduleResPaths";
66 const std::string REQUESTPERMISSION_NAME = "name";
67 const std::string REQUESTPERMISSION_REASON = "reason";
68 const std::string REQUESTPERMISSION_REASON_ID = "reasonId";
69 const std::string REQUESTPERMISSION_USEDSCENE = "usedScene";
70 const std::string REQUESTPERMISSION_ABILITIES = "abilities";
71 const std::string REQUESTPERMISSION_ABILITY = "ability";
72 const std::string REQUESTPERMISSION_WHEN = "when";
73 }
74
ReadFromParcel(Parcel & parcel)75 bool RequestPermissionUsedScene::ReadFromParcel(Parcel &parcel)
76 {
77 int32_t size;
78 READ_PARCEL_AND_RETURN_FALSE_IF_FAIL(Int32, parcel, size);
79 for (int32_t i = 0; i < size; i++) {
80 abilities.emplace_back(Str16ToStr8(parcel.ReadString16()));
81 }
82 when = Str16ToStr8(parcel.ReadString16());
83 return true;
84 }
85
Marshalling(Parcel & parcel) const86 bool RequestPermissionUsedScene::Marshalling(Parcel &parcel) const
87 {
88 WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(Int32, parcel, abilities.size());
89 for (auto &ability : abilities) {
90 WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(String16, parcel, Str8ToStr16(ability));
91 }
92 WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(String16, parcel, Str8ToStr16(when));
93 return true;
94 }
95
Unmarshalling(Parcel & parcel)96 RequestPermissionUsedScene *RequestPermissionUsedScene::Unmarshalling(Parcel &parcel)
97 {
98 RequestPermissionUsedScene *info = new (std::nothrow) RequestPermissionUsedScene();
99 if (info && !info->ReadFromParcel(parcel)) {
100 APP_LOGW("read from parcel failed");
101 delete info;
102 info = nullptr;
103 }
104 return info;
105 }
106
ReadFromParcel(Parcel & parcel)107 bool RequestPermission::ReadFromParcel(Parcel &parcel)
108 {
109 name = Str16ToStr8(parcel.ReadString16());
110 reason = Str16ToStr8(parcel.ReadString16());
111 reasonId = parcel.ReadInt32();
112 std::unique_ptr<RequestPermissionUsedScene> scene(parcel.ReadParcelable<RequestPermissionUsedScene>());
113 if (!scene) {
114 APP_LOGE("ReadParcelable<RequestPermissionUsedScene> failed");
115 return false;
116 }
117 usedScene = *scene;
118 return true;
119 }
120
Marshalling(Parcel & parcel) const121 bool RequestPermission::Marshalling(Parcel &parcel) const
122 {
123 WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(String16, parcel, Str8ToStr16(name));
124 WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(String16, parcel, Str8ToStr16(reason));
125 WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(Int32, parcel, reasonId);
126 WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(Parcelable, parcel, &usedScene);
127 return true;
128 }
129
Unmarshalling(Parcel & parcel)130 RequestPermission *RequestPermission::Unmarshalling(Parcel &parcel)
131 {
132 RequestPermission *info = new (std::nothrow) RequestPermission();
133 if (info && !info->ReadFromParcel(parcel)) {
134 APP_LOGW("read from parcel failed");
135 delete info;
136 info = nullptr;
137 }
138 return info;
139 }
140
ReadFromParcel(Parcel & parcel)141 bool BundleInfo::ReadFromParcel(Parcel &parcel)
142 {
143 MessageParcel *messageParcel = reinterpret_cast<MessageParcel *>(&parcel);
144 if (!messageParcel) {
145 APP_LOGE("Type conversion failed");
146 return false;
147 }
148 uint32_t length = messageParcel->ReadUint32();
149 if (length == 0) {
150 APP_LOGE("Invalid data length");
151 return false;
152 }
153 const char *data = reinterpret_cast<const char *>(messageParcel->ReadRawData(length));
154 if (!data) {
155 APP_LOGE("Fail to read raw data, length = %{public}d", length);
156 return false;
157 }
158 nlohmann::json jsonObject = nlohmann::json::parse(data, nullptr, false);
159 if (jsonObject.is_discarded()) {
160 APP_LOGE("failed to parse BundleInfo");
161 return false;
162 }
163 *this = jsonObject.get<BundleInfo>();
164 return true;
165 }
166
Marshalling(Parcel & parcel) const167 bool BundleInfo::Marshalling(Parcel &parcel) const
168 {
169 MessageParcel *messageParcel = reinterpret_cast<MessageParcel *>(&parcel);
170 if (!messageParcel) {
171 APP_LOGE("Type conversion failed");
172 return false;
173 }
174 nlohmann::json json = *this;
175 std::string str = json.dump();
176 if (!messageParcel->WriteUint32(str.size() + 1)) {
177 APP_LOGE("Failed to write data size");
178 return false;
179 }
180 if (!messageParcel->WriteRawData(str.c_str(), str.size() + 1)) {
181 APP_LOGE("Failed to write data");
182 return false;
183 }
184 return true;
185 }
186
Unmarshalling(Parcel & parcel)187 BundleInfo *BundleInfo::Unmarshalling(Parcel &parcel)
188 {
189 BundleInfo *info = new (std::nothrow) BundleInfo();
190 if (info && !info->ReadFromParcel(parcel)) {
191 APP_LOGW("read from parcel failed");
192 delete info;
193 info = nullptr;
194 }
195 return info;
196 }
197
to_json(nlohmann::json & jsonObject,const RequestPermissionUsedScene & usedScene)198 void to_json(nlohmann::json &jsonObject, const RequestPermissionUsedScene &usedScene)
199 {
200 jsonObject = nlohmann::json {
201 {REQUESTPERMISSION_ABILITIES, usedScene.abilities},
202 {REQUESTPERMISSION_WHEN, usedScene.when}
203 };
204 }
205
to_json(nlohmann::json & jsonObject,const RequestPermission & requestPermission)206 void to_json(nlohmann::json &jsonObject, const RequestPermission &requestPermission)
207 {
208 jsonObject = nlohmann::json {
209 {REQUESTPERMISSION_NAME, requestPermission.name},
210 {REQUESTPERMISSION_REASON, requestPermission.reason},
211 {REQUESTPERMISSION_REASON_ID, requestPermission.reasonId},
212 {REQUESTPERMISSION_USEDSCENE, requestPermission.usedScene}
213 };
214 }
215
from_json(const nlohmann::json & jsonObject,RequestPermissionUsedScene & usedScene)216 void from_json(const nlohmann::json &jsonObject, RequestPermissionUsedScene &usedScene)
217 {
218 const auto &jsonObjectEnd = jsonObject.end();
219 int32_t parseResult = ERR_OK;
220 GetValueIfFindKey<std::vector<std::string>>(jsonObject,
221 jsonObjectEnd,
222 REQUESTPERMISSION_ABILITIES,
223 usedScene.abilities,
224 JsonType::ARRAY,
225 false,
226 parseResult,
227 ArrayType::STRING);
228 GetValueIfFindKey<std::vector<std::string>>(jsonObject,
229 jsonObjectEnd,
230 REQUESTPERMISSION_ABILITY,
231 usedScene.abilities,
232 JsonType::ARRAY,
233 false,
234 parseResult,
235 ArrayType::STRING);
236 GetValueIfFindKey<std::string>(jsonObject,
237 jsonObjectEnd,
238 REQUESTPERMISSION_WHEN,
239 usedScene.when,
240 JsonType::STRING,
241 false,
242 parseResult,
243 ArrayType::NOT_ARRAY);
244 if (parseResult != ERR_OK) {
245 APP_LOGE("read RequestPermissionUsedScene from database error, error code : %{public}d", parseResult);
246 }
247 }
248
from_json(const nlohmann::json & jsonObject,RequestPermission & requestPermission)249 void from_json(const nlohmann::json &jsonObject, RequestPermission &requestPermission)
250 {
251 const auto &jsonObjectEnd = jsonObject.end();
252 int32_t parseResult = ERR_OK;
253 GetValueIfFindKey<std::string>(jsonObject,
254 jsonObjectEnd,
255 REQUESTPERMISSION_NAME,
256 requestPermission.name,
257 JsonType::STRING,
258 false,
259 parseResult,
260 ArrayType::NOT_ARRAY);
261 GetValueIfFindKey<std::string>(jsonObject,
262 jsonObjectEnd,
263 REQUESTPERMISSION_REASON,
264 requestPermission.reason,
265 JsonType::STRING,
266 false,
267 parseResult,
268 ArrayType::NOT_ARRAY);
269 GetValueIfFindKey<int32_t>(jsonObject,
270 jsonObjectEnd,
271 REQUESTPERMISSION_REASON_ID,
272 requestPermission.reasonId,
273 JsonType::NUMBER,
274 false,
275 parseResult,
276 ArrayType::NOT_ARRAY);
277 GetValueIfFindKey<RequestPermissionUsedScene>(jsonObject,
278 jsonObjectEnd,
279 REQUESTPERMISSION_USEDSCENE,
280 requestPermission.usedScene,
281 JsonType::OBJECT,
282 false,
283 parseResult,
284 ArrayType::NOT_ARRAY);
285 if (parseResult != ERR_OK) {
286 APP_LOGE("read RequestPermission from database error, error code : %{public}d", parseResult);
287 }
288 }
289
to_json(nlohmann::json & jsonObject,const BundleInfo & bundleInfo)290 void to_json(nlohmann::json &jsonObject, const BundleInfo &bundleInfo)
291 {
292 jsonObject = nlohmann::json {
293 {BUNDLE_INFO_NAME, bundleInfo.name},
294 {BUNDLE_INFO_LABEL, bundleInfo.label},
295 {BUNDLE_INFO_DESCRIPTION, bundleInfo.description},
296 {BUNDLE_INFO_VENDOR, bundleInfo.vendor},
297 {BUNDLE_INFO_IS_KEEP_ALIVE, bundleInfo.isKeepAlive},
298 {BUNDLE_INFO_IS_NATIVE_APP, bundleInfo.isNativeApp},
299 {BUNDLE_INFO_IS_PREINSTALL_APP, bundleInfo.isPreInstallApp},
300 {BUNDLE_INFO_IS_DIFFERENT_NAME, bundleInfo.isDifferentName},
301 {BUNDLE_INFO_APPLICATION_INFO, bundleInfo.applicationInfo},
302 {BUNDLE_INFO_ABILITY_INFOS, bundleInfo.abilityInfos},
303 {BUNDLE_INFO_HAP_MODULE_INFOS, bundleInfo.hapModuleInfos},
304 {BUNDLE_INFO_EXTENSION_ABILITY_INFOS, bundleInfo.extensionInfos},
305 {BUNDLE_INFO_JOINT_USERID, bundleInfo.jointUserId},
306 {BUNDLE_INFO_VERSION_CODE, bundleInfo.versionCode},
307 {BUNDLE_INFO_MIN_COMPATIBLE_VERSION_CODE, bundleInfo.minCompatibleVersionCode},
308 {BUNDLE_INFO_VERSION_NAME, bundleInfo.versionName},
309 {BUNDLE_INFO_MIN_SDK_VERSION, bundleInfo.minSdkVersion},
310 {BUNDLE_INFO_MAX_SDK_VERSION, bundleInfo.maxSdkVersion},
311 {BUNDLE_INFO_MAIN_ENTRY, bundleInfo.mainEntry},
312 {BUNDLE_INFO_CPU_ABI, bundleInfo.cpuAbi},
313 {BUNDLE_INFO_APPID, bundleInfo.appId},
314 {BUNDLE_INFO_COMPATIBLE_VERSION, bundleInfo.compatibleVersion},
315 {BUNDLE_INFO_TARGET_VERSION, bundleInfo.targetVersion},
316 {BUNDLE_INFO_RELEASE_TYPE, bundleInfo.releaseType},
317 {BUNDLE_INFO_UID, bundleInfo.uid},
318 {BUNDLE_INFO_GID, bundleInfo.gid},
319 {BUNDLE_INFO_SEINFO, bundleInfo.seInfo},
320 {BUNDLE_INFO_INSTALL_TIME, bundleInfo.installTime},
321 {BUNDLE_INFO_UPDATE_TIME, bundleInfo.updateTime},
322 {BUNDLE_INFO_ENTRY_MODULE_NAME, bundleInfo.entryModuleName},
323 {BUNDLE_INFO_ENTRY_INSTALLATION_FREE, bundleInfo.entryInstallationFree},
324 {BUNDLE_INFO_REQ_PERMISSIONS, bundleInfo.reqPermissions},
325 {BUNDLE_INFO_REQ_PERMISSION_STATES, bundleInfo.reqPermissionStates},
326 {BUNDLE_INFO_REQ_PERMISSION_DETAILS, bundleInfo.reqPermissionDetails},
327 {BUNDLE_INFO_DEF_PERMISSIONS, bundleInfo.defPermissions},
328 {BUNDLE_INFO_HAP_MODULE_NAMES, bundleInfo.hapModuleNames},
329 {BUNDLE_INFO_MODULE_NAMES, bundleInfo.moduleNames},
330 {BUNDLE_INFO_MODULE_PUBLIC_DIRS, bundleInfo.modulePublicDirs},
331 {BUNDLE_INFO_MODULE_DIRS, bundleInfo.moduleDirs},
332 {BUNDLE_INFO_MODULE_RES_PATHS, bundleInfo.moduleResPaths},
333 {BUNDLE_INFO_SINGLE_USER, bundleInfo.singleUser}
334 };
335 }
336
from_json(const nlohmann::json & jsonObject,BundleInfo & bundleInfo)337 void from_json(const nlohmann::json &jsonObject, BundleInfo &bundleInfo)
338 {
339 const auto &jsonObjectEnd = jsonObject.end();
340 int32_t parseResult = ERR_OK;
341 GetValueIfFindKey<std::string>(jsonObject,
342 jsonObjectEnd,
343 BUNDLE_INFO_NAME,
344 bundleInfo.name,
345 JsonType::STRING,
346 false,
347 parseResult,
348 ArrayType::NOT_ARRAY);
349 GetValueIfFindKey<std::string>(jsonObject,
350 jsonObjectEnd,
351 BUNDLE_INFO_LABEL,
352 bundleInfo.label,
353 JsonType::STRING,
354 false,
355 parseResult,
356 ArrayType::NOT_ARRAY);
357 GetValueIfFindKey<std::string>(jsonObject,
358 jsonObjectEnd,
359 BUNDLE_INFO_DESCRIPTION,
360 bundleInfo.description,
361 JsonType::STRING,
362 false,
363 parseResult,
364 ArrayType::NOT_ARRAY);
365 GetValueIfFindKey<std::string>(jsonObject,
366 jsonObjectEnd,
367 BUNDLE_INFO_VENDOR,
368 bundleInfo.vendor,
369 JsonType::STRING,
370 false,
371 parseResult,
372 ArrayType::NOT_ARRAY);
373 GetValueIfFindKey<bool>(jsonObject,
374 jsonObjectEnd,
375 BUNDLE_INFO_IS_KEEP_ALIVE,
376 bundleInfo.isKeepAlive,
377 JsonType::BOOLEAN,
378 false,
379 parseResult,
380 ArrayType::NOT_ARRAY);
381 GetValueIfFindKey<bool>(jsonObject,
382 jsonObjectEnd,
383 BUNDLE_INFO_IS_NATIVE_APP,
384 bundleInfo.isNativeApp,
385 JsonType::BOOLEAN,
386 false,
387 parseResult,
388 ArrayType::NOT_ARRAY);
389 GetValueIfFindKey<bool>(jsonObject,
390 jsonObjectEnd,
391 BUNDLE_INFO_IS_PREINSTALL_APP,
392 bundleInfo.isPreInstallApp,
393 JsonType::BOOLEAN,
394 false,
395 parseResult,
396 ArrayType::NOT_ARRAY);
397 GetValueIfFindKey<bool>(jsonObject,
398 jsonObjectEnd,
399 BUNDLE_INFO_IS_DIFFERENT_NAME,
400 bundleInfo.isDifferentName,
401 JsonType::BOOLEAN,
402 false,
403 parseResult,
404 ArrayType::NOT_ARRAY);
405 GetValueIfFindKey<ApplicationInfo>(jsonObject,
406 jsonObjectEnd,
407 BUNDLE_INFO_APPLICATION_INFO,
408 bundleInfo.applicationInfo,
409 JsonType::OBJECT,
410 false,
411 parseResult,
412 ArrayType::NOT_ARRAY);
413 GetValueIfFindKey<std::vector<AbilityInfo>>(jsonObject,
414 jsonObjectEnd,
415 BUNDLE_INFO_ABILITY_INFOS,
416 bundleInfo.abilityInfos,
417 JsonType::ARRAY,
418 false,
419 parseResult,
420 ArrayType::OBJECT);
421 GetValueIfFindKey<std::vector<HapModuleInfo>>(jsonObject,
422 jsonObjectEnd,
423 BUNDLE_INFO_HAP_MODULE_INFOS,
424 bundleInfo.hapModuleInfos,
425 JsonType::ARRAY,
426 false,
427 parseResult,
428 ArrayType::OBJECT);
429 GetValueIfFindKey<uint32_t>(jsonObject,
430 jsonObjectEnd,
431 BUNDLE_INFO_VERSION_CODE,
432 bundleInfo.versionCode,
433 JsonType::NUMBER,
434 false,
435 parseResult,
436 ArrayType::NOT_ARRAY);
437 GetValueIfFindKey<uint32_t>(jsonObject,
438 jsonObjectEnd,
439 BUNDLE_INFO_MIN_COMPATIBLE_VERSION_CODE,
440 bundleInfo.minCompatibleVersionCode,
441 JsonType::NUMBER,
442 false,
443 parseResult,
444 ArrayType::NOT_ARRAY);
445 GetValueIfFindKey<std::string>(jsonObject,
446 jsonObjectEnd,
447 BUNDLE_INFO_VERSION_NAME,
448 bundleInfo.versionName,
449 JsonType::STRING,
450 false,
451 parseResult,
452 ArrayType::NOT_ARRAY);
453 GetValueIfFindKey<std::string>(jsonObject,
454 jsonObjectEnd,
455 BUNDLE_INFO_JOINT_USERID,
456 bundleInfo.jointUserId,
457 JsonType::STRING,
458 false,
459 parseResult,
460 ArrayType::NOT_ARRAY);
461 GetValueIfFindKey<int32_t>(jsonObject,
462 jsonObjectEnd,
463 BUNDLE_INFO_MIN_SDK_VERSION,
464 bundleInfo.minSdkVersion,
465 JsonType::NUMBER,
466 false,
467 parseResult,
468 ArrayType::NOT_ARRAY);
469 GetValueIfFindKey<int32_t>(jsonObject,
470 jsonObjectEnd,
471 BUNDLE_INFO_MAX_SDK_VERSION,
472 bundleInfo.maxSdkVersion,
473 JsonType::NUMBER,
474 false,
475 parseResult,
476 ArrayType::NOT_ARRAY);
477 GetValueIfFindKey<std::string>(jsonObject,
478 jsonObjectEnd,
479 BUNDLE_INFO_MAIN_ENTRY,
480 bundleInfo.mainEntry,
481 JsonType::STRING,
482 false,
483 parseResult,
484 ArrayType::NOT_ARRAY);
485 GetValueIfFindKey<std::string>(jsonObject,
486 jsonObjectEnd,
487 BUNDLE_INFO_CPU_ABI,
488 bundleInfo.cpuAbi,
489 JsonType::STRING,
490 false,
491 parseResult,
492 ArrayType::NOT_ARRAY);
493 GetValueIfFindKey<std::string>(jsonObject,
494 jsonObjectEnd,
495 BUNDLE_INFO_APPID,
496 bundleInfo.appId,
497 JsonType::STRING,
498 false,
499 parseResult,
500 ArrayType::NOT_ARRAY);
501 GetValueIfFindKey<int>(jsonObject,
502 jsonObjectEnd,
503 BUNDLE_INFO_COMPATIBLE_VERSION,
504 bundleInfo.compatibleVersion,
505 JsonType::NUMBER,
506 false,
507 parseResult,
508 ArrayType::NOT_ARRAY);
509 GetValueIfFindKey<uint32_t>(jsonObject,
510 jsonObjectEnd,
511 BUNDLE_INFO_TARGET_VERSION,
512 bundleInfo.targetVersion,
513 JsonType::NUMBER,
514 false,
515 parseResult,
516 ArrayType::NOT_ARRAY);
517 GetValueIfFindKey<std::string>(jsonObject,
518 jsonObjectEnd,
519 BUNDLE_INFO_RELEASE_TYPE,
520 bundleInfo.releaseType,
521 JsonType::STRING,
522 false,
523 parseResult,
524 ArrayType::NOT_ARRAY);
525 GetValueIfFindKey<int>(jsonObject,
526 jsonObjectEnd,
527 BUNDLE_INFO_UID,
528 bundleInfo.uid,
529 JsonType::NUMBER,
530 false,
531 parseResult,
532 ArrayType::NOT_ARRAY);
533 GetValueIfFindKey<int>(jsonObject,
534 jsonObjectEnd,
535 BUNDLE_INFO_GID,
536 bundleInfo.gid,
537 JsonType::NUMBER,
538 false,
539 parseResult,
540 ArrayType::NOT_ARRAY);
541 GetValueIfFindKey<std::string>(jsonObject,
542 jsonObjectEnd,
543 BUNDLE_INFO_SEINFO,
544 bundleInfo.seInfo,
545 JsonType::STRING,
546 false,
547 parseResult,
548 ArrayType::NOT_ARRAY);
549 GetValueIfFindKey<int64_t>(jsonObject,
550 jsonObjectEnd,
551 BUNDLE_INFO_INSTALL_TIME,
552 bundleInfo.installTime,
553 JsonType::NUMBER,
554 false,
555 parseResult,
556 ArrayType::NOT_ARRAY);
557 GetValueIfFindKey<int64_t>(jsonObject,
558 jsonObjectEnd,
559 BUNDLE_INFO_UPDATE_TIME,
560 bundleInfo.updateTime,
561 JsonType::NUMBER,
562 false,
563 parseResult,
564 ArrayType::NOT_ARRAY);
565 GetValueIfFindKey<std::string>(jsonObject,
566 jsonObjectEnd,
567 BUNDLE_INFO_ENTRY_MODULE_NAME,
568 bundleInfo.entryModuleName,
569 JsonType::STRING,
570 false,
571 parseResult,
572 ArrayType::NOT_ARRAY);
573 GetValueIfFindKey<bool>(jsonObject,
574 jsonObjectEnd,
575 BUNDLE_INFO_ENTRY_INSTALLATION_FREE,
576 bundleInfo.entryInstallationFree,
577 JsonType::BOOLEAN,
578 false,
579 parseResult,
580 ArrayType::NOT_ARRAY);
581 GetValueIfFindKey<std::vector<std::string>>(jsonObject,
582 jsonObjectEnd,
583 BUNDLE_INFO_REQ_PERMISSIONS,
584 bundleInfo.reqPermissions,
585 JsonType::ARRAY,
586 false,
587 parseResult,
588 ArrayType::STRING);
589 GetValueIfFindKey<std::vector<int32_t>>(jsonObject,
590 jsonObjectEnd,
591 BUNDLE_INFO_REQ_PERMISSION_STATES,
592 bundleInfo.reqPermissionStates,
593 JsonType::ARRAY,
594 false,
595 parseResult,
596 ArrayType::NUMBER);
597 GetValueIfFindKey<std::vector<RequestPermission>>(jsonObject,
598 jsonObjectEnd,
599 BUNDLE_INFO_REQ_PERMISSION_DETAILS,
600 bundleInfo.reqPermissionDetails,
601 JsonType::ARRAY,
602 false,
603 parseResult,
604 ArrayType::OBJECT);
605 GetValueIfFindKey<std::vector<std::string>>(jsonObject,
606 jsonObjectEnd,
607 BUNDLE_INFO_DEF_PERMISSIONS,
608 bundleInfo.defPermissions,
609 JsonType::ARRAY,
610 false,
611 parseResult,
612 ArrayType::STRING);
613 GetValueIfFindKey<std::vector<std::string>>(jsonObject,
614 jsonObjectEnd,
615 BUNDLE_INFO_HAP_MODULE_NAMES,
616 bundleInfo.hapModuleNames,
617 JsonType::ARRAY,
618 false,
619 parseResult,
620 ArrayType::STRING);
621 GetValueIfFindKey<std::vector<std::string>>(jsonObject,
622 jsonObjectEnd,
623 BUNDLE_INFO_MODULE_NAMES,
624 bundleInfo.moduleNames,
625 JsonType::ARRAY,
626 false,
627 parseResult,
628 ArrayType::STRING);
629 GetValueIfFindKey<std::vector<std::string>>(jsonObject,
630 jsonObjectEnd,
631 BUNDLE_INFO_MODULE_PUBLIC_DIRS,
632 bundleInfo.modulePublicDirs,
633 JsonType::ARRAY,
634 false,
635 parseResult,
636 ArrayType::STRING);
637 GetValueIfFindKey<std::vector<std::string>>(jsonObject,
638 jsonObjectEnd,
639 BUNDLE_INFO_MODULE_DIRS,
640 bundleInfo.moduleDirs,
641 JsonType::ARRAY,
642 false,
643 parseResult,
644 ArrayType::STRING);
645 GetValueIfFindKey<std::vector<std::string>>(jsonObject,
646 jsonObjectEnd,
647 BUNDLE_INFO_MODULE_RES_PATHS,
648 bundleInfo.moduleResPaths,
649 JsonType::ARRAY,
650 false,
651 parseResult,
652 ArrayType::STRING);
653 GetValueIfFindKey<bool>(jsonObject,
654 jsonObjectEnd,
655 BUNDLE_INFO_SINGLE_USER,
656 bundleInfo.singleUser,
657 JsonType::BOOLEAN,
658 false,
659 parseResult,
660 ArrayType::NOT_ARRAY);
661 GetValueIfFindKey<std::vector<ExtensionAbilityInfo>>(jsonObject,
662 jsonObjectEnd,
663 BUNDLE_INFO_EXTENSION_ABILITY_INFOS,
664 bundleInfo.extensionInfos,
665 JsonType::ARRAY,
666 false,
667 parseResult,
668 ArrayType::OBJECT);
669 }
670
671 } // namespace AppExecFwk
672 } // namespace OHOS
673