diff --git a/frameworks/native/appkit/app/context_deal.cpp b/frameworks/native/appkit/app/context_deal.cpp index 2159ed299d8132bdb2bbdd7f2e60772ea1085106..d11c9cb554a2d95a7693d5d3291684193e199430 100644 --- a/frameworks/native/appkit/app/context_deal.cpp +++ b/frameworks/native/appkit/app/context_deal.cpp @@ -219,12 +219,12 @@ sptr ContextDeal::GetAbilityManager() std::string ContextDeal::GetAppType() { - auto ptr = GetBundleManager(); - if (ptr == nullptr) { + auto bundleMgrHelper = GetBundleManager(); + if (bundleMgrHelper == nullptr) { HILOG_ERROR("GetAppType failed to get bundle manager service"); return ""; } - std::string retString = ptr->GetAppType(applicationInfo_->bundleName); + std::string retString = bundleMgrHelper->GetAppType(applicationInfo_->bundleName); return retString; } @@ -453,8 +453,8 @@ int ContextDeal::GetColorMode() bool ContextDeal::HapModuleInfoRequestInit() { - auto ptr = GetBundleManager(); - if (ptr == nullptr) { + auto bundleMgrHelper = GetBundleManager(); + if (bundleMgrHelper == nullptr) { HILOG_ERROR("Failed to get bundle manager service."); return false; } @@ -465,7 +465,7 @@ bool ContextDeal::HapModuleInfoRequestInit() } hapModuleInfoLocal_ = std::make_shared(); - if (!ptr->GetHapModuleInfo(*abilityInfo_.get(), *hapModuleInfoLocal_)) { + if (!bundleMgrHelper->GetHapModuleInfo(*abilityInfo_.get(), *hapModuleInfoLocal_)) { HILOG_ERROR("Failed, will retval false value."); return false; } diff --git a/services/abilitymgr/include/ability_util.h b/services/abilitymgr/include/ability_util.h index bb2ad2a7f4e28437a688c4b1ed4c747aafda2a45..6100129e8ed751ece75e483aec22856327f89840 100644 --- a/services/abilitymgr/include/ability_util.h +++ b/services/abilitymgr/include/ability_util.h @@ -162,11 +162,6 @@ static constexpr int64_t MICROSECONDS = 1000000; // MICROSECONDS mean 10^6 mi return false; } -[[maybe_unused]] static std::shared_ptr GetBundleManagerHelper() -{ - return DelayedSingleton::GetInstance(); -} - [[maybe_unused]] static bool ParseJumpInterceptorWant(Want &targetWant, const std::string callerPkg) { if (callerPkg.empty()) { @@ -196,7 +191,7 @@ static constexpr int64_t MICROSECONDS = 1000000; // MICROSECONDS mean 10^6 mi HILOG_ERROR("get invalid inputs"); return false; } - auto bundleMgrHelper = AbilityUtil::GetBundleManagerHelper(); + auto bundleMgrHelper = DelayedSingleton::GetInstance(); if (bundleMgrHelper == nullptr) { HILOG_ERROR("Get bundle manager helper failed."); return false; @@ -233,7 +228,7 @@ static constexpr int64_t MICROSECONDS = 1000000; // MICROSECONDS mean 10^6 mi [[maybe_unused]] static bool IsStartIncludeAtomicService(const Want &want, const int32_t userId) { - auto bundleMgrHelper = AbilityUtil::GetBundleManagerHelper(); + auto bundleMgrHelper = DelayedSingleton::GetInstance(); if (bundleMgrHelper == nullptr) { HILOG_ERROR("Get bundle manager helper failed."); return false; diff --git a/services/abilitymgr/include/implicit_start_processor.h b/services/abilitymgr/include/implicit_start_processor.h index af8ee70759d2a7285fd8c133ad7e667a52d5024a..4c3816f9798181164331cae2b1389f4a1554d4cb 100644 --- a/services/abilitymgr/include/implicit_start_processor.h +++ b/services/abilitymgr/include/implicit_start_processor.h @@ -70,7 +70,6 @@ private: int GenerateAbilityRequestByAction(int32_t userId, AbilityRequest &request, std::vector &dialogAppInfos, std::string &deviceType, bool isMoreHapList); std::string MatchTypeAndUri(const AAFwk::Want &want); - std::shared_ptr GetBundleManagerHelper(); std::vector SplitStr(const std::string& str, char delimiter); int QueryBmsAppInfos(AbilityRequest &request, int32_t userId, std::vector &dialogAppInfos); diff --git a/services/abilitymgr/src/ability_connect_manager.cpp b/services/abilitymgr/src/ability_connect_manager.cpp index 839c79bdbc2205af0bc1ff0c3a014cb1882de20d..62d0b343c2a0606d40be8d473d1f1a79728f8086 100644 --- a/services/abilitymgr/src/ability_connect_manager.cpp +++ b/services/abilitymgr/src/ability_connect_manager.cpp @@ -766,7 +766,7 @@ int AbilityConnectManager::AbilityTransitionDone(const sptr &toke void AbilityConnectManager::ProcessPreload(const std::shared_ptr &record) const { - auto bundleMgrHelper = AbilityUtil::GetBundleManagerHelper(); + auto bundleMgrHelper = DelayedSingleton::GetInstance(); CHECK_POINTER(bundleMgrHelper); auto abilityInfo = record->GetAbilityInfo(); Want want; @@ -1765,7 +1765,7 @@ bool AbilityConnectManager::IsAbilityNeedKeepAlive(const std::shared_ptrGetAbilityInfo())) { return true; } - auto bundleMgrHelper = AbilityUtil::GetBundleManagerHelper(); + auto bundleMgrHelper = DelayedSingleton::GetInstance(); CHECK_POINTER_AND_RETURN(bundleMgrHelper, false); std::vector bundleInfos; bool getBundleInfos = bundleMgrHelper->GetBundleInfos( @@ -2054,7 +2054,7 @@ void AbilityConnectManager::GetExtensionRunningInfo(std::shared_ptrGetElementName(); - auto bundleMgrHelper = AbilityUtil::GetBundleManagerHelper(); + auto bundleMgrHelper = DelayedSingleton::GetInstance(); CHECK_POINTER(bundleMgrHelper); std::vector extensionInfos; diff --git a/services/abilitymgr/src/ability_interceptor.cpp b/services/abilitymgr/src/ability_interceptor.cpp index 6bbabffb72572a9b419febce5c777e6e4de60685..7b76166334356b9a41ef76a210dd978e7577007c 100644 --- a/services/abilitymgr/src/ability_interceptor.cpp +++ b/services/abilitymgr/src/ability_interceptor.cpp @@ -85,7 +85,7 @@ ErrCode CrowdTestInterceptor::DoProcess(const Want &want, int requestCode, int32 bool CrowdTestInterceptor::CheckCrowdtest(const Want &want, int32_t userId) { // get bms - auto bundleMgrHelper = AbilityUtil::GetBundleManagerHelper(); + auto bundleMgrHelper = DelayedSingleton::GetInstance(); if (bundleMgrHelper == nullptr) { HILOG_ERROR("The bundleMgrHelper is nullptr."); return false; @@ -157,7 +157,7 @@ bool ControlInterceptor::CheckControl(const Want &want, int32_t userId, { HITRACE_METER_NAME(HITRACE_TAG_ABILITY_MANAGER, __PRETTY_FUNCTION__); // get bms - auto bundleMgrHelper = AbilityUtil::GetBundleManagerHelper(); + auto bundleMgrHelper = DelayedSingleton::GetInstance(); if (bundleMgrHelper == nullptr) { HILOG_ERROR("The bundleMgrHelper is nullptr."); return false; @@ -225,7 +225,7 @@ bool DisposedRuleInterceptor::CheckControl(const Want &want, int32_t userId, { HITRACE_METER_NAME(HITRACE_TAG_ABILITY_MANAGER, __PRETTY_FUNCTION__); // get bms - auto bundleMgrHelper = AbilityUtil::GetBundleManagerHelper(); + auto bundleMgrHelper = DelayedSingleton::GetInstance(); if (bundleMgrHelper == nullptr) { HILOG_ERROR("The bundleMgrHelper is nullptr."); return false; @@ -436,7 +436,7 @@ void EcologicalRuleInterceptor::GetEcologicalCallerInfo(const Want &want, ErmsCa callerInfo.targetAppType = ErmsCallerInfo::TYPE_INVALID; callerInfo.callerAppType = ErmsCallerInfo::TYPE_INVALID; - auto bundleMgrHelper = AbilityUtil::GetBundleManagerHelper(); + auto bundleMgrHelper = DelayedSingleton::GetInstance(); if (bundleMgrHelper == nullptr) { HILOG_ERROR("The bundleMgrHelper is nullptr."); return; @@ -489,7 +489,7 @@ ErrCode AbilityJumpInterceptor::DoProcess(const Want &want, int requestCode, int return ERR_OK; } // get bms - auto bundleMgrHelper = AbilityUtil::GetBundleManagerHelper(); + auto bundleMgrHelper = DelayedSingleton::GetInstance(); if (bundleMgrHelper == nullptr) { HILOG_ERROR("The bundleMgrHelper is nullptr."); return ERR_OK; diff --git a/services/abilitymgr/src/ability_manager_service.cpp b/services/abilitymgr/src/ability_manager_service.cpp index 95e0a46a83228ad9edee179439a53e0ee855d50e..b5143034ca8b48eab2a309b902489e118c4e5d89 100644 --- a/services/abilitymgr/src/ability_manager_service.cpp +++ b/services/abilitymgr/src/ability_manager_service.cpp @@ -5422,7 +5422,7 @@ int AbilityManagerService::UninstallApp(const std::string &bundleName, int32_t u std::shared_ptr AbilityManagerService::GetBundleManager() { if (bundleMgrHelper_ == nullptr) { - bundleMgrHelper_ = AbilityUtil::GetBundleManagerHelper(); + bundleMgrHelper_ = DelayedSingleton::GetInstance(); } return bundleMgrHelper_; } diff --git a/services/abilitymgr/src/ability_record.cpp b/services/abilitymgr/src/ability_record.cpp index 8f9f61baba1c08123061079c2558753770a0c9f6..54dc196498bd8780a3f26a31dc5c25c629a2e80b 100644 --- a/services/abilitymgr/src/ability_record.cpp +++ b/services/abilitymgr/src/ability_record.cpp @@ -2925,7 +2925,7 @@ bool AbilityRecord::CheckUriPermission(Uri &uri, uint32_t &flag, uint32_t caller return true; } // uri of bundle name type - auto bundleMgrHelper = AbilityUtil::GetBundleManagerHelper(); + auto bundleMgrHelper = DelayedSingleton::GetInstance(); if (bundleMgrHelper == nullptr) { HILOG_ERROR("bundleMgrHelper is nullptr"); return false; diff --git a/services/abilitymgr/src/app_exit_reason_helper.cpp b/services/abilitymgr/src/app_exit_reason_helper.cpp index cabd044174ee05df717b1d51ea4eba564838ef44..dd09c649e0a3a1576cff94dda3efa17fe6cf0d1b 100644 --- a/services/abilitymgr/src/app_exit_reason_helper.cpp +++ b/services/abilitymgr/src/app_exit_reason_helper.cpp @@ -54,11 +54,11 @@ int32_t AppExitReasonHelper::RecordAppExitReason(const ExitReason &exitReason) return ERR_INVALID_VALUE; } - auto bms = AbilityUtil::GetBundleManagerHelper(); - CHECK_POINTER_AND_RETURN(bms, ERR_NULL_OBJECT); + auto bundleMgrHelper = DelayedSingleton::GetInstance(); + CHECK_POINTER_AND_RETURN(bundleMgrHelper, ERR_NULL_OBJECT); std::string bundleName; int32_t callerUid = IPCSkeleton::GetCallingUid(); - if (IN_PROCESS_CALL(bms->GetNameForUid(callerUid, bundleName)) != ERR_OK) { + if (IN_PROCESS_CALL(bundleMgrHelper->GetNameForUid(callerUid, bundleName)) != ERR_OK) { HILOG_ERROR("Get Bundle Name failed."); return GET_BUNDLE_INFO_FAILED; } diff --git a/services/abilitymgr/src/data_ability_manager.cpp b/services/abilitymgr/src/data_ability_manager.cpp index a2139c27d8ec36784ff1de6a9cf16aeb0b231544..42d18773e835848613d0c5d23d7433f35646ac74 100644 --- a/services/abilitymgr/src/data_ability_manager.cpp +++ b/services/abilitymgr/src/data_ability_manager.cpp @@ -632,7 +632,7 @@ void DataAbilityManager::GetAbilityRunningInfos(std::vector void DataAbilityManager::RestartDataAbility(const std::shared_ptr &abilityRecord) { // restart data ability if necessary - auto bundleMgrHelper = AbilityUtil::GetBundleManagerHelper(); + auto bundleMgrHelper = DelayedSingleton::GetInstance(); CHECK_POINTER(bundleMgrHelper); std::vector bundleInfos; bool getBundleInfos = bundleMgrHelper->GetBundleInfos( diff --git a/services/abilitymgr/src/dialog_session_record.cpp b/services/abilitymgr/src/dialog_session_record.cpp index 049ef4547670a95c0ec1d8352f9d1ad16c8e0feb..10d729ad06349a409eed94dc119eb407dd568a3f 100644 --- a/services/abilitymgr/src/dialog_session_record.cpp +++ b/services/abilitymgr/src/dialog_session_record.cpp @@ -103,7 +103,7 @@ void DialogSessionRecord::ClearAllDialogContexts() bool DialogSessionRecord::QueryDialogAppInfo(DialogAbilityInfo &dialogAbilityInfo, int32_t userId) { std::string bundleName = dialogAbilityInfo.bundleName; - auto bundleMgrHelper = AbilityUtil::GetBundleManagerHelper(); + auto bundleMgrHelper = DelayedSingleton::GetInstance(); CHECK_POINTER_AND_RETURN(bundleMgrHelper, ERR_INVALID_VALUE); BundleInfo bundleInfo; bool ret = IN_PROCESS_CALL(bundleMgrHelper->GetBundleInfoV9(bundleName, diff --git a/services/abilitymgr/src/free_install_manager.cpp b/services/abilitymgr/src/free_install_manager.cpp index a15ef9ce3d59dd3a516a4b174cb7e581658f443d..e4720f2de67103ef3c06a1422e15ce918594c811 100644 --- a/services/abilitymgr/src/free_install_manager.cpp +++ b/services/abilitymgr/src/free_install_manager.cpp @@ -95,7 +95,7 @@ int FreeInstallManager::StartFreeInstall(const Want &want, int32_t userId, int r freeInstallList_.push_back(info); } sptr callback = new AtomicServiceStatusCallback(weak_from_this(), isAsync); - auto bundleMgrHelper = AbilityUtil::GetBundleManagerHelper(); + auto bundleMgrHelper = DelayedSingleton::GetInstance(); CHECK_POINTER_AND_RETURN(bundleMgrHelper, GET_ABILITY_SERVICE_FAILED); AppExecFwk::AbilityInfo abilityInfo = {}; constexpr auto flag = AppExecFwk::AbilityInfoFlag::GET_ABILITY_INFO_WITH_APPLICATION; @@ -334,7 +334,7 @@ int FreeInstallManager::FreeInstallAbilityFromRemote(const Want &want, const spt int FreeInstallManager::ConnectFreeInstall(const Want &want, int32_t userId, const sptr &callerToken, const std::string& localDeviceId) { - auto bundleMgrHelper = AbilityUtil::GetBundleManagerHelper(); + auto bundleMgrHelper = DelayedSingleton::GetInstance(); CHECK_POINTER_AND_RETURN(bundleMgrHelper, GET_ABILITY_SERVICE_FAILED); std::string wantDeviceId = want.GetElement().GetDeviceID(); if (!(localDeviceId == wantDeviceId || wantDeviceId.empty())) { @@ -413,7 +413,7 @@ void FreeInstallManager::PostUpgradeAtomicServiceTask(int resultCode, const Want std::string nameKey = want.GetElement().GetBundleName() + want.GetElement().GetModuleName(); if (timeStampMap.find(nameKey) == timeStampMap.end() || sptr->GetTimeStamp() - timeStampMap[nameKey] > UPDATE_ATOMOIC_SERVICE_TASK_TIMER) { - auto bundleMgrHelper = AbilityUtil::GetBundleManagerHelper(); + auto bundleMgrHelper = DelayedSingleton::GetInstance(); CHECK_POINTER(bundleMgrHelper); bundleMgrHelper->UpgradeAtomicService(want, userId); timeStampMap.emplace(nameKey, sptr->GetTimeStamp()); diff --git a/services/abilitymgr/src/implicit_start_processor.cpp b/services/abilitymgr/src/implicit_start_processor.cpp index 5fbfd8e8a10e91059ba1ea163e479350a9ec7fbd..3e0f11880096a5088da0fbb1ad3389bf3eb08b05 100644 --- a/services/abilitymgr/src/implicit_start_processor.cpp +++ b/services/abilitymgr/src/implicit_start_processor.cpp @@ -253,7 +253,7 @@ int ImplicitStartProcessor::GenerateAbilityRequestByAction(int32_t userId, { HILOG_DEBUG("%{public}s.", __func__); // get abilityinfos from bms - auto bundleMgrHelper = GetBundleManagerHelper(); + auto bundleMgrHelper = DelayedSingleton::GetInstance(); CHECK_POINTER_AND_RETURN(bundleMgrHelper, GET_ABILITY_SERVICE_FAILED); auto abilityInfoFlag = AppExecFwk::AbilityInfoFlag::GET_ABILITY_INFO_DEFAULT | AppExecFwk::AbilityInfoFlag::GET_ABILITY_INFO_WITH_SKILL_URI; @@ -337,7 +337,7 @@ int ImplicitStartProcessor::GenerateAbilityRequestByAction(int32_t userId, int ImplicitStartProcessor::QueryBmsAppInfos(AbilityRequest &request, int32_t userId, std::vector &dialogAppInfos) { - auto bundleMgrHelper = GetBundleManagerHelper(); + auto bundleMgrHelper = DelayedSingleton::GetInstance(); std::vector bmsApps; auto abilityInfoFlag = AppExecFwk::AbilityInfoFlag::GET_ABILITY_INFO_DEFAULT | AppExecFwk::AbilityInfoFlag::GET_ABILITY_INFO_WITH_SKILL_URI; @@ -461,17 +461,9 @@ int ImplicitStartProcessor::CallStartAbilityInner(int32_t userId, return ret; } -std::shared_ptr ImplicitStartProcessor::GetBundleManagerHelper() -{ - if (iBundleManagerHelper_ == nullptr) { - iBundleManagerHelper_ = AbilityUtil::GetBundleManagerHelper(); - } - return iBundleManagerHelper_; -} - sptr ImplicitStartProcessor::GetDefaultAppProxy() { - auto bundleMgrHelper = GetBundleManagerHelper(); + auto bundleMgrHelper = DelayedSingleton::GetInstance(); if (bundleMgrHelper == nullptr) { HILOG_ERROR("The bundleMgrHelper is nullptr."); return nullptr; @@ -506,7 +498,7 @@ void ImplicitStartProcessor::GetEcologicalCallerInfo(const Want &want, ErmsCalle callerInfo.targetAppType = ErmsCallerInfo::TYPE_INVALID; callerInfo.callerAppType = ErmsCallerInfo::TYPE_INVALID; - auto bundleMgrHelper = GetBundleManagerHelper(); + auto bundleMgrHelper = DelayedSingleton::GetInstance(); if (bundleMgrHelper == nullptr) { HILOG_ERROR("Get Bubndle manager helper failed."); return; diff --git a/services/abilitymgr/src/mission_list_manager.cpp b/services/abilitymgr/src/mission_list_manager.cpp index de25738d3554ba43b147b0fc9da45ba985b54157..2fd9ee353cc1dd8afc849eaa87b7298b142610e6 100644 --- a/services/abilitymgr/src/mission_list_manager.cpp +++ b/services/abilitymgr/src/mission_list_manager.cpp @@ -2842,7 +2842,7 @@ void MissionListManager::CompleteFirstFrameDrawing(const sptr &ab void MissionListManager::ProcessPreload(const std::shared_ptr &record) const { - auto bundleMgrHelper = AbilityUtil::GetBundleManagerHelper(); + auto bundleMgrHelper = DelayedSingleton::GetInstance(); CHECK_POINTER(bundleMgrHelper); auto abilityInfo = record->GetAbilityInfo(); Want want; diff --git a/services/abilitymgr/src/system_dialog_scheduler.cpp b/services/abilitymgr/src/system_dialog_scheduler.cpp index 320a0f4bbeed040dc95e6c47ab201d7f8b0dc8f4..258fa354ba0f67da2798db1f43bc4ab482dedb73 100644 --- a/services/abilitymgr/src/system_dialog_scheduler.cpp +++ b/services/abilitymgr/src/system_dialog_scheduler.cpp @@ -377,7 +377,7 @@ int SystemDialogScheduler::GetSelectorDialogWant(const std::vector::GetInstance(); if (bundleMgrHelper == nullptr) { HILOG_ERROR("The bundleMgrHelper is nullptr."); return INNER_ERR; @@ -443,7 +443,7 @@ int SystemDialogScheduler::GetPcSelectorDialogWant(const std::vector::GetInstance(); if (bundleMgrHelper == nullptr) { HILOG_ERROR("The bundleMgrHelper is nullptr."); return INNER_ERR; diff --git a/services/appmgr/include/app_mgr_service_inner.h b/services/appmgr/include/app_mgr_service_inner.h index 60583b7609189f0588c689d55a7f79efcb3e2e11..887bb40ecd5e60ee1e495db4844845f8ec8905d9 100644 --- a/services/appmgr/include/app_mgr_service_inner.h +++ b/services/appmgr/include/app_mgr_service_inner.h @@ -1081,9 +1081,6 @@ private: */ int64_t SystemTimeMillisecond(); - // Test add the bundle manager instance. - void SetBundleManagerHelper(const std::shared_ptr &bundleMgrHelper); - void HandleTerminateApplicationTimeOut(const int64_t eventId); void HandleAddAbilityStageTimeOut(const int64_t eventId); diff --git a/services/appmgr/include/remote_client_manager.h b/services/appmgr/include/remote_client_manager.h index 1e088e39319cd2a92a0cbf8b5955b15813f64062..131770bf37f33564eed82b3b45e01c6e6ca55faa 100644 --- a/services/appmgr/include/remote_client_manager.h +++ b/services/appmgr/include/remote_client_manager.h @@ -43,20 +43,6 @@ public: */ void SetSpawnClient(const std::shared_ptr &appSpawnClient); - /** - * GetBundleManager, Get bundle management services. - * - * @return the bundle management services instance. - */ - std::shared_ptr GetBundleManagerHelper(); - - /** - * @brief Setting bundle management instance. - * - * @param appSpawnClient, the bundle management instance. - */ - void SetBundleManagerHelper(const std::shared_ptr &bundleMgrHelper); - std::shared_ptr GetNWebSpawnClient(); private: diff --git a/services/appmgr/src/app_mgr_service.cpp b/services/appmgr/src/app_mgr_service.cpp index 2ffbec8c63023fb99478b6c2bb6011b38fc02c77..d1edcd9b97f086bf77b4c19d1344eac4c7a0e535 100644 --- a/services/appmgr/src/app_mgr_service.cpp +++ b/services/appmgr/src/app_mgr_service.cpp @@ -280,12 +280,7 @@ int32_t AppMgrService::ClearUpApplicationData(const std::string &bundleName, con if (!IsReady()) { return ERR_INVALID_OPERATION; } - std::shared_ptr remoteClientManager = std::make_shared(); - if (remoteClientManager == nullptr) { - HILOG_ERROR("The remoteClientManager is nullptr."); - return ERR_INVALID_OPERATION; - } - auto bundleMgrHelper = remoteClientManager->GetBundleManagerHelper(); + auto bundleMgrHelper = DelayedSingleton::GetInstance(); if (bundleMgrHelper == nullptr) { HILOG_ERROR("The bundleMgrHelper is nullptr."); return ERR_INVALID_OPERATION; @@ -475,12 +470,7 @@ int AppMgrService::FinishUserTest(const std::string &msg, const int64_t &resultC HILOG_ERROR("Not ready"); return ERR_INVALID_OPERATION; } - std::shared_ptr remoteClientManager = std::make_shared(); - if (remoteClientManager == nullptr) { - HILOG_ERROR("The remoteClientManager is nullptr."); - return ERR_INVALID_OPERATION; - } - auto bundleMgrHelper = remoteClientManager->GetBundleManagerHelper(); + auto bundleMgrHelper = DelayedSingleton::GetInstance(); if (bundleMgrHelper == nullptr) { HILOG_ERROR("The bundleMgrHelper is nullptr."); return ERR_INVALID_OPERATION; diff --git a/services/appmgr/src/app_mgr_service_inner.cpp b/services/appmgr/src/app_mgr_service_inner.cpp index af008da310aa45df2ac5769183f2ce67553057b7..bbb4e64cd6987480a3a0c1c8961b7f35e3bfdcc5 100644 --- a/services/appmgr/src/app_mgr_service_inner.cpp +++ b/services/appmgr/src/app_mgr_service_inner.cpp @@ -517,7 +517,7 @@ bool AppMgrServiceInner::GetBundleAndHapInfo(const AbilityInfo &abilityInfo, int32_t appIndex) const { HITRACE_METER_NAME(HITRACE_TAG_ABILITY_MANAGER, __PRETTY_FUNCTION__); - auto bundleMgrHelper = remoteClientManager_->GetBundleManagerHelper(); + auto bundleMgrHelper = DelayedSingleton::GetInstance(); if (bundleMgrHelper == nullptr) { HILOG_ERROR("The bundleMgrHelper is nullptr."); return false; @@ -814,12 +814,7 @@ int32_t AppMgrServiceInner::UpdateApplicationInfoInstalled(const std::string &bu return result; } - if (remoteClientManager_ == nullptr) { - HILOG_ERROR("The remoteClientManager_ fail."); - return ERR_NO_INIT; - } - - auto bundleMgrHelper = remoteClientManager_->GetBundleManagerHelper(); + auto bundleMgrHelper = DelayedSingleton::GetInstance(); if (bundleMgrHelper == nullptr) { HILOG_ERROR("The bundleMgrHelper is nullptr."); return ERR_NO_INIT; @@ -881,11 +876,7 @@ int32_t AppMgrServiceInner::KillApplicationByUid(const std::string &bundleName, int64_t startTime = SystemTimeMillisecond(); std::list pids; - if (remoteClientManager_ == nullptr) { - HILOG_ERROR("The remoteClientManager_ is nullptr."); - return ERR_NO_INIT; - } - auto bundleMgrHelper = remoteClientManager_->GetBundleManagerHelper(); + auto bundleMgrHelper = DelayedSingleton::GetInstance(); if (bundleMgrHelper == nullptr) { HILOG_ERROR("The bundleMgrHelper is nullptr."); return ERR_NO_INIT; @@ -1009,12 +1000,7 @@ int32_t AppMgrServiceInner::KillApplicationByUserId(const std::string &bundleNam HILOG_ERROR("%{public}s: Permission verification failed", __func__); return ERR_PERMISSION_DENIED; } - - if (remoteClientManager_ == nullptr) { - HILOG_ERROR("remoteClientManager_ fail"); - return ERR_NO_INIT; - } - auto bundleMgrHelper = remoteClientManager_->GetBundleManagerHelper(); + auto bundleMgrHelper = DelayedSingleton::GetInstance(); if (bundleMgrHelper == nullptr) { HILOG_ERROR("The bundleMgrHelper is nullptr."); return ERR_NO_INIT; @@ -1033,11 +1019,7 @@ int32_t AppMgrServiceInner::KillApplicationByUserIdLocked(const std::string &bun int result = ERR_OK; int64_t startTime = SystemTimeMillisecond(); std::list pids; - if (remoteClientManager_ == nullptr) { - HILOG_ERROR("remoteClientManager_ is nullptr."); - return ERR_NO_INIT; - } - auto bundleMgrHelper = remoteClientManager_->GetBundleManagerHelper(); + auto bundleMgrHelper = DelayedSingleton::GetInstance(); if (bundleMgrHelper == nullptr) { HILOG_ERROR("The bundleMgrHelper is nullptr."); return ERR_NO_INIT; @@ -1107,7 +1089,7 @@ int32_t AppMgrServiceInner::ClearUpApplicationDataByUserId( HILOG_ERROR("invalid callerUid:%{public}d", callerUid); return ERR_INVALID_OPERATION; } - auto bundleMgrHelper = remoteClientManager_->GetBundleManagerHelper(); + auto bundleMgrHelper = DelayedSingleton::GetInstance(); if (bundleMgrHelper == nullptr) { HILOG_ERROR("The bundleMgrHelper is nullptr."); return ERR_INVALID_OPERATION; @@ -1618,16 +1600,6 @@ void AppMgrServiceInner::SetAppSpawnClient(std::shared_ptr spawn remoteClientManager_->SetSpawnClient(std::move(spawnClient)); } -void AppMgrServiceInner::SetBundleManagerHelper(const std::shared_ptr &bundleMgrHelper) -{ - if (remoteClientManager_ == nullptr) { - HILOG_ERROR("The remoteClientManager_ is nullptr."); - return; - } - - remoteClientManager_->SetBundleManagerHelper(bundleMgrHelper); -} - void AppMgrServiceInner::RegisterAppStateCallback(const sptr &callback) { pid_t callingPid = IPCSkeleton::GetCallingPid(); @@ -1994,11 +1966,7 @@ void AppMgrServiceInner::SetOverlayInfo(const std::string &bundleName, const int32_t userId, AppSpawnStartMsg &startMsg) { - if (remoteClientManager_ == nullptr) { - HILOG_ERROR("The remoteClientManager_ is nullptr."); - return; - } - auto bundleMgrHelper = remoteClientManager_->GetBundleManagerHelper(); + auto bundleMgrHelper = DelayedSingleton::GetInstance(); if (bundleMgrHelper == nullptr) { HILOG_ERROR("The bundleMgrHelper is nullptr."); return; @@ -2092,7 +2060,7 @@ void AppMgrServiceInner::StartProcess(const std::string &appName, const std::str return; } - auto bundleMgrHelper = remoteClientManager_->GetBundleManagerHelper(); + auto bundleMgrHelper = DelayedSingleton::GetInstance(); if (bundleMgrHelper == nullptr) { HILOG_ERROR("Get bundle manager helper fail."); appRunningManager_->RemoveAppRunningRecordById(appRecord->GetRecordId()); @@ -2775,8 +2743,9 @@ bool AppMgrServiceInner::CheckRemoteClient() return false; } - if (!remoteClientManager_->GetBundleManagerHelper()) { - HILOG_ERROR("Get bundle manager helper fail."); + auto bundleMgrHelper = DelayedSingleton::GetInstance(); + if (bundleMgrHelper == nullptr) { + HILOG_ERROR("The bundleMgrHelper is nullptr."); return false; } return true; @@ -2808,7 +2777,7 @@ void AppMgrServiceInner::RestartResidentProcess(std::shared_ptrGetBundleManagerHelper(); + auto bundleMgrHelper = DelayedSingleton::GetInstance(); BundleInfo bundleInfo; auto callerUid = IPCSkeleton::GetCallingUid(); auto userId = GetUserIdByUid(callerUid); @@ -3658,8 +3627,8 @@ bool AppMgrServiceInner::CheckCallerIsAppGallery() HILOG_ERROR("Get app running record by calling pid failed. callingPId: %{public}d", callerPid); return false; } - auto bundleMgrHelper = remoteClientManager_->GetBundleManagerHelper(); - if (!bundleMgrHelper) { + auto bundleMgrHelper = DelayedSingleton::GetInstance(); + if (bundleMgrHelper == nullptr) { HILOG_ERROR("The bundleMgrHelper is nullptr."); return false; } @@ -4437,12 +4406,9 @@ void AppMgrServiceInner::TimeoutNotifyApp(int32_t pid, int32_t uid, int32_t AppMgrServiceInner::NotifyAppFaultBySA(const AppFaultDataBySA &faultData) { - if (remoteClientManager_ == nullptr) { - HILOG_ERROR("The remoteClientManager_ is nullptr."); - return ERR_NO_INIT; - } std::string callerBundleName; - if (auto bundleMgrHelper = remoteClientManager_->GetBundleManagerHelper(); bundleMgrHelper != nullptr) { + auto bundleMgrHelper = DelayedSingleton::GetInstance(); + if (bundleMgrHelper != nullptr) { int32_t callingUid = IPCSkeleton::GetCallingUid(); IN_PROCESS_CALL(bundleMgrHelper->GetNameForUid(callingUid, callerBundleName)); } @@ -4458,16 +4424,13 @@ int32_t AppMgrServiceInner::NotifyAppFaultBySA(const AppFaultDataBySA &faultData HILOG_ERROR("no such AppRunningRecord"); return ERR_INVALID_VALUE; } - FaultData transformedFaultData = ConvertDataTypes(faultData); int32_t uid = record->GetUid(); std::string bundleName = record->GetBundleName(); - if (faultData.errorObject.name == "appRecovery") { AppRecoveryNotifyApp(pid, bundleName, faultData.faultType, "appRecovery"); return ERR_OK; } - if (transformedFaultData.timeoutMarkers.empty()) { transformedFaultData.timeoutMarkers = "notifyFault:" + transformedFaultData.errorObject.name + std::to_string(pid) + "-" + std::to_string(SystemTimeMillisecond()); @@ -4565,7 +4528,7 @@ int32_t AppMgrServiceInner::IsApplicationRunning(const std::string &bundleName, int32_t AppMgrServiceInner::StartNativeProcessForDebugger(const AAFwk::Want &want) const { - auto&& bundleMgrHelper = remoteClientManager_->GetBundleManagerHelper(); + auto&& bundleMgrHelper = DelayedSingleton::GetInstance(); if (bundleMgrHelper == nullptr) { HILOG_ERROR("Get bundle manager helper error."); return ERR_INVALID_OPERATION; @@ -4716,12 +4679,7 @@ int32_t AppMgrServiceInner::GetRunningProcessInformation( HILOG_ERROR("The appRunningManager is nullptr!"); return ERR_NO_INIT; } - - if (remoteClientManager_ == nullptr) { - HILOG_ERROR("The remoteClientManager_ is nullptr!"); - return ERR_NO_INIT; - } - auto bundleMgrHelper = remoteClientManager_->GetBundleManagerHelper(); + auto bundleMgrHelper = DelayedSingleton::GetInstance(); if (bundleMgrHelper == nullptr) { HILOG_ERROR("The bundleMgrHelper is nullptr!"); return ERR_NO_INIT; diff --git a/services/appmgr/src/app_state_observer_manager.cpp b/services/appmgr/src/app_state_observer_manager.cpp index adc82ed262cc656524b0ccd12cb7d05b938e79f1..eaaca23d90252e3dcb6c3b5e4be98875b74201e7 100644 --- a/services/appmgr/src/app_state_observer_manager.cpp +++ b/services/appmgr/src/app_state_observer_manager.cpp @@ -830,7 +830,7 @@ AppStateData AppStateObserverManager::WrapAppStateData(const std::shared_ptr remoteClientManager = std::make_shared(); - auto bundleMgr = remoteClientManager->GetBundleManagerHelper(); + auto bundleMgr = DelayedSingleton::GetInstance(); std::string callerBundleName; if (bundleMgr != nullptr && IN_PROCESS_CALL(bundleMgr->GetNameForUid(appRecord->GetCallerUid(), callerBundleName)) == ERR_OK) { diff --git a/services/appmgr/src/remote_client_manager.cpp b/services/appmgr/src/remote_client_manager.cpp index b2a1035b079cc2ee21f65fdb7faa225eb90ee9df..777ea5929d0fc2cca95f06e0355febd1dc6419a1 100644 --- a/services/appmgr/src/remote_client_manager.cpp +++ b/services/appmgr/src/remote_client_manager.cpp @@ -43,19 +43,6 @@ void RemoteClientManager::SetSpawnClient(const std::shared_ptr & appSpawnClient_ = appSpawnClient; } -std::shared_ptr RemoteClientManager::GetBundleManagerHelper() -{ - if (bundleManagerHelper_ == nullptr) { - bundleManagerHelper_ = DelayedSingleton::GetInstance(); - } - return bundleManagerHelper_; -} - -void RemoteClientManager::SetBundleManagerHelper(const std::shared_ptr &bundleMgrHelper) -{ - bundleManagerHelper_ = bundleMgrHelper; -} - std::shared_ptr RemoteClientManager::GetNWebSpawnClient() { return nwebSpawnClient_; diff --git a/test/fuzztest/appmgrrest_fuzzer/appmgrrest_fuzzer.cpp b/test/fuzztest/appmgrrest_fuzzer/appmgrrest_fuzzer.cpp index f91110e73f638376a8e4d5142f90e0860ddc4f16..1b4abe21a749034d9ffd51e5f2d7a299e2b961ca 100755 --- a/test/fuzztest/appmgrrest_fuzzer/appmgrrest_fuzzer.cpp +++ b/test/fuzztest/appmgrrest_fuzzer/appmgrrest_fuzzer.cpp @@ -120,12 +120,9 @@ bool DoSomethingInterestingWithMyAPI(const char* data, size_t size) appSpawnSocket.ReadMessage(reinterpret_cast(*data), len); appSpawnSocket.CloseAppSpawnConnection(); RemoteClientManager remoteClientManager; - std::shared_ptr bundleManagerHelper = nullptr; - remoteClientManager.SetBundleManagerHelper(bundleManagerHelper); std::shared_ptr appSpawnClientptr; remoteClientManager.SetSpawnClient(appSpawnClientptr); remoteClientManager.GetSpawnClient(); - remoteClientManager.GetBundleManagerHelper(); remoteClientManager.GetNWebSpawnClient(); std::shared_ptr owner; WindowFocusChangedListener windowFocusChangedListener(owner, handler); diff --git a/test/moduletest/common/ams/app_recent_list_test/BUILD.gn b/test/moduletest/common/ams/app_recent_list_test/BUILD.gn index 6cadac3137c11eb352a516915d37ad4f7aaf9d56..4086c21b3d26cd23aa0115f3365d4d7f742f8510 100644 --- a/test/moduletest/common/ams/app_recent_list_test/BUILD.gn +++ b/test/moduletest/common/ams/app_recent_list_test/BUILD.gn @@ -1,4 +1,4 @@ -# Copyright (c) 2021-2022 Huawei Device Co., Ltd. +# Copyright (c) 2021-2023 Huawei Device Co., Ltd. # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at @@ -19,6 +19,7 @@ ohos_moduletest("AmsAppRecentListModuleTest") { module_out_path = module_output_path include_dirs = [ + "${ability_runtime_test_path}/mock/common/include", "${ability_runtime_test_path}/mock/services_appmgr_test/include", "${ability_runtime_path}/interfaces/kits/native/appkit/ability_bundle_manager_helper", ] diff --git a/test/moduletest/common/ams/app_recent_list_test/ams_app_recent_list_module_test.cpp b/test/moduletest/common/ams/app_recent_list_test/ams_app_recent_list_module_test.cpp index 5accdfc7a3fe2b8cf5c35b23673adf237f7e9f5d..d9200cde14a374e5f973266745f55bb0c4dfa704 100644 --- a/test/moduletest/common/ams/app_recent_list_test/ams_app_recent_list_module_test.cpp +++ b/test/moduletest/common/ams/app_recent_list_test/ams_app_recent_list_module_test.cpp @@ -13,20 +13,24 @@ * limitations under the License. */ +#include +#include + #define private public #include "app_mgr_service_inner.h" +#include "iservice_registry.h" #undef private -#include -#include - -#include "refbase.h" +#include "bundle_mgr_interface.h" #include "hilog_wrapper.h" #include "iremote_object.h" -#include "mock_bundle_manager.h" #include "mock_ability_token.h" #include "mock_app_scheduler.h" #include "mock_app_spawn_client.h" +#include "mock_bundle_installer_service.h" +#include "mock_bundle_manager_service.h" +#include "mock_system_ability_manager.h" +#include "refbase.h" using namespace testing::ext; using testing::_; @@ -43,6 +47,9 @@ const int32_t INDEX_NUM_3 = 3; const int32_t INDEX_NUM_10 = 10; const std::string TEST_APP_NAME = "com.ohos.test.helloworld"; const std::string TEST_ABILITY_NAME = "test_ability_"; +constexpr int32_t BUNDLE_MGR_SERVICE_SYS_ABILITY_ID = 401; +sptr mockBundleInstaller = new (std::nothrow) MockBundleInstallerService(); +sptr mockBundleMgr = new (std::nothrow) MockBundleManagerService(); } // namespace class AmsAppRecentListModuleTest : public testing::Test { @@ -51,6 +58,10 @@ public: static void TearDownTestCase(); void SetUp(); void TearDown(); + void MockBundleInstallerAndSA(); + void MockBundleInstaller(); + sptr iSystemAbilityMgr_ = nullptr; + sptr mockSystemAbility_ = nullptr; protected: const std::shared_ptr GetApplicationByIndex(const int32_t index) const; @@ -59,7 +70,6 @@ protected: std::shared_ptr serviceInner_{ nullptr }; sptr mockToken_{ nullptr }; - std::shared_ptr mockBundleMgr{ nullptr }; }; void AmsAppRecentListModuleTest::SetUpTestCase() @@ -72,12 +82,31 @@ void AmsAppRecentListModuleTest::SetUp() { serviceInner_.reset(new (std::nothrow) AppMgrServiceInner()); serviceInner_->Init(); - mockBundleMgr = DelayedSingleton::GetInstance(); - serviceInner_->SetBundleManagerHelper(mockBundleMgr); + mockSystemAbility_ = new (std::nothrow) AppExecFwk::MockSystemAbilityManager(); + iSystemAbilityMgr_ = SystemAbilityManagerClient::GetInstance().GetSystemAbilityManager(); + SystemAbilityManagerClient::GetInstance().systemAbilityManager_ = mockSystemAbility_; } void AmsAppRecentListModuleTest::TearDown() -{} +{ + SystemAbilityManagerClient::GetInstance().systemAbilityManager_ = iSystemAbilityMgr_; +} + +void AmsAppRecentListModuleTest::MockBundleInstallerAndSA() +{ + auto mockGetBundleInstaller = []() { return mockBundleInstaller; }; + auto mockGetSystemAbility = [bms = mockBundleMgr, saMgr = iSystemAbilityMgr_](int32_t systemAbilityId) { + if (systemAbilityId == BUNDLE_MGR_SERVICE_SYS_ABILITY_ID) { + return bms->AsObject(); + } else { + return saMgr->GetSystemAbility(systemAbilityId); + } + }; + EXPECT_CALL(*mockBundleMgr, GetBundleInstaller()).WillOnce(testing::Invoke(mockGetBundleInstaller)); + EXPECT_CALL(*mockSystemAbility_, GetSystemAbility(testing::_)) + .WillOnce(testing::Invoke(mockGetSystemAbility)) + .WillRepeatedly(testing::Invoke(mockGetSystemAbility)); +} const std::shared_ptr AmsAppRecentListModuleTest::GetApplicationByIndex(const int32_t index) const { @@ -137,6 +166,10 @@ void AmsAppRecentListModuleTest::CreateAppRecentList(const int32_t appNum) */ HWTEST_F(AmsAppRecentListModuleTest, Create_Recent_List_001, TestSize.Level1) { + MockBundleInstallerAndSA(); + EXPECT_CALL(*mockBundleMgr, GetHapModuleInfo(testing::_, testing::_, testing::_)) + .WillOnce(testing::Return(true)) + .WillRepeatedly(testing::Return(true)); HILOG_INFO("Create_Recent_List_001 start"); EXPECT_TRUE(serviceInner_->GetRecentAppList().empty()); CreateAppRecentList(INDEX_NUM_10); diff --git a/test/moduletest/common/ams/app_running_processes_info_module_test/app_running_processes_info_module_test.cpp b/test/moduletest/common/ams/app_running_processes_info_module_test/app_running_processes_info_module_test.cpp index 6f3ea3f621deb36a49557f7d78681b9466dde1b0..de51b14ec5b9b20aff53bb7c280eea2ab8b2f7ee 100644 --- a/test/moduletest/common/ams/app_running_processes_info_module_test/app_running_processes_info_module_test.cpp +++ b/test/moduletest/common/ams/app_running_processes_info_module_test/app_running_processes_info_module_test.cpp @@ -12,26 +12,31 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -#define private public -#include "app_running_record.h" -#undef private + #include #include -#include "iremote_object.h" -#include "app_record_id.h" -#include "app_scheduler_proxy.h" -#include "app_scheduler_host.h" + #define private public #include "app_mgr_service_inner.h" +#include "app_running_record.h" +#include "iservice_registry.h" #undef private -#include "mock_application.h" + #include "ability_info.h" #include "application_info.h" -#include "mock_bundle_manager.h" +#include "app_record_id.h" +#include "app_scheduler_host.h" +#include "app_scheduler_proxy.h" +#include "iremote_object.h" #include "mock_ability_token.h" +#include "mock_application.h" #include "mock_app_scheduler.h" #include "mock_app_spawn_client.h" +#include "mock_bundle_installer_service.h" +#include "mock_bundle_manager_service.h" #include "mock_native_token.h" +#include "mock_system_ability_manager.h" +#include "singleton.h" #include "mock_sa_call.h" using namespace testing::ext; @@ -44,13 +49,20 @@ using testing::InvokeWithoutArgs; namespace OHOS { namespace AppExecFwk { +namespace { +constexpr int32_t BUNDLE_MGR_SERVICE_SYS_ABILITY_ID = 401; +sptr mockBundleInstaller = new (std::nothrow) MockBundleInstallerService(); +sptr mockBundleMgr = new (std::nothrow) MockBundleManagerService(); +} // namespace class AppRunningProcessesInfoModuleTest : public testing::Test { public: static void SetUpTestCase(); static void TearDownTestCase(); void SetUp(); void TearDown(); - + void MockBundleInstallerAndSA() const; + sptr iSystemAbilityMgr_ = nullptr; + sptr mockSystemAbility_ = nullptr; protected: std::string GetTestAppName(const unsigned long num) const { @@ -130,7 +142,6 @@ protected: } std::unique_ptr service_{ nullptr }; - std::shared_ptr mockBundleMgr_{ nullptr }; sptr GetMockToken() const { @@ -168,12 +179,31 @@ void AppRunningProcessesInfoModuleTest::SetUp() AAFwk::IsMockSaCall::IsMockSaCallWithPermission(); service_.reset(new (std::nothrow) AppMgrServiceInner()); mockToken_ = new (std::nothrow) MockAbilityToken(); - mockBundleMgr_ = DelayedSingleton::GetInstance(); - service_->SetBundleManagerHelper(mockBundleMgr_); + mockSystemAbility_ = new (std::nothrow) AppExecFwk::MockSystemAbilityManager(); + iSystemAbilityMgr_ = SystemAbilityManagerClient::GetInstance().GetSystemAbilityManager(); + SystemAbilityManagerClient::GetInstance().systemAbilityManager_ = mockSystemAbility_; } void AppRunningProcessesInfoModuleTest::TearDown() -{} +{ + SystemAbilityManagerClient::GetInstance().systemAbilityManager_ = iSystemAbilityMgr_; +} + +void AppRunningProcessesInfoModuleTest::MockBundleInstallerAndSA() const +{ + auto mockGetBundleInstaller = []() { return mockBundleInstaller; }; + auto mockGetSystemAbility = [bms = mockBundleMgr, saMgr = iSystemAbilityMgr_](int32_t systemAbilityId) { + if (systemAbilityId == BUNDLE_MGR_SERVICE_SYS_ABILITY_ID) { + return bms->AsObject(); + } else { + return saMgr->GetSystemAbility(systemAbilityId); + } + }; + EXPECT_CALL(*mockBundleMgr, GetBundleInstaller()).WillOnce(testing::Invoke(mockGetBundleInstaller)); + EXPECT_CALL(*mockSystemAbility_, GetSystemAbility(testing::_)) + .WillOnce(testing::Invoke(mockGetSystemAbility)) + .WillRepeatedly(testing::Invoke(mockGetSystemAbility)); +} /* * Feature: AppMgrServiceInner @@ -185,6 +215,10 @@ void AppRunningProcessesInfoModuleTest::TearDown() */ HWTEST_F(AppRunningProcessesInfoModuleTest, ApplicationStart_001, TestSize.Level1) { + MockBundleInstallerAndSA(); + EXPECT_CALL(*mockBundleMgr, GetHapModuleInfo(testing::_, testing::_, testing::_)) + .WillOnce(testing::Return(true)) + .WillRepeatedly(testing::Return(true)); // init AppRunningRecord unsigned long index = 0L; int uid = 100; diff --git a/test/moduletest/common/ams/app_service_flow_test/BUILD.gn b/test/moduletest/common/ams/app_service_flow_test/BUILD.gn index 7638a9d9c82d14e9e3bea7469a1ae9e472a1edc8..e9e33afe38832b773d7019f1de276f55c5583803 100644 --- a/test/moduletest/common/ams/app_service_flow_test/BUILD.gn +++ b/test/moduletest/common/ams/app_service_flow_test/BUILD.gn @@ -20,6 +20,7 @@ ohos_moduletest("AmsAppServiceFlowModuleTest") { module_out_path = module_output_path include_dirs = [ + "${ability_runtime_test_path}/mock/common/include", "${ability_runtime_path}/interfaces/kits/native/appkit/ability_bundle_manager_helper", "${ability_runtime_test_path}/mock/services_appmgr_test/include", ] diff --git a/test/moduletest/common/ams/app_service_flow_test/ams_app_service_flow_module_test.cpp b/test/moduletest/common/ams/app_service_flow_test/ams_app_service_flow_module_test.cpp index 2f049362c3d6a8adbbe2f8eaf28db46eb626a099..c2ffde83fffbfc3ec733a92a256925bd140bebea 100644 --- a/test/moduletest/common/ams/app_service_flow_test/ams_app_service_flow_module_test.cpp +++ b/test/moduletest/common/ams/app_service_flow_test/ams_app_service_flow_module_test.cpp @@ -13,22 +13,25 @@ * limitations under the License. */ #include - #include -#include "iremote_object.h" -#include "refbase.h" - -#include "app_launch_data.h" #define private public #include "app_mgr_service_inner.h" +#include "iservice_registry.h" #undef private + + +#include "app_launch_data.h" #include "hilog_wrapper.h" -#include "mock_ability_token.h" -#include "mock_bundle_manager.h" +#include "iremote_object.h" #include "mock_ability_token.h" #include "mock_app_scheduler.h" #include "mock_app_spawn_client.h" +#include "mock_bundle_installer_service.h" +#include "mock_bundle_manager_service.h" +#include "mock_system_ability_manager.h" +#include "refbase.h" +#include "singleton.h" using namespace testing::ext; using testing::_; @@ -39,6 +42,9 @@ namespace OHOS { namespace AppExecFwk { namespace { const uint32_t CYCLE_NUMBER = 10; +constexpr int32_t BUNDLE_MGR_SERVICE_SYS_ABILITY_ID = 401; +sptr mockBundleInstaller = new (std::nothrow) MockBundleInstallerService(); +sptr mockBundleMgr = new (std::nothrow) MockBundleManagerService(); } // namespace struct TestApplicationPreRunningRecord { TestApplicationPreRunningRecord( @@ -64,6 +70,9 @@ public: static void TearDownTestCase(); void SetUp(); void TearDown(); + void MockBundleInstallerAndSA() const; + sptr iSystemAbilityMgr_ = nullptr; + sptr mockSystemAbility_ = nullptr; protected: sptr TestCreateApplicationClient(const std::shared_ptr& appRecord) const; @@ -74,7 +83,6 @@ protected: protected: std::shared_ptr serviceInner_ = nullptr; std::shared_ptr handler_ = nullptr; - std::shared_ptr mockBundleMgr_{ nullptr }; }; void AmsAppServiceFlowModuleTest::SetUpTestCase() @@ -92,12 +100,31 @@ void AmsAppServiceFlowModuleTest::SetUp() handler_ = std::make_shared(taskHandler, serviceInner_); serviceInner_->SetTaskHandler(taskHandler); serviceInner_->SetEventHandler(handler_); - mockBundleMgr_ = DelayedSingleton::GetInstance(); - serviceInner_->SetBundleManagerHelper(mockBundleMgr_); + mockSystemAbility_ = new (std::nothrow) AppExecFwk::MockSystemAbilityManager(); + iSystemAbilityMgr_ = SystemAbilityManagerClient::GetInstance().GetSystemAbilityManager(); + SystemAbilityManagerClient::GetInstance().systemAbilityManager_ = mockSystemAbility_; } void AmsAppServiceFlowModuleTest::TearDown() -{} +{ + SystemAbilityManagerClient::GetInstance().systemAbilityManager_ = iSystemAbilityMgr_; +} + +void AmsAppServiceFlowModuleTest::MockBundleInstallerAndSA() const +{ + auto mockGetBundleInstaller = []() { return mockBundleInstaller; }; + auto mockGetSystemAbility = [bms = mockBundleMgr, saMgr = iSystemAbilityMgr_](int32_t systemAbilityId) { + if (systemAbilityId == BUNDLE_MGR_SERVICE_SYS_ABILITY_ID) { + return bms->AsObject(); + } else { + return saMgr->GetSystemAbility(systemAbilityId); + } + }; + EXPECT_CALL(*mockBundleMgr, GetBundleInstaller()).WillOnce(testing::Invoke(mockGetBundleInstaller)); + EXPECT_CALL(*mockSystemAbility_, GetSystemAbility(testing::_)) + .WillOnce(testing::Invoke(mockGetSystemAbility)) + .WillRepeatedly(testing::Invoke(mockGetSystemAbility)); +} sptr AmsAppServiceFlowModuleTest::TestCreateApplicationClient( const std::shared_ptr& appRecord) const @@ -164,6 +191,10 @@ TestApplicationPreRunningRecord AmsAppServiceFlowModuleTest::TestCreateApplicati */ HWTEST_F(AmsAppServiceFlowModuleTest, ServiceFlow_BackKey_001, TestSize.Level1) { + MockBundleInstallerAndSA(); + EXPECT_CALL(*mockBundleMgr, GetHapModuleInfo(testing::_, testing::_, testing::_)) + .WillOnce(testing::Return(true)) + .WillRepeatedly(testing::Return(true)); HILOG_INFO("AmsAppServiceFlowModuleTest ServiceFlow_BackKey_001 start"); sptr abilityA1Token; TestApplicationPreRunningRecord testAppA = TestCreateApplicationRecordAndSetState("abilityA1", "appA", diff --git a/test/unittest/ability_interceptor_test/ability_interceptor_test.cpp b/test/unittest/ability_interceptor_test/ability_interceptor_test.cpp index d72e511a369fbe6717915e3fa45970797dc797cb..0200376d663e915a84103ef4efa7ca818f28dd6b 100644 --- a/test/unittest/ability_interceptor_test/ability_interceptor_test.cpp +++ b/test/unittest/ability_interceptor_test/ability_interceptor_test.cpp @@ -199,7 +199,7 @@ HWTEST_F(AbilityInterceptorTest, ControlInterceptor_005, TestSize.Level1) ElementName element("", "com.test.control", "MainAbility"); want.SetElement(element); int userId = 100; - auto bundleMgrHelper = AbilityUtil::GetBundleManagerHelper(); + auto bundleMgrHelper = DelayedSingleton::GetInstance(); // make appControlRule become nullptr by crowdtest interceptor executer->AddInterceptor(std::make_shared()); executer->AddInterceptor(std::make_shared()); diff --git a/test/unittest/ams_mgr_kill_process_test/ams_mgr_kill_process_test.cpp b/test/unittest/ams_mgr_kill_process_test/ams_mgr_kill_process_test.cpp index f1c3eeb1e4b710f74da59233f101f10dd13da0e6..f91ecbd0a709a39cb5af3205738fcb630d5f728f 100644 --- a/test/unittest/ams_mgr_kill_process_test/ams_mgr_kill_process_test.cpp +++ b/test/unittest/ams_mgr_kill_process_test/ams_mgr_kill_process_test.cpp @@ -65,8 +65,6 @@ std::shared_ptr AmsMgrKillProcessTest::GetAppMgrServiceInner { auto appMgrServiceInner = std::make_shared(); EXPECT_NE(appMgrServiceInner, nullptr); - auto bundleMgr = DelayedSingleton::GetInstance(); - appMgrServiceInner->remoteClientManager_->SetBundleManagerHelper(bundleMgr); return appMgrServiceInner; } diff --git a/test/unittest/ams_mgr_scheduler_test/ams_mgr_scheduler_test.cpp b/test/unittest/ams_mgr_scheduler_test/ams_mgr_scheduler_test.cpp index e7afdd9734d3f3245f3b680f888c96e7ab68ea3b..3459eab61062a95499ad0f13dccc429d478bd6d4 100644 --- a/test/unittest/ams_mgr_scheduler_test/ams_mgr_scheduler_test.cpp +++ b/test/unittest/ams_mgr_scheduler_test/ams_mgr_scheduler_test.cpp @@ -782,9 +782,7 @@ HWTEST_F(AmsMgrSchedulerTest, GetRunningProcessInfoByPid_001, TestSize.Level0) */ HWTEST_F(AmsMgrSchedulerTest, StartSpecifiedAbility_001, TestSize.Level0) { - auto mockBundleMgr = DelayedSingleton::GetInstance(); auto remoteClientManager = std::make_shared(); - remoteClientManager->SetBundleManagerHelper(mockBundleMgr); auto amsMgrServiceInner = std::make_shared(); amsMgrServiceInner->remoteClientManager_ = remoteClientManager; auto amsMgrScheduler = std::make_unique(amsMgrServiceInner, nullptr); diff --git a/test/unittest/app_mgr_service_inner_test/app_mgr_service_inner_test.cpp b/test/unittest/app_mgr_service_inner_test/app_mgr_service_inner_test.cpp index 9364d51f09dd932db7620bd478acb2eb33109044..cb2bafd2e18b8908ea50ad8610b62a0dc564e296 100644 --- a/test/unittest/app_mgr_service_inner_test/app_mgr_service_inner_test.cpp +++ b/test/unittest/app_mgr_service_inner_test/app_mgr_service_inner_test.cpp @@ -379,7 +379,6 @@ HWTEST_F(AppMgrServiceInnerTest, LoadAbility_001, TestSize.Level0) auto appMgrServiceInner1 = std::make_shared(); EXPECT_NE(appMgrServiceInner1, nullptr); - appMgrServiceInner1->remoteClientManager_->SetBundleManagerHelper(nullptr); appMgrServiceInner1->LoadAbility(token, nullptr, abilityInfo_, applicationInfo_, nullptr); auto appMgrServiceInner2 = std::make_shared(); @@ -508,8 +507,6 @@ HWTEST_F(AppMgrServiceInnerTest, GetBundleAndHapInfo_001, TestSize.Level0) HapModuleInfo hapModuleInfo; appMgrServiceInner->GetBundleAndHapInfo(*abilityInfo_, applicationInfo_, bundleInfo, hapModuleInfo, 1); - appMgrServiceInner->remoteClientManager_->SetBundleManagerHelper(nullptr); - appMgrServiceInner->GetBundleAndHapInfo(*abilityInfo_, applicationInfo_, bundleInfo, hapModuleInfo, 1); HILOG_INFO("GetBundleAndHapInfo_001 end"); } @@ -797,9 +794,6 @@ HWTEST_F(AppMgrServiceInnerTest, KillApplicationByUid_001, TestSize.Level0) std::string bundleName = "test_bundleName"; appMgrServiceInner->KillApplicationByUid(bundleName, 0); - appMgrServiceInner->remoteClientManager_->SetBundleManagerHelper(nullptr); - appMgrServiceInner->KillApplicationByUid(bundleName, 0); - appMgrServiceInner->remoteClientManager_ = nullptr; appMgrServiceInner->KillApplicationByUid(bundleName, 0); @@ -846,10 +840,6 @@ HWTEST_F(AppMgrServiceInnerTest, KillApplicationByUserId_001, TestSize.Level0) int result = appMgrServiceInner->KillApplicationByUserId(bundleName, 0); EXPECT_EQ(result, 0); - appMgrServiceInner->remoteClientManager_->SetBundleManagerHelper(nullptr); - appMgrServiceInner->KillApplicationByUserId(bundleName, 0); - EXPECT_EQ(result, 0); - appMgrServiceInner->remoteClientManager_ = nullptr; appMgrServiceInner->KillApplicationByUserId(bundleName, 0); EXPECT_EQ(result, 0); @@ -877,10 +867,6 @@ HWTEST_F(AppMgrServiceInnerTest, KillApplicationByUserIdLocked_001, TestSize.Lev int result = appMgrServiceInner->KillApplicationByUserIdLocked(bundleName, 0); EXPECT_EQ(result, 0); - appMgrServiceInner->remoteClientManager_->SetBundleManagerHelper(nullptr); - appMgrServiceInner->KillApplicationByUserIdLocked(bundleName, 0); - EXPECT_EQ(result, 0); - appMgrServiceInner->remoteClientManager_ = nullptr; appMgrServiceInner->KillApplicationByUserIdLocked(bundleName, 0); EXPECT_EQ(result, 0); @@ -930,9 +916,6 @@ HWTEST_F(AppMgrServiceInnerTest, ClearUpApplicationDataByUserId_001, TestSize.Le appMgrServiceInner->appRunningManager_ = nullptr; appMgrServiceInner->ClearUpApplicationDataByUserId(bundleName, 1, 1, 0); - appMgrServiceInner->remoteClientManager_->SetBundleManagerHelper(nullptr); - appMgrServiceInner->ClearUpApplicationDataByUserId(bundleName, 1, 1, 0); - HILOG_INFO("ClearUpApplicationDataByUserId_001 end"); } @@ -1411,27 +1394,6 @@ HWTEST_F(AppMgrServiceInnerTest, SetAppSpawnClient_001, TestSize.Level0) HILOG_INFO("SetAppSpawnClient_001 end"); } -/** - * @tc.name: SetBundleManager_001 - * @tc.desc: set bundle manager. - * @tc.type: FUNC - * @tc.require: issueI5W4S7 - */ -HWTEST_F(AppMgrServiceInnerTest, SetBundleManager_001, TestSize.Level0) -{ - HILOG_INFO("SetBundleManager_001 start"); - auto appMgrServiceInner = std::make_shared(); - EXPECT_NE(appMgrServiceInner, nullptr); - - std::shared_ptr bundleManager; - appMgrServiceInner->SetBundleManagerHelper(bundleManager); - - appMgrServiceInner->remoteClientManager_ = nullptr; - appMgrServiceInner->SetBundleManagerHelper(bundleManager); - - HILOG_INFO("SetBundleManager_001 end"); -} - /** * @tc.name: RegisterAppStateCallback_001 * @tc.desc: register app state call back. @@ -1739,9 +1701,6 @@ HWTEST_F(AppMgrServiceInnerTest, StartProcess_001, TestSize.Level0) appMgrServiceInner->StartProcess(appName, processName, 0, appRecord, 0, bundleInfo, bundleName, 0, false); appMgrServiceInner->StartProcess(appName, processName, 0, appRecord, 0, bundleInfo, bundleName, 1, false); - appMgrServiceInner->SetBundleManagerHelper(nullptr); - appMgrServiceInner->StartProcess(appName, processName, 0, appRecord, 0, bundleInfo, bundleName, 0); - appMgrServiceInner->SetAppSpawnClient(nullptr); appMgrServiceInner->StartProcess(appName, processName, 0, nullptr, 0, bundleInfo, bundleName, 0); appMgrServiceInner->StartProcess(appName, processName, 0, appRecord, 0, bundleInfo, bundleName, 0); @@ -2186,9 +2145,6 @@ HWTEST_F(AppMgrServiceInnerTest, CheckRemoteClient_001, TestSize.Level0) appMgrServiceInner->remoteClientManager_->SetSpawnClient(nullptr); appMgrServiceInner->CheckRemoteClient(); - appMgrServiceInner->remoteClientManager_->SetBundleManagerHelper(nullptr); - appMgrServiceInner->CheckRemoteClient(); - appMgrServiceInner->remoteClientManager_ = nullptr; appMgrServiceInner->CheckRemoteClient(); @@ -2542,9 +2498,6 @@ HWTEST_F(AppMgrServiceInnerTest, StartSpecifiedAbility_001, TestSize.Level0) abilityInfo_->applicationInfo = *applicationInfo_; appMgrServiceInner->StartSpecifiedAbility(want, *abilityInfo_); - appMgrServiceInner->remoteClientManager_->SetBundleManagerHelper(nullptr); - appMgrServiceInner->StartSpecifiedAbility(want, *abilityInfo_); - appMgrServiceInner->remoteClientManager_ = nullptr; appMgrServiceInner->StartSpecifiedAbility(want, *abilityInfo_); @@ -3365,10 +3318,6 @@ HWTEST_F(AppMgrServiceInnerTest, GetRunningProcessInformation_001, TestSize.Leve int32_t ret = appMgrServiceInner->GetRunningProcessInformation(bundleName, userId, info); EXPECT_EQ(ret, ERR_OK); - appMgrServiceInner->remoteClientManager_ = nullptr; - ret = appMgrServiceInner->GetRunningProcessInformation(bundleName, userId, info); - EXPECT_EQ(ret, ERR_NO_INIT); - appMgrServiceInner->appRunningManager_ = nullptr; ret = appMgrServiceInner->GetRunningProcessInformation(bundleName, userId, info); EXPECT_EQ(ret, ERR_NO_INIT); diff --git a/test/unittest/app_running_processes_info_test/app_running_processes_info_test.cpp b/test/unittest/app_running_processes_info_test/app_running_processes_info_test.cpp index c09b3b072c53e812f10576c91556f58bd87e2ca0..2f138f4a12329b27257cba772e8abae4a062d90e 100644 --- a/test/unittest/app_running_processes_info_test/app_running_processes_info_test.cpp +++ b/test/unittest/app_running_processes_info_test/app_running_processes_info_test.cpp @@ -67,8 +67,6 @@ public: void MockBundleInstaller(); sptr iSystemAbilityMgr_ = nullptr; sptr mockSystemAbility_ = nullptr; - std::shared_ptr bundleMgrClient = - DelayedSingleton::GetInstance(); protected: static const std::string GetTestProcessName() @@ -126,7 +124,6 @@ void AppRunningProcessesInfoTest::SetUp() mockSystemAbility_ = new (std::nothrow) AppExecFwk::MockSystemAbilityManager(); iSystemAbilityMgr_ = SystemAbilityManagerClient::GetInstance().GetSystemAbilityManager(); SystemAbilityManagerClient::GetInstance().systemAbilityManager_ = mockSystemAbility_; - service_->SetBundleManagerHelper(bundleMgrClient); } void AppRunningProcessesInfoTest::TearDown()