[Renderscript] Set native lib path from java RS context for rs compat lib.

Change-Id: I84c3659bffa34d3fa07f14a7b423ed06c5315855
diff --git a/v8/renderscript/java/src/android/support/v8/renderscript/RenderScript.java b/v8/renderscript/java/src/android/support/v8/renderscript/RenderScript.java
index a577e08..af6476b 100644
--- a/v8/renderscript/java/src/android/support/v8/renderscript/RenderScript.java
+++ b/v8/renderscript/java/src/android/support/v8/renderscript/RenderScript.java
@@ -49,6 +49,7 @@
     static final boolean LOG_ENABLED = false;
 
     private Context mApplicationContext;
+    private String mNativeLibDir;
 
     /*
      * We use a class initializer to allow the native code to cache some
@@ -212,9 +213,9 @@
     // Methods below are wrapped to protect the non-threadsafe
     // lockless fifo.
 
-    native long  rsnContextCreate(long dev, int ver, int sdkVer, int contextType);
-    synchronized long nContextCreate(long dev, int ver, int sdkVer, int contextType) {
-        return rsnContextCreate(dev, ver, sdkVer, contextType);
+    native long  rsnContextCreate(long dev, int ver, int sdkVer, int contextType, String nativeLibDir);
+    synchronized long nContextCreate(long dev, int ver, int sdkVer, int contextType, String nativeLibDir) {
+        return rsnContextCreate(dev, ver, sdkVer, contextType, nativeLibDir);
     }
     native void rsnContextDestroy(long con);
     synchronized void nContextDestroy() {
@@ -981,6 +982,7 @@
     RenderScript(Context ctx) {
         if (ctx != null) {
             mApplicationContext = ctx.getApplicationContext();
+            mNativeLibDir = mApplicationContext.getApplicationInfo().nativeLibraryDir;
         }
         mRWLock = new ReentrantReadWriteLock();
     }
@@ -1040,6 +1042,7 @@
                 }
             }
         }
+
         if (useNative) {
             android.util.Log.v(LOG_TAG, "RS native mode");
         } else {
@@ -1075,8 +1078,9 @@
                 useIOlib = false;
             }
         }
+
         rs.mDev = rs.nDeviceCreate();
-        rs.mContext = rs.nContextCreate(rs.mDev, 0, sdkVersion, ct.mID);
+        rs.mContext = rs.nContextCreate(rs.mDev, 0, sdkVersion, ct.mID, rs.mNativeLibDir);
         if (rs.mContext == 0) {
             throw new RSDriverException("Failed to create RS context.");
         }
diff --git a/v8/renderscript/jni/android_renderscript_RenderScript.cpp b/v8/renderscript/jni/android_renderscript_RenderScript.cpp
index a511993..ac963c2 100644
--- a/v8/renderscript/jni/android_renderscript_RenderScript.cpp
+++ b/v8/renderscript/jni/android_renderscript_RenderScript.cpp
@@ -126,6 +126,7 @@
     }
     return true;
 }
+
 // ---------------------------------------------------------------------------
 
 static void
@@ -223,7 +224,6 @@
 }
 
 // ---------------------------------------------------------------------------
-
 static jlong
 nDeviceCreate(JNIEnv *_env, jobject _this)
 {
@@ -246,12 +246,23 @@
 }
 
 static jlong
-nContextCreate(JNIEnv *_env, jobject _this, jlong dev, jint ver, jint sdkVer, jint ct)
+nContextCreate(JNIEnv *_env, jobject _this, jlong dev, jint ver, jint sdkVer,
+               jint ct, jstring nativeLibDirJava)
 {
     LOG_API("nContextCreate");
-    return (jlong)(uintptr_t)dispatchTab.ContextCreate((RsDevice)dev, ver,
-                                                       sdkVer,
-                                                       (RsContextType)ct, 0);
+    // Access the NativeLibDir in the Java Context.
+    const char * nativeLibDir = _env->GetStringUTFChars(nativeLibDirJava, JNI_FALSE);
+    size_t length = (size_t)_env->GetStringUTFLength(nativeLibDirJava);
+
+    jlong id = (jlong)(uintptr_t)dispatchTab.ContextCreate((RsDevice)dev, ver,
+                                                           sdkVer,
+                                                           (RsContextType)ct, 0);
+    if (dispatchTab.SetNativeLibDir) {
+        dispatchTab.SetNativeLibDir((RsContext)id, nativeLibDir, length);
+    }
+
+    _env->ReleaseStringUTFChars(nativeLibDirJava, nativeLibDir);
+    return id;
 }
 
 
@@ -1325,7 +1336,7 @@
 
 
 // All methods below are thread protected in java.
-{"rsnContextCreate",                 "(JIII)J",                               (void*)nContextCreate },
+{"rsnContextCreate",                 "(JIIILjava/lang/String;)J",             (void*)nContextCreate },
 {"rsnContextFinish",                 "(J)V",                                  (void*)nContextFinish },
 {"rsnContextSetPriority",            "(JI)V",                                 (void*)nContextSetPriority },
 {"rsnContextDestroy",                "(J)V",                                  (void*)nContextDestroy },