Loading core/java/android/view/BatchedInputEventReceiver.java +13 −0 Original line number Diff line number Diff line Loading @@ -19,6 +19,7 @@ package android.view; import android.compat.annotation.UnsupportedAppUsage; import android.os.Handler; import android.os.Looper; import android.os.Trace; /** * Similar to {@link InputEventReceiver}, but batches events to vsync boundaries when possible. Loading @@ -42,6 +43,8 @@ public class BatchedInputEventReceiver extends InputEventReceiver { super(inputChannel, looper); mChoreographer = choreographer; mBatchingEnabled = true; traceBoolVariable("mBatchingEnabled", mBatchingEnabled); traceBoolVariable("mBatchedInputScheduled", mBatchedInputScheduled); mHandler = new Handler(looper); } Loading Loading @@ -71,6 +74,7 @@ public class BatchedInputEventReceiver extends InputEventReceiver { } mBatchingEnabled = batchingEnabled; traceBoolVariable("mBatchingEnabled", mBatchingEnabled); mHandler.removeCallbacks(mConsumeBatchedInputEvents); if (!batchingEnabled) { unscheduleBatchedInput(); Loading @@ -81,6 +85,7 @@ public class BatchedInputEventReceiver extends InputEventReceiver { protected void doConsumeBatchedInput(long frameTimeNanos) { if (mBatchedInputScheduled) { mBatchedInputScheduled = false; traceBoolVariable("mBatchedInputScheduled", mBatchedInputScheduled); if (consumeBatchedInputEvents(frameTimeNanos) && frameTimeNanos != -1) { // If we consumed a batch here, we want to go ahead and schedule the // consumption of batched input events on the next frame. Otherwise, we would Loading @@ -95,6 +100,7 @@ public class BatchedInputEventReceiver extends InputEventReceiver { private void scheduleBatchedInput() { if (!mBatchedInputScheduled) { mBatchedInputScheduled = true; traceBoolVariable("mBatchedInputScheduled", mBatchedInputScheduled); mChoreographer.postCallback(Choreographer.CALLBACK_INPUT, mBatchedInputRunnable, null); } } Loading @@ -102,11 +108,18 @@ public class BatchedInputEventReceiver extends InputEventReceiver { private void unscheduleBatchedInput() { if (mBatchedInputScheduled) { mBatchedInputScheduled = false; traceBoolVariable("mBatchedInputScheduled", mBatchedInputScheduled); mChoreographer.removeCallbacks( Choreographer.CALLBACK_INPUT, mBatchedInputRunnable, null); } } // @TODO(b/311142655): Delete this temporary tracing. It's only used here to debug a very // specific issue. private void traceBoolVariable(String name, boolean value) { Trace.traceCounter(Trace.TRACE_TAG_INPUT, name, value ? 1 : 0); } private final class BatchedInputRunnable implements Runnable { @Override public void run() { Loading core/java/android/view/InputEventReceiver.java +17 −0 Original line number Diff line number Diff line Loading @@ -271,12 +271,29 @@ public abstract class InputEventReceiver { return mInputChannel.getToken(); } private String getShortDescription(InputEvent event) { if (event instanceof MotionEvent motion) { return "MotionEvent " + MotionEvent.actionToString(motion.getAction()) + " deviceId=" + motion.getDeviceId() + " source=0x" + Integer.toHexString(motion.getSource()) + " historySize=" + motion.getHistorySize(); } else if (event instanceof KeyEvent key) { return "KeyEvent " + KeyEvent.actionToString(key.getAction()) + " deviceId=" + key.getDeviceId(); } else { Log.wtf(TAG, "Illegal InputEvent type: " + event); return "InputEvent"; } } // Called from native code. @SuppressWarnings("unused") @UnsupportedAppUsage(maxTargetSdk = Build.VERSION_CODES.R, trackingBug = 170729553) private void dispatchInputEvent(int seq, InputEvent event) { Trace.traceBegin(Trace.TRACE_TAG_INPUT, "dispatchInputEvent " + getShortDescription(event)); mSeqMap.put(event.getSequenceNumber(), seq); onInputEvent(event); Trace.traceEnd(Trace.TRACE_TAG_INPUT); } /** Loading core/jni/android_view_InputEventReceiver.cpp +15 −0 Original line number Diff line number Diff line Loading @@ -15,6 +15,7 @@ */ #define LOG_TAG "InputEventReceiver" #define ATRACE_TAG ATRACE_TAG_INPUT //#define LOG_NDEBUG 0 Loading Loading @@ -46,6 +47,16 @@ static const char* toString(bool value) { return value ? "true" : "false"; } /** * Trace a bool variable, writing "1" if the value is "true" and "0" otherwise. * TODO(b/311142655): delete this tracing. It's only useful for debugging very specific issues. * @param var the name of the variable * @param value the value of the variable */ static void traceBoolVariable(const char* var, bool value) { ATRACE_INT(var, value ? 1 : 0); } static struct { jclass clazz; Loading Loading @@ -130,6 +141,7 @@ NativeInputEventReceiver::NativeInputEventReceiver( mMessageQueue(messageQueue), mBatchedInputEventPending(false), mFdEvents(0) { traceBoolVariable("mBatchedInputEventPending", mBatchedInputEventPending); if (kDebugDispatchCycle) { ALOGD("channel '%s' ~ Initializing input event receiver.", getInputChannelName().c_str()); } Loading Loading @@ -311,6 +323,7 @@ status_t NativeInputEventReceiver::consumeEvents(JNIEnv* env, if (consumeBatches) { mBatchedInputEventPending = false; traceBoolVariable("mBatchedInputEventPending", mBatchedInputEventPending); } if (outConsumedBatch) { *outConsumedBatch = false; Loading Loading @@ -344,6 +357,7 @@ status_t NativeInputEventReceiver::consumeEvents(JNIEnv* env, } mBatchedInputEventPending = true; traceBoolVariable("mBatchedInputEventPending", mBatchedInputEventPending); if (kDebugDispatchCycle) { ALOGD("channel '%s' ~ Dispatching batched input event pending notification.", getInputChannelName().c_str()); Loading @@ -355,6 +369,7 @@ status_t NativeInputEventReceiver::consumeEvents(JNIEnv* env, if (env->ExceptionCheck()) { ALOGE("Exception dispatching batched input events."); mBatchedInputEventPending = false; // try again later traceBoolVariable("mBatchedInputEventPending", mBatchedInputEventPending); } } return OK; Loading Loading
core/java/android/view/BatchedInputEventReceiver.java +13 −0 Original line number Diff line number Diff line Loading @@ -19,6 +19,7 @@ package android.view; import android.compat.annotation.UnsupportedAppUsage; import android.os.Handler; import android.os.Looper; import android.os.Trace; /** * Similar to {@link InputEventReceiver}, but batches events to vsync boundaries when possible. Loading @@ -42,6 +43,8 @@ public class BatchedInputEventReceiver extends InputEventReceiver { super(inputChannel, looper); mChoreographer = choreographer; mBatchingEnabled = true; traceBoolVariable("mBatchingEnabled", mBatchingEnabled); traceBoolVariable("mBatchedInputScheduled", mBatchedInputScheduled); mHandler = new Handler(looper); } Loading Loading @@ -71,6 +74,7 @@ public class BatchedInputEventReceiver extends InputEventReceiver { } mBatchingEnabled = batchingEnabled; traceBoolVariable("mBatchingEnabled", mBatchingEnabled); mHandler.removeCallbacks(mConsumeBatchedInputEvents); if (!batchingEnabled) { unscheduleBatchedInput(); Loading @@ -81,6 +85,7 @@ public class BatchedInputEventReceiver extends InputEventReceiver { protected void doConsumeBatchedInput(long frameTimeNanos) { if (mBatchedInputScheduled) { mBatchedInputScheduled = false; traceBoolVariable("mBatchedInputScheduled", mBatchedInputScheduled); if (consumeBatchedInputEvents(frameTimeNanos) && frameTimeNanos != -1) { // If we consumed a batch here, we want to go ahead and schedule the // consumption of batched input events on the next frame. Otherwise, we would Loading @@ -95,6 +100,7 @@ public class BatchedInputEventReceiver extends InputEventReceiver { private void scheduleBatchedInput() { if (!mBatchedInputScheduled) { mBatchedInputScheduled = true; traceBoolVariable("mBatchedInputScheduled", mBatchedInputScheduled); mChoreographer.postCallback(Choreographer.CALLBACK_INPUT, mBatchedInputRunnable, null); } } Loading @@ -102,11 +108,18 @@ public class BatchedInputEventReceiver extends InputEventReceiver { private void unscheduleBatchedInput() { if (mBatchedInputScheduled) { mBatchedInputScheduled = false; traceBoolVariable("mBatchedInputScheduled", mBatchedInputScheduled); mChoreographer.removeCallbacks( Choreographer.CALLBACK_INPUT, mBatchedInputRunnable, null); } } // @TODO(b/311142655): Delete this temporary tracing. It's only used here to debug a very // specific issue. private void traceBoolVariable(String name, boolean value) { Trace.traceCounter(Trace.TRACE_TAG_INPUT, name, value ? 1 : 0); } private final class BatchedInputRunnable implements Runnable { @Override public void run() { Loading
core/java/android/view/InputEventReceiver.java +17 −0 Original line number Diff line number Diff line Loading @@ -271,12 +271,29 @@ public abstract class InputEventReceiver { return mInputChannel.getToken(); } private String getShortDescription(InputEvent event) { if (event instanceof MotionEvent motion) { return "MotionEvent " + MotionEvent.actionToString(motion.getAction()) + " deviceId=" + motion.getDeviceId() + " source=0x" + Integer.toHexString(motion.getSource()) + " historySize=" + motion.getHistorySize(); } else if (event instanceof KeyEvent key) { return "KeyEvent " + KeyEvent.actionToString(key.getAction()) + " deviceId=" + key.getDeviceId(); } else { Log.wtf(TAG, "Illegal InputEvent type: " + event); return "InputEvent"; } } // Called from native code. @SuppressWarnings("unused") @UnsupportedAppUsage(maxTargetSdk = Build.VERSION_CODES.R, trackingBug = 170729553) private void dispatchInputEvent(int seq, InputEvent event) { Trace.traceBegin(Trace.TRACE_TAG_INPUT, "dispatchInputEvent " + getShortDescription(event)); mSeqMap.put(event.getSequenceNumber(), seq); onInputEvent(event); Trace.traceEnd(Trace.TRACE_TAG_INPUT); } /** Loading
core/jni/android_view_InputEventReceiver.cpp +15 −0 Original line number Diff line number Diff line Loading @@ -15,6 +15,7 @@ */ #define LOG_TAG "InputEventReceiver" #define ATRACE_TAG ATRACE_TAG_INPUT //#define LOG_NDEBUG 0 Loading Loading @@ -46,6 +47,16 @@ static const char* toString(bool value) { return value ? "true" : "false"; } /** * Trace a bool variable, writing "1" if the value is "true" and "0" otherwise. * TODO(b/311142655): delete this tracing. It's only useful for debugging very specific issues. * @param var the name of the variable * @param value the value of the variable */ static void traceBoolVariable(const char* var, bool value) { ATRACE_INT(var, value ? 1 : 0); } static struct { jclass clazz; Loading Loading @@ -130,6 +141,7 @@ NativeInputEventReceiver::NativeInputEventReceiver( mMessageQueue(messageQueue), mBatchedInputEventPending(false), mFdEvents(0) { traceBoolVariable("mBatchedInputEventPending", mBatchedInputEventPending); if (kDebugDispatchCycle) { ALOGD("channel '%s' ~ Initializing input event receiver.", getInputChannelName().c_str()); } Loading Loading @@ -311,6 +323,7 @@ status_t NativeInputEventReceiver::consumeEvents(JNIEnv* env, if (consumeBatches) { mBatchedInputEventPending = false; traceBoolVariable("mBatchedInputEventPending", mBatchedInputEventPending); } if (outConsumedBatch) { *outConsumedBatch = false; Loading Loading @@ -344,6 +357,7 @@ status_t NativeInputEventReceiver::consumeEvents(JNIEnv* env, } mBatchedInputEventPending = true; traceBoolVariable("mBatchedInputEventPending", mBatchedInputEventPending); if (kDebugDispatchCycle) { ALOGD("channel '%s' ~ Dispatching batched input event pending notification.", getInputChannelName().c_str()); Loading @@ -355,6 +369,7 @@ status_t NativeInputEventReceiver::consumeEvents(JNIEnv* env, if (env->ExceptionCheck()) { ALOGE("Exception dispatching batched input events."); mBatchedInputEventPending = false; // try again later traceBoolVariable("mBatchedInputEventPending", mBatchedInputEventPending); } } return OK; Loading