| 74 | namespace { |
| 75 | |
| 76 | JNIEnv* attachJniInternal(const char* threadName) { |
| 77 | if (gJvm == nullptr) { |
| 78 | return nullptr; |
| 79 | } |
| 80 | JavaVMAttachArgs args{}; |
| 81 | args.version = JNI_VERSION_1_6; |
| 82 | args.name = threadName; |
| 83 | args.group = nullptr; |
| 84 | // Deal with difference in signatures between Oracle's jni.h and Android's. |
| 85 | #ifdef _JAVASOFT_JNI_H_ // Oracle's jni.h violates the JNI spec |
| 86 | void* env = nullptr; |
| 87 | #else |
| 88 | JNIEnv* env = nullptr; |
| 89 | #endif |
| 90 | // this function may fail if JVM is shutting down: |
| 91 | [[maybe_unused]] auto result = gJvm->AttachCurrentThread(&env, &args); |
| 92 | assert(result == JNI_OK); |
| 93 | assert(env != nullptr); |
| 94 | |
| 95 | return static_cast<JNIEnv*>(env); |
| 96 | } |
| 97 | } // namespace |
| 98 | |
| 99 | // Return a |JNIEnv*| usable on this thread or NULL if this thread is detached. |
no outgoing calls
no test coverage detected