From 66d85356e4675cfbd23a99c1d1ccf6de3aeabefe Mon Sep 17 00:00:00 2001 From: edwardcaoyue Date: Thu, 16 Nov 2023 15:31:51 +0800 Subject: [PATCH] add focus status Signed-off-by: edwardcaoyue --- .../include/concurrent_task_type.h | 3 +- services/include/concurrent_task_controller.h | 1 + services/include/qos_interface.h | 9 ++-- services/src/concurrent_task_controller.cpp | 43 +++++++++++++++---- services/src/qos_interface.cpp | 14 ++---- services/src/qos_policy.cpp | 33 ++++++++++++-- .../phone/concurrent_task_controller_test.cpp | 2 + test/unittest/phone/qos_interface_test.cpp | 4 +- 8 files changed, 79 insertions(+), 30 deletions(-) diff --git a/frameworks/concurrent_task_client/include/concurrent_task_type.h b/frameworks/concurrent_task_client/include/concurrent_task_type.h index b8171eb..520c13e 100644 --- a/frameworks/concurrent_task_client/include/concurrent_task_type.h +++ b/frameworks/concurrent_task_client/include/concurrent_task_type.h @@ -26,7 +26,8 @@ enum MsgType { MSG_APP_KILLED, MSG_CONTINUOUS_TASK_START, MSG_CONTINUOUS_TASK_END, - MSG_FOCUS, + MSG_GET_FOCUS, + MSG_LOSE_FOCUS, MSG_AUTH_REQUEST, MSG_SYSTEM_MAX, MSG_APP_START_TYPE = 100, diff --git a/services/include/concurrent_task_controller.h b/services/include/concurrent_task_controller.h index b8bdc81..13cbd77 100644 --- a/services/include/concurrent_task_controller.h +++ b/services/include/concurrent_task_controller.h @@ -57,6 +57,7 @@ private: void NewAppStart(int uid, int pid); void AppKilled(int uid, int pid); void ContinuousTaskProcess(int uid, int pid, int status); + void FocusStatusProcess(int uid, int pid, int status); void AuthRequestProcess(int uid, int pid); bool ModifySystemRate(const Json::Value& payload); void SetAppRate(const Json::Value& payload); diff --git a/services/include/qos_interface.h b/services/include/qos_interface.h index c0cf0ae..ed73126 100644 --- a/services/include/qos_interface.h +++ b/services/include/qos_interface.h @@ -31,6 +31,9 @@ constexpr unsigned int QOS_CTRL_IPC_MAGIC = 0xCC; constexpr unsigned int AUTH_CTRL_IPC_MAGIC = 0xCD; constexpr unsigned int RTG_SCHED_IPC_MAGIC = 0xAB; +constexpr unsigned int AF_QOS_ALL = 0x0003; +constexpr unsigned int AF_QOS_DELEGATED = 0x0001; + /* * auth_ctrl */ @@ -58,9 +61,7 @@ enum class AuthStatus { AUTH_STATUS_SYSTEM_SERVER = 2, AUTH_STATUS_FOREGROUND = 3, AUTH_STATUS_BACKGROUND = 4, -#ifdef QOS_EXT_ENABLE AUTH_STATUS_FOCUS = 5, -#endif AUTH_STATUS_DEAD, }; @@ -117,9 +118,7 @@ enum QosPolicyType { QOS_POLICY_SYSTEM_SERVER = 2, QOS_POLICY_FRONT = 3, QOS_POLICY_BACK = 4, -#ifdef QOS_EXT_ENABLE QOS_POLICY_FOCUS = 5, -#endif QOS_POLICY_MAX_NR, }; @@ -172,7 +171,7 @@ int EnableRtg(bool flag); int AuthEnable(unsigned int pid, unsigned int uaFlag, unsigned int status); int AuthPause(unsigned int pid); int AuthDelete(unsigned int pid); -int AuthGet(unsigned int pid, unsigned int *uaFlag, unsigned int *status); +int AuthGet(unsigned int pid); int AuthSwitch(unsigned int pid, unsigned int rtgFlag, unsigned int qosFlag, unsigned int status); int AuthEnhance(unsigned int pid, bool enhanceStatus); int QosApply(unsigned int level); diff --git a/services/src/concurrent_task_controller.cpp b/services/src/concurrent_task_controller.cpp index 429bd43..7eb9617 100644 --- a/services/src/concurrent_task_controller.cpp +++ b/services/src/concurrent_task_controller.cpp @@ -210,6 +210,8 @@ void TaskController::TypeMapInit() msgType_.insert(pair("continuousStart", MSG_CONTINUOUS_TASK_START)); msgType_.insert(pair("continuousEnd", MSG_CONTINUOUS_TASK_END)); msgType_.insert(pair("authRequest", MSG_AUTH_REQUEST)); + msgType_.insert(pair("getFocus", MSG_GET_FOCUS)); + msgType_.insert(pair("loseFocus", MSG_LOSE_FOCUS)); } void TaskController::TryCreateRsGroup() @@ -289,6 +291,10 @@ void TaskController::DealSystemRequest(int requestType, const Json::Value& paylo case MSG_CONTINUOUS_TASK_END: ContinuousTaskProcess(uid, pid, requestType); break; + case MSG_GET_FOCUS: + case MSG_LOSE_FOCUS: + FocusStatusProcess(uid, pid, requestType); + break; case MSG_AUTH_REQUEST: AuthRequestProcess(uid, pid); break; @@ -316,14 +322,20 @@ void TaskController::NewForeground(int uid, int pid) CONCUR_LOGI("un-authed pid %{public}d", pid); return; } - unsigned int pidParam = static_cast(pid); - unsigned int uaFlag = AF_RTG_ALL; - unsigned int status = static_cast(AuthStatus::AUTH_STATUS_FOREGROUND); - int ret = AuthEnable(pidParam, uaFlag, status); - if (ret == 0) { - CONCUR_LOGI("auth_enable %{public}d success", pid); + int ret = AuthGet(pid); + if (ret != static_cast(AuthStatus::AUTH_STATUS_FOCUS)) { + unsigned int pidParam = static_cast(pid); + unsigned int uaFlag = AF_RTG_ALL; + unsigned int status = static_cast(AuthStatus::AUTH_STATUS_FOREGROUND); + int ret = AuthEnable(pidParam, uaFlag, status); + if (ret == 0) { + CONCUR_LOGI("auth_enable %{public}d success", pid); + } else { + CONCUR_LOGE("auth_enable %{public}d fail with ret %{public}d", pid, ret); + } + CONCUR_LOGI("pid %{public}d change to foreground.", pid); } else { - CONCUR_LOGE("auth_enable %{public}d fail with ret %{public}d", pid, ret); + CONCUR_LOGI("pid %{public}d is already focus", pid); } bool found = false; bool ddlEnabled = OHOS::system::GetBoolParameter(INTERVAL_DDL, false); @@ -336,7 +348,6 @@ void TaskController::NewForeground(int uid, int pid) iter->BeginScene(); } } - CONCUR_LOGI("pid %{public}d change to foreground.", pid); if (!found) { ForegroundAppRecord *tempRecord = new ForegroundAppRecord(pid, uiTid); if (tempRecord->IsValid()) { @@ -447,6 +458,22 @@ void TaskController::ContinuousTaskProcess(int uid, int pid, int status) } } +void TaskController::FocusStatusProcess(int uid, int pid, int status) +{ + int ret = -1; + unsigned int rtgFlag = AF_RTG_ALL; + unsigned int qosFlag = AF_QOS_ALL; + if (status == static_cast(MSG_GET_FOCUS)) { + ret = AuthSwitch(pid, rtgFlag, qosFlag, static_cast(AuthStatus::AUTH_STATUS_FOCUS)); + CONCUR_LOGI("pid %{public}d get focus. ret %{public}d", pid, ret); + } else if (status == static_cast(MSG_LOSE_FOCUS)) { + ret = AuthSwitch(pid, rtgFlag, qosFlag, static_cast(AuthStatus::AUTH_STATUS_FOREGROUND)); + CONCUR_LOGI("pid %{public}d lose focus. ret %{public}d", pid, ret); + } else { + CONCUR_LOGE("Invalid focus status %{public}d", status); + } +} + void TaskController::QueryDeadline(int queryItem, DeadlineReply& ddlReply, const Json::Value& payload) { pid_t uid = IPCSkeleton::GetInstance().GetCallingUid(); diff --git a/services/src/qos_interface.cpp b/services/src/qos_interface.cpp index 5ef20e8..0e27a43 100644 --- a/services/src/qos_interface.cpp +++ b/services/src/qos_interface.cpp @@ -24,9 +24,6 @@ #include "../include/qos_interface.h" -constexpr unsigned int AF_QOS_ALL = 0x0003; -constexpr unsigned int AF_QOS_DELEGATED = 0x0001; - static int TrivalOpenRtgNode(void) { char fileName[] = "/proc/self/sched_rtg_ctrl"; @@ -192,7 +189,7 @@ int AuthPause(unsigned int pid) return ret; } -int AuthGet(unsigned int pid, unsigned int *uaFlag, unsigned int *status) +int AuthGet(unsigned int pid) { struct AuthCtrlData data; int fd; @@ -207,17 +204,12 @@ int AuthGet(unsigned int pid, unsigned int *uaFlag, unsigned int *status) data.type = static_cast(AuthManipulateType::AUTH_GET); ret = ioctl(fd, BASIC_AUTH_CTRL_OPERATION, &data); -#ifdef QOS_DEBUG if (ret < 0) { - printf("auth get failed for pid %u\n", pid); + return ret; } -#endif close(fd); - *uaFlag = data.rtgUaFlag; - *status = data.status; - - return ret; + return static_cast(data.status); } int AuthEnhance(unsigned int pid, bool enhanceStatus) diff --git a/services/src/qos_policy.cpp b/services/src/qos_policy.cpp index e3ec985..1663d96 100644 --- a/services/src/qos_policy.cpp +++ b/services/src/qos_policy.cpp @@ -43,7 +43,7 @@ static struct QosPolicyDatas g_foregroundQosPolicy = { #ifdef QOS_EXT_ENABLE {-10, 0, 300, 1024, 0}, {-10, -10, 500, 1024, 0}, - {-10, -10, 500, 1024, 2}, + {-10, -10, 500, 1024, 0}, #else {0, 0, 0, 1024, 0}, {0, 0, 0, 1024, 0}, @@ -64,7 +64,7 @@ static struct QosPolicyDatas g_backgroundQosPolicy = { {0, 0, 0, 300, 0}, #ifdef QOS_EXT_ENABLE {-5, -5, 0, 350, 0}, - {-5, -5, 0, 350, 3}, + {-5, -5, 0, 350, 0}, #else {0, 0, 0, 1024, 0}, {0, 0, 0, 1024, 0}, @@ -84,7 +84,28 @@ static struct QosPolicyDatas g_systemServerQosPolicy = { #ifdef QOS_EXT_ENABLE {-10, 0, 300, 1024, 0}, {-10, -10, 500, 1024, 0}, - {-10, -10, 500, 1024, 2}, + {-10, -10, 500, 1024, 1}, +#else + {0, 0, 0, 1024, 0}, + {0, 0, 0, 1024, 0}, + {0, 0, 0, 1024, 0}, +#endif + {0, 0, 0, 1024, 0}, + } +}; + +static struct QosPolicyDatas g_focusQosPolicy = { + .policyType = QOS_POLICY_FOCUS, + .policyFlag = QOS_FLAG_ALL, + .policys = { + {0, 0, 0, 1024, 0}, + {10, 10, 0, 200, 0}, + {5, 5, 0, 250, 0}, + {0, 0, 0, 1024, 0}, +#ifdef QOS_EXT_ENABLE + {-10, 0, 300, 1024, 0}, + {-10, -10, 500, 1024, 0}, + {-10, -10, 500, 1024, 1}, #else {0, 0, 0, 1024, 0}, {0, 0, 0, 1024, 0}, @@ -124,6 +145,12 @@ void QosPolicy::Init() if (ret) { CONCUR_LOGE("%{public}d set g_systemServerQosPolicy failed", getuid()); } + + ret = SetQosPolicy(&g_focusQosPolicy); + if (ret) { + CONCUR_LOGE("%{public}d set g_focusQosPolicy failed", getuid()); + } + CONCUR_LOGI("set qos policy finish"); } } diff --git a/test/unittest/phone/concurrent_task_controller_test.cpp b/test/unittest/phone/concurrent_task_controller_test.cpp index ab64bf4..a6d4b7e 100644 --- a/test/unittest/phone/concurrent_task_controller_test.cpp +++ b/test/unittest/phone/concurrent_task_controller_test.cpp @@ -197,6 +197,8 @@ HWTEST_F(ConcurrentTaskControllerTest, NewForegroundTest, TestSize.Level1) fore.NewForeground(uid, tid); fore.NewBackground(uid, tid); fore.ContinuousTaskProcess(uid, tid, static_cast(MSG_CONTINUOUS_TASK_START)); + fore.FocusStatusProcess(uid, tid, static_cast(MSG_GET_FOCUS)); + fore.FocusStatusProcess(uid, tid, static_cast(MSG_LOSE_FOCUS)); fore.AppKilled(uid, tid); tid = 574; fore.foregroundApp_.push_back(ForegroundAppRecord(tid, 0)); diff --git a/test/unittest/phone/qos_interface_test.cpp b/test/unittest/phone/qos_interface_test.cpp index cc98bc5..bf4fa39 100644 --- a/test/unittest/phone/qos_interface_test.cpp +++ b/test/unittest/phone/qos_interface_test.cpp @@ -154,10 +154,10 @@ HWTEST_F(QosInterfaceTest, AuthGetTest, TestSize.Level1) unsigned int *uaFlag = &uaFlag1; unsigned int status1 = 0; unsigned int *status = &status1; - int ret = AuthGet(pid, uaFlag, status); + int ret = AuthGet(pid); EXPECT_GE(ret, 0); pid = -1; - ret = AuthGet(pid, uaFlag, status); + ret = AuthGet(pid); EXPECT_EQ(ret, -1); } -- Gitee