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