use of android.net.wifi.WifiConfiguration in project android_frameworks_base by DirtyUnicorns.
the class WifiClientTest method testWifiConfiguredNetworkStatus.
// Test case 6: test configured network status
@LargeTest
public void testWifiConfiguredNetworkStatus() {
/* Initialize */
mWifiManager.setWifiEnabled(false);
sleepAfterWifiEnable();
/* Ensure no network is CURRENT */
List<WifiConfiguration> configList = mWifiManager.getConfiguredNetworks();
for (WifiConfiguration c : configList) {
assertTrue(c.status != WifiConfiguration.Status.CURRENT);
}
/* Enable wifi */
mWifiManager.setWifiEnabled(true);
sleepAfterWifiEnable();
/* Ensure connected network is CURRENT */
String connectedSSID = mWifiManager.getConnectionInfo().getSSID();
configList = mWifiManager.getConfiguredNetworks();
for (WifiConfiguration c : configList) {
if (c.SSID.contains(connectedSSID)) {
assertTrue(c.status == WifiConfiguration.Status.CURRENT);
} else {
assertTrue(c.status != WifiConfiguration.Status.CURRENT);
}
}
/* Disable wifi */
mWifiManager.setWifiEnabled(false);
sleepAfterWifiEnable();
/* Ensure no network is CURRENT */
configList = mWifiManager.getConfiguredNetworks();
for (WifiConfiguration c : configList) {
assertTrue(c.status != WifiConfiguration.Status.CURRENT);
}
}
use of android.net.wifi.WifiConfiguration in project android_frameworks_base by DirtyUnicorns.
the class OSUManager method setOSUSelection.
public void setOSUSelection(int osuID) {
OSUInfo selection = null;
for (OSUInfo osuInfo : mOSUMap.values()) {
Log.d("ZXZ", "In select: " + osuInfo + ", id " + osuInfo.getOsuID());
if (osuInfo.getOsuID() == osuID && osuInfo.getIconStatus() == OSUInfo.IconStatus.Available) {
selection = osuInfo;
break;
}
}
Log.d(TAG, "Selected OSU ID " + osuID + ", matches " + selection);
if (selection == null) {
mPendingOSU = null;
return;
}
mPendingOSU = selection;
WifiConfiguration config = mWifiNetworkAdapter.getActiveWifiConfig();
if (config != null && bssidMatch(selection) && Utils.unquote(config.SSID).equals(selection.getSSID())) {
try {
// Go straight to provisioning if the network is already selected.
// Also note that mOSUNwkID is left unset to leave the network around after
// flow completion since it was not added by the OSU flow.
initiateProvisioning(mPendingOSU, mWifiNetworkAdapter.getCurrentNetwork());
} catch (IOException ioe) {
notifyUser(OSUOperationStatus.ProvisioningFailure, ioe.getMessage(), mPendingOSU.getName(LOCALE));
} finally {
mPendingOSU = null;
}
} else {
try {
mOSUNwkID = mWifiNetworkAdapter.connect(selection, mPendingOSU.getName(LOCALE));
} catch (IOException ioe) {
notifyUser(OSUOperationStatus.ProvisioningFailure, ioe.getMessage(), selection.getName(LOCALE));
}
}
}
use of android.net.wifi.WifiConfiguration in project android_frameworks_base by DirtyUnicorns.
the class ConfigBuilder method buildTTLSConfig.
// Retain for debugging purposes
/*
private static void xIterateCerts(KeyStore ks, X509Certificate caCert)
throws GeneralSecurityException {
Enumeration<String> aliases = ks.aliases();
while (aliases.hasMoreElements()) {
String alias = aliases.nextElement();
Certificate cert = ks.getCertificate(alias);
Log.d("HS2J", "Checking " + alias);
if (cert instanceof X509Certificate) {
X509Certificate x509Certificate = (X509Certificate) cert;
boolean sm = x509Certificate.getSubjectX500Principal().equals(
caCert.getSubjectX500Principal());
boolean eq = false;
if (sm) {
eq = Arrays.equals(x509Certificate.getEncoded(), caCert.getEncoded());
}
Log.d("HS2J", "Subject: " + x509Certificate.getSubjectX500Principal() +
": " + sm + "/" + eq);
}
}
}
*/
private static WifiConfiguration buildTTLSConfig(HomeSP homeSP) throws IOException {
Credential credential = homeSP.getCredential();
if (credential.getUserName() == null || credential.getPassword() == null) {
throw new IOException("EAP-TTLS provisioned without user name or password");
}
EAPMethod eapMethod = credential.getEAPMethod();
AuthParam authParam = eapMethod.getAuthParam();
if (authParam == null || authParam.getAuthInfoID() != EAP.AuthInfoID.NonEAPInnerAuthType) {
throw new IOException("Bad auth parameter for EAP-TTLS: " + authParam);
}
WifiConfiguration config = buildBaseConfiguration(homeSP);
NonEAPInnerAuth ttlsParam = (NonEAPInnerAuth) authParam;
WifiEnterpriseConfig enterpriseConfig = config.enterpriseConfig;
enterpriseConfig.setPhase2Method(remapInnerMethod(ttlsParam.getType()));
enterpriseConfig.setIdentity(credential.getUserName());
enterpriseConfig.setPassword(credential.getPassword());
return config;
}
use of android.net.wifi.WifiConfiguration in project android_frameworks_base by DirtyUnicorns.
the class ConfigBuilder method buildConfig.
public static WifiConfiguration buildConfig(HomeSP homeSP, X509Certificate caCert, List<X509Certificate> clientChain, PrivateKey key) throws IOException, GeneralSecurityException {
Credential credential = homeSP.getCredential();
WifiConfiguration config;
EAP.EAPMethodID eapMethodID = credential.getEAPMethod().getEAPMethodID();
switch(eapMethodID) {
case EAP_TTLS:
if (key != null || clientChain != null) {
Log.w(TAG, "Client cert and/or key included with EAP-TTLS profile");
}
config = buildTTLSConfig(homeSP);
break;
case EAP_TLS:
config = buildTLSConfig(homeSP, clientChain, key);
break;
case EAP_AKA:
case EAP_AKAPrim:
case EAP_SIM:
if (key != null || clientChain != null || caCert != null) {
Log.i(TAG, "Client/CA cert and/or key included with " + eapMethodID + " profile");
}
config = buildSIMConfig(homeSP);
break;
default:
throw new IOException("Unsupported EAP Method: " + eapMethodID);
}
WifiEnterpriseConfig enterpriseConfig = config.enterpriseConfig;
enterpriseConfig.setCaCertificate(caCert);
enterpriseConfig.setAnonymousIdentity("anonymous@" + credential.getRealm());
return config;
}
use of android.net.wifi.WifiConfiguration in project android_frameworks_base by DirtyUnicorns.
the class WifiNetworkAdapter method addNetwork.
public Integer addNetwork(HomeSP homeSP, Map<OSUCertType, List<X509Certificate>> certs, PrivateKey privateKey, Network osuNetwork) throws IOException, GeneralSecurityException {
List<X509Certificate> aaaTrust = certs.get(OSUCertType.AAA);
if (aaaTrust.isEmpty()) {
// Get the CAs from the EST flow.
aaaTrust = certs.get(OSUCertType.CA);
}
WifiConfiguration config = ConfigBuilder.buildConfig(homeSP, aaaTrust.iterator().next(), certs.get(OSUCertType.Client), privateKey);
WifiManager wifiManager = (WifiManager) mContext.getSystemService(Context.WIFI_SERVICE);
int nwkId = wifiManager.addNetwork(config);
boolean saved = false;
if (nwkId >= 0) {
saved = wifiManager.saveConfiguration();
}
Log.d(OSUManager.TAG, "Wifi configuration " + nwkId + " " + (saved ? "saved" : "not saved"));
if (saved) {
reconnect(osuNetwork, nwkId);
return nwkId;
} else {
return null;
}
}
Aggregations