am c1c04ad0: Merge "Add Wi-Fi tests for static IP. DO NOT MERGE" into gingerbread
* commit 'c1c04ad047d7ca2f13aa5c9883da7219df5bee57': Add Wi-Fi tests for static IP. DO NOT MERGE
This commit is contained in:
@@ -13,6 +13,16 @@
|
|||||||
<security>PSK</security>
|
<security>PSK</security>
|
||||||
<password>androidwifi</password>
|
<password>androidwifi</password>
|
||||||
</accesspoint>
|
</accesspoint>
|
||||||
|
<accesspoint>
|
||||||
|
<ssid>securenetstatic</ssid>
|
||||||
|
<security>PSK</security>
|
||||||
|
<password>androidwifi</password>
|
||||||
|
<ip>192.168.14.2</ip>
|
||||||
|
<gateway>192.168.14.1</gateway>
|
||||||
|
<netmask>255.255.255.0</netmask>
|
||||||
|
<dns1>192.168.14.1</dns1>
|
||||||
|
<dns2>192.168.1.9</dns2>
|
||||||
|
</accesspoint>
|
||||||
<accesspoint>
|
<accesspoint>
|
||||||
<ssid>botnet</ssid>
|
<ssid>botnet</ssid>
|
||||||
<security>EAP</security>
|
<security>EAP</security>
|
||||||
|
|||||||
@@ -26,10 +26,12 @@ import org.xml.sax.helpers.DefaultHandler;
|
|||||||
import android.net.wifi.WifiConfiguration;
|
import android.net.wifi.WifiConfiguration;
|
||||||
import android.net.wifi.WifiConfiguration.AuthAlgorithm;
|
import android.net.wifi.WifiConfiguration.AuthAlgorithm;
|
||||||
import android.net.wifi.WifiConfiguration.KeyMgmt;
|
import android.net.wifi.WifiConfiguration.KeyMgmt;
|
||||||
|
import android.net.DhcpInfo;
|
||||||
|
|
||||||
import android.util.Log;
|
|
||||||
import java.io.InputStream;
|
import java.io.InputStream;
|
||||||
|
import java.net.UnknownHostException;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
|
import java.util.HashMap;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
|
|
||||||
@@ -38,7 +40,8 @@ import java.util.List;
|
|||||||
* The configurations of an access point is included in tag
|
* The configurations of an access point is included in tag
|
||||||
* <accesspoint></accesspoint>. The supported configuration includes: ssid,
|
* <accesspoint></accesspoint>. The supported configuration includes: ssid,
|
||||||
* security, eap, phase2, identity, password, anonymousidentity, cacert, usercert,
|
* security, eap, phase2, identity, password, anonymousidentity, cacert, usercert,
|
||||||
* in which each is included in the corresponding tags. All access points have to be
|
* in which each is included in the corresponding tags. Static IP setting is also supported.
|
||||||
|
* Tags that can be used include: ip, gateway, netmask, dns1, dns2. All access points have to be
|
||||||
* enclosed in tags of <resources></resources>.
|
* enclosed in tags of <resources></resources>.
|
||||||
*
|
*
|
||||||
* The following is a sample configuration file for an access point using EAP-PEAP with MSCHAP2.
|
* The following is a sample configuration file for an access point using EAP-PEAP with MSCHAP2.
|
||||||
@@ -62,6 +65,7 @@ public class AccessPointParserHelper {
|
|||||||
static final int EAP = 3;
|
static final int EAP = 3;
|
||||||
|
|
||||||
List<WifiConfiguration> networks = new ArrayList<WifiConfiguration>();
|
List<WifiConfiguration> networks = new ArrayList<WifiConfiguration>();
|
||||||
|
HashMap<String, DhcpInfo> ssidToDhcpInfoHM = new HashMap<String, DhcpInfo>();
|
||||||
|
|
||||||
private int getSecurityType (String security) {
|
private int getSecurityType (String security) {
|
||||||
if (security.equalsIgnoreCase("NONE")) {
|
if (security.equalsIgnoreCase("NONE")) {
|
||||||
@@ -87,15 +91,34 @@ public class AccessPointParserHelper {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private static int stringToIpAddr(String addrString) throws UnknownHostException {
|
||||||
|
try {
|
||||||
|
String[] parts = addrString.split("\\.");
|
||||||
|
if (parts.length != 4) {
|
||||||
|
throw new UnknownHostException(addrString);
|
||||||
|
}
|
||||||
|
|
||||||
|
int a = Integer.parseInt(parts[0]) ;
|
||||||
|
int b = Integer.parseInt(parts[1]) << 8;
|
||||||
|
int c = Integer.parseInt(parts[2]) << 16;
|
||||||
|
int d = Integer.parseInt(parts[3]) << 24;
|
||||||
|
|
||||||
|
return a | b | c | d;
|
||||||
|
} catch (NumberFormatException ex) {
|
||||||
|
throw new UnknownHostException(addrString);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
DefaultHandler mHandler = new DefaultHandler() {
|
DefaultHandler mHandler = new DefaultHandler() {
|
||||||
|
|
||||||
boolean ssid = false;
|
boolean ssid = false;
|
||||||
boolean security = false;
|
boolean security = false;
|
||||||
boolean password = false;
|
boolean password = false;
|
||||||
boolean ip = false;
|
boolean ip = false;
|
||||||
boolean subnetmask = false;
|
boolean netmask = false;
|
||||||
boolean gateway = false;
|
boolean gateway = false;
|
||||||
boolean dns = false;
|
boolean dns1 = false;
|
||||||
|
boolean dns2 = false;
|
||||||
boolean eap = false;
|
boolean eap = false;
|
||||||
boolean phase2 = false;
|
boolean phase2 = false;
|
||||||
boolean identity = false;
|
boolean identity = false;
|
||||||
@@ -104,6 +127,7 @@ public class AccessPointParserHelper {
|
|||||||
boolean usercert = false;
|
boolean usercert = false;
|
||||||
WifiConfiguration config = null;
|
WifiConfiguration config = null;
|
||||||
int securityType = NONE;
|
int securityType = NONE;
|
||||||
|
DhcpInfo mDhcpInfo = null;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void startElement(String uri, String localName, String tagName,
|
public void startElement(String uri, String localName, String tagName,
|
||||||
@@ -138,13 +162,31 @@ public class AccessPointParserHelper {
|
|||||||
if (tagName.equalsIgnoreCase("usercert")) {
|
if (tagName.equalsIgnoreCase("usercert")) {
|
||||||
usercert = true;
|
usercert = true;
|
||||||
}
|
}
|
||||||
|
if (tagName.equalsIgnoreCase("ip")) {
|
||||||
|
ip = true;
|
||||||
|
mDhcpInfo = new DhcpInfo();
|
||||||
|
}
|
||||||
|
if (tagName.equalsIgnoreCase("gateway")) {
|
||||||
|
gateway = true;
|
||||||
|
}
|
||||||
|
if (tagName.equalsIgnoreCase("netmask")) {
|
||||||
|
netmask = true;
|
||||||
|
}
|
||||||
|
if (tagName.equalsIgnoreCase("dns1")) {
|
||||||
|
dns1 = true;
|
||||||
|
}
|
||||||
|
if (tagName.equalsIgnoreCase("dns2")) {
|
||||||
|
dns2 = true;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void endElement(String uri, String localName, String tagName) throws SAXException {
|
public void endElement(String uri, String localName, String tagName) throws SAXException {
|
||||||
Log.v(TAG, "endElement: " + tagName);
|
|
||||||
if (tagName.equalsIgnoreCase("accesspoint")) {
|
if (tagName.equalsIgnoreCase("accesspoint")) {
|
||||||
networks.add(config);
|
networks.add(config);
|
||||||
|
if (mDhcpInfo != null) {
|
||||||
|
ssidToDhcpInfoHM.put(config.SSID, mDhcpInfo);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -152,14 +194,11 @@ public class AccessPointParserHelper {
|
|||||||
public void characters(char ch[], int start, int length) throws SAXException {
|
public void characters(char ch[], int start, int length) throws SAXException {
|
||||||
if (ssid) {
|
if (ssid) {
|
||||||
config.SSID = new String(ch, start, length);
|
config.SSID = new String(ch, start, length);
|
||||||
Log.v(TAG, "ssid: " + config.SSID);
|
|
||||||
ssid = false;
|
ssid = false;
|
||||||
}
|
}
|
||||||
if (security) {
|
if (security) {
|
||||||
String securityStr = (new String(ch, start, length)).toUpperCase();
|
String securityStr = (new String(ch, start, length)).toUpperCase();
|
||||||
Log.v(TAG, "security: " + securityStr);
|
|
||||||
securityType = getSecurityType(securityStr);
|
securityType = getSecurityType(securityStr);
|
||||||
Log.v(TAG, "securityType = " + securityType);
|
|
||||||
switch (securityType) {
|
switch (securityType) {
|
||||||
case NONE:
|
case NONE:
|
||||||
config.allowedKeyManagement.set(KeyMgmt.NONE);
|
config.allowedKeyManagement.set(KeyMgmt.NONE);
|
||||||
@@ -187,7 +226,6 @@ public class AccessPointParserHelper {
|
|||||||
if (len == 0) {
|
if (len == 0) {
|
||||||
throw new SAXException();
|
throw new SAXException();
|
||||||
}
|
}
|
||||||
Log.v(TAG, "passwordStr:" + passwordStr);
|
|
||||||
if (securityType == WEP) {
|
if (securityType == WEP) {
|
||||||
if ((len == 10 || len == 26 || len == 58) &&
|
if ((len == 10 || len == 26 || len == 58) &&
|
||||||
passwordStr.matches("[0-9A-Fa-f]*")) {
|
passwordStr.matches("[0-9A-Fa-f]*")) {
|
||||||
@@ -242,21 +280,65 @@ public class AccessPointParserHelper {
|
|||||||
config.client_cert.setValue(KEYSTORE_SPACE);
|
config.client_cert.setValue(KEYSTORE_SPACE);
|
||||||
usercert = false;
|
usercert = false;
|
||||||
}
|
}
|
||||||
|
if (ip) {
|
||||||
|
try {
|
||||||
|
mDhcpInfo.ipAddress = stringToIpAddr(new String(ch, start, length));
|
||||||
|
} catch (UnknownHostException e) {
|
||||||
|
throw new SAXException();
|
||||||
|
}
|
||||||
|
ip = false;
|
||||||
|
}
|
||||||
|
if (gateway) {
|
||||||
|
try {
|
||||||
|
mDhcpInfo.gateway = stringToIpAddr(new String(ch, start, length));
|
||||||
|
} catch (UnknownHostException e) {
|
||||||
|
throw new SAXException();
|
||||||
|
}
|
||||||
|
gateway = false;
|
||||||
|
}
|
||||||
|
if (netmask) {
|
||||||
|
try {
|
||||||
|
mDhcpInfo.netmask = stringToIpAddr(new String(ch, start, length));
|
||||||
|
} catch (UnknownHostException e) {
|
||||||
|
throw new SAXException();
|
||||||
|
}
|
||||||
|
netmask = false;
|
||||||
|
}
|
||||||
|
if (dns1) {
|
||||||
|
try {
|
||||||
|
mDhcpInfo.dns1 = stringToIpAddr(new String(ch, start, length));
|
||||||
|
} catch (UnknownHostException e) {
|
||||||
|
throw new SAXException();
|
||||||
|
}
|
||||||
|
dns1 = false;
|
||||||
|
}
|
||||||
|
if (dns2) {
|
||||||
|
try {
|
||||||
|
mDhcpInfo.dns2 = stringToIpAddr(new String(ch, start, length));
|
||||||
|
} catch (UnknownHostException e) {
|
||||||
|
throw new SAXException();
|
||||||
|
}
|
||||||
|
dns2 = false;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
public AccessPointParserHelper() {
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Process the accesspoint.xml file
|
* Process the InputStream in
|
||||||
* @return List of WifiConfiguration
|
* @param in is the InputStream that can be used for XML parsing
|
||||||
* @throws Exception when parsing the XML file
|
* @throws Exception
|
||||||
*/
|
*/
|
||||||
public List<WifiConfiguration> processAccessPoint(InputStream in) throws Exception {
|
public AccessPointParserHelper(InputStream in) throws Exception {
|
||||||
SAXParserFactory factory = SAXParserFactory.newInstance();
|
SAXParserFactory factory = SAXParserFactory.newInstance();
|
||||||
SAXParser saxParser = factory.newSAXParser();
|
SAXParser saxParser = factory.newSAXParser();
|
||||||
saxParser.parse(in, mHandler);
|
saxParser.parse(in, mHandler);
|
||||||
|
}
|
||||||
|
|
||||||
|
public List<WifiConfiguration> getNetworkConfigurations() throws Exception {
|
||||||
return networks;
|
return networks;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public HashMap<String, DhcpInfo> getSsidToDhcpInfoHashMap() {
|
||||||
|
return ssidToDhcpInfoHM;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -30,9 +30,11 @@ import android.view.KeyEvent;
|
|||||||
|
|
||||||
import java.io.InputStream;
|
import java.io.InputStream;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
|
import java.util.HashMap;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import android.widget.LinearLayout;
|
import android.widget.LinearLayout;
|
||||||
import android.net.ConnectivityManager;
|
import android.net.ConnectivityManager;
|
||||||
|
import android.net.DhcpInfo;
|
||||||
import android.net.NetworkInfo;
|
import android.net.NetworkInfo;
|
||||||
import android.net.NetworkInfo.State;
|
import android.net.NetworkInfo.State;
|
||||||
|
|
||||||
@@ -61,6 +63,7 @@ public class ConnectivityManagerTestActivity extends Activity {
|
|||||||
private static final String ACCESS_POINT_FILE = "accesspoints.xml";
|
private static final String ACCESS_POINT_FILE = "accesspoints.xml";
|
||||||
public ConnectivityReceiver mConnectivityReceiver = null;
|
public ConnectivityReceiver mConnectivityReceiver = null;
|
||||||
public WifiReceiver mWifiReceiver = null;
|
public WifiReceiver mWifiReceiver = null;
|
||||||
|
private AccessPointParserHelper mParseHelper = null;
|
||||||
/*
|
/*
|
||||||
* Track network connectivity information
|
* Track network connectivity information
|
||||||
*/
|
*/
|
||||||
@@ -156,6 +159,7 @@ public class ConnectivityManagerTestActivity extends Activity {
|
|||||||
} else if (action.equals(WifiManager.WIFI_STATE_CHANGED_ACTION)) {
|
} else if (action.equals(WifiManager.WIFI_STATE_CHANGED_ACTION)) {
|
||||||
mWifiState = intent.getIntExtra(WifiManager.EXTRA_WIFI_STATE,
|
mWifiState = intent.getIntExtra(WifiManager.EXTRA_WIFI_STATE,
|
||||||
WifiManager.WIFI_STATE_UNKNOWN);
|
WifiManager.WIFI_STATE_UNKNOWN);
|
||||||
|
Log.v(LOG_TAG, "mWifiState: " + mWifiState);
|
||||||
notifyWifiState();
|
notifyWifiState();
|
||||||
} else if (action.equals(WifiManager.WIFI_AP_STATE_CHANGED_ACTION)) {
|
} else if (action.equals(WifiManager.WIFI_AP_STATE_CHANGED_ACTION)) {
|
||||||
notifyWifiAPState();
|
notifyWifiAPState();
|
||||||
@@ -220,10 +224,19 @@ public class ConnectivityManagerTestActivity extends Activity {
|
|||||||
|
|
||||||
public List<WifiConfiguration> loadNetworkConfigurations() throws Exception {
|
public List<WifiConfiguration> loadNetworkConfigurations() throws Exception {
|
||||||
InputStream in = getAssets().open(ACCESS_POINT_FILE);
|
InputStream in = getAssets().open(ACCESS_POINT_FILE);
|
||||||
AccessPointParserHelper parseHelper = new AccessPointParserHelper();
|
mParseHelper = new AccessPointParserHelper(in);
|
||||||
return parseHelper.processAccessPoint(in);
|
return mParseHelper.getNetworkConfigurations();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public HashMap<String, DhcpInfo> getDhcpInfo() throws Exception{
|
||||||
|
if (mParseHelper == null) {
|
||||||
|
InputStream in = getAssets().open(ACCESS_POINT_FILE);
|
||||||
|
mParseHelper = new AccessPointParserHelper(in);
|
||||||
|
}
|
||||||
|
return mParseHelper.getSsidToDhcpInfoHashMap();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
private void printNetConfig(String[] configuration) {
|
private void printNetConfig(String[] configuration) {
|
||||||
for (int i = 0; i < configuration.length; i++) {
|
for (int i = 0; i < configuration.length; i++) {
|
||||||
if (i == 0) {
|
if (i == 0) {
|
||||||
@@ -388,7 +401,7 @@ public class ConnectivityManagerTestActivity extends Activity {
|
|||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
if (mWifiState != expectedState) {
|
if (mWifiState != expectedState) {
|
||||||
Log.v(LOG_TAG, "Wifi state is: " + mWifiNetworkInfo.getState());
|
Log.v(LOG_TAG, "Wifi state is: " + mWifiState);
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
|
|||||||
@@ -16,11 +16,14 @@
|
|||||||
|
|
||||||
package com.android.connectivitymanagertest.functional;
|
package com.android.connectivitymanagertest.functional;
|
||||||
|
|
||||||
|
import com.android.connectivitymanagertest.ConnectivityManagerStressTestRunner;
|
||||||
import com.android.connectivitymanagertest.ConnectivityManagerTestActivity;
|
import com.android.connectivitymanagertest.ConnectivityManagerTestActivity;
|
||||||
|
import com.android.connectivitymanagertest.ConnectivityManagerTestRunner;
|
||||||
import com.android.connectivitymanagertest.NetworkState;
|
import com.android.connectivitymanagertest.NetworkState;
|
||||||
|
|
||||||
import android.R;
|
import android.R;
|
||||||
import android.app.Activity;
|
import android.app.Activity;
|
||||||
|
import android.content.ContentResolver;
|
||||||
import android.content.Intent;
|
import android.content.Intent;
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.content.res.Resources;
|
import android.content.res.Resources;
|
||||||
@@ -28,15 +31,20 @@ import android.net.wifi.WifiConfiguration;
|
|||||||
import android.net.wifi.WifiInfo;
|
import android.net.wifi.WifiInfo;
|
||||||
import android.net.wifi.WifiManager;
|
import android.net.wifi.WifiManager;
|
||||||
import android.net.ConnectivityManager;
|
import android.net.ConnectivityManager;
|
||||||
|
import android.net.DhcpInfo;
|
||||||
import android.net.NetworkInfo;
|
import android.net.NetworkInfo;
|
||||||
import android.net.NetworkInfo.State;
|
import android.net.NetworkInfo.State;
|
||||||
|
import android.provider.Settings;
|
||||||
|
|
||||||
import android.test.suitebuilder.annotation.LargeTest;
|
import android.test.suitebuilder.annotation.LargeTest;
|
||||||
import android.test.ActivityInstrumentationTestCase2;
|
import android.test.ActivityInstrumentationTestCase2;
|
||||||
import android.util.Log;
|
import android.util.Log;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
|
import java.util.HashMap;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import java.util.Map.Entry;
|
||||||
|
import java.util.Set;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Test Wi-Fi connection with different configuration
|
* Test Wi-Fi connection with different configuration
|
||||||
@@ -52,18 +60,25 @@ public class WifiConnectionTest
|
|||||||
private static final String PKG_NAME = "com.android.connectivitymanagertests";
|
private static final String PKG_NAME = "com.android.connectivitymanagertests";
|
||||||
private List<WifiConfiguration> networks = new ArrayList<WifiConfiguration>();
|
private List<WifiConfiguration> networks = new ArrayList<WifiConfiguration>();
|
||||||
private ConnectivityManagerTestActivity mAct;
|
private ConnectivityManagerTestActivity mAct;
|
||||||
|
private HashMap<String, DhcpInfo> hm = null;
|
||||||
|
private ConnectivityManagerTestRunner mRunner;
|
||||||
|
private ContentResolver cr;
|
||||||
|
|
||||||
public WifiConnectionTest() {
|
public WifiConnectionTest() {
|
||||||
super(PKG_NAME, ConnectivityManagerTestActivity.class);
|
super(ConnectivityManagerTestActivity.class);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void setUp() throws Exception {
|
public void setUp() throws Exception {
|
||||||
super.setUp();
|
super.setUp();
|
||||||
mAct = getActivity();
|
mAct = getActivity();
|
||||||
|
mRunner = ((ConnectivityManagerTestRunner)getInstrumentation());
|
||||||
|
cr = mRunner.getContext().getContentResolver();
|
||||||
networks = mAct.loadNetworkConfigurations();
|
networks = mAct.loadNetworkConfigurations();
|
||||||
|
hm = mAct.getDhcpInfo();
|
||||||
if (DEBUG) {
|
if (DEBUG) {
|
||||||
printNetworkConfigurations();
|
printNetworkConfigurations();
|
||||||
|
printDhcpInfo();
|
||||||
}
|
}
|
||||||
|
|
||||||
// enable Wifi and verify wpa_supplicant is started
|
// enable Wifi and verify wpa_supplicant is started
|
||||||
@@ -86,12 +101,36 @@ public class WifiConnectionTest
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void printDhcpInfo() {
|
||||||
|
if (hm == null) {
|
||||||
|
return;
|
||||||
|
} else {
|
||||||
|
Set<Entry<String, DhcpInfo>> set = hm.entrySet();
|
||||||
|
for (Entry<String, DhcpInfo> me: set) {
|
||||||
|
Log.v(TAG, "SSID: " + me.getKey());
|
||||||
|
DhcpInfo dhcp = me.getValue();
|
||||||
|
Log.v(TAG, " dhcp: " + dhcp.toString());
|
||||||
|
Log.v(TAG, "IP: " + intToIpString(dhcp.ipAddress));
|
||||||
|
Log.v(TAG, "gateway: " + intToIpString(dhcp.gateway));
|
||||||
|
Log.v(TAG, "Netmask: " + intToIpString(dhcp.netmask));
|
||||||
|
Log.v(TAG, "DNS1: " + intToIpString(dhcp.dns1));
|
||||||
|
Log.v(TAG, "DNS2: " + intToIpString(dhcp.dns2));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void tearDown() throws Exception {
|
public void tearDown() throws Exception {
|
||||||
mAct.removeConfiguredNetworksAndDisableWifi();
|
mAct.removeConfiguredNetworksAndDisableWifi();
|
||||||
super.tearDown();
|
super.tearDown();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private String intToIpString(int i) {
|
||||||
|
return ((i & 0xFF) + "." +
|
||||||
|
((i >> 8) & 0xFF) + "." +
|
||||||
|
((i >> 16) & 0xFF) + "." +
|
||||||
|
((i >> 24) & 0xFF));
|
||||||
|
}
|
||||||
/**
|
/**
|
||||||
* Connect to the provided Wi-Fi network
|
* Connect to the provided Wi-Fi network
|
||||||
* @param config is the network configuration
|
* @param config is the network configuration
|
||||||
@@ -99,6 +138,26 @@ public class WifiConnectionTest
|
|||||||
*/
|
*/
|
||||||
private void connectToWifi(WifiConfiguration config) {
|
private void connectToWifi(WifiConfiguration config) {
|
||||||
// step 1: connect to the test access point
|
// step 1: connect to the test access point
|
||||||
|
boolean isStaticIP = false;
|
||||||
|
if (hm.containsKey(config.SSID)) {
|
||||||
|
DhcpInfo dhcpInfo = hm.get(config.SSID);
|
||||||
|
if (dhcpInfo != null) {
|
||||||
|
isStaticIP = true;
|
||||||
|
// set the system settings:
|
||||||
|
Settings.System.putInt(cr,Settings.System.WIFI_USE_STATIC_IP, 1);
|
||||||
|
Settings.System.putString(cr, Settings.System.WIFI_STATIC_IP,
|
||||||
|
intToIpString(dhcpInfo.ipAddress));
|
||||||
|
Settings.System.putString(cr, Settings.System.WIFI_STATIC_GATEWAY,
|
||||||
|
intToIpString(dhcpInfo.gateway));
|
||||||
|
Settings.System.putString(cr, Settings.System.WIFI_STATIC_NETMASK,
|
||||||
|
intToIpString(dhcpInfo.netmask));
|
||||||
|
Settings.System.putString(cr, Settings.System.WIFI_STATIC_DNS1,
|
||||||
|
intToIpString(dhcpInfo.dns1));
|
||||||
|
Settings.System.putString(cr, Settings.System.WIFI_STATIC_DNS2,
|
||||||
|
intToIpString(dhcpInfo.dns2));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
assertTrue("failed to connect to " + config.SSID,
|
assertTrue("failed to connect to " + config.SSID,
|
||||||
mAct.connectToWifiWithConfiguration(config));
|
mAct.connectToWifiWithConfiguration(config));
|
||||||
|
|
||||||
@@ -118,17 +177,29 @@ public class WifiConnectionTest
|
|||||||
|
|
||||||
// Maintain the connection for 50 seconds before switching
|
// Maintain the connection for 50 seconds before switching
|
||||||
try {
|
try {
|
||||||
Thread.sleep(50*1000);
|
Thread.sleep(mAct.LONG_TIMEOUT);
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
fail("interrupted while waiting for WPA_SUPPLICANT to start");
|
fail("interrupted while waiting for WPA_SUPPLICANT to start");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (isStaticIP) {
|
||||||
|
Settings.System.putInt(cr, Settings.System.WIFI_USE_STATIC_IP, 0);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@LargeTest
|
@LargeTest
|
||||||
public void testWifiConnections() {
|
public void testWifiConnections() {
|
||||||
for (int i = 0; i < networks.size(); i++) {
|
for (int i = 0; i < networks.size(); i++) {
|
||||||
|
String ssid = networks.get(i).SSID;
|
||||||
|
Log.v(TAG, "-- start Wi-Fi connection test for SSID: " + ssid + " --");
|
||||||
connectToWifi(networks.get(i));
|
connectToWifi(networks.get(i));
|
||||||
mAct.removeConfiguredNetworksAndDisableWifi();
|
mAct.removeConfiguredNetworksAndDisableWifi();
|
||||||
|
try {
|
||||||
|
Thread.sleep(4 * mAct.SHORT_TIMEOUT);
|
||||||
|
} catch (Exception e) {
|
||||||
|
fail("Interrupted while disabling wifi");
|
||||||
|
}
|
||||||
|
Log.v(TAG, "-- END Wi-Fi connection test for SSID: " + ssid + " --");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user