Adding android.hardware.light@2.0 service.

Bug: 32022100
Test: end-to-end
Change-Id: I2d143f3a283e3a230c5ae4999e492f29ffe4234c
diff --git a/light/2.0/default/Android.mk b/light/2.0/default/Android.mk
index b0c46b7..61f4cc9 100644
--- a/light/2.0/default/Android.mk
+++ b/light/2.0/default/Android.mk
@@ -18,3 +18,26 @@
     android.hardware.light@2.0 \
 
 include $(BUILD_SHARED_LIBRARY)
+
+include $(CLEAR_VARS)
+LOCAL_MODULE_RELATIVE_PATH := hw
+LOCAL_MODULE := android.hardware.light@2.0-service
+LOCAL_INIT_RC := android.hardware.light@2.0-service.rc
+LOCAL_SRC_FILES := \
+    service.cpp \
+
+LOCAL_SHARED_LIBRARIES := \
+    liblog \
+    libcutils \
+    libdl \
+    libbase \
+    libutils \
+    libhardware_legacy \
+    libhardware \
+
+LOCAL_SHARED_LIBRARIES += \
+    libhwbinder \
+    libhidl \
+    android.hardware.light@2.0 \
+
+include $(BUILD_EXECUTABLE)
diff --git a/light/2.0/default/android.hardware.light@2.0-service.rc b/light/2.0/default/android.hardware.light@2.0-service.rc
new file mode 100644
index 0000000..4228d95
--- /dev/null
+++ b/light/2.0/default/android.hardware.light@2.0-service.rc
@@ -0,0 +1,4 @@
+service light-hal-2-0 /system/bin/hw/android.hardware.light@2.0-service
+    class hal
+    user system
+    group system readproc
\ No newline at end of file
diff --git a/light/2.0/default/service.cpp b/light/2.0/default/service.cpp
new file mode 100644
index 0000000..582d224
--- /dev/null
+++ b/light/2.0/default/service.cpp
@@ -0,0 +1,46 @@
+#define LOG_TAG "android.hardware.light@2.0-service"
+#include <utils/Log.h>
+
+#include <iostream>
+#include <unistd.h>
+
+#include <android/hardware/light/2.0/ILight.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::light::V2_0::ILight;
+
+int main() {
+    ALOGI("Service is starting.");
+    const char instance[] = "light";
+    ALOGI("Retrieving default implementation of instance %s.",
+          instance);
+
+    android::sp<ILight> service = ILight::getService(instance, true);
+
+    if (service.get() == nullptr) {
+        ALOGE("ILight::getService returned NULL, exiting");
+        return -1;
+    }
+
+    LOG_FATAL_IF(service->isRemote(), "Implementation is REMOTE!");
+
+    ALOGI("Registering instance %s.", instance);
+    service->registerAsService(instance);
+    ALOGI("Ready.");
+
+    ProcessState::self()->setThreadPoolMaxThreadCount(0);
+    ProcessState::self()->startThreadPool();
+    IPCThreadState::self()->joinThreadPool();
+}