diff --git a/services/appmgr/include/app_running_record.h b/services/appmgr/include/app_running_record.h index a470a7bc75..428d9a2b7d 100644 --- a/services/appmgr/include/app_running_record.h +++ b/services/appmgr/include/app_running_record.h @@ -542,12 +542,16 @@ public: bool IsEmptyKeepAliveApp() const; + bool IsMainProcess() const; + void SetEmptyKeepAliveAppState(bool isEmptyKeepAliveApp); void SetKeepAliveEnableState(bool isKeepAliveEnable); void SetSingleton(bool isSingleton); + void SetMainProcess(bool isMainProcess); + void SetStageModelState(bool isStageBasedModel); std::list> GetAllModuleRecord() const; @@ -849,6 +853,7 @@ private: bool isKeepAliveApp_ = false; // Only resident processes can be set to true, please choose carefully bool isEmptyKeepAliveApp_ = false; // Only empty resident processes can be set to true, please choose carefully + bool isMainProcess_ = true; // Only MainProcess can be keepalive bool isSingleton_ = false; bool isStageBasedModel_ = false; ApplicationState curState_ = ApplicationState::APP_STATE_CREATE; // current state of this process diff --git a/services/appmgr/src/app_mgr_service_inner.cpp b/services/appmgr/src/app_mgr_service_inner.cpp index 8ece2189a0..1db81bd8ce 100644 --- a/services/appmgr/src/app_mgr_service_inner.cpp +++ b/services/appmgr/src/app_mgr_service_inner.cpp @@ -634,6 +634,7 @@ void AppMgrServiceInner::LoadAbilityNoAppRecord(const std::shared_ptrSetEmptyKeepAliveAppState(false); + appRecord->SetMainProcess(false); TAG_LOGI(AAFwkTag::APPMGR, "The process %{public}s will not keepalive", hapModuleInfo.process.c_str()); } // As taskHandler_ is busy now, the task should be submit to other task queue. @@ -3775,6 +3776,7 @@ void AppMgrServiceInner::StartSpecifiedAbility(const AAFwk::Want &want, const Ap } if (hapModuleInfo.isStageBasedModel && !IsMainProcess(appInfo, hapModuleInfo)) { appRecord->SetEmptyKeepAliveAppState(false); + appRecord->SetMainProcess(false); TAG_LOGD(AAFwkTag::APPMGR, "The process %{public}s will not keepalive", hapModuleInfo.process.c_str()); } auto wantPtr = std::make_shared(want); diff --git a/services/appmgr/src/app_running_record.cpp b/services/appmgr/src/app_running_record.cpp index 8e3cf63c57..515017ac16 100644 --- a/services/appmgr/src/app_running_record.cpp +++ b/services/appmgr/src/app_running_record.cpp @@ -1370,7 +1370,7 @@ bool AppRunningRecord::IsTerminating() bool AppRunningRecord::IsKeepAliveApp() const { - return isKeepAliveApp_ && isSingleton_; + return isKeepAliveApp_ && isSingleton_ && isMainProcess_; } void AppRunningRecord::SetKeepAliveEnableState(bool isKeepAliveEnable) @@ -1388,6 +1388,16 @@ void AppRunningRecord::SetEmptyKeepAliveAppState(bool isEmptyKeepAliveApp) isEmptyKeepAliveApp_ = isEmptyKeepAliveApp; } +bool AppRunningRecord::IsMainProcess() const +{ + return isMainProcess_; +} + +void AppRunningRecord::SetMainProcess(bool isMainProcess) +{ + isMainProcess_ = isMainProcess; +} + void AppRunningRecord::SetSingleton(bool isSingleton) { isSingleton_ = isSingleton;