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

Commit 71233d8c authored by Patrick Williams's avatar Patrick Williams Committed by Android (Google) Code Review
Browse files

Merge "Fix flaky InputSurfacesTest tests" into main

parents 65c0b693 0a4981aa
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) {