use of android.net.wifi.WifiConfiguration in project platform_frameworks_base by android.
the class WifiConfigurationHelper method createPskConfig.
/**
* Create a {@link WifiConfiguration} for a PSK secured network
*
* @param ssid The SSID of the wifi network
* @param password Either a 64 character hex string or the plain text password
* @return The {@link WifiConfiguration}
*/
public static WifiConfiguration createPskConfig(String ssid, String password) {
WifiConfiguration config = createGenericConfig(ssid);
if (isHex(password, 64)) {
config.preSharedKey = password;
} else {
config.preSharedKey = quotedString(password);
}
config.allowedKeyManagement.set(KeyMgmt.WPA_PSK);
return config;
}
use of android.net.wifi.WifiConfiguration in project platform_frameworks_base by android.
the class WifiAssociationTest method testWifiAssociation.
/**
* Test that the wifi can associate with a given access point.
*/
@LargeTest
public void testWifiAssociation() {
WifiAssociationTestRunner runner = (WifiAssociationTestRunner) getInstrumentation();
Bundle arguments = runner.getArguments();
String ssid = arguments.getString("ssid");
assertNotNull("ssid is empty", ssid);
String securityTypeStr = arguments.getString("security-type");
assertNotNull("security-type is empty", securityTypeStr);
SecurityType securityType = SecurityType.valueOf(securityTypeStr);
String password = arguments.getString("password");
assertTrue("enable Wifi failed", enableWifi());
WifiInfo wi = mWifiManager.getConnectionInfo();
logv("%s", wi);
assertNotNull("no active wifi info", wi);
WifiConfiguration config = getConfig(ssid, securityType, password);
logv("Network config: %s", config.toString());
connectToWifi(config);
}
use of android.net.wifi.WifiConfiguration in project platform_frameworks_base by android.
the class WifiAssociationTest method getConfig.
/**
* Get the {@link WifiConfiguration} based on ssid, security, and password.
*/
private WifiConfiguration getConfig(String ssid, SecurityType securityType, String password) {
logv("Security type is %s", securityType.toString());
WifiConfiguration config = null;
switch(securityType) {
case OPEN:
config = WifiConfigurationHelper.createOpenConfig(ssid);
break;
case WEP64:
assertNotNull("password is empty", password);
// always use hex pair for WEP-40
assertTrue(WifiConfigurationHelper.isHex(password, 10));
config = WifiConfigurationHelper.createWepConfig(ssid, password);
config.allowedGroupCiphers.set(GroupCipher.WEP40);
break;
case WEP128:
assertNotNull("password is empty", password);
// always use hex pair for WEP-104
assertTrue(WifiConfigurationHelper.isHex(password, 26));
config = WifiConfigurationHelper.createWepConfig(ssid, password);
config.allowedGroupCiphers.set(GroupCipher.WEP104);
break;
case WPA_TKIP:
assertNotNull("password is empty", password);
config = WifiConfigurationHelper.createPskConfig(ssid, password);
config.allowedAuthAlgorithms.set(AuthAlgorithm.OPEN);
config.allowedProtocols.set(Protocol.WPA);
config.allowedPairwiseCiphers.set(PairwiseCipher.TKIP);
config.allowedGroupCiphers.set(GroupCipher.TKIP);
break;
case WPA2_AES:
assertNotNull("password is empty", password);
config = WifiConfigurationHelper.createPskConfig(ssid, password);
config.allowedAuthAlgorithms.set(AuthAlgorithm.OPEN);
config.allowedProtocols.set(Protocol.RSN);
config.allowedPairwiseCiphers.set(PairwiseCipher.CCMP);
config.allowedGroupCiphers.set(GroupCipher.CCMP);
break;
default:
fail("Not a valid security type: " + securityType);
break;
}
return config;
}
use of android.net.wifi.WifiConfiguration in project platform_frameworks_base by android.
the class WifiClientTest method testEnableDisableNetwork.
// Test case 2: enable/disable a open network
@LargeTest
public void testEnableDisableNetwork() {
WifiConfiguration config = new WifiConfiguration();
config.SSID = "\"TestSSID2\"";
config.allowedKeyManagement.set(KeyMgmt.NONE);
//add
int netId = mWifiManager.addNetwork(config);
assertTrue(netId != -1);
//enable network and disable others
boolean ret = mWifiManager.enableNetwork(netId, true);
assertTrue(ret);
//check config list
List<WifiConfiguration> configList = mWifiManager.getConfiguredNetworks();
for (WifiConfiguration c : configList) {
if (c.networkId == netId) {
assertTrue(c.status == Status.ENABLED);
} else {
assertFalse(c.status == Status.ENABLED);
}
}
//disable network
ret = mWifiManager.disableNetwork(netId);
assertTrue(ret);
//check config list
configList = mWifiManager.getConfiguredNetworks();
for (WifiConfiguration c : configList) {
if (c.networkId == netId) {
assertTrue(c.status == Status.DISABLED);
}
}
}
use of android.net.wifi.WifiConfiguration in project platform_frameworks_base by android.
the class ConnectivityManagerTestBase method disconnectAP.
/*
* Disconnect from the current AP and remove configured networks.
*/
protected boolean disconnectAP() {
// remove saved networks
if (!mWifiManager.isWifiEnabled()) {
logv("Enabled wifi before remove configured networks");
mWifiManager.setWifiEnabled(true);
SystemClock.sleep(SHORT_TIMEOUT);
}
List<WifiConfiguration> wifiConfigList = mWifiManager.getConfiguredNetworks();
if (wifiConfigList == null) {
logv("no configuration list is null");
return true;
}
logv("size of wifiConfigList: " + wifiConfigList.size());
for (WifiConfiguration wifiConfig : wifiConfigList) {
logv("remove wifi configuration: " + wifiConfig.networkId);
int netId = wifiConfig.networkId;
mWifiManager.forget(netId, new WifiManager.ActionListener() {
@Override
public void onSuccess() {
}
@Override
public void onFailure(int reason) {
logv("Failed to forget " + reason);
}
});
}
return true;
}
Aggregations