Search in sources :

Example 46 with WifiManager

use of android.net.wifi.WifiManager in project android_frameworks_base by crdroidandroid.

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)

Example 47 with WifiManager

use of android.net.wifi.WifiManager in project android_frameworks_base by crdroidandroid.

the class WifiNetworkAdapter method matchProviderWithCurrentNetwork.

public PasspointMatch matchProviderWithCurrentNetwork(String fqdn) {
    WifiManager wifiManager = (WifiManager) mContext.getSystemService(Context.WIFI_SERVICE);
    int ordinal = wifiManager.matchProviderWithCurrentNetwork(fqdn);
    return ordinal >= 0 && ordinal < PasspointMatch.values().length ? PasspointMatch.values()[ordinal] : null;
}
Also used : WifiManager(android.net.wifi.WifiManager)

Example 48 with WifiManager

use of android.net.wifi.WifiManager in project android_frameworks_base by AOSPA.

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)

Example 49 with WifiManager

use of android.net.wifi.WifiManager in project android_frameworks_base by AOSPA.

the class WifiNetworkAdapter method connect.

/**
     * Connect to an OSU provisioning network. The connection should not bring down other existing
     * connection and the network should not be made the default network since the connection
     * is solely for sign up and is neither intended for nor likely provides access to any
     * generic resources.
     *
     * @param osuInfo The OSU info object that defines the parameters for the network. An OSU
     *                network is either an open network, or, if the OSU NAI is set, an "OSEN"
     *                network, which is an anonymous EAP-TLS network with special keys.
     * @param info    An opaque string that is passed on to any user notification. The string is used
     *                for the name of the service provider.
     * @return an Integer holding the network-id of the just added network configuration, or null
     * if the network existed prior to this call (was not added by the OSU infrastructure).
     * The value will be used at the end of the OSU flow to delete the network as applicable.
     * @throws IOException Issues:
     *                     1. The network id is not returned. addNetwork cannot be called from here since the method
     *                     runs in the context of the app and doesn't have the appropriate permission.
     *                     2. The connection is not immediately usable if the network was not previously selected
     *                     manually.
     */
public Integer connect(OSUInfo osuInfo, final String info) throws IOException {
    WifiManager wifiManager = (WifiManager) mContext.getSystemService(Context.WIFI_SERVICE);
    WifiConfiguration config = new WifiConfiguration();
    config.SSID = '"' + osuInfo.getSSID() + '"';
    if (osuInfo.getOSUBssid() != 0) {
        config.BSSID = Utils.macToString(osuInfo.getOSUBssid());
        Log.d(OSUManager.TAG, String.format("Setting BSSID of '%s' to %012x", osuInfo.getSSID(), osuInfo.getOSUBssid()));
    }
    if (osuInfo.getOSUProvider().getOsuNai() == null) {
        config.allowedKeyManagement.set(WifiConfiguration.KeyMgmt.NONE);
    } else {
        config.allowedKeyManagement.set(WifiConfiguration.KeyMgmt.OSEN);
        config.allowedProtocols.set(WifiConfiguration.Protocol.OSEN);
        config.allowedPairwiseCiphers.set(WifiConfiguration.PairwiseCipher.CCMP);
        config.allowedGroupCiphers.set(WifiConfiguration.GroupCipher.GTK_NOT_USED);
        config.enterpriseConfig = new WifiEnterpriseConfig();
        config.enterpriseConfig.setEapMethod(WifiEnterpriseConfig.Eap.UNAUTH_TLS);
        config.enterpriseConfig.setIdentity(osuInfo.getOSUProvider().getOsuNai());
    // !!! OSEN CA Cert???
    }
    int networkId = wifiManager.addNetwork(config);
    if (wifiManager.enableNetwork(networkId, true)) {
        return networkId;
    } else {
        return null;
    }
/* sequence of addNetwork(), enableNetwork(), saveConfiguration() and reconnect()
        wifiManager.connect(config, new WifiManager.ActionListener() {
            @Override
            public void onSuccess() {
                // Connection event comes from network change intent registered in initialize
            }

            @Override
            public void onFailure(int reason) {
                mOSUManager.notifyUser(OSUOperationStatus.ProvisioningFailure,
                        "Cannot connect to OSU network: " + reason, info);
            }
        });
        return null;

        /*
        try {
            int nwkID = wifiManager.addOrUpdateOSUNetwork(config);
            if (nwkID == WifiConfiguration.INVALID_NETWORK_ID) {
                throw new IOException("Failed to add OSU network");
            }
            wifiManager.enableNetwork(nwkID, false);
            wifiManager.reconnect();
            return nwkID;
        }
        catch (SecurityException se) {
            Log.d("ZXZ", "Blah: " + se, se);
            wifiManager.connect(config, new WifiManager.ActionListener() {
                @Override
                public void onSuccess() {
                    // Connection event comes from network change intent registered in initialize
                }

                @Override
                public void onFailure(int reason) {
                    mOSUManager.notifyUser(OSUOperationStatus.ProvisioningFailure,
                            "Cannot connect to OSU network: " + reason, info);
                }
            });
            return null;
        }
        */
}
Also used : WifiEnterpriseConfig(android.net.wifi.WifiEnterpriseConfig) WifiManager(android.net.wifi.WifiManager) WifiConfiguration(android.net.wifi.WifiConfiguration)

Example 50 with WifiManager

use of android.net.wifi.WifiManager in project android_frameworks_base by AOSPA.

the class WifiNetworkAdapter method deleteNetwork.

public void deleteNetwork(int id) {
    WifiManager wifiManager = (WifiManager) mContext.getSystemService(Context.WIFI_SERVICE);
    wifiManager.disableNetwork(id);
    wifiManager.forget(id, null);
}
Also used : WifiManager(android.net.wifi.WifiManager)

Aggregations

WifiManager (android.net.wifi.WifiManager)329 WifiInfo (android.net.wifi.WifiInfo)80 WifiConfiguration (android.net.wifi.WifiConfiguration)76 IOException (java.io.IOException)38 Intent (android.content.Intent)27 SuppressLint (android.annotation.SuppressLint)26 ConnectivityManager (android.net.ConnectivityManager)23 Context (android.content.Context)22 NetworkInfo (android.net.NetworkInfo)21 Test (org.junit.Test)20 AccessPoint (com.android.settingslib.wifi.AccessPoint)17 IntentFilter (android.content.IntentFilter)16 Bundle (android.os.Bundle)16 ArrayList (java.util.ArrayList)16 NetworkPolicyEditor (com.android.settingslib.NetworkPolicyEditor)12 PowerManager (android.os.PowerManager)11 WifiEnterpriseConfig (android.net.wifi.WifiEnterpriseConfig)10 SocketException (java.net.SocketException)10 SharedPreferences (android.content.SharedPreferences)9 Method (java.lang.reflect.Method)9