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

Commit fde45f58 authored by Martijn Coenen's avatar Martijn Coenen Committed by Android (Google) Code Review
Browse files

Merge "Support for setting the NfcA transceive timeout (API)."

parents 9d9f2372 112fdf61
Loading
Loading
Loading
Loading
+1 −2
Original line number Diff line number Diff line
@@ -43,7 +43,6 @@ interface INfcTag
    int formatNdef(int nativeHandle, in byte[] key);
    Tag rediscover(int nativehandle);

    void setIsoDepTimeout(int timeout);
    void setFelicaTimeout(int timeout);
    int setTimeout(int technology, int timeout);
    void resetTimeouts();
}
+5 −1
Original line number Diff line number Diff line
@@ -16,6 +16,7 @@

package android.nfc.tech;

import android.nfc.ErrorCodes;
import android.nfc.Tag;
import android.os.Bundle;
import android.os.RemoteException;
@@ -90,7 +91,10 @@ public final class IsoDep extends BasicTagTechnology {
     */
    public void setTimeout(int timeout) {
        try {
            mTag.getTagService().setIsoDepTimeout(timeout);
            int err = mTag.getTagService().setTimeout(TagTechnology.ISO_DEP, timeout);
            if (err != ErrorCodes.SUCCESS) {
                throw new IllegalArgumentException("The supplied timeout is not valid");
            }
        } catch (RemoteException e) {
            Log.e(TAG, "NFC service dead", e);
        }
+29 −0
Original line number Diff line number Diff line
@@ -16,9 +16,11 @@

package android.nfc.tech;

import android.nfc.ErrorCodes;
import android.nfc.Tag;
import android.nfc.TagLostException;
import android.os.RemoteException;
import android.util.Log;

import java.io.IOException;
import java.nio.ByteBuffer;
@@ -69,6 +71,8 @@ import java.nio.ByteOrder;
 * require the {@link android.Manifest.permission#NFC} permission.
 */
public final class MifareClassic extends BasicTagTechnology {
    private static final String TAG = "NFC";

    /**
     * The default factory key.
     */
@@ -568,6 +572,31 @@ public final class MifareClassic extends BasicTagTechnology {
        return transceive(data, true);
    }

    /**
     * Set the timeout of {@link #transceive} in milliseconds.
     * <p>The timeout only applies to MifareUltralight {@link #transceive},
     * and is reset to a default value when {@link #close} is called.
     * <p>Setting a longer timeout may be useful when performing
     * transactions that require a long processing time on the tag
     * such as key generation.
     *
     * <p class="note">Requires the {@link android.Manifest.permission#NFC} permission.
     *
     * @param timeout timeout value in milliseconds
     * @hide
     */
    // TODO Unhide for ICS
    public void setTimeout(int timeout) {
        try {
            int err = mTag.getTagService().setTimeout(TagTechnology.MIFARE_CLASSIC, timeout);
            if (err != ErrorCodes.SUCCESS) {
                throw new IllegalArgumentException("The supplied timeout is not valid");
            }
        } catch (RemoteException e) {
            Log.e(TAG, "NFC service dead", e);
        }
    }

    private static void validateSector(int sector) {
        // Do not be too strict on upper bounds checking, since some cards
        // have more addressable memory than they report. For example,
+30 −0
Original line number Diff line number Diff line
@@ -16,10 +16,12 @@

package android.nfc.tech;

import android.nfc.ErrorCodes;
import android.nfc.Tag;
import android.nfc.TagLostException;
import android.os.Bundle;
import android.os.RemoteException;
import android.util.Log;

import java.io.IOException;

@@ -57,6 +59,8 @@ import java.io.IOException;
 * require the {@link android.Manifest.permission#NFC} permission.
 */
public final class MifareUltralight extends BasicTagTechnology {
    private static final String TAG = "NFC";

    /** A MIFARE Ultralight compatible tag of unknown type */
    public static final int TYPE_UNKNOWN = -1;
    /** A MIFARE Ultralight tag */
@@ -208,6 +212,32 @@ public final class MifareUltralight extends BasicTagTechnology {
        return transceive(data, true);
    }

    /**
     * Set the timeout of {@link #transceive} in milliseconds.
     * <p>The timeout only applies to MifareUltralight {@link #transceive},
     * and is reset to a default value when {@link #close} is called.
     * <p>Setting a longer timeout may be useful when performing
     * transactions that require a long processing time on the tag
     * such as key generation.
     *
     * <p class="note">Requires the {@link android.Manifest.permission#NFC} permission.
     *
     * @param timeout timeout value in milliseconds
     * @hide
     */
    // TODO Unhide for ICS
    public void setTimeout(int timeout) {
        try {
            int err = mTag.getTagService().setTimeout(
                    TagTechnology.MIFARE_ULTRALIGHT, timeout);
            if (err != ErrorCodes.SUCCESS) {
                throw new IllegalArgumentException("The supplied timeout is not valid");
            }
        } catch (RemoteException e) {
            Log.e(TAG, "NFC service dead", e);
        }
    }

    private static void validatePageIndex(int pageIndex) {
        // Do not be too strict on upper bounds checking, since some cards
        // may have more addressable memory than they report.
+29 −0
Original line number Diff line number Diff line
@@ -16,9 +16,11 @@

package android.nfc.tech;

import android.nfc.ErrorCodes;
import android.nfc.Tag;
import android.os.Bundle;
import android.os.RemoteException;
import android.util.Log;

import java.io.IOException;

@@ -33,6 +35,8 @@ import java.io.IOException;
 * require the {@link android.Manifest.permission#NFC} permission.
 */
public final class NfcA extends BasicTagTechnology {
    private static final String TAG = "NFC";

    /** @hide */
    public static final String EXTRA_SAK = "sak";
    /** @hide */
@@ -112,4 +116,29 @@ public final class NfcA extends BasicTagTechnology {
    public byte[] transceive(byte[] data) throws IOException {
        return transceive(data, true);
    }

    /**
     * Set the timeout of {@link #transceive} in milliseconds.
     * <p>The timeout only applies to NfcA {@link #transceive}, and is
     * reset to a default value when {@link #close} is called.
     * <p>Setting a longer timeout may be useful when performing
     * transactions that require a long processing time on the tag
     * such as key generation.
     *
     * <p class="note">Requires the {@link android.Manifest.permission#NFC} permission.
     *
     * @param timeout timeout value in milliseconds
     * @hide
     */
    // TODO Unhide for ICS
    public void setTimeout(int timeout) {
        try {
            int err = mTag.getTagService().setTimeout(TagTechnology.NFC_A, timeout);
            if (err != ErrorCodes.SUCCESS) {
                throw new IllegalArgumentException("The supplied timeout is not valid");
            }
        } catch (RemoteException e) {
            Log.e(TAG, "NFC service dead", e);
        }
    }
}
Loading