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 package com.android.cts.verifier.p2p.testcase; 17 18 import android.content.Context; 19 import android.net.wifi.p2p.nsd.WifiP2pDnsSdServiceRequest; 20 21 import com.android.cts.verifier.R; 22 23 /** 24 * Service discovery requester test case to removeServiceRequest and clearServiceResusts 25 * have no effect against another channel. 26 */ 27 public class ServReqMultiClientTestCase03 extends ServReqTestCase { 28 ServReqMultiClientTestCase03(Context context)29 public ServReqMultiClientTestCase03(Context context) { 30 super(context); 31 } 32 33 @Override executeTest()34 protected boolean executeTest() throws InterruptedException { 35 36 notifyTestMsg(R.string.p2p_checking_serv_capab); 37 38 ActionListenerTest actionListener = new ActionListenerTest(); 39 40 WifiP2pDnsSdServiceRequest bonjourReq = 41 WifiP2pDnsSdServiceRequest.newInstance(); 42 43 /* 44 * add Bonjour request to channel1. 45 */ 46 mP2pMgr.addServiceRequest(mChannel, bonjourReq, actionListener); 47 if (!actionListener.check(ActionListenerTest.SUCCESS, TIMEOUT)) { 48 mReason = mContext.getString(R.string.p2p_add_service_request_error); 49 return false; 50 } 51 52 /* 53 * Try to remove the bonjour request of channel1 on channel2. 54 * However, it should have no efferct. 55 */ 56 mP2pMgr.removeServiceRequest(mSubChannel, bonjourReq, actionListener); 57 if (!actionListener.check(ActionListenerTest.SUCCESS, TIMEOUT)) { 58 mReason = mContext.getString(R.string.p2p_remove_service_request_error); 59 return false; 60 } 61 62 /* 63 * clear the all requests on channel2. 64 * However, it should have no efferct. 65 */ 66 mP2pMgr.clearServiceRequests(mSubChannel, actionListener); 67 if (!actionListener.check(ActionListenerTest.SUCCESS, TIMEOUT)) { 68 mReason = mContext.getString(R.string.p2p_clear_service_requests_error); 69 return false; 70 } 71 72 /* 73 * initialize listener test. 74 */ 75 UPnPServiceResponseListenerTest upnpCh1Listener = 76 new UPnPServiceResponseListenerTest(mTargetAddress); 77 DnsSdResponseListenerTest dnsCh1Listener = 78 new DnsSdResponseListenerTest(mTargetAddress); 79 DnsSdTxtRecordListenerTest txtCh1Listener = 80 new DnsSdTxtRecordListenerTest(mTargetAddress); 81 UPnPServiceResponseListenerTest upnpCh2Listener = 82 new UPnPServiceResponseListenerTest(mTargetAddress); 83 DnsSdResponseListenerTest dnsCh2Listener = 84 new DnsSdResponseListenerTest(mTargetAddress); 85 DnsSdTxtRecordListenerTest txtCh2Listener = 86 new DnsSdTxtRecordListenerTest(mTargetAddress); 87 88 /* 89 * set service response listener callback. 90 */ 91 mP2pMgr.setUpnpServiceResponseListener(mChannel, upnpCh1Listener); 92 mP2pMgr.setDnsSdResponseListeners(mChannel, dnsCh1Listener, txtCh1Listener); 93 mP2pMgr.setUpnpServiceResponseListener(mSubChannel, upnpCh2Listener); 94 mP2pMgr.setDnsSdResponseListeners(mSubChannel, dnsCh2Listener, txtCh2Listener); 95 96 /* 97 * discover services 98 */ 99 mP2pMgr.discoverServices(mChannel, actionListener); 100 if (!actionListener.check(ActionListenerTest.SUCCESS, TIMEOUT)) { 101 mReason = mContext.getString(R.string.p2p_discover_services_error); 102 return false; 103 } 104 105 /* 106 * check that bonjour response can be received on channel1 107 * check that no UPnP response is received on channel1 108 */ 109 Timeout t = new Timeout(TIMEOUT); 110 if (!dnsCh1Listener.check(DnsSdResponseListenerTest.ALL_DNS_PTR, 111 t.getRemainTime())) { 112 mReason = getListenerError(dnsCh1Listener); 113 return false; 114 } 115 if (!txtCh1Listener.check(DnsSdTxtRecordListenerTest.ALL_DNS_TXT, 116 t.getRemainTime())) { 117 mReason = getListenerError(txtCh1Listener); 118 return false; 119 } 120 if (!upnpCh1Listener.check( 121 UPnPServiceResponseListenerTest.NO_UPNP_SERVICES, 122 t.getRemainTime())) { 123 mReason = getListenerError(upnpCh1Listener); 124 return false; 125 } 126 127 return true; 128 } 129 130 @Override getTestName()131 public String getTestName() { 132 return "Multiple clients test 03"; 133 } 134 } 135