Skip to content

Commit 4955d1b

Browse files
committed
fix android timeout bug
1 parent 0646493 commit 4955d1b

File tree

1 file changed

+15
-9
lines changed

1 file changed

+15
-9
lines changed

android/src/main/kotlin/im/nfc/flutter_nfc_kit/FlutterNfcKitPlugin.kt

Lines changed: 15 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import android.nfc.NfcAdapter
88
import android.nfc.NfcAdapter.*
99
import android.nfc.Tag
1010
import android.nfc.tech.*
11+
import android.os.Bundle
1112
import android.os.Handler
1213
import android.os.HandlerThread
1314
import android.os.Looper
@@ -86,13 +87,13 @@ class FlutterNfcKitPlugin : FlutterPlugin, MethodCallHandler, ActivityAware {
8687
Log.e(TAG, "$desc error", ex)
8788
val excMessage = ex.localizedMessage
8889
when (ex) {
89-
is IOException -> result?.error("500", "Communication error", excMessage)
90-
is SecurityException -> result?.error("503", "Tag already removed", excMessage)
91-
is FormatException -> result?.error("400", "NDEF format error", excMessage)
92-
is InvocationTargetException -> result?.error("500", "Communication error", excMessage)
93-
is IllegalArgumentException -> result?.error("400", "Command format error", excMessage)
94-
is NoSuchMethodException -> result?.error("405", "Transceive not supported for this type of card", excMessage)
95-
else -> result?.error("500", "Unhandled error", excMessage)
90+
is IOException -> result.error("500", "Communication error", excMessage)
91+
is SecurityException -> result.error("503", "Tag already removed", excMessage)
92+
is FormatException -> result.error("400", "NDEF format error", excMessage)
93+
is InvocationTargetException -> result.error("500", "Communication error", excMessage)
94+
is IllegalArgumentException -> result.error("400", "Command format error", excMessage)
95+
is NoSuchMethodException -> result.error("405", "Transceive not supported for this type of card", excMessage)
96+
else -> result.error("500", "Unhandled error", excMessage)
9697
}
9798
}
9899
}
@@ -141,7 +142,7 @@ class FlutterNfcKitPlugin : FlutterPlugin, MethodCallHandler, ActivityAware {
141142
tagTechnology = isoDep
142143
// historicalBytes() may return null but is wrongly typed as ByteArray!
143144
// https://developer.android.com/reference/kotlin/android/nfc/tech/IsoDep#gethistoricalbytes
144-
historicalBytes = (isoDep.historicalBytes as ByteArray?)?.toHexString() ?: ""
145+
historicalBytes = isoDep.historicalBytes?.toHexString() ?: ""
145146
}
146147
tag.techList.contains(MifareClassic::class.java.name) -> {
147148
standard = "ISO 14443-3 (Type A)"
@@ -604,7 +605,12 @@ class FlutterNfcKitPlugin : FlutterPlugin, MethodCallHandler, ActivityAware {
604605
result.success(jsonResult)
605606
}
606607

607-
nfcAdapter.enableReaderMode(activity.get(), pollHandler, technologies, null)
608+
// The EXTRA_READER_PRESENCE_CHECK_DELAY is for fixing an obscure bug with
609+
// some Android versions like LineageOS 17.1 that caused the PACE authentication to fail.
610+
// See https://github.com/privacybydesign/vcmrtd/issues/91 for more info.
611+
val options = Bundle()
612+
options.putInt(EXTRA_READER_PRESENCE_CHECK_DELAY, 2000)
613+
nfcAdapter.enableReaderMode(activity.get(), pollHandler, technologies, options)
608614
}
609615

610616
private class MethodResultWrapper(result: Result) : Result {

0 commit comments

Comments
 (0)