Search in sources :

Example 56 with WifiConfiguration

use of android.net.wifi.WifiConfiguration in project android_frameworks_base by DirtyUnicorns.

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 57 with WifiConfiguration

use of android.net.wifi.WifiConfiguration in project android_frameworks_base by DirtyUnicorns.

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 58 with WifiConfiguration

use of android.net.wifi.WifiConfiguration in project android_frameworks_base by DirtyUnicorns.

the class AccessPoint method generateOpenNetworkConfig.

/**
     * Generate and save a default wifiConfiguration with common values.
     * Can only be called for unsecured networks.
     */
public void generateOpenNetworkConfig() {
    if (security != SECURITY_NONE)
        throw new IllegalStateException();
    if (mConfig != null)
        return;
    mConfig = new WifiConfiguration();
    mConfig.SSID = AccessPoint.convertToQuotedString(ssid);
    mConfig.allowedKeyManagement.set(KeyMgmt.NONE);
}
Also used : WifiConfiguration(android.net.wifi.WifiConfiguration)

Example 59 with WifiConfiguration

use of android.net.wifi.WifiConfiguration in project android_frameworks_base by DirtyUnicorns.

the class WifiTracker method updateNetworkInfo.

private void updateNetworkInfo(NetworkInfo networkInfo) {
    /* sticky broadcasts can call this when wifi is disabled */
    if (!mWifiManager.isWifiEnabled()) {
        mMainHandler.sendEmptyMessage(MainHandler.MSG_PAUSE_SCANNING);
        return;
    }
    if (networkInfo != null && networkInfo.getDetailedState() == DetailedState.OBTAINING_IPADDR) {
        mMainHandler.sendEmptyMessage(MainHandler.MSG_PAUSE_SCANNING);
    } else {
        mMainHandler.sendEmptyMessage(MainHandler.MSG_RESUME_SCANNING);
    }
    if (networkInfo != null) {
        mLastNetworkInfo = networkInfo;
    }
    WifiConfiguration connectionConfig = null;
    mLastInfo = mWifiManager.getConnectionInfo();
    if (mLastInfo != null) {
        connectionConfig = getWifiConfigurationForNetworkId(mLastInfo.getNetworkId());
    }
    boolean reorder = false;
    for (int i = mAccessPoints.size() - 1; i >= 0; --i) {
        if (mAccessPoints.get(i).update(connectionConfig, mLastInfo, mLastNetworkInfo)) {
            reorder = true;
        }
    }
    if (reorder) {
        synchronized (mAccessPoints) {
            Collections.sort(mAccessPoints);
        }
        mMainHandler.sendEmptyMessage(MainHandler.MSG_ACCESS_POINT_CHANGED);
    }
}
Also used : WifiConfiguration(android.net.wifi.WifiConfiguration)

Example 60 with WifiConfiguration

use of android.net.wifi.WifiConfiguration in project android_frameworks_base by DirtyUnicorns.

the class WifiTrackerTest method addConfig.

private int addConfig(List<WifiConfiguration> configs, String ssid) {
    WifiConfiguration config = new WifiConfiguration();
    config.networkId = configs.size();
    config.SSID = '"' + ssid + '"';
    configs.add(config);
    return config.networkId;
}
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