Use cc_defaults in inputflinger targets

We add a cc_defaults for all of the targets in inputflinger, and include
those defaults in inputflinger_tests. This makes it so that building
the test compiles all of the sources in the test target and includes
them in the executable.

The primary benefit of this refactor is that running the test on any
device will now test the inputflinger code that the test was compiled
with instead of testing the libraries that were on the device. Also,
the device does not need to be re-flashed or need its libraries to be
updated when running the tests after modifying inputflinger code.

Bug: None
Test: atest inputflinger_tests
Change-Id: Ic0406355e5b485c8bf29a65f7c7c37ea8cb68eab
diff --git a/services/inputflinger/tests/Android.bp b/services/inputflinger/tests/Android.bp
index f913d82..73d2272 100644
--- a/services/inputflinger/tests/Android.bp
+++ b/services/inputflinger/tests/Android.bp
@@ -1,7 +1,31 @@
-// Build the unit tests.
+// Copyright (C) 2020 The Android Open Source Project
+//
+// Licensed under the Apache License, Version 2.0 (the "License");
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+//      http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
 
 cc_test {
     name: "inputflinger_tests",
+    defaults: [
+        "inputflinger_defaults",
+        // For all targets inside inputflinger, these tests build all of their sources using their
+        // defaults rather than including them as shared or static libraries. By doing so, the tests
+        // will always run against the compiled version of the inputflinger code rather than the
+        // version on the device.
+        "libinputflinger_base_defaults",
+        "libinputreader_defaults",
+        "libinputreporter_defaults",
+        "libinputdispatcher_defaults",
+        "libinputflinger_defaults",
+    ],
     srcs: [
         "BlockingQueue_test.cpp",
         "EventHub_test.cpp",
@@ -12,31 +36,5 @@
         "InputReader_test.cpp",
         "UinputDevice.cpp",
     ],
-    cflags: [
-        "-Wall",
-        "-Werror",
-        "-Wextra",
-        "-Wno-unused-parameter",
-        "-Wthread-safety",
-    ],
-    shared_libs: [
-        "android.hardware.input.classifier@1.0",
-        "libbase",
-        "libbinder",
-        "libcutils",
-        "liblog",
-        "libutils",
-        "libhardware",
-        "libhardware_legacy",
-        "libui",
-        "libinput",
-        "libinputflinger",
-        "libinputreader",
-        "libinputflinger_base",
-        "libinputservice",
-    ],
-    header_libs: [
-        "libinputreader_headers",
-    ],
     require_root: true,
 }
diff --git a/services/inputflinger/tests/InputReader_test.cpp b/services/inputflinger/tests/InputReader_test.cpp
index f9ebfc0..af11256 100644
--- a/services/inputflinger/tests/InputReader_test.cpp
+++ b/services/inputflinger/tests/InputReader_test.cpp
@@ -1714,7 +1714,7 @@
         mFakePolicy = new FakeInputReaderPolicy();
         mTestListener = new TestInputListener();
 
-        mReader = createInputReader(mFakePolicy, mTestListener);
+        mReader = new InputReader(std::make_shared<EventHub>(), mFakePolicy, mTestListener);
         ASSERT_EQ(mReader->start(), OK);
 
         // Since this test is run on a real device, all the input devices connected