Merge "Fix NPE on mock NDEF tech operations."

This commit is contained in:
Martijn Coenen
2011-12-15 10:32:11 -08:00
committed by Android (Google) Code Review
2 changed files with 17 additions and 2 deletions

View File

@@ -113,7 +113,7 @@ public final class Tag implements Parcelable {
/*package*/ final String[] mTechStringList;
/*package*/ final Bundle[] mTechExtras;
/*package*/ final int mServiceHandle; // for use by NFC service, 0 indicates a mock
/*package*/ final INfcTag mTagService;
/*package*/ final INfcTag mTagService; // interface to NFC service, will be null if mock tag
/*package*/ int mConnectedTechnology;
@@ -148,7 +148,7 @@ public final class Tag implements Parcelable {
* @hide
*/
public static Tag createMockTag(byte[] id, int[] techList, Bundle[] techListExtras) {
// set serviceHandle to 0 to indicate mock tag
// set serviceHandle to 0 and tagService to null to indicate mock tag
return new Tag(id, techList, techListExtras, 0, null);
}
@@ -266,6 +266,9 @@ public final class Tag implements Parcelable {
throw new IllegalStateException("Close connection to the technology first!");
}
if (mTagService == null) {
throw new IOException("Mock tags don't support this operation.");
}
try {
Tag newTag = mTagService.rediscover(getServiceHandle());
if (newTag != null) {

View File

@@ -259,6 +259,9 @@ public final class Ndef extends BasicTagTechnology {
try {
INfcTag tagService = mTag.getTagService();
if (tagService == null) {
throw new IOException("Mock tags don't support this operation.");
}
int serviceHandle = mTag.getServiceHandle();
if (tagService.isNdef(serviceHandle)) {
NdefMessage msg = tagService.ndefRead(serviceHandle);
@@ -303,6 +306,9 @@ public final class Ndef extends BasicTagTechnology {
try {
INfcTag tagService = mTag.getTagService();
if (tagService == null) {
throw new IOException("Mock tags don't support this operation.");
}
int serviceHandle = mTag.getServiceHandle();
if (tagService.isNdef(serviceHandle)) {
int errorCode = tagService.ndefWrite(serviceHandle, msg);
@@ -335,6 +341,9 @@ public final class Ndef extends BasicTagTechnology {
*/
public boolean canMakeReadOnly() {
INfcTag tagService = mTag.getTagService();
if (tagService == null) {
return false;
}
try {
return tagService.canMakeReadOnly(mNdefType);
} catch (RemoteException e) {
@@ -366,6 +375,9 @@ public final class Ndef extends BasicTagTechnology {
try {
INfcTag tagService = mTag.getTagService();
if (tagService == null) {
return false;
}
if (tagService.isNdef(mTag.getServiceHandle())) {
int errorCode = tagService.ndefMakeReadOnly(mTag.getServiceHandle());
switch (errorCode) {