Wait until dispatcher is idle

Add a mechanism for waiting until the dispatcher is idle. This will
allow tests to not have to wait until a specific timeout is reached when
asserting that a callback did not happen.

For example, the current test approach is like this: 1) do something 2)
monitor policy for a certain amount of time 3) check that the thing you
are interested in did not happen.

With this approach, we will modify this behaviour to be as follows: 1)
do something 2) wait until dispatcher is idle 3) check that the thing
didn't happen.

In this case, the dispatcher is idle condition will happen sooner than
the timeout in the original approach. This will help keep the tests
fast.

Bug: 70668286
Test: atest inputflinger_tests
Change-Id: I2ac5e38ccbc388fe6d94832405b68ef9e52d25f4
diff --git a/services/inputflinger/dispatcher/InputDispatcher.h b/services/inputflinger/dispatcher/InputDispatcher.h
index 5d7d812..38f8674 100644
--- a/services/inputflinger/dispatcher/InputDispatcher.h
+++ b/services/inputflinger/dispatcher/InputDispatcher.h
@@ -81,6 +81,7 @@
 
     virtual void dump(std::string& dump) override;
     virtual void monitor() override;
+    virtual bool waitForIdle() override;
 
     virtual void dispatchOnce() override;
 
@@ -129,6 +130,7 @@
     std::mutex mLock;
 
     std::condition_variable mDispatcherIsAlive;
+    std::condition_variable mDispatcherEnteredIdle;
 
     sp<Looper> mLooper;