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
(cherry picked from commit a0ef47223c)
This commit is contained in:
@@ -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
|
||||
@@ -57,10 +66,15 @@ public class BatchedInputEventReceiver extends InputEventReceiver {
|
||||
* @hide
|
||||
*/
|
||||
public void setBatchingEnabled(boolean batchingEnabled) {
|
||||
if (mBatchingEnabled == batchingEnabled) {
|
||||
return;
|
||||
}
|
||||
|
||||
mBatchingEnabled = batchingEnabled;
|
||||
mHandler.removeCallbacks(mConsumeBatchedInputEvents);
|
||||
if (!batchingEnabled) {
|
||||
unscheduleBatchedInput();
|
||||
consumeBatchedInputEvents(-1);
|
||||
mHandler.post(mConsumeBatchedInputEvents);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user