1 /* 2 * Copyright (C) 2013, 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.connectivitymanagertest; 18 19 import android.content.Context; 20 import android.net.wifi.WifiManager; 21 import android.os.Bundle; 22 import android.test.InstrumentationTestRunner; 23 import android.test.InstrumentationTestSuite; 24 import android.util.Log; 25 26 import com.android.connectivitymanagertest.functional.WifiAssociationTest; 27 28 import junit.framework.TestSuite; 29 import junit.framework.Assert; 30 31 /** 32 * Instrumentation Test Runner for wifi association test. 33 * The instrument will set frequency band if it is necessary 34 * 35 * To run the association tests: 36 * 37 * adb shell am instrument -e ssid <ssid> -e password <password> \ 38 * -e security-type [OPEN|WEP64|WEP128|WPA_TKIP|WPA2_AES] -e frequency-band [2.4|5.0|auto] 39 * -w com.android.connectivitymanagertest/.WifiAssociationTestRunner" 40 */ 41 public class WifiAssociationTestRunner extends InstrumentationTestRunner { 42 private static final String TAG = "WifiAssociationTestRunner"; 43 public int mBand; 44 45 @Override 46 public TestSuite getAllTests() { 47 TestSuite suite = new InstrumentationTestSuite(this); 48 suite.addTestSuite(WifiAssociationTest.class); 49 return suite; 50 } 51 52 @Override 53 public ClassLoader getLoader() { 54 return WifiAssociationTestRunner.class.getClassLoader(); 55 } 56 57 @Override 58 public void onCreate(Bundle icicle) { 59 super.onCreate(icicle); 60 Bundle arguments = icicle; 61 String mFrequencyBand = arguments.getString("frequency-band"); 62 if (mFrequencyBand != null) { 63 setFrequencyBand(mFrequencyBand); 64 } 65 } 66 67 private void setFrequencyBand(String band) { 68 WifiManager mWifiManager = (WifiManager)getContext().getSystemService(Context.WIFI_SERVICE); 69 if (band.equals("2.4")) { 70 Log.v(TAG, "set frequency band to 2.4"); 71 mBand = WifiManager.WIFI_FREQUENCY_BAND_2GHZ; 72 } else if (band.equals("5.0")) { 73 Log.v(TAG, "set frequency band to 5.0"); 74 mBand = WifiManager.WIFI_FREQUENCY_BAND_5GHZ; 75 } else if (band.equals("auto")) { 76 Log.v(TAG, "set frequency band to auto"); 77 mBand = WifiManager.WIFI_FREQUENCY_BAND_AUTO; 78 } else { 79 Assert.fail("invalid frequency band"); 80 } 81 int currentFreq = mWifiManager.getFrequencyBand(); 82 if (mBand == currentFreq) { 83 Log.v(TAG, "frequency band has been set"); 84 return; 85 } 86 mWifiManager.setFrequencyBand(mBand, true); 87 } 88 } 89