Skip to content

Commit fc5a3b6

Browse files
Martijn Coenenjham
authored andcommitted
Changed transceive on all technologies to "raw", except for Mifare classes.
Change-Id: I3d680e37fec0ab84cdbb70d9fb6fff9527dd76a2
1 parent 3300e4c commit fc5a3b6

File tree

6 files changed

+63
-3
lines changed

6 files changed

+63
-3
lines changed

core/java/android/nfc/INfcTag.aidl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ interface INfcTag
2929
byte[] getUid(int nativeHandle);
3030
boolean isNdef(int nativeHandle);
3131
boolean isPresent(int nativeHandle);
32-
byte[] transceive(int nativeHandle, in byte[] data);
32+
byte[] transceive(int nativeHandle, in byte[] data, boolean raw);
3333

3434
int getLastError(int nativeHandle);
3535

core/java/android/nfc/technology/BasicTagTechnology.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -181,9 +181,9 @@ public void close() {
181181
*/
182182
public byte[] transceive(byte[] data) throws IOException {
183183
try {
184-
byte[] response = mTagService.transceive(mTag.getServiceHandle(), data);
184+
byte[] response = mTagService.transceive(mTag.getServiceHandle(), data, true);
185185
if (response == null) {
186-
throw new IOException("transcieve failed");
186+
throw new IOException("transceive failed");
187187
}
188188
return response;
189189
} catch (RemoteException e) {

core/java/android/nfc/technology/MifareClassic.java

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -285,5 +285,30 @@ public byte[] readBlock(int sector, int block) throws IOException {
285285
public void writeSectorAccessControl(int sector, int access);
286286
public void increment(int block);
287287
public void decrement(int block);
288+
288289
*/
290+
/**
291+
* Send data to a tag and receive the response.
292+
* <p>
293+
* This method will block until the response is received. It can be canceled
294+
* with {@link #close}.
295+
* <p>Requires {@link android.Manifest.permission#NFC} permission.
296+
*
297+
* @param data bytes to send
298+
* @return bytes received in response
299+
* @throws IOException if the target is lost or connection closed
300+
*/
301+
@Override
302+
public byte[] transceive(byte[] data) throws IOException {
303+
try {
304+
byte[] response = mTagService.transceive(mTag.getServiceHandle(), data, false);
305+
if (response == null) {
306+
throw new IOException("transceive failed");
307+
}
308+
return response;
309+
} catch (RemoteException e) {
310+
attemptDeadServiceRecovery(e);
311+
throw new IOException("NFC service died");
312+
}
313+
}
289314
}

core/java/android/nfc/technology/MifareUltralight.java

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,31 @@ public byte[] readBlock(int block) throws IOException {
7070
return transceive(blockread_cmd);
7171
}
7272

73+
/**
74+
* Send data to a tag and receive the response.
75+
* <p>
76+
* This method will block until the response is received. It can be canceled
77+
* with {@link #close}.
78+
* <p>Requires {@link android.Manifest.permission#NFC} permission.
79+
*
80+
* @param data bytes to send
81+
* @return bytes received in response
82+
* @throws IOException if the target is lost or connection closed
83+
*/
84+
@Override
85+
public byte[] transceive(byte[] data) throws IOException {
86+
try {
87+
byte[] response = mTagService.transceive(mTag.getServiceHandle(), data, false);
88+
if (response == null) {
89+
throw new IOException("transceive failed");
90+
}
91+
return response;
92+
} catch (RemoteException e) {
93+
attemptDeadServiceRecovery(e);
94+
throw new IOException("NFC service died");
95+
}
96+
}
97+
7398
/**
7499
* @throws IOException
75100
*/

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

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -195,4 +195,9 @@ public boolean makeReadonly() throws IOException {
195195
public void makeLowLevelReadonly() {
196196
throw new UnsupportedOperationException();
197197
}
198+
199+
@Override
200+
public byte[] transceive(byte[] data) {
201+
throw new UnsupportedOperationException();
202+
}
198203
}

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

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,4 +89,9 @@ public void format(NdefMessage firstMessage) throws IOException, FormatException
8989
attemptDeadServiceRecovery(e);
9090
}
9191
}
92+
93+
@Override
94+
public byte[] transceive(byte[] data) {
95+
throw new UnsupportedOperationException();
96+
}
9297
}

0 commit comments

Comments
 (0)