• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2021-2023 Huawei Device Co., Ltd.
3  * Licensed under the Apache License, Version 2.0 (the "License");
4  * you may not use this file except in compliance with the License.
5  * You may obtain a copy of the License at
6  *
7  *     http://www.apache.org/licenses/LICENSE-2.0
8  *
9  * Unless required by applicable law or agreed to in writing, software
10  * distributed under the License is distributed on an "AS IS" BASIS,
11  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12  * See the License for the specific language governing permissions and
13  * limitations under the License.
14  */
15 
16 #include "inner_bundle_info.h"
17 
18 #include <algorithm>
19 #include <deque>
20 #include <regex>
21 #include <unistd.h>
22 #include "string_ex.h"
23 
24 #ifdef BUNDLE_FRAMEWORK_APP_CONTROL
25 #include "app_control_constants.h"
26 #include "app_control_manager.h"
27 #endif
28 #include "bundle_mgr_client.h"
29 #include "bundle_permission_mgr.h"
30 #include "common_profile.h"
31 #include "distributed_module_info.h"
32 #include "distributed_ability_info.h"
33 #include "free_install_params.h"
34 #include "mime_type_mgr.h"
35 #include "parameters.h"
36 
37 namespace OHOS {
38 namespace AppExecFwk {
39 namespace {
40 const std::string APP_TYPE = "appType";
41 const std::string UID = "uid";
42 const std::string GID = "gid";
43 const std::string BUNDLE_STATUS = "bundleStatus";
44 const std::string BASE_APPLICATION_INFO = "baseApplicationInfo";
45 const std::string BASE_BUNDLE_INFO = "baseBundleInfo";
46 const std::string BASE_ABILITY_INFO = "baseAbilityInfos";
47 const std::string INNER_MODULE_INFO = "innerModuleInfos";
48 const std::string SKILL_INFOS = "skillInfos";
49 const std::string USER_ID = "userId_";
50 const std::string APP_FEATURE = "appFeature";
51 const std::string CAN_UNINSTALL = "canUninstall";
52 const std::string NAME = "name";
53 const std::string MODULE_PACKAGE = "modulePackage";
54 const std::string MODULE_PATH = "modulePath";
55 const std::string MODULE_NAME = "moduleName";
56 const std::string MODULE_DESCRIPTION = "description";
57 const std::string MODULE_DESCRIPTION_ID = "descriptionId";
58 const std::string MODULE_ICON = "icon";
59 const std::string MODULE_ICON_ID = "iconId";
60 const std::string MODULE_LABEL = "label";
61 const std::string MODULE_LABEL_ID = "labelId";
62 const std::string MODULE_DESCRIPTION_INSTALLATION_FREE = "installationFree";
63 const std::string MODULE_IS_REMOVABLE = "isRemovable";
64 const std::string MODULE_UPGRADE_FLAG = "upgradeFlag";
65 const std::string MODULE_IS_ENTRY = "isEntry";
66 const std::string MODULE_METADATA = "metaData";
67 const std::string MODULE_COLOR_MODE = "colorMode";
68 const std::string MODULE_DISTRO = "distro";
69 const std::string MODULE_REQ_CAPABILITIES = "reqCapabilities";
70 const std::string MODULE_DATA_DIR = "moduleDataDir";
71 const std::string MODULE_RES_PATH = "moduleResPath";
72 const std::string MODULE_HAP_PATH = "hapPath";
73 const std::string MODULE_ABILITY_KEYS = "abilityKeys";
74 const std::string MODULE_SKILL_KEYS = "skillKeys";
75 const std::string MODULE_FORMS = "formInfos";
76 const std::string MODULE_SHORTCUT = "shortcutInfos";
77 const std::string MODULE_COMMON_EVENT = "commonEvents";
78 const std::string MODULE_MAIN_ABILITY = "mainAbility";
79 const std::string MODULE_ENTRY_ABILITY_KEY = "entryAbilityKey";
80 const std::string MODULE_DEPENDENCIES = "dependencies";
81 const std::string MODULE_IS_LIB_ISOLATED = "isLibIsolated";
82 const std::string MODULE_NATIVE_LIBRARY_PATH = "nativeLibraryPath";
83 const std::string MODULE_CPU_ABI = "cpuAbi";
84 const std::string NEW_BUNDLE_NAME = "newBundleName";
85 const std::string MODULE_SRC_PATH = "srcPath";
86 const std::string MODULE_HASH_VALUE = "hashValue";
87 const std::string SCHEME_SEPARATOR = "://";
88 const std::string PORT_SEPARATOR = ":";
89 const std::string PATH_SEPARATOR = "/";
90 const std::string PARAM_SEPARATOR = "?";
91 const std::string IS_PREINSTALL_APP = "isPreInstallApp";
92 const std::string INSTALL_MARK = "installMark";
93 const char WILDCARD = '*';
94 const std::string TYPE_WILDCARD = "*/*";
95 const std::string INNER_BUNDLE_USER_INFOS = "innerBundleUserInfos";
96 const std::string MODULE_PROCESS = "process";
97 const std::string MODULE_SRC_ENTRANCE = "srcEntrance";
98 const std::string MODULE_DEVICE_TYPES = "deviceTypes";
99 const std::string MODULE_VIRTUAL_MACHINE = "virtualMachine";
100 const std::string MODULE_UI_SYNTAX = "uiSyntax";
101 const std::string MODULE_PAGES = "pages";
102 const std::string MODULE_META_DATA = "metadata";
103 const std::string MODULE_REQUEST_PERMISSIONS = "requestPermissions";
104 const std::string MODULE_DEFINE_PERMISSIONS = "definePermissions";
105 const std::string MODULE_EXTENSION_KEYS = "extensionKeys";
106 const std::string MODULE_EXTENSION_SKILL_KEYS = "extensionSkillKeys";
107 const std::string MODULE_IS_MODULE_JSON = "isModuleJson";
108 const std::string MODULE_IS_STAGE_BASED_MODEL = "isStageBasedModel";
109 const std::string BUNDLE_IS_NEW_VERSION = "isNewVersion";
110 const std::string BUNDLE_IS_NEED_UPDATE = "upgradeFlag";
111 const std::string BUNDLE_BASE_EXTENSION_INFOS = "baseExtensionInfos";
112 const std::string BUNDLE_EXTENSION_SKILL_INFOS = "extensionSkillInfos";
113 const std::string BUNDLE_PACK_INFO = "bundlePackInfo";
114 const std::string ALLOWED_ACLS = "allowedAcls";
115 const std::string META_DATA_SHORTCUTS_NAME = "ohos.ability.shortcuts";
116 const std::string APP_INDEX = "appIndex";
117 const std::string BUNDLE_IS_SANDBOX_APP = "isSandboxApp";
118 const std::string BUNDLE_SANDBOX_PERSISTENT_INFO = "sandboxPersistentInfo";
119 const std::string MODULE_COMPILE_MODE = "compileMode";
120 const std::string BUNDLE_HQF_INFOS = "hqfInfos";
121 const std::string MODULE_TARGET_MODULE_NAME = "targetModuleName";
122 const std::string MODULE_TARGET_PRIORITY = "targetPriority";
123 const std::string MODULE_OVERLAY_MODULE_INFO = "overlayModuleInfo";
124 const std::string OVERLAY_BUNDLE_INFO = "overlayBundleInfo";
125 const std::string OVERLAY_TYPE = "overlayType";
126 const std::string APPLY_QUICK_FIX_FREQUENCY = "applyQuickFixFrequency";
127 const std::string MODULE_ATOMIC_SERVICE_MODULE_TYPE = "atomicServiceModuleType";
128 const std::string MODULE_PRELOADS = "preloads";
129 const std::string INNER_SHARED_MODULE_INFO = "innerSharedModuleInfos";
130 const std::string MODULE_BUNDLE_TYPE = "bundleType";
131 const std::string MODULE_VERSION_CODE = "versionCode";
132 const std::string MODULE_VERSION_NAME = "versionName";
133 const std::string MODULE_PROXY_DATAS = "proxyDatas";
134 const std::string MODULE_BUILD_HASH = "buildHash";
135 const std::string MODULE_ISOLATION_MODE = "isolationMode";
136 const std::string MODULE_COMPRESS_NATIVE_LIBS = "compressNativeLibs";
137 const std::string MODULE_NATIVE_LIBRARY_FILE_NAMES = "nativeLibraryFileNames";
138 const std::string MODULE_AOT_COMPILE_STATUS = "aotCompileStatus";
139 const std::string DATA_GROUP_INFOS = "dataGroupInfos";
140 const int32_t SINGLE_HSP_VERSION = 1;
141 const std::map<std::string, IsolationMode> ISOLATION_MODE_MAP = {
142     {"isolationOnly", IsolationMode::ISOLATION_ONLY},
143     {"nonisolationOnly", IsolationMode::NONISOLATION_ONLY},
144     {"isolationFirst", IsolationMode::ISOLATION_FIRST},
145 };
146 const std::string NATIVE_LIBRARY_PATH_SYMBOL = "!/";
147 
148 const std::string STR_PHONE = "phone";
149 const std::string STR_DEFAULT = "default";
150 
ConvertCompileMode(const std::string & compileMode)151 inline CompileMode ConvertCompileMode(const std::string& compileMode)
152 {
153     if (compileMode == Profile::COMPILE_MODE_ES_MODULE) {
154         return CompileMode::ES_MODULE;
155     } else {
156         return CompileMode::JS_BUNDLE;
157     }
158 }
159 
NameAndUserIdToKey(const std::string & bundleName,int32_t userId)160 const std::string NameAndUserIdToKey(const std::string &bundleName, int32_t userId)
161 {
162     return bundleName + Constants::FILE_UNDERLINE + std::to_string(userId);
163 }
164 }  // namespace
165 
SetAOTCompileStatus(const std::string & moduleName,AOTCompileStatus aotCompileStatus)166 void InnerBundleInfo::SetAOTCompileStatus(const std::string &moduleName, AOTCompileStatus aotCompileStatus)
167 {
168     auto item = innerModuleInfos_.find(moduleName);
169     if (item == innerModuleInfos_.end()) {
170         APP_LOGE("moduleName %{public}s not exist", moduleName.c_str());
171         return;
172     }
173     item->second.aotCompileStatus = aotCompileStatus;
174 }
175 
GetAOTCompileStatus(const std::string & moduleName) const176 AOTCompileStatus InnerBundleInfo::GetAOTCompileStatus(const std::string &moduleName) const
177 {
178     auto item = innerModuleInfos_.find(moduleName);
179     if (item == innerModuleInfos_.end()) {
180         APP_LOGE("moduleName %{public}s not exist", moduleName.c_str());
181         return AOTCompileStatus::NOT_COMPILED;
182     }
183     return item->second.aotCompileStatus;
184 }
185 
ResetAOTFlags()186 void InnerBundleInfo::ResetAOTFlags()
187 {
188     baseApplicationInfo_->arkNativeFilePath.clear();
189     baseApplicationInfo_->arkNativeFileAbi.clear();
190     std::for_each(innerModuleInfos_.begin(), innerModuleInfos_.end(), [](auto &item) {
191         item.second.aotCompileStatus = AOTCompileStatus::NOT_COMPILED;
192     });
193 }
194 
Match(const OHOS::AAFwk::Want & want) const195 bool Skill::Match(const OHOS::AAFwk::Want &want) const
196 {
197     bool matchAction = MatchAction(want.GetAction());
198     if (!matchAction) {
199         APP_LOGD("Action does not match");
200         return false;
201     }
202     bool matchEntities = MatchEntities(want.GetEntities());
203     if (!matchEntities) {
204         APP_LOGD("Entities does not match");
205         return false;
206     }
207     std::vector<std::string> vecTypes;
208     auto deviceType = OHOS::system::GetDeviceType();
209     APP_LOGD("DeviceType %{public}s", deviceType.c_str());
210     if (STR_PHONE == deviceType || STR_DEFAULT == deviceType) {
211         vecTypes = want.GetStringArrayParam(OHOS::AAFwk::Want::PARAM_ABILITY_URITYPES);
212     }
213     if (vecTypes.size() > 0) {
214         for (std::string strType : vecTypes) {
215             if (MatchUriAndType(want.GetUriString(), strType)) {
216                 APP_LOGD("type %{public}s, Is Matched", strType.c_str());
217                 return true;
218             }
219         }
220         return false;
221     }
222     bool matchUriAndType = MatchUriAndType(want.GetUriString(), want.GetType());
223     if (!matchUriAndType) {
224         APP_LOGD("Uri or Type does not match");
225         return false;
226     }
227     return true;
228 }
229 
MatchLauncher(const OHOS::AAFwk::Want & want) const230 bool Skill::MatchLauncher(const OHOS::AAFwk::Want &want) const
231 {
232     bool matchAction = MatchAction(want.GetAction());
233     if (!matchAction) {
234         APP_LOGD("Action does not match");
235         return false;
236     }
237     bool matchEntities = MatchEntities(want.GetEntities());
238     if (!matchEntities) {
239         APP_LOGD("Entities does not match");
240         return false;
241     }
242     return true;
243 }
244 
MatchAction(const std::string & action) const245 bool Skill::MatchAction(const std::string &action) const
246 {
247     // config actions empty, no match
248     if (actions.empty()) {
249         return false;
250     }
251     // config actions not empty, param empty, match
252     if (action.empty()) {
253         return true;
254     }
255     auto actionMatcher = [action] (const std::string &configAction) {
256         if (action == configAction) {
257             return true;
258         }
259         if (action == Constants::ACTION_HOME && configAction == Constants::WANT_ACTION_HOME) {
260             return true;
261         }
262         if (action == Constants::WANT_ACTION_HOME && configAction == Constants::ACTION_HOME) {
263             return true;
264         }
265         return false;
266     };
267     // config actions not empty, param not empty, if config actions contains param action, match
268     return std::find_if(actions.cbegin(), actions.cend(), actionMatcher) != actions.cend();
269 }
270 
MatchEntities(const std::vector<std::string> & paramEntities) const271 bool Skill::MatchEntities(const std::vector<std::string> &paramEntities) const
272 {
273     // param entities empty, match
274     if (paramEntities.empty()) {
275         return true;
276     }
277     // config entities empty, param entities not empty, not match
278     if (entities.empty()) {
279         return false;
280     }
281     // config entities not empty, param entities not empty, if every param entity in config entities, match
282     std::vector<std::string>::size_type size = paramEntities.size();
283     for (std::vector<std::string>::size_type i = 0; i < size; i++) {
284         bool ret = std::find(entities.cbegin(), entities.cend(), paramEntities[i]) == entities.cend();
285         if (ret) {
286             return false;
287         }
288     }
289     return true;
290 }
291 
MatchUriAndType(const std::string & uriString,const std::string & type) const292 bool Skill::MatchUriAndType(const std::string &uriString, const std::string &type) const
293 {
294     if (uriString.empty() && type.empty()) {
295         // case1 : param uri empty, param type empty
296         if (uris.empty()) {
297             return true;
298         }
299         for (const SkillUri &skillUri : uris) {
300             if (skillUri.scheme.empty() && skillUri.type.empty()) {
301                 return true;
302             }
303         }
304         return false;
305     }
306     if (uris.empty()) {
307         return false;
308     }
309     if (!uriString.empty() && type.empty()) {
310         // case2 : param uri not empty, param type empty
311         for (const SkillUri &skillUri : uris) {
312             if (MatchUri(uriString, skillUri) && skillUri.type.empty()) {
313                 return true;
314             }
315         }
316         // if uri is a file path, match type by the suffix
317         return MatchMimeType(uriString);
318     } else if (uriString.empty() && !type.empty()) {
319         // case3 : param uri empty, param type not empty
320         for (const SkillUri &skillUri : uris) {
321             if (skillUri.scheme.empty() && MatchType(type, skillUri.type)) {
322                 return true;
323             }
324         }
325         return false;
326     } else {
327         // case4 : param uri not empty, param type not empty
328         for (const SkillUri &skillUri : uris) {
329             if (MatchUri(uriString, skillUri) && MatchType(type, skillUri.type)) {
330                 return true;
331             }
332         }
333         return false;
334     }
335 }
336 
StartsWith(const std::string & sourceString,const std::string & targetPrefix) const337 bool Skill::StartsWith(const std::string &sourceString, const std::string &targetPrefix) const
338 {
339     return sourceString.rfind(targetPrefix, 0) == 0;
340 }
341 
GetOptParamUri(const std::string & uriString) const342 std::string Skill::GetOptParamUri(const std::string &uriString) const
343 {
344     std::size_t pos = uriString.rfind(PARAM_SEPARATOR);
345     if (pos == std::string::npos) {
346         return uriString;
347     }
348     return uriString.substr(0, pos);
349 }
350 
MatchUri(const std::string & uriString,const SkillUri & skillUri) const351 bool Skill::MatchUri(const std::string &uriString, const SkillUri &skillUri) const
352 {
353     if (skillUri.scheme.empty()) {
354         return uriString.empty();
355     }
356     if (skillUri.host.empty()) {
357         // config uri is : scheme
358         // belows are param uri matched conditions:
359         // 1.scheme
360         // 2.scheme:
361         // 3.scheme:/
362         // 4.scheme://
363         return uriString == skillUri.scheme || StartsWith(uriString, skillUri.scheme + PORT_SEPARATOR);
364     }
365     std::string optParamUri = GetOptParamUri(uriString);
366     std::string skillUriString;
367     skillUriString.append(skillUri.scheme).append(SCHEME_SEPARATOR).append(skillUri.host);
368     if (!skillUri.port.empty()) {
369         skillUriString.append(PORT_SEPARATOR).append(skillUri.port);
370     }
371     if (skillUri.path.empty() && skillUri.pathStartWith.empty() && skillUri.pathRegex.empty()) {
372         // with port, config uri is : scheme://host:port
373         // belows are param uri matched conditions:
374         // 1.scheme://host:port
375         // 2.scheme://host:port/path
376 
377         // without port, config uri is : scheme://host
378         // belows are param uri matched conditions:
379         // 1.scheme://host
380         // 2.scheme://host/path
381         // 3.scheme://host:port     scheme://host:port/path
382         bool ret = (optParamUri == skillUriString || StartsWith(optParamUri, skillUriString + PATH_SEPARATOR));
383         if (skillUri.port.empty()) {
384             ret = ret || StartsWith(optParamUri, skillUriString + PORT_SEPARATOR);
385         }
386         return ret;
387     }
388     skillUriString.append(PATH_SEPARATOR);
389     // if one of path, pathStartWith, pathRegex match, then match
390     if (!skillUri.path.empty()) {
391         // path match
392         std::string pathUri(skillUriString);
393         pathUri.append(skillUri.path);
394         if (optParamUri == pathUri) {
395             return true;
396         }
397     }
398     if (!skillUri.pathStartWith.empty()) {
399         // pathStartWith match
400         std::string pathStartWithUri(skillUriString);
401         pathStartWithUri.append(skillUri.pathStartWith);
402         if (StartsWith(optParamUri, pathStartWithUri)) {
403             return true;
404         }
405     }
406     if (!skillUri.pathRegex.empty()) {
407         // pathRegex match
408         std::string pathRegexUri(skillUriString);
409         pathRegexUri.append(skillUri.pathRegex);
410         try {
411             std::regex regex(pathRegexUri);
412             if (regex_match(optParamUri, regex)) {
413                 return true;
414             }
415         } catch(...) {
416             APP_LOGE("regex error");
417         }
418     }
419     return false;
420 }
421 
MatchType(const std::string & type,const std::string & skillUriType) const422 bool Skill::MatchType(const std::string &type, const std::string &skillUriType) const
423 {
424     // type is not empty
425     if (skillUriType.empty()) {
426         return false;
427     }
428     // only match */*
429     if (type == Constants::TYPE_ONLY_MATCH_WILDCARD) {
430         return skillUriType == TYPE_WILDCARD;
431     }
432     if (type == TYPE_WILDCARD || skillUriType == TYPE_WILDCARD) {
433         // param is */* or config is */*
434         return true;
435     }
436     bool paramTypeRegex = type.back() == WILDCARD;
437     if (paramTypeRegex) {
438         // param is string/*
439         std::string prefix = type.substr(0, type.length() - 1);
440         return skillUriType.find(prefix) == 0;
441     }
442     bool typeRegex = skillUriType.back() == WILDCARD;
443     if (typeRegex) {
444         // config is string/*
445         std::string prefix = skillUriType.substr(0, skillUriType.length() - 1);
446         return type.find(prefix) == 0;
447     } else {
448         return type == skillUriType;
449     }
450 }
451 
MatchMimeType(const std::string & uriString) const452 bool Skill::MatchMimeType(const std::string & uriString) const
453 {
454     std::vector<std::string> mimeTypes;
455     bool ret = MimeTypeMgr::GetMimeTypeByUri(uriString, mimeTypes);
456     if (!ret) {
457         return false;
458     }
459     for (const SkillUri &skillUri : uris) {
460         for (const auto &mimeType : mimeTypes) {
461             if ((MatchUri(uriString, skillUri) || skillUri.scheme.empty())
462                 && MatchType(mimeType, skillUri.type)) {
463                 return true;
464             }
465         }
466     }
467     return false;
468 }
469 
InnerBundleInfo()470 InnerBundleInfo::InnerBundleInfo()
471 {
472     baseApplicationInfo_ = std::make_shared<ApplicationInfo>();
473     if (baseApplicationInfo_ == nullptr) {
474         APP_LOGE("baseApplicationInfo_ is nullptr, create failed");
475     }
476     baseBundleInfo_ = std::make_shared<BundleInfo>();
477     if (baseBundleInfo_ == nullptr) {
478         APP_LOGE("baseBundleInfo_ is nullptr, create failed");
479     }
480     bundlePackInfo_ = std::make_shared<BundlePackInfo>();
481     if (bundlePackInfo_ == nullptr) {
482         APP_LOGE("bundlePackInfo_ is nullptr, create failed");
483     }
484     APP_LOGD("inner bundle info instance is created");
485 }
486 
operator =(const InnerBundleInfo & info)487 InnerBundleInfo &InnerBundleInfo::operator=(const InnerBundleInfo &info)
488 {
489     if (this == &info) {
490         return *this;
491     }
492     this->appType_ = info.appType_;
493     this->uid_ = info.uid_;
494     this->gid_ = info.gid_;
495     this->userId_ = info.userId_;
496     this->bundleStatus_ = info.bundleStatus_;
497     this->appFeature_ = info.appFeature_;
498     this->allowedAcls_ = info.allowedAcls_;
499     this->mark_ = info.mark_;
500     this->appIndex_ = info.appIndex_;
501     this->isSandboxApp_ = info.isSandboxApp_;
502     this->currentPackage_ = info.currentPackage_;
503     this->onlyCreateBundleUser_ = info.onlyCreateBundleUser_;
504     this->innerModuleInfos_ = info.innerModuleInfos_;
505     this->innerSharedModuleInfos_ = info.innerSharedModuleInfos_;
506     this->formInfos_ = info.formInfos_;
507     this->commonEvents_ = info.commonEvents_;
508     this->shortcutInfos_ = info.shortcutInfos_;
509     this->baseAbilityInfos_ = info.baseAbilityInfos_;
510     this->skillInfos_ = info.skillInfos_;
511     this->innerBundleUserInfos_ = info.innerBundleUserInfos_;
512     this->bundlePackInfo_ = std::make_shared<BundlePackInfo>();
513     if (info.bundlePackInfo_ != nullptr) {
514         *(this->bundlePackInfo_) = *(info.bundlePackInfo_);
515     }
516     this->isNewVersion_ = info.isNewVersion_;
517     this->baseExtensionInfos_= info.baseExtensionInfos_;
518     this->extensionSkillInfos_ = info.extensionSkillInfos_;
519     this->baseApplicationInfo_ = std::make_shared<ApplicationInfo>();
520     if (info.baseApplicationInfo_ != nullptr) {
521         *(this->baseApplicationInfo_) = *(info.baseApplicationInfo_);
522     }
523     this->baseBundleInfo_ = std::make_shared<BundleInfo>();
524     if (info.baseBundleInfo_ != nullptr) {
525         *(this->baseBundleInfo_) = *(info.baseBundleInfo_);
526     }
527     this->hqfInfos_ = info.hqfInfos_;
528     this->overlayBundleInfo_ = info.overlayBundleInfo_;
529     this->overlayType_ = info.overlayType_;
530     this->applyQuickFixFrequency_ = info.applyQuickFixFrequency_;
531     this->provisionMetadatas_ = info.provisionMetadatas_;
532     this->dataGroupInfos_ = info.dataGroupInfos_;
533     return *this;
534 }
535 
~InnerBundleInfo()536 InnerBundleInfo::~InnerBundleInfo()
537 {
538     APP_LOGD("inner bundle info instance is destroyed");
539 }
540 
to_json(nlohmann::json & jsonObject,const Distro & distro)541 void to_json(nlohmann::json &jsonObject, const Distro &distro)
542 {
543     jsonObject = nlohmann::json {
544             {ProfileReader::BUNDLE_MODULE_PROFILE_KEY_DELIVERY_WITH_INSTALL, distro.deliveryWithInstall},
545             {ProfileReader::BUNDLE_MODULE_PROFILE_KEY_MODULE_NAME, distro.moduleName},
546             {ProfileReader::BUNDLE_MODULE_PROFILE_KEY_MODULE_TYPE, distro.moduleType},
547             {ProfileReader::BUNDLE_MODULE_PROFILE_KEY_MODULE_INSTALLATION_FREE, distro.installationFree}
548     };
549 }
550 
to_json(nlohmann::json & jsonObject,const DefinePermission & definePermission)551 void to_json(nlohmann::json &jsonObject, const DefinePermission &definePermission)
552 {
553     jsonObject = nlohmann::json {
554         {Profile::DEFINEPERMISSION_NAME, definePermission.name},
555         {Profile::DEFINEPERMISSION_GRANT_MODE, definePermission.grantMode},
556         {Profile::DEFINEPERMISSION_AVAILABLE_LEVEL, definePermission.availableLevel},
557         {Profile::DEFINEPERMISSION_PROVISION_ENABLE, definePermission.provisionEnable},
558         {Profile::DEFINEPERMISSION_DISTRIBUTED_SCENE_ENABLE, definePermission.distributedSceneEnable},
559         {Profile::LABEL, definePermission.label},
560         {Profile::LABEL_ID, definePermission.labelId},
561         {Profile::DESCRIPTION, definePermission.description},
562         {Profile::DESCRIPTION_ID, definePermission.descriptionId}
563     };
564 }
565 
to_json(nlohmann::json & jsonObject,const Dependency & dependency)566 void to_json(nlohmann::json &jsonObject, const Dependency &dependency)
567 {
568     jsonObject = nlohmann::json {
569         {Profile::DEPENDENCIES_MODULE_NAME, dependency.moduleName},
570         {Profile::DEPENDENCIES_BUNDLE_NAME, dependency.bundleName},
571         {Profile::APP_VERSION_CODE, dependency.versionCode}
572     };
573 }
574 
to_json(nlohmann::json & jsonObject,const InnerModuleInfo & info)575 void to_json(nlohmann::json &jsonObject, const InnerModuleInfo &info)
576 {
577     jsonObject = nlohmann::json {
578         {NAME, info.name},
579         {MODULE_PACKAGE, info.modulePackage},
580         {MODULE_NAME, info.moduleName},
581         {MODULE_PATH, info.modulePath},
582         {MODULE_DATA_DIR, info.moduleDataDir},
583         {MODULE_RES_PATH, info.moduleResPath},
584         {MODULE_IS_ENTRY, info.isEntry},
585         {MODULE_METADATA, info.metaData},
586         {MODULE_COLOR_MODE, info.colorMode},
587         {MODULE_DISTRO, info.distro},
588         {MODULE_DESCRIPTION, info.description},
589         {MODULE_DESCRIPTION_ID, info.descriptionId},
590         {MODULE_ICON, info.icon},
591         {MODULE_ICON_ID, info.iconId},
592         {MODULE_LABEL, info.label},
593         {MODULE_LABEL_ID, info.labelId},
594         {MODULE_DESCRIPTION_INSTALLATION_FREE, info.installationFree},
595         {MODULE_IS_REMOVABLE, info.isRemovable},
596         {MODULE_UPGRADE_FLAG, info.upgradeFlag},
597         {MODULE_REQ_CAPABILITIES, info.reqCapabilities},
598         {MODULE_ABILITY_KEYS, info.abilityKeys},
599         {MODULE_SKILL_KEYS, info.skillKeys},
600         {MODULE_MAIN_ABILITY, info.mainAbility},
601         {MODULE_ENTRY_ABILITY_KEY, info.entryAbilityKey},
602         {MODULE_SRC_PATH, info.srcPath},
603         {MODULE_HASH_VALUE, info.hashValue},
604         {MODULE_PROCESS, info.process},
605         {MODULE_SRC_ENTRANCE, info.srcEntrance},
606         {MODULE_DEVICE_TYPES, info.deviceTypes},
607         {MODULE_VIRTUAL_MACHINE, info.virtualMachine},
608         {MODULE_UI_SYNTAX, info.uiSyntax},
609         {MODULE_PAGES, info.pages},
610         {MODULE_META_DATA, info.metadata},
611         {MODULE_REQUEST_PERMISSIONS, info.requestPermissions},
612         {MODULE_DEFINE_PERMISSIONS, info.definePermissions},
613         {MODULE_EXTENSION_KEYS, info.extensionKeys},
614         {MODULE_EXTENSION_SKILL_KEYS, info.extensionSkillKeys},
615         {MODULE_IS_MODULE_JSON, info.isModuleJson},
616         {MODULE_IS_STAGE_BASED_MODEL, info.isStageBasedModel},
617         {MODULE_DEPENDENCIES, info.dependencies},
618         {MODULE_IS_LIB_ISOLATED, info.isLibIsolated},
619         {MODULE_NATIVE_LIBRARY_PATH, info.nativeLibraryPath},
620         {MODULE_CPU_ABI, info.cpuAbi},
621         {MODULE_HAP_PATH, info.hapPath},
622         {MODULE_COMPILE_MODE, info.compileMode},
623         {MODULE_TARGET_MODULE_NAME, info.targetModuleName},
624         {MODULE_TARGET_PRIORITY, info.targetPriority},
625         {MODULE_OVERLAY_MODULE_INFO, info.overlayModuleInfo},
626         {MODULE_ATOMIC_SERVICE_MODULE_TYPE, info.atomicServiceModuleType},
627         {MODULE_PRELOADS, info.preloads},
628         {MODULE_BUNDLE_TYPE, info.bundleType},
629         {MODULE_VERSION_CODE, info.versionCode},
630         {MODULE_VERSION_NAME, info.versionName},
631         {MODULE_PROXY_DATAS, info.proxyDatas},
632         {MODULE_BUILD_HASH, info.buildHash},
633         {MODULE_ISOLATION_MODE, info.isolationMode},
634         {MODULE_COMPRESS_NATIVE_LIBS, info.compressNativeLibs},
635         {MODULE_NATIVE_LIBRARY_FILE_NAMES, info.nativeLibraryFileNames},
636         {MODULE_AOT_COMPILE_STATUS, info.aotCompileStatus},
637     };
638 }
639 
to_json(nlohmann::json & jsonObject,const SkillUri & uri)640 void to_json(nlohmann::json &jsonObject, const SkillUri &uri)
641 {
642     jsonObject = nlohmann::json {
643         {ProfileReader::BUNDLE_MODULE_PROFILE_KEY_SCHEME, uri.scheme},
644         {ProfileReader::BUNDLE_MODULE_PROFILE_KEY_HOST, uri.host},
645         {ProfileReader::BUNDLE_MODULE_PROFILE_KEY_PORT, uri.port},
646         {ProfileReader::BUNDLE_MODULE_PROFILE_KEY_PATH, uri.path},
647         {ProfileReader::BUNDLE_MODULE_PROFILE_KEY_PATHSTARTWITH, uri.pathStartWith},
648         {ProfileReader::BUNDLE_MODULE_PROFILE_KEY_PATHREGEX, uri.pathRegex},
649         {ProfileReader::BUNDLE_MODULE_PROFILE_KEY_TYPE, uri.type}
650     };
651 }
652 
to_json(nlohmann::json & jsonObject,const Skill & skill)653 void to_json(nlohmann::json &jsonObject, const Skill &skill)
654 {
655     jsonObject = nlohmann::json {
656         {ProfileReader::BUNDLE_MODULE_PROFILE_KEY_ACTIONS, skill.actions},
657         {ProfileReader::BUNDLE_MODULE_PROFILE_KEY_ENTITIES, skill.entities},
658         {ProfileReader::BUNDLE_MODULE_PROFILE_KEY_URIS, skill.uris}
659     };
660 }
661 
to_json(nlohmann::json & jsonObject,const InstallMark & installMark)662 void to_json(nlohmann::json &jsonObject, const InstallMark &installMark)
663 {
664     jsonObject = nlohmann::json {
665         {ProfileReader::BUNDLE_INSTALL_MARK_BUNDLE, installMark.bundleName},
666         {ProfileReader::BUNDLE_INSTALL_MARK_PACKAGE, installMark.packageName},
667         {ProfileReader::BUNDLE_INSTALL_MARK_STATUS, installMark.status}
668     };
669 }
670 
ToJson(nlohmann::json & jsonObject) const671 void InnerBundleInfo::ToJson(nlohmann::json &jsonObject) const
672 {
673     jsonObject[APP_TYPE] = appType_;
674     jsonObject[BUNDLE_STATUS] = bundleStatus_;
675     jsonObject[ALLOWED_ACLS] = allowedAcls_;
676     jsonObject[BASE_APPLICATION_INFO] = *baseApplicationInfo_;
677     jsonObject[BASE_BUNDLE_INFO] = *baseBundleInfo_;
678     jsonObject[BASE_ABILITY_INFO] = baseAbilityInfos_;
679     jsonObject[INNER_MODULE_INFO] = innerModuleInfos_;
680     jsonObject[INNER_SHARED_MODULE_INFO] = innerSharedModuleInfos_;
681     jsonObject[SKILL_INFOS] = skillInfos_;
682     jsonObject[USER_ID] = userId_;
683     jsonObject[APP_FEATURE] = appFeature_;
684     jsonObject[MODULE_FORMS] = formInfos_;
685     jsonObject[MODULE_SHORTCUT] = shortcutInfos_;
686     jsonObject[MODULE_COMMON_EVENT] = commonEvents_;
687     jsonObject[INSTALL_MARK] = mark_;
688     jsonObject[INNER_BUNDLE_USER_INFOS] = innerBundleUserInfos_;
689     jsonObject[BUNDLE_IS_NEW_VERSION] = isNewVersion_;
690     jsonObject[BUNDLE_BASE_EXTENSION_INFOS] = baseExtensionInfos_;
691     jsonObject[BUNDLE_EXTENSION_SKILL_INFOS] = extensionSkillInfos_;
692     jsonObject[BUNDLE_PACK_INFO] = *bundlePackInfo_;
693     jsonObject[APP_INDEX] = appIndex_;
694     jsonObject[BUNDLE_IS_SANDBOX_APP] = isSandboxApp_;
695     jsonObject[BUNDLE_HQF_INFOS] = hqfInfos_;
696     jsonObject[OVERLAY_BUNDLE_INFO] = overlayBundleInfo_;
697     jsonObject[OVERLAY_TYPE] = overlayType_;
698     jsonObject[APPLY_QUICK_FIX_FREQUENCY] = applyQuickFixFrequency_;
699     jsonObject[DATA_GROUP_INFOS] = dataGroupInfos_;
700 }
701 
from_json(const nlohmann::json & jsonObject,InnerModuleInfo & info)702 void from_json(const nlohmann::json &jsonObject, InnerModuleInfo &info)
703 {
704     // these are not required fields.
705     const auto &jsonObjectEnd = jsonObject.end();
706     int32_t parseResult = ERR_OK;
707     GetValueIfFindKey<std::string>(jsonObject,
708         jsonObjectEnd,
709         NAME,
710         info.name,
711         JsonType::STRING,
712         false,
713         parseResult,
714         ArrayType::NOT_ARRAY);
715     GetValueIfFindKey<std::string>(jsonObject,
716         jsonObjectEnd,
717         MODULE_PACKAGE,
718         info.modulePackage,
719         JsonType::STRING,
720         false,
721         parseResult,
722         ArrayType::NOT_ARRAY);
723     GetValueIfFindKey<std::string>(jsonObject,
724         jsonObjectEnd,
725         MODULE_NAME,
726         info.moduleName,
727         JsonType::STRING,
728         false,
729         parseResult,
730         ArrayType::NOT_ARRAY);
731     GetValueIfFindKey<std::string>(jsonObject,
732         jsonObjectEnd,
733         MODULE_PATH,
734         info.modulePath,
735         JsonType::STRING,
736         false,
737         parseResult,
738         ArrayType::NOT_ARRAY);
739     GetValueIfFindKey<std::string>(jsonObject,
740         jsonObjectEnd,
741         MODULE_DATA_DIR,
742         info.moduleDataDir,
743         JsonType::STRING,
744         false,
745         parseResult,
746         ArrayType::NOT_ARRAY);
747     GetValueIfFindKey<std::string>(jsonObject,
748         jsonObjectEnd,
749         MODULE_HAP_PATH,
750         info.hapPath,
751         JsonType::STRING,
752         false,
753         parseResult,
754         ArrayType::NOT_ARRAY);
755     GetValueIfFindKey<std::string>(jsonObject,
756         jsonObjectEnd,
757         MODULE_RES_PATH,
758         info.moduleResPath,
759         JsonType::STRING,
760         false,
761         parseResult,
762         ArrayType::NOT_ARRAY);
763     GetValueIfFindKey<bool>(jsonObject,
764         jsonObjectEnd,
765         MODULE_IS_ENTRY,
766         info.isEntry,
767         JsonType::BOOLEAN,
768         false,
769         parseResult,
770         ArrayType::NOT_ARRAY);
771     GetValueIfFindKey<MetaData>(jsonObject,
772         jsonObjectEnd,
773         MODULE_METADATA,
774         info.metaData,
775         JsonType::OBJECT,
776         false,
777         parseResult,
778         ArrayType::NOT_ARRAY);
779     GetValueIfFindKey<ModuleColorMode>(jsonObject,
780         jsonObjectEnd,
781         MODULE_COLOR_MODE,
782         info.colorMode,
783         JsonType::NUMBER,
784         false,
785         parseResult,
786         ArrayType::NOT_ARRAY);
787     GetValueIfFindKey<Distro>(jsonObject,
788         jsonObjectEnd,
789         MODULE_DISTRO,
790         info.distro,
791         JsonType::OBJECT,
792         false,
793         parseResult,
794         ArrayType::NOT_ARRAY);
795     GetValueIfFindKey<std::string>(jsonObject,
796         jsonObjectEnd,
797         MODULE_DESCRIPTION,
798         info.description,
799         JsonType::STRING,
800         false,
801         parseResult,
802         ArrayType::NOT_ARRAY);
803     GetValueIfFindKey<int32_t>(jsonObject,
804         jsonObjectEnd,
805         MODULE_DESCRIPTION_ID,
806         info.descriptionId,
807         JsonType::NUMBER,
808         false,
809         parseResult,
810         ArrayType::NOT_ARRAY);
811     GetValueIfFindKey<std::string>(jsonObject,
812         jsonObjectEnd,
813         MODULE_ICON,
814         info.icon,
815         JsonType::STRING,
816         false,
817         parseResult,
818         ArrayType::NOT_ARRAY);
819     GetValueIfFindKey<int32_t>(jsonObject,
820         jsonObjectEnd,
821         MODULE_ICON_ID,
822         info.iconId,
823         JsonType::NUMBER,
824         false,
825         parseResult,
826         ArrayType::NOT_ARRAY);
827     GetValueIfFindKey<std::string>(jsonObject,
828         jsonObjectEnd,
829         MODULE_LABEL,
830         info.label,
831         JsonType::STRING,
832         false,
833         parseResult,
834         ArrayType::NOT_ARRAY);
835     GetValueIfFindKey<int32_t>(jsonObject,
836         jsonObjectEnd,
837         MODULE_LABEL_ID,
838         info.labelId,
839         JsonType::NUMBER,
840         false,
841         parseResult,
842         ArrayType::NOT_ARRAY);
843     GetValueIfFindKey<std::string>(jsonObject,
844         jsonObjectEnd,
845         MODULE_MAIN_ABILITY,
846         info.mainAbility,
847         JsonType::STRING,
848         false,
849         parseResult,
850         ArrayType::NOT_ARRAY);
851     GetValueIfFindKey<std::string>(jsonObject,
852         jsonObjectEnd,
853         MODULE_ENTRY_ABILITY_KEY,
854         info.entryAbilityKey,
855         JsonType::STRING,
856         false,
857         parseResult,
858         ArrayType::NOT_ARRAY);
859     GetValueIfFindKey<std::string>(jsonObject,
860         jsonObjectEnd,
861         MODULE_SRC_PATH,
862         info.srcPath,
863         JsonType::STRING,
864         false,
865         parseResult,
866         ArrayType::NOT_ARRAY);
867     GetValueIfFindKey<std::string>(jsonObject,
868         jsonObjectEnd,
869         MODULE_HASH_VALUE,
870         info.hashValue,
871         JsonType::STRING,
872         false,
873         parseResult,
874         ArrayType::NOT_ARRAY);
875     GetValueIfFindKey<bool>(jsonObject,
876         jsonObjectEnd,
877         MODULE_DESCRIPTION_INSTALLATION_FREE,
878         info.installationFree,
879         JsonType::BOOLEAN,
880         false,
881         parseResult,
882         ArrayType::NOT_ARRAY);
883     GetValueIfFindKey<std::map<std::string, bool>>(jsonObject,
884         jsonObjectEnd,
885         MODULE_IS_REMOVABLE,
886         info.isRemovable,
887         JsonType::OBJECT,
888         false,
889         parseResult,
890         ArrayType::NOT_ARRAY);
891     GetValueIfFindKey<int32_t>(jsonObject,
892         jsonObjectEnd,
893         MODULE_UPGRADE_FLAG,
894         info.upgradeFlag,
895         JsonType::NUMBER,
896         false,
897         parseResult,
898         ArrayType::NOT_ARRAY);
899     GetValueIfFindKey<std::vector<std::string>>(jsonObject,
900         jsonObjectEnd,
901         MODULE_REQ_CAPABILITIES,
902         info.reqCapabilities,
903         JsonType::ARRAY,
904         false,
905         parseResult,
906         ArrayType::STRING);
907     GetValueIfFindKey<std::vector<std::string>>(jsonObject,
908         jsonObjectEnd,
909         MODULE_ABILITY_KEYS,
910         info.abilityKeys,
911         JsonType::ARRAY,
912         false,
913         parseResult,
914         ArrayType::STRING);
915     GetValueIfFindKey<std::vector<std::string>>(jsonObject,
916         jsonObjectEnd,
917         MODULE_SKILL_KEYS,
918         info.skillKeys,
919         JsonType::ARRAY,
920         false,
921         parseResult,
922         ArrayType::STRING);
923     GetValueIfFindKey<std::string>(jsonObject,
924         jsonObjectEnd,
925         MODULE_PROCESS,
926         info.process,
927         JsonType::STRING,
928         false,
929         parseResult,
930         ArrayType::NOT_ARRAY);
931     GetValueIfFindKey<std::string>(jsonObject,
932         jsonObjectEnd,
933         MODULE_SRC_ENTRANCE,
934         info.srcEntrance,
935         JsonType::STRING,
936         false,
937         parseResult,
938         ArrayType::NOT_ARRAY);
939     GetValueIfFindKey<std::vector<std::string>>(jsonObject,
940         jsonObjectEnd,
941         MODULE_DEVICE_TYPES,
942         info.deviceTypes,
943         JsonType::ARRAY,
944         false,
945         parseResult,
946         ArrayType::STRING);
947     GetValueIfFindKey<std::string>(jsonObject,
948         jsonObjectEnd,
949         MODULE_VIRTUAL_MACHINE,
950         info.virtualMachine,
951         JsonType::STRING,
952         false,
953         parseResult,
954         ArrayType::NOT_ARRAY);
955     GetValueIfFindKey<std::string>(jsonObject,
956         jsonObjectEnd,
957         MODULE_UI_SYNTAX,
958         info.uiSyntax,
959         JsonType::STRING,
960         false,
961         parseResult,
962         ArrayType::NOT_ARRAY);
963     GetValueIfFindKey<std::string>(jsonObject,
964         jsonObjectEnd,
965         MODULE_PAGES,
966         info.pages,
967         JsonType::STRING,
968         false,
969         parseResult,
970         ArrayType::NOT_ARRAY);
971     GetValueIfFindKey<std::vector<Metadata>>(jsonObject,
972         jsonObjectEnd,
973         MODULE_META_DATA,
974         info.metadata,
975         JsonType::ARRAY,
976         false,
977         parseResult,
978         ArrayType::OBJECT);
979     GetValueIfFindKey<std::vector<RequestPermission>>(jsonObject,
980         jsonObjectEnd,
981         MODULE_REQUEST_PERMISSIONS,
982         info.requestPermissions,
983         JsonType::ARRAY,
984         false,
985         parseResult,
986         ArrayType::OBJECT);
987     GetValueIfFindKey<std::vector<DefinePermission>>(jsonObject,
988         jsonObjectEnd,
989         MODULE_DEFINE_PERMISSIONS,
990         info.definePermissions,
991         JsonType::ARRAY,
992         false,
993         parseResult,
994         ArrayType::OBJECT);
995     GetValueIfFindKey<std::vector<std::string>>(jsonObject,
996         jsonObjectEnd,
997         MODULE_EXTENSION_KEYS,
998         info.extensionKeys,
999         JsonType::ARRAY,
1000         false,
1001         parseResult,
1002         ArrayType::STRING);
1003     GetValueIfFindKey<std::vector<std::string>>(jsonObject,
1004         jsonObjectEnd,
1005         MODULE_EXTENSION_SKILL_KEYS,
1006         info.extensionSkillKeys,
1007         JsonType::ARRAY,
1008         false,
1009         parseResult,
1010         ArrayType::STRING);
1011     GetValueIfFindKey<bool>(jsonObject,
1012         jsonObjectEnd,
1013         MODULE_IS_MODULE_JSON,
1014         info.isModuleJson,
1015         JsonType::BOOLEAN,
1016         false,
1017         parseResult,
1018         ArrayType::NOT_ARRAY);
1019     GetValueIfFindKey<bool>(jsonObject,
1020         jsonObjectEnd,
1021         MODULE_IS_STAGE_BASED_MODEL,
1022         info.isStageBasedModel,
1023         JsonType::BOOLEAN,
1024         false,
1025         parseResult,
1026         ArrayType::NOT_ARRAY);
1027     GetValueIfFindKey<std::vector<Dependency>>(jsonObject,
1028         jsonObjectEnd,
1029         MODULE_DEPENDENCIES,
1030         info.dependencies,
1031         JsonType::ARRAY,
1032         false,
1033         parseResult,
1034         ArrayType::OBJECT);
1035     GetValueIfFindKey<std::string>(jsonObject,
1036         jsonObjectEnd,
1037         MODULE_COMPILE_MODE,
1038         info.compileMode,
1039         JsonType::STRING,
1040         false,
1041         parseResult,
1042         ArrayType::NOT_ARRAY);
1043     GetValueIfFindKey<bool>(jsonObject,
1044         jsonObjectEnd,
1045         MODULE_IS_LIB_ISOLATED,
1046         info.isLibIsolated,
1047         JsonType::BOOLEAN,
1048         false,
1049         parseResult,
1050         ArrayType::NOT_ARRAY);
1051     GetValueIfFindKey<std::string>(jsonObject,
1052         jsonObjectEnd,
1053         MODULE_NATIVE_LIBRARY_PATH,
1054         info.nativeLibraryPath,
1055         JsonType::STRING,
1056         false,
1057         parseResult,
1058         ArrayType::NOT_ARRAY);
1059     GetValueIfFindKey<std::string>(jsonObject,
1060         jsonObjectEnd,
1061         MODULE_CPU_ABI,
1062         info.cpuAbi,
1063         JsonType::STRING,
1064         false,
1065         parseResult,
1066         ArrayType::NOT_ARRAY);
1067     GetValueIfFindKey<std::string>(jsonObject,
1068         jsonObjectEnd,
1069         MODULE_TARGET_MODULE_NAME,
1070         info.targetModuleName,
1071         JsonType::STRING,
1072         false,
1073         parseResult,
1074         ArrayType::NOT_ARRAY);
1075     GetValueIfFindKey<int32_t>(jsonObject,
1076         jsonObjectEnd,
1077         MODULE_TARGET_PRIORITY,
1078         info.targetPriority,
1079         JsonType::NUMBER,
1080         false,
1081         parseResult,
1082         ArrayType::NOT_ARRAY);
1083     GetValueIfFindKey<std::vector<OverlayModuleInfo>>(jsonObject,
1084         jsonObjectEnd,
1085         MODULE_OVERLAY_MODULE_INFO,
1086         info.overlayModuleInfo,
1087         JsonType::ARRAY,
1088         false,
1089         parseResult,
1090         ArrayType::OBJECT);
1091     GetValueIfFindKey<AtomicServiceModuleType>(jsonObject,
1092         jsonObjectEnd,
1093         MODULE_ATOMIC_SERVICE_MODULE_TYPE,
1094         info.atomicServiceModuleType,
1095         JsonType::NUMBER,
1096         false,
1097         parseResult,
1098         ArrayType::NOT_ARRAY);
1099     GetValueIfFindKey<std::vector<std::string>>(jsonObject,
1100         jsonObjectEnd,
1101         MODULE_PRELOADS,
1102         info.preloads,
1103         JsonType::ARRAY,
1104         false,
1105         parseResult,
1106         ArrayType::STRING);
1107     GetValueIfFindKey<BundleType>(jsonObject,
1108         jsonObjectEnd,
1109         MODULE_BUNDLE_TYPE,
1110         info.bundleType,
1111         JsonType::NUMBER,
1112         false,
1113         parseResult,
1114         ArrayType::NOT_ARRAY);
1115     GetValueIfFindKey<uint32_t>(jsonObject,
1116         jsonObjectEnd,
1117         MODULE_VERSION_CODE,
1118         info.versionCode,
1119         JsonType::NUMBER,
1120         false,
1121         parseResult,
1122         ArrayType::NOT_ARRAY);
1123     GetValueIfFindKey<std::string>(jsonObject,
1124         jsonObjectEnd,
1125         MODULE_VERSION_NAME,
1126         info.versionName,
1127         JsonType::STRING,
1128         false,
1129         parseResult,
1130         ArrayType::NOT_ARRAY);
1131     GetValueIfFindKey<std::vector<ProxyData>>(jsonObject,
1132         jsonObjectEnd,
1133         MODULE_PROXY_DATAS,
1134         info.proxyDatas,
1135         JsonType::ARRAY,
1136         false,
1137         parseResult,
1138         ArrayType::OBJECT);
1139     GetValueIfFindKey<std::string>(jsonObject,
1140         jsonObjectEnd,
1141         MODULE_BUILD_HASH,
1142         info.buildHash,
1143         JsonType::STRING,
1144         false,
1145         parseResult,
1146         ArrayType::NOT_ARRAY);
1147     GetValueIfFindKey<std::string>(jsonObject,
1148         jsonObjectEnd,
1149         MODULE_ISOLATION_MODE,
1150         info.isolationMode,
1151         JsonType::STRING,
1152         false,
1153         parseResult,
1154         ArrayType::NOT_ARRAY);
1155     GetValueIfFindKey<bool>(jsonObject,
1156         jsonObjectEnd,
1157         MODULE_COMPRESS_NATIVE_LIBS,
1158         info.compressNativeLibs,
1159         JsonType::BOOLEAN,
1160         false,
1161         parseResult,
1162         ArrayType::NOT_ARRAY);
1163     GetValueIfFindKey<std::vector<std::string>>(jsonObject,
1164         jsonObjectEnd,
1165         MODULE_NATIVE_LIBRARY_FILE_NAMES,
1166         info.nativeLibraryFileNames,
1167         JsonType::ARRAY,
1168         false,
1169         parseResult,
1170         ArrayType::STRING);
1171     GetValueIfFindKey<AOTCompileStatus>(jsonObject,
1172         jsonObjectEnd,
1173         MODULE_AOT_COMPILE_STATUS,
1174         info.aotCompileStatus,
1175         JsonType::NUMBER,
1176         false,
1177         parseResult,
1178         ArrayType::NOT_ARRAY);
1179     if (parseResult != ERR_OK) {
1180         APP_LOGE("read InnerModuleInfo from database error, error code : %{public}d", parseResult);
1181     }
1182 }
1183 
from_json(const nlohmann::json & jsonObject,SkillUri & uri)1184 void from_json(const nlohmann::json &jsonObject, SkillUri &uri)
1185 {
1186     // these are required fields.
1187     const auto &jsonObjectEnd = jsonObject.end();
1188     int32_t parseResult = ERR_OK;
1189     GetValueIfFindKey<std::string>(jsonObject,
1190         jsonObjectEnd,
1191         ProfileReader::BUNDLE_MODULE_PROFILE_KEY_SCHEME,
1192         uri.scheme,
1193         JsonType::STRING,
1194         false,
1195         parseResult,
1196         ArrayType::NOT_ARRAY);
1197     // these are not required fields.
1198     GetValueIfFindKey<std::string>(jsonObject,
1199         jsonObjectEnd,
1200         ProfileReader::BUNDLE_MODULE_PROFILE_KEY_HOST,
1201         uri.host,
1202         JsonType::STRING,
1203         false,
1204         parseResult,
1205         ArrayType::NOT_ARRAY);
1206     GetValueIfFindKey<std::string>(jsonObject,
1207         jsonObjectEnd,
1208         ProfileReader::BUNDLE_MODULE_PROFILE_KEY_PORT,
1209         uri.port,
1210         JsonType::STRING,
1211         false,
1212         parseResult,
1213         ArrayType::NOT_ARRAY);
1214     GetValueIfFindKey<std::string>(jsonObject,
1215         jsonObjectEnd,
1216         ProfileReader::BUNDLE_MODULE_PROFILE_KEY_PATH,
1217         uri.path,
1218         JsonType::STRING,
1219         false,
1220         parseResult,
1221         ArrayType::NOT_ARRAY);
1222     GetValueIfFindKey<std::string>(jsonObject,
1223         jsonObjectEnd,
1224         ProfileReader::BUNDLE_MODULE_PROFILE_KEY_PATHSTARTWITH,
1225         uri.pathStartWith,
1226         JsonType::STRING,
1227         false,
1228         parseResult,
1229         ArrayType::NOT_ARRAY);
1230     GetValueIfFindKey<std::string>(jsonObject,
1231         jsonObjectEnd,
1232         ProfileReader::BUNDLE_MODULE_PROFILE_KEY_PATHREGX,
1233         uri.pathRegex,
1234         JsonType::STRING,
1235         false,
1236         parseResult,
1237         ArrayType::NOT_ARRAY);
1238     GetValueIfFindKey<std::string>(jsonObject,
1239         jsonObjectEnd,
1240         ProfileReader::BUNDLE_MODULE_PROFILE_KEY_PATHREGEX,
1241         uri.pathRegex,
1242         JsonType::STRING,
1243         false,
1244         parseResult,
1245         ArrayType::NOT_ARRAY);
1246     GetValueIfFindKey<std::string>(jsonObject,
1247         jsonObjectEnd,
1248         ProfileReader::BUNDLE_MODULE_PROFILE_KEY_TYPE,
1249         uri.type,
1250         JsonType::STRING,
1251         false,
1252         parseResult,
1253         ArrayType::NOT_ARRAY);
1254     if (parseResult != ERR_OK) {
1255         APP_LOGE("SkillUri from_json error, error code : %{public}d", parseResult);
1256     }
1257 }
1258 
from_json(const nlohmann::json & jsonObject,Skill & skill)1259 void from_json(const nlohmann::json &jsonObject, Skill &skill)
1260 {
1261     // these are not required fields.
1262     const auto &jsonObjectEnd = jsonObject.end();
1263     int32_t parseResult = ERR_OK;
1264     GetValueIfFindKey<std::vector<std::string>>(jsonObject,
1265         jsonObjectEnd,
1266         ProfileReader::BUNDLE_MODULE_PROFILE_KEY_ACTIONS,
1267         skill.actions,
1268         JsonType::ARRAY,
1269         false,
1270         parseResult,
1271         ArrayType::STRING);
1272     GetValueIfFindKey<std::vector<std::string>>(jsonObject,
1273         jsonObjectEnd,
1274         ProfileReader::BUNDLE_MODULE_PROFILE_KEY_ENTITIES,
1275         skill.entities,
1276         JsonType::ARRAY,
1277         false,
1278         parseResult,
1279         ArrayType::STRING);
1280     GetValueIfFindKey<std::vector<SkillUri>>(jsonObject,
1281         jsonObjectEnd,
1282         ProfileReader::BUNDLE_MODULE_PROFILE_KEY_URIS,
1283         skill.uris,
1284         JsonType::ARRAY,
1285         false,
1286         parseResult,
1287         ArrayType::OBJECT);
1288     if (parseResult != ERR_OK) {
1289         APP_LOGE("Skill from_json error, error code : %{public}d", parseResult);
1290     }
1291 }
1292 
from_json(const nlohmann::json & jsonObject,Distro & distro)1293 void from_json(const nlohmann::json &jsonObject, Distro &distro)
1294 {
1295     const auto &jsonObjectEnd = jsonObject.end();
1296     int32_t parseResult = ERR_OK;
1297     GetValueIfFindKey<bool>(jsonObject,
1298         jsonObjectEnd,
1299         ProfileReader::BUNDLE_MODULE_PROFILE_KEY_DELIVERY_WITH_INSTALL,
1300         distro.deliveryWithInstall,
1301         JsonType::BOOLEAN,
1302         true,
1303         parseResult,
1304         ArrayType::NOT_ARRAY);
1305     GetValueIfFindKey<std::string>(jsonObject,
1306         jsonObjectEnd,
1307         ProfileReader::BUNDLE_MODULE_PROFILE_KEY_MODULE_NAME,
1308         distro.moduleName,
1309         JsonType::STRING,
1310         true,
1311         parseResult,
1312         ArrayType::NOT_ARRAY);
1313     GetValueIfFindKey<std::string>(jsonObject,
1314         jsonObjectEnd,
1315         ProfileReader::BUNDLE_MODULE_PROFILE_KEY_MODULE_TYPE,
1316         distro.moduleType,
1317         JsonType::STRING,
1318         true,
1319         parseResult,
1320         ArrayType::NOT_ARRAY);
1321     // mustFlag decide by distro.moduleType
1322     GetValueIfFindKey<bool>(jsonObject,
1323         jsonObjectEnd,
1324         ProfileReader::BUNDLE_MODULE_PROFILE_KEY_MODULE_INSTALLATION_FREE,
1325         distro.installationFree,
1326         JsonType::BOOLEAN,
1327         false,
1328         parseResult,
1329         ArrayType::NOT_ARRAY);
1330     if (parseResult != ERR_OK) {
1331         APP_LOGE("Distro from_json error, error code : %{public}d", parseResult);
1332     }
1333 }
1334 
from_json(const nlohmann::json & jsonObject,InstallMark & installMark)1335 void from_json(const nlohmann::json &jsonObject, InstallMark &installMark)
1336 {
1337     const auto &jsonObjectEnd = jsonObject.end();
1338     int32_t parseResult = ERR_OK;
1339     GetValueIfFindKey<std::string>(jsonObject,
1340         jsonObjectEnd,
1341         ProfileReader::BUNDLE_INSTALL_MARK_BUNDLE,
1342         installMark.bundleName,
1343         JsonType::STRING,
1344         false,
1345         parseResult,
1346         ArrayType::NOT_ARRAY);
1347     GetValueIfFindKey<std::string>(jsonObject,
1348         jsonObjectEnd,
1349         ProfileReader::BUNDLE_INSTALL_MARK_PACKAGE,
1350         installMark.packageName,
1351         JsonType::STRING,
1352         false,
1353         parseResult,
1354         ArrayType::NOT_ARRAY);
1355     GetValueIfFindKey<int32_t>(jsonObject,
1356         jsonObjectEnd,
1357         ProfileReader::BUNDLE_INSTALL_MARK_STATUS,
1358         installMark.status,
1359         JsonType::NUMBER,
1360         false,
1361         parseResult,
1362         ArrayType::NOT_ARRAY);
1363     if (parseResult != ERR_OK) {
1364         APP_LOGE("InstallMark from_json error, error code : %{public}d", parseResult);
1365     }
1366 }
1367 
from_json(const nlohmann::json & jsonObject,DefinePermission & definePermission)1368 void from_json(const nlohmann::json &jsonObject, DefinePermission &definePermission)
1369 {
1370     const auto &jsonObjectEnd = jsonObject.end();
1371     int32_t parseResult = ERR_OK;
1372     GetValueIfFindKey<std::string>(jsonObject,
1373         jsonObjectEnd,
1374         Profile::DEFINEPERMISSION_NAME,
1375         definePermission.name,
1376         JsonType::STRING,
1377         false,
1378         parseResult,
1379         ArrayType::NOT_ARRAY);
1380     GetValueIfFindKey<std::string>(jsonObject,
1381         jsonObjectEnd,
1382         Profile::DEFINEPERMISSION_GRANT_MODE,
1383         definePermission.grantMode,
1384         JsonType::STRING,
1385         false,
1386         parseResult,
1387         ArrayType::NOT_ARRAY);
1388     GetValueIfFindKey<std::string>(jsonObject,
1389         jsonObjectEnd,
1390         Profile::DEFINEPERMISSION_AVAILABLE_LEVEL,
1391         definePermission.availableLevel,
1392         JsonType::STRING,
1393         false,
1394         parseResult,
1395         ArrayType::NOT_ARRAY);
1396     GetValueIfFindKey<bool>(jsonObject,
1397         jsonObjectEnd,
1398         Profile::DEFINEPERMISSION_PROVISION_ENABLE,
1399         definePermission.provisionEnable,
1400         JsonType::BOOLEAN,
1401         false,
1402         parseResult,
1403         ArrayType::NOT_ARRAY);
1404     GetValueIfFindKey<bool>(jsonObject,
1405         jsonObjectEnd,
1406         Profile::DEFINEPERMISSION_DISTRIBUTED_SCENE_ENABLE,
1407         definePermission.distributedSceneEnable,
1408         JsonType::BOOLEAN,
1409         false,
1410         parseResult,
1411         ArrayType::NOT_ARRAY);
1412     GetValueIfFindKey<std::string>(jsonObject,
1413         jsonObjectEnd,
1414         Profile::LABEL,
1415         definePermission.label,
1416         JsonType::STRING,
1417         false,
1418         parseResult,
1419         ArrayType::NOT_ARRAY);
1420     GetValueIfFindKey<int32_t>(jsonObject,
1421         jsonObjectEnd,
1422         Profile::LABEL_ID,
1423         definePermission.labelId,
1424         JsonType::NUMBER,
1425         false,
1426         parseResult,
1427         ArrayType::NOT_ARRAY);
1428     GetValueIfFindKey<std::string>(jsonObject,
1429         jsonObjectEnd,
1430         Profile::DESCRIPTION,
1431         definePermission.description,
1432         JsonType::STRING,
1433         false,
1434         parseResult,
1435         ArrayType::NOT_ARRAY);
1436     GetValueIfFindKey<int32_t>(jsonObject,
1437         jsonObjectEnd,
1438         Profile::DESCRIPTION_ID,
1439         definePermission.descriptionId,
1440         JsonType::NUMBER,
1441         false,
1442         parseResult,
1443         ArrayType::NOT_ARRAY);
1444     if (parseResult != ERR_OK) {
1445         APP_LOGE("DefinePermission from_json error, error code : %{public}d", parseResult);
1446     }
1447 }
1448 
from_json(const nlohmann::json & jsonObject,Dependency & dependency)1449 void from_json(const nlohmann::json &jsonObject, Dependency &dependency)
1450 {
1451     const auto &jsonObjectEnd = jsonObject.end();
1452     int32_t parseResult = ERR_OK;
1453     GetValueIfFindKey<std::string>(jsonObject,
1454         jsonObjectEnd,
1455         Profile::DEPENDENCIES_MODULE_NAME,
1456         dependency.moduleName,
1457         JsonType::STRING,
1458         false,
1459         parseResult,
1460         ArrayType::NOT_ARRAY);
1461     GetValueIfFindKey<std::string>(jsonObject,
1462         jsonObjectEnd,
1463         Profile::DEPENDENCIES_BUNDLE_NAME,
1464         dependency.bundleName,
1465         JsonType::STRING,
1466         false,
1467         parseResult,
1468         ArrayType::NOT_ARRAY);
1469     GetValueIfFindKey<int>(jsonObject,
1470         jsonObjectEnd,
1471         Profile::APP_VERSION_CODE,
1472         dependency.versionCode,
1473         JsonType::NUMBER,
1474         false,
1475         parseResult,
1476         ArrayType::NOT_ARRAY);
1477     if (parseResult != ERR_OK) {
1478         APP_LOGE("Dependency from_json error, error code : %{public}d", parseResult);
1479     }
1480 }
1481 
FromJson(const nlohmann::json & jsonObject)1482 int32_t InnerBundleInfo::FromJson(const nlohmann::json &jsonObject)
1483 {
1484     const auto &jsonObjectEnd = jsonObject.end();
1485     int32_t parseResult = ERR_OK;
1486     GetValueIfFindKey<Constants::AppType>(jsonObject,
1487         jsonObjectEnd,
1488         APP_TYPE,
1489         appType_,
1490         JsonType::NUMBER,
1491         true,
1492         parseResult,
1493         ArrayType::NOT_ARRAY);
1494     GetValueIfFindKey<int>(jsonObject,
1495         jsonObjectEnd,
1496         UID,
1497         uid_,
1498         JsonType::NUMBER,
1499         false,
1500         parseResult,
1501         ArrayType::NOT_ARRAY);
1502     GetValueIfFindKey<int>(jsonObject,
1503         jsonObjectEnd,
1504         GID,
1505         gid_,
1506         JsonType::NUMBER,
1507         false,
1508         parseResult,
1509         ArrayType::NOT_ARRAY);
1510     GetValueIfFindKey<std::vector<std::string>>(jsonObject,
1511         jsonObjectEnd,
1512         ALLOWED_ACLS,
1513         allowedAcls_,
1514         JsonType::ARRAY,
1515         false,
1516         parseResult,
1517         ArrayType::STRING);
1518     GetValueIfFindKey<BundleStatus>(jsonObject,
1519         jsonObjectEnd,
1520         BUNDLE_STATUS,
1521         bundleStatus_,
1522         JsonType::NUMBER,
1523         true,
1524         parseResult,
1525         ArrayType::NOT_ARRAY);
1526     GetValueIfFindKey<BundleInfo>(jsonObject,
1527         jsonObjectEnd,
1528         BASE_BUNDLE_INFO,
1529         *baseBundleInfo_,
1530         JsonType::OBJECT,
1531         true,
1532         parseResult,
1533         ArrayType::NOT_ARRAY);
1534     GetValueIfFindKey<ApplicationInfo>(jsonObject,
1535         jsonObjectEnd,
1536         BASE_APPLICATION_INFO,
1537         *baseApplicationInfo_,
1538         JsonType::OBJECT,
1539         true,
1540         parseResult,
1541         ArrayType::NOT_ARRAY);
1542     GetValueIfFindKey<std::map<std::string, AbilityInfo>>(jsonObject,
1543         jsonObjectEnd,
1544         BASE_ABILITY_INFO,
1545         baseAbilityInfos_,
1546         JsonType::OBJECT,
1547         true,
1548         parseResult,
1549         ArrayType::NOT_ARRAY);
1550     GetValueIfFindKey<std::map<std::string, InnerModuleInfo>>(jsonObject,
1551         jsonObjectEnd,
1552         INNER_MODULE_INFO,
1553         innerModuleInfos_,
1554         JsonType::OBJECT,
1555         true,
1556         parseResult,
1557         ArrayType::NOT_ARRAY);
1558     GetValueIfFindKey<std::map<std::string, std::vector<InnerModuleInfo>>>(jsonObject,
1559         jsonObjectEnd,
1560         INNER_SHARED_MODULE_INFO,
1561         innerSharedModuleInfos_,
1562         JsonType::OBJECT,
1563         false,
1564         parseResult,
1565         ArrayType::NOT_ARRAY);
1566     GetValueIfFindKey<std::map<std::string, std::vector<Skill>>>(jsonObject,
1567         jsonObjectEnd,
1568         SKILL_INFOS,
1569         skillInfos_,
1570         JsonType::OBJECT,
1571         true,
1572         parseResult,
1573         ArrayType::NOT_ARRAY);
1574     GetValueIfFindKey<int>(jsonObject,
1575         jsonObjectEnd,
1576         USER_ID,
1577         userId_,
1578         JsonType::NUMBER,
1579         true,
1580         parseResult,
1581         ArrayType::NOT_ARRAY);
1582     GetValueIfFindKey<std::string>(jsonObject,
1583         jsonObjectEnd,
1584         APP_FEATURE,
1585         appFeature_,
1586         JsonType::STRING,
1587         true,
1588         parseResult,
1589         ArrayType::NOT_ARRAY);
1590     GetValueIfFindKey<std::map<std::string, std::vector<FormInfo>>>(jsonObject,
1591         jsonObjectEnd,
1592         MODULE_FORMS,
1593         formInfos_,
1594         JsonType::OBJECT,
1595         true,
1596         parseResult,
1597         ArrayType::NOT_ARRAY);
1598     GetValueIfFindKey<std::map<std::string, ShortcutInfo>>(jsonObject,
1599         jsonObjectEnd,
1600         MODULE_SHORTCUT,
1601         shortcutInfos_,
1602         JsonType::OBJECT,
1603         true,
1604         parseResult,
1605         ArrayType::NOT_ARRAY);
1606     GetValueIfFindKey<std::map<std::string, CommonEventInfo>>(jsonObject,
1607         jsonObjectEnd,
1608         MODULE_COMMON_EVENT,
1609         commonEvents_,
1610         JsonType::OBJECT,
1611         true,
1612         parseResult,
1613         ArrayType::NOT_ARRAY);
1614     GetValueIfFindKey<InstallMark>(jsonObject,
1615         jsonObjectEnd,
1616         INSTALL_MARK,
1617         mark_,
1618         JsonType::OBJECT,
1619         false,
1620         parseResult,
1621         ArrayType::NOT_ARRAY);
1622     int32_t isOldVersion = ERR_OK;
1623     GetValueIfFindKey<std::map<std::string, InnerBundleUserInfo>>(jsonObject,
1624         jsonObjectEnd,
1625         INNER_BUNDLE_USER_INFOS,
1626         innerBundleUserInfos_,
1627         JsonType::OBJECT,
1628         true,
1629         isOldVersion,
1630         ArrayType::NOT_ARRAY);
1631     if (parseResult == ERR_OK && isOldVersion == ERR_APPEXECFWK_PARSE_PROFILE_MISSING_PROP) {
1632         // To be compatible with the old database,
1633         // if the old data does not have bundleUserInfos,
1634         // the default user information needs to be constructed.
1635         BuildDefaultUserInfo();
1636     }
1637     GetValueIfFindKey<bool>(jsonObject,
1638         jsonObjectEnd,
1639         BUNDLE_IS_NEW_VERSION,
1640         isNewVersion_,
1641         JsonType::BOOLEAN,
1642         false,
1643         parseResult,
1644         ArrayType::NOT_ARRAY);
1645     GetValueIfFindKey<std::map<std::string, ExtensionAbilityInfo>>(jsonObject,
1646         jsonObjectEnd,
1647         BUNDLE_BASE_EXTENSION_INFOS,
1648         baseExtensionInfos_,
1649         JsonType::OBJECT,
1650         false,
1651         parseResult,
1652         ArrayType::NOT_ARRAY);
1653     GetValueIfFindKey<std::map<std::string, std::vector<Skill>>>(jsonObject,
1654         jsonObjectEnd,
1655         BUNDLE_EXTENSION_SKILL_INFOS,
1656         extensionSkillInfos_,
1657         JsonType::OBJECT,
1658         false,
1659         parseResult,
1660         ArrayType::NOT_ARRAY);
1661     GetValueIfFindKey<BundlePackInfo>(jsonObject,
1662         jsonObjectEnd,
1663         BUNDLE_PACK_INFO,
1664         *bundlePackInfo_,
1665         JsonType::OBJECT,
1666         false,
1667         parseResult,
1668         ArrayType::NOT_ARRAY);
1669     GetValueIfFindKey<int>(jsonObject,
1670         jsonObjectEnd,
1671         APP_INDEX,
1672         appIndex_,
1673         JsonType::NUMBER,
1674         false,
1675         parseResult,
1676         ArrayType::NOT_ARRAY);
1677     GetValueIfFindKey<bool>(jsonObject,
1678         jsonObjectEnd,
1679         BUNDLE_IS_SANDBOX_APP,
1680         isSandboxApp_,
1681         JsonType::BOOLEAN,
1682         false,
1683         parseResult,
1684         ArrayType::NOT_ARRAY);
1685     GetValueIfFindKey<std::vector<HqfInfo>>(jsonObject,
1686         jsonObjectEnd,
1687         BUNDLE_HQF_INFOS,
1688         hqfInfos_,
1689         JsonType::ARRAY,
1690         false,
1691         parseResult,
1692         ArrayType::OBJECT);
1693     GetValueIfFindKey<std::vector<OverlayBundleInfo>>(jsonObject,
1694         jsonObjectEnd,
1695         OVERLAY_BUNDLE_INFO,
1696         overlayBundleInfo_,
1697         JsonType::ARRAY,
1698         false,
1699         parseResult,
1700         ArrayType::OBJECT);
1701     GetValueIfFindKey<int32_t>(jsonObject,
1702         jsonObjectEnd,
1703         OVERLAY_TYPE,
1704         overlayType_,
1705         JsonType::NUMBER,
1706         false,
1707         parseResult,
1708         ArrayType::NOT_ARRAY);
1709     GetValueIfFindKey<int32_t>(jsonObject,
1710         jsonObjectEnd,
1711         APPLY_QUICK_FIX_FREQUENCY,
1712         applyQuickFixFrequency_,
1713         JsonType::NUMBER,
1714         false,
1715         parseResult,
1716         ArrayType::NOT_ARRAY);
1717     GetValueIfFindKey<std::unordered_map<std::string, std::vector<DataGroupInfo>>>(jsonObject,
1718         jsonObjectEnd,
1719         DATA_GROUP_INFOS,
1720         dataGroupInfos_,
1721         JsonType::OBJECT,
1722         false,
1723         parseResult,
1724         ArrayType::NOT_ARRAY);
1725     if (parseResult != ERR_OK) {
1726         APP_LOGE("read InnerBundleInfo from database error, error code : %{public}d", parseResult);
1727     }
1728     return parseResult;
1729 }
1730 
BuildDefaultUserInfo()1731 void InnerBundleInfo::BuildDefaultUserInfo()
1732 {
1733     APP_LOGD("BuildDefaultUserInfo: bundleName: %{public}s.",
1734         baseApplicationInfo_->bundleName.c_str());
1735     InnerBundleUserInfo defaultInnerBundleUserInfo;
1736     defaultInnerBundleUserInfo.bundleUserInfo.userId = GetUserId();
1737     defaultInnerBundleUserInfo.uid = uid_;
1738     defaultInnerBundleUserInfo.gids.emplace_back(gid_);
1739     defaultInnerBundleUserInfo.installTime = baseBundleInfo_->installTime;
1740     defaultInnerBundleUserInfo.updateTime = baseBundleInfo_->updateTime;
1741     defaultInnerBundleUserInfo.bundleName = baseApplicationInfo_->bundleName;
1742     defaultInnerBundleUserInfo.bundleUserInfo.enabled = baseApplicationInfo_->enabled;
1743     AddInnerBundleUserInfo(defaultInnerBundleUserInfo);
1744 }
1745 
FindHapModuleInfo(const std::string & modulePackage,int32_t userId) const1746 std::optional<HapModuleInfo> InnerBundleInfo::FindHapModuleInfo(const std::string &modulePackage, int32_t userId) const
1747 {
1748     auto it = innerModuleInfos_.find(modulePackage);
1749     if (it == innerModuleInfos_.end()) {
1750         APP_LOGE("can not find module %{public}s", modulePackage.c_str());
1751         return std::nullopt;
1752     }
1753     HapModuleInfo hapInfo;
1754     hapInfo.name = it->second.name;
1755     hapInfo.package = it->second.modulePackage;
1756     hapInfo.moduleName = it->second.moduleName;
1757     hapInfo.description = it->second.description;
1758     hapInfo.descriptionId = it->second.descriptionId;
1759     hapInfo.label = it->second.label;
1760     hapInfo.labelId = it->second.labelId;
1761     hapInfo.iconPath = it->second.icon;
1762     hapInfo.iconId = it->second.iconId;
1763     hapInfo.mainAbility = it->second.mainAbility;
1764     hapInfo.srcPath = it->second.srcPath;
1765     hapInfo.hapPath = it->second.hapPath;
1766     hapInfo.supportedModes = baseApplicationInfo_->supportedModes;
1767     hapInfo.reqCapabilities = it->second.reqCapabilities;
1768     hapInfo.colorMode = it->second.colorMode;
1769     hapInfo.isRemovable = it->second.isRemovable;
1770     hapInfo.upgradeFlag = it->second.upgradeFlag;
1771     hapInfo.isLibIsolated = it->second.isLibIsolated;
1772     hapInfo.nativeLibraryPath = it->second.nativeLibraryPath;
1773     hapInfo.cpuAbi = it->second.cpuAbi;
1774 
1775     hapInfo.bundleName = baseApplicationInfo_->bundleName;
1776     hapInfo.mainElementName = it->second.mainAbility;
1777     hapInfo.pages = it->second.pages;
1778     hapInfo.process = it->second.process;
1779     hapInfo.resourcePath = it->second.moduleResPath;
1780     hapInfo.srcEntrance = it->second.srcEntrance;
1781     hapInfo.uiSyntax = it->second.uiSyntax;
1782     hapInfo.virtualMachine = it->second.virtualMachine;
1783     hapInfo.deliveryWithInstall = it->second.distro.deliveryWithInstall;
1784     hapInfo.installationFree = it->second.distro.installationFree;
1785     hapInfo.isModuleJson = it->second.isModuleJson;
1786     hapInfo.isStageBasedModel = it->second.isStageBasedModel;
1787     std::string moduleType = it->second.distro.moduleType;
1788     if (moduleType == Profile::MODULE_TYPE_ENTRY) {
1789         hapInfo.moduleType = ModuleType::ENTRY;
1790     } else if (moduleType == Profile::MODULE_TYPE_FEATURE) {
1791         hapInfo.moduleType = ModuleType::FEATURE;
1792     } else if (moduleType == Profile::MODULE_TYPE_SHARED) {
1793         hapInfo.moduleType = ModuleType::SHARED;
1794     } else {
1795         hapInfo.moduleType = ModuleType::UNKNOWN;
1796     }
1797     std::string key;
1798     key.append(".").append(modulePackage).append(".");
1799     for (const auto &extension : baseExtensionInfos_) {
1800         if (extension.first.find(key) != std::string::npos) {
1801             hapInfo.extensionInfos.emplace_back(extension.second);
1802         }
1803     }
1804     hapInfo.metadata = it->second.metadata;
1805     bool first = false;
1806     for (auto &ability : baseAbilityInfos_) {
1807         if (ability.second.name == Constants::APP_DETAIL_ABILITY) {
1808             continue;
1809         }
1810         if (ability.first.find(key) != std::string::npos) {
1811             if (!first) {
1812                 hapInfo.deviceTypes = ability.second.deviceTypes;
1813                 first = true;
1814             }
1815             auto &abilityInfo = hapInfo.abilityInfos.emplace_back(ability.second);
1816             GetApplicationInfo(ApplicationFlag::GET_APPLICATION_INFO_WITH_PERMISSION |
1817                 ApplicationFlag::GET_APPLICATION_INFO_WITH_CERTIFICATE_FINGERPRINT, userId,
1818                 abilityInfo.applicationInfo);
1819         }
1820     }
1821     hapInfo.dependencies = it->second.dependencies;
1822     hapInfo.compileMode = ConvertCompileMode(it->second.compileMode);
1823     for (const auto &hqf : hqfInfos_) {
1824         if (hqf.moduleName == it->second.moduleName) {
1825             hapInfo.hqfInfo = hqf;
1826             break;
1827         }
1828     }
1829     hapInfo.atomicServiceModuleType = it->second.atomicServiceModuleType;
1830     for (const auto &item : it->second.preloads) {
1831         PreloadItem preload(item);
1832         hapInfo.preloads.emplace_back(preload);
1833     }
1834     for (const auto &item : it->second.proxyDatas) {
1835         ProxyData proxyData(item);
1836         hapInfo.proxyDatas.emplace_back(proxyData);
1837     }
1838     hapInfo.buildHash = it->second.buildHash;
1839     hapInfo.isolationMode = GetIsolationMode(it->second.isolationMode);
1840     hapInfo.compressNativeLibs = it->second.compressNativeLibs;
1841     hapInfo.nativeLibraryFileNames = it->second.nativeLibraryFileNames;
1842     hapInfo.aotCompileStatus = it->second.aotCompileStatus;
1843     return hapInfo;
1844 }
1845 
FindAbilityInfo(const std::string & moduleName,const std::string & abilityName,int32_t userId) const1846 std::optional<AbilityInfo> InnerBundleInfo::FindAbilityInfo(
1847     const std::string &moduleName,
1848     const std::string &abilityName,
1849     int32_t userId) const
1850 {
1851     for (const auto &ability : baseAbilityInfos_) {
1852         auto abilityInfo = ability.second;
1853         if ((abilityInfo.name == abilityName) &&
1854             (moduleName.empty() || (abilityInfo.moduleName == moduleName))) {
1855             GetApplicationInfo(ApplicationFlag::GET_APPLICATION_INFO_WITH_PERMISSION |
1856                 ApplicationFlag::GET_APPLICATION_INFO_WITH_CERTIFICATE_FINGERPRINT, userId,
1857                 abilityInfo.applicationInfo);
1858             return abilityInfo;
1859         }
1860     }
1861 
1862     return std::nullopt;
1863 }
1864 
FindAbilityInfoV9(const std::string & moduleName,const std::string & abilityName) const1865 std::optional<AbilityInfo> InnerBundleInfo::FindAbilityInfoV9(
1866     const std::string &moduleName, const std::string &abilityName) const
1867 {
1868     for (const auto &ability : baseAbilityInfos_) {
1869         auto abilityInfo = ability.second;
1870         if ((abilityInfo.name == abilityName) &&
1871             (moduleName.empty() || (abilityInfo.moduleName == moduleName))) {
1872             return abilityInfo;
1873         }
1874     }
1875     APP_LOGE("bundleName: %{public}s not find moduleName:%{public}s, abilityName:%{public}s",
1876         GetBundleName().c_str(), moduleName.c_str(), abilityName.c_str());
1877     return std::nullopt;
1878 }
1879 
FindAbilityInfo(const std::string & moduleName,const std::string & abilityName,AbilityInfo & info) const1880 ErrCode InnerBundleInfo::FindAbilityInfo(
1881     const std::string &moduleName, const std::string &abilityName, AbilityInfo &info) const
1882 {
1883     bool isModuleFind = false;
1884     for (const auto &ability : baseAbilityInfos_) {
1885         auto abilityInfo = ability.second;
1886         if ((abilityInfo.moduleName == moduleName)) {
1887             isModuleFind = true;
1888             if (abilityInfo.name == abilityName) {
1889                 info = abilityInfo;
1890                 return ERR_OK;
1891             }
1892         }
1893     }
1894     APP_LOGE("bundleName: %{public}s not find moduleName:%{public}s, abilityName:%{public}s, isModuleFind:%{public}d",
1895         GetBundleName().c_str(), moduleName.c_str(), abilityName.c_str(), isModuleFind);
1896     if (isModuleFind) {
1897         return ERR_BUNDLE_MANAGER_ABILITY_NOT_EXIST;
1898     } else {
1899         return ERR_BUNDLE_MANAGER_MODULE_NOT_EXIST;
1900     }
1901 }
1902 
FindAbilityInfos(int32_t userId) const1903 std::optional<std::vector<AbilityInfo>> InnerBundleInfo::FindAbilityInfos(int32_t userId) const
1904 {
1905     if (!HasInnerBundleUserInfo(userId)) {
1906         return std::nullopt;
1907     }
1908 
1909     std::vector<AbilityInfo> abilitys;
1910     for (const auto &ability : baseAbilityInfos_) {
1911         if (ability.second.name == Constants::APP_DETAIL_ABILITY) {
1912             continue;
1913         }
1914         auto abilityInfo = ability.second;
1915         GetApplicationInfo(ApplicationFlag::GET_APPLICATION_INFO_WITH_PERMISSION |
1916             ApplicationFlag::GET_APPLICATION_INFO_WITH_CERTIFICATE_FINGERPRINT, userId,
1917             abilityInfo.applicationInfo);
1918         abilitys.emplace_back(abilityInfo);
1919     }
1920 
1921     if (abilitys.empty()) {
1922         return std::nullopt;
1923     }
1924     return abilitys;
1925 }
1926 
FindExtensionInfo(const std::string & moduleName,const std::string & extensionName) const1927 std::optional<ExtensionAbilityInfo> InnerBundleInfo::FindExtensionInfo(
1928     const std::string &moduleName, const std::string &extensionName) const
1929 {
1930     for (const auto &extension : baseExtensionInfos_) {
1931         if ((extension.second.name == extensionName) &&
1932             (moduleName.empty() || (extension.second.moduleName == moduleName))) {
1933             return extension.second;
1934         }
1935     }
1936 
1937     return std::nullopt;
1938 }
1939 
FindExtensionInfos() const1940 std::optional<std::vector<ExtensionAbilityInfo>> InnerBundleInfo::FindExtensionInfos() const
1941 {
1942     std::vector<ExtensionAbilityInfo> extensions;
1943     for (const auto &extension : baseExtensionInfos_) {
1944         extensions.emplace_back(extension.second);
1945     }
1946 
1947     if (extensions.empty()) {
1948         return std::nullopt;
1949     }
1950 
1951     return extensions;
1952 }
1953 
AddModuleInfo(const InnerBundleInfo & newInfo)1954 bool InnerBundleInfo::AddModuleInfo(const InnerBundleInfo &newInfo)
1955 {
1956     if (newInfo.currentPackage_.empty()) {
1957         APP_LOGE("current package is empty");
1958         return false;
1959     }
1960     if (FindModule(newInfo.currentPackage_)) {
1961         APP_LOGE("current package %{public}s is exist", currentPackage_.c_str());
1962         return false;
1963     }
1964     AddInnerModuleInfo(newInfo.innerModuleInfos_);
1965     AddModuleAbilityInfo(newInfo.baseAbilityInfos_);
1966     AddModuleSkillInfo(newInfo.skillInfos_);
1967     AddModuleExtensionInfos(newInfo.baseExtensionInfos_);
1968     AddModuleExtensionSkillInfos(newInfo.extensionSkillInfos_);
1969     AddModuleFormInfo(newInfo.formInfos_);
1970     AddModuleShortcutInfo(newInfo.shortcutInfos_);
1971     AddModuleCommonEvent(newInfo.commonEvents_);
1972     UpdateIsCompressNativeLibs();
1973     return true;
1974 }
1975 
UpdateBaseBundleInfo(const BundleInfo & bundleInfo,bool isEntry)1976 void InnerBundleInfo::UpdateBaseBundleInfo(const BundleInfo &bundleInfo, bool isEntry)
1977 {
1978     baseBundleInfo_->name = bundleInfo.name;
1979 
1980     baseBundleInfo_->versionCode = bundleInfo.versionCode;
1981     baseBundleInfo_->versionName = bundleInfo.versionName;
1982     baseBundleInfo_->minCompatibleVersionCode = bundleInfo.minCompatibleVersionCode;
1983 
1984     baseBundleInfo_->compatibleVersion = bundleInfo.compatibleVersion;
1985     baseBundleInfo_->targetVersion = bundleInfo.targetVersion;
1986 
1987     baseBundleInfo_->isKeepAlive = bundleInfo.isKeepAlive;
1988     baseBundleInfo_->singleton = bundleInfo.singleton;
1989     if (!baseBundleInfo_->isPreInstallApp) {
1990         baseBundleInfo_->isPreInstallApp = bundleInfo.isPreInstallApp;
1991     }
1992 
1993     baseBundleInfo_->vendor = bundleInfo.vendor;
1994     baseBundleInfo_->releaseType = bundleInfo.releaseType;
1995     if (!baseBundleInfo_->isNativeApp) {
1996         baseBundleInfo_->isNativeApp = bundleInfo.isNativeApp;
1997     }
1998 
1999     if (isEntry) {
2000         baseBundleInfo_->mainEntry = bundleInfo.mainEntry;
2001         baseBundleInfo_->entryModuleName = bundleInfo.entryModuleName;
2002     }
2003 }
2004 
UpdateBaseApplicationInfo(const ApplicationInfo & applicationInfo,bool isEntry)2005 void InnerBundleInfo::UpdateBaseApplicationInfo(
2006     const ApplicationInfo &applicationInfo, bool isEntry)
2007 {
2008     baseApplicationInfo_->name = applicationInfo.name;
2009     baseApplicationInfo_->bundleName = applicationInfo.bundleName;
2010 
2011     baseApplicationInfo_->versionCode = applicationInfo.versionCode;
2012     baseApplicationInfo_->versionName = applicationInfo.versionName;
2013     baseApplicationInfo_->minCompatibleVersionCode = applicationInfo.minCompatibleVersionCode;
2014 
2015     baseApplicationInfo_->apiCompatibleVersion = applicationInfo.apiCompatibleVersion;
2016     baseApplicationInfo_->apiTargetVersion = applicationInfo.apiTargetVersion;
2017 
2018     baseApplicationInfo_->iconPath = applicationInfo.iconPath;
2019     baseApplicationInfo_->iconId = applicationInfo.iconId;
2020     baseApplicationInfo_->label = applicationInfo.label;
2021     baseApplicationInfo_->labelId = applicationInfo.labelId;
2022     baseApplicationInfo_->description = applicationInfo.description;
2023     baseApplicationInfo_->descriptionId = applicationInfo.descriptionId;
2024     baseApplicationInfo_->iconResource = applicationInfo.iconResource;
2025     baseApplicationInfo_->labelResource = applicationInfo.labelResource;
2026     baseApplicationInfo_->descriptionResource = applicationInfo.descriptionResource;
2027     baseApplicationInfo_->singleton = applicationInfo.singleton;
2028     baseApplicationInfo_->userDataClearable = applicationInfo.userDataClearable;
2029     baseApplicationInfo_->accessible = applicationInfo.accessible;
2030 
2031     if (!baseApplicationInfo_->isSystemApp) {
2032         baseApplicationInfo_->isSystemApp = applicationInfo.isSystemApp;
2033     }
2034     if (!baseApplicationInfo_->isLauncherApp) {
2035         baseApplicationInfo_->isLauncherApp = applicationInfo.isLauncherApp;
2036     }
2037 
2038     baseApplicationInfo_->apiReleaseType = applicationInfo.apiReleaseType;
2039     baseApplicationInfo_->deviceId = applicationInfo.deviceId;
2040     baseApplicationInfo_->distributedNotificationEnabled = applicationInfo.distributedNotificationEnabled;
2041     baseApplicationInfo_->entityType = applicationInfo.entityType;
2042     baseApplicationInfo_->process = applicationInfo.process;
2043     baseApplicationInfo_->supportedModes = applicationInfo.supportedModes;
2044     baseApplicationInfo_->vendor = applicationInfo.vendor;
2045     baseApplicationInfo_->appDistributionType = applicationInfo.appDistributionType;
2046     baseApplicationInfo_->appProvisionType = applicationInfo.appProvisionType;
2047     baseApplicationInfo_->formVisibleNotify = applicationInfo.formVisibleNotify;
2048     baseApplicationInfo_->needAppDetail = applicationInfo.needAppDetail;
2049     baseApplicationInfo_->appDetailAbilityLibraryPath = applicationInfo.appDetailAbilityLibraryPath;
2050     UpdatePrivilegeCapability(applicationInfo);
2051     SetHideDesktopIcon(applicationInfo.hideDesktopIcon);
2052 #ifdef BUNDLE_FRAMEWORK_OVERLAY_INSTALLATION
2053     baseApplicationInfo_->targetBundleName = applicationInfo.targetBundleName;
2054     baseApplicationInfo_->targetPriority = applicationInfo.targetPriority;
2055 #endif
2056     if (isEntry) {
2057         baseApplicationInfo_->debug = applicationInfo.debug;
2058     } else if (!HasEntry() && applicationInfo.debug) {
2059         baseApplicationInfo_->debug = applicationInfo.debug;
2060     }
2061 }
2062 
UpdateAppDetailAbilityAttrs()2063 void InnerBundleInfo::UpdateAppDetailAbilityAttrs()
2064 {
2065     if (IsExistLauncherAbility()) {
2066         baseApplicationInfo_->needAppDetail = false;
2067         baseApplicationInfo_->appDetailAbilityLibraryPath = Constants::EMPTY_STRING;
2068     }
2069     for (auto iter = baseAbilityInfos_.begin(); iter != baseAbilityInfos_.end(); ++iter) {
2070         if (iter->second.name == Constants::APP_DETAIL_ABILITY) {
2071             if (!baseApplicationInfo_->needAppDetail) {
2072                 baseAbilityInfos_.erase(iter);
2073                 return;
2074             }
2075             if (isNewVersion_) {
2076                 iter->second.labelId = baseApplicationInfo_->labelId;
2077                 iter->second.iconId =
2078                     (baseApplicationInfo_->iconId == 0) ? iter->second.iconId : baseApplicationInfo_->iconId;
2079             }
2080             return;
2081         }
2082     }
2083 }
2084 
IsHideDesktopIcon() const2085 bool InnerBundleInfo::IsHideDesktopIcon() const
2086 {
2087     return baseApplicationInfo_->hideDesktopIcon ? true : !IsExistLauncherAbility();
2088 }
2089 
IsExistLauncherAbility() const2090 bool InnerBundleInfo::IsExistLauncherAbility() const
2091 {
2092     bool isExistLauncherAbility = false;
2093     OHOS::AAFwk::Want want;
2094     want.SetAction(OHOS::AAFwk::Want::ACTION_HOME);
2095     want.AddEntity(OHOS::AAFwk::Want::ENTITY_HOME);
2096     for (const auto& abilityInfoPair : baseAbilityInfos_) {
2097         auto skillsPair = skillInfos_.find(abilityInfoPair.first);
2098         if (skillsPair == skillInfos_.end()) {
2099             continue;
2100         }
2101         for (const Skill& skill : skillsPair->second) {
2102             if (skill.MatchLauncher(want) && (abilityInfoPair.second.type == AbilityType::PAGE)) {
2103                 isExistLauncherAbility = true;
2104                 break;
2105             }
2106         }
2107     }
2108     return isExistLauncherAbility;
2109 }
2110 
UpdateNativeLibAttrs(const ApplicationInfo & applicationInfo)2111 void InnerBundleInfo::UpdateNativeLibAttrs(const ApplicationInfo &applicationInfo)
2112 {
2113     baseApplicationInfo_->cpuAbi = applicationInfo.cpuAbi;
2114     baseApplicationInfo_->nativeLibraryPath = applicationInfo.nativeLibraryPath;
2115 }
2116 
UpdateArkNativeAttrs(const ApplicationInfo & applicationInfo)2117 void InnerBundleInfo::UpdateArkNativeAttrs(const ApplicationInfo &applicationInfo)
2118 {
2119     baseApplicationInfo_->arkNativeFileAbi = applicationInfo.arkNativeFileAbi;
2120     baseApplicationInfo_->arkNativeFilePath = applicationInfo.arkNativeFilePath;
2121 }
2122 
UpdatePrivilegeCapability(const ApplicationInfo & applicationInfo)2123 void InnerBundleInfo::UpdatePrivilegeCapability(const ApplicationInfo &applicationInfo)
2124 {
2125     SetKeepAlive(applicationInfo.keepAlive);
2126     baseApplicationInfo_->runningResourcesApply = applicationInfo.runningResourcesApply;
2127     baseApplicationInfo_->associatedWakeUp = applicationInfo.associatedWakeUp;
2128     SetAllowCommonEvent(applicationInfo.allowCommonEvent);
2129     baseApplicationInfo_->resourcesApply = applicationInfo.resourcesApply;
2130 }
2131 
UpdateRemovable(bool isPreInstall,bool removable)2132 void InnerBundleInfo::UpdateRemovable(bool isPreInstall, bool removable)
2133 {
2134 #ifdef USE_PRE_BUNDLE_PROFILE
2135     if (!isPreInstall) {
2136         return;
2137     }
2138 #endif
2139 
2140     baseApplicationInfo_->removable = removable;
2141 }
2142 
UpdateModuleInfo(const InnerBundleInfo & newInfo)2143 void InnerBundleInfo::UpdateModuleInfo(const InnerBundleInfo &newInfo)
2144 {
2145     if (newInfo.currentPackage_.empty()) {
2146         APP_LOGE("no package in new info");
2147         return;
2148     }
2149 
2150     RemoveModuleInfo(newInfo.currentPackage_);
2151     AddInnerModuleInfo(newInfo.innerModuleInfos_);
2152     AddModuleAbilityInfo(newInfo.baseAbilityInfos_);
2153     AddModuleSkillInfo(newInfo.skillInfos_);
2154     AddModuleExtensionInfos(newInfo.baseExtensionInfos_);
2155     AddModuleExtensionSkillInfos(newInfo.extensionSkillInfos_);
2156     AddModuleFormInfo(newInfo.formInfos_);
2157     AddModuleShortcutInfo(newInfo.shortcutInfos_);
2158     AddModuleCommonEvent(newInfo.commonEvents_);
2159     UpdateIsCompressNativeLibs();
2160 }
2161 
GetMaxVerBaseSharedBundleInfo(const std::string & moduleName,BaseSharedBundleInfo & baseSharedBundleInfo) const2162 bool InnerBundleInfo::GetMaxVerBaseSharedBundleInfo(const std::string &moduleName,
2163     BaseSharedBundleInfo &baseSharedBundleInfo) const
2164 {
2165     auto it = innerSharedModuleInfos_.find(moduleName);
2166     if (it == innerSharedModuleInfos_.end()) {
2167         APP_LOGE("The shared module(%{public}s) infomation does not exist", moduleName.c_str());
2168         return false;
2169     }
2170     auto sharedModuleInfoVector = it->second;
2171     if (sharedModuleInfoVector.empty()) {
2172         APP_LOGE("No version exists for the shared module(%{public}s)", moduleName.c_str());
2173         return false;
2174     }
2175     InnerModuleInfo innerModuleInfo = sharedModuleInfoVector.front();
2176     if (innerModuleInfo.bundleType != BundleType::SHARED) {
2177         APP_LOGE("GetMaxVerBaseSharedBundleInfo failed, bundleType is invalid!");
2178         return false;
2179     }
2180     baseSharedBundleInfo.bundleName = baseBundleInfo_->name;
2181     baseSharedBundleInfo.moduleName = innerModuleInfo.moduleName;
2182     baseSharedBundleInfo.versionCode = innerModuleInfo.versionCode;
2183     baseSharedBundleInfo.nativeLibraryPath = innerModuleInfo.nativeLibraryPath;
2184     baseSharedBundleInfo.hapPath = innerModuleInfo.hapPath;
2185     baseSharedBundleInfo.compressNativeLibs = innerModuleInfo.compressNativeLibs;
2186     baseSharedBundleInfo.nativeLibraryFileNames = innerModuleInfo.nativeLibraryFileNames;
2187     return true;
2188 }
2189 
GetBaseSharedBundleInfo(const std::string & moduleName,uint32_t versionCode,BaseSharedBundleInfo & baseSharedBundleInfo) const2190 bool InnerBundleInfo::GetBaseSharedBundleInfo(const std::string &moduleName, uint32_t versionCode,
2191     BaseSharedBundleInfo &baseSharedBundleInfo) const
2192 {
2193     auto it = innerSharedModuleInfos_.find(moduleName);
2194     if (it == innerSharedModuleInfos_.end()) {
2195         APP_LOGE("The shared module(%{public}s) infomation does not exist", moduleName.c_str());
2196         return false;
2197     }
2198     auto sharedModuleInfoVector = it->second;
2199     if (sharedModuleInfoVector.empty()) {
2200         APP_LOGE("No version exists for the shared module(%{public}s)", moduleName.c_str());
2201         return false;
2202     }
2203     for (const auto &item : sharedModuleInfoVector) {
2204         if (item.bundleType != BundleType::SHARED) {
2205             APP_LOGE("GetBaseSharedBundleInfo failed, bundleType is invalid!");
2206             return false;
2207         }
2208         if (item.versionCode == versionCode) {
2209             baseSharedBundleInfo.bundleName = baseBundleInfo_->name;
2210             baseSharedBundleInfo.moduleName = item.moduleName;
2211             baseSharedBundleInfo.versionCode = item.versionCode;
2212             baseSharedBundleInfo.nativeLibraryPath = item.nativeLibraryPath;
2213             baseSharedBundleInfo.hapPath = item.hapPath;
2214             baseSharedBundleInfo.compressNativeLibs = item.compressNativeLibs;
2215             baseSharedBundleInfo.nativeLibraryFileNames = item.nativeLibraryFileNames;
2216             return true;
2217         }
2218     }
2219     APP_LOGE("GetBaseSharedBundleInfo failed, the version(%{public}d) is not exists for this module(%{public}s)",
2220         versionCode, moduleName.c_str());
2221     return false;
2222 }
2223 
InsertInnerSharedModuleInfo(const std::string & moduleName,const InnerModuleInfo & innerModuleInfo)2224 void InnerBundleInfo::InsertInnerSharedModuleInfo(const std::string &moduleName,
2225     const InnerModuleInfo &innerModuleInfo)
2226 {
2227     auto iterator = innerSharedModuleInfos_.find(moduleName);
2228     if (iterator != innerSharedModuleInfos_.end()) {
2229         auto innerModuleInfoVector = iterator->second;
2230         bool insertFlag = false;
2231         for (unsigned long i = 0; i < innerModuleInfoVector.size(); i++) {
2232             if (innerModuleInfo.versionCode == innerModuleInfoVector.at(i).versionCode) {
2233                 // if the inserted versionCode same as the existing one, replace old innerModuleInfo.
2234                 innerModuleInfoVector.at(i) = innerModuleInfo;
2235                 insertFlag = true;
2236                 break;
2237             } else if (innerModuleInfo.versionCode > innerModuleInfoVector.at(i).versionCode) {
2238                 // if the inserted versionCode bigger then the existing one, insert the specified location.
2239                 innerModuleInfoVector.emplace(innerModuleInfoVector.begin() + i, innerModuleInfo);
2240                 insertFlag = true;
2241                 break;
2242             } else {
2243                 continue;
2244             }
2245         }
2246         if (!insertFlag) {
2247             // insert innerModuleInfo in last location.
2248             innerModuleInfoVector.emplace(innerModuleInfoVector.end(), innerModuleInfo);
2249         }
2250         innerSharedModuleInfos_[moduleName] = innerModuleInfoVector;
2251     } else {
2252         std::vector<InnerModuleInfo> newInnerModuleInfoVector;
2253         newInnerModuleInfoVector.emplace_back(innerModuleInfo);
2254         innerSharedModuleInfos_.try_emplace(moduleName, newInnerModuleInfoVector);
2255     }
2256 }
2257 
SetSharedModuleNativeLibraryPath(const std::string & nativeLibraryPath)2258 void InnerBundleInfo::SetSharedModuleNativeLibraryPath(const std::string &nativeLibraryPath)
2259 {
2260     auto sharedModuleInfoIterator = innerSharedModuleInfos_.find(currentPackage_);
2261     auto moduleInfoIterator = innerModuleInfos_.find(currentPackage_);
2262     if ((sharedModuleInfoIterator == innerSharedModuleInfos_.end()) ||
2263         (moduleInfoIterator == innerModuleInfos_.end())) {
2264         APP_LOGE("The shared module(%{public}s) infomation does not exist", currentPackage_.c_str());
2265         return;
2266     }
2267     auto &innerModuleInfoVector = sharedModuleInfoIterator->second;
2268     for (auto iter = innerModuleInfoVector.begin(); iter != innerModuleInfoVector.end(); ++iter) {
2269         if (iter->versionCode == moduleInfoIterator->second.versionCode) {
2270             iter->nativeLibraryPath = nativeLibraryPath;
2271             return;
2272         }
2273     }
2274 }
2275 
GetSharedBundleInfo(SharedBundleInfo & sharedBundleInfo) const2276 bool InnerBundleInfo::GetSharedBundleInfo(SharedBundleInfo &sharedBundleInfo) const
2277 {
2278     sharedBundleInfo.name = GetBundleName();
2279     sharedBundleInfo.compatiblePolicy = CompatiblePolicy::BACKWARD_COMPATIBILITY;
2280     std::vector<SharedModuleInfo> sharedModuleInfos;
2281     for (const auto &infoVector : innerSharedModuleInfos_) {
2282         for (const auto &info : infoVector.second) {
2283             SharedModuleInfo sharedModuleInfo;
2284             sharedModuleInfo.name = info.name;
2285             sharedModuleInfo.versionCode = info.versionCode;
2286             sharedModuleInfo.versionName = info.versionName;
2287             sharedModuleInfo.description = info.description;
2288             sharedModuleInfo.descriptionId = info.descriptionId;
2289             sharedModuleInfo.compressNativeLibs = info.compressNativeLibs;
2290             sharedModuleInfo.hapPath = info.hapPath;
2291             sharedModuleInfo.cpuAbi = info.cpuAbi;
2292             sharedModuleInfo.nativeLibraryPath = info.nativeLibraryPath;
2293             sharedModuleInfo.nativeLibraryFileNames = info.nativeLibraryFileNames;
2294             sharedModuleInfos.emplace_back(sharedModuleInfo);
2295         }
2296     }
2297     sharedBundleInfo.sharedModuleInfos = sharedModuleInfos;
2298     return true;
2299 }
2300 
GetSharedDependencies(const std::string & moduleName,std::vector<Dependency> & dependencies) const2301 bool InnerBundleInfo::GetSharedDependencies(const std::string &moduleName,
2302     std::vector<Dependency> &dependencies) const
2303 {
2304     if (innerModuleInfos_.find(moduleName) != innerModuleInfos_.end()) {
2305         dependencies = innerModuleInfos_.at(moduleName).dependencies;
2306         return true;
2307     }
2308     APP_LOGE("GetSharedDependencies can not find module %{public}s", moduleName.c_str());
2309     return false;
2310 }
2311 
GetAllSharedDependencies(const std::string & moduleName,std::vector<Dependency> & dependencies) const2312 bool InnerBundleInfo::GetAllSharedDependencies(const std::string &moduleName,
2313     std::vector<Dependency> &dependencies) const
2314 {
2315     if (!GetSharedDependencies(moduleName, dependencies)) {
2316         return false;
2317     }
2318     std::deque<Dependency> dependenciesDeque;
2319     std::copy(dependencies.begin(), dependencies.end(), std::back_inserter(dependenciesDeque));
2320     dependencies.clear();
2321     while (!dependenciesDeque.empty()) {
2322         bool isAdd = true;
2323         Dependency itemDependency = dependenciesDeque.front();
2324         dependenciesDeque.pop_front();
2325         for (const auto &item : dependencies) {
2326             if (item.bundleName == itemDependency.bundleName && item.moduleName == itemDependency.moduleName &&
2327                 item.versionCode == itemDependency.versionCode) {
2328                 isAdd = false;
2329                 break;
2330             }
2331         }
2332         if (isAdd) {
2333             dependencies.push_back(itemDependency);
2334             std::vector<Dependency> tempDependencies;
2335             if (GetSharedDependencies(itemDependency.moduleName, tempDependencies)) {
2336                 std::copy(tempDependencies.begin(), tempDependencies.end(), std::back_inserter(dependenciesDeque));
2337             }
2338         }
2339     }
2340     return true;
2341 }
2342 
RemoveModuleInfo(const std::string & modulePackage)2343 void InnerBundleInfo::RemoveModuleInfo(const std::string &modulePackage)
2344 {
2345     auto it = innerModuleInfos_.find(modulePackage);
2346     if (it == innerModuleInfos_.end()) {
2347         APP_LOGE("The module(%{public}s) infomation does not exist", modulePackage.c_str());
2348         return;
2349     }
2350 
2351     auto oldModuleInfo = it->second;
2352     if (oldModuleInfo.isEntry) {
2353         baseBundleInfo_->mainEntry.clear();
2354         baseBundleInfo_->entryModuleName.clear();
2355     }
2356     innerModuleInfos_.erase(it);
2357     std::string key;
2358     key.append(".").append(modulePackage).append(".");
2359     for (auto iter = shortcutInfos_.begin(); iter != shortcutInfos_.end();) {
2360         if (iter->first.find(key) != std::string::npos) {
2361             shortcutInfos_.erase(iter++);
2362         } else {
2363             ++iter;
2364         }
2365     }
2366 
2367     for (auto iter = commonEvents_.begin(); iter != commonEvents_.end();) {
2368         if (iter->first.find(key) != std::string::npos) {
2369             commonEvents_.erase(iter++);
2370         } else {
2371             ++iter;
2372         }
2373     }
2374 
2375     // delete old abilityInfos
2376     for (auto abilityKey : oldModuleInfo.abilityKeys) {
2377         auto abilityItem = baseAbilityInfos_.find(abilityKey);
2378         if (abilityItem == baseAbilityInfos_.end()) {
2379             continue;
2380         }
2381 
2382         baseAbilityInfos_.erase(abilityItem);
2383         formInfos_.erase(abilityKey);
2384     }
2385 
2386     // delete old skillInfos
2387     for (auto skillKey : oldModuleInfo.skillKeys) {
2388         auto skillItem = skillInfos_.find(skillKey);
2389         if (skillItem == skillInfos_.end()) {
2390             continue;
2391         }
2392 
2393         skillInfos_.erase(skillItem);
2394     }
2395 
2396     // delete old extensionInfos
2397     for (auto extensionKey : oldModuleInfo.extensionKeys) {
2398         auto extensionItem = baseExtensionInfos_.find(extensionKey);
2399         if (extensionItem == baseExtensionInfos_.end()) {
2400             continue;
2401         }
2402 
2403         baseExtensionInfos_.erase(extensionItem);
2404     }
2405 
2406     // delete old extensionSkillInfos
2407     for (auto extensionSkillKey : oldModuleInfo.extensionSkillKeys) {
2408         auto extensionSkillItem = extensionSkillInfos_.find(extensionSkillKey);
2409         if (extensionSkillItem == extensionSkillInfos_.end()) {
2410             continue;
2411         }
2412 
2413         extensionSkillInfos_.erase(extensionSkillItem);
2414     }
2415 }
2416 
ToString() const2417 std::string InnerBundleInfo::ToString() const
2418 {
2419     nlohmann::json j;
2420     ToJson(j);
2421     return j.dump();
2422 }
2423 
GetApplicationInfo(int32_t flags,int32_t userId,ApplicationInfo & appInfo) const2424 void InnerBundleInfo::GetApplicationInfo(int32_t flags, int32_t userId, ApplicationInfo &appInfo) const
2425 {
2426     InnerBundleUserInfo innerBundleUserInfo;
2427     if (!GetInnerBundleUserInfo(userId, innerBundleUserInfo)) {
2428         APP_LOGE("can not find userId %{public}d when get applicationInfo", userId);
2429         return;
2430     }
2431 
2432     appInfo = *baseApplicationInfo_;
2433     if (appInfo.removable && !innerBundleUserInfo.isRemovable) {
2434         appInfo.removable = false;
2435     }
2436 
2437     appInfo.accessTokenId = innerBundleUserInfo.accessTokenId;
2438     appInfo.accessTokenIdEx = innerBundleUserInfo.accessTokenIdEx;
2439     appInfo.enabled = innerBundleUserInfo.bundleUserInfo.enabled;
2440     appInfo.uid = innerBundleUserInfo.uid;
2441 
2442     for (const auto &info : innerModuleInfos_) {
2443         bool deCompress = info.second.hapPath.empty();
2444         ModuleInfo moduleInfo;
2445         moduleInfo.moduleName = info.second.moduleName;
2446         if (deCompress) {
2447             moduleInfo.moduleSourceDir = info.second.modulePath;
2448             appInfo.moduleSourceDirs.emplace_back(info.second.modulePath);
2449         }
2450         moduleInfo.preloads = info.second.preloads;
2451         appInfo.moduleInfos.emplace_back(moduleInfo);
2452         if (deCompress && info.second.isEntry) {
2453             appInfo.entryDir = info.second.modulePath;
2454         }
2455         if ((static_cast<uint32_t>(flags) & GET_APPLICATION_INFO_WITH_PERMISSION) ==
2456             GET_APPLICATION_INFO_WITH_PERMISSION) {
2457             for (const auto &item : info.second.requestPermissions) {
2458                 appInfo.permissions.push_back(item.name);
2459             }
2460         }
2461         if ((static_cast<uint32_t>(flags) & GET_APPLICATION_INFO_WITH_METADATA) == GET_APPLICATION_INFO_WITH_METADATA) {
2462             bool isModuleJson = info.second.isModuleJson;
2463             if (!isModuleJson && info.second.metaData.customizeData.size() > 0) {
2464                 appInfo.metaData[info.second.moduleName] = info.second.metaData.customizeData;
2465             }
2466             if (isModuleJson && info.second.metadata.size() > 0) {
2467                 appInfo.metadata[info.second.moduleName] = info.second.metadata;
2468             }
2469         }
2470         if ((static_cast<uint32_t>(flags) & GET_APPLICATION_INFO_WITH_CERTIFICATE_FINGERPRINT) !=
2471             GET_APPLICATION_INFO_WITH_CERTIFICATE_FINGERPRINT) {
2472             appInfo.fingerprint.clear();
2473         }
2474     }
2475     if (!appInfo.permissions.empty()) {
2476         RemoveDuplicateName(appInfo.permissions);
2477     }
2478 }
2479 
GetApplicationInfoV9(int32_t flags,int32_t userId,ApplicationInfo & appInfo) const2480 ErrCode InnerBundleInfo::GetApplicationInfoV9(int32_t flags, int32_t userId, ApplicationInfo &appInfo) const
2481 {
2482     InnerBundleUserInfo innerBundleUserInfo;
2483     if (!GetInnerBundleUserInfo(userId, innerBundleUserInfo)) {
2484         APP_LOGE("can not find userId %{public}d when get applicationInfo", userId);
2485         return ERR_BUNDLE_MANAGER_INTERNAL_ERROR;
2486     }
2487 
2488     appInfo = *baseApplicationInfo_;
2489     if (appInfo.removable && !innerBundleUserInfo.isRemovable) {
2490         appInfo.removable = false;
2491     }
2492 
2493     appInfo.accessTokenId = innerBundleUserInfo.accessTokenId;
2494     appInfo.accessTokenIdEx = innerBundleUserInfo.accessTokenIdEx;
2495     appInfo.enabled = innerBundleUserInfo.bundleUserInfo.enabled;
2496     appInfo.uid = innerBundleUserInfo.uid;
2497 
2498     for (const auto &info : innerModuleInfos_) {
2499         bool deCompress = info.second.hapPath.empty();
2500         ModuleInfo moduleInfo;
2501         moduleInfo.moduleName = info.second.moduleName;
2502         if (deCompress) {
2503             moduleInfo.moduleSourceDir = info.second.modulePath;
2504             appInfo.moduleSourceDirs.emplace_back(info.second.modulePath);
2505         }
2506         moduleInfo.preloads = info.second.preloads;
2507         appInfo.moduleInfos.emplace_back(moduleInfo);
2508         if (deCompress && info.second.isEntry) {
2509             appInfo.entryDir = info.second.modulePath;
2510         }
2511         if ((static_cast<uint32_t>(flags) &
2512             static_cast<int32_t>(GetApplicationFlag::GET_APPLICATION_INFO_WITH_PERMISSION)) ==
2513             static_cast<int32_t>(GetApplicationFlag::GET_APPLICATION_INFO_WITH_PERMISSION)) {
2514             for (const auto &item : info.second.requestPermissions) {
2515                 appInfo.permissions.push_back(item.name);
2516             }
2517         }
2518         if ((static_cast<uint32_t>(flags) &
2519             static_cast<int32_t>(GetApplicationFlag::GET_APPLICATION_INFO_WITH_METADATA)) ==
2520             static_cast<int32_t>(GetApplicationFlag::GET_APPLICATION_INFO_WITH_METADATA)) {
2521             bool isModuleJson = info.second.isModuleJson;
2522             if (!isModuleJson && info.second.metaData.customizeData.size() > 0) {
2523                 appInfo.metaData[info.second.moduleName] = info.second.metaData.customizeData;
2524             }
2525             if (isModuleJson && info.second.metadata.size() > 0) {
2526                 appInfo.metadata[info.second.moduleName] = info.second.metadata;
2527             }
2528         }
2529     }
2530     if (!appInfo.permissions.empty()) {
2531         RemoveDuplicateName(appInfo.permissions);
2532     }
2533     return ERR_OK;
2534 }
2535 
GetBundleInfo(int32_t flags,BundleInfo & bundleInfo,int32_t userId) const2536 bool InnerBundleInfo::GetBundleInfo(int32_t flags, BundleInfo &bundleInfo, int32_t userId) const
2537 {
2538     InnerBundleUserInfo innerBundleUserInfo;
2539     if (!GetInnerBundleUserInfo(userId, innerBundleUserInfo)) {
2540         APP_LOGE("can not find userId %{public}d when GetBundleInfo bundleName:%{public}s",
2541             userId, GetBundleName().c_str());
2542         return false;
2543     }
2544 
2545     bundleInfo = *baseBundleInfo_;
2546 
2547     bundleInfo.uid = innerBundleUserInfo.uid;
2548     if (!innerBundleUserInfo.gids.empty()) {
2549         bundleInfo.gid = innerBundleUserInfo.gids[0];
2550     }
2551     bundleInfo.installTime = innerBundleUserInfo.installTime;
2552     bundleInfo.updateTime = innerBundleUserInfo.updateTime;
2553     bundleInfo.appIndex = appIndex_;
2554     bundleInfo.overlayType = overlayType_;
2555 
2556     GetApplicationInfo(ApplicationFlag::GET_APPLICATION_INFO_WITH_CERTIFICATE_FINGERPRINT, userId,
2557         bundleInfo.applicationInfo);
2558     for (const auto &info : innerModuleInfos_) {
2559         if ((static_cast<uint32_t>(flags) & GET_BUNDLE_WITH_REQUESTED_PERMISSION)
2560             == GET_BUNDLE_WITH_REQUESTED_PERMISSION) {
2561             for (const auto &item : info.second.requestPermissions) {
2562                 bundleInfo.reqPermissions.push_back(item.name);
2563             }
2564             for (const auto &item : info.second.definePermissions) {
2565                 bundleInfo.defPermissions.push_back(item.name);
2566             }
2567         }
2568         bundleInfo.hapModuleNames.emplace_back(info.second.modulePackage);
2569         auto hapmoduleinfo = FindHapModuleInfo(info.second.modulePackage, userId);
2570         if (hapmoduleinfo) {
2571             GetModuleWithHashValue(flags, info.second.modulePackage, *hapmoduleinfo);
2572             bundleInfo.hapModuleInfos.emplace_back(*hapmoduleinfo);
2573             bundleInfo.moduleNames.emplace_back(info.second.moduleName);
2574             bundleInfo.moduleDirs.emplace_back(info.second.modulePath);
2575             bundleInfo.modulePublicDirs.emplace_back(info.second.moduleDataDir);
2576             bundleInfo.moduleResPaths.emplace_back(info.second.moduleResPath);
2577         } else {
2578             APP_LOGE("can not find hapmoduleinfo %{public}s", info.second.moduleName.c_str());
2579         }
2580     }
2581     if ((static_cast<uint32_t>(flags) & GET_BUNDLE_WITH_REQUESTED_PERMISSION)
2582         == GET_BUNDLE_WITH_REQUESTED_PERMISSION) {
2583         if (!bundleInfo.reqPermissions.empty()) {
2584             RemoveDuplicateName(bundleInfo.reqPermissions);
2585         }
2586         if (!bundleInfo.defPermissions.empty()) {
2587             RemoveDuplicateName(bundleInfo.defPermissions);
2588         }
2589         if (!BundlePermissionMgr::GetRequestPermissionStates(bundleInfo,
2590             bundleInfo.applicationInfo.accessTokenId, bundleInfo.applicationInfo.deviceId)) {
2591             APP_LOGE("get request permission state failed");
2592         }
2593         bundleInfo.reqPermissionDetails = GetAllRequestPermissions();
2594     }
2595     GetBundleWithAbilities(flags, bundleInfo, userId);
2596     GetBundleWithExtension(flags, bundleInfo, userId);
2597     return true;
2598 }
2599 
GetBundleInfoV9(int32_t flags,BundleInfo & bundleInfo,int32_t userId) const2600 ErrCode InnerBundleInfo::GetBundleInfoV9(int32_t flags, BundleInfo &bundleInfo, int32_t userId) const
2601 {
2602     InnerBundleUserInfo innerBundleUserInfo;
2603     if (!GetInnerBundleUserInfo(userId, innerBundleUserInfo)) {
2604         APP_LOGE("can not find userId %{public}d when GetBundleInfo", userId);
2605         return ERR_BUNDLE_MANAGER_INTERNAL_ERROR;
2606     }
2607 
2608     bundleInfo = *baseBundleInfo_;
2609 
2610     bundleInfo.uid = innerBundleUserInfo.uid;
2611     if (!innerBundleUserInfo.gids.empty()) {
2612         bundleInfo.gid = innerBundleUserInfo.gids[0];
2613     }
2614     bundleInfo.installTime = innerBundleUserInfo.installTime;
2615     bundleInfo.updateTime = innerBundleUserInfo.updateTime;
2616     bundleInfo.appIndex = appIndex_;
2617 
2618     for (const auto &info : innerModuleInfos_) {
2619         bundleInfo.hapModuleNames.emplace_back(info.second.modulePackage);
2620         auto hapmoduleinfo = FindHapModuleInfo(info.second.modulePackage, userId);
2621         if (hapmoduleinfo) {
2622             bundleInfo.moduleNames.emplace_back(info.second.moduleName);
2623             bundleInfo.moduleDirs.emplace_back(info.second.modulePath);
2624             bundleInfo.modulePublicDirs.emplace_back(info.second.moduleDataDir);
2625             bundleInfo.moduleResPaths.emplace_back(info.second.moduleResPath);
2626         } else {
2627             APP_LOGE("can not find hapmoduleinfo %{public}s", info.second.moduleName.c_str());
2628         }
2629     }
2630     ProcessBundleFlags(flags, userId, bundleInfo);
2631     return ERR_OK;
2632 }
2633 
GetSharedBundleInfo(int32_t flags,BundleInfo & bundleInfo) const2634 bool InnerBundleInfo::GetSharedBundleInfo(int32_t flags, BundleInfo &bundleInfo) const
2635 {
2636     bundleInfo = *baseBundleInfo_;
2637     ProcessBundleWithHapModuleInfoFlag(flags, bundleInfo, Constants::ALL_USERID);
2638     bundleInfo.applicationInfo = *baseApplicationInfo_;
2639     return true;
2640 }
2641 
ProcessBundleFlags(int32_t flags,int32_t userId,BundleInfo & bundleInfo) const2642 void InnerBundleInfo::ProcessBundleFlags(
2643     int32_t flags, int32_t userId, BundleInfo &bundleInfo) const
2644 {
2645     if ((static_cast<uint32_t>(flags) & static_cast<int32_t>(GetBundleInfoFlag::GET_BUNDLE_INFO_WITH_APPLICATION))
2646         == static_cast<int32_t>(GetBundleInfoFlag::GET_BUNDLE_INFO_WITH_APPLICATION)) {
2647         if ((static_cast<uint32_t>(flags) & static_cast<int32_t>(GetBundleInfoFlag::GET_BUNDLE_INFO_WITH_METADATA))
2648             == static_cast<int32_t>(GetBundleInfoFlag::GET_BUNDLE_INFO_WITH_METADATA)) {
2649             GetApplicationInfoV9(static_cast<int32_t>(GetApplicationFlag::GET_APPLICATION_INFO_WITH_METADATA), userId,
2650                 bundleInfo.applicationInfo);
2651         } else {
2652             GetApplicationInfoV9(static_cast<int32_t>(GetApplicationFlag::GET_APPLICATION_INFO_DEFAULT), userId,
2653                 bundleInfo.applicationInfo);
2654         }
2655     }
2656     GetBundleWithReqPermissionsV9(flags, userId, bundleInfo);
2657     ProcessBundleWithHapModuleInfoFlag(flags, bundleInfo, userId);
2658     if ((static_cast<uint32_t>(flags) & static_cast<int32_t>(GetBundleInfoFlag::GET_BUNDLE_INFO_WITH_SIGNATURE_INFO))
2659         == static_cast<int32_t>(GetBundleInfoFlag::GET_BUNDLE_INFO_WITH_SIGNATURE_INFO)) {
2660         bundleInfo.signatureInfo.appId = baseBundleInfo_->appId;
2661         bundleInfo.signatureInfo.fingerprint = baseApplicationInfo_->fingerprint;
2662     }
2663 }
2664 
GetBundleWithReqPermissionsV9(int32_t flags,int32_t userId,BundleInfo & bundleInfo) const2665 void InnerBundleInfo::GetBundleWithReqPermissionsV9(int32_t flags, int32_t userId, BundleInfo &bundleInfo) const
2666 {
2667     if ((static_cast<uint32_t>(flags) &
2668         static_cast<int32_t>(GetBundleInfoFlag::GET_BUNDLE_INFO_WITH_REQUESTED_PERMISSION))
2669         != static_cast<int32_t>(GetBundleInfoFlag::GET_BUNDLE_INFO_WITH_REQUESTED_PERMISSION)) {
2670         return;
2671     }
2672     for (const auto &info : innerModuleInfos_) {
2673         for (const auto &item : info.second.requestPermissions) {
2674             bundleInfo.reqPermissions.push_back(item.name);
2675         }
2676         for (const auto &item : info.second.definePermissions) {
2677             bundleInfo.defPermissions.push_back(item.name);
2678         }
2679     }
2680     if (!bundleInfo.reqPermissions.empty()) {
2681         RemoveDuplicateName(bundleInfo.reqPermissions);
2682     }
2683     if (!bundleInfo.defPermissions.empty()) {
2684         RemoveDuplicateName(bundleInfo.defPermissions);
2685     }
2686     InnerBundleUserInfo innerBundleUserInfo;
2687     if (!GetInnerBundleUserInfo(userId, innerBundleUserInfo)) {
2688         APP_LOGE("can not find userId %{public}d when get applicationInfo", userId);
2689         return;
2690     }
2691     uint32_t tokenId = innerBundleUserInfo.accessTokenId;
2692     std::string deviceId = baseApplicationInfo_->deviceId;
2693     if (!BundlePermissionMgr::GetRequestPermissionStates(bundleInfo, tokenId, deviceId)) {
2694         APP_LOGE("get request permission state failed");
2695     }
2696     bundleInfo.reqPermissionDetails = GetAllRequestPermissions();
2697 }
2698 
GetModuleWithHashValue(int32_t flags,const std::string & modulePackage,HapModuleInfo & hapModuleInfo) const2699 void InnerBundleInfo::GetModuleWithHashValue(
2700     int32_t flags, const std::string &modulePackage, HapModuleInfo &hapModuleInfo) const
2701 {
2702     if (!(static_cast<uint32_t>(flags) & GET_BUNDLE_WITH_HASH_VALUE)) {
2703         return;
2704     }
2705 
2706     auto it = innerModuleInfos_.find(modulePackage);
2707     if (it == innerModuleInfos_.end()) {
2708         APP_LOGE("can not find module %{public}s", modulePackage.c_str());
2709         return;
2710     }
2711 
2712     hapModuleInfo.hashValue = it->second.hashValue;
2713 }
2714 
ProcessBundleWithHapModuleInfoFlag(int32_t flags,BundleInfo & bundleInfo,int32_t userId) const2715 void InnerBundleInfo::ProcessBundleWithHapModuleInfoFlag(int32_t flags, BundleInfo &bundleInfo, int32_t userId) const
2716 {
2717     if ((static_cast<uint32_t>(flags) & static_cast<int32_t>(GetBundleInfoFlag::GET_BUNDLE_INFO_WITH_HAP_MODULE))
2718         != static_cast<int32_t>(GetBundleInfoFlag::GET_BUNDLE_INFO_WITH_HAP_MODULE)) {
2719         bundleInfo.hapModuleInfos.clear();
2720         return;
2721     }
2722     for (const auto &info : innerModuleInfos_) {
2723         auto hapmoduleinfo = FindHapModuleInfo(info.second.modulePackage, userId);
2724         if (hapmoduleinfo) {
2725             HapModuleInfo hapModuleInfo = *hapmoduleinfo;
2726             auto it = innerModuleInfos_.find(info.second.modulePackage);
2727             if (it == innerModuleInfos_.end()) {
2728                 APP_LOGE("can not find module %{public}s", info.second.modulePackage.c_str());
2729             } else {
2730                 hapModuleInfo.hashValue = it->second.hashValue;
2731             }
2732             if (hapModuleInfo.hapPath.empty()) {
2733                 hapModuleInfo.moduleSourceDir = info.second.modulePath;
2734             }
2735             if ((static_cast<uint32_t>(flags) & static_cast<int32_t>(GetBundleInfoFlag::GET_BUNDLE_INFO_WITH_METADATA))
2736                 != static_cast<int32_t>(GetBundleInfoFlag::GET_BUNDLE_INFO_WITH_METADATA)) {
2737                 hapModuleInfo.metadata.clear();
2738             }
2739 
2740             GetBundleWithAbilitiesV9(flags, hapModuleInfo, userId);
2741             GetBundleWithExtensionAbilitiesV9(flags, hapModuleInfo);
2742             bundleInfo.hapModuleInfos.emplace_back(hapModuleInfo);
2743         }
2744     }
2745 }
2746 
GetBundleWithAbilitiesV9(int32_t flags,HapModuleInfo & hapModuleInfo,int32_t userId) const2747 void InnerBundleInfo::GetBundleWithAbilitiesV9(int32_t flags, HapModuleInfo &hapModuleInfo, int32_t userId) const
2748 {
2749     hapModuleInfo.abilityInfos.clear();
2750     if ((static_cast<uint32_t>(flags) & static_cast<int32_t>(GetBundleInfoFlag::GET_BUNDLE_INFO_WITH_ABILITY))
2751         != static_cast<int32_t>(GetBundleInfoFlag::GET_BUNDLE_INFO_WITH_ABILITY)) {
2752         return;
2753     }
2754     APP_LOGD("Get bundleInfo with abilities.");
2755     for (auto &ability : baseAbilityInfos_) {
2756         if ((ability.second.moduleName != hapModuleInfo.moduleName) ||
2757             (ability.second.name == Constants::APP_DETAIL_ABILITY)) {
2758             continue;
2759         }
2760         bool isEnabled = IsAbilityEnabled(ability.second, userId);
2761         if (!(static_cast<uint32_t>(flags) & static_cast<int32_t>(GetBundleInfoFlag::GET_BUNDLE_INFO_WITH_DISABLE))
2762             && !isEnabled) {
2763             APP_LOGW("%{public}s is disabled,", ability.second.name.c_str());
2764             continue;
2765         }
2766         AbilityInfo abilityInfo = ability.second;
2767         abilityInfo.enabled = isEnabled;
2768 
2769         if ((static_cast<uint32_t>(flags) & static_cast<int32_t>(GetBundleInfoFlag::GET_BUNDLE_INFO_WITH_METADATA))
2770             != static_cast<int32_t>(GetBundleInfoFlag::GET_BUNDLE_INFO_WITH_METADATA)) {
2771             abilityInfo.metaData.customizeData.clear();
2772             abilityInfo.metadata.clear();
2773         }
2774         hapModuleInfo.abilityInfos.emplace_back(abilityInfo);
2775     }
2776 }
2777 
GetBundleWithExtensionAbilitiesV9(int32_t flags,HapModuleInfo & hapModuleInfo) const2778 void InnerBundleInfo::GetBundleWithExtensionAbilitiesV9(int32_t flags, HapModuleInfo &hapModuleInfo) const
2779 {
2780     hapModuleInfo.extensionInfos.clear();
2781     if ((static_cast<uint32_t>(flags) &
2782         static_cast<int32_t>(GetBundleInfoFlag::GET_BUNDLE_INFO_WITH_EXTENSION_ABILITY))
2783         != static_cast<int32_t>(GetBundleInfoFlag::GET_BUNDLE_INFO_WITH_EXTENSION_ABILITY)) {
2784         return;
2785     }
2786     APP_LOGD("Get bundleInfo with extensionAbilities.");
2787     for (const auto &extensionInfo : baseExtensionInfos_) {
2788         if (extensionInfo.second.moduleName != hapModuleInfo.moduleName || !extensionInfo.second.enabled) {
2789             continue;
2790         }
2791         ExtensionAbilityInfo info = extensionInfo.second;
2792 
2793         if ((static_cast<uint32_t>(flags) & static_cast<int32_t>(GetBundleInfoFlag::GET_BUNDLE_INFO_WITH_METADATA))
2794             != static_cast<int32_t>(GetBundleInfoFlag::GET_BUNDLE_INFO_WITH_METADATA)) {
2795             info.metadata.clear();
2796         }
2797         hapModuleInfo.extensionInfos.emplace_back(info);
2798     }
2799 }
2800 
GetBundleWithAbilities(int32_t flags,BundleInfo & bundleInfo,int32_t userId) const2801 void InnerBundleInfo::GetBundleWithAbilities(int32_t flags, BundleInfo &bundleInfo, int32_t userId) const
2802 {
2803     APP_LOGD("bundleName:%{public}s userid:%{public}d", bundleInfo.name.c_str(), userId);
2804     if (static_cast<uint32_t>(flags) & GET_BUNDLE_WITH_ABILITIES) {
2805         for (auto &ability : baseAbilityInfos_) {
2806             if (ability.second.name == Constants::APP_DETAIL_ABILITY) {
2807                 continue;
2808             }
2809             bool isEnabled = IsAbilityEnabled(ability.second, userId);
2810             if (!(static_cast<uint32_t>(flags) & GET_ABILITY_INFO_WITH_DISABLE)
2811                 && !isEnabled) {
2812                 APP_LOGW("%{public}s is disabled,", ability.second.name.c_str());
2813                 continue;
2814             }
2815             AbilityInfo abilityInfo = ability.second;
2816             abilityInfo.enabled = isEnabled;
2817             bundleInfo.abilityInfos.emplace_back(abilityInfo);
2818         }
2819     }
2820 }
2821 
GetBundleWithExtension(int32_t flags,BundleInfo & bundleInfo,int32_t userId) const2822 void InnerBundleInfo::GetBundleWithExtension(int32_t flags, BundleInfo &bundleInfo, int32_t userId) const
2823 {
2824     APP_LOGD("get bundleInfo with extensionInfo begin");
2825     if ((static_cast<uint32_t>(flags) & GET_BUNDLE_WITH_EXTENSION_INFO) == GET_BUNDLE_WITH_EXTENSION_INFO) {
2826         for (const auto &extensionInfo : baseExtensionInfos_) {
2827             if (!extensionInfo.second.enabled) {
2828                 continue;
2829             }
2830             ExtensionAbilityInfo info = extensionInfo.second;
2831             bundleInfo.extensionInfos.emplace_back(info);
2832         }
2833     }
2834     APP_LOGD("get bundleInfo with extensionInfo end");
2835 }
2836 
CheckSpecialMetaData(const std::string & metaData) const2837 bool InnerBundleInfo::CheckSpecialMetaData(const std::string &metaData) const
2838 {
2839     if (isNewVersion_) {
2840         for (const auto &moduleInfo : innerModuleInfos_) {
2841             for (const auto &data : moduleInfo.second.metadata) {
2842                 if (metaData == data.name) {
2843                     return true;
2844                 }
2845             }
2846         }
2847         return false;
2848     }
2849     // old version
2850     for (const auto &moduleInfo : innerModuleInfos_) {
2851         for (const auto &data : moduleInfo.second.metaData.customizeData) {
2852             if (metaData == data.name) {
2853                 return true;
2854             }
2855         }
2856     }
2857     return false;
2858 }
2859 
GetFormsInfoByModule(const std::string & moduleName,std::vector<FormInfo> & formInfos) const2860 void InnerBundleInfo::GetFormsInfoByModule(const std::string &moduleName, std::vector<FormInfo> &formInfos) const
2861 {
2862     for (const auto &data : formInfos_) {
2863         for (auto &form : data.second) {
2864             if (form.moduleName == moduleName) {
2865                 formInfos.emplace_back(form);
2866             }
2867         }
2868     }
2869 }
2870 
GetFormsInfoByApp(std::vector<FormInfo> & formInfos) const2871 void InnerBundleInfo::GetFormsInfoByApp(std::vector<FormInfo> &formInfos) const
2872 {
2873     for (const auto &data : formInfos_) {
2874         std::copy(data.second.begin(), data.second.end(), std::back_inserter(formInfos));
2875     }
2876 }
2877 
GetShortcutInfos(std::vector<ShortcutInfo> & shortcutInfos) const2878 void InnerBundleInfo::GetShortcutInfos(std::vector<ShortcutInfo> &shortcutInfos) const
2879 {
2880     if (isNewVersion_) {
2881         AbilityInfo abilityInfo;
2882         GetMainAbilityInfo(abilityInfo);
2883         if ((!abilityInfo.resourcePath.empty() || !abilityInfo.hapPath.empty())
2884             && abilityInfo.metadata.size() > 0) {
2885             std::vector<std::string> rawJson;
2886             BundleMgrClient bundleMgrClient;
2887             bool ret = bundleMgrClient.GetResConfigFile(abilityInfo, META_DATA_SHORTCUTS_NAME, rawJson);
2888             if (!ret) {
2889                 APP_LOGD("GetResConfigFile return false");
2890                 return;
2891             }
2892             if (rawJson.size() == 0) {
2893                 APP_LOGD("rawJson size 0. skip.");
2894                 return;
2895             }
2896             nlohmann::json jsonObject = nlohmann::json::parse(rawJson[0], nullptr, false);
2897             if (jsonObject.is_discarded()) {
2898                 APP_LOGE("shortcuts json invalid");
2899                 return;
2900             }
2901             ShortcutJson shortcutJson = jsonObject.get<ShortcutJson>();
2902             for (const Shortcut &item : shortcutJson.shortcuts) {
2903                 ShortcutInfo shortcutInfo;
2904                 shortcutInfo.bundleName = abilityInfo.bundleName;
2905                 shortcutInfo.moduleName = abilityInfo.moduleName;
2906                 InnerProcessShortcut(item, shortcutInfo);
2907                 shortcutInfos.emplace_back(shortcutInfo);
2908             }
2909         }
2910         return;
2911     }
2912     for (const auto &shortcut : shortcutInfos_) {
2913         shortcutInfos.emplace_back(shortcut.second);
2914     }
2915 }
2916 
GetCommonEvents(const std::string & eventKey,std::vector<CommonEventInfo> & commonEvents) const2917 void InnerBundleInfo::GetCommonEvents(const std::string &eventKey, std::vector<CommonEventInfo> &commonEvents) const
2918 {
2919     CommonEventInfo item;
2920     for (const auto &commonEvent : commonEvents_) {
2921         for (const auto &event : commonEvent.second.events) {
2922             if (event == eventKey) {
2923                 item = commonEvent.second;
2924                 item.uid = GetUid(GetUserId());
2925                 commonEvents.emplace_back(item);
2926                 break;
2927             }
2928         }
2929     }
2930 }
2931 
GetInnerModuleInfoByModuleName(const std::string & moduleName) const2932 std::optional<InnerModuleInfo> InnerBundleInfo::GetInnerModuleInfoByModuleName(const std::string &moduleName) const
2933 {
2934     for (const auto &innerModuleInfo : innerModuleInfos_) {
2935         APP_LOGD("info.moduleName = %{public}s, moduleName= %{public}s",
2936             innerModuleInfo.second.moduleName.c_str(), moduleName.c_str());
2937         if (innerModuleInfo.second.moduleName == moduleName) {
2938             return innerModuleInfo.second;
2939         }
2940     }
2941     return std::nullopt;
2942 }
2943 
GetModuleNames(std::vector<std::string> & moduleNames) const2944 void InnerBundleInfo::GetModuleNames(std::vector<std::string> &moduleNames) const
2945 {
2946     for (const auto &innerModuleInfo : innerModuleInfos_) {
2947         moduleNames.emplace_back(innerModuleInfo.second.moduleName);
2948     }
2949 }
2950 
ResetBundleState(int32_t userId)2951 void InnerBundleInfo::ResetBundleState(int32_t userId)
2952 {
2953     if (userId == Constants::ALL_USERID) {
2954         for (auto& innerBundleUserInfo : innerBundleUserInfos_) {
2955             innerBundleUserInfo.second.bundleUserInfo.Reset();
2956         }
2957 
2958         return;
2959     }
2960 
2961     auto& key = NameAndUserIdToKey(GetBundleName(), userId);
2962     if (innerBundleUserInfos_.find(key) == innerBundleUserInfos_.end()) {
2963         APP_LOGD("no this user %{public}s", key.c_str());
2964         return;
2965     }
2966 
2967     innerBundleUserInfos_.at(key).bundleUserInfo.Reset();
2968 }
2969 
RemoveInnerBundleUserInfo(int32_t userId)2970 void InnerBundleInfo::RemoveInnerBundleUserInfo(int32_t userId)
2971 {
2972     auto& key = NameAndUserIdToKey(GetBundleName(), userId);
2973     auto infoItem = innerBundleUserInfos_.find(key);
2974     if (infoItem == innerBundleUserInfos_.end()) {
2975         return;
2976     }
2977 
2978     auto result = innerBundleUserInfos_.erase(key);
2979     if (result == 0) {
2980         APP_LOGE("remove userId:%{public}d key:%{public}s info failed", userId, key.c_str());
2981     }
2982     for (auto &innerModuleInfo : innerModuleInfos_) {
2983         DeleteModuleRemovable(innerModuleInfo.second.moduleName, userId);
2984     }
2985 }
2986 
AddInnerBundleUserInfo(const InnerBundleUserInfo & innerBundleUserInfo)2987 void InnerBundleInfo::AddInnerBundleUserInfo(
2988     const InnerBundleUserInfo& innerBundleUserInfo)
2989 {
2990     auto& key = NameAndUserIdToKey(
2991         GetBundleName(), innerBundleUserInfo.bundleUserInfo.userId);
2992     auto infoItem = innerBundleUserInfos_.find(key);
2993     if (infoItem == innerBundleUserInfos_.end()) {
2994         innerBundleUserInfos_.emplace(key, innerBundleUserInfo);
2995         return;
2996     }
2997 
2998     innerBundleUserInfos_[key] = innerBundleUserInfo;
2999 }
3000 
GetInnerBundleUserInfo(int32_t userId,InnerBundleUserInfo & innerBundleUserInfo) const3001 bool InnerBundleInfo::GetInnerBundleUserInfo(
3002     int32_t userId, InnerBundleUserInfo& innerBundleUserInfo) const
3003 {
3004     if (userId == Constants::NOT_EXIST_USERID) {
3005         return true;
3006     }
3007 
3008     if (userId == Constants::ALL_USERID) {
3009         if (innerBundleUserInfos_.empty()) {
3010             return false;
3011         }
3012 
3013         innerBundleUserInfo = innerBundleUserInfos_.begin()->second;
3014         return true;
3015     }
3016 
3017     auto& key = NameAndUserIdToKey(GetBundleName(), userId);
3018     auto infoItem = innerBundleUserInfos_.find(key);
3019     if (infoItem == innerBundleUserInfos_.end()) {
3020         return false;
3021     }
3022 
3023     innerBundleUserInfo = infoItem->second;
3024     return true;
3025 }
3026 
HasInnerBundleUserInfo(int32_t userId) const3027 bool InnerBundleInfo::HasInnerBundleUserInfo(int32_t userId) const
3028 {
3029     if (userId == Constants::ALL_USERID || userId == Constants::ANY_USERID) {
3030         return !innerBundleUserInfos_.empty();
3031     }
3032 
3033     auto& key = NameAndUserIdToKey(GetBundleName(), userId);
3034     auto infoItem = innerBundleUserInfos_.find(key);
3035     return infoItem != innerBundleUserInfos_.end();
3036 }
3037 
SetBundleInstallTime(const int64_t time,int32_t userId)3038 void InnerBundleInfo::SetBundleInstallTime(const int64_t time, int32_t userId)
3039 {
3040     auto& key = NameAndUserIdToKey(GetBundleName(), userId);
3041     auto infoItem = innerBundleUserInfos_.find(key);
3042     if (infoItem == innerBundleUserInfos_.end()) {
3043         return;
3044     }
3045 
3046     infoItem->second.installTime = time;
3047     infoItem->second.updateTime = time;
3048 }
3049 
SetAccessTokenId(uint32_t accessToken,const int32_t userId)3050 void InnerBundleInfo::SetAccessTokenId(uint32_t accessToken, const int32_t userId)
3051 {
3052     auto& key = NameAndUserIdToKey(GetBundleName(), userId);
3053     auto infoItem = innerBundleUserInfos_.find(key);
3054     if (infoItem == innerBundleUserInfos_.end()) {
3055         return;
3056     }
3057 
3058     infoItem->second.accessTokenId = accessToken;
3059 }
3060 
SetAccessTokenIdEx(const Security::AccessToken::AccessTokenIDEx accessTokenIdEx,const int32_t userId)3061 void InnerBundleInfo::SetAccessTokenIdEx(
3062     const Security::AccessToken::AccessTokenIDEx accessTokenIdEx,
3063     const int32_t userId)
3064 {
3065     auto& key = NameAndUserIdToKey(GetBundleName(), userId);
3066     auto infoItem = innerBundleUserInfos_.find(key);
3067     if (infoItem == innerBundleUserInfos_.end()) {
3068         return;
3069     }
3070 
3071     infoItem->second.accessTokenId = accessTokenIdEx.tokenIdExStruct.tokenID;
3072     infoItem->second.accessTokenIdEx = accessTokenIdEx.tokenIDEx;
3073 }
3074 
SetBundleUpdateTime(const int64_t time,int32_t userId)3075 void InnerBundleInfo::SetBundleUpdateTime(const int64_t time, int32_t userId)
3076 {
3077     auto& key = NameAndUserIdToKey(GetBundleName(), userId);
3078     auto infoItem = innerBundleUserInfos_.find(key);
3079     if (infoItem == innerBundleUserInfos_.end()) {
3080         return;
3081     }
3082 
3083     infoItem->second.updateTime = time;
3084 }
3085 
IsAbilityEnabled(const AbilityInfo & abilityInfo,int32_t userId) const3086 bool InnerBundleInfo::IsAbilityEnabled(const AbilityInfo &abilityInfo, int32_t userId) const
3087 {
3088     APP_LOGD("IsAbilityEnabled bundleName:%{public}s, userId:%{public}d", abilityInfo.bundleName.c_str(), userId);
3089     if (userId == Constants::NOT_EXIST_USERID) {
3090         return true;
3091     }
3092     auto& key = NameAndUserIdToKey(abilityInfo.bundleName, userId);
3093     auto infoItem = innerBundleUserInfos_.find(key);
3094     if (infoItem == innerBundleUserInfos_.end()) {
3095         APP_LOGE("innerBundleUserInfos find key:%{public}s, error", key.c_str());
3096         return false;
3097     }
3098     auto disabledAbilities = infoItem->second.bundleUserInfo.disabledAbilities;
3099     if (std::find(disabledAbilities.begin(), disabledAbilities.end(), abilityInfo.name) != disabledAbilities.end()) {
3100         return false;
3101     } else {
3102         return true;
3103     }
3104 }
3105 
SetOverlayModuleState(const std::string & moduleName,int32_t state,int32_t userId)3106 void InnerBundleInfo::SetOverlayModuleState(const std::string &moduleName, int32_t state, int32_t userId)
3107 {
3108     APP_LOGD("start to set overlay moduleInfo state of module %{public}s", moduleName.c_str());
3109     if (overlayType_ == NON_OVERLAY_TYPE) {
3110         APP_LOGW("no overlay module");
3111         return;
3112     }
3113     for (auto &innerUserInfo : innerBundleUserInfos_) {
3114         if (innerUserInfo.second.bundleUserInfo.userId != userId) {
3115             continue;
3116         }
3117 
3118         auto &overlayStates = innerUserInfo.second.bundleUserInfo.overlayModulesState;
3119         bool isSetSucc = std::any_of(overlayStates.begin(), overlayStates.end(), [&moduleName, &state](auto &item) {
3120             if (item.find(moduleName + Constants::FILE_UNDERLINE) != std::string::npos) {
3121                 item = moduleName + Constants::FILE_UNDERLINE + std::to_string(state);
3122                 return true;
3123             }
3124             return false;
3125         });
3126         if (!isSetSucc) {
3127             APP_LOGD("no overlay module state info under user %{public}d", userId);
3128             overlayStates.emplace_back(moduleName + Constants::FILE_UNDERLINE + std::to_string(state));
3129         }
3130     }
3131 }
3132 
SetOverlayModuleState(const std::string & moduleName,int32_t state)3133 void InnerBundleInfo::SetOverlayModuleState(const std::string &moduleName, int32_t state)
3134 {
3135     APP_LOGD("start to set overlay moduleInfo state of module %{public}s", moduleName.c_str());
3136     if (overlayType_ == NON_OVERLAY_TYPE) {
3137         APP_LOGW("no overlay module");
3138         return;
3139     }
3140     for (auto &innerUserInfo : innerBundleUserInfos_) {
3141         auto &overlayStates = innerUserInfo.second.bundleUserInfo.overlayModulesState;
3142         bool isSetSucc = std::any_of(overlayStates.begin(), overlayStates.end(), [&moduleName, &state](auto &item) {
3143             if (item.find(moduleName + Constants::FILE_UNDERLINE) != std::string::npos) {
3144                 item = moduleName + Constants::FILE_UNDERLINE + std::to_string(state);
3145                 return true;
3146             }
3147             return false;
3148         });
3149         if (!isSetSucc) {
3150             overlayStates.emplace_back(moduleName + Constants::FILE_UNDERLINE + std::to_string(state));
3151         }
3152     }
3153 }
3154 
GetOverlayModuleState(const std::string & moduleName,int32_t userId,int32_t & state) const3155 bool InnerBundleInfo::GetOverlayModuleState(const std::string &moduleName, int32_t userId, int32_t &state) const
3156 {
3157     APP_LOGD("start to get overlay state of moduleName:%{public}s, userId:%{public}d", moduleName.c_str(), userId);
3158     if (userId == Constants::NOT_EXIST_USERID) {
3159         APP_LOGE("invalid userId %{public}d", userId);
3160         return false;
3161     }
3162     auto& key = NameAndUserIdToKey(GetBundleName(), userId);
3163     auto infoItem = innerBundleUserInfos_.find(key);
3164     if (infoItem == innerBundleUserInfos_.end()) {
3165         APP_LOGE("no userInfo under userId %{public}d", userId);
3166         return false;
3167     }
3168 
3169     auto overlayModulesState = infoItem->second.bundleUserInfo.overlayModulesState;
3170     if (overlayModulesState.empty()) {
3171         APP_LOGE("no overlay module installed under userId %{public}d", userId);
3172         return false;
3173     }
3174     for (const auto &item : overlayModulesState) {
3175         auto pos = item.find(moduleName + Constants::FILE_UNDERLINE);
3176         if (pos == std::string::npos) {
3177             continue;
3178         }
3179         return OHOS::StrToInt(item.substr(moduleName.length() + 1), state);
3180     }
3181     APP_LOGE("no overlay module installed under userId %{public}d", userId);
3182     return false;
3183 }
3184 
ClearOverlayModuleStates(const std::string & moduleName)3185 void InnerBundleInfo::ClearOverlayModuleStates(const std::string &moduleName)
3186 {
3187     // delete overlay module state
3188     for (auto &innerUserInfo : innerBundleUserInfos_) {
3189         auto &overlayStates = innerUserInfo.second.bundleUserInfo.overlayModulesState;
3190         auto iter = std::find_if(overlayStates.begin(), overlayStates.end(), [&moduleName](const auto &item) {
3191             if (item.find(moduleName + Constants::FILE_UNDERLINE) != std::string::npos) {
3192                 return true;
3193             }
3194             return false;
3195         });
3196         if (iter != overlayStates.end()) {
3197             overlayStates.erase(iter);
3198         }
3199     }
3200 }
3201 
IsAbilityEnabledV9(const AbilityInfo & abilityInfo,int32_t userId,bool & isEnable) const3202 ErrCode InnerBundleInfo::IsAbilityEnabledV9(const AbilityInfo &abilityInfo, int32_t userId, bool &isEnable) const
3203 {
3204     APP_LOGD("IsAbilityEnabled bundleName:%{public}s, userId:%{public}d", abilityInfo.bundleName.c_str(), userId);
3205     if (userId == Constants::NOT_EXIST_USERID) {
3206         isEnable = true;
3207         return ERR_OK;
3208     }
3209     auto& key = NameAndUserIdToKey(abilityInfo.bundleName, userId);
3210     auto infoItem = innerBundleUserInfos_.find(key);
3211     if (infoItem == innerBundleUserInfos_.end()) {
3212         APP_LOGE("innerBundleUserInfos find key:%{public}s, error", key.c_str());
3213         return ERR_BUNDLE_MANAGER_BUNDLE_NOT_EXIST;
3214     }
3215     auto disabledAbilities = infoItem->second.bundleUserInfo.disabledAbilities;
3216     if (std::find(disabledAbilities.begin(), disabledAbilities.end(), abilityInfo.name) != disabledAbilities.end()) {
3217         isEnable = false;
3218     } else {
3219         isEnable = true;
3220     }
3221     return ERR_OK;
3222 }
3223 
SetAbilityEnabled(const std::string & moduleName,const std::string & abilityName,bool isEnabled,int32_t userId)3224 ErrCode InnerBundleInfo::SetAbilityEnabled(
3225     const std::string &moduleName, const std::string &abilityName, bool isEnabled, int32_t userId)
3226 {
3227     APP_LOGD("SetAbilityEnabled : %{public}s, %{public}s, %{public}d",
3228         moduleName.c_str(), abilityName.c_str(), userId);
3229     for (const auto &ability : baseAbilityInfos_) {
3230         if ((ability.second.name == abilityName) &&
3231             (moduleName.empty() || (ability.second.moduleName == moduleName))) {
3232             auto &key = NameAndUserIdToKey(GetBundleName(), userId);
3233             auto infoItem = innerBundleUserInfos_.find(key);
3234             if (infoItem == innerBundleUserInfos_.end()) {
3235                 APP_LOGE("SetAbilityEnabled find innerBundleUserInfo failed");
3236                 return ERR_BUNDLE_MANAGER_BUNDLE_NOT_EXIST;
3237             }
3238 
3239             auto iter = std::find(infoItem->second.bundleUserInfo.disabledAbilities.begin(),
3240                                   infoItem->second.bundleUserInfo.disabledAbilities.end(),
3241                                   abilityName);
3242             if (iter != infoItem->second.bundleUserInfo.disabledAbilities.end()) {
3243                 if (isEnabled) {
3244                     infoItem->second.bundleUserInfo.disabledAbilities.erase(iter);
3245                 }
3246             } else {
3247                 if (!isEnabled) {
3248                     infoItem->second.bundleUserInfo.disabledAbilities.push_back(abilityName);
3249                 }
3250             }
3251             return ERR_OK;
3252         }
3253     }
3254     APP_LOGE("SetAbilityEnabled find abilityInfo failed");
3255     return ERR_BUNDLE_MANAGER_ABILITY_NOT_EXIST;
3256 }
3257 
RemoveDuplicateName(std::vector<std::string> & name) const3258 void InnerBundleInfo::RemoveDuplicateName(std::vector<std::string> &name) const
3259 {
3260     std::sort(name.begin(), name.end());
3261     auto iter = std::unique(name.begin(), name.end());
3262     name.erase(iter, name.end());
3263 }
3264 
GetAllDefinePermissions() const3265 std::vector<DefinePermission> InnerBundleInfo::GetAllDefinePermissions() const
3266 {
3267     std::vector<DefinePermission> definePermissions;
3268     for (const auto &info : innerModuleInfos_) {
3269         std::transform(info.second.definePermissions.begin(),
3270             info.second.definePermissions.end(),
3271             std::back_inserter(definePermissions),
3272             [](const auto &p) { return p; });
3273     }
3274     if (!definePermissions.empty()) {
3275         std::sort(definePermissions.begin(), definePermissions.end(),
3276             [](DefinePermission defPermA, DefinePermission defPermB) {
3277                 return defPermA.name < defPermB.name;
3278             });
3279         auto iter = std::unique(definePermissions.begin(), definePermissions.end(),
3280             [](DefinePermission defPermA, DefinePermission defPermB) {
3281                 return defPermA.name == defPermB.name;
3282             });
3283         definePermissions.erase(iter, definePermissions.end());
3284     }
3285     return definePermissions;
3286 }
3287 
GetAllRequestPermissions() const3288 std::vector<RequestPermission> InnerBundleInfo::GetAllRequestPermissions() const
3289 {
3290     std::vector<RequestPermission> requestPermissions;
3291     for (const auto &info : innerModuleInfos_) {
3292         for (auto item : info.second.requestPermissions) {
3293             item.moduleName = info.second.moduleName;
3294             requestPermissions.push_back(item);
3295         }
3296     }
3297     if (!requestPermissions.empty()) {
3298         std::sort(requestPermissions.begin(), requestPermissions.end(),
3299             [](RequestPermission reqPermA, RequestPermission reqPermB) {
3300                 if (reqPermA.name == reqPermB.name) {
3301                     return reqPermA.reasonId > reqPermB.reasonId;
3302                 }
3303                 return reqPermA.name < reqPermB.name;
3304             });
3305         auto iter = std::unique(requestPermissions.begin(), requestPermissions.end(),
3306             [](RequestPermission reqPermA, RequestPermission reqPermB) {
3307                 return reqPermA.name == reqPermB.name;
3308             });
3309         requestPermissions.erase(iter, requestPermissions.end());
3310     }
3311     return requestPermissions;
3312 }
3313 
SetApplicationEnabled(bool enabled,int32_t userId)3314 ErrCode InnerBundleInfo::SetApplicationEnabled(bool enabled, int32_t userId)
3315 {
3316     auto& key = NameAndUserIdToKey(GetBundleName(), userId);
3317     auto infoItem = innerBundleUserInfos_.find(key);
3318     if (infoItem == innerBundleUserInfos_.end()) {
3319         APP_LOGE("SetApplicationEnabled can not find:%{public}s bundleUserInfo in userId: %{public}d",
3320             GetBundleName().c_str(), userId);
3321         return ERR_BUNDLE_MANAGER_BUNDLE_NOT_EXIST;
3322     }
3323 
3324     infoItem->second.bundleUserInfo.enabled = enabled;
3325     return ERR_OK;
3326 }
3327 
GetCurModuleName() const3328 const std::string &InnerBundleInfo::GetCurModuleName() const
3329 {
3330     if (innerModuleInfos_.find(currentPackage_) != innerModuleInfos_.end()) {
3331         return innerModuleInfos_.at(currentPackage_).moduleName;
3332     }
3333 
3334     return Constants::EMPTY_STRING;
3335 }
3336 
IsBundleRemovable() const3337 bool InnerBundleInfo::IsBundleRemovable() const
3338 {
3339     if (IsPreInstallApp()) {
3340         APP_LOGE("PreInstallApp should not be cleaned");
3341         return false;
3342     }
3343 
3344     for (const auto &innerModuleInfo : innerModuleInfos_) {
3345         if (!innerModuleInfo.second.installationFree) {
3346             return false;
3347         }
3348 
3349         for (const auto &stateIter : innerModuleInfo.second.isRemovable) {
3350             if (!stateIter.second) {
3351                 return false;
3352             }
3353         }
3354     }
3355 
3356     return true;
3357 }
3358 
GetLastInstallationTime() const3359 int64_t InnerBundleInfo::GetLastInstallationTime() const
3360 {
3361     int64_t installTime = 0;
3362     for (const auto &innerBundleUserInfo : innerBundleUserInfos_) {
3363         installTime = innerBundleUserInfo.second.updateTime > installTime ?
3364             innerBundleUserInfo.second.updateTime : installTime;
3365     }
3366 
3367     return installTime;
3368 }
3369 
GetRemovableModules(std::vector<std::string> & moduleToDelete) const3370 bool InnerBundleInfo::GetRemovableModules(std::vector<std::string> &moduleToDelete) const
3371 {
3372     for (const auto &innerModuleInfo : innerModuleInfos_) {
3373         if (!innerModuleInfo.second.installationFree) {
3374             continue;
3375         }
3376 
3377         bool canDelete = true;
3378         for (const auto &stateIter : innerModuleInfo.second.isRemovable) {
3379             if (!stateIter.second) {
3380                 canDelete = false;
3381                 break;
3382             }
3383         }
3384 
3385         if (canDelete) {
3386             moduleToDelete.emplace_back(innerModuleInfo.second.moduleName);
3387         }
3388     }
3389 
3390     return !moduleToDelete.empty();
3391 }
3392 
GetFreeInstallModules(std::vector<std::string> & freeInstallModule) const3393 bool InnerBundleInfo::GetFreeInstallModules(std::vector<std::string> &freeInstallModule) const
3394 {
3395     for (const auto &innerModuleInfo : innerModuleInfos_) {
3396         if (!innerModuleInfo.second.installationFree) {
3397             continue;
3398         }
3399 
3400         freeInstallModule.emplace_back(innerModuleInfo.second.moduleName);
3401     }
3402 
3403     return !freeInstallModule.empty();
3404 }
3405 
IsUserExistModule(const std::string & moduleName,int32_t userId) const3406 bool InnerBundleInfo::IsUserExistModule(const std::string &moduleName, int32_t userId) const
3407 {
3408     APP_LOGD("userId:%{public}d moduleName:%{public}s", userId, moduleName.c_str());
3409     auto modInfoItem = GetInnerModuleInfoByModuleName(moduleName);
3410     if (!modInfoItem) {
3411         APP_LOGE("get InnerModuleInfo by moduleName(%{public}s) failed", moduleName.c_str());
3412         return false;
3413     }
3414 
3415     auto item = modInfoItem->isRemovable.find(std::to_string(userId));
3416     if (item == modInfoItem->isRemovable.end()) {
3417         APP_LOGE("userId:%{public}d has not moduleName:%{public}s", userId, moduleName.c_str());
3418         return false;
3419     }
3420 
3421     APP_LOGD("userId:%{public}d exist moduleName:%{public}s", userId, moduleName.c_str());
3422     return true;
3423 }
3424 
IsModuleRemovable(const std::string & moduleName,int32_t userId,bool & isRemovable) const3425 ErrCode InnerBundleInfo::IsModuleRemovable(
3426     const std::string &moduleName, int32_t userId, bool &isRemovable) const
3427 {
3428     APP_LOGD("userId:%{public}d moduleName:%{public}s", userId, moduleName.c_str());
3429     auto modInfoItem = GetInnerModuleInfoByModuleName(moduleName);
3430     if (!modInfoItem) {
3431         APP_LOGE("get InnerModuleInfo by moduleName(%{public}s) failed", moduleName.c_str());
3432         return ERR_BUNDLE_MANAGER_MODULE_NOT_EXIST;
3433     }
3434 
3435     auto item = modInfoItem->isRemovable.find(std::to_string(userId));
3436     if (item == modInfoItem->isRemovable.end()) {
3437         APP_LOGW("userId:%{public}d has not moduleName:%{public}s", userId, moduleName.c_str());
3438         isRemovable = false;
3439         return ERR_OK;
3440     }
3441 
3442     isRemovable = item->second;
3443     APP_LOGD("userId:%{public}d, moduleName:%{public}s, isRemovable:%{public}d,",
3444         userId, moduleName.c_str(), isRemovable);
3445     return ERR_OK;
3446 }
3447 
AddModuleRemovableInfo(InnerModuleInfo & info,const std::string & stringUserId,bool isEnable) const3448 bool InnerBundleInfo::AddModuleRemovableInfo(
3449     InnerModuleInfo &info, const std::string &stringUserId, bool isEnable) const
3450 {
3451     auto item = info.isRemovable.find(stringUserId);
3452     if (item == info.isRemovable.end()) {
3453         auto result = info.isRemovable.try_emplace(stringUserId, isEnable);
3454         if (!result.second) {
3455             APP_LOGE("add userId:%{public}s isRemovable:%{public}d failed", stringUserId.c_str(), isEnable);
3456             return false;
3457         }
3458 
3459         APP_LOGD("add userId:%{public}s isRemovable:%{public}d into map", stringUserId.c_str(), isEnable);
3460         return true;
3461     }
3462 
3463     item->second = isEnable;
3464     APP_LOGD("set userId:%{public}s isEnable:%{public}d ok", stringUserId.c_str(), isEnable);
3465     return true;
3466 }
3467 
SetModuleRemovable(const std::string & moduleName,bool isEnable,int32_t userId)3468 bool InnerBundleInfo::SetModuleRemovable(const std::string &moduleName, bool isEnable, int32_t userId)
3469 {
3470     std::string stringUserId = std::to_string(userId);
3471     APP_LOGD("userId:%{public}d moduleName:%{public}s isEnable:%{public}d", userId, moduleName.c_str(), isEnable);
3472     for (auto &innerModuleInfo : innerModuleInfos_) {
3473         if (innerModuleInfo.second.moduleName == moduleName) {
3474             return AddModuleRemovableInfo(innerModuleInfo.second, stringUserId, isEnable);
3475         }
3476     }
3477 
3478     return false;
3479 }
3480 
DeleteModuleRemovableInfo(InnerModuleInfo & info,const std::string & stringUserId)3481 void InnerBundleInfo::DeleteModuleRemovableInfo(InnerModuleInfo &info, const std::string &stringUserId)
3482 {
3483     auto item = info.isRemovable.find(stringUserId);
3484     if (item == info.isRemovable.end()) {
3485         return;
3486     }
3487 
3488     info.isRemovable.erase(stringUserId);
3489 }
3490 
DeleteModuleRemovable(const std::string & moduleName,int32_t userId)3491 void InnerBundleInfo::DeleteModuleRemovable(const std::string &moduleName, int32_t userId)
3492 {
3493     std::string stringUserId = std::to_string(userId);
3494     APP_LOGD("userId:%{public}d moduleName:%{public}s", userId, moduleName.c_str());
3495     for (auto &innerModuleInfo : innerModuleInfos_) {
3496         if (innerModuleInfo.second.moduleName == moduleName) {
3497             DeleteModuleRemovableInfo(innerModuleInfo.second, stringUserId);
3498             return;
3499         }
3500     }
3501 }
3502 
SetModuleUpgradeFlag(std::string moduleName,int32_t upgradeFlag)3503 ErrCode InnerBundleInfo::SetModuleUpgradeFlag(std::string moduleName, int32_t upgradeFlag)
3504 {
3505     APP_LOGD("moduleName= %{public}s, upgradeFlag = %{public}d", moduleName.c_str(), upgradeFlag);
3506     for (auto &innerModuleInfo : innerModuleInfos_) {
3507         if (innerModuleInfo.second.moduleName == moduleName) {
3508             innerModuleInfo.second.upgradeFlag = upgradeFlag;
3509             return ERR_OK;
3510         }
3511     }
3512     return ERR_BUNDLE_MANAGER_MODULE_NOT_EXIST;
3513 }
3514 
GetModuleUpgradeFlag(std::string moduleName) const3515 int32_t InnerBundleInfo::GetModuleUpgradeFlag(std::string moduleName) const
3516 {
3517     auto moduleInfo = GetInnerModuleInfoByModuleName(moduleName);
3518     if (!moduleInfo) {
3519         APP_LOGE("get InnerModuleInfo by moduleName(%{public}s) failed", moduleName.c_str());
3520         return UpgradeFlag::NOT_UPGRADE;
3521     }
3522     APP_LOGD("innerModuleInfo.upgradeFlag : %{public}d", moduleInfo->upgradeFlag);
3523     return moduleInfo->upgradeFlag;
3524 }
3525 
GetResponseUserId(int32_t requestUserId) const3526 int32_t InnerBundleInfo::GetResponseUserId(int32_t requestUserId) const
3527 {
3528     if (innerBundleUserInfos_.empty()) {
3529         APP_LOGE("Get responseUserId failed due to user map is empty.");
3530         return Constants::INVALID_USERID;
3531     }
3532 
3533     if (requestUserId == Constants::ANY_USERID) {
3534         return innerBundleUserInfos_.begin()->second.bundleUserInfo.userId;
3535     }
3536 
3537     if (HasInnerBundleUserInfo(requestUserId)) {
3538         return requestUserId;
3539     }
3540 
3541     if (requestUserId < Constants::START_USERID) {
3542         APP_LOGD("requestUserId(%{public}d) less than start userId.", requestUserId);
3543         return Constants::INVALID_USERID;
3544     }
3545 
3546     int32_t responseUserId = Constants::INVALID_USERID;
3547     for (const auto &innerBundleUserInfo : innerBundleUserInfos_) {
3548         if (innerBundleUserInfo.second.bundleUserInfo.userId < Constants::START_USERID) {
3549             responseUserId = innerBundleUserInfo.second.bundleUserInfo.userId;
3550             break;
3551         }
3552     }
3553 
3554     APP_LOGD("requestUserId(%{public}d) and responseUserId(%{public}d).", requestUserId, responseUserId);
3555     return responseUserId;
3556 }
3557 
GetUriPrefixList(std::vector<std::string> & uriPrefixList,const std::string & excludeModule) const3558 void InnerBundleInfo::GetUriPrefixList(std::vector<std::string> &uriPrefixList,
3559     const std::string &excludeModule) const
3560 {
3561     std::vector<std::string> uriList;
3562     for (const auto &abilityInfoPair : baseAbilityInfos_) {
3563         if (abilityInfoPair.second.uri.empty()) {
3564             continue;
3565         }
3566         if (!excludeModule.empty() && abilityInfoPair.first.find(excludeModule) == 0) {
3567             continue;
3568         }
3569         uriList.emplace_back(abilityInfoPair.second.uri);
3570     }
3571     for (const auto &extensionInfoPair : baseExtensionInfos_) {
3572         if (extensionInfoPair.second.uri.empty()) {
3573             continue;
3574         }
3575         if (!excludeModule.empty() && extensionInfoPair.first.find(excludeModule) == 0) {
3576             continue;
3577         }
3578         uriList.emplace_back(extensionInfoPair.second.uri);
3579     }
3580     for (const std::string &uri : uriList) {
3581         size_t schemePos = uri.find(Constants::URI_SEPARATOR);
3582         if (schemePos == uri.npos) {
3583             continue;
3584         }
3585         size_t cutPos = uri.find(Constants::SEPARATOR, schemePos + Constants::URI_SEPARATOR_LEN);
3586         std::string uriPrefix;
3587         if (cutPos == uri.npos) {
3588             uriPrefix = uri;
3589         } else {
3590             uriPrefix = uri.substr(0, cutPos);
3591         }
3592         uriPrefixList.emplace_back(uriPrefix);
3593     }
3594 }
3595 
GetUriPrefixList(std::vector<std::string> & uriPrefixList,int32_t userId,const std::string & excludeModule) const3596 void InnerBundleInfo::GetUriPrefixList(std::vector<std::string> &uriPrefixList, int32_t userId,
3597     const std::string &excludeModule) const
3598 {
3599     auto& key = NameAndUserIdToKey(GetBundleName(), userId);
3600     auto infoItem = innerBundleUserInfos_.find(key);
3601     if (infoItem == innerBundleUserInfos_.end()) {
3602         return;
3603     }
3604     GetUriPrefixList(uriPrefixList, excludeModule);
3605 }
3606 
GetDependentModuleNames(const std::string & moduleName,std::vector<std::string> & dependentModuleNames) const3607 bool InnerBundleInfo::GetDependentModuleNames(const std::string &moduleName,
3608     std::vector<std::string> &dependentModuleNames) const
3609 {
3610     for (auto iter = innerModuleInfos_.begin(); iter != innerModuleInfos_.end(); ++iter) {
3611         if (iter->second.moduleName == moduleName) {
3612             for (const auto &dependency : iter->second.dependencies) {
3613                 dependentModuleNames.push_back(dependency.moduleName);
3614             }
3615             return true;
3616         }
3617     }
3618     APP_LOGE("GetDependentModuleNames can not find module %{public}s", moduleName.c_str());
3619     return false;
3620 }
3621 
GetAllDependentModuleNames(const std::string & moduleName,std::vector<std::string> & dependentModuleNames) const3622 bool InnerBundleInfo::GetAllDependentModuleNames(const std::string &moduleName,
3623     std::vector<std::string> &dependentModuleNames) const
3624 {
3625     if (!GetDependentModuleNames(moduleName, dependentModuleNames)) {
3626         return false;
3627     }
3628     std::deque<std::string> moduleDeque;
3629     std::copy(dependentModuleNames.begin(), dependentModuleNames.end(), std::back_inserter(moduleDeque));
3630     dependentModuleNames.clear();
3631     while (!moduleDeque.empty()) {
3632         std::string name = moduleDeque.front();
3633         moduleDeque.pop_front();
3634         if (std::find(dependentModuleNames.begin(), dependentModuleNames.end(), name) == dependentModuleNames.end()) {
3635             dependentModuleNames.push_back(name);
3636             std::vector<std::string> tempModuleNames;
3637             if (GetDependentModuleNames(name, tempModuleNames)) {
3638                 std::copy(tempModuleNames.begin(), tempModuleNames.end(), std::back_inserter(moduleDeque));
3639             }
3640         }
3641     }
3642     return true;
3643 }
3644 
GetMainAbility() const3645 std::string InnerBundleInfo::GetMainAbility() const
3646 {
3647     AbilityInfo abilityInfo;
3648     GetMainAbilityInfo(abilityInfo);
3649     return abilityInfo.name;
3650 }
3651 
GetMainAbilityInfo(AbilityInfo & abilityInfo) const3652 void InnerBundleInfo::GetMainAbilityInfo(AbilityInfo &abilityInfo) const
3653 {
3654     for (const auto& item : innerModuleInfos_) {
3655         const std::string& key = item.second.entryAbilityKey;
3656         if (!key.empty() && (baseAbilityInfos_.count(key) != 0)) {
3657             abilityInfo = baseAbilityInfos_.at(key);
3658             if (item.second.isEntry) {
3659                 return;
3660             }
3661         }
3662     }
3663 }
3664 
HasEntry() const3665 bool InnerBundleInfo::HasEntry() const
3666 {
3667     return std::any_of(innerModuleInfos_.begin(), innerModuleInfos_.end(), [](const auto &item) {
3668             return item.second.isEntry;
3669         });
3670 }
3671 
SetAppDistributionType(const std::string & appDistributionType)3672 void InnerBundleInfo::SetAppDistributionType(const std::string &appDistributionType)
3673 {
3674     baseApplicationInfo_->appDistributionType = appDistributionType;
3675 }
3676 
GetAppDistributionType() const3677 std::string InnerBundleInfo::GetAppDistributionType() const
3678 {
3679     return baseApplicationInfo_->appDistributionType;
3680 }
3681 
SetAppProvisionType(const std::string & appProvisionType)3682 void InnerBundleInfo::SetAppProvisionType(const std::string &appProvisionType)
3683 {
3684     baseApplicationInfo_->appProvisionType = appProvisionType;
3685 }
3686 
GetAppProvisionType() const3687 std::string InnerBundleInfo::GetAppProvisionType() const
3688 {
3689     return baseApplicationInfo_->appProvisionType;
3690 }
3691 
SetAppCrowdtestDeadline(int64_t crowdtestDeadline)3692 void InnerBundleInfo::SetAppCrowdtestDeadline(int64_t crowdtestDeadline)
3693 {
3694     baseApplicationInfo_->crowdtestDeadline = crowdtestDeadline;
3695 }
3696 
GetAppCrowdtestDeadline() const3697 int64_t InnerBundleInfo::GetAppCrowdtestDeadline() const
3698 {
3699     return baseApplicationInfo_->crowdtestDeadline;
3700 }
3701 
GetDistroModuleName() const3702 std::vector<std::string> InnerBundleInfo::GetDistroModuleName() const
3703 {
3704     std::vector<std::string> moduleVec;
3705     for (const auto &item : innerModuleInfos_) {
3706         moduleVec.push_back(item.second.moduleName);
3707     }
3708     return moduleVec;
3709 }
3710 
GetModuleNameByPackage(const std::string & packageName) const3711 std::string InnerBundleInfo::GetModuleNameByPackage(const std::string &packageName) const
3712 {
3713     auto it = innerModuleInfos_.find(packageName);
3714     if (it == innerModuleInfos_.end()) {
3715         return Constants::EMPTY_STRING;
3716     }
3717     return it->second.moduleName;
3718 }
3719 
GetModuleTypeByPackage(const std::string & packageName) const3720 std::string InnerBundleInfo::GetModuleTypeByPackage(const std::string &packageName) const
3721 {
3722     auto it = innerModuleInfos_.find(packageName);
3723     if (it == innerModuleInfos_.end()) {
3724         return Constants::EMPTY_STRING;
3725     }
3726     return it->second.distro.moduleType;
3727 }
3728 
GetAppQuickFix() const3729 AppQuickFix InnerBundleInfo::GetAppQuickFix() const
3730 {
3731     return baseApplicationInfo_->appQuickFix;
3732 }
3733 
SetAppQuickFix(const AppQuickFix & appQuickFix)3734 void InnerBundleInfo::SetAppQuickFix(const AppQuickFix &appQuickFix)
3735 {
3736     baseApplicationInfo_->appQuickFix = appQuickFix;
3737     if (appQuickFix.deployedAppqfInfo.hqfInfos.empty() && appQuickFix.deployingAppqfInfo.hqfInfos.empty()) {
3738         baseApplicationInfo_->appQuickFix.bundleName = Constants::EMPTY_STRING;
3739         baseApplicationInfo_->appQuickFix.versionCode = 0;
3740         baseApplicationInfo_->appQuickFix.versionName = Constants::EMPTY_STRING;
3741     }
3742     SetQuickFixHqfInfos(appQuickFix.deployedAppqfInfo.hqfInfos);
3743 }
3744 
GetQuickFixHqfInfos() const3745 std::vector<HqfInfo> InnerBundleInfo::GetQuickFixHqfInfos() const
3746 {
3747     return hqfInfos_;
3748 }
3749 
SetQuickFixHqfInfos(const std::vector<HqfInfo> & hqfInfos)3750 void InnerBundleInfo::SetQuickFixHqfInfos(const std::vector<HqfInfo> &hqfInfos)
3751 {
3752     hqfInfos_ = hqfInfos;
3753 }
3754 
FetchNativeSoAttrs(const std::string & requestPackage,std::string & cpuAbi,std::string & nativeLibraryPath) const3755 bool InnerBundleInfo::FetchNativeSoAttrs(
3756     const std::string &requestPackage, std::string &cpuAbi, std::string &nativeLibraryPath) const
3757 {
3758     auto moduleIter = innerModuleInfos_.find(requestPackage);
3759     if (moduleIter == innerModuleInfos_.end()) {
3760         APP_LOGE("requestPackage(%{public}s) is not exist", requestPackage.c_str());
3761         return false;
3762     }
3763 
3764     auto &moduleInfo = moduleIter->second;
3765     if (!moduleInfo.compressNativeLibs) {
3766         cpuAbi = moduleInfo.cpuAbi;
3767         nativeLibraryPath = moduleInfo.nativeLibraryPath;
3768         return !nativeLibraryPath.empty();
3769     }
3770 
3771     if (moduleInfo.isLibIsolated) {
3772         cpuAbi = moduleInfo.cpuAbi;
3773         nativeLibraryPath = moduleInfo.nativeLibraryPath;
3774     } else {
3775         cpuAbi = baseApplicationInfo_->cpuAbi;
3776         nativeLibraryPath = baseApplicationInfo_->nativeLibraryPath;
3777     }
3778 
3779     return !nativeLibraryPath.empty();
3780 }
3781 
IsLibIsolated(const std::string & moduleName) const3782 bool InnerBundleInfo::IsLibIsolated(const std::string &moduleName) const
3783 {
3784     auto moduleInfo = GetInnerModuleInfoByModuleName(moduleName);
3785     if (!moduleInfo) {
3786         APP_LOGE("Get moduleInfo(%{public}s) failed.", moduleName.c_str());
3787         return false;
3788     }
3789 
3790     return moduleInfo->isLibIsolated;
3791 }
3792 
GetDeviceType(const std::string & packageName) const3793 std::vector<std::string> InnerBundleInfo::GetDeviceType(const std::string &packageName) const
3794 {
3795     auto it = innerModuleInfos_.find(packageName);
3796     if (it == innerModuleInfos_.end()) {
3797         APP_LOGW("%{public}s is not existed", packageName.c_str());
3798         return std::vector<std::string>();
3799     }
3800     return innerModuleInfos_.at(packageName).deviceTypes;
3801 }
3802 
AddApplyQuickFixFrequency()3803 void InnerBundleInfo::AddApplyQuickFixFrequency()
3804 {
3805     ++applyQuickFixFrequency_;
3806 }
3807 
GetApplyQuickFixFrequency() const3808 int32_t InnerBundleInfo::GetApplyQuickFixFrequency() const
3809 {
3810     return applyQuickFixFrequency_;
3811 }
3812 
ResetApplyQuickFixFrequency()3813 void InnerBundleInfo::ResetApplyQuickFixFrequency()
3814 {
3815     applyQuickFixFrequency_ = 0;
3816 }
3817 
GetAllHspVersion() const3818 std::vector<uint32_t> InnerBundleInfo::GetAllHspVersion() const
3819 {
3820     std::vector<uint32_t> versionCodes;
3821     for (const auto &[moduleName, modules] : innerSharedModuleInfos_) {
3822         for (const auto &module : modules) {
3823             if (std::find(versionCodes.begin(), versionCodes.end(), module.versionCode) == versionCodes.end()) {
3824                 versionCodes.emplace_back(module.versionCode);
3825             }
3826         }
3827     }
3828     return versionCodes;
3829 }
3830 
DeleteHspModuleByVersion(int32_t versionCode)3831 void InnerBundleInfo::DeleteHspModuleByVersion(int32_t versionCode)
3832 {
3833     for (auto modulesIt = innerSharedModuleInfos_.begin(); modulesIt != innerSharedModuleInfos_.end();) {
3834         if (modulesIt->second.size() == SINGLE_HSP_VERSION &&
3835             modulesIt->second.front().versionCode == static_cast<uint32_t>(versionCode)) {
3836             modulesIt = innerSharedModuleInfos_.erase(modulesIt);
3837         } else {
3838             modulesIt->second.erase(
3839                 std::remove_if(modulesIt->second.begin(), modulesIt->second.end(),
3840                     [versionCode] (InnerModuleInfo &module) {
3841                         return module.versionCode == static_cast<uint32_t>(versionCode);
3842                     }));
3843             ++modulesIt;
3844         }
3845     }
3846 }
3847 
GetProxyDataInfos(const std::string & moduleName,std::vector<ProxyData> & proxyDatas) const3848 ErrCode InnerBundleInfo::GetProxyDataInfos(
3849     const std::string &moduleName, std::vector<ProxyData> &proxyDatas) const
3850 {
3851     if (moduleName == Constants::EMPTY_STRING) {
3852         GetAllProxyDataInfos(proxyDatas);
3853         return ERR_OK;
3854     }
3855     auto moduleIt = std::find_if(innerModuleInfos_.begin(), innerModuleInfos_.end(), [&moduleName](const auto &info) {
3856         return info.second.moduleName == moduleName;
3857     });
3858     if (moduleIt != innerModuleInfos_.end()) {
3859         proxyDatas.insert(
3860             proxyDatas.end(), moduleIt->second.proxyDatas.begin(), moduleIt->second.proxyDatas.end());
3861     } else {
3862         APP_LOGE("moduleName %{public}s not found", moduleName.c_str());
3863         return ERR_BUNDLE_MANAGER_MODULE_NOT_EXIST;
3864     }
3865     if (proxyDatas.empty()) {
3866         APP_LOGW("proxyDatas is empty");
3867     }
3868     return ERR_OK;
3869 }
3870 
GetAllProxyDataInfos(std::vector<ProxyData> & proxyDatas) const3871 void InnerBundleInfo::GetAllProxyDataInfos(std::vector<ProxyData> &proxyDatas) const
3872 {
3873     for (const auto &innerModuleInfo : innerModuleInfos_) {
3874         proxyDatas.insert(
3875             proxyDatas.end(), innerModuleInfo.second.proxyDatas.begin(), innerModuleInfo.second.proxyDatas.end());
3876     }
3877 }
3878 
GetIsolationMode(const std::string & isolationMode) const3879 IsolationMode InnerBundleInfo::GetIsolationMode(const std::string &isolationMode) const
3880 {
3881     auto isolationModeRes = ISOLATION_MODE_MAP.find(isolationMode);
3882     if (isolationModeRes != ISOLATION_MODE_MAP.end()) {
3883         return isolationModeRes->second;
3884     } else {
3885         return IsolationMode::NONISOLATION_FIRST;
3886     }
3887 }
3888 
SetModuleHapPath(const std::string & hapPath)3889 void InnerBundleInfo::SetModuleHapPath(const std::string &hapPath)
3890 {
3891     if (innerModuleInfos_.count(currentPackage_) == 1) {
3892         innerModuleInfos_.at(currentPackage_).hapPath = hapPath;
3893         for (auto &abilityInfo : baseAbilityInfos_) {
3894             abilityInfo.second.hapPath = hapPath;
3895         }
3896         for (auto &extensionInfo : baseExtensionInfos_) {
3897             extensionInfo.second.hapPath = hapPath;
3898         }
3899         if (!innerModuleInfos_.at(currentPackage_).compressNativeLibs &&
3900             !innerModuleInfos_.at(currentPackage_).nativeLibraryPath.empty()) {
3901             auto pos = hapPath.rfind(Constants::PATH_SEPARATOR);
3902             if (pos != std::string::npos) {
3903                 innerModuleInfos_.at(currentPackage_).nativeLibraryPath =
3904                     hapPath.substr(pos + 1, hapPath.length() - pos - 1) + NATIVE_LIBRARY_PATH_SYMBOL +
3905                     innerModuleInfos_.at(currentPackage_).nativeLibraryPath;
3906                 return;
3907             }
3908             innerModuleInfos_.at(currentPackage_).nativeLibraryPath =
3909                 hapPath + NATIVE_LIBRARY_PATH_SYMBOL + innerModuleInfos_.at(currentPackage_).nativeLibraryPath;
3910         }
3911     }
3912 }
3913 
IsCompressNativeLibs(const std::string & moduleName) const3914 bool InnerBundleInfo::IsCompressNativeLibs(const std::string &moduleName) const
3915 {
3916     auto moduleInfo = GetInnerModuleInfoByModuleName(moduleName);
3917     if (!moduleInfo) {
3918         APP_LOGE("Get moduleInfo(%{public}s) failed.", moduleName.c_str());
3919         return true; // compressNativeLibs default true
3920     }
3921 
3922     return moduleInfo->compressNativeLibs;
3923 }
3924 
SetNativeLibraryFileNames(const std::string & moduleName,const std::vector<std::string> & fileNames)3925 void InnerBundleInfo::SetNativeLibraryFileNames(const std::string &moduleName,
3926     const std::vector<std::string> &fileNames)
3927 {
3928     if (innerModuleInfos_.find(moduleName) == innerModuleInfos_.end()) {
3929         APP_LOGE("innerBundleInfo does not contain the module: %{public}s.", moduleName.c_str());
3930         return;
3931     }
3932     innerModuleInfos_.at(moduleName).nativeLibraryFileNames = fileNames;
3933 }
3934 
UpdateSharedModuleInfo()3935 void InnerBundleInfo::UpdateSharedModuleInfo()
3936 {
3937     auto sharedModuleInfoIter = innerSharedModuleInfos_.find(currentPackage_);
3938     auto moduleInfoIter = innerModuleInfos_.find(currentPackage_);
3939     if ((sharedModuleInfoIter == innerSharedModuleInfos_.end()) ||
3940         (moduleInfoIter == innerModuleInfos_.end())) {
3941         APP_LOGE("The shared module(%{public}s) infomation does not exist", currentPackage_.c_str());
3942         return;
3943     }
3944     auto &innerModuleInfoVector = sharedModuleInfoIter->second;
3945     for (auto iter = innerModuleInfoVector.begin(); iter != innerModuleInfoVector.end(); ++iter) {
3946         if (iter->versionCode == moduleInfoIter->second.versionCode) {
3947             iter->hapPath = moduleInfoIter->second.hapPath;
3948             iter->compressNativeLibs = moduleInfoIter->second.compressNativeLibs;
3949             iter->cpuAbi = moduleInfoIter->second.cpuAbi;
3950             iter->nativeLibraryPath = moduleInfoIter->second.nativeLibraryPath;
3951             iter->nativeLibraryFileNames = moduleInfoIter->second.nativeLibraryFileNames;
3952             return;
3953         }
3954     }
3955 }
3956 
SetExtName(const std::string & moduleName,const std::string & abilityName,const std::string extName)3957 ErrCode InnerBundleInfo::SetExtName(
3958     const std::string &moduleName, const std::string &abilityName, const std::string extName)
3959 {
3960     auto abilityInfoPair = baseAbilityInfos_.find(abilityName);
3961     if (abilityInfoPair == baseAbilityInfos_.end()) {
3962         APP_LOGE("ability %{public}s not exists", abilityName.c_str());
3963         return ERR_BUNDLE_MANAGER_ABILITY_NOT_EXIST;
3964     }
3965     if (moduleName != abilityInfoPair->second.moduleName) {
3966         APP_LOGE("module %{public}s not exists", moduleName.c_str());
3967         return ERR_BUNDLE_MANAGER_MODULE_NOT_EXIST;
3968     }
3969     auto &supportExtNames = abilityInfoPair->second.supportExtNames;
3970     bool duplicated = std::any_of(supportExtNames.begin(), supportExtNames.end(), [&extName](const auto &name) {
3971             return extName == name;
3972     });
3973     if (duplicated) {
3974         APP_LOGW("extName %{public}s already exist in ability %{public}s", extName.c_str(), abilityName.c_str());
3975         return ERR_BUNDLE_MANAGER_DUPLICATED_EXT_OR_TYPE;
3976     }
3977     supportExtNames.emplace_back(extName);
3978     return ERR_OK;
3979 }
3980 
SetMimeType(const std::string & moduleName,const std::string & abilityName,const std::string mimeType)3981 ErrCode InnerBundleInfo::SetMimeType(
3982     const std::string &moduleName, const std::string &abilityName, const std::string mimeType)
3983 {
3984     auto abilityInfoPair = baseAbilityInfos_.find(abilityName);
3985     if (abilityInfoPair == baseAbilityInfos_.end()) {
3986         APP_LOGE("ability %{public}s not exists", abilityName.c_str());
3987         return ERR_BUNDLE_MANAGER_ABILITY_NOT_EXIST;
3988     }
3989     if (moduleName != abilityInfoPair->second.moduleName) {
3990         APP_LOGE("module %{public}s not exists", moduleName.c_str());
3991         return ERR_BUNDLE_MANAGER_MODULE_NOT_EXIST;
3992     }
3993     auto &supportMimeTypes = abilityInfoPair->second.supportMimeTypes;
3994     bool duplicated = std::any_of(supportMimeTypes.begin(), supportMimeTypes.end(), [&mimeType](const auto &type) {
3995             return mimeType == type;
3996     });
3997     if (duplicated) {
3998         APP_LOGW("MIME type %{public}s already exist in ability %{public}s", mimeType.c_str(), abilityName.c_str());
3999         return ERR_BUNDLE_MANAGER_DUPLICATED_EXT_OR_TYPE;
4000     }
4001     abilityInfoPair->second.supportMimeTypes.emplace_back(mimeType);
4002     return ERR_OK;
4003 }
4004 
DelExtName(const std::string & moduleName,const std::string & abilityName,const std::string extName)4005 ErrCode InnerBundleInfo::DelExtName(
4006     const std::string &moduleName, const std::string &abilityName, const std::string extName)
4007 {
4008     auto abilityInfoPair = baseAbilityInfos_.find(abilityName);
4009     if (abilityInfoPair == baseAbilityInfos_.end()) {
4010         APP_LOGE("ability %{public}s not exists", abilityName.c_str());
4011         return ERR_BUNDLE_MANAGER_ABILITY_NOT_EXIST;
4012     }
4013     if (moduleName != abilityInfoPair->second.moduleName) {
4014         APP_LOGE("module %{public}s not exists", moduleName.c_str());
4015         return ERR_BUNDLE_MANAGER_MODULE_NOT_EXIST;
4016     }
4017     auto &supportExtNames = abilityInfoPair->second.supportExtNames;
4018     supportExtNames.erase(std::remove(supportExtNames.begin(), supportExtNames.end(), extName), supportExtNames.end());
4019     return ERR_OK;
4020 }
4021 
DelMimeType(const std::string & moduleName,const std::string & abilityName,const std::string mimeType)4022 ErrCode InnerBundleInfo::DelMimeType(
4023     const std::string &moduleName, const std::string &abilityName, const std::string mimeType)
4024 {
4025     auto abilityInfoPair = baseAbilityInfos_.find(abilityName);
4026     if (abilityInfoPair == baseAbilityInfos_.end()) {
4027         APP_LOGE("ability %{public}s not exists", abilityName.c_str());
4028         return ERR_BUNDLE_MANAGER_ABILITY_NOT_EXIST;
4029     }
4030     if (moduleName != abilityInfoPair->second.moduleName) {
4031         APP_LOGE("module %{public}s not exists", moduleName.c_str());
4032         return ERR_BUNDLE_MANAGER_MODULE_NOT_EXIST;
4033     }
4034     auto &supportMimeTypes = abilityInfoPair->second.supportMimeTypes;
4035     supportMimeTypes.erase(
4036         std::remove(supportMimeTypes.begin(), supportMimeTypes.end(), mimeType), supportMimeTypes.end());
4037     return ERR_OK;
4038 }
4039 
UpdateIsCompressNativeLibs()4040 void InnerBundleInfo::UpdateIsCompressNativeLibs()
4041 {
4042     if (innerModuleInfos_.empty()) {
4043         baseApplicationInfo_->isCompressNativeLibs = true;
4044         return;
4045     }
4046     baseApplicationInfo_->isCompressNativeLibs = false;
4047     for (const auto &info : innerModuleInfos_) {
4048         baseApplicationInfo_->isCompressNativeLibs =
4049             (baseApplicationInfo_->isCompressNativeLibs || info.second.compressNativeLibs) ? true : false;
4050     }
4051 }
4052 
SetResourcesApply(const std::vector<int32_t> & resourcesApply)4053 void InnerBundleInfo::SetResourcesApply(const std::vector<int32_t> &resourcesApply)
4054 {
4055     baseApplicationInfo_->resourcesApply = resourcesApply;
4056 }
4057 
InnerProcessShortcut(const Shortcut & oldShortcut,ShortcutInfo & shortcutInfo) const4058 void InnerBundleInfo::InnerProcessShortcut(const Shortcut &oldShortcut, ShortcutInfo &shortcutInfo) const
4059 {
4060     shortcutInfo.id = oldShortcut.shortcutId;
4061     shortcutInfo.icon = oldShortcut.icon;
4062     shortcutInfo.label = oldShortcut.label;
4063     shortcutInfo.iconId = oldShortcut.iconId;
4064     if (shortcutInfo.iconId == 0) {
4065         auto iter = oldShortcut.icon.find(PORT_SEPARATOR);
4066         if (iter != std::string::npos) {
4067             shortcutInfo.iconId = atoi(oldShortcut.icon.substr(iter + 1).c_str());
4068         }
4069     }
4070     shortcutInfo.labelId = oldShortcut.labelId;
4071     if (shortcutInfo.labelId == 0) {
4072         auto iter = oldShortcut.label.find(PORT_SEPARATOR);
4073         if (iter != std::string::npos) {
4074             shortcutInfo.labelId = atoi(oldShortcut.label.substr(iter + 1).c_str());
4075         }
4076     }
4077     for (const ShortcutWant &shortcutWant : oldShortcut.wants) {
4078         ShortcutIntent shortcutIntent;
4079         shortcutIntent.targetBundle = shortcutWant.bundleName;
4080         shortcutIntent.targetModule = shortcutWant.moduleName;
4081         shortcutIntent.targetClass = shortcutWant.abilityName;
4082         shortcutInfo.intents.emplace_back(shortcutIntent);
4083     }
4084 }
4085 
GetEntryModuleName() const4086 std::string InnerBundleInfo::GetEntryModuleName() const
4087 {
4088     for (const auto &item : innerModuleInfos_) {
4089         if (item.second.isEntry) {
4090             return item.second.modulePackage;
4091         }
4092     }
4093     return Constants::EMPTY_STRING;
4094 }
4095 }  // namespace AppExecFwk
4096 }  // namespace OHOS
4097