Skip to content

Commit a701cf8

Browse files
Martijn CoenenNick Pelly
authored andcommitted
Implement IsoDep timeout handling (API).
Added a method for setting the timeout on IsoDep transactions. Change-Id: Ie627e7a826556e46295fefe69b9be83ebf911d93
1 parent 72abf01 commit a701cf8

File tree

3 files changed

+46
-0
lines changed

3 files changed

+46
-0
lines changed

api/current.xml

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101199,6 +101199,19 @@
101199101199
<exception name="IOException" type="java.io.IOException">
101200101200
</exception>
101201101201
</method>
101202+
<method name="setTimeout"
101203+
return="void"
101204+
abstract="false"
101205+
native="false"
101206+
synchronized="false"
101207+
static="false"
101208+
final="false"
101209+
deprecated="not deprecated"
101210+
visibility="public"
101211+
>
101212+
<parameter name="timeout" type="int">
101213+
</parameter>
101214+
</method>
101202101215
</class>
101203101216
<class name="MifareClassic"
101204101217
extends="android.nfc.technology.BasicTagTechnology"

core/java/android/nfc/INfcTag.aidl

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,4 +39,7 @@ interface INfcTag
3939
int ndefMakeReadOnly(int nativeHandle);
4040
boolean ndefIsWritable(int nativeHandle);
4141
int formatNdef(int nativeHandle, in byte[] key);
42+
43+
void setIsoDepTimeout(int timeout);
44+
void resetIsoDepTimeout();
4245
}

core/java/android/nfc/technology/IsoDep.java

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
import android.nfc.Tag;
2121
import android.os.Bundle;
2222
import android.os.RemoteException;
23+
import android.util.Log;
2324

2425
import java.io.IOException;
2526

@@ -38,6 +39,8 @@
3839
* permission.
3940
*/
4041
public final class IsoDep extends BasicTagTechnology {
42+
private static final String TAG = "NFC";
43+
4144
/** @hide */
4245
public static final String EXTRA_HI_LAYER_RESP = "hiresp";
4346
/** @hide */
@@ -56,6 +59,33 @@ public IsoDep(NfcAdapter adapter, Tag tag, Bundle extras)
5659
}
5760
}
5861

62+
/**
63+
* Sets the timeout of an IsoDep transceive transaction in milliseconds.
64+
* If the transaction has not completed before the timeout,
65+
* any ongoing {@link BasicTagTechnology#transceive} operation will be
66+
* aborted and the connection to the tag is lost. This setting is applied
67+
* only to the {@link Tag} object linked to this technology and will be
68+
* reset when {@link IsoDep#close} is called.
69+
* The default transaction timeout is 5 seconds.
70+
*/
71+
public void setTimeout(int timeout) {
72+
try {
73+
mTagService.setIsoDepTimeout(timeout);
74+
} catch (RemoteException e) {
75+
Log.e(TAG, "NFC service dead", e);
76+
}
77+
}
78+
79+
@Override
80+
public void close() {
81+
try {
82+
mTagService.resetIsoDepTimeout();
83+
} catch (RemoteException e) {
84+
Log.e(TAG, "NFC service dead", e);
85+
}
86+
super.close();
87+
}
88+
5989
/**
6090
* Return the historical bytes if the tag is using {@link NfcA}, null otherwise.
6191
*/

0 commit comments

Comments
 (0)