Roll android_tools support library to 25.1.0
[android_tools.git] / sdk / sources / android-23 / android / net / wifi / p2p / nsd / WifiP2pServiceInfo.java
blobb931475ed4ab55f76b8652d5845c1d587d44709e
1 /*
2 * Copyright (C) 2012 The Android Open Source Project
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
8 * http://www.apache.org/licenses/LICENSE-2.0
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.
17 package android.net.wifi.p2p.nsd;
19 import android.os.Parcel;
20 import android.os.Parcelable;
22 import java.util.ArrayList;
23 import java.util.List;
25 /**
26 * A class for storing service information that is advertised
27 * over a Wi-Fi peer-to-peer setup
29 * @see WifiP2pUpnpServiceInfo
30 * @see WifiP2pDnsSdServiceInfo
32 public class WifiP2pServiceInfo implements Parcelable {
34 /**
35 * All service protocol types.
37 public static final int SERVICE_TYPE_ALL = 0;
39 /**
40 * DNS based service discovery protocol.
42 public static final int SERVICE_TYPE_BONJOUR = 1;
44 /**
45 * UPnP protocol.
47 public static final int SERVICE_TYPE_UPNP = 2;
49 /**
50 * WS-Discovery protocol
51 * @hide
53 public static final int SERVICE_TYPE_WS_DISCOVERY = 3;
55 /**
56 * Vendor Specific protocol
58 public static final int SERVICE_TYPE_VENDOR_SPECIFIC = 255;
60 /**
61 * the list of query string for wpa_supplicant
63 * e.g)
64 * # IP Printing over TCP (PTR) (RDATA=MyPrinter._ipp._tcp.local.)
65 * {"bonjour", "045f697070c00c000c01", "094d795072696e746572c027"
67 * # IP Printing over TCP (TXT) (RDATA=txtvers=1,pdl=application/postscript)
68 * {"bonjour", "096d797072696e746572045f697070c00c001001",
69 * "09747874766572733d311a70646c3d6170706c69636174696f6e2f706f7374736372797074"}
71 * [UPnP]
72 * # UPnP uuid
73 * {"upnp", "10", "uuid:6859dede-8574-59ab-9332-123456789012"}
75 * # UPnP rootdevice
76 * {"upnp", "10", "uuid:6859dede-8574-59ab-9332-123456789012::upnp:rootdevice"}
78 * # UPnP device
79 * {"upnp", "10", "uuid:6859dede-8574-59ab-9332-123456789012::urn:schemas-upnp
80 * -org:device:InternetGatewayDevice:1"}
82 * # UPnP service
83 * {"upnp", "10", "uuid:6859dede-8574-59ab-9322-123456789012::urn:schemas-upnp
84 * -org:service:ContentDirectory:2"}
86 private List<String> mQueryList;
88 /**
89 * This is only used in subclass.
91 * @param queryList query string for wpa_supplicant
92 * @hide
94 protected WifiP2pServiceInfo(List<String> queryList) {
95 if (queryList == null) {
96 throw new IllegalArgumentException("query list cannot be null");
98 mQueryList = queryList;
102 * Return the list of the query string for wpa_supplicant.
104 * @return the list of the query string for wpa_supplicant.
105 * @hide
107 public List<String> getSupplicantQueryList() {
108 return mQueryList;
112 * Converts byte array to hex string.
114 * @param data
115 * @return hex string.
116 * @hide
118 static String bin2HexStr(byte[] data) {
119 StringBuffer sb = new StringBuffer();
121 for (byte b: data) {
122 String s = null;
123 try {
124 s = Integer.toHexString(b & 0xff);
125 } catch (Exception e) {
126 e.printStackTrace();
127 return null;
129 //add 0 padding
130 if (s.length() == 1) {
131 sb.append('0');
133 sb.append(s);
135 return sb.toString();
138 @Override
139 public boolean equals(Object o) {
140 if (o == this) {
141 return true;
143 if (!(o instanceof WifiP2pServiceInfo)) {
144 return false;
147 WifiP2pServiceInfo servInfo = (WifiP2pServiceInfo)o;
148 return mQueryList.equals(servInfo.mQueryList);
151 @Override
152 public int hashCode() {
153 int result = 17;
154 result = 31 * result + (mQueryList == null ? 0 : mQueryList.hashCode());
155 return result;
158 /** Implement the Parcelable interface {@hide} */
159 public int describeContents() {
160 return 0;
163 /** Implement the Parcelable interface {@hide} */
164 public void writeToParcel(Parcel dest, int flags) {
165 dest.writeStringList(mQueryList);
168 /** Implement the Parcelable interface {@hide} */
169 public static final Creator<WifiP2pServiceInfo> CREATOR =
170 new Creator<WifiP2pServiceInfo>() {
171 public WifiP2pServiceInfo createFromParcel(Parcel in) {
173 List<String> data = new ArrayList<String>();
174 in.readStringList(data);
175 return new WifiP2pServiceInfo(data);
178 public WifiP2pServiceInfo[] newArray(int size) {
179 return new WifiP2pServiceInfo[size];