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
diff --git a/api/current.txt b/api/current.txt
index dfc17ba..163de68 100644
--- a/api/current.txt
+++ b/api/current.txt
@@ -12396,6 +12396,7 @@
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 @@
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 @@
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 @@
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 @@
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 @@
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 @@
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;
}
diff --git a/core/java/android/nfc/NdefRecord.java b/core/java/android/nfc/NdefRecord.java
index 6ba3451..26571ff 100644
--- a/core/java/android/nfc/NdefRecord.java
+++ b/core/java/android/nfc/NdefRecord.java
@@ -152,8 +152,6 @@
* 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 @@
/**
* 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));
diff --git a/core/java/android/nfc/NfcAdapter.java b/core/java/android/nfc/NfcAdapter.java
index d58b249..e392bca 100644
--- a/core/java/android/nfc/NfcAdapter.java
+++ b/core/java/android/nfc/NfcAdapter.java
@@ -507,16 +507,24 @@
* <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 @@
* <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 @@
* 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);
}
}
diff --git a/core/java/android/nfc/tech/IsoDep.java b/core/java/android/nfc/tech/IsoDep.java
index 6054fe8..1859877 100644
--- a/core/java/android/nfc/tech/IsoDep.java
+++ b/core/java/android/nfc/tech/IsoDep.java
@@ -101,14 +101,12 @@
}
/**
- * 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);
diff --git a/core/java/android/nfc/tech/MifareClassic.java b/core/java/android/nfc/tech/MifareClassic.java
index ce923ae..9d1e6a1 100644
--- a/core/java/android/nfc/tech/MifareClassic.java
+++ b/core/java/android/nfc/tech/MifareClassic.java
@@ -584,9 +584,11 @@
}
/**
- * 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 @@
* <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 @@
}
/**
- * 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);
diff --git a/core/java/android/nfc/tech/MifareUltralight.java b/core/java/android/nfc/tech/MifareUltralight.java
index 890b735..dec2c65 100644
--- a/core/java/android/nfc/tech/MifareUltralight.java
+++ b/core/java/android/nfc/tech/MifareUltralight.java
@@ -224,9 +224,11 @@
}
/**
- * 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.
@@ -234,9 +236,7 @@
* <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(
@@ -250,14 +250,12 @@
}
/**
- * 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_ULTRALIGHT);
diff --git a/core/java/android/nfc/tech/NfcA.java b/core/java/android/nfc/tech/NfcA.java
index bb8aec9..88730f9 100644
--- a/core/java/android/nfc/tech/NfcA.java
+++ b/core/java/android/nfc/tech/NfcA.java
@@ -129,9 +129,11 @@
}
/**
- * 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.
+ * 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.
@@ -139,9 +141,7 @@
* <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);
@@ -154,14 +154,12 @@
}
/**
- * 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.NFC_A);
diff --git a/core/java/android/nfc/tech/NfcF.java b/core/java/android/nfc/tech/NfcF.java
index 0938fb4..b3e3ab6 100644
--- a/core/java/android/nfc/tech/NfcF.java
+++ b/core/java/android/nfc/tech/NfcF.java
@@ -128,9 +128,11 @@
}
/**
- * Set the timeout of {@link #transceive} in milliseconds.
- * <p>The timeout only applies to NfcF {@link #transceive}, and is
- * reset to a default value when {@link #close} is called.
+ * 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.
@@ -138,9 +140,7 @@
* <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_F, timeout);
@@ -153,14 +153,12 @@
}
/**
- * 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.NFC_F);