Skip to content

Commit 641dd62

Browse files
committed
First pass at advanced NFC tag dispatching APIs and other cleanup.
Change-Id: I022fcd481274a2f68d93218026e77551cfae8cae
1 parent b79173f commit 641dd62

File tree

5 files changed

+40
-25
lines changed

5 files changed

+40
-25
lines changed

core/java/android/nfc/INfcTag.aidl

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -34,9 +34,9 @@ interface INfcTag
3434

3535
int getLastError(int nativeHandle);
3636

37-
NdefMessage read(int nativeHandle);
38-
int write(int nativeHandle, in NdefMessage msg);
39-
int makeReadOnly(int nativeHandle);
40-
int getModeHint(int nativeHandle);
37+
NdefMessage ndefRead(int nativeHandle);
38+
int ndefWrite(int nativeHandle, in NdefMessage msg);
39+
int ndefMakeReadOnly(int nativeHandle);
40+
boolean ndefIsWritable(int nativeHandle);
4141
int formatNdef(int nativeHandle, in byte[] key);
4242
}

core/java/android/nfc/NfcAdapter.java

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,32 @@
3636
public final class NfcAdapter {
3737
private static final String TAG = "NFC";
3838

39+
/**
40+
* Intent to start an activity when a tag with NDEF payload is discovered.
41+
* If the tag has and NDEF payload this intent is started before
42+
* {@link #ACTION_TECHNOLOGY_DISCOVERED}.
43+
*
44+
* If any activities respond to this intent neither
45+
* {@link #ACTION_TECHNOLOGY_DISCOVERED} or {@link #ACTION_TAG_DISCOVERED} will be started.
46+
* @hide
47+
*/
48+
@SdkConstant(SdkConstantType.ACTIVITY_INTENT_ACTION)
49+
public static final String ACTION_NDEF_DISCOVERED = "android.nfc.action.NDEF_DISCOVERED";
50+
51+
/**
52+
* Intent to started when a tag is discovered. The data URI is formated as
53+
* {@code vnd.android.nfc://tag/} with the path having a directory entry for each technology
54+
* in the {@link Tag#getTechnologyList()} is ascending order.
55+
*
56+
* This intent is started after {@link #ACTION_NDEF_DISCOVERED} and before
57+
* {@link #ACTION_TAG_DISCOVERED}
58+
*
59+
* If any activities respond to this intent {@link #ACTION_TAG_DISCOVERED} will not be started.
60+
* @hide
61+
*/
62+
@SdkConstant(SdkConstantType.ACTIVITY_INTENT_ACTION)
63+
public static final String ACTION_TECHNOLOGY_DISCOVERED = "android.nfc.action.TECH_DISCOVERED";
64+
3965
/**
4066
* Intent to start an activity when a tag is discovered.
4167
*/

core/java/android/nfc/technology/Ndef.java

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ public Ndef(NfcAdapter adapter, Tag tag, int tech, Bundle extras) throws RemoteE
7979
public NdefMessage getNdefMessage() throws IOException, FormatException {
8080
try {
8181
int serviceHandle = mTag.getServiceHandle();
82-
NdefMessage msg = mTagService.read(serviceHandle);
82+
NdefMessage msg = mTagService.ndefRead(serviceHandle);
8383
if (msg == null) {
8484
int errorCode = mTagService.getLastError(serviceHandle);
8585
switch (errorCode) {
@@ -119,7 +119,6 @@ public int getMaxSize() {
119119
* Provides a hint on whether writes are likely to succeed.
120120
* <p>Requires {@link android.Manifest.permission#NFC} permission.
121121
* @return true if write is likely to succeed
122-
* @throws IOException if the target is lost or connection closed
123122
*/
124123
public boolean isWritable() {
125124
return (mCardState == NDEF_MODE_READ_WRITE);
@@ -132,7 +131,7 @@ public boolean isWritable() {
132131
*/
133132
public void writeNdefMessage(NdefMessage msg) throws IOException, FormatException {
134133
try {
135-
int errorCode = mTagService.write(mTag.getServiceHandle(), msg);
134+
int errorCode = mTagService.ndefWrite(mTag.getServiceHandle(), msg);
136135
switch (errorCode) {
137136
case ErrorCodes.SUCCESS:
138137
break;
@@ -169,7 +168,7 @@ public void writeExtraNdefMessage(int i, NdefMessage msg) throws IOException, Fo
169168
*/
170169
public boolean makeReadonly() throws IOException {
171170
try {
172-
int errorCode = mTagService.makeReadOnly(mTag.getServiceHandle());
171+
int errorCode = mTagService.ndefMakeReadOnly(mTag.getServiceHandle());
173172
switch (errorCode) {
174173
case ErrorCodes.SUCCESS:
175174
return true;

core/java/android/nfc/technology/NdefFormatable.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ public void format(NdefMessage firstMessage) throws IOException, FormatException
7373
// Should not happen
7474
throw new IOException();
7575
}
76-
errorCode = mTagService.write(serviceHandle, firstMessage);
76+
errorCode = mTagService.ndefWrite(serviceHandle, firstMessage);
7777
switch (errorCode) {
7878
case ErrorCodes.SUCCESS:
7979
break;

core/java/android/nfc/technology/TagTechnology.java

Lines changed: 6 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -39,42 +39,32 @@ public interface TagTechnology {
3939
/**
4040
* This object is an instance of {@link NfcF}
4141
*/
42-
public static final int NFC_F = 11;
42+
public static final int NFC_F = 4;
4343

4444
/**
4545
* This object is an instance of {@link NfcV}
4646
*/
47-
public static final int NFC_V = 21;
47+
public static final int NFC_V = 5;
4848

4949
/**
5050
* This object is an instance of {@link Ndef}
5151
*/
52-
public static final int NDEF = 101;
52+
public static final int NDEF = 6;
5353

5454
/**
5555
* This object is an instance of {@link NdefFormatable}
5656
*/
57-
public static final int NDEF_FORMATABLE = 110;
57+
public static final int NDEF_FORMATABLE = 7;
5858

5959
/**
6060
* This object is an instance of {@link MifareClassic}
6161
*/
62-
public static final int MIFARE_CLASSIC = 200;
63-
64-
/**
65-
* A Mifare Classic tag with NDEF data
66-
*/
67-
public static final int MIFARE_CLASSIC_NDEF = 201;
62+
public static final int MIFARE_CLASSIC = 8;
6863

6964
/**
7065
* This object is an instance of {@link MifareUltralight}
7166
*/
72-
public static final int MIFARE_ULTRALIGHT = 202;
73-
74-
/**
75-
* A Mifare DESFire tag
76-
*/
77-
public static final int MIFARE_DESFIRE = 203;
67+
public static final int MIFARE_ULTRALIGHT = 9;
7868

7969
/**
8070
* Returns the technology type for this tag connection.

0 commit comments

Comments
 (0)