Merge changes from topic "rs_vndk_step3"

* changes:
  Mark RS libs as VNDK-SP
  Vendor lib can use rsDispatch.h
diff --git a/Android.bp b/Android.bp
index 2694e52..d9f46fa 100644
--- a/Android.bp
+++ b/Android.bp
@@ -17,6 +17,11 @@
 
 cc_library_shared {
     name: "libRSDriver",
+    vendor_available: true,
+    vndk: {
+        enabled: true,
+        support_system_process: true,
+    },
     defaults: ["rs_defaults"],
 
     srcs: [
@@ -55,6 +60,14 @@
         "libbcinfo",
     ],
 
+    static_libs: ["libarect"],
+
+    header_libs: [
+        "libcutils_headers",
+        "libutils_headers",
+        "libnativebase_headers",
+    ],
+
     product_variables: {
         pdk: {
             enabled: false,
@@ -120,6 +133,11 @@
 
 cc_library_shared {
     name: "libRS_internal",
+    vendor_available: true,
+    vndk: {
+        enabled: true,
+        support_system_process: true,
+    },
     defaults: ["rs_defaults"],
 
     srcs: [
@@ -188,6 +206,8 @@
         "libmediandk",
     ],
 
+    static_libs: ["libarect"],
+
     // These runtime modules, including libcompiler_rt.so, are required for
     // RenderScript.
     required: [
@@ -226,6 +246,11 @@
 cc_library_shared {
     name: "libRS",
     defaults: ["rs_defaults"],
+    vendor_available: true,
+    vndk: {
+        enabled: true,
+        support_system_process: true,
+    },
 
     srcs: [
         "rsApiStubs.cpp",
diff --git a/cpp/Android.bp b/cpp/Android.bp
index 710c690..fabb9cb 100644
--- a/cpp/Android.bp
+++ b/cpp/Android.bp
@@ -1,19 +1,25 @@
 cc_library_static {
     name: "libRSDispatch",
+    vendor_available: true,
 
     srcs: ["rsDispatch.cpp"],
 
-    include_dirs: ["frameworks/rs"],
+    include_dirs: [
+        "frameworks/rs",
+        "libnativehelper/include_jni",
+    ],
 
     cflags: [
         "-Wall",
         "-Werror",
         "-Wno-unused-parameter",
         "-std=c++11",
+        "-DRS_COMPATIBILITY_LIB",
     ],
 
+
     sdk_version: "9",
-    shared_libs: ["libdl"],
+    shared_libs: ["libdl", "liblog"],
     // Used in librsjni, which is built as NDK code => no ASan.
     sanitize: {
         never: true,
diff --git a/cpp/rsDispatch.h b/cpp/rsDispatch.h
index 1bcd954..953ba6b 100644
--- a/cpp/rsDispatch.h
+++ b/cpp/rsDispatch.h
@@ -18,7 +18,6 @@
 #define ANDROID_RSDISPATCH_H
 
 #include "rsInternalDefines.h"
-#include "jni.h"
 
 typedef void (*SetNativeLibDirFnPtr)(RsContext con, const char *nativeLibDir, size_t length);
 typedef const void* (*AllocationGetTypeFnPtr)(RsContext con, RsAllocation va);
@@ -263,6 +262,9 @@
 
 bool loadSymbols(void* handle, dispatchTable& dispatchTab, int device_api = 0);
 
+#ifdef RS_COMPATIBILITY_LIB
+#include "jni.h"
+
 // USAGE_IO for RS Support lib
 typedef void (*sAllocationSetSurfaceFnPtr) (JNIEnv *, jobject, RsContext, RsAllocation, RsNativeWindow, dispatchTable);
 struct ioSuppDT {
@@ -271,4 +273,6 @@
 };
 
 bool loadIOSuppSyms(void* handleIO, ioSuppDT& ioDispatch);
-#endif
\ No newline at end of file
+#endif // RS_COMPATIBILITY_LIB
+
+#endif
diff --git a/cpu_ref/Android.bp b/cpu_ref/Android.bp
index 84b2b0b..e929a9c 100644
--- a/cpu_ref/Android.bp
+++ b/cpu_ref/Android.bp
@@ -1,6 +1,11 @@
 cc_library_shared {
     name: "libRSCpuRef",
     defaults: ["libbcc-targets"],
+    vendor_available: true,
+    vndk: {
+        enabled: true,
+        support_system_process: true,
+    },
 
     srcs: [
         "rsCpuCore.cpp",
@@ -97,6 +102,10 @@
         "libblas",
     ],
     static_libs: ["libbnnmlowp"],
+    header_libs: [
+        "libutils_headers",
+        "libhardware_headers",
+    ],
 
     include_dirs: [
         "frameworks/compile/libbcc/include",
diff --git a/cpu_ref/rsCpuExecutable.cpp b/cpu_ref/rsCpuExecutable.cpp
index c42ea0f..9dcc842 100644
--- a/cpu_ref/rsCpuExecutable.cpp
+++ b/cpu_ref/rsCpuExecutable.cpp
@@ -9,11 +9,11 @@
 
 #ifdef RS_COMPATIBILITY_LIB
 #include <stdio.h>
-#include <unistd.h>
 #else
 #include "bcc/Config.h"
 #endif
 
+#include <unistd.h>
 #include <dlfcn.h>
 #include <sys/stat.h>
 
diff --git a/driver/rsdAllocation.cpp b/driver/rsdAllocation.cpp
index 8bdd75b..6b59d1c 100644
--- a/driver/rsdAllocation.cpp
+++ b/driver/rsdAllocation.cpp
@@ -30,6 +30,8 @@
 #include <GLES/glext.h>
 #endif
 
+#include <unistd.h> // for close()
+
 using android::renderscript::Allocation;
 using android::renderscript::Context;
 using android::renderscript::Element;
diff --git a/support/jni/Android.bp b/support/jni/Android.bp
index 3c01fd0..e576fce 100644
--- a/support/jni/Android.bp
+++ b/support/jni/Android.bp
@@ -63,6 +63,7 @@
         "-Wextra",
         "-Wno-unused-parameter",
         "-std=c++11",
+        "-DRS_COMPATIBILITY_LIB",
     ],
 
     required: ["libRSSupport"],