Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit a701cf85 authored by Martijn Coenen's avatar Martijn Coenen Committed by Nick Pelly
Browse files

Implement IsoDep timeout handling (API).

Added a method for setting the timeout on IsoDep transactions.

Change-Id: Ie627e7a826556e46295fefe69b9be83ebf911d93
parent 72abf01a
Loading
Loading
Loading
Loading
+13 −0
Original line number Diff line number Diff line
@@ -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"
+3 −0
Original line number Diff line number Diff line
@@ -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();
}
+30 −0
Original line number Diff line number Diff line
@@ -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.
     */