summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMartijn Coenen <maco@google.com>2012-03-29 10:53:08 -0700
committerMartijn Coenen <maco@google.com>2012-03-29 11:24:15 -0700
commita032783241cbbed47ed05df32c56298ee0f9902b (patch)
tree257c7b20fbf5102171f3a7b436e2298fc77bb2e0
parent2976da0305367ac051d0fcae160bfdb0497b2750 (diff)
downloadframeworks_base-a032783241cbbed47ed05df32c56298ee0f9902b.zip
frameworks_base-a032783241cbbed47ed05df32c56298ee0f9902b.tar.gz
frameworks_base-a032783241cbbed47ed05df32c56298ee0f9902b.tar.bz2
Fix NDEF documentation to indicate the message may be null.
The current NFC stack formats tags to the INITIALIZED state as defined by NFC forum; in that state the tag has the NDEF Capability Container, but does not contain any message yet. Tags in that state (correctly) return the NDEF technology, but the documentation does not specify that the message may be null. Also, get rid of buggy getLastErrorCode and use (cached) presence check value to determine if tag was lost during read. Change-Id: If4293428093024ba9cda5dd7c9979b8b06353234
-rw-r--r--core/java/android/nfc/INfcTag.aidl2
-rw-r--r--core/java/android/nfc/tech/Ndef.java24
2 files changed, 11 insertions, 15 deletions
diff --git a/core/java/android/nfc/INfcTag.aidl b/core/java/android/nfc/INfcTag.aidl
index bb5a9fd..102b6af 100644
--- a/core/java/android/nfc/INfcTag.aidl
+++ b/core/java/android/nfc/INfcTag.aidl
@@ -34,8 +34,6 @@ interface INfcTag
boolean isPresent(int nativeHandle);
TransceiveResult transceive(int nativeHandle, in byte[] data, boolean raw);
- int getLastError(int nativeHandle);
-
NdefMessage ndefRead(int nativeHandle);
int ndefWrite(int nativeHandle, in NdefMessage msg);
int ndefMakeReadOnly(int nativeHandle);
diff --git a/core/java/android/nfc/tech/Ndef.java b/core/java/android/nfc/tech/Ndef.java
index 226e079..b1d5303 100644
--- a/core/java/android/nfc/tech/Ndef.java
+++ b/core/java/android/nfc/tech/Ndef.java
@@ -176,8 +176,11 @@ public final class Ndef extends BasicTagTechnology {
* <p>If the NDEF Message is modified by an I/O operation then it
* will not be updated here, this function only returns what was discovered
* when the tag entered the field.
+ * <p>Note that this method may return null if the tag was in the
+ * INITIALIZED state as defined by NFC Forum, as in this state the
+ * tag is formatted to support NDEF but does not contain a message yet.
* <p>Does not cause any RF activity and does not block.
- * @return NDEF Message read from the tag at discovery time
+ * @return NDEF Message read from the tag at discovery time, can be null
*/
public NdefMessage getCachedNdefMessage() {
return mNdefMsg;
@@ -245,11 +248,15 @@ public final class Ndef extends BasicTagTechnology {
*
* <p>This always reads the current NDEF Message stored on the tag.
*
+ * <p>Note that this method may return null if the tag was in the
+ * INITIALIZED state as defined by NFC Forum, as in that state the
+ * tag is formatted to support NDEF but does not contain a message yet.
+ *
* <p>This is an I/O operation and will block until complete. It must
* not be called from the main application thread. A blocked call will be canceled with
* {@link IOException} if {@link #close} is called from another thread.
*
- * @return the NDEF Message, never null
+ * @return the NDEF Message, can be null
* @throws TagLostException if the tag leaves the field
* @throws IOException if there is an I/O failure, or the operation is canceled
* @throws FormatException if the NDEF Message on the tag is malformed
@@ -265,17 +272,8 @@ public final class Ndef extends BasicTagTechnology {
int serviceHandle = mTag.getServiceHandle();
if (tagService.isNdef(serviceHandle)) {
NdefMessage msg = tagService.ndefRead(serviceHandle);
- if (msg == null) {
- int errorCode = tagService.getLastError(serviceHandle);
- switch (errorCode) {
- case ErrorCodes.ERROR_IO:
- throw new IOException();
- case ErrorCodes.ERROR_INVALID_PARAM:
- throw new FormatException();
- default:
- // Should not happen
- throw new IOException();
- }
+ if (msg == null && !tagService.isPresent(serviceHandle)) {
+ throw new TagLostException();
}
return msg;
} else {