Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit c5a418ec authored by Sylvain Fonteneau's avatar Sylvain Fonteneau Committed by Jeff Hamilton
Browse files

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
parent 93300ce2
Loading
Loading
Loading
Loading
+16 −2
Original line number Diff line number Diff line
@@ -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);
        }