Add support for throttling motion events.
Change-Id: I24b3a17753e91ecda60a60fe5cd2e6b3260e033d
This commit is contained in:
@@ -26,6 +26,7 @@ import android.content.res.Configuration;
|
||||
import android.os.Environment;
|
||||
import android.os.LocalPowerManager;
|
||||
import android.os.PowerManager;
|
||||
import android.os.SystemProperties;
|
||||
import android.util.Slog;
|
||||
import android.util.Xml;
|
||||
import android.view.InputChannel;
|
||||
@@ -507,5 +508,18 @@ public class InputManager {
|
||||
|
||||
return names.toArray(new String[names.size()]);
|
||||
}
|
||||
|
||||
@SuppressWarnings("unused")
|
||||
public int getMaxEventsPerSecond() {
|
||||
int result = 0;
|
||||
try {
|
||||
result = Integer.parseInt(SystemProperties.get("windowsmgr.max_events_per_sec"));
|
||||
} catch (NumberFormatException e) {
|
||||
}
|
||||
if (result < 1) {
|
||||
result = 35;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -139,6 +139,7 @@ static struct {
|
||||
jmethodID filterJumpyTouchEvents;
|
||||
jmethodID getVirtualKeyDefinitions;
|
||||
jmethodID getExcludedDeviceNames;
|
||||
jmethodID getMaxEventsPerSecond;
|
||||
} gCallbacksClassInfo;
|
||||
|
||||
static struct {
|
||||
@@ -249,6 +250,7 @@ public:
|
||||
int32_t injectorPid, int32_t injectorUid, Vector<InputTarget>& outTargets);
|
||||
virtual int32_t waitForMotionEventTargets(MotionEvent* motionEvent, uint32_t policyFlags,
|
||||
int32_t injectorPid, int32_t injectorUid, Vector<InputTarget>& outTargets);
|
||||
virtual int32_t getMaxEventsPerSecond();
|
||||
|
||||
private:
|
||||
struct InputWindow {
|
||||
@@ -310,6 +312,9 @@ private:
|
||||
int32_t mFilterTouchEvents;
|
||||
int32_t mFilterJumpyTouchEvents;
|
||||
|
||||
// Cached throttling policy.
|
||||
int32_t mMaxEventsPerSecond;
|
||||
|
||||
// Cached display state. (lock mDisplayLock)
|
||||
Mutex mDisplayLock;
|
||||
int32_t mDisplayWidth, mDisplayHeight;
|
||||
@@ -400,6 +405,7 @@ private:
|
||||
|
||||
NativeInputManager::NativeInputManager(jobject callbacksObj) :
|
||||
mFilterTouchEvents(-1), mFilterJumpyTouchEvents(-1),
|
||||
mMaxEventsPerSecond(-1),
|
||||
mDisplayWidth(-1), mDisplayHeight(-1), mDisplayOrientation(ROTATION_0),
|
||||
mDispatchEnabled(true), mDispatchFrozen(false), mWindowsReady(true),
|
||||
mFocusedWindow(NULL), mTouchDown(false), mTouchedWindow(NULL),
|
||||
@@ -921,6 +927,21 @@ nsecs_t NativeInputManager::getKeyRepeatTimeout() {
|
||||
}
|
||||
}
|
||||
|
||||
int32_t NativeInputManager::getMaxEventsPerSecond() {
|
||||
if (mMaxEventsPerSecond < 0) {
|
||||
JNIEnv* env = jniEnv();
|
||||
|
||||
jint result = env->CallIntMethod(mCallbacksObj,
|
||||
gCallbacksClassInfo.getMaxEventsPerSecond);
|
||||
if (checkAndClearExceptionFromCallback(env, "getMaxEventsPerSecond")) {
|
||||
result = 35;
|
||||
}
|
||||
|
||||
mMaxEventsPerSecond = result;
|
||||
}
|
||||
return mMaxEventsPerSecond;
|
||||
}
|
||||
|
||||
void NativeInputManager::setInputWindows(JNIEnv* env, jobjectArray windowObjArray) {
|
||||
#if DEBUG_FOCUS
|
||||
LOGD("setInputWindows");
|
||||
@@ -2293,6 +2314,9 @@ int register_android_server_InputManager(JNIEnv* env) {
|
||||
GET_METHOD_ID(gCallbacksClassInfo.getExcludedDeviceNames, gCallbacksClassInfo.clazz,
|
||||
"getExcludedDeviceNames", "()[Ljava/lang/String;");
|
||||
|
||||
GET_METHOD_ID(gCallbacksClassInfo.getMaxEventsPerSecond, gCallbacksClassInfo.clazz,
|
||||
"getMaxEventsPerSecond", "()I");
|
||||
|
||||
// VirtualKeyDefinition
|
||||
|
||||
FIND_CLASS(gVirtualKeyDefinitionClassInfo.clazz,
|
||||
|
||||
Reference in New Issue
Block a user