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

Commit 82328bfd authored by Nick Pelly's avatar Nick Pelly
Browse files

NFC API updates.

o NfcAdapter.set*(): enforce at least one activity is provided at compile time.
o Unhide and update javadoc for some API's scheduled for ICS release.

Change-Id: I2bf4ea101442dcdeb359be26d3869f82e6e3748b
parent c5d0fac0
Loading
Loading
Loading
Loading
+13 −3
Original line number Diff line number Diff line
@@ -12396,6 +12396,7 @@ package android.nfc {
  public final class NdefRecord implements android.os.Parcelable {
    ctor public NdefRecord(short, byte[], byte[], byte[]);
    ctor public NdefRecord(byte[]) throws android.nfc.FormatException;
    method public static android.nfc.NdefRecord createApplicationRecord(java.lang.String);
    method public static android.nfc.NdefRecord createUri(android.net.Uri);
    method public static android.nfc.NdefRecord createUri(java.lang.String);
    method public int describeContents();
@@ -12430,9 +12431,9 @@ package android.nfc {
    method public static android.nfc.NfcAdapter getDefaultAdapter(android.content.Context);
    method public static deprecated android.nfc.NfcAdapter getDefaultAdapter();
    method public boolean isEnabled();
    method public void setNdefPushMessage(android.nfc.NdefMessage, android.app.Activity...);
    method public void setNdefPushMessageCallback(android.nfc.NfcAdapter.CreateNdefMessageCallback, android.app.Activity...);
    method public void setOnNdefPushCompleteCallback(android.nfc.NfcAdapter.OnNdefPushCompleteCallback, android.app.Activity...);
    method public void setNdefPushMessage(android.nfc.NdefMessage, android.app.Activity, android.app.Activity...);
    method public void setNdefPushMessageCallback(android.nfc.NfcAdapter.CreateNdefMessageCallback, android.app.Activity, android.app.Activity...);
    method public void setOnNdefPushCompleteCallback(android.nfc.NfcAdapter.OnNdefPushCompleteCallback, android.app.Activity, android.app.Activity...);
    field public static final java.lang.String ACTION_NDEF_DISCOVERED = "android.nfc.action.NDEF_DISCOVERED";
    field public static final java.lang.String ACTION_TAG_DISCOVERED = "android.nfc.action.TAG_DISCOVERED";
    field public static final java.lang.String ACTION_TECH_DISCOVERED = "android.nfc.action.TECH_DISCOVERED";
@@ -12486,6 +12487,7 @@ package android.nfc.tech {
    method public byte[] getHiLayerResponse();
    method public byte[] getHistoricalBytes();
    method public int getMaxTransceiveLength();
    method public int getTimeout();
    method public void setTimeout(int);
    method public byte[] transceive(byte[]) throws java.io.IOException;
  }
@@ -12501,11 +12503,13 @@ package android.nfc.tech {
    method public int getMaxTransceiveLength();
    method public int getSectorCount();
    method public int getSize();
    method public int getTimeout();
    method public int getType();
    method public void increment(int, int) throws java.io.IOException;
    method public byte[] readBlock(int) throws java.io.IOException;
    method public void restore(int) throws java.io.IOException;
    method public int sectorToBlock(int);
    method public void setTimeout(int);
    method public byte[] transceive(byte[]) throws java.io.IOException;
    method public void transfer(int) throws java.io.IOException;
    method public void writeBlock(int, byte[]) throws java.io.IOException;
@@ -12526,8 +12530,10 @@ package android.nfc.tech {
  public final class MifareUltralight extends android.nfc.tech.BasicTagTechnology {
    method public static android.nfc.tech.MifareUltralight get(android.nfc.Tag);
    method public int getMaxTransceiveLength();
    method public int getTimeout();
    method public int getType();
    method public byte[] readPages(int) throws java.io.IOException;
    method public void setTimeout(int);
    method public byte[] transceive(byte[]) throws java.io.IOException;
    method public void writePage(int, byte[]) throws java.io.IOException;
    field public static final int PAGE_SIZE = 4; // 0x4
@@ -12564,6 +12570,8 @@ package android.nfc.tech {
    method public byte[] getAtqa();
    method public int getMaxTransceiveLength();
    method public short getSak();
    method public int getTimeout();
    method public void setTimeout(int);
    method public byte[] transceive(byte[]) throws java.io.IOException;
  }
@@ -12580,6 +12588,8 @@ package android.nfc.tech {
    method public byte[] getManufacturer();
    method public int getMaxTransceiveLength();
    method public byte[] getSystemCode();
    method public int getTimeout();
    method public void setTimeout(int);
    method public byte[] transceive(byte[]) throws java.io.IOException;
  }
+12 −6
Original line number Diff line number Diff line
@@ -152,8 +152,6 @@ public final class NdefRecord implements Parcelable {
     * RTD_ANDROID_APP records.
     * @hide
     */
    // TODO unhide for ICS
    // TODO recheck docs
    public static final byte[] RTD_ANDROID_APP = "android.com:pkg".getBytes();

    private static final byte FLAG_MB = (byte) 0x80;
@@ -352,21 +350,29 @@ public final class NdefRecord implements Parcelable {
    /**
     * Creates an Android application NDEF record.
     * <p>
     * This record indicates to other Android devices the package
     * that should be used to handle the rest of the NDEF message.
     * You can embed this record anywhere into your NDEF message
     * to ensure that the intended package receives the message.
     * <p>
     * When an Android device dispatches an {@link NdefMessage}
     * containing one or more Android application records,
     * the applications contained in those records will be the
     * preferred target for the NDEF_DISCOVERED intent, in
     * the order in which they appear in the {@link NdefMessage}.
     * This dispatch behavior was first added to Android in
     * Ice Cream Sandwich.
     * <p>
     * If none of the applications are installed on the device,
     * a Market link will be opened to the first application.
     * <p>
     * Note that Android application records do not overrule
     * applications that have called {@link NfcAdapter#enableForegroundDispatch}.
     * @hide
     * applications that have called
     * {@link NfcAdapter#enableForegroundDispatch}.
     *
     * @param packageName Android package name
     * @return Android application NDEF record
     */
    // TODO unhide for ICS
    // TODO recheck javadoc - should mention this works from ICS only
    public static NdefRecord createApplicationRecord(String packageName) {
        return new NdefRecord(TNF_EXTERNAL_TYPE, RTD_ANDROID_APP, new byte[] {},
                packageName.getBytes(Charsets.US_ASCII));
+34 −12
Original line number Diff line number Diff line
@@ -507,16 +507,24 @@ public final class NfcAdapter {
     * <p>Pass a null NDEF message to disable foreground NDEF push in the
     * specified activities.
     *
     * <p>One or more activities must be specified.
     *
     * <p class="note">Requires the {@link android.Manifest.permission#NFC} permission.
     *
     * @param message NDEF message to push over NFC, or null to disable
     * @param activities one or more {@link Activity} to enable for NDEF push
     * @param activity an activity to enable for NDEF push (at least one is required)
     * @param activities zero or more additional activities to enable for NDEF Push
     */
    public void setNdefPushMessage(NdefMessage message, Activity ... activities) {
        if (activities.length == 0) {
            throw new NullPointerException("Must specificy one or more activities");
    public void setNdefPushMessage(NdefMessage message, Activity activity,
            Activity ... activities) {
        if (activity == null) {
            throw new NullPointerException("activity cannot be null");
        }
        mNfcActivityManager.setNdefPushMessage(activity, message);
        for (Activity a : activities) {
            if (a == null) {
                throw new NullPointerException("activities cannot contain null");
            }
            mNfcActivityManager.setNdefPushMessage(a, message);
        }
    }
@@ -536,17 +544,24 @@ public final class NfcAdapter {
     * <p>Pass a null callback to disable the callback in the
     * specified activities.
     *
     * <p>One or more activities must be specified.
     *
     * <p class="note">Requires the {@link android.Manifest.permission#NFC} permission.
     *
     * @param callback callback, or null to disable
     * @param activities one or more {@link Activity} to enable for NDEF push
     * @param activity an activity to enable for NDEF push (at least one is required)
     * @param activities zero or more additional activities to enable for NDEF Push
     */
    public void setNdefPushMessageCallback(CreateNdefMessageCallback callback,
    public void setNdefPushMessageCallback(CreateNdefMessageCallback callback, Activity activity,
            Activity ... activities) {
        if (activities.length == 0) {
            throw new NullPointerException("Must specificy one or more activities");
        if (activity == null) {
            throw new NullPointerException("activity cannot be null");
        }
        mNfcActivityManager.setNdefPushMessageCallback(activity, callback);
        for (Activity a : activities) {
            if (a == null) {
                throw new NullPointerException("activities cannot contain null");
            }
            mNfcActivityManager.setNdefPushMessageCallback(a, callback);
        }
    }
@@ -558,17 +573,24 @@ public final class NfcAdapter {
     * can only occur when one of the specified activities is in resumed
     * (foreground) state.
     *
     * <p>One or more activities must be specified.
     *
     * <p class="note">Requires the {@link android.Manifest.permission#NFC} permission.
     *
     * @param callback callback, or null to disable
     * @param activities one or more {@link Activity} to enable the callback
     * @param activity an activity to enable the callback (at least one is required)
     * @param activities zero or more additional activities to enable to callback
     */
    public void setOnNdefPushCompleteCallback(OnNdefPushCompleteCallback callback,
            Activity ... activities) {
        if (activities.length == 0) {
            throw new NullPointerException("Must specificy one or more activities");
            Activity activity, Activity ... activities) {
        if (activity == null) {
            throw new NullPointerException("activity cannot be null");
        }
        mNfcActivityManager.setOnNdefPushCompleteCallback(activity, callback);
        for (Activity a : activities) {
            if (a == null) {
                throw new NullPointerException("activities cannot contain null");
            }
            mNfcActivityManager.setOnNdefPushCompleteCallback(a, callback);
        }
    }
+1 −3
Original line number Diff line number Diff line
@@ -101,14 +101,12 @@ public final class IsoDep extends BasicTagTechnology {
    }

    /**
     * Gets the currently set timeout of {@link #transceive} in milliseconds.
     * Get the current timeout for {@link #transceive} in milliseconds.
     *
     * <p class="note">Requires the {@link android.Manifest.permission#NFC} permission.
     *
     * @return timeout value in milliseconds
     * @hide
     */
    // TODO Unhide for ICS
    public int getTimeout() {
        try {
            return mTag.getTagService().getTimeout(TagTechnology.ISO_DEP);
+5 −7
Original line number Diff line number Diff line
@@ -584,9 +584,11 @@ public final class MifareClassic extends BasicTagTechnology {
    }

    /**
     * Set the timeout of {@link #transceive} in milliseconds.
     * <p>The timeout only applies to MifareUltralight {@link #transceive},
     * Set the {@link #transceive} timeout in milliseconds.
     *
     * <p>The timeout only applies to {@link #transceive} on this object,
     * 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.
@@ -594,9 +596,7 @@ public final class MifareClassic extends BasicTagTechnology {
     * <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);
@@ -609,14 +609,12 @@ public final class MifareClassic extends BasicTagTechnology {
    }

    /**
     * Gets the currently set timeout of {@link #transceive} in milliseconds.
     * Get the current {@link #transceive} timeout in milliseconds.
     *
     * <p class="note">Requires the {@link android.Manifest.permission#NFC} permission.
     *
     * @return timeout value in milliseconds
     * @hide
     */
    // TODO Unhide for ICS
    public int getTimeout() {
        try {
            return mTag.getTagService().getTimeout(TagTechnology.MIFARE_CLASSIC);
Loading