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