Reland "Let InputReader handle its own thread"
This CL was first landed in Ic732436d4f00a831e317be1f16ac106a11652cff
but was reverted due to flaky tests.
The flaky tests were caused by races between the instrumented test
classes and the InputReader class under test, which now runs in a new
thread.
In addition to re-landing the change, this CL fixes the flaky tests by
changing the tests to eliminate the race condition.
- InputReaderTest should send a configuration change request to
InputReader every time a device is enabled or disabled, and the test
should wait for notifyDeviceReset to be called on the input listener to
ensure it was enabled/disabled successfully.
Bug: 130819454
Test: atest inputflinger_tests
Test: Touch input works on crosshatch
Change-Id: I822d3c33384ebdc1bc850a40534e942a27a79ec9
diff --git a/services/inputflinger/include/InputReaderBase.h b/services/inputflinger/include/InputReaderBase.h
index 5d576b9..56c0a73 100644
--- a/services/inputflinger/include/InputReaderBase.h
+++ b/services/inputflinger/include/InputReaderBase.h
@@ -19,12 +19,12 @@
#include "PointerControllerInterface.h"
+#include <input/DisplayViewport.h>
#include <input/Input.h>
#include <input/InputDevice.h>
-#include <input/DisplayViewport.h>
#include <input/VelocityControl.h>
#include <input/VelocityTracker.h>
-#include <utils/Thread.h>
+#include <utils/Errors.h>
#include <utils/RefBase.h>
#include <stddef.h>
@@ -44,7 +44,16 @@
namespace android {
-/* Processes raw input events and sends cooked event data to an input listener. */
+// --- InputReaderInterface ---
+
+/* The interface for the InputReader shared library.
+ *
+ * Manages one or more threads that process raw input events and sends cooked event data to an
+ * input listener.
+ *
+ * The implementation must guarantee thread safety for this interface. However, since the input
+ * listener is NOT thread safe, all calls to the listener must happen from the same thread.
+ */
class InputReaderInterface : public virtual RefBase {
protected:
InputReaderInterface() { }
@@ -56,18 +65,17 @@
* This method may be called on any thread (usually by the input manager). */
virtual void dump(std::string& dump) = 0;
- /* Called by the heatbeat to ensures that the reader has not deadlocked. */
+ /* Called by the heartbeat to ensures that the reader has not deadlocked. */
virtual void monitor() = 0;
/* Returns true if the input device is enabled. */
virtual bool isInputDeviceEnabled(int32_t deviceId) = 0;
- /* Runs a single iteration of the processing loop.
- * Nominally reads and processes one incoming message from the EventHub.
- *
- * This method should be called on the input reader thread.
- */
- virtual void loopOnce() = 0;
+ /* Makes the reader start processing events from the kernel. */
+ virtual status_t start() = 0;
+
+ /* Makes the reader stop processing any more events. */
+ virtual status_t stop() = 0;
/* Gets information about all input devices.
*
@@ -104,17 +112,7 @@
virtual bool canDispatchToDisplay(int32_t deviceId, int32_t displayId) = 0;
};
-/* Reads raw events from the event hub and processes them, endlessly. */
-class InputReaderThread : public Thread {
-public:
- explicit InputReaderThread(const sp<InputReaderInterface>& reader);
- virtual ~InputReaderThread();
-
-private:
- sp<InputReaderInterface> mReader;
-
- virtual bool threadLoop();
-};
+// --- InputReaderConfiguration ---
/*
* Input reader configuration.
@@ -285,6 +283,8 @@
std::vector<DisplayViewport> mDisplays;
};
+// --- TouchAffineTransformation ---
+
struct TouchAffineTransformation {
float x_scale;
float x_ymix;
@@ -307,6 +307,8 @@
void applyTo(float& x, float& y) const;
};
+// --- InputReaderPolicyInterface ---
+
/*
* Input reader policy interface.
*
@@ -316,8 +318,8 @@
* The actual implementation is partially supported by callbacks into the DVM
* via JNI. This interface is also mocked in the unit tests.
*
- * These methods must NOT re-enter the input reader since they may be called while
- * holding the input reader lock.
+ * These methods will NOT re-enter the input reader interface, so they may be called from
+ * any method in the input reader interface.
*/
class InputReaderPolicyInterface : public virtual RefBase {
protected: