Add VR 1.0 hal.

Bug: 31442830
Test: make all and tested VR mode on a device.
Change-Id: Icff8478c27184661d687d970d5b6759bff21beff
diff --git a/vr/1.0/Android.bp b/vr/1.0/Android.bp
new file mode 100644
index 0000000..8fd00c5
--- /dev/null
+++ b/vr/1.0/Android.bp
@@ -0,0 +1,42 @@
+// This file is autogenerated by hidl-gen. Do not edit manually.
+
+genrule {
+    name: "android.hardware.vr@1.0_genc++",
+    tool: "hidl-gen",
+    cmd: "$tool -o $genDir -Lc++ -randroid.hardware:hardware/interfaces android.hardware.vr@1.0",
+    srcs: [
+        "IVr.hal",
+    ],
+    out: [
+        "android/hardware/vr/1.0/VrAll.cpp",
+    ],
+}
+
+genrule {
+    name: "android.hardware.vr@1.0_genc++_headers",
+    tool: "hidl-gen",
+    cmd: "$tool -o $genDir -Lc++ -randroid.hardware:hardware/interfaces android.hardware.vr@1.0",
+    srcs: [
+        "IVr.hal",
+    ],
+    out: [
+        "android/hardware/vr/1.0/IVr.h",
+        "android/hardware/vr/1.0/IHwVr.h",
+        "android/hardware/vr/1.0/BnVr.h",
+        "android/hardware/vr/1.0/BpVr.h",
+        "android/hardware/vr/1.0/BsVr.h",
+    ],
+}
+
+cc_library_shared {
+    name: "android.hardware.vr@1.0",
+    generated_sources: ["android.hardware.vr@1.0_genc++"],
+    generated_headers: ["android.hardware.vr@1.0_genc++_headers"],
+    export_generated_headers: ["android.hardware.vr@1.0_genc++_headers"],
+    shared_libs: [
+        "libhidl",
+        "libhwbinder",
+        "libutils",
+        "libcutils",
+    ],
+}
diff --git a/vr/1.0/IVr.hal b/vr/1.0/IVr.hal
new file mode 100644
index 0000000..1f996e9
--- /dev/null
+++ b/vr/1.0/IVr.hal
@@ -0,0 +1,41 @@
+/*
+ * Copyright (C) 2016 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.
+ */
+
+package android.hardware.vr@1.0;
+
+interface IVr {
+  /**
+   * Convenience method to set up any state needed at runtime startup.  This is
+   * called once from the VrManagerService during its boot phase.
+   */
+  @callflow(next={"*"})
+  @entry
+  @exit
+  init();
+
+  /**
+   * Set the VR mode state.  Possible states of the enabled parameter are:
+   * false - VR mode is disabled, turn off all VR-specific settings.
+   * true - VR mode is enabled, turn on all VR-specific settings.
+   *
+   * This must be called whenever the the Android system enters or leaves VR
+   * mode. This will typically occur when the user switches to or from a VR
+   * application that is doing stereoscopic rendering.
+   */
+  @callflow(next={"*"})
+  @exit
+  setVrMode(bool enabled);
+};
diff --git a/vr/1.0/default/Android.bp b/vr/1.0/default/Android.bp
new file mode 100644
index 0000000..09b0002
--- /dev/null
+++ b/vr/1.0/default/Android.bp
@@ -0,0 +1,16 @@
+cc_library_shared {
+    name: "android.hardware.vr@1.0-impl",
+    relative_install_path: "hw",
+    srcs: ["Vr.cpp"],
+    shared_libs: [
+        "liblog",
+        "libcutils",
+        "libhardware",
+        "libhwbinder",
+        "libbase",
+        "libcutils",
+        "libutils",
+        "libhidl",
+        "android.hardware.vr@1.0",
+    ],
+}
diff --git a/vr/1.0/default/Vr.cpp b/vr/1.0/default/Vr.cpp
new file mode 100644
index 0000000..4b2c603
--- /dev/null
+++ b/vr/1.0/default/Vr.cpp
@@ -0,0 +1,60 @@
+/*
+ * Copyright (C) 2016 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 "VrService"
+
+#include <hardware/hardware.h>
+#include <hardware/vr.h>
+#include "Vr.h"
+
+namespace android {
+namespace hardware {
+namespace vr {
+namespace V1_0 {
+namespace implementation {
+
+Vr::Vr(vr_module_t *device) : mDevice(device) {}
+
+// Methods from ::android::hardware::vr::V1_0::IVr follow.
+Return<void> Vr::init() {
+    mDevice->init(mDevice);
+    return Void();
+}
+
+Return<void> Vr::setVrMode(bool enabled)  {
+    mDevice->set_vr_mode(mDevice, enabled);
+    return Void();
+}
+
+IVr* HIDL_FETCH_IVr(const char *name) {
+    vr_module_t *vr_module;
+    const hw_module_t *hw_module = NULL;
+
+    int ret = hw_get_module(name, &hw_module);
+    if (ret == 0) {
+        return new Vr(reinterpret_cast<vr_module_t*>(
+                const_cast<hw_module_t*>(hw_module)));
+    } else {
+        ALOGE("hw_get_module %s failed: %d", name, ret);
+        return nullptr;
+    }
+}
+
+} // namespace implementation
+}  // namespace V1_0
+}  // namespace vr
+}  // namespace hardware
+}  // namespace android
diff --git a/vr/1.0/default/Vr.h b/vr/1.0/default/Vr.h
new file mode 100644
index 0000000..90694d9
--- /dev/null
+++ b/vr/1.0/default/Vr.h
@@ -0,0 +1,51 @@
+/*
+ * Copyright (C) 2016 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.
+ */
+#ifndef HIDL_GENERATED_android_hardware_vr_V1_0_Vr_H_
+#define HIDL_GENERATED_android_hardware_vr_V1_0_Vr_H_
+
+#include <android/hardware/vr/1.0/IVr.h>
+#include <hardware/vr.h>
+#include <hidl/MQDescriptor.h>
+
+namespace android {
+namespace hardware {
+namespace vr {
+namespace V1_0 {
+namespace implementation {
+
+using ::android::hardware::vr::V1_0::IVr;
+using ::android::hardware::Return;
+
+struct Vr : public IVr {
+    Vr(vr_module_t *device);
+
+    // Methods from ::android::hardware::vr::V1_0::IVr follow.
+    Return<void> init()  override;
+    Return<void> setVrMode(bool enabled)  override;
+
+  private:
+    vr_module_t    *mDevice;
+};
+
+extern "C" IVr* HIDL_FETCH_IVr(const char* name);
+
+}  // namespace implementation
+}  // namespace V1_0
+}  // namespace vr
+}  // namespace hardware
+}  // namespace android
+
+#endif  // HIDL_GENERATED_android_hardware_vr_V1_0_Vr_H_
diff --git a/vr/1.0/default/android.hardware.vr@1.0-service.rc b/vr/1.0/default/android.hardware.vr@1.0-service.rc
new file mode 100644
index 0000000..6177089
--- /dev/null
+++ b/vr/1.0/default/android.hardware.vr@1.0-service.rc
@@ -0,0 +1,4 @@
+service vr-1-0 /system/bin/hw/android.hardware.vr@1.0-service
+    class hal
+    user system
+    group system readproc
diff --git a/vr/1.0/default/service.cpp b/vr/1.0/default/service.cpp
new file mode 100644
index 0000000..c27ceaf
--- /dev/null
+++ b/vr/1.0/default/service.cpp
@@ -0,0 +1,27 @@
+/*
+ * Copyright (C) 2016 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.vr@1.0-service"
+
+#include <android/hardware/vr/1.0/IVr.h>
+#include <hidl/LegacySupport.h>
+
+// Generated HIDL files
+using android::hardware::vr::V1_0::IVr;
+using android::hardware::defaultPassthroughServiceImplementation;
+
+int main() {
+    return defaultPassthroughServiceImplementation<IVr>("vr");
+}