From 6a63527e2cba30a34418cd0ce9476821508b516f Mon Sep 17 00:00:00 2001 From: joonhaengHeo <85541460+joonhaengHeo@users.noreply.github.com> Date: Fri, 16 Sep 2022 01:40:26 +0900 Subject: [PATCH] Avoid Android crash during QRCode Parsing (#22655) --- .../java/SetupPayloadParser-JNI.cpp | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/src/setup_payload/java/SetupPayloadParser-JNI.cpp b/src/setup_payload/java/SetupPayloadParser-JNI.cpp index 2063fc91c0b3d9..b11c86c63bfb6f 100644 --- a/src/setup_payload/java/SetupPayloadParser-JNI.cpp +++ b/src/setup_payload/java/SetupPayloadParser-JNI.cpp @@ -158,12 +158,8 @@ jobject TransformSetupPayload(JNIEnv * env, SetupPayload & payload) jclass enumClass = env->FindClass("chip/setuppayload/OptionalQRCodeInfo$OptionalQRCodeInfoType"); jfieldID enumType = nullptr; - switch (info.tag) + switch (info.type) { - case optionalQRCodeInfoTypeUnknown: - enumType = - env->GetStaticFieldID(enumClass, "TYPE_UNKNOWN", "Lchip/setuppayload/OptionalQRCodeInfo$OptionalQRCodeInfoType;"); - break; case optionalQRCodeInfoTypeString: enumType = env->GetStaticFieldID(enumClass, "TYPE_STRING", "Lchip/setuppayload/OptionalQRCodeInfo$OptionalQRCodeInfoType;"); @@ -184,12 +180,18 @@ jobject TransformSetupPayload(JNIEnv * env, SetupPayload & payload) enumType = env->GetStaticFieldID(enumClass, "TYPE_UINT64", "Lchip/setuppayload/OptionalQRCodeInfo$OptionalQRCodeInfoType;"); break; - default: + case optionalQRCodeInfoTypeUnknown: + default: // Optional Type variable has to set any value. + enumType = + env->GetStaticFieldID(enumClass, "TYPE_UNKNOWN", "Lchip/setuppayload/OptionalQRCodeInfo$OptionalQRCodeInfoType;"); break; } - jobject enumObj = env->GetStaticObjectField(enumClass, enumType); - env->SetObjectField(optionalInfo, type, enumObj); + if (enumType != nullptr) + { + jobject enumObj = env->GetStaticObjectField(enumClass, enumType); + env->SetObjectField(optionalInfo, type, enumObj); + } env->SetObjectField(optionalInfo, data, env->NewStringUTF(info.data.c_str())); env->SetIntField(optionalInfo, int32, info.int32);