Home | History | Annotate | Download | only in nsd
      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 android.net.wifi.p2p.nsd;
     18 
     19 import android.net.wifi.p2p.WifiP2pManager;
     20 
     21 /**
     22  * A class for creating a Bonjour service discovery request for use with
     23  * {@link WifiP2pManager#addServiceRequest} and {@link WifiP2pManager#removeServiceRequest}
     24  *
     25  * {@see WifiP2pManager}
     26  * {@see WifiP2pServiceRequest}
     27  * {@see WifiP2pUpnpServiceRequest}
     28  */
     29 public class WifiP2pDnsSdServiceRequest extends WifiP2pServiceRequest {
     30 
     31     /**
     32      * This constructor is only used in newInstance().
     33      *
     34      * @param query The part of service specific query.
     35      * @hide
     36      */
     37     private WifiP2pDnsSdServiceRequest(String query) {
     38         super(WifiP2pServiceInfo.SERVICE_TYPE_BONJOUR, query);
     39     }
     40 
     41     /**
     42      * This constructor is only used in newInstance().
     43      * @hide
     44      */
     45     private WifiP2pDnsSdServiceRequest() {
     46         super(WifiP2pServiceInfo.SERVICE_TYPE_BONJOUR, null);
     47     }
     48 
     49     private WifiP2pDnsSdServiceRequest(String dnsQuery, int dnsType, int version) {
     50         super(WifiP2pServiceInfo.SERVICE_TYPE_BONJOUR, WifiP2pDnsSdServiceInfo.createRequest(
     51                 dnsQuery,
     52                 dnsType,
     53                 version));
     54     }
     55 
     56     /**
     57      * Create a service discovery request to search all Bonjour services.
     58      *
     59      * @return service request for Bonjour.
     60      */
     61     public static WifiP2pDnsSdServiceRequest newInstance() {
     62         return new WifiP2pDnsSdServiceRequest();
     63     }
     64 
     65     /**
     66      * Create a service discovery to search for Bonjour services with the specified
     67      * service type.
     68      *
     69      * @param serviceType service type. Cannot be null <br>
     70      *  "_afpovertcp._tcp."(Apple File Sharing over TCP)<br>
     71      *  "_ipp._tcp" (IP Printing over TCP)<br>
     72      *  "_http._tcp" (http service)
     73      * @return service request for DnsSd.
     74      */
     75     public static WifiP2pDnsSdServiceRequest newInstance(String serviceType) {
     76         if (serviceType == null) {
     77             throw new IllegalArgumentException("service type cannot be null");
     78         }
     79         return new WifiP2pDnsSdServiceRequest(serviceType + ".local.",
     80                 WifiP2pDnsSdServiceInfo.DNS_TYPE_PTR,
     81                 WifiP2pDnsSdServiceInfo.VERSION_1);
     82     }
     83 
     84     /**
     85      * Create a service discovery request to get the TXT data from the specified
     86      * Bonjour service.
     87      *
     88      * @param instanceName instance name. Cannot be null. <br>
     89      *  "MyPrinter"
     90      * @param serviceType service type. Cannot be null. <br>
     91      * e.g) <br>
     92      *  "_afpovertcp._tcp"(Apple File Sharing over TCP)<br>
     93      *  "_ipp._tcp" (IP Printing over TCP)<br>
     94      * @return service request for Bonjour.
     95      */
     96     public static WifiP2pDnsSdServiceRequest newInstance(String instanceName,
     97             String serviceType) {
     98         if (instanceName == null || serviceType == null) {
     99             throw new IllegalArgumentException(
    100                     "instance name or service type cannot be null");
    101         }
    102         String fullDomainName = instanceName + "." + serviceType + ".local.";
    103         return new WifiP2pDnsSdServiceRequest(fullDomainName,
    104                 WifiP2pDnsSdServiceInfo.DNS_TYPE_TXT,
    105                 WifiP2pDnsSdServiceInfo.VERSION_1);
    106     }
    107 }
    108