Skip to content

Commit 3300e4c

Browse files
Martijn Coenenjham
authored andcommitted
Implemented isWritable() to indicate NDEF capability container r/w state.
Change-Id: Ie8bdf490c955e620f5e5029346fbe2e188ea4748
1 parent ae56a85 commit 3300e4c

File tree

1 file changed

+21
-31
lines changed

1 file changed

+21
-31
lines changed

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

Lines changed: 21 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -38,19 +38,24 @@
3838
* permission.
3939
*/
4040
public final class Ndef extends BasicTagTechnology {
41-
public static final int NDEF_MODE_READ_ONCE = 1;
42-
public static final int NDEF_MODE_READ_ONLY = 2;
43-
public static final int NDEF_MODE_WRITE_ONCE = 3;
44-
public static final int NDEF_MODE_WRITE_MANY = 4;
45-
public static final int NDEF_MODE_UNKNOWN = 5;
41+
/** @hide */
42+
public static final int NDEF_MODE_READ_ONLY = 1;
43+
/** @hide */
44+
public static final int NDEF_MODE_READ_WRITE = 2;
45+
/** @hide */
46+
public static final int NDEF_MODE_UNKNOWN = 3;
4647

4748
/** @hide */
4849
public static final String EXTRA_NDEF_MSG = "ndefmsg";
4950

5051
/** @hide */
5152
public static final String EXTRA_NDEF_MAXLENGTH = "ndefmaxlength";
5253

53-
private final int maxNdefSize;
54+
/** @hide */
55+
public static final String EXTRA_NDEF_CARDSTATE = "ndefcardstate";
56+
57+
private final int mMaxNdefSize;
58+
private final int mCardState;
5459

5560
/**
5661
* Internal constructor, to be used by NfcAdapter
@@ -59,10 +64,12 @@ public final class Ndef extends BasicTagTechnology {
5964
public Ndef(NfcAdapter adapter, Tag tag, int tech, Bundle extras) throws RemoteException {
6065
super(adapter, tag, tech);
6166
if (extras != null) {
62-
maxNdefSize = extras.getInt(EXTRA_NDEF_MAXLENGTH);
67+
mMaxNdefSize = extras.getInt(EXTRA_NDEF_MAXLENGTH);
68+
mCardState = extras.getInt(EXTRA_NDEF_CARDSTATE);
6369
} else {
64-
maxNdefSize = 0; //TODO: throw exception
70+
throw new NullPointerException("NDEF tech extras are null.");
6571
}
72+
6673
}
6774

6875
/**
@@ -104,35 +111,18 @@ public NdefMessage[] getExtraNdefMessage() throws IOException, FormatException {
104111
/**
105112
* Get maximum NDEF message size in bytes
106113
*/
107-
public int getSize() {
108-
return maxNdefSize;
114+
public int getMaxSize() {
115+
return mMaxNdefSize;
109116
}
110117

111118
/**
112-
* Read/Write mode hint.
113-
* Provides a hint if further reads or writes are likely to succeed.
119+
* Provides a hint on whether writes are likely to succeed.
114120
* <p>Requires {@link android.Manifest.permission#NFC} permission.
115-
* @return one of NDEF_MODE
121+
* @return true if write is likely to succeed
116122
* @throws IOException if the target is lost or connection closed
117123
*/
118-
public int getModeHint() throws IOException {
119-
try {
120-
int result = mTagService.getModeHint(mTag.getServiceHandle());
121-
if (ErrorCodes.isError(result)) {
122-
switch (result) {
123-
case ErrorCodes.ERROR_IO:
124-
throw new IOException();
125-
default:
126-
// Should not happen
127-
throw new IOException();
128-
}
129-
}
130-
return result;
131-
132-
} catch (RemoteException e) {
133-
attemptDeadServiceRecovery(e);
134-
return NDEF_MODE_UNKNOWN;
135-
}
124+
public boolean isWritable() {
125+
return (mCardState == NDEF_MODE_READ_WRITE);
136126
}
137127

138128
// Methods that require connect()

0 commit comments

Comments
 (0)