diff options
author | Martijn Coenen <martijn.coenen@nxp.com> | 2010-12-13 08:14:01 -0800 |
---|---|---|
committer | Android Git Automerger <android-git-automerger@android.com> | 2010-12-13 08:14:01 -0800 |
commit | 6c2471649b5b1d1d9c19305a43676161823b623a (patch) | |
tree | 99aa9f2bff307767fabdc948c916cc5a346e3b5b | |
parent | 80c78a896f32461513b9750fc2869cd6b2795888 (diff) | |
parent | e3f6336bcffc250da90ec864bccfa73ad1d016b9 (diff) | |
download | frameworks_base-6c2471649b5b1d1d9c19305a43676161823b623a.zip frameworks_base-6c2471649b5b1d1d9c19305a43676161823b623a.tar.gz frameworks_base-6c2471649b5b1d1d9c19305a43676161823b623a.tar.bz2 |
am e3f6336b: Fixed API for active NDEF reading and NDEF formatting.
* commit 'e3f6336bcffc250da90ec864bccfa73ad1d016b9':
Fixed API for active NDEF reading and NDEF formatting.
-rw-r--r-- | core/java/android/nfc/technology/Ndef.java | 55 | ||||
-rw-r--r-- | core/java/android/nfc/technology/NdefFormatable.java | 27 |
2 files changed, 50 insertions, 32 deletions
diff --git a/core/java/android/nfc/technology/Ndef.java b/core/java/android/nfc/technology/Ndef.java index aa3f04b..7e194aa 100644 --- a/core/java/android/nfc/technology/Ndef.java +++ b/core/java/android/nfc/technology/Ndef.java @@ -56,6 +56,7 @@ public final class Ndef extends BasicTagTechnology { private final int mMaxNdefSize; private final int mCardState; + private final NdefMessage mNdefMsg; /** * Internal constructor, to be used by NfcAdapter @@ -66,6 +67,7 @@ public final class Ndef extends BasicTagTechnology { if (extras != null) { mMaxNdefSize = extras.getInt(EXTRA_NDEF_MAXLENGTH); mCardState = extras.getInt(EXTRA_NDEF_CARDSTATE); + mNdefMsg = extras.getParcelable(EXTRA_NDEF_MSG); } else { throw new NullPointerException("NDEF tech extras are null."); } @@ -76,27 +78,8 @@ public final class Ndef extends BasicTagTechnology { * Get the primary NDEF message on this tag. This data is read at discovery time * and does not require a connection. */ - public NdefMessage getNdefMessage() throws IOException, FormatException { - try { - int serviceHandle = mTag.getServiceHandle(); - NdefMessage msg = mTagService.ndefRead(serviceHandle); - if (msg == null) { - int errorCode = mTagService.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(); - } - } - return msg; - } catch (RemoteException e) { - attemptDeadServiceRecovery(e); - return null; - } + public NdefMessage getCachedNdefMessage() { + return mNdefMsg; } /** @@ -126,6 +109,36 @@ public final class Ndef extends BasicTagTechnology { // Methods that require connect() /** + * Get the primary NDEF message on this tag. This data is read actively + * and requires a connection. + */ + public NdefMessage getNdefMessage() throws IOException, FormatException { + try { + int serviceHandle = mTag.getServiceHandle(); + if (mTagService.isNdef(serviceHandle)) { + NdefMessage msg = mTagService.ndefRead(serviceHandle); + if (msg == null) { + int errorCode = mTagService.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(); + } + } + return msg; + } else { + return null; + } + } catch (RemoteException e) { + attemptDeadServiceRecovery(e); + return null; + } + } + /** * Overwrite the primary NDEF message * @throws IOException */ diff --git a/core/java/android/nfc/technology/NdefFormatable.java b/core/java/android/nfc/technology/NdefFormatable.java index 05fd67c..bd21e58 100644 --- a/core/java/android/nfc/technology/NdefFormatable.java +++ b/core/java/android/nfc/technology/NdefFormatable.java @@ -73,17 +73,22 @@ public final class NdefFormatable extends BasicTagTechnology { // Should not happen throw new IOException(); } - errorCode = mTagService.ndefWrite(serviceHandle, firstMessage); - switch (errorCode) { - case ErrorCodes.SUCCESS: - break; - case ErrorCodes.ERROR_IO: - throw new IOException(); - case ErrorCodes.ERROR_INVALID_PARAM: - throw new FormatException(); - default: - // Should not happen - throw new IOException(); + // Now check and see if the format worked + if (mTagService.isNdef(serviceHandle)) { + errorCode = mTagService.ndefWrite(serviceHandle, firstMessage); + switch (errorCode) { + case ErrorCodes.SUCCESS: + break; + case ErrorCodes.ERROR_IO: + throw new IOException(); + case ErrorCodes.ERROR_INVALID_PARAM: + throw new FormatException(); + default: + // Should not happen + throw new IOException(); + } + } else { + throw new IOException(); } } catch (RemoteException e) { attemptDeadServiceRecovery(e); |