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