Implement IsoDep timeout handling (API).

Added a method for setting the timeout on IsoDep transactions.

Change-Id: Ie627e7a826556e46295fefe69b9be83ebf911d93
This commit is contained in:
Martijn Coenen
2011-01-12 21:17:43 +01:00
committed by Nick Pelly
parent 72abf01a8b
commit a701cf85a0
3 changed files with 46 additions and 0 deletions

View File

@ -101199,6 +101199,19 @@
<exception name="IOException" type="java.io.IOException">
</exception>
</method>
<method name="setTimeout"
return="void"
abstract="false"
native="false"
synchronized="false"
static="false"
final="false"
deprecated="not deprecated"
visibility="public"
>
<parameter name="timeout" type="int">
</parameter>
</method>
</class>
<class name="MifareClassic"
extends="android.nfc.technology.BasicTagTechnology"

View File

@ -39,4 +39,7 @@ interface INfcTag
int ndefMakeReadOnly(int nativeHandle);
boolean ndefIsWritable(int nativeHandle);
int formatNdef(int nativeHandle, in byte[] key);
void setIsoDepTimeout(int timeout);
void resetIsoDepTimeout();
}

View File

@ -20,6 +20,7 @@ import android.nfc.NfcAdapter;
import android.nfc.Tag;
import android.os.Bundle;
import android.os.RemoteException;
import android.util.Log;
import java.io.IOException;
@ -38,6 +39,8 @@ import java.io.IOException;
* permission.
*/
public final class IsoDep extends BasicTagTechnology {
private static final String TAG = "NFC";
/** @hide */
public static final String EXTRA_HI_LAYER_RESP = "hiresp";
/** @hide */
@ -56,6 +59,33 @@ public final class IsoDep extends BasicTagTechnology {
}
}
/**
* Sets the timeout of an IsoDep transceive transaction in milliseconds.
* If the transaction has not completed before the timeout,
* any ongoing {@link BasicTagTechnology#transceive} operation will be
* aborted and the connection to the tag is lost. This setting is applied
* only to the {@link Tag} object linked to this technology and will be
* reset when {@link IsoDep#close} is called.
* The default transaction timeout is 5 seconds.
*/
public void setTimeout(int timeout) {
try {
mTagService.setIsoDepTimeout(timeout);
} catch (RemoteException e) {
Log.e(TAG, "NFC service dead", e);
}
}
@Override
public void close() {
try {
mTagService.resetIsoDepTimeout();
} catch (RemoteException e) {
Log.e(TAG, "NFC service dead", e);
}
super.close();
}
/**
* Return the historical bytes if the tag is using {@link NfcA}, null otherwise.
*/