OSDN Git Service

media: Check window connect status in ImageWriter
authorEmilian Peev <epeev@google.com>
Tue, 5 Jun 2018 16:52:16 +0000 (17:52 +0100)
committerEmilian Peev <epeev@google.com>
Wed, 6 Jun 2018 09:57:15 +0000 (09:57 +0000)
ImageWriter clients could pass invalid or already
connected surface during initialization. Check the
status after trying to connect to the producer
interface and raise an exception if necessary.

Bug: 80086132
Test: Camera CTS
Change-Id: I46810885046a3b89ea18510574c22db27e812a9c

media/jni/android_media_ImageWriter.cpp

index f8f7a90..031e373 100644 (file)
@@ -252,7 +252,14 @@ static jlong ImageWriter_init(JNIEnv* env, jobject thiz, jobject weakThiz, jobje
      * after disconnect. MEDIA or CAMERA are treated the same internally. The producer listener
      * will be cleared after disconnect call.
      */
-    producer->connect(/*api*/NATIVE_WINDOW_API_CAMERA, /*listener*/ctx);
+    res = producer->connect(/*api*/NATIVE_WINDOW_API_CAMERA, /*listener*/ctx);
+    if (res != OK) {
+        ALOGE("%s: Connecting to surface producer interface failed: %s (%d)",
+                __FUNCTION__, strerror(-res), res);
+        jniThrowRuntimeException(env, "Failed to connect to native window");
+        return 0;
+    }
+
     jlong nativeCtx = reinterpret_cast<jlong>(ctx.get());
 
     // Get the dimension and format of the producer.