OSDN Git Service

Handle mock tags in android.nfc.Tag conversion to Parcel.
authorSylvain Fonteneau <sylvain.fonteneau@trusted-logic.com>
Mon, 24 Jan 2011 09:23:43 +0000 (10:23 +0100)
committerJeff Hamilton <jham@android.com>
Mon, 24 Jan 2011 18:15:13 +0000 (12:15 -0600)
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

core/java/android/nfc/Tag.java

index 55a9556..946ac24 100644 (file)
@@ -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.writeStrongBinder(mTagService.asBinder());
+        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);
         }