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