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

Commit 14fae06b authored by Martijn Coenen's avatar Martijn Coenen
Browse files

Add nullable parameter to readEmbeddedBuffer.

To support reading embedded buffers that can be
nullptr (currently only in empty hidl_vec).

Bug: 34255213
Test: hidl_test_java
Change-Id: I72028f580b7863b6bfeb31a5c0f43deed36dfd64
parent 0938b22c
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
@@ -212,7 +212,7 @@ public class HwParcel {
    public native final HwBlob readBuffer();

    public native final HwBlob readEmbeddedBuffer(
            long parentHandle, long offset);
            long parentHandle, long offset, boolean nullable);

    public native final void writeBuffer(HwBlob blob);

+8 −3
Original line number Diff line number Diff line
@@ -822,7 +822,8 @@ static jobject JHwParcel_native_readBuffer(JNIEnv *env, jobject thiz) {
}

static jobject JHwParcel_native_readEmbeddedBuffer(
        JNIEnv *env, jobject thiz, jlong parentHandle, jlong offset) {
        JNIEnv *env, jobject thiz, jlong parentHandle, jlong offset,
        jboolean nullable) {
    hardware::Parcel *parcel =
        JHwParcel::GetNativeContext(env, thiz)->getParcel();

@@ -830,11 +831,15 @@ static jobject JHwParcel_native_readEmbeddedBuffer(

    const void *ptr;
    status_t status =
        parcel->readEmbeddedBuffer(&childHandle, parentHandle, offset, &ptr);
        parcel->readNullableEmbeddedBuffer(&childHandle, parentHandle, offset,
                &ptr);

    if (status != OK) {
        jniThrowException(env, "java/util/NoSuchElementException", NULL);
        return 0;
    } else if (status == OK && !nullable && ptr == nullptr) {
        jniThrowException(env, "java/lang/NullPointerException", NULL);
        return 0;
    }

    return JHwBlob::NewObject(env, ptr, childHandle);
@@ -945,7 +950,7 @@ static JNINativeMethod gMethods[] = {
    { "readBuffer", "()L" PACKAGE_PATH "/HwBlob;",
        (void *)JHwParcel_native_readBuffer },

    { "readEmbeddedBuffer", "(JJ)L" PACKAGE_PATH "/HwBlob;",
    { "readEmbeddedBuffer", "(JJZ)L" PACKAGE_PATH "/HwBlob;",
        (void *)JHwParcel_native_readEmbeddedBuffer },

    { "writeBuffer", "(L" PACKAGE_PATH "/HwBlob;)V",