exp/audio/al: use the correct native library dir to locate libopenal.so

Use Context.getApplicationInfo().nativeLibraryDir to locate
libopenal.so. That path is always correct, even on newer devices.

Found while testing external NDK use on Windows.

Manually tested; there are no existing OpenAL tests or examples.

Change-Id: Ie204a7d7139566f85c9121126722ad597f9d6b19
Reviewed-on: https://go-review.googlesource.com/35175
Reviewed-by: Hyang-Ah Hana Kim <hyangah@gmail.com>
This commit is contained in:
Elias Naur 2017-01-13 01:00:38 +01:00
parent 91f2c8983e
commit 64505ab867
1 changed files with 10 additions and 7 deletions

View File

@ -18,15 +18,18 @@ void al_init(uintptr_t java_vm, uintptr_t jni_env, jobject context, void** handl
JNIEnv* env = (JNIEnv*)jni_env;
jclass android_content_Context = (*env)->FindClass(env, "android/content/Context");
jmethodID get_package_name = (*env)->GetMethodID(env, android_content_Context, "getPackageName", "()Ljava/lang/String;");
jstring package_name = (*env)->CallObjectMethod(env, context, get_package_name);
const char *cpackage_name = (*env)->GetStringUTFChars(env, package_name, 0);
jmethodID get_application_info = (*env)->GetMethodID(env, android_content_Context, "getApplicationInfo", "()Landroid/content/pm/ApplicationInfo;");
jclass android_content_pm_ApplicationInfo = (*env)->FindClass(env, "android/content/pm/ApplicationInfo");
jfieldID native_library_dir = (*env)->GetFieldID(env, android_content_pm_ApplicationInfo, "nativeLibraryDir", "Ljava/lang/String;");
jobject app_info = (*env)->CallObjectMethod(env, context, get_application_info);
jstring native_dir = (*env)->GetObjectField(env, app_info, native_library_dir);
const char *cnative_dir = (*env)->GetStringUTFChars(env, native_dir, 0);
char lib_path[PATH_MAX] = "/data/data/";
strlcat(lib_path, cpackage_name, sizeof(lib_path));
strlcat(lib_path, "/lib/libopenal.so", sizeof(lib_path));
char lib_path[PATH_MAX] = "";
strlcat(lib_path, cnative_dir, sizeof(lib_path));
strlcat(lib_path, "/libopenal.so", sizeof(lib_path));
*handle = dlopen(lib_path, RTLD_LAZY);
(*env)->ReleaseStringUTFChars(env, package_name, cpackage_name);
(*env)->ReleaseStringUTFChars(env, native_dir, cnative_dir);
}
void call_alEnable(LPALENABLE fn, ALenum capability) {