1/* 2 * Copyright (c) 2021-2023 Huawei Device Co., Ltd. 3 * Licensed under the Apache License, Version 2.0 (the "License"); 4 * you may not use this file except in compliance with the License. 5 * You may obtain a copy of the License at 6 * 7 * http://www.apache.org/licenses/LICENSE-2.0 8 * 9 * Unless required by applicable law or agreed to in writing, software 10 * distributed under the License is distributed on an "AS IS" BASIS, 11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 * See the License for the specific language governing permissions and 13 * limitations under the License. 14 */ 15 16#include "bundle_profile.h" 17 18#include <sstream> 19#include <unordered_map> 20#include <unordered_set> 21 22#include "parameter.h" 23 24namespace OHOS { 25namespace AppExecFwk { 26namespace ProfileReader { 27int32_t g_parseResult = ERR_OK; 28std::mutex g_mutex; 29 30const std::unordered_set<std::string> MODULE_TYPE_SET = { 31 "entry", 32 "feature", 33 "shared" 34}; 35const std::unordered_map<std::string, AbilityType> ABILITY_TYPE_MAP = { 36 {"page", AbilityType::PAGE}, 37 {"service", AbilityType::SERVICE}, 38 {"data", AbilityType::DATA}, 39 {"form", AbilityType::FORM} 40}; 41const std::unordered_map<std::string, DisplayOrientation> DISPLAY_ORIENTATION_MAP = { 42 {"unspecified", DisplayOrientation::UNSPECIFIED}, 43 {"landscape", DisplayOrientation::LANDSCAPE}, 44 {"portrait", DisplayOrientation::PORTRAIT}, 45 {"followRecent", DisplayOrientation::FOLLOWRECENT} 46}; 47const std::unordered_map<std::string, LaunchMode> LAUNCH_MODE_MAP = { 48 {"singleton", LaunchMode::SINGLETON}, 49 {"standard", LaunchMode::STANDARD}, 50 {"specified", LaunchMode::SPECIFIED} 51}; 52const std::unordered_map<std::string, int32_t> dimensionMap = { 53 {"1*2", 1}, 54 {"2*2", 2}, 55 {"2*4", 3}, 56 {"4*4", 4}, 57 {"2*1", 5} 58}; 59const std::unordered_map<std::string, FormType> formTypeMap = { 60 {"JS", FormType::JS}, 61 {"Java", FormType::JAVA} 62}; 63const std::unordered_map<std::string, ModuleColorMode> moduleColorMode = { 64 {"auto", ModuleColorMode::AUTO}, 65 {"dark", ModuleColorMode::DARK}, 66 {"light", ModuleColorMode::LIGHT}, 67}; 68const std::unordered_map<std::string, FormsColorMode> formColorModeMap = { 69 {"auto", FormsColorMode::AUTO_MODE}, 70 {"dark", FormsColorMode::DARK_MODE}, 71 {"light", FormsColorMode::LIGHT_MODE} 72}; 73constexpr const char* BACKGROUND_MODE_MAP_KEY[] = { 74 KEY_DATA_TRANSFER, 75 KEY_AUDIO_PLAYBACK, 76 KEY_AUDIO_RECORDING, 77 KEY_LOCATION, 78 KEY_BLUETOOTH_INTERACTION, 79 KEY_MULTI_DEVICE_CONNECTION, 80 KEY_WIFI_INTERACTION, 81 KEY_VOIP, 82 KEY_TASK_KEEPING, 83 KEY_PICTURE_IN_PICTURE, 84 KEY_SCREEN_FETCH 85}; 86const uint32_t BACKGROUND_MODE_MAP_VALUE[] = { 87 VALUE_DATA_TRANSFER, 88 VALUE_AUDIO_PLAYBACK, 89 VALUE_AUDIO_RECORDING, 90 VALUE_LOCATION, 91 VALUE_BLUETOOTH_INTERACTION, 92 VALUE_MULTI_DEVICE_CONNECTION, 93 VALUE_WIFI_INTERACTION, 94 VALUE_VOIP, 95 VALUE_TASK_KEEPING, 96 VALUE_PICTURE_IN_PICTURE, 97 VALUE_SCREEN_FETCH 98}; 99 100struct Version { 101 int32_t code = 0; 102 int32_t minCompatibleVersionCode = -1; 103 std::string name; 104}; 105 106struct ApiVersion { 107 uint32_t compatible = 0; 108 uint32_t target = 0; 109 std::string releaseType = "Release"; 110 std::string compileSdkVersion; 111 std::string compileSdkType = Profile::COMPILE_SDK_TYPE_OPEN_HARMONY; 112}; 113 114// config.json app 115struct App { 116 std::string bundleName; 117 std::string originalName; 118 std::string vendor; 119 // pair first : if exist in config.json then true, otherwise false 120 // pair second : actual value 121 std::pair<bool, bool> removable = std::make_pair<>(false, true); 122 Version version; 123 ApiVersion apiVersion; 124 bool singleton = false; 125 bool userDataClearable = true; 126 bool asanEnabled = false; 127 uint32_t iconId = 0; 128 uint32_t labelId = 0; 129 std::vector<std::string> targetBundleList; 130}; 131 132struct ReqVersion { 133 uint32_t compatible = 0; 134 uint32_t target = 0; 135}; 136 137struct Ark { 138 ReqVersion reqVersion; 139 std::string flag; 140}; 141 142struct Domain { 143 bool subDomains = false; 144 std::string name; 145}; 146 147struct DomainSetting { 148 bool cleartextPermitted = false; 149 std::vector<Domain> domains; 150}; 151 152struct SecurityConfig { 153 DomainSetting domainSetting; 154}; 155 156struct Network { 157 bool usesCleartext = false; 158 SecurityConfig securityConfig; 159}; 160 161struct Device { 162 std::string jointUserId; 163 std::string process; 164 bool keepAlive = false; 165 bool directLaunch = false; 166 bool supportBackup = false; 167 bool compressNativeLibs = true; 168 bool debug = false; 169 Ark ark; 170 Network network; 171}; 172// config.json deviceConfig 173struct DeviceConfig { 174 Device defaultDevice; 175 Device phone; 176 Device tablet; 177 Device tv; 178 Device car; 179 Device wearable; 180 Device liteWearable; 181 Device smartVision; 182 Device twoInOne; 183}; 184 185struct Form { 186 std::vector<std::string> formEntity; 187 int32_t minHeight = 0; 188 int32_t defaultHeight = 0; 189 int32_t minWidth = 0; 190 int32_t defaultWidth = 0; 191}; 192 193struct FormsCustomizeData { 194 std::string name; 195 std::string value; 196}; 197 198struct FormsMetaData { 199 std::vector<FormsCustomizeData> customizeData; 200}; 201 202struct Window { 203 int32_t designWidth = 720; 204 bool autoDesignWidth = false; 205}; 206 207struct Forms { 208 bool isDefault = false; 209 bool updateEnabled = false; 210 bool formVisibleNotify = false; 211 uint32_t descriptionId = 0; 212 int32_t updateDuration = 0; 213 std::string name; 214 std::string description; 215 std::string type; 216 std::string src; 217 Window window; 218 std::string colorMode = "auto"; 219 std::vector<std::string> supportDimensions; 220 std::string defaultDimension; 221 std::vector<std::string> landscapeLayouts; 222 std::vector<std::string> portraitLayouts; 223 std::string scheduledUpdateTime = ""; 224 std::string deepLink; 225 std::string formConfigAbility; 226 std::string jsComponentName; 227 FormsMetaData metaData; 228}; 229 230struct CustomizeData { 231 std::string name; 232 std::string value; 233 std::string extra; 234}; 235 236struct MetaData { 237 std::vector<CustomizeData> customizeData; 238}; 239 240struct UriPermission { 241 std::string mode; 242 std::string path; 243}; 244 245struct Ability { 246 bool visible = false; 247 bool continuable = false; 248 bool formEnabled = false; 249 bool grantPermission; 250 bool directLaunch = false; 251 bool multiUserShared = false; 252 bool supportPipMode = false; 253 bool formsEnabled = false; 254 bool removeMissionAfterTerminate = false; 255 uint32_t descriptionId = 0; 256 uint32_t iconId = 0; 257 uint32_t labelId = 0; 258 int32_t priority = 0; 259 uint32_t startWindowIconId = 0; 260 uint32_t startWindowBackgroundId = 0; 261 std::string name; 262 std::string originalName; 263 std::string description; 264 std::string icon; 265 std::string label; 266 std::string uri; 267 std::string process; 268 std::string launchType = "singleton"; 269 std::string theme; 270 std::vector<std::string> permissions; 271 std::vector<Skill> skills; 272 std::vector<std::string> deviceCapability; 273 MetaData metaData; 274 std::string type; 275 std::string srcPath; 276 std::string srcLanguage = "js"; 277 Form form; 278 std::string orientation = "unspecified"; 279 std::vector<std::string> backgroundModes; 280 UriPermission uriPermission; 281 std::string readPermission; 282 std::string writePermission; 283 std::vector<std::string> configChanges; 284 std::string mission; 285 std::string targetAbility; 286 std::vector<Forms> formses; 287 std::string startWindowIcon; 288 std::string startWindowBackground; 289}; 290 291struct Js { 292 std::string name = "default"; 293 std::vector<std::string> pages; 294 Window window; 295 std::string type = "normal"; 296}; 297 298struct Intent { 299 std::string targetClass; 300 std::string targetBundle; 301}; 302 303struct CommonEvent { 304 std::string name; 305 std::string permission; 306 std::vector<std::string> data; 307 std::vector<std::string> type; 308 std::vector<std::string> events; 309}; 310 311struct Shortcut { 312 std::string shortcutId; 313 std::string label; 314 std::string icon; 315 uint32_t iconId; 316 uint32_t labelId; 317 std::vector<Intent> intents; 318}; 319 320// config.json module 321struct Module { 322 std::string package; 323 std::string name; 324 std::string description; 325 bool isLibIsolated = false; 326 uint32_t descriptionId = 0; 327 std::string colorMode = "auto"; 328 std::vector<std::string> supportedModes; 329 std::vector<std::string> reqCapabilities; 330 std::vector<std::string> deviceType; 331 std::vector<Dependency> dependencies; 332 Distro distro; 333 MetaData metaData; 334 std::vector<Ability> abilities; 335 std::vector<Js> jses; 336 std::vector<CommonEvent> commonEvents; 337 std::vector<Shortcut> shortcuts; 338 std::vector<RequestPermission> requestPermissions; 339 std::vector<DefinePermission> definePermissions; 340 std::string mainAbility; 341 std::string srcPath; 342 std::string buildHash; 343}; 344 345// config.json 346struct ConfigJson { 347 App app; 348 DeviceConfig deveicConfig; 349 Module module; 350}; 351 352/* 353 * form_json is global static overload method in self namespace ProfileReader, 354 * which need callback by json library, and can not rename this function, 355 * so don't named according UpperCamelCase style 356 */ 357void from_json(const nlohmann::json &jsonObject, Version &version) 358{ 359 const auto &jsonObjectEnd = jsonObject.end(); 360 GetValueIfFindKey<int32_t>(jsonObject, 361 jsonObjectEnd, 362 BUNDLE_APP_PROFILE_KEY_CODE, 363 version.code, 364 JsonType::NUMBER, 365 true, 366 g_parseResult, 367 ArrayType::NOT_ARRAY); 368 BMSJsonUtil::GetStrValueIfFindKey(jsonObject, 369 jsonObjectEnd, 370 PROFILE_KEY_NAME, 371 version.name, 372 true, 373 g_parseResult); 374 GetValueIfFindKey<int32_t>(jsonObject, 375 jsonObjectEnd, 376 BUNDLE_APP_PROFILE_KEY_MIN_COMPATIBLE_VERSION_CODE, 377 version.minCompatibleVersionCode, 378 JsonType::NUMBER, 379 false, 380 g_parseResult, 381 ArrayType::NOT_ARRAY); 382} 383 384void from_json(const nlohmann::json &jsonObject, ApiVersion &apiVersion) 385{ 386 // these are required fields. 387 const auto &jsonObjectEnd = jsonObject.end(); 388 GetValueIfFindKey<uint32_t>(jsonObject, 389 jsonObjectEnd, 390 BUNDLE_APP_PROFILE_KEY_COMPATIBLE, 391 apiVersion.compatible, 392 JsonType::NUMBER, 393 true, 394 g_parseResult, 395 ArrayType::NOT_ARRAY); 396 // these are not required fields. 397 GetValueIfFindKey<uint32_t>(jsonObject, 398 jsonObjectEnd, 399 BUNDLE_APP_PROFILE_KEY_TARGET, 400 apiVersion.target, 401 JsonType::NUMBER, 402 false, 403 g_parseResult, 404 ArrayType::NOT_ARRAY); 405 BMSJsonUtil::GetStrValueIfFindKey(jsonObject, 406 jsonObjectEnd, 407 BUNDLE_APP_PROFILE_KEY_RELEASE_TYPE, 408 apiVersion.releaseType, 409 false, 410 g_parseResult); 411 BMSJsonUtil::GetStrValueIfFindKey(jsonObject, 412 jsonObjectEnd, 413 BUNDLE_APP_PROFILE_KEY_COMPILE_SDK_VERSION, 414 apiVersion.compileSdkVersion, 415 false, 416 g_parseResult); 417 BMSJsonUtil::GetStrValueIfFindKey(jsonObject, 418 jsonObjectEnd, 419 BUNDLE_APP_PROFILE_KEY_COMPILE_SDK_TYPE, 420 apiVersion.compileSdkType, 421 false, 422 g_parseResult); 423} 424 425void from_json(const nlohmann::json &jsonObject, App &app) 426{ 427 // these are required fields. 428 const auto &jsonObjectEnd = jsonObject.end(); 429 BMSJsonUtil::GetStrValueIfFindKey(jsonObject, 430 jsonObjectEnd, 431 BUNDLE_APP_PROFILE_KEY_BUNDLE_NAME, 432 app.bundleName, 433 true, 434 g_parseResult); 435 BMSJsonUtil::GetStrValueIfFindKey(jsonObject, 436 jsonObjectEnd, 437 PROFILE_KEY_ORIGINAL_NAME, 438 app.originalName, 439 false, 440 g_parseResult); 441 GetValueIfFindKey<Version>(jsonObject, 442 jsonObjectEnd, 443 BUNDLE_APP_PROFILE_KEY_VERSION, 444 app.version, 445 JsonType::OBJECT, 446 true, 447 g_parseResult, 448 ArrayType::NOT_ARRAY); 449 GetValueIfFindKey<ApiVersion>(jsonObject, 450 jsonObjectEnd, 451 BUNDLE_APP_PROFILE_KEY_API_VERSION, 452 app.apiVersion, 453 JsonType::OBJECT, 454 true, 455 g_parseResult, 456 ArrayType::NOT_ARRAY); 457 // these are not required fields. 458 BMSJsonUtil::GetStrValueIfFindKey(jsonObject, 459 jsonObjectEnd, 460 BUNDLE_APP_PROFILE_KEY_VENDOR, 461 app.vendor, 462 false, 463 g_parseResult); 464 BMSJsonUtil::GetBoolValueIfFindKey(jsonObject, 465 jsonObjectEnd, 466 BUNDLE_APP_PROFILE_KEY_SINGLETON, 467 app.singleton, 468 false, 469 g_parseResult); 470 GetValueIfFindKey<uint32_t>(jsonObject, 471 jsonObjectEnd, 472 PROFILE_KEY_ICON_ID, 473 app.iconId, 474 JsonType::NUMBER, 475 false, 476 g_parseResult, 477 ArrayType::NOT_ARRAY); 478 GetValueIfFindKey<uint32_t>(jsonObject, 479 jsonObjectEnd, 480 PROFILE_KEY_LABEL_ID, 481 app.labelId, 482 JsonType::NUMBER, 483 false, 484 g_parseResult, 485 ArrayType::NOT_ARRAY); 486 if (jsonObject.find(BUNDLE_APP_PROFILE_KEY_REMOVABLE) != jsonObject.end()) { 487 app.removable.first = true; 488 BMSJsonUtil::GetBoolValueIfFindKey(jsonObject, 489 jsonObjectEnd, 490 BUNDLE_APP_PROFILE_KEY_REMOVABLE, 491 app.removable.second, 492 false, 493 g_parseResult); 494 } 495 BMSJsonUtil::GetBoolValueIfFindKey(jsonObject, 496 jsonObjectEnd, 497 BUNDLE_APP_PROFILE_KEY_USER_DATA_CLEARABLE, 498 app.userDataClearable, 499 false, 500 g_parseResult); 501 GetValueIfFindKey<std::vector<std::string>>(jsonObject, 502 jsonObjectEnd, 503 BUNDLE_APP_PROFILE_KEY_TARGETET_BUNDLE_LIST, 504 app.targetBundleList, 505 JsonType::ARRAY, 506 false, 507 g_parseResult, 508 ArrayType::STRING); 509 BMSJsonUtil::GetBoolValueIfFindKey(jsonObject, 510 jsonObjectEnd, 511 BUNDLE_APP_PROFILE_KEY_ASAN_ENABLED, 512 app.asanEnabled, 513 false, 514 g_parseResult); 515} 516 517void from_json(const nlohmann::json &jsonObject, ReqVersion &reqVersion) 518{ 519 // these are required fields. 520 const auto &jsonObjectEnd = jsonObject.end(); 521 GetValueIfFindKey<uint32_t>(jsonObject, 522 jsonObjectEnd, 523 BUNDLE_DEVICE_CONFIG_PROFILE_KEY_COMPATIBLE, 524 reqVersion.compatible, 525 JsonType::NUMBER, 526 true, 527 g_parseResult, 528 ArrayType::NOT_ARRAY); 529 // these are not required fields. 530 GetValueIfFindKey<uint32_t>(jsonObject, 531 jsonObjectEnd, 532 BUNDLE_DEVICE_CONFIG_PROFILE_KEY_TARGET, 533 reqVersion.target, 534 JsonType::NUMBER, 535 false, 536 g_parseResult, 537 ArrayType::NOT_ARRAY); 538} 539 540void from_json(const nlohmann::json &jsonObject, Ark &ark) 541{ 542 // these are not required fields. 543 const auto &jsonObjectEnd = jsonObject.end(); 544 GetValueIfFindKey<ReqVersion>(jsonObject, 545 jsonObjectEnd, 546 BUNDLE_DEVICE_CONFIG_PROFILE_KEY_REQ_VERSION, 547 ark.reqVersion, 548 JsonType::OBJECT, 549 false, 550 g_parseResult, 551 ArrayType::NOT_ARRAY); 552 BMSJsonUtil::GetStrValueIfFindKey(jsonObject, 553 jsonObjectEnd, 554 BUNDLE_DEVICE_CONFIG_PROFILE_KEY_FLAG, 555 ark.flag, 556 false, 557 g_parseResult); 558} 559 560void from_json(const nlohmann::json &jsonObject, Domain &domain) 561{ 562 // these are required fields. 563 const auto &jsonObjectEnd = jsonObject.end(); 564 BMSJsonUtil::GetBoolValueIfFindKey(jsonObject, 565 jsonObjectEnd, 566 BUNDLE_DEVICE_CONFIG_PROFILE_KEY_SUB_DOMAINS, 567 domain.subDomains, 568 true, 569 g_parseResult); 570 BMSJsonUtil::GetStrValueIfFindKey(jsonObject, 571 jsonObjectEnd, 572 PROFILE_KEY_NAME, 573 domain.name, 574 true, 575 g_parseResult); 576} 577 578void from_json(const nlohmann::json &jsonObject, DomainSetting &domainSetting) 579{ 580 // these are required fields. 581 const auto &jsonObjectEnd = jsonObject.end(); 582 BMSJsonUtil::GetBoolValueIfFindKey(jsonObject, 583 jsonObjectEnd, 584 BUNDLE_DEVICE_CONFIG_PROFILE_KEY_CLEAR_TEXT_PERMITTED, 585 domainSetting.cleartextPermitted, 586 true, 587 g_parseResult); 588 GetValueIfFindKey<std::vector<Domain>>(jsonObject, 589 jsonObjectEnd, 590 BUNDLE_DEVICE_CONFIG_PROFILE_KEY_DOMAINS, 591 domainSetting.domains, 592 JsonType::ARRAY, 593 true, 594 g_parseResult, 595 ArrayType::OBJECT); 596} 597 598void from_json(const nlohmann::json &jsonObject, SecurityConfig &securityConfig) 599{ 600 // these are not required fields. 601 const auto &jsonObjectEnd = jsonObject.end(); 602 GetValueIfFindKey<DomainSetting>(jsonObject, 603 jsonObjectEnd, 604 BUNDLE_DEVICE_CONFIG_PROFILE_KEY_DOMAIN_SETTINGS, 605 securityConfig.domainSetting, 606 JsonType::OBJECT, 607 false, 608 g_parseResult, 609 ArrayType::NOT_ARRAY); 610} 611 612void from_json(const nlohmann::json &jsonObject, Network &network) 613{ 614 // these are not required fields. 615 const auto &jsonObjectEnd = jsonObject.end(); 616 BMSJsonUtil::GetBoolValueIfFindKey(jsonObject, 617 jsonObjectEnd, 618 BUNDLE_DEVICE_CONFIG_PROFILE_KEY_USES_CLEAR_TEXT, 619 network.usesCleartext, 620 false, 621 g_parseResult); 622 GetValueIfFindKey<SecurityConfig>(jsonObject, 623 jsonObjectEnd, 624 BUNDLE_DEVICE_CONFIG_PROFILE_KEY_SECURITY_CONFIG, 625 network.securityConfig, 626 JsonType::OBJECT, 627 false, 628 g_parseResult, 629 ArrayType::NOT_ARRAY); 630} 631 632void from_json(const nlohmann::json &jsonObject, Device &device) 633{ 634 // these are not required fields. 635 const auto &jsonObjectEnd = jsonObject.end(); 636 BMSJsonUtil::GetStrValueIfFindKey(jsonObject, 637 jsonObjectEnd, 638 BUNDLE_DEVICE_CONFIG_PROFILE_KEY_JOINT_USER_ID, 639 device.jointUserId, 640 false, 641 g_parseResult); 642 BMSJsonUtil::GetStrValueIfFindKey(jsonObject, 643 jsonObjectEnd, 644 BUNDLE_DEVICE_CONFIG_PROFILE_KEY_PROCESS, 645 device.process, 646 false, 647 g_parseResult); 648 BMSJsonUtil::GetBoolValueIfFindKey(jsonObject, 649 jsonObjectEnd, 650 BUNDLE_DEVICE_CONFIG_PROFILE_KEY_KEEP_ALIVE, 651 device.keepAlive, 652 false, 653 g_parseResult); 654 GetValueIfFindKey<Ark>(jsonObject, 655 jsonObjectEnd, 656 BUNDLE_DEVICE_CONFIG_PROFILE_KEY_ARK, 657 device.ark, 658 JsonType::OBJECT, 659 false, 660 g_parseResult, 661 ArrayType::NOT_ARRAY); 662 BMSJsonUtil::GetBoolValueIfFindKey(jsonObject, 663 jsonObjectEnd, 664 BUNDLE_DEVICE_CONFIG_PROFILE_KEY_DIRECT_LAUNCH, 665 device.directLaunch, 666 false, 667 g_parseResult); 668 BMSJsonUtil::GetBoolValueIfFindKey(jsonObject, 669 jsonObjectEnd, 670 BUNDLE_DEVICE_CONFIG_PROFILE_KEY_SUPPORT_BACKUP, 671 device.supportBackup, 672 false, 673 g_parseResult); 674 BMSJsonUtil::GetBoolValueIfFindKey(jsonObject, 675 jsonObjectEnd, 676 BUNDLE_DEVICE_CONFIG_PROFILE_KEY_DEBUG, 677 device.debug, 678 false, 679 g_parseResult); 680 BMSJsonUtil::GetBoolValueIfFindKey(jsonObject, 681 jsonObjectEnd, 682 BUNDLE_DEVICE_CONFIG_PROFILE_KEY_COMPRESS_NATIVE_LIBS, 683 device.compressNativeLibs, 684 false, 685 g_parseResult); 686 GetValueIfFindKey<Network>(jsonObject, 687 jsonObjectEnd, 688 BUNDLE_DEVICE_CONFIG_PROFILE_KEY_NETWORK, 689 device.network, 690 JsonType::OBJECT, 691 false, 692 g_parseResult, 693 ArrayType::NOT_ARRAY); 694} 695 696void from_json(const nlohmann::json &jsonObject, DeviceConfig &deviceConfig) 697{ 698 // these are required fields. 699 const auto &jsonObjectEnd = jsonObject.end(); 700 GetValueIfFindKey<Device>(jsonObject, 701 jsonObjectEnd, 702 BUNDLE_DEVICE_CONFIG_PROFILE_KEY_DEFAULT, 703 deviceConfig.defaultDevice, 704 JsonType::OBJECT, 705 false, 706 g_parseResult, 707 ArrayType::NOT_ARRAY); 708 // these are not required fields. 709 GetValueIfFindKey<Device>(jsonObject, 710 jsonObjectEnd, 711 BUNDLE_DEVICE_CONFIG_PROFILE_KEY_PHONE, 712 deviceConfig.phone, 713 JsonType::OBJECT, 714 false, 715 g_parseResult, 716 ArrayType::NOT_ARRAY); 717 GetValueIfFindKey<Device>(jsonObject, 718 jsonObjectEnd, 719 BUNDLE_DEVICE_CONFIG_PROFILE_KEY_TABLET, 720 deviceConfig.tablet, 721 JsonType::OBJECT, 722 false, 723 g_parseResult, 724 ArrayType::NOT_ARRAY); 725 GetValueIfFindKey<Device>(jsonObject, 726 jsonObjectEnd, 727 BUNDLE_DEVICE_CONFIG_PROFILE_KEY_TV, 728 deviceConfig.tv, 729 JsonType::OBJECT, 730 false, 731 g_parseResult, 732 ArrayType::NOT_ARRAY); 733 GetValueIfFindKey<Device>(jsonObject, 734 jsonObjectEnd, 735 BUNDLE_DEVICE_CONFIG_PROFILE_KEY_CAR, 736 deviceConfig.car, 737 JsonType::OBJECT, 738 false, 739 g_parseResult, 740 ArrayType::NOT_ARRAY); 741 GetValueIfFindKey<Device>(jsonObject, 742 jsonObjectEnd, 743 BUNDLE_DEVICE_CONFIG_PROFILE_KEY_WEARABLE, 744 deviceConfig.wearable, 745 JsonType::OBJECT, 746 false, 747 g_parseResult, 748 ArrayType::NOT_ARRAY); 749 GetValueIfFindKey<Device>(jsonObject, 750 jsonObjectEnd, 751 BUNDLE_DEVICE_CONFIG_PROFILE_KEY_LITE_WEARABLE, 752 deviceConfig.liteWearable, 753 JsonType::OBJECT, 754 false, 755 g_parseResult, 756 ArrayType::NOT_ARRAY); 757 GetValueIfFindKey<Device>(jsonObject, 758 jsonObjectEnd, 759 BUNDLE_DEVICE_CONFIG_PROFILE_KEY_SMART_VISION, 760 deviceConfig.smartVision, 761 JsonType::OBJECT, 762 false, 763 g_parseResult, 764 ArrayType::NOT_ARRAY); 765 GetValueIfFindKey<Device>(jsonObject, 766 jsonObjectEnd, 767 BUNDLE_DEVICE_CONFIG_PROFILE_KEY_TWO_IN_ONE, 768 deviceConfig.twoInOne, 769 JsonType::OBJECT, 770 false, 771 g_parseResult, 772 ArrayType::NOT_ARRAY); 773} 774 775void from_json(const nlohmann::json &jsonObject, Form &form) 776{ 777 // these are not required fields. 778 const auto &jsonObjectEnd = jsonObject.end(); 779 GetValueIfFindKey<std::vector<std::string>>(jsonObject, 780 jsonObjectEnd, 781 BUNDLE_MODULE_PROFILE_FORM_ENTITY, 782 form.formEntity, 783 JsonType::ARRAY, 784 false, 785 g_parseResult, 786 ArrayType::STRING); 787 GetValueIfFindKey<int32_t>(jsonObject, 788 jsonObjectEnd, 789 BUNDLE_MODULE_PROFILE_FORM_MIN_HEIGHT, 790 form.minHeight, 791 JsonType::NUMBER, 792 false, 793 g_parseResult, 794 ArrayType::NOT_ARRAY); 795 GetValueIfFindKey<int32_t>(jsonObject, 796 jsonObjectEnd, 797 BUNDLE_MODULE_PROFILE_FORM_DEFAULT_HEIGHT, 798 form.defaultHeight, 799 JsonType::NUMBER, 800 false, 801 g_parseResult, 802 ArrayType::NOT_ARRAY); 803 GetValueIfFindKey<int32_t>(jsonObject, 804 jsonObjectEnd, 805 BUNDLE_MODULE_PROFILE_FORM_MIN_WIDTH, 806 form.minWidth, 807 JsonType::NUMBER, 808 false, 809 g_parseResult, 810 ArrayType::NOT_ARRAY); 811 GetValueIfFindKey<int32_t>(jsonObject, 812 jsonObjectEnd, 813 BUNDLE_MODULE_PROFILE_FORM_DEFAULT_WIDTH, 814 form.defaultWidth, 815 JsonType::NUMBER, 816 false, 817 g_parseResult, 818 ArrayType::NOT_ARRAY); 819} 820 821void from_json(const nlohmann::json &jsonObject, CustomizeData &customizeData) 822{ 823 // these are not required fields. 824 const auto &jsonObjectEnd = jsonObject.end(); 825 BMSJsonUtil::GetStrValueIfFindKey(jsonObject, 826 jsonObjectEnd, 827 PROFILE_KEY_NAME, 828 customizeData.name, 829 false, 830 g_parseResult); 831 BMSJsonUtil::GetStrValueIfFindKey(jsonObject, 832 jsonObjectEnd, 833 BUNDLE_MODULE_META_KEY_EXTRA, 834 customizeData.extra, 835 false, 836 g_parseResult); 837 BMSJsonUtil::GetStrValueIfFindKey(jsonObject, 838 jsonObjectEnd, 839 BUNDLE_MODULE_META_KEY_VALUE, 840 customizeData.value, 841 false, 842 g_parseResult); 843} 844 845void from_json(const nlohmann::json &jsonObject, MetaData &metaData) 846{ 847 // these are not required fields. 848 const auto &jsonObjectEnd = jsonObject.end(); 849 GetValueIfFindKey<std::vector<CustomizeData>>(jsonObject, 850 jsonObjectEnd, 851 BUNDLE_MODULE_META_KEY_CUSTOMIZE_DATA, 852 metaData.customizeData, 853 JsonType::ARRAY, 854 false, 855 g_parseResult, 856 ArrayType::OBJECT); 857} 858 859void from_json(const nlohmann::json &jsonObject, FormsCustomizeData &customizeDataForms) 860{ 861 // these are not required fields. 862 const auto &jsonObjectEnd = jsonObject.end(); 863 BMSJsonUtil::GetStrValueIfFindKey(jsonObject, 864 jsonObjectEnd, 865 PROFILE_KEY_NAME, 866 customizeDataForms.name, 867 false, 868 g_parseResult); 869 BMSJsonUtil::GetStrValueIfFindKey(jsonObject, 870 jsonObjectEnd, 871 BUNDLE_MODULE_PROFILE_FORMS_VALUE, 872 customizeDataForms.value, 873 false, 874 g_parseResult); 875} 876 877void from_json(const nlohmann::json &jsonObject, FormsMetaData &formsMetaData) 878{ 879 // these are not required fields. 880 const auto &jsonObjectEnd = jsonObject.end(); 881 GetValueIfFindKey<std::vector<FormsCustomizeData>>(jsonObject, 882 jsonObjectEnd, 883 BUNDLE_MODULE_PROFILE_KEY_CUSTOMIZE_DATA, 884 formsMetaData.customizeData, 885 JsonType::ARRAY, 886 false, 887 g_parseResult, 888 ArrayType::OBJECT); 889} 890 891void from_json(const nlohmann::json &jsonObject, Window &window) 892{ 893 // these are not required fields. 894 const auto &jsonObjectEnd = jsonObject.end(); 895 GetValueIfFindKey<int32_t>(jsonObject, 896 jsonObjectEnd, 897 BUNDLE_MODULE_PROFILE_KEY_DESIGN_WIDTH, 898 window.designWidth, 899 JsonType::NUMBER, 900 false, 901 g_parseResult, 902 ArrayType::NOT_ARRAY); 903 BMSJsonUtil::GetBoolValueIfFindKey(jsonObject, 904 jsonObjectEnd, 905 BUNDLE_MODULE_PROFILE_KEY_AUTO_DESIGN_WIDTH, 906 window.autoDesignWidth, 907 false, 908 g_parseResult); 909} 910 911void from_json(const nlohmann::json &jsonObject, Forms &forms) 912{ 913 // these are required fields. 914 const auto &jsonObjectEnd = jsonObject.end(); 915 BMSJsonUtil::GetStrValueIfFindKey(jsonObject, 916 jsonObjectEnd, 917 PROFILE_KEY_NAME, 918 forms.name, 919 true, 920 g_parseResult); 921 BMSJsonUtil::GetBoolValueIfFindKey(jsonObject, 922 jsonObjectEnd, 923 BUNDLE_MODULE_PROFILE_FORMS_IS_DEFAULT, 924 forms.isDefault, 925 true, 926 g_parseResult); 927 BMSJsonUtil::GetStrValueIfFindKey(jsonObject, 928 jsonObjectEnd, 929 PROFILE_KEY_TYPE, 930 forms.type, 931 true, 932 g_parseResult); 933 BMSJsonUtil::GetStrValueIfFindKey(jsonObject, 934 jsonObjectEnd, 935 BUNDLE_MODULE_PROFILE_FORMS_SRC, 936 forms.src, 937 false, 938 g_parseResult); 939 GetValueIfFindKey<Window>(jsonObject, 940 jsonObjectEnd, 941 BUNDLE_MODULE_PROFILE_KEY_WINDOW, 942 forms.window, 943 JsonType::OBJECT, 944 false, 945 g_parseResult, 946 ArrayType::NOT_ARRAY); 947 GetValueIfFindKey<std::vector<std::string>>(jsonObject, 948 jsonObjectEnd, 949 BUNDLE_MODULE_PROFILE_FORMS_SUPPORT_DIMENSIONS, 950 forms.supportDimensions, 951 JsonType::ARRAY, 952 true, 953 g_parseResult, 954 ArrayType::STRING); 955 BMSJsonUtil::GetStrValueIfFindKey(jsonObject, 956 jsonObjectEnd, 957 BUNDLE_MODULE_PROFILE_FORMS_DEFAULT_DIMENSION, 958 forms.defaultDimension, 959 true, 960 g_parseResult); 961 GetValueIfFindKey<std::vector<std::string>>(jsonObject, 962 jsonObjectEnd, 963 BUNDLE_MODULE_PROFILE_FORMS_LANDSCAPE_LAYOUTS, 964 forms.landscapeLayouts, 965 JsonType::ARRAY, 966 false, 967 g_parseResult, 968 ArrayType::STRING); 969 GetValueIfFindKey<std::vector<std::string>>(jsonObject, 970 jsonObjectEnd, 971 BUNDLE_MODULE_PROFILE_FORMS_PORTRAIT_LAYOUTS, 972 forms.portraitLayouts, 973 JsonType::ARRAY, 974 false, 975 g_parseResult, 976 ArrayType::STRING); 977 BMSJsonUtil::GetBoolValueIfFindKey(jsonObject, 978 jsonObjectEnd, 979 BUNDLE_MODULE_PROFILE_FORMS_UPDATEENABLED, 980 forms.updateEnabled, 981 true, 982 g_parseResult); 983 BMSJsonUtil::GetStrValueIfFindKey(jsonObject, 984 jsonObjectEnd, 985 BUNDLE_MODULE_PROFILE_FORMS_JS_COMPONENT_NAME, 986 forms.jsComponentName, 987 true, 988 g_parseResult); 989 // these are not required fields. 990 BMSJsonUtil::GetStrValueIfFindKey(jsonObject, 991 jsonObjectEnd, 992 PROFILE_KEY_DESCRIPTION, 993 forms.description, 994 false, 995 g_parseResult); 996 GetValueIfFindKey<int32_t>(jsonObject, 997 jsonObjectEnd, 998 PROFILE_KEY_DESCRIPTION_ID, 999 forms.descriptionId, 1000 JsonType::NUMBER, 1001 false, 1002 g_parseResult, 1003 ArrayType::NOT_ARRAY); 1004 BMSJsonUtil::GetStrValueIfFindKey(jsonObject, 1005 jsonObjectEnd, 1006 BUNDLE_MODULE_PROFILE_FORMS_COLOR_MODE, 1007 forms.colorMode, 1008 false, 1009 g_parseResult); 1010 BMSJsonUtil::GetStrValueIfFindKey(jsonObject, 1011 jsonObjectEnd, 1012 BUNDLE_MODULE_PROFILE_FORMS_SCHEDULED_UPDATE_TIME, 1013 forms.scheduledUpdateTime, 1014 false, 1015 g_parseResult); 1016 GetValueIfFindKey<int32_t>(jsonObject, 1017 jsonObjectEnd, 1018 BUNDLE_MODULE_PROFILE_FORMS_UPDATE_DURATION, 1019 forms.updateDuration, 1020 JsonType::NUMBER, 1021 false, 1022 g_parseResult, 1023 ArrayType::NOT_ARRAY); 1024 BMSJsonUtil::GetStrValueIfFindKey(jsonObject, 1025 jsonObjectEnd, 1026 BUNDLE_MODULE_PROFILE_FORMS_DEEP_LINK, 1027 forms.deepLink, 1028 false, 1029 g_parseResult); 1030 BMSJsonUtil::GetStrValueIfFindKey(jsonObject, 1031 jsonObjectEnd, 1032 BUNDLE_MODULE_PROFILE_FORMS_FORM_CONFIG_ABILITY, 1033 forms.formConfigAbility, 1034 false, 1035 g_parseResult); 1036 BMSJsonUtil::GetBoolValueIfFindKey(jsonObject, 1037 jsonObjectEnd, 1038 BUNDLE_MODULE_PROFILE_FORMS_FORM_VISIBLE_NOTIFY, 1039 forms.formVisibleNotify, 1040 false, 1041 g_parseResult); 1042 GetValueIfFindKey<FormsMetaData>(jsonObject, 1043 jsonObjectEnd, 1044 BUNDLE_MODULE_PROFILE_KEY_META_DATA, 1045 forms.metaData, 1046 JsonType::OBJECT, 1047 false, 1048 g_parseResult, 1049 ArrayType::NOT_ARRAY); 1050} 1051 1052void from_json(const nlohmann::json &jsonObject, UriPermission &uriPermission) 1053{ 1054 // these are not required fields. 1055 const auto &jsonObjectEnd = jsonObject.end(); 1056 BMSJsonUtil::GetStrValueIfFindKey(jsonObject, 1057 jsonObjectEnd, 1058 BUNDLE_MODULE_PROFILE_KEY_MODE, 1059 uriPermission.mode, 1060 false, 1061 g_parseResult); 1062 BMSJsonUtil::GetStrValueIfFindKey(jsonObject, 1063 jsonObjectEnd, 1064 BUNDLE_MODULE_PROFILE_KEY_PATH, 1065 uriPermission.path, 1066 false, 1067 g_parseResult); 1068} 1069 1070void from_json(const nlohmann::json &jsonObject, Ability &ability) 1071{ 1072 // these are required fields. 1073 const auto &jsonObjectEnd = jsonObject.end(); 1074 BMSJsonUtil::GetStrValueIfFindKey(jsonObject, 1075 jsonObjectEnd, 1076 PROFILE_KEY_NAME, 1077 ability.name, 1078 true, 1079 g_parseResult); 1080 BMSJsonUtil::GetStrValueIfFindKey(jsonObject, 1081 jsonObjectEnd, 1082 PROFILE_KEY_ORIGINAL_NAME, 1083 ability.originalName, 1084 false, 1085 g_parseResult); 1086 BMSJsonUtil::GetStrValueIfFindKey(jsonObject, 1087 jsonObjectEnd, 1088 PROFILE_KEY_TYPE, 1089 ability.type, 1090 true, 1091 g_parseResult); 1092 BMSJsonUtil::GetStrValueIfFindKey(jsonObject, 1093 jsonObjectEnd, 1094 PROFILE_KEY_SRCPATH, 1095 ability.srcPath, 1096 false, 1097 g_parseResult); 1098 // these are not required fields. 1099 BMSJsonUtil::GetStrValueIfFindKey(jsonObject, 1100 jsonObjectEnd, 1101 PROFILE_KEY_SRCLANGUAGE, 1102 ability.srcLanguage, 1103 false, 1104 g_parseResult); 1105 BMSJsonUtil::GetStrValueIfFindKey(jsonObject, 1106 jsonObjectEnd, 1107 PROFILE_KEY_DESCRIPTION, 1108 ability.description, 1109 false, 1110 g_parseResult); 1111 GetValueIfFindKey<int32_t>(jsonObject, 1112 jsonObjectEnd, 1113 PROFILE_KEY_DESCRIPTION_ID, 1114 ability.descriptionId, 1115 JsonType::NUMBER, 1116 false, 1117 g_parseResult, 1118 ArrayType::NOT_ARRAY); 1119 BMSJsonUtil::GetStrValueIfFindKey(jsonObject, 1120 jsonObjectEnd, 1121 BUNDLE_MODULE_PROFILE_KEY_ICON, 1122 ability.icon, 1123 false, 1124 g_parseResult); 1125 GetValueIfFindKey<int32_t>(jsonObject, 1126 jsonObjectEnd, 1127 BUNDLE_MODULE_PROFILE_KEY_ICON_ID, 1128 ability.iconId, 1129 JsonType::NUMBER, 1130 false, 1131 g_parseResult, 1132 ArrayType::NOT_ARRAY); 1133 BMSJsonUtil::GetStrValueIfFindKey(jsonObject, 1134 jsonObjectEnd, 1135 BUNDLE_MODULE_PROFILE_KEY_PROCESS, 1136 ability.process, 1137 false, 1138 g_parseResult); 1139 BMSJsonUtil::GetStrValueIfFindKey(jsonObject, 1140 jsonObjectEnd, 1141 PROFILE_KEY_LABEL, 1142 ability.label, 1143 false, 1144 g_parseResult); 1145 GetValueIfFindKey<int32_t>(jsonObject, 1146 jsonObjectEnd, 1147 PROFILE_KEY_LABEL_ID, 1148 ability.labelId, 1149 JsonType::NUMBER, 1150 false, 1151 g_parseResult, 1152 ArrayType::NOT_ARRAY); 1153 GetValueIfFindKey<int32_t>(jsonObject, 1154 jsonObjectEnd, 1155 PRIORITY, 1156 ability.priority, 1157 JsonType::NUMBER, 1158 false, 1159 g_parseResult, 1160 ArrayType::NOT_ARRAY); 1161 BMSJsonUtil::GetStrValueIfFindKey(jsonObject, 1162 jsonObjectEnd, 1163 BUNDLE_MODULE_PROFILE_KEY_URI, 1164 ability.uri, 1165 false, 1166 g_parseResult); 1167 BMSJsonUtil::GetStrValueIfFindKey(jsonObject, 1168 jsonObjectEnd, 1169 BUNDLE_MODULE_PROFILE_KEY_LAUNCH_TYPE, 1170 ability.launchType, 1171 false, 1172 g_parseResult); 1173 BMSJsonUtil::GetStrValueIfFindKey(jsonObject, 1174 jsonObjectEnd, 1175 BUNDLE_MODULE_PROFILE_KEY_LAUNCH_THEME, 1176 ability.theme, 1177 false, 1178 g_parseResult); 1179 BMSJsonUtil::GetBoolValueIfFindKey(jsonObject, 1180 jsonObjectEnd, 1181 BUNDLE_MODULE_PROFILE_KEY_VISIBLE, 1182 ability.visible, 1183 false, 1184 g_parseResult); 1185 BMSJsonUtil::GetBoolValueIfFindKey(jsonObject, 1186 jsonObjectEnd, 1187 BUNDLE_MODULE_PROFILE_KEY_CONTINUABLE, 1188 ability.continuable, 1189 false, 1190 g_parseResult); 1191 GetValueIfFindKey<std::vector<std::string>>(jsonObject, 1192 jsonObjectEnd, 1193 BUNDLE_MODULE_PROFILE_KEY_PERMISSIONS, 1194 ability.permissions, 1195 JsonType::ARRAY, 1196 false, 1197 g_parseResult, 1198 ArrayType::STRING); 1199 GetValueIfFindKey<std::vector<Skill>>(jsonObject, 1200 jsonObjectEnd, 1201 BUNDLE_MODULE_PROFILE_KEY_SKILLS, 1202 ability.skills, 1203 JsonType::ARRAY, 1204 false, 1205 g_parseResult, 1206 ArrayType::OBJECT); 1207 GetValueIfFindKey<std::vector<std::string>>(jsonObject, 1208 jsonObjectEnd, 1209 BUNDLE_MODULE_PROFILE_KEY_DEVICE_CAP_ABILITY, 1210 ability.deviceCapability, 1211 JsonType::ARRAY, 1212 false, 1213 g_parseResult, 1214 ArrayType::STRING); 1215 GetValueIfFindKey<MetaData>(jsonObject, 1216 jsonObjectEnd, 1217 BUNDLE_MODULE_PROFILE_KEY_META_DATA, 1218 ability.metaData, 1219 JsonType::OBJECT, 1220 false, 1221 g_parseResult, 1222 ArrayType::NOT_ARRAY); 1223 BMSJsonUtil::GetBoolValueIfFindKey(jsonObject, 1224 jsonObjectEnd, 1225 BUNDLE_MODULE_PROFILE_KEY_FORM_ENABLED, 1226 ability.formEnabled, 1227 false, 1228 g_parseResult); 1229 GetValueIfFindKey<Form>(jsonObject, 1230 jsonObjectEnd, 1231 BUNDLE_MODULE_PROFILE_KEY_FORM, 1232 ability.form, 1233 JsonType::OBJECT, 1234 false, 1235 g_parseResult, 1236 ArrayType::NOT_ARRAY); 1237 BMSJsonUtil::GetStrValueIfFindKey(jsonObject, 1238 jsonObjectEnd, 1239 BUNDLE_MODULE_PROFILE_KEY_ORIENTATION, 1240 ability.orientation, 1241 false, 1242 g_parseResult); 1243 GetValueIfFindKey<std::vector<std::string>>(jsonObject, 1244 jsonObjectEnd, 1245 BUNDLE_MODULE_PROFILE_KEY_BACKGROUND_MODES, 1246 ability.backgroundModes, 1247 JsonType::ARRAY, 1248 false, 1249 g_parseResult, 1250 ArrayType::STRING); 1251 BMSJsonUtil::GetBoolValueIfFindKey(jsonObject, 1252 jsonObjectEnd, 1253 BUNDLE_MODULE_PROFILE_KEY_GRANT_PERMISSION, 1254 ability.grantPermission, 1255 false, 1256 g_parseResult); 1257 GetValueIfFindKey<UriPermission>(jsonObject, 1258 jsonObjectEnd, 1259 BUNDLE_MODULE_PROFILE_KEY_URI_PERMISSION, 1260 ability.uriPermission, 1261 JsonType::OBJECT, 1262 false, 1263 g_parseResult, 1264 ArrayType::NOT_ARRAY); 1265 BMSJsonUtil::GetStrValueIfFindKey(jsonObject, 1266 jsonObjectEnd, 1267 BUNDLE_MODULE_PROFILE_KEY_READ_PERMISSION, 1268 ability.readPermission, 1269 false, 1270 g_parseResult); 1271 BMSJsonUtil::GetStrValueIfFindKey(jsonObject, 1272 jsonObjectEnd, 1273 BUNDLE_MODULE_PROFILE_KEY_WRITE_PERMISSION, 1274 ability.writePermission, 1275 false, 1276 g_parseResult); 1277 BMSJsonUtil::GetBoolValueIfFindKey(jsonObject, 1278 jsonObjectEnd, 1279 BUNDLE_MODULE_PROFILE_KEY_DIRECT_LAUNCH, 1280 ability.directLaunch, 1281 false, 1282 g_parseResult); 1283 GetValueIfFindKey<std::vector<std::string>>(jsonObject, 1284 jsonObjectEnd, 1285 BUNDLE_MODULE_PROFILE_KEY_CONFIG_CHANGES, 1286 ability.configChanges, 1287 JsonType::ARRAY, 1288 false, 1289 g_parseResult, 1290 ArrayType::STRING); 1291 BMSJsonUtil::GetStrValueIfFindKey(jsonObject, 1292 jsonObjectEnd, 1293 BUNDLE_MODULE_PROFILE_KEY_MISSION, 1294 ability.mission, 1295 false, 1296 g_parseResult); 1297 BMSJsonUtil::GetStrValueIfFindKey(jsonObject, 1298 jsonObjectEnd, 1299 BUNDLE_MODULE_PROFILE_KEY_TARGET_ABILITY, 1300 ability.targetAbility, 1301 false, 1302 g_parseResult); 1303 BMSJsonUtil::GetBoolValueIfFindKey(jsonObject, 1304 jsonObjectEnd, 1305 BUNDLE_MODULE_PROFILE_KEY_MULTIUSER_SHARED, 1306 ability.multiUserShared, 1307 false, 1308 g_parseResult); 1309 BMSJsonUtil::GetBoolValueIfFindKey(jsonObject, 1310 jsonObjectEnd, 1311 BUNDLE_MODULE_PROFILE_KEY_SUPPORT_PIP_MODE, 1312 ability.supportPipMode, 1313 false, 1314 g_parseResult); 1315 BMSJsonUtil::GetBoolValueIfFindKey(jsonObject, 1316 jsonObjectEnd, 1317 BUNDLE_MODULE_PROFILE_KEY_FORMS_ENABLED, 1318 ability.formsEnabled, 1319 false, 1320 g_parseResult); 1321 GetValueIfFindKey<std::vector<Forms>>(jsonObject, 1322 jsonObjectEnd, 1323 BUNDLE_MODULE_PROFILE_KEY_FORMS, 1324 ability.formses, 1325 JsonType::ARRAY, 1326 false, 1327 g_parseResult, 1328 ArrayType::OBJECT); 1329 BMSJsonUtil::GetStrValueIfFindKey(jsonObject, 1330 jsonObjectEnd, 1331 BUNDLE_MODULE_PROFILE_KEY_START_WINDOW_ICON, 1332 ability.startWindowIcon, 1333 false, 1334 g_parseResult); 1335 GetValueIfFindKey<uint32_t>(jsonObject, 1336 jsonObjectEnd, 1337 BUNDLE_MODULE_PROFILE_KEY_START_WINDOW_ICON_ID, 1338 ability.startWindowIconId, 1339 JsonType::NUMBER, 1340 false, 1341 g_parseResult, 1342 ArrayType::NOT_ARRAY); 1343 BMSJsonUtil::GetStrValueIfFindKey(jsonObject, 1344 jsonObjectEnd, 1345 BUNDLE_MODULE_PROFILE_KEY_START_WINDOW_BACKGROUND, 1346 ability.startWindowBackground, 1347 false, 1348 g_parseResult); 1349 GetValueIfFindKey<uint32_t>(jsonObject, 1350 jsonObjectEnd, 1351 BUNDLE_MODULE_PROFILE_KEY_START_WINDOW_BACKGROUND_ID, 1352 ability.startWindowBackgroundId, 1353 JsonType::NUMBER, 1354 false, 1355 g_parseResult, 1356 ArrayType::NOT_ARRAY); 1357 BMSJsonUtil::GetBoolValueIfFindKey(jsonObject, 1358 jsonObjectEnd, 1359 BUNDLE_MODULE_PROFILE_KEY_REMOVE_MISSION_AFTER_TERMINATE, 1360 ability.removeMissionAfterTerminate, 1361 false, 1362 g_parseResult); 1363} 1364 1365void from_json(const nlohmann::json &jsonObject, Js &js) 1366{ 1367 // these are required fields. 1368 const auto &jsonObjectEnd = jsonObject.end(); 1369 BMSJsonUtil::GetStrValueIfFindKey(jsonObject, 1370 jsonObjectEnd, 1371 PROFILE_KEY_NAME, 1372 js.name, 1373 true, 1374 g_parseResult); 1375 GetValueIfFindKey<std::vector<std::string>>(jsonObject, 1376 jsonObjectEnd, 1377 BUNDLE_MODULE_PROFILE_KEY_PAGES, 1378 js.pages, 1379 JsonType::ARRAY, 1380 true, 1381 g_parseResult, 1382 ArrayType::STRING); 1383 // these are not required fields. 1384 GetValueIfFindKey<Window>(jsonObject, 1385 jsonObjectEnd, 1386 BUNDLE_MODULE_PROFILE_KEY_WINDOW, 1387 js.window, 1388 JsonType::OBJECT, 1389 false, 1390 g_parseResult, 1391 ArrayType::NOT_ARRAY); 1392 BMSJsonUtil::GetStrValueIfFindKey(jsonObject, 1393 jsonObjectEnd, 1394 PROFILE_KEY_TYPE, 1395 js.type, 1396 false, 1397 g_parseResult); 1398} 1399 1400void from_json(const nlohmann::json &jsonObject, Intent &intents) 1401{ 1402 // these are not required fields. 1403 const auto &jsonObjectEnd = jsonObject.end(); 1404 BMSJsonUtil::GetStrValueIfFindKey(jsonObject, 1405 jsonObjectEnd, 1406 BUNDLE_MODULE_PROFILE_KEY_TARGET_CLASS, 1407 intents.targetClass, 1408 false, 1409 g_parseResult); 1410 BMSJsonUtil::GetStrValueIfFindKey(jsonObject, 1411 jsonObjectEnd, 1412 BUNDLE_MODULE_PROFILE_KEY_TARGET_BUNDLE, 1413 intents.targetBundle, 1414 false, 1415 g_parseResult); 1416} 1417 1418void from_json(const nlohmann::json &jsonObject, CommonEvent &commonEvent) 1419{ 1420 // these are required fields. 1421 const auto &jsonObjectEnd = jsonObject.end(); 1422 BMSJsonUtil::GetStrValueIfFindKey(jsonObject, 1423 jsonObjectEnd, 1424 PROFILE_KEY_NAME, 1425 commonEvent.name, 1426 true, 1427 g_parseResult); 1428 GetValueIfFindKey<std::vector<std::string>>(jsonObject, 1429 jsonObjectEnd, 1430 BUNDLE_MODULE_PROFILE_KEY_EVENTS, 1431 commonEvent.events, 1432 JsonType::ARRAY, 1433 true, 1434 g_parseResult, 1435 ArrayType::STRING); 1436 // these are not required fields. 1437 BMSJsonUtil::GetStrValueIfFindKey(jsonObject, 1438 jsonObjectEnd, 1439 BUNDLE_MODULE_PROFILE_KEY_PERMISSION, 1440 commonEvent.permission, 1441 false, 1442 g_parseResult); 1443 GetValueIfFindKey<std::vector<std::string>>(jsonObject, 1444 jsonObjectEnd, 1445 BUNDLE_MODULE_PROFILE_KEY_DATA, 1446 commonEvent.data, 1447 JsonType::ARRAY, 1448 false, 1449 g_parseResult, 1450 ArrayType::STRING); 1451 GetValueIfFindKey<std::vector<std::string>>(jsonObject, 1452 jsonObjectEnd, 1453 BUNDLE_MODULE_PROFILE_KEY_TYPE, 1454 commonEvent.type, 1455 JsonType::ARRAY, 1456 false, 1457 g_parseResult, 1458 ArrayType::STRING); 1459} 1460 1461void from_json(const nlohmann::json &jsonObject, Shortcut &shortcut) 1462{ 1463 // these are required fields. 1464 const auto &jsonObjectEnd = jsonObject.end(); 1465 BMSJsonUtil::GetStrValueIfFindKey(jsonObject, 1466 jsonObjectEnd, 1467 BUNDLE_MODULE_PROFILE_KEY_SHORTCUT_ID, 1468 shortcut.shortcutId, 1469 true, 1470 g_parseResult); 1471 // these are not required fields. 1472 BMSJsonUtil::GetStrValueIfFindKey(jsonObject, 1473 jsonObjectEnd, 1474 PROFILE_KEY_LABEL, 1475 shortcut.label, 1476 false, 1477 g_parseResult); 1478 BMSJsonUtil::GetStrValueIfFindKey(jsonObject, 1479 jsonObjectEnd, 1480 BUNDLE_MODULE_PROFILE_KEY_ICON, 1481 shortcut.icon, 1482 false, 1483 g_parseResult); 1484 GetValueIfFindKey<std::vector<Intent>>(jsonObject, 1485 jsonObjectEnd, 1486 BUNDLE_MODULE_PROFILE_KEY_SHORTCUT_WANTS, 1487 shortcut.intents, 1488 JsonType::ARRAY, 1489 false, 1490 g_parseResult, 1491 ArrayType::OBJECT); 1492 // get label id 1493 GetValueIfFindKey<uint32_t>(jsonObject, 1494 jsonObjectEnd, 1495 PROFILE_KEY_LABEL_ID, 1496 shortcut.labelId, 1497 JsonType::NUMBER, 1498 false, 1499 g_parseResult, 1500 ArrayType::NOT_ARRAY); 1501 // get icon id 1502 GetValueIfFindKey<uint32_t>(jsonObject, 1503 jsonObjectEnd, 1504 BUNDLE_MODULE_PROFILE_KEY_ICON_ID, 1505 shortcut.iconId, 1506 JsonType::NUMBER, 1507 false, 1508 g_parseResult, 1509 ArrayType::NOT_ARRAY); 1510} 1511 1512void from_json(const nlohmann::json &jsonObject, Module &module) 1513{ 1514 // these are required fields. 1515 const auto &jsonObjectEnd = jsonObject.end(); 1516 BMSJsonUtil::GetStrValueIfFindKey(jsonObject, 1517 jsonObjectEnd, 1518 BUNDLE_MODULE_PROFILE_KEY_PACKAGE, 1519 module.package, 1520 false, 1521 g_parseResult); 1522 BMSJsonUtil::GetStrValueIfFindKey(jsonObject, 1523 jsonObjectEnd, 1524 PROFILE_KEY_NAME, 1525 module.name, 1526 false, 1527 g_parseResult); 1528 GetValueIfFindKey<std::vector<std::string>>(jsonObject, 1529 jsonObjectEnd, 1530 BUNDLE_MODULE_PROFILE_KEY_DEVICE_TYPE, 1531 module.deviceType, 1532 JsonType::ARRAY, 1533 true, 1534 g_parseResult, 1535 ArrayType::STRING); 1536 BMSJsonUtil::GetStrValueIfFindKey(jsonObject, 1537 jsonObjectEnd, 1538 BUNDLE_MODULE_PROFILE_KEY_COLOR_MODE, 1539 module.colorMode, 1540 false, 1541 g_parseResult); 1542 GetValueIfFindKey<Distro>(jsonObject, 1543 jsonObjectEnd, 1544 BUNDLE_MODULE_PROFILE_KEY_DISTRO, 1545 module.distro, 1546 JsonType::OBJECT, 1547 false, 1548 g_parseResult, 1549 ArrayType::NOT_ARRAY); 1550 // these are not required fields. 1551 BMSJsonUtil::GetStrValueIfFindKey(jsonObject, 1552 jsonObjectEnd, 1553 PROFILE_KEY_DESCRIPTION, 1554 module.description, 1555 false, 1556 g_parseResult); 1557 GetValueIfFindKey<uint32_t>(jsonObject, 1558 jsonObjectEnd, 1559 PROFILE_KEY_DESCRIPTION_ID, 1560 module.descriptionId, 1561 JsonType::NUMBER, 1562 false, 1563 g_parseResult, 1564 ArrayType::NOT_ARRAY); 1565 GetValueIfFindKey<std::vector<std::string>>(jsonObject, 1566 jsonObjectEnd, 1567 BUNDLE_MODULE_PROFILE_KEY_SUPPORTED_MODES, 1568 module.supportedModes, 1569 JsonType::ARRAY, 1570 false, 1571 g_parseResult, 1572 ArrayType::STRING); 1573 GetValueIfFindKey<std::vector<std::string>>(jsonObject, 1574 jsonObjectEnd, 1575 BUNDLE_MODULE_PROFILE_KEY_REQ_CAPABILITIES, 1576 module.reqCapabilities, 1577 JsonType::ARRAY, 1578 false, 1579 g_parseResult, 1580 ArrayType::STRING); 1581 GetValueIfFindKey<MetaData>(jsonObject, 1582 jsonObjectEnd, 1583 BUNDLE_MODULE_PROFILE_KEY_META_DATA, 1584 module.metaData, 1585 JsonType::OBJECT, 1586 false, 1587 g_parseResult, 1588 ArrayType::NOT_ARRAY); 1589 GetValueIfFindKey<std::vector<Ability>>(jsonObject, 1590 jsonObjectEnd, 1591 BUNDLE_MODULE_PROFILE_KEY_ABILITIES, 1592 module.abilities, 1593 JsonType::ARRAY, 1594 false, 1595 g_parseResult, 1596 ArrayType::OBJECT); 1597 GetValueIfFindKey<std::vector<Js>>(jsonObject, 1598 jsonObjectEnd, 1599 BUNDLE_MODULE_PROFILE_KEY_JS, 1600 module.jses, 1601 JsonType::ARRAY, 1602 false, 1603 g_parseResult, 1604 ArrayType::OBJECT); 1605 GetValueIfFindKey<std::vector<CommonEvent>>(jsonObject, 1606 jsonObjectEnd, 1607 BUNDLE_MODULE_PROFILE_KEY_COMMON_EVENTS, 1608 module.commonEvents, 1609 JsonType::ARRAY, 1610 false, 1611 g_parseResult, 1612 ArrayType::OBJECT); 1613 GetValueIfFindKey<std::vector<Shortcut>>(jsonObject, 1614 jsonObjectEnd, 1615 BUNDLE_MODULE_PROFILE_KEY_SHORTCUTS, 1616 module.shortcuts, 1617 JsonType::ARRAY, 1618 false, 1619 g_parseResult, 1620 ArrayType::OBJECT); 1621 GetValueIfFindKey<std::vector<RequestPermission>>(jsonObject, 1622 jsonObjectEnd, 1623 BUNDLE_MODULE_PROFILE_KEY_REQ_PERMISSIONS, 1624 module.requestPermissions, 1625 JsonType::ARRAY, 1626 false, 1627 g_parseResult, 1628 ArrayType::OBJECT); 1629 GetValueIfFindKey<std::vector<DefinePermission>>(jsonObject, 1630 jsonObjectEnd, 1631 BUNDLE_MODULE_PROFILE_KEY_DEFINE_PERMISSIONS, 1632 module.definePermissions, 1633 JsonType::ARRAY, 1634 false, 1635 g_parseResult, 1636 ArrayType::OBJECT); 1637 BMSJsonUtil::GetStrValueIfFindKey(jsonObject, 1638 jsonObjectEnd, 1639 BUNDLE_MODULE_PROFILE_KEY_MAIN_ABILITY, 1640 module.mainAbility, 1641 false, 1642 g_parseResult); 1643 BMSJsonUtil::GetStrValueIfFindKey(jsonObject, 1644 jsonObjectEnd, 1645 BUNDLE_MODULE_PROFILE_KEY_SRC_PATH, 1646 module.srcPath, 1647 false, 1648 g_parseResult); 1649 GetValueIfFindKey<std::vector<Dependency>>(jsonObject, 1650 jsonObjectEnd, 1651 BUNDLE_MODULE_DEPENDENCIES, 1652 module.dependencies, 1653 JsonType::ARRAY, 1654 false, 1655 g_parseResult, 1656 ArrayType::OBJECT); 1657 BMSJsonUtil::GetBoolValueIfFindKey(jsonObject, 1658 jsonObjectEnd, 1659 BUNDLE_MODULE_PROFILE_KEY_IS_LIB_ISOLATED, 1660 module.isLibIsolated, 1661 false, 1662 g_parseResult); 1663 BMSJsonUtil::GetStrValueIfFindKey(jsonObject, 1664 jsonObjectEnd, 1665 BUNDLE_MODULE_PROFILE_BUILD_HASH, 1666 module.buildHash, 1667 false, 1668 g_parseResult); 1669} 1670 1671void from_json(const nlohmann::json &jsonObject, ConfigJson &configJson) 1672{ 1673 // Because it does not support exceptions, every element needs to be searched first 1674 APP_LOGI("read 'App' tag from config.json"); 1675 const auto &jsonObjectEnd = jsonObject.end(); 1676 GetValueIfFindKey<App>(jsonObject, 1677 jsonObjectEnd, 1678 BUNDLE_PROFILE_KEY_APP, 1679 configJson.app, 1680 JsonType::OBJECT, 1681 true, 1682 g_parseResult, 1683 ArrayType::NOT_ARRAY); 1684 APP_LOGI("read 'DeviceConfig' tag from config.json"); 1685 GetValueIfFindKey<DeviceConfig>(jsonObject, 1686 jsonObjectEnd, 1687 BUNDLE_PROFILE_KEY_DEVICE_CONFIG, 1688 configJson.deveicConfig, 1689 JsonType::OBJECT, 1690 true, 1691 g_parseResult, 1692 ArrayType::NOT_ARRAY); 1693 APP_LOGI("read 'Module' tag from config.json"); 1694 GetValueIfFindKey<Module>(jsonObject, 1695 jsonObjectEnd, 1696 BUNDLE_PROFILE_KEY_MODULE, 1697 configJson.module, 1698 JsonType::OBJECT, 1699 true, 1700 g_parseResult, 1701 ArrayType::NOT_ARRAY); 1702 APP_LOGI("read tag from config.json"); 1703} 1704 1705} // namespace ProfileReader 1706 1707namespace { 1708struct TransformParam { 1709 bool isSystemApp = false; 1710 bool isPreInstallApp = false; 1711}; 1712 1713bool CheckBundleNameIsValid(const std::string &bundleName) 1714{ 1715 if (bundleName.empty()) { 1716 return false; 1717 } 1718 if (bundleName.size() < Constants::MIN_BUNDLE_NAME || bundleName.size() > Constants::MAX_BUNDLE_NAME) { 1719 return false; 1720 } 1721 char head = bundleName.at(0); 1722 if (head < 'A' || ('Z' < head && head < 'a') || head > 'z') { 1723 return false; 1724 } 1725 for (const auto &c : bundleName) { 1726 if (c < '.' || c == '/' || ('9' < c && c < 'A') || ('Z' < c && c < '_') || c == '`' || c > 'z') { 1727 return false; 1728 } 1729 } 1730 return true; 1731} 1732 1733bool CheckModuleNameIsValid(const std::string &moduleName) 1734{ 1735 if (moduleName.empty()) { 1736 return false; 1737 } 1738 if (moduleName.find(ServiceConstants::RELATIVE_PATH) != std::string::npos) { 1739 return false; 1740 } 1741 if (moduleName.find(ServiceConstants::MODULE_NAME_SEPARATOR) != std::string::npos) { 1742 APP_LOGE("module name should not contain ,"); 1743 return false; 1744 } 1745 return true; 1746} 1747 1748bool CheckModuleInfosIsValid(ProfileReader::ConfigJson &configJson) 1749{ 1750 if (configJson.module.deviceType.empty()) { 1751 APP_LOGE("module deviceType invalid"); 1752 return false; 1753 } 1754 if (!configJson.module.abilities.empty()) { 1755 for (const auto &ability : configJson.module.abilities) { 1756 if (ability.name.empty() || ability.type.empty()) { 1757 APP_LOGE("ability name or type invalid"); 1758 return false; 1759 } 1760 } 1761 } 1762 if (configJson.app.version.code <= 0) { 1763 APP_LOGE("version code invalid"); 1764 return false; 1765 } 1766 auto iter = 1767 std::find_if(configJson.module.deviceType.begin(), configJson.module.deviceType.end(), [](const auto &d) { 1768 return ((d.compare(ProfileReader::BUNDLE_DEVICE_CONFIG_PROFILE_KEY_LITE_WEARABLE) == 0 || 1769 d.compare(ProfileReader::BUNDLE_DEVICE_CONFIG_PROFILE_KEY_SMART_VISION) == 0)); 1770 }); 1771 if (iter != configJson.module.deviceType.end()) { 1772 APP_LOGE("this is a lite device app, ignores other check"); 1773 // if lite device hap doesn't have a module package name, assign it as bundle name. 1774 if (configJson.module.package.empty()) { 1775 configJson.module.package = configJson.app.bundleName; 1776 } 1777 return true; 1778 } 1779 if (!CheckModuleNameIsValid(configJson.module.package)) { 1780 APP_LOGE("module package invalid"); 1781 return false; 1782 } 1783 if (!CheckModuleNameIsValid(configJson.module.distro.moduleName)) { 1784 APP_LOGE("module distro invalid"); 1785 return false; 1786 } 1787 return true; 1788} 1789uint32_t GetFormEntity(const std::vector<std::string> &formEntity) 1790{ 1791 static std::map<std::string, uint32_t> formEntityMap; 1792 if (formEntityMap.empty()) { 1793 formEntityMap.insert({ProfileReader::KEY_HOME_SCREEN, ProfileReader::VALUE_HOME_SCREEN}); 1794 formEntityMap.insert({ProfileReader::KEY_SEARCHBOX, ProfileReader::VALUE_SEARCHBOX}); 1795 } 1796 1797 uint32_t formEntityInBinary = 0; 1798 for (const auto &item : formEntity) { 1799 if (formEntityMap.find(item) != formEntityMap.end()) { 1800 formEntityInBinary |= formEntityMap[item]; 1801 } 1802 } 1803 return formEntityInBinary; 1804} 1805 1806bool ConvertFormInfo(FormInfo &formInfo, const ProfileReader::Forms &form) 1807{ 1808 formInfo.name = form.name; 1809 formInfo.description = form.description; 1810 formInfo.descriptionId = form.descriptionId; 1811 formInfo.formConfigAbility = form.formConfigAbility; 1812 formInfo.formVisibleNotify = form.formVisibleNotify; 1813 formInfo.deepLink = form.deepLink; 1814 formInfo.defaultFlag = form.isDefault; 1815 auto type = std::find_if(std::begin(ProfileReader::formTypeMap), 1816 std::end(ProfileReader::formTypeMap), 1817 [&form](const auto &item) { return item.first == form.type; }); 1818 if (type != ProfileReader::formTypeMap.end()) { 1819 formInfo.type = type->second; 1820 } 1821 auto colorMode = std::find_if(std::begin(ProfileReader::formColorModeMap), 1822 std::end(ProfileReader::formColorModeMap), 1823 [&form](const auto &item) { return item.first == form.colorMode; }); 1824 if (colorMode != ProfileReader::formColorModeMap.end()) { 1825 formInfo.colorMode = colorMode->second; 1826 } 1827 formInfo.updateEnabled = form.updateEnabled; 1828 formInfo.scheduledUpdateTime = form.scheduledUpdateTime; 1829 formInfo.updateDuration = form.updateDuration; 1830 formInfo.jsComponentName = form.jsComponentName; 1831 for (const auto &data : form.metaData.customizeData) { 1832 FormCustomizeData customizeData; 1833 customizeData.name = data.name; 1834 customizeData.value = data.value; 1835 formInfo.customizeDatas.emplace_back(customizeData); 1836 } 1837 for (const auto &dimensions : form.supportDimensions) { 1838 auto dimension = std::find_if(std::begin(ProfileReader::dimensionMap), 1839 std::end(ProfileReader::dimensionMap), 1840 [&dimensions](const auto &item) { return item.first == dimensions; }); 1841 if (dimension != ProfileReader::dimensionMap.end()) { 1842 formInfo.supportDimensions.emplace_back(dimension->second); 1843 } 1844 } 1845 auto dimension = std::find_if(std::begin(ProfileReader::dimensionMap), 1846 std::end(ProfileReader::dimensionMap), 1847 [&form](const auto &item) { return item.first == form.defaultDimension; }); 1848 if (dimension != ProfileReader::dimensionMap.end()) { 1849 formInfo.defaultDimension = dimension->second; 1850 } 1851 formInfo.landscapeLayouts = form.landscapeLayouts; 1852 formInfo.portraitLayouts = form.portraitLayouts; 1853 formInfo.src = form.src; 1854 formInfo.window.autoDesignWidth = form.window.autoDesignWidth; 1855 formInfo.window.designWidth = form.window.designWidth; 1856 return true; 1857} 1858 1859void UpdateNativeSoAttrs( 1860 const std::string &cpuAbi, 1861 const std::string &soRelativePath, 1862 bool isLibIsolated, 1863 InnerBundleInfo &innerBundleInfo) 1864{ 1865 APP_LOGD("cpuAbi %{public}s, soRelativePath : %{public}s, isLibIsolated : %{public}d", 1866 cpuAbi.c_str(), soRelativePath.c_str(), isLibIsolated); 1867 innerBundleInfo.SetCpuAbi(cpuAbi); 1868 if (!innerBundleInfo.IsCompressNativeLibs(innerBundleInfo.GetCurModuleName())) { 1869 APP_LOGD("UpdateNativeSoAttrs compressNativeLibs is false, no need to decompress so"); 1870 if (!isLibIsolated) { 1871 innerBundleInfo.SetNativeLibraryPath(soRelativePath); 1872 } 1873 if (!soRelativePath.empty()) { 1874 innerBundleInfo.SetModuleNativeLibraryPath(ServiceConstants::LIBS + cpuAbi); 1875 innerBundleInfo.SetSharedModuleNativeLibraryPath(ServiceConstants::LIBS + cpuAbi); 1876 } 1877 innerBundleInfo.SetModuleCpuAbi(cpuAbi); 1878 return; 1879 } 1880 if (!isLibIsolated) { 1881 innerBundleInfo.SetNativeLibraryPath(soRelativePath); 1882 return; 1883 } 1884 1885 innerBundleInfo.SetModuleNativeLibraryPath( 1886 innerBundleInfo.GetCurModuleName() + ServiceConstants::PATH_SEPARATOR + soRelativePath); 1887 innerBundleInfo.SetModuleCpuAbi(cpuAbi); 1888} 1889 1890bool ParserNativeSo( 1891 const ProfileReader::ConfigJson &configJson, 1892 const BundleExtractor &bundleExtractor, 1893 InnerBundleInfo &innerBundleInfo) 1894{ 1895 std::string abis = GetAbiList(); 1896 std::vector<std::string> abiList; 1897 SplitStr(abis, ServiceConstants::ABI_SEPARATOR, abiList, false, false); 1898 if (abiList.empty()) { 1899 APP_LOGD("Abi is empty"); 1900 return false; 1901 } 1902 1903 bool isDefault = 1904 std::find(abiList.begin(), abiList.end(), ServiceConstants::ABI_DEFAULT) != abiList.end(); 1905 bool isSystemLib64Exist = BundleUtil::IsExistDir(ServiceConstants::SYSTEM_LIB64); 1906 APP_LOGD("abi list : %{public}s, isDefault : %{public}d", abis.c_str(), isDefault); 1907 std::string cpuAbi; 1908 std::string soRelativePath; 1909 bool soExist = bundleExtractor.IsDirExist(ServiceConstants::LIBS); 1910 if (!soExist) { 1911 APP_LOGD("so not exist"); 1912 if (isDefault) { 1913 cpuAbi = isSystemLib64Exist ? ServiceConstants::ARM64_V8A : ServiceConstants::ARM_EABI_V7A; 1914 UpdateNativeSoAttrs(cpuAbi, soRelativePath, false, innerBundleInfo); 1915 return true; 1916 } 1917 1918 for (const auto &abi : abiList) { 1919 if (ServiceConstants::ABI_MAP.find(abi) != ServiceConstants::ABI_MAP.end()) { 1920 cpuAbi = abi; 1921 UpdateNativeSoAttrs(cpuAbi, soRelativePath, false, innerBundleInfo); 1922 return true; 1923 } 1924 } 1925 1926 return false; 1927 } 1928 1929 APP_LOGD("so exist"); 1930 bool isLibIsolated = configJson.module.isLibIsolated; 1931 if (isDefault) { 1932 if (isSystemLib64Exist) { 1933 if (bundleExtractor.IsDirExist(std::string(ServiceConstants::LIBS) + ServiceConstants::ARM64_V8A)) { 1934 cpuAbi = ServiceConstants::ARM64_V8A; 1935 soRelativePath = ServiceConstants::LIBS + ServiceConstants::ABI_MAP.at(ServiceConstants::ARM64_V8A); 1936 UpdateNativeSoAttrs(cpuAbi, soRelativePath, isLibIsolated, innerBundleInfo); 1937 return true; 1938 } 1939 1940 return false; 1941 } 1942 1943 if (bundleExtractor.IsDirExist(std::string(ServiceConstants::LIBS) + ServiceConstants::ARM_EABI_V7A)) { 1944 cpuAbi = ServiceConstants::ARM_EABI_V7A; 1945 soRelativePath = ServiceConstants::LIBS + ServiceConstants::ABI_MAP.at(ServiceConstants::ARM_EABI_V7A); 1946 UpdateNativeSoAttrs(cpuAbi, soRelativePath, isLibIsolated, innerBundleInfo); 1947 return true; 1948 } 1949 1950 if (bundleExtractor.IsDirExist(std::string(ServiceConstants::LIBS) + ServiceConstants::ARM_EABI)) { 1951 cpuAbi = ServiceConstants::ARM_EABI; 1952 soRelativePath = ServiceConstants::LIBS + ServiceConstants::ABI_MAP.at(ServiceConstants::ARM_EABI); 1953 UpdateNativeSoAttrs(cpuAbi, soRelativePath, isLibIsolated, innerBundleInfo); 1954 return true; 1955 } 1956 1957 return false; 1958 } 1959 1960 for (const auto &abi : abiList) { 1961 std::string libsPath; 1962 libsPath.append(ServiceConstants::LIBS).append(abi).append(ServiceConstants::PATH_SEPARATOR); 1963 if (ServiceConstants::ABI_MAP.find(abi) != ServiceConstants::ABI_MAP.end() && 1964 bundleExtractor.IsDirExist(libsPath)) { 1965 cpuAbi = abi; 1966 soRelativePath = ServiceConstants::LIBS + ServiceConstants::ABI_MAP.at(abi); 1967 UpdateNativeSoAttrs(cpuAbi, soRelativePath, isLibIsolated, innerBundleInfo); 1968 return true; 1969 } 1970 } 1971 1972 return false; 1973} 1974 1975bool ToApplicationInfo( 1976 const ProfileReader::ConfigJson &configJson, 1977 const BundleExtractor &bundleExtractor, 1978 const TransformParam &transformParam, 1979 ApplicationInfo &applicationInfo) 1980{ 1981 APP_LOGD("transform ConfigJson to ApplicationInfo"); 1982 applicationInfo.name = configJson.app.bundleName; 1983 applicationInfo.bundleName = configJson.app.bundleName; 1984 1985 applicationInfo.versionCode = static_cast<uint32_t>(configJson.app.version.code); 1986 applicationInfo.versionName = configJson.app.version.name; 1987 if (configJson.app.version.minCompatibleVersionCode != -1) { 1988 applicationInfo.minCompatibleVersionCode = configJson.app.version.minCompatibleVersionCode; 1989 } else { 1990 applicationInfo.minCompatibleVersionCode = static_cast<int32_t>(applicationInfo.versionCode); 1991 } 1992 1993 applicationInfo.apiCompatibleVersion = configJson.app.apiVersion.compatible; 1994 applicationInfo.apiTargetVersion = configJson.app.apiVersion.target; 1995 applicationInfo.apiReleaseType = configJson.app.apiVersion.releaseType; 1996 applicationInfo.asanEnabled = configJson.app.asanEnabled; 1997 applicationInfo.compileSdkVersion = configJson.app.apiVersion.compileSdkVersion; 1998 applicationInfo.compileSdkType = configJson.app.apiVersion.compileSdkType; 1999 2000 // if there is main ability, it's icon label description will be set to applicationInfo. 2001 2002 if (transformParam.isSystemApp && transformParam.isPreInstallApp) { 2003 applicationInfo.keepAlive = configJson.deveicConfig.defaultDevice.keepAlive; 2004 applicationInfo.singleton = configJson.app.singleton; 2005 applicationInfo.userDataClearable = configJson.app.userDataClearable; 2006 if (configJson.app.removable.first) { 2007 applicationInfo.removable = configJson.app.removable.second; 2008 } else { 2009 applicationInfo.removable = false; 2010 } 2011 } 2012 2013 applicationInfo.debug = configJson.deveicConfig.defaultDevice.debug; 2014 applicationInfo.deviceId = ServiceConstants::CURRENT_DEVICE_ID; 2015 applicationInfo.distributedNotificationEnabled = true; 2016 applicationInfo.entityType = Profile::APP_ENTITY_TYPE_DEFAULT_VALUE; 2017 applicationInfo.process = configJson.deveicConfig.defaultDevice.process; 2018 2019 auto it = find(configJson.module.supportedModes.begin(), 2020 configJson.module.supportedModes.end(), 2021 ProfileReader::MODULE_SUPPORTED_MODES_VALUE_DRIVE); 2022 if (it != configJson.module.supportedModes.end()) { 2023 applicationInfo.supportedModes = 1; 2024 } else { 2025 applicationInfo.supportedModes = 0; 2026 } 2027 applicationInfo.vendor = configJson.app.vendor; 2028 2029 // for SystemResource 2030 applicationInfo.iconId = configJson.app.iconId; 2031 applicationInfo.labelId = configJson.app.labelId; 2032 applicationInfo.iconResource = BundleUtil::GetResource( 2033 configJson.app.bundleName, configJson.module.distro.moduleName, configJson.app.iconId); 2034 applicationInfo.labelResource = BundleUtil::GetResource( 2035 configJson.app.bundleName, configJson.module.distro.moduleName, configJson.app.labelId); 2036 2037 applicationInfo.enabled = true; 2038 for (const auto &targetBundle : configJson.app.targetBundleList) { 2039 APP_LOGD("targetBundle = %{public}s", targetBundle.c_str()); 2040 applicationInfo.targetBundleList.emplace_back(targetBundle); 2041 } 2042 2043 if (configJson.module.distro.moduleType.compare(ProfileReader::MODULE_DISTRO_MODULE_TYPE_VALUE_ENTRY) == 0) { 2044 applicationInfo.description = configJson.module.description; 2045 applicationInfo.descriptionId = configJson.module.descriptionId; 2046 applicationInfo.descriptionResource = BundleUtil::GetResource( 2047 configJson.app.bundleName, configJson.module.distro.moduleName, configJson.module.descriptionId); 2048 } 2049 return true; 2050} 2051 2052bool ToBundleInfo( 2053 const ProfileReader::ConfigJson &configJson, 2054 const ApplicationInfo &applicationInfo, 2055 const InnerModuleInfo &innerModuleInfo, 2056 const TransformParam &transformParam, 2057 BundleInfo &bundleInfo) 2058{ 2059 bundleInfo.name = applicationInfo.bundleName; 2060 2061 bundleInfo.versionCode = static_cast<uint32_t>(applicationInfo.versionCode); 2062 bundleInfo.versionName = applicationInfo.versionName; 2063 bundleInfo.minCompatibleVersionCode = static_cast<uint32_t>(applicationInfo.minCompatibleVersionCode); 2064 2065 bundleInfo.compatibleVersion = static_cast<uint32_t>(applicationInfo.apiCompatibleVersion); 2066 bundleInfo.targetVersion = static_cast<uint32_t>(applicationInfo.apiTargetVersion); 2067 2068 bundleInfo.isKeepAlive = applicationInfo.keepAlive; 2069 bundleInfo.singleton = applicationInfo.singleton; 2070 bundleInfo.isPreInstallApp = transformParam.isPreInstallApp; 2071 2072 bundleInfo.vendor = applicationInfo.vendor; 2073 bundleInfo.releaseType = applicationInfo.apiReleaseType; 2074 if (configJson.module.jses.empty()) { 2075 bundleInfo.isNativeApp = true; 2076 } 2077 2078 if (innerModuleInfo.isEntry) { 2079 bundleInfo.mainEntry = innerModuleInfo.modulePackage; 2080 bundleInfo.entryModuleName = innerModuleInfo.moduleName; 2081 } 2082 2083 return true; 2084} 2085 2086void GetMetaData(MetaData &metaData, const ProfileReader::MetaData &profileMetaData) 2087{ 2088 for (const auto &item : profileMetaData.customizeData) { 2089 CustomizeData customizeData; 2090 customizeData.name = item.name; 2091 customizeData.extra = item.extra; 2092 customizeData.value = item.value; 2093 metaData.customizeData.emplace_back(customizeData); 2094 } 2095} 2096 2097uint32_t GetBackgroundModes(const std::vector<std::string>& backgroundModes) 2098{ 2099 uint32_t backgroundMode = 0; 2100 size_t len = sizeof(ProfileReader::BACKGROUND_MODE_MAP_KEY) / 2101 sizeof(ProfileReader::BACKGROUND_MODE_MAP_KEY[0]); 2102 for (const auto& item : backgroundModes) { 2103 for (size_t i = 0; i < len; i++) { 2104 if (item == ProfileReader::BACKGROUND_MODE_MAP_KEY[i]) { 2105 backgroundMode |= ProfileReader::BACKGROUND_MODE_MAP_VALUE[i]; 2106 break; 2107 } 2108 } 2109 } 2110 return backgroundMode; 2111} 2112 2113bool CheckDefinePermissions(const std::vector<DefinePermission> &definePermissions) 2114{ 2115 for (const auto &definePermission : definePermissions) { 2116 if (!definePermission.availableType.empty() && 2117 definePermission.availableType != Profile::DEFINEPERMISSION_AVAILABLE_TYPE_MDM) { 2118 APP_LOGE("availableType(%{public}s) invalid", definePermission.availableType.c_str()); 2119 return false; 2120 } 2121 } 2122 return true; 2123} 2124 2125bool ToInnerModuleInfo(const ProfileReader::ConfigJson &configJson, InnerModuleInfo &innerModuleInfo) 2126{ 2127 if (configJson.module.name.substr(0, 1) == ".") { 2128 innerModuleInfo.name = configJson.module.package + configJson.module.name; 2129 } else { 2130 innerModuleInfo.name = configJson.module.name; 2131 } 2132 innerModuleInfo.modulePackage = configJson.module.package; 2133 innerModuleInfo.moduleName = configJson.module.distro.moduleName; 2134 innerModuleInfo.installationFree = configJson.module.distro.installationFree; 2135 innerModuleInfo.description = configJson.module.description; 2136 innerModuleInfo.descriptionId = configJson.module.descriptionId; 2137 auto colorModeInfo = std::find_if(std::begin(ProfileReader::moduleColorMode), 2138 std::end(ProfileReader::moduleColorMode), 2139 [&configJson](const auto &item) { return item.first == configJson.module.colorMode; }); 2140 if (colorModeInfo != ProfileReader::moduleColorMode.end()) { 2141 innerModuleInfo.colorMode = colorModeInfo->second; 2142 } 2143 GetMetaData(innerModuleInfo.metaData, configJson.module.metaData); 2144 innerModuleInfo.distro = configJson.module.distro; 2145 innerModuleInfo.reqCapabilities = configJson.module.reqCapabilities; 2146 innerModuleInfo.requestPermissions = configJson.module.requestPermissions; 2147 if (configJson.app.bundleName == Profile::SYSTEM_RESOURCES_APP) { 2148 if (!CheckDefinePermissions(configJson.module.definePermissions)) { 2149 APP_LOGE("CheckDefinePermissions failed"); 2150 return false; 2151 } 2152 innerModuleInfo.definePermissions = configJson.module.definePermissions; 2153 } 2154 if (configJson.module.mainAbility.substr(0, 1) == ".") { 2155 innerModuleInfo.mainAbility = configJson.module.package + configJson.module.mainAbility; 2156 } else { 2157 innerModuleInfo.mainAbility = configJson.module.mainAbility; 2158 } 2159 innerModuleInfo.srcPath = configJson.module.srcPath; 2160 std::string moduleType = innerModuleInfo.distro.moduleType; 2161 if (ProfileReader::MODULE_TYPE_SET.find(moduleType) != ProfileReader::MODULE_TYPE_SET.end()) { 2162 if (moduleType == ProfileReader::MODULE_DISTRO_MODULE_TYPE_VALUE_ENTRY) { 2163 innerModuleInfo.isEntry = true; 2164 } 2165 } 2166 innerModuleInfo.dependencies = configJson.module.dependencies; 2167 2168 innerModuleInfo.isModuleJson = false; 2169 innerModuleInfo.isLibIsolated = configJson.module.isLibIsolated; 2170 innerModuleInfo.deviceTypes = configJson.module.deviceType; 2171 innerModuleInfo.buildHash = configJson.module.buildHash; 2172 innerModuleInfo.compressNativeLibs = configJson.deveicConfig.defaultDevice.compressNativeLibs; 2173 return true; 2174} 2175 2176bool ToAbilityInfo( 2177 const ProfileReader::ConfigJson &configJson, 2178 const ProfileReader::Ability &ability, 2179 const TransformParam &transformParam, 2180 AbilityInfo &abilityInfo) 2181{ 2182 abilityInfo.name = ability.name; 2183 if (ability.srcLanguage != "c++" && ability.name.substr(0, 1) == ".") { 2184 abilityInfo.name = configJson.module.package + ability.name; 2185 } 2186 abilityInfo.label = ability.label; 2187 abilityInfo.description = ability.description; 2188 abilityInfo.iconPath = ability.icon; 2189 abilityInfo.labelId = ability.labelId; 2190 abilityInfo.descriptionId = ability.descriptionId; 2191 abilityInfo.iconId = ability.iconId; 2192 abilityInfo.visible = ability.visible; 2193 abilityInfo.continuable = ability.continuable; 2194 abilityInfo.kind = ability.type; 2195 abilityInfo.srcPath = ability.srcPath; 2196 abilityInfo.srcLanguage = ability.srcLanguage; 2197 abilityInfo.priority = ability.priority; 2198 2199 std::transform( 2200 abilityInfo.srcLanguage.begin(), abilityInfo.srcLanguage.end(), abilityInfo.srcLanguage.begin(), ::tolower); 2201 if (abilityInfo.srcLanguage != ProfileReader::BUNDLE_MODULE_PROFILE_KEY_JS && 2202 abilityInfo.srcLanguage != ProfileReader::BUNDLE_MODULE_PROFILE_KEY_JS_TYPE_ETS) { 2203 abilityInfo.isNativeAbility = true; 2204 } 2205 auto iterType = std::find_if(std::begin(ProfileReader::ABILITY_TYPE_MAP), 2206 std::end(ProfileReader::ABILITY_TYPE_MAP), 2207 [&ability](const auto &item) { return item.first == ability.type; }); 2208 if (iterType != ProfileReader::ABILITY_TYPE_MAP.end()) { 2209 abilityInfo.type = iterType->second; 2210 } else { 2211 APP_LOGE("ability type invalid"); 2212 return false; 2213 } 2214 2215 auto iterOrientation = std::find_if(std::begin(ProfileReader::DISPLAY_ORIENTATION_MAP), 2216 std::end(ProfileReader::DISPLAY_ORIENTATION_MAP), 2217 [&ability](const auto &item) { return item.first == ability.orientation; }); 2218 if (iterOrientation != ProfileReader::DISPLAY_ORIENTATION_MAP.end()) { 2219 abilityInfo.orientation = iterOrientation->second; 2220 } 2221 2222 auto iterLaunch = std::find_if(std::begin(ProfileReader::LAUNCH_MODE_MAP), 2223 std::end(ProfileReader::LAUNCH_MODE_MAP), 2224 [&ability](const auto &item) { return item.first == ability.launchType; }); 2225 if (iterLaunch != ProfileReader::LAUNCH_MODE_MAP.end()) { 2226 abilityInfo.launchMode = iterLaunch->second; 2227 } 2228 2229 for (const auto &permission : ability.permissions) { 2230 abilityInfo.permissions.emplace_back(permission); 2231 } 2232 abilityInfo.process = (ability.process.empty()) ? configJson.app.bundleName : ability.process; 2233 abilityInfo.theme = ability.theme; 2234 abilityInfo.deviceTypes = configJson.module.deviceType; 2235 abilityInfo.deviceCapabilities = ability.deviceCapability; 2236 if (iterType->second == AbilityType::DATA && 2237 ability.uri.find(ServiceConstants::DATA_ABILITY_URI_PREFIX) == std::string::npos) { 2238 APP_LOGE("ability uri invalid"); 2239 return false; 2240 } 2241 abilityInfo.uri = ability.uri; 2242 abilityInfo.package = configJson.module.package; 2243 abilityInfo.bundleName = configJson.app.bundleName; 2244 abilityInfo.moduleName = configJson.module.distro.moduleName; 2245 abilityInfo.applicationName = configJson.app.bundleName; 2246 abilityInfo.targetAbility = ability.targetAbility; 2247 abilityInfo.enabled = true; 2248 abilityInfo.supportPipMode = ability.supportPipMode; 2249 abilityInfo.readPermission = ability.readPermission; 2250 abilityInfo.writePermission = ability.writePermission; 2251 abilityInfo.configChanges = ability.configChanges; 2252 abilityInfo.formEntity = GetFormEntity(ability.form.formEntity); 2253 abilityInfo.minFormHeight = ability.form.minHeight; 2254 abilityInfo.defaultFormHeight = ability.form.defaultHeight; 2255 abilityInfo.minFormWidth = ability.form.minWidth; 2256 abilityInfo.defaultFormWidth = ability.form.defaultWidth; 2257 GetMetaData(abilityInfo.metaData, ability.metaData); 2258 abilityInfo.formEnabled = ability.formsEnabled; 2259 abilityInfo.backgroundModes = GetBackgroundModes(ability.backgroundModes); 2260 abilityInfo.isModuleJson = false; 2261 abilityInfo.startWindowIcon = ability.startWindowIcon; 2262 abilityInfo.startWindowIconId = ability.startWindowIconId; 2263 abilityInfo.startWindowBackground = ability.startWindowBackground; 2264 abilityInfo.startWindowBackgroundId = ability.startWindowBackgroundId; 2265 abilityInfo.removeMissionAfterTerminate = ability.removeMissionAfterTerminate; 2266 return true; 2267} 2268 2269bool ToInnerBundleInfo( 2270 ProfileReader::ConfigJson &configJson, 2271 const BundleExtractor &bundleExtractor, 2272 InnerBundleInfo &innerBundleInfo) 2273{ 2274 APP_LOGD("transform profile configJson to innerBundleInfo"); 2275 if (!CheckBundleNameIsValid(configJson.app.bundleName)) { 2276 APP_LOGE("bundle name is invalid"); 2277 return false; 2278 } 2279 if (!CheckModuleInfosIsValid(configJson)) { 2280 APP_LOGE("module infos is invalid"); 2281 return false; 2282 } 2283 2284 TransformParam transformParam; 2285 transformParam.isPreInstallApp = innerBundleInfo.IsPreInstallApp(); 2286 2287 ApplicationInfo applicationInfo; 2288 applicationInfo.isSystemApp = innerBundleInfo.GetAppType() == Constants::AppType::SYSTEM_APP; 2289 transformParam.isSystemApp = applicationInfo.isSystemApp; 2290 applicationInfo.isCompressNativeLibs = configJson.deveicConfig.defaultDevice.compressNativeLibs; 2291 if (!ToApplicationInfo(configJson, bundleExtractor, transformParam, applicationInfo)) { 2292 APP_LOGE("To applicationInfo failed"); 2293 return false; 2294 } 2295 2296 InnerModuleInfo innerModuleInfo; 2297 ToInnerModuleInfo(configJson, innerModuleInfo); 2298 2299 if (applicationInfo.apiTargetVersion % ServiceConstants::API_VERSION_MOD <= 2300 ServiceConstants::API_VERSION_THIRTEEN) { 2301 APP_LOGD("targetAPIVersion is less than 14, set isCompressNativeLibs flag to true"); 2302 applicationInfo.isCompressNativeLibs = true; 2303 innerModuleInfo.compressNativeLibs = true; 2304 } 2305 BundleInfo bundleInfo; 2306 ToBundleInfo(configJson, applicationInfo, innerModuleInfo, transformParam, bundleInfo); 2307 2308 for (const auto &info : configJson.module.shortcuts) { 2309 ShortcutInfo shortcutInfo; 2310 shortcutInfo.id = info.shortcutId; 2311 shortcutInfo.bundleName = configJson.app.bundleName; 2312 shortcutInfo.moduleName = configJson.module.distro.moduleName; 2313 shortcutInfo.icon = info.icon; 2314 shortcutInfo.label = info.label; 2315 shortcutInfo.iconId = info.iconId; 2316 shortcutInfo.labelId = info.labelId; 2317 for (const auto &intent : info.intents) { 2318 ShortcutIntent shortcutIntent; 2319 shortcutIntent.targetBundle = intent.targetBundle; 2320 shortcutIntent.targetModule = Constants::EMPTY_STRING; 2321 shortcutIntent.targetClass = intent.targetClass; 2322 shortcutInfo.intents.emplace_back(shortcutIntent); 2323 } 2324 std::string shortcutkey; 2325 shortcutkey.append(configJson.app.bundleName).append(".") 2326 .append(configJson.module.package).append(".").append(info.shortcutId); 2327 innerBundleInfo.InsertShortcutInfos(shortcutkey, shortcutInfo); 2328 } 2329 if (innerBundleInfo.GetAppType() == Constants::AppType::SYSTEM_APP) { 2330 for (const auto &info : configJson.module.commonEvents) { 2331 CommonEventInfo commonEvent; 2332 commonEvent.name = info.name; 2333 commonEvent.bundleName = configJson.app.bundleName; 2334 commonEvent.permission = info.permission; 2335 commonEvent.data = info.data; 2336 commonEvent.type = info.type; 2337 commonEvent.events = info.events; 2338 std::string commonEventKey; 2339 commonEventKey.append(configJson.app.bundleName).append(".") 2340 .append(configJson.module.package).append(".").append(info.name); 2341 innerBundleInfo.InsertCommonEvents(commonEventKey, commonEvent); 2342 } 2343 } 2344 auto entryActionMatcher = [] (const std::string &action) { 2345 return action == Constants::ACTION_HOME || action == Constants::WANT_ACTION_HOME; 2346 }; 2347 bool find = false; 2348 bool isExistPageAbility = false; 2349 for (const auto &ability : configJson.module.abilities) { 2350 AbilityInfo abilityInfo; 2351 if (!ToAbilityInfo(configJson, ability, transformParam, abilityInfo)) { 2352 APP_LOGE("parse to abilityInfo failed"); 2353 return false; 2354 } 2355 bool isMainAbility = false; 2356 if (innerModuleInfo.mainAbility == abilityInfo.name) { 2357 innerModuleInfo.icon = abilityInfo.iconPath; 2358 innerModuleInfo.iconId = abilityInfo.iconId; 2359 innerModuleInfo.label = abilityInfo.label; 2360 innerModuleInfo.labelId = abilityInfo.labelId; 2361 isMainAbility = true; 2362 } 2363 if (abilityInfo.type == AbilityType::PAGE) { 2364 isExistPageAbility = true; 2365 } 2366 std::string keyName; 2367 keyName.append(configJson.app.bundleName).append(".") 2368 .append(configJson.module.package).append(".").append(abilityInfo.name); 2369 innerModuleInfo.abilityKeys.emplace_back(keyName); 2370 innerModuleInfo.skillKeys.emplace_back(keyName); 2371 innerBundleInfo.InsertSkillInfo(keyName, ability.skills); 2372 std::vector<FormInfo> formInfos; 2373 for (const auto &form : ability.formses) { 2374 FormInfo formInfo; 2375 ConvertFormInfo(formInfo, form); 2376 formInfo.abilityName = ability.name; 2377 if (ability.srcLanguage != "c++" && ability.name.substr(0, 1) == ".") { 2378 formInfo.abilityName = configJson.module.package + ability.name; 2379 } 2380 formInfo.bundleName = configJson.app.bundleName; 2381 formInfo.moduleName = configJson.module.distro.moduleName; 2382 formInfo.package = configJson.module.package; 2383 formInfo.originalBundleName = configJson.app.originalName; 2384 formInfos.emplace_back(formInfo); 2385 } 2386 innerBundleInfo.InsertFormInfos(keyName, formInfos); 2387 if (!find || isMainAbility) { 2388 for (const auto &skill : ability.skills) { 2389 bool isEntryAction = std::find_if(skill.actions.begin(), skill.actions.end(), 2390 entryActionMatcher) != skill.actions.end(); 2391 bool isEntryEntity = std::find(skill.entities.begin(), skill.entities.end(), 2392 Constants::ENTITY_HOME) != skill.entities.end(); 2393 if (isEntryAction && isEntryEntity && (!find || isMainAbility)) { 2394 innerModuleInfo.entryAbilityKey = keyName; 2395 // if there is main ability, it's label will be the application's label 2396 applicationInfo.label = ability.label; 2397 applicationInfo.labelId = ability.labelId; 2398 applicationInfo.iconPath = ability.icon; 2399 applicationInfo.iconId = ability.iconId; 2400 applicationInfo.iconResource = BundleUtil::GetResource( 2401 configJson.app.bundleName, configJson.module.distro.moduleName, ability.iconId); 2402 applicationInfo.labelResource = BundleUtil::GetResource( 2403 configJson.app.bundleName, configJson.module.distro.moduleName, ability.labelId); 2404 find = true; 2405 } 2406 if (std::find(skill.entities.begin(), skill.entities.end(), 2407 ServiceConstants::FLAG_HOME_INTENT_FROM_SYSTEM) != 2408 skill.entities.end() && transformParam.isPreInstallApp && 2409 (abilityInfo.type == AbilityType::PAGE)) { 2410 applicationInfo.isLauncherApp = true; 2411 abilityInfo.isLauncherAbility = true; 2412 } 2413 } 2414 } 2415 innerBundleInfo.InsertAbilitiesInfo(keyName, abilityInfo); 2416 } 2417 if ((!find || !isExistPageAbility) && !transformParam.isPreInstallApp) { 2418 applicationInfo.needAppDetail = true; 2419 if (BundleUtil::IsExistDir(ServiceConstants::SYSTEM_LIB64)) { 2420 applicationInfo.appDetailAbilityLibraryPath = Profile::APP_DETAIL_ABILITY_LIBRARY_PATH_64; 2421 } else { 2422 applicationInfo.appDetailAbilityLibraryPath = Profile::APP_DETAIL_ABILITY_LIBRARY_PATH; 2423 } 2424 if ((applicationInfo.labelId == 0) && (applicationInfo.label.empty())) { 2425 applicationInfo.label = applicationInfo.bundleName; 2426 } 2427 } 2428 innerBundleInfo.SetCurrentModulePackage(configJson.module.package); 2429 innerBundleInfo.SetBaseApplicationInfo(applicationInfo); 2430 innerBundleInfo.SetBaseBundleInfo(bundleInfo); 2431 innerBundleInfo.InsertInnerModuleInfo(configJson.module.package, innerModuleInfo); 2432 if (innerBundleInfo.GetEntryInstallationFree()) { 2433 innerBundleInfo.SetApplicationBundleType(BundleType::ATOMIC_SERVICE); 2434 } 2435 return true; 2436} 2437 2438} // namespace 2439 2440ErrCode BundleProfile::TransformTo( 2441 const std::ostringstream &source, 2442 const BundleExtractor &bundleExtractor, 2443 InnerBundleInfo &innerBundleInfo) const 2444{ 2445 APP_LOGI("transform profile stream to bundle info"); 2446 nlohmann::json jsonObject = nlohmann::json::parse(source.str(), nullptr, false); 2447 if (jsonObject.is_discarded()) { 2448 APP_LOGE("bad profile"); 2449 return ERR_APPEXECFWK_PARSE_BAD_PROFILE; 2450 } 2451 ProfileReader::ConfigJson configJson; 2452 { 2453 std::lock_guard<std::mutex> lock(ProfileReader::g_mutex); 2454 ProfileReader::g_parseResult = ERR_OK; 2455 configJson = jsonObject.get<ProfileReader::ConfigJson>(); 2456 if (ProfileReader::g_parseResult != ERR_OK) { 2457 APP_LOGE("g_parseResult %{public}d", ProfileReader::g_parseResult); 2458 int32_t ret = ProfileReader::g_parseResult; 2459 // need recover parse result to ERR_OK 2460 ProfileReader::g_parseResult = ERR_OK; 2461 return ret; 2462 } 2463 } 2464 if (!ToInnerBundleInfo( 2465 configJson, bundleExtractor, innerBundleInfo)) { 2466 return ERR_APPEXECFWK_PARSE_PROFILE_PROP_CHECK_ERROR; 2467 } 2468 if (!ParserNativeSo(configJson, bundleExtractor, innerBundleInfo)) { 2469#ifdef X86_EMULATOR_MODE 2470 APP_LOGE("Parser native so failed"); 2471 return ERR_APPEXECFWK_PARSE_NATIVE_SO_FAILED; 2472#endif 2473 APP_LOGW("Parser native so failed"); 2474 } 2475 return ERR_OK; 2476} 2477 2478ErrCode BundleProfile::TransformTo(const std::ostringstream &source, BundlePackInfo &bundlePackInfo) 2479{ 2480 APP_LOGD("transform packinfo stream to bundle pack info"); 2481 nlohmann::json jsonObject = nlohmann::json::parse(source.str(), nullptr, false); 2482 if (jsonObject.is_discarded()) { 2483 APP_LOGE("bad profile"); 2484 return ERR_APPEXECFWK_PARSE_BAD_PROFILE; 2485 } 2486 bundlePackInfo = jsonObject.get<BundlePackInfo>(); 2487 return ERR_OK; 2488} 2489} // namespace AppExecFwk 2490} // namespace OHOS 2491