1 /*
2 * Copyright (c) 2021-2022 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
22 #ifdef BUNDLE_FRAMEWORK_APP_CONTROL
23 #include "app_control_constants.h"
24 #include "app_control_manager.h"
25 #endif
26 #include "bundle_mgr_client.h"
27 #include "bundle_permission_mgr.h"
28 #include "common_profile.h"
29 #include "distributed_module_info.h"
30 #include "distributed_ability_info.h"
31 #include "free_install_params.h"
32
33 namespace OHOS {
34 namespace AppExecFwk {
35 namespace {
36 const std::string APP_TYPE = "appType";
37 const std::string UID = "uid";
38 const std::string GID = "gid";
39 const std::string BASE_DATA_DIR = "baseDataDir";
40 const std::string BUNDLE_STATUS = "bundleStatus";
41 const std::string BASE_APPLICATION_INFO = "baseApplicationInfo";
42 const std::string BASE_BUNDLE_INFO = "baseBundleInfo";
43 const std::string BASE_ABILITY_INFO = "baseAbilityInfos";
44 const std::string INNER_MODULE_INFO = "innerModuleInfos";
45 const std::string SKILL_INFOS = "skillInfos";
46 const std::string USER_ID = "userId_";
47 const std::string APP_FEATURE = "appFeature";
48 const std::string CAN_UNINSTALL = "canUninstall";
49 const std::string NAME = "name";
50 const std::string MODULE_PACKAGE = "modulePackage";
51 const std::string MODULE_PATH = "modulePath";
52 const std::string MODULE_NAME = "moduleName";
53 const std::string MODULE_DESCRIPTION = "description";
54 const std::string MODULE_DESCRIPTION_ID = "descriptionId";
55 const std::string MODULE_ICON = "icon";
56 const std::string MODULE_ICON_ID = "iconId";
57 const std::string MODULE_LABEL = "label";
58 const std::string MODULE_LABEL_ID = "labelId";
59 const std::string MODULE_DESCRIPTION_INSTALLATION_FREE = "installationFree";
60 const std::string MODULE_IS_REMOVABLE = "isRemovable";
61 const std::string MODULE_UPGRADE_FLAG = "upgradeFlag";
62 const std::string MODULE_IS_ENTRY = "isEntry";
63 const std::string MODULE_METADATA = "metaData";
64 const std::string MODULE_COLOR_MODE = "colorMode";
65 const std::string MODULE_DISTRO = "distro";
66 const std::string MODULE_REQ_CAPABILITIES = "reqCapabilities";
67 const std::string MODULE_DATA_DIR = "moduleDataDir";
68 const std::string MODULE_RES_PATH = "moduleResPath";
69 const std::string MODULE_HAP_PATH = "hapPath";
70 const std::string MODULE_ABILITY_KEYS = "abilityKeys";
71 const std::string MODULE_SKILL_KEYS = "skillKeys";
72 const std::string MODULE_FORMS = "formInfos";
73 const std::string MODULE_SHORTCUT = "shortcutInfos";
74 const std::string MODULE_COMMON_EVENT = "commonEvents";
75 const std::string MODULE_MAIN_ABILITY = "mainAbility";
76 const std::string MODULE_ENTRY_ABILITY_KEY = "entryAbilityKey";
77 const std::string MODULE_DEPENDENCIES = "dependencies";
78 const std::string MODULE_IS_LIB_ISOLATED = "isLibIsolated";
79 const std::string MODULE_NATIVE_LIBRARY_PATH = "nativeLibraryPath";
80 const std::string MODULE_CPU_ABI = "cpuAbi";
81 const std::string NEW_BUNDLE_NAME = "newBundleName";
82 const std::string MODULE_SRC_PATH = "srcPath";
83 const std::string MODULE_HASH_VALUE = "hashValue";
84 const std::string SCHEME_SEPARATOR = "://";
85 const std::string PORT_SEPARATOR = ":";
86 const std::string PATH_SEPARATOR = "/";
87 const std::string PARAM_SEPARATOR = "?";
88 const std::string IS_PREINSTALL_APP = "isPreInstallApp";
89 const std::string INSTALL_MARK = "installMark";
90 const char WILDCARD = '*';
91 const std::string TYPE_WILDCARD = "*/*";
92 const std::string INNER_BUNDLE_USER_INFOS = "innerBundleUserInfos";
93 const std::string MODULE_PROCESS = "process";
94 const std::string MODULE_SRC_ENTRANCE = "srcEntrance";
95 const std::string MODULE_DEVICE_TYPES = "deviceTypes";
96 const std::string MODULE_VIRTUAL_MACHINE = "virtualMachine";
97 const std::string MODULE_UI_SYNTAX = "uiSyntax";
98 const std::string MODULE_PAGES = "pages";
99 const std::string MODULE_META_DATA = "metadata";
100 const std::string MODULE_REQUEST_PERMISSIONS = "requestPermissions";
101 const std::string MODULE_DEFINE_PERMISSIONS = "definePermissions";
102 const std::string MODULE_EXTENSION_KEYS = "extensionKeys";
103 const std::string MODULE_EXTENSION_SKILL_KEYS = "extensionSkillKeys";
104 const std::string MODULE_IS_MODULE_JSON = "isModuleJson";
105 const std::string MODULE_IS_STAGE_BASED_MODEL = "isStageBasedModel";
106 const std::string BUNDLE_IS_NEW_VERSION = "isNewVersion";
107 const std::string BUNDLE_IS_NEED_UPDATE = "upgradeFlag";
108 const std::string BUNDLE_BASE_EXTENSION_INFOS = "baseExtensionInfos";
109 const std::string BUNDLE_EXTENSION_SKILL_INFOS = "extensionSkillInfos";
110 const std::string BUNDLE_PACK_INFO = "bundlePackInfo";
111 const std::string ALLOWED_ACLS = "allowedAcls";
112 const std::string META_DATA_SHORTCUTS_NAME = "ohos.ability.shortcuts";
113 const std::string APP_INDEX = "appIndex";
114 const std::string BUNDLE_IS_SANDBOX_APP = "isSandboxApp";
115 const std::string BUNDLE_SANDBOX_PERSISTENT_INFO = "sandboxPersistentInfo";
116 const std::string DISPOSED_STATUS = "disposedStatus";
117 const std::string MODULE_COMPILE_MODE = "compileMode";
118 const std::string BUNDLE_HQF_INFOS = "hqfInfos";
119 const std::string MODULE_ATOMIC_SERVICE_MODULE_TYPE = "atomicServiceModuleType";
120 const std::string MODULE_PRELOADS = "preloads";
121 const std::string HAS_ATOMIC_SERVICE_CONFIG = "hasAtomicServiceConfig";
122 const std::string MAIN_ATOMIC_MODULE_NAME = "mainAtomicModuleName";
123
ConvertCompileMode(const std::string & compileMode)124 inline CompileMode ConvertCompileMode(const std::string& compileMode)
125 {
126 if (compileMode == Profile::COMPILE_MODE_ES_MODULE) {
127 return CompileMode::ES_MODULE;
128 } else {
129 return CompileMode::JS_BUNDLE;
130 }
131 }
132
NameAndUserIdToKey(const std::string & bundleName,int32_t userId)133 const std::string NameAndUserIdToKey(const std::string &bundleName, int32_t userId)
134 {
135 return bundleName + Constants::FILE_UNDERLINE + std::to_string(userId);
136 }
137 } // namespace
138
Match(const OHOS::AAFwk::Want & want) const139 bool Skill::Match(const OHOS::AAFwk::Want &want) const
140 {
141 bool matchAction = MatchAction(want.GetAction());
142 if (!matchAction) {
143 APP_LOGD("Action does not match");
144 return false;
145 }
146 bool matchEntities = MatchEntities(want.GetEntities());
147 if (!matchEntities) {
148 APP_LOGD("Entities does not match");
149 return false;
150 }
151 bool matchUriAndType = MatchUriAndType(want.GetUriString(), want.GetType());
152 if (!matchUriAndType) {
153 APP_LOGD("Uri or Type does not match");
154 return false;
155 }
156 return true;
157 }
158
MatchLauncher(const OHOS::AAFwk::Want & want) const159 bool Skill::MatchLauncher(const OHOS::AAFwk::Want &want) const
160 {
161 bool matchAction = MatchAction(want.GetAction());
162 if (!matchAction) {
163 APP_LOGD("Action does not match");
164 return false;
165 }
166 bool matchEntities = MatchEntities(want.GetEntities());
167 if (!matchEntities) {
168 APP_LOGD("Entities does not match");
169 return false;
170 }
171 return true;
172 }
173
MatchAction(const std::string & action) const174 bool Skill::MatchAction(const std::string &action) const
175 {
176 // config actions empty, no match
177 if (actions.empty()) {
178 return false;
179 }
180 // config actions not empty, param empty, match
181 if (action.empty()) {
182 return true;
183 }
184 auto actionMatcher = [action] (const std::string &configAction) {
185 if (action == configAction) {
186 return true;
187 }
188 if (action == Constants::ACTION_HOME && configAction == Constants::WANT_ACTION_HOME) {
189 return true;
190 }
191 if (action == Constants::WANT_ACTION_HOME && configAction == Constants::ACTION_HOME) {
192 return true;
193 }
194 return false;
195 };
196 // config actions not empty, param not empty, if config actions contains param action, match
197 return std::find_if(actions.cbegin(), actions.cend(), actionMatcher) != actions.cend();
198 }
199
MatchEntities(const std::vector<std::string> & paramEntities) const200 bool Skill::MatchEntities(const std::vector<std::string> ¶mEntities) const
201 {
202 // param entities empty, match
203 if (paramEntities.empty()) {
204 return true;
205 }
206 // config entities empty, param entities not empty, not match
207 if (entities.empty()) {
208 return false;
209 }
210 // config entities not empty, param entities not empty, if every param entity in config entities, match
211 std::vector<std::string>::size_type size = paramEntities.size();
212 for (std::vector<std::string>::size_type i = 0; i < size; i++) {
213 bool ret = std::find(entities.cbegin(), entities.cend(), paramEntities[i]) == entities.cend();
214 if (ret) {
215 return false;
216 }
217 }
218 return true;
219 }
220
MatchUriAndType(const std::string & uriString,const std::string & type) const221 bool Skill::MatchUriAndType(const std::string &uriString, const std::string &type) const
222 {
223 if (uriString.empty() && type.empty()) {
224 // case1 : param uri empty, param type empty
225 if (uris.empty()) {
226 return true;
227 }
228 for (const SkillUri &skillUri : uris) {
229 if (skillUri.scheme.empty() && skillUri.type.empty()) {
230 return true;
231 }
232 }
233 return false;
234 }
235 if (uris.empty()) {
236 return false;
237 }
238 if (!uriString.empty() && type.empty()) {
239 // case2 : param uri not empty, param type empty
240 for (const SkillUri &skillUri : uris) {
241 if (MatchUri(uriString, skillUri) && skillUri.type.empty()) {
242 return true;
243 }
244 }
245 return false;
246 } else if (uriString.empty() && !type.empty()) {
247 // case3 : param uri empty, param type not empty
248 for (const SkillUri &skillUri : uris) {
249 if (skillUri.scheme.empty() && MatchType(type, skillUri.type)) {
250 return true;
251 }
252 }
253 return false;
254 } else {
255 // case4 : param uri not empty, param type not empty
256 for (const SkillUri &skillUri : uris) {
257 if (MatchUri(uriString, skillUri) && MatchType(type, skillUri.type)) {
258 return true;
259 }
260 }
261 return false;
262 }
263 }
264
StartsWith(const std::string & sourceString,const std::string & targetPrefix) const265 bool Skill::StartsWith(const std::string &sourceString, const std::string &targetPrefix) const
266 {
267 return sourceString.rfind(targetPrefix, 0) == 0;
268 }
269
GetOptParamUri(const std::string & uriString) const270 std::string Skill::GetOptParamUri(const std::string &uriString) const
271 {
272 std::size_t pos = uriString.rfind(PARAM_SEPARATOR);
273 if (pos == std::string::npos) {
274 return uriString;
275 }
276 return uriString.substr(0, pos);
277 }
278
MatchUri(const std::string & uriString,const SkillUri & skillUri) const279 bool Skill::MatchUri(const std::string &uriString, const SkillUri &skillUri) const
280 {
281 if (skillUri.scheme.empty()) {
282 return uriString.empty();
283 }
284 if (skillUri.host.empty()) {
285 // config uri is : scheme
286 // belows are param uri matched conditions:
287 // 1.scheme
288 // 2.scheme:
289 // 3.scheme:/
290 // 4.scheme://
291 return uriString == skillUri.scheme || StartsWith(uriString, skillUri.scheme + PORT_SEPARATOR);
292 }
293 std::string optParamUri = GetOptParamUri(uriString);
294 std::string skillUriString;
295 skillUriString.append(skillUri.scheme).append(SCHEME_SEPARATOR).append(skillUri.host);
296 if (!skillUri.port.empty()) {
297 skillUriString.append(PORT_SEPARATOR).append(skillUri.port);
298 }
299 if (skillUri.path.empty() && skillUri.pathStartWith.empty() && skillUri.pathRegex.empty()) {
300 // with port, config uri is : scheme://host:port
301 // belows are param uri matched conditions:
302 // 1.scheme://host:port
303 // 2.scheme://host:port/path
304
305 // without port, config uri is : scheme://host
306 // belows are param uri matched conditions:
307 // 1.scheme://host
308 // 2.scheme://host/path
309 // 3.scheme://host:port scheme://host:port/path
310 bool ret = (optParamUri == skillUriString || StartsWith(optParamUri, skillUriString + PATH_SEPARATOR));
311 if (skillUri.port.empty()) {
312 ret = ret || StartsWith(optParamUri, skillUriString + PORT_SEPARATOR);
313 }
314 return ret;
315 }
316 skillUriString.append(PATH_SEPARATOR);
317 // if one of path, pathStartWith, pathRegex match, then match
318 if (!skillUri.path.empty()) {
319 // path match
320 std::string pathUri(skillUriString);
321 pathUri.append(skillUri.path);
322 if (optParamUri == pathUri) {
323 return true;
324 }
325 }
326 if (!skillUri.pathStartWith.empty()) {
327 // pathStartWith match
328 std::string pathStartWithUri(skillUriString);
329 pathStartWithUri.append(skillUri.pathStartWith);
330 if (StartsWith(optParamUri, pathStartWithUri)) {
331 return true;
332 }
333 }
334 if (!skillUri.pathRegex.empty()) {
335 // pathRegex match
336 std::string pathRegexUri(skillUriString);
337 pathRegexUri.append(skillUri.pathRegex);
338 try {
339 std::regex regex(pathRegexUri);
340 if (regex_match(optParamUri, regex)) {
341 return true;
342 }
343 } catch(...) {
344 APP_LOGE("regex error");
345 }
346 }
347 return false;
348 }
349
MatchType(const std::string & type,const std::string & skillUriType) const350 bool Skill::MatchType(const std::string &type, const std::string &skillUriType) const
351 {
352 // type is not empty
353 if (skillUriType.empty()) {
354 return false;
355 }
356 if (type == TYPE_WILDCARD || skillUriType == TYPE_WILDCARD) {
357 // param is */* or config is */*
358 return true;
359 }
360 bool paramTypeRegex = type.back() == WILDCARD;
361 if (paramTypeRegex) {
362 // param is string/*
363 std::string prefix = type.substr(0, type.length() - 1);
364 return skillUriType.find(prefix) == 0;
365 }
366 bool typeRegex = skillUriType.back() == WILDCARD;
367 if (typeRegex) {
368 // config is string/*
369 std::string prefix = skillUriType.substr(0, skillUriType.length() - 1);
370 return type.find(prefix) == 0;
371 } else {
372 return type == skillUriType;
373 }
374 }
375
InnerBundleInfo()376 InnerBundleInfo::InnerBundleInfo()
377 {
378 baseApplicationInfo_ = std::make_shared<ApplicationInfo>();
379 if (baseApplicationInfo_ == nullptr) {
380 APP_LOGE("baseApplicationInfo_ is nullptr, create failed");
381 }
382 baseBundleInfo_ = std::make_shared<BundleInfo>();
383 if (baseBundleInfo_ == nullptr) {
384 APP_LOGE("baseBundleInfo_ is nullptr, create failed");
385 }
386 APP_LOGD("inner bundle info instance is created");
387 }
388
operator =(const InnerBundleInfo & info)389 InnerBundleInfo &InnerBundleInfo::operator=(const InnerBundleInfo &info)
390 {
391 if (this == &info) {
392 return *this;
393 }
394 this->appType_ = info.appType_;
395 this->uid_ = info.uid_;
396 this->gid_ = info.gid_;
397 this->userId_ = info.userId_;
398 this->baseDataDir_ = info.baseDataDir_;
399 this->bundleStatus_ = info.bundleStatus_;
400 this->appFeature_ = info.appFeature_;
401 this->allowedAcls_ = info.allowedAcls_;
402 this->mark_ = info.mark_;
403 this->appIndex_ = info.appIndex_;
404 this->disposedStatus_ = info.disposedStatus_;
405 this->isSandboxApp_ = info.isSandboxApp_;
406 this->currentPackage_ = info.currentPackage_;
407 this->onlyCreateBundleUser_ = info.onlyCreateBundleUser_;
408 this->innerModuleInfos_ = info.innerModuleInfos_;
409 this->formInfos_ = info.formInfos_;
410 this->commonEvents_ = info.commonEvents_;
411 this->shortcutInfos_ = info.shortcutInfos_;
412 this->baseAbilityInfos_ = info.baseAbilityInfos_;
413 this->skillInfos_ = info.skillInfos_;
414 this->innerBundleUserInfos_ = info.innerBundleUserInfos_;
415 this->bundlePackInfo_ = info.bundlePackInfo_;
416 this->isNewVersion_ = info.isNewVersion_;
417 this->baseExtensionInfos_= info.baseExtensionInfos_;
418 this->extensionSkillInfos_ = info.extensionSkillInfos_;
419 this->sandboxPersistentInfo_ = info.sandboxPersistentInfo_;
420 this->baseApplicationInfo_ = std::make_shared<ApplicationInfo>();
421 if (this->baseApplicationInfo_ == nullptr) {
422 APP_LOGE("baseApplicationInfo_ is nullptr, create failed");
423 } else {
424 *(this->baseApplicationInfo_) = *(info.baseApplicationInfo_);
425 }
426 this->baseBundleInfo_ = std::make_shared<BundleInfo>();
427 if (this->baseBundleInfo_ == nullptr) {
428 APP_LOGE("baseBundleInfo_ is nullptr, create failed");
429 } else {
430 *(this->baseBundleInfo_) = *(info.baseBundleInfo_);
431 }
432 this->hqfInfos_ = info.hqfInfos_;
433
434 this->hasAtomicServiceConfig_ = info.hasAtomicServiceConfig_;
435 this->mainAtomicModuleName_ = info.mainAtomicModuleName_;
436 this->provisionMetadatas_ = info.provisionMetadatas_;
437 return *this;
438 }
439
~InnerBundleInfo()440 InnerBundleInfo::~InnerBundleInfo()
441 {
442 APP_LOGD("inner bundle info instance is destroyed");
443 }
444
to_json(nlohmann::json & jsonObject,const Distro & distro)445 void to_json(nlohmann::json &jsonObject, const Distro &distro)
446 {
447 jsonObject = nlohmann::json {
448 {ProfileReader::BUNDLE_MODULE_PROFILE_KEY_DELIVERY_WITH_INSTALL, distro.deliveryWithInstall},
449 {ProfileReader::BUNDLE_MODULE_PROFILE_KEY_MODULE_NAME, distro.moduleName},
450 {ProfileReader::BUNDLE_MODULE_PROFILE_KEY_MODULE_TYPE, distro.moduleType},
451 {ProfileReader::BUNDLE_MODULE_PROFILE_KEY_MODULE_INSTALLATION_FREE, distro.installationFree}
452 };
453 }
454
to_json(nlohmann::json & jsonObject,const DefinePermission & definePermission)455 void to_json(nlohmann::json &jsonObject, const DefinePermission &definePermission)
456 {
457 jsonObject = nlohmann::json {
458 {Profile::DEFINEPERMISSION_NAME, definePermission.name},
459 {Profile::DEFINEPERMISSION_GRANT_MODE, definePermission.grantMode},
460 {Profile::DEFINEPERMISSION_AVAILABLE_LEVEL, definePermission.availableLevel},
461 {Profile::DEFINEPERMISSION_PROVISION_ENABLE, definePermission.provisionEnable},
462 {Profile::DEFINEPERMISSION_DISTRIBUTED_SCENE_ENABLE, definePermission.distributedSceneEnable},
463 {Profile::LABEL, definePermission.label},
464 {Profile::LABEL_ID, definePermission.labelId},
465 {Profile::DESCRIPTION, definePermission.description},
466 {Profile::DESCRIPTION_ID, definePermission.descriptionId}
467 };
468 }
469
to_json(nlohmann::json & jsonObject,const Dependency & dependency)470 void to_json(nlohmann::json &jsonObject, const Dependency &dependency)
471 {
472 jsonObject = nlohmann::json {
473 {Profile::DEPENDENCIES_MODULE_NAME, dependency.moduleName},
474 {Profile::DEPENDENCIES_BUNDLE_NAME, dependency.bundleName}
475 };
476 }
477
to_json(nlohmann::json & jsonObject,const InnerModuleInfo & info)478 void to_json(nlohmann::json &jsonObject, const InnerModuleInfo &info)
479 {
480 jsonObject = nlohmann::json {
481 {NAME, info.name},
482 {MODULE_PACKAGE, info.modulePackage},
483 {MODULE_NAME, info.moduleName},
484 {MODULE_PATH, info.modulePath},
485 {MODULE_DATA_DIR, info.moduleDataDir},
486 {MODULE_RES_PATH, info.moduleResPath},
487 {MODULE_IS_ENTRY, info.isEntry},
488 {MODULE_METADATA, info.metaData},
489 {MODULE_COLOR_MODE, info.colorMode},
490 {MODULE_DISTRO, info.distro},
491 {MODULE_DESCRIPTION, info.description},
492 {MODULE_DESCRIPTION_ID, info.descriptionId},
493 {MODULE_ICON, info.icon},
494 {MODULE_ICON_ID, info.iconId},
495 {MODULE_LABEL, info.label},
496 {MODULE_LABEL_ID, info.labelId},
497 {MODULE_DESCRIPTION_INSTALLATION_FREE, info.installationFree},
498 {MODULE_IS_REMOVABLE, info.isRemovable},
499 {MODULE_UPGRADE_FLAG, info.upgradeFlag},
500 {MODULE_REQ_CAPABILITIES, info.reqCapabilities},
501 {MODULE_ABILITY_KEYS, info.abilityKeys},
502 {MODULE_SKILL_KEYS, info.skillKeys},
503 {MODULE_MAIN_ABILITY, info.mainAbility},
504 {MODULE_ENTRY_ABILITY_KEY, info.entryAbilityKey},
505 {MODULE_SRC_PATH, info.srcPath},
506 {MODULE_HASH_VALUE, info.hashValue},
507 {MODULE_PROCESS, info.process},
508 {MODULE_SRC_ENTRANCE, info.srcEntrance},
509 {MODULE_DEVICE_TYPES, info.deviceTypes},
510 {MODULE_VIRTUAL_MACHINE, info.virtualMachine},
511 {MODULE_UI_SYNTAX, info.uiSyntax},
512 {MODULE_PAGES, info.pages},
513 {MODULE_META_DATA, info.metadata},
514 {MODULE_REQUEST_PERMISSIONS, info.requestPermissions},
515 {MODULE_DEFINE_PERMISSIONS, info.definePermissions},
516 {MODULE_EXTENSION_KEYS, info.extensionKeys},
517 {MODULE_EXTENSION_SKILL_KEYS, info.extensionSkillKeys},
518 {MODULE_IS_MODULE_JSON, info.isModuleJson},
519 {MODULE_IS_STAGE_BASED_MODEL, info.isStageBasedModel},
520 {MODULE_DEPENDENCIES, info.dependencies},
521 {MODULE_IS_LIB_ISOLATED, info.isLibIsolated},
522 {MODULE_NATIVE_LIBRARY_PATH, info.nativeLibraryPath},
523 {MODULE_CPU_ABI, info.cpuAbi},
524 {MODULE_HAP_PATH, info.hapPath},
525 {MODULE_COMPILE_MODE, info.compileMode},
526 {MODULE_ATOMIC_SERVICE_MODULE_TYPE, info.atomicServiceModuleType},
527 {MODULE_PRELOADS, info.preloads}
528 };
529 }
530
to_json(nlohmann::json & jsonObject,const SkillUri & uri)531 void to_json(nlohmann::json &jsonObject, const SkillUri &uri)
532 {
533 jsonObject = nlohmann::json {
534 {ProfileReader::BUNDLE_MODULE_PROFILE_KEY_SCHEME, uri.scheme},
535 {ProfileReader::BUNDLE_MODULE_PROFILE_KEY_HOST, uri.host},
536 {ProfileReader::BUNDLE_MODULE_PROFILE_KEY_PORT, uri.port},
537 {ProfileReader::BUNDLE_MODULE_PROFILE_KEY_PATH, uri.path},
538 {ProfileReader::BUNDLE_MODULE_PROFILE_KEY_PATHSTARTWITH, uri.pathStartWith},
539 {ProfileReader::BUNDLE_MODULE_PROFILE_KEY_PATHREGEX, uri.pathRegex},
540 {ProfileReader::BUNDLE_MODULE_PROFILE_KEY_TYPE, uri.type}
541 };
542 }
543
to_json(nlohmann::json & jsonObject,const Skill & skill)544 void to_json(nlohmann::json &jsonObject, const Skill &skill)
545 {
546 jsonObject = nlohmann::json {
547 {ProfileReader::BUNDLE_MODULE_PROFILE_KEY_ACTIONS, skill.actions},
548 {ProfileReader::BUNDLE_MODULE_PROFILE_KEY_ENTITIES, skill.entities},
549 {ProfileReader::BUNDLE_MODULE_PROFILE_KEY_URIS, skill.uris}
550 };
551 }
552
to_json(nlohmann::json & jsonObject,const InstallMark & installMark)553 void to_json(nlohmann::json &jsonObject, const InstallMark &installMark)
554 {
555 jsonObject = nlohmann::json {
556 {ProfileReader::BUNDLE_INSTALL_MARK_BUNDLE, installMark.bundleName},
557 {ProfileReader::BUNDLE_INSTALL_MARK_PACKAGE, installMark.packageName},
558 {ProfileReader::BUNDLE_INSTALL_MARK_STATUS, installMark.status}
559 };
560 }
561
to_json(nlohmann::json & jsonObject,const SandboxAppPersistentInfo & sandboxPersistentInfo)562 void to_json(nlohmann::json &jsonObject, const SandboxAppPersistentInfo &sandboxPersistentInfo)
563 {
564 jsonObject = nlohmann::json {
565 {ProfileReader::BUNDLE_SANDBOX_PERSISTENT_ACCESS_TOKEN_ID, sandboxPersistentInfo.accessTokenId},
566 {ProfileReader::BUNDLE_SANDBOX_PERSISTENT_APP_INDEX, sandboxPersistentInfo.appIndex},
567 {ProfileReader::BUNDLE_SANDBOX_PERSISTENT_USER_ID, sandboxPersistentInfo.userId}
568 };
569 }
570
ToJson(nlohmann::json & jsonObject) const571 void InnerBundleInfo::ToJson(nlohmann::json &jsonObject) const
572 {
573 jsonObject[APP_TYPE] = appType_;
574 jsonObject[BASE_DATA_DIR] = baseDataDir_;
575 jsonObject[BUNDLE_STATUS] = bundleStatus_;
576 jsonObject[ALLOWED_ACLS] = allowedAcls_;
577 jsonObject[BASE_APPLICATION_INFO] = *baseApplicationInfo_;
578 jsonObject[BASE_BUNDLE_INFO] = *baseBundleInfo_;
579 jsonObject[BASE_ABILITY_INFO] = baseAbilityInfos_;
580 jsonObject[INNER_MODULE_INFO] = innerModuleInfos_;
581 jsonObject[SKILL_INFOS] = skillInfos_;
582 jsonObject[USER_ID] = userId_;
583 jsonObject[APP_FEATURE] = appFeature_;
584 jsonObject[MODULE_FORMS] = formInfos_;
585 jsonObject[MODULE_SHORTCUT] = shortcutInfos_;
586 jsonObject[MODULE_COMMON_EVENT] = commonEvents_;
587 jsonObject[INSTALL_MARK] = mark_;
588 jsonObject[INNER_BUNDLE_USER_INFOS] = innerBundleUserInfos_;
589 jsonObject[BUNDLE_IS_NEW_VERSION] = isNewVersion_;
590 jsonObject[BUNDLE_BASE_EXTENSION_INFOS] = baseExtensionInfos_;
591 jsonObject[BUNDLE_EXTENSION_SKILL_INFOS] = extensionSkillInfos_;
592 jsonObject[BUNDLE_PACK_INFO] = bundlePackInfo_;
593 jsonObject[APP_INDEX] = appIndex_;
594 jsonObject[BUNDLE_IS_SANDBOX_APP] = isSandboxApp_;
595 jsonObject[BUNDLE_SANDBOX_PERSISTENT_INFO] = sandboxPersistentInfo_;
596 jsonObject[DISPOSED_STATUS] = disposedStatus_;
597 jsonObject[BUNDLE_HQF_INFOS] = hqfInfos_;
598 jsonObject[HAS_ATOMIC_SERVICE_CONFIG] = hasAtomicServiceConfig_;
599 jsonObject[MAIN_ATOMIC_MODULE_NAME] = mainAtomicModuleName_;
600 }
601
from_json(const nlohmann::json & jsonObject,InnerModuleInfo & info)602 void from_json(const nlohmann::json &jsonObject, InnerModuleInfo &info)
603 {
604 // these are not required fields.
605 const auto &jsonObjectEnd = jsonObject.end();
606 GetValueIfFindKey<std::string>(jsonObject,
607 jsonObjectEnd,
608 NAME,
609 info.name,
610 JsonType::STRING,
611 false,
612 ProfileReader::parseResult,
613 ArrayType::NOT_ARRAY);
614 GetValueIfFindKey<std::string>(jsonObject,
615 jsonObjectEnd,
616 MODULE_PACKAGE,
617 info.modulePackage,
618 JsonType::STRING,
619 false,
620 ProfileReader::parseResult,
621 ArrayType::NOT_ARRAY);
622 GetValueIfFindKey<std::string>(jsonObject,
623 jsonObjectEnd,
624 MODULE_NAME,
625 info.moduleName,
626 JsonType::STRING,
627 false,
628 ProfileReader::parseResult,
629 ArrayType::NOT_ARRAY);
630 GetValueIfFindKey<std::string>(jsonObject,
631 jsonObjectEnd,
632 MODULE_PATH,
633 info.modulePath,
634 JsonType::STRING,
635 false,
636 ProfileReader::parseResult,
637 ArrayType::NOT_ARRAY);
638 GetValueIfFindKey<std::string>(jsonObject,
639 jsonObjectEnd,
640 MODULE_DATA_DIR,
641 info.moduleDataDir,
642 JsonType::STRING,
643 false,
644 ProfileReader::parseResult,
645 ArrayType::NOT_ARRAY);
646 GetValueIfFindKey<std::string>(jsonObject,
647 jsonObjectEnd,
648 MODULE_HAP_PATH,
649 info.hapPath,
650 JsonType::STRING,
651 false,
652 ProfileReader::parseResult,
653 ArrayType::NOT_ARRAY);
654 GetValueIfFindKey<std::string>(jsonObject,
655 jsonObjectEnd,
656 MODULE_RES_PATH,
657 info.moduleResPath,
658 JsonType::STRING,
659 false,
660 ProfileReader::parseResult,
661 ArrayType::NOT_ARRAY);
662 GetValueIfFindKey<bool>(jsonObject,
663 jsonObjectEnd,
664 MODULE_IS_ENTRY,
665 info.isEntry,
666 JsonType::BOOLEAN,
667 false,
668 ProfileReader::parseResult,
669 ArrayType::NOT_ARRAY);
670 GetValueIfFindKey<MetaData>(jsonObject,
671 jsonObjectEnd,
672 MODULE_METADATA,
673 info.metaData,
674 JsonType::OBJECT,
675 false,
676 ProfileReader::parseResult,
677 ArrayType::NOT_ARRAY);
678 GetValueIfFindKey<ModuleColorMode>(jsonObject,
679 jsonObjectEnd,
680 MODULE_COLOR_MODE,
681 info.colorMode,
682 JsonType::NUMBER,
683 false,
684 ProfileReader::parseResult,
685 ArrayType::NOT_ARRAY);
686 GetValueIfFindKey<Distro>(jsonObject,
687 jsonObjectEnd,
688 MODULE_DISTRO,
689 info.distro,
690 JsonType::OBJECT,
691 false,
692 ProfileReader::parseResult,
693 ArrayType::NOT_ARRAY);
694 GetValueIfFindKey<std::string>(jsonObject,
695 jsonObjectEnd,
696 MODULE_DESCRIPTION,
697 info.description,
698 JsonType::STRING,
699 false,
700 ProfileReader::parseResult,
701 ArrayType::NOT_ARRAY);
702 GetValueIfFindKey<int32_t>(jsonObject,
703 jsonObjectEnd,
704 MODULE_DESCRIPTION_ID,
705 info.descriptionId,
706 JsonType::NUMBER,
707 false,
708 ProfileReader::parseResult,
709 ArrayType::NOT_ARRAY);
710 GetValueIfFindKey<std::string>(jsonObject,
711 jsonObjectEnd,
712 MODULE_ICON,
713 info.icon,
714 JsonType::STRING,
715 false,
716 ProfileReader::parseResult,
717 ArrayType::NOT_ARRAY);
718 GetValueIfFindKey<int32_t>(jsonObject,
719 jsonObjectEnd,
720 MODULE_ICON_ID,
721 info.iconId,
722 JsonType::NUMBER,
723 false,
724 ProfileReader::parseResult,
725 ArrayType::NOT_ARRAY);
726 GetValueIfFindKey<std::string>(jsonObject,
727 jsonObjectEnd,
728 MODULE_LABEL,
729 info.label,
730 JsonType::STRING,
731 false,
732 ProfileReader::parseResult,
733 ArrayType::NOT_ARRAY);
734 GetValueIfFindKey<int32_t>(jsonObject,
735 jsonObjectEnd,
736 MODULE_LABEL_ID,
737 info.labelId,
738 JsonType::NUMBER,
739 false,
740 ProfileReader::parseResult,
741 ArrayType::NOT_ARRAY);
742 GetValueIfFindKey<std::string>(jsonObject,
743 jsonObjectEnd,
744 MODULE_MAIN_ABILITY,
745 info.mainAbility,
746 JsonType::STRING,
747 false,
748 ProfileReader::parseResult,
749 ArrayType::NOT_ARRAY);
750 GetValueIfFindKey<std::string>(jsonObject,
751 jsonObjectEnd,
752 MODULE_ENTRY_ABILITY_KEY,
753 info.entryAbilityKey,
754 JsonType::STRING,
755 false,
756 ProfileReader::parseResult,
757 ArrayType::NOT_ARRAY);
758 GetValueIfFindKey<std::string>(jsonObject,
759 jsonObjectEnd,
760 MODULE_SRC_PATH,
761 info.srcPath,
762 JsonType::STRING,
763 false,
764 ProfileReader::parseResult,
765 ArrayType::NOT_ARRAY);
766 GetValueIfFindKey<std::string>(jsonObject,
767 jsonObjectEnd,
768 MODULE_HASH_VALUE,
769 info.hashValue,
770 JsonType::STRING,
771 false,
772 ProfileReader::parseResult,
773 ArrayType::NOT_ARRAY);
774 GetValueIfFindKey<bool>(jsonObject,
775 jsonObjectEnd,
776 MODULE_DESCRIPTION_INSTALLATION_FREE,
777 info.installationFree,
778 JsonType::BOOLEAN,
779 false,
780 ProfileReader::parseResult,
781 ArrayType::NOT_ARRAY);
782 GetValueIfFindKey<std::map<std::string, bool>>(jsonObject,
783 jsonObjectEnd,
784 MODULE_IS_REMOVABLE,
785 info.isRemovable,
786 JsonType::OBJECT,
787 false,
788 ProfileReader::parseResult,
789 ArrayType::NOT_ARRAY);
790 GetValueIfFindKey<int32_t>(jsonObject,
791 jsonObjectEnd,
792 MODULE_UPGRADE_FLAG,
793 info.upgradeFlag,
794 JsonType::NUMBER,
795 false,
796 ProfileReader::parseResult,
797 ArrayType::NOT_ARRAY);
798 GetValueIfFindKey<std::vector<std::string>>(jsonObject,
799 jsonObjectEnd,
800 MODULE_REQ_CAPABILITIES,
801 info.reqCapabilities,
802 JsonType::ARRAY,
803 false,
804 ProfileReader::parseResult,
805 ArrayType::STRING);
806 GetValueIfFindKey<std::vector<std::string>>(jsonObject,
807 jsonObjectEnd,
808 MODULE_ABILITY_KEYS,
809 info.abilityKeys,
810 JsonType::ARRAY,
811 false,
812 ProfileReader::parseResult,
813 ArrayType::STRING);
814 GetValueIfFindKey<std::vector<std::string>>(jsonObject,
815 jsonObjectEnd,
816 MODULE_SKILL_KEYS,
817 info.skillKeys,
818 JsonType::ARRAY,
819 false,
820 ProfileReader::parseResult,
821 ArrayType::STRING);
822 int32_t parseResult = ERR_OK;
823 GetValueIfFindKey<std::string>(jsonObject,
824 jsonObjectEnd,
825 MODULE_PROCESS,
826 info.process,
827 JsonType::STRING,
828 false,
829 parseResult,
830 ArrayType::NOT_ARRAY);
831 GetValueIfFindKey<std::string>(jsonObject,
832 jsonObjectEnd,
833 MODULE_SRC_ENTRANCE,
834 info.srcEntrance,
835 JsonType::STRING,
836 false,
837 parseResult,
838 ArrayType::NOT_ARRAY);
839 GetValueIfFindKey<std::vector<std::string>>(jsonObject,
840 jsonObjectEnd,
841 MODULE_DEVICE_TYPES,
842 info.deviceTypes,
843 JsonType::ARRAY,
844 false,
845 parseResult,
846 ArrayType::STRING);
847 GetValueIfFindKey<std::string>(jsonObject,
848 jsonObjectEnd,
849 MODULE_VIRTUAL_MACHINE,
850 info.virtualMachine,
851 JsonType::STRING,
852 false,
853 parseResult,
854 ArrayType::NOT_ARRAY);
855 GetValueIfFindKey<std::string>(jsonObject,
856 jsonObjectEnd,
857 MODULE_UI_SYNTAX,
858 info.uiSyntax,
859 JsonType::STRING,
860 false,
861 parseResult,
862 ArrayType::NOT_ARRAY);
863 GetValueIfFindKey<std::string>(jsonObject,
864 jsonObjectEnd,
865 MODULE_PAGES,
866 info.pages,
867 JsonType::STRING,
868 false,
869 parseResult,
870 ArrayType::NOT_ARRAY);
871 GetValueIfFindKey<std::vector<Metadata>>(jsonObject,
872 jsonObjectEnd,
873 MODULE_META_DATA,
874 info.metadata,
875 JsonType::ARRAY,
876 false,
877 parseResult,
878 ArrayType::OBJECT);
879 GetValueIfFindKey<std::vector<RequestPermission>>(jsonObject,
880 jsonObjectEnd,
881 MODULE_REQUEST_PERMISSIONS,
882 info.requestPermissions,
883 JsonType::ARRAY,
884 false,
885 parseResult,
886 ArrayType::OBJECT);
887 GetValueIfFindKey<std::vector<DefinePermission>>(jsonObject,
888 jsonObjectEnd,
889 MODULE_DEFINE_PERMISSIONS,
890 info.definePermissions,
891 JsonType::ARRAY,
892 false,
893 parseResult,
894 ArrayType::OBJECT);
895 GetValueIfFindKey<std::vector<std::string>>(jsonObject,
896 jsonObjectEnd,
897 MODULE_EXTENSION_KEYS,
898 info.extensionKeys,
899 JsonType::ARRAY,
900 false,
901 parseResult,
902 ArrayType::STRING);
903 GetValueIfFindKey<std::vector<std::string>>(jsonObject,
904 jsonObjectEnd,
905 MODULE_EXTENSION_SKILL_KEYS,
906 info.extensionSkillKeys,
907 JsonType::ARRAY,
908 false,
909 parseResult,
910 ArrayType::STRING);
911 GetValueIfFindKey<bool>(jsonObject,
912 jsonObjectEnd,
913 MODULE_IS_MODULE_JSON,
914 info.isModuleJson,
915 JsonType::BOOLEAN,
916 false,
917 parseResult,
918 ArrayType::NOT_ARRAY);
919 GetValueIfFindKey<bool>(jsonObject,
920 jsonObjectEnd,
921 MODULE_IS_STAGE_BASED_MODEL,
922 info.isStageBasedModel,
923 JsonType::BOOLEAN,
924 false,
925 parseResult,
926 ArrayType::NOT_ARRAY);
927 GetValueIfFindKey<std::vector<Dependency>>(jsonObject,
928 jsonObjectEnd,
929 MODULE_DEPENDENCIES,
930 info.dependencies,
931 JsonType::ARRAY,
932 false,
933 ProfileReader::parseResult,
934 ArrayType::OBJECT);
935 GetValueIfFindKey<std::string>(jsonObject,
936 jsonObjectEnd,
937 MODULE_COMPILE_MODE,
938 info.compileMode,
939 JsonType::STRING,
940 false,
941 parseResult,
942 ArrayType::NOT_ARRAY);
943 GetValueIfFindKey<bool>(jsonObject,
944 jsonObjectEnd,
945 MODULE_IS_LIB_ISOLATED,
946 info.isLibIsolated,
947 JsonType::BOOLEAN,
948 false,
949 parseResult,
950 ArrayType::NOT_ARRAY);
951 GetValueIfFindKey<std::string>(jsonObject,
952 jsonObjectEnd,
953 MODULE_NATIVE_LIBRARY_PATH,
954 info.nativeLibraryPath,
955 JsonType::STRING,
956 false,
957 parseResult,
958 ArrayType::NOT_ARRAY);
959 GetValueIfFindKey<std::string>(jsonObject,
960 jsonObjectEnd,
961 MODULE_CPU_ABI,
962 info.cpuAbi,
963 JsonType::STRING,
964 false,
965 parseResult,
966 ArrayType::NOT_ARRAY);
967 GetValueIfFindKey<AtomicServiceModuleType>(jsonObject,
968 jsonObjectEnd,
969 MODULE_ATOMIC_SERVICE_MODULE_TYPE,
970 info.atomicServiceModuleType,
971 JsonType::NUMBER,
972 false,
973 ProfileReader::parseResult,
974 ArrayType::NOT_ARRAY);
975 GetValueIfFindKey<std::vector<std::string>>(jsonObject,
976 jsonObjectEnd,
977 MODULE_PRELOADS,
978 info.preloads,
979 JsonType::ARRAY,
980 false,
981 ProfileReader::parseResult,
982 ArrayType::STRING);
983 if (parseResult != ERR_OK) {
984 APP_LOGE("read InnerModuleInfo from database error, error code : %{public}d", parseResult);
985 }
986 }
987
from_json(const nlohmann::json & jsonObject,SkillUri & uri)988 void from_json(const nlohmann::json &jsonObject, SkillUri &uri)
989 {
990 // these are required fields.
991 const auto &jsonObjectEnd = jsonObject.end();
992 GetValueIfFindKey<std::string>(jsonObject,
993 jsonObjectEnd,
994 ProfileReader::BUNDLE_MODULE_PROFILE_KEY_SCHEME,
995 uri.scheme,
996 JsonType::STRING,
997 false,
998 ProfileReader::parseResult,
999 ArrayType::NOT_ARRAY);
1000 // these are not required fields.
1001 GetValueIfFindKey<std::string>(jsonObject,
1002 jsonObjectEnd,
1003 ProfileReader::BUNDLE_MODULE_PROFILE_KEY_HOST,
1004 uri.host,
1005 JsonType::STRING,
1006 false,
1007 ProfileReader::parseResult,
1008 ArrayType::NOT_ARRAY);
1009 GetValueIfFindKey<std::string>(jsonObject,
1010 jsonObjectEnd,
1011 ProfileReader::BUNDLE_MODULE_PROFILE_KEY_PORT,
1012 uri.port,
1013 JsonType::STRING,
1014 false,
1015 ProfileReader::parseResult,
1016 ArrayType::NOT_ARRAY);
1017 GetValueIfFindKey<std::string>(jsonObject,
1018 jsonObjectEnd,
1019 ProfileReader::BUNDLE_MODULE_PROFILE_KEY_PATH,
1020 uri.path,
1021 JsonType::STRING,
1022 false,
1023 ProfileReader::parseResult,
1024 ArrayType::NOT_ARRAY);
1025 GetValueIfFindKey<std::string>(jsonObject,
1026 jsonObjectEnd,
1027 ProfileReader::BUNDLE_MODULE_PROFILE_KEY_PATHSTARTWITH,
1028 uri.pathStartWith,
1029 JsonType::STRING,
1030 false,
1031 ProfileReader::parseResult,
1032 ArrayType::NOT_ARRAY);
1033 GetValueIfFindKey<std::string>(jsonObject,
1034 jsonObjectEnd,
1035 ProfileReader::BUNDLE_MODULE_PROFILE_KEY_PATHREGX,
1036 uri.pathRegex,
1037 JsonType::STRING,
1038 false,
1039 ProfileReader::parseResult,
1040 ArrayType::NOT_ARRAY);
1041 GetValueIfFindKey<std::string>(jsonObject,
1042 jsonObjectEnd,
1043 ProfileReader::BUNDLE_MODULE_PROFILE_KEY_PATHREGEX,
1044 uri.pathRegex,
1045 JsonType::STRING,
1046 false,
1047 ProfileReader::parseResult,
1048 ArrayType::NOT_ARRAY);
1049 GetValueIfFindKey<std::string>(jsonObject,
1050 jsonObjectEnd,
1051 ProfileReader::BUNDLE_MODULE_PROFILE_KEY_TYPE,
1052 uri.type,
1053 JsonType::STRING,
1054 false,
1055 ProfileReader::parseResult,
1056 ArrayType::NOT_ARRAY);
1057 }
1058
from_json(const nlohmann::json & jsonObject,Skill & skill)1059 void from_json(const nlohmann::json &jsonObject, Skill &skill)
1060 {
1061 // these are not required fields.
1062 const auto &jsonObjectEnd = jsonObject.end();
1063 GetValueIfFindKey<std::vector<std::string>>(jsonObject,
1064 jsonObjectEnd,
1065 ProfileReader::BUNDLE_MODULE_PROFILE_KEY_ACTIONS,
1066 skill.actions,
1067 JsonType::ARRAY,
1068 false,
1069 ProfileReader::parseResult,
1070 ArrayType::STRING);
1071 GetValueIfFindKey<std::vector<std::string>>(jsonObject,
1072 jsonObjectEnd,
1073 ProfileReader::BUNDLE_MODULE_PROFILE_KEY_ENTITIES,
1074 skill.entities,
1075 JsonType::ARRAY,
1076 false,
1077 ProfileReader::parseResult,
1078 ArrayType::STRING);
1079 GetValueIfFindKey<std::vector<SkillUri>>(jsonObject,
1080 jsonObjectEnd,
1081 ProfileReader::BUNDLE_MODULE_PROFILE_KEY_URIS,
1082 skill.uris,
1083 JsonType::ARRAY,
1084 false,
1085 ProfileReader::parseResult,
1086 ArrayType::OBJECT);
1087 }
1088
from_json(const nlohmann::json & jsonObject,Distro & distro)1089 void from_json(const nlohmann::json &jsonObject, Distro &distro)
1090 {
1091 const auto &jsonObjectEnd = jsonObject.end();
1092 GetValueIfFindKey<bool>(jsonObject,
1093 jsonObjectEnd,
1094 ProfileReader::BUNDLE_MODULE_PROFILE_KEY_DELIVERY_WITH_INSTALL,
1095 distro.deliveryWithInstall,
1096 JsonType::BOOLEAN,
1097 true,
1098 ProfileReader::parseResult,
1099 ArrayType::NOT_ARRAY);
1100 GetValueIfFindKey<std::string>(jsonObject,
1101 jsonObjectEnd,
1102 ProfileReader::BUNDLE_MODULE_PROFILE_KEY_MODULE_NAME,
1103 distro.moduleName,
1104 JsonType::STRING,
1105 true,
1106 ProfileReader::parseResult,
1107 ArrayType::NOT_ARRAY);
1108 GetValueIfFindKey<std::string>(jsonObject,
1109 jsonObjectEnd,
1110 ProfileReader::BUNDLE_MODULE_PROFILE_KEY_MODULE_TYPE,
1111 distro.moduleType,
1112 JsonType::STRING,
1113 true,
1114 ProfileReader::parseResult,
1115 ArrayType::NOT_ARRAY);
1116 // mustFlag decide by distro.moduleType
1117 GetValueIfFindKey<bool>(jsonObject,
1118 jsonObjectEnd,
1119 ProfileReader::BUNDLE_MODULE_PROFILE_KEY_MODULE_INSTALLATION_FREE,
1120 distro.installationFree,
1121 JsonType::BOOLEAN,
1122 false,
1123 ProfileReader::parseResult,
1124 ArrayType::NOT_ARRAY);
1125 }
1126
from_json(const nlohmann::json & jsonObject,InstallMark & installMark)1127 void from_json(const nlohmann::json &jsonObject, InstallMark &installMark)
1128 {
1129 const auto &jsonObjectEnd = jsonObject.end();
1130 GetValueIfFindKey<std::string>(jsonObject,
1131 jsonObjectEnd,
1132 ProfileReader::BUNDLE_INSTALL_MARK_BUNDLE,
1133 installMark.bundleName,
1134 JsonType::STRING,
1135 false,
1136 ProfileReader::parseResult,
1137 ArrayType::NOT_ARRAY);
1138 GetValueIfFindKey<std::string>(jsonObject,
1139 jsonObjectEnd,
1140 ProfileReader::BUNDLE_INSTALL_MARK_PACKAGE,
1141 installMark.packageName,
1142 JsonType::STRING,
1143 false,
1144 ProfileReader::parseResult,
1145 ArrayType::NOT_ARRAY);
1146 GetValueIfFindKey<int32_t>(jsonObject,
1147 jsonObjectEnd,
1148 ProfileReader::BUNDLE_INSTALL_MARK_STATUS,
1149 installMark.status,
1150 JsonType::NUMBER,
1151 false,
1152 ProfileReader::parseResult,
1153 ArrayType::NOT_ARRAY);
1154 }
1155
from_json(const nlohmann::json & jsonObject,SandboxAppPersistentInfo & sandboxPersistentInfo)1156 void from_json(const nlohmann::json &jsonObject, SandboxAppPersistentInfo &sandboxPersistentInfo)
1157 {
1158 const auto &jsonObjectEnd = jsonObject.end();
1159 GetValueIfFindKey<uint32_t>(jsonObject,
1160 jsonObjectEnd,
1161 ProfileReader::BUNDLE_SANDBOX_PERSISTENT_ACCESS_TOKEN_ID,
1162 sandboxPersistentInfo.accessTokenId,
1163 JsonType::NUMBER,
1164 false,
1165 ProfileReader::parseResult,
1166 ArrayType::NOT_ARRAY);
1167 GetValueIfFindKey<int32_t>(jsonObject,
1168 jsonObjectEnd,
1169 ProfileReader::BUNDLE_SANDBOX_PERSISTENT_APP_INDEX,
1170 sandboxPersistentInfo.appIndex,
1171 JsonType::NUMBER,
1172 false,
1173 ProfileReader::parseResult,
1174 ArrayType::NOT_ARRAY);
1175 GetValueIfFindKey<int32_t>(jsonObject,
1176 jsonObjectEnd,
1177 ProfileReader::BUNDLE_SANDBOX_PERSISTENT_USER_ID,
1178 sandboxPersistentInfo.userId,
1179 JsonType::NUMBER,
1180 false,
1181 ProfileReader::parseResult,
1182 ArrayType::NOT_ARRAY);
1183 }
1184
from_json(const nlohmann::json & jsonObject,DefinePermission & definePermission)1185 void from_json(const nlohmann::json &jsonObject, DefinePermission &definePermission)
1186 {
1187 const auto &jsonObjectEnd = jsonObject.end();
1188 int32_t parseResult = ERR_OK;
1189 GetValueIfFindKey<std::string>(jsonObject,
1190 jsonObjectEnd,
1191 Profile::DEFINEPERMISSION_NAME,
1192 definePermission.name,
1193 JsonType::STRING,
1194 false,
1195 parseResult,
1196 ArrayType::NOT_ARRAY);
1197 GetValueIfFindKey<std::string>(jsonObject,
1198 jsonObjectEnd,
1199 Profile::DEFINEPERMISSION_GRANT_MODE,
1200 definePermission.grantMode,
1201 JsonType::STRING,
1202 false,
1203 parseResult,
1204 ArrayType::NOT_ARRAY);
1205 GetValueIfFindKey<std::string>(jsonObject,
1206 jsonObjectEnd,
1207 Profile::DEFINEPERMISSION_AVAILABLE_LEVEL,
1208 definePermission.availableLevel,
1209 JsonType::STRING,
1210 false,
1211 parseResult,
1212 ArrayType::NOT_ARRAY);
1213 GetValueIfFindKey<bool>(jsonObject,
1214 jsonObjectEnd,
1215 Profile::DEFINEPERMISSION_PROVISION_ENABLE,
1216 definePermission.provisionEnable,
1217 JsonType::BOOLEAN,
1218 false,
1219 parseResult,
1220 ArrayType::NOT_ARRAY);
1221 GetValueIfFindKey<bool>(jsonObject,
1222 jsonObjectEnd,
1223 Profile::DEFINEPERMISSION_DISTRIBUTED_SCENE_ENABLE,
1224 definePermission.distributedSceneEnable,
1225 JsonType::BOOLEAN,
1226 false,
1227 parseResult,
1228 ArrayType::NOT_ARRAY);
1229 GetValueIfFindKey<std::string>(jsonObject,
1230 jsonObjectEnd,
1231 Profile::LABEL,
1232 definePermission.label,
1233 JsonType::STRING,
1234 false,
1235 parseResult,
1236 ArrayType::NOT_ARRAY);
1237 GetValueIfFindKey<int32_t>(jsonObject,
1238 jsonObjectEnd,
1239 Profile::LABEL_ID,
1240 definePermission.labelId,
1241 JsonType::NUMBER,
1242 false,
1243 parseResult,
1244 ArrayType::NOT_ARRAY);
1245 GetValueIfFindKey<std::string>(jsonObject,
1246 jsonObjectEnd,
1247 Profile::DESCRIPTION,
1248 definePermission.description,
1249 JsonType::STRING,
1250 false,
1251 parseResult,
1252 ArrayType::NOT_ARRAY);
1253 GetValueIfFindKey<int32_t>(jsonObject,
1254 jsonObjectEnd,
1255 Profile::DESCRIPTION_ID,
1256 definePermission.descriptionId,
1257 JsonType::NUMBER,
1258 false,
1259 parseResult,
1260 ArrayType::NOT_ARRAY);
1261 if (parseResult != ERR_OK) {
1262 APP_LOGE("read DefinePermission from database error, error code : %{public}d", parseResult);
1263 }
1264 }
1265
from_json(const nlohmann::json & jsonObject,Dependency & dependency)1266 void from_json(const nlohmann::json &jsonObject, Dependency &dependency)
1267 {
1268 const auto &jsonObjectEnd = jsonObject.end();
1269 GetValueIfFindKey<std::string>(jsonObject,
1270 jsonObjectEnd,
1271 Profile::DEPENDENCIES_MODULE_NAME,
1272 dependency.moduleName,
1273 JsonType::STRING,
1274 false,
1275 ProfileReader::parseResult,
1276 ArrayType::NOT_ARRAY);
1277 GetValueIfFindKey<std::string>(jsonObject,
1278 jsonObjectEnd,
1279 Profile::DEPENDENCIES_BUNDLE_NAME,
1280 dependency.bundleName,
1281 JsonType::STRING,
1282 false,
1283 ProfileReader::parseResult,
1284 ArrayType::NOT_ARRAY);
1285 }
1286
FromJson(const nlohmann::json & jsonObject)1287 int32_t InnerBundleInfo::FromJson(const nlohmann::json &jsonObject)
1288 {
1289 const auto &jsonObjectEnd = jsonObject.end();
1290 GetValueIfFindKey<Constants::AppType>(jsonObject,
1291 jsonObjectEnd,
1292 APP_TYPE,
1293 appType_,
1294 JsonType::NUMBER,
1295 true,
1296 ProfileReader::parseResult,
1297 ArrayType::NOT_ARRAY);
1298 GetValueIfFindKey<int>(jsonObject,
1299 jsonObjectEnd,
1300 UID,
1301 uid_,
1302 JsonType::NUMBER,
1303 false,
1304 ProfileReader::parseResult,
1305 ArrayType::NOT_ARRAY);
1306 GetValueIfFindKey<int>(jsonObject,
1307 jsonObjectEnd,
1308 GID,
1309 gid_,
1310 JsonType::NUMBER,
1311 false,
1312 ProfileReader::parseResult,
1313 ArrayType::NOT_ARRAY);
1314 GetValueIfFindKey<std::vector<std::string>>(jsonObject,
1315 jsonObjectEnd,
1316 ALLOWED_ACLS,
1317 allowedAcls_,
1318 JsonType::ARRAY,
1319 false,
1320 ProfileReader::parseResult,
1321 ArrayType::STRING);
1322 GetValueIfFindKey<std::string>(jsonObject,
1323 jsonObjectEnd,
1324 BASE_DATA_DIR,
1325 baseDataDir_,
1326 JsonType::STRING,
1327 true,
1328 ProfileReader::parseResult,
1329 ArrayType::NOT_ARRAY);
1330 GetValueIfFindKey<BundleStatus>(jsonObject,
1331 jsonObjectEnd,
1332 BUNDLE_STATUS,
1333 bundleStatus_,
1334 JsonType::NUMBER,
1335 true,
1336 ProfileReader::parseResult,
1337 ArrayType::NOT_ARRAY);
1338 GetValueIfFindKey<BundleInfo>(jsonObject,
1339 jsonObjectEnd,
1340 BASE_BUNDLE_INFO,
1341 *baseBundleInfo_,
1342 JsonType::OBJECT,
1343 true,
1344 ProfileReader::parseResult,
1345 ArrayType::NOT_ARRAY);
1346 GetValueIfFindKey<ApplicationInfo>(jsonObject,
1347 jsonObjectEnd,
1348 BASE_APPLICATION_INFO,
1349 *baseApplicationInfo_,
1350 JsonType::OBJECT,
1351 true,
1352 ProfileReader::parseResult,
1353 ArrayType::NOT_ARRAY);
1354 GetValueIfFindKey<std::map<std::string, AbilityInfo>>(jsonObject,
1355 jsonObjectEnd,
1356 BASE_ABILITY_INFO,
1357 baseAbilityInfos_,
1358 JsonType::OBJECT,
1359 true,
1360 ProfileReader::parseResult,
1361 ArrayType::NOT_ARRAY);
1362 GetValueIfFindKey<std::map<std::string, InnerModuleInfo>>(jsonObject,
1363 jsonObjectEnd,
1364 INNER_MODULE_INFO,
1365 innerModuleInfos_,
1366 JsonType::OBJECT,
1367 true,
1368 ProfileReader::parseResult,
1369 ArrayType::NOT_ARRAY);
1370 GetValueIfFindKey<std::map<std::string, std::vector<Skill>>>(jsonObject,
1371 jsonObjectEnd,
1372 SKILL_INFOS,
1373 skillInfos_,
1374 JsonType::OBJECT,
1375 true,
1376 ProfileReader::parseResult,
1377 ArrayType::NOT_ARRAY);
1378 GetValueIfFindKey<int>(jsonObject,
1379 jsonObjectEnd,
1380 USER_ID,
1381 userId_,
1382 JsonType::NUMBER,
1383 true,
1384 ProfileReader::parseResult,
1385 ArrayType::NOT_ARRAY);
1386 GetValueIfFindKey<std::string>(jsonObject,
1387 jsonObjectEnd,
1388 APP_FEATURE,
1389 appFeature_,
1390 JsonType::STRING,
1391 true,
1392 ProfileReader::parseResult,
1393 ArrayType::NOT_ARRAY);
1394 GetValueIfFindKey<std::map<std::string, std::vector<FormInfo>>>(jsonObject,
1395 jsonObjectEnd,
1396 MODULE_FORMS,
1397 formInfos_,
1398 JsonType::OBJECT,
1399 true,
1400 ProfileReader::parseResult,
1401 ArrayType::NOT_ARRAY);
1402 GetValueIfFindKey<std::map<std::string, ShortcutInfo>>(jsonObject,
1403 jsonObjectEnd,
1404 MODULE_SHORTCUT,
1405 shortcutInfos_,
1406 JsonType::OBJECT,
1407 true,
1408 ProfileReader::parseResult,
1409 ArrayType::NOT_ARRAY);
1410 GetValueIfFindKey<std::map<std::string, CommonEventInfo>>(jsonObject,
1411 jsonObjectEnd,
1412 MODULE_COMMON_EVENT,
1413 commonEvents_,
1414 JsonType::OBJECT,
1415 true,
1416 ProfileReader::parseResult,
1417 ArrayType::NOT_ARRAY);
1418 GetValueIfFindKey<InstallMark>(jsonObject,
1419 jsonObjectEnd,
1420 INSTALL_MARK,
1421 mark_,
1422 JsonType::OBJECT,
1423 false,
1424 ProfileReader::parseResult,
1425 ArrayType::NOT_ARRAY);
1426 int32_t isOldVersion = ERR_OK;
1427 GetValueIfFindKey<std::map<std::string, InnerBundleUserInfo>>(jsonObject,
1428 jsonObjectEnd,
1429 INNER_BUNDLE_USER_INFOS,
1430 innerBundleUserInfos_,
1431 JsonType::OBJECT,
1432 true,
1433 isOldVersion,
1434 ArrayType::NOT_ARRAY);
1435 int32_t ret = ProfileReader::parseResult;
1436 // need recover parse result to ERR_OK
1437 ProfileReader::parseResult = ERR_OK;
1438 if (ret == ERR_OK && isOldVersion == ERR_APPEXECFWK_PARSE_PROFILE_MISSING_PROP) {
1439 // To be compatible with the old database,
1440 // if the old data does not have bundleUserInfos,
1441 // the default user information needs to be constructed.
1442 BuildDefaultUserInfo();
1443 }
1444 int32_t parseResult = ERR_OK;
1445 GetValueIfFindKey<bool>(jsonObject,
1446 jsonObjectEnd,
1447 BUNDLE_IS_NEW_VERSION,
1448 isNewVersion_,
1449 JsonType::BOOLEAN,
1450 false,
1451 parseResult,
1452 ArrayType::NOT_ARRAY);
1453 GetValueIfFindKey<std::map<std::string, ExtensionAbilityInfo>>(jsonObject,
1454 jsonObjectEnd,
1455 BUNDLE_BASE_EXTENSION_INFOS,
1456 baseExtensionInfos_,
1457 JsonType::OBJECT,
1458 false,
1459 parseResult,
1460 ArrayType::NOT_ARRAY);
1461 GetValueIfFindKey<std::map<std::string, std::vector<Skill>>>(jsonObject,
1462 jsonObjectEnd,
1463 BUNDLE_EXTENSION_SKILL_INFOS,
1464 extensionSkillInfos_,
1465 JsonType::OBJECT,
1466 false,
1467 parseResult,
1468 ArrayType::NOT_ARRAY);
1469 GetValueIfFindKey<BundlePackInfo>(jsonObject,
1470 jsonObjectEnd,
1471 BUNDLE_PACK_INFO,
1472 bundlePackInfo_,
1473 JsonType::OBJECT,
1474 false,
1475 parseResult,
1476 ArrayType::NOT_ARRAY);
1477 GetValueIfFindKey<int>(jsonObject,
1478 jsonObjectEnd,
1479 APP_INDEX,
1480 appIndex_,
1481 JsonType::NUMBER,
1482 false,
1483 ProfileReader::parseResult,
1484 ArrayType::NOT_ARRAY);
1485 GetValueIfFindKey<bool>(jsonObject,
1486 jsonObjectEnd,
1487 BUNDLE_IS_SANDBOX_APP,
1488 isSandboxApp_,
1489 JsonType::BOOLEAN,
1490 false,
1491 ProfileReader::parseResult,
1492 ArrayType::NOT_ARRAY);
1493 GetValueIfFindKey<std::vector<SandboxAppPersistentInfo>>(jsonObject,
1494 jsonObjectEnd,
1495 BUNDLE_SANDBOX_PERSISTENT_INFO,
1496 sandboxPersistentInfo_,
1497 JsonType::ARRAY,
1498 false,
1499 ProfileReader::parseResult,
1500 ArrayType::OBJECT);
1501 GetValueIfFindKey<int32_t>(jsonObject,
1502 jsonObjectEnd,
1503 DISPOSED_STATUS,
1504 disposedStatus_,
1505 JsonType::NUMBER,
1506 false,
1507 parseResult,
1508 ArrayType::NOT_ARRAY);
1509 GetValueIfFindKey<std::vector<HqfInfo>>(jsonObject,
1510 jsonObjectEnd,
1511 BUNDLE_HQF_INFOS,
1512 hqfInfos_,
1513 JsonType::ARRAY,
1514 false,
1515 ProfileReader::parseResult,
1516 ArrayType::OBJECT);
1517 GetValueIfFindKey<bool>(jsonObject,
1518 jsonObjectEnd,
1519 HAS_ATOMIC_SERVICE_CONFIG,
1520 hasAtomicServiceConfig_,
1521 JsonType::BOOLEAN,
1522 false,
1523 parseResult,
1524 ArrayType::NOT_ARRAY);
1525 GetValueIfFindKey<std::string>(jsonObject,
1526 jsonObjectEnd,
1527 MAIN_ATOMIC_MODULE_NAME,
1528 mainAtomicModuleName_,
1529 JsonType::STRING,
1530 false,
1531 ProfileReader::parseResult,
1532 ArrayType::NOT_ARRAY);
1533 if (parseResult != ERR_OK) {
1534 APP_LOGE("read InnerBundleInfo from database error, error code : %{public}d", parseResult);
1535 return parseResult;
1536 }
1537 return ret;
1538 }
1539
BuildDefaultUserInfo()1540 void InnerBundleInfo::BuildDefaultUserInfo()
1541 {
1542 APP_LOGD("BuildDefaultUserInfo: bundleName: %{public}s.",
1543 baseApplicationInfo_->bundleName.c_str());
1544 InnerBundleUserInfo defaultInnerBundleUserInfo;
1545 defaultInnerBundleUserInfo.bundleUserInfo.userId = GetUserId();
1546 defaultInnerBundleUserInfo.uid = uid_;
1547 defaultInnerBundleUserInfo.gids.emplace_back(gid_);
1548 defaultInnerBundleUserInfo.installTime = baseBundleInfo_->installTime;
1549 defaultInnerBundleUserInfo.updateTime = baseBundleInfo_->updateTime;
1550 defaultInnerBundleUserInfo.bundleName = baseApplicationInfo_->bundleName;
1551 defaultInnerBundleUserInfo.bundleUserInfo.enabled = baseApplicationInfo_->enabled;
1552 AddInnerBundleUserInfo(defaultInnerBundleUserInfo);
1553 }
1554
FindHapModuleInfo(const std::string & modulePackage,int32_t userId) const1555 std::optional<HapModuleInfo> InnerBundleInfo::FindHapModuleInfo(const std::string &modulePackage, int32_t userId) const
1556 {
1557 auto it = innerModuleInfos_.find(modulePackage);
1558 if (it == innerModuleInfos_.end()) {
1559 APP_LOGE("can not find module %{public}s", modulePackage.c_str());
1560 return std::nullopt;
1561 }
1562 HapModuleInfo hapInfo;
1563 hapInfo.name = it->second.name;
1564 hapInfo.package = it->second.modulePackage;
1565 hapInfo.moduleName = it->second.moduleName;
1566 hapInfo.description = it->second.description;
1567 hapInfo.descriptionId = it->second.descriptionId;
1568 hapInfo.label = it->second.label;
1569 hapInfo.labelId = it->second.labelId;
1570 hapInfo.iconPath = it->second.icon;
1571 hapInfo.iconId = it->second.iconId;
1572 hapInfo.mainAbility = it->second.mainAbility;
1573 hapInfo.srcPath = it->second.srcPath;
1574 hapInfo.hapPath = it->second.hapPath;
1575 hapInfo.supportedModes = baseApplicationInfo_->supportedModes;
1576 hapInfo.reqCapabilities = it->second.reqCapabilities;
1577 hapInfo.colorMode = it->second.colorMode;
1578 hapInfo.isRemovable = it->second.isRemovable;
1579 hapInfo.upgradeFlag = it->second.upgradeFlag;
1580 hapInfo.isLibIsolated = it->second.isLibIsolated;
1581 hapInfo.nativeLibraryPath = it->second.nativeLibraryPath;
1582 hapInfo.cpuAbi = it->second.cpuAbi;
1583
1584 hapInfo.bundleName = baseApplicationInfo_->bundleName;
1585 hapInfo.mainElementName = it->second.mainAbility;
1586 hapInfo.pages = it->second.pages;
1587 hapInfo.process = it->second.process;
1588 hapInfo.resourcePath = it->second.moduleResPath;
1589 hapInfo.srcEntrance = it->second.srcEntrance;
1590 hapInfo.uiSyntax = it->second.uiSyntax;
1591 hapInfo.virtualMachine = it->second.virtualMachine;
1592 hapInfo.deliveryWithInstall = it->second.distro.deliveryWithInstall;
1593 hapInfo.installationFree = it->second.distro.installationFree;
1594 hapInfo.isModuleJson = it->second.isModuleJson;
1595 hapInfo.isStageBasedModel = it->second.isStageBasedModel;
1596 std::string moduleType = it->second.distro.moduleType;
1597 if (moduleType == Profile::MODULE_TYPE_ENTRY) {
1598 hapInfo.moduleType = ModuleType::ENTRY;
1599 } else if (moduleType == Profile::MODULE_TYPE_FEATURE) {
1600 hapInfo.moduleType = ModuleType::FEATURE;
1601 } else if (moduleType == Profile::MODULE_TYPE_SHARED) {
1602 hapInfo.moduleType = ModuleType::SHARED;
1603 } else {
1604 hapInfo.moduleType = ModuleType::UNKNOWN;
1605 }
1606 std::string key;
1607 key.append(".").append(modulePackage).append(".");
1608 for (const auto &extension : baseExtensionInfos_) {
1609 if (extension.first.find(key) != std::string::npos) {
1610 hapInfo.extensionInfos.emplace_back(extension.second);
1611 }
1612 }
1613 hapInfo.metadata = it->second.metadata;
1614 bool first = false;
1615 for (auto &ability : baseAbilityInfos_) {
1616 if (ability.second.name == Constants::APP_DETAIL_ABILITY) {
1617 continue;
1618 }
1619 if (ability.first.find(key) != std::string::npos) {
1620 if (!first) {
1621 hapInfo.deviceTypes = ability.second.deviceTypes;
1622 first = true;
1623 }
1624 auto &abilityInfo = hapInfo.abilityInfos.emplace_back(ability.second);
1625 GetApplicationInfo(ApplicationFlag::GET_APPLICATION_INFO_WITH_PERMISSION |
1626 ApplicationFlag::GET_APPLICATION_INFO_WITH_CERTIFICATE_FINGERPRINT, userId,
1627 abilityInfo.applicationInfo);
1628 }
1629 }
1630 for (const auto &dependency : it->second.dependencies) {
1631 hapInfo.dependencies.emplace_back(dependency.moduleName);
1632 }
1633 hapInfo.compileMode = ConvertCompileMode(it->second.compileMode);
1634 for (const auto &hqf : hqfInfos_) {
1635 if (hqf.moduleName == it->second.moduleName) {
1636 hapInfo.hqfInfo = hqf;
1637 break;
1638 }
1639 }
1640 hapInfo.atomicServiceModuleType = it->second.atomicServiceModuleType;
1641 for (const auto &item : it->second.preloads) {
1642 PreloadItem preload(item);
1643 hapInfo.preloads.emplace_back(preload);
1644 }
1645 return hapInfo;
1646 }
1647
FindAbilityInfo(const std::string & bundleName,const std::string & moduleName,const std::string & abilityName,int32_t userId) const1648 std::optional<AbilityInfo> InnerBundleInfo::FindAbilityInfo(
1649 const std::string &bundleName, const std::string &moduleName,
1650 const std::string &abilityName, int32_t userId) const
1651 {
1652 for (const auto &ability : baseAbilityInfos_) {
1653 auto abilityInfo = ability.second;
1654 if ((abilityInfo.bundleName == bundleName) && (abilityInfo.name == abilityName) &&
1655 (moduleName.empty() || (abilityInfo.moduleName == moduleName))) {
1656 GetApplicationInfo(ApplicationFlag::GET_APPLICATION_INFO_WITH_PERMISSION |
1657 ApplicationFlag::GET_APPLICATION_INFO_WITH_CERTIFICATE_FINGERPRINT, userId,
1658 abilityInfo.applicationInfo);
1659 return abilityInfo;
1660 }
1661 }
1662 return std::nullopt;
1663 }
1664
FindAbilityInfoV9(const std::string & bundleName,const std::string & moduleName,const std::string & abilityName) const1665 std::optional<AbilityInfo> InnerBundleInfo::FindAbilityInfoV9(
1666 const std::string &bundleName, const std::string &moduleName,
1667 const std::string &abilityName) const
1668 {
1669 for (const auto &ability : baseAbilityInfos_) {
1670 auto abilityInfo = ability.second;
1671 if ((abilityInfo.bundleName == bundleName) && (abilityInfo.name == abilityName) &&
1672 (moduleName.empty() || (abilityInfo.moduleName == moduleName))) {
1673 return abilityInfo;
1674 }
1675 }
1676 return std::nullopt;
1677 }
1678
FindAbilityInfo(const std::string & bundleName,const std::string & moduleName,const std::string & abilityName,AbilityInfo & info) const1679 ErrCode InnerBundleInfo::FindAbilityInfo(const std::string &bundleName, const std::string &moduleName,
1680 const std::string &abilityName, AbilityInfo &info) const
1681 {
1682 bool isModuleFind = false;
1683 for (const auto &ability : baseAbilityInfos_) {
1684 auto abilityInfo = ability.second;
1685 if ((abilityInfo.bundleName == bundleName) && (abilityInfo.moduleName == moduleName)) {
1686 isModuleFind = true;
1687 if (abilityInfo.name == abilityName) {
1688 info = abilityInfo;
1689 return ERR_OK;
1690 }
1691 }
1692 }
1693 if (isModuleFind) {
1694 return ERR_BUNDLE_MANAGER_ABILITY_NOT_EXIST;
1695 } else {
1696 return ERR_BUNDLE_MANAGER_MODULE_NOT_EXIST;
1697 }
1698 }
1699
FindAbilityInfos(const std::string & bundleName,int32_t userId) const1700 std::optional<std::vector<AbilityInfo>> InnerBundleInfo::FindAbilityInfos(
1701 const std::string &bundleName, int32_t userId) const
1702 {
1703 std::vector<AbilityInfo> abilitys;
1704
1705 if (bundleName.empty()) {
1706 return std::nullopt;
1707 }
1708
1709 for (const auto &ability : baseAbilityInfos_) {
1710 if (ability.second.name == Constants::APP_DETAIL_ABILITY) {
1711 continue;
1712 }
1713 auto abilityInfo = ability.second;
1714 if ((abilityInfo.bundleName == bundleName)) {
1715 GetApplicationInfo(ApplicationFlag::GET_APPLICATION_INFO_WITH_PERMISSION |
1716 ApplicationFlag::GET_APPLICATION_INFO_WITH_CERTIFICATE_FINGERPRINT, userId,
1717 abilityInfo.applicationInfo);
1718 abilitys.emplace_back(abilityInfo);
1719 }
1720 }
1721 if (!abilitys.empty()) {
1722 return abilitys;
1723 }
1724
1725 return std::nullopt;
1726 }
1727
FindExtensionInfo(const std::string & bundleName,const std::string & moduleName,const std::string & extensionName) const1728 std::optional<ExtensionAbilityInfo> InnerBundleInfo::FindExtensionInfo(
1729 const std::string &bundleName, const std::string &moduleName, const std::string &extensionName) const
1730 {
1731 for (const auto &extension : baseExtensionInfos_) {
1732 if ((extension.second.bundleName == bundleName) && (extension.second.name == extensionName) &&
1733 (moduleName.empty() || (extension.second.moduleName == moduleName))) {
1734 return extension.second;
1735 }
1736 }
1737 return std::nullopt;
1738 }
1739
FindExtensionInfos(const std::string & bundleName) const1740 std::optional<std::vector<ExtensionAbilityInfo>> InnerBundleInfo::FindExtensionInfos(
1741 const std::string &bundleName) const
1742 {
1743 std::vector<ExtensionAbilityInfo> extensions;
1744
1745 if (bundleName.empty()) {
1746 return std::nullopt;
1747 }
1748
1749 for (const auto &extension : baseExtensionInfos_) {
1750 if ((extension.second.bundleName == bundleName)) {
1751 extensions.emplace_back(extension.second);
1752 }
1753 }
1754 if (!extensions.empty()) {
1755 return extensions;
1756 }
1757
1758 return std::nullopt;
1759 }
1760
AddModuleInfo(const InnerBundleInfo & newInfo)1761 bool InnerBundleInfo::AddModuleInfo(const InnerBundleInfo &newInfo)
1762 {
1763 if (newInfo.currentPackage_.empty()) {
1764 APP_LOGE("current package is empty");
1765 return false;
1766 }
1767 if (FindModule(newInfo.currentPackage_)) {
1768 APP_LOGE("current package %{public}s is exist", currentPackage_.c_str());
1769 return false;
1770 }
1771 AddInnerModuleInfo(newInfo.innerModuleInfos_);
1772 AddModuleAbilityInfo(newInfo.baseAbilityInfos_);
1773 AddModuleSkillInfo(newInfo.skillInfos_);
1774 AddModuleExtensionInfos(newInfo.baseExtensionInfos_);
1775 AddModuleExtensionSkillInfos(newInfo.extensionSkillInfos_);
1776 AddModuleFormInfo(newInfo.formInfos_);
1777 AddModuleShortcutInfo(newInfo.shortcutInfos_);
1778 AddModuleCommonEvent(newInfo.commonEvents_);
1779 return true;
1780 }
1781
UpdateBaseBundleInfo(const BundleInfo & bundleInfo,bool isEntry)1782 void InnerBundleInfo::UpdateBaseBundleInfo(const BundleInfo &bundleInfo, bool isEntry)
1783 {
1784 baseBundleInfo_->name = bundleInfo.name;
1785
1786 baseBundleInfo_->versionCode = bundleInfo.versionCode;
1787 baseBundleInfo_->versionName = bundleInfo.versionName;
1788 baseBundleInfo_->minCompatibleVersionCode = bundleInfo.minCompatibleVersionCode;
1789
1790 baseBundleInfo_->compatibleVersion = bundleInfo.compatibleVersion;
1791 baseBundleInfo_->targetVersion = bundleInfo.targetVersion;
1792
1793 baseBundleInfo_->isKeepAlive = bundleInfo.isKeepAlive;
1794 baseBundleInfo_->singleton = bundleInfo.singleton;
1795 baseBundleInfo_->isPreInstallApp = bundleInfo.isPreInstallApp;
1796
1797 baseBundleInfo_->vendor = bundleInfo.vendor;
1798 baseBundleInfo_->releaseType = bundleInfo.releaseType;
1799 if (!baseBundleInfo_->isNativeApp) {
1800 baseBundleInfo_->isNativeApp = bundleInfo.isNativeApp;
1801 }
1802
1803 if (isEntry) {
1804 baseBundleInfo_->mainEntry = bundleInfo.mainEntry;
1805 baseBundleInfo_->entryModuleName = bundleInfo.entryModuleName;
1806 }
1807 }
1808
UpdateBaseApplicationInfo(const ApplicationInfo & applicationInfo)1809 void InnerBundleInfo::UpdateBaseApplicationInfo(const ApplicationInfo &applicationInfo)
1810 {
1811 baseApplicationInfo_->name = applicationInfo.name;
1812 baseApplicationInfo_->bundleName = applicationInfo.bundleName;
1813
1814 baseApplicationInfo_->versionCode = applicationInfo.versionCode;
1815 baseApplicationInfo_->versionName = applicationInfo.versionName;
1816 baseApplicationInfo_->minCompatibleVersionCode = applicationInfo.minCompatibleVersionCode;
1817
1818 baseApplicationInfo_->apiCompatibleVersion = applicationInfo.apiCompatibleVersion;
1819 baseApplicationInfo_->apiTargetVersion = applicationInfo.apiTargetVersion;
1820
1821 baseApplicationInfo_->iconPath = applicationInfo.iconPath;
1822 baseApplicationInfo_->iconId = applicationInfo.iconId;
1823 baseApplicationInfo_->label = applicationInfo.label;
1824 baseApplicationInfo_->labelId = applicationInfo.labelId;
1825 baseApplicationInfo_->description = applicationInfo.description;
1826 baseApplicationInfo_->descriptionId = applicationInfo.descriptionId;
1827 baseApplicationInfo_->iconResource = applicationInfo.iconResource;
1828 baseApplicationInfo_->labelResource = applicationInfo.labelResource;
1829 baseApplicationInfo_->descriptionResource = applicationInfo.descriptionResource;
1830 baseApplicationInfo_->singleton = applicationInfo.singleton;
1831 baseApplicationInfo_->userDataClearable = applicationInfo.userDataClearable;
1832 baseApplicationInfo_->accessible = applicationInfo.accessible;
1833
1834 if (!baseApplicationInfo_->isSystemApp) {
1835 baseApplicationInfo_->isSystemApp = applicationInfo.isSystemApp;
1836 }
1837 if (!baseApplicationInfo_->isLauncherApp) {
1838 baseApplicationInfo_->isLauncherApp = applicationInfo.isLauncherApp;
1839 }
1840
1841 baseApplicationInfo_->apiReleaseType = applicationInfo.apiReleaseType;
1842 baseApplicationInfo_->debug = applicationInfo.debug;
1843 baseApplicationInfo_->deviceId = applicationInfo.deviceId;
1844 baseApplicationInfo_->distributedNotificationEnabled = applicationInfo.distributedNotificationEnabled;
1845 baseApplicationInfo_->entityType = applicationInfo.entityType;
1846 baseApplicationInfo_->process = applicationInfo.process;
1847 baseApplicationInfo_->supportedModes = applicationInfo.supportedModes;
1848 baseApplicationInfo_->vendor = applicationInfo.vendor;
1849 baseApplicationInfo_->appDistributionType = applicationInfo.appDistributionType;
1850 baseApplicationInfo_->appProvisionType = applicationInfo.appProvisionType;
1851 baseApplicationInfo_->formVisibleNotify = applicationInfo.formVisibleNotify;
1852 baseApplicationInfo_->needAppDetail = applicationInfo.needAppDetail;
1853 baseApplicationInfo_->appDetailAbilityLibraryPath = applicationInfo.appDetailAbilityLibraryPath;
1854 UpdatePrivilegeCapability(applicationInfo);
1855 SetHideDesktopIcon(applicationInfo.hideDesktopIcon);
1856 }
1857
UpdateAppDetailAbilityAttrs()1858 void InnerBundleInfo::UpdateAppDetailAbilityAttrs()
1859 {
1860 bool isExistLauncherAbility = false;
1861 OHOS::AAFwk::Want want;
1862 want.SetAction(OHOS::AAFwk::Want::ACTION_HOME);
1863 want.AddEntity(OHOS::AAFwk::Want::ENTITY_HOME);
1864 for (const auto& abilityInfoPair : baseAbilityInfos_) {
1865 auto skillsPair = skillInfos_.find(abilityInfoPair.first);
1866 if (skillsPair == skillInfos_.end()) {
1867 continue;
1868 }
1869 for (const Skill& skill : skillsPair->second) {
1870 if (skill.MatchLauncher(want) && (abilityInfoPair.second.type == AbilityType::PAGE)) {
1871 isExistLauncherAbility = true;
1872 break;
1873 }
1874 }
1875 }
1876 if (isExistLauncherAbility) {
1877 baseApplicationInfo_->needAppDetail = false;
1878 baseApplicationInfo_->appDetailAbilityLibraryPath = Constants::EMPTY_STRING;
1879 }
1880 for (auto iter = baseAbilityInfos_.begin(); iter != baseAbilityInfos_.end(); ++iter) {
1881 if (iter->second.name == Constants::APP_DETAIL_ABILITY) {
1882 if (!baseApplicationInfo_->needAppDetail) {
1883 baseAbilityInfos_.erase(iter);
1884 return;
1885 }
1886 if (isNewVersion_) {
1887 iter->second.labelId = baseApplicationInfo_->labelId;
1888 if (baseApplicationInfo_->iconId != 0) {
1889 iter->second.iconId = baseApplicationInfo_->iconId;
1890 }
1891 }
1892 return;
1893 }
1894 }
1895 }
1896
UpdateNativeLibAttrs(const ApplicationInfo & applicationInfo)1897 void InnerBundleInfo::UpdateNativeLibAttrs(const ApplicationInfo &applicationInfo)
1898 {
1899 baseApplicationInfo_->cpuAbi = applicationInfo.cpuAbi;
1900 baseApplicationInfo_->nativeLibraryPath = applicationInfo.nativeLibraryPath;
1901 }
1902
UpdateArkNativeAttrs(const ApplicationInfo & applicationInfo)1903 void InnerBundleInfo::UpdateArkNativeAttrs(const ApplicationInfo &applicationInfo)
1904 {
1905 baseApplicationInfo_->arkNativeFileAbi = applicationInfo.arkNativeFileAbi;
1906 baseApplicationInfo_->arkNativeFilePath = applicationInfo.arkNativeFilePath;
1907 }
1908
UpdatePrivilegeCapability(const ApplicationInfo & applicationInfo)1909 void InnerBundleInfo::UpdatePrivilegeCapability(const ApplicationInfo &applicationInfo)
1910 {
1911 SetKeepAlive(applicationInfo.keepAlive);
1912 baseApplicationInfo_->runningResourcesApply = applicationInfo.runningResourcesApply;
1913 baseApplicationInfo_->associatedWakeUp = applicationInfo.associatedWakeUp;
1914 SetAllowCommonEvent(applicationInfo.allowCommonEvent);
1915 }
1916
UpdateRemovable(bool isPreInstall,bool removable)1917 void InnerBundleInfo::UpdateRemovable(bool isPreInstall, bool removable)
1918 {
1919 #ifdef USE_PRE_BUNDLE_PROFILE
1920 if (!isPreInstall) {
1921 return;
1922 }
1923 #endif
1924
1925 baseApplicationInfo_->removable = removable;
1926 }
1927
UpdateModuleInfo(const InnerBundleInfo & newInfo)1928 void InnerBundleInfo::UpdateModuleInfo(const InnerBundleInfo &newInfo)
1929 {
1930 if (newInfo.currentPackage_.empty()) {
1931 APP_LOGE("no package in new info");
1932 return;
1933 }
1934
1935 RemoveModuleInfo(newInfo.currentPackage_);
1936 AddInnerModuleInfo(newInfo.innerModuleInfos_);
1937 AddModuleAbilityInfo(newInfo.baseAbilityInfos_);
1938 AddModuleSkillInfo(newInfo.skillInfos_);
1939 AddModuleExtensionInfos(newInfo.baseExtensionInfos_);
1940 AddModuleExtensionSkillInfos(newInfo.extensionSkillInfos_);
1941 AddModuleFormInfo(newInfo.formInfos_);
1942 AddModuleShortcutInfo(newInfo.shortcutInfos_);
1943 AddModuleCommonEvent(newInfo.commonEvents_);
1944 }
1945
RemoveModuleInfo(const std::string & modulePackage)1946 void InnerBundleInfo::RemoveModuleInfo(const std::string &modulePackage)
1947 {
1948 auto it = innerModuleInfos_.find(modulePackage);
1949 if (it == innerModuleInfos_.end()) {
1950 APP_LOGE("The module(%{public}s) infomation does not exist", modulePackage.c_str());
1951 return;
1952 }
1953
1954 auto oldModuleInfo = it->second;
1955 if (oldModuleInfo.isEntry) {
1956 baseBundleInfo_->mainEntry.clear();
1957 baseBundleInfo_->entryModuleName.clear();
1958 }
1959 innerModuleInfos_.erase(it);
1960 std::string key;
1961 key.append(".").append(modulePackage).append(".");
1962 for (auto iter = shortcutInfos_.begin(); iter != shortcutInfos_.end();) {
1963 if (iter->first.find(key) != std::string::npos) {
1964 shortcutInfos_.erase(iter++);
1965 } else {
1966 ++iter;
1967 }
1968 }
1969
1970 for (auto iter = commonEvents_.begin(); iter != commonEvents_.end();) {
1971 if (iter->first.find(key) != std::string::npos) {
1972 commonEvents_.erase(iter++);
1973 } else {
1974 ++iter;
1975 }
1976 }
1977
1978 // delete old abilityInfos
1979 for (auto abilityKey : oldModuleInfo.abilityKeys) {
1980 auto abilityItem = baseAbilityInfos_.find(abilityKey);
1981 if (abilityItem == baseAbilityInfos_.end()) {
1982 continue;
1983 }
1984
1985 baseAbilityInfos_.erase(abilityItem);
1986 formInfos_.erase(abilityKey);
1987 }
1988
1989 // delete old skillInfos
1990 for (auto skillKey : oldModuleInfo.skillKeys) {
1991 auto skillItem = skillInfos_.find(skillKey);
1992 if (skillItem == skillInfos_.end()) {
1993 continue;
1994 }
1995
1996 skillInfos_.erase(skillItem);
1997 }
1998
1999 // delete old extensionInfos
2000 for (auto extensionKey : oldModuleInfo.extensionKeys) {
2001 auto extensionItem = baseExtensionInfos_.find(extensionKey);
2002 if (extensionItem == baseExtensionInfos_.end()) {
2003 continue;
2004 }
2005
2006 baseExtensionInfos_.erase(extensionItem);
2007 }
2008
2009 // delete old extensionSkillInfos
2010 for (auto extensionSkillKey : oldModuleInfo.extensionSkillKeys) {
2011 auto extensionSkillItem = extensionSkillInfos_.find(extensionSkillKey);
2012 if (extensionSkillItem == extensionSkillInfos_.end()) {
2013 continue;
2014 }
2015
2016 extensionSkillInfos_.erase(extensionSkillItem);
2017 }
2018 }
2019
ToString() const2020 std::string InnerBundleInfo::ToString() const
2021 {
2022 nlohmann::json j;
2023 ToJson(j);
2024 return j.dump();
2025 }
2026
GetApplicationInfo(int32_t flags,int32_t userId,ApplicationInfo & appInfo) const2027 void InnerBundleInfo::GetApplicationInfo(int32_t flags, int32_t userId, ApplicationInfo &appInfo) const
2028 {
2029 InnerBundleUserInfo innerBundleUserInfo;
2030 if (!GetInnerBundleUserInfo(userId, innerBundleUserInfo)) {
2031 APP_LOGE("can not find userId %{public}d when get applicationInfo", userId);
2032 return;
2033 }
2034
2035 appInfo = *baseApplicationInfo_;
2036 if (!CheckAppInstallControl(GetAppId(), userId)) {
2037 appInfo.removable = false;
2038 }
2039 if (!GetHasAtomicServiceConfig()) {
2040 std::vector<std::string> moduleNames;
2041 GetModuleNames(moduleNames);
2042 appInfo.split = moduleNames.size() != 1;
2043 }
2044
2045 appInfo.accessTokenId = innerBundleUserInfo.accessTokenId;
2046 appInfo.enabled = innerBundleUserInfo.bundleUserInfo.enabled;
2047 appInfo.uid = innerBundleUserInfo.uid;
2048
2049 for (const auto &info : innerModuleInfos_) {
2050 ModuleInfo moduleInfo;
2051 moduleInfo.moduleName = info.second.moduleName;
2052 moduleInfo.moduleSourceDir = info.second.modulePath;
2053 moduleInfo.preloads = info.second.preloads;
2054 appInfo.moduleInfos.emplace_back(moduleInfo);
2055 appInfo.moduleSourceDirs.emplace_back(info.second.modulePath);
2056 if (info.second.isEntry) {
2057 appInfo.entryDir = info.second.modulePath;
2058 }
2059 if ((static_cast<uint32_t>(flags) & GET_APPLICATION_INFO_WITH_PERMISSION) ==
2060 GET_APPLICATION_INFO_WITH_PERMISSION) {
2061 std::transform(info.second.requestPermissions.begin(),
2062 info.second.requestPermissions.end(),
2063 std::back_inserter(appInfo.permissions),
2064 [](const auto &p) { return p.name; });
2065 }
2066 if ((static_cast<uint32_t>(flags) & GET_APPLICATION_INFO_WITH_METADATA) == GET_APPLICATION_INFO_WITH_METADATA) {
2067 bool isModuleJson = info.second.isModuleJson;
2068 if (!isModuleJson && info.second.metaData.customizeData.size() > 0) {
2069 appInfo.metaData[info.second.moduleName] = info.second.metaData.customizeData;
2070 }
2071 if (isModuleJson && info.second.metadata.size() > 0) {
2072 appInfo.metadata[info.second.moduleName] = info.second.metadata;
2073 }
2074 }
2075 if ((static_cast<uint32_t>(flags) & GET_APPLICATION_INFO_WITH_CERTIFICATE_FINGERPRINT) !=
2076 GET_APPLICATION_INFO_WITH_CERTIFICATE_FINGERPRINT) {
2077 appInfo.fingerprint.clear();
2078 }
2079 }
2080 if (!appInfo.permissions.empty()) {
2081 RemoveDuplicateName(appInfo.permissions);
2082 }
2083 }
2084
GetApplicationInfoV9(int32_t flags,int32_t userId,ApplicationInfo & appInfo) const2085 ErrCode InnerBundleInfo::GetApplicationInfoV9(int32_t flags, int32_t userId, ApplicationInfo &appInfo) const
2086 {
2087 InnerBundleUserInfo innerBundleUserInfo;
2088 if (!GetInnerBundleUserInfo(userId, innerBundleUserInfo)) {
2089 APP_LOGE("can not find userId %{public}d when get applicationInfo", userId);
2090 return ERR_BUNDLE_MANAGER_INTERNAL_ERROR;
2091 }
2092
2093 appInfo = *baseApplicationInfo_;
2094 if (!CheckAppInstallControl(GetAppId(), userId)) {
2095 appInfo.removable = false;
2096 }
2097 if (!GetHasAtomicServiceConfig()) {
2098 std::vector<std::string> moduleNames;
2099 GetModuleNames(moduleNames);
2100 appInfo.split = moduleNames.size() != 1;
2101 }
2102
2103 appInfo.accessTokenId = innerBundleUserInfo.accessTokenId;
2104 appInfo.enabled = innerBundleUserInfo.bundleUserInfo.enabled;
2105 appInfo.uid = innerBundleUserInfo.uid;
2106
2107 for (const auto &info : innerModuleInfos_) {
2108 ModuleInfo moduleInfo;
2109 moduleInfo.moduleName = info.second.moduleName;
2110 moduleInfo.moduleSourceDir = info.second.modulePath;
2111 moduleInfo.preloads = info.second.preloads;
2112 appInfo.moduleInfos.emplace_back(moduleInfo);
2113 appInfo.moduleSourceDirs.emplace_back(info.second.modulePath);
2114 if (info.second.isEntry) {
2115 appInfo.entryDir = info.second.modulePath;
2116 }
2117 if ((static_cast<uint32_t>(flags) &
2118 static_cast<int32_t>(GetApplicationFlag::GET_APPLICATION_INFO_WITH_PERMISSION)) ==
2119 static_cast<int32_t>(GetApplicationFlag::GET_APPLICATION_INFO_WITH_PERMISSION)) {
2120 std::transform(info.second.requestPermissions.begin(),
2121 info.second.requestPermissions.end(),
2122 std::back_inserter(appInfo.permissions),
2123 [](const auto &p) { return p.name; });
2124 }
2125 if ((static_cast<uint32_t>(flags) &
2126 static_cast<int32_t>(GetApplicationFlag::GET_APPLICATION_INFO_WITH_METADATA)) ==
2127 static_cast<int32_t>(GetApplicationFlag::GET_APPLICATION_INFO_WITH_METADATA)) {
2128 bool isModuleJson = info.second.isModuleJson;
2129 if (!isModuleJson && info.second.metaData.customizeData.size() > 0) {
2130 appInfo.metaData[info.second.moduleName] = info.second.metaData.customizeData;
2131 }
2132 if (isModuleJson && info.second.metadata.size() > 0) {
2133 appInfo.metadata[info.second.moduleName] = info.second.metadata;
2134 }
2135 }
2136 }
2137 if (!appInfo.permissions.empty()) {
2138 RemoveDuplicateName(appInfo.permissions);
2139 }
2140 return ERR_OK;
2141 }
2142
GetBundleInfo(int32_t flags,BundleInfo & bundleInfo,int32_t userId) const2143 bool InnerBundleInfo::GetBundleInfo(int32_t flags, BundleInfo &bundleInfo, int32_t userId) const
2144 {
2145 InnerBundleUserInfo innerBundleUserInfo;
2146 if (!GetInnerBundleUserInfo(userId, innerBundleUserInfo)) {
2147 APP_LOGE("can not find userId %{public}d when GetBundleInfo", userId);
2148 return false;
2149 }
2150
2151 bundleInfo = *baseBundleInfo_;
2152
2153 bundleInfo.uid = innerBundleUserInfo.uid;
2154 if (!innerBundleUserInfo.gids.empty()) {
2155 bundleInfo.gid = innerBundleUserInfo.gids[0];
2156 }
2157 bundleInfo.installTime = innerBundleUserInfo.installTime;
2158 bundleInfo.updateTime = innerBundleUserInfo.updateTime;
2159 bundleInfo.appIndex = appIndex_;
2160
2161 GetApplicationInfo(ApplicationFlag::GET_APPLICATION_INFO_WITH_CERTIFICATE_FINGERPRINT, userId,
2162 bundleInfo.applicationInfo);
2163 for (const auto &info : innerModuleInfos_) {
2164 if ((static_cast<uint32_t>(flags) & GET_BUNDLE_WITH_REQUESTED_PERMISSION)
2165 == GET_BUNDLE_WITH_REQUESTED_PERMISSION) {
2166 std::transform(info.second.requestPermissions.begin(),
2167 info.second.requestPermissions.end(),
2168 std::back_inserter(bundleInfo.reqPermissions),
2169 [](const auto &p) { return p.name; });
2170 std::transform(info.second.definePermissions.begin(),
2171 info.second.definePermissions.end(),
2172 std::back_inserter(bundleInfo.defPermissions),
2173 [](const auto &p) { return p.name; });
2174 }
2175 bundleInfo.hapModuleNames.emplace_back(info.second.modulePackage);
2176 auto hapmoduleinfo = FindHapModuleInfo(info.second.modulePackage, userId);
2177 if (hapmoduleinfo) {
2178 GetModuleWithHashValue(flags, info.second.modulePackage, *hapmoduleinfo);
2179 bundleInfo.hapModuleInfos.emplace_back(*hapmoduleinfo);
2180 bundleInfo.moduleNames.emplace_back(info.second.moduleName);
2181 bundleInfo.moduleDirs.emplace_back(info.second.modulePath);
2182 bundleInfo.modulePublicDirs.emplace_back(info.second.moduleDataDir);
2183 bundleInfo.moduleResPaths.emplace_back(info.second.moduleResPath);
2184 } else {
2185 APP_LOGE("can not find hapmoduleinfo %{public}s", info.second.moduleName.c_str());
2186 }
2187 }
2188 if ((static_cast<uint32_t>(flags) & GET_BUNDLE_WITH_REQUESTED_PERMISSION)
2189 == GET_BUNDLE_WITH_REQUESTED_PERMISSION) {
2190 if (!bundleInfo.reqPermissions.empty()) {
2191 RemoveDuplicateName(bundleInfo.reqPermissions);
2192 }
2193 if (!bundleInfo.defPermissions.empty()) {
2194 RemoveDuplicateName(bundleInfo.defPermissions);
2195 }
2196 if (!BundlePermissionMgr::GetRequestPermissionStates(bundleInfo,
2197 bundleInfo.applicationInfo.accessTokenId, bundleInfo.applicationInfo.deviceId)) {
2198 APP_LOGE("get request permission state failed");
2199 }
2200 bundleInfo.reqPermissionDetails = GetAllRequestPermissions();
2201 }
2202 GetBundleWithAbilities(flags, bundleInfo, userId);
2203 GetBundleWithExtension(flags, bundleInfo, userId);
2204 return true;
2205 }
2206
GetBundleInfoV9(int32_t flags,BundleInfo & bundleInfo,int32_t userId) const2207 ErrCode InnerBundleInfo::GetBundleInfoV9(int32_t flags, BundleInfo &bundleInfo, int32_t userId) const
2208 {
2209 InnerBundleUserInfo innerBundleUserInfo;
2210 if (!GetInnerBundleUserInfo(userId, innerBundleUserInfo)) {
2211 APP_LOGE("can not find userId %{public}d when GetBundleInfo", userId);
2212 return ERR_BUNDLE_MANAGER_INTERNAL_ERROR;
2213 }
2214
2215 bundleInfo = *baseBundleInfo_;
2216
2217 bundleInfo.uid = innerBundleUserInfo.uid;
2218 if (!innerBundleUserInfo.gids.empty()) {
2219 bundleInfo.gid = innerBundleUserInfo.gids[0];
2220 }
2221 bundleInfo.installTime = innerBundleUserInfo.installTime;
2222 bundleInfo.updateTime = innerBundleUserInfo.updateTime;
2223 bundleInfo.appIndex = appIndex_;
2224
2225 for (const auto &info : innerModuleInfos_) {
2226 bundleInfo.hapModuleNames.emplace_back(info.second.modulePackage);
2227 auto hapmoduleinfo = FindHapModuleInfo(info.second.modulePackage, userId);
2228 if (hapmoduleinfo) {
2229 bundleInfo.moduleNames.emplace_back(info.second.moduleName);
2230 bundleInfo.moduleDirs.emplace_back(info.second.modulePath);
2231 bundleInfo.modulePublicDirs.emplace_back(info.second.moduleDataDir);
2232 bundleInfo.moduleResPaths.emplace_back(info.second.moduleResPath);
2233 } else {
2234 APP_LOGE("can not find hapmoduleinfo %{public}s", info.second.moduleName.c_str());
2235 }
2236 }
2237 ProcessBundleFlags(flags, userId, bundleInfo);
2238 return ERR_OK;
2239 }
2240
ProcessBundleFlags(int32_t flags,int32_t userId,BundleInfo & bundleInfo) const2241 void InnerBundleInfo::ProcessBundleFlags(
2242 int32_t flags, int32_t userId, BundleInfo &bundleInfo) const
2243 {
2244 if ((static_cast<uint32_t>(flags) & static_cast<int32_t>(GetBundleInfoFlag::GET_BUNDLE_INFO_WITH_APPLICATION))
2245 == static_cast<int32_t>(GetBundleInfoFlag::GET_BUNDLE_INFO_WITH_APPLICATION)) {
2246 if ((static_cast<uint32_t>(flags) & static_cast<int32_t>(GetBundleInfoFlag::GET_BUNDLE_INFO_WITH_METADATA))
2247 == static_cast<int32_t>(GetBundleInfoFlag::GET_BUNDLE_INFO_WITH_METADATA)) {
2248 GetApplicationInfoV9(static_cast<int32_t>(GetApplicationFlag::GET_APPLICATION_INFO_WITH_METADATA), userId,
2249 bundleInfo.applicationInfo);
2250 } else {
2251 GetApplicationInfoV9(static_cast<int32_t>(GetApplicationFlag::GET_APPLICATION_INFO_DEFAULT), userId,
2252 bundleInfo.applicationInfo);
2253 }
2254 }
2255 GetBundleWithReqPermissionsV9(flags, userId, bundleInfo);
2256 ProcessBundleWithHapModuleInfoFlag(flags, bundleInfo, userId);
2257 if ((static_cast<uint32_t>(flags) & static_cast<int32_t>(GetBundleInfoFlag::GET_BUNDLE_INFO_WITH_SIGNATURE_INFO))
2258 == static_cast<int32_t>(GetBundleInfoFlag::GET_BUNDLE_INFO_WITH_SIGNATURE_INFO)) {
2259 bundleInfo.signatureInfo.appId = baseBundleInfo_->appId;
2260 bundleInfo.signatureInfo.fingerprint = baseApplicationInfo_->fingerprint;
2261 }
2262 }
2263
GetBundleWithReqPermissionsV9(int32_t flags,uint32_t userId,BundleInfo & bundleInfo) const2264 void InnerBundleInfo::GetBundleWithReqPermissionsV9(int32_t flags, uint32_t userId, BundleInfo &bundleInfo) const
2265 {
2266 if ((static_cast<uint32_t>(flags) &
2267 static_cast<int32_t>(GetBundleInfoFlag::GET_BUNDLE_INFO_WITH_REQUESTED_PERMISSION))
2268 != static_cast<int32_t>(GetBundleInfoFlag::GET_BUNDLE_INFO_WITH_REQUESTED_PERMISSION)) {
2269 return;
2270 }
2271 for (const auto &info : innerModuleInfos_) {
2272 std::transform(info.second.requestPermissions.begin(),
2273 info.second.requestPermissions.end(),
2274 std::back_inserter(bundleInfo.reqPermissions),
2275 [](const auto &p) { return p.name; });
2276 std::transform(info.second.definePermissions.begin(),
2277 info.second.definePermissions.end(),
2278 std::back_inserter(bundleInfo.defPermissions),
2279 [](const auto &p) { return p.name; });
2280 }
2281 if (!bundleInfo.reqPermissions.empty()) {
2282 RemoveDuplicateName(bundleInfo.reqPermissions);
2283 }
2284 if (!bundleInfo.defPermissions.empty()) {
2285 RemoveDuplicateName(bundleInfo.defPermissions);
2286 }
2287 InnerBundleUserInfo innerBundleUserInfo;
2288 if (!GetInnerBundleUserInfo(userId, innerBundleUserInfo)) {
2289 APP_LOGE("can not find userId %{public}d when get applicationInfo", userId);
2290 return;
2291 }
2292 uint32_t tokenId = innerBundleUserInfo.accessTokenId;
2293 std::string deviceId = baseApplicationInfo_->deviceId;
2294 if (!BundlePermissionMgr::GetRequestPermissionStates(bundleInfo, tokenId, deviceId)) {
2295 APP_LOGE("get request permission state failed");
2296 }
2297 bundleInfo.reqPermissionDetails = GetAllRequestPermissions();
2298 }
2299
GetModuleWithHashValue(int32_t flags,const std::string & modulePackage,HapModuleInfo & hapModuleInfo) const2300 void InnerBundleInfo::GetModuleWithHashValue(
2301 int32_t flags, const std::string &modulePackage, HapModuleInfo &hapModuleInfo) const
2302 {
2303 if (!(static_cast<uint32_t>(flags) & GET_BUNDLE_WITH_HASH_VALUE)) {
2304 return;
2305 }
2306
2307 auto it = innerModuleInfos_.find(modulePackage);
2308 if (it == innerModuleInfos_.end()) {
2309 APP_LOGE("can not find module %{public}s", modulePackage.c_str());
2310 return;
2311 }
2312
2313 hapModuleInfo.hashValue = it->second.hashValue;
2314 }
2315
ProcessBundleWithHapModuleInfoFlag(int32_t flags,BundleInfo & bundleInfo,int32_t userId) const2316 void InnerBundleInfo::ProcessBundleWithHapModuleInfoFlag(int32_t flags, BundleInfo &bundleInfo, int32_t userId) const
2317 {
2318 if ((static_cast<uint32_t>(flags) & static_cast<int32_t>(GetBundleInfoFlag::GET_BUNDLE_INFO_WITH_HAP_MODULE))
2319 != static_cast<int32_t>(GetBundleInfoFlag::GET_BUNDLE_INFO_WITH_HAP_MODULE)) {
2320 bundleInfo.hapModuleInfos.clear();
2321 return;
2322 }
2323 for (const auto &info : innerModuleInfos_) {
2324 auto hapmoduleinfo = FindHapModuleInfo(info.second.modulePackage, userId);
2325 if (hapmoduleinfo) {
2326 HapModuleInfo hapModuleInfo = *hapmoduleinfo;
2327 auto it = innerModuleInfos_.find(info.second.modulePackage);
2328 if (it == innerModuleInfos_.end()) {
2329 APP_LOGE("can not find module %{public}s", info.second.modulePackage.c_str());
2330 } else {
2331 hapModuleInfo.hashValue = it->second.hashValue;
2332 }
2333 hapModuleInfo.moduleSourceDir = info.second.modulePath;
2334 if ((static_cast<uint32_t>(flags) & static_cast<int32_t>(GetBundleInfoFlag::GET_BUNDLE_INFO_WITH_METADATA))
2335 != static_cast<int32_t>(GetBundleInfoFlag::GET_BUNDLE_INFO_WITH_METADATA)) {
2336 hapModuleInfo.metadata.clear();
2337 }
2338
2339 GetBundleWithAbilitiesV9(flags, hapModuleInfo, userId);
2340 GetBundleWithExtensionAbilitiesV9(flags, hapModuleInfo);
2341 bundleInfo.hapModuleInfos.emplace_back(hapModuleInfo);
2342 }
2343 }
2344 }
2345
GetBundleWithAbilitiesV9(int32_t flags,HapModuleInfo & hapModuleInfo,int32_t userId) const2346 void InnerBundleInfo::GetBundleWithAbilitiesV9(int32_t flags, HapModuleInfo &hapModuleInfo, int32_t userId) const
2347 {
2348 hapModuleInfo.abilityInfos.clear();
2349 if ((static_cast<uint32_t>(flags) & static_cast<int32_t>(GetBundleInfoFlag::GET_BUNDLE_INFO_WITH_ABILITY))
2350 != static_cast<int32_t>(GetBundleInfoFlag::GET_BUNDLE_INFO_WITH_ABILITY)) {
2351 return;
2352 }
2353 APP_LOGD("Get bundleInfo with abilities.");
2354 for (auto &ability : baseAbilityInfos_) {
2355 if ((ability.second.moduleName != hapModuleInfo.moduleName) ||
2356 (ability.second.name == Constants::APP_DETAIL_ABILITY)) {
2357 continue;
2358 }
2359 bool isEnabled = IsAbilityEnabled(ability.second, userId);
2360 if (!(static_cast<uint32_t>(flags) & static_cast<int32_t>(GetBundleInfoFlag::GET_BUNDLE_INFO_WITH_DISABLE))
2361 && !isEnabled) {
2362 APP_LOGW("%{public}s is disabled,", ability.second.name.c_str());
2363 continue;
2364 }
2365 AbilityInfo abilityInfo = ability.second;
2366 abilityInfo.enabled = isEnabled;
2367
2368 if ((static_cast<uint32_t>(flags) & static_cast<int32_t>(GetBundleInfoFlag::GET_BUNDLE_INFO_WITH_METADATA))
2369 != static_cast<int32_t>(GetBundleInfoFlag::GET_BUNDLE_INFO_WITH_METADATA)) {
2370 abilityInfo.metaData.customizeData.clear();
2371 abilityInfo.metadata.clear();
2372 }
2373 hapModuleInfo.abilityInfos.emplace_back(abilityInfo);
2374 }
2375 }
2376
GetBundleWithExtensionAbilitiesV9(int32_t flags,HapModuleInfo & hapModuleInfo) const2377 void InnerBundleInfo::GetBundleWithExtensionAbilitiesV9(int32_t flags, HapModuleInfo &hapModuleInfo) const
2378 {
2379 hapModuleInfo.extensionInfos.clear();
2380 if ((static_cast<uint32_t>(flags) &
2381 static_cast<int32_t>(GetBundleInfoFlag::GET_BUNDLE_INFO_WITH_EXTENSION_ABILITY))
2382 != static_cast<int32_t>(GetBundleInfoFlag::GET_BUNDLE_INFO_WITH_EXTENSION_ABILITY)) {
2383 return;
2384 }
2385 APP_LOGD("Get bundleInfo with extensionAbilities.");
2386 for (const auto &extensionInfo : baseExtensionInfos_) {
2387 if (extensionInfo.second.moduleName != hapModuleInfo.moduleName || !extensionInfo.second.enabled) {
2388 continue;
2389 }
2390 ExtensionAbilityInfo info = extensionInfo.second;
2391
2392 if ((static_cast<uint32_t>(flags) & static_cast<int32_t>(GetBundleInfoFlag::GET_BUNDLE_INFO_WITH_METADATA))
2393 != static_cast<int32_t>(GetBundleInfoFlag::GET_BUNDLE_INFO_WITH_METADATA)) {
2394 info.metadata.clear();
2395 }
2396 hapModuleInfo.extensionInfos.emplace_back(info);
2397 }
2398 }
2399
GetBundleWithAbilities(int32_t flags,BundleInfo & bundleInfo,int32_t userId) const2400 void InnerBundleInfo::GetBundleWithAbilities(int32_t flags, BundleInfo &bundleInfo, int32_t userId) const
2401 {
2402 APP_LOGD("bundleName:%{public}s userid:%{public}d", bundleInfo.name.c_str(), userId);
2403 if (static_cast<uint32_t>(flags) & GET_BUNDLE_WITH_ABILITIES) {
2404 for (auto &ability : baseAbilityInfos_) {
2405 if (ability.second.name == Constants::APP_DETAIL_ABILITY) {
2406 continue;
2407 }
2408 bool isEnabled = IsAbilityEnabled(ability.second, userId);
2409 if (!(static_cast<uint32_t>(flags) & GET_ABILITY_INFO_WITH_DISABLE)
2410 && !isEnabled) {
2411 APP_LOGW("%{public}s is disabled,", ability.second.name.c_str());
2412 continue;
2413 }
2414 AbilityInfo abilityInfo = ability.second;
2415 abilityInfo.enabled = isEnabled;
2416 bundleInfo.abilityInfos.emplace_back(abilityInfo);
2417 }
2418 }
2419 }
2420
GetBundleWithExtension(int32_t flags,BundleInfo & bundleInfo,int32_t userId) const2421 void InnerBundleInfo::GetBundleWithExtension(int32_t flags, BundleInfo &bundleInfo, int32_t userId) const
2422 {
2423 APP_LOGD("get bundleInfo with extensionInfo begin");
2424 if ((static_cast<uint32_t>(flags) & GET_BUNDLE_WITH_EXTENSION_INFO) == GET_BUNDLE_WITH_EXTENSION_INFO) {
2425 for (const auto &extensionInfo : baseExtensionInfos_) {
2426 if (!extensionInfo.second.enabled) {
2427 continue;
2428 }
2429 ExtensionAbilityInfo info = extensionInfo.second;
2430 bundleInfo.extensionInfos.emplace_back(info);
2431 }
2432 }
2433 APP_LOGD("get bundleInfo with extensionInfo end");
2434 }
2435
CheckSpecialMetaData(const std::string & metaData) const2436 bool InnerBundleInfo::CheckSpecialMetaData(const std::string &metaData) const
2437 {
2438 if (isNewVersion_) {
2439 for (const auto &moduleInfo : innerModuleInfos_) {
2440 for (const auto &data : moduleInfo.second.metadata) {
2441 if (metaData == data.name) {
2442 return true;
2443 }
2444 }
2445 }
2446 return false;
2447 }
2448 // old version
2449 for (const auto &moduleInfo : innerModuleInfos_) {
2450 for (const auto &data : moduleInfo.second.metaData.customizeData) {
2451 if (metaData == data.name) {
2452 return true;
2453 }
2454 }
2455 }
2456 return false;
2457 }
2458
GetFormsInfoByModule(const std::string & moduleName,std::vector<FormInfo> & formInfos) const2459 void InnerBundleInfo::GetFormsInfoByModule(const std::string &moduleName, std::vector<FormInfo> &formInfos) const
2460 {
2461 for (const auto &data : formInfos_) {
2462 for (auto &form : data.second) {
2463 if (form.moduleName == moduleName) {
2464 formInfos.emplace_back(form);
2465 }
2466 }
2467 }
2468 }
2469
GetFormsInfoByApp(std::vector<FormInfo> & formInfos) const2470 void InnerBundleInfo::GetFormsInfoByApp(std::vector<FormInfo> &formInfos) const
2471 {
2472 for (const auto &data : formInfos_) {
2473 std::copy(data.second.begin(), data.second.end(), std::back_inserter(formInfos));
2474 }
2475 }
2476
GetShortcutInfos(std::vector<ShortcutInfo> & shortcutInfos) const2477 void InnerBundleInfo::GetShortcutInfos(std::vector<ShortcutInfo> &shortcutInfos) const
2478 {
2479 if (isNewVersion_) {
2480 AbilityInfo abilityInfo;
2481 GetMainAbilityInfo(abilityInfo);
2482 if ((!abilityInfo.resourcePath.empty() || !abilityInfo.hapPath.empty())
2483 && abilityInfo.metadata.size() > 0) {
2484 std::vector<std::string> rawJson;
2485 BundleMgrClient bundleMgrClient;
2486 bool ret = bundleMgrClient.GetResConfigFile(abilityInfo, META_DATA_SHORTCUTS_NAME, rawJson);
2487 if (!ret) {
2488 APP_LOGD("GetResConfigFile return false");
2489 return;
2490 }
2491 if (rawJson.size() == 0) {
2492 APP_LOGD("rawJson size 0. skip.");
2493 return;
2494 }
2495 nlohmann::json jsonObject = nlohmann::json::parse(rawJson[0], nullptr, false);
2496 if (jsonObject.is_discarded()) {
2497 APP_LOGE("shortcuts json invalid");
2498 return;
2499 }
2500 ShortcutJson shortcutJson = jsonObject.get<ShortcutJson>();
2501 for (const Shortcut &item : shortcutJson.shortcuts) {
2502 ShortcutInfo shortcutInfo;
2503 shortcutInfo.id = item.shortcutId;
2504 shortcutInfo.bundleName = abilityInfo.bundleName;
2505 shortcutInfo.moduleName = abilityInfo.moduleName;
2506 shortcutInfo.icon = item.icon;
2507 shortcutInfo.label = item.label;
2508 shortcutInfo.iconId = item.iconId;
2509 shortcutInfo.labelId = item.labelId;
2510 for (const ShortcutWant &shortcutWant : item.wants) {
2511 ShortcutIntent shortcutIntent;
2512 shortcutIntent.targetBundle = shortcutWant.bundleName;
2513 shortcutIntent.targetModule = shortcutWant.moduleName;
2514 shortcutIntent.targetClass = shortcutWant.abilityName;
2515 shortcutInfo.intents.emplace_back(shortcutIntent);
2516 }
2517 shortcutInfos.emplace_back(shortcutInfo);
2518 }
2519 }
2520 return;
2521 }
2522 for (const auto &shortcut : shortcutInfos_) {
2523 shortcutInfos.emplace_back(shortcut.second);
2524 }
2525 }
2526
GetCommonEvents(const std::string & eventKey,std::vector<CommonEventInfo> & commonEvents) const2527 void InnerBundleInfo::GetCommonEvents(const std::string &eventKey, std::vector<CommonEventInfo> &commonEvents) const
2528 {
2529 CommonEventInfo item;
2530 for (const auto &commonEvent : commonEvents_) {
2531 for (const auto &event : commonEvent.second.events) {
2532 if (event == eventKey) {
2533 item = commonEvent.second;
2534 item.uid = GetUid(GetUserId());
2535 commonEvents.emplace_back(item);
2536 break;
2537 }
2538 }
2539 }
2540 }
2541
GetInnerModuleInfoByModuleName(const std::string & moduleName) const2542 std::optional<InnerModuleInfo> InnerBundleInfo::GetInnerModuleInfoByModuleName(const std::string &moduleName) const
2543 {
2544 for (const auto &innerModuleInfo : innerModuleInfos_) {
2545 APP_LOGD("info.moduleName = %{public}s, moduleName= %{public}s",
2546 innerModuleInfo.second.moduleName.c_str(), moduleName.c_str());
2547 if (innerModuleInfo.second.moduleName == moduleName) {
2548 return innerModuleInfo.second;
2549 }
2550 }
2551 return std::nullopt;
2552 }
2553
GetModuleNames(std::vector<std::string> & moduleNames) const2554 void InnerBundleInfo::GetModuleNames(std::vector<std::string> &moduleNames) const
2555 {
2556 for (const auto &innerModuleInfo : innerModuleInfos_) {
2557 moduleNames.emplace_back(innerModuleInfo.second.moduleName);
2558 }
2559 }
2560
CheckAppInstallControl(const std::string & appId,int32_t userId) const2561 bool InnerBundleInfo::CheckAppInstallControl(const std::string &appId, int32_t userId) const
2562 {
2563 #ifdef BUNDLE_FRAMEWORK_APP_CONTROL
2564 std::vector<std::string> appIds;
2565 ErrCode ret = DelayedSingleton<AppControlManager>::GetInstance()->GetAppInstallControlRule(
2566 AppControlConstants::EDM_CALLING, AppControlConstants::APP_DISALLOWED_UNINSTALL, userId, appIds);
2567 if (ret != ERR_OK) {
2568 APP_LOGE("GetAppInstallControlRule failed code:%{public}d", ret);
2569 return true;
2570 }
2571 if (std::find(appIds.begin(), appIds.end(), appId) == appIds.end()) {
2572 return true;
2573 }
2574 APP_LOGW("appId is not removable");
2575 return false;
2576 #else
2577 APP_LOGW("app control is disable");
2578 return true;
2579 #endif
2580 }
2581
ResetBundleState(int32_t userId)2582 void InnerBundleInfo::ResetBundleState(int32_t userId)
2583 {
2584 if (userId == Constants::ALL_USERID) {
2585 for (auto& innerBundleUserInfo : innerBundleUserInfos_) {
2586 innerBundleUserInfo.second.bundleUserInfo.Reset();
2587 }
2588
2589 return;
2590 }
2591
2592 auto& key = NameAndUserIdToKey(GetBundleName(), userId);
2593 if (innerBundleUserInfos_.find(key) == innerBundleUserInfos_.end()) {
2594 APP_LOGD("no this user %{public}s", key.c_str());
2595 return;
2596 }
2597
2598 innerBundleUserInfos_.at(key).bundleUserInfo.Reset();
2599 }
2600
RemoveInnerBundleUserInfo(int32_t userId)2601 void InnerBundleInfo::RemoveInnerBundleUserInfo(int32_t userId)
2602 {
2603 auto& key = NameAndUserIdToKey(GetBundleName(), userId);
2604 auto infoItem = innerBundleUserInfos_.find(key);
2605 if (infoItem == innerBundleUserInfos_.end()) {
2606 return;
2607 }
2608
2609 auto result = innerBundleUserInfos_.erase(key);
2610 if (result == 0) {
2611 APP_LOGE("remove userId:%{public}d key:%{public}s info failed", userId, key.c_str());
2612 }
2613 for (auto &innerModuleInfo : innerModuleInfos_) {
2614 DeleteModuleRemovable(innerModuleInfo.second.moduleName, userId);
2615 }
2616 }
2617
AddInnerBundleUserInfo(const InnerBundleUserInfo & innerBundleUserInfo)2618 void InnerBundleInfo::AddInnerBundleUserInfo(
2619 const InnerBundleUserInfo& innerBundleUserInfo)
2620 {
2621 auto& key = NameAndUserIdToKey(
2622 GetBundleName(), innerBundleUserInfo.bundleUserInfo.userId);
2623 auto infoItem = innerBundleUserInfos_.find(key);
2624 if (infoItem == innerBundleUserInfos_.end()) {
2625 innerBundleUserInfos_.emplace(key, innerBundleUserInfo);
2626 return;
2627 }
2628
2629 innerBundleUserInfos_[key] = innerBundleUserInfo;
2630 }
2631
GetInnerBundleUserInfo(int32_t userId,InnerBundleUserInfo & innerBundleUserInfo) const2632 bool InnerBundleInfo::GetInnerBundleUserInfo(
2633 int32_t userId, InnerBundleUserInfo& innerBundleUserInfo) const
2634 {
2635 if (userId == Constants::NOT_EXIST_USERID) {
2636 return true;
2637 }
2638
2639 if (userId == Constants::ALL_USERID) {
2640 if (innerBundleUserInfos_.empty()) {
2641 return false;
2642 }
2643
2644 innerBundleUserInfo = innerBundleUserInfos_.begin()->second;
2645 return true;
2646 }
2647
2648 auto& key = NameAndUserIdToKey(GetBundleName(), userId);
2649 auto infoItem = innerBundleUserInfos_.find(key);
2650 if (infoItem == innerBundleUserInfos_.end()) {
2651 return false;
2652 }
2653
2654 innerBundleUserInfo = infoItem->second;
2655 return true;
2656 }
2657
HasInnerBundleUserInfo(int32_t userId) const2658 bool InnerBundleInfo::HasInnerBundleUserInfo(int32_t userId) const
2659 {
2660 if (userId == Constants::ALL_USERID) {
2661 return !innerBundleUserInfos_.empty();
2662 }
2663
2664 auto& key = NameAndUserIdToKey(GetBundleName(), userId);
2665 auto infoItem = innerBundleUserInfos_.find(key);
2666 return infoItem != innerBundleUserInfos_.end();
2667 }
2668
SetBundleInstallTime(const int64_t time,int32_t userId)2669 void InnerBundleInfo::SetBundleInstallTime(const int64_t time, int32_t userId)
2670 {
2671 auto& key = NameAndUserIdToKey(GetBundleName(), userId);
2672 auto infoItem = innerBundleUserInfos_.find(key);
2673 if (infoItem == innerBundleUserInfos_.end()) {
2674 return;
2675 }
2676
2677 infoItem->second.installTime = time;
2678 infoItem->second.updateTime = time;
2679 }
2680
SetAccessTokenId(uint32_t accessToken,const int32_t userId)2681 void InnerBundleInfo::SetAccessTokenId(uint32_t accessToken, const int32_t userId)
2682 {
2683 auto& key = NameAndUserIdToKey(GetBundleName(), userId);
2684 auto infoItem = innerBundleUserInfos_.find(key);
2685 if (infoItem == innerBundleUserInfos_.end()) {
2686 return;
2687 }
2688
2689 infoItem->second.accessTokenId = accessToken;
2690 }
2691
SetBundleUpdateTime(const int64_t time,int32_t userId)2692 void InnerBundleInfo::SetBundleUpdateTime(const int64_t time, int32_t userId)
2693 {
2694 auto& key = NameAndUserIdToKey(GetBundleName(), userId);
2695 auto infoItem = innerBundleUserInfos_.find(key);
2696 if (infoItem == innerBundleUserInfos_.end()) {
2697 return;
2698 }
2699
2700 infoItem->second.updateTime = time;
2701 }
2702
IsAbilityEnabled(const AbilityInfo & abilityInfo,int32_t userId) const2703 bool InnerBundleInfo::IsAbilityEnabled(const AbilityInfo &abilityInfo, int32_t userId) const
2704 {
2705 APP_LOGD("IsAbilityEnabled bundleName:%{public}s, userId:%{public}d", abilityInfo.bundleName.c_str(), userId);
2706 if (userId == Constants::NOT_EXIST_USERID) {
2707 return true;
2708 }
2709 auto& key = NameAndUserIdToKey(abilityInfo.bundleName, userId);
2710 auto infoItem = innerBundleUserInfos_.find(key);
2711 if (infoItem == innerBundleUserInfos_.end()) {
2712 APP_LOGE("innerBundleUserInfos find key:%{public}s, error", key.c_str());
2713 return false;
2714 }
2715 auto disabledAbilities = infoItem->second.bundleUserInfo.disabledAbilities;
2716 if (std::find(disabledAbilities.begin(), disabledAbilities.end(), abilityInfo.name) != disabledAbilities.end()) {
2717 return false;
2718 } else {
2719 return true;
2720 }
2721 }
2722
IsAbilityEnabledV9(const AbilityInfo & abilityInfo,int32_t userId,bool & isEnable) const2723 ErrCode InnerBundleInfo::IsAbilityEnabledV9(const AbilityInfo &abilityInfo, int32_t userId, bool &isEnable) const
2724 {
2725 APP_LOGD("IsAbilityEnabled bundleName:%{public}s, userId:%{public}d", abilityInfo.bundleName.c_str(), userId);
2726 if (userId == Constants::NOT_EXIST_USERID) {
2727 isEnable = true;
2728 return ERR_OK;
2729 }
2730 auto& key = NameAndUserIdToKey(abilityInfo.bundleName, userId);
2731 auto infoItem = innerBundleUserInfos_.find(key);
2732 if (infoItem == innerBundleUserInfos_.end()) {
2733 APP_LOGE("innerBundleUserInfos find key:%{public}s, error", key.c_str());
2734 return ERR_BUNDLE_MANAGER_BUNDLE_NOT_EXIST;
2735 }
2736 auto disabledAbilities = infoItem->second.bundleUserInfo.disabledAbilities;
2737 if (std::find(disabledAbilities.begin(), disabledAbilities.end(), abilityInfo.name) != disabledAbilities.end()) {
2738 isEnable = false;
2739 } else {
2740 isEnable = true;
2741 }
2742 return ERR_OK;
2743 }
2744
SetAbilityEnabled(const std::string & bundleName,const std::string & moduleName,const std::string & abilityName,bool isEnabled,int32_t userId)2745 ErrCode InnerBundleInfo::SetAbilityEnabled(const std::string &bundleName, const std::string &moduleName,
2746 const std::string &abilityName, bool isEnabled, int32_t userId)
2747 {
2748 APP_LOGD("SetAbilityEnabled :%{public}s, %{public}s, %{public}s, %{public}d",
2749 bundleName.c_str(), moduleName.c_str(), abilityName.c_str(), userId);
2750 for (const auto &ability : baseAbilityInfos_) {
2751 if ((ability.second.bundleName == bundleName) && (ability.second.name == abilityName) &&
2752 (moduleName.empty() || (ability.second.moduleName == moduleName))) {
2753 auto &key = NameAndUserIdToKey(bundleName, userId);
2754 auto infoItem = innerBundleUserInfos_.find(key);
2755 if (infoItem == innerBundleUserInfos_.end()) {
2756 APP_LOGE("SetAbilityEnabled find innerBundleUserInfo failed");
2757 return ERR_BUNDLE_MANAGER_BUNDLE_NOT_EXIST;
2758 }
2759 auto iter = std::find(infoItem->second.bundleUserInfo.disabledAbilities.begin(),
2760 infoItem->second.bundleUserInfo.disabledAbilities.end(),
2761 abilityName);
2762 if (iter != infoItem->second.bundleUserInfo.disabledAbilities.end()) {
2763 if (isEnabled) {
2764 infoItem->second.bundleUserInfo.disabledAbilities.erase(iter);
2765 }
2766 } else {
2767 if (!isEnabled) {
2768 infoItem->second.bundleUserInfo.disabledAbilities.push_back(abilityName);
2769 }
2770 }
2771 return ERR_OK;
2772 }
2773 }
2774 APP_LOGE("SetAbilityEnabled find abilityInfo failed");
2775 return ERR_BUNDLE_MANAGER_ABILITY_NOT_EXIST;
2776 }
2777
RemoveDuplicateName(std::vector<std::string> & name) const2778 void InnerBundleInfo::RemoveDuplicateName(std::vector<std::string> &name) const
2779 {
2780 std::sort(name.begin(), name.end());
2781 auto iter = std::unique(name.begin(), name.end());
2782 name.erase(iter, name.end());
2783 }
2784
GetAllDefinePermissions() const2785 std::vector<DefinePermission> InnerBundleInfo::GetAllDefinePermissions() const
2786 {
2787 std::vector<DefinePermission> definePermissions;
2788 for (const auto &info : innerModuleInfos_) {
2789 std::transform(info.second.definePermissions.begin(),
2790 info.second.definePermissions.end(),
2791 std::back_inserter(definePermissions),
2792 [](const auto &p) { return p; });
2793 }
2794 if (!definePermissions.empty()) {
2795 std::sort(definePermissions.begin(), definePermissions.end(),
2796 [](DefinePermission defPermA, DefinePermission defPermB) {
2797 return defPermA.name < defPermB.name;
2798 });
2799 auto iter = std::unique(definePermissions.begin(), definePermissions.end(),
2800 [](DefinePermission defPermA, DefinePermission defPermB) {
2801 return defPermA.name == defPermB.name;
2802 });
2803 definePermissions.erase(iter, definePermissions.end());
2804 }
2805 return definePermissions;
2806 }
2807
GetAllRequestPermissions() const2808 std::vector<RequestPermission> InnerBundleInfo::GetAllRequestPermissions() const
2809 {
2810 std::vector<RequestPermission> requestPermissions;
2811 for (const auto &info : innerModuleInfos_) {
2812 std::transform(info.second.requestPermissions.begin(),
2813 info.second.requestPermissions.end(),
2814 std::back_inserter(requestPermissions),
2815 [](const auto &p) { return p; });
2816 }
2817 if (!requestPermissions.empty()) {
2818 std::sort(requestPermissions.begin(), requestPermissions.end(),
2819 [](RequestPermission reqPermA, RequestPermission reqPermB) {
2820 return reqPermA.name < reqPermB.name;
2821 });
2822 auto iter = std::unique(requestPermissions.begin(), requestPermissions.end(),
2823 [](RequestPermission reqPermA, RequestPermission reqPermB) {
2824 return reqPermA.name == reqPermB.name;
2825 });
2826 requestPermissions.erase(iter, requestPermissions.end());
2827 }
2828 return requestPermissions;
2829 }
2830
SetApplicationEnabled(bool enabled,int32_t userId)2831 ErrCode InnerBundleInfo::SetApplicationEnabled(bool enabled, int32_t userId)
2832 {
2833 auto& key = NameAndUserIdToKey(GetBundleName(), userId);
2834 auto infoItem = innerBundleUserInfos_.find(key);
2835 if (infoItem == innerBundleUserInfos_.end()) {
2836 APP_LOGE("SetApplicationEnabled can not find:%{public}s bundleUserInfo in userId: %{public}d",
2837 GetBundleName().c_str(), userId);
2838 return ERR_BUNDLE_MANAGER_BUNDLE_NOT_EXIST;
2839 }
2840
2841 infoItem->second.bundleUserInfo.enabled = enabled;
2842 return ERR_OK;
2843 }
2844
GetCurModuleName() const2845 const std::string &InnerBundleInfo::GetCurModuleName() const
2846 {
2847 if (innerModuleInfos_.find(currentPackage_) != innerModuleInfos_.end()) {
2848 return innerModuleInfos_.at(currentPackage_).moduleName;
2849 }
2850
2851 return Constants::EMPTY_STRING;
2852 }
2853
IsBundleRemovable(int32_t userId) const2854 bool InnerBundleInfo::IsBundleRemovable(int32_t userId) const
2855 {
2856 APP_LOGD("userId is %{public}d", userId);
2857 if (IsPreInstallApp()) {
2858 APP_LOGE("PreInstallApp should not be cleaned");
2859 return false;
2860 }
2861 for (const auto &innerModuleInfo : innerModuleInfos_) {
2862 bool isRemovable = true;
2863 if ((IsModuleRemovable(innerModuleInfo.second.moduleName, userId, isRemovable) == ERR_OK) &&
2864 !isRemovable) {
2865 APP_LOGE("not all haps should be cleaned");
2866 return false;
2867 }
2868 }
2869 APP_LOGD("this bundle should be cleaned");
2870 return true;
2871 }
2872
IsUserExistModule(const std::string & moduleName,int32_t userId) const2873 bool InnerBundleInfo::IsUserExistModule(const std::string &moduleName, int32_t userId) const
2874 {
2875 std::string stringUserId = "";
2876 stringUserId.append(std::to_string(userId));
2877 APP_LOGD("userId:%{public}d moduleName:%{public}s", userId, moduleName.c_str());
2878 auto modInfoItem = GetInnerModuleInfoByModuleName(moduleName);
2879 if (!modInfoItem) {
2880 APP_LOGE("get InnerModuleInfo by moduleName(%{public}s) failed", moduleName.c_str());
2881 return false;
2882 }
2883 auto item = modInfoItem->isRemovable.find(stringUserId);
2884 if (item == modInfoItem->isRemovable.end()) {
2885 APP_LOGE("userId:%{public}d has not moduleName:%{public}s", userId, moduleName.c_str());
2886 return false;
2887 }
2888 APP_LOGD("userId:%{public}d exist moduleName:%{public}s", userId, moduleName.c_str());
2889 return true;
2890 }
2891
IsModuleRemovable(const std::string & moduleName,int32_t userId,bool & isRemovable) const2892 ErrCode InnerBundleInfo::IsModuleRemovable(const std::string &moduleName, int32_t userId,
2893 bool &isRemovable) const
2894 {
2895 std::string stringUserId = "";
2896 stringUserId.append(std::to_string(userId));
2897 APP_LOGD("userId:%{public}d moduleName:%{public}s", userId, moduleName.c_str());
2898 auto modInfoItem = GetInnerModuleInfoByModuleName(moduleName);
2899 if (!modInfoItem) {
2900 APP_LOGE("get InnerModuleInfo by moduleName(%{public}s) failed", moduleName.c_str());
2901 return ERR_BUNDLE_MANAGER_MODULE_NOT_EXIST;
2902 }
2903 auto item = modInfoItem->isRemovable.find(stringUserId);
2904 if (item == modInfoItem->isRemovable.end()) {
2905 APP_LOGW("userId:%{public}d has not moduleName:%{public}s", userId, moduleName.c_str());
2906 isRemovable = false;
2907 return ERR_OK;
2908 }
2909 isRemovable = item->second;
2910 APP_LOGD("userId:%{public}d, moduleName:%{public}s, isRemovable:%{public}d,", userId, moduleName.c_str(),
2911 isRemovable);
2912 return ERR_OK;
2913 }
2914
AddModuleRemovableInfo(InnerModuleInfo & info,const std::string & stringUserId,bool isEnable) const2915 bool InnerBundleInfo::AddModuleRemovableInfo(
2916 InnerModuleInfo &info, const std::string &stringUserId, bool isEnable) const
2917 {
2918 auto item = info.isRemovable.find(stringUserId);
2919 if (item == info.isRemovable.end()) {
2920 auto result = info.isRemovable.try_emplace(stringUserId, isEnable);
2921 if (!result.second) {
2922 APP_LOGE("add userId:%{public}s isRemovable:%{public}d failed", stringUserId.c_str(), isEnable);
2923 return false;
2924 } else {
2925 APP_LOGD("add userId:%{public}s isRemovable:%{public}d into map", stringUserId.c_str(), isEnable);
2926 return true;
2927 }
2928 }
2929 item->second = isEnable;
2930 APP_LOGD("set userId:%{public}s isEnable:%{public}d ok", stringUserId.c_str(), isEnable);
2931 return true;
2932 }
2933
SetModuleRemovable(const std::string & moduleName,bool isEnable,int32_t userId)2934 bool InnerBundleInfo::SetModuleRemovable(const std::string &moduleName, bool isEnable, int32_t userId)
2935 {
2936 std::string stringUserId = "";
2937 stringUserId.append(std::to_string(userId));
2938 APP_LOGD("userId:%{public}d moduleName:%{public}s isEnable:%{public}d", userId, moduleName.c_str(), isEnable);
2939 for (auto &innerModuleInfo : innerModuleInfos_) {
2940 if (innerModuleInfo.second.moduleName == moduleName) {
2941 return AddModuleRemovableInfo(innerModuleInfo.second, stringUserId, isEnable);
2942 }
2943 }
2944 return false;
2945 }
2946
DeleteModuleRemovableInfo(InnerModuleInfo & info,const std::string & stringUserId)2947 void InnerBundleInfo::DeleteModuleRemovableInfo(InnerModuleInfo &info, const std::string &stringUserId)
2948 {
2949 auto item = info.isRemovable.find(stringUserId);
2950 if (item != info.isRemovable.end()) {
2951 auto result = info.isRemovable.erase(stringUserId);
2952 if (result == 0) {
2953 APP_LOGE("del userId:%{public}s from map failed", stringUserId.c_str());
2954 return;
2955 }
2956 APP_LOGD("del userId:%{public}s from map", stringUserId.c_str());
2957 return;
2958 }
2959 }
2960
DeleteModuleRemovable(const std::string & moduleName,int32_t userId)2961 void InnerBundleInfo::DeleteModuleRemovable(const std::string &moduleName, int32_t userId)
2962 {
2963 std::string stringUserId = "";
2964 stringUserId.append(std::to_string(userId));
2965 APP_LOGD("userId:%{public}d moduleName:%{public}s", userId, moduleName.c_str());
2966 for (auto &innerModuleInfo : innerModuleInfos_) {
2967 if (innerModuleInfo.second.moduleName == moduleName) {
2968 DeleteModuleRemovableInfo(innerModuleInfo.second, stringUserId);
2969 return;
2970 }
2971 }
2972 }
2973
SetModuleUpgradeFlag(std::string moduleName,int32_t upgradeFlag)2974 ErrCode InnerBundleInfo::SetModuleUpgradeFlag(std::string moduleName, int32_t upgradeFlag)
2975 {
2976 APP_LOGD("moduleName= %{public}s, upgradeFlag = %{public}d", moduleName.c_str(), upgradeFlag);
2977 for (auto &innerModuleInfo : innerModuleInfos_) {
2978 if (innerModuleInfo.second.moduleName == moduleName) {
2979 innerModuleInfo.second.upgradeFlag = upgradeFlag;
2980 return ERR_OK;
2981 }
2982 }
2983 return ERR_BUNDLE_MANAGER_MODULE_NOT_EXIST;
2984 }
2985
GetModuleUpgradeFlag(std::string moduleName) const2986 int32_t InnerBundleInfo::GetModuleUpgradeFlag(std::string moduleName) const
2987 {
2988 auto moduleInfo = GetInnerModuleInfoByModuleName(moduleName);
2989 if (!moduleInfo) {
2990 APP_LOGE("get InnerModuleInfo by moduleName(%{public}s) failed", moduleName.c_str());
2991 return UpgradeFlag::NOT_UPGRADE;
2992 }
2993 APP_LOGD("innerModuleInfo.upgradeFlag : %{public}d", moduleInfo->upgradeFlag);
2994 return moduleInfo->upgradeFlag;
2995 }
2996
GetResponseUserId(int32_t requestUserId) const2997 int32_t InnerBundleInfo::GetResponseUserId(int32_t requestUserId) const
2998 {
2999 if (innerBundleUserInfos_.empty()) {
3000 APP_LOGE("Get responseUserId failed due to user map is empty.");
3001 return Constants::INVALID_USERID;
3002 }
3003
3004 if (requestUserId == Constants::ANY_USERID) {
3005 return innerBundleUserInfos_.begin()->second.bundleUserInfo.userId;
3006 }
3007
3008 if (HasInnerBundleUserInfo(requestUserId)) {
3009 return requestUserId;
3010 }
3011
3012 if (requestUserId < Constants::START_USERID) {
3013 APP_LOGE("requestUserId(%{public}d) less than start userId.", requestUserId);
3014 return Constants::INVALID_USERID;
3015 }
3016
3017 int32_t responseUserId = Constants::INVALID_USERID;
3018 for (const auto &innerBundleUserInfo : innerBundleUserInfos_) {
3019 if (innerBundleUserInfo.second.bundleUserInfo.userId < Constants::START_USERID) {
3020 responseUserId = innerBundleUserInfo.second.bundleUserInfo.userId;
3021 break;
3022 }
3023 }
3024
3025 APP_LOGD("requestUserId(%{public}d) and responseUserId(%{public}d).", requestUserId, responseUserId);
3026 return responseUserId;
3027 }
3028
GetUriPrefixList(std::vector<std::string> & uriPrefixList,const std::string & excludeModule) const3029 void InnerBundleInfo::GetUriPrefixList(std::vector<std::string> &uriPrefixList,
3030 const std::string &excludeModule) const
3031 {
3032 std::vector<std::string> uriList;
3033 for (const auto &abilityInfoPair : baseAbilityInfos_) {
3034 if (abilityInfoPair.second.uri.empty()) {
3035 continue;
3036 }
3037 if (!excludeModule.empty() && abilityInfoPair.first.find(excludeModule) == 0) {
3038 continue;
3039 }
3040 uriList.emplace_back(abilityInfoPair.second.uri);
3041 }
3042 for (const auto &extensionInfoPair : baseExtensionInfos_) {
3043 if (extensionInfoPair.second.uri.empty()) {
3044 continue;
3045 }
3046 if (!excludeModule.empty() && extensionInfoPair.first.find(excludeModule) == 0) {
3047 continue;
3048 }
3049 uriList.emplace_back(extensionInfoPair.second.uri);
3050 }
3051 for (const std::string &uri : uriList) {
3052 size_t schemePos = uri.find(Constants::URI_SEPARATOR);
3053 if (schemePos == uri.npos) {
3054 continue;
3055 }
3056 size_t cutPos = uri.find(Constants::SEPARATOR, schemePos + Constants::URI_SEPARATOR_LEN);
3057 std::string uriPrefix;
3058 if (cutPos == uri.npos) {
3059 uriPrefix = uri;
3060 } else {
3061 uriPrefix = uri.substr(0, cutPos);
3062 }
3063 uriPrefixList.emplace_back(uriPrefix);
3064 }
3065 }
3066
GetUriPrefixList(std::vector<std::string> & uriPrefixList,int32_t userId,const std::string & excludeModule) const3067 void InnerBundleInfo::GetUriPrefixList(std::vector<std::string> &uriPrefixList, int32_t userId,
3068 const std::string &excludeModule) const
3069 {
3070 auto& key = NameAndUserIdToKey(GetBundleName(), userId);
3071 auto infoItem = innerBundleUserInfos_.find(key);
3072 if (infoItem == innerBundleUserInfos_.end()) {
3073 return;
3074 }
3075 GetUriPrefixList(uriPrefixList, excludeModule);
3076 }
3077
GetDependentModuleNames(const std::string & moduleName,std::vector<std::string> & dependentModuleNames) const3078 bool InnerBundleInfo::GetDependentModuleNames(const std::string &moduleName,
3079 std::vector<std::string> &dependentModuleNames) const
3080 {
3081 for (auto iter = innerModuleInfos_.begin(); iter != innerModuleInfos_.end(); ++iter) {
3082 if (iter->second.moduleName == moduleName) {
3083 for (const auto &dependency : iter->second.dependencies) {
3084 dependentModuleNames.push_back(dependency.moduleName);
3085 }
3086 return true;
3087 }
3088 }
3089 APP_LOGE("GetDependentModuleNames can not find module %{public}s", moduleName.c_str());
3090 return false;
3091 }
3092
GetAllDependentModuleNames(const std::string & moduleName,std::vector<std::string> & dependentModuleNames) const3093 bool InnerBundleInfo::GetAllDependentModuleNames(const std::string &moduleName,
3094 std::vector<std::string> &dependentModuleNames) const
3095 {
3096 if (!GetDependentModuleNames(moduleName, dependentModuleNames)) {
3097 return false;
3098 }
3099 std::deque<std::string> moduleDeque;
3100 std::copy(dependentModuleNames.begin(), dependentModuleNames.end(), std::back_inserter(moduleDeque));
3101 dependentModuleNames.clear();
3102 while (!moduleDeque.empty()) {
3103 std::string name = moduleDeque.front();
3104 moduleDeque.pop_front();
3105 if (std::find(dependentModuleNames.begin(), dependentModuleNames.end(), name) == dependentModuleNames.end()) {
3106 dependentModuleNames.push_back(name);
3107 std::vector<std::string> tempModuleNames;
3108 if (GetDependentModuleNames(name, tempModuleNames)) {
3109 std::copy(tempModuleNames.begin(), tempModuleNames.end(), std::back_inserter(moduleDeque));
3110 }
3111 }
3112 }
3113 return true;
3114 }
3115
GetMainAbility() const3116 std::string InnerBundleInfo::GetMainAbility() const
3117 {
3118 AbilityInfo abilityInfo;
3119 GetMainAbilityInfo(abilityInfo);
3120 return abilityInfo.name;
3121 }
3122
GetMainAbilityInfo(AbilityInfo & abilityInfo) const3123 void InnerBundleInfo::GetMainAbilityInfo(AbilityInfo &abilityInfo) const
3124 {
3125 for (const auto& item : innerModuleInfos_) {
3126 const std::string& key = item.second.entryAbilityKey;
3127 if (!key.empty() && (baseAbilityInfos_.count(key) != 0)) {
3128 abilityInfo = baseAbilityInfos_.at(key);
3129 if (item.second.isEntry) {
3130 return;
3131 }
3132 }
3133 }
3134 }
3135
HasEntry() const3136 bool InnerBundleInfo::HasEntry() const
3137 {
3138 return std::any_of(innerModuleInfos_.begin(), innerModuleInfos_.end(), [](const auto &item) {
3139 return item.second.isEntry;
3140 });
3141 }
3142
SetDisposedStatus(int32_t status)3143 void InnerBundleInfo::SetDisposedStatus(int32_t status)
3144 {
3145 disposedStatus_ = status;
3146 }
3147
GetDisposedStatus() const3148 int32_t InnerBundleInfo::GetDisposedStatus() const
3149 {
3150 return disposedStatus_;
3151 }
3152
SetAppDistributionType(const std::string & appDistributionType)3153 void InnerBundleInfo::SetAppDistributionType(const std::string &appDistributionType)
3154 {
3155 baseApplicationInfo_->appDistributionType = appDistributionType;
3156 }
3157
GetAppDistributionType() const3158 std::string InnerBundleInfo::GetAppDistributionType() const
3159 {
3160 return baseApplicationInfo_->appDistributionType;
3161 }
3162
SetAppProvisionType(const std::string & appProvisionType)3163 void InnerBundleInfo::SetAppProvisionType(const std::string &appProvisionType)
3164 {
3165 baseApplicationInfo_->appProvisionType = appProvisionType;
3166 }
3167
GetAppProvisionType() const3168 std::string InnerBundleInfo::GetAppProvisionType() const
3169 {
3170 return baseApplicationInfo_->appProvisionType;
3171 }
3172
SetAppCrowdtestDeadline(int64_t crowdtestDeadline)3173 void InnerBundleInfo::SetAppCrowdtestDeadline(int64_t crowdtestDeadline)
3174 {
3175 baseApplicationInfo_->crowdtestDeadline = crowdtestDeadline;
3176 }
3177
GetAppCrowdtestDeadline() const3178 int64_t InnerBundleInfo::GetAppCrowdtestDeadline() const
3179 {
3180 return baseApplicationInfo_->crowdtestDeadline;
3181 }
3182
GetDistroModuleName() const3183 std::vector<std::string> InnerBundleInfo::GetDistroModuleName() const
3184 {
3185 std::vector<std::string> moduleVec;
3186 std::transform(innerModuleInfos_.begin(), innerModuleInfos_.end(),
3187 std::back_inserter(moduleVec), [](const auto &info) {
3188 return info.second.moduleName;
3189 });
3190 return moduleVec;
3191 }
3192
GetModuleNameByPackage(const std::string & packageName) const3193 std::string InnerBundleInfo::GetModuleNameByPackage(const std::string &packageName) const
3194 {
3195 auto it = innerModuleInfos_.find(packageName);
3196 if (it == innerModuleInfos_.end()) {
3197 return Constants::EMPTY_STRING;
3198 }
3199 return it->second.moduleName;
3200 }
3201
GetModuleTypeByPackage(const std::string & packageName) const3202 std::string InnerBundleInfo::GetModuleTypeByPackage(const std::string &packageName) const
3203 {
3204 auto it = innerModuleInfos_.find(packageName);
3205 if (it == innerModuleInfos_.end()) {
3206 return Constants::EMPTY_STRING;
3207 }
3208 return it->second.distro.moduleType;
3209 }
3210
GetAppQuickFix() const3211 AppQuickFix InnerBundleInfo::GetAppQuickFix() const
3212 {
3213 return baseApplicationInfo_->appQuickFix;
3214 }
3215
SetAppQuickFix(const AppQuickFix & appQuickFix)3216 void InnerBundleInfo::SetAppQuickFix(const AppQuickFix &appQuickFix)
3217 {
3218 baseApplicationInfo_->appQuickFix = appQuickFix;
3219 if (appQuickFix.deployedAppqfInfo.hqfInfos.empty() && appQuickFix.deployingAppqfInfo.hqfInfos.empty()) {
3220 baseApplicationInfo_->appQuickFix.bundleName = Constants::EMPTY_STRING;
3221 baseApplicationInfo_->appQuickFix.versionCode = 0;
3222 baseApplicationInfo_->appQuickFix.versionName = Constants::EMPTY_STRING;
3223 }
3224 SetQuickFixHqfInfos(appQuickFix.deployedAppqfInfo.hqfInfos);
3225 }
3226
GetQuickFixHqfInfos() const3227 std::vector<HqfInfo> InnerBundleInfo::GetQuickFixHqfInfos() const
3228 {
3229 return hqfInfos_;
3230 }
3231
SetQuickFixHqfInfos(const std::vector<HqfInfo> & hqfInfos)3232 void InnerBundleInfo::SetQuickFixHqfInfos(const std::vector<HqfInfo> &hqfInfos)
3233 {
3234 hqfInfos_ = hqfInfos;
3235 }
3236
FetchNativeSoAttrs(const std::string & requestPackage,std::string & cpuAbi,std::string & nativeLibraryPath) const3237 bool InnerBundleInfo::FetchNativeSoAttrs(
3238 const std::string &requestPackage, std::string &cpuAbi, std::string &nativeLibraryPath) const
3239 {
3240 auto moduleIter = innerModuleInfos_.find(requestPackage);
3241 if (moduleIter == innerModuleInfos_.end()) {
3242 APP_LOGE("requestPackage(%{public}s) is not exist", requestPackage.c_str());
3243 return false;
3244 }
3245
3246 auto &moduleInfo = moduleIter->second;
3247 if (moduleInfo.isLibIsolated) {
3248 cpuAbi = moduleInfo.cpuAbi;
3249 nativeLibraryPath = moduleInfo.nativeLibraryPath;
3250 } else {
3251 cpuAbi = baseApplicationInfo_->cpuAbi;
3252 nativeLibraryPath = baseApplicationInfo_->nativeLibraryPath;
3253 }
3254
3255 return !nativeLibraryPath.empty();
3256 }
3257
IsLibIsolated(const std::string & moduleName) const3258 bool InnerBundleInfo::IsLibIsolated(const std::string &moduleName) const
3259 {
3260 auto moduleInfo = GetInnerModuleInfoByModuleName(moduleName);
3261 if (!moduleInfo) {
3262 APP_LOGE("Get moduleInfo(%{public}s) failed.", moduleName.c_str());
3263 return false;
3264 }
3265
3266 return moduleInfo->isLibIsolated;
3267 }
3268
GetDeviceType(const std::string & packageName) const3269 std::vector<std::string> InnerBundleInfo::GetDeviceType(const std::string &packageName) const
3270 {
3271 auto it = innerModuleInfos_.find(packageName);
3272 if (it == innerModuleInfos_.end()) {
3273 APP_LOGW("%{public}s is not existed", packageName.c_str());
3274 return std::vector<std::string>();
3275 }
3276 return innerModuleInfos_.at(packageName).deviceTypes;
3277 }
3278 } // namespace AppExecFwk
3279 } // namespace OHOS
3280