Create TestInputChannel and TestLooper to better test InputConsumerNoResampling

Created TestInputChannel and TestLooper to control how InputMessages are
batched in InputConsumerNoResampling_test

Bug: 297226446
Flag: EXEMPT refactor
Test: TEST=libinput_tests; m $TEST && $ANDROID_HOST_OUT/nativetest64/$TEST/$TEST --gtest_filter="InputConsumerTest*"
Change-Id: I036593b311a93ec301e8b9776b461505e853119f
diff --git a/libs/input/InputConsumerNoResampling.cpp b/libs/input/InputConsumerNoResampling.cpp
index 99ffa68..eb41918 100644
--- a/libs/input/InputConsumerNoResampling.cpp
+++ b/libs/input/InputConsumerNoResampling.cpp
@@ -14,7 +14,7 @@
  * limitations under the License.
  */
 
-#define LOG_TAG "InputTransport"
+#define LOG_TAG "InputConsumerNoResampling"
 #define ATRACE_TAG ATRACE_TAG_INPUT
 
 #include <chrono>
@@ -33,8 +33,6 @@
 #include <input/PrintTools.h>
 #include <input/TraceTools.h>
 
-namespace input_flags = com::android::input::flags;
-
 namespace android {
 
 namespace {
@@ -46,6 +44,27 @@
 const bool DEBUG_TRANSPORT_CONSUMER =
         __android_log_is_loggable(ANDROID_LOG_DEBUG, LOG_TAG "Consumer", ANDROID_LOG_INFO);
 
+/**
+ * RealLooper is a wrapper of Looper. All the member functions exclusively call the internal looper.
+ * This class' behavior is the same as Looper.
+ */
+class RealLooper final : public LooperInterface {
+public:
+    RealLooper(sp<Looper> looper) : mLooper{looper} {}
+
+    int addFd(int fd, int ident, int events, const sp<LooperCallback>& callback,
+              void* data) override {
+        return mLooper->addFd(fd, ident, events, callback, data);
+    }
+
+    int removeFd(int fd) override { return mLooper->removeFd(fd); }
+
+    sp<Looper> getLooper() const override { return mLooper; }
+
+private:
+    sp<Looper> mLooper;
+};
+
 std::unique_ptr<KeyEvent> createKeyEvent(const InputMessage& msg) {
     std::unique_ptr<KeyEvent> event = std::make_unique<KeyEvent>();
     event->initialize(msg.body.key.eventId, msg.body.key.deviceId, msg.body.key.source,
@@ -173,22 +192,20 @@
 bool isPointerEvent(const MotionEvent& motionEvent) {
     return (motionEvent.getSource() & AINPUT_SOURCE_CLASS_POINTER) == AINPUT_SOURCE_CLASS_POINTER;
 }
-
 } // namespace
 
 using android::base::Result;
-using android::base::StringPrintf;
 
 // --- InputConsumerNoResampling ---
 
 InputConsumerNoResampling::InputConsumerNoResampling(const std::shared_ptr<InputChannel>& channel,
-                                                     sp<Looper> looper,
+                                                     std::shared_ptr<LooperInterface> looper,
                                                      InputConsumerCallbacks& callbacks,
                                                      std::unique_ptr<Resampler> resampler)
-      : mChannel(channel),
-        mLooper(looper),
+      : mChannel{channel},
+        mLooper{looper},
         mCallbacks(callbacks),
-        mResampler(std::move(resampler)),
+        mResampler{std::move(resampler)},
         mFdEvents(0) {
     LOG_ALWAYS_FATAL_IF(mLooper == nullptr);
     mCallback = sp<LooperEventCallback>::make(
@@ -199,6 +216,13 @@
     setFdEvents(ALOOPER_EVENT_INPUT);
 }
 
+InputConsumerNoResampling::InputConsumerNoResampling(const std::shared_ptr<InputChannel>& channel,
+                                                     sp<Looper> looper,
+                                                     InputConsumerCallbacks& callbacks,
+                                                     std::unique_ptr<Resampler> resampler)
+      : InputConsumerNoResampling(channel, std::make_shared<RealLooper>(looper), callbacks,
+                                  std::move(resampler)) {}
+
 InputConsumerNoResampling::~InputConsumerNoResampling() {
     ensureCalledOnLooperThread(__func__);
     consumeBatchedInputEvents(std::nullopt);
@@ -513,7 +537,7 @@
 
 void InputConsumerNoResampling::ensureCalledOnLooperThread(const char* func) const {
     sp<Looper> callingThreadLooper = Looper::getForThread();
-    if (callingThreadLooper != mLooper) {
+    if (callingThreadLooper != mLooper->getLooper()) {
         LOG(FATAL) << "The function " << func << " can only be called on the looper thread";
     }
 }