Search in sources :

Example 51 with WifiConfiguration

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);
    }
}
Also used : WifiConfiguration(android.net.wifi.WifiConfiguration) LargeTest(android.test.suitebuilder.annotation.LargeTest)

Example 52 with WifiConfiguration

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));
        }
    }
}
Also used : WifiConfiguration(android.net.wifi.WifiConfiguration) IOException(java.io.IOException)

Example 53 with WifiConfiguration

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;
}
Also used : WifiEnterpriseConfig(android.net.wifi.WifiEnterpriseConfig) Credential(com.android.hotspot2.pps.Credential) WifiConfiguration(android.net.wifi.WifiConfiguration) IOException(java.io.IOException) AuthParam(com.android.anqp.eap.AuthParam) EAPMethod(com.android.anqp.eap.EAPMethod) NonEAPInnerAuth(com.android.anqp.eap.NonEAPInnerAuth)

Example 54 with WifiConfiguration

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;
}
Also used : WifiEnterpriseConfig(android.net.wifi.WifiEnterpriseConfig) Credential(com.android.hotspot2.pps.Credential) WifiConfiguration(android.net.wifi.WifiConfiguration) EAP(com.android.anqp.eap.EAP) IOException(java.io.IOException)

Example 55 with WifiConfiguration

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;
    }
}
Also used : WifiManager(android.net.wifi.WifiManager) WifiConfiguration(android.net.wifi.WifiConfiguration) X509Certificate(java.security.cert.X509Certificate)

Aggregations

WifiConfiguration (android.net.wifi.WifiConfiguration)569 WifiManager (android.net.wifi.WifiManager)88 LargeTest (android.test.suitebuilder.annotation.LargeTest)53 IOException (java.io.IOException)48 ArrayList (java.util.ArrayList)47 AccessPoint (com.android.settingslib.wifi.AccessPoint)46 Test (org.junit.Test)45 WifiEnterpriseConfig (android.net.wifi.WifiEnterpriseConfig)40 WifiInfo (android.net.wifi.WifiInfo)36 ScanResult (android.net.wifi.ScanResult)27 NetworkInfo (android.net.NetworkInfo)22 StaticIpConfiguration (android.net.StaticIpConfiguration)20 Credential (com.android.hotspot2.pps.Credential)20 Scanner (com.android.settingslib.wifi.WifiTracker.Scanner)20 Intent (android.content.Intent)19 Bundle (android.os.Bundle)19 ValidatedEditTextPreference (com.android.settings.widget.ValidatedEditTextPreference)16 Before (org.junit.Before)13 VisibleForTesting (android.support.annotation.VisibleForTesting)12 Preference (android.support.v7.preference.Preference)12