Merge "Add API check for loadSymbols(), so that functions being dlsymed will depend on the device API level. (default: only load functions in API <= 21);"
diff --git a/cpp/rsDispatch.cpp b/cpp/rsDispatch.cpp
index f5f52a5..e0d6788 100644
--- a/cpp/rsDispatch.cpp
+++ b/cpp/rsDispatch.cpp
@@ -21,7 +21,7 @@
 
 #define LOG_API(...)
 
-bool loadSymbols(void* handle, dispatchTable& dispatchTab) {
+bool loadSymbols(void* handle, dispatchTable& dispatchTab, int device_api) {
     //fucntion to set the native lib path for 64bit compat lib.
 #ifdef __LP64__
     dispatchTab.SetNativeLibDir = (SetNativeLibDirFnPtr)dlsym(handle, "rsaContextSetNativeLibDir");
@@ -320,11 +320,6 @@
         LOG_API("Couldn't initialize dispatchTab.ScriptKernelIDCreate");
         return false;
     }
-    dispatchTab.ScriptInvokeIDCreate = (ScriptInvokeIDCreateFnPtr)dlsym(handle, "rsScriptInvokeIDCreate");
-    if (dispatchTab.ScriptInvokeIDCreate == NULL) {
-        LOG_API("Couldn't initialize dispatchTab.ScriptInvokeIDCreate");
-        // return false;
-    }
     dispatchTab.ScriptFieldIDCreate = (ScriptFieldIDCreateFnPtr)dlsym(handle, "rsScriptFieldIDCreate");
     if (dispatchTab.ScriptFieldIDCreate == NULL) {
         LOG_API("Couldn't initialize dispatchTab.ScriptFieldIDCreate");
@@ -366,7 +361,38 @@
         return false;
     }
 
+    // API_23 functions
+    if (device_api >= 23) {
+        //ScriptGroup V2 functions
+        dispatchTab.ScriptInvokeIDCreate = (ScriptInvokeIDCreateFnPtr)dlsym(handle, "rsScriptInvokeIDCreate");
+        if (dispatchTab.ScriptInvokeIDCreate == NULL) {
+            LOG_API("Couldn't initialize dispatchTab.ScriptInvokeIDCreate");
+            return false;
+        }
+        dispatchTab.ClosureCreate = (ClosureCreateFnPtr)dlsym(handle, "rsClosureCreate");
+        if (dispatchTab.ClosureCreate == NULL) {
+            LOG_API("Couldn't initialize dispatchTab.ClosureCreate");
+            return false;
+        }
+        dispatchTab.ClosureSetArg = (ClosureSetArgFnPtr)dlsym(handle, "rsClosureSetArg");
+        if (dispatchTab.ClosureSetArg == NULL) {
+            LOG_API("Couldn't initialize dispatchTab.ClosureSetArg");
+            return false;
+        }
+        dispatchTab.ClosureSetGlobal = (ClosureSetGlobalFnPtr)dlsym(handle, "rsClosureSetGlobal");
+        if (dispatchTab.ClosureSetGlobal == NULL) {
+            LOG_API("Couldn't initialize dispatchTab.ClosureSetGlobal");
+            return false;
+        }
+        dispatchTab.ScriptGroup2Create = (ScriptGroup2CreateFnPtr)dlsym(handle, "rsScriptGroup2Create");
+        if (dispatchTab.ScriptGroup2Create == NULL) {
+            LOG_API("Couldn't initialize dispatchTab.ScriptGroup2Create");
+            return false;
+        }
+    }
+
     return true;
+
 }
 
 
diff --git a/cpp/rsDispatch.h b/cpp/rsDispatch.h
index 066018d..c1c8d77 100644
--- a/cpp/rsDispatch.h
+++ b/cpp/rsDispatch.h
@@ -173,7 +173,7 @@
     AllocationGetPointerFnPtr AllocationGetPointer;
 };
 
-bool loadSymbols(void* handle, dispatchTable& dispatchTab);
+bool loadSymbols(void* handle, dispatchTable& dispatchTab, int device_api = 0);
 
 //USAGE_IO for RS Support lib
 typedef void (*sAllocationSetSurfaceFnPtr) (JNIEnv *, jobject, RsContext, RsAllocation, RsNativeWindow, dispatchTable);