From 27db62fa49f662c5e81ca72f08b7e70d932e7fc6 Mon Sep 17 00:00:00 2001 From: Jerry Chang Date: Wed, 19 Jun 2024 11:38:29 +0000 Subject: Apply input event profile to mitigate input latency of input threads Bug: 347122505 Flag: com.android.input.flags.enable_input_policy_profile Test: check the priority and latency of input thread in Perffeto Change-Id: I428b9e718eace0bc39f1965d98475eebe9d3aaa5 --- services/inputflinger/InputThread.cpp | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) (limited to 'services/inputflinger/InputThread.cpp') diff --git a/services/inputflinger/InputThread.cpp b/services/inputflinger/InputThread.cpp index e74f258168..449eb45b4b 100644 --- a/services/inputflinger/InputThread.cpp +++ b/services/inputflinger/InputThread.cpp @@ -16,8 +16,14 @@ #include "InputThread.h" +#include +#include +#include + namespace android { +namespace input_flags = com::android::input::flags; + namespace { // Implementation of Thread from libutils. @@ -43,6 +49,11 @@ InputThread::InputThread(std::string name, std::function loop, std::func : mName(name), mThreadWake(wake) { mThread = sp::make(loop); mThread->run(mName.c_str(), ANDROID_PRIORITY_URGENT_DISPLAY); + if (input_flags::enable_input_policy_profile()) { + if (!applyInputEventProfile()) { + LOG(ERROR) << "Couldn't apply input policy profile for " << name; + } + } } InputThread::~InputThread() { @@ -63,4 +74,14 @@ bool InputThread::isCallingThread() { #endif } +bool InputThread::applyInputEventProfile() { +#if defined(__ANDROID__) + return SetTaskProfiles(mThread->getTid(), {"InputPolicy"}); +#else + // Since thread information is not available and there's no benefit of + // applying the task profile on host, return directly. + return true; +#endif +} + } // namespace android \ No newline at end of file -- cgit v1.2.3-59-g8ed1b