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