summaryrefslogtreecommitdiffstats
path: root/core/java/android/nfc
diff options
context:
space:
mode:
authorNick Pelly <npelly@google.com>2011-01-31 23:27:37 -0800
committerNick Pelly <npelly@google.com>2011-02-01 09:20:45 -0800
commitf003e26df96067b4b136f0859012cb7ec3ed930f (patch)
treeba9fc5774bf961c77eadcf4ac427739b26771859 /core/java/android/nfc
parent113834c5ab30bfc554202d0f3144a662d77f2484 (diff)
downloadframeworks_base-f003e26df96067b4b136f0859012cb7ec3ed930f.zip
frameworks_base-f003e26df96067b4b136f0859012cb7ec3ed930f.tar.gz
frameworks_base-f003e26df96067b4b136f0859012cb7ec3ed930f.tar.bz2
Final final final Gingerbread MR API changes.
This is it. I promise. ACTION_TECHNOLOGY_DISCOVERED -> ACTION_TECH_DISCOVERED This was missed in our technology->tech rename. Hide TagTechnology.reconnect() This is used to reset any per-connection state in a tag, by reconnecting to it. The first problem is that it belongs on Tag, not TagTechnology. The second problem is that it may become redundant once we add Tag.rediscover() which will also reconnect to the tag, and will also return a new Tag with newly created technologies enumerated. And the third and most significant problem is that you can already achieve the same result by just calling close() followed by connect(). Hide Tag.createMockTag() This API cannot be used reliably. First it requires using int[] for the technology list, but those int constants are now hidden. Second it requires knowledge of the extras parcel used to fill technology specific data - also not public. Introduce TagTechnology.isConnected() Every child class already impelmented this, and given that connect() and close() are defined on the interface, then isConnected() should be there too. Modify Ndef.getType to return a string (not int) Allows more flexibility in adding new NDEF types. Current public strings are org.nfcforum.ndef.type1 org.nfcforum.ndef.type2 org.nfcforum.ndef.type3 org.nfcforum.ndef.type4 com.nxp.ndef.mifareclassic Add NdefFormatable.formatReadOnly() This allows you to make the tag read-only at the same time as performing format and write. It is important because we currently don't have any public API to re-enumerate a tag technology list after making a tag NDEF compatible, so you can't perform the format as a seperate step without physically removing the tag from field and returning it. Modify Readonly -> ReadOnly Make Tag class final Change-Id: Icf306aeb37b936ca3007e4868e99b6baceac4aff
Diffstat (limited to 'core/java/android/nfc')
-rw-r--r--core/java/android/nfc/NfcAdapter.java6
-rw-r--r--core/java/android/nfc/Tag.java3
-rw-r--r--core/java/android/nfc/tech/BasicTagTechnology.java11
-rw-r--r--core/java/android/nfc/tech/Ndef.java64
-rw-r--r--core/java/android/nfc/tech/NdefFormatable.java32
-rw-r--r--core/java/android/nfc/tech/TagTechnology.java12
6 files changed, 97 insertions, 31 deletions
diff --git a/core/java/android/nfc/NfcAdapter.java b/core/java/android/nfc/NfcAdapter.java
index 4808032..d30a0c6 100644
--- a/core/java/android/nfc/NfcAdapter.java
+++ b/core/java/android/nfc/NfcAdapter.java
@@ -44,10 +44,10 @@ public final class NfcAdapter {
/**
* Intent to start an activity when a tag with NDEF payload is discovered.
* If the tag has and NDEF payload this intent is started before
- * {@link #ACTION_TECHNOLOGY_DISCOVERED}.
+ * {@link #ACTION_TECH_DISCOVERED}.
*
* If any activities respond to this intent neither
- * {@link #ACTION_TECHNOLOGY_DISCOVERED} or {@link #ACTION_TAG_DISCOVERED} will be started.
+ * {@link #ACTION_TECH_DISCOVERED} or {@link #ACTION_TAG_DISCOVERED} will be started.
*/
@SdkConstant(SdkConstantType.ACTIVITY_INTENT_ACTION)
public static final String ACTION_NDEF_DISCOVERED = "android.nfc.action.NDEF_DISCOVERED";
@@ -63,7 +63,7 @@ public final class NfcAdapter {
* If any activities respond to this intent {@link #ACTION_TAG_DISCOVERED} will not be started.
*/
@SdkConstant(SdkConstantType.ACTIVITY_INTENT_ACTION)
- public static final String ACTION_TECHNOLOGY_DISCOVERED = "android.nfc.action.TECH_DISCOVERED";
+ public static final String ACTION_TECH_DISCOVERED = "android.nfc.action.TECH_DISCOVERED";
/**
* Intent to start an activity when a tag is discovered.
diff --git a/core/java/android/nfc/Tag.java b/core/java/android/nfc/Tag.java
index aae75c9..45a3447 100644
--- a/core/java/android/nfc/Tag.java
+++ b/core/java/android/nfc/Tag.java
@@ -55,7 +55,7 @@ import java.util.Arrays;
* not cause any further RF activity or block. Note however that arrays passed to and
* returned by this class are *not* cloned, so be careful not to modify them.
*/
-public class Tag implements Parcelable {
+public final class Tag implements Parcelable {
/*package*/ final byte[] mId;
/*package*/ final int[] mTechList;
/*package*/ final String[] mTechStringList;
@@ -93,6 +93,7 @@ public class Tag implements Parcelable {
* @param id The tag identifier, can be null
* @param techList must not be null
* @return freshly constructed tag
+ * @hide
*/
public static Tag createMockTag(byte[] id, int[] techList, Bundle[] techListExtras) {
// set serviceHandle to 0 to indicate mock tag
diff --git a/core/java/android/nfc/tech/BasicTagTechnology.java b/core/java/android/nfc/tech/BasicTagTechnology.java
index 32a850d..7ec807a 100644
--- a/core/java/android/nfc/tech/BasicTagTechnology.java
+++ b/core/java/android/nfc/tech/BasicTagTechnology.java
@@ -53,15 +53,7 @@ import java.io.IOException;
}
}
- /**
- * Helper to indicate if {@link #connect} has succeeded.
- * <p>
- * Does not cause RF activity, and does not block.
- * @return true if {@link #connect} has completed successfully and the {@link Tag} is believed
- * to be within range. Applications must still handle {@link java.io.IOException}
- * while using methods that require a connection in case the connection is lost after this
- * method returns.
- */
+ @Override
public boolean isConnected() {
if (!mIsConnected) {
return false;
@@ -94,6 +86,7 @@ import java.io.IOException;
}
}
+ /** @hide */
@Override
public void reconnect() throws IOException {
if (!mIsConnected) {
diff --git a/core/java/android/nfc/tech/Ndef.java b/core/java/android/nfc/tech/Ndef.java
index c6804f9..39ff282 100644
--- a/core/java/android/nfc/tech/Ndef.java
+++ b/core/java/android/nfc/tech/Ndef.java
@@ -61,12 +61,31 @@ public final class Ndef extends BasicTagTechnology {
/** @hide */
public static final String EXTRA_NDEF_TYPE = "ndeftype";
- public static final int OTHER = -1;
- public static final int NFC_FORUM_TYPE_1 = 1;
- public static final int NFC_FORUM_TYPE_2 = 2;
- public static final int NFC_FORUM_TYPE_3 = 3;
- public static final int NFC_FORUM_TYPE_4 = 4;
- public static final int MIFARE_CLASSIC = 101;
+ /** @hide */
+ public static final int TYPE_OTHER = -1;
+ /** @hide */
+ public static final int TYPE_1 = 1;
+ /** @hide */
+ public static final int TYPE_2 = 2;
+ /** @hide */
+ public static final int TYPE_3 = 3;
+ /** @hide */
+ public static final int TYPE_4 = 4;
+ /** @hide */
+ public static final int TYPE_MIFARE_CLASSIC = 101;
+
+ /** @hide */
+ public static final String UNKNOWN = "android.ndef.unknown";
+
+ public static final String NFC_FORUM_TYPE_1 = "org.nfcforum.ndef.type1";
+
+ public static final String NFC_FORUM_TYPE_2 = "org.nfcforum.ndef.type2";
+
+ public static final String NFC_FORUM_TYPE_3 = "org.nfcforum.ndef.type3";
+
+ public static final String NFC_FORUM_TYPE_4 = "org.nfcforum.ndef.type4";
+
+ public static final String MIFARE_CLASSIC = "com.nxp.ndef.mifareclassic";
private final int mMaxNdefSize;
private final int mCardState;
@@ -118,18 +137,27 @@ public final class Ndef extends BasicTagTechnology {
* Get NDEF tag type.
* <p>Returns one of {@link #NFC_FORUM_TYPE_1}, {@link #NFC_FORUM_TYPE_2},
* {@link #NFC_FORUM_TYPE_3}, {@link #NFC_FORUM_TYPE_4},
- * {@link #MIFARE_CLASSIC} or {@link #OTHER}.
- * <p>Platforms of this API revision will always return one of the above
- * values. Platforms at future API revisions may return other values, which
- * can be treated as {@link #OTHER} by applications targeting this API.
+ * {@link #MIFARE_CLASSIC} or another NDEF tag type that is not yet in the
+ * Android API.
* <p>Android devices with NFC support must always correctly enumerate
* NFC Forum tag types, and may optionally enumerate
* {@link #MIFARE_CLASSIC} since it requires proprietary technology.
- * Devices that cannot enumerate {@link #MIFARE_CLASSIC} will use
- * {@link #OTHER} instead.
*/
- public int getType() {
- return mNdefType;
+ public String getType() {
+ switch (mNdefType) {
+ case TYPE_1:
+ return NFC_FORUM_TYPE_1;
+ case TYPE_2:
+ return NFC_FORUM_TYPE_2;
+ case TYPE_3:
+ return NFC_FORUM_TYPE_3;
+ case TYPE_4:
+ return NFC_FORUM_TYPE_4;
+ case TYPE_MIFARE_CLASSIC:
+ return MIFARE_CLASSIC;
+ default:
+ return UNKNOWN;
+ }
}
/**
@@ -217,10 +245,10 @@ public final class Ndef extends BasicTagTechnology {
/**
* Indicates whether a tag can be made read-only with
- * {@link #makeReadonly()}
+ * {@link #makeReadOnly()}
*/
- public boolean canMakeReadonly() {
- if (mNdefType == NFC_FORUM_TYPE_1 || mNdefType == NFC_FORUM_TYPE_2) {
+ public boolean canMakeReadOnly() {
+ if (mNdefType == TYPE_1 || mNdefType == TYPE_2) {
return true;
} else {
return false;
@@ -234,7 +262,7 @@ public final class Ndef extends BasicTagTechnology {
* This is a one-way process and can not be reverted!
* @throws IOException
*/
- public boolean makeReadonly() throws IOException {
+ public boolean makeReadOnly() throws IOException {
checkConnected();
try {
diff --git a/core/java/android/nfc/tech/NdefFormatable.java b/core/java/android/nfc/tech/NdefFormatable.java
index 2919c43..e2828b5 100644
--- a/core/java/android/nfc/tech/NdefFormatable.java
+++ b/core/java/android/nfc/tech/NdefFormatable.java
@@ -65,8 +65,25 @@ 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.
+ * <p>Either all steps succeed, or an IOException is thrown if any one step
+ * fails.
*/
public void format(NdefMessage firstMessage) throws IOException, FormatException {
+ format(firstMessage, false);
+ }
+
+ /**
+ * Formats a tag as NDEF, if possible. You may supply a first
+ * NdefMessage to be written on the tag.
+ * <p>Either all steps succeed, or an IOException is thrown if any one step
+ * fails.
+ */
+ public void formatReadOnly(NdefMessage firstMessage) throws IOException, FormatException {
+ format(firstMessage, true);
+ }
+
+ /*package*/ void format(NdefMessage firstMessage, boolean makeReadOnly) throws IOException,
+ FormatException {
checkConnected();
try {
@@ -101,6 +118,21 @@ public final class NdefFormatable extends BasicTagTechnology {
} else {
throw new IOException();
}
+ // optionally make read-only
+ if (makeReadOnly) {
+ errorCode = tagService.ndefMakeReadOnly(serviceHandle);
+ switch (errorCode) {
+ case ErrorCodes.SUCCESS:
+ break;
+ case ErrorCodes.ERROR_IO:
+ throw new IOException();
+ case ErrorCodes.ERROR_INVALID_PARAM:
+ throw new IOException();
+ default:
+ // Should not happen
+ throw new IOException();
+ }
+ }
} catch (RemoteException e) {
Log.e(TAG, "NFC service dead", e);
}
diff --git a/core/java/android/nfc/tech/TagTechnology.java b/core/java/android/nfc/tech/TagTechnology.java
index c8ccdcf..50df865 100644
--- a/core/java/android/nfc/tech/TagTechnology.java
+++ b/core/java/android/nfc/tech/TagTechnology.java
@@ -121,6 +121,7 @@ public interface TagTechnology extends Closeable {
* @see #connect()
* @see #close()
* @throws IOException
+ * @hide
*/
public void reconnect() throws IOException;
@@ -137,4 +138,15 @@ public interface TagTechnology extends Closeable {
* @see #reconnect()
*/
public void close() throws IOException;
+
+ /**
+ * Helper to indicate if {@link #connect} has succeeded.
+ * <p>
+ * Does not cause RF activity, and does not block.
+ * @return true if {@link #connect} has completed successfully and the {@link Tag} is believed
+ * to be within range. Applications must still handle {@link java.io.IOException}
+ * while using methods that require a connection in case the connection is lost after this
+ * method returns.
+ */
+ public boolean isConnected();
}