MCPcopy Create free account
hub / github.com/Snapchat/Valdi / attachJniInternal

Function attachJniInternal

libs/utils/src/utils/platform/JvmUtils.cpp:76–96  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

74namespace {
75
76JNIEnv* 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.

Callers 2

attachThreadIfNeededFunction · 0.85
attachJniFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected