1 package android.nfc; 2 3 import android.net.Uri; 4 import android.os.Parcel; 5 import android.os.Parcelable; 6 7 /** 8 * Class to IPC data to be shared over Android Beam. 9 * Allows bundling NdefMessage, Uris and flags in a single 10 * IPC call. This is important as we want to reduce the 11 * amount of IPC calls at "touch time". 12 * @hide 13 */ 14 public final class BeamShareData implements Parcelable { 15 public final NdefMessage ndefMessage; 16 public final Uri[] uris; 17 public final int flags; 18 19 public BeamShareData(NdefMessage msg, Uri[] uris, int flags) { 20 this.ndefMessage = msg; 21 this.uris = uris; 22 this.flags = flags; 23 } 24 25 @Override 26 public int describeContents() { 27 return 0; 28 } 29 30 @Override 31 public void writeToParcel(Parcel dest, int flags) { 32 int urisLength = (uris != null) ? uris.length : 0; 33 dest.writeParcelable(ndefMessage, 0); 34 dest.writeInt(urisLength); 35 if (urisLength > 0) { 36 dest.writeTypedArray(uris, 0); 37 } 38 dest.writeInt(this.flags); 39 } 40 41 public static final Parcelable.Creator<BeamShareData> CREATOR = 42 new Parcelable.Creator<BeamShareData>() { 43 @Override 44 public BeamShareData createFromParcel(Parcel source) { 45 Uri[] uris = null; 46 NdefMessage msg = source.readParcelable(NdefMessage.class.getClassLoader()); 47 int numUris = source.readInt(); 48 if (numUris > 0) { 49 uris = new Uri[numUris]; 50 source.readTypedArray(uris, Uri.CREATOR); 51 } 52 int flags = source.readInt(); 53 54 return new BeamShareData(msg, uris, flags); 55 } 56 57 @Override 58 public BeamShareData[] newArray(int size) { 59 return new BeamShareData[size]; 60 } 61 }; 62 } 63