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 #ifndef FOUNDATION_APPEXECFWK_SERVICES_BUNDLEMGR_INCLUDE_INNER_BUNDLE_INFO_H 17 #define FOUNDATION_APPEXECFWK_SERVICES_BUNDLEMGR_INCLUDE_INNER_BUNDLE_INFO_H 18 19 #include "nocopyable.h" 20 21 #include "ability_info.h" 22 #include "bundle_constants.h" 23 #include "bundle_info.h" 24 #include "common_event_info.h" 25 #include "common_profile.h" 26 #include "extension_ability_info.h" 27 #include "form_info.h" 28 #include "hap_module_info.h" 29 #include "inner_bundle_user_info.h" 30 #include "json_util.h" 31 #include "shortcut_info.h" 32 #include "want.h" 33 #include "distributed_bundle_info.h" 34 35 namespace OHOS { 36 namespace AppExecFwk { 37 struct Distro { 38 bool deliveryWithInstall = false; 39 std::string moduleName; 40 std::string moduleType; 41 bool installationFree = false; 42 }; 43 44 struct DefinePermission { 45 std::string name; 46 std::string grantMode = Profile::DEFINEPERMISSION_GRANT_MODE_DEFAULT_VALUE; 47 std::string availableLevel = Profile::DEFINEPERMISSION_AVAILABLE_LEVEL_DEFAULT_VALUE; 48 std::vector<std::string> availableScope; 49 bool provisionEnable = true; 50 bool distributedSceneEnable = false; 51 std::string label; 52 int32_t labelId = 0; 53 std::string description; 54 int32_t descriptionId = 0; 55 }; 56 57 struct InnerModuleInfo { 58 std::string name; 59 std::string modulePackage; 60 std::string moduleName; 61 std::string modulePath; 62 std::string moduleDataDir; 63 std::string moduleResPath; 64 std::string label; 65 int32_t labelId = 0; 66 std::string description; 67 int32_t descriptionId = 0; 68 std::string icon; 69 int32_t iconId = 0; 70 std::string mainAbility; 71 std::string srcPath; 72 bool isEntry = false; 73 bool installationFree = false; 74 MetaData metaData; 75 ModuleColorMode colorMode = ModuleColorMode::AUTO; 76 Distro distro; 77 std::vector<std::string> reqCapabilities; 78 std::vector<DefinePermission> defPermissions; 79 std::vector<std::string> abilityKeys; 80 std::vector<std::string> skillKeys; 81 // new version fields 82 std::string pages; 83 std::string process; 84 std::string srcEntrance; 85 std::string uiSyntax; 86 std::string virtualMachine; 87 bool isModuleJson = false; 88 bool isStageBasedModel = false; 89 std::vector<DefinePermission> definePermissions; 90 std::vector<RequestPermission> requestPermissions; 91 std::vector<std::string> deviceTypes; 92 std::vector<std::string> extensionKeys; 93 std::vector<std::string> extensionSkillKeys; 94 std::vector<Metadata> metadata; 95 }; 96 97 struct SkillUri { 98 std::string scheme; 99 std::string host; 100 std::string port; 101 std::string path; 102 std::string pathStartWith; 103 std::string pathRegex; 104 std::string type; 105 }; 106 107 struct Skill { 108 public: 109 std::vector<std::string> actions; 110 std::vector<std::string> entities; 111 std::vector<SkillUri> uris; 112 bool Match(const OHOS::AAFwk::Want &want) const; 113 bool MatchLauncher(const OHOS::AAFwk::Want &want) const; 114 private: 115 bool MatchAction(const std::string &action) const; 116 bool MatchEntities(const std::vector<std::string> ¶mEntities) const; 117 bool MatchUriAndType(const std::string &uriString, const std::string &type) const; 118 bool MatchUri(const std::string &uriString, const SkillUri &skillUri) const; 119 bool MatchType(const std::string &type, const std::string &skillUriType) const; 120 }; 121 122 enum InstallExceptionStatus : int32_t { 123 INSTALL_START = 1, 124 INSTALL_FINISH, 125 UPDATING_EXISTED_START, 126 UPDATING_NEW_START, 127 UPDATING_FINISH, 128 UNINSTALL_BUNDLE_START, 129 UNINSTALL_PACKAGE_START, 130 UNKNOWN_STATUS, 131 }; 132 133 struct InstallMark { 134 std::string bundleName; 135 std::string packageName; 136 int32_t status = InstallExceptionStatus::UNKNOWN_STATUS; 137 }; 138 139 class InnerBundleInfo { 140 public: 141 enum class BundleStatus { 142 ENABLED = 1, 143 DISABLED, 144 }; 145 146 InnerBundleInfo(); 147 ~InnerBundleInfo(); 148 /** 149 * @brief Transform the InnerBundleInfo object to json. 150 * @param jsonObject Indicates the obtained json object. 151 * @return 152 */ 153 void ToJson(nlohmann::json &jsonObject) const; 154 /** 155 * @brief Transform the json object to InnerBundleInfo object. 156 * @param jsonObject Indicates the obtained json object. 157 * @return Returns 0 if the json object parsed successfully; returns error code otherwise. 158 */ 159 int32_t FromJson(const nlohmann::json &jsonObject); 160 /** 161 * @brief Add module info to old InnerBundleInfo object. 162 * @param newInfo Indicates the new InnerBundleInfo object. 163 * @return Returns true if the module successfully added; returns false otherwise. 164 */ 165 bool AddModuleInfo(const InnerBundleInfo &newInfo); 166 /** 167 * @brief Update module info to old InnerBundleInfo object. 168 * @param newInfo Indicates the new InnerBundleInfo object. 169 * @return 170 */ 171 void UpdateModuleInfo(const InnerBundleInfo &newInfo); 172 /** 173 * @brief Update common hap info to old InnerBundleInfo object. 174 * @param newInfo Indicates the new InnerBundleInfo object. 175 * @return 176 */ 177 void updateCommonHapInfo(const InnerBundleInfo &newInfo); 178 /** 179 * @brief Remove module info from InnerBundleInfo object. 180 * @param modulePackage Indicates the module package to be remove. 181 * @return 182 */ 183 void RemoveModuleInfo(const std::string &modulePackage); 184 /** 185 * @brief Find hap module info by module package. 186 * @param modulePackage Indicates the module package. 187 * @param userId Indicates the user ID. 188 * @return Returns the HapModuleInfo object if find it; returns null otherwise. 189 */ 190 std::optional<HapModuleInfo> FindHapModuleInfo( 191 const std::string &modulePackage, int32_t userId = Constants::UNSPECIFIED_USERID) const; 192 /** 193 * @brief Find abilityInfo by bundle name and ability name. 194 * @param bundleName Indicates the bundle name. 195 * @param abilityName Indicates the ability name 196 * @param userId Indicates the user ID. 197 * @return Returns the AbilityInfo object if find it; returns null otherwise. 198 */ 199 std::optional<AbilityInfo> FindAbilityInfo(const std::string &bundleName, 200 const std::string &abilityName, int32_t userId = Constants::UNSPECIFIED_USERID) const; 201 /** 202 * @brief Find abilityInfo of list by bundle name. 203 * @param bundleName Indicates the bundle name. 204 * @param userId Indicates the user ID. 205 * @return Returns the AbilityInfo of list if find it; returns null otherwise. 206 */ 207 std::optional<std::vector<AbilityInfo>> FindAbilityInfos( 208 const std::string &bundleName, int32_t userId = Constants::UNSPECIFIED_USERID) const; 209 /** 210 * @brief Find extensionInfo by bundle name and extension name. 211 * @param bundleName Indicates the bundle name. 212 * @param extensionName Indicates the extension name 213 * @return Returns the ExtensionAbilityInfo object if find it; returns null otherwise. 214 */ 215 std::optional<ExtensionAbilityInfo> FindExtensionInfo( 216 const std::string &bundleName, const std::string &extensionName) const; 217 /** 218 * @brief Find extensionInfos by bundle name. 219 * @param bundleName Indicates the bundle name. 220 * @return Returns the ExtensionAbilityInfo array if find it; returns null otherwise. 221 */ 222 std::optional<std::vector<ExtensionAbilityInfo>> FindExtensionInfos(const std::string &bundleName) const; 223 /** 224 * @brief Find abilityInfo of list for clone by bundle name and ability name. 225 * @param bundleName Indicates the bundle name. 226 * @param abilityName Indicates the ability name 227 * @param userId Indicates the user ID. 228 * @return Returns the AbilityInfo of list if find it; returns null otherwise. 229 */ 230 void FindAbilityInfosForClone(const std::string &bundleName, 231 const std::string &abilityName, int32_t userId, std::vector<AbilityInfo> &abilitys); 232 /** 233 * @brief Transform the InnerBundleInfo object to string. 234 * @return Returns the string object 235 */ 236 std::string ToString() const; 237 /** 238 * @brief Add ability infos to old InnerBundleInfo object. 239 * @param abilityInfos Indicates the AbilityInfo object to be add. 240 * @return 241 */ AddModuleAbilityInfo(const std::map<std::string,AbilityInfo> & abilityInfos)242 void AddModuleAbilityInfo(const std::map<std::string, AbilityInfo> &abilityInfos) 243 { 244 for (const auto &ability : abilityInfos) { 245 baseAbilityInfos_.try_emplace(ability.first, ability.second); 246 } 247 } 248 AddModuleExtensionInfos(const std::map<std::string,ExtensionAbilityInfo> & extensionInfos)249 void AddModuleExtensionInfos(const std::map<std::string, ExtensionAbilityInfo> &extensionInfos) 250 { 251 for (const auto &extensionInfo : extensionInfos) { 252 baseExtensionInfos_.try_emplace(extensionInfo.first, extensionInfo.second); 253 } 254 } 255 /** 256 * @brief Add skill infos to old InnerBundleInfo object. 257 * @param skillInfos Indicates the Skill object to be add. 258 * @return 259 */ AddModuleSkillInfo(const std::map<std::string,std::vector<Skill>> & skillInfos)260 void AddModuleSkillInfo(const std::map<std::string, std::vector<Skill>> &skillInfos) 261 { 262 for (const auto &skills : skillInfos) { 263 skillInfos_.try_emplace(skills.first, skills.second); 264 } 265 } AddModuleExtensionSkillInfos(const std::map<std::string,std::vector<Skill>> & extensionSkillInfos)266 void AddModuleExtensionSkillInfos(const std::map<std::string, std::vector<Skill>> &extensionSkillInfos) 267 { 268 for (const auto &skills : extensionSkillInfos) { 269 extensionSkillInfos_.try_emplace(skills.first, skills.second); 270 } 271 } 272 /** 273 * @brief Add form infos to old InnerBundleInfo object. 274 * @param formInfos Indicates the Forms object to be add. 275 * @return 276 */ AddModuleFormInfo(const std::map<std::string,std::vector<FormInfo>> & formInfos)277 void AddModuleFormInfo(const std::map<std::string, std::vector<FormInfo>> &formInfos) 278 { 279 for (const auto &forms : formInfos) { 280 formInfos_.try_emplace(forms.first, forms.second); 281 } 282 } 283 /** 284 * @brief Add common events to old InnerBundleInfo object. 285 * @param commonEvents Indicates the Common Event object to be add. 286 * @return 287 */ AddModuleCommonEvent(const std::map<std::string,CommonEventInfo> & commonEvents)288 void AddModuleCommonEvent(const std::map<std::string, CommonEventInfo> &commonEvents) 289 { 290 for (const auto &commonEvent : commonEvents) { 291 commonEvents_.try_emplace(commonEvent.first, commonEvent.second); 292 } 293 } 294 /** 295 * @brief Add shortcut infos to old InnerBundleInfo object. 296 * @param shortcutInfos Indicates the Shortcut object to be add. 297 * @return 298 */ AddModuleShortcutInfo(const std::map<std::string,ShortcutInfo> & shortcutInfos)299 void AddModuleShortcutInfo(const std::map<std::string, ShortcutInfo> &shortcutInfos) 300 { 301 for (const auto &shortcut : shortcutInfos) { 302 shortcutInfos_.try_emplace(shortcut.first, shortcut.second); 303 } 304 } 305 /** 306 * @brief Add innerModuleInfos to old InnerBundleInfo object. 307 * @param innerModuleInfos Indicates the InnerModuleInfo object to be add. 308 * @return 309 */ AddInnerModuleInfo(const std::map<std::string,InnerModuleInfo> & innerModuleInfos)310 void AddInnerModuleInfo(const std::map<std::string, InnerModuleInfo> &innerModuleInfos) 311 { 312 for (const auto &info : innerModuleInfos) { 313 innerModuleInfos_.try_emplace(info.first, info.second); 314 } 315 } 316 /** 317 * @brief Get application name. 318 * @return Return application name 319 */ GetApplicationName()320 std::string GetApplicationName() const 321 { 322 return baseApplicationInfo_.name; 323 } 324 /** 325 * @brief Set bundle status. 326 * @param status Indicates the BundleStatus object to set. 327 * @return 328 */ SetBundleStatus(const BundleStatus & status)329 void SetBundleStatus(const BundleStatus &status) 330 { 331 bundleStatus_ = status; 332 } 333 /** 334 * @brief Get bundle status. 335 * @return Return the BundleStatus object 336 */ GetBundleStatus()337 BundleStatus GetBundleStatus() const 338 { 339 return bundleStatus_; 340 } 341 /** 342 * @brief Set bundle install time. 343 * @param time Indicates the install time to set. 344 * @param userId Indicates the user ID. 345 * @return 346 */ 347 void SetBundleInstallTime( 348 const int64_t time, int32_t userId = Constants::UNSPECIFIED_USERID); 349 /** 350 * @brief Get bundle install time. 351 * @param userId Indicates the user ID. 352 * @return Return the bundle install time. 353 */ 354 int64_t GetBundleInstallTime(int32_t userId = Constants::UNSPECIFIED_USERID) const 355 { 356 InnerBundleUserInfo innerBundleUserInfo; 357 if (!GetInnerBundleUserInfo(userId, innerBundleUserInfo)) { 358 APP_LOGE("can not find userId %{public}d when GetBundleInstallTime", userId); 359 return -1; 360 } 361 return innerBundleUserInfo.installTime; 362 } 363 /** 364 * @brief Set bundle update time. 365 * @param time Indicates the update time to set. 366 * @param userId Indicates the user ID. 367 * @return 368 */ 369 void SetBundleUpdateTime(const int64_t time, int32_t userId = Constants::UNSPECIFIED_USERID); 370 /** 371 * @brief Get bundle update time. 372 * @param userId Indicates the user ID. 373 * @return Return the bundle update time. 374 */ 375 int64_t GetBundleUpdateTime(int32_t userId = Constants::UNSPECIFIED_USERID) const 376 { 377 InnerBundleUserInfo innerBundleUserInfo; 378 if (!GetInnerBundleUserInfo(userId, innerBundleUserInfo)) { 379 APP_LOGE("can not find userId %{public}d when GetBundleUpdateTime", userId); 380 return -1; 381 } 382 return innerBundleUserInfo.updateTime; 383 } 384 /** 385 * @brief Set whether the application supports backup. 386 * @param isSupportBackup Indicates the supports status to set. 387 */ SetIsSupportBackup(bool isSupportBackup)388 void SetIsSupportBackup(bool isSupportBackup) 389 { 390 isSupportBackup_ = isSupportBackup; 391 } 392 /** 393 * @brief Get whether the application supports backup. 394 * @return Return the supports status. 395 */ GetIsSupportBackup()396 bool GetIsSupportBackup() const 397 { 398 return isSupportBackup_; 399 } 400 /** 401 * @brief Get bundle name. 402 * @return Return bundle name 403 */ GetBundleName()404 const std::string GetBundleName() const 405 { 406 return baseApplicationInfo_.bundleName; 407 } 408 /** 409 * @brief Get baseBundleInfo. 410 * @return Return the BundleInfo object. 411 */ GetBaseBundleInfo()412 BundleInfo GetBaseBundleInfo() const 413 { 414 return baseBundleInfo_; 415 } 416 /** 417 * @brief Set baseBundleInfo. 418 * @param bundleInfo Indicates the BundleInfo object. 419 */ SetBaseBundleInfo(const BundleInfo & bundleInfo)420 void SetBaseBundleInfo(const BundleInfo &bundleInfo) 421 { 422 baseBundleInfo_ = bundleInfo; 423 } 424 /** 425 * @brief Update baseBundleInfo. 426 * @param bundleInfo Indicates the new BundleInfo object. 427 * @return 428 */ 429 void UpdateBaseBundleInfo(const BundleInfo &bundleInfo, bool isEntry); 430 /** 431 * @brief Get baseApplicationInfo. 432 * @return Return the ApplicationInfo object. 433 */ GetBaseApplicationInfo()434 ApplicationInfo GetBaseApplicationInfo() const 435 { 436 return baseApplicationInfo_; 437 } 438 /** 439 * @brief Set baseApplicationInfo. 440 * @param applicationInfo Indicates the ApplicationInfo object. 441 */ SetBaseApplicationInfo(const ApplicationInfo & applicationInfo)442 void SetBaseApplicationInfo(const ApplicationInfo &applicationInfo) 443 { 444 baseApplicationInfo_ = applicationInfo; 445 } 446 /** 447 * @brief Update baseApplicationInfo. 448 * @param applicationInfo Indicates the ApplicationInfo object. 449 */ 450 void UpdateBaseApplicationInfo(const ApplicationInfo &applicationInfo); 451 /** 452 * @brief Get application enabled. 453 * @param userId Indicates the user ID. 454 * @return Return whether the application is enabled. 455 */ 456 bool GetApplicationEnabled(int32_t userId = Constants::UNSPECIFIED_USERID) const 457 { 458 InnerBundleUserInfo innerBundleUserInfo; 459 if (!GetInnerBundleUserInfo(userId, innerBundleUserInfo)) { 460 APP_LOGE("can not find userId %{public}d when GetApplicationEnabled", userId); 461 return false; 462 } 463 464 return innerBundleUserInfo.bundleUserInfo.enabled; 465 } 466 /** 467 * @brief Set application enabled. 468 * @param userId Indicates the user ID. 469 * @return Return whether the application is enabled. 470 */ 471 void SetApplicationEnabled(bool enabled, int32_t userId = Constants::UNSPECIFIED_USERID); 472 /** 473 * @brief Get application code path. 474 * @return Return the string object. 475 */ GetAppCodePath()476 const std::string GetAppCodePath() const 477 { 478 return baseApplicationInfo_.codePath; 479 } 480 /** 481 * @brief Set application code path. 482 * @param codePath Indicates the code path to be set. 483 */ SetAppCodePath(const std::string codePath)484 void SetAppCodePath(const std::string codePath) 485 { 486 baseApplicationInfo_.codePath = codePath; 487 } 488 /** 489 * @brief Insert innerModuleInfos. 490 * @param modulePackage Indicates the modulePackage object as key. 491 * @param innerModuleInfo Indicates the InnerModuleInfo object as value. 492 */ InsertInnerModuleInfo(const std::string & modulePackage,const InnerModuleInfo & innerModuleInfo)493 void InsertInnerModuleInfo(const std::string &modulePackage, const InnerModuleInfo &innerModuleInfo) 494 { 495 innerModuleInfos_.try_emplace(modulePackage, innerModuleInfo); 496 } 497 /** 498 * @brief Insert AbilityInfo. 499 * @param key bundleName.moduleName.abilityName 500 * @param abilityInfo value. 501 */ InsertAbilitiesInfo(const std::string & key,const AbilityInfo & abilityInfo)502 void InsertAbilitiesInfo(const std::string &key, const AbilityInfo &abilityInfo) 503 { 504 baseAbilityInfos_.emplace(key, abilityInfo); 505 } 506 /** 507 * @brief Insert ExtensionAbilityInfo. 508 * @param key bundleName.moduleName.extensionName 509 * @param extensionInfo value. 510 */ InsertExtensionInfo(const std::string & key,const ExtensionAbilityInfo & extensionInfo)511 void InsertExtensionInfo(const std::string &key, const ExtensionAbilityInfo &extensionInfo) 512 { 513 baseExtensionInfos_.emplace(key, extensionInfo); 514 } 515 /** 516 * @brief Insert ability skillInfos. 517 * @param key bundleName.moduleName.abilityName 518 * @param skills ability skills. 519 */ InsertSkillInfo(const std::string & key,const std::vector<Skill> & skills)520 void InsertSkillInfo(const std::string &key, const std::vector<Skill> &skills) 521 { 522 skillInfos_.emplace(key, skills); 523 } 524 /** 525 * @brief Insert extension skillInfos. 526 * @param key bundleName.moduleName.extensionName 527 * @param skills extension skills. 528 */ InsertExtensionSkillInfo(const std::string & key,const std::vector<Skill> & skills)529 void InsertExtensionSkillInfo(const std::string &key, const std::vector<Skill> &skills) 530 { 531 extensionSkillInfos_.emplace(key, skills); 532 } 533 /** 534 * @brief Find AbilityInfo object by Uri. 535 * @param abilityUri Indicates the ability uri. 536 * @param userId Indicates the user ID. 537 * @return Returns the AbilityInfo object if find it; returns null otherwise. 538 */ FindAbilityInfoByUri(const std::string & abilityUri)539 std::optional<AbilityInfo> FindAbilityInfoByUri(const std::string &abilityUri) const 540 { 541 APP_LOGI("Uri is %{public}s", abilityUri.c_str()); 542 for (const auto &ability : baseAbilityInfos_) { 543 auto abilityInfo = ability.second; 544 if (abilityInfo.uri.size() < Constants::DATA_ABILITY_URI_PREFIX.size()) { 545 continue; 546 } 547 548 auto configUri = abilityInfo.uri.substr(Constants::DATA_ABILITY_URI_PREFIX.size()); 549 APP_LOGI("configUri is %{public}s", configUri.c_str()); 550 if (configUri == abilityUri) { 551 return abilityInfo; 552 } 553 } 554 return std::nullopt; 555 } 556 FindExtensionAbilityInfoByUri(const std::string & uri,ExtensionAbilityInfo & extensionAbilityInfo)557 bool FindExtensionAbilityInfoByUri(const std::string &uri, ExtensionAbilityInfo &extensionAbilityInfo) const 558 { 559 APP_LOGD("uri : %{public}s", uri.c_str()); 560 for (const auto &item : baseExtensionInfos_) { 561 if (uri == item.second.uri) { 562 extensionAbilityInfo = item.second; 563 APP_LOGD("find target extension, bundleName : %{public}s, moduleName : %{public}s, name : %{public}s", 564 extensionAbilityInfo.bundleName.c_str(), extensionAbilityInfo.moduleName.c_str(), 565 extensionAbilityInfo.name.c_str()); 566 return true; 567 } 568 } 569 return false; 570 } 571 572 /** 573 * @brief Find AbilityInfo object by Uri. 574 * @param abilityUri Indicates the ability uri. 575 * @param userId Indicates the user ID. 576 * @return Returns the AbilityInfo object if find it; returns null otherwise. 577 */ 578 void FindAbilityInfosByUri(const std::string &abilityUri, 579 std::vector<AbilityInfo> &abilityInfos, int32_t userId = Constants::UNSPECIFIED_USERID) 580 { 581 APP_LOGI("Uri is %{public}s", abilityUri.c_str()); 582 for (auto &ability : baseAbilityInfos_) { 583 auto abilityInfo = ability.second; 584 if (abilityInfo.uri.size() < Constants::DATA_ABILITY_URI_PREFIX.size()) { 585 continue; 586 } 587 588 auto configUri = abilityInfo.uri.substr(Constants::DATA_ABILITY_URI_PREFIX.size()); 589 APP_LOGI("configUri is %{public}s", configUri.c_str()); 590 if (configUri == abilityUri) { 591 GetApplicationInfo( 592 ApplicationFlag::GET_APPLICATION_INFO_WITH_PERMISSION, userId, abilityInfo.applicationInfo); 593 abilityInfos.emplace_back(abilityInfo); 594 } 595 } 596 return; 597 } 598 /** 599 * @brief Get all ability names in application. 600 * @return Returns ability names. 601 */ GetAbilityNames()602 auto GetAbilityNames() const 603 { 604 std::vector<std::string> abilityNames; 605 for (auto &ability : baseAbilityInfos_) { 606 abilityNames.emplace_back(ability.second.name); 607 } 608 return abilityNames; 609 } 610 /** 611 * @brief Get version code in application. 612 * @return Returns version code. 613 */ GetVersionCode()614 uint32_t GetVersionCode() const 615 { 616 return baseBundleInfo_.versionCode; 617 } 618 /** 619 * @brief Get version name in application. 620 * @return Returns version name. 621 */ GetVersionName()622 std::string GetVersionName() const 623 { 624 return baseBundleInfo_.versionName; 625 } 626 /** 627 * @brief Get vendor in application. 628 * @return Returns vendor. 629 */ GetVendor()630 std::string GetVendor() const 631 { 632 return baseBundleInfo_.vendor; 633 } 634 /** 635 * @brief Get comparible version in application. 636 * @return Returns comparible version. 637 */ GetCompatibleVersion()638 uint32_t GetCompatibleVersion() const 639 { 640 return baseBundleInfo_.compatibleVersion; 641 } 642 /** 643 * @brief Get target version in application. 644 * @return Returns target version. 645 */ GetTargetVersion()646 uint32_t GetTargetVersion() const 647 { 648 return baseBundleInfo_.targetVersion; 649 } 650 /** 651 * @brief Get release type in application. 652 * @return Returns release type. 653 */ GetReleaseType()654 std::string GetReleaseType() const 655 { 656 return baseBundleInfo_.releaseType; 657 } 658 /** 659 * @brief Get install mark in application. 660 * @return Returns install mark. 661 */ SetInstallMark(const std::string & bundleName,const std::string & packageName,const InstallExceptionStatus & status)662 void SetInstallMark(const std::string &bundleName, const std::string &packageName, 663 const InstallExceptionStatus &status) 664 { 665 mark_.bundleName = bundleName; 666 mark_.packageName = packageName; 667 mark_.status = status; 668 } 669 /** 670 * @brief Get install mark in application. 671 * @return Returns install mark. 672 */ GetInstallMark()673 InstallMark GetInstallMark() const 674 { 675 return mark_; 676 } 677 /** 678 * @brief Set application base data dir. 679 * @param baseDataDir Indicates the dir to be set. 680 */ SetBaseDataDir(const std::string & baseDataDir)681 void SetBaseDataDir(const std::string &baseDataDir) 682 { 683 baseDataDir_ = baseDataDir; 684 } 685 /** 686 * @brief Get application base data dir. 687 * @return Return the string object. 688 */ GetBaseDataDir()689 std::string GetBaseDataDir() const 690 { 691 return baseDataDir_; 692 } 693 /** 694 * @brief Get application data dir. 695 * @return Return the string object. 696 */ GetAppDataDir()697 std::string GetAppDataDir() const 698 { 699 return baseApplicationInfo_.dataDir; 700 } 701 /** 702 * @brief Set application data dir. 703 * @param dataDir Indicates the data Dir to be set. 704 */ SetAppDataDir(std::string dataDir)705 void SetAppDataDir(std::string dataDir) 706 { 707 baseApplicationInfo_.dataDir = dataDir; 708 } 709 /** 710 * @brief Set application data base dir. 711 * @param dataBaseDir Indicates the data base Dir to be set. 712 */ SetAppDataBaseDir(std::string dataBaseDir)713 void SetAppDataBaseDir(std::string dataBaseDir) 714 { 715 baseApplicationInfo_.dataBaseDir = dataBaseDir; 716 } 717 /** 718 * @brief Set application cache dir. 719 * @param cacheDir Indicates the cache Dir to be set. 720 */ SetAppCacheDir(std::string cacheDir)721 void SetAppCacheDir(std::string cacheDir) 722 { 723 baseApplicationInfo_.cacheDir = cacheDir; 724 } 725 /** 726 * @brief Set application uid. 727 * @param uid Indicates the uid to be set. 728 */ SetUid(int uid)729 void SetUid(int uid) {} 730 /** 731 * @brief Get application uid. 732 * @param userId Indicates the user ID. 733 * @return Returns the uid. 734 */ 735 int GetUid(int32_t userId = Constants::UNSPECIFIED_USERID) const 736 { 737 InnerBundleUserInfo innerBundleUserInfo; 738 if (!GetInnerBundleUserInfo(userId, innerBundleUserInfo)) { 739 return Constants::INVALID_UID; 740 } 741 742 return innerBundleUserInfo.uid; 743 } 744 /** 745 * @brief Get application gid. 746 * @param userId Indicates the user ID. 747 * @return Returns the gid. 748 */ 749 int GetGid(int32_t userId = Constants::UNSPECIFIED_USERID) const 750 { 751 InnerBundleUserInfo innerBundleUserInfo; 752 if (!GetInnerBundleUserInfo(userId, innerBundleUserInfo)) { 753 return Constants::INVALID_GID; 754 } 755 756 if (innerBundleUserInfo.gids.empty()) { 757 return Constants::INVALID_GID; 758 } 759 760 return innerBundleUserInfo.gids[0]; 761 } 762 /** 763 * @brief Set application gid. 764 * @param gid Indicates the gid to be set. 765 */ SetGid(int gid)766 void SetGid(int gid) {} 767 /** 768 * @brief Get application AppType. 769 * @return Returns the AppType. 770 */ GetAppType()771 Constants::AppType GetAppType() const 772 { 773 return appType_; 774 } 775 /** 776 * @brief Set application AppType. 777 * @param gid Indicates the AppType to be set. 778 */ SetAppType(Constants::AppType appType)779 void SetAppType(Constants::AppType appType) 780 { 781 appType_ = appType; 782 if (appType_ == Constants::AppType::SYSTEM_APP) { 783 baseApplicationInfo_.isSystemApp = true; 784 } else { 785 baseApplicationInfo_.isSystemApp = false; 786 } 787 } 788 /** 789 * @brief Get application user id. 790 * @return Returns the user id. 791 */ GetUserId()792 int GetUserId() const 793 { 794 return userId_; 795 } 796 /** 797 * @brief Set application user id. 798 * @param gid Indicates the user id to be set. 799 */ SetUserId(int userId)800 void SetUserId(int userId) 801 { 802 userId_ = userId; 803 } 804 805 // only used in install progress with newInfo GetCurrentModulePackage()806 std::string GetCurrentModulePackage() const 807 { 808 return currentPackage_; 809 } SetCurrentModulePackage(const std::string & modulePackage)810 void SetCurrentModulePackage(const std::string &modulePackage) 811 { 812 currentPackage_ = modulePackage; 813 } AddModuleSrcDir(const std::string & moduleSrcDir)814 void AddModuleSrcDir(const std::string &moduleSrcDir) 815 { 816 if (innerModuleInfos_.count(currentPackage_) == 1) { 817 innerModuleInfos_.at(currentPackage_).modulePath = moduleSrcDir; 818 } 819 } AddModuleDataDir(const std::string & moduleDataDir)820 void AddModuleDataDir(const std::string &moduleDataDir) 821 { 822 if (innerModuleInfos_.count(currentPackage_) == 1) { 823 innerModuleInfos_.at(currentPackage_).moduleDataDir = moduleDataDir; 824 } 825 } AddModuleResPath(const std::string & moduleSrcDir)826 void AddModuleResPath(const std::string &moduleSrcDir) 827 { 828 if (innerModuleInfos_.count(currentPackage_) == 1) { 829 std::string moduleResPath; 830 if (isNewVersion_) { 831 moduleResPath = moduleSrcDir + Constants::PATH_SEPARATOR + Constants::RESOURCES_INDEX; 832 } else { 833 moduleResPath = moduleSrcDir + Constants::PATH_SEPARATOR + Constants::ASSETS_DIR + 834 Constants::PATH_SEPARATOR +innerModuleInfos_.at(currentPackage_).distro.moduleName + 835 Constants::PATH_SEPARATOR + Constants::RESOURCES_INDEX; 836 } 837 838 innerModuleInfos_.at(currentPackage_).moduleResPath = moduleResPath; 839 for (auto &abilityInfo : baseAbilityInfos_) { 840 abilityInfo.second.resourcePath = moduleResPath; 841 } 842 for (auto &extensionInfo : baseExtensionInfos_) { 843 extensionInfo.second.resourcePath = moduleResPath; 844 } 845 } 846 } 847 GetDefPermissions()848 std::vector<DefinePermission> GetDefPermissions() const 849 { 850 std::vector<DefinePermission> defPermissions; 851 if (innerModuleInfos_.count(currentPackage_) == 1) { 852 defPermissions = innerModuleInfos_.at(currentPackage_).defPermissions; 853 } 854 return defPermissions; 855 } 856 GetDefinePermissions()857 std::vector<DefinePermission> GetDefinePermissions() const 858 { 859 std::vector<DefinePermission> definePermissions; 860 if (innerModuleInfos_.count(currentPackage_) == 1) { 861 definePermissions = innerModuleInfos_.at(currentPackage_).definePermissions; 862 } 863 return definePermissions; 864 } 865 GetRequestPermissions()866 std::vector<RequestPermission> GetRequestPermissions() const 867 { 868 std::vector<RequestPermission> requestPermissions; 869 if (innerModuleInfos_.count(currentPackage_) == 1) { 870 requestPermissions = innerModuleInfos_.at(currentPackage_).requestPermissions; 871 } 872 return requestPermissions; 873 } 874 875 std::vector<DefinePermission> GetAllDefinePermissions() const; 876 877 std::vector<RequestPermission> GetAllRequestPermissions() const; 878 FindModule(std::string modulePackage)879 bool FindModule(std::string modulePackage) const 880 { 881 return (innerModuleInfos_.find(modulePackage) != innerModuleInfos_.end()); 882 } 883 SetIsKeepData(bool isKeepData)884 void SetIsKeepData(bool isKeepData) 885 { 886 isKeepData_ = isKeepData; 887 } 888 GetIsKeepData()889 bool GetIsKeepData() const 890 { 891 return isKeepData_; 892 } 893 SetIsKeepAlive(bool isKeepAlive)894 void SetIsKeepAlive(bool isKeepAlive) 895 { 896 baseBundleInfo_.isKeepAlive = isKeepAlive; 897 } 898 GetIsKeepAlive()899 bool GetIsKeepAlive() const 900 { 901 return baseBundleInfo_.isKeepAlive; 902 } 903 SetIsNativeApp(bool isNativeApp)904 void SetIsNativeApp(bool isNativeApp) 905 { 906 baseBundleInfo_.isNativeApp = isNativeApp; 907 } 908 GetIsNativeApp()909 bool GetIsNativeApp() const 910 { 911 return baseBundleInfo_.isNativeApp; 912 } 913 SetApplicationInfoUid()914 void SetApplicationInfoUid() 915 { 916 baseApplicationInfo_.uid = uid_; 917 } 918 GetApplicationInfoUid()919 int GetApplicationInfoUid() const 920 { 921 return baseApplicationInfo_.uid; 922 } 923 SetIsCloned(bool isClone)924 void SetIsCloned(bool isClone) 925 { 926 baseApplicationInfo_.isCloned = isClone; 927 } 928 GetisCloned()929 bool GetisCloned() const 930 { 931 return baseApplicationInfo_.isCloned; 932 } 933 SetNewBundleName(std::string bundlename)934 void SetNewBundleName(std::string bundlename) 935 { 936 std::string strUid = std::to_string(uid_); 937 newBundleName_ = bundlename + '#' + strUid; 938 APP_LOGI("set clone newBundleName_ %{public}s", newBundleName_.c_str()); 939 } 940 GetDBKeyBundleName()941 std::string GetDBKeyBundleName() const 942 { 943 if (!baseApplicationInfo_.isCloned) { 944 return baseApplicationInfo_.bundleName; 945 } 946 return newBundleName_; 947 } 948 SetIsLauncherApp(bool isLauncher)949 void SetIsLauncherApp(bool isLauncher) 950 { 951 baseApplicationInfo_.isLauncherApp = isLauncher; 952 } 953 GetIsLauncherApp()954 bool GetIsLauncherApp() const 955 { 956 return baseApplicationInfo_.isLauncherApp; 957 } 958 SetMainAbility(const std::string & mainAbility)959 void SetMainAbility(const std::string &mainAbility) 960 { 961 mainAbility_ = mainAbility; 962 } 963 GetMainAbility()964 std::string GetMainAbility() const 965 { 966 return mainAbility_; 967 } 968 SetMainAbilityName(const std::string & mainAbilityName)969 void SetMainAbilityName(const std::string &mainAbilityName) 970 { 971 mainAbilityName_ = mainAbilityName; 972 } 973 GetMainAbilityName()974 std::string GetMainAbilityName() const 975 { 976 return mainAbilityName_; 977 } 978 GetMainAbilityInfo(AbilityInfo & abilityInfo)979 void GetMainAbilityInfo(AbilityInfo &abilityInfo) const 980 { 981 if (!mainAbility_.empty()) { 982 abilityInfo = baseAbilityInfos_.at(mainAbility_); 983 } 984 } 985 GetModuleDir(std::string modulePackage)986 std::string GetModuleDir(std::string modulePackage) const 987 { 988 if (innerModuleInfos_.find(modulePackage) != innerModuleInfos_.end()) { 989 return innerModuleInfos_.at(modulePackage).modulePath; 990 } 991 return Constants::EMPTY_STRING; 992 } 993 GetModuleDataDir(std::string modulePackage)994 std::string GetModuleDataDir(std::string modulePackage) const 995 { 996 if (innerModuleInfos_.find(modulePackage) != innerModuleInfos_.end()) { 997 return innerModuleInfos_.at(modulePackage).moduleDataDir; 998 } 999 return Constants::EMPTY_STRING; 1000 } 1001 IsDisabled()1002 bool IsDisabled() const 1003 { 1004 return (bundleStatus_ == BundleStatus::DISABLED); 1005 } 1006 IsEnabled()1007 bool IsEnabled() const 1008 { 1009 return (bundleStatus_ == BundleStatus::ENABLED); 1010 } 1011 IsOnlyModule(const std::string & modulePackage)1012 bool IsOnlyModule(const std::string &modulePackage) 1013 { 1014 if ((innerModuleInfos_.size() == 1) && (innerModuleInfos_.count(modulePackage) == 1)) { 1015 return true; 1016 } 1017 return false; 1018 } 1019 SetProvisionId(const std::string & provisionId)1020 void SetProvisionId(const std::string &provisionId) 1021 { 1022 baseBundleInfo_.appId = baseBundleInfo_.name + Constants::FILE_UNDERLINE + provisionId; 1023 } 1024 GetProvisionId()1025 std::string GetProvisionId() const 1026 { 1027 if (!baseBundleInfo_.appId.empty()) { 1028 return baseBundleInfo_.appId.substr(baseBundleInfo_.name.size() + 1); 1029 } 1030 return ""; 1031 } 1032 SetAppFeature(const std::string & appFeature)1033 void SetAppFeature(const std::string &appFeature) 1034 { 1035 appFeature_ = appFeature; 1036 } 1037 GetAppFeature()1038 std::string GetAppFeature() const 1039 { 1040 return appFeature_; 1041 } 1042 SetAppPrivilegeLevel(const std::string & appPrivilegeLevel)1043 void SetAppPrivilegeLevel(const std::string &appPrivilegeLevel) 1044 { 1045 if (appPrivilegeLevel.empty()) { 1046 return; 1047 } 1048 baseApplicationInfo_.appPrivilegeLevel = appPrivilegeLevel; 1049 } 1050 GetAppPrivilegeLevel()1051 std::string GetAppPrivilegeLevel() const 1052 { 1053 return baseApplicationInfo_.appPrivilegeLevel; 1054 } 1055 SetHasEntry(bool hasEntry)1056 void SetHasEntry(bool hasEntry) 1057 { 1058 hasEntry_ = hasEntry; 1059 } 1060 HasEntry()1061 bool HasEntry() const 1062 { 1063 return hasEntry_; 1064 } 1065 1066 /** 1067 * @brief Insert formInfo. 1068 * @param keyName Indicates object as key. 1069 * @param formInfos Indicates the formInfo object as value. 1070 */ InsertFormInfos(const std::string & keyName,const std::vector<FormInfo> & formInfos)1071 void InsertFormInfos(const std::string &keyName, const std::vector<FormInfo> &formInfos) 1072 { 1073 formInfos_.emplace(keyName, formInfos); 1074 } 1075 /** 1076 * @brief Insert commonEvent. 1077 * @param keyName Indicates object as key. 1078 * @param commonEvents Indicates the common event object as value. 1079 */ InsertCommonEvents(const std::string & keyName,const CommonEventInfo & commonEvents)1080 void InsertCommonEvents(const std::string &keyName, const CommonEventInfo &commonEvents) 1081 { 1082 commonEvents_.emplace(keyName, commonEvents); 1083 } 1084 /** 1085 * @brief Insert shortcutInfos. 1086 * @param keyName Indicates object as key. 1087 * @param shortcutInfos Indicates the shortcutInfos object as value. 1088 */ InsertShortcutInfos(const std::string & keyName,const ShortcutInfo & shortcutInfos)1089 void InsertShortcutInfos(const std::string &keyName, const ShortcutInfo &shortcutInfos) 1090 { 1091 shortcutInfos_.emplace(keyName, shortcutInfos); 1092 } 1093 // use for new Info in updating progress RestoreFromOldInfo(const InnerBundleInfo & oldInfo)1094 void RestoreFromOldInfo(const InnerBundleInfo &oldInfo) 1095 { 1096 SetAppCodePath(oldInfo.GetAppCodePath()); 1097 SetBaseDataDir(oldInfo.GetBaseDataDir()); 1098 SetUid(oldInfo.GetUid()); 1099 SetGid(oldInfo.GetGid()); 1100 } RestoreModuleInfo(const InnerBundleInfo & oldInfo)1101 void RestoreModuleInfo(const InnerBundleInfo &oldInfo) 1102 { 1103 if (oldInfo.FindModule(currentPackage_)) { 1104 innerModuleInfos_.at(currentPackage_).moduleDataDir = oldInfo.GetModuleDataDir(currentPackage_); 1105 } 1106 } 1107 /** 1108 * @brief Set ability enabled. 1109 * @param bundleName Indicates the bundleName. 1110 * @param abilityName Indicates the abilityName. 1111 * @param isEnabled Indicates the ability enabled. 1112 * @param userId Indicates the user id. 1113 * @return Return whether the application is enabled. 1114 */ 1115 bool SetAbilityEnabled( 1116 const std::string &bundleName, const std::string &abilityName, bool isEnabled, int32_t userId); 1117 /** 1118 * @brief Obtains configuration information about an application. 1119 * @param flags Indicates the flag used to specify information contained 1120 * in the ApplicationInfo object that will be returned. 1121 * @param userId Indicates the user ID. 1122 * @param appInfo Indicates the obtained ApplicationInfo object. 1123 */ 1124 void GetApplicationInfo(int32_t flags, int32_t userId, ApplicationInfo &appInfo) const; 1125 /** 1126 * @brief Obtains configuration information about an bundle. 1127 * @param flags Indicates the flag used to specify information contained in the BundleInfo that will be returned. 1128 * @param bundleInfos Indicates all of the obtained BundleInfo objects. 1129 * @param userId Indicates the user ID. 1130 */ 1131 void GetBundleInfo(int32_t flags, BundleInfo &bundleInfo, int32_t userId = Constants::UNSPECIFIED_USERID) const; 1132 /** 1133 * @brief Check if special metadata is in the application. 1134 * @param metaData Indicates the special metaData. 1135 * @param bundleInfos Returns true if the metadata in application; returns false otherwise. 1136 */ 1137 bool CheckSpecialMetaData(const std::string &metaData) const; 1138 /** 1139 * @brief Obtains the FormInfo objects provided by all applications on the device. 1140 * @param moduleName Indicates the module name of the application. 1141 * @param formInfos List of FormInfo objects if obtained; 1142 */ 1143 void GetFormsInfoByModule(const std::string &moduleName, std::vector<FormInfo> &formInfos) const; 1144 /** 1145 * @brief Obtains the FormInfo objects provided by a specified application on the device. 1146 * @param formInfos List of FormInfo objects if obtained; 1147 */ 1148 void GetFormsInfoByApp(std::vector<FormInfo> &formInfos) const; 1149 /** 1150 * @brief Obtains the ShortcutInfo objects provided by a specified application on the device. 1151 * @param shortcutInfos List of ShortcutInfo objects if obtained. 1152 */ 1153 void GetShortcutInfos(std::vector<ShortcutInfo> &shortcutInfos) const; 1154 /** 1155 * @brief Obtains the common event objects provided by a specified application on the device. 1156 * @param commonEvents List of common event objects if obtained. 1157 */ 1158 void GetCommonEvents(const std::string &eventKey, std::vector<CommonEventInfo> &commonEvents) const; 1159 1160 1161 std::optional<InnerModuleInfo> GetInnerModuleInfoByModuleName(const std::string &moduleName) const; 1162 1163 void GetModuleNames(std::vector<std::string> &moduleNames) const; 1164 /** 1165 * @brief Fetch all innerModuleInfos, can be modify. 1166 */ FetchInnerModuleInfos()1167 std::map<std::string, InnerModuleInfo> &FetchInnerModuleInfos() 1168 { 1169 return innerModuleInfos_; 1170 } 1171 /** 1172 * @brief Fetch all abilityInfos, can be modify. 1173 */ FetchAbilityInfos()1174 std::map<std::string, AbilityInfo> &FetchAbilityInfos() 1175 { 1176 return baseAbilityInfos_; 1177 } 1178 /** 1179 * @brief Obtains all abilityInfos. 1180 */ GetInnerAbilityInfos()1181 const std::map<std::string, AbilityInfo> &GetInnerAbilityInfos() const 1182 { 1183 return baseAbilityInfos_; 1184 } 1185 /** 1186 * @brief Obtains all skillInfos. 1187 */ GetInnerSkillInfos()1188 const std::map<std::string, std::vector<Skill>> &GetInnerSkillInfos() const 1189 { 1190 return skillInfos_; 1191 } 1192 /** 1193 * @brief Obtains all extensionAbilityInfos. 1194 */ GetInnerExtensionInfos()1195 const std::map<std::string, ExtensionAbilityInfo> &GetInnerExtensionInfos() const 1196 { 1197 return baseExtensionInfos_; 1198 } 1199 /** 1200 * @brief Obtains all extensionSkillInfos. 1201 */ GetExtensionSkillInfos()1202 const std::map<std::string, std::vector<Skill>> &GetExtensionSkillInfos() const 1203 { 1204 return extensionSkillInfos_; 1205 } 1206 /** 1207 * @brief Get the bundle is whether removable. 1208 * @return Return whether the bundle is removable. 1209 */ IsRemovable()1210 bool IsRemovable() const 1211 { 1212 return baseApplicationInfo_.removable; 1213 } SetIsPreInstallApp(bool isPreInstallApp)1214 void SetIsPreInstallApp(bool isPreInstallApp) 1215 { 1216 baseBundleInfo_.isPreInstallApp = isPreInstallApp; 1217 } IsPreInstallApp()1218 bool IsPreInstallApp() const 1219 { 1220 return baseBundleInfo_.isPreInstallApp; 1221 } 1222 /** 1223 * @brief Get whether the bundle is a system app. 1224 * @return Return whether the bundle is a system app. 1225 */ IsSystemApp()1226 bool IsSystemApp() const 1227 { 1228 return baseApplicationInfo_.isSystemApp; 1229 } 1230 /** 1231 * @brief Get all InnerBundleUserInfo. 1232 * @return Return about all userinfo under the app. 1233 */ GetInnerBundleUserInfos()1234 const std::map<std::string, InnerBundleUserInfo>& GetInnerBundleUserInfos() const 1235 { 1236 return innerBundleUserInfos_; 1237 } 1238 /** 1239 * @brief Set userId to remove userinfo. 1240 * @param userId Indicates the userId to set. 1241 */ 1242 void RemoveInnerBundleUserInfo(int32_t userId); 1243 /** 1244 * @brief Set userId to add userinfo. 1245 * @param userId Indicates the userInfo to set. 1246 */ 1247 void AddInnerBundleUserInfo(const InnerBundleUserInfo& userInfo); 1248 /** 1249 * @brief Set userId to add userinfo. 1250 * @param userId Indicates the userInfo to set. 1251 * @param userInfo Indicates the userInfo to get. 1252 * @return Return whether the user information is obtained successfully. 1253 */ 1254 bool GetInnerBundleUserInfo(int32_t userId, InnerBundleUserInfo& userInfo) const; 1255 /** 1256 * @brief Check whether the user exists. 1257 * @param userId Indicates the userInfo to set. 1258 * @return Return whether the user exists.. 1259 */ 1260 bool HasInnerBundleUserInfo(int32_t userId) const; 1261 /** 1262 * @brief Check whether onlyCreateBundleUser. 1263 * @return Return onlyCreateBundleUser. 1264 */ IsOnlyCreateBundleUser()1265 bool IsOnlyCreateBundleUser() const 1266 { 1267 return onlyCreateBundleUser_; 1268 } 1269 /** 1270 * @brief Set onlyCreateBundleUser. 1271 * @param onlyCreateBundleUser Indicates the onlyCreateBundleUser. 1272 */ SetOnlyCreateBundleUser(bool onlyCreateBundleUser)1273 void SetOnlyCreateBundleUser(bool onlyCreateBundleUser) 1274 { 1275 onlyCreateBundleUser_ = onlyCreateBundleUser; 1276 } 1277 /** 1278 * @brief Check whether isSingleUser. 1279 * @return Return isSingleUser. 1280 */ IsSingleUser()1281 bool IsSingleUser() const 1282 { 1283 return baseApplicationInfo_.singleUser; 1284 } 1285 /** 1286 * @brief Get response userId. 1287 * @param userId Indicates the request userId.. 1288 * @return Return response userId. 1289 */ 1290 int32_t GetResponseUserId(int32_t requestUserId) const; 1291 GetModuleNameVec()1292 std::vector<std::string> GetModuleNameVec() 1293 { 1294 std::vector<std::string> moduleVec; 1295 for (const auto &it : innerModuleInfos_) { 1296 moduleVec.emplace_back(it.first); 1297 } 1298 return moduleVec; 1299 } 1300 GetAccessTokenId(const int32_t userId)1301 uint32_t GetAccessTokenId(const int32_t userId) const 1302 { 1303 InnerBundleUserInfo userInfo; 1304 if (GetInnerBundleUserInfo(userId, userInfo)) { 1305 return userInfo.accessTokenId; 1306 } 1307 return 0; 1308 } 1309 1310 void SetAccessTokenId(uint32_t accessToken, const int32_t userId); 1311 SetIsNewVersion(bool flag)1312 void SetIsNewVersion(bool flag) 1313 { 1314 isNewVersion_ = flag; 1315 } 1316 GetIsNewVersion()1317 bool GetIsNewVersion() const 1318 { 1319 return isNewVersion_; 1320 } 1321 1322 void GetDistributedBundleInfo(DistributedBundleInfo &distributedBundleInfo) const; 1323 SetAllowedAcls(const std::vector<std::string> & allowedAcls)1324 void SetAllowedAcls(const std::vector<std::string> &allowedAcls) 1325 { 1326 allowedAcls_.clear(); 1327 for (const auto &acl : allowedAcls) { 1328 allowedAcls_.emplace_back(acl); 1329 } 1330 } 1331 GetAllowedAcls()1332 std::vector<std::string> GetAllowedAcls() const 1333 { 1334 return allowedAcls_; 1335 } 1336 /** 1337 * @brief ability is enabled. 1338 * @param abilityInfo Indicates the abilityInfo. 1339 * @param userId Indicates the user Id. 1340 * @return Return set ability enabled result. 1341 */ 1342 bool IsAbilityEnabled(const AbilityInfo &abilityInfo, int32_t userId) const; 1343 IsAccessible()1344 bool IsAccessible() const 1345 { 1346 return baseApplicationInfo_.accessible; 1347 } 1348 1349 void GetUriPrefixList(std::vector<std::string> &uriPrefixList, const std::string &excludeModule = "") const; 1350 void GetUriPrefixList(std::vector<std::string> &uriPrefixList, int32_t userId, 1351 const std::string &excludeModule = "") const; 1352 1353 const std::string &GetCurModuleName() const; 1354 1355 std::vector<std::string> GetDistroModuleName() const; 1356 1357 std::string GetModuleNameByPackage(const std::string &packageName) const; 1358 1359 std::string GetModuleTypeByPackage(const std::string &packageName) const; 1360 1361 private: 1362 void GetBundleWithAbilities( 1363 int32_t flags, BundleInfo &bundleInfo, int32_t userId = Constants::UNSPECIFIED_USERID) const; 1364 void GetBundeleWithExtension( 1365 int32_t flags, BundleInfo &bundleInfo, int32_t userId = Constants::UNSPECIFIED_USERID) const; 1366 void BuildDefaultUserInfo(); 1367 void RemoveDuplicateName(std::vector<std::string> &name) const; 1368 1369 // using for get 1370 bool isSupportBackup_ = false; 1371 bool isKeepData_ = false; 1372 Constants::AppType appType_ = Constants::AppType::THIRD_PARTY_APP; 1373 int uid_ = Constants::INVALID_UID; 1374 int gid_ = Constants::INVALID_GID; 1375 int userId_ = Constants::DEFAULT_USERID; 1376 std::string baseDataDir_; 1377 BundleStatus bundleStatus_ = BundleStatus::ENABLED; 1378 ApplicationInfo baseApplicationInfo_; 1379 BundleInfo baseBundleInfo_; // applicationInfo and abilityInfo empty 1380 std::string mainAbility_; 1381 std::string mainAbilityName_; 1382 std::string appFeature_; 1383 bool hasEntry_ = false; 1384 std::vector<std::string> allowedAcls_; 1385 InstallMark mark_; 1386 1387 // only using for install or update progress, doesn't need to save to database 1388 std::string currentPackage_; 1389 std::string newBundleName_; 1390 // Auxiliary property, which is used when the application 1391 // has been installed when the user is created. 1392 bool onlyCreateBundleUser_ = false; 1393 1394 std::map<std::string, InnerModuleInfo> innerModuleInfos_; 1395 1396 std::map<std::string, std::vector<FormInfo>> formInfos_; 1397 std::map<std::string, CommonEventInfo> commonEvents_; 1398 std::map<std::string, ShortcutInfo> shortcutInfos_; 1399 1400 std::map<std::string, AbilityInfo> baseAbilityInfos_; 1401 std::map<std::string, std::vector<Skill>> skillInfos_; 1402 1403 std::map<std::string, InnerBundleUserInfo> innerBundleUserInfos_; 1404 // new version fields 1405 bool isNewVersion_ = false; 1406 std::map<std::string, ExtensionAbilityInfo> baseExtensionInfos_; 1407 std::map<std::string, std::vector<Skill>> extensionSkillInfos_; 1408 }; 1409 1410 void from_json(const nlohmann::json &jsonObject, InnerModuleInfo &info); 1411 void from_json(const nlohmann::json &jsonObject, SkillUri &uri); 1412 void from_json(const nlohmann::json &jsonObject, Skill &skill); 1413 void from_json(const nlohmann::json &jsonObject, Distro &distro); 1414 void from_json(const nlohmann::json &jsonObject, InstallMark &installMark); 1415 void from_json(const nlohmann::json &jsonObject, DefinePermission &definePermission); 1416 } // namespace AppExecFwk 1417 } // namespace OHOS 1418 #endif // FOUNDATION_APPEXECFWK_SERVICES_BUNDLEMGR_INCLUDE_INNER_BUNDLE_INFO_H 1419