diff --git a/frameworks/core/frame_aware_policy/include/app_info.h b/frameworks/core/frame_aware_policy/include/app_info.h index 06919d5bc2390cd08872ecf7cbe1b0221002cd22..556d05854bd2a83bc8dd85021fc08a122e962e8a 100644 --- a/frameworks/core/frame_aware_policy/include/app_info.h +++ b/frameworks/core/frame_aware_policy/include/app_info.h @@ -18,6 +18,7 @@ #include #include +#include namespace OHOS { namespace RME { @@ -48,6 +49,9 @@ public: void SetRenderTid(const int tid); int GetRenderTid(); + void AddKeyTid(const int tid); + void RemoveKeyTid(const int tid); + std::unordered_set GetKeyTids(); void SetUiTid(const int tid); int GetUiTid(); void SetAppName(const std::string appName); @@ -66,6 +70,7 @@ private: int m_uid; int m_uiTid; int m_renderTid; + std::unordered_set m_keyTids; int m_isFocus; int m_rtGrp; AppState m_appState; diff --git a/frameworks/core/frame_aware_policy/include/intellisense_server.h b/frameworks/core/frame_aware_policy/include/intellisense_server.h index ed01efe679ca013ceea738bd37ff842bce045b9f..4b53d75085165530a656f983067e42cd21681fbe 100644 --- a/frameworks/core/frame_aware_policy/include/intellisense_server.h +++ b/frameworks/core/frame_aware_policy/include/intellisense_server.h @@ -40,6 +40,7 @@ public: void ReportCgroupChange(const int pid, const int uid, const int oldGroup, const int newGroup); void ReportWindowFocus(const int pid, const int uid, int isFocus); void ReportRenderThread(const int pid, const int uid, int renderTid); + void ReportKeyThread(const int pid, const int uid, int tid, int role); void ReportContinuousTask(const int pid, const int uid, const int status); bool ReadXml(); void SetPara(const int32_t currentFps, const int32_t currentRenderType); diff --git a/frameworks/core/frame_aware_policy/src/app_info.cpp b/frameworks/core/frame_aware_policy/src/app_info.cpp index 474d83eaec98886eafbfc0f2ae5ba150e9fc5797..25786ecb5cee18e791ae9080f8f50b0a9be2538b 100644 --- a/frameworks/core/frame_aware_policy/src/app_info.cpp +++ b/frameworks/core/frame_aware_policy/src/app_info.cpp @@ -23,6 +23,7 @@ AppInfo::AppInfo(int pid, int uid) m_uid(uid), m_uiTid(0), m_renderTid(0), + m_keyTids({}), m_isFocus(0), m_rtGrp(0), m_appState(AppState::APP_TERMINATED) @@ -38,6 +39,21 @@ int AppInfo::GetRenderTid() return m_renderTid; } +void AppInfo::AddKeyTid(const int tid) +{ + this->m_keyTids.insert(tid); +} + +void AppInfo::RemoveKeyTid(const int tid) +{ + this->m_keyTids.erase(tid); +} + +std::unordered_set AppInfo::GetKeyTids() +{ + return m_keyTids; +} + void AppInfo::SetUiTid(const int tid) { this->m_uiTid = tid; diff --git a/frameworks/core/frame_aware_policy/src/intellisense_server.cpp b/frameworks/core/frame_aware_policy/src/intellisense_server.cpp index ce09546eb2cc2a46e32f1972de55a996f7e2ce50..10ab02603dde93fde622702c4cb7f8131dc222b4 100644 --- a/frameworks/core/frame_aware_policy/src/intellisense_server.cpp +++ b/frameworks/core/frame_aware_policy/src/intellisense_server.cpp @@ -132,12 +132,16 @@ int IntelliSenseServer::TryCreateRtgForApp(AppInfo *app) app->SetRtgrp(grpId); int uiTid = app->GetUiTid(); int renderTid = app->GetRenderTid(); + auto keyTids = app->GetKeyTids(); if (uiTid > 0) { AddThreadToRtg(uiTid, grpId, 0); // add ui thread } if (renderTid > 0) { AddThreadToRtg(renderTid, grpId, 0); // add render thread } + for (int keyTid : keyTids) { + AddThreadToRtg(keyTid, grpId, 0); // add key thread + } return grpId; } @@ -225,6 +229,41 @@ void IntelliSenseServer::ReportRenderThread(const int pid, const int uid, int re } } +void IntelliSenseServer::ReportKeyThread(const int pid, const int uid, int tid, int role) +{ + if (uid >= WEB_BASE_UID && uid <= WEB_END_UID) { + return; + } + if (!m_switch) { + return; + } + HITRACE_METER(HITRACE_TAG_ACE); + auto record = GetRecordOfPid(pid); + if (record == m_historyApp.end()) { + RME_LOGE("Didn't find key in history app %{public}d with ui %{public}d", pid, tid); + return; + } + if (role) { + record->AddKeyTid(tid); + } else { + record->RemoveKeyTid(tid); + } + int grpId = record->GetRtgrp(); + if (grpId >= 0) { + int ret = 0; + if (!role) { + ret = RemoveRtgThread(tid); // remove key thread + } else if (record->GetAppState() == AppState::APP_FOREGROUND) { + ret = AddThreadToRtg(tid, grpId, 0); // add key thread + } + RME_LOGE("web test ReportKeyThread uid is %{public}d", uid); + if (ret != 0) { + RME_LOGE("[OnFore]:key thread fail! pid:%{public}d,rtg:%{public}d!ret:%{publid}d", + tid, grpId, ret); + } + } +} + void IntelliSenseServer::ReportContinuousTask(const int pid, const int uid, const int status) { if (!m_switch) { diff --git a/interfaces/innerkits/frameintf/frame_msg_intf.cpp b/interfaces/innerkits/frameintf/frame_msg_intf.cpp index 714856fd53b4faeac72f971756374b19416285c6..317b5aac156f457e7f7a20b227fdba9c92a28e82 100644 --- a/interfaces/innerkits/frameintf/frame_msg_intf.cpp +++ b/interfaces/innerkits/frameintf/frame_msg_intf.cpp @@ -90,6 +90,19 @@ void FrameMsgIntf::ReportRenderThread(const int pid, const int uid, const int re }); } +void FrameMsgIntf::ReportKeyThread(const int pid, const int uid, const int tid, const int role) +{ + std::lock_guard autoLock(frameMsgIntfMutex_); + RME_LOGI("[ReportKeyThread]:key get %{public}d with id %{public}d role %{public}d", pid, tid, role); + if (taskQueue_ == nullptr) { + RME_LOGE("[ReportKeyThread]:taskQueue none!"); + return; + } + taskQueue_->submit([pid, uid, tid, role] { + IntelliSenseServer::GetInstance().ReportKeyThread(pid, uid, tid, role); + }); +} + void FrameMsgIntf::ReportAppInfo(const int pid, const int uid, const std::string bundleName, ThreadState state) { std::lock_guard autoLock(frameMsgIntfMutex_); diff --git a/interfaces/innerkits/frameintf/frame_msg_intf.h b/interfaces/innerkits/frameintf/frame_msg_intf.h index 37e42db0d3e467dfab36c3f0ebff044f5821538f..472a03b54379d799c2f87c33b0e3970d18a2654a 100644 --- a/interfaces/innerkits/frameintf/frame_msg_intf.h +++ b/interfaces/innerkits/frameintf/frame_msg_intf.h @@ -33,6 +33,7 @@ public: void ReportCgroupChange(const int pid, const int uid, const int oldGroup, const int newGroup); void ReportWindowFocus(const int pid, const int uid, const int isFocus); void ReportRenderThread(const int pid, const int uid, const int renderTid); + void ReportKeyThread(const int pid, const int uid, const int tid, const int role); void ReportContinuousTask(const int pid, const int uid, const int status); void ReportSlideEvent(const int pid, const int uid, const int64_t status); void Stop();