• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 
17 package com.android.nfc.handover;
18 
19 import android.bluetooth.BluetoothDevice;
20 import android.net.Uri;
21 import android.os.Parcel;
22 import android.os.Parcelable;
23 
24 public class PendingHandoverTransfer implements Parcelable {
25 
26     public String remoteMacAddress; // For type WIFI only
27     public BluetoothDevice remoteDevice; // For type BLUETOOTH only
28     public int id;
29     public boolean incoming;
30     public boolean remoteActivating;
31     public Uri[] uris;
32     public int deviceType;
33 
PendingHandoverTransfer(int id, boolean incoming, BluetoothDevice remoteDevice, boolean remoteActivating, Uri[] uris)34     private PendingHandoverTransfer(int id, boolean incoming, BluetoothDevice remoteDevice,
35                             boolean remoteActivating, Uri[] uris) {
36         this.id = id;
37         this.incoming = incoming;
38         this.remoteDevice = remoteDevice;
39         this.remoteActivating = remoteActivating;
40         this.uris = uris;
41 
42         this.deviceType = HandoverTransfer.DEVICE_TYPE_BLUETOOTH;
43     }
44 
PendingHandoverTransfer(int id, boolean incoming, String remoteMacAddress, boolean remoteActivating, Uri[] uris)45     private PendingHandoverTransfer(int id, boolean incoming, String remoteMacAddress,
46                             boolean remoteActivating, Uri[] uris) {
47         this.id = id;
48         this.incoming = incoming;
49         this.remoteMacAddress = remoteMacAddress;
50         this.remoteActivating = remoteActivating;
51         this.uris = uris;
52 
53         this.deviceType = HandoverTransfer.DEVICE_TYPE_WIFI;
54     }
55 
forBluetoothDevice( int id, boolean incoming, BluetoothDevice remoteDevice, boolean remoteActivating, Uri[] uris)56     public static final PendingHandoverTransfer forBluetoothDevice(
57             int id, boolean incoming, BluetoothDevice remoteDevice, boolean remoteActivating,
58             Uri[] uris) {
59        return new PendingHandoverTransfer(id, incoming, remoteDevice, remoteActivating, uris);
60     }
61 
forWifiDevice( int id, boolean incoming, String macAddress, boolean remoteActivating, Uri[] uris)62     public static final PendingHandoverTransfer forWifiDevice(
63             int id, boolean incoming, String macAddress, boolean remoteActivating, Uri[] uris) {
64         return new PendingHandoverTransfer(id, incoming, macAddress, remoteActivating, uris);
65     }
66 
67     public static final Parcelable.Creator<PendingHandoverTransfer> CREATOR
68             = new Parcelable.Creator<PendingHandoverTransfer>() {
69         public PendingHandoverTransfer createFromParcel(Parcel in) {
70             int id = in.readInt();
71             boolean incoming = (in.readInt() == 1) ? true : false;
72             int deviceType = in.readInt();
73             BluetoothDevice remoteDevice = null;
74             String remoteMac = null;
75             if (deviceType == HandoverTransfer.DEVICE_TYPE_BLUETOOTH) {
76                 remoteDevice = in.readParcelable(getClass().getClassLoader());
77             } else {
78                 remoteMac = in.readString();
79             }
80             boolean remoteActivating = (in.readInt() == 1) ? true : false;
81             int numUris = in.readInt();
82             Uri[] uris = null;
83             if (numUris > 0) {
84                 uris = new Uri[numUris];
85                 in.readTypedArray(uris, Uri.CREATOR);
86             }
87             if (deviceType == HandoverTransfer.DEVICE_TYPE_BLUETOOTH) {
88                 return new PendingHandoverTransfer(id, incoming, remoteDevice,
89                         remoteActivating, uris);
90             } else {
91                 return new PendingHandoverTransfer(id, incoming, remoteMac, remoteActivating, uris);
92             }
93         }
94 
95         @Override
96         public PendingHandoverTransfer[] newArray(int size) {
97             return new PendingHandoverTransfer[size];
98         }
99     };
100 
101     @Override
describeContents()102     public int describeContents() {
103         return 0;
104     }
105 
106     @Override
writeToParcel(Parcel dest, int flags)107     public void writeToParcel(Parcel dest, int flags) {
108         dest.writeInt(id);
109         dest.writeInt(incoming ? 1 : 0);
110         dest.writeInt(deviceType);
111         if (deviceType == HandoverTransfer.DEVICE_TYPE_BLUETOOTH) {
112             dest.writeParcelable(remoteDevice, 0);
113         } else {
114             dest.writeString(remoteMacAddress);
115         }
116         dest.writeInt(remoteActivating ? 1 : 0);
117         dest.writeInt(uris != null ? uris.length : 0);
118         if (uris != null && uris.length > 0) {
119             dest.writeTypedArray(uris, 0);
120         }
121     }
122 }
123