16 April, 2014

Tag was lost when touching the HCE android device.

I implemented A KitKat device as a reader, and B KitKat device as a card.
When touching them, if the card app is not started, I got the error exception on reader: Tag was lost.

What happened? Why I need to touch the reader twice when the app is not started?

Checked the whole log, I found that the reason is that the isoDep transceive operation is timeout.
In my app, when returning data from HostApduService at the first time, it costs about 100ms, after that, it will cost 10ms.
The default timeout of transceive operation is 306ms.

After I set timeout to 2000, everything works well.
ULogUtil.d(TAG, "code = timeout" + dep.getTimeout());
ULogUtil.d(TAG, "code = length" + dep.getMaxTransceiveLength());
byte[] data = dep.transceive(createApdu(AID_ANDROID));

setTimeout(int timeout)
Set the timeout of transceive(byte[]) in milliseconds.