diff options
| author | Martijn Coenen <martijn.coenen@nxp.com> | 2010-12-07 23:01:02 -0800 |
|---|---|---|
| committer | Android Git Automerger <android-git-automerger@android.com> | 2010-12-07 23:01:02 -0800 |
| commit | 53bf29b9169c2240bea4c18676dcb34783d57f26 (patch) | |
| tree | 17583fd055238e880d3fb3b4208b83791c74cdf1 | |
| parent | 055ed42e7062bd46820b8e629cda0b7cf9a4fb65 (diff) | |
| parent | 2f3ed7912e852da88efd5ebf9651ba3a89d3c9bd (diff) | |
| download | frameworks_base-53bf29b9169c2240bea4c18676dcb34783d57f26.zip frameworks_base-53bf29b9169c2240bea4c18676dcb34783d57f26.tar.gz frameworks_base-53bf29b9169c2240bea4c18676dcb34783d57f26.tar.bz2 | |
am 2f3ed791: am 5289b91c: Implement ndef formatting.
* commit '2f3ed7912e852da88efd5ebf9651ba3a89d3c9bd':
Implement ndef formatting.
| -rw-r--r-- | core/java/android/nfc/INfcTag.aidl | 3 | ||||
| -rw-r--r-- | core/java/android/nfc/Tag.java | 4 | ||||
| -rw-r--r-- | core/java/android/nfc/technology/NdefFormatable.java | 34 |
3 files changed, 38 insertions, 3 deletions
diff --git a/core/java/android/nfc/INfcTag.aidl b/core/java/android/nfc/INfcTag.aidl index ad3c1bb..f5c79e7 100644 --- a/core/java/android/nfc/INfcTag.aidl +++ b/core/java/android/nfc/INfcTag.aidl @@ -37,4 +37,5 @@ interface INfcTag int write(int nativeHandle, in NdefMessage msg); int makeReadOnly(int nativeHandle); int getModeHint(int nativeHandle); -}
\ No newline at end of file + int formatNdef(int nativeHandle, in byte[] key); +} diff --git a/core/java/android/nfc/Tag.java b/core/java/android/nfc/Tag.java index 2f6b3a5..36de915 100644 --- a/core/java/android/nfc/Tag.java +++ b/core/java/android/nfc/Tag.java @@ -21,6 +21,7 @@ import android.nfc.technology.MifareClassic; import android.nfc.technology.MifareUltralight; import android.nfc.technology.NfcV; import android.nfc.technology.Ndef; +import android.nfc.technology.NdefFormatable; import android.nfc.technology.NfcA; import android.nfc.technology.NfcB; import android.nfc.technology.NfcF; @@ -157,6 +158,9 @@ public class Tag implements Parcelable { case TagTechnology.NDEF: { return new Ndef(adapter, this, tech, extras); } + case TagTechnology.NDEF_FORMATABLE: { + return new NdefFormatable(adapter, this, tech, extras); + } case TagTechnology.NFC_F: { return new NfcF(adapter, this, extras); } diff --git a/core/java/android/nfc/technology/NdefFormatable.java b/core/java/android/nfc/technology/NdefFormatable.java index 7c4f9ab..3ed37a5 100644 --- a/core/java/android/nfc/technology/NdefFormatable.java +++ b/core/java/android/nfc/technology/NdefFormatable.java @@ -56,7 +56,37 @@ public final class NdefFormatable extends BasicTagTechnology { * Formats a tag as NDEF, if possible. You may supply a first * NdefMessage to be written on the tag. */ - public void format(NdefMessage firstMessage) throws IOException { - throw new UnsupportedOperationException(); + public void format(NdefMessage firstMessage) throws IOException, FormatException { + try { + byte[] DEFAULT_KEY = {(byte)0xFF,(byte)0xFF,(byte)0xFF, + (byte)0xFF,(byte)0xFF,(byte)0xFF}; + int serviceHandle = mTag.getServiceHandle(); + int errorCode = mTagService.formatNdef(serviceHandle, DEFAULT_KEY); + 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(); + } + errorCode = mTagService.write(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(); + } + } catch (RemoteException e) { + attemptDeadServiceRecovery(e); + } } } |
