diff --git a/frameworks/native/appkit/ability_bundle_manager_helper/bundle_mgr_helper.cpp b/frameworks/native/appkit/ability_bundle_manager_helper/bundle_mgr_helper.cpp index f07249f52c73b80bf01bfb07ea10bfd944025175..da16455451ebd62195a64309fae348a23288fb3f 100644 --- a/frameworks/native/appkit/ability_bundle_manager_helper/bundle_mgr_helper.cpp +++ b/frameworks/native/appkit/ability_bundle_manager_helper/bundle_mgr_helper.cpp @@ -539,6 +539,43 @@ bool BundleMgrHelper::GetApplicationInfo( return bundleMgr->GetApplicationInfo(appName, flags, userId, appInfo); } +bool BundleMgrHelper::GetApplicationInfoWithAppIndex( + const std::string &appName, int32_t appIndex, int32_t userId, ApplicationInfo &appInfo) +{ + TAG_LOGI(AAFwkTag::BUNDLEMGRHELPER, "appName: %{public}s, appIndex: %{public}d", appName.c_str(), appIndex); + if (appIndex < 0) { + TAG_LOGE(AAFwkTag::BUNDLEMGRHELPER, "Invalid appIndex."); + return false; + } + auto bundleMgr = Connect(); + if (bundleMgr == nullptr) { + TAG_LOGE(AAFwkTag::BUNDLEMGRHELPER, "Failed to connect."); + return false; + } + + HITRACE_METER_NAME(HITRACE_TAG_ABILITY_MANAGER, __PRETTY_FUNCTION__); + BundleInfo bundleInfo; + if (appIndex == 0) { + if (bundleMgr->GetApplicationInfo(appName, AppExecFwk::BundleFlag::GET_BUNDLE_DEFAULT, userId, appInfo)) { + return true; + } + } else if (appIndex <= AbilityRuntime::GlobalConstant::MAX_APP_CLONE_INDEX) { + if (bundleMgr->GetCloneBundleInfo(appName, + static_cast(GetBundleInfoFlag::GET_BUNDLE_INFO_WITH_APPLICATION), + appIndex, bundleInfo, userId) == ERR_OK) { + appInfo = bundleInfo.applicationInfo; + return true; + } + } else { + if (bundleMgr->GetSandboxBundleInfo(appName, appIndex, userId, bundleInfo) == ERR_OK) { + appInfo = bundleInfo.applicationInfo; + return true; + } + } + TAG_LOGE(AAFwkTag::BUNDLEMGRHELPER, "GetApplicationInfo failed."); + return false; +} + bool BundleMgrHelper::UnregisterBundleEventCallback(const sptr &bundleEventCallback) { TAG_LOGD(AAFwkTag::BUNDLEMGRHELPER, "Called."); diff --git a/interfaces/kits/native/appkit/ability_bundle_manager_helper/bundle_mgr_helper.h b/interfaces/kits/native/appkit/ability_bundle_manager_helper/bundle_mgr_helper.h index 2e95258eb01803dfe3565059b8178c50f35216fb..3765fc8322f01dfb6142c6549840474b03478e2c 100644 --- a/interfaces/kits/native/appkit/ability_bundle_manager_helper/bundle_mgr_helper.h +++ b/interfaces/kits/native/appkit/ability_bundle_manager_helper/bundle_mgr_helper.h @@ -65,6 +65,8 @@ public: bool GetApplicationInfo( const std::string &appName, const ApplicationFlag flag, const int32_t userId, ApplicationInfo &appInfo); bool GetApplicationInfo(const std::string &appName, int32_t flags, int32_t userId, ApplicationInfo &appInfo); + bool GetApplicationInfoWithAppIndex(const std::string &appName, int32_t appIndex, + int32_t userId, ApplicationInfo &appInfo); ErrCode GetJsonProfile(ProfileType profileType, const std::string &bundleName, const std::string &moduleName, std::string &profile, int32_t userId = Constants::UNSPECIFIED_USERID); bool UnregisterBundleEventCallback(const sptr &bundleEventCallback); diff --git a/services/abilitymgr/include/ability_manager_service.h b/services/abilitymgr/include/ability_manager_service.h index 45a4f4538d12d070b0e2e9ee1be4b85048f45aeb..95f793a4b7a1eda04ad43fe329979b8a55b41f1f 100644 --- a/services/abilitymgr/include/ability_manager_service.h +++ b/services/abilitymgr/include/ability_manager_service.h @@ -2085,7 +2085,7 @@ private: int32_t RequestDialogServiceInner(const Want &want, const sptr &callerToken, int requestCode, int32_t userId); - bool CheckCallingTokenId(const std::string &bundleName, int32_t userId = INVALID_USER_ID); + bool CheckCallingTokenId(const std::string &bundleName, int32_t userId = INVALID_USER_ID, int32_t appIndex = 0); bool IsCallerSceneBoard(); void ReleaseAbilityTokenMap(const sptr &token); diff --git a/services/abilitymgr/src/ability_manager_service.cpp b/services/abilitymgr/src/ability_manager_service.cpp index 4599bc2e81b8d2a184c9feff52c92a7d15da5d07..d827827cc9c66a44dee358c9c647ad06120daa6d 100644 --- a/services/abilitymgr/src/ability_manager_service.cpp +++ b/services/abilitymgr/src/ability_manager_service.cpp @@ -2032,18 +2032,15 @@ int AbilityManagerService::StartUIAbilityBySCB(sptr sessionInfo, bo return uiAbilityManager->StartUIAbility(abilityRequest, sessionInfo, isColdStart); } -bool AbilityManagerService::CheckCallingTokenId(const std::string &bundleName, int32_t userId) +bool AbilityManagerService::CheckCallingTokenId(const std::string &bundleName, int32_t userId, int32_t appIndex) { HITRACE_METER_NAME(HITRACE_TAG_ABILITY_MANAGER, __PRETTY_FUNCTION__); - auto bms = GetBundleManager(); - if (bms == nullptr) { - TAG_LOGE(AAFwkTag::ABILITYMGR, "bms is invalid."); - return false; - } + auto bundleMgrHelper = DelayedSingleton::GetInstance(); + CHECK_POINTER_AND_RETURN(bundleMgrHelper, false); auto validUserId = GetValidUserId(userId); AppExecFwk::ApplicationInfo appInfo; - IN_PROCESS_CALL_WITHOUT_RET(bms->GetApplicationInfo(bundleName, - AppExecFwk::BundleFlag::GET_BUNDLE_DEFAULT, validUserId, appInfo)); + IN_PROCESS_CALL_WITHOUT_RET(bundleMgrHelper->GetApplicationInfoWithAppIndex(bundleName, + appIndex, validUserId, appInfo)); auto accessTokenId = IPCSkeleton::GetCallingTokenID(); if (accessTokenId != appInfo.accessTokenId) { TAG_LOGE(AAFwkTag::ABILITYMGR, "Permission verification failed"); @@ -9639,7 +9636,7 @@ int32_t AbilityManagerService::CheckProcessOptions(const Want &want, const Start return ERR_OK; } - TAG_LOGD(AAFwkTag::ABILITYMGR, "start ability with process options."); + TAG_LOGI(AAFwkTag::ABILITYMGR, "start ability with process options."); bool isEnable = AppUtils::GetInstance().IsStartOptionsWithProcessOptions(); if (!Rosen::SceneBoardJudgement::IsSceneBoardEnabled() || !isEnable) { TAG_LOGE(AAFwkTag::ABILITYMGR, "Not support process options."); @@ -9652,7 +9649,9 @@ int32_t AbilityManagerService::CheckProcessOptions(const Want &want, const Start return ERR_NOT_ALLOW_IMPLICIT_START; } - if (!CheckCallingTokenId(element.GetBundleName(), userId)) { + int32_t appIndex = 0; + appIndex = !AbilityRuntime::StartupUtil::GetAppIndex(want, appIndex) ? 0 : appIndex; + if (!CheckCallingTokenId(element.GetBundleName(), userId, appIndex)) { TAG_LOGE(AAFwkTag::ABILITYMGR, "Not self application."); return ERR_NOT_SELF_APPLICATION; }