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

Commit 0a4981aa authored by Patrick Williams's avatar Patrick Williams
Browse files

Fix flaky InputSurfacesTest tests

This CL updates InputSurfacesTest to use a WindowInfosReportedListener to ensure window changes have made their way to InputFlinger before injecting taps.

Bug: 288344458
Test: ran each flaky test 200+ times
Change-Id: Iec9de64b20750f1292ac09437dff1a747eade98c
parent 774bcbe5
Loading
Loading
Loading
Loading
+25 −1
Original line number Diff line number Diff line
@@ -24,6 +24,7 @@

#include <memory>

#include <android/gui/BnWindowInfosReportedListener.h>
#include <android/keycodes.h>
#include <android/native_window.h>

@@ -74,6 +75,26 @@ sp<IInputFlinger> getInputFlinger() {
static const int LAYER_BASE = INT32_MAX - 10;
static constexpr std::chrono::nanoseconds DISPATCHING_TIMEOUT = 5s;

class SynchronousWindowInfosReportedListener : public gui::BnWindowInfosReportedListener {
public:
    binder::Status onWindowInfosReported() override {
        std::lock_guard<std::mutex> lock{mMutex};
        mWindowInfosReported = true;
        mConditionVariable.notify_one();
        return binder::Status::ok();
    }

    void wait() {
        std::unique_lock<std::mutex> lock{mMutex};
        mConditionVariable.wait(lock, [&] { return mWindowInfosReported; });
    }

private:
    std::mutex mMutex;
    std::condition_variable mConditionVariable;
    bool mWindowInfosReported{false};
};

class InputSurface {
public:
    InputSurface(const sp<SurfaceControl> &sc, int width, int height, bool noInputChannel = false) {
@@ -264,7 +285,10 @@ public:
        t.setPosition(mSurfaceControl, x, y);
        t.setCrop(mSurfaceControl, crop);
        t.setAlpha(mSurfaceControl, 1);
        t.apply(true);
        auto reportedListener = sp<SynchronousWindowInfosReportedListener>::make();
        t.addWindowInfosReportedListener(reportedListener);
        t.apply();
        reportedListener->wait();
    }

    void requestFocus(int displayId = ADISPLAY_ID_DEFAULT) {