diff --git a/cgroup_sched/framework/sched_controller/app_state_observer.cpp b/cgroup_sched/framework/sched_controller/app_state_observer.cpp index 8b8490a04c5351a8afa1a37e1475eb00db20479f..5f68eed49f4b09c890a0705cfbd0dc036e735eae 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 ff511cdbaafe93395a8fc7a7c56ea83ad6e72676..38d9f638f5c30e24bccdcfe0ee90424aea526e29 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 bae3d194f21d95d52047170a4b96f15a586c5bae..36f53102aea96d385bc4f352ff45bbb389269ded 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}d, %{public}s, %{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 1310555dea77df02c9bd53d997dd653f0a8e7b77..1cbb15a9dd44f4e966c102289210dce359b90103 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 365fe3b49f94a4abbdefc41621bc75ad58dd7b26..ceb2be6dd235bd4da7438b50a7b76cf6aa05919f 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,