Get rid of dependency on native AssetManager API. Confirmed the native code builds with the NDK r3.

Change-Id: I0d2d3a0e262847d6948a0336a35440e21e312ad2
diff --git a/native/Android.mk b/native/Android.mk
index 3cf6aa8..9524484 100644
--- a/native/Android.mk
+++ b/native/Android.mk
@@ -11,15 +11,8 @@
 LOCAL_C_INCLUDES += \
 	$(JNI_H_INCLUDE)
 
-LOCAL_LDLIBS := -lm
-
 LOCAL_PRELINK_MODULE := false
 
-LOCAL_SHARED_LIBRARIES := \
-    libandroid_runtime \
-    libcutils \
-    libutils
-
 LOCAL_MODULE := libjni_latinime
 
 LOCAL_MODULE_TAGS := user
diff --git a/native/jni/com_android_inputmethod_latin_BinaryDictionary.cpp b/native/jni/com_android_inputmethod_latin_BinaryDictionary.cpp
index d068f3f..bb45cb5 100644
--- a/native/jni/com_android_inputmethod_latin_BinaryDictionary.cpp
+++ b/native/jni/com_android_inputmethod_latin_BinaryDictionary.cpp
@@ -15,31 +15,18 @@
 ** limitations under the License.
 */
 
-#define LOG_TAG "BinaryDictionary"
-#include "utils/Log.h"
-
 #include <stdio.h>
 #include <assert.h>
 #include <unistd.h>
 #include <fcntl.h>
 
-#include <nativehelper/jni.h>
-#include "utils/AssetManager.h"
-#include "utils/Asset.h"
-
+#include <jni.h>
 #include "dictionary.h"
 
 // ----------------------------------------------------------------------------
 
 using namespace latinime;
 
-using namespace android;
-
-static jfieldID sDescriptorField;
-static jfieldID sAssetManagerNativeField;
-static jmethodID sAddWordMethod;
-static jfieldID sDictLength;
-
 //
 // helper function to throw an exception
 //
@@ -54,35 +41,15 @@
 }
 
 static jint latinime_BinaryDictionary_open
-        (JNIEnv *env, jobject object, jobject assetManager, jstring resourceString,
+        (JNIEnv *env, jobject object, jobject dictDirectBuffer,
          jint typedLetterMultiplier, jint fullWordMultiplier)
 {
-    // Get the native file descriptor from the FileDescriptor object
-    AssetManager *am = (AssetManager*) env->GetIntField(assetManager, sAssetManagerNativeField);
-    if (!am) {
-        LOGE("DICT: Couldn't get AssetManager native peer\n");
-        return 0;
-    }
-    const char *resourcePath = env->GetStringUTFChars(resourceString, NULL);
-
-    Asset *dictAsset = am->openNonAsset(resourcePath, Asset::ACCESS_BUFFER);
-    if (dictAsset == NULL) {
-        LOGE("DICT: Couldn't get asset %s\n", resourcePath);
-        env->ReleaseStringUTFChars(resourceString, resourcePath);
-        return 0;
-    }
-
-    void *dict = (void*) dictAsset->getBuffer(false);
+    void *dict = env->GetDirectBufferAddress(dictDirectBuffer);
     if (dict == NULL) {
-        LOGE("DICT: Dictionary buffer is null\n");
-        env->ReleaseStringUTFChars(resourceString, resourcePath);
+        fprintf(stderr, "DICT: Dictionary buffer is null\n");
         return 0;
     }
     Dictionary *dictionary = new Dictionary(dict, typedLetterMultiplier, fullWordMultiplier);
-    dictionary->setAsset(dictAsset);
-    env->SetIntField(object, sDictLength, (jint) dictAsset->getLength());
-
-    env->ReleaseStringUTFChars(resourceString, resourcePath);
     return (jint) dictionary;
 }
 
@@ -131,14 +98,13 @@
         (JNIEnv *env, jobject object, jint dict)
 {
     Dictionary *dictionary = (Dictionary*) dict;
-    ((Asset*) dictionary->getAsset())->close();
     delete (Dictionary*) dict;
 }
 
 // ----------------------------------------------------------------------------
 
 static JNINativeMethod gMethods[] = {
-    {"openNative",           "(Landroid/content/res/AssetManager;Ljava/lang/String;II)I",
+    {"openNative",           "(Ljava/nio/ByteBuffer;II)I",
                                           (void*)latinime_BinaryDictionary_open},
     {"closeNative",          "(I)V",            (void*)latinime_BinaryDictionary_close},
     {"getSuggestionsNative", "(I[II[C[IIIII[II)I",  (void*)latinime_BinaryDictionary_getSuggestions},
@@ -167,30 +133,6 @@
 static int registerNatives(JNIEnv *env)
 {
     const char* const kClassPathName = "com/android/inputmethod/latin/BinaryDictionary";
-    jclass clazz;
-
-    clazz = env->FindClass("java/io/FileDescriptor");
-    if (clazz == NULL) {
-        LOGE("Can't find %s", "java/io/FileDescriptor");
-        return -1;
-    }
-    sDescriptorField = env->GetFieldID(clazz, "descriptor", "I");
-
-    clazz = env->FindClass("android/content/res/AssetManager");
-    if (clazz == NULL) {
-        LOGE("Can't find %s", "java/io/FileDescriptor");
-        return -1;
-    }
-    sAssetManagerNativeField = env->GetFieldID(clazz, "mObject", "I");
-
-    // Get the field pointer for the dictionary length
-    clazz = env->FindClass(kClassPathName);
-    if (clazz == NULL) {
-        LOGE("Can't find %s", kClassPathName);
-        return -1;
-    }
-    sDictLength = env->GetFieldID(clazz, "mDictLength", "I");
-
     return registerNativeMethods(env,
             kClassPathName, gMethods, sizeof(gMethods) / sizeof(gMethods[0]));
 }
diff --git a/native/src/dictionary.cpp b/native/src/dictionary.cpp
index 3f196a9..e75beb5 100644
--- a/native/src/dictionary.cpp
+++ b/native/src/dictionary.cpp
@@ -19,14 +19,8 @@
 #include <fcntl.h>
 #include <sys/mman.h>
 #include <string.h>
-#include <cutils/log.h>
-
-//#define USE_ASSET_MANAGER
-
-#ifdef USE_ASSET_MANAGER
-#include <utils/AssetManager.h>
-#include <utils/Asset.h>
-#endif
+//#include <cutils/log.h>
+#define LOGI
 
 #include "dictionary.h"
 #include "basechars.h"