• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2023-2024 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 "module_profile.h"
17 
18 #include <algorithm>
19 #include <mutex>
20 #include <set>
21 #include <sstream>
22 #include "bundle_constants.h"
23 #include "common_profile.h"
24 #include "hilog_tag_wrapper.h"
25 #include "string_ex.h"
26 
27 namespace OHOS {
28 namespace AppExecFwk {
29 const std::unordered_map<std::string, ExtensionAbilityType> EXTENSION_TYPE_MAP = {
30     { "form", ExtensionAbilityType::FORM },
31     { "workScheduler", ExtensionAbilityType::WORK_SCHEDULER },
32     { "inputMethod", ExtensionAbilityType::INPUTMETHOD },
33     { "service", ExtensionAbilityType::SERVICE },
34     { "accessibility", ExtensionAbilityType::ACCESSIBILITY },
35     { "dataShare", ExtensionAbilityType::DATASHARE },
36     { "fileShare", ExtensionAbilityType::FILESHARE },
37     { "staticSubscriber", ExtensionAbilityType::STATICSUBSCRIBER },
38     { "fence", ExtensionAbilityType::FENCE },
39     { "wallpaper", ExtensionAbilityType::WALLPAPER },
40     { "backup", ExtensionAbilityType::BACKUP },
41     { "window", ExtensionAbilityType::WINDOW },
42     { "enterpriseAdmin", ExtensionAbilityType::ENTERPRISE_ADMIN },
43     { "fileAccess", ExtensionAbilityType::FILEACCESS_EXTENSION },
44     { "thumbnail", ExtensionAbilityType::THUMBNAIL },
45     { "preview", ExtensionAbilityType::PREVIEW_TYPE },
46     { "print", ExtensionAbilityType::PRINT },
47     { "push", ExtensionAbilityType::PUSH },
48     { "driver", ExtensionAbilityType::DRIVER },
49     { "appAccountAuthorization", ExtensionAbilityType::APP_ACCOUNT_AUTHORIZATION },
50     { "ui", ExtensionAbilityType::UI },
51     { "sysDialog/userAuth", ExtensionAbilityType::SYSDIALOG_USERAUTH },
52     { "sysDialog/common", ExtensionAbilityType::SYSDIALOG_COMMON },
53     { "sysPicker/mediaControl", ExtensionAbilityType::SYSPICKER_MEDIACONTROL },
54     { "sysDialog/atomicServicePanel", ExtensionAbilityType::SYSDIALOG_ATOMICSERVICEPANEL },
55     { "sysPicker/share", ExtensionAbilityType::SYSPICKER_SHARE },
56     { "hms/account", ExtensionAbilityType::HMS_ACCOUNT },
57     { "distributed", ExtensionAbilityType::DISTRIBUTED }
58 };
59 
ConvertToExtensionAbilityType(const std::string & type)60 ExtensionAbilityType ConvertToExtensionAbilityType(const std::string &type)
61 {
62     TAG_LOGD(AAFwkTag::ABILITY_SIM, "called");
63     if (EXTENSION_TYPE_MAP.find(type) != EXTENSION_TYPE_MAP.end()) {
64         return EXTENSION_TYPE_MAP.at(type);
65     }
66 
67     return ExtensionAbilityType::UNSPECIFIED;
68 }
69 
ConvertToExtensionTypeName(ExtensionAbilityType type)70 std::string ConvertToExtensionTypeName(ExtensionAbilityType type)
71 {
72     TAG_LOGD(AAFwkTag::ABILITY_SIM, "called");
73     for (const auto &[key, val] : EXTENSION_TYPE_MAP) {
74         if (val == type) {
75             return key;
76         }
77     }
78 
79     return "Unspecified";
80 }
81 
82 namespace Profile {
83 int32_t g_parseResult = ERR_OK;
84 std::mutex g_mutex;
85 
86 const std::set<std::string> MODULE_TYPE_SET = {
87     "entry",
88     "feature",
89     "shared"
90 };
91 
92 const std::set<std::string> VIRTUAL_MACHINE_SET = {
93     "ark",
94     "default"
95 };
96 
97 const std::map<std::string, uint32_t> BACKGROUND_MODES_MAP = {
98     {ProfileReader::KEY_DATA_TRANSFER, ProfileReader::VALUE_DATA_TRANSFER},
99     {ProfileReader::KEY_AUDIO_PLAYBACK, ProfileReader::VALUE_AUDIO_PLAYBACK},
100     {ProfileReader::KEY_AUDIO_RECORDING, ProfileReader::VALUE_AUDIO_RECORDING},
101     {ProfileReader::KEY_LOCATION, ProfileReader::VALUE_LOCATION},
102     {ProfileReader::KEY_BLUETOOTH_INTERACTION, ProfileReader::VALUE_BLUETOOTH_INTERACTION},
103     {ProfileReader::KEY_MULTI_DEVICE_CONNECTION, ProfileReader::VALUE_MULTI_DEVICE_CONNECTION},
104     {ProfileReader::KEY_WIFI_INTERACTION, ProfileReader::VALUE_WIFI_INTERACTION},
105     {ProfileReader::KEY_VOIP, ProfileReader::VALUE_VOIP},
106     {ProfileReader::KEY_TASK_KEEPING, ProfileReader::VALUE_TASK_KEEPING},
107     {ProfileReader::KEY_PICTURE_IN_PICTURE, ProfileReader::VALUE_PICTURE_IN_PICTURE},
108     {ProfileReader::KEY_SCREEN_FETCH, ProfileReader::VALUE_SCREEN_FETCH}
109 };
110 
111 const std::set<std::string> GRANT_MODE_SET = {
112     "system_grant",
113     "user_grant"
114 };
115 
116 const std::set<std::string> AVAILABLE_LEVEL_SET = {
117     "system_core",
118     "system_basic",
119     "normal"
120 };
121 
122 const std::map<std::string, LaunchMode> LAUNCH_MODE_MAP = {
123     {"singleton", LaunchMode::SINGLETON},
124     {"standard", LaunchMode::STANDARD},
125     {"multiton", LaunchMode::STANDARD},
126     {"specified", LaunchMode::SPECIFIED}
127 };
128 const std::unordered_map<std::string, DisplayOrientation> DISPLAY_ORIENTATION_MAP = {
129     {"unspecified", DisplayOrientation::UNSPECIFIED},
130     {"landscape", DisplayOrientation::LANDSCAPE},
131     {"portrait", DisplayOrientation::PORTRAIT},
132     {"landscape_inverted", DisplayOrientation::LANDSCAPE_INVERTED},
133     {"portrait_inverted", DisplayOrientation::PORTRAIT_INVERTED},
134     {"auto_rotation", DisplayOrientation::AUTO_ROTATION},
135     {"auto_rotation_landscape", DisplayOrientation::AUTO_ROTATION_LANDSCAPE},
136     {"auto_rotation_portrait", DisplayOrientation::AUTO_ROTATION_PORTRAIT},
137     {"auto_rotation_restricted", DisplayOrientation::AUTO_ROTATION_RESTRICTED},
138     {"auto_rotation_landscape_restricted", DisplayOrientation::AUTO_ROTATION_LANDSCAPE_RESTRICTED},
139     {"auto_rotation_portrait_restricted", DisplayOrientation::AUTO_ROTATION_PORTRAIT_RESTRICTED},
140     {"locked", DisplayOrientation::LOCKED}
141 };
142 const std::unordered_map<std::string, SupportWindowMode> WINDOW_MODE_MAP = {
143     {"fullscreen", SupportWindowMode::FULLSCREEN},
144     {"split", SupportWindowMode::SPLIT},
145     {"floating", SupportWindowMode::FLOATING}
146 };
147 const std::unordered_map<std::string, BundleType> BUNDLE_TYPE_MAP = {
148     {"app", BundleType::APP},
149     {"atomicService", BundleType::ATOMIC_SERVICE},
150     {"shared", BundleType::SHARED}
151 };
152 
153 struct DeviceConfig {
154     // pair first : if exist in module.json then true, otherwise false
155     // pair second : actual value
156     std::pair<bool, int32_t> minAPIVersion = std::make_pair<>(false, 0);
157     std::pair<bool, bool> keepAlive = std::make_pair<>(false, false);
158     std::pair<bool, bool> removable = std::make_pair<>(false, true);
159     std::pair<bool, bool> singleton = std::make_pair<>(false, false);
160     std::pair<bool, bool> userDataClearable = std::make_pair<>(false, true);
161     std::pair<bool, bool> accessible = std::make_pair<>(false, true);
162 };
163 
164 struct Metadata {
165     std::string name;
166     std::string value;
167     std::string resource;
168 };
169 
170 struct Ability {
171     std::string name;
172     std::string srcEntrance;
173     std::string launchType = ABILITY_LAUNCH_TYPE_DEFAULT_VALUE;
174     std::string description;
175     int32_t descriptionId = 0;
176     std::string icon;
177     int32_t iconId = 0;
178     std::string label;
179     int32_t labelId = 0;
180     int32_t priority = 0;
181     std::vector<std::string> permissions;
182     std::vector<Metadata> metadata;
183     bool visible = false;
184     bool continuable = false;
185     std::vector<std::string> backgroundModes;
186     std::string startWindowIcon;
187     int32_t startWindowIconId = 0;
188     std::string startWindowBackground;
189     int32_t startWindowBackgroundId = 0;
190     bool removeMissionAfterTerminate = false;
191     std::string orientation = "unspecified";
192     std::vector<std::string> windowModes;
193     double maxWindowRatio = 0;
194     double minWindowRatio = 0;
195     uint32_t maxWindowWidth = 0;
196     uint32_t minWindowWidth = 0;
197     uint32_t maxWindowHeight = 0;
198     uint32_t minWindowHeight = 0;
199     bool excludeFromMissions = false;
200     bool recoverable = false;
201     bool unclearableMission = false;
202 };
203 
204 struct Extension {
205     std::string name;
206     std::string srcEntrance;
207     std::string icon;
208     int32_t iconId = 0;
209     std::string label;
210     int32_t labelId = 0;
211     std::string description;
212     int32_t descriptionId = 0;
213     int32_t priority = 0;
214     std::string type;
215     std::string readPermission;
216     std::string writePermission;
217     std::string uri;
218     std::vector<std::string> permissions;
219     bool visible = false;
220     std::vector<Metadata> metadata;
221 };
222 
223 struct App {
224     std::string bundleName;
225     bool debug = false;
226     std::string icon;
227     int32_t iconId = 0;
228     std::string label;
229     int32_t labelId = 0;
230     std::string description;
231     int32_t descriptionId = 0;
232     std::string vendor;
233     int32_t versionCode = 0;
234     std::string versionName;
235     int32_t minCompatibleVersionCode = -1;
236     uint32_t minAPIVersion = 0;
237     int32_t targetAPIVersion = 0;
238     std::string apiReleaseType = APP_API_RELEASETYPE_DEFAULT_VALUE;
239     bool keepAlive = false;
240     std::pair<bool, bool> removable = std::make_pair<>(false, true);
241     bool singleton = false;
242     bool userDataClearable = true;
243     bool accessible = false;
244     std::vector<std::string> targetBundleList;
245     std::map<std::string, DeviceConfig> deviceConfigs;
246     bool multiProjects = false;
247     std::string targetBundle;
248     int32_t targetPriority = 0;
249     bool asanEnabled = false;
250     std::string bundleType = Profile::BUNDLE_TYPE_APP;
251     std::string compileSdkVersion;
252     std::string compileSdkType = Profile::COMPILE_SDK_TYPE_OPEN_HARMONY;
253 };
254 
255 struct Module {
256     std::string name;
257     std::string type;
258     std::string srcEntrance;
259     std::string description;
260     int32_t descriptionId = 0;
261     std::string process;
262     std::string mainElement;
263     std::vector<std::string> deviceTypes;
264     bool deliveryWithInstall = false;
265     bool installationFree = false;
266     std::string virtualMachine = MODULE_VIRTUAL_MACHINE_DEFAULT_VALUE;
267     std::string pages;
268     std::vector<Metadata> metadata;
269     std::vector<Ability> abilities;
270     std::vector<Extension> extensionAbilities;
271     std::vector<Dependency> dependencies;
272     std::string compileMode;
273     bool isLibIsolated = false;
274     std::string targetModule;
275     int32_t targetPriority = 0;
276     std::vector<ProxyData> proxyDatas;
277     std::vector<ProxyData> proxyData;
278     std::string buildHash;
279     std::string isolationMode;
280     bool compressNativeLibs = true;
281 };
282 
283 struct ModuleJson {
284     App app;
285     Module module;
286 };
287 
from_json(const nlohmann::json & jsonObject,Metadata & metadata)288 void from_json(const nlohmann::json &jsonObject, Metadata &metadata)
289 {
290     TAG_LOGD(AAFwkTag::ABILITY_SIM, "read metadata tag from module.json");
291     const auto &jsonObjectEnd = jsonObject.end();
292     GetValueIfFindKey<std::string>(jsonObject,
293         jsonObjectEnd,
294         META_DATA_NAME,
295         metadata.name,
296         JsonType::STRING,
297         false,
298         g_parseResult,
299         ArrayType::NOT_ARRAY);
300     GetValueIfFindKey<std::string>(jsonObject,
301         jsonObjectEnd,
302         META_DATA_VALUE,
303         metadata.value,
304         JsonType::STRING,
305         false,
306         g_parseResult,
307         ArrayType::NOT_ARRAY);
308     GetValueIfFindKey<std::string>(jsonObject,
309         jsonObjectEnd,
310         META_DATA_RESOURCE,
311         metadata.resource,
312         JsonType::STRING,
313         false,
314         g_parseResult,
315         ArrayType::NOT_ARRAY);
316 }
317 
from_json(const nlohmann::json & jsonObject,Ability & ability)318 void from_json(const nlohmann::json &jsonObject, Ability &ability)
319 {
320     TAG_LOGD(AAFwkTag::ABILITY_SIM, "read ability tag from module.json");
321     const auto &jsonObjectEnd = jsonObject.end();
322     GetValueIfFindKey<std::string>(jsonObject,
323         jsonObjectEnd,
324         ABILITY_NAME,
325         ability.name,
326         JsonType::STRING,
327         true,
328         g_parseResult,
329         ArrayType::NOT_ARRAY);
330     // both srcEntry and srcEntrance can be configured, but srcEntry has higher priority
331     if (jsonObject.find(SRC_ENTRY) != jsonObject.end()) {
332         GetValueIfFindKey<std::string>(jsonObject,
333             jsonObjectEnd,
334             SRC_ENTRY,
335             ability.srcEntrance,
336             JsonType::STRING,
337             true,
338             g_parseResult,
339             ArrayType::NOT_ARRAY);
340     } else {
341         GetValueIfFindKey<std::string>(jsonObject,
342             jsonObjectEnd,
343             SRC_ENTRANCE,
344             ability.srcEntrance,
345             JsonType::STRING,
346             true,
347             g_parseResult,
348             ArrayType::NOT_ARRAY);
349     }
350     GetValueIfFindKey<std::string>(jsonObject,
351         jsonObjectEnd,
352         ABILITY_LAUNCH_TYPE,
353         ability.launchType,
354         JsonType::STRING,
355         false,
356         g_parseResult,
357         ArrayType::NOT_ARRAY);
358     GetValueIfFindKey<std::string>(jsonObject,
359         jsonObjectEnd,
360         DESCRIPTION,
361         ability.description,
362         JsonType::STRING,
363         false,
364         g_parseResult,
365         ArrayType::NOT_ARRAY);
366     GetValueIfFindKey<int32_t>(jsonObject,
367         jsonObjectEnd,
368         DESCRIPTION_ID,
369         ability.descriptionId,
370         JsonType::NUMBER,
371         false,
372         g_parseResult,
373         ArrayType::NOT_ARRAY);
374     GetValueIfFindKey<std::string>(jsonObject,
375         jsonObjectEnd,
376         ICON,
377         ability.icon,
378         JsonType::STRING,
379         false,
380         g_parseResult,
381         ArrayType::NOT_ARRAY);
382     GetValueIfFindKey<int32_t>(jsonObject,
383         jsonObjectEnd,
384         ICON_ID,
385         ability.iconId,
386         JsonType::NUMBER,
387         false,
388         g_parseResult,
389         ArrayType::NOT_ARRAY);
390     GetValueIfFindKey<std::string>(jsonObject,
391         jsonObjectEnd,
392         LABEL,
393         ability.label,
394         JsonType::STRING,
395         false,
396         g_parseResult,
397         ArrayType::NOT_ARRAY);
398     GetValueIfFindKey<int32_t>(jsonObject,
399         jsonObjectEnd,
400         LABEL_ID,
401         ability.labelId,
402         JsonType::NUMBER,
403         false,
404         g_parseResult,
405         ArrayType::NOT_ARRAY);
406     GetValueIfFindKey<int32_t>(jsonObject,
407         jsonObjectEnd,
408         PRIORITY,
409         ability.priority,
410         JsonType::NUMBER,
411         false,
412         g_parseResult,
413         ArrayType::NOT_ARRAY);
414     GetValueIfFindKey<std::vector<std::string>>(jsonObject,
415         jsonObjectEnd,
416         PERMISSIONS,
417         ability.permissions,
418         JsonType::ARRAY,
419         false,
420         g_parseResult,
421         ArrayType::STRING);
422     GetValueIfFindKey<std::vector<Metadata>>(jsonObject,
423         jsonObjectEnd,
424         META_DATA,
425         ability.metadata,
426         JsonType::ARRAY,
427         false,
428         g_parseResult,
429         ArrayType::OBJECT);
430     // both exported and visible can be configured, but exported has higher priority
431     GetValueIfFindKey<bool>(jsonObject,
432         jsonObjectEnd,
433         VISIBLE,
434         ability.visible,
435         JsonType::BOOLEAN,
436         false,
437         g_parseResult,
438         ArrayType::NOT_ARRAY);
439     GetValueIfFindKey<bool>(jsonObject,
440         jsonObjectEnd,
441         EXPORTED,
442         ability.visible,
443         JsonType::BOOLEAN,
444         false,
445         g_parseResult,
446         ArrayType::NOT_ARRAY);
447     GetValueIfFindKey<bool>(jsonObject,
448         jsonObjectEnd,
449         ABILITY_CONTINUABLE,
450         ability.continuable,
451         JsonType::BOOLEAN,
452         false,
453         g_parseResult,
454         ArrayType::NOT_ARRAY);
455     GetValueIfFindKey<std::vector<std::string>>(jsonObject,
456         jsonObjectEnd,
457         ABILITY_BACKGROUNDMODES,
458         ability.backgroundModes,
459         JsonType::ARRAY,
460         false,
461         g_parseResult,
462         ArrayType::STRING);
463     GetValueIfFindKey<std::string>(jsonObject,
464         jsonObjectEnd,
465         ABILITY_START_WINDOW_ICON,
466         ability.startWindowIcon,
467         JsonType::STRING,
468         false,
469         g_parseResult,
470         ArrayType::NOT_ARRAY);
471     GetValueIfFindKey<int32_t>(jsonObject,
472         jsonObjectEnd,
473         ABILITY_START_WINDOW_ICON_ID,
474         ability.startWindowIconId,
475         JsonType::NUMBER,
476         false,
477         g_parseResult,
478         ArrayType::NOT_ARRAY);
479     GetValueIfFindKey<std::string>(jsonObject,
480         jsonObjectEnd,
481         ABILITY_START_WINDOW_BACKGROUND,
482         ability.startWindowBackground,
483         JsonType::STRING,
484         false,
485         g_parseResult,
486         ArrayType::NOT_ARRAY);
487     GetValueIfFindKey<int32_t>(jsonObject,
488         jsonObjectEnd,
489         ABILITY_START_WINDOW_BACKGROUND_ID,
490         ability.startWindowBackgroundId,
491         JsonType::NUMBER,
492         false,
493         g_parseResult,
494         ArrayType::NOT_ARRAY);
495     GetValueIfFindKey<bool>(jsonObject,
496         jsonObjectEnd,
497         ABILITY_REMOVE_MISSION_AFTER_TERMINATE,
498         ability.removeMissionAfterTerminate,
499         JsonType::BOOLEAN,
500         false,
501         g_parseResult,
502         ArrayType::NOT_ARRAY);
503     GetValueIfFindKey<std::string>(jsonObject,
504         jsonObjectEnd,
505         ABILITY_ORIENTATION,
506         ability.orientation,
507         JsonType::STRING,
508         false,
509         g_parseResult,
510         ArrayType::NOT_ARRAY);
511     GetValueIfFindKey<std::vector<std::string>>(jsonObject,
512         jsonObjectEnd,
513         ABILITY_SUPPORT_WINDOW_MODE,
514         ability.windowModes,
515         JsonType::ARRAY,
516         false,
517         g_parseResult,
518         ArrayType::STRING);
519     GetValueIfFindKey<double>(jsonObject,
520         jsonObjectEnd,
521         ABILITY_MAX_WINDOW_RATIO,
522         ability.maxWindowRatio,
523         JsonType::NUMBER,
524         false,
525         g_parseResult,
526         ArrayType::NOT_ARRAY);
527     GetValueIfFindKey<double>(jsonObject,
528         jsonObjectEnd,
529         ABILITY_MIN_WINDOW_RATIO,
530         ability.minWindowRatio,
531         JsonType::NUMBER,
532         false,
533         g_parseResult,
534         ArrayType::NOT_ARRAY);
535     GetValueIfFindKey<uint32_t>(jsonObject,
536         jsonObjectEnd,
537         ABILITY_MAX_WINDOW_WIDTH,
538         ability.maxWindowWidth,
539         JsonType::NUMBER,
540         false,
541         g_parseResult,
542         ArrayType::NOT_ARRAY);
543     GetValueIfFindKey<uint32_t>(jsonObject,
544         jsonObjectEnd,
545         ABILITY_MIN_WINDOW_WIDTH,
546         ability.minWindowWidth,
547         JsonType::NUMBER,
548         false,
549         g_parseResult,
550         ArrayType::NOT_ARRAY);
551     GetValueIfFindKey<uint32_t>(jsonObject,
552         jsonObjectEnd,
553         ABILITY_MAX_WINDOW_HEIGHT,
554         ability.maxWindowHeight,
555         JsonType::NUMBER,
556         false,
557         g_parseResult,
558         ArrayType::NOT_ARRAY);
559     GetValueIfFindKey<uint32_t>(jsonObject,
560         jsonObjectEnd,
561         ABILITY_MIN_WINDOW_HEIGHT,
562         ability.minWindowHeight,
563         JsonType::NUMBER,
564         false,
565         g_parseResult,
566         ArrayType::NOT_ARRAY);
567     GetValueIfFindKey<bool>(jsonObject,
568         jsonObjectEnd,
569         ABILITY_EXCLUDE_FROM_MISSIONS,
570         ability.excludeFromMissions,
571         JsonType::BOOLEAN,
572         false,
573         g_parseResult,
574         ArrayType::NOT_ARRAY);
575     GetValueIfFindKey<bool>(jsonObject,
576         jsonObjectEnd,
577         ABILITY_RECOVERABLE,
578         ability.recoverable,
579         JsonType::BOOLEAN,
580         false,
581         g_parseResult,
582         ArrayType::NOT_ARRAY);
583     GetValueIfFindKey<bool>(jsonObject,
584         jsonObjectEnd,
585         ABILITY_UNCLEARABLE_MISSION,
586         ability.unclearableMission,
587         JsonType::BOOLEAN,
588         false,
589         g_parseResult,
590         ArrayType::NOT_ARRAY);
591 }
592 
from_json(const nlohmann::json & jsonObject,Extension & extension)593 void from_json(const nlohmann::json &jsonObject, Extension &extension)
594 {
595     TAG_LOGD(AAFwkTag::ABILITY_SIM, "read extension tag from module.json");
596     const auto &jsonObjectEnd = jsonObject.end();
597     GetValueIfFindKey<std::string>(jsonObject,
598         jsonObjectEnd,
599         EXTENSION_ABILITY_NAME,
600         extension.name,
601         JsonType::STRING,
602         true,
603         g_parseResult,
604         ArrayType::NOT_ARRAY);
605     // both srcEntry and srcEntrance can be configured, but srcEntry has higher priority
606     if (jsonObject.find(SRC_ENTRY) != jsonObject.end()) {
607         GetValueIfFindKey<std::string>(jsonObject,
608             jsonObjectEnd,
609             SRC_ENTRY,
610             extension.srcEntrance,
611             JsonType::STRING,
612             true,
613             g_parseResult,
614             ArrayType::NOT_ARRAY);
615     } else {
616         GetValueIfFindKey<std::string>(jsonObject,
617             jsonObjectEnd,
618             SRC_ENTRANCE,
619             extension.srcEntrance,
620             JsonType::STRING,
621             true,
622             g_parseResult,
623             ArrayType::NOT_ARRAY);
624     }
625     GetValueIfFindKey<std::string>(jsonObject,
626         jsonObjectEnd,
627         ICON,
628         extension.icon,
629         JsonType::STRING,
630         false,
631         g_parseResult,
632         ArrayType::NOT_ARRAY);
633     GetValueIfFindKey<int32_t>(jsonObject,
634         jsonObjectEnd,
635         ICON_ID,
636         extension.iconId,
637         JsonType::NUMBER,
638         false,
639         g_parseResult,
640         ArrayType::NOT_ARRAY);
641     GetValueIfFindKey<std::string>(jsonObject,
642         jsonObjectEnd,
643         LABEL,
644         extension.label,
645         JsonType::STRING,
646         false,
647         g_parseResult,
648         ArrayType::NOT_ARRAY);
649     GetValueIfFindKey<int32_t>(jsonObject,
650         jsonObjectEnd,
651         LABEL_ID,
652         extension.labelId,
653         JsonType::NUMBER,
654         false,
655         g_parseResult,
656         ArrayType::NOT_ARRAY);
657     GetValueIfFindKey<std::string>(jsonObject,
658         jsonObjectEnd,
659         DESCRIPTION,
660         extension.description,
661         JsonType::STRING,
662         false,
663         g_parseResult,
664         ArrayType::NOT_ARRAY);
665     GetValueIfFindKey<int32_t>(jsonObject,
666         jsonObjectEnd,
667         DESCRIPTION_ID,
668         extension.descriptionId,
669         JsonType::NUMBER,
670         false,
671         g_parseResult,
672         ArrayType::NOT_ARRAY);
673     GetValueIfFindKey<int32_t>(jsonObject,
674         jsonObjectEnd,
675         PRIORITY,
676         extension.priority,
677         JsonType::NUMBER,
678         false,
679         g_parseResult,
680         ArrayType::NOT_ARRAY);
681     GetValueIfFindKey<std::string>(jsonObject,
682         jsonObjectEnd,
683         EXTENSION_ABILITY_TYPE,
684         extension.type,
685         JsonType::STRING,
686         true,
687         g_parseResult,
688         ArrayType::NOT_ARRAY);
689     GetValueIfFindKey<std::string>(jsonObject,
690         jsonObjectEnd,
691         EXTENSION_ABILITY_READ_PERMISSION,
692         extension.readPermission,
693         JsonType::STRING,
694         false,
695         g_parseResult,
696         ArrayType::NOT_ARRAY);
697     GetValueIfFindKey<std::string>(jsonObject,
698         jsonObjectEnd,
699         EXTENSION_ABILITY_WRITE_PERMISSION,
700         extension.writePermission,
701         JsonType::STRING,
702         false,
703         g_parseResult,
704         ArrayType::NOT_ARRAY);
705     GetValueIfFindKey<std::string>(jsonObject,
706         jsonObjectEnd,
707         EXTENSION_URI,
708         extension.uri,
709         JsonType::STRING,
710         false,
711         g_parseResult,
712         ArrayType::NOT_ARRAY);
713     GetValueIfFindKey<std::vector<std::string>>(jsonObject,
714         jsonObjectEnd,
715         PERMISSIONS,
716         extension.permissions,
717         JsonType::ARRAY,
718         false,
719         g_parseResult,
720         ArrayType::STRING);
721     // both exported and visible can be configured, but exported has higher priority
722     GetValueIfFindKey<bool>(jsonObject,
723         jsonObjectEnd,
724         VISIBLE,
725         extension.visible,
726         JsonType::BOOLEAN,
727         false,
728         g_parseResult,
729         ArrayType::NOT_ARRAY);
730     GetValueIfFindKey<bool>(jsonObject,
731         jsonObjectEnd,
732         EXPORTED,
733         extension.visible,
734         JsonType::BOOLEAN,
735         false,
736         g_parseResult,
737         ArrayType::NOT_ARRAY);
738     GetValueIfFindKey<std::vector<Metadata>>(jsonObject,
739         jsonObjectEnd,
740         META_DATA,
741         extension.metadata,
742         JsonType::ARRAY,
743         false,
744         g_parseResult,
745         ArrayType::OBJECT);
746 }
747 
from_json(const nlohmann::json & jsonObject,DeviceConfig & deviceConfig)748 void from_json(const nlohmann::json &jsonObject, DeviceConfig &deviceConfig)
749 {
750     const auto &jsonObjectEnd = jsonObject.end();
751     if (jsonObject.find(MIN_API_VERSION) != jsonObjectEnd) {
752         deviceConfig.minAPIVersion.first = true;
753         GetValueIfFindKey<int32_t>(jsonObject,
754             jsonObjectEnd,
755             MIN_API_VERSION,
756             deviceConfig.minAPIVersion.second,
757             JsonType::NUMBER,
758             false,
759             g_parseResult,
760             ArrayType::NOT_ARRAY);
761     }
762     if (jsonObject.find(DEVICE_CONFIG_KEEP_ALIVE) != jsonObjectEnd) {
763         deviceConfig.keepAlive.first = true;
764         GetValueIfFindKey<bool>(jsonObject,
765             jsonObjectEnd,
766             DEVICE_CONFIG_KEEP_ALIVE,
767             deviceConfig.keepAlive.second,
768             JsonType::BOOLEAN,
769             false,
770             g_parseResult,
771             ArrayType::NOT_ARRAY);
772     }
773     if (jsonObject.find(DEVICE_CONFIG_REMOVABLE) != jsonObjectEnd) {
774         deviceConfig.removable.first = true;
775         GetValueIfFindKey<bool>(jsonObject,
776             jsonObjectEnd,
777             DEVICE_CONFIG_REMOVABLE,
778             deviceConfig.removable.second,
779             JsonType::BOOLEAN,
780             false,
781             g_parseResult,
782             ArrayType::NOT_ARRAY);
783     }
784     if (jsonObject.find(DEVICE_CONFIG_SINGLETON) != jsonObjectEnd) {
785         deviceConfig.singleton.first = true;
786         GetValueIfFindKey<bool>(jsonObject,
787             jsonObjectEnd,
788             DEVICE_CONFIG_SINGLETON,
789             deviceConfig.singleton.second,
790             JsonType::BOOLEAN,
791             false,
792             g_parseResult,
793             ArrayType::NOT_ARRAY);
794     }
795     if (jsonObject.find(DEVICE_CONFIG_USER_DATA_CLEARABLE) != jsonObjectEnd) {
796         deviceConfig.userDataClearable.first = true;
797         GetValueIfFindKey<bool>(jsonObject,
798             jsonObjectEnd,
799             DEVICE_CONFIG_USER_DATA_CLEARABLE,
800             deviceConfig.userDataClearable.second,
801             JsonType::BOOLEAN,
802             false,
803             g_parseResult,
804             ArrayType::NOT_ARRAY);
805     }
806     if (jsonObject.find(DEVICE_CONFIG_ACCESSIBLE) != jsonObjectEnd) {
807         deviceConfig.accessible.first = true;
808         GetValueIfFindKey<bool>(jsonObject,
809             jsonObjectEnd,
810             DEVICE_CONFIG_ACCESSIBLE,
811             deviceConfig.accessible.second,
812             JsonType::BOOLEAN,
813             false,
814             g_parseResult,
815             ArrayType::NOT_ARRAY);
816     }
817 }
818 
from_json(const nlohmann::json & jsonObject,App & app)819 void from_json(const nlohmann::json &jsonObject, App &app)
820 {
821     TAG_LOGD(AAFwkTag::ABILITY_SIM, "read app tag from module.json");
822     const auto &jsonObjectEnd = jsonObject.end();
823     GetValueIfFindKey<std::string>(jsonObject,
824         jsonObjectEnd,
825         APP_BUNDLE_NAME,
826         app.bundleName,
827         JsonType::STRING,
828         true,
829         g_parseResult,
830         ArrayType::NOT_ARRAY);
831     GetValueIfFindKey<std::string>(jsonObject,
832         jsonObjectEnd,
833         ICON,
834         app.icon,
835         JsonType::STRING,
836         true,
837         g_parseResult,
838         ArrayType::NOT_ARRAY);
839     GetValueIfFindKey<std::string>(jsonObject,
840         jsonObjectEnd,
841         LABEL,
842         app.label,
843         JsonType::STRING,
844         true,
845         g_parseResult,
846         ArrayType::NOT_ARRAY);
847     GetValueIfFindKey<int32_t>(jsonObject,
848         jsonObjectEnd,
849         APP_VERSION_CODE,
850         app.versionCode,
851         JsonType::NUMBER,
852         true,
853         g_parseResult,
854         ArrayType::NOT_ARRAY);
855     GetValueIfFindKey<std::string>(jsonObject,
856         jsonObjectEnd,
857         APP_VERSION_NAME,
858         app.versionName,
859         JsonType::STRING,
860         true,
861         g_parseResult,
862         ArrayType::NOT_ARRAY);
863     GetValueIfFindKey<uint32_t>(jsonObject,
864         jsonObjectEnd,
865         APP_MIN_API_VERSION,
866         app.minAPIVersion,
867         JsonType::NUMBER,
868         true,
869         g_parseResult,
870         ArrayType::NOT_ARRAY);
871     GetValueIfFindKey<int32_t>(jsonObject,
872         jsonObjectEnd,
873         APP_TARGET_API_VERSION,
874         app.targetAPIVersion,
875         JsonType::NUMBER,
876         true,
877         g_parseResult,
878         ArrayType::NOT_ARRAY);
879     GetValueIfFindKey<bool>(jsonObject,
880         jsonObjectEnd,
881         APP_DEBUG,
882         app.debug,
883         JsonType::BOOLEAN,
884         false,
885         g_parseResult,
886         ArrayType::NOT_ARRAY);
887     GetValueIfFindKey<int32_t>(jsonObject,
888         jsonObjectEnd,
889         ICON_ID,
890         app.iconId,
891         JsonType::NUMBER,
892         false,
893         g_parseResult,
894         ArrayType::NOT_ARRAY);
895     GetValueIfFindKey<int32_t>(jsonObject,
896         jsonObjectEnd,
897         LABEL_ID,
898         app.labelId,
899         JsonType::NUMBER,
900         false,
901         g_parseResult,
902         ArrayType::NOT_ARRAY);
903     GetValueIfFindKey<std::string>(jsonObject,
904         jsonObjectEnd,
905         DESCRIPTION,
906         app.description,
907         JsonType::STRING,
908         false,
909         g_parseResult,
910         ArrayType::NOT_ARRAY);
911     GetValueIfFindKey<int32_t>(jsonObject,
912         jsonObjectEnd,
913         DESCRIPTION_ID,
914         app.descriptionId,
915         JsonType::NUMBER,
916         false,
917         g_parseResult,
918         ArrayType::NOT_ARRAY);
919     GetValueIfFindKey<std::string>(jsonObject,
920         jsonObjectEnd,
921         APP_VENDOR,
922         app.vendor,
923         JsonType::STRING,
924         false,
925         g_parseResult,
926         ArrayType::NOT_ARRAY);
927     GetValueIfFindKey<int32_t>(jsonObject,
928         jsonObjectEnd,
929         APP_MIN_COMPATIBLE_VERSION_CODE,
930         app.minCompatibleVersionCode,
931         JsonType::NUMBER,
932         false,
933         g_parseResult,
934         ArrayType::NOT_ARRAY);
935     GetValueIfFindKey<std::string>(jsonObject,
936         jsonObjectEnd,
937         APP_API_RELEASETYPE,
938         app.apiReleaseType,
939         JsonType::STRING,
940         false,
941         g_parseResult,
942         ArrayType::NOT_ARRAY);
943     GetValueIfFindKey<bool>(jsonObject,
944         jsonObjectEnd,
945         APP_KEEP_ALIVE,
946         app.keepAlive,
947         JsonType::BOOLEAN,
948         false,
949         g_parseResult,
950         ArrayType::NOT_ARRAY);
951     GetValueIfFindKey<std::vector<std::string>>(jsonObject,
952         jsonObjectEnd,
953         APP_TARGETBUNDLELIST,
954         app.targetBundleList,
955         JsonType::ARRAY,
956         false,
957         g_parseResult,
958         ArrayType::STRING);
959     if (jsonObject.find(APP_REMOVABLE) != jsonObject.end()) {
960         app.removable.first = true;
961         GetValueIfFindKey<bool>(jsonObject,
962             jsonObjectEnd,
963             APP_REMOVABLE,
964             app.removable.second,
965             JsonType::BOOLEAN,
966             false,
967             g_parseResult,
968             ArrayType::NOT_ARRAY);
969     }
970     GetValueIfFindKey<bool>(jsonObject,
971         jsonObjectEnd,
972         APP_SINGLETON,
973         app.singleton,
974         JsonType::BOOLEAN,
975         false,
976         g_parseResult,
977         ArrayType::NOT_ARRAY);
978     GetValueIfFindKey<bool>(jsonObject,
979         jsonObjectEnd,
980         APP_USER_DATA_CLEARABLE,
981         app.userDataClearable,
982         JsonType::BOOLEAN,
983         false,
984         g_parseResult,
985         ArrayType::NOT_ARRAY);
986     GetValueIfFindKey<bool>(jsonObject,
987         jsonObjectEnd,
988         APP_ACCESSIBLE,
989         app.accessible,
990         JsonType::BOOLEAN,
991         false,
992         g_parseResult,
993         ArrayType::NOT_ARRAY);
994     GetValueIfFindKey<bool>(jsonObject,
995         jsonObjectEnd,
996         APP_ASAN_ENABLED,
997         app.asanEnabled,
998         JsonType::BOOLEAN,
999         false,
1000         g_parseResult,
1001         ArrayType::NOT_ARRAY);
1002     GetValueIfFindKey<std::string>(jsonObject,
1003         jsonObjectEnd,
1004         BUNDLE_TYPE,
1005         app.bundleType,
1006         JsonType::STRING,
1007         false,
1008         g_parseResult,
1009         ArrayType::NOT_ARRAY);
1010     if (jsonObject.find(APP_PHONE) != jsonObjectEnd) {
1011         DeviceConfig deviceConfig;
1012         GetValueIfFindKey<DeviceConfig>(jsonObject,
1013             jsonObjectEnd,
1014             APP_PHONE,
1015             deviceConfig,
1016             JsonType::OBJECT,
1017             false,
1018             g_parseResult,
1019             ArrayType::NOT_ARRAY);
1020         app.deviceConfigs[APP_PHONE] = deviceConfig;
1021     }
1022     if (jsonObject.find(APP_TABLET) != jsonObjectEnd) {
1023         DeviceConfig deviceConfig;
1024         GetValueIfFindKey<DeviceConfig>(jsonObject,
1025             jsonObjectEnd,
1026             APP_TABLET,
1027             deviceConfig,
1028             JsonType::OBJECT,
1029             false,
1030             g_parseResult,
1031             ArrayType::NOT_ARRAY);
1032         app.deviceConfigs[APP_TABLET] = deviceConfig;
1033     }
1034     if (jsonObject.find(APP_TV) != jsonObjectEnd) {
1035         DeviceConfig deviceConfig;
1036         GetValueIfFindKey<DeviceConfig>(jsonObject,
1037             jsonObjectEnd,
1038             APP_TV,
1039             deviceConfig,
1040             JsonType::OBJECT,
1041             false,
1042             g_parseResult,
1043             ArrayType::NOT_ARRAY);
1044         app.deviceConfigs[APP_TV] = deviceConfig;
1045     }
1046     if (jsonObject.find(APP_WEARABLE) != jsonObjectEnd) {
1047         DeviceConfig deviceConfig;
1048         GetValueIfFindKey<DeviceConfig>(jsonObject,
1049             jsonObjectEnd,
1050             APP_WEARABLE,
1051             deviceConfig,
1052             JsonType::OBJECT,
1053             false,
1054             g_parseResult,
1055             ArrayType::NOT_ARRAY);
1056         app.deviceConfigs[APP_WEARABLE] = deviceConfig;
1057     }
1058     if (jsonObject.find(APP_LITE_WEARABLE) != jsonObjectEnd) {
1059         DeviceConfig deviceConfig;
1060         GetValueIfFindKey<DeviceConfig>(jsonObject,
1061             jsonObjectEnd,
1062             APP_LITE_WEARABLE,
1063             deviceConfig,
1064             JsonType::OBJECT,
1065             false,
1066             g_parseResult,
1067             ArrayType::NOT_ARRAY);
1068         app.deviceConfigs[APP_LITE_WEARABLE] = deviceConfig;
1069     }
1070     if (jsonObject.find(APP_CAR) != jsonObjectEnd) {
1071         DeviceConfig deviceConfig;
1072         GetValueIfFindKey<DeviceConfig>(jsonObject,
1073             jsonObjectEnd,
1074             APP_CAR,
1075             deviceConfig,
1076             JsonType::OBJECT,
1077             false,
1078             g_parseResult,
1079             ArrayType::NOT_ARRAY);
1080         app.deviceConfigs[APP_CAR] = deviceConfig;
1081     }
1082     if (jsonObject.find(APP_SMART_VISION) != jsonObjectEnd) {
1083         DeviceConfig deviceConfig;
1084         GetValueIfFindKey<DeviceConfig>(jsonObject,
1085             jsonObjectEnd,
1086             APP_SMART_VISION,
1087             deviceConfig,
1088             JsonType::OBJECT,
1089             false,
1090             g_parseResult,
1091             ArrayType::NOT_ARRAY);
1092         app.deviceConfigs[APP_SMART_VISION] = deviceConfig;
1093     }
1094     if (jsonObject.find(APP_ROUTER) != jsonObjectEnd) {
1095         DeviceConfig deviceConfig;
1096         GetValueIfFindKey<DeviceConfig>(jsonObject,
1097             jsonObjectEnd,
1098             APP_ROUTER,
1099             deviceConfig,
1100             JsonType::OBJECT,
1101             false,
1102             g_parseResult,
1103             ArrayType::NOT_ARRAY);
1104         app.deviceConfigs[APP_ROUTER] = deviceConfig;
1105     }
1106     GetValueIfFindKey<bool>(jsonObject,
1107         jsonObjectEnd,
1108         APP_MULTI_PROJECTS,
1109         app.multiProjects,
1110         JsonType::BOOLEAN,
1111         false,
1112         g_parseResult,
1113         ArrayType::NOT_ARRAY);
1114     GetValueIfFindKey<std::string>(jsonObject,
1115         jsonObjectEnd,
1116         APP_TARGET_BUNDLE_NAME,
1117         app.targetBundle,
1118         JsonType::STRING,
1119         false,
1120         g_parseResult,
1121         ArrayType::NOT_ARRAY);
1122     GetValueIfFindKey<int32_t>(jsonObject,
1123         jsonObjectEnd,
1124         APP_TARGET_PRIORITY,
1125         app.targetPriority,
1126         JsonType::NUMBER,
1127         false,
1128         g_parseResult,
1129         ArrayType::NOT_ARRAY);
1130     GetValueIfFindKey<std::string>(jsonObject,
1131         jsonObjectEnd,
1132         COMPILE_SDK_VERSION,
1133         app.compileSdkVersion,
1134         JsonType::STRING,
1135         false,
1136         g_parseResult,
1137         ArrayType::NOT_ARRAY);
1138     GetValueIfFindKey<std::string>(jsonObject,
1139         jsonObjectEnd,
1140         COMPILE_SDK_TYPE,
1141         app.compileSdkType,
1142         JsonType::STRING,
1143         false,
1144         g_parseResult,
1145         ArrayType::NOT_ARRAY);
1146 }
1147 
from_json(const nlohmann::json & jsonObject,Module & module)1148 void from_json(const nlohmann::json &jsonObject, Module &module)
1149 {
1150     TAG_LOGD(AAFwkTag::ABILITY_SIM, "read module tag from module.json");
1151     const auto &jsonObjectEnd = jsonObject.end();
1152     GetValueIfFindKey<std::string>(jsonObject,
1153         jsonObjectEnd,
1154         MODULE_NAME,
1155         module.name,
1156         JsonType::STRING,
1157         true,
1158         g_parseResult,
1159         ArrayType::NOT_ARRAY);
1160     GetValueIfFindKey<std::string>(jsonObject,
1161         jsonObjectEnd,
1162         MODULE_TYPE,
1163         module.type,
1164         JsonType::STRING,
1165         true,
1166         g_parseResult,
1167         ArrayType::NOT_ARRAY);
1168     GetValueIfFindKey<std::vector<std::string>>(jsonObject,
1169         jsonObjectEnd,
1170         MODULE_DEVICE_TYPES,
1171         module.deviceTypes,
1172         JsonType::ARRAY,
1173         true,
1174         g_parseResult,
1175         ArrayType::STRING);
1176     GetValueIfFindKey<bool>(jsonObject,
1177         jsonObjectEnd,
1178         MODULE_DELIVERY_WITH_INSTALL,
1179         module.deliveryWithInstall,
1180         JsonType::BOOLEAN,
1181         true,
1182         g_parseResult,
1183         ArrayType::NOT_ARRAY);
1184     GetValueIfFindKey<std::string>(jsonObject,
1185         jsonObjectEnd,
1186         MODULE_PAGES,
1187         module.pages,
1188         JsonType::STRING,
1189         false,
1190         g_parseResult,
1191         ArrayType::NOT_ARRAY);
1192     // both srcEntry and srcEntrance can be configured, but srcEntry has higher priority
1193     if (jsonObject.find(SRC_ENTRY) != jsonObject.end()) {
1194         GetValueIfFindKey<std::string>(jsonObject,
1195             jsonObjectEnd,
1196             SRC_ENTRY,
1197             module.srcEntrance,
1198             JsonType::STRING,
1199             false,
1200             g_parseResult,
1201             ArrayType::NOT_ARRAY);
1202     } else {
1203         GetValueIfFindKey<std::string>(jsonObject,
1204             jsonObjectEnd,
1205             SRC_ENTRANCE,
1206             module.srcEntrance,
1207             JsonType::STRING,
1208             false,
1209             g_parseResult,
1210             ArrayType::NOT_ARRAY);
1211     }
1212     GetValueIfFindKey<std::string>(jsonObject,
1213         jsonObjectEnd,
1214         DESCRIPTION,
1215         module.description,
1216         JsonType::STRING,
1217         false,
1218         g_parseResult,
1219         ArrayType::NOT_ARRAY);
1220     GetValueIfFindKey<int32_t>(jsonObject,
1221         jsonObjectEnd,
1222         DESCRIPTION_ID,
1223         module.descriptionId,
1224         JsonType::NUMBER,
1225         false,
1226         g_parseResult,
1227         ArrayType::NOT_ARRAY);
1228     GetValueIfFindKey<std::string>(jsonObject,
1229         jsonObjectEnd,
1230         MODULE_PROCESS,
1231         module.process,
1232         JsonType::STRING,
1233         false,
1234         g_parseResult,
1235         ArrayType::NOT_ARRAY);
1236     GetValueIfFindKey<std::string>(jsonObject,
1237         jsonObjectEnd,
1238         MODULE_MAIN_ELEMENT,
1239         module.mainElement,
1240         JsonType::STRING,
1241         false,
1242         g_parseResult,
1243         ArrayType::NOT_ARRAY);
1244     GetValueIfFindKey<bool>(jsonObject,
1245         jsonObjectEnd,
1246         MODULE_INSTALLATION_FREE,
1247         module.installationFree,
1248         JsonType::BOOLEAN,
1249         false,
1250         g_parseResult,
1251         ArrayType::NOT_ARRAY);
1252     GetValueIfFindKey<std::string>(jsonObject,
1253         jsonObjectEnd,
1254         MODULE_VIRTUAL_MACHINE,
1255         module.virtualMachine,
1256         JsonType::STRING,
1257         false,
1258         g_parseResult,
1259         ArrayType::NOT_ARRAY);
1260     GetValueIfFindKey<std::vector<Metadata>>(jsonObject,
1261         jsonObjectEnd,
1262         META_DATA,
1263         module.metadata,
1264         JsonType::ARRAY,
1265         false,
1266         g_parseResult,
1267         ArrayType::OBJECT);
1268     GetValueIfFindKey<std::vector<Ability>>(jsonObject,
1269         jsonObjectEnd,
1270         MODULE_ABILITIES,
1271         module.abilities,
1272         JsonType::ARRAY,
1273         false,
1274         g_parseResult,
1275         ArrayType::OBJECT);
1276     GetValueIfFindKey<std::vector<Extension>>(jsonObject,
1277         jsonObjectEnd,
1278         MODULE_EXTENSION_ABILITIES,
1279         module.extensionAbilities,
1280         JsonType::ARRAY,
1281         false,
1282         g_parseResult,
1283         ArrayType::OBJECT);
1284     GetValueIfFindKey<std::vector<Dependency>>(jsonObject,
1285         jsonObjectEnd,
1286         MODULE_DEPENDENCIES,
1287         module.dependencies,
1288         JsonType::ARRAY,
1289         false,
1290         g_parseResult,
1291         ArrayType::OBJECT);
1292     GetValueIfFindKey<std::string>(jsonObject,
1293         jsonObjectEnd,
1294         MODULE_COMPILE_MODE,
1295         module.compileMode,
1296         JsonType::STRING,
1297         false,
1298         g_parseResult,
1299         ArrayType::NOT_ARRAY);
1300     GetValueIfFindKey<bool>(jsonObject,
1301         jsonObjectEnd,
1302         MODULE_IS_LIB_ISOLATED,
1303         module.isLibIsolated,
1304         JsonType::BOOLEAN,
1305         false,
1306         g_parseResult,
1307         ArrayType::NOT_ARRAY);
1308     GetValueIfFindKey<std::string>(jsonObject,
1309         jsonObjectEnd,
1310         MODULE_TARGET_MODULE_NAME,
1311         module.targetModule,
1312         JsonType::STRING,
1313         false,
1314         g_parseResult,
1315         ArrayType::NOT_ARRAY);
1316     GetValueIfFindKey<int32_t>(jsonObject,
1317         jsonObjectEnd,
1318         MODULE_TARGET_PRIORITY,
1319         module.targetPriority,
1320         JsonType::NUMBER,
1321         false,
1322         g_parseResult,
1323         ArrayType::NOT_ARRAY);
1324     GetValueIfFindKey<std::vector<ProxyData>>(jsonObject,
1325         jsonObjectEnd,
1326         MODULE_PROXY_DATAS,
1327         module.proxyDatas,
1328         JsonType::ARRAY,
1329         false,
1330         g_parseResult,
1331         ArrayType::OBJECT);
1332     GetValueIfFindKey<std::vector<ProxyData>>(jsonObject,
1333         jsonObjectEnd,
1334         MODULE_PROXY_DATA,
1335         module.proxyData,
1336         JsonType::ARRAY,
1337         false,
1338         g_parseResult,
1339         ArrayType::OBJECT);
1340     GetValueIfFindKey<std::string>(jsonObject,
1341         jsonObjectEnd,
1342         MODULE_BUILD_HASH,
1343         module.buildHash,
1344         JsonType::STRING,
1345         false,
1346         g_parseResult,
1347         ArrayType::NOT_ARRAY);
1348     GetValueIfFindKey<std::string>(jsonObject,
1349         jsonObjectEnd,
1350         MODULE_ISOLATION_MODE,
1351         module.isolationMode,
1352         JsonType::STRING,
1353         false,
1354         g_parseResult,
1355         ArrayType::NOT_ARRAY);
1356 }
1357 
from_json(const nlohmann::json & jsonObject,ModuleJson & moduleJson)1358 void from_json(const nlohmann::json &jsonObject, ModuleJson &moduleJson)
1359 {
1360     const auto &jsonObjectEnd = jsonObject.end();
1361     GetValueIfFindKey<App>(jsonObject,
1362         jsonObjectEnd,
1363         APP,
1364         moduleJson.app,
1365         JsonType::OBJECT,
1366         true,
1367         g_parseResult,
1368         ArrayType::NOT_ARRAY);
1369     GetValueIfFindKey<Module>(jsonObject,
1370         jsonObjectEnd,
1371         MODULE,
1372         moduleJson.module,
1373         JsonType::OBJECT,
1374         true,
1375         g_parseResult,
1376         ArrayType::NOT_ARRAY);
1377 }
1378 } // namespace Profile
1379 
1380 namespace {
1381 struct TransformParam {
1382     bool isSystemApp = false;
1383     bool isPreInstallApp = false;
1384 };
1385 
GetMetadata(std::vector<Metadata> & metadata,const std::vector<Profile::Metadata> & profileMetadata)1386 void GetMetadata(std::vector<Metadata> &metadata, const std::vector<Profile::Metadata> &profileMetadata)
1387 {
1388     for (const Profile::Metadata &item : profileMetadata) {
1389         Metadata tmpMetadata;
1390         tmpMetadata.name = item.name;
1391         tmpMetadata.value = item.value;
1392         tmpMetadata.resource = item.resource;
1393         metadata.emplace_back(tmpMetadata);
1394     }
1395 }
1396 
CheckBundleNameIsValid(const std::string & bundleName)1397 bool CheckBundleNameIsValid(const std::string &bundleName)
1398 {
1399     if (bundleName.empty()) {
1400         return false;
1401     }
1402     if (bundleName.size() < Constants::MIN_BUNDLE_NAME || bundleName.size() > Constants::MAX_BUNDLE_NAME) {
1403         return false;
1404     }
1405     char head = bundleName.at(0);
1406     if (!isalpha(head)) {
1407         return false;
1408     }
1409     for (const auto &c : bundleName) {
1410         if (!isalnum(c) && (c != '.') && (c != '_')) {
1411             return false;
1412         }
1413     }
1414     return true;
1415 }
1416 
CheckModuleNameIsValid(const std::string & moduleName)1417 bool CheckModuleNameIsValid(const std::string &moduleName)
1418 {
1419     if (moduleName.empty()) {
1420         return false;
1421     }
1422     if (moduleName.size() > Constants::MAX_MODULE_NAME) {
1423         return false;
1424     }
1425     if (moduleName.find(Constants::RELATIVE_PATH) != std::string::npos) {
1426         return false;
1427     }
1428     if (moduleName.find(Constants::MODULE_NAME_SEPARATOR) != std::string::npos) {
1429         TAG_LOGE(AAFwkTag::ABILITY_SIM, "module name contain");
1430         return false;
1431     }
1432     return true;
1433 }
1434 
GetResource(const std::string & bundleName,const std::string & moduleName,int32_t resId)1435 Resource GetResource(const std::string &bundleName, const std::string &moduleName, int32_t resId)
1436 {
1437     Resource resource;
1438     resource.bundleName = bundleName;
1439     resource.moduleName = moduleName;
1440     resource.id = resId;
1441     return resource;
1442 }
1443 
ToApplicationInfo(const Profile::ModuleJson & moduleJson,const TransformParam & transformParam,ApplicationInfo & applicationInfo)1444 bool ToApplicationInfo(
1445     const Profile::ModuleJson &moduleJson,
1446     const TransformParam &transformParam,
1447     ApplicationInfo &applicationInfo)
1448 {
1449     TAG_LOGD(AAFwkTag::ABILITY_SIM, "transform ModuleJson to ApplicationInfo");
1450     auto app = moduleJson.app;
1451     applicationInfo.name = app.bundleName;
1452     applicationInfo.bundleName = app.bundleName;
1453 
1454     applicationInfo.versionCode = static_cast<uint32_t>(app.versionCode);
1455     applicationInfo.versionName = app.versionName;
1456     if (app.minCompatibleVersionCode != -1) {
1457         applicationInfo.minCompatibleVersionCode = app.minCompatibleVersionCode;
1458     } else {
1459         applicationInfo.minCompatibleVersionCode = static_cast<int32_t>(applicationInfo.versionCode);
1460     }
1461 
1462     applicationInfo.apiCompatibleVersion = app.minAPIVersion;
1463     applicationInfo.apiTargetVersion = app.targetAPIVersion;
1464 
1465     applicationInfo.iconPath = app.icon;
1466     applicationInfo.iconId = app.iconId;
1467     applicationInfo.label = app.label;
1468     applicationInfo.labelId = app.labelId;
1469     applicationInfo.description = app.description;
1470     applicationInfo.descriptionId = app.descriptionId;
1471     applicationInfo.iconResource = GetResource(app.bundleName, moduleJson.module.name, app.iconId);
1472     applicationInfo.labelResource = GetResource(app.bundleName, moduleJson.module.name, app.labelId);
1473     applicationInfo.descriptionResource = GetResource(app.bundleName, moduleJson.module.name, app.descriptionId);
1474     applicationInfo.targetBundleList = app.targetBundleList;
1475 
1476     if (transformParam.isSystemApp && transformParam.isPreInstallApp) {
1477         applicationInfo.keepAlive = app.keepAlive;
1478         applicationInfo.singleton = app.singleton;
1479         applicationInfo.userDataClearable = app.userDataClearable;
1480         if (app.removable.first) {
1481             applicationInfo.removable = app.removable.second;
1482         } else {
1483             applicationInfo.removable = false;
1484         }
1485         applicationInfo.accessible = app.accessible;
1486     }
1487 
1488     applicationInfo.apiReleaseType = app.apiReleaseType;
1489     applicationInfo.debug = app.debug;
1490     applicationInfo.deviceId = Constants::CURRENT_DEVICE_ID;
1491     applicationInfo.distributedNotificationEnabled = true;
1492     applicationInfo.entityType = Profile::APP_ENTITY_TYPE_DEFAULT_VALUE;
1493     applicationInfo.vendor = app.vendor;
1494     applicationInfo.asanEnabled = app.asanEnabled;
1495     if (app.bundleType == Profile::BUNDLE_TYPE_ATOMIC_SERVICE) {
1496         applicationInfo.bundleType = BundleType::ATOMIC_SERVICE;
1497     }
1498 
1499     applicationInfo.enabled = true;
1500     applicationInfo.multiProjects = app.multiProjects;
1501     applicationInfo.process = app.bundleName;
1502     applicationInfo.targetBundleName = app.targetBundle;
1503     applicationInfo.targetPriority = app.targetPriority;
1504 
1505     auto iterBundleType = std::find_if(std::begin(Profile::BUNDLE_TYPE_MAP),
1506         std::end(Profile::BUNDLE_TYPE_MAP),
1507         [&app](const auto &item) { return item.first == app.bundleType; });
1508     if (iterBundleType != Profile::BUNDLE_TYPE_MAP.end()) {
1509         applicationInfo.bundleType = iterBundleType->second;
1510     }
1511     applicationInfo.compileSdkVersion = app.compileSdkVersion;
1512     applicationInfo.compileSdkType = app.compileSdkType;
1513     return true;
1514 }
1515 
GetBackgroundModes(const std::vector<std::string> & backgroundModes)1516 uint32_t GetBackgroundModes(const std::vector<std::string> &backgroundModes)
1517 {
1518     uint32_t backgroundMode = 0;
1519     for (const std::string &item : backgroundModes) {
1520         if (Profile::BACKGROUND_MODES_MAP.find(item) != Profile::BACKGROUND_MODES_MAP.end()) {
1521             backgroundMode |= Profile::BACKGROUND_MODES_MAP.at(item);
1522         }
1523     }
1524     return backgroundMode;
1525 }
1526 
ConvertCompileMode(const std::string & compileMode)1527 inline CompileMode ConvertCompileMode(const std::string& compileMode)
1528 {
1529     if (compileMode == Profile::COMPILE_MODE_ES_MODULE) {
1530         return CompileMode::ES_MODULE;
1531     } else {
1532         return CompileMode::JS_BUNDLE;
1533     }
1534 }
1535 
ConvertToAbilityWindowMode(const std::vector<std::string> & windowModes,const std::unordered_map<std::string,SupportWindowMode> & windowMap)1536 std::set<SupportWindowMode> ConvertToAbilityWindowMode(const std::vector<std::string> &windowModes,
1537     const std::unordered_map<std::string, SupportWindowMode> &windowMap)
1538 {
1539     std::set<SupportWindowMode> modes;
1540     for_each(windowModes.begin(), windowModes.end(),
1541         [&windowMap, &modes](const auto &mode)->decltype(auto) {
1542         if (windowMap.find(mode) != windowMap.end()) {
1543             modes.emplace(windowMap.at(mode));
1544         }
1545     });
1546     if (modes.empty()) {
1547         modes.insert(SupportWindowMode::FULLSCREEN);
1548         modes.insert(SupportWindowMode::SPLIT);
1549         modes.insert(SupportWindowMode::FLOATING);
1550     }
1551     return modes;
1552 }
1553 
ToAbilityInfo(const Profile::ModuleJson & moduleJson,const Profile::Ability & ability,const TransformParam & transformParam,AbilityInfo & abilityInfo)1554 bool ToAbilityInfo(
1555     const Profile::ModuleJson &moduleJson,
1556     const Profile::Ability &ability,
1557     const TransformParam &transformParam,
1558     AbilityInfo &abilityInfo)
1559 {
1560     TAG_LOGD(AAFwkTag::ABILITY_SIM, "transform ModuleJson to AbilityInfo");
1561     abilityInfo.name = ability.name;
1562     abilityInfo.srcEntrance = ability.srcEntrance;
1563     abilityInfo.description = ability.description;
1564     abilityInfo.descriptionId = ability.descriptionId;
1565     abilityInfo.iconPath = ability.icon;
1566     abilityInfo.iconId = ability.iconId;
1567     abilityInfo.label = ability.label;
1568     abilityInfo.labelId = ability.labelId;
1569     abilityInfo.priority = ability.priority;
1570     abilityInfo.excludeFromMissions = ability.excludeFromMissions;
1571     abilityInfo.unclearableMission = ability.unclearableMission;
1572     abilityInfo.recoverable = ability.recoverable;
1573     abilityInfo.permissions = ability.permissions;
1574     abilityInfo.visible = ability.visible;
1575     abilityInfo.continuable = ability.continuable;
1576     abilityInfo.backgroundModes = GetBackgroundModes(ability.backgroundModes);
1577     GetMetadata(abilityInfo.metadata, ability.metadata);
1578     abilityInfo.package = moduleJson.module.name;
1579     abilityInfo.bundleName = moduleJson.app.bundleName;
1580     abilityInfo.moduleName = moduleJson.module.name;
1581     abilityInfo.applicationName = moduleJson.app.bundleName;
1582     auto iterLaunch = std::find_if(std::begin(Profile::LAUNCH_MODE_MAP),
1583         std::end(Profile::LAUNCH_MODE_MAP),
1584         [&ability](const auto &item) { return item.first == ability.launchType; });
1585     if (iterLaunch != Profile::LAUNCH_MODE_MAP.end()) {
1586         abilityInfo.launchMode = iterLaunch->second;
1587     }
1588     abilityInfo.enabled = true;
1589     abilityInfo.isModuleJson = true;
1590     abilityInfo.isStageBasedModel = true;
1591     abilityInfo.type = AbilityType::PAGE;
1592     for (const std::string &deviceType : moduleJson.module.deviceTypes) {
1593         abilityInfo.deviceTypes.emplace_back(deviceType);
1594     }
1595     abilityInfo.startWindowIcon = ability.startWindowIcon;
1596     abilityInfo.startWindowIconId = ability.startWindowIconId;
1597     abilityInfo.startWindowBackground = ability.startWindowBackground;
1598     abilityInfo.startWindowBackgroundId = ability.startWindowBackgroundId;
1599     abilityInfo.removeMissionAfterTerminate = ability.removeMissionAfterTerminate;
1600     abilityInfo.compileMode = ConvertCompileMode(moduleJson.module.compileMode);
1601     auto iterOrientation = std::find_if(std::begin(Profile::DISPLAY_ORIENTATION_MAP),
1602         std::end(Profile::DISPLAY_ORIENTATION_MAP),
1603         [&ability](const auto &item) { return item.first == ability.orientation; });
1604     if (iterOrientation != Profile::DISPLAY_ORIENTATION_MAP.end()) {
1605         abilityInfo.orientation = iterOrientation->second;
1606     }
1607 
1608     auto modesSet = ConvertToAbilityWindowMode(ability.windowModes, Profile::WINDOW_MODE_MAP);
1609     abilityInfo.windowModes.assign(modesSet.begin(), modesSet.end());
1610     abilityInfo.maxWindowRatio = ability.maxWindowRatio;
1611     abilityInfo.minWindowRatio = ability.minWindowRatio;
1612     abilityInfo.maxWindowWidth = ability.maxWindowWidth;
1613     abilityInfo.minWindowWidth = ability.minWindowWidth;
1614     abilityInfo.maxWindowHeight = ability.maxWindowHeight;
1615     abilityInfo.minWindowHeight = ability.minWindowHeight;
1616     return true;
1617 }
1618 
ToExtensionInfo(const Profile::ModuleJson & moduleJson,const Profile::Extension & extension,const TransformParam & transformParam,ExtensionAbilityInfo & extensionInfo)1619 bool ToExtensionInfo(
1620     const Profile::ModuleJson &moduleJson,
1621     const Profile::Extension &extension,
1622     const TransformParam &transformParam,
1623     ExtensionAbilityInfo &extensionInfo)
1624 {
1625     TAG_LOGD(AAFwkTag::ABILITY_SIM, "transform ModuleJson to ExtensionAbilityInfo");
1626     extensionInfo.type = ConvertToExtensionAbilityType(extension.type);
1627     extensionInfo.name = extension.name;
1628     extensionInfo.srcEntrance = extension.srcEntrance;
1629     extensionInfo.icon = extension.icon;
1630     extensionInfo.iconId = extension.iconId;
1631     extensionInfo.label = extension.label;
1632     extensionInfo.labelId = extension.labelId;
1633     extensionInfo.description = extension.description;
1634     extensionInfo.descriptionId = extension.descriptionId;
1635     if (transformParam.isSystemApp && transformParam.isPreInstallApp) {
1636         extensionInfo.readPermission = extension.readPermission;
1637         extensionInfo.writePermission = extension.writePermission;
1638     }
1639     extensionInfo.priority = extension.priority;
1640     extensionInfo.uri = extension.uri;
1641     extensionInfo.permissions = extension.permissions;
1642     extensionInfo.visible = extension.visible;
1643     GetMetadata(extensionInfo.metadata, extension.metadata);
1644     extensionInfo.bundleName = moduleJson.app.bundleName;
1645     extensionInfo.moduleName = moduleJson.module.name;
1646 
1647     if (extensionInfo.type != ExtensionAbilityType::SERVICE &&
1648         extensionInfo.type != ExtensionAbilityType::DATASHARE) {
1649         extensionInfo.process = extensionInfo.bundleName;
1650         extensionInfo.process.append(":");
1651         extensionInfo.process.append(ConvertToExtensionTypeName(extensionInfo.type));
1652     }
1653 
1654     extensionInfo.compileMode = ConvertCompileMode(moduleJson.module.compileMode);
1655 
1656     return true;
1657 }
1658 
ToInnerModuleInfo(const Profile::ModuleJson & moduleJson,const TransformParam & transformParam,InnerModuleInfo & innerModuleInfo)1659 bool ToInnerModuleInfo(
1660     const Profile::ModuleJson &moduleJson,
1661     const TransformParam &transformParam,
1662     InnerModuleInfo &innerModuleInfo)
1663 {
1664     TAG_LOGD(AAFwkTag::ABILITY_SIM, "transform ModuleJson to InnerModuleInfo");
1665     innerModuleInfo.name = moduleJson.module.name;
1666     innerModuleInfo.modulePackage = moduleJson.module.name;
1667     innerModuleInfo.moduleName = moduleJson.module.name;
1668     innerModuleInfo.description = moduleJson.module.description;
1669     innerModuleInfo.descriptionId = moduleJson.module.descriptionId;
1670     GetMetadata(innerModuleInfo.metadata, moduleJson.module.metadata);
1671     innerModuleInfo.distro.deliveryWithInstall = moduleJson.module.deliveryWithInstall;
1672     innerModuleInfo.distro.installationFree = moduleJson.module.installationFree;
1673     innerModuleInfo.distro.moduleName = moduleJson.module.name;
1674     innerModuleInfo.installationFree = moduleJson.module.installationFree;
1675     if (Profile::MODULE_TYPE_SET.find(moduleJson.module.type) != Profile::MODULE_TYPE_SET.end()) {
1676         innerModuleInfo.distro.moduleType = moduleJson.module.type;
1677         if (moduleJson.module.type == Profile::MODULE_TYPE_ENTRY) {
1678             innerModuleInfo.isEntry = true;
1679         }
1680     }
1681 
1682     innerModuleInfo.mainAbility = moduleJson.module.mainElement;
1683     innerModuleInfo.srcEntrance = moduleJson.module.srcEntrance;
1684     innerModuleInfo.process = moduleJson.module.process;
1685 
1686     for (const std::string &deviceType : moduleJson.module.deviceTypes) {
1687         innerModuleInfo.deviceTypes.emplace_back(deviceType);
1688     }
1689 
1690     if (Profile::VIRTUAL_MACHINE_SET.find(moduleJson.module.virtualMachine) != Profile::VIRTUAL_MACHINE_SET.end()) {
1691         innerModuleInfo.virtualMachine = moduleJson.module.virtualMachine;
1692     }
1693 
1694     innerModuleInfo.uiSyntax = Profile::MODULE_UI_SYNTAX_DEFAULT_VALUE;
1695     innerModuleInfo.pages = moduleJson.module.pages;
1696     innerModuleInfo.dependencies = moduleJson.module.dependencies;
1697     innerModuleInfo.compileMode = moduleJson.module.compileMode;
1698     innerModuleInfo.isModuleJson = true;
1699     innerModuleInfo.isStageBasedModel = true;
1700     innerModuleInfo.isLibIsolated = moduleJson.module.isLibIsolated;
1701     innerModuleInfo.targetModuleName = moduleJson.module.targetModule;
1702     innerModuleInfo.targetPriority = moduleJson.module.targetPriority;
1703     if (moduleJson.module.proxyDatas.empty()) {
1704         innerModuleInfo.proxyDatas = moduleJson.module.proxyData;
1705     } else {
1706         innerModuleInfo.proxyDatas = moduleJson.module.proxyDatas;
1707     }
1708     innerModuleInfo.buildHash = moduleJson.module.buildHash;
1709     innerModuleInfo.isolationMode = moduleJson.module.isolationMode;
1710     return true;
1711 }
1712 
SetInstallationFree(InnerModuleInfo & innerModuleInfo,BundleType bundleType)1713 void SetInstallationFree(InnerModuleInfo &innerModuleInfo, BundleType bundleType)
1714 {
1715     if (bundleType == BundleType::ATOMIC_SERVICE) {
1716         innerModuleInfo.distro.installationFree = true;
1717         innerModuleInfo.installationFree = true;
1718     } else {
1719         innerModuleInfo.distro.installationFree = false;
1720         innerModuleInfo.installationFree = false;
1721     }
1722 }
1723 
ParseExtensionInfo(const Profile::ModuleJson & moduleJson,InnerBundleInfo & innerBundleInfo,const TransformParam & transformParam,InnerModuleInfo & innerModuleInfo)1724 bool ParseExtensionInfo(const Profile::ModuleJson &moduleJson, InnerBundleInfo &innerBundleInfo,
1725     const TransformParam &transformParam, InnerModuleInfo &innerModuleInfo)
1726 {
1727     for (const Profile::Extension &extension : moduleJson.module.extensionAbilities) {
1728         ExtensionAbilityInfo extensionInfo;
1729         if (!ToExtensionInfo(moduleJson, extension, transformParam, extensionInfo)) {
1730             TAG_LOGE(AAFwkTag::ABILITY_SIM, "extensionInfo failed");
1731             return false;
1732         }
1733 
1734         if (innerModuleInfo.mainAbility == extensionInfo.name) {
1735             innerModuleInfo.icon = extensionInfo.icon;
1736             innerModuleInfo.iconId = extensionInfo.iconId;
1737             innerModuleInfo.label = extensionInfo.label;
1738             innerModuleInfo.labelId = extensionInfo.labelId;
1739         }
1740 
1741         std::string key;
1742         key.append(moduleJson.app.bundleName).append(".")
1743             .append(moduleJson.module.name).append(".").append(extension.name);
1744         innerModuleInfo.extensionKeys.emplace_back(key);
1745         innerBundleInfo.InsertExtensionInfo(key, extensionInfo);
1746     }
1747     return true;
1748 }
1749 
ToInnerBundleInfo(const Profile::ModuleJson & moduleJson,InnerBundleInfo & innerBundleInfo)1750 bool ToInnerBundleInfo(const Profile::ModuleJson &moduleJson, InnerBundleInfo &innerBundleInfo)
1751 {
1752     if (!CheckBundleNameIsValid(moduleJson.app.bundleName) || !CheckModuleNameIsValid(moduleJson.module.name)) {
1753         return false;
1754     }
1755     TransformParam transformParam;
1756     ApplicationInfo applicationInfo;
1757     applicationInfo.isSystemApp = innerBundleInfo.GetAppType() == Constants::AppType::SYSTEM_APP;
1758     transformParam.isSystemApp = applicationInfo.isSystemApp;
1759     if (!ToApplicationInfo(moduleJson, transformParam, applicationInfo)) {
1760         return false;
1761     }
1762     InnerModuleInfo innerModuleInfo;
1763     ToInnerModuleInfo(moduleJson, transformParam, innerModuleInfo);
1764     SetInstallationFree(innerModuleInfo, applicationInfo.bundleType);
1765     for (const Profile::Ability &ability : moduleJson.module.abilities) {
1766         AbilityInfo abilityInfo;
1767         ToAbilityInfo(moduleJson, ability, transformParam, abilityInfo);
1768         if (innerModuleInfo.mainAbility == abilityInfo.name) {
1769             innerModuleInfo.icon = abilityInfo.iconPath;
1770             innerModuleInfo.iconId = abilityInfo.iconId;
1771             innerModuleInfo.label = abilityInfo.label;
1772             innerModuleInfo.labelId = abilityInfo.labelId;
1773         }
1774         std::string key;
1775         key.append(moduleJson.app.bundleName).append(".")
1776             .append(moduleJson.module.name).append(".").append(abilityInfo.name);
1777         innerModuleInfo.abilityKeys.emplace_back(key);
1778         innerBundleInfo.InsertAbilitiesInfo(key, abilityInfo);
1779     }
1780     if (!ParseExtensionInfo(moduleJson, innerBundleInfo, transformParam, innerModuleInfo)) {
1781         return false;
1782     }
1783     if (!transformParam.isPreInstallApp &&
1784         innerModuleInfo.distro.moduleType != Profile::MODULE_TYPE_SHARED) {
1785         applicationInfo.needAppDetail = true;
1786         applicationInfo.appDetailAbilityLibraryPath = Profile::APP_DETAIL_ABILITY_LIBRARY_PATH;
1787         if ((applicationInfo.labelId == 0) && (applicationInfo.label.empty())) {
1788             applicationInfo.label = applicationInfo.bundleName;
1789         }
1790     }
1791     innerBundleInfo.SetCurrentModulePackage(moduleJson.module.name);
1792     innerBundleInfo.SetBaseApplicationInfo(applicationInfo);
1793     innerBundleInfo.InsertInnerModuleInfo(moduleJson.module.name, innerModuleInfo);
1794     innerBundleInfo.SetTargetPriority(moduleJson.app.targetPriority);
1795     return true;
1796 }
1797 } // namespace
1798 
TransformTo(const std::vector<uint8_t> & buf,InnerBundleInfo & innerBundleInfo) const1799 ErrCode ModuleProfile::TransformTo(const std::vector<uint8_t> &buf, InnerBundleInfo &innerBundleInfo) const
1800 {
1801     TAG_LOGD(AAFwkTag::ABILITY_SIM, "transform module.json stream to InnerBundleInfo");
1802     std::vector<uint8_t> buffer = buf;
1803     buffer.push_back('\0');
1804     nlohmann::json jsonObject = nlohmann::json::parse(buffer.data(), nullptr, false);
1805     if (jsonObject.is_discarded()) {
1806         TAG_LOGE(AAFwkTag::ABILITY_SIM, "bad profile");
1807         return ERR_APPEXECFWK_PARSE_BAD_PROFILE;
1808     }
1809 
1810     Profile::ModuleJson moduleJson = jsonObject.get<Profile::ModuleJson>();
1811     if (Profile::g_parseResult != ERR_OK) {
1812         TAG_LOGE(AAFwkTag::ABILITY_SIM, "g_parseResult:%{public}d", Profile::g_parseResult);
1813         int32_t ret = Profile::g_parseResult;
1814         // need recover parse result to ERR_OK
1815         Profile::g_parseResult = ERR_OK;
1816         return ret;
1817     }
1818 
1819     if (!ToInnerBundleInfo(moduleJson, innerBundleInfo)) {
1820         return ERR_APPEXECFWK_PARSE_PROFILE_PROP_CHECK_ERROR;
1821     }
1822 
1823     return ERR_OK;
1824 }
1825 }  // namespace AppExecFwk
1826 }  // namespace OHOS
1827