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 <regex>
19 #include "bundle_mgr_client.h"
20 #include "bundle_permission_mgr.h"
21 #include "common_profile.h"
22
23 namespace OHOS {
24 namespace AppExecFwk {
25 namespace {
26
27 const std::string IS_SUPPORT_BACKUP = "isSupportBackup";
28 const std::string APP_TYPE = "appType";
29 const std::string UID = "uid";
30 const std::string GID = "gid";
31 const std::string BASE_DATA_DIR = "baseDataDir";
32 const std::string BUNDLE_STATUS = "bundleStatus";
33 const std::string BASE_APPLICATION_INFO = "baseApplicationInfo";
34 const std::string BASE_BUNDLE_INFO = "baseBundleInfo";
35 const std::string BASE_ABILITY_INFO = "baseAbilityInfos";
36 const std::string INNER_MODULE_INFO = "innerModuleInfos";
37 const std::string MAIN_ABILITY = "mainAbility";
38 const std::string MAIN_ABILITY_NAME = "mainAbilityName";
39 const std::string SKILL_INFOS = "skillInfos";
40 const std::string USER_ID = "userId_";
41 const std::string APP_FEATURE = "appFeature";
42 const std::string HAS_ENTRY = "hasEntry";
43 const std::string CAN_UNINSTALL = "canUninstall";
44 const std::string NAME = "name";
45 const std::string MODULE_PACKAGE = "modulePackage";
46 const std::string MODULE_PATH = "modulePath";
47 const std::string MODULE_NAME = "moduleName";
48 const std::string MODULE_DESCRIPTION = "description";
49 const std::string MODULE_DESCRIPTION_ID = "descriptionId";
50 const std::string MODULE_ICON = "icon";
51 const std::string MODULE_ICON_ID = "iconId";
52 const std::string MODULE_LABEL = "label";
53 const std::string MODULE_LABEL_ID = "labelId";
54 const std::string MODULE_DESCRIPTION_INSTALLATION_FREE = "installationFree";
55 const std::string MODULE_IS_ENTRY = "isEntry";
56 const std::string MODULE_METADATA = "metaData";
57 const std::string MODULE_COLOR_MODE = "colorMode";
58 const std::string MODULE_DISTRO = "distro";
59 const std::string MODULE_REQ_CAPABILITIES = "reqCapabilities";
60 const std::string MODULE_DATA_DIR = "moduleDataDir";
61 const std::string MODULE_RES_PATH = "moduleResPath";
62 const std::string MODULE_ABILITY_KEYS = "abilityKeys";
63 const std::string MODULE_SKILL_KEYS = "skillKeys";
64 const std::string MODULE_FORMS = "formInfos";
65 const std::string MODULE_SHORTCUT = "shortcutInfos";
66 const std::string MODULE_COMMON_EVENT = "commonEvents";
67 const std::string MODULE_MAIN_ABILITY = "mainAbility";
68 const std::string NEW_BUNDLE_NAME = "newBundleName";
69 const std::string MODULE_SRC_PATH = "srcPath";
70 const std::string SCHEME_SEPARATOR = "://";
71 const std::string PORT_SEPARATOR = ":";
72 const std::string PATH_SEPARATOR = "/";
73 const std::string IS_PREINSTALL_APP = "isPreInstallApp";
74 const std::string INSTALL_MARK = "installMark";
75 const char WILDCARD = '*';
76 const std::string TYPE_WILDCARD = "*/*";
77 const std::string INNER_BUNDLE_USER_INFOS = "innerBundleUserInfos";
78 const std::string MODULE_PROCESS = "process";
79 const std::string MODULE_SRC_ENTRANCE = "srcEntrance";
80 const std::string MODULE_DEVICE_TYPES = "deviceTypes";
81 const std::string MODULE_VIRTUAL_MACHINE = "virtualMachine";
82 const std::string MODULE_UI_SYNTAX = "uiSyntax";
83 const std::string MODULE_PAGES = "pages";
84 const std::string MODULE_META_DATA = "metadata";
85 const std::string MODULE_REQUEST_PERMISSIONS = "requestPermissions";
86 const std::string MODULE_DEFINE_PERMISSIONS = "definePermissions";
87 const std::string MODULE_DEF_PERMS = "defPermissions";
88 const std::string MODULE_EXTENSION_KEYS = "extensionKeys";
89 const std::string MODULE_EXTENSION_SKILL_KEYS = "extensionSkillKeys";
90 const std::string MODULE_IS_MODULE_JSON = "isModuleJson";
91 const std::string MODULE_IS_STAGE_BASED_MODEL = "isStageBasedModel";
92 const std::string BUNDLE_IS_NEW_VERSION = "isNewVersion_";
93 const std::string BUNDLE_BASE_EXTENSION_INFOS = "baseExtensionInfos_";
94 const std::string BUNDLE_EXTENSION_SKILL_INFOS = "extensionSkillInfos_";
95 const std::string ALLOWED_ACLS = "allowedAcls";
96 const std::string META_DATA_SHORTCUTS_NAME = "ohos.ability.shortcuts";
97
NameAndUserIdToKey(const std::string & bundleName,int32_t userId)98 const std::string NameAndUserIdToKey(const std::string &bundleName, int32_t userId)
99 {
100 return bundleName + Constants::FILE_UNDERLINE + std::to_string(userId);
101 }
102 } // namespace
103
Match(const OHOS::AAFwk::Want & want) const104 bool Skill::Match(const OHOS::AAFwk::Want &want) const
105 {
106 bool matchAction = MatchAction(want.GetAction());
107 if (!matchAction) {
108 APP_LOGD("Action does not match");
109 return false;
110 }
111 bool matchEntities = MatchEntities(want.GetEntities());
112 if (!matchEntities) {
113 APP_LOGD("Entities does not match");
114 return false;
115 }
116 bool matchUriAndType = MatchUriAndType(want.GetUriString(), want.GetType());
117 if (!matchUriAndType) {
118 APP_LOGD("Uri or Type does not match");
119 return false;
120 }
121 return true;
122 }
123
MatchLauncher(const OHOS::AAFwk::Want & want) const124 bool Skill::MatchLauncher(const OHOS::AAFwk::Want &want) const
125 {
126 bool matchAction = MatchAction(want.GetAction());
127 if (!matchAction) {
128 APP_LOGD("Action does not match");
129 return false;
130 }
131 bool matchEntities = MatchEntities(want.GetEntities());
132 if (!matchEntities) {
133 APP_LOGD("Entities does not match");
134 return false;
135 }
136 return true;
137 }
138
MatchAction(const std::string & action) const139 bool Skill::MatchAction(const std::string &action) const
140 {
141 // config actions empty, no match
142 if (actions.empty()) {
143 return false;
144 }
145 // config actions not empty, param empty, match
146 if (action.empty()) {
147 return true;
148 }
149 // config actions not empty, param not empty, if config actions contains param action, match
150 return std::find(actions.cbegin(), actions.cend(), action) != actions.cend();
151 }
152
MatchEntities(const std::vector<std::string> & paramEntities) const153 bool Skill::MatchEntities(const std::vector<std::string> ¶mEntities) const
154 {
155 // param entities empty, match
156 if (paramEntities.empty()) {
157 return true;
158 }
159 // config entities empty, param entities not empty, not match
160 if (entities.empty()) {
161 return false;
162 }
163 // config entities not empty, param entities not empty, if every param entity in config entities, match
164 std::vector<std::string>::size_type size = paramEntities.size();
165 for (std::vector<std::string>::size_type i = 0; i < size; i++) {
166 bool ret = std::find(entities.cbegin(), entities.cend(), paramEntities[i]) == entities.cend();
167 if (ret) {
168 return false;
169 }
170 }
171 return true;
172 }
173
MatchUriAndType(const std::string & uriString,const std::string & type) const174 bool Skill::MatchUriAndType(const std::string &uriString, const std::string &type) const
175 {
176 if (uriString.empty() && type.empty()) {
177 // case1 : param uri empty, param type empty
178 if (uris.empty()) {
179 return true;
180 }
181 for (const SkillUri &skillUri : uris) {
182 if (skillUri.scheme.empty() && skillUri.type.empty()) {
183 return true;
184 }
185 }
186 return false;
187 }
188 if (uris.empty()) {
189 return false;
190 }
191 if (!uriString.empty() && type.empty()) {
192 // case2 : param uri not empty, param type empty
193 for (const SkillUri &skillUri : uris) {
194 if (MatchUri(uriString, skillUri) && skillUri.type.empty()) {
195 return true;
196 }
197 }
198 return false;
199 } else if (uriString.empty() && !type.empty()) {
200 // case3 : param uri empty, param type not empty
201 for (const SkillUri &skillUri : uris) {
202 if (skillUri.scheme.empty() && MatchType(type, skillUri.type)) {
203 return true;
204 }
205 }
206 return false;
207 } else {
208 // case4 : param uri not empty, param type not empty
209 for (const SkillUri &skillUri : uris) {
210 if (MatchUri(uriString, skillUri) && MatchType(type, skillUri.type)) {
211 return true;
212 }
213 }
214 return false;
215 }
216 }
217
MatchUri(const std::string & uriString,const SkillUri & skillUri) const218 bool Skill::MatchUri(const std::string &uriString, const SkillUri &skillUri) const
219 {
220 if (skillUri.scheme.empty()) {
221 return uriString.empty();
222 }
223 if (skillUri.host.empty()) {
224 return uriString == skillUri.scheme;
225 }
226 std::string skillUriString;
227 skillUriString.append(skillUri.scheme).append(SCHEME_SEPARATOR).append(skillUri.host);
228 if (!skillUri.port.empty()) {
229 skillUriString.append(PORT_SEPARATOR).append(skillUri.port);
230 }
231 if (skillUri.path.empty() && skillUri.pathStartWith.empty() && skillUri.pathRegex.empty()) {
232 return uriString == skillUriString;
233 }
234 skillUriString.append(PATH_SEPARATOR);
235 // if one of path, pathStartWith, pathRegex match, then match
236 if (!skillUri.path.empty()) {
237 // path match
238 std::string pathUri(skillUriString);
239 pathUri.append(skillUri.path);
240 if (uriString == pathUri) {
241 return true;
242 }
243 }
244 if (!skillUri.pathStartWith.empty()) {
245 // pathStartWith match
246 std::string pathStartWithUri(skillUriString);
247 pathStartWithUri.append(skillUri.pathStartWith);
248 if (uriString.find(pathStartWithUri) == 0) {
249 return true;
250 }
251 }
252 if (!skillUri.pathRegex.empty()) {
253 // pathRegex match
254 std::string pathRegxUri(skillUriString);
255 pathRegxUri.append(skillUri.pathRegex);
256 try {
257 std::regex regex(pathRegxUri);
258 if (regex_match(uriString, regex)) {
259 return true;
260 }
261 } catch(...) {
262 APP_LOGE("regex error");
263 }
264 }
265 return false;
266 }
267
MatchType(const std::string & type,const std::string & skillUriType) const268 bool Skill::MatchType(const std::string &type, const std::string &skillUriType) const
269 {
270 // type is not empty
271 if (skillUriType.empty()) {
272 return false;
273 }
274 if (type == TYPE_WILDCARD || skillUriType == TYPE_WILDCARD) {
275 // param is */* or config is */*
276 return true;
277 }
278 bool paramTypeRegex = type.back() == WILDCARD;
279 if (paramTypeRegex) {
280 // param is string/*
281 std::string prefix = type.substr(0, type.length() - 1);
282 return skillUriType.find(prefix) == 0;
283 }
284 bool typeRegex = skillUriType.back() == WILDCARD;
285 if (typeRegex) {
286 // config is string/*
287 std::string prefix = skillUriType.substr(0, skillUriType.length() - 1);
288 return type.find(prefix) == 0;
289 } else {
290 return type == skillUriType;
291 }
292 }
293
InnerBundleInfo()294 InnerBundleInfo::InnerBundleInfo()
295 {
296 APP_LOGD("inner bundle info instance is created");
297 }
298
~InnerBundleInfo()299 InnerBundleInfo::~InnerBundleInfo()
300 {
301 APP_LOGD("inner bundle info instance is destroyed");
302 }
303
to_json(nlohmann::json & jsonObject,const Distro & distro)304 void to_json(nlohmann::json &jsonObject, const Distro &distro)
305 {
306 jsonObject = nlohmann::json {
307 {ProfileReader::BUNDLE_MODULE_PROFILE_KEY_DELIVERY_WITH_INSTALL, distro.deliveryWithInstall},
308 {ProfileReader::BUNDLE_MODULE_PROFILE_KEY_MODULE_NAME, distro.moduleName},
309 {ProfileReader::BUNDLE_MODULE_PROFILE_KEY_MODULE_TYPE, distro.moduleType},
310 {ProfileReader::BUNDLE_MODULE_PROFILE_KEY_MODULE_INSTALLATION_FREE, distro.installationFree}
311 };
312 }
313
to_json(nlohmann::json & jsonObject,const DefinePermission & definePermission)314 void to_json(nlohmann::json &jsonObject, const DefinePermission &definePermission)
315 {
316 jsonObject = nlohmann::json {
317 {Profile::DEFINEPERMISSION_NAME, definePermission.name},
318 {Profile::DEFINEPERMISSION_GRANT_MODE, definePermission.grantMode},
319 {Profile::DEFINEPERMISSION_AVAILABLE_LEVEL, definePermission.availableLevel},
320 {ProfileReader::BUNDLE_MODULE_PROFILE_KEY_DEF_PERMISSIONS_AVAILABLESCOPE, definePermission.availableScope},
321 {Profile::DEFINEPERMISSION_PROVISION_ENABLE, definePermission.provisionEnable},
322 {Profile::DEFINEPERMISSION_DISTRIBUTED_SCENE_ENABLE, definePermission.distributedSceneEnable},
323 {Profile::LABEL, definePermission.label},
324 {Profile::LABEL_ID, definePermission.labelId},
325 {Profile::DESCRIPTION, definePermission.description},
326 {Profile::DESCRIPTION_ID, definePermission.descriptionId}
327 };
328 }
329
to_json(nlohmann::json & jsonObject,const InnerModuleInfo & info)330 void to_json(nlohmann::json &jsonObject, const InnerModuleInfo &info)
331 {
332 jsonObject = nlohmann::json {
333 {NAME, info.name},
334 {MODULE_PACKAGE, info.modulePackage},
335 {MODULE_NAME, info.moduleName},
336 {MODULE_PATH, info.modulePath},
337 {MODULE_DATA_DIR, info.moduleDataDir},
338 {MODULE_RES_PATH, info.moduleResPath},
339 {MODULE_IS_ENTRY, info.isEntry},
340 {MODULE_METADATA, info.metaData},
341 {MODULE_COLOR_MODE, info.colorMode},
342 {MODULE_DISTRO, info.distro},
343 {MODULE_DESCRIPTION, info.description},
344 {MODULE_DESCRIPTION_ID, info.descriptionId},
345 {MODULE_ICON, info.icon},
346 {MODULE_ICON_ID, info.iconId},
347 {MODULE_LABEL, info.label},
348 {MODULE_LABEL_ID, info.labelId},
349 {MODULE_DESCRIPTION_INSTALLATION_FREE, info.installationFree},
350 {MODULE_REQ_CAPABILITIES, info.reqCapabilities},
351 {MODULE_ABILITY_KEYS, info.abilityKeys},
352 {MODULE_SKILL_KEYS, info.skillKeys},
353 {MODULE_MAIN_ABILITY, info.mainAbility},
354 {MODULE_SRC_PATH, info.srcPath},
355 {MODULE_PROCESS, info.process},
356 {MODULE_SRC_ENTRANCE, info.srcEntrance},
357 {MODULE_DEVICE_TYPES, info.deviceTypes},
358 {MODULE_VIRTUAL_MACHINE, info.virtualMachine},
359 {MODULE_UI_SYNTAX, info.uiSyntax},
360 {MODULE_PAGES, info.pages},
361 {MODULE_META_DATA, info.metadata},
362 {MODULE_REQUEST_PERMISSIONS, info.requestPermissions},
363 {MODULE_DEFINE_PERMISSIONS, info.definePermissions},
364 {MODULE_DEF_PERMS, info.defPermissions},
365 {MODULE_EXTENSION_KEYS, info.extensionKeys},
366 {MODULE_EXTENSION_SKILL_KEYS, info.extensionSkillKeys},
367 {MODULE_IS_MODULE_JSON, info.isModuleJson},
368 {MODULE_IS_STAGE_BASED_MODEL, info.isStageBasedModel}
369 };
370 }
371
to_json(nlohmann::json & jsonObject,const SkillUri & uri)372 void to_json(nlohmann::json &jsonObject, const SkillUri &uri)
373 {
374 jsonObject = nlohmann::json {
375 {ProfileReader::BUNDLE_MODULE_PROFILE_KEY_SCHEME, uri.scheme},
376 {ProfileReader::BUNDLE_MODULE_PROFILE_KEY_HOST, uri.host},
377 {ProfileReader::BUNDLE_MODULE_PROFILE_KEY_PORT, uri.port},
378 {ProfileReader::BUNDLE_MODULE_PROFILE_KEY_PATH, uri.path},
379 {ProfileReader::BUNDLE_MODULE_PROFILE_KEY_PATHSTARTWITH, uri.pathStartWith},
380 {ProfileReader::BUNDLE_MODULE_PROFILE_KEY_PATHREGEX, uri.pathRegex},
381 {ProfileReader::BUNDLE_MODULE_PROFILE_KEY_TYPE, uri.type}
382 };
383 }
384
to_json(nlohmann::json & jsonObject,const Skill & skill)385 void to_json(nlohmann::json &jsonObject, const Skill &skill)
386 {
387 jsonObject = nlohmann::json {
388 {ProfileReader::BUNDLE_MODULE_PROFILE_KEY_ACTIONS, skill.actions},
389 {ProfileReader::BUNDLE_MODULE_PROFILE_KEY_ENTITIES, skill.entities},
390 {ProfileReader::BUNDLE_MODULE_PROFILE_KEY_URIS, skill.uris}
391 };
392 }
393
to_json(nlohmann::json & jsonObject,const InstallMark & installMark)394 void to_json(nlohmann::json &jsonObject, const InstallMark &installMark)
395 {
396 jsonObject = nlohmann::json {
397 {ProfileReader::BUNDLE_INSTALL_MARK_BUNDLE, installMark.bundleName},
398 {ProfileReader::BUNDLE_INSTALL_MARK_PACKAGE, installMark.packageName},
399 {ProfileReader::BUNDLE_INSTALL_MARK_STATUS, installMark.status}
400 };
401 }
402
ToJson(nlohmann::json & jsonObject) const403 void InnerBundleInfo::ToJson(nlohmann::json &jsonObject) const
404 {
405 jsonObject[IS_SUPPORT_BACKUP] = isSupportBackup_;
406 jsonObject[APP_TYPE] = appType_;
407 jsonObject[BASE_DATA_DIR] = baseDataDir_;
408 jsonObject[BUNDLE_STATUS] = bundleStatus_;
409 jsonObject[ALLOWED_ACLS] = allowedAcls_;
410 jsonObject[BASE_APPLICATION_INFO] = baseApplicationInfo_;
411 jsonObject[BASE_BUNDLE_INFO] = baseBundleInfo_;
412 jsonObject[BASE_ABILITY_INFO] = baseAbilityInfos_;
413 jsonObject[INNER_MODULE_INFO] = innerModuleInfos_;
414 jsonObject[SKILL_INFOS] = skillInfos_;
415 jsonObject[USER_ID] = userId_;
416 jsonObject[MAIN_ABILITY] = mainAbility_;
417 jsonObject[MAIN_ABILITY_NAME] = mainAbilityName_;
418 jsonObject[APP_FEATURE] = appFeature_;
419 jsonObject[HAS_ENTRY] = hasEntry_;
420 jsonObject[MODULE_FORMS] = formInfos_;
421 jsonObject[MODULE_SHORTCUT] = shortcutInfos_;
422 jsonObject[NEW_BUNDLE_NAME] = newBundleName_;
423 jsonObject[MODULE_COMMON_EVENT] = commonEvents_;
424 jsonObject[INSTALL_MARK] = mark_;
425 jsonObject[INNER_BUNDLE_USER_INFOS] = innerBundleUserInfos_;
426 jsonObject[BUNDLE_IS_NEW_VERSION] = isNewVersion_;
427 jsonObject[BUNDLE_BASE_EXTENSION_INFOS] = baseExtensionInfos_;
428 jsonObject[BUNDLE_EXTENSION_SKILL_INFOS] = extensionSkillInfos_;
429 }
430
from_json(const nlohmann::json & jsonObject,InnerModuleInfo & info)431 void from_json(const nlohmann::json &jsonObject, InnerModuleInfo &info)
432 {
433 // these are not required fields.
434 const auto &jsonObjectEnd = jsonObject.end();
435 GetValueIfFindKey<std::string>(jsonObject,
436 jsonObjectEnd,
437 NAME,
438 info.name,
439 JsonType::STRING,
440 false,
441 ProfileReader::parseResult,
442 ArrayType::NOT_ARRAY);
443 GetValueIfFindKey<std::string>(jsonObject,
444 jsonObjectEnd,
445 MODULE_PACKAGE,
446 info.modulePackage,
447 JsonType::STRING,
448 false,
449 ProfileReader::parseResult,
450 ArrayType::NOT_ARRAY);
451 GetValueIfFindKey<std::string>(jsonObject,
452 jsonObjectEnd,
453 MODULE_NAME,
454 info.moduleName,
455 JsonType::STRING,
456 false,
457 ProfileReader::parseResult,
458 ArrayType::NOT_ARRAY);
459 GetValueIfFindKey<std::string>(jsonObject,
460 jsonObjectEnd,
461 MODULE_PATH,
462 info.modulePath,
463 JsonType::STRING,
464 false,
465 ProfileReader::parseResult,
466 ArrayType::NOT_ARRAY);
467 GetValueIfFindKey<std::string>(jsonObject,
468 jsonObjectEnd,
469 MODULE_DATA_DIR,
470 info.moduleDataDir,
471 JsonType::STRING,
472 false,
473 ProfileReader::parseResult,
474 ArrayType::NOT_ARRAY);
475 GetValueIfFindKey<std::string>(jsonObject,
476 jsonObjectEnd,
477 MODULE_RES_PATH,
478 info.moduleResPath,
479 JsonType::STRING,
480 false,
481 ProfileReader::parseResult,
482 ArrayType::NOT_ARRAY);
483 GetValueIfFindKey<bool>(jsonObject,
484 jsonObjectEnd,
485 MODULE_IS_ENTRY,
486 info.isEntry,
487 JsonType::BOOLEAN,
488 false,
489 ProfileReader::parseResult,
490 ArrayType::NOT_ARRAY);
491 GetValueIfFindKey<MetaData>(jsonObject,
492 jsonObjectEnd,
493 MODULE_METADATA,
494 info.metaData,
495 JsonType::OBJECT,
496 false,
497 ProfileReader::parseResult,
498 ArrayType::NOT_ARRAY);
499 GetValueIfFindKey<ModuleColorMode>(jsonObject,
500 jsonObjectEnd,
501 MODULE_COLOR_MODE,
502 info.colorMode,
503 JsonType::NUMBER,
504 false,
505 ProfileReader::parseResult,
506 ArrayType::NOT_ARRAY);
507 GetValueIfFindKey<Distro>(jsonObject,
508 jsonObjectEnd,
509 MODULE_DISTRO,
510 info.distro,
511 JsonType::OBJECT,
512 false,
513 ProfileReader::parseResult,
514 ArrayType::NOT_ARRAY);
515 GetValueIfFindKey<std::string>(jsonObject,
516 jsonObjectEnd,
517 MODULE_DESCRIPTION,
518 info.description,
519 JsonType::STRING,
520 false,
521 ProfileReader::parseResult,
522 ArrayType::NOT_ARRAY);
523 GetValueIfFindKey<int32_t>(jsonObject,
524 jsonObjectEnd,
525 MODULE_DESCRIPTION_ID,
526 info.descriptionId,
527 JsonType::NUMBER,
528 false,
529 ProfileReader::parseResult,
530 ArrayType::NOT_ARRAY);
531 GetValueIfFindKey<std::string>(jsonObject,
532 jsonObjectEnd,
533 MODULE_ICON,
534 info.icon,
535 JsonType::STRING,
536 false,
537 ProfileReader::parseResult,
538 ArrayType::NOT_ARRAY);
539 GetValueIfFindKey<int32_t>(jsonObject,
540 jsonObjectEnd,
541 MODULE_ICON_ID,
542 info.iconId,
543 JsonType::NUMBER,
544 false,
545 ProfileReader::parseResult,
546 ArrayType::NOT_ARRAY);
547 GetValueIfFindKey<std::string>(jsonObject,
548 jsonObjectEnd,
549 MODULE_LABEL,
550 info.label,
551 JsonType::STRING,
552 false,
553 ProfileReader::parseResult,
554 ArrayType::NOT_ARRAY);
555 GetValueIfFindKey<int32_t>(jsonObject,
556 jsonObjectEnd,
557 MODULE_LABEL_ID,
558 info.labelId,
559 JsonType::NUMBER,
560 false,
561 ProfileReader::parseResult,
562 ArrayType::NOT_ARRAY);
563 GetValueIfFindKey<std::string>(jsonObject,
564 jsonObjectEnd,
565 MODULE_MAIN_ABILITY,
566 info.mainAbility,
567 JsonType::STRING,
568 false,
569 ProfileReader::parseResult,
570 ArrayType::NOT_ARRAY);
571 GetValueIfFindKey<std::string>(jsonObject,
572 jsonObjectEnd,
573 MODULE_SRC_PATH,
574 info.srcPath,
575 JsonType::STRING,
576 false,
577 ProfileReader::parseResult,
578 ArrayType::NOT_ARRAY);
579 GetValueIfFindKey<bool>(jsonObject,
580 jsonObjectEnd,
581 MODULE_DESCRIPTION_INSTALLATION_FREE,
582 info.installationFree,
583 JsonType::BOOLEAN,
584 false,
585 ProfileReader::parseResult,
586 ArrayType::NOT_ARRAY);
587 GetValueIfFindKey<std::vector<std::string>>(jsonObject,
588 jsonObjectEnd,
589 MODULE_REQ_CAPABILITIES,
590 info.reqCapabilities,
591 JsonType::ARRAY,
592 false,
593 ProfileReader::parseResult,
594 ArrayType::STRING);
595 GetValueIfFindKey<std::vector<std::string>>(jsonObject,
596 jsonObjectEnd,
597 MODULE_ABILITY_KEYS,
598 info.abilityKeys,
599 JsonType::ARRAY,
600 false,
601 ProfileReader::parseResult,
602 ArrayType::STRING);
603 GetValueIfFindKey<std::vector<std::string>>(jsonObject,
604 jsonObjectEnd,
605 MODULE_SKILL_KEYS,
606 info.skillKeys,
607 JsonType::ARRAY,
608 false,
609 ProfileReader::parseResult,
610 ArrayType::STRING);
611 int32_t parseResult = ERR_OK;
612 GetValueIfFindKey<std::string>(jsonObject,
613 jsonObjectEnd,
614 MODULE_PROCESS,
615 info.process,
616 JsonType::STRING,
617 false,
618 parseResult,
619 ArrayType::NOT_ARRAY);
620 GetValueIfFindKey<std::string>(jsonObject,
621 jsonObjectEnd,
622 MODULE_SRC_ENTRANCE,
623 info.srcEntrance,
624 JsonType::STRING,
625 false,
626 parseResult,
627 ArrayType::NOT_ARRAY);
628 GetValueIfFindKey<std::vector<std::string>>(jsonObject,
629 jsonObjectEnd,
630 MODULE_DEVICE_TYPES,
631 info.deviceTypes,
632 JsonType::ARRAY,
633 false,
634 parseResult,
635 ArrayType::STRING);
636 GetValueIfFindKey<std::string>(jsonObject,
637 jsonObjectEnd,
638 MODULE_VIRTUAL_MACHINE,
639 info.virtualMachine,
640 JsonType::STRING,
641 false,
642 parseResult,
643 ArrayType::NOT_ARRAY);
644 GetValueIfFindKey<std::string>(jsonObject,
645 jsonObjectEnd,
646 MODULE_UI_SYNTAX,
647 info.uiSyntax,
648 JsonType::STRING,
649 false,
650 parseResult,
651 ArrayType::NOT_ARRAY);
652 GetValueIfFindKey<std::string>(jsonObject,
653 jsonObjectEnd,
654 MODULE_PAGES,
655 info.pages,
656 JsonType::STRING,
657 false,
658 parseResult,
659 ArrayType::NOT_ARRAY);
660 GetValueIfFindKey<std::vector<Metadata>>(jsonObject,
661 jsonObjectEnd,
662 MODULE_META_DATA,
663 info.metadata,
664 JsonType::ARRAY,
665 false,
666 parseResult,
667 ArrayType::OBJECT);
668 GetValueIfFindKey<std::vector<RequestPermission>>(jsonObject,
669 jsonObjectEnd,
670 MODULE_REQUEST_PERMISSIONS,
671 info.requestPermissions,
672 JsonType::ARRAY,
673 false,
674 parseResult,
675 ArrayType::OBJECT);
676 GetValueIfFindKey<std::vector<DefinePermission>>(jsonObject,
677 jsonObjectEnd,
678 MODULE_DEFINE_PERMISSIONS,
679 info.definePermissions,
680 JsonType::ARRAY,
681 false,
682 parseResult,
683 ArrayType::OBJECT);
684 GetValueIfFindKey<std::vector<DefinePermission>>(jsonObject,
685 jsonObjectEnd,
686 MODULE_DEF_PERMS,
687 info.defPermissions,
688 JsonType::ARRAY,
689 false,
690 ProfileReader::parseResult,
691 ArrayType::OBJECT);
692 GetValueIfFindKey<std::vector<std::string>>(jsonObject,
693 jsonObjectEnd,
694 MODULE_EXTENSION_KEYS,
695 info.extensionKeys,
696 JsonType::ARRAY,
697 false,
698 parseResult,
699 ArrayType::STRING);
700 GetValueIfFindKey<std::vector<std::string>>(jsonObject,
701 jsonObjectEnd,
702 MODULE_EXTENSION_SKILL_KEYS,
703 info.extensionSkillKeys,
704 JsonType::ARRAY,
705 false,
706 parseResult,
707 ArrayType::STRING);
708 GetValueIfFindKey<bool>(jsonObject,
709 jsonObjectEnd,
710 MODULE_IS_MODULE_JSON,
711 info.isModuleJson,
712 JsonType::BOOLEAN,
713 false,
714 parseResult,
715 ArrayType::NOT_ARRAY);
716 GetValueIfFindKey<bool>(jsonObject,
717 jsonObjectEnd,
718 MODULE_IS_STAGE_BASED_MODEL,
719 info.isStageBasedModel,
720 JsonType::BOOLEAN,
721 false,
722 parseResult,
723 ArrayType::NOT_ARRAY);
724 if (parseResult != ERR_OK) {
725 APP_LOGE("read InnerModuleInfo from database error, error code : %{public}d", parseResult);
726 }
727 }
728
from_json(const nlohmann::json & jsonObject,SkillUri & uri)729 void from_json(const nlohmann::json &jsonObject, SkillUri &uri)
730 {
731 // these are required fields.
732 const auto &jsonObjectEnd = jsonObject.end();
733 GetValueIfFindKey<std::string>(jsonObject,
734 jsonObjectEnd,
735 ProfileReader::BUNDLE_MODULE_PROFILE_KEY_SCHEME,
736 uri.scheme,
737 JsonType::STRING,
738 false,
739 ProfileReader::parseResult,
740 ArrayType::NOT_ARRAY);
741 // these are not required fields.
742 GetValueIfFindKey<std::string>(jsonObject,
743 jsonObjectEnd,
744 ProfileReader::BUNDLE_MODULE_PROFILE_KEY_HOST,
745 uri.host,
746 JsonType::STRING,
747 false,
748 ProfileReader::parseResult,
749 ArrayType::NOT_ARRAY);
750 GetValueIfFindKey<std::string>(jsonObject,
751 jsonObjectEnd,
752 ProfileReader::BUNDLE_MODULE_PROFILE_KEY_PORT,
753 uri.port,
754 JsonType::STRING,
755 false,
756 ProfileReader::parseResult,
757 ArrayType::NOT_ARRAY);
758 GetValueIfFindKey<std::string>(jsonObject,
759 jsonObjectEnd,
760 ProfileReader::BUNDLE_MODULE_PROFILE_KEY_PATH,
761 uri.path,
762 JsonType::STRING,
763 false,
764 ProfileReader::parseResult,
765 ArrayType::NOT_ARRAY);
766 GetValueIfFindKey<std::string>(jsonObject,
767 jsonObjectEnd,
768 ProfileReader::BUNDLE_MODULE_PROFILE_KEY_PATHSTARTWITH,
769 uri.pathStartWith,
770 JsonType::STRING,
771 false,
772 ProfileReader::parseResult,
773 ArrayType::NOT_ARRAY);
774 GetValueIfFindKey<std::string>(jsonObject,
775 jsonObjectEnd,
776 ProfileReader::BUNDLE_MODULE_PROFILE_KEY_PATHREGX,
777 uri.pathRegex,
778 JsonType::STRING,
779 false,
780 ProfileReader::parseResult,
781 ArrayType::NOT_ARRAY);
782 GetValueIfFindKey<std::string>(jsonObject,
783 jsonObjectEnd,
784 ProfileReader::BUNDLE_MODULE_PROFILE_KEY_PATHREGEX,
785 uri.pathRegex,
786 JsonType::STRING,
787 false,
788 ProfileReader::parseResult,
789 ArrayType::NOT_ARRAY);
790 GetValueIfFindKey<std::string>(jsonObject,
791 jsonObjectEnd,
792 ProfileReader::BUNDLE_MODULE_PROFILE_KEY_TYPE,
793 uri.type,
794 JsonType::STRING,
795 false,
796 ProfileReader::parseResult,
797 ArrayType::NOT_ARRAY);
798 }
799
from_json(const nlohmann::json & jsonObject,Skill & skill)800 void from_json(const nlohmann::json &jsonObject, Skill &skill)
801 {
802 // these are not required fields.
803 const auto &jsonObjectEnd = jsonObject.end();
804 GetValueIfFindKey<std::vector<std::string>>(jsonObject,
805 jsonObjectEnd,
806 ProfileReader::BUNDLE_MODULE_PROFILE_KEY_ACTIONS,
807 skill.actions,
808 JsonType::ARRAY,
809 false,
810 ProfileReader::parseResult,
811 ArrayType::STRING);
812 GetValueIfFindKey<std::vector<std::string>>(jsonObject,
813 jsonObjectEnd,
814 ProfileReader::BUNDLE_MODULE_PROFILE_KEY_ENTITIES,
815 skill.entities,
816 JsonType::ARRAY,
817 false,
818 ProfileReader::parseResult,
819 ArrayType::STRING);
820 GetValueIfFindKey<std::vector<SkillUri>>(jsonObject,
821 jsonObjectEnd,
822 ProfileReader::BUNDLE_MODULE_PROFILE_KEY_URIS,
823 skill.uris,
824 JsonType::ARRAY,
825 false,
826 ProfileReader::parseResult,
827 ArrayType::OBJECT);
828 }
829
from_json(const nlohmann::json & jsonObject,Distro & distro)830 void from_json(const nlohmann::json &jsonObject, Distro &distro)
831 {
832 const auto &jsonObjectEnd = jsonObject.end();
833 GetValueIfFindKey<bool>(jsonObject,
834 jsonObjectEnd,
835 ProfileReader::BUNDLE_MODULE_PROFILE_KEY_DELIVERY_WITH_INSTALL,
836 distro.deliveryWithInstall,
837 JsonType::BOOLEAN,
838 true,
839 ProfileReader::parseResult,
840 ArrayType::NOT_ARRAY);
841 GetValueIfFindKey<std::string>(jsonObject,
842 jsonObjectEnd,
843 ProfileReader::BUNDLE_MODULE_PROFILE_KEY_MODULE_NAME,
844 distro.moduleName,
845 JsonType::STRING,
846 true,
847 ProfileReader::parseResult,
848 ArrayType::NOT_ARRAY);
849 GetValueIfFindKey<std::string>(jsonObject,
850 jsonObjectEnd,
851 ProfileReader::BUNDLE_MODULE_PROFILE_KEY_MODULE_TYPE,
852 distro.moduleType,
853 JsonType::STRING,
854 true,
855 ProfileReader::parseResult,
856 ArrayType::NOT_ARRAY);
857 // mustFlag decide by distro.moduleType
858 GetValueIfFindKey<bool>(jsonObject,
859 jsonObjectEnd,
860 ProfileReader::BUNDLE_MODULE_PROFILE_KEY_MODULE_INSTALLATION_FREE,
861 distro.installationFree,
862 JsonType::BOOLEAN,
863 false,
864 ProfileReader::parseResult,
865 ArrayType::NOT_ARRAY);
866 }
867
from_json(const nlohmann::json & jsonObject,InstallMark & installMark)868 void from_json(const nlohmann::json &jsonObject, InstallMark &installMark)
869 {
870 const auto &jsonObjectEnd = jsonObject.end();
871 GetValueIfFindKey<std::string>(jsonObject,
872 jsonObjectEnd,
873 ProfileReader::BUNDLE_INSTALL_MARK_BUNDLE,
874 installMark.bundleName,
875 JsonType::STRING,
876 false,
877 ProfileReader::parseResult,
878 ArrayType::NOT_ARRAY);
879 GetValueIfFindKey<std::string>(jsonObject,
880 jsonObjectEnd,
881 ProfileReader::BUNDLE_INSTALL_MARK_PACKAGE,
882 installMark.packageName,
883 JsonType::STRING,
884 false,
885 ProfileReader::parseResult,
886 ArrayType::NOT_ARRAY);
887 GetValueIfFindKey<int32_t>(jsonObject,
888 jsonObjectEnd,
889 ProfileReader::BUNDLE_INSTALL_MARK_STATUS,
890 installMark.status,
891 JsonType::NUMBER,
892 false,
893 ProfileReader::parseResult,
894 ArrayType::NOT_ARRAY);
895 }
896
from_json(const nlohmann::json & jsonObject,DefinePermission & definePermission)897 void from_json(const nlohmann::json &jsonObject, DefinePermission &definePermission)
898 {
899 const auto &jsonObjectEnd = jsonObject.end();
900 int32_t parseResult = ERR_OK;
901 GetValueIfFindKey<std::string>(jsonObject,
902 jsonObjectEnd,
903 Profile::DEFINEPERMISSION_NAME,
904 definePermission.name,
905 JsonType::STRING,
906 false,
907 parseResult,
908 ArrayType::NOT_ARRAY);
909 GetValueIfFindKey<std::string>(jsonObject,
910 jsonObjectEnd,
911 Profile::DEFINEPERMISSION_GRANT_MODE,
912 definePermission.grantMode,
913 JsonType::STRING,
914 false,
915 parseResult,
916 ArrayType::NOT_ARRAY);
917 GetValueIfFindKey<std::string>(jsonObject,
918 jsonObjectEnd,
919 Profile::DEFINEPERMISSION_AVAILABLE_LEVEL,
920 definePermission.availableLevel,
921 JsonType::STRING,
922 false,
923 parseResult,
924 ArrayType::NOT_ARRAY);
925 GetValueIfFindKey<std::vector<std::string>>(jsonObject,
926 jsonObjectEnd,
927 ProfileReader::BUNDLE_MODULE_PROFILE_KEY_DEF_PERMISSIONS_AVAILABLESCOPE,
928 definePermission.availableScope,
929 JsonType::ARRAY,
930 false,
931 ProfileReader::parseResult,
932 ArrayType::STRING);
933 GetValueIfFindKey<bool>(jsonObject,
934 jsonObjectEnd,
935 Profile::DEFINEPERMISSION_PROVISION_ENABLE,
936 definePermission.provisionEnable,
937 JsonType::BOOLEAN,
938 false,
939 parseResult,
940 ArrayType::NOT_ARRAY);
941 GetValueIfFindKey<bool>(jsonObject,
942 jsonObjectEnd,
943 Profile::DEFINEPERMISSION_DISTRIBUTED_SCENE_ENABLE,
944 definePermission.distributedSceneEnable,
945 JsonType::BOOLEAN,
946 false,
947 parseResult,
948 ArrayType::NOT_ARRAY);
949 GetValueIfFindKey<std::string>(jsonObject,
950 jsonObjectEnd,
951 Profile::LABEL,
952 definePermission.label,
953 JsonType::STRING,
954 false,
955 parseResult,
956 ArrayType::NOT_ARRAY);
957 GetValueIfFindKey<int32_t>(jsonObject,
958 jsonObjectEnd,
959 Profile::LABEL_ID,
960 definePermission.labelId,
961 JsonType::NUMBER,
962 false,
963 parseResult,
964 ArrayType::NOT_ARRAY);
965 GetValueIfFindKey<std::string>(jsonObject,
966 jsonObjectEnd,
967 Profile::DESCRIPTION,
968 definePermission.description,
969 JsonType::STRING,
970 false,
971 parseResult,
972 ArrayType::NOT_ARRAY);
973 GetValueIfFindKey<int32_t>(jsonObject,
974 jsonObjectEnd,
975 Profile::DESCRIPTION_ID,
976 definePermission.descriptionId,
977 JsonType::NUMBER,
978 false,
979 parseResult,
980 ArrayType::NOT_ARRAY);
981 if (parseResult != ERR_OK) {
982 APP_LOGE("read DefinePermission from database error, error code : %{public}d", parseResult);
983 }
984 }
985
FromJson(const nlohmann::json & jsonObject)986 int32_t InnerBundleInfo::FromJson(const nlohmann::json &jsonObject)
987 {
988 const auto &jsonObjectEnd = jsonObject.end();
989 GetValueIfFindKey<bool>(jsonObject,
990 jsonObjectEnd,
991 IS_SUPPORT_BACKUP,
992 isSupportBackup_,
993 JsonType::BOOLEAN,
994 true,
995 ProfileReader::parseResult,
996 ArrayType::NOT_ARRAY);
997 GetValueIfFindKey<Constants::AppType>(jsonObject,
998 jsonObjectEnd,
999 APP_TYPE,
1000 appType_,
1001 JsonType::NUMBER,
1002 true,
1003 ProfileReader::parseResult,
1004 ArrayType::NOT_ARRAY);
1005 GetValueIfFindKey<int>(jsonObject,
1006 jsonObjectEnd,
1007 UID,
1008 uid_,
1009 JsonType::NUMBER,
1010 false,
1011 ProfileReader::parseResult,
1012 ArrayType::NOT_ARRAY);
1013 GetValueIfFindKey<int>(jsonObject,
1014 jsonObjectEnd,
1015 GID,
1016 gid_,
1017 JsonType::NUMBER,
1018 false,
1019 ProfileReader::parseResult,
1020 ArrayType::NOT_ARRAY);
1021 GetValueIfFindKey<std::vector<std::string>>(jsonObject,
1022 jsonObjectEnd,
1023 ALLOWED_ACLS,
1024 allowedAcls_,
1025 JsonType::ARRAY,
1026 false,
1027 ProfileReader::parseResult,
1028 ArrayType::STRING);
1029 GetValueIfFindKey<std::string>(jsonObject,
1030 jsonObjectEnd,
1031 BASE_DATA_DIR,
1032 baseDataDir_,
1033 JsonType::STRING,
1034 true,
1035 ProfileReader::parseResult,
1036 ArrayType::NOT_ARRAY);
1037 GetValueIfFindKey<BundleStatus>(jsonObject,
1038 jsonObjectEnd,
1039 BUNDLE_STATUS,
1040 bundleStatus_,
1041 JsonType::NUMBER,
1042 true,
1043 ProfileReader::parseResult,
1044 ArrayType::NOT_ARRAY);
1045 GetValueIfFindKey<BundleInfo>(jsonObject,
1046 jsonObjectEnd,
1047 BASE_BUNDLE_INFO,
1048 baseBundleInfo_,
1049 JsonType::OBJECT,
1050 true,
1051 ProfileReader::parseResult,
1052 ArrayType::NOT_ARRAY);
1053 GetValueIfFindKey<ApplicationInfo>(jsonObject,
1054 jsonObjectEnd,
1055 BASE_APPLICATION_INFO,
1056 baseApplicationInfo_,
1057 JsonType::OBJECT,
1058 true,
1059 ProfileReader::parseResult,
1060 ArrayType::NOT_ARRAY);
1061 GetValueIfFindKey<std::map<std::string, AbilityInfo>>(jsonObject,
1062 jsonObjectEnd,
1063 BASE_ABILITY_INFO,
1064 baseAbilityInfos_,
1065 JsonType::OBJECT,
1066 true,
1067 ProfileReader::parseResult,
1068 ArrayType::NOT_ARRAY);
1069 GetValueIfFindKey<std::map<std::string, InnerModuleInfo>>(jsonObject,
1070 jsonObjectEnd,
1071 INNER_MODULE_INFO,
1072 innerModuleInfos_,
1073 JsonType::OBJECT,
1074 true,
1075 ProfileReader::parseResult,
1076 ArrayType::NOT_ARRAY);
1077 GetValueIfFindKey<std::map<std::string, std::vector<Skill>>>(jsonObject,
1078 jsonObjectEnd,
1079 SKILL_INFOS,
1080 skillInfos_,
1081 JsonType::OBJECT,
1082 true,
1083 ProfileReader::parseResult,
1084 ArrayType::NOT_ARRAY);
1085 GetValueIfFindKey<int>(jsonObject,
1086 jsonObjectEnd,
1087 USER_ID,
1088 userId_,
1089 JsonType::NUMBER,
1090 true,
1091 ProfileReader::parseResult,
1092 ArrayType::NOT_ARRAY);
1093 GetValueIfFindKey<std::string>(jsonObject,
1094 jsonObjectEnd,
1095 MAIN_ABILITY,
1096 mainAbility_,
1097 JsonType::STRING,
1098 true,
1099 ProfileReader::parseResult,
1100 ArrayType::NOT_ARRAY);
1101 GetValueIfFindKey<std::string>(jsonObject,
1102 jsonObjectEnd,
1103 MAIN_ABILITY_NAME,
1104 mainAbilityName_,
1105 JsonType::STRING,
1106 false,
1107 ProfileReader::parseResult,
1108 ArrayType::NOT_ARRAY);
1109 GetValueIfFindKey<std::string>(jsonObject,
1110 jsonObjectEnd,
1111 APP_FEATURE,
1112 appFeature_,
1113 JsonType::STRING,
1114 true,
1115 ProfileReader::parseResult,
1116 ArrayType::NOT_ARRAY);
1117 GetValueIfFindKey<std::map<std::string, std::vector<FormInfo>>>(jsonObject,
1118 jsonObjectEnd,
1119 MODULE_FORMS,
1120 formInfos_,
1121 JsonType::OBJECT,
1122 true,
1123 ProfileReader::parseResult,
1124 ArrayType::NOT_ARRAY);
1125 GetValueIfFindKey<std::map<std::string, ShortcutInfo>>(jsonObject,
1126 jsonObjectEnd,
1127 MODULE_SHORTCUT,
1128 shortcutInfos_,
1129 JsonType::OBJECT,
1130 true,
1131 ProfileReader::parseResult,
1132 ArrayType::NOT_ARRAY);
1133 GetValueIfFindKey<std::map<std::string, CommonEventInfo>>(jsonObject,
1134 jsonObjectEnd,
1135 MODULE_COMMON_EVENT,
1136 commonEvents_,
1137 JsonType::OBJECT,
1138 true,
1139 ProfileReader::parseResult,
1140 ArrayType::NOT_ARRAY);
1141 GetValueIfFindKey<bool>(jsonObject,
1142 jsonObjectEnd,
1143 HAS_ENTRY,
1144 hasEntry_,
1145 JsonType::BOOLEAN,
1146 true,
1147 ProfileReader::parseResult,
1148 ArrayType::NOT_ARRAY);
1149 GetValueIfFindKey<std::string>(jsonObject,
1150 jsonObjectEnd,
1151 NEW_BUNDLE_NAME,
1152 newBundleName_,
1153 JsonType::STRING,
1154 true,
1155 ProfileReader::parseResult,
1156 ArrayType::NOT_ARRAY);
1157 GetValueIfFindKey<InstallMark>(jsonObject,
1158 jsonObjectEnd,
1159 INSTALL_MARK,
1160 mark_,
1161 JsonType::OBJECT,
1162 false,
1163 ProfileReader::parseResult,
1164 ArrayType::NOT_ARRAY);
1165 int32_t isOldVersion = ERR_OK;
1166 GetValueIfFindKey<std::map<std::string, InnerBundleUserInfo>>(jsonObject,
1167 jsonObjectEnd,
1168 INNER_BUNDLE_USER_INFOS,
1169 innerBundleUserInfos_,
1170 JsonType::OBJECT,
1171 true,
1172 isOldVersion,
1173 ArrayType::NOT_ARRAY);
1174 int32_t ret = ProfileReader::parseResult;
1175 // need recover parse result to ERR_OK
1176 ProfileReader::parseResult = ERR_OK;
1177 if (ret == ERR_OK && isOldVersion == ERR_APPEXECFWK_PARSE_PROFILE_MISSING_PROP) {
1178 // To be compatible with the old database,
1179 // if the old data does not have bundleUserInfos,
1180 // the default user information needs to be constructed.
1181 BuildDefaultUserInfo();
1182 }
1183 int32_t parseResult = ERR_OK;
1184 GetValueIfFindKey<bool>(jsonObject,
1185 jsonObjectEnd,
1186 BUNDLE_IS_NEW_VERSION,
1187 isNewVersion_,
1188 JsonType::BOOLEAN,
1189 false,
1190 parseResult,
1191 ArrayType::NOT_ARRAY);
1192 GetValueIfFindKey<std::map<std::string, ExtensionAbilityInfo>>(jsonObject,
1193 jsonObjectEnd,
1194 BUNDLE_BASE_EXTENSION_INFOS,
1195 baseExtensionInfos_,
1196 JsonType::OBJECT,
1197 false,
1198 parseResult,
1199 ArrayType::NOT_ARRAY);
1200 GetValueIfFindKey<std::map<std::string, std::vector<Skill>>>(jsonObject,
1201 jsonObjectEnd,
1202 BUNDLE_EXTENSION_SKILL_INFOS,
1203 extensionSkillInfos_,
1204 JsonType::OBJECT,
1205 false,
1206 parseResult,
1207 ArrayType::NOT_ARRAY);
1208 if (parseResult != ERR_OK) {
1209 APP_LOGE("read InnerBundleInfo from database error, error code : %{public}d", parseResult);
1210 return parseResult;
1211 }
1212 return ret;
1213 }
1214
BuildDefaultUserInfo()1215 void InnerBundleInfo::BuildDefaultUserInfo()
1216 {
1217 APP_LOGD("BuildDefaultUserInfo: bundleName: %{public}s.",
1218 baseApplicationInfo_.bundleName.c_str());
1219 InnerBundleUserInfo defaultInnerBundleUserInfo;
1220 defaultInnerBundleUserInfo.bundleUserInfo.userId = GetUserId();
1221 defaultInnerBundleUserInfo.uid = uid_;
1222 defaultInnerBundleUserInfo.gids.emplace_back(gid_);
1223 defaultInnerBundleUserInfo.installTime = baseBundleInfo_.installTime;
1224 defaultInnerBundleUserInfo.updateTime = baseBundleInfo_.updateTime;
1225 defaultInnerBundleUserInfo.bundleName = baseApplicationInfo_.bundleName;
1226 defaultInnerBundleUserInfo.bundleUserInfo.enabled = baseApplicationInfo_.enabled;
1227 AddInnerBundleUserInfo(defaultInnerBundleUserInfo);
1228 }
1229
FindHapModuleInfo(const std::string & modulePackage,int32_t userId) const1230 std::optional<HapModuleInfo> InnerBundleInfo::FindHapModuleInfo(const std::string &modulePackage, int32_t userId) const
1231 {
1232 auto it = innerModuleInfos_.find(modulePackage);
1233 if (it == innerModuleInfos_.end()) {
1234 APP_LOGE("can not find module %{public}s", modulePackage.c_str());
1235 return std::nullopt;
1236 }
1237 HapModuleInfo hapInfo;
1238 hapInfo.name = it->second.name;
1239 hapInfo.package = it->second.modulePackage;
1240 hapInfo.moduleName = it->second.moduleName;
1241 hapInfo.description = it->second.description;
1242 hapInfo.descriptionId = it->second.descriptionId;
1243 hapInfo.label = it->second.label;
1244 hapInfo.labelId = it->second.labelId;
1245 hapInfo.iconPath = it->second.icon;
1246 hapInfo.iconId = it->second.iconId;
1247 hapInfo.mainAbility = it->second.mainAbility;
1248 hapInfo.srcPath = it->second.srcPath;
1249 hapInfo.supportedModes = baseApplicationInfo_.supportedModes;
1250 hapInfo.reqCapabilities = it->second.reqCapabilities;
1251 hapInfo.colorMode = it->second.colorMode;
1252
1253 hapInfo.bundleName = baseApplicationInfo_.bundleName;
1254 hapInfo.mainElementName = it->second.mainAbility;
1255 hapInfo.pages = it->second.pages;
1256 hapInfo.process = it->second.process;
1257 hapInfo.resourcePath = it->second.moduleResPath;
1258 hapInfo.srcEntrance = it->second.srcEntrance;
1259 hapInfo.uiSyntax = it->second.uiSyntax;
1260 hapInfo.virtualMachine = it->second.virtualMachine;
1261 hapInfo.deliveryWithInstall = it->second.distro.deliveryWithInstall;
1262 hapInfo.installationFree = it->second.distro.installationFree;
1263 hapInfo.isModuleJson = it->second.isModuleJson;
1264 hapInfo.isStageBasedModel = it->second.isStageBasedModel;
1265 std::string moduleType = it->second.distro.moduleType;
1266 if (moduleType == Profile::MODULE_TYPE_ENTRY) {
1267 hapInfo.moduleType = ModuleType::ENTRY;
1268 } else if (moduleType == Profile::MODULE_TYPE_FEATURE) {
1269 hapInfo.moduleType = ModuleType::FEATURE;
1270 } else if (moduleType == Profile::MODULE_TYPE_HAR) {
1271 hapInfo.moduleType = ModuleType::HAR;
1272 } else {
1273 hapInfo.moduleType = ModuleType::UNKNOWN;
1274 }
1275 std::string key;
1276 key.append(".").append(modulePackage).append(".");
1277 for (const auto &extension : baseExtensionInfos_) {
1278 if (extension.first.find(key) != std::string::npos) {
1279 hapInfo.extensionInfos.emplace_back(extension.second);
1280 }
1281 }
1282 hapInfo.metadata = it->second.metadata;
1283 bool first = false;
1284 for (auto &ability : baseAbilityInfos_) {
1285 if (ability.first.find(key) != std::string::npos) {
1286 if (!first) {
1287 hapInfo.deviceTypes = ability.second.deviceTypes;
1288 first = true;
1289 }
1290 auto &abilityInfo = hapInfo.abilityInfos.emplace_back(ability.second);
1291 GetApplicationInfo(
1292 ApplicationFlag::GET_APPLICATION_INFO_WITH_PERMISSION, userId, abilityInfo.applicationInfo);
1293 }
1294 }
1295 return hapInfo;
1296 }
1297
FindAbilityInfo(const std::string & bundleName,const std::string & abilityName,int32_t userId) const1298 std::optional<AbilityInfo> InnerBundleInfo::FindAbilityInfo(
1299 const std::string &bundleName, const std::string &abilityName, int32_t userId) const
1300 {
1301 for (const auto &ability : baseAbilityInfos_) {
1302 auto abilityInfo = ability.second;
1303 if ((abilityInfo.bundleName == bundleName) && (abilityInfo.name == abilityName)) {
1304 GetApplicationInfo(
1305 ApplicationFlag::GET_APPLICATION_INFO_WITH_PERMISSION, userId, abilityInfo.applicationInfo);
1306 return abilityInfo;
1307 }
1308 }
1309 return std::nullopt;
1310 }
1311
FindAbilityInfos(const std::string & bundleName,int32_t userId) const1312 std::optional<std::vector<AbilityInfo>> InnerBundleInfo::FindAbilityInfos(
1313 const std::string &bundleName, int32_t userId) const
1314 {
1315 std::vector<AbilityInfo> abilitys;
1316
1317 if (bundleName.empty()) {
1318 return std::nullopt;
1319 }
1320
1321 for (const auto &ability : baseAbilityInfos_) {
1322 auto abilityInfo = ability.second;
1323 if ((abilityInfo.bundleName == bundleName)) {
1324 GetApplicationInfo(
1325 ApplicationFlag::GET_APPLICATION_INFO_WITH_PERMISSION, userId, abilityInfo.applicationInfo);
1326 abilitys.emplace_back(abilityInfo);
1327 }
1328 }
1329 if (!abilitys.empty()) {
1330 return abilitys;
1331 }
1332
1333 return std::nullopt;
1334 }
1335
FindExtensionInfo(const std::string & bundleName,const std::string & extensionName) const1336 std::optional<ExtensionAbilityInfo> InnerBundleInfo::FindExtensionInfo(
1337 const std::string &bundleName, const std::string &extensionName) const
1338 {
1339 for (const auto &extension : baseExtensionInfos_) {
1340 if ((extension.second.bundleName == bundleName) && (extension.second.name == extensionName)) {
1341 return extension.second;
1342 }
1343 }
1344 return std::nullopt;
1345 }
1346
FindExtensionInfos(const std::string & bundleName) const1347 std::optional<std::vector<ExtensionAbilityInfo>> InnerBundleInfo::FindExtensionInfos(
1348 const std::string &bundleName) const
1349 {
1350 std::vector<ExtensionAbilityInfo> extensions;
1351
1352 if (bundleName.empty()) {
1353 return std::nullopt;
1354 }
1355
1356 for (const auto &extension : baseExtensionInfos_) {
1357 if ((extension.second.bundleName == bundleName)) {
1358 extensions.emplace_back(extension.second);
1359 }
1360 }
1361 if (!extensions.empty()) {
1362 return extensions;
1363 }
1364
1365 return std::nullopt;
1366 }
1367
FindAbilityInfosForClone(const std::string & bundleName,const std::string & abilityName,int32_t userId,std::vector<AbilityInfo> & abilitys)1368 void InnerBundleInfo::FindAbilityInfosForClone(const std::string &bundleName,
1369 const std::string &abilityName, int32_t userId, std::vector<AbilityInfo> &abilitys)
1370 {
1371 if (bundleName.empty()) {
1372 return;
1373 }
1374
1375 for (auto &ability : baseAbilityInfos_) {
1376 APP_LOGE("FindAbilityInfosForClonekey = %{public}s", ability.first.c_str());
1377 auto abilityInfo = ability.second;
1378 if ((abilityInfo.bundleName == bundleName && (abilityInfo.name == abilityName))) {
1379 GetApplicationInfo(
1380 ApplicationFlag::GET_APPLICATION_INFO_WITH_PERMISSION, userId, abilityInfo.applicationInfo);
1381 abilitys.emplace_back(abilityInfo);
1382 }
1383 }
1384 return;
1385 }
1386
AddModuleInfo(const InnerBundleInfo & newInfo)1387 bool InnerBundleInfo::AddModuleInfo(const InnerBundleInfo &newInfo)
1388 {
1389 if (newInfo.currentPackage_.empty()) {
1390 APP_LOGE("current package is empty");
1391 return false;
1392 }
1393 if (FindModule(newInfo.currentPackage_)) {
1394 APP_LOGE("current package %{public}s is exist", currentPackage_.c_str());
1395 return false;
1396 }
1397 if (!hasEntry_ && newInfo.HasEntry()) {
1398 hasEntry_ = true;
1399 }
1400 if (mainAbility_.empty() && !newInfo.mainAbility_.empty()) {
1401 UpdateBaseApplicationInfo(newInfo.baseApplicationInfo_);
1402 SetMainAbility(newInfo.mainAbility_);
1403 SetMainAbilityName(newInfo.mainAbilityName_);
1404 }
1405 AddInnerModuleInfo(newInfo.innerModuleInfos_);
1406 AddModuleAbilityInfo(newInfo.baseAbilityInfos_);
1407 AddModuleSkillInfo(newInfo.skillInfos_);
1408 AddModuleExtensionInfos(newInfo.baseExtensionInfos_);
1409 AddModuleExtensionSkillInfos(newInfo.extensionSkillInfos_);
1410 AddModuleFormInfo(newInfo.formInfos_);
1411 AddModuleShortcutInfo(newInfo.shortcutInfos_);
1412 AddModuleCommonEvent(newInfo.commonEvents_);
1413 return true;
1414 }
1415
UpdateBaseBundleInfo(const BundleInfo & bundleInfo,bool isEntry)1416 void InnerBundleInfo::UpdateBaseBundleInfo(const BundleInfo &bundleInfo, bool isEntry)
1417 {
1418 baseBundleInfo_.name = bundleInfo.name;
1419
1420 baseBundleInfo_.versionCode = bundleInfo.versionCode;
1421 baseBundleInfo_.versionName = bundleInfo.versionName;
1422 baseBundleInfo_.minCompatibleVersionCode = bundleInfo.minCompatibleVersionCode;
1423
1424 baseBundleInfo_.compatibleVersion = bundleInfo.compatibleVersion;
1425 baseBundleInfo_.targetVersion = bundleInfo.targetVersion;
1426
1427 baseBundleInfo_.isKeepAlive = bundleInfo.isKeepAlive;
1428 baseBundleInfo_.singleUser = bundleInfo.singleUser;
1429 baseBundleInfo_.isPreInstallApp = bundleInfo.isPreInstallApp;
1430
1431 baseBundleInfo_.vendor = bundleInfo.vendor;
1432 baseBundleInfo_.releaseType = bundleInfo.releaseType;
1433 if (!baseBundleInfo_.isNativeApp) {
1434 baseBundleInfo_.isNativeApp = bundleInfo.isNativeApp;
1435 }
1436
1437 if (isEntry) {
1438 baseBundleInfo_.mainEntry = bundleInfo.mainEntry;
1439 baseBundleInfo_.entryModuleName = bundleInfo.entryModuleName;
1440 baseBundleInfo_.entryInstallationFree = bundleInfo.entryInstallationFree;
1441 }
1442 }
1443
UpdateBaseApplicationInfo(const ApplicationInfo & applicationInfo)1444 void InnerBundleInfo::UpdateBaseApplicationInfo(const ApplicationInfo &applicationInfo)
1445 {
1446 baseApplicationInfo_.name = applicationInfo.name;
1447 baseApplicationInfo_.bundleName = applicationInfo.bundleName;
1448
1449 baseApplicationInfo_.versionCode = applicationInfo.versionCode;
1450 baseApplicationInfo_.versionName = applicationInfo.versionName;
1451 baseApplicationInfo_.minCompatibleVersionCode = applicationInfo.minCompatibleVersionCode;
1452
1453 baseApplicationInfo_.apiCompatibleVersion = applicationInfo.apiCompatibleVersion;
1454 baseApplicationInfo_.apiTargetVersion = applicationInfo.apiTargetVersion;
1455
1456 baseApplicationInfo_.iconPath = applicationInfo.iconPath;
1457 baseApplicationInfo_.iconId = applicationInfo.iconId;
1458 baseApplicationInfo_.label = applicationInfo.label;
1459 baseApplicationInfo_.labelId = applicationInfo.labelId;
1460 baseApplicationInfo_.description = applicationInfo.description;
1461 baseApplicationInfo_.descriptionId = applicationInfo.descriptionId;
1462
1463 baseApplicationInfo_.keepAlive = applicationInfo.keepAlive;
1464 baseApplicationInfo_.removable = applicationInfo.removable;
1465 baseApplicationInfo_.singleUser = applicationInfo.singleUser;
1466 baseApplicationInfo_.userDataClearable = applicationInfo.userDataClearable;
1467 baseApplicationInfo_.accessible = applicationInfo.accessible;
1468
1469 if (!baseApplicationInfo_.isSystemApp) {
1470 baseApplicationInfo_.isSystemApp = applicationInfo.isSystemApp;
1471 }
1472 if (!baseApplicationInfo_.isLauncherApp) {
1473 baseApplicationInfo_.isLauncherApp = applicationInfo.isLauncherApp;
1474 }
1475
1476 baseApplicationInfo_.apiReleaseType = applicationInfo.apiReleaseType;
1477 baseApplicationInfo_.debug = applicationInfo.debug;
1478 baseApplicationInfo_.deviceId = applicationInfo.deviceId;
1479 baseApplicationInfo_.distributedNotificationEnabled = applicationInfo.distributedNotificationEnabled;
1480 baseApplicationInfo_.entityType = applicationInfo.entityType;
1481 baseApplicationInfo_.process = applicationInfo.process;
1482 baseApplicationInfo_.supportedModes = applicationInfo.supportedModes;
1483 baseApplicationInfo_.vendor = applicationInfo.vendor;
1484
1485 baseApplicationInfo_.appPrivilegeLevel = applicationInfo.appPrivilegeLevel;
1486
1487 if (baseApplicationInfo_.nativeLibraryPath.empty()) {
1488 baseApplicationInfo_.nativeLibraryPath = applicationInfo.nativeLibraryPath;
1489 baseApplicationInfo_.cpuAbi = applicationInfo.cpuAbi;
1490 }
1491 }
1492
updateCommonHapInfo(const InnerBundleInfo & newInfo)1493 void InnerBundleInfo::updateCommonHapInfo(const InnerBundleInfo &newInfo)
1494 {
1495 if (newInfo.currentPackage_.empty()) {
1496 APP_LOGE("no package in new info");
1497 return;
1498 }
1499 SetIsKeepData(newInfo.GetIsKeepData());
1500 SetIsSupportBackup(newInfo.GetIsSupportBackup());
1501 }
1502
UpdateModuleInfo(const InnerBundleInfo & newInfo)1503 void InnerBundleInfo::UpdateModuleInfo(const InnerBundleInfo &newInfo)
1504 {
1505 if (newInfo.currentPackage_.empty()) {
1506 APP_LOGE("no package in new info");
1507 return;
1508 }
1509 innerModuleInfos_.erase(newInfo.currentPackage_);
1510 std::string key;
1511 key.append(newInfo.baseApplicationInfo_.bundleName).append(".").append(newInfo.currentPackage_).append(".");
1512 for (auto it = baseAbilityInfos_.begin(); it != baseAbilityInfos_.end();) {
1513 if (it->first.find(key) == 0) {
1514 skillInfos_.erase(it->first);
1515 formInfos_.erase(it->first);
1516 it = baseAbilityInfos_.erase(it);
1517 } else {
1518 ++it;
1519 }
1520 }
1521 for (auto it = baseExtensionInfos_.begin(); it != baseExtensionInfos_.end();) {
1522 if (it->first.find(key) == 0) {
1523 extensionSkillInfos_.erase(it->first);
1524 it = baseExtensionInfos_.erase(it);
1525 } else {
1526 ++it;
1527 }
1528 }
1529 for (auto it = shortcutInfos_.begin(); it != shortcutInfos_.end();) {
1530 if (it->first.find(key) == 0) {
1531 shortcutInfos_.erase(it++);
1532 } else {
1533 ++it;
1534 }
1535 }
1536 for (auto it = commonEvents_.begin(); it != commonEvents_.end();) {
1537 if (it->first.find(key) == 0) {
1538 commonEvents_.erase(it++);
1539 } else {
1540 ++it;
1541 }
1542 }
1543
1544 AddInnerModuleInfo(newInfo.innerModuleInfos_);
1545 AddModuleAbilityInfo(newInfo.baseAbilityInfos_);
1546 AddModuleSkillInfo(newInfo.skillInfos_);
1547 AddModuleExtensionInfos(newInfo.baseExtensionInfos_);
1548 AddModuleExtensionSkillInfos(newInfo.extensionSkillInfos_);
1549 AddModuleFormInfo(newInfo.formInfos_);
1550 AddModuleShortcutInfo(newInfo.shortcutInfos_);
1551 AddModuleCommonEvent(newInfo.commonEvents_);
1552 }
1553
RemoveModuleInfo(const std::string & modulePackage)1554 void InnerBundleInfo::RemoveModuleInfo(const std::string &modulePackage)
1555 {
1556 if (innerModuleInfos_.find(modulePackage) == innerModuleInfos_.end()) {
1557 APP_LOGE("can not find module %{public}s", modulePackage.c_str());
1558 return;
1559 }
1560 std::string key;
1561 key.append(".").append(modulePackage).append(".");
1562 if (mainAbility_.find(key) != std::string::npos) {
1563 mainAbility_.clear();
1564 hasEntry_ = false;
1565 mainAbilityName_.clear();
1566 }
1567 for (auto it = innerModuleInfos_.begin(); it != innerModuleInfos_.end();) {
1568 if (it->first == modulePackage) {
1569 innerModuleInfos_.erase(it++);
1570 } else {
1571 ++it;
1572 }
1573 }
1574 for (auto it = baseAbilityInfos_.begin(); it != baseAbilityInfos_.end();) {
1575 if (it->first.find(key) != std::string::npos) {
1576 baseAbilityInfos_.erase(it++);
1577 } else {
1578 ++it;
1579 }
1580 }
1581 for (auto it = skillInfos_.begin(); it != skillInfos_.end();) {
1582 if (it->first.find(key) != std::string::npos) {
1583 skillInfos_.erase(it++);
1584 } else {
1585 ++it;
1586 }
1587 }
1588 for (auto it = baseExtensionInfos_.begin(); it != baseExtensionInfos_.end();) {
1589 if (it->first.find(key) != std::string::npos) {
1590 baseExtensionInfos_.erase(it++);
1591 } else {
1592 ++it;
1593 }
1594 }
1595 for (auto it = extensionSkillInfos_.begin(); it != extensionSkillInfos_.end();) {
1596 if (it->first.find(key) != std::string::npos) {
1597 extensionSkillInfos_.erase(it++);
1598 } else {
1599 ++it;
1600 }
1601 }
1602 for (auto it = formInfos_.begin(); it != formInfos_.end();) {
1603 if (it->first.find(key) != std::string::npos) {
1604 formInfos_.erase(it++);
1605 } else {
1606 ++it;
1607 }
1608 }
1609 for (auto it = shortcutInfos_.begin(); it != shortcutInfos_.end();) {
1610 if (it->first.find(key) != std::string::npos) {
1611 shortcutInfos_.erase(it++);
1612 } else {
1613 ++it;
1614 }
1615 }
1616 for (auto it = commonEvents_.begin(); it != commonEvents_.end();) {
1617 if (it->first.find(key) != std::string::npos) {
1618 commonEvents_.erase(it++);
1619 } else {
1620 ++it;
1621 }
1622 }
1623 }
1624
ToString() const1625 std::string InnerBundleInfo::ToString() const
1626 {
1627 nlohmann::json j;
1628 j[IS_SUPPORT_BACKUP] = isSupportBackup_;
1629 j[APP_TYPE] = appType_;
1630 j[UID] = uid_;
1631 j[GID] = gid_;
1632 j[BASE_DATA_DIR] = baseDataDir_;
1633 j[BUNDLE_STATUS] = bundleStatus_;
1634 j[ALLOWED_ACLS] = allowedAcls_;
1635 j[BASE_APPLICATION_INFO] = baseApplicationInfo_;
1636 j[BASE_BUNDLE_INFO] = baseBundleInfo_;
1637 j[BASE_ABILITY_INFO] = baseAbilityInfos_;
1638 j[INNER_MODULE_INFO] = innerModuleInfos_;
1639 j[SKILL_INFOS] = skillInfos_;
1640 j[USER_ID] = userId_;
1641 j[MAIN_ABILITY] = mainAbility_;
1642 j[MAIN_ABILITY_NAME] = mainAbilityName_;
1643 j[APP_FEATURE] = appFeature_;
1644 j[HAS_ENTRY] = hasEntry_;
1645 j[MODULE_FORMS] = formInfos_;
1646 j[MODULE_SHORTCUT] = shortcutInfos_;
1647 j[NEW_BUNDLE_NAME] = newBundleName_;
1648 j[MODULE_COMMON_EVENT] = commonEvents_;
1649 j[INSTALL_MARK] = mark_;
1650 j[INNER_BUNDLE_USER_INFOS] = innerBundleUserInfos_;
1651 j[BUNDLE_IS_NEW_VERSION] = isNewVersion_;
1652 j[BUNDLE_BASE_EXTENSION_INFOS] = baseExtensionInfos_;
1653 j[BUNDLE_EXTENSION_SKILL_INFOS] = extensionSkillInfos_;
1654 return j.dump();
1655 }
1656
GetApplicationInfo(int32_t flags,int32_t userId,ApplicationInfo & appInfo) const1657 void InnerBundleInfo::GetApplicationInfo(int32_t flags, int32_t userId, ApplicationInfo &appInfo) const
1658 {
1659 InnerBundleUserInfo innerBundleUserInfo;
1660 if (!GetInnerBundleUserInfo(userId, innerBundleUserInfo)) {
1661 APP_LOGE("can not find userId %{public}d when get applicationInfo", userId);
1662 return;
1663 }
1664
1665 appInfo = baseApplicationInfo_;
1666
1667 appInfo.accessTokenId = innerBundleUserInfo.accessTokenId;
1668 appInfo.enabled = innerBundleUserInfo.bundleUserInfo.enabled;
1669 appInfo.uid = innerBundleUserInfo.uid;
1670
1671 for (const auto &info : innerModuleInfos_) {
1672 ModuleInfo moduleInfo;
1673 moduleInfo.moduleName = info.second.moduleName;
1674 moduleInfo.moduleSourceDir = info.second.modulePath;
1675 appInfo.moduleInfos.emplace_back(moduleInfo);
1676 appInfo.moduleSourceDirs.emplace_back(info.second.modulePath);
1677 if (info.second.isEntry) {
1678 appInfo.entryDir = info.second.modulePath;
1679 }
1680 if ((static_cast<uint32_t>(flags) & GET_APPLICATION_INFO_WITH_PERMISSION) ==
1681 GET_APPLICATION_INFO_WITH_PERMISSION) {
1682 std::transform(info.second.requestPermissions.begin(),
1683 info.second.requestPermissions.end(),
1684 std::back_inserter(appInfo.permissions),
1685 [](const auto &p) { return p.name; });
1686 }
1687 if ((static_cast<uint32_t>(flags) & GET_APPLICATION_INFO_WITH_METADATA) == GET_APPLICATION_INFO_WITH_METADATA) {
1688 bool isModuleJson = info.second.isModuleJson;
1689 if (!isModuleJson && info.second.metaData.customizeData.size() > 0) {
1690 appInfo.metaData[info.second.moduleName] = info.second.metaData.customizeData;
1691 }
1692 if (isModuleJson && info.second.metadata.size() > 0) {
1693 appInfo.metadata[info.second.moduleName] = info.second.metadata;
1694 }
1695 }
1696 }
1697 if (!appInfo.permissions.empty()) {
1698 RemoveDuplicateName(appInfo.permissions);
1699 }
1700 }
1701
GetBundleInfo(int32_t flags,BundleInfo & bundleInfo,int32_t userId) const1702 void InnerBundleInfo::GetBundleInfo(int32_t flags, BundleInfo &bundleInfo, int32_t userId) const
1703 {
1704 InnerBundleUserInfo innerBundleUserInfo;
1705 if (!GetInnerBundleUserInfo(userId, innerBundleUserInfo)) {
1706 APP_LOGE("can not find userId %{public}d when GetBundleInfo", userId);
1707 return;
1708 }
1709
1710 bundleInfo = baseBundleInfo_;
1711
1712 bundleInfo.uid = innerBundleUserInfo.uid;
1713 if (!innerBundleUserInfo.gids.empty()) {
1714 bundleInfo.gid = innerBundleUserInfo.gids[0];
1715 }
1716 bundleInfo.installTime = innerBundleUserInfo.installTime;
1717 bundleInfo.updateTime = innerBundleUserInfo.updateTime;
1718
1719 GetApplicationInfo(ApplicationFlag::GET_BASIC_APPLICATION_INFO, userId, bundleInfo.applicationInfo);
1720 for (const auto &info : innerModuleInfos_) {
1721 if ((static_cast<uint32_t>(flags) & GET_BUNDLE_WITH_REQUESTED_PERMISSION)
1722 == GET_BUNDLE_WITH_REQUESTED_PERMISSION) {
1723 std::transform(info.second.requestPermissions.begin(),
1724 info.second.requestPermissions.end(),
1725 std::back_inserter(bundleInfo.reqPermissions),
1726 [](const auto &p) { return p.name; });
1727 std::transform(info.second.definePermissions.begin(),
1728 info.second.definePermissions.end(),
1729 std::back_inserter(bundleInfo.defPermissions),
1730 [](const auto &p) { return p.name; });
1731 std::transform(info.second.defPermissions.begin(),
1732 info.second.defPermissions.end(),
1733 std::back_inserter(bundleInfo.defPermissions),
1734 [](const auto &p) { return p.name; });
1735 }
1736 bundleInfo.hapModuleNames.emplace_back(info.second.modulePackage);
1737 auto hapmoduleinfo = FindHapModuleInfo(info.second.modulePackage, userId);
1738 if (hapmoduleinfo) {
1739 bundleInfo.hapModuleInfos.emplace_back(*hapmoduleinfo);
1740 bundleInfo.moduleNames.emplace_back(info.second.moduleName);
1741 bundleInfo.moduleDirs.emplace_back(info.second.modulePath);
1742 bundleInfo.modulePublicDirs.emplace_back(info.second.moduleDataDir);
1743 bundleInfo.moduleResPaths.emplace_back(info.second.moduleResPath);
1744 } else {
1745 APP_LOGE("can not find hapmoduleinfo %{public}s", info.second.moduleName.c_str());
1746 }
1747 }
1748 if ((static_cast<uint32_t>(flags) & GET_BUNDLE_WITH_REQUESTED_PERMISSION)
1749 == GET_BUNDLE_WITH_REQUESTED_PERMISSION) {
1750 if (!bundleInfo.reqPermissions.empty()) {
1751 RemoveDuplicateName(bundleInfo.reqPermissions);
1752 }
1753 if (!bundleInfo.defPermissions.empty()) {
1754 RemoveDuplicateName(bundleInfo.defPermissions);
1755 }
1756 if (!BundlePermissionMgr::GetRequestPermissionStates(bundleInfo)) {
1757 APP_LOGE("get request permission state failed");
1758 }
1759 bundleInfo.reqPermissionDetails = GetAllRequestPermissions();
1760 }
1761 GetBundleWithAbilities(flags, bundleInfo, userId);
1762 GetBundeleWithExtension(flags, bundleInfo, userId);
1763 }
1764
GetBundleWithAbilities(int32_t flags,BundleInfo & bundleInfo,int32_t userId) const1765 void InnerBundleInfo::GetBundleWithAbilities(int32_t flags, BundleInfo &bundleInfo, int32_t userId) const
1766 {
1767 APP_LOGD("bundleName:%{public}s userid:%{public}d", bundleInfo.name.c_str(), userId);
1768 if (static_cast<uint32_t>(flags) & GET_BUNDLE_WITH_ABILITIES) {
1769 for (auto &ability : baseAbilityInfos_) {
1770 if (!(static_cast<uint32_t>(flags) & GET_ABILITY_INFO_WITH_DISABLE)
1771 && !IsAbilityEnabled(ability.second, userId)) {
1772 APP_LOGW("%{public}s is disabled,", ability.second.name.c_str());
1773 continue;
1774 }
1775 AbilityInfo abilityInfo = ability.second;
1776 bundleInfo.abilityInfos.emplace_back(abilityInfo);
1777 }
1778 }
1779 }
1780
GetBundeleWithExtension(int32_t flags,BundleInfo & bundleInfo,int32_t userId) const1781 void InnerBundleInfo::GetBundeleWithExtension(int32_t flags, BundleInfo &bundleInfo, int32_t userId) const
1782 {
1783 APP_LOGD("get bundleInfo with extensionInfo begin");
1784 if ((static_cast<uint32_t>(flags) & GET_BUNDLE_WITH_EXTENSION_INFO) == GET_BUNDLE_WITH_EXTENSION_INFO) {
1785 for (const auto &extensionInfo : baseExtensionInfos_) {
1786 if (!extensionInfo.second.enabled) {
1787 continue;
1788 }
1789 ExtensionAbilityInfo info = extensionInfo.second;
1790 bundleInfo.extensionInfos.emplace_back(info);
1791 }
1792 }
1793 APP_LOGD("get bundleInfo with extensionInfo end");
1794 }
1795
CheckSpecialMetaData(const std::string & metaData) const1796 bool InnerBundleInfo::CheckSpecialMetaData(const std::string &metaData) const
1797 {
1798 if (isNewVersion_) {
1799 for (const auto &moduleInfo : innerModuleInfos_) {
1800 for (const auto &data : moduleInfo.second.metadata) {
1801 if (metaData == data.name) {
1802 return true;
1803 }
1804 }
1805 }
1806 return false;
1807 }
1808 // old version
1809 for (const auto &moduleInfo : innerModuleInfos_) {
1810 for (const auto &data : moduleInfo.second.metaData.customizeData) {
1811 if (metaData == data.name) {
1812 return true;
1813 }
1814 }
1815 }
1816 return false;
1817 }
1818
GetFormsInfoByModule(const std::string & moduleName,std::vector<FormInfo> & formInfos) const1819 void InnerBundleInfo::GetFormsInfoByModule(const std::string &moduleName, std::vector<FormInfo> &formInfos) const
1820 {
1821 for (const auto &data : formInfos_) {
1822 for (auto &form : data.second) {
1823 if (form.moduleName == moduleName) {
1824 formInfos.emplace_back(form);
1825 }
1826 }
1827 }
1828 }
1829
GetFormsInfoByApp(std::vector<FormInfo> & formInfos) const1830 void InnerBundleInfo::GetFormsInfoByApp(std::vector<FormInfo> &formInfos) const
1831 {
1832 for (const auto &data : formInfos_) {
1833 for (auto &form : data.second) {
1834 formInfos.emplace_back(form);
1835 }
1836 }
1837 }
1838
GetShortcutInfos(std::vector<ShortcutInfo> & shortcutInfos) const1839 void InnerBundleInfo::GetShortcutInfos(std::vector<ShortcutInfo> &shortcutInfos) const
1840 {
1841 if (isNewVersion_) {
1842 AbilityInfo abilityInfo;
1843 GetMainAbilityInfo(abilityInfo);
1844 if (!abilityInfo.resourcePath.empty() && abilityInfo.metadata.size() > 0) {
1845 std::vector<std::string> rawJson;
1846 BundleMgrClient bundleMgrClient;
1847 bool ret = bundleMgrClient.GetResConfigFile(abilityInfo, META_DATA_SHORTCUTS_NAME, rawJson);
1848 if (ret == false) {
1849 APP_LOGD("GetResConfigFile return false");
1850 return;
1851 }
1852 if (rawJson.size() == 0) {
1853 APP_LOGD("rawJson size 0. skip.");
1854 return;
1855 }
1856 nlohmann::json jsonObject = nlohmann::json::parse(rawJson[0], nullptr, false);
1857 if (jsonObject.is_discarded()) {
1858 APP_LOGE("shortcuts json invalid");
1859 return;
1860 }
1861 ShortcutJson shortcutJson = jsonObject.get<ShortcutJson>();
1862 for (const Shortcut &item : shortcutJson.shortcuts) {
1863 ShortcutInfo shortcutInfo;
1864 shortcutInfo.id = item.shortcutId;
1865 shortcutInfo.bundleName = abilityInfo.bundleName;
1866 shortcutInfo.icon = item.icon;
1867 shortcutInfo.label = item.label;
1868 shortcutInfo.iconId = item.iconId;
1869 shortcutInfo.labelId = item.labelId;
1870 for (const ShortcutWant &shortcutWant : item.wants) {
1871 ShortcutIntent shortcutIntent;
1872 shortcutIntent.targetBundle = shortcutWant.bundleName;
1873 shortcutIntent.targetClass = shortcutWant.abilityName;
1874 shortcutInfo.intents.emplace_back(shortcutIntent);
1875 }
1876 shortcutInfos.emplace_back(shortcutInfo);
1877 }
1878 }
1879 return;
1880 }
1881 for (const auto &shortcut : shortcutInfos_) {
1882 shortcutInfos.emplace_back(shortcut.second);
1883 }
1884 }
1885
GetCommonEvents(const std::string & eventKey,std::vector<CommonEventInfo> & commonEvents) const1886 void InnerBundleInfo::GetCommonEvents(const std::string &eventKey, std::vector<CommonEventInfo> &commonEvents) const
1887 {
1888 CommonEventInfo item;
1889 for (const auto &commonEvent : commonEvents_) {
1890 for (const auto &event : commonEvent.second.events) {
1891 if (event == eventKey) {
1892 item = commonEvent.second;
1893 item.uid = GetUid(GetUserId());
1894 commonEvents.emplace_back(item);
1895 break;
1896 }
1897 }
1898 }
1899 }
1900
GetInnerModuleInfoByModuleName(const std::string & moduleName) const1901 std::optional<InnerModuleInfo> InnerBundleInfo::GetInnerModuleInfoByModuleName(const std::string &moduleName) const
1902 {
1903 for (const auto &innerModuleInfo : innerModuleInfos_) {
1904 if (innerModuleInfo.second.moduleName == moduleName) {
1905 return innerModuleInfo.second;
1906 }
1907 }
1908 return std::nullopt;
1909 }
1910
GetModuleNames(std::vector<std::string> & moduleNames) const1911 void InnerBundleInfo::GetModuleNames(std::vector<std::string> &moduleNames) const
1912 {
1913 for (const auto &innerModuleInfo : innerModuleInfos_) {
1914 moduleNames.emplace_back(innerModuleInfo.second.moduleName);
1915 }
1916 }
1917
RemoveInnerBundleUserInfo(int32_t userId)1918 void InnerBundleInfo::RemoveInnerBundleUserInfo(int32_t userId)
1919 {
1920 auto& key = NameAndUserIdToKey(GetBundleName(), userId);
1921 auto infoItem = innerBundleUserInfos_.find(key);
1922 if (infoItem == innerBundleUserInfos_.end()) {
1923 return;
1924 }
1925
1926 innerBundleUserInfos_.erase(key);
1927 }
1928
AddInnerBundleUserInfo(const InnerBundleUserInfo & innerBundleUserInfo)1929 void InnerBundleInfo::AddInnerBundleUserInfo(
1930 const InnerBundleUserInfo& innerBundleUserInfo)
1931 {
1932 auto& key = NameAndUserIdToKey(
1933 GetBundleName(), innerBundleUserInfo.bundleUserInfo.userId);
1934 auto infoItem = innerBundleUserInfos_.find(key);
1935 if (infoItem == innerBundleUserInfos_.end()) {
1936 innerBundleUserInfos_.emplace(key, innerBundleUserInfo);
1937 return;
1938 }
1939
1940 innerBundleUserInfos_[key] = innerBundleUserInfo;
1941 }
1942
GetInnerBundleUserInfo(int32_t userId,InnerBundleUserInfo & innerBundleUserInfo) const1943 bool InnerBundleInfo::GetInnerBundleUserInfo(
1944 int32_t userId, InnerBundleUserInfo& innerBundleUserInfo) const
1945 {
1946 if (userId == Constants::NOT_EXIST_USERID) {
1947 return true;
1948 }
1949
1950 if (userId == Constants::ALL_USERID) {
1951 if (innerBundleUserInfos_.empty()) {
1952 return false;
1953 }
1954
1955 innerBundleUserInfo = innerBundleUserInfos_.begin()->second;
1956 return true;
1957 }
1958
1959 auto& key = NameAndUserIdToKey(GetBundleName(), userId);
1960 auto infoItem = innerBundleUserInfos_.find(key);
1961 if (infoItem == innerBundleUserInfos_.end()) {
1962 APP_LOGD("no this user %{public}s", key.c_str());
1963 return false;
1964 }
1965
1966 innerBundleUserInfo = infoItem->second;
1967 return true;
1968 }
1969
HasInnerBundleUserInfo(int32_t userId) const1970 bool InnerBundleInfo::HasInnerBundleUserInfo(int32_t userId) const
1971 {
1972 if (userId == Constants::ALL_USERID) {
1973 return !innerBundleUserInfos_.empty();
1974 }
1975
1976 auto& key = NameAndUserIdToKey(GetBundleName(), userId);
1977 auto infoItem = innerBundleUserInfos_.find(key);
1978 return infoItem != innerBundleUserInfos_.end();
1979 }
1980
SetBundleInstallTime(const int64_t time,int32_t userId)1981 void InnerBundleInfo::SetBundleInstallTime(const int64_t time, int32_t userId)
1982 {
1983 auto& key = NameAndUserIdToKey(GetBundleName(), userId);
1984 auto infoItem = innerBundleUserInfos_.find(key);
1985 if (infoItem == innerBundleUserInfos_.end()) {
1986 return;
1987 }
1988
1989 infoItem->second.installTime = time;
1990 infoItem->second.updateTime = time;
1991 }
1992
SetAccessTokenId(uint32_t accessToken,const int32_t userId)1993 void InnerBundleInfo::SetAccessTokenId(uint32_t accessToken, const int32_t userId)
1994 {
1995 auto& key = NameAndUserIdToKey(GetBundleName(), userId);
1996 auto infoItem = innerBundleUserInfos_.find(key);
1997 if (infoItem == innerBundleUserInfos_.end()) {
1998 return;
1999 }
2000
2001 infoItem->second.accessTokenId = accessToken;
2002 }
2003
SetBundleUpdateTime(const int64_t time,int32_t userId)2004 void InnerBundleInfo::SetBundleUpdateTime(const int64_t time, int32_t userId)
2005 {
2006 auto& key = NameAndUserIdToKey(GetBundleName(), userId);
2007 auto infoItem = innerBundleUserInfos_.find(key);
2008 if (infoItem == innerBundleUserInfos_.end()) {
2009 return;
2010 }
2011
2012 infoItem->second.updateTime = time;
2013 }
2014
IsAbilityEnabled(const AbilityInfo & abilityInfo,int32_t userId) const2015 bool InnerBundleInfo::IsAbilityEnabled(const AbilityInfo &abilityInfo, int32_t userId) const
2016 {
2017 APP_LOGD("IsAbilityEnabled bundleName:%{public}s, userId:%{public}d", abilityInfo.bundleName.c_str(), userId);
2018 if (userId == Constants::NOT_EXIST_USERID) {
2019 return true;
2020 }
2021 auto& key = NameAndUserIdToKey(abilityInfo.bundleName, userId);
2022 auto infoItem = innerBundleUserInfos_.find(key);
2023 if (infoItem == innerBundleUserInfos_.end()) {
2024 APP_LOGE("innerBundleUserInfos find key:%{public}s, error", key.c_str());
2025 return false;
2026 }
2027 auto disabledAbilities = infoItem->second.bundleUserInfo.disabledAbilities;
2028 if (std::find(disabledAbilities.begin(), disabledAbilities.end(), abilityInfo.name) != disabledAbilities.end()) {
2029 return false;
2030 } else {
2031 return true;
2032 }
2033 }
2034
SetAbilityEnabled(const std::string & bundleName,const std::string & abilityName,bool isEnabled,int32_t userId)2035 bool InnerBundleInfo::SetAbilityEnabled(const std::string &bundleName,
2036 const std::string &abilityName,
2037 bool isEnabled,
2038 int32_t userId)
2039 {
2040 APP_LOGD("SetAbilityEnabled :%{public}s, %{public}s, %{public}d",
2041 bundleName.c_str(), abilityName.c_str(), userId);
2042 for (auto &ability : baseAbilityInfos_) {
2043 if ((ability.second.bundleName == bundleName) && (ability.second.name == abilityName)) {
2044 auto &key = NameAndUserIdToKey(bundleName, userId);
2045 auto infoItem = innerBundleUserInfos_.find(key);
2046 if (infoItem == innerBundleUserInfos_.end()) {
2047 APP_LOGE("SetAbilityEnabled find innerBundleUserInfo failed");
2048 return false;
2049 }
2050 auto iter = std::find(infoItem->second.bundleUserInfo.disabledAbilities.begin(),
2051 infoItem->second.bundleUserInfo.disabledAbilities.end(),
2052 abilityName);
2053 if (iter != infoItem->second.bundleUserInfo.disabledAbilities.end()) {
2054 if (isEnabled) {
2055 infoItem->second.bundleUserInfo.disabledAbilities.erase(iter);
2056 }
2057 } else {
2058 if (!isEnabled) {
2059 infoItem->second.bundleUserInfo.disabledAbilities.push_back(abilityName);
2060 }
2061 }
2062 return true;
2063 }
2064 }
2065 return false;
2066 }
2067
RemoveDuplicateName(std::vector<std::string> & name) const2068 void InnerBundleInfo::RemoveDuplicateName(std::vector<std::string> &name) const
2069 {
2070 std::sort(name.begin(), name.end());
2071 auto iter = std::unique(name.begin(), name.end());
2072 name.erase(iter, name.end());
2073 }
2074
GetAllDefinePermissions() const2075 std::vector<DefinePermission> InnerBundleInfo::GetAllDefinePermissions() const
2076 {
2077 std::vector<DefinePermission> definePermissions;
2078 for (const auto &info : innerModuleInfos_) {
2079 std::transform(info.second.definePermissions.begin(),
2080 info.second.definePermissions.end(),
2081 std::back_inserter(definePermissions),
2082 [](const auto &p) { return p; });
2083 }
2084 if (!definePermissions.empty()) {
2085 std::sort(definePermissions.begin(), definePermissions.end(),
2086 [](DefinePermission defPermA, DefinePermission defPermB) {
2087 return defPermA.name < defPermB.name;
2088 });
2089 auto iter = std::unique(definePermissions.begin(), definePermissions.end(),
2090 [](DefinePermission defPermA, DefinePermission defPermB) {
2091 return defPermA.name == defPermB.name;
2092 });
2093 definePermissions.erase(iter, definePermissions.end());
2094 }
2095 return definePermissions;
2096 }
2097
GetAllRequestPermissions() const2098 std::vector<RequestPermission> InnerBundleInfo::GetAllRequestPermissions() const
2099 {
2100 std::vector<RequestPermission> requestPermissions;
2101 for (const auto &info : innerModuleInfos_) {
2102 std::transform(info.second.requestPermissions.begin(),
2103 info.second.requestPermissions.end(),
2104 std::back_inserter(requestPermissions),
2105 [](const auto &p) { return p; });
2106 }
2107 if (!requestPermissions.empty()) {
2108 std::sort(requestPermissions.begin(), requestPermissions.end(),
2109 [](RequestPermission reqPermA, RequestPermission reqPermB) {
2110 return reqPermA.name < reqPermB.name;
2111 });
2112 auto iter = std::unique(requestPermissions.begin(), requestPermissions.end(),
2113 [](RequestPermission reqPermA, RequestPermission reqPermB) {
2114 return reqPermA.name == reqPermB.name;
2115 });
2116 requestPermissions.erase(iter, requestPermissions.end());
2117 }
2118 return requestPermissions;
2119 }
2120
SetApplicationEnabled(bool enabled,int32_t userId)2121 void InnerBundleInfo::SetApplicationEnabled(bool enabled, int32_t userId)
2122 {
2123 auto& key = NameAndUserIdToKey(GetBundleName(), userId);
2124 auto infoItem = innerBundleUserInfos_.find(key);
2125 if (infoItem == innerBundleUserInfos_.end()) {
2126 return;
2127 }
2128
2129 infoItem->second.bundleUserInfo.enabled = enabled;
2130 }
2131
GetCurModuleName() const2132 const std::string &InnerBundleInfo::GetCurModuleName() const
2133 {
2134 if (innerModuleInfos_.find(currentPackage_) != innerModuleInfos_.end()) {
2135 return innerModuleInfos_.at(currentPackage_).moduleName;
2136 }
2137
2138 return Constants::EMPTY_STRING;
2139 }
2140
GetResponseUserId(int32_t requestUserId) const2141 int32_t InnerBundleInfo::GetResponseUserId(int32_t requestUserId) const
2142 {
2143 if (HasInnerBundleUserInfo(requestUserId)) {
2144 return requestUserId;
2145 }
2146
2147 if (requestUserId < Constants::START_USERID) {
2148 APP_LOGE("requestUserId(%{public}d) less than start userId.", requestUserId);
2149 return Constants::INVALID_USERID;
2150 }
2151
2152 int32_t responseUserId = Constants::INVALID_USERID;
2153 for (const auto &innerBundleUserInfo : innerBundleUserInfos_) {
2154 if (innerBundleUserInfo.second.bundleUserInfo.userId < Constants::START_USERID) {
2155 responseUserId = innerBundleUserInfo.second.bundleUserInfo.userId;
2156 break;
2157 }
2158 }
2159
2160 APP_LOGD("requestUserId(%{public}d) and responseUserId(%{public}d).", requestUserId, responseUserId);
2161 return responseUserId;
2162 }
2163
GetDistributedBundleInfo(DistributedBundleInfo & distributedBundleInfo) const2164 void InnerBundleInfo::GetDistributedBundleInfo(DistributedBundleInfo &distributedBundleInfo) const
2165 {
2166 distributedBundleInfo.name = baseBundleInfo_.name;
2167 distributedBundleInfo.versionCode = baseBundleInfo_.versionCode;
2168 distributedBundleInfo.compatibleVersionCode = baseBundleInfo_.compatibleVersion;
2169 distributedBundleInfo.versionName = baseBundleInfo_.versionName;
2170 distributedBundleInfo.minCompatibleVersion = baseBundleInfo_.minCompatibleVersionCode;
2171 distributedBundleInfo.targetVersionCode = baseBundleInfo_.targetVersion;
2172 distributedBundleInfo.appId = baseBundleInfo_.appId;
2173
2174 for (const auto &innerModuleInfo : innerModuleInfos_) {
2175 if (innerModuleInfo.second.isEntry) {
2176 distributedBundleInfo.mainAbility = innerModuleInfo.second.mainAbility;
2177 }
2178 }
2179
2180 for (const auto &innerBundleUserInfo : innerBundleUserInfos_) {
2181 BundleUserInfo bundleUserInfo = innerBundleUserInfo.second.bundleUserInfo;
2182 for (const auto &item : baseAbilityInfos_) {
2183 bundleUserInfo.abilities.emplace_back(item.second.name);
2184 }
2185 distributedBundleInfo.bundleUserInfos.emplace_back(bundleUserInfo);
2186 }
2187 }
2188
GetUriPrefixList(std::vector<std::string> & uriPrefixList,const std::string & excludeModule) const2189 void InnerBundleInfo::GetUriPrefixList(std::vector<std::string> &uriPrefixList,
2190 const std::string &excludeModule) const
2191 {
2192 std::vector<std::string> uriList;
2193 for (const auto &abilityInfoPair : baseAbilityInfos_) {
2194 if (abilityInfoPair.second.uri.empty()) {
2195 continue;
2196 }
2197 if (!excludeModule.empty() && abilityInfoPair.first.find(excludeModule) == 0) {
2198 continue;
2199 }
2200 uriList.emplace_back(abilityInfoPair.second.uri);
2201 }
2202 for (const auto &extensionInfoPair : baseExtensionInfos_) {
2203 if (extensionInfoPair.second.uri.empty()) {
2204 continue;
2205 }
2206 if (!excludeModule.empty() && extensionInfoPair.first.find(excludeModule) == 0) {
2207 continue;
2208 }
2209 uriList.emplace_back(extensionInfoPair.second.uri);
2210 }
2211 for (const std::string &uri : uriList) {
2212 size_t schemePos = uri.find(Constants::URI_SEPARATOR);
2213 if (schemePos == uri.npos) {
2214 continue;
2215 }
2216 size_t cutPos = uri.find(Constants::SEPARATOR, schemePos + Constants::URI_SEPARATOR_LEN);
2217 std::string uriPrefix;
2218 if (cutPos == uri.npos) {
2219 uriPrefix = uri;
2220 } else {
2221 uriPrefix = uri.substr(0, cutPos);
2222 }
2223 uriPrefixList.emplace_back(uriPrefix);
2224 }
2225 }
2226
GetUriPrefixList(std::vector<std::string> & uriPrefixList,int32_t userId,const std::string & excludeModule) const2227 void InnerBundleInfo::GetUriPrefixList(std::vector<std::string> &uriPrefixList, int32_t userId,
2228 const std::string &excludeModule) const
2229 {
2230 auto& key = NameAndUserIdToKey(GetBundleName(), userId);
2231 auto infoItem = innerBundleUserInfos_.find(key);
2232 if (infoItem == innerBundleUserInfos_.end()) {
2233 return;
2234 }
2235 GetUriPrefixList(uriPrefixList, excludeModule);
2236 }
2237
GetDistroModuleName() const2238 std::vector<std::string> InnerBundleInfo::GetDistroModuleName() const
2239 {
2240 std::vector<std::string> moduleVec;
2241 for (const auto &info : innerModuleInfos_) {
2242 moduleVec.emplace_back(info.second.moduleName);
2243 }
2244 return moduleVec;
2245 }
2246
GetModuleNameByPackage(const std::string & packageName) const2247 std::string InnerBundleInfo::GetModuleNameByPackage(const std::string &packageName) const
2248 {
2249 auto it = innerModuleInfos_.find(packageName);
2250 if (it == innerModuleInfos_.end()) {
2251 return Constants::EMPTY_STRING;
2252 }
2253 return it->second.moduleName;
2254 }
2255
GetModuleTypeByPackage(const std::string & packageName) const2256 std::string InnerBundleInfo::GetModuleTypeByPackage(const std::string &packageName) const
2257 {
2258 auto it = innerModuleInfos_.find(packageName);
2259 if (it == innerModuleInfos_.end()) {
2260 return Constants::EMPTY_STRING;
2261 }
2262 return it->second.distro.moduleType;
2263 }
2264 } // namespace AppExecFwk
2265 } // namespace OHOS
2266