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