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 import java.util.Locale;
22 
23 /**
24  * A class for creating a Upnp service discovery request for use with
25  * {@link WifiP2pManager#addServiceRequest} and {@link WifiP2pManager#removeServiceRequest}
26  *
27  * {@see WifiP2pManager}
28  * {@see WifiP2pServiceRequest}
29  * {@see WifiP2pDnsSdServiceRequest}
30  */
31 public class WifiP2pUpnpServiceRequest extends WifiP2pServiceRequest {
32 
33     /**
34      * This constructor is only used in newInstance().
35      *
36      * @param query The part of service specific query.
37      * @hide
38      */
WifiP2pUpnpServiceRequest(String query)39     protected WifiP2pUpnpServiceRequest(String query) {
40         super(WifiP2pServiceInfo.SERVICE_TYPE_UPNP, query);
41     }
42 
43     /**
44      * This constructor is only used in newInstance().
45      * @hide
46      */
WifiP2pUpnpServiceRequest()47     protected WifiP2pUpnpServiceRequest() {
48         super(WifiP2pServiceInfo.SERVICE_TYPE_UPNP, null);
49     }
50 
51     /**
52      * Create a service discovery request to search all UPnP services.
53      *
54      * @return service request for UPnP.
55      */
newInstance()56     public static WifiP2pUpnpServiceRequest newInstance() {
57         return new WifiP2pUpnpServiceRequest();
58     }
59     /**
60      * Create a service discovery request to search specified UPnP services.
61      *
62      * @param st ssdp search target.  Cannot be null.<br>
63      * e.g ) <br>
64      * <ul>
65      * <li>"ssdp:all"
66      * <li>"upnp:rootdevice"
67      * <li>"urn:schemas-upnp-org:device:MediaServer:2"
68      * <li>"urn:schemas-upnp-org:service:ContentDirectory:2"
69      * <li>"uuid:6859dede-8574-59ab-9332-123456789012"
70      * </ul>
71      * @return service request for UPnP.
72      */
newInstance(String st)73     public static WifiP2pUpnpServiceRequest newInstance(String st) {
74         if (st == null) {
75             throw new IllegalArgumentException("search target cannot be null");
76         }
77         StringBuffer sb = new StringBuffer();
78         sb.append(String.format(Locale.US, "%02x", WifiP2pUpnpServiceInfo.VERSION_1_0));
79         sb.append(WifiP2pServiceInfo.bin2HexStr(st.getBytes()));
80         return new WifiP2pUpnpServiceRequest(sb.toString());
81     }
82 }
83