Handle mock tags in android.nfc.Tag conversion to Parcel.
When generating a mock tag (after a NDEF exchange over LLCP), one of the internal fields is set to null. This was causing NullPointerException when being converted to a Parcel. This is fixed by not including this field in the Parcel for mock tags. Change-Id: I000e2faa54d71fd755ba7993e1e258743aad98fb
This commit is contained in:
committed by
Jeff Hamilton
parent
93300ce2d3
commit
c5a418ecb7
@ -187,25 +187,39 @@ public class Tag implements Parcelable {
|
||||
|
||||
@Override
|
||||
public void writeToParcel(Parcel dest, int flags) {
|
||||
// Null mTagService means this is a mock tag
|
||||
int isMock = (mTagService == null)?1:0;
|
||||
|
||||
writeBytesWithNull(dest, mId);
|
||||
dest.writeInt(mTechList.length);
|
||||
dest.writeIntArray(mTechList);
|
||||
dest.writeTypedArray(mTechExtras, 0);
|
||||
dest.writeInt(mServiceHandle);
|
||||
dest.writeInt(isMock);
|
||||
if (isMock == 0) {
|
||||
dest.writeStrongBinder(mTagService.asBinder());
|
||||
}
|
||||
}
|
||||
|
||||
public static final Parcelable.Creator<Tag> CREATOR =
|
||||
new Parcelable.Creator<Tag>() {
|
||||
@Override
|
||||
public Tag createFromParcel(Parcel in) {
|
||||
INfcTag tagService;
|
||||
|
||||
// Tag fields
|
||||
byte[] id = Tag.readBytesWithNull(in);
|
||||
int[] techList = new int[in.readInt()];
|
||||
in.readIntArray(techList);
|
||||
Bundle[] techExtras = in.createTypedArray(Bundle.CREATOR);
|
||||
int serviceHandle = in.readInt();
|
||||
INfcTag tagService = INfcTag.Stub.asInterface(in.readStrongBinder());
|
||||
int isMock = in.readInt();
|
||||
if (isMock == 0) {
|
||||
tagService = INfcTag.Stub.asInterface(in.readStrongBinder());
|
||||
}
|
||||
else {
|
||||
tagService = null;
|
||||
}
|
||||
|
||||
return new Tag(id, techList, techExtras, serviceHandle, tagService);
|
||||
}
|
||||
|
Reference in New Issue
Block a user