diff options
author | Chien-Yu Chen <cychen@google.com> | 2015-07-06 17:46:05 -0700 |
---|---|---|
committer | Chien-Yu Chen <cychen@google.com> | 2015-07-06 18:26:28 -0700 |
commit | e0ee63046ad062040aafc977585fb461a2acf666 (patch) | |
tree | ba229ef179ac0b33398bccd914305d212e206209 /media/jni | |
parent | 13c25290099a570fdd903511e7ec605119af3ce3 (diff) | |
download | frameworks_base-e0ee63046ad062040aafc977585fb461a2acf666.zip frameworks_base-e0ee63046ad062040aafc977585fb461a2acf666.tar.gz frameworks_base-e0ee63046ad062040aafc977585fb461a2acf666.tar.bz2 |
ImageWriter: Exception when Surface is abandoned
Throw IllegalStateException when queueing or dequeueing an
image if the input surface is already abandoned by the consumer.
Also fix a crash when planes are not initialized when closing
ImageWriter.
Bug: 22279111
Change-Id: I8301920d64a53c45b29e947e52ff323733abbf16
Diffstat (limited to 'media/jni')
-rw-r--r-- | media/jni/android_media_ImageWriter.cpp | 44 |
1 files changed, 38 insertions, 6 deletions
diff --git a/media/jni/android_media_ImageWriter.cpp b/media/jni/android_media_ImageWriter.cpp index ba7634c..f92a8ef 100644 --- a/media/jni/android_media_ImageWriter.cpp +++ b/media/jni/android_media_ImageWriter.cpp @@ -338,9 +338,16 @@ static void ImageWriter_dequeueImage(JNIEnv* env, jobject thiz, jlong nativeCtx, int fenceFd = -1; status_t res = anw->dequeueBuffer(anw.get(), &anb, &fenceFd); if (res != OK) { - // TODO: handle different error cases here. ALOGE("%s: Dequeue buffer failed: %s (%d)", __FUNCTION__, strerror(-res), res); - jniThrowRuntimeException(env, "dequeue buffer failed"); + switch (res) { + case NO_INIT: + jniThrowException(env, "java/lang/IllegalStateException", + "Surface has been abandoned"); + break; + default: + // TODO: handle other error cases here. + jniThrowRuntimeException(env, "dequeue buffer failed"); + } return; } // New GraphicBuffer object doesn't own the handle, thus the native buffer @@ -468,7 +475,16 @@ static void ImageWriter_queueImage(JNIEnv* env, jobject thiz, jlong nativeCtx, j // Finally, queue input buffer res = anw->queueBuffer(anw.get(), buffer, fenceFd); if (res != OK) { - jniThrowRuntimeException(env, "Queue input buffer failed"); + ALOGE("%s: Queue buffer failed: %s (%d)", __FUNCTION__, strerror(-res), res); + switch (res) { + case NO_INIT: + jniThrowException(env, "java/lang/IllegalStateException", + "Surface has been abandoned"); + break; + default: + // TODO: handle other error cases here. + jniThrowRuntimeException(env, "Queue input buffer failed"); + } return; } @@ -514,9 +530,16 @@ static jint ImageWriter_attachAndQueueImage(JNIEnv* env, jobject thiz, jlong nat // Step 1. Attach Image res = surface->attachBuffer(opaqueBuffer->mGraphicBuffer.get()); if (res != OK) { - // TODO: handle different error case separately. ALOGE("Attach image failed: %s (%d)", strerror(-res), res); - jniThrowRuntimeException(env, "nativeAttachImage failed!!!"); + switch (res) { + case NO_INIT: + jniThrowException(env, "java/lang/IllegalStateException", + "Surface has been abandoned"); + break; + default: + // TODO: handle other error cases here. + jniThrowRuntimeException(env, "nativeAttachImage failed!!!"); + } return res; } sp < ANativeWindow > anw = surface; @@ -545,7 +568,16 @@ static jint ImageWriter_attachAndQueueImage(JNIEnv* env, jobject thiz, jlong nat res = anw->queueBuffer(anw.get(), opaqueBuffer->mGraphicBuffer.get(), /*fenceFd*/ -1); if (res != OK) { - jniThrowRuntimeException(env, "Queue input buffer failed"); + ALOGE("%s: Queue buffer failed: %s (%d)", __FUNCTION__, strerror(-res), res); + switch (res) { + case NO_INIT: + jniThrowException(env, "java/lang/IllegalStateException", + "Surface has been abandoned"); + break; + default: + // TODO: handle other error cases here. + jniThrowRuntimeException(env, "Queue input buffer failed"); + } return res; } |