1 /* 2 * Copyright (C) 2018 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 com.android.cts.verifier.p2p.testcase; 18 19 import android.content.Context; 20 import android.net.wifi.p2p.WifiP2pConfig; 21 22 import com.android.cts.verifier.R; 23 24 /** 25 * Test case to join a p2p group with wps push button. 26 */ 27 public class P2pClientConfigTestCase extends ConnectReqTestCase { 28 29 private int mGroupOperatingBand = WifiP2pConfig.GROUP_OWNER_BAND_AUTO; 30 private int mGroupOperatingFrequency = 0; 31 private String mNetworkName = "DIRECT-XY-HELLO"; 32 P2pClientConfigTestCase(Context context)33 public P2pClientConfigTestCase(Context context) { 34 super(context); 35 } 36 P2pClientConfigTestCase(Context context, int bandOrFrequency)37 public P2pClientConfigTestCase(Context context, int bandOrFrequency) { 38 super(context); 39 StringBuilder builder = new StringBuilder(mNetworkName); 40 switch(bandOrFrequency) { 41 case WifiP2pConfig.GROUP_OWNER_BAND_AUTO: 42 break; 43 case WifiP2pConfig.GROUP_OWNER_BAND_2GHZ: 44 builder.append("-2.4G"); 45 mGroupOperatingBand = bandOrFrequency; 46 break; 47 case WifiP2pConfig.GROUP_OWNER_BAND_5GHZ: 48 builder.append("-5G"); 49 mGroupOperatingBand = bandOrFrequency; 50 break; 51 default: 52 builder.append("-" + bandOrFrequency + "MHz"); 53 mGroupOperatingFrequency = bandOrFrequency; 54 } 55 mNetworkName = builder.toString(); 56 } 57 58 @Override executeTest()59 protected boolean executeTest() throws InterruptedException { 60 61 WifiP2pConfig.Builder b = new WifiP2pConfig.Builder() 62 .setNetworkName(mNetworkName) 63 .setPassphrase("DEADBEEF"); 64 65 if (mGroupOperatingBand > 0) { 66 b.setGroupOperatingBand(mGroupOperatingBand); 67 } else if (mGroupOperatingFrequency > 0) { 68 b.setGroupOperatingFrequency(mGroupOperatingFrequency); 69 } 70 71 WifiP2pConfig config = b.build(); 72 73 return connectTest(config); 74 } 75 getListenerError(ListenerTest listener)76 private String getListenerError(ListenerTest listener) { 77 StringBuilder sb = new StringBuilder(); 78 sb.append(mContext.getText(R.string.p2p_receive_invalid_response_error)); 79 sb.append(listener.getReason()); 80 return sb.toString(); 81 } 82 83 @Override getTestName()84 public String getTestName() { 85 if (mGroupOperatingBand > 0) { 86 String bandName = ""; 87 switch (mGroupOperatingBand) { 88 case WifiP2pConfig.GROUP_OWNER_BAND_2GHZ: 89 bandName = "2.4G"; 90 break; 91 case WifiP2pConfig.GROUP_OWNER_BAND_5GHZ: 92 bandName = "5G"; 93 break; 94 } 95 return "Join p2p group test (" + bandName + " config)"; 96 } else if (mGroupOperatingFrequency > 0) { 97 String freqName = mGroupOperatingFrequency + " MHz"; 98 return "Join p2p group test (" + freqName + " config)"; 99 } else { 100 return "Join p2p group test (config)"; 101 } 102 } 103 } 104