android_frameworks_base/vr/dvr_library_loader.cpp
Steven Thomas 054f235c61 Add vr platform lib
Add the vr platform library, which allows client code to load the dvr
api and access the getVrBoot() method.

Bug: 38134403
Test: Booted a Marlin.

Change-Id: I884a623ec9a297a2973f1c42c3da094c6c155630
2017-05-10 16:54:20 -07:00

26 lines
663 B
C++

#include <dlfcn.h>
#include <jni.h>
#include <string>
extern "C" {
JNIEXPORT jlong JNICALL
Java_com_google_vr_platform_Dvr_nativeLoadLibrary(
JNIEnv* env, jclass, jstring java_library) {
if (!java_library)
return 0;
// Convert the Java String object to a C++ null-terminated string.
const char* data = env->GetStringUTFChars(java_library, NULL);
size_t size = env->GetStringUTFLength(java_library);
std::string library(data, size);
env->ReleaseStringUTFChars(java_library, data);
// Return the handle to the requested library.
return reinterpret_cast<jlong>(
dlopen(library.c_str(), RTLD_NOW | RTLD_LOCAL));
}
} // extern "C"