• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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.WifiP2pInfo;
20 
21 import com.android.cts.verifier.R;
22 
23 /**
24  * A test case which accepts a connection from p2p client.
25  *
26  * The requester device tries to join this device.
27  */
28 public class GoTestCase extends TestCase {
29 
30     protected P2pBroadcastReceiverTest mReceiverTest;
31 
GoTestCase(Context context)32     public GoTestCase(Context context) {
33         super(context);
34     }
35 
36     @Override
setUp()37     protected void setUp() {
38         super.setUp();
39         mReceiverTest = new P2pBroadcastReceiverTest(mContext);
40         mReceiverTest.init(mChannel);
41     }
42 
43     @Override
executeTest()44     protected boolean executeTest() throws InterruptedException {
45 
46         ActionListenerTest listener = new ActionListenerTest();
47 
48         /*
49          * Add renderer service
50          */
51         mP2pMgr.addLocalService(mChannel, LocalServices.createRendererService(),
52                 listener);
53         if (!listener.check(ActionListenerTest.SUCCESS, TIMEOUT)) {
54             mReason = mContext.getString(R.string.p2p_add_local_service_error);
55             return false;
56         }
57 
58         /*
59          * Add IPP service
60          */
61         mP2pMgr.addLocalService(mChannel, LocalServices.createIppService(),
62                 listener);
63         if (!listener.check(ActionListenerTest.SUCCESS, TIMEOUT)) {
64             mReason = mContext.getString(R.string.p2p_add_local_service_error);
65             return false;
66         }
67 
68         /*
69          * Add AFP service
70          */
71         mP2pMgr.addLocalService(mChannel, LocalServices.createAfpService(),
72                 listener);
73         if (!listener.check(ActionListenerTest.SUCCESS, TIMEOUT)) {
74             mReason = mContext.getString(R.string.p2p_add_local_service_error);
75             return false;
76         }
77 
78         /*
79          * Start up an autonomous group owner.
80          */
81         mP2pMgr.createGroup(mChannel, listener);
82         if (!listener.check(ActionListenerTest.SUCCESS, TIMEOUT)) {
83             mReason = mContext.getString(R.string.p2p_ceate_group_error);
84             return false;
85         }
86 
87         /*
88          * Check whether createGroup() is succeeded.
89          */
90         WifiP2pInfo info = mReceiverTest.waitConnectionNotice(TIMEOUT);
91         if (info == null || !info.isGroupOwner) {
92             mReason = mContext.getString(R.string.p2p_ceate_group_error);
93             return false;
94         }
95 
96         // wait until p2p client is joining.
97         return true;
98     }
99 
100     @Override
tearDown()101     protected void tearDown() {
102 
103         // wait until p2p client is joining.
104         synchronized(this) {
105             try {
106                 wait();
107             } catch (InterruptedException e) {
108                 e.printStackTrace();
109             }
110         }
111 
112         if (mP2pMgr != null) {
113             mP2pMgr.cancelConnect(mChannel, null);
114             mP2pMgr.removeGroup(mChannel, null);
115         }
116         if (mReceiverTest != null) {
117             mReceiverTest.close();
118         }
119         super.tearDown();
120     }
121 
122     @Override
getTestName()123     public String getTestName() {
124         return "Accept client connection test";
125     }
126 }
127