diff --git a/services/abilitymgr/src/scene_board/ui_ability_lifecycle_manager.cpp b/services/abilitymgr/src/scene_board/ui_ability_lifecycle_manager.cpp index ff330f7903c95ee5b50429000795b70f890e8a5e..43c1db2d30a49cef051b51a580f6560fef1b2cae 100644 --- a/services/abilitymgr/src/scene_board/ui_ability_lifecycle_manager.cpp +++ b/services/abilitymgr/src/scene_board/ui_ability_lifecycle_manager.cpp @@ -2266,7 +2266,8 @@ int32_t UIAbilityLifecycleManager::StartSpecifiedProcessRequest(const AbilityReq auto isCreating = abilityRequest.want.GetBoolParam(Want::CREATE_APP_INSTANCE_KEY, false); const auto &abilityInfo = abilityRequest.abilityInfo; auto sceneSessionManager = Rosen::SessionManagerLite::GetInstance().GetSceneSessionManagerLiteProxy(); - if (abilityInfo.applicationInfo.multiAppMode.multiAppModeType == AppExecFwk::MultiAppModeType::MULTI_INSTANCE && + if (AppUtils::GetInstance().InOnNewProcessEnableList(abilityRequest.abilityInfo.bundleName) && + abilityInfo.applicationInfo.multiAppMode.multiAppModeType == AppExecFwk::MultiAppModeType::MULTI_INSTANCE && isCreating && sceneSessionManager != nullptr) { std::string instanceKey; Rosen::WMError ret = sceneSessionManager->CreateNewInstanceKey(abilityRequest.want.GetBundle(), instanceKey); diff --git a/services/appmgr/src/app_mgr_service_inner.cpp b/services/appmgr/src/app_mgr_service_inner.cpp index d096db2f29af72a414d3fd4c555ead06c08de468..e625fd3efd32af146707850755763428523858b0 100644 --- a/services/appmgr/src/app_mgr_service_inner.cpp +++ b/services/appmgr/src/app_mgr_service_inner.cpp @@ -500,31 +500,33 @@ void AppMgrServiceInner::StartSpecifiedProcess(const AAFwk::Want &want, const Ap } std::shared_ptr appRecord = nullptr; TAG_LOGI(AAFwkTag::APPMGR, "main process do not exists."); - if (abilityInfo.type == AppExecFwk::AbilityType::PAGE) { - appRecord = - appRunningManager_->CheckAppRunningRecordForSpecifiedProcess(appInfo->uid, instanceKey, customProcessFlag); - } else { - appRecord = - appRunningManager_->CheckAppRunningRecordForUIExtension(appInfo->uid, instanceKey, customProcessFlag); - } - if (appRecord != nullptr) { - TAG_LOGI(AAFwkTag::APPMGR, "starting process [%{public}s]", processName.c_str()); - AbilityRuntime::LoadParam loadParam; - loadParam.instanceKey = instanceKey; - auto newAppRecord = CreateAppRunningRecord(std::make_shared(loadParam), - appInfo, std::make_shared(abilityInfo), processName, bundleInfo, hapModuleInfo, - std::make_shared(want), false); - if (newAppRecord == nullptr) { - TAG_LOGE(AAFwkTag::APPMGR, "create new appRecord failed"); + if (AppUtils::GetInstance().InOnNewProcessEnableList(bundleInfo.name)) { + if (abilityInfo.type == AppExecFwk::AbilityType::PAGE) { + appRecord = + appRunningManager_->CheckAppRunningRecordForSpecifiedProcess(appInfo->uid, instanceKey, customProcessFlag); + } else { + appRecord = + appRunningManager_->CheckAppRunningRecordForUIExtension(appInfo->uid, instanceKey, customProcessFlag); + } + if (appRecord != nullptr) { + TAG_LOGI(AAFwkTag::APPMGR, "starting process [%{public}s]", processName.c_str()); + AbilityRuntime::LoadParam loadParam; + loadParam.instanceKey = instanceKey; + auto newAppRecord = CreateAppRunningRecord(std::make_shared(loadParam), + appInfo, std::make_shared(abilityInfo), processName, bundleInfo, hapModuleInfo, + std::make_shared(want), false); + if (newAppRecord == nullptr) { + TAG_LOGE(AAFwkTag::APPMGR, "create new appRecord failed"); + return; + } + newAppRecord->SetMasterProcess(true); + newAppRecord->SetScheduleNewProcessRequestState(requestId, want, hapModuleInfo.moduleName); + bool appExistFlag = appRunningManager_->IsAppExist(bundleInfo.applicationInfo.accessTokenId); + auto ret = StartProcess(abilityInfo.applicationName, processName, 0, newAppRecord, + appInfo->uid, bundleInfo, appInfo->bundleName, 0, appExistFlag); + TAG_LOGI(AAFwkTag::APPMGR, "start process ret %{public}d, schedule new process request", ret); return; } - newAppRecord->SetMasterProcess(true); - newAppRecord->SetScheduleNewProcessRequestState(requestId, want, hapModuleInfo.moduleName); - bool appExistFlag = appRunningManager_->IsAppExist(bundleInfo.applicationInfo.accessTokenId); - auto ret = StartProcess(abilityInfo.applicationName, processName, 0, newAppRecord, - appInfo->uid, bundleInfo, appInfo->bundleName, 0, appExistFlag); - TAG_LOGI(AAFwkTag::APPMGR, "start process ret %{public}d, schedule new process request", ret); - return; } if (startSpecifiedAbilityResponse_) { startSpecifiedAbilityResponse_->OnNewProcessRequestResponse("", requestId); diff --git a/services/common/include/app_utils.h b/services/common/include/app_utils.h index d89cfbafc692f5cf6e1026c2b5320ad7d7a81189..e488a9148ac85b5b49a222cc129cf7b455a8c843 100644 --- a/services/common/include/app_utils.h +++ b/services/common/include/app_utils.h @@ -340,6 +340,8 @@ public: const std::vector &GetResidentWhiteList(); + bool InOnNewProcessEnableList(const std::string &bundleName); + private: /** * LoadResidentProcessInExtremeMemory, load resident process in extreme low memory. @@ -389,6 +391,12 @@ private: */ void LoadResidentWhiteList(); + /** + * LoadOnNewProcessEnableList, load on new process enable list. + * + */ + void LoadOnNewProcessEnableList(); + /** * AppUtils, private constructor. * @@ -441,6 +449,8 @@ private: cacheAbilityList_ = {false, {}}; DeviceConfiguration> residentWhiteList_ = {false, {}}; std::mutex residentWhiteListMutex_; + DeviceConfiguration> onNewProcessEnableList_ = {false, {}}; + std::mutex onNewProcessEnableListMutex_; DISALLOW_COPY_AND_MOVE(AppUtils); }; } // namespace AAFwk diff --git a/services/common/src/app_utils.cpp b/services/common/src/app_utils.cpp index 144dc9cd0050ec107a3b57ebb0d3d9b388eecf00..9dbbaa0b052e7522d218f4de3420f6b534f2a441 100644 --- a/services/common/src/app_utils.cpp +++ b/services/common/src/app_utils.cpp @@ -90,6 +90,8 @@ constexpr const char* CACHE_ABILITY_LIST_PATH = "etc/ability/abilityms_cache_abi constexpr const char* CACHE_PROCESS_NAME = "cache_list"; constexpr const char* RESIDENT_WHITE_LIST_PATH = "etc/ability_runtime/resident_process.json"; constexpr const char* NORMAL_RESIDENT_APPS = "normal_resident_apps"; +constexpr const char* ON_NEW_PROCESS_ENABLE_LIST_PATH = "etc/ability_runtime/on_new_process_enable_list.json"; +constexpr const char* ON_NEW_PROCESS_ENABLE_LIST = "onNewProcessEnableList"; } AppUtils::~AppUtils() {} @@ -838,6 +840,45 @@ bool AppUtils::InResidentWhiteList(const std::string &bundleName) return false; } +void AppUtils::LoadOnNewProcessEnableList() +{ + cJSON *object = nullptr; + if (!JsonUtils::GetInstance().LoadConfiguration(ON_NEW_PROCESS_ENABLE_LIST_PATH, object)) { + TAG_LOGI(AAFwkTag::ABILITYMGR, "load onNewProcessEnableList file failed"); + return; + } + cJSON *onNewProcessEnableListItem = cJSON_GetObjectItem(object, ON_NEW_PROCESS_ENABLE_LIST); + if (onNewProcessEnableListItem == nullptr || !cJSON_IsArray(onNewProcessEnableListItem)) { + TAG_LOGE(AAFwkTag::ABILITYMGR, "onNewProcessEnableList file invalid"); + return; + } + int size = cJSON_GetArraySize(onNewProcessEnableListItem); + for (int i = 0; i < size; i++) { + cJSON *jsonObject = cJSON_GetArrayItem(onNewProcessEnableListItem, i); + if (jsonObject == nullptr || !cJSON_IsString(jsonObject)) { + TAG_LOGE(AAFwkTag::ABILITYMGR, "load onNewProcessEnableList bundleName failed"); + return; + } + std::string jsonStr = jsonObject->valuestring; + onNewProcessEnableList_.value.emplace_back(jsonStr); + } +} + +bool AppUtils::InOnNewProcessEnableList(const std::string &bundleName) +{ + std::lock_guard lock(onNewProcessEnableListMutex_); + if (!onNewProcessEnableList_.isLoaded) { + LoadOnNewProcessEnableList(); + onNewProcessEnableList_.isLoaded = true; + } + for (const auto &item: residentWhiteList_.value) { + if (bundleName == item) { + return true; + } + } + return false; +} + bool AppUtils::IsSupportAppServiceExtension() { if (!isSupportAppServiceExtension_.isLoaded) { diff --git a/test/unittest/app_utils_test/app_utils_test.cpp b/test/unittest/app_utils_test/app_utils_test.cpp index 07cde8bd39b9a1a892eb83d59a81d8abd63f16ad..68692ed6406960065f482ecf6773d04a23ba971e 100644 --- a/test/unittest/app_utils_test/app_utils_test.cpp +++ b/test/unittest/app_utils_test/app_utils_test.cpp @@ -932,5 +932,31 @@ HWTEST_F(AppUtilsTest, AppUtilsTest_4100, TestSize.Level2) auto isSupportNativeChildProcess = appUtils.IsSupportNativeChildProcess(); EXPECT_TRUE(isSupportNativeChildProcess); } + +/** + * @tc.number: InOnNewProcessEnableList_0100 + * @tc.desc: Test InOnNewProcessEnableList works + * @tc.type: FUNC + */ +HWTEST_F(AppUtilsTest, InOnNewProcessEnableList_0100, TestSize.Level2) +{ + TAG_LOGI(AAFwkTag::TEST, "InOnNewProcessEnableList_0100 called."); + auto &appUtils = AAFwk::AppUtils::GetInstance(); + bool result = appUtils.GetOnNewProcessEnableList(); + EXPECT_FALSE(result); +} + +/** + * @tc.number: InOnNewProcessEnableList_0200 + * @tc.desc: Test InOnNewProcessEnableList works + * @tc.type: FUNC + */ +HWTEST_F(AppUtilsTest, InOnNewProcessEnableList_0200, TestSize.Level2) +{ + TAG_LOGI(AAFwkTag::TEST, "InOnNewProcessEnableList_0200 called."); + auto &appUtils = AAFwk::AppUtils::GetInstance(); + bool result = appUtils.GetOnNewProcessEnableList(); + EXPECT_FALSE(result); +} } // namespace AbilityRuntime } // namespace OHOS