1 /*
2 * Copyright (c) 2023-2024 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 "module_profile.h"
17
18 #include <algorithm>
19 #include <mutex>
20 #include <set>
21 #include <sstream>
22 #include "bundle_constants.h"
23 #include "bundle_info.h"
24 #include "common_profile.h"
25 #include "hilog_tag_wrapper.h"
26 #include "string_ex.h"
27
28 namespace OHOS {
29 namespace AppExecFwk {
30 const std::unordered_map<std::string, ExtensionAbilityType> EXTENSION_TYPE_MAP = {
31 { "form", ExtensionAbilityType::FORM },
32 { "workScheduler", ExtensionAbilityType::WORK_SCHEDULER },
33 { "inputMethod", ExtensionAbilityType::INPUTMETHOD },
34 { "service", ExtensionAbilityType::SERVICE },
35 { "accessibility", ExtensionAbilityType::ACCESSIBILITY },
36 { "dataShare", ExtensionAbilityType::DATASHARE },
37 { "fileShare", ExtensionAbilityType::FILESHARE },
38 { "staticSubscriber", ExtensionAbilityType::STATICSUBSCRIBER },
39 { "fence", ExtensionAbilityType::FENCE },
40 { "wallpaper", ExtensionAbilityType::WALLPAPER },
41 { "backup", ExtensionAbilityType::BACKUP },
42 { "window", ExtensionAbilityType::WINDOW },
43 { "enterpriseAdmin", ExtensionAbilityType::ENTERPRISE_ADMIN },
44 { "fileAccess", ExtensionAbilityType::FILEACCESS_EXTENSION },
45 { "thumbnail", ExtensionAbilityType::THUMBNAIL },
46 { "preview", ExtensionAbilityType::PREVIEW_TYPE },
47 { "print", ExtensionAbilityType::PRINT },
48 { "push", ExtensionAbilityType::PUSH },
49 { "driver", ExtensionAbilityType::DRIVER },
50 { "appAccountAuthorization", ExtensionAbilityType::APP_ACCOUNT_AUTHORIZATION },
51 { "ui", ExtensionAbilityType::UI },
52 { "sysDialog/userAuth", ExtensionAbilityType::SYSDIALOG_USERAUTH },
53 { "sysDialog/common", ExtensionAbilityType::SYSDIALOG_COMMON },
54 { "sysPicker/mediaControl", ExtensionAbilityType::SYSPICKER_MEDIACONTROL },
55 { "sysDialog/atomicServicePanel", ExtensionAbilityType::SYSDIALOG_ATOMICSERVICEPANEL },
56 { "sysPicker/share", ExtensionAbilityType::SYSPICKER_SHARE },
57 { "hms/account", ExtensionAbilityType::HMS_ACCOUNT },
58 { "distributed", ExtensionAbilityType::DISTRIBUTED }
59 };
60
ConvertToExtensionAbilityType(const std::string & type)61 ExtensionAbilityType ConvertToExtensionAbilityType(const std::string &type)
62 {
63 TAG_LOGD(AAFwkTag::ABILITY_SIM, "called");
64 if (EXTENSION_TYPE_MAP.find(type) != EXTENSION_TYPE_MAP.end()) {
65 return EXTENSION_TYPE_MAP.at(type);
66 }
67
68 return ExtensionAbilityType::UNSPECIFIED;
69 }
70
ConvertToExtensionTypeName(ExtensionAbilityType type)71 std::string ConvertToExtensionTypeName(ExtensionAbilityType type)
72 {
73 TAG_LOGD(AAFwkTag::ABILITY_SIM, "called");
74 for (const auto &[key, val] : EXTENSION_TYPE_MAP) {
75 if (val == type) {
76 return key;
77 }
78 }
79
80 return "Unspecified";
81 }
82
83 namespace Profile {
84 int32_t g_parseResult = ERR_OK;
85 std::mutex g_mutex;
86
87 const std::set<std::string> MODULE_TYPE_SET = {
88 "entry",
89 "feature",
90 "shared"
91 };
92
93 const std::set<std::string> VIRTUAL_MACHINE_SET = {
94 "ark",
95 "default"
96 };
97
98 const std::map<std::string, uint32_t> BACKGROUND_MODES_MAP = {
99 {ProfileReader::KEY_DATA_TRANSFER, ProfileReader::VALUE_DATA_TRANSFER},
100 {ProfileReader::KEY_AUDIO_PLAYBACK, ProfileReader::VALUE_AUDIO_PLAYBACK},
101 {ProfileReader::KEY_AUDIO_RECORDING, ProfileReader::VALUE_AUDIO_RECORDING},
102 {ProfileReader::KEY_LOCATION, ProfileReader::VALUE_LOCATION},
103 {ProfileReader::KEY_BLUETOOTH_INTERACTION, ProfileReader::VALUE_BLUETOOTH_INTERACTION},
104 {ProfileReader::KEY_MULTI_DEVICE_CONNECTION, ProfileReader::VALUE_MULTI_DEVICE_CONNECTION},
105 {ProfileReader::KEY_WIFI_INTERACTION, ProfileReader::VALUE_WIFI_INTERACTION},
106 {ProfileReader::KEY_VOIP, ProfileReader::VALUE_VOIP},
107 {ProfileReader::KEY_TASK_KEEPING, ProfileReader::VALUE_TASK_KEEPING},
108 {ProfileReader::KEY_PICTURE_IN_PICTURE, ProfileReader::VALUE_PICTURE_IN_PICTURE},
109 {ProfileReader::KEY_SCREEN_FETCH, ProfileReader::VALUE_SCREEN_FETCH}
110 };
111
112 const std::set<std::string> GRANT_MODE_SET = {
113 "system_grant",
114 "user_grant"
115 };
116
117 const std::set<std::string> AVAILABLE_LEVEL_SET = {
118 "system_core",
119 "system_basic",
120 "normal"
121 };
122
123 const std::map<std::string, LaunchMode> LAUNCH_MODE_MAP = {
124 {"singleton", LaunchMode::SINGLETON},
125 {"standard", LaunchMode::STANDARD},
126 {"multiton", LaunchMode::STANDARD},
127 {"specified", LaunchMode::SPECIFIED}
128 };
129 const std::unordered_map<std::string, DisplayOrientation> DISPLAY_ORIENTATION_MAP = {
130 {"unspecified", DisplayOrientation::UNSPECIFIED},
131 {"landscape", DisplayOrientation::LANDSCAPE},
132 {"portrait", DisplayOrientation::PORTRAIT},
133 {"landscape_inverted", DisplayOrientation::LANDSCAPE_INVERTED},
134 {"portrait_inverted", DisplayOrientation::PORTRAIT_INVERTED},
135 {"auto_rotation", DisplayOrientation::AUTO_ROTATION},
136 {"auto_rotation_landscape", DisplayOrientation::AUTO_ROTATION_LANDSCAPE},
137 {"auto_rotation_portrait", DisplayOrientation::AUTO_ROTATION_PORTRAIT},
138 {"auto_rotation_restricted", DisplayOrientation::AUTO_ROTATION_RESTRICTED},
139 {"auto_rotation_landscape_restricted", DisplayOrientation::AUTO_ROTATION_LANDSCAPE_RESTRICTED},
140 {"auto_rotation_portrait_restricted", DisplayOrientation::AUTO_ROTATION_PORTRAIT_RESTRICTED},
141 {"locked", DisplayOrientation::LOCKED}
142 };
143 const std::unordered_map<std::string, SupportWindowMode> WINDOW_MODE_MAP = {
144 {"fullscreen", SupportWindowMode::FULLSCREEN},
145 {"split", SupportWindowMode::SPLIT},
146 {"floating", SupportWindowMode::FLOATING}
147 };
148 const std::unordered_map<std::string, BundleType> BUNDLE_TYPE_MAP = {
149 {"app", BundleType::APP},
150 {"atomicService", BundleType::ATOMIC_SERVICE},
151 {"shared", BundleType::SHARED}
152 };
153
154 struct DeviceConfig {
155 // pair first : if exist in module.json then true, otherwise false
156 // pair second : actual value
157 std::pair<bool, int32_t> minAPIVersion = std::make_pair<>(false, 0);
158 std::pair<bool, bool> keepAlive = std::make_pair<>(false, false);
159 std::pair<bool, bool> removable = std::make_pair<>(false, true);
160 std::pair<bool, bool> singleton = std::make_pair<>(false, false);
161 std::pair<bool, bool> userDataClearable = std::make_pair<>(false, true);
162 std::pair<bool, bool> accessible = std::make_pair<>(false, true);
163 };
164
165 struct Metadata {
166 std::string name;
167 std::string value;
168 std::string resource;
169 };
170
171 struct Ability {
172 std::string name;
173 std::string srcEntrance;
174 std::string launchType = ABILITY_LAUNCH_TYPE_DEFAULT_VALUE;
175 std::string description;
176 int32_t descriptionId = 0;
177 std::string icon;
178 int32_t iconId = 0;
179 std::string label;
180 int32_t labelId = 0;
181 int32_t priority = 0;
182 std::vector<std::string> permissions;
183 std::vector<Metadata> metadata;
184 bool visible = false;
185 bool continuable = false;
186 std::vector<std::string> backgroundModes;
187 std::string startWindowIcon;
188 int32_t startWindowIconId = 0;
189 std::string startWindowBackground;
190 int32_t startWindowBackgroundId = 0;
191 bool removeMissionAfterTerminate = false;
192 std::string orientation = "unspecified";
193 std::vector<std::string> windowModes;
194 double maxWindowRatio = 0;
195 double minWindowRatio = 0;
196 uint32_t maxWindowWidth = 0;
197 uint32_t minWindowWidth = 0;
198 uint32_t maxWindowHeight = 0;
199 uint32_t minWindowHeight = 0;
200 bool excludeFromMissions = false;
201 bool recoverable = false;
202 bool unclearableMission = false;
203 };
204
205 struct Extension {
206 std::string name;
207 std::string srcEntrance;
208 std::string icon;
209 int32_t iconId = 0;
210 std::string label;
211 int32_t labelId = 0;
212 std::string description;
213 int32_t descriptionId = 0;
214 int32_t priority = 0;
215 std::string type;
216 std::string readPermission;
217 std::string writePermission;
218 std::string uri;
219 std::vector<std::string> permissions;
220 bool visible = false;
221 std::vector<Metadata> metadata;
222 };
223
224 struct App {
225 std::string bundleName;
226 bool debug = false;
227 std::string icon;
228 int32_t iconId = 0;
229 std::string label;
230 int32_t labelId = 0;
231 std::string description;
232 int32_t descriptionId = 0;
233 std::string vendor;
234 int32_t versionCode = 0;
235 std::string versionName;
236 int32_t minCompatibleVersionCode = -1;
237 uint32_t minAPIVersion = 0;
238 int32_t targetAPIVersion = 0;
239 std::string apiReleaseType = APP_API_RELEASETYPE_DEFAULT_VALUE;
240 bool keepAlive = false;
241 std::pair<bool, bool> removable = std::make_pair<>(false, true);
242 bool singleton = false;
243 bool userDataClearable = true;
244 bool accessible = false;
245 std::vector<std::string> targetBundleList;
246 std::map<std::string, DeviceConfig> deviceConfigs;
247 bool multiProjects = false;
248 std::string targetBundle;
249 int32_t targetPriority = 0;
250 bool asanEnabled = false;
251 std::string bundleType = Profile::BUNDLE_TYPE_APP;
252 std::string compileSdkVersion;
253 std::string compileSdkType = Profile::COMPILE_SDK_TYPE_OPEN_HARMONY;
254 };
255
256 struct Module {
257 std::string name;
258 std::string type;
259 std::string srcEntrance;
260 std::string description;
261 int32_t descriptionId = 0;
262 std::string process;
263 std::string mainElement;
264 std::vector<std::string> deviceTypes;
265 bool deliveryWithInstall = false;
266 bool installationFree = false;
267 std::string virtualMachine = MODULE_VIRTUAL_MACHINE_DEFAULT_VALUE;
268 std::string pages;
269 std::vector<Metadata> metadata;
270 std::vector<Ability> abilities;
271 std::vector<Extension> extensionAbilities;
272 std::vector<Dependency> dependencies;
273 std::string compileMode;
274 bool isLibIsolated = false;
275 std::string targetModule;
276 int32_t targetPriority = 0;
277 std::vector<ProxyData> proxyDatas;
278 std::vector<ProxyData> proxyData;
279 std::string buildHash;
280 std::string isolationMode;
281 bool compressNativeLibs = true;
282 };
283
284 struct ModuleJson {
285 App app;
286 Module module;
287 };
288
from_json(const nlohmann::json & jsonObject,Metadata & metadata)289 void from_json(const nlohmann::json &jsonObject, Metadata &metadata)
290 {
291 TAG_LOGD(AAFwkTag::ABILITY_SIM, "read metadata tag from module.json");
292 const auto &jsonObjectEnd = jsonObject.end();
293 GetValueIfFindKey<std::string>(jsonObject,
294 jsonObjectEnd,
295 META_DATA_NAME,
296 metadata.name,
297 JsonType::STRING,
298 false,
299 g_parseResult,
300 ArrayType::NOT_ARRAY);
301 GetValueIfFindKey<std::string>(jsonObject,
302 jsonObjectEnd,
303 META_DATA_VALUE,
304 metadata.value,
305 JsonType::STRING,
306 false,
307 g_parseResult,
308 ArrayType::NOT_ARRAY);
309 GetValueIfFindKey<std::string>(jsonObject,
310 jsonObjectEnd,
311 META_DATA_RESOURCE,
312 metadata.resource,
313 JsonType::STRING,
314 false,
315 g_parseResult,
316 ArrayType::NOT_ARRAY);
317 }
318
from_json(const nlohmann::json & jsonObject,Ability & ability)319 void from_json(const nlohmann::json &jsonObject, Ability &ability)
320 {
321 TAG_LOGD(AAFwkTag::ABILITY_SIM, "read ability tag from module.json");
322 const auto &jsonObjectEnd = jsonObject.end();
323 GetValueIfFindKey<std::string>(jsonObject,
324 jsonObjectEnd,
325 ABILITY_NAME,
326 ability.name,
327 JsonType::STRING,
328 true,
329 g_parseResult,
330 ArrayType::NOT_ARRAY);
331 // both srcEntry and srcEntrance can be configured, but srcEntry has higher priority
332 if (jsonObject.find(SRC_ENTRY) != jsonObject.end()) {
333 GetValueIfFindKey<std::string>(jsonObject,
334 jsonObjectEnd,
335 SRC_ENTRY,
336 ability.srcEntrance,
337 JsonType::STRING,
338 true,
339 g_parseResult,
340 ArrayType::NOT_ARRAY);
341 } else {
342 GetValueIfFindKey<std::string>(jsonObject,
343 jsonObjectEnd,
344 SRC_ENTRANCE,
345 ability.srcEntrance,
346 JsonType::STRING,
347 true,
348 g_parseResult,
349 ArrayType::NOT_ARRAY);
350 }
351 GetValueIfFindKey<std::string>(jsonObject,
352 jsonObjectEnd,
353 ABILITY_LAUNCH_TYPE,
354 ability.launchType,
355 JsonType::STRING,
356 false,
357 g_parseResult,
358 ArrayType::NOT_ARRAY);
359 GetValueIfFindKey<std::string>(jsonObject,
360 jsonObjectEnd,
361 DESCRIPTION,
362 ability.description,
363 JsonType::STRING,
364 false,
365 g_parseResult,
366 ArrayType::NOT_ARRAY);
367 GetValueIfFindKey<int32_t>(jsonObject,
368 jsonObjectEnd,
369 DESCRIPTION_ID,
370 ability.descriptionId,
371 JsonType::NUMBER,
372 false,
373 g_parseResult,
374 ArrayType::NOT_ARRAY);
375 GetValueIfFindKey<std::string>(jsonObject,
376 jsonObjectEnd,
377 ICON,
378 ability.icon,
379 JsonType::STRING,
380 false,
381 g_parseResult,
382 ArrayType::NOT_ARRAY);
383 GetValueIfFindKey<int32_t>(jsonObject,
384 jsonObjectEnd,
385 ICON_ID,
386 ability.iconId,
387 JsonType::NUMBER,
388 false,
389 g_parseResult,
390 ArrayType::NOT_ARRAY);
391 GetValueIfFindKey<std::string>(jsonObject,
392 jsonObjectEnd,
393 LABEL,
394 ability.label,
395 JsonType::STRING,
396 false,
397 g_parseResult,
398 ArrayType::NOT_ARRAY);
399 GetValueIfFindKey<int32_t>(jsonObject,
400 jsonObjectEnd,
401 LABEL_ID,
402 ability.labelId,
403 JsonType::NUMBER,
404 false,
405 g_parseResult,
406 ArrayType::NOT_ARRAY);
407 GetValueIfFindKey<int32_t>(jsonObject,
408 jsonObjectEnd,
409 PRIORITY,
410 ability.priority,
411 JsonType::NUMBER,
412 false,
413 g_parseResult,
414 ArrayType::NOT_ARRAY);
415 GetValueIfFindKey<std::vector<std::string>>(jsonObject,
416 jsonObjectEnd,
417 PERMISSIONS,
418 ability.permissions,
419 JsonType::ARRAY,
420 false,
421 g_parseResult,
422 ArrayType::STRING);
423 GetValueIfFindKey<std::vector<Metadata>>(jsonObject,
424 jsonObjectEnd,
425 META_DATA,
426 ability.metadata,
427 JsonType::ARRAY,
428 false,
429 g_parseResult,
430 ArrayType::OBJECT);
431 // both exported and visible can be configured, but exported has higher priority
432 GetValueIfFindKey<bool>(jsonObject,
433 jsonObjectEnd,
434 VISIBLE,
435 ability.visible,
436 JsonType::BOOLEAN,
437 false,
438 g_parseResult,
439 ArrayType::NOT_ARRAY);
440 GetValueIfFindKey<bool>(jsonObject,
441 jsonObjectEnd,
442 EXPORTED,
443 ability.visible,
444 JsonType::BOOLEAN,
445 false,
446 g_parseResult,
447 ArrayType::NOT_ARRAY);
448 GetValueIfFindKey<bool>(jsonObject,
449 jsonObjectEnd,
450 ABILITY_CONTINUABLE,
451 ability.continuable,
452 JsonType::BOOLEAN,
453 false,
454 g_parseResult,
455 ArrayType::NOT_ARRAY);
456 GetValueIfFindKey<std::vector<std::string>>(jsonObject,
457 jsonObjectEnd,
458 ABILITY_BACKGROUNDMODES,
459 ability.backgroundModes,
460 JsonType::ARRAY,
461 false,
462 g_parseResult,
463 ArrayType::STRING);
464 GetValueIfFindKey<std::string>(jsonObject,
465 jsonObjectEnd,
466 ABILITY_START_WINDOW_ICON,
467 ability.startWindowIcon,
468 JsonType::STRING,
469 false,
470 g_parseResult,
471 ArrayType::NOT_ARRAY);
472 GetValueIfFindKey<int32_t>(jsonObject,
473 jsonObjectEnd,
474 ABILITY_START_WINDOW_ICON_ID,
475 ability.startWindowIconId,
476 JsonType::NUMBER,
477 false,
478 g_parseResult,
479 ArrayType::NOT_ARRAY);
480 GetValueIfFindKey<std::string>(jsonObject,
481 jsonObjectEnd,
482 ABILITY_START_WINDOW_BACKGROUND,
483 ability.startWindowBackground,
484 JsonType::STRING,
485 false,
486 g_parseResult,
487 ArrayType::NOT_ARRAY);
488 GetValueIfFindKey<int32_t>(jsonObject,
489 jsonObjectEnd,
490 ABILITY_START_WINDOW_BACKGROUND_ID,
491 ability.startWindowBackgroundId,
492 JsonType::NUMBER,
493 false,
494 g_parseResult,
495 ArrayType::NOT_ARRAY);
496 GetValueIfFindKey<bool>(jsonObject,
497 jsonObjectEnd,
498 ABILITY_REMOVE_MISSION_AFTER_TERMINATE,
499 ability.removeMissionAfterTerminate,
500 JsonType::BOOLEAN,
501 false,
502 g_parseResult,
503 ArrayType::NOT_ARRAY);
504 GetValueIfFindKey<std::string>(jsonObject,
505 jsonObjectEnd,
506 ABILITY_ORIENTATION,
507 ability.orientation,
508 JsonType::STRING,
509 false,
510 g_parseResult,
511 ArrayType::NOT_ARRAY);
512 GetValueIfFindKey<std::vector<std::string>>(jsonObject,
513 jsonObjectEnd,
514 ABILITY_SUPPORT_WINDOW_MODE,
515 ability.windowModes,
516 JsonType::ARRAY,
517 false,
518 g_parseResult,
519 ArrayType::STRING);
520 GetValueIfFindKey<double>(jsonObject,
521 jsonObjectEnd,
522 ABILITY_MAX_WINDOW_RATIO,
523 ability.maxWindowRatio,
524 JsonType::NUMBER,
525 false,
526 g_parseResult,
527 ArrayType::NOT_ARRAY);
528 GetValueIfFindKey<double>(jsonObject,
529 jsonObjectEnd,
530 ABILITY_MIN_WINDOW_RATIO,
531 ability.minWindowRatio,
532 JsonType::NUMBER,
533 false,
534 g_parseResult,
535 ArrayType::NOT_ARRAY);
536 GetValueIfFindKey<uint32_t>(jsonObject,
537 jsonObjectEnd,
538 ABILITY_MAX_WINDOW_WIDTH,
539 ability.maxWindowWidth,
540 JsonType::NUMBER,
541 false,
542 g_parseResult,
543 ArrayType::NOT_ARRAY);
544 GetValueIfFindKey<uint32_t>(jsonObject,
545 jsonObjectEnd,
546 ABILITY_MIN_WINDOW_WIDTH,
547 ability.minWindowWidth,
548 JsonType::NUMBER,
549 false,
550 g_parseResult,
551 ArrayType::NOT_ARRAY);
552 GetValueIfFindKey<uint32_t>(jsonObject,
553 jsonObjectEnd,
554 ABILITY_MAX_WINDOW_HEIGHT,
555 ability.maxWindowHeight,
556 JsonType::NUMBER,
557 false,
558 g_parseResult,
559 ArrayType::NOT_ARRAY);
560 GetValueIfFindKey<uint32_t>(jsonObject,
561 jsonObjectEnd,
562 ABILITY_MIN_WINDOW_HEIGHT,
563 ability.minWindowHeight,
564 JsonType::NUMBER,
565 false,
566 g_parseResult,
567 ArrayType::NOT_ARRAY);
568 GetValueIfFindKey<bool>(jsonObject,
569 jsonObjectEnd,
570 ABILITY_EXCLUDE_FROM_MISSIONS,
571 ability.excludeFromMissions,
572 JsonType::BOOLEAN,
573 false,
574 g_parseResult,
575 ArrayType::NOT_ARRAY);
576 GetValueIfFindKey<bool>(jsonObject,
577 jsonObjectEnd,
578 ABILITY_RECOVERABLE,
579 ability.recoverable,
580 JsonType::BOOLEAN,
581 false,
582 g_parseResult,
583 ArrayType::NOT_ARRAY);
584 GetValueIfFindKey<bool>(jsonObject,
585 jsonObjectEnd,
586 ABILITY_UNCLEARABLE_MISSION,
587 ability.unclearableMission,
588 JsonType::BOOLEAN,
589 false,
590 g_parseResult,
591 ArrayType::NOT_ARRAY);
592 }
593
from_json(const nlohmann::json & jsonObject,Extension & extension)594 void from_json(const nlohmann::json &jsonObject, Extension &extension)
595 {
596 TAG_LOGD(AAFwkTag::ABILITY_SIM, "read extension tag from module.json");
597 const auto &jsonObjectEnd = jsonObject.end();
598 GetValueIfFindKey<std::string>(jsonObject,
599 jsonObjectEnd,
600 EXTENSION_ABILITY_NAME,
601 extension.name,
602 JsonType::STRING,
603 true,
604 g_parseResult,
605 ArrayType::NOT_ARRAY);
606 // both srcEntry and srcEntrance can be configured, but srcEntry has higher priority
607 if (jsonObject.find(SRC_ENTRY) != jsonObject.end()) {
608 GetValueIfFindKey<std::string>(jsonObject,
609 jsonObjectEnd,
610 SRC_ENTRY,
611 extension.srcEntrance,
612 JsonType::STRING,
613 true,
614 g_parseResult,
615 ArrayType::NOT_ARRAY);
616 } else {
617 GetValueIfFindKey<std::string>(jsonObject,
618 jsonObjectEnd,
619 SRC_ENTRANCE,
620 extension.srcEntrance,
621 JsonType::STRING,
622 true,
623 g_parseResult,
624 ArrayType::NOT_ARRAY);
625 }
626 GetValueIfFindKey<std::string>(jsonObject,
627 jsonObjectEnd,
628 ICON,
629 extension.icon,
630 JsonType::STRING,
631 false,
632 g_parseResult,
633 ArrayType::NOT_ARRAY);
634 GetValueIfFindKey<int32_t>(jsonObject,
635 jsonObjectEnd,
636 ICON_ID,
637 extension.iconId,
638 JsonType::NUMBER,
639 false,
640 g_parseResult,
641 ArrayType::NOT_ARRAY);
642 GetValueIfFindKey<std::string>(jsonObject,
643 jsonObjectEnd,
644 LABEL,
645 extension.label,
646 JsonType::STRING,
647 false,
648 g_parseResult,
649 ArrayType::NOT_ARRAY);
650 GetValueIfFindKey<int32_t>(jsonObject,
651 jsonObjectEnd,
652 LABEL_ID,
653 extension.labelId,
654 JsonType::NUMBER,
655 false,
656 g_parseResult,
657 ArrayType::NOT_ARRAY);
658 GetValueIfFindKey<std::string>(jsonObject,
659 jsonObjectEnd,
660 DESCRIPTION,
661 extension.description,
662 JsonType::STRING,
663 false,
664 g_parseResult,
665 ArrayType::NOT_ARRAY);
666 GetValueIfFindKey<int32_t>(jsonObject,
667 jsonObjectEnd,
668 DESCRIPTION_ID,
669 extension.descriptionId,
670 JsonType::NUMBER,
671 false,
672 g_parseResult,
673 ArrayType::NOT_ARRAY);
674 GetValueIfFindKey<int32_t>(jsonObject,
675 jsonObjectEnd,
676 PRIORITY,
677 extension.priority,
678 JsonType::NUMBER,
679 false,
680 g_parseResult,
681 ArrayType::NOT_ARRAY);
682 GetValueIfFindKey<std::string>(jsonObject,
683 jsonObjectEnd,
684 EXTENSION_ABILITY_TYPE,
685 extension.type,
686 JsonType::STRING,
687 true,
688 g_parseResult,
689 ArrayType::NOT_ARRAY);
690 GetValueIfFindKey<std::string>(jsonObject,
691 jsonObjectEnd,
692 EXTENSION_ABILITY_READ_PERMISSION,
693 extension.readPermission,
694 JsonType::STRING,
695 false,
696 g_parseResult,
697 ArrayType::NOT_ARRAY);
698 GetValueIfFindKey<std::string>(jsonObject,
699 jsonObjectEnd,
700 EXTENSION_ABILITY_WRITE_PERMISSION,
701 extension.writePermission,
702 JsonType::STRING,
703 false,
704 g_parseResult,
705 ArrayType::NOT_ARRAY);
706 GetValueIfFindKey<std::string>(jsonObject,
707 jsonObjectEnd,
708 EXTENSION_URI,
709 extension.uri,
710 JsonType::STRING,
711 false,
712 g_parseResult,
713 ArrayType::NOT_ARRAY);
714 GetValueIfFindKey<std::vector<std::string>>(jsonObject,
715 jsonObjectEnd,
716 PERMISSIONS,
717 extension.permissions,
718 JsonType::ARRAY,
719 false,
720 g_parseResult,
721 ArrayType::STRING);
722 // both exported and visible can be configured, but exported has higher priority
723 GetValueIfFindKey<bool>(jsonObject,
724 jsonObjectEnd,
725 VISIBLE,
726 extension.visible,
727 JsonType::BOOLEAN,
728 false,
729 g_parseResult,
730 ArrayType::NOT_ARRAY);
731 GetValueIfFindKey<bool>(jsonObject,
732 jsonObjectEnd,
733 EXPORTED,
734 extension.visible,
735 JsonType::BOOLEAN,
736 false,
737 g_parseResult,
738 ArrayType::NOT_ARRAY);
739 GetValueIfFindKey<std::vector<Metadata>>(jsonObject,
740 jsonObjectEnd,
741 META_DATA,
742 extension.metadata,
743 JsonType::ARRAY,
744 false,
745 g_parseResult,
746 ArrayType::OBJECT);
747 }
748
from_json(const nlohmann::json & jsonObject,DeviceConfig & deviceConfig)749 void from_json(const nlohmann::json &jsonObject, DeviceConfig &deviceConfig)
750 {
751 const auto &jsonObjectEnd = jsonObject.end();
752 if (jsonObject.find(MIN_API_VERSION) != jsonObjectEnd) {
753 deviceConfig.minAPIVersion.first = true;
754 GetValueIfFindKey<int32_t>(jsonObject,
755 jsonObjectEnd,
756 MIN_API_VERSION,
757 deviceConfig.minAPIVersion.second,
758 JsonType::NUMBER,
759 false,
760 g_parseResult,
761 ArrayType::NOT_ARRAY);
762 }
763 if (jsonObject.find(DEVICE_CONFIG_KEEP_ALIVE) != jsonObjectEnd) {
764 deviceConfig.keepAlive.first = true;
765 GetValueIfFindKey<bool>(jsonObject,
766 jsonObjectEnd,
767 DEVICE_CONFIG_KEEP_ALIVE,
768 deviceConfig.keepAlive.second,
769 JsonType::BOOLEAN,
770 false,
771 g_parseResult,
772 ArrayType::NOT_ARRAY);
773 }
774 if (jsonObject.find(DEVICE_CONFIG_REMOVABLE) != jsonObjectEnd) {
775 deviceConfig.removable.first = true;
776 GetValueIfFindKey<bool>(jsonObject,
777 jsonObjectEnd,
778 DEVICE_CONFIG_REMOVABLE,
779 deviceConfig.removable.second,
780 JsonType::BOOLEAN,
781 false,
782 g_parseResult,
783 ArrayType::NOT_ARRAY);
784 }
785 if (jsonObject.find(DEVICE_CONFIG_SINGLETON) != jsonObjectEnd) {
786 deviceConfig.singleton.first = true;
787 GetValueIfFindKey<bool>(jsonObject,
788 jsonObjectEnd,
789 DEVICE_CONFIG_SINGLETON,
790 deviceConfig.singleton.second,
791 JsonType::BOOLEAN,
792 false,
793 g_parseResult,
794 ArrayType::NOT_ARRAY);
795 }
796 if (jsonObject.find(DEVICE_CONFIG_USER_DATA_CLEARABLE) != jsonObjectEnd) {
797 deviceConfig.userDataClearable.first = true;
798 GetValueIfFindKey<bool>(jsonObject,
799 jsonObjectEnd,
800 DEVICE_CONFIG_USER_DATA_CLEARABLE,
801 deviceConfig.userDataClearable.second,
802 JsonType::BOOLEAN,
803 false,
804 g_parseResult,
805 ArrayType::NOT_ARRAY);
806 }
807 if (jsonObject.find(DEVICE_CONFIG_ACCESSIBLE) != jsonObjectEnd) {
808 deviceConfig.accessible.first = true;
809 GetValueIfFindKey<bool>(jsonObject,
810 jsonObjectEnd,
811 DEVICE_CONFIG_ACCESSIBLE,
812 deviceConfig.accessible.second,
813 JsonType::BOOLEAN,
814 false,
815 g_parseResult,
816 ArrayType::NOT_ARRAY);
817 }
818 }
819
from_json(const nlohmann::json & jsonObject,App & app)820 void from_json(const nlohmann::json &jsonObject, App &app)
821 {
822 TAG_LOGD(AAFwkTag::ABILITY_SIM, "read app tag from module.json");
823 const auto &jsonObjectEnd = jsonObject.end();
824 GetValueIfFindKey<std::string>(jsonObject,
825 jsonObjectEnd,
826 APP_BUNDLE_NAME,
827 app.bundleName,
828 JsonType::STRING,
829 true,
830 g_parseResult,
831 ArrayType::NOT_ARRAY);
832 GetValueIfFindKey<std::string>(jsonObject,
833 jsonObjectEnd,
834 ICON,
835 app.icon,
836 JsonType::STRING,
837 true,
838 g_parseResult,
839 ArrayType::NOT_ARRAY);
840 GetValueIfFindKey<std::string>(jsonObject,
841 jsonObjectEnd,
842 LABEL,
843 app.label,
844 JsonType::STRING,
845 true,
846 g_parseResult,
847 ArrayType::NOT_ARRAY);
848 GetValueIfFindKey<int32_t>(jsonObject,
849 jsonObjectEnd,
850 APP_VERSION_CODE,
851 app.versionCode,
852 JsonType::NUMBER,
853 true,
854 g_parseResult,
855 ArrayType::NOT_ARRAY);
856 GetValueIfFindKey<std::string>(jsonObject,
857 jsonObjectEnd,
858 APP_VERSION_NAME,
859 app.versionName,
860 JsonType::STRING,
861 true,
862 g_parseResult,
863 ArrayType::NOT_ARRAY);
864 GetValueIfFindKey<uint32_t>(jsonObject,
865 jsonObjectEnd,
866 APP_MIN_API_VERSION,
867 app.minAPIVersion,
868 JsonType::NUMBER,
869 true,
870 g_parseResult,
871 ArrayType::NOT_ARRAY);
872 GetValueIfFindKey<int32_t>(jsonObject,
873 jsonObjectEnd,
874 APP_TARGET_API_VERSION,
875 app.targetAPIVersion,
876 JsonType::NUMBER,
877 true,
878 g_parseResult,
879 ArrayType::NOT_ARRAY);
880 GetValueIfFindKey<bool>(jsonObject,
881 jsonObjectEnd,
882 APP_DEBUG,
883 app.debug,
884 JsonType::BOOLEAN,
885 false,
886 g_parseResult,
887 ArrayType::NOT_ARRAY);
888 GetValueIfFindKey<int32_t>(jsonObject,
889 jsonObjectEnd,
890 ICON_ID,
891 app.iconId,
892 JsonType::NUMBER,
893 false,
894 g_parseResult,
895 ArrayType::NOT_ARRAY);
896 GetValueIfFindKey<int32_t>(jsonObject,
897 jsonObjectEnd,
898 LABEL_ID,
899 app.labelId,
900 JsonType::NUMBER,
901 false,
902 g_parseResult,
903 ArrayType::NOT_ARRAY);
904 GetValueIfFindKey<std::string>(jsonObject,
905 jsonObjectEnd,
906 DESCRIPTION,
907 app.description,
908 JsonType::STRING,
909 false,
910 g_parseResult,
911 ArrayType::NOT_ARRAY);
912 GetValueIfFindKey<int32_t>(jsonObject,
913 jsonObjectEnd,
914 DESCRIPTION_ID,
915 app.descriptionId,
916 JsonType::NUMBER,
917 false,
918 g_parseResult,
919 ArrayType::NOT_ARRAY);
920 GetValueIfFindKey<std::string>(jsonObject,
921 jsonObjectEnd,
922 APP_VENDOR,
923 app.vendor,
924 JsonType::STRING,
925 false,
926 g_parseResult,
927 ArrayType::NOT_ARRAY);
928 GetValueIfFindKey<int32_t>(jsonObject,
929 jsonObjectEnd,
930 APP_MIN_COMPATIBLE_VERSION_CODE,
931 app.minCompatibleVersionCode,
932 JsonType::NUMBER,
933 false,
934 g_parseResult,
935 ArrayType::NOT_ARRAY);
936 GetValueIfFindKey<std::string>(jsonObject,
937 jsonObjectEnd,
938 APP_API_RELEASETYPE,
939 app.apiReleaseType,
940 JsonType::STRING,
941 false,
942 g_parseResult,
943 ArrayType::NOT_ARRAY);
944 GetValueIfFindKey<bool>(jsonObject,
945 jsonObjectEnd,
946 APP_KEEP_ALIVE,
947 app.keepAlive,
948 JsonType::BOOLEAN,
949 false,
950 g_parseResult,
951 ArrayType::NOT_ARRAY);
952 GetValueIfFindKey<std::vector<std::string>>(jsonObject,
953 jsonObjectEnd,
954 APP_TARGETBUNDLELIST,
955 app.targetBundleList,
956 JsonType::ARRAY,
957 false,
958 g_parseResult,
959 ArrayType::STRING);
960 if (jsonObject.find(APP_REMOVABLE) != jsonObject.end()) {
961 app.removable.first = true;
962 GetValueIfFindKey<bool>(jsonObject,
963 jsonObjectEnd,
964 APP_REMOVABLE,
965 app.removable.second,
966 JsonType::BOOLEAN,
967 false,
968 g_parseResult,
969 ArrayType::NOT_ARRAY);
970 }
971 GetValueIfFindKey<bool>(jsonObject,
972 jsonObjectEnd,
973 APP_SINGLETON,
974 app.singleton,
975 JsonType::BOOLEAN,
976 false,
977 g_parseResult,
978 ArrayType::NOT_ARRAY);
979 GetValueIfFindKey<bool>(jsonObject,
980 jsonObjectEnd,
981 APP_USER_DATA_CLEARABLE,
982 app.userDataClearable,
983 JsonType::BOOLEAN,
984 false,
985 g_parseResult,
986 ArrayType::NOT_ARRAY);
987 GetValueIfFindKey<bool>(jsonObject,
988 jsonObjectEnd,
989 APP_ACCESSIBLE,
990 app.accessible,
991 JsonType::BOOLEAN,
992 false,
993 g_parseResult,
994 ArrayType::NOT_ARRAY);
995 GetValueIfFindKey<bool>(jsonObject,
996 jsonObjectEnd,
997 APP_ASAN_ENABLED,
998 app.asanEnabled,
999 JsonType::BOOLEAN,
1000 false,
1001 g_parseResult,
1002 ArrayType::NOT_ARRAY);
1003 GetValueIfFindKey<std::string>(jsonObject,
1004 jsonObjectEnd,
1005 BUNDLE_TYPE,
1006 app.bundleType,
1007 JsonType::STRING,
1008 false,
1009 g_parseResult,
1010 ArrayType::NOT_ARRAY);
1011 if (jsonObject.find(APP_PHONE) != jsonObjectEnd) {
1012 DeviceConfig deviceConfig;
1013 GetValueIfFindKey<DeviceConfig>(jsonObject,
1014 jsonObjectEnd,
1015 APP_PHONE,
1016 deviceConfig,
1017 JsonType::OBJECT,
1018 false,
1019 g_parseResult,
1020 ArrayType::NOT_ARRAY);
1021 app.deviceConfigs[APP_PHONE] = deviceConfig;
1022 }
1023 if (jsonObject.find(APP_TABLET) != jsonObjectEnd) {
1024 DeviceConfig deviceConfig;
1025 GetValueIfFindKey<DeviceConfig>(jsonObject,
1026 jsonObjectEnd,
1027 APP_TABLET,
1028 deviceConfig,
1029 JsonType::OBJECT,
1030 false,
1031 g_parseResult,
1032 ArrayType::NOT_ARRAY);
1033 app.deviceConfigs[APP_TABLET] = deviceConfig;
1034 }
1035 if (jsonObject.find(APP_TV) != jsonObjectEnd) {
1036 DeviceConfig deviceConfig;
1037 GetValueIfFindKey<DeviceConfig>(jsonObject,
1038 jsonObjectEnd,
1039 APP_TV,
1040 deviceConfig,
1041 JsonType::OBJECT,
1042 false,
1043 g_parseResult,
1044 ArrayType::NOT_ARRAY);
1045 app.deviceConfigs[APP_TV] = deviceConfig;
1046 }
1047 if (jsonObject.find(APP_WEARABLE) != jsonObjectEnd) {
1048 DeviceConfig deviceConfig;
1049 GetValueIfFindKey<DeviceConfig>(jsonObject,
1050 jsonObjectEnd,
1051 APP_WEARABLE,
1052 deviceConfig,
1053 JsonType::OBJECT,
1054 false,
1055 g_parseResult,
1056 ArrayType::NOT_ARRAY);
1057 app.deviceConfigs[APP_WEARABLE] = deviceConfig;
1058 }
1059 if (jsonObject.find(APP_LITE_WEARABLE) != jsonObjectEnd) {
1060 DeviceConfig deviceConfig;
1061 GetValueIfFindKey<DeviceConfig>(jsonObject,
1062 jsonObjectEnd,
1063 APP_LITE_WEARABLE,
1064 deviceConfig,
1065 JsonType::OBJECT,
1066 false,
1067 g_parseResult,
1068 ArrayType::NOT_ARRAY);
1069 app.deviceConfigs[APP_LITE_WEARABLE] = deviceConfig;
1070 }
1071 if (jsonObject.find(APP_CAR) != jsonObjectEnd) {
1072 DeviceConfig deviceConfig;
1073 GetValueIfFindKey<DeviceConfig>(jsonObject,
1074 jsonObjectEnd,
1075 APP_CAR,
1076 deviceConfig,
1077 JsonType::OBJECT,
1078 false,
1079 g_parseResult,
1080 ArrayType::NOT_ARRAY);
1081 app.deviceConfigs[APP_CAR] = deviceConfig;
1082 }
1083 if (jsonObject.find(APP_SMART_VISION) != jsonObjectEnd) {
1084 DeviceConfig deviceConfig;
1085 GetValueIfFindKey<DeviceConfig>(jsonObject,
1086 jsonObjectEnd,
1087 APP_SMART_VISION,
1088 deviceConfig,
1089 JsonType::OBJECT,
1090 false,
1091 g_parseResult,
1092 ArrayType::NOT_ARRAY);
1093 app.deviceConfigs[APP_SMART_VISION] = deviceConfig;
1094 }
1095 if (jsonObject.find(APP_ROUTER) != jsonObjectEnd) {
1096 DeviceConfig deviceConfig;
1097 GetValueIfFindKey<DeviceConfig>(jsonObject,
1098 jsonObjectEnd,
1099 APP_ROUTER,
1100 deviceConfig,
1101 JsonType::OBJECT,
1102 false,
1103 g_parseResult,
1104 ArrayType::NOT_ARRAY);
1105 app.deviceConfigs[APP_ROUTER] = deviceConfig;
1106 }
1107 GetValueIfFindKey<bool>(jsonObject,
1108 jsonObjectEnd,
1109 APP_MULTI_PROJECTS,
1110 app.multiProjects,
1111 JsonType::BOOLEAN,
1112 false,
1113 g_parseResult,
1114 ArrayType::NOT_ARRAY);
1115 GetValueIfFindKey<std::string>(jsonObject,
1116 jsonObjectEnd,
1117 APP_TARGET_BUNDLE_NAME,
1118 app.targetBundle,
1119 JsonType::STRING,
1120 false,
1121 g_parseResult,
1122 ArrayType::NOT_ARRAY);
1123 GetValueIfFindKey<int32_t>(jsonObject,
1124 jsonObjectEnd,
1125 APP_TARGET_PRIORITY,
1126 app.targetPriority,
1127 JsonType::NUMBER,
1128 false,
1129 g_parseResult,
1130 ArrayType::NOT_ARRAY);
1131 GetValueIfFindKey<std::string>(jsonObject,
1132 jsonObjectEnd,
1133 COMPILE_SDK_VERSION,
1134 app.compileSdkVersion,
1135 JsonType::STRING,
1136 false,
1137 g_parseResult,
1138 ArrayType::NOT_ARRAY);
1139 GetValueIfFindKey<std::string>(jsonObject,
1140 jsonObjectEnd,
1141 COMPILE_SDK_TYPE,
1142 app.compileSdkType,
1143 JsonType::STRING,
1144 false,
1145 g_parseResult,
1146 ArrayType::NOT_ARRAY);
1147 }
1148
from_json(const nlohmann::json & jsonObject,Module & module)1149 void from_json(const nlohmann::json &jsonObject, Module &module)
1150 {
1151 TAG_LOGD(AAFwkTag::ABILITY_SIM, "read module tag from module.json");
1152 const auto &jsonObjectEnd = jsonObject.end();
1153 GetValueIfFindKey<std::string>(jsonObject,
1154 jsonObjectEnd,
1155 MODULE_NAME,
1156 module.name,
1157 JsonType::STRING,
1158 true,
1159 g_parseResult,
1160 ArrayType::NOT_ARRAY);
1161 GetValueIfFindKey<std::string>(jsonObject,
1162 jsonObjectEnd,
1163 MODULE_TYPE,
1164 module.type,
1165 JsonType::STRING,
1166 true,
1167 g_parseResult,
1168 ArrayType::NOT_ARRAY);
1169 GetValueIfFindKey<std::vector<std::string>>(jsonObject,
1170 jsonObjectEnd,
1171 MODULE_DEVICE_TYPES,
1172 module.deviceTypes,
1173 JsonType::ARRAY,
1174 true,
1175 g_parseResult,
1176 ArrayType::STRING);
1177 GetValueIfFindKey<bool>(jsonObject,
1178 jsonObjectEnd,
1179 MODULE_DELIVERY_WITH_INSTALL,
1180 module.deliveryWithInstall,
1181 JsonType::BOOLEAN,
1182 true,
1183 g_parseResult,
1184 ArrayType::NOT_ARRAY);
1185 GetValueIfFindKey<std::string>(jsonObject,
1186 jsonObjectEnd,
1187 MODULE_PAGES,
1188 module.pages,
1189 JsonType::STRING,
1190 false,
1191 g_parseResult,
1192 ArrayType::NOT_ARRAY);
1193 // both srcEntry and srcEntrance can be configured, but srcEntry has higher priority
1194 if (jsonObject.find(SRC_ENTRY) != jsonObject.end()) {
1195 GetValueIfFindKey<std::string>(jsonObject,
1196 jsonObjectEnd,
1197 SRC_ENTRY,
1198 module.srcEntrance,
1199 JsonType::STRING,
1200 false,
1201 g_parseResult,
1202 ArrayType::NOT_ARRAY);
1203 } else {
1204 GetValueIfFindKey<std::string>(jsonObject,
1205 jsonObjectEnd,
1206 SRC_ENTRANCE,
1207 module.srcEntrance,
1208 JsonType::STRING,
1209 false,
1210 g_parseResult,
1211 ArrayType::NOT_ARRAY);
1212 }
1213 GetValueIfFindKey<std::string>(jsonObject,
1214 jsonObjectEnd,
1215 DESCRIPTION,
1216 module.description,
1217 JsonType::STRING,
1218 false,
1219 g_parseResult,
1220 ArrayType::NOT_ARRAY);
1221 GetValueIfFindKey<int32_t>(jsonObject,
1222 jsonObjectEnd,
1223 DESCRIPTION_ID,
1224 module.descriptionId,
1225 JsonType::NUMBER,
1226 false,
1227 g_parseResult,
1228 ArrayType::NOT_ARRAY);
1229 GetValueIfFindKey<std::string>(jsonObject,
1230 jsonObjectEnd,
1231 MODULE_PROCESS,
1232 module.process,
1233 JsonType::STRING,
1234 false,
1235 g_parseResult,
1236 ArrayType::NOT_ARRAY);
1237 GetValueIfFindKey<std::string>(jsonObject,
1238 jsonObjectEnd,
1239 MODULE_MAIN_ELEMENT,
1240 module.mainElement,
1241 JsonType::STRING,
1242 false,
1243 g_parseResult,
1244 ArrayType::NOT_ARRAY);
1245 GetValueIfFindKey<bool>(jsonObject,
1246 jsonObjectEnd,
1247 MODULE_INSTALLATION_FREE,
1248 module.installationFree,
1249 JsonType::BOOLEAN,
1250 false,
1251 g_parseResult,
1252 ArrayType::NOT_ARRAY);
1253 GetValueIfFindKey<std::string>(jsonObject,
1254 jsonObjectEnd,
1255 MODULE_VIRTUAL_MACHINE,
1256 module.virtualMachine,
1257 JsonType::STRING,
1258 false,
1259 g_parseResult,
1260 ArrayType::NOT_ARRAY);
1261 GetValueIfFindKey<std::vector<Metadata>>(jsonObject,
1262 jsonObjectEnd,
1263 META_DATA,
1264 module.metadata,
1265 JsonType::ARRAY,
1266 false,
1267 g_parseResult,
1268 ArrayType::OBJECT);
1269 GetValueIfFindKey<std::vector<Ability>>(jsonObject,
1270 jsonObjectEnd,
1271 MODULE_ABILITIES,
1272 module.abilities,
1273 JsonType::ARRAY,
1274 false,
1275 g_parseResult,
1276 ArrayType::OBJECT);
1277 GetValueIfFindKey<std::vector<Extension>>(jsonObject,
1278 jsonObjectEnd,
1279 MODULE_EXTENSION_ABILITIES,
1280 module.extensionAbilities,
1281 JsonType::ARRAY,
1282 false,
1283 g_parseResult,
1284 ArrayType::OBJECT);
1285 GetValueIfFindKey<std::vector<Dependency>>(jsonObject,
1286 jsonObjectEnd,
1287 MODULE_DEPENDENCIES,
1288 module.dependencies,
1289 JsonType::ARRAY,
1290 false,
1291 g_parseResult,
1292 ArrayType::OBJECT);
1293 GetValueIfFindKey<std::string>(jsonObject,
1294 jsonObjectEnd,
1295 MODULE_COMPILE_MODE,
1296 module.compileMode,
1297 JsonType::STRING,
1298 false,
1299 g_parseResult,
1300 ArrayType::NOT_ARRAY);
1301 GetValueIfFindKey<bool>(jsonObject,
1302 jsonObjectEnd,
1303 MODULE_IS_LIB_ISOLATED,
1304 module.isLibIsolated,
1305 JsonType::BOOLEAN,
1306 false,
1307 g_parseResult,
1308 ArrayType::NOT_ARRAY);
1309 GetValueIfFindKey<std::string>(jsonObject,
1310 jsonObjectEnd,
1311 MODULE_TARGET_MODULE_NAME,
1312 module.targetModule,
1313 JsonType::STRING,
1314 false,
1315 g_parseResult,
1316 ArrayType::NOT_ARRAY);
1317 GetValueIfFindKey<int32_t>(jsonObject,
1318 jsonObjectEnd,
1319 MODULE_TARGET_PRIORITY,
1320 module.targetPriority,
1321 JsonType::NUMBER,
1322 false,
1323 g_parseResult,
1324 ArrayType::NOT_ARRAY);
1325 GetValueIfFindKey<std::vector<ProxyData>>(jsonObject,
1326 jsonObjectEnd,
1327 MODULE_PROXY_DATAS,
1328 module.proxyDatas,
1329 JsonType::ARRAY,
1330 false,
1331 g_parseResult,
1332 ArrayType::OBJECT);
1333 GetValueIfFindKey<std::vector<ProxyData>>(jsonObject,
1334 jsonObjectEnd,
1335 MODULE_PROXY_DATA,
1336 module.proxyData,
1337 JsonType::ARRAY,
1338 false,
1339 g_parseResult,
1340 ArrayType::OBJECT);
1341 GetValueIfFindKey<std::string>(jsonObject,
1342 jsonObjectEnd,
1343 MODULE_BUILD_HASH,
1344 module.buildHash,
1345 JsonType::STRING,
1346 false,
1347 g_parseResult,
1348 ArrayType::NOT_ARRAY);
1349 GetValueIfFindKey<std::string>(jsonObject,
1350 jsonObjectEnd,
1351 MODULE_ISOLATION_MODE,
1352 module.isolationMode,
1353 JsonType::STRING,
1354 false,
1355 g_parseResult,
1356 ArrayType::NOT_ARRAY);
1357 }
1358
from_json(const nlohmann::json & jsonObject,ModuleJson & moduleJson)1359 void from_json(const nlohmann::json &jsonObject, ModuleJson &moduleJson)
1360 {
1361 const auto &jsonObjectEnd = jsonObject.end();
1362 GetValueIfFindKey<App>(jsonObject,
1363 jsonObjectEnd,
1364 APP,
1365 moduleJson.app,
1366 JsonType::OBJECT,
1367 true,
1368 g_parseResult,
1369 ArrayType::NOT_ARRAY);
1370 GetValueIfFindKey<Module>(jsonObject,
1371 jsonObjectEnd,
1372 MODULE,
1373 moduleJson.module,
1374 JsonType::OBJECT,
1375 true,
1376 g_parseResult,
1377 ArrayType::NOT_ARRAY);
1378 }
1379 } // namespace Profile
1380
1381 namespace {
1382 struct TransformParam {
1383 bool isSystemApp = false;
1384 bool isPreInstallApp = false;
1385 };
1386
GetMetadata(std::vector<Metadata> & metadata,const std::vector<Profile::Metadata> & profileMetadata)1387 void GetMetadata(std::vector<Metadata> &metadata, const std::vector<Profile::Metadata> &profileMetadata)
1388 {
1389 for (const Profile::Metadata &item : profileMetadata) {
1390 Metadata tmpMetadata;
1391 tmpMetadata.name = item.name;
1392 tmpMetadata.value = item.value;
1393 tmpMetadata.resource = item.resource;
1394 metadata.emplace_back(tmpMetadata);
1395 }
1396 }
1397
CheckBundleNameIsValid(const std::string & bundleName)1398 bool CheckBundleNameIsValid(const std::string &bundleName)
1399 {
1400 if (bundleName.empty()) {
1401 return false;
1402 }
1403 if (bundleName.size() < Constants::MIN_BUNDLE_NAME || bundleName.size() > Constants::MAX_BUNDLE_NAME) {
1404 return false;
1405 }
1406 char head = bundleName.at(0);
1407 if (!isalpha(head)) {
1408 return false;
1409 }
1410 for (const auto &c : bundleName) {
1411 if (!isalnum(c) && (c != '.') && (c != '_')) {
1412 return false;
1413 }
1414 }
1415 return true;
1416 }
1417
CheckModuleNameIsValid(const std::string & moduleName)1418 bool CheckModuleNameIsValid(const std::string &moduleName)
1419 {
1420 if (moduleName.empty()) {
1421 return false;
1422 }
1423 if (moduleName.size() > Constants::MAX_MODULE_NAME) {
1424 return false;
1425 }
1426 if (moduleName.find(Constants::RELATIVE_PATH) != std::string::npos) {
1427 return false;
1428 }
1429 if (moduleName.find(Constants::MODULE_NAME_SEPARATOR) != std::string::npos) {
1430 TAG_LOGE(AAFwkTag::ABILITY_SIM, "module name contain");
1431 return false;
1432 }
1433 return true;
1434 }
1435
GetResource(const std::string & bundleName,const std::string & moduleName,int32_t resId)1436 Resource GetResource(const std::string &bundleName, const std::string &moduleName, int32_t resId)
1437 {
1438 Resource resource;
1439 resource.bundleName = bundleName;
1440 resource.moduleName = moduleName;
1441 resource.id = resId;
1442 return resource;
1443 }
1444
ToApplicationInfo(const Profile::ModuleJson & moduleJson,const TransformParam & transformParam,ApplicationInfo & applicationInfo)1445 bool ToApplicationInfo(
1446 const Profile::ModuleJson &moduleJson,
1447 const TransformParam &transformParam,
1448 ApplicationInfo &applicationInfo)
1449 {
1450 TAG_LOGD(AAFwkTag::ABILITY_SIM, "transform ModuleJson to ApplicationInfo");
1451 auto app = moduleJson.app;
1452 applicationInfo.name = app.bundleName;
1453 applicationInfo.bundleName = app.bundleName;
1454
1455 applicationInfo.versionCode = static_cast<uint32_t>(app.versionCode);
1456 applicationInfo.versionName = app.versionName;
1457 if (app.minCompatibleVersionCode != -1) {
1458 applicationInfo.minCompatibleVersionCode = app.minCompatibleVersionCode;
1459 } else {
1460 applicationInfo.minCompatibleVersionCode = static_cast<int32_t>(applicationInfo.versionCode);
1461 }
1462
1463 applicationInfo.apiCompatibleVersion = app.minAPIVersion;
1464 applicationInfo.apiTargetVersion = app.targetAPIVersion;
1465
1466 applicationInfo.iconPath = app.icon;
1467 applicationInfo.iconId = app.iconId;
1468 applicationInfo.label = app.label;
1469 applicationInfo.labelId = app.labelId;
1470 applicationInfo.description = app.description;
1471 applicationInfo.descriptionId = app.descriptionId;
1472 applicationInfo.iconResource = GetResource(app.bundleName, moduleJson.module.name, app.iconId);
1473 applicationInfo.labelResource = GetResource(app.bundleName, moduleJson.module.name, app.labelId);
1474 applicationInfo.descriptionResource = GetResource(app.bundleName, moduleJson.module.name, app.descriptionId);
1475 applicationInfo.targetBundleList = app.targetBundleList;
1476
1477 if (transformParam.isSystemApp && transformParam.isPreInstallApp) {
1478 applicationInfo.keepAlive = app.keepAlive;
1479 applicationInfo.singleton = app.singleton;
1480 applicationInfo.userDataClearable = app.userDataClearable;
1481 if (app.removable.first) {
1482 applicationInfo.removable = app.removable.second;
1483 } else {
1484 applicationInfo.removable = false;
1485 }
1486 applicationInfo.accessible = app.accessible;
1487 }
1488
1489 applicationInfo.apiReleaseType = app.apiReleaseType;
1490 applicationInfo.debug = app.debug;
1491 applicationInfo.deviceId = Constants::CURRENT_DEVICE_ID;
1492 applicationInfo.distributedNotificationEnabled = true;
1493 applicationInfo.entityType = Profile::APP_ENTITY_TYPE_DEFAULT_VALUE;
1494 applicationInfo.vendor = app.vendor;
1495 applicationInfo.asanEnabled = app.asanEnabled;
1496 if (app.bundleType == Profile::BUNDLE_TYPE_ATOMIC_SERVICE) {
1497 applicationInfo.bundleType = BundleType::ATOMIC_SERVICE;
1498 }
1499
1500 applicationInfo.enabled = true;
1501 applicationInfo.multiProjects = app.multiProjects;
1502 applicationInfo.process = app.bundleName;
1503 applicationInfo.targetBundleName = app.targetBundle;
1504 applicationInfo.targetPriority = app.targetPriority;
1505
1506 auto iterBundleType = std::find_if(std::begin(Profile::BUNDLE_TYPE_MAP),
1507 std::end(Profile::BUNDLE_TYPE_MAP),
1508 [&app](const auto &item) { return item.first == app.bundleType; });
1509 if (iterBundleType != Profile::BUNDLE_TYPE_MAP.end()) {
1510 applicationInfo.bundleType = iterBundleType->second;
1511 }
1512 applicationInfo.compileSdkVersion = app.compileSdkVersion;
1513 applicationInfo.compileSdkType = app.compileSdkType;
1514 return true;
1515 }
1516
GetBackgroundModes(const std::vector<std::string> & backgroundModes)1517 uint32_t GetBackgroundModes(const std::vector<std::string> &backgroundModes)
1518 {
1519 uint32_t backgroundMode = 0;
1520 for (const std::string &item : backgroundModes) {
1521 if (Profile::BACKGROUND_MODES_MAP.find(item) != Profile::BACKGROUND_MODES_MAP.end()) {
1522 backgroundMode |= Profile::BACKGROUND_MODES_MAP.at(item);
1523 }
1524 }
1525 return backgroundMode;
1526 }
1527
ConvertCompileMode(const std::string & compileMode)1528 inline CompileMode ConvertCompileMode(const std::string& compileMode)
1529 {
1530 if (compileMode == Profile::COMPILE_MODE_ES_MODULE) {
1531 return CompileMode::ES_MODULE;
1532 } else {
1533 return CompileMode::JS_BUNDLE;
1534 }
1535 }
1536
ConvertToAbilityWindowMode(const std::vector<std::string> & windowModes,const std::unordered_map<std::string,SupportWindowMode> & windowMap)1537 std::set<SupportWindowMode> ConvertToAbilityWindowMode(const std::vector<std::string> &windowModes,
1538 const std::unordered_map<std::string, SupportWindowMode> &windowMap)
1539 {
1540 std::set<SupportWindowMode> modes;
1541 for_each(windowModes.begin(), windowModes.end(),
1542 [&windowMap, &modes](const auto &mode)->decltype(auto) {
1543 if (windowMap.find(mode) != windowMap.end()) {
1544 modes.emplace(windowMap.at(mode));
1545 }
1546 });
1547 if (modes.empty()) {
1548 modes.insert(SupportWindowMode::FULLSCREEN);
1549 modes.insert(SupportWindowMode::SPLIT);
1550 modes.insert(SupportWindowMode::FLOATING);
1551 }
1552 return modes;
1553 }
1554
ToAbilityInfo(const Profile::ModuleJson & moduleJson,const Profile::Ability & ability,const TransformParam & transformParam,AbilityInfo & abilityInfo)1555 bool ToAbilityInfo(
1556 const Profile::ModuleJson &moduleJson,
1557 const Profile::Ability &ability,
1558 const TransformParam &transformParam,
1559 AbilityInfo &abilityInfo)
1560 {
1561 TAG_LOGD(AAFwkTag::ABILITY_SIM, "transform ModuleJson to AbilityInfo");
1562 abilityInfo.name = ability.name;
1563 abilityInfo.srcEntrance = ability.srcEntrance;
1564 abilityInfo.description = ability.description;
1565 abilityInfo.descriptionId = ability.descriptionId;
1566 abilityInfo.iconPath = ability.icon;
1567 abilityInfo.iconId = ability.iconId;
1568 abilityInfo.label = ability.label;
1569 abilityInfo.labelId = ability.labelId;
1570 abilityInfo.priority = ability.priority;
1571 abilityInfo.excludeFromMissions = ability.excludeFromMissions;
1572 abilityInfo.unclearableMission = ability.unclearableMission;
1573 abilityInfo.recoverable = ability.recoverable;
1574 abilityInfo.permissions = ability.permissions;
1575 abilityInfo.visible = ability.visible;
1576 abilityInfo.continuable = ability.continuable;
1577 abilityInfo.backgroundModes = GetBackgroundModes(ability.backgroundModes);
1578 GetMetadata(abilityInfo.metadata, ability.metadata);
1579 abilityInfo.package = moduleJson.module.name;
1580 abilityInfo.bundleName = moduleJson.app.bundleName;
1581 abilityInfo.moduleName = moduleJson.module.name;
1582 abilityInfo.applicationName = moduleJson.app.bundleName;
1583 auto iterLaunch = std::find_if(std::begin(Profile::LAUNCH_MODE_MAP),
1584 std::end(Profile::LAUNCH_MODE_MAP),
1585 [&ability](const auto &item) { return item.first == ability.launchType; });
1586 if (iterLaunch != Profile::LAUNCH_MODE_MAP.end()) {
1587 abilityInfo.launchMode = iterLaunch->second;
1588 }
1589 abilityInfo.enabled = true;
1590 abilityInfo.isModuleJson = true;
1591 abilityInfo.isStageBasedModel = true;
1592 abilityInfo.type = AbilityType::PAGE;
1593 for (const std::string &deviceType : moduleJson.module.deviceTypes) {
1594 abilityInfo.deviceTypes.emplace_back(deviceType);
1595 }
1596 abilityInfo.startWindowIcon = ability.startWindowIcon;
1597 abilityInfo.startWindowIconId = ability.startWindowIconId;
1598 abilityInfo.startWindowBackground = ability.startWindowBackground;
1599 abilityInfo.startWindowBackgroundId = ability.startWindowBackgroundId;
1600 abilityInfo.removeMissionAfterTerminate = ability.removeMissionAfterTerminate;
1601 abilityInfo.compileMode = ConvertCompileMode(moduleJson.module.compileMode);
1602 auto iterOrientation = std::find_if(std::begin(Profile::DISPLAY_ORIENTATION_MAP),
1603 std::end(Profile::DISPLAY_ORIENTATION_MAP),
1604 [&ability](const auto &item) { return item.first == ability.orientation; });
1605 if (iterOrientation != Profile::DISPLAY_ORIENTATION_MAP.end()) {
1606 abilityInfo.orientation = iterOrientation->second;
1607 }
1608
1609 auto modesSet = ConvertToAbilityWindowMode(ability.windowModes, Profile::WINDOW_MODE_MAP);
1610 abilityInfo.windowModes.assign(modesSet.begin(), modesSet.end());
1611 abilityInfo.maxWindowRatio = ability.maxWindowRatio;
1612 abilityInfo.minWindowRatio = ability.minWindowRatio;
1613 abilityInfo.maxWindowWidth = ability.maxWindowWidth;
1614 abilityInfo.minWindowWidth = ability.minWindowWidth;
1615 abilityInfo.maxWindowHeight = ability.maxWindowHeight;
1616 abilityInfo.minWindowHeight = ability.minWindowHeight;
1617 return true;
1618 }
1619
ToExtensionInfo(const Profile::ModuleJson & moduleJson,const Profile::Extension & extension,const TransformParam & transformParam,ExtensionAbilityInfo & extensionInfo)1620 bool ToExtensionInfo(
1621 const Profile::ModuleJson &moduleJson,
1622 const Profile::Extension &extension,
1623 const TransformParam &transformParam,
1624 ExtensionAbilityInfo &extensionInfo)
1625 {
1626 TAG_LOGD(AAFwkTag::ABILITY_SIM, "transform ModuleJson to ExtensionAbilityInfo");
1627 extensionInfo.type = ConvertToExtensionAbilityType(extension.type);
1628 extensionInfo.name = extension.name;
1629 extensionInfo.srcEntrance = extension.srcEntrance;
1630 extensionInfo.icon = extension.icon;
1631 extensionInfo.iconId = extension.iconId;
1632 extensionInfo.label = extension.label;
1633 extensionInfo.labelId = extension.labelId;
1634 extensionInfo.description = extension.description;
1635 extensionInfo.descriptionId = extension.descriptionId;
1636 if (transformParam.isSystemApp && transformParam.isPreInstallApp) {
1637 extensionInfo.readPermission = extension.readPermission;
1638 extensionInfo.writePermission = extension.writePermission;
1639 }
1640 extensionInfo.priority = extension.priority;
1641 extensionInfo.uri = extension.uri;
1642 extensionInfo.permissions = extension.permissions;
1643 extensionInfo.visible = extension.visible;
1644 GetMetadata(extensionInfo.metadata, extension.metadata);
1645 extensionInfo.bundleName = moduleJson.app.bundleName;
1646 extensionInfo.moduleName = moduleJson.module.name;
1647
1648 if (extensionInfo.type != ExtensionAbilityType::SERVICE &&
1649 extensionInfo.type != ExtensionAbilityType::DATASHARE) {
1650 extensionInfo.process = extensionInfo.bundleName;
1651 extensionInfo.process.append(":");
1652 extensionInfo.process.append(ConvertToExtensionTypeName(extensionInfo.type));
1653 }
1654
1655 extensionInfo.compileMode = ConvertCompileMode(moduleJson.module.compileMode);
1656
1657 return true;
1658 }
1659
ToInnerModuleInfo(const Profile::ModuleJson & moduleJson,const TransformParam & transformParam,InnerModuleInfo & innerModuleInfo)1660 bool ToInnerModuleInfo(
1661 const Profile::ModuleJson &moduleJson,
1662 const TransformParam &transformParam,
1663 InnerModuleInfo &innerModuleInfo)
1664 {
1665 TAG_LOGD(AAFwkTag::ABILITY_SIM, "transform ModuleJson to InnerModuleInfo");
1666 innerModuleInfo.name = moduleJson.module.name;
1667 innerModuleInfo.modulePackage = moduleJson.module.name;
1668 innerModuleInfo.moduleName = moduleJson.module.name;
1669 innerModuleInfo.description = moduleJson.module.description;
1670 innerModuleInfo.descriptionId = moduleJson.module.descriptionId;
1671 GetMetadata(innerModuleInfo.metadata, moduleJson.module.metadata);
1672 innerModuleInfo.distro.deliveryWithInstall = moduleJson.module.deliveryWithInstall;
1673 innerModuleInfo.distro.installationFree = moduleJson.module.installationFree;
1674 innerModuleInfo.distro.moduleName = moduleJson.module.name;
1675 innerModuleInfo.installationFree = moduleJson.module.installationFree;
1676 if (Profile::MODULE_TYPE_SET.find(moduleJson.module.type) != Profile::MODULE_TYPE_SET.end()) {
1677 innerModuleInfo.distro.moduleType = moduleJson.module.type;
1678 if (moduleJson.module.type == Profile::MODULE_TYPE_ENTRY) {
1679 innerModuleInfo.isEntry = true;
1680 }
1681 }
1682
1683 innerModuleInfo.mainAbility = moduleJson.module.mainElement;
1684 innerModuleInfo.srcEntrance = moduleJson.module.srcEntrance;
1685 innerModuleInfo.process = moduleJson.module.process;
1686
1687 for (const std::string &deviceType : moduleJson.module.deviceTypes) {
1688 innerModuleInfo.deviceTypes.emplace_back(deviceType);
1689 }
1690
1691 if (Profile::VIRTUAL_MACHINE_SET.find(moduleJson.module.virtualMachine) != Profile::VIRTUAL_MACHINE_SET.end()) {
1692 innerModuleInfo.virtualMachine = moduleJson.module.virtualMachine;
1693 }
1694
1695 innerModuleInfo.uiSyntax = Profile::MODULE_UI_SYNTAX_DEFAULT_VALUE;
1696 innerModuleInfo.pages = moduleJson.module.pages;
1697 innerModuleInfo.dependencies = moduleJson.module.dependencies;
1698 innerModuleInfo.compileMode = moduleJson.module.compileMode;
1699 innerModuleInfo.isModuleJson = true;
1700 innerModuleInfo.isStageBasedModel = true;
1701 innerModuleInfo.isLibIsolated = moduleJson.module.isLibIsolated;
1702 innerModuleInfo.targetModuleName = moduleJson.module.targetModule;
1703 innerModuleInfo.targetPriority = moduleJson.module.targetPriority;
1704 if (moduleJson.module.proxyDatas.empty()) {
1705 innerModuleInfo.proxyDatas = moduleJson.module.proxyData;
1706 } else {
1707 innerModuleInfo.proxyDatas = moduleJson.module.proxyDatas;
1708 }
1709 innerModuleInfo.buildHash = moduleJson.module.buildHash;
1710 innerModuleInfo.isolationMode = moduleJson.module.isolationMode;
1711 return true;
1712 }
1713
SetInstallationFree(InnerModuleInfo & innerModuleInfo,BundleType bundleType)1714 void SetInstallationFree(InnerModuleInfo &innerModuleInfo, BundleType bundleType)
1715 {
1716 if (bundleType == BundleType::ATOMIC_SERVICE) {
1717 innerModuleInfo.distro.installationFree = true;
1718 innerModuleInfo.installationFree = true;
1719 } else {
1720 innerModuleInfo.distro.installationFree = false;
1721 innerModuleInfo.installationFree = false;
1722 }
1723 }
1724
ToBundleInfo(const ApplicationInfo & applicationInfo,const InnerModuleInfo & innerModuleInfo,const TransformParam & transformParam,BundleInfo & bundleInfo)1725 void ToBundleInfo(const ApplicationInfo &applicationInfo, const InnerModuleInfo &innerModuleInfo,
1726 const TransformParam &transformParam, BundleInfo &bundleInfo)
1727 {
1728 bundleInfo.name = applicationInfo.bundleName;
1729
1730 bundleInfo.versionCode = static_cast<uint32_t>(applicationInfo.versionCode);
1731 bundleInfo.versionName = applicationInfo.versionName;
1732 bundleInfo.minCompatibleVersionCode = static_cast<uint32_t>(applicationInfo.minCompatibleVersionCode);
1733
1734 bundleInfo.compatibleVersion = static_cast<uint32_t>(applicationInfo.apiCompatibleVersion);
1735 bundleInfo.targetVersion = static_cast<uint32_t>(applicationInfo.apiTargetVersion);
1736
1737 bundleInfo.isKeepAlive = applicationInfo.keepAlive;
1738 bundleInfo.singleton = applicationInfo.singleton;
1739 bundleInfo.isPreInstallApp = transformParam.isPreInstallApp;
1740
1741 bundleInfo.vendor = applicationInfo.vendor;
1742 bundleInfo.releaseType = applicationInfo.apiReleaseType;
1743 bundleInfo.isNativeApp = false;
1744
1745 if (innerModuleInfo.isEntry) {
1746 bundleInfo.mainEntry = innerModuleInfo.moduleName;
1747 bundleInfo.entryModuleName = innerModuleInfo.moduleName;
1748 }
1749 }
1750
ParseExtensionInfo(const Profile::ModuleJson & moduleJson,InnerBundleInfo & innerBundleInfo,const TransformParam & transformParam,InnerModuleInfo & innerModuleInfo)1751 bool ParseExtensionInfo(const Profile::ModuleJson &moduleJson, InnerBundleInfo &innerBundleInfo,
1752 const TransformParam &transformParam, InnerModuleInfo &innerModuleInfo)
1753 {
1754 for (const Profile::Extension &extension : moduleJson.module.extensionAbilities) {
1755 ExtensionAbilityInfo extensionInfo;
1756 if (!ToExtensionInfo(moduleJson, extension, transformParam, extensionInfo)) {
1757 TAG_LOGE(AAFwkTag::ABILITY_SIM, "extensionInfo failed");
1758 return false;
1759 }
1760
1761 if (innerModuleInfo.mainAbility == extensionInfo.name) {
1762 innerModuleInfo.icon = extensionInfo.icon;
1763 innerModuleInfo.iconId = extensionInfo.iconId;
1764 innerModuleInfo.label = extensionInfo.label;
1765 innerModuleInfo.labelId = extensionInfo.labelId;
1766 }
1767
1768 std::string key;
1769 key.append(moduleJson.app.bundleName).append(".")
1770 .append(moduleJson.module.name).append(".").append(extension.name);
1771 innerModuleInfo.extensionKeys.emplace_back(key);
1772 innerBundleInfo.InsertExtensionInfo(key, extensionInfo);
1773 }
1774 return true;
1775 }
1776
ToInnerBundleInfo(const Profile::ModuleJson & moduleJson,InnerBundleInfo & innerBundleInfo)1777 bool ToInnerBundleInfo(const Profile::ModuleJson &moduleJson, InnerBundleInfo &innerBundleInfo)
1778 {
1779 if (!CheckBundleNameIsValid(moduleJson.app.bundleName) || !CheckModuleNameIsValid(moduleJson.module.name)) {
1780 return false;
1781 }
1782 TransformParam transformParam;
1783 ApplicationInfo applicationInfo;
1784 applicationInfo.isSystemApp = innerBundleInfo.GetAppType() == Constants::AppType::SYSTEM_APP;
1785 transformParam.isSystemApp = applicationInfo.isSystemApp;
1786 if (!ToApplicationInfo(moduleJson, transformParam, applicationInfo)) {
1787 return false;
1788 }
1789 InnerModuleInfo innerModuleInfo;
1790 ToInnerModuleInfo(moduleJson, transformParam, innerModuleInfo);
1791 SetInstallationFree(innerModuleInfo, applicationInfo.bundleType);
1792
1793 BundleInfo bundleInfo;
1794 ToBundleInfo(applicationInfo, innerModuleInfo, transformParam, bundleInfo);
1795
1796 for (const Profile::Ability &ability : moduleJson.module.abilities) {
1797 AbilityInfo abilityInfo;
1798 ToAbilityInfo(moduleJson, ability, transformParam, abilityInfo);
1799 if (innerModuleInfo.mainAbility == abilityInfo.name) {
1800 innerModuleInfo.icon = abilityInfo.iconPath;
1801 innerModuleInfo.iconId = abilityInfo.iconId;
1802 innerModuleInfo.label = abilityInfo.label;
1803 innerModuleInfo.labelId = abilityInfo.labelId;
1804 }
1805 std::string key;
1806 key.append(moduleJson.app.bundleName).append(".")
1807 .append(moduleJson.module.name).append(".").append(abilityInfo.name);
1808 innerModuleInfo.abilityKeys.emplace_back(key);
1809 innerBundleInfo.InsertAbilitiesInfo(key, abilityInfo);
1810 }
1811 if (!ParseExtensionInfo(moduleJson, innerBundleInfo, transformParam, innerModuleInfo)) {
1812 return false;
1813 }
1814 if (!transformParam.isPreInstallApp &&
1815 innerModuleInfo.distro.moduleType != Profile::MODULE_TYPE_SHARED) {
1816 applicationInfo.needAppDetail = true;
1817 applicationInfo.appDetailAbilityLibraryPath = Profile::APP_DETAIL_ABILITY_LIBRARY_PATH;
1818 if ((applicationInfo.labelId == 0) && (applicationInfo.label.empty())) {
1819 applicationInfo.label = applicationInfo.bundleName;
1820 }
1821 }
1822 innerBundleInfo.SetCurrentModulePackage(moduleJson.module.name);
1823 innerBundleInfo.SetBaseApplicationInfo(applicationInfo);
1824 innerBundleInfo.SetBaseBundleInfo(bundleInfo);
1825 innerBundleInfo.InsertInnerModuleInfo(moduleJson.module.name, innerModuleInfo);
1826 innerBundleInfo.SetTargetPriority(moduleJson.app.targetPriority);
1827 return true;
1828 }
1829
ParserAtomicModuleConfig(const nlohmann::json & jsonObject,InnerBundleInfo & innerBundleInfo)1830 bool ParserAtomicModuleConfig(const nlohmann::json &jsonObject, InnerBundleInfo &innerBundleInfo)
1831 {
1832 nlohmann::json moduleJson = jsonObject.at(Profile::MODULE);
1833 std::vector<std::string> preloads;
1834 std::string moduleName = moduleJson.at(Profile::MODULE_NAME);
1835 if (moduleJson.contains(Profile::ATOMIC_SERVICE)) {
1836 nlohmann::json moduleAtomicObj = moduleJson.at(Profile::ATOMIC_SERVICE);
1837 if (moduleAtomicObj.contains(Profile::MODULE_ATOMIC_SERVICE_PRELOADS)) {
1838 nlohmann::json preloadObj = moduleAtomicObj.at(Profile::MODULE_ATOMIC_SERVICE_PRELOADS);
1839 if (preloadObj.empty()) {
1840 TAG_LOGE(AAFwkTag::ABILITY_SIM, "reloadObj is empty");
1841 return true;
1842 }
1843 if (preloadObj.size() > Constants::MAX_JSON_ARRAY_LENGTH) {
1844 TAG_LOGE(AAFwkTag::ABILITY_SIM, "preloads config in module.json is oversize");
1845 return false;
1846 }
1847 for (const auto &preload : preloadObj) {
1848 if (preload.contains(Profile::PRELOADS_MODULE_NAME)) {
1849 std::string preloadName = preload.at(Profile::PRELOADS_MODULE_NAME);
1850 preloads.emplace_back(preloadName);
1851 } else {
1852 TAG_LOGE(AAFwkTag::ABILITY_SIM, "preloads must have moduleName");
1853 return false;
1854 }
1855 }
1856 }
1857 }
1858 innerBundleInfo.SetInnerModuleAtomicPreload(moduleName, preloads);
1859 return true;
1860 }
1861
ParserAtomicConfig(const nlohmann::json & jsonObject,InnerBundleInfo & innerBundleInfo)1862 bool ParserAtomicConfig(const nlohmann::json &jsonObject, InnerBundleInfo &innerBundleInfo)
1863 {
1864 if (!jsonObject.contains(Profile::MODULE) || !jsonObject.contains(Profile::APP)) {
1865 TAG_LOGE(AAFwkTag::ABILITY_SIM, "ParserAtomicConfig failed due to bad module.json");
1866 return false;
1867 }
1868 nlohmann::json appJson = jsonObject.at(Profile::APP);
1869 nlohmann::json moduleJson = jsonObject.at(Profile::MODULE);
1870 if (!moduleJson.is_object() || !appJson.is_object()) {
1871 TAG_LOGE(AAFwkTag::ABILITY_SIM, "module.json file lacks of invalid module or app properties");
1872 return false;
1873 }
1874 BundleType bundleType = BundleType::APP;
1875 if (appJson.contains(Profile::BUNDLE_TYPE)) {
1876 if (appJson.at(Profile::BUNDLE_TYPE) == Profile::BUNDLE_TYPE_ATOMIC_SERVICE) {
1877 bundleType = BundleType::ATOMIC_SERVICE;
1878 } else if (appJson.at(Profile::BUNDLE_TYPE) == Profile::BUNDLE_TYPE_SHARED) {
1879 bundleType = BundleType::SHARED;
1880 } else if (appJson.at(Profile::BUNDLE_TYPE) == Profile::BUNDLE_TYPE_APP_SERVICE_FWK) {
1881 bundleType = BundleType::APP_SERVICE_FWK;
1882 } else if (appJson.at(Profile::BUNDLE_TYPE) == Profile::BUNDLE_TYPE_PLUGIN) {
1883 bundleType = BundleType::APP_PLUGIN;
1884 }
1885 }
1886
1887 innerBundleInfo.SetApplicationBundleType(bundleType);
1888 if (!ParserAtomicModuleConfig(jsonObject, innerBundleInfo)) {
1889 TAG_LOGE(AAFwkTag::ABILITY_SIM, "parse module atomicService failed");
1890 return false;
1891 }
1892 return true;
1893 }
1894 } // namespace
1895
TransformTo(const std::vector<uint8_t> & buf,InnerBundleInfo & innerBundleInfo) const1896 ErrCode ModuleProfile::TransformTo(const std::vector<uint8_t> &buf, InnerBundleInfo &innerBundleInfo) const
1897 {
1898 TAG_LOGD(AAFwkTag::ABILITY_SIM, "transform module.json stream to InnerBundleInfo");
1899 std::vector<uint8_t> buffer = buf;
1900 buffer.push_back('\0');
1901 nlohmann::json jsonObject = nlohmann::json::parse(buffer.data(), nullptr, false);
1902 if (jsonObject.is_discarded()) {
1903 TAG_LOGE(AAFwkTag::ABILITY_SIM, "bad profile");
1904 return ERR_APPEXECFWK_PARSE_BAD_PROFILE;
1905 }
1906
1907 Profile::ModuleJson moduleJson = jsonObject.get<Profile::ModuleJson>();
1908 if (Profile::g_parseResult != ERR_OK) {
1909 TAG_LOGE(AAFwkTag::ABILITY_SIM, "g_parseResult:%{public}d", Profile::g_parseResult);
1910 int32_t ret = Profile::g_parseResult;
1911 // need recover parse result to ERR_OK
1912 Profile::g_parseResult = ERR_OK;
1913 return ret;
1914 }
1915
1916 if (!ToInnerBundleInfo(moduleJson, innerBundleInfo)) {
1917 return ERR_APPEXECFWK_PARSE_PROFILE_PROP_CHECK_ERROR;
1918 }
1919
1920 if (!ParserAtomicConfig(jsonObject, innerBundleInfo)) {
1921 TAG_LOGE(AAFwkTag::ABILITY_SIM, "Parser atomicService config failed");
1922 return ERR_APPEXECFWK_PARSE_PROFILE_PROP_CHECK_ERROR;
1923 }
1924
1925 return ERR_OK;
1926 }
1927 } // namespace AppExecFwk
1928 } // namespace OHOS
1929