Martijn Coenen | 1fa2aff | 2013-02-27 09:21:22 -0800 | [diff] [blame] | 1 | package android.nfc; |
| 2 | |
| 3 | import android.net.Uri; |
| 4 | import android.os.Parcel; |
| 5 | import android.os.Parcelable; |
Andres Morales | 56f299b | 2014-10-31 08:26:33 -0700 | [diff] [blame] | 6 | import android.os.UserHandle; |
Martijn Coenen | 1fa2aff | 2013-02-27 09:21:22 -0800 | [diff] [blame] | 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; |
Andres Morales | 56f299b | 2014-10-31 08:26:33 -0700 | [diff] [blame] | 18 | public final UserHandle userHandle; |
Martijn Coenen | 1fa2aff | 2013-02-27 09:21:22 -0800 | [diff] [blame] | 19 | public final int flags; |
| 20 | |
Andres Morales | 56f299b | 2014-10-31 08:26:33 -0700 | [diff] [blame] | 21 | public BeamShareData(NdefMessage msg, Uri[] uris, UserHandle userHandle, int flags) { |
Martijn Coenen | 1fa2aff | 2013-02-27 09:21:22 -0800 | [diff] [blame] | 22 | this.ndefMessage = msg; |
| 23 | this.uris = uris; |
Andres Morales | 56f299b | 2014-10-31 08:26:33 -0700 | [diff] [blame] | 24 | this.userHandle = userHandle; |
Martijn Coenen | 1fa2aff | 2013-02-27 09:21:22 -0800 | [diff] [blame] | 25 | this.flags = flags; |
| 26 | } |
| 27 | |
| 28 | @Override |
| 29 | public int describeContents() { |
| 30 | return 0; |
| 31 | } |
| 32 | |
| 33 | @Override |
| 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 | } |
Andres Morales | 56f299b | 2014-10-31 08:26:33 -0700 | [diff] [blame] | 41 | dest.writeParcelable(userHandle, 0); |
Martijn Coenen | 1fa2aff | 2013-02-27 09:21:22 -0800 | [diff] [blame] | 42 | dest.writeInt(this.flags); |
| 43 | } |
| 44 | |
| 45 | public static final 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 | } |
Andres Morales | 56f299b | 2014-10-31 08:26:33 -0700 | [diff] [blame] | 56 | UserHandle userHandle = source.readParcelable(UserHandle.class.getClassLoader()); |
Martijn Coenen | 1fa2aff | 2013-02-27 09:21:22 -0800 | [diff] [blame] | 57 | int flags = source.readInt(); |
| 58 | |
Andres Morales | 56f299b | 2014-10-31 08:26:33 -0700 | [diff] [blame] | 59 | return new BeamShareData(msg, uris, userHandle, flags); |
Martijn Coenen | 1fa2aff | 2013-02-27 09:21:22 -0800 | [diff] [blame] | 60 | } |
| 61 | |
| 62 | @Override |
| 63 | public BeamShareData[] newArray(int size) { |
| 64 | return new BeamShareData[size]; |
| 65 | } |
| 66 | }; |
| 67 | } |