summaryrefslogtreecommitdiff
path: root/core/java/android/view/InputEventAssigner.java
diff options
context:
space:
mode:
authorSiarhei Vishniakou <svv@google.com>2021-03-17 23:49:15 +0000
committerSiarhei Vishniakou <svv@google.com>2021-03-22 07:59:18 +0000
commit5054a9d00990ce35eb5ea6e5c9748d001a87c55c (patch)
tree6f93aa53cdb6dcbebf70480538bdc0427e996e36 /core/java/android/view/InputEventAssigner.java
parent0467858710e42343f6e67b1e8d11345b0459cdfb (diff)
Notify InputEventAssigner about every frame
InputEventAssigner does not currently get notified about all frames. In the existing logic, only the cases for batched consumption would be counted as 'choreographer callback'. This misses several cases, such as: 1) CALLBACK_INPUT was never scheduled, but a frame is produced 2) CALLBACK_INPUT was scheduled, but no events were consumed However, it is critical that InputEventAssigner knows about all frames, because it needs to reset the 'down' state for proper frame attribution. At the same time, we refactor the logic in InputEventAssigner. In the updated logic, we will specifically store the event id with ACTION_DOWN only. In all other cases, we will use the current / latest input event. In this CL, we reset the 'down' state after the input event id is used for the current frame. A good proxy for that is the ThreadedRenderer::draw call, which in turns calls attachInfo.mViewRootImpl.getUpdatedFrameInfo(). Also, rename "onChoreographerCallback" since it's not exactly clear which callback this is referring to. In the new logic, this callback will happen from 'draw'/'onDraw' functions. Bug: 167947340 Test: add LOG_ALWAYS_FATAL crashes in LatencyTracker for duplicate 'reportTimeline' calls. The crashes are gone after this CL. Change-Id: I5fad6665d10e0594963209b138e9bd2bdf00ca38
Diffstat (limited to 'core/java/android/view/InputEventAssigner.java')
-rw-r--r--core/java/android/view/InputEventAssigner.java43
1 files changed, 17 insertions, 26 deletions
diff --git a/core/java/android/view/InputEventAssigner.java b/core/java/android/view/InputEventAssigner.java
index c159a127f4eb..7fac6c5e4af6 100644
--- a/core/java/android/view/InputEventAssigner.java
+++ b/core/java/android/view/InputEventAssigner.java
@@ -45,13 +45,13 @@ import static android.view.InputDevice.SOURCE_TOUCHSCREEN;
public class InputEventAssigner {
private static final String TAG = "InputEventAssigner";
private boolean mHasUnprocessedDown = false;
- private int mEventId = INVALID_INPUT_EVENT_ID;
+ private int mDownEventId = INVALID_INPUT_EVENT_ID;
/**
- * Notify InputEventAssigner that the Choreographer callback has been processed. This will reset
- * the 'down' state to assign the latest input event to the current frame.
+ * Notify InputEventAssigner that a frame has been processed. We no longer need to keep track of
+ * the DOWN event because a frame has already been produced for it.
*/
- public void onChoreographerCallback() {
+ public void notifyFrameProcessed() {
// Mark completion of this frame. Use newest input event from now on.
mHasUnprocessedDown = false;
}
@@ -62,31 +62,22 @@ public class InputEventAssigner {
* @return the id of the input event to use for the current frame
*/
public int processEvent(InputEvent event) {
- if (event instanceof KeyEvent) {
- // We will not do any special handling for key events
- return event.getId();
- }
-
if (event instanceof MotionEvent) {
MotionEvent motionEvent = (MotionEvent) event;
- final int action = motionEvent.getActionMasked();
-
- if (action == MotionEvent.ACTION_CANCEL || action == MotionEvent.ACTION_UP) {
- mHasUnprocessedDown = false;
+ if (motionEvent.isFromSource(SOURCE_TOUCHSCREEN)) {
+ final int action = motionEvent.getActionMasked();
+ if (action == MotionEvent.ACTION_DOWN) {
+ mHasUnprocessedDown = true;
+ mDownEventId = event.getId();
+ }
+ if (mHasUnprocessedDown && action == MotionEvent.ACTION_MOVE) {
+ return mDownEventId;
+ }
+ if (action == MotionEvent.ACTION_CANCEL || action == MotionEvent.ACTION_UP) {
+ mHasUnprocessedDown = false;
+ }
}
- if (motionEvent.isFromSource(SOURCE_TOUCHSCREEN) && action == MotionEvent.ACTION_DOWN) {
- mHasUnprocessedDown = true;
- mEventId = event.getId();
- // This will remain 'true' even if we receive a MOVE event, as long as choreographer
- // hasn't invoked the 'CALLBACK_INPUT' callback.
- }
- // Don't update the event id if we haven't processed DOWN yet.
- if (!mHasUnprocessedDown) {
- mEventId = event.getId();
- }
- return mEventId;
}
-
- throw new IllegalArgumentException("Received unexpected " + event);
+ return event.getId();
}
}