Merge "Add option to set frequency band" into jb-mr2-dev
This commit is contained in:
@@ -32,11 +32,7 @@
|
||||
</intent-filter>
|
||||
</activity>
|
||||
</application>
|
||||
<!-- default test runner -->
|
||||
<instrumentation android:name="android.test.InstrumentationTestRunner"
|
||||
android:targetPackage="com.android.connectivitymanagertest"
|
||||
android:label="default instrumentation test runner"
|
||||
/>
|
||||
|
||||
<!--
|
||||
This declares that this app uses the instrumentation test runner targeting
|
||||
the package of connectivitymanagertest. To run the tests use the command:
|
||||
@@ -68,6 +64,16 @@
|
||||
android:label="Test runner for Connectivity Manager Stress Tests"
|
||||
/>
|
||||
|
||||
<!-- run associate test:
|
||||
"adb shell am instrument -e ssid <ssid> -e password <password>
|
||||
-e ecurity-type [OPEN|WEP64|WEP128|WPA_TKIP|WPA2_AES] -e frequency-band [2.4|5.0|auto]
|
||||
-w com.android.connectivitymanagertest/.WifiAssociationTestRunner"
|
||||
-->
|
||||
<instrumentation android:name=".WifiAssociationTestRunner"
|
||||
android:targetPackage="com.android.connectivitymanagertest"
|
||||
android:label="Test runner for Wifi association test"
|
||||
/>
|
||||
|
||||
<uses-permission android:name="android.permission.INTERNET" />
|
||||
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE" />
|
||||
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
|
||||
|
||||
@@ -0,0 +1,88 @@
|
||||
/*
|
||||
* Copyright (C) 2013, The Android Open Source Project
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package com.android.connectivitymanagertest;
|
||||
|
||||
import android.content.Context;
|
||||
import android.net.wifi.WifiManager;
|
||||
import android.os.Bundle;
|
||||
import android.test.InstrumentationTestRunner;
|
||||
import android.test.InstrumentationTestSuite;
|
||||
import android.util.Log;
|
||||
|
||||
import com.android.connectivitymanagertest.functional.WifiAssociationTest;
|
||||
|
||||
import junit.framework.TestSuite;
|
||||
import junit.framework.Assert;
|
||||
|
||||
/**
|
||||
* Instrumentation Test Runner for wifi association test.
|
||||
* The instrument will set frequency band if it is necessary
|
||||
*
|
||||
* To run the association tests:
|
||||
*
|
||||
* adb shell am instrument -e ssid <ssid> -e password <password> \
|
||||
* -e security-type [OPEN|WEP64|WEP128|WPA_TKIP|WPA2_AES] -e frequency-band [2.4|5.0|auto]
|
||||
* -w com.android.connectivitymanagertest/.WifiAssociationTestRunner"
|
||||
*/
|
||||
public class WifiAssociationTestRunner extends InstrumentationTestRunner {
|
||||
private static final String TAG = "WifiAssociationTestRunner";
|
||||
public int mBand;
|
||||
|
||||
@Override
|
||||
public TestSuite getAllTests() {
|
||||
TestSuite suite = new InstrumentationTestSuite(this);
|
||||
suite.addTestSuite(WifiAssociationTest.class);
|
||||
return suite;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ClassLoader getLoader() {
|
||||
return WifiAssociationTestRunner.class.getClassLoader();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onCreate(Bundle icicle) {
|
||||
super.onCreate(icicle);
|
||||
Bundle arguments = icicle;
|
||||
String mFrequencyBand = arguments.getString("frequency-band");
|
||||
if (mFrequencyBand != null) {
|
||||
setFrequencyBand(mFrequencyBand);
|
||||
}
|
||||
}
|
||||
|
||||
private void setFrequencyBand(String band) {
|
||||
WifiManager mWifiManager = (WifiManager)getContext().getSystemService(Context.WIFI_SERVICE);
|
||||
if (band.equals("2.4")) {
|
||||
Log.v(TAG, "set frequency band to 2.4");
|
||||
mBand = WifiManager.WIFI_FREQUENCY_BAND_2GHZ;
|
||||
} else if (band.equals("5.0")) {
|
||||
Log.v(TAG, "set frequency band to 5.0");
|
||||
mBand = WifiManager.WIFI_FREQUENCY_BAND_5GHZ;
|
||||
} else if (band.equals("auto")) {
|
||||
Log.v(TAG, "set frequency band to auto");
|
||||
mBand = WifiManager.WIFI_FREQUENCY_BAND_AUTO;
|
||||
} else {
|
||||
Assert.fail("invalid frequency band");
|
||||
}
|
||||
int currentFreq = mWifiManager.getFrequencyBand();
|
||||
if (mBand == currentFreq) {
|
||||
Log.v(TAG, "frequency band has been set");
|
||||
return;
|
||||
}
|
||||
mWifiManager.setFrequencyBand(mBand, true);
|
||||
}
|
||||
}
|
||||
@@ -17,6 +17,7 @@
|
||||
package com.android.connectivitymanagertest.functional;
|
||||
|
||||
import com.android.connectivitymanagertest.ConnectivityManagerTestActivity;
|
||||
import com.android.connectivitymanagertest.WifiAssociationTestRunner;
|
||||
|
||||
import android.content.Context;
|
||||
import android.os.Bundle;
|
||||
@@ -27,22 +28,19 @@ import android.net.wifi.WifiConfiguration.AuthAlgorithm;
|
||||
import android.net.wifi.WifiConfiguration.GroupCipher;
|
||||
import android.net.wifi.WifiConfiguration.PairwiseCipher;
|
||||
import android.net.wifi.WifiConfiguration.Protocol;
|
||||
import android.net.wifi.WifiConfiguration.Status;
|
||||
import android.net.wifi.WifiManager;
|
||||
import android.net.ConnectivityManager;
|
||||
import android.net.NetworkInfo;
|
||||
import android.net.NetworkInfo.State;
|
||||
import android.test.suitebuilder.annotation.LargeTest;
|
||||
import android.test.ActivityInstrumentationTestCase2;
|
||||
import android.test.InstrumentationTestRunner;
|
||||
import android.util.Log;
|
||||
|
||||
/**
|
||||
* Test Wi-Fi connection with different configuration
|
||||
* To run this tests:
|
||||
* adb shell am instrument -e ssid <ssid> -e password <password>
|
||||
* -e security-type <security-type>
|
||||
* -w com.android.connectivitymanagertest/android.test.InstrumentationTestRunner
|
||||
* * adb shell am instrument -e ssid <ssid> -e password <password> \
|
||||
* -e security-type [OPEN|WEP64|WEP128|WPA_TKIP|WPA2_AES] -e frequency-band [2.4|5.0|auto]
|
||||
* -w com.android.connectivitymanagertest/.WifiAssociationTestRunner"
|
||||
*/
|
||||
public class WifiAssociationTest
|
||||
extends ActivityInstrumentationTestCase2<ConnectivityManagerTestActivity> {
|
||||
@@ -51,6 +49,8 @@ public class WifiAssociationTest
|
||||
private String mSsid = null;
|
||||
private String mPassword = null;
|
||||
private String mSecurityType = null;
|
||||
private String mFrequencyBand = null;
|
||||
private int mBand;
|
||||
private WifiManager mWifiManager = null;
|
||||
|
||||
enum SECURITY_TYPE {
|
||||
@@ -64,15 +64,18 @@ public class WifiAssociationTest
|
||||
@Override
|
||||
public void setUp() throws Exception {
|
||||
super.setUp();
|
||||
InstrumentationTestRunner mRunner = (InstrumentationTestRunner)getInstrumentation();
|
||||
WifiAssociationTestRunner mRunner = (WifiAssociationTestRunner)getInstrumentation();
|
||||
mWifiManager = (WifiManager) mRunner.getContext().getSystemService(Context.WIFI_SERVICE);
|
||||
mAct = getActivity();
|
||||
Bundle arguments = mRunner.getArguments();
|
||||
mSecurityType = arguments.getString("security-type");
|
||||
mSsid = arguments.getString("ssid");
|
||||
mPassword = arguments.getString("password");
|
||||
mFrequencyBand = arguments.getString("frequency-band");
|
||||
mBand = mRunner.mBand;
|
||||
assertNotNull("Security type is empty", mSecurityType);
|
||||
assertNotNull("Ssid is empty", mSsid);
|
||||
validateFrequencyBand();
|
||||
// enable Wifi and verify wpa_supplicant is started
|
||||
assertTrue("enable Wifi failed", mAct.enableWifi());
|
||||
sleep(2 * ConnectivityManagerTestActivity.SHORT_TIMEOUT,
|
||||
@@ -88,6 +91,14 @@ public class WifiAssociationTest
|
||||
super.tearDown();
|
||||
}
|
||||
|
||||
private void validateFrequencyBand() {
|
||||
if (mFrequencyBand != null) {
|
||||
int currentFreq = mWifiManager.getFrequencyBand();
|
||||
Log.v(TAG, "read frequency band: " + currentFreq);
|
||||
assertTrue("device frequency band is not set successfully", (mBand == currentFreq));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Connect to the provided Wi-Fi network
|
||||
* @param config is the network configuration
|
||||
|
||||
Reference in New Issue
Block a user