Files
MapLibreParticleLab/platform/android/src/attach_env.cpp
Bart Louwers 71f6da2722 Add clang-format (#1086)
Co-authored-by: mwilsnd <mwilsnd@gmail.com>
2023-05-01 16:57:37 +02:00

23 lines
588 B
C++

#include "attach_env.hpp"
#include "jni.hpp"
namespace mbgl {
namespace android {
UniqueEnv AttachEnv() {
JNIEnv* env = nullptr;
jint err = theJVM->GetEnv(reinterpret_cast<void**>(&env), JNI_VERSION_1_6);
switch (err) {
case JNI_OK:
return UniqueEnv(env, JNIEnvDeleter(*theJVM, false));
case JNI_EDETACHED:
return UniqueEnv(jni::AttachCurrentThread(*theJVM).release(), JNIEnvDeleter(*theJVM, true));
default:
throw std::system_error(err, jni::ErrorCategory());
}
}
} // namespace android
} // namespace mbgl