FileDocCategorySizeDatePackage
WifiP2pServiceRequest.javaAPI DocAndroid 5.1 API8855Thu Mar 12 22:22:44 GMT 2015android.net.wifi.p2p.nsd

WifiP2pServiceRequest

public class WifiP2pServiceRequest extends Object implements android.os.Parcelable
A class for creating a service discovery request for use with {@link WifiP2pManager#addServiceRequest} and {@link WifiP2pManager#removeServiceRequest}

This class is used to create service discovery request for custom vendor specific service discovery protocol {@link WifiP2pServiceInfo#SERVICE_TYPE_VENDOR_SPECIFIC} or to search all service protocols {@link WifiP2pServiceInfo#SERVICE_TYPE_ALL}.

For the purpose of creating a UPnP or Bonjour service request, use {@link WifiP2pUpnpServiceRequest} or {@link WifiP2pDnsSdServiceRequest} respectively. {@see WifiP2pManager} {@see WifiP2pUpnpServiceRequest} {@see WifiP2pDnsSdServiceRequest}

Fields Summary
private int
mProtocolType
Service discovery protocol. It's defined in table63 in Wi-Fi Direct specification.
private int
mLength
The length of the service request TLV. The value is equal to 2 plus the number of octets in the query data field.
private int
mTransId
Service transaction ID. This is a nonzero value used to match the service request/response TLVs.
private String
mQuery
The hex dump string of query data for the requested service information. e.g) DnsSd apple file sharing over tcp (dns name=_afpovertcp._tcp.local.) 0b5f6166706f766572746370c00c000c01
public static final Creator
CREATOR
Implement the Parcelable interface {@hide}
Constructors Summary
protected WifiP2pServiceRequest(int protocolType, String query)
This constructor is only used in newInstance().

param
protocolType service discovery protocol.
param
query The part of service specific query.
hide

        validateQuery(query);

        mProtocolType = protocolType;
        mQuery = query;
        if (query != null) {
            mLength = query.length()/2 + 2;
        } else {
            mLength = 2;
        }
    
private WifiP2pServiceRequest(int serviceType, int length, int transId, String query)
This constructor is only used in Parcelable.

param
serviceType service discovery type.
param
length the length of service discovery packet.
param
transId the transaction id
param
query The part of service specific query.

        mProtocolType = serviceType;
        mLength = length;
        mTransId = transId;
        mQuery = query;
    
Methods Summary
public intdescribeContents()
Implement the Parcelable interface {@hide}

        return 0;
    
public booleanequals(java.lang.Object o)

        if (o == this) {
            return true;
        }
        if (!(o instanceof WifiP2pServiceRequest)) {
            return false;
        }

        WifiP2pServiceRequest req = (WifiP2pServiceRequest)o;

        /*
         * Not compare transaction id.
         * Transaction id may be changed on each service discovery operation.
         */
        if ((req.mProtocolType != mProtocolType) ||
                (req.mLength != mLength)) {
            return false;
        }

        if (req.mQuery == null && mQuery == null) {
            return true;
        } else if (req.mQuery != null) {
            return req.mQuery.equals(mQuery);
        }
        return false;
   
public java.lang.StringgetSupplicantQuery()
Return wpa_supplicant request string. The format is the hex dump of the following frame.
_______________________________________________________________
| Length (2) | Type (1) | Transaction ID (1) |
| Query Data (variable) |

return
wpa_supplicant request string.
hide

        StringBuffer sb = new StringBuffer();
        // length is retained as little endian format.
        sb.append(String.format(Locale.US, "%02x", (mLength) & 0xff));
        sb.append(String.format(Locale.US, "%02x", (mLength >> 8) & 0xff));
        sb.append(String.format(Locale.US, "%02x", mProtocolType));
        sb.append(String.format(Locale.US, "%02x", mTransId));
        if (mQuery != null) {
            sb.append(mQuery);
        }

        return sb.toString();
    
public intgetTransactionId()
Return transaction id.

return
transaction id
hide

        return mTransId;
    
public inthashCode()

        int result = 17;
        result = 31 * result + mProtocolType;
        result = 31 * result + mLength;
        result = 31 * result + (mQuery == null ? 0 : mQuery.hashCode());
        return result;
    
public static android.net.wifi.p2p.nsd.WifiP2pServiceRequestnewInstance(int protocolType, java.lang.String queryData)
Create a service discovery request.

param
protocolType can be {@link WifiP2pServiceInfo#SERVICE_TYPE_ALL} or {@link WifiP2pServiceInfo#SERVICE_TYPE_VENDOR_SPECIFIC}. In order to create a UPnP or Bonjour service request, use {@link WifiP2pUpnpServiceRequest} or {@link WifiP2pDnsSdServiceRequest} respectively
param
queryData hex string that is vendor specific. Can be null.
return
service discovery request.

        return new WifiP2pServiceRequest(protocolType, queryData);
    
public static android.net.wifi.p2p.nsd.WifiP2pServiceRequestnewInstance(int protocolType)
Create a service discovery request.

param
protocolType can be {@link WifiP2pServiceInfo#SERVICE_TYPE_ALL} or {@link WifiP2pServiceInfo#SERVICE_TYPE_VENDOR_SPECIFIC}. In order to create a UPnP or Bonjour service request, use {@link WifiP2pUpnpServiceRequest} or {@link WifiP2pDnsSdServiceRequest} respectively
return
service discovery request.

        return new WifiP2pServiceRequest(protocolType, null);
    
public voidsetTransactionId(int id)
Set transaction id.

param
id
hide

        mTransId = id;
    
private voidvalidateQuery(java.lang.String query)
Validate query.

If invalid, throw IllegalArgumentException.

param
query The part of service specific query.

        if (query == null) {
            return;
        }

        int UNSIGNED_SHORT_MAX = 0xffff;
        if (query.length()%2 == 1) {
            throw new IllegalArgumentException(
                    "query size is invalid. query=" + query);
        }
        if (query.length()/2 > UNSIGNED_SHORT_MAX) {
            throw new IllegalArgumentException(
                    "query size is too large. len=" + query.length());
        }

        // check whether query is hex string.
        query = query.toLowerCase(Locale.ROOT);
        char[] chars = query.toCharArray();
        for (char c: chars) {
            if (!((c >= '0" && c <= '9") ||
                    (c >= 'a" && c <= 'f"))){
                throw new IllegalArgumentException(
                        "query should be hex string. query=" + query);
            }
        }
    
public voidwriteToParcel(android.os.Parcel dest, int flags)
Implement the Parcelable interface {@hide}

        dest.writeInt(mProtocolType);
        dest.writeInt(mLength);
        dest.writeInt(mTransId);
        dest.writeString(mQuery);