Fix flaky test WindowInputTestsi#testTrustedOverlapWindow

When disabling batching input, we should post the action to consume
batched events to prevent it would be handled before current event.

Bug: 189241600
Test: atest WindowInputTests --rerun-until-failure
Change-Id: I87aaa2574a27368f88df1aba3f2eb769a8e8f36b
This commit is contained in:
Arthur Hung
2021-08-12 13:19:35 +00:00
parent 1c5cbd49a1
commit a0ef47223c

View File

@@ -17,6 +17,7 @@
package android.view;
import android.compat.annotation.UnsupportedAppUsage;
import android.os.Handler;
import android.os.Looper;
/**
@@ -27,6 +28,13 @@ public class BatchedInputEventReceiver extends InputEventReceiver {
private Choreographer mChoreographer;
private boolean mBatchingEnabled;
private boolean mBatchedInputScheduled;
private final Handler mHandler;
private final Runnable mConsumeBatchedInputEvents = new Runnable() {
@Override
public void run() {
consumeBatchedInputEvents(-1);
}
};
@UnsupportedAppUsage
public BatchedInputEventReceiver(
@@ -34,6 +42,7 @@ public class BatchedInputEventReceiver extends InputEventReceiver {
super(inputChannel, looper);
mChoreographer = choreographer;
mBatchingEnabled = true;
mHandler = new Handler(looper);
}
@Override
@@ -60,7 +69,7 @@ public class BatchedInputEventReceiver extends InputEventReceiver {
mBatchingEnabled = batchingEnabled;
if (!batchingEnabled) {
unscheduleBatchedInput();
consumeBatchedInputEvents(-1);
mHandler.post(mConsumeBatchedInputEvents);
}
}