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
|
@Override
|
||||||
public void writeToParcel(Parcel dest, int flags) {
|
public void writeToParcel(Parcel dest, int flags) {
|
||||||
|
// Null mTagService means this is a mock tag
|
||||||
|
int isMock = (mTagService == null)?1:0;
|
||||||
|
|
||||||
writeBytesWithNull(dest, mId);
|
writeBytesWithNull(dest, mId);
|
||||||
dest.writeInt(mTechList.length);
|
dest.writeInt(mTechList.length);
|
||||||
dest.writeIntArray(mTechList);
|
dest.writeIntArray(mTechList);
|
||||||
dest.writeTypedArray(mTechExtras, 0);
|
dest.writeTypedArray(mTechExtras, 0);
|
||||||
dest.writeInt(mServiceHandle);
|
dest.writeInt(mServiceHandle);
|
||||||
dest.writeStrongBinder(mTagService.asBinder());
|
dest.writeInt(isMock);
|
||||||
|
if (isMock == 0) {
|
||||||
|
dest.writeStrongBinder(mTagService.asBinder());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static final Parcelable.Creator<Tag> CREATOR =
|
public static final Parcelable.Creator<Tag> CREATOR =
|
||||||
new Parcelable.Creator<Tag>() {
|
new Parcelable.Creator<Tag>() {
|
||||||
@Override
|
@Override
|
||||||
public Tag createFromParcel(Parcel in) {
|
public Tag createFromParcel(Parcel in) {
|
||||||
|
INfcTag tagService;
|
||||||
|
|
||||||
// Tag fields
|
// Tag fields
|
||||||
byte[] id = Tag.readBytesWithNull(in);
|
byte[] id = Tag.readBytesWithNull(in);
|
||||||
int[] techList = new int[in.readInt()];
|
int[] techList = new int[in.readInt()];
|
||||||
in.readIntArray(techList);
|
in.readIntArray(techList);
|
||||||
Bundle[] techExtras = in.createTypedArray(Bundle.CREATOR);
|
Bundle[] techExtras = in.createTypedArray(Bundle.CREATOR);
|
||||||
int serviceHandle = in.readInt();
|
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);
|
return new Tag(id, techList, techExtras, serviceHandle, tagService);
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user