Search in sources :

Example 81 with WifiConfiguration

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

the class OSUManager method wnmRemediate.

// !!! Consistently check passpoint match.
// !!! Convert to a one-thread thread-pool
public void wnmRemediate(long bssid, String url, PasspointMatch match) throws IOException, SAXException {
    WifiConfiguration config = mWifiNetworkAdapter.getActiveWifiConfig();
    HomeSP homeSP = MOManager.buildSP(config.getMoTree());
    if (homeSP == null) {
        throw new IOException("Remediation request for unidentified Passpoint network " + config.networkId);
    }
    Network network = mWifiNetworkAdapter.getCurrentNetwork();
    if (network == null) {
        throw new IOException("Failed to determine current network");
    }
    WifiInfo wifiInfo = mWifiNetworkAdapter.getConnectionInfo();
    if (wifiInfo == null || Utils.parseMac(wifiInfo.getBSSID()) != bssid) {
        throw new IOException("Mismatching BSSID");
    }
    Log.d(TAG, "WNM Remediation on " + network.netId + " FQDN " + homeSP.getFQDN());
    doRemediate(url, network, homeSP, false);
}
Also used : HomeSP(com.android.hotspot2.pps.HomeSP) WifiConfiguration(android.net.wifi.WifiConfiguration) Network(android.net.Network) IOException(java.io.IOException) WifiInfo(android.net.wifi.WifiInfo)

Example 82 with WifiConfiguration

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

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

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

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

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

the class Wifi method shiftPriorityAndSave.

private 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 85 with WifiConfiguration

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

the class Wifi method checkForExcessOpenNetworkAndSave.

/**
     * Ensure no more than numOpenNetworksKept open networks in configuration list.
     *
     * @param wifiMgr
     * @param numOpenNetworksKept
     * @return Operation succeed or not.
     */
private static boolean checkForExcessOpenNetworkAndSave(final WifiManager wifiMgr, final int numOpenNetworksKept) {
    final List<WifiConfiguration> configurations = wifiMgr.getConfiguredNetworks();
    sortByPriority(configurations);
    boolean modified = false;
    int tempCount = 0;
    for (int i = configurations.size() - 1; i >= 0; i--) {
        final WifiConfiguration config = configurations.get(i);
        if (ConfigSec.isOpenNetwork(ConfigSec.getWifiConfigurationSecurity(config))) {
            tempCount++;
            if (tempCount >= numOpenNetworksKept) {
                modified = true;
                wifiMgr.removeNetwork(config.networkId);
            }
        }
    }
    return !modified || wifiMgr.saveConfiguration();
}
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