Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit a0ef4722 authored by Arthur Hung's avatar Arthur Hung
Browse files

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
parent 1c5cbd49
Loading
Loading
Loading
Loading
+10 −1
Original line number Diff line number Diff line
@@ -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);
        }
    }