From b090de04680fdeaa57f1883b8e8526b621624ed9 Mon Sep 17 00:00:00 2001 From: luopengtao Date: Wed, 29 Nov 2023 11:59:47 +0000 Subject: [PATCH 1/3] =?UTF-8?q?=E4=BD=BF=E7=94=A8ProcessStateChanged?= =?UTF-8?q?=E5=9B=9E=E8=B0=83=20=E6=9B=BF=E4=BB=A3=20onForegroundApplicati?= =?UTF-8?q?onChanged?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: luopengtao --- .../sched_controller/app_state_observer.cpp | 12 ---------- .../sched_controller/cgroup_adjuster.cpp | 8 +++---- .../sched_controller/cgroup_event_handler.cpp | 22 ++++--------------- .../include/cgroup_adjuster.h | 1 + .../include/cgroup_event_handler.h | 1 - 5 files changed, 9 insertions(+), 35 deletions(-) diff --git a/cgroup_sched/framework/sched_controller/app_state_observer.cpp b/cgroup_sched/framework/sched_controller/app_state_observer.cpp index 8b8490a0..5f68eed4 100644 --- a/cgroup_sched/framework/sched_controller/app_state_observer.cpp +++ b/cgroup_sched/framework/sched_controller/app_state_observer.cpp @@ -34,18 +34,6 @@ void RmsApplicationStateObserver::OnForegroundApplicationChanged(const AppStateD CGS_LOGE("%{public}s : validate app state data failed!", __func__); return; } - auto cgHandler = SchedController::GetInstance().GetCgroupEventHandler(); - if (cgHandler) { - auto uid = appStateData.uid; - auto bundleName = appStateData.bundleName; - auto state = appStateData.state; - auto pid = appStateData.pid; - - cgHandler->Submit([cgHandler, uid, pid, bundleName, state] { - cgHandler->HandleForegroundApplicationChanged(uid, pid, bundleName, state); - }); - } - nlohmann::json payload; payload["pid"] = std::to_string(appStateData.pid); payload["uid"] = std::to_string(appStateData.uid); diff --git a/cgroup_sched/framework/sched_controller/cgroup_adjuster.cpp b/cgroup_sched/framework/sched_controller/cgroup_adjuster.cpp index ff511cdb..38d9f638 100644 --- a/cgroup_sched/framework/sched_controller/cgroup_adjuster.cpp +++ b/cgroup_sched/framework/sched_controller/cgroup_adjuster.cpp @@ -122,20 +122,20 @@ void CgroupAdjuster::ComputeProcessGroup(Application &app, ProcessRecord &pr, Ad } else { if (pr.abilities_.size() == 0) { group = SP_DEFAULT; - if (app.state_ == (int32_t)ApplicationState::APP_STATE_BACKGROUND) { + if (pr.processState_ == (int32_t)ApplicationState::APP_STATE_BACKGROUND) { group = SP_BACKGROUND; } } else if (pr.IsVisible()) { group = SP_FOREGROUND; } else if (pr.HasServiceExtension()) { group = SP_DEFAULT; - if (app.state_ == (int32_t)ApplicationState::APP_STATE_BACKGROUND) { + if (pr.processState_ == (int32_t)ApplicationState::APP_STATE_BACKGROUND) { group = SP_BACKGROUND; } } else { - if (app.state_ == (int32_t)ApplicationState::APP_STATE_BACKGROUND) { + if (pr.processState_ == (int32_t)ApplicationState::APP_STATE_BACKGROUND) { group = SP_BACKGROUND; - } else if (app.state_ == (int32_t)ApplicationState::APP_STATE_FOREGROUND) { + } else if (pr.processState_ == (int32_t)ApplicationState::APP_STATE_FOREGROUND) { group = SP_FOREGROUND; } else { group = SP_DEFAULT; diff --git a/cgroup_sched/framework/sched_controller/cgroup_event_handler.cpp b/cgroup_sched/framework/sched_controller/cgroup_event_handler.cpp index bae3d194..b5f743f7 100644 --- a/cgroup_sched/framework/sched_controller/cgroup_event_handler.cpp +++ b/cgroup_sched/framework/sched_controller/cgroup_event_handler.cpp @@ -187,23 +187,6 @@ void CgroupEventHandler::HandleAbilityRemoved(int32_t saId, const std::string& d } } -void CgroupEventHandler::HandleForegroundApplicationChanged(uid_t uid, pid_t pid, - const std::string& bundleName, int32_t state) -{ - if (!supervisor_) { - CGS_LOGE("%{public}s : supervisor nullptr!", __func__); - return; - } - CGS_LOGD("%{public}s : %{public}d, %{public}s, %{public}d", __func__, uid, bundleName.c_str(), state); - ChronoScope cs("HandleForegroundApplicationChanged"); - std::shared_ptr app = supervisor_->GetAppRecordNonNull(uid); - std::shared_ptr procRecord = app->GetProcessRecordNonNull(pid); - app->SetName(bundleName); - app->state_ = state; - app->SetMainProcess(procRecord); - CgroupAdjuster::GetInstance().AdjustAllProcessGroup(*(app.get()), AdjustSource::ADJS_FG_APP_CHANGE); -} - void CgroupEventHandler::HandleApplicationStateChanged(uid_t uid, pid_t pid, const std::string& bundleName, int32_t state) { @@ -232,11 +215,14 @@ void CgroupEventHandler::HandleProcessStateChanged(uid_t uid, pid_t pid, CGS_LOGE("%{public}s : supervisor nullptr!", __func__); return; } - CGS_LOGD("%{public}s : %{public}d, %{public}s, %{public}d", __func__, uid, bundleName.c_str(), state); + CGS_LOGD("%{public}s : %{public}d, %{public}s, %{public}d, %{public}d", __func__, uid, + pid,bundleName.c_str(), state); ChronoScope cs("HandleProcessStateChanged"); std::shared_ptr app = supervisor_->GetAppRecordNonNull(uid); std::shared_ptr procRecord = app->GetProcessRecordNonNull(pid); procRecord->processState_ = state; + CgroupAdjuster::GetInstance().AdjustProcessGroup(*(app.get()), *(procRecord.get()), + AdjustSource::ADJS_PROCESS_STATE); } void CgroupEventHandler::HandleAbilityStateChanged(uid_t uid, pid_t pid, const std::string& bundleName, diff --git a/cgroup_sched/framework/sched_controller/include/cgroup_adjuster.h b/cgroup_sched/framework/sched_controller/include/cgroup_adjuster.h index 1310555d..1cbb15a9 100644 --- a/cgroup_sched/framework/sched_controller/include/cgroup_adjuster.h +++ b/cgroup_sched/framework/sched_controller/include/cgroup_adjuster.h @@ -44,6 +44,7 @@ enum class AdjustSource { ADJS_REPORT_WEBVIEW_STATE_CHANGED, ADJS_REPORT_ENTER_NAP, ADJS_REPORT_EXIT_NAP, + ADJS_PROCESS_STATE, ADJS_END }; diff --git a/cgroup_sched/framework/sched_controller/include/cgroup_event_handler.h b/cgroup_sched/framework/sched_controller/include/cgroup_event_handler.h index 365fe3b4..ceb2be6d 100644 --- a/cgroup_sched/framework/sched_controller/include/cgroup_event_handler.h +++ b/cgroup_sched/framework/sched_controller/include/cgroup_event_handler.h @@ -37,7 +37,6 @@ public: void RemoveAllEvents(); void HandleAbilityAdded(int32_t saId, const std::string& deviceId); void HandleAbilityRemoved(int32_t saId, const std::string& deviceId); - void HandleForegroundApplicationChanged(uid_t uid, pid_t pid, const std::string& bundleName, int32_t state); void HandleApplicationStateChanged(uid_t uid, pid_t pid, const std::string& bundleName, int32_t state); void HandleProcessStateChanged(uid_t uid, pid_t pid, const std::string& bundleName, int32_t state); void HandleAbilityStateChanged(uid_t uid, pid_t pid, const std::string& bundleName, -- Gitee From bd6c0496d4efe33c93752fe84bb4d259edca8bd2 Mon Sep 17 00:00:00 2001 From: luopengtao Date: Wed, 29 Nov 2023 12:03:38 +0000 Subject: [PATCH 2/3] update cgroup_sched/framework/sched_controller/cgroup_event_handler.cpp. Signed-off-by: luopengtao --- .../framework/sched_controller/cgroup_event_handler.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cgroup_sched/framework/sched_controller/cgroup_event_handler.cpp b/cgroup_sched/framework/sched_controller/cgroup_event_handler.cpp index b5f743f7..13baa560 100644 --- a/cgroup_sched/framework/sched_controller/cgroup_event_handler.cpp +++ b/cgroup_sched/framework/sched_controller/cgroup_event_handler.cpp @@ -216,7 +216,7 @@ void CgroupEventHandler::HandleProcessStateChanged(uid_t uid, pid_t pid, return; } CGS_LOGD("%{public}s : %{public}d, %{public}s, %{public}d, %{public}d", __func__, uid, - pid,bundleName.c_str(), state); + pid, bundleName.c_str(), state); ChronoScope cs("HandleProcessStateChanged"); std::shared_ptr app = supervisor_->GetAppRecordNonNull(uid); std::shared_ptr procRecord = app->GetProcessRecordNonNull(pid); -- Gitee From 2d30a4c13d76309d85d3c6a28744ba4beadddedc Mon Sep 17 00:00:00 2001 From: luopengtao Date: Wed, 29 Nov 2023 12:50:16 +0000 Subject: [PATCH 3/3] update cgroup_sched/framework/sched_controller/cgroup_event_handler.cpp. Signed-off-by: luopengtao --- .../framework/sched_controller/cgroup_event_handler.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cgroup_sched/framework/sched_controller/cgroup_event_handler.cpp b/cgroup_sched/framework/sched_controller/cgroup_event_handler.cpp index 13baa560..36f53102 100644 --- a/cgroup_sched/framework/sched_controller/cgroup_event_handler.cpp +++ b/cgroup_sched/framework/sched_controller/cgroup_event_handler.cpp @@ -215,7 +215,7 @@ void CgroupEventHandler::HandleProcessStateChanged(uid_t uid, pid_t pid, CGS_LOGE("%{public}s : supervisor nullptr!", __func__); return; } - CGS_LOGD("%{public}s : %{public}d, %{public}s, %{public}d, %{public}d", __func__, uid, + CGS_LOGD("%{public}s : %{public}d, %{public}d, %{public}s, %{public}d", __func__, uid, pid, bundleName.c_str(), state); ChronoScope cs("HandleProcessStateChanged"); std::shared_ptr app = supervisor_->GetAppRecordNonNull(uid); -- Gitee