diff options
author | Jens Trillmann <jens.trillmann@governikus.de> | 2021-08-17 09:25:46 +0200 |
---|---|---|
committer | Ivan Solovev <ivan.solovev@qt.io> | 2021-09-07 16:29:03 +0200 |
commit | 7768a384e0a4f92a82bd14ea04d76f163e4bb38f (patch) | |
tree | f64cc7f2717d88a484f0da5d838f8f1cbe6ff478 | |
parent | 3f7bdee1fdd0b5d3e4f955a4a8be9537a716e5e6 (diff) |
Android: Call handleTargetLost directly on NFC TagLostException
If in a transceive() a TagLostException occurs, subsequent calls to
transceive() may lead to an app crash with "JNI DETECTED ERROR IN
APPLICATION: GetMethodID received NULL jclass" on Android 11 if the
timer did not clean up first.
This fix calls handleTargetLost directly. This could lead to a race
condition in which the targetLost signal is send twice, which should be
handled correctly by the Qt code.
Change-Id: I886e0bd436272ee393a92b0193fd4d40ed4e965e
Reviewed-by: Ivan Solovev <ivan.solovev@qt.io>
Reviewed-by: Alex Blasche <alexander.blasche@qt.io>
Reviewed-by: Lars Schmertmann <lars.schmertmann@governikus.de>
(cherry picked from commit 8362edb220cb77e7bcaf766dc8a9545d1c9246e5)
Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org>
-rw-r--r-- | src/nfc/qnearfieldtarget_android.cpp | 6 |
1 files changed, 6 insertions, 0 deletions
diff --git a/src/nfc/qnearfieldtarget_android.cpp b/src/nfc/qnearfieldtarget_android.cpp index 295c603c..5cc01807 100644 --- a/src/nfc/qnearfieldtarget_android.cpp +++ b/src/nfc/qnearfieldtarget_android.cpp @@ -253,6 +253,12 @@ QNearFieldTarget::RequestId NearFieldTarget::sendCommand(const QByteArray &comma // Writing QAndroidJniObject myNewVal = m_tagTech.callObjectMethod("transceive", "([B)[B", jba); if (catchJavaExceptions()) { + // Some devices (Samsung, Huawei) throw an exception when the card is lost: + // "android.nfc.TagLostException: Tag was lost". But there seems to be a bug that + // isConnected still reports true. So we need to invalidate the target as soon as + // possible and treat the card as lost. + handleTargetLost(); + reportError(QNearFieldTarget::CommandError, requestId); return requestId; } |