1/*
2 * Copyright (C) 2012 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 *      http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17package com.android.nfc.handover;
18
19import android.bluetooth.BluetoothDevice;
20import android.net.Uri;
21import android.os.Parcel;
22import android.os.Parcelable;
23
24public class PendingHandoverTransfer implements Parcelable {
25    public int id;
26    public boolean incoming;
27    public BluetoothDevice remoteDevice;
28    public boolean remoteActivating;
29    public Uri[] uris;
30
31    PendingHandoverTransfer(int id, boolean incoming, BluetoothDevice remoteDevice,
32            boolean remoteActivating, Uri[] uris) {
33        this.id = id;
34        this.incoming = incoming;
35        this.remoteDevice = remoteDevice;
36        this.remoteActivating = remoteActivating;
37        this.uris = uris;
38    }
39
40    public static final Parcelable.Creator<PendingHandoverTransfer> CREATOR
41            = new Parcelable.Creator<PendingHandoverTransfer>() {
42        public PendingHandoverTransfer createFromParcel(Parcel in) {
43            int id = in.readInt();
44            boolean incoming = (in.readInt() == 1) ? true : false;
45            BluetoothDevice remoteDevice = in.readParcelable(getClass().getClassLoader());
46            boolean remoteActivating = (in.readInt() == 1) ? true : false;
47            int numUris = in.readInt();
48            Uri[] uris = null;
49            if (numUris > 0) {
50                uris = new Uri[numUris];
51                in.readTypedArray(uris, Uri.CREATOR);
52            }
53            return new PendingHandoverTransfer(id, incoming, remoteDevice,
54                    remoteActivating, uris);
55        }
56
57        @Override
58        public PendingHandoverTransfer[] newArray(int size) {
59            return new PendingHandoverTransfer[size];
60        }
61    };
62
63    @Override
64    public int describeContents() {
65        return 0;
66    }
67
68    @Override
69    public void writeToParcel(Parcel dest, int flags) {
70        dest.writeInt(id);
71        dest.writeInt(incoming ? 1 : 0);
72        dest.writeParcelable(remoteDevice, 0);
73        dest.writeInt(remoteActivating ? 1 : 0);
74        dest.writeInt(uris != null ? uris.length : 0);
75        if (uris != null && uris.length > 0) {
76            dest.writeTypedArray(uris, 0);
77        }
78    }
79}
80