Switch get_env_or_die to requireEnv
Fixes: 153099745
Test: manual
The heif decoder may need to continue reading the input from a
JavaInputStreamAdaptor on the AnimatedImageThread. Attach the JVM like
we do for ByteBufferStream and ByteArrayStream.
Similarly, if the AnimatedImageThread is holding a reference to an
AnimatedImageDrawable, it is possible to call its destructor, and
ultimately InvokeListener's destructor or ByteBufferStreamAdaptor's
release_proc on that thread without the JVM attached. Attach in that
case, too.
Change-Id: I84d236eed2fb5c8617533aed0cae4c762d1eb6dd
diff --git a/libs/hwui/jni/ByteBufferStreamAdaptor.cpp b/libs/hwui/jni/ByteBufferStreamAdaptor.cpp
index db5f6f6..b10540c 100644
--- a/libs/hwui/jni/ByteBufferStreamAdaptor.cpp
+++ b/libs/hwui/jni/ByteBufferStreamAdaptor.cpp
@@ -9,24 +9,6 @@
static jmethodID gByteBuffer_getMethodID;
static jmethodID gByteBuffer_setPositionMethodID;
-/**
- * Helper method for accessing the JNI interface pointer.
- *
- * Image decoding (which this supports) is started on a thread that is already
- * attached to the Java VM. But an AnimatedImageDrawable continues decoding on
- * the AnimatedImageThread, which is not attached. This will attach if
- * necessary.
- */
-static JNIEnv* requireEnv(JavaVM* jvm) {
- JNIEnv* env;
- if (jvm->GetEnv(reinterpret_cast<void**>(&env), JNI_VERSION_1_6) != JNI_OK) {
- if (jvm->AttachCurrentThreadAsDaemon(&env, nullptr) != JNI_OK) {
- LOG_ALWAYS_FATAL("Failed to AttachCurrentThread!");
- }
- }
- return env;
-}
-
class ByteBufferStream : public SkStreamAsset {
private:
ByteBufferStream(JavaVM* jvm, jobject jbyteBuffer, size_t initialPosition, size_t length,
@@ -304,7 +286,7 @@
auto* context = new release_proc_context{jvm, jbyteBuffer};
auto releaseProc = [](const void*, void* context) {
auto* c = reinterpret_cast<release_proc_context*>(context);
- JNIEnv* env = get_env_or_die(c->jvm);
+ JNIEnv* env = requireEnv(c->jvm);
env->DeleteGlobalRef(c->jbyteBuffer);
delete c;
};