From 8e04a5fc5bf9b39baca4b94c4bbfb0fdbe35bcba Mon Sep 17 00:00:00 2001 From: jsjzju Date: Wed, 14 Aug 2024 00:47:53 +0800 Subject: [PATCH] =?UTF-8?q?=E9=98=B2=E6=AD=A2=E5=BA=94=E7=94=A8=E4=BC=AA?= =?UTF-8?q?=E9=80=A0=E8=AF=B7=E6=B1=82=E6=94=B9=E5=8F=98=E5=BA=94=E7=94=A8?= =?UTF-8?q?=E7=8A=B6=E6=80=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: jsjzju Change-Id: I02fb676d0a035f73acfe5f3fdbaf700f410d2285 --- .../app_manager/include/appmgr/app_mgr_constants.h | 6 ++++++ services/appmgr/include/app_running_record.h | 4 ++++ services/appmgr/src/app_mgr_service_inner.cpp | 12 ++++++++++++ services/appmgr/src/app_running_record.cpp | 12 ++++++++++++ 4 files changed, 34 insertions(+) diff --git a/interfaces/inner_api/app_manager/include/appmgr/app_mgr_constants.h b/interfaces/inner_api/app_manager/include/appmgr/app_mgr_constants.h index 6ada3e6844c..3b69fa094cf 100644 --- a/interfaces/inner_api/app_manager/include/appmgr/app_mgr_constants.h +++ b/interfaces/inner_api/app_manager/include/appmgr/app_mgr_constants.h @@ -40,6 +40,12 @@ enum class ApplicationPendingState { BACKGROUNDING, }; +enum class ApplicationScheduleState { + SCHEDULE_READY = 0, + SCHEDULE_FOREGROUNDING, + SCHEDULE_BACKGROUNDING, +}; + enum class AbilityState { ABILITY_STATE_CREATE = 0, ABILITY_STATE_READY, diff --git a/services/appmgr/include/app_running_record.h b/services/appmgr/include/app_running_record.h index 93cb3e6e422..c821f299270 100644 --- a/services/appmgr/include/app_running_record.h +++ b/services/appmgr/include/app_running_record.h @@ -732,6 +732,9 @@ public: void SetApplicationPendingState(ApplicationPendingState pendingState); ApplicationPendingState GetApplicationPendingState() const; + void SetApplicationScheduleState(ApplicationScheduleState scheduleState); + ApplicationScheduleState GetApplicationScheduleState() const; + void GetSplitModeAndFloatingMode(bool &isSplitScreenMode, bool &isFloatingWindowMode); void AddChildProcessRecord(pid_t pid, const std::shared_ptr record); @@ -900,6 +903,7 @@ private: bool isStageBasedModel_ = false; ApplicationState curState_ = ApplicationState::APP_STATE_CREATE; // current state of this process ApplicationPendingState pendingState_ = ApplicationPendingState::READY; + ApplicationScheduleState scheduleState_ = ApplicationScheduleState::SCHEDULE_READY; bool isFocused_ = false; // if process is focused. /** * If there is an ability is foregrounding, this flag will be true, diff --git a/services/appmgr/src/app_mgr_service_inner.cpp b/services/appmgr/src/app_mgr_service_inner.cpp index 8a46819a4db..5679039f201 100644 --- a/services/appmgr/src/app_mgr_service_inner.cpp +++ b/services/appmgr/src/app_mgr_service_inner.cpp @@ -997,6 +997,12 @@ void AppMgrServiceInner::ApplicationForegrounded(const int32_t recordId) TAG_LOGE(AAFwkTag::APPMGR, "get app record failed"); return; } + // Prevent forged requests from changing the app's state. + if (appRecord->GetApplicationScheduleState() != ApplicationScheduleState::SCHEDULE_FOREGROUNDING) { + TAG_LOGE(AAFwkTag::APPMGR, "app is not scheduling to foreground."); + return; + } + appRecord->SetApplicationScheduleState(ApplicationScheduleState::SCHEDULE_READY); ApplicationState appState = appRecord->GetState(); if (appState == ApplicationState::APP_STATE_READY || appState == ApplicationState::APP_STATE_BACKGROUND) { if (appState == ApplicationState::APP_STATE_BACKGROUND) { @@ -1037,6 +1043,12 @@ void AppMgrServiceInner::ApplicationBackgrounded(const int32_t recordId) TAG_LOGE(AAFwkTag::APPMGR, "get app record failed"); return; } + // Prevent forged requests from changing the app's state. + if (appRecord->GetApplicationScheduleState() != ApplicationScheduleState::SCHEDULE_BACKGROUNDING) { + TAG_LOGE(AAFwkTag::APPMGR, "app is not scheduling to background."); + return; + } + appRecord->SetApplicationScheduleState(ApplicationScheduleState::SCHEDULE_READY); if (appRecord->GetState() == ApplicationState::APP_STATE_FOREGROUND) { appRecord->SetState(ApplicationState::APP_STATE_BACKGROUND); bool needNotifyApp = !AAFwk::UIExtensionUtils::IsUIExtension(appRecord->GetExtensionType()) diff --git a/services/appmgr/src/app_running_record.cpp b/services/appmgr/src/app_running_record.cpp index 33d3b612097..b14938bb5e9 100644 --- a/services/appmgr/src/app_running_record.cpp +++ b/services/appmgr/src/app_running_record.cpp @@ -632,6 +632,7 @@ void AppRunningRecord::LaunchPendingAbilities() } void AppRunningRecord::ScheduleForegroundRunning() { + SetApplicationScheduleState(ApplicationScheduleState::SCHEDULE_FOREGROUNDING); if (appLifeCycleDeal_) { appLifeCycleDeal_->ScheduleForegroundRunning(); } @@ -639,6 +640,7 @@ void AppRunningRecord::ScheduleForegroundRunning() void AppRunningRecord::ScheduleBackgroundRunning() { + SetApplicationScheduleState(ApplicationScheduleState::SCHEDULE_BACKGROUNDING); int32_t recordId = GetRecordId(); auto serviceInner = appMgrServiceInner_; auto appbackgroundtask = [recordId, serviceInner]() { @@ -2120,6 +2122,16 @@ ApplicationPendingState AppRunningRecord::GetApplicationPendingState() const return pendingState_; } +void AppRunningRecord::SetApplicationScheduleState(ApplicationScheduleState scheduleState) +{ + scheduleState_ = scheduleState; +} + +ApplicationScheduleState AppRunningRecord::GetApplicationScheduleState() const +{ + return scheduleState_; +} + void AppRunningRecord::AddChildProcessRecord(pid_t pid, const std::shared_ptr record) { if (!record) { -- Gitee