From accbb8c908d764c5f0b8030480f3e84f0f319ff5 Mon Sep 17 00:00:00 2001 From: Martijn Coenen Date: Tue, 9 Oct 2012 15:21:49 -0700 Subject: Don't return target lost in case of NACK for T2T. Causes applications such as TagInfo to report the tag as being lost. Also fixed a small memory leak triggered in this case. Bug: 7294613 Change-Id: I260e02896e534b23de5c7e0278609e27a9a20e7f --- nci/jni/NativeNfcTag.cpp | 26 ++++++++++++-------------- 1 file changed, 12 insertions(+), 14 deletions(-) diff --git a/nci/jni/NativeNfcTag.cpp b/nci/jni/NativeNfcTag.cpp index 8c0426b..0ba7b21 100755 --- a/nci/jni/NativeNfcTag.cpp +++ b/nci/jni/NativeNfcTag.cpp @@ -806,6 +806,7 @@ static jbyteArray nativeNfcTag_doTransceive (JNIEnv *e, jobject o, jbyteArray da bool fNeedToSwitchBack = false; nfc_jni_native_data *nat = getNative (0, 0); bool waitOk = false; + bool isNack = false; uint8_t *buf = NULL; uint32_t bufLen = 0; jint *targetLost = NULL; @@ -884,24 +885,21 @@ static jbyteArray nativeNfcTag_doTransceive (JNIEnv *e, jobject o, jbyteArray da if ((natTag.getProtocol () == NFA_PROTOCOL_T2T) && natTag.isT2tNackResponse (sTransceiveData, sTransceiveDataLen)) { - if (targetLost) - { - ALOGD ("%s: t2t nack", __FUNCTION__); - *targetLost = 1; //causes NFC service to throw TagLostException - } - break; + isNack = true; } if (sTransceiveDataLen) { - // marshall data to java for return - result = e->NewByteArray (sTransceiveDataLen); - if (result != NULL) - { - e->SetByteArrayRegion (result, 0, sTransceiveDataLen, (jbyte *) sTransceiveData); - } - else - ALOGE ("%s: Failed to allocate java byte array", __FUNCTION__); + if (!isNack) { + // marshall data to java for return + result = e->NewByteArray (sTransceiveDataLen); + if (result != NULL) + { + e->SetByteArrayRegion (result, 0, sTransceiveDataLen, (jbyte *) sTransceiveData); + } + else + ALOGE ("%s: Failed to allocate java byte array", __FUNCTION__); + } // else a nack is treated as a transceive failure to the upper layers free (sTransceiveData); sTransceiveData = NULL; -- cgit v1.1