Default binderized implementation of android.hardware.nfc@1.0

Provide a default binderized HAL implementation.  The implementation
uses android.hardware.nfc@1.0-impl.so, which in turn loads the
conventional HAL (nfc_nci.default.so).  If a device includes package
android.hardware.nfc@1.0-service, the device will automatically use the
binderized implementation of the NFC HAL.  If a device includes package
android.hardware.nfc@1.0-impl instead, it will use the default
implementation in hardware/interfaces/nfc/1.0/default.

b/31688271
Test: pass

Change-Id: I31cd93d28705d287975b485092cffd7661599d7c
Signed-off-by: Iliyan Malchev <malchev@google.com>
diff --git a/nfc/1.0/default/service.cpp b/nfc/1.0/default/service.cpp
new file mode 100644
index 0000000..8952052
--- /dev/null
+++ b/nfc/1.0/default/service.cpp
@@ -0,0 +1,44 @@
+#define LOG_TAG "android.hardware.nfc@1.0-service"
+#include <utils/Log.h>
+
+#include <iostream>
+#include <unistd.h>
+
+#include <android/hardware/nfc/1.0/INfc.h>
+
+#include <hidl/IServiceManager.h>
+#include <hwbinder/IPCThreadState.h>
+#include <hwbinder/ProcessState.h>
+#include <utils/Errors.h>
+#include <utils/StrongPointer.h>
+
+using android::sp;
+
+// libhwbinder:
+using android::hardware::IPCThreadState;
+using android::hardware::ProcessState;
+
+// Generated HIDL files
+using android::hardware::nfc::V1_0::INfc;
+
+int main() {
+    ALOGI("Service is starting.");
+    const char instance[] = "nfc_nci";
+    ALOGI("Retrieving default implementation of instance %s.",
+          instance);
+    android::sp<INfc> service = INfc::getService(instance, true);
+    if (service.get() == nullptr) {
+        ALOGE("INfc::getService returned NULL, exiting");
+        return -1;
+    }
+    ALOGI("Default implementation using %s is %s",
+          instance, (service->isRemote() ? "REMOTE" : "LOCAL"));
+    LOG_FATAL_IF(service->isRemote(), "Implementation is REMOTE!");
+    ALOGI("Registering instance %s.", instance);
+    service->registerAsService("nfc_nci");
+    ALOGI("Ready.");
+
+    ProcessState::self()->setThreadPoolMaxThreadCount(0);
+    ProcessState::self()->startThreadPool();
+    IPCThreadState::self()->joinThreadPool();
+}