Search in sources :

Example 26 with WifiConfiguration

use of android.net.wifi.WifiConfiguration in project robolectric by robolectric.

the class ShadowWifiManagerTest method updateNetwork_shouldReplaceNetworks.

@Test
public void updateNetwork_shouldReplaceNetworks() throws Exception {
    WifiConfiguration wifiConfiguration = new WifiConfiguration();
    wifiConfiguration.networkId = -1;
    wifiManager.addNetwork(wifiConfiguration);
    WifiConfiguration anotherConfig = new WifiConfiguration();
    int networkId = wifiManager.addNetwork(anotherConfig);
    assertThat(networkId).isEqualTo(1);
    WifiConfiguration configuration = new WifiConfiguration();
    configuration.networkId = networkId;
    configuration.priority = 44;
    assertThat(wifiManager.updateNetwork(configuration)).isEqualTo(networkId);
    List<WifiConfiguration> configuredNetworks = wifiManager.getConfiguredNetworks();
    assertThat(configuredNetworks.size()).isEqualTo(2);
    assertThat(configuration.priority).isEqualTo(44);
    assertThat(configuredNetworks.get(1).priority).isEqualTo(44);
}
Also used : WifiConfiguration(android.net.wifi.WifiConfiguration) Test(org.junit.Test)

Example 27 with WifiConfiguration

use of android.net.wifi.WifiConfiguration in project robolectric by robolectric.

the class ShadowWifiConfiguration method copy.

public WifiConfiguration copy() {
    WifiConfiguration config = new WifiConfiguration();
    config.networkId = realObject.networkId;
    config.SSID = realObject.SSID;
    config.BSSID = realObject.BSSID;
    config.preSharedKey = realObject.preSharedKey;
    config.wepTxKeyIndex = realObject.wepTxKeyIndex;
    config.status = realObject.status;
    config.priority = realObject.priority;
    config.hiddenSSID = realObject.hiddenSSID;
    config.allowedKeyManagement = (BitSet) realObject.allowedKeyManagement.clone();
    config.allowedProtocols = (BitSet) realObject.allowedProtocols.clone();
    config.allowedAuthAlgorithms = (BitSet) realObject.allowedAuthAlgorithms.clone();
    config.allowedPairwiseCiphers = (BitSet) realObject.allowedPairwiseCiphers.clone();
    config.allowedGroupCiphers = (BitSet) realObject.allowedGroupCiphers.clone();
    config.wepKeys = new String[4];
    System.arraycopy(realObject.wepKeys, 0, config.wepKeys, 0, config.wepKeys.length);
    return config;
}
Also used : WifiConfiguration(android.net.wifi.WifiConfiguration)

Example 28 with WifiConfiguration

use of android.net.wifi.WifiConfiguration in project robolectric by robolectric.

the class ShadowWifiManager method makeCopy.

private WifiConfiguration makeCopy(WifiConfiguration config, int networkId) {
    WifiConfiguration copy = Shadows.shadowOf(config).copy();
    copy.networkId = networkId;
    return copy;
}
Also used : WifiConfiguration(android.net.wifi.WifiConfiguration)

Example 29 with WifiConfiguration

use of android.net.wifi.WifiConfiguration in project android by cSploit.

the class NetworkManager method shiftPriorityAndSave.

public static int shiftPriorityAndSave(final WifiManager wifiMgr) {
    final List<WifiConfiguration> configurations = wifiMgr.getConfiguredNetworks();
    sortByPriority(configurations);
    final int size = configurations.size();
    for (int i = 0; i < size; i++) {
        final WifiConfiguration config = configurations.get(i);
        config.priority = i;
        wifiMgr.updateNetwork(config);
    }
    wifiMgr.saveConfiguration();
    return size;
}
Also used : WifiConfiguration(android.net.wifi.WifiConfiguration)

Example 30 with WifiConfiguration

use of android.net.wifi.WifiConfiguration in project zxingfragmentlib by mitoyarzun.

the class WifiConfigManager method changeNetworkWPA.

// Adding a WPA or WPA2 network
private static void changeNetworkWPA(WifiManager wifiManager, WifiParsedResult wifiResult) {
    WifiConfiguration config = changeNetworkCommon(wifiResult);
    // Hex passwords that are 64 bits long are not to be quoted.
    config.preSharedKey = quoteNonHex(wifiResult.getPassword(), 64);
    config.allowedAuthAlgorithms.set(WifiConfiguration.AuthAlgorithm.OPEN);
    // For WPA
    config.allowedProtocols.set(WifiConfiguration.Protocol.WPA);
    // For WPA2
    config.allowedProtocols.set(WifiConfiguration.Protocol.RSN);
    config.allowedKeyManagement.set(WifiConfiguration.KeyMgmt.WPA_PSK);
    config.allowedKeyManagement.set(WifiConfiguration.KeyMgmt.WPA_EAP);
    config.allowedPairwiseCiphers.set(WifiConfiguration.PairwiseCipher.TKIP);
    config.allowedPairwiseCiphers.set(WifiConfiguration.PairwiseCipher.CCMP);
    config.allowedGroupCiphers.set(WifiConfiguration.GroupCipher.TKIP);
    config.allowedGroupCiphers.set(WifiConfiguration.GroupCipher.CCMP);
    updateNetwork(wifiManager, config);
}
Also used : WifiConfiguration(android.net.wifi.WifiConfiguration)

Aggregations

WifiConfiguration (android.net.wifi.WifiConfiguration)316 WifiManager (android.net.wifi.WifiManager)54 LargeTest (android.test.suitebuilder.annotation.LargeTest)53 IOException (java.io.IOException)44 ArrayList (java.util.ArrayList)38 WifiEnterpriseConfig (android.net.wifi.WifiEnterpriseConfig)32 ScanResult (android.net.wifi.ScanResult)27 Credential (com.android.hotspot2.pps.Credential)20 Scanner (com.android.settingslib.wifi.WifiTracker.Scanner)20 WifiInfo (android.net.wifi.WifiInfo)16 Bundle (android.os.Bundle)12 NetworkPolicy (android.net.NetworkPolicy)10 SpannableString (android.text.SpannableString)10 EAP (com.android.anqp.eap.EAP)10 X509Certificate (java.security.cert.X509Certificate)10 StaticIpConfiguration (android.net.StaticIpConfiguration)7 PackageManager (android.content.pm.PackageManager)6 NetworkInfo (android.net.NetworkInfo)6 PowerManager (android.os.PowerManager)6 RemoteException (android.os.RemoteException)6