configstore: add configstore@1.0 HAL

This change adds configstore@1.0 HAL which provides static configuration values
to the framework. As a first attempt, a configuration item in the
surfaceflinger (VSYNC_EVENT_PHASE_OFFSET_NS) is choosen and converted to
a HAL function named vsyncEventPhaseoffsetNs().

Design doc: go/design-confighal

Bug: 34314793
Test: build & run. make sure that configstore is up and running.
$ ps -A | grep configstore
Change-Id: Ibc70b14176d2e0144a5745d71ceba49ebc3ca706
diff --git a/configstore/1.0/default/Android.mk b/configstore/1.0/default/Android.mk
new file mode 100644
index 0000000..5de3451
--- /dev/null
+++ b/configstore/1.0/default/Android.mk
@@ -0,0 +1,40 @@
+LOCAL_PATH := $(call my-dir)
+
+################################################################################
+include $(CLEAR_VARS)
+LOCAL_MODULE := android.hardware.configstore@1.0-impl
+LOCAL_MODULE_CLASS := SHARED_LIBRARIES
+LOCAL_MODULE_RELATIVE_PATH := hw
+
+include $(LOCAL_PATH)/surfaceflinger.mk
+
+LOCAL_SHARED_LIBRARIES := \
+    libbase \
+    libhidlbase \
+    libhidltransport \
+    libhwbinder \
+    libutils \
+    android.hardware.configstore@1.0 \
+    android.hidl.base@1.0
+
+include $(BUILD_SHARED_LIBRARY)
+
+################################################################################
+include $(CLEAR_VARS)
+LOCAL_MODULE := android.hardware.configstore@1.0-service
+LOCAL_MODULE_CLASS := EXECUTABLES
+LOCAL_MODULE_RELATIVE_PATH := hw
+LOCAL_INIT_RC := android.hardware.configstore@1.0-service.rc
+LOCAL_SRC_FILES:= service.cpp
+
+LOCAL_SHARED_LIBRARIES := \
+    liblog \
+    libdl \
+    libutils \
+    libhidlbase \
+    libhidltransport \
+    libhwbinder \
+    android.hardware.configstore@1.0 \
+
+include $(BUILD_EXECUTABLE)
+
diff --git a/configstore/1.0/default/SurfaceFlingerConfigs.cpp b/configstore/1.0/default/SurfaceFlingerConfigs.cpp
new file mode 100644
index 0000000..fc75182
--- /dev/null
+++ b/configstore/1.0/default/SurfaceFlingerConfigs.cpp
@@ -0,0 +1,33 @@
+#include "SurfaceFlingerConfigs.h"
+
+#include <android-base/logging.h>
+
+namespace android {
+namespace hardware {
+namespace configstore {
+namespace V1_0 {
+namespace implementation {
+
+// Methods from ::android::hardware::configstore::V1_0::ISurfaceFlingerConfigs follow.
+Return<void> SurfaceFlingerConfigs::vsyncEventPhaseOffsetNs(vsyncEventPhaseOffsetNs_cb _hidl_cb) {
+#ifdef VSYNC_EVENT_PHASE_OFFSET_NS
+    _hidl_cb({true, VSYNC_EVENT_PHASE_OFFSET_NS});
+    LOG(INFO) << "vsync event phase offset ns =  " << VSYNC_EVENT_PHASE_OFFSET_NS;
+#else
+    _hidl_cb({false, 0});
+#endif
+    return Void();
+}
+
+
+// Methods from ::android::hidl::base::V1_0::IBase follow.
+
+ISurfaceFlingerConfigs* HIDL_FETCH_ISurfaceFlingerConfigs(const char* /* name */) {
+    return new SurfaceFlingerConfigs();
+}
+
+}  // namespace implementation
+}  // namespace V1_0
+}  // namespace configstore
+}  // namespace hardware
+}  // namespace android
diff --git a/configstore/1.0/default/SurfaceFlingerConfigs.h b/configstore/1.0/default/SurfaceFlingerConfigs.h
new file mode 100644
index 0000000..5c754a0
--- /dev/null
+++ b/configstore/1.0/default/SurfaceFlingerConfigs.h
@@ -0,0 +1,41 @@
+#ifndef ANDROID_HARDWARE_CONFIGSTORE_V1_0_SURFACEFLINGERCONFIGS_H
+#define ANDROID_HARDWARE_CONFIGSTORE_V1_0_SURFACEFLINGERCONFIGS_H
+
+#include <android/hardware/configstore/1.0/ISurfaceFlingerConfigs.h>
+#include <hidl/MQDescriptor.h>
+#include <hidl/Status.h>
+
+namespace android {
+namespace hardware {
+namespace configstore {
+namespace V1_0 {
+namespace implementation {
+
+using ::android::hardware::configstore::V1_0::ISurfaceFlingerConfigs;
+using ::android::hardware::configstore::V1_0::OptionalBool;
+using ::android::hidl::base::V1_0::IBase;
+using ::android::hardware::hidl_array;
+using ::android::hardware::hidl_memory;
+using ::android::hardware::hidl_string;
+using ::android::hardware::hidl_vec;
+using ::android::hardware::Return;
+using ::android::hardware::Void;
+using ::android::sp;
+
+struct SurfaceFlingerConfigs : public ISurfaceFlingerConfigs {
+    // Methods from ::android::hardware::configstore::V1_0::ISurfaceFlingerConfigs follow.
+    Return<void> vsyncEventPhaseOffsetNs(vsyncEventPhaseOffsetNs_cb _hidl_cb) override;
+
+    // Methods from ::android::hidl::base::V1_0::IBase follow.
+
+};
+
+extern "C" ISurfaceFlingerConfigs* HIDL_FETCH_ISurfaceFlingerConfigs(const char* name);
+
+}  // namespace implementation
+}  // namespace V1_0
+}  // namespace configstore
+}  // namespace hardware
+}  // namespace android
+
+#endif  // ANDROID_HARDWARE_CONFIGSTORE_V1_0_SURFACEFLINGERCONFIGS_H
diff --git a/configstore/1.0/default/android.hardware.configstore@1.0-service.rc b/configstore/1.0/default/android.hardware.configstore@1.0-service.rc
new file mode 100644
index 0000000..2e303b0
--- /dev/null
+++ b/configstore/1.0/default/android.hardware.configstore@1.0-service.rc
@@ -0,0 +1,4 @@
+service configstore-hal-1-0 /system/bin/hw/android.hardware.configstore@1.0-service
+    class hal
+    user system
+    group system
diff --git a/configstore/1.0/default/service.cpp b/configstore/1.0/default/service.cpp
new file mode 100644
index 0000000..caec0ba
--- /dev/null
+++ b/configstore/1.0/default/service.cpp
@@ -0,0 +1,34 @@
+/*
+ * Copyright (C) 2017 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.
+ */
+
+#define LOG_TAG "android.hardware.configstore@1.0-service"
+
+#include <android/hardware/configstore/1.0/ISurfaceFlingerConfigs.h>
+#include <hidl/LegacySupport.h>
+
+using android::hardware::configstore::V1_0::ISurfaceFlingerConfigs;
+using android::hardware::configureRpcThreadpool;
+using android::hardware::registerPassthroughServiceImplementation;
+using android::hardware::joinRpcThreadpool;
+
+int main() {
+    // TODO(b/34857894): tune the max thread count.
+    configureRpcThreadpool(10, true);
+    registerPassthroughServiceImplementation<ISurfaceFlingerConfigs>();
+    // other interface registration comes here
+    joinRpcThreadpool();
+    return 0;
+}
diff --git a/configstore/1.0/default/surfaceflinger.mk b/configstore/1.0/default/surfaceflinger.mk
new file mode 100644
index 0000000..42fa191
--- /dev/null
+++ b/configstore/1.0/default/surfaceflinger.mk
@@ -0,0 +1,6 @@
+
+LOCAL_SRC_FILES += SurfaceFlingerConfigs.cpp
+
+ifneq ($(VSYNC_EVENT_PHASE_OFFSET_NS),)
+    LOCAL_CFLAGS += -DVSYNC_EVENT_PHASE_OFFSET_NS=$(VSYNC_EVENT_PHASE_OFFSET_NS)
+endif