Methods Summary |
---|
public int | describeContents()Implement the Parcelable interface {@hide}
return 0;
|
public boolean | equals(java.lang.Object o)
if (o == this) {
return true;
}
if (!(o instanceof WifiP2pServiceResponse)) {
return false;
}
WifiP2pServiceResponse req = (WifiP2pServiceResponse)o;
return (req.mServiceType == mServiceType) &&
(req.mStatus == mStatus) &&
equals(req.mDevice.deviceAddress, mDevice.deviceAddress) &&
Arrays.equals(req.mData, mData);
|
private boolean | equals(java.lang.Object a, java.lang.Object b)
if (a == null && b == null) {
return true;
} else if (a != null) {
return a.equals(b);
}
return false;
|
public byte[] | getRawData()Return response data.
Data format depends on service type
return mData;
|
public int | getServiceType()Return the service type of service discovery response.
return mServiceType;
|
public android.net.wifi.p2p.WifiP2pDevice | getSrcDevice()Returns the source device of service discovery response.
This is valid only when service discovery response.
return mDevice;
|
public int | getStatus()Return the status code of service discovery response.
return mStatus;
|
public int | getTransactionId()Return the transaction id of service discovery response.
return mTransId;
|
public int | hashCode()
int result = 17;
result = 31 * result + mServiceType;
result = 31 * result + mStatus;
result = 31 * result + mTransId;
result = 31 * result + (mDevice.deviceAddress == null ?
0 : mDevice.deviceAddress.hashCode());
result = 31 * result + (mData == null ? 0 : mData.hashCode());
return result;
|
private static byte[] | hexStr2Bin(java.lang.String hex)Converts hex string to byte array.
int sz = hex.length()/2;
byte[] b = new byte[hex.length()/2];
for (int i=0;i<sz;i++) {
try {
b[i] = (byte)Integer.parseInt(hex.substring(i*2, i*2+2), 16);
} catch (Exception e) {
e.printStackTrace();
return null;
}
}
return b;
|
public static java.util.List | newInstance(java.lang.String supplicantEvent)Create the list of WifiP2pServiceResponse instance from supplicant event.
The format is as follows.
P2P-SERV-DISC-RESP <address> <update indicator> <response data>
e.g) P2P-SERV-DISC-RESP 02:03:7f:11:62:da 1 0300000101
List<WifiP2pServiceResponse> respList = new ArrayList<WifiP2pServiceResponse>();
String[] args = supplicantEvent.split(" ");
if (args.length != 4) {
return null;
}
WifiP2pDevice dev = new WifiP2pDevice();
String srcAddr = args[1];
dev.deviceAddress = srcAddr;
//String updateIndicator = args[2];//not used.
byte[] bin = hexStr2Bin(args[3]);
if (bin == null) {
return null;
}
DataInputStream dis = new DataInputStream(new ByteArrayInputStream(bin));
try {
while (dis.available() > 0) {
/*
* Service discovery header is as follows.
* ______________________________________________________________
* | Length(2byte) | Type(1byte) | TransId(1byte)}|
* ______________________________________________________________
* | status(1byte) | vendor specific(variable) |
*/
// The length equals to 3 plus the number of octets in the vendor
// specific content field. And this is little endian.
int length = (dis.readUnsignedByte() +
(dis.readUnsignedByte() << 8)) - 3;
int type = dis.readUnsignedByte();
int transId = dis.readUnsignedByte();
int status = dis.readUnsignedByte();
if (length < 0) {
return null;
}
if (length == 0) {
if (status == Status.SUCCESS) {
respList.add(new WifiP2pServiceResponse(type, status,
transId, dev, null));
}
continue;
}
if (length > MAX_BUF_SIZE) {
dis.skip(length);
continue;
}
byte[] data = new byte[length];
dis.readFully(data);
WifiP2pServiceResponse resp;
if (type == WifiP2pServiceInfo.SERVICE_TYPE_BONJOUR) {
resp = WifiP2pDnsSdServiceResponse.newInstance(status,
transId, dev, data);
} else if (type == WifiP2pServiceInfo.SERVICE_TYPE_UPNP) {
resp = WifiP2pUpnpServiceResponse.newInstance(status,
transId, dev, data);
} else {
resp = new WifiP2pServiceResponse(type, status, transId, dev, data);
}
if (resp != null && resp.getStatus() == Status.SUCCESS) {
respList.add(resp);
}
}
return respList;
} catch (IOException e) {
e.printStackTrace();
}
if (respList.size() > 0) {
return respList;
}
return null;
|
public void | setSrcDevice(android.net.wifi.p2p.WifiP2pDevice dev)
if (dev == null) return;
this.mDevice = dev;
|
public java.lang.String | toString()
StringBuffer sbuf = new StringBuffer();
sbuf.append("serviceType:").append(mServiceType);
sbuf.append(" status:").append(Status.toString(mStatus));
sbuf.append(" srcAddr:").append(mDevice.deviceAddress);
sbuf.append(" data:").append(mData);
return sbuf.toString();
|
public void | writeToParcel(android.os.Parcel dest, int flags)Implement the Parcelable interface {@hide}
dest.writeInt(mServiceType);
dest.writeInt(mStatus);
dest.writeInt(mTransId);
dest.writeParcelable(mDevice, flags);
if (mData == null || mData.length == 0) {
dest.writeInt(0);
} else {
dest.writeInt(mData.length);
dest.writeByteArray(mData);
}
|