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