Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 01fc279c authored by Songyue Han's avatar Songyue Han
Browse files

Adding nullptr check in Image_getHardwareBuffer() and Image_getFormat().

Change-Id: I22f3aaf312540d4d9288f2de3d1ce4432e956a7e
Test: build
Bug: 371065563
parent 70e8833a
Loading
Loading
Loading
Loading
+10 −0
Original line number Diff line number Diff line
@@ -935,6 +935,11 @@ static jint Image_getFormat(JNIEnv* env, jobject thiz, jint readerFormat)
        return static_cast<jint>(PublicFormat::PRIVATE);
    } else {
        BufferItem* buffer = Image_getBufferItem(env, thiz);
        if (buffer == nullptr) {
            jniThrowException(env, "java/lang/IllegalStateException",
                    "Image is not initialized");
            return -1;
        }
        int readerHalFormat = mapPublicFormatToHalFormat(static_cast<PublicFormat>(readerFormat));
        int32_t fmt = applyFormatOverrides(
                buffer->mGraphicBuffer->getPixelFormat(), readerHalFormat);
@@ -953,6 +958,11 @@ static jint Image_getFormat(JNIEnv* env, jobject thiz, jint readerFormat)

static jobject Image_getHardwareBuffer(JNIEnv* env, jobject thiz) {
    BufferItem* buffer = Image_getBufferItem(env, thiz);
    if (buffer == nullptr) {
        jniThrowException(env, "java/lang/IllegalStateException",
                "Image is not initialized");
        return NULL;
    }
    AHardwareBuffer* b = AHardwareBuffer_from_GraphicBuffer(buffer->mGraphicBuffer.get());
    // don't user the public AHardwareBuffer_toHardwareBuffer() because this would force us
    // to link against libandroid.so