Skip to content

Commit 07e6f61

Browse files
Martijn CoenenNick Pelly
authored andcommitted
Check NDEF before calling makeReadOnly().
Change-Id: Iadbaf5c29821eff78ad487b248af529febcdc4ce
1 parent a701cf8 commit 07e6f61

File tree

1 file changed

+17
-12
lines changed

1 file changed

+17
-12
lines changed

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

Lines changed: 17 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -221,18 +221,23 @@ public boolean makeReadonly() throws IOException {
221221
checkConnected();
222222

223223
try {
224-
int errorCode = mTagService.ndefMakeReadOnly(mTag.getServiceHandle());
225-
switch (errorCode) {
226-
case ErrorCodes.SUCCESS:
227-
return true;
228-
case ErrorCodes.ERROR_IO:
229-
throw new IOException();
230-
case ErrorCodes.ERROR_INVALID_PARAM:
231-
return false;
232-
default:
233-
// Should not happen
234-
throw new IOException();
235-
}
224+
if (mTagService.isNdef(mTag.getServiceHandle())) {
225+
int errorCode = mTagService.ndefMakeReadOnly(mTag.getServiceHandle());
226+
switch (errorCode) {
227+
case ErrorCodes.SUCCESS:
228+
return true;
229+
case ErrorCodes.ERROR_IO:
230+
throw new IOException();
231+
case ErrorCodes.ERROR_INVALID_PARAM:
232+
return false;
233+
default:
234+
// Should not happen
235+
throw new IOException();
236+
}
237+
}
238+
else {
239+
throw new IOException("Tag is not ndef");
240+
}
236241
} catch (RemoteException e) {
237242
Log.e(TAG, "NFC service dead", e);
238243
return false;

0 commit comments

Comments
 (0)