• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2021 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 #ifndef FOUNDATION_APPEXECFWK_SERVICES_BUNDLEMGR_INCLUDE_INNER_BUNDLE_INFO_H
17 #define FOUNDATION_APPEXECFWK_SERVICES_BUNDLEMGR_INCLUDE_INNER_BUNDLE_INFO_H
18 
19 #include "nocopyable.h"
20 #include "permission/permission_kit.h"
21 #include "app_log_wrapper.h"
22 
23 #include "appexecfwk_errors.h"
24 #include "ability_info.h"
25 #include "form_info.h"
26 #include "bundle_info.h"
27 #include "hap_module_info.h"
28 #include "bundle_constants.h"
29 #include "json_serializer.h"
30 #include "common_profile.h"
31 #include "shortcut_info.h"
32 
33 namespace OHOS {
34 namespace AppExecFwk {
35 
36 struct Distro {
37     bool deliveryWithInstall;
38     std::string moduleName;
39     std::string moduleType;
40     bool installationFree = false;
41 };
42 
43 struct DefPermission {
44     std::string name;
45     std::string grantMode;
46     std::vector<std::string> availableScope;
47     std::string label;
48     int32_t labelId;
49     std::string description;
50     int32_t descriptionId;
51 };
52 
53 struct UsedScene {
54     std::vector<std::string> ability;
55     std::string when;
56 };
57 
58 struct ReqPermission {
59     std::string name;
60     std::string reason;
61     UsedScene usedScene;
62 };
63 
64 struct InnerModuleInfo {
65     std::string modulePackage;
66     std::string moduleName;
67     std::string modulePath;
68     std::string moduleDataDir;
69     std::string moduleResPath;
70     std::string label;
71     int32_t labelId = 0;
72     std::string description;
73     int32_t descriptionId = 0;
74     std::string mainAbility;
75     bool isEntry;
76     bool installationFree;
77     MetaData metaData;
78     ModuleColorMode colorMode = ModuleColorMode::AUTO;
79     Distro distro;
80     std::vector<std::string> reqCapabilities;
81     std::vector<ReqPermission> reqPermissions;
82     std::vector<DefPermission> defPermissions;
83     std::vector<std::string> abilityKeys;
84     std::vector<std::string> skillKeys;
85 };
86 
87 struct SkillUri {
88     std::string scheme;
89     std::string host;
90     std::string port;
91     std::string path;
92     std::string type;
93 };
94 
95 struct Skill {
96     std::vector<std::string> actions;
97     std::vector<std::string> entities;
98     std::vector<SkillUri> uris;
99 };
100 
101 enum class JsonType {
102     NULLABLE,
103     BOOLEAN,
104     NUMBER,
105     OBJECT,
106     ARRAY,
107     STRING,
108 };
109 
110 enum class ArrayType {
111     NUMBER,
112     OBJECT,
113     STRING,
114     NOT_ARRAY,
115 };
116 
117 template<typename T, typename dataType>
CheckArrayType(const nlohmann::json & jsonObject,const std::string & key,dataType & data,ArrayType arrayType,int32_t & parseResult)118 void CheckArrayType(
119     const nlohmann::json &jsonObject, const std::string &key, dataType &data, ArrayType arrayType, int32_t &parseResult)
120 {
121     auto arrays = jsonObject.at(key);
122     if (arrays.empty()) {
123         APP_LOGI("array is empty");
124         return;
125     }
126     switch (arrayType) {
127         case ArrayType::STRING:
128             for (const auto &array : arrays) {
129                 if (!array.is_string()) {
130                     APP_LOGE("array %{public}s is not string type", key.c_str());
131                     parseResult = ERR_APPEXECFWK_PARSE_PROFILE_PROP_TYPE_ERROR;
132                 }
133             }
134             if (parseResult == ERR_OK) {
135                 data = jsonObject.at(key).get<T>();
136             }
137             break;
138         case ArrayType::OBJECT:
139             for (const auto &array : arrays) {
140                 if (!array.is_object()) {
141                     APP_LOGE("array %{public}s is not object type", key.c_str());
142                     parseResult = ERR_APPEXECFWK_PARSE_PROFILE_PROP_TYPE_ERROR;
143                     break;
144                 }
145             }
146             if (parseResult == ERR_OK) {
147                 data = jsonObject.at(key).get<T>();
148             }
149             break;
150         case ArrayType::NUMBER:
151             for (const auto &array : arrays) {
152                 if (!array.is_number()) {
153                     APP_LOGE("array %{public}s is not number type", key.c_str());
154                     parseResult = ERR_APPEXECFWK_PARSE_PROFILE_PROP_TYPE_ERROR;
155                 }
156             }
157             if (parseResult == ERR_OK) {
158                 data = jsonObject.at(key).get<T>();
159             }
160             break;
161         case ArrayType::NOT_ARRAY:
162             APP_LOGE("array %{public}s is not string type", key.c_str());
163             break;
164         default:
165             APP_LOGE("array %{public}s type error", key.c_str());
166             break;
167     }
168 }
169 
170 template<typename T, typename dataType>
GetValueIfFindKey(const nlohmann::json & jsonObject,const nlohmann::detail::iter_impl<const nlohmann::json> & end,const std::string & key,dataType & data,JsonType jsonType,bool isNecessary,int32_t & parseResult,ArrayType arrayType)171 void GetValueIfFindKey(const nlohmann::json &jsonObject, const nlohmann::detail::iter_impl<const nlohmann::json> &end,
172     const std::string &key, dataType &data, JsonType jsonType, bool isNecessary, int32_t &parseResult,
173     ArrayType arrayType)
174 {
175     if (parseResult) {
176         return;
177     }
178     if (jsonObject.find(key) != end) {
179         switch (jsonType) {
180             case JsonType::BOOLEAN:
181                 if (!jsonObject.at(key).is_boolean()) {
182                     APP_LOGE("type is error %{public}s is not boolean", key.c_str());
183                     parseResult = ERR_APPEXECFWK_PARSE_PROFILE_PROP_TYPE_ERROR;
184                     break;
185                 }
186                 data = jsonObject.at(key).get<T>();
187                 break;
188             case JsonType::NUMBER:
189                 if (!jsonObject.at(key).is_number()) {
190                     APP_LOGE("type is error %{public}s is not number", key.c_str());
191                     parseResult = ERR_APPEXECFWK_PARSE_PROFILE_PROP_TYPE_ERROR;
192                     break;
193                 }
194                 data = jsonObject.at(key).get<T>();
195                 break;
196             case JsonType::OBJECT:
197                 if (!jsonObject.at(key).is_object()) {
198                     APP_LOGE("type is error %{public}s is not object", key.c_str());
199                     parseResult = ERR_APPEXECFWK_PARSE_PROFILE_PROP_TYPE_ERROR;
200                     break;
201                 }
202                 data = jsonObject.at(key).get<T>();
203                 break;
204             case JsonType::ARRAY:
205                 if (!jsonObject.at(key).is_array()) {
206                     APP_LOGE("type is error %{public}s is not array", key.c_str());
207                     parseResult = ERR_APPEXECFWK_PARSE_PROFILE_PROP_TYPE_ERROR;
208                     break;
209                 }
210                 CheckArrayType<T>(jsonObject, key, data, arrayType, parseResult);
211                 break;
212             case JsonType::STRING:
213                 if (!jsonObject.at(key).is_string()) {
214                     APP_LOGE("type is error %{public}s is not string", key.c_str());
215                     parseResult = ERR_APPEXECFWK_PARSE_PROFILE_PROP_TYPE_ERROR;
216                     break;
217                 }
218                 data = jsonObject.at(key).get<T>();
219                 break;
220             case JsonType::NULLABLE:
221                 APP_LOGE("type is error %{public}s is nullable", key.c_str());
222                 break;
223             default:
224                 APP_LOGE("type is error %{public}s is not jsonType", key.c_str());
225                 parseResult = ERR_APPEXECFWK_PARSE_PROFILE_PROP_TYPE_ERROR;
226         }
227         return;
228     }
229     if (isNecessary) {
230         APP_LOGE("profile prop %{public}s is mission", key.c_str());
231         parseResult = ERR_APPEXECFWK_PARSE_PROFILE_MISSING_PROP;
232     }
233 }
234 
235 class InnerBundleInfo {
236 public:
237     enum class BundleStatus {
238         ENABLED = 1,
239         DISABLED,
240     };
241 
242     InnerBundleInfo();
243     ~InnerBundleInfo();
244     /**
245      * @brief Transform the InnerBundleInfo object to json.
246      * @param jsonObject Indicates the obtained json object.
247      * @return
248      */
249     void ToJson(nlohmann::json &jsonObject) const;
250     /**
251      * @brief Transform the json object to InnerBundleInfo object.
252      * @param jsonObject Indicates the obtained json object.
253      * @return Returns 0 if the json object parsed successfully; returns error code otherwise.
254      */
255     int32_t FromJson(const nlohmann::json &jsonObject);
256     /**
257      * @brief Add module info to old InnerBundleInfo object.
258      * @param newInfo Indicates the new InnerBundleInfo object.
259      * @return Returns true if the module successfully added; returns false otherwise.
260      */
261     bool AddModuleInfo(const InnerBundleInfo &newInfo);
262     /**
263      * @brief Update module info to old InnerBundleInfo object.
264      * @param newInfo Indicates the new InnerBundleInfo object.
265      * @return
266      */
267     void UpdateModuleInfo(const InnerBundleInfo &newInfo);
268     /**
269      * @brief Update version info to old InnerBundleInfo object.
270      * @param newInfo Indicates the new InnerBundleInfo object.
271      * @return
272      */
273     void UpdateVersionInfo(const InnerBundleInfo &newInfo);
274     /**
275      * @brief Remove module info from InnerBundleInfo object.
276      * @param modulePackage Indicates the module package to be remove.
277      * @return
278      */
279     void RemoveModuleInfo(const std::string &modulePackage);
280     /**
281      * @brief Find hap module info by module package.
282      * @param modulePackage Indicates the module package.
283      * @return Returns the HapModuleInfo object if find it; returns null otherwise.
284      */
285     std::optional<HapModuleInfo> FindHapModuleInfo(const std::string &modulePackage) const;
286     /**
287      * @brief Find skills by keyName.
288      * @param keyName Indicates the keyName.
289      * @return Returns the skills object if find it; returns null otherwise.
290      */
291     std::optional<std::vector<Skill>> FindSkills(const std::string &keyName) const;
292     /**
293      * @brief Find abilityInfo by bundle name and ability name.
294      * @param bundleName Indicates the bundle name.
295      * @param abilityName Indicates the ability name
296      * @return Returns the AbilityInfo object if find it; returns null otherwise.
297      */
298     std::optional<AbilityInfo> FindAbilityInfo(const std::string &bundleName, const std::string &abilityName) const;
299     /**
300      * @brief Find abilityInfo of list  by bundle name.
301      * @param bundleName Indicates the bundle name.
302      * @return Returns the AbilityInfo of list if find it; returns null otherwise.
303      */
304     std::optional<std::vector<AbilityInfo>> FindAbilityInfos(const std::string &bundleName) const;
305     /**
306      * @brief Transform the InnerBundleInfo object to string.
307      * @return Returns the string object
308      */
309     std::string ToString() const;
310     /**
311      * @brief Add ability infos to old InnerBundleInfo object.
312      * @param abilityInfos Indicates the AbilityInfo object to be add.
313      * @return
314      */
AddModuleAbilityInfo(const std::map<std::string,AbilityInfo> & abilityInfos)315     void AddModuleAbilityInfo(const std::map<std::string, AbilityInfo> &abilityInfos)
316     {
317         for (const auto &ability : abilityInfos) {
318             baseAbilityInfos_.try_emplace(ability.first, ability.second);
319         }
320     }
321     /**
322      * @brief Add skill infos to old InnerBundleInfo object.
323      * @param skillInfos Indicates the Skill object to be add.
324      * @return
325      */
AddModuleSkillInfo(const std::map<std::string,std::vector<Skill>> & skillInfos)326     void AddModuleSkillInfo(const std::map<std::string, std::vector<Skill>> &skillInfos)
327     {
328         for (const auto &skills : skillInfos) {
329             skillInfos_.try_emplace(skills.first, skills.second);
330         }
331     }
332     /**
333      * @brief Add form infos to old InnerBundleInfo object.
334      * @param formInfos Indicates the Forms object to be add.
335      * @return
336      */
AddModuleFormInfo(const std::map<std::string,std::vector<FormInfo>> & formInfos)337     void AddModuleFormInfo(const std::map<std::string, std::vector<FormInfo>> &formInfos)
338     {
339         for (const auto &forms : formInfos) {
340             formInfos_.try_emplace(forms.first, forms.second);
341         }
342     }
343     /**
344      * @brief Add shortcut infos to old InnerBundleInfo object.
345      * @param shortcutInfos Indicates the Shortcut object to be add.
346      * @return
347      */
AddModuleShortcutInfo(const std::map<std::string,ShortcutInfo> & shortcutInfos)348     void AddModuleShortcutInfo(const std::map<std::string, ShortcutInfo> &shortcutInfos)
349     {
350         for (const auto &shortcut : shortcutInfos) {
351             shortcutInfos_.try_emplace(shortcut.first, shortcut.second);
352         }
353     }
354     /**
355      * @brief Add innerModuleInfos to old InnerBundleInfo object.
356      * @param innerModuleInfos Indicates the InnerModuleInfo object to be add.
357      * @return
358      */
AddInnerModuleInfo(const std::map<std::string,InnerModuleInfo> & innerModuleInfos)359     void AddInnerModuleInfo(const std::map<std::string, InnerModuleInfo> &innerModuleInfos)
360     {
361         for (const auto &info : innerModuleInfos) {
362             innerModuleInfos_.try_emplace(info.first, info.second);
363         }
364     }
365     /**
366      * @brief Get application name.
367      * @return Return application name
368      */
GetApplicationName()369     std::string GetApplicationName() const
370     {
371         return baseApplicationInfo_.name;
372     }
373     /**
374      * @brief Set bundle status.
375      * @param status Indicates the BundleStatus object to set.
376      * @return
377      */
SetBundleStatus(const BundleStatus & status)378     void SetBundleStatus(const BundleStatus &status)
379     {
380         bundleStatus_ = status;
381     }
382     /**
383      * @brief Get bundle status.
384      * @return Return the BundleStatus object
385      */
GetBundleStatus()386     BundleStatus GetBundleStatus() const
387     {
388         return bundleStatus_;
389     }
390     /**
391      * @brief Set bundle install time.
392      * @param time Indicates the install time to set.
393      * @return
394      */
SetBundleInstallTime(const int64_t time)395     void SetBundleInstallTime(const int64_t time)
396     {
397         baseBundleInfo_.installTime = time;
398         baseBundleInfo_.updateTime = time;
399     }
400     /**
401      * @brief Get bundle install time.
402      * @return Return the bundle install time.
403      */
GetBundleInstallTime()404     int64_t GetBundleInstallTime() const
405     {
406         return baseBundleInfo_.installTime;
407     }
408     /**
409      * @brief Set bundle update time.
410      * @param time Indicates the update time to set.
411      * @return
412      */
SetBundleUpdateTime(const int64_t time)413     void SetBundleUpdateTime(const int64_t time)
414     {
415         baseBundleInfo_.updateTime = time;
416     }
417     /**
418      * @brief Get bundle update time.
419      * @return Return the bundle update time.
420      */
GetBundleUpdateTime()421     int64_t GetBundleUpdateTime() const
422     {
423         return baseBundleInfo_.updateTime;
424     }
425     /**
426      * @brief Set whether the application supports backup.
427      * @param isSupportBackup Indicates the supports status to set.
428      */
SetIsSupportBackup(bool isSupportBackup)429     void SetIsSupportBackup(bool isSupportBackup)
430     {
431         isSupportBackup_ = isSupportBackup;
432     }
433     /**
434      * @brief Get whether the application supports backup.
435      * @return Return the supports status.
436      */
GetIsSupportBackup()437     bool GetIsSupportBackup() const
438     {
439         return isSupportBackup_;
440     }
441     /**
442      * @brief Get bundle name.
443      * @return Return bundle name
444      */
GetBundleName()445     std::string GetBundleName() const
446     {
447         return baseApplicationInfo_.bundleName;
448     }
449     /**
450      * @brief Set baseBundleInfo.
451      * @param bundleInfo Indicates the BundleInfo object.
452      */
SetBaseBundleInfo(const BundleInfo & bundleInfo)453     void SetBaseBundleInfo(const BundleInfo &bundleInfo)
454     {
455         baseBundleInfo_ = bundleInfo;
456     }
457     /**
458      * @brief Get baseBundleInfo.
459      * @return Return the BundleInfo object.
460      */
GetBaseBundleInfo()461     BundleInfo GetBaseBundleInfo() const
462     {
463         return baseBundleInfo_;
464     }
465     /**
466      * @brief Set baseApplicationInfo.
467      * @param applicationInfo Indicates the ApplicationInfo object.
468      */
SetBaseApplicationInfo(const ApplicationInfo & applicationInfo)469     void SetBaseApplicationInfo(const ApplicationInfo &applicationInfo)
470     {
471         baseApplicationInfo_ = applicationInfo;
472     }
473     /**
474      * @brief Update baseApplicationInfo.
475      * @param applicationInfo Indicates the ApplicationInfo object.
476      */
UpdateBaseApplicationInfo(const ApplicationInfo & applicationInfo)477     void UpdateBaseApplicationInfo(const ApplicationInfo &applicationInfo)
478     {
479         baseApplicationInfo_.label = applicationInfo.label;
480         baseApplicationInfo_.labelId = applicationInfo.labelId;
481         baseApplicationInfo_.iconPath = applicationInfo.iconPath;
482         baseApplicationInfo_.iconId = applicationInfo.iconId;
483         baseApplicationInfo_.description = applicationInfo.description;
484         baseApplicationInfo_.descriptionId = applicationInfo.descriptionId;
485         if (!baseApplicationInfo_.isLauncherApp) {
486             baseApplicationInfo_.isLauncherApp = applicationInfo.isLauncherApp;
487         }
488     }
489     /**
490      * @brief Get baseApplicationInfo.
491      * @return Return the ApplicationInfo object.
492      */
GetBaseApplicationInfo()493     ApplicationInfo GetBaseApplicationInfo() const
494     {
495         return baseApplicationInfo_;
496     }
497     /**
498      * @brief Get application enabled.
499      * @return Return whether the application is enabled.
500      */
GetApplicationEnabled()501     bool GetApplicationEnabled() const
502     {
503         return baseApplicationInfo_.enabled;
504     }
505     /**
506      * @brief Set application enabled.
507      * @return Return whether the application is enabled.
508      */
SetApplicationEnabled(bool enabled)509     void SetApplicationEnabled(bool enabled)
510     {
511         baseApplicationInfo_.enabled = enabled;
512     }
513     /**
514      * @brief Get application code path.
515      * @return Return the string object.
516      */
GetAppCodePath()517     std::string GetAppCodePath() const
518     {
519         return baseApplicationInfo_.codePath;
520     }
521     /**
522      * @brief Set application code path.
523      * @param codePath Indicates the code path to be set.
524      */
SetAppCodePath(std::string codePath)525     void SetAppCodePath(std::string codePath)
526     {
527         baseApplicationInfo_.codePath = codePath;
528     }
529     /**
530      * @brief Insert innerModuleInfos.
531      * @param modulePackage Indicates the modulePackage object as key.
532      * @param innerModuleInfo Indicates the InnerModuleInfo object as value.
533      */
InsertInnerModuleInfo(const std::string & modulePackage,const InnerModuleInfo & innerModuleInfo)534     void InsertInnerModuleInfo(const std::string &modulePackage, const InnerModuleInfo &innerModuleInfo)
535     {
536         innerModuleInfos_.try_emplace(modulePackage, innerModuleInfo);
537     }
538     /**
539      * @brief Insert baseAbilityInfos.
540      * @param keyName Indicates the key.
541      * @param abilityInfo Indicates the AbilityInfo object as value.
542      */
InsertAbilitiesInfo(const std::string & keyName,const AbilityInfo & abilityInfo)543     void InsertAbilitiesInfo(const std::string &keyName, const AbilityInfo &abilityInfo)
544     {
545         baseAbilityInfos_.emplace(keyName, abilityInfo);
546     }
547     /**
548      * @brief Insert skillInfos.
549      * @param keyName Indicates the abilityName as key.
550      * @param abilityInfo Indicates the Skills object as value.
551      */
InsertSkillInfo(const std::string & abilityName,const std::vector<Skill> & skills)552     void InsertSkillInfo(const std::string &abilityName, const std::vector<Skill> &skills)
553     {
554         skillInfos_.emplace(abilityName, skills);
555     }
556     /**
557      * @brief Find AbilityInfo object by Uri.
558      * @param abilityUri Indicates the ability uri.
559      * @return Returns the AbilityInfo object if find it; returns null otherwise.
560      */
FindAbilityInfoByUri(const std::string & abilityUri)561     std::optional<AbilityInfo> FindAbilityInfoByUri(const std::string &abilityUri) const
562     {
563         APP_LOGI("Uri is %{public}s", abilityUri.c_str());
564         for (const auto &ability : baseAbilityInfos_) {
565             if (ability.second.uri.size() < Constants::DATA_ABILITY_URI_PREFIX.size()) {
566                 continue;
567             }
568             auto configUri = ability.second.uri.substr(Constants::DATA_ABILITY_URI_PREFIX.size());
569             APP_LOGI("configUri is %{public}s", configUri.c_str());
570             if (configUri == abilityUri) {
571                 return ability.second;
572             }
573         }
574         return std::nullopt;
575     }
576     /**
577      * @brief Get all ability names in application.
578      * @return Returns ability names.
579      */
GetAbilityNames()580     auto GetAbilityNames() const
581     {
582         std::vector<std::string> abilityNames;
583         for (auto &ability : baseAbilityInfos_) {
584             abilityNames.emplace_back(ability.second.name);
585         }
586         return abilityNames;
587     }
588     /**
589      * @brief Get all skill keys in application.
590      * @return Returns skill keys.
591      */
GetSkillKeys()592     auto GetSkillKeys() const
593     {
594         std::vector<std::string> skillKeys;
595         for (auto &skill : skillInfos_) {
596             skillKeys.emplace_back(skill.first);
597         }
598         return skillKeys;
599     }
600     /**
601      * @brief Get version code in application.
602      * @return Returns version code.
603      */
GetVersionCode()604     uint32_t GetVersionCode() const
605     {
606         return baseBundleInfo_.versionCode;
607     }
608     /**
609      * @brief Get signature key in application.
610      * @return Returns signature key.
611      */
GetSignatureKey()612     std::string GetSignatureKey() const
613     {
614         return baseApplicationInfo_.signatureKey;
615     }
616     /**
617      * @brief Set application base data dir.
618      * @param baseDataDir Indicates the dir to be set.
619      */
SetBaseDataDir(std::string baseDataDir)620     void SetBaseDataDir(std::string baseDataDir)
621     {
622         baseDataDir_ = baseDataDir;
623     }
624     /**
625      * @brief Get application base data dir.
626      * @return Return the string object.
627      */
GetBaseDataDir()628     std::string GetBaseDataDir() const
629     {
630         return baseDataDir_;
631     }
632     /**
633      * @brief Get application data dir.
634      * @return Return the string object.
635      */
GetAppDataDir()636     std::string GetAppDataDir() const
637     {
638         return baseApplicationInfo_.dataDir;
639     }
640     /**
641      * @brief Set application data dir.
642      * @param dataDir Indicates the data Dir to be set.
643      */
SetAppDataDir(std::string dataDir)644     void SetAppDataDir(std::string dataDir)
645     {
646         baseApplicationInfo_.dataDir = dataDir;
647     }
648     /**
649      * @brief Set application data base dir.
650      * @param dataBaseDir Indicates the data base Dir to be set.
651      */
SetAppDataBaseDir(std::string dataBaseDir)652     void SetAppDataBaseDir(std::string dataBaseDir)
653     {
654         baseApplicationInfo_.dataBaseDir = dataBaseDir;
655     }
656     /**
657      * @brief Set application cache dir.
658      * @param cacheDir Indicates the cache Dir to be set.
659      */
SetAppCacheDir(std::string cacheDir)660     void SetAppCacheDir(std::string cacheDir)
661     {
662         baseApplicationInfo_.cacheDir = cacheDir;
663     }
664     /**
665      * @brief Set application uid.
666      * @param uid Indicates the uid to be set.
667      */
SetUid(int uid)668     void SetUid(int uid)
669     {
670         uid_ = uid;
671         baseBundleInfo_.uid = uid;
672     }
673     /**
674      * @brief Get application uid.
675      * @return Returns the uid.
676      */
GetUid()677     int GetUid() const
678     {
679         return uid_;
680     }
681     /**
682      * @brief Get application gid.
683      * @return Returns the gid.
684      */
GetGid()685     int GetGid() const
686     {
687         return gid_;
688     }
689     /**
690      * @brief Set application gid.
691      * @param gid Indicates the gid to be set.
692      */
SetGid(int gid)693     void SetGid(int gid)
694     {
695         gid_ = gid;
696         baseBundleInfo_.gid = gid;
697     }
698     /**
699      * @brief Get application AppType.
700      * @return Returns the AppType.
701      */
GetAppType()702     Constants::AppType GetAppType() const
703     {
704         return appType_;
705     }
706     /**
707      * @brief Set application AppType.
708      * @param gid Indicates the AppType to be set.
709      */
SetAppType(Constants::AppType appType)710     void SetAppType(Constants::AppType appType)
711     {
712         appType_ = appType;
713     }
714     /**
715      * @brief Get application user id.
716      * @return Returns the user id.
717      */
GetUserId()718     int GetUserId() const
719     {
720         return userId_;
721     }
722     /**
723      * @brief Set application user id.
724      * @param gid Indicates the user id to be set.
725      */
SetUserId(int userId)726     void SetUserId(int userId)
727     {
728         userId_ = userId;
729     }
730 
731     // only used in install progress with newInfo
GetCurrentModulePackage()732     std::string GetCurrentModulePackage() const
733     {
734         return currentPackage_;
735     }
SetCurrentModulePackage(const std::string & modulePackage)736     void SetCurrentModulePackage(const std::string &modulePackage)
737     {
738         currentPackage_ = modulePackage;
739     }
AddModuleSrcDir(const std::string & moduleSrcDir)740     void AddModuleSrcDir(const std::string &moduleSrcDir)
741     {
742         if (innerModuleInfos_.count(currentPackage_) == 1) {
743             innerModuleInfos_.at(currentPackage_).modulePath = moduleSrcDir;
744         }
745     }
AddModuleDataDir(const std::string & moduleDataDir)746     void AddModuleDataDir(const std::string &moduleDataDir)
747     {
748         if (innerModuleInfos_.count(currentPackage_) == 1) {
749             innerModuleInfos_.at(currentPackage_).moduleDataDir = moduleDataDir;
750         }
751     }
AddModuleResPath(const std::string & moduleSrcDir)752     void AddModuleResPath(const std::string &moduleSrcDir)
753     {
754         if (innerModuleInfos_.count(currentPackage_) == 1) {
755             std::string moduleResPath = moduleSrcDir + Constants::PATH_SEPARATOR + Constants::ASSETS_DIR +
756                                         Constants::PATH_SEPARATOR +
757                                         innerModuleInfos_.at(currentPackage_).distro.moduleName +
758                                         Constants::PATH_SEPARATOR + Constants::RESOURCES_INDEX;
759             innerModuleInfos_.at(currentPackage_).moduleResPath = moduleResPath;
760             for (auto &abilityInfo : baseAbilityInfos_) {
761                 abilityInfo.second.resourcePath = moduleResPath;
762             }
763         }
764     }
GetDefPermissions()765     std::vector<DefPermission> GetDefPermissions() const
766     {
767         std::vector<DefPermission> defPermissions;
768         if (innerModuleInfos_.count(currentPackage_) == 1) {
769             defPermissions = innerModuleInfos_.at(currentPackage_).defPermissions;
770         }
771         return defPermissions;
772     }
773 
GetReqPermissions()774     std::vector<ReqPermission> GetReqPermissions() const
775     {
776         std::vector<ReqPermission> reqPermissions;
777         if (innerModuleInfos_.count(currentPackage_) == 1) {
778             reqPermissions = innerModuleInfos_.at(currentPackage_).reqPermissions;
779         }
780         return reqPermissions;
781     }
782 
FindModule(std::string modulePackage)783     bool FindModule(std::string modulePackage) const
784     {
785         return (innerModuleInfos_.find(modulePackage) != innerModuleInfos_.end());
786     }
787 
SetIsKeepData(bool isKeepData)788     void SetIsKeepData(bool isKeepData)
789     {
790         isKeepData_ = isKeepData;
791     }
792 
GetIsKeepData()793     bool GetIsKeepData() const
794     {
795         return isKeepData_;
796     }
797 
SetIsKeepAlive(bool isKeepAlive)798     void SetIsKeepAlive(bool isKeepAlive)
799     {
800         baseBundleInfo_.isKeepAlive = isKeepAlive;
801     }
802 
GetIsKeepAlive()803     bool GetIsKeepAlive() const
804     {
805         return baseBundleInfo_.isKeepAlive;
806     }
807 
SetIsNativeApp(bool isNativeApp)808     void SetIsNativeApp(bool isNativeApp)
809     {
810         baseBundleInfo_.isNativeApp = isNativeApp;
811     }
812 
GetIsNativeApp()813     bool GetIsNativeApp() const
814     {
815         return baseBundleInfo_.isNativeApp;
816     }
817 
SetIsLauncherApp(bool isLauncher)818     void SetIsLauncherApp(bool isLauncher)
819     {
820         baseApplicationInfo_.isLauncherApp = isLauncher;
821     }
822 
GetIsLauncherApp()823     bool GetIsLauncherApp() const
824     {
825         return baseApplicationInfo_.isLauncherApp;
826     }
827 
SetMainAbility(const std::string & mainAbility)828     void SetMainAbility(const std::string &mainAbility)
829     {
830         mainAbility_ = mainAbility;
831     }
832 
GetMainAbility()833     std::string GetMainAbility() const
834     {
835         return mainAbility_;
836     }
837 
SetMainAbilityName(const std::string & mainAbilityName)838     void SetMainAbilityName(const std::string &mainAbilityName)
839     {
840         mainAbilityName_ = mainAbilityName;
841     }
842 
GetMainAbilityName()843     std::string GetMainAbilityName() const
844     {
845         return mainAbilityName_;
846     }
847 
GetMainAbilityInfo(AbilityInfo & abilityInfo)848     void GetMainAbilityInfo(AbilityInfo &abilityInfo) const
849     {
850         if (!mainAbility_.empty()) {
851             abilityInfo = baseAbilityInfos_.at(mainAbility_);
852         }
853     }
854 
GetModuleDir(std::string modulePackage)855     std::string GetModuleDir(std::string modulePackage) const
856     {
857         if (innerModuleInfos_.find(modulePackage) != innerModuleInfos_.end()) {
858             return innerModuleInfos_.at(modulePackage).modulePath;
859         }
860         return Constants::EMPTY_STRING;
861     }
862 
GetModuleDataDir(std::string modulePackage)863     std::string GetModuleDataDir(std::string modulePackage) const
864     {
865         if (innerModuleInfos_.find(modulePackage) != innerModuleInfos_.end()) {
866             return innerModuleInfos_.at(modulePackage).moduleDataDir;
867         }
868         return Constants::EMPTY_STRING;
869     }
870 
IsDisabled()871     bool IsDisabled() const
872     {
873         return (bundleStatus_ == BundleStatus::DISABLED);
874     }
875 
SetSeInfo(const std::string & seInfo)876     void SetSeInfo(const std::string &seInfo)
877     {
878         baseBundleInfo_.seInfo = seInfo;
879     }
880 
GetSeInfo()881     std::string GetSeInfo() const
882     {
883         return baseBundleInfo_.seInfo;
884     }
885 
IsOnlyModule(const std::string & modulePackage)886     bool IsOnlyModule(const std::string &modulePackage)
887     {
888         if ((innerModuleInfos_.size() == 1) && (innerModuleInfos_.count(modulePackage) == 1)) {
889             return true;
890         }
891         return false;
892     }
893 
SetProvisionId(const std::string & provisionId)894     void SetProvisionId(const std::string &provisionId)
895     {
896         baseBundleInfo_.appId = baseBundleInfo_.name + Constants::FILE_UNDERLINE + provisionId;
897     }
898 
GetProvisionId()899     std::string GetProvisionId() const
900     {
901         return baseBundleInfo_.appId;
902     }
903 
SetAppFeature(const std::string & appFeature)904     void SetAppFeature(const std::string &appFeature)
905     {
906         appFeature_ = appFeature;
907     }
908 
GetAppFeature()909     std::string GetAppFeature() const
910     {
911         return appFeature_;
912     }
913 
SetHasEntry(bool hasEntry)914     void SetHasEntry(bool hasEntry)
915     {
916         hasEntry_ = hasEntry;
917     }
918 
HasEntry()919     bool HasEntry() const
920     {
921         return hasEntry_;
922     }
923 
SetAbilityEnabled(const std::string & bundleName,const std::string & abilityName,bool isEnabled)924     bool SetAbilityEnabled(const std::string &bundleName, const std::string &abilityName, bool isEnabled)
925     {
926         for (auto &ability : baseAbilityInfos_) {
927             if ((ability.second.bundleName == bundleName) && (ability.second.name == abilityName)) {
928                 ability.second.enabled = isEnabled;
929                 return true;
930             }
931         }
932         return false;
933     }
934     /**
935      * @brief Insert formInfo.
936      * @param keyName Indicates object as key.
937      * @param formInfos Indicates the formInfo object as value.
938      */
InsertFormInfos(const std::string & keyName,const std::vector<FormInfo> & formInfos)939     void InsertFormInfos(const std::string &keyName, const std::vector<FormInfo> &formInfos)
940     {
941         formInfos_.emplace(keyName, formInfos);
942     }
943     /**
944      * @brief Insert shortcutInfos.
945      * @param keyName Indicates object as key.
946      * @param shortcutInfos Indicates the shortcutInfos object as value.
947      */
InsertShortcutInfos(const std::string & keyName,const ShortcutInfo & shortcutInfos)948     void InsertShortcutInfos(const std::string &keyName, const ShortcutInfo &shortcutInfos)
949     {
950         shortcutInfos_.emplace(keyName, shortcutInfos);
951     }
952     // use for new Info in updating progress
RestoreFromOldInfo(const InnerBundleInfo & oldInfo)953     void RestoreFromOldInfo(const InnerBundleInfo &oldInfo)
954     {
955         SetAppCodePath(oldInfo.GetAppCodePath());
956         SetBaseDataDir(oldInfo.GetBaseDataDir());
957         SetUid(oldInfo.GetUid());
958         SetGid(oldInfo.GetGid());
959     }
RestoreModuleInfo(const InnerBundleInfo & oldInfo)960     void RestoreModuleInfo(const InnerBundleInfo &oldInfo)
961     {
962         if (oldInfo.FindModule(currentPackage_)) {
963             innerModuleInfos_.at(currentPackage_).moduleDataDir = oldInfo.GetModuleDataDir(currentPackage_);
964         }
965     }
966     /**
967      * @brief Obtains configuration information about an application.
968      * @param flag Indicates the flag used to specify information contained
969      *             in the ApplicationInfo object that will be returned.
970      * @param userId Indicates the user ID.
971      * @param appInfo Indicates the obtained ApplicationInfo object.
972      */
973     void GetApplicationInfo(const ApplicationFlag flag, const int userId, ApplicationInfo &appInfo) const;
974     /**
975      * @brief Obtains configuration information about an bundle.
976      * @param flag Indicates the flag used to specify information contained in the BundleInfo that will be returned.
977      * @param bundleInfos Indicates all of the obtained BundleInfo objects.
978      */
979     void GetBundleInfo(const BundleFlag flag, BundleInfo &bundleInfo) const;
980     /**
981      * @brief Check if special metadata is in the application.
982      * @param metaData Indicates the special metaData.
983      * @param bundleInfos Returns true if the metadata in application; returns false otherwise.
984      */
985     bool CheckSpecialMetaData(const std::string &metaData) const;
986     /**
987      * @brief Obtains the FormInfo objects provided by all applications on the device.
988      * @param moduleName Indicates the module name of the application.
989      * @param formInfos List of FormInfo objects if obtained;
990      */
991     void GetFormsInfoByModule(const std::string &moduleName, std::vector<FormInfo> &formInfos) const;
992     /**
993      * @brief Obtains the FormInfo objects provided by a specified application on the device.
994      * @param formInfos List of FormInfo objects if obtained;
995      */
996     void GetFormsInfoByApp(std::vector<FormInfo> &formInfos) const;
997     /**
998      * @brief Obtains the ShortcutInfo objects provided by a specified application on the device.
999      * @param shortcutInfos List of ShortcutInfo objects if obtained.
1000      */
1001     void GetShortcutInfos(std::vector<ShortcutInfo> &shortcutInfos) const;
1002 
1003     std::optional<InnerModuleInfo> GetInnerModuleInfoByModuleName(const std::string &moduleName) const;
1004 
1005     void GetModuleNames(std::vector<std::string> &moduleNames) const;
1006 
1007 private:
1008     // using for get
1009     bool isSupportBackup_ = false;
1010     bool isKeepData_ = false;
1011     Constants::AppType appType_ = Constants::AppType::THIRD_PARTY_APP;
1012     int uid_ = Constants::INVALID_UID;
1013     int gid_ = Constants::INVALID_GID;
1014     int userId_ = Constants::DEFAULT_USERID;
1015     std::string baseDataDir_;
1016     BundleStatus bundleStatus_ = BundleStatus::ENABLED;
1017     ApplicationInfo baseApplicationInfo_;
1018     BundleInfo baseBundleInfo_;  // applicationInfo and abilityInfo empty
1019     std::string mainAbility_;
1020     std::string appFeature_;
1021     bool hasEntry_ = false;
1022     // only using for install or update progress, doesn't need to save to database
1023     std::string currentPackage_;
1024     std::string mainAbilityName_;
1025 
1026     std::map<std::string, std::vector<FormInfo>> formInfos_;
1027     std::map<std::string, AbilityInfo> baseAbilityInfos_;
1028     std::map<std::string, InnerModuleInfo> innerModuleInfos_;
1029     std::map<std::string, std::vector<Skill>> skillInfos_;
1030     std::map<std::string, ShortcutInfo> shortcutInfos_;
1031 };
1032 
1033 void from_json(const nlohmann::json &jsonObject, InnerModuleInfo &info);
1034 void from_json(const nlohmann::json &jsonObject, SkillUri &uri);
1035 void from_json(const nlohmann::json &jsonObject, Skill &skill);
1036 void from_json(const nlohmann::json &jsonObject, Distro &distro);
1037 void from_json(const nlohmann::json &jsonObject, ReqPermission &ReqPermission);
1038 void from_json(const nlohmann::json &jsonObject, DefPermission &DefPermission);
1039 }  // namespace AppExecFwk
1040 }  // namespace OHOS
1041 #endif  // FOUNDATION_APPEXECFWK_SERVICES_BUNDLEMGR_INCLUDE_INNER_BUNDLE_INFO_H
1042