Search in sources :

Example 86 with WifiConfiguration

use of android.net.wifi.WifiConfiguration in project routerkeygenAndroid by routerkeygen.

the class Wifi method getWifiConfiguration.

private static WifiConfiguration getWifiConfiguration(final WifiManager wifiMgr, final ScanResult hotspot, String hotspotSecurity) {
    final String ssid = convertToQuotedString(hotspot.SSID);
    if (ssid.length() == 0) {
        return null;
    }
    final String bssid = hotspot.BSSID;
    if (bssid == null) {
        return null;
    }
    if (hotspotSecurity == null) {
        hotspotSecurity = ConfigSec.getScanResultSecurity(hotspot);
    }
    final List<WifiConfiguration> configurations = wifiMgr.getConfiguredNetworks();
    if (configurations == null) {
        return null;
    }
    for (final WifiConfiguration config : configurations) {
        if (config.SSID == null || !ssid.equals(config.SSID)) {
            continue;
        }
        if (config.BSSID == null || bssid.equals(config.BSSID)) {
            final String configSecurity = ConfigSec.getWifiConfigurationSecurity(config);
            if (hotspotSecurity.equals(configSecurity)) {
                return config;
            }
        }
    }
    return null;
}
Also used : WifiConfiguration(android.net.wifi.WifiConfiguration)

Example 87 with WifiConfiguration

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

the class NetworkPolicyManagerShellCommand method setMeteredWifiNetwork.

private int setMeteredWifiNetwork() throws RemoteException {
    final PrintWriter pw = getOutPrintWriter();
    final String id = getNextArg();
    if (id == null) {
        pw.println("Error: didn't specify ID");
        return -1;
    }
    final String arg = getNextArg();
    if (arg == null) {
        pw.println("Error: didn't specify BOOLEAN");
        return -1;
    }
    final boolean metered = Boolean.valueOf(arg);
    final NetworkPolicy[] policies = mInterface.getNetworkPolicies(null);
    boolean changed = false;
    // First try to find a policy with such id
    for (NetworkPolicy policy : policies) {
        if (policy.template.isMatchRuleMobile() || policy.metered == metered) {
            continue;
        }
        final String networkId = getNetworkId(policy);
        if (id.equals(networkId)) {
            Log.i(TAG, "Changing " + networkId + " metered status to " + metered);
            policy.metered = metered;
            changed = true;
        }
    }
    if (changed) {
        mInterface.setNetworkPolicies(policies);
        return 0;
    }
    // Policy not found: check if there is a saved wi-fi with such id.
    for (WifiConfiguration config : mWifiManager.getConfiguredNetworks()) {
        final String ssid = removeDoubleQuotes(config.SSID);
        if (id.equals(ssid)) {
            final NetworkPolicy policy = newPolicy(ssid);
            policy.metered = true;
            Log.i(TAG, "Creating new policy for " + ssid + ": " + policy);
            final NetworkPolicy[] newPolicies = new NetworkPolicy[policies.length + 1];
            System.arraycopy(policies, 0, newPolicies, 0, policies.length);
            newPolicies[newPolicies.length - 1] = policy;
            mInterface.setNetworkPolicies(newPolicies);
        }
    }
    return 0;
}
Also used : WifiConfiguration(android.net.wifi.WifiConfiguration) NetworkPolicy(android.net.NetworkPolicy) PrintWriter(java.io.PrintWriter)

Example 88 with WifiConfiguration

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

the class NetworkPolicyManagerShellCommand method getWifiPolicies.

private List<NetworkPolicy> getWifiPolicies() throws RemoteException {
    // First gets a list of saved wi-fi networks.
    final List<WifiConfiguration> configs = mWifiManager.getConfiguredNetworks();
    final int size = configs != null ? configs.size() : 0;
    final Set<String> ssids = new HashSet<>(size);
    if (configs != null) {
        for (WifiConfiguration config : configs) {
            ssids.add(removeDoubleQuotes(config.SSID));
        }
    }
    // Then gets the saved policies.
    final NetworkPolicy[] policies = mInterface.getNetworkPolicies(null);
    final List<NetworkPolicy> wifiPolicies = new ArrayList<NetworkPolicy>(policies.length);
    for (NetworkPolicy policy : policies) {
        if (!policy.template.isMatchRuleMobile()) {
            wifiPolicies.add(policy);
            final String netId = getNetworkId(policy);
            ssids.remove(netId);
        }
    }
    // Finally, creates new default policies for saved WI-FIs not policied yet.
    for (String ssid : ssids) {
        final NetworkPolicy policy = newPolicy(ssid);
        wifiPolicies.add(policy);
    }
    return wifiPolicies;
}
Also used : WifiConfiguration(android.net.wifi.WifiConfiguration) NetworkPolicy(android.net.NetworkPolicy) ArrayList(java.util.ArrayList) HashSet(java.util.HashSet)

Example 89 with WifiConfiguration

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

the class WifiConfigurationHelper method createGenericConfig.

/**
     * Create a generic {@link WifiConfiguration} used by the other create methods.
     */
private static WifiConfiguration createGenericConfig(String ssid) {
    WifiConfiguration config = new WifiConfiguration();
    config.SSID = quotedString(ssid);
    config.setIpAssignment(IpAssignment.DHCP);
    config.setProxySettings(ProxySettings.NONE);
    return config;
}
Also used : WifiConfiguration(android.net.wifi.WifiConfiguration)

Example 90 with WifiConfiguration

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

the class WifiConfigurationHelper method createWepConfig.

/**
     * Create a {@link WifiConfiguration} for a WEP secured network
     *
     * @param ssid The SSID of the wifi network
     * @param password Either a 10, 26, or 58 character hex string or the plain text password
     * @return The {@link WifiConfiguration}
     */
public static WifiConfiguration createWepConfig(String ssid, String password) {
    WifiConfiguration config = createGenericConfig(ssid);
    if (isHex(password, 10) || isHex(password, 26) || isHex(password, 58)) {
        config.wepKeys[0] = password;
    } else {
        config.wepKeys[0] = quotedString(password);
    }
    config.allowedKeyManagement.set(KeyMgmt.NONE);
    config.allowedAuthAlgorithms.set(AuthAlgorithm.OPEN);
    config.allowedAuthAlgorithms.set(AuthAlgorithm.SHARED);
    return config;
}
Also used : WifiConfiguration(android.net.wifi.WifiConfiguration)

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