1 /*
2 * Copyright (c) 2023-2024 Huawei Device Co., Ltd.
3 * Licensed under the Apache License, Version 2.0 (the "License");
4 * you may not use this file except in compliance with the License.
5 * You may obtain a copy of the License at
6 *
7 * http://www.apache.org/licenses/LICENSE-2.0
8 *
9 * Unless required by applicable law or agreed to in writing, software
10 * distributed under the License is distributed on an "AS IS" BASIS,
11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 * See the License for the specific language governing permissions and
13 * limitations under the License.
14 */
15
16 #include "inner_bundle_info.h"
17
18 #include <algorithm>
19 #include <deque>
20 #include <regex>
21 #include <unistd.h>
22
23 #include "common_profile.h"
24 #include "hilog_tag_wrapper.h"
25 #include "string_ex.h"
26
27 namespace OHOS {
28 namespace AppExecFwk {
29 namespace {
30 const std::string APP_TYPE = "appType";
31 const std::string UID = "uid";
32 const std::string GID = "gid";
33 const std::string BUNDLE_STATUS = "bundleStatus";
34 const std::string BASE_APPLICATION_INFO = "baseApplicationInfo";
35 const std::string BASE_BUNDLE_INFO = "baseBundleInfo";
36 const std::string BASE_ABILITY_INFO = "baseAbilityInfos";
37 const std::string INNER_MODULE_INFO = "innerModuleInfos";
38 const std::string USER_ID = "userId_";
39 const std::string APP_FEATURE = "appFeature";
40 const std::string CAN_UNINSTALL = "canUninstall";
41 const std::string NAME = "name";
42 const std::string MODULE_PACKAGE = "modulePackage";
43 const std::string MODULE_PATH = "modulePath";
44 const std::string MODULE_NAME = "moduleName";
45 const std::string MODULE_DESCRIPTION = "description";
46 const std::string MODULE_DESCRIPTION_ID = "descriptionId";
47 const std::string MODULE_ICON = "icon";
48 const std::string MODULE_ICON_ID = "iconId";
49 const std::string MODULE_LABEL = "label";
50 const std::string MODULE_LABEL_ID = "labelId";
51 const std::string MODULE_DESCRIPTION_INSTALLATION_FREE = "installationFree";
52 const std::string MODULE_IS_REMOVABLE = "isRemovable";
53 const std::string MODULE_UPGRADE_FLAG = "upgradeFlag";
54 const std::string MODULE_IS_ENTRY = "isEntry";
55 const std::string MODULE_METADATA = "metaData";
56 const std::string MODULE_COLOR_MODE = "colorMode";
57 const std::string MODULE_DISTRO = "distro";
58 const std::string MODULE_REQ_CAPABILITIES = "reqCapabilities";
59 const std::string MODULE_DATA_DIR = "moduleDataDir";
60 const std::string MODULE_RES_PATH = "moduleResPath";
61 const std::string MODULE_HAP_PATH = "hapPath";
62 const std::string MODULE_ABILITY_KEYS = "abilityKeys";
63 const std::string MODULE_MAIN_ABILITY = "mainAbility";
64 const std::string MODULE_ENTRY_ABILITY_KEY = "entryAbilityKey";
65 const std::string MODULE_DEPENDENCIES = "dependencies";
66 const std::string MODULE_IS_LIB_ISOLATED = "isLibIsolated";
67 const std::string MODULE_NATIVE_LIBRARY_PATH = "nativeLibraryPath";
68 const std::string MODULE_CPU_ABI = "cpuAbi";
69 const std::string NEW_BUNDLE_NAME = "newBundleName";
70 const std::string MODULE_SRC_PATH = "srcPath";
71 const std::string MODULE_HASH_VALUE = "hashValue";
72 const std::string SCHEME_SEPARATOR = "://";
73 const std::string PORT_SEPARATOR = ":";
74 const std::string PATH_SEPARATOR = "/";
75 const std::string PARAM_SEPARATOR = "?";
76 const std::string INSTALL_MARK = "installMark";
77 const std::string TYPE_WILDCARD = "*/*";
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_EXTENSION_KEYS = "extensionKeys";
86 const std::string MODULE_IS_MODULE_JSON = "isModuleJson";
87 const std::string MODULE_IS_STAGE_BASED_MODEL = "isStageBasedModel";
88 const std::string BUNDLE_IS_NEW_VERSION = "isNewVersion";
89 const std::string BUNDLE_IS_NEED_UPDATE = "upgradeFlag";
90 const std::string BUNDLE_BASE_EXTENSION_INFOS = "baseExtensionInfos";
91 const std::string ALLOWED_ACLS = "allowedAcls";
92 const std::string META_DATA_SHORTCUTS_NAME = "ohos.ability.shortcuts";
93 const std::string APP_INDEX = "appIndex";
94 const std::string BUNDLE_IS_SANDBOX_APP = "isSandboxApp";
95 const std::string BUNDLE_SANDBOX_PERSISTENT_INFO = "sandboxPersistentInfo";
96 const std::string MODULE_COMPILE_MODE = "compileMode";
97 const std::string BUNDLE_HQF_INFOS = "hqfInfos";
98 const std::string MODULE_TARGET_MODULE_NAME = "targetModuleName";
99 const std::string MODULE_TARGET_PRIORITY = "targetPriority";
100 const std::string MODULE_ATOMIC_SERVICE_MODULE_TYPE = "atomicServiceModuleType";
101 const std::string MODULE_PRELOADS = "preloads";
102 const std::string MODULE_BUNDLE_TYPE = "bundleType";
103 const std::string MODULE_VERSION_CODE = "versionCode";
104 const std::string MODULE_VERSION_NAME = "versionName";
105 const std::string MODULE_PROXY_DATAS = "proxyDatas";
106 const std::string MODULE_BUILD_HASH = "buildHash";
107 const std::string MODULE_ISOLATION_MODE = "isolationMode";
108 const std::string MODULE_COMPRESS_NATIVE_LIBS = "compressNativeLibs";
109 const std::string MODULE_NATIVE_LIBRARY_FILE_NAMES = "nativeLibraryFileNames";
110 const std::string MODULE_AOT_COMPILE_STATUS = "aotCompileStatus";
111 const std::string DATA_GROUP_INFOS = "dataGroupInfos";
112 const std::map<std::string, IsolationMode> ISOLATION_MODE_MAP = {
113 {"isolationOnly", IsolationMode::ISOLATION_ONLY},
114 {"nonisolationOnly", IsolationMode::NONISOLATION_ONLY},
115 {"isolationFirst", IsolationMode::ISOLATION_FIRST},
116 };
117 const std::string NATIVE_LIBRARY_PATH_SYMBOL = "!/";
118
119 const std::string STR_PHONE = "phone";
120 const std::string STR_DEFAULT = "default";
121
122 const std::string OVERLAY_TYPE = "overlayType";
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 } // namespace
133
InnerBundleInfo()134 InnerBundleInfo::InnerBundleInfo()
135 {
136 baseApplicationInfo_ = std::make_shared<ApplicationInfo>();
137 if (baseApplicationInfo_ == nullptr) {
138 TAG_LOGE(AAFwkTag::ABILITY_SIM, "null baseApplicationInfo_");
139 }
140 baseBundleInfo_ = std::make_shared<BundleInfo>();
141 TAG_LOGD(AAFwkTag::ABILITY_SIM, "instance created");
142 }
143
operator =(const InnerBundleInfo & info)144 InnerBundleInfo &InnerBundleInfo::operator=(const InnerBundleInfo &info)
145 {
146 if (this == &info) {
147 return *this;
148 }
149 this->appType_ = info.appType_;
150 this->userId_ = info.userId_;
151 this->bundleStatus_ = info.bundleStatus_;
152 this->appFeature_ = info.appFeature_;
153 this->allowedAcls_ = info.allowedAcls_;
154 this->appIndex_ = info.appIndex_;
155 this->isSandboxApp_ = info.isSandboxApp_;
156 this->currentPackage_ = info.currentPackage_;
157 this->onlyCreateBundleUser_ = info.onlyCreateBundleUser_;
158 this->innerModuleInfos_ = info.innerModuleInfos_;
159 this->baseAbilityInfos_ = info.baseAbilityInfos_;
160 this->isNewVersion_ = info.isNewVersion_;
161 this->baseExtensionInfos_= info.baseExtensionInfos_;
162 this->baseApplicationInfo_ = std::make_shared<ApplicationInfo>();
163 if (info.baseApplicationInfo_ != nullptr) {
164 *(this->baseApplicationInfo_) = *(info.baseApplicationInfo_);
165 }
166 this->provisionMetadatas_ = info.provisionMetadatas_;
167 this->baseBundleInfo_ = std::make_shared<BundleInfo>();
168 if (info.baseBundleInfo_ != nullptr) {
169 *(this->baseBundleInfo_) = *(info.baseBundleInfo_);
170 }
171 this->overlayType_ = info.overlayType_;
172 return *this;
173 }
174
~InnerBundleInfo()175 InnerBundleInfo::~InnerBundleInfo()
176 {
177 TAG_LOGD(AAFwkTag::ABILITY_SIM, "instance destroyed");
178 }
179
to_json(nlohmann::json & jsonObject,const Distro & distro)180 void to_json(nlohmann::json &jsonObject, const Distro &distro)
181 {
182 jsonObject = nlohmann::json {
183 {ProfileReader::BUNDLE_MODULE_PROFILE_KEY_DELIVERY_WITH_INSTALL, distro.deliveryWithInstall},
184 {ProfileReader::BUNDLE_MODULE_PROFILE_KEY_MODULE_NAME, distro.moduleName},
185 {ProfileReader::BUNDLE_MODULE_PROFILE_KEY_MODULE_TYPE, distro.moduleType},
186 {ProfileReader::BUNDLE_MODULE_PROFILE_KEY_MODULE_INSTALLATION_FREE, distro.installationFree}
187 };
188 }
189
to_json(nlohmann::json & jsonObject,const Dependency & dependency)190 void to_json(nlohmann::json &jsonObject, const Dependency &dependency)
191 {
192 jsonObject = nlohmann::json {
193 {Profile::DEPENDENCIES_MODULE_NAME, dependency.moduleName},
194 {Profile::DEPENDENCIES_BUNDLE_NAME, dependency.bundleName},
195 {Profile::APP_VERSION_CODE, dependency.versionCode}
196 };
197 }
198
to_json(nlohmann::json & jsonObject,const InnerModuleInfo & info)199 void to_json(nlohmann::json &jsonObject, const InnerModuleInfo &info)
200 {
201 jsonObject = nlohmann::json {
202 {NAME, info.name},
203 {MODULE_PACKAGE, info.modulePackage},
204 {MODULE_NAME, info.moduleName},
205 {MODULE_PATH, info.modulePath},
206 {MODULE_DATA_DIR, info.moduleDataDir},
207 {MODULE_RES_PATH, info.moduleResPath},
208 {MODULE_IS_ENTRY, info.isEntry},
209 {MODULE_METADATA, info.metaData},
210 {MODULE_COLOR_MODE, info.colorMode},
211 {MODULE_DISTRO, info.distro},
212 {MODULE_DESCRIPTION, info.description},
213 {MODULE_DESCRIPTION_ID, info.descriptionId},
214 {MODULE_ICON, info.icon},
215 {MODULE_ICON_ID, info.iconId},
216 {MODULE_LABEL, info.label},
217 {MODULE_LABEL_ID, info.labelId},
218 {MODULE_DESCRIPTION_INSTALLATION_FREE, info.installationFree},
219 {MODULE_IS_REMOVABLE, info.isRemovable},
220 {MODULE_UPGRADE_FLAG, info.upgradeFlag},
221 {MODULE_REQ_CAPABILITIES, info.reqCapabilities},
222 {MODULE_ABILITY_KEYS, info.abilityKeys},
223 {MODULE_MAIN_ABILITY, info.mainAbility},
224 {MODULE_ENTRY_ABILITY_KEY, info.entryAbilityKey},
225 {MODULE_SRC_PATH, info.srcPath},
226 {MODULE_HASH_VALUE, info.hashValue},
227 {MODULE_PROCESS, info.process},
228 {MODULE_SRC_ENTRANCE, info.srcEntrance},
229 {MODULE_DEVICE_TYPES, info.deviceTypes},
230 {MODULE_VIRTUAL_MACHINE, info.virtualMachine},
231 {MODULE_UI_SYNTAX, info.uiSyntax},
232 {MODULE_PAGES, info.pages},
233 {MODULE_META_DATA, info.metadata},
234 {MODULE_EXTENSION_KEYS, info.extensionKeys},
235 {MODULE_IS_MODULE_JSON, info.isModuleJson},
236 {MODULE_IS_STAGE_BASED_MODEL, info.isStageBasedModel},
237 {MODULE_DEPENDENCIES, info.dependencies},
238 {MODULE_IS_LIB_ISOLATED, info.isLibIsolated},
239 {MODULE_NATIVE_LIBRARY_PATH, info.nativeLibraryPath},
240 {MODULE_CPU_ABI, info.cpuAbi},
241 {MODULE_HAP_PATH, info.hapPath},
242 {MODULE_COMPILE_MODE, info.compileMode},
243 {MODULE_TARGET_MODULE_NAME, info.targetModuleName},
244 {MODULE_TARGET_PRIORITY, info.targetPriority},
245 {MODULE_ATOMIC_SERVICE_MODULE_TYPE, info.atomicServiceModuleType},
246 {MODULE_PRELOADS, info.preloads},
247 {MODULE_BUNDLE_TYPE, info.bundleType},
248 {MODULE_VERSION_CODE, info.versionCode},
249 {MODULE_VERSION_NAME, info.versionName},
250 {MODULE_PROXY_DATAS, info.proxyDatas},
251 {MODULE_BUILD_HASH, info.buildHash},
252 {MODULE_ISOLATION_MODE, info.isolationMode},
253 {MODULE_COMPRESS_NATIVE_LIBS, info.compressNativeLibs},
254 {MODULE_NATIVE_LIBRARY_FILE_NAMES, info.nativeLibraryFileNames},
255 {MODULE_AOT_COMPILE_STATUS, info.aotCompileStatus},
256 };
257 }
258
ToJson(nlohmann::json & jsonObject) const259 void InnerBundleInfo::ToJson(nlohmann::json &jsonObject) const
260 {
261 jsonObject[APP_TYPE] = appType_;
262 jsonObject[BUNDLE_STATUS] = bundleStatus_;
263 jsonObject[ALLOWED_ACLS] = allowedAcls_;
264 jsonObject[BASE_APPLICATION_INFO] = *baseApplicationInfo_;
265 jsonObject[BASE_BUNDLE_INFO] = *baseBundleInfo_;
266 jsonObject[BASE_ABILITY_INFO] = baseAbilityInfos_;
267 jsonObject[INNER_MODULE_INFO] = innerModuleInfos_;
268 jsonObject[USER_ID] = userId_;
269 jsonObject[APP_FEATURE] = appFeature_;
270 jsonObject[BUNDLE_IS_NEW_VERSION] = isNewVersion_;
271 jsonObject[BUNDLE_BASE_EXTENSION_INFOS] = baseExtensionInfos_;
272 jsonObject[APP_INDEX] = appIndex_;
273 jsonObject[BUNDLE_IS_SANDBOX_APP] = isSandboxApp_;
274 jsonObject[OVERLAY_TYPE] = overlayType_;
275 }
276
from_json(const nlohmann::json & jsonObject,InnerModuleInfo & info)277 void from_json(const nlohmann::json &jsonObject, InnerModuleInfo &info)
278 {
279 // these are not required fields.
280 const auto &jsonObjectEnd = jsonObject.end();
281 int32_t parseResult = ERR_OK;
282 GetValueIfFindKey<std::string>(jsonObject,
283 jsonObjectEnd,
284 NAME,
285 info.name,
286 JsonType::STRING,
287 false,
288 parseResult,
289 ArrayType::NOT_ARRAY);
290 GetValueIfFindKey<std::string>(jsonObject,
291 jsonObjectEnd,
292 MODULE_PACKAGE,
293 info.modulePackage,
294 JsonType::STRING,
295 false,
296 parseResult,
297 ArrayType::NOT_ARRAY);
298 GetValueIfFindKey<std::string>(jsonObject,
299 jsonObjectEnd,
300 MODULE_NAME,
301 info.moduleName,
302 JsonType::STRING,
303 false,
304 parseResult,
305 ArrayType::NOT_ARRAY);
306 GetValueIfFindKey<std::string>(jsonObject,
307 jsonObjectEnd,
308 MODULE_PATH,
309 info.modulePath,
310 JsonType::STRING,
311 false,
312 parseResult,
313 ArrayType::NOT_ARRAY);
314 GetValueIfFindKey<std::string>(jsonObject,
315 jsonObjectEnd,
316 MODULE_DATA_DIR,
317 info.moduleDataDir,
318 JsonType::STRING,
319 false,
320 parseResult,
321 ArrayType::NOT_ARRAY);
322 GetValueIfFindKey<std::string>(jsonObject,
323 jsonObjectEnd,
324 MODULE_HAP_PATH,
325 info.hapPath,
326 JsonType::STRING,
327 false,
328 parseResult,
329 ArrayType::NOT_ARRAY);
330 GetValueIfFindKey<std::string>(jsonObject,
331 jsonObjectEnd,
332 MODULE_RES_PATH,
333 info.moduleResPath,
334 JsonType::STRING,
335 false,
336 parseResult,
337 ArrayType::NOT_ARRAY);
338 GetValueIfFindKey<bool>(jsonObject,
339 jsonObjectEnd,
340 MODULE_IS_ENTRY,
341 info.isEntry,
342 JsonType::BOOLEAN,
343 false,
344 parseResult,
345 ArrayType::NOT_ARRAY);
346 GetValueIfFindKey<MetaData>(jsonObject,
347 jsonObjectEnd,
348 MODULE_METADATA,
349 info.metaData,
350 JsonType::OBJECT,
351 false,
352 parseResult,
353 ArrayType::NOT_ARRAY);
354 GetValueIfFindKey<ModuleColorMode>(jsonObject,
355 jsonObjectEnd,
356 MODULE_COLOR_MODE,
357 info.colorMode,
358 JsonType::NUMBER,
359 false,
360 parseResult,
361 ArrayType::NOT_ARRAY);
362 GetValueIfFindKey<Distro>(jsonObject,
363 jsonObjectEnd,
364 MODULE_DISTRO,
365 info.distro,
366 JsonType::OBJECT,
367 false,
368 parseResult,
369 ArrayType::NOT_ARRAY);
370 GetValueIfFindKey<std::string>(jsonObject,
371 jsonObjectEnd,
372 MODULE_DESCRIPTION,
373 info.description,
374 JsonType::STRING,
375 false,
376 parseResult,
377 ArrayType::NOT_ARRAY);
378 GetValueIfFindKey<int32_t>(jsonObject,
379 jsonObjectEnd,
380 MODULE_DESCRIPTION_ID,
381 info.descriptionId,
382 JsonType::NUMBER,
383 false,
384 parseResult,
385 ArrayType::NOT_ARRAY);
386 GetValueIfFindKey<std::string>(jsonObject,
387 jsonObjectEnd,
388 MODULE_ICON,
389 info.icon,
390 JsonType::STRING,
391 false,
392 parseResult,
393 ArrayType::NOT_ARRAY);
394 GetValueIfFindKey<int32_t>(jsonObject,
395 jsonObjectEnd,
396 MODULE_ICON_ID,
397 info.iconId,
398 JsonType::NUMBER,
399 false,
400 parseResult,
401 ArrayType::NOT_ARRAY);
402 GetValueIfFindKey<std::string>(jsonObject,
403 jsonObjectEnd,
404 MODULE_LABEL,
405 info.label,
406 JsonType::STRING,
407 false,
408 parseResult,
409 ArrayType::NOT_ARRAY);
410 GetValueIfFindKey<int32_t>(jsonObject,
411 jsonObjectEnd,
412 MODULE_LABEL_ID,
413 info.labelId,
414 JsonType::NUMBER,
415 false,
416 parseResult,
417 ArrayType::NOT_ARRAY);
418 GetValueIfFindKey<std::string>(jsonObject,
419 jsonObjectEnd,
420 MODULE_MAIN_ABILITY,
421 info.mainAbility,
422 JsonType::STRING,
423 false,
424 parseResult,
425 ArrayType::NOT_ARRAY);
426 GetValueIfFindKey<std::string>(jsonObject,
427 jsonObjectEnd,
428 MODULE_ENTRY_ABILITY_KEY,
429 info.entryAbilityKey,
430 JsonType::STRING,
431 false,
432 parseResult,
433 ArrayType::NOT_ARRAY);
434 GetValueIfFindKey<std::string>(jsonObject,
435 jsonObjectEnd,
436 MODULE_SRC_PATH,
437 info.srcPath,
438 JsonType::STRING,
439 false,
440 parseResult,
441 ArrayType::NOT_ARRAY);
442 GetValueIfFindKey<std::string>(jsonObject,
443 jsonObjectEnd,
444 MODULE_HASH_VALUE,
445 info.hashValue,
446 JsonType::STRING,
447 false,
448 parseResult,
449 ArrayType::NOT_ARRAY);
450 GetValueIfFindKey<bool>(jsonObject,
451 jsonObjectEnd,
452 MODULE_DESCRIPTION_INSTALLATION_FREE,
453 info.installationFree,
454 JsonType::BOOLEAN,
455 false,
456 parseResult,
457 ArrayType::NOT_ARRAY);
458 GetValueIfFindKey<std::map<std::string, bool>>(jsonObject,
459 jsonObjectEnd,
460 MODULE_IS_REMOVABLE,
461 info.isRemovable,
462 JsonType::OBJECT,
463 false,
464 parseResult,
465 ArrayType::NOT_ARRAY);
466 GetValueIfFindKey<int32_t>(jsonObject,
467 jsonObjectEnd,
468 MODULE_UPGRADE_FLAG,
469 info.upgradeFlag,
470 JsonType::NUMBER,
471 false,
472 parseResult,
473 ArrayType::NOT_ARRAY);
474 GetValueIfFindKey<std::vector<std::string>>(jsonObject,
475 jsonObjectEnd,
476 MODULE_REQ_CAPABILITIES,
477 info.reqCapabilities,
478 JsonType::ARRAY,
479 false,
480 parseResult,
481 ArrayType::STRING);
482 GetValueIfFindKey<std::vector<std::string>>(jsonObject,
483 jsonObjectEnd,
484 MODULE_ABILITY_KEYS,
485 info.abilityKeys,
486 JsonType::ARRAY,
487 false,
488 parseResult,
489 ArrayType::STRING);
490 GetValueIfFindKey<std::string>(jsonObject,
491 jsonObjectEnd,
492 MODULE_PROCESS,
493 info.process,
494 JsonType::STRING,
495 false,
496 parseResult,
497 ArrayType::NOT_ARRAY);
498 GetValueIfFindKey<std::string>(jsonObject,
499 jsonObjectEnd,
500 MODULE_SRC_ENTRANCE,
501 info.srcEntrance,
502 JsonType::STRING,
503 false,
504 parseResult,
505 ArrayType::NOT_ARRAY);
506 GetValueIfFindKey<std::vector<std::string>>(jsonObject,
507 jsonObjectEnd,
508 MODULE_DEVICE_TYPES,
509 info.deviceTypes,
510 JsonType::ARRAY,
511 false,
512 parseResult,
513 ArrayType::STRING);
514 GetValueIfFindKey<std::string>(jsonObject,
515 jsonObjectEnd,
516 MODULE_VIRTUAL_MACHINE,
517 info.virtualMachine,
518 JsonType::STRING,
519 false,
520 parseResult,
521 ArrayType::NOT_ARRAY);
522 GetValueIfFindKey<std::string>(jsonObject,
523 jsonObjectEnd,
524 MODULE_UI_SYNTAX,
525 info.uiSyntax,
526 JsonType::STRING,
527 false,
528 parseResult,
529 ArrayType::NOT_ARRAY);
530 GetValueIfFindKey<std::string>(jsonObject,
531 jsonObjectEnd,
532 MODULE_PAGES,
533 info.pages,
534 JsonType::STRING,
535 false,
536 parseResult,
537 ArrayType::NOT_ARRAY);
538 GetValueIfFindKey<std::vector<Metadata>>(jsonObject,
539 jsonObjectEnd,
540 MODULE_META_DATA,
541 info.metadata,
542 JsonType::ARRAY,
543 false,
544 parseResult,
545 ArrayType::OBJECT);
546 GetValueIfFindKey<std::vector<std::string>>(jsonObject,
547 jsonObjectEnd,
548 MODULE_EXTENSION_KEYS,
549 info.extensionKeys,
550 JsonType::ARRAY,
551 false,
552 parseResult,
553 ArrayType::STRING);
554 GetValueIfFindKey<bool>(jsonObject,
555 jsonObjectEnd,
556 MODULE_IS_MODULE_JSON,
557 info.isModuleJson,
558 JsonType::BOOLEAN,
559 false,
560 parseResult,
561 ArrayType::NOT_ARRAY);
562 GetValueIfFindKey<bool>(jsonObject,
563 jsonObjectEnd,
564 MODULE_IS_STAGE_BASED_MODEL,
565 info.isStageBasedModel,
566 JsonType::BOOLEAN,
567 false,
568 parseResult,
569 ArrayType::NOT_ARRAY);
570 GetValueIfFindKey<std::vector<Dependency>>(jsonObject,
571 jsonObjectEnd,
572 MODULE_DEPENDENCIES,
573 info.dependencies,
574 JsonType::ARRAY,
575 false,
576 parseResult,
577 ArrayType::OBJECT);
578 GetValueIfFindKey<std::string>(jsonObject,
579 jsonObjectEnd,
580 MODULE_COMPILE_MODE,
581 info.compileMode,
582 JsonType::STRING,
583 false,
584 parseResult,
585 ArrayType::NOT_ARRAY);
586 GetValueIfFindKey<bool>(jsonObject,
587 jsonObjectEnd,
588 MODULE_IS_LIB_ISOLATED,
589 info.isLibIsolated,
590 JsonType::BOOLEAN,
591 false,
592 parseResult,
593 ArrayType::NOT_ARRAY);
594 GetValueIfFindKey<std::string>(jsonObject,
595 jsonObjectEnd,
596 MODULE_NATIVE_LIBRARY_PATH,
597 info.nativeLibraryPath,
598 JsonType::STRING,
599 false,
600 parseResult,
601 ArrayType::NOT_ARRAY);
602 GetValueIfFindKey<std::string>(jsonObject,
603 jsonObjectEnd,
604 MODULE_CPU_ABI,
605 info.cpuAbi,
606 JsonType::STRING,
607 false,
608 parseResult,
609 ArrayType::NOT_ARRAY);
610 GetValueIfFindKey<std::string>(jsonObject,
611 jsonObjectEnd,
612 MODULE_TARGET_MODULE_NAME,
613 info.targetModuleName,
614 JsonType::STRING,
615 false,
616 parseResult,
617 ArrayType::NOT_ARRAY);
618 GetValueIfFindKey<int32_t>(jsonObject,
619 jsonObjectEnd,
620 MODULE_TARGET_PRIORITY,
621 info.targetPriority,
622 JsonType::NUMBER,
623 false,
624 parseResult,
625 ArrayType::NOT_ARRAY);
626 GetValueIfFindKey<AtomicServiceModuleType>(jsonObject,
627 jsonObjectEnd,
628 MODULE_ATOMIC_SERVICE_MODULE_TYPE,
629 info.atomicServiceModuleType,
630 JsonType::NUMBER,
631 false,
632 parseResult,
633 ArrayType::NOT_ARRAY);
634 GetValueIfFindKey<std::vector<std::string>>(jsonObject,
635 jsonObjectEnd,
636 MODULE_PRELOADS,
637 info.preloads,
638 JsonType::ARRAY,
639 false,
640 parseResult,
641 ArrayType::STRING);
642 GetValueIfFindKey<BundleType>(jsonObject,
643 jsonObjectEnd,
644 MODULE_BUNDLE_TYPE,
645 info.bundleType,
646 JsonType::NUMBER,
647 false,
648 parseResult,
649 ArrayType::NOT_ARRAY);
650 GetValueIfFindKey<uint32_t>(jsonObject,
651 jsonObjectEnd,
652 MODULE_VERSION_CODE,
653 info.versionCode,
654 JsonType::NUMBER,
655 false,
656 parseResult,
657 ArrayType::NOT_ARRAY);
658 GetValueIfFindKey<std::string>(jsonObject,
659 jsonObjectEnd,
660 MODULE_VERSION_NAME,
661 info.versionName,
662 JsonType::STRING,
663 false,
664 parseResult,
665 ArrayType::NOT_ARRAY);
666 GetValueIfFindKey<std::vector<ProxyData>>(jsonObject,
667 jsonObjectEnd,
668 MODULE_PROXY_DATAS,
669 info.proxyDatas,
670 JsonType::ARRAY,
671 false,
672 parseResult,
673 ArrayType::OBJECT);
674 GetValueIfFindKey<std::string>(jsonObject,
675 jsonObjectEnd,
676 MODULE_BUILD_HASH,
677 info.buildHash,
678 JsonType::STRING,
679 false,
680 parseResult,
681 ArrayType::NOT_ARRAY);
682 GetValueIfFindKey<std::string>(jsonObject,
683 jsonObjectEnd,
684 MODULE_ISOLATION_MODE,
685 info.isolationMode,
686 JsonType::STRING,
687 false,
688 parseResult,
689 ArrayType::NOT_ARRAY);
690 GetValueIfFindKey<bool>(jsonObject,
691 jsonObjectEnd,
692 MODULE_COMPRESS_NATIVE_LIBS,
693 info.compressNativeLibs,
694 JsonType::BOOLEAN,
695 false,
696 parseResult,
697 ArrayType::NOT_ARRAY);
698 GetValueIfFindKey<std::vector<std::string>>(jsonObject,
699 jsonObjectEnd,
700 MODULE_NATIVE_LIBRARY_FILE_NAMES,
701 info.nativeLibraryFileNames,
702 JsonType::ARRAY,
703 false,
704 parseResult,
705 ArrayType::STRING);
706 GetValueIfFindKey<AOTCompileStatus>(jsonObject,
707 jsonObjectEnd,
708 MODULE_AOT_COMPILE_STATUS,
709 info.aotCompileStatus,
710 JsonType::NUMBER,
711 false,
712 parseResult,
713 ArrayType::NOT_ARRAY);
714 if (parseResult != ERR_OK) {
715 TAG_LOGE(
716 AAFwkTag::ABILITY_SIM, "read InnerModuleInfo from database error:%{public}d", parseResult);
717 }
718 }
719
from_json(const nlohmann::json & jsonObject,Dependency & dependency)720 void from_json(const nlohmann::json &jsonObject, Dependency &dependency)
721 {
722 const auto &jsonObjectEnd = jsonObject.end();
723 int32_t parseResult = ERR_OK;
724 GetValueIfFindKey<std::string>(jsonObject,
725 jsonObjectEnd,
726 Profile::DEPENDENCIES_MODULE_NAME,
727 dependency.moduleName,
728 JsonType::STRING,
729 false,
730 parseResult,
731 ArrayType::NOT_ARRAY);
732 GetValueIfFindKey<std::string>(jsonObject,
733 jsonObjectEnd,
734 Profile::DEPENDENCIES_BUNDLE_NAME,
735 dependency.bundleName,
736 JsonType::STRING,
737 false,
738 parseResult,
739 ArrayType::NOT_ARRAY);
740 GetValueIfFindKey<int>(jsonObject,
741 jsonObjectEnd,
742 Profile::APP_VERSION_CODE,
743 dependency.versionCode,
744 JsonType::NUMBER,
745 false,
746 parseResult,
747 ArrayType::NOT_ARRAY);
748 if (parseResult != ERR_OK) {
749 TAG_LOGE(AAFwkTag::ABILITY_SIM, "Dependency error:%{public}d", parseResult);
750 }
751 }
752
from_json(const nlohmann::json & jsonObject,Distro & distro)753 void from_json(const nlohmann::json &jsonObject, Distro &distro)
754 {
755 TAG_LOGD(AAFwkTag::ABILITY_SIM, "called");
756 const auto &jsonObjectEnd = jsonObject.end();
757 int32_t parseResult = ERR_OK;
758 GetValueIfFindKey<bool>(jsonObject,
759 jsonObjectEnd,
760 ProfileReader::BUNDLE_MODULE_PROFILE_KEY_DELIVERY_WITH_INSTALL,
761 distro.deliveryWithInstall,
762 JsonType::BOOLEAN,
763 true,
764 parseResult,
765 ArrayType::NOT_ARRAY);
766 GetValueIfFindKey<std::string>(jsonObject,
767 jsonObjectEnd,
768 ProfileReader::BUNDLE_MODULE_PROFILE_KEY_MODULE_NAME,
769 distro.moduleName,
770 JsonType::STRING,
771 true,
772 parseResult,
773 ArrayType::NOT_ARRAY);
774 GetValueIfFindKey<std::string>(jsonObject,
775 jsonObjectEnd,
776 ProfileReader::BUNDLE_MODULE_PROFILE_KEY_MODULE_TYPE,
777 distro.moduleType,
778 JsonType::STRING,
779 true,
780 parseResult,
781 ArrayType::NOT_ARRAY);
782 // mustFlag decide by distro.moduleType
783 GetValueIfFindKey<bool>(jsonObject,
784 jsonObjectEnd,
785 ProfileReader::BUNDLE_MODULE_PROFILE_KEY_MODULE_INSTALLATION_FREE,
786 distro.installationFree,
787 JsonType::BOOLEAN,
788 false,
789 parseResult,
790 ArrayType::NOT_ARRAY);
791 if (parseResult != ERR_OK) {
792 TAG_LOGE(AAFwkTag::ABILITY_SIM, "Distro error:%{public}d", parseResult);
793 }
794 }
795
FromJson(const nlohmann::json & jsonObject)796 int32_t InnerBundleInfo::FromJson(const nlohmann::json &jsonObject)
797 {
798 const auto &jsonObjectEnd = jsonObject.end();
799 int32_t parseResult = ERR_OK;
800 GetValueIfFindKey<Constants::AppType>(jsonObject,
801 jsonObjectEnd,
802 APP_TYPE,
803 appType_,
804 JsonType::NUMBER,
805 true,
806 parseResult,
807 ArrayType::NOT_ARRAY);
808 GetValueIfFindKey<std::vector<std::string>>(jsonObject,
809 jsonObjectEnd,
810 ALLOWED_ACLS,
811 allowedAcls_,
812 JsonType::ARRAY,
813 false,
814 parseResult,
815 ArrayType::STRING);
816 GetValueIfFindKey<BundleStatus>(jsonObject,
817 jsonObjectEnd,
818 BUNDLE_STATUS,
819 bundleStatus_,
820 JsonType::NUMBER,
821 true,
822 parseResult,
823 ArrayType::NOT_ARRAY);
824 GetValueIfFindKey<BundleInfo>(jsonObject,
825 jsonObjectEnd,
826 BASE_BUNDLE_INFO,
827 *baseBundleInfo_,
828 JsonType::OBJECT,
829 true,
830 parseResult,
831 ArrayType::NOT_ARRAY);
832 GetValueIfFindKey<ApplicationInfo>(jsonObject,
833 jsonObjectEnd,
834 BASE_APPLICATION_INFO,
835 *baseApplicationInfo_,
836 JsonType::OBJECT,
837 true,
838 parseResult,
839 ArrayType::NOT_ARRAY);
840 GetValueIfFindKey<std::map<std::string, AbilityInfo>>(jsonObject,
841 jsonObjectEnd,
842 BASE_ABILITY_INFO,
843 baseAbilityInfos_,
844 JsonType::OBJECT,
845 true,
846 parseResult,
847 ArrayType::NOT_ARRAY);
848 GetValueIfFindKey<std::map<std::string, InnerModuleInfo>>(jsonObject,
849 jsonObjectEnd,
850 INNER_MODULE_INFO,
851 innerModuleInfos_,
852 JsonType::OBJECT,
853 true,
854 parseResult,
855 ArrayType::NOT_ARRAY);
856 GetValueIfFindKey<int>(jsonObject,
857 jsonObjectEnd,
858 USER_ID,
859 userId_,
860 JsonType::NUMBER,
861 true,
862 parseResult,
863 ArrayType::NOT_ARRAY);
864 GetValueIfFindKey<std::string>(jsonObject,
865 jsonObjectEnd,
866 APP_FEATURE,
867 appFeature_,
868 JsonType::STRING,
869 true,
870 parseResult,
871 ArrayType::NOT_ARRAY);
872 GetValueIfFindKey<bool>(jsonObject,
873 jsonObjectEnd,
874 BUNDLE_IS_NEW_VERSION,
875 isNewVersion_,
876 JsonType::BOOLEAN,
877 false,
878 parseResult,
879 ArrayType::NOT_ARRAY);
880 GetValueIfFindKey<std::map<std::string, ExtensionAbilityInfo>>(jsonObject,
881 jsonObjectEnd,
882 BUNDLE_BASE_EXTENSION_INFOS,
883 baseExtensionInfos_,
884 JsonType::OBJECT,
885 false,
886 parseResult,
887 ArrayType::NOT_ARRAY);
888 GetValueIfFindKey<int>(jsonObject,
889 jsonObjectEnd,
890 APP_INDEX,
891 appIndex_,
892 JsonType::NUMBER,
893 false,
894 parseResult,
895 ArrayType::NOT_ARRAY);
896 GetValueIfFindKey<bool>(jsonObject,
897 jsonObjectEnd,
898 BUNDLE_IS_SANDBOX_APP,
899 isSandboxApp_,
900 JsonType::BOOLEAN,
901 false,
902 parseResult,
903 ArrayType::NOT_ARRAY);
904 GetValueIfFindKey<int32_t>(jsonObject,
905 jsonObjectEnd,
906 OVERLAY_TYPE,
907 overlayType_,
908 JsonType::NUMBER,
909 false,
910 parseResult,
911 ArrayType::NOT_ARRAY);
912 if (parseResult != ERR_OK) {
913 TAG_LOGE(
914 AAFwkTag::ABILITY_SIM, "read InnerBundleInfo from database error:%{public}d", parseResult);
915 }
916 return parseResult;
917 }
918
FindHapModuleInfo(const std::string & modulePackage,int32_t userId) const919 std::optional<HapModuleInfo> InnerBundleInfo::FindHapModuleInfo(const std::string &modulePackage, int32_t userId) const
920 {
921 auto it = innerModuleInfos_.find(modulePackage);
922 if (it == innerModuleInfos_.end()) {
923 TAG_LOGE(AAFwkTag::ABILITY_SIM, "not find module %{public}s", modulePackage.c_str());
924 return std::nullopt;
925 }
926 HapModuleInfo hapInfo;
927 hapInfo.name = it->second.name;
928 hapInfo.package = it->second.modulePackage;
929 hapInfo.moduleName = it->second.moduleName;
930 hapInfo.description = it->second.description;
931 hapInfo.descriptionId = it->second.descriptionId;
932 hapInfo.label = it->second.label;
933 hapInfo.labelId = it->second.labelId;
934 hapInfo.iconPath = it->second.icon;
935 hapInfo.iconId = it->second.iconId;
936 hapInfo.mainAbility = it->second.mainAbility;
937 hapInfo.srcPath = it->second.srcPath;
938 hapInfo.hapPath = it->second.hapPath;
939 hapInfo.supportedModes = baseApplicationInfo_->supportedModes;
940 hapInfo.reqCapabilities = it->second.reqCapabilities;
941 hapInfo.colorMode = it->second.colorMode;
942 hapInfo.isRemovable = it->second.isRemovable;
943 hapInfo.upgradeFlag = it->second.upgradeFlag;
944 hapInfo.isLibIsolated = it->second.isLibIsolated;
945 hapInfo.nativeLibraryPath = it->second.nativeLibraryPath;
946 hapInfo.cpuAbi = it->second.cpuAbi;
947
948 hapInfo.bundleName = baseApplicationInfo_->bundleName;
949 hapInfo.mainElementName = it->second.mainAbility;
950 hapInfo.pages = it->second.pages;
951 hapInfo.process = it->second.process;
952 hapInfo.resourcePath = it->second.moduleResPath;
953 hapInfo.srcEntrance = it->second.srcEntrance;
954 hapInfo.uiSyntax = it->second.uiSyntax;
955 hapInfo.virtualMachine = it->second.virtualMachine;
956 hapInfo.deliveryWithInstall = it->second.distro.deliveryWithInstall;
957 hapInfo.installationFree = it->second.distro.installationFree;
958 hapInfo.isModuleJson = it->second.isModuleJson;
959 hapInfo.isStageBasedModel = it->second.isStageBasedModel;
960 std::string moduleType = it->second.distro.moduleType;
961 if (moduleType == Profile::MODULE_TYPE_ENTRY) {
962 hapInfo.moduleType = ModuleType::ENTRY;
963 } else if (moduleType == Profile::MODULE_TYPE_FEATURE) {
964 hapInfo.moduleType = ModuleType::FEATURE;
965 } else if (moduleType == Profile::MODULE_TYPE_SHARED) {
966 hapInfo.moduleType = ModuleType::SHARED;
967 } else {
968 hapInfo.moduleType = ModuleType::UNKNOWN;
969 }
970 std::string key;
971 key.append(".").append(modulePackage).append(".");
972 for (const auto &extension : baseExtensionInfos_) {
973 if (extension.first.find(key) != std::string::npos) {
974 hapInfo.extensionInfos.emplace_back(extension.second);
975 }
976 }
977 hapInfo.metadata = it->second.metadata;
978 bool first = false;
979 for (auto &ability : baseAbilityInfos_) {
980 if (ability.second.name == Constants::APP_DETAIL_ABILITY) {
981 continue;
982 }
983 if (ability.first.find(key) != std::string::npos) {
984 if (!first) {
985 hapInfo.deviceTypes = ability.second.deviceTypes;
986 first = true;
987 }
988 auto &abilityInfo = hapInfo.abilityInfos.emplace_back(ability.second);
989 GetApplicationInfo(ApplicationFlag::GET_APPLICATION_INFO_WITH_PERMISSION |
990 ApplicationFlag::GET_APPLICATION_INFO_WITH_CERTIFICATE_FINGERPRINT, userId,
991 abilityInfo.applicationInfo);
992 }
993 }
994 hapInfo.dependencies = it->second.dependencies;
995 hapInfo.compileMode = ConvertCompileMode(it->second.compileMode);
996 hapInfo.atomicServiceModuleType = it->second.atomicServiceModuleType;
997 for (const auto &item : it->second.preloads) {
998 PreloadItem preload(item);
999 hapInfo.preloads.emplace_back(preload);
1000 }
1001 for (const auto &item : it->second.proxyDatas) {
1002 ProxyData proxyData(item);
1003 hapInfo.proxyDatas.emplace_back(proxyData);
1004 }
1005 hapInfo.buildHash = it->second.buildHash;
1006 hapInfo.isolationMode = GetIsolationMode(it->second.isolationMode);
1007 hapInfo.compressNativeLibs = it->second.compressNativeLibs;
1008 hapInfo.nativeLibraryFileNames = it->second.nativeLibraryFileNames;
1009 hapInfo.aotCompileStatus = it->second.aotCompileStatus;
1010 return hapInfo;
1011 }
1012
FindAbilityInfo(const std::string & moduleName,const std::string & abilityName,int32_t userId) const1013 std::optional<AbilityInfo> InnerBundleInfo::FindAbilityInfo(
1014 const std::string &moduleName,
1015 const std::string &abilityName,
1016 int32_t userId) const
1017 {
1018 for (const auto &ability : baseAbilityInfos_) {
1019 auto abilityInfo = ability.second;
1020 if ((abilityInfo.name == abilityName) &&
1021 (moduleName.empty() || (abilityInfo.moduleName == moduleName))) {
1022 GetApplicationInfo(ApplicationFlag::GET_APPLICATION_INFO_WITH_PERMISSION |
1023 ApplicationFlag::GET_APPLICATION_INFO_WITH_CERTIFICATE_FINGERPRINT, userId,
1024 abilityInfo.applicationInfo);
1025 return abilityInfo;
1026 }
1027 }
1028
1029 return std::nullopt;
1030 }
1031
FindAbilityInfo(const std::string & moduleName,const std::string & abilityName,AbilityInfo & info) const1032 ErrCode InnerBundleInfo::FindAbilityInfo(
1033 const std::string &moduleName, const std::string &abilityName, AbilityInfo &info) const
1034 {
1035 bool isModuleFind = false;
1036 for (const auto &ability : baseAbilityInfos_) {
1037 auto abilityInfo = ability.second;
1038 if ((abilityInfo.moduleName == moduleName)) {
1039 isModuleFind = true;
1040 if (abilityInfo.name == abilityName) {
1041 info = abilityInfo;
1042 return ERR_OK;
1043 }
1044 }
1045 }
1046 TAG_LOGE(AAFwkTag::ABILITY_SIM,
1047 "bundleName:%{public}s not find moduleName:%{public}s, abilityName:%{public}s, isModuleFind:%{public}d",
1048 GetBundleName().c_str(), moduleName.c_str(), abilityName.c_str(), isModuleFind);
1049 if (isModuleFind) {
1050 return ERR_BUNDLE_MANAGER_ABILITY_NOT_EXIST;
1051 } else {
1052 return ERR_BUNDLE_MANAGER_MODULE_NOT_EXIST;
1053 }
1054 }
1055
ToString() const1056 std::string InnerBundleInfo::ToString() const
1057 {
1058 nlohmann::json j;
1059 ToJson(j);
1060 return j.dump();
1061 }
1062
GetApplicationInfo(int32_t flags,int32_t userId,ApplicationInfo & appInfo) const1063 void InnerBundleInfo::GetApplicationInfo(int32_t flags, int32_t userId, ApplicationInfo &appInfo) const
1064 {
1065 appInfo = *baseApplicationInfo_;
1066
1067 for (const auto &info : innerModuleInfos_) {
1068 bool deCompress = info.second.hapPath.empty();
1069 ModuleInfo moduleInfo;
1070 moduleInfo.moduleName = info.second.moduleName;
1071 if (deCompress) {
1072 moduleInfo.moduleSourceDir = info.second.modulePath;
1073 appInfo.moduleSourceDirs.emplace_back(info.second.modulePath);
1074 }
1075 moduleInfo.preloads = info.second.preloads;
1076 appInfo.moduleInfos.emplace_back(moduleInfo);
1077 if (deCompress && info.second.isEntry) {
1078 appInfo.entryDir = info.second.modulePath;
1079 }
1080 if ((static_cast<uint32_t>(flags) & GET_APPLICATION_INFO_WITH_METADATA) == GET_APPLICATION_INFO_WITH_METADATA) {
1081 bool isModuleJson = info.second.isModuleJson;
1082 if (!isModuleJson && info.second.metaData.customizeData.size() > 0) {
1083 appInfo.metaData[info.second.moduleName] = info.second.metaData.customizeData;
1084 }
1085 if (isModuleJson && info.second.metadata.size() > 0) {
1086 appInfo.metadata[info.second.moduleName] = info.second.metadata;
1087 }
1088 }
1089 if ((static_cast<uint32_t>(flags) & GET_APPLICATION_INFO_WITH_CERTIFICATE_FINGERPRINT) !=
1090 GET_APPLICATION_INFO_WITH_CERTIFICATE_FINGERPRINT) {
1091 appInfo.fingerprint.clear();
1092 }
1093 }
1094 if (!appInfo.permissions.empty()) {
1095 RemoveDuplicateName(appInfo.permissions);
1096 }
1097 }
1098
RemoveDuplicateName(std::vector<std::string> & name) const1099 void InnerBundleInfo::RemoveDuplicateName(std::vector<std::string> &name) const
1100 {
1101 std::sort(name.begin(), name.end());
1102 auto iter = std::unique(name.begin(), name.end());
1103 name.erase(iter, name.end());
1104 }
1105
GetIsolationMode(const std::string & isolationMode) const1106 IsolationMode InnerBundleInfo::GetIsolationMode(const std::string &isolationMode) const
1107 {
1108 auto isolationModeRes = ISOLATION_MODE_MAP.find(isolationMode);
1109 if (isolationModeRes != ISOLATION_MODE_MAP.end()) {
1110 return isolationModeRes->second;
1111 } else {
1112 return IsolationMode::NONISOLATION_FIRST;
1113 }
1114 }
1115
SetBaseBundleInfo(const BundleInfo & bundleInfo)1116 void InnerBundleInfo::SetBaseBundleInfo(const BundleInfo &bundleInfo)
1117 {
1118 *baseBundleInfo_ = bundleInfo;
1119 }
SetApplicationBundleType(BundleType type)1120 void InnerBundleInfo::SetApplicationBundleType(BundleType type)
1121 {
1122 baseApplicationInfo_->bundleType = type;
1123 }
SetInnerModuleAtomicPreload(const std::string & moduleName,const std::vector<std::string> & preloads)1124 bool InnerBundleInfo::SetInnerModuleAtomicPreload(
1125 const std::string &moduleName, const std::vector<std::string> &preloads)
1126 {
1127 if (innerModuleInfos_.find(moduleName) == innerModuleInfos_.end()) {
1128 TAG_LOGE(AAFwkTag::ABILITY_SIM, "innerBundleInfo does not contain the module");
1129 return false;
1130 }
1131 innerModuleInfos_.at(moduleName).preloads = preloads;
1132 return true;
1133 }
1134
GetApplicationInfoV9(int32_t flags,int32_t userId,ApplicationInfo & appInfo) const1135 ErrCode InnerBundleInfo::GetApplicationInfoV9(int32_t flags, int32_t userId, ApplicationInfo &appInfo) const
1136 {
1137 appInfo = *baseApplicationInfo_;
1138 for (const auto &info : innerModuleInfos_) {
1139 bool deCompress = info.second.hapPath.empty();
1140 ModuleInfo moduleInfo;
1141 moduleInfo.moduleName = info.second.moduleName;
1142 if (deCompress) {
1143 moduleInfo.moduleSourceDir = info.second.modulePath;
1144 appInfo.moduleSourceDirs.emplace_back(info.second.modulePath);
1145 }
1146 moduleInfo.preloads = info.second.preloads;
1147 appInfo.moduleInfos.emplace_back(moduleInfo);
1148 if (deCompress && info.second.isEntry) {
1149 appInfo.entryDir = info.second.modulePath;
1150 }
1151 if ((static_cast<uint32_t>(flags) &
1152 static_cast<uint32_t>(GetApplicationFlag::GET_APPLICATION_INFO_WITH_METADATA)) ==
1153 static_cast<uint32_t>(GetApplicationFlag::GET_APPLICATION_INFO_WITH_METADATA)) {
1154 bool isModuleJson = info.second.isModuleJson;
1155 if (!isModuleJson && info.second.metaData.customizeData.size() > 0) {
1156 appInfo.metaData[info.second.moduleName] = info.second.metaData.customizeData;
1157 }
1158 if (isModuleJson && info.second.metadata.size() > 0) {
1159 appInfo.metadata[info.second.moduleName] = info.second.metadata;
1160 }
1161 }
1162 }
1163 if (!appInfo.permissions.empty()) {
1164 RemoveDuplicateName(appInfo.permissions);
1165 }
1166 return ERR_OK;
1167 }
1168
ProcessBundleWithHapModuleInfoFlag(int32_t flags,BundleInfo & bundleInfo,int32_t userId,int32_t appIndex) const1169 void InnerBundleInfo::ProcessBundleWithHapModuleInfoFlag(
1170 int32_t flags, BundleInfo &bundleInfo, int32_t userId, int32_t appIndex) const
1171 {
1172 if ((static_cast<uint32_t>(flags) & static_cast<uint32_t>(GetBundleInfoFlag::GET_BUNDLE_INFO_WITH_HAP_MODULE)) !=
1173 static_cast<uint32_t>(GetBundleInfoFlag::GET_BUNDLE_INFO_WITH_HAP_MODULE)) {
1174 bundleInfo.hapModuleInfos.clear();
1175 return;
1176 }
1177 for (const auto &info : innerModuleInfos_) {
1178 auto hapmoduleinfo = FindHapModuleInfo(info.second.modulePackage, userId);
1179 if (hapmoduleinfo) {
1180 HapModuleInfo hapModuleInfo = *hapmoduleinfo;
1181 auto it = innerModuleInfos_.find(info.second.modulePackage);
1182 if (it == innerModuleInfos_.end()) {
1183 TAG_LOGE(AAFwkTag::ABILITY_SIM, "not find module %{public}s", info.second.modulePackage.c_str());
1184 } else {
1185 hapModuleInfo.hashValue = it->second.hashValue;
1186 }
1187 if (hapModuleInfo.hapPath.empty()) {
1188 hapModuleInfo.moduleSourceDir = info.second.modulePath;
1189 }
1190 if ((static_cast<uint32_t>(flags) &
1191 static_cast<uint32_t>(GetBundleInfoFlag::GET_BUNDLE_INFO_WITH_METADATA)) !=
1192 static_cast<uint32_t>(GetBundleInfoFlag::GET_BUNDLE_INFO_WITH_METADATA)) {
1193 hapModuleInfo.metadata.clear();
1194 }
1195 bundleInfo.hapModuleInfos.emplace_back(hapModuleInfo);
1196 }
1197 }
1198 }
1199
ProcessBundleFlags(int32_t flags,int32_t userId,BundleInfo & bundleInfo,int32_t appIndex) const1200 void InnerBundleInfo::ProcessBundleFlags(int32_t flags, int32_t userId, BundleInfo &bundleInfo, int32_t appIndex) const
1201 {
1202 if ((static_cast<uint32_t>(flags) & static_cast<uint32_t>(GetBundleInfoFlag::GET_BUNDLE_INFO_WITH_APPLICATION)) ==
1203 static_cast<uint32_t>(GetBundleInfoFlag::GET_BUNDLE_INFO_WITH_APPLICATION)) {
1204 if ((static_cast<uint32_t>(flags) & static_cast<uint32_t>(GetBundleInfoFlag::GET_BUNDLE_INFO_WITH_METADATA)) ==
1205 static_cast<uint32_t>(GetBundleInfoFlag::GET_BUNDLE_INFO_WITH_METADATA)) {
1206 GetApplicationInfoV9(static_cast<int32_t>(GetApplicationFlag::GET_APPLICATION_INFO_WITH_METADATA), userId,
1207 bundleInfo.applicationInfo);
1208 } else {
1209 GetApplicationInfoV9(static_cast<int32_t>(GetApplicationFlag::GET_APPLICATION_INFO_DEFAULT), userId,
1210 bundleInfo.applicationInfo);
1211 }
1212 }
1213 bundleInfo.applicationInfo.appIndex = appIndex;
1214 ProcessBundleWithHapModuleInfoFlag(flags, bundleInfo, userId, appIndex);
1215 if ((static_cast<uint32_t>(flags) &
1216 static_cast<uint32_t>(GetBundleInfoFlag::GET_BUNDLE_INFO_WITH_SIGNATURE_INFO)) ==
1217 static_cast<uint32_t>(GetBundleInfoFlag::GET_BUNDLE_INFO_WITH_SIGNATURE_INFO)) {
1218 bundleInfo.signatureInfo.appId = baseBundleInfo_->appId;
1219 bundleInfo.signatureInfo.fingerprint = baseApplicationInfo_->fingerprint;
1220 bundleInfo.signatureInfo.certificate = baseBundleInfo_->signatureInfo.certificate;
1221 }
1222 }
1223
GetBundleInfoV9(int32_t flags,BundleInfo & bundleInfo,int32_t userId,int32_t appIndex) const1224 ErrCode InnerBundleInfo::GetBundleInfoV9(int32_t flags, BundleInfo &bundleInfo, int32_t userId, int32_t appIndex) const
1225 {
1226 bundleInfo = *baseBundleInfo_;
1227 bundleInfo.overlayType = overlayType_;
1228 bundleInfo.isNewVersion = isNewVersion_;
1229 for (const auto &info : innerModuleInfos_) {
1230 bundleInfo.hapModuleNames.emplace_back(info.second.modulePackage);
1231 bundleInfo.moduleNames.emplace_back(info.second.moduleName);
1232 bundleInfo.moduleDirs.emplace_back(info.second.modulePath);
1233 bundleInfo.modulePublicDirs.emplace_back(info.second.moduleDataDir);
1234 bundleInfo.moduleResPaths.emplace_back(info.second.moduleResPath);
1235 }
1236 ProcessBundleFlags(flags, userId, bundleInfo, appIndex);
1237 return ERR_OK;
1238 }
1239
GetAppServiceHspInfo(BundleInfo & bundleInfo) const1240 ErrCode InnerBundleInfo::GetAppServiceHspInfo(BundleInfo &bundleInfo) const
1241 {
1242 if (baseApplicationInfo_->bundleType != BundleType::APP_SERVICE_FWK) {
1243 TAG_LOGE(AAFwkTag::ABILITY_SIM, "%{public}s is not app service", GetBundleName().c_str());
1244 return ERR_BUNDLE_MANAGER_BUNDLE_NOT_EXIST;
1245 }
1246 bundleInfo = *baseBundleInfo_;
1247 bundleInfo.applicationInfo = *baseApplicationInfo_;
1248 for (const auto &info : innerModuleInfos_) {
1249 if (info.second.distro.moduleType == Profile::MODULE_TYPE_SHARED) {
1250 auto hapmoduleinfo = FindHapModuleInfo(info.second.modulePackage, Constants::ALL_USERID);
1251 if (hapmoduleinfo) {
1252 HapModuleInfo hapModuleInfo = *hapmoduleinfo;
1253 hapModuleInfo.moduleSourceDir =
1254 hapModuleInfo.hapPath.empty() ? info.second.modulePath : hapModuleInfo.moduleSourceDir;
1255 bundleInfo.hapModuleInfos.emplace_back(hapModuleInfo);
1256 }
1257 }
1258 }
1259 if (bundleInfo.hapModuleInfos.empty()) {
1260 TAG_LOGE(AAFwkTag::ABILITY_SIM, "bundleName:%{public}s no hsp module info",
1261 baseApplicationInfo_->bundleName.c_str());
1262 return ERR_BUNDLE_MANAGER_MODULE_NOT_EXIST;
1263 }
1264 return ERR_OK;
1265 }
1266
GetSharedBundleInfo(int32_t flags,BundleInfo & bundleInfo) const1267 bool InnerBundleInfo::GetSharedBundleInfo(int32_t flags, BundleInfo &bundleInfo) const
1268 {
1269 bundleInfo = *baseBundleInfo_;
1270 ProcessBundleWithHapModuleInfoFlag(flags, bundleInfo, Constants::ALL_USERID);
1271 bundleInfo.applicationInfo = *baseApplicationInfo_;
1272 return true;
1273 }
1274 } // namespace AppExecFwk
1275 } // namespace OHOS
1276